Minor changes. Bump version.

This commit is contained in:
back2dos
2013-09-27 23:27:25 +02:00
parent cd15e4b00c
commit 8dc700b434
6 changed files with 162 additions and 140 deletions

20
LICENSE Normal file
View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 Juraj Kirchheim
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -4,11 +4,11 @@
"license": "MIT", "license": "MIT",
"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.3",
"releasenote": "Overall refactoring.", "releasenote": "Overall refactoring.",
"contributors": ["back2dos"], "contributors": ["back2dos"],
"dependencies": { "dependencies": {
"tink_core": "1.0.0-alpha.2" "tink_core": "1.0.0-beta.1"
}, },
"classPath": "src" "classPath": "src"
} }

View File

@@ -3,13 +3,14 @@ package tink.macro;
import haxe.macro.Context; import haxe.macro.Context;
import haxe.macro.Expr; import haxe.macro.Expr;
import tink.core.Error; import tink.core.Error;
using tink.macro.Positions; using tink.macro.Positions;
using tink.core.Outcome; using tink.core.Outcome;
class Positions { class Positions {
static public function getOutcome<D, F>(pos:Position, outcome:Outcome<D, F>):D static public function getOutcome<D, F>(pos:Position, outcome:Outcome<D, F>):D
return return
switch (outcome) { switch outcome {
case Success(d): d; case Success(d): d;
case Failure(f): pos.error(f); case Failure(f): pos.error(f);
} }

View File

@@ -1,70 +1,70 @@
package ; package ;
import haxe.macro.Expr; import haxe.macro.Expr;
using tink.Macro; using tink.Macro;
class Exprs extends Base { class Exprs extends Base {
function exprEq(e1:Expr, e2:Expr) { function exprEq(e1:Expr, e2:Expr) {
assertEquals(e1.toString(), e2.toString()); assertEquals(e1.toString(), e2.toString());
} }
function testGet() { function testGet() {
assertEquals('foo', (macro foo).getIdent().sure()); assertEquals('foo', (macro foo).getIdent().sure());
assertEquals('foo', (macro "foo").getString().sure()); assertEquals('foo', (macro "foo").getString().sure());
assertEquals('foo', (macro foo).getName().sure()); assertEquals('foo', (macro foo).getName().sure());
assertEquals('foo', (macro "foo").getName().sure()); assertEquals('foo', (macro "foo").getName().sure());
assertEquals(5, (macro 5).getInt().sure()); assertEquals(5, (macro 5).getInt().sure());
exprEq(macro [a, b, c], (macro function (a, b, c) [a, b, c]).getFunction().sure().expr); exprEq(macro [a, b, c], (macro function (a, b, c) [a, b, c]).getFunction().sure().expr);
assertEquals('a,b,c', [for (arg in (macro function (a, b, c) [a, b, c]).getFunction().sure().args) arg.name].join(',')); assertEquals('a,b,c', [for (arg in (macro function (a, b, c) [a, b, c]).getFunction().sure().args) arg.name].join(','));
assertFalse((macro 'foo').getIdent().isSuccess()); assertFalse((macro 'foo').getIdent().isSuccess());
assertFalse((macro foo).getString().isSuccess()); assertFalse((macro foo).getString().isSuccess());
assertFalse((macro 5).getName().isSuccess()); assertFalse((macro 5).getName().isSuccess());
assertFalse((macro 5.1).getInt().isSuccess()); assertFalse((macro 5.1).getInt().isSuccess());
assertFalse((macro foo).getFunction().isSuccess()); assertFalse((macro foo).getFunction().isSuccess());
} }
function testShortcuts() { function testShortcuts() {
assertTrue(true); assertTrue(true);
} }
function testIterType() { function testIterType() {
assertEquals('Int', (macro [1, 2]).getIterType().sure().getID()); assertEquals('Int', (macro [1, 2]).getIterType().sure().getID());
assertEquals('Int', (macro [1, 2].iterator()).getIterType().sure().getID()); assertEquals('Int', (macro [1, 2].iterator()).getIterType().sure().getID());
assertEquals('Int', ECheckType(macro null, macro: Arrayish).at().getIterType().sure().getID()); assertEquals('Int', ECheckType(macro null, macro: Arrayish).at().getIterType().sure().getID());
} }
function testYield() { function testYield() {
function yielder(e) return macro @yield $e; function yielder(e) return macro @yield $e;
function test(x:Expr, e:Expr) function test(x:Expr, e:Expr)
exprEq(x, e.yield(yielder)); exprEq(x, e.yield(yielder));
test(macro @yield foo, macro foo); test(macro @yield foo, macro foo);
test(macro @yield (foo), macro (foo)); test(macro @yield (foo), macro (foo));
test(macro for (_) @yield foo, macro for (_) foo); test(macro for (_) @yield foo, macro for (_) foo);
test(macro while (_) @yield foo, macro while (_) foo); test(macro while (_) @yield foo, macro while (_) foo);
test(macro @yield [while (_) foo], macro [while (_) foo]); test(macro @yield [while (_) foo], macro [while (_) foo]);
} }
function testSubstitute() { function testSubstitute() {
exprEq( exprEq(
macro foo.call(arg1, arg2), macro foo.call(arg1, arg2),
(macro bar.call(x, y)).substitute({ x: macro arg1, y: macro arg2, bar: macro foo }) (macro bar.call(x, y)).substitute({ x: macro arg1, y: macro arg2, bar: macro foo })
); );
exprEq( exprEq(
macro { macro {
var x:Map<Int, String> = new Map(), var x:Map<Int, String> = new Map(),
y:Array<Float> = []; y:Array<Float> = [];
}, },
(macro { (macro {
var x:Map<A, B> = new Map(), var x:Map<A, B> = new Map(),
y:C = []; y:C = [];
}).substParams([ }).substParams([
'A' => macro : Int, 'A' => macro : Int,
'B' => macro : String, 'B' => macro : String,
'C' => macro : Array<Float> 'C' => macro : Array<Float>
]) ])
); );
} }
} }

View File

@@ -1,23 +1,24 @@
package ; package ;
import haxe.macro.Context; import haxe.macro.Context;
import haxe.macro.Expr; import haxe.macro.Expr;
using tink.Macro;
using tink.Macro;
class Positions extends Base {
function stringCompare<A>(v1:A, v2:A) class Positions extends Base {
assertEquals(Std.string(v1), Std.string(v2)); function stringCompare<A>(v1:A, v2:A)
assertEquals(Std.string(v1), Std.string(v2));
function testSanitize() {
var p:Position = null; function testSanitize() {
stringCompare(Context.currentPos(), p.sanitize()); var p:Position = null;
p = Context.makePosition({ min: 0, max: 10, file: 'foo.txt' }); stringCompare(Context.currentPos(), p.sanitize());
stringCompare(p, p); p = Context.makePosition({ min: 0, max: 10, file: 'foo.txt' });
} stringCompare(p, p);
}
function testBlank() {
var p:Position = null; function testBlank() {
var t = p.makeBlankType(); var p:Position = null;
stringCompare('TMono(<mono>)', cast t.toType().sure()); var t = p.makeBlankType();
} stringCompare('TMono(<mono>)', cast t.toType().sure());
}
} }

View File

@@ -1,46 +1,46 @@
package ; package ;
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.Context; import haxe.macro.Context;
using tink.Macro;
using tink.Macro;
class Types extends Base {
function type(c:ComplexType) class Types extends Base {
return c.toType().sure(); function type(c:ComplexType)
return c.toType().sure();
function resolve(type:String)
return Context.getType(type); function resolve(type:String)
return Context.getType(type);
inline function assertSuccess<S, F>(o:Outcome<S, F>)
assertTrue(o.isSuccess()); inline function assertSuccess<S, F>(o:Outcome<S, F>)
assertTrue(o.isSuccess());
inline function assertFailure<S, F>(o:Outcome<S, F>)
assertFalse(o.isSuccess()); inline function assertFailure<S, F>(o:Outcome<S, F>)
assertFalse(o.isSuccess());
function testIs() {
assertSuccess(resolve('Int').isSubTypeOf(resolve('Float'))); function testIs() {
assertFailure(resolve('Float').isSubTypeOf(resolve('Int'))); assertSuccess(resolve('Int').isSubTypeOf(resolve('Float')));
} assertFailure(resolve('Float').isSubTypeOf(resolve('Int')));
}
function testFields() {
var iterator = type(macro : haxe.ds.StringMap<Arrayish>).getFields(true).sure().filter(function (c) return c.name == 'iterator')[0]; function testFields() {
var expected = type(macro : Void -> Iterator<Arrayish>); var expected = type(macro : Void -> Iterator<Arrayish>),
iterator = type(macro : haxe.ds.StringMap<Arrayish>).getFields(true).sure().filter(function (c) return c.name == 'iterator')[0];
assertSuccess(iterator.type.isSubTypeOf(expected));
assertSuccess(expected.isSubTypeOf(iterator.type)); assertSuccess(iterator.type.isSubTypeOf(expected));
} assertSuccess(expected.isSubTypeOf(iterator.type));
}
function testConvert() {
assertSuccess((macro : Int).toType()); function testConvert() {
assertFailure((macro : Tni).toType()); assertSuccess((macro : Int).toType());
function blank() assertFailure((macro : Tni).toType());
return type(Macro.pos().makeBlankType()); function blank()
return type(Macro.pos().makeBlankType());
var bool = type(macro : Bool);
assertTrue(blank().isSubTypeOf(bool).isSuccess()); var bool = type(macro : Bool);
assertTrue(bool.isSubTypeOf(blank()).isSuccess()); assertTrue(blank().isSubTypeOf(bool).isSuccess());
assertTrue(bool.isSubTypeOf(blank()).isSuccess());
Macro.pos().makeBlankType().toString();
} Macro.pos().makeBlankType().toString();
} }
}