Skip to content

Commit

Permalink
Use singleton interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
uchenily committed Nov 15, 2023
1 parent f3b43e2 commit 6e6f7e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class VM {
const std::string &reason);

private:
static Interpreter interpreter;
static bool has_parse_error;
static bool has_runtime_error;
};
4 changes: 3 additions & 1 deletion src/zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <string>

using namespace zero;
// 全局解释器
Interpreter VM::interpreter{};
bool VM::has_parse_error = false;
bool VM::has_runtime_error = false;

Expand All @@ -32,7 +34,7 @@ void VM::run(std::string source) {

// 解释器
// TODO: 暂时是每一次执行都新创建一个解释器, 在REPL模式下不能利用上下文
Interpreter interpreter{};
// Interpreter interpreter{};
interpreter.interpret(statements);

if (has_runtime_error) {
Expand Down

0 comments on commit 6e6f7e8

Please sign in to comment.