Class: DTRToRust::InstructionHandler

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

Overview

This class is responsible for generating Rust code for a single instruction.

Instance Method Summary collapse

Constructor Details

#initialize(instruction) ⇒ InstructionHandler

Returns a new instance of InstructionHandler.



6
7
8
# File 'lib/instruction_handler.rb', line 6

def initialize(instruction)
  @instruction = instruction
end

Instance Method Details

#generate_rustObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/instruction_handler.rb', line 10

def generate_rust
  case @instruction[:instruction]
  when 'Return'
    Instruction::Return.handle(@instruction)
  when 'log_string'
    Instruction::LogString.handle(@instruction)
  when 'add_and_assign'
    Instruction::AddAndAssign.handle(@instruction)
  when 'evaluate'
    Instruction::Evaluate.handle(@instruction)
  when 'create_list'
    Instruction::CreateList.handle(@instruction)
  else
    raise "Unknown instruction type: #{@instruction[:instruction]}"
  end
end