Skip to content

Commit 1937bef

Browse files
offsets are probably wrong, but this should work
1 parent ee43e88 commit 1937bef

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
nostd: prod
3-
./production --nostd -o tmp.s tests/strict/s-xp1.lm
3+
./production --nostd -o tmp.s tests/strict/match2.lm
44
as -o tmp.o tmp.s
55
ld -o tmp tmp.o
66
./tmp && echo $?

PRODUCTION/codegen-strict.lm

+6-8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ compile-expr-strict := λctx e offset used . (tail(
6969
\o \s 'unlet \s lname \s '= \s (quote-s rhs) \s ': \s (quote-s(typecheck-lookup rhs)) \n
7070
(expr::get-unframe e1) \t 'add \s '$ sz , \s '%rsp \n
7171
))))
72+
(set e1 (expr::set-altframe( e1 (
73+
\o \s 'altlet \s lname \s '= \s (quote-s rhs) \s ': \s (quote-s(typecheck-lookup rhs)) \n
74+
\t 'sub \s '$ sz , \s '%rsp \n
75+
))))
7276
))
7377
(set ctx (context::bind( (expr::get-context e1) lname
7478
(typecheck-ascript( (LocalVariable offset) (typecheck-lookup rhs) ))
@@ -159,8 +163,6 @@ compile-expr-strict := λctx e offset used . (tail(
159163
( (App( (App( (App( (Variable 'if) cond )) t )) f )) (tail(
160164
(set e1 (compile-expr-strict( ctx cond offset Used )))
161165
(set e2 (compile-expr-strict( (expr::get-context e1) t (expr::get-offset e1) Used )))
162-
(local e2-size)
163-
(print-s (E2Offset (expr::get-offset e2)))(print-s \n)
164166
(set e3 (compile-expr-strict( (expr::get-context e2) f (expr::get-offset e2) Used )))
165167
(match (expr::get-type e1) (
166168
()
@@ -181,19 +183,15 @@ compile-expr-strict := λctx e offset used . (tail(
181183
(local label-end)
182184
(set label-end (uuid()))
183185
(set e4 (expr::set-prog( e4 (
184-
(expr::get-frame e2)
185-
(expr::get-frame e3)
186186
(expr::get-prog e1)
187187
\t (expr::get-expr e1) \s label-true-branch \n
188-
(expr::get-frame e3)
188+
(expr::get-altframe e2)
189189
(expr::get-prog e3)
190-
(expr::get-unframe e3)
191190
\t 'jmp \s label-end \n
192191
label-true-branch ': \n
193192
(expr::get-prog e2)
193+
(expr::get-altframe e3)
194194
label-end ': \n
195-
(expr::get-unframe e2)
196-
(expr::get-unframe e3)
197195
))))
198196
(set e4 (expr::set-context( e4 (expr::get-context e3) )))
199197
(set e4 (expr::set-offset( e4 (expr::get-offset e3) )))

PRODUCTION/expression.lm

+40-10
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
11

2-
expr::new := λ . (StrictExpr(() () () () () () () () 0));
2+
expr::new := λ . (StrictExpr(() () () () () () () () 0 ()));
33
expr::get-type := λe . (match e (
44
()
55
((Expr(f p u t d pc off)) ())
6-
((StrictExpr(tt f u t d p e c o)) tt)
6+
((StrictExpr(tt f u t d p e c o a)) tt)
77
));
88
expr::get-frame := λe . (match e (
99
()
1010
((Expr(f p u t d pc off)) f)
11-
((StrictExpr(tt f u t d p e c o)) f)
11+
((StrictExpr(tt f u t d p e c o a)) f)
1212
));
1313
expr::get-unframe := λe . (match e (
1414
()
1515
((Expr(f p u t d pc off)) u)
16-
((StrictExpr(tt f u t d p e c o)) u)
16+
((StrictExpr(tt f u t d p e c o a)) u)
1717
));
1818
expr::get-text := λe . (match e (
1919
()
2020
((Expr(f p u t d pc off)) t)
21-
((StrictExpr(tt f u t d p e c o)) t)
21+
((StrictExpr(tt f u t d p e c o a)) t)
2222
));
2323
expr::get-data := λe . (match e (
2424
()
2525
((Expr(f p u t d pc off)) d)
26-
((StrictExpr(tt f u t d p e c o)) d)
26+
((StrictExpr(tt f u t d p e c o a)) d)
2727
));
2828
expr::get-prog := λe . (match e (
2929
()
3030
((Expr(f p u t d pc off)) p)
31-
((StrictExpr(tt f u t d p e c o)) p)
31+
((StrictExpr(tt f u t d p e c o a)) p)
3232
));
3333
expr::get-expr := λe . (match e (
3434
()
35-
((StrictExpr(tt f u t d p x c o)) x)
35+
((StrictExpr(tt f u t d p x c o a)) x)
3636
));
3737
expr::get-context := λe . (match e (
3838
()
3939
((Expr(f p u t d pc off)) pc)
40-
((StrictExpr(tt f u t d p e c o)) c)
40+
((StrictExpr(tt f u t d p e c o a)) c)
4141
));
4242
expr::get-offset := λe . (match e (
4343
()
4444
((Expr(f p u t d pc off)) off )
45-
((StrictExpr(tt f u t d p e c o)) o )
45+
((StrictExpr(tt f u t d p e c o a)) o )
46+
));
47+
expr::get-altframe := λe . (match e (
48+
()
49+
((StrictExpr(tt f u t d p e c o a)) a )
4650
));
4751
expr::set-frame := λe x . (
4852
(StrictExpr(
@@ -55,6 +59,7 @@ expr::set-frame := λe x . (
5559
(expr::get-expr e)
5660
(expr::get-context e)
5761
(expr::get-offset e)
62+
(expr::get-altframe e)
5863
))
5964
);
6065
expr::set-unframe := λe x . (
@@ -68,6 +73,7 @@ expr::set-unframe := λe x . (
6873
(expr::get-expr e)
6974
(expr::get-context e)
7075
(expr::get-offset e)
76+
(expr::get-altframe e)
7177
))
7278
);
7379
expr::set-text := λe x . (
@@ -81,6 +87,7 @@ expr::set-text := λe x . (
8187
(expr::get-expr e)
8288
(expr::get-context e)
8389
(expr::get-offset e)
90+
(expr::get-altframe e)
8491
))
8592
);
8693
expr::set-data := λe x . (
@@ -94,6 +101,7 @@ expr::set-data := λe x . (
94101
(expr::get-expr e)
95102
(expr::get-context e)
96103
(expr::get-offset e)
104+
(expr::get-altframe e)
97105
))
98106
);
99107
expr::set-prog := λe x . (
@@ -107,6 +115,7 @@ expr::set-prog := λe x . (
107115
(expr::get-expr e)
108116
(expr::get-context e)
109117
(expr::get-offset e)
118+
(expr::get-altframe e)
110119
))
111120
);
112121
expr::set-expr := λe x . (
@@ -120,6 +129,7 @@ expr::set-expr := λe x . (
120129
x
121130
(expr::get-context e)
122131
(expr::get-offset e)
132+
(expr::get-altframe e)
123133
))
124134
);
125135
expr::set-context := λe x . (
@@ -133,6 +143,7 @@ expr::set-context := λe x . (
133143
(expr::get-expr e)
134144
x
135145
(expr::get-offset e)
146+
(expr::get-altframe e)
136147
))
137148
);
138149
expr::set-offset := λe x . (
@@ -146,6 +157,7 @@ expr::set-offset := λe x . (
146157
(expr::get-expr e)
147158
(expr::get-context e)
148159
x
160+
(expr::get-altframe e)
149161
))
150162
);
151163
expr::set-type := λe x . (
@@ -159,6 +171,21 @@ expr::set-type := λe x . (
159171
(expr::get-expr e)
160172
(expr::get-context e)
161173
(expr::get-offset e)
174+
(expr::get-altframe e)
175+
))
176+
);
177+
expr::set-altframe := λe x . (
178+
(StrictExpr(
179+
(expr::get-type e)
180+
(expr::get-frame e)
181+
(expr::get-unframe e)
182+
(expr::get-text e)
183+
(expr::get-data e)
184+
(expr::get-prog e)
185+
(expr::get-expr e)
186+
(expr::get-context e)
187+
(expr::get-offset e)
188+
x
162189
))
163190
);
164191

@@ -184,6 +211,9 @@ expr::chain := λ e1 e2 . (tail(
184211
(set e1 (expr::set-unframe(
185212
e1 ( (expr::get-unframe e1) (expr::get-unframe e2) )
186213
)))
214+
(set e1 (expr::set-altframe(
215+
e1 ( (expr::get-altframe e1) (expr::get-altframe e2) )
216+
)))
187217
(set e1 (expr::set-offset( e1 (expr::get-offset e2) )))
188218
(set e1 (expr::set-context( e1 (expr::get-context e2) )))
189219
e1

0 commit comments

Comments
 (0)