[NativeBoost] New update available

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[NativeBoost] New update available

Igor Stasenko
Hello all.

The main direction of work during last days, were introducing a new
function formal specification format.

With new format, NativeBoost jumps on a next level of flexibility and
much less error prone to use!!

Here is the old format:

primGetModuleFileName: hModule with: lpFileName with: nSize
        <primitive: #primitiveNativeCall module: #NativeBoostPlugin>

        ^ NBFFICallout
                apiCall: #(DWORD 'GetModuleFileNameA' ("in" HMODULE "out"LPCSTR "in"DWORD) )
                module: #Kernel32
                options: #( - coerceNilToNull )

and here is new:

primGetModuleFileName: hModule with: lpFileName with: nSize
        <primitive: #primitiveNativeCall module: #NativeBoostPlugin>

        ^ NBFFICallout
                apiCall: #(
                        DWORD GetModuleFileName (
                                HMODULE hModule,
                                LPTSTR lpFilename,
                                DWORD nSize))
                module: #Kernel32
                options: #( - coerceNilToNull )

A new format matching very closely to C syntax.. so , for most C
functions you can just do a copy-paste!

Also, see that formal spec includes an argument names. They are not a
dummy ones, but instead should match the argument names of method.
In that way, the formal spec can check the argument names and also,
takes in account their order on ST stack.
So, you can push arguments in different order as you specified in
smalltalk method.
But that's not all.
Besides a formal argument names, a new format also accepts  constants
, instance variables and special variable - self.

Here:

alloc: numberOfBytes
        <primitive: #primitiveNativeCall module: #NativeBoostPlugin>

        ^ NBFFICallout apiCall: #( LPVOID HeapAlloc (self , 0 , SIZE_T
numberOfBytes) ) module: #Kernel32

a windoze function takes 3 arguments
LPVOID HeapAlloc( HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes );

but your method takes just one, while other two is 'self'  and 0 constant.
Instead of just integer literal, you can also use a class variables or
pool variables, to make things more convenient and readable:

zalloc: numberOfBytes
        "same as #alloc: but additionally zero-fill the allocated memory"
        <primitive: #primitiveNativeCall module: #NativeBoostPlugin>

        ^ NBFFICallout apiCall:
                #( LPVOID HeapAlloc (self , HEAP_ZERO_MEMORY , SIZE_T numberOfBytes) )
                module: #Kernel32


And the last thing, is instance variable access.

Point>>nbX

        <primitive: #primitiveNativeCall module: #NativeBoostPlugin >
       
        ^ NBFFICallout cdecl: #( sbyte (long x) ) emitCall: [:gen |
                gen asm pop: gen asm EAX ]

here, primitive reads x ivar of Point instance, as a 'long' C value,
but on return, converts it to a signed byte value, so:

(127@5) nbX 127
(128@5) nbX -128
(-200@5) nbX 56
(5000@5) nbX -120

P.S. Thanks Henrik for a suggestion to change the format! It is now roxxx! :)

--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project