Skip to content

Commit 2df3c5e

Browse files
match literal works
1 parent ce71511 commit 2df3c5e

File tree

6 files changed

+39
-47
lines changed

6 files changed

+39
-47
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lambda_mountain"
3-
version = "1.11.79"
3+
version = "1.11.80"
44
authors = ["Andrew <andrew@subarctic.org>"]
55
license = "MIT"
66
description = "Lambda Mountain"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
nostd: prod
3-
./production --nostd -o tmp.s tests/strict/match1.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 $?

STDLIB/default-primitives.lm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ fragment == := λ(: l U64+GlobalVariable)(: r U64+Literal+Constant). (: (
183183
))
184184
(.expression( 'je ))
185185
) BranchConditional);
186+
fragment == := λ(: l U64+LocalVariable)(: r U64+Literal+Constant). (: (
187+
(.program (
188+
\t 'cmp \s '$ (.expression r) , (.expression l) \[ '%rbp \] \n
189+
))
190+
(.expression( 'je ))
191+
) BranchConditional);
186192
fragment == := λ(: l U64+Literal+Constant)(: r U64+GlobalVariable). (: (
187193
(.program (
188194
\t 'mov \s '$ (.expression r) , '%r15 \n

STDLIB/default-rules.lm

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,7 @@ macro ('match-pats-condition term (:Variable: v)) (
2323
(tail( (let v term) (branchtrue()) ))
2424
);
2525

26-
#macro ('match-pats( term matched return (ps (lhs rhs)) )) (
27-
# (match-pats( term matched return ps ))
28-
# (if matched () (
29-
# (set matched True)
30-
# (match-destructure( term matched return lhs ))
31-
# (if matched (
32-
# (set return rhs)
33-
# ) ())
34-
# ))
35-
#);
36-
#macro ('match-destructure( term matched return () )) (
37-
# (if matched (
38-
# (if term (
39-
# (set matched ())
40-
# ) ())
41-
# ) ())
42-
#);
43-
#macro ('match-destructure( term matched return (:Literal: l) )) (
44-
# (if matched (
45-
# (if (is-atom term) (
46-
# (if (eq( term l )) () (
47-
# (set matched ())
48-
# ))
49-
# ) (
50-
# (set matched ())
51-
# ))
52-
# ) ())
53-
#);
54-
#macro ('match-destructure( term matched return (:Variable: v) )) (
55-
# (let v term)
56-
#);
57-
#macro ('match-destructure( term matched return (l r) )) (
58-
# (if matched (
59-
# (if (is-cons term) (
60-
# (let (uuid x) term)
61-
# (set term (head (uuid x)))
62-
# (match-destructure( term matched return l ))
63-
# (set term (tail (uuid x)))
64-
# (match-destructure( term matched return r ))
65-
# (set term (uuid x))
66-
# ) (
67-
# (set matched ())
68-
# ))
69-
# ) ())
70-
#);
26+
macro ('match-pats-condition term (:Literal: l)) (
27+
(==( term l ))
28+
);
29+

tests/strict/match2.lm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
import STDLIB/default-instruction-set.lm;
3+
import STDLIB/default-primitives.lm;
4+
import STDLIB/default-rules.lm;
5+
import STDLIB/default-stdlib.lm;
6+
7+
main := (tail(
8+
(match 1u64 (
9+
()
10+
(1u64 (print 1u64))
11+
(2u64 (print 2u64))
12+
(3u64 (print 3u64))
13+
))
14+
(match 2u64 (
15+
()
16+
(1u64 (print 1u64))
17+
(2u64 (print 2u64))
18+
(3u64 (print 3u64))
19+
))
20+
(match 3u64 (
21+
()
22+
(1u64 (print 1u64))
23+
(2u64 (print 2u64))
24+
(3u64 (print 3u64))
25+
))
26+
));

tests/strict/match2.lm.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123

0 commit comments

Comments
 (0)