예제 #1
0
def _structure_to_swipy_ref(item: Structure, swipy_ref, lit_var_store: Dict[Variable, int]):
    func = _functor_to_swipy(item.get_functor())
    compound_arg = swipy.swipy_new_term_refs(item.get_functor().get_arity())
    struct_args = item.get_arguments()
    _to_swipy_ref(struct_args[0], compound_arg, lit_var_store)
    for i in range(1, item.get_functor().get_arity()):
        _to_swipy_ref(struct_args[i], compound_arg + i, lit_var_store)

    swipy.swipy_cons_functor(swipy_ref, func, compound_arg)
예제 #2
0
def _pyxsb_string_to_structure(term: str):
    first_bracket = term.find('(')
    functor = term[:first_bracket]
    args = [
        _pyxsb_string_to_pylo(x)
        for x in _extract_arguments_from_compound(term)
    ]
    functor = c_symbol(functor, arity=len(args))

    return Structure(functor, args)
예제 #3
0
def _pygp_to_structure(term):
    v1 = pygprolog.pygp_Mk_Variable()
    v2 = pygprolog.pygp_Mk_Variable()

    pygprolog.pygp_Builtin_Functor(term, v1, v2)

    functor = pygprolog.pygp_Rd_String(v1)
    arity = pygprolog.pygp_Rd_Integer(v2)
    args = []
    for i in range(1, arity+1):
        v = pygprolog.pygp_Mk_Variable()
        pygprolog.pygp_Builtin_Arg(pygprolog.pygp_Mk_Integer(i), term, v)
        args.append(_read_pygp(v))

    # global global_context

    return Structure(c_functor(functor, arity), args)
예제 #4
0
def _structure_to_pygp(struct: Structure, lit_var_store: Dict[Variable, int]):
    func = _functor_to_pygp(struct.get_functor())
    args = [_to_pygp(x, lit_var_store) for x in struct.get_arguments()]

    return pygprolog.pygp_Mk_Compound(func, struct.get_functor().get_arity(), args)