1
1
2
- let infer-global-context- terms(term: AST): AST = (
2
+ let infer-global-terms(term: AST): AST = (
3
3
match term {
4
4
Seq{} => (
5
5
let seqs = mk-vector(type(AST));
@@ -15,7 +15,7 @@ let infer-global-context-terms(term: AST): AST = (
15
15
let def-i = seqs.length - 1;
16
16
while def-i > 0 {
17
17
let r = seqs[def-i];
18
- let new-r = infer-global-context- terms(r);
18
+ let new-r = infer-global-terms(r);
19
19
if not(is(r,new-r)) then { is-diff = true; seqs[def-i] = new-r; };
20
20
def-i = def-i - 1;
21
21
};
@@ -30,9 +30,10 @@ let infer-global-context-terms(term: AST): AST = (
30
30
};
31
31
}
32
32
);
33
- Glb{rhs :Abs{}} => ();
33
+ Glb{val :Abs{}} => ();
34
34
Glb{k=key, rhs=val} => (
35
35
(_, 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);
36
37
let kt = normalize(typeof(rhs)) && t1(c"GlobalVariable");
37
38
global-type-context = global-type-context.bind(k.key, kt, term);
38
39
mark-global-as-seen(k.key, kt, TAny);
@@ -43,33 +44,42 @@ let infer-global-context-terms(term: AST): AST = (
43
44
}; term
44
45
);
45
46
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
+ );
0 commit comments