This commit is contained in:
2026-01-19 23:10:09 +08:00
parent 1a66d45204
commit 2839c0daff
17 changed files with 2274 additions and 46 deletions

View File

@@ -4,18 +4,30 @@
#include "lexer.h"
#include "parser.h"
#include "interpreter.h"
#include "vm.h"
#include "compiler.h"
#include "value.h"
#include <string>
#include <memory>
namespace camellya {
// Execution mode
enum class ExecutionMode {
INTERPRETER, // Tree-walking interpreter
VM // Bytecode VM
};
// Main state class - similar to lua_State
class State {
public:
State();
State(ExecutionMode mode = ExecutionMode::VM);
~State() = default;
// Set execution mode
void set_execution_mode(ExecutionMode mode) { execution_mode_ = mode; }
ExecutionMode get_execution_mode() const { return execution_mode_; }
// Execute script from string
bool do_string(const std::string& script);
@@ -51,11 +63,17 @@ public:
const std::string& get_error() const { return last_error_; }
private:
ExecutionMode execution_mode_;
std::unique_ptr<Interpreter> interpreter_;
std::unique_ptr<VM> vm_;
std::unique_ptr<Compiler> compiler_;
std::vector<ValuePtr> stack_;
std::string last_error_;
ValuePtr get_stack_value(int index);
// Helper for execution
bool execute_program(const Program& program);
};
} // namespace camellya