From f275a35fdba5748e0f23ac0267c4f44e09b44e7d Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Thu, 28 Dec 2023 09:28:00 +0100 Subject: [PATCH] feat(DaedalusVm): add up to 10 parameter external variants --- ZenKit/DaedalusVm.cs | 209 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 204 insertions(+), 5 deletions(-) diff --git a/ZenKit/DaedalusVm.cs b/ZenKit/DaedalusVm.cs index ab2085e..3a89dda 100644 --- a/ZenKit/DaedalusVm.cs +++ b/ZenKit/DaedalusVm.cs @@ -21,6 +21,21 @@ public class DaedalusVm : DaedalusScript public delegate TR ExternalFunc(TP0 p0, TP1 p1, TP2 p2, TP3 p3, TP4 p4); + public delegate TR ExternalFunc(TP0 p0, TP1 p1, TP2 p2, + TP3 p3, TP4 p4, TP5 p5); + + public delegate TR ExternalFunc(TP0 p0, TP1 p1, + TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6); + + public delegate TR ExternalFunc(TP0 p0, + TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7); + + public delegate TR ExternalFunc( + TP0 p0, TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7, TP8 p8); + + public delegate TR ExternalFunc(TP0 p0, TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7, TP8 p8, TP9 p9); + public delegate void ExternalFuncV(); public delegate void ExternalFuncV(TP0 p0); @@ -34,6 +49,26 @@ public delegate TR ExternalFunc( public delegate void ExternalFuncV(TP0 p0, TP1 p1, TP2 p2, TP3 p3, TP4 p4); + public delegate void ExternalFuncV(TP0 p0, TP1 p1, TP2 p2, + TP3 p3, TP4 p4, TP5 p5); + + public delegate void ExternalFuncV(TP0 p0, TP1 p1, + TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6); + + public delegate void ExternalFuncV(TP0 p0, + TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7); + + public delegate void ExternalFuncV( + TP0 p0, TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7, TP8 p8); + + public delegate void ExternalFuncV(TP0 p0, TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7, TP8 p8, TP9 p9); + + private readonly List _externalCallbacks = + new List(); + + private Native.Callbacks.ZkDaedalusVmExternalDefaultCallback? _externalDefaultCallback; + public DaedalusVm(string path) : base(Native.ZkDaedalusVm_loadPath(path)) { if (Handle == UIntPtr.Zero) throw new Exception("Failed to load DaedalusVm"); @@ -206,8 +241,6 @@ public void Call(string name, TP0 p0, TP1 p1, TP2 p2, TP3 p3 Call(name); } - private Native.Callbacks.ZkDaedalusVmExternalDefaultCallback? _externalDefaultCallback = null; - public void RegisterExternalDefault(ExternalDefaultFunction cb) { _externalDefaultCallback = (_0, _1, sym) => cb(this, new DaedalusSymbol(sym)); @@ -275,6 +308,90 @@ public void RegisterExternal(string name, }); } + public void RegisterExternal(string name, + ExternalFunc cb) + { + RegisterExternalUnsafe(name, () => + { + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + Push(cb(p0, p1, p2, p3, p4, p5)); + }); + } + + public void RegisterExternal(string name, + ExternalFunc cb) + { + RegisterExternalUnsafe(name, () => + { + var p6 = Pop(); + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + Push(cb(p0, p1, p2, p3, p4, p5, p6)); + }); + } + + public void RegisterExternal(string name, + ExternalFunc cb) + { + RegisterExternalUnsafe(name, () => + { + var p7 = Pop(); + var p6 = Pop(); + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + Push(cb(p0, p1, p2, p3, p4, p5, p6, p7)); + }); + } + + public void RegisterExternal(string name, + ExternalFunc cb) + { + RegisterExternalUnsafe(name, () => + { + var p8 = Pop(); + var p7 = Pop(); + var p6 = Pop(); + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + Push(cb(p0, p1, p2, p3, p4, p5, p6, p7, p8)); + }); + } + + public void RegisterExternal(string name, + ExternalFunc cb) + { + RegisterExternalUnsafe(name, () => + { + var p9 = Pop(); + var p8 = Pop(); + var p7 = Pop(); + var p6 = Pop(); + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + Push(cb(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)); + }); + } public void RegisterExternal(string name, ExternalFuncV cb) { @@ -336,6 +453,91 @@ public void RegisterExternal(string name, ExternalFuncV }); } + public void RegisterExternal(string name, + ExternalFuncV cb) + { + RegisterExternalUnsafe(name, () => + { + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + cb(p0, p1, p2, p3, p4, p5); + }); + } + + public void RegisterExternal(string name, + ExternalFuncV cb) + { + RegisterExternalUnsafe(name, () => + { + var p6 = Pop(); + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + cb(p0, p1, p2, p3, p4, p5, p6); + }); + } + + public void RegisterExternal(string name, + ExternalFuncV cb) + { + RegisterExternalUnsafe(name, () => + { + var p7 = Pop(); + var p6 = Pop(); + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + cb(p0, p1, p2, p3, p4, p5, p6, p7); + }); + } + + public void RegisterExternal(string name, + ExternalFuncV cb) + { + RegisterExternalUnsafe(name, () => + { + var p8 = Pop(); + var p7 = Pop(); + var p6 = Pop(); + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + cb(p0, p1, p2, p3, p4, p5, p6, p7, p8); + }); + } + + public void RegisterExternal(string name, + ExternalFuncV cb) + { + RegisterExternalUnsafe(name, () => + { + var p9 = Pop(); + var p8 = Pop(); + var p7 = Pop(); + var p6 = Pop(); + var p5 = Pop(); + var p4 = Pop(); + var p3 = Pop(); + var p2 = Pop(); + var p1 = Pop(); + var p0 = Pop(); + cb(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); + }); + } + private void Push(T value) { switch (value) @@ -384,9 +586,6 @@ private void RegisterExternalUnsafe(string name, ExternalFunc cb) RegisterExternalUnsafe(sym, cb); } - private List _externalCallbacks = - new List(); - private void RegisterExternalUnsafe(DaedalusSymbol sym, ExternalFunc cb) { Native.Callbacks.ZkDaedalusVmExternalCallback handle = (_0, _1) => cb();