class Upl::Atom

Attributes

atom_t[R]

Public Class Methods

new( atom_t ) click to toggle source

NOTE these are atom_t, NOT term_t and NOT Fiddle::Pointer to atom_t

# File lib/upl/atom.rb, line 4
def initialize( atom_t )
  @atom_t = atom_t

  # pretty much all other methods need chars, so just do it now.
  @chars = (::Upl::Extern::PL_atom_chars @atom_t).to_s.freeze
end
of_term( term_t ) click to toggle source

drop the term immediately, and just keep the atom value

# File lib/upl/atom.rb, line 12
def self.of_term( term_t )
  rv = Extern::PL_get_atom term_t, (atom_t = Fiddle::Pointer[0].ref)
  rv == 1 or raise "can't get atom from term"
  new atom_t.ptr
end
t_of_ruby(obj) click to toggle source

NOTE this returns an atom_t for obj.object_id embedded in an atom

# File lib/upl/atom.rb, line 21
def self.t_of_ruby obj
  Upl::Extern.PL_new_atom "ruby-#{obj.object_id.to_s}"
end

Public Instance Methods

==(rhs) click to toggle source
# File lib/upl/atom.rb, line 55
def == rhs
  atom_t == rhs.atom_t
end
inspect() click to toggle source
# File lib/upl/atom.rb, line 67
def inspect; to_sym end
pretty_print(pp) click to toggle source
# File lib/upl/atom.rb, line 69
def pretty_print pp
  pp.text atom_t
  pp.text '-'
  pp.text to_s
end
to_obj_id() click to toggle source

return the object_id embedded in the atom, or nil if it's not an embedded object_id

# File lib/upl/atom.rb, line 27
def to_obj_id
  if instance_variable_defined? :@to_obj_id
    @to_obj_id
  else
    @to_obj_id =
    if @chars =~ /^ruby-(\d+)/
      $1.to_i
    end
  end
end
to_ruby() click to toggle source

return the ruby object associated with the object_id embedded in the atom

# File lib/upl/atom.rb, line 39
def to_ruby
  if to_obj_id
    ObjectSpace._id2ref to_obj_id
  else
    case _sym = to_sym
    when :false; false
    when :true; true
    else _sym
    end
  end
rescue RangeError
  # object with the given obj_id no longer exists in ruby, so just return
  # the symbol with the embedded object_id.
  to_sym
end
to_s() click to toggle source
# File lib/upl/atom.rb, line 63
def to_s
  @chars
end
to_sym() click to toggle source
# File lib/upl/atom.rb, line 59
def to_sym
  @chars.to_sym
end