ArrayInstance RebuildShovelValueList( object[] objects, int index, Composite composite, Func <int, object> reader, int version) { var result = new ArrayInstance(); objects [index] = result; var length = composite.Elements.Length; if (version > 4) { length -= 2; } for (var i = 0; i < length; i++) { result.Add(RebuildShovelValue(reader(composite.Elements [i]))); } if (version > 4) { // The indirect get/set are stored as the last elements of the array. result.IndirectGet = RebuildShovelValue(reader(composite.Elements[length])); result.IndirectSet = RebuildShovelValue(reader(composite.Elements[length + 1])); } return(result); }
static void CallFunction(Callable callable, Vm vm, int numArgs, bool saveReturnAddress, bool inApply) { if (callable.Arity != null) { // FIXME: Find out why/when the arity can be null. if (callable.HasCollectParams) { if (callable.Arity.Value <= numArgs) { var extraArgs = numArgs - callable.Arity.Value; var values = new ArrayInstance(); for (int i = 0; i < extraArgs; i++) { values.Add(vm.stack.Storage[i + vm.stack.Count - extraArgs]); } vm.stack.PopMany(extraArgs); vm.stack.Push(Value.Make(values)); } else { ArityError(vm, callable.Arity.Value, numArgs, inApply); } } else if (callable.Arity.Value != numArgs) { ArityError(vm, callable.Arity.Value, numArgs, inApply); } } if (saveReturnAddress) { vm.stack.Push (Value.Make (new ReturnAddress () { ProgramCounter = vm.programCounter + 1, Environment = vm.currentEnvironment })); } vm.currentEnvironment = callable.Environment; vm.programCounter = callable.ProgramCounter.Value; }
static Value ArrayConstructor(VmApi api, Value[] args, int start, int length) { var result = new ArrayInstance (); var sizeIncrease = 1 + length; api.CellsIncrementHerald (sizeIncrease); for (var i = start; i < start+length; i++) { result.Add (args [i]); } api.CellsIncrementer (sizeIncrease); return Value.Make (result); }
static Value SizedArrayConstructor(VmApi api, Value size) { if (size.Kind != Value.Kinds.Integer) { api.RaiseShovelError ("Argument must be an integer."); } var result = new ArrayInstance (); var sizeIncrease = 1 + (int)size.integerValue; api.CellsIncrementHerald (sizeIncrease); for (var i = 0; i < size.integerValue; i++) { result.Add (Value.Make ()); } api.CellsIncrementer (sizeIncrease); return Value.Make (result); }
ArrayInstance RebuildShovelValueList( object[] objects, int index, Composite composite, Func<int, object> reader, int version) { var result = new ArrayInstance (); objects [index] = result; var length = composite.Elements.Length; if (version > 4) { length -= 2; } for (var i = 0; i < length; i++) { result.Add (RebuildShovelValue (reader (composite.Elements [i]))); } if (version > 4) { // The indirect get/set are stored as the last elements of the array. result.IndirectGet = RebuildShovelValue(reader(composite.Elements[length])); result.IndirectSet = RebuildShovelValue(reader(composite.Elements[length + 1])); } return result; }