Sha256: 923eef0c667778e7798ee9b3de5e358947b274aa90c9a9cb7a69b680da0ed343

Contents?: true

Size: 1.58 KB

Versions: 23

Compression:

Stored size: 1.58 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2020 Eric Crane.  All rights reserved.
#
# A stack of items, a call stack.
#

module GlooLang
  module Exec
    class Stack

      attr_accessor :stack

      #
      # Set up the stack.
      #
      def initialize( engine, name )
        @engine = engine
        @name = name
        clear_stack
        @engine.log.debug "#{name} stack intialized..."
      end

      #
      # Push an item onto the stack.
      #
      def push( obj )
        @engine.log.debug "#{@name}:push #{obj.display_value}"
        @stack.push obj
        self.update_out_file if @engine.settings.debug
      end

      #
      # Pop an item from the stack.
      #
      def pop
        o = @stack.pop
        @engine.log.debug "#{@name}:pop #{o.display_value}"
        self.update_out_file if @engine.settings.debug
      end

      #
      # Get the current size of the call stack.
      #
      def size
        return @stack.size
      end

      #
      # Get stack data for output.
      #
      def out_data
        return @stack.map( &:display_value ).join( "\n" )
      end

      #
      # Get the file we'll write debug information for the stack.
      #
      def out_file
        return File.join( @engine.settings.debug_path, @name )
      end

      #
      # Update the stack trace file.
      #
      def update_out_file
        File.write( self.out_file, self.out_data )
      end

      #
      # Clear the stack and the output file.
      #
      def clear_stack
        @stack = []
        self.update_out_file
      end

    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
gloo-lang-1.4.3 lib/gloo_lang/exec/stack.rb
gloo-lang-1.4.2 lib/gloo_lang/exec/stack.rb
gloo-lang-1.4.1 lib/gloo_lang/exec/stack.rb
gloo-lang-1.4.0 lib/gloo_lang/exec/stack.rb
gloo-lang-1.3.2 lib/gloo_lang/exec/stack.rb
gloo-lang-1.3.1 lib/gloo_lang/exec/stack.rb
gloo-lang-1.3.0 lib/gloo_lang/exec/stack.rb
gloo-lang-1.2.8 lib/gloo_lang/exec/stack.rb
gloo-lang-1.2.7 lib/gloo_lang/exec/stack.rb
gloo-lang-1.2.6 lib/gloo_lang/exec/stack.rb
gloo-lang-1.2.5 lib/gloo_lang/exec/stack.rb
gloo-lang-1.2.4 lib/gloo_lang/exec/stack.rb
gloo-lang-1.2.3 lib/gloo_lang/exec/stack.rb
gloo-lang-1.2.2 lib/gloo_lang/exec/stack.rb
gloo-lang-1.2.1 lib/gloo_lang/exec/stack.rb
gloo-lang-1.2.0 lib/gloo_lang/exec/stack.rb
gloo-lang-1.1.0 lib/gloo_lang/exec/stack.rb
gloo-lang-1.0.2 lib/gloo_lang/exec/stack.rb
gloo-lang-1.0.1 lib/gloo_lang/exec/stack.rb
gloo-lang-1.0.0 lib/gloo_lang/exec/stack.rb