author | Claus Gittinger <cg@exept.de> |
Tue, 02 Apr 2019 10:50:28 +0200 | |
branch | jv |
changeset 24091 | 691c182c3105 |
parent 23547 | c69c97cec351 |
permissions | -rw-r--r-- |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3 |
All Rights Reserved |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
4 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
5 |
This software is furnished under a license and may be used |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
6 |
only in accordance with the terms of that license and with the |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
7 |
inclusion of the above copyright notice. This software may not |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
10 |
hereby transferred. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
11 |
" |
7257 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
20510 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
16 |
ExecutableFunction subclass:#ExternalFunction |
1542
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
17 |
instanceVariableNames:'name moduleHandle' |
1184
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
18 |
classVariableNames:'InvalidCustomFunctionSignal' |
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
19 |
poolDictionaries:'' |
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
20 |
category:'System-Support' |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
21 |
! |
3612 | 22 |
|
2880 | 23 |
!ExternalFunction primitiveDefinitions! |
24 |
%{ |
|
25 |
typedef INT (*LINTFUNC)(); |
|
26 |
%} |
|
27 |
! ! |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
28 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
29 |
!ExternalFunction primitiveFunctions! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
30 |
%{ |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
31 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
32 |
/* |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
33 |
* given an ST-object, make something useful for C |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
34 |
* cast it to an int |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
35 |
* |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
36 |
* CAVEAT: floats are not allowed. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
37 |
*/ |
2769 | 38 |
INT |
8534 | 39 |
convertST_to_C(stObj) |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
40 |
OBJ stObj; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
41 |
{ |
7665 | 42 |
INT flags, nInst; |
43 |
OBJ *oP; |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
44 |
|
7665 | 45 |
if (__isString(stObj) || __isSymbol(stObj)) { |
46 |
return (INT)(__stringVal(stObj)); |
|
47 |
} |
|
48 |
if (__isByteArray(stObj)) { |
|
49 |
return (INT)(__ByteArrayInstPtr(stObj)->ba_element); |
|
50 |
} |
|
51 |
if (__isExternalBytes(stObj)) { |
|
52 |
return (INT)(__externalBytesAddress(stObj)); |
|
53 |
} |
|
54 |
if (__isExternalAddress(stObj)) { |
|
55 |
return (INT)(__externalAddressVal(stObj)); |
|
56 |
} |
|
57 |
if (__isExternalFunction(stObj)) { |
|
58 |
return (INT)(__externalFunctionVal(stObj)); |
|
59 |
} |
|
60 |
if (__isSmallInteger(stObj)) { |
|
61 |
return (INT)(__intVal(stObj)); |
|
62 |
} |
|
63 |
if (__isLargeInteger(stObj)) { |
|
64 |
return (INT)(__signedLongIntVal(stObj)); |
|
65 |
} |
|
66 |
if (__isCharacter(stObj)) { |
|
67 |
return (INT)(__intVal(__characterVal(stObj))); |
|
68 |
} |
|
69 |
if (stObj == nil) { |
|
70 |
return 0; |
|
71 |
} |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
72 |
|
7665 | 73 |
if (__qClass(stObj) == @global(ShortFloat)) { |
74 |
return (INT)(__shortFloatVal(stObj)); |
|
75 |
} |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
76 |
|
7665 | 77 |
flags = __intVal(__ClassInstPtr(__qClass(stObj))->c_flags) & ARRAYMASK; |
78 |
nInst = __intVal(__ClassInstPtr(__qClass(stObj))->c_ninstvars); |
|
79 |
oP = (OBJ *)__InstPtr(stObj)->i_instvars[nInst]; |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
80 |
|
7665 | 81 |
if (flags & FLOATARRAY) { |
82 |
return (INT)(oP); |
|
83 |
} |
|
84 |
if (flags & DOUBLEARRAY) { |
|
85 |
return (INT)(oP); |
|
86 |
} |
|
87 |
if (flags & DOUBLEARRAY) { |
|
88 |
return (INT)(oP); |
|
89 |
} |
|
90 |
if (flags & BYTEARRAY) { |
|
91 |
return (INT)(oP); |
|
92 |
} |
|
93 |
if (flags & WORDARRAY) { |
|
94 |
return (INT)(oP); |
|
95 |
} |
|
96 |
if (flags & LONGARRAY) { |
|
97 |
return (INT)(oP); |
|
98 |
} |
|
99 |
if (flags & SWORDARRAY) { |
|
100 |
return (INT)(oP); |
|
101 |
} |
|
102 |
if (flags & SLONGARRAY) { |
|
103 |
return (INT)(oP); |
|
104 |
} |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
105 |
|
7665 | 106 |
if (stObj == true) { |
107 |
return 1; |
|
108 |
} |
|
109 |
if (stObj == false) { |
|
110 |
return 0; |
|
111 |
} |
|
112 |
return 0; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
113 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
114 |
|
8534 | 115 |
%} |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
116 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
117 |
|
3612 | 118 |
!ExternalFunction class methodsFor:'documentation'! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
119 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
120 |
copyright |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
121 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
122 |
COPYRIGHT (c) 1994 by Claus Gittinger |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
123 |
All Rights Reserved |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
124 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
125 |
This software is furnished under a license and may be used |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
126 |
only in accordance with the terms of that license and with the |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
127 |
inclusion of the above copyright notice. This software may not |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
128 |
be provided or otherwise made available to, or used by, any |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
129 |
other person. No title to or ownership of the software is |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
130 |
hereby transferred. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
131 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
132 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
133 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
134 |
documentation |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
135 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
136 |
Instances of this class represent external (non-Smalltalk) functions. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
137 |
|
9323 | 138 |
(Obsolete) Custom Functions: |
20957 | 139 |
This class also provides access to custom functions. |
140 |
These custom functions enable you to call c functions |
|
141 |
even if no stc compiler is available (they are kind of what user-primitives are in ST-80). |
|
142 |
You can register your own custom C-functions in a private main.c and relink ST/X from the binaries. |
|
143 |
(see the demo functions provided in main.c). |
|
144 |
Notice, that custom functions are ugly and inflexible. |
|
145 |
They are to be considered obsolete and support for them will vanish. |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
146 |
|
9323 | 147 |
If you have the stc compiler, we recommend using either inline primitive |
148 |
code or the new external function call interface which is based upon libffi. |
|
149 |
Both are easier to enter, compile, debug and maintain. |
|
1257 | 150 |
(especially, to maintain, since the primitive code is contained |
8534 | 151 |
in the classes source/object file - while custom functions are |
1257 | 152 |
external to the classLibraries). |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
153 |
|
8534 | 154 |
Non custom externalFunctions are created, when a non-ST shared library is loaded, |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
155 |
and returned by the ObjectFileHandles>>getFunction: method. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
156 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
157 |
The C functions contained in that lib are callable (instances of myself) |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
158 |
with the call / callWith: methods. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
159 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
160 |
ST-arguments are converted to C as follows: |
20957 | 161 |
ST class C argument |
162 |
------------------------------ |
|
163 |
SmallInteger int |
|
164 |
LargeInteger int (must be 4-byte unsigned largeInteger) |
|
165 |
String char * |
|
166 |
Symbol char * |
|
167 |
Character int |
|
168 |
ExternalBytes char * |
|
169 |
ExternalAddress char * |
|
170 |
ExternalFunction char * |
|
171 |
FloatArray float * |
|
172 |
DoubleArray double * |
|
173 |
ByteArray char * |
|
174 |
ShortFloat float |
|
175 |
true 1 |
|
176 |
false 0 |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
177 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
178 |
The returned value is converted to an unsigned integer (smallInteger or largeInteger). |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
179 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
180 |
Notice, that no doubles can be passed; the reason is that the calling |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
181 |
conventions (on stack, in registers, in FPU registers etc.) are so different among |
8534 | 182 |
machines (and even compilers), that a general solution is not possible (difficult) |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
183 |
to program here. To pass doubles, either use shortFloats, or pack them into a DoubleArray. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
184 |
For functions with up to 2 double arguments, specialized call methods are provided. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
185 |
Sorry for that inconvenience. |
8534 | 186 |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
187 |
|
8534 | 188 |
- This is still in construction and NOT yet published for |
9323 | 189 |
general use. For now, use inline C-code. |
1286 | 190 |
|
191 |
[author:] |
|
20957 | 192 |
Claus Gittinger |
1317 | 193 |
|
194 |
[see also:] |
|
20957 | 195 |
ExternalAddress ExternalBytes |
196 |
( how to write primitive code :html: programming/primitive.html ) |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
197 |
" |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
198 |
! |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
199 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
200 |
examples |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
201 |
" |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
202 |
see a sample demo c file in doc/coding/cModules; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
203 |
compile and link (shared) it to an object module. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
204 |
Load it into the system: |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
205 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
206 |
handle := ObjectFileLoader loadDynamicObject:'demo1.o'. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
207 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
208 |
get a C-function (an instance of ExternalFunction): |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
209 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
210 |
f := handle getFunction:'function1'. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
211 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
212 |
call it: |
8534 | 213 |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
214 |
f callWith:999 |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
215 |
" |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
216 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
217 |
|
3612 | 218 |
!ExternalFunction class methodsFor:'initialization'! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
219 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
220 |
initialize |
1257 | 221 |
"create signals" |
222 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
223 |
InvalidCustomFunctionSignal isNil ifTrue:[ |
7665 | 224 |
InvalidCustomFunctionSignal := ExecutionError newSignalMayProceed:true. |
225 |
InvalidCustomFunctionSignal nameClass:self message:#invalidCustomFunctionSignal. |
|
226 |
InvalidCustomFunctionSignal notifierString:'attempt to execute unknown custom function'. |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
227 |
] |
1257 | 228 |
|
229 |
"Modified: 22.4.1996 / 18:08:55 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
230 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
231 |
|
3612 | 232 |
!ExternalFunction class methodsFor:'Signal constants'! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
233 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
234 |
invalidCustomFunctionSignal |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
235 |
"return the signal raised when a non existent custom function is |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
236 |
called for." |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
237 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
238 |
^ InvalidCustomFunctionSignal |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
239 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
240 |
|
3612 | 241 |
!ExternalFunction class methodsFor:'calling custom functions'! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
242 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
243 |
callCustomFunction:nr |
19480 | 244 |
"call the custom function #nr without arguments. |
245 |
See main.c for examples." |
|
1257 | 246 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
247 |
^ self callCustomFunction:nr withArguments:#() |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
248 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
249 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
250 |
ExternalFunction callCustomFunction:0 |
8534 | 251 |
ExternalFunction callCustomFunction:999 |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
252 |
" |
1257 | 253 |
|
254 |
"Modified: 22.4.1996 / 18:06:52 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
255 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
256 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
257 |
callCustomFunction:nr with:arg |
19480 | 258 |
"call the custom function #nr with a single argument. |
259 |
See main.c for examples." |
|
1257 | 260 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
261 |
^ self callCustomFunction:nr withArguments:(Array with:arg) |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
262 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
263 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
264 |
ExternalFunction callCustomFunction:1 with:'hello world' |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
265 |
" |
1257 | 266 |
|
267 |
"Modified: 22.4.1996 / 18:07:03 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
268 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
269 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
270 |
callCustomFunction:nr with:arg1 with:arg2 |
19480 | 271 |
"call the custom function #nr with two arguments. |
272 |
See main.c for examples." |
|
1257 | 273 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
274 |
^ self callCustomFunction:nr withArguments:(Array with:arg1 with:arg2) |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
275 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
276 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
277 |
ExternalFunction callCustomFunction:2 with:(Float pi) with:1.0 |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
278 |
" |
1257 | 279 |
|
280 |
"Modified: 22.4.1996 / 18:07:11 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
281 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
282 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
283 |
callCustomFunction:nr with:arg1 with:arg2 with:arg3 |
19480 | 284 |
"call the custom function #nr with three arguments. |
285 |
See main.c for examples." |
|
1257 | 286 |
|
8534 | 287 |
^ self callCustomFunction:nr |
7665 | 288 |
withArguments:(Array with:arg1 with:arg2 with:arg3) |
1257 | 289 |
|
290 |
"Modified: 22.4.1996 / 18:07:18 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
291 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
292 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
293 |
callCustomFunction:nr withArguments:argArray |
19480 | 294 |
"call the custom function #nr with arguments from argArray. |
295 |
See main.c for examples." |
|
1257 | 296 |
|
19480 | 297 |
|retVal called errCode| |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
298 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
299 |
%{ |
917 | 300 |
#ifndef __stxNCustomFunctions__ |
856
d2c9f9ecedcf
renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
301 |
extern int __stxNCustomFunctions__; |
d2c9f9ecedcf
renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
302 |
extern CUSTOMFUNCTION __stxCustomFunctions__[]; |
917 | 303 |
#endif |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
304 |
int (* func)(); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
305 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
306 |
called = false; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
307 |
if (__isSmallInteger(nr) && __isArray(argArray)) { |
7665 | 308 |
int nargs = __arraySize(argArray); |
309 |
int functionNr; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
310 |
|
7665 | 311 |
functionNr = __intVal(nr); |
312 |
if ((functionNr >= 0) && (functionNr < __stxNCustomFunctions__)) { |
|
313 |
/* |
|
314 |
* now, call the function; passing nargs and arg-vector |
|
315 |
*/ |
|
316 |
func = __stxCustomFunctions__[functionNr].func; |
|
317 |
if (func) { |
|
318 |
int ok; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
319 |
|
7665 | 320 |
retVal = self; |
321 |
ok = (*func)(nargs, &retVal, __ArrayInstPtr(argArray)->a_element); |
|
19480 | 322 |
if (ok == 0) { |
7665 | 323 |
RETURN (retVal); |
324 |
} |
|
19480 | 325 |
errCode = __mkSmallInteger(ok); |
7665 | 326 |
called = true; |
327 |
} |
|
328 |
} |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
329 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
330 |
%}. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
331 |
called ifTrue:[ |
7665 | 332 |
" |
19480 | 333 |
the customFunction returned non-0 (failure) |
334 |
PRIM_OK 0 |
|
335 |
PRIM_FAIL -1 |
|
336 |
PRIM_ARGCOUNT -2 |
|
337 |
PRIM_ARGTYPE -3 |
|
7665 | 338 |
" |
19480 | 339 |
errCode == -2 ifTrue:[ |
340 |
^ self primitiveFailed:'argument count' |
|
341 |
]. |
|
342 |
errCode == -3 ifTrue:[ |
|
343 |
^ self primitiveFailed:'argument type' |
|
344 |
]. |
|
7665 | 345 |
^ self primitiveFailed |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
346 |
]. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
347 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
348 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
349 |
an invalid customFunction-nr was given, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
350 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
351 |
InvalidCustomFunctionSignal raise |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
352 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
353 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
354 |
ExternalFunction callCustomFunction:2 withArguments:#(1.0 1.0) |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
355 |
ExternalFunction callCustomFunction:999 withArguments:#(1.0 1.0) |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
356 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
357 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
358 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
359 |
callCustomFunctionNamed:name withArguments:argArray |
1257 | 360 |
"call a custom function by name with arguments from argArray" |
361 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
362 |
|index| |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
363 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
364 |
index := self indexOfCustomFunctionNamed:name. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
365 |
index notNil ifTrue:[ |
7665 | 366 |
^ self callCustomFunction:index withArguments:argArray |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
367 |
]. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
368 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
369 |
no such function exists |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
370 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
371 |
InvalidCustomFunctionSignal raise |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
372 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
373 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
374 |
ExternalFunction callCustomFunctionNamed:'demoFunction0' |
7665 | 375 |
withArguments:#() |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
376 |
" |
1257 | 377 |
|
378 |
"Modified: 22.4.1996 / 18:08:09 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
379 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
380 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
381 |
indexOfCustomFunctionNamed:functionName |
1257 | 382 |
"return the index of a named custom function" |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
383 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
384 |
%{ /* NOCONTEXT */ |
917 | 385 |
#ifndef __stxNCustomFunctions__ |
856
d2c9f9ecedcf
renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
386 |
extern int __stxNCustomFunctions__; |
d2c9f9ecedcf
renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
387 |
extern CUSTOMFUNCTION __stxCustomFunctions__[]; |
917 | 388 |
#endif |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
389 |
|
12484
7f0cc6e86a66
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9397
diff
changeset
|
390 |
if (__isStringLike(functionName)) { |
19480 | 391 |
char *nm; |
392 |
int i; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
393 |
|
19480 | 394 |
nm = (char *)__stringVal(functionName); |
395 |
for (i=0; i < __stxNCustomFunctions__; i++) { |
|
396 |
if (strcmp(__stxCustomFunctions__[i].name, nm) == 0) { |
|
397 |
RETURN (__mkSmallInteger(i)); |
|
398 |
} |
|
399 |
} |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
400 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
401 |
%}. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
402 |
^ nil |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
403 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
404 |
" |
8534 | 405 |
ExternalFunction indexOfCustomFunctionNamed:'demoFunction0' |
406 |
ExternalFunction indexOfCustomFunctionNamed:'fooBar' |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
407 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
408 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
409 |
|
3612 | 410 |
!ExternalFunction class methodsFor:'queries'! |
1184
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
411 |
|
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
412 |
isBuiltInClass |
1267 | 413 |
"return true if this class is known by the run-time-system. |
414 |
Here, true is returned for myself, false for subclasses." |
|
1184
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
415 |
|
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
416 |
^ self == ExternalFunction |
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
417 |
|
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
418 |
"Created: 16.4.1996 / 11:24:50 / cg" |
1267 | 419 |
"Modified: 23.4.1996 / 15:58:55 / cg" |
1184
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
420 |
! ! |
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
421 |
|
1542
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
422 |
!ExternalFunction methodsFor:'accessing'! |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
423 |
|
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
424 |
moduleHandle |
20510 | 425 |
"return the function's moduleHandle |
426 |
(nil if not loaded dynamically)" |
|
1542
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
427 |
|
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
428 |
^ moduleHandle |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
429 |
! |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
430 |
|
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
431 |
name |
20510 | 432 |
"return the function's name" |
1542
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
433 |
|
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
434 |
^ name |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
435 |
! ! |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
436 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
437 |
!ExternalFunction methodsFor:'function calling'! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
438 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
439 |
call |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
440 |
"call the underlying C function, passing no argument. |
8534 | 441 |
The return value is interpreted as an integer |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
442 |
(and must be converted to an externalBytes object, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
443 |
if it is a pointer to something). |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
444 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
445 |
DANGER alert: This is an unprotected low-level entry. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
446 |
Not for normal application usage. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
447 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
448 |
%{ |
2880 | 449 |
LINTFUNC func; |
2769 | 450 |
INT retVal; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
451 |
|
2880 | 452 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
453 |
if (func) { |
7665 | 454 |
retVal = (*func)(); |
455 |
RETURN (__MKINT(retVal)); |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
456 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
457 |
%}. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
458 |
self primitiveFailed |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
459 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
460 |
|
8594 | 461 |
callByRefWith:arg |
462 |
"call the underlying C function, passing a single argument by reference. |
|
463 |
The pointer of the argument is passed. Use this if you want to call a |
|
464 |
function with call-by-refernece semantics, like in fortran. |
|
465 |
The argument arg is converted to a corresponding C data type, |
|
466 |
as defined in the convertST_to_C() function. |
|
467 |
The return value is interpreted as an integer |
|
468 |
(and must be converted to an externalBytes object, |
|
469 |
if it is a pointer to something). |
|
470 |
||
471 |
DANGER alert: This is an unprotected low-level entry. |
|
472 |
Not for normal application usage. |
|
473 |
" |
|
474 |
%{ |
|
475 |
LINTFUNC func; |
|
476 |
INT retVal; |
|
477 |
INT cArg; |
|
478 |
||
479 |
func = (LINTFUNC) __INST(code_); |
|
480 |
if (func) { |
|
9323 | 481 |
cArg = convertST_to_C(arg); |
482 |
retVal = (*func)(&cArg); |
|
483 |
RETURN (__MKINT(retVal)); |
|
8594 | 484 |
} |
485 |
%}. |
|
486 |
self primitiveFailed |
|
487 |
! |
|
488 |
||
489 |
callByRefWith:arg with:arg2 |
|
490 |
"call the underlying C function, passing two args. |
|
491 |
The pointer of the arguments are passed. Use this if you want to call a |
|
492 |
function with call-by-refernece semantics, like in fortran. |
|
493 |
The arguments are converted to a corresponding C data type, |
|
494 |
as defined in the convertST_to_C() function. |
|
495 |
The return value is interpreted as an integer |
|
496 |
(and must be converted to an externalBytes object, |
|
497 |
if it is a pointer to something). |
|
498 |
||
499 |
DANGER alert: This is an unprotected low-level entry. |
|
500 |
Not for normal application usage. |
|
501 |
" |
|
502 |
%{ |
|
503 |
LINTFUNC func; |
|
504 |
INT retVal; |
|
505 |
INT cArg, cArg2; |
|
506 |
||
507 |
func = (LINTFUNC) __INST(code_); |
|
508 |
if (func) { |
|
9323 | 509 |
cArg = convertST_to_C(arg); |
510 |
cArg2 = convertST_to_C(arg2); |
|
511 |
retVal = (*func)(&cArg, &cArg2); |
|
512 |
RETURN (__MKINT(retVal)); |
|
8594 | 513 |
} |
514 |
%}. |
|
515 |
self primitiveFailed |
|
516 |
! |
|
517 |
||
518 |
callByRefWith:arg with:arg2 with:arg3 |
|
519 |
"call the underlying C function, passing three args. |
|
520 |
The pointer of the arguments are passed. Use this if you want to call a |
|
521 |
function with call-by-refernece semantics, like in fortran. |
|
522 |
The arguments are converted to a corresponding C data type, |
|
523 |
as defined in the convertST_to_C() function. |
|
524 |
The return value is interpreted as an integer |
|
525 |
(and must be converted to an externalBytes object, |
|
526 |
if it is a pointer to something). |
|
527 |
||
528 |
DANGER alert: This is an unprotected low-level entry. |
|
529 |
Not for normal application usage. |
|
530 |
" |
|
531 |
%{ |
|
532 |
LINTFUNC func; |
|
533 |
INT retVal; |
|
534 |
INT cArg, cArg2, cArg3; |
|
535 |
||
536 |
func = (LINTFUNC) __INST(code_); |
|
537 |
if (func) { |
|
9323 | 538 |
cArg = convertST_to_C(arg); |
539 |
cArg2 = convertST_to_C(arg2); |
|
540 |
cArg3 = convertST_to_C(arg3); |
|
541 |
retVal = (*func)(&cArg, &cArg2, &cArg3); |
|
542 |
RETURN (__MKINT(retVal)); |
|
8594 | 543 |
} |
544 |
%}. |
|
545 |
self primitiveFailed |
|
546 |
! |
|
547 |
||
548 |
callByRefWithArguments:argArray |
|
549 |
"call the underlying C function, passing up to 10 arguments by reference. |
|
550 |
The arguments are converted to a corresponding C data type, |
|
551 |
as defined in the convertST_to_C() function. |
|
552 |
The return value is interpreted as an integer |
|
553 |
(and must be converted to an externalBytes object, |
|
554 |
if it is a pointer to something). |
|
555 |
||
556 |
DANGER alert: This is an unprotected low-level entry. |
|
557 |
Not for normal application usage. |
|
558 |
" |
|
559 |
%{ |
|
560 |
LINTFUNC func; |
|
561 |
# define NUMARGS 10 |
|
562 |
INT args[NUMARGS]; |
|
563 |
INT retVal; |
|
564 |
OBJ *ap; |
|
565 |
INT convertST_to_C(); |
|
566 |
||
567 |
func = (LINTFUNC) __INST(code_); |
|
568 |
if (func && __isArray(argArray)) { |
|
9323 | 569 |
int n = __arraySize(argArray); |
570 |
int i; |
|
8594 | 571 |
|
9323 | 572 |
if (n <= 10) { |
573 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
574 |
for (i=0; i<NUMARGS; i++) { |
|
575 |
args[i] = convertST_to_C(*ap++); |
|
576 |
} |
|
577 |
} |
|
578 |
switch (n) { |
|
579 |
case 0: |
|
580 |
retVal = (*func)(); |
|
581 |
break; |
|
582 |
case 1: |
|
583 |
retVal = (*func)(&args[0]); |
|
584 |
break; |
|
585 |
case 2: |
|
586 |
retVal = (*func)(&args[0], &args[1]); |
|
587 |
break; |
|
588 |
case 3: |
|
589 |
retVal = (*func)(&args[0], &args[1], &args[2]); |
|
590 |
break; |
|
591 |
case 4: |
|
592 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3]); |
|
593 |
break; |
|
594 |
case 5: |
|
595 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
596 |
&args[4]); |
|
597 |
break; |
|
598 |
case 6: |
|
599 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
600 |
&args[4], &args[5]); |
|
601 |
break; |
|
602 |
case 7: |
|
603 |
retVal = (*func)(&args[0], &args[1],& args[2], &args[3], |
|
604 |
&args[4], &args[5], &args[6]); |
|
605 |
break; |
|
606 |
case 8: |
|
607 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
608 |
&args[4], &args[5], &args[6], &args[7]); |
|
609 |
break; |
|
610 |
case 9: |
|
611 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
612 |
&args[4], &args[5], &args[6], &args[7], |
|
613 |
&args[8]); |
|
614 |
break; |
|
615 |
case 10: |
|
616 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
617 |
&args[4], &args[5], &args[6], &args[7], |
|
618 |
&args[8], &args[9]); |
|
619 |
break; |
|
620 |
default: |
|
621 |
goto err; |
|
622 |
} |
|
623 |
RETURN (__MKINT(retVal)); |
|
8594 | 624 |
} |
625 |
err: ; |
|
626 |
%}. |
|
627 |
self primitiveFailed |
|
628 |
! |
|
629 |
||
5164 | 630 |
callO |
631 |
"call the underlying C function, passing no argument. |
|
632 |
The return value must be a valid object. |
|
633 |
||
634 |
DANGER alert: This is an unprotected low-level entry. |
|
635 |
Not for normal application usage. |
|
636 |
" |
|
637 |
%{ |
|
638 |
OBJFUNC func; |
|
639 |
OBJ retVal; |
|
640 |
||
641 |
func = (OBJFUNC) __INST(code_); |
|
642 |
if (func) { |
|
7665 | 643 |
retVal = (*func)(); |
644 |
RETURN (retVal); |
|
5164 | 645 |
} |
646 |
%}. |
|
647 |
self primitiveFailed |
|
648 |
! |
|
649 |
||
650 |
callOWith:arg |
|
651 |
"call the underlying C function, passing a single object argument. |
|
8534 | 652 |
The return value must be a valid object. |
5164 | 653 |
|
654 |
DANGER alert: This is an unprotected low-level entry. |
|
655 |
Not for normal application usage. |
|
656 |
" |
|
657 |
%{ |
|
658 |
OBJFUNC func; |
|
659 |
OBJ retVal; |
|
660 |
||
661 |
func = (OBJFUNC) __INST(code_); |
|
662 |
if (func) { |
|
7665 | 663 |
retVal = (*func)(arg); |
664 |
RETURN (retVal); |
|
5164 | 665 |
} |
666 |
%}. |
|
667 |
self primitiveFailed |
|
668 |
! |
|
669 |
||
670 |
callOWith:arg1 with:arg2 |
|
671 |
"call the underlying C function, passing two args. |
|
8534 | 672 |
The return value must be a valid object. |
5164 | 673 |
|
674 |
DANGER alert: This is an unprotected low-level entry. |
|
675 |
Not for normal application usage. |
|
676 |
" |
|
677 |
%{ |
|
678 |
OBJFUNC func; |
|
679 |
OBJ retVal; |
|
680 |
||
681 |
func = (OBJFUNC) __INST(code_); |
|
682 |
if (func) { |
|
7665 | 683 |
retVal = (*func)(arg1, arg2); |
684 |
RETURN (retVal); |
|
5164 | 685 |
} |
686 |
%}. |
|
687 |
self primitiveFailed |
|
688 |
! |
|
689 |
||
690 |
callOWith:arg1 with:arg2 with:arg3 |
|
691 |
"call the underlying C function, passing three args. |
|
8534 | 692 |
The return value must be a valid object. |
5164 | 693 |
|
694 |
DANGER alert: This is an unprotected low-level entry. |
|
695 |
Not for normal application usage. |
|
696 |
" |
|
697 |
%{ |
|
698 |
OBJFUNC func; |
|
7665 | 699 |
OBJ retVal; |
5164 | 700 |
|
701 |
func = (OBJFUNC) __INST(code_); |
|
702 |
if (func) { |
|
7665 | 703 |
retVal = (*func)(arg1, arg2, arg3); |
704 |
RETURN (retVal); |
|
5164 | 705 |
} |
706 |
%}. |
|
707 |
self primitiveFailed |
|
708 |
! |
|
709 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
710 |
callWith:arg |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
711 |
"call the underlying C function, passing a single argument. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
712 |
The argument arg is converted to a corresponding C data type, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
713 |
as defined in the convertST_to_C() function. |
8534 | 714 |
The return value is interpreted as an integer |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
715 |
(and must be converted to an externalBytes object, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
716 |
if it is a pointer to something). |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
717 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
718 |
DANGER alert: This is an unprotected low-level entry. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
719 |
Not for normal application usage. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
720 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
721 |
%{ |
2880 | 722 |
LINTFUNC func; |
2769 | 723 |
INT retVal; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
724 |
|
2880 | 725 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
726 |
if (func) { |
7665 | 727 |
retVal = (*func)(convertST_to_C(arg)); |
728 |
RETURN (__MKINT(retVal)); |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
729 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
730 |
%}. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
731 |
self primitiveFailed |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
732 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
733 |
|
3612 | 734 |
callWith:arg1 with:arg2 |
735 |
"call the underlying C function, passing two args. |
|
736 |
The arguments are converted to a corresponding C data type, |
|
737 |
as defined in the convertST_to_C() function. |
|
8534 | 738 |
The return value is interpreted as an integer |
3612 | 739 |
(and must be converted to an externalBytes object, |
740 |
if it is a pointer to something). |
|
741 |
||
742 |
DANGER alert: This is an unprotected low-level entry. |
|
743 |
Not for normal application usage. |
|
744 |
" |
|
745 |
%{ |
|
746 |
LINTFUNC func; |
|
747 |
INT retVal; |
|
748 |
||
749 |
func = (LINTFUNC) __INST(code_); |
|
750 |
if (func) { |
|
7665 | 751 |
retVal = (*func)(convertST_to_C(arg1), convertST_to_C(arg2)); |
752 |
RETURN (__MKINT(retVal)); |
|
3612 | 753 |
} |
754 |
%}. |
|
755 |
self primitiveFailed |
|
756 |
! |
|
757 |
||
758 |
callWith:arg1 with:arg2 with:arg3 |
|
759 |
"call the underlying C function, passing three args. |
|
760 |
The arguments are converted to a corresponding C data type, |
|
761 |
as defined in the convertST_to_C() function. |
|
8534 | 762 |
The return value is interpreted as an integer |
3612 | 763 |
(and must be converted to an externalBytes object, |
764 |
if it is a pointer to something). |
|
765 |
||
766 |
DANGER alert: This is an unprotected low-level entry. |
|
767 |
Not for normal application usage. |
|
768 |
" |
|
769 |
%{ |
|
770 |
LINTFUNC func; |
|
771 |
INT retVal; |
|
772 |
||
773 |
func = (LINTFUNC) __INST(code_); |
|
774 |
if (func) { |
|
7665 | 775 |
retVal = (*func)(convertST_to_C(arg1), convertST_to_C(arg2), convertST_to_C(arg3)); |
776 |
RETURN (__MKINT(retVal)); |
|
3612 | 777 |
} |
778 |
%}. |
|
779 |
self primitiveFailed |
|
780 |
! |
|
781 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
782 |
callWithArguments:argArray |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
783 |
"call the underlying C function, passing up to 10 arguments. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
784 |
The arguments are converted to a corresponding C data type, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
785 |
as defined in the convertST_to_C() function. |
8534 | 786 |
The return value is interpreted as an integer |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
787 |
(and must be converted to an externalBytes object, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
788 |
if it is a pointer to something). |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
789 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
790 |
DANGER alert: This is an unprotected low-level entry. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
791 |
Not for normal application usage. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
792 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
793 |
%{ |
2880 | 794 |
LINTFUNC func; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
795 |
# define NUMARGS 10 |
2880 | 796 |
INT args[NUMARGS]; |
797 |
INT retVal; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
798 |
OBJ *ap; |
2880 | 799 |
INT convertST_to_C(); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
800 |
|
2880 | 801 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
802 |
if (func && __isArray(argArray)) { |
1133 | 803 |
int n = __arraySize(argArray); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
804 |
int i; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
805 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
806 |
if (n <= 10) { |
1133 | 807 |
ap = __ArrayInstPtr(argArray)->a_element; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
808 |
for (i=0; i<NUMARGS; i++) { |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
809 |
args[i] = convertST_to_C(*ap++); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
810 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
811 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
812 |
switch (n) { |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
813 |
case 0: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
814 |
retVal = (*func)(); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
815 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
816 |
case 1: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
817 |
retVal = (*func)(args[0]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
818 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
819 |
case 2: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
820 |
retVal = (*func)(args[0], args[1]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
821 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
822 |
case 3: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
823 |
retVal = (*func)(args[0], args[1], args[2]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
824 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
825 |
case 4: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
826 |
retVal = (*func)(args[0], args[1], args[2], args[3]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
827 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
828 |
case 5: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
829 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
830 |
args[4]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
831 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
832 |
case 6: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
833 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
834 |
args[4], args[5]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
835 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
836 |
case 7: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
837 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
838 |
args[4], args[5], args[6]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
839 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
840 |
case 8: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
841 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
842 |
args[4], args[5], args[6], args[7]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
843 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
844 |
case 9: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
845 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
846 |
args[4], args[5], args[6], args[7], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
847 |
args[8]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
848 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
849 |
case 10: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
850 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
851 |
args[4], args[5], args[6], args[7], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
852 |
args[8], args[9]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
853 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
854 |
default: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
855 |
goto err; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
856 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
857 |
RETURN (__MKINT(retVal)); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
858 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
859 |
err: ; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
860 |
%}. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
861 |
self primitiveFailed |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
862 |
! |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
863 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
864 |
callWithDouble:aFloatArg returnsDouble:doubleFlag |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
865 |
"call the underlying C function, passing a single double argument. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
866 |
The returnsDouble flag specifies if the returnValue is a double; if false, |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
867 |
an integer returnValue is assumed." |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
868 |
%{ |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
869 |
typedef double (*DOUBLEFUNC)(); |
2880 | 870 |
LINTFUNC func; |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
871 |
DOUBLEFUNC dfunc; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
872 |
double arg, dretVal; |
2880 | 873 |
INT retVal; |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
874 |
|
2880 | 875 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
876 |
if (func) { |
7665 | 877 |
if (__isFloat(aFloatArg)) { |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
878 |
arg = __floatVal(aFloatArg); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
879 |
} else if (__isShortFloat(aFloatArg)) { |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
880 |
arg = (double)(__shortFloatVal(aFloatArg)); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
881 |
} else { |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
882 |
arg = (double)(__signedLongIntVal(aFloatArg)); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
883 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
884 |
if (doubleFlag == true) { |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
885 |
dfunc = (DOUBLEFUNC)func; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
886 |
dretVal = (*dfunc)(arg); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
887 |
RETURN (__MKFLOAT(dretVal)); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
888 |
} else { |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
889 |
retVal = (*func)(arg); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
890 |
RETURN (__MKINT(retVal)); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
891 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
892 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
893 |
%}. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
894 |
self primitiveFailed |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
895 |
! |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
896 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
897 |
callWithDouble:aFloatArg1 withDouble:aFloatArg2 returnsDouble:doubleFlag |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
898 |
"call the underlying C function, passing two double arguments. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
899 |
The returnsDouble flag specifies if the returnValue is a double; if false, |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
900 |
an integer returnValue is assumed." |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
901 |
%{ |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
902 |
typedef double (*DOUBLEFUNC)(); |
2880 | 903 |
LINTFUNC func; |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
904 |
DOUBLEFUNC dfunc; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
905 |
double arg1, arg2, dretVal; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
906 |
int retVal; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
907 |
|
2880 | 908 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
909 |
if (func) { |
7665 | 910 |
if (__isFloat(aFloatArg1)) { |
911 |
arg1 = __floatVal(aFloatArg1); |
|
912 |
} else if (__isShortFloat(aFloatArg1)) { |
|
913 |
arg1 = (double)(__shortFloatVal(aFloatArg1)); |
|
914 |
} else { |
|
915 |
arg1 = (double)(__signedLongIntVal(aFloatArg1)); |
|
916 |
} |
|
917 |
if (__isFloat(aFloatArg2)) { |
|
918 |
arg2 = __floatVal(aFloatArg2); |
|
919 |
} else if (__isShortFloat(aFloatArg2)) { |
|
920 |
arg2 = (double)(__shortFloatVal(aFloatArg2)); |
|
921 |
} else { |
|
922 |
arg2 = (double)(__signedLongIntVal(aFloatArg2)); |
|
923 |
} |
|
924 |
if (doubleFlag == true) { |
|
925 |
dfunc = (DOUBLEFUNC)func; |
|
926 |
dretVal = (*dfunc)(arg1, arg2); |
|
927 |
RETURN (__MKFLOAT(dretVal)); |
|
928 |
} else { |
|
929 |
retVal = (*func)(arg1, arg2); |
|
930 |
RETURN (__MKINT(retVal)); |
|
931 |
} |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
932 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
933 |
%}. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
934 |
self primitiveFailed |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
935 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
936 |
|
1547 | 937 |
!ExternalFunction methodsFor:'printing & storing'! |
938 |
||
939 |
printOn:aStream |
|
940 |
"append a printed representation of the receiver to aStream" |
|
941 |
||
942 |
|addr| |
|
943 |
||
944 |
name isNil ifTrue:[^ super printOn:aStream]. |
|
945 |
||
946 |
aStream nextPutAll:self class name; nextPutAll:'(name: '''; |
|
7665 | 947 |
nextPutAll:name; nextPutAll:''' address: '. |
1547 | 948 |
|
949 |
addr := self code. |
|
950 |
addr isNil ifTrue:[ |
|
7665 | 951 |
aStream nextPutAll:'** unloaded **' |
1547 | 952 |
] ifFalse:[ |
7665 | 953 |
aStream nextPutAll:'0x'; |
954 |
nextPutAll:(addr hexPrintString) |
|
1547 | 955 |
]. |
956 |
||
957 |
moduleHandle notNil ifTrue:[ |
|
8534 | 958 |
aStream nextPutAll:' from: '''; |
7665 | 959 |
nextPutAll:(moduleHandle pathName asFilename baseName); |
960 |
nextPutAll:''''. |
|
1547 | 961 |
]. |
962 |
||
963 |
aStream nextPutAll:')' |
|
964 |
||
965 |
"Modified: 12.7.1996 / 23:31:49 / cg" |
|
966 |
! ! |
|
967 |
||
7257 | 968 |
!ExternalFunction methodsFor:'private-loader access'! |
1547 | 969 |
|
9395
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
970 |
invalidate |
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
971 |
super invalidate. |
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
972 |
moduleHandle := nil. |
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
973 |
! |
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
974 |
|
9397 | 975 |
setModuleHandle:aHandle |
976 |
"set the moduleHandle. |
|
977 |
This is a private interface for the objectFileLoader; not for public use." |
|
978 |
||
979 |
moduleHandle := aHandle |
|
980 |
! |
|
981 |
||
1547 | 982 |
setName:aString moduleHandle:aHandle |
983 |
"set the name & moduleHandle. |
|
984 |
This is a private interface for the objectFileLoader; not for public use." |
|
985 |
||
986 |
name := aString. |
|
987 |
moduleHandle := aHandle |
|
988 |
! ! |
|
989 |
||
3612 | 990 |
!ExternalFunction class methodsFor:'documentation'! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
991 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
992 |
version |
19480 | 993 |
^ '$Header$' |
12484
7f0cc6e86a66
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9397
diff
changeset
|
994 |
! |
7f0cc6e86a66
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9397
diff
changeset
|
995 |
|
7f0cc6e86a66
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9397
diff
changeset
|
996 |
version_CVS |
19480 | 997 |
^ '$Header$' |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
998 |
! ! |
7257 | 999 |
|
20510 | 1000 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1001 |
ExternalFunction initialize! |