Skip to content

Commit

Permalink
Merge pull request #624 from andrew-johnson-4/implicit-tail
Browse files Browse the repository at this point in the history
Implicit tail
  • Loading branch information
andrew-johnson-4 committed Jul 24, 2024
2 parents 02761c7 + c4823c8 commit 804d5e8
Show file tree
Hide file tree
Showing 45 changed files with 28,676 additions and 29,198 deletions.
54,813 changes: 27,145 additions & 27,668 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.15.24"
version = "1.15.25"
authors = ["Andrew <[email protected]>"]
license = "MIT"
description = "Compiler Backend / Programming Language Scaffolding"
Expand Down
48 changes: 24 additions & 24 deletions LIB/default-btree.lm
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
type BTreeIs<k,v> (BTreeIsBranch( U64 , k , v , BTreeIs<k,v>[] , BTreeIs<k,v>[] )) | BTreeIsEOF;
type BTreeEq<k,v> (BTreeEqBranch( U64 , k , v , BTreeEq<k,v>[] , BTreeEq<k,v>[] )) | BTreeEqEOF;

.lookup := λ(: index BTreeIs<k,v>)(: k k)(: default v). (: (tail(
.lookup := λ(: index BTreeIs<k,v>)(: k k)(: default v). (: (
(let th (hash k))
(let continue True_u8)
(while (==( continue True_u8 )) (
(let ih (.5 (as index Tag<BTreeIsBranch>)))
(if (==( th ih )) (
(if (is( k (.4 (as index Tag<BTreeIsBranch>)) )) (tail(
(if (is( k (.4 (as index Tag<BTreeIsBranch>)) )) (
(set default (.3 (as index Tag<BTreeIsBranch>)))
(set continue False_u8)
)) ())
) ())
) ())
(if (==( continue True_u8 )) (
(if (<( ih th )) (
Expand All @@ -30,18 +30,18 @@ type BTreeEq<k,v> (BTreeEqBranch( U64 , k , v , BTreeEq<k,v>[] , BTreeEq<k,v>[]
) ())
))
default
)) v);
) v);

.lookup := λ(: index BTreeEq<k,v>)(: k k)(: default v). (: (tail(
.lookup := λ(: index BTreeEq<k,v>)(: k k)(: default v). (: (
(let th (deep-hash k))
(let continue True_u8)
(while (==( continue True_u8 )) (
(let ih (.5 (as index Tag<BTreeEqBranch>)))
(if (==( th ih )) (
(if (==( k (.4 (as index Tag<BTreeEqBranch>)) )) (tail(
(if (==( k (.4 (as index Tag<BTreeEqBranch>)) )) (
(set default (.3 (as index Tag<BTreeEqBranch>)))
(set continue False_u8)
)) ())
) ())
) ())
(if (==( continue True_u8 )) (
(if (<( ih th )) (
Expand All @@ -60,58 +60,58 @@ type BTreeEq<k,v> (BTreeEqBranch( U64 , k , v , BTreeEq<k,v>[] , BTreeEq<k,v>[]
) ())
))
default
)) v);
) v);

.bind := λ(: index BTreeIs<k,v>[])(: k k)(: v v). (: (tail(
.bind := λ(: index BTreeIs<k,v>[])(: k k)(: v v). (: (
(let ht (hash k))
(let continue True_u8)
(let cell (close(BTreeIsBranch( ht k v (as 0_u64 BTreeIs<k,v>[]) (as 0_u64 BTreeIs<k,v>[]) ))))
(while (==( continue True_u8 )) (tail(
(while (==( continue True_u8 )) (
(let flat-index (open index))
(if (<( (.5 (as flat-index Tag<BTreeIsBranch>)) ht )) (
(if (==( (as (.1 (as flat-index Tag<BTreeIsBranch>)) U64) 0_u64 )) (tail(
(if (==( (as (.1 (as flat-index Tag<BTreeIsBranch>)) U64) 0_u64 )) (
(mov( (as cell U64) R8 ))
(set[]( (as index Field<Sized<8>,1>[]) 1_u64 R8 ))
(set continue False_u8)
)) (
) (
(set index (.1 (as flat-index Tag<BTreeIsBranch>)))
))
) (
(if (==( (as (.2 (as flat-index Tag<BTreeIsBranch>)) U64) 0_u64 )) (tail(
(if (==( (as (.2 (as flat-index Tag<BTreeIsBranch>)) U64) 0_u64 )) (
(mov( (as cell U64) R8 ))
(set[]( (as index Field<Sized<8>,1>[]) 2_u64 R8 ))
(set continue False_u8)
)) (
) (
(set index (.2 (as flat-index Tag<BTreeIsBranch>)))
))
))
)))
)) Nil);
))
) Nil);


.bind := λ(: index BTreeEq<k,v>[])(: k k)(: v v). (: (tail(
.bind := λ(: index BTreeEq<k,v>[])(: k k)(: v v). (: (
(let ht (deep-hash k))
(let continue True_u8)
(let cell (close(BTreeEqBranch( ht k v (as 0_u64 BTreeEq<k,v>[]) (as 0_u64 BTreeEq<k,v>[]) ))))
(while (==( continue True_u8 )) (tail(
(while (==( continue True_u8 )) (
(let flat-index (open index))
(if (<( (.5 (as flat-index Tag<BTreeEqBranch>)) ht )) (
(if (==( (as (.1 (as flat-index Tag<BTreeEqBranch>)) U64) 0_u64 )) (tail(
(if (==( (as (.1 (as flat-index Tag<BTreeEqBranch>)) U64) 0_u64 )) (
(mov( (as cell U64) R8 ))
(set[]( (as index Field<Sized<8>,1>[]) 1_u64 R8 ))
(set continue False_u8)
)) (
) (
(set index (.1 (as flat-index Tag<BTreeEqBranch>)))
))
) (
(if (==( (as (.2 (as flat-index Tag<BTreeEqBranch>)) U64) 0_u64 )) (tail(
(if (==( (as (.2 (as flat-index Tag<BTreeEqBranch>)) U64) 0_u64 )) (
(mov( (as cell U64) R8 ))
(set[]( (as index Field<Sized<8>,1>[]) 2_u64 R8 ))
(set continue False_u8)
)) (
) (
(set index (.2 (as flat-index Tag<BTreeEqBranch>)))
))
))
)))
)) Nil);
))
) Nil);

8 changes: 4 additions & 4 deletions LIB/default-cell.lm
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

type Cell<x> (Cell( x[] ));

cell := λ(: x x). (: (tail(
cell := λ(: x x). (: (
(let c (Cell( (close x) )))
c
)) Cell<x>);
) Cell<x>);

deref := λ(: c Cell<x>). (: (tail(
deref := λ(: c Cell<x>). (: (
(let x (open(.1(as c Tag<Cell>))))
x
)) x);
) x);

set[] := λ(: c Cell<x>)(: x x). (: (
(set[]( (.1(as c Tag<Cell>)) x ))
Expand Down
36 changes: 18 additions & 18 deletions LIB/default-list.lm
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@

type List<x> LEOF | (LCons( x , List<x>[] )); zero List<x> LEOF;

cons := λ(: hd x)(: tl List<x>). (: (tail(
cons := λ(: hd x)(: tl List<x>). (: (
(set tl (LCons( hd (close tl) )))
tl
)) List<x>);
) List<x>);

+ := λ(: hd List<x>)(: tl List<x>). (: (tail(
+ := λ(: hd List<x>)(: tl List<x>). (: (
(set hd (reverse hd))
(while (non-zero hd) (match hd (
()
( (LCons( hdhd tlhd )) (tail(
( (LCons( hdhd tlhd )) (
(set tl (cons( hdhd tl )))
(set hd tlhd)
)))
))
)))
tl
)) List<x>);
) List<x>);

.length := λ(: list List<x>). (: (tail(
.length := λ(: list List<x>). (: (
(let l 0_u64)
(while (non-zero list) (tail(
(while (non-zero list) (
(match list (
()
( (LCons( _ tl )) (set list tl) )
))
(set l (+( l 1_u64 )))
)))
))
l
)) U64);
) U64);

reverse := λ(: l List<x>). (: (tail(
reverse := λ(: l List<x>). (: (
(let r (: LEOF List<x>))
(while (non-zero l) (match l (
()
( (LCons( v rst )) (tail(
( (LCons( v rst )) (
(set r (LCons( v (close r) )))
(set l rst)
)))
))
)))
r
)) List<x>);
) List<x>);

print := λ(: l List<x>). (: (tail(
print := λ(: l List<x>). (: (
(print '[_s)
(let some False_u8)
(while (non-zero l) (match l (
()
( (LCons( v rst )) (tail(
( (LCons( v rst )) (
(if (==( some True_u8 )) (print ',_s) ())
(print v)
(set some True_u8)
(set l rst)
)))
))
)))
(print ']_s)
)) Nil);
) Nil);
Loading

0 comments on commit 804d5e8

Please sign in to comment.