Class: Bud::Lattice
- Inherits:
-
Object
show all
- Includes:
- Comparable
- Defined in:
- lib/bud/lattice-core.rb
Constant Summary
- @@lattice_kinds =
{}
- @@global_morphs =
Set.new
- @@global_mfuncs =
Set.new
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Class Method Details
+ (Object) global_mfuncs
61
62
63
|
# File 'lib/bud/lattice-core.rb', line 61
def self.global_mfuncs
@@global_mfuncs
end
|
+ (Object) global_morphs
43
44
45
|
# File 'lib/bud/lattice-core.rb', line 43
def self.global_morphs
@@global_morphs
end
|
+ (Object) lattice_kinds
21
22
23
|
# File 'lib/bud/lattice-core.rb', line 21
def self.lattice_kinds
@@lattice_kinds
end
|
+ (Object) mfuncs
57
58
59
|
# File 'lib/bud/lattice-core.rb', line 57
def self.mfuncs
@mfuncs || Set.new
end
|
+ (Object) monotone(name, &block)
47
48
49
50
51
52
53
54
55
|
# 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
|
+ (Object) morph(name, &block)
29
30
31
32
33
34
35
36
37
|
# 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
|
+ (Object) morphs
39
40
41
|
# File 'lib/bud/lattice-core.rb', line 39
def self.morphs
@morphs || Set.new
end
|
+ (Object) wrapper
25
26
27
|
# File 'lib/bud/lattice-core.rb', line 25
def self.wrapper
@wrapper_name
end
|
+ (Object) wrapper_name(name)
10
11
12
13
14
15
16
17
18
19
|
# 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
|
Instance Method Details
- (Object) <=>(o)
Similarly, use reveal'ed value to implement Comparable.
90
91
92
|
# File 'lib/bud/lattice-core.rb', line 90
def <=>(o)
reveal <=> o.reveal
end
|
- (Object) ==(o)
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.
75
76
77
78
|
# File 'lib/bud/lattice-core.rb', line 75
def ==(o)
return false unless o.kind_of? Bud::Lattice
return reveal == o.reveal
end
|
- (Boolean) eql?(o)
80
81
82
|
# File 'lib/bud/lattice-core.rb', line 80
def eql?(o)
self == o
end
|
- (Object) hash
Ensure hashing and equality semantics are consistent.
85
86
87
|
# File 'lib/bud/lattice-core.rb', line 85
def hash
reveal.hash
end
|
- (Object) inspect
101
102
103
|
# File 'lib/bud/lattice-core.rb', line 101
def inspect
"<#{self.class.wrapper}: #{reveal.inspect}>"
end
|
65
66
67
68
|
# 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
|
- (Object) reveal
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.
97
98
99
|
# File 'lib/bud/lattice-core.rb', line 97
def reveal
@v
end
|
- (Object) wrap_unsafe(new_v)
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.
108
109
110
111
112
|
# 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
|