From b8af9c56c95722e7a3289f02568b9e2a7495c484 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 6 Mar 1997 14:30:55 -0300 Subject: new form for constructors: {[exp] = exp, ...} --- lua.stx | 50 +++++++++++++++++++++++--------------------------- opcode.c | 14 ++++++++++++-- opcode.h | 6 +++--- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/lua.stx b/lua.stx index d803d4ba..cb0a29d3 100644 --- a/lua.stx +++ b/lua.stx @@ -1,6 +1,6 @@ %{ -char *rcs_luastx = "$Id: lua.stx,v 3.43 1997/01/31 14:27:11 roberto Exp roberto $"; +char *rcs_luastx = "$Id: lua.stx,v 3.44 1997/02/13 16:18:39 roberto Exp roberto $"; #include #include @@ -50,8 +50,6 @@ static TaggedString *localvar[MAXLOCALS]; /* store local variable names */ static int nlocalvar=0; /* number of local variables */ #define MAXFIELDS FIELDS_PER_FLUSH*2 -static Word fields[MAXFIELDS]; /* fieldnames to be flushed */ -static int nfields=0; int lua_debug = 0; @@ -103,22 +101,11 @@ static void code_word_at (Byte *p, int n) memcpy(p, &w, sizeof(Word)); } -static void push_field (Word name) -{ - if (nfields < MAXFIELDS) - fields[nfields++] = name; - else - yyerror ("too many fields in nested constructors"); -} - static void flush_record (int n) { - int i; if (n == 0) return; - code_byte(STORERECORD); + code_byte(STOREMAP); code_byte(n); - for (i=0; i #include @@ -1184,7 +1184,7 @@ static StkId lua_execute (Byte *pc, StkId base) } break; - case STORERECORD: + case STORERECORD: /* opcode obsolete: supersed by STOREMAP */ { int n = *(pc++); Object *arr = top-n-1; @@ -1200,6 +1200,16 @@ static StkId lua_execute (Byte *pc, StkId base) } break; + case STOREMAP: { + int n = *(pc++); + Object *arr = top-(2*n)-1; + while (n--) { + *(lua_hashdefine (avalue(arr), top-2)) = *(top-1); + top-=2; + } + } + break; + case ADJUST0: adjust_top(base); break; diff --git a/opcode.h b/opcode.h index c3942159..c15b9533 100644 --- a/opcode.h +++ b/opcode.h @@ -1,6 +1,6 @@ /* ** TeCGraf - PUC-Rio -** $Id: opcode.h,v 3.25 1997/02/11 11:35:05 roberto Exp roberto $ +** $Id: opcode.h,v 3.26 1997/02/20 15:51:14 roberto Exp roberto $ */ #ifndef opcode_h @@ -101,8 +101,8 @@ CALLFUNC,/* n m v_n...v_1 f r_m...r_1 f(v1,...,v_n) */ RETCODE0, RETCODE,/* b - - */ SETLINE,/* w - - LINE=w */ -VARARGS/* b v_n...v_1 {v_1...v_n;n=n} */ - +VARARGS,/* b v_n...v_1 {v_1...v_n;n=n} */ +STOREMAP/* n v_n k_n ...v_1 k_1 t - t[k_i]=v_i */ } OpCode; -- cgit v1.2.3-55-g6feb