Inline the bytecode array in ObjFn.

This commit is contained in:
Bob Nystrom
2013-12-25 16:19:35 -08:00
parent 8c4a58a0a3
commit e62bccd7f2
3 changed files with 3 additions and 4 deletions

View File

@ -114,7 +114,6 @@ ObjFn* wrenNewFunction(WrenVM* vm)
// Allocate these before the function in case they trigger a GC which would
// free the function.
// TODO: Hack! make variable sized.
unsigned char* bytecode = allocate(vm, sizeof(Code) * 1024);
Value* constants = allocate(vm, sizeof(Value) * 256);
ObjFn* fn = allocate(vm, sizeof(ObjFn));
@ -122,7 +121,6 @@ ObjFn* wrenNewFunction(WrenVM* vm)
fn->numConstants = 0;
fn->numUpvalues = 0;
fn->bytecode = bytecode;
fn->constants = constants;
return fn;

View File

@ -168,10 +168,12 @@ typedef struct
Obj obj;
int numConstants;
int numUpvalues;
unsigned char* bytecode;
// TODO: Flexible array?
Value* constants;
// TODO: Hack! Don't hardcode.
unsigned char bytecode[1024];
} ObjFn;
// An instance of a first-class function and the environment it has closed over.

View File

@ -332,7 +332,6 @@ static void freeObj(WrenVM* vm, Obj* obj)
switch (obj->type)
{
case OBJ_FN:
deallocate(vm, ((ObjFn*)obj)->bytecode);
deallocate(vm, ((ObjFn*)obj)->constants);
break;