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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CC = clang
CFLAGS = -w -O2 -march=native -mtune=native

dev: install-production
time lm --v2 tests/promises/lm-ascript/ascript-integrated.lsts
time lm --v2 tests/promises/string/prefix.lsts
gcc tmp.c
./a.out

Expand Down
1 change: 1 addition & 0 deletions lib2/core/baremetal.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ import lib2/core/cstring.lsts;
import lib2/core/array.lsts;
import lib2/core/io.lsts;
import lib2/core/cmp.lsts;
import lib2/core/c_int.lsts;

let config-v23 = true;
21 changes: 21 additions & 0 deletions lib2/core/c_int.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

declare-binop( $"!=", raw-type(C<"int">), raw-type(C<"int">), raw-type(Bool), ( l"("; x; l"!="; y; l")"; ) );
declare-binop( $"==", raw-type(C<"int">), raw-type(C<"int">), raw-type(Bool), ( l"("; x; l"=="; y; l")"; ) );
declare-binop( $"<", raw-type(C<"int">), raw-type(C<"int">), raw-type(Bool), ( l"("; x; l"<"; y; l")"; ) );
declare-binop( $"<=", raw-type(C<"int">), raw-type(C<"int">), raw-type(Bool), ( l"("; x; l"<="; y; l")"; ) );
declare-binop( $">", raw-type(C<"int">), raw-type(C<"int">), raw-type(Bool), ( l"("; x; l">"; y; l")"; ) );
declare-binop( $">=", raw-type(C<"int">), raw-type(C<"int">), raw-type(Bool), ( l"("; x; l">="; y; l")"; ) );

declare-binop( $"&", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l"&"; y; l")"; ) );
declare-binop( $"|", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l"|"; y; l")"; ) );
declare-binop( $"^", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l"^"; y; l")"; ) );
declare-binop( $"+", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l"+"; y; l")"; ) );
declare-binop( $"-", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l"-"; y; l")"; ) );
declare-binop( $"/", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l"/"; y; l")"; ) );
declare-binop( $"%", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l"%"; y; l")"; ) );
declare-binop( $"*", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l"*"; y; l")"; ) );

declare-binop( $"<<", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l"<<"; y; l")"; ) );
declare-binop( $">>", raw-type(C<"int">), raw-type(C<"int">), raw-type(C<"int">), ( l"("; x; l">>"; y; l")"; ) );

declare-unop( $"~", raw-type(C<"int">), raw-type(C<"int">), ( l"((uint64_t)(~"; x; l"))"; ) );
6 changes: 6 additions & 0 deletions lib2/core/platform-macros.lsts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

deprecated macro (rl"declare-zop"(op-alias, r-type, op-expr)) (
let :Blob op-alias(): r-type = (
$":expression"(op-expr);
);
);

