Skip to content

Commit cef0088

Browse files
authored
Merge pull request #1962 from andrew-johnson-4/more-lmcommon-fdslwelwl
More lmcommon fdslwelwl
2 parents 3dad808 + 5db7cd9 commit cef0088

22 files changed

Lines changed: 2894 additions & 3091 deletions

BOOTSTRAP/cli.c

Lines changed: 2739 additions & 2787 deletions
Large diffs are not rendered by default.

LM23COMMON/prop-is-lone-tag.lsts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
let lone-index = {} : Hashtable<CString,Bool>;
3+
4+
let index-lone-tag(tag: CString): Nil = lone-index = lone-index.bind(tag,true);
5+
let is-lone-tag(tag: CString): Bool = lone-index.lookup(tag,false);

LM23COMMON/type-with-only-phi.lsts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
let .with-only-phi(tt: Type): Type = tt.slot(c"Phi::State",1).l1;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
let substitute-lhs(tctx: TypeContext?, t: AST): AST = substitute-lhs(tctx, t, 0);
3+
4+
let substitute-lhs(tctx: TypeContext?, t: AST, idx: U64): AST = (
5+
match t {
6+
App{ ps=left, right:App{ left:Lit{key:c":",ctk=token}, right:App{ left:Var{v1=key,vtk1=token}, right:AType{vt1=tt} } } } => (
7+
vt1 = substitute-macro(tctx, vt1.accept-interface(idx)).expand-implied-phi.without-phi-keep-state;
8+
mk-app( substitute-lhs(tctx,ps,idx+1),
9+
mk-app( mk-lit(c":",ctk.unique), mk-app(
10+
mk-var(v1,vtk1.unique), mk-atype(vt1)
11+
))
12+
)
13+
);
14+
App{ left:Lit{key:c":",ctk=token}, right:App{ left:Var{v2=key,vtk2=token}, right:AType{vt2=tt} } } => (
15+
vt2 = substitute-macro(tctx, vt2.accept-interface(idx)).expand-implied-phi.without-phi-keep-state;
16+
mk-app( mk-lit(c":",ctk.unique), mk-app(
17+
mk-var(v2,vtk2.unique), mk-atype(tctx.substitute(vt2.accept-interface(idx)))
18+
))
19+
);
20+
App{ ps=left, right:Var{v3=key,vtk3=token} } => mk-app(substitute-lhs(tctx,ps),mk-var(v3,vtk3.unique));
21+
Var{v4=key,vtk4=token} => mk-var(v4,vtk4.unique);
22+
ASTNil{} => t;
23+
}
24+
);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
let substitute(tctx: TypeContext?, t: AST): AST = substitute(tctx,t,false);
3+
4+
let substitute(tctx: TypeContext?, t: AST, is-return: Bool): AST = (
5+
match t {
6+
ASTEOF{} => t;
7+
ASTNil{} => t;
8+
App{ left:Lit{key:c":",ctk=token}, right:App{ left:Var{v1=key,vtk1=token}, right:AType{vt1=tt} } } => (
9+
vt1 = substitute-macro(tctx, vt1).expand-implied-phi.without-phi-keep-state;
10+
t = mk-app( mk-lit(c":",ctk.unique), mk-app(mk-var(v1,vtk1.unique), mk-atype(vt1)) );
11+
let found = false;
12+
for TypeContextRow{tk1=key,ta=def} in tctx.get-or(mk-tctx()).tctx {
13+
if not(found) and tk1==v1 {
14+
t = mk-app( mk-lit(c":",ctk.unique), mk-app(substitute(tctx,ta), mk-atype(vt1)) );
15+
found = true;
16+
}
17+
}; t
18+
);
19+
App{ left:Lit{key:c":",ctk=token}, right:App{ inner-t=left, right:AType{vt2=tt} } } => (
20+
vt2 = substitute-macro(tctx, vt2).expand-implied-phi.without-phi-keep-state;
21+
mk-app( mk-lit(c":",ctk.unique), mk-app(substitute(tctx, inner-t), mk-atype(vt2)) );
22+
);
23+
Lit{v2=key,vtk2=token} => mk-lit(v2,vtk2.unique);
24+
Var{v3=key,vtk3=token} => mk-var(v3,vtk3.unique);
25+
Abs{lhs=lhs,rhs=rhs,tt1=tt} => mk-abs(substitute-lhs(tctx,lhs),substitute(tctx,rhs,true),tctx.substitute(tt1));
26+
AType{tt2=tt} => mk-atype(tctx.substitute(tt2).sanitize-phi);
27+
App{is-cons=is-cons,lt=left,rt=right} => mk-cons-or-app(is-cons,substitute(tctx,lt),substitute(tctx,rt));
28+
Seq{seq=seq} => (
29+
t = mk-eof();
30+
for s in seq { t = t + substitute(tctx,s); };
31+
t
32+
);
33+
Glb{k=key, rt=val} => (
34+
let found = false;
35+
for TypeContextRow{tk2=key,ta=def} in tctx.get-or(mk-tctx()).tctx {
36+
if not(found) and k.key==tk2 {
37+
match ta {
38+
Var{tvtk=token} => k = tvtk;
39+
_ => ();
40+
};
41+
found = true;
42+
}
43+
};
44+
mk-glb(k.unique,substitute(tctx,rt))
45+
);
46+
}
47+
);
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
let try-destructure-macro(loc: SourceLocation, lhs: AST, term: AST): AContext? = (
3+
let r = None : AContext?;
4+
let yes = Some([] : AContext);
5+
match (lhs, term) {
6+
Tuple{first:ASTNil{}, second:ASTNil{}} => r = yes;
7+
Tuple{
8+
first:App{left:App{left:Var{}, right:Var{}}, right:Var{}},
9+
second:App{left:App{left:Lit{}}}
10+
} => ();
11+
Tuple{
12+
first:App{left:Lit{key:c":Literal:"},right:Var{pv=key}},
13+
second:App{left:Lit{key:c":",ctk=token}, right:App{left:Lit{},right:AType{}}}
14+
} => r = r.bind(pv,term.with-location(ctk.location));
15+
Tuple{
16+
first:App{left:Var{},right:Var{}},
17+
second:App{left:Lit{tag=key}}
18+
} => (
19+
if is-lone-tag(tag) or tag.is-suffixed {
20+
match (lhs,term) {
21+
Tuple{first:App{pl=left,pr=right}, second:App{el=left,er=right}} => (
22+
let ll = try-destructure-macro(loc,pl,el);
23+
if non-zero(ll) {
24+
let rl = try-destructure-macro(loc,pr,er);
25+
if non-zero(rl) then r = union(ll,rl);
26+
}
27+
);
28+
}
29+
}
30+
);
31+
Tuple{ first:App{pl1=left,pr1=right}, second:App{el1=left,er1=right} } => (
32+
let ll1 = try-destructure-macro(loc,pl1,el1);
33+
if non-zero(ll1) {
34+
let rl1 = try-destructure-macro(loc,pr1,er1);
35+
if non-zero(rl1) then r = union(ll1,rl1);
36+
}
37+
);
38+
Tuple{ first:Abs{pl2=lhs,pr2=rhs,ptlt2=tt}, second:Abs{el2=lhs,er2=rhs,etlt2=tt} } => (
39+
let ll2 = try-destructure-macro(loc,pl2,el2);
40+
if non-zero(ll2) {
41+
let rl2 = try-destructure-macro(loc,pr2,er2);
42+
if non-zero(rl2) then r = union(ll2,rl2);
43+
}
44+
);
45+
Tuple{ first:Lit{key:c":Any:"}, second:Var{key:c"_"} } => r = yes;
46+
Tuple{ first:Lit{pl3=key}, second:Var{el3=key} } => if pl3==el3 then r = yes;
47+
Tuple{ first:Lit{pl4=key}, second:Lit{el4=key} } => if pl4==el4 then r = yes;
48+
Tuple{ first:App{left:Lit{key:c":Literal:"}, right:Var{pv5=key}}, second:Lit{el5=key,eltk5=token} } => (
49+
if index-of-tag(el5)==unknown-index-of-tag then r = r.bind(pv5,term.with-location(eltk5.location));
50+
);
51+
Tuple{ first:App{left:Lit{key:c":Field:"}, right:Var{pv6=key}}, second:Lit{el6=key,eltk6=token} } => (
52+
if el6.has-prefix(c".") then r = r.bind(pv6,term.with-location(eltk6.location));
53+
);
54+
Tuple{ first:App{left:Lit{key:c":Variable:"}, right:Var{pv7=key}}, second:Var{key:c"_"} } => (
55+
);
56+
Tuple{ first:App{left:Lit{key:c":Variable:"}, right:Var{pv8=key}}, second:Var{el8=key,eltk8=token} } => (
57+
r = r.bind(pv8,term.with-location(eltk8.location));
58+
);
59+
Tuple{ first:App{ left:App{ left:Lit{key:c":Tag:"}, right:Var{pv9=key} }, right:Var{pt9=key} }, second:Lit{el9=key,eltk9=token} } => (
60+
if index-of-tag(el9)!=unknown-index-of-tag {
61+
r = yes;
62+
let tag-i = index-of-tag(el9).into(type(CString));
63+
r = r.bind(pv9, mk-app( mk-lit(c":",with-key(eltk9,c":")), mk-app( mk-lit(tag-i,with-key(eltk9,tag-i)), mk-atype(t0(c"Constant") && t0(c"Literal") && t0(c"U64")) ) ));
64+
let tag-tt = c"Tag::" + el9;
65+
r = r.bind(pt9, mk-lit(tag-tt,with-key(eltk9,tag-tt)));
66+
}
67+
);
68+
Tuple{ first:Var{pv10=key}, t10=second } => r = r.bind(pv10,term.with-location(t10.location));
69+
_ => ();
70+
}; r
71+
);

