Class: NaturalDSL::CommandRunner

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

Defined Under Namespace

Classes: StackNotEmpty

Instance Method Summary collapse

Constructor Details

#initialize(command, vm) ⇒ CommandRunner

Returns a new instance of CommandRunner.



9
10
11
12
# File 'lib/natural_dsl/command_runner.rb', line 9

def initialize(command, vm)
  @command = command
  @vm = vm
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
# File 'lib/natural_dsl/command_runner.rb', line 14

def run
  args = @command.expectations.flat_map do |expectation|
    expectation.read_arguments(@vm.stack)
  end

  raise_stack_not_empty_error if @vm.stack.any?

  @command.execution_block.call(@vm, *args)
end