Replace MacroType with @:genericBuild for direct type converions.

This commit is contained in:
Juraj Kirchheim
2016-05-18 07:58:28 +02:00
parent 810c2f9630
commit 065788c198
2 changed files with 22 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
package tink.macro;
@:genericBuild(tink.macro.Types.resolveDirectType())
class DirectType<Const> {
}

View File

@@ -16,8 +16,8 @@ class Types {
static var types = new Map<Int,Void->Type>();
static var idCounter = 0;
@:noUsing macro static public function getType(id:Int):Type
return types.get(id)();
//@:noUsing macro static public function getType(id:Int):Type
//return types.get(id)();
static public function getID(t:Type, ?reduced = true)
return
@@ -162,9 +162,20 @@ class Types {
static public function lazyComplex(f:Void->Type)
return
TPath({
pack : ['haxe','macro'],
name : 'MacroType',
params : [TPExpr('tink.macro.Types.getType'.resolve().call([register(f).toExpr()]))],
pack : ['tink','macro'],
name : 'DirectType',
params : [TPExpr(register(f).toExpr())],
sub : null,
});
static function resolveDirectType()
return
switch reduce(Context.getLocalType()) {
case TInst(_, [TInst(_.get() => { kind: KExpr(e) }, _)]):
types.get(Std.parseInt(e.toString()))();
default:
throw 'assert';
}
}