Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.3216
Browse files Browse the repository at this point in the history
SmartSyntaxInterpreterPlugins:

A flaw of the rather lovely SmartSyntaxInterpreterPlugin framework is that when
simulating pointer type  is determined by spec array (parameters: and/or
reciever: in primitive:parameters:[receiver:]), not by the type of the variable
assigned to.  But this shouldn't be the case.  The type of firstIndexableField:
is intentionally #'void *', which in C can freely be assigned to any pointer
type. Fix simulation so that the casts applied to firstIndexableField: reflect
the type of the target variable, only defaulting to the type specified by the
spec class if there is no declaration.

Hence significantly simplify the pointer API, removing
ccgLoad:expr:asCharPtrFrom:andThen: et al, and keeping only
ccgLoad:expr:asNullTerminatedCharPtrFrom:andThen:,
ccgLoad:expr:asPtrFrom:andThen:ccgLoad:expr:asOopPtrFrom:andThen:.

The consequence for the generated C is that firstIndexbaleField: is not cast to a pointer, simply assigned to a variable (whose type will not have changed).
  • Loading branch information
eliotmiranda committed Jul 19, 2022
1 parent 1a2f811 commit 0ca2861
Show file tree
Hide file tree
Showing 26 changed files with 272 additions and 2,372 deletions.
10 changes: 5 additions & 5 deletions src/plugins/AsynchFilePlugin/AsynchFilePlugin.c
@@ -1,9 +1,9 @@
/* Automatically generated by
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2
from
AsynchFilePlugin VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526
AsynchFilePlugin VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2
*/
static char __buildInfo[] = "AsynchFilePlugin VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526 " __DATE__ ;
static char __buildInfo[] = "AsynchFilePlugin VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -112,7 +112,7 @@ extern sqInt success(sqInt aBoolean);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "AsynchFilePlugin VMMaker.oscog-eem.3166 " INT_EXT;
static const char *moduleName = "AsynchFilePlugin VMMaker.oscog-eem.3216 " INT_EXT;
static void * sCOAFfn;


