aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-05-06 11:41:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-05-06 11:41:41 -0300
commit288fa056020f20647c6db3e721498b96d8c62713 (patch)
treec063b3464a1e15580e6a0cbb06b53436ce4afe19
parent7808ea3a5ffe8c2045dc76099f8968e3b8104360 (diff)
downloadlua-288fa056020f20647c6db3e721498b96d8c62713.tar.gz
lua-288fa056020f20647c6db3e721498b96d8c62713.tar.bz2
lua-288fa056020f20647c6db3e721498b96d8c62713.zip
opcodes with LONGARG do not use byte variants.
-rw-r--r--lparser.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/lparser.c b/lparser.c
index 221fdf40..9a206fba 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.30 1999/03/23 19:58:37 roberto Exp roberto $ 2** $Id: lparser.c,v 1.31 1999/03/25 21:06:57 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -159,24 +159,25 @@ static void code_oparg_at (LexState *ls, int pc, OpCode op,
159 code[pc] = (Byte)op; 159 code[pc] = (Byte)op;
160 code[pc+1] = (Byte)arg; 160 code[pc+1] = (Byte)arg;
161 } 161 }
162 else if (arg <= MAX_WORD) { 162 else if (arg > MAX_ARG)
163 luaX_error(ls, "code too long");
164 else { /* MAX_BYTE < arg < MAX_ARG */
165 if (arg > MAX_WORD) {
166 code[pc] = (Byte)LONGARG;
167 code[pc+1] = (Byte)(arg>>16);
168 pc += 2;
169 }
163 code[pc] = (Byte)(op-1); /* opcode for word argument */ 170 code[pc] = (Byte)(op-1); /* opcode for word argument */
164 code[pc+1] = (Byte)(arg>>8); 171 code[pc+1] = (Byte)((arg&0xFFFF)>>8);
165 code[pc+2] = (Byte)(arg&0xFF); 172 code[pc+2] = (Byte)(arg&0xFF);
166 } 173 }
167 else if (arg <= MAX_ARG) {
168 code[pc] = (Byte)LONGARG;
169 code[pc+1] = (Byte)(arg>>16);
170 code_oparg_at(ls, pc+2, op, arg&0xFFFF, 0);
171 }
172 else luaX_error(ls, "code too long");
173} 174}
174 175
175 176
176static int codesize (int arg) { 177static int codesize (int arg) {
177 if (arg <= MAX_BYTE) return 2; /* opcode + 1 byte */ 178 if (arg <= MAX_BYTE) return 2; /* opcode + 1 byte */
178 else if (arg <= MAX_WORD) return 3; /* opcode + 1 word */ 179 else if (arg <= MAX_WORD) return 3; /* opcode + 1 word (2 bytes) */
179 else return 2+codesize(arg&0xFFFF); /* LONGARG + 1 byte + original opcode */ 180 else return 5; /* LONGARG + 1 byte + opcode + 1 word (2 bytes) */
180} 181}
181 182
182 183