rename and generalize CompileError->KissError. close #39
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
package kiss;
|
||||
|
||||
import kiss.Reader;
|
||||
import kiss.List;
|
||||
|
||||
using kiss.Stream;
|
||||
using kiss.Reader;
|
||||
|
||||
class CompileError {
|
||||
var exps:List<ReaderExp>;
|
||||
var message:String;
|
||||
|
||||
function new(exps:Array<ReaderExp>, message:String) {
|
||||
this.exps = exps;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static function fromExp(exp:ReaderExp, message:String) {
|
||||
return new CompileError([exp], message);
|
||||
}
|
||||
|
||||
public static function fromExpStr(pos:Position, expStr:String, message:String) {
|
||||
switch (Reader.read(Stream.fromString(expStr), Kiss.defaultKissState())) {
|
||||
case Some(exp):
|
||||
return fromExp({pos: pos, def: exp.def}, message);
|
||||
default:
|
||||
throw 'bad'; // TODO better message
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromArgs(exps:Array<ReaderExp>, message:String) {
|
||||
return new CompileError(exps, message);
|
||||
}
|
||||
|
||||
public function toString(warning = false) {
|
||||
var posPrefix = switch (exps.length) {
|
||||
case 1:
|
||||
exps[0].pos.toPrint();
|
||||
default:
|
||||
var firstPos = exps[0].pos.toPrint();
|
||||
var lastPos = exps[-1].pos.toPrint();
|
||||
var justLineAndColumnIdx = lastPos.indexOf(":") + 1;
|
||||
firstPos + '-' + lastPos.substr(justLineAndColumnIdx);
|
||||
}
|
||||
|
||||
var failed = if (warning) "warning"; else "failed";
|
||||
|
||||
return '$posPrefix: Kiss compilation $failed: $message'
|
||||
+ "\nFrom:"
|
||||
+ [for (exp in exps) exp.def.toString()].toString();
|
||||
}
|
||||
|
||||
public static function warnFromExp(exp:ReaderExp, message:String) {
|
||||
Prelude.print(new CompileError([exp], message).toString(true));
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@ import haxe.macro.Context;
|
||||
import kiss.Reader;
|
||||
import kiss.Helpers;
|
||||
import kiss.Stream;
|
||||
import kiss.CompileError;
|
||||
import kiss.KissError;
|
||||
import kiss.Kiss;
|
||||
|
||||
using kiss.Kiss;
|
||||
@@ -23,7 +23,7 @@ class FieldForms {
|
||||
function renameAndDeprecate(oldName:String, newName:String) {
|
||||
var form = map[oldName];
|
||||
map[oldName] = (wholeExp, args, k) -> {
|
||||
CompileError.warnFromExp(wholeExp, '$oldName has been renamed to $newName and deprecated');
|
||||
KissError.warnFromExp(wholeExp, '$oldName has been renamed to $newName and deprecated');
|
||||
form(wholeExp, args, k);
|
||||
}
|
||||
map[newName] = form;
|
||||
|
@@ -7,7 +7,7 @@ import hscript.Parser;
|
||||
import hscript.Interp;
|
||||
import kiss.Reader;
|
||||
import kiss.ReaderExp;
|
||||
import kiss.CompileError;
|
||||
import kiss.KissError;
|
||||
import kiss.Kiss;
|
||||
import kiss.SpecialForms;
|
||||
import kiss.Prelude;
|
||||
@@ -56,7 +56,7 @@ class Helpers {
|
||||
if (from == null) {
|
||||
throw errorMessage;
|
||||
} else {
|
||||
throw CompileError.fromExp(from, errorMessage);
|
||||
throw KissError.fromExp(from, errorMessage);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class Helpers {
|
||||
if (from == null) {
|
||||
throw errorMessage;
|
||||
} else {
|
||||
throw CompileError.fromExp(from, errorMessage);
|
||||
throw KissError.fromExp(from, errorMessage);
|
||||
};
|
||||
}
|
||||
try {
|
||||
@@ -105,7 +105,7 @@ class Helpers {
|
||||
case MetaExp(_, nameExp) | TypedExp(_, nameExp):
|
||||
varName(formName, nameExp);
|
||||
default:
|
||||
throw CompileError.fromExp(nameExp, 'The first argument to $formName should be a $nameType name, :Typed $nameType name, and/or &meta $nameType name.');
|
||||
throw KissError.fromExp(nameExp, 'The first argument to $formName should be a $nameType name, :Typed $nameType name, and/or &meta $nameType name.');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -126,12 +126,12 @@ class Helpers {
|
||||
|
||||
function makeFuncArg(funcArg:ReaderExp):FunctionArg {
|
||||
if (restProcessed) {
|
||||
throw CompileError.fromExp(funcArg, "cannot declare more arguments after a &rest argument");
|
||||
throw KissError.fromExp(funcArg, "cannot declare more arguments after a &rest argument");
|
||||
}
|
||||
return switch (funcArg.def) {
|
||||
case MetaExp("rest", innerFuncArg):
|
||||
if (funcName == "") {
|
||||
throw CompileError.fromExp(funcArg, "lambda does not support &rest arguments");
|
||||
throw KissError.fromExp(funcArg, "lambda does not support &rest arguments");
|
||||
}
|
||||
|
||||
// rest arguments define a Kiss special form with the function's name that wraps
|
||||
@@ -161,7 +161,7 @@ class Helpers {
|
||||
case Symbol(name) | TypedExp(_, {pos: _, def: Symbol(name)}):
|
||||
name;
|
||||
default:
|
||||
throw CompileError.fromExp(funcArg, 'function argument should be a symbol or typed symbol');
|
||||
throw KissError.fromExp(funcArg, 'function argument should be a symbol or typed symbol');
|
||||
},
|
||||
type: switch (funcArg.def) {
|
||||
case TypedExp(type, _):
|
||||
@@ -195,9 +195,9 @@ class Helpers {
|
||||
case ListExp(funcArgs):
|
||||
funcArgs.map(makeFuncArg);
|
||||
case CallExp(_, _):
|
||||
throw CompileError.fromExp(argList, 'expected an argument list. Change the parens () to brackets []');
|
||||
throw KissError.fromExp(argList, 'expected an argument list. Change the parens () to brackets []');
|
||||
default:
|
||||
throw CompileError.fromExp(argList, 'expected an argument list');
|
||||
throw KissError.fromExp(argList, 'expected an argument list');
|
||||
},
|
||||
expr: expr
|
||||
}
|
||||
@@ -216,17 +216,17 @@ class Helpers {
|
||||
case CallExp({pos: _, def: Symbol("when")}, whenExps):
|
||||
patternExp.checkNumArgs(2, 2, "(when <guard> <pattern>)");
|
||||
if (guard != null)
|
||||
throw CompileError.fromExp(caseExp, "case pattern can only have one `when` or `unless` guard");
|
||||
throw KissError.fromExp(caseExp, "case pattern can only have one `when` or `unless` guard");
|
||||
guard = macro Prelude.truthy(${k.convert(whenExps[0])});
|
||||
makeSwitchPattern(whenExps[1]);
|
||||
case CallExp({pos: _, def: Symbol("unless")}, whenExps):
|
||||
patternExp.checkNumArgs(2, 2, "(unless <guard> <pattern>)");
|
||||
if (guard != null)
|
||||
throw CompileError.fromExp(caseExp, "case pattern can only have one `when` or `unless` guard");
|
||||
throw KissError.fromExp(caseExp, "case pattern can only have one `when` or `unless` guard");
|
||||
guard = macro !Prelude.truthy(${k.convert(whenExps[0])});
|
||||
makeSwitchPattern(whenExps[1]);
|
||||
case ListEatingExp(exps) if (exps.length == 0):
|
||||
throw CompileError.fromExp(patternExp, "list-eating pattern should not be empty");
|
||||
throw KissError.fromExp(patternExp, "list-eating pattern should not be empty");
|
||||
case ListEatingExp(exps):
|
||||
for (idx in 0...exps.length) {
|
||||
var exp = exps[idx];
|
||||
@@ -235,21 +235,21 @@ class Helpers {
|
||||
expNames.push(exp);
|
||||
case ListRestExp(name):
|
||||
if (restExpIndex > -1) {
|
||||
throw CompileError.fromExp(patternExp, "list-eating pattern cannot have multiple ... or ...[restVar] expressions");
|
||||
throw KissError.fromExp(patternExp, "list-eating pattern cannot have multiple ... or ...[restVar] expressions");
|
||||
}
|
||||
restExpIndex = idx;
|
||||
restExpName = name;
|
||||
default:
|
||||
throw CompileError.fromExp(exp, "list-eating pattern can only contain symbols, ..., or ...[restVar]");
|
||||
throw KissError.fromExp(exp, "list-eating pattern can only contain symbols, ..., or ...[restVar]");
|
||||
}
|
||||
}
|
||||
|
||||
if (restExpIndex == -1) {
|
||||
throw CompileError.fromExp(patternExp, "list-eating pattern is missing ... or ...[restVar]");
|
||||
throw KissError.fromExp(patternExp, "list-eating pattern is missing ... or ...[restVar]");
|
||||
}
|
||||
|
||||
if (expNames.length == 0) {
|
||||
throw CompileError.fromExp(patternExp, "list-eating pattern must match at least one single element");
|
||||
throw KissError.fromExp(patternExp, "list-eating pattern must match at least one single element");
|
||||
}
|
||||
|
||||
var b = patternExp.expBuilder();
|
||||
@@ -300,12 +300,12 @@ class Helpers {
|
||||
guard: guard
|
||||
};
|
||||
default:
|
||||
throw CompileError.fromExp(caseExp, "case expressions for (case...) must take the form ([pattern] [body...])");
|
||||
throw KissError.fromExp(caseExp, "case expressions for (case...) must take the form ([pattern] [body...])");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Throw a CompileError if the given expression has the wrong number of arguments
|
||||
Throw a KissError if the given expression has the wrong number of arguments
|
||||
**/
|
||||
public static function checkNumArgs(wholeExp:ReaderExp, min:Null<Int>, max:Null<Int>, ?expectedForm:String) {
|
||||
if (expectedForm == null) {
|
||||
@@ -324,13 +324,13 @@ class Helpers {
|
||||
|
||||
var args = switch (wholeExp.def) {
|
||||
case CallExp(_, args): args;
|
||||
default: throw CompileError.fromExp(wholeExp, "Can only check number of args in a CallExp");
|
||||
default: throw KissError.fromExp(wholeExp, "Can only check number of args in a CallExp");
|
||||
};
|
||||
|
||||
if (min != null && args.length < min) {
|
||||
throw CompileError.fromExp(wholeExp, 'Not enough arguments. Expected $expectedForm');
|
||||
throw KissError.fromExp(wholeExp, 'Not enough arguments. Expected $expectedForm');
|
||||
} else if (max != null && args.length > max) {
|
||||
throw CompileError.fromExp(wholeExp, 'Too many arguments. Expected $expectedForm');
|
||||
throw KissError.fromExp(wholeExp, 'Too many arguments. Expected $expectedForm');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ class Helpers {
|
||||
case None:
|
||||
None;
|
||||
default:
|
||||
throw CompileError.fromExp(exp, 'cannot remove type annotations');
|
||||
throw KissError.fromExp(exp, 'cannot remove type annotations');
|
||||
};
|
||||
return def.withPosOf(exp);
|
||||
}
|
||||
@@ -391,7 +391,7 @@ class Helpers {
|
||||
var parsed = try {
|
||||
parser.parseString(code);
|
||||
} catch (e) {
|
||||
throw CompileError.fromExp(exp, 'macro-time hscript parsing failed with $e:\n$code');
|
||||
throw KissError.fromExp(exp, 'macro-time hscript parsing failed with $e:\n$code');
|
||||
};
|
||||
return parsed;
|
||||
}
|
||||
@@ -420,7 +420,7 @@ class Helpers {
|
||||
k.macroVars[name] = value;
|
||||
interp.variables.set(name, value);
|
||||
});
|
||||
interp.variables.set("CompileError", CompileError);
|
||||
interp.variables.set("KissError", KissError);
|
||||
|
||||
function innerRunAtCompileTimeDynamic(innerExp:ReaderExp) {
|
||||
// in case macroVars have changed
|
||||
@@ -432,7 +432,7 @@ class Helpers {
|
||||
var value = interp.publicExprReturn(compileTimeHScript(innerExp, k));
|
||||
interp.setLocals(locals);
|
||||
if (value == null) {
|
||||
throw CompileError.fromExp(exp, "compile-time evaluation returned null");
|
||||
throw KissError.fromExp(exp, "compile-time evaluation returned null");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -455,7 +455,7 @@ class Helpers {
|
||||
}
|
||||
var value:Dynamic = interp.execute(parsed);
|
||||
if (value == null) {
|
||||
throw CompileError.fromExp(exp, "compile-time evaluation returned null");
|
||||
throw KissError.fromExp(exp, "compile-time evaluation returned null");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -486,7 +486,7 @@ class Helpers {
|
||||
} else if (e.pos != null && e.def != null) {
|
||||
(e : ReaderExp);
|
||||
} else {
|
||||
throw CompileError.fromExp(source, 'Value $e cannot be used as a Kiss expression');
|
||||
throw KissError.fromExp(source, 'Value $e cannot be used as a Kiss expression');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,7 +516,7 @@ class Helpers {
|
||||
case ListExp(elements):
|
||||
elements;
|
||||
default:
|
||||
throw CompileError.fromExp(listToInsert, ",@ can only be used with lists");
|
||||
throw KissError.fromExp(listToInsert, ",@ can only be used with lists");
|
||||
};
|
||||
};
|
||||
for (el in newElements) {
|
||||
@@ -550,7 +550,7 @@ class Helpers {
|
||||
case MetaExp(meta, innerExp):
|
||||
MetaExp(meta, recurse(innerExp));
|
||||
default:
|
||||
throw CompileError.fromExp(exp, 'unquote evaluation not implemented');
|
||||
throw KissError.fromExp(exp, 'unquote evaluation not implemented');
|
||||
};
|
||||
return def.withPosOf(exp);
|
||||
}
|
||||
@@ -608,9 +608,9 @@ class Helpers {
|
||||
begin: (exps:Array<ReaderExp>) -> callSymbol("begin", exps),
|
||||
let: (bindings:Array<ReaderExp>, body:Array<ReaderExp>) -> callSymbol("let", [list(bindings)].concat(body)),
|
||||
objectWith: objectWith,
|
||||
throwCompileError: (reason:String) -> {
|
||||
throwKissError: (reason:String) -> {
|
||||
callSymbol("throw", [
|
||||
callSymbol("CompileError.fromExpStr", [
|
||||
callSymbol("KissError.fromExpStr", [
|
||||
// pos
|
||||
objectWith([
|
||||
_symbol("file"), str(posRef.pos.file),
|
||||
@@ -633,7 +633,7 @@ class Helpers {
|
||||
case ListExp(argExps):
|
||||
argExps;
|
||||
default:
|
||||
throw CompileError.fromExp(exp, '$forThis arg list should be a list expression');
|
||||
throw KissError.fromExp(exp, '$forThis arg list should be a list expression');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -642,7 +642,7 @@ class Helpers {
|
||||
case ListExp(bindingExps) if ((allowEmpty || bindingExps.length > 0) && bindingExps.length % 2 == 0):
|
||||
bindingExps;
|
||||
default:
|
||||
throw CompileError.fromExp(exp, '$forThis bindings should be a list expression with an even number of sub expressions (at least 2)');
|
||||
throw KissError.fromExp(exp, '$forThis bindings should be a list expression with an even number of sub expressions (at least 2)');
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import kiss.ReaderExp;
|
||||
import kiss.FieldForms;
|
||||
import kiss.SpecialForms;
|
||||
import kiss.Macros;
|
||||
import kiss.CompileError;
|
||||
import kiss.KissError;
|
||||
import kiss.cloner.Cloner;
|
||||
|
||||
using kiss.Kiss;
|
||||
@@ -169,7 +169,7 @@ class Kiss {
|
||||
Sys.stderr().writeString(err + "\n");
|
||||
Sys.exit(1);
|
||||
return null;
|
||||
} catch (err:CompileError) {
|
||||
} catch (err:KissError) {
|
||||
Sys.stderr().writeString(err + "\n");
|
||||
Sys.exit(1);
|
||||
return null;
|
||||
@@ -238,7 +238,7 @@ class Kiss {
|
||||
// If no main function is defined manually, Kiss expressions at the top of a file will be put in a main function.
|
||||
// If a main function IS defined, this will result in an error
|
||||
if (k.fieldDict.exists("main")) {
|
||||
throw CompileError.fromExp(topLevelBegin, '$kissFile has expressions outside of field definitions, but already defines its own main function.');
|
||||
throw KissError.fromExp(topLevelBegin, '$kissFile has expressions outside of field definitions, but already defines its own main function.');
|
||||
}
|
||||
var b = topLevelBegin.expBuilder();
|
||||
// This doesn't need to be added to the fieldDict because all code generation is done
|
||||
@@ -386,7 +386,7 @@ class Kiss {
|
||||
try {
|
||||
Context.parse(name, exp.macroPos());
|
||||
} catch (err:haxe.Exception) {
|
||||
throw CompileError.fromExp(exp, "invalid symbol");
|
||||
throw KissError.fromExp(exp, "invalid symbol");
|
||||
};
|
||||
case StrExp(s):
|
||||
EConst(CString(s)).withMacroPosOf(exp);
|
||||
@@ -436,7 +436,7 @@ class Kiss {
|
||||
try {
|
||||
Context.parse(code, exp.macroPos());
|
||||
} catch (err:Exception) {
|
||||
throw CompileError.fromExp(exp, 'Haxe parse error: $err');
|
||||
throw KissError.fromExp(exp, 'Haxe parse error: $err');
|
||||
};
|
||||
case FieldExp(field, innerExp):
|
||||
EField(convert(innerExp), field).withMacroPosOf(exp);
|
||||
@@ -448,7 +448,7 @@ class Kiss {
|
||||
Helpers.evalUnquotes($v{innerExp}).def;
|
||||
};
|
||||
default:
|
||||
throw CompileError.fromExp(exp, 'conversion not implemented');
|
||||
throw KissError.fromExp(exp, 'conversion not implemented');
|
||||
};
|
||||
#if test
|
||||
// Sys.println(expr.toString()); // For very fine-grained codegen inspection--slows compilation a lot.
|
||||
@@ -461,7 +461,7 @@ class Kiss {
|
||||
copy.macros[m] = (wholeExp:ReaderExp, exps, k) -> {
|
||||
var b = wholeExp.expBuilder();
|
||||
// have this throw during macroEXPANSION, not before (so assertThrows will catch it)
|
||||
b.throwCompileError('$m is unavailable in macros because $reason');
|
||||
b.throwKissError('$m is unavailable in macros because $reason');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -497,7 +497,7 @@ class Kiss {
|
||||
case Symbol(varName) if (k.macroVars.exists(varName)):
|
||||
var b = wholeExp.expBuilder();
|
||||
// have this throw during macroEXPANSION, not before (so assertThrows will catch it)
|
||||
copy.convert(b.throwCompileError('If you intend to change macroVar $varName, use setMacroVar instead. If not, rename your local variable for clarity.'));
|
||||
copy.convert(b.throwKissError('If you intend to change macroVar $varName, use setMacroVar instead. If not, rename your local variable for clarity.'));
|
||||
default:
|
||||
setLocal(wholeExp, exps, copy);
|
||||
};
|
||||
|
@@ -45,7 +45,7 @@ class KissInterp extends Interp {
|
||||
#end
|
||||
|
||||
#if macro
|
||||
variables.set("CompileError", kiss.CompileError);
|
||||
variables.set("KissError", kiss.KissError);
|
||||
#end
|
||||
|
||||
// Might eventually need to simulate types in the namespace:
|
||||
|
@@ -5,7 +5,7 @@ import haxe.macro.Context;
|
||||
import kiss.Reader;
|
||||
import kiss.ReaderExp;
|
||||
import kiss.Kiss;
|
||||
import kiss.CompileError;
|
||||
import kiss.KissError;
|
||||
import kiss.CompilerTools;
|
||||
import uuid.Uuid;
|
||||
import hscript.Parser;
|
||||
@@ -28,7 +28,7 @@ class Macros {
|
||||
function renameAndDeprecate(oldName:String, newName:String) {
|
||||
var form = macros[oldName];
|
||||
macros[oldName] = (wholeExp, args, k) -> {
|
||||
CompileError.warnFromExp(wholeExp, '$oldName has been renamed to $newName and deprecated');
|
||||
KissError.warnFromExp(wholeExp, '$oldName has been renamed to $newName and deprecated');
|
||||
form(wholeExp, args, k);
|
||||
}
|
||||
macros[newName] = form;
|
||||
@@ -41,7 +41,7 @@ class Macros {
|
||||
case StrExp(otherKissFile):
|
||||
Kiss.load(otherKissFile, k);
|
||||
default:
|
||||
throw CompileError.fromExp(args[0], "only argument to load should be a string literal of a .kiss file path");
|
||||
throw KissError.fromExp(args[0], "only argument to load should be a string literal of a .kiss file path");
|
||||
};
|
||||
};
|
||||
|
||||
@@ -52,13 +52,13 @@ class Macros {
|
||||
case StrExp(libName):
|
||||
Prelude.libPath(libName);
|
||||
default:
|
||||
throw CompileError.fromExp(args[0], "first argument to loadFrom should be a string literal of a haxe library's name");
|
||||
throw KissError.fromExp(args[0], "first argument to loadFrom should be a string literal of a haxe library's name");
|
||||
};
|
||||
switch (args[1].def) {
|
||||
case StrExp(otherKissFile):
|
||||
Kiss.load(otherKissFile, k, libPath);
|
||||
default:
|
||||
throw CompileError.fromExp(args[1], "second argument to loadFrom should be a string literal of a .kiss file path");
|
||||
throw KissError.fromExp(args[1], "second argument to loadFrom should be a string literal of a .kiss file path");
|
||||
};
|
||||
};
|
||||
|
||||
@@ -174,7 +174,7 @@ class Macros {
|
||||
elseExp;
|
||||
}
|
||||
} catch (e) {
|
||||
throw CompileError.fromExp(conditionExp, 'condition for #if threw error $e');
|
||||
throw KissError.fromExp(conditionExp, 'condition for #if threw error $e');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -197,7 +197,7 @@ class Macros {
|
||||
matchBodySymbols.push(gensym);
|
||||
caseArgs.push(b.call(pattern, [gensym]));
|
||||
default:
|
||||
throw CompileError.fromExp(exp, "invalid pattern expression for #case");
|
||||
throw KissError.fromExp(exp, "invalid pattern expression for #case");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ class Macros {
|
||||
#end
|
||||
return caseInterp.evalHaxe(hscriptStr);
|
||||
} catch (e) {
|
||||
throw CompileError.fromExp(caseExp, '#case evaluation threw error $e');
|
||||
throw KissError.fromExp(caseExp, '#case evaluation threw error $e');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,11 +360,11 @@ class Macros {
|
||||
case StrExp(s):
|
||||
s;
|
||||
default:
|
||||
throw CompileError.fromExp(s, 'initiator list of $formName must only contain strings');
|
||||
throw KissError.fromExp(s, 'initiator list of $formName must only contain strings');
|
||||
}
|
||||
];
|
||||
default:
|
||||
throw CompileError.fromExp(exp, 'first argument to $formName should be a String or list of strings');
|
||||
throw KissError.fromExp(exp, 'first argument to $formName should be a String or list of strings');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -373,15 +373,15 @@ class Macros {
|
||||
|
||||
var name = switch (exps[0].def) {
|
||||
case Symbol(name): name;
|
||||
default: throw CompileError.fromExp(exps[0], "macro name should be a symbol");
|
||||
default: throw KissError.fromExp(exps[0], "macro name should be a symbol");
|
||||
};
|
||||
|
||||
var argList = switch (exps[1].def) {
|
||||
case ListExp(macroArgs): macroArgs;
|
||||
case CallExp(_, _):
|
||||
throw CompileError.fromExp(exps[1], 'expected a macro argument list. Change the parens () to brackets []');
|
||||
throw KissError.fromExp(exps[1], 'expected a macro argument list. Change the parens () to brackets []');
|
||||
default:
|
||||
throw CompileError.fromExp(exps[1], 'expected a macro argument list');
|
||||
throw KissError.fromExp(exps[1], 'expected a macro argument list');
|
||||
};
|
||||
|
||||
// This is similar to &opt and &rest processing done by Helpers.makeFunction()
|
||||
@@ -401,7 +401,7 @@ class Macros {
|
||||
var builderName:String = null;
|
||||
for (arg in argList) {
|
||||
if (restIndex != -1) {
|
||||
throw CompileError.fromExp(arg, "macros cannot declare arguments after a &rest or &body argument");
|
||||
throw KissError.fromExp(arg, "macros cannot declare arguments after a &rest or &body argument");
|
||||
}
|
||||
switch (arg.def) {
|
||||
case Symbol(name):
|
||||
@@ -417,7 +417,7 @@ class Macros {
|
||||
if (builderName == null) {
|
||||
builderName = name;
|
||||
} else {
|
||||
throw CompileError.fromExp(arg, 'Cannot declare multiple &builder args. Already declared: $builderName');
|
||||
throw KissError.fromExp(arg, 'Cannot declare multiple &builder args. Already declared: $builderName');
|
||||
}
|
||||
case MetaExp("opt", {pos: _, def: Symbol(name)}):
|
||||
argNames.push(name);
|
||||
@@ -426,7 +426,7 @@ class Macros {
|
||||
++maxArgs;
|
||||
case MetaExp("rest", {pos: _, def: Symbol(name)}):
|
||||
if (name == "body") {
|
||||
CompileError.warnFromExp(arg, "Consider using &body instead of &rest when writing macros with bodies.");
|
||||
KissError.warnFromExp(arg, "Consider using &body instead of &rest when writing macros with bodies.");
|
||||
}
|
||||
argNames.push(name);
|
||||
macroCallForm += ' [$name...]';
|
||||
@@ -439,7 +439,7 @@ class Macros {
|
||||
requireRest = true;
|
||||
maxArgs = null;
|
||||
default:
|
||||
throw CompileError.fromExp(arg, "macro argument should be an untyped symbol or a symbol annotated with &opt or &rest or &builder");
|
||||
throw KissError.fromExp(arg, "macro argument should be an untyped symbol or a symbol annotated with &opt or &rest or &builder");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,7 +467,7 @@ class Macros {
|
||||
if (innerArgNames.length > 0) {
|
||||
var restArgs = innerExps.slice(restIndex);
|
||||
if (requireRest && restArgs.length == 0) {
|
||||
throw CompileError.fromExp(wholeExp, 'Macro $name requires one or more expression for &body');
|
||||
throw KissError.fromExp(wholeExp, 'Macro $name requires one or more expression for &body');
|
||||
}
|
||||
args[innerArgNames.shift()] = restArgs;
|
||||
}
|
||||
@@ -475,11 +475,11 @@ class Macros {
|
||||
try {
|
||||
// Return the macro expansion:
|
||||
return Helpers.runAtCompileTime(b.callSymbol("begin", exps.slice(2)), k, args);
|
||||
} catch (error:CompileError) {
|
||||
} catch (error:KissError) {
|
||||
throw error;
|
||||
} catch (error:Dynamic) {
|
||||
// TODO this could print the hscript, with some refactoring
|
||||
throw CompileError.fromExp(wholeExp, 'Macro expansion error: $error');
|
||||
throw KissError.fromExp(wholeExp, 'Macro expansion error: $error');
|
||||
};
|
||||
};
|
||||
|
||||
@@ -492,7 +492,7 @@ class Macros {
|
||||
|
||||
var name = switch (exps[0].def) {
|
||||
case Symbol(name): name;
|
||||
default: throw CompileError.fromExp(exps[0], "macro name should be a symbol");
|
||||
default: throw KissError.fromExp(exps[0], "macro name should be a symbol");
|
||||
};
|
||||
|
||||
k.macros.remove(name);
|
||||
@@ -525,7 +525,7 @@ class Macros {
|
||||
|
||||
var streamArgName = null;
|
||||
var builderArgName = null;
|
||||
var messageForBadArgs = CompileError.fromExp(exps[1], 'expected an argument list for a reader macro, like [stream] or [stream &builder b]');
|
||||
var messageForBadArgs = KissError.fromExp(exps[1], 'expected an argument list for a reader macro, like [stream] or [stream &builder b]');
|
||||
switch (exps[1].def) {
|
||||
case ListExp(args):
|
||||
for (arg in args) {
|
||||
@@ -536,7 +536,7 @@ class Macros {
|
||||
if (builderArgName == null) {
|
||||
builderArgName = b;
|
||||
} else {
|
||||
throw CompileError.fromExp(arg, 'Cannot declare multiple &builder args. Already declared: $builderArgName');
|
||||
throw KissError.fromExp(arg, 'Cannot declare multiple &builder args. Already declared: $builderArgName');
|
||||
}
|
||||
default:
|
||||
throw messageForBadArgs;
|
||||
@@ -560,8 +560,8 @@ class Macros {
|
||||
Helpers.runAtCompileTime(body, k, evalArgs).def;
|
||||
} catch (err) {
|
||||
var expForError = Symbol(s).withPos(startingPos);
|
||||
CompileError.warnFromExp(wholeExp, 'Error from this reader macro');
|
||||
throw CompileError.fromExp(expForError, '$err');
|
||||
KissError.warnFromExp(wholeExp, 'Error from this reader macro');
|
||||
throw KissError.fromExp(expForError, '$err');
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -604,7 +604,7 @@ class Macros {
|
||||
var aliasMap:Map<String, ReaderExpDef> = null;
|
||||
|
||||
function getAliasName(k:KissState, nameExpWithMeta:ReaderExp, formName:String):String {
|
||||
var error = CompileError.fromExp(nameExpWithMeta, 'first argument to $formName should be &call [alias] or &ident [alias]');
|
||||
var error = KissError.fromExp(nameExpWithMeta, 'first argument to $formName should be &call [alias] or &ident [alias]');
|
||||
var nameExp = switch (nameExpWithMeta.def) {
|
||||
case MetaExp("call", nameExp):
|
||||
aliasMap = k.callAliases;
|
||||
@@ -807,7 +807,7 @@ class Macros {
|
||||
propertySetExps.push(
|
||||
b.call(b.symbol("set"), [b.field(name, b.symbol("this")), b.symbol(name)]));
|
||||
default:
|
||||
throw CompileError.fromExp(arg, "invalid use of &prop in defNew");
|
||||
throw KissError.fromExp(arg, "invalid use of &prop in defNew");
|
||||
}
|
||||
default:
|
||||
argList.push(arg);
|
||||
@@ -899,7 +899,7 @@ class Macros {
|
||||
objectExps.push(exp);
|
||||
objectExps.push(exp);
|
||||
default:
|
||||
throw CompileError.fromExp(exp, "invalid expression in (objectWith)");
|
||||
throw KissError.fromExp(exp, "invalid expression in (objectWith)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -913,7 +913,7 @@ class Macros {
|
||||
var blockName = try {
|
||||
exps[0].symbolNameValue();
|
||||
} catch (notSymbolError:String) {
|
||||
throw CompileError.fromExp(wholeExp, notSymbolError);
|
||||
throw KissError.fromExp(wholeExp, notSymbolError);
|
||||
}
|
||||
k.collectedBlocks[blockName] = [];
|
||||
// TODO some assertion that the coder hasn't defined over another macro (also should apply to defMacro)
|
||||
@@ -929,11 +929,11 @@ class Macros {
|
||||
var blockName = try {
|
||||
exps[0].symbolNameValue();
|
||||
} catch (notSymbolError:String) {
|
||||
throw CompileError.fromExp(wholeExp, notSymbolError);
|
||||
throw KissError.fromExp(wholeExp, notSymbolError);
|
||||
}
|
||||
var b = wholeExp.expBuilder();
|
||||
if (!k.collectedBlocks.exists(blockName)) {
|
||||
throw CompileError.fromExp(wholeExp, 'no blocks for $blockName were collected. Try adding (collectBlocks ${blockName}) at the start of the file.');
|
||||
throw KissError.fromExp(wholeExp, 'no blocks for $blockName were collected. Try adding (collectBlocks ${blockName}) at the start of the file.');
|
||||
}
|
||||
b.begin(k.collectedBlocks[blockName]);
|
||||
};
|
||||
@@ -980,11 +980,11 @@ class Macros {
|
||||
return b.begin(body);
|
||||
}
|
||||
default:
|
||||
throw CompileError.fromExp(patternExp, "bad exprCase pattern expression");
|
||||
throw KissError.fromExp(patternExp, "bad exprCase pattern expression");
|
||||
}
|
||||
}
|
||||
|
||||
throw CompileError.fromExp(wholeExp, 'expression ${toMatch.def.toString()} matches no pattern in exprCase');
|
||||
throw KissError.fromExp(wholeExp, 'expression ${toMatch.def.toString()} matches no pattern in exprCase');
|
||||
};
|
||||
|
||||
return b.call(b.symbol("Macros.exprCase"), [b.str(functionKey), toMatch, b.symbol("__interp__")]);
|
||||
@@ -1012,7 +1012,7 @@ class Macros {
|
||||
|
||||
var allowedLangs = EnumTools.getConstructors(CompileLang);
|
||||
if (allowedLangs.indexOf(lang) == -1) {
|
||||
throw CompileError.fromExp(langExp, 'unsupported lang for #extern: $originalLang should be one of $allowedLangs');
|
||||
throw KissError.fromExp(langExp, 'unsupported lang for #extern: $originalLang should be one of $allowedLangs');
|
||||
}
|
||||
var langArg = EnumTools.createByName(CompileLang, lang);
|
||||
|
||||
@@ -1026,13 +1026,13 @@ class Macros {
|
||||
case ListExp(_):
|
||||
// Let the next switch handle the binding list
|
||||
default:
|
||||
throw CompileError.fromExp(nextArg, "second argument to #extern can either be a CompileArgs object or a list of typed bindings");
|
||||
throw KissError.fromExp(nextArg, "second argument to #extern can either be a CompileArgs object or a list of typed bindings");
|
||||
}
|
||||
switch (nextArg.def) {
|
||||
case ListExp(_):
|
||||
bindingListExp = nextArg;
|
||||
default:
|
||||
throw CompileError.fromExp(nextArg, "#extern requires a list of typed bindings");
|
||||
throw KissError.fromExp(nextArg, "#extern requires a list of typed bindings");
|
||||
}
|
||||
|
||||
var compileArgs:CompilationArgs = if (compileArgsExp != null) {
|
||||
@@ -1052,7 +1052,7 @@ class Macros {
|
||||
case TypedExp(_type, symbol = {pos: _, def: Symbol(name)}):
|
||||
type = _type;
|
||||
symbol;
|
||||
default: throw CompileError.fromExp(bindingList[idx], "name in #extern binding list must be a typed symbol");
|
||||
default: throw KissError.fromExp(bindingList[idx], "name in #extern binding list must be a typed symbol");
|
||||
};
|
||||
switch (bindingList[idx + 1].def) {
|
||||
// _ in the value position of the #extern binding list will reuse the name as the value
|
||||
@@ -1279,7 +1279,7 @@ class Macros {
|
||||
// key-value expressions, quasiquotes, unquotes, or UnquoteLists. This function can be expanded
|
||||
// later if those features are ever needed.
|
||||
default:
|
||||
throw CompileError.fromExp(pattern, "unsupported pattern for exprCase");
|
||||
throw KissError.fromExp(pattern, "unsupported pattern for exprCase");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1299,7 +1299,7 @@ class Macros {
|
||||
}
|
||||
]);
|
||||
default:
|
||||
throw CompileError.fromExp(exps[0], 'top-level expression of (cond... ) must be a call list starting with a condition expression');
|
||||
throw KissError.fromExp(exps[0], 'top-level expression of (cond... ) must be a call list starting with a condition expression');
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -162,7 +162,7 @@ class Reader {
|
||||
argsExp = b.list([]);
|
||||
bodyExp = firstExp;
|
||||
default:
|
||||
throw CompileError.fromExp(firstExp, "first expression after -> should be [args...], arg, (exp) or {body}, or one of those prefixed with :Void");
|
||||
throw KissError.fromExp(firstExp, "first expression after -> should be [args...], arg, (exp) or {body}, or one of those prefixed with :Void");
|
||||
}
|
||||
if (!returnsValue) {
|
||||
argsExp = TypedExp("Void", argsExp).withPosOf(argsExp);
|
||||
|
@@ -24,7 +24,7 @@ class SpecialForms {
|
||||
function renameAndDeprecate(oldName:String, newName:String) {
|
||||
var form = map[oldName];
|
||||
map[oldName] = (wholeExp, args, k) -> {
|
||||
CompileError.warnFromExp(wholeExp, '$oldName has been renamed to $newName and deprecated');
|
||||
KissError.warnFromExp(wholeExp, '$oldName has been renamed to $newName and deprecated');
|
||||
form(wholeExp, args, k);
|
||||
}
|
||||
map[newName] = form;
|
||||
@@ -83,7 +83,7 @@ class SpecialForms {
|
||||
// Declare anonymous objects
|
||||
map["object"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
||||
if (args.length % 2 != 0) {
|
||||
throw CompileError.fromExp(wholeExp, "(object [field bindings]...) must have an even number of arguments");
|
||||
throw KissError.fromExp(wholeExp, "(object [field bindings]...) must have an even number of arguments");
|
||||
}
|
||||
EObjectDecl([
|
||||
for (pair in args.groups(2))
|
||||
@@ -92,8 +92,8 @@ class SpecialForms {
|
||||
field: switch (pair[0].def) {
|
||||
case Symbol(name): name;
|
||||
case TypedExp(_,
|
||||
{pos: _, def: Symbol(_)}): throw CompileError.fromExp(pair[0], "type specification on anonymous objects will be ignored");
|
||||
default: throw CompileError.fromExp(pair[0], "first expression in anonymous object field binding should be a plain symbol");
|
||||
{pos: _, def: Symbol(_)}): throw KissError.fromExp(pair[0], "type specification on anonymous objects will be ignored");
|
||||
default: throw KissError.fromExp(pair[0], "first expression in anonymous object field binding should be a plain symbol");
|
||||
},
|
||||
expr: k.convert(pair[1])
|
||||
}
|
||||
@@ -104,7 +104,7 @@ class SpecialForms {
|
||||
wholeExp.checkNumArgs(1, null, '(new [type] [constructorArgs...])');
|
||||
var classType = switch (args[0].def) {
|
||||
case Symbol(name): name;
|
||||
default: throw CompileError.fromExp(args[0], 'first arg in (new [type] ...) should be a class to instantiate');
|
||||
default: throw KissError.fromExp(args[0], 'first arg in (new [type] ...) should be a class to instantiate');
|
||||
};
|
||||
ENew(Helpers.parseTypePath(classType, args[0]), args.slice(1).map(k.convert)).withMacroPosOf(wholeExp);
|
||||
};
|
||||
@@ -121,7 +121,7 @@ class SpecialForms {
|
||||
case KeyValueExp(_, valueNameExp):
|
||||
varName(valueNameExp);
|
||||
default:
|
||||
throw CompileError.fromExp(nameExp, 'expected a symbol, typed symbol, or keyed symbol for variable name in a var binding');
|
||||
throw KissError.fromExp(nameExp, 'expected a symbol, typed symbol, or keyed symbol for variable name in a var binding');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ class SpecialForms {
|
||||
}, k, if (isFinal == false) false else null)
|
||||
]);
|
||||
default:
|
||||
throw CompileError.fromExp(namesExp, "Can only bind variables to a symbol or list of symbols for destructuring");
|
||||
throw KissError.fromExp(namesExp, "Can only bind variables to a symbol or list of symbols for destructuring");
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -196,7 +196,7 @@ class SpecialForms {
|
||||
|
||||
var body = args.slice(1);
|
||||
if (body.length == 0) {
|
||||
throw CompileError.fromArgs(args, '(let....) expression needs a body');
|
||||
throw KissError.fromArgs(args, '(let....) expression needs a body');
|
||||
}
|
||||
|
||||
EBlock([
|
||||
@@ -337,7 +337,7 @@ class SpecialForms {
|
||||
}
|
||||
|
||||
if (nullExpr == null) {
|
||||
throw CompileError.fromExp(wholeExp, "Unmatched pattern: null");
|
||||
throw KissError.fromExp(wholeExp, "Unmatched pattern: null");
|
||||
}
|
||||
|
||||
var nullCase = b.callSymbol("null", [b.raw(nullExpr.toString())]);
|
||||
@@ -357,13 +357,13 @@ class SpecialForms {
|
||||
if (args.length == 3) {
|
||||
pkg = switch (args.shift().def) {
|
||||
case Symbol(pkg): pkg;
|
||||
default: throw CompileError.fromExp(args[0], '$whichArg argument to (the... ) should be a valid haxe package');
|
||||
default: throw KissError.fromExp(args[0], '$whichArg argument to (the... ) should be a valid haxe package');
|
||||
};
|
||||
whichArg = "second";
|
||||
}
|
||||
var type = switch (args[0].def) {
|
||||
case Symbol(type): type;
|
||||
default: throw CompileError.fromExp(args[0], '$whichArg argument to (the... ) should be a valid type');
|
||||
default: throw KissError.fromExp(args[0], '$whichArg argument to (the... ) should be a valid type');
|
||||
};
|
||||
if (pkg.length > 0)
|
||||
type = pkg + "." + type;
|
||||
@@ -387,7 +387,7 @@ class SpecialForms {
|
||||
def: Symbol(name) | TypedExp(_, {pos: _, def: Symbol(name)})
|
||||
}
|
||||
]): name;
|
||||
default: throw CompileError.fromExp(catchArgs[0], 'first argument to (catch... ) should be a one-element argument list');
|
||||
default: throw KissError.fromExp(catchArgs[0], 'first argument to (catch... ) should be a one-element argument list');
|
||||
},
|
||||
type: switch (catchArgs[0].def) {
|
||||
case ListExp([{pos: _, def: TypedExp(type, _)}]):
|
||||
@@ -397,7 +397,7 @@ class SpecialForms {
|
||||
expr: k.convert(CallExp(Symbol("begin").withPos(catchArgs[1].pos), catchArgs.slice(1)).withPos(catchArgs[1].pos))
|
||||
};
|
||||
default:
|
||||
throw CompileError.fromExp(catchKissExp,
|
||||
throw KissError.fromExp(catchKissExp,
|
||||
'expressions following the first expression in a (try... ) should all be (catch [[error]] [body...]) expressions');
|
||||
}
|
||||
}
|
||||
@@ -406,7 +406,7 @@ class SpecialForms {
|
||||
|
||||
map["throw"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
||||
if (args.length != 1) {
|
||||
throw CompileError.fromExp(wholeExp, 'throw expression should only throw one value');
|
||||
throw KissError.fromExp(wholeExp, 'throw expression should only throw one value');
|
||||
}
|
||||
EThrow(k.convert(args[0])).withMacroPosOf(wholeExp);
|
||||
};
|
||||
@@ -446,7 +446,7 @@ class SpecialForms {
|
||||
case Symbol(typePath):
|
||||
t = Helpers.parseComplexType(typePath, args[1]);
|
||||
default:
|
||||
throw CompileError.fromExp(args[1], 'second argument to cast should be a type path symbol');
|
||||
throw KissError.fromExp(args[1], 'second argument to cast should be a type path symbol');
|
||||
}
|
||||
}
|
||||
ECast(e, t).withMacroPosOf(wholeExp);
|
||||
|
Reference in New Issue
Block a user