Search in sources :

Example 1 with SLLexicalScope

use of com.oracle.truffle.sl.nodes.local.SLLexicalScope in project graal by oracle.

the class SLLanguage method findLocalScopes.

@Override
public Iterable<Scope> findLocalScopes(SLContext context, Node node, Frame frame) {
    final SLLexicalScope scope = SLLexicalScope.createScope(node);
    return new Iterable<Scope>() {

        @Override
        public Iterator<Scope> iterator() {
            return new Iterator<Scope>() {

                private SLLexicalScope previousScope;

                private SLLexicalScope nextScope = scope;

                @Override
                public boolean hasNext() {
                    if (nextScope == null) {
                        nextScope = previousScope.findParent();
                    }
                    return nextScope != null;
                }

                @Override
                public Scope next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    Scope vscope = Scope.newBuilder(nextScope.getName(), nextScope.getVariables(frame)).node(nextScope.getNode()).arguments(nextScope.getArguments(frame)).build();
                    previousScope = nextScope;
                    nextScope = null;
                    return vscope;
                }
            };
        }
    };
}
Also used : SLLexicalScope(com.oracle.truffle.sl.nodes.local.SLLexicalScope) Scope(com.oracle.truffle.api.Scope) Iterator(java.util.Iterator) SLLexicalScope(com.oracle.truffle.sl.nodes.local.SLLexicalScope) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Scope (com.oracle.truffle.api.Scope)1 SLLexicalScope (com.oracle.truffle.sl.nodes.local.SLLexicalScope)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1