Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5,188 changes: 2,604 additions & 2,584 deletions BOOTSTRAP/cli.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LM23COMMON/typecheck-infer-expr.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ let std-infer-call-arg(tctx: TypeContext?, term: AST, function-name: CString, hi
}} else if function-name==c"map::cons" { match term {
App{k=left, m=right} => (
(tctx, let new-k) = std-infer-expr(tctx, k, false, Call(function-name), ta);
let direct-hint = if config-v3
let direct-hint = if config-v3 or config-v23
then t2(c"Hashtable",typeof-term(new-k).normalize.slot(c"Cons",2).l1,typeof-term(new-k).normalize.slot(c"Cons",2).l2) && t0(c"ReturnHint")
else t2(c"HashtableEq",typeof-term(new-k).normalize.slot(c"Cons",2).l1,typeof-term(new-k).normalize.slot(c"Cons",2).l2);
(tctx, let new-m) = std-infer-expr(tctx, m, false, Used(), direct-hint);
Expand Down
28 changes: 17 additions & 11 deletions LM23COMMON/typecheck-infer-global-terms.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ let infer-global-terms(tctx: TypeContext?, term: AST): (TypeContext?, AST) = (
let kto = typeof-term(rhs);
let ktd = kto && t0(c"GlobalVariable");
tctx = tctx.bind-global(k.key, kto, ktd, term);
mark-global-as-seen(k.key, ktd, ta);
tctx = tctx.ascript(term, ktd);
(tctx, _) = tctx.maybe-apply-callable(c"mov", t2(c"Cons",ktd.without-phi,ktd.without-phi), term);
if not(global-is-seen(k.key, ktd)) {
mark-global-as-seen(k.key, ktd, ta);
tctx = tctx.ascript(term, ktd);
(tctx, _) = tctx.maybe-apply-callable(c"mov", t2(c"Cons",ktd.without-phi,ktd.without-phi), term);
}
);
_ => (
(tctx, term) = std-infer-expr(tctx, term, false, Unused, ta);
Expand All @@ -44,10 +46,12 @@ let infer-global-context-prim(term: AST): Nil = (
Glb{ k=key, frhs=val:Abs{lhs=lhs, rhs:App{left:Lit{key:c":"}, right:App{rhs=left, right:AType{return-type=tt}}}, misc-tt=tt} } => (
if k.key.has-prefix(c"primitive::") then {
let ft = t2(c"Arrow", typeof-lhs(lhs), return-type.without-modifiers).without-phi-keep-state && misc-tt;
mark-global-as-seen(k.key, ft, misc-tt);
Some(mk-tctx()).ascript(term, ft);
Some(mk-tctx()).ascript(frhs, ft);
Some(mk-tctx()).bind-global(k.key, ft, ft, term);
if not(global-is-seen(k.key, ft)) {
mark-global-as-seen(k.key, ft, misc-tt);
Some(mk-tctx()).ascript(term, ft);
Some(mk-tctx()).ascript(frhs, ft);
Some(mk-tctx()).bind-global(k.key, ft, ft, term);
}
};
);
_ => ();
Expand Down Expand Up @@ -75,10 +79,12 @@ let infer-global-context(term: AST): Nil = (
else if misc-tt.is-t(c"TypedMacro",0) then bind-new-macro(k.key, frhs)
else {
let ft = t2(c"Arrow", typeof-lhs(lhs), return-type.rewrite-type-alias.expand-implied-phi.without-modifiers).without-phi-keep-state && misc-tt;
mark-global-as-seen(k.key, ft, misc-tt);
Some(mk-tctx()).ascript(term, ft);
Some(mk-tctx()).ascript(frhs, ft);
Some(mk-tctx()).bind-global(k.key, ft, denormalize-strong(ft), term);
if not(global-is-seen(k.key, ft)) {
mark-global-as-seen(k.key, ft, misc-tt);
Some(mk-tctx()).ascript(term, ft);
Some(mk-tctx()).ascript(frhs, ft);
Some(mk-tctx()).bind-global(k.key, ft, denormalize-strong(ft), term);
}
};
);
_ => ();
Expand Down
2 changes: 2 additions & 0 deletions LM23COMMON/unit-main-core.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let print-toks-json(fp: CString): Nil = (
let show-alloc-count = false;

let main(argc: C_int, argv: CString[]): Nil = (
config-v23 = false;
let argi = 1_sz;
let input = [] : List<CString>;
let highlight = false;
Expand All @@ -43,6 +44,7 @@ let main(argc: C_int, argv: CString[]): Nil = (
c"--v0" => (config-v3 = false; config-v0 = true;);
c"--v1" => (config-v3 = false; config-v1 = true;);
c"--v2" => config-v3 = false;
c"--v23" => (config-v3 = false; config-v23 = true;);
c"--v3" => config-v3 = true;
c"--highlight" => (
config-mode = ModeTokenize();
Expand Down
12 changes: 6 additions & 6 deletions PLUGINS/BACKEND/C/blob-render.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let blob-render-simple(ctx: FContext, context-key: CString, term: AST): (FContex
let ri = to-i64(clone-rope(rs));
while li < ri {
ri = ri - 1;
r = SCons( close(SAtom(to-string(ri))), close(r) );
r = SCons( close(SAtom(ri.into(type(CString)))), close(r) );
}
);
App{ left:Var{key:c"uuid"} } => r = SAtom(uuid());
Expand All @@ -72,7 +72,7 @@ let blob-render-simple(ctx: FContext, context-key: CString, term: AST): (FContex
if typeof-term(f).is-arrow { match f {
Var{fname=key} => (
if fname.has-prefix(c":")
then r = blob-render-simple(ctx, tail-string(fname), a).second
then r = blob-render-simple(ctx, tail(fname), a).second
else r = std-c-compile-call(ctx, fname, a).get(context-key);
);
_ => (
Expand All @@ -97,14 +97,14 @@ let blob-render(ctx: FContext, term: AST, f: Fragment): Fragment = (
App{ left:Lit{key:c":"}, right:App{ t=left, right:AType{} } } => blob-render(ctx, t, f);
App{ left:Var{k=key}, a=right } => (
if k.has-prefix(c":")
then f.set(tail-string(k), blob-render-simple(ctx, tail-string(k), a).second)
else f.set(c"expression", blob-render-simple(ctx, tail-string(k), a).second)
then f.set(tail(k), blob-render-simple(ctx, tail(k), a).second)
else f.set(c"expression", blob-render-simple(ctx, tail(k), a).second)
);
App{ rst=left, right:App{ left:Var{k=key}, a=right } } => (
f = blob-render(ctx, rst, f);
if k.has-prefix(c":")
then f.set(tail-string(k), blob-render-simple(ctx, tail-string(k), a).second)
else f.set(c"expression", blob-render-simple(ctx, tail-string(k), a).second)
then f.set(tail(k), blob-render-simple(ctx, tail(k), a).second)
else f.set(c"expression", blob-render-simple(ctx, tail(k), a).second)
);
_ => f.set(c"expression", blob-render-simple(ctx,c"expression",term).second);
}
Expand Down
2 changes: 1 addition & 1 deletion PLUGINS/BACKEND/C/compile-program-ordered.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let compile-program-ordered(global-ctx: FContext, program: AST): Nil = (
for vector g in program.unroll-seq { match g {
Glb{ key=key, val=val } => (
if not(typeof-term(def-to-sym(g)).is-open)
|| not(typeof-term(val).is-open) then {
or not(typeof-term(val).is-open) then {
std-c-compile-global(global-ctx, key.key, val);
};
);
Expand Down
6 changes: 3 additions & 3 deletions PLUGINS/BACKEND/C/escape-as-cstring.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ let .escape-as-cstring(in: CString): S = (
c"\\o".. rest => (out = out + SAtom(c"#"); in = rest;);
c"\\s".. rest => (out = out + SAtom(c" "); in = rest;);
c"\\t".. rest => (out = out + SAtom(c"\\\\t"); in = rest;);
c"\\".. rest => fail("Illegal Escape Character: \{head-string(rest)}");
c"\\".. rest => fail("Illegal Escape Character: \{head(rest)}");
rest => (
out = out + SAtom(clone-rope(head-string(rest)));
in = tail-string(rest);
out = out + SAtom(clone-rope(head(rest)));
in = tail(rest);
);
}};
SAtom(c"\"") + out + SAtom(c"\"")
Expand Down
14 changes: 7 additions & 7 deletions PLUGINS/BACKEND/C/escape-string.lsts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

let escape-string(s: CString): CString = (
let e = SNil;
while head-string(s) {
if head-string(s) == 92 {
s = tail-string(s);
match head-string(s) {
while head(s) {
if head(s) == 92 {
s = tail(s);
match head(s) {
58 => e = e + SAtom(c";"); # \: -> ;
91 => e = e + SAtom(c"("); # \[ -> (
92 => e = e + SAtom(c"\\"); # \\ -> \
Expand All @@ -16,10 +16,10 @@ let escape-string(s: CString): CString = (
115 => e = e + SAtom(c" "); # \s -> [space]
c => fail("Illegal Escape Sequence In String: \{c}\n");
};
s = tail-string(s);
s = tail(s);
} else {
e = e + SAtom(clone-rope(head-string(s)));
s = tail-string(s);
e = e + SAtom(clone-rope(head(s)));
s = tail(s);
}
};
clone-rope(e)
Expand Down
4 changes: 2 additions & 2 deletions PLUGINS/BACKEND/C/mangle-identifier.lsts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

let mangle-identifier(k: CString): S = (
let cs = SAtom(c"LM_");
while head-string(k) { match head-string(k) {
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_"); # %
Expand All @@ -28,7 +28,7 @@ let mangle-identifier(k: CString): S = (
124 => cs = cs + SAtom(c"_BR_"); # |
126 => cs = cs + SAtom(c"_TL_"); # ~
c => cs = cs + SAtom(clone-rope(c));
}; k = tail-string(k); };
}; k = tail(k); };
cs
);

Expand Down
2 changes: 1 addition & 1 deletion PLUGINS/BACKEND/C/std-c-compile-call.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let std-c-compile-call(ctx: FContext, fname: CString, return-hint-if-constructor
exit-error("STD C compile call is open \{fname} (\{typeof-term(args)})\n\{typeof-term(fterm)}\nArgs \{args}\n", args);
};
let push-args = std-c-compile-push-args(ctx, args);
let function-id = if typeof-term(fterm).is-t(c"FFI",0) || typeof-term(fterm).is-t(c"C-FFI",0)
let function-id = if typeof-term(fterm).is-t(c"FFI",0) or typeof-term(fterm).is-t(c"C-FFI",0)
then fname else mangle-identifier-function(fname, typeof-term(fterm));
let ictx = mk-fragment().set(c"function-id", SAtom(function-id));
let inner-ctx = mk-fctx().bind(c"ictx", t0(c"ImplicitContext"), ictx)
Expand Down
2 changes: 1 addition & 1 deletion PLUGINS/BACKEND/C/std-c-compile-destructure-args.lsts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

let std-c-compile-destructure-args(ctx: FContext, lhs: AST, is-fragment: U64): FContext = (
let std-c-compile-destructure-args(ctx: FContext, lhs: AST, is-fragment: Bool): FContext = (
match lhs {
App{ rst=left, right:App{ left:Lit{key:c":"}, right:App{ lhs-v=left:Var{k=key}, right:AType{kt=tt} } } } => (
ctx = std-c-compile-destructure-args(ctx, rst, is-fragment);
Expand Down
32 changes: 16 additions & 16 deletions PLUGINS/BACKEND/C/std-c-compile-expr.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
f = f.set(c"expression", v.get(c"expression") + SAtom(c":"));
} else {
(let pre, let post) = std-c-mangle-declaration(lt, t);
if config-v3 or config-v1 or config-v0 {
if config-v3 or config-v23 or config-v1 or config-v0 {
f = f.set(c"frame",
f.get(c"frame") + pre + SAtom(c" ")
+ v.get(c"expression")
Expand Down Expand Up @@ -170,15 +170,15 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
);
Lit{val=key} => (
let tt = typeof-term(t);
if tt.is-t(c"C",1) && tt.r1.is-t(c"uint8_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) && tt.r1.is-t(c"uint06_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) && tt.r1.is-t(c"uint22_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) && tt.r1.is-t(c"uint64_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) && tt.r1.is-t(c"int8_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) && tt.r1.is-t(c"int06_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) && tt.r1.is-t(c"int22_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) && tt.r1.is-t(c"int64_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) && tt.r1.is-t(c":Label",0) then mk-expression(val)
if tt.is-t(c"C",1) and tt.r1.is-t(c"uint8_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) and tt.r1.is-t(c"uint06_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) and tt.r1.is-t(c"uint22_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) and tt.r1.is-t(c"uint64_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) and tt.r1.is-t(c"int8_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) and tt.r1.is-t(c"int06_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) and tt.r1.is-t(c"int22_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) and tt.r1.is-t(c"int64_t",0) then mk-expression(val)
else if tt.is-t(c"C",1) and tt.r1.is-t(c":Label",0) then mk-expression(val)
else if tt.is-t(c"L",0) then mk-expression(val)
else if tt.is-t(c"CString",0) then mk-expression(val.escape-as-cstring)
else if tt.slot(c"Array",2).l1.slot(c"C",1).l1.is-t(c"char",0) then mk-expression(val.escape-as-cstring)
Expand All @@ -190,9 +190,9 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
SAtom(c"{int return_code = regcomp(&") + SAtom(rgx-id) + SAtom(c", ") +
val.escape-as-cstring + SAtom(c", REG_EXTENDED); if(return_code){ fprintf(stderr,\"Could not compile regex.\"); exit(1);}};\n");
mk-expression(rgx-id);
} else if tt.is-datatype && tt.is-t(c"List",1) && val==c"LEOF" {
} else if tt.is-datatype and tt.is-t(c"List",1) and val==c"LEOF" {
std-c-compile-call(ctx, val, typeof-term(t), mk-nil());
} else if tt.is-datatype && tt.is-t(c"HashtableEq",2) && val==c"HashtableEqEOF" {
} else if tt.is-datatype and tt.is-t(c"HashtableEq",2) and val==c"HashtableEqEOF" {
std-c-compile-call(ctx, val, typeof-term(t), mk-nil());
} else { match val {
c"True" => mk-expression(c"(1)");
Expand Down Expand Up @@ -239,14 +239,14 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
e
);
App{ is-cons=is-cons, left=left, right=right } => (
if not(is-cons) && typeof-term(left).is-arrow {
if not(is-cons) and typeof-term(left).is-arrow {
match left {
Var{fname=key:c"<:"} => (
match right {
App{ lt=left, rt=right } => (
let lt-tt = typeof-term(lt);
let rt-tt = typeof-term(rt);
if lt-tt.is-t(c"Type",1) && rt-tt.is-t(c"Type",1)
if lt-tt.is-t(c"Type",1) and rt-tt.is-t(c"Type",1)
then (
let lt-val = denormalize(lt-tt.slot(c"Type",1).l1);
let rt-val = denormalize(rt-tt.slot(c"Type",1).l1);
Expand All @@ -263,7 +263,7 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
App{ lt=left, rt=right } => (
let lt-tt = typeof-term(lt);
let rt-tt = typeof-term(rt);
if lt-tt.is-t(c"Type",1) && rt-tt <: t1(c"Type",t0(c"CString")).rewrite-type-alias
if lt-tt.is-t(c"Type",1) and rt-tt <: t1(c"Type",t0(c"CString")).rewrite-type-alias
then (
let lt-val = lt-tt.slot(c"Type",1).l1.into(type(String)).into(type(CString));
mk-expression(lt-val.escape-as-cstring)
Expand Down Expand Up @@ -315,7 +315,7 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
mk-fragment();
);
};
if is-stmt && non-zero(f.get(c"expression")) then f = f.set(c"expression", f.get(c"expression") + SAtom(c";"));
if is-stmt and non-zero(f.get(c"expression")) then f = f.set(c"expression", f.get(c"expression") + SAtom(c";"));
f.context = close(ctx);
f.type = typeof-term(t); f
);
Expand Down
Loading
Loading