Class: Flux::Runtime::Opcode

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Class Attribute Details

.execute_blockObject

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

.formatObject

Returns the value of attribute format.



11
12
13
# File 'lib/superinstance/flux-runtime/runtime/opcode.rb', line 11

def format
  @format
end

.opcode_idObject

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

Examples:

Flux::Runtime::Opcode.define(0xF0, format: :C) do |vm, rd, ra, rb|
  vm.gp[rd] = vm.gp[ra] + vm.gp[rb] * 2
end

Parameters:

  • opcode_id (Integer)

    0-255 opcode number

  • format (Symbol) (defaults to: :C)

    :A, :B, :C, :D, :E, or :G

  • block (Proc)

    execution block receiving vm and operands



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