コード例 #1
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);
        }
コード例 #2
0
        public static Variable ExtractConst(string str)
        {
            int      intValue;
            Variable v = null;

            if (Int32.TryParse(str, out intValue))
            {
                v = new ConstIntVariable(intValue);
            }

            return(v);
        }
コード例 #3
0
        private static Variable TryConst(string stringValue)
        {
            Variable v = null;

            if (Int32.TryParse(stringValue, out int ivalue))
            {
                v = new ConstIntVariable(ivalue);
            }
            else if (Single.TryParse(stringValue, out float fvalue))
            {
                v = new ConstFloatVariable(fvalue);
            }

            return(v);
        }
コード例 #4
0
        public void ExtractVariables(Function fct, string[] args, int count)
        {
            int value = 0;

            while (args.Length > count)
            {
                Variable v = fct.GetVariable(args[count]);

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

                Variables.Add(v);
                ++count;
            }
        }
コード例 #5
0
        public static void Set(Compiler cmp, Argument[] args)
        {
            int      value;
            Function fct = cmp.Functions.Last();
            Variable v   = fct.GetVariable(args[1]);

            if (TryConstSet(fct, v, args[2]))
            {
            }
            else if (TryPtrSet(fct, v, args[2]))
            {
            }

/* TODO Casts && Copy
 * else if ()
 *          {
 *
 *          }*/
            else
            {
                int count              = 3;
                int startIdx           = 2;
                FctCallInstruction fci = FctCallInstruction.GetCallInstruction(cmp, args.StringArray(), ref startIdx);

                count = startIdx + 1;
                while (count < args.Length)
                {
                    Variable a = fct.GetVariable(args[count]);

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

                    fci.Variables.Add(a);
                    ++count;
                }

                RetCarryInstruction rci = new RetCarryInstruction(v);

                fct.Instructions.Add(fci);
                fct.Instructions.Add(rci);
            }
        }