Skip to content

Instantly share code, notes, and snippets.

@devboy
Created November 26, 2011 21:43
Show Gist options
  • Save devboy/1396340 to your computer and use it in GitHub Desktop.
Save devboy/1396340 to your computer and use it in GitHub Desktop.
package org.devboy;
import haxe.macro.Type;
import neko.Lib;
import haxe.macro.Expr;
import haxe.macro.Context;
class Funk
{
@:macro public static function partial( expressions: Array<Expr> ): Expr
{
var pos = Context.currentPos();
function mk(e:ExprDef) return { expr: e, pos: pos };
var meth = expressions.shift();
var methType: haxe.macro.Type = Context.typeof(meth);
var methArgs: Array<{ name : String, opt : Bool, t : Type }>;
switch(methType)
{
case TFun(args, ret):
methArgs = args;
case TType(t, params):
case TMono(t):
case TInst(t, params):
case TEnum(t, params):
case TDynamic(t):
case TAnonymous(a):
}
Lib.println("methType");
Lib.println(methType);
var args: Array<FunctionArg> = [];
var pIndex: Int = 0;
for ( i in (expressions.length)...methArgs.length )
{
args.push({name: "p"+pIndex, opt: false,type: null, value: null});
pIndex++;
}
Lib.println("args");
Lib.println(args);
for (arg in args)
expressions.push(mk(EConst(CIdent(arg.name))));
Lib.println("expressions");
Lib.println(expressions);
var partialFunction = mk( EFunction( null,
{ ret: null,
params: [],
args: args,
expr: mk(
EReturn( mk(
ECall( meth, expressions )
))
)
}
));
Lib.println("partialFunction");
Lib.println(partialFunction);
Lib.println(macrotools.Print.make(partialFunction));
return partialFunction;
}
}
@devboy
Copy link
Author

devboy commented Nov 27, 2011

Seems to work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment