Esempio n. 1
0
        private void _defVar()
        {
            byte id     = Pop();
            byte typeId = Pop();

            if (typeId == 0)
            {
                throw new Exception("Cannot have a null (type_0) variable type.");
            }

            byte numFields = _types[typeId];

            vars[id] = new BytecodeClass()
            {
                Type   = typeId,
                Fields = new byte[numFields]
            };

            Console.WriteLine($"type_{typeId} var_{id} = new type_{typeId}()");
        }
Esempio n. 2
0
        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}.");
        }
Esempio n. 3
0
        private void _setVar()
        {
            byte id = Pop();

            BytecodeClass variable  = vars[id];
            byte          numFields = _types[variable.Type];

            Console.Write($"var_{id} = [");
            for (int i = 0; i < numFields; i++)
            {
                byte value = Pop();
                variable.Fields[i] = value;

                if (i == numFields - 1)
                {
                    Console.WriteLine($"{value}]");
                }
                else
                {
                    Console.Write($"{value}, ");
                }
            }
        }
Esempio n. 4
0
        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}, ");
                }
            }
        }
Esempio n. 5
0
        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}, ");
                }
            }
        }