Skip to content

Commit 4d6680c

Browse files
Merge pull request #221 from andrew-johnson-4/booleans
Booleans
2 parents 65ab755 + af25e78 commit 4d6680c

File tree

14 files changed

+16786
-13912
lines changed

14 files changed

+16786
-13912
lines changed

BOOTSTRAP/cli.s

Lines changed: 15308 additions & 13894 deletions
Large diffs are not rendered by default.

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

PRODUCTION/assemble.lm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ assemble-initialize-data := λ e tt . (
207207
( (Literal v) (match (typecheck-datatype tt) (
208208
()
209209
(I8 ( \t '.byte \s v \n ))
210-
(U8 ( \t '.byte \s v \n ))
210+
(U8 (tail(
211+
(if (eq( v True )) (set v '1) ())
212+
(if (eq( v False )) (set v '0) ())
213+
(\t '.byte \s v \n)
214+
)))
211215
(I16 ( \t '.2byte \s v \n ))
212216
(U16 ( \t '.2byte \s v \n ))
213217
(I32 ( \t '.4byte \s v \n ))

PRODUCTION/cli.lm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ main := (
106106
))
107107
)))
108108

109-
(set parse-parsed-program (preprocess-apply-macros parse-parsed-program))
109+
(set parse-parsed-program (preprocess parse-parsed-program))
110110
(if config-strict (typecheck parse-parsed-program) ())
111111

112112
(match mode (

PRODUCTION/codegen-strict.lm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ compile-expr-strict := λctx e offset used . (tail(
182182
(set uid (strict-declare-cstring( lval )))
183183
(set e1 (expr::set-expr( (expr::new ()) uid )))
184184
) (
185-
(set e1 (expr::set-expr( (expr::new ()) lval )))
185+
(match lval (
186+
()
187+
(True (set e1 (expr::set-expr( (expr::new ()) '1 ))))
188+
(False (set e1 (expr::set-expr( (expr::new ()) '0 ))))
189+
(_ (set e1 (expr::set-expr( (expr::new ()) lval ))))
190+
))
186191
))
187192
(set e1 (expr::set-context( e1 ctx )))
188193
(set e1 (expr::set-offset( e1 offset )))
@@ -202,7 +207,12 @@ compile-expr-strict := λctx e offset used . (tail(
202207
(set uid (strict-declare-cstring( lval )))
203208
(set e1 (expr::set-expr( (expr::new ()) uid )))
204209
) (
205-
(set e1 (expr::set-expr( (expr::new ()) lval )))
210+
(match lval (
211+
()
212+
(True (set e1 (expr::set-expr( (expr::new ()) '1 ))))
213+
(False (set e1 (expr::set-expr( (expr::new ()) '0 ))))
214+
(_ (set e1 (expr::set-expr( (expr::new ()) lval ))))
215+
))
206216
))
207217
(set e1 (expr::set-context( e1 ctx )))
208218
(set e1 (expr::set-offset( e1 offset )))

PRODUCTION/preprocess.lm

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
11

2+
preprocess-index-types := ();
3+
4+
preprocess := λprogram . (tail(
5+
(preprocess-index-typedefs program)
6+
(preprocess-apply-macros program)
7+
));
8+
9+
preprocess-index-typedefs := λprogram . (tail(
10+
(while program (
11+
(preprocess-index-typedef (tail program))
12+
(set program (head program))
13+
))
14+
));
15+
16+
preprocess-index-typedef := λterm . (match term (
17+
()
18+
( (Type( l ds )) (
19+
(preprocess-index-indices( ds 0 ))
20+
))
21+
));
22+
23+
preprocess-index-indices := λdef index . (match def (
24+
()
25+
( (App( (App( tds (Variable '|) )) body )) (tail(
26+
(preprocess-index-indices( tds (i2s(inc(s2i index))) ))
27+
(preprocess-index-index( body index ))
28+
)))
29+
( body (
30+
(preprocess-index-index( body index ))
31+
))
32+
));
33+
34+
preprocess-index-index := λbody index . (match body (
35+
()
36+
( (Literal tag) (tail(
37+
(set preprocess-index-types (preprocess-index-types (tag index)))
38+
)))
39+
( (App( (Literal tag) args )) (tail(
40+
(set preprocess-index-types (preprocess-index-types (tag index)))
41+
)))
42+
));
43+
44+
preprocess-index-of-tag := λtag . (tail(
45+
(local indices)
46+
(local index)
47+
(set indices preprocess-index-types)
48+
(while indices (
49+
(if (eq( (head(tail indices)) tag )) (
50+
(set index (tail(tail indices)))
51+
) ())
52+
(set indices (head indices))
53+
))
54+
index
55+
));
56+
257
substitute-macro-body := λkvs e . (match e (
358
()
459
((Variable n) (tail(
@@ -48,7 +103,24 @@ try-destructure-macro := λlhs e . (match (lhs e) (
48103
(if (eq( pl el )) Accept ())
49104
))
50105
( ( (App( (Literal :Literal:) (Variable pv) )) (Literal el)) (
51-
(Accept (KV( pv e )))
106+
(if (preprocess-index-of-tag el)
107+
()
108+
(Accept (KV( pv e )))
109+
)
110+
))
111+
( ( (App( (Literal :Tag:) (Variable pv) )) (Literal el)) (
112+
(if (preprocess-index-of-tag el)
113+
(Accept (KV( pv
114+
(App(
115+
(App(
116+
(Literal :)
117+
(Literal (preprocess-index-of-tag el))
118+
))
119+
(preprocess-restructure-type(parse-type( Constant+Literal+U64 )))
120+
))
121+
)))
122+
()
123+
)
52124
))
53125
( ( (App( (Literal :Variable:) (Variable pv) )) (Variable el)) (
54126
(Accept (KV( pv e )))

STDLIB/default-instruction-set.lm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fragment push := λ(: src GlobalVariable+Sized<size>). (: (
4747
\t 'mov \s '0 \[ '%r15 \] , \s '%r15w \n
4848
\t 'push \s '%r15 \n
4949
))
50-
(if-eq size 2 (
50+
(if-eq size 1 (
5151
\t 'mov \s '0 \[ '%r15 \] , \s '%r15b \n
5252
\t 'push \s '%r15 \n
5353
))

STDLIB/default-rules.lm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ macro ('match-pats-condition term (:Literal: l)) (
2727
(==( term l ))
2828
);
2929

30+
macro ('match-pats-condition term (:Tag: l)) (
31+
(==( (.0( term )) l ))
32+
);
33+

STRICT/cli.lm

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import STDLIB/default-stdlib.lm;
66

77
import STRICT/utility.lm;
88

9-
#config-strict := True;
10-
#config-preprocess := True;
9+
config-strict := Trueu8;
10+
config-preprocess := Trueu8;
1111
config-target := 'tmp.s_s;
1212

1313
type CompileMode ModeTokenize | ModeParse | ModeTypecheck | ModeCompile;
@@ -23,24 +23,29 @@ main := λ(: argc U64)(: argv U8[][]).(tail(
2323
('--parse_s (set config-mode ModeParse))
2424
('--typecheck_s (set config-mode ModeTypecheck))
2525
('--compile_s (set config-mode ModeCompile))
26-
# ('--strict_s (set config-strict True))
27-
# ('--gradual_s (set config-strict False))
28-
# ('--macro_s (set config-preprocess True))
29-
# ('--nomacro_s (set config-preprocess False))
26+
('--strict_s (set config-strict Trueu8))
27+
('--gradual_s (set config-strict Falseu8))
28+
('--macro_s (set config-preprocess Trueu8))
29+
('--nomacro_s (set config-preprocess Falseu8))
3030
('-o_s (tail(
3131
(set argi (+( argi 1u64 )))
3232
(set input (SCons(
3333
(close input)
3434
(close (SAtom([]( argv argi ))))
3535
)))
3636
)))
37-
(fp (set input (SCons(
38-
(close input)
39-
(close (SAtom( fp )))
40-
))))
37+
(fp (tail(
38+
(print fp)
39+
(set input (SCons(
40+
(close input)
41+
(close (SAtom( fp )))
42+
)))
43+
)))
4144
))
4245
(set argi (+( argi 1u64 )))
4346
))
4447
(print Input:\s_s)(print input)(print \n_s)
4548
(print Output:\s_s)(print config-target)(print \n_s)
49+
(print Preprocess:\s_s)(print config-preprocess)(print \n_s)
50+
(print Strict:\s_s)(print config-strict)(print \n_s)
4651
));

0 commit comments

Comments
 (0)