static void HandlePrim0(Vm vm) { var instruction = vm.CurrentInstruction (); if (vm.GetCurrentCache () == null) { var primName = (string)instruction.Arguments; if (!Vm.Prim0Hash.ContainsKey (primName)) { vm.RaiseShovelError (String.Format ( "Cannot take address of primitive '{0}' (implemented as instruction).", primName) ); } vm.SetCurrentCache (Value.Make (Vm.Prim0Hash [primName])); } vm.stack.Push ((Value)vm.GetCurrentCache ()); vm.IncrementTicks (1); vm.programCounter++; }
static void HandleNewFrame(Vm vm) { var instruction = vm.CurrentInstruction (); var args = (string[])instruction.Arguments; var frame = new VmEnvFrame () { VarNames = args, Values = new Value[args.Length], IntroducedAtProgramCounter = vm.programCounter }; var newEnv = new VmEnvironment () { Frame = frame, Next = vm.currentEnvironment }; vm.currentEnvironment = newEnv; vm.IncrementCells (args.Length * 3 + 5); vm.programCounter++; }
static void HandlePrim(Vm vm) { var instruction = vm.CurrentInstruction (); if (vm.GetCurrentCache () == null) { var udpName = (string)instruction.Arguments; vm.SetCurrentCache (Value.Make (GetUdpByName (vm, udpName))); } vm.stack.Push ((Value)vm.GetCurrentCache ()); vm.IncrementTicks (1); vm.programCounter++; }
static void HandleLget(Vm vm) { var instruction = vm.CurrentInstruction (); var args = (int[])instruction.Arguments; vm.stack.Push (FindFrame (vm.currentEnvironment, args [0]).Values [args [1]]); vm.IncrementCells (1); vm.programCounter++; }
static void HandleLset(Vm vm) { var instruction = vm.CurrentInstruction (); var args = (int[])instruction.Arguments; SetInEnvironment (vm.currentEnvironment, args [0], args [1], vm.stack.Top ()); vm.programCounter++; }
static void HandleFn(Vm vm) { var instruction = vm.CurrentInstruction (); var args = (int[])instruction.Arguments; var arity = args[1]; var hasCollectParameters = arity >= Callable.CollectParamsArityModifier; if (hasCollectParameters) { arity -= Callable.CollectParamsArityModifier; } var callable = new Callable () { ProgramCounter = args[0], Arity = arity, HasCollectParams = hasCollectParameters, Environment = vm.currentEnvironment }; vm.stack.Push (Value.Make (callable)); vm.IncrementCells (5); vm.programCounter++; }
static void HandleJump(Vm vm) { vm.programCounter = (int)vm.CurrentInstruction ().Arguments; }
static void HandleConst(Vm vm) { vm.stack.Push ((Value)vm.CurrentInstruction ().Arguments); vm.programCounter++; vm.IncrementCells (1); }
static void HandleFjump(Vm vm) { var args = (int)vm.CurrentInstruction ().Arguments; // vm.CheckBool (); if (!vm.stack.PopTop ().boolValue) { vm.programCounter = args; } else { vm.programCounter ++; } }
static void HandleCallj(Vm vm) { var instruction = vm.CurrentInstruction (); var numArgs = (int)instruction.Arguments; Vm.HandleCallImpl (vm, numArgs, false); }
static void HandleBlock(Vm vm) { var instruction = vm.CurrentInstruction (); var blockEnd = (int)instruction.Arguments; var name = vm.stack.PopTop (); if (name.Kind != Value.Kinds.String) { vm.RaiseShovelError ("The name of a block must be a string."); } vm.stack.Push (Value.Make (new NamedBlock () { Name = name.stringValue, BlockEnd = blockEnd, Environment = vm.currentEnvironment } ) ); vm.IncrementCells (3); vm.programCounter++; }
static void HandleArgs(Vm vm) { var instruction = vm.CurrentInstruction (); var argCount = (int)instruction.Arguments; if (argCount > 0) { Value? returnAddress = null; if (vm.stack.Top ().Kind == Value.Kinds.ReturnAddress) { returnAddress = vm.stack.PopTop (); } var values = vm.currentEnvironment.Frame.Values; Array.Copy ( vm.stack.Storage, vm.stack.Count - argCount, values, 0, argCount); vm.stack.PopMany (argCount); if (returnAddress.HasValue) { vm.stack.Push (returnAddress.Value); } } vm.programCounter++; }
static void HandleNewFrame(Vm vm) { var instruction = vm.CurrentInstruction (); if (instruction.Cache == null) { FreshFrame (vm, instruction); } var newEnv = (VmEnvironment)instruction.Cache; if (newEnv.IsUsed) { newEnv = FreshFrame (vm, instruction); } var values = newEnv.Frame.Values; for (var i = 0; i < values.Length; i++) { values [i].Kind = Value.Kinds.Null; } newEnv.Next = vm.currentEnvironment; vm.currentEnvironment = newEnv; vm.programCounter++; }
static void HandleFn(Vm vm) { var instruction = vm.CurrentInstruction (); var args = (int[])instruction.Arguments; var callable = new Callable () { ProgramCounter = args[0], Arity = args[1], Environment = vm.currentEnvironment }; if (vm.currentEnvironment != null) { vm.currentEnvironment.IncreaseUses (); } vm.stack.Push (Value.Make (callable)); vm.IncrementCells (5); vm.programCounter++; }