Class: Flux::Runtime::Agent
- Inherits:
-
Object
- Object
- Flux::Runtime::Agent
- Defined in:
- lib/superinstance/flux-runtime/runtime/agent.rb
Overview
Agent shell that wraps a FluxVM and provides method_missing for PLATO-based capability lookup
Instance Attribute Summary collapse
-
#vessel_id ⇒ Object
readonly
Returns the value of attribute vessel_id.
-
#vm ⇒ Object
readonly
Returns the value of attribute vm.
Instance Method Summary collapse
-
#initialize(plato_client: nil, vessel_id: nil) ⇒ Agent
constructor
A new instance of Agent.
-
#load(bytecode) ⇒ Object
Load bytecode into the VM.
-
#method_missing(method_name, *args, &block) ⇒ Object
Delegate unknown methods to VM if they exist there Otherwise, look up in PLATO.
-
#regs ⇒ Object
Get register values.
-
#reset ⇒ Object
Reset the VM.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Proper introspection support.
-
#run(max_cycles: nil) ⇒ Object
Run the VM.
-
#state ⇒ Object
Get current state.
-
#stats ⇒ Object
Get execution stats.
-
#step ⇒ Object
Step one instruction.
Constructor Details
#initialize(plato_client: nil, vessel_id: nil) ⇒ Agent
Returns a new instance of Agent.
25 26 27 28 29 30 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 25 def initialize(plato_client: nil, vessel_id: nil) @vm = FluxVM.new @plato = plato_client @vessel_id = vessel_id @capabilities = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Delegate unknown methods to VM if they exist there Otherwise, look up in PLATO
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 73 def method_missing(method_name, *args, &block) # Check if it's a VM method if @vm.respond_to?(method_name) @vm.send(method_name, *args, &block) else # Look up capability in PLATO capability = lookup_capability(method_name) if capability execute_capability(capability, *args, &block) else super end end end |
Instance Attribute Details
#vessel_id ⇒ Object (readonly)
Returns the value of attribute vessel_id.
23 24 25 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 23 def vessel_id @vessel_id end |
#vm ⇒ Object (readonly)
Returns the value of attribute vm.
23 24 25 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 23 def vm @vm end |
Instance Method Details
#load(bytecode) ⇒ Object
Load bytecode into the VM
33 34 35 36 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 33 def load(bytecode) @vm.load(bytecode) self end |
#regs ⇒ Object
Get register values
62 63 64 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 62 def regs @vm.regs end |
#reset ⇒ Object
Reset the VM
51 52 53 54 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 51 def reset @vm.reset self end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Proper introspection support
90 91 92 93 94 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 90 def respond_to_missing?(method_name, include_private = false) @vm.respond_to?(method_name, include_private) || lookup_capability(method_name) || super end |
#run(max_cycles: nil) ⇒ Object
Run the VM
39 40 41 42 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 39 def run(max_cycles: nil) @vm.run(max_cycles: max_cycles) self end |
#state ⇒ Object
Get current state
57 58 59 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 57 def state @vm.state end |
#stats ⇒ Object
Get execution stats
67 68 69 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 67 def stats @vm.stats end |
#step ⇒ Object
Step one instruction
45 46 47 48 |
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 45 def step @vm.step self end |