Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ LSTSFLAGS = MALLOC_CHECK_=3
# recommendation: ulimit -s unlimited

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

build: compile-production
time env $(LSTSFLAGS) ./production --v23 --c -o deploy1.c SRC/index.lsts
time env $(LSTSFLAGS) ./production --v23 --c -o deploy1.c SRC/dev-index.lsts
$(CC) $(CFLAGS) deploy1.c -o deploy1
time env $(LSTSFLAGS) ./deploy1 --v23 --c -o deploy2.c SRC/index.lsts
time env $(LSTSFLAGS) ./deploy1 --v23 --c -o deploy2.c SRC/dev-index.lsts
diff deploy1.c deploy2.c
mv deploy1.c BOOTSTRAP/cli.c
rm -f deploy1 deploy1.c deploy2.c
Expand Down Expand Up @@ -50,7 +50,7 @@ compile-bootstrap:

compile-production: compile-bootstrap
rm -f production
$(LSTSFLAGS) ./bootstrap.exe --v23 --c -o production.c SRC/index.lsts
$(LSTSFLAGS) ./bootstrap.exe --v23 --c -o production.c SRC/dev-index.lsts
$(CC) $(CFLAGS) -o production production.c
rm -f production.c

Expand Down
26 changes: 26 additions & 0 deletions PLUGINS/BACKEND/C/dev-index.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import PLUGINS/BACKEND/C/compile-c.lsts;
import PLUGINS/BACKEND/C/never-as-expr.lsts;
import PLUGINS/BACKEND/C/compile-finish.lsts;
import PLUGINS/BACKEND/C/compile-program-ordered.lsts;
import PLUGINS/BACKEND/C/compile-write.lsts;
import PLUGINS/BACKEND/C/cc-blob.lsts;
import PLUGINS/BACKEND/C/blob-render.lsts;
import PLUGINS/BACKEND/C/dev-mangle-identifier.lsts;
import PLUGINS/BACKEND/C/register-hook.lsts;
import PLUGINS/BACKEND/C/std-c-compile-global.lsts;
import PLUGINS/BACKEND/C/dev-std-c-mangle-type.lsts;
import PLUGINS/BACKEND/C/std-c-mangle-declaration.lsts;
import PLUGINS/BACKEND/C/std-c-compile-function-args.lsts;
import PLUGINS/BACKEND/C/std-c-compile-expr.lsts;
import PLUGINS/BACKEND/C/std-c-print.lsts;
import PLUGINS/BACKEND/C/std-c-chain.lsts;
import PLUGINS/BACKEND/C/std-c-compile-call.lsts;
import PLUGINS/BACKEND/C/std-c-compile-constructor.lsts;
import PLUGINS/BACKEND/C/std-c-compile-args.lsts;
import PLUGINS/BACKEND/C/std-c-is-ctype.lsts;
import PLUGINS/BACKEND/C/std-c-fragment-context.lsts;
import PLUGINS/BACKEND/C/std-c-compile-destructure-args.lsts;
import PLUGINS/BACKEND/C/escape-as-cstring.lsts;
import PLUGINS/BACKEND/C/escape-string.lsts;
import PLUGINS/BACKEND/C/std-c-compile-push-args.lsts;
import PLUGINS/BACKEND/C/std-c-compile-type-typedef.lsts;
70 changes: 70 additions & 0 deletions PLUGINS/BACKEND/C/dev-mangle-identifier.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

let mangle-identifier(k: CString): S = (
let cs = SAtom(c"LM_");
while head(k) != 0 { match head(k) {
33 => cs = cs + SAtom(c"_EX_"); # !
36 => cs = cs + SAtom(c"_DL_"); # $
37 => cs = cs + SAtom(c"_MD_"); # %
38 => cs = cs + SAtom(c"_AM_"); # &
39 => cs = cs + SAtom(c"_SQ_"); # '
42 => cs = cs + SAtom(c"_ML_"); # *
43 => cs = cs + SAtom(c"_AD_"); # +
44 => cs = cs + SAtom(c"_CM_"); # ,
45 => cs = cs + SAtom(c"_SB_"); # -
46 => cs = cs + SAtom(c"_DT_"); # .
47 => cs = cs + SAtom(c"_DV_"); # /
58 => cs = cs + SAtom(c"_CL_"); # :
59 => cs = cs + SAtom(c"_SC_"); # ;
60 => cs = cs + SAtom(c"_LT_"); # <
61 => cs = cs + SAtom(c"_EQ_"); # =
62 => cs = cs + SAtom(c"_GT_"); # >
63 => cs = cs + SAtom(c"_QM_"); # ?
64 => cs = cs + SAtom(c"_AT_"); # @
91 => cs = cs + SAtom(c"_LB_"); # [
93 => cs = cs + SAtom(c"_RB_"); # ]
94 => cs = cs + SAtom(c"_HT_"); # ^
95 => cs = cs + SAtom(c"_US_"); # _
96 => cs = cs + SAtom(c"_TK_"); # `
124 => cs = cs + SAtom(c"_BR_"); # |
126 => cs = cs + SAtom(c"_TL_"); # ~
c => cs = cs + SAtom(clone-rope(c));
}; k = tail(k); };
cs
);

