rpl.rb/lib/runner.rb

34 lines
671 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2021-11-10 11:01:26 +01:00
module Rpl
2021-12-07 15:50:58 +01:00
module Lang
2022-02-08 15:45:36 +01:00
module_function
2021-11-10 11:01:26 +01:00
2022-02-08 15:45:36 +01:00
def run_input( input, stack, dictionary )
dictionary.add_local_vars_layer
2022-02-02 15:20:24 +01:00
2022-02-08 15:45:36 +01:00
input.each do |elt|
case elt[:type]
when :word
command = dictionary.lookup( elt[:value] )
2021-11-10 11:01:26 +01:00
2022-02-08 15:45:36 +01:00
if command.nil?
# if there's command by that name then it's a name
elt[:type] = :name
2021-12-07 15:50:58 +01:00
stack << elt
2022-02-08 15:45:36 +01:00
else
stack, dictionary = command.call( stack, dictionary )
2021-11-10 11:01:26 +01:00
end
2022-02-08 15:45:36 +01:00
else
stack << elt
2021-11-10 11:01:26 +01:00
end
2022-02-08 15:45:36 +01:00
end
2021-11-10 11:01:26 +01:00
2022-02-08 15:45:36 +01:00
dictionary.remove_local_vars_layer
2022-02-02 15:20:24 +01:00
2022-02-08 15:45:36 +01:00
[stack, dictionary]
2021-11-10 11:01:26 +01:00
end
end
end