Sha256: 3b6839a91c6f16151ecc9bf4584f32ced2173c4b2d93e8314db025636c6d6d71

Contents?: true

Size: 1.51 KB

Versions: 11

Compression:

Stored size: 1.51 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 Gloo
  module Exec
    class Stack

      attr_accessor :stack

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

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

      #
      # Pop an item from the stack.
      #
      def pop
        o = @stack.pop
        $log.debug "#{@name}:pop #{o.display_value}"
        self.update_out_file if $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( $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

11 entries across 11 versions & 1 rubygems

Version Path
gloo-0.8.0 lib/gloo/exec/stack.rb
gloo-0.7.7 lib/gloo/exec/stack.rb
gloo-0.7.6 lib/gloo/exec/stack.rb
gloo-0.7.5 lib/gloo/exec/stack.rb
gloo-0.7.4 lib/gloo/exec/stack.rb
gloo-0.7.3 lib/gloo/exec/stack.rb
gloo-0.7.2 lib/gloo/exec/stack.rb
gloo-0.7.1 lib/gloo/exec/stack.rb
gloo-0.7.0 lib/gloo/exec/stack.rb
gloo-0.6.1 lib/gloo/exec/stack.rb
gloo-0.6.0 lib/gloo/exec/stack.rb