class BefungeInterpreter
This is the top-level class containing everything needed to interpret befunge code. Intialize with a string location of a filename and an array of flags and then call BefungeInterpreter#interpret
. This will run the befunge code. TODO: Implement flags - debugging mode, animation mode.
Public Class Methods
new(file, flags)
click to toggle source
# File lib/befunge_interpreter.rb, line 9 def initialize(file, flags) @code_map = CodeMap.new(file) @flags = flags @stack = Stack.new @string_mode = false @computing = true @return_string = '' end
Public Instance Methods
interpret()
click to toggle source
# File lib/befunge_interpreter.rb, line 18 def interpret operate_and_step while @computing end
Private Instance Methods
operate_and_step()
click to toggle source
# File lib/befunge_interpreter.rb, line 24 def operate_and_step operate!(@code_map.get_operation) @code_map.pointer.step end
print_return_string()
click to toggle source
# File lib/befunge_interpreter.rb, line 51 def print_return_string p @return_string end
print_stack()
click to toggle source
# File lib/befunge_interpreter.rb, line 36 def print_stack print_whole_stack if @stack.length <= 10 print_top_ten_stack if @stack.length > 10 end
print_status()
click to toggle source
# File lib/befunge_interpreter.rb, line 29 def print_status system 'clear' @code_map.print_map print_stack print_return_string end
print_top_ten_stack()
click to toggle source
# File lib/befunge_interpreter.rb, line 45 def print_top_ten_stack puts "Showing top ten items on stack..." @stack[-11..-1].each { |stack_item| print ", #{stack_item}" } print "]\n" end
print_whole_stack()
click to toggle source
# File lib/befunge_interpreter.rb, line 41 def print_whole_stack p @stack end