示例#1
0
        private void CGFuncCallStat(FuncInfo funcInfo, FuncCallStatNode node)
        {
            var             r        = funcInfo.AllocReg();
            FuncCallExpNode funcCall = new FuncCallExpNode();

            funcCall.Args    = node.Args;
            funcCall.NameExp = node.NameExp;
            funcCall.PreExp  = node.PreExp;
            CGFuncCallExp(funcInfo, funcCall, r, 0);
        }
示例#2
0
        private int PrepFuncCall(FuncInfo funcInfo, FuncCallExpNode node, int a)
        {
            int  nArgs = node.Args.Count;
            bool lastVarIsVarargOrFuncCall = false;

            CGExp(funcInfo, node.PreExp, a, 1);
            if (node.NameExp.ExpType != ConstExpNode.ConstExpType.NilExp)
            {
                int c = 0x100 + funcInfo.IndexOfConstVar(node.NameExp.name);
                funcInfo.EmitSelf(a, a, c);
            }
            int i = 0;

            foreach (var arg in node.Args)
            {
                int r = funcInfo.AllocReg();
                if (i == nArgs - 1 && IsVarargOrFuncCall(arg))
                {
                    lastVarIsVarargOrFuncCall = true;
                    CGExp(funcInfo, arg, r, -1);
                }
                else
                {
                    CGExp(funcInfo, arg, r, 1);
                }
                i++;
            }
            funcInfo.FreeRegs(nArgs);
            if (node.NameExp.ExpType != ConstExpNode.ConstExpType.NilExp)
            {
                nArgs++;
            }
            if (lastVarIsVarargOrFuncCall)
            {
                nArgs--;
            }
            return(nArgs);
        }
示例#3
0
        private void CGFuncCallExp(FuncInfo funcInfo, FuncCallExpNode node, int a, int n)
        {
            int nArgs = PrepFuncCall(funcInfo, node, a);

            funcInfo.EmitCall(a, nArgs, n);
        }