Skip to content

Commit 1072c9f

Browse files
authored
Merge pull request #1963 from andrew-johnson-4/more-lmcommon-fdsjkoww
More lmcommon fdsjkoww
2 parents cef0088 + 72a7f76 commit 1072c9f

20 files changed

Lines changed: 2880 additions & 2872 deletions

BOOTSTRAP/cli.c

Lines changed: 2693 additions & 2687 deletions
Large diffs are not rendered by default.

LM23COMMON/ast-misc-todo-remove-or-stabilize.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ let .into(used: IsUsed, ty: Type<String>): String = (
4747
);
4848

4949
type Macro = { lhs:AST, rhs:AST };
50-
type MacroList zero MEOF = MEOF | MSeq{ k:MacroList[], v:Macro };
50+
type MacroList zero MEOF = MEOF | MSeq{ k:OwnedData<MacroList>[], v:Macro };
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
let global-symbol-registry = {} : Hashtable<(CString,Type),Bool>;
3+
4+
let mark-global-as-seen(name: CString, tt: Type, tlt: Type): Nil = (
5+
if global-is-seen(name,tt) and not(tlt.is-t(c"FFI",0)) then fail("Duplicate Global Symbol \{name} : \{tt}");
6+
global-symbol-registry = global-symbol-registry.bind((name,tt), true);
7+
);
8+
9+
let global-is-seen(name: CString, tt: Type): Bool = global-symbol-registry.lookup((name,tt),false);

LM23COMMON/prop-is-macro-head.lsts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
let is-macro-head(s: CString, arity: U64): Bool = (
3+
let macros = preprocess-macros;
4+
let found = false;
5+
while non-zero(macros) { match macros {
6+
MSeq{ rst1=k, v:Macro{ lhs:App{ left:Lit{mv1=key}, p11=right }, mrhs1=rhs } } => (
7+
if arity==1 and s==mv1 then found = true;
8+
macros = rst1;
9+
);
10+
MSeq{ rst2=k, v:Macro{ lhs:App{ left:App{ left:Lit{mv2=key}, p12=right }, p22=right }, mrhs2=rhs } } => (
11+
if arity==2 and s==mv2 then found = true;
12+
macros = rst2;
13+
);
14+
MSeq{ rst3=k, v:Macro{ mlhs3=lhs, mrhs3=rhs } } => fail("Unrecognized Macro Pattern: \{mlhs3}");
15+
}};
16+
found
17+
);

