|
|
|
@ -8,11 +8,14 @@ |
|
|
|
|
#include "instruction.hpp" |
|
|
|
|
#include "env.hpp" |
|
|
|
|
#include "definition.hpp" |
|
|
|
|
#include "location.hh" |
|
|
|
|
#include "global_scope.hpp" |
|
|
|
|
|
|
|
|
|
struct ast { |
|
|
|
|
type_env_ptr env; |
|
|
|
|
yy::location loc; |
|
|
|
|
|
|
|
|
|
ast(yy::location l) : env(nullptr), loc(std::move(l)) {} |
|
|
|
|
virtual ~ast() = default; |
|
|
|
|
|
|
|
|
|
virtual void print(int indent, std::ostream& to) const = 0; |
|
|
|
@ -48,8 +51,8 @@ using branch_ptr = std::unique_ptr<branch>; |
|
|
|
|
struct ast_int : public ast { |
|
|
|
|
int value; |
|
|
|
|
|
|
|
|
|
explicit ast_int(int v) |
|
|
|
|
: value(v) {} |
|
|
|
|
explicit ast_int(int v, yy::location l = yy::location()) |
|
|
|
|
: ast(std::move(l)), value(v) {} |
|
|
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(std::set<std::string>& into); |
|
|
|
@ -61,8 +64,8 @@ struct ast_int : public ast { |
|
|
|
|
struct ast_lid : public ast { |
|
|
|
|
std::string id; |
|
|
|
|
|
|
|
|
|
explicit ast_lid(std::string i) |
|
|
|
|
: id(std::move(i)) {} |
|
|
|
|
explicit ast_lid(std::string i, yy::location l = yy::location()) |
|
|
|
|
: ast(std::move(l)), id(std::move(i)) {} |
|
|
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(std::set<std::string>& into); |
|
|
|
@ -74,8 +77,8 @@ struct ast_lid : public ast { |
|
|
|
|
struct ast_uid : public ast { |
|
|
|
|
std::string id; |
|
|
|
|
|
|
|
|
|
explicit ast_uid(std::string i) |
|
|
|
|
: id(std::move(i)) {} |
|
|
|
|
explicit ast_uid(std::string i, yy::location l = yy::location()) |
|
|
|
|
: ast(std::move(l)), id(std::move(i)) {} |
|
|
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(std::set<std::string>& into); |
|
|
|
@ -89,8 +92,8 @@ struct ast_binop : public ast { |
|
|
|
|
ast_ptr left; |
|
|
|
|
ast_ptr right; |
|
|
|
|
|
|
|
|
|
ast_binop(binop o, ast_ptr l, ast_ptr r) |
|
|
|
|
: op(o), left(std::move(l)), right(std::move(r)) {} |
|
|
|
|
ast_binop(binop o, ast_ptr l, ast_ptr r, yy::location lc = yy::location()) |
|
|
|
|
: ast(std::move(lc)), op(o), left(std::move(l)), right(std::move(r)) {} |
|
|
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(std::set<std::string>& into); |
|
|
|
@ -103,8 +106,8 @@ struct ast_app : public ast { |
|
|
|
|
ast_ptr left; |
|
|
|
|
ast_ptr right; |
|
|
|
|
|
|
|
|
|
ast_app(ast_ptr l, ast_ptr r) |
|
|
|
|
: left(std::move(l)), right(std::move(r)) {} |
|
|
|
|
ast_app(ast_ptr l, ast_ptr r, yy::location lc = yy::location()) |
|
|
|
|
: ast(std::move(lc)), left(std::move(l)), right(std::move(r)) {} |
|
|
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(std::set<std::string>& into); |
|
|
|
@ -118,8 +121,8 @@ struct ast_case : public ast { |
|
|
|
|
type_ptr input_type; |
|
|
|
|
std::vector<branch_ptr> branches; |
|
|
|
|
|
|
|
|
|
ast_case(ast_ptr o, std::vector<branch_ptr> b) |
|
|
|
|
: of(std::move(o)), branches(std::move(b)) {} |
|
|
|
|
ast_case(ast_ptr o, std::vector<branch_ptr> b, yy::location l = yy::location()) |
|
|
|
|
: ast(std::move(l)), of(std::move(o)), branches(std::move(b)) {} |
|
|
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(std::set<std::string>& into); |
|
|
|
@ -136,8 +139,8 @@ struct ast_let : public ast { |
|
|
|
|
|
|
|
|
|
std::vector<basic_definition> translated_definitions; |
|
|
|
|
|
|
|
|
|
ast_let(definition_group g, ast_ptr i) |
|
|
|
|
: definitions(std::move(g)), in(std::move(i)) {} |
|
|
|
|
ast_let(definition_group g, ast_ptr i, yy::location l = yy::location()) |
|
|
|
|
: ast(std::move(l)), definitions(std::move(g)), in(std::move(i)) {} |
|
|
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(std::set<std::string>& into); |
|
|
|
@ -155,8 +158,8 @@ struct ast_lambda : public ast { |
|
|
|
|
std::set<std::string> free_variables; |
|
|
|
|
ast_ptr translated; |
|
|
|
|
|
|
|
|
|
ast_lambda(std::vector<std::string> ps, ast_ptr b) |
|
|
|
|
: params(std::move(ps)), body(std::move(b)) {} |
|
|
|
|
ast_lambda(std::vector<std::string> ps, ast_ptr b, yy::location l = yy::location()) |
|
|
|
|
: ast(std::move(l)), params(std::move(ps)), body(std::move(b)) {} |
|
|
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const; |
|
|
|
|
void find_free(std::set<std::string>& into); |
|
|
|
|