This commit is contained in:
blueloveTH 2022-11-09 23:16:20 +08:00
parent 93be8d7a7b
commit 65f6026e64
3 changed files with 14 additions and 19 deletions

View File

@ -26,18 +26,6 @@ struct Loop {
Loop(bool forLoop, int start) : forLoop(forLoop), start(start) {} 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 { class Compiler {
public: public:
std::unique_ptr<Parser> parser; std::unique_ptr<Parser> parser;
@ -501,7 +489,16 @@ __LISTCOMP:
} }
void exprCall() { 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); emitCode(OP_CALL, ARGC);
} }

View File

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

View File

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