LM23COMMON/unit-prop-core.lsts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ import LM23COMMON/prop-tctx-substitute.lsts;
2222
import LM23COMMON/prop-typeof-var-raw.lsts;
2323
import LM23COMMON/prop-typeof-tag.lsts;
2424
import LM23COMMON/prop-type-datatype.lsts;
25+
import LM23COMMON/prop-is-lone-tag.lsts;
26+
import LM23COMMON/prop-is-suffixed.lsts;

LM23COMMON/unit-type-core.lsts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ import LM23COMMON/type-as-return-hint.lsts;
3838
import LM23COMMON/type-resurrect.lsts;
3939
import LM23COMMON/type-cons-tail-or-self.lsts;
4040
import LM23COMMON/type-without-modifiers.lsts;
41+
import LM23COMMON/type-with-only-phi.lsts;

LM23COMMON/unit-typecheck-core.lsts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ import LM23COMMON/typecheck-std-maybe-release-after-call.lsts;
2323
import LM23COMMON/typecheck-index-of-tag.lsts;
2424
import LM23COMMON/typecheck-extract-uuids.lsts;
2525
import LM23COMMON/typecheck-std-direct-destructure-macro.lsts;
26+
import LM23COMMON/typecheck-tctx-substitute-lhs.lsts;
27+
import LM23COMMON/typecheck-tctx-substitute.lsts;
28+
import LM23COMMON/typecheck-try-destructure-macro.lsts;

0 commit comments

Comments
 (0)