def impl(_vars, dnf=None): st = new(ConditionsType) st.vars = List.empty_list(GenericVarType) st.vars.append(_struct_from_pointer(GenericVarType, _vars.base_ptr)) st.var_map = build_var_map(st.vars) # print("A",st.var_map) st.dnf = dnf if (dnf) else new_dnf(1) st.is_initialized = False return st
def all_facts_of_type(kb, typ): t_id = resolve_t_id(kb, typ) out = List.empty_list(typ) facts = facts_for_t_id(kb.kb_data, t_id) for i in range(facts.head): fact_ptr = facts.data[i] if (fact_ptr != 0): #u8(-1)): # out.append(cast_fact(typ,b_fact)) out.append(_struct_from_pointer(typ, fact_ptr)) return out
def kb_data_dtor(kb_data): '''Decref out data structures in kb_data that we explicitly incref'ed ''' #Decref all declared facts and their container vectors for i in range(kb_data.facts.head): facts_ptr = kb_data.facts.data[i] facts = _struct_from_pointer(VectorType, facts_ptr) for j in range(facts.head): fact_ptr = facts.data[j] _decref_pointer(fact_ptr) _decref_pointer(facts_ptr) #Decref the inner vectors of retracted_f_ids for i in range(kb_data.retracted_f_ids.head): ptr = kb_data.retracted_f_ids.data[i] _decref_pointer(ptr)
def restore_struct_from_pointer(p): return _struct_from_pointer(BOOPType,p)
def build_var_list(var_map): '''Makes a Var list from a var_map''' var_list = List.empty_list(GenericVarType) for ptr in var_map: var_list.append(_struct_from_pointer(GenericVarType, ptr)) return var_list
def retracted_f_ids_for_t_id(kb_data, t_id): return _struct_from_pointer(VectorType, kb_data.retracted_f_ids[t_id])
def fact_at_f_id(typ, t_id_facts, f_id): ptr = t_id_facts.data[f_id] if (ptr != 0): return _struct_from_pointer(typ, ptr) else: return None
def facts_for_t_id(kb_data, t_id): L = len(kb_data.facts) if (t_id >= L): expand_kb_data_types(kb_data, 1 + L - t_id) return _struct_from_pointer(VectorType, kb_data.facts[t_id])