Skip to content

Commit 3f3c6f4

Browse files
location is unknown
1 parent 638a6ad commit 3f3c6f4

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

PLATFORM/C/LIB/common-macros.lsts

+4
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ typed macro macro::for(item: lazy, iter: Vector<?>, loop: lazy): lazy = (
6666
typed macro macro::while(cond: lazy, body: lazy): lazy = (
6767
primitive::while( body as Nil, into-branch-conditional(cond) )
6868
);
69+
70+
typed macro macro::assert(cond: lazy): lazy = (
71+
if not(cond) then fail("Assertion Failed", macro::location(here))
72+
);

PLATFORM/C/LIB/io.lm

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ fail := λ(: msg SmartString). (: (
1919
(as (exit 1_u32) Never)
2020
) Never);
2121

22+
fail := λ(: msg SmartString)(: loc SmartString). (: (
23+
(print msg)(print '\sat\s_s)(print loc)
24+
(as (exit 1_u32) Never)
25+
) Never);
26+
2227
fail := λ(: msg String). (: (
2328
(print msg)
2429
(as (exit 1_u32) Never)

PLUGINS/FRONTEND/LSTS/lsts-parse.lsts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1286,9 +1286,7 @@ let lsts-make-lit(t: Token): AST = (
12861286
while non-zero(s) && s != c"_ss" {
12871287
if s.has-prefix(c"\\{") {
12881288
if non-zero(buffer) {
1289-
buffer = buffer + SAtom{c"_ss"};
1290-
let bs = clone-rope(buffer);
1291-
let be = Lit { bs, with-location(mk-token(bs),loc) };
1289+
let be = mk-lit(with-location(mk-token(clone-rope(buffer)),loc)).ascript(t1(c"SmartString"));
12921290
if non-zero(base) {
12931291
base = mk-app(
12941292
Var{ c"+", with-location(mk-token("+"),loc) },
@@ -1330,9 +1328,7 @@ let lsts-make-lit(t: Token): AST = (
13301328
}
13311329
};
13321330
if non-zero(buffer) {
1333-
buffer = buffer + SAtom{ c"_ss" };
1334-
let bs = clone-rope(buffer);
1335-
let be = Lit{ bs, with-location(mk-token(bs),loc) };
1331+
let be = mk-lit(with-location(mk-token(clone-rope(buffer)),loc)).ascript(t1(c"SmartString"));
13361332
if non-zero(base) {
13371333
base = mk-app(
13381334
Var{ c"+", with-location(mk-token("+"),loc) },
@@ -1342,6 +1338,8 @@ let lsts-make-lit(t: Token): AST = (
13421338
base = be;
13431339
};
13441340
};
1341+
} else if t.key.has-suffix(c"_ss") {
1342+
base = with-location(mk-lit(t.key.remove-suffix(c"_ss")),loc).ascript(t1(c"SmartString"));
13451343
};
13461344
base
13471345
);
@@ -1493,6 +1491,8 @@ let lsts-parse-atom-without-tail(tokens: List<Token>): Tuple<AST,List<Token>> =
14931491
tokens = term-rest.second;
14941492
lsts-parse-expect(c")", tokens); tokens = tail(tokens);
14951493
term = AType{ term-rest.first };
1494+
} else if lsts-parse-head(tokens).has-suffix(c"_ss") {
1495+
(term, tokens) = lsts-parse-lit(tokens);
14961496
} else if lsts-parse-head(tokens)==c"sizeof" {
14971497
let loc = head(tokens).location;
14981498
tokens = tail(tokens);

SRC/macro-table.lsts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
let index-macro-table = {} :: HashtableEq<CString,List<(Type,Type,AST)>>;
33
index-macro-table = index-macro-table.bind(c"macro::concat", [] :: List<(Type,Type,AST)>);
4+
index-macro-table = index-macro-table.bind(c"macro::location", [] :: List<(Type,Type,AST)>);
45

56
let bind-new-macro(mname: CString, mterm: AST): Nil = (
67
let row = index-macro-table.lookup(mname, [] :: List<(Type,Type,AST)>);

SRC/std-apply-macro.lsts

+5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ let std-apply-macro-concat(tctx: Maybe<TContext>, mname: CString, margs: AST): (
1717
}
1818
);
1919

20+
let std-apply-macro-location(tctx: Maybe<TContext>, mname: CString, margs: AST): (TContext?, AST) = (
21+
(tctx, mk-lit(to-smart-string(margs.location)).ascript(t1(c"SmartString")))
22+
);
23+
2024
let std-apply-macro(tctx: Maybe<TContext>, mname: CString, margs: AST, strong: Bool): (TContext?, AST) = (
2125
let result = ASTEOF;
2226
if mname==c"macro::concat" then (tctx, result) = std-apply-macro-concat(tctx, mname, margs)
27+
else if mname==c"macro::location" then (tctx, result) = std-apply-macro-location(tctx, mname, margs)
2328
else {
2429
let row = index-macro-table.lookup(mname, [] :: List<(Type,Type,AST)>);
2530
let peep-holes = TAny;

tests/unit/ast-macros.lsts

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type A = A{a:U64};
3030
macro::while( wi < 4, ( print(wi); wi = wi + 1; ) )
3131
);
3232

33+
macro::assert(true);
34+
macro::assert(false);
35+
3336
# assert
3437

3538
# match

0 commit comments

Comments
 (0)