diff --git a/asm/asm.r8asm b/asm/asm.r8asm index dc7ab11..247b724 100644 --- a/asm/asm.r8asm +++ b/asm/asm.r8asm @@ -1,12 +1,10 @@ -%macro test_erase 1 -.tp %1 -.loop _UNIT_MAX -biz -flb -rnz -ror -.endloop -%endmacro - -.xor 15 -test_erase $ \ No newline at end of file +inp +.anchor arg1 +step +inp +.anchor arg2 +step +.anchor ans +and arg1 arg2 ans +.tp ans +out \ No newline at end of file diff --git a/asm/lib.r8asm b/asm/lib.r8asm new file mode 100644 index 0000000..82483a4 --- /dev/null +++ b/asm/lib.r8asm @@ -0,0 +1,38 @@ +%macro step 1 +stp %1 +stp %1 +%endmacro + +%macro back 1 +btp %1 +btp %1 +%endmacro + +%macro and 3 + .anchor before_and + .tp %1 + + stp + xor _UNIT_MAX + btp + + .loop + biz + .tp %2 + biz + .tp %3 + flb + biz + flb + rnz + ror + rnz + .tp %2 + ror + rnz + .tp %1 + ror + .endloop + + .tp before_and +%endmacro diff --git a/src/r8asm_macro.cc b/src/r8asm_macro.cc index a89b24e..308473a 100644 --- a/src/r8asm_macro.cc +++ b/src/r8asm_macro.cc @@ -2,15 +2,7 @@ #include #include -std::map r8asm_macromap = { - {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")}}}}}; +std::map r8asm_macromap; R8Operand read_arg(std::vector &actual_args, R8Operand formal_para, argc_type argc) { diff --git a/src/r8asm_parse.cc b/src/r8asm_parse.cc index f95a257..2b6dbad 100644 --- a/src/r8asm_parse.cc +++ b/src/r8asm_parse.cc @@ -106,11 +106,11 @@ r8asm_translate_single_ins(std::vector const raw_ins) { } void R8Src::preprocess() { - std::vector codeblock; + std::vector tmp_codeblock; while (!this->codeblocks.empty()) { auto i = this->codeblocks.top(); this->codeblocks.pop(); - codeblock.clear(); + tmp_codeblock.clear(); auto raw_codeblock = std::ranges::subrange(std::next(i.first), i.second); /* @@ -119,12 +119,12 @@ void R8Src::preprocess() { subrange:--------------------4 5 6--------------- */ for (auto j : raw_codeblock) - codeblock.push_back(r8asm_translate_single_ins(j)); + tmp_codeblock.push_back(r8asm_translate_single_ins(j)); if ((*i.first)[0] == "%macro") { r8asm_macromap.insert_or_assign( (*i.first)[1], R8Macro{(argc_type)std::get( r8asm_arg_stoi((*i.first)[2])), - codeblock}); + tmp_codeblock}); } else if ((*i.first)[0] == "%repeat") { for (auto count = std::get(r8asm_arg_stoi((*i.first)[1])); diff --git a/tests/r8_test.cc b/tests/r8_test.cc index 6755924..6a7bcaa 100644 --- a/tests/r8_test.cc +++ b/tests/r8_test.cc @@ -1,9 +1,16 @@ #include #include "r8asm/r8asm.hh" +#include "r8asm/r8asm_parse.hh" int main(int argc, char *argv[]) { - auto src = read_src(argc > 1 ? argv[1] : "asm/asm.r8asm"); + auto lib = read_src("/home/admin/Git/R8ASM/asm/lib.r8asm"); + /* + for (auto i : lib.raw_src) + for (auto j : i) + std::cout << j << ';';*/ + lib.preprocess(); + auto src = read_src("asm/asm.r8asm"); auto out_tape = r8asm_tape_out(expand_macros(r8asm_preprocess(src))); for (auto i : out_tape) std::cout << ROT8_BC_TO_CHAR(i);