Exemplo n.º 1
0
        private void PushCall(VMModule module, int functionIndex, byte[] argumentData)
        {
            // TODO: Need either better documentation about how bound functions must not re-retrieve arguments from
            // the original argumentSource after a Call Continuation, or we need to use unique argument buffers for each
            // bound function call (with pooling of course). I'd opt for the former, it's super easy to just grab your
            // arguments as soon as you enter the bound function, and is the cleanest as well.

            GetFunctionStackSizes(module, functionIndex,
                                  out int _,
                                  out int argumentMemorySize,
                                  out int stackSize);

            if (argumentData.Length != argumentMemorySize)
            {
                throw new ArgumentOutOfRangeException(nameof(argumentData), "Function argument size differs.");
            }

            // Function input + space for function index
            _argumentBuffer.Recreate(stackSize + sizeof(int));

            for (int i = 0, ilen = argumentData.Length; i < ilen; ++i)
            {
                _argumentBuffer.PushVal(argumentData[i]);
            }
            _argumentBuffer.PushValInt(functionIndex);
            PushCall(module, _argumentBuffer);
        }
Exemplo n.º 2
0
        private void InterpretLogicalNot()
        {
            StackFrameMemory stack = PeekCallStack().Memory;
            int val = stack.PopValInt();

            stack.PushValInt(val == 0 ? 1 : 0);
        }
Exemplo n.º 3
0
        private void InterpretBool()
        {
            StackFrameMemory stack = PeekCallStack().Memory;
            int val = stack.PopValInt();

            stack.PushValInt(val == 0 ? 0 : 1);
        }
Exemplo n.º 4
0
        private void InterpretMod()
        {
            StackFrameMemory stack = PeekCallStack().Memory;
            int a = stack.PopValInt();
            int b = stack.PopValInt();

            stack.PushValInt(a % b);
        }