cauldron 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. data/Gemfile +6 -0
  2. data/Gemfile.lock +63 -0
  3. data/History.md +5 -0
  4. data/Rakefile +62 -16
  5. data/VERSION +1 -1
  6. data/cauldron.gemspec +463 -0
  7. data/cauldron/lib/cauldron.rb +1 -1
  8. data/features/cauldron_generates_runtime_method.feature +7 -4
  9. data/features/cauldron_generates_single_paramter_methods.feature +25 -0
  10. data/features/cauldron_interactive_start_terminal.feature +17 -0
  11. data/features/cauldron_quit_terminal.feature +9 -0
  12. data/features/cauldron_start_terminal.feature +0 -1
  13. data/features/step_definitions/cauldron_steps.rb +10 -5
  14. data/features/step_definitions/terminal_steps.rb +27 -0
  15. data/features/support/env.rb +2 -0
  16. data/features/support/hooks.rb +15 -0
  17. data/lib/Chain.rb +3 -3
  18. data/lib/Mapping.rb +1 -0
  19. data/lib/PartialChain.rb +253 -0
  20. data/lib/Theory.rb +28 -4
  21. data/lib/UnifiedChain.rb +94 -125
  22. data/lib/cauldron.rb +3 -0
  23. data/lib/cauldron/demos.rb +4 -4
  24. data/lib/cauldron/env.rb +1 -0
  25. data/lib/cauldron/pot.rb +42 -38
  26. data/lib/cauldron/terminal.rb +19 -3
  27. data/lib/cauldron/util/home.rb +21 -0
  28. data/lib/cauldron/util/saver.rb +45 -0
  29. data/lib/core/Container.rb +1 -1
  30. data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +28 -28
  31. data/lib/core/runtime_method/RuntimeMethod.rb +6 -23
  32. data/lib/core/statement/ActsAsStatement.rb +0 -96
  33. data/lib/core/statement/BlockStatement.rb +1 -1
  34. data/lib/core/statement/OpenStatement.rb +1 -1
  35. data/lib/core/statement/Statement.rb +39 -94
  36. data/lib/core/statement/TheoryStatement.rb +1 -1
  37. data/lib/core/syntax/BlockContainer.rb +0 -28
  38. data/lib/core/variable/MethodParameter.rb +1 -1
  39. data/lib/required.rb +2 -14
  40. data/lib/theories.rb +0 -1
  41. data/lib/theory/ActionImplementation.rb +1 -1
  42. data/lib/theory/TheoryAction.rb +2 -2
  43. data/lib/theory/TheoryConnector.rb +11 -14
  44. data/lib/theory/TheoryImplementation.rb +10 -9
  45. data/lib/util/MethodWriter.rb +10 -10
  46. data/sandbox.rb +23 -0
  47. data/spec/cauldron/pot_spec.rb +62 -10
  48. data/spec/cauldron/runtime_method_spec.rb +31 -17
  49. data/spec/cauldron/saver_spec.rb +45 -0
  50. data/spec/cauldron/terminal_spec.rb +10 -1
  51. data/spec/cauldron/theory_spec.rb +4 -4
  52. data/spec/cauldron/unified_chain_spec.rb +38 -0
  53. data/spec/spec_helper.rb +3 -1
  54. data/tasks/development_tasks.rake +4 -0
  55. data/tasks/theory_tasks.rake +16 -20
  56. data/test/fixtures/theories/0/desc +6 -6
  57. data/test/fixtures/theories/0/dump +0 -0
  58. data/test/fixtures/theories/1/desc +7 -7
  59. data/test/fixtures/theories/1/dump +0 -0
  60. data/test/fixtures/theories/10/desc +13 -13
  61. data/test/fixtures/theories/10/dump +0 -0
  62. data/test/fixtures/theories/11/desc +10 -10
  63. data/test/fixtures/theories/11/dump +0 -0
  64. data/test/fixtures/theories/12/desc +9 -9
  65. data/test/fixtures/theories/12/dump +0 -0
  66. data/test/fixtures/theories/13/desc +16 -16
  67. data/test/fixtures/theories/13/dump +0 -0
  68. data/test/fixtures/theories/14/desc +16 -16
  69. data/test/fixtures/theories/14/dump +0 -0
  70. data/test/fixtures/theories/15/desc +10 -10
  71. data/test/fixtures/theories/15/dump +0 -0
  72. data/test/fixtures/theories/16/desc +10 -10
  73. data/test/fixtures/theories/16/dump +0 -0
  74. data/test/fixtures/theories/17/desc +7 -7
  75. data/test/fixtures/theories/17/dump +0 -0
  76. data/test/fixtures/theories/18/desc +7 -7
  77. data/test/fixtures/theories/18/dump +0 -0
  78. data/test/fixtures/theories/19/desc +7 -7
  79. data/test/fixtures/theories/19/dump +0 -0
  80. data/test/fixtures/theories/2/desc +6 -6
  81. data/test/fixtures/theories/2/dump +0 -0
  82. data/test/fixtures/theories/20/desc +13 -13
  83. data/test/fixtures/theories/20/dump +0 -0
  84. data/test/fixtures/theories/3/desc +7 -7
  85. data/test/fixtures/theories/3/dump +0 -0
  86. data/test/fixtures/theories/4/desc +7 -7
  87. data/test/fixtures/theories/4/dump +0 -0
  88. data/test/fixtures/theories/5/desc +6 -6
  89. data/test/fixtures/theories/5/dump +0 -0
  90. data/test/fixtures/theories/6/desc +7 -7
  91. data/test/fixtures/theories/6/dump +0 -0
  92. data/test/fixtures/theories/7/desc +7 -7
  93. data/test/fixtures/theories/7/dump +0 -0
  94. data/test/fixtures/theories/8/desc +7 -7
  95. data/test/fixtures/theories/8/dump +0 -0
  96. data/test/fixtures/theories/9/desc +16 -16
  97. data/test/fixtures/theories/9/dump +0 -0
  98. data/test/fixtures/theory_implementations/0/dump +0 -0
  99. data/test/fixtures/theory_implementations/2/dump +0 -0
  100. data/test/ts_complete.rb +1 -10
  101. data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +1 -0
  102. data/test/unit/core/runtime_method/tc_runtime_method.rb +16 -39
  103. data/test/unit/core/statement/tc_block_statement.rb +3 -3
  104. data/test/unit/core/statement/tc_open_statement.rb +4 -4
  105. data/test/unit/core/statement/tc_statement.rb +2 -147
  106. data/test/unit/core/statement/tc_theory_statement.rb +1 -1
  107. data/test/unit/theory/tc_theory_dependent.rb +3 -3
  108. data/test/unit/theory/tc_theory_result.rb +5 -5
  109. data/test/unit/util/tc_method_validation.rb +45 -45
  110. data/test/unit/util/tc_parser.rb +1 -1
  111. data/test/unit/util/tc_string_to_theory.rb +2 -2
  112. metadata +74 -48
  113. data/lib/ScopeDependencies.rb +0 -8
  114. data/lib/core/statement/StatementDependencies.rb +0 -271
  115. data/lib/core/structure/DeclareNewInstanceStructure.rb +0 -49
  116. data/lib/core/structure/DeclareRuntimeMethodStructure.rb +0 -34
  117. data/lib/core/structure/DeclareVariableAsLiteralStructure.rb +0 -31
  118. data/lib/core/structure/DeclareVariableAsVariableStructure.rb +0 -52
  119. data/lib/core/structure/FixnumAdditionStructure.rb +0 -56
  120. data/lib/core/structure/InstanceCallContainerStructure.rb +0 -50
  121. data/lib/core/structure/InstanceCallStructure.rb +0 -53
  122. data/lib/core/structure/InstanceMethodCallStructure.rb +0 -21
  123. data/lib/core/structure/ReturnStructure.rb +0 -20
  124. data/lib/core/structure/StatementStructure.rb +0 -11
  125. data/test/unit/core/statement/tc_statement_dependencies.rb +0 -147
  126. data/test/unit/core/structure/tc_declare_new_instance_structure.rb +0 -41
  127. data/test/unit/core/structure/tc_declare_variable_as_literal_structure.rb +0 -41
  128. data/test/unit/core/structure/tc_declare_variable_as_variable_structure.rb +0 -66
  129. data/test/unit/core/structure/tc_instance_call_container_structure.rb +0 -41
  130. data/test/unit/core/structure/tc_return_structure.rb +0 -32
  131. data/test/unit/tc_instance_call_structure.rb +0 -35
  132. data/test/unit/tc_statement_structure_2.rb +0 -43
