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.

Remove AstGetSetSymbol, AstMacroInvocation, AstGetSetReference in favour of AstIndirectCall, AstReference and AstExpand.

Christian Klauser (Feb 10, 2013, 3:01 PM +0100) f302961c 82333d9b

+477 -1451
+10 -10
Prexonite/Compiler/AST/AstFactoryBase.cs
··· 359 359 private AstExpr _resolveImplementation(ISourcePosition position, Func<AstGetSet, AstExpr> impl, string id) 360 360 { 361 361 Symbol operatorSymbol; 362 - CurrentBlock.Symbols.TryGet(id, out operatorSymbol); 363 - var expr = ExprFor(position, operatorSymbol); 362 + var expr = CurrentBlock.Symbols.TryGet(id, out operatorSymbol) 363 + ? ExprFor(position, operatorSymbol) 364 + : new AstUnresolved(position, id); 364 365 var call = expr as AstGetSet; 365 366 if(call == null) 366 367 ReportMessage(Message.Error(string.Format(Resources.AstFactoryBase__resolveImplementation_LValueExpected, id),position, MessageClasses.LValueExpected)); ··· 418 419 // Create "not ?" 419 420 var notId = OperatorNames.Prexonite.GetName(UnaryOperator.LogicalNot); 420 421 Symbol notSymbol; 421 - CurrentBlock.Symbols.TryGet(notId, out notSymbol); 422 - var notOp = ExprFor(position, notSymbol); 422 + var notOp = CurrentBlock.Symbols.TryGet(notId, out notSymbol) 423 + ? ExprFor(position, notSymbol) 424 + : new AstUnresolved(position, notId); 423 425 var notCall = notOp as AstGetSet; 424 426 if (notCall == null) 425 427 { ··· 452 454 var id = OperatorNames.Prexonite.GetName(op); 453 455 Symbol symbol; 454 456 CurrentBlock.Symbols.TryGet(id, out symbol); 455 - var callExpr = ExprFor(position, symbol); 457 + var callExpr = CurrentBlock.Symbols.TryGet(id, out symbol) 458 + ? ExprFor(position, symbol) 459 + : new AstUnresolved(position, id); 456 460 var callLValue = callExpr as AstGetSet; 457 461 if (callLValue == null) 458 462 { ··· 470 474 case UnaryOperator.PostIncrement: 471 475 case UnaryOperator.PostDecrement: 472 476 { 473 - var legacySymbol = operand as AstGetSetSymbol; 474 - 475 477 var symbolCall = operand as AstIndirectCall; 476 478 var symbol = symbolCall == null ? null : symbolCall.Subject as AstReference; 477 479 EntityRef.Variable variableRef; 478 480 var complex = operand as AstGetSet; 479 481 480 - var isLegacyVariable = legacySymbol != null && legacySymbol.IsObjectVariable; 481 482 var isVariable = symbol != null && symbol.Entity.TryGetVariable(out variableRef); 482 483 483 484 var isAssignable = complex != null; ··· 485 486 var isIncrement = op == UnaryOperator.PostIncrement || 486 487 op == UnaryOperator.PreIncrement; 487 488 488 - 489 - if (isLegacyVariable || isVariable) 489 + if (isVariable) 490 490 { 491 491 return new AstUnaryOperator(position, op,operand); 492 492 }
-201
Prexonite/Compiler/AST/AstGetSetReference.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2011, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - 27 - using System; 28 - using System.Collections.Generic; 29 - using Prexonite.Compiler.Macro.Commands; 30 - using Prexonite.Properties; 31 - using Prexonite.Types; 32 - 33 - namespace Prexonite.Compiler.Ast 34 - { 35 - public class AstGetSetReference : AstGetSetSymbol 36 - { 37 - public AstGetSetReference(string file, int line, int column, PCall call, SymbolEntry implementation) 38 - : base(file, line, column, call, implementation) 39 - { 40 - } 41 - 42 - public AstGetSetReference(string file, int line, int column, SymbolEntry implementation) 43 - : base(file, line, column, PCall.Get, implementation) 44 - { 45 - } 46 - 47 - internal AstGetSetReference(Parser p, PCall call, SymbolEntry implementation) 48 - : base(p.scanner.File, p.t.line, p.t.col, call, implementation) 49 - { 50 - } 51 - 52 - internal AstGetSetReference(Parser p, SymbolEntry implementation) 53 - : base(p, PCall.Get, implementation) 54 - { 55 - } 56 - 57 - protected override void EmitGetCode(CompilerTarget target, StackSemantics stackSemantics) 58 - { 59 - var justEffect = stackSemantics == StackSemantics.Effect; 60 - if (justEffect) 61 - return; 62 - switch (Implementation.Interpretation) 63 - { 64 - case SymbolInterpretations.Command: 65 - target.Emit(Position,OpCode.ldr_cmd, Implementation.InternalId); 66 - break; 67 - case SymbolInterpretations.Function: 68 - PFunction func; 69 - //Check if the function is a macro (Cannot create references to macros) 70 - if(target.Loader.ParentApplication.TryGetFunction(Implementation.InternalId, Implementation.Module, out func) 71 - && func.IsMacro) 72 - { 73 - target.Loader.ReportMessage(Message.Create(MessageSeverity.Warning, 74 - string.Format( 75 - "Reference to macro {0} detected. Prexonite version {1} treats this " + 76 - "as a partial application. This behavior might change in the future. " + 77 - "Use partial application syntax explicitly {0}(?) or use the {2} command " + 78 - "to obtain a reference to the macro.", 79 - Implementation, Engine.PrexoniteVersion, 80 - Reference.Alias), Position, 81 - MessageClasses.ReferenceToMacro)); 82 - 83 - _emitAsPartialApplication(target); 84 - } 85 - else 86 - { 87 - target.Emit(Position,OpCode.ldr_func, Implementation.InternalId, target.ToInternalModule(Implementation.Module)); 88 - } 89 - break; 90 - case SymbolInterpretations.GlobalObjectVariable: 91 - target.Emit(Position,OpCode.ldr_glob, Implementation.InternalId, target.ToInternalModule(Implementation.Module)); 92 - break; 93 - case SymbolInterpretations.GlobalReferenceVariable: 94 - target.EmitLoadGlobal(Position, Implementation.InternalId, Implementation.Module); 95 - break; 96 - case SymbolInterpretations.LocalObjectVariable: 97 - target.Emit(Position,OpCode.ldr_loc, Implementation.InternalId); 98 - break; 99 - case SymbolInterpretations.LocalReferenceVariable: 100 - target.Emit(Position,OpCode.ldloc, Implementation.InternalId); 101 - break; 102 - case SymbolInterpretations.MacroCommand: 103 - target.Loader.ReportMessage(Message.Create(MessageSeverity.Warning, 104 - string.Format( 105 - Resources.AstGetSetReference_ReferenceToMacroTreatedAsPartialApplication, 106 - Implementation.InternalId, Engine.PrexoniteVersion, Reference.Alias), Position, MessageClasses.ReferenceToMacro)); 107 - 108 - _emitAsPartialApplication(target); 109 - 110 - break; 111 - default: 112 - target.Loader.ReportMessage( 113 - Message.Create( 114 - MessageSeverity.Error, 115 - string.Format( 116 - Resources.AstGetSetReference_CannotCreateReference, 117 - Enum.GetName( 118 - typeof (SymbolInterpretations), Implementation.Interpretation), 119 - Implementation.InternalId), Position, MessageClasses.InvalidReference)); 120 - target.EmitNull(Position); 121 - break; 122 - } 123 - } 124 - 125 - private void _emitAsPartialApplication(CompilerTarget target) 126 - { 127 - var pa = new AstMacroInvocation(File, Line, Column, Implementation) {Call = Call}; 128 - pa.Arguments.Add(new AstPlaceholder(File, Line, Column, 0)); 129 - var ipa = (AstExpr) pa; 130 - _OptimizeNode(target, ref ipa); 131 - ipa.EmitValueCode(target); 132 - } 133 - 134 - //"Assigning to a reference" 135 - protected override void EmitSetCode(CompilerTarget target) 136 - { 137 - switch (Implementation.Interpretation) 138 - { 139 - case SymbolInterpretations.Command: 140 - case SymbolInterpretations.Function: 141 - case SymbolInterpretations.JumpLabel: 142 - case SymbolInterpretations.KnownType: 143 - throw new PrexoniteException( 144 - // ReSharper disable PossibleNullReferenceException 145 - string.Format(Resources.AstGetSetReference_CannotAssignReference, (Enum.GetName(typeof(SymbolInterpretations), Implementation.Interpretation) ?? Enum.GetName(typeof(SymbolInterpretations),SymbolInterpretations.Undefined)).ToLower())); 146 - // ReSharper restore PossibleNullReferenceException 147 - 148 - //Variables are not automatically dereferenced 149 - case SymbolInterpretations.GlobalObjectVariable: 150 - case SymbolInterpretations.GlobalReferenceVariable: 151 - target.EmitStoreGlobal(Position, Implementation.InternalId, Implementation.Module); 152 - break; 153 - case SymbolInterpretations.LocalObjectVariable: 154 - case SymbolInterpretations.LocalReferenceVariable: 155 - target.EmitStoreLocal(Position, Implementation.InternalId); 156 - break; 157 - } 158 - } 159 - 160 - #region ICanBeReferenced Members 161 - 162 - public override bool TryToReference(out AstExpr reference) 163 - { 164 - reference = null; 165 - switch (Implementation.Interpretation) 166 - { 167 - case SymbolInterpretations.Command: 168 - case SymbolInterpretations.Function: 169 - case SymbolInterpretations.JumpLabel: 170 - case SymbolInterpretations.KnownType: 171 - case SymbolInterpretations.GlobalObjectVariable: 172 - case SymbolInterpretations.LocalObjectVariable: 173 - return false; 174 - 175 - //Variables are not automatically dereferenced 176 - 177 - case SymbolInterpretations.GlobalReferenceVariable: 178 - reference = 179 - new AstGetSetReference( 180 - File, 181 - Line, 182 - Column, 183 - PCall.Get, Implementation.With(SymbolInterpretations.GlobalObjectVariable)); 184 - break; 185 - 186 - case SymbolInterpretations.LocalReferenceVariable: 187 - reference = 188 - new AstGetSetReference( 189 - File, 190 - Line, 191 - Column, 192 - PCall.Get, Implementation.With(SymbolInterpretations.LocalObjectVariable)); 193 - break; 194 - } 195 - 196 - return reference != null; 197 - } 198 - 199 - #endregion 200 - } 201 - }
-210
Prexonite/Compiler/AST/AstGetSetSymbol.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2011, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - 27 - using System; 28 - using System.Collections.Generic; 29 - using System.Diagnostics; 30 - using Prexonite.Types; 31 - 32 - namespace Prexonite.Compiler.Ast 33 - { 34 - public class AstGetSetSymbol : AstGetSet, IAstPartiallyApplicable 35 - { 36 - public SymbolEntry Implementation { get; set; } 37 - 38 - public AstGetSetSymbol( 39 - string file, 40 - int line, 41 - int column, 42 - PCall call, 43 - SymbolEntry symbol) 44 - : base(file, line, column, call) 45 - { 46 - if (symbol == null) 47 - throw new ArgumentNullException("symbol"); 48 - 49 - Implementation = symbol; 50 - } 51 - 52 - public AstGetSetSymbol(string file, int line, int column, SymbolEntry symbol) 53 - : this(file, line, column, PCall.Get, symbol) 54 - { 55 - } 56 - 57 - internal AstGetSetSymbol(Parser p, PCall call, SymbolEntry symbol) 58 - : this(p.scanner.File, p.t.line, p.t.col, call, symbol) 59 - { 60 - } 61 - 62 - internal AstGetSetSymbol(Parser p, SymbolEntry symbol) 63 - : this(p, PCall.Get, symbol) 64 - { 65 - } 66 - 67 - protected override void EmitGetCode(CompilerTarget target, StackSemantics stackSemantics) 68 - { 69 - var justEffect = stackSemantics == StackSemantics.Effect; 70 - switch (Implementation.Interpretation) 71 - { 72 - case SymbolInterpretations.Command: 73 - target.EmitCommandCall(Position, Arguments.Count, Implementation.InternalId, justEffect); 74 - break; 75 - case SymbolInterpretations.Function: 76 - target.EmitFunctionCall(Position, Arguments.Count, Implementation.InternalId, Implementation.Module, justEffect); 77 - break; 78 - case SymbolInterpretations.GlobalObjectVariable: 79 - if (!justEffect) 80 - target.EmitLoadGlobal(Position, Implementation.InternalId, Implementation.Module); 81 - break; 82 - case SymbolInterpretations.LocalObjectVariable: 83 - if (!justEffect) 84 - target.EmitLoadLocal(Position, Implementation.InternalId); 85 - break; 86 - case SymbolInterpretations.LocalReferenceVariable: 87 - target.Emit(Position,Instruction.CreateLocalIndirectCall(Arguments.Count, Implementation.InternalId, justEffect)); 88 - break; 89 - case SymbolInterpretations.GlobalReferenceVariable: 90 - target.Emit(Position,Instruction.CreateGlobalIndirectCall(Arguments.Count, Implementation.InternalId, target.ToInternalModule(Implementation.Module), justEffect)); 91 - break; 92 - default: 93 - throw new PrexoniteException( 94 - "Invalid self " + 95 - Enum.GetName(typeof (SymbolInterpretations), Implementation.Interpretation) + 96 - " in AST."); 97 - } 98 - } 99 - 100 - protected override void EmitSetCode(CompilerTarget target) 101 - { 102 - const bool justEffect = true; 103 - 104 - switch (Implementation.Interpretation) 105 - { 106 - case SymbolInterpretations.Command: 107 - target.EmitCommandCall(Position, Arguments.Count, Implementation.InternalId, justEffect); 108 - break; 109 - case SymbolInterpretations.Function: 110 - target.EmitFunctionCall(Position, Arguments.Count, Implementation.InternalId, Implementation.Module, justEffect); 111 - break; 112 - case SymbolInterpretations.GlobalObjectVariable: 113 - target.EmitStoreGlobal(Position, Implementation.InternalId, Implementation.Module); 114 - break; 115 - case SymbolInterpretations.LocalReferenceVariable: 116 - target.Emit(Position,Instruction.CreateLocalIndirectCall(Arguments.Count, Implementation.InternalId, justEffect)); 117 - break; 118 - case SymbolInterpretations.GlobalReferenceVariable: 119 - target.Emit(Position,Instruction.CreateGlobalIndirectCall(Arguments.Count, Implementation.InternalId, target.ToInternalModule(Implementation.Module), justEffect)); 120 - break; 121 - case SymbolInterpretations.LocalObjectVariable: 122 - target.EmitStoreLocal(Position, Implementation.InternalId); 123 - break; 124 - default: 125 - throw new PrexoniteException( 126 - string.Format("Invalid self {0} in AST.", Implementation)); 127 - } 128 - } 129 - 130 - public bool IsObjectVariable 131 - { 132 - get 133 - { 134 - return 135 - Implementation.Interpretation == SymbolInterpretations.GlobalObjectVariable || 136 - Implementation.Interpretation == SymbolInterpretations.LocalObjectVariable; 137 - } 138 - } 139 - 140 - public bool IsVariable 141 - { 142 - get 143 - { 144 - return 145 - Implementation.Interpretation == SymbolInterpretations.GlobalObjectVariable || 146 - Implementation.Interpretation == SymbolInterpretations.GlobalReferenceVariable || 147 - Implementation.Interpretation == SymbolInterpretations.LocalObjectVariable || 148 - Implementation.Interpretation == SymbolInterpretations.LocalReferenceVariable; 149 - } 150 - } 151 - 152 - public override AstGetSet GetCopy() 153 - { 154 - AstGetSet copy = new AstGetSetSymbol(File, Line, Column, Call, Implementation); 155 - CopyBaseMembers(copy); 156 - return copy; 157 - } 158 - 159 - public override string ToString() 160 - { 161 - return 162 - base.ToString() + 163 - String.Format( 164 - " {0}-{1} {2}{3}", 165 - Enum.GetName(typeof (SymbolInterpretations), Implementation.Interpretation), 166 - Implementation.InternalId, 167 - ArgumentsToString(), Implementation.Module == null ? "" : (" from " + Implementation.Module)); 168 - } 169 - 170 - #region ICanBeReferenced Members 171 - 172 - public virtual bool TryToReference(out AstExpr result) 173 - { 174 - result = null; 175 - switch (Implementation.Interpretation) 176 - { 177 - case SymbolInterpretations.Function: 178 - case SymbolInterpretations.GlobalObjectVariable: 179 - case SymbolInterpretations.LocalObjectVariable: 180 - case SymbolInterpretations.LocalReferenceVariable: 181 - case SymbolInterpretations.GlobalReferenceVariable: 182 - case SymbolInterpretations.Command: 183 - result = 184 - new AstGetSetReference(File, Line, Column, PCall.Get, Implementation); 185 - break; 186 - } 187 - 188 - return result != null; 189 - } 190 - 191 - #endregion 192 - 193 - #region Implementation of IAstPartiallyApplicable 194 - 195 - public void DoEmitPartialApplicationCode(CompilerTarget target) 196 - { 197 - AstExpr refNode; 198 - if (!TryToReference(out refNode)) 199 - throw new PrexoniteException("Cannot partially apply " + this + 200 - " because it can't be converted to a reference."); 201 - 202 - var indTemplate = new AstIndirectCall(File, Line, Column, Call, refNode); 203 - indTemplate.Arguments.AddRange(Arguments); 204 - Debug.Assert(indTemplate.CheckForPlaceholders()); 205 - indTemplate.EmitValueCode(target); 206 - } 207 - 208 - #endregion 209 - } 210 - }
-15
Prexonite/Compiler/AST/AstIndirectCall.cs
··· 258 258 base.TryOptimize(target, out expr); 259 259 _OptimizeNode(target, ref Subject); 260 260 261 - //Try to replace { ldloc var ; indarg.x } by { indloc.x var } (same for glob) 262 - var symbol = Subject as AstGetSetSymbol; 263 - if (symbol != null && symbol.IsObjectVariable) 264 - { 265 - var kind = 266 - symbol.Implementation.Interpretation == SymbolInterpretations.GlobalObjectVariable 267 - ? SymbolInterpretations.GlobalReferenceVariable 268 - : SymbolInterpretations.LocalReferenceVariable; 269 - var refcall = 270 - new AstGetSetSymbol(File, Line, Column, Call, symbol.Implementation.With(kind)); 271 - refcall.Arguments.AddRange(Arguments); 272 - expr = refcall; 273 - return true; 274 - } 275 - 276 261 expr = null; 277 262 return false; 278 263 }
-112
Prexonite/Compiler/AST/AstMacroInvocation.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2011, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - 27 - using System; 28 - using System.Diagnostics; 29 - using Prexonite.Compiler.Macro; 30 - using Prexonite.Types; 31 - 32 - namespace Prexonite.Compiler.Ast 33 - { 34 - public sealed class AstMacroInvocation : AstGetSet 35 - { 36 - private readonly SymbolEntry _implementation; 37 - 38 - public AstMacroInvocation(string file, int line, int column, SymbolEntry implementation) : base(file, line, column, PCall.Get) 39 - { 40 - if (implementation == null) 41 - throw new ArgumentNullException("implementation"); 42 - _implementation = implementation; 43 - } 44 - 45 - internal AstMacroInvocation(Parser p, SymbolEntry implementation) 46 - : base(p, PCall.Get) 47 - { 48 - _implementation = implementation; 49 - } 50 - 51 - public SymbolEntry Implementation 52 - { 53 - get { return _implementation; } 54 - } 55 - 56 - protected override void EmitGetCode(CompilerTarget target, StackSemantics stackSemantics) 57 - { 58 - throw new NotSupportedException( 59 - "Macro invocation requires a different mechanic. Use AstGetSet.EmitCode instead."); 60 - } 61 - 62 - protected override void EmitSetCode(CompilerTarget target) 63 - { 64 - throw new NotSupportedException( 65 - "Macro invocation requires a different mechanic. Use AstGetSet.EmitCode instead."); 66 - } 67 - 68 - protected override void DoEmitCode(CompilerTarget target, StackSemantics stackSemantics) 69 - { 70 - //instantiate macro for the current target 71 - MacroSession session = null; 72 - 73 - try 74 - { 75 - //Acquire current macro session 76 - session = target.AcquireMacroSession(); 77 - 78 - //Expand macro 79 - var justEffect = stackSemantics == StackSemantics.Effect; 80 - var node = session.ExpandMacro(this, justEffect); 81 - 82 - //Emit generated code 83 - node.EmitCode(target, stackSemantics); 84 - } 85 - finally 86 - { 87 - if (session != null) 88 - target.ReleaseMacroSession(session); 89 - } 90 - } 91 - 92 - public override bool TryOptimize(CompilerTarget target, out AstExpr expr) 93 - { 94 - //Do not optimize the macros arguments! They should be passed to the macro in their original form. 95 - // the macro should decide whether or not to apply AST-optimization to the arguments or not. 96 - expr = null; 97 - return false; 98 - } 99 - 100 - public override AstGetSet GetCopy() 101 - { 102 - var macro = new AstMacroInvocation(File, Line, Column, Implementation); 103 - CopyBaseMembers(macro); 104 - return macro; 105 - } 106 - 107 - public override string ToString() 108 - { 109 - return string.Format("{0} {1}{2}", base.ToString(), Implementation, ArgumentsToString()); 110 - } 111 - } 112 - }
+2 -31
Prexonite/Compiler/AST/AstReturn.cs
··· 124 124 { 125 125 if (_optimizeConditionalReturnExpression(target)) 126 126 return; 127 - 128 - var symbol = Expression as AstGetSetSymbol; 129 127 var indirectCall = Expression as AstIndirectCall; 130 128 131 - AstExpr reference; 132 - if ( symbol != null 133 - && !symbol.IsObjectVariable 134 - && symbol.TryToReference(out reference) 135 - && _isStacklessRecursionPossible(target, symbol)) 129 + if (indirectCall != null 130 + && _isStacklessRecursionPossible(target, indirectCall)) 136 131 { 137 132 // specialized approach 138 133 // self(arg1, arg2, ..., argn) => { param1 = arg1; param2 = arg2; ... paramn = argn; goto 0; } 139 - _emitRecursiveTailCall(target, symbol.Arguments); 140 - } 141 - else if (indirectCall != null 142 - && _isStacklessRecursionPossible(target, indirectCall)) 143 - { 144 134 _emitRecursiveTailCall(target, indirectCall.Arguments); 145 135 } 146 136 else ··· 176 166 { 177 167 Expression.EmitValueCode(target); 178 168 target.Emit(Position, OpCode.ret_value); 179 - } 180 - 181 - private static bool _isStacklessRecursionPossible(CompilerTarget target, 182 - AstGetSetSymbol symbol) 183 - { 184 - if (symbol.Implementation.Interpretation != SymbolInterpretations.Function) //must be function call 185 - return false; 186 - if(symbol.Implementation.Module != target.Loader.ParentApplication.Module.Name) //must be direct recursive iteration 187 - return false; 188 - if (!Engine.StringsAreEqual(target.Function.Id, symbol.Implementation.InternalId)) 189 - //must be direct recursive iteration 190 - return false; 191 - if (target.Function.Variables.Contains(PFunction.ArgumentListId)) 192 - //must not use argument list 193 - return false; 194 - if (symbol.Arguments.Count > target.Function.Parameters.Count) 195 - //must not supply more arguments than mapped 196 - return false; 197 - return true; 198 169 } 199 170 200 171 private static bool _isStacklessRecursionPossible(CompilerTarget target,
+1 -36
Prexonite/Compiler/AST/AstUnaryOperator.cs
··· 29 29 using JetBrains.Annotations; 30 30 using Prexonite.Modular; 31 31 using Prexonite.Properties; 32 - using Prexonite.Types; 33 32 34 33 namespace Prexonite.Compiler.Ast 35 34 { ··· 143 142 144 143 private void _emitIncrementDecrementCode(CompilerTarget target, StackSemantics value) 145 144 { 146 - var legacySymbol = _operand as AstGetSetSymbol; 147 - var isLegacyVariable = legacySymbol != null && legacySymbol.IsObjectVariable; 148 145 var symbolCall = _operand as AstIndirectCall; 149 146 var symbol = symbolCall == null ? null : symbolCall.Subject as AstReference; 150 147 EntityRef.Variable variableRef = null; 151 148 var isVariable = symbol != null && symbol.Entity.TryGetVariable(out variableRef); 152 - var complex = _operand as AstGetSet; 153 - var isAssignable = complex != null; 154 149 var isPre = _operator == UnaryOperator.PreDecrement || _operator == UnaryOperator.PreIncrement; 155 150 switch (_operator) 156 151 { ··· 161 156 var isIncrement = 162 157 _operator == UnaryOperator.PostIncrement || 163 158 _operator == UnaryOperator.PreIncrement; 164 - if (isLegacyVariable) //The easy way 165 - { 166 - var isGlobal = legacySymbol.Implementation.Interpretation == SymbolInterpretations.GlobalObjectVariable; 167 - var sym = legacySymbol.Implementation; 168 - 169 - if(!isPre && value == StackSemantics.Value) 170 - { 171 - if (isGlobal) 172 - target.EmitLoadGlobal(Position, sym.InternalId, sym.Module); 173 - else 174 - target.EmitLoadLocal(Position, sym.InternalId); 175 - } 176 - 177 - OpCode opc; 178 - 179 - if (isIncrement) 180 - opc = isGlobal ? OpCode.incglob : OpCode.incloc; 181 - else 182 - opc = isGlobal ? OpCode.decglob : OpCode.decloc; 183 - 184 - target.Emit(Position,opc, legacySymbol.Implementation.InternalId, target.ToInternalModule(legacySymbol.Implementation.Module)); 185 - 186 - if (isPre && value == StackSemantics.Value) 187 - { 188 - if (isGlobal) 189 - target.EmitLoadGlobal(Position, sym.InternalId, sym.Module); 190 - else 191 - target.EmitLoadLocal(Position, sym.InternalId); 192 - } 193 - } 194 - else if (isVariable) 159 + if (isVariable) 195 160 { 196 161 Debug.Assert(variableRef != null); 197 162 EntityRef.Variable.Local localRef;
+9 -7
Prexonite/Compiler/AST/AstUnresolved.cs
··· 43 43 _id = id; 44 44 } 45 45 46 + public AstUnresolved(ISourcePosition position, string id) : base(position,PCall.Get) 47 + { 48 + if (id == null) 49 + throw new ArgumentNullException("id"); 50 + 51 + _id = id; 52 + } 53 + 46 54 #region Overrides of AstGetSet 47 55 48 56 protected override void EmitGetCode(CompilerTarget target, StackSemantics stackSemantics) ··· 58 66 MessageClasses.SymbolNotResolved)); 59 67 } 60 68 61 - private string _id; 69 + private readonly string _id; 62 70 63 71 public string Id 64 72 { 65 73 get { return _id; } 66 - set 67 - { 68 - if (value == null) 69 - throw new ArgumentNullException("value"); 70 - _id = value; 71 - } 72 74 } 73 75 74 76 protected override void EmitSetCode(CompilerTarget target)
+2 -1
Prexonite/Compiler/AST/IAstFactory.cs
··· 124 124 /// <para><see cref="ExprFor"/> reports all messages generated by the use of the symbol (errors, warnings, etc.)</para> 125 125 /// <para> 126 126 /// The parameter <paramref name="symbol"/> can be null, indicating that the symbol was not found in the first place. 127 - /// In that case, a corresponding "Symbol not found" message is automatically generated and a default node returned. 127 + /// <see cref="ExprFor"/> does <em>not</em> treat this as an error. 128 + /// The caller must make sure that a corresponding error message has been emitted. 128 129 /// </para> 129 130 /// </remarks> 130 131 /// <returns>An expression that implements a usage of the supplied <paramref name="symbol"/>. Never null.</returns>
+18 -16
Prexonite/Compiler/DebugHook.cs
··· 26 26 27 27 using System; 28 28 using System.Collections.Generic; 29 + using JetBrains.Annotations; 29 30 using Prexonite.Commands.Core; 30 31 using Prexonite.Compiler.Ast; 31 32 using Prexonite.Modular; 32 - using Prexonite.Types; 33 33 using Prexonite.Compiler.Internal; 34 34 35 35 namespace Prexonite.Compiler ··· 37 37 /// <summary> 38 38 /// Implementation of a compiler hook that optimizes the using of the <see cref = "Debug" /> command. 39 39 /// </summary> 40 + [PublicAPI] 40 41 public static class DebugHook 41 42 { 42 43 /// <summary> ··· 61 62 /// Installs the hook in the supplied <see cref = "Loader" />. 62 63 /// </summary> 63 64 /// <param name = "ldr">The loader.</param> 65 + [PublicAPI] 64 66 public static void InstallHook(Loader ldr) 65 67 { 66 68 if (ldr == null) ··· 72 74 /// Uninstalls the hook in the supplied <see cref = "Loader" />. 73 75 /// </summary> 74 76 /// <param name = "ldr">The loader.</param> 77 + [PublicAPI] 75 78 public static void UninstallHook(Loader ldr) 76 79 { 77 80 if (ldr == null) ··· 97 100 for (var i = 0; i < block.Count; i++) 98 101 { 99 102 var stmt = block[i] as AstGetSet; 100 - var legacySymbol = stmt as AstGetSetSymbol; 101 103 //look for calls 102 - if (_isLegacyDebugCall(legacySymbol) || _isDebugCall(stmt)) 104 + if (_isDebugCall(stmt)) 103 105 { 104 106 System.Diagnostics.Debug.Assert(stmt != null); 105 107 //Found a call to debug ··· 108 110 { 109 111 for (var j = 0; j < stmt.Arguments.Count; j++) 110 112 { 111 - var arg = stmt.Arguments[j] as AstGetSetSymbol; 112 - if (arg != null) 113 + var arg = stmt.Arguments[j] as AstIndirectCall; 114 + AstReference refNode; 115 + if (arg != null && (refNode = arg.Subject as AstReference) != null) 113 116 { 114 117 var printlnCall = t.Factory.Call(stmt.Position, 115 118 EntityRef.Command.Create(Engine.PrintLineAlias)); ··· 120 123 stmt.File, 121 124 stmt.Line, 122 125 stmt.Column, 123 - String.Concat("DEBUG ", arg.Implementation.InternalId, " = ")); 126 + String.Concat("DEBUG ", refNode.Entity, " = ")); 124 127 concatCall.Arguments.Add(consts); 125 128 concatCall.Arguments.Add(arg); 126 129 printlnCall.Arguments.Add(concatCall); ··· 139 142 //look for conditions 140 143 if (cond != null) 141 144 { 142 - var expr = cond.Condition as AstGetSetSymbol; 143 - if (expr != null && expr.Implementation.Interpretation == SymbolInterpretations.Command && 144 - Engine.StringsAreEqual(expr.Implementation.InternalId, Engine.DebugAlias)) 145 + var expr = cond.Condition as AstIndirectCall; 146 + AstReference refNode; 147 + EntityRef.Command cmd; 148 + if (expr != null 149 + && (refNode = expr.Subject as AstReference) != null 150 + && refNode.Entity.TryGetCommand(out cmd) 151 + && Engine.StringsAreEqual(cmd.Id,Engine.DebugAlias) ) 145 152 cond.Condition = 146 153 new AstConstant(expr.File, expr.Line, expr.Column, debugging); 147 154 } ··· 154 161 } //end for statements 155 162 } 156 163 157 - private static bool _isDebugCall(AstGetSet stmt) 164 + [ContractAnnotation("=>true,stmt:notnull;=>false,stmt:canbenull")] 165 + private static bool _isDebugCall([CanBeNull] AstGetSet stmt) 158 166 { 159 167 EntityRef entityRef; 160 168 EntityRef.Command cmdRef; 161 169 return stmt.TryMatchCall(out entityRef) && entityRef.TryGetCommand(out cmdRef) && Engine.StringsAreEqual(cmdRef.Id,Engine.DebugAlias); 162 - } 163 - 164 - private static bool _isLegacyDebugCall(AstGetSetSymbol legacySymbol) 165 - { 166 - return legacySymbol != null && legacySymbol.Implementation.Interpretation == SymbolInterpretations.Command && 167 - Engine.StringsAreEqual(legacySymbol.Implementation.InternalId, Engine.DebugAlias); 168 170 } 169 171 } 170 172 }
+3 -2
Prexonite/Compiler/Grammar/Parser.Statement.atg
··· 299 299 .) 300 300 = (. position = GetPosition(); .) 301 301 Id<out id> (. Symbol sym; 302 - Symbols.TryGet(id, out sym); 303 - var expr = Create.ExprFor(position,sym); 302 + var expr = Symbols.TryGet(id, out sym) 303 + ? Create.ExprFor(position, sym) 304 + : new AstUnresolved(position, id); 304 305 complex = expr as AstGetSet; 305 306 if(complex == null) 306 307 {
+13 -8
Prexonite/Compiler/Internal/SymbolMExprParser.cs
··· 9 9 { 10 10 public static class SymbolMExprParser 11 11 { 12 + private const string HerePositionHead = "here"; 13 + 12 14 [NotNull] 13 15 public static Symbol Parse([NotNull] ISymbolView<Symbol> symbols, [NotNull] MExpr expr) 14 16 { ··· 49 51 { 50 52 return _parseMessage(MessageSeverity.Info, symbols, expr, elements); 51 53 } 52 - else if(expr.TryMatchHead(SymbolMExprSerializer.ExpandHead,out innerSymbolExpr)) 54 + else if (expr.TryMatchHead(SymbolMExprSerializer.ExpandHead, out innerSymbolExpr)) 53 55 { 54 56 innerSymbol = Parse(symbols, innerSymbolExpr); 55 57 return Symbol.CreateExpand(innerSymbol, expr.Position); ··· 61 63 else 62 64 { 63 65 // must be a reference 64 - return Symbol.CreateReference(EntityRefMExprParser.Parse(expr),expr.Position); 66 + return Symbol.CreateReference(EntityRefMExprParser.Parse(expr), expr.Position); 65 67 } 66 68 } 67 69 ··· 78 80 string messageText; 79 81 if (elements[1].TryMatchAtom(out rawMessageClass) && elements[2].TryMatchStringAtom(out messageText)) 80 82 { 81 - return 82 - Symbol.CreateMessage( 83 - Message.Create(severity, messageText, position, 84 - (rawMessageClass == null ? null : rawMessageClass.ToString())), 85 - Parse(symbols, elements[3]), expr.Position); 83 + var message = Message.Create(severity, messageText, position, 84 + (rawMessageClass == null ? null : rawMessageClass.ToString())); 85 + return Symbol.CreateMessage(message, Parse(symbols, elements[3]), expr.Position); 86 86 } 87 87 else 88 88 { ··· 101 101 string file; 102 102 int line; 103 103 int column; 104 + List<MExpr> hereArgs; 104 105 if (expr.TryMatchHead(SymbolMExprSerializer.SourcePositionHead, out fileExpr, out lineExpr, 105 106 out columnExpr) 106 107 && fileExpr.TryMatchStringAtom(out file) 107 108 && lineExpr.TryMatchIntAtom(out line) 108 109 && columnExpr.TryMatchIntAtom(out column)) 109 110 { 110 - return new SourcePosition(file,line,column); 111 + return new SourcePosition(file, line, column); 112 + } 113 + else if(expr.TryMatchHead(HerePositionHead, out hereArgs)) 114 + { 115 + return expr.Position; 111 116 } 112 117 else 113 118 {
+2 -2
Prexonite/Compiler/Lexer.cs
··· 1 - /* The following code was generated by CSFlex 1.4 on 27/01/2013 */ 1 + /* The following code was generated by CSFlex 1.4 on 10/02/2013 */ 2 2 3 3 #line 1 "Prexonite.lex" 4 4 /* ··· 41 41 /** 42 42 * This class is a scanner generated by <a href="http://www.sourceforge.net/projects/csflex/">C# Flex</a>, based on 43 43 * <a href="http://www.jflex.de/">JFlex</a>, version 1.4 44 - * on 27/01/2013 from the specification file 44 + * on 10/02/2013 from the specification file 45 45 * <tt>Prexonite.lex</tt> 46 46 */ 47 47 class Lexer: IScanner {
+1 -39
Prexonite/Compiler/Macro/Commands/CallMacro.cs
··· 30 30 using Prexonite.Commands; 31 31 using Prexonite.Commands.Core; 32 32 using Prexonite.Compiler.Ast; 33 - using Prexonite.Compiler.Symbolic; 34 - using Prexonite.Compiler.Symbolic.Compatibility; 35 33 using Prexonite.Modular; 36 34 using Prexonite.Properties; 37 35 using Prexonite.Types; ··· 436 434 AstExpr specProto, out PCall protoCall, out IList<AstExpr> protoArguments, 437 435 out AstExpr macroSpec) 438 436 { 439 - var proto = specProto as AstMacroInvocation; 440 437 var proto2 = specProto as AstExpand; 441 - if (proto != null) 442 - { 443 - macroSpec = _getMacroSpecExpr(context, proto); 444 - protoCall = proto.Call; 445 - protoArguments = proto.Arguments; 446 - } 447 - else if (specProto.IsPlaceholder()) 438 + if (specProto.IsPlaceholder()) 448 439 { 449 440 //As an exception, allow a placeholder here 450 441 macroSpec = specProto; ··· 466 457 return false; 467 458 } 468 459 return true; 469 - } 470 - 471 - private static AstExpr _getMacroSpecExpr(MacroContext context, 472 - AstMacroInvocation proto) 473 - { 474 - var symbolEntry = proto.Implementation; 475 - 476 - return _getMacroSpecExpr(context, proto.Position, symbolEntry); 477 - } 478 - 479 - private static AstExpr _getMacroSpecExpr(MacroContext context, ISourcePosition position, SymbolEntry symbolEntry) 480 - { 481 - //macroId: as a constant 482 - var sym = symbolEntry.ToSymbol(); 483 - DereferenceSymbol ds; 484 - ReferenceSymbol rs; 485 - ExpandSymbol es; 486 - if ((ds = sym as DereferenceSymbol) != null && (rs = ds.InnerSymbol as ReferenceSymbol) != null) 487 - { 488 - return EntityRefTo.ToExpr(context.Factory, context.Invocation.Position, rs.Entity); 489 - } 490 - else if ((es = sym as ExpandSymbol) != null && (rs = es.InnerSymbol as ReferenceSymbol) != null) 491 - { 492 - return EntityRefTo.ToExpr(context.Factory, context.Invocation.Position, rs.Entity); 493 - } 494 - else 495 - { 496 - throw new ErrorMessageException(Message.Error("Cannot convert usage of legacy macro invocation in call macro.",position, MessageClasses.CallMacroUsage)); 497 - } 498 460 } 499 461 500 462 private static AstExpr _getMacroSpecExpr(MacroContext context,
+1 -1
Prexonite/Compiler/Macro/Commands/EntityRefTo.cs
··· 45 45 context.Invocation.Position, MessageClasses.EntityRefTo)); 46 46 return; 47 47 } 48 - 48 + 49 49 var prototype = context.Invocation.Arguments[0]; 50 50 EntityRef entityRef; 51 51 AstExpand expand;
+1 -6
Prexonite/Compiler/Macro/Commands/Reference.cs
··· 145 145 return; 146 146 } 147 147 148 - var legacyPrototype = context.Invocation.Arguments[0] as AstMacroInvocation; 149 148 var prototype = context.Invocation.Arguments[0] as AstExpand; 150 - if (legacyPrototype == null && prototype == null) 149 + if (prototype == null) 151 150 { 152 151 context.ReportMessage( 153 152 Message.Error( 154 153 string.Format(Resources.Reference_requires_argument_to_be_a_prototype_of_a_macro_invocation, Alias), 155 154 context.Invocation.Position, MessageClasses.ReferenceUsage)); 156 - } 157 - else if (legacyPrototype != null) 158 - { 159 - context.Block.Expression = _assembleImplCall(context, legacyPrototype.Implementation, legacyPrototype.Position); 160 155 } 161 156 else 162 157 {
-16
Prexonite/Compiler/Macro/MacroContextExtensions.cs
··· 118 118 context.RequireOuterVariable(MacroAliases.ContextAlias); 119 119 } 120 120 121 - /// <summary> 122 - /// Creates a macro invocation node 123 - /// </summary> 124 - /// <param name = "context">The context for which to generate the AST node.</param> 125 - /// <param name = "callType">The call type (get or set)</param> 126 - /// <param name="implementation"></param> 127 - /// <param name = "args">The arguments to pass as part of teh access (optional)</param> 128 - /// <returns>A self access node.</returns> 129 - public static AstMacroInvocation CreateMacroInvocation(this MacroContext context, PCall callType, SymbolEntry implementation, params AstExpr[] args) 130 - { 131 - var m = new AstMacroInvocation(context.Invocation.File, context.Invocation.Line, 132 - context.Invocation.Column, implementation) {Call = callType}; 133 - m.Arguments.AddRange(args); 134 - return m; 135 - } 136 - 137 121 #region IAstFactory forwarded methods 138 122 139 123 public static AstTypeExpr CreateConstantType(this MacroContext context, string typeExpression)
+13 -90
Prexonite/Compiler/Macro/MacroSession.cs
··· 234 234 } 235 235 } 236 236 237 - private class LegacyMacroCommandExpander : MacroCommandExpanderBase 238 - { 239 - public override void Initialize(CompilerTarget target, AstGetSet macroNode, 240 - bool justEffect) 241 - { 242 - var invocation = (AstMacroInvocation) macroNode; 243 - 244 - MacroCommand = null; 245 - 246 - if (!target.Loader.MacroCommands.TryGetValue(invocation.Implementation.InternalId, out MacroCommand)) 247 - { 248 - target.Loader.ReportMessage(Message.Create(MessageSeverity.Error, 249 - String.Format(Resources.MacroCommandExpander_CannotFindMacro, invocation.Implementation.InternalId), 250 - invocation.Position, MessageClasses.NoSuchMacroCommand)); 251 - HumanId = "cannot_find_macro_command"; 252 - return; 253 - } 254 - 255 - HumanId = MacroCommand.Id; 256 - } 257 - } 258 - 259 237 private class MacroCommandExpander : MacroCommandExpanderBase 260 238 { 261 239 public override void Initialize(CompilerTarget target, AstGetSet macroNode, bool justEffect) ··· 342 320 * {fs} = fe 343 321 */ 344 322 var contextBlock = context.Block; 345 - var macroBlockExpr = ast as AstBlock; 346 323 var macroBlock = ast as AstBlock; 347 324 348 325 // ReSharper disable JoinDeclarationAndInitializer ··· 353 330 ce = contextBlock.Expression; 354 331 355 332 //determine fe 356 - if (macroBlockExpr != null) 357 - fe = macroBlockExpr.Expression; 333 + if (macroBlock != null) 334 + fe = macroBlock.Expression; 358 335 else if (expr != null) 359 336 { 360 337 fe = expr; ··· 481 458 } 482 459 } 483 460 484 - private class LegacyMacroFunctionExpander : MacroFunctionExpanderBase 485 - { 486 - public override void Initialize(CompilerTarget target, AstGetSet macroNode, 487 - bool justEffect) 488 - { 489 - var invocation = (AstMacroInvocation) macroNode; 490 - MacroFunction = null; 491 - 492 - PFunction macroFunc; 493 - var sourceApp = target.Loader.Options.TargetApplication; 494 - if (!sourceApp.TryGetFunction(invocation.Implementation.InternalId, invocation.Implementation.Module, out macroFunc)) 495 - { 496 - target.Loader.ReportMessage( 497 - Message.Create( 498 - MessageSeverity.Error, 499 - String.Format( 500 - Resources.MacroFunctionExpander_MacroFunctionNotAvailable, 501 - _toFunctionNameString(invocation.Implementation), 502 - target.Function.Id, target.Loader.ParentApplication.Module.Name), 503 - invocation.Position, MessageClasses.NoSuchMacroFunction)); 504 - HumanId = "could_not_resolve_macro_function"; 505 - return; 506 - } 507 - MacroFunction = macroFunc; 508 - 509 - MetaEntry logicalIdEntry; 510 - if (macroFunc.Meta.TryGetValue(PFunction.LogicalIdKey, out logicalIdEntry)) 511 - HumanId = logicalIdEntry.Text; 512 - else 513 - HumanId = invocation.Implementation.InternalId; 514 - } 515 - } 516 - 517 461 private class MacroFunctionExpander : MacroFunctionExpanderBase 518 462 { 519 463 public override void Initialize(CompilerTarget target, AstGetSet macroNode, bool justEffect) ··· 662 606 private IMacroExpander _getExpander(AstGetSet macroNode, CompilerTarget target) 663 607 { 664 608 IMacroExpander expander = null; 665 - var invocation = macroNode as AstMacroInvocation; 666 - if (invocation != null) 609 + AstExpand expansion; 610 + EntityRef.MacroCommand mcmd; 611 + EntityRef.Function func; 612 + if ((expansion = macroNode as AstExpand) != null) 667 613 { 668 - switch (invocation.Implementation.Interpretation) 669 - { 670 - case SymbolInterpretations.Function: 671 - expander = new LegacyMacroFunctionExpander(); 672 - break; 673 - case SymbolInterpretations.MacroCommand: 674 - expander = new LegacyMacroCommandExpander(); 675 - break; 676 - default: 677 - _reportMacroNodeNotMacro(target, 678 - Enum.GetName(typeof (SymbolInterpretations), 679 - invocation.Implementation.Interpretation), invocation); 680 - break; 681 - } 614 + if (expansion.Entity.TryGetMacroCommand(out mcmd)) 615 + expander = new MacroCommandExpander(); 616 + else if (expansion.Entity.TryGetFunction(out func)) 617 + expander = new MacroFunctionExpander(); 618 + else 619 + _reportMacroNodeNotMacro(target, expansion.Entity.GetType().Name, macroNode); 682 620 } 683 621 else 684 622 { 685 - AstExpand expansion; 686 - EntityRef.MacroCommand mcmd; 687 - EntityRef.Function func; 688 - if ((expansion = macroNode as AstExpand) != null) 689 - { 690 - if (expansion.Entity.TryGetMacroCommand(out mcmd)) 691 - expander = new MacroCommandExpander(); 692 - else if (expansion.Entity.TryGetFunction(out func)) 693 - expander = new MacroFunctionExpander(); 694 - else 695 - _reportMacroNodeNotMacro(target, expansion.Entity.GetType().Name, macroNode); 696 - } 697 - else 698 - { 699 - _reportMacroNodeNotMacro(target,macroNode.GetType().Name,macroNode); 700 - } 623 + _reportMacroNodeNotMacro(target, macroNode.GetType().Name, macroNode); 701 624 } 702 625 return expander; 703 626 }
+2 -5
Prexonite/Compiler/Parser.Code.cs
··· 1109 1109 AstIndirectCall indirectCallNode; 1110 1110 AstReference refNode; 1111 1111 EntityRef.Variable dummyVariable; 1112 - if ((rhs is AstGetSetSymbol 1113 - && ((AstGetSetSymbol)rhs).IsObjectVariable) 1114 - || ( 1115 - (indirectCallNode = rhs as AstIndirectCall) != null 1116 - && (refNode = indirectCallNode.Subject as AstReference) != null) 1112 + if ((indirectCallNode = rhs as AstIndirectCall) != null 1113 + && (refNode = indirectCallNode.Subject as AstReference) != null 1117 1114 && refNode.Entity.TryGetVariable(out dummyVariable)) 1118 1115 rhs.Call = PCall.Set; 1119 1116 }
+165 -164
Prexonite/Compiler/Parser.cs
··· 803 803 } 804 804 } 805 805 806 - void GetCall(/*Parser.Statement.atg:487*/out AstGetSet complex) { 807 - /*Parser.Statement.atg:487*/AstGetSet getMember = null; 806 + void GetCall(/*Parser.Statement.atg:488*/out AstGetSet complex) { 807 + /*Parser.Statement.atg:488*/AstGetSet getMember = null; 808 808 AstExpr expr; 809 809 810 - GetInitiator(/*Parser.Statement.atg:491*/out expr); 811 - /*Parser.Statement.atg:492*/complex = expr as AstGetSet; 810 + GetInitiator(/*Parser.Statement.atg:492*/out expr); 811 + /*Parser.Statement.atg:493*/complex = expr as AstGetSet; 812 812 if(complex == null) 813 813 { 814 814 var pos = GetPosition(); ··· 817 817 } 818 818 819 819 while (la.kind == _dot || la.kind == _lbrack) { 820 - GetSetExtension(/*Parser.Statement.atg:500*/complex, out getMember); 821 - /*Parser.Statement.atg:501*/complex = getMember; 820 + GetSetExtension(/*Parser.Statement.atg:501*/complex, out getMember); 821 + /*Parser.Statement.atg:502*/complex = getMember; 822 822 } 823 823 } 824 824 ··· 1541 1541 Expect(_null); 1542 1542 } 1543 1543 1544 - void WhileLoop(/*Parser.Statement.atg:414*/AstBlock block) { 1545 - /*Parser.Statement.atg:414*/AstWhileLoop loop = new AstWhileLoop(GetPosition(),CurrentBlock); 1544 + void WhileLoop(/*Parser.Statement.atg:415*/AstBlock block) { 1545 + /*Parser.Statement.atg:415*/AstWhileLoop loop = new AstWhileLoop(GetPosition(),CurrentBlock); 1546 1546 if (la.kind == _while || la.kind == _until) { 1547 1547 if (la.kind == _while) { 1548 1548 Get(); 1549 1549 } else { 1550 1550 Get(); 1551 - /*Parser.Statement.atg:416*/loop.IsPositive = false; 1551 + /*Parser.Statement.atg:417*/loop.IsPositive = false; 1552 1552 } 1553 1553 Expect(_lpar); 1554 - Expr(/*Parser.Statement.atg:418*/out loop.Condition); 1554 + Expr(/*Parser.Statement.atg:419*/out loop.Condition); 1555 1555 Expect(_rpar); 1556 - /*Parser.Statement.atg:419*/_PushScope(loop.Block); //EndBlock is common for both loops 1556 + /*Parser.Statement.atg:420*/_PushScope(loop.Block); //EndBlock is common for both loops 1557 1557 1558 - StatementBlock(/*Parser.Statement.atg:421*/loop.Block); 1558 + StatementBlock(/*Parser.Statement.atg:422*/loop.Block); 1559 1559 } else if (la.kind == _do) { 1560 1560 Get(); 1561 - /*Parser.Statement.atg:423*/_PushScope(loop.Block); 1561 + /*Parser.Statement.atg:424*/_PushScope(loop.Block); 1562 1562 loop.IsPrecondition = false; 1563 1563 1564 - StatementBlock(/*Parser.Statement.atg:426*/loop.Block); 1564 + StatementBlock(/*Parser.Statement.atg:427*/loop.Block); 1565 1565 if (la.kind == _while) { 1566 1566 Get(); 1567 1567 } else if (la.kind == _until) { 1568 1568 Get(); 1569 - /*Parser.Statement.atg:427*/loop.IsPositive = false; 1569 + /*Parser.Statement.atg:428*/loop.IsPositive = false; 1570 1570 } else SynErr(127); 1571 1571 Expect(_lpar); 1572 - Expr(/*Parser.Statement.atg:429*/out loop.Condition); 1572 + Expr(/*Parser.Statement.atg:430*/out loop.Condition); 1573 1573 Expect(_rpar); 1574 1574 } else SynErr(128); 1575 - /*Parser.Statement.atg:430*/_PopScope(loop.Block); block.Add(loop); 1575 + /*Parser.Statement.atg:431*/_PopScope(loop.Block); block.Add(loop); 1576 1576 } 1577 1577 1578 - void ForLoop(/*Parser.Statement.atg:433*/AstBlock block) { 1579 - /*Parser.Statement.atg:433*/AstForLoop loop; 1578 + void ForLoop(/*Parser.Statement.atg:434*/AstBlock block) { 1579 + /*Parser.Statement.atg:434*/AstForLoop loop; 1580 1580 AstExpr condition; 1581 1581 1582 1582 Expect(_for); 1583 - /*Parser.Statement.atg:437*/loop = new AstForLoop(GetPosition(), CurrentBlock); 1583 + /*Parser.Statement.atg:438*/loop = new AstForLoop(GetPosition(), CurrentBlock); 1584 1584 _PushScope(loop.Initialize); 1585 1585 1586 1586 Expect(_lpar); 1587 - StatementBlock(/*Parser.Statement.atg:440*/loop.Initialize); 1587 + StatementBlock(/*Parser.Statement.atg:441*/loop.Initialize); 1588 1588 if (la.kind == _do) { 1589 - /*Parser.Statement.atg:442*/_PushScope(loop.NextIteration); 1589 + /*Parser.Statement.atg:443*/_PushScope(loop.NextIteration); 1590 1590 1591 1591 Get(); 1592 - StatementBlock(/*Parser.Statement.atg:444*/loop.NextIteration); 1593 - /*Parser.Statement.atg:445*/loop.IsPrecondition = false; 1592 + StatementBlock(/*Parser.Statement.atg:445*/loop.NextIteration); 1593 + /*Parser.Statement.atg:446*/loop.IsPrecondition = false; 1594 1594 if (la.kind == _while) { 1595 1595 Get(); 1596 1596 } else if (la.kind == _until) { 1597 1597 Get(); 1598 - /*Parser.Statement.atg:447*/loop.IsPositive = false; 1598 + /*Parser.Statement.atg:448*/loop.IsPositive = false; 1599 1599 } else SynErr(129); 1600 - /*Parser.Statement.atg:448*/_PopScope(loop.NextIteration); 1601 - Expr(/*Parser.Statement.atg:449*/out condition); 1602 - /*Parser.Statement.atg:449*/loop.Condition = condition; 1600 + /*Parser.Statement.atg:449*/_PopScope(loop.NextIteration); 1601 + Expr(/*Parser.Statement.atg:450*/out condition); 1602 + /*Parser.Statement.atg:450*/loop.Condition = condition; 1603 1603 _PushScope(loop.NextIteration); 1604 1604 1605 1605 } else if (StartOf(14)) { ··· 1608 1608 Get(); 1609 1609 } else { 1610 1610 Get(); 1611 - /*Parser.Statement.atg:453*/loop.IsPositive = false; 1611 + /*Parser.Statement.atg:454*/loop.IsPositive = false; 1612 1612 } 1613 1613 } 1614 - Expr(/*Parser.Statement.atg:455*/out condition); 1615 - /*Parser.Statement.atg:455*/loop.Condition = condition; 1614 + Expr(/*Parser.Statement.atg:456*/out condition); 1615 + /*Parser.Statement.atg:456*/loop.Condition = condition; 1616 1616 Expect(_semicolon); 1617 - /*Parser.Statement.atg:456*/_PushScope(loop.NextIteration); 1618 - SimpleStatement(/*Parser.Statement.atg:457*/loop.NextIteration); 1617 + /*Parser.Statement.atg:457*/_PushScope(loop.NextIteration); 1618 + SimpleStatement(/*Parser.Statement.atg:458*/loop.NextIteration); 1619 1619 if (la.kind == _semicolon) { 1620 1620 Get(); 1621 1621 } 1622 1622 } else SynErr(130); 1623 1623 Expect(_rpar); 1624 - /*Parser.Statement.atg:460*/_PushScope(loop.Block); 1625 - StatementBlock(/*Parser.Statement.atg:461*/loop.Block); 1626 - /*Parser.Statement.atg:461*/_PopScope(loop.Block); 1624 + /*Parser.Statement.atg:461*/_PushScope(loop.Block); 1625 + StatementBlock(/*Parser.Statement.atg:462*/loop.Block); 1626 + /*Parser.Statement.atg:462*/_PopScope(loop.Block); 1627 1627 _PopScope(loop.NextIteration); 1628 1628 _PopScope(loop.Initialize); 1629 1629 block.Add(loop); 1630 1630 1631 1631 } 1632 1632 1633 - void ForeachLoop(/*Parser.Statement.atg:469*/AstBlock block) { 1633 + void ForeachLoop(/*Parser.Statement.atg:470*/AstBlock block) { 1634 1634 Expect(_foreach); 1635 - /*Parser.Statement.atg:470*/AstForeachLoop loop = Create.ForeachLoop(GetPosition()); 1635 + /*Parser.Statement.atg:471*/AstForeachLoop loop = Create.ForeachLoop(GetPosition()); 1636 1636 _PushScope(loop.Block); 1637 1637 1638 1638 Expect(_lpar); 1639 - GetCall(/*Parser.Statement.atg:474*/out loop.Element); 1639 + GetCall(/*Parser.Statement.atg:475*/out loop.Element); 1640 1640 Expect(_in); 1641 - Expr(/*Parser.Statement.atg:476*/out loop.List); 1641 + Expr(/*Parser.Statement.atg:477*/out loop.List); 1642 1642 Expect(_rpar); 1643 - StatementBlock(/*Parser.Statement.atg:478*/loop.Block); 1644 - /*Parser.Statement.atg:479*/_PopScope(loop.Block); 1643 + StatementBlock(/*Parser.Statement.atg:479*/loop.Block); 1644 + /*Parser.Statement.atg:480*/_PopScope(loop.Block); 1645 1645 block.Add(loop); 1646 1646 1647 1647 } 1648 1648 1649 - void Arguments(/*Parser.Statement.atg:680*/ArgumentsProxy args) { 1650 - /*Parser.Statement.atg:681*/AstExpr expr; 1649 + void Arguments(/*Parser.Statement.atg:681*/ArgumentsProxy args) { 1650 + /*Parser.Statement.atg:682*/AstExpr expr; 1651 1651 bool missingArg = false; 1652 1652 1653 1653 if (la.kind == _lpar) { 1654 1654 Get(); 1655 1655 if (StartOf(14)) { 1656 - Expr(/*Parser.Statement.atg:687*/out expr); 1657 - /*Parser.Statement.atg:687*/args.Add(expr); 1656 + Expr(/*Parser.Statement.atg:688*/out expr); 1657 + /*Parser.Statement.atg:688*/args.Add(expr); 1658 1658 while (la.kind == _comma) { 1659 1659 Get(); 1660 - /*Parser.Statement.atg:688*/if(missingArg) 1660 + /*Parser.Statement.atg:689*/if(missingArg) 1661 1661 SemErr("Missing argument expression (two consecutive commas)"); 1662 1662 1663 1663 if (StartOf(14)) { 1664 - Expr(/*Parser.Statement.atg:691*/out expr); 1665 - /*Parser.Statement.atg:692*/args.Add(expr); 1664 + Expr(/*Parser.Statement.atg:692*/out expr); 1665 + /*Parser.Statement.atg:693*/args.Add(expr); 1666 1666 missingArg = false; 1667 1667 1668 1668 } else if (la.kind == _comma || la.kind == _rpar) { 1669 - /*Parser.Statement.atg:695*/missingArg = true; 1669 + /*Parser.Statement.atg:696*/missingArg = true; 1670 1670 } else SynErr(131); 1671 1671 } 1672 1672 } 1673 1673 Expect(_rpar); 1674 1674 } 1675 - /*Parser.Statement.atg:701*/args.RememberRightAppendPosition(); 1675 + /*Parser.Statement.atg:702*/args.RememberRightAppendPosition(); 1676 1676 if (la.kind == _appendleft) { 1677 1677 Get(); 1678 - if (/*Parser.Statement.atg:706*/la.kind == _lpar && (!isLambdaExpression())) { 1678 + if (/*Parser.Statement.atg:707*/la.kind == _lpar && (!isLambdaExpression())) { 1679 1679 Expect(_lpar); 1680 1680 if (StartOf(14)) { 1681 - Expr(/*Parser.Statement.atg:707*/out expr); 1682 - /*Parser.Statement.atg:707*/args.Add(expr); 1681 + Expr(/*Parser.Statement.atg:708*/out expr); 1682 + /*Parser.Statement.atg:708*/args.Add(expr); 1683 1683 while (la.kind == _comma) { 1684 1684 Get(); 1685 - Expr(/*Parser.Statement.atg:709*/out expr); 1686 - /*Parser.Statement.atg:710*/args.Add(expr); 1685 + Expr(/*Parser.Statement.atg:710*/out expr); 1686 + /*Parser.Statement.atg:711*/args.Add(expr); 1687 1687 } 1688 1688 } 1689 1689 Expect(_rpar); 1690 1690 } else if (StartOf(14)) { 1691 - Expr(/*Parser.Statement.atg:714*/out expr); 1692 - /*Parser.Statement.atg:714*/args.Add(expr); 1691 + Expr(/*Parser.Statement.atg:715*/out expr); 1692 + /*Parser.Statement.atg:715*/args.Add(expr); 1693 1693 } else SynErr(132); 1694 1694 } 1695 1695 } ··· 3133 3133 } else SynErr(164); 3134 3134 } 3135 3135 3136 - void ExplicitLabel(/*Parser.Statement.atg:341*/AstBlock block) { 3137 - /*Parser.Statement.atg:341*/string id = "--\\NotAnId\\--"; 3136 + void ExplicitLabel(/*Parser.Statement.atg:342*/AstBlock block) { 3137 + /*Parser.Statement.atg:342*/string id = "--\\NotAnId\\--"; 3138 3138 if (StartOf(4)) { 3139 - Id(/*Parser.Statement.atg:343*/out id); 3139 + Id(/*Parser.Statement.atg:344*/out id); 3140 3140 Expect(_colon); 3141 3141 } else if (la.kind == _lid) { 3142 3142 Get(); 3143 - /*Parser.Statement.atg:344*/id = cache(t.val.Substring(0,t.val.Length-1)); 3143 + /*Parser.Statement.atg:345*/id = cache(t.val.Substring(0,t.val.Length-1)); 3144 3144 } else SynErr(165); 3145 - /*Parser.Statement.atg:345*/block.Statements.Add(new AstExplicitLabel(this, id)); 3145 + /*Parser.Statement.atg:346*/block.Statements.Add(new AstExplicitLabel(this, id)); 3146 3146 } 3147 3147 3148 3148 void SimpleStatement(/*Parser.Statement.atg:43*/AstBlock block) { ··· 3212 3212 } 3213 3213 } 3214 3214 3215 - void ExplicitGoTo(/*Parser.Statement.atg:348*/AstBlock block) { 3216 - /*Parser.Statement.atg:348*/string id; 3215 + void ExplicitGoTo(/*Parser.Statement.atg:349*/AstBlock block) { 3216 + /*Parser.Statement.atg:349*/string id; 3217 3217 Expect(_goto); 3218 - Id(/*Parser.Statement.atg:351*/out id); 3219 - /*Parser.Statement.atg:351*/block.Statements.Add(new AstExplicitGoTo(this, id)); 3218 + Id(/*Parser.Statement.atg:352*/out id); 3219 + /*Parser.Statement.atg:352*/block.Statements.Add(new AstExplicitGoTo(this, id)); 3220 3220 } 3221 3221 3222 3222 void GetSetComplex(/*Parser.Statement.atg:72*/AstBlock block) { ··· 3274 3274 } else SynErr(168); 3275 3275 } 3276 3276 3277 - void Return(/*Parser.Statement.atg:505*/AstBlock block) { 3278 - /*Parser.Statement.atg:505*/AstReturn ret = null; 3277 + void Return(/*Parser.Statement.atg:506*/AstBlock block) { 3278 + /*Parser.Statement.atg:506*/AstReturn ret = null; 3279 3279 AstExplicitGoTo jump = null; 3280 3280 AstExpr expr; 3281 3281 AstLoopBlock bl = target.CurrentLoopBlock; ··· 3283 3283 if (la.kind == _return || la.kind == _yield) { 3284 3284 if (la.kind == _return) { 3285 3285 Get(); 3286 - /*Parser.Statement.atg:513*/ret = new AstReturn(this, ReturnVariant.Exit); 3286 + /*Parser.Statement.atg:514*/ret = new AstReturn(this, ReturnVariant.Exit); 3287 3287 } else { 3288 3288 Get(); 3289 - /*Parser.Statement.atg:514*/ret = new AstReturn(this, ReturnVariant.Continue); 3289 + /*Parser.Statement.atg:515*/ret = new AstReturn(this, ReturnVariant.Continue); 3290 3290 } 3291 3291 if (StartOf(45)) { 3292 3292 if (StartOf(14)) { 3293 - Expr(/*Parser.Statement.atg:516*/out expr); 3294 - /*Parser.Statement.atg:516*/ret.Expression = expr; 3293 + Expr(/*Parser.Statement.atg:517*/out expr); 3294 + /*Parser.Statement.atg:517*/ret.Expression = expr; 3295 3295 } else { 3296 3296 Get(); 3297 - /*Parser.Statement.atg:517*/ret.ReturnVariant = ReturnVariant.Set; 3298 - Expr(/*Parser.Statement.atg:518*/out expr); 3299 - /*Parser.Statement.atg:518*/ret.Expression = expr; 3300 - /*Parser.Statement.atg:519*/SemErr("Return value assignment is no longer supported. You must use local variables instead."); 3297 + /*Parser.Statement.atg:518*/ret.ReturnVariant = ReturnVariant.Set; 3298 + Expr(/*Parser.Statement.atg:519*/out expr); 3299 + /*Parser.Statement.atg:519*/ret.Expression = expr; 3300 + /*Parser.Statement.atg:520*/SemErr("Return value assignment is no longer supported. You must use local variables instead."); 3301 3301 } 3302 3302 } 3303 3303 } else if (la.kind == _break) { 3304 3304 Get(); 3305 - /*Parser.Statement.atg:521*/if(bl == null) 3305 + /*Parser.Statement.atg:522*/if(bl == null) 3306 3306 ret = new AstReturn(this, ReturnVariant.Break); 3307 3307 else 3308 3308 jump = new AstExplicitGoTo(this, bl.BreakLabel); 3309 3309 3310 3310 } else if (la.kind == _continue) { 3311 3311 Get(); 3312 - /*Parser.Statement.atg:526*/if(bl == null) 3312 + /*Parser.Statement.atg:527*/if(bl == null) 3313 3313 ret = new AstReturn(this, ReturnVariant.Continue); 3314 3314 else 3315 3315 jump = new AstExplicitGoTo(this, bl.ContinueLabel); 3316 3316 3317 3317 } else SynErr(169); 3318 - /*Parser.Statement.atg:531*/block.Add((AstNode)ret ?? jump); 3318 + /*Parser.Statement.atg:532*/block.Add((AstNode)ret ?? jump); 3319 3319 } 3320 3320 3321 - void Throw(/*Parser.Statement.atg:656*/AstBlock block) { 3322 - /*Parser.Statement.atg:656*/AstThrow th; 3323 - ThrowExpression(/*Parser.Statement.atg:658*/out th); 3324 - /*Parser.Statement.atg:659*/block.Add(th); 3321 + void Throw(/*Parser.Statement.atg:657*/AstBlock block) { 3322 + /*Parser.Statement.atg:657*/AstThrow th; 3323 + ThrowExpression(/*Parser.Statement.atg:659*/out th); 3324 + /*Parser.Statement.atg:660*/block.Add(th); 3325 3325 } 3326 3326 3327 - void LetBindingStmt(/*Parser.Statement.atg:571*/AstBlock block) { 3327 + void LetBindingStmt(/*Parser.Statement.atg:572*/AstBlock block) { 3328 3328 Expect(_let); 3329 - LetBinder(/*Parser.Statement.atg:572*/block); 3329 + LetBinder(/*Parser.Statement.atg:573*/block); 3330 3330 while (la.kind == _comma) { 3331 3331 Get(); 3332 - LetBinder(/*Parser.Statement.atg:572*/block); 3332 + LetBinder(/*Parser.Statement.atg:573*/block); 3333 3333 } 3334 3334 } 3335 3335 3336 - void Condition(/*Parser.Statement.atg:391*/AstBlock block) { 3337 - /*Parser.Statement.atg:391*/AstExpr expr; bool isNegative = false; 3336 + void Condition(/*Parser.Statement.atg:392*/AstBlock block) { 3337 + /*Parser.Statement.atg:392*/AstExpr expr; bool isNegative = false; 3338 3338 if (la.kind == _if) { 3339 3339 Get(); 3340 3340 3341 3341 } else if (la.kind == _unless) { 3342 3342 Get(); 3343 - /*Parser.Statement.atg:394*/isNegative = true; 3343 + /*Parser.Statement.atg:395*/isNegative = true; 3344 3344 } else SynErr(170); 3345 3345 Expect(_lpar); 3346 - Expr(/*Parser.Statement.atg:397*/out expr); 3346 + Expr(/*Parser.Statement.atg:398*/out expr); 3347 3347 Expect(_rpar); 3348 - /*Parser.Statement.atg:397*/if(expr == null) 3348 + /*Parser.Statement.atg:398*/if(expr == null) 3349 3349 expr = _createUnknownExpr(); 3350 3350 AstCondition cond = Create.Condition(GetPosition(), expr, isNegative); 3351 3351 _PushScope(cond.IfBlock); 3352 3352 3353 - StatementBlock(/*Parser.Statement.atg:403*/cond.IfBlock); 3354 - /*Parser.Statement.atg:404*/_PopScope(cond.IfBlock); 3353 + StatementBlock(/*Parser.Statement.atg:404*/cond.IfBlock); 3354 + /*Parser.Statement.atg:405*/_PopScope(cond.IfBlock); 3355 3355 if (la.kind == _else) { 3356 3356 Get(); 3357 - /*Parser.Statement.atg:407*/_PushScope(cond.ElseBlock); 3358 - StatementBlock(/*Parser.Statement.atg:408*/cond.ElseBlock); 3359 - /*Parser.Statement.atg:409*/_PopScope(cond.ElseBlock); 3357 + /*Parser.Statement.atg:408*/_PushScope(cond.ElseBlock); 3358 + StatementBlock(/*Parser.Statement.atg:409*/cond.ElseBlock); 3359 + /*Parser.Statement.atg:410*/_PopScope(cond.ElseBlock); 3360 3360 } 3361 - /*Parser.Statement.atg:410*/block.Add(cond); 3361 + /*Parser.Statement.atg:411*/block.Add(cond); 3362 3362 } 3363 3363 3364 - void NestedFunction(/*Parser.Statement.atg:535*/AstBlock block) { 3365 - /*Parser.Statement.atg:535*/PFunction func; 3366 - FunctionDefinition(/*Parser.Statement.atg:537*/out func); 3367 - /*Parser.Statement.atg:539*/string logicalId = func.Meta[PFunction.LogicalIdKey]; 3364 + void NestedFunction(/*Parser.Statement.atg:536*/AstBlock block) { 3365 + /*Parser.Statement.atg:536*/PFunction func; 3366 + FunctionDefinition(/*Parser.Statement.atg:538*/out func); 3367 + /*Parser.Statement.atg:540*/string logicalId = func.Meta[PFunction.LogicalIdKey]; 3368 3368 func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 3369 3369 3370 3370 CompilerTarget ft = FunctionTargets[func]; ··· 3395 3395 3396 3396 } 3397 3397 3398 - void TryCatchFinally(/*Parser.Statement.atg:598*/AstBlock block) { 3399 - /*Parser.Statement.atg:598*/var a = Create.TryCatchFinally(GetPosition()); 3398 + void TryCatchFinally(/*Parser.Statement.atg:599*/AstBlock block) { 3399 + /*Parser.Statement.atg:599*/var a = Create.TryCatchFinally(GetPosition()); 3400 3400 AstGetSet excVar; 3401 3401 3402 3402 Expect(_try); 3403 - /*Parser.Statement.atg:602*/_PushScope(a); 3403 + /*Parser.Statement.atg:603*/_PushScope(a); 3404 3404 _PushScope(a.TryBlock); 3405 3405 3406 3406 Expect(_lbrace); 3407 3407 while (StartOf(20)) { 3408 - Statement(/*Parser.Statement.atg:606*/a.TryBlock); 3408 + Statement(/*Parser.Statement.atg:607*/a.TryBlock); 3409 3409 } 3410 3410 Expect(_rbrace); 3411 3411 3412 3412 if (la.kind == _catch || la.kind == _finally) { 3413 3413 if (la.kind == _catch) { 3414 3414 Get(); 3415 - /*Parser.Statement.atg:609*/_PushScope(a.CatchBlock); 3415 + /*Parser.Statement.atg:610*/_PushScope(a.CatchBlock); 3416 3416 if (la.kind == _lpar) { 3417 3417 Get(); 3418 - GetCall(/*Parser.Statement.atg:611*/out excVar); 3419 - /*Parser.Statement.atg:611*/a.ExceptionVar = excVar; 3418 + GetCall(/*Parser.Statement.atg:612*/out excVar); 3419 + /*Parser.Statement.atg:612*/a.ExceptionVar = excVar; 3420 3420 Expect(_rpar); 3421 3421 } else if (la.kind == _lbrace) { 3422 - /*Parser.Statement.atg:613*/SemErr(la,"catch-clauses that don't store the exception are illegal."); 3422 + /*Parser.Statement.atg:614*/SemErr(la,"catch-clauses that don't store the exception are illegal."); 3423 3423 } else SynErr(171); 3424 3424 Expect(_lbrace); 3425 3425 while (StartOf(20)) { 3426 - Statement(/*Parser.Statement.atg:616*/a.CatchBlock); 3426 + Statement(/*Parser.Statement.atg:617*/a.CatchBlock); 3427 3427 } 3428 3428 Expect(_rbrace); 3429 - /*Parser.Statement.atg:618*/_PopScope(a.CatchBlock); 3429 + /*Parser.Statement.atg:619*/_PopScope(a.CatchBlock); 3430 3430 if (la.kind == _finally) { 3431 3431 Get(); 3432 - /*Parser.Statement.atg:621*/_PushScope(a.FinallyBlock); 3432 + /*Parser.Statement.atg:622*/_PushScope(a.FinallyBlock); 3433 3433 Expect(_lbrace); 3434 3434 while (StartOf(20)) { 3435 - Statement(/*Parser.Statement.atg:623*/a.FinallyBlock); 3435 + Statement(/*Parser.Statement.atg:624*/a.FinallyBlock); 3436 3436 } 3437 3437 Expect(_rbrace); 3438 - /*Parser.Statement.atg:625*/_PopScope(a.FinallyBlock); 3438 + /*Parser.Statement.atg:626*/_PopScope(a.FinallyBlock); 3439 3439 } 3440 3440 } else { 3441 3441 Get(); 3442 - /*Parser.Statement.atg:628*/_PushScope(a.FinallyBlock); 3442 + /*Parser.Statement.atg:629*/_PushScope(a.FinallyBlock); 3443 3443 Expect(_lbrace); 3444 3444 while (StartOf(20)) { 3445 - Statement(/*Parser.Statement.atg:630*/a.FinallyBlock); 3445 + Statement(/*Parser.Statement.atg:631*/a.FinallyBlock); 3446 3446 } 3447 3447 Expect(_rbrace); 3448 - /*Parser.Statement.atg:632*/_PopScope(a.FinallyBlock); 3448 + /*Parser.Statement.atg:633*/_PopScope(a.FinallyBlock); 3449 3449 if (la.kind == _catch) { 3450 - /*Parser.Statement.atg:634*/_PushScope(a.CatchBlock); 3450 + /*Parser.Statement.atg:635*/_PushScope(a.CatchBlock); 3451 3451 Get(); 3452 3452 if (la.kind == _lpar) { 3453 3453 Get(); 3454 - GetCall(/*Parser.Statement.atg:637*/out excVar); 3455 - /*Parser.Statement.atg:638*/a.ExceptionVar = excVar; 3454 + GetCall(/*Parser.Statement.atg:638*/out excVar); 3455 + /*Parser.Statement.atg:639*/a.ExceptionVar = excVar; 3456 3456 Expect(_rpar); 3457 3457 } else if (la.kind == _lbrace) { 3458 - /*Parser.Statement.atg:640*/SemErr(la,"catch-clauses that don't store the exception are illegal."); 3458 + /*Parser.Statement.atg:641*/SemErr(la,"catch-clauses that don't store the exception are illegal."); 3459 3459 } else SynErr(172); 3460 3460 Expect(_lbrace); 3461 3461 while (StartOf(20)) { 3462 - Statement(/*Parser.Statement.atg:643*/a.CatchBlock); 3462 + Statement(/*Parser.Statement.atg:644*/a.CatchBlock); 3463 3463 } 3464 3464 Expect(_rbrace); 3465 - /*Parser.Statement.atg:646*/_PopScope(a.CatchBlock); 3465 + /*Parser.Statement.atg:647*/_PopScope(a.CatchBlock); 3466 3466 } 3467 3467 } 3468 3468 } 3469 - /*Parser.Statement.atg:649*/_PopScope(a.TryBlock); 3469 + /*Parser.Statement.atg:650*/_PopScope(a.TryBlock); 3470 3470 _PopScope(a); 3471 3471 block.Add(a); 3472 3472 3473 3473 } 3474 3474 3475 - void Using(/*Parser.Statement.atg:663*/AstBlock block) { 3476 - /*Parser.Statement.atg:663*/AstUsing use = Create.Using(GetPosition()); 3475 + void Using(/*Parser.Statement.atg:664*/AstBlock block) { 3476 + /*Parser.Statement.atg:664*/AstUsing use = Create.Using(GetPosition()); 3477 3477 AstExpr e; 3478 3478 3479 - /*Parser.Statement.atg:667*/_PushScope(use); 3479 + /*Parser.Statement.atg:668*/_PushScope(use); 3480 3480 _PushScope(use.Block); 3481 3481 Expect(_uusing); 3482 3482 Expect(_lpar); 3483 - Expr(/*Parser.Statement.atg:669*/out e); 3483 + Expr(/*Parser.Statement.atg:670*/out e); 3484 3484 Expect(_rpar); 3485 - /*Parser.Statement.atg:670*/use.ResourceExpression = e; 3486 - StatementBlock(/*Parser.Statement.atg:672*/use.Block); 3487 - /*Parser.Statement.atg:673*/_PopScope(use.Block); 3485 + /*Parser.Statement.atg:671*/use.ResourceExpression = e; 3486 + StatementBlock(/*Parser.Statement.atg:673*/use.Block); 3487 + /*Parser.Statement.atg:674*/_PopScope(use.Block); 3488 3488 _PopScope(use); 3489 3489 block.Add(use); 3490 3490 3491 3491 } 3492 3492 3493 - void Assignment(/*Parser.Statement.atg:355*/AstGetSet lvalue, out AstNode node) { 3494 - /*Parser.Statement.atg:355*/AstExpr expr = null; 3493 + void Assignment(/*Parser.Statement.atg:356*/AstGetSet lvalue, out AstNode node) { 3494 + /*Parser.Statement.atg:356*/AstExpr expr = null; 3495 3495 BinaryOperator setModifier = BinaryOperator.None; 3496 3496 AstTypeExpr typeExpr; 3497 3497 node = lvalue; 3498 3498 ISourcePosition position; 3499 3499 3500 - /*Parser.Statement.atg:361*/position = GetPosition(); 3500 + /*Parser.Statement.atg:362*/position = GetPosition(); 3501 3501 if (StartOf(9)) { 3502 3502 switch (la.kind) { 3503 3503 case _assign: { 3504 3504 Get(); 3505 - /*Parser.Statement.atg:363*/setModifier = BinaryOperator.None; 3505 + /*Parser.Statement.atg:364*/setModifier = BinaryOperator.None; 3506 3506 break; 3507 3507 } 3508 3508 case _plus: { 3509 3509 Get(); 3510 3510 Expect(_assign); 3511 - /*Parser.Statement.atg:364*/setModifier = BinaryOperator.Addition; 3511 + /*Parser.Statement.atg:365*/setModifier = BinaryOperator.Addition; 3512 3512 break; 3513 3513 } 3514 3514 case _minus: { 3515 3515 Get(); 3516 3516 Expect(_assign); 3517 - /*Parser.Statement.atg:365*/setModifier = BinaryOperator.Subtraction; 3517 + /*Parser.Statement.atg:366*/setModifier = BinaryOperator.Subtraction; 3518 3518 break; 3519 3519 } 3520 3520 case _times: { 3521 3521 Get(); 3522 3522 Expect(_assign); 3523 - /*Parser.Statement.atg:366*/setModifier = BinaryOperator.Multiply; 3523 + /*Parser.Statement.atg:367*/setModifier = BinaryOperator.Multiply; 3524 3524 break; 3525 3525 } 3526 3526 case _div: { 3527 3527 Get(); 3528 3528 Expect(_assign); 3529 - /*Parser.Statement.atg:367*/setModifier = BinaryOperator.Division; 3529 + /*Parser.Statement.atg:368*/setModifier = BinaryOperator.Division; 3530 3530 break; 3531 3531 } 3532 3532 case _bitAnd: { 3533 3533 Get(); 3534 3534 Expect(_assign); 3535 - /*Parser.Statement.atg:368*/setModifier = BinaryOperator.BitwiseAnd; 3535 + /*Parser.Statement.atg:369*/setModifier = BinaryOperator.BitwiseAnd; 3536 3536 break; 3537 3537 } 3538 3538 case _bitOr: { 3539 3539 Get(); 3540 3540 Expect(_assign); 3541 - /*Parser.Statement.atg:369*/setModifier = BinaryOperator.BitwiseOr; 3541 + /*Parser.Statement.atg:370*/setModifier = BinaryOperator.BitwiseOr; 3542 3542 break; 3543 3543 } 3544 3544 case _coalescence: { 3545 3545 Get(); 3546 3546 Expect(_assign); 3547 - /*Parser.Statement.atg:370*/setModifier = BinaryOperator.Coalescence; 3547 + /*Parser.Statement.atg:371*/setModifier = BinaryOperator.Coalescence; 3548 3548 break; 3549 3549 } 3550 3550 } 3551 - Expr(/*Parser.Statement.atg:371*/out expr); 3551 + Expr(/*Parser.Statement.atg:372*/out expr); 3552 3552 } else if (la.kind == _tilde) { 3553 3553 Get(); 3554 3554 Expect(_assign); 3555 - /*Parser.Statement.atg:373*/setModifier = BinaryOperator.Cast; 3556 - TypeExpr(/*Parser.Statement.atg:374*/out typeExpr); 3557 - /*Parser.Statement.atg:374*/expr = typeExpr; 3555 + /*Parser.Statement.atg:374*/setModifier = BinaryOperator.Cast; 3556 + TypeExpr(/*Parser.Statement.atg:375*/out typeExpr); 3557 + /*Parser.Statement.atg:375*/expr = typeExpr; 3558 3558 } else SynErr(173); 3559 - /*Parser.Statement.atg:376*/if(expr == null) 3559 + /*Parser.Statement.atg:377*/if(expr == null) 3560 3560 { 3561 3561 Loader.ReportMessage(Message.Error("Internal error during translation of assignment. This is likely caused by an error reported previously.",GetPosition(),MessageClasses.ParserInternal)); 3562 3562 } ··· 3585 3585 /*Parser.Statement.atg:301*/position = GetPosition(); 3586 3586 Id(/*Parser.Statement.atg:302*/out id); 3587 3587 /*Parser.Statement.atg:302*/Symbol sym; 3588 - Symbols.TryGet(id, out sym); 3589 - var expr = Create.ExprFor(position,sym); 3588 + var expr = Symbols.TryGet(id, out sym) 3589 + ? Create.ExprFor(position, sym) 3590 + : new AstUnresolved(position, id); 3590 3591 complex = expr as AstGetSet; 3591 3592 if(complex == null) 3592 3593 { ··· 3594 3595 complex = Create.IndirectCall(position,Create.Null(position)); 3595 3596 } 3596 3597 3597 - Arguments(/*Parser.Statement.atg:312*/complex.Arguments); 3598 + Arguments(/*Parser.Statement.atg:313*/complex.Arguments); 3598 3599 } 3599 3600 3600 3601 void VariableDeclaration(/*Parser.Statement.atg:202*/out AstGetSet complex) { ··· 3715 3716 3716 3717 } 3717 3718 3718 - void StaticCall(/*Parser.Statement.atg:316*/out AstGetSetStatic staticCall) { 3719 - /*Parser.Statement.atg:316*/AstTypeExpr typeExpr; 3719 + void StaticCall(/*Parser.Statement.atg:317*/out AstGetSetStatic staticCall) { 3720 + /*Parser.Statement.atg:317*/AstTypeExpr typeExpr; 3720 3721 string memberId; 3721 3722 3722 - ExplicitTypeExpr(/*Parser.Statement.atg:320*/out typeExpr); 3723 + ExplicitTypeExpr(/*Parser.Statement.atg:321*/out typeExpr); 3723 3724 Expect(_dot); 3724 - Id(/*Parser.Statement.atg:321*/out memberId); 3725 - /*Parser.Statement.atg:321*/staticCall = new AstGetSetStatic(this, PCall.Get, typeExpr, memberId); 3726 - Arguments(/*Parser.Statement.atg:322*/staticCall.Arguments); 3725 + Id(/*Parser.Statement.atg:322*/out memberId); 3726 + /*Parser.Statement.atg:322*/staticCall = new AstGetSetStatic(this, PCall.Get, typeExpr, memberId); 3727 + Arguments(/*Parser.Statement.atg:323*/staticCall.Arguments); 3727 3728 } 3728 3729 3729 - void LetBinder(/*Parser.Statement.atg:576*/AstBlock block) { 3730 - /*Parser.Statement.atg:576*/string id = null; 3730 + void LetBinder(/*Parser.Statement.atg:577*/AstBlock block) { 3731 + /*Parser.Statement.atg:577*/string id = null; 3731 3732 AstExpr thunk; 3732 3733 3733 - /*Parser.Statement.atg:579*/var position = GetPosition(); 3734 - Id(/*Parser.Statement.atg:580*/out id); 3735 - /*Parser.Statement.atg:581*/SmartDeclareLocal(id, SymbolInterpretations.LocalObjectVariable); 3734 + /*Parser.Statement.atg:580*/var position = GetPosition(); 3735 + Id(/*Parser.Statement.atg:581*/out id); 3736 + /*Parser.Statement.atg:582*/SmartDeclareLocal(id, SymbolInterpretations.LocalObjectVariable); 3736 3737 mark_as_let(target.Function, id); 3737 3738 if(la.kind == _assign) 3738 3739 _inject(_lazy,"lazy"); 3739 3740 3740 3741 if (la.kind == _assign) { 3741 3742 Get(); 3742 - LazyExpression(/*Parser.Statement.atg:587*/out thunk); 3743 - /*Parser.Statement.atg:590*/var assign = Create.Call(position, EntityRef.Variable.Local.Create(id), PCall.Set); 3743 + LazyExpression(/*Parser.Statement.atg:588*/out thunk); 3744 + /*Parser.Statement.atg:591*/var assign = Create.Call(position, EntityRef.Variable.Local.Create(id), PCall.Set); 3744 3745 assign.Arguments.Add(thunk); 3745 3746 block.Add(assign); 3746 3747
+7
Prexonite/Compiler/SourcePosition.cs
··· 109 109 { 110 110 return (_file ?? String.Empty).GetHashCode() ^ _line ^ (_column + 256); 111 111 } 112 + 113 + public override string ToString() 114 + { 115 + return File != null 116 + ? String.Format("{0} {1}.{2}", File, Line, Column) 117 + : String.Format("{0}.{1}", Line, Column); 118 + } 112 119 } 113 120 }
-3
Prexonite/Prexonite.csproj
··· 324 324 <Compile Include="Compiler\Ast\AstBinaryOperator.cs" /> 325 325 <Compile Include="Compiler\Ast\AstGetSetMemberAccess.cs" /> 326 326 <Compile Include="Compiler\Ast\AstGetSetNewDecl.cs" /> 327 - <Compile Include="Compiler\Ast\AstGetSetReference.cs" /> 328 327 <Compile Include="Compiler\Ast\AstHashLiteral.cs" /> 329 328 <Compile Include="Compiler\Ast\AstIndirectCall.cs" /> 330 329 <Compile Include="Compiler\Ast\AstKeyValuePair.cs" /> ··· 334 333 <Compile Include="Compiler\Ast\AstLogicalOr.cs" /> 335 334 <Compile Include="Compiler\Ast\AstDynamicTypeExpression.cs" /> 336 335 <Compile Include="Compiler\Ast\AstLoop.cs" /> 337 - <Compile Include="Compiler\Ast\AstMacroInvocation.cs" /> 338 336 <Compile Include="Compiler\Ast\AstNull.cs" /> 339 337 <Compile Include="Compiler\Ast\AstObjectCreation.cs" /> 340 338 <Compile Include="Compiler\Ast\AstPlaceholder.cs" /> ··· 351 349 <Compile Include="Compiler\Ast\AstWhileLoop.cs" /> 352 350 <Compile Include="Compiler\Ast\AstForeachLoop.cs" /> 353 351 <Compile Include="Compiler\Ast\AstBlock.cs" /> 354 - <Compile Include="Compiler\Ast\AstGetSetSymbol.cs" /> 355 352 <Compile Include="Compiler\Ast\AstNode.cs" /> 356 353 <Compile Include="Compiler\Ast\IAstHasBlocks.cs" /> 357 354 <Compile Include="Compiler\Ast\IAstHasExpressions.cs" />
+3 -2
Prexonite/Prexonite__gen.atg
··· 2322 2322 .) 2323 2323 = (. position = GetPosition(); .) 2324 2324 Id<out id> (. Symbol sym; 2325 - Symbols.TryGet(id, out sym); 2326 - var expr = Create.ExprFor(position,sym); 2325 + var expr = Symbols.TryGet(id, out sym) 2326 + ? Create.ExprFor(position, sym) 2327 + : new AstUnresolved(position, id); 2327 2328 complex = expr as AstGetSet; 2328 2329 if(complex == null) 2329 2330 {
-1
Prexonite/Types/PType.cs
··· 817 817 818 818 #endregion //Operators 819 819 820 - [DebuggerStepThrough] 821 820 public virtual PValue DynamicCall( 822 821 StackContext sctx, PValue subject, PValue[] args, PCall call, string id) 823 822 {
+3
Prexonite/prxlib/sys.pxs
··· 105 105 $not, 106 106 create_enumerator, 107 107 create_module_name, 108 + create_source_position, 109 + get_unscoped_ast_factory, 108 110 seqconcat, 109 111 macro command: 110 112 call, ··· 119 121 call\star, 120 122 call\macro, 121 123 call\macro\impl, 124 + entityref_to 122 125 };
-10
PrexoniteTests/Tests/Configurations/PsrUnitTests.cs
··· 64 64 RunUnitTest(@"test_unique_id_counter"); 65 65 } 66 66 [Test] 67 - public void test_is_function_call() 68 - { 69 - RunUnitTest(@"test_is_function_call"); 70 - } 71 - [Test] 72 67 public void test_is_member_access() 73 68 { 74 69 RunUnitTest(@"test_is_member_access"); ··· 279 274 public void test_macro_internal_id() 280 275 { 281 276 RunUnitTest(@"test_macro_internal_id"); 282 - } 283 - [Test] 284 - public void test_macro_interpretation() 285 - { 286 - RunUnitTest(@"test_macro_interpretation"); 287 277 } 288 278 [Test] 289 279 public void test_macro_entity_static()
+54 -3
PrexoniteTests/Tests/Translation.cs
··· 24 24 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 25 // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 26 27 + using System; 27 28 using System.Collections.Generic; 28 29 using Moq; 29 30 using NUnit.Framework; ··· 165 166 return g*x; 166 167 } 167 168 169 + // At this point, we should have 170 + // g -> function g 171 + // f -> variable f 172 + // p -> function f 173 + 168 174 function main(x) 169 175 { 170 176 var f' = f; ··· 176 182 177 183 Expect(3*2 + 5 + 7, 2); 178 184 Expect(3*11 + 5 + 7, 11); 185 + 186 + var mn = ldr.ParentApplication.Module.Name; 179 187 180 188 { 181 189 Assert.That(ldr.Symbols.Contains("f"), Is.True, ··· 188 196 Assert.That(refSym.Entity,Is.InstanceOf<EntityRef.Variable.Global>()); 189 197 EntityRef.Variable.Global globVar; 190 198 refSym.Entity.TryGetGlobalVariable(out globVar); 191 - Assert.That(globVar,Is.EqualTo("f")); 199 + Assert.That(globVar,Is.EqualTo(EntityRef.Variable.Global.Create("f",mn))); 192 200 } 193 201 194 202 { ··· 202 210 Assert.That(refSym.Entity, Is.InstanceOf<EntityRef.Function>()); 203 211 EntityRef.Function func; 204 212 refSym.Entity.TryGetFunction(out func); 205 - Assert.That(func, Is.EqualTo("g")); 213 + Assert.That(func, Is.EqualTo(EntityRef.Function.Create("g",mn))); 206 214 } 207 215 208 216 { ··· 216 224 Assert.That(refSym.Entity, Is.InstanceOf<EntityRef.Function>()); 217 225 EntityRef.Function func; 218 226 refSym.Entity.TryGetFunction(out func); 219 - Assert.That(func, Is.EqualTo("f")); 227 + Assert.That(func, Is.EqualTo(EntityRef.Function.Create("f",mn))); 220 228 } 221 229 } 222 230 ··· 463 471 Expect(true); 464 472 Assert.That(ldr.Warnings.Count,Is.EqualTo(1)); 465 473 Assert.That(ldr.Warnings[0].MessageClass,Is.EqualTo("T.tt")); 474 + } 475 + 476 + [Test] 477 + public void EntityRefToCommand() 478 + { 479 + var ldr = Compile(@" 480 + function f{} 481 + var v; 482 + ref r; 483 + macro m{} 484 + 485 + function main() 486 + { 487 + var loc; 488 + ref rloc; 489 + var sep = ""|""; 490 + return """" + entityref_to(f) + sep 491 + + entityref_to(v) + sep 492 + + entityref_to(->r) + sep 493 + + entityref_to(m) + sep 494 + + entityref_to(loc) + sep 495 + + entityref_to(->rloc) + sep 496 + + entityref_to(entityref_to) + sep 497 + + entityref_to(print); 498 + } 499 + "); 500 + var nm = ldr.ParentApplication.Module.Name; 501 + 502 + Expect(rv => 503 + { 504 + var r = rv.CallToString(sctx).Split('|'); 505 + Console.WriteLine(rv); 506 + Assert.That(r.Length,Is.EqualTo(8),"Expected return value to consist of 8 elements. Returned {0}",rv); 507 + 508 + Assert.That(r[0],Is.EqualTo(EntityRef.Function.Create("f",nm).ToString())); 509 + Assert.That(r[1], Is.EqualTo(EntityRef.Variable.Global.Create("v", nm).ToString())); 510 + Assert.That(r[2], Is.EqualTo(EntityRef.Variable.Global.Create("r", nm).ToString())); 511 + Assert.That(r[3], Is.EqualTo(EntityRef.Function.Create("m", nm).ToString())); 512 + Assert.That(r[4], Is.EqualTo(EntityRef.Variable.Local.Create("loc").ToString())); 513 + Assert.That(r[5], Is.EqualTo(EntityRef.Variable.Local.Create("rloc").ToString())); 514 + Assert.That(r[6], Is.EqualTo(EntityRef.MacroCommand.Create("entityref_to").ToString())); 515 + Assert.That(r[7], Is.EqualTo(EntityRef.Command.Create("print").ToString())); 516 + }); 466 517 } 467 518 } 468 519 }
-123
PrexoniteTests/Tests/VMTests.cs
··· 660 660 } 661 661 662 662 [Test] 663 - public void InitializationCodeHook() 664 - { 665 - Compile( 666 - @" 667 - Imports { System, Prexonite, Prexonite::Types, Prexonite::Compiler, Prexonite::Compiler::Ast }; 668 - 669 - function ast(type) [is compiler;] 670 - { 671 - var args; 672 - var targs = []; 673 - for(var i = 1; i < args.Count; i++) 674 - targs[] = args[i]; 675 - 676 - return 677 - asm(ldr.eng) 678 - .CreatePType(""Object(\""Prexonite.Compiler.Ast.Ast$(type)\"")"") 679 - .Construct((["""",-1,-1]+targs)~Object<""Prexonite.PValue[]"">) 680 - .self; 681 - } 682 - 683 - var SI [is compiler;] = null; 684 - build { 685 - SI = new Structure; 686 - SI.\(""var"") = ::SymbolInterpretations.LocalObjectVariable; 687 - SI.\(""ref"") = ::SymbolInterpretations.LocalReferenceVariable; 688 - SI.\(""gvar"") = ::SymbolInterpretations.GlobalObjectVariable; 689 - SI.\(""gref"") = ::SymbolInterpretations.GlobalReferenceVariable; 690 - SI.\(""func"") = ::SymbolInterpretations.$Function; 691 - SI.\(""cmd"") = ::SymbolInterpretations.$Command; 692 - SI.\\(""eq"") = (self, l, r) => l~Int == r~Int; 693 - SI.\\(""is_lvar"") = (self, s) => s~Int == self.$var~Int; 694 - SI.\\(""is_lref"") = (self, s) => s~Int == self.$ref~Int; 695 - SI.\\(""is_gvar"") = (self, s) => s~Int == self.$gvar~Int; 696 - SI.\\(""is_gref"") = (self, s) => s~Int == self.$gref~Int; 697 - SI.\\(""is_func"") = (self, s) => s~Int == self.$func~Int; 698 - SI.\\(""is_cmd"") = (self, s) => s~Int == self.$cmd~Int; 699 - SI.\\(""is_obj"") = (self, s) => self.is_lvar(s) || self.is_gvar(s); 700 - SI.\\(""is_ref"") = (self, s) => self.is_lref(s) || self.is_gref(s); 701 - SI.\\(""is_global"") = (self, s) => self.is_gvar(s) || self.is_gref(s); 702 - SI.\\(""is_local"") = (self, s) => self.is_lvar(s) || self.is_lref(s); 703 - SI.\\(""make_global"") = (self, s) => 704 - if(self.is_obj(s)) 705 - self.gvar 706 - else if(self.is_ref(s)) 707 - self.gref 708 - else 709 - throw ""$s cannot be made global.""; 710 - SI.\\(""make_local"") = (self, s) => 711 - if(self.is_obj(s)) 712 - self.lvar 713 - else if(self.is_ref(s)) 714 - self.lref 715 - else 716 - throw ""$s cannot be made local.""; 717 - SI.\\(""make_obj"") = (self, s) => 718 - if(self.is_local(s)) 719 - self.lvar 720 - else if(self.is_global(s)) 721 - self.gvar 722 - else 723 - throw ""$s cannot be made object.""; 724 - SI.\\(""make_ref"") = (self, s) => 725 - if(self.is_local(s)) 726 - self.lref 727 - else if(self.is_global(s)) 728 - self.gref 729 - else 730 - throw ""$s cannot be made reference.""; 731 - } 732 - 733 - build does hook(t => 734 - { 735 - //Promote local to global variables 736 - var init = t.$Function; 737 - 738 - if(init.Id != Prexonite::Application.InitializationId) 739 - return; 740 - 741 - var alreadyPromoted = []; 742 - foreach(var entry in init.Meta[""alreadyPromoted""].List) 743 - alreadyPromoted[] = entry.Text; 744 - 745 - 746 - var toPromote = []; 747 - foreach(var loc in init.Variables) 748 - unless(alreadyPromoted.Contains(loc)) 749 - toPromote[] = loc; 750 - 751 - foreach(var loc in toPromote) 752 - { 753 - if(not t.Symbols.TryGet(loc~String,->loc)) 754 - throw ""Cannot find $loc in hook.""; 755 - loc = Prexonite::Compiler::Symbolic::Compatibility::LegacyExtensions.ToSymbolEntry(loc); 756 - var glob = new ::SymbolEntry(SI.make_global(loc.Interpretation), loc.InternalId, asm(ldr.app).Module.Name); 757 - var ss = Prexonite::Compiler::Symbolic::Compatibility::LegacyExtensions.ToSymbol(glob); 758 - t.Loader.Symbols.Declare(loc.InternalId, ss); 759 - t.Loader.Options.TargetApplication.Variables[loc.InternalId] = new ::PVariable(loc.InternalId); 760 - var assignment = ast(""GetSetSymbol"", ::PCall.Set, glob); 761 - assignment.Arguments.Add(ast(""GetSetSymbol"", ::PCall.Get, loc)); 762 - t.Ast.Add(assignment); 763 - println(""Declared $glob""); 764 - } 765 - 766 - init.Meta[""alreadyPromoted""].AddToList(::MetaEntry.CreateArray(toPromote)); 767 - }); 768 - 769 - { 770 - var goo = 600; 771 - } 772 - 773 - { 774 - var goo2 = 780; 775 - } 776 - 777 - function main() 778 - { 779 - return ""goo = $goo; goo2 = $goo2;""; 780 - } 781 - "); 782 - Expect("goo = 600; goo2 = 780;"); 783 - } 784 - 785 - [Test] 786 663 public void CastAssign() 787 664 { 788 665 Compile(
+30 -7
PrexoniteTests/Tests/VMTestsBase.cs
··· 185 185 ExpectReturnValue(target.Meta[Application.EntryKey], expectedReturnValue, args); 186 186 } 187 187 188 + protected void Expect(Action<PValue> assertion, params PValue[] args) 189 + { 190 + ExpectReturnValue(target.Meta[Application.EntryKey], assertion, args); 191 + } 192 + 188 193 protected void ExpectNamed<T>(string functionId, T expectedReturnValue, params PValue[] args) 189 194 { 190 195 ExpectReturnValue(functionId, expectedReturnValue, args); ··· 192 197 193 198 protected void ExpectReturnValue<T>(string functionId, T expectedReturnValue, PValue[] args) 194 199 { 195 - if (!args.All(value => value != null)) 200 + ExpectReturnValue(functionId, rv => 201 + { 202 + var expected = engine.CreateNativePValue(expectedReturnValue); 203 + AssertPValuesAreEqual(expected, rv); 204 + }, args); 205 + } 206 + 207 + protected void ExpectReturnValue(string functionId, Action<PValue> assertion, PValue[] args) 208 + { 209 + if (assertion == null) 210 + throw new ArgumentNullException("assertion"); 211 + 212 + if (args.Any(value => value == null)) 196 213 throw new ArgumentException( 197 214 "Arguments must not contain naked CLR null references. Use `PType.Null`."); 198 215 199 - var expected = engine.CreateNativePValue(expectedReturnValue); 200 216 if (!target.Functions.Contains(functionId)) 201 217 throw new PrexoniteException("Function " + functionId + " cannot be found."); 202 - 203 - Console.WriteLine("Expecting " + functionId + " to return " + expected); 204 218 205 219 var func = target.Functions[functionId]; 206 220 if (func.Meta[StoreDebugImplementationKey].Switch) ··· 226 240 throw; 227 241 } 228 242 229 - AssertPValuesAreEqual(expected, rv); 243 + assertion(rv); 230 244 } 231 245 232 246 public void AssertPValuesAreEqual(PValue expected, PValue rv) ··· 266 280 267 281 protected void ExpectNull(params PValue[] args) 268 282 { 269 - ExpectReturnValue<object>(target.Meta[Application.EntryKey], null, args); 283 + var functionId = target.Meta[Application.EntryKey]; 284 + ExpectReturnValue(functionId, _buildIsNullAssertion(functionId), args); 270 285 } 271 286 272 287 protected void ExpectNull(string functionId, params PValue[] args) 273 288 { 274 - ExpectReturnValue<object>(functionId, null, args); 289 + ExpectReturnValue(functionId, _buildIsNullAssertion(functionId), args); 290 + } 291 + 292 + private static Action<PValue> _buildIsNullAssertion(string functionId) 293 + { 294 + return v => 295 + Assert.That(v.IsNull, Is.True, 296 + string.Format("Value returned from {0} is expected to be a null reference, was {1} instead.", 297 + functionId, v)); 275 298 } 276 299 277 300 protected PValue GetReturnValueNamed(string functionId, params PValue[] args)
+12 -24
PrexoniteTests/psr-tests/ast.test.pxs
··· 5 5 declare ast2\simple as ast2; 6 6 declare ast3\simple as ast3; 7 7 8 + function ast3 = call(ast3\simple(?), [get_unscoped_ast_factory], var args); 9 + 8 10 function compiler_is_loaded[test] 9 11 { 10 12 var found = null; ··· 26 28 27 29 assert(found is not Null, "After loading psr\\ast.pxs, one module in the compound should have 'compiler_loaded' enabled."); 28 30 } 31 + 32 + // Such a function is usually defined by macro.pxs, but we'll provide a simplified version 33 + // here to make testing of ast.pxs easier. 34 + // Do not use this implementation in actual code as it does not use the correct factory and 35 + // will not encode the caller's source position. 36 + function ast\call(entityref) 37 + { 38 + return ast3("IndirectCall",ast3("Reference",entityref)); 39 + } 29 40 30 41 function test_ast_withpos_null[test] 31 42 { ··· 120 131 121 132 function test_h_thisModule as thisModule = asm(ldr.app).Module.Name; 122 133 123 - function test_is_function_call[ 124 - is test; 125 - Add Prexonite to Imports; 126 - Add Prexonite::Compiler to Imports; 127 - Add Prexonite::Compiler::Ast to Imports; 128 - Add Prexonite::Types to Imports; 129 - ] 130 - { 131 - var func = ast("GetSetSymbol", 132 - new ::SymbolEntry(::SymbolInterpretations.Function,->test_is_function_call.Id, ->test_is_function_call.ParentApplication.Module.Name)); 133 - var nonFunc = ast("GetSetSymbol", ::SymbolEntry.Command(->test_is_function_call.Id)); 134 - var wrongFunc = ast("GetSetSymbol", 135 - new ::SymbolEntry(::SymbolInterpretations.Function,->test_unique_id_counter.Id, ->test_unique_id_counter.ParentApplication.Module.Name)); 136 - var notSym = ast("MacroInvocation", 137 - new ::SymbolEntry(::SymbolInterpretations.Function,->test_is_function_call.Id, ->test_is_function_call.ParentApplication.Module.Name)); 138 - 139 - var id = ->test_is_function_call.Id; 140 - assert(isFunctionCall(id, func), "Should recognize $func"); 141 - assert(not isFunctionCall(id, nonFunc), "Should reject $nonFunc"); 142 - assert(not isFunctionCall(id, wrongFunc), "Should reject $wrongFunc"); 143 - assert(not isFunctionCall(id, notSym), "Should reject $notSym"); 144 - } 145 - 146 134 function test_is_member_access[ 147 135 is test; 148 136 Add Prexonite to Imports; ··· 155 143 var mem = "member"; 156 144 var memacc = ast("GetSetMemberAccess", nt, mem); 157 145 var wrongmemacc = ast("GetSetMemberAccess", nt, "otherMember"); 158 - var notMemacc = ast("GetSetSymbol", new ::SymbolEntry(::SymbolInterpretations.Function, mem, thisModule)); 146 + var notMemacc = ast\call(entityref_to(test_is_member_access)); 159 147 160 148 assert(isMemberAccess(mem, memacc), "Should recognize $memacc"); 161 149 assert(not isMemberAccess(mem, wrongmemacc), "Should reject $wrongmemacc");
+9 -30
PrexoniteTests/psr-tests/macro.test.pxs
··· 198 198 199 199 function test_ast_is_effect[test] 200 200 { 201 - var isEffect = ast("GetSetSymbol", SI.get, SI.func(->test_ast_is_effect)); 201 + var isEffect = ast\call(entityref_to(test_ast_is_effect)); 202 202 var notEffect = ast3("CreateClosure",macro\entity(test_ast_is_effect)); 203 203 204 204 assert_eq(ast_is_effect(isEffect), true, "$(boxed(isEffect)) is a node."); ··· 209 209 210 210 function test_ast_is_partially_applicable[test] 211 211 { 212 - var pa = ast("GetSetSymbol", SI.get, SI.func(->test_ast_is_partially_applicable)); 212 + var pa = ast\call(entityref_to(test_ast_is_partially_applicable)); 213 213 var npa = ast3("CreateClosure", macro\entity(test_ast_is_partially_applicable)); 214 214 215 215 assert_eq(ast_is_partially_applicable(pa), true, "$(boxed(pa)) is partially applicable"); ··· 220 220 221 221 function test_ast_is_partial_application[test] 222 222 { 223 - var pa = ast("GetSetSymbol", SI.get, SI.func(->test_ast_is_partial_application)); 224 - pa.Arguments.Add(ast("Null")); 223 + var pa = ast\call(entityref_to(test_ast_is_partial_application)); 224 + pa.Arguments.Add(ast3("Null")); 225 225 226 226 assert_eq(ast_is_partial_application(pa), false, "$(boxed(pa)) is not a partial application (no placeholders)"); 227 227 228 - pa.Arguments.Add(ast("Placeholder")); 228 + pa.Arguments.Add(ast3("Placeholder")); 229 229 230 230 assert_eq(ast_is_partial_application(pa),true, "$(boxed(pa)) is a partial application"); 231 231 ··· 235 235 function test_ast_is_CreateClosure[test] 236 236 { 237 237 var cc = ast3("CreateClosure", macro\entity(test_ast_is_CreateClosure)); 238 - var ncc = ast("GetSetSymbol", SI.get, Si.func(->test_ast_is_CreateClosure)); 238 + var ncc = ast\call(entityref_to(test_ast_is_CreateClosure)); 239 239 240 240 assert_eq(ast_is_CreateClosure(cc),true,"$(boxed(cc)) is a CreateClosure node"); 241 241 assert_eq(ast_is_CreateClosure(ncc),false,"$(boxed(ncc)) is not a CreateClosure node"); ··· 244 244 245 245 function test_ast_is_node[test] 246 246 { 247 - var node = ast("Null"); 247 + var node = ast3("Null"); 248 248 var nonNode = new Structure; 249 249 var nonNode2 = new System::Object; 250 250 ··· 387 387 388 388 macro test_macro_internal_id[test] 389 389 { 390 - var invk = ast("MacroInvocation", SI.m.i.func("ast\\macro")); 390 + var invk = ast3("Expand", entityref_to(ast\macro)); 391 391 392 392 var c = call\macro([macro\internal_id(invk)]).Expression; 393 393 assert(ast_is_Constant(c),"$(boxed(c)) should be constant"); 394 394 395 - assert_eq(ast\read(c),"ast\\macro"); 396 - } 397 - 398 - macro test_macro_interpretation[test] 399 - { 400 - var invk1 = ast("MacroInvocation", SI.m.func("ast\\macro")); 401 - 402 - var c1 = call\macro([macro\interpretation(invk1)]).Expression; 403 - assert(ast_is_GetSetMemberAccess(c1),"$(boxed(c1)) should be get set member access"); 404 - assert_eq(c1.Id,"func","ast\\macro is implemented as a function (macro)"); 405 - 406 - var invk2 = ast("MacroInvocation", SI.m.cmd("call\\macro")); 407 - 408 - var c2 = call\macro([macro\interpretation(invk2)]).Expression; 409 - assert(ast_is_GetSetMemberAccess(c2),"$(boxed(c2)) should be get set member access"); 410 - assert_eq(c2.Id,"cmd","ast\\macro is implemented as a macro command"); 411 - 412 - var invk3 = ast("GetSetSymbol", SI.get, SI.i.func("test_macro_id_static")); 413 - 414 - var c3 = call\macro([macro\interpretation(invk3)]).Expression; 415 - assert(ast_is_GetSetMemberAccess(c3),"$(boxed(c3)) should be get set member access"); 416 - assert_eq(c3.Id,"func","test_macro_id_static is implemented as a function"); 395 + assert_eq(ast\read(c),entityref_to(ast\macro).Id); 417 396 } 418 397 419 398 function test_macro_entity_static[test]
+2 -2
PrexoniteTests/psr-tests/testconfig.txt
··· 1 - .\ast.test.pxs>|psr\impl\ast.pxs>>|compiler_is_loaded|test_ast_withpos_null|test_ast_withpos_memcall|test_ast_simple_memcall|test_ast_memcall|test_unique_id_counter|test_is_function_call|test_is_member_access|test_local_meta|test_si_fields|test_si_is_star|test_si_make_star|test_si_m_is_star|test_sub_blocks 1 + .\ast.test.pxs>|psr\impl\ast.pxs>>|compiler_is_loaded|test_ast_withpos_null|test_ast_withpos_memcall|test_ast_simple_memcall|test_ast_memcall|test_unique_id_counter|test_is_member_access|test_local_meta|test_si_fields|test_si_is_star|test_si_make_star|test_si_m_is_star|test_sub_blocks 2 2 .\lang-ext.test.pxs>|psr\impl\ast.pxs|psr\impl\macro.pxs<psr\impl\ast.pxs|psr\impl\struct.pxs<psr\impl\ast.pxs<psr\impl\macro.pxs|psr\impl\pattern.pxs<psr\impl\ast.pxs<psr\impl\macro.pxs<psr\impl\struct.pxs|psr\impl\prop.pxs<psr\impl\ast.pxs<psr\impl\macro.pxs>|psr\test\meta_macro.pxs>|test_con|test_dcon|test_prop_simple|test_prop_proxy|test_prop_complex|test_prop_simple_glob 3 - .\macro.test.pxs>|psr\impl\ast.pxs|psr\impl\macro.pxs<psr\impl\ast.pxs>|psr\test\meta_macro.pxs>|test_file|test_pos|test_is_in_macro|test_establish_macro_context|test_reports|test_ast_is_expression|test_ast_is_effect|test_ast_is_partially_applicable|test_ast_is_partial_application|test_ast_is_CreateClosure|test_ast_is_node|test_temp|test_optimize|test_read|test_macro_internal_id_static|test_macro_internal_id|test_macro_interpretation|test_macro_entity_static|test_expand_macro|test_ast_symbol|test_ast_member|test_ast_const|test_ast_ret|test_ast\with_arguments|test_ast\new|test_ast\null 3 + .\macro.test.pxs>|psr\impl\ast.pxs|psr\impl\macro.pxs<psr\impl\ast.pxs>|psr\test\meta_macro.pxs>|test_file|test_pos|test_is_in_macro|test_establish_macro_context|test_reports|test_ast_is_expression|test_ast_is_effect|test_ast_is_partially_applicable|test_ast_is_partial_application|test_ast_is_CreateClosure|test_ast_is_node|test_temp|test_optimize|test_read|test_macro_internal_id_static|test_macro_internal_id|test_macro_entity_static|test_expand_macro|test_ast_symbol|test_ast_member|test_ast_const|test_ast_ret|test_ast\with_arguments|test_ast\new|test_ast\null 4 4 .\misc.test.pxs>|psr\impl\ast.pxs|psr\impl\macro.pxs<psr\impl\ast.pxs|psr\impl\struct.pxs<psr\impl\ast.pxs<psr\impl\macro.pxs|psr\impl\misc.pxs<psr\impl\struct.pxs<psr\impl\ast.pxs<psr\impl\macro.pxs>>|test_cmp|test_cmp_values|test_cmp_keys|test_cmp_with|test_cmp_then|test_cmpr|test_ieq|test_ieq_any|test_ieq_all|test_refeq|test_nrefeq|test_create_terminator|test_swap 5 5 .\struct.test.pxs>|psr\impl\ast.pxs|psr\impl\macro.pxs<psr\impl\ast.pxs|psr\impl\struct.pxs<psr\impl\ast.pxs<psr\impl\macro.pxs|psr\impl\set.pxs<psr\impl\struct.pxs|psr\impl\queue.pxs<psr\impl\struct.pxs|psr\impl\stack.pxs<psr\impl\struct.pxs>>|test_struct|tsm_create|tsm_add_remove|tsi_create|tsi_add_remove|tqm_count|tqm_peek|tqm_dequeue|tqi_create|tqi_enqueuedequeue|tqi_nonserial|tm_count|tm_peek|tm_pop|tm_enumarte_pops|ti_create|ti_pushpop|ti_nonserial
+9 -4
Prx/psr/impl/ast.pxs
··· 43 43 44 44 if(factory is null) 45 45 throw "AST factory cannot be null."; 46 + 47 + if(type is null) 48 + throw "ast3(type, ...) the parameter `type` cannot be null."; 46 49 47 50 //return call\member(factory,type, targs); 48 51 return call(factory,[type],targs); ··· 50 53 51 54 function ast\withPos(type, file, line, column) [is compiler;] 52 55 { 56 + if(type is null) 57 + throw "ast(type, file, line, column, ...) the parameter `type` cannot be null."; 58 + 53 59 var args; 54 60 var targs = args >> skip(4); 55 61 ··· 122 128 } 123 129 function uniqueId(verb) [is compiler;] = "uniq\\" + verb + uniqueIdCounter++; 124 130 125 - function isFunctionCall(id, node)[is compiler;] = 126 - node is ::AstGetSetSymbol And 127 - node.Implementation.Interpretation~Int == ::SymbolInterpretations.Function~Int And 128 - Prexonite::Engine.StringsAreEqual(node.Implementation.InternalId, id.ToString); 131 + declare( 132 + isFunctionCall = error(here,"PSR.Obsolete",@"isFunctionCall is deprecated. Use checking functions from the psr\\macro instead.",null) 133 + ); 129 134 130 135 function isMemberAccess(id, node)[is compiler;] = 131 136 node is ::AstGetSetMemberAccess And
+101 -268
Prx/psr/impl/macro.pxs
··· 56 56 var macroInvocation = context.Invocation; 57 57 58 58 ref ast = ast\withPos(?,macroInvocation.File, macroInvocation.Line,macroInvocation.Column,?); 59 + ref ast3 = ast3\withPos(context.Factory,?,macroInvocation.Position,?); 59 60 60 61 if(SI.eq(context.Call,SI.set)) 61 62 { ··· 65 66 return false; 66 67 } 67 68 68 - var astCall = ast("GetSetSymbol", SI.get, SI.func(->ast\withPos)); 69 + var astCall = ast3("IndirectCall", ast3("Reference",entityref_to(ast\withPos)), SI.get); 69 70 70 71 var nodeFile; 71 72 var nodeLine; ··· 77 78 { 78 79 establish_macro_context(context); 79 80 80 - var getContext = ast("GetSetSymbol", 81 - SI.get,SI.lref(Prexonite::Compiler::MacroAliases.ContextAlias)); 81 + var getContext = ast3("IndirectCall",ast3("IndirectCall", ast3("Reference",SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)), SI.get), SI.get); 82 82 83 83 var getInvComp = ast("GetSetMemberAccess",SI.get,getContext,"Invocation"); 84 84 85 85 var invkV = context.AllocateTemporaryVariable(); 86 - var storeInvk = ast("GetSetSymbol", 87 - SI.set, SI.lvar(invkV)); 86 + var storeInvk = ast3("IndirectCall", ast3("Reference",SI.e.lvar(invkV)), SI.set); 88 87 storeInvk.Arguments.Add(getInvComp); 89 88 90 - var getInv = ast("GetSetSymbol",SI.get,SI.lvar(invkV)); 89 + var getInv = ast3("IndirectCall", ast3("Reference", SI.e.lvar(invkV)), SI.get); 91 90 92 91 nodeFile = ast("GetSetMemberAccess", SI.get, storeInvk, "File"); 93 92 nodeLine = ast("GetSetMemberAccess", SI.get, getInv, "Line"); ··· 115 114 var pos = context.Invocation.Position; 116 115 var create = context.Factory; 117 116 118 - var ctorNode = create.ObjectCreation(pos,create.ConstantTypeExpression("Object(\"Prexonite.Compiler.SourcePosition\")")); 119 - ctorNode.Arguments.Add(create.Constant(position.File)); 120 - ctorNode.Arguments.Add(create.Constant(position.Line)); 121 - ctorNode.Arguments.Add(create.Constant(position.Column)); 117 + var ctorNode = create.ObjectCreation(pos,create.ConstantTypeExpression(pos,"Object(\"Prexonite.Compiler.SourcePosition\")")); 118 + ctorNode.Arguments.Add(create.Constant(pos, position.File)); 119 + ctorNode.Arguments.Add(create.Constant(pos, position.Line)); 120 + ctorNode.Arguments.Add(create.Constant(pos, position.Column)); 122 121 return ctorNode; 123 122 } 124 123 ··· 129 128 var macroInvocation = context.Invocation; 130 129 131 130 ref ast = ast\withPos(?,macroInvocation.File, macroInvocation.Line,macroInvocation.Column,?); 131 + ref ast3 = ast3\withPos(context.Factory,?,macroInvocation.Position,?); 132 132 133 133 if(SI.eq(context.Call,SI.set)) 134 134 { ··· 138 138 return false; 139 139 } 140 140 141 - var astCall = ast("GetSetSymbol", SI.get, SI.func(->ast\withPos)); 141 + var astCall = ast3("IndirectCall", ast3("Reference", entityref_to(ast\withPos)), SI.get); 142 142 143 143 var nodePosition; 144 144 ··· 146 146 { 147 147 establish_macro_context(context); 148 148 149 - var getContext = ast("GetSetSymbol", 150 - SI.get,SI.lref(Prexonite::Compiler::MacroAliases.ContextAlias)); 149 + var getContext = ast3("IndirectCall", ast3("IndirectCall", ast3("Reference", SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)), SI.get), SI.get); 151 150 152 151 var getInvComp = ast("GetSetMemberAccess",SI.get,getContext,"Invocation"); 153 152 ··· 183 182 } 184 183 185 184 ref ast3 = ast3\withPos(context.Factory,?,context.Invocation.Position,?); 186 - var refNode = ast3("Reference",SI.e.func(->ast3\withPos)); 185 + var refNode = ast3("Reference",entityref_to(ast3\withPos)); 187 186 var astCallNode = ast3("IndirectCall",refNode,SI.get); 188 187 189 188 var getFactory; ··· 236 235 if(explicitContext is null) 237 236 { 238 237 establish_macro_context(context); 239 - getContext = ast("GetSetSymbol",SI.get,SI.lref(Prexonite::Compiler::MacroAliases.ContextAlias)); 238 + getContext = ast3("IndirectCall",ast3("IndirectCall",ast3("Reference", SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)), SI.get), SI.get); 240 239 } 241 240 else 242 241 { 243 242 getContext = explicitContext; 244 243 } 245 244 246 - var funcCall = ast("GetSetSymbol",SI.get,SI.func(->is_in_macro\impl)); 245 + var funcCall = ast3("IndirectCall", ast3("Reference", entityref_to(is_in_macro\impl)), SI.get); 247 246 funcCall.Arguments.Add(getContext); 248 247 return funcCall; 249 248 } ··· 252 251 { 253 252 establish_macro_context\impl(context); 254 253 255 - var estCall = ast("GetSetSymbol", SI.get, SI.func(->establish_macro_context\impl)); 256 - estCall.Arguments.Add(ast("GetSetSymbol", SI.get, SI.lref(Prexonite::Compiler::MacroAliases.ContextAlias))); 254 + var estCall = ast3("IndirectCall", ast3("Reference", entityref_to(establish_macro_context\impl)), SI.get); 255 + estCall.Arguments.Add(ast3("IndirectCall", ast3("IndirectCall", ast3("Reference", SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)), SI.get), SI.get)); 257 256 return estCall; 258 257 } 259 258 260 259 macro macro\get_context() 261 - { 262 - function create_getSI = ast3("IndirectCall",ast3("Reference",SI.e.func(->SI))); 263 - var astCall = ast3("Expand",SI.e.func(macro\reference(ast))); 264 - astCall.Arguments.AddRange([ 265 - ast("Constant","GetSetSymbol"), 266 - ast("GetSetMemberAccess",SI.get,new getSI,"get"), 267 - var lref = ast("GetSetMemberAccess",SI.get,new getSI,"lref"), 268 - ]); 269 - lref.Arguments.Add(ast("Constant",Prexonite::Compiler::MacroAliases.ContextAlias)); 270 - 271 - context.Block.Expression = astCall; 272 - return null; 260 + { 261 + // `SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)` 262 + var getSI = ast3("IndirectCall", ast3("Reference",entityref_to(SI))); 263 + var getSIEntity = ast3("MemberAccess", getSI, "e"); 264 + var getSIEntityLVar = ast3("MemberAccess", getSIEntity, "lvar"); 265 + getSIEntityLVar.Arguments.Add(ast3("Constant",Prexonite::Compiler::MacroAliases.ContextAlias)); 266 + 267 + // `ast3("Reference",SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias))` 268 + var refCtor = ast3("Expand",entityref_to(ast3)); 269 + refCtor.Arguments.Add(ast3("Constant","Reference")); 270 + refCtor.Arguments.Add(getSIEntityLVar); 271 + 272 + function dereference(node) 273 + { 274 + var ctor = ast3("Expand", entityref_to(ast3)); 275 + ctor.Arguments.Add(ast3("Constant","IndirectCall")); 276 + ctor.Arguments.Add(node); 277 + return ctor; 278 + } 279 + 280 + // `ast3("IndirectCall",ast3("IndirectCall",ast3("Reference",SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias))))` 281 + return dereference(dereference(refCtor)); 273 282 } 274 283 275 284 function macro\report_any(message, severity) ··· 320 329 { 321 330 if(context.IsJustEffect) 322 331 return; 323 - 324 - function create_getSI = ast("GetSetSymbol",SI.get,SI.func(->SI)); 325 332 326 - var mi = ast("MacroInvocation", SI.m.func("ast\\macro", macro\macro_pxs_module)); 327 - mi.Arguments.Add(ast("Constant","GetSetSymbol")); 328 - mi.Arguments.Add(ast("GetSetMemberAccess",new getSI,"get")); 329 - mi.Arguments.Add(var si_func = ast("GetSetMemberAccess",new getSI,"func")); 330 - si_func.Arguments.Add(ast("GetSetReference", SI.func(->SI))); 331 - 332 - context.Block.Expression = mi; 333 + // We need to construct the following expression: 334 + // `ast3("IndirectCall",ast3("Reference",entityref_to(->SI))` 335 + 336 + // `entityref_to(SI)` 337 + var SIentityRefNode = ast3("Expand",entityref_to(entityref_to)); 338 + SIentityRefNode.Arguments.Add(ast3("IndirectCall",ast3("Reference",entityref_to(SI)))); 339 + 340 + // `ast3("Reference", $SIentityRefNode)` 341 + var refCtor = ast3("Expand", entityref_to(ast3)); 342 + refCtor.Arguments.Add(ast3("Constant","Reference")); 343 + refCtor.Arguments.Add(SIentityRefNode); 344 + 345 + // `ast3("IndirectCall",$refCtor)` 346 + var indirectCallCtor = ast3("Expand",entityref_to(ast3)); 347 + indirectCallCtor.Arguments.Add(ast3("Constant","IndirectCall")); 348 + indirectCallCtor.Arguments.Add(refCtor); 349 + 350 + context.Block.Expression = indirectCallCtor; 351 + return; 333 352 } 334 353 335 354 macro tempalloc(getContext) ··· 365 384 } 366 385 else if(getContext is Null) 367 386 { 368 - macro\report_error("tempfree must either be called in a macro context, or be supplied a macroInvocation~Prexonite::Compiler::Ast::AstMacroInvocation"); 387 + macro\report_error("tempfree must either be called in a macro context, or be supplied a macro context."); 369 388 return; 370 389 } 371 390 ··· 396 415 //create function body {return <body>(node_arg, <args...>);} 397 416 var block = target.Ast; 398 417 block.Add(var ret = ast("Return",Prexonite::Compiler::Ast::ReturnVariant.Exit)); 399 - ret.Expression = var bodyMi = ast("MacroInvocation", body); 400 - bodyMi.Arguments.Add(ast("GetSetSymbol",SI.get,SI.lvar(node_arg))); 418 + ret.Expression = var bodyMi = ast3("Expand", body); 419 + bodyMi.Arguments.Add(ast3("IndirectCall", ast3("Reference", SI.e.lvar(node_arg)), SI.get)); 401 420 bodyMi.Arguments.AddRange(var args >> skip(3)); 402 421 403 422 //Have the body compiled ··· 446 465 // TODO: make create_global_variable available to build block code. 447 466 establish_macro_context; 448 467 449 - context.Block.Expression = var implCall = ast("GetSetSymbol", context.Call, SI.func(->create_global_variable\impl)); 468 + context.Block.Expression = var implCall = ast3("IndirectCall", ast3("Reference", entityref_to(create_global_variable\impl)), context.Call); 450 469 implCall.Arguments.Add(macro\get_context); 451 470 implCall.Arguments.AddRange(var args); 452 471 ··· 468 487 469 488 // //Ensure is object type in the first place 470 489 var arg_pt = tempalloc; 471 - function create_arg_pt(c) = ast("GetSetSymbol", c ?? SI.get, SI.lvar(arg_pt)); 490 + function create_arg_pt(c) = ast3("IndirectCall", ast3("Reference",SI.e.lvar(arg_pt)), c ?? SI.get); 472 491 473 492 var node_t = uniqueId(id + @"\node_t"); 474 - function create_node_t(c) = ast("GetSetSymbol",c ?? SI.get, SI.gvar(node_t, macro\macro_pxs_module)); 493 + function create_node_t(c) = ast3("IndirectCall", ast3("Reference", SI.e.gvar(node_t, macro\macro_pxs_module)), c ?? SI.get); 475 494 476 495 var node_t_var = new global_variable(node_t); 477 496 node_t_var.Meta["compiler"] = true; ··· 479 498 // if((var arg_pt = boxed(node_arg).Type) is not Prexonite::Types::ObjectPType) 480 499 // return false; 481 500 { 482 - var box_node_arg = ast("GetSetSymbol",SI.get,SI.cmd("boxed")); 501 + var box_node_arg = ast3("IndirectCall", ast3("Reference", entityref_to(boxed)), SI.get); 483 502 box_node_arg.Arguments.Add(new node_arg); 484 503 var set_arg_pt = new arg_pt(SI.set); 485 504 set_arg_pt.Arguments.Add(ast("GetSetMemberAccess", box_node_arg, "Type")); ··· 531 550 } 532 551 else 533 552 { 534 - var assignableAstNode = ast("GetSetMemberAccess", ast("GetSetSymbol", SI.get, SI.func(->AstNode_t)), 553 + var assignableAstNode = ast("GetSetMemberAccess", ast3("IndirectCall", ast3("Reference", entityref_to(AstNode_t)), SI.get), 535 554 "IsAssignableFrom"); 536 555 assignableAstNode.Arguments.Add(ast("GetSetMemberAccess", new arg_pt, "ClrType")); 537 556 ··· 541 560 542 561 context.Block.Expression = conjunction; 543 562 } 563 + return; 544 564 } 545 565 546 566 build ··· 552 572 >> where(AstNode_t.IsAssignableFrom(?)) 553 573 >> var node_ts; 554 574 555 - var impl = SI.m.func(asm(ldr.app).Functions[@"macro\_check_is_node_t"]); 575 + var impl = SI.e.func(asm(ldr.app).Functions[@"macro\_check_is_node_t"]); 556 576 557 577 foreach(new var node_t in node_ts) 558 578 { ··· 601 621 } 602 622 603 623 function ast_is_effect(n) = ast_is_Node(n); 624 + function ast_is_something_obsolete as ast_is_MacroInvocation, ast_is_GetSetSymbol, ast_is_GetSetReference(_)[\sps] = false; 625 + 626 + declare( 627 + ast_is_MacroInvocation = warn(pos("macro.pxs",607,0),"PSR.Obsolete",@"MacroInvocation nodes no longer exist. Use Expand instead.",sym "ast_is_MacroInvocation"), 628 + ast_is_GetSetSymbol = warn(pos("macro.pxs",608,0),"PSR.Obsolete",@"GetSetSymbol nodes no longer exist. Use IndirectCall of Reference instead.",sym "ast_is_GetSetSymbol"), 629 + ast_is_GetSetReference = warn(pos("macro.pxs",609,0),"PSR.Obsolete",@"GetSetReference nodes no longer exist. Use Reference instead.",sym "ast_is_GetSetReference") 630 + ); 604 631 605 632 //Optimization 606 633 function optimize\ref(context, ref node) [is compiler;] ··· 716 743 contextRef = macro\get_context; 717 744 } 718 745 719 - var fcall = context.Block.Expression = ast("GetSetSymbol", context.Call, SI.func(->ast\read\impl)); 746 + var fcall = context.Block.Expression = ast3("IndirectCall",ast3("Reference",entityref_to(ast\read\impl)),context.Call); 720 747 fcall.Arguments.Add(contextRef); 721 748 fcall.Arguments.Add(expr); 722 749 return true; ··· 724 751 725 752 function macro\_extract_id(prototype)[is compiler;] 726 753 { 727 - if(prototype is Prexonite::Compiler::Ast::AstMacroInvocation) 728 - return prototype.Implementation.InternalId; 729 - else if(prototype is Prexonite::Compiler::Ast::AstExpand) 754 + if(prototype is Prexonite::Compiler::Ast::AstExpand) 730 755 return prototype.Entity.Id; 731 756 else 732 757 return prototype.Subject.Entity.Id; ··· 762 787 var siMem; 763 788 if(ast_is_MacroInvocation(prototype)) 764 789 { 765 - var i = prototype.Implementation.Interpretation; 766 - if(SI.m.is_func(i)) 767 - siMem = "func"; 768 - else if(SI.m.is_cmd(i)) 769 - siMem = "cmd"; 770 - else { 771 - macro\report_error("Unkown macro interpretation $i. Assuming function"); 772 - siMem = "func"; 773 - } 774 - 775 - var getSI\m = ast("GetSetMemberAccess",SI.get,getSI,"m"); 776 - var getSI\m\i = ast("GetSetMemberAccess",SI.get,getSI\m,siMem); 777 - 778 - return getSI\m\i; 790 + macro\report_error("MacroInvocation no longer exists."); 791 + return; 779 792 } 780 793 else if(ast_is_GetSetSymbol(prototype)) 781 794 { ··· 810 823 } 811 824 812 825 // Converts `macro\entity(someCall)` into an expression that represents the entity "someCall" (an EntityRef). 813 - macro macro\entity(prototype) 814 - { 815 - if(context.IsJustEffect) 816 - return; 817 - 818 - var e; 819 - if(ast_is_Expand(prototype)) 820 - { 821 - e = prototype.Entity; 822 - } 823 - else if(ast_is_IndirectCall(prototype) and ast_is_Reference(prototype.Subject)) 824 - { 825 - e = prototype.Subject.Entity; 826 - } 827 - else 828 - { 829 - macro\report_error("macro\\entity cannot deal with invocations or expansions via legacy mechanisms. Offending prototype: $(prototype)."); 830 - return; 831 - } 832 - 833 - var internalId; 834 - var moduleName = null; 835 - var entityKind; 836 - if(SI.e.is_func(e)) 837 - { 838 - entityKind = "func"; 839 - internalId = e.Id; 840 - moduleName = e.ModuleName; 841 - } 842 - else if(SI.e.is_cmd(e)) 843 - { 844 - entityKind = "cmd"; 845 - internalId = e.Id; 846 - } 847 - else if(SI.e.is_mcmd(e)) 848 - { 849 - entityKind = "mcmd"; 850 - internalId = e.Id; 851 - } 852 - else if(SI.e.is_gvar) 853 - { 854 - entityKind = "gvar"; 855 - internalId = e.Id; 856 - moduleName = e.ModuleName; 857 - } 858 - else if(SI.e.is_lvar) 859 - { 860 - entityKind = "lvar"; 861 - internalId = e.Id; 862 - } 863 - else 864 - { 865 - macro\report_error("macro\\entity cannot handle unknown entity kind $(e)."); 866 - return; 867 - } 868 - 869 - internalId = ast3("Constant",internalId); 870 - if(moduleName is not null) 871 - { 872 - var create_module_name_reference = ast3("Reference",SI.e.cmd(Prexonite::Commands::Core::CreateModuleName.Alias)); 873 - var create_module_name_node = ast3("IndirectCall",create_module_name_reference,SI.get); 874 - create_module_name_node.Arguments.Add(ast3("Constant",moduleName.Id)); 875 - create_module_name_node.Arguments.Add(ast3("Constant",moduleName.Version.ToString())); 876 - moduleName = create_module_name_node; 877 - } 878 - 879 - var entityMode = ast3("MemberAccess",macro\getSI,"e",SI.get); 880 - var ctorCall = ast3("MemberAccess",entityMode,entityKind,context.Invocation.Call); 881 - ctorCall.Arguments.Add(internalId); 882 - if(moduleName is not null) 883 - ctorCall.Arguments.Add(moduleName); 884 - 885 - context.Block.Expression = ctorCall; 886 - return; 887 - } 888 - 889 - macro macro\symbol(prototype) 890 - { 891 - if(context.IsJustEffect) 892 - return; 893 - 894 - declare: macro\getSI as getSI; 895 - 896 - ref sym = prototype.Implementation(?); 897 - 898 - function mkModuleName 899 - { 900 - var mkModuleName = ast("GetSetSymbol", SI.get, SI.cmd(macro\internal_id(create_module_name))); 901 - mkModuleName.Arguments.Add(ast("Constant",sym.Module.ToString)); 902 - return mkModuleName; 903 - } 904 - 905 - var siMem; 906 - var modReq = false; 907 - if(ast_is_MacroInvocation(prototype)) 908 - { 909 - var i = sym.Interpretation; 910 - if(SI.m.is_func(i)) 911 - { 912 - siMem = "func"; 913 - modReq = true; 914 - } 915 - else if(SI.m.is_cmd(i)) 916 - { 917 - siMem = "cmd"; 918 - } 919 - else { 920 - macro\report_error("Unkown macro interpretation $i. Assuming function"); 921 - siMem = "func"; 922 - } 923 - 924 - var getSI\m = ast("GetSetMemberAccess",SI.get,getSI,"m"); 925 - var getSI\m\i = ast("GetSetMemberAccess",SI.get,getSI\m,siMem); 926 - getSI\m\i.Arguments.Add(ast("Constant",sym.InternalId)); 927 - if(modReq) 928 - getSI\m\i.Arguments.Add(mkModuleName); 929 - 930 - return getSI\m\i; 931 - } 932 - else if(ast_is_GetSetSymbol(prototype)) 933 - { 934 - var i = sym.Interpretation; 935 - 936 - if(SI.is_lvar(i)) 937 - siMem = "lvar"; 938 - else if(SI.is_lref(i)) 939 - siMem = "lref"; 940 - else if(SI.is_gvar(i)) 941 - { 942 - siMem = "gvar"; 943 - modReq = true; 944 - } 945 - else if(SI.is_gref(i)) 946 - { 947 - siMem = "gref"; 948 - modReq = true; 949 - } 950 - else if(SI.is_func(i)) 951 - { 952 - siMem = "func"; 953 - modReq = true; 954 - } 955 - else if(SI.is_cmd(i)) 956 - siMem = "cmd"; 957 - else if(SI.is_mcmd(i)) 958 - siMem = "mcmd"; 959 - else { 960 - macro\report_error("Unkown symbol interpretation $i. Assuming function"); 961 - siMem = "func"; 962 - } 963 - 964 - var getSI\i = ast("GetSetMemberAccess",SI.get,getSI,siMem); 965 - getSI\i.Arguments.Add(ast("Constant", sym.InternalId)); 966 - if(modReq) 967 - getSI\i.Arguments.Add(mkModuleName); 968 - 969 - return getSI\i; 970 - } 971 - else 972 - { 973 - macro\report_error("Cannot derive symbol entry from AST node $prototype."); 974 - } 975 - } 976 - 977 - declare macro\symbol as entityof; 826 + declare( 827 + macro\entity = warn(here,"PSR.Obsolete",@"macro\entity is a backwards-compatibility alias to entityref_to. Use that instead.",sym "entityref_to"), 828 + macro\symbol = error(here,"PSR.Obsolete",@"macro\symbol is deprecated. Use entityref_to instead.",null), 829 + ast\symbol = error(here,"PSR.Obsolete",@"ast\symbol is deprecated. Use EntityRef instead.",null), 830 + ast\invoke_macro = error(pos("macro.pxs",978,0),"PSR.Obsolete",@"ast\invoke_macro is obsolete. Use ast\expand_macro(macro\entity(yourMacro)) instead.",null) 831 + ); 978 832 979 833 macro ast\null 980 834 { 981 835 if(context.IsJustEffect) 982 836 return; 983 837 984 - var mi = ast("MacroInvocation", SI.m.func("ast\\macro",macro\macro_pxs_module)); 985 - mi.Arguments.Add(ast("Constant","Null")); 986 - 987 - context.Block.Expression = mi; 838 + var ctor = ast3("Expand",entityref_to(ast3)); 839 + ctor.Arguments.Add(ast3("Constant","Null")); 840 + context.Block.Expression = ctor; 841 + return; 988 842 } 989 - 990 - //Creates a macro invocation for the supplied macro 991 - declare( 992 - ast\invoke_macro = error(pos("macro.pxs",978,0),"PSR.Obsolete",@"ast\invoke_macro is obsolete. Use ast\expand_macro(macro\entity(yourMacro)) instead.",null) 993 - ); 994 843 995 844 macro ast\expand_macro(entity,callType) 996 845 { ··· 1013 862 c.Arguments.Add(callType ?? ast3("MemberAccess",macro\getSI,"get",SI.get)); 1014 863 1015 864 context.Block.Expression = c; 1016 - } 1017 - 1018 - macro ast\symbol(symbolInterpretation) 1019 - { 1020 - var args; 1021 - 1022 - if(args.Count < 2) 1023 - { 1024 - macro\report_error("Symbol description missing in symbol access node creation."); 1025 - return null; 1026 - } 1027 - 1028 - var c = ast\expand_macro(macro\entity(ast\macro)); 1029 - var getSI\si = ast3("MemberAccess",macro\getSI,ast\read(context, symbolInterpretation),SI.get); 1030 - var last = args[args.Count - 1]; 1031 - if(ast_is_ListLiteral(last)) 1032 - getSI\si.Arguments.AddRange(last.Elements); 1033 - else 1034 - getSI\si.Arguments.Add(last); 1035 - c.Arguments.Add(ast3("Constant", "GetSetSymbol")); 1036 - c.Arguments.AddRange(args >> skip(1) >> take(args.Count-2)); 1037 - c.Arguments.Add(getSI\si); 1038 - //println(context.Function," LINE ", context.Invocation.Line, " :: ", c); 1039 - return c; 865 + return; 1040 866 } 1041 867 1042 868 macro ast\call(callTypeExpr,entityExpr) ··· 1061 887 1062 888 // ast3("IndirectCall",ast3("Reference",$(entity)),$(callType)); 1063 889 1064 - var referenceCtor = ast\expand_macro(macro\entity(ast3)); 890 + var referenceCtor = ast\expand_macro(entityref_to(ast3)); 1065 891 referenceCtor.Arguments.Add(ast3("Constant","Reference")); 1066 892 referenceCtor.Arguments.Add(entityExpr); 1067 893 1068 - var indirectCallCtor = ast\expand_macro(macro\entity(ast3)); 894 + var indirectCallCtor = ast\expand_macro(entityref_to(ast3)); 1069 895 indirectCallCtor.Arguments.Add(ast3("Constant","IndirectCall")); 1070 896 indirectCallCtor.Arguments.Add(referenceCtor); 1071 897 indirectCallCtor.Arguments.Add(callTypeExpr); 1072 898 1073 899 context.Block.Expression = indirectCallCtor; 900 + return; 1074 901 } 1075 902 1076 903 macro ast\cmd(callType,id) ··· 1103 930 callExpansion.Arguments.Add(entityExpr); 1104 931 1105 932 context.Block.Expression = callExpansion; 933 + return; 1106 934 } 1107 935 1108 936 macro ast\lvar(callType,id) ··· 1135 963 callExpansion.Arguments.Add(entityExpr); 1136 964 1137 965 context.Block.Expression = callExpansion; 966 + return; 1138 967 } 1139 968 1140 969 macro ast\lref(callType,id) ··· 1176 1005 indirectCallCtor.Arguments.Add(callType); 1177 1006 1178 1007 context.Block.Expression = indirectCallCtor; 1008 + return; 1179 1009 } 1180 1010 1181 1011 macro ast\func(callType,internalId,moduleName) ··· 1212 1042 callExpansion.Arguments.Add(entityExpr); 1213 1043 1214 1044 context.Block.Expression = callExpansion; 1045 + return; 1215 1046 } 1216 1047 1217 1048 macro ast\gvar(callType,internalId,moduleName) ··· 1246 1077 callExpansion.Arguments.Add(entityExpr); 1247 1078 1248 1079 context.Block.Expression = callExpansion; 1080 + return; 1249 1081 } 1250 1082 1251 1083 macro ast\gref(callType,internalId,moduleName) ··· 1289 1121 indirectCallCtor.Arguments.Add(callType); 1290 1122 1291 1123 context.Block.Expression = indirectCallCtor; 1124 + return; 1292 1125 } 1293 1126 //Create GetSetMemberAccess node 1294 1127 macro ast\member(subject, call_type, id) ··· 1357 1190 if(ast_is_Null(value) or (ast_is_Constant(value) and value.Constant is null)) 1358 1191 { 1359 1192 var c = ast\expand_macro(macro\entity(ast\macro)); 1360 - c.Arguments.Add(ast("Constant","Null")); 1193 + c.Arguments.Add(ast3("Constant","Null")); 1361 1194 return c; 1362 1195 } 1363 1196 else if(ast_is_Constant(value)) 1364 1197 { 1365 1198 var c = ast\expand_macro(macro\entity(ast\macro)); 1366 - c.Arguments.Add(ast("Constant","Constant")); 1199 + c.Arguments.Add(ast3("Constant","Constant")); 1367 1200 c.Arguments.Add(value); 1368 1201 return c; 1369 1202 }
+4 -2
Prx/psr/test/meta_macro.pxs
··· 49 49 var block = funcTar.Ast; 50 50 51 51 //Setup invocation of test macro 52 - var invocation = new ::AstMacroInvocation(fakeFile,-1,-1, 53 - new ::SymbolEntry(::SymbolInterpretations.Function,testMacro.Id, testMacro.ParentApplication.Module.Name)); 52 + var invocation = new ::AstExpand( 53 + Prexonite::Compiler::NoSourcePosition.Instance, 54 + ~Object<"Prexonite.Modular.EntityRef+Function">.Create(testMacro.Id, testMacro.ParentApplication.Module.Name), 55 + Prexonite::Types::PCall.Get); 54 56 block.Add(invocation); 55 57 56 58 //Compile host function