Compare commits
33 Commits
0.8.1
...
kevinresol
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e06c40325b | ||
|
|
7a3914094d | ||
|
|
a597d7fa50 | ||
|
|
3d5626d66f | ||
|
|
88a1ffba0b | ||
|
|
8f81959da9 | ||
|
|
b20986ecd0 | ||
|
|
e55b72b697 | ||
|
|
240ace34ec | ||
|
|
d851094aa3 | ||
|
|
ea16f79090 | ||
|
|
aad311f524 | ||
|
|
f0d5d80266 | ||
|
|
38aa0f4dc4 | ||
|
|
f4fb7d63c3 | ||
|
|
27de7bb3e7 | ||
|
|
371f393299 | ||
|
|
abbb9e5a4c | ||
|
|
921ae162c8 | ||
|
|
fe779872d2 | ||
|
|
f8ab1c7354 | ||
|
|
ba5349f55f | ||
|
|
241919549c | ||
|
|
92f60cbe4f | ||
|
|
3b822b4cdb | ||
|
|
f2b670f9e4 | ||
|
|
ff491fe7e7 | ||
|
|
7e869cd9c8 | ||
|
|
983ffa16af | ||
|
|
4207dea754 | ||
|
|
3470f1cc47 | ||
|
|
d84fb38d73 | ||
|
|
065788c198 |
@@ -1,4 +1,5 @@
|
|||||||
# Tinkerbell Macro Library
|
# Tinkerbell Macro Library
|
||||||
|
[](https://gitter.im/haxetink/public)
|
||||||
|
|
||||||
Explained in current marketing speak, `tink_macro` is *the* macro toolkit ;)
|
Explained in current marketing speak, `tink_macro` is *the* macro toolkit ;)
|
||||||
|
|
||||||
@@ -63,6 +64,8 @@ Rejects an expression and displays a generic or custom error message
|
|||||||
Converts an expression into the corresponding Haxe source code
|
Converts an expression into the corresponding Haxe source code
|
||||||
- `log(e:Expr, ?pos:Position):Expr`
|
- `log(e:Expr, ?pos:Position):Expr`
|
||||||
Traces the string representation of an expression and returns it.
|
Traces the string representation of an expression and returns it.
|
||||||
|
- `concat(e1:Expr, e2:Expr):Expr`
|
||||||
|
Concats two expressions into a block. If either sub-expression is a block itself, it gets flattened into the resulting block.
|
||||||
|
|
||||||
#### Extracting Constants
|
#### Extracting Constants
|
||||||
|
|
||||||
@@ -412,4 +415,4 @@ Because the state of a constructor is rather delicate, the API prohibits you to
|
|||||||
|
|
||||||
# TypeMap
|
# 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.
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
"contributors": [
|
"contributors": [
|
||||||
"back2dos"
|
"back2dos"
|
||||||
],
|
],
|
||||||
"releasenote": "Minor API improvement.",
|
"releasenote": "Fix issue with .toComplex()",
|
||||||
"version": "0.8.1",
|
"version": "0.12.2",
|
||||||
"url": "http://haxetink.org/tink_macro",
|
"url": "http://haxetink.org/tink_macro",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tink_core": ""
|
"tink_core": ""
|
||||||
|
|||||||
@@ -14,13 +14,12 @@ typedef Bouncer = tink.macro.Bouncer;
|
|||||||
typedef Types = tink.macro.Types;
|
typedef Types = tink.macro.Types;
|
||||||
typedef Binops = tink.macro.Ops.Binary;
|
typedef Binops = tink.macro.Ops.Binary;
|
||||||
typedef Unops = tink.macro.Ops.Unary;
|
typedef Unops = tink.macro.Ops.Unary;
|
||||||
|
typedef TypeMap<T> = tink.macro.TypeMap<T>;
|
||||||
|
|
||||||
//TODO: consider adding stuff from haxe.macro.Expr here
|
//TODO: consider adding stuff from haxe.macro.Expr here
|
||||||
typedef MacroOutcome<D, F> = tink.core.Outcome<D, F>;
|
typedef MacroOutcome<D, F> = tink.core.Outcome<D, F>;
|
||||||
typedef MacroOutcomeTools = tink.OutcomeTools;
|
typedef MacroOutcomeTools = tink.OutcomeTools;
|
||||||
|
|
||||||
typedef Option<T> = haxe.ds.Option<T>;
|
|
||||||
|
|
||||||
typedef Member = tink.macro.Member;
|
typedef Member = tink.macro.Member;
|
||||||
typedef Constructor = tink.macro.Constructor;
|
typedef Constructor = tink.macro.Constructor;
|
||||||
typedef ClassBuilder = tink.macro.ClassBuilder;
|
typedef ClassBuilder = tink.macro.ClassBuilder;
|
||||||
@@ -37,4 +36,4 @@ class MacroApi {
|
|||||||
static public function pos()
|
static public function pos()
|
||||||
return haxe.macro.Context.currentPos();
|
return haxe.macro.Context.currentPos();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,16 @@ import haxe.macro.Expr;
|
|||||||
import haxe.macro.Type;
|
import haxe.macro.Type;
|
||||||
import tink.macro.TypeMap;
|
import tink.macro.TypeMap;
|
||||||
|
|
||||||
|
using haxe.macro.Tools;
|
||||||
|
|
||||||
|
typedef BuildContextN = {
|
||||||
|
pos:Position,
|
||||||
|
types:Array<Type>,
|
||||||
|
usings:Array<TypePath>,
|
||||||
|
name:String,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef BuildContext = {
|
typedef BuildContext = {
|
||||||
pos:Position,
|
pos:Position,
|
||||||
type:Type,
|
type:Type,
|
||||||
@@ -12,21 +22,87 @@ typedef BuildContext = {
|
|||||||
name:String,
|
name:String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef BuildContext2 = {>BuildContext,
|
||||||
|
type2:Type,
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef BuildContext3 = {>BuildContext2,
|
||||||
|
type3:Type,
|
||||||
|
}
|
||||||
|
|
||||||
class BuildCache {
|
class BuildCache {
|
||||||
|
|
||||||
static var cache = init();
|
static var cache = new Map();
|
||||||
|
|
||||||
static function init() {
|
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 getTypeN(name, ?types, ?pos:Position, build:BuildContextN->TypeDefinition) {
|
||||||
|
|
||||||
function refresh() {
|
if (pos == null)
|
||||||
cache = new Map();
|
pos = Context.currentPos();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Context.onMacroContextReused(refresh);
|
if (types == null)
|
||||||
refresh();
|
switch Context.getLocalType() {
|
||||||
|
case TInst(_.toString() == name => true, params):
|
||||||
return cache;
|
types = params;
|
||||||
|
default:
|
||||||
|
throw 'assert';
|
||||||
|
}
|
||||||
|
|
||||||
|
var compound = ComplexType.TAnonymous([for (i in 0...types.length) {
|
||||||
|
name: 't$i',
|
||||||
|
pos: pos,
|
||||||
|
kind: FVar(types[i].toComplexType()),
|
||||||
|
}]).toType();
|
||||||
|
|
||||||
|
return getType(name, compound, pos, function (ctx) return build({
|
||||||
|
types: types,
|
||||||
|
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) {
|
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition) {
|
||||||
@@ -38,20 +114,42 @@ class BuildCache {
|
|||||||
switch Context.getLocalType() {
|
switch Context.getLocalType() {
|
||||||
case TInst(_.toString() == name => true, [v]):
|
case TInst(_.toString() == name => true, [v]):
|
||||||
type = v;
|
type = v;
|
||||||
|
case TInst(_.toString() == name => true, _):
|
||||||
|
Context.fatalError('type parameter expected', pos);
|
||||||
|
case TInst(_.get() => { pos: pos }, _):
|
||||||
|
Context.fatalError('Expected $name', pos);
|
||||||
default:
|
default:
|
||||||
throw 'assert';
|
throw 'assert';
|
||||||
}
|
}
|
||||||
|
|
||||||
var forName =
|
var forName =
|
||||||
switch cache[name] {
|
switch cache[name] {
|
||||||
case null: cache[name] = new TypeMap();
|
case null: cache[name] = new Group(name);
|
||||||
case v: v;
|
case v: v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!forName.exists(type)) {
|
return forName.get(type, pos, build);
|
||||||
var path = '$name${Lambda.count(forName)}',
|
}
|
||||||
usings = [];
|
}
|
||||||
|
|
||||||
|
private typedef Entry = {
|
||||||
|
name:String,
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Group {
|
||||||
|
|
||||||
|
var name:String;
|
||||||
|
var counter = 0;
|
||||||
|
var entries = new TypeMap<Entry>();
|
||||||
|
|
||||||
|
public function new(name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(type:Type, pos:Position, build:BuildContext->TypeDefinition):Type {
|
||||||
|
|
||||||
|
function make(path:String) {
|
||||||
|
var usings = [];
|
||||||
var def = build({
|
var def = build({
|
||||||
pos: pos,
|
pos: pos,
|
||||||
type: type,
|
type: type,
|
||||||
@@ -60,9 +158,16 @@ class BuildCache {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Context.defineModule(path, [def], usings);
|
Context.defineModule(path, [def], usings);
|
||||||
forName.set(type, Context.getType(path));
|
entries.set(type, { name: path } );
|
||||||
|
return Context.getType(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return forName.get(type);
|
return
|
||||||
|
switch entries.get(type) {
|
||||||
|
case null:
|
||||||
|
make('$name${counter++}');
|
||||||
|
case v:
|
||||||
|
Context.getType(v.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ class ClassBuilder {
|
|||||||
init();
|
init();
|
||||||
if (constructor == null)
|
if (constructor == null)
|
||||||
if (fallback != null)
|
if (fallback != null)
|
||||||
new Constructor(this, fallback);
|
constructor = new Constructor(this, fallback);
|
||||||
else {
|
else {
|
||||||
var sup = target.superClass;
|
var sup = target.superClass;
|
||||||
while (sup != null) {
|
while (sup != null) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class Constructor {
|
|||||||
case Success(member): member.addMeta(':isVar');
|
case Success(member): member.addMeta(':isVar');
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
addStatement(macro @:pos(pos) (cast this).$name = if (true) $e else this.$name, options.prepend);
|
addStatement(macro @:pos(pos) (cast this).$name = if (true) $e else this.$name, options.prepend);//TODO: this seems to report type errors here rather than at the declaration position
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
addStatement(macro @:pos(pos) this.$name = $e, options.prepend);
|
addStatement(macro @:pos(pos) this.$name = $e, options.prepend);
|
||||||
|
|||||||
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> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,10 +27,10 @@ private class Heureka { public function new() {} }
|
|||||||
class Exprs {
|
class Exprs {
|
||||||
|
|
||||||
static public function has(e:Expr, condition:Expr->Bool, ?options: { ?enterFunctions: Bool }) {
|
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)
|
function seek(e:Expr)
|
||||||
switch e {
|
switch e {
|
||||||
case { expr: EFunction(_) } if (options != null || options.enterFunctions != true):
|
case { expr: EFunction(_) } if (skipFunctions):
|
||||||
case _ if (condition(e)): throw new Heureka();
|
case _ if (condition(e)): throw new Heureka();
|
||||||
default: haxe.macro.ExprTools.iter(e, seek);
|
default: haxe.macro.ExprTools.iter(e, seek);
|
||||||
}
|
}
|
||||||
@@ -388,10 +388,21 @@ class Exprs {
|
|||||||
case EFunction(_, f): Success(f);
|
case EFunction(_, f): Success(f);
|
||||||
default: e.pos.makeFailure(NOT_A_FUNCTION);
|
default: e.pos.makeFailure(NOT_A_FUNCTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function concat(e:Expr, with:Expr, ?pos) {
|
||||||
|
if(pos == null) pos = e.pos;
|
||||||
|
return
|
||||||
|
switch [e.expr, with.expr] {
|
||||||
|
case [EBlock(e1), EBlock(e2)]: EBlock(e1.concat(e2)).at(pos);
|
||||||
|
case [EBlock(e1), e2]: EBlock(e1.concat([with])).at(pos);
|
||||||
|
case [e1, EBlock(e2)]: EBlock([e].concat(e2)).at(pos);
|
||||||
|
default: EBlock([e, with]).at(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline var NOT_AN_INT = "integer constant expected";
|
static inline var NOT_AN_INT = "integer constant expected";
|
||||||
static inline var NOT_AN_IDENT = "identifier expected";
|
static inline var NOT_AN_IDENT = "identifier expected";
|
||||||
static inline var NOT_A_STRING = "string constant expected";
|
static inline var NOT_A_STRING = "string constant expected";
|
||||||
static inline var NOT_A_NAME = "name expected";
|
static inline var NOT_A_NAME = "name expected";
|
||||||
static inline var NOT_A_FUNCTION = "function expected";
|
static inline var NOT_A_FUNCTION = "function expected";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Positions {
|
|||||||
return errorFunc(sanitize(pos), Std.string(error));
|
return errorFunc(sanitize(pos), Std.string(error));
|
||||||
|
|
||||||
static function contextError(pos:Position, error:String):Dynamic
|
static function contextError(pos:Position, error:String):Dynamic
|
||||||
return Context.error(error, pos);
|
return Context.fatalError(error, pos);
|
||||||
|
|
||||||
static function abortTypeBuild(pos:Position, error:String):Dynamic
|
static function abortTypeBuild(pos:Position, error:String):Dynamic
|
||||||
return throw new AbortBuild(error, pos);
|
return throw new AbortBuild(error, pos);
|
||||||
|
|||||||
105
src/tink/macro/Sisyphus.hx
Normal file
105
src/tink/macro/Sisyphus.hx
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package tink.macro;
|
||||||
|
|
||||||
|
import haxe.macro.Expr;
|
||||||
|
import haxe.macro.Type;
|
||||||
|
|
||||||
|
class Sisyphus {
|
||||||
|
|
||||||
|
static function nullable(complexType : ComplexType) : ComplexType return macro : Null<$complexType>;
|
||||||
|
|
||||||
|
static function toField(cf : ClassField) : Field return {
|
||||||
|
function varAccessToString(va : VarAccess, getOrSet : String) : String return {
|
||||||
|
switch (va) {
|
||||||
|
case AccNormal: "default";
|
||||||
|
case AccNo: "null";
|
||||||
|
case AccNever: "never";
|
||||||
|
case AccResolve: throw "Invalid TAnonymous";
|
||||||
|
case AccCall: getOrSet;
|
||||||
|
case AccInline: "default";
|
||||||
|
case AccRequire(_, _): "default";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cf.params.length == 0) {
|
||||||
|
name: cf.name,
|
||||||
|
doc: cf.doc,
|
||||||
|
access: cf.isPublic ? [ APublic ] : [ APrivate ],
|
||||||
|
kind: switch([ cf.kind, cf.type ]) {
|
||||||
|
case [ FVar(read, write), ret ]:
|
||||||
|
FProp(
|
||||||
|
varAccessToString(read, "get"),
|
||||||
|
varAccessToString(write, "set"),
|
||||||
|
toComplexType(ret),
|
||||||
|
null);
|
||||||
|
case [ FMethod(_), TFun(args, ret) ]:
|
||||||
|
FFun({
|
||||||
|
args: [
|
||||||
|
for (a in args) {
|
||||||
|
name: a.name,
|
||||||
|
opt: a.opt,
|
||||||
|
type: toComplexType(a.t),
|
||||||
|
}
|
||||||
|
],
|
||||||
|
ret: toComplexType(ret),
|
||||||
|
expr: null,
|
||||||
|
});
|
||||||
|
default:
|
||||||
|
throw "Invalid TAnonymous";
|
||||||
|
},
|
||||||
|
pos: cf.pos,
|
||||||
|
meta: cf.meta.get(),
|
||||||
|
} else {
|
||||||
|
throw "Invalid TAnonymous";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function toComplexType(type : Null<Type>) : Null<ComplexType> return
|
||||||
|
switch (type) {
|
||||||
|
case null:
|
||||||
|
null;
|
||||||
|
case TMono(_.get() => t):
|
||||||
|
t == null ? null : toComplexType(t);
|
||||||
|
case TEnum(_.get() => baseType, params):
|
||||||
|
TPath(toTypePath(baseType, params));
|
||||||
|
case TInst(_.get() => classType, params):
|
||||||
|
switch (classType.kind) {
|
||||||
|
case KTypeParameter(_):
|
||||||
|
TPath({
|
||||||
|
name: classType.name,
|
||||||
|
pack: [],
|
||||||
|
});
|
||||||
|
default:
|
||||||
|
TPath(toTypePath(classType, params));
|
||||||
|
}
|
||||||
|
case TType(_.get() => baseType, params):
|
||||||
|
TPath(toTypePath(baseType, params));
|
||||||
|
case TFun(args, ret):
|
||||||
|
TFunction(
|
||||||
|
[ for (a in args) a.opt ? nullable(toComplexType(a.t)) : toComplexType(a.t) ],
|
||||||
|
toComplexType(ret));
|
||||||
|
case TAnonymous(_.get() => { fields: fields }):
|
||||||
|
TAnonymous([ for (cf in fields) toField(cf) ]);
|
||||||
|
case TDynamic(t):
|
||||||
|
if (t == null) {
|
||||||
|
macro : Dynamic;
|
||||||
|
} else {
|
||||||
|
var ct = toComplexType(t);
|
||||||
|
macro : Dynamic<$ct>;
|
||||||
|
}
|
||||||
|
case TLazy(f):
|
||||||
|
toComplexType(f());
|
||||||
|
case TAbstract(_.get() => baseType, params):
|
||||||
|
TPath(toTypePath(baseType, params));
|
||||||
|
default:
|
||||||
|
throw "Invalid type";
|
||||||
|
}
|
||||||
|
|
||||||
|
static function toTypePath(baseType : BaseType, params : Array<Type>) : TypePath return {
|
||||||
|
var module = baseType.module;
|
||||||
|
{
|
||||||
|
pack: baseType.pack,
|
||||||
|
name: module.substring(module.lastIndexOf(".") + 1),
|
||||||
|
sub: baseType.name,
|
||||||
|
params: [ for (t in params) TPType(toComplexType(t)) ],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,14 +17,15 @@ class TypeMap<V> extends BalancedTree<Type, V> implements IMap<Type, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override function compare(k1:Type, k2:Type):Int {
|
override function compare(k1:Type, k2:Type):Int {
|
||||||
|
|
||||||
if (follow) {
|
if (follow) {
|
||||||
k1 = k1.reduce();
|
k1 = k1.reduce();
|
||||||
k2 = k2.reduce();
|
k2 = k2.reduce();
|
||||||
}
|
}
|
||||||
//trace(k1.toString());
|
|
||||||
//trace(k2.toString());
|
|
||||||
return switch k1.getIndex() - k2.getIndex() {
|
return switch k1.getIndex() - k2.getIndex() {
|
||||||
case 0: Reflect.compare(k1.toString(), k2.toString());//TODO: this may be rather expensive and not very reliable
|
case 0:
|
||||||
|
Reflect.compare(k1.toString(), k2.toString());//much to my surprise, this actually seems to work (at least with 3.4)
|
||||||
case v: v;
|
case v: v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,6 @@ using tink.CoreApi;
|
|||||||
class Types {
|
class Types {
|
||||||
static var types = new Map<Int,Void->Type>();
|
static var types = new Map<Int,Void->Type>();
|
||||||
static var idCounter = 0;
|
static var idCounter = 0;
|
||||||
|
|
||||||
@:noUsing macro static public function getType(id:Int):Type
|
|
||||||
return types.get(id)();
|
|
||||||
|
|
||||||
static public function getID(t:Type, ?reduced = true)
|
static public function getID(t:Type, ?reduced = true)
|
||||||
return
|
return
|
||||||
if (reduced)
|
if (reduced)
|
||||||
@@ -152,7 +148,7 @@ class Types {
|
|||||||
|
|
||||||
static public function toComplex(type:Type, ?options:{ ?direct: Bool }):ComplexType {
|
static public function toComplex(type:Type, ?options:{ ?direct: Bool }):ComplexType {
|
||||||
var ret =
|
var ret =
|
||||||
if (options == null || options.direct != true) haxe.macro.TypeTools.toComplexType(type);
|
if (options == null || options.direct != true) tink.macro.Sisyphus.toComplexType(type);
|
||||||
else null;
|
else null;
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
ret = lazyComplex(function () return type);
|
ret = lazyComplex(function () return type);
|
||||||
@@ -162,9 +158,19 @@ class Types {
|
|||||||
static public function lazyComplex(f:Void->Type)
|
static public function lazyComplex(f:Void->Type)
|
||||||
return
|
return
|
||||||
TPath({
|
TPath({
|
||||||
pack : ['haxe','macro'],
|
pack : ['tink','macro'],
|
||||||
name : 'MacroType',
|
name : 'DirectType',
|
||||||
params : [TPExpr('tink.macro.Types.getType'.resolve().call([register(f).toExpr()]))],
|
params : [TPExpr(register(f).toExpr())],
|
||||||
sub : null,
|
sub : null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static function resolveDirectType()
|
||||||
|
return
|
||||||
|
switch reduce(Context.getLocalType()) {
|
||||||
|
case TInst(_, [TInst(_.get() => { kind: KExpr(e) }, _)]):
|
||||||
|
types[e.getInt().sure()]();//When using compiler server, this call throws on occasion, in which case modifying this file (to update mtime and invalidate the cache) will solve the problem
|
||||||
|
default:
|
||||||
|
throw 'assert';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,4 +80,11 @@ class Exprs extends Base {
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testConcat() {
|
||||||
|
exprEq(macro {a; b;}, (macro a).concat(macro b));
|
||||||
|
exprEq(macro {a; b; c;}, (macro {a; b;}).concat(macro c));
|
||||||
|
exprEq(macro {a; b; c;}, (macro a).concat(macro {b; c;}));
|
||||||
|
exprEq(macro {a; b; c; d;}, (macro {a; b;}).concat(macro {c; d;}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user