rpl.rb/lib/language/program.rb

20 lines
599 B
Ruby
Raw Normal View History

module Rpl
2021-11-18 12:00:02 +01:00
module Core
module_function
2021-11-18 12:00:02 +01:00
# evaluate (run) a program, or recall a variable. ex: 'my_prog' eval
def eval( stack, dictionary )
stack, args = Rpl::Core.stack_extract( stack, [%i[program word name]] )
2021-11-18 12:00:02 +01:00
# we trim enclosing «»
preparsed_input = args[0][:type] == :word ? args[0][:value] : args[0][:value][1..-2]
parsed_input = Rpl::Parser.new.parse_input( preparsed_input )
2021-11-18 12:00:02 +01:00
stack, _dictionary = Rpl::Runner.new.run_input( stack, dictionary, parsed_input )
# TODO: check that STO actually updates dictionary
2021-11-18 12:11:19 +01:00
stack
2021-11-18 12:00:02 +01:00
end
end
end