Class: Rjq::CompiledProgram

Inherits:
Object
  • Object
show all
Defined in:
lib/rjq/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast, program:) ⇒ CompiledProgram

Returns a new instance of CompiledProgram.



7
8
9
10
11
# File 'lib/rjq/compiler.rb', line 7

def initialize(ast, program:)
  @ast = ast
  @program = program
  freeze
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



5
6
7
# File 'lib/rjq/compiler.rb', line 5

def ast
  @ast
end

#programObject (readonly)

Returns the value of attribute program.



5
6
7
# File 'lib/rjq/compiler.rb', line 5

def program
  @program
end

Instance Method Details

#disasmObject



30
31
32
# File 'lib/rjq/compiler.rb', line 30

def disasm
  program.disasm
end

#instructionsObject



13
14
15
# File 'lib/rjq/compiler.rb', line 13

def instructions
  program.instructions
end

#run(input_value, opts = {}) ⇒ Object



17
18
19
# File 'lib/rjq/compiler.rb', line 17

def run(input_value, opts = {})
  VM.new(self, Runtime.normalize_options(opts)).run(input_value)
end

#run_with_instruction_budget(input_value, opts, budget) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/rjq/compiler.rb', line 21

def run_with_instruction_budget(input_value, opts, budget)
  normalized = Runtime.normalize_options(opts)
  unless budget.is_a?(VM::InstructionBudget) && budget.maximum == normalized[:max_instructions]
    raise ArgumentError, 'instruction budget must match max_instructions'
  end

  VM.new(self, normalized, instruction_budget: budget).run(input_value)
end