Compare commits
4 Commits
0.17.7
...
genes-issu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a77aedb458 | ||
|
|
b4fa5f4fe0 | ||
|
|
e59fab499d | ||
|
|
3356172b7f |
2
.haxerc
2
.haxerc
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"version": "4.0.0-rc.3",
|
"version": "e552bdc",
|
||||||
"resolveLibs": "scoped"
|
"resolveLibs": "scoped"
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ env:
|
|||||||
- HAXE_VERSION=edge
|
- HAXE_VERSION=edge
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- npm i -g lix@15.3.13
|
- npm i -g lix@15.5.4
|
||||||
- lix install haxe $HAXE_VERSION
|
- lix install haxe $HAXE_VERSION
|
||||||
- lix download
|
- lix download
|
||||||
|
|
||||||
|
|||||||
@@ -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.24.0
|
||||||
-D tink_core=1.16.1
|
# @install: lix --silent download "haxelib:/tink_core#1.24.0" into tink_core/1.24.0/haxelib
|
||||||
-cp ${HAXESHIM_LIBCACHE}/tink_core/1.16.1/haxelib/src
|
-cp ${HAXE_LIBCACHE}/tink_core/1.24.0/haxelib/src
|
||||||
|
|||||||
24
haxelib.json
24
haxelib.json
@@ -1,20 +1,20 @@
|
|||||||
{
|
{
|
||||||
"name": "tink_macro",
|
"name": "tink_macro",
|
||||||
"description": "The macro toolkit ;)",
|
"license": "MIT",
|
||||||
"classPath": "src",
|
|
||||||
"dependencies": {
|
|
||||||
"tink_core": ""
|
|
||||||
},
|
|
||||||
"url": "http://haxetink.org/tink_macro",
|
|
||||||
"contributors": [
|
|
||||||
"back2dos"
|
|
||||||
],
|
|
||||||
"version": "0.17.7",
|
|
||||||
"releasenote": "Use @:persistent as necessary.",
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"tink",
|
"tink",
|
||||||
"macro",
|
"macro",
|
||||||
"utility"
|
"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": ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,24 +21,24 @@ class Constructor {
|
|||||||
var afterArgs:Array<FunctionArg>;
|
var afterArgs:Array<FunctionArg>;
|
||||||
var pos:Position;
|
var pos:Position;
|
||||||
var onGenerateHooks:Array<Function->Void>;
|
var onGenerateHooks:Array<Function->Void>;
|
||||||
var superCall:Expr;
|
var superCall:Array<Expr>;
|
||||||
var owner:ClassBuilder;
|
var owner:ClassBuilder;
|
||||||
var meta:Metadata;
|
var meta:Metadata;
|
||||||
public var isPublic:Null<Bool>;
|
public var isPublic:Null<Bool>;
|
||||||
|
|
||||||
public function new(owner:ClassBuilder, f:Function, ?isPublic:Null<Bool> = null, ?pos:Position, ?meta:Metadata) {
|
public function new(owner:ClassBuilder, f:Function, ?isPublic:Null<Bool> = null, ?pos:Position, ?meta:Metadata) {
|
||||||
this.nuStatements = [];
|
this.nuStatements = [];
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.isPublic = isPublic;
|
this.isPublic = isPublic;
|
||||||
this.pos = pos.sanitize();
|
this.pos = pos.sanitize();
|
||||||
|
|
||||||
this.onGenerateHooks = [];
|
this.onGenerateHooks = [];
|
||||||
this.args = [];
|
this.args = [];
|
||||||
this.beforeArgs = [];
|
this.beforeArgs = [];
|
||||||
this.afterArgs = [];
|
this.afterArgs = [];
|
||||||
this.meta = meta;
|
this.meta = meta;
|
||||||
|
|
||||||
this.oldStatements =
|
this.oldStatements =
|
||||||
if (f == null) [];
|
if (f == null) [];
|
||||||
else {
|
else {
|
||||||
for (i in 0...f.args.length) {
|
for (i in 0...f.args.length) {
|
||||||
@@ -49,62 +49,67 @@ class Constructor {
|
|||||||
}
|
}
|
||||||
beforeArgs.push(a);
|
beforeArgs.push(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f.expr == null) [];
|
if (f.expr == null) [];
|
||||||
else
|
else
|
||||||
switch (f.expr.expr) {
|
switch (f.expr.expr) {
|
||||||
case EBlock(exprs): exprs;
|
case EBlock(exprs): exprs;
|
||||||
default: oldStatements = [f.expr];
|
default: oldStatements = [f.expr];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
superCall =
|
|
||||||
if (oldStatements.length == 0) [].toBlock();
|
for (i in 0...oldStatements.length)
|
||||||
else switch oldStatements[0] {
|
switch oldStatements[i] {
|
||||||
case macro super($a{_}): oldStatements.shift();
|
case macro super($a{_}):
|
||||||
default: [].toBlock();
|
superCall = oldStatements.splice(0, i + 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (superCall == null)
|
||||||
|
superCall = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArgList():Array<FunctionArg>
|
public function getArgList():Array<FunctionArg>
|
||||||
return beforeArgs.concat(args).concat(afterArgs);
|
return beforeArgs.concat(args).concat(afterArgs);
|
||||||
|
|
||||||
public function addStatement(e:Expr, ?prepend)
|
public function addStatement(e:Expr, ?prepend)
|
||||||
if (prepend)
|
if (prepend)
|
||||||
this.nuStatements.unshift(e)
|
this.nuStatements.unshift(e)
|
||||||
else
|
else
|
||||||
this.nuStatements.push(e);
|
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 } );
|
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 }) {
|
public function init(name:String, pos:Position, with:FieldInit, ?options:{ ?prepend:Bool, ?bypass:Bool }) {
|
||||||
if (options == null)
|
if (options == null)
|
||||||
options = {};
|
options = {};
|
||||||
var e =
|
var e =
|
||||||
switch with {
|
switch with {
|
||||||
case Arg(t, noPublish):
|
case Arg(t, noPublish):
|
||||||
if (noPublish != true)
|
if (noPublish != true)
|
||||||
publish();
|
publish();
|
||||||
args.push( { name : name, opt : false, type : t } );
|
args.push( { name : name, opt : false, type : t } );
|
||||||
name.resolve(pos);
|
name.resolve(pos);
|
||||||
case OptArg(e, t, noPublish):
|
case OptArg(e, t, noPublish):
|
||||||
if (noPublish != true)
|
if (noPublish != true)
|
||||||
publish();
|
publish();
|
||||||
args.push( { name : name, opt : true, type : t, value: e } );
|
args.push( { name : name, opt : true, type : t, value: e } );
|
||||||
name.resolve(pos);
|
name.resolve(pos);
|
||||||
case Value(e): e;
|
case Value(e): e;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tmp = MacroApi.tempName();
|
var tmp = MacroApi.tempName();
|
||||||
var member = owner.memberByName(name).sure();
|
var member = owner.memberByName(name).sure();
|
||||||
|
|
||||||
if (options.bypass && member.kind.match(FProp(_, 'never' | 'set', _, _))) {
|
if (options.bypass && member.kind.match(FProp(_, 'never' | 'set', _, _))) {
|
||||||
|
|
||||||
member.addMeta(':isVar');
|
member.addMeta(':isVar');
|
||||||
|
|
||||||
addStatement((function () {
|
addStatement((function () {
|
||||||
var fields = [for (f in (macro this).typeof().sure().getClass().fields.get()) f.name => f];
|
var fields = [for (f in (macro this).typeof().sure().getClass().fields.get()) f.name => f];
|
||||||
|
|
||||||
function setDirectly(t:TypedExpr) {
|
function setDirectly(t:TypedExpr) {
|
||||||
var direct = null;
|
var direct = null;
|
||||||
function seek(t:TypedExpr) {
|
function seek(t:TypedExpr) {
|
||||||
@@ -112,15 +117,15 @@ class Constructor {
|
|||||||
case TField({ expr: TConst(TThis) }, FInstance(_, _, f)) if (f.get().name == name): direct = t;
|
case TField({ expr: TConst(TThis) }, FInstance(_, _, f)) if (f.get().name == name): direct = t;
|
||||||
default: t.iter(seek);
|
default: t.iter(seek);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
seek(t);
|
seek(t);
|
||||||
if (direct == null) pos.error('nope');
|
if (direct == null) pos.error('nope');
|
||||||
var direct = Context.storeTypedExpr(direct);
|
var direct = Context.storeTypedExpr(direct);
|
||||||
return macro @:pos(pos) $direct = $e;
|
return macro @:pos(pos) $direct = $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return switch fields[name] {
|
return switch fields[name] {
|
||||||
case null:
|
case null:
|
||||||
pos.error('this direct initialization causes the compiler to do really weird things');
|
pos.error('this direct initialization causes the compiler to do really weird things');
|
||||||
case f:
|
case f:
|
||||||
switch f.kind {
|
switch f.kind {
|
||||||
@@ -138,24 +143,24 @@ class Constructor {
|
|||||||
pos.error('not implemented');
|
pos.error('not implemented');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).bounce(), options.prepend);
|
}).bounce(), options.prepend);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
addStatement(macro @:pos(pos) this.$name = $e, options.prepend);
|
addStatement(macro @:pos(pos) this.$name = $e, options.prepend);
|
||||||
}
|
}
|
||||||
public inline function publish()
|
public inline function publish()
|
||||||
if (isPublic == null)
|
if (isPublic == null)
|
||||||
isPublic = true;
|
isPublic = true;
|
||||||
|
|
||||||
function toBlock()
|
function toBlock()
|
||||||
return [superCall]
|
return superCall
|
||||||
.concat(nuStatements)
|
.concat(nuStatements)
|
||||||
.concat(oldStatements)
|
.concat(oldStatements)
|
||||||
.toBlock(pos);
|
.toBlock(pos);
|
||||||
|
|
||||||
public function onGenerate(hook)
|
public function onGenerate(hook)
|
||||||
this.onGenerateHooks.push(hook);
|
this.onGenerateHooks.push(hook);
|
||||||
|
|
||||||
public function toHaxe():Field {
|
public function toHaxe():Field {
|
||||||
var f:Function = {
|
var f:Function = {
|
||||||
args: this.beforeArgs.concat(this.args).concat(this.afterArgs),
|
args: this.beforeArgs.concat(this.args).concat(this.afterArgs),
|
||||||
|
|||||||
@@ -4,9 +4,18 @@ import haxe.macro.Expr;
|
|||||||
|
|
||||||
using tink.macro.Exprs;
|
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 {
|
class Functions {
|
||||||
static public inline function asExpr(f:Function, ?name, ?pos)
|
static public inline function asExpr(f:Function, ?kind:Kind, ?pos)
|
||||||
return EFunction(name, f).at(pos);
|
return EFunction(kind, f).at(pos);
|
||||||
|
|
||||||
static public inline function toArg(name:String, ?t, ?opt = false, ?value = null):FunctionArg {
|
static public inline function toArg(name:String, ?t, ?opt = false, ?value = null):FunctionArg {
|
||||||
return {
|
return {
|
||||||
|
|||||||
11
tests/Functions.hx
Normal file
11
tests/Functions.hx
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ class Run {
|
|||||||
new Types(),
|
new Types(),
|
||||||
new Positions(),
|
new Positions(),
|
||||||
new TypeMapTest(),
|
new TypeMapTest(),
|
||||||
|
new Functions(),
|
||||||
new Misc(),
|
new Misc(),
|
||||||
];
|
];
|
||||||
#end
|
#end
|
||||||
|
|||||||
Reference in New Issue
Block a user