Skip to content

Commit d4022c1

Browse files
authored
Merge pull request #2007 from andrew-johnson-4/type-list-to-type-vector-fdskldsl
Type list to type vector fdskldsl
2 parents 5b331ab + 3cd7e7b commit d4022c1

50 files changed

Lines changed: 3634 additions & 45 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ LSTSFLAGS = MALLOC_CHECK_=3
88
# recommendation: ulimit -s unlimited
99

1010
dev: install-production
11-
lm SRC/dev-index.lsts
11+
lm --v23 tests/promises/vector/constructor.lsts
1212
$(CC) $(CFLAGS) tmp.c
1313
./a.out
1414

1515
build: compile-production
16-
time env $(LSTSFLAGS) ./production --v23 --c -o deploy1.c SRC/index.lsts
16+
time env $(LSTSFLAGS) ./production --v23 --c -o deploy1.c SRC/dev-index.lsts
1717
$(CC) $(CFLAGS) deploy1.c -o deploy1
18-
time env $(LSTSFLAGS) ./deploy1 --v23 --c -o deploy2.c SRC/index.lsts
18+
time env $(LSTSFLAGS) ./deploy1 --v23 --c -o deploy2.c SRC/dev-index.lsts
1919
diff deploy1.c deploy2.c
2020
mv deploy1.c BOOTSTRAP/cli.c
2121
rm -f deploy1 deploy1.c deploy2.c
@@ -50,7 +50,7 @@ compile-bootstrap:
5050

5151
compile-production: compile-bootstrap
5252
rm -f production
53-
$(LSTSFLAGS) ./bootstrap.exe --v23 --c -o production.c SRC/index.lsts
53+
$(LSTSFLAGS) ./bootstrap.exe --v23 --c -o production.c SRC/dev-index.lsts
5454
$(CC) $(CFLAGS) -o production production.c
5555
rm -f production.c
5656

