lojix/wam_prolog/src/main/com/thesett/aima/logic/fol/wam/machine/WAMResolvingMachine.java
protected Set<Variable> executeAndExtractBindings(WAMCompiledQuery query)
    {
        // Execute the query and program. The starting point for the execution is the first functor in the query
        // body, this will follow on to the subsequent functors and make calls to functors in the compiled programs.
        boolean success = execute(query.getCallPoint());

        // Used to collect the results in.
        Set<Variable> results = null;

        // Collect the results only if the resolution was successfull.
        if (success)
        {
            results = new HashSet<Variable>();

            // The same variable context is used accross all of the results, for common use of variables in the
            // results.
            Map<Integer, Variable> varContext = new HashMap<Integer, Variable>();

            // For each of the free variables in the query, extract its value from the location on the heap pointed to
            // by the register that holds the variable.
            /*log.fine("query.getVarNames().size() =  " + query.getVarNames().size());*/

            for (byte reg : query.getVarNames().keySet())
            {
                int varName = query.getVarNames().get(reg);

                if (query.getNonAnonymousFreeVariables().contains(varName))
                {
                    int addr = derefStack(reg);
                    Term term = decodeHeap(addr, varContext);

                    results.add(new Variable(varName, term, false));
                }
            }
        }

        return results;
    }
protected Set<Variable> executeAndExtractBindings(WAMCompiledQuery query)
    {
        // Execute the query and program. The starting point for the execution is the first functor in the query
        // body, this will follow on to the subsequent functors and make calls to functors in the compiled programs.
        boolean success = execute(query.getCallPoint());

        // Used to collect the results in.
        Set<Variable> results = null;

        // Collect the results only if the resolution was successfull.
        if (success)
        {
            results = new HashSet<Variable>();

            // The same variable context is used accross all of the results, for common use of variables in the
            // results.
            Map<Integer, Variable> varContext = new HashMap<Integer, Variable>();

            // For each of the free variables in the query, extract its value from the location on the heap pointed to
            // by the register that holds the variable.
            /*log.fine("query.getVarNames().size() =  " + query.getVarNames().size());*/

            for (byte reg : query.getVarNames().keySet())
            {
                int varName = query.getVarNames().get(reg);

                if (query.getNonAnonymousFreeVariables().contains(varName))
                {
                    int addr = derefStack(reg);
                    Term term = decodeHeap(addr, varContext);

                    results.add(new Variable(varName, term, false));
                }
            }
        }

        return results;
    }
Runs a query, and for every non-anonymous variable in the query, decodes its binding value from the heap and
returns it in a set of variable bindings.

@param  query The query to execute.

@return A set of variable bindings resulting from the query.