Skip to content

Commit

Permalink
Merge pull request #153 from andrew-johnson-4/fragment-cleanup-aisle1
Browse files Browse the repository at this point in the history
Fragment cleanup aisle1
  • Loading branch information
andrew-johnson-4 authored Mar 16, 2024
2 parents 99a45b0 + 185d40c commit 0f11e31
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 8 deletions.
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.23"
version = "1.11.24"
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,5 +1,5 @@

unit-tests:
unit-tests: prod
cargo test unit_test_suite -- --nocapture

nostd: prod
Expand Down
6 changes: 6 additions & 0 deletions PRODUCTION/fragment.lm
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ fragment-apply-context := λctx fragment-rhs e . (match fragment-rhs (
))
( u (fail (UnknownSubstituteFragment fragment-rhs)))
));

# ( [(String,StrictExpr)], String, Type, [StrictExpr] ) -> StrictExpr
fragment-apply := λctx function-name function-type function-args . (tail(
(assert-typeof( ctx List<[Atom,StrictExpr]> ))
(fail (TODO FragmentApply function-name function-type))
));
150 changes: 146 additions & 4 deletions PRODUCTION/utility.lm
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,153 @@ is-builtin := λf . (match f (



assert-eq := λ msg l r . (
(if (deep-eq( l r)) () (
(print-s AssertNotEqual)(print-s \n)
assert-eq := λ l r . (
(if (deep-eq( l r )) () (
(print-s FailedAssertEqual)(print-s \n)
(print-s \t)(print-s l)(print-s \n)
(print-s \t)(print-s r)(print-s \n)
(print-s \t)(fail msg)
(exit 1)
))
));

assert-typeof := λ term tt . (tail(
(set tt (parse-typeof tt))
(if (is-typeof( term tt )) () (
(print-s FailedAssertTypeof)(print-s \n)
(print-s \t)(print-s tt)(print-s \n)
(print-s \t)(print-s term)(print-s \n)
(exit 1)
))
));

assert-not-typeof := λ term tt . (tail(
(set tt (parse-typeof tt))
(if (is-typeof( term tt )) (
(print-s FailedAssertNotTypeof)(print-s \n)
(print-s \t)(print-s tt)(print-s \n)
(print-s \t)(print-s term)(print-s \n)
(exit 1)
) ())
));

parse-parameter-typeof := λ tt . (tail(
(assert-eq( '< (head-string tt) ))
(set tt (tail-string tt))
(local inner)
(local depth)
(while tt (
(match (head-string tt) (
()
('< (tail(
(set inner (inner '<))
(set depth (inc depth))
)))
('> (
(if depth (
(set depth (dec depth))
) (
(assert-eq( () (tail-string tt) ))
))
))
(c (set inner (inner (clone-rope c)) ))
))
(set tt (tail-string tt))
))
(parse-typeof (clone-rope inner))
));

parse-tuple-typeof := λ tt . (tail(
(assert-eq( '[ (head-string tt) ))
(set tt (tail-string tt))
(local inner)
(local base)
(local depth)
(while tt (
(match (head-string tt) (
()
('[ (tail(
(set inner (inner '[))
(set depth (inc depth))
)))
('] (
(if depth (
(set depth (dec depth))
) (
(assert-eq( () (tail-string tt) ))
))
))
(', (tail(
(if depth (
(set inner (inner ',))
) (
(set inner (parse-typeof (clone-rope inner) ))
(if base (
(set base ('[] ( base inner )))
) (
(set base inner)
))
(set inner ())
))
)))
(c (set inner (inner (clone-rope c)) ))
))
(set tt (tail-string tt))
))
(if base (
(set base ('[] ( base (parse-typeof (clone-rope inner )) )))
) (
(set base (parse-typeof (clone-rope inner)))
))
base
));

parse-typeof := λ tt . (tail(
(local buff)
(local base)
(if (is-cons tt) (
(set base tt)
(set tt ())
) ())
(while tt (
(match (head-string tt) (
()
('[ (
(set base (parse-tuple-typeof tt))
(set tt ())
))
('< (
(set base ( (clone-rope buff) (parse-parameter-typeof tt) ))
(set tt ())
))
(c (set buff (buff (clone-rope c)) ))
))
(set tt (tail-string tt))
))
(if base base (clone-rope buff))
));

is-typeof := λ term tt . (match tt (
()
( Nil (not term) )
( Atom (is-atom term) )
( Cons (is-cons term) )
( (List te) (
(if (is-cons term) (
(if (is-typeof( (tail term) te )) (
(is-typeof( (head term) tt ))
) ())
) (
(not term)
))
))
( ('[] ( lt rt )) (
(if (is-cons term) (
(if (is-typeof( (head term) lt )) (
(is-typeof( (tail term) rt ))
) ())
) ())
))
( (l r) (fail (UnknownTypeofType tt)))
( () (fail (UnknownTypeofType tt)))
( label (eq( (head term) label )) )
));
3 changes: 2 additions & 1 deletion tests/b_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn compile_compiler() {
.stderr(std::process::Stdio::piped())
.arg("-o")
.arg("production.s")
.arg("PRODUCTION/cli.lm")
.spawn()
.expect("failed to execute process")
.wait_with_output()
Expand Down Expand Up @@ -87,13 +88,13 @@ fn compile_compiler() {
}

fn run_unit(unit: &str) {
println!("Run unit test {}", unit);
let exit = Command::new("./production")
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.arg("-o")
.arg("unit.s")
.arg(unit)
.arg("PRODUCTION/utility.lm")
.spawn()
.expect("failed to execute process")
.wait_with_output()
Expand Down
47 changes: 46 additions & 1 deletion tests/unit/utility.lm
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@

import PRODUCTION/utility.lm;

(assert-eq( LiteralEquality True True ));
(assert-eq( True True ));

(assert-eq( (parse-typeof Nil) Nil ));
(assert-eq( (parse-typeof Atom) Atom ));
(assert-eq( (parse-typeof List<Atom>) (List Atom) ));
(assert-eq( (parse-typeof List<List<Atom>>) (List (List Atom)) ));
(assert-eq( (parse-typeof [Atom,Nil]) ('[] (Atom Nil)) ));
(assert-eq( (parse-typeof [Atom,Nil,Cons]) ([] (([] (Atom Nil)) Cons)) ));

(assert-eq( (parse-typeof [Atom,List<[Cons,Nil]>]) ([] (Atom (List ([] (Cons Nil))))) ));

(assert-typeof( () Nil ));
(assert-not-typeof( 1 Nil ));
(assert-not-typeof( (1 2) Nil ));

(assert-typeof( 1 Atom ));
(assert-not-typeof( () Atom ));
(assert-not-typeof( (1 2) Atom ));

(assert-typeof( (1 2) Cons ));
(assert-not-typeof( 1 Cons ));
(assert-not-typeof( () Cons ));

(assert-typeof( (StrictExpr ()) StrictExpr ));
(assert-not-typeof( (StrictExpr ()) Expr ));
(assert-not-typeof( (StrictExpr ()) Nil ));
(assert-not-typeof( (StrictExpr ()) Atom ));

(assert-typeof( () (List Atom) ));
(assert-typeof( () List<Atom> ));
(assert-typeof( ((() 1) 2) List<Atom> ));
(assert-not-typeof( ((() 1) 2) List<Cons> ));
(assert-not-typeof( ((() 1) 2) List<Nil> ));

(assert-typeof( () List<[Atom,Nil]> ));
(assert-typeof( ((() (1 ()) ) (2 ()) ) List<[Atom,Nil]> ));
(assert-not-typeof( ((() (1 ()) ) (2 ()) ) List<[Nil,Nil]> ));
(assert-not-typeof( ((() (1 ()) ) (2 ()) ) List<[Atom,Atom]> ));

(assert-typeof( () List<List<Atom>> ));
(assert-typeof( ( () (() '1) ) List<List<Atom>> ));
(assert-not-typeof( ( () (() '1) ) List<List<Nil>> ));
(assert-not-typeof( ( () (() '1) ) List<Atom> ));

(assert-typeof( ( (1 2) () ) [Atom,Atom,Nil] ));
(assert-not-typeof( ( (1 2) () ) [Atom,Nil,Nil] ));

0 comments on commit 0f11e31

Please sign in to comment.