202608251836
This commit is contained in:
1 parent
4145ce3989
commit
0c6b494f22
2 files changed
+20
-8
No files matched your search
@@ -24,6 +24,7 @@ public:
|
||||
BUILTIN,
|
||||
MACROCALL,
|
||||
ROT8,
|
||||
CODEBLOCK,
|
||||
};
|
||||
struct ast_node {
|
||||
ast_node_t type;
|
||||
@@ -33,10 +34,10 @@ public:
|
||||
class ast {
|
||||
private:
|
||||
public:
|
||||
ast_node root;
|
||||
ast_node root = {r8asm::ast_node_t::CODEBLOCK, "", {}};
|
||||
addr dataptr = 0;
|
||||
std::vector<std::map<std::string, general_data>> scopes;
|
||||
std::map<std::string, std::vector<ast_node>> macro_bodies;
|
||||
std::vector<std::map<std::string, general_data>> scopes = {{}};
|
||||
std::map<std::string, ast_node> macros;
|
||||
|
||||
general_data expand_node_to_data(const ast_node &node);
|
||||
std::vector<ast_node> expand_node_to_ins(const ast_node &node);
|
||||
|
||||
+16
-5
@@ -66,7 +66,7 @@ r8asm::general_data r8asm::ast::expand_node_to_data(const ast_node &node) {
|
||||
|
||||
r8asm::general_data r8asm::ast::read_parameter(std::string index_str) {
|
||||
parameter_index i = std::stoi(index_str);
|
||||
return scopes.back()['%' + index_str];
|
||||
return scopes.back().at('%' + index_str);
|
||||
}
|
||||
|
||||
// TODO: FILL THE BLANK
|
||||
@@ -91,18 +91,29 @@ r8asm::ast::expand_node_to_ins(const ast_node &node) {
|
||||
value: macro_name
|
||||
children: arguments
|
||||
*/
|
||||
|
||||
std::map<std::string, general_data> tmp_scope = {};
|
||||
for (auto i = 0; i < node.children.size(); i++)
|
||||
tmp_scope.insert_or_assign('%' + std::to_string(i + 1),
|
||||
// %1 in macro means children[0]
|
||||
expand_node_to_data(node.children[i]));
|
||||
scopes.push_back(tmp_scope);
|
||||
// %1 in macro means children[0]
|
||||
for (auto body : macro_bodies.at(node.value))
|
||||
for (auto it : expand_node_to_ins(body))
|
||||
to_return.push_back(it);
|
||||
for (const auto &it : expand_node_to_ins(macros.at(node.value)))
|
||||
to_return.push_back(it);
|
||||
scopes.pop_back();
|
||||
|
||||
} break;
|
||||
|
||||
case ast_node_t::CODEBLOCK: {
|
||||
/*
|
||||
CODEBLOCK
|
||||
children: ins
|
||||
*/
|
||||
for (const auto &child : node.children)
|
||||
for (const auto &ins : expand_node_to_ins(child))
|
||||
to_return.push_back(ins);
|
||||
} break;
|
||||
|
||||
case ast_node_t::BUILTIN: {
|
||||
switch (builtin_map.at(node.value)) {
|
||||
case builtin_t::ANCHOR: {
|
||||
|
||||
Reference in new issue
Block a user