Add typechecking to let/in expressions.
This commit is contained in:
parent
35928b3a54
commit
63f82a1c64
26
12/ast.cpp
26
12/ast.cpp
|
@ -226,6 +226,32 @@ void ast_case::compile(const env_ptr& env, std::vector<instruction_ptr>& into) c
|
|||
}
|
||||
}
|
||||
|
||||
void ast_let::print(int indent, std::ostream& to) const {
|
||||
print_indent(indent, to);
|
||||
to << "LET: " << std::endl;
|
||||
in->print(indent + 1, to);
|
||||
}
|
||||
|
||||
void ast_let::find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& into) {
|
||||
this->env = env;
|
||||
definitions.find_free(mgr, env, into);
|
||||
std::set<std::string> all_free;
|
||||
in->find_free(mgr, definitions.env, all_free);
|
||||
for(auto& free_var : all_free) {
|
||||
if(definitions.defs_defn.find(free_var) == definitions.defs_defn.end())
|
||||
into.insert(free_var);
|
||||
}
|
||||
}
|
||||
|
||||
type_ptr ast_let::typecheck(type_mgr& mgr) {
|
||||
definitions.typecheck(mgr);
|
||||
return in->typecheck(mgr);
|
||||
}
|
||||
|
||||
void ast_let::compile(const env_ptr& env, std::vector<instruction_ptr>& into) const {
|
||||
throw 0;
|
||||
}
|
||||
|
||||
void pattern_var::print(std::ostream& to) const {
|
||||
to << var;
|
||||
}
|
||||
|
|
14
12/ast.hpp
14
12/ast.hpp
|
@ -7,6 +7,7 @@
|
|||
#include "binop.hpp"
|
||||
#include "instruction.hpp"
|
||||
#include "env.hpp"
|
||||
#include "definition.hpp"
|
||||
|
||||
struct ast {
|
||||
type_env_ptr env;
|
||||
|
@ -120,6 +121,19 @@ struct ast_case : public ast {
|
|||
void compile(const env_ptr& env, std::vector<instruction_ptr>& into) const;
|
||||
};
|
||||
|
||||
struct ast_let : public ast {
|
||||
definition_group definitions;
|
||||
ast_ptr in;
|
||||
|
||||
ast_let(ast_ptr i, definition_group g)
|
||||
: in(std::move(i)), definitions(std::move(g)) {}
|
||||
|
||||
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 compile(const env_ptr& env, std::vector<instruction_ptr>& into) const;
|
||||
};
|
||||
|
||||
struct pattern_var : public pattern {
|
||||
std::string var;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user