@@ -1,8 +0,0 @@
1
- class ScopeDependencies < Array
2
-
3
- def initialize
4
- raise StandardError.new('Will anyone miss me')
5
- super()
6
- end
7
-
8
- end
@@ -1,271 +0,0 @@
1
- #
2
- # TODO I might just make this part of StatementGroup
3
- #
4
- # TODO TSort examples show a single use. So you basically add all your variables
5
- # and then sort them once. Rather than what I'm doing which is to attempt
6
- # to find the dependencies for particular statements. It might be better
7
- # to rebuild the dependies each time and then do a single sort.
8
-
9
- # Include a scope dependencies as well - if a statement resides within a nested statement
10
- # the nested statement must come first.
11
- #
12
- # New statement: - statement level: 183
13
- # var_5918 = var_652 + var_658
14
- #
15
- # Pre-requiste statements:
16
- # var_34 = method_13
17
- # var_34.times do |var_658|
18
- # end
19
- # var_652 = var_34 + var_34
20
-
21
- # In this case the scope means that the nested "var_34.times do |var_658|" is dependent
22
- # on var_652 = var_34 + var_34.
23
- #
24
- # # Find the statement that contains this statement - if it exists
25
- # self.each do |x|
26
- # if x.kind_of?(BlockStatement)
27
- # if x.scope_id == statement.statement_level
28
- #
29
- # # Apply the dependencies for the statement to the containing statement
30
- # # unless it's the containing statement itself.
31
- #
32
- # end
33
- # end
34
- # end
35
- #
36
- class StatementDependencies < Array
37
- #include TSort # See p750
38
-
39
- alias :array_push :push
40
-
41
- def initialize(*params)
42
- super()
43
- #@dependencies = {}
44
-
45
- # Add the statements
46
- params.each {|x| self.push(x)}
47
- end
48
-
49
- # TODO Write about this in more detail
50
- #
51
- def tsort_for_statement(statement)
52
-
53
- @statement_sort = TopologicalStatements.new
54
- add_dependent_statements(@statement_sort,statement)
55
-
56
- # TODO Should probably copy the @statement_sort before itterating through it
57
- #
58
- each_used_nest_statement(@statement_sort,statement) do |x|
59
- # CONTINUE - Why are these nested statements populated
60
-
61
- # Find statements that have the same scope as this
62
- each_nested_statement(@statement_sort,statement,x.scope_id) do |y|
63
-
64
- # Add the inner statement dependencies onto the nested statement
65
- @statement_sort[x.statement_id] += @statement_sort[y.statement_id]
66
- end
67
-
68
- end
69
-
70
- return @statement_sort.tsort
71
-
72
- end
73
-
74
- def dependencies_for(statement_id)
75
-
76
- # Check that the statement exists
77
- unknown_statement_id = lambda {raise StandardError.new('Could\'nt find statement_id '+statement_id.to_s)}
78
- self.detect(unknown_statement_id) {|x| x.statement_id == statement_id}
79
-
80
- #
81
- @statement_sort = TopologicalStatements.new
82
-
83
- # First find the initial statement
84
- initial_statement = find_statement(statement_id)
85
- add_dependent_statements(@statement_sort,initial_statement)
86
-
87
-
88
- return @statement_sort.tsort
89
- end
90
-
91
- def add_dependent_statements(tsort,statement)
92
- dependencies = find_dependencies_for(statement)
93
- tsort[statement.statement_id] = dependencies
94
-
95
- # Find the dependiencies for the
96
- dependencies.each do |x|
97
- add_dependent_statements(tsort,find_statement(x))
98
- end
99
- end
100
-
101
- def find_statement(id)
102
- self.each do |x|
103
- if x.statement_id == id
104
- return x
105
- end
106
- end
107
- # TODO Should raise error here
108
- end
109
-
110
- # Returns an array of statement ids of all the statements that the supplied
111
- # statement is dependent on.
112
- #
113
- # @param statement A statement instance thats dependencies are returned
114
- #
115
- def find_dependencies_for(statement)
116
- results = []
117
- statement.not_declared_variables.each do |x|
118
-
119
- # Find the original declaration statement
120
- # TODO Doesn't catch no results
121
- statement_ids = self.inject([]) do |ids,y|
122
- #ids.push(y.statement_id) if x.uniq_id == y.created_variable.uniq_id
123
- if x.uniq_id == y.created_variable.uniq_id
124
- # TODO Quick hack to prevent bug
125
- ids.push(y.statement_id) unless statement.statement_id == y.statement_id
126
- end
127
- ids
128
- end
129
-
130
- # Find any further required uniq ids
131
- x.uniq_id_history.each do |y|
132
- # TODO Change to detect since this presumes a result is found
133
- statement_ids.push(self.select {|z| z.created_variable.uniq_id == y}.first.statement_id)
134
- end
135
- raise StandardError.new('Can\'t find the declaration of '+x.write+' or '+x.write_with_uniq_id) if statement_ids.empty?
136
- results += statement_ids
137
- results.each do |y|
138
- raise StandardError.new('dksafkjdashfkahsdf '+statement.statement_id.to_s) if(y==statement.statement_id)
139
- end
140
- # # TODO Change to catch :found
141
- # found = false
142
- # self.each do |y|
143
- # #if x.variable_id == y.declared_variable_id
144
- # if x.uniq_id == y.created_variable.uniq_id
145
- # found = true
146
- # results.push(y.statement_id)
147
- # break
148
- # end
149
- # end
150
- # raise StandardError.new('Can\'t find the declaration of '+x.write+' or '+x.write_with_uniq_id) unless found
151
- end
152
- return results
153
- end
154
-
155
- # Saves any of the statements thats dependencies are being
156
- # saved.
157
- #
158
- # @param statement
159
- #
160
- def push(statement)
161
-
162
- # Check that any statements this statement is dependent on is included
163
- find_dependencies_for(statement)
164
-
165
- # Add the new piece of code to the statement
166
- array_push(statement)
167
-
168
- end
169
-
170
- # Returns the saved statement based on the statement id provided
171
- #
172
- # @param statement_id The statement id of the stored statement.
173
- #
174
- def find_statement(statement_id,new_statement=nil)
175
- unless new_statement.nil?
176
- return new_statement if new_statement.statement_id == statement_id
177
- end
178
- return self.detect {|x| x.statement_id == statement_id}
179
- end
180
-
181
- # Returns a string to be printed out for the general use of
182
- # debugging.
183
- #
184
- # @param topsort Topological sort containing the dependencies
185
- # for each statement.
186
- # @param statements An array of statements that have already been
187
- # saved.
188
- # @param new_statement The new statement that has yet to be included
189
- # in a large method and hasn't been realised yet.
190
- #
191
- def display_statement_dependencies(topsort,statements,new_statement)
192
- msg = ''
193
- msg += topsort.inspect+"\n"
194
- topsort.each_key do |x|
195
- msg += x.to_s+"\n"
196
- msg += find_statement(x,new_statement).write+"\n"
197
- end
198
- return msg
199
- end
200
-
201
- # Modifies the supplied topological sort to include scope dependency. This
202
- # basically involves applying the dependencies of nested statements to
203
- # the containing statement. e.g.
204
- #
205
- # var_a = 6
206
- # 5.times do |var_b|
207
- # var_c = var_b+var_a
208
- # end
209
- #
210
- # So "var_c = var_b+var_a" is dependent on the two proceeding statements but
211
- # sequentially they could be written as
212
- #
213
- # 5.times do |var_b|
214
- # var_a = 6
215
- # var_c = var_b+var_a
216
- #
217
- # But when put it into its particular nest we end up with
218
- #
219
- # 5.times do |var_b|
220
- # var_c = var_b+var_a
221
- # end
222
- # var_a = 6
223
- #
224
- # @param topsort Topoligical sort indicating an ordering dependencey
225
- # @param new_statement The new statement that is yet to saved internally
226
- # (because it hasn't been realised)
227
- #
228
- def apply_scope_dependencies(topsort,new_statement)
229
-
230
- # Find each nest statement and then any statements contained within
231
- each_used_nested_statement(topsort,new_statement) do |x|
232
- # CONTIUE
233
- end
234
-
235
- end
236
-
237
- # Yeilds each nested statement. Despite the naming convention a nested
238
- # statement is really a nest statement. NOTE This is not every contained
239
- # NestStatement but rather those used.
240
- #
241
- # TODO NestStatement would be a more reflective name - after all the statements
242
- # within the statement are nested.
243
- #
244
- def each_used_nest_statement(topsort,new_statement)
245
- topsort.each_key do |x|
246
- found_statement = find_statement(x,new_statement)
247
- yield found_statement if found_statement.kind_of?(BlockStatement)
248
- end
249
- end
250
-
251
- # Yeilds each statement that is nested within the scope specified
252
- #
253
- # @param topsort The has containing each relevent statement id as well
254
- # as there dependencies.
255
- # @param statement The statement in the process of being added. It needs
256
- # passed since is not yet saved within this class.
257
- # @param scope_id The scope id of the nest statement that contains the
258
- # nested statements.
259
- #
260
- def each_nested_statement(topsort,new_statement,scope_id)
261
- topsort.each_key do |x|
262
- found_statement = find_statement(x,new_statement)
263
- # TODO I need to clarify the terms ,scope,scope_id and statement_level
264
- # - I think one can at least go or at least have less confusing names.
265
- if found_statement.statement_level == scope_id
266
- yield found_statement
267
- end
268
- end
269
- end
270
-
271
- end
@@ -1,49 +0,0 @@
1
- # Returns statements that declare new instances of the available classes
2
- #
3
- # Example:
4
- # var_a = MethodUsage.new
5
- # var_b = RuntimeMethod.new(var_a)
6
- #
7
- class DeclareNewInstanceStructure < StatementStructure
8
-
9
- #
10
- # @param available_classes Any number of class instances that can be used
11
- # when generating statements, e.g. MethodUsageClass.new
12
- #
13
- def initialize(*available_classes)
14
- super()
15
- available_classes.each {|x| self.push(x)}
16
- end
17
-
18
- # Returns an array of instance declaration statements using
19
- # the available variables.
20
- #
21
- # @param available An array of variables that are made available
22
- # when declaring new statements.
23
- #
24
- def statements(available=[])
25
-
26
- # Get all the various arrangements of parameters at all the lengths (capped at 5)
27
- arrangements = [[]]
28
-
29
- # Add one of each available variable
30
- available.each do |x|
31
- arrangements.push([x])
32
- end
33
-
34
- # For each arrangement create a new statement declaration
35
- results = []
36
-
37
- # Create a number of declaration statements using the method classes
38
- # e.g. Unknown.new,Equal.new,ClassMethodCallContainer.new(MethodUsageClass.new,New.new)
39
- self.each do |x|
40
- x.class_method_calls(available).each do |y|
41
- new_statement = Statement.new(Unknown.new,Equal.new,y)
42
- results.push(new_statement)
43
- end
44
- end
45
-
46
- return results
47
- end
48
-
49
- end
@@ -1,34 +0,0 @@
1
- # TODO I think this structure has been super seeded by DeclareVariableAsVariableStructure
2
- # Example - where the method_a returns a RuntimeMethod instance
3
- #
4
- # var_a = method_a()
5
- #
6
- class DeclareRuntimeMethodStructure < StatementStructure
7
-
8
- def initialize()
9
- super([Unknown,Equal,RuntimeMethodParameter])
10
- end
11
-
12
- # Returns an array of possible statements that can be created
13
- # using the available variables. Currently the only way to
14
- # create runtime method instances is via a separate runtime
15
- # method call.
16
- #
17
- # @param available An array of variables that can be used to
18
- # to create the statements that declared new
19
- # runtime variables.
20
- #
21
- def statements(available=[])
22
- return [] if available.empty?
23
- def_calls = available.find_all {|x| x.kind_of?(DefCall)}
24
- results = []
25
- def_calls.each do |x|
26
- if x.response.class == RuntimeMethodParameter
27
- new_statement = Statement.new(Unknown.new,Equal.new,x.copy)
28
- results.push(new_statement)
29
- end
30
- end
31
- return results
32
- end
33
-
34
- end
@@ -1,31 +0,0 @@
1
- #
2
- # Example
3
- #
4
- # var = 6
5
- # var = 'Shepard'
6
- # var = []
7
- #
8
- class DeclareVariableAsLiteralStructure < StatementStructure
9
-
10
- def initialize(*available_literals)
11
- super([Unknown,Equal,Literal])
12
- @available_literals = available_literals
13
- end
14
-
15
- # TODO Write tests for this
16
- # Returns an array of possible statements that can be created
17
- # given the variables supplied.
18
- #
19
- # @param available An array of possible variables that can be used to generate
20
- # new statements. Although for this structure it is only
21
- # interested in the literals.
22
- #
23
- def statements(available=[])
24
- combined_available = @available_literals + available
25
- return [] if combined_available.empty?
26
- literals = combined_available.find_all {|x| x.kind_of?(Literal)}
27
- results = literals.collect {|x| Statement.new(Unknown.new,Equal.new,x) }
28
- return results
29
- end
30
-
31
- end
@@ -1,52 +0,0 @@
1
- # NOTE: I'm not certain whether these types of strucutres are actually necessary
2
- # but they did exist when I was using StatementStrucuture2.rb
3
- #
4
- # Example
5
- #
6
- # var_b = var_a
7
- # var_c = var_b
8
- # var_e = var_b.chop
9
-
10
- class DeclareVariableAsVariableStructure < StatementStructure
11
-
12
- def initialize()
13
- super([Unknown,Equal,TypeVariable])
14
- end
15
-
16
- # Returns an array of statements constructed using the supplied
17
- # variables.
18
- #
19
- def statements(available=[])
20
- return [] if available.empty?
21
- variables = available.select {|x| x.kind_of?(TypeVariable)}
22
-
23
- # Generate all the possible direct variable declarations e.g. var_a = var_b
24
- direct_declarations = variables.collect {|x| Statement.new(Unknown.new,Equal.new,x.copy)}
25
-
26
- # Generate all the possible instance call declarations - I'm not sure if this will be used in this way
27
- results = variables.collect do |x|
28
- result = x.returning_instance_calls(available).collect do |y|
29
- Statement.new(Unknown.new,Equal.new,y)
30
- end
31
- end
32
-
33
- # TODO This seems a bit sloppy - I should do it in a nicer way
34
- instance_call_declarations = []
35
- results.each do |x|
36
- x.each {|y| instance_call_declarations.push(y)}
37
- end
38
-
39
- # Find all the possible method calss
40
- # TODO Write tests for this method call bit
41
- # TODO This doesn't allow for parameters
42
- available.each do |x|
43
- if x.kind_of?(DefCall)
44
- instance_call_declarations.push(Statement.new(Unknown.new,Equal.new,x.copy))
45
- end
46
- end
47
-
48
- return direct_declarations.concat(instance_call_declarations)
49
-
50
- end
51
-
52
- end