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
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
CC = clang
CFLAGS = -w -O2 -march=native -mtune=native
LSTSFLAGS = MALLOC_CHECK_=3

dev: install-production
time lm --v2 tests/promises/string/prefix.lsts
gcc tmp.c
./a.out
$(LSTSFLAGS) ./a.out

build: compile-production
time ./production --v2 --c -o deploy1.c SRC/index.lsts
time env $(LSTSFLAGS) ./production --v2 --c -o deploy1.c SRC/index.lsts
$(CC) $(CFLAGS) deploy1.c -o deploy1
time ./deploy1 --v2 --c -o deploy2.c SRC/index.lsts
time env $(LSTSFLAGS) ./deploy1 --v2 --c -o deploy2.c SRC/index.lsts
diff deploy1.c deploy2.c
mv deploy1.c BOOTSTRAP/cli.c
rm -f deploy1 deploy1.c deploy2.c
Expand All @@ -26,7 +27,7 @@ valgrind-view:

gprof:
$(CC) $(CFLAGS) -pg -o bootstrap.exe BOOTSTRAP/cli.c
./bootstrap.exe SRC/index.lsts
$(LSTSFLAGS) ./bootstrap.exe SRC/index.lsts

gprof-view-count:
gprof bootstrap.exe gmon.out | less
Expand All @@ -44,7 +45,7 @@ compile-bootstrap:

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

Expand Down
8 changes: 4 additions & 4 deletions lib2/core/baremetal-into.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ let clone-rope(s: U8): CString = (

# TODO: optimize, this is really inefficient
let .replace(base: CString, pat: CString, n: CString): CString = (
let r = SNil;
let r = c"";
while head(base)!=0 {
if base.has-prefix(pat) {
base = base.remove-prefix(pat).get-or(c"");
r = r + SAtom(n);
r = r + n;
} else {
r = r + SAtom(clone-rope(head(base)));
r = r + clone-rope(head(base));
base = tail(base);
}
};
clone-rope(r);
r
);

let read-binary-file-to(out: Vector<U8>, path: CString): Vector<U8> = (
Expand Down
6 changes: 5 additions & 1 deletion lib2/core/bedrock-cstring.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ let .remove-prefix(base: CString, prefix: CString): CString? = (
let base_length = base.length;
let prefix_length = prefix.length;
let buf = malloc(base_length - prefix_length + 1) as C<"char">[];
strcat(buf, (base as C<"char">[])+prefix_length);
let si = 0_sz;
while si < (base_length - prefix_length) {
buf[si] = base[prefix_length+si] as C<"char">;
si = si + 1;
};
buf[base_length - prefix_length] = 0 as C<"char">;
Some(buf as CString)
}
Expand Down
7 changes: 5 additions & 2 deletions lib2/core/cstring.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ let hash(key: CString): U64 = (
);

let $"+"(l: CString, r: CString): CString = (
let buf = malloc(l.length + r.length + 1) as C<"char">[];
let l-length = l.length;
let r-length = r.length;
let buf = malloc(l-length + r-length + 1) as C<"char">[];

memset(buf.void-pointer, 0, l.length+r.length+1);
memset(buf.void-pointer, 0, l-length+r-length+1);
strcat(buf, l as C<"char">[]);
strcat(buf, r as C<"char">[]);
buf[l-length+r-length] = 0 as C<"char">;
buf as CString
);

Expand Down
2 changes: 1 addition & 1 deletion lib2/core/s.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let $"SAtom"(key: CString): S = SAtom(key.into(type(String)));
let clone-rope(s: S): CString = (
let out = mk-vector(type(U8));
out = clone-rope-impl(s, out);
out.buffer-into-string.into(type(CString))
out.buffer-into-cstring
);

let clone-rope-impl(s: S, out: Vector<U8>): Vector<U8> = (
Expand Down
5 changes: 5 additions & 0 deletions tests/promises/cstring/comparison.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ assert( not(c"abcd".contains(c"e")) );
assert( c"abcd".remove-prefix(c"") == Some(c"abcd") );
assert( c"abcd".remove-prefix(c"ab") == Some(c"cd") );
assert( c"abcd".remove-prefix(c"cd") == (None : CString?) );
assert( c"abcd".remove-prefix(c"abcd") == Some(c"") );

assert( c"abcd".remove-suffix(c"") == Some(c"abcd") );
assert( c"abcd".remove-suffix(c"cd") == Some(c"ab") );
assert( c"abcd".remove-suffix(c"ab") == (None : CString?) );
assert( c"abcd".remove-suffix(c"abcd") == Some(c"") );

assert( c"abcdef".split(c"cd") == mk-vector(type(CString)).push(c"ab").push(c"ef") );

assert( c"dabababd".replace(c"ab",c"c") == c"dcccd" );

Loading