[tmp]202605071335
This commit is contained in:
1 parent
8390a0253e
commit
169bb3a756
3 files changed
+42
-11
No files matched your search
@@ -1,17 +1,25 @@
|
||||
#ifndef R8ASM_PARSE
|
||||
#define R8ASM_PARSE
|
||||
|
||||
#include "r8asm/r8asm_core.hh"
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#define EMPTY_CHARS (" \t\n\r\f\v")
|
||||
|
||||
typedef size_t ins_type_sign;
|
||||
|
||||
struct r8asm_src {
|
||||
std::vector<std::vector<std::string>> raw_src;
|
||||
std::vector<std::pair<ins_type_sign, ins_type_sign>> codeblocks;
|
||||
};
|
||||
|
||||
r8asm_src read_src(std::string filename);
|
||||
|
||||
void include_src(r8asm_src);
|
||||
|
||||
std::vector<R8Instruction> r8asm_preprocess(r8asm_src &src);
|
||||
|
||||
#endif
|
||||
+9
-7
@@ -28,6 +28,7 @@ R8Operand read_arg(std::vector<R8Operand> &argv, R8Operand argf,
|
||||
std::vector<R8Instruction> expand_single_macro(std::string macro_name,
|
||||
std::vector<R8Operand> argv) {
|
||||
std::vector<R8Instruction> tmp_tape;
|
||||
std::vector<R8Operand> macro_args;
|
||||
|
||||
for (auto i : macros[macro_name].ins) {
|
||||
if (std::get_if<rot8_bytecode>(&i.op) ||
|
||||
@@ -35,7 +36,7 @@ std::vector<R8Instruction> expand_single_macro(std::string macro_name,
|
||||
tmp_tape.push_back(
|
||||
{i.op, read_arg(argv, i.arg, macros[macro_name].argc)});
|
||||
else if (r8asm_macro *macro = std::get_if<r8asm_macro>(&i.op)) {
|
||||
std::vector<R8Operand> macro_args;
|
||||
macro_args.clear();
|
||||
for (auto j : macro->args)
|
||||
macro_args.push_back(
|
||||
read_arg(argv, j, macros[macro_name].argc));
|
||||
@@ -50,14 +51,15 @@ std::vector<R8Instruction> expand_single_macro(std::string macro_name,
|
||||
}
|
||||
|
||||
std::vector<R8Instruction> expand_macros(std::vector<R8Instruction> &ins) {
|
||||
std::vector<R8Instruction> out_tape;
|
||||
std::vector<R8Instruction> tape;
|
||||
std::vector<R8Instruction> tmp_tape;
|
||||
for (auto i : ins) {
|
||||
tmp_tape.clear();
|
||||
if (r8asm_macro *macro = std::get_if<r8asm_macro>(&i.op)) {
|
||||
std::vector<R8Instruction> tmp_tape =
|
||||
(expand_single_macro(macro->name, macro->args));
|
||||
out_tape.insert(out_tape.end(), tmp_tape.begin(), tmp_tape.end());
|
||||
tmp_tape = (expand_single_macro(macro->name, macro->args));
|
||||
tape.insert(tape.end(), tmp_tape.begin(), tmp_tape.end());
|
||||
} else
|
||||
out_tape.push_back(i);
|
||||
tape.push_back(i);
|
||||
}
|
||||
return (out_tape);
|
||||
return (tape);
|
||||
}
|
||||
+25
-4
@@ -1,6 +1,10 @@
|
||||
#include "r8asm/r8asm_parse.hh"
|
||||
#include "r8asm/r8asm_core.hh"
|
||||
#include <fstream>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
void r8asm_trim(std::string &str) {
|
||||
auto start = str.find_first_not_of(EMPTY_CHARS);
|
||||
@@ -30,20 +34,37 @@ std::string r8asm_peel(std::string &str) {
|
||||
}
|
||||
|
||||
r8asm_src read_src(std::string filename) {
|
||||
r8asm_src out_src;
|
||||
r8asm_src src;
|
||||
|
||||
ins_type_sign line_counter = 0;
|
||||
std::ifstream ifile;
|
||||
std::string line_buffer;
|
||||
ifile.open(filename, std::ios::in);
|
||||
std::vector<std::string> ins_buffer;
|
||||
std::stack<ins_type_sign> matcher;
|
||||
while (std::getline(ifile, line_buffer)) {
|
||||
ins_buffer.clear();
|
||||
auto comment = line_buffer.find_first_of(';');
|
||||
if (comment != std::string::npos)
|
||||
line_buffer = line_buffer.substr(0, comment);
|
||||
std::vector<std::string> ins_buffer;
|
||||
if (line_buffer.empty())
|
||||
continue;
|
||||
line_counter++;
|
||||
while (!line_buffer.empty())
|
||||
ins_buffer.push_back(r8asm_peel(line_buffer));
|
||||
out_src.raw_src.push_back(ins_buffer);
|
||||
src.raw_src.push_back({ins_buffer});
|
||||
if (ins_buffer[0][0] == '%') {
|
||||
if (ins_buffer[0].substr(1, 3) == "end") {
|
||||
src.codeblocks.push_back({matcher.top(), line_counter});
|
||||
matcher.pop();
|
||||
} else
|
||||
matcher.push(line_counter);
|
||||
}
|
||||
}
|
||||
ifile.close();
|
||||
return (out_src);
|
||||
return (src);
|
||||
}
|
||||
|
||||
std::vector<R8Instruction> r8asm_preprocess(r8asm_src &src) {
|
||||
std::vector<R8Instruction> ins;
|
||||
}
|
||||
Reference in new issue
Block a user