#if !macro
macro function asComponent(fun:haxe.macro.Expr, ?options:{}) {
// trace(fun);
// var fExpr:Expr = toExpr(fun);
return switch fun.expr {
case EFunction(kind, f): {
var params:Array<haxe.macro.Expr> = getArgIdents(f);
var paramNames:Array<{name:String, options:{}}> = [];
for (p in params) {
trace(p);
final portOptions = {required: true};
var pType = typeof(p);
switch pType {
case Success(data): {
var complx = toComplex(data);
switch complx {
case TOptional(t): {
portOptions.required = false;
}
case _:
}
}
case _:
}
final pName = getName(p);
switch pName {
case Success(n): {
paramNames.push({name: n, options: portOptions});
}
case _:
}
}
var resIsPromise = false;
switch f.ret {
case TPath(p): {
var pName = p.name;
var pPath = p.pack.join(".");
if (pPath + "." + pName == "tink.core.tink.core.Promise") {
// Result is a tink.core.Promise, resolve and handle
resIsPromise = true;
} else {
resIsPromise = false;
}
}
case _: resIsPromise = false;
};
return macro {
var c = new zenflo.lib.Component(options);
for (p in paramNames) {
c.inPorts.add(p.name, p.options);
c.forwardBrackets[p.name] = ['out', 'error'];
}
if (params.length == 0) {
c.inPorts.add('in', {datatype: 'bang'});
}
c.outPorts.add('out');
c.outPorts.add('error');
c.process((input, output, _) -> {
var values:Array<String> = [];
if (paramNames.length != 0) {
for (p in paramNames) {
if (!input.hasData(p.name)) {
return tink.core.Promise.resolve(null);
}
}
values = paramNames.map((p) -> input.getData(p));
} else {
if (!input.hasData('in')) {
return tink.core.Promise.resolve(null);
}
input.getData('in');
values = [];
}
var isPromise = $v{resIsPromise};
if (isPromise){
var res:tink.core.Promise<Dynamic> = $v{call(fun, params)};
res.handle((_c)->{
switch _c {
case Success(v):{
output.sendDone(v);
}
case Failure(err):{
output.done(err);
}
}
});
} else {
var res = $v{call(fun, params)};
output.sendDone(res);
}
return tink.core.Promise.resolve(null);
});
return c;
};
}
case _: macro { throw "unable to generate Component from Function"; };
}
}
#end
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:40: characters 13-22 : Null<tink.core.Pos> should be haxe.macro.Position
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:40: characters 13-22 : ... { methodName : String, lineNumber : Int, fileName : String, ?customParams : Null<Array<Dynamic>>, className : String } has no field file
//haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:40: characters 13-22 : ... For function argument 'pos'
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:38: lines 38-44 : Void should be Dynamic
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:61: characters 30-36 : String should be Null<tink.core.ErrorCode>
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:61: characters 30-36 : ... For optional function argument 'code'
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:61: characters 30-36 : ... For function argument 'failure'
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Sisyphus.hx:218: characters 37-45 : haxe.macro.Type has no field toString
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Sisyphus.hx:218: characters 52-60 : haxe.macro.Type has no field toString
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:29: characters 20-26 : Class<tink.macro.Bouncer> has no field bounce
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:51: characters 33-38 : String should be Null<tink.core.ErrorCode>
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Positions.hx:51: characters 33-38 : ... For optional function argument 'code'
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Exprs.hx:53: characters 20-30 : Class<tink.macro.Bouncer> has no field lastEvaled
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Constructor.hx:129: characters 63-71 : haxe.macro.Type has no field getClass
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Constructor.hx:129: characters 34-86 : You can't iterate on a Dynamic value, please specify Iterator or Iterable
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Constructor.hx:150: characters 28-37 : haxe.macro.VarAccess should be Null<haxe.macro.Expr>
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Constructor.hx:150: characters 28-37 : ... For function argument 'e'
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:166: characters 44-63 : Class<haxe.macro.TypeTools> has no field applyTypeParameters
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:337: characters 36-76 : String should be Null<tink.core.ErrorCode>
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:337: characters 36-76 : ... For optional function argument 'code'
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:337: characters 36-76 : ... For function argument 'failure'
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:240: characters 32-40 : haxe.macro.Type has no field toString
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:240: characters 64-72 : haxe.macro.Type has no field toString
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:240: characters 32-40 : haxe.macro.Type has no field toString
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:240: characters 64-72 : haxe.macro.Type has no field toString
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:240: characters 30-74 : String should be Null<tink.core.ErrorCode>
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:240: characters 30-74 : ... For optional function argument 'code'
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:240: characters 30-74 : ... For function argument 'failure'
/haxe/haxe_libraries/tink_macro/0.24.0/haxelib/src/tink/macro/Types.hx:240: characters 12-92 : Void should be tink.core.Outcome<haxe.macro.Type, tink.core.Error>
src/zenflo/spec/lib/AsComponent.hx:29: characters 49-70 : Method asComponent not found on class zenflo.lib._Macros.Macros_Fields_
I get errors but I don't know where to look
The macro