Compare commits

..

11 Commits

Author SHA1 Message Date
Juraj Kirchheim
a77aedb458 Partial workaround for https://github.com/benmerckx/genes/issues/6 2020-01-02 19:44:41 +01:00
Juraj Kirchheim
b4fa5f4fe0 Update lix version to download correct nightly. 2019-09-13 09:45:24 +02:00
Juraj Kirchheim
e59fab499d Release 0.18.0 2019-09-13 09:40:22 +02:00
Juraj Kirchheim
3356172b7f Update to newest haxe version. 2019-09-13 09:39:24 +02:00
Juraj Kirchheim
4fd03ed667 Release 0.17.7 2019-06-29 11:27:39 +02:00
Juraj Kirchheim
4cb5ee4196 Use @:persistent as necessary. 2019-06-22 15:16:04 +02:00
Kevin Leung
888481094a Pin lix version 2019-05-14 11:33:28 +08:00
Kevin Leung
7686fe3e35 Use xenial 2019-05-14 11:10:52 +08:00
Kevin Leung
747d07bfc5 Revert "Better type comparison (closes #25)"
This reverts commit 00640d8328.
2019-05-13 18:53:42 +08:00
Kevin Leung
00640d8328 Better type comparison (closes #25) 2019-05-13 17:01:54 +08:00
Kevin Leung
77973f6007 print metadata 2019-05-13 17:00:54 +08:00
11 changed files with 89 additions and 58 deletions

View File

@@ -1,4 +1,4 @@
{
"version": "4.0.0-rc.1",
"version": "e552bdc",
"resolveLibs": "scoped"
}

View File

@@ -1,5 +1,5 @@
sudo: required
dist: trusty
dist: xenial
stages:
- test
@@ -17,7 +17,7 @@ env:
- HAXE_VERSION=edge
install:
- npm i -g lix
- npm i -g lix@15.5.4
- lix install haxe $HAXE_VERSION
- lix download

View File

@@ -1,3 +1,3 @@
# @install: lix --silent download "haxelib:tink_core#1.16.1" into tink_core/1.16.1/haxelib
-D tink_core=1.16.1
-cp ${HAXESHIM_LIBCACHE}/tink_core/1.16.1/haxelib/src
-D tink_core=1.24.0
# @install: lix --silent download "haxelib:/tink_core#1.24.0" into tink_core/1.24.0/haxelib
-cp ${HAXE_LIBCACHE}/tink_core/1.24.0/haxelib/src

View File

@@ -1,20 +1,20 @@
{
"name": "tink_macro",
"description": "The macro toolkit ;)",
"classPath": "src",
"dependencies": {
"tink_core": ""
},
"url": "http://haxetink.org/tink_macro",
"contributors": [
"back2dos"
],
"version": "0.17.6",
"releasenote": "Add call to find main class.",
"license": "MIT",
"tags": [
"tink",
"macro",
"utility"
],
"license": "MIT"
"classPath": "src",
"description": "The macro toolkit ;)",
"contributors": [
"back2dos"
],
"releasenote": "Compat with haxe 4 rc4 onward.",
"version": "0.18.0",
"url": "http://haxetink.org/tink_macro",
"dependencies": {
"tink_core": ""
}
}

View File

@@ -42,7 +42,7 @@ class MacroApi {
return None;
}
static var idCounter = 0;
@:persistent static var idCounter = 0;
@:noUsing static public inline function tempName(?prefix:String = 'tmp'):String
return '__tink_' + prefix + Std.string(idCounter++);

View File

@@ -33,7 +33,7 @@ typedef BuildContext3 = {>BuildContext2,
class BuildCache {
static var cache = new Map();
@:persistent static var cache = new Map();
static public function getType3(name, ?types, ?pos:Position, build:BuildContext3->TypeDefinition) {
if (types == null)

View File

@@ -21,24 +21,24 @@ class Constructor {
var afterArgs:Array<FunctionArg>;
var pos:Position;
var onGenerateHooks:Array<Function->Void>;
var superCall:Expr;
var superCall:Array<Expr>;
var owner:ClassBuilder;
var meta:Metadata;
public var isPublic:Null<Bool>;
public function new(owner:ClassBuilder, f:Function, ?isPublic:Null<Bool> = null, ?pos:Position, ?meta:Metadata) {
this.nuStatements = [];
this.owner = owner;
this.isPublic = isPublic;
this.pos = pos.sanitize();
this.onGenerateHooks = [];
this.args = [];
this.beforeArgs = [];
this.afterArgs = [];
this.meta = meta;
this.oldStatements =
this.oldStatements =
if (f == null) [];
else {
for (i in 0...f.args.length) {
@@ -49,62 +49,67 @@ class Constructor {
}
beforeArgs.push(a);
}
if (f.expr == null) [];
else
switch (f.expr.expr) {
case EBlock(exprs): exprs;
default: oldStatements = [f.expr];
default: oldStatements = [f.expr];
}
}
superCall =
if (oldStatements.length == 0) [].toBlock();
else switch oldStatements[0] {
case macro super($a{_}): oldStatements.shift();
default: [].toBlock();
for (i in 0...oldStatements.length)
switch oldStatements[i] {
case macro super($a{_}):
superCall = oldStatements.splice(0, i + 1);
break;
default:
}
if (superCall == null)
superCall = [];
}
public function getArgList():Array<FunctionArg>
return beforeArgs.concat(args).concat(afterArgs);
public function addStatement(e:Expr, ?prepend)
public function addStatement(e:Expr, ?prepend)
if (prepend)
this.nuStatements.unshift(e)
else
this.nuStatements.push(e);
public function addArg(name:String, ?t:ComplexType, ?e:Expr, ?opt = false)
public function addArg(name:String, ?t:ComplexType, ?e:Expr, ?opt = false)
args.push( { name : name, opt : opt || e != null, type : t, value: e } );
public function init(name:String, pos:Position, with:FieldInit, ?options:{ ?prepend:Bool, ?bypass:Bool }) {
if (options == null)
if (options == null)
options = {};
var e =
switch with {
case Arg(t, noPublish):
if (noPublish != true)
if (noPublish != true)
publish();
args.push( { name : name, opt : false, type : t } );
name.resolve(pos);
case OptArg(e, t, noPublish):
if (noPublish != true)
if (noPublish != true)
publish();
args.push( { name : name, opt : true, type : t, value: e } );
name.resolve(pos);
case Value(e): e;
}
var tmp = MacroApi.tempName();
var member = owner.memberByName(name).sure();
if (options.bypass && member.kind.match(FProp(_, 'never' | 'set', _, _))) {
member.addMeta(':isVar');
addStatement((function () {
var fields = [for (f in (macro this).typeof().sure().getClass().fields.get()) f.name => f];
function setDirectly(t:TypedExpr) {
var direct = null;
function seek(t:TypedExpr) {
@@ -112,15 +117,15 @@ class Constructor {
case TField({ expr: TConst(TThis) }, FInstance(_, _, f)) if (f.get().name == name): direct = t;
default: t.iter(seek);
}
}
}
seek(t);
if (direct == null) pos.error('nope');
var direct = Context.storeTypedExpr(direct);
return macro @:pos(pos) $direct = $e;
}
return switch fields[name] {
case null:
case null:
pos.error('this direct initialization causes the compiler to do really weird things');
case f:
switch f.kind {
@@ -138,24 +143,24 @@ class Constructor {
pos.error('not implemented');
}
}
}).bounce(), options.prepend);
}).bounce(), options.prepend);
}
else
else
addStatement(macro @:pos(pos) this.$name = $e, options.prepend);
}
public inline function publish()
if (isPublic == null)
public inline function publish()
if (isPublic == null)
isPublic = true;
function toBlock()
return [superCall]
function toBlock()
return superCall
.concat(nuStatements)
.concat(oldStatements)
.toBlock(pos);
public function onGenerate(hook)
public function onGenerate(hook)
this.onGenerateHooks.push(hook);
public function toHaxe():Field {
var f:Function = {
args: this.beforeArgs.concat(this.args).concat(this.afterArgs),

View File

@@ -4,9 +4,18 @@ import haxe.macro.Expr;
using tink.macro.Exprs;
#if haxe4
private abstract Kind(FunctionKind) from FunctionKind to FunctionKind {
@:from static function ofString(s:String):Kind
return FNamed(s);
}
#else
private typedef Kind = String;
#end
class Functions {
static public inline function asExpr(f:Function, ?name, ?pos)
return EFunction(name, f).at(pos);
static public inline function asExpr(f:Function, ?kind:Kind, ?pos)
return EFunction(kind, f).at(pos);
static public inline function toArg(name:String, ?t, ?opt = false, ?value = null):FunctionArg {
return {

View File

@@ -3,6 +3,7 @@ package tink.macro;
import haxe.macro.Expr;
class Metadatas {
static var printer = new haxe.macro.Printer();
static public function toMap(m:Metadata) {
var ret = new Map<String,Array<Array<Expr>>>();
if (m != null)
@@ -18,4 +19,8 @@ class Metadatas {
return
if (m == null) [];
else [for (meta in m) if (meta.name == name) meta.params];
static public inline function toString(m:MetadataEntry) {
return printer.printMetadata(m);
}
}

11
tests/Functions.hx Normal file
View File

@@ -0,0 +1,11 @@
import haxe.macro.Context;
import haxe.macro.Expr;
using tink.MacroApi;
class Functions extends Base {
function test() {
var f:Function = (macro function () {}).getFunction().sure();
f.asExpr('foo');
assertTrue(true);
}
}

View File

@@ -12,6 +12,7 @@ class Run {
new Types(),
new Positions(),
new TypeMapTest(),
new Functions(),
new Misc(),
];
#end