let mangle-identifier(kt: Type): S = (
match kt {
TAny{} => mangle-identifier(c"?");
TVar{name=name} => mangle-identifier(name);
TGround{tag=tag, parameters=parameters} => (
let r = mangle-identifier(tag);
if parameters.length > 0 then r = r + mangle-identifier(c"<");
let c-has-prev = false;
for vector c in parameters {
if c-has-prev { r = r + mangle-identifier(c",") };
r = r + mangle-identifier(c);
c-has-prev = true;
};
if parameters.length > 0 then r = r + mangle-identifier(c">");
r
);
TAnd{conjugate=conjugate} => (
let r = SNil;
for vector c in conjugate { r = r + mangle-identifier(c); };
r
);
}
);

let mangle-identifier(k: CString, kt: Type): CString = (
clone-rope(
mangle-identifier(k) + SAtom(c"_CL_") + mangle-identifier(kt.normalize)
);
);

let mangle-identifier-function(k: CString, kt: Type): CString = (
clone-rope(
mangle-identifier(k) + SAtom(c"_CL_") + mangle-identifier(kt.normalize && kt.with-only-phi)
);
);

134 changes: 134 additions & 0 deletions PLUGINS/BACKEND/C/dev-std-c-mangle-type.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

let std-c-mangle-type(tt: Type, blame: AST): S = (
tt = tt.normalize.rewrite-opaque-type-alias.normalize.without-any-phi;
let r = std-c-mangle-type-internal(tt, blame);
if not(non-zero(r)) then fail("Unable To Mangle \{tt}\nAt \{blame.location}\n\{blame}\n");
r
);

let std-c-mangle-type-internal(tt: Type, blame: AST): S = (
let r = std-c-mangle-type-internal-internal(tt, blame);
if not(non-zero(r)) then r = std-c-mangle-type-internal-internal(tt.slot(c"Sized",1).l1, blame);
r
);

