blueloveTH 3 years ago
parent
commit
e5ced9d194
2 changed files with 21 additions and 7 deletions
  1. 2 1
      src/compiler.h
  2. 19 6
      src/vm.h

+ 2 - 1
src/compiler.h

@@ -604,7 +604,8 @@ class Compiler {
                 break;
             default: return false;
         }
-        ctx()->emit_expr();
+        Expr_ rhs = ctx()->s_expr.popx();
+        rhs->emit(ctx());
         bool ok = lhs_p->emit_store(ctx());
         if(!ok) SyntaxError();
         return true;

+ 19 - 6
src/vm.h

@@ -590,12 +590,25 @@ inline Str VM::disassemble(CodeObject_ co){
         ss << pad(line, 8) << pointer << pad(std::to_string(i), 3);
         ss << " " << pad(OP_NAMES[byte.op], 20) << " ";
         // ss << pad(byte.arg == -1 ? "" : std::to_string(byte.arg), 5);
-        std::string argStr = byte.arg == -1 ? "" : std::to_string(byte.arg);
-        if(byte.op == OP_LOAD_CONST){
-            argStr += " (" + CAST(Str, asRepr(co->consts[byte.arg])) + ")";
-        }
-        if(byte.op == OP_LOAD_NAME || byte.op == OP_STORE_LOCAL || byte.op == OP_STORE_GLOBAL){
-            argStr += " (" + co->names[byte.arg].str().escape(true) + ")";
+        Str argStr = byte.arg == -1 ? "" : std::to_string(byte.arg);
+        switch(byte.op){
+            case OP_LOAD_CONST:
+                argStr += " (" + CAST(Str, asRepr(co->consts[byte.arg])) + ")";
+                break;
+            case OP_LOAD_NAME: case OP_STORE_LOCAL: case OP_STORE_GLOBAL:
+            case OP_LOAD_ATTR: case OP_STORE_ATTR: case OP_DELETE_ATTR:
+            case OP_DELETE_LOCAL: case OP_DELETE_GLOBAL:
+                argStr += " (" + co->names[byte.arg].str().escape(true) + ")";
+                break;
+            case OP_BINARY_OP:
+                argStr += " (" + BINARY_SPECIAL_METHODS[byte.arg].str() + ")";
+                break;
+            case OP_COMPARE_OP:
+                argStr += " (" + COMPARE_SPECIAL_METHODS[byte.arg].str() + ")";
+                break;
+            case OP_BITWISE_OP:
+                argStr += " (" + BITWISE_SPECIAL_METHODS[byte.arg].str() + ")";
+                break;
         }
         ss << argStr;
         // ss << pad(argStr, 20);      // may overflow