Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d84fb38d73 | ||
![]() |
065788c198 | ||
![]() |
810c2f9630 | ||
![]() |
331f186dcd |
@@ -11,8 +11,8 @@
|
||||
"contributors": [
|
||||
"back2dos"
|
||||
],
|
||||
"releasenote": "Add build cache utility.",
|
||||
"version": "0.8.0",
|
||||
"releasenote": "Replace MacroType with @:genericBuild for direct type converions.",
|
||||
"version": "0.9.0",
|
||||
"url": "http://haxetink.org/tink_macro",
|
||||
"dependencies": {
|
||||
"tink_core": ""
|
||||
|
@@ -5,6 +5,13 @@ import haxe.macro.Expr;
|
||||
import haxe.macro.Type;
|
||||
import tink.macro.TypeMap;
|
||||
|
||||
typedef BuildContext = {
|
||||
pos:Position,
|
||||
type:Type,
|
||||
usings:Array<TypePath>,
|
||||
name:String,
|
||||
}
|
||||
|
||||
class BuildCache {
|
||||
|
||||
static var cache = init();
|
||||
@@ -22,7 +29,7 @@ class BuildCache {
|
||||
return cache;
|
||||
}
|
||||
|
||||
static public function getType(name, ?type, ?pos:Position, build:Position->Type->Array<TypePath>->String->TypeDefinition) {
|
||||
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition) {
|
||||
|
||||
if (pos == null)
|
||||
pos = Context.currentPos();
|
||||
@@ -45,7 +52,12 @@ class BuildCache {
|
||||
var path = '$name${Lambda.count(forName)}',
|
||||
usings = [];
|
||||
|
||||
var def = build(pos, type, usings, path.split('.').pop());
|
||||
var def = build({
|
||||
pos: pos,
|
||||
type: type,
|
||||
usings: usings,
|
||||
name: path.split('.').pop()
|
||||
});
|
||||
|
||||
Context.defineModule(path, [def], usings);
|
||||
forName.set(type, Context.getType(path));
|
||||
|
6
src/tink/macro/DirectType.hx
Normal file
6
src/tink/macro/DirectType.hx
Normal file
@@ -0,0 +1,6 @@
|
||||
package tink.macro;
|
||||
|
||||
@:genericBuild(tink.macro.Types.resolveDirectType())
|
||||
class DirectType<Const> {
|
||||
|
||||
}
|
@@ -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';
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user