Compare commits

...

2 Commits

Author SHA1 Message Date
be75ccd6f8 parser: apparently i don't know how realloc works 2026-06-02 21:04:34 +02:00
269d2c8ae9 documented the vm more 2026-05-27 15:43:13 +02:00
2 changed files with 19 additions and 5 deletions

View File

@@ -149,13 +149,15 @@ noomP_Node* noomP_allocNode(noomP_Parser* parser) {
int noomP_addSubnode(noomP_Parser* parser, noomP_Node* node, noomP_Node* subnode) {
if (node->subnodec == node->subnode_cap) {
node->subnode_cap = node->subnode_cap * 2;
node->subnodes = noom_realloc(node->subnodes, sizeof(noomP_Node*) * node->subnode_cap);
if (node->subnodes == 0) {
parser->error_state = NOOMP_ERROR_OOM;
noomP_Node** new = noom_realloc(node->subnodes, sizeof(noomP_Node*) * node->subnode_cap * 2);
if (new == 0) {
parser->error_state = NOOMP_ERROR_OOM; // well fuck
return 1;
}
node->subnodes = new;
node->subnode_cap = node->subnode_cap * 2;
}
node->subnodes[node->subnodec++] = subnode;

View File

@@ -51,6 +51,7 @@ typedef struct noomV_Value {
noom_int_t integer;
noom_float_t number;
noomV_Object *obj;
struct noomV_Pointer *ptr;
};
} noomV_Value;
@@ -64,8 +65,15 @@ typedef struct noomV_String {
typedef struct noomV_Table {
noomV_Object obj;
struct noomV_Table *meta;
// amount of entries allocated
noom_uint_t entries;
// how many entries are defined.
// Note, this includes keys with null values, which are still scanned.
noom_uint_t used;
// cache of #t, for faster subsequent fetches
noom_uint_t len;
// actual values. Given index i, V[i] is the key and V[i+entries] is the value.
// This is because we mostly read the key, so we should put more keys in cache.
noomV_Value *entrydata;
} noomV_Table;
@@ -166,6 +174,7 @@ typedef struct noomV_Inst {
typedef struct noomV_UpvalDesc {
char *name;
unsigned char idx;
// whether the index is a stack index
noom_bool_t isStack;
} noomV_UpvalDesc;
@@ -188,7 +197,9 @@ typedef struct noomV_Function {
noomV_UpvalDesc *upvals;
noomV_LocalDesc *locals;
unsigned int codesize;
// line of function
unsigned int linedefined;
// line of end
unsigned int lastlinedefined;
// very size limited
// ░░░░░░░░░ ░ ▒░░▒ ▒░ ░░ ░
@@ -296,6 +307,7 @@ struct noom_LuaVM {
noom_LuaVersion version;
};
// Allocating objects
noomV_Object *noomV_allocObj(noom_LuaVM *vm, noomV_ObjTag tag, noom_uint_t size);
void noomV_freeObj(noomV_Object *obj);