class Bud::Lattice

Public Class Methods

global_mfuncs() click to toggle source
# File lib/bud/lattice-core.rb, line 61
def self.global_mfuncs
  @@global_mfuncs
end
global_morphs() click to toggle source
# File lib/bud/lattice-core.rb, line 43
def self.global_morphs
  @@global_morphs
end
lattice_kinds() click to toggle source
# File lib/bud/lattice-core.rb, line 21
def self.lattice_kinds
  @@lattice_kinds
end
mfuncs() click to toggle source
# File lib/bud/lattice-core.rb, line 57
def self.mfuncs
  @mfuncs || Set.new
end
monotone(name, &block) click to toggle source
# File lib/bud/lattice-core.rb, line 47
def self.monotone(name, &block)
  if morphs.include?(name) || @@global_morphs.include?(name)
    raise Bud::CompileError, "#{name} declared as both monotone and morph"
  end
  @mfuncs ||= Set.new
  @mfuncs << name
  @@global_mfuncs << name
  define_method(name, &block)
end
morph(name, &block) click to toggle source
# File lib/bud/lattice-core.rb, line 29
def self.morph(name, &block)
  if mfuncs.include?(name) || @@global_mfuncs.include?(name)
    raise Bud::CompileError, "#{name} declared as both monotone and morph"
  end
  @morphs ||= Set.new
  @morphs << name
  @@global_morphs << name
  define_method(name, &block)
end
morphs() click to toggle source
# File lib/bud/lattice-core.rb, line 39
def self.morphs
  @morphs || Set.new
end
wrapper() click to toggle source
# File lib/bud/lattice-core.rb, line 25
def self.wrapper
  @wrapper_name
end
wrapper_name(name) click to toggle source
# File lib/bud/lattice-core.rb, line 10
def self.wrapper_name(name)
  if @wrapper_name
    raise Bud::CompileError, "lattice #{self.name} has multiple wrapper names"
  end
  if @@lattice_kinds.has_key? name
    raise Bud::CompileError, "duplicate lattice definition: #{name}"
  end
  @@lattice_kinds[name] = self
  @wrapper_name = name
end

Public Instance Methods

<=>(o) click to toggle source

Similarly, use reveal'ed value to implement Comparable.

# File lib/bud/lattice-core.rb, line 90
def <=>(o)
  reveal <=> o.reveal
end
==(o) click to toggle source

The default equality semantics for lattice objects is based on reveal. Note that this isn't always appropriate: if the intended equality semantics for the lattice type differ from the equality semantics of the object returned by reveal (e.g., a set lattice might return an array with an unpredictable order), the lattice type should override this behavior.

# File lib/bud/lattice-core.rb, line 75
def ==(o)
  return false unless o.kind_of? Bud::Lattice
  return reveal == o.reveal
end
eql?(o) click to toggle source
# File lib/bud/lattice-core.rb, line 80
def eql?(o)
  self == o
end
hash() click to toggle source

Ensure hashing and equality semantics are consistent.

# File lib/bud/lattice-core.rb, line 85
def hash
  reveal.hash
end
inspect() click to toggle source
# File lib/bud/lattice-core.rb, line 101
def inspect
  "<#{self.class.wrapper}: #{reveal.inspect}>"
end
reject_input(i, meth="initialize") click to toggle source
# File lib/bud/lattice-core.rb, line 65
def reject_input(i, meth="initialize")
  site = "#{self.class.wrapper}\##{meth}"
  raise Bud::TypeError, "illegal input to #{site}: #{i.inspect}"
end
reveal() click to toggle source

Return the state valued associated with a lattice instance. Note that this is non-monotonic when invoked from user code; it should be used with care by framework code.

# File lib/bud/lattice-core.rb, line 97
def reveal
  @v
end
wrap_unsafe(new_v) click to toggle source

Construct a new instance of the current class that wraps “new_v”. We assume that new_v is already a legal input value for the class, so we can bypass the class's normal initializer – this avoids redundant error checks.

# File lib/bud/lattice-core.rb, line 108
def wrap_unsafe(new_v)
  rv = self.class.new
  rv.instance_variable_set('@v', new_v)
  rv
end