예제 #1
0
        private static Action <Compiler, Argument[]> GenericVariableType <T, U, V>(ConverterFct <T> converter) where U : Variable <T>, new() where V : ConstVariable <T>, new()
        {
            Action <Compiler, Argument[]> act = (cmp, args) =>
            {
                U v = new U
                {
                    Name = args[1],
                };

                if (cmp.ProcessingBlock is Structure)
                {
                    cmp.ProcessingBlock.As <Structure>().Variables.Add(v);

                    return;
                }

                T        value;
                Function fct = cmp.Functions.Last();

                if (args.Length == 3 && converter(args[2], out value))
                {
                    v.HaveValue = true;
                    v.Value     = value;

                    fct.Instructions.Insert(0, new NewSetInstruction
                    {
                        Destination = v,
                        Source      = new ConstValue(v.Value)
                    });
                }
                else if (args.Length >= 3)
                {
                    int                count     = 3;
                    Function           fctToCall = cmp.Functions.First(i => i.Name == args[2]);
                    FctCallInstruction ret       = new FctCallInstruction(fctToCall);

                    fct.Instructions.Add(ret);
                    fct.Instructions.Add(new RetCarryInstruction(v));
                    while (args.Length > count)
                    {
                        Variable target = fct.Variables.FirstOrDefault(a => a.Name == args[count]);

                        if (target == null && converter(args[count], out value))
                        {
                            V constVar = new V();

                            constVar.SetValue(value);
                            target = constVar;
                        }

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

                fct.AddVariable(v);
            };

            return(act);
        }
예제 #2
0
        public static void CallFct(Compiler cmp, Argument[] args)
        {
            int                count    = 0;
            int                startIdx = 1;
            int                value    = 0;
            Function           fct      = cmp.Functions.Last();
            FctCallInstruction c        = FctCallInstruction.GetCallInstruction(cmp, args.StringArray(), ref startIdx);

            count = startIdx + 1;
            c.ExtractVariables(fct, args.StringArray(), count);
            fct.Instructions.Add(c);
        }
예제 #3
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);
            }
        }