Пример #1
0
        public override Instruction Build(Token[] args)
        {
            // todo1[ak] check args
            AsmHelper.CheckArgsCount(args, 0);

            Instruction instr = new RetInstruction();
            return instr;
        }
Пример #2
0
        public static void Ret(Compiler cmp, Argument[] args)
        {
            int         value = 0;
            Function    fct   = cmp.Functions.Last();
            Instruction r     = null;

            if (args.Length == 1)
            {
                r = new RetInstruction();
            }
            else
            {
                Variable v = fct.Variables.FirstOrDefault(a => a.Name == args[1]);

                if (v != null)
                {
                    r = new VariableRetInstruction(v);
                }
                else if (Int32.TryParse(args[1], out value))
                {
                    v = new ConstIntVariable(value);
                    r = new VariableRetInstruction(v);

                    fct.Variables.Add(v);
                }
                else
                {
                    int count = 2;

                    FunctionRetInstruction ret = new FunctionRetInstruction
                    {
                        FunctionToCall = cmp.Functions.First(i => i.Name == args[1])
                    };

                    while (args.Length > count)
                    {
                        v = fct.Variables.FirstOrDefault(a => a.Name == args[count]);

                        if (v == null && Int32.TryParse(args[count], out value))
                        {
                            v = new ConstIntVariable(value);
                        }

                        ret.Variables.Add(v);
                        ++count;
                    }

                    r = ret;
                }
            }

            fct.Instructions.Add(r);
        }