PLUGINS/BACKEND/C/dev-index.lsts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import PLUGINS/BACKEND/C/compile-c.lsts;
2+
import PLUGINS/BACKEND/C/never-as-expr.lsts;
3+
import PLUGINS/BACKEND/C/compile-finish.lsts;
4+
import PLUGINS/BACKEND/C/compile-program-ordered.lsts;
5+
import PLUGINS/BACKEND/C/compile-write.lsts;
6+
import PLUGINS/BACKEND/C/cc-blob.lsts;
7+
import PLUGINS/BACKEND/C/blob-render.lsts;
8+
import PLUGINS/BACKEND/C/dev-mangle-identifier.lsts;
9+
import PLUGINS/BACKEND/C/register-hook.lsts;
10+
import PLUGINS/BACKEND/C/std-c-compile-global.lsts;
11+
import PLUGINS/BACKEND/C/dev-std-c-mangle-type.lsts;
12+
import PLUGINS/BACKEND/C/std-c-mangle-declaration.lsts;
13+
import PLUGINS/BACKEND/C/std-c-compile-function-args.lsts;
14+
import PLUGINS/BACKEND/C/std-c-compile-expr.lsts;
15+
import PLUGINS/BACKEND/C/std-c-print.lsts;
16+
import PLUGINS/BACKEND/C/std-c-chain.lsts;
17+
import PLUGINS/BACKEND/C/std-c-compile-call.lsts;
18+
import PLUGINS/BACKEND/C/std-c-compile-constructor.lsts;
19+
import PLUGINS/BACKEND/C/std-c-compile-args.lsts;
20+
import PLUGINS/BACKEND/C/std-c-is-ctype.lsts;
21+
import PLUGINS/BACKEND/C/std-c-fragment-context.lsts;
22+
import PLUGINS/BACKEND/C/std-c-compile-destructure-args.lsts;
23+
import PLUGINS/BACKEND/C/escape-as-cstring.lsts;
24+
import PLUGINS/BACKEND/C/escape-string.lsts;
25+
import PLUGINS/BACKEND/C/std-c-compile-push-args.lsts;
26+
import PLUGINS/BACKEND/C/std-c-compile-type-typedef.lsts;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
let mangle-identifier(k: CString): S = (
3+
let cs = SAtom(c"LM_");
4+
while head(k) != 0 { match head(k) {
5+
33 => cs = cs + SAtom(c"_EX_"); # !
6+
36 => cs = cs + SAtom(c"_DL_"); # $
7+
37 => cs = cs + SAtom(c"_MD_"); # %
8+
38 => cs = cs + SAtom(c"_AM_"); # &
9+
39 => cs = cs + SAtom(c"_SQ_"); # '
10+
42 => cs = cs + SAtom(c"_ML_"); # *
11+
43 => cs = cs + SAtom(c"_AD_"); # +
12+
44 => cs = cs + SAtom(c"_CM_"); # ,
13+
45 => cs = cs + SAtom(c"_SB_"); # -
14+
46 => cs = cs + SAtom(c"_DT_"); # .
15+
47 => cs = cs + SAtom(c"_DV_"); # /
16+
58 => cs = cs + SAtom(c"_CL_"); # :
17+
59 => cs = cs + SAtom(c"_SC_"); # ;
18+
60 => cs = cs + SAtom(c"_LT_"); # <
19+
61 => cs = cs + SAtom(c"_EQ_"); # =
20+
62 => cs = cs + SAtom(c"_GT_"); # >
21+
63 => cs = cs + SAtom(c"_QM_"); # ?
22+
64 => cs = cs + SAtom(c"_AT_"); # @
23+
91 => cs = cs + SAtom(c"_LB_"); # [
24+
93 => cs = cs + SAtom(c"_RB_"); # ]
25+
94 => cs = cs + SAtom(c"_HT_"); # ^
26+
95 => cs = cs + SAtom(c"_US_"); # _
27+
96 => cs = cs + SAtom(c"_TK_"); # `
28+
124 => cs = cs + SAtom(c"_BR_"); # |
29+
126 => cs = cs + SAtom(c"_TL_"); # ~
30+
c => cs = cs + SAtom(clone-rope(c));
31+
}; k = tail(k); };
32+
cs
33+
);
34+
35+
let mangle-identifier(kt: Type): S = (
36+
match kt {
37+
TAny{} => mangle-identifier(c"?");
38+
TVar{name=name} => mangle-identifier(name);
39+
TGround{tag=tag, parameters=parameters} => (
40+
let r = mangle-identifier(tag);
41+
if parameters.length > 0 then r = r + mangle-identifier(c"<");
42+
let c-has-prev = false;
43+
for vector c in parameters {
44+
if c-has-prev { r = r + mangle-identifier(c",") };
45+
r = r + mangle-identifier(c);
46+
c-has-prev = true;
47+
};
48+
if parameters.length > 0 then r = r + mangle-identifier(c">");
49+
r
50+
);
51+
TAnd{conjugate=conjugate} => (
52+
let r = SNil;
53+
for vector c in conjugate { r = r + mangle-identifier(c); };
54+
r
55+
);
56+
}
57+
);
58+
59+
let mangle-identifier(k: CString, kt: Type): CString = (
60+
clone-rope(
61+
mangle-identifier(k) + SAtom(c"_CL_") + mangle-identifier(kt.normalize)
62+
);
63+
);
64+
65+
let mangle-identifier-function(k: CString, kt: Type): CString = (
66+
clone-rope(
67+
mangle-identifier(k) + SAtom(c"_CL_") + mangle-identifier(kt.normalize && kt.with-only-phi)
68+
);
69+
);
70+
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
2+
let std-c-mangle-type(tt: Type, blame: AST): S = (
3+
tt = tt.normalize.rewrite-opaque-type-alias.normalize.without-any-phi;
4+
let r = std-c-mangle-type-internal(tt, blame);
5+
if not(non-zero(r)) then fail("Unable To Mangle \{tt}\nAt \{blame.location}\n\{blame}\n");
6+
r
7+
);
8+
9+
let std-c-mangle-type-internal(tt: Type, blame: AST): S = (
10+
let r = std-c-mangle-type-internal-internal(tt, blame);
11+
if not(non-zero(r)) then r = std-c-mangle-type-internal-internal(tt.slot(c"Sized",1).l1, blame);
12+
r
13+
);
14+
15+
let std-c-mangle-type-internal-internal(tt: Type, blame: AST): S = (
16+
match tt {
17+
TAnd{ conjugate=conjugate } => (
18+
let is-c = can-unify(t1(c"C",ta), tt);
19+
let modifiers = SNil;
20+
let result = SNil;
21+
for vector c in conjugate {
22+
if is-c and c.simple-tag != c"C" {} else {
23+
if c.simple-tag == c"C" {
24+
let rt = std-c-mangle-type-internal-internal(c, blame);
25+
if non-zero(rt) then modifiers = modifiers + SAtom(c" ") + rt;
26+
} else {
27+
let rt = std-c-mangle-type-internal-internal(c, blame);
28+
if non-zero(rt) then result = rt;
29+
}
30+
}
31+
};
32+
modifiers + result;
33+
);
34+
TAny{} => SNil();
35+
TGround{tag:c"Nil", parameters:[]} => SAtom(c"void");
36+
TGround{tag:c"Never", parameters:[]} => SAtom(c"void");
37+
TGround{tag:c"U8", parameters:[]} => SAtom(c"char");
38+
TGround{tag:c"U16", parameters:[]} => SAtom(c"unsigned short");
39+
TGround{tag:c"U32", parameters:[]} => SAtom(c"unsigned int");
40+
TGround{tag:c"U64", parameters:[]} => SAtom(c"unsigned long");
41+
TGround{tag:c"I8", parameters:[]} => SAtom(c"signed char");
42+
TGround{tag:c"I16", parameters:[]} => SAtom(c"signed short");
43+
TGround{tag:c"I32", parameters:[]} => SAtom(c"signed int");
44+
TGround{tag:c"I64", parameters:[]} => SAtom(c"signed long");
45+
TGround{tag:c"F64", parameters:[]} => SAtom(c"double");
46+
TGround{tag:c"CString", parameters:[]} => SAtom(c"char*");
47+
TGround{tag:c"File", parameters:[]} => SAtom(c"FILE");
48+
TGround{tag:c"IO::File", parameters:[]} => SAtom(c"FILE*");
49+
TGround{tag:c"PID", parameters:[]} => SAtom(c"pid_t");
50+
TGround{tag:c"Regex", parameters:[]} => SAtom(c"regex_t");
51+
TGround{tag:c"C_regex__t_*_", parameters:[]} => SAtom(c"regex_t*");
52+
TGround{tag:c"C_char", parameters:[]} => SAtom(c"char");
53+
TGround{tag:c"C_int", parameters:[]} => SAtom(c"int");
54+
TGround{tag:c"C_char_*", parameters:[]} => SAtom(c"char*");
55+
TGround{tag:c"C_size__t_", parameters:[]} => SAtom(c"size_t");
56+
TGround{tag:c"C_regmatch__t_*", parameters:[]} => SAtom(c"regmatch_t*");
57+
TGround{tag:c"C_regmatch__t_", parameters:[]} => SAtom(c"regmatch_t");
58+
TGround{tag:c"DefaultPrintable", parameters:[]} => SNil;
59+
TGround{tag:c"Type", parameters:[inner-tt..]} => SAtom(c"int");
60+
TGround{tag:c"Array", parameters:[_.. TAny{}..]} => SAtom(c"void*");
61+
TGround{tag:c"Array", parameters:[_.. array-base..]} => (
62+
if array-base.is-arrow
63+
then std-c-mangle-type-internal-internal(array-base, blame)
64+
else ( std-c-mangle-type-internal-internal(array-base, blame) + SAtom(c"*") );
65+
);
66+
TGround{tag:c"Arrow"} => (
67+
(let pre, let post) = std-c-mangle-declaration-internal(tt, blame);
68+
let td-id = uuid();
69+
assemble-header-typedef-section = assemble-header-typedef-section
70+
+ SAtom(c"typedef ")
71+
+ pre
72+
+ SAtom(c" ")
73+
+ SAtom(td-id)
74+
+ SAtom(c" ")
75+
+ post
76+
+ SAtom(c";\n");
77+
SAtom(td-id)
78+
);
79+
TGround{tag:c"C", parameters:[TGround{tag1=tag}..]} => (
80+
SAtom(tag1)
81+
);
82+
TGround{tag:c"Sized", parameters:[_..]} => SNil;
83+
TGround{tag=tag, parameters=parameters} => (
84+
let r = mangle-identifier(tag);
85+
if parameters.length > 0 {
86+
r = r + mangle-identifier(c"<");
87+
let pi = 0;
88+
for vector p in parameters {
89+
if pi > 0 then r = r + mangle-identifier(c",");
90+
r = r + std-c-mangle-type-simple(p, blame);
91+
pi = pi + 1;
92+
};
93+
r = r + mangle-identifier(c">");
94+
};
95+
r;
96+
);
97+
_ => SNil();
98+
}
99+
);
100+
101+
let std-c-mangle-type-simple(tt: Type, blame: AST): S = (
102+
match tt {
103+
TAnd{ conjugate=conjugate } => (
104+
let is-c = can-unify(t1(c"C",ta), tt);
105+
let result = SNil();
106+
for vector c in conjugate {
107+
if is-c and c.simple-tag != c"C" {} else {
108+
let rt = std-c-mangle-type-internal-internal(c, blame);
109+
result = if non-zero(result) and non-zero(rt) then result + SAtom(c" ") + rt
110+
else if non-zero(result) then result
111+
else rt;
112+
}
113+
};
114+
result;
115+
);
116+
TGround{tag:c"Nil", parameters:[]} => SAtom(c"void");
117+
TGround{tag:c"Never", parameters:[]} => SAtom(c"void");
118+
TGround{tag=tag, parameters=parameters} => (
119+
let r = mangle-identifier(tag);
120+
if parameters.length > 0 {
121+
r = r + mangle-identifier(c"<");
122+
let pi = 0;
123+
for vector p in parameters {
124+
if pi > 0 then r = r + mangle-identifier(c",");
125+
r = r + std-c-mangle-type-simple(p, blame);
126+
pi = pi + 1;
127+
};
128+
r = r + mangle-identifier(c">");
129+
};
130+
r;
131+
);
132+
_ => SNil();
133+
}
134+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
import PLUGINS/FRONTEND/LSTS/lsts-frontend.lsts;
3+
import PLUGINS/FRONTEND/LSTS/lsts-smart-tokenize.lsts;
4+
import PLUGINS/FRONTEND/LSTS/lsts-tokenize.lsts;
5+
import PLUGINS/FRONTEND/LSTS/dev-lsts-parse.lsts;
6+
import PLUGINS/FRONTEND/LSTS/mk-lsts-token.lsts;

0 commit comments

Comments
 (0)