ExternalLibraryFunction.st
changeset 19950 ee2f6bfd55c1
parent 19933 d45636ff51df
child 19951 2ba5ef097a79
equal deleted inserted replaced
19944:c4f52f26c084 19950:ee2f6bfd55c1
    83 # define TYPE_SINT16    __get_ffi_type_sint16()
    83 # define TYPE_SINT16    __get_ffi_type_sint16()
    84 # define TYPE_SINT32    __get_ffi_type_sint32()
    84 # define TYPE_SINT32    __get_ffi_type_sint32()
    85 # define TYPE_SINT64    __get_ffi_type_sint64()
    85 # define TYPE_SINT64    __get_ffi_type_sint64()
    86 
    86 
    87 # define TYPE_POINTER   __get_ffi_type_pointer()
    87 # define TYPE_POINTER   __get_ffi_type_pointer()
    88 # define TYPE_FLOAT     __get_ffi_type_float();
    88 # define TYPE_FLOAT     __get_ffi_type_float()
    89 # define TYPE_DOUBLE    __get_ffi_type_double();
    89 # define TYPE_DOUBLE    __get_ffi_type_double()
    90 # define TYPE_VOID      __get_ffi_type_void();
    90 # define TYPE_VOID      __get_ffi_type_void()
    91 
    91 
    92 #else /* NO FFI */
    92 #else /* NO FFI */
    93 
    93 
    94 # define MAX_ARGS    15
    94 # define MAX_ARGS    15
    95 # define TYPE_UINT      1
    95 # define TYPE_UINT      1
   138     instances of me are used to interface to external library functions (as found in a dll/shared object).
   138     instances of me are used to interface to external library functions (as found in a dll/shared object).
   139     Foreign function calls are based on the FFI library if available.
   139     Foreign function calls are based on the FFI library if available.
   140     A limited fallback implementation is provided for systems with no libffi.
   140     A limited fallback implementation is provided for systems with no libffi.
   141     (this may have limitations on the supported argument types; for example,
   141     (this may have limitations on the supported argument types; for example,
   142      the x86_64 fallback does not support float/double arguments).
   142      the x86_64 fallback does not support float/double arguments).
   143     Therefore the fallback should be considered a temporary workaround, 
   143     Therefore the fallback should be considered a temporary workaround,
   144     until libffi has been ported.
   144     until libffi has been ported.
   145     
   145 
   146     Inside a method, when a special external-call pragma such as:
   146     Inside a method, when a special external-call pragma such as:
   147         <api: bool MessageBeep(uint)>
   147 	<api: bool MessageBeep(uint)>
   148 
   148 
   149     is encountered by the parser, the compiler generates a call via
   149     is encountered by the parser, the compiler generates a call via
   150         <correspondingExternalLibraryFunctionObject> invokeWithArguments: argumentArray.
   150 	<correspondingExternalLibraryFunctionObject> invokeWithArguments: argumentArray.
   151     and the correspondingExternalLibraryFunctionObject is kept in the literal array.
   151     and the correspondingExternalLibraryFunctionObject is kept in the literal array.
   152 
   152 
   153     In the invoke method, the library is checked to be loaded (and loaded if not already),
   153     In the invoke method, the library is checked to be loaded (and loaded if not already),
   154     the arguments are converted to C and pushed onto the C-stack, the function is called,
   154     the arguments are converted to C and pushed onto the C-stack, the function is called,
   155     and finally, the return value is converted back from C to a smalltalk object.
   155     and finally, the return value is converted back from C to a smalltalk object.
   156 
   156 
   157     The parser supports the call-syntax of various other smalltalk dialects:
   157     The parser supports the call-syntax of various other smalltalk dialects:
   158         Squeak / ST-X:
   158 	Squeak / ST-X:
   159             <cdecl:   [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName >
   159 	    <cdecl:   [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName >
   160             <apicall: [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName >
   160 	    <apicall: [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName >
   161 
   161 
   162         Dolphin:
   162 	Dolphin:
   163             <stdcall: [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN>
   163 	    <stdcall: [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN>
   164             <cdecl:   [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN>
   164 	    <cdecl:   [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN>
   165 
   165 
   166         ST/V:
   166 	ST/V:
   167             <api: functionName argType1 .. argTypeN returnType>
   167 	    <api: functionName argType1 .. argTypeN returnType>
   168             <ccall: functionName argType1 .. argTypeN returnType>
   168 	    <ccall: functionName argType1 .. argTypeN returnType>
   169             <ole: vFunctionIndex argType1 .. argTypeN returnType>
   169 	    <ole: vFunctionIndex argType1 .. argTypeN returnType>
   170 
   170 
   171         VisualWorks:
   171 	VisualWorks:
   172             <c: ...>
   172 	    <c: ...>
   173             <c: #define NAME value>
   173 	    <c: #define NAME value>
   174 "
   174 "
   175 !
   175 !
   176 
   176 
   177 example
   177 example
   178 "
   178 "