Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4207dea754 | ||
![]() |
3470f1cc47 | ||
![]() |
d84fb38d73 | ||
![]() |
065788c198 | ||
![]() |
810c2f9630 | ||
![]() |
331f186dcd | ||
![]() |
c406e0b844 | ||
![]() |
43fb9eb16a |
@@ -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": ""
|
||||
|
68
src/tink/macro/BuildCache.hx
Normal file
68
src/tink/macro/BuildCache.hx
Normal 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);
|
||||
}
|
||||
}
|
@@ -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) {
|
||||
|
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