Compare commits

..

12 Commits

Author SHA1 Message Date
Juraj Kirchheim
92f60cbe4f Release 0.10.0 2016-07-08 11:49:30 +02:00
Juraj Kirchheim
3b822b4cdb Merge branch 'master' of https://github.com/haxetink/tink_macro 2016-07-08 11:49:00 +02:00
Juraj Kirchheim
f2b670f9e4 Expand build cache for 2 and 3 type parameters. 2016-07-08 11:48:40 +02:00
Kevin Leung
ff491fe7e7 Add gitter link 2016-07-06 15:22:47 +08:00
Juraj Kirchheim
7e869cd9c8 Fix logic in Exprs.has 2016-06-23 05:19:53 +02:00
Juraj Kirchheim
983ffa16af Avoid stringly approach. 2016-06-10 08:20:09 +02:00
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
7 changed files with 98 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
# Tinkerbell Macro Library
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg?maxAge=2592000)](https://gitter.im/haxetink/public)
Explained in current marketing speak, `tink_macro` is *the* macro toolkit ;)
@@ -412,4 +413,4 @@ Because the state of a constructor is rather delicate, the API prohibits you to
# TypeMap
You can find a type map, i.e. a map where the keys are `haxe.macro.Type`, in `tink.macro.TypeMap`. It's pretty much an ordinary map. Currently, it relies rather strongly on [`haxe.macro.TypeTools.toString()`](http://api.haxe.org/haxe/macro/TypeTools.html#toString) and it remains to be determined whether that is a reliable choice. Please report any issues you might face.
You can find a type map, i.e. a map where the keys are `haxe.macro.Type`, in `tink.macro.TypeMap`. It's pretty much an ordinary map. Currently, it relies rather strongly on [`haxe.macro.TypeTools.toString()`](http://api.haxe.org/haxe/macro/TypeTools.html#toString) and it remains to be determined whether that is a reliable choice. Please report any issues you might face.

View File

@@ -11,8 +11,8 @@
"contributors": [
"back2dos"
],
"releasenote": "Add build cache utility.",
"version": "0.8.0",
"releasenote": "Expand build cache for 2 and 3 type parameters.",
"version": "0.10.0",
"url": "http://haxetink.org/tink_macro",
"dependencies": {
"tink_core": ""

View File

@@ -5,6 +5,24 @@ import haxe.macro.Expr;
import haxe.macro.Type;
import tink.macro.TypeMap;
using haxe.macro.ComplexTypeTools;
using haxe.macro.TypeTools;
typedef BuildContext = {
pos:Position,
type:Type,
usings:Array<TypePath>,
name:String,
}
typedef BuildContext2 = {>BuildContext,
type2:Type,
}
typedef BuildContext3 = {>BuildContext2,
type3:Type,
}
class BuildCache {
static var cache = init();
@@ -22,7 +40,51 @@ class BuildCache {
return cache;
}
static public function getType(name, ?type, ?pos:Position, build:Position->Type->Array<TypePath>->String->TypeDefinition) {
static public function getType3(name, ?types, ?pos:Position, build:BuildContext3->TypeDefinition) {
if (types == null)
switch Context.getLocalType() {
case TInst(_.toString() == name => true, [t1, t2, t3]):
types = { t1: t1, t2: t2, t3: t3 };
default:
throw 'assert';
}
var t1 = types.t1.toComplexType(),
t2 = types.t2.toComplexType(),
t3 = types.t2.toComplexType();
return getType(name, (macro : { t1: $t1, t2: $t2, t3: $t3 } ).toType(), pos, function (ctx) return build({
type: types.t1,
type2: types.t2,
type3: types.t3,
pos: ctx.pos,
name: ctx.name,
usings: ctx.usings
}));
}
static public function getType2(name, ?types, ?pos:Position, build:BuildContext2->TypeDefinition) {
if (types == null)
switch Context.getLocalType() {
case TInst(_.toString() == name => true, [t1, t2]):
types = { t1: t1, t2: t2 };
default:
throw 'assert';
}
var t1 = types.t1.toComplexType(),
t2 = types.t2.toComplexType();
return getType(name, (macro : { t1: $t1, t2: $t2 } ).toType(), pos, function (ctx) return build({
type: types.t1,
type2: types.t2,
pos: ctx.pos,
name: ctx.name,
usings: ctx.usings
}));
}
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition) {
if (pos == null)
pos = Context.currentPos();
@@ -45,7 +107,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

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

@@ -27,10 +27,10 @@ private class Heureka { public function new() {} }
class Exprs {
static public function has(e:Expr, condition:Expr->Bool, ?options: { ?enterFunctions: Bool }) {
var enterFunctions = options != null && options.enterFunctions;
var skipFunctions = options == null || options.enterFunctions != true;
function seek(e:Expr)
switch e {
case { expr: EFunction(_) } if (options != null || options.enterFunctions != true):
case { expr: EFunction(_) } if (skipFunctions):
case _ if (condition(e)): throw new Heureka();
default: haxe.macro.ExprTools.iter(e, seek);
}
@@ -394,4 +394,4 @@ class Exprs {
static inline var NOT_A_STRING = "string constant expected";
static inline var NOT_A_NAME = "name expected";
static inline var NOT_A_FUNCTION = "function expected";
}
}

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,19 @@ 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[e.getInt().sure()]();
default:
throw 'assert';
}
}