示例#1
0
        public DLR.Expression <Func <Rila, dynamic> > ConstructProgram(Rila runtime)
        {
            var scope = new GenScopeRoot(runtime);

            var stmts = new DLR.Expression[Statements.Count];

            for (int i = 0; i < Statements.Count; i++)
            {
                stmts[i] = Statements.ElementAt(i).GenerateExpressionTree(scope);
            }

            //Set the variables defined at the top level
            var globals = scope.Definitions.Select(x => x.Value);

            var block = DLR.Expression.Block(globals, stmts);

            if (block.Type == typeof(void)) //Program should always return a value
            {
                block = DLR.Expression.Block(block, DLR.Expression.Default(typeof(object)));
            }

            return(DLR.Expression.Lambda <Func <Rila, dynamic> >(block, scope.Root.RuntimeParameter));
        }