Expand Down Expand Up @@ -217,7 +217,7 @@ primitiveAsyncFileOpen(void)
&& (isIntegerObject((semaIndex = stackValue(0))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
fileName = ((char *) (firstIndexableField(stackValue(2))));
fileName = firstIndexableField(stackValue(2));
writeFlag = booleanValueOf(stackValue(1));
semaIndex = integerValueOf(semaIndex);

Expand Down
16 changes: 8 additions & 8 deletions src/plugins/BochsIA32Plugin/BochsIA32Plugin.c
@@ -1,5 +1,5 @@
/* Automatically generated by
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2
from
BochsIA32Plugin Cog-eem.450 uuid: 5598d2df-ceec-431e-be4f-29b1458b907f
*/
Expand Down Expand Up @@ -231,7 +231,7 @@ primitiveDisassembleAtInMemory(void)
return primitiveFailFor(PrimErrBadArgument);
}
address = integerValueOf(address);
memory = ((char *) (firstIndexableField(stackValue(0))));
memory = firstIndexableField(stackValue(0));
cpuAlien = stackValue(2);
if (((cpu = ((void *) (((longAt(cpuAlien + BaseHeaderSize)) > 0
? (cpuAlien + BaseHeaderSize) + BytesPerOop
Expand Down Expand Up @@ -465,7 +465,7 @@ primitiveRunInMemoryMinAddressMaxAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0)))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(3))));
memory = firstIndexableField(stackValue(3));
minAddress = integerValueOf(minAddress);
maxAddress = integerValueOf(maxAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
Expand Down Expand Up @@ -522,7 +522,7 @@ primitiveRunInMemoryMinimumAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(2))));
memory = firstIndexableField(stackValue(2));
minAddress = integerValueOf(minAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
cpuAlien = stackValue(3);
Expand Down Expand Up @@ -579,7 +579,7 @@ primitiveRunInMemoryOffsetMinimumAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0)))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(3))));
memory = firstIndexableField(stackValue(3));
offset = integerValueOf(offset);
minAddress = integerValueOf(minAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
Expand Down Expand Up @@ -637,7 +637,7 @@ primitiveSingleStepInMemoryMinAddressMaxAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0)))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(3))));
memory = firstIndexableField(stackValue(3));
minAddress = integerValueOf(minAddress);
maxAddress = integerValueOf(maxAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
Expand Down Expand Up @@ -688,7 +688,7 @@ primitiveSingleStepInMemoryMinimumAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(2))));
memory = firstIndexableField(stackValue(2));
minAddress = integerValueOf(minAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
cpuAlien = stackValue(3);
Expand Down Expand Up @@ -739,7 +739,7 @@ primitiveSingleStepInMemoryOffsetMinimumAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0)))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(3))));
memory = firstIndexableField(stackValue(3));
offset = integerValueOf(offset);
minAddress = integerValueOf(minAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
Expand Down
16 changes: 8 additions & 8 deletions src/plugins/BochsX64Plugin/BochsX64Plugin.c
@@ -1,5 +1,5 @@
/* Automatically generated by
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2
from
BochsX64Plugin Cog-eem.450 uuid: 5598d2df-ceec-431e-be4f-29b1458b907f
*/
Expand Down Expand Up @@ -231,7 +231,7 @@ primitiveDisassembleAtInMemory(void)
return primitiveFailFor(PrimErrBadArgument);
}
address = integerValueOf(address);
memory = ((char *) (firstIndexableField(stackValue(0))));
memory = firstIndexableField(stackValue(0));
cpuAlien = stackValue(2);
if (((cpu = ((void *) (((longAt(cpuAlien + BaseHeaderSize)) > 0
? (cpuAlien + BaseHeaderSize) + BytesPerOop
Expand Down Expand Up @@ -465,7 +465,7 @@ primitiveRunInMemoryMinAddressMaxAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0)))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(3))));
memory = firstIndexableField(stackValue(3));
minAddress = integerValueOf(minAddress);
maxAddress = integerValueOf(maxAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
Expand Down Expand Up @@ -522,7 +522,7 @@ primitiveRunInMemoryMinimumAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(2))));
memory = firstIndexableField(stackValue(2));
minAddress = integerValueOf(minAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
cpuAlien = stackValue(3);
Expand Down Expand Up @@ -579,7 +579,7 @@ primitiveRunInMemoryOffsetMinimumAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0)))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(3))));
memory = firstIndexableField(stackValue(3));
offset = integerValueOf(offset);
minAddress = integerValueOf(minAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
Expand Down Expand Up @@ -637,7 +637,7 @@ primitiveSingleStepInMemoryMinAddressMaxAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0)))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(3))));
memory = firstIndexableField(stackValue(3));
minAddress = integerValueOf(minAddress);
maxAddress = integerValueOf(maxAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
Expand Down Expand Up @@ -688,7 +688,7 @@ primitiveSingleStepInMemoryMinimumAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(2))));
memory = firstIndexableField(stackValue(2));
minAddress = integerValueOf(minAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
cpuAlien = stackValue(3);
Expand Down Expand Up @@ -739,7 +739,7 @@ primitiveSingleStepInMemoryOffsetMinimumAddressReadWrite(void)
&& (isIntegerObject((minWriteMaxExecAddress = stackValue(0)))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
memory = ((char *) (firstIndexableField(stackValue(3))));
memory = firstIndexableField(stackValue(3));
offset = integerValueOf(offset);
minAddress = integerValueOf(minAddress);
minWriteMaxExecAddress = integerValueOf(minWriteMaxExecAddress);
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/ClipboardExtendedPlugin/ClipboardExtendedPlugin.c
@@ -1,9 +1,9 @@
/* Automatically generated by
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2
from
ClipboardExtendedPlugin VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526
ClipboardExtendedPlugin VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2
*/
static char __buildInfo[] = "ClipboardExtendedPlugin VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526 " __DATE__ ;
static char __buildInfo[] = "ClipboardExtendedPlugin VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -98,7 +98,7 @@ extern sqInt stackValue(sqInt offset);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "ClipboardExtendedPlugin VMMaker.oscog-eem.3166 " INT_EXT;
static const char *moduleName = "ClipboardExtendedPlugin VMMaker.oscog-eem.3216 " INT_EXT;



Expand Down Expand Up @@ -130,8 +130,8 @@ ioAddClipboardData(void)
return primitiveFailFor(PrimErrBadArgument);
}
clipboard = stackValue(2);
data = ((char *) (firstIndexableField(stackValue(1))));
aFormat = ((char *) (firstIndexableField(stackValue(0))));
data = firstIndexableField(stackValue(1));
aFormat = firstIndexableField(stackValue(0));
clipboardAddress = positiveMachineIntegerValueOf(clipboard);
dataLength = slotSizeOf(((sqInt)(sqIntptr_t)(data) - BaseHeaderSize));
formatLength = slotSizeOf(((sqInt)(sqIntptr_t)(aFormat) - BaseHeaderSize));
Expand Down Expand Up @@ -217,7 +217,7 @@ ioReadClipboardData(void)
return primitiveFailFor(PrimErrBadArgument);
}
clipboard = stackValue(1);
format = ((char *) (firstIndexableField(stackValue(0))));
format = firstIndexableField(stackValue(0));
clipboardAddress = positiveMachineIntegerValueOf(clipboard);
formatLength = slotSizeOf(((sqInt)(sqIntptr_t)(format) - BaseHeaderSize));
if (!(failed())) {
Expand Down
36 changes: 4 additions & 32 deletions src/plugins/FileAttributesPlugin/FileAttributesPlugin.c
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526
VMPluginCodeGenerator VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2
from
FileAttributesPlugin FileAttributesPlugin.oscog-eem.61 uuid: bf616f5a-459a-4d9a-b061-d887e3107deb
FileAttributesPlugin FileAttributesPlugin.oscog-eem.62 uuid: ebb2584e-9c7a-4f03-aa3e-4f6f68bb8d05
*/
static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.61 uuid: bf616f5a-459a-4d9a-b061-d887e3107deb " __DATE__ ;
static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.62 uuid: ebb2584e-9c7a-4f03-aa3e-4f6f68bb8d05 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -77,7 +77,6 @@ EXPORT(const char*) getModuleName(void);
EXPORT(sqInt) initialiseModule(void);
static sqInt objectFromStructsize(void *aMachineAddress, sqInt structSize);
static int pathOoptoBuffermaxLen(sqInt pathNameOop, char *cPathName, sqInt maxLen);
static void * pointerFrom(sqInt directoryPointerBytes);
EXPORT(sqInt) primitiveChangeMode(void);
EXPORT(sqInt) primitiveChangeOwner(void);
EXPORT(sqInt) primitiveClosedir(void);
Expand Down Expand Up @@ -115,7 +114,6 @@ static sqInt (*instantiateClassindexableSize)(sqInt classPointer, sqInt size);
static sqInt (*integerObjectOf)(sqInt value);
#endif
static void * (*ioLoadFunctionFrom)(char *functionName, char *moduleName);
static sqInt (*isKindOf)(sqInt oop, char *aString);
static sqInt (*isBytes)(sqInt oop);
static sqInt (*methodReturnBool)(sqInt boolean);
static sqInt (*methodReturnInteger)(sqInt integer);
Expand Down Expand Up @@ -151,7 +149,6 @@ extern sqInt instantiateClassindexableSize(sqInt classPointer, sqInt size);
extern sqInt integerObjectOf(sqInt value);
#endif
extern void * ioLoadFunctionFrom(char *functionName, char *moduleName);
extern sqInt isKindOf(sqInt oop, char *aString);
extern sqInt isBytes(sqInt oop);
extern sqInt methodReturnBool(sqInt boolean);
extern sqInt methodReturnInteger(sqInt integer);
Expand All @@ -178,7 +175,7 @@ extern sqInt storePointerofObjectwithValue(sqInt index, sqInt oop, sqInt valuePo
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.61 " INT_EXT;
static const char *moduleName = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.62 " INT_EXT;
static void * sCLPfn;
static void * sCOFfn;
static int hasSecurityPlugin = 1;
Expand Down Expand Up @@ -478,30 +475,6 @@ pathOoptoBuffermaxLen(sqInt pathNameOop, char *cPathName, sqInt maxLen)
}


/* Answer the machine address contained in anExternalAddressOop. */

/* FileAttributesPlugin>>#pointerFrom: */
static void *
pointerFrom(sqInt directoryPointerBytes)
{
union {void *address; unsigned char bytes[sizeof(void *)];} addressUnion;
sqInt idx;
unsigned char *ptr;

if (!((isKindOf(directoryPointerBytes, "ByteArray"))
&& ((stSizeOf(directoryPointerBytes)) == (sizeof(void *))))) {
return null;
}
ptr = arrayValueOf(directoryPointerBytes);
idx = 0;
while (idx < (sizeof(void *))) {
addressUnion.bytes[idx] = ptr[idx];
idx += 1;
}
return addressUnion.address;
}


/* Set the mode of the supplied file using chmod(). */

/* FileAttributesPlugin>>#primitiveChangeMode */
Expand Down Expand Up @@ -1246,7 +1219,6 @@ setInterpreter(struct VirtualMachine *anInterpreter)
integerObjectOf = interpreterProxy->integerObjectOf;
#endif
ioLoadFunctionFrom = interpreterProxy->ioLoadFunctionFrom;
isKindOf = interpreterProxy->isKindOf;
isBytes = interpreterProxy->isBytes;
methodReturnBool = interpreterProxy->methodReturnBool;
methodReturnInteger = interpreterProxy->methodReturnInteger;
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/FileCopyPlugin/FileCopyPlugin.c
@@ -1,9 +1,9 @@
/* Automatically generated by
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2
from
FileCopyPlugin VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526
FileCopyPlugin VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2
*/
static char __buildInfo[] = "FileCopyPlugin VMMaker.oscog-eem.3166 uuid: bda1c176-bedf-4490-bb95-90d3851c1526 " __DATE__ ;
static char __buildInfo[] = "FileCopyPlugin VMMaker.oscog-eem.3216 uuid: 6a3c37f5-cdcd-4eda-874c-cd4ea7f427a2 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -63,7 +63,7 @@ extern sqInt stackValue(sqInt offset);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "FileCopyPlugin VMMaker.oscog-eem.3166 " INT_EXT;
static const char *moduleName = "FileCopyPlugin VMMaker.oscog-eem.3216 " INT_EXT;



Expand Down Expand Up @@ -93,8 +93,8 @@ primitiveFileCopyNamedTo(void)
&& (isBytes(stackValue(0))))) {
return primitiveFailFor(PrimErrBadArgument);
}
srcName = ((char *) (firstIndexableField(stackValue(1))));
dstName = ((char *) (firstIndexableField(stackValue(0))));
srcName = firstIndexableField(stackValue(1));
dstName = firstIndexableField(stackValue(0));
srcSz = slotSizeOf(((sqInt)(sqIntptr_t)(srcName) - BaseHeaderSize));
dstSz = slotSizeOf(((sqInt)(sqIntptr_t)(dstName) - BaseHeaderSize));
ok = sqCopyFilesizetosize(srcName, srcSz, dstName, dstSz);
Expand Down

0 comments on commit 0ca2861

Please sign in to comment.