Sha256: 38592db3d6031d1d22a393d9b3f4e61fc5a3df02154f592ce3592ef397d9dbda

Contents?: true

Size: 592 Bytes

Versions: 1

Compression:

Stored size: 592 Bytes

Contents

# # frozen_string_literal: true

require_relative 'word'
require_relative '../token'

module Forthic
  class EndArrayWord < Word
    def initialize
      super("]")
    end

    # @param [Interpreter] interp
    def execute(interp)
      items = []
      item = interp.stack_pop

      # NOTE: This won't infinite loop because interp.stack_pop() will eventually fail
      loop do
        break if item.is_a?(Token) && item.type == TokenType::START_ARRAY
        items.push(item)
        item = interp.stack_pop
      end

      items.reverse!
      interp.stack_push(items)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forthic-0.1.0 lib/forthic/words/end_array_word.rb