Skip to content

Commit

Permalink
feat(DaedalusVm): allow calling functions by symbol index
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Dec 28, 2023
1 parent 1f342f2 commit 7e5663a
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions ZenKit/DaedalusVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ public void Call(string name)
if (!(sym is { Type: DaedalusDataType.Function })) throw new Exception("Symbol not found");
Native.ZkDaedalusVm_callFunction(Handle, sym.Handle);
}

public void Call(int symId)
{
var sym = GetSymbolByIndex((uint)symId);
if (!(sym is { Type: DaedalusDataType.Function })) throw new Exception("Symbol not found");
Native.ZkDaedalusVm_callFunction(Handle, sym.Handle);
}

public TR Call<TR>(string name)
{
Expand All @@ -225,6 +232,16 @@ public TR Call<TR>(string name)
if (!sym.HasReturn) throw new InvalidOperationException("The function does not return anything!");
return Pop<TR>();
}

public TR Call<TR>(int symId)
{
var sym = GetSymbolByIndex((uint)symId);
if (!(sym is { Type: DaedalusDataType.Function })) throw new Exception("Symbol not found");
Native.ZkDaedalusVm_callFunction(Handle, sym.Handle);

if (!sym.HasReturn) throw new InvalidOperationException("The function does not return anything!");
return Pop<TR>();
}

public TR Call<TR, TP0>(string name, TP0 p0)
{
Expand Down Expand Up @@ -256,34 +273,64 @@ public TR Call<TR, TP0, TP1, TP2, TP3>(string name, TP0 p0, TP1 p1, TP2 p2, TP3
return Call<TR>(name);
}

public void Call<TP0>(string name, TP0 p0)
public TR Call<TR, TP0>(int symId, TP0 p0)
{
Push(p0);
return Call<TR>(symId);
}

public TR Call<TR, TP0, TP1>(int symId, TP0 p0, TP1 p1)
{
Push(p0);
Push(p1);
return Call<TR>(symId);
}

public TR Call<TR, TP0, TP1, TP2>(int symId, TP0 p0, TP1 p1, TP2 p2)
{
Push(p0);
Push(p1);
Push(p2);
return Call<TR>(symId);
}

public TR Call<TR, TP0, TP1, TP2, TP3>(int symId, TP0 p0, TP1 p1, TP2 p2, TP3 p3)
{
Push(p0);
Push(p1);
Push(p2);
Push(p3);
return Call<TR>(symId);
}

public void Call<TP0>(int symId, TP0 p0)
{
Push(p0);
Call(name);
Call(symId);
}

public void Call<TP0, TP1>(string name, TP0 p0, TP1 p1)
public void Call<TP0, TP1>(int symId, TP0 p0, TP1 p1)
{
Push(p0);
Push(p1);
Call(name);
Call(symId);
}

public void Call<TP0, TP1, TP2>(string name, TP0 p0, TP1 p1, TP2 p2)
public void Call<TP0, TP1, TP2>(int symId, TP0 p0, TP1 p1, TP2 p2)
{
Push(p0);
Push(p1);
Push(p2);
Call(name);
Call(symId);
}

public void Call<TP0, TP1, TP2, TP3>(string name, TP0 p0, TP1 p1, TP2 p2, TP3 p3)
public void Call<TP0, TP1, TP2, TP3>(int symId, TP0 p0, TP1 p1, TP2 p2, TP3 p3)
{
Push(p0);
Push(p1);
Push(p2);
Push(p3);
Call(name);
Call(symId);
}

public void RegisterExternalDefault(ExternalDefaultFunction cb)
Expand Down

0 comments on commit 7e5663a

Please sign in to comment.