compiler: start work on binary expressions & stuff
Reviewed-on: #7 Co-authored-by: tema5002 <tema5002@tuta.io> Co-committed-by: tema5002 <tema5002@tuta.io>
This commit was merged in pull request #7.
This commit is contained in:
41
src/vm.c
41
src/vm.c
@@ -13,6 +13,47 @@ noomV_Object *noomV_allocObj(noom_LuaVM *vm, noomV_ObjTag tag, noom_uint_t size)
|
||||
return o;
|
||||
}
|
||||
|
||||
noomV_String *noomV_allocStr(noom_LuaVM *vm, const char *str, noom_uint_t len) {
|
||||
noomV_String *s = (noomV_String*)noomV_allocObj(vm, NOOMV_OSTR, sizeof(noomV_String) + len + 1);
|
||||
if (s == 0) return 0;
|
||||
noom_memcpy(s->data, str, len);
|
||||
s->data[len] = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
noomV_Function *noomV_allocFunc(noom_LuaVM *vm, const char *str, noom_uint_t len) {
|
||||
noomV_Function *f = (noomV_Function*)noomV_allocObj(vm, NOOMV_OFUNC, sizeof(noomV_Function));
|
||||
if (f == 0) return 0;
|
||||
f->chunkname = noomV_allocStr(vm, str, len);
|
||||
if (f->chunkname == 0) return 0;
|
||||
f->code = 0;
|
||||
f->consts = 0;
|
||||
f->protos = 0;
|
||||
f->upvals = 0;
|
||||
f->locals = 0;
|
||||
f->codesize = 0;
|
||||
f->linedefined = 0;
|
||||
f->lastlinedefined = 0;
|
||||
f->argc = 0;
|
||||
f->flags = 0;
|
||||
f->constsize = 0;
|
||||
f->protosize = 0;
|
||||
f->upvalsize = 0;
|
||||
f->localsize = 0;
|
||||
return f;
|
||||
}
|
||||
|
||||
noomV_Table *noomV_allocTable(noom_LuaVM *vm) {
|
||||
noomV_Table *t = (noomV_Table *)noomV_allocObj(vm, NOOMV_OTABLE, sizeof(noomV_Table));
|
||||
if (t == 0) return 0;
|
||||
t->meta = 0;
|
||||
t->entries = 0;
|
||||
t->used = 0;
|
||||
t->len = 0;
|
||||
t->entrydata = 0;
|
||||
return t;
|
||||
}
|
||||
|
||||
void noomV_freeObj(noomV_Object *obj) {
|
||||
noom_free(obj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user