···2828using System.Collections.Generic;
2929using System.Diagnostics;
3030using System.Linq;
3131+using Prexonite.Commands.Core;
3132using Prexonite.Compiler.Ast;
32333334namespace Prexonite.Compiler.Macro.Commands
3435{
3636+ /// <summary>
3737+ /// Wraps invocations of call\* commands (or functions), handling partial applications where
3838+ /// placeholders occur in list literals.
3939+ /// </summary>
4040+ /// <remarks>
4141+ /// <para>In the following example, <c>pcw</c> is a <see cref="PartialCallWrapper"/>
4242+ /// for the <see cref="Call"/> command.</para>
4343+ /// <code>pcw(f(?),?,[1,?,2])</code>
4444+ /// <para>becomes</para>
4545+ /// <code>call\star(2,call(?),f(?),?,[1,?,2])</code>
4646+ /// <para>But if there are no placeholders, the macro removes itself:</para>
4747+ /// <code>pcw(f(?),x,[1,2,3])</code>
4848+ /// <para>becomes</para>
4949+ /// <code>call(f(?),x,[1,2,3])</code>
5050+ /// <para>In most cases, <see cref="PartialCallWrapper"/> can be used directly, just by supplying the
5151+ /// underlying call implementation (doesn't need to be a command).</para>
5252+ /// <para> In case your call\* has special
5353+ /// requirement (e.g., like call\member, it has the member id as an additional parameter), you can
5454+ /// inherit from <see cref="PartialCallWrapper"/> and override <see cref="GetTrivialPartialApplication"/>,
5555+ /// <see cref="GetCallArguments"/> and <see cref="GetPassThroughArguments"/>.</para>
5656+ /// </remarks>
3557 public class PartialCallWrapper : PartialMacroCommand
3658 {
3759 private readonly string _callImplementationId;
···4971 get { return _callImplementetaionInterpretation; }
5072 }
51737474+ /// <summary>
7575+ /// Creates a new instance of <see cref="PartialCallWrapper"/> around the specified call implementation.
7676+ /// </summary>
7777+ /// <param name="alias">The name of this macro command.</param>
7878+ /// <param name="callImplementationId">The physical id of the call implementation.</param>
7979+ /// <param name="callImplementetaionInterpretation">The interpretation of the call implementation.</param>
5280 public PartialCallWrapper(string alias, string callImplementationId,
5381 SymbolInterpretations callImplementetaionInterpretation)
5482 : base(alias)
···84112 {
85113 // call(?0) ⇒ call\perform(?0)
861148787- var cp = GetTrivialPartialApplication(context);
8888- context.Block.Expression = cp;
115115+ context.Block.Expression = GetTrivialPartialApplication(context);
89116 return;
90117 }
91118···104131 CallStar.Instance.Id,
105132 SymbolInterpretations.MacroCommand);
106133107107- // Protected the first two arguments
134134+ // Protect the first two arguments
108135 inv.Arguments.Add(context.CreateConstant(GetPassThroughArguments(context)));
109136110110- // Indicate the kind of call by passing `call(?)`, a partial application of call
137137+ // Indicate the kind of call by passing `call\perform(?)`, a partial application of call
111138 var paCall = context.CreateGetSetSymbol(_callImplementetaionInterpretation,
112139 context.Invocation.Call, _callImplementationId,
113140 new AstPlaceholder(context.Invocation.File, context.Invocation.Line,
···120147 context.Block.Expression = inv;
121148 }
122149150150+ /// <summary>
151151+ /// Returns a trivial partial application of the call implementation (call\perform(?))
152152+ /// </summary>
153153+ /// <param name="context">The macro context in which to create the AST node.</param>
154154+ /// <returns>A trivial partial application of the call implementation.</returns>
123155 protected virtual AstGetSetSymbol GetTrivialPartialApplication(MacroContext context)
124156 {
125157 var cp = new AstGetSetSymbol(context.Invocation.File, context.Invocation.Line,
···130162 return cp;
131163 }
132164165165+ /// <summary>
166166+ /// Provides access to the call arguments, including the call target and any other
167167+ /// parameters (like the member id for call\member).
168168+ /// </summary>
169169+ /// <param name="context">The context from which to derive the arguments.</param>
170170+ /// <returns>The arguments to the call invocation.</returns>
133171 protected virtual IEnumerable<IAstExpression> GetCallArguments(MacroContext context)
134172 {
135173 return context.Invocation.Arguments;
136174 }
137175176176+ /// <summary>
177177+ /// Determines the number of arguments that need to be protected when passed to call\star.
178178+ /// </summary>
179179+ /// <param name="context"></param>
180180+ /// <returns></returns>
181181+ /// <remarks>
182182+ /// <para>For call and call\async, for instance, two arguments need to be passed to call\star
183183+ /// unprocessed: the reference to the call implementation (<c>call(?)</c> or <c>call\async(?)</c>)
184184+ /// and the call target.</para>
185185+ /// <para>In the case of <c>call\member</c>, however, there is an additional argument to be
186186+ /// protected: the member id.</para></remarks>
138187 protected virtual int GetPassThroughArguments(MacroContext context)
139188 {
140189 return 2;
+2-1
Prexonite/PVariable.cs
···125125 throw new ArgumentNullException("name");
126126 if (name.Length == 0)
127127 throw new ArgumentException("name is expected to contain at least one character.");
128128- Meta[Application.NameKey] = name;
128128+ _meta = new MetaTable();
129129+ _meta[Application.NameKey] = name;
129130 }
130131131132 #region IIndirectCall Members