From 16cabba2ee64cf7e71ea42d0715601cb9f1e11bb Mon Sep 17 00:00:00 2001 From: StarCells Date: Wed, 26 Aug 2026 23:07:57 +0800 Subject: [PATCH] added an export for r8asm --- include/r8asm/r8asm.hh | 53 +++++++++++++++++++++++++++++++----------- src/r8asm.cc | 14 ++++++++++- 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/include/r8asm/r8asm.hh b/include/r8asm/r8asm.hh index 553c6d1..556b22e 100644 --- a/include/r8asm/r8asm.hh +++ b/include/r8asm/r8asm.hh @@ -15,7 +15,40 @@ class r8asm { using general_data = int32_t; private: -public: + enum class directive_t { + MACRO, + ENDMACRO, + REP, + ENDREP, + INCLUDE, + }; + std::map directive_map = { + {"dir_macro", r8asm::directive_t::MACRO}, + {"dir_endmacro", r8asm::directive_t::ENDMACRO}, + {"dir_rep", r8asm::directive_t::REP}, + {"dir_endrep", r8asm::directive_t::ENDREP}, + {"dir_include", r8asm::directive_t::INCLUDE}}; + enum class token_t { + STRING, + OPERATOR, + + PREFIX_DIRECTIVE, + PREFIX_PARAMETER, + PREFIX_BUILTIN, + PREFIX_REMARK, + + LPAREN, + RPAREN, + LQUOTE, + RQUOTE, + + ENDL, + ENDF, + }; + struct token { + token_t type; + std::string value; + }; enum class ast_node_t { CONSTANT, PARAMETER, @@ -94,18 +127,10 @@ public: public: ast_node expand_node_to_ins(const ast_node &node); + std::string expand_root(); }; - enum class directive_t { - MACRO, - ENDMACRO, - REP, - ENDREP, - INCLUDE, - }; - std::map directive_map = { - {"dir_macro", r8asm::directive_t::MACRO}, - {"dir_endmacro", r8asm::directive_t::ENDMACRO}, - {"dir_rep", r8asm::directive_t::REP}, - {"dir_endrep", r8asm::directive_t::ENDREP}, - {"dir_include", r8asm::directive_t::INCLUDE}}; + + ast main_tree; +public: + std::string export_rot8(); }; \ No newline at end of file diff --git a/src/r8asm.cc b/src/r8asm.cc index 4713c53..e4fd05a 100644 --- a/src/r8asm.cc +++ b/src/r8asm.cc @@ -230,4 +230,16 @@ r8asm::ast_node r8asm::ast::expand_node_to_ins(const ast_node &node) { } return to_return; } -#undef ROT8_NODE \ No newline at end of file +#undef ROT8_NODE + +#define ROT8_BC_TO_CHAR(bc) ("><+-[].,"[static_cast(bc)]) +std::string r8asm::ast::expand_root() { + auto rot8_ins = expand_node_to_ins(root); + std::string rot8_tape = ""; + for (const auto &i : rot8_ins.children) + rot8_tape += ROT8_BC_TO_CHAR(rot8_map.at(i.value)); + return rot8_tape; +} +#undef ROT8_BC_TO_CHAR + +std::string r8asm::export_rot8() { return main_tree.expand_root(); } \ No newline at end of file