Exemple #1
0
        public object execXVARScript(BinaryReader source, ImportedObject[] imports)
        {
            //Create an XVARFunctionContainer
            int headercount = source.ReadInt32();

            #region Generic import logic
            //Import imports from source machine
            foreach (ImportedObject e in imports)
            {
                internalobjects.Add(e.VObject.refValue, e.VObject);
            }
            //Import the global variables
            for (int i = 0; i < headercount; i++)
            {
                //Read in the reference value ON THE double (yes, pun intended :)
                double refval = source.ReadDouble();
                if (source.ReadBoolean())
                {
                    int      len  = source.ReadInt32();
                    byte[]   data = source.ReadBytes(len);
                    VMObject obj  = VMObject.Deserialize(data);
                    obj.refValue = refval;
                    internalobjects.Add(refval, obj);
                }
                else
                {
                    internalobjects.Add(refval, null);
                }
            }

            //Read in the length of the INIT function
            long       initlen    = source.ReadInt64();
            byte[]     mainmethod = source.ReadBytes((int)initlen);
            XVARMethod method     = new XVARMethod(mainmethod, this);
            //TODO: Invoke method with arguments
            return(method.Invoke(new VMObject[0]));

            #endregion
        }
Exemple #2
0
        public object execXVARScript(BinaryReader source, ImportedObject[] imports)
        {
            //Create an XVARFunctionContainer
            int headercount = source.ReadInt32();

            #region Generic import logic
            //Import imports from source machine
            foreach (ImportedObject e in imports)
            {
                internalobjects.Add(e.VObject.refValue, e.VObject);
            }
            //Import the global variables
            for (int i = 0; i < headercount; i++)
            {
                //Read in the reference value ON THE double (yes, pun intended :)
                double refval = source.ReadDouble();
                if (source.ReadBoolean())
                {
                    int      len  = source.ReadInt32();
                    byte[]   data = source.ReadBytes(len);
                    VMObject obj  = VMObject.Deserialize(data);
                    obj.refValue = refval;
                    internalobjects.Add(refval, obj);
                }
                else
                {
                    internalobjects.Add(refval, null);
                }
            }
            long beginningoffile = source.BaseStream.Position;
            //Read in the length of the INIT function
            long       initlen    = source.ReadInt64();
            byte[]     mainmethod = source.ReadBytes((int)initlen);
            XVARMethod method     = new XVARMethod(source.BaseStream, this);

            //TODO: Read in all of the functions (with offsets)
            while (true)
            {
                try
                {
                    //Read in function length, and download function
                    int funclen = source.ReadInt32();
                    //TODO: Correct this. There should be a better way to load functions (without loading them all into RAM first. Maybe as variables somehow???)
                    byte[]       functiondata = source.ReadBytes(funclen);
                    MemoryStream mstream      = new MemoryStream(functiondata);
                    BinaryReader mreader      = new BinaryReader(mstream);
                    //Read in the return type (not really used for anything at THIS point)
                    mreader.ReadDouble();
                    //Read in associated object
                    VMObject assocObj = internalobjects[mreader.ReadDouble()];
                    assocObj.functions.Add(mreader.ReadInt32(), new FunctionDeclaration()
                    {
                        function = functiondata
                    });

                    mstream.Dispose();
                }
                catch (EndOfStreamException)
                {
                    break;
                }
            }
            //Invoke the MAIN method
            source.BaseStream.Position = beginningoffile;
            return(method.Invoke(new VMObject[0]));

            #endregion
        }
Exemple #3
0
        public object execXVARScript(BinaryReader source, ImportedObject[] imports)
        {
            //Create an XVARFunctionContainer
            int headercount = source.ReadInt32();
            #region Generic import logic
            //Import imports from source machine
            foreach (ImportedObject e in imports)
            {
                internalobjects.Add(e.VObject.refValue, e.VObject);

            }
            //Import the global variables
            for (int i = 0; i < headercount; i++)
            {
            //Read in the reference value ON THE double (yes, pun intended :)
                double refval = source.ReadDouble();
                if (source.ReadBoolean())
                {
                    int len = source.ReadInt32();
                    byte[] data = source.ReadBytes(len);
                    VMObject obj = VMObject.Deserialize(data);
                    obj.refValue = refval;
                    internalobjects.Add(refval,obj);

                }
                else
                {
                    internalobjects.Add(refval, null);
                }

            }
            long beginningoffile = source.BaseStream.Position;
            //Read in the length of the INIT function
            long initlen = source.ReadInt64();
            byte[] mainmethod = source.ReadBytes((int)initlen);
            XVARMethod method = new XVARMethod(source.BaseStream,this);

            //TODO: Read in all of the functions (with offsets)
            while (true)
            {
                try
                {
                    //Read in function length, and download function
                    int funclen = source.ReadInt32();
                    //TODO: Correct this. There should be a better way to load functions (without loading them all into RAM first. Maybe as variables somehow???)
                    byte[] functiondata = source.ReadBytes(funclen);
                    MemoryStream mstream = new MemoryStream(functiondata);
                    BinaryReader mreader = new BinaryReader(mstream);
                    //Read in the return type (not really used for anything at THIS point)
                    mreader.ReadDouble();
                    //Read in associated object
                    VMObject assocObj = internalobjects[mreader.ReadDouble()];
                    assocObj.functions.Add(mreader.ReadInt32(), new FunctionDeclaration() { function = functiondata });

                    mstream.Dispose();
                }
                catch (EndOfStreamException)
                {
                    break;
                }
            }
            //Invoke the MAIN method
            source.BaseStream.Position = beginningoffile;
            return method.Invoke(new VMObject[0]);

            #endregion
        }