diff options
author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1995-04-11 14:56:30 -0300 |
---|---|---|
committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1995-04-11 14:56:30 -0300 |
commit | 8156604823aa487f4436d33fe89302598faab3db (patch) | |
tree | 6ed6e5ec52c397e8e3ce11fec01440fd4287b1ab | |
parent | 36b6fdda833d4dd4a866d2c96ac42062b2b29af9 (diff) | |
download | lua-8156604823aa487f4436d33fe89302598faab3db.tar.gz lua-8156604823aa487f4436d33fe89302598faab3db.tar.bz2 lua-8156604823aa487f4436d33fe89302598faab3db.zip |
run-time stack now is controled at run time, instead of
compilation time.
-rw-r--r-- | lua.stx | 50 | ||||
-rw-r--r-- | opcode.c | 136 | ||||
-rw-r--r-- | opcode.h | 8 |
3 files changed, 108 insertions, 86 deletions
@@ -1,6 +1,6 @@ | |||
1 | %{ | 1 | %{ |
2 | 2 | ||
3 | char *rcs_luastx = "$Id: lua.stx,v 3.16 1994/12/27 20:41:11 celes Exp roberto $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 3.17 1995/01/13 22:11:12 roberto Exp celes $"; |
4 | 4 | ||
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
@@ -41,7 +41,8 @@ static Long varbuffer[MAXVAR]; /* variables in an assignment list; | |||
41 | it's long to store negative Word values */ | 41 | it's long to store negative Word values */ |
42 | static int nvarbuffer=0; /* number of variables at a list */ | 42 | static int nvarbuffer=0; /* number of variables at a list */ |
43 | 43 | ||
44 | static Word localvar[STACKGAP]; /* store local variable names */ | 44 | #define MAXLOCALS 32 |
45 | static Word localvar[MAXLOCALS]; /* store local variable names */ | ||
45 | static int nlocalvar=0; /* number of local variables */ | 46 | static int nlocalvar=0; /* number of local variables */ |
46 | 47 | ||
47 | #define MAXFIELDS FIELDS_PER_FLUSH*2 | 48 | #define MAXFIELDS FIELDS_PER_FLUSH*2 |
@@ -103,10 +104,10 @@ static void code_word_at (Byte *p, Word n) | |||
103 | 104 | ||
104 | static void push_field (Word name) | 105 | static void push_field (Word name) |
105 | { | 106 | { |
106 | if (nfields < STACKGAP-1) | 107 | if (nfields < MAXFIELDS) |
107 | fields[nfields++] = name; | 108 | fields[nfields++] = name; |
108 | else | 109 | else |
109 | lua_error ("too many fields in a constructor"); | 110 | lua_error ("too many fields in nested constructors"); |
110 | } | 111 | } |
111 | 112 | ||
112 | static void flush_record (int n) | 113 | static void flush_record (int n) |
@@ -135,18 +136,26 @@ static void flush_list (int m, int n) | |||
135 | code_byte(n); | 136 | code_byte(n); |
136 | } | 137 | } |
137 | 138 | ||
138 | static void add_nlocalvar (int n) | 139 | static void add_localvar (Word name) |
139 | { | 140 | { |
140 | if (MAX_TEMPS+nlocalvar+MAXVAR+n < STACKGAP) | 141 | if (nlocalvar < MAXLOCALS) |
141 | nlocalvar += n; | 142 | localvar[nlocalvar++] = name; |
142 | else | 143 | else |
143 | lua_error ("too many local variables"); | 144 | lua_error ("too many local variables"); |
144 | } | 145 | } |
145 | 146 | ||
146 | static void incr_nvarbuffer (void) | 147 | static void store_localvar (Word name, int n) |
147 | { | 148 | { |
148 | if (nvarbuffer < MAXVAR-1) | 149 | if (nlocalvar+n < MAXLOCALS) |
149 | nvarbuffer++; | 150 | localvar[nlocalvar+n] = name; |
151 | else | ||
152 | lua_error ("too many local variables"); | ||
153 | } | ||
154 | |||
155 | static void add_varbuffer (Long var) | ||
156 | { | ||
157 | if (nvarbuffer < MAXVAR) | ||
158 | varbuffer[nvarbuffer++] = var; | ||
150 | else | 159 | else |
151 | lua_error ("variable buffer overflow"); | 160 | lua_error ("variable buffer overflow"); |
152 | } | 161 | } |
@@ -436,8 +445,7 @@ function : FUNCTION NAME | |||
436 | method : FUNCTION NAME ':' NAME | 445 | method : FUNCTION NAME ':' NAME |
437 | { | 446 | { |
438 | init_function($4); | 447 | init_function($4); |
439 | localvar[nlocalvar]=luaI_findsymbolbyname("self"); | 448 | add_localvar(luaI_findsymbolbyname("self")); |
440 | add_nlocalvar(1); | ||
441 | } | 449 | } |
442 | body | 450 | body |
443 | { | 451 | { |
@@ -506,9 +514,9 @@ stat1 : IF expr1 THEN PrepJump block PrepJump elsepart END | |||
506 | } | 514 | } |
507 | | functioncall { code_byte(0); } | 515 | | functioncall { code_byte(0); } |
508 | | LOCAL localdeclist decinit | 516 | | LOCAL localdeclist decinit |
509 | { add_nlocalvar($2); | 517 | { nlocalvar += $2; |
510 | adjust_mult_assign($2, $3, 0); | 518 | adjust_mult_assign($2, $3, 0); |
511 | } | 519 | } |
512 | ; | 520 | ; |
513 | 521 | ||
514 | elsepart : /* empty */ | 522 | elsepart : /* empty */ |
@@ -632,13 +640,11 @@ parlist : /* empty */ { lua_codeadjust(0); } | |||
632 | 640 | ||
633 | parlist1 : NAME | 641 | parlist1 : NAME |
634 | { | 642 | { |
635 | localvar[nlocalvar]=luaI_findsymbol($1); | 643 | add_localvar(luaI_findsymbol($1)); |
636 | add_nlocalvar(1); | ||
637 | } | 644 | } |
638 | | parlist1 ',' NAME | 645 | | parlist1 ',' NAME |
639 | { | 646 | { |
640 | localvar[nlocalvar]=luaI_findsymbol($3); | 647 | add_localvar(luaI_findsymbol($3)); |
641 | add_nlocalvar(1); | ||
642 | } | 648 | } |
643 | ; | 649 | ; |
644 | 650 | ||
@@ -683,12 +689,12 @@ lfieldlist1 : expr1 {$$=1;} | |||
683 | varlist1 : var | 689 | varlist1 : var |
684 | { | 690 | { |
685 | nvarbuffer = 0; | 691 | nvarbuffer = 0; |
686 | varbuffer[nvarbuffer] = $1; incr_nvarbuffer(); | 692 | add_varbuffer($1); |
687 | $$ = ($1 == 0) ? 1 : 0; | 693 | $$ = ($1 == 0) ? 1 : 0; |
688 | } | 694 | } |
689 | | varlist1 ',' var | 695 | | varlist1 ',' var |
690 | { | 696 | { |
691 | varbuffer[nvarbuffer] = $3; incr_nvarbuffer(); | 697 | add_varbuffer($3); |
692 | $$ = ($3 == 0) ? $1 + 1 : $1; | 698 | $$ = ($3 == 0) ? $1 + 1 : $1; |
693 | } | 699 | } |
694 | ; | 700 | ; |
@@ -720,10 +726,10 @@ singlevar : NAME | |||
720 | varexp : var { lua_pushvar($1); } | 726 | varexp : var { lua_pushvar($1); } |
721 | ; | 727 | ; |
722 | 728 | ||
723 | localdeclist : NAME {localvar[nlocalvar]=luaI_findsymbol($1); $$ = 1;} | 729 | localdeclist : NAME {store_localvar(luaI_findsymbol($1), 0); $$ = 1;} |
724 | | localdeclist ',' NAME | 730 | | localdeclist ',' NAME |
725 | { | 731 | { |
726 | localvar[nlocalvar+$1]=luaI_findsymbol($3); | 732 | store_localvar(luaI_findsymbol($3), $1); |
727 | $$ = $1+1; | 733 | $$ = $1+1; |
728 | } | 734 | } |
729 | ; | 735 | ; |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.34 1995/02/06 19:35:09 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.35 1995/02/10 12:51:29 roberto Exp celes $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -23,13 +23,15 @@ char *rcs_opcode="$Id: opcode.c,v 3.34 1995/02/06 19:35:09 roberto Exp roberto $ | |||
23 | #define tostring(o) ((tag(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) | 23 | #define tostring(o) ((tag(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) |
24 | 24 | ||
25 | 25 | ||
26 | #define STACK_BUFFER (STACKGAP+128) | 26 | #define STACK_SIZE 128 |
27 | 27 | ||
28 | typedef int StkId; /* index to stack elements */ | 28 | typedef int StkId; /* index to stack elements */ |
29 | 29 | ||
30 | static Long maxstack = 0L; | 30 | static Object initial_stack; |
31 | static Object *stack = NULL; | 31 | |
32 | static Object *top = NULL; | 32 | static Object *stackLimit = &initial_stack+1; |
33 | static Object *stack = &initial_stack; | ||
34 | static Object *top = &initial_stack; | ||
33 | 35 | ||
34 | 36 | ||
35 | /* macros to convert from lua_Object to (Object *) and back */ | 37 | /* macros to convert from lua_Object to (Object *) and back */ |
@@ -38,6 +40,11 @@ static Object *top = NULL; | |||
38 | #define Ref(st) ((st)-stack+1) | 40 | #define Ref(st) ((st)-stack+1) |
39 | 41 | ||
40 | 42 | ||
43 | /* macro to increment stack top. There must be always an empty slot in | ||
44 | * the stack | ||
45 | */ | ||
46 | #define incr_top if (++top >= stackLimit) growstack() | ||
47 | |||
41 | static StkId CBase = 0; /* when Lua calls C or C calls Lua, points to */ | 48 | static StkId CBase = 0; /* when Lua calls C or C calls Lua, points to */ |
42 | /* the first slot after the last parameter. */ | 49 | /* the first slot after the last parameter. */ |
43 | static int CnResults = 0; /* when Lua calls C, has the number of parameters; */ | 50 | static int CnResults = 0; /* when Lua calls C, has the number of parameters; */ |
@@ -88,29 +95,35 @@ void lua_error (char *s) | |||
88 | */ | 95 | */ |
89 | static void lua_initstack (void) | 96 | static void lua_initstack (void) |
90 | { | 97 | { |
91 | maxstack = STACK_BUFFER; | 98 | Long maxstack = STACK_SIZE; |
92 | stack = newvector(maxstack, Object); | 99 | stack = newvector(maxstack, Object); |
100 | stackLimit = stack+maxstack; | ||
93 | top = stack; | 101 | top = stack; |
102 | *top = initial_stack; | ||
94 | } | 103 | } |
95 | 104 | ||
96 | 105 | ||
97 | /* | 106 | /* |
98 | ** Check stack overflow and, if necessary, realloc vector | 107 | ** Check stack overflow and, if necessary, realloc vector |
99 | */ | 108 | */ |
100 | #define lua_checkstack(n) if ((Long)(n) > maxstack) checkstack(n) | 109 | #define lua_checkstack(nt) if ((nt) >= stackLimit) growstack() |
101 | 110 | ||
102 | static void checkstack (StkId n) | 111 | static void growstack (void) |
103 | { | 112 | { |
104 | StkId t; | 113 | StkId t = top-stack; |
105 | if (stack == NULL) | 114 | if (stack == &initial_stack) |
106 | lua_initstack(); | 115 | lua_initstack(); |
107 | if (maxstack >= MAX_INT) | 116 | else |
108 | lua_error("stack size overflow"); | 117 | { |
109 | t = top-stack; | 118 | Long maxstack = stackLimit - stack; |
110 | maxstack *= 2; | 119 | if (maxstack >= MAX_INT) |
111 | if (maxstack >= MAX_INT) | 120 | lua_error("stack size overflow"); |
112 | maxstack = MAX_INT; | 121 | maxstack *= 2; |
113 | stack = growvector(stack, maxstack, Object); | 122 | if (maxstack >= MAX_INT) |
123 | maxstack = MAX_INT; | ||
124 | stack = growvector(stack, maxstack, Object); | ||
125 | stackLimit = stack+maxstack; | ||
126 | } | ||
114 | top = stack + t; | 127 | top = stack + t; |
115 | } | 128 | } |
116 | 129 | ||
@@ -185,8 +198,8 @@ static int lua_tostring (Object *obj) | |||
185 | static void adjust_top (StkId newtop) | 198 | static void adjust_top (StkId newtop) |
186 | { | 199 | { |
187 | Object *nt; | 200 | Object *nt; |
188 | lua_checkstack(newtop); | 201 | lua_checkstack(stack+newtop); |
189 | nt = stack+newtop; | 202 | nt = stack+newtop; /* warning: previous call may change stack */ |
190 | while (top < nt) tag(top++) = LUA_T_NIL; | 203 | while (top < nt) tag(top++) = LUA_T_NIL; |
191 | top = nt; /* top could be bigger than newtop */ | 204 | top = nt; /* top could be bigger than newtop */ |
192 | } | 205 | } |
@@ -227,7 +240,7 @@ static void call_funcFB (Object *func, StkId base, int nResults, StkId whereRes) | |||
227 | /* open space for first parameter (func) */ | 240 | /* open space for first parameter (func) */ |
228 | for (i=top-stack; i>base; i--) | 241 | for (i=top-stack; i>base; i--) |
229 | stack[i] = stack[i-1]; | 242 | stack[i] = stack[i-1]; |
230 | top++; | 243 | incr_top; |
231 | stack[base] = *func; | 244 | stack[base] = *func; |
232 | do_call(&luaI_fallBacks[FB_FUNCTION].function, base, nResults, whereRes); | 245 | do_call(&luaI_fallBacks[FB_FUNCTION].function, base, nResults, whereRes); |
233 | } | 246 | } |
@@ -499,7 +512,7 @@ lua_Object lua_createtable (void) | |||
499 | adjustC(0); | 512 | adjustC(0); |
500 | avalue(top) = lua_createarray(0); | 513 | avalue(top) = lua_createarray(0); |
501 | tag(top) = LUA_T_ARRAY; | 514 | tag(top) = LUA_T_ARRAY; |
502 | top++; | 515 | incr_top; |
503 | CBase++; /* incorporate object in the stack */ | 516 | CBase++; /* incorporate object in the stack */ |
504 | return Ref(top-1); | 517 | return Ref(top-1); |
505 | } | 518 | } |
@@ -561,7 +574,7 @@ lua_Object lua_getlocked (int ref) | |||
561 | { | 574 | { |
562 | adjustC(0); | 575 | adjustC(0); |
563 | *top = *luaI_getlocked(ref); | 576 | *top = *luaI_getlocked(ref); |
564 | top++; | 577 | incr_top; |
565 | CBase++; /* incorporate object in the stack */ | 578 | CBase++; /* incorporate object in the stack */ |
566 | return Ref(top-1); | 579 | return Ref(top-1); |
567 | } | 580 | } |
@@ -569,9 +582,8 @@ lua_Object lua_getlocked (int ref) | |||
569 | 582 | ||
570 | void lua_pushlocked (int ref) | 583 | void lua_pushlocked (int ref) |
571 | { | 584 | { |
572 | lua_checkstack(top-stack+1); | ||
573 | *top = *luaI_getlocked(ref); | 585 | *top = *luaI_getlocked(ref); |
574 | top++; | 586 | incr_top; |
575 | } | 587 | } |
576 | 588 | ||
577 | 589 | ||
@@ -590,7 +602,7 @@ lua_Object lua_getglobal (char *name) | |||
590 | Word n = luaI_findsymbolbyname(name); | 602 | Word n = luaI_findsymbolbyname(name); |
591 | adjustC(0); | 603 | adjustC(0); |
592 | *top = s_object(n); | 604 | *top = s_object(n); |
593 | top++; | 605 | incr_top; |
594 | CBase++; /* incorporate object in the stack */ | 606 | CBase++; /* incorporate object in the stack */ |
595 | return Ref(top-1); | 607 | return Ref(top-1); |
596 | } | 608 | } |
@@ -610,8 +622,8 @@ void lua_storeglobal (char *name) | |||
610 | */ | 622 | */ |
611 | void lua_pushnil (void) | 623 | void lua_pushnil (void) |
612 | { | 624 | { |
613 | lua_checkstack(top-stack+1); | 625 | tag(top) = LUA_T_NIL; |
614 | tag(top++) = LUA_T_NIL; | 626 | incr_top; |
615 | } | 627 | } |
616 | 628 | ||
617 | /* | 629 | /* |
@@ -619,8 +631,8 @@ void lua_pushnil (void) | |||
619 | */ | 631 | */ |
620 | void lua_pushnumber (real n) | 632 | void lua_pushnumber (real n) |
621 | { | 633 | { |
622 | lua_checkstack(top-stack+1); | 634 | tag(top) = LUA_T_NUMBER; nvalue(top) = n; |
623 | tag(top) = LUA_T_NUMBER; nvalue(top++) = n; | 635 | incr_top; |
624 | } | 636 | } |
625 | 637 | ||
626 | /* | 638 | /* |
@@ -628,10 +640,9 @@ void lua_pushnumber (real n) | |||
628 | */ | 640 | */ |
629 | void lua_pushstring (char *s) | 641 | void lua_pushstring (char *s) |
630 | { | 642 | { |
631 | lua_checkstack(top-stack+1); | ||
632 | tsvalue(top) = lua_createstring(s); | 643 | tsvalue(top) = lua_createstring(s); |
633 | tag(top) = LUA_T_STRING; | 644 | tag(top) = LUA_T_STRING; |
634 | top++; | 645 | incr_top; |
635 | } | 646 | } |
636 | 647 | ||
637 | /* | 648 | /* |
@@ -639,10 +650,9 @@ void lua_pushstring (char *s) | |||
639 | */ | 650 | */ |
640 | void lua_pushliteral (char *s) | 651 | void lua_pushliteral (char *s) |
641 | { | 652 | { |
642 | lua_checkstack(top-stack+1); | ||
643 | tsvalue(top) = lua_constant[luaI_findconstant(lua_constcreate(s))]; | 653 | tsvalue(top) = lua_constant[luaI_findconstant(lua_constcreate(s))]; |
644 | tag(top) = LUA_T_STRING; | 654 | tag(top) = LUA_T_STRING; |
645 | top++; | 655 | incr_top; |
646 | } | 656 | } |
647 | 657 | ||
648 | /* | 658 | /* |
@@ -650,8 +660,8 @@ void lua_pushliteral (char *s) | |||
650 | */ | 660 | */ |
651 | void lua_pushcfunction (lua_CFunction fn) | 661 | void lua_pushcfunction (lua_CFunction fn) |
652 | { | 662 | { |
653 | lua_checkstack(top-stack+1); | 663 | tag(top) = LUA_T_CFUNCTION; fvalue(top) = fn; |
654 | tag(top) = LUA_T_CFUNCTION; fvalue(top++) = fn; | 664 | incr_top; |
655 | } | 665 | } |
656 | 666 | ||
657 | /* | 667 | /* |
@@ -660,8 +670,8 @@ void lua_pushcfunction (lua_CFunction fn) | |||
660 | void lua_pushusertag (void *u, int tag) | 670 | void lua_pushusertag (void *u, int tag) |
661 | { | 671 | { |
662 | if (tag < LUA_T_USERDATA) return; | 672 | if (tag < LUA_T_USERDATA) return; |
663 | lua_checkstack(top-stack+1); | 673 | tag(top) = tag; uvalue(top) = u; |
664 | tag(top) = tag; uvalue(top++) = u; | 674 | incr_top; |
665 | } | 675 | } |
666 | 676 | ||
667 | /* | 677 | /* |
@@ -669,8 +679,8 @@ void lua_pushusertag (void *u, int tag) | |||
669 | */ | 679 | */ |
670 | void lua_pushobject (lua_Object o) | 680 | void lua_pushobject (lua_Object o) |
671 | { | 681 | { |
672 | lua_checkstack(top-stack+1); | 682 | *top = *Address(o); |
673 | *top++ = *Address(o); | 683 | incr_top; |
674 | } | 684 | } |
675 | 685 | ||
676 | /* | 686 | /* |
@@ -678,8 +688,8 @@ void lua_pushobject (lua_Object o) | |||
678 | */ | 688 | */ |
679 | void luaI_pushobject (Object *o) | 689 | void luaI_pushobject (Object *o) |
680 | { | 690 | { |
681 | lua_checkstack(top-stack+1); | 691 | *top = *o; |
682 | *top++ = *o; | 692 | incr_top; |
683 | } | 693 | } |
684 | 694 | ||
685 | int lua_type (lua_Object o) | 695 | int lua_type (lua_Object o) |
@@ -693,7 +703,8 @@ int lua_type (lua_Object o) | |||
693 | 703 | ||
694 | void luaI_gcFB (Object *o) | 704 | void luaI_gcFB (Object *o) |
695 | { | 705 | { |
696 | *(top++) = *o; | 706 | *top = *o; |
707 | incr_top; | ||
697 | do_call(&luaI_fallBacks[FB_GC].function, (top-stack)-1, 0, (top-stack)-1); | 708 | do_call(&luaI_fallBacks[FB_GC].function, (top-stack)-1, 0, (top-stack)-1); |
698 | } | 709 | } |
699 | 710 | ||
@@ -734,26 +745,28 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal, | |||
734 | */ | 745 | */ |
735 | static StkId lua_execute (Byte *pc, StkId base) | 746 | static StkId lua_execute (Byte *pc, StkId base) |
736 | { | 747 | { |
737 | lua_checkstack(STACKGAP+MAX_TEMPS+base); | ||
738 | while (1) | 748 | while (1) |
739 | { | 749 | { |
740 | OpCode opcode; | 750 | OpCode opcode; |
741 | switch (opcode = (OpCode)*pc++) | 751 | switch (opcode = (OpCode)*pc++) |
742 | { | 752 | { |
743 | case PUSHNIL: tag(top++) = LUA_T_NIL; break; | 753 | case PUSHNIL: tag(top) = LUA_T_NIL; incr_top; break; |
744 | 754 | ||
745 | case PUSH0: case PUSH1: case PUSH2: | 755 | case PUSH0: case PUSH1: case PUSH2: |
746 | tag(top) = LUA_T_NUMBER; | 756 | tag(top) = LUA_T_NUMBER; |
747 | nvalue(top++) = opcode-PUSH0; | 757 | nvalue(top) = opcode-PUSH0; |
758 | incr_top; | ||
748 | break; | 759 | break; |
749 | 760 | ||
750 | case PUSHBYTE: tag(top) = LUA_T_NUMBER; nvalue(top++) = *pc++; break; | 761 | case PUSHBYTE: |
762 | tag(top) = LUA_T_NUMBER; nvalue(top) = *pc++; incr_top; break; | ||
751 | 763 | ||
752 | case PUSHWORD: | 764 | case PUSHWORD: |
753 | { | 765 | { |
754 | CodeWord code; | 766 | CodeWord code; |
755 | get_word(code,pc); | 767 | get_word(code,pc); |
756 | tag(top) = LUA_T_NUMBER; nvalue(top++) = code.w; | 768 | tag(top) = LUA_T_NUMBER; nvalue(top) = code.w; |
769 | incr_top; | ||
757 | } | 770 | } |
758 | break; | 771 | break; |
759 | 772 | ||
@@ -761,7 +774,8 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
761 | { | 774 | { |
762 | CodeFloat code; | 775 | CodeFloat code; |
763 | get_float(code,pc); | 776 | get_float(code,pc); |
764 | tag(top) = LUA_T_NUMBER; nvalue(top++) = code.f; | 777 | tag(top) = LUA_T_NUMBER; nvalue(top) = code.f; |
778 | incr_top; | ||
765 | } | 779 | } |
766 | break; | 780 | break; |
767 | 781 | ||
@@ -769,7 +783,8 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
769 | { | 783 | { |
770 | CodeWord code; | 784 | CodeWord code; |
771 | get_word(code,pc); | 785 | get_word(code,pc); |
772 | tag(top) = LUA_T_STRING; tsvalue(top++) = lua_constant[code.w]; | 786 | tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[code.w]; |
787 | incr_top; | ||
773 | } | 788 | } |
774 | break; | 789 | break; |
775 | 790 | ||
@@ -777,22 +792,25 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
777 | { | 792 | { |
778 | CodeCode code; | 793 | CodeCode code; |
779 | get_code(code,pc); | 794 | get_code(code,pc); |
780 | tag(top) = LUA_T_FUNCTION; bvalue(top++) = code.b; | 795 | tag(top) = LUA_T_FUNCTION; bvalue(top) = code.b; |
796 | incr_top; | ||
781 | } | 797 | } |
782 | break; | 798 | break; |
783 | 799 | ||
784 | case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: | 800 | case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: |
785 | case PUSHLOCAL3: case PUSHLOCAL4: case PUSHLOCAL5: | 801 | case PUSHLOCAL3: case PUSHLOCAL4: case PUSHLOCAL5: |
786 | case PUSHLOCAL6: case PUSHLOCAL7: case PUSHLOCAL8: | 802 | case PUSHLOCAL6: case PUSHLOCAL7: case PUSHLOCAL8: |
787 | case PUSHLOCAL9: *top++ = *((stack+base) + (int)(opcode-PUSHLOCAL0)); break; | 803 | case PUSHLOCAL9: |
804 | *top = *((stack+base) + (int)(opcode-PUSHLOCAL0)); incr_top; break; | ||
788 | 805 | ||
789 | case PUSHLOCAL: *top++ = *((stack+base) + (*pc++)); break; | 806 | case PUSHLOCAL: *top = *((stack+base) + (*pc++)); incr_top; break; |
790 | 807 | ||
791 | case PUSHGLOBAL: | 808 | case PUSHGLOBAL: |
792 | { | 809 | { |
793 | CodeWord code; | 810 | CodeWord code; |
794 | get_word(code,pc); | 811 | get_word(code,pc); |
795 | *top++ = s_object(code.w); | 812 | *top = s_object(code.w); |
813 | incr_top; | ||
796 | } | 814 | } |
797 | break; | 815 | break; |
798 | 816 | ||
@@ -805,9 +823,11 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
805 | Object receiver = *(top-1); | 823 | Object receiver = *(top-1); |
806 | CodeWord code; | 824 | CodeWord code; |
807 | get_word(code,pc); | 825 | get_word(code,pc); |
808 | tag(top) = LUA_T_STRING; tsvalue(top++) = lua_constant[code.w]; | 826 | tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[code.w]; |
827 | incr_top; | ||
809 | pushsubscript(); | 828 | pushsubscript(); |
810 | *(top++) = receiver; | 829 | *top = receiver; |
830 | incr_top; | ||
811 | break; | 831 | break; |
812 | } | 832 | } |
813 | 833 | ||
@@ -837,6 +857,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
837 | int n = *pc++; | 857 | int n = *pc++; |
838 | if (tag(top-3-n) != LUA_T_ARRAY) | 858 | if (tag(top-3-n) != LUA_T_ARRAY) |
839 | { | 859 | { |
860 | lua_checkstack(top+2); | ||
840 | *(top+1) = *(top-1); | 861 | *(top+1) = *(top-1); |
841 | *(top) = *(top-2-n); | 862 | *(top) = *(top-2-n); |
842 | *(top-1) = *(top-3-n); | 863 | *(top-1) = *(top-3-n); |
@@ -901,7 +922,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
901 | get_word(size,pc); | 922 | get_word(size,pc); |
902 | avalue(top) = lua_createarray(size.w); | 923 | avalue(top) = lua_createarray(size.w); |
903 | tag(top) = LUA_T_ARRAY; | 924 | tag(top) = LUA_T_ARRAY; |
904 | top++; | 925 | incr_top; |
905 | } | 926 | } |
906 | break; | 927 | break; |
907 | 928 | ||
@@ -1007,7 +1028,8 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1007 | case MINUSOP: | 1028 | case MINUSOP: |
1008 | if (tonumber(top-1)) | 1029 | if (tonumber(top-1)) |
1009 | { | 1030 | { |
1010 | tag(top++) = LUA_T_NIL; | 1031 | tag(top) = LUA_T_NIL; |
1032 | incr_top; | ||
1011 | call_arith("unm"); | 1033 | call_arith("unm"); |
1012 | } | 1034 | } |
1013 | else | 1035 | else |
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
3 | ** $Id: opcode.h,v 3.9 1994/11/23 14:31:11 roberto Stab $ | 3 | ** $Id: opcode.h,v 3.10 1994/12/20 21:20:36 roberto Exp celes $ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
@@ -10,18 +10,12 @@ | |||
10 | #include "types.h" | 10 | #include "types.h" |
11 | #include "tree.h" | 11 | #include "tree.h" |
12 | 12 | ||
13 | #ifndef STACKGAP | ||
14 | #define STACKGAP 128 | ||
15 | #endif | ||
16 | |||
17 | #ifndef real | 13 | #ifndef real |
18 | #define real float | 14 | #define real float |
19 | #endif | 15 | #endif |
20 | 16 | ||
21 | #define FIELDS_PER_FLUSH 40 | 17 | #define FIELDS_PER_FLUSH 40 |
22 | 18 | ||
23 | #define MAX_TEMPS 20 | ||
24 | |||
25 | 19 | ||
26 | typedef enum | 20 | typedef enum |
27 | { | 21 | { |