Example #1
0
        public override BSizeT parse(ByteBuffer buffer, BHeader header)
        {
            BSizeT @value = new BSizeT(integerType.raw_parse(buffer, header));

            if (header.debug)
            {
                Console.WriteLine("-- parsed <size_t> " + @value.asInt());
            }
            return(@value);
        }
Example #2
0
        public override BInteger parse(ByteBuffer buffer, BHeader header)
        {
            BInteger @value = raw_parse(buffer, header);

            if (header.debug)
            {
                Console.WriteLine("-- parsed <integer> " + @value.asInt());
            }
            return(@value);
        }
Example #3
0
 protected internal override void parse_main(ByteBuffer buffer, BHeader header, LFunctionParseState s)
 {
     s.lineBegin        = header.integer.parse(buffer, header).asInt();
     s.lineEnd          = header.integer.parse(buffer, header).asInt();
     s.lenParameter     = 0xFF & buffer.GetByte();
     s.vararg           = 0xFF & buffer.GetByte();
     s.maximumStackSize = 0xFF & buffer.GetByte();
     parse_code(buffer, header, s);
     parse_constants(buffer, header, s);
     parse_upvalues(buffer, header, s);
     parse_debug(buffer, header, s);
 }
Example #4
0
 protected internal virtual void parse_constants(ByteBuffer buffer, BHeader header, LFunctionParseState s)
 {
     if (header.debug)
     {
         Console.WriteLine("-- beginning to parse constants list");
     }
     s.constants = header.constant.parseList(buffer, header);
     if (header.debug)
     {
         Console.WriteLine("-- beginning to parse functions list");
     }
     s.functions = header.function.parseList(buffer, header);
 }
Example #5
0
        public override LLocal parse(ByteBuffer buffer, BHeader header)
        {
            LString  name  = [email protected](buffer, header);
            BInteger Start = header.integer.parse(buffer, header);
            BInteger end   = header.integer.parse(buffer, header);

            if (header.debug)
            {
                Console.Write("-- parsing local, name: ");
                Console.Write(name);
                Console.Write(" from " + Start.asInt() + " to " + end.asInt());
                Console.WriteLine();
            }
            return(new LLocal(name, Start, end));
        }
Example #6
0
        public override LString parse(ByteBuffer buffer, BHeader header)
        {
            BSizeT sizeT = header.sizeT.parse(buffer, header);

            System.Text.StringBuilder b = this.b.Value;
            b.Length = 0;
            sizeT.iterate(() => b.Append((char)(0xFF & buffer.GetByte())));
            string s = b.ToString();

            if (header.debug)
            {
                Console.WriteLine("-- parsed <string> \"" + s + "\"");
            }
            return(new LString(sizeT, s));
        }
Example #7
0
        public override LFunction parse(ByteBuffer buffer, BHeader header)
        {
            if (header.debug)
            {
                Console.WriteLine("-- beginning to parse function");
            }
            if (header.debug)
            {
                Console.WriteLine("-- parsing name...start...end...upvalues...params...varargs...stack");
            }
            LFunctionParseState s = new LFunctionParseState();

            parse_main(buffer, header, s);
            return(new LFunction(header, s.code, s.locals.asArray(new LLocal[s.locals.length.asInt()]), s.constants.asArray(new LObject[s.constants.length.asInt()]), s.upvalues, s.functions.asArray(new LFunction[s.functions.length.asInt()]), s.maximumStackSize, s.lenUpvalues, s.lenParameter, s.vararg));
        }
Example #8
0
        public override LObject parse(ByteBuffer buffer, BHeader header)
        {
            int type = 0xFF & buffer.GetByte();

            if (header.debug)
            {
                Console.Write("-- parsing <constant>, type is ");
                switch (type)
                {
                case 0:
                    Console.WriteLine("<nil>");
                    break;

                case 1:
                    Console.WriteLine("<boolean>");
                    break;

                case 3:
                    Console.WriteLine("<number>");
                    break;

                case 4:
                    Console.WriteLine("<strin>");
                    break;

                default:
                    Console.WriteLine("illegal " + type);
                    break;
                }
            }
            switch (type)
            {
            case 0:
                return(LNil.NIL);

            case 1:
                return([email protected](buffer, header));

            case 3:
                return(header.number.parse(buffer, header));

            case 4:
                return([email protected](buffer, header));

            default:
                throw new Exception();
            }
        }
