From a398de07ac5d2930d1167c43d8722f05125e04db Mon Sep 17 00:00:00 2001 From: PuqiAR Date: Wed, 25 Feb 2026 17:23:57 +0800 Subject: [PATCH] =?UTF-8?q?0.4.4=20=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/core.hpp | 2 +- src/IR/IR.hpp | 62 ---------------- src/IR/IRInterpreter.hpp | 74 ------------------- src/IR/ir_test_main.cpp | 14 ---- .../VirtualMachine.cpp | 0 .../VirtualMachine.hpp | 0 xmake.lua | 18 ++--- 7 files changed, 9 insertions(+), 161 deletions(-) delete mode 100644 src/IR/IR.hpp delete mode 100644 src/IR/IRInterpreter.hpp delete mode 100644 src/IR/ir_test_main.cpp rename src/{VirtualMachine => __VirtualMachine}/VirtualMachine.cpp (100%) rename src/{VirtualMachine => __VirtualMachine}/VirtualMachine.hpp (100%) diff --git a/src/Core/core.hpp b/src/Core/core.hpp index 2e07843..e7fe0f4 100644 --- a/src/Core/core.hpp +++ b/src/Core/core.hpp @@ -4,7 +4,7 @@ #include #include -#define __FCORE_VERSION "0.4.3-alpha" +#define __FCORE_VERSION "0.4.4-alpha" #if defined(_WIN32) #define __FCORE_PLATFORM "Windows" diff --git a/src/IR/IR.hpp b/src/IR/IR.hpp deleted file mode 100644 index c0bc9f4..0000000 --- a/src/IR/IR.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include - -#include -#include -namespace Fig::IR -{ - using Reg = uint16_t; - using Label = uint32_t; - - constexpr Reg INVALID_REG = 0xFFFF; - - enum class Op : uint8_t - { - // ---- control ---- - Nop, - Jmp, - Br, // conditional branch - Ret, - Call, - - // ---- arithmetic ---- - Add, - Sub, - Mul, - Div, - - // ---- compare ---- - Lt, - Le, - Gt, - Ge, - Eq, - - // ---- data ---- - LoadImm, // immediate -> reg - Mov, - }; - - struct Inst - { - Op op; - - Reg dst; // 结果寄存器 - Reg a; // operand a - Reg b; // operand b - - int64_t imm; // immediate / jump offset - }; - - struct Function - { - FString name; - - uint16_t paramCount; - uint16_t localCount; // 不含参数 - uint16_t regCount; // param + locals + temps - - std::vector code; - }; -}; \ No newline at end of file diff --git a/src/IR/IRInterpreter.hpp b/src/IR/IRInterpreter.hpp deleted file mode 100644 index f0466cc..0000000 --- a/src/IR/IRInterpreter.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include - -#include - -namespace Fig::IR -{ - struct VirtualMachine - { - std::vector functions; - - int64_t execute(Function *fn, const int64_t *args) - { - assert(fn != nullptr); - std::vector regs(fn->regCount); - // load params - - size_t ip = 0; - - while (ip < fn->code.size()) - { - const Inst &ins = fn->code[ip++]; - - switch (ins.op) - { - case Op::Nop: break; - - case Op::LoadImm: regs[ins.dst] = ins.imm; break; - - case Op::Mov: regs[ins.dst] = regs[ins.a]; break; - - case Op::Add: regs[ins.dst] = regs[ins.a] + regs[ins.b]; break; - - case Op::Sub: regs[ins.dst] = regs[ins.a] - regs[ins.b]; break; - - case Op::Mul: regs[ins.dst] = regs[ins.a] * regs[ins.b]; break; - - case Op::Div: regs[ins.dst] = regs[ins.a] / regs[ins.b]; break; - - case Op::Lt: regs[ins.dst] = regs[ins.a] < regs[ins.b]; break; - - case Op::Le: regs[ins.dst] = regs[ins.a] <= regs[ins.b]; break; - - case Op::Gt: regs[ins.dst] = regs[ins.a] > regs[ins.b]; break; - - case Op::Ge: regs[ins.dst] = regs[ins.a] >= regs[ins.b]; break; - - case Op::Eq: regs[ins.dst] = regs[ins.a] == regs[ins.b]; break; - - case Op::Jmp: ip = static_cast(static_cast(ip) + ins.imm); break; - - case Op::Br: - if (regs[ins.a] == 0) { ip = static_cast(static_cast(ip) + ins.imm); } - break; - - case Op::Call: { - // currently supports 1-arg call via reg a - Function *callee = functions.at(static_cast(ins.imm)); - int64_t arg0 = regs[ins.a]; - int64_t ret = execute(callee, &arg0); - regs[ins.dst] = ret; - break; - } - - case Op::Ret: return regs[ins.a]; - } - } - - // unreachable normally - return 0; - } - }; -}; // namespace Fig::IR \ No newline at end of file diff --git a/src/IR/ir_test_main.cpp b/src/IR/ir_test_main.cpp deleted file mode 100644 index b1ab6c2..0000000 --- a/src/IR/ir_test_main.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - - -int main() -{ - using namespace Fig; - IR::VirtualMachine vm; - - using namespace IR; - IR::Inst fib_ir[] = { - - }; -} \ No newline at end of file diff --git a/src/VirtualMachine/VirtualMachine.cpp b/src/__VirtualMachine/VirtualMachine.cpp similarity index 100% rename from src/VirtualMachine/VirtualMachine.cpp rename to src/__VirtualMachine/VirtualMachine.cpp diff --git a/src/VirtualMachine/VirtualMachine.hpp b/src/__VirtualMachine/VirtualMachine.hpp similarity index 100% rename from src/VirtualMachine/VirtualMachine.hpp rename to src/__VirtualMachine/VirtualMachine.hpp diff --git a/xmake.lua b/xmake.lua index f7db62d..53c05d6 100644 --- a/xmake.lua +++ b/xmake.lua @@ -42,27 +42,25 @@ target("Fig") set_kind("binary") add_files("src/Evaluator/Core/*.cpp") - add_files("src/VirtualMachine/VirtualMachine.cpp") add_files("src/Evaluator/evaluator.cpp") add_files("src/Repl/Repl.cpp") add_files("src/main.cpp") set_warnings("all") -target("vm_test_main") - set_kind("binary") +-- target("vm_test_main") +-- set_kind("binary") - add_files("src/VirtualMachine/VirtualMachine.cpp") - add_files("src/Bytecode/vm_test_main.cpp") +-- add_files("src/Bytecode/vm_test_main.cpp") - set_warnings("all") +-- set_warnings("all") -target("ir_test_main") - set_kind("binary") +-- target("ir_test_main") +-- set_kind("binary") - add_files("src/IR/ir_test_main.cpp") +-- add_files("src/IR/ir_test_main.cpp") - set_warnings("all") +-- set_warnings("all") target("StringTest") set_kind("binary")