aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
Diffstat (limited to 'lopcodes.h')
-rw-r--r--lopcodes.h35
1 files changed, 29 insertions, 6 deletions
diff --git a/lopcodes.h b/lopcodes.h
index 63918be1..736946e3 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -19,25 +19,30 @@
19 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 19 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
20 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 20 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
21iABC C(8) | B(8) |k| A(8) | Op(7) | 21iABC C(8) | B(8) |k| A(8) | Op(7) |
22ivABC vC(10) | vB(6) |k| A(8) | Op(7) |
22iABx Bx(17) | A(8) | Op(7) | 23iABx Bx(17) | A(8) | Op(7) |
23iAsBx sBx (signed)(17) | A(8) | Op(7) | 24iAsBx sBx (signed)(17) | A(8) | Op(7) |
24iAx Ax(25) | Op(7) | 25iAx Ax(25) | Op(7) |
25isJ sJ (signed)(25) | Op(7) | 26isJ sJ (signed)(25) | Op(7) |
26 27
28 ('v' stands for "variant", 's' for "signed", 'x' for "extended".)
27 A signed argument is represented in excess K: The represented value is 29 A signed argument is represented in excess K: The represented value is
28 the written unsigned value minus K, where K is half (rounded down) the 30 the written unsigned value minus K, where K is half (rounded down) the
29 maximum value for the corresponding unsigned argument. 31 maximum value for the corresponding unsigned argument.
30===========================================================================*/ 32===========================================================================*/
31 33
32 34
33enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */ 35/* basic instruction formats */
36enum OpMode {iABC, ivABC, iABx, iAsBx, iAx, isJ};
34 37
35 38
36/* 39/*
37** size and position of opcode arguments. 40** size and position of opcode arguments.
38*/ 41*/
39#define SIZE_C 8 42#define SIZE_C 8
43#define SIZE_vC 10
40#define SIZE_B 8 44#define SIZE_B 8
45#define SIZE_vB 6
41#define SIZE_Bx (SIZE_C + SIZE_B + 1) 46#define SIZE_Bx (SIZE_C + SIZE_B + 1)
42#define SIZE_A 8 47#define SIZE_A 8
43#define SIZE_Ax (SIZE_Bx + SIZE_A) 48#define SIZE_Ax (SIZE_Bx + SIZE_A)
@@ -50,7 +55,9 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
50#define POS_A (POS_OP + SIZE_OP) 55#define POS_A (POS_OP + SIZE_OP)
51#define POS_k (POS_A + SIZE_A) 56#define POS_k (POS_A + SIZE_A)
52#define POS_B (POS_k + 1) 57#define POS_B (POS_k + 1)
58#define POS_vB (POS_k + 1)
53#define POS_C (POS_B + SIZE_B) 59#define POS_C (POS_B + SIZE_B)
60#define POS_vC (POS_vB + SIZE_vB)
54 61
55#define POS_Bx POS_k 62#define POS_Bx POS_k
56 63
@@ -95,7 +102,9 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
95 102
96#define MAXARG_A ((1<<SIZE_A)-1) 103#define MAXARG_A ((1<<SIZE_A)-1)
97#define MAXARG_B ((1<<SIZE_B)-1) 104#define MAXARG_B ((1<<SIZE_B)-1)
105#define MAXARG_vB ((1<<SIZE_vB)-1)
98#define MAXARG_C ((1<<SIZE_C)-1) 106#define MAXARG_C ((1<<SIZE_C)-1)
107#define MAXARG_vC ((1<<SIZE_vC)-1)
99#define OFFSET_sC (MAXARG_C >> 1) 108#define OFFSET_sC (MAXARG_C >> 1)
100 109
101#define int2sC(i) ((i) + OFFSET_sC) 110#define int2sC(i) ((i) + OFFSET_sC)
@@ -126,16 +135,24 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
126#define GETARG_A(i) getarg(i, POS_A, SIZE_A) 135#define GETARG_A(i) getarg(i, POS_A, SIZE_A)
127#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A) 136#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
128 137
129#define GETARG_B(i) check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B)) 138#define GETARG_B(i) \
139 check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B))
140#define GETARG_vB(i) \
141 check_exp(checkopm(i, ivABC), getarg(i, POS_vB, SIZE_vB))
130#define GETARG_sB(i) sC2int(GETARG_B(i)) 142#define GETARG_sB(i) sC2int(GETARG_B(i))
131#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B) 143#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
144#define SETARG_vB(i,v) setarg(i, v, POS_vB, SIZE_vB)
132 145
133#define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C)) 146#define GETARG_C(i) \
147 check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C))
148#define GETARG_vC(i) \
149 check_exp(checkopm(i, ivABC), getarg(i, POS_vC, SIZE_vC))
134#define GETARG_sC(i) sC2int(GETARG_C(i)) 150#define GETARG_sC(i) sC2int(GETARG_C(i))
135#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) 151#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
152#define SETARG_vC(i,v) setarg(i, v, POS_vC, SIZE_vC)
136 153
137#define TESTARG_k(i) check_exp(checkopm(i, iABC), (cast_int(((i) & (1u << POS_k))))) 154#define TESTARG_k(i) (cast_int(((i) & (1u << POS_k))))
138#define GETARG_k(i) check_exp(checkopm(i, iABC), getarg(i, POS_k, 1)) 155#define GETARG_k(i) getarg(i, POS_k, 1)
139#define SETARG_k(i,v) setarg(i, v, POS_k, 1) 156#define SETARG_k(i,v) setarg(i, v, POS_k, 1)
140 157
141#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx)) 158#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx))
@@ -160,6 +177,12 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
160 | (cast(Instruction, c)<<POS_C) \ 177 | (cast(Instruction, c)<<POS_C) \
161 | (cast(Instruction, k)<<POS_k)) 178 | (cast(Instruction, k)<<POS_k))
162 179
180#define CREATE_vABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \
181 | (cast(Instruction, a)<<POS_A) \
182 | (cast(Instruction, b)<<POS_vB) \
183 | (cast(Instruction, c)<<POS_vC) \
184 | (cast(Instruction, k)<<POS_k))
185
163#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \ 186#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \
164 | (cast(Instruction, a)<<POS_A) \ 187 | (cast(Instruction, a)<<POS_A) \
165 | (cast(Instruction, bc)<<POS_Bx)) 188 | (cast(Instruction, bc)<<POS_Bx))
@@ -306,7 +329,7 @@ OP_TFORPREP,/* A Bx create upvalue for R[A + 3]; pc+=Bx */
306OP_TFORCALL,/* A C R[A+4], ... ,R[A+3+C] := R[A](R[A+1], R[A+2]); */ 329OP_TFORCALL,/* A C R[A+4], ... ,R[A+3+C] := R[A](R[A+1], R[A+2]); */
307OP_TFORLOOP,/* A Bx if R[A+2] ~= nil then { R[A]=R[A+2]; pc -= Bx } */ 330OP_TFORLOOP,/* A Bx if R[A+2] ~= nil then { R[A]=R[A+2]; pc -= Bx } */
308 331
309OP_SETLIST,/* A B C k R[A][C+i] := R[A+i], 1 <= i <= B */ 332OP_SETLIST,/* A vB vC k R[A][vC+i] := R[A+i], 1 <= i <= vB */
310 333
311OP_CLOSURE,/* A Bx R[A] := closure(KPROTO[Bx]) */ 334OP_CLOSURE,/* A Bx R[A] := closure(KPROTO[Bx]) */
312 335