diff options
Diffstat (limited to 'lopcodes.h')
-rw-r--r-- | lopcodes.h | 147 |
1 files changed, 63 insertions, 84 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.38 2000/01/28 16:53:00 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.39 2000/02/11 16:52:54 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -8,67 +8,79 @@ | |||
8 | #define lopcodes_h | 8 | #define lopcodes_h |
9 | 9 | ||
10 | 10 | ||
11 | /* | ||
12 | ** NOTICE: variants of the same opcode must be consecutive: First, those | ||
13 | ** with word parameter, then with byte parameter. | ||
14 | */ | ||
15 | 11 | ||
12 | /*=========================================================================== | ||
13 | We assume that instructions are unsigned numbers with 4 bytes. | ||
14 | All instructions have an opcode in the lower byte. Moreover, | ||
15 | an instruction can have 0, 1, or 2 arguments. There are 4 types of | ||
16 | Instructions: | ||
17 | type 0: no arguments | ||
18 | type 1: 1 unsigned argument in the higher 24 bits (called `U') | ||
19 | type 2: 1 signed argument in the higher 24 bits (`S') | ||
20 | type 3: 1st unsigned argument in the higher 16 bits (`A') | ||
21 | 2nd unsigned argument in the middle 8 bits (`B') | ||
16 | 22 | ||
17 | typedef enum { | 23 | The signed argument is represented in excess 2^23; that is, the real value |
18 | /* name parm before after side effect | 24 | is 2^23 minus the usigned value. |
19 | -----------------------------------------------------------------------------*/ | 25 | ===========================================================================*/ |
20 | ENDCODE,/* - - (return) */ | ||
21 | RETCODE,/* b - (return) */ | ||
22 | |||
23 | CALL,/* b c v_n-v_1 f(at c) r_b-r_1 f(v1,...,v_n) */ | ||
24 | 26 | ||
25 | TAILCALL,/* b c v_c-v_1 f (return) f(v1,...,v_c) */ | 27 | /* |
28 | ** the following macros help to manipulate instructions | ||
29 | */ | ||
26 | 30 | ||
27 | PUSHNIL,/* b - nil_0-nil_b */ | 31 | #define MAXARG_U ((1<<24)-1) |
28 | POP,/* b a_b-a_1 - */ | 32 | #define MAXARG_S ((1<<23)-1) |
33 | #define MAXARG_A ((1<<16)-1) | ||
34 | #define MAXARG_B ((1<<8)-1) | ||
29 | 35 | ||
30 | PUSHINTW,/* w - (float)w */ | 36 | #define GET_OPCODE(i) ((OpCode)((i)&0xFF)) |
31 | PUSHINT,/* b - (float)b */ | 37 | #define GETARG_U(i) ((int)((i)>>8)) |
38 | #define GETARG_S(i) ((int)((i)>>8)-(1<<23)) | ||
39 | #define GETARG_A(i) ((int)((i)>>16)) | ||
40 | #define GETARG_B(i) ((int)(((i)>>8) & 0xFF)) | ||
32 | 41 | ||
33 | PUSHINTNEGW,/* w - (float)-w */ | 42 | #define SET_OPCODE(i,o) (((i)&0xFFFFFF00u) | (Instruction)(o)) |
34 | PUSHINTNEG,/* b - (float)-b */ | 43 | #define SETARG_U(i,u) (((i)&0x000000FFu) | ((Instruction)(u)<<8)) |
44 | #define SETARG_S(i,s) (((i)&0x000000FFu) | ((Instruction)((s)+(1<<23))<<8)) | ||
45 | #define SETARG_A(i,a) (((i)&0x0000FFFFu) | ((Instruction)(a)<<16)) | ||
46 | #define SETARG_B(i,b) (((i)&0xFFFF00FFu) | ((Instruction)(b)<<8)) | ||
35 | 47 | ||
36 | PUSHSTRINGW,/* w - KSTR[w] */ | ||
37 | PUSHSTRING,/* b - KSTR[b] */ | ||
38 | PUSHNUMBERW,/* w - KNUM[w] */ | ||
39 | PUSHNUMBER,/* b - KNUM[b] */ | ||
40 | 48 | ||
41 | PUSHUPVALUE,/* b - Closure[b] */ | ||
42 | 49 | ||
43 | PUSHLOCAL,/* b - LOC[b] */ | 50 | typedef enum { |
51 | /* name parm before after side effect | ||
52 | -----------------------------------------------------------------------------*/ | ||
53 | ENDCODE,/* - - (return) */ | ||
54 | RETCODE,/* U - (return) */ | ||
44 | 55 | ||
45 | GETGLOBALW,/* w - VAR[CNST[w]] */ | 56 | CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */ |
46 | GETGLOBAL,/* b - VAR[CNST[b]] */ | 57 | TAILCALL,/* A B v_a-v_1 f (return) f(v1,...,v_a) */ |
47 | 58 | ||
48 | GETTABLE,/* - i t t[i] */ | 59 | PUSHNIL,/* U - nil_0-nil_u */ |
60 | POP,/* U a_u-a_1 - */ | ||
49 | 61 | ||
50 | GETDOTTEDW,/* w t t[CNST[w]] */ | 62 | PUSHINT,/* S - (real)s */ |
51 | GETDOTTED,/* b t t[CNST[b]] */ | 63 | PUSHSTRING,/* U - KSTR[u] */ |
64 | PUSHNUMBER,/* U - KNUM[u] */ | ||
52 | 65 | ||
53 | PUSHSELFW,/* w t t t[CNST[w]] */ | 66 | PUSHUPVALUE,/* U - Closure[u] */ |
54 | PUSHSELF,/* b t t t[CNST[b]] */ | ||
55 | 67 | ||
56 | CREATEARRAYW,/* w - newarray(size = w) */ | 68 | PUSHLOCAL,/* U - LOC[u] */ |
57 | CREATEARRAY,/* b - newarray(size = b) */ | 69 | GETGLOBAL,/* U - VAR[CNST[u]] */ |
58 | 70 | ||
59 | SETLOCAL,/* b x - LOC[b]=x */ | 71 | GETTABLE,/* - i t t[i] */ |
72 | GETDOTTED,/* U t t[CNST[u]] */ | ||
73 | PUSHSELF,/* U t t t[CNST[u]] */ | ||
60 | 74 | ||
61 | SETGLOBALW,/* w x - VAR[CNST[w]]=x */ | 75 | CREATETABLE,/* U - newarray(size = u) */ |
62 | SETGLOBAL,/* b x - VAR[CNST[b]]=x */ | ||
63 | 76 | ||
77 | SETLOCAL,/* U x - LOC[u]=x */ | ||
78 | SETGLOBAL,/* U x - VAR[CNST[u]]=x */ | ||
64 | SETTABLEPOP,/* - v i t - t[i]=v */ | 79 | SETTABLEPOP,/* - v i t - t[i]=v */ |
80 | SETTABLE,/* U v a_u-a_1 i t a_u-a_1 i t t[i]=v */ | ||
65 | 81 | ||
66 | SETTABLE,/* b v a_b-a_1 i t a_b-a_1 i t t[i]=v */ | 82 | SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */ |
67 | 83 | SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */ | |
68 | SETLISTW,/* w c v_c-v_1 t t t[i+w*FPF]=v_i */ | ||
69 | SETLIST,/* b c v_c-v_1 t t t[i+b*FPF]=v_i */ | ||
70 | |||
71 | SETMAP,/* b v_b k_b - v_0 k_0 t t t[k_i]=v_i */ | ||
72 | 84 | ||
73 | NEQOP,/* - y x (x~=y)? 1 : nil */ | 85 | NEQOP,/* - y x (x~=y)? 1 : nil */ |
74 | EQOP,/* - y x (x==y)? 1 : nil */ | 86 | EQOP,/* - y x (x==y)? 1 : nil */ |
@@ -85,54 +97,21 @@ CONCOP,/* - y x x..y */ | |||
85 | MINUSOP,/* - x -x */ | 97 | MINUSOP,/* - x -x */ |
86 | NOTOP,/* - x (x==nil)? 1 : nil */ | 98 | NOTOP,/* - x (x==nil)? 1 : nil */ |
87 | 99 | ||
88 | ONTJMPW,/* w x (x!=nil)? x : - (x!=nil)? PC+=w */ | 100 | ONTJMP,/* S x (x!=nil)? x : - (x!=nil)? PC+=s */ |
89 | ONTJMP,/* b x (x!=nil)? x : - (x!=nil)? PC+=b */ | 101 | ONFJMP,/* S x (x==nil)? x : - (x==nil)? PC+=s */ |
90 | ONFJMPW,/* w x (x==nil)? x : - (x==nil)? PC+=w */ | 102 | JMP,/* S - - PC+=s */ |
91 | ONFJMP,/* b x (x==nil)? x : - (x==nil)? PC+=b */ | 103 | IFTJMP,/* S x - (x!=nil)? PC+=s */ |
92 | JMPW,/* w - - PC+=w */ | 104 | IFFJMP,/* S x - (x==nil)? PC+=s */ |
93 | JMP,/* b - - PC+=b */ | ||
94 | IFFJMPW,/* w x - (x==nil)? PC+=w */ | ||
95 | IFFJMP,/* b x - (x==nil)? PC+=b */ | ||
96 | IFTUPJMPW,/* w x - (x!=nil)? PC-=w */ | ||
97 | IFTUPJMP,/* b x - (x!=nil)? PC-=b */ | ||
98 | IFFUPJMPW,/* w x - (x==nil)? PC-=w */ | ||
99 | IFFUPJMP,/* b x - (x==nil)? PC-=b */ | ||
100 | 105 | ||
101 | CLOSUREW,/* w c v_c-v_1 closure(CNST[w], v_c-v_1) */ | 106 | CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_b-v_1) */ |
102 | CLOSURE,/* b c v_c-v_1 closure(CNST[b], v_c-v_1) */ | ||
103 | 107 | ||
104 | SETLINEW,/* w - - LINE=w */ | 108 | SETLINE/* U - - LINE=u */ |
105 | SETLINE,/* b - - LINE=b */ | ||
106 | |||
107 | LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */ | ||
108 | LONGARG /* b (add b*(1<<16) to arg of next instruction) */ | ||
109 | 109 | ||
110 | } OpCode; | 110 | } OpCode; |
111 | 111 | ||
112 | 112 | ||
113 | #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ | 113 | #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ |
114 | #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) */ | 114 | #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) (<MAXARG_B) */ |
115 | |||
116 | #define ZEROVARARG 128 | ||
117 | |||
118 | |||
119 | /* maximum value of an arg of 3 bytes; must fit in an "int" */ | ||
120 | #if MAX_INT < (1<<24) | ||
121 | #define MAX_ARG MAX_INT | ||
122 | #else | ||
123 | #define MAX_ARG ((1<<24)-1) | ||
124 | #endif | ||
125 | |||
126 | /* maximum value of a word of 2 bytes; cannot be larger than MAX_ARG */ | ||
127 | #if MAX_ARG < (1<<16) | ||
128 | #define MAX_WORD MAX_ARG | ||
129 | #else | ||
130 | #define MAX_WORD ((1<<16)-1) | ||
131 | #endif | ||
132 | |||
133 | |||
134 | /* maximum value of a byte */ | ||
135 | #define MAX_BYTE ((1<<8)-1) | ||
136 | 115 | ||
137 | 116 | ||
138 | #endif | 117 | #endif |