Class: BlockContainer

Inherits:
Array show all
Defined in:
lib/core/syntax/BlockContainer.rb

Instance Method Summary collapse

Methods inherited from Array

#cauldron_method_calls, #contains?, #select_all, #to_declaration, #to_intrinsic, #to_literal, #to_var

Constructor Details

#initialize(*parameters) ⇒ BlockContainer

Returns a new instance of BlockContainer.



3
4
5
6
7
# File 'lib/core/syntax/BlockContainer.rb', line 3

def initialize(*parameters)
  super()
  
  parameters.each { |x| self.push(x) }
end

Instance Method Details

#copyObject

TODO Write tests for this



53
54
55
# File 'lib/core/syntax/BlockContainer.rb', line 53

def copy
  return BlockContainer.new(*self.collect {|x| x.copy})
end

#describeObject



19
20
21
22
23
24
25
26
27
# File 'lib/core/syntax/BlockContainer.rb', line 19

def describe
  l = '|'
  self.each do |x|
    l += x.describe
    l += ', ' unless x.object_id == self.last.object_id
  end
  l += '|'
  return l    
end

#each_variableObject

Returns each variable used within the block in turn.



124
125
126
127
128
# File 'lib/core/syntax/BlockContainer.rb', line 124

def each_variable
  variables.each do |x|        
    yield x
  end
end

#realise(statement, containing_method) ⇒ Object

Returns a block container where all the block variables have been realised.

I had previously intended to just work out the values for the block but this would create problems when I have blocks within blocks.

NOTE I have copied code here from the history call in RuntimeMethod

Raises:

  • (StandardError)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/core/syntax/BlockContainer.rb', line 74

def realise(statement,containing_method)
  
  # Create the method to track the change in values of the block variable
  # TODO  I shouldn't need to redeclare this runtime method each time
  #tracking_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new)) 
  # Create the method that block values are logged to
  instance_tracking_variable = ArrayVariable.new
  instance_tracking_variable.instance_variable = true
  tracking_method = RuntimeTrackingMethod.new(instance_tracking_variable)
  
  raise StandardError.new('This should not be used')
  # Create a method to call the method and return the results
  #process_method = RuntimeMethod.new(MethodUsage.new)
  #process_method << Statement.new( DefCall.new(NilVariable.new) )
  #process_method << Statement.new( Return.new,instance_tracking_variable )    
  
  # CONTINUE Look up the tracking method
  #exit
end

#realise2(method_map) ⇒ Object

Returns an updated block container where all the values for the block have been realised through the method map.

Parameters:

  • method_map

    The history of the method that the block container is used in.



100
101
102
103
104
105
106
107
# File 'lib/core/syntax/BlockContainer.rb', line 100

def realise2(method_map)
  return self.copy if realised?
  result = BlockContainer.new
  self.each do |x|
    result.push(x.realise(method_map))
  end
  return result
end

#realised?Boolean

Returns true if all the block variables returned true.

Returns:



58
59
60
61
62
63
64
# File 'lib/core/syntax/BlockContainer.rb', line 58

def realised?
  
  # Go through each of the block variables and determine if they're realised
  return false if self.any? {|x| x.realised? == false }      
  return true
    
end

#unrealised_variablesObject

Returns an array of all the unrealised variables within the block container.



112
113
114
# File 'lib/core/syntax/BlockContainer.rb', line 112

def unrealised_variables
  return variables.find_all {|x| x.realised? == false}
end

#variablesObject

Returns an array of all the variables within this block container.



118
119
120
# File 'lib/core/syntax/BlockContainer.rb', line 118

def variables
  return self.collect {|x| x.copy}      
end

#writeObject



9
10
11
12
13
14
15
16
17
# File 'lib/core/syntax/BlockContainer.rb', line 9

def write
  l = '|'
  self.each do |x|
    l += x.write
    l += ', ' unless x.object_id == self.last.object_id
  end
  l += '|'
  return l
end

#write_with_uniq_idObject



29
30
31
32
33
34
35
36
37
# File 'lib/core/syntax/BlockContainer.rb', line 29

def write_with_uniq_id
  l = '|'
  self.each do |x|
    (x.respond_to?('write_with_uniq_id')) ? l += x.write_with_uniq_id : l += x.write
    l += ', ' unless x.object_id == self.last.object_id
  end
  l += '|'
  return l
end

#write_with_valueObject

Returns the block variables but with their values next to them. This presumes that the block container has been realised.



42
43
44
45
46
47
48
49
50
# File 'lib/core/syntax/BlockContainer.rb', line 42

def write_with_value
  l = '|'
  self.each do |x|
    l += x.write_with_value
    l += ', ' unless x.object_id == self.last.object_id
  end
  l += '|'
  return l     
end