Exemplo n.º 1
0
 public static void Release(TempValString temp)
 {
     lock (lockObj) {
         temp.next     = _tempPoolHead;
         _tempPoolHead = temp;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Look up the given identifier as quickly as possible, without
        /// walking the __isa chain or doing anything fancy.  (This is used
        /// when looking up local variables.)
        /// </summary>
        /// <param name="identifier">identifier to look up</param>
        /// <returns>true if found, false if not</returns>
        public bool TryGetValue(string identifier, out Value value)
        {
            var  idVal  = TempValString.Get(identifier);
            bool result = map.TryGetValue(idVal, out value);

            TempValString.Release(idVal);
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convenience method to check whether the map contains a given string key.
        /// </summary>
        /// <param name="identifier">string key to check for</param>
        /// <returns>true if the map contains that key; false otherwise</returns>
        public bool ContainsKey(string identifier)
        {
            var  idVal  = TempValString.Get(identifier);
            bool result = map.ContainsKey(idVal);

            TempValString.Release(idVal);
            return(result);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Accessor to get/set on element of this map by a string key, walking
 /// the __isa chain as needed.  (Note that if you want to avoid that, then
 /// simply look up your value in .map directly.)
 /// </summary>
 /// <param name="identifier">string key to get/set</param>
 /// <returns>value associated with that key</returns>
 public Value this [string identifier] {
     get {
         var   idVal  = TempValString.Get(identifier);
         Value result = Lookup(idVal);
         TempValString.Release(idVal);
         return(result);
     }
     set { map[new ValString(identifier)] = value; }
 }
Exemplo n.º 5
0
 public static TempValString Get(string s)
 {
     lock (lockObj) {
         if (_tempPoolHead == null)
         {
             return(new TempValString(s));
         }
         else
         {
             var result = _tempPoolHead;
             _tempPoolHead = _tempPoolHead.next;
             result.value  = s;
             return(result);
         }
     }
 }
Exemplo n.º 6
0
 private TempValString(string s) : base(s)
 {
     this.next = null;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Look up the given identifier in the given sequence, walking the type chain
        /// until we either find it, or fail.
        /// </summary>
        /// <param name="sequence">Sequence (object) to look in.</param>
        /// <param name="identifier">Identifier to look for.</param>
        /// <param name="context">Context.</param>
        public static Value Resolve(Value sequence, string identifier, TAC.Context context, out ValMap valueFoundIn)
        {
            var includeMapType = true;

            valueFoundIn = null;
            int loopsLeft = 1000;                       // (max __isa chain depth)

            while (sequence != null)
            {
                if (sequence is ValTemp || sequence is ValVar)
                {
                    sequence = sequence.Val(context);
                }
                if (sequence is ValMap)
                {
                    // If the map contains this identifier, return its value.
                    Value result = null;
                    var   idVal  = TempValString.Get(identifier);
                    bool  found  = ((ValMap)sequence).map.TryGetValue(idVal, out result);
                    TempValString.Release(idVal);
                    if (found)
                    {
                        valueFoundIn = (ValMap)sequence;
                        return(result);
                    }

                    // Otherwise, if we have an __isa, try that next.
                    if (loopsLeft < 0)
                    {
                        return(null);                                           // (unless we've hit the loop limit)
                    }
                    if (!((ValMap)sequence).map.TryGetValue(ValString.magicIsA, out sequence))
                    {
                        // ...and if we don't have an __isa, try the generic map type if allowed
                        if (!includeMapType)
                        {
                            throw new KeyException(identifier);
                        }
                        sequence       = context.vm.mapType ?? Intrinsics.MapType();
                        includeMapType = false;
                    }
                }
                else if (sequence is ValList)
                {
                    sequence       = context.vm.listType ?? Intrinsics.ListType();
                    includeMapType = false;
                }
                else if (sequence is ValString)
                {
                    sequence       = context.vm.stringType ?? Intrinsics.StringType();
                    includeMapType = false;
                }
                else if (sequence is ValNumber)
                {
                    sequence       = context.vm.numberType ?? Intrinsics.NumberType();
                    includeMapType = false;
                }
                else if (sequence is ValFunction)
                {
                    sequence       = context.vm.functionType ?? Intrinsics.FunctionType();
                    includeMapType = false;
                }
                else
                {
                    throw new TypeException("Type Error (while attempting to look up " + identifier + ")");
                }
                loopsLeft--;
            }
            return(null);
        }