Exemplo n.º 1
0
 private Expression ParseKeyword_DO(string Keyword)
 {
     if (!INTERCATIVE)
     {
         var snap      = ExpressionTypeBeam.TakeSnapshot();
         var @break    = Expression.Label("break");
         var @continue = Expression.Label("continue");
         Contextual.Push(Expression.Goto(@break));
         Contextual.Push(Expression.Goto(@continue));
         List <Expression> Instruction = new List <Expression>();
         Instruction.Add(Expression.Label(@continue));
         Instruction.AddRange(ParseBlock(true));
         LineNumber--;
         if (Peek(5).ToUpper() != "UNTIL")
         {
             throw new AutoitException(AutoitExceptionType.EXPECTUNTIL, LineNumber, Cursor, Getstr(Reg_AlphaNum));
         }
         Consume(5);
         ConsumeWS();
         var Cond = Expression.Not(ParseBoolean(false).ConvertTo(typeof(bool)));
         //Instruction.AddRange(VarSynchronisation);
         //VarSynchronisation.Clear();
         Instruction.Add(Expression.IfThen(Cond, Expression.Goto(@continue)));
         Instruction.Add(Expression.Label(@break));
         Instruction.Add(ExpressionTypeBeam.RestoreSnapshot(snap));
         Contextual.Pop();
         Contextual.Pop();
         return(Expression.Block(Instruction.ToArray()));
     }
     else
     {
         throw new AutoitException(AutoitExceptionType.MULTILINEININTERACTIVE, LineNumber, Cursor, Keyword);
     }
 }
        //protected CompileFuncDelegate CompileFunc;
        public void LiCompileFunction()
        {
            foreach (var ID in FunctionIdentifiers)
            {
                GotoLine(ID.Key);
                var FMeta = GetFunctionMeta();
                NextLine();
                var Ret = Expression.Label();
                Contextual.Push(Expression.Goto(Ret, FMeta.ReturnType));
                ExpressionTypeBeam.PushScope();
                foreach (var arg in FMeta.Parameters)
                {
                    ExpressionTypeBeam.CurrentScope.SetVarCached(arg.Name, Expression.Constant(arg.ArgType.DefaultValue(), arg.ArgType), false);
                }
                ExpressionTypeBeam.CurrentScope.DefineFunc(ID.Value, Expression.Lambda(ParseBlock(), ExpressionTypeBeam.PopScope()));
            }

            /*
             * return;
             * var Matches = Script.Where(x => Regex.IsMatch(x, "^(?:\t| )*func(.*?)$", RegexOptions.IgnoreCase)).ToList();
             * var Lines = Matches.Select(x => Array.IndexOf(Script, x));
             * List<ParameterExpression> Params = new List<ParameterExpression>();
             * foreach (var L in Lines)
             * {
             *  GotoLine(L);
             *  var FMeta = GetFunctionMeta();
             *  ExpressionTypeBeam.PushScope();
             *  List<Expression> PreFunction = new List<Expression>();
             *
             *  var MyFunc = ExpressionTypeBeam.CurrentScope.Parent.ScopeFunctions.First(x => x.Name == FMeta.Name && x.Parameters.SequenceEqual(FMeta.Parameters) && x.ReturnType == FMeta.ReturnType);
             *
             *  PreFunction.Add(VarAutExpression.VariableAccess("Return-store", false)
             *      .Setter(Expression.Constant(FMeta.ReturnType.DefaultValue(), FMeta.ReturnType)));
             *  PreFunction.AddRange(
             *      MyFunc.Parameters.Select(x =>
             *      {
             *          var PType = x.GetTypeInfo().IsValueType ? typeof(Nullable<>).MakeGenericType(x) : x;
             *          Params.Add(Expression.Parameter(PType));
             *          return VarAutExpression.VariableAccess(x.ArgName).Setter(
             *              Expression.Coalesce(Params.Last(), x.DefaultValue().ConvertTo(x))
             *          );
             *      })
             *  );
             *  var Ret = Expression.Label();
             *  Contextual.Push(Expression.Goto(Ret, FMeta.ReturnType));
             *
             *  var Block = ParseBlock();
             *
             *  Block.Add(Expression.Label(Ret));
             *  Block.Add(VarAutExpression.VariableAccess("Return-store", false).Getter(L.FDef.ReturnType));
             *  ExpressionTypeBeam.CurrentScope.DefineFunc(, Expression.Lambda(Expression.Block(ExpressionTypeBeam.PopScope(), Block), Params));
             *  Block.Clear();
             *  Params.Clear();
             * }*/
        }
