Created
November 26, 2011 21:43
-
-
Save devboy/1396340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems to work :)