first draft for Slate's ffi
Paul Dufresne
dufrp at hotmail.com
Mon Oct 11 16:14:29 PDT 2004
Well, this is just a simple text file, I was writing to put some order in
the
mess going on in my mind about ffi. Clearly, this is still a mess. It would
need some more cleaning, but I hope one could get the idea from just
that, and be able to comment early in the design process.
Here I am trying to summarize my thinking about Slate's ffi to C
openDynLib
enter:
libname: name of lib
symbLib: symbol that will identify it
structs: dictionnary of structSymbole ->
tuple of slateType of each member of the structure
constants: dictionnary of constantSymbole -> slateType
"note that slateType can be a simpleSlateType, or a structSymb"
out:
Boolean (was able to open it, by prelinking all)
closeDynLib
enter:
symbLib
out:
Nothing
Defining a ffi method:
" ffiC is a special macro with paramaters "
paramName1!(slateType) paramName2!(slateType)... returns:!(slateType)
selector [
" I see no reason to have a body here"
] 'ffiC symlib funcname!String
calling the method would looks like:
ffiCallC selector param1 param2 param3 ...
where params would be of the correct slateType
Under the hood
==============
opendDynLib:
-call dlopen with libname, asking prelinking
-save structs and constants in ffiCStore
closeDynLib:
call dlclose
ffiC macro:
-funcPtr = dlsym to find funcname in symlib (Symbol for the library)
-generate ffi_type **atypes from all the params
To do this, use a dictionnary of simpleSlateType -> ffi_type,
if param is part of structs saved in ffiCStore, give the
good ffi_type for that
"note alse that each symbolType can
have "Ptr" at the end, if so, add a pointer ffi_type"
-call in ffi_prep_cif (cif, FFI_DEFAULT_ABI, number of params
excluding returns: , returns: value, generated atypes ), after
which cif (Call interface function) is initialized and ready
be called
-Save in ffiCStore
funcInfo: dictionnary of selector -> ( cif, atypes, list of
slateType, returnLength of returns:, returns: , funcPtr )
"The Slate list of ffi_type is usefull, to check when calling "
ffiCallC:
"too fuzzy, need to be more cleanly designed"
-use selector to get from ffiCStore: cif, atypes, list of slateType,
returnLength of returns: , returns: and funcPtr
-allocate void **avalues, that is, a list of pointers to
each parameter allocated space
-allocate a rvalue buffer big enough for returns:
-call ffi_call (cif, funcPtr, rvalue, aavalues )
-Translate back, each element of aavalues to it's slateType
ffiCStore is an Object holding infos on libraries, and
on each function of these libraries
funcInfo: dictionnary of selector -> ( cif, atypes, list of
slateType, returnLength of returns:, returns: , funcPtr )
"The Slate list of ffi_type is usefull, to check when calling "
bufferLengths: dictionnary of slateType -> length of a ByteArrayBuffer
needed to hold slateType
... need to think more
_________________________________________________________________
Balayez vos courriels entrants et sortants et les pièces jointes et
contribuez à éliminer les virus destructeurs susceptibles dy être intégrés.
http://join.msn.com/?pgmarket=fr-ca&page=features/virus Commencez dès
maintenant à profiter de tous les avantages de MSN Premium et obtenez les
deux premiers mois GRATUITS*.
More information about the Slate
mailing list