aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-10-16 08:59:34 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-10-16 08:59:34 -0200
commit45ccb0e881064492a3f422b15b50dad71eed36fa (patch)
treed819206b4af4fb9a257534471455ce233c1c93e3
parent4be18fa889657ebd317f5311ecf65da64891242b (diff)
downloadlua-45ccb0e881064492a3f422b15b50dad71eed36fa.tar.gz
lua-45ccb0e881064492a3f422b15b50dad71eed36fa.tar.bz2
lua-45ccb0e881064492a3f422b15b50dad71eed36fa.zip
"nupvalues" is kept in Closure, not in prototype (as a preparation
for C closures...)
-rw-r--r--ldo.c4
-rw-r--r--lfunc.c3
-rw-r--r--lgc.c4
-rw-r--r--lobject.h4
-rw-r--r--lopcodes.h7
-rw-r--r--lua.stx15
-rw-r--r--lvm.c26
-rw-r--r--lvm.h4
8 files changed, 34 insertions, 33 deletions
diff --git a/ldo.c b/ldo.c
index ca3cdc67..f10d614c 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ 2** $Id: ldo.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -338,7 +338,7 @@ static int protectedparser (ZIO *z, char *chunkname, int bin)
338 luaD_adjusttop(luaD_Cstack.base+1); /* one slot for the pseudo-function */ 338 luaD_adjusttop(luaD_Cstack.base+1); /* one slot for the pseudo-function */
339 luaD_stack.stack[luaD_Cstack.base].ttype = LUA_T_PROTO; 339 luaD_stack.stack[luaD_Cstack.base].ttype = LUA_T_PROTO;
340 luaD_stack.stack[luaD_Cstack.base].value.tf = tf; 340 luaD_stack.stack[luaD_Cstack.base].value.tf = tf;
341 luaV_closure(); 341 luaV_closure(0);
342 return 0; 342 return 0;
343} 343}
344 344
diff --git a/lfunc.c b/lfunc.c
index 3f13a89a..4e802cee 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.2 1997/09/26 16:46:20 roberto Exp roberto $
3** Lua Funcion auxiliar 3** Lua Funcion auxiliar
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -32,7 +32,6 @@ TProtoFunc *luaF_newproto (void)
32 f->fileName = NULL; 32 f->fileName = NULL;
33 f->consts = NULL; 33 f->consts = NULL;
34 f->nconsts = 0; 34 f->nconsts = 0;
35 f->nupvalues = 0;
36 f->locvars = NULL; 35 f->locvars = NULL;
37 luaO_insertlist(&luaF_root, (GCnode *)f); 36 luaO_insertlist(&luaF_root, (GCnode *)f);
38 return f; 37 return f;
diff --git a/lgc.c b/lgc.c
index 6633d6a1..627db17d 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ 2** $Id: lgc.c,v 1.3 1997/09/26 16:46:20 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -187,7 +187,7 @@ static void funcmark (Closure *f)
187 if (!f->head.marked) { 187 if (!f->head.marked) {
188 int i; 188 int i;
189 f->head.marked = 1; 189 f->head.marked = 1;
190 for (i=f->consts[0].value.tf->nupvalues; i>=0; i--) 190 for (i=f->nelems; i>=0; i--)
191 markobject(&f->consts[i]); 191 markobject(&f->consts[i]);
192 } 192 }
193} 193}
diff --git a/lobject.h b/lobject.h
index fcfb7d3b..132108d3 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ 2** $Id: lobject.h,v 1.3 1997/09/26 16:46:20 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -110,7 +110,6 @@ typedef struct TProtoFunc {
110 struct TObject *consts; 110 struct TObject *consts;
111 int nconsts; 111 int nconsts;
112 struct LocVar *locvars; /* ends with line = -1 */ 112 struct LocVar *locvars; /* ends with line = -1 */
113 int nupvalues;
114} TProtoFunc; 113} TProtoFunc;
115 114
116typedef struct LocVar { 115typedef struct LocVar {
@@ -138,6 +137,7 @@ typedef struct LocVar {
138*/ 137*/
139typedef struct Closure { 138typedef struct Closure {
140 GCnode head; 139 GCnode head;
140 int nelems; /* not included the first one (always the prototype) */
141 TObject consts[1]; /* at least one for prototype */ 141 TObject consts[1]; /* at least one for prototype */
142} Closure; 142} Closure;
143 143
diff --git a/lopcodes.h b/lopcodes.h
index 5b1856d8..a4644b78 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.7 1997/10/06 14:51:11 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.8 1997/10/13 22:12:04 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*/
@@ -135,8 +135,9 @@ IFTUPJMPW,/* w x - (x!=nil)? PC-=w */
135IFFUPJMP,/* b x - (x==nil)? PC-=b */ 135IFFUPJMP,/* b x - (x==nil)? PC-=b */
136IFFUPJMPW,/* w x - (x==nil)? PC-=w */ 136IFFUPJMPW,/* w x - (x==nil)? PC-=w */
137 137
138CLOSURE,/* b v_1...v_n c(CNST[b]) */ 138CLOSURE,/* b v_b...v_1 prt c(prt) */
139CLOSUREW,/* w v_1...v_n c(CNST[w]) */ 139CLOSURE0,/* b prt c(prt) */
140CLOSURE1,/* b v_1 prt c(prt) */
140 141
141CALLFUNC,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */ 142CALLFUNC,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */
142CALLFUNC0,/* b v_b...v_1 f - f(v1,...,v_b) */ 143CALLFUNC0,/* b v_b...v_1 f - f(v1,...,v_b) */
diff --git a/lua.stx b/lua.stx
index 112a6b40..12d06bc4 100644
--- a/lua.stx
+++ b/lua.stx
@@ -1,6 +1,6 @@
1%{ 1%{
2/* 2/*
3** $Id: lua.stx,v 1.9 1997/10/13 22:12:04 roberto Exp roberto $ 3** $Id: lua.stx,v 1.10 1997/10/15 20:16:00 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*/
@@ -57,6 +57,7 @@ typedef struct State {
57 int stacksize; /* number of values on activation register */ 57 int stacksize; /* number of values on activation register */
58 int maxstacksize; /* maximum number of values on activation register */ 58 int maxstacksize; /* maximum number of values on activation register */
59 int nlocalvar; /* number of active local variables */ 59 int nlocalvar; /* number of active local variables */
60 int nupvalues; /* number of upvalues */
60 int nvars; /* number of entries in f->locvars */ 61 int nvars; /* number of entries in f->locvars */
61 int maxcode; /* size of f->code */ 62 int maxcode; /* size of f->code */
62 int maxvars; /* size of f->locvars (-1 if no debug information) */ 63 int maxvars; /* size of f->locvars (-1 if no debug information) */
@@ -347,14 +348,14 @@ static int indexupvalue (TaggedString *n)
347{ 348{
348 vardesc v = singlevar(n, currState-1); 349 vardesc v = singlevar(n, currState-1);
349 int i; 350 int i;
350 for (i=0; i<currState->f->nupvalues; i++) { 351 for (i=0; i<currState->nupvalues; i++) {
351 if (currState->upvalues[i] == v) 352 if (currState->upvalues[i] == v)
352 return i; 353 return i;
353 } 354 }
354 /* new one */ 355 /* new one */
355 if (++currState->f->nupvalues > MAXUPVALUES) 356 if (++currState->nupvalues > MAXUPVALUES)
356 luaY_error("too many upvalues in a single function"); 357 luaY_error("too many upvalues in a single function");
357 currState->upvalues[i] = v; /* i = currState->f->nupvalues - 1 */ 358 currState->upvalues[i] = v; /* i = currState->nupvalues - 1 */
358 return i; 359 return i;
359} 360}
360 361
@@ -515,13 +516,14 @@ static void codereturn (void)
515static void func_onstack (TProtoFunc *f) 516static void func_onstack (TProtoFunc *f)
516{ 517{
517 int i; 518 int i;
518 int nupvalues = (currState+1)->f->nupvalues; 519 int nupvalues = (currState+1)->nupvalues;
519 int c = next_constant(currState); 520 int c = next_constant(currState);
520 ttype(&currState->f->consts[c]) = LUA_T_PROTO; 521 ttype(&currState->f->consts[c]) = LUA_T_PROTO;
521 currState->f->consts[c].value.tf = (currState+1)->f; 522 currState->f->consts[c].value.tf = (currState+1)->f;
523 code_constant(c);
522 for (i=0; i<nupvalues; i++) 524 for (i=0; i<nupvalues; i++)
523 lua_pushvar((currState+1)->upvalues[i]); 525 lua_pushvar((currState+1)->upvalues[i]);
524 code_oparg(CLOSURE, 0, c, 1-nupvalues); 526 code_oparg(CLOSURE, 2, nupvalues, -nupvalues);
525} 527}
526 528
527 529
@@ -531,6 +533,7 @@ static void init_state (TaggedString *filename)
531 currState->stacksize = 0; 533 currState->stacksize = 0;
532 currState->maxstacksize = 0; 534 currState->maxstacksize = 0;
533 currState->nlocalvar = 0; 535 currState->nlocalvar = 0;
536 currState->nupvalues = 0;
534 currState->f = f; 537 currState->f = f;
535 f->fileName = filename; 538 f->fileName = filename;
536 currState->pc = 0; 539 currState->pc = 0;
diff --git a/lvm.c b/lvm.c
index 91d923a4..4b77c3a6 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.8 1997/10/06 14:51:11 roberto Exp roberto $ 2** $Id: lvm.c,v 1.9 1997/10/13 22:12:04 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -76,12 +76,11 @@ int luaV_tostring (TObject *obj)
76} 76}
77 77
78 78
79void luaV_closure (void) 79void luaV_closure (int nelems)
80{ 80{
81 int nelems = (luaD_stack.top-1)->value.tf->nupvalues;
82 Closure *c = luaF_newclosure(nelems); 81 Closure *c = luaF_newclosure(nelems);
83 c->consts[0] = *(luaD_stack.top-1); 82 memcpy(c->consts, luaD_stack.top-(nelems+1), (nelems+1)*sizeof(TObject));
84 memcpy(&c->consts[1], luaD_stack.top-(nelems+1), nelems*sizeof(TObject)); 83 c->nelems = nelems;
85 luaD_stack.top -= nelems; 84 luaD_stack.top -= nelems;
86 ttype(luaD_stack.top-1) = LUA_T_FUNCTION; 85 ttype(luaD_stack.top-1) = LUA_T_FUNCTION;
87 (luaD_stack.top-1)->value.cl = c; 86 (luaD_stack.top-1)->value.cl = c;
@@ -427,7 +426,7 @@ StkId luaV_execute (Closure *cl, StkId base)
427 aux = 0; goto setmap; 426 aux = 0; goto setmap;
428 427
429 case SETMAP: 428 case SETMAP:
430 aux = *(pc++); 429 aux = *pc++;
431 setmap: { 430 setmap: {
432 TObject *arr = luaD_stack.top-(2*aux)-3; 431 TObject *arr = luaD_stack.top-(2*aux)-3;
433 do { 432 do {
@@ -447,12 +446,12 @@ StkId luaV_execute (Closure *cl, StkId base)
447 break; 446 break;
448 447
449 case ARGS: 448 case ARGS:
450 luaD_adjusttop(base + *(pc++)); 449 luaD_adjusttop(base+(*pc++));
451 break; 450 break;
452 451
453 case VARARGS: 452 case VARARGS:
454 luaC_checkGC(); 453 luaC_checkGC();
455 adjust_varargs(base + *(pc++)); 454 adjust_varargs(base+(*pc++));
456 break; 455 break;
457 456
458 case CREATEARRAYW: 457 case CREATEARRAYW:
@@ -632,14 +631,13 @@ StkId luaV_execute (Closure *cl, StkId base)
632 if (ttype(--luaD_stack.top) == LUA_T_NIL) pc -= aux; 631 if (ttype(--luaD_stack.top) == LUA_T_NIL) pc -= aux;
633 break; 632 break;
634 633
635 case CLOSUREW:
636 aux = next_word(pc); goto closure;
637
638 case CLOSURE: 634 case CLOSURE:
639 aux = *pc++; 635 aux = *pc++; goto closure;
636
637 case CLOSURE0: case CLOSURE1:
638 aux -= CLOSURE0;
640 closure: 639 closure:
641 *luaD_stack.top++ = consts[aux]; 640 luaV_closure(aux);
642 luaV_closure();
643 luaC_checkGC(); 641 luaC_checkGC();
644 break; 642 break;
645 643
diff --git a/lvm.h b/lvm.h
index 312ce871..bbe1e6a4 100644
--- a/lvm.h
+++ b/lvm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ 2** $Id: lvm.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -24,6 +24,6 @@ void luaV_settable (TObject *t, int mode);
24void luaV_getglobal (TaggedString *ts); 24void luaV_getglobal (TaggedString *ts);
25void luaV_setglobal (TaggedString *ts); 25void luaV_setglobal (TaggedString *ts);
26StkId luaV_execute (Closure *func, StkId base); 26StkId luaV_execute (Closure *func, StkId base);
27void luaV_closure (void); 27void luaV_closure (int nelems);
28 28
29#endif 29#endif