Exemplo n.º 1
0
 public GML2VM()
 {
     VMB        = new VMBuffer();
     TypeStack  = new Stack <eVM_Type>();
     LoopEnv    = new Stack <VMLabel>();
     LoopEndEnv = new Stack <VMLabel>();
 }
Exemplo n.º 2
0
 public VMLabel(string _label, VMBuffer _vmb)
 {
     Label      = _label;
     Address    = 0L;
     Patches    = new List <int>();
     Marked     = false;
     BreakCount = 0;
     VMB        = _vmb;
 }
Exemplo n.º 3
0
        private void EmitI(eVM_Instruction _inst, string _val)
        {
            VMB.Add(VMBuffer.EncodeInstructionArg((int)_inst, 6));
            int count = Strings.Count;

            Strings.Add(_val);
            StringPatches.Add(VMB.Buffer.Position);
            VMB.Buffer.WriteInteger(count);
        }
Exemplo n.º 4
0
 public void Patch()
 {
     foreach (int patch in Patches)
     {
         long address = Address;
         int  @int    = VMB.GetInt(patch);
         int  value   = VMBuffer.EncodeInstructionBranch(VMBuffer.GetInstruction(@int), patch);
         VMB.SetInt(patch, value);
     }
     Patches.Clear();
 }
Exemplo n.º 5
0
 private void Emit(eVM_Instruction _inst, VMLabel _label)
 {
     if (!_label.Marked)
     {
         _label.Patches.Add((int)VMB.Buffer.Position);
         VMB.Add(VMBuffer.EncodeInstructionBranch((int)_inst, 0));
     }
     else
     {
         long num = _label.Address - VMB.Buffer.Position;
         VMB.Add(VMBuffer.EncodeInstructionBranch((int)_inst, (int)num));
     }
 }
Exemplo n.º 6
0
        private void CompileConstant(GMLToken _tok)
        {
            switch (_tok.Value.Kind)
            {
            case eKind.eConstant:
                Error("constant token", _tok);
                break;

            case eKind.eNone:
                Error("None constant token", _tok);
                break;

            case eKind.eNumber:
            {
                double num = (long)_tok.Value.ValueI;
                if (num == _tok.Value.ValueI)
                {
                    long num2 = (long)_tok.Value.ValueI;
                    if (num2 > int.MaxValue || num2 < int.MinValue)
                    {
                        EmitI(eVM_Instruction.eVMI_PUSH, num2);
                        TypeStack.Push(eVM_Type.eVMT_Long);
                    }
                    else if (num2 > 32767 || num2 < -32768)
                    {
                        EmitI(eVM_Instruction.eVMI_PUSH, (int)num2);
                        TypeStack.Push(eVM_Type.eVMT_Int);
                    }
                    else
                    {
                        VMB.Add(VMBuffer.EncodeInstructionArg(192, 15) | (int)(num2 & 0xFFFF));
                        TypeStack.Push(eVM_Type.eVMT_Int);
                    }
                }
                else
                {
                    EmitI(eVM_Instruction.eVMI_PUSH, _tok.Value.ValueI);
                    TypeStack.Push(eVM_Type.eVMT_Double);
                }
                break;
            }

            case eKind.eString:
                EmitI(eVM_Instruction.eVMI_PUSH, _tok.Value.ValueS);
                TypeStack.Push(eVM_Type.eVMT_String);
                break;
            }
        }
Exemplo n.º 7
0
 private void EmitIVar(eVM_Instruction _inst, int _var, eVM_Type _target)
 {
     VMB.Add(VMBuffer.EncodeInstructionArg((int)_inst, VMBuffer.EncodeArgDouble(5, (int)_target)));
     VMB.Buffer.WriteInteger(_var);
 }
Exemplo n.º 8
0
 private void EmitIVar(eVM_Instruction _inst, int _var)
 {
     VMB.Add(VMBuffer.EncodeInstructionArg((int)_inst, 5));
     VMB.Buffer.WriteInteger(_var);
 }
Exemplo n.º 9
0
 private void EmitI(eVM_Instruction _inst, bool _val)
 {
     VMB.Add(VMBuffer.EncodeInstructionArg((int)_inst, 4));
     VMB.Buffer.WriteBoolean(_val);
 }
