Skip to content

Commit 9a91b9b

Browse files
Merge pull request #1449 from andrew-johnson-4/remove-more-fctx-lookup-fpqrrii
Remove more fctx lookup fpqrrii
2 parents 26663b1 + 48be9b6 commit 9a91b9b

File tree

6 files changed

+29248
-29187
lines changed

6 files changed

+29248
-29187
lines changed

BOOTSTRAP/cli.c

+29,209-29,157
Large diffs are not rendered by default.

PLUGINS/BACKEND/C/compile-c-function-args.lm

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ compile-c-function-args := λ(: ctx FContext)(: lhs AST). (: (
33
(let r SNil)
44
(match lhs (
55
()
6-
( (App( rst (App( (Lit( ':_s _ )) (App( (Var( k _ )) (AType kt) )) )) )) (
6+
( (App( rst (App( (Lit( ':_s _ )) (App( (@( v-t (Var( k _ )) )) (AType kt) )) )) )) (
77
(let decl (mangle-c-declaration kt))
88
(set r (compile-c-function-args(ctx rst)))
99
(set r (+( r (SAtom ',_s) )))
1010
(set r (+( r (.first decl) )))
1111
(set r (+( r (SAtom '\s_s) )))
12-
(let kf (.lookup( ctx k TAny lhs )))
13-
(set r (+( r (.get( kf 'expression_s)) )))
12+
(let def-bound (.lookup( std-c-fragment-context v-t (mk-fragment()) )))
13+
(set r (+( r (.get( def-bound 'expression_s)) )))
1414
(set r (+( r (.second decl) )))
1515
))
16-
( (App( (Lit( ':_s _ )) (App( (Var( k _ )) (AType kt) )) )) (
16+
( (App( (Lit( ':_s _ )) (App( (@( v-t (Var( k _ )) )) (AType kt) )) )) (
1717
(let decl (mangle-c-declaration kt))
1818
(set r (.first decl))
1919
(set r (+( r (SAtom '\s_s) )))
20-
(let kf (.lookup( ctx k TAny lhs )))
21-
(set r (+( r (.get( kf 'expression_s)) )))
20+
(let def-bound (.lookup( std-c-fragment-context v-t (mk-fragment()) )))
21+
(set r (+( r (.get( def-bound 'expression_s)) )))
2222
(set r (+( r (.second decl) )))
2323
))
2424
( _ () )

PLUGINS/BACKEND/C/compile-expr-direct.lm

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ compile-expr-direct := λ(: ctx FContext)(: term AST)(: stack-offset I64)(: used
1616
(set e (compile-expr( ctx t stack-offset Tail )))
1717
(set.context( e (close ctx) ))
1818
))
19-
( (App( (Var( 'open_s _ )) t )) (
19+
( (App( (@( o-t (Var( 'open_s _ )) )) t )) (
2020
(let tt (typeof t))
2121
(if (.is-t( tt 'Array_s )) (
2222
(match (.slot( tt 'Array_s )) (
@@ -25,14 +25,16 @@ compile-expr-direct := λ(: ctx FContext)(: term AST)(: stack-offset I64)(: used
2525
(set e (compile-expr( ctx t stack-offset Used )))
2626
) )
2727
( (TGround( 'Array_s (LCons( TAny (LCons( inner-tt LEOF )) )) )) (
28-
(set e (std-c-compile-call( ctx 'open_s (find-global-callable( 'open_s (typeof t) )) t )))
28+
(let fterm (.lookup( var-to-def-index o-t ASTEOF )))
29+
(set e (std-c-compile-call( ctx 'open_s fterm t )))
2930
))
3031
( (TGround( 'Array_s (LCons( array-length (LCons( inner-tt LEOF )) )) )) (
3132
(set e (compile-expr( ctx t stack-offset Used )))
3233
))
3334
))
3435
) (
35-
(set e (std-c-compile-call( ctx 'open_s (find-global-callable( 'open_s (typeof t) )) t )))
36+
(let fterm (.lookup( var-to-def-index o-t ASTEOF )))
37+
(set e (std-c-compile-call( ctx 'open_s fterm t )))
3638
))
3739
))
3840
( (App( (Var( 'sizeof_s _ )) (AType tt) )) (

PLUGINS/BACKEND/C/std-c-compile-call.lsts

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

22
let std-c-compile-call(ctx: FContext, fname: CString, fterm: AST, args: AST): Fragment = (
33
if typeof(fterm).is-t(c"Blob") {
4-
let f = ctx.lookup(fname, typeof(args), args);
54
let r = mk-fragment();
6-
match f.term {
7-
Abs{lhs=lhs, rhs=rhs} => (
5+
match fterm {
6+
Glb{val:Abs{lhs=lhs, rhs=rhs}} => (
87
(let callee-ctx, let caller-ctx) = std-c-compile-args(global-ctx, ctx, lhs, args);
98
r = blob-render(callee-ctx, rhs, r, 0);
109
r.context = close(caller-ctx);
1110
);
11+
_ => fail("Unexpected fterm in std-c-compile-call: \{fname}\n\{fterm}\n");
1212
}; r
1313
} else if typeof(fterm).is-t(c"Prop") { std-c-compile-expr(ctx, args, false)
1414
} else {
1515
let push-args = std-c-compile-push-args(ctx, args);
1616
let ictx = mk-fragment().set(c"function-id", SAtom{mangle-identifier(fname, typeof(fterm))});
1717
let inner-ctx = mk-fctx().bind(c"ictx", t1(c"ImplicitContext"), ictx)
1818
.bind(c"args", typeof(args), push-args);
19-
let f = ctx.lookup(c"primitive::call", t3(c"Cons",t1(c"ImplicitContext"),typeof(args)), args);
2019
let r = mk-fragment();
21-
match f.term {
22-
Abs{lhs=lhs, rhs=rhs} => (
20+
match find-global-callable(c"primitive::call", t3(c"Cons",t1(c"ImplicitContext"),typeof(args))) {
21+
Glb{val:Abs{lhs=lhs, rhs=rhs}} => (
2322
r = blob-render(inner-ctx, rhs, r, 0);
2423
r.context = close(ctx);
2524
);
25+
_ => fail("Unexpected fterm in std-c-compile-call: \{fname}\n\{fterm}\n");
2626
}; r
2727
}
2828
);

SRC/infer-expr.lm

+9-3
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,23 @@ infer-expr-one := λ(: tctx Maybe<TContext>)(: term AST)(: scoped IsScoped)(: hi
129129
(let weak-ctx (infer-expr( tctx r Scoped TAny Tail )))
130130
(ascript-normal( term (typeof r) ))
131131
))
132-
( (App( (Var( 'open_s _ )) r )) (
132+
( (App( (@( o-t (Var( 'open_s _ )) )) r )) (
133133
(set tctx (infer-expr( tctx r Unscoped TAny Used )))
134134
(let deref-type (typeof r))
135135
(match (.slot( deref-type 'Array_s )) (
136136
()
137137
( (TGround( 'Array_s (LCons( _ (LCons( TAny LEOF )) )) )) () )
138138
( (TGround( 'Array_s (LCons( TAny (LCons( array-base LEOF )) )) )) (
139+
(let def (defof-var( term tctx 'open_s deref-type )))
140+
(set var-to-def-index (.bind( var-to-def-index o-t def )))
139141
(maybe-specialize( 'open_s (typeof-var-raw( term tctx 'open_s )) deref-type ))
140142
(set deref-type array-base)
141143
))
142-
( _ (do-specialize( 'open_s (typeof-var-raw( term tctx 'open_s )) deref-type term )) )
144+
( _ (
145+
(let def (defof-var( term tctx 'open_s deref-type )))
146+
(set var-to-def-index (.bind( var-to-def-index o-t def )))
147+
(do-specialize( 'open_s (typeof-var-raw( term tctx 'open_s )) deref-type term ))
148+
))
143149
))
144150
(ascript-normal( term deref-type ))
145151
))
@@ -267,7 +273,7 @@ infer-expr-one := λ(: tctx Maybe<TContext>)(: term AST)(: scoped IsScoped)(: hi
267273
(let arg-type (typeof r))
268274
(if (&&( (non-zero(var-name-if-var l)) (.is-arrow(typeof l)) )) (
269275
(let def (defof-var( term tctx (var-name-if-var l) arg-type )))
270-
(set var-to-def-index (.bind( var-to-def-index term def )))
276+
(set var-to-def-index (.bind( var-to-def-index l def )))
271277
) ())
272278
))
273279
( (Abs( lhs rhs tlt )) (

SRC/typeof-var-raw.lm

+13-12
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,27 @@ defof-var := λ(: sloc AST)(: tctx Maybe<TContext>)(: vname String). (: (
5555

5656
defof-var := λ(: sloc AST)(: tctx Maybe<TContext>)(: vname String)(: tt Type). (: (
5757
(set vname (find-alias( vname tt )))
58-
(let f-type (typeof-var-raw( sloc tctx vname )))
59-
(set f-type (.function-type(apply( (var-name-if-var sloc) f-type tt false ))))
6058
(let found ASTEOF)
59+
(let found-type TAny)
6160
(let continue 1_u64)
6261
(for-each ( (Tuple( k vt def )) in
6362
(.get-or( tctx (: LEOF List<Tuple<String,Type,AST>>) )) ) (
6463
(if (&&( continue (==( k vname )) )) (
65-
(if (non-zero found) (
66-
(if (==( f-type vt )) (set found def) ())
67-
) (
68-
(set found def)
69-
))
70-
(if (not(.is-arrow vt)) (
71-
(set continue 0_u64)
72-
) ())
64+
(set found def)
65+
(set continue 0_u64)
7366
) ())
7467
))
7568
(for-each ((Tuple( kt t )) in (.lookup( global-type-context vname (: LEOF List<Tuple<Type,AST>>) ))) (
76-
(if (non-zero found) (
77-
(if (==( f-type kt )) (set found t) ())
69+
(if (.is-arrow kt) (
70+
(if (can-unify( (.domain kt) tt )) (
71+
(if (non-zero found-type) (
72+
(set found-type (most-special( found-type kt )))
73+
(if (==( found-type kt )) (set found t) ())
74+
) (
75+
(set found-type kt)
76+
(set found t)
77+
))
78+
) ())
7879
) (
7980
(set found t)
8081
))

0 commit comments

Comments
 (0)