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