Class: LibRebl
- Inherits:
-
Object
- Object
- LibRebl
- Defined in:
- lib/bud/rebl.rb
Overview
Library of functions used by rebl. More generally, this can be viewed as a way to have a bud class that you can add and remove rules from, and that you can step through the execution of.
Constant Summary
- @@builtin_tables =
[:stdio, :periodics_tbl, :halt, :localtick, :t_depends, :t_cycle, :t_provides, :t_rule_stratum, :t_rules, :t_stratum, :t_underspecified, :t_table_info, :t_table_schema, :rebl_breakpoint]
- @@classid =
0
Instance Attribute Summary collapse
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#rebl_class_inst ⇒ Object
readonly
Returns the value of attribute rebl_class_inst.
-
#rules ⇒ Object
Returns the value of attribute rules.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
-
#add_collection(c) ⇒ Object
Declares a new collection.
-
#add_rule(r) ⇒ Object
Adds a new rule at the current time; only derives tuples based on data that exists at the current or a future time.
-
#del_rule(rid) ⇒ Object
Deactivates a rule at the current time; any tuples derived by the rule at a previous time are still available.
-
#dump(c) ⇒ Object
Dumps the contents of a table at the current time.
-
#initialize(ip, port) ⇒ LibRebl
constructor
A new instance of LibRebl.
- #mk_rebl_class ⇒ Object
-
#run ⇒ Object
Runs the bud instance (until a breakpoint, or stop() is called).
-
#stop ⇒ Object
Stops the bud instance (and then performs another tick).
-
#tick(x = 1) ⇒ Object
Ticks the bud instance a specified integer number of times.
Constructor Details
#initialize(ip, port) ⇒ LibRebl
Returns a new instance of LibRebl
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/bud/rebl.rb', line 215 def initialize(ip, port) @ip = ip @port = port @rules = {} @ruleid = 0 @state = {} @stateid = 0 @rebl_class = nil @rebl_class_inst = nil @old_inst = nil reinstantiate end |
Instance Attribute Details
#ip ⇒ Object (readonly)
Returns the value of attribute ip
208 209 210 |
# File 'lib/bud/rebl.rb', line 208 def ip @ip end |
#port ⇒ Object (readonly)
Returns the value of attribute port
208 209 210 |
# File 'lib/bud/rebl.rb', line 208 def port @port end |
#rebl_class_inst ⇒ Object (readonly)
Returns the value of attribute rebl_class_inst
208 209 210 |
# File 'lib/bud/rebl.rb', line 208 def rebl_class_inst @rebl_class_inst end |
#rules ⇒ Object
Returns the value of attribute rules
207 208 209 |
# File 'lib/bud/rebl.rb', line 207 def rules @rules end |
#state ⇒ Object
Returns the value of attribute state
207 208 209 |
# File 'lib/bud/rebl.rb', line 207 def state @state end |
Instance Method Details
#add_collection(c) ⇒ Object
Declares a new collection.
259 260 261 262 263 264 265 266 267 |
# File 'lib/bud/rebl.rb', line 259 def add_collection(c) @state[@stateid += 1] = c begin reinstantiate rescue Exception @state.delete(@stateid) raise end end |
#add_rule(r) ⇒ Object
Adds a new rule at the current time; only derives tuples based on data that exists at the current or a future time.
282 283 284 285 286 287 288 289 290 |
# File 'lib/bud/rebl.rb', line 282 def add_rule(r) @rules[@ruleid += 1] = r begin reinstantiate rescue Exception @rules.delete(@ruleid) raise end end |
#del_rule(rid) ⇒ Object
Deactivates a rule at the current time; any tuples derived by the rule at a previous time are still available.
271 272 273 274 275 276 277 278 |
# File 'lib/bud/rebl.rb', line 271 def del_rule(rid) unless @rules.has_key? rid puts "No rule with ID #{rid}" return end @rules.delete(rid) reinstantiate end |
#dump(c) ⇒ Object
Dumps the contents of a table at the current time.
244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/bud/rebl.rb', line 244 def dump(c) if c.nil? puts "Error: dump must be passed a collection name" elsif @rebl_class_inst.tables.has_key? c.to_sym tups = @rebl_class_inst.tables[c.to_sym].to_a.sort puts(tups.empty? ? "(empty)" : tups.sort.map{|t| "#{t}"}.join("\n")) elsif @rebl_class_inst.lattices.has_key? c.to_sym val = @rebl_class_inst.lattices[c.to_sym].current_value puts val.inspect else puts "Error: non-existent collection \"#{c}\"" end end |
#mk_rebl_class ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/bud/rebl.rb', line 292 def mk_rebl_class @@classid += 1 cls_name = "ReblClass#{@@classid}" str = "" str =<<-EOS $BUD_SAFE=1 class #{cls_name} < ReblBase include Bud EOS unless @state.empty? str += "state do\n" + @state.values.join("\n") + "\nend\n" end unless @rules.empty? str += "bloom :rebl_rules do\n" + @rules.sort.map {|_,r| r}.join("\n") + "\nend\n" end str += "\nend\n" f = Tempfile.new("rebl") f.write(str) f.close begin load f.path return eval cls_name # return the class object rescue $stderr.puts "Unable to eval the following code:\n" + str raise ensure f.unlink end end |
#run ⇒ Object
Runs the bud instance (until a breakpoint, or stop() is called)
229 230 231 |
# File 'lib/bud/rebl.rb', line 229 def run @rebl_class_inst.run_bg end |
#stop ⇒ Object
Stops the bud instance (and then performs another tick)
234 235 236 |
# File 'lib/bud/rebl.rb', line 234 def stop @rebl_class_inst.pause end |
#tick(x = 1) ⇒ Object
Ticks the bud instance a specified integer number of times.
239 240 241 |
# File 'lib/bud/rebl.rb', line 239 def tick(x=1) x.times {@rebl_class_inst.sync_do} end |