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