Ejemplo n.º 1
0
        public static VMRoutine Assemble(VM vm, BHAV bhav)
        {
            var context = vm.Context;

            var routine = new VMRoutine();

            routine.Locals    = bhav.Locals;
            routine.Arguments = bhav.Args;
            routine.Type      = bhav.Type;
            routine.ID        = bhav.ChunkID;
            routine.Chunk     = bhav;
            routine.VM        = vm;
            routine.Rti       = new VMFunctionRTI {
                Name = bhav.ChunkLabel
            };

            VMInstruction[] instructions = new VMInstruction[bhav.Instructions.Length];
            for (var i = 0; i < bhav.Instructions.Length; i++)
            {
                var bhavInstruction = bhav.Instructions[i];
                var instruction     = new VMInstruction();

                instruction.Index        = (byte)i;
                instruction.Opcode       = bhavInstruction.Opcode;
                instruction.Operand      = null;
                instruction.FalsePointer = bhavInstruction.FalsePointer;
                instruction.TruePointer  = bhavInstruction.TruePointer;
                instruction.Breakpoint   = bhavInstruction.Breakpoint;
                instruction.Function     = routine;

                /** Routine call **/
                if (instruction.Opcode >= 256)
                {
                    var operand = new VMSubRoutineOperand();
                    operand.Read(bhavInstruction.Operand);
                    instruction.Operand = operand;
                }
                else
                {
                    var primitive = context.Primitives[instruction.Opcode];
                    if (primitive != null)
                    {
                        if (primitive.OperandModel != null)
                        {
                            VMPrimitiveOperand operand = (VMPrimitiveOperand)Activator.CreateInstance(primitive.OperandModel);
                            operand.Read(bhavInstruction.Operand);
                            instruction.Operand = operand;
                        }
                    }
                }
                instructions[i] = instruction;
            }
            routine.Instructions = instructions;
            return(routine);
        }
Ejemplo n.º 2
0
        public static VMRoutine Assemble(VM vm, BHAV bhav)
        {
            var context = vm.Context;

            var routine = new VMRoutine();
            routine.Locals = bhav.Locals;
            routine.Arguments = bhav.Args;
            routine.Type = bhav.Type;
            routine.ID = bhav.ChunkID;
            routine.VM = vm;
            routine.Rti = new VMFunctionRTI {
                Name = bhav.ChunkLabel
            };

            VMInstruction[] instructions = new VMInstruction[bhav.Instructions.Length];
            for (var i = 0; i < bhav.Instructions.Length; i++)
            {
                var bhavInstruction = bhav.Instructions[i];
                var instruction = new VMInstruction();

                instruction.Index = (byte)i;
                instruction.Opcode = bhavInstruction.Opcode;
                instruction.Operand = null;
                instruction.FalsePointer = bhavInstruction.FalsePointer;
                instruction.TruePointer = bhavInstruction.TruePointer;
                instruction.Function = routine;

                /** Routine call **/
                if (instruction.Opcode >= 256)
                {
                    var operand = new VMSubRoutineOperand();
                    operand.Read(bhavInstruction.Operand);
                    instruction.Operand = operand;
                }
                else
                {
                    var primitive = context.Primitives[instruction.Opcode];
                    if (primitive != null)
                    {
                        if (primitive.OperandModel != null)
                        {
                            VMPrimitiveOperand operand = (VMPrimitiveOperand)Activator.CreateInstance(primitive.OperandModel);
                            operand.Read(bhavInstruction.Operand);
                            instruction.Operand = operand;
                        }
                    }
                }
                instructions[i] = instruction;

            }
            routine.Instructions = instructions;
            return routine;
        }
Ejemplo n.º 3
0
        protected void PopulateRoutineFields(BHAV bhav, VMRoutine routine)
        {
            routine.Locals    = bhav.Locals;
            routine.Arguments = bhav.Args;
            routine.Type      = bhav.Type;
            routine.ID        = bhav.ChunkID;
            routine.Chunk     = bhav;
            routine.Rti       = new VMFunctionRTI
            {
                Name = bhav.ChunkLabel
            };

            VMInstruction[] instructions = new VMInstruction[bhav.Instructions.Length];
            for (var i = 0; i < bhav.Instructions.Length; i++)
            {
                var bhavInstruction = bhav.Instructions[i];
                var instruction     = new VMInstruction();

                instruction.Index        = (byte)i;
                instruction.Opcode       = bhavInstruction.Opcode;
                instruction.Operand      = null;
                instruction.FalsePointer = bhavInstruction.FalsePointer;
                instruction.TruePointer  = bhavInstruction.TruePointer;
                instruction.Breakpoint   = bhavInstruction.Breakpoint;
                instruction.Function     = routine;

                /** Routine call **/
                if (instruction.Opcode >= 256)
                {
                    var operand = new VMSubRoutineOperand();
                    operand.Read(bhavInstruction.Operand);
                    instruction.Operand = operand;
                }
                else
                {
                    var primitive = VMContext.Primitives[instruction.Opcode];
                    if (primitive != null)
                    {
                        if (primitive.OperandModel != null)
                        {
                            VMPrimitiveOperand operand = (VMPrimitiveOperand)Activator.CreateInstance(primitive.OperandModel);
                            operand.Read(bhavInstruction.Operand);
                            instruction.Operand = operand;
                        }
                    }
                }
                instructions[i] = instruction;
            }
            routine.Instructions = instructions;
        }