Moved bouncer back top package.

This commit is contained in:
back2dos
2013-06-27 13:43:04 +02:00
parent 3a92c22790
commit b7c421cad2
5 changed files with 32 additions and 10 deletions

View File

@@ -5,7 +5,7 @@
"tags": ["tink", "macro", "utility"], "tags": ["tink", "macro", "utility"],
"description": "The macro toolkit ;)", "description": "The macro toolkit ;)",
"version": "0.0.0-alpha.2", "version": "0.0.0-alpha.2",
"releasenote": "Shorter names.", "releasenote": "Overall refactoring.",
"contributors": ["back2dos"], "contributors": ["back2dos"],
"dependencies": { "dependencies": {
"tink_core": "1.1.0-alpha.2" "tink_core": "1.1.0-alpha.2"

View File

@@ -1,4 +1,4 @@
package tink.macro.helpers; package tink.macro;
#if macro #if macro
import haxe.macro.Context; import haxe.macro.Context;
@@ -7,8 +7,7 @@ package tink.macro.helpers;
using tink.macro.Positions; using tink.macro.Positions;
using tink.macro.Exprs; using tink.macro.Exprs;
#end #end
class Bouncer { @:exclude class Bouncer {
//TODO: as is, a more less empty class is generated in the output. This is unneccessary.
#if macro #if macro
static var idCounter = 0; static var idCounter = 0;
static var bounceMap = new Map<Int,Void->Expr>(); static var bounceMap = new Map<Int,Void->Expr>();
@@ -16,13 +15,13 @@ class Bouncer {
static public function bounce(f:Void->Expr, ?pos) { static public function bounce(f:Void->Expr, ?pos) {
var id = idCounter++; var id = idCounter++;
bounceMap.set(id, f); bounceMap.set(id, f);
return 'tink.macro.helpers.Bouncer.catchBounce'.resolve(pos).call([id.toExpr(pos)], pos); return 'tink.macro.Bouncer.catchBounce'.resolve(pos).call([id.toExpr(pos)], pos);
} }
static public function outerTransform(e:Expr, transform:Expr->Expr) { static public function outerTransform(e:Expr, transform:Expr->Expr) {
var id = idCounter++, var id = idCounter++,
pos = e.pos; pos = e.pos;
outerMap.set(id, transform); outerMap.set(id, transform);
return 'tink.macro.helpers.Bouncer.makeOuter'.resolve(pos).call([e], pos).field('andBounce', pos).call([id.toExpr(pos)], pos); return 'tink.macro.Bouncer.makeOuter'.resolve(pos).call([e], pos).field('andBounce', pos).call([id.toExpr(pos)], pos);
} }
static function doOuter(id:Int, e:Expr) { static function doOuter(id:Int, e:Expr) {
return return
@@ -38,10 +37,10 @@ class Bouncer {
else else
Context.currentPos().error('unknown id ' + id); Context.currentPos().error('unknown id ' + id);
} }
#end #else
static public function makeOuter<A>(a:A):Bouncer static public function makeOuter<A>(a:A):Bouncer
return null; return null;
#end
macro public function andBounce(ethis:Expr, id:Int) { macro public function andBounce(ethis:Expr, id:Int) {
return return
switch (ethis.expr) { switch (ethis.expr) {

View File

@@ -2,7 +2,6 @@ package tink.macro;
import haxe.macro.Context; import haxe.macro.Context;
import haxe.macro.Expr; import haxe.macro.Expr;
import tink.macro.helpers.Bouncer;
using tink.macro.Positions; using tink.macro.Positions;
using tink.core.Outcome; using tink.core.Outcome;

View File

@@ -6,10 +6,11 @@ package tink.macro;
typedef _Exprs = Exprs; typedef _Exprs = Exprs;
typedef _Functions = Functions; typedef _Functions = Functions;
typedef _Metadatas = Metadatas; typedef _Metadatas = Metadatas;
typedef _Bouncer = tink.macro.helpers.Bouncer; typedef _Bouncer = Bouncer;
typedef _Types = Types; typedef _Types = Types;
typedef _Binops = Ops.Binary; typedef _Binops = Ops.Binary;
typedef _Unops = Ops.Unary; typedef _Unops = Ops.Unary;
typedef _Outcomes = tink.core.Outcome.OutcomeTools;
#end #end
class Tools { class Tools {
static var idCounter = 0; static var idCounter = 0;

23
tests/Run.hx Normal file
View File

@@ -0,0 +1,23 @@
package ;
#if !macro
import haxe.unit.TestCase;
import haxe.unit.TestRunner;
import neko.Lib;
#else
import haxe.macro.*;
using tink.macro.Tools;
#end
class Run {
#if !macro
static var tests:Array<TestCase> = [
];
static function main() {
test();//it compiles!!!
}
#end
macro static function test() {
return macro null;
}
}