#pragma once #include #include #include #include #include "instruction.hpp" #include "llvm_context.hpp" #include "parsed_type.hpp" #include "type_env.hpp" #include "location.hh" #include "global_scope.hpp" struct ast; using ast_ptr = std::unique_ptr; struct constructor { std::string name; std::vector types; int8_t tag; constructor(std::string n, std::vector ts) : name(std::move(n)), types(std::move(ts)) {} }; using constructor_ptr = std::unique_ptr; struct definition_defn { std::string name; std::vector params; ast_ptr body; yy::location loc; type_env_ptr env; type_env_ptr var_env; std::set free_variables; std::set nearby_variables; type_ptr full_type; type_ptr return_type; definition_defn( std::string n, std::vector p, ast_ptr b, yy::location l = yy::location()) : name(std::move(n)), params(std::move(p)), body(std::move(b)), loc(std::move(l)) { } void find_free(); void insert_types(type_mgr& mgr, type_env_ptr& env, visibility v); void typecheck(type_mgr& mgr); global_function& into_global(global_scope& scope); }; using definition_defn_ptr = std::unique_ptr; struct definition_data { std::string name; std::vector vars; std::vector constructors; yy::location loc; type_env_ptr env; definition_data( std::string n, std::vector vs, std::vector cs, yy::location l = yy::location()) : name(std::move(n)), vars(std::move(vs)), constructors(std::move(cs)), loc(std::move(l)) {} void insert_types(type_env_ptr& env); void insert_constructors() const; void into_globals(global_scope& scope); }; using definition_data_ptr = std::unique_ptr; struct definition_group { std::map defs_data; std::map defs_defn; visibility vis; type_env_ptr env; definition_group(visibility v = visibility::local) : vis(v) {} void find_free(std::set& into); void typecheck(type_mgr& mgr, type_env_ptr& env); };