SRC/preprocess-apply-hard.lsts renamed to LM23COMMON/typecheck-preprocess-apply-hard.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ let preprocess-apply-hard(macro-name: CString, arity: U64, program: AST): AST =
88
macros = rst;
99
let go = false;
1010
match lhs {
11-
App{ left:Lit{m=key} } => if macro-name==m && arity==1 then go = true;
12-
App{ left:App{ left:Lit{m=key} } } => if macro-name==m && arity==2 then go = true;
11+
App{ left:Lit{m1=key} } => if macro-name==m1 and arity==1 then go = true;
12+
App{ left:App{ left:Lit{m2=key} } } => if macro-name==m2 and arity==2 then go = true;
1313
};
1414
if go {
1515
let des = try-destructure-macro(program.location, lhs, program);

SRC/preprocess-apply-literals.lsts renamed to LM23COMMON/typecheck-preprocess-apply-literals.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ let preprocess-apply-literals(program: AST): AST = (
77
for p in seqs { program = program + preprocess-apply-literals(p) };
88
program
99
);
10-
Abs{al=lhs, ar=rhs, tlt=tt} => mk-abs(preprocess-apply-literals(al), preprocess-apply-literals(ar), tlt);
11-
Glb{k=key, ar=val} => mk-glb(k.unique, preprocess-apply-literals(ar));
10+
Abs{al1=lhs, ar1=rhs, tlt1=tt} => mk-abs(preprocess-apply-literals(al1), preprocess-apply-literals(ar1), tlt1);
11+
Glb{k2=key, ar2=val} => mk-glb(k2.unique, preprocess-apply-literals(ar2));
1212
_ => program;
1313
}
1414
);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
let preprocess-apply-locations(program: AST): AST = (
3+
match program {
4+
App{ left:Var{key:c"p"}, right:Lit{key:c":Location:",ltk1=token} } => (
5+
let l = c"File: " + ltk1.location.filename
6+
+ c" Line: " + ltk1.location.line.into(type(CString))
7+
+ c" Column: " + ltk1.location.column.into(type(CString));
8+
mk-lit(l, with-key(ltk1.unique,l))
9+
);
10+
Lit{l2=key,ltk2=token} => mk-lit(l2, ltk2.unique);
11+
Var{l3=key,ltk3=token} => mk-var(l3, ltk3.unique);
12+
App{is-cons4=is-cons,t04=left,t14=right} => mk-cons-or-app(is-cons4, preprocess-apply-locations(t04), preprocess-apply-locations(t14));
13+
Seq{seq=seq} => (
14+
program = mk-eof();
15+
for p in seq { program = program + preprocess-apply-locations(p) };
16+
program
17+
);
18+
Abs{al1=lhs, ar1=rhs, tlt1=tt} => mk-abs(preprocess-apply-locations(al1), preprocess-apply-locations(ar1), tlt1);
19+
Glb{k2=key, ar2=val} => mk-glb(k2.unique, preprocess-apply-locations(ar2));
20+
_ => program;
21+
}
22+
);
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
let preprocess-apply(program: AST): AST = preprocess-apply(program, false);
3+
4+
let preprocess-apply(program: AST, is-lhs: Bool): AST = (
5+
match program {
6+
App{ left:App{ left:Var{key:c"macro::concat",ctk1=token}, right:App{ left:Var{lk1=key}, right:Var{rk1=key} } }, nt1=right } => (
7+
mk-app( mk-var(lk1+rk1, ctk1.unique), preprocess-apply(nt1) )
8+
);
9+
App{ left:App{ left:Var{key:c"macro::concat",ctk2=token}, right:App{ left:Var{lk2=key}, right:Lit{rk2=key} } }, nt2=right } => (
10+
mk-app( mk-var(lk2+rk2, ctk2.unique), preprocess-apply(nt2) )
11+
);
12+
App{ left:App{ left:Var{key:c"macro::concat",ctk3=token}, right:App{ left:Lit{lk3=key}, right:Var{rk3=key} } }, nt3=right } => (
13+
mk-app( mk-var(lk3+rk3, ctk3.unique), preprocess-apply(nt3) )
14+
);
15+
App{ left:App{ left:Var{key:c"macro::concat",ctk4=token}, right:App{ left:Lit{lk4=key}, right:Lit{rk4=key} } }, nt4=right } => (
16+
mk-app( mk-var(lk4+rk4, ctk4.unique), preprocess-apply(nt4) )
17+
);
18+
App{ is-cons-14=is-cons,
19+
left:App{is-cons-24=is-cons,
20+
left:Lit{key:c":",ctk4=token},
21+
right:App{is-cons-34=is-cons,
22+
t4=left:Lit{l4=key,ltk4=token},
23+
right:AType{tt4=tt}
24+
}
25+
}, nt4=right } => (
26+
if not(tt4.is-t(c"String",0)) then t4 = preprocess-apply(t4);
27+
mk-cons-or-app(is-cons-14,
28+
mk-cons-or-app(is-cons-24,
29+
mk-lit(c":",ctk4.unique),
30+
mk-cons-or-app(is-cons-34,t4,mk-atype(tt4))
31+
), preprocess-apply(nt4,is-lhs)
32+
);
33+
);
34+
App{ is-cons-15=is-cons,
35+
left:App{is-cons-25=is-cons,
36+
left:Lit{key:c":",ctk5=token},
37+
right:App{is-cons-35=is-cons,
38+
t5=left,
39+
right:AType{tt5=tt}
40+
}
41+
}, nt5=right } => (
42+
tt5 = phi-as-state(tt5).expand-implied-phi;
43+
mk-cons-or-app(is-cons-15,
44+
mk-cons-or-app(is-cons-25,
45+
mk-lit(c":",ctk5.unique),
46+
mk-cons-or-app(is-cons-35,preprocess-apply(t5,is-lhs),mk-atype(tt5))
47+
), preprocess-apply(nt5,is-lhs)
48+
);
49+
);
50+
App{is-cons-26=is-cons, left:Lit{key:c":",ctk6=token}, right:App{is-cons-36=is-cons,t6=left:Lit{},right:AType{tt6=tt}}} => (
51+
if not(tt6.is-t(c"String",0)) then t6 = preprocess-apply(t6);
52+
mk-cons-or-app(is-cons-26,
53+
mk-lit(c":",ctk6.unique),
54+
mk-cons-or-app(is-cons-36,t6,mk-atype(tt6))
55+
);
56+
);
57+
App{is-cons-27=is-cons, left:Lit{key:c":",ctk7=token}, right:App{is-cons-37=is-cons,t7=left,right:AType{tt7=tt}}} => (
58+
tt7 = phi-as-state(tt7).expand-implied-phi;
59+
t7 = preprocess-apply(t7);
60+
mk-cons-or-app(is-cons-27,
61+
mk-lit(c":",ctk7.unique),
62+
mk-cons-or-app(is-cons-37,t7,mk-atype(tt7))
63+
);
64+
);
65+
App{
66+
left:App{
67+
left:Var{key:c"as",atk8=token},
68+
right:App{ t8=left, right:AType{tt8=tt} }
69+
}, nt8=right
70+
} => (
71+
mk-app( mk-app( mk-var(c"as",atk8.unique), mk-app(preprocess-apply(t8),mk-atype(tt8)) ), preprocess-apply(nt8) )
72+
);
73+
Lit{l9=key,ltk9=token} => (
74+
for Tuple{sfxs9=first, sfxtt9=second} in parse-suffixes {
75+
if l9.has-suffix(sfxs9) {
76+
let lpfx9 = l9.remove-suffix(sfxs9).get-or(c"");
77+
program = mk-app( mk-lit(c":",with-key(ltk9,c":")), mk-app( mk-lit(lpfx9,with-key(ltk9,lpfx9)), mk-atype(sfxtt9) ) )
78+
}
79+
}; program
80+
);
81+
Var{l10=key,ltk10=token} => (
82+
for Tuple{sfxs10=first, sfxtt10=second} in parse-suffixes {
83+
if l10.has-suffix(sfxs10) {
84+
let lpfx10 = l10.remove-suffix(sfxs10).get-or(c"");
85+
program = mk-app( mk-lit(c":",with-key(ltk10,c":")), mk-app( mk-lit(lpfx10,with-key(ltk10,lpfx10)), mk-atype(sfxtt10) ) )
86+
}
87+
}; program
88+
);
89+
App{ is-cons11=is-cons, left:Var{vn11=key,vntk11=token}, vt11=right } => (
90+
if is-macro-head(vn11,1) {
91+
preprocess-apply-hard(vn11,1,program)
92+
} else {
93+
mk-cons-or-app(is-cons11, preprocess-apply(mk-var(vn11,vntk11.unique)), preprocess-apply(vt11))
94+
}
95+
);
96+
App{ is-cons-112=is-cons, left:App{ is-cons-212=is-cons, left:Var{vn12=key,vntk12=token}, vt012=right }, vt112=right } => (
97+
if is-macro-head(vn12,2) {
98+
preprocess-apply-hard(vn12,2,program)
99+
} else {
100+
mk-cons-or-app(is-cons-112,
101+
preprocess-apply(mk-cons-or-app(is-cons-212,
102+
mk-var(vn12,vntk12.unique), vt012
103+
),is-lhs), preprocess-apply(vt112,is-lhs)
104+
)
105+
}
106+
);
107+
Seq{seq=seq} => (
108+
program = mk-eof();
109+
for s in seq { program = program + preprocess-apply(s) };
110+
program
111+
);
112+
App{is-cons14=is-cons, al14=left, ar14=right} => (
113+
mk-cons-or-app( is-cons14, preprocess-apply(al14,is-lhs), preprocess-apply(ar14,is-lhs) )
114+
);
115+
Abs{al15=lhs, ar15=rhs, tlt15=tt} => (
116+
if not(tlt15.is-t(c"TypedMacro",0))
117+
then mk-abs(preprocess-apply(al15,true),preprocess-apply(ar15),tlt15)
118+
else program
119+
);
120+
Glb{k16=key, ar16=val} => mk-glb(k16.unique, preprocess-apply(ar16));
121+
_ => program;
122+
}
123+
);
124+

LM23COMMON/unit-ast-core.lsts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ import LM23COMMON/ast-acontext-apply.lsts;
2727
import LM23COMMON/ast-acontext-bind.lsts;
2828
import LM23COMMON/ast-acontext-substitute.lsts;
2929
import LM23COMMON/ast-acontext-union.lsts;
30+
import LM23COMMON/ast-substitute-uuids.lsts;

0 commit comments

Comments
 (0)