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)):
|
case CallExp({pos: _, def: Symbol(mac)}, args) if (macros.exists(mac)):
|
||||||
checkNumArgs(mac);
|
checkNumArgs(mac);
|
||||||
macroUsed = true;
|
macroUsed = true;
|
||||||
var expanded = try {
|
var expanded =
|
||||||
Kiss.measure(mac, ()->macros[mac](exp, args.copy(), k), true);
|
#if !macrotest
|
||||||
} catch (error:KissError) {
|
try {
|
||||||
throw error;
|
#end
|
||||||
} catch (error:Dynamic) {
|
Kiss.measure(mac, ()->macros[mac](exp, args.copy(), k), true);
|
||||||
throw KissError.fromExp(exp, 'Macro expansion error: $error');
|
#if !macrotest
|
||||||
};
|
} catch (error:KissError) {
|
||||||
|
throw error;
|
||||||
if (expanded != null) {
|
} catch (error:Dynamic) {
|
||||||
convert(expanded);
|
throw KissError.fromExp(exp, 'Macro expansion error: $error');
|
||||||
} else if (macroExpandOnly) {
|
};
|
||||||
Left(None.withPosOf(exp));
|
#end
|
||||||
} else{
|
if (expanded != null) {
|
||||||
Right(none);
|
convert(expanded);
|
||||||
};
|
} else if (macroExpandOnly) {
|
||||||
|
Left(None.withPosOf(exp));
|
||||||
|
} else{
|
||||||
|
Right(none);
|
||||||
|
};
|
||||||
case CallExp({pos: _, def: Symbol(specialForm)}, args) if (specialForms.exists(specialForm) && !macroExpandOnly):
|
case CallExp({pos: _, def: Symbol(specialForm)}, args) if (specialForms.exists(specialForm) && !macroExpandOnly):
|
||||||
checkNumArgs(specialForm);
|
checkNumArgs(specialForm);
|
||||||
Right(Kiss.measure(specialForm, ()->specialForms[specialForm](exp, args.copy(), k), true));
|
Right(Kiss.measure(specialForm, ()->specialForms[specialForm](exp, args.copy(), k), true));
|
||||||
|
@@ -520,15 +520,7 @@ class Macros {
|
|||||||
args[innerArgNames.shift()] = restArgs;
|
args[innerArgNames.shift()] = restArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return Helpers.runAtCompileTime(b.callSymbol("begin", exps.slice(2)), k, args);
|
||||||
// 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');
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
null;
|
null;
|
||||||
|
Reference in New Issue
Block a user