let std-c-mangle-type-internal-internal(tt: Type, blame: AST): S = (
match tt {
TAnd{ conjugate=conjugate } => (
let is-c = can-unify(t1(c"C",ta), tt);
let modifiers = SNil;
let result = SNil;
for vector c in conjugate {
if is-c and c.simple-tag != c"C" {} else {
if c.simple-tag == c"C" {
let rt = std-c-mangle-type-internal-internal(c, blame);
if non-zero(rt) then modifiers = modifiers + SAtom(c" ") + rt;
} else {
let rt = std-c-mangle-type-internal-internal(c, blame);
if non-zero(rt) then result = rt;
}
}
};
modifiers + result;
);
TAny{} => SNil();
TGround{tag:c"Nil", parameters:[]} => SAtom(c"void");
TGround{tag:c"Never", parameters:[]} => SAtom(c"void");
TGround{tag:c"U8", parameters:[]} => SAtom(c"char");
TGround{tag:c"U16", parameters:[]} => SAtom(c"unsigned short");
TGround{tag:c"U32", parameters:[]} => SAtom(c"unsigned int");
TGround{tag:c"U64", parameters:[]} => SAtom(c"unsigned long");
TGround{tag:c"I8", parameters:[]} => SAtom(c"signed char");
TGround{tag:c"I16", parameters:[]} => SAtom(c"signed short");
TGround{tag:c"I32", parameters:[]} => SAtom(c"signed int");
TGround{tag:c"I64", parameters:[]} => SAtom(c"signed long");
TGround{tag:c"F64", parameters:[]} => SAtom(c"double");
TGround{tag:c"CString", parameters:[]} => SAtom(c"char*");
TGround{tag:c"File", parameters:[]} => SAtom(c"FILE");
TGround{tag:c"IO::File", parameters:[]} => SAtom(c"FILE*");
TGround{tag:c"PID", parameters:[]} => SAtom(c"pid_t");
TGround{tag:c"Regex", parameters:[]} => SAtom(c"regex_t");
TGround{tag:c"C_regex__t_*_", parameters:[]} => SAtom(c"regex_t*");
TGround{tag:c"C_char", parameters:[]} => SAtom(c"char");
TGround{tag:c"C_int", parameters:[]} => SAtom(c"int");
TGround{tag:c"C_char_*", parameters:[]} => SAtom(c"char*");
TGround{tag:c"C_size__t_", parameters:[]} => SAtom(c"size_t");
TGround{tag:c"C_regmatch__t_*", parameters:[]} => SAtom(c"regmatch_t*");
TGround{tag:c"C_regmatch__t_", parameters:[]} => SAtom(c"regmatch_t");
TGround{tag:c"DefaultPrintable", parameters:[]} => SNil;
TGround{tag:c"Type", parameters:[inner-tt..]} => SAtom(c"int");
TGround{tag:c"Array", parameters:[_.. TAny{}..]} => SAtom(c"void*");
TGround{tag:c"Array", parameters:[_.. array-base..]} => (
if array-base.is-arrow
then std-c-mangle-type-internal-internal(array-base, blame)
else ( std-c-mangle-type-internal-internal(array-base, blame) + SAtom(c"*") );
);
TGround{tag:c"Arrow"} => (
(let pre, let post) = std-c-mangle-declaration-internal(tt, blame);
let td-id = uuid();
assemble-header-typedef-section = assemble-header-typedef-section
+ SAtom(c"typedef ")
+ pre
+ SAtom(c" ")
+ SAtom(td-id)
+ SAtom(c" ")
+ post
+ SAtom(c";\n");
SAtom(td-id)
);
TGround{tag:c"C", parameters:[TGround{tag1=tag}..]} => (
SAtom(tag1)
);
TGround{tag:c"Sized", parameters:[_..]} => SNil;
TGround{tag=tag, parameters=parameters} => (
let r = mangle-identifier(tag);
if parameters.length > 0 {
r = r + mangle-identifier(c"<");
let pi = 0;
for vector p in parameters {
if pi > 0 then r = r + mangle-identifier(c",");
r = r + std-c-mangle-type-simple(p, blame);
pi = pi + 1;
};
r = r + mangle-identifier(c">");
};
r;
);
_ => SNil();
}
);

let std-c-mangle-type-simple(tt: Type, blame: AST): S = (
match tt {
TAnd{ conjugate=conjugate } => (
let is-c = can-unify(t1(c"C",ta), tt);
let result = SNil();
for vector c in conjugate {
if is-c and c.simple-tag != c"C" {} else {
let rt = std-c-mangle-type-internal-internal(c, blame);
result = if non-zero(result) and non-zero(rt) then result + SAtom(c" ") + rt
else if non-zero(result) then result
else rt;
}
};
result;
);
TGround{tag:c"Nil", parameters:[]} => SAtom(c"void");
TGround{tag:c"Never", parameters:[]} => SAtom(c"void");
TGround{tag=tag, parameters=parameters} => (
let r = mangle-identifier(tag);
if parameters.length > 0 {
r = r + mangle-identifier(c"<");
let pi = 0;
for vector p in parameters {
if pi > 0 then r = r + mangle-identifier(c",");
r = r + std-c-mangle-type-simple(p, blame);
pi = pi + 1;
};
r = r + mangle-identifier(c">");
};
r;
);
_ => SNil();
}
);
6 changes: 6 additions & 0 deletions PLUGINS/FRONTEND/LSTS/dev-index.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import PLUGINS/FRONTEND/LSTS/lsts-frontend.lsts;
import PLUGINS/FRONTEND/LSTS/lsts-smart-tokenize.lsts;
import PLUGINS/FRONTEND/LSTS/lsts-tokenize.lsts;
import PLUGINS/FRONTEND/LSTS/dev-lsts-parse.lsts;
import PLUGINS/FRONTEND/LSTS/mk-lsts-token.lsts;
Loading
Loading