author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 29 Mar 2016 08:38:24 +0100 | |
branch | jv |
changeset 19496 | 7613c0fb5f3c |
parent 18011 | deb0c3355881 |
parent 19480 | dedfb6c4bc16 |
child 20579 | 9add81aadb7a |
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 |
19480 | 242 |
"call the custom function #nr without arguments. |
243 |
See main.c for examples." |
|
1257 | 244 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
245 |
^ self callCustomFunction:nr withArguments:#() |
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 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
248 |
ExternalFunction callCustomFunction:0 |
8534 | 249 |
ExternalFunction callCustomFunction:999 |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
250 |
" |
1257 | 251 |
|
252 |
"Modified: 22.4.1996 / 18:06:52 / cg" |
|
848
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 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
255 |
callCustomFunction:nr with:arg |
19480 | 256 |
"call the custom function #nr with a single argument. |
257 |
See main.c for examples." |
|
1257 | 258 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
259 |
^ self callCustomFunction:nr withArguments:(Array with:arg) |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
260 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
261 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
262 |
ExternalFunction callCustomFunction:1 with:'hello world' |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
263 |
" |
1257 | 264 |
|
265 |
"Modified: 22.4.1996 / 18:07:03 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
266 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
267 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
268 |
callCustomFunction:nr with:arg1 with:arg2 |
19480 | 269 |
"call the custom function #nr with two arguments. |
270 |
See main.c for examples." |
|
1257 | 271 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
272 |
^ self callCustomFunction:nr withArguments:(Array with:arg1 with:arg2) |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
273 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
274 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
275 |
ExternalFunction callCustomFunction:2 with:(Float pi) with:1.0 |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
276 |
" |
1257 | 277 |
|
278 |
"Modified: 22.4.1996 / 18:07:11 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
279 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
280 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
281 |
callCustomFunction:nr with:arg1 with:arg2 with:arg3 |
19480 | 282 |
"call the custom function #nr with three arguments. |
283 |
See main.c for examples." |
|
1257 | 284 |
|
8534 | 285 |
^ self callCustomFunction:nr |
7665 | 286 |
withArguments:(Array with:arg1 with:arg2 with:arg3) |
1257 | 287 |
|
288 |
"Modified: 22.4.1996 / 18:07:18 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
289 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
290 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
291 |
callCustomFunction:nr withArguments:argArray |
19480 | 292 |
"call the custom function #nr with arguments from argArray. |
293 |
See main.c for examples." |
|
1257 | 294 |
|
19480 | 295 |
|retVal called errCode| |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
296 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
297 |
%{ |
917 | 298 |
#ifndef __stxNCustomFunctions__ |
856
d2c9f9ecedcf
renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
299 |
extern int __stxNCustomFunctions__; |
d2c9f9ecedcf
renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
300 |
extern CUSTOMFUNCTION __stxCustomFunctions__[]; |
917 | 301 |
#endif |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
302 |
int (* func)(); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
303 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
304 |
called = false; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
305 |
if (__isSmallInteger(nr) && __isArray(argArray)) { |
7665 | 306 |
int nargs = __arraySize(argArray); |
307 |
int functionNr; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
308 |
|
7665 | 309 |
functionNr = __intVal(nr); |
310 |
if ((functionNr >= 0) && (functionNr < __stxNCustomFunctions__)) { |
|
311 |
/* |
|
312 |
* now, call the function; passing nargs and arg-vector |
|
313 |
*/ |
|
314 |
func = __stxCustomFunctions__[functionNr].func; |
|
315 |
if (func) { |
|
316 |
int ok; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
317 |
|
7665 | 318 |
retVal = self; |
319 |
ok = (*func)(nargs, &retVal, __ArrayInstPtr(argArray)->a_element); |
|
19480 | 320 |
if (ok == 0) { |
7665 | 321 |
RETURN (retVal); |
322 |
} |
|
19480 | 323 |
errCode = __mkSmallInteger(ok); |
7665 | 324 |
called = true; |
325 |
} |
|
326 |
} |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
327 |
} |
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 |
called ifTrue:[ |
7665 | 330 |
" |
19480 | 331 |
the customFunction returned non-0 (failure) |
332 |
PRIM_OK 0 |
|
333 |
PRIM_FAIL -1 |
|
334 |
PRIM_ARGCOUNT -2 |
|
335 |
PRIM_ARGTYPE -3 |
|
7665 | 336 |
" |
19480 | 337 |
errCode == -2 ifTrue:[ |
338 |
^ self primitiveFailed:'argument count' |
|
339 |
]. |
|
340 |
errCode == -3 ifTrue:[ |
|
341 |
^ self primitiveFailed:'argument type' |
|
342 |
]. |
|
7665 | 343 |
^ self primitiveFailed |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
344 |
]. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
345 |
|
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 |
an invalid customFunction-nr was given, |
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 |
InvalidCustomFunctionSignal raise |
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 |
ExternalFunction callCustomFunction:2 withArguments:#(1.0 1.0) |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
353 |
ExternalFunction callCustomFunction:999 withArguments:#(1.0 1.0) |
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 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
357 |
callCustomFunctionNamed:name withArguments:argArray |
1257 | 358 |
"call a custom function by name with arguments from argArray" |
359 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
360 |
|index| |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
361 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
362 |
index := self indexOfCustomFunctionNamed:name. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
363 |
index notNil ifTrue:[ |
7665 | 364 |
^ self callCustomFunction:index withArguments:argArray |
848
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 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
367 |
no such function exists |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
368 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
369 |
InvalidCustomFunctionSignal raise |
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 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
372 |
ExternalFunction callCustomFunctionNamed:'demoFunction0' |
7665 | 373 |
withArguments:#() |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
374 |
" |
1257 | 375 |
|
376 |
"Modified: 22.4.1996 / 18:08:09 / cg" |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
377 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
378 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
379 |
indexOfCustomFunctionNamed:functionName |
1257 | 380 |
"return the index of a named custom function" |
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 |
%{ /* NOCONTEXT */ |
917 | 383 |
#ifndef __stxNCustomFunctions__ |
856
d2c9f9ecedcf
renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
384 |
extern int __stxNCustomFunctions__; |
d2c9f9ecedcf
renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
385 |
extern CUSTOMFUNCTION __stxCustomFunctions__[]; |
917 | 386 |
#endif |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
387 |
|
12484
7f0cc6e86a66
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9397
diff
changeset
|
388 |
if (__isStringLike(functionName)) { |
19480 | 389 |
char *nm; |
390 |
int i; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
391 |
|
19480 | 392 |
nm = (char *)__stringVal(functionName); |
393 |
for (i=0; i < __stxNCustomFunctions__; i++) { |
|
394 |
if (strcmp(__stxCustomFunctions__[i].name, nm) == 0) { |
|
395 |
RETURN (__mkSmallInteger(i)); |
|
396 |
} |
|
397 |
} |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
398 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
399 |
%}. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
400 |
^ nil |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
401 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
402 |
" |
8534 | 403 |
ExternalFunction indexOfCustomFunctionNamed:'demoFunction0' |
404 |
ExternalFunction indexOfCustomFunctionNamed:'fooBar' |
|
848
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 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
407 |
|
3612 | 408 |
!ExternalFunction class methodsFor:'queries'! |
1184
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
409 |
|
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
410 |
isBuiltInClass |
1267 | 411 |
"return true if this class is known by the run-time-system. |
412 |
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
|
413 |
|
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
414 |
^ self == ExternalFunction |
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
415 |
|
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
416 |
"Created: 16.4.1996 / 11:24:50 / cg" |
1267 | 417 |
"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
|
418 |
! ! |
e15a6702c812
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
419 |
|
1542
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
420 |
!ExternalFunction methodsFor:'accessing'! |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
421 |
|
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
422 |
moduleHandle |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
423 |
"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
|
424 |
|
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
425 |
^ moduleHandle |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
426 |
! |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
427 |
|
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
428 |
name |
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
429 |
"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
|
430 |
|
cdcf4ad7556f
need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
431 |
^ name |
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 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
434 |
!ExternalFunction methodsFor:'function calling'! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
435 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
436 |
call |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
437 |
"call the underlying C function, passing no argument. |
8534 | 438 |
The return value is interpreted as an integer |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
439 |
(and must be converted to an externalBytes object, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
440 |
if it is a pointer to something). |
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 |
DANGER alert: This is an unprotected low-level entry. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
443 |
Not for normal application usage. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
444 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
445 |
%{ |
2880 | 446 |
LINTFUNC func; |
2769 | 447 |
INT retVal; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
448 |
|
2880 | 449 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
450 |
if (func) { |
7665 | 451 |
retVal = (*func)(); |
452 |
RETURN (__MKINT(retVal)); |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
453 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
454 |
%}. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
455 |
self primitiveFailed |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
456 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
457 |
|
8594 | 458 |
callByRefWith:arg |
459 |
"call the underlying C function, passing a single argument by reference. |
|
460 |
The pointer of the argument is passed. Use this if you want to call a |
|
461 |
function with call-by-refernece semantics, like in fortran. |
|
462 |
The argument arg is converted to a corresponding C data type, |
|
463 |
as defined in the convertST_to_C() function. |
|
464 |
The return value is interpreted as an integer |
|
465 |
(and must be converted to an externalBytes object, |
|
466 |
if it is a pointer to something). |
|
467 |
||
468 |
DANGER alert: This is an unprotected low-level entry. |
|
469 |
Not for normal application usage. |
|
470 |
" |
|
471 |
%{ |
|
472 |
LINTFUNC func; |
|
473 |
INT retVal; |
|
474 |
INT cArg; |
|
475 |
||
476 |
func = (LINTFUNC) __INST(code_); |
|
477 |
if (func) { |
|
9323 | 478 |
cArg = convertST_to_C(arg); |
479 |
retVal = (*func)(&cArg); |
|
480 |
RETURN (__MKINT(retVal)); |
|
8594 | 481 |
} |
482 |
%}. |
|
483 |
self primitiveFailed |
|
484 |
! |
|
485 |
||
486 |
callByRefWith:arg with:arg2 |
|
487 |
"call the underlying C function, passing two args. |
|
488 |
The pointer of the arguments are passed. Use this if you want to call a |
|
489 |
function with call-by-refernece semantics, like in fortran. |
|
490 |
The arguments are converted to a corresponding C data type, |
|
491 |
as defined in the convertST_to_C() function. |
|
492 |
The return value is interpreted as an integer |
|
493 |
(and must be converted to an externalBytes object, |
|
494 |
if it is a pointer to something). |
|
495 |
||
496 |
DANGER alert: This is an unprotected low-level entry. |
|
497 |
Not for normal application usage. |
|
498 |
" |
|
499 |
%{ |
|
500 |
LINTFUNC func; |
|
501 |
INT retVal; |
|
502 |
INT cArg, cArg2; |
|
503 |
||
504 |
func = (LINTFUNC) __INST(code_); |
|
505 |
if (func) { |
|
9323 | 506 |
cArg = convertST_to_C(arg); |
507 |
cArg2 = convertST_to_C(arg2); |
|
508 |
retVal = (*func)(&cArg, &cArg2); |
|
509 |
RETURN (__MKINT(retVal)); |
|
8594 | 510 |
} |
511 |
%}. |
|
512 |
self primitiveFailed |
|
513 |
! |
|
514 |
||
515 |
callByRefWith:arg with:arg2 with:arg3 |
|
516 |
"call the underlying C function, passing three args. |
|
517 |
The pointer of the arguments are passed. Use this if you want to call a |
|
518 |
function with call-by-refernece semantics, like in fortran. |
|
519 |
The arguments are converted to a corresponding C data type, |
|
520 |
as defined in the convertST_to_C() function. |
|
521 |
The return value is interpreted as an integer |
|
522 |
(and must be converted to an externalBytes object, |
|
523 |
if it is a pointer to something). |
|
524 |
||
525 |
DANGER alert: This is an unprotected low-level entry. |
|
526 |
Not for normal application usage. |
|
527 |
" |
|
528 |
%{ |
|
529 |
LINTFUNC func; |
|
530 |
INT retVal; |
|
531 |
INT cArg, cArg2, cArg3; |
|
532 |
||
533 |
func = (LINTFUNC) __INST(code_); |
|
534 |
if (func) { |
|
9323 | 535 |
cArg = convertST_to_C(arg); |
536 |
cArg2 = convertST_to_C(arg2); |
|
537 |
cArg3 = convertST_to_C(arg3); |
|
538 |
retVal = (*func)(&cArg, &cArg2, &cArg3); |
|
539 |
RETURN (__MKINT(retVal)); |
|
8594 | 540 |
} |
541 |
%}. |
|
542 |
self primitiveFailed |
|
543 |
! |
|
544 |
||
545 |
callByRefWithArguments:argArray |
|
546 |
"call the underlying C function, passing up to 10 arguments by reference. |
|
547 |
The arguments are converted to a corresponding C data type, |
|
548 |
as defined in the convertST_to_C() function. |
|
549 |
The return value is interpreted as an integer |
|
550 |
(and must be converted to an externalBytes object, |
|
551 |
if it is a pointer to something). |
|
552 |
||
553 |
DANGER alert: This is an unprotected low-level entry. |
|
554 |
Not for normal application usage. |
|
555 |
" |
|
556 |
%{ |
|
557 |
LINTFUNC func; |
|
558 |
# define NUMARGS 10 |
|
559 |
INT args[NUMARGS]; |
|
560 |
INT retVal; |
|
561 |
OBJ *ap; |
|
562 |
INT convertST_to_C(); |
|
563 |
||
564 |
func = (LINTFUNC) __INST(code_); |
|
565 |
if (func && __isArray(argArray)) { |
|
9323 | 566 |
int n = __arraySize(argArray); |
567 |
int i; |
|
8594 | 568 |
|
9323 | 569 |
if (n <= 10) { |
570 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
571 |
for (i=0; i<NUMARGS; i++) { |
|
572 |
args[i] = convertST_to_C(*ap++); |
|
573 |
} |
|
574 |
} |
|
575 |
switch (n) { |
|
576 |
case 0: |
|
577 |
retVal = (*func)(); |
|
578 |
break; |
|
579 |
case 1: |
|
580 |
retVal = (*func)(&args[0]); |
|
581 |
break; |
|
582 |
case 2: |
|
583 |
retVal = (*func)(&args[0], &args[1]); |
|
584 |
break; |
|
585 |
case 3: |
|
586 |
retVal = (*func)(&args[0], &args[1], &args[2]); |
|
587 |
break; |
|
588 |
case 4: |
|
589 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3]); |
|
590 |
break; |
|
591 |
case 5: |
|
592 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
593 |
&args[4]); |
|
594 |
break; |
|
595 |
case 6: |
|
596 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
597 |
&args[4], &args[5]); |
|
598 |
break; |
|
599 |
case 7: |
|
600 |
retVal = (*func)(&args[0], &args[1],& args[2], &args[3], |
|
601 |
&args[4], &args[5], &args[6]); |
|
602 |
break; |
|
603 |
case 8: |
|
604 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
605 |
&args[4], &args[5], &args[6], &args[7]); |
|
606 |
break; |
|
607 |
case 9: |
|
608 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
609 |
&args[4], &args[5], &args[6], &args[7], |
|
610 |
&args[8]); |
|
611 |
break; |
|
612 |
case 10: |
|
613 |
retVal = (*func)(&args[0], &args[1], &args[2], &args[3], |
|
614 |
&args[4], &args[5], &args[6], &args[7], |
|
615 |
&args[8], &args[9]); |
|
616 |
break; |
|
617 |
default: |
|
618 |
goto err; |
|
619 |
} |
|
620 |
RETURN (__MKINT(retVal)); |
|
8594 | 621 |
} |
622 |
err: ; |
|
623 |
%}. |
|
624 |
self primitiveFailed |
|
625 |
! |
|
626 |
||
5164 | 627 |
callO |
628 |
"call the underlying C function, passing no argument. |
|
629 |
The return value must be a valid object. |
|
630 |
||
631 |
DANGER alert: This is an unprotected low-level entry. |
|
632 |
Not for normal application usage. |
|
633 |
" |
|
634 |
%{ |
|
635 |
OBJFUNC func; |
|
636 |
OBJ retVal; |
|
637 |
||
638 |
func = (OBJFUNC) __INST(code_); |
|
639 |
if (func) { |
|
7665 | 640 |
retVal = (*func)(); |
641 |
RETURN (retVal); |
|
5164 | 642 |
} |
643 |
%}. |
|
644 |
self primitiveFailed |
|
645 |
! |
|
646 |
||
647 |
callOWith:arg |
|
648 |
"call the underlying C function, passing a single object argument. |
|
8534 | 649 |
The return value must be a valid object. |
5164 | 650 |
|
651 |
DANGER alert: This is an unprotected low-level entry. |
|
652 |
Not for normal application usage. |
|
653 |
" |
|
654 |
%{ |
|
655 |
OBJFUNC func; |
|
656 |
OBJ retVal; |
|
657 |
||
658 |
func = (OBJFUNC) __INST(code_); |
|
659 |
if (func) { |
|
7665 | 660 |
retVal = (*func)(arg); |
661 |
RETURN (retVal); |
|
5164 | 662 |
} |
663 |
%}. |
|
664 |
self primitiveFailed |
|
665 |
! |
|
666 |
||
667 |
callOWith:arg1 with:arg2 |
|
668 |
"call the underlying C function, passing two args. |
|
8534 | 669 |
The return value must be a valid object. |
5164 | 670 |
|
671 |
DANGER alert: This is an unprotected low-level entry. |
|
672 |
Not for normal application usage. |
|
673 |
" |
|
674 |
%{ |
|
675 |
OBJFUNC func; |
|
676 |
OBJ retVal; |
|
677 |
||
678 |
func = (OBJFUNC) __INST(code_); |
|
679 |
if (func) { |
|
7665 | 680 |
retVal = (*func)(arg1, arg2); |
681 |
RETURN (retVal); |
|
5164 | 682 |
} |
683 |
%}. |
|
684 |
self primitiveFailed |
|
685 |
! |
|
686 |
||
687 |
callOWith:arg1 with:arg2 with:arg3 |
|
688 |
"call the underlying C function, passing three args. |
|
8534 | 689 |
The return value must be a valid object. |
5164 | 690 |
|
691 |
DANGER alert: This is an unprotected low-level entry. |
|
692 |
Not for normal application usage. |
|
693 |
" |
|
694 |
%{ |
|
695 |
OBJFUNC func; |
|
7665 | 696 |
OBJ retVal; |
5164 | 697 |
|
698 |
func = (OBJFUNC) __INST(code_); |
|
699 |
if (func) { |
|
7665 | 700 |
retVal = (*func)(arg1, arg2, arg3); |
701 |
RETURN (retVal); |
|
5164 | 702 |
} |
703 |
%}. |
|
704 |
self primitiveFailed |
|
705 |
! |
|
706 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
707 |
callWith:arg |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
708 |
"call the underlying C function, passing a single argument. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
709 |
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
|
710 |
as defined in the convertST_to_C() function. |
8534 | 711 |
The return value is interpreted as an integer |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
712 |
(and must be converted to an externalBytes object, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
713 |
if it is a pointer to something). |
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 |
DANGER alert: This is an unprotected low-level entry. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
716 |
Not for normal application usage. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
717 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
718 |
%{ |
2880 | 719 |
LINTFUNC func; |
2769 | 720 |
INT retVal; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
721 |
|
2880 | 722 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
723 |
if (func) { |
7665 | 724 |
retVal = (*func)(convertST_to_C(arg)); |
725 |
RETURN (__MKINT(retVal)); |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
726 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
727 |
%}. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
728 |
self primitiveFailed |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
729 |
! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
730 |
|
3612 | 731 |
callWith:arg1 with:arg2 |
732 |
"call the underlying C function, passing two args. |
|
733 |
The arguments are converted to a corresponding C data type, |
|
734 |
as defined in the convertST_to_C() function. |
|
8534 | 735 |
The return value is interpreted as an integer |
3612 | 736 |
(and must be converted to an externalBytes object, |
737 |
if it is a pointer to something). |
|
738 |
||
739 |
DANGER alert: This is an unprotected low-level entry. |
|
740 |
Not for normal application usage. |
|
741 |
" |
|
742 |
%{ |
|
743 |
LINTFUNC func; |
|
744 |
INT retVal; |
|
745 |
||
746 |
func = (LINTFUNC) __INST(code_); |
|
747 |
if (func) { |
|
7665 | 748 |
retVal = (*func)(convertST_to_C(arg1), convertST_to_C(arg2)); |
749 |
RETURN (__MKINT(retVal)); |
|
3612 | 750 |
} |
751 |
%}. |
|
752 |
self primitiveFailed |
|
753 |
! |
|
754 |
||
755 |
callWith:arg1 with:arg2 with:arg3 |
|
756 |
"call the underlying C function, passing three args. |
|
757 |
The arguments are converted to a corresponding C data type, |
|
758 |
as defined in the convertST_to_C() function. |
|
8534 | 759 |
The return value is interpreted as an integer |
3612 | 760 |
(and must be converted to an externalBytes object, |
761 |
if it is a pointer to something). |
|
762 |
||
763 |
DANGER alert: This is an unprotected low-level entry. |
|
764 |
Not for normal application usage. |
|
765 |
" |
|
766 |
%{ |
|
767 |
LINTFUNC func; |
|
768 |
INT retVal; |
|
769 |
||
770 |
func = (LINTFUNC) __INST(code_); |
|
771 |
if (func) { |
|
7665 | 772 |
retVal = (*func)(convertST_to_C(arg1), convertST_to_C(arg2), convertST_to_C(arg3)); |
773 |
RETURN (__MKINT(retVal)); |
|
3612 | 774 |
} |
775 |
%}. |
|
776 |
self primitiveFailed |
|
777 |
! |
|
778 |
||
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
779 |
callWithArguments:argArray |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
780 |
"call the underlying C function, passing up to 10 arguments. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
781 |
The arguments are converted to a corresponding C data type, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
782 |
as defined in the convertST_to_C() function. |
8534 | 783 |
The return value is interpreted as an integer |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
784 |
(and must be converted to an externalBytes object, |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
785 |
if it is a pointer to something). |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
786 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
787 |
DANGER alert: This is an unprotected low-level entry. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
788 |
Not for normal application usage. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
789 |
" |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
790 |
%{ |
2880 | 791 |
LINTFUNC func; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
792 |
# define NUMARGS 10 |
2880 | 793 |
INT args[NUMARGS]; |
794 |
INT retVal; |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
795 |
OBJ *ap; |
2880 | 796 |
INT convertST_to_C(); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
797 |
|
2880 | 798 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
799 |
if (func && __isArray(argArray)) { |
1133 | 800 |
int n = __arraySize(argArray); |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
801 |
int i; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
802 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
803 |
if (n <= 10) { |
1133 | 804 |
ap = __ArrayInstPtr(argArray)->a_element; |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
805 |
for (i=0; i<NUMARGS; i++) { |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
806 |
args[i] = convertST_to_C(*ap++); |
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 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
809 |
switch (n) { |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
810 |
case 0: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
811 |
retVal = (*func)(); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
812 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
813 |
case 1: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
814 |
retVal = (*func)(args[0]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
815 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
816 |
case 2: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
817 |
retVal = (*func)(args[0], args[1]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
818 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
819 |
case 3: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
820 |
retVal = (*func)(args[0], args[1], args[2]); |
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 4: |
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 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
825 |
case 5: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
826 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
827 |
args[4]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
828 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
829 |
case 6: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
830 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
831 |
args[4], args[5]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
832 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
833 |
case 7: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
834 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
835 |
args[4], args[5], args[6]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
836 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
837 |
case 8: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
838 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
839 |
args[4], args[5], args[6], args[7]); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
840 |
break; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
841 |
case 9: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
842 |
retVal = (*func)(args[0], args[1], args[2], args[3], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
843 |
args[4], args[5], args[6], args[7], |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
844 |
args[8]); |
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 10: |
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], args[9]); |
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 |
default: |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
852 |
goto err; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
853 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
854 |
RETURN (__MKINT(retVal)); |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
855 |
} |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
856 |
err: ; |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
857 |
%}. |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
858 |
self primitiveFailed |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
859 |
! |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
860 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
861 |
callWithDouble:aFloatArg returnsDouble:doubleFlag |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
862 |
"call the underlying C function, passing a single double argument. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
863 |
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
|
864 |
an integer returnValue is assumed." |
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 |
typedef double (*DOUBLEFUNC)(); |
2880 | 867 |
LINTFUNC func; |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
868 |
DOUBLEFUNC dfunc; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
869 |
double arg, dretVal; |
2880 | 870 |
INT retVal; |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
871 |
|
2880 | 872 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
873 |
if (func) { |
7665 | 874 |
if (__isFloat(aFloatArg)) { |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
875 |
arg = __floatVal(aFloatArg); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
876 |
} else if (__isShortFloat(aFloatArg)) { |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
877 |
arg = (double)(__shortFloatVal(aFloatArg)); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
878 |
} else { |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
879 |
arg = (double)(__signedLongIntVal(aFloatArg)); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
880 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
881 |
if (doubleFlag == true) { |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
882 |
dfunc = (DOUBLEFUNC)func; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
883 |
dretVal = (*dfunc)(arg); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
884 |
RETURN (__MKFLOAT(dretVal)); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
885 |
} else { |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
886 |
retVal = (*func)(arg); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
887 |
RETURN (__MKINT(retVal)); |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
888 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
889 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
890 |
%}. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
891 |
self primitiveFailed |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
892 |
! |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
893 |
|
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
894 |
callWithDouble:aFloatArg1 withDouble:aFloatArg2 returnsDouble:doubleFlag |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
895 |
"call the underlying C function, passing two double arguments. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
896 |
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
|
897 |
an integer returnValue is assumed." |
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 |
typedef double (*DOUBLEFUNC)(); |
2880 | 900 |
LINTFUNC func; |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
901 |
DOUBLEFUNC dfunc; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
902 |
double arg1, arg2, dretVal; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
903 |
int retVal; |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
904 |
|
2880 | 905 |
func = (LINTFUNC) __INST(code_); |
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
906 |
if (func) { |
7665 | 907 |
if (__isFloat(aFloatArg1)) { |
908 |
arg1 = __floatVal(aFloatArg1); |
|
909 |
} else if (__isShortFloat(aFloatArg1)) { |
|
910 |
arg1 = (double)(__shortFloatVal(aFloatArg1)); |
|
911 |
} else { |
|
912 |
arg1 = (double)(__signedLongIntVal(aFloatArg1)); |
|
913 |
} |
|
914 |
if (__isFloat(aFloatArg2)) { |
|
915 |
arg2 = __floatVal(aFloatArg2); |
|
916 |
} else if (__isShortFloat(aFloatArg2)) { |
|
917 |
arg2 = (double)(__shortFloatVal(aFloatArg2)); |
|
918 |
} else { |
|
919 |
arg2 = (double)(__signedLongIntVal(aFloatArg2)); |
|
920 |
} |
|
921 |
if (doubleFlag == true) { |
|
922 |
dfunc = (DOUBLEFUNC)func; |
|
923 |
dretVal = (*dfunc)(arg1, arg2); |
|
924 |
RETURN (__MKFLOAT(dretVal)); |
|
925 |
} else { |
|
926 |
retVal = (*func)(arg1, arg2); |
|
927 |
RETURN (__MKINT(retVal)); |
|
928 |
} |
|
1545
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
929 |
} |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
930 |
%}. |
01e11b46ca65
more possible argument types
Claus Gittinger <cg@exept.de>
parents:
1543
diff
changeset
|
931 |
self primitiveFailed |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
932 |
! ! |
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
933 |
|
1547 | 934 |
!ExternalFunction methodsFor:'printing & storing'! |
935 |
||
936 |
printOn:aStream |
|
937 |
"append a printed representation of the receiver to aStream" |
|
938 |
||
939 |
|addr| |
|
940 |
||
941 |
name isNil ifTrue:[^ super printOn:aStream]. |
|
942 |
||
943 |
aStream nextPutAll:self class name; nextPutAll:'(name: '''; |
|
7665 | 944 |
nextPutAll:name; nextPutAll:''' address: '. |
1547 | 945 |
|
946 |
addr := self code. |
|
947 |
addr isNil ifTrue:[ |
|
7665 | 948 |
aStream nextPutAll:'** unloaded **' |
1547 | 949 |
] ifFalse:[ |
7665 | 950 |
aStream nextPutAll:'0x'; |
951 |
nextPutAll:(addr hexPrintString) |
|
1547 | 952 |
]. |
953 |
||
954 |
moduleHandle notNil ifTrue:[ |
|
8534 | 955 |
aStream nextPutAll:' from: '''; |
7665 | 956 |
nextPutAll:(moduleHandle pathName asFilename baseName); |
957 |
nextPutAll:''''. |
|
1547 | 958 |
]. |
959 |
||
960 |
aStream nextPutAll:')' |
|
961 |
||
962 |
"Modified: 12.7.1996 / 23:31:49 / cg" |
|
963 |
! ! |
|
964 |
||
7257 | 965 |
!ExternalFunction methodsFor:'private-loader access'! |
1547 | 966 |
|
9395
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
967 |
invalidate |
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
968 |
super invalidate. |
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
969 |
moduleHandle := nil. |
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
970 |
! |
f02332e03370
also flush the moduleHandle (to force reloading of the library)
ca
parents:
9323
diff
changeset
|
971 |
|
9397 | 972 |
setModuleHandle:aHandle |
973 |
"set the moduleHandle. |
|
974 |
This is a private interface for the objectFileLoader; not for public use." |
|
975 |
||
976 |
moduleHandle := aHandle |
|
977 |
! |
|
978 |
||
1547 | 979 |
setName:aString moduleHandle:aHandle |
980 |
"set the name & moduleHandle. |
|
981 |
This is a private interface for the objectFileLoader; not for public use." |
|
982 |
||
983 |
name := aString. |
|
984 |
moduleHandle := aHandle |
|
985 |
! ! |
|
986 |
||
3612 | 987 |
!ExternalFunction class methodsFor:'documentation'! |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
988 |
|
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
989 |
version |
19480 | 990 |
^ '$Header$' |
12484
7f0cc6e86a66
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9397
diff
changeset
|
991 |
! |
7f0cc6e86a66
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9397
diff
changeset
|
992 |
|
7f0cc6e86a66
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
9397
diff
changeset
|
993 |
version_CVS |
19480 | 994 |
^ '$Header$' |
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
995 |
! ! |
7257 | 996 |
|
848
76a83f34c26a
moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
997 |
ExternalFunction initialize! |