public static Expression<Func<Scope, object>> Generate(Block block, BinderFactory factory, string fileName)
        {
            Contract.Requires<ArgumentNullException>(block != null);
            Contract.Requires<ArgumentNullException>(factory != null);
            Contract.Requires<ArgumentNullException>(fileName != null);

            var global = Expression.Parameter(typeof(Scope), "global");
            var gen = new GlobalGen(fileName, factory, global);
            Expression expr = gen.Generate(block);
            if (expr.Type != typeof(object))
                expr = Expression.Convert(expr, typeof(object));
            return Expression.Lambda<Func<Scope, object>>(expr, "プログラム", new[] { global });
        }
 // ===== ===== ===== ===== ===== method ===== ===== ===== ===== =====
 public Expression Generate(Block block)
 {
     if (block.Statements.Count == 0)
         return NullExpr;
     var list = new List<Expression> { DebugInfo(block.Range) };
     foreach (var stmt in block.Statements) {
         var pair = GenStmt(stmt);
         UpdateLocals(pair.Parameters, block.Range.Start);
         list.Add(pair.Expression);
     }
     var blockExpr = Expression.Block(ParamList.ToEnum(_locals), list);
     if (Target == null)
         return blockExpr;
     else
         return Expression.Label(Target, blockExpr);
 }
            // ===== ===== ===== ===== ===== method ===== ===== ===== ===== =====
            public Expression Generate(Block block)
            {
                Contract.Requires<ArgumentNullException>(block != null);
                Contract.Ensures(Contract.Result<Expression>() != null);

                if (block.Statements.Count == 0)
                    return NullExpr;
                var list = new List<Expression> { DebugInfo(block.Range) };
                foreach (var stmt in block.Statements) {
                    var pair = GenStmt(stmt);
                    if (pair.Parameters == null) {
                        list.Add(pair.Expression);
                    }
                    else {
                        var tmp = Expression.Parameter(pair.Expression.Type, "tmp_global_stmt");
                        var tmpLocal = new List<Expression>();
                        tmpLocal.Add(Expression.Assign(tmp, pair.Expression));
                        foreach (var p in ParamList.ToEnum(pair.Parameters))
                            tmpLocal.Add(AssignGlobal(p.Name, p));
                        tmpLocal.Add(tmp);
                        var ps = new ParamList(tmp, pair.Parameters);
                        list.Add(Expression.Block(ParamList.ToEnum(ps), tmpLocal));
                        Contract.Assume(list[list.Count - 1].Type == tmp.Type);
                    }
                }
                var blockExpr = Expression.Block(list);
                if (Target == null) {
                    return blockExpr;
                }
                else {
                    return Expression.Label(Target, blockExpr);
                }
            }
Exemple #4
0
 public Defun(string name, IEnumerable<ParamSuffixPair> parameters, Block block)
 {
     Contract.Requires<ArgumentNullException>(name != null);
     Contract.Requires<ArgumentNullException>(parameters != null);
     Contract.Requires<ArgumentNullException>(block != null);
     this.Name = name;
     this.Params = Array.AsReadOnly(parameters.ToArray());
     this.Block = block;
 }
Exemple #5
0
 public BlockExecute(Block block)
 {
     Contract.Requires<ArgumentNullException>(block != null);
     this.Block = block;
 }