cauldron 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +51 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +16 -3
- data/Rakefile +94 -92
- data/VERSION +1 -1
- data/bin/cauldron +2 -2
- data/cauldron.gemspec +15 -451
- data/features/cauldron_new_approach.feature +46 -0
- data/features/step_definitions/cauldron_steps.rb +11 -0
- data/features/step_definitions/terminal_steps.rb +0 -2
- data/features/support/env.rb +11 -1
- data/features/support/hooks.rb +5 -0
- data/lib/cauldron.rb +13 -7
- data/lib/cauldron/array_reverse_operator.rb +39 -0
- data/lib/cauldron/concat_operator.rb +34 -0
- data/lib/cauldron/if_relationship.rb +37 -0
- data/lib/cauldron/numeric_operator.rb +45 -0
- data/lib/cauldron/pot.rb +54 -162
- data/lib/cauldron/relationship.rb +5 -0
- data/lib/cauldron/terminal.rb +4 -60
- data/lib/cauldron/version.rb +3 -0
- data/lib/core/string.rb +21 -0
- data/sandbox.rb +27 -6
- data/spec/cauldron/array_reverse_operator_spec.rb +59 -0
- data/spec/cauldron/concat_operator_spec.rb +89 -0
- data/spec/cauldron/if_relationship_spec.rb +25 -0
- data/spec/cauldron/numeric_operator_spec.rb +70 -0
- data/spec/cauldron/pot_spec.rb +81 -151
- data/spec/cauldron/terminal_spec.rb +1 -39
- data/spec/examples/adding_if_statement.yml +13 -0
- data/spec/examples/simple_head_theory.txt +13 -0
- data/spec/spec_helper.rb +1 -14
- data/tasks/theory_tasks.rake +207 -207
- metadata +92 -532
- data/cauldron/.autotest +0 -23
- data/cauldron/History.txt +0 -6
- data/cauldron/Manifest.txt +0 -8
- data/cauldron/README.txt +0 -57
- data/cauldron/Rakefile +0 -27
- data/cauldron/bin/cauldron +0 -3
- data/cauldron/lib/cauldron.rb +0 -3
- data/cauldron/test/test_cauldron.rb +0 -8
- data/features/cauldron_example_cases.feature +0 -13
- data/features/cauldron_generates_runtime_method.feature +0 -16
- data/features/cauldron_generates_single_paramter_methods.feature +0 -25
- data/features/cauldron_interactive_start_terminal.feature +0 -17
- data/features/cauldron_quit_terminal.feature +0 -9
- data/features/cauldron_start_terminal.feature +0 -12
- data/features/support/method_1.example +0 -3
- data/features/support/method_2.example +0 -6
- data/lib/Chain.rb +0 -771
- data/lib/ChainMapping.rb +0 -172
- data/lib/CodeHandler.rb +0 -513
- data/lib/Mapping.rb +0 -27
- data/lib/MappingValues.rb +0 -24
- data/lib/PartialChain.rb +0 -253
- data/lib/Theory.rb +0 -295
- data/lib/UnifiedChain.rb +0 -351
- data/lib/cauldron/conversion.rb +0 -15
- data/lib/cauldron/demos.rb +0 -280
- data/lib/cauldron/env.rb +0 -1
- data/lib/cauldron/sexp2cauldron.rb +0 -139
- data/lib/cauldron/theory_factory.rb +0 -10
- data/lib/cauldron/util/home.rb +0 -21
- data/lib/cauldron/util/saver.rb +0 -45
- data/lib/core/ActsAsCode.rb +0 -25
- data/lib/core/BlockToken.rb +0 -33
- data/lib/core/CCall.rb +0 -7
- data/lib/core/CTestCase.rb +0 -27
- data/lib/core/ClassMethodCallContainer.rb +0 -58
- data/lib/core/Container.rb +0 -95
- data/lib/core/InstanceCallContainer.rb +0 -298
- data/lib/core/MethodUsage.rb +0 -65
- data/lib/core/PrintVariables.rb +0 -25
- data/lib/core/TheoryGenerator.rb +0 -753
- data/lib/core/Token.rb +0 -7
- data/lib/core/assignment/Assignment.rb +0 -18
- data/lib/core/assignment/Equal.rb +0 -39
- data/lib/core/assignment/Equivalent.rb +0 -20
- data/lib/core/assignment/NotEqual.rb +0 -14
- data/lib/core/call_container/CallContainer.rb +0 -72
- data/lib/core/class_method_call/New.rb +0 -15
- data/lib/core/class_method_call/RuntimeClassMethodCall.rb +0 -31
- data/lib/core/declaration/Declaration.rb +0 -16
- data/lib/core/declaration/LiteralDeclaration.rb +0 -47
- data/lib/core/declaration/VariableDeclaration.rb +0 -59
- data/lib/core/instance_call/ArrayEach.rb +0 -23
- data/lib/core/instance_call/ArrayLength.rb +0 -15
- data/lib/core/instance_call/Chop.rb +0 -19
- data/lib/core/instance_call/Copy.rb +0 -22
- data/lib/core/instance_call/DeclaredVariable.rb +0 -18
- data/lib/core/instance_call/InstanceCall.rb +0 -77
- data/lib/core/instance_call/Params.rb +0 -15
- data/lib/core/instance_call/Push.rb +0 -20
- data/lib/core/instance_call/StringLength.rb +0 -32
- data/lib/core/instance_call/Times.rb +0 -20
- data/lib/core/instance_call/instance_calls.rb +0 -176
- data/lib/core/instance_call/length_equal.rb +0 -15
- data/lib/core/kernal/EvalCall.rb +0 -15
- data/lib/core/kernal/LocalVariablesCall.rb +0 -15
- data/lib/core/literal/Literal.rb +0 -111
- data/lib/core/literal/Raw.rb +0 -23
- data/lib/core/literal/RuntimeMethodLiteral.rb +0 -21
- data/lib/core/literal/StatementLiteral.rb +0 -28
- data/lib/core/method_call/AvailableVariablesCall.rb +0 -25
- data/lib/core/method_call/ClassCall.rb +0 -33
- data/lib/core/method_call/DefCall.rb +0 -72
- data/lib/core/method_call/EvaluateClassCall.rb +0 -29
- data/lib/core/method_call/MethodNameCall.rb +0 -27
- data/lib/core/method_call/ToDeclarationCall.rb +0 -15
- data/lib/core/requirement/Requirement.rb +0 -292
- data/lib/core/runtime_class/ArrayClass.rb +0 -19
- data/lib/core/runtime_class/ClassCallClass.rb +0 -23
- data/lib/core/runtime_class/ClassEvaluationClass.rb +0 -19
- data/lib/core/runtime_class/ClassName.rb +0 -18
- data/lib/core/runtime_class/DefCallClass.rb +0 -21
- data/lib/core/runtime_class/EqualClass.rb +0 -19
- data/lib/core/runtime_class/FixnumClass.rb +0 -15
- data/lib/core/runtime_class/InstanceCallClass.rb +0 -19
- data/lib/core/runtime_class/InstanceCallContainerClass.rb +0 -16
- data/lib/core/runtime_class/InstanceClassCallClass.rb +0 -19
- data/lib/core/runtime_class/LiteralClass.rb +0 -19
- data/lib/core/runtime_class/MethodParameterClass.rb +0 -27
- data/lib/core/runtime_class/MethodUsageClass.rb +0 -27
- data/lib/core/runtime_class/RequirementClass.rb +0 -19
- data/lib/core/runtime_class/ReturnClass.rb +0 -21
- data/lib/core/runtime_class/RuntimeClass.rb +0 -30
- data/lib/core/runtime_class/RuntimeClassClass.rb +0 -19
- data/lib/core/runtime_class/RuntimeMethodClass.rb +0 -34
- data/lib/core/runtime_class/StatementClass.rb +0 -53
- data/lib/core/runtime_class/StringClass.rb +0 -23
- data/lib/core/runtime_class/StringLengthClass.rb +0 -19
- data/lib/core/runtime_class/StringVariableClass.rb +0 -19
- data/lib/core/runtime_class/ThisClass.rb +0 -15
- data/lib/core/runtime_class/UnknownClass.rb +0 -23
- data/lib/core/runtime_class/class_names.rb +0 -95
- data/lib/core/runtime_class/runtime_class.rb +0 -123
- data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +0 -293
- data/lib/core/runtime_method/ParametersContainer.rb +0 -29
- data/lib/core/runtime_method/RealisedRuntimeMethod.rb +0 -94
- data/lib/core/runtime_method/RuntimeMethod.rb +0 -814
- data/lib/core/runtime_method/WriteParameters.rb +0 -35
- data/lib/core/statement/ActsAsStatement.rb +0 -20
- data/lib/core/statement/ArrayAccess.rb +0 -122
- data/lib/core/statement/BlockStatement.rb +0 -348
- data/lib/core/statement/DeclarationStatement.rb +0 -19
- data/lib/core/statement/HackStatement.rb +0 -25
- data/lib/core/statement/HashAccess.rb +0 -18
- data/lib/core/statement/OpenStatement.rb +0 -178
- data/lib/core/statement/RealisedStatement.rb +0 -5
- data/lib/core/statement/SingleLineBlockStatement.rb +0 -39
- data/lib/core/statement/Statement.rb +0 -1091
- data/lib/core/statement/StatementGroup.rb +0 -157
- data/lib/core/statement/StatementStructure2.rb +0 -224
- data/lib/core/statement/TheoryStatement.rb +0 -68
- data/lib/core/statement/TopologicalStatements.rb +0 -34
- data/lib/core/syntax/Addition.rb +0 -26
- data/lib/core/syntax/BlockContainer.rb +0 -102
- data/lib/core/syntax/Boolean.rb +0 -15
- data/lib/core/syntax/Code.rb +0 -11
- data/lib/core/syntax/Do.rb +0 -20
- data/lib/core/syntax/False.rb +0 -12
- data/lib/core/syntax/If.rb +0 -36
- data/lib/core/syntax/Nil.rb +0 -15
- data/lib/core/syntax/Return.rb +0 -33
- data/lib/core/syntax/Subtract.rb +0 -19
- data/lib/core/syntax/This.rb +0 -40
- data/lib/core/syntax/True.rb +0 -20
- data/lib/core/syntax/syntax.rb +0 -24
- data/lib/core/tracking/ActsAsTrackable.rb +0 -65
- data/lib/core/tracking/History.rb +0 -167
- data/lib/core/tracking/RuntimeTrackingMethod.rb +0 -32
- data/lib/core/tracking/Step.rb +0 -52
- data/lib/core/variable/ArrayVariable.rb +0 -76
- data/lib/core/variable/BaseVariable.rb +0 -152
- data/lib/core/variable/BlockVariable.rb +0 -92
- data/lib/core/variable/FixnumVariable.rb +0 -35
- data/lib/core/variable/HistoryVariable.rb +0 -8
- data/lib/core/variable/MethodParameter.rb +0 -179
- data/lib/core/variable/MethodUsageVariable.rb +0 -60
- data/lib/core/variable/NilVariable.rb +0 -29
- data/lib/core/variable/RuntimeMethodParameter.rb +0 -67
- data/lib/core/variable/StatementVariable.rb +0 -72
- data/lib/core/variable/StepVariable.rb +0 -7
- data/lib/core/variable/StringVariable.rb +0 -46
- data/lib/core/variable/TypeVariable.rb +0 -72
- data/lib/core/variable/Unknown.rb +0 -102
- data/lib/core/variable/UnknownVariable.rb +0 -29
- data/lib/core/variable/Variable.rb +0 -70
- data/lib/core/variable/VariableContainer.rb +0 -28
- data/lib/core/variable/VariableIncluded.rb +0 -27
- data/lib/core/variable/VariableReference.rb +0 -85
- data/lib/error/FailedToFindStatementContainerError.rb +0 -7
- data/lib/error/FailedToFindStatementError.rb +0 -7
- data/lib/error/FailedToFindVariableError.rb +0 -7
- data/lib/error/FailedToLiteraliseError.rb +0 -7
- data/lib/error/FailedVariableMatch.rb +0 -7
- data/lib/error/ImproperStatementUsageError.rb +0 -7
- data/lib/error/IncompatiableRequirementsError.rb +0 -7
- data/lib/error/InvalidStatementError.rb +0 -7
- data/lib/error/MethodSizeError.rb +0 -7
- data/lib/error/RuntimeSyntaxError.rb +0 -7
- data/lib/error/UnexpectedStatementTypeError.rb +0 -7
- data/lib/error/UnknownStatementType.rb +0 -7
- data/lib/error/UnliteralisableError.rb +0 -7
- data/lib/implemented_chain.rb +0 -35
- data/lib/intrinsic/IntrinsicLastRuntimeMethod.rb +0 -20
- data/lib/intrinsic/IntrinsicLiteral.rb +0 -26
- data/lib/intrinsic/IntrinsicObject.rb +0 -22
- data/lib/intrinsic/IntrinsicRuntimeMethod.rb +0 -27
- data/lib/intrinsic/IntrinsicTestCases.rb +0 -17
- data/lib/logger/StandardLogger.rb +0 -62
- data/lib/required.rb +0 -222
- data/lib/ruby_code/Array.rb +0 -95
- data/lib/ruby_code/Fixnum.rb +0 -39
- data/lib/ruby_code/Hash.rb +0 -25
- data/lib/ruby_code/NilClass.rb +0 -19
- data/lib/ruby_code/Object.rb +0 -24
- data/lib/ruby_code/String.rb +0 -63
- data/lib/ruby_code/Symbol.rb +0 -7
- data/lib/standard_library/Tasks.rb +0 -12
- data/lib/theories.rb +0 -166
- data/lib/theory/ActionImplementation.rb +0 -17
- data/lib/theory/TheoryAction.rb +0 -100
- data/lib/theory/TheoryChainValidator.rb +0 -103
- data/lib/theory/TheoryComponent.rb +0 -59
- data/lib/theory/TheoryConnector.rb +0 -756
- data/lib/theory/TheoryDependent.rb +0 -135
- data/lib/theory/TheoryImplementation.rb +0 -75
- data/lib/theory/TheoryResult.rb +0 -131
- data/lib/theory/TheoryVariable.rb +0 -63
- data/lib/theory/theory_collection.rb +0 -62
- data/lib/util/ClassEvaluation.rb +0 -44
- data/lib/util/CodeEvaluation.rb +0 -39
- data/lib/util/DeclarationStatementEvaluation.rb +0 -32
- data/lib/util/MethodEvaluation.rb +0 -49
- data/lib/util/MethodTester.rb +0 -71
- data/lib/util/MethodValidation.rb +0 -149
- data/lib/util/MethodWriter.rb +0 -66
- data/lib/util/Parser.rb +0 -305
- data/lib/util/StatementCheck.rb +0 -44
- data/lib/util/StringToTheory.rb +0 -142
- data/lib/util/System.rb +0 -8
- data/spec/cauldron/chain_spec.rb +0 -24
- data/spec/cauldron/demos_spec.rb +0 -30
- data/spec/cauldron/runtime_method_spec.rb +0 -92
- data/spec/cauldron/saver_spec.rb +0 -45
- data/spec/cauldron/sexp_2_cauldron_spec.rb +0 -118
- data/spec/cauldron/theory_action_spec.rb +0 -25
- data/spec/cauldron/theory_connector_spec.rb +0 -52
- data/spec/cauldron/theory_spec.rb +0 -59
- data/spec/cauldron/unified_chain_spec.rb +0 -140
- data/test/fixtures/chains/1/declaration.txt +0 -26
- data/test/fixtures/chains/1/dump +0 -0
- data/test/fixtures/chains/2/declaration.txt +0 -26
- data/test/fixtures/chains/2/dump +0 -0
- data/test/fixtures/chains/3/declaration.txt +0 -26
- data/test/fixtures/chains/3/dump +0 -0
- data/test/fixtures/implementation_results/0/declaration.txt +0 -3
- data/test/fixtures/implementation_results/0/dump +0 -0
- data/test/fixtures/theories/0/declaration.txt +0 -9
- data/test/fixtures/theories/0/desc +0 -10
- data/test/fixtures/theories/0/dump +0 -0
- data/test/fixtures/theories/1/declaration.txt +0 -15
- data/test/fixtures/theories/1/desc +0 -11
- data/test/fixtures/theories/1/dump +0 -0
- data/test/fixtures/theories/10/declaration.txt +0 -23
- data/test/fixtures/theories/10/desc +0 -17
- data/test/fixtures/theories/10/dump +0 -0
- data/test/fixtures/theories/11/declaration.txt +0 -20
- data/test/fixtures/theories/11/desc +0 -14
- data/test/fixtures/theories/11/dump +0 -0
- data/test/fixtures/theories/12/declaration.txt +0 -18
- data/test/fixtures/theories/12/desc +0 -12
- data/test/fixtures/theories/12/dump +0 -0
- data/test/fixtures/theories/13/declaration.txt +0 -24
- data/test/fixtures/theories/13/desc +0 -20
- data/test/fixtures/theories/13/dump +0 -0
- data/test/fixtures/theories/14/declaration.txt +0 -26
- data/test/fixtures/theories/14/desc +0 -20
- data/test/fixtures/theories/14/dump +0 -0
- data/test/fixtures/theories/15/declaration.txt +0 -20
- data/test/fixtures/theories/15/desc +0 -14
- data/test/fixtures/theories/15/dump +0 -0
- data/test/fixtures/theories/16/declaration.txt +0 -30
- data/test/fixtures/theories/16/desc +0 -14
- data/test/fixtures/theories/16/dump +0 -0
- data/test/fixtures/theories/17/declaration.txt +0 -25
- data/test/fixtures/theories/17/desc +0 -11
- data/test/fixtures/theories/17/dump +0 -0
- data/test/fixtures/theories/18/declaration.txt +0 -23
- data/test/fixtures/theories/18/desc +0 -11
- data/test/fixtures/theories/18/dump +0 -0
- data/test/fixtures/theories/19/declaration.txt +0 -23
- data/test/fixtures/theories/19/desc +0 -11
- data/test/fixtures/theories/19/dump +0 -0
- data/test/fixtures/theories/2/declaration.txt +0 -12
- data/test/fixtures/theories/2/desc +0 -10
- data/test/fixtures/theories/2/dump +0 -0
- data/test/fixtures/theories/20/declaration.txt +0 -23
- data/test/fixtures/theories/20/desc +0 -17
- data/test/fixtures/theories/20/dump +0 -0
- data/test/fixtures/theories/3/declaration.txt +0 -19
- data/test/fixtures/theories/3/desc +0 -11
- data/test/fixtures/theories/3/dump +0 -0
- data/test/fixtures/theories/4/declaration.txt +0 -11
- data/test/fixtures/theories/4/desc +0 -11
- data/test/fixtures/theories/4/dump +0 -0
- data/test/fixtures/theories/5/declaration.txt +0 -6
- data/test/fixtures/theories/5/desc +0 -9
- data/test/fixtures/theories/5/dump +0 -0
- data/test/fixtures/theories/6/declaration.txt +0 -13
- data/test/fixtures/theories/6/desc +0 -11
- data/test/fixtures/theories/6/dump +0 -0
- data/test/fixtures/theories/7/declaration.txt +0 -19
- data/test/fixtures/theories/7/desc +0 -11
- data/test/fixtures/theories/7/dump +0 -0
- data/test/fixtures/theories/8/declaration.txt +0 -21
- data/test/fixtures/theories/8/desc +0 -11
- data/test/fixtures/theories/8/dump +0 -0
- data/test/fixtures/theories/9/declaration.txt +0 -24
- data/test/fixtures/theories/9/desc +0 -20
- data/test/fixtures/theories/9/dump +0 -0
- data/test/fixtures/theory_implementations/0/declaration.txt +0 -11
- data/test/fixtures/theory_implementations/0/desc.txt +0 -9
- data/test/fixtures/theory_implementations/0/dump +0 -0
- data/test/fixtures/theory_implementations/0/theory_id +0 -1
- data/test/fixtures/theory_implementations/1/declaration.txt +0 -11
- data/test/fixtures/theory_implementations/1/desc.txt +0 -9
- data/test/fixtures/theory_implementations/1/dump +0 -1
- data/test/fixtures/theory_implementations/1/theory_id +0 -1
- data/test/fixtures/theory_implementations/2/declaration.txt +0 -11
- data/test/fixtures/theory_implementations/2/desc.txt +0 -9
- data/test/fixtures/theory_implementations/2/dump +0 -0
- data/test/fixtures/theory_implementations/2/theory_id +0 -1
- data/test/output/simple_method.txt +0 -5
- data/test/output/test_method/first_possible_method.txt +0 -6
- data/test/output/test_simple_cases/simple_case_01.txt +0 -8
- data/test/output/test_simple_cases/simple_case_02.txt +0 -7
- data/test/output/test_simple_cases/simple_case_03.txt +0 -8
- data/test/output/test_simple_cases/simple_case_04.txt +0 -8
- data/test/output/test_simple_cases/simple_case_05.txt +0 -8
- data/test/output/test_simple_cases/simple_case_06.txt +0 -9
- data/test/output/test_simple_cases/simple_case_07.txt +0 -9
- data/test/output/test_simple_cases/simple_case_08.txt +0 -9
- data/test/tc_describe.rb +0 -46
- data/test/tc_method.rb +0 -130
- data/test/tc_requirement.rb +0 -30
- data/test/tc_suite_complete.rb +0 -26
- data/test/tc_variable.rb +0 -52
- data/test/ts_complete.rb +0 -74
- data/test/ts_stable.rb +0 -81
- data/test/unit/core/declaration/tc_literal_declaration.rb +0 -34
- data/test/unit/core/method_call/tc_class_call.rb +0 -20
- data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +0 -132
- data/test/unit/core/runtime_method/tc_runtime_method.rb +0 -546
- data/test/unit/core/statement/tc_array_access.rb +0 -63
- data/test/unit/core/statement/tc_block_statement.rb +0 -53
- data/test/unit/core/statement/tc_hack_statement.rb +0 -26
- data/test/unit/core/statement/tc_open_statement.rb +0 -79
- data/test/unit/core/statement/tc_statement.rb +0 -483
- data/test/unit/core/statement/tc_statement_group.rb +0 -35
- data/test/unit/core/statement/tc_statement_replace_variable.rb +0 -61
- data/test/unit/core/statement/tc_theory_statement.rb +0 -53
- data/test/unit/core/syntax/tc_block_container.rb +0 -32
- data/test/unit/core/syntax/tc_if_container.rb +0 -39
- data/test/unit/core/tc_class_method_call.rb +0 -34
- data/test/unit/core/tc_container.rb +0 -41
- data/test/unit/core/tc_ctest_case.rb +0 -25
- data/test/unit/core/tc_instance_call_container.rb +0 -93
- data/test/unit/core/tc_literal.rb +0 -30
- data/test/unit/core/tc_theory_generator.rb +0 -336
- data/test/unit/core/tc_theory_generator_heavy.rb +0 -42
- data/test/unit/core/tracking/tc_history.rb +0 -104
- data/test/unit/core/tracking/tc_step.rb +0 -65
- data/test/unit/core/variable/tc_array_variable.rb +0 -61
- data/test/unit/core/variable/tc_block_variable.rb +0 -17
- data/test/unit/core/variable/tc_fixnum_variable.rb +0 -54
- data/test/unit/core/variable/tc_method_parameter_variable.rb +0 -22
- data/test/unit/core/variable/tc_runtime_method_variable.rb +0 -32
- data/test/unit/core/variable/tc_string_variable.rb +0 -37
- data/test/unit/core/variable/tc_unknown.rb +0 -24
- data/test/unit/core/variable/tc_variable_reference.rb +0 -28
- data/test/unit/ruby_code/tc_array.rb +0 -64
- data/test/unit/ruby_code/tc_fixnum.rb +0 -18
- data/test/unit/ruby_code/tc_hash.rb +0 -41
- data/test/unit/ruby_code/tc_string.rb +0 -38
- data/test/unit/tc_chain.rb +0 -434
- data/test/unit/tc_chain_mapping.rb +0 -62
- data/test/unit/tc_chain_with_case_1.rb +0 -169
- data/test/unit/tc_instance_call.rb +0 -40
- data/test/unit/tc_method_usage.rb +0 -35
- data/test/unit/tc_pot.rb +0 -124
- data/test/unit/tc_runtime_tracking_method.rb +0 -40
- data/test/unit/tc_theory.rb +0 -531
- data/test/unit/tc_variable_declaration.rb +0 -32
- data/test/unit/theory/tc_theory_action.rb +0 -108
- data/test/unit/theory/tc_theory_action_implementation.rb +0 -23
- data/test/unit/theory/tc_theory_chain_validator.rb +0 -340
- data/test/unit/theory/tc_theory_connector.rb +0 -361
- data/test/unit/theory/tc_theory_dependent.rb +0 -153
- data/test/unit/theory/tc_theory_implementation.rb +0 -137
- data/test/unit/theory/tc_theory_result.rb +0 -112
- data/test/unit/theory/tc_theory_variable.rb +0 -45
- data/test/unit/util/tc_method_validation.rb +0 -101
- data/test/unit/util/tc_parser.rb +0 -110
- data/test/unit/util/tc_string_to_theory.rb +0 -300
- data/test/unit/variable/tc_method_usage_variable.rb +0 -25
- data/tmp/runtime_method_evaluation.rb +0 -16
data/lib/ChainMapping.rb
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
# note about the global mapping=>
|
2
|
-
#
|
3
|
-
# This method needs to map the theory variables used in one theory to the
|
4
|
-
# rest. This basically means there is a global theory that has a respective
|
5
|
-
# id in each of the other theories in the chain. e.g.
|
6
|
-
#
|
7
|
-
# +----------+--------+--------+--------+--------+
|
8
|
-
# |Global #ID| head | link#2 | link#3 | link#4 |
|
9
|
-
# +----------+--------+--------+--------+--------+
|
10
|
-
# | 0 | 1 | 1 | 2 | 89 |
|
11
|
-
# +----------+--------+--------+--------+--------+
|
12
|
-
# | 1 | 2 | 4 | 6 | 1 |
|
13
|
-
# +----------+--------+--------+--------+--------+
|
14
|
-
|
15
|
-
class ChainMapping
|
16
|
-
attr_reader :mapping, :history
|
17
|
-
|
18
|
-
def initialize(mapping={},history=[])
|
19
|
-
@history, @mapping = history, mapping
|
20
|
-
end
|
21
|
-
|
22
|
-
def copy
|
23
|
-
return ChainMapping.new(@mapping.copy,@history.copy)
|
24
|
-
end
|
25
|
-
|
26
|
-
# Returns the global id for the this theory variable in this theory.
|
27
|
-
#
|
28
|
-
# @param theory_id The id of the theory that is being retreived
|
29
|
-
# @param variable_id The id of the theory variable in the context of the single theory
|
30
|
-
#
|
31
|
-
def find_global(theory_instance_id,variable_id)
|
32
|
-
res = @mapping.detect do |key,value|
|
33
|
-
value.has_key?(theory_instance_id) && value[theory_instance_id] == variable_id
|
34
|
-
end
|
35
|
-
return nil if res.nil?
|
36
|
-
return res[0]
|
37
|
-
end
|
38
|
-
|
39
|
-
def same?(chain_map)
|
40
|
-
return false if @mapping.length != chain_map.mapping.length
|
41
|
-
return false if @history.length != chain_map.history.length
|
42
|
-
return @history == chain_map.history
|
43
|
-
end
|
44
|
-
|
45
|
-
# Adds a new variable mapping to a global id
|
46
|
-
# TODO Assigning global_id should probably not be allowed publically
|
47
|
-
#
|
48
|
-
def add_mapping(global_id,theory_instance_id,variable_id)
|
49
|
-
if @mapping[global_id].nil?
|
50
|
-
@mapping[global_id] = {}
|
51
|
-
end
|
52
|
-
# TODO Write tests to check that the error is raised
|
53
|
-
unless @mapping[global_id][theory_instance_id].nil?
|
54
|
-
if @mapping[global_id][theory_instance_id] != variable_id
|
55
|
-
raise ChainMappingError.new('This global variable has already been defined')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
# TODO Should check that the theory_id#variable_id has not already been assigned to a global id
|
59
|
-
@mapping[global_id][theory_instance_id] = variable_id
|
60
|
-
end
|
61
|
-
|
62
|
-
# TODO I'd like to change global ids to letters for clarity
|
63
|
-
# Returns the next key that hasn't been defined in the mapping
|
64
|
-
def next_free_global_id
|
65
|
-
a = (0..100).to_a.detect() {|x| !@mapping.has_key?(x)}
|
66
|
-
raise StandardError.new('No more free global id') if a.nil?
|
67
|
-
return a
|
68
|
-
end
|
69
|
-
|
70
|
-
# Returns a string listing all the dependent to result connections
|
71
|
-
# that have been made.
|
72
|
-
#
|
73
|
-
def display_history
|
74
|
-
@history.each do |x|
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# TODO This is temporary - it doesn't resolve the issue of the same theory
|
79
|
-
# being used twice.
|
80
|
-
# Returns all the components that have been sucessfully connected to another
|
81
|
-
# component.
|
82
|
-
#
|
83
|
-
def connected_component_ids
|
84
|
-
@history.inject([]) {|total,x| total += x}
|
85
|
-
end
|
86
|
-
|
87
|
-
# Either returns an updated chain mapping if the mapping works or returns the
|
88
|
-
# existing mapping.
|
89
|
-
#
|
90
|
-
def apply_mapping_update(theory_a,component_a_id,theory_b,component_b_id)
|
91
|
-
updated_mapping = copy
|
92
|
-
begin
|
93
|
-
updated_mapping.connect(theory_a,component_a_id,theory_b,component_b_id)
|
94
|
-
rescue ChainMappingError => e
|
95
|
-
StandardLogger.instance.warning e
|
96
|
-
return self.copy
|
97
|
-
end
|
98
|
-
return updated_mapping
|
99
|
-
end
|
100
|
-
|
101
|
-
# TODO I need to include a mapping that doesn't declare a globlal_id. A global id only needs
|
102
|
-
# identified when connecting separate theories.
|
103
|
-
|
104
|
-
# TODO Mapping is not about theory_component_id it is about what is connected to what and
|
105
|
-
# when - consider when the same theory is added twice but connected differently.
|
106
|
-
|
107
|
-
# TODO This needs wrapped in some transaction incase one of the mappings won't work
|
108
|
-
# or in the wider context some of the other connections won't work.
|
109
|
-
|
110
|
-
# Updates the global mapping to connect the two theories so that
|
111
|
-
# they share the same global mapping
|
112
|
-
#
|
113
|
-
# TODO Need to include the theories instance id
|
114
|
-
#
|
115
|
-
def connect(theory_a,component_a_id,theory_b,component_b_id)
|
116
|
-
|
117
|
-
# Retrieve each of the components
|
118
|
-
component_a = theory_a.find_component(component_a_id)
|
119
|
-
component_b = theory_b.find_component(component_b_id)
|
120
|
-
|
121
|
-
# Check that the number of variables match
|
122
|
-
unless component_a.theory_variables.length == component_b.theory_variables.length
|
123
|
-
raise ChainMappingError.new('These components do not have the same number of variables')
|
124
|
-
end
|
125
|
-
|
126
|
-
# Go through each variable and confirm they have the same global mapping
|
127
|
-
component_a.theory_variables.zip(component_b.theory_variables) do |variable_a,variable_b|
|
128
|
-
|
129
|
-
# Do any of the theory variables already have a global id
|
130
|
-
global_var_a = find_global(theory_a.theory_instance_id,variable_a.theory_variable_id)
|
131
|
-
global_var_b = find_global(theory_b.theory_instance_id,variable_b.theory_variable_id)
|
132
|
-
|
133
|
-
# Nearly variables has been added as global - add new global connections
|
134
|
-
if ([global_var_a,global_var_b].all? {|x| x.nil?})
|
135
|
-
mapping_global_id = next_free_global_id
|
136
|
-
add_mapping(mapping_global_id,theory_a.theory_instance_id,variable_a.theory_variable_id)
|
137
|
-
add_mapping(mapping_global_id,theory_b.theory_instance_id,variable_b.theory_variable_id)
|
138
|
-
else
|
139
|
-
|
140
|
-
# If both the global ids are defined then they should be the same value.
|
141
|
-
if([global_var_a,global_var_b].all? {|x| !x.nil? })
|
142
|
-
if global_var_a != global_var_b
|
143
|
-
raise ChainMappingError.new(
|
144
|
-
'Both global ids have already been defiend but are not equal '+global_var_a.to_s+' and '+global_var_b.to_s
|
145
|
-
)
|
146
|
-
end
|
147
|
-
next
|
148
|
-
end
|
149
|
-
|
150
|
-
# Get the id of the only defined global id
|
151
|
-
global_id = [global_var_a,global_var_b].detect {|x| !x.nil? }
|
152
|
-
|
153
|
-
# Add the mapping for both
|
154
|
-
add_mapping(global_id,theory_a.theory_instance_id,variable_a.theory_variable_id)
|
155
|
-
add_mapping(global_id,theory_b.theory_instance_id,variable_b.theory_variable_id)
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
@history.unshift([theory_a.theory_instance_id,component_a_id,theory_b.theory_instance_id,component_b_id])
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
class ChainMappingError < StandardError
|
167
|
-
|
168
|
-
def initialize(msg)
|
169
|
-
super(msg)
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
data/lib/CodeHandler.rb
DELETED
@@ -1,513 +0,0 @@
|
|
1
|
-
require "tsort"
|
2
|
-
|
3
|
-
# A code handler continualy considers how to extend the complexity
|
4
|
-
# of a method in a custom class given the intial starting methods
|
5
|
-
# already availble within the class.
|
6
|
-
#
|
7
|
-
# It also can refactor the code into separate methods thereby
|
8
|
-
# reusing the same functionality.
|
9
|
-
#
|
10
|
-
# Essentially it just tries to create as many uniquely new variables as it
|
11
|
-
# can. Note they are consider unique if the process to create them is
|
12
|
-
# new, NOT whether or not there value is new.
|
13
|
-
#
|
14
|
-
class CodeHandler
|
15
|
-
|
16
|
-
attr_reader :runtime_methods
|
17
|
-
attr_writer :default_structures
|
18
|
-
|
19
|
-
@@CODE_HANDLER_ID = 0
|
20
|
-
|
21
|
-
def initialize(runtime_methods=[],structures=nil)
|
22
|
-
@runtime_methods = runtime_methods
|
23
|
-
@entrance_method = create_entrance_method
|
24
|
-
@code_handler_id = @@CODE_HANDLER_ID
|
25
|
-
@@CODE_HANDLER_ID += 1
|
26
|
-
|
27
|
-
# These are the default statement structures if non-are supplied
|
28
|
-
@default_structures = [
|
29
|
-
DeclareVariableAsVariableStructure.new,
|
30
|
-
StatementStructure2.new(StatementStructure2.declared_runtime_method),
|
31
|
-
StatementStructure2.new(StatementStructure2.declared_array),
|
32
|
-
StatementStructure2.new(StatementStructure2.declared_string_addition),
|
33
|
-
DeclareNewInstanceStructure.new(MethodUsageClass.new,RuntimeMethodClass.new)
|
34
|
-
]
|
35
|
-
|
36
|
-
# If structures are supplied the overwrite the default structures
|
37
|
-
@default_structures = structures unless structures.nil?
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns a string that prints out how the dynamic code for the
|
41
|
-
# code handler currently looks.
|
42
|
-
#
|
43
|
-
def write
|
44
|
-
|
45
|
-
dynamic_code = "class #{class_name}"+"\n"
|
46
|
-
|
47
|
-
# Include each of the avaialble runtime methods
|
48
|
-
@runtime_methods.each do |x|
|
49
|
-
dynamic_code += x.write(ParametersContainer.new,1)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Now add the entrance method
|
53
|
-
dynamic_code += @entrance_method.write(ParametersContainer.new,1)
|
54
|
-
|
55
|
-
dynamic_code += "end"
|
56
|
-
return dynamic_code
|
57
|
-
end
|
58
|
-
|
59
|
-
# Returns an array of method instances containing various numbers of statements.
|
60
|
-
#
|
61
|
-
# 1. At this point we are creating a statement to go straight into a method or
|
62
|
-
# into a nested statement. First we find all the available variables in the
|
63
|
-
# context. For this to work the variables should be saved with a scope. At
|
64
|
-
# this point it isn't concerning it's self with the dependencies for the variable.
|
65
|
-
# It does however have to take into consideration scope. As such every nested
|
66
|
-
# statement maintains an array of it's level e.g. [5,7] for a two level nested
|
67
|
-
# statement. This would mean that varibles with a scope level of 5 or 7 would
|
68
|
-
# be valid consideration.
|
69
|
-
#
|
70
|
-
# 2. Next using the variables available to it it constructs a number of different
|
71
|
-
# statements.
|
72
|
-
#
|
73
|
-
# 3. From this statement it needs to work backwards to construct the full method.
|
74
|
-
# It does this by finding all the dependencies that have the same scope level.
|
75
|
-
# After that has been done, if finds and adds all the dependcies on the other
|
76
|
-
# scope level.
|
77
|
-
#
|
78
|
-
# 4. With the method constructed the value for the new variable can be asscertained.
|
79
|
-
# The asscertained value gets added to available array. Also if a variable is
|
80
|
-
# overwritten within the nested statement then its value is included with a scope
|
81
|
-
# value outside the nested statement. Specifically a scope level the same as the
|
82
|
-
# variable that was overridden. The variable simple has a depencey on the nested
|
83
|
-
# statement. This allows it to rebuild the statements in the correct order. It
|
84
|
-
# can then check the scopes and wrap the nested statement accordingly.
|
85
|
-
#
|
86
|
-
# @param count The number of itterations to go through when generating new
|
87
|
-
# runtime method arrangements.
|
88
|
-
# @param additional_available Any additional values that should be made available when
|
89
|
-
# generating statements.
|
90
|
-
#
|
91
|
-
def itterate(count=1,additional_available=[])
|
92
|
-
|
93
|
-
# Create an array to contain the vessels currently available
|
94
|
-
initial_copied_method = @entrance_method.copy
|
95
|
-
initial_copied_method.clear
|
96
|
-
vessels = [initial_copied_method]
|
97
|
-
|
98
|
-
# Create the array to contain the available variables and the initial runtime method calls
|
99
|
-
available = []
|
100
|
-
available += additional_available
|
101
|
-
@runtime_methods.each {|x| available += x.callable_combinations}
|
102
|
-
|
103
|
-
# Set the scope id for all the method calls
|
104
|
-
available.each {|x| x.scope_id = initial_copied_method.scope_id}
|
105
|
-
|
106
|
-
# Maintains all the statements and their dependencies
|
107
|
-
dependencies = StatementDependencies.new
|
108
|
-
|
109
|
-
# Completed methods
|
110
|
-
results = []
|
111
|
-
|
112
|
-
# Itterate over the number of times specified
|
113
|
-
count.times do |i|
|
114
|
-
|
115
|
-
# Keep track of the newly created variables
|
116
|
-
newly_created_variable = []
|
117
|
-
|
118
|
-
# Keeps track of newly created vessels
|
119
|
-
newly_created_vessels = []
|
120
|
-
|
121
|
-
# For each vessel create appropriate statements
|
122
|
-
vessels.each do |vessel|
|
123
|
-
|
124
|
-
# Find potential new statements available to the current vessel
|
125
|
-
new_statement_results = find_possible_new_statements(vessel,available,dependencies)
|
126
|
-
|
127
|
-
# Find the statement dependencies for each statement
|
128
|
-
new_statement_results.each do |y|
|
129
|
-
|
130
|
-
# Create the vessel for the new statement
|
131
|
-
new_vessel = vessel.copy
|
132
|
-
|
133
|
-
# Create a runtime method with the statement and all the dependencies
|
134
|
-
copied_method = build_minimalist_method(@entrance_method,y,dependencies)
|
135
|
-
|
136
|
-
# Realise the generated method
|
137
|
-
begin
|
138
|
-
realised_method = copied_method.realise2(ParametersContainer.new,@runtime_methods)
|
139
|
-
rescue ImproperStatementUsageError => e
|
140
|
-
|
141
|
-
# TODO I have rejected statements "var = <#statement_variable>.declare_variable" if the statement
|
142
|
-
# variable doesn't represent a declaration statement. I don't know if this is the right way to
|
143
|
-
# do things. It might be better to return a NilVariable or prevent it from ever being created.
|
144
|
-
|
145
|
-
# TODO I should check this is logged
|
146
|
-
StandardLogger.instance.warning('Method rejeceted')
|
147
|
-
StandardLogger.instance.warning(e)
|
148
|
-
next
|
149
|
-
end
|
150
|
-
|
151
|
-
results.push(realised_method)
|
152
|
-
|
153
|
-
# TODO I should determine the nature of the statement and then
|
154
|
-
# determine the new variables available.
|
155
|
-
# - I should maybe save structures with statements.
|
156
|
-
|
157
|
-
raise StandardError.new('Statement type has not defined for this statement') if y.statement_type.nil?
|
158
|
-
|
159
|
-
# Determine the id of the statement that declares the value
|
160
|
-
#case(y.statement_type)
|
161
|
-
# when StatementStructure::DECLARATION_STATEMENT
|
162
|
-
if((y.statement_type == StatementStructure::MODIFYING_STATEMENT)or(y.statement_type == StatementStructure::DECLARATION_STATEMENT))
|
163
|
-
|
164
|
-
#declared_variable_id = y.created_variable.variable_id
|
165
|
-
variable_uniq_id = y.created_variable.uniq_id
|
166
|
-
|
167
|
-
# Find the value of the variable within the realised method and set it's scope
|
168
|
-
#resulting_variable = realised_method.find_variable(declared_variable_id)
|
169
|
-
resulting_variable = realised_method.find_variable(variable_uniq_id)
|
170
|
-
|
171
|
-
if y.kind_of?(BlockStatement)
|
172
|
-
resulting_variable.scope_id = y.scope_id
|
173
|
-
resulting_variable.clear
|
174
|
-
else
|
175
|
-
resulting_variable.scope_id = vessel.scope_id
|
176
|
-
end
|
177
|
-
newly_created_variable.push(resulting_variable)
|
178
|
-
|
179
|
-
#new_vessel = realised_method.find_statement_that_declares_variable(declared_variable_id)
|
180
|
-
# TODO Check this works with uniq_id
|
181
|
-
new_vessel = realised_method.find_statement_that_created_variable(variable_uniq_id)
|
182
|
-
|
183
|
-
# Find the statement from the typed method that declares the variable
|
184
|
-
# NOTE I wonder if it would be quicker and safe to add the realised statement here
|
185
|
-
#declaring_statement = realised_method.find_statement_that_declares_variable(declared_variable_id)
|
186
|
-
# TODO Check this works with uniq_id
|
187
|
-
declaring_statement = realised_method.find_statement_that_created_variable(variable_uniq_id)
|
188
|
-
dependencies.push(declaring_statement)
|
189
|
-
|
190
|
-
# If the new statement was a nested statement then add as vessel
|
191
|
-
if y.kind_of?(BlockStatement)
|
192
|
-
new_vessels_scope = [new_vessel.scope_id]
|
193
|
-
new_vessels_scope += vessel.scope
|
194
|
-
new_vessel.scope = new_vessels_scope
|
195
|
-
new_vessel.clear
|
196
|
-
newly_created_vessels.push(new_vessel)
|
197
|
-
end
|
198
|
-
|
199
|
-
# when StatementStructure::MODIFYING_STATEMENT:
|
200
|
-
|
201
|
-
# # exit
|
202
|
-
# # Need to save modified statement;
|
203
|
-
# StandardLogger.instance.warning('I think I need to treat modifying statements as if they declare new variables')
|
204
|
-
#
|
205
|
-
# # TODO I'm not certain this isn't going to add loads of statement
|
206
|
-
# StandardLogger.instance.info('Statement ID: '+y.statement_id.to_s)
|
207
|
-
# StandardLogger.instance.info(': '+y.write)
|
208
|
-
#
|
209
|
-
# # Adding the statement the newly modified statement
|
210
|
-
# dependencies.push(realised_method.select {|stment| stment.statement_id == y.statement_id}.first)
|
211
|
-
# elsif(StatementStructure::USAGE_STATEMENT)
|
212
|
-
else
|
213
|
-
raise StandardError.new('Unknown statement_type "'+y.statement_type+'" "'+y.write+'"')
|
214
|
-
end
|
215
|
-
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
|
220
|
-
# Add the new variables to available list
|
221
|
-
# TODO newly_created_variable is an array - it should be newly_created_variables
|
222
|
-
available += newly_created_variable
|
223
|
-
|
224
|
-
# Add the new vessel to the list
|
225
|
-
vessels += newly_created_vessels
|
226
|
-
|
227
|
-
end
|
228
|
-
return results
|
229
|
-
|
230
|
-
end
|
231
|
-
|
232
|
-
def self.reset_global_id
|
233
|
-
#http://www.zenspider.com/Languages/Ruby/QuickRef.html
|
234
|
-
unless $".include?('test/unit.rb')
|
235
|
-
StandardLogger.log 'WARNING: Resetting variable id, this should only be done for tests'
|
236
|
-
end
|
237
|
-
@@CODE_HANDLER_ID = 0
|
238
|
-
end
|
239
|
-
|
240
|
-
def class_name
|
241
|
-
return "RuntimeCodeHandler"+@code_handler_id.to_s
|
242
|
-
end
|
243
|
-
|
244
|
-
protected
|
245
|
-
|
246
|
-
# Returns an array of new statements after removing any statements
|
247
|
-
# that have previously been considered when generating code.
|
248
|
-
#
|
249
|
-
# TODO This needs re-thought for seanarios when new containers become
|
250
|
-
# available.
|
251
|
-
#
|
252
|
-
# @param possible_statements
|
253
|
-
# @param considered_statements
|
254
|
-
#
|
255
|
-
def new_statements(possible_statements,considered_statements)
|
256
|
-
|
257
|
-
# TODO I imagine there is a nicer way of doing this method using Procs or
|
258
|
-
# passing blocks.
|
259
|
-
|
260
|
-
results = StatementGroup.new
|
261
|
-
possible_statements.each do |x|
|
262
|
-
|
263
|
-
# Declare the statement that is being considered - for block statements
|
264
|
-
# e.g. test.each do |x| only the "test.each" bit is considered
|
265
|
-
if x.kind_of?(BlockStatement)
|
266
|
-
subject = x.opening_statement
|
267
|
-
end
|
268
|
-
subject ||= x
|
269
|
-
|
270
|
-
catch(:already_exists) do
|
271
|
-
considered_statements.each do |y|
|
272
|
-
|
273
|
-
if y.kind_of?(BlockStatement)
|
274
|
-
other = y.opening_statement
|
275
|
-
end
|
276
|
-
other ||= y
|
277
|
-
|
278
|
-
catch(:different_from_this_statement) do
|
279
|
-
|
280
|
-
# Checks whether the statements are equivalent
|
281
|
-
if subject.equivalent?(other)
|
282
|
-
throw :already_exists
|
283
|
-
end
|
284
|
-
throw :different_from_this_statement
|
285
|
-
end
|
286
|
-
end
|
287
|
-
results.push(x)
|
288
|
-
end
|
289
|
-
end
|
290
|
-
return results
|
291
|
-
end
|
292
|
-
|
293
|
-
# Return the next set of available statements given the
|
294
|
-
# elements avialable.
|
295
|
-
#
|
296
|
-
def next_statements(available=[])
|
297
|
-
|
298
|
-
# Collect a number of runtime variables
|
299
|
-
results = StatementGroup.new
|
300
|
-
statement_structures.each do |structure|
|
301
|
-
results += structure.statements(available)
|
302
|
-
end
|
303
|
-
return results
|
304
|
-
end
|
305
|
-
|
306
|
-
# Retuns a runtime method instance that is the starting
|
307
|
-
# point when generating unique variable journeys.
|
308
|
-
#
|
309
|
-
def create_entrance_method
|
310
|
-
return RuntimeMethod.new(MethodUsage.new,NilVariable.new)
|
311
|
-
end
|
312
|
-
|
313
|
-
# Returns an array of potential statement structures
|
314
|
-
# e.g.
|
315
|
-
#
|
316
|
-
# Structure.new(Unknown,Equal,FixnumVariable,Addition,FixnumVariable)
|
317
|
-
#
|
318
|
-
# TODO Write more tests for StatementStructure2
|
319
|
-
# TODO I don't know if I want to declare the structures here. It might be
|
320
|
-
# nicer to keep them with the variables. They need to be with the variables
|
321
|
-
# since even if they were created by the same StatementStrucutre this is
|
322
|
-
# no guarantee that they will have the same the structure. e..g
|
323
|
-
#
|
324
|
-
# var_a.push(var_b);
|
325
|
-
#
|
326
|
-
def statement_structures
|
327
|
-
return @default_structures
|
328
|
-
end
|
329
|
-
|
330
|
-
# Returns the current runtime class instance
|
331
|
-
def to_runtime_class
|
332
|
-
runtime_class = RuntimeClass.new(class_name)
|
333
|
-
@runtime_methods.each do |x|
|
334
|
-
runtime_class.push x.copy
|
335
|
-
end
|
336
|
-
runtime_class.push @entrance_method
|
337
|
-
return runtime_class
|
338
|
-
end
|
339
|
-
|
340
|
-
# Returns an array of statements that need
|
341
|
-
# DEPENDENCY - check ruby code
|
342
|
-
# TODO Look up Matrix in ruby p694
|
343
|
-
def requisite_statements_for(entrance_method,statement,journeys)
|
344
|
-
statement.required_variable_ids.each do |x|
|
345
|
-
journeys[x].each do |y|
|
346
|
-
entrance_method.push(y)
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
# Returns an array of statements based on the available variables and
|
352
|
-
# previously created statements.
|
353
|
-
#
|
354
|
-
def create_statements(available,dependencies,vessel)
|
355
|
-
|
356
|
-
# Now attempt to create statements with each of the elements
|
357
|
-
statements = next_statements(available)
|
358
|
-
|
359
|
-
# Remove out of scope dependencies
|
360
|
-
# If a statement is used in a new scope it should be considered a new statement
|
361
|
-
# NOTE For now I wont allow this
|
362
|
-
|
363
|
-
# Remove statements that may have been considered at previous itteration
|
364
|
-
statements = new_statements(statements,dependencies)
|
365
|
-
|
366
|
-
# Remove any statements that simple declare an existing variable var_a = var_b
|
367
|
-
# TODO With better structures this shouldn't be necessary
|
368
|
-
statements = statements.remove_simple
|
369
|
-
|
370
|
-
return statements
|
371
|
-
end
|
372
|
-
|
373
|
-
# Returns an updated array of variables thats scope is with
|
374
|
-
# the tolerance specified.
|
375
|
-
#
|
376
|
-
# @param available A array of available variables
|
377
|
-
# @param scope An array indicating the scope to allow e.g.
|
378
|
-
# [5,7].
|
379
|
-
#
|
380
|
-
def filter_within_scope(available,scope)
|
381
|
-
results = available.find_all {|x| scope.any?{|y| x.scope_id==y} }
|
382
|
-
return results
|
383
|
-
end
|
384
|
-
|
385
|
-
# Returns an array of statements in the order of their depenence.
|
386
|
-
#
|
387
|
-
# @param dependencies A statement dependencies instance containing the
|
388
|
-
# depenency structure.
|
389
|
-
# @param statement The most recently added statement that's depenencies
|
390
|
-
# need found for.
|
391
|
-
#
|
392
|
-
def find_prerequisite_statements(dependencies,statement)
|
393
|
-
|
394
|
-
# TODO Call this method within dependencies
|
395
|
-
# Find the dependcies for the statement - the last one is the current statement
|
396
|
-
required_ids = dependencies.tsort_for_statement(statement)
|
397
|
-
required_ids.pop
|
398
|
-
|
399
|
-
# Add the dependent statements
|
400
|
-
results = []
|
401
|
-
required_ids.each do |y|
|
402
|
-
dependencies.each do |z|
|
403
|
-
results.push(z.copy) if z.statement_id == y
|
404
|
-
end
|
405
|
-
end
|
406
|
-
return results
|
407
|
-
|
408
|
-
end
|
409
|
-
|
410
|
-
# Strips out all the variables that are used as part of the
|
411
|
-
# the nested statements. This is to avoid editing variables
|
412
|
-
# that are being itterated over. For example
|
413
|
-
#
|
414
|
-
# var_a = ['test']
|
415
|
-
# var_a.each do |x|
|
416
|
-
# var_a.push('test')
|
417
|
-
# end
|
418
|
-
#
|
419
|
-
# @param vars An array of in-scope variables (relative to the supplied vessel)
|
420
|
-
# @param vessel The nested statement or method thats structure is being considered
|
421
|
-
# @param dependencies The dependencey structure of all the statements.
|
422
|
-
#
|
423
|
-
def strip_dependent_variables(vars,vessel,dependencies)
|
424
|
-
# Go through each nested statement in scope and remove any variables used in the statemnet
|
425
|
-
# this is to prevent variables being itterated over being used in the nested statement.
|
426
|
-
nested_statements = dependencies.find_all {|x| x.kind_of?(BlockStatement)}
|
427
|
-
vessel.scope.each do |used_scope|
|
428
|
-
nested_statement = nested_statements.detect {|x| x.scope_id == used_scope}
|
429
|
-
next if nested_statement.nil?
|
430
|
-
|
431
|
-
# Find the id of the variable used in the nested statement and remove it as a in_scope_variables
|
432
|
-
# TODO This presumes allot about the position of the variable in the statement
|
433
|
-
vars.delete_if {|x| x.kind_of?(Variable) && x.variable_id == nested_statement.opening_statement.first.variable.variable_id }
|
434
|
-
end
|
435
|
-
return vars
|
436
|
-
end
|
437
|
-
|
438
|
-
# Returns an array of possible new statements given the currently
|
439
|
-
# available variables, scope limitations and statement dependencies.
|
440
|
-
#
|
441
|
-
# @param vessel A vessel is something that contains statements. This
|
442
|
-
# is either a nested statement or a runtime method.
|
443
|
-
# @param available Is an array of all the variables and method calls. Note
|
444
|
-
# this has not been tailored to suit the vessel so some
|
445
|
-
# of the variables shouldn't be available.
|
446
|
-
# @param dependencies A statement dependencies instance that maintains what statements
|
447
|
-
# are dependent on what.
|
448
|
-
#
|
449
|
-
def find_possible_new_statements(vessel,available,dependencies)
|
450
|
-
|
451
|
-
# Filter the array of available variables to only include those within scope.
|
452
|
-
in_scope_variables = filter_within_scope(available,vessel.scope)
|
453
|
-
|
454
|
-
# Strip out parent itterating variables
|
455
|
-
in_scope_variables = strip_dependent_variables(in_scope_variables,vessel,dependencies)
|
456
|
-
|
457
|
-
# Create statements with the available variables
|
458
|
-
new_statement_results = create_statements(in_scope_variables,dependencies,vessel)
|
459
|
-
|
460
|
-
# All new statements should have the statement level of the vessel scope_id
|
461
|
-
new_statement_results.each {|x| x.statement_level = vessel.scope_id}
|
462
|
-
|
463
|
-
return new_statement_results
|
464
|
-
|
465
|
-
end
|
466
|
-
|
467
|
-
# Returns an updated method that includes a specified statement and
|
468
|
-
# all of its dependencies in the correct order and depth.
|
469
|
-
#
|
470
|
-
# @param initial_method
|
471
|
-
#
|
472
|
-
def build_minimalist_method(initial_method,statement,dependencies)
|
473
|
-
|
474
|
-
# Find all the pre-requisite statements for the leading statement
|
475
|
-
prerequisite_statements = find_prerequisite_statements(dependencies,statement)
|
476
|
-
|
477
|
-
# Create an empty initial method to contain each arrangement
|
478
|
-
constructing_method = initial_method.copy
|
479
|
-
constructing_method.clear
|
480
|
-
|
481
|
-
# Add all the statement in their scope order
|
482
|
-
prerequisite_statements.copy.each do |remaining_statement|
|
483
|
-
unless remaining_statement.statement_level == constructing_method.scope_id
|
484
|
-
|
485
|
-
# Find the pre-requiste statement the statement should reside in
|
486
|
-
actual_statement = prerequisite_statements.delete_if {|z| z.statement_id == remaining_statement.statement_id}
|
487
|
-
|
488
|
-
prerequisite_statements.each do |h|
|
489
|
-
if h.kind_of?(StatementGroup)
|
490
|
-
if h.scope_id == actual_statement.statement_level
|
491
|
-
h.push(actual_statement)
|
492
|
-
break
|
493
|
-
end
|
494
|
-
end
|
495
|
-
end
|
496
|
-
exit
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
|
-
# Add each pre-requisite statement to the copied method
|
501
|
-
prerequisite_statements.each do |f|
|
502
|
-
constructing_method.push(f)
|
503
|
-
end
|
504
|
-
|
505
|
-
# Find the statement with the correct statement level and add the new statement
|
506
|
-
container_statement = constructing_method.find_container_at_level(statement.statement_level)
|
507
|
-
container_statement.push(statement)
|
508
|
-
|
509
|
-
return constructing_method
|
510
|
-
|
511
|
-
end
|
512
|
-
|
513
|
-
end
|