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,29 +0,0 @@
1
- # TODO I think this class is pretty pointless - I should try and drop it
2
- class ParametersContainer < Array
3
-
4
- # TODO Should this be able to write parameters?
5
-
6
- def initialize(*params)
7
- super()
8
- params.each do |x|
9
- self.push(x)
10
- end
11
- end
12
-
13
- def variables
14
- return self
15
- end
16
-
17
- def each_variable
18
- self.each do |x|
19
- yield x
20
- end
21
- end
22
-
23
- # Creates a duplicate of this parameters container.
24
- #
25
- def copy
26
- return ParametersContainer.new(*self.collect {|x| x.copy})
27
- end
28
-
29
- end
@@ -1,94 +0,0 @@
1
- class RealisedRuntimeMethod < StatementGroup
2
- include ActsAsRuntimeMethod
3
-
4
- attr_reader :method_id
5
- attr_writer :method_id
6
-
7
- def initialize(x,*statements)
8
- @open = true
9
- @parameters = x
10
- super(*statements)
11
- end
12
-
13
- def push(statement)
14
- raise StandardError.new('This realised method has been closed') unless @open
15
- super(statement)
16
- end
17
-
18
- def close
19
- @open = false
20
- end
21
-
22
- def cauldron_method_calls
23
- return ['.params']
24
- end
25
-
26
- def write
27
- return MethodWriter.new.write(
28
- @parameters,
29
- self.collect {|x| x.copy}
30
- )
31
- end
32
-
33
- # [Overwrites] Returns a duplicate of this realised runtime
34
- # method.
35
- #
36
- def copy
37
- #result = self.class.new(@usage.copy,*self.collect {|x| x.copy })
38
- result = self.class.new(@parameters.copy,*self.collect {|x| x.copy })
39
- #result = self.class.new(nil,*self.collect {|x| x.copy })
40
- result.scope_id = scope_id
41
- result.scope = scope
42
- result.statement_level = statement_level
43
- result.close
44
- return result
45
- end
46
-
47
- # TODO I should use ParseTree to get a list of all the methods - I can then use
48
- # that to see what method aren't used and which ones don't have any
49
- # tests.
50
-
51
- # Returns an array of the parameters used in this realised runtime
52
- # method.
53
- #
54
- def params
55
- return @parameters
56
- end
57
-
58
- # Returns an array of all the variables available at the end of the
59
- # method. This is essentially all the variables available on the
60
- # last line. As such the variables scope must be the same as the
61
- # method and it should also take into account if any of the variables
62
- # have been overriden.
63
- #
64
- # @param params A param container instance that contains the necessary parameters for the
65
- # runtime method instance.
66
- # @param additional_methods An array of runtime method instances that may be
67
- # called by this runtime method.
68
- #
69
- def final_variables(additional_methods=[])
70
-
71
- # TODO Params should not be needed for realised runtime methods
72
- # Relise the method - not sure if this strictly nessesary or preferable but I think
73
- # it might be required to identify variables that are overwritten.
74
- relised_method = self.copy
75
-
76
- # Add the passed parameters
77
- results = params.collect {|x| x.copy}
78
-
79
- # Go through each statement that is nested/open etc and find all the declared varibles
80
- # results = parameters.clone
81
- relised_method.each do |x|
82
- next if x.kind_of?(StatementGroup)
83
- begin
84
- results.push(x.declared_variable.copy)
85
- rescue ImproperStatementUsageError => e
86
- # Catch statements don't declare a variable
87
- next
88
- end
89
- end
90
- return results
91
-
92
- end
93
-
94
- end
@@ -1,814 +0,0 @@
1
- # This class represents the code of a method generated at runitme
2
- #
3
- # This a variation on code set that contains usage and a return
4
- # variable. It shouldn't contain any other runtime methods
5
- # since you can't write methods within methods.
6
- #
7
- class RuntimeMethod < StatementGroup
8
- include ActsAsTrackable
9
- include ActsAsRuntimeMethod
10
-
11
- attr_reader :method_id, :method_return, :usage
12
- attr_writer :method_id
13
-
14
-
15
- alias :statement_group_push :array_push
16
-
17
- @@METHOD_ID = 0
18
-
19
- # TODO I'm still not sure how to handle the method usage - a runtime method by default
20
- # doesn't have literal values since it depends what it is like in each case.
21
- #
22
- # @param usage How the method should be used - this usage issue needs re-thought
23
- # for now the only requirement is for usage.length to equal
24
- # parameters.length
25
- # @param method_return The response variable to return or nil if nothing is returned
26
- #
27
- #def initialize(usage,method_return=nil,*statements)
28
- def initialize(usage,method_id=nil,*statements)
29
- super(*statements)
30
-
31
- # Set the method id for the generated method
32
- if method_id.nil?
33
- @@METHOD_ID += 1
34
- method_id = @@METHOD_ID
35
- end
36
- @method_id = method_id
37
-
38
- # Save how the method should be used
39
- @usage = usage
40
- @scope_variables = []
41
-
42
- if method_return.nil? then method_return = NilVariable.new end
43
- @method_return = method_return
44
-
45
- # Set the statement level for runtime method (always - because it is the lowest depth)
46
- @statement_level = 0
47
-
48
- end
49
-
50
- #
51
- def self.reset_global_id
52
- #http://www.zenspider.com/Languages/Ruby/QuickRef.html
53
- unless $".include?('test/unit.rb')
54
- StandardLogger.log 'WARNING: Resetting variable id, this should only be done for tests'
55
- end
56
- @@METHOD_ID = 0
57
- end
58
-
59
- #
60
- def method_id=(id)
61
-
62
- # Only let this method be called from fellow RuntimeMethod classes
63
- # TODO Test this prevents the method_id from being set non runtime method class
64
- unless caller.first.split(':')[0]==__FILE__
65
- raise StandardError.new('Attempting to set method_id')
66
- end
67
- @method_id = id
68
- end
69
-
70
- def reset_ids!
71
- copied_method = copy
72
- copied_method.method_id = '0'
73
- unique_variable_ids = variables.collect {|x| x.variable_id}.uniq
74
- reset_variable_ids = (0...unique_variable_ids.length)
75
- mapping = {}
76
- unique_variable_ids.zip(reset_variable_ids.to_a) do |var_id,reset_id|
77
- mapping[var_id] = reset_id
78
- end
79
-
80
- method_parameters = []
81
- @usage.each do |x|
82
- method_parameters.push(MethodParameter.new(mapping[x.variable_id]))
83
- end
84
- usage = MethodUsage.new(*method_parameters)
85
-
86
- copied_method.usage = usage
87
-
88
- replacement_mapping = {}
89
- mapping.each do |var_id,reset_id|
90
- replacement_mapping[var_id] = Unknown.new(reset_id)
91
- end
92
-
93
- copied_method.each do |statement|
94
- replacement_mapping.each do |var_id,value|
95
- statement.subst_variable!(var_id,value)
96
- end
97
- end
98
-
99
- copied_method
100
- end
101
-
102
- def variables
103
- return @usage
104
- end
105
-
106
- # Returns an array of variables that are available at a particular line
107
- # in the method.
108
- #
109
- # TODO This needs tests written for it especially for nested statements
110
- #
111
- def available_variable_at(params,line=0)
112
- reduced_copy = copy.clear
113
- self.each_with_index do |x,i|
114
- break if i > line
115
- reduced_copy.push x.copy
116
- end
117
- return reduced_copy.available_variables(params)
118
- end
119
-
120
- # NOTE: This doesn't handle the case when there are two unknowns -
121
- # dependent on each other. e.g. 5 = var1+var2
122
- def find_next_unknown(complete_statements,concept)
123
-
124
- # If there are no unknown variables then the concept if fine to use
125
- if concept.unknown_count == 0
126
- complete_statements.push(concept)
127
- return
128
- end
129
-
130
- concept.each_unknown do |unknown|
131
-
132
- # Go through each of the varialbes and see if they could be the unknown
133
- available_variables.each do |var|
134
-
135
- # Attempt to substitute one variable for another
136
- updated_concept = concept.subst(unknown.variable_id,var)
137
- next if updated_concept.nil?
138
-
139
- # Find any further unknown variables in the statement
140
- find_next_unknown(complete_statements,updated_concept)
141
-
142
- end
143
-
144
- # Actually only look for the first unknown
145
- return
146
- end
147
-
148
- end
149
-
150
- # TODO This is temporary
151
- def params
152
- return usage
153
- end
154
-
155
- # Inserts a statement at a particular position within the runtime method. This
156
- # could be at the root of the runtime method or within one of its statement
157
- # groups.
158
- #
159
- def add_statement_at(statement,position)
160
- if position == self.statement_id
161
- push(statement)
162
- return
163
- end
164
- statement_groups = self.select_all {|x| x.kind_of?(StatementGroup) && x.statement_id == position}
165
- unless statement_groups.empty?
166
- statement_groups.first.push(statement)
167
- return
168
- end
169
- raise StandardError.new('The is no statement group with the id '+position.to_s)
170
- end
171
-
172
- # Returns true if all the test cases when run through this runtime
173
- # method return the correct value.
174
- #
175
- def all_pass?(test_cases)
176
- test_cases.each do |x|
177
- result = MethodEvaluation.new.evaluate_method(self.copy,x[:params].collect {|y| y.to_literal})
178
- return false unless result == x[:output]
179
- end
180
- return true
181
- end
182
-
183
- def pass?(test_case)
184
- result = MethodEvaluation.new.evaluate_method(self.copy,test_case[:params].collect {|y| y.to_literal})
185
- return false unless result == test_case[:output]
186
- return true
187
- end
188
-
189
- def push(statement)
190
-
191
- # Confirms that supplied statement is a statement
192
- unless statement.kind_of? Statement or statement.kind_of?(StatementGroup)
193
- raise StandardError.new('Only statements can be included in a runtime method not '+statement.class.to_s)
194
- end
195
-
196
- # Check if the statement creates a new variable - and add it the available variables
197
- if statement.kind_of? DeclarationStatement
198
- @scope_variables.push(statement.declared)
199
-
200
- # The variable in the statement needs to have its requirements updated
201
-
202
- end
203
-
204
- #if statement.kind_of?(StatementGroup)
205
- if statement.class.to_s == 'StatementGroup'
206
- statement.each do |x|
207
- statement_group_push(x)
208
- end
209
- else
210
-
211
- # Adding statement to array
212
- statement_group_push(statement)
213
- end
214
-
215
- end
216
-
217
- #
218
- #
219
- # @param found_variables
220
- # @param statement The statement that contains the solution. It should be
221
- # in the following format:
222
- # return_var = var or return_var = var.<method_call>
223
- # @param rule
224
- #
225
- def build_solution(found_variables,statement,rule)
226
-
227
- # Create the return statement
228
- return_statement = Statement.new
229
- return_statement.push Return.new
230
-
231
- #new_statement = statement.copy
232
-
233
- # Check the statement follows a "x = y" structure
234
- unless statement.assignment? then raise StandardError.new('Statement needs to inlcude an "="') end
235
-
236
- # Check whether any of the variables are unknown
237
- statement.each_unknown do |unknown|
238
-
239
- # Check if any of the unknown variables have been found
240
- #unless found_variables[unknown.variable_id.to_s].nil?
241
- if found_variables.has_key?(unknown.variable_id.to_s)
242
-
243
- # Select the first possible variable id
244
- match_variable_id = found_variables[unknown.variable_id.to_s].first
245
-
246
- # Get the right hand side of the statement
247
- rhs = statement.right_hand_side
248
-
249
- unless rhs.length == 1 then raise StandardError.new('Only expecting one right hand side element') end
250
-
251
- case rhs.first.class.to_s
252
- when 'InstanceCallContainer'
253
-
254
- # Does the subject of the call match?
255
- if found_variables.has_key? rhs.first.subject.variable_id.to_s
256
-
257
- # Replace unknown variable with the known one
258
- variables(rule) do |v|
259
- if v.variable_id == found_variables[rhs.first.subject.variable_id.to_s].first
260
- return_statement.push InstanceCallContainer.new(v.copy,rhs.first.method_call)
261
- return return_statement
262
- end
263
- end
264
- end
265
-
266
- when 'Unknown'
267
-
268
- # Look through the variables
269
- if found_variables.has_key? rhs.first.variable_id.to_s
270
-
271
- variables(rule) do |v|
272
-
273
- if v.variable_id == found_variables[rhs.first.variable_id.to_s].first
274
- return_statement.push v.copy
275
- return return_statement
276
- end
277
-
278
- end
279
-
280
- end
281
-
282
- else
283
- raise StandardError.new('Unexpected class '+rhs.first.class.to_s)
284
- end
285
-
286
- end
287
-
288
- end
289
-
290
- raise StandardError.new('Unable to find variable with matching id')
291
-
292
- end
293
-
294
- # Creates a copy of the method with the same usage and
295
- # statements but a different id. I'm not sure if
296
- # should be using the same id or not.
297
- #
298
- def copy
299
- return Marshal.load(Marshal.dump(self))
300
- # # Create the copied method
301
- # empty_copy = copy_base
302
- # empty_copy.method_id = @method_id
303
- # empty_copy.scope_id = scope_id
304
- # empty_copy.scope = scope
305
- # empty_copy.statement_level = statement_level
306
- # self.each do |statement|
307
- # empty_copy.push(statement.copy)
308
- # end
309
- #
310
- # return empty_copy
311
- end
312
-
313
- # Returns the total number of statements within the method. Note
314
- # This includes the statements within nested statements.
315
- #
316
- def statement_count
317
- return self.inject(0) {|count, x| count += x.statement_count}
318
- end
319
-
320
- # Returns a dupicate method but only with the statements
321
- # up to the line given.
322
- #
323
- def partial_method(line)
324
-
325
- # Create a copy of the base runtime method
326
- x = copy_base
327
-
328
- # Check the length of method
329
- if(line>statement_count) then raise MethodSizeError.new('Attmpting to create partial method larger than actual method - crazy bastard!') end
330
-
331
- # Now add statements up until the line limit has been met
332
- index = 0
333
- limit = Array.new(line)
334
-
335
- while(limit.length>0)
336
- if self[index].kind_of?(Statement)
337
- x.push(self[index].copy)
338
- limit.pop
339
- index += 1
340
- elsif self[index].kind_of?(BlockStatement)
341
- x.push(self[index].partial(limit))
342
- index += 1
343
- else
344
- raise StandardError.new('Unexpected class type '+self[index].class.to_s)
345
- end
346
-
347
- end
348
-
349
- return x
350
- end
351
-
352
- # Returns a duplicate method but without any statements in it
353
- #
354
- def copy_base
355
- copied_method = RuntimeMethod.new(@usage.copy,method_id)
356
- return copied_method
357
- end
358
-
359
- # Adds a new statement to the method that returns a variable
360
- # with the specified id.
361
- #
362
- # @param id The id of the variable that a return statement is being created
363
- # for.
364
- #
365
- def add_return_variable_statement!(id)
366
-
367
- # Find the requested variable
368
- var = contextual_variable(id)
369
-
370
- # Create the return statement and add it
371
- self.push(Statement.new(Return.new,var))
372
-
373
- end
374
-
375
- # Returns a describtion of the method and the variables
376
- # within it.
377
- #
378
- def describe
379
- line = write+"\n"
380
- available_variables.each do |var|
381
- line += var.describe(self)
382
- end
383
- return line
384
- end
385
-
386
- # Searches through each statement and identifies whether they
387
- # override an existing variable or not.
388
- #
389
- def identify_overriding_statements(params)
390
- previously_declared_variables = params.collect {|x| {:variable_id=>x.variable_id} }
391
- self.each do |x|
392
- x.identify_overriding_statements(previously_declared_variables)
393
- end
394
- end
395
-
396
- # Returns a statement that declares the runtime method instance.
397
- # e.g. RuntimeMethod.new(MethodUsage.new,ResponseVariable.new)
398
- #
399
- def declaration_statement
400
- new_runtime_method = ClassMethodCallContainer.new(
401
- RuntimeMethodClass.new,
402
- New.new,
403
- @usage.declaration_statement
404
- )
405
- return Statement.new(new_runtime_method)
406
- end
407
-
408
- # Evaluates the method but includes a return statement for the variable
409
- # thats id is specified.
410
- #
411
- def literal_value_of_var(id,params)
412
-
413
- # Create a copy of the runtime method
414
- copied = self.copy
415
-
416
- # Find a reference to the variable in the method's statements and parameters
417
- var = nil
418
- # TODO Remove all the @parameters
419
- params.each do |param|
420
- var = param if(param.variable_id == id)
421
- end
422
- if var.nil?
423
- copy.each do |statement|
424
- begin
425
- var = statement.find_variable(id)
426
- rescue FailedToFindVariableError
427
- next
428
- end
429
- break
430
- end
431
- end
432
-
433
- if(var.nil?) then raise FailedToFindVariableError.new('Couldn\'t find variable with the id:'+id.to_s) end
434
-
435
- # Create a return statement for the requested variable
436
- copied.push(Statement.new(Return.new,var))
437
-
438
- # Now use the method to determine its value at runtime
439
- result = MethodEvaluation.new.evaluate_method(copied,params)
440
- return result
441
-
442
- end
443
-
444
- # Searches the paramaters for a variable with the specified id
445
- def find_variable_in_parameters(id)
446
- no_var_error = Proc.new { raise FailedToFindVariableError.new('Unable to find variable with the id '+id.to_s) }
447
- return @usage.find(no_var_error){|i| i.variable_id == id}.copy
448
- end
449
-
450
- # Returns an array of statements with a number of method calls
451
- # added to it that are equivalent to the variable specified.
452
- #
453
- # So a number of statements is provided and a say a string variable.
454
- # A number method call is added to each statement where the method
455
- # call will also return a string variable.
456
- #
457
- def replace_statement_element_with_method_calls(statements,variable,available=[])
458
-
459
- updated_statements = []
460
-
461
- if @method_return.meets_requirements?(variable)
462
-
463
- # Find potential method calls and include them as partial statements
464
- callable_combinations(available).each do |x|
465
- statements.each do |y|
466
- copied_statement = y.copy
467
- copied_statement.push(x)
468
- updated_statements.push(copied_statement)
469
- end
470
- end
471
- end
472
- return updated_statements
473
- end
474
-
475
- # Returns an array of def calls given the code elements made
476
- # available.
477
- #
478
- # @param available An array of possible paramaters for the method call
479
- #
480
- def callable_combinations(available=[])
481
-
482
- # Handle the case where the method doesn't require any parameters
483
- if @usage.empty?
484
- return [DefCall.new(@method_return.copy,self.copy)]
485
- end
486
-
487
- # NOTE This assumes that all the paramaters must be populated
488
-
489
- # Go thorugh each usage method variable and construct arranges for each paramater
490
- # So if the method expects two parameters - say a string and a number you might
491
- # have variables.
492
- # A, B
493
- # C, B
494
- arrangements = [[]]
495
- @usage.each do |method_variable|
496
- extended_arrangements = []
497
- arrangements.each do |existing_arrangement|
498
- available.each do |x|
499
- if method_variable.meets_requirements?(x)
500
- arrangement = existing_arrangement.copy
501
- arrangement.push(x)
502
- extended_arrangements.push(arrangement)
503
- end
504
- end
505
- end
506
- arrangements = extended_arrangements.copy
507
- end
508
-
509
- # Convert the arrangements to DefCalls
510
- def_calls = []
511
- arrangements.each do |x|
512
- def_calls.push(DefCall.new(@method_return.copy,self.copy,*x))
513
- end
514
- return def_calls
515
-
516
- end
517
-
518
- # Returns an array of possible statements that contain
519
- # a call to this runtime method.
520
- #
521
- def usage_statements(available=[])
522
- results = []
523
- def_calls = callable_combinations(available)
524
- def_calls.each do |x|
525
- # TODO Unknown variables should be replaced
526
- results.push Statement.new(Var)
527
- end
528
- end
529
-
530
- # Returns the runtime methods as a RuntimeMethodParameter.
531
- #
532
- # @param id The id of the variable to give to the returned method
533
- # variable.
534
- #
535
- def to_var(id=nil,uniq_id=nil)
536
- var = RuntimeMethodParameter.new(self.copy) {{:variable_id => id,:uniq_id=>uniq_id}}
537
- # TODO This means that global variable_id is increamented when it doesn't need to be
538
- var.variable_id = id unless id.nil?
539
- return var
540
- end
541
-
542
- # Returns a history object reflecting how the runtime method
543
- # is processed.
544
- #
545
- # @param params An array of realised variables
546
- # @param additional_methods An array of add
547
- #
548
- def history(params,additional_methods=[])
549
-
550
- # Check the number of parameters to method usage
551
- raise StandardError.new('Incorrect number of parameters') unless params.length == @usage.length
552
-
553
- # Create the method that changes are logged to
554
- instance_tracking_variable = ArrayVariable.new
555
- instance_tracking_variable.instance_variable = true
556
- tracking_method = RuntimeTrackingMethod.new(instance_tracking_variable)
557
-
558
- # Duplicate the current method and add tracking calls
559
- copied = self.copy.trackify(params,tracking_method)
560
-
561
- # Create a method to call the method and return the results
562
- process_method = RuntimeMethod.new(MethodUsage.new)
563
- track_statement = Statement.new( DefCall.new(NilVariable.new,copied,*params.collect {|x| x.value} ) )
564
- process_method << track_statement
565
- return_statement = Statement.new( Return.new,instance_tracking_variable )
566
- process_method << return_statement
567
-
568
- # Evaluate the method
569
- # TODO This might need to have a number pre-fixed (I'm not certain it's overwritten)
570
- # runtime_class = RuntimeClass.new('Temporary'+rand(1000).to_s,tracking_method,copied,process_method,*additional_methods)
571
- runtime_class = RuntimeClass.new('Temporary',tracking_method,copied,process_method,*additional_methods)
572
- result = ClassEvaluation.new.evaluate_class(runtime_class,process_method.method_name)
573
- return result
574
- end
575
-
576
- # Proxy for the history method except it expects to receive an array of literals.
577
- #
578
- # TODO Probably best to change the real history method to use literals
579
- #
580
- def history2(params,additional_methods=[])
581
-
582
- if(params.any? {|x| x.kind_of?(Variable)})
583
- raise StandardError.new('Currently only literal values can be realised')
584
- end
585
-
586
- # TODO Is KnownVariable a better name than LiteralVariable
587
- # Convert the passed paramters into literal variables with the appropriate ids
588
- unless usage.length == params.length
589
- raise StandardError.new('This method expects '+usage.length.to_s+' param(s) but '+params.length.to_s+' were passed')
590
- end
591
- realised_params = []
592
- usage.zip(params).each do |x,y|
593
- realised_params.push y.to_var(x.variable_id,x.uniq_id)
594
- end
595
-
596
- return history(realised_params,methods)
597
- end
598
-
599
- # Returns an updated method that includes a method call
600
- # after each statement to monitor the usage of a runtime method.
601
- #
602
- # @param tracking_method A runtime tracking method instance that the track calls
603
- # saved to.
604
- #
605
- def trackify(params,tracking_method)
606
-
607
- # TODO Really need to give the tracking method parameter proper names - and get them in
608
- # correct order.
609
-
610
- # Identify what statements are overridden to inform what variables need tracked
611
- identify_overriding_statements(params)
612
-
613
- line = []
614
- copied = copy_base
615
- modified_params = params
616
-
617
- # Start by adding the initial tracking call - to catch the parameters
618
- # CONTINUE: tracking the statement_id
619
- initial_tracking_statement = tracking_statement(
620
- tracking_method,
621
- line,
622
- self.statement_id.to_literal,
623
- abstract_variables_for_tracking(modified_params)
624
- )
625
- copied.push(initial_tracking_statement)
626
-
627
- # TODO Currently I am collect all the variables in the variable container -be that
628
- # a nested statement or a single statment. I don't know what variables I
629
- # actually need to retain.
630
-
631
- # Create an array to update the variable ids to suite the method usage
632
- # TODO I'm not sure this is needed any more
633
- id_conversion = Hash.new
634
- @usage.zip(params) do |x,y|
635
- new_var = y.copy
636
- new_var.variable_id = x.variable_id
637
- new_var.uniq_id = x.uniq_id
638
- id_conversion[x.uniq_id.to_s.to_sym] = new_var
639
- end
640
-
641
- # Copy the runtime method and update each statement
642
- copy.each_with_index do |x,i|
643
- if x.kind_of?(Statement)
644
-
645
- # Update the ids of the variables used in the statement to use the ids of the method usage
646
- #duplicated_statement = x.exchange_variables(id_conversion)
647
- duplicated_statement = x.copy
648
- variable_values = abstract_variables_for_tracking(duplicated_statement)
649
- copied.push(duplicated_statement)
650
- copied.push(
651
- tracking_statement(
652
- tracking_method,
653
- line,
654
- duplicated_statement.statement_id,
655
- variable_values,
656
- duplicated_statement
657
- )
658
- )
659
- # TODO I think this has to be a OpenStatement
660
- elsif(x.kind_of?(StatementGroup))
661
-
662
- # Retrieve tha variables available at the point before the nested statement opens
663
- results = []
664
- available_variable_at(params,line.length).each do |y|
665
- # TODO I should change these to symbols
666
- results.push(Hash['id'=>y.variable_id,'value'=>InstanceCallContainer.new(y,Copy.new)])
667
- end
668
-
669
- # Retrieve the nested statement and trackify it
670
- trackifyied_nested_statement = x.trackify(
671
- tracking_method,line
672
- )
673
- copied.push(trackifyied_nested_statement)
674
-
675
- # Add the tracking call for after the statement (this has the id for the whole nested statement)
676
-
677
- # Retrieve the variables used in the nested statement - excluding those no longer in scope
678
- # TODO I should maybe only be concerned with the variables that change in the nested
679
- # statement.
680
- # containers = [x.opening_statement]+x.each
681
-
682
- # Search through the nested statement for all the statements that override a variable
683
- # TODO It really should be all the variables that are overridden and available
684
- # outside the nested statement.
685
- variable_values = abstract_variables_for_tracking(*x.find_overriding_statements)
686
-
687
- # TODO The only variables recorded here are ones that overriden inside the nested statement
688
- copied.push(
689
- tracking_statement(
690
- tracking_method,
691
- line,
692
- self.statement_id,
693
- variable_values,
694
- x
695
- )
696
- )
697
-
698
- # TODO I think I'm going to give nested statements two ids - one outside
699
- # one inside. I might use the internal statment id as one and the
700
- # actual nested statement as the other.
701
- else
702
- raise StandardError.new('Unexpected class '+x.class.to_s)
703
- end
704
-
705
- end
706
- return copied
707
- end
708
-
709
- # Rebuilds the method with TypeVariables that all have literal
710
- # values.
711
- #
712
- # @param params A param container instance that contains the necessary parameters for the
713
- # runtime method instance.
714
- # @param params [UPDATE] This is being changed to except only an array of literal
715
- # values e.g. 'tests', 9, <#SomeObject>. This will be converted into
716
- # a literal variable within the method.
717
- #
718
- # @param additional_methods An array of any methods that are required by the runtime method instance
719
- #
720
- # TODO I expect "params" could probably be changed from a paramaters container to an
721
- # array of literal values.
722
- #
723
- def realise2(params,additional_methods=[])
724
-
725
- # TEMP
726
- if(params.any? {|x| x.kind_of?(Variable)})
727
- raise StandardError.new('Currently only literal values can be realised')
728
- end
729
-
730
- # Convert the passed paramters into literal variables with the appropriate ids
731
- unless usage.length == params.length
732
- raise StandardError.new('This method expects '+usage.length.to_s+' param(s) but '+params.length.to_s+' were passed')
733
- end
734
- realised_params = []
735
- usage.zip(params).each do |x,y|
736
- realised_params.push y.to_var(x.variable_id,x.uniq_id)
737
- end
738
-
739
- # Check that any required runtime methods were supplied
740
- # TODO Given that I can retrieve all the runtime methods from the statements I probably shouldn't
741
- # bother passing them in as parameters to the method.
742
- find_all_required_runtime_methods.each do |x|
743
- missing_method = lambda{raise StandardError.new('Missing method with id '+x.method_id.to_s)}
744
- additional_methods.detect(missing_method) {|y| y.method_id == x.method_id}
745
- end
746
-
747
- # Retrieve a history object reflecting the use of the runtime method
748
- past = history(realised_params,additional_methods)
749
-
750
- # Create a realised method instance to return
751
- realised_runtime_method = RealisedRuntimeMethod.new(realised_params)
752
- realised_runtime_method.method_id = @method_id
753
-
754
- # Go through each statement and substitue any of the variables
755
- # for those in the history object
756
- self.each do |x|
757
-
758
- if x.realised?
759
- realised_runtime_method.push(x)
760
- next
761
- end
762
-
763
- # Handle nested and single statements differently
764
- if(x.kind_of?(Statement))
765
- realised_statement = x.realise2(past)
766
- realised_runtime_method.push(realised_statement)
767
- elsif(x.kind_of?(BlockStatement))
768
-
769
- # TODO - TEMP DEBUG
770
- instance_tracking_variable = ArrayVariable.new
771
- instance_tracking_variable.instance_variable = true
772
- tracking_method = RuntimeTrackingMethod.new(instance_tracking_variable)
773
-
774
- #resulting_method.push(x.realise2(past))
775
- realised_runtime_method.push(x.realise2(past))
776
-
777
- # TODO I have just added this ---------------------08/02/2011 - I really need to go through the whole
778
- # tracking thing.
779
- elsif(x.kind_of?(OpenStatement))
780
-
781
- # TODO - TEMP DEBUG
782
- instance_tracking_variable = ArrayVariable.new
783
- instance_tracking_variable.instance_variable = true
784
- tracking_method = RuntimeTrackingMethod.new(instance_tracking_variable)
785
-
786
- #resulting_method.push(x.realise2(past))
787
- realised_runtime_method.push(x.realise2(past))
788
-
789
- else
790
- raise StandardError.new('Unexpected data type '+x.class.to_s)
791
- end
792
-
793
- end
794
-
795
- realised_runtime_method.close
796
- return realised_runtime_method
797
-
798
- end
799
-
800
- def cauldron_method_calls
801
- return ['.all_pass?','.pass?','.history2','.last','.statement_id','.params','.realise2']
802
- end
803
-
804
- def to_intrinsic
805
- return IntrinsicRuntimeMethod.new()
806
- end
807
-
808
- protected
809
-
810
- def usage=(usage)
811
- @usage = usage
812
- end
813
-
814
- end