202608271413

This commit is contained in:
starcells committed 2026-08-27 14:14:01 +08:00
1 parent f65b46a91a
commit 7a55472569
2 files changed
+58 -3

No files matched your search

+4 -1
View File
@@ -20,6 +20,9 @@ private:
STRING,
OPERATOR,
MACROCALL,
ROT8,
PREFIX_DIRECTIVE,
PREFIX_PARAMETER,
PREFIX_BUILTIN,
@@ -128,7 +131,7 @@ private:
public:
ast_node expand_node_to_ins(const ast_node &node);
std::string expand_root();
bool import_macro(const std::string &macro_name,const ast_node &node);
bool import_macro(const std::string &macro_name, const ast_node &node);
};
ast main_tree;
+54 -2
View File
@@ -289,6 +289,7 @@ r8asm::ast_node r8asm::parse(const token_stream &stream) {
0 1 2
*/
switch (directive_keywords.at(it->tokens[1].value)) {
// match an entire operation (not a cut for arguments) first
case directive_t::MACRO: {
std::string macro_name = it->tokens[2].value;
@@ -332,7 +333,7 @@ r8asm::ast_node r8asm::parse(const token_stream &stream) {
if (POINTS_AT(it, REP))
layer++;
else if (POINTS_AT(it, ENDREP))
layer++;
layer--;
tmp_codeblock_stream.lines.push_back(*it);
}
// now it points at %endrep line
@@ -359,7 +360,58 @@ r8asm::ast_node r8asm::parse(const token_stream &stream) {
break;
}
} break;
default:
case token_t::PREFIX_BUILTIN: {
/* like this:
. var pos1 15
0 1 2 3
*/
to_return.children.push_back(
{r8asm::ast_node_t::BUILTIN, it->tokens[1].value, {}});
// build subtree for argument(s) of builtin
token_line buffer = {it->number, {}};
for (auto token_it = it->tokens.begin() + 2; // where argument begins
token_it < it->tokens.end(); token_it++)
buffer.tokens.push_back(*token_it);
tmp_codeblock_stream.lines = {buffer};
/*
REPEAT
children[0]: count
children[1]: codeblock
*/
auto args = parse(tmp_codeblock_stream).children;
for (const auto &arg_it : args)
to_return.children.back().children.push_back(arg_it);
} break;
case token_t::MACROCALL: {
/* like this:
raw_add 2 4 4 + 2 ( 4 + 4 ) pos1 pos1 + 2
0 1 ...
*/
to_return.children.push_back(
{r8asm::ast_node_t::MACROCALL, it->tokens[0].value, {}});
// build subtree for argument(s) of macro
token_line buffer = {it->number, {}};
for (auto token_it = it->tokens.begin() + 1; // where argument begins
token_it < it->tokens.end(); token_it++)
buffer.tokens.push_back(*token_it);
tmp_codeblock_stream.lines = {buffer};
/*
REPEAT
children[0]: count
children[1]: codeblock
*/
auto args = parse(tmp_codeblock_stream).children;
for (const auto &arg_it : args)
to_return.children.back().children.push_back(arg_it);
} break;
case token_t::ROT8: {
to_return.children.push_back(
{r8asm::ast_node_t::ROT8, it->tokens[0].value, {}});
} break;
case token_t::PREFIX_REMARK:
// ignore it.
break;
default: // Now it's surely a line of one argument or arguments.
break;
}
}