public VM.StackFrame ToStackFrame()
        {
            VM.StackFrame frame = new VM.StackFrame(this.FunctionInfo, this.ReturnAddress);
            frame.Locals = SerializedLSLPrimitive.ToPrimitiveList(this.Locals);

            return(frame);
        }
        public static SerializedLSLPrimitive[] FromPrimitiveStack(Stack <object> primStack)
        {
            SerializedLSLPrimitive[] serPrimList = new SerializedLSLPrimitive[primStack.Count];

            int i = 0;

            foreach (object obj in primStack)
            {
                serPrimList[i] = SerializedLSLPrimitive.FromPrimitive(obj);

                /*if (validate)
                 * {
                 *  if (!serPrimList[i].IsValid())
                 *  {
                 *      throw new SerializationException(
                 *          String.Format(
                 *              "FromPrimitiveStack: Unable to serialize object to SerializedLSLPrimitive: Type: {0} Value: {1}",
                 *              obj != null ? obj.GetType().FullName : "null", obj));
                 *
                 *  }
                 * }*/

                i++;
            }

            return(serPrimList);
        }
        public VM.CompiledScript ToCompiledScript()
        {
            VM.CompiledScript compScript = new VM.CompiledScript();
            compScript.Version  = this.Version;
            compScript.ByteCode = this.ByteCode;

            //const pool, only type that needs changing is the list type
            compScript.ConstPool = SerializedLSLPrimitive.ToPrimitiveList(this.ConstPool);

            if (this.StateEvents != null)
            {
                compScript.StateEvents = new VM.EventInfo[this.StateEvents.Count][];

                for (int i = 0; i < this.StateEvents.Count; i++)
                {
                    compScript.StateEvents[i] = this.StateEvents[i];
                }
            }
            else
            {
                compScript.StateEvents = new VM.EventInfo[0][];
            }



            compScript.NumGlobals = this.NumGlobals;
            compScript.AssetId    = this.AssetId;

            return(compScript);
        }
        public static SerializedRuntimeState FromRuntimeState(VM.RuntimeState state)
        {
            SerializedRuntimeState serState = new SerializedRuntimeState();

            serState.IP       = state.IP;
            serState.LSLState = state.LSLState;
            serState.Globals  = SerializedLSLPrimitive.FromPrimitiveList(state.Globals);
            serState.Operands = SerializedLSLPrimitive.FromPrimitiveStack(state.Operands);



            serState.Calls = new SerializedStackFrame[state.Calls.Count];
            int i = 0;

            foreach (VM.StackFrame frame in state.Calls)
            {
                serState.Calls[i] = SerializedStackFrame.FromStackFrame(frame);
                i++;
            }

            serState.TopFrame = SerializedStackFrame.FromStackFrame(state.TopFrame);
            serState.MemInfo  = state.MemInfo;

            serState.EventQueue = new SerializedPostedEvent[state.EventQueue.Count];
            i = 0;
            foreach (VM.PostedEvent evt in state.EventQueue)
            {
                serState.EventQueue[i] = SerializedPostedEvent.FromPostedEvent(evt);
                i++;
            }

            serState.RunState = state.RunState;
            serState.Enabled  = state.GeneralEnable;

            UInt64 tickCountNow = Util.Clock.GetLongTickCount();

            serState.StateCapturedOn = DateTime.Now;

            //if the next wakeup is in the past, just filter it to be now equal to the state capture time
            //this prevents strange values from getting into the tickcounttodatetime calculation
            serState.NextWakeup           = state.NextWakeup < tickCountNow ? serState.StateCapturedOn : Util.Clock.TickCountToDateTime(state.NextWakeup, tickCountNow);
            serState.TimerLastScheduledOn = Util.Clock.TickCountToDateTime(state.TimerLastScheduledOn, tickCountNow);

            serState.TimerInterval  = state.TimerInterval;
            serState.RunningEvent   = SerializedPostedEvent.FromPostedEvent(state.RunningEvent);
            serState.ActiveListens  = new Dictionary <int, VM.ActiveListen>(state.ActiveListens);
            serState.StartParameter = state.StartParameter;

            serState.MiscAttributes = new Dictionary <int, SerializedLSLPrimitive[]>();
            foreach (KeyValuePair <int, object[]> kvp in state.MiscAttributes)
            {
                serState.MiscAttributes[kvp.Key] = SerializedLSLPrimitive.FromPrimitiveList(kvp.Value);
            }

            //calculate total runtime
            serState.TotalRuntime = state.TotalRuntime;

            return(serState);
        }
Exemple #5
0
        internal VM.PostedEvent ToPostedEvent()
        {
            VM.PostedEvent evt = new VM.PostedEvent();
            evt.EventType = this.EventType;

            evt.Args = SerializedLSLPrimitive.ToPrimitiveList(this.Args);

            evt.DetectVars = this.DetectVars;

            evt.TransitionToState = this.TransitionToState;

            return(evt);
        }
