--- a/ExternalFunction.st Sun Oct 12 16:08:36 2003 +0200
+++ b/ExternalFunction.st Tue Oct 14 12:32:56 2003 +0200
@@ -38,77 +38,77 @@
convertST_to_C(stObj)
OBJ stObj;
{
- INT flags, nInst;
- OBJ *oP;
+ INT flags, nInst;
+ OBJ *oP;
- if (__isString(stObj) || __isSymbol(stObj)) {
- return (INT)(__stringVal(stObj));
- }
- if (__isByteArray(stObj)) {
- return (INT)(__ByteArrayInstPtr(stObj)->ba_element);
- }
- if (__isExternalBytes(stObj)) {
- return (INT)(__externalBytesAddress(stObj));
- }
- if (__isExternalAddress(stObj)) {
- return (INT)(__externalAddressVal(stObj));
- }
- if (__isExternalFunction(stObj)) {
- return (INT)(__externalFunctionVal(stObj));
- }
- if (__isSmallInteger(stObj)) {
- return (INT)(__intVal(stObj));
- }
- if (__isLargeInteger(stObj)) {
- return (INT)(__signedLongIntVal(stObj));
- }
- if (__isCharacter(stObj)) {
- return (INT)(__intVal(__characterVal(stObj)));
- }
- if (stObj == nil) {
- return 0;
- }
+ if (__isString(stObj) || __isSymbol(stObj)) {
+ return (INT)(__stringVal(stObj));
+ }
+ if (__isByteArray(stObj)) {
+ return (INT)(__ByteArrayInstPtr(stObj)->ba_element);
+ }
+ if (__isExternalBytes(stObj)) {
+ return (INT)(__externalBytesAddress(stObj));
+ }
+ if (__isExternalAddress(stObj)) {
+ return (INT)(__externalAddressVal(stObj));
+ }
+ if (__isExternalFunction(stObj)) {
+ return (INT)(__externalFunctionVal(stObj));
+ }
+ if (__isSmallInteger(stObj)) {
+ return (INT)(__intVal(stObj));
+ }
+ if (__isLargeInteger(stObj)) {
+ return (INT)(__signedLongIntVal(stObj));
+ }
+ if (__isCharacter(stObj)) {
+ return (INT)(__intVal(__characterVal(stObj)));
+ }
+ if (stObj == nil) {
+ return 0;
+ }
- if (__qClass(stObj) == @global(ShortFloat)) {
- return (INT)(__shortFloatVal(stObj));
- }
+ if (__qClass(stObj) == @global(ShortFloat)) {
+ return (INT)(__shortFloatVal(stObj));
+ }
- flags = __intVal(__ClassInstPtr(__qClass(stObj))->c_flags) & ARRAYMASK;
- nInst = __intVal(__ClassInstPtr(__qClass(stObj))->c_ninstvars);
- oP = (OBJ *)__InstPtr(stObj)->i_instvars[nInst];
+ flags = __intVal(__ClassInstPtr(__qClass(stObj))->c_flags) & ARRAYMASK;
+ nInst = __intVal(__ClassInstPtr(__qClass(stObj))->c_ninstvars);
+ oP = (OBJ *)__InstPtr(stObj)->i_instvars[nInst];
- if (flags & FLOATARRAY) {
- return (INT)(oP);
- }
- if (flags & DOUBLEARRAY) {
- return (INT)(oP);
- }
- if (flags & DOUBLEARRAY) {
- return (INT)(oP);
- }
- if (flags & BYTEARRAY) {
- return (INT)(oP);
- }
- if (flags & WORDARRAY) {
- return (INT)(oP);
- }
- if (flags & LONGARRAY) {
- return (INT)(oP);
- }
- if (flags & SWORDARRAY) {
- return (INT)(oP);
- }
- if (flags & SLONGARRAY) {
- return (INT)(oP);
- }
+ if (flags & FLOATARRAY) {
+ return (INT)(oP);
+ }
+ if (flags & DOUBLEARRAY) {
+ return (INT)(oP);
+ }
+ if (flags & DOUBLEARRAY) {
+ return (INT)(oP);
+ }
+ if (flags & BYTEARRAY) {
+ return (INT)(oP);
+ }
+ if (flags & WORDARRAY) {
+ return (INT)(oP);
+ }
+ if (flags & LONGARRAY) {
+ return (INT)(oP);
+ }
+ if (flags & SWORDARRAY) {
+ return (INT)(oP);
+ }
+ if (flags & SLONGARRAY) {
+ return (INT)(oP);
+ }
- if (stObj == true) {
- return 1;
- }
- if (stObj == false) {
- return 0;
- }
- return 0;
+ if (stObj == true) {
+ return 1;
+ }
+ if (stObj == false) {
+ return 0;
+ }
+ return 0;
}
%}
@@ -155,22 +155,22 @@
with the call / callWith: methods.
ST-arguments are converted to C as follows:
- ST class C argument
+ ST class C argument
------------------------------
- SmallInteger int
- LargeInteger int (must be 4-byte unsigned largeInteger)
- String char *
- Symbol char *
- Character int
- ExternalBytes char *
- ExternalAddress char *
+ SmallInteger int
+ LargeInteger int (must be 4-byte unsigned largeInteger)
+ String char *
+ Symbol char *
+ Character int
+ ExternalBytes char *
+ ExternalAddress char *
ExternalFunction char *
- FloatArray float *
- DoubleArray double *
- ByteArray char *
- ShortFloat float
- true 1
- false 0
+ FloatArray float *
+ DoubleArray double *
+ ByteArray char *
+ ShortFloat float
+ true 1
+ false 0
The returned value is converted to an unsigned integer (smallInteger or largeInteger).
@@ -187,11 +187,11 @@
mechanism.
[author:]
- Claus Gittinger
+ Claus Gittinger
[see also:]
- ExternalAddress ExternalBytes
- ( how to write primitive code :html: programming/primitive.html )
+ ExternalAddress ExternalBytes
+ ( how to write primitive code :html: programming/primitive.html )
"
!
@@ -208,7 +208,7 @@
f := handle getFunction:'function1'.
call it:
-
+
f callWith:999
"
! !
@@ -219,9 +219,9 @@
"create signals"
InvalidCustomFunctionSignal isNil ifTrue:[
- InvalidCustomFunctionSignal := ExecutionError newSignalMayProceed:true.
- InvalidCustomFunctionSignal nameClass:self message:#invalidCustomFunctionSignal.
- InvalidCustomFunctionSignal notifierString:'attempt to execute unknown custom function'.
+ InvalidCustomFunctionSignal := ExecutionError newSignalMayProceed:true.
+ InvalidCustomFunctionSignal nameClass:self message:#invalidCustomFunctionSignal.
+ InvalidCustomFunctionSignal notifierString:'attempt to execute unknown custom function'.
]
"Modified: 22.4.1996 / 18:08:55 / cg"
@@ -279,7 +279,7 @@
"call the custom function #nr with three arguments"
^ self callCustomFunction:nr
- withArguments:(Array with:arg1 with:arg2 with:arg3)
+ withArguments:(Array with:arg1 with:arg2 with:arg3)
"Modified: 22.4.1996 / 18:07:18 / cg"
!
@@ -298,33 +298,33 @@
called = false;
if (__isSmallInteger(nr) && __isArray(argArray)) {
- int nargs = __arraySize(argArray);
- int functionNr;
+ int nargs = __arraySize(argArray);
+ int functionNr;
- functionNr = __intVal(nr);
- if ((functionNr >= 0) && (functionNr < __stxNCustomFunctions__)) {
- /*
- * now, call the function; passing nargs and arg-vector
- */
- func = __stxCustomFunctions__[functionNr].func;
- if (func) {
- int ok;
+ functionNr = __intVal(nr);
+ if ((functionNr >= 0) && (functionNr < __stxNCustomFunctions__)) {
+ /*
+ * now, call the function; passing nargs and arg-vector
+ */
+ func = __stxCustomFunctions__[functionNr].func;
+ if (func) {
+ int ok;
- retVal = self;
- ok = (*func)(nargs, &retVal, __ArrayInstPtr(argArray)->a_element);
- if (ok) {
- RETURN (retVal);
- }
- called = true;
- }
- }
+ retVal = self;
+ ok = (*func)(nargs, &retVal, __ArrayInstPtr(argArray)->a_element);
+ if (ok) {
+ RETURN (retVal);
+ }
+ called = true;
+ }
+ }
}
%}.
called ifTrue:[
- "
- the customFunction returned 0 (failure)
- "
- ^ self primitiveFailed
+ "
+ the customFunction returned 0 (failure)
+ "
+ ^ self primitiveFailed
].
"
@@ -346,7 +346,7 @@
index := self indexOfCustomFunctionNamed:name.
index notNil ifTrue:[
- ^ self callCustomFunction:index withArguments:argArray
+ ^ self callCustomFunction:index withArguments:argArray
].
"
no such function exists
@@ -355,7 +355,7 @@
"
ExternalFunction callCustomFunctionNamed:'demoFunction0'
- withArguments:#()
+ withArguments:#()
"
"Modified: 22.4.1996 / 18:08:09 / cg"
@@ -371,15 +371,15 @@
#endif
if (__isString(functionName)) {
- char *nm;
- int i;
+ char *nm;
+ int i;
- nm = (char *)__stringVal(functionName);
- for (i=0; i < __stxNCustomFunctions__; i++) {
- if (strcmp(__stxCustomFunctions__[i].name, nm) == 0) {
- RETURN (__MKSMALLINT(i));
- }
- }
+ nm = (char *)__stringVal(functionName);
+ for (i=0; i < __stxNCustomFunctions__; i++) {
+ if (strcmp(__stxCustomFunctions__[i].name, nm) == 0) {
+ RETURN (__MKSMALLINT(i));
+ }
+ }
}
%}.
^ nil
@@ -433,8 +433,8 @@
func = (LINTFUNC) __INST(code_);
if (func) {
- retVal = (*func)();
- RETURN (__MKINT(retVal));
+ retVal = (*func)();
+ RETURN (__MKINT(retVal));
}
%}.
self primitiveFailed
@@ -453,8 +453,8 @@
func = (OBJFUNC) __INST(code_);
if (func) {
- retVal = (*func)();
- RETURN (retVal);
+ retVal = (*func)();
+ RETURN (retVal);
}
%}.
self primitiveFailed
@@ -473,8 +473,8 @@
func = (OBJFUNC) __INST(code_);
if (func) {
- retVal = (*func)(arg);
- RETURN (retVal);
+ retVal = (*func)(arg);
+ RETURN (retVal);
}
%}.
self primitiveFailed
@@ -493,8 +493,8 @@
func = (OBJFUNC) __INST(code_);
if (func) {
- retVal = (*func)(arg1, arg2);
- RETURN (retVal);
+ retVal = (*func)(arg1, arg2);
+ RETURN (retVal);
}
%}.
self primitiveFailed
@@ -509,12 +509,12 @@
"
%{
OBJFUNC func;
- INT retVal;
+ OBJ retVal;
func = (OBJFUNC) __INST(code_);
if (func) {
- retVal = (*func)(arg1, arg2, arg3);
- RETURN (retVal);
+ retVal = (*func)(arg1, arg2, arg3);
+ RETURN (retVal);
}
%}.
self primitiveFailed
@@ -537,8 +537,8 @@
func = (LINTFUNC) __INST(code_);
if (func) {
- retVal = (*func)(convertST_to_C(arg));
- RETURN (__MKINT(retVal));
+ retVal = (*func)(convertST_to_C(arg));
+ RETURN (__MKINT(retVal));
}
%}.
self primitiveFailed
@@ -561,8 +561,8 @@
func = (LINTFUNC) __INST(code_);
if (func) {
- retVal = (*func)(convertST_to_C(arg1), convertST_to_C(arg2));
- RETURN (__MKINT(retVal));
+ retVal = (*func)(convertST_to_C(arg1), convertST_to_C(arg2));
+ RETURN (__MKINT(retVal));
}
%}.
self primitiveFailed
@@ -585,8 +585,8 @@
func = (LINTFUNC) __INST(code_);
if (func) {
- retVal = (*func)(convertST_to_C(arg1), convertST_to_C(arg2), convertST_to_C(arg3));
- RETURN (__MKINT(retVal));
+ retVal = (*func)(convertST_to_C(arg1), convertST_to_C(arg2), convertST_to_C(arg3));
+ RETURN (__MKINT(retVal));
}
%}.
self primitiveFailed
@@ -687,7 +687,7 @@
func = (LINTFUNC) __INST(code_);
if (func) {
- if (__isFloat(aFloatArg)) {
+ if (__isFloat(aFloatArg)) {
arg = __floatVal(aFloatArg);
} else if (__isShortFloat(aFloatArg)) {
arg = (double)(__shortFloatVal(aFloatArg));
@@ -720,28 +720,28 @@
func = (LINTFUNC) __INST(code_);
if (func) {
- if (__isFloat(aFloatArg1)) {
- arg1 = __floatVal(aFloatArg1);
- } else if (__isShortFloat(aFloatArg1)) {
- arg1 = (double)(__shortFloatVal(aFloatArg1));
- } else {
- arg1 = (double)(__signedLongIntVal(aFloatArg1));
- }
- if (__isFloat(aFloatArg2)) {
- arg2 = __floatVal(aFloatArg2);
- } else if (__isShortFloat(aFloatArg2)) {
- arg2 = (double)(__shortFloatVal(aFloatArg2));
- } else {
- arg2 = (double)(__signedLongIntVal(aFloatArg2));
- }
- if (doubleFlag == true) {
- dfunc = (DOUBLEFUNC)func;
- dretVal = (*dfunc)(arg1, arg2);
- RETURN (__MKFLOAT(dretVal));
- } else {
- retVal = (*func)(arg1, arg2);
- RETURN (__MKINT(retVal));
- }
+ if (__isFloat(aFloatArg1)) {
+ arg1 = __floatVal(aFloatArg1);
+ } else if (__isShortFloat(aFloatArg1)) {
+ arg1 = (double)(__shortFloatVal(aFloatArg1));
+ } else {
+ arg1 = (double)(__signedLongIntVal(aFloatArg1));
+ }
+ if (__isFloat(aFloatArg2)) {
+ arg2 = __floatVal(aFloatArg2);
+ } else if (__isShortFloat(aFloatArg2)) {
+ arg2 = (double)(__shortFloatVal(aFloatArg2));
+ } else {
+ arg2 = (double)(__signedLongIntVal(aFloatArg2));
+ }
+ if (doubleFlag == true) {
+ dfunc = (DOUBLEFUNC)func;
+ dretVal = (*dfunc)(arg1, arg2);
+ RETURN (__MKFLOAT(dretVal));
+ } else {
+ retVal = (*func)(arg1, arg2);
+ RETURN (__MKINT(retVal));
+ }
}
%}.
self primitiveFailed
@@ -757,20 +757,20 @@
name isNil ifTrue:[^ super printOn:aStream].
aStream nextPutAll:self class name; nextPutAll:'(name: ''';
- nextPutAll:name; nextPutAll:''' address: '.
+ nextPutAll:name; nextPutAll:''' address: '.
addr := self code.
addr isNil ifTrue:[
- aStream nextPutAll:'** unloaded **'
+ aStream nextPutAll:'** unloaded **'
] ifFalse:[
- aStream nextPutAll:'0x';
- nextPutAll:(addr hexPrintString)
+ aStream nextPutAll:'0x';
+ nextPutAll:(addr hexPrintString)
].
moduleHandle notNil ifTrue:[
- aStream nextPutAll:' from: ''';
- nextPutAll:(moduleHandle pathName asFilename baseName);
- nextPutAll:''''.
+ aStream nextPutAll:' from: ''';
+ nextPutAll:(moduleHandle pathName asFilename baseName);
+ nextPutAll:''''.
].
aStream nextPutAll:')'
@@ -791,7 +791,7 @@
!ExternalFunction class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunction.st,v 1.19 2003-09-05 10:28:21 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunction.st,v 1.20 2003-10-14 10:32:56 cg Exp $'
! !
ExternalFunction initialize!