Exemplo n.º 3
0
        private Expression ParseKeyword_WHILE(string Keyword)
        {
            var Element = ParseBoolean(false).ConvertTo(typeof(bool));
            var snap    = ExpressionTypeBeam.TakeSnapshot();

            ConsumeWS();
            if (!EOL)
            {
                var @break    = Expression.Label();
                var @continue = Expression.Label();
                return(Expression.Block(
                           Expression.Label(@continue),
                           Expression.IfThen(Expression.Not(Element), Expression.Goto(@break)),
                           ParseBoolean(),
                           Expression.Goto(@continue),
                           Expression.Label(@break)));
            }
            else if (!INTERCATIVE)
            {
                var @break    = Expression.Label("break");
                var @continue = Expression.Label("continue");
                Contextual.Push(Expression.Goto(@break));
                Contextual.Push(Expression.Goto(@continue));
                List <Expression> Instruction = new List <Expression>();
                Instruction.Add(Expression.Label(@continue));
                Instruction.Add(Expression.IfThen(Expression.Not(Element), Expression.Goto(@break)));
                Instruction.AddRange(ParseBlock(true));
                Instruction.Add(Expression.Goto(@continue));
                Instruction.Add(Expression.Label(@break));
                Instruction.Add(ExpressionTypeBeam.RestoreSnapshot(snap));
                Contextual.Pop();
                Contextual.Pop();
                return(Expression.Block(Instruction.ToArray()));
            }
            else
            {
                throw new AutoitException(AutoitExceptionType.MULTILINEININTERACTIVE, LineNumber, Cursor, Keyword);
            }
        }
Exemplo n.º 4
0
        private Expression ParseKeyword_FOR(string Keyword)
        {
            Expression InitVal, LastVal, Step;
            string     ForVarName;

            ForVarName = (ParsePrimary() as VarAutExpression).Name;
            ConsumeWS();
            if (Peek(1).ToUpper() != "=")
            {
                throw new AutoitException(AutoitExceptionType.FORWITHOUTTO, LineNumber, Cursor);
            }
            Consume(); ConsumeWS();
            InitVal = ParseBoolean().ConvertToNumber();
            ConsumeWS();
            if (Peek(2).ToUpper() != "TO")
            {
                throw new AutoitException(AutoitExceptionType.FORWITHOUTTO, LineNumber, Cursor);
            }
            Consume(2); ConsumeWS();
            LastVal = ParseBoolean().ConvertTo(InitVal.Type);
            ConsumeWS();
            if (Peek(4).ToUpper() == "STEP")
            {
                Consume(4); ConsumeWS();
                Step = ParseBoolean().ConvertTo(InitVal.Type);
            }
            else
            {
                Step = Expression.Constant(1, typeof(int)).ConvertTo(InitVal.Type);
            }
            if (!INTERCATIVE)
            {
                var @break    = Expression.Label("break");
                var @continue = Expression.Label("continue");
                var @DownTo   = VarAutExpression.VariableAccess("downto-" + Contextual.Count, false);
                var @LoopVar  = VarAutExpression.VariableAccess(ForVarName, false);
                Contextual.Push(Expression.Goto(@break));
                Contextual.Push(Expression.Goto(@continue));
                List <Expression> Instruction = new List <Expression>();
                if (Step is ConstantExpression)
                {
                    Instruction.Add(@DownTo.Setter((ConstantExpression)Expression.Constant((dynamic)(Step as ConstantExpression).Value < 0, typeof(bool))));
                }
                else
                {
                    Instruction.Add(@DownTo.Setter(Expression.LessThan(Step, Expression.Constant(0, InitVal.Type))));
                }
                Instruction.Add(@LoopVar.Setter(InitVal));
                Instruction.Add(Expression.Label(@continue));
                Instruction.Add(Expression.IfThen(
                                    Expression.OrElse(
                                        Expression.AndAlso(
                                            @DownTo.Getter(typeof(bool)),
                                            Expression.LessThan(@LoopVar.Getter(InitVal.Type), LastVal)),
                                        Expression.AndAlso(
                                            Expression.Not(@DownTo.Getter(typeof(bool))),
                                            Expression.GreaterThan(@LoopVar.Getter(InitVal.Type), LastVal)))
                                    , Expression.Goto(@break)));
                Instruction.AddRange(ParseBlock(true));
                Instruction.Add(Expression.Assign(
                                    @LoopVar.Getter(InitVal.Type),
                                    Expression.Add(@LoopVar.Getter(InitVal.Type), Step)));
                Instruction.Add(Expression.Goto(@continue));
                Instruction.Add(Expression.Label(@break));
                Contextual.Pop();
                Contextual.Pop();
                return(Expression.Block(Instruction.ToArray()));
            }
            else
            {
                throw new AutoitException(AutoitExceptionType.MULTILINEININTERACTIVE, LineNumber, Cursor, Keyword);
            }
        }