Skip to content

Commit 0512a2b

Browse files
OK
1 parent 2ad5b13 commit 0512a2b

File tree

9 files changed

+30099
-30121
lines changed

9 files changed

+30099
-30121
lines changed

BOOTSTRAP/cli.c

Lines changed: 30063 additions & 30065 deletions
Large diffs are not rendered by default.

SRC/index-types.lm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import SRC/quick-prop.lsts;
55

66
import SRC/substitute.lm;
77
import SRC/cons-root.lsts;
8-
import SRC/infer-expr.lm;
98
import SRC/is-special.lm;
109
import SRC/global-is-seen.lm;
1110
import SRC/index-of-tag.lm;

SRC/infer-expr.lm

Lines changed: 0 additions & 38 deletions
This file was deleted.

SRC/infer-global-context.lm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ infer-global-context-2 := λ(: td AST). (: (
3737
( (Glb( k (@( frhs (Abs( lhs (App( (Lit( ':_s _ )) (App( rhs (AType rhst) )) )) tlt )) )) )) (
3838
))
3939
( (Glb( k rhs )) (
40-
(infer-expr( (: None Maybe<TContext>) rhs Unscoped TAny Used ))
40+
(let tctx-rhs (std-infer-expr( (: None Maybe<TContext>) rhs false Used TAny )))
41+
# TODO: make this rewrite terms if the subtree has changes
4142
(let rhst (normalize(typeof rhs)))
4243
(let kt (&&( rhst (t1 'GlobalVariable_s) )))
4344
(set global-type-context (.bind( global-type-context (.key k) kt td )))

SRC/mk-app.lsts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ let mk-app(f: AST, a: AST): AST = (
33
App{ close(f), close(a) }
44
);
55

6+
let mk-cons-or-app(is-cons: U64, f: AST, a: AST): AST = (
7+
App{ is-cons, close(f), close(a) }
8+
);
9+
610
let mk-cons(f: AST, a: AST): AST = (
711
App{ true, close(f), close(a) }
812
);

SRC/specialize.lm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ specialize := λ(: key String)(: ft Type)(: unify-ctx Maybe<TContext>)(: result-
1515
(mark-as-special( key result-type ))
1616
(let special-term (substitute( unify-ctx term )))
1717
(infer-global-context( special-term ))
18-
(infer-expr( (: None Maybe<TContext>) special-term Unscoped (t1 'Specialize_s) Used ))
18+
(let tctx-special (std-infer-expr( (: None Maybe<TContext>) special-term false Used TAny )))
1919
(set global-type-context (.bind( global-type-context key (typeof special-term) special-term )))
2020
(set ast-parsed-program (Seq(
2121
(close ast-parsed-program)

SRC/std-apply-macro.lsts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let std-apply-macro(tctx: Maybe<TContext>, mname: CString, margs: AST): (TContex
1919
peeped = mtype;
2020
};
2121
};
22-
let peeped-type = std-infer-peeped-arguments(tctx, margs, peep-holes);
22+
(let peeped-type, _) = std-infer-peeped-arguments(tctx, margs, peep-holes);
2323

2424
let matched = [] :: List<(Type,AST)>;
2525
for Tuple{mtype=first, mterm=third} in row {
@@ -45,20 +45,24 @@ let std-apply-macro(tctx: Maybe<TContext>, mname: CString, margs: AST): (TContex
4545
std-apply-macro-candidates(tctx, mname, margs, candidates);
4646
);
4747

48-
let std-infer-peeped-arguments(tctx: Maybe<TContext>, t: AST, peep: Type): Type = (
48+
let std-infer-peeped-arguments(tctx: Maybe<TContext>, t: AST, peep: Type): (Type, AST) = (
4949
match peep {
5050
TGround{tag:c"Cons", parameters:[p2.. p1..]} => (
5151
match t {
52-
App{left=left, right=right} => (
53-
t3(c"Cons",
54-
std-infer-peeped-arguments(tctx, left, p1),
55-
std-infer-peeped-arguments(tctx, right, p2)
56-
)
52+
App{is-cons=is-cons, left=left, right=right} => (
53+
(let lt, let new-left) = std-infer-peeped-arguments(tctx, left, p1);
54+
(let rt, let new-right) = std-infer-peeped-arguments(tctx, right, p2);
55+
if not(is(left,new-left)) || not(is(right,new-right))
56+
then t = mk-cons-or-app(is-cons,new-left,new-right);
57+
(t3(c"Cons",lt,rt), t)
5758
);
5859
_ => fail("std-infer-peeped-arguments expected cons term: \{t}\n");
5960
}
6061
);
61-
TAny{} => ta;
62-
_ => ( infer-expr(tctx, t, Unscoped, TAny, Used); typeof(t) );
62+
TAny{} => (ta, t);
63+
_ => (
64+
(_, t) = std-infer-expr(tctx, t, false, Used, TAny);
65+
(typeof(t), t);
66+
);
6367
}
6468
);

SRC/std-infer-expr.lsts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,21 @@ let std-infer-expr(tctx: Maybe<TContext>, term: AST, is-scoped: Bool, used: IsUs
7676
Meta{} => ascript-normal(term, t1(c"Nil"));
7777
Typedef{} => ();
7878
AType{tt=tt} => ascript-normal(term, tt);
79-
Seq{left=left, right=right} => (
80-
(tctx, let new-left) = std-infer-expr(tctx, left, false, Used, TAny);
81-
(tctx, let new-right) = std-infer-expr(tctx, right, false, Used, TAny);
82-
if not(is(left,new-left)) || not(is(right,new-right))
83-
then term = mk-seq(new-left, new-right);
79+
Seq{} => (
80+
let seqs = [] :: List<AST>;
81+
while term.is-seq { match term {
82+
Seq{l=left, r=right} => (
83+
(tctx, r) = std-infer-expr(tctx, r, false, Used, hint);
84+
seqs = cons(r,seqs);
85+
term = l;
86+
);
87+
}};
88+
term = ASTEOF;
89+
for r in seqs {
90+
if non-zero(term)
91+
then term = mk-seq(term, r)
92+
else term = r
93+
};
8494
);
8595
Glb{key=key, val=val} => (
8696
# TODO: remove after infer-expr.lm is ported

SRC/typecheck.lm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typecheck := λ. (: (
2424
(set ordered-type-exprs rst)
2525
))
2626
)))
27-
(infer-expr( (: None Maybe<TContext>) ast-parsed-program Unscoped TAny Used ))
27+
(let tctx-ast (std-infer-expr( (: None Maybe<TContext>) ast-parsed-program false Used TAny )))
2828
(while (non-zero stack-to-specialize) (match stack-to-specialize (
2929
()
3030
( (LCons( (StackToSpecialize( function-name ft unify-ctx special-type )) rst )) (

0 commit comments

Comments
 (0)