Skip to content

Commit bd2b8ad

Browse files
typecheck passed
1 parent 6b8a316 commit bd2b8ad

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

SRC/infer-global-terms.lsts

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
let infer-global-context-terms(term: AST): AST = (
2+
let infer-global-terms(term: AST): AST = (
33
match term {
44
Seq{} => (
55
let seqs = mk-vector(type(AST));
@@ -15,7 +15,7 @@ let infer-global-context-terms(term: AST): AST = (
1515
let def-i = seqs.length - 1;
1616
while def-i > 0 {
1717
let r = seqs[def-i];
18-
let new-r = infer-global-context-terms(r);
18+
let new-r = infer-global-terms(r);
1919
if not(is(r,new-r)) then { is-diff = true; seqs[def-i] = new-r; };
2020
def-i = def-i - 1;
2121
};
@@ -30,9 +30,10 @@ let infer-global-context-terms(term: AST): AST = (
3030
};
3131
}
3232
);
33-
Glb{rhs:Abs{}} => ();
33+
Glb{val:Abs{}} => ();
3434
Glb{k=key, rhs=val} => (
3535
(_, let new-rhs) = std-infer-expr((None :: TContext?), rhs, false, Used, TAny);
36+
if not(is(rhs,new-rhs)) then term = mk-glb(k, new-rhs);
3637
let kt = normalize(typeof(rhs)) && t1(c"GlobalVariable");
3738
global-type-context = global-type-context.bind(k.key, kt, term);
3839
mark-global-as-seen(k.key, kt, TAny);
@@ -43,33 +44,42 @@ let infer-global-context-terms(term: AST): AST = (
4344
}; term
4445
);
4546

46-
infer-global-context := λ(: td AST). (: (
47-
(match td (
48-
()
49-
( (Typedef( (Lit( base-type _ )) case-constructors )) (
50-
(let bt (parse-type base-type))
51-
(infer-type-definition( bt case-constructors 0_u64 )) ()
52-
))
53-
( (Typedef( (AType( bt )) case-constructors )) (
54-
(infer-type-definition( bt case-constructors 0_u64 )) ()
55-
))
56-
( (Glb( k (@( frhs (Abs( lhs (App( (Lit( ':_s _ )) (App( rhs (AType rhst) )) )) tlt )) )) )) (
57-
(if (.is-t( tlt 'TypedMacro_s )) (
58-
(bind-new-macro( (.key k) frhs ))
59-
) (
60-
(let lt (typeof-lhs lhs))
61-
(let return-type rhst)
62-
(let ft (t3( 'Arrow_s lt return-type )))
63-
(set ft (&&( ft tlt )))
64-
(if (&&( (.is-t( tlt 'Hook_s )) (not(.is-t( rhst 'Nil_s ))) )) (
65-
(exit-error( 'Hooks\sMust\sNot\sReturn\sValues._s td ))
66-
) ())
67-
(mark-global-as-seen( (.key k) ft tlt ))
68-
(ascript-normal( td ft ))
69-
(ascript-normal( frhs ft ))
70-
(set global-type-context (.bind( global-type-context (.key k) ft td )))
71-
))
72-
))
73-
( _ () )
74-
))
75-
) Nil);
47+
let infer-global-context(term: AST): Nil = (
48+
match term {
49+
Seq{} => (
50+
let seqs = mk-vector(type(AST));
51+
while term.is-seq { match term {
52+
Seq{l=left, r=right} => (
53+
seqs = seqs.push(r);
54+
if l.is-seq
55+
then term = l
56+
else (term = ASTEOF; seqs = seqs.push(l));
57+
);
58+
}};
59+
let def-i = seqs.length - 1;
60+
while def-i > 0 {
61+
infer-global-context(seqs[def-i]);
62+
def-i = def-i - 1;
63+
};
64+
);
65+
Typedef{ lhs:Lit{base-type=key}, case-constructors=rhs } => (
66+
# TODO: remove when LM frontend is removed
67+
let bt = parse-type(base-type);
68+
infer-type-definition(bt, case-constructors, 0);
69+
);
70+
Typedef{ lhs:AType{bt=tt}, case-constructors=rhs } => (
71+
infer-type-definition(bt, case-constructors, 0);
72+
);
73+
Glb{ k=key, frhs=val:Abs{lhs=lhs, rhs:App{left:Lit{key:c":"}, right:App{rhs=left, right:AType{return-type=tt}}}, misc-tt=tt} } => (
74+
if misc-tt.is-t(c"TypedMacro") then bind-new-macro(k.key, frhs)
75+
else {
76+
let ft = t3(c"Arrow", typeof-lhs(lhs), return-type) && misc-tt;
77+
mark-global-as-seen(k.key, ft, misc-tt);
78+
ascript-normal(term, ft);
79+
ascript-normal(frhs, ft);
80+
global-type-context = global-type-context.bind(k.key, ft, term);
81+
};
82+
);
83+
_ => ();
84+
}
85+
);

SRC/std-infer-expr.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let std-infer-expr(tctx: Maybe<TContext>, term: AST, is-scoped: Bool, used: IsUs
3737
);
3838
App{szof=left:Var{key:c"scope"}, r=right} => (
3939
(_, let new-r) = std-infer-expr(tctx, r, true, Tail, TAny);
40-
if not(is(r,new-r)) then { r = new-r; term = mk-app(sz-of, r); };
40+
if not(is(r,new-r)) then { r = new-r; term = mk-app(szof, r); };
4141
ascript-normal(term, typeof(r));
4242
);
4343
App{asc=left:Lit{key:c":"}, right:App{t=left,right:AType{tt=tt}}} => (
@@ -46,7 +46,7 @@ let std-infer-expr(tctx: Maybe<TContext>, term: AST, is-scoped: Bool, used: IsUs
4646
match t {
4747
Lit{} => ();
4848
_ => (
49-
(tctx, let new-t) = std-infer-expr(tctx, t, false, Tail, tt)
49+
(tctx, let new-t) = std-infer-expr(tctx, t, false, Tail, tt);
5050
if not(is(t,new-t)) then { t = new-t; term = mk-app(asc, mk-app(t, mk-atype(tt))); };
5151
);
5252
};

0 commit comments

Comments
 (0)