Compare commits

..

4 Commits
0.8.0 ... 0.9.0

Author SHA1 Message Date
Juraj Kirchheim
d84fb38d73 Release 0.9.0 2016-05-18 07:59:04 +02:00
Juraj Kirchheim
065788c198 Replace MacroType with @:genericBuild for direct type converions. 2016-05-18 07:58:28 +02:00
Juraj Kirchheim
810c2f9630 Release 0.8.1 2016-05-02 17:58:30 +02:00
Juraj Kirchheim
331f186dcd Minor API improvement. 2016-05-02 17:58:09 +02:00
4 changed files with 38 additions and 9 deletions

View File

@@ -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": ""

View File

@@ -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));

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';
}
}