Compare commits

..

36 Commits

Author SHA1 Message Date
Juraj Kirchheim
56b7caaf01 Release 0.13.5 2017-05-06 12:42:01 +02:00
Juraj Kirchheim
73e9da8435 Fix 3.2.1. 2017-04-13 21:07:44 +02:00
Juraj Kirchheim
bf23337923 Release 0.13.4 2017-04-13 21:04:00 +02:00
Juraj Kirchheim
02bd3bf69d Add Types.getMeta. 2017-04-13 21:02:58 +02:00
Juraj Kirchheim
82a3417b97 Gitignore. 2017-04-13 20:58:16 +02:00
Juraj Kirchheim
1f986c3732 VSCode setup. 2017-04-13 20:57:29 +02:00
Kevin Leung
20e998fd12 Release 0.13.3 2017-03-20 20:01:41 +08:00
Kevin Leung
0f9c0d1e97 what the haxe? 2017-03-20 19:49:21 +08:00
Kevin Leung
2ae13d534e my turn 2017-03-20 19:41:16 +08:00
back2dos
65d341f1e1 "push and read travis log" is the best kind of debugging ... 2017-03-20 11:50:32 +01:00
back2dos
68fa50c7c3 Let's see if we can fix that. 2017-03-20 11:32:50 +01:00
back2dos
32aa2d6570 Bump version. 2017-03-20 11:20:59 +01:00
back2dos
d81642e733 Use travix release. 2017-03-20 11:19:49 +01:00
Juraj Kirchheim
d5f4987ddb Release 0.13.1 2017-03-16 16:31:14 +01:00
Juraj Kirchheim
671f1bc995 Merge pull request #11 from haxetink/kevinresol-patch-1
Add TypeMap alias
2017-03-16 16:02:34 +01:00
back2dos
b1012937fc Release 0.13.0 2017-03-06 17:58:24 +01:00
back2dos
bd4b8c436f Build cache works better with compiler server. 2017-03-06 17:58:07 +01:00
back2dos
dbebd0d70d Allow querying whether a type exists. 2017-03-06 17:57:30 +01:00
Juraj Kirchheim
4c523e02a5 Release 0.12.3 2017-03-06 14:31:20 +01:00
Juraj Kirchheim
f39fc3b296 Try to save TMono. 2017-03-06 09:16:31 +01:00
Kevin Leung
e06c40325b Add TypeMap alias 2017-03-04 22:33:13 +08:00
back2dos
7a3914094d Release 0.12.2 2017-03-01 18:26:05 +01:00
back2dos
a597d7fa50 Workaround for https://github.com/HaxeFoundation/haxe/issues/6063 2017-03-01 18:25:21 +01:00
back2dos
3d5626d66f Give up on trying to work around cache problems. 2017-03-01 18:17:42 +01:00
Juraj Kirchheim
88a1ffba0b Release 0.12.1 2017-02-18 19:01:45 +01:00
Juraj Kirchheim
8f81959da9 Cleanup. 2017-02-18 19:00:51 +01:00
Juraj Kirchheim
b20986ecd0 Remove some old trace statements. 2017-02-18 19:00:07 +01:00
Juraj Kirchheim
e55b72b697 Merge branch 'master' of https://github.com/haxetink/tink_macro 2017-02-18 18:40:57 +01:00
Juraj Kirchheim
240ace34ec Try to deal with caching problems. 2017-02-18 18:40:48 +01:00
Juraj Kirchheim
d851094aa3 Update README.md 2016-12-07 06:44:36 +01:00
Juraj Kirchheim
ea16f79090 Merge pull request #8 from kevinresol/concat_block
Add concat()
2016-12-07 06:42:24 +01:00
Kevin Leung
aad311f524 Don't even need an outcome 2016-12-07 10:10:22 +08:00
Kevin Leung
f0d5d80266 Remove unused error message 2016-12-07 10:09:20 +08:00
Kevin Leung
38aa0f4dc4 Concat any exprs 2016-12-07 10:08:47 +08:00
Kevin Leung
f4fb7d63c3 Merge branch 'master' into concat_block 2016-12-07 10:01:38 +08:00
kevinresol
241919549c Add concat() 2016-08-21 15:02:42 +08:00
15 changed files with 202 additions and 36 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/bin

View File

@@ -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: haxe && haxelib run travix release
on:
tags: true

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"haxe.displayConfigurations": [
["tests.hxml"]
]
}

6
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"version": "0.1.0",
"command": "haxelib",
"args": ["run", "travix", "node"],
"problemMatcher": "$haxe"
}

View File

@@ -64,6 +64,8 @@ Rejects an expression and displays a generic or custom error message
Converts an expression into the corresponding Haxe source code
- `log(e:Expr, ?pos:Position):Expr`
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

View File

@@ -1,3 +0,0 @@
cd bin
neko tests.n
pause

1
bin/.gitignore vendored
View File

@@ -1 +0,0 @@
*.n

View File

@@ -11,8 +11,8 @@
"contributors": [
"back2dos"
],
"releasenote": "Improved build cache.",
"version": "0.12.0",
"releasenote": "Fix 3.2.1.",
"version": "0.13.5",
"url": "http://haxetink.org/tink_macro",
"dependencies": {
"tink_core": ""

View File

@@ -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();
}
}

View File

@@ -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,22 +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:
make('$name${counter++}');
doMake();
case v:
try {
Context.getType(v.name);
}
catch (e:Dynamic) {
make(v.name);
switch v.name.definedType() {
case Some(v): v;
default: doMake();
}
}
}

View File

@@ -388,6 +388,17 @@ class Exprs {
case EFunction(_, f): Success(f);
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_IDENT = "identifier expected";

105
src/tink/macro/Sisyphus.hx Normal file
View 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)) ],
}
}
}

View File

@@ -17,14 +17,15 @@ class TypeMap<V> extends BalancedTree<Type, V> implements IMap<Type, V> {
}
override function compare(k1:Type, k2:Type):Int {
if (follow) {
k1 = k1.reduce();
k2 = k2.reduce();
}
//trace(k1.toString());
//trace(k2.toString());
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;
}
}

View File

@@ -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)
@@ -43,6 +49,16 @@ class Types {
throw 'not implemented';
}
static public function getMeta(type:Type)
return switch type {
case TInst(_.get().meta => m, _): [m];
case TEnum(_.get().meta => m, _): [m];
case TAbstract(_.get().meta => m, _): [m];
case TType(_.get() => t, _): [t.meta].concat(getMeta(t.type));
case TLazy(f): getMeta(f());
default: [];
}
static function getDeclaredFields(t:ClassType, out:Array<ClassField>, marker:Map<String,Bool>) {
for (field in t.fields.get())
if (!marker.exists(field.name)) {
@@ -152,7 +168,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);
@@ -168,11 +184,11 @@ class Types {
sub : null,
});
static function resolveDirectType()
static function resolveDirectType()
return
switch reduce(Context.getLocalType()) {
case TInst(_, [TInst(_.get() => { kind: KExpr(e) }, _)]):
types[e.getInt().sure()]();
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';
}

View File

@@ -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;}));
}
}