Example #9
0
        public override LBoolean parse(ByteBuffer buffer, BHeader header)
        {
            int @value = buffer.GetByte();

            if ((@value & 0xFFFFFFFE) != 0)
            {
                throw new Exception();
            }
            else
            {
                LBoolean @bool = @value == 0 ? LBoolean.LFALSE : LBoolean.LTRUE;
                if (header.debug)
                {
                    Console.WriteLine("-- parsed <boolean> " + @bool);
                }
                return(@bool);
            }
        }
Example #10
0
        protected internal virtual BInteger raw_parse(ByteBuffer buffer, BHeader header)
        {
            BInteger @value;

            switch (intSize)
            {
            case 0:
                @value = new BInteger(0);
                break;

            case 1:
                @value = new BInteger(buffer.GetByte());
                break;

            case 2:
                @value = new BInteger(buffer.GetShort());
                break;

            case 4:
                @value = new BInteger(buffer.GetInt());
                break;

            default:
            {
                byte[] bytes = new byte[intSize];
                int    Start = 0;
                int    delta = 1;
                if (!BitConverter.IsLittleEndian)
                {
                    Start = intSize - 1;
                    delta = -1;
                }
                for (int i = Start; i >= 0 && i < intSize; i += delta)
                {
                    bytes[i] = (byte)Convert.ToSByte(buffer.GetByte());
                }
                @value = new BInteger(new BigInteger(bytes));
            }

            break;
            }
            return(@value);
        }
Example #11
0
        public override LNumber parse(ByteBuffer buffer, BHeader header)
        {
            LNumber @value = null;

            if (integral)
            {
                switch (size)
                {
                case 4:
                    @value = new LIntNumber(buffer.GetInt());
                    break;

                case 8:
                    @value = new LLongNumber(buffer.GetLong());
                    break;
                }
            }
            else
            {
                switch (size)
                {
                case 4:
                    @value = new LFloatNumber(buffer.GetFloat());

                    break;

                case 8:
                    @value = new LDoubleNumber(buffer.GetDouble());
                    break;
                }
            }
            if (@value == null)
            {
                throw new Exception("The input chunk has an unsupported Lua number format");
            }
            if (header.debug)
            {
                Console.WriteLine("-- parsed <number> " + @value);
            }
            return(@value);
        }
Example #12
0
 protected internal virtual void parse_code(ByteBuffer buffer, BHeader header, LFunctionParseState s)
 {
     if (header.debug)
     {
         Console.WriteLine("-- beginning to parse bytecode list");
     }
     s.length = header.integer.parse(buffer, header).asInt();
     s.code   = new int[s.length];
     for (int i = 0; i < s.length; i++)
     {
         /*byte[] intByteArray = new byte[4];
          * intByteArray[0] = Convert.ToByte(buffer.ReadByte());
          * intByteArray[1] = Convert.ToByte(buffer.ReadByte());
          * intByteArray[2] = Convert.ToByte(buffer.ReadByte());
          * intByteArray[3] = Convert.ToByte(buffer.ReadByte());*/
         s.code[i] = buffer.GetInt(); //BitConverter.ToInt32(intByteArray, 0);//buffer.getInt();
         if (header.debug)
         {
             Console.WriteLine("-- parsed codepoint " + s.code[i].ToString("X8"));
         }
     }
 }
Example #13
0
        protected internal virtual void parse_debug(ByteBuffer buffer, BHeader header, LFunctionParseState s)
        {
            if (header.debug)
            {
                Console.WriteLine("-- beginning to parse source lines list");
            }
            s.lines = header.integer.parseList(buffer, header);
            if (header.debug)
            {
                Console.WriteLine("-- beginning to parse locals list");
            }
            s.locals = header.local.parseList(buffer, header);
            if (header.debug)
            {
                Console.WriteLine("-- beginning to parse upvalues list");
            }
            BList <LString> upvalueNames = [email protected](buffer, header);

            for (int i = 0; i < upvalueNames.length.asInt(); i++)
            {
                s.upvalues[i].name = upvalueNames.get(i).deref();
            }
        }
Example #14
0
 abstract public T parse(ByteBuffer buffer, BHeader header);
Example #15
0
 protected internal override void parse_debug(ByteBuffer buffer, BHeader header, LFunctionParseState s)
 {
     s.name = [email protected](buffer, header);
     base.parse_debug(buffer, header, s);
 }