Skip to content

Booleans #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 16, 2024
29,202 changes: 15,308 additions & 13,894 deletions BOOTSTRAP/cli.s

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lambda_mountain"
version = "1.11.84"
version = "1.11.85"
authors = ["Andrew <andrew@subarctic.org>"]
license = "MIT"
description = "Lambda Mountain"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

nostd: prod
./production --nostd -o tmp.s STRICT/cli.lm
./production --nostd -o tmp.s tests/strict/match4.lm
as -o tmp.o tmp.s
ld -o tmp tmp.o
./tmp && echo $?
Expand Down
6 changes: 5 additions & 1 deletion PRODUCTION/assemble.lm
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ assemble-initialize-data := λ e tt . (
( (Literal v) (match (typecheck-datatype tt) (
()
(I8 ( \t '.byte \s v \n ))
(U8 ( \t '.byte \s v \n ))
(U8 (tail(
(if (eq( v True )) (set v '1) ())
(if (eq( v False )) (set v '0) ())
(\t '.byte \s v \n)
)))
(I16 ( \t '.2byte \s v \n ))
(U16 ( \t '.2byte \s v \n ))
(I32 ( \t '.4byte \s v \n ))
Expand Down
2 changes: 1 addition & 1 deletion PRODUCTION/cli.lm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ main := (
))
)))

(set parse-parsed-program (preprocess-apply-macros parse-parsed-program))
(set parse-parsed-program (preprocess parse-parsed-program))
(if config-strict (typecheck parse-parsed-program) ())

(match mode (
Expand Down
14 changes: 12 additions & 2 deletions PRODUCTION/codegen-strict.lm
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ compile-expr-strict := λctx e offset used . (tail(
(set uid (strict-declare-cstring( lval )))
(set e1 (expr::set-expr( (expr::new ()) uid )))
) (
(set e1 (expr::set-expr( (expr::new ()) lval )))
(match lval (
()
(True (set e1 (expr::set-expr( (expr::new ()) '1 ))))
(False (set e1 (expr::set-expr( (expr::new ()) '0 ))))
(_ (set e1 (expr::set-expr( (expr::new ()) lval ))))
))
))
(set e1 (expr::set-context( e1 ctx )))
(set e1 (expr::set-offset( e1 offset )))
Expand All @@ -202,7 +207,12 @@ compile-expr-strict := λctx e offset used . (tail(
(set uid (strict-declare-cstring( lval )))
(set e1 (expr::set-expr( (expr::new ()) uid )))
) (
(set e1 (expr::set-expr( (expr::new ()) lval )))
(match lval (
()
(True (set e1 (expr::set-expr( (expr::new ()) '1 ))))
(False (set e1 (expr::set-expr( (expr::new ()) '0 ))))
(_ (set e1 (expr::set-expr( (expr::new ()) lval ))))
))
))
(set e1 (expr::set-context( e1 ctx )))
(set e1 (expr::set-offset( e1 offset )))
Expand Down
74 changes: 73 additions & 1 deletion PRODUCTION/preprocess.lm
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@

preprocess-index-types := ();

preprocess := λprogram . (tail(
(preprocess-index-typedefs program)
(preprocess-apply-macros program)
));

preprocess-index-typedefs := λprogram . (tail(
(while program (
(preprocess-index-typedef (tail program))
(set program (head program))
))
));

preprocess-index-typedef := λterm . (match term (
()
( (Type( l ds )) (
(preprocess-index-indices( ds 0 ))
))
));

preprocess-index-indices := λdef index . (match def (
()
( (App( (App( tds (Variable '|) )) body )) (tail(
(preprocess-index-indices( tds (i2s(inc(s2i index))) ))
(preprocess-index-index( body index ))
)))
( body (
(preprocess-index-index( body index ))
))
));

preprocess-index-index := λbody index . (match body (
()
( (Literal tag) (tail(
(set preprocess-index-types (preprocess-index-types (tag index)))
)))
( (App( (Literal tag) args )) (tail(
(set preprocess-index-types (preprocess-index-types (tag index)))
)))
));

preprocess-index-of-tag := λtag . (tail(
(local indices)
(local index)
(set indices preprocess-index-types)
(while indices (
(if (eq( (head(tail indices)) tag )) (
(set index (tail(tail indices)))
) ())
(set indices (head indices))
))
index
));

substitute-macro-body := λkvs e . (match e (
()
((Variable n) (tail(
Expand Down Expand Up @@ -48,7 +103,24 @@ try-destructure-macro := λlhs e . (match (lhs e) (
(if (eq( pl el )) Accept ())
))
( ( (App( (Literal :Literal:) (Variable pv) )) (Literal el)) (
(Accept (KV( pv e )))
(if (preprocess-index-of-tag el)
()
(Accept (KV( pv e )))
)
))
( ( (App( (Literal :Tag:) (Variable pv) )) (Literal el)) (
(if (preprocess-index-of-tag el)
(Accept (KV( pv
(App(
(App(
(Literal :)
(Literal (preprocess-index-of-tag el))
))
(preprocess-restructure-type(parse-type( Constant+Literal+U64 )))
))
)))
()
)
))
( ( (App( (Literal :Variable:) (Variable pv) )) (Variable el)) (
(Accept (KV( pv e )))
Expand Down
2 changes: 1 addition & 1 deletion STDLIB/default-instruction-set.lm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fragment push := λ(: src GlobalVariable+Sized<size>). (: (
\t 'mov \s '0 \[ '%r15 \] , \s '%r15w \n
\t 'push \s '%r15 \n
))
(if-eq size 2 (
(if-eq size 1 (
\t 'mov \s '0 \[ '%r15 \] , \s '%r15b \n
\t 'push \s '%r15 \n
))
Expand Down
4 changes: 4 additions & 0 deletions STDLIB/default-rules.lm
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ macro ('match-pats-condition term (:Literal: l)) (
(==( term l ))
);

macro ('match-pats-condition term (:Tag: l)) (
(==( (.0( term )) l ))
);

25 changes: 15 additions & 10 deletions STRICT/cli.lm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import STDLIB/default-stdlib.lm;

import STRICT/utility.lm;

#config-strict := True;
#config-preprocess := True;
config-strict := Trueu8;
config-preprocess := Trueu8;
config-target := 'tmp.s_s;

type CompileMode ModeTokenize | ModeParse | ModeTypecheck | ModeCompile;
Expand All @@ -23,24 +23,29 @@ main := λ(: argc U64)(: argv U8[][]).(tail(
('--parse_s (set config-mode ModeParse))
('--typecheck_s (set config-mode ModeTypecheck))
('--compile_s (set config-mode ModeCompile))
# ('--strict_s (set config-strict True))
# ('--gradual_s (set config-strict False))
# ('--macro_s (set config-preprocess True))
# ('--nomacro_s (set config-preprocess False))
('--strict_s (set config-strict Trueu8))
('--gradual_s (set config-strict Falseu8))
('--macro_s (set config-preprocess Trueu8))
('--nomacro_s (set config-preprocess Falseu8))
('-o_s (tail(
(set argi (+( argi 1u64 )))
(set input (SCons(
(close input)
(close (SAtom([]( argv argi ))))
)))
)))
(fp (set input (SCons(
(close input)
(close (SAtom( fp )))
))))
(fp (tail(
(print fp)
(set input (SCons(
(close input)
(close (SAtom( fp )))
)))
)))
))
(set argi (+( argi 1u64 )))
))
(print Input:\s_s)(print input)(print \n_s)
(print Output:\s_s)(print config-target)(print \n_s)
(print Preprocess:\s_s)(print config-preprocess)(print \n_s)
(print Strict:\s_s)(print config-strict)(print \n_s)
));
Loading
Loading