de-duplicate the try/catch for macroexpansions
This commit is contained in:
@@ -590,21 +590,25 @@ class Kiss {
|
||||
case CallExp({pos: _, def: Symbol(mac)}, args) if (macros.exists(mac)):
|
||||
checkNumArgs(mac);
|
||||
macroUsed = true;
|
||||
var expanded = try {
|
||||
Kiss.measure(mac, ()->macros[mac](exp, args.copy(), k), true);
|
||||
} catch (error:KissError) {
|
||||
throw error;
|
||||
} catch (error:Dynamic) {
|
||||
throw KissError.fromExp(exp, 'Macro expansion error: $error');
|
||||
};
|
||||
|
||||
if (expanded != null) {
|
||||
convert(expanded);
|
||||
} else if (macroExpandOnly) {
|
||||
Left(None.withPosOf(exp));
|
||||
} else{
|
||||
Right(none);
|
||||
};
|
||||
var expanded =
|
||||
#if !macrotest
|
||||
try {
|
||||
#end
|
||||
Kiss.measure(mac, ()->macros[mac](exp, args.copy(), k), true);
|
||||
#if !macrotest
|
||||
} catch (error:KissError) {
|
||||
throw error;
|
||||
} catch (error:Dynamic) {
|
||||
throw KissError.fromExp(exp, 'Macro expansion error: $error');
|
||||
};
|
||||
#end
|
||||
if (expanded != null) {
|
||||
convert(expanded);
|
||||
} else if (macroExpandOnly) {
|
||||
Left(None.withPosOf(exp));
|
||||
} else{
|
||||
Right(none);
|
||||
};
|
||||
case CallExp({pos: _, def: Symbol(specialForm)}, args) if (specialForms.exists(specialForm) && !macroExpandOnly):
|
||||
checkNumArgs(specialForm);
|
||||
Right(Kiss.measure(specialForm, ()->specialForms[specialForm](exp, args.copy(), k), true));
|
||||
|
@@ -520,15 +520,7 @@ class Macros {
|
||||
args[innerArgNames.shift()] = restArgs;
|
||||
}
|
||||
|
||||
try {
|
||||
// Return the macro expansion:
|
||||
return Helpers.runAtCompileTime(b.callSymbol("begin", exps.slice(2)), k, args);
|
||||
} catch (error:KissError) {
|
||||
throw error;
|
||||
} catch (error:Dynamic) {
|
||||
// TODO this could print the hscript, with some refactoring
|
||||
throw KissError.fromExp(wholeExp, 'Macro expansion error: $error');
|
||||
};
|
||||
return Helpers.runAtCompileTime(b.callSymbol("begin", exps.slice(2)), k, args);
|
||||
};
|
||||
|
||||
null;
|
||||
|
Reference in New Issue
Block a user