blueloveTH 3 lat temu
rodzic
commit
76d167437c
4 zmienionych plików z 9 dodań i 16 usunięć
  1. 0 4
      src/codeobject.h
  2. 7 6
      src/compiler.h
  3. 0 2
      src/opcodes.h
  4. 2 4
      src/vm.h

+ 0 - 4
src/codeobject.h

@@ -220,10 +220,6 @@ public:
         this->ip = i;
     }
 
-    inline void jumpRelative(int i){
-        this->ip += i;
-    }
-
     void jumpAbsoluteSafe(int target){
         const ByteCode& prev = code->co_code[this->ip];
         int i = prev.block;

+ 7 - 6
src/compiler.h

@@ -837,14 +837,10 @@ __LISTCOMP:
     void compileTryExcept() {
         getCode()->__enterBlock(TRY_EXCEPT);
         compileBlockBody();
-        getCode()->__exitBlock();
         int patch = emitCode(OP_JUMP_ABSOLUTE);
+        getCode()->__exitBlock();
         consume(TK("except"));
         if(match(TK("@id"))){       // exception name
-            if(match(TK("as"))){    // exception name as alias
-                consume(TK("@id"));
-                exprName();
-            }
             compileBlockBody();
         }
         if(match(TK("finally"))){
@@ -915,7 +911,12 @@ __LISTCOMP:
         } else if(match(TK("raise"))){
             consume(TK("@id"));         // dummy exception type
             emitCode(OP_LOAD_CONST, getCode()->addConst(vm->PyStr(parser->previous.str())));
-            consume(TK("("));EXPR();consume(TK(")"));
+            if(match(TK("("))){
+                EXPR();
+                consume(TK(")"));
+            }else{
+                emitCode(OP_LOAD_NONE); // ...?
+            }
             emitCode(OP_RAISE_ERROR);
             consumeEndStatement();
         } else if(match(TK("del"))){

+ 0 - 2
src/opcodes.h

@@ -72,8 +72,6 @@ OPCODE(GOTO)
 OPCODE(WITH_ENTER)
 OPCODE(WITH_EXIT)
 
-OPCODE(JUMP_RELATIVE)
-
 OPCODE(RAISE_VARARGS)
 
 OPCODE(LOOP_BREAK)

+ 2 - 4
src/vm.h

@@ -246,7 +246,6 @@ protected:
                     frame->push(std::move(ret));
                 } break;
             case OP_JUMP_ABSOLUTE: frame->jumpAbsolute(byte.arg); break;
-            case OP_JUMP_RELATIVE: frame->jumpRelative(byte.arg); break;
             case OP_SAFE_JUMP_ABSOLUTE: frame->jumpAbsoluteSafe(byte.arg); break;
             case OP_GOTO: {
                 PyVar obj = frame->popValue(this);
@@ -277,8 +276,7 @@ protected:
                     auto& it = PyIter_AS_C(frame->__top());
                     if(it->hasNext()){
                         PyRef_AS_C(it->var)->set(this, frame, it->next());
-                    }
-                    else{
+                    }else{
                         int blockEnd = frame->code->co_blocks[byte.block].end;
                         frame->jumpAbsoluteSafe(blockEnd);
                     }
@@ -405,7 +403,7 @@ public:
         return asRepr(obj);
     }
 
-    Frame* topFrame(){
+    inline Frame* topFrame() const {
         if(callstack.size() == 0) UNREACHABLE();
         return callstack.back().get();
     }