Sha256: ae0f3f29bd6a2803a236c5e4f25408d1e086033b0b755679cd09876d47dc3840
Contents?: true
Size: 821 Bytes
Versions: 3
Compression:
Stored size: 821 Bytes
Contents
module Basic101 class ProgramCounter def initialize(program) @program = program @index = 0 @stack = [] end def goto_next_statement @index += 1 end def end? @index >= @program.statement_count end def goto_index(index) @index = index end def goto_index_after(index) goto_index(index + 1) end def goto_line(line_number) goto_index @program.index_of_line(line_number) end def gosub_line(line_number) @stack.push @index goto_line line_number end def goto_end @index = @program.statement_count + 1 end def return index = @stack.pop raise ReturnWithoutGosub unless index @index = index end def current_statement @program[@index] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
basic101-0.4.0 | lib/basic101/program_counter.rb |
basic101-0.2.0 | lib/basic101/program_counter.rb |
basic101-0.1.0 | lib/basic101/program_counter.rb |