Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
65d341f1e1 | ||
![]() |
68fa50c7c3 | ||
![]() |
32aa2d6570 | ||
![]() |
d81642e733 | ||
![]() |
d5f4987ddb | ||
![]() |
671f1bc995 | ||
![]() |
b1012937fc | ||
![]() |
bd4b8c436f | ||
![]() |
dbebd0d70d | ||
![]() |
4c523e02a5 | ||
![]() |
f39fc3b296 | ||
![]() |
e06c40325b | ||
![]() |
7a3914094d | ||
![]() |
a597d7fa50 | ||
![]() |
3d5626d66f |
26
.travis.yml
26
.travis.yml
@@ -2,18 +2,26 @@ sudo: required
|
||||
dist: trusty
|
||||
|
||||
language: haxe
|
||||
|
||||
haxe:
|
||||
- "3.2.1"
|
||||
- development
|
||||
|
||||
- 3.2.1
|
||||
- development
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- haxe: development
|
||||
|
||||
- haxe: development
|
||||
|
||||
install:
|
||||
- haxelib install travix
|
||||
- haxelib run travix install
|
||||
- haxelib install travix
|
||||
- haxelib run travix install
|
||||
|
||||
script:
|
||||
- haxelib run travix node
|
||||
- haxelib run travix node
|
||||
|
||||
env:
|
||||
secure: T4SCtY5qmEsK1ARWPevJmqLm23tv4CobLrbPOQV3FsoQno7FCP1S/+9GmuoJKzeTjWMzdTeDsp8TVwZ6AyGjvhl2nZNjhU+QTsir4tfbYYRyvsz/QK6pveFbPQVv7OsnnaB4wbZtqGZ8mzFeQf7Ol4tsNe7iUFJb/iVc+4/lUxo=
|
||||
|
||||
deploy:
|
||||
provider: script
|
||||
script: haxelib run travix release
|
||||
on:
|
||||
tags: true
|
@@ -11,8 +11,8 @@
|
||||
"contributors": [
|
||||
"back2dos"
|
||||
],
|
||||
"releasenote": "Several minor improvements.",
|
||||
"version": "0.12.1",
|
||||
"releasenote": "Alias for TypeMap",
|
||||
"version": "0.13.2",
|
||||
"url": "http://haxetink.org/tink_macro",
|
||||
"dependencies": {
|
||||
"tink_core": ""
|
||||
|
@@ -14,6 +14,7 @@ typedef Bouncer = tink.macro.Bouncer;
|
||||
typedef Types = tink.macro.Types;
|
||||
typedef Binops = tink.macro.Ops.Binary;
|
||||
typedef Unops = tink.macro.Ops.Unary;
|
||||
typedef TypeMap<T> = tink.macro.TypeMap<T>;
|
||||
|
||||
//TODO: consider adding stuff from haxe.macro.Expr here
|
||||
typedef MacroOutcome<D, F> = tink.core.Outcome<D, F>;
|
||||
@@ -35,4 +36,4 @@ class MacroApi {
|
||||
static public function pos()
|
||||
return haxe.macro.Context.currentPos();
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import haxe.macro.Expr;
|
||||
import haxe.macro.Type;
|
||||
import tink.macro.TypeMap;
|
||||
|
||||
using tink.MacroApi;
|
||||
using haxe.macro.Tools;
|
||||
|
||||
typedef BuildContextN = {
|
||||
@@ -104,7 +105,7 @@ class BuildCache {
|
||||
usings: ctx.usings
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition) {
|
||||
|
||||
if (pos == null)
|
||||
@@ -156,32 +157,28 @@ private class Group {
|
||||
usings: usings,
|
||||
name: path.split('.').pop()
|
||||
});
|
||||
|
||||
Context.defineModule(path, [def], usings);
|
||||
|
||||
entries.set(type, { name: path } );
|
||||
Context.defineModule(path, [def], usings);
|
||||
return Context.getType(path);
|
||||
}
|
||||
|
||||
|
||||
function doMake()
|
||||
while (true)
|
||||
switch '$name${counter++}' {
|
||||
case _.definedType() => Some(_):
|
||||
case v:
|
||||
return make(v);
|
||||
}
|
||||
|
||||
return
|
||||
switch entries.get(type) {
|
||||
case null:
|
||||
var ret = null;
|
||||
while (ret == null) {
|
||||
try {
|
||||
Context.getType('$name$counter');
|
||||
}
|
||||
catch (e:Dynamic) {
|
||||
ret = make('$name$counter');
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
ret;
|
||||
doMake();
|
||||
case v:
|
||||
try {
|
||||
Context.getType(v.name);
|
||||
}
|
||||
catch (e:Dynamic) {
|
||||
make(v.name);
|
||||
switch v.name.definedType() {
|
||||
case Some(v): v;
|
||||
default: doMake();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
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 ? Types.toComplex(type, { direct: true }) : 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)) ],
|
||||
}
|
||||
}
|
||||
}
|
@@ -13,12 +13,18 @@ using tink.macro.Functions;
|
||||
using tink.CoreApi;
|
||||
|
||||
class Types {
|
||||
|
||||
static public function definedType(typeName:String)
|
||||
return
|
||||
try {
|
||||
Some(Context.getType(typeName));
|
||||
}
|
||||
catch (e:Dynamic)
|
||||
if (Std.string(e) == 'Type not found \'$typeName\'') None;
|
||||
else neko.Lib.rethrow(e);
|
||||
|
||||
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)();
|
||||
|
||||
static public function getID(t:Type, ?reduced = true)
|
||||
return
|
||||
if (reduced)
|
||||
@@ -152,7 +158,7 @@ class Types {
|
||||
|
||||
static public function toComplex(type:Type, ?options:{ ?direct: Bool }):ComplexType {
|
||||
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;
|
||||
if (ret == null)
|
||||
ret = lazyComplex(function () return type);
|
||||
|
Reference in New Issue
Block a user