示例#1
0
 /// <summary>
 /// Creates a new symbol reference pointing to a global var
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="envSymbol">The _ENV symbol.</param>
 /// <returns></returns>
 public static SymbolRef Global(string name, SymbolRef envSymbol)
 {
     return(new SymbolRef()
     {
         i_Index = -1, i_Type = SymbolRefType.Global, i_Env = envSymbol, i_Name = name
     });
 }
示例#2
0
        /// <summary>
        /// Creates a closure from a bytecode address.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="envTable">The env table to create a 0-upvalue</param>
        /// <returns></returns>
        private DynValue MakeClosure(int address, Table envTable = null)
        {
            this.CheckScriptOwnership(envTable);
            Closure c;

            if (envTable == null)
            {
                c = new Closure(this, address, new SymbolRef[0], new DynValue[0]);
            }
            else
            {
                var syms = new SymbolRef[1] {
                    new SymbolRef()
                    {
                        i_Env = null, i_Index = 0, i_Name = WellKnownSymbols.ENV, i_Type = SymbolRefType.DefaultEnv
                    },
                };

                var vals = new DynValue[1] {
                    DynValue.NewTable(envTable)
                };

                c = new Closure(this, address, syms, vals);
            }

            return(DynValue.NewClosure(c));
        }
示例#3
0
        /// <summary>
        /// Tries to get the reference of a symbol in the current execution state
        /// </summary>
        public DynValue EvaluateSymbol(SymbolRef symref)
        {
            if (symref == null)
            {
                return(DynValue.Nil);
            }

            return(m_Processor.GetGenericSymbol(symref));
        }
示例#4
0
        internal void ReadBinaryEnv(BinDumpReader br, SymbolRef[] symbolRefs)
        {
            uint idx = br.ReadVarUInt32();

            if (idx >= 1)
            {
                i_Env = symbolRefs[idx - 1];
            }
        }
示例#5
0
        /// <summary>
        /// Reads a symbolref from a binary stream
        /// </summary>
        internal static SymbolRef ReadBinary(BinDumpReader br)
        {
            SymbolRef that = new SymbolRef();

            that.i_Type  = (SymbolRefType)br.ReadByte();
            that.i_Index = br.ReadVarInt32();
            that.i_Name  = br.ReadString();
            return(that);
        }
示例#6
0
        internal void ReadBinaryEnv(BinaryReader br, SymbolRef[] symbolRefs)
        {
            int idx = br.ReadInt32();

            if (idx >= 0)
            {
                i_Env = symbolRefs[idx];
            }
        }
示例#7
0
        /// <summary>
        /// Creates a closure from a bytecode address.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="envTable">The env table to create a 0-upvalue</param>
        /// <returns></returns>
        private DynValue MakeClosure(int address, Table envTable = null)
        {
            if (!m_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to make a closure on dead Script [{0}]", FriendlyName));
            }
            this.CheckScriptOwnership(envTable);
            Closure c;

            if (envTable == null)
            {
                Instruction meta = m_MainProcessor.FindMeta(ref address);

                // if we find the meta for a new chunk, we use the value in the meta for the _ENV upvalue
                if ((meta != null) && (meta.NumVal2 == (int)OpCodeMetadataType.ChunkEntrypoint))
                {
                    var             index    = HeapAllocatedDynValue.Allocate(ref meta.Value);
                    ClosureRefValue refValue = new ClosureRefValue(SymbolRef.Upvalue(WellKnownSymbols.ENV, 0), index);
                    c = new Closure(this, address, new ClosureRefValue[] { refValue });
                    HeapAllocatedDynValue.DecreaseReferenceCount(index);
                }
                else
                {
                    ClosureRefValue[] refValue = new ClosureRefValue[0];
                    c = new Closure(this, address, refValue);
                }
            }
            else
            {
                var syms = new SymbolRef[] {
                    new SymbolRef()
                    {
                        i_Env = null, i_Index = 0, i_Name = WellKnownSymbols.ENV, i_Type = SymbolRefType.DefaultEnv
                    },
                };
                var             d        = DynValue.NewTable(envTable);
                var             index    = HeapAllocatedDynValue.Allocate(ref d);
                ClosureRefValue refValue = new ClosureRefValue(syms[0], index);
                c = new Closure(this, address, new ClosureRefValue[] { refValue });
                HeapAllocatedDynValue.DecreaseReferenceCount(index);
            }

            return(DynValue.NewClosure(c));
        }
