From fc9f7c05b4c8945f40c0aac837fe9e78aedbfa99 Mon Sep 17 00:00:00 2001 From: ionut Date: Tue, 5 May 2026 23:38:00 +0300 Subject: [PATCH] banger commit --- build.lua | 9 +++- src/noom.h | 36 ++++++++++++++++ src/types.h | 5 +++ src/vm.h | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 src/vm.h diff --git a/build.lua b/build.lua index 5c741c3..c7da02a 100644 --- a/build.lua +++ b/build.lua @@ -2,6 +2,8 @@ -- TODO: script the build +local isBlendi = os.getenv("USER") == "blendi" + local function filename(path) local s,e = 1, #path for i = 1,#path do @@ -29,14 +31,17 @@ local files = { } local objects = {} + +local coolArgs = {} +if not isBlendi then table.insert(coolArgs, '-fsanitize=undefined,address') end for i = 1,#files do local fname = files[i] local out = "build/" .. filename(fname) .. '.o' - runCommand('clang -c -o ' .. out .. ' ' .. fname) + runCommand('clang -c -o ' .. out .. ' ' .. fname .. ' ' .. table.concat(coolArgs, ' ')) objects[#objects+1] = out; end -runCommand('clang -o noom ' .. table.concat(objects, ' ')) +runCommand('clang -o noom ' .. table.concat(objects, ' ') .. ' ' .. table.concat(coolArgs, ' ')) diff --git a/src/noom.h b/src/noom.h index a0bbec4..355aca9 100644 --- a/src/noom.h +++ b/src/noom.h @@ -1,5 +1,8 @@ // #define NOOM_USE_NFT +#ifndef NOOM_H +#define NOOM_H + typedef enum noom_LuaVersion { // no 5.0, at least for now, cause it doesn't seem to be used much and is a bit *weird* NOOM_VERSION_51, @@ -9,4 +12,37 @@ typedef enum noom_LuaVersion { // no you don't get 5.5; if someone wants to do it and maintain it, they can, i'm not gonna. } noom_LuaVersion; +typedef enum noom_LuaType { + NOOM_LUA_TNIL, + NOOM_LUA_TBOOL, + NOOM_LUA_TNUM, + NOOM_LUA_TSTR, + NOOM_LUA_TTABLE, + NOOM_LUA_TFUNCTION, + NOOM_LUA_TTHREAD, + NOOM_LUA_TUSERDATA, +} noom_LuaType; +typedef enum noom_Exit { + NOOM_OK = 0, + NOOM_YIELD, + // out of memory + NOOM_ENOMEM, + // runtime error + NOOM_ERUNTIME, + // stack overflow + NOOM_ENOSTACK, + // I/O error + NOOM_EIO, + // buffer overflow + NOOM_ELIMIT, + // error in error handler + NOOM_EERROR, +} noom_Exit; + +typedef struct noom_LuaVM noom_LuaVM; + +typedef noom_Exit noom_CFunction(noom_LuaVM *vm); +typedef noom_Exit noom_KFunction(noom_LuaVM *vm, noom_Exit status, void *ctx); + +#endif diff --git a/src/types.h b/src/types.h index 2033139..258bbb4 100644 --- a/src/types.h +++ b/src/types.h @@ -1,6 +1,11 @@ +#ifndef NOOM_TYPES +#define NOOM_TYPES + typedef unsigned long long int noom_uint_t; typedef signed long long int noom_int_t; typedef double noom_float_t; typedef unsigned char noom_bool_t; typedef void * noom_table_t; // atom figure this shit out typedef char * noom_string_t; + +#endif diff --git a/src/vm.h b/src/vm.h new file mode 100644 index 0000000..726058b --- /dev/null +++ b/src/vm.h @@ -0,0 +1,116 @@ +#ifndef NOOM_VM +#define NOOM_VM + +#include "types.h" + +// Defines values, threads, bullshit, idc + +typedef enum noomV_ObjTag { + NOOMV_OSTR, + NOOMV_OFUNC, + NOOMV_OCLOSURE, + NOOMV_OTABLE, + NOOMV_OUSERDATA, + NOOMV_OPOINTER, +} noomV_ObjTag; + +typedef struct noomV_Object { + noomV_ObjTag tag; + bool marked; + struct noomV_Object *next; + struct noomV_Object *nextGray; +} noomV_Object; + +typedef enum noomV_ValueTag { + NOOMV_VNIL, + NOOMV_VBOOL, + NOOMV_VINT, + NOOMV_VNUM, + NOOMV_VLUSER, + NOOMV_VCFUNC, + NOOMV_VOBJ, +} noomV_ValueTag; + +typedef struct noomV_Value { + noomV_ValueTag tag; + union { + noom_bool_t boolean; + noom_int_t integer; + noom_float_t number; + noomV_Object *obj; + }; +} noomV_Value; + +typedef struct noomV_String { + noomV_Object obj; + noom_uint_t len; + // Includes NUL-terminator! + char data[]; +} noomV_String; + +typedef struct noomV_Table { + noomV_Object obj; + struct noomV_Table *meta; + noom_uint_t entries; + noomV_Value *entrydata; +} noomV_Table; + +typedef struct noomV_Pointer { + noomV_Object obj; + noomV_Value value; +} noomV_Pointer; + +typedef enum noomV_Opcode : unsigned char { + NOOMV_NOP, + // TODO: rest of ops +} noomV_Opcode; + +typedef struct noomV_Inst { + noomV_Opcode op; + unsigned char A; + union { + struct { + unsigned char B; + unsigned char C; + }; + short sD; + unsigned short uD; + }; +} noomV_Inst; + +typedef struct noomV_UpvalDesc { + char *name; + unsigned char idx; + noom_bool_t isStack; +} noomV_UpvalDesc; + +typedef struct noomV_LocalDesc { + char *name; + unsigned char stackIdx; + // offset of first instruction where local exists + unsigned int pcStart; + // offset of first instruction where local is dropped + unsigned int pcEnd; +} noomV_LocalDesc; + +typedef struct noomV_Function { + noomV_Object obj; + // source location string + noomV_String *chunkname; + noomV_Inst *code; + noomV_Value *consts; + noomV_Function **protos; + noomV_UpvalDesc *upvals; + noomV_LocalDesc *locals; + unsigned int codesize; + unsigned int linedefined; + unsigned int lastlinedefined; + unsigned char argc; + unsigned char flags; + unsigned char constsize; + unsigned char protosize; + unsigned char upvalsize; + unsigned char localsize; +} noomV_Function; + +#endif