···359359 private AstExpr _resolveImplementation(ISourcePosition position, Func<AstGetSet, AstExpr> impl, string id)
360360 {
361361 Symbol operatorSymbol;
362362- CurrentBlock.Symbols.TryGet(id, out operatorSymbol);
363363- var expr = ExprFor(position, operatorSymbol);
362362+ var expr = CurrentBlock.Symbols.TryGet(id, out operatorSymbol)
363363+ ? ExprFor(position, operatorSymbol)
364364+ : new AstUnresolved(position, id);
364365 var call = expr as AstGetSet;
365366 if(call == null)
366367 ReportMessage(Message.Error(string.Format(Resources.AstFactoryBase__resolveImplementation_LValueExpected, id),position, MessageClasses.LValueExpected));
···418419 // Create "not ?"
419420 var notId = OperatorNames.Prexonite.GetName(UnaryOperator.LogicalNot);
420421 Symbol notSymbol;
421421- CurrentBlock.Symbols.TryGet(notId, out notSymbol);
422422- var notOp = ExprFor(position, notSymbol);
422422+ var notOp = CurrentBlock.Symbols.TryGet(notId, out notSymbol)
423423+ ? ExprFor(position, notSymbol)
424424+ : new AstUnresolved(position, notId);
423425 var notCall = notOp as AstGetSet;
424426 if (notCall == null)
425427 {
···452454 var id = OperatorNames.Prexonite.GetName(op);
453455 Symbol symbol;
454456 CurrentBlock.Symbols.TryGet(id, out symbol);
455455- var callExpr = ExprFor(position, symbol);
457457+ var callExpr = CurrentBlock.Symbols.TryGet(id, out symbol)
458458+ ? ExprFor(position, symbol)
459459+ : new AstUnresolved(position, id);
456460 var callLValue = callExpr as AstGetSet;
457461 if (callLValue == null)
458462 {
···470474 case UnaryOperator.PostIncrement:
471475 case UnaryOperator.PostDecrement:
472476 {
473473- var legacySymbol = operand as AstGetSetSymbol;
474474-475477 var symbolCall = operand as AstIndirectCall;
476478 var symbol = symbolCall == null ? null : symbolCall.Subject as AstReference;
477479 EntityRef.Variable variableRef;
478480 var complex = operand as AstGetSet;
479481480480- var isLegacyVariable = legacySymbol != null && legacySymbol.IsObjectVariable;
481482 var isVariable = symbol != null && symbol.Entity.TryGetVariable(out variableRef);
482483483484 var isAssignable = complex != null;
···485486 var isIncrement = op == UnaryOperator.PostIncrement ||
486487 op == UnaryOperator.PreIncrement;
487488488488-489489- if (isLegacyVariable || isVariable)
489489+ if (isVariable)
490490 {
491491 return new AstUnaryOperator(position, op,operand);
492492 }
-201
Prexonite/Compiler/AST/AstGetSetReference.cs
···11-// Prexonite
22-//
33-// Copyright (c) 2011, Christian Klauser
44-// All rights reserved.
55-//
66-// Redistribution and use in source and binary forms, with or without modification,
77-// are permitted provided that the following conditions are met:
88-//
99-// Redistributions of source code must retain the above copyright notice,
1010-// this list of conditions and the following disclaimer.
1111-// Redistributions in binary form must reproduce the above copyright notice,
1212-// this list of conditions and the following disclaimer in the
1313-// documentation and/or other materials provided with the distribution.
1414-// The names of the contributors may be used to endorse or
1515-// promote products derived from this software without specific prior written permission.
1616-//
1717-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1818-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1919-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2020-// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2121-// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2222-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2323-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2424-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
2525-// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626-2727-using System;
2828-using System.Collections.Generic;
2929-using Prexonite.Compiler.Macro.Commands;
3030-using Prexonite.Properties;
3131-using Prexonite.Types;
3232-3333-namespace Prexonite.Compiler.Ast
3434-{
3535- public class AstGetSetReference : AstGetSetSymbol
3636- {
3737- public AstGetSetReference(string file, int line, int column, PCall call, SymbolEntry implementation)
3838- : base(file, line, column, call, implementation)
3939- {
4040- }
4141-4242- public AstGetSetReference(string file, int line, int column, SymbolEntry implementation)
4343- : base(file, line, column, PCall.Get, implementation)
4444- {
4545- }
4646-4747- internal AstGetSetReference(Parser p, PCall call, SymbolEntry implementation)
4848- : base(p.scanner.File, p.t.line, p.t.col, call, implementation)
4949- {
5050- }
5151-5252- internal AstGetSetReference(Parser p, SymbolEntry implementation)
5353- : base(p, PCall.Get, implementation)
5454- {
5555- }
5656-5757- protected override void EmitGetCode(CompilerTarget target, StackSemantics stackSemantics)
5858- {
5959- var justEffect = stackSemantics == StackSemantics.Effect;
6060- if (justEffect)
6161- return;
6262- switch (Implementation.Interpretation)
6363- {
6464- case SymbolInterpretations.Command:
6565- target.Emit(Position,OpCode.ldr_cmd, Implementation.InternalId);
6666- break;
6767- case SymbolInterpretations.Function:
6868- PFunction func;
6969- //Check if the function is a macro (Cannot create references to macros)
7070- if(target.Loader.ParentApplication.TryGetFunction(Implementation.InternalId, Implementation.Module, out func)
7171- && func.IsMacro)
7272- {
7373- target.Loader.ReportMessage(Message.Create(MessageSeverity.Warning,
7474- string.Format(
7575- "Reference to macro {0} detected. Prexonite version {1} treats this " +
7676- "as a partial application. This behavior might change in the future. " +
7777- "Use partial application syntax explicitly {0}(?) or use the {2} command " +
7878- "to obtain a reference to the macro.",
7979- Implementation, Engine.PrexoniteVersion,
8080- Reference.Alias), Position,
8181- MessageClasses.ReferenceToMacro));
8282-8383- _emitAsPartialApplication(target);
8484- }
8585- else
8686- {
8787- target.Emit(Position,OpCode.ldr_func, Implementation.InternalId, target.ToInternalModule(Implementation.Module));
8888- }
8989- break;
9090- case SymbolInterpretations.GlobalObjectVariable:
9191- target.Emit(Position,OpCode.ldr_glob, Implementation.InternalId, target.ToInternalModule(Implementation.Module));
9292- break;
9393- case SymbolInterpretations.GlobalReferenceVariable:
9494- target.EmitLoadGlobal(Position, Implementation.InternalId, Implementation.Module);
9595- break;
9696- case SymbolInterpretations.LocalObjectVariable:
9797- target.Emit(Position,OpCode.ldr_loc, Implementation.InternalId);
9898- break;
9999- case SymbolInterpretations.LocalReferenceVariable:
100100- target.Emit(Position,OpCode.ldloc, Implementation.InternalId);
101101- break;
102102- case SymbolInterpretations.MacroCommand:
103103- target.Loader.ReportMessage(Message.Create(MessageSeverity.Warning,
104104- string.Format(
105105- Resources.AstGetSetReference_ReferenceToMacroTreatedAsPartialApplication,
106106- Implementation.InternalId, Engine.PrexoniteVersion, Reference.Alias), Position, MessageClasses.ReferenceToMacro));
107107-108108- _emitAsPartialApplication(target);
109109-110110- break;
111111- default:
112112- target.Loader.ReportMessage(
113113- Message.Create(
114114- MessageSeverity.Error,
115115- string.Format(
116116- Resources.AstGetSetReference_CannotCreateReference,
117117- Enum.GetName(
118118- typeof (SymbolInterpretations), Implementation.Interpretation),
119119- Implementation.InternalId), Position, MessageClasses.InvalidReference));
120120- target.EmitNull(Position);
121121- break;
122122- }
123123- }
124124-125125- private void _emitAsPartialApplication(CompilerTarget target)
126126- {
127127- var pa = new AstMacroInvocation(File, Line, Column, Implementation) {Call = Call};
128128- pa.Arguments.Add(new AstPlaceholder(File, Line, Column, 0));
129129- var ipa = (AstExpr) pa;
130130- _OptimizeNode(target, ref ipa);
131131- ipa.EmitValueCode(target);
132132- }
133133-134134- //"Assigning to a reference"
135135- protected override void EmitSetCode(CompilerTarget target)
136136- {
137137- switch (Implementation.Interpretation)
138138- {
139139- case SymbolInterpretations.Command:
140140- case SymbolInterpretations.Function:
141141- case SymbolInterpretations.JumpLabel:
142142- case SymbolInterpretations.KnownType:
143143- throw new PrexoniteException(
144144-// ReSharper disable PossibleNullReferenceException
145145- string.Format(Resources.AstGetSetReference_CannotAssignReference, (Enum.GetName(typeof(SymbolInterpretations), Implementation.Interpretation) ?? Enum.GetName(typeof(SymbolInterpretations),SymbolInterpretations.Undefined)).ToLower()));
146146-// ReSharper restore PossibleNullReferenceException
147147-148148- //Variables are not automatically dereferenced
149149- case SymbolInterpretations.GlobalObjectVariable:
150150- case SymbolInterpretations.GlobalReferenceVariable:
151151- target.EmitStoreGlobal(Position, Implementation.InternalId, Implementation.Module);
152152- break;
153153- case SymbolInterpretations.LocalObjectVariable:
154154- case SymbolInterpretations.LocalReferenceVariable:
155155- target.EmitStoreLocal(Position, Implementation.InternalId);
156156- break;
157157- }
158158- }
159159-160160- #region ICanBeReferenced Members
161161-162162- public override bool TryToReference(out AstExpr reference)
163163- {
164164- reference = null;
165165- switch (Implementation.Interpretation)
166166- {
167167- case SymbolInterpretations.Command:
168168- case SymbolInterpretations.Function:
169169- case SymbolInterpretations.JumpLabel:
170170- case SymbolInterpretations.KnownType:
171171- case SymbolInterpretations.GlobalObjectVariable:
172172- case SymbolInterpretations.LocalObjectVariable:
173173- return false;
174174-175175- //Variables are not automatically dereferenced
176176-177177- case SymbolInterpretations.GlobalReferenceVariable:
178178- reference =
179179- new AstGetSetReference(
180180- File,
181181- Line,
182182- Column,
183183- PCall.Get, Implementation.With(SymbolInterpretations.GlobalObjectVariable));
184184- break;
185185-186186- case SymbolInterpretations.LocalReferenceVariable:
187187- reference =
188188- new AstGetSetReference(
189189- File,
190190- Line,
191191- Column,
192192- PCall.Get, Implementation.With(SymbolInterpretations.LocalObjectVariable));
193193- break;
194194- }
195195-196196- return reference != null;
197197- }
198198-199199- #endregion
200200- }
201201-}
-210
Prexonite/Compiler/AST/AstGetSetSymbol.cs
···11-// Prexonite
22-//
33-// Copyright (c) 2011, Christian Klauser
44-// All rights reserved.
55-//
66-// Redistribution and use in source and binary forms, with or without modification,
77-// are permitted provided that the following conditions are met:
88-//
99-// Redistributions of source code must retain the above copyright notice,
1010-// this list of conditions and the following disclaimer.
1111-// Redistributions in binary form must reproduce the above copyright notice,
1212-// this list of conditions and the following disclaimer in the
1313-// documentation and/or other materials provided with the distribution.
1414-// The names of the contributors may be used to endorse or
1515-// promote products derived from this software without specific prior written permission.
1616-//
1717-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1818-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1919-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2020-// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2121-// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2222-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2323-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2424-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
2525-// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626-2727-using System;
2828-using System.Collections.Generic;
2929-using System.Diagnostics;
3030-using Prexonite.Types;
3131-3232-namespace Prexonite.Compiler.Ast
3333-{
3434- public class AstGetSetSymbol : AstGetSet, IAstPartiallyApplicable
3535- {
3636- public SymbolEntry Implementation { get; set; }
3737-3838- public AstGetSetSymbol(
3939- string file,
4040- int line,
4141- int column,
4242- PCall call,
4343- SymbolEntry symbol)
4444- : base(file, line, column, call)
4545- {
4646- if (symbol == null)
4747- throw new ArgumentNullException("symbol");
4848-4949- Implementation = symbol;
5050- }
5151-5252- public AstGetSetSymbol(string file, int line, int column, SymbolEntry symbol)
5353- : this(file, line, column, PCall.Get, symbol)
5454- {
5555- }
5656-5757- internal AstGetSetSymbol(Parser p, PCall call, SymbolEntry symbol)
5858- : this(p.scanner.File, p.t.line, p.t.col, call, symbol)
5959- {
6060- }
6161-6262- internal AstGetSetSymbol(Parser p, SymbolEntry symbol)
6363- : this(p, PCall.Get, symbol)
6464- {
6565- }
6666-6767- protected override void EmitGetCode(CompilerTarget target, StackSemantics stackSemantics)
6868- {
6969- var justEffect = stackSemantics == StackSemantics.Effect;
7070- switch (Implementation.Interpretation)
7171- {
7272- case SymbolInterpretations.Command:
7373- target.EmitCommandCall(Position, Arguments.Count, Implementation.InternalId, justEffect);
7474- break;
7575- case SymbolInterpretations.Function:
7676- target.EmitFunctionCall(Position, Arguments.Count, Implementation.InternalId, Implementation.Module, justEffect);
7777- break;
7878- case SymbolInterpretations.GlobalObjectVariable:
7979- if (!justEffect)
8080- target.EmitLoadGlobal(Position, Implementation.InternalId, Implementation.Module);
8181- break;
8282- case SymbolInterpretations.LocalObjectVariable:
8383- if (!justEffect)
8484- target.EmitLoadLocal(Position, Implementation.InternalId);
8585- break;
8686- case SymbolInterpretations.LocalReferenceVariable:
8787- target.Emit(Position,Instruction.CreateLocalIndirectCall(Arguments.Count, Implementation.InternalId, justEffect));
8888- break;
8989- case SymbolInterpretations.GlobalReferenceVariable:
9090- target.Emit(Position,Instruction.CreateGlobalIndirectCall(Arguments.Count, Implementation.InternalId, target.ToInternalModule(Implementation.Module), justEffect));
9191- break;
9292- default:
9393- throw new PrexoniteException(
9494- "Invalid self " +
9595- Enum.GetName(typeof (SymbolInterpretations), Implementation.Interpretation) +
9696- " in AST.");
9797- }
9898- }
9999-100100- protected override void EmitSetCode(CompilerTarget target)
101101- {
102102- const bool justEffect = true;
103103-104104- switch (Implementation.Interpretation)
105105- {
106106- case SymbolInterpretations.Command:
107107- target.EmitCommandCall(Position, Arguments.Count, Implementation.InternalId, justEffect);
108108- break;
109109- case SymbolInterpretations.Function:
110110- target.EmitFunctionCall(Position, Arguments.Count, Implementation.InternalId, Implementation.Module, justEffect);
111111- break;
112112- case SymbolInterpretations.GlobalObjectVariable:
113113- target.EmitStoreGlobal(Position, Implementation.InternalId, Implementation.Module);
114114- break;
115115- case SymbolInterpretations.LocalReferenceVariable:
116116- target.Emit(Position,Instruction.CreateLocalIndirectCall(Arguments.Count, Implementation.InternalId, justEffect));
117117- break;
118118- case SymbolInterpretations.GlobalReferenceVariable:
119119- target.Emit(Position,Instruction.CreateGlobalIndirectCall(Arguments.Count, Implementation.InternalId, target.ToInternalModule(Implementation.Module), justEffect));
120120- break;
121121- case SymbolInterpretations.LocalObjectVariable:
122122- target.EmitStoreLocal(Position, Implementation.InternalId);
123123- break;
124124- default:
125125- throw new PrexoniteException(
126126- string.Format("Invalid self {0} in AST.", Implementation));
127127- }
128128- }
129129-130130- public bool IsObjectVariable
131131- {
132132- get
133133- {
134134- return
135135- Implementation.Interpretation == SymbolInterpretations.GlobalObjectVariable ||
136136- Implementation.Interpretation == SymbolInterpretations.LocalObjectVariable;
137137- }
138138- }
139139-140140- public bool IsVariable
141141- {
142142- get
143143- {
144144- return
145145- Implementation.Interpretation == SymbolInterpretations.GlobalObjectVariable ||
146146- Implementation.Interpretation == SymbolInterpretations.GlobalReferenceVariable ||
147147- Implementation.Interpretation == SymbolInterpretations.LocalObjectVariable ||
148148- Implementation.Interpretation == SymbolInterpretations.LocalReferenceVariable;
149149- }
150150- }
151151-152152- public override AstGetSet GetCopy()
153153- {
154154- AstGetSet copy = new AstGetSetSymbol(File, Line, Column, Call, Implementation);
155155- CopyBaseMembers(copy);
156156- return copy;
157157- }
158158-159159- public override string ToString()
160160- {
161161- return
162162- base.ToString() +
163163- String.Format(
164164- " {0}-{1} {2}{3}",
165165- Enum.GetName(typeof (SymbolInterpretations), Implementation.Interpretation),
166166- Implementation.InternalId,
167167- ArgumentsToString(), Implementation.Module == null ? "" : (" from " + Implementation.Module));
168168- }
169169-170170- #region ICanBeReferenced Members
171171-172172- public virtual bool TryToReference(out AstExpr result)
173173- {
174174- result = null;
175175- switch (Implementation.Interpretation)
176176- {
177177- case SymbolInterpretations.Function:
178178- case SymbolInterpretations.GlobalObjectVariable:
179179- case SymbolInterpretations.LocalObjectVariable:
180180- case SymbolInterpretations.LocalReferenceVariable:
181181- case SymbolInterpretations.GlobalReferenceVariable:
182182- case SymbolInterpretations.Command:
183183- result =
184184- new AstGetSetReference(File, Line, Column, PCall.Get, Implementation);
185185- break;
186186- }
187187-188188- return result != null;
189189- }
190190-191191- #endregion
192192-193193- #region Implementation of IAstPartiallyApplicable
194194-195195- public void DoEmitPartialApplicationCode(CompilerTarget target)
196196- {
197197- AstExpr refNode;
198198- if (!TryToReference(out refNode))
199199- throw new PrexoniteException("Cannot partially apply " + this +
200200- " because it can't be converted to a reference.");
201201-202202- var indTemplate = new AstIndirectCall(File, Line, Column, Call, refNode);
203203- indTemplate.Arguments.AddRange(Arguments);
204204- Debug.Assert(indTemplate.CheckForPlaceholders());
205205- indTemplate.EmitValueCode(target);
206206- }
207207-208208- #endregion
209209- }
210210-}
-15
Prexonite/Compiler/AST/AstIndirectCall.cs
···258258 base.TryOptimize(target, out expr);
259259 _OptimizeNode(target, ref Subject);
260260261261- //Try to replace { ldloc var ; indarg.x } by { indloc.x var } (same for glob)
262262- var symbol = Subject as AstGetSetSymbol;
263263- if (symbol != null && symbol.IsObjectVariable)
264264- {
265265- var kind =
266266- symbol.Implementation.Interpretation == SymbolInterpretations.GlobalObjectVariable
267267- ? SymbolInterpretations.GlobalReferenceVariable
268268- : SymbolInterpretations.LocalReferenceVariable;
269269- var refcall =
270270- new AstGetSetSymbol(File, Line, Column, Call, symbol.Implementation.With(kind));
271271- refcall.Arguments.AddRange(Arguments);
272272- expr = refcall;
273273- return true;
274274- }
275275-276261 expr = null;
277262 return false;
278263 }
-112
Prexonite/Compiler/AST/AstMacroInvocation.cs
···11-// Prexonite
22-//
33-// Copyright (c) 2011, Christian Klauser
44-// All rights reserved.
55-//
66-// Redistribution and use in source and binary forms, with or without modification,
77-// are permitted provided that the following conditions are met:
88-//
99-// Redistributions of source code must retain the above copyright notice,
1010-// this list of conditions and the following disclaimer.
1111-// Redistributions in binary form must reproduce the above copyright notice,
1212-// this list of conditions and the following disclaimer in the
1313-// documentation and/or other materials provided with the distribution.
1414-// The names of the contributors may be used to endorse or
1515-// promote products derived from this software without specific prior written permission.
1616-//
1717-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1818-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1919-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2020-// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2121-// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2222-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2323-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2424-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
2525-// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626-2727-using System;
2828-using System.Diagnostics;
2929-using Prexonite.Compiler.Macro;
3030-using Prexonite.Types;
3131-3232-namespace Prexonite.Compiler.Ast
3333-{
3434- public sealed class AstMacroInvocation : AstGetSet
3535- {
3636- private readonly SymbolEntry _implementation;
3737-3838- public AstMacroInvocation(string file, int line, int column, SymbolEntry implementation) : base(file, line, column, PCall.Get)
3939- {
4040- if (implementation == null)
4141- throw new ArgumentNullException("implementation");
4242- _implementation = implementation;
4343- }
4444-4545- internal AstMacroInvocation(Parser p, SymbolEntry implementation)
4646- : base(p, PCall.Get)
4747- {
4848- _implementation = implementation;
4949- }
5050-5151- public SymbolEntry Implementation
5252- {
5353- get { return _implementation; }
5454- }
5555-5656- protected override void EmitGetCode(CompilerTarget target, StackSemantics stackSemantics)
5757- {
5858- throw new NotSupportedException(
5959- "Macro invocation requires a different mechanic. Use AstGetSet.EmitCode instead.");
6060- }
6161-6262- protected override void EmitSetCode(CompilerTarget target)
6363- {
6464- throw new NotSupportedException(
6565- "Macro invocation requires a different mechanic. Use AstGetSet.EmitCode instead.");
6666- }
6767-6868- protected override void DoEmitCode(CompilerTarget target, StackSemantics stackSemantics)
6969- {
7070- //instantiate macro for the current target
7171- MacroSession session = null;
7272-7373- try
7474- {
7575- //Acquire current macro session
7676- session = target.AcquireMacroSession();
7777-7878- //Expand macro
7979- var justEffect = stackSemantics == StackSemantics.Effect;
8080- var node = session.ExpandMacro(this, justEffect);
8181-8282- //Emit generated code
8383- node.EmitCode(target, stackSemantics);
8484- }
8585- finally
8686- {
8787- if (session != null)
8888- target.ReleaseMacroSession(session);
8989- }
9090- }
9191-9292- public override bool TryOptimize(CompilerTarget target, out AstExpr expr)
9393- {
9494- //Do not optimize the macros arguments! They should be passed to the macro in their original form.
9595- // the macro should decide whether or not to apply AST-optimization to the arguments or not.
9696- expr = null;
9797- return false;
9898- }
9999-100100- public override AstGetSet GetCopy()
101101- {
102102- var macro = new AstMacroInvocation(File, Line, Column, Implementation);
103103- CopyBaseMembers(macro);
104104- return macro;
105105- }
106106-107107- public override string ToString()
108108- {
109109- return string.Format("{0} {1}{2}", base.ToString(), Implementation, ArgumentsToString());
110110- }
111111- }
112112-}
+2-31
Prexonite/Compiler/AST/AstReturn.cs
···124124 {
125125 if (_optimizeConditionalReturnExpression(target))
126126 return;
127127-128128- var symbol = Expression as AstGetSetSymbol;
129127 var indirectCall = Expression as AstIndirectCall;
130128131131- AstExpr reference;
132132- if ( symbol != null
133133- && !symbol.IsObjectVariable
134134- && symbol.TryToReference(out reference)
135135- && _isStacklessRecursionPossible(target, symbol))
129129+ if (indirectCall != null
130130+ && _isStacklessRecursionPossible(target, indirectCall))
136131 {
137132 // specialized approach
138133 // self(arg1, arg2, ..., argn) => { param1 = arg1; param2 = arg2; ... paramn = argn; goto 0; }
139139- _emitRecursiveTailCall(target, symbol.Arguments);
140140- }
141141- else if (indirectCall != null
142142- && _isStacklessRecursionPossible(target, indirectCall))
143143- {
144134 _emitRecursiveTailCall(target, indirectCall.Arguments);
145135 }
146136 else
···176166 {
177167 Expression.EmitValueCode(target);
178168 target.Emit(Position, OpCode.ret_value);
179179- }
180180-181181- private static bool _isStacklessRecursionPossible(CompilerTarget target,
182182- AstGetSetSymbol symbol)
183183- {
184184- if (symbol.Implementation.Interpretation != SymbolInterpretations.Function) //must be function call
185185- return false;
186186- if(symbol.Implementation.Module != target.Loader.ParentApplication.Module.Name) //must be direct recursive iteration
187187- return false;
188188- if (!Engine.StringsAreEqual(target.Function.Id, symbol.Implementation.InternalId))
189189- //must be direct recursive iteration
190190- return false;
191191- if (target.Function.Variables.Contains(PFunction.ArgumentListId))
192192- //must not use argument list
193193- return false;
194194- if (symbol.Arguments.Count > target.Function.Parameters.Count)
195195- //must not supply more arguments than mapped
196196- return false;
197197- return true;
198169 }
199170200171 private static bool _isStacklessRecursionPossible(CompilerTarget target,
+1-36
Prexonite/Compiler/AST/AstUnaryOperator.cs
···2929using JetBrains.Annotations;
3030using Prexonite.Modular;
3131using Prexonite.Properties;
3232-using Prexonite.Types;
33323433namespace Prexonite.Compiler.Ast
3534{
···143142144143 private void _emitIncrementDecrementCode(CompilerTarget target, StackSemantics value)
145144 {
146146- var legacySymbol = _operand as AstGetSetSymbol;
147147- var isLegacyVariable = legacySymbol != null && legacySymbol.IsObjectVariable;
148145 var symbolCall = _operand as AstIndirectCall;
149146 var symbol = symbolCall == null ? null : symbolCall.Subject as AstReference;
150147 EntityRef.Variable variableRef = null;
151148 var isVariable = symbol != null && symbol.Entity.TryGetVariable(out variableRef);
152152- var complex = _operand as AstGetSet;
153153- var isAssignable = complex != null;
154149 var isPre = _operator == UnaryOperator.PreDecrement || _operator == UnaryOperator.PreIncrement;
155150 switch (_operator)
156151 {
···161156 var isIncrement =
162157 _operator == UnaryOperator.PostIncrement ||
163158 _operator == UnaryOperator.PreIncrement;
164164- if (isLegacyVariable) //The easy way
165165- {
166166- var isGlobal = legacySymbol.Implementation.Interpretation == SymbolInterpretations.GlobalObjectVariable;
167167- var sym = legacySymbol.Implementation;
168168-169169- if(!isPre && value == StackSemantics.Value)
170170- {
171171- if (isGlobal)
172172- target.EmitLoadGlobal(Position, sym.InternalId, sym.Module);
173173- else
174174- target.EmitLoadLocal(Position, sym.InternalId);
175175- }
176176-177177- OpCode opc;
178178-179179- if (isIncrement)
180180- opc = isGlobal ? OpCode.incglob : OpCode.incloc;
181181- else
182182- opc = isGlobal ? OpCode.decglob : OpCode.decloc;
183183-184184- target.Emit(Position,opc, legacySymbol.Implementation.InternalId, target.ToInternalModule(legacySymbol.Implementation.Module));
185185-186186- if (isPre && value == StackSemantics.Value)
187187- {
188188- if (isGlobal)
189189- target.EmitLoadGlobal(Position, sym.InternalId, sym.Module);
190190- else
191191- target.EmitLoadLocal(Position, sym.InternalId);
192192- }
193193- }
194194- else if (isVariable)
159159+ if (isVariable)
195160 {
196161 Debug.Assert(variableRef != null);
197162 EntityRef.Variable.Local localRef;
+9-7
Prexonite/Compiler/AST/AstUnresolved.cs
···4343 _id = id;
4444 }
45454646+ public AstUnresolved(ISourcePosition position, string id) : base(position,PCall.Get)
4747+ {
4848+ if (id == null)
4949+ throw new ArgumentNullException("id");
5050+5151+ _id = id;
5252+ }
5353+4654 #region Overrides of AstGetSet
47554856 protected override void EmitGetCode(CompilerTarget target, StackSemantics stackSemantics)
···5866 MessageClasses.SymbolNotResolved));
5967 }
60686161- private string _id;
6969+ private readonly string _id;
62706371 public string Id
6472 {
6573 get { return _id; }
6666- set
6767- {
6868- if (value == null)
6969- throw new ArgumentNullException("value");
7070- _id = value;
7171- }
7274 }
73757476 protected override void EmitSetCode(CompilerTarget target)
+2-1
Prexonite/Compiler/AST/IAstFactory.cs
···124124 /// <para><see cref="ExprFor"/> reports all messages generated by the use of the symbol (errors, warnings, etc.)</para>
125125 /// <para>
126126 /// The parameter <paramref name="symbol"/> can be null, indicating that the symbol was not found in the first place.
127127- /// In that case, a corresponding "Symbol not found" message is automatically generated and a default node returned.
127127+ /// <see cref="ExprFor"/> does <em>not</em> treat this as an error.
128128+ /// The caller must make sure that a corresponding error message has been emitted.
128129 /// </para>
129130 /// </remarks>
130131 /// <returns>An expression that implements a usage of the supplied <paramref name="symbol"/>. Never null.</returns>
+18-16
Prexonite/Compiler/DebugHook.cs
···26262727using System;
2828using System.Collections.Generic;
2929+using JetBrains.Annotations;
2930using Prexonite.Commands.Core;
3031using Prexonite.Compiler.Ast;
3132using Prexonite.Modular;
3232-using Prexonite.Types;
3333using Prexonite.Compiler.Internal;
34343535namespace Prexonite.Compiler
···3737 /// <summary>
3838 /// Implementation of a compiler hook that optimizes the using of the <see cref = "Debug" /> command.
3939 /// </summary>
4040+ [PublicAPI]
4041 public static class DebugHook
4142 {
4243 /// <summary>
···6162 /// Installs the hook in the supplied <see cref = "Loader" />.
6263 /// </summary>
6364 /// <param name = "ldr">The loader.</param>
6565+ [PublicAPI]
6466 public static void InstallHook(Loader ldr)
6567 {
6668 if (ldr == null)
···7274 /// Uninstalls the hook in the supplied <see cref = "Loader" />.
7375 /// </summary>
7476 /// <param name = "ldr">The loader.</param>
7777+ [PublicAPI]
7578 public static void UninstallHook(Loader ldr)
7679 {
7780 if (ldr == null)
···97100 for (var i = 0; i < block.Count; i++)
98101 {
99102 var stmt = block[i] as AstGetSet;
100100- var legacySymbol = stmt as AstGetSetSymbol;
101103 //look for calls
102102- if (_isLegacyDebugCall(legacySymbol) || _isDebugCall(stmt))
104104+ if (_isDebugCall(stmt))
103105 {
104106 System.Diagnostics.Debug.Assert(stmt != null);
105107 //Found a call to debug
···108110 {
109111 for (var j = 0; j < stmt.Arguments.Count; j++)
110112 {
111111- var arg = stmt.Arguments[j] as AstGetSetSymbol;
112112- if (arg != null)
113113+ var arg = stmt.Arguments[j] as AstIndirectCall;
114114+ AstReference refNode;
115115+ if (arg != null && (refNode = arg.Subject as AstReference) != null)
113116 {
114117 var printlnCall = t.Factory.Call(stmt.Position,
115118 EntityRef.Command.Create(Engine.PrintLineAlias));
···120123 stmt.File,
121124 stmt.Line,
122125 stmt.Column,
123123- String.Concat("DEBUG ", arg.Implementation.InternalId, " = "));
126126+ String.Concat("DEBUG ", refNode.Entity, " = "));
124127 concatCall.Arguments.Add(consts);
125128 concatCall.Arguments.Add(arg);
126129 printlnCall.Arguments.Add(concatCall);
···139142 //look for conditions
140143 if (cond != null)
141144 {
142142- var expr = cond.Condition as AstGetSetSymbol;
143143- if (expr != null && expr.Implementation.Interpretation == SymbolInterpretations.Command &&
144144- Engine.StringsAreEqual(expr.Implementation.InternalId, Engine.DebugAlias))
145145+ var expr = cond.Condition as AstIndirectCall;
146146+ AstReference refNode;
147147+ EntityRef.Command cmd;
148148+ if (expr != null
149149+ && (refNode = expr.Subject as AstReference) != null
150150+ && refNode.Entity.TryGetCommand(out cmd)
151151+ && Engine.StringsAreEqual(cmd.Id,Engine.DebugAlias) )
145152 cond.Condition =
146153 new AstConstant(expr.File, expr.Line, expr.Column, debugging);
147154 }
···154161 } //end for statements
155162 }
156163157157- private static bool _isDebugCall(AstGetSet stmt)
164164+ [ContractAnnotation("=>true,stmt:notnull;=>false,stmt:canbenull")]
165165+ private static bool _isDebugCall([CanBeNull] AstGetSet stmt)
158166 {
159167 EntityRef entityRef;
160168 EntityRef.Command cmdRef;
161169 return stmt.TryMatchCall(out entityRef) && entityRef.TryGetCommand(out cmdRef) && Engine.StringsAreEqual(cmdRef.Id,Engine.DebugAlias);
162162- }
163163-164164- private static bool _isLegacyDebugCall(AstGetSetSymbol legacySymbol)
165165- {
166166- return legacySymbol != null && legacySymbol.Implementation.Interpretation == SymbolInterpretations.Command &&
167167- Engine.StringsAreEqual(legacySymbol.Implementation.InternalId, Engine.DebugAlias);
168170 }
169171 }
170172}
+3-2
Prexonite/Compiler/Grammar/Parser.Statement.atg
···299299 .)
300300= (. position = GetPosition(); .)
301301 Id<out id> (. Symbol sym;
302302- Symbols.TryGet(id, out sym);
303303- var expr = Create.ExprFor(position,sym);
302302+ var expr = Symbols.TryGet(id, out sym)
303303+ ? Create.ExprFor(position, sym)
304304+ : new AstUnresolved(position, id);
304305 complex = expr as AstGetSet;
305306 if(complex == null)
306307 {
···11-/* The following code was generated by CSFlex 1.4 on 27/01/2013 */
11+/* The following code was generated by CSFlex 1.4 on 10/02/2013 */
2233#line 1 "Prexonite.lex"
44/*
···4141/**
4242 * This class is a scanner generated by <a href="http://www.sourceforge.net/projects/csflex/">C# Flex</a>, based on
4343 * <a href="http://www.jflex.de/">JFlex</a>, version 1.4
4444- * on 27/01/2013 from the specification file
4444+ * on 10/02/2013 from the specification file
4545 * <tt>Prexonite.lex</tt>
4646 */
4747class Lexer: IScanner {
+1-39
Prexonite/Compiler/Macro/Commands/CallMacro.cs
···3030using Prexonite.Commands;
3131using Prexonite.Commands.Core;
3232using Prexonite.Compiler.Ast;
3333-using Prexonite.Compiler.Symbolic;
3434-using Prexonite.Compiler.Symbolic.Compatibility;
3533using Prexonite.Modular;
3634using Prexonite.Properties;
3735using Prexonite.Types;
···436434 AstExpr specProto, out PCall protoCall, out IList<AstExpr> protoArguments,
437435 out AstExpr macroSpec)
438436 {
439439- var proto = specProto as AstMacroInvocation;
440437 var proto2 = specProto as AstExpand;
441441- if (proto != null)
442442- {
443443- macroSpec = _getMacroSpecExpr(context, proto);
444444- protoCall = proto.Call;
445445- protoArguments = proto.Arguments;
446446- }
447447- else if (specProto.IsPlaceholder())
438438+ if (specProto.IsPlaceholder())
448439 {
449440 //As an exception, allow a placeholder here
450441 macroSpec = specProto;
···466457 return false;
467458 }
468459 return true;
469469- }
470470-471471- private static AstExpr _getMacroSpecExpr(MacroContext context,
472472- AstMacroInvocation proto)
473473- {
474474- var symbolEntry = proto.Implementation;
475475-476476- return _getMacroSpecExpr(context, proto.Position, symbolEntry);
477477- }
478478-479479- private static AstExpr _getMacroSpecExpr(MacroContext context, ISourcePosition position, SymbolEntry symbolEntry)
480480- {
481481-//macroId: as a constant
482482- var sym = symbolEntry.ToSymbol();
483483- DereferenceSymbol ds;
484484- ReferenceSymbol rs;
485485- ExpandSymbol es;
486486- if ((ds = sym as DereferenceSymbol) != null && (rs = ds.InnerSymbol as ReferenceSymbol) != null)
487487- {
488488- return EntityRefTo.ToExpr(context.Factory, context.Invocation.Position, rs.Entity);
489489- }
490490- else if ((es = sym as ExpandSymbol) != null && (rs = es.InnerSymbol as ReferenceSymbol) != null)
491491- {
492492- return EntityRefTo.ToExpr(context.Factory, context.Invocation.Position, rs.Entity);
493493- }
494494- else
495495- {
496496- throw new ErrorMessageException(Message.Error("Cannot convert usage of legacy macro invocation in call macro.",position, MessageClasses.CallMacroUsage));
497497- }
498460 }
499461500462 private static AstExpr _getMacroSpecExpr(MacroContext context,
···185185 ExpectReturnValue(target.Meta[Application.EntryKey], expectedReturnValue, args);
186186 }
187187188188+ protected void Expect(Action<PValue> assertion, params PValue[] args)
189189+ {
190190+ ExpectReturnValue(target.Meta[Application.EntryKey], assertion, args);
191191+ }
192192+188193 protected void ExpectNamed<T>(string functionId, T expectedReturnValue, params PValue[] args)
189194 {
190195 ExpectReturnValue(functionId, expectedReturnValue, args);
···192197193198 protected void ExpectReturnValue<T>(string functionId, T expectedReturnValue, PValue[] args)
194199 {
195195- if (!args.All(value => value != null))
200200+ ExpectReturnValue(functionId, rv =>
201201+ {
202202+ var expected = engine.CreateNativePValue(expectedReturnValue);
203203+ AssertPValuesAreEqual(expected, rv);
204204+ }, args);
205205+ }
206206+207207+ protected void ExpectReturnValue(string functionId, Action<PValue> assertion, PValue[] args)
208208+ {
209209+ if (assertion == null)
210210+ throw new ArgumentNullException("assertion");
211211+212212+ if (args.Any(value => value == null))
196213 throw new ArgumentException(
197214 "Arguments must not contain naked CLR null references. Use `PType.Null`.");
198215199199- var expected = engine.CreateNativePValue(expectedReturnValue);
200216 if (!target.Functions.Contains(functionId))
201217 throw new PrexoniteException("Function " + functionId + " cannot be found.");
202202-203203- Console.WriteLine("Expecting " + functionId + " to return " + expected);
204218205219 var func = target.Functions[functionId];
206220 if (func.Meta[StoreDebugImplementationKey].Switch)
···226240 throw;
227241 }
228242229229- AssertPValuesAreEqual(expected, rv);
243243+ assertion(rv);
230244 }
231245232246 public void AssertPValuesAreEqual(PValue expected, PValue rv)
···266280267281 protected void ExpectNull(params PValue[] args)
268282 {
269269- ExpectReturnValue<object>(target.Meta[Application.EntryKey], null, args);
283283+ var functionId = target.Meta[Application.EntryKey];
284284+ ExpectReturnValue(functionId, _buildIsNullAssertion(functionId), args);
270285 }
271286272287 protected void ExpectNull(string functionId, params PValue[] args)
273288 {
274274- ExpectReturnValue<object>(functionId, null, args);
289289+ ExpectReturnValue(functionId, _buildIsNullAssertion(functionId), args);
290290+ }
291291+292292+ private static Action<PValue> _buildIsNullAssertion(string functionId)
293293+ {
294294+ return v =>
295295+ Assert.That(v.IsNull, Is.True,
296296+ string.Format("Value returned from {0} is expected to be a null reference, was {1} instead.",
297297+ functionId, v));
275298 }
276299277300 protected PValue GetReturnValueNamed(string functionId, params PValue[] args)
+12-24
PrexoniteTests/psr-tests/ast.test.pxs
···55declare ast2\simple as ast2;
66declare ast3\simple as ast3;
7788+function ast3 = call(ast3\simple(?), [get_unscoped_ast_factory], var args);
99+810function compiler_is_loaded[test]
911{
1012 var found = null;
···26282729 assert(found is not Null, "After loading psr\\ast.pxs, one module in the compound should have 'compiler_loaded' enabled.");
2830}
3131+3232+// Such a function is usually defined by macro.pxs, but we'll provide a simplified version
3333+// here to make testing of ast.pxs easier.
3434+// Do not use this implementation in actual code as it does not use the correct factory and
3535+// will not encode the caller's source position.
3636+function ast\call(entityref)
3737+{
3838+ return ast3("IndirectCall",ast3("Reference",entityref));
3939+}
29403041function test_ast_withpos_null[test]
3142{
···120131121132function test_h_thisModule as thisModule = asm(ldr.app).Module.Name;
122133123123-function test_is_function_call[
124124- is test;
125125- Add Prexonite to Imports;
126126- Add Prexonite::Compiler to Imports;
127127- Add Prexonite::Compiler::Ast to Imports;
128128- Add Prexonite::Types to Imports;
129129-]
130130-{
131131- var func = ast("GetSetSymbol",
132132- new ::SymbolEntry(::SymbolInterpretations.Function,->test_is_function_call.Id, ->test_is_function_call.ParentApplication.Module.Name));
133133- var nonFunc = ast("GetSetSymbol", ::SymbolEntry.Command(->test_is_function_call.Id));
134134- var wrongFunc = ast("GetSetSymbol",
135135- new ::SymbolEntry(::SymbolInterpretations.Function,->test_unique_id_counter.Id, ->test_unique_id_counter.ParentApplication.Module.Name));
136136- var notSym = ast("MacroInvocation",
137137- new ::SymbolEntry(::SymbolInterpretations.Function,->test_is_function_call.Id, ->test_is_function_call.ParentApplication.Module.Name));
138138-139139- var id = ->test_is_function_call.Id;
140140- assert(isFunctionCall(id, func), "Should recognize $func");
141141- assert(not isFunctionCall(id, nonFunc), "Should reject $nonFunc");
142142- assert(not isFunctionCall(id, wrongFunc), "Should reject $wrongFunc");
143143- assert(not isFunctionCall(id, notSym), "Should reject $notSym");
144144-}
145145-146134function test_is_member_access[
147135 is test;
148136 Add Prexonite to Imports;
···155143 var mem = "member";
156144 var memacc = ast("GetSetMemberAccess", nt, mem);
157145 var wrongmemacc = ast("GetSetMemberAccess", nt, "otherMember");
158158- var notMemacc = ast("GetSetSymbol", new ::SymbolEntry(::SymbolInterpretations.Function, mem, thisModule));
146146+ var notMemacc = ast\call(entityref_to(test_is_member_access));
159147160148 assert(isMemberAccess(mem, memacc), "Should recognize $memacc");
161149 assert(not isMemberAccess(mem, wrongmemacc), "Should reject $wrongmemacc");
+9-30
PrexoniteTests/psr-tests/macro.test.pxs
···198198199199function test_ast_is_effect[test]
200200{
201201- var isEffect = ast("GetSetSymbol", SI.get, SI.func(->test_ast_is_effect));
201201+ var isEffect = ast\call(entityref_to(test_ast_is_effect));
202202 var notEffect = ast3("CreateClosure",macro\entity(test_ast_is_effect));
203203204204 assert_eq(ast_is_effect(isEffect), true, "$(boxed(isEffect)) is a node.");
···209209210210function test_ast_is_partially_applicable[test]
211211{
212212- var pa = ast("GetSetSymbol", SI.get, SI.func(->test_ast_is_partially_applicable));
212212+ var pa = ast\call(entityref_to(test_ast_is_partially_applicable));
213213 var npa = ast3("CreateClosure", macro\entity(test_ast_is_partially_applicable));
214214215215 assert_eq(ast_is_partially_applicable(pa), true, "$(boxed(pa)) is partially applicable");
···220220221221function test_ast_is_partial_application[test]
222222{
223223- var pa = ast("GetSetSymbol", SI.get, SI.func(->test_ast_is_partial_application));
224224- pa.Arguments.Add(ast("Null"));
223223+ var pa = ast\call(entityref_to(test_ast_is_partial_application));
224224+ pa.Arguments.Add(ast3("Null"));
225225226226 assert_eq(ast_is_partial_application(pa), false, "$(boxed(pa)) is not a partial application (no placeholders)");
227227228228- pa.Arguments.Add(ast("Placeholder"));
228228+ pa.Arguments.Add(ast3("Placeholder"));
229229230230 assert_eq(ast_is_partial_application(pa),true, "$(boxed(pa)) is a partial application");
231231···235235function test_ast_is_CreateClosure[test]
236236{
237237 var cc = ast3("CreateClosure", macro\entity(test_ast_is_CreateClosure));
238238- var ncc = ast("GetSetSymbol", SI.get, Si.func(->test_ast_is_CreateClosure));
238238+ var ncc = ast\call(entityref_to(test_ast_is_CreateClosure));
239239240240 assert_eq(ast_is_CreateClosure(cc),true,"$(boxed(cc)) is a CreateClosure node");
241241 assert_eq(ast_is_CreateClosure(ncc),false,"$(boxed(ncc)) is not a CreateClosure node");
···244244245245function test_ast_is_node[test]
246246{
247247- var node = ast("Null");
247247+ var node = ast3("Null");
248248 var nonNode = new Structure;
249249 var nonNode2 = new System::Object;
250250···387387388388macro test_macro_internal_id[test]
389389{
390390- var invk = ast("MacroInvocation", SI.m.i.func("ast\\macro"));
390390+ var invk = ast3("Expand", entityref_to(ast\macro));
391391392392 var c = call\macro([macro\internal_id(invk)]).Expression;
393393 assert(ast_is_Constant(c),"$(boxed(c)) should be constant");
394394395395- assert_eq(ast\read(c),"ast\\macro");
396396-}
397397-398398-macro test_macro_interpretation[test]
399399-{
400400- var invk1 = ast("MacroInvocation", SI.m.func("ast\\macro"));
401401-402402- var c1 = call\macro([macro\interpretation(invk1)]).Expression;
403403- assert(ast_is_GetSetMemberAccess(c1),"$(boxed(c1)) should be get set member access");
404404- assert_eq(c1.Id,"func","ast\\macro is implemented as a function (macro)");
405405-406406- var invk2 = ast("MacroInvocation", SI.m.cmd("call\\macro"));
407407-408408- var c2 = call\macro([macro\interpretation(invk2)]).Expression;
409409- assert(ast_is_GetSetMemberAccess(c2),"$(boxed(c2)) should be get set member access");
410410- assert_eq(c2.Id,"cmd","ast\\macro is implemented as a macro command");
411411-412412- var invk3 = ast("GetSetSymbol", SI.get, SI.i.func("test_macro_id_static"));
413413-414414- var c3 = call\macro([macro\interpretation(invk3)]).Expression;
415415- assert(ast_is_GetSetMemberAccess(c3),"$(boxed(c3)) should be get set member access");
416416- assert_eq(c3.Id,"func","test_macro_id_static is implemented as a function");
395395+ assert_eq(ast\read(c),entityref_to(ast\macro).Id);
417396}
418397419398function test_macro_entity_static[test]
···43434444 if(factory is null)
4545 throw "AST factory cannot be null.";
4646+4747+ if(type is null)
4848+ throw "ast3(type, ...) the parameter `type` cannot be null.";
46494750 //return call\member(factory,type, targs);
4851 return call(factory,[type],targs);
···50535154function ast\withPos(type, file, line, column) [is compiler;]
5255{
5656+ if(type is null)
5757+ throw "ast(type, file, line, column, ...) the parameter `type` cannot be null.";
5858+5359 var args;
5460 var targs = args >> skip(4);
5561···122128}
123129function uniqueId(verb) [is compiler;] = "uniq\\" + verb + uniqueIdCounter++;
124130125125-function isFunctionCall(id, node)[is compiler;] =
126126- node is ::AstGetSetSymbol And
127127- node.Implementation.Interpretation~Int == ::SymbolInterpretations.Function~Int And
128128- Prexonite::Engine.StringsAreEqual(node.Implementation.InternalId, id.ToString);
131131+declare(
132132+ isFunctionCall = error(here,"PSR.Obsolete",@"isFunctionCall is deprecated. Use checking functions from the psr\\macro instead.",null)
133133+);
129134130135function isMemberAccess(id, node)[is compiler;] =
131136 node is ::AstGetSetMemberAccess And
+101-268
Prx/psr/impl/macro.pxs
···5656 var macroInvocation = context.Invocation;
57575858 ref ast = ast\withPos(?,macroInvocation.File, macroInvocation.Line,macroInvocation.Column,?);
5959+ ref ast3 = ast3\withPos(context.Factory,?,macroInvocation.Position,?);
59606061 if(SI.eq(context.Call,SI.set))
6162 {
···6566 return false;
6667 }
67686868- var astCall = ast("GetSetSymbol", SI.get, SI.func(->ast\withPos));
6969+ var astCall = ast3("IndirectCall", ast3("Reference",entityref_to(ast\withPos)), SI.get);
69707071 var nodeFile;
7172 var nodeLine;
···7778 {
7879 establish_macro_context(context);
79808080- var getContext = ast("GetSetSymbol",
8181- SI.get,SI.lref(Prexonite::Compiler::MacroAliases.ContextAlias));
8181+ var getContext = ast3("IndirectCall",ast3("IndirectCall", ast3("Reference",SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)), SI.get), SI.get);
82828383 var getInvComp = ast("GetSetMemberAccess",SI.get,getContext,"Invocation");
84848585 var invkV = context.AllocateTemporaryVariable();
8686- var storeInvk = ast("GetSetSymbol",
8787- SI.set, SI.lvar(invkV));
8686+ var storeInvk = ast3("IndirectCall", ast3("Reference",SI.e.lvar(invkV)), SI.set);
8887 storeInvk.Arguments.Add(getInvComp);
89889090- var getInv = ast("GetSetSymbol",SI.get,SI.lvar(invkV));
8989+ var getInv = ast3("IndirectCall", ast3("Reference", SI.e.lvar(invkV)), SI.get);
91909291 nodeFile = ast("GetSetMemberAccess", SI.get, storeInvk, "File");
9392 nodeLine = ast("GetSetMemberAccess", SI.get, getInv, "Line");
···115114 var pos = context.Invocation.Position;
116115 var create = context.Factory;
117116118118- var ctorNode = create.ObjectCreation(pos,create.ConstantTypeExpression("Object(\"Prexonite.Compiler.SourcePosition\")"));
119119- ctorNode.Arguments.Add(create.Constant(position.File));
120120- ctorNode.Arguments.Add(create.Constant(position.Line));
121121- ctorNode.Arguments.Add(create.Constant(position.Column));
117117+ var ctorNode = create.ObjectCreation(pos,create.ConstantTypeExpression(pos,"Object(\"Prexonite.Compiler.SourcePosition\")"));
118118+ ctorNode.Arguments.Add(create.Constant(pos, position.File));
119119+ ctorNode.Arguments.Add(create.Constant(pos, position.Line));
120120+ ctorNode.Arguments.Add(create.Constant(pos, position.Column));
122121 return ctorNode;
123122}
124123···129128 var macroInvocation = context.Invocation;
130129131130 ref ast = ast\withPos(?,macroInvocation.File, macroInvocation.Line,macroInvocation.Column,?);
131131+ ref ast3 = ast3\withPos(context.Factory,?,macroInvocation.Position,?);
132132133133 if(SI.eq(context.Call,SI.set))
134134 {
···138138 return false;
139139 }
140140141141- var astCall = ast("GetSetSymbol", SI.get, SI.func(->ast\withPos));
141141+ var astCall = ast3("IndirectCall", ast3("Reference", entityref_to(ast\withPos)), SI.get);
142142143143 var nodePosition;
144144···146146 {
147147 establish_macro_context(context);
148148149149- var getContext = ast("GetSetSymbol",
150150- SI.get,SI.lref(Prexonite::Compiler::MacroAliases.ContextAlias));
149149+ var getContext = ast3("IndirectCall", ast3("IndirectCall", ast3("Reference", SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)), SI.get), SI.get);
151150152151 var getInvComp = ast("GetSetMemberAccess",SI.get,getContext,"Invocation");
153152···183182 }
184183185184 ref ast3 = ast3\withPos(context.Factory,?,context.Invocation.Position,?);
186186- var refNode = ast3("Reference",SI.e.func(->ast3\withPos));
185185+ var refNode = ast3("Reference",entityref_to(ast3\withPos));
187186 var astCallNode = ast3("IndirectCall",refNode,SI.get);
188187189188 var getFactory;
···236235 if(explicitContext is null)
237236 {
238237 establish_macro_context(context);
239239- getContext = ast("GetSetSymbol",SI.get,SI.lref(Prexonite::Compiler::MacroAliases.ContextAlias));
238238+ getContext = ast3("IndirectCall",ast3("IndirectCall",ast3("Reference", SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)), SI.get), SI.get);
240239 }
241240 else
242241 {
243242 getContext = explicitContext;
244243 }
245244246246- var funcCall = ast("GetSetSymbol",SI.get,SI.func(->is_in_macro\impl));
245245+ var funcCall = ast3("IndirectCall", ast3("Reference", entityref_to(is_in_macro\impl)), SI.get);
247246 funcCall.Arguments.Add(getContext);
248247 return funcCall;
249248}
···252251{
253252 establish_macro_context\impl(context);
254253255255- var estCall = ast("GetSetSymbol", SI.get, SI.func(->establish_macro_context\impl));
256256- estCall.Arguments.Add(ast("GetSetSymbol", SI.get, SI.lref(Prexonite::Compiler::MacroAliases.ContextAlias)));
254254+ var estCall = ast3("IndirectCall", ast3("Reference", entityref_to(establish_macro_context\impl)), SI.get);
255255+ estCall.Arguments.Add(ast3("IndirectCall", ast3("IndirectCall", ast3("Reference", SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)), SI.get), SI.get));
257256 return estCall;
258257}
259258260259macro macro\get_context()
261261-{
262262- function create_getSI = ast3("IndirectCall",ast3("Reference",SI.e.func(->SI)));
263263- var astCall = ast3("Expand",SI.e.func(macro\reference(ast)));
264264- astCall.Arguments.AddRange([
265265- ast("Constant","GetSetSymbol"),
266266- ast("GetSetMemberAccess",SI.get,new getSI,"get"),
267267- var lref = ast("GetSetMemberAccess",SI.get,new getSI,"lref"),
268268- ]);
269269- lref.Arguments.Add(ast("Constant",Prexonite::Compiler::MacroAliases.ContextAlias));
270270-271271- context.Block.Expression = astCall;
272272- return null;
260260+{
261261+ // `SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias)`
262262+ var getSI = ast3("IndirectCall", ast3("Reference",entityref_to(SI)));
263263+ var getSIEntity = ast3("MemberAccess", getSI, "e");
264264+ var getSIEntityLVar = ast3("MemberAccess", getSIEntity, "lvar");
265265+ getSIEntityLVar.Arguments.Add(ast3("Constant",Prexonite::Compiler::MacroAliases.ContextAlias));
266266+267267+ // `ast3("Reference",SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias))`
268268+ var refCtor = ast3("Expand",entityref_to(ast3));
269269+ refCtor.Arguments.Add(ast3("Constant","Reference"));
270270+ refCtor.Arguments.Add(getSIEntityLVar);
271271+272272+ function dereference(node)
273273+ {
274274+ var ctor = ast3("Expand", entityref_to(ast3));
275275+ ctor.Arguments.Add(ast3("Constant","IndirectCall"));
276276+ ctor.Arguments.Add(node);
277277+ return ctor;
278278+ }
279279+280280+ // `ast3("IndirectCall",ast3("IndirectCall",ast3("Reference",SI.e.lvar(Prexonite::Compiler::MacroAliases.ContextAlias))))`
281281+ return dereference(dereference(refCtor));
273282}
274283275284function macro\report_any(message, severity)
···320329{
321330 if(context.IsJustEffect)
322331 return;
323323-324324- function create_getSI = ast("GetSetSymbol",SI.get,SI.func(->SI));
325332326326- var mi = ast("MacroInvocation", SI.m.func("ast\\macro", macro\macro_pxs_module));
327327- mi.Arguments.Add(ast("Constant","GetSetSymbol"));
328328- mi.Arguments.Add(ast("GetSetMemberAccess",new getSI,"get"));
329329- mi.Arguments.Add(var si_func = ast("GetSetMemberAccess",new getSI,"func"));
330330- si_func.Arguments.Add(ast("GetSetReference", SI.func(->SI)));
331331-332332- context.Block.Expression = mi;
333333+ // We need to construct the following expression:
334334+ // `ast3("IndirectCall",ast3("Reference",entityref_to(->SI))`
335335+336336+ // `entityref_to(SI)`
337337+ var SIentityRefNode = ast3("Expand",entityref_to(entityref_to));
338338+ SIentityRefNode.Arguments.Add(ast3("IndirectCall",ast3("Reference",entityref_to(SI))));
339339+340340+ // `ast3("Reference", $SIentityRefNode)`
341341+ var refCtor = ast3("Expand", entityref_to(ast3));
342342+ refCtor.Arguments.Add(ast3("Constant","Reference"));
343343+ refCtor.Arguments.Add(SIentityRefNode);
344344+345345+ // `ast3("IndirectCall",$refCtor)`
346346+ var indirectCallCtor = ast3("Expand",entityref_to(ast3));
347347+ indirectCallCtor.Arguments.Add(ast3("Constant","IndirectCall"));
348348+ indirectCallCtor.Arguments.Add(refCtor);
349349+350350+ context.Block.Expression = indirectCallCtor;
351351+ return;
333352}
334353335354macro tempalloc(getContext)
···365384 }
366385 else if(getContext is Null)
367386 {
368368- macro\report_error("tempfree must either be called in a macro context, or be supplied a macroInvocation~Prexonite::Compiler::Ast::AstMacroInvocation");
387387+ macro\report_error("tempfree must either be called in a macro context, or be supplied a macro context.");
369388 return;
370389 }
371390···396415 //create function body {return <body>(node_arg, <args...>);}
397416 var block = target.Ast;
398417 block.Add(var ret = ast("Return",Prexonite::Compiler::Ast::ReturnVariant.Exit));
399399- ret.Expression = var bodyMi = ast("MacroInvocation", body);
400400- bodyMi.Arguments.Add(ast("GetSetSymbol",SI.get,SI.lvar(node_arg)));
418418+ ret.Expression = var bodyMi = ast3("Expand", body);
419419+ bodyMi.Arguments.Add(ast3("IndirectCall", ast3("Reference", SI.e.lvar(node_arg)), SI.get));
401420 bodyMi.Arguments.AddRange(var args >> skip(3));
402421403422 //Have the body compiled
···446465 // TODO: make create_global_variable available to build block code.
447466 establish_macro_context;
448467449449- context.Block.Expression = var implCall = ast("GetSetSymbol", context.Call, SI.func(->create_global_variable\impl));
468468+ context.Block.Expression = var implCall = ast3("IndirectCall", ast3("Reference", entityref_to(create_global_variable\impl)), context.Call);
450469 implCall.Arguments.Add(macro\get_context);
451470 implCall.Arguments.AddRange(var args);
452471···468487469488 // //Ensure is object type in the first place
470489 var arg_pt = tempalloc;
471471- function create_arg_pt(c) = ast("GetSetSymbol", c ?? SI.get, SI.lvar(arg_pt));
490490+ function create_arg_pt(c) = ast3("IndirectCall", ast3("Reference",SI.e.lvar(arg_pt)), c ?? SI.get);
472491473492 var node_t = uniqueId(id + @"\node_t");
474474- function create_node_t(c) = ast("GetSetSymbol",c ?? SI.get, SI.gvar(node_t, macro\macro_pxs_module));
493493+ function create_node_t(c) = ast3("IndirectCall", ast3("Reference", SI.e.gvar(node_t, macro\macro_pxs_module)), c ?? SI.get);
475494476495 var node_t_var = new global_variable(node_t);
477496 node_t_var.Meta["compiler"] = true;
···479498 // if((var arg_pt = boxed(node_arg).Type) is not Prexonite::Types::ObjectPType)
480499 // return false;
481500 {
482482- var box_node_arg = ast("GetSetSymbol",SI.get,SI.cmd("boxed"));
501501+ var box_node_arg = ast3("IndirectCall", ast3("Reference", entityref_to(boxed)), SI.get);
483502 box_node_arg.Arguments.Add(new node_arg);
484503 var set_arg_pt = new arg_pt(SI.set);
485504 set_arg_pt.Arguments.Add(ast("GetSetMemberAccess", box_node_arg, "Type"));
···531550 }
532551 else
533552 {
534534- var assignableAstNode = ast("GetSetMemberAccess", ast("GetSetSymbol", SI.get, SI.func(->AstNode_t)),
553553+ var assignableAstNode = ast("GetSetMemberAccess", ast3("IndirectCall", ast3("Reference", entityref_to(AstNode_t)), SI.get),
535554 "IsAssignableFrom");
536555 assignableAstNode.Arguments.Add(ast("GetSetMemberAccess", new arg_pt, "ClrType"));
537556···541560542561 context.Block.Expression = conjunction;
543562 }
563563+ return;
544564}
545565546566build
···552572 >> where(AstNode_t.IsAssignableFrom(?))
553573 >> var node_ts;
554574555555- var impl = SI.m.func(asm(ldr.app).Functions[@"macro\_check_is_node_t"]);
575575+ var impl = SI.e.func(asm(ldr.app).Functions[@"macro\_check_is_node_t"]);
556576557577 foreach(new var node_t in node_ts)
558578 {
···601621}
602622603623function ast_is_effect(n) = ast_is_Node(n);
624624+function ast_is_something_obsolete as ast_is_MacroInvocation, ast_is_GetSetSymbol, ast_is_GetSetReference(_)[\sps] = false;
625625+626626+declare(
627627+ ast_is_MacroInvocation = warn(pos("macro.pxs",607,0),"PSR.Obsolete",@"MacroInvocation nodes no longer exist. Use Expand instead.",sym "ast_is_MacroInvocation"),
628628+ 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"),
629629+ ast_is_GetSetReference = warn(pos("macro.pxs",609,0),"PSR.Obsolete",@"GetSetReference nodes no longer exist. Use Reference instead.",sym "ast_is_GetSetReference")
630630+);
604631605632//Optimization
606633function optimize\ref(context, ref node) [is compiler;]
···716743 contextRef = macro\get_context;
717744 }
718745719719- var fcall = context.Block.Expression = ast("GetSetSymbol", context.Call, SI.func(->ast\read\impl));
746746+ var fcall = context.Block.Expression = ast3("IndirectCall",ast3("Reference",entityref_to(ast\read\impl)),context.Call);
720747 fcall.Arguments.Add(contextRef);
721748 fcall.Arguments.Add(expr);
722749 return true;
···724751725752function macro\_extract_id(prototype)[is compiler;]
726753{
727727- if(prototype is Prexonite::Compiler::Ast::AstMacroInvocation)
728728- return prototype.Implementation.InternalId;
729729- else if(prototype is Prexonite::Compiler::Ast::AstExpand)
754754+ if(prototype is Prexonite::Compiler::Ast::AstExpand)
730755 return prototype.Entity.Id;
731756 else
732757 return prototype.Subject.Entity.Id;
···762787 var siMem;
763788 if(ast_is_MacroInvocation(prototype))
764789 {
765765- var i = prototype.Implementation.Interpretation;
766766- if(SI.m.is_func(i))
767767- siMem = "func";
768768- else if(SI.m.is_cmd(i))
769769- siMem = "cmd";
770770- else {
771771- macro\report_error("Unkown macro interpretation $i. Assuming function");
772772- siMem = "func";
773773- }
774774-775775- var getSI\m = ast("GetSetMemberAccess",SI.get,getSI,"m");
776776- var getSI\m\i = ast("GetSetMemberAccess",SI.get,getSI\m,siMem);
777777-778778- return getSI\m\i;
790790+ macro\report_error("MacroInvocation no longer exists.");
791791+ return;
779792 }
780793 else if(ast_is_GetSetSymbol(prototype))
781794 {
···810823}
811824812825// Converts `macro\entity(someCall)` into an expression that represents the entity "someCall" (an EntityRef).
813813-macro macro\entity(prototype)
814814-{
815815- if(context.IsJustEffect)
816816- return;
817817-818818- var e;
819819- if(ast_is_Expand(prototype))
820820- {
821821- e = prototype.Entity;
822822- }
823823- else if(ast_is_IndirectCall(prototype) and ast_is_Reference(prototype.Subject))
824824- {
825825- e = prototype.Subject.Entity;
826826- }
827827- else
828828- {
829829- macro\report_error("macro\\entity cannot deal with invocations or expansions via legacy mechanisms. Offending prototype: $(prototype).");
830830- return;
831831- }
832832-833833- var internalId;
834834- var moduleName = null;
835835- var entityKind;
836836- if(SI.e.is_func(e))
837837- {
838838- entityKind = "func";
839839- internalId = e.Id;
840840- moduleName = e.ModuleName;
841841- }
842842- else if(SI.e.is_cmd(e))
843843- {
844844- entityKind = "cmd";
845845- internalId = e.Id;
846846- }
847847- else if(SI.e.is_mcmd(e))
848848- {
849849- entityKind = "mcmd";
850850- internalId = e.Id;
851851- }
852852- else if(SI.e.is_gvar)
853853- {
854854- entityKind = "gvar";
855855- internalId = e.Id;
856856- moduleName = e.ModuleName;
857857- }
858858- else if(SI.e.is_lvar)
859859- {
860860- entityKind = "lvar";
861861- internalId = e.Id;
862862- }
863863- else
864864- {
865865- macro\report_error("macro\\entity cannot handle unknown entity kind $(e).");
866866- return;
867867- }
868868-869869- internalId = ast3("Constant",internalId);
870870- if(moduleName is not null)
871871- {
872872- var create_module_name_reference = ast3("Reference",SI.e.cmd(Prexonite::Commands::Core::CreateModuleName.Alias));
873873- var create_module_name_node = ast3("IndirectCall",create_module_name_reference,SI.get);
874874- create_module_name_node.Arguments.Add(ast3("Constant",moduleName.Id));
875875- create_module_name_node.Arguments.Add(ast3("Constant",moduleName.Version.ToString()));
876876- moduleName = create_module_name_node;
877877- }
878878-879879- var entityMode = ast3("MemberAccess",macro\getSI,"e",SI.get);
880880- var ctorCall = ast3("MemberAccess",entityMode,entityKind,context.Invocation.Call);
881881- ctorCall.Arguments.Add(internalId);
882882- if(moduleName is not null)
883883- ctorCall.Arguments.Add(moduleName);
884884-885885- context.Block.Expression = ctorCall;
886886- return;
887887-}
888888-889889-macro macro\symbol(prototype)
890890-{
891891- if(context.IsJustEffect)
892892- return;
893893-894894- declare: macro\getSI as getSI;
895895-896896- ref sym = prototype.Implementation(?);
897897-898898- function mkModuleName
899899- {
900900- var mkModuleName = ast("GetSetSymbol", SI.get, SI.cmd(macro\internal_id(create_module_name)));
901901- mkModuleName.Arguments.Add(ast("Constant",sym.Module.ToString));
902902- return mkModuleName;
903903- }
904904-905905- var siMem;
906906- var modReq = false;
907907- if(ast_is_MacroInvocation(prototype))
908908- {
909909- var i = sym.Interpretation;
910910- if(SI.m.is_func(i))
911911- {
912912- siMem = "func";
913913- modReq = true;
914914- }
915915- else if(SI.m.is_cmd(i))
916916- {
917917- siMem = "cmd";
918918- }
919919- else {
920920- macro\report_error("Unkown macro interpretation $i. Assuming function");
921921- siMem = "func";
922922- }
923923-924924- var getSI\m = ast("GetSetMemberAccess",SI.get,getSI,"m");
925925- var getSI\m\i = ast("GetSetMemberAccess",SI.get,getSI\m,siMem);
926926- getSI\m\i.Arguments.Add(ast("Constant",sym.InternalId));
927927- if(modReq)
928928- getSI\m\i.Arguments.Add(mkModuleName);
929929-930930- return getSI\m\i;
931931- }
932932- else if(ast_is_GetSetSymbol(prototype))
933933- {
934934- var i = sym.Interpretation;
935935-936936- if(SI.is_lvar(i))
937937- siMem = "lvar";
938938- else if(SI.is_lref(i))
939939- siMem = "lref";
940940- else if(SI.is_gvar(i))
941941- {
942942- siMem = "gvar";
943943- modReq = true;
944944- }
945945- else if(SI.is_gref(i))
946946- {
947947- siMem = "gref";
948948- modReq = true;
949949- }
950950- else if(SI.is_func(i))
951951- {
952952- siMem = "func";
953953- modReq = true;
954954- }
955955- else if(SI.is_cmd(i))
956956- siMem = "cmd";
957957- else if(SI.is_mcmd(i))
958958- siMem = "mcmd";
959959- else {
960960- macro\report_error("Unkown symbol interpretation $i. Assuming function");
961961- siMem = "func";
962962- }
963963-964964- var getSI\i = ast("GetSetMemberAccess",SI.get,getSI,siMem);
965965- getSI\i.Arguments.Add(ast("Constant", sym.InternalId));
966966- if(modReq)
967967- getSI\i.Arguments.Add(mkModuleName);
968968-969969- return getSI\i;
970970- }
971971- else
972972- {
973973- macro\report_error("Cannot derive symbol entry from AST node $prototype.");
974974- }
975975-}
976976-977977-declare macro\symbol as entityof;
826826+declare(
827827+ macro\entity = warn(here,"PSR.Obsolete",@"macro\entity is a backwards-compatibility alias to entityref_to. Use that instead.",sym "entityref_to"),
828828+ macro\symbol = error(here,"PSR.Obsolete",@"macro\symbol is deprecated. Use entityref_to instead.",null),
829829+ ast\symbol = error(here,"PSR.Obsolete",@"ast\symbol is deprecated. Use EntityRef instead.",null),
830830+ 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)
831831+);
978832979833macro ast\null
980834{
981835 if(context.IsJustEffect)
982836 return;
983837984984- var mi = ast("MacroInvocation", SI.m.func("ast\\macro",macro\macro_pxs_module));
985985- mi.Arguments.Add(ast("Constant","Null"));
986986-987987- context.Block.Expression = mi;
838838+ var ctor = ast3("Expand",entityref_to(ast3));
839839+ ctor.Arguments.Add(ast3("Constant","Null"));
840840+ context.Block.Expression = ctor;
841841+ return;
988842}
989989-990990-//Creates a macro invocation for the supplied macro
991991-declare(
992992- 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)
993993-);
994843995844macro ast\expand_macro(entity,callType)
996845{
···1013862 c.Arguments.Add(callType ?? ast3("MemberAccess",macro\getSI,"get",SI.get));
10148631015864 context.Block.Expression = c;
10161016-}
10171017-10181018-macro ast\symbol(symbolInterpretation)
10191019-{
10201020- var args;
10211021-10221022- if(args.Count < 2)
10231023- {
10241024- macro\report_error("Symbol description missing in symbol access node creation.");
10251025- return null;
10261026- }
10271027-10281028- var c = ast\expand_macro(macro\entity(ast\macro));
10291029- var getSI\si = ast3("MemberAccess",macro\getSI,ast\read(context, symbolInterpretation),SI.get);
10301030- var last = args[args.Count - 1];
10311031- if(ast_is_ListLiteral(last))
10321032- getSI\si.Arguments.AddRange(last.Elements);
10331033- else
10341034- getSI\si.Arguments.Add(last);
10351035- c.Arguments.Add(ast3("Constant", "GetSetSymbol"));
10361036- c.Arguments.AddRange(args >> skip(1) >> take(args.Count-2));
10371037- c.Arguments.Add(getSI\si);
10381038- //println(context.Function," LINE ", context.Invocation.Line, " :: ", c);
10391039- return c;
865865+ return;
1040866}
10418671042868macro ast\call(callTypeExpr,entityExpr)
···10618871062888 // ast3("IndirectCall",ast3("Reference",$(entity)),$(callType));
106388910641064- var referenceCtor = ast\expand_macro(macro\entity(ast3));
890890+ var referenceCtor = ast\expand_macro(entityref_to(ast3));
1065891 referenceCtor.Arguments.Add(ast3("Constant","Reference"));
1066892 referenceCtor.Arguments.Add(entityExpr);
106789310681068- var indirectCallCtor = ast\expand_macro(macro\entity(ast3));
894894+ var indirectCallCtor = ast\expand_macro(entityref_to(ast3));
1069895 indirectCallCtor.Arguments.Add(ast3("Constant","IndirectCall"));
1070896 indirectCallCtor.Arguments.Add(referenceCtor);
1071897 indirectCallCtor.Arguments.Add(callTypeExpr);
10728981073899 context.Block.Expression = indirectCallCtor;
900900+ return;
1074901}
10759021076903macro ast\cmd(callType,id)
···1103930 callExpansion.Arguments.Add(entityExpr);
11049311105932 context.Block.Expression = callExpansion;
933933+ return;
1106934}
11079351108936macro ast\lvar(callType,id)
···1135963 callExpansion.Arguments.Add(entityExpr);
11369641137965 context.Block.Expression = callExpansion;
966966+ return;
1138967}
11399681140969macro ast\lref(callType,id)
···11761005 indirectCallCtor.Arguments.Add(callType);
1177100611781007 context.Block.Expression = indirectCallCtor;
10081008+ return;
11791009}
1180101011811011macro ast\func(callType,internalId,moduleName)
···12121042 callExpansion.Arguments.Add(entityExpr);
1213104312141044 context.Block.Expression = callExpansion;
10451045+ return;
12151046}
1216104712171048macro ast\gvar(callType,internalId,moduleName)
···12461077 callExpansion.Arguments.Add(entityExpr);
1247107812481079 context.Block.Expression = callExpansion;
10801080+ return;
12491081}
1250108212511083macro ast\gref(callType,internalId,moduleName)
···12891121 indirectCallCtor.Arguments.Add(callType);
1290112212911123 context.Block.Expression = indirectCallCtor;
11241124+ return;
12921125}
12931126//Create GetSetMemberAccess node
12941127macro ast\member(subject, call_type, id)
···13571190 if(ast_is_Null(value) or (ast_is_Constant(value) and value.Constant is null))
13581191 {
13591192 var c = ast\expand_macro(macro\entity(ast\macro));
13601360- c.Arguments.Add(ast("Constant","Null"));
11931193+ c.Arguments.Add(ast3("Constant","Null"));
13611194 return c;
13621195 }
13631196 else if(ast_is_Constant(value))
13641197 {
13651198 var c = ast\expand_macro(macro\entity(ast\macro));
13661366- c.Arguments.Add(ast("Constant","Constant"));
11991199+ c.Arguments.Add(ast3("Constant","Constant"));
13671200 c.Arguments.Add(value);
13681201 return c;
13691202 }
+4-2
Prx/psr/test/meta_macro.pxs
···4949 var block = funcTar.Ast;
50505151 //Setup invocation of test macro
5252- var invocation = new ::AstMacroInvocation(fakeFile,-1,-1,
5353- new ::SymbolEntry(::SymbolInterpretations.Function,testMacro.Id, testMacro.ParentApplication.Module.Name));
5252+ var invocation = new ::AstExpand(
5353+ Prexonite::Compiler::NoSourcePosition.Instance,
5454+ ~Object<"Prexonite.Modular.EntityRef+Function">.Create(testMacro.Id, testMacro.ParentApplication.Module.Name),
5555+ Prexonite::Types::PCall.Get);
5456 block.Add(invocation);
55575658 //Compile host function