Skip to content

Commit 687dc19

Browse files
really close to working
1 parent 8cf25b8 commit 687dc19

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
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/cc2.lm
3+
./production --nostd -o tmp.s tests/strict/match6.lm
44
as -o tmp.o tmp.s
55
ld -o tmp tmp.o
66
./tmp && echo $?

PRODUCTION/codegen-strict.lm

+7-3
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ compile-expr-strict := λctx e offset used . (tail(
133133
(expr::get-unframe e3)
134134
\t 'jmp \s label-end \n
135135
label-true-branch ': \n
136-
(expr::get-frame e2)
137136
(expr::get-prog e2)
138-
(expr::get-unframe e2)
139137
label-end ': \n
140138
))))
141139
(set e4 (expr::set-context( e4 (expr::get-context e2) )))
142-
(set e4 (expr::set-offset( e4 (expr::get-offset e3) )))
140+
(set e4 (expr::set-offset( e4 (expr::get-offset e1) )))
141+
(set e4 (expr::set-frame( e4 (
142+
(expr::get-frame e1) (expr::get-frame e2)
143+
))))
144+
(set e4 (expr::set-unframe( e4 (
145+
(expr::get-unframe e1) (expr::get-unframe e2)
146+
))))
143147
e4
144148
)))
145149
( (App( (Variable 'label) (Variable label-name) )) (

STDLIB/default-rules.lm

+13-13
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ macro ('match-pats-condition( term (:Tag: l lt) )) (
3131
(==( (.0( term )) l ))
3232
);
3333

34-
macro ('match-pats-condition( term ((:Tag: l lt) ( x1 )) )) (
35-
if (==( (.0( term )) l ))
36-
(match-pats-condition( (.1( (as term lt) )) x1 ))
37-
(branchfalse())
38-
);
34+
macro ('match-pats-condition( term ((:Tag: l lt) ( x1 )) )) (tail(
35+
(let ok Trueu8)
36+
(if (==( (.0( term )) l )) () (set ok Falseu8))
37+
(if (match-pats-condition( (.1( (as term lt) )) x1 )) () (set ok Falseu8))
38+
(==( ok Trueu8 ))
39+
));
3940

40-
macro ('match-pats-condition( term ((:Tag: l lt) ( x1 x2 ) ))) (
41-
if (==( (.0( term )) l ))
42-
(if (match-pats-condition( (.2( (as term lt) )) x1 ))
43-
(match-pats-condition( (.1( (as term lt) )) x2 ))
44-
(branchfalse())
45-
)
46-
(branchfalse())
47-
);
41+
macro ('match-pats-condition( term ((:Tag: l lt) ( x1 x2 ) ))) (tail(
42+
(let ok Trueu8)
43+
(if (==( (.0( term )) l )) () (set ok Falseu8))
44+
(if (match-pats-condition( (.2( (as term lt) )) x2 )) () (set ok Falseu8))
45+
(if (match-pats-condition( (.1( (as term lt) )) x1 )) () (set ok Falseu8))
46+
(==( ok Trueu8 ))
47+
));
4848

tests/strict/match6.lm

+15-17
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,22 @@ import STDLIB/default-stdlib.lm;
88
type Cases CaseOne | (CaseTwo( U64 )) | (CaseThree( U64 , U64 ));
99

1010
main := (
11-
# (match (CaseOne) (
12-
# ()
13-
# ( (CaseOne) (print 'CaseOne_s) )
14-
# ( (CaseTwo( x )) (tail( (print 'CaseTwo_s) (print x) )) )
15-
# ( (CaseThree( x y )) (tail( (print 'CaseThree_s) (print x) (print y) )))
16-
# ))
17-
# (match (CaseTwo( 1u64 )) (
18-
# ()
19-
# ( (CaseOne) (print 'CaseOne_s) )
20-
# ( (CaseTwo( x )) (tail( (print 'CaseTwo_s) (print x) )) )
21-
# ( (CaseThree( x y )) (tail( (print 'CaseThree_s) (print x) (print y) )))
22-
# ))
11+
(match (CaseOne) (
12+
()
13+
( (CaseOne) (print 'CaseOne_s) )
14+
( (CaseTwo( x )) (tail( (print 'CaseTwo_s) (print x) )) )
15+
( (CaseThree( x y )) (tail( (print 'CaseThree_s) (print x) (print y) )))
16+
))
17+
(match (CaseTwo( 1u64 )) (
18+
()
19+
( (CaseOne) (print 'CaseOne_s) )
20+
( (CaseTwo( x )) (tail( (print 'CaseTwo_s) (print x) )) )
21+
( (CaseThree( x y )) (tail( (print 'CaseThree_s) (print x) (print y) )))
22+
))
2323
(match (CaseThree( 2u64 3u64 )) (
2424
()
25-
# ( (CaseOne) (print 'CaseOne_s) )
26-
# ( (CaseTwo( x )) (tail( (print 'CaseTwo_s) (print x) )) )
27-
# ( (CaseThree( x y )) (tail( (print 'CaseThree_s) (print x) (print y) )))
28-
# ( (CaseTwo( x )) () )
29-
( (CaseThree( x y )) (tail( (print x) (print y) )) )
25+
( (CaseOne) (print 'CaseOne_s) )
26+
( (CaseTwo( x )) (tail( (print 'CaseTwo_s) (print x) )) )
27+
( (CaseThree( x y )) (tail( (print 'CaseThree_s) (print x) (print y) )))
3028
))
3129
);

0 commit comments

Comments
 (0)