feat(profile): refactor lua, bc code

This commit is contained in:
phaneron 2026-04-01 17:37:40 -04:00
parent e79ee08905
commit 37db5336e4
40 changed files with 3424 additions and 0 deletions

View file

@ -0,0 +1,20 @@
#ifndef LUA_DEBUG_H
#define LUA_DEBUG_H
DECLARE_STRUCT(lua_Debug);
struct lua_Debug {
int32_t event;
char* name;
char* namewhat;
char* what;
char* source;
int32_t currentline;
int32_t nups;
int32_t linedefined;
int32_t lastlinedefined;
char short_src[60];
int32_t i_ci;
};
#endif

View file

@ -0,0 +1,199 @@
#ifndef LUA_OBJECT_H
#define LUA_OBJECT_H
DECLARE_UNION(GCObject);
DECLARE_STRUCT(GCheader);
DECLARE_UNION(Value);
DECLARE_STRUCT(lua_TValue);
typedef lua_TValue TValue;
typedef TValue* StkId;
DECLARE_STRUCT(TString_tsv);
DECLARE_UNION(TString);
DECLARE_STRUCT(Udata_uv);
DECLARE_UNION(Udata);
DECLARE_STRUCT(Proto);
DECLARE_STRUCT(LocVar);
DECLARE_STRUCT(UpVal_u_l);
DECLARE_UNION(UpVal_u);
DECLARE_STRUCT(UpVal);
DECLARE_STRUCT(CClosure);
DECLARE_STRUCT(LClosure);
DECLARE_UNION(Closure);
DECLARE_STRUCT(TKey_nk);
DECLARE_UNION(TKey);
DECLARE_STRUCT(Node);
DECLARE_STRUCT(Table);
#include "lua/types.h"
struct GCheader {
GCObject* next;
lu_byte tt;
lu_byte marked;
};
union Value {
GCObject* gc;
void* p;
lua_Number n;
int32_t b;
};
struct lua_TValue {
Value value;
int32_t tt;
uint32_t tainted; // UC: Added by Blizzard
};
struct TString_tsv {
GCObject* next;
lu_byte tt;
lu_byte marked;
lu_byte reserved;
uint32_t hash;
size_t len;
};
union TString {
L_Umaxalign dummy;
TString_tsv tsv;
};
struct Udata_uv {
GCObject* next;
lu_byte tt;
lu_byte marked;
Table* metatable;
Table* env;
size_t len;
};
union Udata {
L_Umaxalign dummy;
Udata_uv uv;
};
struct Proto {
GCObject* next;
lu_byte tt;
lu_byte marked;
TValue* k;
Instruction* code;
Proto** p;
int32_t* lineinfo;
LocVar* locvars;
TString** upvalues;
TString* source;
int32_t sizeupvalues;
int32_t sizek;
int32_t sizecode;
int32_t sizelineinfo;
int32_t sizep;
int32_t sizelocvars;
int32_t linedefined;
int32_t lastlinedefined;
GCObject* gclist;
lu_byte nups;
lu_byte numparams;
lu_byte is_vararg;
lu_byte maxstacksize;
};
struct LocVar {
TString* varname;
int32_t startpc;
int32_t endpc;
};
struct UpVal_u_l {
UpVal* prev;
UpVal* next;
};
union UpVal_u {
TValue value;
UpVal_u_l l;
};
struct UpVal {
GCObject* next;
lu_byte tt;
lu_byte marked;
TValue* v;
UpVal_u u;
};
struct CClosure {
GCObject* next;
lu_byte tt;
lu_byte marked;
lu_byte isC;
lu_byte nupvalues;
GCObject* gclist;
Table* env;
lua_CFunction f;
TValue upvalue[1];
};
struct LClosure {
GCObject* next;
lu_byte tt;
lu_byte marked;
lu_byte isC;
lu_byte nupvalues;
GCObject* gclist;
Table* env;
Proto* p;
UpVal* upvals[1];
};
union Closure {
CClosure c;
LClosure l;
};
struct TKey_nk {
Value value;
int32_t tt;
Node* next;
};
union TKey {
TKey_nk nk;
TValue tvk;
};
struct Node {
TValue i_val;
TKey i_key;
};
struct Table {
GCObject* next;
lu_byte tt;
lu_byte marked;
lu_byte flags;
lu_byte lsizenode;
Table* metatable;
TValue* array;
Node* node;
Node* lastfree;
GCObject* gclist;
int32_t sizearray;
};
#endif

