sammine-lang
Loading...
Searching...
No Matches
Monomorphizer.h
1#pragma once
2
3#include "ast/Ast.h"
4#include "typecheck/Types.h"
5#include "util/MonomorphizedName.h"
6#include <memory>
7#include <string>
8#include <unordered_map>
9
10namespace sammine_lang::AST {
11
12class Monomorphizer {
13public:
14 using SubstitutionMap = std::unordered_map<std::string, Type>;
15
16 static std::unique_ptr<FuncDefAST>
17 instantiate(FuncDefAST *generic,
18 const sammine_util::MonomorphizedName &mono_name,
19 const SubstitutionMap &bindings);
20
21 static std::unique_ptr<EnumDefAST>
22 instantiate_enum(EnumDefAST *generic,
23 const sammine_util::MonomorphizedName &mono_name,
24 const SubstitutionMap &bindings);
25
26private:
27 const SubstitutionMap &bindings;
28 explicit Monomorphizer(const SubstitutionMap &bindings)
29 : bindings(bindings) {}
30
31 std::unique_ptr<TypeExprAST> clone_type_expr(TypeExprAST *expr);
32 std::unique_ptr<TypedVarAST> clone_typed_var(TypedVarAST *var);
33 std::unique_ptr<PrototypeAST>
34 clone_prototype(PrototypeAST *proto,
35 const sammine_util::MonomorphizedName &mono_name);
36 std::unique_ptr<BlockAST> clone_block(BlockAST *block);
37 std::unique_ptr<ExprAST> clone_expr(ExprAST *expr);
38 std::vector<std::unique_ptr<ExprAST>>
39 clone_expr_vec(const std::vector<std::unique_ptr<ExprAST>> &exprs);
40
41 // Helper to get the concrete type name for a type param
42 std::string resolve_type_name(const std::string &name) const;
43};
44
45} // namespace sammine_lang::AST
Defined the AST Node classes (ProgramAST, StructDefAST, FuncDefAST) and a visitor interface for trave...
Defines the core Type system for Sammine.
An AST to simulate a { } code block.
Definition Ast.h:317
Definition Ast.h:378
Definition Ast.h:302
Definition Ast.h:326
A prototype to present "func func_name(...) -> type;".
Definition Ast.h:236
Definition Ast.h:205
Definition MonomorphizedName.h:15