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