module Upl::Inter

Inter operation

Public Class Methods

each_of_list(lst_term) { |head_t| ... } click to toggle source

lst_term is a Term, or a Fiddle::Pointer to term_t yield term_t items of the lst_term

# File lib/upl/inter.rb, line 32
def self.each_of_list lst_term, &blk
  return enum_for __method__, lst_term unless block_given?
  lst_term = Inter.term_t_of lst_term

  while Extern::PL_get_nil(lst_term) != 1 # not end of list
    res = Extern::PL_get_list \
      lst_term,
      (head_t = Extern.PL_new_term_ref),
      (rst_t = Extern.PL_new_term_ref)

    break unless res == 1

    yield head_t
    lst_term = rst_t
  end
end
register_mcall_predicate() click to toggle source

call any method on any object, from prolog

# File lib/upl/inter.rb, line 21
def self.register_mcall_predicate
  Upl::Foreign.register_semidet :mcall do |obj,meth,val|
    val === obj.send(meth)
  end
end
term_t_of(term_or_ptr) click to toggle source

Try Term, then Fiddle::Pointer, then to_term_t. Return a term_t pointer

# File lib/upl/inter.rb, line 9
def self.term_t_of term_or_ptr
  case term_or_ptr
  when Term
    term_or_ptr.term_t
  when Fiddle::Pointer
    term_or_ptr
  else
    term_or_ptr.to_term_t
  end
end

Public Instance Methods

attach_atom_hook() click to toggle source
# File lib/upl/inter.rb, line 69
                def attach_atom_hook
  @atom_hook = atom_hook = Fiddle::Closure::BlockCaller.new Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP] do |atom_t|
    atom = Upl::Atom.new atom_t
    p atom_t: atom_t.to_i, atom: atom
    if atom.to_obj_id
      obj = atom.to_ruby
      p obj: obj, dereg: (Agc.instance.deregister obj)
    end

    #  FALSE here will prevent garbage collection
    Upl::Extern::TRUE
  end

  # NOTENOTE this must NOT be garbage-collected, otherwise the callback to it will fail.
  @atom_hook_fn = Fiddle::Function.new atom_hook, atom_hook.args, atom_hook.ctype

  # returns old fn ptr
  Upl::Extern.PL_agc_hook @atom_hook_fn
end