diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-06 14:30:55 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-06 14:30:55 -0300 |
commit | b8af9c56c95722e7a3289f02568b9e2a7495c484 (patch) | |
tree | 463f99205e403ff0790dc7dc7a4fd7ab0676f935 | |
parent | c3c0b52a1f1318c3b1131d260100ad9d999db5d5 (diff) | |
download | lua-b8af9c56c95722e7a3289f02568b9e2a7495c484.tar.gz lua-b8af9c56c95722e7a3289f02568b9e2a7495c484.tar.bz2 lua-b8af9c56c95722e7a3289f02568b9e2a7495c484.zip |
new form for constructors: {[exp] = exp, ...}
-rw-r--r-- | lua.stx | 50 | ||||
-rw-r--r-- | opcode.c | 14 | ||||
-rw-r--r-- | opcode.h | 6 |
3 files changed, 38 insertions, 32 deletions
@@ -1,6 +1,6 @@ | |||
1 | %{ | 1 | %{ |
2 | 2 | ||
3 | char *rcs_luastx = "$Id: lua.stx,v 3.43 1997/01/31 14:27:11 roberto Exp roberto $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 3.44 1997/02/13 16:18:39 roberto Exp roberto $"; |
4 | 4 | ||
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
@@ -50,8 +50,6 @@ static TaggedString *localvar[MAXLOCALS]; /* store local variable names */ | |||
50 | static int nlocalvar=0; /* number of local variables */ | 50 | static int nlocalvar=0; /* number of local variables */ |
51 | 51 | ||
52 | #define MAXFIELDS FIELDS_PER_FLUSH*2 | 52 | #define MAXFIELDS FIELDS_PER_FLUSH*2 |
53 | static Word fields[MAXFIELDS]; /* fieldnames to be flushed */ | ||
54 | static int nfields=0; | ||
55 | 53 | ||
56 | int lua_debug = 0; | 54 | int lua_debug = 0; |
57 | 55 | ||
@@ -103,22 +101,11 @@ static void code_word_at (Byte *p, int n) | |||
103 | memcpy(p, &w, sizeof(Word)); | 101 | memcpy(p, &w, sizeof(Word)); |
104 | } | 102 | } |
105 | 103 | ||
106 | static void push_field (Word name) | ||
107 | { | ||
108 | if (nfields < MAXFIELDS) | ||
109 | fields[nfields++] = name; | ||
110 | else | ||
111 | yyerror ("too many fields in nested constructors"); | ||
112 | } | ||
113 | |||
114 | static void flush_record (int n) | 104 | static void flush_record (int n) |
115 | { | 105 | { |
116 | int i; | ||
117 | if (n == 0) return; | 106 | if (n == 0) return; |
118 | code_byte(STORERECORD); | 107 | code_byte(STOREMAP); |
119 | code_byte(n); | 108 | code_byte(n); |
120 | for (i=0; i<n; i++) | ||
121 | code_word(fields[--nfields]); | ||
122 | } | 109 | } |
123 | 110 | ||
124 | static void flush_list (int m, int n) | 111 | static void flush_list (int m, int n) |
@@ -161,6 +148,17 @@ static void add_varbuffer (Long var) | |||
161 | yyerror ("variable buffer overflow"); | 148 | yyerror ("variable buffer overflow"); |
162 | } | 149 | } |
163 | 150 | ||
151 | static void code_string (Word w) | ||
152 | { | ||
153 | code_byte(PUSHSTRING); | ||
154 | code_word(w); | ||
155 | } | ||
156 | |||
157 | static void code_constant (TaggedString *s) | ||
158 | { | ||
159 | code_string(luaI_findconstant(s)); | ||
160 | } | ||
161 | |||
164 | static void code_number (float f) | 162 | static void code_number (float f) |
165 | { | 163 | { |
166 | Word i; | 164 | Word i; |
@@ -477,8 +475,7 @@ function : FUNCTION funcname body | |||
477 | funcname : var { $$ =$1; init_func(); } | 475 | funcname : var { $$ =$1; init_func(); } |
478 | | varexp ':' NAME | 476 | | varexp ':' NAME |
479 | { | 477 | { |
480 | code_byte(PUSHSTRING); | 478 | code_constant($3); |
481 | code_word(luaI_findconstant($3)); | ||
482 | $$ = 0; /* indexed variable */ | 479 | $$ = 0; /* indexed variable */ |
483 | init_func(); | 480 | init_func(); |
484 | add_localvar(luaI_createfixedstring("self")); | 481 | add_localvar(luaI_createfixedstring("self")); |
@@ -605,9 +602,8 @@ expr : '(' expr ')' { $$ = $2; } | |||
605 | | NUMBER { code_number($1); $$ = 0; } | 602 | | NUMBER { code_number($1); $$ = 0; } |
606 | | STRING | 603 | | STRING |
607 | { | 604 | { |
608 | code_byte(PUSHSTRING); | 605 | code_string($1); |
609 | code_word($1); | 606 | $$ = 0; |
610 | $$ = 0; | ||
611 | } | 607 | } |
612 | | NIL {code_byte(PUSHNIL); $$ = 0; } | 608 | | NIL {code_byte(PUSHNIL); $$ = 0; } |
613 | | functioncall { $$ = $1; } | 609 | | functioncall { $$ = $1; } |
@@ -723,12 +719,13 @@ ffieldlist1 : ffield {$$=1;} | |||
723 | } | 719 | } |
724 | ; | 720 | ; |
725 | 721 | ||
726 | ffield : NAME '=' expr1 | 722 | ffield : ffieldkey '=' expr1 |
727 | { | ||
728 | push_field(luaI_findconstant($1)); | ||
729 | } | ||
730 | ; | 723 | ; |
731 | 724 | ||
725 | ffieldkey : '[' expr1 ']' | ||
726 | | NAME { code_constant($1); } | ||
727 | ; | ||
728 | |||
732 | lfieldlist : /* empty */ { $$ = 0; } | 729 | lfieldlist : /* empty */ { $$ = 0; } |
733 | | lfieldlist1 lastcomma { $$ = $1; } | 730 | | lfieldlist1 lastcomma { $$ = $1; } |
734 | ; | 731 | ; |
@@ -762,9 +759,8 @@ var : singlevar { $$ = $1; } | |||
762 | } | 759 | } |
763 | | varexp '.' NAME | 760 | | varexp '.' NAME |
764 | { | 761 | { |
765 | code_byte(PUSHSTRING); | 762 | code_constant($3); |
766 | code_word(luaI_findconstant($3)); | 763 | $$ = 0; /* indexed variable */ |
767 | $$ = 0; /* indexed variable */ | ||
768 | } | 764 | } |
769 | ; | 765 | ; |
770 | 766 | ||
@@ -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.81 1997/02/20 15:51:14 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.82 1997/02/26 17:38:41 roberto Unstable roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -1184,7 +1184,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1184 | } | 1184 | } |
1185 | break; | 1185 | break; |
1186 | 1186 | ||
1187 | case STORERECORD: | 1187 | case STORERECORD: /* opcode obsolete: supersed by STOREMAP */ |
1188 | { | 1188 | { |
1189 | int n = *(pc++); | 1189 | int n = *(pc++); |
1190 | Object *arr = top-n-1; | 1190 | Object *arr = top-n-1; |
@@ -1200,6 +1200,16 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1200 | } | 1200 | } |
1201 | break; | 1201 | break; |
1202 | 1202 | ||
1203 | case STOREMAP: { | ||
1204 | int n = *(pc++); | ||
1205 | Object *arr = top-(2*n)-1; | ||
1206 | while (n--) { | ||
1207 | *(lua_hashdefine (avalue(arr), top-2)) = *(top-1); | ||
1208 | top-=2; | ||
1209 | } | ||
1210 | } | ||
1211 | break; | ||
1212 | |||
1203 | case ADJUST0: | 1213 | case ADJUST0: |
1204 | adjust_top(base); | 1214 | adjust_top(base); |
1205 | break; | 1215 | break; |
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
3 | ** $Id: opcode.h,v 3.25 1997/02/11 11:35:05 roberto Exp roberto $ | 3 | ** $Id: opcode.h,v 3.26 1997/02/20 15:51:14 roberto Exp roberto $ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
@@ -101,8 +101,8 @@ CALLFUNC,/* n m v_n...v_1 f r_m...r_1 f(v1,...,v_n) */ | |||
101 | RETCODE0, | 101 | RETCODE0, |
102 | RETCODE,/* b - - */ | 102 | RETCODE,/* b - - */ |
103 | SETLINE,/* w - - LINE=w */ | 103 | SETLINE,/* w - - LINE=w */ |
104 | VARARGS/* b v_n...v_1 {v_1...v_n;n=n} */ | 104 | VARARGS,/* b v_n...v_1 {v_1...v_n;n=n} */ |
105 | 105 | STOREMAP/* n v_n k_n ...v_1 k_1 t - t[k_i]=v_i */ | |
106 | } OpCode; | 106 | } OpCode; |
107 | 107 | ||
108 | 108 | ||