Resolves #12. Resolves #18.

This commit is contained in:
Juraj Kirchheim
2020-04-24 15:38:51 +02:00
parent e3bac681ce
commit acb7237ae4
2 changed files with 52 additions and 50 deletions

View File

@@ -35,7 +35,7 @@ class BuildCache {
@:persistent static var cache = new Map();
static public function getType3(name, ?types, ?pos:Position, build:BuildContext3->TypeDefinition) {
static public function getType3(name, ?types, ?pos:Position, build:BuildContext3->TypeDefinition, ?normalizer:Type->Type) {
if (types == null)
switch Context.getLocalType() {
case TInst(_.toString() == name => true, [t1, t2, t3]):
@@ -55,10 +55,10 @@ class BuildCache {
pos: ctx.pos,
name: ctx.name,
usings: ctx.usings
}));
}), normalizer);
}
static public function getTypeN(name, ?types, ?pos:Position, build:BuildContextN->TypeDefinition) {
static public function getTypeN(name, ?types, ?pos:Position, build:BuildContextN->TypeDefinition, ?normalizer:Type->Type) {
if (pos == null)
pos = Context.currentPos();
@@ -86,10 +86,10 @@ class BuildCache {
pos: ctx.pos,
name: ctx.name,
usings: ctx.usings
}));
}), normalizer);
}
static public function getType2(name, ?types, ?pos:Position, build:BuildContext2->TypeDefinition) {
static public function getType2(name, ?types, ?pos:Position, build:BuildContext2->TypeDefinition, ?normalizer:Type->Type) {
if (types == null)
switch Context.getLocalType() {
case TInst(_.toString() == name => true, [t1, t2]):
@@ -107,7 +107,7 @@ class BuildCache {
pos: ctx.pos,
name: ctx.name,
usings: ctx.usings
}));
}), normalizer);
}
static public function getParams(name:String, ?pos:Position)
@@ -130,14 +130,14 @@ class BuildCache {
default: pos.makeFailure('too many parameters');
});
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition) {
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition, ?normalizer:Type->Type) {
if (type == null)
type = getParam(name, pos).sure();
var forName =
switch cache[name] {
case null: cache[name] = new Group(name);
case null: cache[name] = new Group(name, normalizer);
case v: v;
}
@@ -155,10 +155,11 @@ private class Group {
var name:String;
var counter = 0;
var entries = new TypeMap<Entry>();
var entries:TypeMap<Entry>;
public function new(name) {
public function new(name, ?normalizer) {
this.name = name;
this.entries = new TypeMap(normalizer);
}
public function get(type:Type, pos:Position, build:BuildContext->TypeDefinition):Type {

View File

@@ -19,6 +19,7 @@ class Run {
macro static function test() {
var runner = new TestRunner();
tink.macro.ClassBuilder;
tink.macro.BuildCache;
for (c in cases)
runner.add(c);
runner.run();