Skip to content

Commit 7b39d8d

Browse files
committed
CogVM source as per VMMaker.oscog-eem.2830
IA32ABIPlugin: Add primAlienCopyInto, a slightly more convenient way of getting data out of aliens.
1 parent 24be48c commit 7b39d8d

File tree

1 file changed

+104
-26
lines changed

1 file changed

+104
-26
lines changed

src/plugins/IA32ABI/IA32ABI.c

Lines changed: 104 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated by
2-
VMPluginCodeGenerator VMMaker.oscog-eem.2826 uuid: 0dd1c326-6391-497c-896b-b605178640de
2+
VMPluginCodeGenerator VMMaker.oscog-eem.2830 uuid: b30cd73c-7118-461b-9d8a-1c523c6aa011
33
from
4-
IA32ABIPlugin VMMaker.oscog-eem.2826 uuid: 0dd1c326-6391-497c-896b-b605178640de
4+
IA32ABIPlugin VMMaker.oscog-eem.2830 uuid: b30cd73c-7118-461b-9d8a-1c523c6aa011
55
*/
6-
static char __buildInfo[] = "IA32ABIPlugin VMMaker.oscog-eem.2826 uuid: 0dd1c326-6391-497c-896b-b605178640de " __DATE__ ;
6+
static char __buildInfo[] = "IA32ABIPlugin VMMaker.oscog-eem.2830 uuid: b30cd73c-7118-461b-9d8a-1c523c6aa011 " __DATE__ ;
77

88

99

@@ -74,6 +74,7 @@ static sqInt indexlengthinRange(sqInt byteIndex, sqInt length, sqInt rcvr);
7474
EXPORT(sqInt) isAlien(sqInt anOop);
7575
EXPORT(sqInt) primAddressField(void);
7676
EXPORT(sqInt) primAddressFieldPut(void);
77+
EXPORT(sqInt) primAlienCopyInto(void);
7778
EXPORT(sqInt) primAlienReplace(void);
7879
EXPORT(sqInt) primAllocateExecutablePage(void);
7980
EXPORT(sqInt) primBoxedFree(void);
@@ -193,6 +194,9 @@ static sqInt (*isOopImmutable)(sqInt oop);
193194
#endif /* IMMUTABILITY */
194195
static sqInt (*isWordsOrBytes)(sqInt oop);
195196
static sqInt (*methodArgumentCount)(void);
197+
static sqInt (*methodReturnFloat)(double aFloat);
198+
static sqInt (*methodReturnInteger)(sqInt integer);
199+
static sqInt (*methodReturnReceiver)(void);
196200
static sqInt (*methodReturnValue)(sqInt oop);
197201
static sqInt (*pop)(sqInt nItems);
198202
static sqInt (*popthenPush)(sqInt nItems, sqInt oop);
@@ -202,7 +206,6 @@ static sqInt (*positive64BitIntegerFor)(usqLong integerValue);
202206
static usqLong (*positive64BitValueOf)(sqInt oop);
203207
static usqIntptr_t (*positiveMachineIntegerValueOf)(sqInt oop);
204208
static sqInt (*primitiveFailFor)(sqInt reasonCode);
205-
static sqInt (*pushFloat)(double f);
206209
static sqInt (*returnAsThroughCallbackContext)(sqInt returnTypeOop, VMCallbackContext *vmCallbackContext, sqInt callbackMethodContext);
207210
static sqInt (*signalNoResume)(sqInt aSemaphore);
208211
static sqInt (*signed32BitIntegerFor)(sqInt integerValue);
@@ -254,6 +257,9 @@ extern sqInt isOopImmutable(sqInt oop);
254257
#endif
255258
extern sqInt isWordsOrBytes(sqInt oop);
256259
extern sqInt methodArgumentCount(void);
260+
extern sqInt methodReturnFloat(double aFloat);
261+
extern sqInt methodReturnInteger(sqInt integer);
262+
extern sqInt methodReturnReceiver(void);
257263
extern sqInt methodReturnValue(sqInt oop);
258264
extern sqInt pop(sqInt nItems);
259265
extern sqInt popthenPush(sqInt nItems, sqInt oop);
@@ -263,7 +269,6 @@ extern sqInt positive64BitIntegerFor(usqLong integerValue);
263269
extern usqLong positive64BitValueOf(sqInt oop);
264270
extern usqIntptr_t positiveMachineIntegerValueOf(sqInt oop);
265271
extern sqInt primitiveFailFor(sqInt reasonCode);
266-
extern sqInt pushFloat(double f);
267272
extern sqInt returnAsThroughCallbackContext(sqInt returnTypeOop, VMCallbackContext *vmCallbackContext, sqInt callbackMethodContext);
268273
extern sqInt signalNoResume(sqInt aSemaphore);
269274
extern sqInt signed32BitIntegerFor(sqInt integerValue);
@@ -280,7 +285,7 @@ extern sqInt trueObject(void);
280285
extern
281286
#endif
282287
struct VirtualMachine* interpreterProxy;
283-
static const char *moduleName = "IA32ABI VMMaker.oscog-eem.2826 " INT_EXT;
288+
static const char *moduleName = "IA32ABI VMMaker.oscog-eem.2830 " INT_EXT;
284289

