Compare commits

..

8 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
6 changed files with 64 additions and 9 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": "Replace MacroType with @:genericBuild for direct type converions.",
"version": "0.9.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,9 @@ 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,
@@ -12,6 +15,14 @@ typedef BuildContext = {
name:String,
}
typedef BuildContext2 = {>BuildContext,
type2:Type,
}
typedef BuildContext3 = {>BuildContext2,
type3:Type,
}
class BuildCache {
static var cache = init();
@@ -29,6 +40,50 @@ class BuildCache {
return cache;
}
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)

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

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

@@ -168,12 +168,11 @@ class Types {
sub : null,
});
static function resolveDirectType()
return
switch reduce(Context.getLocalType()) {
case TInst(_, [TInst(_.get() => { kind: KExpr(e) }, _)]):
types.get(Std.parseInt(e.toString()))();
types[e.getInt().sure()]();
default:
throw 'assert';
}