Skip to content

Strict tokenize 3 #233

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 11 commits into from
Apr 19, 2024
18,971 changes: 9,584 additions & 9,387 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.96"
version = "1.11.97"
authors = ["Andrew <andrew@subarctic.org>"]
license = "MIT"
description = "Lambda Mountain"
Expand Down
9 changes: 7 additions & 2 deletions PRODUCTION/codegen-strict.lm
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ compile-expr-strict := λctx e offset used . (tail(
( (Array( x '? )) (
(if (typecheck-unify-implies( x '? )) () (
(set deref True)
(set new-size (typecheck-sizeof x))
))
))
))
Expand Down Expand Up @@ -250,6 +251,8 @@ compile-expr-strict := λctx e offset used . (tail(
()
(True (set e1 (expr::set-expr( (expr::new ()) '1 ))))
(False (set e1 (expr::set-expr( (expr::new ()) '0 ))))
('\\o (set e1 (expr::set-expr( (expr::new ()) '35 ))))
('\\n (set e1 (expr::set-expr( (expr::new ()) '10 ))))
(_ (set e1 (expr::set-expr( (expr::new ()) lval ))))
))
))
Expand All @@ -275,6 +278,8 @@ compile-expr-strict := λctx e offset used . (tail(
()
(True (set e1 (expr::set-expr( (expr::new ()) '1 ))))
(False (set e1 (expr::set-expr( (expr::new ()) '0 ))))
('\\o (set e1 (expr::set-expr( (expr::new ()) '35 ))))
('\\n (set e1 (expr::set-expr( (expr::new ()) '10 ))))
(_ (set e1 (expr::set-expr( (expr::new ()) lval ))))
))
))
Expand Down Expand Up @@ -497,7 +502,7 @@ strict-codegen-type-case := λ ctx base-type type-body case-number . (tail(
(App( (Variable '.program) (
DontChain
(if (eq( case-padding 0 )) () (
\t 'sub \s '$ case-padding , \s '%r15 \n
\t 'sub \s '$ case-padding , \s '%rsp \n
))
(App( (Variable '.program) (Variable 'src) ))
\t 'mov \s '$ (Variable 'dst) , \s '%r15 \n
Expand Down Expand Up @@ -598,10 +603,10 @@ strict-codegen-type-case := λ ctx base-type type-body case-number . (tail(
(App( (Variable '.program) (
DontChain
\t 'mov \s '$ (Variable 'dst) , \s '%r15 \n
\t 'movq \s '$ case-number , \s 0 \[ '%r15 \] \n
(if (eq( case-padding 0 )) () (
\t 'sub \s '$ case-padding , \s '%r15 \n
))
\t 'movq \s '$ case-number , \s 0 \[ '%r15 \] \n
)))
))))
(typecheck-ascript( body ('->(
Expand Down
26 changes: 24 additions & 2 deletions STDLIB/default-instruction-set.lm
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ fragment push := λ(: src GlobalVariable+Sized<size>). (: (
(.program (
(\t 'mov \s '$ (.expression src) , \s '%r15 \n)
(for word-offset in (range( 0 (/( size 8 )) )) (
\t 'pushq \s '0 \[ '%r15 \] \n
\t 'add \s '$8 , \s '%r15 \n
\t 'pushq \s (+( (+( size -8 )) (inv(*( word-offset 8 ))) )) \[ '%r15 \] \n
))
(if-eq size 4 (
\t 'mov \s '0 \[ '%r15 \] , \s '%r15d \n
Expand Down Expand Up @@ -111,6 +110,29 @@ fragment push := λ(: src Reg64+Array<Sized<size>,max>)(: index Literal+Constant
))
))
) Nil);
fragment push := λ(: src LocalVariable+Array<Sized<size>,max>)(: index Literal+Constant). (: (
(.program (
\t 'mov \s (.expression src) \[ '%rbp \] , \s '%r15 \n
(for word-offset in (range( 0 (/( size 8 )) )) (
\t 'pushq \s (+(
(*( (.expression index) size ))
(+(
(+( size '-8 ))
(inv(*( word-offset 8 )))
))
)) \[ '%r15 \] \n
))
(if-eq size 4 (
\t 'pushq \s (+( (.expression src) (*( (.expression index) size )) )) \[ '%r15 \] \n
))
(if-eq size 2 (
\t 'pushq \s (+( (.expression src) (*( (.expression index) size )) )) \[ '%r15 \] \n
))
(if-eq size 1 (
\t 'pushq \s (+( (.expression src) (*( (.expression index) size )) )) \[ '%r15 \] \n
))
))
) Nil);

fragment pop := λ(: src LocalVariable+Sized<size>). (: (
(.program ( for word-offset in (range( 1 (+( (/( size 8 )) 1 )) )) (
Expand Down
54 changes: 27 additions & 27 deletions STDLIB/default-primitives.lm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

fragment type U8; size U8 1; atom suffix U8 u8;
fragment type U16; size U16 2; atom suffix U16 u16;
fragment type U32; size U32 4; atom suffix U32 u32;
fragment type U64; size U64 8; atom suffix U64 u64;
fragment type I8; size I8 1; atom suffix I8 i8;
fragment type I16; size I16 2; atom suffix I16 i16;
fragment type I32; size I32 4; atom suffix I32 i32;
fragment type I64; size I64 8; atom suffix I64 i64;
fragment type ASCII; size ASCII 1; atom suffix ASCII _c;
fragment type U8; size U8 1; atom suffix U8 _u8;
fragment type U16; size U16 2; atom suffix U16 _u16;
fragment type U32; size U32 4; atom suffix U32 _u32;
fragment type U64; size U64 8; atom suffix U64 _u64;
fragment type I8; size I8 1; atom suffix I8 _i8;
fragment type I16; size I16 2; atom suffix I16 _i16;
fragment type I32; size I32 4; atom suffix I32 _i32;
fragment type I64; size I64 8; atom suffix I64 _i64;
fragment type ASCII; size ASCII 1; atom suffix ASCII _c;
fragment type String; size String 8; atom suffix String _s;

fragment [] := λ(: l GlobalVariable+Array<x,?>)(: r GlobalVariable+U64). (: (
Expand Down Expand Up @@ -60,12 +60,12 @@ fragment > := λ(: l LocalVariable+U64)(: r Constant+U64). (: (

< := λ(: l U64)(: r U64). (: (tail(
(gensym-label end)
(mov( 1u64 RAX ))
(mov( 1_u64 RAX ))
(mov( l R8 ))
(mov( r R9 ))
(cmp( R9 R8 ))
(jb end)
(mov( 0u64 RAX ))
(mov( 0_u64 RAX ))
(label end)
(as RAX U64)
)) U64);
Expand Down Expand Up @@ -122,10 +122,10 @@ fragment - := λ(: l GlobalVariable+U64)(: r Constant+U64). (: (
(je end-true)
(jmp end-false)
(label end-true)
(mov( 1u64 RAX ))
(mov( 1_u64 RAX ))
(jmp end)
(label end-false)
(mov( 0u64 RAX ))
(mov( 0_u64 RAX ))
(jmp end)
(label end)
(pop R15)
Expand All @@ -144,10 +144,10 @@ fragment - := λ(: l GlobalVariable+U64)(: r Constant+U64). (: (
(je end-true)
(jmp end-false)
(label end-true)
(mov( 1u64 RAX ))
(mov( 1_u64 RAX ))
(jmp end)
(label end-false)
(mov( 0u64 RAX ))
(mov( 0_u64 RAX ))
(jmp end)
(label end)
(pop R15)
Expand All @@ -166,10 +166,10 @@ fragment - := λ(: l GlobalVariable+U64)(: r Constant+U64). (: (
(je end-true)
(jmp end-false)
(label end-true)
(mov( 1u64 RAX ))
(mov( 1_u64 RAX ))
(jmp end)
(label end-false)
(mov( 0u64 RAX ))
(mov( 0_u64 RAX ))
(jmp end)
(label end)
(pop R15)
Expand All @@ -188,10 +188,10 @@ fragment - := λ(: l GlobalVariable+U64)(: r Constant+U64). (: (
(je end-true)
(jmp end-false)
(label end-true)
(mov( 1u64 RAX ))
(mov( 1_u64 RAX ))
(jmp end)
(label end-false)
(mov( 0u64 RAX ))
(mov( 0_u64 RAX ))
(jmp end)
(label end)
(pop R15)
Expand All @@ -212,10 +212,10 @@ fragment - := λ(: l GlobalVariable+U64)(: r Constant+U64). (: (
(je end-true)
(jmp end-false)
(label end-true)
(mov( 1u64 RAX ))
(mov( 1_u64 RAX ))
(jmp end)
(label end-false)
(mov( 0u64 RAX ))
(mov( 0_u64 RAX ))
(jmp end)
(label end)
(pop R15)
Expand All @@ -234,10 +234,10 @@ fragment - := λ(: l GlobalVariable+U64)(: r Constant+U64). (: (
(je end-true)
(jmp end-false)
(label end-true)
(mov( 1u64 RAX ))
(mov( 1_u64 RAX ))
(jmp end)
(label end-false)
(mov( 0u64 RAX ))
(mov( 0_u64 RAX ))
(jmp end)
(label end)
(pop R15)
Expand All @@ -256,10 +256,10 @@ fragment - := λ(: l GlobalVariable+U64)(: r Constant+U64). (: (
(je end-true)
(jmp end-false)
(label end-true)
(mov( 1u64 RAX ))
(mov( 1_u64 RAX ))
(jmp end)
(label end-false)
(mov( 0u64 RAX ))
(mov( 0_u64 RAX ))
(jmp end)
(label end)
(pop R15)
Expand All @@ -278,10 +278,10 @@ fragment - := λ(: l GlobalVariable+U64)(: r Constant+U64). (: (
(je end-true)
(jmp end-false)
(label end-true)
(mov( 1u64 RAX ))
(mov( 1_u64 RAX ))
(jmp end)
(label end-false)
(mov( 0u64 RAX ))
(mov( 0_u64 RAX ))
(jmp end)
(label end)
(pop R15)
Expand Down
Loading
Loading