/** * Generates the next element in the search. * * @return The next solution from the search if one is available, or <tt>null</tt> if the search is * complete. */ public T nextInSequence() { try { return search.search(); } catch (SearchNotExhaustiveException e) { // SearchNotExhaustiveException means that the search has completed within its designed parameters // without exhausting the search space. Consequently there are no more solutions to find, // the exception can be ignored and the sequence correctly terminated. e = null; return null; } } };
/** * Allocates terms within a functor expression to registers. The outermost functor itself is not assigned to a * register in WAM (only in l0). Functors already directly assigned to argument registers will not be re-assigned by * this. Variables as arguments will be assigned but not as argument registers. * * @param expression The expression to walk over. */ protected void allocateTemporaryRegisters(Term expression) { // Need to assign registers to the whole syntax tree, working in from the outermost functor. The outermost // functor itself is not assigned to a register in l3 (only in l0). Functors already directly assigned to // argument registers will not be re-assigned by this, variables as arguments will be assigned. SearchMethod outInSearch = new BreadthFirstSearch<Term, Term>(); outInSearch.reset(); outInSearch.addStartState(expression); Iterator<Term> treeWalker = Searches.allSolutions(outInSearch); // Discard the outermost functor from the variable allocation. treeWalker.next(); // For each term encountered: set X++ = term. while (treeWalker.hasNext()) { Term term = treeWalker.next(); if (symbolTable.get(term.getSymbolKey(), SymbolTableKeys.SYMKEY_ALLOCATION) == null) { int allocation = (lastAllocatedTempReg++ & 0xff) | (REG_ADDR << 8); symbolTable.put(term.getSymbolKey(), SymbolTableKeys.SYMKEY_ALLOCATION, allocation); } } }
labelSearch.reset(); labelSearch.addStartState(startState);
outInSearch.reset(); outInSearch.addStartState(expression);
/** * Generates the next element in the search. * * @return The next solution from the search if one is available, or <tt>null</tt> if the search is * complete. */ public T nextInSequence() { try { return search.search(); } catch (SearchNotExhaustiveException e) { // SearchNotExhaustiveException means that the search has completed within its designed parameters // without exhausting the search space. Consequently there are no more solutions to find, // the exception can be ignored and the sequence correctly terminated. e = null; return null; } } };