Exemplo n.º 1
0
        private void Call(InstructionCode instruction, ReadOnlySpan <byte> program)
        {
            GetOpCodeArg(program, out int address);

            if ((uint)address >= (uint)program.Length)
            {
                throw new VmExecutionException($"Invalid method address '0x{address.ToString("X4")}'.");
            }

            _localsState.Save(_locals);
            _locals = new();

            _argsState.Save(_args);
            _args = new();

            for (int idx = 0; idx < program[address]; idx++)
            {
                _args.Add(program[address] - idx - 1, _stackFrame.Pop());
            }

            // TODO (RH vNext): Use method table instead of arg count.

            _stackFrame.AddStack();
            _stackFrame.Push(_pointer);

            _pointer = address + InstructionFacts.SizeOfMethodHeader;
        }