示例#1
0
        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
            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");
            }