示例#8
0
        /// <summary>
        /// Creates a closure from a bytecode address.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="envTable">The env table to create a 0-upvalue</param>
        /// <returns></returns>
        private DynValue MakeClosure(int address, Table envTable = null)
        {
            this.CheckScriptOwnership(envTable);
            Closure c;

            if (envTable == null)
            {
                Instruction meta = m_MainProcessor.FindMeta(ref address);

                // if we find the meta for a new chunk, we use the value in the meta for the _ENV upvalue
                if ((meta != null) && (meta.NumVal2 == (int)OpCodeMetadataType.ChunkEntrypoint))
                {
                    c = new Closure(this, address,
                                    new SymbolRef[] { SymbolRef.Upvalue(WellKnownSymbols.ENV, 0) },
                                    new DynValue[] { meta.Value });
                }
                else
                {
                    c = new Closure(this, address, new SymbolRef[0], new DynValue[0]);
                }
            }
            else
            {
                var syms = new SymbolRef[] {
                    new SymbolRef()
                    {
                        i_Env = null, i_Index = 0, i_Name = WellKnownSymbols.ENV, i_Type = SymbolRefType.DefaultEnv
                    },
                };

                var vals = new DynValue[] {
                    DynValue.NewTable(envTable)
                };

                c = new Closure(this, address, syms, vals);
            }

            return(DynValue.NewClosure(c));
        }
示例#9
0
		/// <summary>
		/// Creates a closure from a bytecode address.
		/// </summary>
		/// <param name="address">The address.</param>
		/// <param name="envTable">The env table to create a 0-upvalue</param>
		/// <returns></returns>
		private DynValue MakeClosure(int address, Table envTable = null)
		{
			this.CheckScriptOwnership(envTable);
			Closure c;

			if (envTable == null)
				c = new Closure(this, address, new SymbolRef[0], new DynValue[0]);
			else
			{
				var syms = new SymbolRef[1] {
					new SymbolRef() { i_Env = null, i_Index= 0, i_Name = WellKnownSymbols.ENV, i_Type =  SymbolRefType.DefaultEnv },
				};

				var vals = new DynValue[1] {
					DynValue.NewTable(envTable)
				};

				c = new Closure(this, address, syms, vals);
			}

			return DynValue.NewClosure(c);
		}
示例#10
0
		/// <summary>
		/// Creates a new symbol reference pointing to a global var
		/// </summary>
		/// <param name="name">The name.</param>
		/// <param name="envSymbol">The _ENV symbol.</param>
		/// <returns></returns>
		public static SymbolRef Global(string name, SymbolRef envSymbol)
		{
			return new SymbolRef() { i_Index = -1, i_Type = SymbolRefType.Global, i_Env = envSymbol, i_Name = name };
		}
示例#11
0
		internal void ReadBinaryEnv(BinaryReader br, SymbolRef[] symbolRefs)
		{
			int idx = br.ReadInt32();

			if (idx >= 0)
				i_Env = symbolRefs[idx];
		}
示例#12
0
		/// <summary>
		/// Reads a symbolref from a binary stream 
		/// </summary>
		internal static SymbolRef ReadBinary(BinaryReader br)
		{
			SymbolRef that = new SymbolRef();
			that.i_Type = (SymbolRefType)br.ReadByte();
			that.i_Index = br.ReadInt32();
			that.i_Name = br.ReadString();
			return that;
		}
示例#13
0
		/// <summary>
		/// Tries to get the reference of a symbol in the current execution state
		/// </summary>
		public DynValue EvaluateSymbol(SymbolRef symref)
		{
			if (symref == null)
				return DynValue.Nil;

			return m_Processor.GetGenericSymbol(symref);
		}
示例#14
0
		/// <summary>
		/// Creates a closure from a bytecode address.
		/// </summary>
		/// <param name="address">The address.</param>
		/// <param name="envTable">The env table to create a 0-upvalue</param>
		/// <returns></returns>
		private DynValue MakeClosure(int address, Table envTable = null)
		{
			this.CheckScriptOwnership(envTable);
			Closure c;

			if (envTable == null)
			{
				Instruction meta = m_MainProcessor.FindMeta(ref address);

				// if we find the meta for a new chunk, we use the value in the meta for the _ENV upvalue
				if ((meta != null) && (meta.NumVal2 == (int)OpCodeMetadataType.ChunkEntrypoint))
				{
					c = new Closure(this, address,
						new SymbolRef[] { SymbolRef.Upvalue(WellKnownSymbols.ENV, 0) },
						new DynValue[] { meta.Value });
				}
				else
				{
					c = new Closure(this, address, new SymbolRef[0], new DynValue[0]);
				}
			}
			else
			{
				var syms = new SymbolRef[] {
					new SymbolRef() { i_Env = null, i_Index= 0, i_Name = WellKnownSymbols.ENV, i_Type =  SymbolRefType.DefaultEnv },
				};

				var vals = new DynValue[] {
					DynValue.NewTable(envTable)
				};

				c = new Closure(this, address, syms, vals);
			}

			return DynValue.NewClosure(c);
		}
示例#15
0
 /// <summary>
 /// Creates a new symbol reference pointing to a global var
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="envSymbol">The _ENV symbol.</param>
 public static SymbolRef Global(string name, SymbolRef envSymbol)
 {
     return(new SymbolRef {
         _index = -1, _type = SymbolRefType.Global, _env = envSymbol, _name = name
     });
 }
示例#16
0
 static SymbolRef()
 {
     DefaultEnv = new SymbolRef {i_Type = SymbolRefType.DefaultEnv};
 }