-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenv.c
89 lines (85 loc) · 1.71 KB
/
env.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "env.h"
#include "util.h"
#include "symbol.h"
E_enventry E_VarEntry(Ty_ty ty)
{
E_enventry p = checked_malloc(sizeof(*p));
p->kind = E_varEntry;
p->u.var.ty = ty;
return p;
}
E_enventry E_FunEntry(Ty_tyList formals, Ty_ty result)
{
E_enventry p = checked_malloc(sizeof(*p));
p->kind = E_funEntry;
p->u.fun.formals = formals;
p->u.fun.result = result;
return p;
}
S_table E_base_tenv(void)
{
S_table t = S_empty();
S_enter(t, S_Symbol("int"), Ty_Int());
S_enter(t, S_Symbol("string"), Ty_String());
return t;
}
S_table E_base_venv(void)
{
S_table t = S_empty();
S_enter(
t,
S_Symbol("print"),
E_FunEntry(Ty_TyList(Ty_String(), NULL), Ty_Void())
);
S_enter(
t,
S_Symbol("flush"),
E_FunEntry(NULL, Ty_Void())
);
S_enter(
t,
S_Symbol("getchar"),
E_FunEntry(NULL, Ty_String())
);
S_enter(
t,
S_Symbol("ord"),
E_FunEntry(Ty_TyList(Ty_String(), NULL), Ty_Int())
);
S_enter(
t,
S_Symbol("chr"),
E_FunEntry(Ty_TyList(Ty_Int(), NULL), Ty_String())
);
S_enter(
t,
S_Symbol("size"),
E_FunEntry(Ty_TyList(Ty_String(), NULL), Ty_Int())
);
S_enter(
t,
S_Symbol("substring"),
E_FunEntry(Ty_TyList(Ty_String(),
Ty_TyList(Ty_Int(),
Ty_TyList(Ty_Int(), NULL))),
Ty_String())
);
S_enter(
t,
S_Symbol("concat"),
E_FunEntry(Ty_TyList(Ty_String(),
Ty_TyList(Ty_String(), NULL)),
Ty_String())
);
S_enter(
t,
S_Symbol("not"),
E_FunEntry(Ty_TyList(Ty_Int(), NULL), Ty_Int())
);
S_enter(
t,
S_Symbol("exit"),
E_FunEntry(Ty_TyList(Ty_Int(), NULL), Ty_Void())
);
return t;
}