Exemplo n.º 1
0
 public TjsCodeObject(CodeObject obj)
 {
     Object = obj;
 }
Exemplo n.º 2
0
 public TjsCodeObject(CodeObject obj, CodeObject ths)
 {
     Object = obj;
     This   = ths;
 }
Exemplo n.º 3
0
        private void ReadObjects(BinaryReader br)
        {
            int topLevel = br.ReadInt32();
            int objCount = br.ReadInt32();

            int[]        parents           = new int[objCount];
            int[]        propSetters       = new int[objCount];
            int[]        propGetters       = new int[objCount];
            int[]        superClassGetters = new int[objCount];
            List <int[]> properties        = new List <int[]>(objCount);
            List <(TjsCodeObject Var, int Index)> replacements = new List <(TjsCodeObject Var, int Index)>();
            List <CodeObject> objects = new List <CodeObject>(objCount);

            for (int i = 0; i < objCount; i++)
            {
                if (br.ReadChars(4).ToRealString() != FILE_TAG_LE)
                {
                    throw new TjsFormatException(TjsBadFormatReason.Header, "ByteCode Signature error");
                }

                int objSize = br.ReadInt32(); // indicate the following size, objSize not included
                parents[i] = br.ReadInt32();
                int name                        = br.ReadInt32();
                int contextType                 = br.ReadInt32();
                int maxVariableCount            = br.ReadInt32();
                int variableReserveCount        = br.ReadInt32();
                int maxFrameCount               = br.ReadInt32();
                int funcDeclArgCount            = br.ReadInt32();
                int funcDeclUnnamedArgArrayBase = br.ReadInt32();
                int funcDeclCollapseBase        = br.ReadInt32();
                propSetters[i]       = br.ReadInt32();
                propGetters[i]       = br.ReadInt32();
                superClassGetters[i] = br.ReadInt32();
                //codePos/srcPos
                int    count  = br.ReadInt32();
                long[] srcPos = new long[count];
                for (int j = 0; j < count; j++)
                {
                    srcPos[j] = br.ReadInt64();
                }

                //code
                count = br.ReadInt32();
                short[] code = new short[count];
                for (int j = 0; j < count; j++)
                {
                    code[j] = br.ReadInt16();
                }

                var padding = 4 - (count * 2) % 4;
                if (padding > 0 && padding < 4)
                {
                    br.ReadBytes(padding);
                }

                //var
                count = br.ReadInt32();
                int vCount   = count * 2;
                var varTypes = new List <short>(vCount);


                for (int j = 0; j < vCount; j++)
                {
                    varTypes.Add(br.ReadInt16());
                }

                List <ITjsVariant> vars = new List <ITjsVariant>(count);

                for (int j = 0; j < count; j++)
                {
                    int p     = j * 2;
                    var type  = varTypes[p];
                    int index = varTypes[p + 1];
                    switch ((TjsInternalType)type)
                    {
                    case TjsInternalType.Void:
                        vars.Add(TjsVoid.Void);
                        break;

                    case TjsInternalType.Object:
                        vars.Add(new TjsObject(null)
                        {
                            Internal = false
                        });
                        break;

                    case TjsInternalType.InterObject:
                        var co = new TjsCodeObject(null)
                        {
                            Internal = true
                        };
                        vars.Add(co);
                        replacements.Add((co, index));
                        break;

                    case TjsInternalType.InterGenerator:
                        var co2 = new TjsCodeObject(null)
                        {
                            Internal = true
                        };
                        vars.Add(co2);
                        replacements.Add((co2, index));
                        break;

                    case TjsInternalType.String:
                        vars.Add(new TjsString(Data.Strings[index]));
                        break;

                    case TjsInternalType.Octet:
                        vars.Add(new TjsOctet(Data.Octets[index]));
                        break;

                    case TjsInternalType.Real:
                        vars.Add(new TjsReal(Data.Doubles[index]));
                        break;

                    case TjsInternalType.Byte:
                        vars.Add(new TjsInt(Data.Bytes[index]));
                        break;

                    case TjsInternalType.Short:
                        vars.Add(new TjsInt(Data.Shorts[index]));
                        break;

                    case TjsInternalType.Int:
                        vars.Add(new TjsInt(Data.Ints[index]));
                        break;

                    case TjsInternalType.Long:
                        vars.Add(new TjsReal(Data.Longs[index]));
                        break;

                    case TjsInternalType.Unknown:
                    default:
                        vars.Add(TjsVoid.Void);
                        break;
                    }
                }

                count = br.ReadInt32();
                int[] superPointers = new int[count];
                for (int j = 0; j < count; j++)
                {
                    superPointers[j] = br.ReadInt32();
                }

                //properties
                count = br.ReadInt32();
                int[] props = new int[count * 2];
                for (int j = 0; j < count * 2; j++)
                {
                    props[j] = br.ReadInt32();
                }

                properties.Add(props);

                CodeObject obj = new CodeObject(this, Data.Strings[name], contextType, code, vars, maxVariableCount,
                                                variableReserveCount, maxFrameCount, funcDeclArgCount, funcDeclUnnamedArgArrayBase,
                                                funcDeclCollapseBase, true, srcPos, superPointers);

                objects.Add(obj);
            }

            TjsCodeObject propVar = null;

            for (int i = 0; i < objCount; i++)
            {
                CodeObject parent           = null;
                CodeObject propSetter       = null;
                CodeObject propGetter       = null;
                CodeObject superClassGetter = null;

                if (parents[i] >= 0)
                {
                    parent = objects[parents[i]];
                }

                if (propSetters[i] >= 0)
                {
                    propSetter = objects[propSetters[i]];
                }

                if (propGetters[i] >= 0)
                {
                    propGetter = objects[propGetters[i]];
                }

                if (superClassGetters[i] >= 0)
                {
                    superClassGetter = objects[superClassGetters[i]];
                }

                objects[i].Parent     = parent;
                objects[i].Setter     = propSetter;
                objects[i].Getter     = propGetter;
                objects[i].SuperClass = superClassGetter;

                if (properties[i] != null)
                {
                    var pObj  = parent;
                    var props = properties[i];
                    for (int j = 0; j < props.Length / 2; j++)
                    {
                        var name = Data.Strings[props[j * 2]];
                        var obj  = objects[props[j * 2 + 1]];
                        propVar = new TjsCodeObject(obj);
                        pObj?.SetProperty(TjsInterfaceFlag.MemberEnsure | TjsInterfaceFlag.IgnorePropInvoking, name,
                                          propVar, obj);
                    }
                }
            }

            foreach (var replacement in replacements)
            {
                replacement.Var.Object = objects[replacement.Index];
            }

            replacements.Clear();
            if (topLevel >= 0)
            {
                TopLevel = objects[topLevel];
            }

            Objects = objects;
        }
Exemplo n.º 4
0
 private void CollectObjectData(DataSection data, CodeObject code)
 {
 }
Exemplo n.º 5
0
 public Variable(short slot, CodeObject obj)
 {
     Slot        = slot;
     IsParameter = CheckIsParameter(obj, slot);
 }