コード例 #1
0
 public void Visit(CallSelf e)
 {
     e.Object.Accept(this);
     o.Write(":");
     o.Write(e.MethodName);
     o.Write("(");
     if (e.Arguments.Count > 0 || e.ArgumentValues != null)
     {
         o.Write(" ");
         bool bFirst = true;
         foreach (Expression argument in e.Arguments)
         {
             if (!bFirst)
             {
                 o.Write(", ");
             }
             bFirst = false;
             argument.Accept(this);
         }
         if (e.ArgumentValues != null)
         {
             if (!bFirst)
             {
                 o.Write(", ");
             }
             bFirst = false;
             o.Write("values ");
             e.ArgumentValues.Accept(this);
         }
         o.Write(" ");
     }
     o.Write(")");
 }
コード例 #2
0
ファイル: BytecodeCompiler.cs プロジェクト: edmundmk/apollua
        Allocation SetTop(Expression e)
        {
            Allocation results;

            if (e is Call)
            {
                Call call = (Call)e;
                results = BuildCall(0, call.Function, null, call.Arguments, call.ArgumentValues);
            }
            else if (e is CallSelf)
            {
                CallSelf call = (CallSelf)e;
                results = BuildCall(0, call.Object, call.MethodName, call.Arguments, call.ArgumentValues);
            }
            else if (e is Vararg)
            {
                results = function.Top();
                function.InstructionABC(e.SourceSpan, Opcode.Vararg, results, 0, 0);
                results.SetTop();
            }
            else
            {
                throw new InvalidOperationException();
            }

            return(results);
        }
コード例 #3
0
ファイル: BytecodeCompiler.cs プロジェクト: edmundmk/apollua
        public void Visit(CallSelf e)
        {
            Allocation result = BuildCall(2, e.Object, e.MethodName, e.Arguments, e.ArgumentValues);

            if ((int)target != (int)result)
            {
                function.InstructionABC(e.SourceSpan, Opcode.Move, target, result, 0);
            }
            result.Release();
        }
コード例 #4
0
ファイル: FunctionTransform.cs プロジェクト: edmundmk/apollua
        public virtual void Visit(CallSelf e)
        {
            Expression o = Transform(e.Object);

            Expression[] arguments = new Expression[e.Arguments.Count];
            for (int i = 0; i < e.Arguments.Count; ++i)
            {
                arguments[i] = Transform(e.Arguments[i]);
            }
            Expression argumentValues = e.ArgumentValues != null?Transform(e.ArgumentValues) : null;

            result = new CallSelf(e.SourceSpan, o, e.MethodName, Array.AsReadOnly(arguments), argumentValues);
        }
コード例 #5
0
ファイル: BytecodeCompiler.cs プロジェクト: edmundmk/apollua
        public void Visit(ReturnList s)
        {
            // Check for tailcall.
            if (s.Results.Count == 0)
            {
                if (s.ResultList is Call)
                {
                    Call call = (Call)s.ResultList;
                    BuildCall(TailCallC, call.Function, null, call.Arguments, call.ArgumentValues);
                    return;
                }
                else if (s.ResultList is CallSelf)
                {
                    CallSelf call = (CallSelf)s.ResultList;
                    BuildCall(TailCallC, call.Object, call.MethodName, call.Arguments, call.ArgumentValues);
                    return;
                }
            }

            // Push results onto the stack.
            Allocation allocation = function.Top();

            foreach (Expression result in s.Results)
            {
                Allocation allocResult = Push(result);
                allocResult.Release();
                allocation.Allocate();
            }

            // Push result values onto the stack.
            int B;

            if (s.ResultList != null)
            {
                Allocation allocValues = SetTop(s.ResultList);
                allocValues.Release();
                allocation.SetTop();
                B = 0;
            }
            else
            {
                B = s.Results.Count + 1;
            }

            // Return.
            function.InstructionABC(s.SourceSpan, Opcode.Return, allocation, B, 0);
            allocation.Release();
        }
コード例 #6
0
ファイル: BytecodeCompiler.cs プロジェクト: edmundmk/apollua
 void Evaluate(Expression e)
 {
     if (e is Call)
     {
         Call call = (Call)e;
         BuildCall(1, call.Function, null, call.Arguments, call.ArgumentValues);
     }
     else if (e is CallSelf)
     {
         CallSelf call = (CallSelf)e;
         BuildCall(1, call.Object, call.MethodName, call.Arguments, call.ArgumentValues);
     }
     else if (e is Vararg)
     {
         // Do nothing since vararg has no side effects.
     }
     else
     {
         Allocation allocation = R(e);
         allocation.Release();
     }
 }