Skip to content

Commit 219e732

Browse files
Merge pull request #1497 from andrew-johnson-4/infer-expr-allow-tree-edits
Infer expr allow tree edits
2 parents eb66997 + 8e7b30e commit 219e732

12 files changed

+33818
-33964
lines changed

BOOTSTRAP/cli.c

+33,647-33,711
Large diffs are not rendered by default.

SRC/assert-one-typed.lm

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
assert-one-typed := λ(: term AST). (: (
33
(if (non-zero(typeof term)) () (
4+
(print 'Assert\sOne\s_s)(print term)(print '\n_s)
45
(exit-error( 'Unable\sto\sinfer\stype\sof\sexpression_s term ))
56
))
67
) Nil);

SRC/index-definitions.lm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
type CompileMode ModeParse | ModePreprocess | ModeTypecheck | ModeCompile;
33

4-
type IsUsed Used | Unused | Tail | Return | Call | C;
4+
type IsUsed Used | Unused | Tail | Return | Call;
55
type IsScoped Scoped | Unscoped;
66

77
type FContext FCtxEOF | (FCtxBind( remainder:FContext[] , k:String , kt:Type , kv:Fragment )); zero FContext FCtxEOF;

SRC/index-types.lm

-1
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

-227
This file was deleted.

SRC/infer-global-context.lm

+2-1
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

+7
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
);
@@ -26,3 +30,6 @@ let mk-abs(l: AST, r: AST, t: Type): AST = (
2630
let mk-meta(l: AST): AST = (
2731
Meta{ close(l) }
2832
);
33+
34+
let mk-nil(): AST = ASTNil{};
35+
let mk-eof(): AST = ASTEOF{};

SRC/specialize.lm

+1-1
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

+13-9
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
);

0 commit comments

Comments
 (0)