cauldron 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (409) hide show
  1. data/.gitignore +51 -0
  2. data/Gemfile +6 -3
  3. data/Gemfile.lock +16 -3
  4. data/Rakefile +94 -92
  5. data/VERSION +1 -1
  6. data/bin/cauldron +2 -2
  7. data/cauldron.gemspec +15 -451
  8. data/features/cauldron_new_approach.feature +46 -0
  9. data/features/step_definitions/cauldron_steps.rb +11 -0
  10. data/features/step_definitions/terminal_steps.rb +0 -2
  11. data/features/support/env.rb +11 -1
  12. data/features/support/hooks.rb +5 -0
  13. data/lib/cauldron.rb +13 -7
  14. data/lib/cauldron/array_reverse_operator.rb +39 -0
  15. data/lib/cauldron/concat_operator.rb +34 -0
  16. data/lib/cauldron/if_relationship.rb +37 -0
  17. data/lib/cauldron/numeric_operator.rb +45 -0
  18. data/lib/cauldron/pot.rb +54 -162
  19. data/lib/cauldron/relationship.rb +5 -0
  20. data/lib/cauldron/terminal.rb +4 -60
  21. data/lib/cauldron/version.rb +3 -0
  22. data/lib/core/string.rb +21 -0
  23. data/sandbox.rb +27 -6
  24. data/spec/cauldron/array_reverse_operator_spec.rb +59 -0
  25. data/spec/cauldron/concat_operator_spec.rb +89 -0
  26. data/spec/cauldron/if_relationship_spec.rb +25 -0
  27. data/spec/cauldron/numeric_operator_spec.rb +70 -0
  28. data/spec/cauldron/pot_spec.rb +81 -151
  29. data/spec/cauldron/terminal_spec.rb +1 -39
  30. data/spec/examples/adding_if_statement.yml +13 -0
  31. data/spec/examples/simple_head_theory.txt +13 -0
  32. data/spec/spec_helper.rb +1 -14
  33. data/tasks/theory_tasks.rake +207 -207
  34. metadata +92 -532
  35. data/cauldron/.autotest +0 -23
  36. data/cauldron/History.txt +0 -6
  37. data/cauldron/Manifest.txt +0 -8
  38. data/cauldron/README.txt +0 -57
  39. data/cauldron/Rakefile +0 -27
  40. data/cauldron/bin/cauldron +0 -3
  41. data/cauldron/lib/cauldron.rb +0 -3
  42. data/cauldron/test/test_cauldron.rb +0 -8
  43. data/features/cauldron_example_cases.feature +0 -13
  44. data/features/cauldron_generates_runtime_method.feature +0 -16
  45. data/features/cauldron_generates_single_paramter_methods.feature +0 -25
  46. data/features/cauldron_interactive_start_terminal.feature +0 -17
  47. data/features/cauldron_quit_terminal.feature +0 -9
  48. data/features/cauldron_start_terminal.feature +0 -12
  49. data/features/support/method_1.example +0 -3
  50. data/features/support/method_2.example +0 -6
  51. data/lib/Chain.rb +0 -771
  52. data/lib/ChainMapping.rb +0 -172
  53. data/lib/CodeHandler.rb +0 -513
  54. data/lib/Mapping.rb +0 -27
  55. data/lib/MappingValues.rb +0 -24
  56. data/lib/PartialChain.rb +0 -253
  57. data/lib/Theory.rb +0 -295
  58. data/lib/UnifiedChain.rb +0 -351
  59. data/lib/cauldron/conversion.rb +0 -15
  60. data/lib/cauldron/demos.rb +0 -280
  61. data/lib/cauldron/env.rb +0 -1
  62. data/lib/cauldron/sexp2cauldron.rb +0 -139
  63. data/lib/cauldron/theory_factory.rb +0 -10
  64. data/lib/cauldron/util/home.rb +0 -21
  65. data/lib/cauldron/util/saver.rb +0 -45
  66. data/lib/core/ActsAsCode.rb +0 -25
  67. data/lib/core/BlockToken.rb +0 -33
  68. data/lib/core/CCall.rb +0 -7
  69. data/lib/core/CTestCase.rb +0 -27
  70. data/lib/core/ClassMethodCallContainer.rb +0 -58
  71. data/lib/core/Container.rb +0 -95
  72. data/lib/core/InstanceCallContainer.rb +0 -298
  73. data/lib/core/MethodUsage.rb +0 -65
  74. data/lib/core/PrintVariables.rb +0 -25
  75. data/lib/core/TheoryGenerator.rb +0 -753
  76. data/lib/core/Token.rb +0 -7
  77. data/lib/core/assignment/Assignment.rb +0 -18
  78. data/lib/core/assignment/Equal.rb +0 -39
  79. data/lib/core/assignment/Equivalent.rb +0 -20
  80. data/lib/core/assignment/NotEqual.rb +0 -14
  81. data/lib/core/call_container/CallContainer.rb +0 -72
  82. data/lib/core/class_method_call/New.rb +0 -15
  83. data/lib/core/class_method_call/RuntimeClassMethodCall.rb +0 -31
  84. data/lib/core/declaration/Declaration.rb +0 -16
  85. data/lib/core/declaration/LiteralDeclaration.rb +0 -47
  86. data/lib/core/declaration/VariableDeclaration.rb +0 -59
  87. data/lib/core/instance_call/ArrayEach.rb +0 -23
  88. data/lib/core/instance_call/ArrayLength.rb +0 -15
  89. data/lib/core/instance_call/Chop.rb +0 -19
  90. data/lib/core/instance_call/Copy.rb +0 -22
  91. data/lib/core/instance_call/DeclaredVariable.rb +0 -18
  92. data/lib/core/instance_call/InstanceCall.rb +0 -77
  93. data/lib/core/instance_call/Params.rb +0 -15
  94. data/lib/core/instance_call/Push.rb +0 -20
  95. data/lib/core/instance_call/StringLength.rb +0 -32
  96. data/lib/core/instance_call/Times.rb +0 -20
  97. data/lib/core/instance_call/instance_calls.rb +0 -176
  98. data/lib/core/instance_call/length_equal.rb +0 -15
  99. data/lib/core/kernal/EvalCall.rb +0 -15
  100. data/lib/core/kernal/LocalVariablesCall.rb +0 -15
  101. data/lib/core/literal/Literal.rb +0 -111
  102. data/lib/core/literal/Raw.rb +0 -23
  103. data/lib/core/literal/RuntimeMethodLiteral.rb +0 -21
  104. data/lib/core/literal/StatementLiteral.rb +0 -28
  105. data/lib/core/method_call/AvailableVariablesCall.rb +0 -25
  106. data/lib/core/method_call/ClassCall.rb +0 -33
  107. data/lib/core/method_call/DefCall.rb +0 -72
  108. data/lib/core/method_call/EvaluateClassCall.rb +0 -29
  109. data/lib/core/method_call/MethodNameCall.rb +0 -27
  110. data/lib/core/method_call/ToDeclarationCall.rb +0 -15
  111. data/lib/core/requirement/Requirement.rb +0 -292
  112. data/lib/core/runtime_class/ArrayClass.rb +0 -19
  113. data/lib/core/runtime_class/ClassCallClass.rb +0 -23
  114. data/lib/core/runtime_class/ClassEvaluationClass.rb +0 -19
  115. data/lib/core/runtime_class/ClassName.rb +0 -18
  116. data/lib/core/runtime_class/DefCallClass.rb +0 -21
  117. data/lib/core/runtime_class/EqualClass.rb +0 -19
  118. data/lib/core/runtime_class/FixnumClass.rb +0 -15
  119. data/lib/core/runtime_class/InstanceCallClass.rb +0 -19
  120. data/lib/core/runtime_class/InstanceCallContainerClass.rb +0 -16
  121. data/lib/core/runtime_class/InstanceClassCallClass.rb +0 -19
  122. data/lib/core/runtime_class/LiteralClass.rb +0 -19
  123. data/lib/core/runtime_class/MethodParameterClass.rb +0 -27
  124. data/lib/core/runtime_class/MethodUsageClass.rb +0 -27
  125. data/lib/core/runtime_class/RequirementClass.rb +0 -19
  126. data/lib/core/runtime_class/ReturnClass.rb +0 -21
  127. data/lib/core/runtime_class/RuntimeClass.rb +0 -30
  128. data/lib/core/runtime_class/RuntimeClassClass.rb +0 -19
  129. data/lib/core/runtime_class/RuntimeMethodClass.rb +0 -34
  130. data/lib/core/runtime_class/StatementClass.rb +0 -53
  131. data/lib/core/runtime_class/StringClass.rb +0 -23
  132. data/lib/core/runtime_class/StringLengthClass.rb +0 -19
  133. data/lib/core/runtime_class/StringVariableClass.rb +0 -19
  134. data/lib/core/runtime_class/ThisClass.rb +0 -15
  135. data/lib/core/runtime_class/UnknownClass.rb +0 -23
  136. data/lib/core/runtime_class/class_names.rb +0 -95
  137. data/lib/core/runtime_class/runtime_class.rb +0 -123
  138. data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +0 -293
  139. data/lib/core/runtime_method/ParametersContainer.rb +0 -29
  140. data/lib/core/runtime_method/RealisedRuntimeMethod.rb +0 -94
  141. data/lib/core/runtime_method/RuntimeMethod.rb +0 -814
  142. data/lib/core/runtime_method/WriteParameters.rb +0 -35
  143. data/lib/core/statement/ActsAsStatement.rb +0 -20
  144. data/lib/core/statement/ArrayAccess.rb +0 -122
  145. data/lib/core/statement/BlockStatement.rb +0 -348
  146. data/lib/core/statement/DeclarationStatement.rb +0 -19
  147. data/lib/core/statement/HackStatement.rb +0 -25
  148. data/lib/core/statement/HashAccess.rb +0 -18
  149. data/lib/core/statement/OpenStatement.rb +0 -178
  150. data/lib/core/statement/RealisedStatement.rb +0 -5
  151. data/lib/core/statement/SingleLineBlockStatement.rb +0 -39
  152. data/lib/core/statement/Statement.rb +0 -1091
  153. data/lib/core/statement/StatementGroup.rb +0 -157
  154. data/lib/core/statement/StatementStructure2.rb +0 -224
  155. data/lib/core/statement/TheoryStatement.rb +0 -68
  156. data/lib/core/statement/TopologicalStatements.rb +0 -34
  157. data/lib/core/syntax/Addition.rb +0 -26
  158. data/lib/core/syntax/BlockContainer.rb +0 -102
  159. data/lib/core/syntax/Boolean.rb +0 -15
  160. data/lib/core/syntax/Code.rb +0 -11
  161. data/lib/core/syntax/Do.rb +0 -20
  162. data/lib/core/syntax/False.rb +0 -12
  163. data/lib/core/syntax/If.rb +0 -36
  164. data/lib/core/syntax/Nil.rb +0 -15
  165. data/lib/core/syntax/Return.rb +0 -33
  166. data/lib/core/syntax/Subtract.rb +0 -19
  167. data/lib/core/syntax/This.rb +0 -40
  168. data/lib/core/syntax/True.rb +0 -20
  169. data/lib/core/syntax/syntax.rb +0 -24
  170. data/lib/core/tracking/ActsAsTrackable.rb +0 -65
  171. data/lib/core/tracking/History.rb +0 -167
  172. data/lib/core/tracking/RuntimeTrackingMethod.rb +0 -32
  173. data/lib/core/tracking/Step.rb +0 -52
  174. data/lib/core/variable/ArrayVariable.rb +0 -76
  175. data/lib/core/variable/BaseVariable.rb +0 -152
  176. data/lib/core/variable/BlockVariable.rb +0 -92
  177. data/lib/core/variable/FixnumVariable.rb +0 -35
  178. data/lib/core/variable/HistoryVariable.rb +0 -8
  179. data/lib/core/variable/MethodParameter.rb +0 -179
  180. data/lib/core/variable/MethodUsageVariable.rb +0 -60
  181. data/lib/core/variable/NilVariable.rb +0 -29
  182. data/lib/core/variable/RuntimeMethodParameter.rb +0 -67
  183. data/lib/core/variable/StatementVariable.rb +0 -72
  184. data/lib/core/variable/StepVariable.rb +0 -7
  185. data/lib/core/variable/StringVariable.rb +0 -46
  186. data/lib/core/variable/TypeVariable.rb +0 -72
  187. data/lib/core/variable/Unknown.rb +0 -102
  188. data/lib/core/variable/UnknownVariable.rb +0 -29
  189. data/lib/core/variable/Variable.rb +0 -70
  190. data/lib/core/variable/VariableContainer.rb +0 -28
  191. data/lib/core/variable/VariableIncluded.rb +0 -27
  192. data/lib/core/variable/VariableReference.rb +0 -85
  193. data/lib/error/FailedToFindStatementContainerError.rb +0 -7
  194. data/lib/error/FailedToFindStatementError.rb +0 -7
  195. data/lib/error/FailedToFindVariableError.rb +0 -7
  196. data/lib/error/FailedToLiteraliseError.rb +0 -7
  197. data/lib/error/FailedVariableMatch.rb +0 -7
  198. data/lib/error/ImproperStatementUsageError.rb +0 -7
  199. data/lib/error/IncompatiableRequirementsError.rb +0 -7
  200. data/lib/error/InvalidStatementError.rb +0 -7
  201. data/lib/error/MethodSizeError.rb +0 -7
  202. data/lib/error/RuntimeSyntaxError.rb +0 -7
  203. data/lib/error/UnexpectedStatementTypeError.rb +0 -7
  204. data/lib/error/UnknownStatementType.rb +0 -7
  205. data/lib/error/UnliteralisableError.rb +0 -7
  206. data/lib/implemented_chain.rb +0 -35
  207. data/lib/intrinsic/IntrinsicLastRuntimeMethod.rb +0 -20
  208. data/lib/intrinsic/IntrinsicLiteral.rb +0 -26
  209. data/lib/intrinsic/IntrinsicObject.rb +0 -22
  210. data/lib/intrinsic/IntrinsicRuntimeMethod.rb +0 -27
  211. data/lib/intrinsic/IntrinsicTestCases.rb +0 -17
  212. data/lib/logger/StandardLogger.rb +0 -62
  213. data/lib/required.rb +0 -222
  214. data/lib/ruby_code/Array.rb +0 -95
  215. data/lib/ruby_code/Fixnum.rb +0 -39
  216. data/lib/ruby_code/Hash.rb +0 -25
  217. data/lib/ruby_code/NilClass.rb +0 -19
  218. data/lib/ruby_code/Object.rb +0 -24
  219. data/lib/ruby_code/String.rb +0 -63
  220. data/lib/ruby_code/Symbol.rb +0 -7
  221. data/lib/standard_library/Tasks.rb +0 -12
  222. data/lib/theories.rb +0 -166
  223. data/lib/theory/ActionImplementation.rb +0 -17
  224. data/lib/theory/TheoryAction.rb +0 -100
  225. data/lib/theory/TheoryChainValidator.rb +0 -103
  226. data/lib/theory/TheoryComponent.rb +0 -59
  227. data/lib/theory/TheoryConnector.rb +0 -756
  228. data/lib/theory/TheoryDependent.rb +0 -135
  229. data/lib/theory/TheoryImplementation.rb +0 -75
  230. data/lib/theory/TheoryResult.rb +0 -131
  231. data/lib/theory/TheoryVariable.rb +0 -63
  232. data/lib/theory/theory_collection.rb +0 -62
  233. data/lib/util/ClassEvaluation.rb +0 -44
  234. data/lib/util/CodeEvaluation.rb +0 -39
  235. data/lib/util/DeclarationStatementEvaluation.rb +0 -32
  236. data/lib/util/MethodEvaluation.rb +0 -49
  237. data/lib/util/MethodTester.rb +0 -71
  238. data/lib/util/MethodValidation.rb +0 -149
  239. data/lib/util/MethodWriter.rb +0 -66
  240. data/lib/util/Parser.rb +0 -305
  241. data/lib/util/StatementCheck.rb +0 -44
  242. data/lib/util/StringToTheory.rb +0 -142
  243. data/lib/util/System.rb +0 -8
  244. data/spec/cauldron/chain_spec.rb +0 -24
  245. data/spec/cauldron/demos_spec.rb +0 -30
  246. data/spec/cauldron/runtime_method_spec.rb +0 -92
  247. data/spec/cauldron/saver_spec.rb +0 -45
  248. data/spec/cauldron/sexp_2_cauldron_spec.rb +0 -118
  249. data/spec/cauldron/theory_action_spec.rb +0 -25
  250. data/spec/cauldron/theory_connector_spec.rb +0 -52
  251. data/spec/cauldron/theory_spec.rb +0 -59
  252. data/spec/cauldron/unified_chain_spec.rb +0 -140
  253. data/test/fixtures/chains/1/declaration.txt +0 -26
  254. data/test/fixtures/chains/1/dump +0 -0
  255. data/test/fixtures/chains/2/declaration.txt +0 -26
  256. data/test/fixtures/chains/2/dump +0 -0
  257. data/test/fixtures/chains/3/declaration.txt +0 -26
  258. data/test/fixtures/chains/3/dump +0 -0
  259. data/test/fixtures/implementation_results/0/declaration.txt +0 -3
  260. data/test/fixtures/implementation_results/0/dump +0 -0
  261. data/test/fixtures/theories/0/declaration.txt +0 -9
  262. data/test/fixtures/theories/0/desc +0 -10
  263. data/test/fixtures/theories/0/dump +0 -0
  264. data/test/fixtures/theories/1/declaration.txt +0 -15
  265. data/test/fixtures/theories/1/desc +0 -11
  266. data/test/fixtures/theories/1/dump +0 -0
  267. data/test/fixtures/theories/10/declaration.txt +0 -23
  268. data/test/fixtures/theories/10/desc +0 -17
  269. data/test/fixtures/theories/10/dump +0 -0
  270. data/test/fixtures/theories/11/declaration.txt +0 -20
  271. data/test/fixtures/theories/11/desc +0 -14
  272. data/test/fixtures/theories/11/dump +0 -0
  273. data/test/fixtures/theories/12/declaration.txt +0 -18
  274. data/test/fixtures/theories/12/desc +0 -12
  275. data/test/fixtures/theories/12/dump +0 -0
  276. data/test/fixtures/theories/13/declaration.txt +0 -24
  277. data/test/fixtures/theories/13/desc +0 -20
  278. data/test/fixtures/theories/13/dump +0 -0
  279. data/test/fixtures/theories/14/declaration.txt +0 -26
  280. data/test/fixtures/theories/14/desc +0 -20
  281. data/test/fixtures/theories/14/dump +0 -0
  282. data/test/fixtures/theories/15/declaration.txt +0 -20
  283. data/test/fixtures/theories/15/desc +0 -14
  284. data/test/fixtures/theories/15/dump +0 -0
  285. data/test/fixtures/theories/16/declaration.txt +0 -30
  286. data/test/fixtures/theories/16/desc +0 -14
  287. data/test/fixtures/theories/16/dump +0 -0
  288. data/test/fixtures/theories/17/declaration.txt +0 -25
  289. data/test/fixtures/theories/17/desc +0 -11
  290. data/test/fixtures/theories/17/dump +0 -0
  291. data/test/fixtures/theories/18/declaration.txt +0 -23
  292. data/test/fixtures/theories/18/desc +0 -11
  293. data/test/fixtures/theories/18/dump +0 -0
  294. data/test/fixtures/theories/19/declaration.txt +0 -23
  295. data/test/fixtures/theories/19/desc +0 -11
  296. data/test/fixtures/theories/19/dump +0 -0
  297. data/test/fixtures/theories/2/declaration.txt +0 -12
  298. data/test/fixtures/theories/2/desc +0 -10
  299. data/test/fixtures/theories/2/dump +0 -0
  300. data/test/fixtures/theories/20/declaration.txt +0 -23
  301. data/test/fixtures/theories/20/desc +0 -17
  302. data/test/fixtures/theories/20/dump +0 -0
  303. data/test/fixtures/theories/3/declaration.txt +0 -19
  304. data/test/fixtures/theories/3/desc +0 -11
  305. data/test/fixtures/theories/3/dump +0 -0
  306. data/test/fixtures/theories/4/declaration.txt +0 -11
  307. data/test/fixtures/theories/4/desc +0 -11
  308. data/test/fixtures/theories/4/dump +0 -0
  309. data/test/fixtures/theories/5/declaration.txt +0 -6
  310. data/test/fixtures/theories/5/desc +0 -9
  311. data/test/fixtures/theories/5/dump +0 -0
  312. data/test/fixtures/theories/6/declaration.txt +0 -13
  313. data/test/fixtures/theories/6/desc +0 -11
  314. data/test/fixtures/theories/6/dump +0 -0
  315. data/test/fixtures/theories/7/declaration.txt +0 -19
  316. data/test/fixtures/theories/7/desc +0 -11
  317. data/test/fixtures/theories/7/dump +0 -0
  318. data/test/fixtures/theories/8/declaration.txt +0 -21
  319. data/test/fixtures/theories/8/desc +0 -11
  320. data/test/fixtures/theories/8/dump +0 -0
  321. data/test/fixtures/theories/9/declaration.txt +0 -24
  322. data/test/fixtures/theories/9/desc +0 -20
  323. data/test/fixtures/theories/9/dump +0 -0
  324. data/test/fixtures/theory_implementations/0/declaration.txt +0 -11
  325. data/test/fixtures/theory_implementations/0/desc.txt +0 -9
  326. data/test/fixtures/theory_implementations/0/dump +0 -0
  327. data/test/fixtures/theory_implementations/0/theory_id +0 -1
  328. data/test/fixtures/theory_implementations/1/declaration.txt +0 -11
  329. data/test/fixtures/theory_implementations/1/desc.txt +0 -9
  330. data/test/fixtures/theory_implementations/1/dump +0 -1
  331. data/test/fixtures/theory_implementations/1/theory_id +0 -1
  332. data/test/fixtures/theory_implementations/2/declaration.txt +0 -11
  333. data/test/fixtures/theory_implementations/2/desc.txt +0 -9
  334. data/test/fixtures/theory_implementations/2/dump +0 -0
  335. data/test/fixtures/theory_implementations/2/theory_id +0 -1
  336. data/test/output/simple_method.txt +0 -5
  337. data/test/output/test_method/first_possible_method.txt +0 -6
  338. data/test/output/test_simple_cases/simple_case_01.txt +0 -8
  339. data/test/output/test_simple_cases/simple_case_02.txt +0 -7
  340. data/test/output/test_simple_cases/simple_case_03.txt +0 -8
  341. data/test/output/test_simple_cases/simple_case_04.txt +0 -8
  342. data/test/output/test_simple_cases/simple_case_05.txt +0 -8
  343. data/test/output/test_simple_cases/simple_case_06.txt +0 -9
  344. data/test/output/test_simple_cases/simple_case_07.txt +0 -9
  345. data/test/output/test_simple_cases/simple_case_08.txt +0 -9
  346. data/test/tc_describe.rb +0 -46
  347. data/test/tc_method.rb +0 -130
  348. data/test/tc_requirement.rb +0 -30
  349. data/test/tc_suite_complete.rb +0 -26
  350. data/test/tc_variable.rb +0 -52
  351. data/test/ts_complete.rb +0 -74
  352. data/test/ts_stable.rb +0 -81
  353. data/test/unit/core/declaration/tc_literal_declaration.rb +0 -34
  354. data/test/unit/core/method_call/tc_class_call.rb +0 -20
  355. data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +0 -132
  356. data/test/unit/core/runtime_method/tc_runtime_method.rb +0 -546
  357. data/test/unit/core/statement/tc_array_access.rb +0 -63
  358. data/test/unit/core/statement/tc_block_statement.rb +0 -53
  359. data/test/unit/core/statement/tc_hack_statement.rb +0 -26
  360. data/test/unit/core/statement/tc_open_statement.rb +0 -79
  361. data/test/unit/core/statement/tc_statement.rb +0 -483
  362. data/test/unit/core/statement/tc_statement_group.rb +0 -35
  363. data/test/unit/core/statement/tc_statement_replace_variable.rb +0 -61
  364. data/test/unit/core/statement/tc_theory_statement.rb +0 -53
  365. data/test/unit/core/syntax/tc_block_container.rb +0 -32
  366. data/test/unit/core/syntax/tc_if_container.rb +0 -39
  367. data/test/unit/core/tc_class_method_call.rb +0 -34
  368. data/test/unit/core/tc_container.rb +0 -41
  369. data/test/unit/core/tc_ctest_case.rb +0 -25
  370. data/test/unit/core/tc_instance_call_container.rb +0 -93
  371. data/test/unit/core/tc_literal.rb +0 -30
  372. data/test/unit/core/tc_theory_generator.rb +0 -336
  373. data/test/unit/core/tc_theory_generator_heavy.rb +0 -42
  374. data/test/unit/core/tracking/tc_history.rb +0 -104
  375. data/test/unit/core/tracking/tc_step.rb +0 -65
  376. data/test/unit/core/variable/tc_array_variable.rb +0 -61
  377. data/test/unit/core/variable/tc_block_variable.rb +0 -17
  378. data/test/unit/core/variable/tc_fixnum_variable.rb +0 -54
  379. data/test/unit/core/variable/tc_method_parameter_variable.rb +0 -22
  380. data/test/unit/core/variable/tc_runtime_method_variable.rb +0 -32
  381. data/test/unit/core/variable/tc_string_variable.rb +0 -37
  382. data/test/unit/core/variable/tc_unknown.rb +0 -24
  383. data/test/unit/core/variable/tc_variable_reference.rb +0 -28
  384. data/test/unit/ruby_code/tc_array.rb +0 -64
  385. data/test/unit/ruby_code/tc_fixnum.rb +0 -18
  386. data/test/unit/ruby_code/tc_hash.rb +0 -41
  387. data/test/unit/ruby_code/tc_string.rb +0 -38
  388. data/test/unit/tc_chain.rb +0 -434
  389. data/test/unit/tc_chain_mapping.rb +0 -62
  390. data/test/unit/tc_chain_with_case_1.rb +0 -169
  391. data/test/unit/tc_instance_call.rb +0 -40
  392. data/test/unit/tc_method_usage.rb +0 -35
  393. data/test/unit/tc_pot.rb +0 -124
  394. data/test/unit/tc_runtime_tracking_method.rb +0 -40
  395. data/test/unit/tc_theory.rb +0 -531
  396. data/test/unit/tc_variable_declaration.rb +0 -32
  397. data/test/unit/theory/tc_theory_action.rb +0 -108
  398. data/test/unit/theory/tc_theory_action_implementation.rb +0 -23
  399. data/test/unit/theory/tc_theory_chain_validator.rb +0 -340
  400. data/test/unit/theory/tc_theory_connector.rb +0 -361
  401. data/test/unit/theory/tc_theory_dependent.rb +0 -153
  402. data/test/unit/theory/tc_theory_implementation.rb +0 -137
  403. data/test/unit/theory/tc_theory_result.rb +0 -112
  404. data/test/unit/theory/tc_theory_variable.rb +0 -45
  405. data/test/unit/util/tc_method_validation.rb +0 -101
  406. data/test/unit/util/tc_parser.rb +0 -110
  407. data/test/unit/util/tc_string_to_theory.rb +0 -300
  408. data/test/unit/variable/tc_method_usage_variable.rb +0 -25
  409. data/tmp/runtime_method_evaluation.rb +0 -16
