lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, 28 Jan 2011, Alexander Gladysh wrote:
>
> Thank you, Tony. Can you please produce the same patch for LuaJIT 2?

Something like this:

diff --git a/src/lj_parse.c b/src/lj_parse.c
index b9338c2..2c22a22 100644
--- a/src/lj_parse.c
+++ b/src/lj_parse.c
@@ -601,9 +601,12 @@ static void bcemit_method(FuncState *fs, ExpDesc *e,
ExpDesc *key)
   expr_free(fs, e);
   func = fs->freereg;
   bcemit_AD(fs, BC_MOV, func+1, obj);  /* Copy object to first argument. */
-  lua_assert(expr_isstrk(key));
-  idx = const_str(fs, key);
-  if (idx <= BCMAX_C) {
+  if (!expr_isstrk(key)) {
+    bcreg_reserve(fs, 3);
+    expr_toreg(fs, key, func+2);
+    bcemit_ABC(fs, BC_TGETV, func, obj, func+2);
+    fs->freereg--;
+  } else if ((idx = const_str(fs, key)) < BCMAX_C) {
     bcreg_reserve(fs, 2);
     bcemit_ABC(fs, BC_TGETS, func, obj, idx);
   } else {
@@ -1614,7 +1617,11 @@ static void expr_primary(LexState *ls, ExpDesc *v)
     } else if (ls->token == ':') {
       ExpDesc key;
       lj_lex_next(ls);
-      expr_str(ls, &key);
+      expr_toanyreg(fs, v);
+      if (ls->token == '[')
+        expr_bracket(ls, &key);
+      else
+        expr_str(ls, &key);
       bcemit_method(fs, v, &key);
       parse_args(ls, v);
     } else if (ls->token == '(' || ls->token == TK_string ||


Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
HUMBER THAMES DOVER WIGHT PORTLAND: NORTH BACKING WEST OR NORTHWEST, 5 TO 7,
DECREASING 4 OR 5, OCCASIONALLY 6 LATER IN HUMBER AND THAMES. MODERATE OR
ROUGH. RAIN THEN FAIR. GOOD.