aboutsummaryrefslogtreecommitdiff
path: root/lua.stx
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-26 16:38:16 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-26 16:38:16 -0200
commitda96eb2cceb9a4b89ee3d08747d3306d166f9c87 (patch)
tree65ee363e339cbd55199af68ba34ffba2b9a57c88 /lua.stx
parentfada8efd017c9834607a8d634d2f2a2c0c5d5289 (diff)
downloadlua-da96eb2cceb9a4b89ee3d08747d3306d166f9c87.tar.gz
lua-da96eb2cceb9a4b89ee3d08747d3306d166f9c87.tar.bz2
lua-da96eb2cceb9a4b89ee3d08747d3306d166f9c87.zip
some details related to OLD_ANSI
Diffstat (limited to 'lua.stx')
-rw-r--r--lua.stx101
1 files changed, 46 insertions, 55 deletions
diff --git a/lua.stx b/lua.stx
index 6e40b7d6..ad9dd1d6 100644
--- a/lua.stx
+++ b/lua.stx
@@ -1,6 +1,6 @@
1%{ 1%{
2/* 2/*
3** $Id: lua.stx,v 1.25 1997/12/22 20:57:18 roberto Exp roberto $ 3** $Id: lua.stx,v 1.26 1997/12/23 19:24:19 roberto Exp roberto $
4** Syntax analizer and code generator 4** Syntax analizer and code generator
5** See Copyright Notice in lua.h 5** See Copyright Notice in lua.h
6*/ 6*/
@@ -108,24 +108,10 @@ void luaY_error (char *s)
108 108
109static void check_pc (int n) 109static void check_pc (int n)
110{ 110{
111 if (L->currState->pc+n > L->currState->maxcode) 111 FuncState *fs = L->currState;
112 L->currState->maxcode = luaM_growvector(&L->currState->f->code, 112 if (fs->pc+n > fs->maxcode)
113 L->currState->maxcode, Byte, codeEM, MAX_INT); 113 fs->maxcode = luaM_growvector(&fs->f->code, fs->maxcode,
114} 114 Byte, codeEM, MAX_INT);
115
116
117static void movecode_up (int d, int s, int n)
118{
119 while (n--)
120 L->currState->f->code[d+n] = L->currState->f->code[s+n];
121}
122
123
124static void movecode_down (int d, int s, int n)
125{
126 int i;
127 for (i=0; i<n; i++)
128 L->currState->f->code[d+i] = L->currState->f->code[s+i];
129} 115}
130 116
131 117
@@ -138,31 +124,33 @@ static void code_byte (Byte c)
138 124
139static void deltastack (int delta) 125static void deltastack (int delta)
140{ 126{
141 L->currState->stacksize += delta; 127 FuncState *fs = L->currState;
142 if (L->currState->stacksize > L->currState->maxstacksize) { 128 fs->stacksize += delta;
143 if (L->currState->stacksize > 255) 129 if (fs->stacksize > fs->maxstacksize) {
130 if (fs->stacksize > 255)
144 luaY_error("function/expression too complex"); 131 luaY_error("function/expression too complex");
145 L->currState->maxstacksize = L->currState->stacksize; 132 fs->maxstacksize = fs->stacksize;
146 } 133 }
147} 134}
148 135
149 136
150static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta) 137static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta)
151{ 138{
139 Byte *code = L->currState->f->code;
152 deltastack(delta); 140 deltastack(delta);
153 if (arg < builtin) { 141 if (arg < builtin) {
154 L->currState->f->code[pc] = op+1+arg; 142 code[pc] = op+1+arg;
155 return 1; 143 return 1;
156 } 144 }
157 else if (arg <= 255) { 145 else if (arg <= 255) {
158 L->currState->f->code[pc] = op; 146 code[pc] = op;
159 L->currState->f->code[pc+1] = arg; 147 code[pc+1] = arg;
160 return 2; 148 return 2;
161 } 149 }
162 else if (arg <= MAX_WORD) { 150 else if (arg <= MAX_WORD) {
163 L->currState->f->code[pc] = op+1+builtin; 151 code[pc] = op+1+builtin;
164 L->currState->f->code[pc+1] = arg&0xFF; 152 code[pc+1] = arg&0xFF;
165 L->currState->f->code[pc+2] = arg>>8; 153 code[pc+2] = arg>>8;
166 return 3; 154 return 3;
167 } 155 }
168 else luaY_error("code too long " MES_LIM("64K")); 156 else luaY_error("code too long " MES_LIM("64K"));
@@ -172,14 +160,15 @@ static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta)
172 160
173static int fix_opcode (int pc, OpCode op, int builtin, int arg) 161static int fix_opcode (int pc, OpCode op, int builtin, int arg)
174{ 162{
163 FuncState *fs = L->currState;
175 if (arg < builtin) { /* close space */ 164 if (arg < builtin) { /* close space */
176 movecode_down(pc+1, pc+2, L->currState->pc-(pc+2)); 165 luaO_memdown(fs->f->code+pc+1, fs->f->code+pc+2, fs->pc-(pc+2));
177 L->currState->pc--; 166 fs->pc--;
178 } 167 }
179 else if (arg > 255) { /* open space */ 168 else if (arg > 255) { /* open space */
180 check_pc(1); 169 check_pc(1);
181 movecode_up(pc+1, pc, L->currState->pc-pc); 170 luaO_memup(fs->f->code+pc+1, fs->f->code+pc, fs->pc-pc);
182 L->currState->pc++; 171 fs->pc++;
183 } 172 }
184 return code_oparg_at(pc, op, builtin, arg, 0) - 2; 173 return code_oparg_at(pc, op, builtin, arg, 0) - 2;
185} 174}
@@ -301,13 +290,14 @@ static void flush_list (int m, int n)
301 290
302static void luaI_registerlocalvar (TaggedString *varname, int line) 291static void luaI_registerlocalvar (TaggedString *varname, int line)
303{ 292{
304 if (L->currState->maxvars != -1) { /* debug information? */ 293 FuncState *fs = L->currState;
305 if (L->currState->nvars >= L->currState->maxvars) 294 if (fs->maxvars != -1) { /* debug information? */
306 L->currState->maxvars = luaM_growvector(&L->currState->f->locvars, 295 if (fs->nvars >= fs->maxvars)
307 L->currState->maxvars, LocVar, "", MAX_WORD); 296 fs->maxvars = luaM_growvector(&fs->f->locvars, fs->maxvars,
308 L->currState->f->locvars[L->currState->nvars].varname = varname; 297 LocVar, "", MAX_WORD);
309 L->currState->f->locvars[L->currState->nvars].line = line; 298 fs->f->locvars[fs->nvars].varname = varname;
310 L->currState->nvars++; 299 fs->f->locvars[fs->nvars].line = line;
300 fs->nvars++;
311 } 301 }
312} 302}
313 303
@@ -569,22 +559,23 @@ static void func_onstack (TProtoFunc *f)
569static void init_state (TaggedString *filename) 559static void init_state (TaggedString *filename)
570{ 560{
571 TProtoFunc *f = luaF_newproto(); 561 TProtoFunc *f = luaF_newproto();
572 L->currState->stacksize = 0; 562 FuncState *fs = L->currState;
573 L->currState->maxstacksize = 0; 563 fs->stacksize = 0;
574 L->currState->nlocalvar = 0; 564 fs->maxstacksize = 0;
575 L->currState->nupvalues = 0; 565 fs->nlocalvar = 0;
576 L->currState->f = f; 566 fs->nupvalues = 0;
567 fs->f = f;
577 f->fileName = filename; 568 f->fileName = filename;
578 L->currState->pc = 0; 569 fs->pc = 0;
579 L->currState->maxcode = 0; 570 fs->maxcode = 0;
580 f->code = NULL; 571 f->code = NULL;
581 L->currState->maxconsts = 0; 572 fs->maxconsts = 0;
582 if (lua_debug) { 573 if (lua_debug) {
583 L->currState->nvars = 0; 574 fs->nvars = 0;
584 L->currState->maxvars = 0; 575 fs->maxvars = 0;
585 } 576 }
586 else 577 else
587 L->currState->maxvars = -1; /* flag no debug information */ 578 fs->maxvars = -1; /* flag no debug information */
588 code_byte(0); /* to be filled with stacksize */ 579 code_byte(0); /* to be filled with stacksize */
589 L->lexstate->lastline = 0; /* invalidate it */ 580 L->lexstate->lastline = 0; /* invalidate it */
590} 581}
@@ -696,13 +687,13 @@ stat : IF cond THEN block SaveWord elsepart END { codeIf($2, $5); }
696 687
697 | WHILE GetPC cond DO block END 688 | WHILE GetPC cond DO block END
698 {{ 689 {{
690 FuncState *fs = L->currState;
699 int expsize = $3-$2; 691 int expsize = $3-$2;
700 int newpos = $2+JMPSIZE; 692 int newpos = $2+JMPSIZE;
701 check_pc(expsize); 693 check_pc(expsize);
702 memcpy(&L->currState->f->code[L->currState->pc], 694 memcpy(fs->f->code+fs->pc, fs->f->code+$2, expsize);
703 &L->currState->f->code[$2], expsize); 695 luaO_memdown(fs->f->code+$2, fs->f->code+$3, fs->pc-$2);
704 movecode_down($2, $3, L->currState->pc-$2); 696 newpos += fix_jump($2, JMP, fs->pc-expsize);
705 newpos += fix_jump($2, JMP, L->currState->pc-expsize);
706 fix_upjmp(IFTUPJMP, newpos); 697 fix_upjmp(IFTUPJMP, newpos);
707 }} 698 }}
708 699