/** * 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);