internal static Vm RunVm(
Instruction[] bytecode,
List<SourceFile> sources = null,
IEnumerable<Callable> userPrimitives = null,
byte[] state = null,
Vm vm = null,
int? cellsQuota = null,
long? totalTicksQuota = null,
long? untilNextNapTicksQuota = null)
{
if (vm == null) {
vm = new Vm ();
vm.bytecode = bytecode;
vm.cache = new object[bytecode.Length];
vm.programCounter = 0;
vm.currentEnvironment = null;
vm.stack = new Stack ();
vm.sources = sources;
vm.userPrimitives = new Dictionary<string, Callable> ();
}
vm.cellsQuota = cellsQuota;
vm.totalTicksQuota = totalTicksQuota;
vm.untilNextNapTicksQuota = untilNextNapTicksQuota;
if (state != null) {
// Utils.TimeIt ("Deserialize VM state", () => {
vm.DeserializeState (state);
// }
// );
}
if (userPrimitives != null) {
foreach (var udp in userPrimitives) {
vm.userPrimitives [udp.UdpName] = udp;
}
}
vm.executedTicksSinceLastNap = 0;
vm.api = new VmApi (
raiseShovelError: vm.RaiseShovelError,
ticksIncrementer: vm.IncrementTicks,
cellsIncrementer: vm.IncrementCells,
cellsIncrementHerald: vm.IncrementCellsHerald);
do {
} while (vm.StepVm());
return vm;
}