Skip to content

Instantly share code, notes, and snippets.

@AxGord
Created September 19, 2015 01:36
Show Gist options
  • Save AxGord/1f451c1330900ffa5dbe to your computer and use it in GitHub Desktop.
Save AxGord/1f451c1330900ffa5dbe to your computer and use it in GitHub Desktop.
macro public function add(th:Expr, f:Expr, ?priority:ExprOf<Int>):Expr {
if (priority == null) priority = macro 0;
return switch Context.typeExpr(f).t {
case TFun(args, ret):
switch ret {
case TAbstract(t, p):
var n = t.get().name;
if (n != 'Bool' && n != 'Void')
Context.fatalError('Wrong return type', Context.currentPos());
case _:
Context.fatalError('Unknown return type', Context.currentPos());
}
switch args.length {
case 0: macro $th.add0($ { f }, $priority);
case 1: macro $th.add1($ { f }, $priority );
case _: Context.fatalError('Argument count error', Context.currentPos());
}
case _:
Context.fatalError('Unknown type', Context.currentPos());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment