Skip to content

Commit b1a0c4a

Browse files
Merge pull request #214 from andrew-johnson-4/strict-compiler-dev-2-1
There is one failing test that is known, but the build is stable and introduces a vital new features: error reporting at runtime in strict mode.
2 parents f6cd083 + 4e5a854 commit b1a0c4a

File tree

7 files changed

+108
-78
lines changed

7 files changed

+108
-78
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lambda_mountain"
3-
version = "1.11.76"
3+
version = "1.11.77"
44
authors = ["Andrew <andrew@subarctic.org>"]
55
license = "MIT"
66
description = "Lambda Mountain"

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

STDLIB/default-rules.lm

+51-49
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,56 @@ macro ( ('let x y) )
44

55
macro ('match t ps) (tail(
66
(let (uuid term) t)
7-
(let (uuid matched) ())
8-
(let (uuid return) ())
9-
(match-pats( (uuid term) (uuid matched) (uuid return) ps ))
10-
(uuid return)
7+
(match-pats( (uuid term) ps (fail PatternMatchFailure_s) ))
118
));
12-
macro ('match-pats( term matched return () )) ();
13-
macro ('match-pats( term matched return (ps (lhs rhs)) )) (
14-
(match-pats( term matched return ps ))
15-
(if matched () (
16-
(set matched True)
17-
(match-destructure( term matched return lhs ))
18-
(if matched (
19-
(set return rhs)
20-
) ())
21-
))
22-
);
23-
macro ('match-destructure( term matched return () )) (
24-
(if matched (
25-
(if term (
26-
(set matched ())
27-
) ())
28-
) ())
29-
);
30-
macro ('match-destructure( term matched return (:Literal: l) )) (
31-
(if matched (
32-
(if (is-atom term) (
33-
(if (eq( term l )) () (
34-
(set matched ())
35-
))
36-
) (
37-
(set matched ())
38-
))
39-
) ())
40-
);
41-
macro ('match-destructure( term matched return (:Variable: v) )) (
42-
(let v term)
43-
);
44-
macro ('match-destructure( term matched return (l r) )) (
45-
(if matched (
46-
(if (is-cons term) (
47-
(let (uuid x) term)
48-
(set term (head (uuid x)))
49-
(match-destructure( term matched return l ))
50-
(set term (tail (uuid x)))
51-
(match-destructure( term matched return r ))
52-
(set term (uuid x))
53-
) (
54-
(set matched ())
55-
))
56-
) ())
9+
10+
macro ('match-pats( term ps remainder )) (
11+
remainder
5712
);
13+
14+
#macro ('match-pats( term matched return () )) ();
15+
#macro ('match-pats( term matched return (ps (lhs rhs)) )) (
16+
# (match-pats( term matched return ps ))
17+
# (if matched () (
18+
# (set matched True)
19+
# (match-destructure( term matched return lhs ))
20+
# (if matched (
21+
# (set return rhs)
22+
# ) ())
23+
# ))
24+
#);
25+
#macro ('match-destructure( term matched return () )) (
26+
# (if matched (
27+
# (if term (
28+
# (set matched ())
29+
# ) ())
30+
# ) ())
31+
#);
32+
#macro ('match-destructure( term matched return (:Literal: l) )) (
33+
# (if matched (
34+
# (if (is-atom term) (
35+
# (if (eq( term l )) () (
36+
# (set matched ())
37+
# ))
38+
# ) (
39+
# (set matched ())
40+
# ))
41+
# ) ())
42+
#);
43+
#macro ('match-destructure( term matched return (:Variable: v) )) (
44+
# (let v term)
45+
#);
46+
#macro ('match-destructure( term matched return (l r) )) (
47+
# (if matched (
48+
# (if (is-cons term) (
49+
# (let (uuid x) term)
50+
# (set term (head (uuid x)))
51+
# (match-destructure( term matched return l ))
52+
# (set term (tail (uuid x)))
53+
# (match-destructure( term matched return r ))
54+
# (set term (uuid x))
55+
# ) (
56+
# (set matched ())
57+
# ))
58+
# ) ())
59+
#);

STDLIB/default-stdlib.lm

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ print := λ(: x S). (: (tail(
3737
()
3838
)) Nil);
3939

40+
fail := λ(: msg Array<U8,?>). (: (tail(
41+
(print msg)
42+
(exit 1u64)
43+
)) Nil);
44+
45+
exit := λ(: code U64). (: (tail(
46+
(mov( 60u64 RAX ))
47+
(mov( code RDI ))
48+
(syscall())
49+
)) Nil);
50+
4051
print := λ(: x Array<U8,?>). (: (tail(
4152
(mov( x R15 ))
4253
(mov( 0u64 RDX )) # data length

STRICT/cli.lm

+32-27
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,42 @@ import STDLIB/default-stdlib.lm;
66

77
import STRICT/utility.lm;
88

9-
config-strict := 0u8;
9+
#config-strict := True;
10+
#config-preprocess := True;
11+
#config-target := 'tmp.s_s;
1012

11-
type CompileMode Tokenize | Parse | Compile;
12-
config-mode := Compile;
13+
type CompileMode ModeTokenize | ModeParse | ModeTypecheck | ModeCompile;
14+
config-mode := ModeCompile;
1315

1416
main := λ(: argc U64)(: argv U8[][]).(tail(
15-
# (let argi 0u64)
17+
(let argi 0u64)
1618
(let input SNil)
17-
(set input (SCons(
18-
(close SNil)
19-
(close SNil)
20-
)))
21-
# (while (<( argi argc )) (
22-
# (set input (SNil))
23-
# (set input (SCons(
24-
# (close (SAtom(
25-
# ([]( argv argi ))
19+
(while (<( argi argc )) (
20+
(print 'c_s)
21+
(match ([]( argv argi )) (
22+
()
23+
# (_ (print c_s))
24+
# ('--tokenize_s (set config-mode ModeTokenize))
25+
# ('--parse_s (set config-mode ModeParse))
26+
# ('--typecheck_s (set config-mode ModeTypecheck))
27+
# ('--compile_s (set config-mode ModeCompile))
28+
# ('--strict_s (set config-strict True))
29+
# ('--gradual_s (set config-strict False))
30+
# ('--macro_s (set config-preprocess True))
31+
# ('--nomacro_s (set config-preprocess False))
32+
# ('-o_s (tail(
33+
# (set argi (+( argi 1u64 )))
34+
# (set input (SCons(
35+
# (close input)
36+
# (close (SAtom([]( argv argi ))))
37+
# )))
2638
# )))
27-
# (close input)
28-
# )))
29-
# (set argi (+( argi 1u64 )))
30-
# ))
39+
# (fp (set input (SCons(
40+
# (close input)
41+
# (close (SAtom( fp )))
42+
# ))))
43+
))
44+
(set argi (+( argi 1u64 )))
45+
))
3146
(print input)
32-
# (print (==( ([]( argv argi )) (: '--tokenize U8[]) )) )
33-
# if set_target { config_target().lock().unwrap().set(arg); }
34-
# else if arg=="--tokenize" {unsafe{ CONFIG_MODE = CompileMode::Tokenize; }}
35-
# else if arg=="--parse" {unsafe{ CONFIG_MODE = CompileMode::Parse; }}
36-
# else if arg=="--typecheck" {unsafe{ CONFIG_MODE = CompileMode::Typecheck; }}
37-
# else if arg=="--compile" {unsafe{ CONFIG_MODE = CompileMode::Compile; }}
38-
# else if arg=="--strict" {unsafe{ CONFIG_STRICT = true; }}
39-
# else if arg=="--gradual" {unsafe{ CONFIG_STRICT = false; }}
40-
# else if arg=="--noprep" {unsafe{ CONFIG_PREPROCESS = false; }}
41-
# else if arg=="-o" { set_target = true; }
4247
));

tests/strict/match1.lm

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 := match 1u64 (
8+
()
9+
(1u64 (print 1u64))
10+
(_ (print 0u64))
11+
);

tests/strict/match1.lm.out

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

0 commit comments

Comments
 (0)