예제 #1
0
파일: rhs.cpp 프로젝트: emamanto/Soar
rhs_value copy_rhs_value(agent* thisAgent, rhs_value rv, bool get_identity_set, bool get_cloned_identity)
{
    cons* c = NULL, *new_c = NULL, *prev_new_c = NULL;
    cons* fl=NULL, *new_fl=NULL;

    if (!rv) {
            return NULL;
    } else if ((rhs_value_is_reteloc(rv)) || (rhs_value_is_unboundvar(rv)))
    {
        return rv;
    } else if (rhs_value_is_funcall(rv))
    {
        fl = rhs_value_to_funcall_list(rv);
        allocate_cons(thisAgent, &new_fl);
        new_fl->first = fl->first;
        prev_new_c = new_fl;
        for (c = fl->rest; c != NIL; c = c->rest)
        {
            allocate_cons(thisAgent, &new_c);
            new_c->first = copy_rhs_value(thisAgent, static_cast<char*>(c->first), get_identity_set, get_cloned_identity);
            prev_new_c->rest = new_c;
            prev_new_c = new_c;
        }
        prev_new_c->rest = NIL;
        return funcall_list_to_rhs_value(new_fl);
    }
    else
    {
        rhs_symbol r = rhs_value_to_rhs_symbol(rv);
        uint64_t lID = r->inst_identity;
        Identity* l_identity = r->identity;
        if (get_identity_set)
        {
            if (l_identity)
            {
                if (l_identity->get_clone_identity())
                {
                    assert(false);
                    l_identity = thisAgent->explanationBasedChunker->get_identity_for_id(l_identity->get_clone_identity());
                }
                else
                {
                    l_identity = thisAgent->explanationBasedChunker->get_identity_for_id(l_identity->get_identity());
                }
            }
            else if (lID)
                l_identity = thisAgent->explanationBasedChunker->get_identity_for_id(lID);
        }
        if (l_identity && get_cloned_identity)
        {
            lID = l_identity->get_clone_identity();
            l_identity = NULL_IDENTITY_SET; // Will be filled in later based when finalizing
        }

        return allocate_rhs_value_for_symbol(thisAgent, r->referent, lID, r->cv_id, l_identity, r->was_unbound_var);
    }
}
예제 #2
0
void Explanation_Based_Chunker::reinstantiate_rhs_symbol(rhs_value pRhs_val)
{

    Symbol* var;

    if (rhs_value_is_funcall(pRhs_val))
    {
        cons* fl = rhs_value_to_funcall_list(pRhs_val);
        cons* c;

        for (c = fl->rest; c != NULL; c = c->rest)
        {
            dprint(DT_RHS_FUN_VARIABLIZATION, "Reversing variablization of funcall RHS value %r\n", static_cast<char*>(c->first));
            reinstantiate_rhs_symbol(static_cast<char*>(c->first));
            dprint(DT_RHS_FUN_VARIABLIZATION, "... RHS value is now %r\n", static_cast<char*>(c->first));
        }
        return;
    }

    rhs_symbol rs = rhs_value_to_rhs_symbol(pRhs_val);

    if (rs->referent->is_variable())
    {
        dprint(DT_REINSTANTIATE, "Reversing variablization for RHS symbol %y [%u] -> %y.\n", rs->referent, rs->inst_identity, rs->referent->var->instantiated_sym);
        Symbol* oldSym = rs->referent;
        rs->referent = rs->referent->var->instantiated_sym;
        thisAgent->symbolManager->symbol_add_ref(rs->referent);
        thisAgent->symbolManager->symbol_remove_ref(&oldSym);
        Identity* l_identity = rs->identity;
        if (l_identity)
        {
            rs->inst_identity = l_identity->get_clone_identity();
            rs->identity = NULL;
        }
    } else {
        dprint(DT_REINSTANTIATE, "Not a variable.  Ignoring %y [%u]\n", rs->referent, rs->inst_identity);
        rs->inst_identity = LITERAL_VALUE;
        rs->identity = NULL;
    }
}
예제 #3
0
파일: rhs.cpp 프로젝트: emamanto/Soar
void deallocate_rhs_value(agent* thisAgent, rhs_value rv)
{
    cons* c;
    cons* fl;

    if (!rv || rhs_value_is_reteloc(rv) || rhs_value_is_unboundvar(rv)) return;

    if (rhs_value_is_funcall(rv))
    {

        fl = rhs_value_to_funcall_list(rv);
        for (c = fl->rest; c != NIL; c = c->rest)
        {
            deallocate_rhs_value(thisAgent, static_cast<char*>(c->first));
        }
        free_list(thisAgent, fl);
    }
    else
    {
        rhs_symbol r = rhs_value_to_rhs_symbol(rv);
        if (r->referent) thisAgent->symbolManager->symbol_remove_ref(&r->referent);
        thisAgent->memoryManager->free_with_pool(MP_rhs_symbol, r);
    }
}
예제 #4
0
void Explanation_Based_Chunker::sti_variablize_rhs_symbol(rhs_value &pRhs_val, bool generate_identity)
{
    char prefix[2];
    Symbol* var;
    bool has_variablization = false, was_unbound = false;
    uint64_t lMatchedIdentity = LITERAL_VALUE, lMatchedCIdentity = LITERAL_VALUE;

    if (rhs_value_is_funcall(pRhs_val))
    {
        cons* fl = rhs_value_to_funcall_list(pRhs_val);
        cons* c;
        rhs_value lRhsValue, *lc;

        for (c = fl->rest; c != NIL; c = c->rest)
        {
            lRhsValue = static_cast<rhs_value>(c->first);
            sti_variablize_rhs_symbol(lRhsValue, false);
        }
        return;
    }

    rhs_symbol rs = rhs_value_to_rhs_symbol(pRhs_val);

    auto iter_sym = m_sym_to_var_map->find(rs->referent);
    has_variablization = (iter_sym != m_sym_to_var_map->end());

    if (!has_variablization && rs->referent->is_sti())
    {
        /* -- First time we've encountered an unbound rhs var. -- */
        prefix[0] = static_cast<char>(tolower(rs->referent->id->name_letter));
        prefix[1] = 0;
        var = thisAgent->symbolManager->generate_new_variable(prefix);
        if (generate_identity) lMatchedIdentity = thisAgent->explanationBasedChunker->get_or_create_inst_identity_for_sym(var);
        add_sti_variablization(rs->referent, var, lMatchedIdentity, lMatchedCIdentity);
        has_variablization = true;
        was_unbound = true;
    } else if (rs->referent->is_sti()) {
        var = iter_sym->second->variable_sym;
        if (generate_identity)
        {
        	lMatchedIdentity = iter_sym->second->inst_identity;
            lMatchedCIdentity = iter_sym->second->cv_id;
        }
        has_variablization = true;
    }
    if (has_variablization)
    {
        thisAgent->symbolManager->symbol_remove_ref(&rs->referent);
        thisAgent->symbolManager->symbol_add_ref(var);
        rs->referent = var;
        rs->inst_identity = lMatchedIdentity;
        rs->cv_id = lMatchedCIdentity;
        rs->identity = NULL;
        rs->was_unbound_var = was_unbound;
    }
    else
    {
        rs->inst_identity = LITERAL_VALUE;
        rs->identity = NULL;
    }
}
예제 #5
0
파일: rhs.cpp 프로젝트: emamanto/Soar
rhs_value create_RHS_value(agent* thisAgent,
                           rhs_value rv,
                           condition* cond,
                           char first_letter,
                           ExplainTraceType ebcTraceType)
{
    cons* c, *new_c, *prev_new_c;
    cons* fl, *new_fl;
    Symbol* sym;
    int64_t index;
    char prefix[2];
	test t;//, original_t;
    uint64_t lO_id = 0;


    /* (1) Reteloc identifiers or constants originally bound to variables
     * (2) unbound_vars for unbound vars of course
     * (3) rhs_symbols for literal constants, including those in RHS functions */

    if (rhs_value_is_reteloc(rv))
    {
        /* Symbol pointed to by a rete location
         * This case seems to only be for identifiers or constants originally bound to variables */

        t = var_test_bound_in_reconstructed_conds(thisAgent, cond,
                rhs_value_to_reteloc_field_num(rv),
                rhs_value_to_reteloc_levels_up(rv));
        return allocate_rhs_value_for_symbol(thisAgent, t->data.referent, t->inst_identity, 0, t->identity);
    }

    if (rhs_value_is_unboundvar(rv))
    {
        /* Unbound variable */
        index = static_cast<int64_t>(rhs_value_to_unboundvar(rv));
        if (! *(thisAgent->rhs_variable_bindings + index))
        {
            prefix[0] = first_letter;
            prefix[1] = 0;

            sym = thisAgent->symbolManager->generate_new_variable(prefix);
            *(thisAgent->rhs_variable_bindings + index) = sym;

            if (thisAgent->highest_rhs_unboundvar_index < index)
            {
                thisAgent->highest_rhs_unboundvar_index = index;
            }
            if (ebcTraceType == Explanation_Trace)
            {
                lO_id = thisAgent->explanationBasedChunker->get_or_create_inst_identity_for_sym(sym);
            }
            /* generate will increment the refcount on the new variable, so don't need to do it here. */
            return allocate_rhs_value_for_symbol_no_refcount(thisAgent, sym, lO_id, 0, NULL, true);
        }
        else
        {
            /* unbound variable was already created in previous rhs action */
            sym = *(thisAgent->rhs_variable_bindings + index);
        }
        if (ebcTraceType == Explanation_Trace)
        {
            lO_id = thisAgent->explanationBasedChunker->get_or_create_inst_identity_for_sym(sym);
        }

        return allocate_rhs_value_for_symbol(thisAgent, sym, lO_id, 0, NULL, true);
    }

    if (rhs_value_is_funcall(rv))
    {
        fl = rhs_value_to_funcall_list(rv);
        allocate_cons(thisAgent, &new_fl);
        new_fl->first = fl->first;
        prev_new_c = new_fl;
        for (c = fl->rest; c != NIL; c = c->rest)
        {
            allocate_cons(thisAgent, &new_c);
            new_c->first = create_RHS_value(thisAgent,
                                            static_cast<char*>(c->first),
                                            cond,
                                            first_letter,
                                            ebcTraceType);
            prev_new_c->rest = new_c;
            prev_new_c = new_c;
        }
        prev_new_c->rest = NIL;
        return funcall_list_to_rhs_value(new_fl);
    }
    else
    {
        /* Literal values including those in function calls. */
        rhs_symbol rs = rhs_value_to_rhs_symbol(rv);
        if (ebcTraceType == Explanation_Trace)
            return allocate_rhs_value_for_symbol(thisAgent, rs->referent, rs->inst_identity, rs->cv_id, rs->identity, rs->was_unbound_var);
        else
            return allocate_rhs_value_for_symbol(thisAgent, rs->referent, LITERAL_VALUE, 0, NULL, rs->was_unbound_var);
    }
}