blueloveTH 3 years ago
parent
commit
65f6026e64
3 changed files with 14 additions and 19 deletions
  1. 10 13
      src/compiler.h
  2. 4 1
      src/pocketpy.h
  3. 0 5
      src/vm.h

+ 10 - 13
src/compiler.h

@@ -26,18 +26,6 @@ struct Loop {
     Loop(bool forLoop, int start) : forLoop(forLoop), start(start) {}
 };
 
-#define ExprCommaSplitArgs(end)     \
-    int ARGC = 0;                   \
-    do {                            \
-        matchNewLines();            \
-        if (peek() == TK(end)) break;   \
-        EXPR();                     \
-        ARGC++;                     \
-        matchNewLines();            \
-    } while (match(TK(",")));       \
-    matchNewLines();                \
-    consume(TK(end));
-
 class Compiler {
 public:
     std::unique_ptr<Parser> parser;
@@ -501,7 +489,16 @@ __LISTCOMP:
     }
 
     void exprCall() {
-        ExprCommaSplitArgs(")");
+        int ARGC = 0;
+        do {
+            matchNewLines();
+            if (peek() == TK(")")) break;
+            EXPR();
+            ARGC++;
+            matchNewLines();
+        } while (match(TK(",")));
+        matchNewLines();
+        consume(TK(")"));
         emitCode(OP_CALL, ARGC);
     }
 

+ 4 - 1
src/pocketpy.h

@@ -449,6 +449,9 @@ extern "C" {
     __EXPORT
     void registerModule(VM* vm, const char* name, const char* source){
         _Code code = compile(vm, source, name + _Str(".py"));
-        vm->registerCompiledModule(name, code);
+        if(code != nullptr){
+            PyVar _m = vm->newModule(name);
+            vm->exec(code, {}, _m);
+        }
     }
 }

+ 0 - 5
src/vm.h

@@ -633,11 +633,6 @@ public:
         return 0;
     }
 
-    void registerCompiledModule(_Str name, _Code code){
-        PyVar _m = newModule(name);
-        exec(code, {}, _m);
-    }
-
     /***** Error Reporter *****/
 private:
     void _error(const _Str& name, const _Str& msg){