Prexonite, a .NET hosted scripting language with a focus on meta-programming and embedded DSLs
0

Configure Feed

Select the types of activity you want to include in your feed.

Merge remote-tracking branch 'origin/r1-2-3'

Christian Klauser (Jul 10, 2012, 1:12 PM +0200) b7a56a53 07870c83

+60 -12
+53 -4
Prexonite/Compiler/Macro/Commands/PartialCallWrapper.cs
··· 28 28 using System.Collections.Generic; 29 29 using System.Diagnostics; 30 30 using System.Linq; 31 + using Prexonite.Commands.Core; 31 32 using Prexonite.Compiler.Ast; 32 33 33 34 namespace Prexonite.Compiler.Macro.Commands 34 35 { 36 + /// <summary> 37 + /// Wraps invocations of call\* commands (or functions), handling partial applications where 38 + /// placeholders occur in list literals. 39 + /// </summary> 40 + /// <remarks> 41 + /// <para>In the following example, <c>pcw</c> is a <see cref="PartialCallWrapper"/> 42 + /// for the <see cref="Call"/> command.</para> 43 + /// <code>pcw(f(?),?,[1,?,2])</code> 44 + /// <para>becomes</para> 45 + /// <code>call\star(2,call(?),f(?),?,[1,?,2])</code> 46 + /// <para>But if there are no placeholders, the macro removes itself:</para> 47 + /// <code>pcw(f(?),x,[1,2,3])</code> 48 + /// <para>becomes</para> 49 + /// <code>call(f(?),x,[1,2,3])</code> 50 + /// <para>In most cases, <see cref="PartialCallWrapper"/> can be used directly, just by supplying the 51 + /// underlying call implementation (doesn't need to be a command).</para> 52 + /// <para> In case your call\* has special 53 + /// requirement (e.g., like call\member, it has the member id as an additional parameter), you can 54 + /// inherit from <see cref="PartialCallWrapper"/> and override <see cref="GetTrivialPartialApplication"/>, 55 + /// <see cref="GetCallArguments"/> and <see cref="GetPassThroughArguments"/>.</para> 56 + /// </remarks> 35 57 public class PartialCallWrapper : PartialMacroCommand 36 58 { 37 59 private readonly string _callImplementationId; ··· 49 71 get { return _callImplementetaionInterpretation; } 50 72 } 51 73 74 + /// <summary> 75 + /// Creates a new instance of <see cref="PartialCallWrapper"/> around the specified call implementation. 76 + /// </summary> 77 + /// <param name="alias">The name of this macro command.</param> 78 + /// <param name="callImplementationId">The physical id of the call implementation.</param> 79 + /// <param name="callImplementetaionInterpretation">The interpretation of the call implementation.</param> 52 80 public PartialCallWrapper(string alias, string callImplementationId, 53 81 SymbolInterpretations callImplementetaionInterpretation) 54 82 : base(alias) ··· 84 112 { 85 113 // call(?0) ⇒ call\perform(?0) 86 114 87 - var cp = GetTrivialPartialApplication(context); 88 - context.Block.Expression = cp; 115 + context.Block.Expression = GetTrivialPartialApplication(context); 89 116 return; 90 117 } 91 118 ··· 104 131 CallStar.Instance.Id, 105 132 SymbolInterpretations.MacroCommand); 106 133 107 - // Protected the first two arguments 134 + // Protect the first two arguments 108 135 inv.Arguments.Add(context.CreateConstant(GetPassThroughArguments(context))); 109 136 110 - // Indicate the kind of call by passing `call(?)`, a partial application of call 137 + // Indicate the kind of call by passing `call\perform(?)`, a partial application of call 111 138 var paCall = context.CreateGetSetSymbol(_callImplementetaionInterpretation, 112 139 context.Invocation.Call, _callImplementationId, 113 140 new AstPlaceholder(context.Invocation.File, context.Invocation.Line, ··· 120 147 context.Block.Expression = inv; 121 148 } 122 149 150 + /// <summary> 151 + /// Returns a trivial partial application of the call implementation (call\perform(?)) 152 + /// </summary> 153 + /// <param name="context">The macro context in which to create the AST node.</param> 154 + /// <returns>A trivial partial application of the call implementation.</returns> 123 155 protected virtual AstGetSetSymbol GetTrivialPartialApplication(MacroContext context) 124 156 { 125 157 var cp = new AstGetSetSymbol(context.Invocation.File, context.Invocation.Line, ··· 130 162 return cp; 131 163 } 132 164 165 + /// <summary> 166 + /// Provides access to the call arguments, including the call target and any other 167 + /// parameters (like the member id for call\member). 168 + /// </summary> 169 + /// <param name="context">The context from which to derive the arguments.</param> 170 + /// <returns>The arguments to the call invocation.</returns> 133 171 protected virtual IEnumerable<IAstExpression> GetCallArguments(MacroContext context) 134 172 { 135 173 return context.Invocation.Arguments; 136 174 } 137 175 176 + /// <summary> 177 + /// Determines the number of arguments that need to be protected when passed to call\star. 178 + /// </summary> 179 + /// <param name="context"></param> 180 + /// <returns></returns> 181 + /// <remarks> 182 + /// <para>For call and call\async, for instance, two arguments need to be passed to call\star 183 + /// unprocessed: the reference to the call implementation (<c>call(?)</c> or <c>call\async(?)</c>) 184 + /// and the call target.</para> 185 + /// <para>In the case of <c>call\member</c>, however, there is an additional argument to be 186 + /// protected: the member id.</para></remarks> 138 187 protected virtual int GetPassThroughArguments(MacroContext context) 139 188 { 140 189 return 2;
+2 -1
Prexonite/PVariable.cs
··· 125 125 throw new ArgumentNullException("name"); 126 126 if (name.Length == 0) 127 127 throw new ArgumentException("name is expected to contain at least one character."); 128 - Meta[Application.NameKey] = name; 128 + _meta = new MetaTable(); 129 + _meta[Application.NameKey] = name; 129 130 } 130 131 131 132 #region IIndirectCall Members
+5 -7
Prx/psr/queue.pxs
··· 51 51 return create_queue(all << skip(1) << lst); 52 52 } 53 53 54 + function GetEnumerator = lst.GetEnumerator; 55 + 54 56 function ToString this = "queue $lst"; 55 57 56 58 return struct; ··· 83 85 84 86 function GetEnumerator 85 87 { 86 - coroutine dq'ing_sequence 87 - { 88 - var z; 89 - while(q.count > 0) 90 - yield dequeue; 91 - } 92 - return dq'ing_sequence.GetEnumerator; 88 + return q.GetEnumerator; 93 89 } 90 + 91 + function snapshot = q; 94 92 95 93 return struct; 96 94 }