Skip to content

Commit cd56903

Browse files
passing typecheck
1 parent ad65b6d commit cd56903

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

PLATFORM/C/LIB/common-macros.lsts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ typed macro macro::set(lhs: lazy, rhs: lazy): lazy = (
77
mov(rhs, lhs)
88
);
99

10-
typed macro macro::set(base field: macro::lhs-field, rhs: lazy): lazy = (
11-
macro::concat(l"set.", field) (base, rhs)
12-
);
10+
#typed macro macro::set(base field: macro::lhs-field, rhs: lazy): lazy = (
11+
# macro::concat(l"set.", field) (base, rhs)
12+
#);
1313

1414
typed macro macro::set(base index: macro::lhs-index, rhs: lazy): lazy = (
1515
$"set[]"( $"macro::lhs-as-rhs"(base), index, rhs )

SRC/std-apply-macro-candidates.lsts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ let std-apply-macro-candidates(tctx: TContext?, mname: CString, margs: AST, cand
1414
if mctx.is-some then t = with-location(substitute(mctx.get-or-panic, mrhs), margs.location);
1515
}
1616
};
17-
if not(non-zero(t)) then fail("Macro Application failed match during destructuring: \{mname}\n");
1817
(tctx, t) = std-infer-expr(tctx, t, false, Used, TAny);
1918
(tctx, t)
2019
);
@@ -44,8 +43,10 @@ let std-try-destructure-macro(tctx: TContext?, margs: AST, mtype: Type, mcandida
4443
App{left:Lit{key:c":"}, right:App{mstruct=left, right:AType{tt=tt}}} => (
4544
if non-zero(std-macro-helper-name(tt))
4645
then {
47-
(tctx, let helped) = std-apply-macro(tctx, std-macro-helper-name(tt), margs);
48-
(tctx, std-direct-destructure-macro(helped, mstruct))
46+
(tctx, let helped) = std-apply-macro-weak(tctx, std-macro-helper-name(tt), margs);
47+
if non-zero(helped)
48+
then (tctx, std-direct-destructure-macro(helped, mstruct))
49+
else (tctx, no)
4950
} else (tctx, std-direct-destructure-macro(margs, mstruct))
5051
);
5152
_ => (tctx, no);

SRC/std-apply-macro.lsts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ let std-apply-macro(tctx: Maybe<TContext>, t: AST): (TContext?, AST) = (
77
}
88
);
99

10-
let std-apply-macro(tctx: Maybe<TContext>, mname: CString, margs: AST): (TContext?, AST) = (
10+
let std-apply-macro(tctx: Maybe<TContext>, mname: CString, margs: AST): (TContext?, AST) = std-apply-macro(tctx, mname, margs, true);
11+
let std-apply-macro-weak(tctx: Maybe<TContext>, mname: CString, margs: AST): (TContext?, AST) = std-apply-macro(tctx, mname, margs, false);
12+
13+
let std-apply-macro(tctx: Maybe<TContext>, mname: CString, margs: AST, strong: Bool): (TContext?, AST) = (
1114
let row = index-macro-table.lookup(mname, [] :: List<(Type,Type,AST)>);
1215
let peep-holes = TAny;
1316
let peeped = TAny;
@@ -42,7 +45,9 @@ let std-apply-macro(tctx: Maybe<TContext>, mname: CString, margs: AST): (TContex
4245
candidates = [(mtype,mterm)];
4346
}
4447
};
45-
std-apply-macro-candidates(tctx, mname, margs, candidates);
48+
(tctx, let result) = std-apply-macro-candidates(tctx, mname, margs, candidates);
49+
if strong && not(non-zero(result)) then exit-error("Failed to Apply Macro: \{mname}", margs);
50+
(tctx, result)
4651
);
4752

4853
let std-infer-peeped-arguments(tctx: Maybe<TContext>, t: AST, peep: Type): (Type, AST) = (

SRC/std-direct-destructure-macro.lsts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ 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{ first:App{lrest=left,val=right}, second:App{rrest=left,right:Var{key=key}} } => (
7-
let rest = std-direct-destructure-macro(lrest, rrest);
8-
if rest.is-some then Some{cons((key,val), rest.get-or-panic)} else no;
9-
);
10-
_ => (fail("Unexpected Pattern std-direct-destructure-macro:\nargs: \{margs}\nlhs: \{mstruct}\n"); no);
6+
_ => no;
117
}
128
);

0 commit comments

Comments
 (0)