@@ -1,23 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'autotest/restart'
4
-
5
- # Autotest.add_hook :initialize do |at|
6
- # at.extra_files << "../some/external/dependency.rb"
7
- #
8
- # at.libs << ":../some/external"
9
- #
10
- # at.add_exception 'vendor'
11
- #
12
- # at.add_mapping(/dependency.rb/) do |f, _|
13
- # at.files_matching(/test_.*rb$/)
14
- # end
15
- #
16
- # %w(TestA TestB).each do |klass|
17
- # at.extra_class_map[klass] = "test/test_misc.rb"
18
- # end
19
- # end
20
-
21
- # Autotest.add_hook :run_command do |at|
22
- # system "rake build"
23
- # end
@@ -1,6 +0,0 @@
1
- === 1.0.0 / 2011-06-08
2
-
3
- * 1 major enhancement
4
-
5
- * Birthday!
6
-
@@ -1,8 +0,0 @@
1
- .autotest
2
- History.txt
3
- Manifest.txt
4
- README.txt
5
- Rakefile
6
- bin/cauldron
7
- lib/cauldron.rb
8
- test/test_cauldron.rb
@@ -1,57 +0,0 @@
1
- = cauldron
2
-
3
- * FIX (url)
4
-
5
- == DESCRIPTION:
6
-
7
- FIX (describe your package)
8
-
9
- == FEATURES/PROBLEMS:
10
-
11
- * FIX (list of features or problems)
12
-
13
- == SYNOPSIS:
14
-
15
- FIX (code sample of usage)
16
-
17
- == REQUIREMENTS:
18
-
19
- * FIX (list of requirements)
20
-
21
- == INSTALL:
22
-
23
- * FIX (sudo gem install, anything else)
24
-
25
- == DEVELOPERS:
26
-
27
- After checking out the source, run:
28
-
29
- $ rake newb
30
-
31
- This task will install any missing dependencies, run the tests/specs,
32
- and generate the RDoc.
33
-
34
- == LICENSE:
35
-
36
- (The MIT License)
37
-
38
- Copyright (c) 2011 FIX
39
-
40
- Permission is hereby granted, free of charge, to any person obtaining
41
- a copy of this software and associated documentation files (the
42
- 'Software'), to deal in the Software without restriction, including
43
- without limitation the rights to use, copy, modify, merge, publish,
44
- distribute, sublicense, and/or sell copies of the Software, and to
45
- permit persons to whom the Software is furnished to do so, subject to
46
- the following conditions:
47
-
48
- The above copyright notice and this permission notice shall be
49
- included in all copies or substantial portions of the Software.
50
-
51
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
52
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
54
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
55
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
57
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,27 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'rubygems'
4
- require 'hoe'
5
-
6
- # Hoe.plugin :compiler
7
- # Hoe.plugin :compiler
8
- # Hoe.plugin :gem_prelude_sucks
9
- # Hoe.plugin :gem_prelude_sucks
10
- # Hoe.plugin :inline
11
- # Hoe.plugin :inline
12
- # Hoe.plugin :racc
13
- # Hoe.plugin :racc
14
- # Hoe.plugin :rubyforge
15
- # Hoe.plugin :rubyforge
16
-
17
- Hoe.spec 'cauldron' do
18
- # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
19
- # you'll never have to touch them again!
20
- # (delete this comment too, of course)
21
-
22
- # developer('FIX', 'FIX@example.com')
23
-
24
- # self.rubyforge_name = 'cauldronx' # if different than 'cauldron'
25
- end
26
-
27
- # vim: syntax=ruby
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- abort "you need to write me"
@@ -1,3 +0,0 @@
1
- class Cauldron
2
-
3
- end
@@ -1,8 +0,0 @@
1
- require "test/unit"
2
- require "cauldron"
3
-
4
- class TestCauldron < Test::Unit::TestCase
5
- def test_sanity
6
- flunk "write tests or I will kneecap you"
7
- end
8
- end
@@ -1,13 +0,0 @@
1
- Feature: User enters example cases
2
- The user enters a number of example cases that get saved to be ran later
3
-
4
- Scenario Outline: add test cases
5
- Given that the terminal has been started
6
- When I add the case "<case>"
7
- Then the case "<case>" should be saved
8
-
9
- Scenarios: single paramerter cases
10
- | case |
11
- | 'sparky', 'spark' |
12
- | 'kel', 'kel' |
13
-
@@ -1,16 +0,0 @@
1
- Feature: Cauldron generates a runtime method
2
- I want a runtime method
3
- That will solve a set of example cases
4
-
5
- TODO The second solution isn't correct but for now it will do
6
-
7
- Scenario Outline: Generate a solution to a previously solved problem
8
- Given that the terminal has been created
9
- When I add a case with a param <case_1_param> and an expected output of <case_1_output>
10
- And I add a case with a param <case_2_param> and an expected output of <case_2_output>
11
- Then I should receive a runtime method like this <runtime_method>
12
-
13
- Scenarios: example with only one parameter
14
- | case_1_param | case_1_output | case_2_param | case_2_output | runtime_method |
15
- | "sparky" | "sparky" | "kel" | "kel" | "def method_0(var_0)\n return var_0\nend\n" |
16
- | "fish" | "animal" | "carrot" | "vegetable" | "def method_0(var_0)\n if(var_0 == 'fish')\n return 'animal'\n end\n return 'vegetable'\n return var_0\nend\n" |
@@ -1,25 +0,0 @@
1
- Feature: Cauldron generates single parameter methods
2
-
3
- Cauldron can generate runtime methods that accepts one parameters
4
-
5
- NOTE: it creates the file in tmp/aruba/launch.rb - so that loading path needs to be changed
6
- - use @pause to see if it's working.
7
-
8
- @announce @slow_process
9
- Scenario: Method returns the passed in value
10
- Given a file named "launch.rb" with:
11
- """
12
- $LOAD_PATH.unshift File.expand_path( File.join('lib') )
13
- require 'cauldron'
14
- cauldron = Cauldron::Terminal.new(STDOUT,false)
15
- cauldron.start
16
- """
17
- And I run `ruby launch.rb` interactively
18
- And I add the case "sparky","sparky"
19
- And I type "RUN"
20
- When I type "QUIT"
21
- Then the output should contain:
22
- """
23
- return var_0
24
- """
25
-
@@ -1,17 +0,0 @@
1
- Feature: It should display a start up message
2
-
3
- @announce @slow_process
4
- Scenario: Interactive cauldron start up
5
- Given a file named "launch.rb" with:
6
- """
7
- $LOAD_PATH.unshift File.expand_path( File.join('lib') )
8
- require 'cauldron'
9
- cauldron = Cauldron::Terminal.new(STDOUT,false)
10
- cauldron.start
11
- """
12
- And I run `ruby launch.rb` interactively
13
- When I type "QUIT"
14
- Then the output should contain:
15
- """
16
- Starting...
17
- """
@@ -1,9 +0,0 @@
1
- Feature: Cauldron can be quit from the terminal
2
- Typing "QUIT" in the terminal will cause the process to quit
3
-
4
- see for examples https://github.com/cucumber/aruba/blob/master/features/interactive.feature
5
-
6
- #Scenario: quit cauldron from the terminal
7
- # Given I've started Cauldron
8
- # Then the exit status should be 0
9
-
@@ -1,12 +0,0 @@
1
- Feature: Cauldron starts on the command line
2
- I want cauldron to start
3
- So that I can describe the method I want it generate
4
- Scenario: start cauldron
5
- When I start cauldron
6
- Then I should see "Thanks for trying Cauldron - it's at really early stage right now"
7
- And then I should see "To start enter your first test like this"
8
- And then I should see "input,input,output"
9
- And then I should see "For example "
10
- And then I should see "'cat','animal'"
11
- And then I should see "'carrot','vegtable'"
12
- And then I should see "and when you're done just type RUN"
@@ -1,3 +0,0 @@
1
- def method_3(var_6)
2
- return var_6
3
- end
@@ -1,6 +0,0 @@
1
- def method_1(var_1)
2
- if var_1 == 'fish'
3
- return 'animal'
4
- end
5
- return 'vegtable'
6
- end
@@ -1,771 +0,0 @@
1
- require "logger"
2
- class Chain
3
- # TODO This access is proably temporary
4
- attr_reader :chain_mapping
5
-
6
- @@default_tail_theory = nil
7
- #
8
- # @param nodes An array of theories in order
9
- #
10
- def initialize()
11
- @values, @nodes = {}, []
12
-
13
- # Create an array of possible ids for any theories added
14
- @uniq_theory_instance_ids = ('AA'...'ZZ').to_a
15
-
16
- # Create a result version of 'finish'
17
-
18
- # TODO Drop @tail_theory as a instance variable
19
- #@tail_theory = Theory.new([tail_dependent],nil,[])
20
- @tail_theory = Chain.default_tail_theory
21
-
22
- # NOTE: Now the head and tail are using the same ids for their variables
23
- @chain_mapping = ChainMapping.new()
24
-
25
- # Get the value mappings for the chain
26
- tc = Parser.run('test_cases')
27
- real_method = Parser.run('runtime_method')
28
-
29
- # Add the tail to the nodes list
30
- #add_link(@tail_theory,{1=>real_method,2=>tc})
31
- extension_permutaions(@tail_theory,{1=>real_method,2=>tc})
32
-
33
- end
34
-
35
- def self.default_tail_theory
36
- if @@default_tail_theory.nil?
37
- finish = Parser.run("if(runtime_method.all_pass?(test_cases))\nreturn true\nend")
38
- tail_theory = finish.write
39
- tail_theory.gsub!('runtime_method','var1')
40
- tail_theory.gsub!('test_cases','var2')
41
- tail_dependent = TheoryDependent.new(StringToTheory.run(tail_theory))
42
- @@default_tail_theory = Theory.new([tail_dependent],nil,[])
43
- @@default_tail_theory.copy
44
- else
45
- @@default_tail_theory.copy
46
- end
47
- end
48
-
49
- # TODO I want to drop allot of these quick methods
50
- def <<(node)
51
- @nodes << node
52
- end
53
-
54
- def length
55
- return @nodes.length
56
- end
57
-
58
- def each(&block)
59
- @nodes.each(&block)
60
- end
61
-
62
- def [](index)
63
- return @nodes[index]
64
- end
65
-
66
- def first
67
- return @nodes.first
68
- end
69
-
70
- def last
71
- return @nodes.last
72
- end
73
-
74
- def reverse
75
- return Chain.new(@nodes.reverse)
76
- end
77
-
78
- def shift
79
- return @nodes.shift
80
- end
81
-
82
- def copy
83
- #return Chain.new(@nodes.copy)
84
- return Marshal.load(Marshal.dump(self))
85
- end
86
-
87
- def empty?
88
- return @nodes.empty?
89
- end
90
-
91
- def pop
92
- return @nodes.pop
93
- end
94
-
95
- def collect(&block)
96
- return @nodes.collect(&block)
97
- end
98
-
99
- def write(tab=0)
100
- return @nodes.inject('') {|total,x| total += x.write}
101
- end
102
-
103
- def describe(tab=0)
104
- return @nodes.inject('') {|total,x| total += x.describe}
105
- end
106
-
107
- # Returns an array of all the unique theory variables used within
108
- # the chain.
109
- #
110
- # e.g. [0,6,7]
111
- #
112
- def uniq_theory_variable_ids
113
- return @nodes.inject([]) do |total,theory|
114
- total = total | theory.all_theory_variables.collect {|x| x.theory_variable_id}
115
- end
116
- end
117
-
118
- def unmet_dependents_ids
119
- collection = TheoryCollection.new(@nodes)
120
- return collection.dependents.inject([]) do |total,dependent|
121
- total << dependent.theory_component_id unless @chain_mapping.connected_component_ids.include?(dependent.theory_component_id)
122
- total
123
- end
124
- end
125
-
126
- def theories_sequence
127
- @nodes.collect {|x| x.theory_id}
128
- end
129
-
130
- # Returns a new chain where they are all using the same respective theory
131
- # variables.
132
- #
133
- # TODO This seems to create implemented theories - I'm not sure this is what I want
134
- #
135
- def unify_chain
136
- unless complete?
137
- raise StandardError.new('Only complete chains can be unified')
138
- end
139
- unified_theories = @nodes.inject([]) do |total,theory|
140
- mapping = generate_theory_mapping(theory.theory_instance_id)
141
- mapped_theory = theory.map_to(mapping)
142
- total.push(mapped_theory)
143
- end
144
- # => TODO This contians information about the chain before it has been unified - this should not be included
145
- return UnifiedChain.new(unified_theories,@chain_mapping.copy).freeze
146
- end
147
-
148
- # DEVELOPMENT
149
- # Because I'm using Marshal to restore some of the theories I just need to check that
150
- # none of the components have duplicate ids.
151
- #
152
- def duplicate_component_ids?
153
- collection = TheoryCollection.new(@nodes)
154
- component_ids = collection.components.inject([]) {|total,x| total << x.theory_component_id }
155
- return (component_ids.length != component_ids.uniq.length)
156
- end
157
-
158
- # Returns the number of breaks in the chain - this is essential the number of
159
- # unmet depements.
160
- #
161
- def broken_link_count
162
- collection = TheoryCollection.new(@nodes)
163
- return collection.dependents.inject(0) do |total,dependent|
164
- unless @chain_mapping.connected_component_ids.include?(dependent.theory_component_id)
165
- total += 1
166
- end
167
- total
168
- end
169
- end
170
-
171
- # TODO Really need a method to highlight what is connected to what
172
-
173
- # Writes out the chain but highlights any of links in the chain weren't connected
174
- # to a dependent.
175
- #
176
- def highlight_broken_links
177
- if duplicate_component_ids?
178
- StandardLogger.instance.warning('You are using theories that share the same component_id')
179
- end
180
- unmet = []
181
- each_unmet(:dependents,0,@nodes) do |index,theory,dependent|
182
- unmet << dependent.theory_component_id
183
- end
184
- return @nodes.inject('') {|msg,x| msg += x.highlight(unmet)}
185
- end
186
-
187
- # Attempts to add a new link to form a complete chain between the head and tail. It starts
188
- # by linking to the tail and then head.
189
- #
190
- def extension_permutaions(theory,value_mapping=nil)
191
-
192
- # Give the theory an instance id
193
- theory = theory.copy
194
- raise StandardError.new('Reached limit to chains length') if @uniq_theory_instance_ids.empty?
195
- theory.theory_instance_id = @uniq_theory_instance_ids.shift
196
-
197
- # Save the values for use later during the global mapping
198
- @values[theory.theory_instance_id] = value_mapping
199
-
200
- # The first link added should be the tail
201
- if @nodes.empty?
202
- add_tail(theory,value_mapping)
203
- return
204
- end
205
-
206
- # The second link should be the head
207
- # (this doesn't necessarily need to be be case but I'll keep this convention
208
- if @nodes.length == 1
209
- return add_link_to(theory,0,value_mapping)
210
- end
211
-
212
- # Attempt to add a link to all the possible locations (head and tail are exempt)
213
- extended_chains = []
214
- (1...@nodes.length).each do |position|
215
- res = self.copy.add_link_to(theory,position,value_mapping)
216
- extended_chains += res
217
- end
218
- return extended_chains
219
-
220
- end
221
-
222
- # Returns true if the chain can be connected from the head to the tail.
223
- #
224
- def complete?
225
-
226
- # Check that all the variables in all the theories have been globally mapped, as well as the head
227
- @nodes.each do |theory|
228
- # Find the global variable for each of the theory variables
229
- theory.all_theory_variables.each do |theory_variable|
230
- begin
231
- to_global_id(@chain_mapping,theory.theory_instance_id,theory_variable.theory_variable_id)
232
- rescue StandardError => e
233
- StandardLogger.instance.error(e)
234
- return false
235
- end
236
- end
237
- end
238
- return dependents_met?
239
-
240
- end
241
-
242
- # This uses the supplied theories and checks whether the dependents
243
- # of any of theories that might be used are reachable.
244
- #
245
- # NOTE: This is only a rough assessment of whether the dependents are available
246
- # it doesn't mean that it is solvable but does identify that it definitely
247
- # isn't.
248
- #
249
- def solvable?(finish,theories)
250
-
251
- # Get the finish and check all the dependents can be met by the theories
252
- all_results = theories.inject([]) {|total,x| total += x.results}
253
- return false unless all_results.any? {|x| x.same_structure?(finish)}
254
-
255
- # Find the theories that can solve the problem and check their dependents can be met
256
- # TODO Should probably include the head theory in here too.
257
- collection = TheoryCollection.new(theories.copy)
258
- finishing_theories = []
259
- collection.each_with_result_structure(finish) do |t,r|
260
- finishing_theories.push(t)
261
- end
262
-
263
- finishing_theories.each do |x|
264
- end
265
- res = finishing_theories.any? do |x|
266
- dependency_tree_met?(x,theories+[self.first.copy])
267
- end
268
- return res
269
- end
270
-
271
- # Returns any number of new chains after adding this link to the position
272
- # specified.
273
- #
274
- # TODO SHould I raise an error if it doesn't connect to anything?
275
- #
276
- def add_link_to(theory,position,value_mapping)
277
- # TODO Down and up are quite similar I should consider refactoring
278
-
279
- # Do through each of the dependents and then find a result with the same structure
280
- mappings = [@chain_mapping.copy]
281
- upward_links = @nodes[0...position]
282
-
283
- theory.copy.dependents.each do |dependent|
284
- each_result(position,upward_links) do |index,link,result|
285
- if result.same_structure?(dependent)
286
- new_mappings = []
287
- mappings.each do |x|
288
- new_mappings << x.apply_mapping_update(theory,dependent.theory_component_id,link,result.theory_component_id)
289
- end
290
- mappings = new_mappings
291
- end
292
- end
293
- end
294
-
295
- # Go down the rest of the chain looking for exisitng links with unmet dependents
296
- downward_links = @nodes[position...@nodes.length]
297
- theory.copy.results.each do |result|
298
- each_unmet(:dependents,position,downward_links) do |index,link,dependent|
299
- if dependent.same_structure?(result)
300
- new_mappings = []
301
- mappings.each do |x|
302
- new_mappings << x.apply_mapping_update(link,dependent.theory_component_id,theory,result.theory_component_id)
303
- end
304
- mappings = new_mappings
305
- end
306
- end
307
- end
308
-
309
- # Strip out any mappings that are identical to original they are
310
- # links that haven't been connected with anything
311
- # (don't include the head since it only has one thing to connect to)
312
- # => TODO Do I like this? It means I'm including some forced connections
313
- unless @nodes.length < 2
314
-
315
- # Identify the mappings that are the same
316
- mappings = mappings.select {|x| !@chain_mapping.same?(x) }
317
- # => TODO Should inlcude error/warning and exit when there are no new mappings
318
- end
319
-
320
- # Identify any orphan variables in the action and give them uniq global ids
321
- mappings.each do |mapping|
322
- theory.orphan_action_variables.each do |x|
323
- mapping.add_mapping(
324
- mapping.next_free_global_id,
325
- theory.theory_instance_id,
326
- x.theory_variable_id
327
- )
328
- end
329
- end
330
-
331
- # Create a new nodes array with the new theory in place
332
- updated_nodes = @nodes.copy
333
- updated_nodes.insert(position,theory)
334
-
335
- # Create a new chain for each of the possible mappings
336
- extended_chains = []
337
- mappings.each do |x|
338
- c = self.copy
339
- new_chain = c.create!(updated_nodes,x,@uniq_theory_instance_ids.copy,@values.copy)
340
- extended_chains << new_chain
341
- end
342
- return extended_chains
343
- end
344
-
345
- # Implements a new the chain where all the theories are implemented. It can
346
- # only be implemented if the chain is complete e.g. all the dependents and results
347
- # are matched up.
348
- #
349
- def implement
350
- raise StandardError.new('This chain is not complete') unless complete?
351
-
352
- # Generate a global value mapping - so global id to real value
353
- unifyied_chain = unify_chain
354
-
355
- return unifyied_chain.implement(intrinsic_mapping)
356
-
357
- end
358
-
359
- # Returns an array of implemented theories that have variable syntax that can
360
- # be mapped to literal syntax(runtime_method,0,...) and also contain
361
- # real values for each of the variables. So the runtime method will
362
- # include all statements added to it.
363
- #
364
- def each_theory_progression(initial_runtime_method,test_cases)
365
- raise StandardError.new('Only complete theories can be watched') unless self.implementable?
366
-
367
- theories = []
368
- previous_runtime_method = initial_runtime_method.copy
369
- chain_validator = TheoryChainValidator.new
370
- progressive_chain do |chain,theory|
371
- initial_runtime_method.copy
372
- runtime_method = chain_validator.build_method_from_chain( chain.implement,
373
- initial_runtime_method.copy,
374
- test_cases)
375
-
376
- # Create the intrinsic mapping for the theory
377
- unified_chain = chain.unify_chain
378
-
379
- # * Go through each variable and find the intrinsic value
380
- theory_intrinsic_mapping = Mapping.new
381
- values = {:before=>{},:after=>{}}
382
- unified_chain.theory_variables.each do |var|
383
- intrinsic_value = global_id_intrinsic_value(var.theory_variable_id)
384
- theory_intrinsic_mapping[var.theory_variable_id] = intrinsic_value
385
-
386
- # Add the actual varlue of the intrinsic value
387
- if intrinsic_value.kind_of?(IntrinsicRuntimeMethod)
388
- values[:before][var.theory_variable_id] = previous_runtime_method.copy
389
- values[:after][var.theory_variable_id] = previous_runtime_method.copy
390
- next
391
- end
392
- if intrinsic_value.kind_of?(IntrinsicTestCases)
393
- values[:before][var.theory_variable_id] = test_cases.copy
394
- values[:after][var.theory_variable_id] = test_cases.copy
395
- next
396
- else
397
- values[:before][var.theory_variable_id] = intrinsic_value.literal
398
- values[:after][var.theory_variable_id] = intrinsic_value.literal
399
- end
400
- end
401
-
402
- # Generate a unified version of the theory
403
- mapping = generate_theory_mapping(theory.theory_instance_id)
404
- unified_theory = theory.map_to(mapping)
405
-
406
- yield theory.map_to(theory_intrinsic_mapping,values), unified_theory
407
-
408
- # Save the previous method for the dependents
409
- previous_runtime_method = runtime_method
410
-
411
- end
412
- return theories
413
-
414
- end
415
-
416
- # Return true if the chain can be implemented - so all the theories have literal values
417
- # associated with them. This could be directly via when the theory was added to the
418
- # chain or indirectly via connecting two theories.
419
- #
420
- def implementable?
421
- self.implement
422
- return true
423
- rescue StandardError => e
424
- StandardLogger.instance.info e
425
- return false
426
- end
427
-
428
- # Returns an array of all the theory variables used in the chain
429
- #
430
- def theory_variables
431
- return TheoryCollection.new(@nodes).theory_variables
432
- end
433
-
434
- # Returns an array of all the depdendents in the chain that haven't
435
- # been met by the front of the chain.
436
- #
437
- def unmet_dependents
438
- results = []
439
- return results if self.empty?
440
- duplicate_chain = self.copy
441
- last_link = duplicate_chain.pop
442
- last_link.dependents.each do |dependent|
443
- results.push dependent unless dependent_met?(dependent,duplicate_chain.copy)
444
- end
445
- return results+duplicate_chain.unmet_dependents
446
- end
447
-
448
- # TODO Maybe just move this method to the UnfiedChain class
449
- # Returns a set containing the intrinsic statements that created the variables. It should look
450
- # something like the following.
451
- #
452
- # [{:global_variable_id=>0,:intrinsic_statement=>runtime_method,:written_statement=>'var1'},
453
- # {:global_variable_id=>3,:intrinsic_statement=>runtime_method.params[0],:written_statement=>'var1.params[var3]'},
454
- # ...]
455
- #
456
- # Currently the only way variables are created are for array access.
457
- #
458
- # There should not be the case where there are duplicate intrinsic_statements but different global_variable_ids -
459
- # for now at least.
460
- #
461
- def variables_creation(runtime_method,test_cases)
462
- raise StandardError.new('This should only be called on complete chains') unless complete?
463
- res = []
464
- unify_chain.theory_variables.each do |var|
465
-
466
- intrinsic_value = global_id_intrinsic_value(var.theory_variable_id)
467
- if intrinsic_value.kind_of?(IntrinsicRuntimeMethod)
468
- res << {
469
- :global_variable_id=>var.theory_variable_id,
470
- :intrinsic_statement=>Parser.run('runtime_method'),
471
- :written_statement=>'var'+var.theory_variable_id.to_s,
472
- :variable_value=>runtime_method.copy
473
- }
474
- elsif intrinsic_value.kind_of?(IntrinsicTestCases)
475
- res << {
476
- :global_variable_id=>var.theory_variable_id,
477
- :intrinsic_statement=>Parser.run('test_cases'),
478
- :written_statement=>'var'+var.theory_variable_id.to_s,
479
- :variable_value=>test_cases.copy
480
- }
481
- else
482
-
483
- # TODO This whole bit is just really rushed------------------ write tests!
484
-
485
- # Find all the statements that include that variable
486
- unified_components = unify_chain.components
487
-
488
- # TODO This is an extremely clumsy approach
489
- # Collect all the written components matching the delcaration
490
- written_components = unified_components.collect {|x| x.write}
491
- written_components = written_components.select {|x| x.include?('var'+var.theory_variable_id.to_s)}
492
-
493
- # => DEV
494
- temp_component = written_components.first
495
-
496
- # => MATCH var0.params[var2] in runtime_method.add_statement_at(OpenStatement.new(TheoryStatement.new(If.new, Container.new(var0.params[var2], Equivalent.new, var1[var4][:params][var3]))),var0.statement_id)
497
- reg = eval('/[\w\d\.\[\]:]*\['+var.write+'\]/')
498
-
499
- # TODO Should use the Parser to find the statement with the varx in
500
- #var_match = /\s.*\[var[\d]\]/
501
- #var_match = /^[\s|\(]+(.*\[var[\d]\])/
502
- var_match = reg
503
- usage_statements = written_components.inject([]) do |total,x|
504
-
505
- #unless x.write.match(/\s.*\[var[\d]\]/).nil?
506
- unless x.write.match(var_match).nil?
507
- match = x.write.match(var_match)[0]
508
- total << TheoryStatement.new(StringToTheory.run(match))
509
- end
510
- total
511
- end
512
- intrinsic_statements = usage_statements.collect {|x| x.map_to(intrinsic_mapping)}
513
-
514
- unless intrinsic_statements.collect {|x| x.write}.uniq.length == 1
515
- raise StandardError.new('Unable to create intrinsic variable create for variable '+var.theory_variable_id.to_s)
516
- end
517
-
518
- res << {
519
- :global_variable_id=>var.theory_variable_id,
520
- :intrinsic_statement=>intrinsic_statements.first,
521
- :written_statement=>usage_statements.first.write,
522
- :variable_value=>intrinsic_mapping[var.theory_variable_id].copy
523
- }
524
-
525
- end
526
- end
527
- return res
528
- end
529
-
530
- # Returns a hash of all the unmet dependents down the chain (excluding the head)
531
- # and the link/theory that it belongs to.
532
- #
533
- def unmet_dependents_and_link
534
- results = []
535
- return results if self.empty?
536
- duplicate_chain = self.copy
537
-
538
- # Remove the head link from the chain
539
- duplicate_chain.shift
540
-
541
- duplicate_chain.length.times do
542
- last_link = duplicate_chain.pop
543
- last_link.dependents.each do |d|
544
- next if dependent_met?(d,duplicate_chain.copy)
545
- results.push({:dependent=>d.copy,:theory=>last_link.copy})
546
- end
547
- end
548
- return results
549
- end
550
-
551
- protected
552
-
553
- # Returns the intrinsic mapping for the unified chain
554
- #
555
- def intrinsic_mapping
556
-
557
- # Generate a global value mapping - so global id to real value
558
- unifyied_chain = unify_chain
559
-
560
- # Get all the global variable ids -
561
- m = Mapping.new
562
- unifyied_chain.theory_variables.each do |x|
563
- m[x.theory_variable_id] = global_id_intrinsic_value(x.theory_variable_id)
564
- end
565
- return m
566
- end
567
-
568
- # Returns an array of all the components used in the chain
569
- # TODO Could be turned into a set.
570
- def components
571
- return @nodes.inject([]) {|total,x| total += x.components }
572
- end
573
-
574
- # Returns the intrinsic value for specified global id. The intrinsic value is
575
- # IntrinsicRuntimeMethod.new(7), IntrinsicFixnum.new(8), ...
576
- #
577
- # @param global_id The global id saved in chain_mapping
578
- #
579
- def global_id_intrinsic_value(global_id)
580
-
581
- # Possible values for global_id
582
- potentential_values = []
583
- @chain_mapping.mapping[global_id].each do |key,value|
584
- if @values[key]
585
- potentential_values << @values[key][value]
586
- end
587
- end
588
-
589
- if potentential_values.empty?
590
- raise StandardError.new('Could not find an implementation value for global variable '+global_id.to_s)
591
- end
592
-
593
- if potentential_values.length > 1
594
- unless potentential_values.collect {|y| y.write}.uniq.length == 1
595
- raise StandardError.new('There is more than one possible value for this('+global_id.to_s+') - it is ok if there the same')
596
- end
597
- end
598
- return potentential_values[0]
599
-
600
- end
601
-
602
- # Replaces the current chain with the values specified
603
- #
604
- def create!(n,m,instance_ids,v=[])
605
- @nodes, @chain_mapping, @uniq_theory_instance_ids, @values = n,m,instance_ids,v
606
- # TODO I need to check there won't be a problem with @uniq_theory_instance_ids
607
- return self
608
- end
609
-
610
- def nodes=(obj)
611
- @nodes = obj
612
- end
613
-
614
- # TODO This could probably be replaced by the normal add_link_to method
615
- def add_tail(theory,value_mapping={})
616
- @nodes.push(theory.copy)
617
- end
618
-
619
- # Returns the global id of the variable given the theory id and the variable
620
- # id.
621
- #
622
- def to_global_id(global_mapping,theory_id,theory_variable_id)
623
- global_id = global_mapping.find_global(theory_id,theory_variable_id)
624
- if global_id.nil?
625
- raise StandardError.new('Unable to find global id for theory '+theory_id.to_s+' theory_variable_id: '+theory_variable_id.to_s)
626
- end
627
- return global_id
628
- end
629
-
630
- # NOTE: The :tail isn't a real link, the last link just matches the :tail settings
631
- def link_to_tail(theory)
632
-
633
- # * Find the dependent(s) that connect to the finish
634
- linking_results = theory.select_result_structure(@tail)
635
- raise StandardError.new('Only expecting the theory to have one result that matches the finish') unless linking_results.length == 1
636
- if linking_results.empty?
637
- StandardLogger.instance.warning "this theory does not link to the tail"
638
- return
639
- end
640
- linking_result = linking_results.first
641
- end
642
-
643
- # Returns a new theory mapping that replace the theories local ids with global
644
- # ids.
645
- #
646
- def generate_theory_mapping(theory_id)
647
- mapping = Mapping.new
648
- @chain_mapping.mapping.each do |key,value|
649
- if value[theory_id]
650
- mapping[value[theory_id]] = TheoryVariable.new(key)
651
- end
652
- end
653
- return mapping
654
- end
655
-
656
- # Returns true if the dependents of all the theories have been me. It
657
- # does this by starting from the last link in the chain(the one cloest to
658
- # the tail) and goes through each of it's dependents. It searches up the
659
- # the chain until it finds a result that matches.
660
- #
661
- # Check that all the dependents have been connected to a result component
662
- #
663
- # NOTE: This should only be ran on unfied chains.
664
- #
665
- def dependents_met?
666
- collection = TheoryCollection.new(@nodes)
667
- return collection.dependents.all? do |dependent|
668
- @chain_mapping.connected_component_ids.include?(dependent.theory_component_id)
669
- end
670
- end
671
-
672
- # Start from the back of the chain and work backwards to the head.
673
- #
674
- def dependent_met?(dependent,chain)
675
- chain.reverse.each do |theory|
676
- theory.results.each do |result|
677
- return true if result.write == dependent.write
678
- end
679
- end
680
- return false
681
- end
682
-
683
- # Goes up through each theory in the chain from the position
684
- # specifies and yeilds any unment dependents or results and the
685
- # theory it belongs to.
686
- #
687
- # @param approach Either :depndents or :results
688
- #
689
- def each_unmet(approach,position,nodes)
690
- # TODO Need to exclude theories that use the immediate runtime method
691
- index = 0
692
- comp_ids = @chain_mapping.connected_component_ids
693
- nodes.each do |theory|
694
- unmets = theory.send(approach).select do |x|
695
- !comp_ids.include?(x.theory_component_id)
696
- end
697
- unmets.each {|x| yield index, theory, x}
698
- index += 1
699
- end
700
- end
701
-
702
- def each_result(position,nodes)
703
- index = 0
704
- nodes.each do |theory|
705
- theory.results.each {|x| yield index, theory, x}
706
- index += 1
707
- end
708
- end
709
-
710
- # Removes any results from the head that aren't needed to meet
711
- # the dependents of the supplied theories.
712
- #
713
- # NOTE This method is only really needed while the head is so large
714
- # as development continue I don't think this call will be needed.(26/04/2011)
715
- #
716
- def remove_superfluous_head_results!(theories)
717
- theory_dependents = theories.inject([]) {|total,x| total += x.dependents}
718
- new_results = []
719
- @nodes.first.results.each do |r|
720
- if theory_dependents.any? {|x| r.same_structure?(x)}
721
- new_results.push(r)
722
- end
723
- end
724
- @nodes.first.results = new_results
725
- end
726
-
727
- # Retruns true if all the dependents,and subsequent dependents of
728
- # the theory can be met otherwise it returns false.
729
- #
730
- def dependency_tree_met?(theory,theories,pending_theories=[])
731
-
732
- return theory.dependents.all? {|d| dependent_can_be_met?(d,theories,pending_theories+[theory.copy])}
733
-
734
- # Finish if the theory is already in pending theories or has no dependents.
735
- end
736
-
737
- def dependent_can_be_met?(dependent,theories,pending_theories=[])
738
-
739
- # Try to find theories thats result meets this dependent
740
- theory_collection = TheoryCollection.new(theories.copy)
741
- theory_collection.each_with_result_structure(dependent) do |theory,result|
742
-
743
- # Check whether the matching theory is in pending theories
744
- # (it is already being checked otherwise)
745
- if pending_theories.any? {|x| x.theory_id == theory.theory_id}
746
- return true
747
- end
748
-
749
- #return dependency_tree_met?(theory,theories,pending_theories+[theory.copy])
750
- return dependency_tree_met?(theory,theories,pending_theories+[theory.copy])
751
-
752
- end
753
- StandardLogger.instance.warning '* failed to find a theory with a result to dependent: '
754
- StandardLogger.instance.warning dependent.describe
755
- return false
756
- end
757
-
758
- private
759
-
760
- # Itterates through a progressive extending chain also returning
761
- # the theory that has just been added to the chain.
762
- #
763
- def progressive_chain
764
- return @nodes.length.times do |i|
765
- copied_chain = self.copy
766
- copied_chain.nodes = @nodes[0..i]
767
- yield copied_chain, @nodes[i].copy
768
- end
769
- end
770
-
771
- end