Exemplo n.º 10
0
 private void EmitI(eVM_Instruction _inst, long _val)
 {
     VMB.Add(VMBuffer.EncodeInstructionArg((int)_inst, 3));
     VMB.Buffer.WriteLong(_val);
 }
Exemplo n.º 11
0
 private void EmitI(eVM_Instruction _inst, float _val)
 {
     VMB.Add(VMBuffer.EncodeInstructionArg((int)_inst, 1));
     VMB.Buffer.WriteSingle(_val);
 }
Exemplo n.º 12
0
 private void EmitI(eVM_Instruction _inst, double _val)
 {
     VMB.Add(VMBuffer.EncodeInstructionArg((int)_inst, 0));
     VMB.Buffer.WriteDouble(_val);
 }
Exemplo n.º 13
0
 private void Emit(eVM_Instruction _inst, eVM_Type _type1, eVM_Type _type2)
 {
     VMB.Add(VMBuffer.EncodeInstructionArg((int)_inst, VMBuffer.EncodeArgDouble((int)_type1, (int)_type2)));
 }
Exemplo n.º 14
0
 private void Emit(eVM_Instruction _inst, eVM_Type _type1)
 {
     VMB.Add(VMBuffer.EncodeInstructionArg((int)_inst, (int)_type1));
 }
Exemplo n.º 15
0
 private void EmitBreak(ushort _v)
 {
     VMB.Add(VMBuffer.EncodeInstructionArg(255, 15) | _v);
 }
Exemplo n.º 16
0
        public int DisasmOne(VMBuffer _vmb, int _offs, TextWriter _sw)
        {
            int num  = _offs;
            int @int = _vmb.GetInt(_offs);

            _offs += 4;
            int instruction = VMBuffer.GetInstruction(@int);
            int arg         = VMBuffer.GetArg(@int);
            int num2        = _offs;

            if ((instruction & 0x40) != 0)
            {
                _offs += ParamSize(arg);
            }
            int i = 11;

            _sw.Write("{0:x8} : ", num);
            int num3 = num;

            while (num3 < _offs)
            {
                _sw.Write("{0:x2}", _vmb.Buffer.GetBuffer()[num3]);
                num3++;
                i += 2;
            }
            for (; i < 36; i++)
            {
                _sw.Write(" ");
            }
            string text = Instruction2String(instruction);

            _sw.Write(text);
            i += text.Length;
            if ((instruction & 0xA0) == 128)
            {
                _sw.Write(Arg2String(arg));
                i += 2;
            }
            else if ((instruction & 0xA0) == 0)
            {
                _sw.Write(Arg2String(arg & 0xF));
                _sw.Write(Arg2String(arg >> 4));
                i += 4;
            }
            for (; i < 46; i++)
            {
                _sw.Write(" ");
            }
            if ((instruction & 0x40) != 0)
            {
                long position = _vmb.Buffer.Position;
                _vmb.Buffer.Position = num2;
                switch (arg & 0xF)
                {
                case 3:
                    _sw.Write("{0}", _vmb.Buffer.ReadLong());
                    break;

                case 0:
                    _sw.Write("{0}", _vmb.Buffer.ReadDouble());
                    break;

                case 2:
                    _sw.Write("{0}", _vmb.Buffer.ReadInteger());
                    break;

                case 5:
                    _sw.Write("{0}", _vmb.Buffer.ReadInteger() & 0x1FFFFFFF);
                    break;

                case 6:
                    _sw.Write("{0}", Strings[_vmb.Buffer.ReadInteger()]);
                    break;

                case 1:
                    _sw.Write("{0}", _vmb.Buffer.ReadSingle());
                    break;

                case 4:
                    _sw.Write("{0}", _vmb.Buffer.ReadInteger() != 0);
                    break;

                case 15:
                    _sw.Write("{0}", @int << 16 >> 16);
                    break;
                }
                _vmb.Buffer.Position = position;
            }
            else if ((instruction & 0x20) != 0)
            {
                int num4 = num + VMBuffer.GetBranch(@int);
                _sw.WriteLine("0x{0:x8}", num4);
            }
            _sw.WriteLine("");
            return(_offs);
        }