IronLua.Compiler.Scope.CreateFunctionChild C# (CSharp) Method

CreateFunctionChild() public static method

public static CreateFunctionChild ( Scope parent ) : Scope
parent Scope
return Scope
        public static Scope CreateFunctionChild(Scope parent)
        {
            return new Scope
                       {
                           parent = parent,
                           returnLabel = Expr.Label(typeof(object))
                       };
        }

Usage Example

示例#1
0
        Expr Visit(string name, FunctionBody function)
        {
            var parentScope = scope;

            scope = Scope.CreateFunctionChild(scope);

            var parameters = function.Parameters.Select(p => scope.AddLocal(p)).ToList();

            if (function.Varargs)
            {
                parameters.Add(scope.AddLocal(Constant.VARARGS, typeof(Varargs)));
            }

            var bodyExpr   = Expr.Block(Visit(function.Body), Expr.Label(scope.GetReturnLabel(), Expr.Constant(null)));
            var lambdaExpr = Expr.Lambda(bodyExpr, Constant.FUNCTION_PREFIX + name, parameters);

            scope = parentScope;
            return(lambdaExpr);
        }