Skip to content

Commit

Permalink
Merge pull request #154 from andrew-johnson-4/strict-cleanup-aisle2
Browse files Browse the repository at this point in the history
Strict cleanup aisle2
  • Loading branch information
andrew-johnson-4 authored Mar 17, 2024
2 parents 8c38cdd + 36e98cd commit 849041e
Show file tree
Hide file tree
Showing 15 changed files with 15,996 additions and 16,480 deletions.
32,169 changes: 15,892 additions & 16,277 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.24"
version = "1.11.25"
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 STDLIB/default-instruction-set.lm STDLIB/default-primitives.lm STDLIB/default-stdlib.lm STDLIB/default-rules.lm tests/nostd/printU64.lm
./production --nostd -o tmp.s STDLIB/default-instruction-set.lm STDLIB/default-primitives.lm STDLIB/default-rules.lm tests/nostd/normal_fib.lm
as -o tmp.o tmp.s
ld -o tmp tmp.o
./tmp && echo $?
Expand Down
42 changes: 0 additions & 42 deletions PRODUCTION/assemble.lm
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,6 @@ assemble-destructure-fragment := λctx lmb args offset . (match lmb (
( u (fail (UnrecgonizedDestructureFragment u)))
));

assemble-apply-fragment := λctx arrow args offset . (tail(
(local rc)
(set rc (assemble-destructure-fragment( ctx arrow args offset )))
(local base)
(set base (expr::new()))
(local rc1)
(set rc1 rc)
(while rc1 (
(set base (expr::set-prog (
base
( (expr::get-prog base) (expr::get-prog (tail (tail rc1))) )
)))
(set base (expr::set-data (
base
( (expr::get-data base) (expr::get-data (tail (tail rc1))) )
)))
(set base (expr::set-text (
base
( (expr::get-text base) (expr::get-text (tail (tail rc1))) )
)))
(set base (expr::set-frame (
base
( (expr::get-frame base) (expr::get-frame (tail (tail rc1))) )
)))
(set base (expr::set-unframe (
base
( (expr::get-unframe base) (expr::get-unframe (tail (tail rc1))) )
)))
(set rc1 (head rc1))
))
(local result)
(match arrow (
()
( (Lambda( lhs rhs )) (
(set result (fragment-apply-context( rc rhs base )))
(set result (expr::set-context( result ctx )))
(set result (expr::set-offset( result offset )))
))
))
result
));

