Esempio n. 1
0
        public R Call(VirtualMachine vm, A arguments)
        {
            System.Diagnostics.Debug.Assert(Marshal.SizeOf <R> .size > 0);

            vm.memory.PushBackStack(new ValueData(functionIndex));
            vm.callFrameStack.PushBackUnchecked(new CallFrame(
                                                    vm.chunk.bytes.count - 1,
                                                    vm.memory.stackCount,
                                                    0,
                                                    CallFrame.Type.EntryPoint
                                                    ));
            vm.callFrameStack.PushBackUnchecked(new CallFrame(
                                                    codeIndex,
                                                    vm.memory.stackCount,
                                                    functionIndex,
                                                    CallFrame.Type.Function
                                                    ));

            var writer = new MemoryWriteMarshaler(vm, vm.memory.stackCount);

            vm.memory.GrowStack(parametersSize);
            arguments.Marshal(ref writer);

            VirtualMachineInstructions.RunTopFunction(vm);
            if (vm.error.isSome)
            {
                return(default);
Esempio n. 2
0
        public static void Return <T>(VirtualMachine vm, T value) where T : struct, IMarshalable
        {
            System.Diagnostics.Debug.Assert(Marshal.SizeOf <T> .size > 0);

            var marshaler = new MemoryWriteMarshaler(vm, vm.memory.stackCount);

            vm.memory.GrowStack(Marshal.SizeOf <T> .size);
            value.Marshal(ref marshaler);
        }
Esempio n. 3
0
        public T this[int index]
        {
            get
            {
                var size      = global::cflat.Marshal.SizeOf <T> .size;
                var marshaler = new MemoryReadMarshaler(vm, headAddress + size * index);
                var value     = default(T);
                value.Marshal(ref marshaler);
                return(value);
            }

            set
            {
                var size      = global::cflat.Marshal.SizeOf <T> .size;
                var marshaler = new MemoryWriteMarshaler(vm, headAddress + size * index);
                value.Marshal(ref marshaler);
            }
        }