-
Notifications
You must be signed in to change notification settings - Fork 7
/
semantics.h
73 lines (54 loc) · 2.31 KB
/
semantics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include "stringtable.h"
//#include "node.h"
#include "exprfndef.h"
struct Type;
struct TParamDef;
struct Expr;
struct Name;
// type inference
struct CaptureVars;
ResolveResult resolve_make_fn_call(Expr* receiver,ExprBlock* block/*caller*/,Scope* scope,const Type* desired,int flags) ;
ResolveResult resolve_make_fn_call(Expr* receiver,ExprBlock* block,Scope* scope,const Type* desired);
struct Call;
struct FnName;
/// 'StructDef' handles everything for struct,trait,impl,vtable class,mod/namespace,
///
/// specific types derived expose a subset as language sugar.
/// a transpiler should handle conversions eg spot a 'struct' with pure virtuals -> trait, etc.
/// TODO a Rust Enum is sugar for a struct holding constants & derived variant structs.
typedef Type TParamVal;
struct TParamXlat{
const MyVec<TParamDef*>& tparams; const MyVec<TParamVal*>& given_types;
TParamXlat();
TParamXlat( const MyVec<TParamDef*>& t, const MyVec<TParamVal*>& g):tparams(t),given_types(g){}
bool typeparams_all_set()const{
for (int i=0; i<given_types.size(); i++) {
if (given_types[i]==0) return false;
}
return true;
}
int typeparam_index(const Name& n) const;
void dump(PrinterRef depth)const;
};
struct FindFunction {
struct Candidate{ExprFnDef* f; int score;};
MyVec<Candidate> candidates;
Name name;
const Expr* callsite;
int flags;
bool verbose=false;
int max_candidates=5;
const MyVec<Expr*>& args;
const Type* ret_type;
FindFunction(Name n, const MyVec<Expr*>& a, const Type* r,int f):name(n),args(a),ret_type(r),flags(f){}
void consider_candidate(ExprFnDef* f);
void find_fn_sub(Expr* src);
void find_fn_from_scopes(Scope* s,Scope* ex);
void insert_candidate(ExprFnDef* f,int score);
void dump();
};
int match_fn_tparams(MyVec<TParamVal*>& matched, const ExprFnDef* f, const MyVec<Expr*>& args, const Expr* callsite);
int match_struct_tparams(MyVec<TParamVal*>& matched, const ExprStructDef* sd, const MyVec<Expr*>& field_inits, const Expr* callsite);
int match_tparams(MyVec<TParamVal*>& matched, const MyVec<ArgDef*>& arg_fmt,const Type* ret_type,const MyVec<TParamDef*>& tparams, const MyVec<Expr*>& given_args,int first_arg_index, const Expr* callsite,bool variadic);
void fill_given_tparams(MyVec<TParamVal*>& matched, const MyVec<TParamDef*>& arg_fmt, const MyVec<TParamVal*>& given_types);