assemble := λprogram . (
(local target)
(set target 'tmp.s)
Expand Down
42 changes: 1 addition & 41 deletions PRODUCTION/codegen-dynamic.lm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ compile-append := λoutput_e gctx e . (tail(
));

compile-expr := λctx e offset used . (
if config-strict (compile-expr-strict( ctx e offset used ))
if config-strict (compile-expr-strict( ctx e (if offset offset 0) used ))
(compile-expr-dynamic( ctx e offset used ))
);

Expand Down Expand Up @@ -271,9 +271,6 @@ apply-calling-convention-s := λ ctx e fname arg offset used . (tail(
(set prog ((expr::get-prog e1) (\t 'call \s mangledname \n)))
(Expr( (expr::get-frame e1) prog (expr::get-unframe e1) (expr::get-text e1) (expr::get-data e1) (expr::get-context e1) (expr::get-offset e1) ))
)))
( (Fragment( (Variable _) body )) (
(assemble-apply-fragment( ctx body arg offset ))
))
( () (
(fail (ReferenceToUndefinedVariable fname (typecheck-lookup-type arg)))
))
Expand Down Expand Up @@ -308,44 +305,7 @@ get-local := λctx v . (tail(
) ()
)
))
( (StackVariable( l offset ltype )) (
if r () (
if (eq(l v)) (
(local size)
(set size (typecheck-sizeof ltype))
# register allocation = '%r12, '%r13 only for now
(local dst)
(match size (
()
(1 (set dst ( R12B (And( Constant Reg8 )) )))
(2 (set dst ( R12W (And( Constant Reg16 )) )))
(4 (set dst ( R12D (And( Constant Reg32 )) )))
(8 (set dst ( R12 (And( Constant Reg64 )) )))
(u (fail (InvalidStackVariableSize u)))
))
(local arg_type)
(set arg_type (Cons( (And( Constant Offset )) (tail dst) )))
(match (get-maybe-function( ctx 'get arg_type )) (
()
( (Fragment( fname body )) (tail(
(local arg)
(set arg (
(App(
(App( (App( (Literal :) (Literal offset) ))
(App( (Literal Constant) (Literal Offset) ))
))
(App( (App( (Literal :) (Literal (head dst)) )) (Literal (tail dst)) ))
))
))
(set r (expr::get-prog (assemble-apply-fragment( ctx body arg () ))))
)))
(u (fail (UndefinedStackGetter 'get arg_type u)))
))
) ()
)
))
( (GlobalFunction( _ _ )) () )
( (Fragment( _ _ )) () )
( (Label( l luid )) (
if r () (
if (eq(l v)) (
Expand Down
71 changes: 31 additions & 40 deletions PRODUCTION/codegen-strict.lm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

compile-expr-strict := λctx e offset used . (tail(
(assert-typeof( 'compile-expr-strict::offset offset Atom ))
(assert-typeof( 'compile-expr-strict::used used Atom ))
(local e1)
(local e2)
(local e3)
Expand All @@ -8,16 +10,7 @@ compile-expr-strict := λctx e offset used . (tail(
()
(Return (tail(
(set e1 (compile-expr-strict( ctx e offset Used )))
(match (get-maybe-function(ctx 'cdecl::return (typecheck-lookup-type e))) (
()
( (Fragment( (Variable _) body )) (tail(
(set e2 (assemble-apply-fragment( ctx body e1 offset )))
e2
)))
( v (
(fail (ReferenceToUndefinedVariable 'cdecl::return (typecheck-lookup-type e)))
))
))
(fragment-apply( ctx 'cdecl::return (typecheck-lookup-type e) e1 ))
)))
(_ (
(match e (
Expand Down Expand Up @@ -64,7 +57,8 @@ compile-expr-strict := λctx e offset used . (tail(
))
(set svoffset (i2s (add( bti (s2i(expr::get-expr sv4)) )) ))
(set sv4 (expr::set-expr( sv4 svoffset )))
(set e4 (assemble-apply-fragment( ctx body (App( e2 sv4 )) offset )))
(fail (TODO AssembleApplyFragment 1))
#(set e4 (assemble-apply-fragment( ctx body (App( e2 sv4 )) offset )))
(set e3 (expr::set-frame( e3 ( (expr::get-frame e2) (expr::get-frame e3) (expr::get-frame e4) ))))
(set e3 (expr::set-unframe( e3 ( (expr::get-unframe e2) (expr::get-unframe e3) (expr::get-unframe e4) ))))
(set e3 (expr::set-text( e3 ( (expr::get-text e2) (expr::get-text e3) (expr::get-text e4) ))))
Expand All @@ -83,15 +77,7 @@ compile-expr-strict := λctx e offset used . (tail(
(set e2 (expr::new()))
))) (_ (
(set e2 (compile-expr-strict( ctx rhs offset Used )))
(match (get-maybe-function( ctx 'mov (Cons( (typecheck-lookup-type rhs) LocalVariable )) )) (
()
( (Fragment( (Variable _) body )) (
(set e3 (assemble-apply-fragment( ctx body (App( e2 (Variable lname) )) offset )))
))
( v (
(fail (ReferenceToUndefinedVariable 'mov (Cons( (typecheck-lookup-type rhs) LocalVariable )) ))
))
))
(fragment-apply( ctx 'mov (Cons( (typecheck-lookup-type rhs) LocalVariable )) (() e2) ))
))
))
(set e3 (expr::set-frame( e3 ( (expr::get-frame e1) (expr::get-frame e2) (expr::get-frame e3) ))))
Expand Down Expand Up @@ -176,7 +162,8 @@ apply-calling-convention-stack := λ ctx e fname arg offset used . (tail(
)))
( (Fragment( vname body )) (tail(
()
(set e (assemble-apply-fragment( ctx body arg offset )))
(fail (TODO AssembleApplyFragment 3))
#(set e (assemble-apply-fragment( ctx body arg offset )))
e
)))
( (StackVariable vname) (tail(
Expand Down Expand Up @@ -209,9 +196,11 @@ define-calling-convention-stack := λ ctx fname lmb . (tail(
(set text ( text (expr::get-unframe e2) ))
(set text ( text (\t 'ret \n) ))
(set text ( text (expr::get-text e2) ))
(Expr(
() () () text ( (expr::get-data e2) ) () ()
))
(local return)
(set return (expr::new()))
(set return (expr::set-text( return text )))
(set return (expr::set-data( return (expr::get-data e2) )))
return
)))
))
));
Expand All @@ -226,7 +215,8 @@ destructure-push-stack := λ ctx arg offset . (match arg (
(set e1 (compile-expr-strict( ctx arg offset Used )))
(local e2)
(set e2 (expr::set-expr( (expr::new()) (expr::get-expr e1) )))
(set e2 (assemble-apply-fragment( ctx body e2 offset )))
(fail (TODO AssembleApplyFragment 4))
#(set e2 (assemble-apply-fragment( ctx body e2 offset )))
(set e1 (expr::set-expr( e1 (expr::get-prog e2) )))
e1
)))
Expand Down Expand Up @@ -292,13 +282,13 @@ define-calling-convention-stack-destructure-args := λ ctx lhs offset . (match l
(set size (typecheck-sizeof ltype))
(local new_offset)
(set new_offset (add( offset (inv(s2i size)) )) )
(Expr(
() () () () ()
( ctx (StackVariable(
lname (i2s new_offset) ltype
)) )
(i2s new_offset)
))
(local return)
(set return (expr::new()))
(set return (expr::set-context( return
( ctx (StackVariable( lname (i2s new_offset) ltype )) )
)))
(set return (expr::set-offset( return (i2s new_offset) )))
return
)))
( (App( more (App( (App( (Literal :) (Variable lname) )) ltype )) )) (tail(
(set ltype (typecheck-infer-type-compound ltype))
Expand All @@ -307,13 +297,13 @@ define-calling-convention-stack-destructure-args := λ ctx lhs offset . (match l
(local new_offset)
(set new_offset (add( offset (inv(s2i size)) )) )
(set ctx (define-calling-convention-stack-destructure-args( ctx more new_offset )))
(Expr(
() () () () ()
( (expr::get-context ctx) (StackVariable(
lname (i2s new_offset) ltype
)) )
(expr::get-offset ctx)
))
(local return)
(set return (expr::new()))
(set return (expr::set-context( return
( ctx (StackVariable( lname (i2s new_offset) ltype )) )
)))
(set return (expr::set-offset( return (i2s new_offset) )))
return
)))
( u (fail (UnknownStackArg lhs)))
));
Expand All @@ -337,7 +327,8 @@ compile-fragment := λctx e offset used . (match e (
()
( (Fragment( (Variable _) body )) (tail(
()
(assemble-apply-fragment( ctx body arg offset ))
(fail (TODO AssembleApplyFragment 5))
#(assemble-apply-fragment( ctx body arg offset ))
)))
( v (
(fail (ReferenceToUndefinedOperator op (typecheck-lookup-type arg)))
Expand Down
6 changes: 3 additions & 3 deletions PRODUCTION/expression.lm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

expr::new := λ . (StrictExpr(() () () () () () () ()));
expr::new := λ . (StrictExpr(() () () () () () () 0));
expr::get-frame := λe . (match e (
()
((Expr(f p u t d pc off)) f)
Expand Down Expand Up @@ -36,8 +36,8 @@ expr::get-context := λe . (match e (
));
expr::get-offset := λe . (match e (
()
((Expr(f p u t d pc off)) off)
((StrictExpr(f u t d p e c o)) o)
((Expr(f p u t d pc off)) off )
((StrictExpr(f u t d p e c o)) o )
));
expr::set-frame := λe x . (
(StrictExpr(
Expand Down
7 changes: 4 additions & 3 deletions PRODUCTION/fragment.lm
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,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]> ))
# ( [(Atom,StrictExpr)], Atom, Type, [StrictExpr] ) -> StrictExpr
fragment-apply := λ ctx function-name function-type function-args . (tail(
(assert-typeof( 'fragment-apply::function-name function-name Atom ))
(assert-typeof( 'fragment-apply::function-args function-args List<StrictExpr> ))
(fail (TODO FragmentApply function-name function-type))
));
30 changes: 16 additions & 14 deletions PRODUCTION/utility.lm
Original file line number Diff line number Diff line change
Expand Up @@ -252,37 +252,37 @@ is-builtin := λf . (match f (



assert-eq := λ l r . (
assert-eq := λ loc l r . (
(if (deep-eq( l r )) () (
(print-s FailedAssertEqual)(print-s \n)
(print-s FailedAssertEqual)(print-s \s)(print-s 'in)(print-s \s)(print-s loc)(print-s \n)
(print-s \t)(print-s l)(print-s \n)
(print-s \t)(print-s r)(print-s \n)
(exit 1)
))
));

assert-typeof := λ term tt . (tail(
assert-typeof := λ loc term tt . (tail(
(set tt (parse-typeof tt))
(if (is-typeof( term tt )) () (
(print-s FailedAssertTypeof)(print-s \n)
(print-s FailedAssertTypeof)(print-s \s)(print-s 'in)(print-s \s)(print-s loc)(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(
assert-not-typeof := λ loc term tt . (tail(
(set tt (parse-typeof tt))
(if (is-typeof( term tt )) (
(print-s FailedAssertNotTypeof)(print-s \n)
(print-s FailedAssertNotTypeof)(print-s \s)(print-s 'in)(print-s \s)(print-s loc)(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) ))
(assert-eq( 'parse-parameter-typeof '< (head-string tt) ))
(set tt (tail-string tt))
(local inner)
(local depth)
Expand All @@ -295,9 +295,10 @@ parse-parameter-typeof := λ tt . (tail(
)))
('> (
(if depth (
(set inner (inner '>))
(set depth (dec depth))
) (
(assert-eq( () (tail-string tt) ))
(assert-eq( 'parse-parameter-typeof () (tail-string tt) ))
))
))
(c (set inner (inner (clone-rope c)) ))
Expand All @@ -308,7 +309,7 @@ parse-parameter-typeof := λ tt . (tail(
));

parse-tuple-typeof := λ tt . (tail(
(assert-eq( '[ (head-string tt) ))
(assert-eq( 'parse-tuple-typeof '[ (head-string tt) ))
(set tt (tail-string tt))
(local inner)
(local base)
Expand All @@ -322,9 +323,10 @@ parse-tuple-typeof := λ tt . (tail(
)))
('] (
(if depth (
(set inner (inner ']))
(set depth (dec depth))
) (
(assert-eq( () (tail-string tt) ))
(assert-eq( 'parse-tuple-typeof () (tail-string tt) ))
))
))
(', (tail(
Expand Down Expand Up @@ -362,14 +364,14 @@ parse-typeof := λ tt . (tail(
(while tt (
(match (head-string tt) (
()
('[ (
('[ (tail(
(set base (parse-tuple-typeof tt))
(set tt ())
))
('< (
)))
('< (tail(
(set base ( (clone-rope buff) (parse-parameter-typeof tt) ))
(set tt ())
))
)))
(c (set buff (buff (clone-rope c)) ))
))
(set tt (tail-string tt))
Expand Down
Loading

0 comments on commit 849041e

Please sign in to comment.