Skip to content

Commit ea0d57a

Browse files
macro application succeeds
1 parent d09646b commit ea0d57a

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

PLATFORM/C/LIB/common-macros.lsts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ typed macro macro::lhs-field(base: lazy, field: lazy): lazy = (
3232
);
3333

3434
typed macro macro::lhs-as-rhs(base field: macro::lhs-index): lazy = (
35-
macro::concat(l".", field)(base)
35+
$"macro::concat"(l".", field)(base)
3636
);
3737

38-
typed macro macro::lhs-index(base: lazy, field: lazy): lazy = (
39-
base; field
38+
typed macro macro::lhs-index(base: lazy, index: lazy): lazy = (
39+
base; index
40+
);
41+
42+
typed macro macro::lhs-index(base field: macro::lhs-field, index: lazy): lazy = (
43+
$"macro::concat"($".", field); index
4044
);
4145

4246
typed macro macro::for(item: lazy, iter: List<?>, loop: lazy): lazy = (

PLUGINS/FRONTEND/LSTS/lsts-parse.lsts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let lsts-parse-identifier(tokens: List<Token>): Tuple<CString, List<Token>> = (
3535
if lsts-parse-head(tokens)==c"." { name = c"."; tokens = tail(tokens); };
3636
lsts-parse-expect(c"Identifier", lsts-is-ident-head(lsts-parse-head(tokens)), tokens);
3737
name = name + lsts-unwrap-identifier(lsts-parse-head(tokens)); tokens = tail(tokens);
38-
while lsts-parse-head(tokens)==c":" && lsts-parse-head(tail(tokens))==c":" {
38+
while lsts-parse-head(tokens)==c":" && lsts-parse-head(tail(tokens))==c":" && lsts-is-ident-head(lsts-parse-head(tail(tail(tokens)))) {
3939
name = name + c"::"; tokens = tail(tokens); tokens = tail(tokens);
4040
lsts-parse-expect(c"Identifier", lsts-is-ident-head(lsts-parse-head(tokens)), tokens);
4141
name = name + lsts-unwrap-identifier(lsts-parse-head(tokens)); tokens = tail(tokens);
@@ -525,10 +525,14 @@ let lsts-make-maybe-var(tokens: List<Token>): Tuple<AST,List<Token>> = (
525525
lsts-parse-lit(tokens)
526526
} else {
527527
if not(non-zero(tokens)) { lsts-parse-expect(c"Identifier", tokens); };
528-
let t = head(tokens);
529-
let base = Var { lsts-unwrap-identifier(t.key), lsts-unwrap-identifier(t) };
530-
if lsts-is-lit(t.key) { base = lsts-make-lit(t); };
531-
tokens = tail(tokens);
528+
let base = ASTEOF;
529+
if lsts-is-lit(head(tokens).key) {
530+
base = lsts-make-lit(head(tokens));
531+
tokens = tail(tokens);
532+
} else {
533+
(let var-name, tokens) = lsts-parse-identifier(tokens);
534+
base = mk-var(var-name);
535+
};
532536
Tuple { base, tokens }
533537
}
534538
);

SRC/std-apply-macro.lsts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ let std-apply-macro(tctx: Maybe<TContext>, mname: CString, margs: AST, strong: B
6060
};
6161
if strong && not(non-zero(result)) then exit-error("Failed to Apply Macro: \{mname}\nArgs: \{margs}\n", margs);
6262
if strong then (tctx, result) = std-infer-expr(tctx, result, false, Used, TAny);
63+
print("Applied \{mname} \{margs}\nResult \{result}\n");
6364
(tctx, result)
6465
);
6566

SRC/std-direct-destructure-macro.lsts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ let std-direct-destructure-macro(margs: AST, mstruct: AST): AContext? = (
33
let no = None :: AContext?;
44
match (margs, mstruct) {
55
Tuple{ val=first, second:Var{key=key} } => Some{[(key,val)]};
6-
Tuple{
7-
first:App{is-cons:1_u8, lrest=left, val=right },
8-
second:App{is-cons:1_u8, rrest=left, right:Var{key=key} }
9-
} => (
6+
Tuple{ first:App{lrest=left, val=right}, second:App{rrest=left, right:Var{key=key}} } => (
107
let ctx = std-direct-destructure-macro(lrest, rrest);
118
if ctx.is-some then Some{cons((key,val), ctx.get-or-panic)} else no;
129
);

0 commit comments

Comments
 (0)