Class: Flux::Runtime::Opcode
- Inherits:
-
Object
- Object
- Flux::Runtime::Opcode
- Defined in:
- lib/superinstance/flux-runtime/runtime/opcode.rb
Overview
Runtime opcode registration module Allows Ruby code to add custom FLUX opcodes dynamically
Class Attribute Summary collapse
-
.execute_block ⇒ Object
Returns the value of attribute execute_block.
-
.format ⇒ Object
Returns the value of attribute format.
-
.opcode_id ⇒ Object
Returns the value of attribute opcode_id.
Class Method Summary collapse
-
.create(opcode_id, format: :C, &block) ⇒ Object
Create and register in one call.
-
.define(opcode_id, format: :C, &block) ⇒ Object
Define a new opcode at runtime.
-
.execute(vm, *operands) ⇒ Object
Execute this opcode on a VM.
Class Attribute Details
.execute_block ⇒ Object
Returns the value of attribute execute_block.
11 12 13 |
# File 'lib/superinstance/flux-runtime/runtime/opcode.rb', line 11 def execute_block @execute_block end |
.format ⇒ Object
Returns the value of attribute format.
11 12 13 |
# File 'lib/superinstance/flux-runtime/runtime/opcode.rb', line 11 def format @format end |
.opcode_id ⇒ Object
Returns the value of attribute opcode_id.
11 12 13 |
# File 'lib/superinstance/flux-runtime/runtime/opcode.rb', line 11 def opcode_id @opcode_id end |
Class Method Details
.create(opcode_id, format: :C, &block) ⇒ Object
Create and register in one call
37 38 39 40 41 |
# File 'lib/superinstance/flux-runtime/runtime/opcode.rb', line 37 def create(opcode_id, format: :C, &block) Class.new(self) do define(opcode_id, format: format, &block) end end |
.define(opcode_id, format: :C, &block) ⇒ Object
Define a new opcode at runtime
22 23 24 25 26 27 28 29 |
# File 'lib/superinstance/flux-runtime/runtime/opcode.rb', line 22 def define(opcode_id, format: :C, &block) @opcode_id = opcode_id @format = format @execute_block = block # Register with VM FluxVM.register_opcode(self) end |
.execute(vm, *operands) ⇒ Object
Execute this opcode on a VM
32 33 34 |
# File 'lib/superinstance/flux-runtime/runtime/opcode.rb', line 32 def execute(vm, *operands) @execute_block.call(vm, *operands) end |