コード例 #1
0
ファイル: BodySyntax.cs プロジェクト: pvginkel/Jint2
        public BodySyntax(BodyType bodyType, ReadOnlyArray<SyntaxNode> statements, ReadOnlyArray<IIdentifier> identifiers, bool isStrict, Closure closure)
            : base(statements)
        {
            if (identifiers == null)
                throw new ArgumentNullException("identifiers");

            BodyType = bodyType;
            Identifiers = identifiers;
            IsStrict = isStrict;
            Closure = closure;
        }
コード例 #2
0
            public Scope(Scope parent, BodySyntax body, IScriptBuilder scriptBuilder)
            {
                Parent = parent;
                TypeManager = new BoundTypeManager();

                if (body.Closure != null)
                {
                    _sourceClosure = body.Closure;

                    Closure = new BoundClosure(
                        FindParentClosure(),
                        body.Closure.Fields.Select(p => TypeManager.CreateType(p, BoundTypeKind.ClosureField)),
                        scriptBuilder
                    );
                }

                foreach (var variable in body.Identifiers)
                {
                    if (variable.Index.HasValue)
                    {
                        BoundClosure closure = null;
                        if (variable.Closure != null)
                            closure = GetClosure(variable.Closure);

                        _arguments.Add(variable, new BoundArgument(variable.Name, variable.Index.Value, closure));
                    }
                    else if (variable.Closure == null)
                    {
                        BoundLocalBase local;
                        if (variable.Type == IdentifierType.Global)
                            local = new BoundGlobal(variable.IsDeclared, TypeManager.CreateType(variable.Name, BoundTypeKind.Global));
                        else
                            local = new BoundLocal(variable.IsDeclared, TypeManager.CreateType(variable.Name, BoundTypeKind.Local));

                        _locals.Add(variable, local);
                    }
                }
            }
コード例 #3
0
ファイル: AstBuilder.Scope.cs プロジェクト: pvginkel/Jint2
            private Closure BuildClosure()
            {
                if (_closedOverIdentifiers.Count <= 0)
                    return null;

                // Build the closure.

                var closure = new Closure(_closedOverIdentifiers.OrderBy(p => p.Name).Select(p => p.Name).ToReadOnlyArray());

                foreach (var identifier in _closedOverIdentifiers)
                {
                    identifier.Closure = closure;
                }

                return closure;
            }
コード例 #4
0
            private BoundClosure GetClosure(Closure closure)
            {
                var scope = this;

                while (scope != null)
                {
                    if (scope._sourceClosure == closure)
                        return scope.Closure;

                    scope = scope.Parent;
                }

                throw new InvalidOperationException("Cannot find bound closure");
            }