deprecated macro (rl"declare-unop"(op-alias, x-type, r-type, op-expr)) (
let :Blob op-alias(x: x-type): r-type = (
$":expression"(op-expr);
Expand Down
37 changes: 27 additions & 10 deletions lib2/core/regex.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,33 @@ let :Blob .rm_eo(t: C<"regmatch_t">): U64 = (
$":expression"( l"("; $":expression"(t); l".rm_eo)"; );
);

declare-binop( $"set.rm_so", raw-type(C<"regmatch_t">), raw-type(U64), raw-type(Nil), ( l"("; x; l".rm_so="; y; l")"; ) );
declare-binop( $"set.rm_eo", raw-type(C<"regmatch_t">), raw-type(U64), raw-type(Nil), ( l"("; x; l".rm_eo="; y; l")"; ) );

declare-ternop( $"set.rm_so", raw-type(C<"regmatch_t">[]), raw-type(USize), raw-type(U64), raw-type(Nil), ( l"("; x; l"["; y; l"].rm_so="; z; l")"; ) );
declare-ternop( $"set.rm_eo", raw-type(C<"regmatch_t">[]), raw-type(USize), raw-type(U64), raw-type(Nil), ( l"("; x; l"["; y; l"].rm_eo="; z; l")"; ) );

declare-zop( $"reg_startend", raw-type(C<"int">), l"REG_STARTEND" );
declare-zop( $"reg_nomatch", raw-type(C<"int">), l"REG_NOMATCH" );

let .has-prefix(text: String, rgx: Regex): Bool = (
# TODO: fix this mess. The preprocessor is unpacking these erroneously
# macros 2.0 doesn't have this problem, but this code still needs to be updated after swapping
let a1 = &rgx as C<"regex_t">[];
let a2 = (text.data.data + text.start-offset) as C<"char">[];
let a3 = 0 as C<"size_t">;
let a4 = 0 as C<"regmatch_t">[];
let a5 = 0 as C<"int">;
let a4 = () : C<"regmatch_t">[1];
a4[0].rm_so = 0;
a4[0].rm_eo = text.length;
let a5 = reg_startend();
let status = regexec(
a1,
a2,
a3,
a4,
a4 as C<"regmatch_t">[],
a5
);
(status as U64) == 0
status != reg_nomatch() and a4[0].rm_so==0
);

let $"=="(text: CString, rgx: Regex): Bool = (
Expand All @@ -42,43 +53,49 @@ let $"=="(text: CString, rgx: Regex): Bool = (
a4,
a5
);
(status as U64)==0 and matches[0].rm_so==0 and matches[0].rm_eo==text.length
status != reg_nomatch() and matches[0].rm_so==0 and matches[0].rm_eo==text.length
);

let .remove-prefix(text: String, rgx: Regex): String? = (
let matches = () : C<"regmatch_t">[1];
matches[0].rm_so = 0;
matches[0].rm_eo = text.length;
let a1 = &rgx as C<"regex_t">[];
let a2 = (text.data.data + text.start-offset) as C<"char">[];
let a3 = 1 as C<"size_t">;
let a4 = matches as C<"regmatch_t">[];
let a5 = 0 as C<"int">;
let a5 = reg_startend();
let status = regexec(
a1,
a2,
a3,
a4,
a5
);
if matches[0].rm_so != 0 then (None : String?)
if status == reg_nomatch() then (None : String?)
else if matches[0].rm_so != 0 then (None : String?)
else if matches[0].rm_eo == 0 then (None : String?)
else Some(text[matches[0].rm_eo as I64 : ])
else Some(text[matches[0].rm_eo as I64 : ]);
);

let .get-prefix(text: String, rgx: Regex): String? = (
let matches = () : C<"regmatch_t">[1];
matches[0].rm_so = 0;
matches[0].rm_eo = text.length;
let a1 = &rgx as C<"regex_t">[];
let a2 = (text.data.data + text.start-offset) as C<"char">[];
let a3 = 1 as C<"size_t">;
let a4 = matches as C<"regmatch_t">[];
let a5 = 0 as C<"int">;
let a5 = reg_startend();
let status = regexec(
a1,
a2,
a3,
a4,
a5
);
if matches[0].rm_so != 0 then (None : String?)
if status == reg_nomatch() then (None : String?)
else if matches[0].rm_so != 0 then (None : String?)
else if matches[0].rm_eo == 0 then (None : String?)
else Some(text[0_i64 : matches[0].rm_eo as I64])
);
3 changes: 3 additions & 0 deletions tests/promises/string/prefix.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ assert( " ".remove-prefix(r/^[a-zA-Z0-9_-]+/) == (None : String?) );

assert( " import "[1_u64:].remove-prefix(r/^[a-zA-Z0-9_-]+/) == Some(" ") );
assert( " "[1_u64:].remove-prefix(r/^[a-zA-Z0-9_-]+/) == (None : String?) );

assert( "ORANGEAPPLE"[:6_u64].remove-prefix(r/APPLE/) == (None : String?) );
assert( not("ORANGEAPPLE"[:6_u64].has-prefix(r/APPLE/)) );
Loading