get owned

This commit is contained in:
2026-06-18 22:38:01 +02:00
parent 3e1d0ba5d9
commit 2d043ca39f
7 changed files with 156 additions and 168 deletions

170
src/vm.h
View File

@@ -8,7 +8,7 @@
#endif
#ifndef NOOM_MAXCALL
#define NOOM_MAXCALL (NOOM_MAXSTACK/32)
#define NOOM_MAXCALL (NOOM_MAXSTACK / 32)
#endif
// Defines values, threads, bullshit, idc
@@ -25,8 +25,8 @@ typedef enum noomV_ObjTag {
typedef struct noomV_Object {
noomV_ObjTag tag;
noom_bool_t marked;
struct noomV_Object *next;
struct noomV_Object *nextGray;
struct noomV_Object* next;
struct noomV_Object* nextGray;
} noomV_Object;
typedef enum noomV_ValueTag : unsigned char {
@@ -49,9 +49,9 @@ typedef struct noomV_Value {
noom_bool_t boolean;
noom_int_t integer;
noom_float_t number;
void *lightuserdata;
noomV_Object *obj;
struct noomV_Pointer *ptr;
void* lightuserdata;
noomV_Object* obj;
struct noomV_Pointer* ptr;
};
} noomV_Value;
@@ -64,7 +64,7 @@ typedef struct noomV_String {
typedef struct noomV_Table {
noomV_Object obj;
struct noomV_Table *meta;
struct noomV_Table* meta;
// amount of entries allocated
noom_uint_t entries;
// how many entries are defined.
@@ -74,7 +74,7 @@ typedef struct noomV_Table {
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_Value* entrydata;
} noomV_Table;
typedef struct noomV_Pointer {
@@ -109,7 +109,7 @@ typedef enum noomV_Opcode : unsigned char {
NOOMV_INSTR_PUSHCLOSURE,
// High-level ops
// Call the function stored at stack[op.a]. All values after that are treated at arguments. op.uD is the expected return count plus one, and if op.uD is 0,
// all returns are pushed.
NOOMV_INSTR_CALL,
@@ -142,7 +142,7 @@ typedef enum noomV_Opcode : unsigned char {
NOOMV_INSTR_SETGLOBAL,
// Control flow
// returns from a function. The amount returned is from op.uD
NOOMV_INSTR_RET,
@@ -188,14 +188,14 @@ typedef struct noomV_Inst {
} noomV_Inst;
typedef struct noomV_UpvalDesc {
char *name;
char* name;
unsigned char idx;
// whether the index is a stack index
noom_bool_t isStack;
} noomV_UpvalDesc;
typedef struct noomV_LocalDesc {
char *name;
char* name;
unsigned char stackIdx;
// to forbid changing it with debug.setlocal
noom_bool_t isConst;
@@ -208,78 +208,78 @@ typedef struct noomV_LocalDesc {
typedef struct noomV_Function {
noomV_Object obj;
// source location string
noomV_String *chunkname;
noomV_String* chunkname;
// globals. Lua 5.1 only, use the _ENV upvalue for Lua 5.2+
noomV_Table *env;
noomV_Inst *code;
noomV_Value *consts;
struct noomV_Function **protos;
noomV_UpvalDesc *upvals;
noomV_LocalDesc *locals;
noomV_Table* env;
noomV_Inst* code;
noomV_Value* consts;
struct noomV_Function** protos;
noomV_UpvalDesc* upvals;
noomV_LocalDesc* locals;
unsigned int codesize;
// line of function
unsigned int linedefined;
// line of end
unsigned int lastlinedefined;
// very size limited
// ░░░░░░░░░ ░ ▒░░▒ ▒░ ░░ ░
// ░░░░░░░░░ ░ ▒░░▒ ▒░ ░░ ░
// ░░░░░░░░░ █░█░▓▓ ░█▒████▒░ █░░████▓
// ░░░░░░░░░ ▓████████░█░▒████▓░████ ░█░
// ░░░░░░░░░ ░░░ ░█▓░█▒█░█░▒▒█▓████▒ ░█▒█ ░█░░
// ░░░░░░░░░ ░░░░░ ░█▓▓███▒█ ▓▓▒▒▒▓▓▒ ▒█▒█▓██▓▓
// ░░░░░░░░░ ░░ ░▓▓███▓█▒░░█▒▓█▓██▓ ▒▓█▓▓▓█▒▒
// ░░░░░░░░░░ ░░ ▒▓█░█▒█░ ░▓▓██████░░██░░▒█
// ░░░░░░░░░░ ░░░░ ░░ ▓▓█▒█▓█▒░ ▒▒▒█▒░█░ ███░░█
// ░░░░░░░░░░ ░░ ▓▒▓███░█▒ ▒░░░▓▓█░░██░▓▒██
// ░░░░░░░░░░ ░░ ░ ░░ ░░ ░░ ░░ ▒░ ░░░ ░░
// ░░░░░░░░░░ ░ ░░░ ░ ░ ░ ░
// ░░░░░░░░░░ ░░░░ ░░ ░
// ░ ░░░░░░░░░ ░░░░ ░ ░ ░ ░░ ░░░ ░░░ ░ ░░
// ░░░░░░░░░ ░ █████ ▒████ ░▓███▓░ ░████░ ░████▓ ░████░ ░▓███▓ ░████░
//░░ ░░░░░░░░░ █▓▒██░░██▓██▒░░██▒██░░██▒▓██░▒██▒██ ██▓▓██ ░██▒██░ ██▒▓██
//░░ ░░░░░░░░░░ ██░▒█▓ ░██░██▒ ▒█▒░██ ░██ ██░ ▓█▒░██ ░██░██░ ▓█▒░██ ██░
// ░░░░░░░░░░░ ░▓███░▒█▓ ██░██░ ▒██▒██ ░██░██ ▒█▒░██ ░██░██░ ▒█▓▒█▓ ░██░
// ░░░░░░░░░░ ░ ░▒███░ ▓████░▓█▒ ░██░██░ ▒██▒█▓ ░██░██ ░▒█▒░██ ░██░██░ ░██▒█▓ ░██░░
// ░░░░░░░░░ ░░ ░ ░░██▓▓█▓░░██ ██░ ▒█▓▒█▓ ██░██░ ▒█▒░██ ░██░██░ ░██▒█▓ ░██░░
// ░░░░░░░░░░ ░░░░ ░ ░███▒██ ░██ ██▒ ▓█▒▒██ ░██░██░ ██░░██░░██ ██▒ ▓█░░██ ░██
// ░░░░░░░░░ ░░░ ░█████▒░█████▒▒▓█████ ░█████▒ ▒█████▓██████▓ ▒██▓██░ █████▒
// ░░░░░░░░░ ░░ ░████▒ ░░███▒░█▒▒███░ ░███▓ ▓███░▓█░███▓░ ▒███░ ░███▒
// ░░░░░░░░░░ ░█░ ░ ░ ▒▒ ░
// ░░░░░░░░░ ░ ░
// ░░░░░░░░░ ░░░░
// ░░░░░░░░░ ░░░░░ ░░ ░ ░ ░ ░
// ░░░░░░░░░ ░░ ░░▒░░ ░▓▒ ░█▓ ░ ░ ░
// ░░░░░░░░░ ░░ ▒█████░ ░██ ░██ ░ ░
// ░░░░░░░░░░░░░ ██▒▒███ ░░ ░ ░ ░░ ░░ ░██
// ░ ░░░░░░░░░░░░░░░ ██░ ░▓▓ ░████ ░████░░█▓ ▒███▓░░██
// ░░░░░░░░░░░░░░░░░░░░░▓███░░ ░██████░██▓██▓▒██░██▓██▒▒██░
// ░░░░░░░░░░░░░░░░░░░░ ░████░░█▓ ██░██ ▓▓░██ ░░▒██▓▒██░ ░
// ░░░░░░░░░░░░░░░░░░░ ░░░░███▒█▓ ██▒██ ░░██░█████▓▒██░ ░░ ░
// ░░░░░░░░░░░░░░░░░░ ░██▒ ░██▒██░░██░██ ░█▓░██░██░▓█▓░██░ ░ ██▓████████▓▒██▒
// ░░░░░░░░░░░░░░░░░ ░██████▓ █████▓ █████▓▒██░█████▓░██░ ░ ░░░███████████▓█▓
// ░░░░░░░░░░░░░░░░░░ ░▓███▒ ░███▒ ░▓██▓ ░█▓ ▒██▓█▓░██░ ░████████████▓█░
// ░░░░░░░░░░░░░░░░░ ░ ░ ░█████████▓██
// ░░░░░░░░░░░░░░ ░░ ▒███████▓█▓
// ░ ░░░░░░░░░░░░░░ ░░░░ ██▓██▓▓▓███ ░
// ░░░░░░░░░░░░░░░ ░░ ░ ░███████████
// ░░░░░░░░░░░░ ░░ ░ ████████████ ▒
// ░░░░░░░░░░░░ ░░▒▒░░ ░ ░██░▓█░ ░ ░░████ ▒██████ █
// ░░░░░░░░░░ ░░ ▒▓█░█▒█░ ░▓▓██████░░██░░▒█
// ░░░░░░░░░░ ░░░░ ░░ ▓▓█▒█▓█▒░ ▒▒▒█▒░█░ ███░░█
// ░░░░░░░░░░ ░░ ▓▒▓███░█▒ ▒░░░▓▓█░░██░▓▒██
// ░░░░░░░░░░ ░░ ░ ░░ ░░ ░░ ░░ ▒░ ░░░ ░░
// ░░░░░░░░░░ ░ ░░░ ░ ░ ░ ░
// ░░░░░░░░░░ ░░░░ ░░ ░
// ░ ░░░░░░░░░ ░░░░ ░ ░ ░ ░░ ░░░ ░░░ ░ ░░
// ░░░░░░░░░ ░ █████ ▒████ ░▓███▓░ ░████░ ░████▓ ░████░ ░▓███▓ ░████░
// ░░ ░░░░░░░░░ █▓▒██░░██▓██▒░░██▒██░░██▒▓██░▒██▒██ ██▓▓██ ░██▒██░ ██▒▓██
// ░░ ░░░░░░░░░░ ██░▒█▓ ░██░██▒ ▒█▒░██ ░██ ██░ ▓█▒░██ ░██░██░ ▓█▒░██ ██░
// ░░░░░░░░░░░ ░▓███░▒█▓ ██░██░ ▒██▒██ ░██░██ ▒█▒░██ ░██░██░ ▒█▓▒█▓ ░██░
// ░░░░░░░░░░ ░ ░▒███░ ▓████░▓█▒ ░██░██░ ▒██▒█▓ ░██░██ ░▒█▒░██ ░██░██░ ░██▒█▓ ░██░░
// ░░░░░░░░░ ░░ ░ ░░██▓▓█▓░░██ ██░ ▒█▓▒█▓ ██░██░ ▒█▒░██ ░██░██░ ░██▒█▓ ░██░░
// ░░░░░░░░░░ ░░░░ ░ ░███▒██ ░██ ██▒ ▓█▒▒██ ░██░██░ ██░░██░░██ ██▒ ▓█░░██ ░██
// ░░░░░░░░░ ░░░ ░█████▒░█████▒▒▓█████ ░█████▒ ▒█████▓██████▓ ▒██▓██░ █████▒
// ░░░░░░░░░ ░░ ░████▒ ░░███▒░█▒▒███░ ░███▓ ▓███░▓█░███▓░ ▒███░ ░███▒
// ░░░░░░░░░░ ░█░ ░ ░ ▒▒ ░
// ░░░░░░░░░ ░ ░
// ░░░░░░░░░ ░░░░
// ░░░░░░░░░ ░░░░░ ░░ ░ ░ ░ ░
// ░░░░░░░░░ ░░ ░░▒░░ ░▓▒ ░█▓ ░ ░ ░
// ░░░░░░░░░ ░░ ▒█████░ ░██ ░██ ░ ░
// ░░░░░░░░░░░░░ ██▒▒███ ░░ ░ ░ ░░ ░░ ░██
// ░ ░░░░░░░░░░░░░░░ ██░ ░▓▓ ░████ ░████░░█▓ ▒███▓░░██
// ░░░░░░░░░░░░░░░░░░░░░▓███░░ ░██████░██▓██▓▒██░██▓██▒▒██░
// ░░░░░░░░░░░░░░░░░░░░ ░████░░█▓ ██░██ ▓▓░██ ░░▒██▓▒██░ ░
// ░░░░░░░░░░░░░░░░░░░ ░░░░███▒█▓ ██▒██ ░░██░█████▓▒██░ ░░ ░
// ░░░░░░░░░░░░░░░░░░ ░██▒ ░██▒██░░██░██ ░█▓░██░██░▓█▓░██░ ░ ██▓████████▓▒██▒
// ░░░░░░░░░░░░░░░░░ ░██████▓ █████▓ █████▓▒██░█████▓░██░ ░ ░░░███████████▓█▓
// ░░░░░░░░░░░░░░░░░░ ░▓███▒ ░███▒ ░▓██▓ ░█▓ ▒██▓█▓░██░ ░████████████▓█░
// ░░░░░░░░░░░░░░░░░ ░ ░ ░█████████▓██
// ░░░░░░░░░░░░░░ ░░ ▒███████▓█▓
// ░ ░░░░░░░░░░░░░░ ░░░░ ██▓██▓▓▓███ ░
// ░░░░░░░░░░░░░░░ ░░ ░ ░███████████
// ░░░░░░░░░░░░ ░░ ░ ████████████ ▒
// ░░░░░░░░░░░░ ░░▒▒░░ ░ ░██░▓█░ ░ ░░████ ▒██████ █
// ░░░░░░░░░░░ ▓█████░ ░██ ██░░█▓░ ▓████ ▓█████ ░█ ▒▒
// ░░░░░░░░░░░ ▒██░░██▒░░░░░ ░░░░░ ░░░░██ ░░░██░ █████ ▒█████ ▒█ ▒█░
// ░░░░░░░░░░░░░ ██▒ ░█▓░████░████░ ░█████ ██▒████ █████ ▓████▒ ████░
// ░░░░░░░░░░░░░ ██▒ ░█▓░████░████░ ░█████ ██▒████ █████ ▓████▒ ████░
// ░░░░░░░░░░░░ ██░ ▒███▓██▓▓██ ██▒▒██ ██░▒██░ ████▒ █████ ▒████████
// ░░░░░░░░░░ ██░ ░ ▒██░ ██▒▒██░██ ░██ ██ ░██░ ░████ ░█████ ▓██▓▒░░
// ░░░░░░░░░░ ██▒ ░▒░▒██ ░██████▒██ ░██░██░░██ ▒███▒ █████▒
// ░ ░░░░░░░░░ ▓█▓░ ▓█▓▒██ ░██░ ░░░██ ░██ ██░░██░ ░███░░░█████
// ░░░░░░░░░ ██████ ▒█▓ ▓█████ ██████ ██░░███░ ░██▒ █████▒
// ░░░░░░░░░ ░▓███░░░█▓ ░░▒███░░░██▓█▓ ▓█░ ▒█▓░ ▓▓ ░█████
// ░░░░░░░░░ ░░░░ ░░ ░░ ░ ░ ▓▒ ▓████░
// ░░░░░░░░ ░░ ░░ ░ ▒▓ ████▒
// ░ ░░░░░ ░ ░ ▒░▓███▒
// ░░░░ ░ ░▓▓██
// ░░░
// ░░░
// ░░
// ░░░░░░░░░░ ██▒ ░▒░▒██ ░██████▒██ ░██░██░░██ ▒███▒ █████▒
// ░ ░░░░░░░░░ ▓█▓░ ▓█▓▒██ ░██░ ░░░██ ░██ ██░░██░ ░███░░░█████
// ░░░░░░░░░ ██████ ▒█▓ ▓█████ ██████ ██░░███░ ░██▒ █████▒
// ░░░░░░░░░ ░▓███░░░█▓ ░░▒███░░░██▓█▓ ▓█░ ▒█▓░ ▓▓ ░█████
// ░░░░░░░░░ ░░░░ ░░ ░░ ░ ░ ▓▒ ▓████░
// ░░░░░░░░ ░░ ░░ ░ ▒▓ ████▒
// ░ ░░░░░ ░ ░ ▒░▓███▒
// ░░░░ ░ ░▓▓██
// ░░░
// ░░░
// ░░
unsigned char argc;
unsigned char flags;
unsigned short constsize;
@@ -294,14 +294,14 @@ typedef struct noomV_CallFrame {
noom_bool_t isC;
union {
struct {
//
//
unsigned int pc;
// amount of varargs
unsigned int varargc;
} lua;
struct {
noom_KFunction *resumeFunc;
void *resumeCtx;
noom_KFunction* resumeFunc;
void* resumeCtx;
} c;
};
} noomV_CallFrame;
@@ -311,26 +311,26 @@ typedef struct noomV_Thread {
unsigned int stacklen, calldepth;
unsigned int stackcap, callcap;
// can have pointers!
noomV_Value *stack;
noomV_CallFrame *calls;
struct noomV_Thread *resumedBy;
struct noomV_Thread *resuming;
noomV_Value* stack;
noomV_CallFrame* calls;
struct noomV_Thread* resumedBy;
struct noomV_Thread* resuming;
} noomV_Thread;
struct noom_LuaVM {
noomV_Object *heap;
noomV_Object *graySet;
noomV_Table *globals;
noomV_Table *registry;
noomV_Thread *mainThread;
noomV_Thread *currentThread;
noomV_Object* heap;
noomV_Object* graySet;
noomV_Table* globals;
noomV_Table* registry;
noomV_Thread* mainThread;
noomV_Thread* currentThread;
noom_LuaVersion version;
};
// Allocating objects
noomV_Object *noomV_allocObj(noom_LuaVM *vm, noomV_ObjTag tag, noom_uint_t size);
noomV_String *noomV_allocStr(noom_LuaVM *vm, const char *str, noom_uint_t len);
noomV_Function *noomV_allocFunc(noom_LuaVM *vm, noomV_String *chunkname);
void noomV_freeObj(noomV_Object *obj);
noomV_Object* noomV_allocObj(noom_LuaVM* vm, noomV_ObjTag tag, noom_uint_t size);
noomV_String* noomV_allocStr(noom_LuaVM* vm, const char* str, noom_uint_t len);
noomV_Function* noomV_allocFunc(noom_LuaVM* vm, noomV_String* chunkname);
void noomV_freeObj(noomV_Object* obj);
#endif