예제 #1
0
        void Gen(Instruction.Opcodes opcode,
                 object arguments = null,
                 ParseTree pos    = null,
                 string comments  = null,
                 int?startPos     = null,
                 int?endPos       = null)
        {
            var instruction = new Instruction()
            {
                Opcode    = opcode,
                Arguments = arguments,
                Comments  = comments
            };

            if (startPos != null)
            {
                instruction.StartPos = startPos;
            }
            else if (pos != null && pos.StartPos != -1)
            {
                instruction.StartPos = pos.StartPos;
            }
            if (endPos != null)
            {
                instruction.EndPos = endPos;
            }
            else if (pos != null && pos.EndPos != -1)
            {
                instruction.EndPos = pos.EndPos;
            }
            this.bytecode.Add(instruction);
        }
        private void SetInstructions()
        {
            int tBIdx = 0;

            Instruction.Opcodes opC = Instruction.Opcodes.ADDD;
            parent.instructionUnit.ClearInstructions();
            foreach (ComboBox cbx in cBoxes)
            {
                switch (cbx.SelectedIndex)
                {
                case 0:
                    opC = Instruction.Opcodes.ADDD;
                    break;

                case 1:
                    opC = Instruction.Opcodes.SUBD;
                    break;

                case 2:
                    opC = Instruction.Opcodes.MULD;
                    break;

                case 3:
                    opC = Instruction.Opcodes.DIVD;
                    break;

                case 4:
                    opC = Instruction.Opcodes.LD;
                    break;

                case 5:
                    opC = Instruction.Opcodes.SD;
                    break;

                case 6:
                    opC = Instruction.Opcodes.BEQ;
                    break;

                case 7:
                    opC = Instruction.Opcodes.BNE;
                    break;
                }


                parent.instructionUnit.AddInstruction(new Instruction(opC, tBoxes[tBIdx].Text.ToString(), tBoxes[tBIdx + 1].Text.ToString(), tBoxes[tBIdx + 2].Text.ToString()));
                tBIdx += 3;
            }
        }
예제 #3
0
파일: Utils.cs 프로젝트: ichaos/Shovel
        static byte GetNumericOpcode(Instruction.Opcodes opcode)
        {
            switch (opcode)
            {
            case Instruction.Opcodes.Jump:
                return(0);

            case Instruction.Opcodes.Const:
                return(1);

            case Instruction.Opcodes.Prim0:
                return(2);

            case Instruction.Opcodes.Prim:
                return(3);

            case Instruction.Opcodes.Call:
                return(4);

            case Instruction.Opcodes.CallJ:
                return(5);

            case Instruction.Opcodes.Fjump:
                return(6);

            case Instruction.Opcodes.Lset:
                return(7);

            case Instruction.Opcodes.Pop:
                return(8);

            case Instruction.Opcodes.Lget:
                return(9);

            case Instruction.Opcodes.Fn:
                return(10);

            case Instruction.Opcodes.NewFrame:
                return(11);

            case Instruction.Opcodes.DropFrame:
                return(12);

            case Instruction.Opcodes.Args:
                return(13);

            case Instruction.Opcodes.Return:
                return(14);

            case Instruction.Opcodes.Block:
                return(15);

            case Instruction.Opcodes.PopBlock:
                return(16);

            case Instruction.Opcodes.BlockReturn:
                return(17);

            case Instruction.Opcodes.Context:
                return(18);

            case Instruction.Opcodes.Tjump:
                return(19);

            case Instruction.Opcodes.FileName:
                return(20);

            case Instruction.Opcodes.VmVersion:
                return(20);

            case Instruction.Opcodes.VmSourcesMd5:
                return(20);

            case Instruction.Opcodes.VmBytecodeMd5:
                return(20);

            case Instruction.Opcodes.Div:
                return(21);

            case Instruction.Opcodes.Mod:
                return(22);

            case Instruction.Opcodes.Neq:
                return(23);

            case Instruction.Opcodes.Lt:
                return(24);

            case Instruction.Opcodes.Add:
                return(25);

            case Instruction.Opcodes.Gref:
                return(26);

            case Instruction.Opcodes.Eq:
                return(27);

            case Instruction.Opcodes.Apush:
                return(28);

            case Instruction.Opcodes.GrefDot:
                return(29);

            case Instruction.Opcodes.Sub:
                return(30);

            case Instruction.Opcodes.Neg:
                return(31);

            case Instruction.Opcodes.Mul:
                return(32);

            case Instruction.Opcodes.Shl:
                return(33);

            case Instruction.Opcodes.Shr:
                return(34);

            case Instruction.Opcodes.Pow:
                return(35);

            case Instruction.Opcodes.Floor:
                return(36);

            case Instruction.Opcodes.Lte:
                return(37);

            case Instruction.Opcodes.Gt:
                return(38);

            case Instruction.Opcodes.Gte:
                return(39);

            case Instruction.Opcodes.Not:
                return(40);

            case Instruction.Opcodes.And:
                return(41);

            case Instruction.Opcodes.Ior:
                return(42);

            case Instruction.Opcodes.Xor:
                return(43);

            case Instruction.Opcodes.Keys:
                return(44);

            case Instruction.Opcodes.HasKey:
                return(45);

            case Instruction.Opcodes.Apop:
                return(46);

            case Instruction.Opcodes.SetIndexed:
                return(47);

            case Instruction.Opcodes.Len:
                return(48);

            case Instruction.Opcodes.IsString:
                return(49);

            case Instruction.Opcodes.IsHash:
                return(50);

            case Instruction.Opcodes.IsBool:
                return(51);

            case Instruction.Opcodes.IsArray:
                return(52);

            case Instruction.Opcodes.IsNumber:
                return(53);

            case Instruction.Opcodes.IsInteger:
                return(54);

            case Instruction.Opcodes.IsCallable:
                return(55);

            default:
                Utils.Panic();
                return(0);
            }
        }