private void _defArray() { byte length = Pop(); byte id = Pop(); byte typeId = Pop(); if (typeId == 0) { throw new Exception("Cannot have null (type_0) array type."); } byte numFields = _types[typeId]; BytecodeArray array = new BytecodeArray() { Type = typeId, Items = new BytecodeClass[length] }; for (int i = 0; i < length; i++) { array.Items[i] = new BytecodeClass() { Fields = new byte[numFields] }; } _arrays[id] = array; Console.WriteLine($"type_{typeId}[] array_{id} = new type_{typeId}[{length}]"); }
private void _getArray() { byte arrayId = Pop(); BytecodeArray array = _arrays[arrayId]; byte numFields = _types[array.Type]; for (int i = 0; i < array.Items.Length; i++) { BytecodeClass item = array.Items[i]; for (int j = 0; j < numFields; j++) { Push(item.Fields[j]); } } //push length so we can read it back Push((byte)array.Items.Length); Console.WriteLine($"Retrieved array_{arrayId}."); }
private void _setArrayValueAtIndex() { byte itemIndex = Pop(); byte arrayId = Pop(); BytecodeArray array = _arrays[arrayId]; BytecodeClass item = array.Items[itemIndex]; Console.Write($"array_{arrayId}[{itemIndex}] = ["); for (int field = 0; field < item.Fields.Length; field++) { byte value = Pop(); item.Fields[field] = value; if (field == item.Fields.Length - 1) { Console.WriteLine($"{value}]"); } else { Console.Write($"{value}, "); } } }
private void _getArrayValueAtIndex() { byte itemIndex = Pop(); byte arrayId = Pop(); BytecodeArray array = _arrays[arrayId]; BytecodeClass item = array.Items[itemIndex]; Console.Write($"array_{arrayId}[{itemIndex}] has a value of ["); for (int i = 0; i < item.Fields.Length; i++) { byte value = item.Fields[i]; Push(value); if (i == item.Fields.Length - 1) { Console.WriteLine($"{value}]"); } else { Console.Write($"{value}, "); } } }