|
|
|
@ -8,6 +8,7 @@
|
|
|
|
|
#include "instruction.hpp" |
|
|
|
|
#include "env.hpp" |
|
|
|
|
#include "definition.hpp" |
|
|
|
|
#include "global_scope.hpp" |
|
|
|
|
|
|
|
|
|
struct ast { |
|
|
|
|
type_env_ptr env; |
|
|
|
@ -18,6 +19,7 @@ struct ast {
|
|
|
|
|
virtual void find_free(type_mgr& mgr, |
|
|
|
|
type_env_ptr& env, std::set<std::string>& into) = 0; |
|
|
|
|
virtual type_ptr typecheck(type_mgr& mgr) = 0; |
|
|
|
|
virtual void translate(global_scope& scope) = 0; |
|
|
|
|
virtual void compile(const env_ptr& env, |
|
|
|
|
std::vector<instruction_ptr>& into) const = 0; |
|
|
|
|
}; |
|
|
|
@ -53,6 +55,7 @@ struct ast_int : public ast {
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& into); |
|
|
|
|
type_ptr typecheck(type_mgr& mgr); |
|
|
|
|
void translate(global_scope& scope); |
|
|
|
|
void compile(const env_ptr& env, std::vector<instruction_ptr>& into) const; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -65,6 +68,7 @@ struct ast_lid : public ast {
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& into); |
|
|
|
|
type_ptr typecheck(type_mgr& mgr); |
|
|
|
|
void translate(global_scope& scope); |
|
|
|
|
void compile(const env_ptr& env, std::vector<instruction_ptr>& into) const; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -77,6 +81,7 @@ struct ast_uid : public ast {
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& into); |
|
|
|
|
type_ptr typecheck(type_mgr& mgr); |
|
|
|
|
void translate(global_scope& scope); |
|
|
|
|
void compile(const env_ptr& env, std::vector<instruction_ptr>& into) const; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -91,6 +96,7 @@ struct ast_binop : public ast {
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& into); |
|
|
|
|
type_ptr typecheck(type_mgr& mgr); |
|
|
|
|
void translate(global_scope& scope); |
|
|
|
|
void compile(const env_ptr& env, std::vector<instruction_ptr>& into) const; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -104,6 +110,7 @@ struct ast_app : public ast {
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& into); |
|
|
|
|
type_ptr typecheck(type_mgr& mgr); |
|
|
|
|
void translate(global_scope& scope); |
|
|
|
|
void compile(const env_ptr& env, std::vector<instruction_ptr>& into) const; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -118,19 +125,25 @@ struct ast_case : public ast {
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& into); |
|
|
|
|
type_ptr typecheck(type_mgr& mgr); |
|
|
|
|
void translate(global_scope& scope); |
|
|
|
|
void compile(const env_ptr& env, std::vector<instruction_ptr>& into) const; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct ast_let : public ast { |
|
|
|
|
using basic_definition = std::pair<std::string, ast_ptr>; |
|
|
|
|
|
|
|
|
|
definition_group definitions; |
|
|
|
|
ast_ptr in; |
|
|
|
|
|
|
|
|
|
std::vector<basic_definition> translated_definitions; |
|
|
|
|
|
|
|
|
|
ast_let(definition_group g, ast_ptr i) |
|
|
|
|
: definitions(std::move(g)), in(std::move(i)) {} |
|
|
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& into); |
|
|
|
|
type_ptr typecheck(type_mgr& mgr); |
|
|
|
|
void translate(global_scope& scope); |
|
|
|
|
void compile(const env_ptr& env, std::vector<instruction_ptr>& into) const; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|