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