6
#include "sqVirtualMachine.h"
8
/*** Function prototypes ***/
10
/* InterpreterProxy methodsFor: 'stack access' */
11
sqInt pop(sqInt nItems);
12
sqInt popthenPush(sqInt nItems, sqInt oop);
13
sqInt push(sqInt object);
14
sqInt pushBool(sqInt trueOrFalse);
15
sqInt pushFloat(double f);
16
sqInt pushInteger(sqInt integerValue);
17
double stackFloatValue(sqInt offset);
18
sqInt stackIntegerValue(sqInt offset);
19
sqInt stackObjectValue(sqInt offset);
20
sqInt stackValue(sqInt offset);
24
extern sqInt (*compilerHooks[])();
25
extern sqInt setCompilerInitialized(sqInt flagValue);
27
/* InterpreterProxy methodsFor: 'object access' */
28
sqInt argumentCountOf(sqInt methodPointer);
29
void *arrayValueOf(sqInt oop);
30
sqInt byteSizeOf(sqInt oop);
31
void *fetchArrayofObject(sqInt fieldIndex, sqInt objectPointer);
32
sqInt fetchClassOf(sqInt oop);
33
double fetchFloatofObject(sqInt fieldIndex, sqInt objectPointer);
34
sqInt fetchIntegerofObject(sqInt fieldIndex, sqInt objectPointer);
35
sqInt fetchPointerofObject(sqInt index, sqInt oop);
36
/* sqInt fetchWordofObject(sqInt fieldIndex, sqInt oop); *
37
* has been rescinded as of VMMaker 3.8 and the 64bitclean VM *
38
* work. To support old plugins we keep a valid function in *
39
* the same location in the VM struct but rename it to *
40
* something utterly horrible to scare off the natives. A new *
41
* equivalent but 64 bit valid function is added as *
42
* 'fetchLong32OfObject' */
43
sqInt obsoleteDontUseThisFetchWordofObject(sqInt index, sqInt oop);
44
sqInt fetchLong32ofObject(sqInt index, sqInt oop);
45
void *firstFixedField(sqInt oop);
46
void *firstIndexableField(sqInt oop);
47
sqInt literalofMethod(sqInt offset, sqInt methodPointer);
48
sqInt literalCountOf(sqInt methodPointer);
49
sqInt methodArgumentCount(void);
50
sqInt methodPrimitiveIndex(void);
51
sqInt primitiveMethod(void);
52
sqInt primitiveIndexOf(sqInt methodPointer);
53
sqInt sizeOfSTArrayFromCPrimitive(void *cPtr);
54
sqInt slotSizeOf(sqInt oop);
55
sqInt stObjectat(sqInt array, sqInt index);
56
sqInt stObjectatput(sqInt array, sqInt index, sqInt value);
57
sqInt stSizeOf(sqInt oop);
58
sqInt storeIntegerofObjectwithValue(sqInt index, sqInt oop, sqInt integer);
59
sqInt storePointerofObjectwithValue(sqInt index, sqInt oop, sqInt valuePointer);
62
/* InterpreterProxy methodsFor: 'testing' */
63
sqInt isKindOf(sqInt oop, char *aString);
64
sqInt isMemberOf(sqInt oop, char *aString);
65
sqInt isBytes(sqInt oop);
66
sqInt isFloatObject(sqInt oop);
67
sqInt isIndexable(sqInt oop);
68
sqInt isIntegerObject(sqInt objectPointer);
69
sqInt isIntegerValue(sqInt intValue);
70
sqInt isPointers(sqInt oop);
71
sqInt isWeak(sqInt oop);
72
sqInt isWords(sqInt oop);
73
sqInt isWordsOrBytes(sqInt oop);
74
sqInt includesBehaviorThatOf(sqInt aClass, sqInt aSuperClass);
75
sqInt isArray(sqInt oop);
76
sqInt internalIsMutable(sqInt oop);
77
sqInt internalIsImmutable(sqInt oop);
79
/* InterpreterProxy methodsFor: 'converting' */
80
sqInt booleanValueOf(sqInt obj);
81
sqInt checkedIntegerValueOf(sqInt intOop);
82
sqInt floatObjectOf(double aFloat);
83
double floatValueOf(sqInt oop);
84
sqInt integerObjectOf(sqInt value);
85
sqInt integerValueOf(sqInt oop);
86
sqInt positive32BitIntegerFor(sqInt integerValue);
87
sqInt positive32BitValueOf(sqInt oop);
88
sqInt signed32BitIntegerFor(sqInt integerValue);
89
sqInt signed32BitValueOf(sqInt oop);
90
sqInt positive64BitIntegerFor(sqLong integerValue);
91
sqLong positive64BitValueOf(sqInt oop);
92
sqInt signed64BitIntegerFor(sqLong integerValue);
93
sqLong signed64BitValueOf(sqInt oop);
95
/* InterpreterProxy methodsFor: 'special objects' */
96
sqInt characterTable(void);
97
sqInt displayObject(void);
98
sqInt falseObject(void);
99
sqInt nilObject(void);
100
sqInt trueObject(void);
103
/* InterpreterProxy methodsFor: 'special classes' */
104
sqInt classArray(void);
105
sqInt classBitmap(void);
106
sqInt classByteArray(void);
107
sqInt classCharacter(void);
108
sqInt classFloat(void);
109
sqInt classLargePositiveInteger(void);
110
sqInt classLargeNegativeInteger(void);
111
sqInt classPoint(void);
112
sqInt classSemaphore(void);
113
sqInt classSmallInteger(void);
114
sqInt classString(void);
117
/* InterpreterProxy methodsFor: 'instance creation' */
118
sqInt clone(sqInt oop);
119
sqInt instantiateClassindexableSize(sqInt classPointer, sqInt size);
120
sqInt makePointwithxValueyValue(sqInt xValue, sqInt yValue);
121
sqInt popRemappableOop(void);
122
sqInt pushRemappableOop(sqInt oop);
125
/* InterpreterProxy methodsFor: 'other' */
126
sqInt becomewith(sqInt array1, sqInt array2);
127
sqInt byteSwapped(sqInt w);
129
sqInt fullDisplayUpdate(void);
131
sqInt incrementalGC(void);
132
sqInt primitiveFail(void);
133
sqInt primitiveFailFor(sqInt reasonCode);
134
sqInt showDisplayBitsLeftTopRightBottom(sqInt aForm, sqInt l, sqInt t, sqInt r, sqInt b);
135
sqInt signalSemaphoreWithIndex(sqInt semaIndex);
136
sqInt success(sqInt aBoolean);
137
sqInt superclassOf(sqInt classPointer);
138
sqInt ioMicroMSecs(void);
139
sqInt forceInterruptCheck(void);
140
sqInt getThisSessionID(void);
141
sqInt ioFilenamefromStringofLengthresolveAliases(char* aCharBuffer, char* filenameIndex, sqInt filenameLength, sqInt resolveFlag);
142
sqInt vmEndianness(void);
144
/* InterpreterProxy methodsFor: 'BitBlt support' */
145
sqInt loadBitBltFrom(sqInt bbOop);
146
sqInt copyBits(void);
147
sqInt copyBitsFromtoat(sqInt leftX, sqInt rightX, sqInt yValue);
149
/* InterpreterProxy methodsFor: 'FFI support' */
150
sqInt classExternalAddress(void); /* Old Squeak FFI */
151
sqInt classExternalData(void);
152
sqInt classExternalFunction(void);
153
sqInt classExternalLibrary(void);
154
sqInt classExternalStructure(void);
155
sqInt classAlien(void); /* Newsqueak FFI */
156
sqInt classUnsafeAlien(void); /* Newsqueak FFI */
157
sqInt getStackPointer(void); /* Newsqueak FFI */
158
sqInt sendInvokeCallbackStackRegistersJmpbuf(sqInt thunkPtrAsInt, sqInt stackPtrAsInt, sqInt regsPtrAsInt, sqInt jmpBufPtrAsInt); /* Newsqueak FFI */
159
sqInt reestablishContextPriorToCallback(sqInt callbackContext); /* Newsqueak FFI */
160
sqInt ioLoadModuleOfLength(sqInt moduleNameIndex, sqInt moduleNameLength);
161
sqInt ioLoadSymbolOfLengthFromModule(sqInt functionNameIndex, sqInt functionNameLength, sqInt moduleHandle);
162
sqInt isInMemory(sqInt address);
164
void *ioLoadFunctionFrom(char *fnName, char *modName);
167
/* Proxy declarations for v1.8 */
168
sqInt callbackEnter(sqInt *callbackID);
169
sqInt callbackLeave(sqInt callbackID);
170
sqInt addGCRoot(sqInt *varLoc);
171
sqInt removeGCRoot(sqInt *varLoc);
173
struct VirtualMachine *VM = NULL;
175
static sqInt majorVersion(void) {
176
return VM_PROXY_MAJOR;
179
static sqInt minorVersion(void) {
180
return VM_PROXY_MINOR;
183
static CompilerHook *compilerHookVector(void) {
184
return compilerHooks;
188
struct VirtualMachine* sqGetInterpreterProxy(void)
191
VM = (struct VirtualMachine *)calloc(1, sizeof(VirtualMachine));
192
/* Initialize Function pointers */
193
VM->majorVersion = majorVersion;
194
VM->minorVersion = minorVersion;
196
/* InterpreterProxy methodsFor: 'stack access' */
198
VM->popthenPush = popthenPush;
200
VM->pushBool = pushBool;
201
VM->pushFloat = pushFloat;
202
VM->pushInteger = pushInteger;
203
VM->stackFloatValue = stackFloatValue;
204
VM->stackIntegerValue = stackIntegerValue;
205
VM->stackObjectValue = stackObjectValue;
206
VM->stackValue = stackValue;
208
/* InterpreterProxy methodsFor: 'object access' */
209
VM->argumentCountOf = argumentCountOf;
210
VM->arrayValueOf = arrayValueOf;
211
VM->byteSizeOf = byteSizeOf;
212
VM->fetchArrayofObject = fetchArrayofObject;
213
VM->fetchClassOf = fetchClassOf;
214
VM->fetchFloatofObject = fetchFloatofObject;
215
VM->fetchIntegerofObject = fetchIntegerofObject;
216
VM->fetchPointerofObject = fetchPointerofObject;
217
VM->obsoleteDontUseThisFetchWordofObject = obsoleteDontUseThisFetchWordofObject;
218
VM->firstFixedField = firstFixedField;
219
VM->firstIndexableField = firstIndexableField;
220
VM->literalofMethod = literalofMethod;
221
VM->literalCountOf = literalCountOf;
222
VM->methodArgumentCount = methodArgumentCount;
223
VM->methodPrimitiveIndex = methodPrimitiveIndex;
224
VM->primitiveIndexOf = primitiveIndexOf;
225
VM->primitiveMethod = primitiveMethod;
226
VM->sizeOfSTArrayFromCPrimitive = sizeOfSTArrayFromCPrimitive;
227
VM->slotSizeOf = slotSizeOf;
228
VM->stObjectat = stObjectat;
229
VM->stObjectatput = stObjectatput;
230
VM->stSizeOf = stSizeOf;
231
VM->storeIntegerofObjectwithValue = storeIntegerofObjectwithValue;
232
VM->storePointerofObjectwithValue = storePointerofObjectwithValue;
234
/* InterpreterProxy methodsFor: 'testing' */
235
VM->isKindOf = isKindOf;
236
VM->isMemberOf = isMemberOf;
237
VM->isBytes = isBytes;
238
VM->isFloatObject = isFloatObject;
239
VM->isIndexable = isIndexable;
240
VM->isIntegerObject = isIntegerObject;
241
VM->isIntegerValue = isIntegerValue;
242
VM->isPointers = isPointers;
244
VM->isWords = isWords;
245
VM->isWordsOrBytes = isWordsOrBytes;
247
/* InterpreterProxy methodsFor: 'converting' */
248
VM->booleanValueOf = booleanValueOf;
249
VM->checkedIntegerValueOf = checkedIntegerValueOf;
250
VM->floatObjectOf = floatObjectOf;
251
VM->floatValueOf = floatValueOf;
252
VM->integerObjectOf = integerObjectOf;
253
VM->integerValueOf = integerValueOf;
254
VM->positive32BitIntegerFor = positive32BitIntegerFor;
255
VM->positive32BitValueOf = positive32BitValueOf;
257
/* InterpreterProxy methodsFor: 'special objects' */
258
VM->characterTable = characterTable;
259
VM->displayObject = displayObject;
260
VM->falseObject = falseObject;
261
VM->nilObject = nilObject;
262
VM->trueObject = trueObject;
264
/* InterpreterProxy methodsFor: 'special classes' */
265
VM->classArray = classArray;
266
VM->classBitmap = classBitmap;
267
VM->classByteArray = classByteArray;
268
VM->classCharacter = classCharacter;
269
VM->classFloat = classFloat;
270
VM->classLargePositiveInteger = classLargePositiveInteger;
271
VM->classPoint = classPoint;
272
VM->classSemaphore = classSemaphore;
273
VM->classSmallInteger = classSmallInteger;
274
VM->classString = classString;
276
/* InterpreterProxy methodsFor: 'instance creation' */
278
VM->instantiateClassindexableSize = instantiateClassindexableSize;
279
VM->makePointwithxValueyValue = makePointwithxValueyValue;
280
VM->popRemappableOop = popRemappableOop;
281
VM->pushRemappableOop = pushRemappableOop;
283
/* InterpreterProxy methodsFor: 'other' */
284
VM->becomewith = becomewith;
285
VM->byteSwapped = byteSwapped;
287
VM->fullDisplayUpdate = fullDisplayUpdate;
289
VM->incrementalGC = incrementalGC;
290
VM->primitiveFail = primitiveFail;
291
VM->showDisplayBitsLeftTopRightBottom = showDisplayBitsLeftTopRightBottom;
292
VM->signalSemaphoreWithIndex = signalSemaphoreWithIndex;
293
VM->success = success;
294
VM->superclassOf = superclassOf;
296
VM->compilerHookVector= compilerHookVector;
297
VM->setCompilerInitialized= setCompilerInitialized;
299
#if VM_PROXY_MINOR > 1
301
/* InterpreterProxy methodsFor: 'BitBlt support' */
302
VM->loadBitBltFrom = loadBitBltFrom;
303
VM->copyBits = copyBits;
304
VM->copyBitsFromtoat = copyBitsFromtoat;
308
#if VM_PROXY_MINOR > 2
310
/* InterpreterProxy methodsFor: 'FFI support' */
311
VM->classExternalAddress = classExternalAddress;
312
VM->classExternalData = classExternalData;
313
VM->classExternalFunction = classExternalFunction;
314
VM->classExternalLibrary = classExternalLibrary;
315
VM->classExternalStructure = classExternalStructure;
316
VM->ioLoadModuleOfLength = ioLoadModuleOfLength;
317
VM->ioLoadSymbolOfLengthFromModule = ioLoadSymbolOfLengthFromModule;
318
VM->isInMemory = isInMemory;
319
VM->signed32BitIntegerFor = signed32BitIntegerFor;
320
VM->signed32BitValueOf = signed32BitValueOf;
321
VM->includesBehaviorThatOf = includesBehaviorThatOf;
322
VM->classLargeNegativeInteger = classLargeNegativeInteger;
326
#if VM_PROXY_MINOR > 3
328
VM->ioLoadFunctionFrom = ioLoadFunctionFrom;
329
VM->ioMicroMSecs = ioMicroMSecs;
333
#if VM_PROXY_MINOR > 4
335
VM->positive64BitIntegerFor = positive64BitIntegerFor;
336
VM->positive64BitValueOf = positive64BitValueOf;
337
VM->signed64BitIntegerFor = signed64BitIntegerFor;
338
VM->signed64BitValueOf = signed64BitValueOf;
342
#if VM_PROXY_MINOR > 5
343
VM->isArray = isArray;
344
VM->forceInterruptCheck = forceInterruptCheck;
347
#if VM_PROXY_MINOR > 6
349
VM->fetchLong32ofObject = fetchLong32ofObject;
350
VM->getThisSessionID = getThisSessionID;
351
VM->ioFilenamefromStringofLengthresolveAliases = ioFilenamefromStringofLengthresolveAliases;
352
VM->vmEndianness = vmEndianness;
356
#if VM_PROXY_MINOR > 7
358
VM->internalIsImmutable = internalIsImmutable;
359
VM->internalIsMutable = internalIsMutable;
360
VM->primitiveFailFor = primitiveFailFor;
361
VM->classAlien = classAlien;
362
VM->getStackPointer = (sqInt *(*)(void))getStackPointer;
363
VM->sendInvokeCallbackStackRegistersJmpbuf = sendInvokeCallbackStackRegistersJmpbuf;
364
VM->reestablishContextPriorToCallback = reestablishContextPriorToCallback;
365
VM->classUnsafeAlien = classUnsafeAlien;
369
#if VM_PROXY_MINOR > 7
370
VM->callbackEnter = callbackEnter;
371
VM->callbackLeave = callbackLeave;
372
VM->addGCRoot = addGCRoot;
373
VM->removeGCRoot = removeGCRoot;