/// <summary> /// Pushes a new frame, e.g. when starting to process a lambda expression or a block expression. /// </summary> /// <param name="parameters">Parameters to add to the new frame.</param> /// <returns>Frame containing mappings for the specified parameters.</returns> public SerializationFrame PushFrame(IEnumerable <ParameterExpression> parameters) { // // E.g. when serializing "a => f(a, (b, c) => g(a, b, c))" // // 1. Serialization of "a => ..." causes extension of the environment with one frame: // ^^ // [ a -> p0.0 ] <-- // // 2. Serialization of the body "f(a, (b, c) => g(a, b, c))" causes a lookup for "a": // ^ // [ a -> p0.0 ] // ^^^ // // 3. Serialization of "(b, c) => g(a, b, c)" causes extension of the environment with one frame: // // [ b -> p1.0, c -> p1.1 ] <-- // [ a -> p0.0 ] // // 4. Serialization of the body "g(a, b, c)" causes a lookup for "a", "b", and "c", in a top-down. // fashion. Notice if both parameters are reference identical, the scoped lookup causes the // desired effect of shadowing. // var scope = _environment.Count; var frame = new SerializationFrame("p" + scope, parameters); _environment.Push(frame); return(frame); }
/// <summary> /// Creates a new serialization state object. /// </summary> public SerializationState() { _environment = new Stack <SerializationFrame>(); _globals = new SerializationFrame("g"); }