285290

286291

@@ -343,15 +348,12 @@ primAddressField(void)
343348
{
344349
sqInt rcvr;
345350
sqInt value;
346-
sqInt valueOop;
347351

348352
rcvr = stackValue(0);
349353
value = longAt((rcvr + BaseHeaderSize) + BytesPerOop);
350-
/* begin positiveMachineIntegerFor: */
351-
valueOop = (BytesPerWord == 8
354+
return methodReturnValue((BytesPerWord == 8
352355
? positive64BitIntegerFor(value)
353-
: positive32BitIntegerFor(value));
354-
return methodReturnValue(valueOop);
356+
: positive32BitIntegerFor(value)));
355357
}
356358

357359

@@ -383,6 +385,81 @@ primAddressFieldPut(void)
383385
}
384386

385387

388+
/* Copy some number of bytes from the receiver starting at the first index
389+
into some destination
390+
object starting at the second index. The destination may be an Aliens or a
391+
bit-indexable object.
392+
The primitive will have the following signature:
393+
<Alien>
394+
primCopyFrom: start <Integer>
395+
to: stop <Integer>
396+
into: destination <Alien | indexableByteSubclass et al>
397+
startingAt: destStart <Integer> ^<self>
398+
<primitive: 'primitiveAlienReplace' error: errorCode module: 'IA32ABI'>
399+
*/
400+
401+
/* IA32ABIPlugin>>#primAlienCopyInto */
402+
EXPORT(sqInt)
403+
primAlienCopyInto(void)
404+
{
405+
sqInt alien;
406+
sqInt dest;
407+
sqInt destAddr;
408+
sqInt destStart;
409+
sqInt myLength;
410+
sqInt src;
411+
sqInt start;
412+
sqInt stop;
413+
sqInt totalLength;
414+
415+
416+
/* Unchecked! */
417+
alien = stackValue(4);
418+
start = stackIntegerValue(3);
419+
stop = stackIntegerValue(2);
420+
dest = stackValue(1);
421+
destStart = stackIntegerValue(0);
422+
if ((failed())
423+
|| (!(isWordsOrBytes(dest)))) {
424+
return primitiveFailFor(PrimErrBadArgument);
425+
}
426+
myLength = longAt(alien + BaseHeaderSize);
427+
src = (((myLength > 0
428+
? (alien + BaseHeaderSize) + BytesPerOop
429+
: longAt((alien + BaseHeaderSize) + BytesPerOop))) + start) - 1;
430+
if (includesBehaviorThatOf(fetchClassOf(dest), classAlien())) {
431+
totalLength = longAt(dest + BaseHeaderSize);
432+
destAddr = (((totalLength > 0
433+
? (dest + BaseHeaderSize) + BytesPerOop
434+
: longAt((dest + BaseHeaderSize) + BytesPerOop))) + start) - 1;
435+
if (totalLength == 0) {
436+
437+
/* no bounds checks for zero-sized (pointer) Aliens */
438+
totalLength = stop;
439+
}
440+
else {
441+
totalLength = SQABS(totalLength);
442+
}
443+
}
444+
else {
445+
totalLength = byteSizeOf(dest);
446+
destAddr = ((dest + BaseHeaderSize) + start) - 1;
447+
}
448+
if (!(((start >= 1)
449+
&& (((start - 1) <= stop)
450+
&& (stop <= (SQABS(myLength)))))
451+
&& (((stop - start) + 1) <= totalLength))) {
452+
return primitiveFailFor(PrimErrBadIndex);
453+
}
454+
if (isOopImmutable(dest)) {
455+
return primitiveFailFor(PrimErrNoModification);
456+
}
457+
memmove(((void *)destAddr), ((void *)src), (stop - start) + 1);
458+
methodReturnReceiver();
459+
return 0;
460+
}
461+
462+
386463
/* Copy some number of bytes from some source object starting at the index
387464
into the receiver destination object from startIndex to stopIndex. The
388465
source and destination may be Aliens or byte-indexable objects. The
@@ -408,7 +485,6 @@ EXPORT(sqInt)
408485
primAlienReplace(void)
409486
{
410487
sqInt array;
411-
sqInt count;
412488
sqInt dest;
413489
sqInt repl;
414490
sqInt replStart;
@@ -485,9 +561,8 @@ primAlienReplace(void)
485561
if (isOopImmutable(array)) {
486562
return primitiveFailFor(PrimErrNoModification);
487563
}
488-
count = (stop - start) + 1;
489-
memmove(((void *)dest), ((void *)src), count);
490-
pop(methodArgumentCount());
564+
memmove(((void *)dest), ((void *)src), (stop - start) + 1);
565+
methodReturnReceiver();
491566
return 0;
492567
}
493568

@@ -551,7 +626,7 @@ primBoxedFree(void)
551626
|| (isInMemory(addr)))) {
552627
return primitiveFailFor(PrimErrInappropriate);
553628
}
554-
free((void *)addr);
629+
free(((void *)addr));
555630
ptr[0] = 0;
556631
ptr[1] = 0;
557632
return 0;
@@ -754,8 +829,8 @@ primDoubleAt(void)
754829
}
755830
addr = startAddr + byteOffset;
756831
memcpy((&floatValue), addr, sizeof(floatValue));
757-
pop(2);
758-
return pushFloat(floatValue);
832+
methodReturnFloat(floatValue);
833+
return 0;
759834
}
760835

761836

@@ -846,8 +921,8 @@ primFloatAt(void)
846921
}
847922
addr = startAddr + byteOffset;
848923
memcpy((&floatValue), addr, sizeof(floatValue));
849-
pop(2);
850-
return pushFloat(floatValue);
924+
methodReturnFloat(floatValue);
925+
return 0;
851926
}
852927

853928

@@ -916,7 +991,7 @@ primFree(void)
916991
|| (isInMemory(addr))) {
917992
return primitiveFailFor(PrimErrInappropriate);
918993
}
919-
free((void *)addr);
994+
free(((void *)addr));
920995
pop(1);
921996
return 0;
922997
}
@@ -1615,7 +1690,8 @@ primStrlenFromStartIndex(void)
16151690
index += 1;
16161691
}
16171692
}
1618-
return methodReturnValue(positive32BitIntegerFor(index));
1693+
methodReturnInteger(index);
1694+
return 0;
16191695
}
16201696

16211697

@@ -1632,7 +1708,6 @@ primStrlenThroughPointerAtIndex(void)
16321708
{
16331709
usqIntptr_t addr;
16341710
usqIntptr_t byteOffset;
1635-
char *ptr;
16361711
sqInt rcvr;
16371712

16381713
byteOffset = (stackPositiveMachineIntegerValue(0)) - 1;
@@ -1646,8 +1721,7 @@ primStrlenThroughPointerAtIndex(void)
16461721
addr = (((longAt(rcvr + BaseHeaderSize)) > 0
16471722
? (rcvr + BaseHeaderSize) + BytesPerOop
16481723
: longAt((rcvr + BaseHeaderSize) + BytesPerOop))) + byteOffset;
1649-
ptr = ((char *) (longAt(addr)));
1650-
return methodReturnValue(positive32BitIntegerFor(strlen(ptr)));
1724+
return methodReturnInteger(strlen(((char *) (longAt(addr)))));
16511725
}
16521726

16531727

@@ -2245,6 +2319,9 @@ setInterpreter(struct VirtualMachine *anInterpreter)
22452319
#endif
22462320
isWordsOrBytes = interpreterProxy->isWordsOrBytes;
22472321
methodArgumentCount = interpreterProxy->methodArgumentCount;
2322+
methodReturnFloat = interpreterProxy->methodReturnFloat;
2323+
methodReturnInteger = interpreterProxy->methodReturnInteger;
2324+
methodReturnReceiver = interpreterProxy->methodReturnReceiver;
22482325
methodReturnValue = interpreterProxy->methodReturnValue;
22492326
pop = interpreterProxy->pop;
22502327
popthenPush = interpreterProxy->popthenPush;
@@ -2254,7 +2331,6 @@ setInterpreter(struct VirtualMachine *anInterpreter)
22542331
positive64BitValueOf = interpreterProxy->positive64BitValueOf;
22552332
positiveMachineIntegerValueOf = interpreterProxy->positiveMachineIntegerValueOf;
22562333
primitiveFailFor = interpreterProxy->primitiveFailFor;
2257-
pushFloat = interpreterProxy->pushFloat;
22582334
returnAsThroughCallbackContext = interpreterProxy->returnAsThroughCallbackContext;
22592335
signalNoResume = interpreterProxy->signalNoResume;
22602336
signed32BitIntegerFor = interpreterProxy->signed32BitIntegerFor;
@@ -2335,6 +2411,7 @@ void* IA32ABI_exports[][3] = {
23352411
{(void*)_m, "isAlien", (void*)isAlien},
23362412
{(void*)_m, "primAddressField\000\000", (void*)primAddressField},
23372413
{(void*)_m, "primAddressFieldPut\000\000", (void*)primAddressFieldPut},
2414+
{(void*)_m, "primAlienCopyInto\000\000", (void*)primAlienCopyInto},
23382415
{(void*)_m, "primAlienReplace\000\000", (void*)primAlienReplace},
23392416
{(void*)_m, "primAllocateExecutablePage\000\377", (void*)primAllocateExecutablePage},
23402417
{(void*)_m, "primBoxedFree\000\001", (void*)primBoxedFree},
@@ -2390,6 +2467,7 @@ void* IA32ABI_exports[][3] = {
23902467

23912468
signed char primAddressFieldAccessorDepth = 0;
23922469
signed char primAddressFieldPutAccessorDepth = 0;
2470+
signed char primAlienCopyIntoAccessorDepth = 0;
23932471
signed char primAlienReplaceAccessorDepth = 0;
23942472
signed char primBoxedFreeAccessorDepth = 1;
23952473
signed char primCallOutDoubleReturnAccessorDepth = 0;

0 commit comments

Comments
 (0)