public ValMap EvalCopy(TAC.Context context) { // Create a copy of this map, evaluating its members as we go. // This is used when a map literal appears in the source, to // ensure that each time that code executes, we get a new, distinct // mutable object, rather than the same object multiple times. var result = new ValMap(); foreach (Value k in map.Keys) { Value key = k; // stupid C#! Value value = map[key]; if (key is ValTemp || key is ValVar) { key = key.Val(context); } if (value is ValTemp || value is ValVar) { value = value.Val(context); } result.map[key] = value; } return(result); }
/// <summary> /// This version of Val is like the one above, but also returns /// (via the output parameter) the ValMap the value was found in, /// which could be several steps up the __isa chain. /// </summary> /// <returns>The value.</returns> /// <param name="context">Context.</param> /// <param name="valueFoundIn">Value found in.</param> public virtual Value Val(TAC.Context context, out ValMap valueFoundIn) { valueFoundIn = null; return(this); }
/// <summary> /// Similar to Val, but recurses into the sub-values contained by this /// value (if it happens to be a container, such as a list or map). /// </summary> /// <param name="context">context in which to evaluate</param> /// <returns>fully-evaluated value</returns> public virtual Value FullEval(TAC.Context context) { return(this); }
public override Value FullEval(TAC.Context context) { return(null); }
/// <summary> /// Get the current value of this Value in the given context. Basic types /// evaluate to themselves, but some types (e.g. variable references) may /// evaluate to something else. /// </summary> /// <param name="context">TAC context to evaluate in</param> /// <returns>value of this value (possibly the same as this)</returns> public virtual Value Val(TAC.Context context) { return(this); // most types evaluate to themselves }
public override Value Val(TAC.Context context) { ValMap ignored; return(Val(context, out ignored)); }
public override Value Val(TAC.Context context, out ValMap valueFoundIn) { valueFoundIn = null; return(null); }
/// <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); }
public override Value Val(TAC.Context context, out ValMap valueFoundIn) { valueFoundIn = null; return(context.GetTemp(tempNum)); }
public override Value Val(TAC.Context context) { return(context.GetTemp(tempNum)); }
public override Value Val(TAC.Context context, out ValMap valueFoundIn) { valueFoundIn = null; return(context.GetVar(identifier)); }
public override Value Val(TAC.Context context) { return(context.GetVar(identifier)); }