memoryAccessor

Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 279
Joined: 14 Nov 2002 0:01

memoryAccessor

Unread post by Martin Meyer » 7 Jan 2020 19:07

Hello Thomas,

the debugger has a problem in this console application (in build 902):

Code: Select all

implement main   clauses     run() :-         ArM = arrayM::new(1),         ArM:set(0, ""),         stdIO::write(ArM).  %set a breakpoint here   end implement main   goal     console::runUtf8(main::run).
To cure that I have changed the memoryAccessor class a little. With the change the debugger worked well in all my tests. Please have a look at it and tell whether the change is OK or you see cases in which it does not work as intended:

Code: Select all

namespace collectionSupport   interface memoryAccessor{@Elem}     open core   properties     size : byteCount (o).     % @short Size of <b>@Elem</b> values in bytes.     % @end   properties     isAtomic : boolean (o).     % @short States whether <b>@Elem</b> values are atomic.     % @end   properties     set : predicate{pointer Pointer, @Elem Elem} (o).     % @short Store #Elem at memory location #Pointer.     % @end   properties     get : function{pointer Pointer, @Elem Elem} (o).     % @short Retrieve #Elem from memory location #Pointer.     % @end   end interface memoryAccessor

Code: Select all

namespace collectionSupport   implement memoryAccessor{@Elem}     open core   facts     size : byteCount [constant].     isAtomic : boolean [constant].     set : predicate{pointer, @Elem} [constant].     get : function{pointer, @Elem} [constant].   #if platform_bits = 32 #then     clauses         new() :-             TL = typeLibraryOf(@Elem),             % The relevant change is omitting exceptions by using sizeOfDomain(@Elem)             % instead of V = uncheckedConvert(@Elem, 0x10) and sizeOf(V):             SV = if TL:isFunctorType() = _ then sizeOfDomain(pointer) else sizeOfDomain(@Elem) end if,             isAtomic := toBoolean(pfc\reflection\reflection_native::termRepresentedByValue(TL)),             if SV <= 1 then                 size := 1,                 set := set1,                 get := get1             elseif SV <= 2 then                 size := 2,                 set := set2,                 get := get2             else                 size := 4,                 set := set4,                 get := get4             end if. #elseif platform_bits = 64 #then     clauses         new() :-             TL = typeLibraryOf(@Elem),             SV = if TL:isFunctorType() = _ then sizeOfDomain(pointer) else sizeOfDomain(@Elem) end if,             isAtomic := toBoolean(pfc\reflection\reflection_native::termRepresentedByValue(TL)),             if SV <= 1 then                 size := 1,                 set := set1,                 get := get1             elseif SV <= 2 then                 size := 2,                 set := set2,                 get := get2             elseif SV <= 4 then                 size := 4,                 set := set4,                 get := get4             else                 size := 8,                 set := set8,                 get := get8             end if. #else     #error "platform_bits has unexpected value" #endif   predicates     get1 : (pointer P) -> @Elem E. clauses     get1(P) = uncheckedConvert(@Elem, convert(unsignedNative, memory::getUnsigned8(P))).   predicates     get2 : (pointer P) -> @Elem E. clauses     get2(P) = uncheckedConvert(@Elem, convert(unsignedNative, memory::getUnsigned16(P))).   predicates     get4 : (pointer P) -> @Elem E. clauses     get4(P) = uncheckedConvert(@Elem, convert(unsignedNative, memory::getUnsigned(P))).   #if platform_bits = 64 #then     predicates         get8 : (pointer P) -> @Elem E.     clauses         get8(P) = uncheckedConvert(@Elem, convert(unsignedNative, memory::getUnsigned64(P))). #endif   predicates     set1 : (pointer P, @Elem E). clauses     set1(P, E) :-         memory::move(P, uncheckedConvert(pointer, memory::pUnsignedNative(uncheckedConvert(unsignedNative, E))), 1).   predicates     set2 : (pointer P, @Elem E). clauses     set2(P, E) :-         memory::move(P, uncheckedConvert(pointer, memory::pUnsignedNative(uncheckedConvert(unsignedNative, E))), 2).   predicates     set4 : (pointer P, @Elem E). clauses     set4(P, E) :-         memory::move(P, uncheckedConvert(pointer, memory::pUnsignedNative(uncheckedConvert(unsignedNative, E))), 4).   #if platform_bits = 64 #then     predicates         set8 : (pointer P, @Elem E).     clauses         set8(P, E) :-             memory::move(P, uncheckedConvert(pointer, memory::pUnsignedNative(uncheckedConvert(unsignedNative, E))), 8). #endif   end implement memoryAccessor
Regards Martin

User avatar
Thomas Linder Puls
VIP Member
Posts: 1165
Joined: 28 Feb 2000 0:01

Re: memoryAccessor

Unread post by Thomas Linder Puls » 9 Jan 2020 11:11

I am not really sure why the original code was that complex; this should do:

Code: Select all

clauses     new() :-         isAtomic := toBoolean(pfc\reflection\reflection_native::termRepresentedByValue(typeLibraryOf(@Elem))),         SV = if true = isAtomic then sizeOfDomain(@Elem) else sizeOfDomain(pointer) end if,         if SV = 1 then             get_fact := get1,             set_fact := set1,             size := 1         elseif SV = 2 then             get_fact := get2,             set_fact := set2,             size := 2         elseif SV <= 4 then             get_fact := get4,             set_fact := set4,             size := 4         elseif SV <= 8 then             get_fact := get8,             set_fact := set8,             size := 8         else             exception::raise_error()         end if.
Regards Thomas Linder Puls
PDC

Martin Meyer
VIP Member
Posts: 279
Joined: 14 Nov 2002 0:01

Re: memoryAccessor

Unread post by Martin Meyer » 9 Jan 2020 20:20

Ah, thank you Thomas! I have updated memoryAccessor to your code.
Regards Martin

Post Reply