forked from middlefeng/LuaVMRead
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlvm.c
86 lines (73 loc) · 3.38 KB
/
lvm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
lua_State
--------------------------------- ----------------- ----------------
| GCObject* next |
| lu_byte tt | CommonHeader
| lu_byte marked |
--------------------------------- ----------------- ----------------
| lu_byte status | Store the status of a stack-shrunk event, e.g. LUA_YIELD, and/or error code
| | of an "unprotected" call (i.e. errorJmp == NULL).
--------------------------------- ----------------- ----------------
| StkId top |
| global_State* l_G |
| CallInfo* ci |
| Instruction* oldpc | (debug info) for trace
| StkId stack_last | the first slot of EXTRA_STACK (room beyond maximally-allowed "top" but under "stacksize")
| StkId stack |
| int stacksize |
| unsigned short nny |
| unsigned short nCcalls | with dual-meaning: 1. Nested C call, 2. Nested syntac structure.
| ... |
| lua_longjmp* errorJmp | store the location and error-code of longjmp, except coroutine yeild.
| CallInfo base_ci | first level CallInfo
---------------------------------
global_State
--------------------------------- ----------------- ----------------
| lua_Alloc freealloc | memory allocator with its
| void* ud | user-data
--------------------------------- ----------------- ---------------- ---------------- ----------------
| lu_mem totalbytes | invariant: totalbytes + GCdebt = sizeof(LG) + "allocated" |
| l_mem GCdebt | just-allocated bytes | Seems not real purpose except
| lu_mem GCmemtrav | | guranteeing some invariants.
| lu_mem GCestimate | used as the "debt" of the next step |
--------------------------------- ----------------- ---------------- ---------------- ----------------
| GCObject** hash |
| lu_int32 nuse | stringtable strt
| int size |
--------------------------------- ----------------- ----------------
| TValue l_registry |
| unsigned int seed |
--------------------------------- ----------------- ----------------
| lu_byte currentwhite|
| lu_byte gcstate | GC incremental steps
| lu_byte gckind |
| lu_byte gcrunning |
| int sweepstrgc |
| ... |
-------------------
| |
| Local |
| |
-------------------
| |
| Copied Fixed | ci->p->numparams
| |
------------------- <---- ci->u.l.base Current
| | Stake Frame (Callee)
| |
| |
| Var Args |
| |
| |
------------------- ------------------------------
| |
| Fixed Params | ci->p->numparams
| | Previous
------------------- Stack Frame (Caller)
| Function |
------------------- <---- ci->func
| |
| |
ci->u.l.base is the "top" of the previous function call frame. In Lua, instructions specify var-length register
parameters by a number to indicate registers indexed from that number to the "stack top".
OP_VARARGS re-set the "stack top" if it accept "all" var-args so a following var-args function-call will get
right number of parameters from the "func" register to the "stack top".