Compare commits

...

8 Commits
0.7.1 ... 0.9.1

Author SHA1 Message Date
Juraj Kirchheim
4207dea754 Release 0.9.1 2016-05-20 12:41:35 +02:00
Juraj Kirchheim
3470f1cc47 Store user defined constructors. 2016-05-20 12:41:20 +02:00
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
Juraj Kirchheim
c406e0b844 Release 0.8.0 2016-05-02 17:54:13 +02:00
Juraj Kirchheim
43fb9eb16a Add build cache utility. 2016-05-02 17:45:45 +02:00
5 changed files with 93 additions and 8 deletions

View File

@@ -11,8 +11,8 @@
"contributors": [
"back2dos"
],
"releasenote": "Avoid stale fields cache.",
"version": "0.7.1",
"releasenote": "Store user defined constructors.",
"version": "0.9.1",
"url": "http://haxetink.org/tink_macro",
"dependencies": {
"tink_core": ""

View File

@@ -0,0 +1,68 @@
package tink.macro;
import haxe.macro.Context;
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();
static function init() {
function refresh() {
cache = new Map();
return true;
}
Context.onMacroContextReused(refresh);
refresh();
return cache;
}
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition) {
if (pos == null)
pos = Context.currentPos();
if (type == null)
switch Context.getLocalType() {
case TInst(_.toString() == name => true, [v]):
type = v;
default:
throw 'assert';
}
var forName =
switch cache[name] {
case null: cache[name] = new TypeMap();
case v: v;
}
if (!forName.exists(type)) {
var path = '$name${Lambda.count(forName)}',
usings = [];
var def = build({
pos: pos,
type: type,
usings: usings,
name: path.split('.').pop()
});
Context.defineModule(path, [def], usings);
forName.set(type, Context.getType(path));
}
return forName.get(type);
}
}

View File

@@ -55,7 +55,7 @@ class ClassBuilder {
init();
if (constructor == null)
if (fallback != null)
new Constructor(this, fallback);
constructor = new Constructor(this, fallback);
else {
var sup = target.superClass;
while (sup != null) {

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