aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
Diffstat (limited to 'lopcodes.h')
-rw-r--r--lopcodes.h147
1 files changed, 63 insertions, 84 deletions
diff --git a/lopcodes.h b/lopcodes.h
index 6da468f5..2094b2d3 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -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
17typedef 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===========================================================================*/
20ENDCODE,/* - - (return) */
21RETCODE,/* b - (return) */
22
23CALL,/* b c v_n-v_1 f(at c) r_b-r_1 f(v1,...,v_n) */
24 26
25TAILCALL,/* b c v_c-v_1 f (return) f(v1,...,v_c) */ 27/*
28** the following macros help to manipulate instructions
29*/
26 30
27PUSHNIL,/* b - nil_0-nil_b */ 31#define MAXARG_U ((1<<24)-1)
28POP,/* 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
30PUSHINTW,/* w - (float)w */ 36#define GET_OPCODE(i) ((OpCode)((i)&0xFF))
31PUSHINT,/* 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
33PUSHINTNEGW,/* w - (float)-w */ 42#define SET_OPCODE(i,o) (((i)&0xFFFFFF00u) | (Instruction)(o))
34PUSHINTNEG,/* 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
36PUSHSTRINGW,/* w - KSTR[w] */
37PUSHSTRING,/* b - KSTR[b] */
38PUSHNUMBERW,/* w - KNUM[w] */
39PUSHNUMBER,/* b - KNUM[b] */
40 48
41PUSHUPVALUE,/* b - Closure[b] */
42 49
43PUSHLOCAL,/* b - LOC[b] */ 50typedef enum {
51/* name parm before after side effect
52-----------------------------------------------------------------------------*/
53ENDCODE,/* - - (return) */
54RETCODE,/* U - (return) */
44 55
45GETGLOBALW,/* w - VAR[CNST[w]] */ 56CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */
46GETGLOBAL,/* b - VAR[CNST[b]] */ 57TAILCALL,/* A B v_a-v_1 f (return) f(v1,...,v_a) */
47 58
48GETTABLE,/* - i t t[i] */ 59PUSHNIL,/* U - nil_0-nil_u */
60POP,/* U a_u-a_1 - */
49 61
50GETDOTTEDW,/* w t t[CNST[w]] */ 62PUSHINT,/* S - (real)s */
51GETDOTTED,/* b t t[CNST[b]] */ 63PUSHSTRING,/* U - KSTR[u] */
64PUSHNUMBER,/* U - KNUM[u] */
52 65
53PUSHSELFW,/* w t t t[CNST[w]] */ 66PUSHUPVALUE,/* U - Closure[u] */
54PUSHSELF,/* b t t t[CNST[b]] */
55 67
56CREATEARRAYW,/* w - newarray(size = w) */ 68PUSHLOCAL,/* U - LOC[u] */
57CREATEARRAY,/* b - newarray(size = b) */ 69GETGLOBAL,/* U - VAR[CNST[u]] */
58 70
59SETLOCAL,/* b x - LOC[b]=x */ 71GETTABLE,/* - i t t[i] */
72GETDOTTED,/* U t t[CNST[u]] */
73PUSHSELF,/* U t t t[CNST[u]] */
60 74
61SETGLOBALW,/* w x - VAR[CNST[w]]=x */ 75CREATETABLE,/* U - newarray(size = u) */
62SETGLOBAL,/* b x - VAR[CNST[b]]=x */
63 76
77SETLOCAL,/* U x - LOC[u]=x */
78SETGLOBAL,/* U x - VAR[CNST[u]]=x */
64SETTABLEPOP,/* - v i t - t[i]=v */ 79SETTABLEPOP,/* - v i t - t[i]=v */
80SETTABLE,/* U v a_u-a_1 i t a_u-a_1 i t t[i]=v */
65 81
66SETTABLE,/* b v a_b-a_1 i t a_b-a_1 i t t[i]=v */ 82SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */
67 83SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */
68SETLISTW,/* w c v_c-v_1 t t t[i+w*FPF]=v_i */
69SETLIST,/* b c v_c-v_1 t t t[i+b*FPF]=v_i */
70
71SETMAP,/* b v_b k_b - v_0 k_0 t t t[k_i]=v_i */
72 84
73NEQOP,/* - y x (x~=y)? 1 : nil */ 85NEQOP,/* - y x (x~=y)? 1 : nil */
74EQOP,/* - y x (x==y)? 1 : nil */ 86EQOP,/* - y x (x==y)? 1 : nil */
@@ -85,54 +97,21 @@ CONCOP,/* - y x x..y */
85MINUSOP,/* - x -x */ 97MINUSOP,/* - x -x */
86NOTOP,/* - x (x==nil)? 1 : nil */ 98NOTOP,/* - x (x==nil)? 1 : nil */
87 99
88ONTJMPW,/* w x (x!=nil)? x : - (x!=nil)? PC+=w */ 100ONTJMP,/* S x (x!=nil)? x : - (x!=nil)? PC+=s */
89ONTJMP,/* b x (x!=nil)? x : - (x!=nil)? PC+=b */ 101ONFJMP,/* S x (x==nil)? x : - (x==nil)? PC+=s */
90ONFJMPW,/* w x (x==nil)? x : - (x==nil)? PC+=w */ 102JMP,/* S - - PC+=s */
91ONFJMP,/* b x (x==nil)? x : - (x==nil)? PC+=b */ 103IFTJMP,/* S x - (x!=nil)? PC+=s */
92JMPW,/* w - - PC+=w */ 104IFFJMP,/* S x - (x==nil)? PC+=s */
93JMP,/* b - - PC+=b */
94IFFJMPW,/* w x - (x==nil)? PC+=w */
95IFFJMP,/* b x - (x==nil)? PC+=b */
96IFTUPJMPW,/* w x - (x!=nil)? PC-=w */
97IFTUPJMP,/* b x - (x!=nil)? PC-=b */
98IFFUPJMPW,/* w x - (x==nil)? PC-=w */
99IFFUPJMP,/* b x - (x==nil)? PC-=b */
100 105
101CLOSUREW,/* w c v_c-v_1 closure(CNST[w], v_c-v_1) */ 106CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_b-v_1) */
102CLOSURE,/* b c v_c-v_1 closure(CNST[b], v_c-v_1) */
103 107
104SETLINEW,/* w - - LINE=w */ 108SETLINE/* U - - LINE=u */
105SETLINE,/* b - - LINE=b */
106
107LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */
108LONGARG /* 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