[tmp]202604252142
This commit is contained in:
1 parent
4d842917c2
commit
b717e89992
4 files changed
+34
-24
No files matched your search
@@ -37,7 +37,8 @@ enum class r8asm_builtin {
|
||||
ENDMACRO,
|
||||
};
|
||||
|
||||
using R8Operand = std::variant<std::monostate, r8asm_data, std::string, std::vector<std::string>>;
|
||||
using R8Operand = std::variant<std::monostate, r8asm_data, std::string,
|
||||
std::vector<std::string>>;
|
||||
|
||||
struct r8asm_macro {
|
||||
std::string name;
|
||||
@@ -49,10 +50,6 @@ using R8MetaOp = std::variant<r8asm_builtin, r8asm_macro, rot8_bytecode>;
|
||||
struct R8Instruction {
|
||||
R8MetaOp op;
|
||||
R8Operand arg;
|
||||
R8Instruction(R8MetaOp in_op, R8Operand in_arg = std::monostate {})
|
||||
: op(in_op)
|
||||
, arg(in_arg) {
|
||||
};
|
||||
};
|
||||
|
||||
extern std::map<std::string, r8asm_label> labels;
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
#define R8ASM_MACRO
|
||||
|
||||
#include "r8asm/r8asm_core.hh"
|
||||
#include <vector>
|
||||
struct R8Macro {
|
||||
argc_type argc;
|
||||
argc_type argc = 0;
|
||||
std::vector<R8Instruction> ins;
|
||||
};
|
||||
extern std::map<std::string, R8Macro> macros;
|
||||
|
||||
std::vector<R8Instruction> expand_macro(std::string macro_name, std::vector<R8Operand> argv);
|
||||
std::vector<R8Instruction> expand_single_macro(std::string macro_name,
|
||||
std::vector<R8Operand> argv);
|
||||
|
||||
std::vector<R8Instruction> expand_macros(std::vector<R8Instruction> &ins);
|
||||
|
||||
#endif
|
||||
+17
-4
@@ -1,7 +1,16 @@
|
||||
#include "r8asm/r8asm_macro.hh"
|
||||
#include "r8asm/r8asm_core.hh"
|
||||
#include <vector>
|
||||
|
||||
std::map<std::string, R8Macro> macros;
|
||||
std::map<std::string, R8Macro> 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<R8Operand> &argv, R8Operand argf,
|
||||
argc_type argc) {
|
||||
@@ -15,8 +24,8 @@ R8Operand read_arg(std::vector<R8Operand> &argv, R8Operand argf,
|
||||
return (argf);
|
||||
}
|
||||
|
||||
std::vector<R8Instruction> expand_macro(std::string macro_name,
|
||||
std::vector<R8Operand> argv) {
|
||||
std::vector<R8Instruction> expand_single_macro(std::string macro_name,
|
||||
std::vector<R8Operand> argv) {
|
||||
std::vector<R8Instruction> tmp_tape;
|
||||
|
||||
for (auto i : macros[macro_name].ins) {
|
||||
@@ -30,11 +39,15 @@ std::vector<R8Instruction> expand_macro(std::string macro_name,
|
||||
macro_args.push_back(
|
||||
read_arg(argv, j, macros[macro_name].argc));
|
||||
std::vector<R8Instruction> 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<R8Instruction> expand_macros(std::vector<R8Instruction> &ins) {
|
||||
std::vector<R8Instruction> out_tape;
|
||||
}
|
||||
+9
-13
@@ -2,22 +2,18 @@
|
||||
|
||||
#include "r8asm/r8asm.hh"
|
||||
#include "r8asm/r8asm_core.hh"
|
||||
#include "r8asm/r8asm_macro.hh"
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
std::vector<R8Instruction> 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<rot8_bytecode> 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);
|
||||
}
|
||||
Reference in new issue
Block a user