From b717e89992a9730a2d8dadf30376a0b63c3d0732 Mon Sep 17 00:00:00 2001 From: starcells Date: Sat, 25 Apr 2026 21:42:52 +0800 Subject: [PATCH] [tmp]202604252142 --- include/r8asm/r8asm_core.hh | 7 ++----- include/r8asm/r8asm_macro.hh | 8 ++++++-- src/r8asm_macro.cc | 21 +++++++++++++++++---- tests/r8_test.cc | 22 +++++++++------------- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/include/r8asm/r8asm_core.hh b/include/r8asm/r8asm_core.hh index a5ddf9c..f6775d5 100644 --- a/include/r8asm/r8asm_core.hh +++ b/include/r8asm/r8asm_core.hh @@ -37,7 +37,8 @@ enum class r8asm_builtin { ENDMACRO, }; -using R8Operand = std::variant>; +using R8Operand = std::variant>; struct r8asm_macro { std::string name; @@ -49,10 +50,6 @@ using R8MetaOp = std::variant; struct R8Instruction { R8MetaOp op; R8Operand arg; - R8Instruction(R8MetaOp in_op, R8Operand in_arg = std::monostate {}) - : op(in_op) - , arg(in_arg) { - }; }; extern std::map labels; diff --git a/include/r8asm/r8asm_macro.hh b/include/r8asm/r8asm_macro.hh index 3b4b06f..83e1ef1 100644 --- a/include/r8asm/r8asm_macro.hh +++ b/include/r8asm/r8asm_macro.hh @@ -2,12 +2,16 @@ #define R8ASM_MACRO #include "r8asm/r8asm_core.hh" +#include struct R8Macro { - argc_type argc; + argc_type argc = 0; std::vector ins; }; extern std::map macros; -std::vector expand_macro(std::string macro_name, std::vector argv); +std::vector expand_single_macro(std::string macro_name, + std::vector argv); + +std::vector expand_macros(std::vector &ins); #endif \ No newline at end of file diff --git a/src/r8asm_macro.cc b/src/r8asm_macro.cc index b177ea0..637b7f9 100644 --- a/src/r8asm_macro.cc +++ b/src/r8asm_macro.cc @@ -1,7 +1,16 @@ #include "r8asm/r8asm_macro.hh" #include "r8asm/r8asm_core.hh" +#include -std::map macros; +std::map macros = { + {std::string("STEP"), + {1, + {{rot8_bytecode::STP, std::string("%1")}, + {rot8_bytecode::STP, std::string("%1")}}}}, + {std::string("BACK"), + {1, + {{rot8_bytecode::BTP, std::string("%1")}, + {rot8_bytecode::BTP, std::string("%1")}}}}}; R8Operand read_arg(std::vector &argv, R8Operand argf, argc_type argc) { @@ -15,8 +24,8 @@ R8Operand read_arg(std::vector &argv, R8Operand argf, return (argf); } -std::vector expand_macro(std::string macro_name, - std::vector argv) { +std::vector expand_single_macro(std::string macro_name, + std::vector argv) { std::vector tmp_tape; for (auto i : macros[macro_name].ins) { @@ -30,11 +39,15 @@ std::vector expand_macro(std::string macro_name, macro_args.push_back( read_arg(argv, j, macros[macro_name].argc)); std::vector macro_body = - expand_macro(macro->name, macro_args); + expand_single_macro(macro->name, macro_args); tmp_tape.insert(tmp_tape.end(), macro_body.begin(), macro_body.end()); } } return (tmp_tape); +} + +std::vector expand_macros(std::vector &ins) { + std::vector out_tape; } \ No newline at end of file diff --git a/tests/r8_test.cc b/tests/r8_test.cc index eaae839..f15c50f 100644 --- a/tests/r8_test.cc +++ b/tests/r8_test.cc @@ -2,22 +2,18 @@ #include "r8asm/r8asm.hh" #include "r8asm/r8asm_core.hh" +#include "r8asm/r8asm_macro.hh" -int main() -{ +int main() { std::vector ins = { - R8Instruction { rot8_bytecode::INP }, // To make clang-format distribute all - // instructions into diffirent lines. - { r8asm_builtin::LOOP }, - { rot8_bytecode::BIZ }, - { rot8_bytecode::FLB }, - { rot8_bytecode::RNZ }, - { rot8_bytecode::ROR }, - { r8asm_builtin::ENDLOOP }, + R8Instruction{rot8_bytecode::INP}, + // To make clang-format distribute all instructions into diffirent + // lines. + {r8asm_macro("STEP"), {15}}, + {rot8_bytecode::OUT}, }; - std::vector tape = r8asm_tape_out(ins); - for (const auto i : tape) - std::cout << ROT8_BC_TO_CHAR(i); + // for (const auto i : tape) + // std::cout << ROT8_BC_TO_CHAR(i); return (0); }