Skip to content

Commit 28286ca

Browse files
committed
many more fixes
1 parent 341e30b commit 28286ca

10 files changed

Lines changed: 39 additions & 27 deletions

PLUGINS/BACKEND/C/blob-render.lsts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let blob-render-simple(ctx: FContext, context-key: CString, term: AST): (FContex
5353
let ri = to-i64(clone-rope(rs));
5454
while li < ri {
5555
ri = ri - 1;
56-
r = SCons( close(SAtom(to-string(ri))), close(r) );
56+
r = SCons( close(SAtom(ri.into(type(CString)))), close(r) );
5757
}
5858
);
5959
App{ left:Var{key:c"uuid"} } => r = SAtom(uuid());
@@ -72,7 +72,7 @@ let blob-render-simple(ctx: FContext, context-key: CString, term: AST): (FContex
7272
if typeof-term(f).is-arrow { match f {
7373
Var{fname=key} => (
7474
if fname.has-prefix(c":")
75-
then r = blob-render-simple(ctx, tail-string(fname), a).second
75+
then r = blob-render-simple(ctx, tail(fname), a).second
7676
else r = std-c-compile-call(ctx, fname, a).get(context-key);
7777
);
7878
_ => (
@@ -97,14 +97,14 @@ let blob-render(ctx: FContext, term: AST, f: Fragment): Fragment = (
9797
App{ left:Lit{key:c":"}, right:App{ t=left, right:AType{} } } => blob-render(ctx, t, f);
9898
App{ left:Var{k=key}, a=right } => (
9999
if k.has-prefix(c":")
100-
then f.set(tail-string(k), blob-render-simple(ctx, tail-string(k), a).second)
101-
else f.set(c"expression", blob-render-simple(ctx, tail-string(k), a).second)
100+
then f.set(tail(k), blob-render-simple(ctx, tail(k), a).second)
101+
else f.set(c"expression", blob-render-simple(ctx, tail(k), a).second)
102102
);
103103
App{ rst=left, right:App{ left:Var{k=key}, a=right } } => (
104104
f = blob-render(ctx, rst, f);
105105
if k.has-prefix(c":")
106-
then f.set(tail-string(k), blob-render-simple(ctx, tail-string(k), a).second)
107-
else f.set(c"expression", blob-render-simple(ctx, tail-string(k), a).second)
106+
then f.set(tail(k), blob-render-simple(ctx, tail(k), a).second)
107+
else f.set(c"expression", blob-render-simple(ctx, tail(k), a).second)
108108
);
109109
_ => f.set(c"expression", blob-render-simple(ctx,c"expression",term).second);
110110
}

PLUGINS/BACKEND/C/escape-as-cstring.lsts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ let .escape-as-cstring(in: CString): S = (
1313
c"\\o".. rest => (out = out + SAtom(c"#"); in = rest;);
1414
c"\\s".. rest => (out = out + SAtom(c" "); in = rest;);
1515
c"\\t".. rest => (out = out + SAtom(c"\\\\t"); in = rest;);
16-
c"\\".. rest => fail("Illegal Escape Character: \{head-string(rest)}");
16+
c"\\".. rest => fail("Illegal Escape Character: \{head(rest)}");
1717
rest => (
18-
out = out + SAtom(clone-rope(head-string(rest)));
19-
in = tail-string(rest);
18+
out = out + SAtom(clone-rope(head(rest)));
19+
in = tail(rest);
2020
);
2121
}};
2222
SAtom(c"\"") + out + SAtom(c"\"")

PLUGINS/BACKEND/C/escape-string.lsts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
let escape-string(s: CString): CString = (
33
let e = SNil;
4-
while head-string(s) {
5-
if head-string(s) == 92 {
6-
s = tail-string(s);
7-
match head-string(s) {
4+
while head(s) {
5+
if head(s) == 92 {
6+
s = tail(s);
7+
match head(s) {
88
58 => e = e + SAtom(c";"); # \: -> ;
99
91 => e = e + SAtom(c"("); # \[ -> (
1010
92 => e = e + SAtom(c"\\"); # \\ -> \
@@ -16,10 +16,10 @@ let escape-string(s: CString): CString = (
1616
115 => e = e + SAtom(c" "); # \s -> [space]
1717
c => fail("Illegal Escape Sequence In String: \{c}\n");
1818
};
19-
s = tail-string(s);
19+
s = tail(s);
2020
} else {
21-
e = e + SAtom(clone-rope(head-string(s)));
22-
s = tail-string(s);
21+
e = e + SAtom(clone-rope(head(s)));
22+
s = tail(s);
2323
}
2424
};
2525
clone-rope(e)

PLUGINS/BACKEND/C/mangle-identifier.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
let mangle-identifier(k: CString): S = (
33
let cs = SAtom(c"LM_");
4-
while head-string(k) { match head-string(k) {
4+
while head(k) != 0 { match head(k) {
55
33 => cs = cs + SAtom(c"_EX_"); # !
66
36 => cs = cs + SAtom(c"_DL_"); # $
77
37 => cs = cs + SAtom(c"_MD_"); # %
@@ -28,7 +28,7 @@ let mangle-identifier(k: CString): S = (
2828
124 => cs = cs + SAtom(c"_BR_"); # |
2929
126 => cs = cs + SAtom(c"_TL_"); # ~
3030
c => cs = cs + SAtom(clone-rope(c));
31-
}; k = tail-string(k); };
31+
}; k = tail(k); };
3232
cs
3333
);
3434

PLUGINS/BACKEND/C/std-c-compile-destructure-args.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
let std-c-compile-destructure-args(ctx: FContext, lhs: AST, is-fragment: U64): FContext = (
2+
let std-c-compile-destructure-args(ctx: FContext, lhs: AST, is-fragment: Bool): FContext = (
33
match lhs {
44
App{ rst=left, right:App{ left:Lit{key:c":"}, right:App{ lhs-v=left:Var{k=key}, right:AType{kt=tt} } } } => (
55
ctx = std-c-compile-destructure-args(ctx, rst, is-fragment);

PLUGINS/BACKEND/C/std-c-compile-global.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
107107
let text = SNil();
108108
if not(config-strip-debug) and loc.filename != c"Unknown" {
109109
text = text + SAtom(c"\n#line ");
110-
text = text + SAtom(to-string(loc.line));
110+
text = text + SAtom(loc.line.into(type(CString)));
111111
text = text + SAtom(c" \"");
112112
text = text + SAtom(loc.filename);
113113
text = text + SAtom(c"\"\n");
@@ -130,7 +130,7 @@ let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
130130
let text = SNil();
131131
if not(config-strip-debug) and loc.filename != c"Unknown" {
132132
text = text + SAtom(c"\n#line ");
133-
text = text + SAtom(to-string(loc.line));
133+
text = text + SAtom(loc.line.into(type(CString)));
134134
text = text + SAtom(c" \"");
135135
text = text + SAtom(loc.filename);
136136
text = text + SAtom(c"\"\n");

PLUGINS/BACKEND/C/std-c-compile-type-typedef.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let std-c-compile-type-typedef-concrete(tctx: Maybe<TypeContext>, concrete-type:
6666
if case-tag!=c"" and case-fields.length > 0 {
6767
assemble-types-section = assemble-types-section + SAtom(c" struct {\n");
6868
for vector Tuple{field-name=first, field-type=second} in case-fields {
69-
let mangled-field-name = to-string(case-number) + c"_" + field-name;
69+
let mangled-field-name = case-number.into(type(CString)) + c"_" + field-name;
7070
field-type = tctx.substitute(field-type);
7171
(let pre-tt, let post-tt) = std-c-mangle-declaration(field-type, td);
7272
assemble-types-section = assemble-types-section + SAtom(c" ") + pre-tt + SAtom(c" ") + mangle-identifier(mangled-field-name) + post-tt + SAtom(c";\n");

PLUGINS/FRONTEND/C/c-ast-to-lm-ast.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ let std-c-decorate-pointer(tt: Type, ptr: CTerm): Type = (
608608

609609
let std-c-type-of-integer(i: String): Type = (
610610
if i.has-prefix("-") {
611-
let n = to-u64(untern(tail-string(i)));
611+
let n = to-u64(untern(tail(i)));
612612
if n <= 128 then t1(c"C",t0(c"uint8_t")) else
613613
if n <= 32768 then t1(c"C",t0(c"uint06_t")) else
614614
if n <= 2147483648 then t1(c"C",t0(c"uint22_t")) else

lib2/core/baremetal-into.lsts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ let .into(i: I64, tt: Type<String>): String = (
3232
String(0 as USize, cs-length, od)
3333
);
3434

35-
let .into(i: U64, tt: Type<CString>): CString = (
36-
i.into(type(String)).into(type(CString))
37-
);
38-
3935
let .into(i: U64, tt: Type<String>): String = (
4036
let od = mk-owned-data(type(U8), 20_sz);
4137
let cs-length = 0_sz;
@@ -135,3 +131,8 @@ let read-file(fp: CString): CString = (
135131
let v = read-binary-file-to(mk-vector(type(U8)), fp);
136132
v.buffer-into-string.into(type(CString))
137133
);
134+
135+
let .into(i: x, tt: Type<CString>): CString = (
136+
i.into(type(String)).into(type(CString))
137+
);
138+

lib2/core/i64.lsts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ let cmp(l: I64, r: I64): Ord = (
3838
let abs(i: I64): I64 = if i<0 then 0_i64 - i else i;
3939

4040
let hash(x: I64): U64 = x as U64;
41+
42+
let to-i64(s: CString): I64 = (
43+
let negative = false;
44+
if head(s)==45 {
45+
negative = true;
46+
s = tail(s);
47+
};
48+
let base = to-u64(s) as I64;
49+
if negative then base = 0_i64 - base;
50+
base
51+
);

0 commit comments

Comments
 (0)