Exemple #6
0
        /// <summary>
        /// Create a new Serializable List from the LSLList primitive type
        /// </summary>
        /// <param name="lSLList"></param>
        /// <returns></returns>
        public static SerializedLSLList FromList(Types.LSLList lSLList)
        {
            SerializedLSLList list = new SerializedLSLList();

            list.ListContents = new List <SerializedLSLPrimitive>();

            foreach (object obj in lSLList.Members)
            {
                SerializedLSLPrimitive primitive = new SerializedLSLPrimitive();
                primitive.Value = obj;
                list.ListContents.Add(primitive);
            }

            return(list);
        }
        public static SerializedLSLPrimitive FromPrimitive(object obj)
        {
            if (!(obj is Types.LSLList))
            {
                SerializedLSLPrimitive primitive = new SerializedLSLPrimitive();
                primitive.Value = obj;

                return(primitive);
            }
            else
            {
                SerializedLSLPrimitive primitive = new SerializedLSLPrimitive();
                primitive.Value = SerializedLSLList.FromList((Types.LSLList)obj);
                return(primitive);
            }
        }
Exemple #8
0
        /// <summary>
        /// Creates a new serialized event from a posted event
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        public static SerializedPostedEvent FromPostedEvent(VM.PostedEvent evt)
        {
            if (evt == null)
            {
                return(null);
            }

            SerializedPostedEvent serEvent = new SerializedPostedEvent();

            serEvent.EventType = evt.EventType;

            serEvent.Args = SerializedLSLPrimitive.FromPrimitiveList(evt.Args);

            serEvent.DetectVars = evt.DetectVars;

            serEvent.TransitionToState = evt.TransitionToState;

            return(serEvent);
        }
        /// <summary>
        /// Creates a new SerializedScript from a CompiledScript
        /// </summary>
        /// <param name="script"></param>
        /// <returns></returns>
        public static SerializedScript FromCompiledScript(VM.CompiledScript script)
        {
            SerializedScript serScript = new SerializedScript();

            serScript.Version  = script.Version;
            serScript.ByteCode = script.ByteCode;

            serScript.ConstPool = SerializedLSLPrimitive.FromPrimitiveList(script.ConstPool);

            serScript.StateEvents = new Dictionary <int, VM.EventInfo[]>();
            for (int i = 0; i < script.StateEvents.Length; i++)
            {
                serScript.StateEvents.Add(i, script.StateEvents[i]);
            }

            serScript.NumGlobals = script.NumGlobals;
            serScript.AssetId    = script.AssetId;

            return(serScript);
        }
        public static SerializedStackFrame FromStackFrame(VM.StackFrame frame)
        {
            if (frame == null)
            {
                return(null);
            }

            SerializedStackFrame serFrame = new SerializedStackFrame();

            serFrame.FunctionInfo = frame.FunctionInfo;

            serFrame.ReturnAddress = frame.ReturnAddress;

            serFrame.Locals = new SerializedLSLPrimitive[frame.Locals.Length];
            for (int i = 0; i < serFrame.Locals.Length; i++)
            {
                serFrame.Locals[i] = SerializedLSLPrimitive.FromPrimitive(frame.Locals[i]);
            }

            return(serFrame);
        }
        public static Stack <object> ToPrimitiveStack(SerializedLSLPrimitive[] serializedLSLPrimitive)
        {
            if (serializedLSLPrimitive == null)
            {
                return(new Stack <object>());
            }

            //push the primitives back onto the stack in reverse order
            Stack <object> primStack = new Stack <object>(serializedLSLPrimitive.Length);

            for (int i = serializedLSLPrimitive.Length - 1; i >= 0; i--)
            {
                SerializedLSLPrimitive obj = serializedLSLPrimitive[i];

                if (!(obj.Value is SerializedLSLList))
                {
                    /*if (validate)
                     * {
                     *  if (!obj.IsValid())
                     *  {
                     *      throw new SerializationException(
                     *          String.Format(
                     *              "ToPrimitiveStack: Unable to deserialize LSLPrimitive to object: Type: {0} Value: {1}",
                     *              obj != null && obj.Value != null ? obj.Value.GetType().FullName : "null", obj.Value));
                     *  }
                     * }*/

                    primStack.Push(obj.Value);
                }
                else
                {
                    SerializedLSLList list = (SerializedLSLList)obj.Value;
                    primStack.Push(list.ToList());
                }
            }

            return(primStack);
        }
        public static object[] ToPrimitiveList(SerializedLSLPrimitive[] serPrimList)
        {
            if (serPrimList == null)
            {
                return(new object[0]);
            }

            object[] primitiveList = new object[serPrimList.Length];

            for (int i = 0; i < serPrimList.Length; i++)
            {
                SerializedLSLPrimitive obj = serPrimList[i];

                if (!(obj.Value is SerializedLSLList))
                {
                    /*if (validate)
                     * {
                     *  if (!obj.IsValid())
                     *  {
                     *      throw new SerializationException(
                     *          String.Format(
                     *              "ToPrimitiveList: Unable to deserialize LSLPrimitive to object: Type: {0} Value: {1}",
                     *              obj != null && obj.Value != null ? obj.Value.GetType().FullName : "null", obj));
                     *  }
                     * }*/

                    primitiveList[i] = obj.Value;
                }
                else
                {
                    SerializedLSLList list = (SerializedLSLList)obj.Value;
                    primitiveList[i] = list.ToList();
                }
            }

            return(primitiveList);
        }
        public static SerializedLSLPrimitive[] FromPrimitiveList(object[] primList)
        {
            SerializedLSLPrimitive[] serPrimList = new SerializedLSLPrimitive[primList.Length];

            for (int i = 0; i < primList.Length; i++)
            {
                object obj = primList[i];
                serPrimList[i] = SerializedLSLPrimitive.FromPrimitive(obj);

                /*if (validate)
                 * {
                 *  if (!serPrimList[i].IsValid())
                 *  {
                 *      throw new SerializationException(
                 *          String.Format(
                 *              "FromPrimitiveList: Unable to serialize object to SerializedLSLPrimitive: Type: {0} Value: {1}",
                 *              obj != null ? obj.GetType().FullName : "null", obj));
                 *
                 *  }
                 * }*/
            }

            return(serPrimList);
        }
        public VM.RuntimeState ToRuntimeState()
        {
            VM.RuntimeState state = new VM.RuntimeState();
            state.IP       = this.IP;
            state.LSLState = this.LSLState;
            state.Globals  = SerializedLSLPrimitive.ToPrimitiveList(this.Globals);
            state.Operands = SerializedLSLPrimitive.ToPrimitiveStack(this.Operands);

            if (this.Calls != null)
            {
                state.Calls = new Stack <VM.StackFrame>(this.Calls.Length);
                //calls is a stack, so again push them in reverse order
                for (int i = this.Calls.Length - 1; i >= 0; i--)
                {
                    state.Calls.Push(this.Calls[i].ToStackFrame());
                }
            }
            else
            {
                state.Calls = new Stack <VM.StackFrame>();
            }

            if (state.Calls.Count > 0)
            {
                //DO NOT USE THE SERIALIZED TOPFRAME HERE, IT IS A DIFFERENT REFERENCE THAN
                //state.Calls.Peek!!!
                state.TopFrame = state.Calls.Peek();
            }
            else
            {
                state.TopFrame = null;
            }

            state.MemInfo = this.MemInfo;

            state.EventQueue = new C5.LinkedList <VM.PostedEvent>();
            if (this.EventQueue != null)
            {
                foreach (SerializedPostedEvent evt in this.EventQueue)
                {
                    state.EventQueue.Add(evt.ToPostedEvent());
                }
            }

            state.RunState      = this.RunState;
            state.GeneralEnable = this.Enabled;

            UInt64 currentTickCount = Util.Clock.GetLongTickCount();

            state.StateCapturedOn = currentTickCount;

            Int64 relativeNextWakeup = (Int64)currentTickCount + (Int64)(this.NextWakeup - this.StateCapturedOn).TotalMilliseconds;

            if (relativeNextWakeup < 0)
            {
                relativeNextWakeup = 0;
            }

            state.NextWakeup = (UInt64)relativeNextWakeup;

            Int64 relativeTimerLastScheduledOn = (Int64)currentTickCount + (Int64)(this.TimerLastScheduledOn - this.StateCapturedOn).TotalMilliseconds;

            if (relativeTimerLastScheduledOn < 0)
            {
                relativeTimerLastScheduledOn = 0;
            }

            state.TimerLastScheduledOn = (UInt64)relativeTimerLastScheduledOn;
            state.TimerInterval        = this.TimerInterval;

            if (this.RunningEvent != null)
            {
                state.RunningEvent = this.RunningEvent.ToPostedEvent();
            }

            if (this.ActiveListens != null)
            {
                state.ActiveListens = this.ActiveListens;
            }
            else
            {
                state.ActiveListens = new Dictionary <int, VM.ActiveListen>();
            }

            state.StartParameter = this.StartParameter;

            state.MiscAttributes = new Dictionary <int, object[]>();
            if (this.MiscAttributes != null)
            {
                foreach (KeyValuePair <int, SerializedLSLPrimitive[]> kvp in MiscAttributes)
                {
                    state.MiscAttributes[kvp.Key] = SerializedLSLPrimitive.ToPrimitiveList(kvp.Value);
                }
            }

            state.OtherRuntime         = TotalRuntime;
            state.StartTimeOnSimulator = Util.Clock.GetLongTickCount();

            return(state);
        }