Exemplo n.º 1
0
 public static bool IsCommandCall(this AstNode node, string commandAlias, out AstIndirectCall indirectCallNode)
 {
     EntityRef entityRef;
     EntityRef.Command cmd;
     return node.TryMatchCall(out indirectCallNode, out entityRef) && entityRef.TryGetCommand(out cmd) &&
            Engine.StringsAreEqual(cmd.Id, commandAlias);
 }
Exemplo n.º 2
0
 public static bool TryMatchCall(this AstNode node, out AstIndirectCall indirectCallNode,
                                 out AstReference referenceNode, out EntityRef entityRef)
 {
     if ((indirectCallNode = node as AstIndirectCall) != null
         && (referenceNode = indirectCallNode.Subject as AstReference) != null)
     {
         entityRef = referenceNode.Entity;
         return true;
     }
     else
     {
         referenceNode = null;
         entityRef = null;
         return false;
     }
 }
Exemplo n.º 3
0
     private static bool _isStacklessRecursionPossible(CompilerTarget target,
 AstIndirectCall symbol)
     {
         var refNode = symbol.Subject as AstReference;
         if (refNode == null)
             return false;
         EntityRef.Function funcRef;
         if (!refNode.Entity.TryGetFunction(out funcRef))
             return false;
         if (funcRef.Id != target.Function.Id)
             return false;
         if (funcRef.ModuleName != target.Function.ParentApplication.Module.Name)
             return false;
         if (target.Function.Variables.Contains(PFunction.ArgumentListId))
             //must not use argument list
             return false;
         if (symbol.Arguments.Count > target.Function.Parameters.Count)
             //must not supply more arguments than mapped
             return false;
         return true;
     }
Exemplo n.º 4
0
        protected override void DoExpand(MacroContext context)
        {
            if (context.Invocation.Arguments.Count < 1)
            {
                context.ReportMessage(
                    Message.Error(
                        string.Format(Resources.CallStar_usage, Id), context.Invocation.Position,
                        MessageClasses.CallStarUsage));
                return;
            }

            int passThrough;
            List<AstExpr> arguments;
            _determinePassThrough(context, out passThrough, out arguments);

            if (arguments.Skip(passThrough).Any(_isPartialList))
            {
                _expandPartialApplication(context, passThrough, arguments);
                return;
            }

            // "Fallback" direct invocation
            var ic = new AstIndirectCall(context.Invocation.File, context.Invocation.Line,
                context.Invocation.Column, context.Invocation.Call, arguments[0]);
            ic.Arguments.AddRange(arguments.Skip(1));
            context.Block.Expression = ic;
        }
Exemplo n.º 5
0
        public static AstGetSet CreateNeutralExpression(AstGetSet invocation)
        {
            var nullLiteral = new AstNull(invocation.File, invocation.Line, invocation.Column);
            var call = new AstIndirectCall(invocation.File, invocation.Line, invocation.Column,
                invocation.Call, nullLiteral);
            if (invocation.Call == PCall.Set)
                call.Arguments.Add(new AstNull(invocation.File, invocation.Line, invocation.Column));

            return call;
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Emits code responsible for changing the variables identity.
        /// </summary>
        /// <param name = "target">The target to compile to</param>
        private void _emitNewDeclareCode(CompilerTarget target)
        {
            _ensureValid();
            //create command call
            //  unbind(->variable)
            var unlinkCall = new AstIndirectCall(Position, PCall.Get,
                                                 new AstReference(Position, EntityRef.Command.Create(Engine.UnbindAlias)));
            var targetRef = new AstReference(Position, EntityRef.Variable.Local.Create(Id));
            unlinkCall.Arguments.Add(targetRef);

            //Optimize call and emit code
            var call = (AstExpr) unlinkCall;
            _OptimizeNode(target, ref call);
            call.EmitEffectCode(target);
        }
Exemplo n.º 7
0
 public static bool TryMatchCall(this AstNode node, out AstIndirectCall indirectCallNode, out EntityRef entityRef)
 {
     AstReference referenceNode;
     return TryMatchCall(node, out indirectCallNode, out referenceNode, out entityRef);
 }