Minor cleanup and refactoring.
This commit is contained in:
parent
aab02bcded
commit
db082967f4
@ -85,7 +85,6 @@ WrenVM* wrenNewVM(WrenConfiguration* configuration);
|
|||||||
void wrenFreeVM(WrenVM* vm);
|
void wrenFreeVM(WrenVM* vm);
|
||||||
|
|
||||||
// Runs [source], a string of Wren source code in a new fiber in [vm].
|
// Runs [source], a string of Wren source code in a new fiber in [vm].
|
||||||
// TODO: Define error codes.
|
|
||||||
WrenInterpretResult wrenInterpret(WrenVM* vm, const char* sourcePath,
|
WrenInterpretResult wrenInterpret(WrenVM* vm, const char* sourcePath,
|
||||||
const char* source);
|
const char* source);
|
||||||
|
|
||||||
|
|||||||
@ -1159,7 +1159,7 @@ static int resolveName(Compiler* compiler, const char* name, int length,
|
|||||||
// If we got here, it wasn't in a local scope, so try the global scope.
|
// If we got here, it wasn't in a local scope, so try the global scope.
|
||||||
*loadInstruction = CODE_LOAD_GLOBAL;
|
*loadInstruction = CODE_LOAD_GLOBAL;
|
||||||
return wrenSymbolTableFind(
|
return wrenSymbolTableFind(
|
||||||
&compiler->parser->vm->globalSymbols, name, length);
|
&compiler->parser->vm->globalNames, name, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copies the identifier from the previously consumed `TOKEN_NAME` into [name],
|
// Copies the identifier from the previously consumed `TOKEN_NAME` into [name],
|
||||||
@ -1300,7 +1300,7 @@ GrammarRule rules[];
|
|||||||
// instruction with an offset that jumps to the current end of bytecode.
|
// instruction with an offset that jumps to the current end of bytecode.
|
||||||
static void patchJump(Compiler* compiler, int offset)
|
static void patchJump(Compiler* compiler, int offset)
|
||||||
{
|
{
|
||||||
// - 2 to adjust for the bytecode for the jump offset itself.
|
// -2 to adjust for the bytecode for the jump offset itself.
|
||||||
int jump = compiler->bytecode.count - offset - 2;
|
int jump = compiler->bytecode.count - offset - 2;
|
||||||
// TODO: Check for overflow.
|
// TODO: Check for overflow.
|
||||||
compiler->bytecode.data[offset] = (jump >> 8) & 0xff;
|
compiler->bytecode.data[offset] = (jump >> 8) & 0xff;
|
||||||
@ -1420,7 +1420,7 @@ static int methodSymbol(Compiler* compiler, const char* name, int length)
|
|||||||
{
|
{
|
||||||
if (length == 0) length = (int)strlen(name);
|
if (length == 0) length = (int)strlen(name);
|
||||||
return wrenSymbolTableEnsure(compiler->parser->vm,
|
return wrenSymbolTableEnsure(compiler->parser->vm,
|
||||||
&compiler->parser->vm->methods, name, length);
|
&compiler->parser->vm->methodNames, name, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compiles an (optional) argument list and then calls it.
|
// Compiles an (optional) argument list and then calls it.
|
||||||
@ -1890,9 +1890,8 @@ static void new_(Compiler* compiler, bool allowAssignment)
|
|||||||
call(compiler, false);
|
call(compiler, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Give this a name the user can't type to prevent explicit calls.
|
// The leading space in the name is to ensure users can't call it directly.
|
||||||
// Instantiate the instance.
|
emitShort(compiler, CODE_CALL_0, methodSymbol(compiler, " instantiate", 12));
|
||||||
emitShort(compiler, CODE_CALL_0, methodSymbol(compiler, "instantiate", 11));
|
|
||||||
|
|
||||||
// Invoke the constructor on the new instance.
|
// Invoke the constructor on the new instance.
|
||||||
char name[MAX_METHOD_SIGNATURE];
|
char name[MAX_METHOD_SIGNATURE];
|
||||||
@ -2618,7 +2617,7 @@ static void classDefinition(Compiler* compiler)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the class with the number of fields.
|
// Update the class with the number of fields.
|
||||||
compiler->bytecode.data[numFieldsInstruction] = fields.names.count;
|
compiler->bytecode.data[numFieldsInstruction] = fields.count;
|
||||||
wrenSymbolTableClear(compiler->parser->vm, &fields);
|
wrenSymbolTableClear(compiler->parser->vm, &fields);
|
||||||
|
|
||||||
compiler->enclosingClass = NULL;
|
compiler->enclosingClass = NULL;
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
#define NATIVE(cls, name, fn) \
|
#define NATIVE(cls, name, fn) \
|
||||||
{ \
|
{ \
|
||||||
int symbol = wrenSymbolTableEnsure(vm, \
|
int symbol = wrenSymbolTableEnsure(vm, \
|
||||||
&vm->methods, name, strlen(name)); \
|
&vm->methodNames, name, strlen(name)); \
|
||||||
Method method; \
|
Method method; \
|
||||||
method.type = METHOD_PRIMITIVE; \
|
method.type = METHOD_PRIMITIVE; \
|
||||||
method.primitive = native_##fn; \
|
method.primitive = native_##fn; \
|
||||||
@ -909,7 +909,7 @@ static ObjClass* defineClass(WrenVM* vm, const char* name)
|
|||||||
// Returns the global variable named [name].
|
// Returns the global variable named [name].
|
||||||
static Value findGlobal(WrenVM* vm, const char* name)
|
static Value findGlobal(WrenVM* vm, const char* name)
|
||||||
{
|
{
|
||||||
int symbol = wrenSymbolTableFind(&vm->globalSymbols, name, strlen(name));
|
int symbol = wrenSymbolTableFind(&vm->globalNames, name, strlen(name));
|
||||||
return vm->globals.data[symbol];
|
return vm->globals.data[symbol];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -923,7 +923,7 @@ void wrenInitializeCore(WrenVM* vm)
|
|||||||
NATIVE(vm->objectClass, "new", object_new);
|
NATIVE(vm->objectClass, "new", object_new);
|
||||||
NATIVE(vm->objectClass, "toString", object_toString);
|
NATIVE(vm->objectClass, "toString", object_toString);
|
||||||
NATIVE(vm->objectClass, "type", object_type);
|
NATIVE(vm->objectClass, "type", object_type);
|
||||||
NATIVE(vm->objectClass, "instantiate", object_instantiate);
|
NATIVE(vm->objectClass, " instantiate", object_instantiate);
|
||||||
|
|
||||||
// Now we can define Class, which is a subclass of Object, but Object's
|
// Now we can define Class, which is a subclass of Object, but Object's
|
||||||
// metaclass.
|
// metaclass.
|
||||||
@ -937,8 +937,8 @@ void wrenInitializeCore(WrenVM* vm)
|
|||||||
// Define the methods specific to Class after wiring up its superclass to
|
// Define the methods specific to Class after wiring up its superclass to
|
||||||
// prevent the inherited ones from overwriting them.
|
// prevent the inherited ones from overwriting them.
|
||||||
// TODO: Now that instantiation is controlled by the class, implement "new"
|
// TODO: Now that instantiation is controlled by the class, implement "new"
|
||||||
// for List, Fiber, et. al.
|
// for List.
|
||||||
NATIVE(vm->classClass, "instantiate", class_instantiate);
|
NATIVE(vm->classClass, " instantiate", class_instantiate);
|
||||||
NATIVE(vm->classClass, "name", class_name);
|
NATIVE(vm->classClass, "name", class_name);
|
||||||
|
|
||||||
// The core class diagram ends up looking like this, where single lines point
|
// The core class diagram ends up looking like this, where single lines point
|
||||||
@ -967,7 +967,7 @@ void wrenInitializeCore(WrenVM* vm)
|
|||||||
NATIVE(vm->boolClass, "!", bool_not);
|
NATIVE(vm->boolClass, "!", bool_not);
|
||||||
|
|
||||||
vm->fiberClass = defineClass(vm, "Fiber");
|
vm->fiberClass = defineClass(vm, "Fiber");
|
||||||
NATIVE(vm->fiberClass->metaclass, "instantiate", fiber_instantiate);
|
NATIVE(vm->fiberClass->metaclass, " instantiate", fiber_instantiate);
|
||||||
NATIVE(vm->fiberClass->metaclass, "new ", fiber_new);
|
NATIVE(vm->fiberClass->metaclass, "new ", fiber_new);
|
||||||
NATIVE(vm->fiberClass->metaclass, "yield", fiber_yield);
|
NATIVE(vm->fiberClass->metaclass, "yield", fiber_yield);
|
||||||
NATIVE(vm->fiberClass->metaclass, "yield ", fiber_yield1);
|
NATIVE(vm->fiberClass->metaclass, "yield ", fiber_yield1);
|
||||||
@ -979,7 +979,7 @@ void wrenInitializeCore(WrenVM* vm)
|
|||||||
|
|
||||||
vm->fnClass = defineClass(vm, "Fn");
|
vm->fnClass = defineClass(vm, "Fn");
|
||||||
|
|
||||||
NATIVE(vm->fnClass->metaclass, "instantiate", fn_instantiate);
|
NATIVE(vm->fnClass->metaclass, " instantiate", fn_instantiate);
|
||||||
NATIVE(vm->fnClass->metaclass, "new ", fn_new);
|
NATIVE(vm->fnClass->metaclass, "new ", fn_new);
|
||||||
|
|
||||||
NATIVE(vm->fnClass, "call", fn_call0);
|
NATIVE(vm->fnClass, "call", fn_call0);
|
||||||
|
|||||||
@ -76,7 +76,7 @@ static int debugPrintInstruction(WrenVM* vm, ObjFn* fn, int i, int* lastLine)
|
|||||||
{
|
{
|
||||||
int global = READ_SHORT();
|
int global = READ_SHORT();
|
||||||
printf("%-16s %5d '%s'\n", "LOAD_GLOBAL", global,
|
printf("%-16s %5d '%s'\n", "LOAD_GLOBAL", global,
|
||||||
vm->globalSymbols.names.data[global]);
|
vm->globalNames.data[global]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ static int debugPrintInstruction(WrenVM* vm, ObjFn* fn, int i, int* lastLine)
|
|||||||
{
|
{
|
||||||
int global = READ_SHORT();
|
int global = READ_SHORT();
|
||||||
printf("%-16s %5d '%s'\n", "STORE_GLOBAL", global,
|
printf("%-16s %5d '%s'\n", "STORE_GLOBAL", global,
|
||||||
vm->globalSymbols.names.data[global]);
|
vm->globalNames.data[global]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ static int debugPrintInstruction(WrenVM* vm, ObjFn* fn, int i, int* lastLine)
|
|||||||
int numArgs = bytecode[i - 1] - CODE_CALL_0;
|
int numArgs = bytecode[i - 1] - CODE_CALL_0;
|
||||||
int symbol = READ_SHORT();
|
int symbol = READ_SHORT();
|
||||||
printf("CALL_%-11d %5d '%s'\n", numArgs, symbol,
|
printf("CALL_%-11d %5d '%s'\n", numArgs, symbol,
|
||||||
vm->methods.names.data[symbol]);
|
vm->methodNames.data[symbol]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ static int debugPrintInstruction(WrenVM* vm, ObjFn* fn, int i, int* lastLine)
|
|||||||
int numArgs = bytecode[i - 1] - CODE_SUPER_0;
|
int numArgs = bytecode[i - 1] - CODE_SUPER_0;
|
||||||
int symbol = READ_SHORT();
|
int symbol = READ_SHORT();
|
||||||
printf("SUPER_%-10d %5d '%s'\n", numArgs, symbol,
|
printf("SUPER_%-10d %5d '%s'\n", numArgs, symbol,
|
||||||
vm->methods.names.data[symbol]);
|
vm->methodNames.data[symbol]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ static int debugPrintInstruction(WrenVM* vm, ObjFn* fn, int i, int* lastLine)
|
|||||||
{
|
{
|
||||||
int symbol = READ_SHORT();
|
int symbol = READ_SHORT();
|
||||||
printf("%-16s %5d '%s'\n", "METHOD_INSTANCE", symbol,
|
printf("%-16s %5d '%s'\n", "METHOD_INSTANCE", symbol,
|
||||||
vm->methods.names.data[symbol]);
|
vm->methodNames.data[symbol]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ static int debugPrintInstruction(WrenVM* vm, ObjFn* fn, int i, int* lastLine)
|
|||||||
{
|
{
|
||||||
int symbol = READ_SHORT();
|
int symbol = READ_SHORT();
|
||||||
printf("%-16s %5d '%s'\n", "METHOD_STATIC", symbol,
|
printf("%-16s %5d '%s'\n", "METHOD_STATIC", symbol,
|
||||||
vm->methods.names.data[symbol]);
|
vm->methodNames.data[symbol]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,17 +9,17 @@ DEFINE_BUFFER(String, char*)
|
|||||||
|
|
||||||
void wrenSymbolTableInit(WrenVM* vm, SymbolTable* symbols)
|
void wrenSymbolTableInit(WrenVM* vm, SymbolTable* symbols)
|
||||||
{
|
{
|
||||||
wrenStringBufferInit(vm, &symbols->names);
|
wrenStringBufferInit(vm, symbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wrenSymbolTableClear(WrenVM* vm, SymbolTable* symbols)
|
void wrenSymbolTableClear(WrenVM* vm, SymbolTable* symbols)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < symbols->names.count; i++)
|
for (int i = 0; i < symbols->count; i++)
|
||||||
{
|
{
|
||||||
wrenReallocate(vm, symbols->names.data[i], 0, 0);
|
wrenReallocate(vm, symbols->data[i], 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
wrenStringBufferClear(vm, &symbols->names);
|
wrenStringBufferClear(vm, symbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int addSymbol(WrenVM* vm, SymbolTable* symbols,
|
static int addSymbol(WrenVM* vm, SymbolTable* symbols,
|
||||||
@ -29,8 +29,8 @@ static int addSymbol(WrenVM* vm, SymbolTable* symbols,
|
|||||||
strncpy(heapString, name, length);
|
strncpy(heapString, name, length);
|
||||||
heapString[length] = '\0';
|
heapString[length] = '\0';
|
||||||
|
|
||||||
wrenStringBufferWrite(vm, &symbols->names, heapString);
|
wrenStringBufferWrite(vm, symbols, heapString);
|
||||||
return symbols->names.count - 1;
|
return symbols->count - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wrenSymbolTableAdd(WrenVM* vm, SymbolTable* symbols, const char* name,
|
int wrenSymbolTableAdd(WrenVM* vm, SymbolTable* symbols, const char* name,
|
||||||
@ -57,10 +57,10 @@ int wrenSymbolTableFind(SymbolTable* symbols, const char* name, size_t length)
|
|||||||
{
|
{
|
||||||
// See if the symbol is already defined.
|
// See if the symbol is already defined.
|
||||||
// TODO: O(n). Do something better.
|
// TODO: O(n). Do something better.
|
||||||
for (int i = 0; i < symbols->names.count; i++)
|
for (int i = 0; i < symbols->count; i++)
|
||||||
{
|
{
|
||||||
if (strlen(symbols->names.data[i]) == length &&
|
if (strlen(symbols->data[i]) == length &&
|
||||||
strncmp(symbols->names.data[i], name, length) == 0) return i;
|
strncmp(symbols->data[i], name, length) == 0) return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@ -51,10 +51,7 @@ DECLARE_BUFFER(Byte, uint8_t);
|
|||||||
DECLARE_BUFFER(Int, int);
|
DECLARE_BUFFER(Int, int);
|
||||||
DECLARE_BUFFER(String, char*);
|
DECLARE_BUFFER(String, char*);
|
||||||
|
|
||||||
typedef struct
|
typedef StringBuffer SymbolTable;
|
||||||
{
|
|
||||||
StringBuffer names;
|
|
||||||
} SymbolTable;
|
|
||||||
|
|
||||||
// Initializes the symbol table.
|
// Initializes the symbol table.
|
||||||
void wrenSymbolTableInit(WrenVM* vm, SymbolTable* symbols);
|
void wrenSymbolTableInit(WrenVM* vm, SymbolTable* symbols);
|
||||||
|
|||||||
@ -36,8 +36,8 @@ WrenVM* wrenNewVM(WrenConfiguration* configuration)
|
|||||||
|
|
||||||
vm->reallocate = reallocate;
|
vm->reallocate = reallocate;
|
||||||
|
|
||||||
wrenSymbolTableInit(vm, &vm->methods);
|
wrenSymbolTableInit(vm, &vm->methodNames);
|
||||||
wrenSymbolTableInit(vm, &vm->globalSymbols);
|
wrenSymbolTableInit(vm, &vm->globalNames);
|
||||||
wrenValueBufferInit(vm, &vm->globals);
|
wrenValueBufferInit(vm, &vm->globals);
|
||||||
|
|
||||||
vm->bytesAllocated = 0;
|
vm->bytesAllocated = 0;
|
||||||
@ -88,8 +88,8 @@ void wrenFreeVM(WrenVM* vm)
|
|||||||
obj = next;
|
obj = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
wrenSymbolTableClear(vm, &vm->methods);
|
wrenSymbolTableClear(vm, &vm->methodNames);
|
||||||
wrenSymbolTableClear(vm, &vm->globalSymbols);
|
wrenSymbolTableClear(vm, &vm->globalNames);
|
||||||
wrenValueBufferClear(vm, &vm->globals);
|
wrenValueBufferClear(vm, &vm->globals);
|
||||||
|
|
||||||
wrenReallocate(vm, vm, 0, 0);
|
wrenReallocate(vm, vm, 0, 0);
|
||||||
@ -528,7 +528,7 @@ static bool runInterpreter(WrenVM* vm)
|
|||||||
char message[100];
|
char message[100];
|
||||||
snprintf(message, 100, "%s does not implement method '%s'.",
|
snprintf(message, 100, "%s does not implement method '%s'.",
|
||||||
classObj->name->value,
|
classObj->name->value,
|
||||||
vm->methods.names.data[symbol]);
|
vm->methodNames.data[symbol]);
|
||||||
RUNTIME_ERROR(message);
|
RUNTIME_ERROR(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,7 +581,7 @@ static bool runInterpreter(WrenVM* vm)
|
|||||||
char message[100];
|
char message[100];
|
||||||
snprintf(message, 100, "%s does not implement method '%s'.",
|
snprintf(message, 100, "%s does not implement method '%s'.",
|
||||||
classObj->name->value,
|
classObj->name->value,
|
||||||
vm->methods.names.data[symbol]);
|
vm->methodNames.data[symbol]);
|
||||||
RUNTIME_ERROR(message);
|
RUNTIME_ERROR(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -635,8 +635,7 @@ static bool runInterpreter(WrenVM* vm)
|
|||||||
{
|
{
|
||||||
char message[100];
|
char message[100];
|
||||||
snprintf(message, 100, "%s does not implement method '%s'.",
|
snprintf(message, 100, "%s does not implement method '%s'.",
|
||||||
classObj->name->value,
|
classObj->name->value, vm->methodNames.data[symbol]);
|
||||||
vm->methods.names.data[symbol]);
|
|
||||||
RUNTIME_ERROR(message);
|
RUNTIME_ERROR(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,8 +687,7 @@ static bool runInterpreter(WrenVM* vm)
|
|||||||
{
|
{
|
||||||
char message[100];
|
char message[100];
|
||||||
snprintf(message, 100, "%s does not implement method '%s'.",
|
snprintf(message, 100, "%s does not implement method '%s'.",
|
||||||
classObj->name->value,
|
classObj->name->value, vm->methodNames.data[symbol]);
|
||||||
vm->methods.names.data[symbol]);
|
|
||||||
RUNTIME_ERROR(message);
|
RUNTIME_ERROR(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1025,7 +1023,7 @@ int wrenDefineGlobal(WrenVM* vm, const char* name, size_t length, Value value)
|
|||||||
|
|
||||||
if (IS_OBJ(value)) WREN_PIN(vm, AS_OBJ(value));
|
if (IS_OBJ(value)) WREN_PIN(vm, AS_OBJ(value));
|
||||||
|
|
||||||
int symbol = wrenSymbolTableAdd(vm, &vm->globalSymbols, name, length);
|
int symbol = wrenSymbolTableAdd(vm, &vm->globalNames, name, length);
|
||||||
if (symbol != -1) wrenValueBufferWrite(vm, &vm->globals, value);
|
if (symbol != -1) wrenValueBufferWrite(vm, &vm->globals, value);
|
||||||
|
|
||||||
if (IS_OBJ(value)) WREN_UNPIN(vm);
|
if (IS_OBJ(value)) WREN_UNPIN(vm);
|
||||||
@ -1061,7 +1059,7 @@ static void defineMethod(WrenVM* vm, const char* className,
|
|||||||
ASSERT(methodFn != NULL, "Must provide method function.");
|
ASSERT(methodFn != NULL, "Must provide method function.");
|
||||||
|
|
||||||
// Find or create the class to bind the method to.
|
// Find or create the class to bind the method to.
|
||||||
int classSymbol = wrenSymbolTableFind(&vm->globalSymbols,
|
int classSymbol = wrenSymbolTableFind(&vm->globalNames,
|
||||||
className, strlen(className));
|
className, strlen(className));
|
||||||
ObjClass* classObj;
|
ObjClass* classObj;
|
||||||
|
|
||||||
@ -1095,7 +1093,7 @@ static void defineMethod(WrenVM* vm, const char* className,
|
|||||||
name[length] = '\0';
|
name[length] = '\0';
|
||||||
|
|
||||||
// Bind the method.
|
// Bind the method.
|
||||||
int methodSymbol = wrenSymbolTableEnsure(vm, &vm->methods, name, length);
|
int methodSymbol = wrenSymbolTableEnsure(vm, &vm->methodNames, name, length);
|
||||||
|
|
||||||
Method method;
|
Method method;
|
||||||
method.type = METHOD_FOREIGN;
|
method.type = METHOD_FOREIGN;
|
||||||
|
|||||||
@ -202,8 +202,6 @@ typedef struct sPinnedObj
|
|||||||
// TODO: Move into wren_vm.c?
|
// TODO: Move into wren_vm.c?
|
||||||
struct WrenVM
|
struct WrenVM
|
||||||
{
|
{
|
||||||
SymbolTable methods;
|
|
||||||
|
|
||||||
// TODO: Use an array for some of these.
|
// TODO: Use an array for some of these.
|
||||||
ObjClass* boolClass;
|
ObjClass* boolClass;
|
||||||
ObjClass* classClass;
|
ObjClass* classClass;
|
||||||
@ -216,16 +214,9 @@ struct WrenVM
|
|||||||
ObjClass* rangeClass;
|
ObjClass* rangeClass;
|
||||||
ObjClass* stringClass;
|
ObjClass* stringClass;
|
||||||
|
|
||||||
// TODO: Move to end of struct since less frequently accessed?
|
// The currently defined global variables.
|
||||||
SymbolTable globalSymbols;
|
|
||||||
|
|
||||||
ValueBuffer globals;
|
ValueBuffer globals;
|
||||||
|
|
||||||
// The compiler that is currently compiling code. This is used so that heap
|
|
||||||
// allocated objects used by the compiler can be found if a GC is kicked off
|
|
||||||
// in the middle of a compile.
|
|
||||||
Compiler* compiler;
|
|
||||||
|
|
||||||
// The fiber that is currently running.
|
// The fiber that is currently running.
|
||||||
ObjFiber* fiber;
|
ObjFiber* fiber;
|
||||||
|
|
||||||
@ -258,6 +249,8 @@ struct WrenVM
|
|||||||
// The externally-provided function used to allocate memory.
|
// The externally-provided function used to allocate memory.
|
||||||
WrenReallocateFn reallocate;
|
WrenReallocateFn reallocate;
|
||||||
|
|
||||||
|
// Foreign function data:
|
||||||
|
|
||||||
// During a foreign function call, this will point to the first argument (the
|
// During a foreign function call, this will point to the first argument (the
|
||||||
// receiver) of the call on the fiber's stack.
|
// receiver) of the call on the fiber's stack.
|
||||||
Value* foreignCallSlot;
|
Value* foreignCallSlot;
|
||||||
@ -265,6 +258,21 @@ struct WrenVM
|
|||||||
// During a foreign function call, this will contain the number of arguments
|
// During a foreign function call, this will contain the number of arguments
|
||||||
// to the function.
|
// to the function.
|
||||||
int foreignCallNumArgs;
|
int foreignCallNumArgs;
|
||||||
|
|
||||||
|
// Compiler and debugger data:
|
||||||
|
|
||||||
|
// The compiler that is currently compiling code. This is used so that heap
|
||||||
|
// allocated objects used by the compiler can be found if a GC is kicked off
|
||||||
|
// in the middle of a compile.
|
||||||
|
Compiler* compiler;
|
||||||
|
|
||||||
|
// There is a single global symbol table for all method names on all classes.
|
||||||
|
// Method calls are dispatched directly by index in this table.
|
||||||
|
SymbolTable methodNames;
|
||||||
|
|
||||||
|
// Symbol table for the names of all global variables. Indexes here directly
|
||||||
|
// correspond to entries in [globals].
|
||||||
|
SymbolTable globalNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
// A generic allocation function that handles all explicit memory management.
|
// A generic allocation function that handles all explicit memory management.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user