2020-05-25 21:20:41 -07:00
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2020-05-25 22:11:45 -07:00
|
|
|
#include <map>
|
2020-05-25 21:20:41 -07:00
|
|
|
#include <set>
|
|
|
|
#include "instruction.hpp"
|
|
|
|
#include "llvm_context.hpp"
|
|
|
|
#include "parsed_type.hpp"
|
|
|
|
#include "type_env.hpp"
|
2020-05-31 18:52:52 -07:00
|
|
|
#include "global_scope.hpp"
|
2020-05-25 21:20:41 -07:00
|
|
|
|
|
|
|
struct ast;
|
|
|
|
using ast_ptr = std::unique_ptr<ast>;
|
|
|
|
|
|
|
|
struct constructor {
|
|
|
|
std::string name;
|
|
|
|
std::vector<parsed_type_ptr> types;
|
|
|
|
int8_t tag;
|
|
|
|
|
|
|
|
constructor(std::string n, std::vector<parsed_type_ptr> ts)
|
|
|
|
: name(std::move(n)), types(std::move(ts)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
using constructor_ptr = std::unique_ptr<constructor>;
|
|
|
|
|
|
|
|
struct definition_defn {
|
|
|
|
std::string name;
|
|
|
|
std::vector<std::string> params;
|
|
|
|
ast_ptr body;
|
|
|
|
|
|
|
|
type_env_ptr env;
|
|
|
|
type_env_ptr var_env;
|
|
|
|
std::set<std::string> free_variables;
|
2020-05-30 23:29:36 -07:00
|
|
|
std::set<std::string> nearby_variables;
|
2020-05-25 21:20:41 -07:00
|
|
|
type_ptr full_type;
|
|
|
|
type_ptr return_type;
|
|
|
|
|
|
|
|
definition_defn(std::string n, std::vector<std::string> p, ast_ptr b)
|
|
|
|
: name(std::move(n)), params(std::move(p)), body(std::move(b)) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-01 00:23:41 -07:00
|
|
|
void find_free();
|
|
|
|
void insert_types(type_mgr& mgr, type_env_ptr& env, visibility v);
|
2020-05-25 21:20:41 -07:00
|
|
|
void typecheck(type_mgr& mgr);
|
2020-05-31 18:52:52 -07:00
|
|
|
|
2020-06-01 00:23:41 -07:00
|
|
|
global_function& into_global(global_scope& scope);
|
2020-05-25 21:20:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
using definition_defn_ptr = std::unique_ptr<definition_defn>;
|
|
|
|
|
|
|
|
struct definition_data {
|
|
|
|
std::string name;
|
|
|
|
std::vector<std::string> vars;
|
|
|
|
std::vector<constructor_ptr> constructors;
|
|
|
|
|
|
|
|
type_env_ptr env;
|
|
|
|
|
|
|
|
definition_data(
|
|
|
|
std::string n,
|
|
|
|
std::vector<std::string> vs,
|
|
|
|
std::vector<constructor_ptr> cs)
|
|
|
|
: name(std::move(n)), vars(std::move(vs)), constructors(std::move(cs)) {}
|
|
|
|
|
|
|
|
void insert_types(type_env_ptr& env);
|
|
|
|
void insert_constructors() const;
|
2020-06-01 00:23:41 -07:00
|
|
|
|
|
|
|
void into_globals(global_scope& scope);
|
2020-05-25 21:20:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
using definition_data_ptr = std::unique_ptr<definition_data>;
|
2020-05-25 22:11:45 -07:00
|
|
|
|
|
|
|
struct definition_group {
|
|
|
|
std::map<std::string, definition_data_ptr> defs_data;
|
|
|
|
std::map<std::string, definition_defn_ptr> defs_defn;
|
2020-05-31 00:34:12 -07:00
|
|
|
visibility vis;
|
2020-05-25 23:58:56 -07:00
|
|
|
type_env_ptr env;
|
|
|
|
|
2020-05-31 00:34:12 -07:00
|
|
|
definition_group(visibility v = visibility::local) : vis(v) {}
|
|
|
|
|
2020-06-01 00:23:41 -07:00
|
|
|
void find_free(std::set<std::string>& into);
|
|
|
|
void typecheck(type_mgr& mgr, type_env_ptr& env);
|
2020-05-25 22:11:45 -07:00
|
|
|
};
|