Execute call-script: nested frame, shared globals, return to caller

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-07-07 13:13:57 -04:00
parent 3f9117363c
commit 4c27707d57
3 changed files with 121 additions and 2 deletions

View File

@@ -168,7 +168,19 @@ public sealed class VirtualMachine
}
case "exit":
case "exit-script": return FRAME_RETURN;
case "call-script": _host.CallScript(a.Count > 0 ? Read(a[0]) : 0); return pc + 1; // stub (executes in Task 3)
case "call-script":
{
long id = a.Count > 0 ? Read(a[0]) : 0;
_host.CallScript(id); // notify (diagnostics)
if (_provider == null) return pc + 1; // no script source: prior stub behavior
if (_depth >= _o.CallDepthCap) { HaltReason ??= "call-depth-exceeded"; return HALT; }
var child = _provider.GetById(id);
if (child == null) { HaltReason ??= $"callscript-unresolved:0x{id:x}"; return HALT; }
var entry = child.IndexByOffset.TryGetValue(0, out var ci) ? ci : 0;
var outcome = RunFrame(new ExecFrame(child, entry));
if (outcome == FrameOutcome.Halted) return HALT; // propagate whole-VM halt up
return pc + 1; // Returned / RanOff: resume caller
}
case "show-text":
foreach (var o in a)
{

View File

@@ -1,2 +1,2 @@
namespace Age.Engine.Vm;
public sealed record VmOptions(int EmitCap = 2, long MaxSteps = 2_000_000);
public sealed record VmOptions(int EmitCap = 2, long MaxSteps = 2_000_000, int CallDepthCap = 64);