| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2021-09-07 21:27:55 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2021-09-07 21:27:55 +0200 |
| commit | 5ae284c11fa12b7d17359096557ffc0d90229aed (patch) | |
| tree | 2638b78fcc4befca5763ad46f9dd2b41bed09eb7 /src | |
| parent | 0bc7e2178111f43b63bd8b5ea25a5f4c5277dbfb (diff) | |
Fixes collections attempting to compile with their content's base type.
Diffstat (limited to 'src')
5 files changed, 85 insertions, 35 deletions
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java index ec24f86..f9d70da 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java @@ -65,41 +65,30 @@ public class AddElementComputation extends GenericComputation return null; } - - - if (call_parameters.size() > 2) + else if (call_parameters.size() > 2) { - final int param_size; - Computation temp_collection; - List<Computation> temp_params; + final int size_minus_one; + Computation result; - param_size = call_parameters.size(); + size_minus_one = call_parameters.size() - 1; - temp_collection = call_parameters.get(param_size - 1); + result = call_parameters.get(size_minus_one); - temp_params = new ArrayList<Computation>(); - temp_params.add(temp_collection); - temp_params.add(temp_collection); - - for - ( - final Computation addition: - call_parameters.subList(0, (param_size - 2)) - ) + for (int i = 0; i < size_minus_one; ++i) { - temp_params.set(0, addition); + final List<Computation> temp_params; + final Computation addition; - temp_collection = - build - ( - origin, - alias, - temp_params - ); + addition = call_parameters.get(i); + temp_params = new ArrayList<Computation>(); + + temp_params.add(addition); + temp_params.add(result); + + result = build(addition.get_origin(), alias, temp_params); } - element = call_parameters.get(param_size - 2); - collection = temp_collection; + return result; } else { diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/PopElementComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/PopElementComputation.java index c5c5c9a..dd2c230 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/PopElementComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/PopElementComputation.java @@ -17,6 +17,10 @@ import tonkadur.fate.v1.lang.meta.RecurrentChecks; import tonkadur.fate.v1.lang.computation.GenericComputation; +import tonkadur.fate.v1.lang.type.Type; +import tonkadur.fate.v1.lang.type.ConsType; +import tonkadur.fate.v1.lang.type.CollectionType; + public class PopElementComputation extends GenericComputation { public static Collection<String> get_aliases () @@ -93,7 +97,20 @@ public class PopElementComputation extends GenericComputation RecurrentChecks.assert_is_a_list(collection); } - return new PopElementComputation(origin, collection, is_from_left); + return + new PopElementComputation + ( + origin, + collection, + is_from_left, + new ConsType + ( + origin, + ((CollectionType) collection.get_type()).get_content_type(), + collection.get_type(), + "auto gen" + ) + ); } /***************************************************************************/ /**** MEMBERS **************************************************************/ @@ -109,10 +126,11 @@ public class PopElementComputation extends GenericComputation ( final Origin origin, final Computation collection, - final boolean is_from_left + final boolean is_from_left, + final Type type ) { - super(origin, collection.get_type()); + super(origin, type); this.collection = collection; this.is_from_left = is_from_left; diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/AddElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/AddElement.java index e084ff0..81b5d7d 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/AddElement.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/AddElement.java @@ -18,6 +18,8 @@ import tonkadur.fate.v1.lang.meta.RecurrentChecks; import tonkadur.fate.v1.lang.instruction.GenericInstruction; +import tonkadur.fate.v1.lang.instruction.InstructionList; + public class AddElement extends GenericInstruction { public static Collection<String> get_aliases () @@ -50,7 +52,7 @@ public class AddElement extends GenericInstruction final Computation element; final Computation collection; - if (call_parameters.size() != 2) + if (call_parameters.size() < 2) { ErrorManager.handle ( @@ -60,13 +62,40 @@ public class AddElement extends GenericInstruction ( "(" + alias - + "! <element: X> <collection: (LIST X)|(SET X)>)" + + "! <element: X>+ <collection: (LIST X)|(SET X)>)" ) ) ); return null; } + else if (call_parameters.size() > 2) + { + final int size_minus_one; + final List<Instruction> result; + final List<Computation> sub_call_parameters; + + size_minus_one = call_parameters.size() - 1; + + result = new ArrayList<Instruction>(); + sub_call_parameters = new ArrayList<Computation>(); + + sub_call_parameters.add(call_parameters.get(size_minus_one)); + sub_call_parameters.add(sub_call_parameters.get(0)); + + for (int i = 0; i < size_minus_one; ++i) + { + final Computation added_element; + + added_element = call_parameters.get(i); + + sub_call_parameters.set(0, added_element); + + result.add(build(origin, alias, sub_call_parameters)); + } + + return new InstructionList(origin, result); + } element = call_parameters.get(0); collection = call_parameters.get(1); diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index 95a614c..42feda0 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -117,7 +117,7 @@ IGNORE_ERROR_KW: L_PAREN 'ignore'US('error'|'warning') SEP+; //EXTRA_COMPUTATION_KW: L_PAREN '$'; -FIELD_ACCESS_KW: L_PAREN 'struct:get'(US'field')? SEP+; +FIELD_ACCESS_KW: L_PAREN 'struct:'(('get'(US'field')?)|'field') SEP+; SET_FIELDS_KW: L_PAREN 'struct:set'(US'fields')? SEP+; IMP_SET_FIELDS_KW: L_PAREN 'struct:set'((US'fields!')|'!') SEP+; diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java index 1b97e10..7d293cf 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java @@ -49,6 +49,8 @@ public class TypeCompiler if (fate_type instanceof tonkadur.fate.v1.lang.type.PointerType) { + System.out.println("Pointer type: " + fate_type.toString()); + return new PointerType ( @@ -111,7 +113,15 @@ public class TypeCompiler return Type.STRING; } - System.err.println("[P] Unknown basic fate type '" + fate_type + "'."); + System.err.println + ( + "[P] Unknown basic fate type '" + + fate_type + + "'. Using java class '" + + fate_type.getClass().toString() + + "'. It was defined at: " + + fate_type.get_origin() + ); return null; } @@ -202,6 +212,10 @@ public class TypeCompiler return MapType.MAP_TO_INT; } - return new MapType(compile(compiler, fate_content_type)); + return + new MapType + ( + compile(compiler, fate_collection_type.get_content_type()) + ); } } |