View file

@ -0,0 +1,99 @@
#ifndef LUA_STATE_H
#define LUA_STATE_H
DECLARE_STRUCT(stringtable);
DECLARE_STRUCT(CallInfo);
DECLARE_STRUCT(global_State);
DECLARE_STRUCT(lua_State);
#include "lua/object.h"
#include "lua/types.h"
struct stringtable {
GCObject** hash;
lu_int32 nuse;
int32_t size;
};
struct CallInfo {
StkId base;
StkId func;
StkId top;
Instruction* savedpc;
int32_t nresults;
int32_t tailcalls;
};
struct global_State {
stringtable strt;
lua_Alloc frealloc;
void* ud;
lu_byte currentwhite;
lu_byte gcstate;
int32_t sweepstrgc;
GCObject* rootgc;
GCObject** sweepgc;
GCObject* gray;
GCObject* grayagain;
GCObject* weak;
GCObject* tmudata;
Mbuffer buff;
lu_mem GCthreshold;
lu_mem totalbytes;
lu_mem estimate;
lu_mem gcdept;
int32_t gcpause;
int32_t gcstepmul;
lua_CFunction panic;
TValue l_registry;
lua_State* mainthread;
UpVal uvhead;
Table* mt[9];
TString* tmname[0];
};
struct lua_State {
GCObject* next;
lu_byte tt;
lu_byte marked;
lu_byte status;
StkId top;
StkId base;
global_State* l_G;
CallInfo* ci;
Instruction* savedpc;
StkId stack_last;
StkId stack;
CallInfo* end_ci;
CallInfo* base_ci;
int32_t stacksize;
int32_t size_ci;
uint16_t nCcalls;
lu_byte hookmask;
lu_byte allowhook;
int32_t basehookcount;
int32_t hookcount;
lua_Hook hook;
TValue l_gt;
TValue env;
GCObject* openupval;
GCObject* gclist;
lua_longjmp* errorJmp;
ptrdiff_t errfunc;
};
union GCObject {
GCheader gch;
TString ts;
Udata u;
Closure cl;
Table h;
Proto p;
UpVal uv;
lua_State th;
};
#endif

View file

@ -0,0 +1,57 @@
#ifndef LUA_TYPES_H
#define LUA_TYPES_H
#define LUA_REGISTRYINDEX -10000
#define LUA_ENVIRONINDEX -10001
#define LUA_GLOBALSINDEX -10002
DECLARE_STRUCT(lua_State);
DECLARE_STRUCT(lua_Debug);
DECLARE_STRUCT(Mbuffer);
DECLARE_UNION(L_Umaxalign);
DECLARE_STRUCT(lua_longjmp);
DECLARE_STRUCT(luaL_Reg);
struct Mbuffer {
char* buffer;
size_t n;
size_t buffsize;
};
typedef void (*lua_Hook)(lua_State*, lua_Debug*);
typedef uint8_t lu_byte;
typedef uint32_t lu_int32;
typedef uint32_t lu_mem;
typedef double lua_Number;
union L_Umaxalign {
double u;
void* s;
long l;
};
/* chain list of long jump buffers */
struct lua_longjmp {
lua_longjmp* previous;
// luai_jmpbuf b;
int b;
volatile int status; /* error code */
};
typedef lu_int32 Instruction;
typedef int32_t (*lua_CFunction)(lua_State*);
typedef void* (*lua_Alloc)(void*, void*, size_t, size_t);
struct luaL_Reg {
const char* name;
lua_CFunction func;
};
#endif