formatting

This commit is contained in:
Djeeberjr 2023-07-30 23:34:43 +02:00
parent 0fc2d4d397
commit 016063e3be
4 changed files with 35 additions and 38 deletions

View File

@ -14,7 +14,7 @@ class HelloWorld implements Process {
var c = new HelloWorldServiceRPC(0); var c = new HelloWorldServiceRPC(0);
c.getNumber(2,3).handle((res) -> { c.getNumber(2, 3).handle((res) -> {
Log.debug("Got number: " + res); Log.debug("Got number: " + res);
}); });

View File

@ -20,7 +20,7 @@ class HelloWorldService implements Process {
} }
@rpc @rpc
public function getNumber(arg1: Int, arg2: Int):Int { public function getNumber(arg1:Int, arg2:Int):Int {
Log.debug(arg1); Log.debug(arg1);
Log.debug(arg2); Log.debug(arg2);
return 42; return 42;

View File

@ -1,7 +1,6 @@
package macros; package macros;
#if macro #if macro
import haxe.macro.TypeTools; import haxe.macro.TypeTools;
import haxe.macro.Expr.Position; import haxe.macro.Expr.Position;
import haxe.macro.Expr.ComplexType; import haxe.macro.Expr.ComplexType;
@ -9,22 +8,22 @@ import haxe.macro.Context;
import haxe.macro.Type; import haxe.macro.Type;
class Helper { class Helper {
public static function resolveType(t: ComplexType,pos: Position): Null<ComplexType> { public static function resolveType(t:ComplexType, pos:Position):Null<ComplexType> {
if (t == null) return null; if (t == null)
return TypeTools.toComplexType(Context.resolveType(t,pos)); return null;
return TypeTools.toComplexType(Context.resolveType(t, pos));
} }
public static function newPromise(t: ComplexType): ComplexType { public static function newPromise(t:ComplexType):ComplexType {
if (Helper.isVoidC(t)){ if (Helper.isVoidC(t)) {
return TPath({name: "Promise", params: [TPType(TPath({name:"Noise",pack: ["tink", "core"]}))], pack: ["tink", "core"]}); return TPath({name: "Promise", params: [TPType(TPath({name: "Noise", pack: ["tink", "core"]}))], pack: ["tink", "core"]});
} }
return TPath({name: "Promise", params: [TPType(t)], pack: ["tink", "core"]}); return TPath({name: "Promise", params: [TPType(t)], pack: ["tink", "core"]});
} }
public static function isVoidC(t:ComplexType):Bool {
public static function isVoidC(t: ComplexType): Bool { switch (t) {
switch (t){
case TPath(p): case TPath(p):
return (p.name == "Void"); return (p.name == "Void");
default: default:
@ -32,15 +31,13 @@ class Helper {
} }
} }
public static function isVoid(t: Type) { public static function isVoid(t:Type) {
switch (t){ switch (t) {
case TAbstract(t, _): case TAbstract(t, _):
return (t.get().name == "Void"); return (t.get().name == "Void");
default: default:
return false; return false;
} }
} }
} }
#end #end

View File

@ -31,7 +31,7 @@ class RPC {
var convertedArgs = []; var convertedArgs = [];
for (a in f.args) { for (a in f.args) {
a.type = Helper.resolveType(a.type,field.pos); a.type = Helper.resolveType(a.type, field.pos);
convertedArgs.push(a); convertedArgs.push(a);
} }
@ -43,7 +43,7 @@ class RPC {
expr: macro { expr: macro {
return cast this._performRequest($v{field.name}, $a{argsExprs}); return cast this._performRequest($v{field.name}, $a{argsExprs});
}, },
ret: Helper.newPromise(Helper.resolveType(f.ret,field.pos)), ret: Helper.newPromise(Helper.resolveType(f.ret, field.pos)),
}), }),
access: [APublic], access: [APublic],
doc: null, doc: null,
@ -76,18 +76,18 @@ class RPC {
var exprsType = field.expr().t; var exprsType = field.expr().t;
switch (exprsType){ switch (exprsType) {
case TFun(args, ret): case TFun(args, ret):
var callArgs = [for (k => v in args) macro pack.data.args[$v{k}]]; var callArgs = [for (k => v in args) macro pack.data.args[$v{k}]];
if (Helper.isVoid(ret)){ if (Helper.isVoid(ret)) {
exprs.push(macro { exprs.push(macro {
if (pack.data.func == $v{funName}) { if (pack.data.func == $v{funName}) {
this.$funName($a{callArgs}); this.$funName($a{callArgs});
pack.respond(null); pack.respond(null);
} }
}); });
}else{ } else {
exprs.push(macro { exprs.push(macro {
if (pack.data.func == $v{funName}) { if (pack.data.func == $v{funName}) {
pack.respond(this.$funName($a{callArgs})); pack.respond(this.$funName($a{callArgs}));