Class: Gloo::Exec::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/exec/stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, name) ⇒ Stack

Set up the stack.



16
17
18
19
20
21
# File 'lib/gloo/exec/stack.rb', line 16

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

Instance Attribute Details

#stackObject

Returns the value of attribute stack.



11
12
13
# File 'lib/gloo/exec/stack.rb', line 11

def stack
  @stack
end

Instance Method Details

#clear_stackObject

Clear the stack and the output file.



72
73
74
75
# File 'lib/gloo/exec/stack.rb', line 72

def clear_stack
  @stack = []
  self.update_out_file
end

#out_dataObject

Get stack data for output.



51
52
53
# File 'lib/gloo/exec/stack.rb', line 51

def out_data
  return @stack.map( &:display_value ).join( "\n" )
end

#out_fileObject

Get the file we’ll write debug information for the stack.



58
59
60
# File 'lib/gloo/exec/stack.rb', line 58

def out_file
  return File.join( @engine.settings.debug_path, @name )
end

#popObject

Pop an item from the stack.



35
36
37
38
39
# File 'lib/gloo/exec/stack.rb', line 35

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

#push(obj) ⇒ Object

Push an item onto the stack.



26
27
28
29
30
# File 'lib/gloo/exec/stack.rb', line 26

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

#sizeObject

Get the current size of the call stack.



44
45
46
# File 'lib/gloo/exec/stack.rb', line 44

def size
  return @stack.size
end

#update_out_fileObject

Update the stack trace file.



65
66
67
# File 'lib/gloo/exec/stack.rb', line 65

def update_out_file
  File.write( self.out_file, self.out_data )
end