| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2021-08-14 04:13:56 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2021-08-14 04:13:56 +0200 |
| commit | c44f60829dc93687fe7d904b60d154de58f0492d (patch) | |
| tree | 1aa26fa93648698b25b3f76dc0f452d11e4f9d83 | |
| parent | bf160c51418e8d67e6338052bc2f310a1edc4dd6 (diff) | |
Adds the Wyrd compilers for all generic Fate computations.
43 files changed, 3225 insertions, 2861 deletions
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java b/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java index cbd0b6b..83960b7 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java @@ -45,13 +45,7 @@ public class ExtraComputationInstance extends Computation ) throws ParsingError { - RecurrentChecks.propagate_expected_types - ( - parameters, - computation.get_signature() - ); - - RecurrentChecks.assert_computations_matches_signature + RecurrentChecks.propagate_expected_types_and_assert_computations_matches_signature ( origin, parameters, diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java b/src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java index d5647c0..a4f029f 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java @@ -54,7 +54,7 @@ public class TextWithEffect extends Computation ) throws ParsingError { - RecurrentChecks.assert_computations_matches_signature + RecurrentChecks.propagate_expected_types_and_assert_computations_matches_signature ( origin, parameters, diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/LambdaEvaluation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/LambdaEvaluation.java index f1af59f..9e1597f 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/LambdaEvaluation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/LambdaEvaluation.java @@ -63,13 +63,7 @@ public class LambdaEvaluation extends GenericComputation call_parameters.remove(0); - RecurrentChecks.propagate_expected_types - ( - call_parameters, - lambda_signature - ); - - RecurrentChecks.assert_computations_matches_signature + RecurrentChecks.propagate_expected_types_and_assert_computations_matches_signature ( origin, call_parameters, diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/TextJoin.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/TextJoin.java index 4d10497..7d5d364 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/TextJoin.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/TextJoin.java @@ -57,7 +57,7 @@ public class TextJoin extends GenericComputation text_collection.expect_non_string(); link.expect_string(); - RecurrentChecks.assert_is_a_collection_of + RecurrentChecks.propagate_expected_types_and_assert_is_a_collection_of ( origin, text_collection.get_type(), diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/EventOption.java b/src/core/src/tonkadur/fate/v1/lang/instruction/EventOption.java index d2d4fc3..6b4413e 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/EventOption.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/EventOption.java @@ -70,13 +70,7 @@ public class EventOption extends Instruction ) throws ParsingError { - RecurrentChecks.propagate_expected_types - ( - parameters, - event.get_signature() - ); - - RecurrentChecks.assert_computations_matches_signature + RecurrentChecks.propagate_expected_types_and_assert_computations_matches_signature ( origin, parameters, diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/ExtraInstructionInstance.java b/src/core/src/tonkadur/fate/v1/lang/instruction/ExtraInstructionInstance.java index 2a5a13e..efeafaa 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/ExtraInstructionInstance.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/ExtraInstructionInstance.java @@ -46,13 +46,7 @@ public class ExtraInstructionInstance extends Instruction ) throws ParsingError { - RecurrentChecks.propagate_expected_types - ( - parameters, - instruction.get_signature() - ); - - RecurrentChecks.assert_computations_matches_signature + RecurrentChecks.propagate_expected_types_and_assert_computations_matches_signature ( origin, parameters, diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java index 1b93aba..2972417 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java @@ -65,7 +65,7 @@ public class SequenceCall extends Instruction signature ); - RecurrentChecks.assert_computations_matches_signature + RecurrentChecks.propagate_expected_types_and_assert_computations_matches_signature ( get_origin(), parameters, diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceJump.java b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceJump.java index 9d8513c..f7157ff 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceJump.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceJump.java @@ -48,7 +48,7 @@ public class SequenceJump extends Instruction signature ); - RecurrentChecks.assert_computations_matches_signature + RecurrentChecks.propagate_expected_types_and_assert_computations_matches_signature ( get_origin(), parameters, diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceVariableCall.java b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceVariableCall.java index 0e4a654..7fb0d1c 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceVariableCall.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceVariableCall.java @@ -79,7 +79,7 @@ public class SequenceVariableCall extends Instruction ); } - RecurrentChecks.assert_computations_matches_signature + RecurrentChecks.propagate_expected_types_and_assert_computations_matches_signature ( origin, parameters, diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceVariableJump.java b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceVariableJump.java index f0a0cae..72bb3a2 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceVariableJump.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceVariableJump.java @@ -79,7 +79,7 @@ public class SequenceVariableJump extends Instruction ); } - RecurrentChecks.assert_computations_matches_signature + RecurrentChecks.propagate_expected_types_and_assert_computations_matches_signature ( origin, parameters, diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java index f5bb4a0..b02b600 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java @@ -164,37 +164,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor return result; } -/* - @Override - public void visit_at_reference - ( - final tonkadur.fate.v1.lang.computation.AtReference n - ) - throws Throwable - { - final ComputationCompiler n_cc; - n_cc = new ComputationCompiler(compiler); - - n.get_parent().get_visited_by(n_cc); - - assimilate(n_cc); - - result_as_address = - new Address - ( - n_cc.get_computation(), - TypeCompiler.compile - ( - compiler, - ( - (tonkadur.fate.v1.lang.type.PointerType) - n.get_parent().get_type() - ).get_referenced_type() - ) - ); - } -*/ @Override public void visit_cast ( @@ -374,105 +344,6 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor n.get_value_as_string() ); } -/* - @Override - public void visit_count_operator - ( - final tonkadur.fate.v1.lang.computation.CountOperator n - ) - throws Throwable - { - final ComputationCompiler collection_compiler, element_compiler; - - collection_compiler = new ComputationCompiler(compiler); - element_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(collection_compiler); - n.get_element().get_visited_by(element_compiler); - - collection_compiler.generate_address(); - - assimilate(collection_compiler); - assimilate(element_compiler); - - if - ( - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_collection().get_type() - ).is_set() - ) - { - final Register was_found, index, element; - - was_found = reserve(Type.BOOL); - index = reserve(Type.INT); - element = reserve(element_compiler.get_computation().get_type()); - - init_instructions.add - ( - new SetValue - ( - element.get_address(), - element_compiler.get_computation() - ) - ); - init_instructions.add - ( - BinarySearch.generate - ( - compiler.registers(), - compiler.assembler(), - element.get_value(), - new Size(collection_compiler.get_address()), - collection_compiler.get_address(), - was_found.get_address(), - index.get_address() - ) - ); - - result_as_computation = - new IfElseComputation - ( - was_found.get_value(), - Constant.ONE, - Constant.ZERO - ); - } - else - { - final Register result, element; - - result = reserve(Type.INT); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - element = reserve(element_compiler.get_computation().get_type()); - - init_instructions.add - ( - new SetValue - ( - element.get_address(), - element_compiler.get_computation() - ) - ); - init_instructions.add - ( - CountOccurrences.generate - ( - compiler.registers(), - compiler.assembler(), - element.get_value(), - new Size(collection_compiler.get_address()), - collection_compiler.get_address(), - result_as_address - ) - ); - } - } -*/ @Override public void visit_field_access @@ -614,99 +485,6 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor } } -/* - @Override - public void visit_is_member_operator - ( - final tonkadur.fate.v1.lang.computation.IsMemberOperator n - ) - throws Throwable - { - final Register result; - final ComputationCompiler collection_compiler, element_compiler; - - collection_compiler = new ComputationCompiler(compiler); - element_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(collection_compiler); - n.get_element().get_visited_by(element_compiler); - - collection_compiler.generate_address(); - - assimilate(collection_compiler); - assimilate(element_compiler); - - result = reserve(Type.BOOL); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - if - ( - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_collection().get_type() - ).is_set() - ) - { - final Register index, element; - - index = reserve(Type.INT); - element = reserve(element_compiler.get_computation().get_type()); - - init_instructions.add - ( - new SetValue - ( - element.get_address(), - element_compiler.get_computation() - ) - ); - init_instructions.add - ( - BinarySearch.generate - ( - compiler.registers(), - compiler.assembler(), - element.get_value(), - new Size(collection_compiler.get_address()), - collection_compiler.get_address(), - result_as_address, - index.get_address() - ) - ); - - } - else - { - final Register index, element; - - index = reserve(Type.INT); - element = reserve(element_compiler.get_computation().get_type()); - - init_instructions.add - ( - new SetValue - ( - element.get_address(), - element_compiler.get_computation() - ) - ); - init_instructions.add - ( - IterativeSearch.generate - ( - compiler.registers(), - compiler.assembler(), - element.get_value(), - new Size(collection_compiler.get_address()), - collection_compiler.get_address(), - result_as_address, - index.get_address() - ) - ); - } - } -*/ @Override public void visit_newline ( @@ -716,571 +494,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor { result_as_computation = new Newline(); } -/* - @Override - public void visit_operation - ( - final tonkadur.fate.v1.lang.computation.Operation n - ) - throws Throwable - { - final String fate_op_name; - final List<Computation> operands; - - operands = new ArrayList<Computation>(); - for (final tonkadur.fate.v1.lang.meta.Computation x: n.get_operands()) - { - final ComputationCompiler cc; - - cc = new ComputationCompiler(compiler); - - x.get_visited_by(cc); - - assimilate(cc); - - operands.add(cc.get_computation()); - } - - fate_op_name = n.get_operator().get_name(); - - if - ( - fate_op_name.equals(tonkadur.fate.v1.lang.computation.Operator.PLUS.get_name()) - ) - { - final Iterator<Computation> operands_it; - - operands_it = operands.iterator(); - - result_as_computation = operands_it.next(); - - while (operands_it.hasNext()) - { - result_as_computation = - Operation.plus(operands_it.next(), result_as_computation); - } - } - else if - ( - fate_op_name.equals(tonkadur.fate.v1.lang.computation.Operator.MINUS.get_name()) - ) - { - final Iterator<Computation> operands_it; - Computation sum; - - operands_it = operands.iterator(); - - result_as_computation = operands_it.next(); - sum = operands_it.next(); - - while (operands_it.hasNext()) - { - sum = Operation.plus(operands_it.next(), sum); - } - - result_as_computation = Operation.minus(result_as_computation, sum); - } - else if - ( - fate_op_name.equals(tonkadur.fate.v1.lang.computation.Operator.TIMES.get_name()) - ) - { - final Iterator<Computation> operands_it; - - operands_it = operands.iterator(); - - result_as_computation = operands_it.next(); - - while (operands_it.hasNext()) - { - result_as_computation = - Operation.times(operands_it.next(), result_as_computation); - } - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.DIVIDE.get_name() - ) - ) - { - result_as_computation = - Operation.divide(operands.get(0), operands.get(1)); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.MIN.get_name() - ) - ) - { - final Register candidate; - - candidate = reserve(operands.get(0).get_type()); - result_as_address = candidate.get_address(); - result_as_computation = candidate.get_value(); - - init_instructions.add - ( - new SetValue(result_as_address, operands.get(0)) - ); - - for (final Computation operand: operands) - { - init_instructions.add - ( - new SetValue - ( - result_as_address, - new IfElseComputation - ( - Operation.less_than - ( - result_as_computation, - operand - ), - result_as_computation, - operand - ) - ) - ); - } - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.MAX.get_name() - ) - ) - { - final Register candidate; - - candidate = reserve(operands.get(0).get_type()); - result_as_address = candidate.get_address(); - result_as_computation = candidate.get_value(); - - init_instructions.add - ( - new SetValue(result_as_address, operands.get(0)) - ); - - for (final Computation operand: operands) - { - init_instructions.add - ( - new SetValue - ( - result_as_address, - new IfElseComputation - ( - Operation.greater_than(result_as_computation, operand), - result_as_computation, - operand - ) - ) - ); - } - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.ABS.get_name() - ) - ) - { - final Computation zero, minus_one; - - if (operands.get(0).get_type().equals(Type.INT)) - { - zero = Constant.ZERO; - minus_one = new Constant(Type.INT, "-1"); - } - else - { - zero = new Constant(Type.FLOAT, "0.0"); - minus_one = new Constant(Type.FLOAT, "-1.0"); - } - - result_as_computation = - new IfElseComputation - ( - Operation.greater_than(zero, operands.get(0)), - Operation.times(minus_one, operands.get(0)), - operands.get(0) - ); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.CLAMP.get_name() - ) - ) - { - final Type t; - final Register candidate; - final Computation result_as_computation; - - t = operands.get(2).get_type(); - candidate = reserve(t); - result_as_address = candidate.get_address(); - result_as_computation = candidate.get_value(); - - init_instructions.add - ( - new SetValue - ( - result_as_address, - new IfElseComputation - ( - Operation.greater_than(operands.get(2), operands.get(1)), - operands.get(1), - operands.get(2) - ) - ) - ); - init_instructions.add - ( - new SetValue - ( - result_as_address, - new IfElseComputation - ( - Operation.less_than(result_as_computation, operands.get(0)), - operands.get(0), - result_as_computation - ) - ) - ); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.MODULO.get_name() - ) - ) - { - result_as_computation = - Operation.modulo(operands.get(0), operands.get(1)); - } - else if - ( - fate_op_name.equals(tonkadur.fate.v1.lang.computation.Operator.POWER.get_name()) - ) - { - result_as_computation = - Operation.power(operands.get(0), operands.get(1)); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.RANDOM.get_name() - ) - ) - { - final List<Instruction> push_rand, pop_rand; - final Register result, zero_holder; - - push_rand = new ArrayList<Instruction>(); - pop_rand = new ArrayList<Instruction>(); - - result = reserve(Type.INT); - zero_holder = reserve(Type.INT); - - result_as_computation = result.get_value(); - result_as_address = result.get_address(); - - push_rand.add - ( - new SetValue - ( - result_as_address, - Operation.rand(operands.get(0), operands.get(1)) - ) - ); - - push_rand.add - ( - new SetValue - ( - new RelativeAddress - ( - compiler.registers().get_rand_value_holder().get_address(), - new Cast - ( - new Size - ( - compiler.registers().get_rand_value_holder - ( - ).get_address() - ), - Type.STRING - ), - Type.INT - ), - result_as_computation - ) - ); - - pop_rand.add - ( - new SetValue - ( - result_as_address, - new ValueOf - ( - new RelativeAddress - ( - compiler.registers().get_rand_value_holder().get_address(), - new Cast(Constant.ZERO, Type.STRING), - Type.INT - ) - ) - ) - ); - - pop_rand.add(new SetValue(zero_holder.get_address(), Constant.ZERO)); - - pop_rand.add - ( - RemoveAt.generate - ( - compiler.registers(), - compiler.assembler(), - zero_holder.get_address(), - new Size - ( - compiler.registers().get_rand_value_holder().get_address() - ), - compiler.registers().get_rand_value_holder().get_address() - ) - ); - - init_instructions.add - ( - IfElse.generate - ( - compiler.registers(), - compiler.assembler(), - Operation.equals - ( - compiler.registers().get_rand_mode_holder().get_value(), - Constant.ZERO - ), - new SetValue - ( - result_as_address, - Operation.rand(operands.get(0), operands.get(1)) - ), - IfElse.generate - ( - compiler.registers(), - compiler.assembler(), - Operation.equals - ( - compiler.registers().get_rand_mode_holder().get_value(), - Constant.ONE - ), - compiler.assembler().merge(push_rand), - compiler.assembler().merge(pop_rand) - ) - ) - ); - } - else if - ( - fate_op_name.equals(tonkadur.fate.v1.lang.computation.Operator.AND.get_name()) - ) - { - final Iterator<Computation> operands_it; - - operands_it = operands.iterator(); - - result_as_computation = operands_it.next(); - - while (operands_it.hasNext()) - { - result_as_computation = - Operation.and(operands_it.next(), result_as_computation); - } - } - else if - ( - fate_op_name.equals(tonkadur.fate.v1.lang.computation.Operator.OR.get_name()) - ) - { - final Iterator<Computation> operands_it; - - operands_it = operands.iterator(); - - result_as_computation = operands_it.next(); - - while (operands_it.hasNext()) - { - result_as_computation = - Operation.or(operands_it.next(), result_as_computation); - } - } - else if - ( - fate_op_name.equals(tonkadur.fate.v1.lang.computation.Operator.NOT.get_name()) - ) - { - result_as_computation = Operation.not(operands.get(0)); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.IMPLIES.get_name() - ) - ) - { - result_as_computation = - Operation.implies(operands.get(0), operands.get(1)); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.ONE_IN.get_name() - ) - ) - { - final Iterator<Computation> operand_it; - - operand_it = operands.iterator(); - - result_as_computation = - new IfElseComputation - ( - operand_it.next(), - Constant.ONE, - Constant.ZERO - ); - - while (operand_it.hasNext()) - { - result_as_computation = - Operation.plus - ( - new IfElseComputation - ( - operand_it.next(), - Constant.ONE, - Constant.ZERO - ), - result_as_computation - ); - } - - result_as_computation = - Operation.equals(result_as_computation, Constant.ONE); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.EQUALS.get_name() - ) - ) - { - final Iterator<Computation> operands_it; - final Computation first_elem; - - operands_it = operands.iterator(); - - first_elem = operands_it.next(); - - result_as_computation = - Operation.equals(first_elem, operands_it.next()); - - while (operands_it.hasNext()) - { - result_as_computation = - Operation.and - ( - result_as_computation, - Operation.equals(first_elem, operands_it.next()) - ); - } - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.LOWER_THAN.get_name() - ) - ) - { - result_as_computation = - Operation.less_than(operands.get(0), operands.get(1)); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.LOWER_EQUAL_THAN.get_name() - ) - ) - { - result_as_computation = - Operation.less_equal_than(operands.get(0), operands.get(1)); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.GREATER_EQUAL_THAN.get_name() - ) - ) - { - result_as_computation = - Operation.greater_equal_than(operands.get(0), operands.get(1)); - } - else if - ( - fate_op_name.equals - ( - tonkadur.fate.v1.lang.computation.Operator.GREATER_THAN.get_name() - ) - ) - { - result_as_computation = - Operation.greater_than(operands.get(0), operands.get(1)); - } - else - { - System.err.println("[P] Unknown Fate operator '" + fate_op_name+ "'."); - } - } -*/ -/* - @Override - public void visit_size_operator - ( - final tonkadur.fate.v1.lang.computation.SizeOperator n - ) - throws Throwable - { - final ComputationCompiler cc; - - cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(cc); - - assimilate(cc); - - result_as_computation = new Size(cc.get_address()); - } -*/ @Override public void visit_extra_computation ( @@ -1317,67 +531,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor parameters ); } -/* - @Override - public void visit_is_empty - ( - final tonkadur.fate.v1.lang.computation.IsEmpty n - ) - throws Throwable - { - final ComputationCompiler cc; - - cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(cc); - - assimilate(cc); - result_as_computation = - Operation.equals(new Size(cc.get_address()), Constant.ZERO); - } -*/ -/* - @Override - public void visit_index_of_operator - ( - final tonkadur.fate.v1.lang.computation.IndexOfOperator n - ) - throws Throwable - { - final ComputationCompiler elem_cc, collection_cc; - final Register result, result_found; - - result = reserve(Type.INT); - result_found = reserve(Type.BOOL); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - elem_cc = new ComputationCompiler(compiler); - collection_cc = new ComputationCompiler(compiler); - - n.get_element().get_visited_by(elem_cc); - n.get_collection().get_visited_by(collection_cc); - - assimilate(elem_cc); - assimilate(collection_cc); - - init_instructions.add - ( - IterativeSearch.generate - ( - compiler.registers(), - compiler.assembler(), - elem_cc.get_computation(), - new Size(collection_cc.get_address()), - collection_cc.get_address(), - result_found.get_address(), - result_as_address - ) - ); - } -*/ @Override public void visit_default ( @@ -1465,43 +619,6 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ); } */ -/* - @Override - public void visit_access - ( - final tonkadur.fate.v1.lang.computation.Access n - ) - throws Throwable - { - final ComputationCompiler extra_address_cc, base_address_cc; - - base_address_cc = new ComputationCompiler(compiler); - extra_address_cc = new ComputationCompiler(compiler); - - n.get_parent().get_visited_by(base_address_cc); - n.get_index().get_visited_by(extra_address_cc); - - base_address_cc.generate_address(); - - assimilate(base_address_cc); - assimilate(extra_address_cc); - - result_as_address = - new RelativeAddress - ( - base_address_cc.get_address(), - new Cast(extra_address_cc.get_computation(), Type.STRING), - TypeCompiler.compile - ( - compiler, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_parent().get_type() - ).get_content_type() - ) - ); - } -*/ @Override public void visit_switch_value ( @@ -1882,59 +999,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor result_as_computation = compiler.assembler().get_label_constant(in_label); } -/* - @Override - public void visit_lambda_evaluation - ( - final tonkadur.fate.v1.lang.computation.LambdaEvaluation n - ) - throws Throwable - { - final ComputationCompiler target_line_cc; - final List<Computation> parameters; - final Register result; - parameters = new ArrayList<Computation>(); - target_line_cc = new ComputationCompiler(compiler); - - n.get_lambda_function_reference().get_visited_by(target_line_cc); - - assimilate(target_line_cc); - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation param: n.get_parameters() - ) - { - final ComputationCompiler cc; - - cc = new ComputationCompiler(compiler); - - param.get_visited_by(cc); - - assimilate(cc); - - parameters.add(cc.get_computation()); - } - - init_instructions.add - ( - LambdaEvaluation.generate - ( - compiler.registers(), - compiler.assembler(), - target_line_cc.get_computation(), - result_as_address, - parameters - ) - ); - } -*/ @Override public void visit_generic_computation ( @@ -2027,1898 +1092,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor result_as_address = register.get_address(); result_as_computation = register.get_value(); } -/* - @Override - public void visit_car_cdr - ( - final tonkadur.fate.v1.lang.computation.CarCdr n - ) - throws Throwable - { - final ComputationCompiler address_cc; - - address_cc = new ComputationCompiler(compiler); - - n.get_parent().get_visited_by(address_cc); - - assimilate(address_cc); - - result_as_address = - new RelativeAddress - ( - address_cc.get_address(), - new Constant - ( - Type.STRING, - (n.is_car()? "0" : "1") - ), - TypeCompiler.compile(compiler, n.get_type()) - ); - } -*/ -/* - @Override - public void visit_cons - ( - final tonkadur.fate.v1.lang.computation.ConsComputation n - ) - throws Throwable - { - final ComputationCompiler car_compiler, cdr_compiler; - final Register result; - - result = reserve(DictType.WILD); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - car_compiler = new ComputationCompiler(compiler); - - n.get_car().get_visited_by(car_compiler); - - if (car_compiler.has_init()) - { - init_instructions.add(car_compiler.get_init()); - } - - cdr_compiler = new ComputationCompiler(compiler); - - n.get_cdr().get_visited_by(cdr_compiler); - - if (cdr_compiler.has_init()) - { - init_instructions.add(cdr_compiler.get_init()); - } - - init_instructions.add - ( - CreateCons.generate - ( - compiler.registers(), - compiler.assembler(), - result_as_address, - car_compiler.get_computation(), - cdr_compiler.get_computation() - ) - ); - - car_compiler.release_registers(init_instructions); - cdr_compiler.release_registers(init_instructions); - } -*/ -/* - @Override - public void visit_add_element - ( - final tonkadur.fate.v1.lang.computation.AddElementComputation n - ) - throws Throwable - { - final ComputationCompiler address_compiler, element_compiler; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - address_compiler = new ComputationCompiler(compiler); - element_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(address_compiler); - - if (address_compiler.has_init()) - { - init_instructions.add(address_compiler.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, address_compiler.get_computation()) - ); - - address_compiler.release_registers(init_instructions); - - n.get_element().get_visited_by(element_compiler); - assimilate(element_compiler); - - init_instructions.add - ( - AddElement.generate - ( - compiler.registers(), - compiler.assembler(), - element_compiler.get_computation(), - result_as_address, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_collection().get_type() - ).is_set() - ) - ); - } -*/ -/* - @Override - public void visit_add_element_at - ( - final tonkadur.fate.v1.lang.computation.AddElementAtComputation n - ) - throws Throwable - { - final ComputationCompiler address_compiler, index_compiler; - final ComputationCompiler element_compiler; - final Register result, index, collection_size; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - address_compiler = new ComputationCompiler(compiler); - index_compiler = new ComputationCompiler(compiler); - element_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(address_compiler); - - if (address_compiler.has_init()) - { - init_instructions.add(address_compiler.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, address_compiler.get_computation()) - ); - - address_compiler.release_registers(init_instructions); - - n.get_index().get_visited_by(index_compiler); - - index_compiler.generate_address(); - assimilate(index_compiler); - - n.get_element().get_visited_by(element_compiler); - assimilate(element_compiler); - - collection_size = reserve(Type.INT); - index = reserve(Type.INT); - - init_instructions.add - ( - new SetValue - ( - collection_size.get_address(), - new Size(result_as_address) - ) - ); - - init_instructions.add - ( - new SetValue - ( - index.get_address(), - new IfElseComputation - ( - Operation.greater_than - ( - index_compiler.get_computation(), - collection_size.get_value() - ), - collection_size.get_value(), - new IfElseComputation - ( - Operation.less_than - ( - index_compiler.get_computation(), - Constant.ZERO - ), - Constant.ZERO, - index_compiler.get_computation() - ) - ) - ) - ); - - init_instructions.add - ( - InsertAt.generate - ( - compiler.registers(), - compiler.assembler(), - index.get_address(), - element_compiler.get_computation(), - collection_size.get_value(), - result_as_address - ) - ); - } -*/ -/* - @Override - public void visit_remove_elements_of - ( - final tonkadur.fate.v1.lang.computation.RemoveElementsOfComputation n - ) - throws Throwable - { - final ComputationCompiler collection_in_cc, collection_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - collection_cc = new ComputationCompiler(compiler); - - n.get_target_collection().get_visited_by(collection_cc); - - if (collection_cc.has_init()) - { - init_instructions.add(collection_cc.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, collection_cc.get_computation()) - ); - - collection_cc.release_registers(init_instructions); - - collection_in_cc = new ComputationCompiler(compiler); - - n.get_source_collection().get_visited_by(collection_in_cc); - - assimilate(collection_in_cc); - - init_instructions.add - ( - RemoveElementsOf.generate - ( - compiler.registers(), - compiler.assembler(), - collection_in_cc.get_address(), - result_as_address, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_target_collection().get_type() - ).is_set() - ) - ); - } -*/ -/* - @Override - public void visit_add_elements_of - ( - final tonkadur.fate.v1.lang.computation.AddElementsOfComputation n - ) - throws Throwable - { - final ComputationCompiler collection_in_cc, collection_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - collection_cc = new ComputationCompiler(compiler); - - n.get_target_collection().get_visited_by(collection_cc); - - if (collection_cc.has_init()) - { - init_instructions.add(collection_cc.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, collection_cc.get_computation()) - ); - - collection_cc.release_registers(init_instructions); - - collection_in_cc = new ComputationCompiler(compiler); - - n.get_source_collection().get_visited_by(collection_in_cc); - - assimilate(collection_in_cc); - - init_instructions.add - ( - AddElementsOf.generate - ( - compiler.registers(), - compiler.assembler(), - collection_in_cc.get_address(), - result_as_address, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_target_collection().get_type() - ).is_set() - ) - ); - } -*/ -/* - @Override - public void visit_fold - ( - final tonkadur.fate.v1.lang.computation.Fold n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, in_collection_cc, default_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - default_cc = new ComputationCompiler(compiler); - - n.get_initial_value().get_visited_by(default_cc); - - if (default_cc.has_init()) - { - init_instructions.add(default_cc.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, default_cc.get_computation()) - ); - - default_cc.release_registers(init_instructions); - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(in_collection_cc); - - assimilate(in_collection_cc); - - init_instructions.add - ( - Fold.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - result_as_address, - in_collection_cc.get_address(), - n.is_foldl(), - params - ) - ); - } -*/ -/* - @Override - public void visit_map - ( - final tonkadur.fate.v1.lang.computation.MapComputation n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, in_collection_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(in_collection_cc); - - assimilate(in_collection_cc); - - init_instructions.add - ( - MapLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - in_collection_cc.get_address(), - result_as_address, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_collection().get_type() - ).is_set(), - params - ) - ); - } -*/ -/* - @Override - public void visit_range - ( - final tonkadur.fate.v1.lang.computation.Range n - ) - throws Throwable - { - final List<Instruction> while_body; - final ComputationCompiler start_cc, end_cc, inc_cc; - final Register result, iterator, accumulator; - final Address new_element_addr; - - while_body = new ArrayList<Instruction>(); - - result = reserve(MapType.MAP_TO_INT); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - start_cc = new ComputationCompiler(compiler); - end_cc = new ComputationCompiler(compiler); - inc_cc = new ComputationCompiler(compiler); - - n.get_start().get_visited_by(start_cc); - start_cc.generate_address(); - - n.get_end().get_visited_by(end_cc); - end_cc.generate_address(); - - n.get_increment().get_visited_by(inc_cc); - inc_cc.generate_address(); - - assimilate(start_cc); - assimilate(end_cc); - assimilate(inc_cc); - - iterator = reserve(Type.INT); - accumulator = reserve(Type.INT); - - init_instructions.add - ( - new SetValue(iterator.get_address(), Constant.ZERO) - ); - init_instructions.add - ( - new SetValue(accumulator.get_address(), start_cc.get_computation()) - ); - - new_element_addr = - new RelativeAddress - ( - result_as_address, - new Cast(iterator.get_value(), Type.STRING), - Type.INT - ); - - while_body.add(new Initialize(new_element_addr)); - while_body.add - ( - new SetValue(new_element_addr, accumulator.get_value()) - ); - while_body.add - ( - new SetValue - ( - accumulator.get_address(), - Operation.plus(accumulator.get_value(), inc_cc.get_computation()) - ) - ); - while_body.add - ( - new SetValue - ( - iterator.get_address(), - Operation.plus(iterator.get_value(), Constant.ONE) - ) - ); - - init_instructions.add - ( - While.generate - ( - compiler.registers(), - compiler.assembler(), - Operation.or - ( - Operation.and - ( - Operation.greater_than - ( - inc_cc.get_computation(), - Constant.ZERO - ), - Operation.less_equal_than - ( - accumulator.get_value(), - end_cc.get_computation() - ) - ), - Operation.and - ( - Operation.less_equal_than - ( - inc_cc.get_computation(), - Constant.ZERO - ), - Operation.greater_equal_than - ( - accumulator.get_value(), - end_cc.get_computation() - ) - ) - ), - compiler.assembler.merge(while_body) - ) - ); - } -*/ -/* - @Override - public void visit_remove_all_of_element - ( - final tonkadur.fate.v1.lang.computation.RemoveAllOfElementComputation n - ) - throws Throwable - { - final ComputationCompiler address_compiler, target_compiler; - final Address collection_address; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - address_compiler = new ComputationCompiler(compiler); - target_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(address_compiler); - - if (address_compiler.has_init()) - { - init_instructions.add(address_compiler.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, address_compiler.get_computation()) - ); - - address_compiler.release_registers(init_instructions); - - n.get_element().get_visited_by(target_compiler); - - assimilate(target_compiler); - - init_instructions.add - ( - RemoveAllOf.generate - ( - compiler.registers(), - compiler.assembler(), - target_compiler.get_computation(), - new Size(result_as_address), - result_as_address - ) - ); - } -*/ -/* - @Override - public void visit_remove_element_at - ( - final tonkadur.fate.v1.lang.computation.RemoveElementAtComputation n - ) - throws Throwable - { - final ComputationCompiler address_compiler, target_compiler; - final Address collection_address; - final Register result, target_index; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - address_compiler = new ComputationCompiler(compiler); - target_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(address_compiler); - - if (address_compiler.has_init()) - { - init_instructions.add(address_compiler.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, address_compiler.get_computation()) - ); - - address_compiler.release_registers(init_instructions); - - n.get_index().get_visited_by(target_compiler); - - target_compiler.generate_address(); - - assimilate(target_compiler); - - init_instructions.add - ( - RemoveAt.generate - ( - compiler.registers(), - compiler.assembler(), - target_compiler.get_address(), - new Size(result_as_address), - result_as_address - ) - ); - } -*/ -/* - @Override - public void visit_remove_element - ( - final tonkadur.fate.v1.lang.computation.RemoveElementComputation n - ) - throws Throwable - { - final ComputationCompiler elem_cc, collection_cc; - final Register result; - - elem_cc = new ComputationCompiler(compiler); - collection_cc = new ComputationCompiler(compiler); - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - n.get_collection().get_visited_by(collection_cc); - - if (collection_cc.has_init()) - { - init_instructions.add(collection_cc.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, collection_cc.get_computation()) - ); - - collection_cc.release_registers(init_instructions); - - n.get_element().get_visited_by(elem_cc); - - elem_cc.generate_address(); - - assimilate(elem_cc); - - init_instructions.add - ( - RemoveOneOf.generate - ( - compiler.registers(), - compiler.assembler(), - elem_cc.get_computation(), - result_as_address, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_collection().get_type() - ).is_set() - ) - ); - } -*/ -/* - @Override - public void visit_reverse_list - ( - final tonkadur.fate.v1.lang.computation.ReverseListComputation n - ) - throws Throwable - { - final ComputationCompiler address_compiler; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - address_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(address_compiler); - - if (address_compiler.has_init()) - { - init_instructions.add(address_compiler.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, address_compiler.get_computation()) - ); - - address_compiler.release_registers(init_instructions); - - init_instructions.add - ( - ReverseList.generate - ( - compiler.registers(), - compiler.assembler(), - new Size(result_as_address), - result_as_address - ) - ); - } -*/ -/* - @Override - public void visit_shuffle - ( - final tonkadur.fate.v1.lang.computation.ShuffleComputation n - ) - throws Throwable - { - final ComputationCompiler address_compiler; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - address_compiler = new ComputationCompiler(compiler); - n.get_collection().get_visited_by(address_compiler); - - if (address_compiler.has_init()) - { - init_instructions.add(address_compiler.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, address_compiler.get_computation()) - ); - - address_compiler.release_registers(init_instructions); - - init_instructions.add - ( - Shuffle.generate - ( - compiler.registers(), - compiler.assembler(), - result_as_address - ) - ); - } -*/ -/* - private void visit_merge_with_defaults - ( - final tonkadur.fate.v1.lang.computation.MergeComputation n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, default_a_cc, default_b_cc; - final ComputationCompiler in_collection_a_cc, in_collection_b_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - default_a_cc = new ComputationCompiler(compiler); - - n.get_default_a().get_visited_by(default_a_cc); - - default_a_cc.generate_address(); - - assimilate(default_a_cc); - - default_b_cc = new ComputationCompiler(compiler); - - n.get_default_b().get_visited_by(default_b_cc); - - default_b_cc.generate_address(); - - assimilate(default_b_cc); - - in_collection_a_cc = new ComputationCompiler(compiler); - - n.get_collection_in_a().get_visited_by(in_collection_a_cc); - - assimilate(in_collection_a_cc); - - in_collection_b_cc = new ComputationCompiler(compiler); - - n.get_collection_in_b().get_visited_by(in_collection_b_cc); - - assimilate(in_collection_b_cc); - - init_instructions.add - ( - MergeLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - default_a_cc.get_computation(), - in_collection_a_cc.get_address(), - default_b_cc.get_computation(), - in_collection_b_cc.get_address(), - result_as_address, - n.to_set(), - params - ) - ); - } -*/ -/* - @Override - public void visit_merge - ( - final tonkadur.fate.v1.lang.computation.MergeComputation n - ) - throws Throwable - { - if (n.get_default_a() != null) - { - visit_merge_with_defaults(n); - - return; - } - - final List<Computation> params; - final ComputationCompiler lambda_cc; - final ComputationCompiler in_collection_a_cc, in_collection_b_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_a_cc = new ComputationCompiler(compiler); - - n.get_collection_in_a().get_visited_by(in_collection_a_cc); - - assimilate(in_collection_a_cc); - - in_collection_b_cc = new ComputationCompiler(compiler); - - n.get_collection_in_b().get_visited_by(in_collection_b_cc); - - assimilate(in_collection_b_cc); - - init_instructions.add - ( - MergeLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - in_collection_a_cc.get_address(), - in_collection_b_cc.get_address(), - result_as_address, - n.to_set(), - params - ) - ); - } -*/ -/* - private void visit_indexed_merge_with_defaults - ( - final tonkadur.fate.v1.lang.computation.IndexedMergeComputation n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, default_a_cc, default_b_cc; - final ComputationCompiler in_collection_a_cc, in_collection_b_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - default_a_cc = new ComputationCompiler(compiler); - - n.get_default_a().get_visited_by(default_a_cc); - - default_a_cc.generate_address(); - - assimilate(default_a_cc); - - default_b_cc = new ComputationCompiler(compiler); - - n.get_default_b().get_visited_by(default_b_cc); - - default_b_cc.generate_address(); - - assimilate(default_b_cc); - - in_collection_a_cc = new ComputationCompiler(compiler); - - n.get_collection_in_a().get_visited_by(in_collection_a_cc); - - assimilate(in_collection_a_cc); - - in_collection_b_cc = new ComputationCompiler(compiler); - - n.get_collection_in_b().get_visited_by(in_collection_b_cc); - - assimilate(in_collection_b_cc); - - init_instructions.add - ( - IndexedMergeLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - default_a_cc.get_computation(), - in_collection_a_cc.get_address(), - default_b_cc.get_computation(), - in_collection_b_cc.get_address(), - result_as_address, - n.to_set(), - params - ) - ); - } -*/ -/* - @Override - public void visit_indexed_merge - ( - final tonkadur.fate.v1.lang.computation.IndexedMergeComputation n - ) - throws Throwable - { - if (n.get_default_a() != null) - { - visit_indexed_merge_with_defaults(n); - - return; - } - - final List<Computation> params; - final ComputationCompiler lambda_cc; - final ComputationCompiler in_collection_a_cc, in_collection_b_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_a_cc = new ComputationCompiler(compiler); - - n.get_collection_in_a().get_visited_by(in_collection_a_cc); - - assimilate(in_collection_a_cc); - - in_collection_b_cc = new ComputationCompiler(compiler); - - n.get_collection_in_b().get_visited_by(in_collection_b_cc); - - assimilate(in_collection_b_cc); - - init_instructions.add - ( - IndexedMergeLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - in_collection_a_cc.get_address(), - in_collection_b_cc.get_address(), - result_as_address, - n.to_set(), - params - ) - ); - } -*/ -/* - @Override - public void visit_sublist - ( - final tonkadur.fate.v1.lang.computation.SubListComputation n - ) - throws Throwable - { - final ComputationCompiler address_compiler, start_compiler, end_compiler; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - address_compiler = new ComputationCompiler(compiler); - start_compiler = new ComputationCompiler(compiler); - end_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(address_compiler); - - if (address_compiler.has_init()) - { - init_instructions.add(address_compiler.get_init()); - } - - n.get_start_index().get_visited_by(start_compiler); - - if (start_compiler.has_init()) - { - init_instructions.add(start_compiler.get_init()); - } - - n.get_end_index().get_visited_by(end_compiler); - - if (end_compiler.has_init()) - { - init_instructions.add(end_compiler.get_init()); - } - - init_instructions.add - ( - SubList.generate - ( - compiler.registers(), - compiler.assembler(), - start_compiler.get_computation(), - end_compiler.get_computation(), - address_compiler.get_address(), - result_as_address - ) - ); - - start_compiler.release_registers(init_instructions); - end_compiler.release_registers(init_instructions); - address_compiler.release_registers(init_instructions); - } -*/ -/* - @Override - public void visit_partition - ( - final tonkadur.fate.v1.lang.computation.PartitionComputation n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, in_collection_cc; - final Address car_addr, cdr_addr; - final Register result; - - result = reserve(DictType.WILD); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(in_collection_cc); - - if (in_collection_cc.has_init()) - { - init_instructions.add(in_collection_cc.get_init()); - } - - car_addr = - new RelativeAddress - ( - result_as_address, - new Constant(Type.STRING, "0"), - in_collection_cc.get_computation().get_type() - ); - - init_instructions.add - ( - new SetValue - ( - car_addr, - in_collection_cc.get_computation() - ) - ); - - cdr_addr = - new RelativeAddress - ( - result_as_address, - new Constant(Type.STRING, "1"), - in_collection_cc.get_computation().get_type() - ); - - in_collection_cc.release_registers(init_instructions); - - init_instructions.add(new Initialize(cdr_addr)); - - init_instructions.add - ( - PartitionLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - car_addr, - cdr_addr, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_collection().get_type() - ).is_set(), - params - ) - ); - } -*/ -/* - @Override - public void visit_indexed_partition - ( - final tonkadur.fate.v1.lang.computation.IndexedPartitionComputation n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, in_collection_cc; - final Address car_addr, cdr_addr; - final Register result; - - result = reserve(DictType.WILD); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(in_collection_cc); - - if (in_collection_cc.has_init()) - { - init_instructions.add(in_collection_cc.get_init()); - } - - car_addr = - new RelativeAddress - ( - result_as_address, - new Constant(Type.STRING, "0"), - in_collection_cc.get_computation().get_type() - ); - - init_instructions.add - ( - new SetValue - ( - car_addr, - in_collection_cc.get_computation() - ) - ); - - cdr_addr = - new RelativeAddress - ( - result_as_address, - new Constant(Type.STRING, "1"), - in_collection_cc.get_computation().get_type() - ); - - in_collection_cc.release_registers(init_instructions); - - init_instructions.add(new Initialize(cdr_addr)); - - init_instructions.add - ( - IndexedPartitionLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - car_addr, - cdr_addr, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_collection().get_type() - ).is_set(), - params - ) - ); - } -*/ -/* - @Override - public void visit_sort - ( - final tonkadur.fate.v1.lang.computation.SortComputation n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, in_collection_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(in_collection_cc); - - if (in_collection_cc.has_init()) - { - init_instructions.add(in_collection_cc.get_init()); - } - - init_instructions.add - ( - Sort.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - in_collection_cc.get_address(), - result_as_address, - params - ) - ); - - in_collection_cc.release_registers(init_instructions); - } -*/ - -/* - @Override - public void visit_filter - ( - final tonkadur.fate.v1.lang.computation.FilterComputation n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, in_collection_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(in_collection_cc); - - if (in_collection_cc.has_init()) - { - init_instructions.add(in_collection_cc.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, in_collection_cc.get_computation()) - ); - - in_collection_cc.release_registers(init_instructions); - - init_instructions.add - ( - FilterLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - result_as_address, - params - ) - ); - } -*/ -/* - @Override - public void visit_indexed_filter - ( - final tonkadur.fate.v1.lang.computation.IndexedFilterComputation n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, in_collection_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(in_collection_cc); - - if (in_collection_cc.has_init()) - { - init_instructions.add(in_collection_cc.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, in_collection_cc.get_computation()) - ); - - in_collection_cc.release_registers(init_instructions); - - init_instructions.add - ( - IndexedFilterLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - result_as_address, - params - ) - ); - } -*/ -/* - @Override - public void visit_indexed_map - ( - final tonkadur.fate.v1.lang.computation.IndexedMapComputation n - ) - throws Throwable - { - final List<Computation> params; - final ComputationCompiler lambda_cc, in_collection_cc; - final Register result; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - params = new ArrayList<Computation>(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation p: - n.get_extra_parameters() - ) - { - final ComputationCompiler param_cc; - - param_cc = new ComputationCompiler(compiler); - - p.get_visited_by(param_cc); - - // Let's not re-compute the parameters on every iteration. - param_cc.generate_address(); - - assimilate(param_cc); - - params.add(param_cc.get_computation()); - } - - lambda_cc = new ComputationCompiler(compiler); - - n.get_lambda_function().get_visited_by(lambda_cc); - - assimilate(lambda_cc); - - in_collection_cc = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(in_collection_cc); - - assimilate(in_collection_cc); - - init_instructions.add - ( - IndexedMapLambda.generate - ( - compiler.registers(), - compiler.assembler(), - lambda_cc.get_computation(), - in_collection_cc.get_address(), - result_as_address, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_collection().get_type() - ).is_set(), - params - ) - ); - } -*/ -/* - @Override - public void visit_push_element - ( - final tonkadur.fate.v1.lang.computation.PushElementComputation n - ) - throws Throwable - { - final ComputationCompiler address_compiler, element_compiler; - final Register result, collection_size, index; - - result = reserve(TypeCompiler.compile(compiler, n.get_type())); - result_as_address = result.get_address(); - result_as_computation = result.get_value(); - - address_compiler = new ComputationCompiler(compiler); - element_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(address_compiler); - - if (address_compiler.has_init()) - { - init_instructions.add(address_compiler.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, address_compiler.get_computation()) - ); - - address_compiler.release_registers(init_instructions); - - n.get_element().get_visited_by(element_compiler); - - if (element_compiler.has_init()) - { - init_instructions.add(element_compiler.get_init()); - } - - collection_size = reserve(Type.INT); - index = reserve(Type.INT); - - init_instructions.add - ( - new SetValue - ( - collection_size.get_address(), - new Size(result_as_address) - ) - ); - - init_instructions.add - ( - new SetValue - ( - index.get_address(), - (n.is_from_left() ? Constant.ZERO : collection_size.get_value()) - ) - ); - - init_instructions.add - ( - InsertAt.generate - ( - compiler.registers(), - compiler.assembler(), - index.get_address(), - element_compiler.get_computation(), - collection_size.get_value(), - result_as_address - ) - ); - - element_compiler.release_registers(init_instructions); - } -*/ -/* - @Override - public void visit_pop_element - ( - final tonkadur.fate.v1.lang.computation.PopElementComputation n - ) - throws Throwable - { - final ComputationCompiler address_compiler; - final Register result; - final Address car_addr, cdr_addr; - - result = reserve(DictType.WILD); - result_as_computation = result.get_value(); - result_as_address = result.get_address(); - - address_compiler = new ComputationCompiler(compiler); - - n.get_collection().get_visited_by(address_compiler); - - if (address_compiler.has_init()) - { - init_instructions.add(address_compiler.get_init()); - } - - init_instructions.add - ( - new SetValue(result_as_address, address_compiler.get_computation()) - ); - - car_addr = - new RelativeAddress - ( - result_as_address, - new Constant(Type.STRING, "0"), - address_compiler.get_computation().get_type() - ); - - init_instructions.add - ( - new SetValue - ( - car_addr, - address_compiler.get_computation() - ) - ); - - address_compiler.release_registers(init_instructions); - - cdr_addr = - new RelativeAddress - ( - result_as_address, - new Constant(Type.STRING, "1"), - TypeCompiler.compile - ( - compiler, - ( - (tonkadur.fate.v1.lang.type.CollectionType) - n.get_collection().get_type() - ).get_content_type() - ) - ); - - init_instructions.add(new Initialize(cdr_addr)); - - init_instructions.add - ( - PopElement.generate - ( - compiler.registers(), - compiler.assembler(), - car_addr, - cdr_addr, - n.is_from_left() - ) - ); - } -*/ @Override public void visit_set_fields ( diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AccessCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AccessCompiler.java new file mode 100644 index 0000000..1960da0 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AccessCompiler.java @@ -0,0 +1,65 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.Access; + +import tonkadur.wyrd.v1.lang.computation.Cast; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class AccessCompiler extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return Access.class; + } + + public AccessCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final Access source; + final ComputationCompiler extra_address_cc, base_address_cc; + + source = (Access) computation; + + base_address_cc = new ComputationCompiler(compiler); + extra_address_cc = new ComputationCompiler(compiler); + + source.get_parent().get_visited_by(base_address_cc); + source.get_index().get_visited_by(extra_address_cc); + + base_address_cc.generate_address(); + + assimilate(base_address_cc); + assimilate(extra_address_cc); + + result_as_address = + new RelativeAddress + ( + base_address_cc.get_address(), + new Cast(extra_address_cc.get_computation(), Type.STRING), + TypeCompiler.compile + ( + compiler, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_parent().get_type() + ).get_content_type() + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AddElementAtComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AddElementAtComputationCompiler.java new file mode 100644 index 0000000..dd774f5 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AddElementAtComputationCompiler.java @@ -0,0 +1,130 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.AddElementAtComputation; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.IfElseComputation; +import tonkadur.wyrd.v1.lang.computation.Operation; +import tonkadur.wyrd.v1.lang.computation.Size; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class AddElementAtComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return AddElementAtComputation.class; + } + + public AddElementAtComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final AddElementAtComputation source; + final ComputationCompiler address_compiler, index_compiler; + final ComputationCompiler element_compiler; + final Register result, index, collection_size; + + source = (AddElementAtComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + address_compiler = new ComputationCompiler(compiler); + index_compiler = new ComputationCompiler(compiler); + element_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(address_compiler); + + if (address_compiler.has_init()) + { + init_instructions.add(address_compiler.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, address_compiler.get_computation()) + ); + + address_compiler.release_registers(init_instructions); + + source.get_index().get_visited_by(index_compiler); + + index_compiler.generate_address(); + assimilate(index_compiler); + + source.get_element().get_visited_by(element_compiler); + assimilate(element_compiler); + + collection_size = reserve(Type.INT); + index = reserve(Type.INT); + + init_instructions.add + ( + new SetValue + ( + collection_size.get_address(), + new Size(result_as_address) + ) + ); + + init_instructions.add + ( + new SetValue + ( + index.get_address(), + new IfElseComputation + ( + Operation.greater_than + ( + index_compiler.get_computation(), + collection_size.get_value() + ), + collection_size.get_value(), + new IfElseComputation + ( + Operation.less_than + ( + index_compiler.get_computation(), + Constant.ZERO + ), + Constant.ZERO, + index_compiler.get_computation() + ) + ) + ) + ); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.InsertAt.generate + ( + compiler.registers(), + compiler.assembler(), + index.get_address(), + element_compiler.get_computation(), + collection_size.get_value(), + result_as_address + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AddElementComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AddElementComputationCompiler.java new file mode 100644 index 0000000..b1a3742 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AddElementComputationCompiler.java @@ -0,0 +1,82 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.AddElementComputation; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class AddElementComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return AddElementComputation.class; + } + + public AddElementComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final AddElementComputation source; + final ComputationCompiler address_compiler, element_compiler; + final Register result; + + source = (AddElementComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + address_compiler = new ComputationCompiler(compiler); + element_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(address_compiler); + + if (address_compiler.has_init()) + { + init_instructions.add(address_compiler.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, address_compiler.get_computation()) + ); + + address_compiler.release_registers(init_instructions); + + source.get_element().get_visited_by(element_compiler); + assimilate(element_compiler); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.AddElement.generate + ( + compiler.registers(), + compiler.assembler(), + element_compiler.get_computation(), + result_as_address, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_collection().get_type() + ).is_set() + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AddElementsOfComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AddElementsOfComputationCompiler.java new file mode 100644 index 0000000..4e57413 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/AddElementsOfComputationCompiler.java @@ -0,0 +1,84 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.AddElementsOfComputation; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class AddElementsOfComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return AddElementsOfComputation.class; + } + + public AddElementsOfComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final AddElementsOfComputation source; + final ComputationCompiler collection_in_cc, collection_cc; + final Register result; + + source = (AddElementsOfComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + collection_cc = new ComputationCompiler(compiler); + + source.get_target_collection().get_visited_by(collection_cc); + + if (collection_cc.has_init()) + { + init_instructions.add(collection_cc.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, collection_cc.get_computation()) + ); + + collection_cc.release_registers(init_instructions); + + collection_in_cc = new ComputationCompiler(compiler); + + source.get_source_collection().get_visited_by(collection_in_cc); + + assimilate(collection_in_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.AddElementsOf.generate + ( + compiler.registers(), + compiler.assembler(), + collection_in_cc.get_address(), + result_as_address, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_target_collection().get_type() + ).is_set() + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/CarCdrCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/CarCdrCompiler.java new file mode 100644 index 0000000..81a458a --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/CarCdrCompiler.java @@ -0,0 +1,58 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.CarCdr; + +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class CarCdrCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return CarCdr.class; + } + + public CarCdrCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final CarCdr source; + final ComputationCompiler address_cc; + + source = (CarCdr) computation; + + address_cc = new ComputationCompiler(compiler); + + source.get_parent().get_visited_by(address_cc); + + assimilate(address_cc); + + result_as_address = + new RelativeAddress + ( + address_cc.get_address(), + new Constant + ( + Type.STRING, + (source.is_car()? "0" : "1") + ), + TypeCompiler.compile(compiler, source.get_type()) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/ConsComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/ConsComputationCompiler.java new file mode 100644 index 0000000..8d73c6a --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/ConsComputationCompiler.java @@ -0,0 +1,77 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.ConsComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.type.DictType; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class ConsComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return ConsComputation.class; + } + + public ConsComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final ConsComputation source; + final ComputationCompiler car_compiler, cdr_compiler; + final Register result; + + source = (ConsComputation) computation; + + result = reserve(DictType.WILD); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + car_compiler = new ComputationCompiler(compiler); + + source.get_car().get_visited_by(car_compiler); + + if (car_compiler.has_init()) + { + init_instructions.add(car_compiler.get_init()); + } + + cdr_compiler = new ComputationCompiler(compiler); + + source.get_cdr().get_visited_by(cdr_compiler); + + if (cdr_compiler.has_init()) + { + init_instructions.add(cdr_compiler.get_init()); + } + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.CreateCons.generate + ( + compiler.registers(), + compiler.assembler(), + result_as_address, + car_compiler.get_computation(), + cdr_compiler.get_computation() + ) + ); + + car_compiler.release_registers(init_instructions); + cdr_compiler.release_registers(init_instructions); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/CountOperatorCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/CountOperatorCompiler.java new file mode 100644 index 0000000..ed2e3fb --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/CountOperatorCompiler.java @@ -0,0 +1,132 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.CountOperator; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.computation.Size; +import tonkadur.wyrd.v1.lang.computation.IfElseComputation; +import tonkadur.wyrd.v1.lang.computation.Constant; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class CountOperatorCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return CountOperator.class; + } + + public CountOperatorCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final CountOperator source; + final ComputationCompiler collection_compiler, element_compiler; + + source = (CountOperator) computation; + + collection_compiler = new ComputationCompiler(compiler); + element_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(collection_compiler); + source.get_element().get_visited_by(element_compiler); + + collection_compiler.generate_address(); + + assimilate(collection_compiler); + assimilate(element_compiler); + + if + ( + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_collection().get_type() + ).is_set() + ) + { + final Register was_found, index, element; + + was_found = reserve(Type.BOOL); + index = reserve(Type.INT); + element = reserve(element_compiler.get_computation().get_type()); + + init_instructions.add + ( + new SetValue + ( + element.get_address(), + element_compiler.get_computation() + ) + ); + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.BinarySearch.generate + ( + compiler.registers(), + compiler.assembler(), + element.get_value(), + new Size(collection_compiler.get_address()), + collection_compiler.get_address(), + was_found.get_address(), + index.get_address() + ) + ); + + result_as_computation = + new IfElseComputation + ( + was_found.get_value(), + Constant.ONE, + Constant.ZERO + ); + } + else + { + final Register result, element; + + result = reserve(Type.INT); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + element = reserve(element_compiler.get_computation().get_type()); + + init_instructions.add + ( + new SetValue + ( + element.get_address(), + element_compiler.get_computation() + ) + ); + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.CountOccurrences.generate + ( + compiler.registers(), + compiler.assembler(), + element.get_value(), + new Size(collection_compiler.get_address()), + collection_compiler.get_address(), + result_as_address + ) + ); + } + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/FilterComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/FilterComputationCompiler.java new file mode 100644 index 0000000..b2123f7 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/FilterComputationCompiler.java @@ -0,0 +1,110 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.fate.v1.lang.computation.generic.FilterComputation; + + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class FilterComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return FilterComputation.class; + } + + public FilterComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final FilterComputation source; + final List<Computation> params; + final ComputationCompiler lambda_cc, in_collection_cc; + final Register result; + + source = (FilterComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(in_collection_cc); + + if (in_collection_cc.has_init()) + { + init_instructions.add(in_collection_cc.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, in_collection_cc.get_computation()) + ); + + in_collection_cc.release_registers(init_instructions); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.FilterLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + result_as_address, + params + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/FoldCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/FoldCompiler.java new file mode 100644 index 0000000..9dc4106 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/FoldCompiler.java @@ -0,0 +1,118 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.fate.v1.lang.computation.generic.Fold; + + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class FoldCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return Fold.class; + } + + public FoldCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final Fold source; + final List<Computation> params; + final ComputationCompiler lambda_cc, in_collection_cc, default_cc; + final Register result; + + source = (Fold) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + default_cc = new ComputationCompiler(compiler); + + source.get_initial_value().get_visited_by(default_cc); + + if (default_cc.has_init()) + { + init_instructions.add(default_cc.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, default_cc.get_computation()) + ); + + default_cc.release_registers(init_instructions); + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(in_collection_cc); + + assimilate(in_collection_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.Fold.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + result_as_address, + in_collection_cc.get_address(), + source.is_foldl(), + params + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexOfOperatorCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexOfOperatorCompiler.java new file mode 100644 index 0000000..61b8b05 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexOfOperatorCompiler.java @@ -0,0 +1,70 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.IndexOfOperator; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.computation.Size; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class IndexOfOperatorCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return IndexOfOperator.class; + } + + public IndexOfOperatorCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final IndexOfOperator source; + final ComputationCompiler elem_cc, collection_cc; + final Register result, result_found; + + source = (IndexOfOperator) computation; + + result = reserve(Type.INT); + result_found = reserve(Type.BOOL); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + elem_cc = new ComputationCompiler(compiler); + collection_cc = new ComputationCompiler(compiler); + + source.get_element().get_visited_by(elem_cc); + source.get_collection().get_visited_by(collection_cc); + + assimilate(elem_cc); + assimilate(collection_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.IterativeSearch.generate + ( + compiler.registers(), + compiler.assembler(), + elem_cc.get_computation(), + new Size(collection_cc.get_address()), + collection_cc.get_address(), + result_found.get_address(), + result_as_address + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedFilterComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedFilterComputationCompiler.java new file mode 100644 index 0000000..6ebcd62 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedFilterComputationCompiler.java @@ -0,0 +1,109 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.fate.v1.lang.computation.generic.IndexedFilterComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class IndexedFilterComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return IndexedFilterComputation.class; + } + + public IndexedFilterComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final IndexedFilterComputation source; + final List<Computation> params; + final ComputationCompiler lambda_cc, in_collection_cc; + final Register result; + + source = (IndexedFilterComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(in_collection_cc); + + if (in_collection_cc.has_init()) + { + init_instructions.add(in_collection_cc.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, in_collection_cc.get_computation()) + ); + + in_collection_cc.release_registers(init_instructions); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.IndexedFilterLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + result_as_address, + params + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedMapComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedMapComputationCompiler.java new file mode 100644 index 0000000..c5b5e3c --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedMapComputationCompiler.java @@ -0,0 +1,105 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.fate.v1.lang.computation.generic.IndexedMapComputation; + + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class IndexedMapComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return IndexedMapComputation.class; + } + + public IndexedMapComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final IndexedMapComputation source; + final List<Computation> params; + final ComputationCompiler lambda_cc, in_collection_cc; + final Register result; + + source = (IndexedMapComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(in_collection_cc); + + assimilate(in_collection_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.IndexedMapLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + in_collection_cc.get_address(), + result_as_address, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_collection().get_type() + ).is_set(), + params + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedMergeComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedMergeComputationCompiler.java new file mode 100644 index 0000000..a327d68 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedMergeComputationCompiler.java @@ -0,0 +1,213 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.fate.v1.lang.computation.generic.IndexedMergeComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class IndexedMergeComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return IndexedMergeComputation.class; + } + + public IndexedMergeComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + protected void compile_with_defaults (final IndexedMergeComputation source) + throws Throwable + { + final List<Computation> params; + final ComputationCompiler lambda_cc, default_a_cc, default_b_cc; + final ComputationCompiler in_collection_a_cc, in_collection_b_cc; + final Register result; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + default_a_cc = new ComputationCompiler(compiler); + + source.get_default_a().get_visited_by(default_a_cc); + + default_a_cc.generate_address(); + + assimilate(default_a_cc); + + default_b_cc = new ComputationCompiler(compiler); + + source.get_default_b().get_visited_by(default_b_cc); + + default_b_cc.generate_address(); + + assimilate(default_b_cc); + + in_collection_a_cc = new ComputationCompiler(compiler); + + source.get_collection_in_a().get_visited_by(in_collection_a_cc); + + assimilate(in_collection_a_cc); + + in_collection_b_cc = new ComputationCompiler(compiler); + + source.get_collection_in_b().get_visited_by(in_collection_b_cc); + + assimilate(in_collection_b_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.IndexedMergeLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + default_a_cc.get_computation(), + in_collection_a_cc.get_address(), + default_b_cc.get_computation(), + in_collection_b_cc.get_address(), + result_as_address, + source.to_set(), + params + ) + ); + } + + protected void compile_without_defaults + ( + final IndexedMergeComputation source + ) + throws Throwable + { + final List<Computation> params; + final ComputationCompiler lambda_cc; + final ComputationCompiler in_collection_a_cc, in_collection_b_cc; + final Register result; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_a_cc = new ComputationCompiler(compiler); + + source.get_collection_in_a().get_visited_by(in_collection_a_cc); + + assimilate(in_collection_a_cc); + + in_collection_b_cc = new ComputationCompiler(compiler); + + source.get_collection_in_b().get_visited_by(in_collection_b_cc); + + assimilate(in_collection_b_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.IndexedMergeLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + in_collection_a_cc.get_address(), + in_collection_b_cc.get_address(), + result_as_address, + source.to_set(), + params + ) + ); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final IndexedMergeComputation source; + + source = (IndexedMergeComputation) computation; + + if (source.get_default_a() == null) + { + compile_without_defaults(source); + } + else + { + compile_with_defaults(source); + } + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedPartitionComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedPartitionComputationCompiler.java new file mode 100644 index 0000000..196ae37 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IndexedPartitionComputationCompiler.java @@ -0,0 +1,144 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.fate.v1.lang.computation.generic.IndexedPartitionComputation; + + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.lang.instruction.Initialize; + +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.type.Type; +import tonkadur.wyrd.v1.lang.type.DictType; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class IndexedPartitionComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return IndexedPartitionComputation.class; + } + + public IndexedPartitionComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final IndexedPartitionComputation source; + final List<Computation> params; + final ComputationCompiler lambda_cc, in_collection_cc; + final Address car_addr, cdr_addr; + final Register result; + + source = (IndexedPartitionComputation) computation; + + result = reserve(DictType.WILD); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(in_collection_cc); + + if (in_collection_cc.has_init()) + { + init_instructions.add(in_collection_cc.get_init()); + } + + car_addr = + new RelativeAddress + ( + result_as_address, + new Constant(Type.STRING, "0"), + in_collection_cc.get_computation().get_type() + ); + + init_instructions.add + ( + new SetValue + ( + car_addr, + in_collection_cc.get_computation() + ) + ); + + cdr_addr = + new RelativeAddress + ( + result_as_address, + new Constant(Type.STRING, "1"), + in_collection_cc.get_computation().get_type() + ); + + in_collection_cc.release_registers(init_instructions); + + init_instructions.add(new Initialize(cdr_addr)); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.IndexedPartitionLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + car_addr, + cdr_addr, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_collection().get_type() + ).is_set(), + params + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IsEmptyCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IsEmptyCompiler.java new file mode 100644 index 0000000..80bbe9a --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IsEmptyCompiler.java @@ -0,0 +1,47 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.IsEmpty; + +import tonkadur.wyrd.v1.lang.computation.Size; +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.Operation; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class IsEmptyCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return IsEmpty.class; + } + + public IsEmptyCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final IsEmpty source; + final ComputationCompiler cc; + + source = (IsEmpty) computation; + + cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(cc); + + assimilate(cc); + + result_as_computation = + Operation.equals(new Size(cc.get_address()), Constant.ZERO); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IsMemberOperatorCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IsMemberOperatorCompiler.java new file mode 100644 index 0000000..e5e1925 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/IsMemberOperatorCompiler.java @@ -0,0 +1,124 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.IsMemberOperator; + +import tonkadur.wyrd.v1.lang.computation.Size; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class IsMemberOperatorCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return IsMemberOperator.class; + } + + public IsMemberOperatorCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final IsMemberOperator source; + final Register result; + final ComputationCompiler collection_compiler, element_compiler; + + source = (IsMemberOperator) computation; + + collection_compiler = new ComputationCompiler(compiler); + element_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(collection_compiler); + source.get_element().get_visited_by(element_compiler); + + collection_compiler.generate_address(); + + assimilate(collection_compiler); + assimilate(element_compiler); + + result = reserve(Type.BOOL); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + if + ( + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_collection().get_type() + ).is_set() + ) + { + final Register index, element; + + index = reserve(Type.INT); + element = reserve(element_compiler.get_computation().get_type()); + + init_instructions.add + ( + new SetValue + ( + element.get_address(), + element_compiler.get_computation() + ) + ); + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.BinarySearch.generate + ( + compiler.registers(), + compiler.assembler(), + element.get_value(), + new Size(collection_compiler.get_address()), + collection_compiler.get_address(), + result_as_address, + index.get_address() + ) + ); + + } + else + { + final Register index, element; + + index = reserve(Type.INT); + element = reserve(element_compiler.get_computation().get_type()); + + init_instructions.add + ( + new SetValue + ( + element.get_address(), + element_compiler.get_computation() + ) + ); + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.IterativeSearch.generate + ( + compiler.registers(), + compiler.assembler(), + element.get_value(), + new Size(collection_compiler.get_address()), + collection_compiler.get_address(), + result_as_address, + index.get_address() + ) + ); + } + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/LambdaEvaluationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/LambdaEvaluationCompiler.java index c914d0c..fb74eb9 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/LambdaEvaluationCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/LambdaEvaluationCompiler.java @@ -44,7 +44,6 @@ public class LambdaEvaluationCompiler extends GenericComputationCompiler source = (LambdaEvaluation) computation; - parameters = new ArrayList<Computation>(); target_line_cc = new ComputationCompiler(compiler); diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/MapComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/MapComputationCompiler.java new file mode 100644 index 0000000..459936f --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/MapComputationCompiler.java @@ -0,0 +1,102 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.fate.v1.lang.computation.generic.MapComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class MapComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return MapComputation.class; + } + + public MapComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final MapComputation source; + final List<Computation> params; + final ComputationCompiler lambda_cc, in_collection_cc; + final Register result; + + source = (MapComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(in_collection_cc); + + assimilate(in_collection_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.MapLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + in_collection_cc.get_address(), + result_as_address, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_collection().get_type() + ).is_set(), + params + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/MergeComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/MergeComputationCompiler.java new file mode 100644 index 0000000..d0cde2f --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/MergeComputationCompiler.java @@ -0,0 +1,208 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.fate.v1.lang.computation.generic.MergeComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class MergeComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return MergeComputation.class; + } + + public MergeComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + protected void compile_with_defaults (final MergeComputation source) + throws Throwable + { + final List<Computation> params; + final ComputationCompiler lambda_cc, default_a_cc, default_b_cc; + final ComputationCompiler in_collection_a_cc, in_collection_b_cc; + final Register result; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + default_a_cc = new ComputationCompiler(compiler); + + source.get_default_a().get_visited_by(default_a_cc); + + default_a_cc.generate_address(); + + assimilate(default_a_cc); + + default_b_cc = new ComputationCompiler(compiler); + + source.get_default_b().get_visited_by(default_b_cc); + + default_b_cc.generate_address(); + + assimilate(default_b_cc); + + in_collection_a_cc = new ComputationCompiler(compiler); + + source.get_collection_in_a().get_visited_by(in_collection_a_cc); + + assimilate(in_collection_a_cc); + + in_collection_b_cc = new ComputationCompiler(compiler); + + source.get_collection_in_b().get_visited_by(in_collection_b_cc); + + assimilate(in_collection_b_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.MergeLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + default_a_cc.get_computation(), + in_collection_a_cc.get_address(), + default_b_cc.get_computation(), + in_collection_b_cc.get_address(), + result_as_address, + source.to_set(), + params + ) + ); + } + + protected void compile_without_defaults (final MergeComputation source) + throws Throwable + { + final List<Computation> params; + final ComputationCompiler lambda_cc; + final ComputationCompiler in_collection_a_cc, in_collection_b_cc; + final Register result; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_a_cc = new ComputationCompiler(compiler); + + source.get_collection_in_a().get_visited_by(in_collection_a_cc); + + assimilate(in_collection_a_cc); + + in_collection_b_cc = new ComputationCompiler(compiler); + + source.get_collection_in_b().get_visited_by(in_collection_b_cc); + + assimilate(in_collection_b_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.MergeLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + in_collection_a_cc.get_address(), + in_collection_b_cc.get_address(), + result_as_address, + source.to_set(), + params + ) + ); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final MergeComputation source; + + source = (MergeComputation) computation; + + if (source.get_default_a() == null) + { + compile_without_defaults(source); + } + else + { + compile_with_defaults(source); + } + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/PartitionComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/PartitionComputationCompiler.java new file mode 100644 index 0000000..d66c1dd --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/PartitionComputationCompiler.java @@ -0,0 +1,144 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.fate.v1.lang.computation.generic.PartitionComputation; + + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.lang.instruction.Initialize; + +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.type.Type; +import tonkadur.wyrd.v1.lang.type.DictType; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class PartitionComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return PartitionComputation.class; + } + + public PartitionComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final PartitionComputation source; + final List<Computation> params; + final ComputationCompiler lambda_cc, in_collection_cc; + final Address car_addr, cdr_addr; + final Register result; + + source = (PartitionComputation) computation; + + result = reserve(DictType.WILD); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(in_collection_cc); + + if (in_collection_cc.has_init()) + { + init_instructions.add(in_collection_cc.get_init()); + } + + car_addr = + new RelativeAddress + ( + result_as_address, + new Constant(Type.STRING, "0"), + in_collection_cc.get_computation().get_type() + ); + + init_instructions.add + ( + new SetValue + ( + car_addr, + in_collection_cc.get_computation() + ) + ); + + cdr_addr = + new RelativeAddress + ( + result_as_address, + new Constant(Type.STRING, "1"), + in_collection_cc.get_computation().get_type() + ); + + in_collection_cc.release_registers(init_instructions); + + init_instructions.add(new Initialize(cdr_addr)); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.PartitionLambda.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + car_addr, + cdr_addr, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_collection().get_type() + ).is_set(), + params + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/PopElementComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/PopElementComputationCompiler.java new file mode 100644 index 0000000..b6a0e1b --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/PopElementComputationCompiler.java @@ -0,0 +1,115 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.PopElementComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.lang.instruction.Initialize; + +import tonkadur.wyrd.v1.lang.type.DictType; +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; +import tonkadur.wyrd.v1.lang.computation.Constant; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class PopElementComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return PopElementComputation.class; + } + + public PopElementComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final PopElementComputation source; + final ComputationCompiler address_compiler; + final Register result; + final Address car_addr, cdr_addr; + + source = (PopElementComputation) computation; + + result = reserve(DictType.WILD); + result_as_computation = result.get_value(); + result_as_address = result.get_address(); + + address_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(address_compiler); + + if (address_compiler.has_init()) + { + init_instructions.add(address_compiler.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, address_compiler.get_computation()) + ); + + car_addr = + new RelativeAddress + ( + result_as_address, + new Constant(Type.STRING, "0"), + address_compiler.get_computation().get_type() + ); + + init_instructions.add + ( + new SetValue + ( + car_addr, + address_compiler.get_computation() + ) + ); + + address_compiler.release_registers(init_instructions); + + cdr_addr = + new RelativeAddress + ( + result_as_address, + new Constant(Type.STRING, "1"), + TypeCompiler.compile + ( + compiler, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_collection().get_type() + ).get_content_type() + ) + ); + + init_instructions.add(new Initialize(cdr_addr)); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.PopElement.generate + ( + compiler.registers(), + compiler.assembler(), + car_addr, + cdr_addr, + source.is_from_left() + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/PushElementComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/PushElementComputationCompiler.java new file mode 100644 index 0000000..7b7169e --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/PushElementComputationCompiler.java @@ -0,0 +1,113 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.PushElementComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.computation.Size; +import tonkadur.wyrd.v1.lang.computation.Constant; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class PushElementComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return PushElementComputation.class; + } + + public PushElementComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final PushElementComputation source; + final ComputationCompiler address_compiler, element_compiler; + final Register result, collection_size, index; + + source = (PushElementComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + address_compiler = new ComputationCompiler(compiler); + element_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(address_compiler); + + if (address_compiler.has_init()) + { + init_instructions.add(address_compiler.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, address_compiler.get_computation()) + ); + + address_compiler.release_registers(init_instructions); + + source.get_element().get_visited_by(element_compiler); + + if (element_compiler.has_init()) + { + init_instructions.add(element_compiler.get_init()); + } + + collection_size = reserve(Type.INT); + index = reserve(Type.INT); + + init_instructions.add + ( + new SetValue + ( + collection_size.get_address(), + new Size(result_as_address) + ) + ); + + init_instructions.add + ( + new SetValue + ( + index.get_address(), + ( + source.is_from_left() ? + Constant.ZERO : + collection_size.get_value() + ) + ) + ); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.InsertAt.generate + ( + compiler.registers(), + compiler.assembler(), + index.get_address(), + element_compiler.get_computation(), + collection_size.get_value(), + result_as_address + ) + ); + + element_compiler.release_registers(init_instructions); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RangeCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RangeCompiler.java new file mode 100644 index 0000000..a6abeb3 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RangeCompiler.java @@ -0,0 +1,160 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.ArrayList; +import java.util.List; + +import tonkadur.fate.v1.lang.computation.generic.Range; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.lang.instruction.Initialize; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; +import tonkadur.wyrd.v1.lang.computation.Cast; +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.Operation; + +import tonkadur.wyrd.v1.lang.meta.Instruction; + +import tonkadur.wyrd.v1.lang.type.Type; +import tonkadur.wyrd.v1.lang.type.MapType; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class RangeCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return Range.class; + } + + public RangeCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final Range source; + final List<Instruction> while_body; + final ComputationCompiler start_cc, end_cc, inc_cc; + final Register result, iterator, accumulator; + final Address new_element_addr; + + source = (Range) computation; + + while_body = new ArrayList<Instruction>(); + + result = reserve(MapType.MAP_TO_INT); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + start_cc = new ComputationCompiler(compiler); + end_cc = new ComputationCompiler(compiler); + inc_cc = new ComputationCompiler(compiler); + + source.get_start().get_visited_by(start_cc); + start_cc.generate_address(); + + source.get_end().get_visited_by(end_cc); + end_cc.generate_address(); + + source.get_increment().get_visited_by(inc_cc); + inc_cc.generate_address(); + + assimilate(start_cc); + assimilate(end_cc); + assimilate(inc_cc); + + iterator = reserve(Type.INT); + accumulator = reserve(Type.INT); + + init_instructions.add + ( + new SetValue(iterator.get_address(), Constant.ZERO) + ); + init_instructions.add + ( + new SetValue(accumulator.get_address(), start_cc.get_computation()) + ); + + new_element_addr = + new RelativeAddress + ( + result_as_address, + new Cast(iterator.get_value(), Type.STRING), + Type.INT + ); + + while_body.add(new Initialize(new_element_addr)); + while_body.add + ( + new SetValue(new_element_addr, accumulator.get_value()) + ); + while_body.add + ( + new SetValue + ( + accumulator.get_address(), + Operation.plus(accumulator.get_value(), inc_cc.get_computation()) + ) + ); + while_body.add + ( + new SetValue + ( + iterator.get_address(), + Operation.plus(iterator.get_value(), Constant.ONE) + ) + ); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.While.generate + ( + compiler.registers(), + compiler.assembler(), + Operation.or + ( + Operation.and + ( + Operation.greater_than + ( + inc_cc.get_computation(), + Constant.ZERO + ), + Operation.less_equal_than + ( + accumulator.get_value(), + end_cc.get_computation() + ) + ), + Operation.and + ( + Operation.less_equal_than + ( + inc_cc.get_computation(), + Constant.ZERO + ), + Operation.greater_equal_than + ( + accumulator.get_value(), + end_cc.get_computation() + ) + ) + ), + compiler.assembler().merge(while_body) + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveAllOfElementComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveAllOfElementComputationCompiler.java new file mode 100644 index 0000000..651f4aa --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveAllOfElementComputationCompiler.java @@ -0,0 +1,81 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.RemoveAllOfElementComputation; + +import tonkadur.wyrd.v1.lang.computation.Size; +import tonkadur.wyrd.v1.lang.computation.Address; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class RemoveAllOfElementComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return RemoveAllOfElementComputation.class; + } + + public RemoveAllOfElementComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final RemoveAllOfElementComputation source; + final ComputationCompiler address_compiler, target_compiler; + final Address collection_address; + final Register result; + + source = (RemoveAllOfElementComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + address_compiler = new ComputationCompiler(compiler); + target_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(address_compiler); + + if (address_compiler.has_init()) + { + init_instructions.add(address_compiler.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, address_compiler.get_computation()) + ); + + address_compiler.release_registers(init_instructions); + + source.get_element().get_visited_by(target_compiler); + + assimilate(target_compiler); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.RemoveAllOf.generate + ( + compiler.registers(), + compiler.assembler(), + target_compiler.get_computation(), + new Size(result_as_address), + result_as_address + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveElementAtComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveElementAtComputationCompiler.java new file mode 100644 index 0000000..2670814 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveElementAtComputationCompiler.java @@ -0,0 +1,83 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.RemoveElementAtComputation; + +import tonkadur.wyrd.v1.lang.computation.Size; +import tonkadur.wyrd.v1.lang.computation.Address; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class RemoveElementAtComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return RemoveElementAtComputation.class; + } + + public RemoveElementAtComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final RemoveElementAtComputation source; + final ComputationCompiler address_compiler, target_compiler; + final Address collection_address; + final Register result, target_index; + + source = (RemoveElementAtComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + address_compiler = new ComputationCompiler(compiler); + target_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(address_compiler); + + if (address_compiler.has_init()) + { + init_instructions.add(address_compiler.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, address_compiler.get_computation()) + ); + + address_compiler.release_registers(init_instructions); + + source.get_index().get_visited_by(target_compiler); + + target_compiler.generate_address(); + + assimilate(target_compiler); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.RemoveAt.generate + ( + compiler.registers(), + compiler.assembler(), + target_compiler.get_address(), + new Size(result_as_address), + result_as_address + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveElementComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveElementComputationCompiler.java new file mode 100644 index 0000000..4a5d4c8 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveElementComputationCompiler.java @@ -0,0 +1,82 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.RemoveElementComputation; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class RemoveElementComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return RemoveElementComputation.class; + } + + public RemoveElementComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final RemoveElementComputation source; + final ComputationCompiler elem_cc, collection_cc; + final Register result; + + source = (RemoveElementComputation) computation; + + elem_cc = new ComputationCompiler(compiler); + collection_cc = new ComputationCompiler(compiler); + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + source.get_collection().get_visited_by(collection_cc); + + if (collection_cc.has_init()) + { + init_instructions.add(collection_cc.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, collection_cc.get_computation()) + ); + + collection_cc.release_registers(init_instructions); + + source.get_element().get_visited_by(elem_cc); + + elem_cc.generate_address(); + + assimilate(elem_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.RemoveOneOf.generate + ( + compiler.registers(), + compiler.assembler(), + elem_cc.get_computation(), + result_as_address, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_collection().get_type() + ).is_set() + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveElementsOfComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveElementsOfComputationCompiler.java new file mode 100644 index 0000000..6415dac --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/RemoveElementsOfComputationCompiler.java @@ -0,0 +1,85 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.RemoveElementsOfComputation; + +import tonkadur.wyrd.v1.lang.computation.Size; +import tonkadur.wyrd.v1.lang.computation.Address; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class RemoveElementsOfComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return RemoveElementsOfComputation.class; + } + + public RemoveElementsOfComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final RemoveElementsOfComputation source; + final ComputationCompiler collection_in_cc, collection_cc; + final Register result; + + source = (RemoveElementsOfComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + collection_cc = new ComputationCompiler(compiler); + + source.get_target_collection().get_visited_by(collection_cc); + + if (collection_cc.has_init()) + { + init_instructions.add(collection_cc.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, collection_cc.get_computation()) + ); + + collection_cc.release_registers(init_instructions); + + collection_in_cc = new ComputationCompiler(compiler); + + source.get_source_collection().get_visited_by(collection_in_cc); + + assimilate(collection_in_cc); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.RemoveElementsOf.generate + ( + compiler.registers(), + compiler.assembler(), + collection_in_cc.get_address(), + result_as_address, + ( + (tonkadur.fate.v1.lang.type.CollectionType) + source.get_target_collection().get_type() + ).is_set() + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/ReverseListComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/ReverseListComputationCompiler.java new file mode 100644 index 0000000..0c39eee --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/ReverseListComputationCompiler.java @@ -0,0 +1,73 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.ReverseListComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.computation.Size; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class ReverseListComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return ReverseListComputation.class; + } + + public ReverseListComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final ReverseListComputation source; + final ComputationCompiler address_compiler; + final Register result; + + source = (ReverseListComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + address_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(address_compiler); + + if (address_compiler.has_init()) + { + init_instructions.add(address_compiler.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, address_compiler.get_computation()) + ); + + address_compiler.release_registers(init_instructions); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.ReverseList.generate + ( + compiler.registers(), + compiler.assembler(), + new Size(result_as_address), + result_as_address + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/ShuffleComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/ShuffleComputationCompiler.java new file mode 100644 index 0000000..b8477c8 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/ShuffleComputationCompiler.java @@ -0,0 +1,72 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.ShuffleComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; + +import tonkadur.wyrd.v1.lang.computation.Size; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class ShuffleComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return ShuffleComputation.class; + } + + public ShuffleComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final ShuffleComputation source; + final ComputationCompiler address_compiler; + final Register result; + + source = (ShuffleComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + address_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(address_compiler); + + if (address_compiler.has_init()) + { + init_instructions.add(address_compiler.get_init()); + } + + init_instructions.add + ( + new SetValue(result_as_address, address_compiler.get_computation()) + ); + + address_compiler.release_registers(init_instructions); + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.Shuffle.generate + ( + compiler.registers(), + compiler.assembler(), + result_as_address + ) + ); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/SizeOperatorCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/SizeOperatorCompiler.java new file mode 100644 index 0000000..2c8bfff --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/SizeOperatorCompiler.java @@ -0,0 +1,44 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.SizeOperator; + +import tonkadur.wyrd.v1.lang.computation.Size; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class SizeOperatorCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return SizeOperator.class; + } + + public SizeOperatorCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final SizeOperator source; + final ComputationCompiler cc; + + source = (SizeOperator) computation; + + cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(cc); + + assimilate(cc); + + result_as_computation = new Size(cc.get_address()); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/SortComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/SortComputationCompiler.java new file mode 100644 index 0000000..f4805e1 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/SortComputationCompiler.java @@ -0,0 +1,101 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import java.util.ArrayList; +import java.util.List; + +import tonkadur.fate.v1.lang.computation.generic.SortComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class SortComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return SortComputation.class; + } + + public SortComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final SortComputation source; + final List<Computation> params; + final ComputationCompiler lambda_cc, in_collection_cc; + final Register result; + + source = (SortComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + params = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation p: + source.get_extra_parameters() + ) + { + final ComputationCompiler param_cc; + + param_cc = new ComputationCompiler(compiler); + + p.get_visited_by(param_cc); + + // Let's not re-compute the parameters on every iteration. + param_cc.generate_address(); + + assimilate(param_cc); + + params.add(param_cc.get_computation()); + } + + lambda_cc = new ComputationCompiler(compiler); + + source.get_lambda_function().get_visited_by(lambda_cc); + + assimilate(lambda_cc); + + in_collection_cc = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(in_collection_cc); + + if (in_collection_cc.has_init()) + { + init_instructions.add(in_collection_cc.get_init()); + } + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.Sort.generate + ( + compiler.registers(), + compiler.assembler(), + lambda_cc.get_computation(), + in_collection_cc.get_address(), + result_as_address, + params + ) + ); + + in_collection_cc.release_registers(init_instructions); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/SubListComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/SubListComputationCompiler.java new file mode 100644 index 0000000..929eddb --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/generic/SubListComputationCompiler.java @@ -0,0 +1,84 @@ +package tonkadur.wyrd.v1.compiler.fate.v1.computation.generic; + +import tonkadur.fate.v1.lang.computation.generic.SubListComputation; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.compiler.fate.v1.Compiler; +import tonkadur.wyrd.v1.compiler.fate.v1.TypeCompiler; +import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler; + +import tonkadur.wyrd.v1.compiler.fate.v1.computation.GenericComputationCompiler; + +public class SubListComputationCompiler +extends GenericComputationCompiler +{ + public static Class get_target_class () + { + return SubListComputation.class; + } + + public SubListComputationCompiler (final Compiler compiler) + { + super(compiler); + } + + public void compile + ( + final tonkadur.fate.v1.lang.computation.GenericComputation computation + ) + throws Throwable + { + final SubListComputation source; + final ComputationCompiler address_compiler, start_compiler, end_compiler; + final Register result; + + source = (SubListComputation) computation; + + result = reserve(TypeCompiler.compile(compiler, source.get_type())); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + + address_compiler = new ComputationCompiler(compiler); + start_compiler = new ComputationCompiler(compiler); + end_compiler = new ComputationCompiler(compiler); + + source.get_collection().get_visited_by(address_compiler); + + if (address_compiler.has_init()) + { + init_instructions.add(address_compiler.get_init()); + } + + source.get_start_index().get_visited_by(start_compiler); + + if (start_compiler.has_init()) + { + init_instructions.add(start_compiler.get_init()); + } + + source.get_end_index().get_visited_by(end_compiler); + + if (end_compiler.has_init()) + { + init_instructions.add(end_compiler.get_init()); + } + + init_instructions.add + ( + tonkadur.wyrd.v1.compiler.util.SubList.generate + ( + compiler.registers(), + compiler.assembler(), + start_compiler.get_computation(), + end_compiler.get_computation(), + address_compiler.get_address(), + result_as_address + ) + ); + + start_compiler.release_registers(init_instructions); + end_compiler.release_registers(init_instructions); + address_compiler.release_registers(init_instructions); + } +} |


