feat(profile): more Lua information

This commit is contained in:
phaneron 2026-04-15 13:55:03 -04:00
parent 1479e2f5a0
commit fcf5f9352a
10 changed files with 233 additions and 12 deletions

View file

@ -0,0 +1,34 @@
#ifndef LUA_LEX_H
#define LUA_LEX_H
DECLARE_UNION(SemInfo);
DECLARE_STRUCT(LexState);
#include "lua/parser.h"
#include "lua/state.h"
union SemInfo {
lua_Number r;
TString* ts;
}; /* semantics information */
typedef struct Token {
int token;
SemInfo seminfo;
} Token;
struct LexState {
int32_t current; /* current character (charint) */
int32_t linenumber; /* input line counter */
int32_t lastline; /* line of last token `consumed' */
Token t; /* current token */
Token lookahead; /* look ahead token */
FuncState* fs; /* `FuncState' is private to the parser */
lua_State* L;
ZIO* z; /* input stream */
Mbuffer* buff; /* buffer for tokens */
TString* source; /* current source name */
char decpoint; /* locale decimal point */
};
#endif

View file

@ -140,6 +140,7 @@ struct UpVal {
struct CClosure {
GCObject* next;
uint32_t unk04;
lu_byte tt;
lu_byte marked;
lu_byte isC;
@ -155,7 +156,7 @@ struct LClosure {
lu_byte tt;
lu_byte marked;
lu_byte isC;
lu_byte nupvalues;
lu_byte nupvalues; // accessed at
GCObject* gclist;
Table* env;
Proto* p;

View file

@ -0,0 +1,44 @@
#ifndef LUA_PARSER_H
#define LUA_PARSER_H
DECLARE_STRUCT(upvaldesc);
DECLARE_STRUCT(BlockCnt);
DECLARE_STRUCT(FuncState);
#include "lua/lex.h"
#include "lua/object.h"
#include "lua/types.h"
struct upvaldesc {
lu_byte k;
lu_byte info;
};
struct BlockCnt {
BlockCnt* previous;
int32_t breaklist;
lu_byte nactvar;
lu_byte upval;
lu_byte isbreakable;
};
struct FuncState {
Proto* f;
Table* h;
FuncState* prev;
LexState* ls;
lua_State* L;
BlockCnt* bl;
int32_t pc;
int32_t lasttarget;
int32_t jpc;
int32_t freereg;
int32_t nk;
int32_t np;
int16_t nlocvars;
lu_byte nactvar;
upvaldesc upvalues[60];
uint16_t actvar[200];
};
#endif

View file

@ -13,6 +13,7 @@ DECLARE_STRUCT(LG);
#include "lua/object.h"
#include "lua/types.h"
#include "lua/zio.h"
struct stringtable {
GCObject** hash;

View file

@ -8,18 +8,19 @@
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;
};
DECLARE_ENUM(OpArgMask);
DECLARE_ENUM(OpMode);
DECLARE_ENUM(OpCode);
typedef void (*lua_Hook)(lua_State*, lua_Debug*);
typedef const char* (*lua_Reader_interface)(lua_State* L, void* ud, size_t* sz);
typedef lua_Reader_interface lua_Reader;
typedef void (*lua_Hook_interface)(lua_State*, lua_Debug*);
typedef lua_Hook_interface lua_Hook;
typedef uint8_t lu_byte;
@ -56,4 +57,73 @@ struct luaL_Reg {
lua_CFunction func;
};
enum OpArgMask {
OpArgN, /* argument is not used */
OpArgU, /* argument is used */
OpArgR, /* argument is a register or a jump offset */
OpArgK /* argument is a constant or register/constant */
};
enum OpMode { iABC, iABx, iAsBx };
enum OpCode {
/*----------------------------------------------------------------------
name args description
------------------------------------------------------------------------*/
OP_MOVE, /* A B R(A) := R(B) */
OP_LOADK, /* A Bx R(A) := Kst(Bx) */
OP_LOADBOOL, /* A B C R(A) := (Bool)B; if (C) pc++ */
OP_LOADNIL, /* A B R(A) := ... := R(B) := nil */
OP_GETUPVAL, /* A B R(A) := UpValue[B] */
OP_GETGLOBAL, /* A Bx R(A) := Gbl[Kst(Bx)] */
OP_GETTABLE, /* A B C R(A) := R(B)[RK(C)] */
OP_SETGLOBAL, /* A Bx Gbl[Kst(Bx)] := R(A) */
OP_SETUPVAL, /* A B UpValue[B] := R(A) */
OP_SETTABLE, /* A B C R(A)[RK(B)] := RK(C) */
OP_NEWTABLE, /* A B C R(A) := {} (size = B,C) */
OP_SELF, /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
OP_ADD, /* A B C R(A) := RK(B) + RK(C) */
OP_SUB, /* A B C R(A) := RK(B) - RK(C) */
OP_MUL, /* A B C R(A) := RK(B) * RK(C) */
OP_DIV, /* A B C R(A) := RK(B) / RK(C) */
OP_MOD, /* A B C R(A) := RK(B) % RK(C) */
OP_POW, /* A B C R(A) := RK(B) ^ RK(C) */
OP_UNM, /* A B R(A) := -R(B) */
OP_NOT, /* A B R(A) := not R(B) */
OP_LEN, /* A B R(A) := length of R(B) */
OP_CONCAT, /* A B C R(A) := R(B).. ... ..R(C) */
OP_JMP, /* sBx pc+=sBx */
OP_EQ, /* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
OP_LT, /* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
OP_LE, /* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
OP_TEST, /* A C if not (R(A) <=> C) then pc++ */
OP_TESTSET, /* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */
OP_CALL, /* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
OP_TAILCALL, /* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */
OP_RETURN, /* A B return R(A), ... ,R(A+B-2) (see note) */
OP_FORLOOP, /* A sBx R(A)+=R(A+2);
if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
OP_FORPREP, /* A sBx R(A)-=R(A+2); pc+=sBx */
OP_TFORLOOP, /* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */
OP_SETLIST, /* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
OP_CLOSE, /* A close all variables in the stack up to (>=) R(A)*/
OP_CLOSURE, /* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */
OP_VARARG /* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
};
#endif

View file

@ -0,0 +1,25 @@
#ifndef LUA_ZIO_H
#define LUA_ZIO_H
DECLARE_STRUCT(Mbuffer);
DECLARE_STRUCT(Zio);
typedef Zio ZIO;
struct Mbuffer {
char* buffer;
size_t n;
size_t buffsize;
};
#include "lua/state.h"
#include "lua/types.h"
struct Zio {
size_t n; /* bytes still unread */
const char* p; /* current position in buffer */
lua_Reader reader;
void* data; /* additional data */
lua_State* L; /* Lua state (for reader) */
};
#endif

View file

@ -10,7 +10,9 @@
#include "external/d3d9/d3d9.h"
#include "lua/debug.h"
#include "lua/lex.h"
#include "lua/object.h"
#include "lua/parser.h"
#include "lua/state.h"
#include "lua/types.h"

View file

@ -11,7 +11,49 @@ luaG_concaterror 00850BF0 f end=00850C13 type="void __stdcall func(lua_State* L,
luaG_typeerror 00850B60 f end=00850BEC type="void __stdcall func(lua_State* L, TValue* o, char* op)"
getobjname 008505A0 f end=008506F9 type="char* __usercall func@<eax>(lua_State* L, CallInfo* ci, int32_t stackpos@<eax>, char** name)"
symbexec 00850130 f end=0085050D type="Instruction __stdcall func(Proto* pt, int32_t lastpc, int32_t reg)"
checkArgMode 008500E0 f end=0085012C
luaG_checkopenop 008500B0 f end=008500DC type="bool __stdcall func(Instruction i)"
checkArgMode 008500E0 f end=0085012C type="int32_t __usercall func@<eax>(Proto* pt@<edx>, int32_t r@<ecx>, OpArgMask mode@<eax>)"
kname 00850570 f end=00850596 type="char* __usercall func@<eax>(Proto* p@<ecx>, int32_t c@<eax>)"
auxgetinfo 00850950 f end=00850A4C type="int32_t __usercall func@<eax>(lua_State* L, char* what, lua_Debug* ar@<esi>, Closure* f, CallInfo* ci@<ebx>)"
funcinfo 0084FF80 f end=0084FFF4 type="void __usercall func(lua_Debug* ar@<eax>, Closure* cl@<ecx>)"
currentline 0084FDF0 f end=0084FE33 type="int32_t __usercall func@<eax>(lua_State* L@<edx>, CallInfo* ci@<eax>)"
getfuncname 00850720 f end=008507C0 type="char* __usercall func@<eax>(lua_State* L@<edi>, CallInfo* ci@<ecx>, char** name)"
collectvalidlines 00850000 f end=008500AD type="void __usercall func(lua_State* L@<edi>, Closure* f@<ebx>)"
luaH_setnum 0085C590 f end=0085C5DA type="TValue* __stdcall func(lua_State* L, Table* t, int32_t key)"
luaH_getnum 0085C3A0 f end=0085C427 type="TValue* __stdcall func(Table* t, int32_t key)"
mainposition 0085BCB0 f end=0085BD56 type="Node* __usercall func@<eax>(Table* t@<eax>, TValue* key@<edx>)"
hashnum 0085BC70 f end=0085BCA6 type="Node* __usercall func@<eax>(Table* t@<esi>, lua_Number n)"
newkey 0085CAB0 f end=0085CBB4 type="TValue* __stdcall func(lua_State* L, Table* t, TValue* key)"
luaH_set 0085C520 f end=0085C582 type="void __stdcall func(lua_State* L, Table* t, TValue* key)"
numusearray 0085C050 f end=0085C0CD type="int32_t __stdcall func(Table* t, int32_t* nums)"
numusehash 0085C0D0 f end=0085C189 type="int32_t __usercall func@<eax>(Table* t@<ebx>, int32_t* nums, int32_t* pnasize)"
computesizes 0085BFD0 f end=0085C04D type="int32_t __stdcall func(int32_t* nums, int32_t* narray)"
resize 0085C6F0 f end=0085C95A type="void __usercall func(lua_State* L, Table* t@<ecx>, int32_t nasize@<eax>, int32_t nhsize)"
rehash 0085C9B0 f end=0085CAA3 type="void __usercall func(lua_State* L, Table* t@<eax>, TValue* ek@<edi>)"
luaH_setstr 0085CBC0 f end=0085CC08 type="void __stdcall func(lua_State* L, Table* t, TString* key)"
luaX_newstring 0085DA00 f end=0085DA50 type="TString* __stdcall func(LexState* ls, char* str, size_t l)"
save 0085D810 f end=0085D884 type="void __usercall func(LexState* ls@<ebx>, char c)"
luaX_lexerror 0085D940 f end=0085D9D3 type="void __stdcall func(LexState* ls, char* msg, int32_t token)"
luaO_pushfstring 0084D840 f end=0084D859 type="char* __stdcall func(lua_State* L, char* fmt, ...)"
luaX_token2str 0085D8E0 f end=0085D935 type="char* __stdcall func(LexState* ls, int32_t token)"
llex 0085E600 f end=0085EBF6 type="int32_t __usercall func@<eax>(LexState* ls@<eax>, SemInfo* seminfo)"
luaZ_fill 0085D0F0 f end=0085D132 type="int32_t __stdcall func(ZIO* z)"
inclinenumber 0085DA50 f end=0085DADC type="void __usercall func(LexState* ls@<esi>)"
read_string 0085E160 f end=0085E4E8 type="void __stdcall func(LexState* ls, int32_t del, SemInfo* seminfo)"
skip_sep 0085DDD0 f end=0085DE67 type="int32_t __stdcall func@<eax>(LexState* ls@<eax>)"
read_long_string 0085DE70 f end=0085E0E9 type="void __usercall func(LexState* ls@<eax>, SemInfo* seminfo@<edi>, int32_t sep)"
check_next 0085DB70 f end=0085DBCB type="int32_t __usercall func@<eax>(LexState* ls@<eax>, char* set@<ecx>)"
luaO_str2d 0084D480 f end=0084D51D type="bool __stdcall func(char* s, lua_Number* result)"
trydecpoint 0085DBD0 f end=0085DCAF type="void __usercall func(LexState* ls@<eax>, SemInfo* seminfo)"
read_numeral 0085DCB0 f end=0085DDC1 type="void __usercall func(LexState* ls@<eax>, SemInfo* seminfo@<edi>)"
luaX_lookahead 0085ED00 f end=0085ED1B type="void __stdcall func(LexState* ls)"
luaX_next 0085ECB0 f end=0085ECF9 type="void __stdcall func(LexState* ls)" ; TODO: understand changes to structures
testnext 0085ED70 f end=0085ED8F type="int32_t __usercall func@<eax>(LexState* ls@<eax>, int32_t c)"
check_match 0085ED90 f end=0085EDFE type="void __usercall func(LexState* ls@<esi>, int32_t what@<edi>, int32_t who, int32_t where@<eax>)"
singlevar 0085F1F0 f end=0085F24F type="void __usercall func(LexState* ls@<eax>, expdesc* var@<ebx>)"
singlevaraux 0085F100 f end=0085F1E2 type="int32_t __stdcall func(FuncState* fs, TString* n, expdesc* var, int base)"
indexupvalue 0085EFB0 f end=0085F0FB type="int32_t __stdcall func(FuncState* fs, TString* name, expdesc* v)"
luaM_growaux_ 0085D740 f end=0085D805 type="int32_t __stdcall func(lua_State* L, void* block, int32_t* size, size_t size_elems, int32_t limit, char* errormsg)"
lua_checkstack 0084DAB0 f end=0084DB06
lua_xmove 0084DB10 f end=0084DB90
lua_newthread 0084DB90 f end=0084DBD0
@ -116,7 +158,7 @@ luaC_gettime 0085B5A0 f end=0085B602
luaC_step 0085B950 f end=0085B9D2
luaC_fullgc 0085B9E0 f end=0085BA4B
luaC_barrierf 0085BA50 f end=0085BA83
luaC_barrierback 0085BA90 f end=0085BAAB
luaC_barrierback 0085BA90 f end=0085BAAB type="void __stdcall func(lua_State* L, Table* t)"
luaC_link 0085BAB0 f end=0085BAF1
luaT_gettm 0085BBE0 f end=0085BC09
luaT_gettmbyobj 0085BC10 f end=0085BC67
@ -163,8 +205,8 @@ luaL_openlib 0084FC00 f end=0084FD1E
lua_getlocal 0084FEC0 f end=0084FF26
luaG_errormsg 00850830 f end=0085091E
luaG_ordererror 00850C60 f end=00850CB2
_luaopen_string 00854070 f end=008540C3
_luaopen_base 00854F40 f end=0085505E
createmetatable 00854070 f end=008540C3 type="void __usercall func(lua_State* L@<esi>)"
base_open 00854F40 f end=0085505E type="void __usercall func(lua_State* L@<esi>)"
luaD_pcall 00855A20 f end=00855AD6
lua_yield 00856150 f end=00856184
luaV_gettable 00857250 f end=008573B5

View file

@ -7,3 +7,4 @@ lua_taintexpected 00D413A0 l type="int32_t"
lua_taintedclosure 00D413A4 l type="int32_t"
luaT_typenames 00A48208 l type="char*[11]"
luaP_opmodes 00A484B4 l type="lu_byte[38]"
luaX_tokens 00A48588 l type="char*[32]"

View file

@ -0,0 +1 @@
strtod 0088E9C1 f end=0088E9D4 type="double __stdcall func(char* str, char** endptr)"