| summaryrefslogtreecommitdiff |
diff options
7 files changed, 95 insertions, 43 deletions
diff --git a/data/unit-testing/access.fate b/data/unit-testing/access.fate index 6079d7d..c7df9e6 100644 --- a/data/unit-testing/access.fate +++ b/data/unit-testing/access.fate @@ -9,13 +9,13 @@ (global int i) (for (set! i 0) (=< i 10) (set! i (+ i 1)) - (assert! (= (access i li) (var i)) + (assert! (= (list:access i li) (var i)) [FAILED] ACCESS assert failed on (var i) for li. ) - (assert! (= (access i li_ptr) (var i)) + (assert! (= (list:access i (at li_ptr)) (var i)) [FAILED] ACCESS assert failed on (var i) with for li_ptr. ) - (assert! (= (access i (range 0 10 1)) (var i)) + (assert! (= (list:access i (list:range 0 10 1)) (var i)) [FAILED] ACCESS assert failed on (var i) with for range. ) ) diff --git a/data/unit-testing/ptr_and_at.fate b/data/unit-testing/ptr_and_at.fate index 9b12862..b98850d 100644 --- a/data/unit-testing/ptr_and_at.fate +++ b/data/unit-testing/ptr_and_at.fate @@ -27,6 +27,8 @@ ((ptr (list (ptr int))) int_ptr_list_ptr) ) +(global test_struct0 test_struct0) + (global (list test_struct0) test_struct0_list) (declare_structure test_struct1 @@ -80,11 +82,11 @@ (int_ptr_list_ptr (ptr ts0.int_ptr_list)) ) -(add! (ptr i) ts0.int_ptr_list) -(add! (ptr j) ts0.int_ptr_list) -(add! (at int_ptr_ptr) ts0.int_ptr_list) -(add! (var ts0.int_ptr0) ts0.int_ptr_list) -(add! (var ts0.int_ptr1) ts0.int_ptr_list) +(list:add! (ptr i) ts0.int_ptr_list) +(list:add! (ptr j) ts0.int_ptr_list) +(list:add! (at int_ptr_ptr) ts0.int_ptr_list) +(list:add! (var ts0.int_ptr0) ts0.int_ptr_list) +(list:add! (var ts0.int_ptr1) ts0.int_ptr_list) (assert! (= (var ts0.int_ptr_list.0) (var i_ptr) (ptr i)) [FAILED] (var test_name) equality 3.) (assert! (= (var ts0.int_ptr_list.1) (var j_ptr) (ptr j)) [FAILED] (var test_name) equality 4.) 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()) + ); } } |


