diff --git a/code/compiler/12/definition.hpp b/code/compiler/12/definition.hpp index c14ec0f..d70d539 100644 --- a/code/compiler/12/definition.hpp +++ b/code/compiler/12/definition.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #include "instruction.hpp" #include "llvm_context.hpp" @@ -70,3 +71,8 @@ struct definition_data { }; using definition_data_ptr = std::unique_ptr; + +struct definition_group { + std::map defs_data; + std::map defs_defn; +}; diff --git a/code/compiler/12/main.cpp b/code/compiler/12/main.cpp index 45a3e8b..6495d92 100644 --- a/code/compiler/12/main.cpp +++ b/code/compiler/12/main.cpp @@ -21,8 +21,7 @@ void yy::parser::error(const std::string& msg) { std::cout << "An error occured: " << msg << std::endl; } -extern std::map defs_data; -extern std::map defs_defn; +extern definition_group global_defs; void typecheck_program( const std::map& defs_data, @@ -180,7 +179,7 @@ int main() { type_env_ptr env(new type_env); parser.parse(); - for(auto& def_defn : defs_defn) { + for(auto& def_defn : global_defs.defs_defn) { std::cout << def_defn.second->name; for(auto& param : def_defn.second->params) std::cout << " " << param; std::cout << ":" << std::endl; @@ -188,9 +187,9 @@ int main() { def_defn.second->body->print(1, std::cout); } try { - typecheck_program(defs_data, defs_defn, mgr, env); - compile_program(defs_defn); - gen_llvm(defs_data, defs_defn); + typecheck_program(global_defs.defs_data, global_defs.defs_defn, mgr, env); + compile_program(global_defs.defs_defn); + gen_llvm(global_defs.defs_data, global_defs.defs_defn); } catch(unification_error& err) { std::cout << "failed to unify types: " << std::endl; std::cout << " (1) \033[34m"; diff --git a/code/compiler/12/parser.y b/code/compiler/12/parser.y index 686e79e..5256fae 100644 --- a/code/compiler/12/parser.y +++ b/code/compiler/12/parser.y @@ -7,8 +7,7 @@ #include "parser.hpp" #include "parsed_type.hpp" -std::map defs_data; -std::map defs_defn; +definition_group global_defs; extern yy::parser::symbol_type yylex(); @@ -63,8 +62,8 @@ definitions ; definition - : defn { auto name = $1->name; defs_defn[name] = std::move($1); } - | data { auto name = $1->name; defs_data[name] = std::move($1); } + : defn { auto name = $1->name; global_defs.defs_defn[name] = std::move($1); } + | data { auto name = $1->name; global_defs.defs_data[name] = std::move($1); } ; defn