From 6e6f7e83a16ec2125ab7911c1b401a9cbbc6b9cf Mon Sep 17 00:00:00 2001 From: ivin Date: Thu, 16 Nov 2023 06:31:24 +0800 Subject: [PATCH] Use singleton interpreter --- include/zero.hpp | 1 + src/zero.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/zero.hpp b/include/zero.hpp index 88f2528..ce6c126 100644 --- a/include/zero.hpp +++ b/include/zero.hpp @@ -21,6 +21,7 @@ class VM { const std::string &reason); private: + static Interpreter interpreter; static bool has_parse_error; static bool has_runtime_error; }; diff --git a/src/zero.cpp b/src/zero.cpp index 6fdad7d..e6cf91c 100644 --- a/src/zero.cpp +++ b/src/zero.cpp @@ -14,6 +14,8 @@ #include using namespace zero; +// 全局解释器 +Interpreter VM::interpreter{}; bool VM::has_parse_error = false; bool VM::has_runtime_error = false; @@ -32,7 +34,7 @@ void VM::run(std::string source) { // 解释器 // TODO: 暂时是每一次执行都新创建一个解释器, 在REPL模式下不能利用上下文 - Interpreter interpreter{}; + // Interpreter interpreter{}; interpreter.interpret(statements); if (has_runtime_error) {