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++; }
internal static bool HashOrStructGetDot(Vm vm, VmApi api, ref Value obj, ref Value index) { if (index.Kind != Value.Kinds.String) { api.RaiseShovelError ("Second argument must be a string."); } if (obj.Kind == Value.Kinds.StructInstance) { var cache = vm.GetCurrentCache (); var structInstance = obj.structInstanceValue; var ztruct = structInstance.Struct; if (cache != null) { var info = (Tuple<Struct, int>)cache; if (info.Item1 == ztruct) { obj = structInstance.Values [info.Item2]; return true; } } int location = FindLocationInStruct (api, ztruct, index.stringValue); obj = structInstance.Values [location]; vm.SetCurrentCache (Tuple.Create (ztruct, location)); } else if (obj.Kind == Value.Kinds.Hash) { if (!obj.hashValue.ContainsKey (index)) { if (obj.hashValue.IndirectGet.Kind == Value.Kinds.Callable) { return false; } else { api.RaiseShovelError("Key not found in hash table."); } } obj = obj.hashValue [index]; } else { api.RaiseShovelError ("First argument must be a struct instance or a hash table."); } return true; }
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++; }
internal static bool HashOrStructDotSet( Vm vm, VmApi api, ref Value obj, ref Value index, ref Value value) { if (obj.Kind == Value.Kinds.StructInstance) { var cache = vm.GetCurrentCache (); var structInstance = obj.structInstanceValue; var ztruct = structInstance.Struct; if (cache != null) { var info = (Tuple<Struct, int>)cache; if (info.Item1 == ztruct) { structInstance.Values [info.Item2] = value; return true; } } int location = FindLocationInStruct (api, ztruct, index.stringValue); structInstance.Values [location] = value; vm.SetCurrentCache (Tuple.Create (ztruct, location)); } else if (obj.Kind == Value.Kinds.Hash) { return HashSet(api, ref obj, ref index, ref value); } else { api.RaiseShovelError ("First argument must be a hash or a struct instance."); } return true; }