| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
38 files changed, 931 insertions, 1206 deletions
| diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/AddElementAtComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/AddElementAtComputation.java index b34b293..2b0c06a 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/AddElementAtComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/AddElementAtComputation.java @@ -1,22 +1,22 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.AddElementAt; +import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class AddElementAtComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final AddElementAt instruction; +   protected final Computation index; +   protected final Computation element; +   protected final Computation collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -24,12 +24,17 @@ public class AddElementAtComputation extends Computation     /**** Constructors *********************************************************/     protected AddElementAtComputation     ( -      final AddElementAt instruction +      final Origin origin, +      final Computation index, +      final Computation element, +      final Computation collection     )     { -      super(instruction.get_origin(), instruction.get_collection().get_type()); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.index = index; +      this.collection = collection; +      this.element = element;     }     /***************************************************************************/ @@ -43,16 +48,12 @@ public class AddElementAtComputation extends Computation        final Computation element,        final Computation collection     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     { -      return -         new AddElementAtComputation -         ( -            AddElementAt.build(origin, index, element, collection) -         ); +      RecurrentChecks.assert_is_a_list_of(collection, element); +      RecurrentChecks.assert_can_be_used_as(index, Type.INT); + +      return new AddElementAtComputation(origin, index, element, collection);     }     /**** Accessors ************************************************************/ @@ -63,19 +64,47 @@ public class AddElementAtComputation extends Computation        cv.visit_add_element_at(this);     } -   public AddElementAt get_instruction () +   public Computation get_collection () +   { +      return collection; +   } + +   public Computation get_index () +   { +      return index; +   } + +   public Computation get_element ()     { -      return instruction; +      return element;     } +     /**** Misc. ****************************************************************/     @Override     public String toString ()     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      sb.append("(AddElementAt"); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("index:"); +      sb.append(System.lineSeparator()); +      sb.append(index.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("element:"); +      sb.append(System.lineSeparator()); +      sb.append(element.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/AddElementComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/AddElementComputation.java index 74e0fac..b99d94c 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/AddElementComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/AddElementComputation.java @@ -3,21 +3,17 @@ package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin;  import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.AddElement; -  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class AddElementComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final AddElement instruction; +   protected final Computation element; +   protected final Computation collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -25,12 +21,15 @@ public class AddElementComputation extends Computation     /**** Constructors *********************************************************/     protected AddElementComputation     ( -      final AddElement instruction +      final Origin origin, +      final Computation element, +      final Computation collection     )     { -      super(instruction.get_origin(), instruction.get_collection().get_type()); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.collection = collection; +      this.element = element;     }     /***************************************************************************/ @@ -45,11 +44,9 @@ public class AddElementComputation extends Computation     )     throws ParsingError     { -      return -         new AddElementComputation -         ( -            AddElement.build(origin, element, collection) -         ); +      RecurrentChecks.assert_is_a_collection_of(collection, element); + +      return new AddElementComputation(origin, element, collection);     }     /**** Accessors ************************************************************/ @@ -60,9 +57,14 @@ public class AddElementComputation extends Computation        cv.visit_add_element(this);     } -   public AddElement get_instruction () +   public Computation get_collection ()     { -      return instruction; +      return collection; +   } + +   public Computation get_element () +   { +      return element;     }     /**** Misc. ****************************************************************/ @@ -71,8 +73,19 @@ public class AddElementComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      sb.append("(AddElement"); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("element:"); +      sb.append(System.lineSeparator()); +      sb.append(element.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/AddElementsOfComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/AddElementsOfComputation.java index b6ecec4..b9d4468 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/AddElementsOfComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/AddElementsOfComputation.java @@ -1,23 +1,22 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.AddElementsOf; +import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class AddElementsOfComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final AddElementsOf instruction; +   protected final Reference other_collection; +   protected final Reference collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -25,16 +24,15 @@ public class AddElementsOfComputation extends Computation     /**** Constructors *********************************************************/     protected AddElementsOfComputation     ( -      final AddElementsOf instruction +      final Origin origin, +      final Reference other_collection, +      final Reference collection     )     { -      super -      ( -         instruction.get_origin(), -         instruction.get_source_collection().get_type() -      ); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.collection = collection; +      this.other_collection = other_collection;     }     /***************************************************************************/ @@ -47,16 +45,18 @@ public class AddElementsOfComputation extends Computation        final Reference other_collection,        final Reference collection     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     { -      return -         new AddElementsOfComputation -         ( -            AddElementsOf.build(origin, other_collection, collection) -         ); +      RecurrentChecks.assert_is_a_collection(collection); +      RecurrentChecks.assert_is_a_collection(other_collection); +      RecurrentChecks.assert_can_be_used_as +      ( +         other_collection.get_origin(), +         ((CollectionType) other_collection.get_type()).get_content_type(), +         ((CollectionType) collection.get_type()).get_content_type() +      ); + +      return new AddElementsOfComputation(origin, other_collection, collection);     }     /**** Accessors ************************************************************/ @@ -67,9 +67,14 @@ public class AddElementsOfComputation extends Computation        cv.visit_add_elements_of(this);     } -   public AddElementsOf get_instruction () +   public Reference get_source_collection ()     { -      return instruction; +      return other_collection; +   } + +   public Reference get_target_collection () +   { +      return collection;     }     /**** Misc. ****************************************************************/ @@ -78,8 +83,19 @@ public class AddElementsOfComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      sb.append("(AddElementsOf"); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("other_collection:"); +      sb.append(System.lineSeparator()); +      sb.append(other_collection.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/CondValue.java b/src/core/src/tonkadur/fate/v1/lang/computation/CondValue.java index dcd014b..91f6b6b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/CondValue.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/CondValue.java @@ -1,22 +1,17 @@  package tonkadur.fate.v1.lang.computation;  import java.util.List; -import java.util.Collections;  import tonkadur.functional.Cons; -import tonkadur.error.ErrorManager; -  import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class CondValue extends Computation  { @@ -50,70 +45,17 @@ public class CondValue extends Computation        final Origin origin,        final List<Cons<Computation, Computation>> branches     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     { -      final Type first_type; -      Type candidate_hint, hint; +      Type hint; -      first_type = branches.get(0).get_cdr().get_type(); -      hint = first_type; +      hint = branches.get(0).get_cdr().get_type();        for (final Cons<Computation, Computation> entry: branches)        { -         if (!entry.get_car().get_type().can_be_used_as(Type.BOOL)) -         { -            ErrorManager.handle -            ( -               new InvalidTypeException -               ( -                  entry.get_car().get_origin(), -                  entry.get_car().get_type(), -                  Collections.singleton(Type.BOOL) -               ) -            ); -         } - -         if (entry.get_cdr().get_type().equals(hint)) -         { -            continue; -         } - -         candidate_hint = entry.get_cdr().get_type().try_merging_with(hint); - -         if (candidate_hint != null) -         { -            hint = candidate_hint; - -            continue; -         } - -         ErrorManager.handle -         ( -            new ConflictingTypeException -            ( -               entry.get_cdr().get_origin(), -               entry.get_cdr().get_type(), -               first_type -            ) -         ); - -         hint = (Type) hint.generate_comparable_to(entry.get_cdr().get_type()); - -         if (hint.equals(Type.ANY)) -         { -            ErrorManager.handle -            ( -               new IncomparableTypeException -               ( -                  entry.get_cdr().get_origin(), -                  entry.get_cdr().get_type(), -                  first_type -               ) -            ); -         } +         RecurrentChecks.assert_can_be_used_as(entry.get_car(), Type.BOOL); + +         hint = RecurrentChecks.assert_can_be_used_as(entry.get_cdr(), hint);        }        return new CondValue(origin, hint, branches); @@ -138,7 +80,6 @@ public class CondValue extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(CondValue");        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java index 56d4cac..a46387d 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java @@ -3,16 +3,13 @@ package tonkadur.fate.v1.lang.computation;  import tonkadur.error.ErrorManager;  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class CountOperator extends Computation  { @@ -49,72 +46,9 @@ public class CountOperator extends Computation        final Computation element,        final Computation collection     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     { -      final Type hint; -      final Type collection_type; -      final CollectionType collection_true_type; -      final Type collection_element_type; - -      collection_type = collection.get_type(); - -      if (!(collection_type instanceof CollectionType)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               collection.get_origin(), -               collection.get_type(), -               Type.COLLECTION_TYPES -            ) -         ); -      } - -      collection_true_type = (CollectionType) collection_type; -      collection_element_type = collection_true_type.get_content_type(); - -      if -      ( -         element.get_type().can_be_used_as(collection_element_type) -         || -         (element.get_type().try_merging_with(collection_element_type) != null) -      ) -      { -         return new CountOperator(origin, element, collection); -      } - -      ErrorManager.handle -      ( -         new ConflictingTypeException -         ( -            element.get_origin(), -            element.get_type(), -            collection_element_type -         ) -      ); - -      hint = -         (Type) element.get_type().generate_comparable_to -         ( -            collection_element_type -         ); - -      if (hint.equals(Type.ANY)) -      { -         ErrorManager.handle -         ( -            new IncomparableTypeException -            ( -               element.get_origin(), -               element.get_type(), -               collection_element_type -            ) -         ); -      } +      RecurrentChecks.assert_is_a_collection_of(collection, element);        return new CountOperator(origin, element, collection);     } @@ -143,7 +77,6 @@ public class CountOperator extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(CountOperator");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/FilterComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/FilterComputation.java index 8884941..4926265 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/FilterComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/FilterComputation.java @@ -1,25 +1,25 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.parser.Origin; +import java.util.Collections; -import tonkadur.error.ErrorManager; +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type; -import tonkadur.fate.v1.lang.type.LambdaType;  import tonkadur.fate.v1.lang.type.CollectionType; -import tonkadur.fate.v1.lang.instruction.Filter; -  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class FilterComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final Filter instruction; +   protected final Computation lambda_function; +   protected final Reference collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -27,13 +27,15 @@ public class FilterComputation extends Computation     /**** Constructors *********************************************************/     protected FilterComputation     ( -      final Filter instruction, -      final Type output_type +      final Origin origin, +      final Computation lambda_function, +      final Reference collection     )     { -      super(instruction.get_origin(), output_type); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.lambda_function = lambda_function; +      this.collection = collection;     }     /***************************************************************************/ @@ -44,18 +46,22 @@ public class FilterComputation extends Computation     (        final Origin origin,        final Computation lambda_function, -      final Reference collection_in +      final Reference collection     ) -   throws Throwable +   throws ParsingError     { -      final Type type; -      final Filter parent; - -      parent = Filter.build(origin, lambda_function, collection_in); - -      type = collection_in.get_type(); - -      return new FilterComputation(parent, type); +      RecurrentChecks.assert_is_a_collection(collection); +      RecurrentChecks.assert_lambda_matches_types +      ( +         lambda_function, +         Type.BOOL, +         Collections.singletonList +         ( +            ((CollectionType) collection.get_type()).get_content_type() +         ) +      ); + +      return new FilterComputation(origin, lambda_function, collection);     }     /**** Accessors ************************************************************/ @@ -66,9 +72,14 @@ public class FilterComputation extends Computation        cv.visit_filter(this);     } -   public Filter get_instruction () +   public Computation get_lambda_function () +   { +      return lambda_function; +   } + +   public Reference get_collection ()     { -      return instruction; +      return collection;     }     /**** Misc. ****************************************************************/ @@ -77,9 +88,10 @@ public class FilterComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); - +      sb.append("(Filter "); +      sb.append(lambda_function.toString()); +      sb.append(" "); +      sb.append(collection.toString());        sb.append(")");        return sb.toString(); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Fold.java b/src/core/src/tonkadur/fate/v1/lang/computation/Fold.java index 55f1877..293036c 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/Fold.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/Fold.java @@ -1,19 +1,11 @@  package tonkadur.fate.v1.lang.computation;  import java.util.ArrayList; -import java.util.Collections;  import java.util.List;  import tonkadur.parser.Origin;  import tonkadur.parser.ParsingError; -import tonkadur.error.ErrorManager; - -import tonkadur.fate.v1.error.IncompatibleTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidArityException; -import tonkadur.fate.v1.error.InvalidTypeException; -  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.type.LambdaType;  import tonkadur.fate.v1.lang.type.CollectionType; @@ -21,6 +13,7 @@ import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class Fold extends Computation  { @@ -66,76 +59,26 @@ public class Fold extends Computation        final Reference collection,        final boolean is_foldl     ) -   throws Throwable +   throws ParsingError     { -      final Type var_type, collection_generic_type; -      final CollectionType collection_type; -      final LambdaType lambda_type; -      final List<Type> signature; - -      var_type = lambda_function.get_type(); - -      if (!(var_type instanceof LambdaType)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               origin, -               var_type, -               Collections.singleton(Type.LAMBDA) -            ) -         ); - -         return null; -      } +      final List<Type> types_in; -      lambda_type = (LambdaType) var_type; +      types_in = new ArrayList<Type>(); -      signature = lambda_type.get_signature(); +      RecurrentChecks.assert_is_a_collection(collection); -      if (signature.size() != 2) -      { -         ErrorManager.handle -         ( -            new InvalidArityException -            ( -               lambda_function.get_origin(), -               signature.size(), -               2, -               2 -            ) -         ); -      } +      types_in.add(initial_value.get_type()); +      types_in.add +      ( +         ((CollectionType) collection.get_type()).get_content_type() +      ); -      collection_generic_type = collection.get_type(); - -      if (!(collection_generic_type instanceof CollectionType)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               origin, -               collection_generic_type, -               Type.COLLECTION_TYPES -            ) -         ); - -         return null; -      } - -      collection_type = (CollectionType) collection_generic_type; - -      if (!initial_value.get_type().can_be_used_as(signature.get(0))) -      { -         /* TODO */ -      } - -      if (!collection_type.get_content_type().can_be_used_as(signature.get(1))) -      { -         /* TODO */ -      } +      RecurrentChecks.assert_lambda_matches_types +      ( +         lambda_function, +         initial_value.get_type(), +         types_in +      );        return           new Fold diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/IfElseValue.java b/src/core/src/tonkadur/fate/v1/lang/computation/IfElseValue.java index 2fdb15e..0097537 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/IfElseValue.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/IfElseValue.java @@ -1,19 +1,13 @@  package tonkadur.fate.v1.lang.computation; -import java.util.Collections; - -import tonkadur.error.ErrorManager; -  import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class IfElseValue extends Computation  { @@ -55,74 +49,25 @@ public class IfElseValue extends Computation        final Computation if_true,        final Computation if_false     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     { -      Type hint; -      final Type if_true_type; -      final Type if_false_type; - -      if (!condition.get_type().can_be_used_as(Type.BOOL)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               condition.get_origin(), -               condition.get_type(), -               Collections.singleton(Type.BOOL) -            ) -         ); -      } - -      if_true_type = if_true.get_type(); -      if_false_type = if_false.get_type(); - -      if (if_true_type.equals(if_false_type)) -      { -         return -            new IfElseValue(origin, if_true_type, condition, if_true, if_false); -      } - -      hint = if_true_type.try_merging_with(if_false_type); - -      if (hint != null) -      { -         return new IfElseValue(origin, hint, condition, if_true, if_false); -      } - -      ErrorManager.handle -      ( -         new ConflictingTypeException -         ( -            if_false.get_origin(), -            if_false_type, -            if_true_type -         ) -      ); - -      hint = -         (Type) if_false_type.generate_comparable_to(if_true_type); - -      if (hint.equals(Type.ANY)) -      { -         ErrorManager.handle -         ( -            new IncomparableTypeException -            ( -               if_false.get_origin(), -               if_false_type, -               if_true_type -            ) -         ); -      } - -      return new IfElseValue(origin, hint, condition, if_true, if_false); +      final Type type; + +      RecurrentChecks.assert_can_be_used_as(condition, Type.BOOL); + +      type = +         RecurrentChecks.assert_can_be_used_as(if_false, if_true.get_type()); + +      return new IfElseValue(origin, type, condition, if_true, if_false);     }     /**** Accessors ************************************************************/ +   @Override +   public void get_visited_by (final ComputationVisitor cv) +   throws Throwable +   { +      cv.visit_if_else_value(this); +   }     public Computation get_condition ()     { @@ -139,20 +84,12 @@ public class IfElseValue extends Computation        return if_false;     } -   @Override -   public void get_visited_by (final ComputationVisitor cv) -   throws Throwable -   { -      cv.visit_if_else_value(this); -   } -     /**** Misc. ****************************************************************/     @Override     public String toString ()     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(IfElseValue");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/IndexOfOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/IndexOfOperator.java index 73123f6..3269dbb 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/IndexOfOperator.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/IndexOfOperator.java @@ -1,18 +1,13 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.error.ErrorManager; -  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class IndexOfOperator extends Computation  { @@ -49,72 +44,9 @@ public class IndexOfOperator extends Computation        final Computation element,        final Computation collection     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     { -      final Type hint; -      final Type collection_type; -      final CollectionType collection_true_type; -      final Type collection_element_type; - -      collection_type = collection.get_type(); - -      if (!(collection_type instanceof CollectionType)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               collection.get_origin(), -               collection.get_type(), -               Type.COLLECTION_TYPES -            ) -         ); -      } - -      collection_true_type = (CollectionType) collection_type; -      collection_element_type = collection_true_type.get_content_type(); - -      if -      ( -         element.get_type().can_be_used_as(collection_element_type) -         || -         (element.get_type().try_merging_with(collection_element_type) != null) -      ) -      { -         return new IndexOfOperator(origin, element, collection); -      } - -      ErrorManager.handle -      ( -         new ConflictingTypeException -         ( -            element.get_origin(), -            element.get_type(), -            collection_element_type -         ) -      ); - -      hint = -         (Type) element.get_type().generate_comparable_to -         ( -            collection_element_type -         ); - -      if (hint.equals(Type.ANY)) -      { -         ErrorManager.handle -         ( -            new IncomparableTypeException -            ( -               element.get_origin(), -               element.get_type(), -               collection_element_type -            ) -         ); -      } +      RecurrentChecks.assert_is_a_collection_of(collection, element);        return new IndexOfOperator(origin, element, collection);     } @@ -143,7 +75,6 @@ public class IndexOfOperator extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(IndexOfOperator");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/IndexedMapComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/IndexedMapComputation.java index dc3b9e4..d134b71 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/IndexedMapComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/IndexedMapComputation.java @@ -1,25 +1,27 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.parser.Origin; +import java.util.List; +import java.util.ArrayList; -import tonkadur.error.ErrorManager; +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.type.LambdaType;  import tonkadur.fate.v1.lang.type.CollectionType; -import tonkadur.fate.v1.lang.instruction.IndexedMap; -  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class IndexedMapComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final IndexedMap instruction; +   protected final Computation lambda_function; +   protected final Reference collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -27,13 +29,16 @@ public class IndexedMapComputation extends Computation     /**** Constructors *********************************************************/     protected IndexedMapComputation     ( -      final IndexedMap instruction, +      final Origin origin, +      final Computation lambda_function, +      final Reference collection,        final Type output_type     )     { -      super(instruction.get_origin(), output_type); +      super(origin, output_type); -      this.instruction = instruction; +      this.lambda_function = lambda_function; +      this.collection = collection;     }     /***************************************************************************/ @@ -44,25 +49,38 @@ public class IndexedMapComputation extends Computation     (        final Origin origin,        final Computation lambda_function, -      final Reference collection_in +      final Reference collection     )     throws Throwable     { -      final Type type; -      final IndexedMap parent; +      final List<Type> in_types; + +      in_types = new ArrayList<Type>(); + +      RecurrentChecks.assert_is_a_collection(collection); -      parent = IndexedMap.build(origin, lambda_function, collection_in, null); +      in_types.add(Type.INT); +      in_types.add +      ( +         ((CollectionType) collection.get_type()).get_content_type() +      ); -      type = -         CollectionType.build +      RecurrentChecks.assert_lambda_matches_types(lambda_function, in_types); + +      return +         new IndexedMapComputation           (              origin, -            ((LambdaType) lambda_function.get_type()).get_return_type(), -            ((CollectionType) collection_in.get_type()).is_set(), -            "auto generated" +            lambda_function, +            collection, +            CollectionType.build +            ( +               origin, +               ((LambdaType) lambda_function.get_type()).get_return_type(), +               ((CollectionType) collection.get_type()).is_set(), +               "auto generated" +            )           ); - -      return new IndexedMapComputation(parent, type);     }     /**** Accessors ************************************************************/ @@ -73,9 +91,14 @@ public class IndexedMapComputation extends Computation        cv.visit_indexed_map(this);     } -   public IndexedMap get_instruction () +   public Computation get_lambda_function () +   { +      return lambda_function; +   } + +   public Reference get_collection ()     { -      return instruction; +      return collection;     }     /**** Misc. ****************************************************************/ @@ -84,9 +107,10 @@ public class IndexedMapComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); - +      sb.append("(IndexedMap "); +      sb.append(lambda_function.toString()); +      sb.append(" "); +      sb.append(collection.toString());        sb.append(")");        return sb.toString(); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/IsEmpty.java b/src/core/src/tonkadur/fate/v1/lang/computation/IsEmpty.java index 66d40f0..054447b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/IsEmpty.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/IsEmpty.java @@ -1,16 +1,13 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.error.ErrorManager; -  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class IsEmpty extends Computation  { @@ -43,21 +40,9 @@ public class IsEmpty extends Computation        final Origin origin,        final Computation collection     ) -   throws InvalidTypeException +   throws ParsingError     { - -      if (!(collection.get_type() instanceof CollectionType)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               collection.get_origin(), -               collection.get_type(), -               Type.COLLECTION_TYPES -            ) -         ); -      } +      RecurrentChecks.assert_is_a_collection(collection);        return new IsEmpty(origin, collection);     } @@ -81,7 +66,6 @@ public class IsEmpty extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(IsEmpty");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java index 0422dc2..e909213 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java @@ -1,18 +1,13 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.error.ErrorManager; -  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class IsMemberOperator extends Computation  { @@ -49,72 +44,9 @@ public class IsMemberOperator extends Computation        final Computation element,        final Computation collection     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     { -      final Type hint; -      final Type collection_type; -      final CollectionType collection_true_type; -      final Type collection_element_type; - -      collection_type = collection.get_type(); - -      if (!(collection_type instanceof CollectionType)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               collection.get_origin(), -               collection.get_type(), -               Type.COLLECTION_TYPES -            ) -         ); -      } - -      collection_true_type = (CollectionType) collection_type; -      collection_element_type = collection_true_type.get_content_type(); - -      if -      ( -         element.get_type().can_be_used_as(collection_element_type) -         || -         (element.get_type().try_merging_with(collection_element_type) != null) -      ) -      { -         return new IsMemberOperator(origin, element, collection); -      } - -      ErrorManager.handle -      ( -         new ConflictingTypeException -         ( -            element.get_origin(), -            element.get_type(), -            collection_element_type -         ) -      ); - -      hint = -         (Type) element.get_type().generate_comparable_to -         ( -            collection_element_type -         ); - -      if (hint.equals(Type.ANY)) -      { -         ErrorManager.handle -         ( -            new IncomparableTypeException -            ( -               element.get_origin(), -               element.get_type(), -               collection_element_type -            ) -         ); -      } +      RecurrentChecks.assert_is_a_collection_of(collection, element);        return new IsMemberOperator(origin, element, collection);     } @@ -143,7 +75,6 @@ public class IsMemberOperator extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(IsMemberOperator");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/LambdaEvaluation.java b/src/core/src/tonkadur/fate/v1/lang/computation/LambdaEvaluation.java index 9bdc731..e29ac6b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/LambdaEvaluation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/LambdaEvaluation.java @@ -1,27 +1,17 @@  package tonkadur.fate.v1.lang.computation; -import java.util.ArrayList; -import java.util.Collections;  import java.util.List;  import tonkadur.parser.Origin;  import tonkadur.parser.ParsingError; -import tonkadur.functional.Merge; - -import tonkadur.error.ErrorManager; - -import tonkadur.fate.v1.error.IncompatibleTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidArityException; -import tonkadur.fate.v1.error.InvalidTypeException; -  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.type.LambdaType;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class LambdaEvaluation extends Computation  { @@ -59,100 +49,9 @@ public class LambdaEvaluation extends Computation        final Reference reference,        final List<Computation> parameters     ) -   throws Throwable +   throws ParsingError     { -      final Type var_type; -      final LambdaType lambda_type; -      final List<Type> signature; - -      var_type = reference.get_type(); - -      if (!(var_type instanceof LambdaType)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               origin, -               var_type, -               Collections.singleton(Type.LAMBDA) -            ) -         ); - -         return null; -      } - -      lambda_type = (LambdaType) var_type; - -      signature = lambda_type.get_signature(); - -      if (parameters.size() != signature.size()) -      { -         ErrorManager.handle -         ( -            new InvalidArityException -            ( -               origin, -               parameters.size(), -               signature.size(), -               signature.size() -            ) -         ); -      } - -      (new Merge<Type, Computation, Boolean>() -      { -         @Override -         public Boolean risky_lambda (final Type t, final Computation p) -         throws ParsingError -         { -            if ((t == null) || (p == null)) -            { -               return Boolean.FALSE; -            } -            else -            { -               final Type hint; - -               if (p.get_type().can_be_used_as(t)) -               { -                  return Boolean.TRUE; -               } - -               if (p.get_type().try_merging_with(t) != null) -               { -                  return Boolean.TRUE; -               } - -               ErrorManager.handle -               ( -                  new IncompatibleTypeException -                  ( -                     p.get_origin(), -                     p.get_type(), -                     t -                  ) -               ); - -               hint = (Type) p.get_type().generate_comparable_to(t); - -               if (hint.equals(Type.ANY)) -               { -                  ErrorManager.handle -                  ( -                     new IncomparableTypeException -                     ( -                        p.get_origin(), -                        p.get_type(), -                        t -                     ) -                  ); -               } - -               return Boolean.FALSE; -            } -         } -      }).risky_merge(signature, parameters); +      RecurrentChecks.assert_lambda_matches_computations(reference, parameters);        return           new LambdaEvaluation @@ -160,7 +59,7 @@ public class LambdaEvaluation extends Computation              origin,              reference,              parameters, -            lambda_type.get_return_type() +            (((LambdaType) reference.get_type()).get_return_type())           );     } diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/MapComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/MapComputation.java index c81926e..4cbd2a7 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/MapComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/MapComputation.java @@ -1,25 +1,26 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.parser.Origin; +import java.util.Collections; -import tonkadur.error.ErrorManager; +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.type.LambdaType;  import tonkadur.fate.v1.lang.type.CollectionType; -import tonkadur.fate.v1.lang.instruction.Map; -  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class MapComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final Map instruction; +   protected final Computation lambda_function; +   protected final Reference collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -27,13 +28,15 @@ public class MapComputation extends Computation     /**** Constructors *********************************************************/     protected MapComputation     ( -      final Map instruction, +      final Origin origin, +      final Computation lambda_function, +      final Reference collection,        final Type output_type     )     { -      super(instruction.get_origin(), output_type); - -      this.instruction = instruction; +      super(origin, output_type); +      this.lambda_function = lambda_function; +      this.collection = collection;     }     /***************************************************************************/ @@ -44,25 +47,34 @@ public class MapComputation extends Computation     (        final Origin origin,        final Computation lambda_function, -      final Reference collection_in +      final Reference collection     ) -   throws Throwable +   throws ParsingError     { -      final Type type; -      final Map parent; - -      parent = Map.build(origin, lambda_function, collection_in, null); +      RecurrentChecks.assert_is_a_collection(collection); +      RecurrentChecks.assert_lambda_matches_types +      ( +         lambda_function, +         Collections.singletonList +         ( +            ((CollectionType) collection.get_type()).get_content_type() +         ) +      ); -      type = -         CollectionType.build +      return +         new MapComputation           (              origin, -            ((LambdaType) lambda_function.get_type()).get_return_type(), -            ((CollectionType) collection_in.get_type()).is_set(), -            "auto generated" +            lambda_function, +            collection, +            CollectionType.build +            ( +               origin, +               ((LambdaType) lambda_function.get_type()).get_return_type(), +               ((CollectionType) collection.get_type()).is_set(), +               "auto generated" +            )           ); - -      return new MapComputation(parent, type);     }     /**** Accessors ************************************************************/ @@ -73,9 +85,14 @@ public class MapComputation extends Computation        cv.visit_map(this);     } -   public Map get_instruction () +   public Computation get_lambda_function ()     { -      return instruction; +      return lambda_function; +   } + +   public Reference get_collection () +   { +      return collection;     }     /**** Misc. ****************************************************************/ @@ -84,9 +101,10 @@ public class MapComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); - +      sb.append("(Map "); +      sb.append(lambda_function.toString()); +      sb.append(" "); +      sb.append(collection.toString());        sb.append(")");        return sb.toString(); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/MergeComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/MergeComputation.java index 3b742c1..a4b41b6 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/MergeComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/MergeComputation.java @@ -1,8 +1,10 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.parser.Origin; +import java.util.ArrayList; +import java.util.List; -import tonkadur.error.ErrorManager; +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.type.LambdaType; @@ -13,13 +15,19 @@ import tonkadur.fate.v1.lang.instruction.Merge;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class MergeComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final Merge instruction; +   protected final Computation lambda_function; +   protected final Reference collection_in_a; +   protected final Computation default_a; +   protected final Reference collection_in_b; +   protected final Computation default_b; +   protected final boolean to_set;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -27,13 +35,24 @@ public class MergeComputation extends Computation     /**** Constructors *********************************************************/     protected MergeComputation     ( -      final Merge instruction, +      final Origin origin, +      final Computation lambda_function, +      final Reference collection_in_a, +      final Computation default_a, +      final Reference collection_in_b, +      final Computation default_b, +      final boolean to_set,        final Type output_type     )     { -      super(instruction.get_origin(), output_type); - -      this.instruction = instruction; +      super(origin, output_type); + +      this.lambda_function = lambda_function; +      this.collection_in_a = collection_in_a; +      this.default_a = default_a; +      this.collection_in_b = collection_in_b; +      this.default_b = default_b; +      this.to_set = to_set;     }     /***************************************************************************/ @@ -47,15 +66,47 @@ public class MergeComputation extends Computation        final Reference collection_in_a,        final Computation default_a,        final Reference collection_in_b, -      final Computation default_b +      final Computation default_b, +      final boolean to_set     )     throws Throwable     { -      final Type type; -      final Merge parent; - -      parent = -         Merge.build +      final List<Type> types_in; + +      types_in = new ArrayList<Type>(); + +      if (default_a == null) +      { +         RecurrentChecks.assert_is_a_collection(collection_in_a); +      } +      else +      { +         RecurrentChecks.assert_is_a_collection_of(collection_in_a, default_a); +      } + +      if (default_b == null) +      { +         RecurrentChecks.assert_is_a_collection(collection_in_b); +      } +      else +      { +         RecurrentChecks.assert_is_a_collection_of(collection_in_b, default_b); +      } + +      types_in.add +      ( +         ((CollectionType) collection_in_a.get_type()).get_content_type() +      ); + +      types_in.add +      ( +         ((CollectionType) collection_in_b.get_type()).get_content_type() +      ); + +      RecurrentChecks.assert_lambda_matches_types(lambda_function, types_in); + +      return +         new MergeComputation           (              origin,              lambda_function, @@ -63,22 +114,15 @@ public class MergeComputation extends Computation              default_a,              collection_in_b,              default_b, -            null -         ); - -      type = -         CollectionType.build -         ( -            origin, -            ((LambdaType) lambda_function.get_type()).get_return_type(), +            to_set, +            CollectionType.build              ( -               ((CollectionType) collection_in_a.get_type()).is_set() -               || ((CollectionType) collection_in_b.get_type()).is_set() -            ), -            "auto generated" +               origin, +               ((LambdaType) lambda_function.get_type()).get_return_type(), +               to_set, +               "auto generated" +            )           ); - -      return new MergeComputation(parent, type);     }     /**** Accessors ************************************************************/ @@ -89,9 +133,34 @@ public class MergeComputation extends Computation        cv.visit_merge(this);     } -   public Merge get_instruction () +   public Computation get_lambda_function () +   { +      return lambda_function; +   } + +   public Reference get_collection_in_a () +   { +      return collection_in_a; +   } + +   public Computation get_default_a () +   { +      return default_a; +   } + +   public Reference get_collection_in_b () +   { +      return collection_in_b; +   } + +   public Computation get_default_b () +   { +      return default_b; +   } + +   public boolean to_set ()     { -      return instruction; +      return to_set;     }     /**** Misc. ****************************************************************/ @@ -100,8 +169,41 @@ public class MergeComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      if (to_set) +      { +         sb.append("(MergeToSet "); +      } +      else +      { +         sb.append("(MergeToList "); +      } + +      sb.append(lambda_function.toString()); +      sb.append(" "); +      sb.append(collection_in_a.toString()); +      sb.append(" "); + +      if (default_a == null) +      { +         sb.append("null"); +      } +      else +      { +         sb.append(default_a.toString()); +      } + +      sb.append(" "); +      sb.append(collection_in_b.toString()); +      sb.append(" "); + +      if (default_b == null) +      { +         sb.append("null"); +      } +      else +      { +         sb.append(default_b.toString()); +      }        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/PartitionComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/PartitionComputation.java index ed578dd..a30a893 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/PartitionComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/PartitionComputation.java @@ -1,26 +1,26 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.parser.Origin; +import java.util.Collections; -import tonkadur.error.ErrorManager; +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.type.ConsType; -import tonkadur.fate.v1.lang.type.LambdaType;  import tonkadur.fate.v1.lang.type.Type; -import tonkadur.fate.v1.lang.instruction.Partition; -  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class PartitionComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final Partition instruction; +   protected final Computation lambda_function; +   protected final Reference collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -28,13 +28,16 @@ public class PartitionComputation extends Computation     /**** Constructors *********************************************************/     protected PartitionComputation     ( -      final Partition instruction, +      final Origin origin, +      final Computation lambda_function, +      final Reference collection,        final Type output_type     )     { -      super(instruction.get_origin(), output_type); +      super(origin, output_type); -      this.instruction = instruction; +      this.lambda_function = lambda_function; +      this.collection = collection;     }     /***************************************************************************/ @@ -45,32 +48,41 @@ public class PartitionComputation extends Computation     (        final Origin origin,        final Computation lambda_function, -      final Reference collection_in +      final Reference collection     )     throws Throwable     {        final Type type; -      final Partition parent; -      parent = -         Partition.build +      RecurrentChecks.assert_is_a_collection(collection); + +      RecurrentChecks.assert_lambda_matches_types +      ( +         lambda_function, +         Type.BOOL, +         Collections.singletonList           ( -            origin, -            lambda_function, -            collection_in, -            null -         ); +            ((CollectionType) collection.get_type()).get_content_type() +         ) +      );        type =           new ConsType           (              origin, -            collection_in.get_type(), -            collection_in.get_type(), +            collection.get_type(), +            collection.get_type(),              "auto generated"           ); -      return new PartitionComputation(parent, type); +      return +         new PartitionComputation +         ( +            origin, +            lambda_function, +            collection, +            type +         );     }     /**** Accessors ************************************************************/ @@ -81,9 +93,14 @@ public class PartitionComputation extends Computation        cv.visit_partition(this);     } -   public Partition get_instruction () +   public Computation get_lambda_function ()     { -      return instruction; +      return lambda_function; +   } + +   public Reference get_collection () +   { +      return collection;     }     /**** Misc. ****************************************************************/ @@ -92,9 +109,10 @@ public class PartitionComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); - +      sb.append("(Partition "); +      sb.append(lambda_function.toString()); +      sb.append(" "); +      sb.append(collection.toString());        sb.append(")");        return sb.toString(); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/PopElementComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/PopElementComputation.java index 6e0a7f0..5d50018 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/PopElementComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/PopElementComputation.java @@ -1,20 +1,19 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.PopElement; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class PopElementComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final PopElement instruction; +   protected final Computation collection; +   protected final boolean is_from_left;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -22,12 +21,15 @@ public class PopElementComputation extends Computation     /**** Constructors *********************************************************/     protected PopElementComputation     ( -      final PopElement instruction +      final Origin origin, +      final Computation collection, +      final boolean is_from_left     )     { -      super(instruction.get_origin(), instruction.get_collection().get_type()); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.collection = collection; +      this.is_from_left = is_from_left;     }     /***************************************************************************/ @@ -40,14 +42,11 @@ public class PopElementComputation extends Computation        final Computation collection,        final boolean is_from_left     ) -   throws -      InvalidTypeException +   throws ParsingError     { -      return -         new PopElementComputation -         ( -            PopElement.build(origin, collection, is_from_left) -         ); +      RecurrentChecks.assert_is_a_collection(collection); + +      return new PopElementComputation(origin, collection, is_from_left);     }     /**** Accessors ************************************************************/ @@ -58,9 +57,14 @@ public class PopElementComputation extends Computation        cv.visit_pop_element(this);     } -   public PopElement get_instruction () +   public Computation get_collection ()     { -      return instruction; +      return collection; +   } + +   public boolean is_from_left () +   { +      return is_from_left;     }     /**** Misc. ****************************************************************/ @@ -69,8 +73,16 @@ public class PopElementComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      if (is_from_left) +      { +         sb.append("(PopLeftElement "); +      } +      else +      { +         sb.append("(PopRightElement "); +      } + +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/PushElementComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/PushElementComputation.java index 5347f0a..f13e1c7 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/PushElementComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/PushElementComputation.java @@ -1,22 +1,20 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.PushElement; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class PushElementComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final PushElement instruction; +   protected final Computation element; +   protected final Computation collection; +   protected final boolean is_from_left;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -24,12 +22,17 @@ public class PushElementComputation extends Computation     /**** Constructors *********************************************************/     protected PushElementComputation     ( -      final PushElement instruction +      final Origin origin, +      final Computation element, +      final Computation collection, +      final boolean is_from_left     )     { -      super(instruction.get_origin(), instruction.get_collection().get_type()); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.collection = collection; +      this.element = element; +      this.is_from_left = is_from_left;     }     /***************************************************************************/ @@ -43,15 +46,15 @@ public class PushElementComputation extends Computation        final Computation collection,        final boolean is_from_left     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     {        return           new PushElementComputation           ( -            PushElement.build(origin, element, collection, is_from_left) +            origin, +            element, +            collection, +            is_from_left           );     } @@ -63,9 +66,19 @@ public class PushElementComputation extends Computation        cv.visit_push_element(this);     } -   public PushElement get_instruction () +   public Computation get_collection ()     { -      return instruction; +      return collection; +   } + +   public Computation get_element () +   { +      return element; +   } + +   public boolean  is_from_left () +   { +      return is_from_left;     }     /**** Misc. ****************************************************************/ @@ -74,8 +87,27 @@ public class PushElementComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      if (is_from_left) +      { +         sb.append("(LeftPushElement"); +      } +      else +      { +         sb.append("(RightPushElement"); +      } + +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("element:"); +      sb.append(System.lineSeparator()); +      sb.append(element.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Range.java b/src/core/src/tonkadur/fate/v1/lang/computation/Range.java index 257a722..736ecf7 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/Range.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/Range.java @@ -1,18 +1,14 @@  package tonkadur.fate.v1.lang.computation; -import java.util.Collections; - -import tonkadur.error.ErrorManager; -  import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.InvalidTypeException; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class Range extends Computation  { @@ -54,46 +50,11 @@ public class Range extends Computation        final Computation end,        final Computation increment     ) -   throws InvalidTypeException +   throws ParsingError     { -      if (!start.get_type().can_be_used_as(Type.INT)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               start.get_origin(), -               start.get_type(), -               Collections.singletonList(Type.INT) -            ) -         ); -      } - -      if (!end.get_type().can_be_used_as(Type.INT)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               end.get_origin(), -               end.get_type(), -               Collections.singletonList(Type.INT) -            ) -         ); -      } - -      if (!increment.get_type().can_be_used_as(Type.INT)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               increment.get_origin(), -               increment.get_type(), -               Collections.singletonList(Type.INT) -            ) -         ); -      } +      RecurrentChecks.assert_can_be_used_as(start, Type.INT); +      RecurrentChecks.assert_can_be_used_as(end, Type.INT); +      RecurrentChecks.assert_can_be_used_as(increment, Type.INT);        return           new Range diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/RemoveAllOfElementComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/RemoveAllOfElementComputation.java index fb6b9da..6220875 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/RemoveAllOfElementComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/RemoveAllOfElementComputation.java @@ -1,23 +1,20 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.RemoveAllOfElement; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class RemoveAllOfElementComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final RemoveAllOfElement instruction; +   protected final Computation element; +   protected final Reference collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -25,12 +22,15 @@ public class RemoveAllOfElementComputation extends Computation     /**** Constructors *********************************************************/     protected RemoveAllOfElementComputation     ( -      final RemoveAllOfElement instruction +      final Origin origin, +      final Computation element, +      final Reference collection     )     { -      super(instruction.get_origin(), instruction.get_collection().get_type()); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.collection = collection; +      this.element = element;     }     /***************************************************************************/     /**** PUBLIC ***************************************************************/ @@ -42,16 +42,11 @@ public class RemoveAllOfElementComputation extends Computation        final Computation element,        final Reference collection     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     { -      return -         new RemoveAllOfElementComputation -         ( -            RemoveAllOfElement.build(origin, element, collection) -         ); +      RecurrentChecks.assert_is_a_collection_of(collection, element); + +      return new RemoveAllOfElementComputation(origin, element, collection);     }     /**** Accessors ************************************************************/ @@ -62,9 +57,14 @@ public class RemoveAllOfElementComputation extends Computation        cv.visit_remove_all_of_element(this);     } -   public RemoveAllOfElement get_instruction () +   public Computation get_element ()     { -      return instruction; +      return element; +   } + +   public Reference get_collection () +   { +      return collection;     }     /**** Misc. ****************************************************************/ @@ -73,8 +73,19 @@ public class RemoveAllOfElementComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      sb.append("(RemoveAllOfElement"); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("element:"); +      sb.append(System.lineSeparator()); +      sb.append(element.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/RemoveElementAtComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/RemoveElementAtComputation.java index 4a87a02..837af0e 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/RemoveElementAtComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/RemoveElementAtComputation.java @@ -1,23 +1,22 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.RemoveElementAt; +import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class RemoveElementAtComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final RemoveElementAt instruction; +   protected final Computation index; +   protected final Reference collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -25,12 +24,15 @@ public class RemoveElementAtComputation extends Computation     /**** Constructors *********************************************************/     protected RemoveElementAtComputation     ( -      final RemoveElementAt instruction +      final Origin origin, +      final Computation index, +      final Reference collection     )     { -      super(instruction.get_origin(), instruction.get_collection().get_type()); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.collection = collection; +      this.index = index;     }     /***************************************************************************/ @@ -43,15 +45,12 @@ public class RemoveElementAtComputation extends Computation        final Computation index,        final Reference collection     ) -   throws -      InvalidTypeException, -      IncomparableTypeException +   throws ParsingError     { -      return -         new RemoveElementAtComputation -         ( -            RemoveElementAt.build(origin, index, collection) -         ); +      RecurrentChecks.assert_is_a_collection(collection); +      RecurrentChecks.assert_can_be_used_as(index, Type.INT); + +      return new RemoveElementAtComputation(origin, index, collection);     }     /**** Accessors ************************************************************/ @@ -62,9 +61,14 @@ public class RemoveElementAtComputation extends Computation        cv.visit_remove_element_at(this);     } -   public RemoveElementAt get_instruction () +   public Computation get_index ()     { -      return instruction; +      return index; +   } + +   public Reference get_collection () +   { +      return collection;     }     /**** Misc. ****************************************************************/ @@ -73,8 +77,19 @@ public class RemoveElementAtComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      sb.append("(RemoveElementAt"); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("index:"); +      sb.append(System.lineSeparator()); +      sb.append(index.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/RemoveElementComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/RemoveElementComputation.java index e3acd4b..cb9c275 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/RemoveElementComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/RemoveElementComputation.java @@ -1,23 +1,20 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.RemoveElement; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class RemoveElementComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final RemoveElement instruction; +   protected final Computation element; +   protected final Computation collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -25,12 +22,15 @@ public class RemoveElementComputation extends Computation     /**** Constructors *********************************************************/     protected RemoveElementComputation     ( -      final RemoveElement instruction +      final Origin origin, +      final Computation element, +      final Computation collection     )     { -      super(instruction.get_origin(), instruction.get_collection().get_type()); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.collection = collection; +      this.element = element;     }     /***************************************************************************/     /**** PUBLIC ***************************************************************/ @@ -42,16 +42,11 @@ public class RemoveElementComputation extends Computation        final Computation element,        final Reference collection     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     { -      return -         new RemoveElementComputation -         ( -            RemoveElement.build(origin, element, collection) -         ); +      RecurrentChecks.assert_is_a_collection_of(collection, element); + +      return new RemoveElementComputation(origin, element, collection);     }     /**** Accessors ************************************************************/ @@ -62,9 +57,14 @@ public class RemoveElementComputation extends Computation        cv.visit_remove_element(this);     } -   public RemoveElement get_instruction () +   public Computation get_element ()     { -      return instruction; +      return element; +   } + +   public Computation get_collection () +   { +      return collection;     }     /**** Misc. ****************************************************************/ @@ -73,8 +73,19 @@ public class RemoveElementComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      sb.append("(RemoveElement"); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("element:"); +      sb.append(System.lineSeparator()); +      sb.append(element.toString()); +      sb.append(System.lineSeparator()); +      sb.append(System.lineSeparator()); + +      sb.append("collection:"); +      sb.append(System.lineSeparator()); +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/ReverseListComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/ReverseListComputation.java index 022633a..2d23e5c 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/ReverseListComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/ReverseListComputation.java @@ -1,20 +1,21 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.ReverseList; +import tonkadur.fate.v1.lang.type.CollectionType; +import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class ReverseListComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final ReverseList instruction; +   protected final Computation collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -22,12 +23,14 @@ public class ReverseListComputation extends Computation     /**** Constructors *********************************************************/     protected ReverseListComputation     ( -      final ReverseList instruction +      final Origin origin, +      final Computation collection, +      final Type result_type     )     { -      super(instruction.get_origin(), instruction.get_collection().get_type()); +      super(origin, result_type); -      this.instruction = instruction; +      this.collection = collection;     }     /***************************************************************************/ @@ -39,13 +42,23 @@ public class ReverseListComputation extends Computation        final Origin origin,        final Computation collection     ) -   throws InvalidTypeException +   throws ParsingError     { -      /* -       * FIXME: this computation should accept any collection type, and return a -       * list, which is not the case of ReverseList.build -       */ -      return new ReverseListComputation(ReverseList.build(origin, collection)); +      RecurrentChecks.assert_is_a_collection(collection); + +      return +         new ReverseListComputation +         ( +            origin, +            collection, +            CollectionType.build +            ( +               origin, +               (((CollectionType) collection.get_type()).get_content_type()), +               false, +               "auto generated" +            ) +         );     }     /**** Accessors ************************************************************/ @@ -56,9 +69,9 @@ public class ReverseListComputation extends Computation        cv.visit_reverse_list(this);     } -   public ReverseList get_instruction () +   public Computation get_collection ()     { -      return instruction; +      return collection;     }     /**** Misc. ****************************************************************/ @@ -67,8 +80,8 @@ public class ReverseListComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      sb.append("(ReverseList "); +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/ShuffleComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/ShuffleComputation.java index b9b42a0..41a747e 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/ShuffleComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/ShuffleComputation.java @@ -1,20 +1,21 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.instruction.Shuffle; +import tonkadur.fate.v1.lang.type.CollectionType; +import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class ShuffleComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final Shuffle instruction; +   protected final Computation collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -22,12 +23,14 @@ public class ShuffleComputation extends Computation     /**** Constructors *********************************************************/     protected ShuffleComputation     ( -      final Shuffle instruction +      final Origin origin, +      final Computation collection, +      final Type result_type     )     { -      super(instruction.get_origin(), instruction.get_collection().get_type()); +      super(origin, result_type); -      this.instruction = instruction; +      this.collection = collection;     }     /***************************************************************************/ @@ -39,13 +42,23 @@ public class ShuffleComputation extends Computation        final Origin origin,        final Computation collection     ) -   throws InvalidTypeException +   throws ParsingError     { -      /* -       * FIXME: this computation should accept any collection type, and return a -       * list, which is not the case of Shuffle.build -       */ -      return new ShuffleComputation(Shuffle.build(origin, collection)); +      RecurrentChecks.assert_is_a_collection(collection); + +      return +         new ShuffleComputation +         ( +            origin, +            collection, +            CollectionType.build +            ( +               origin, +               (((CollectionType) collection.get_type()).get_content_type()), +               false, +               "auto generated" +            ) +         );     }     /**** Accessors ************************************************************/ @@ -56,9 +69,9 @@ public class ShuffleComputation extends Computation        cv.visit_shuffle(this);     } -   public Shuffle get_instruction () +   public Computation get_collection ()     { -      return instruction; +      return collection;     }     /**** Misc. ****************************************************************/ @@ -67,8 +80,8 @@ public class ShuffleComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); +      sb.append("(Shuffle "); +      sb.append(collection.toString());        sb.append(")"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/SizeOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/SizeOperator.java index 9882b31..a80efcf 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/SizeOperator.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/SizeOperator.java @@ -1,16 +1,13 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.error.ErrorManager; -  import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class SizeOperator extends Computation  { @@ -43,21 +40,9 @@ public class SizeOperator extends Computation        final Origin origin,        final Computation collection     ) -   throws InvalidTypeException +   throws ParsingError     { - -      if (!(collection.get_type() instanceof CollectionType)) -      { -         ErrorManager.handle -         ( -            new InvalidTypeException -            ( -               collection.get_origin(), -               collection.get_type(), -               Type.COLLECTION_TYPES -            ) -         ); -      } +      RecurrentChecks.assert_is_a_collection(collection);        return new SizeOperator(origin, collection);     } diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/SortComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/SortComputation.java index fab922b..7131c8b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/SortComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/SortComputation.java @@ -1,11 +1,12 @@  package tonkadur.fate.v1.lang.computation; -import tonkadur.parser.Origin; +import java.util.ArrayList; +import java.util.List; -import tonkadur.error.ErrorManager; +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type; -import tonkadur.fate.v1.lang.type.LambdaType;  import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.instruction.Sort; @@ -13,13 +14,15 @@ import tonkadur.fate.v1.lang.instruction.Sort;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class SortComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final Sort instruction; +   protected final Computation lambda_function; +   protected final Reference collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -27,16 +30,15 @@ public class SortComputation extends Computation     /**** Constructors *********************************************************/     protected SortComputation     ( -      final Sort instruction +      final Origin origin, +      final Computation lambda_function, +      final Reference collection     )     { -      super -      ( -         instruction.get_origin(), -         instruction.get_collection().get_type() -      ); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.lambda_function = lambda_function; +      this.collection = collection;     }     /***************************************************************************/ @@ -49,13 +51,25 @@ public class SortComputation extends Computation        final Computation lambda_function,        final Reference collection     ) -   throws Throwable +   throws ParsingError     { -      final Sort parent; +      final List<Type> types_in; + +      types_in = new ArrayList<Type>(); -      parent = Sort.build(origin, lambda_function, collection); +      RecurrentChecks.assert_is_a_list(collection); -      return new SortComputation(parent); +      types_in.add(((CollectionType) collection.get_type()).get_content_type()); +      types_in.add(types_in.get(0)); + +      RecurrentChecks.assert_lambda_matches_types +      ( +         lambda_function, +         Type.INT, +         types_in +      ); + +      return new SortComputation(origin, lambda_function, collection);     }     /**** Accessors ************************************************************/ @@ -66,9 +80,14 @@ public class SortComputation extends Computation        cv.visit_sort(this);     } -   public Sort get_instruction () +   public Computation get_lambda_function ()     { -      return instruction; +      return lambda_function; +   } + +   public Reference get_collection () +   { +      return collection;     }     /**** Misc. ****************************************************************/ @@ -77,9 +96,10 @@ public class SortComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); - +      sb.append("(Sort "); +      sb.append(lambda_function.toString()); +      sb.append(" "); +      sb.append(collection.toString());        sb.append(")");        return sb.toString(); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/SubListComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/SubListComputation.java index 39133c2..38ba1d9 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/SubListComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/SubListComputation.java @@ -1,24 +1,23 @@  package tonkadur.fate.v1.lang.computation;  import tonkadur.parser.Origin; - -import tonkadur.error.ErrorManager; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type; -import tonkadur.fate.v1.lang.type.CollectionType; - -import tonkadur.fate.v1.lang.instruction.SubList;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation;  import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class SubListComputation extends Computation  {     /***************************************************************************/     /**** MEMBERS **************************************************************/     /***************************************************************************/ -   protected final SubList instruction; +   protected final Computation start; +   protected final Computation end; +   protected final Reference collection;     /***************************************************************************/     /**** PROTECTED ************************************************************/ @@ -26,13 +25,17 @@ public class SubListComputation extends Computation     /**** Constructors *********************************************************/     protected SubListComputation     ( -      final SubList instruction, -      final Type output_type +      final Origin origin, +      final Computation start, +      final Computation end, +      final Reference collection     )     { -      super(instruction.get_origin(), output_type); +      super(origin, collection.get_type()); -      this.instruction = instruction; +      this.start = start; +      this.end = end; +      this.collection = collection;     }     /***************************************************************************/ @@ -44,18 +47,15 @@ public class SubListComputation extends Computation        final Origin origin,        final Computation start,        final Computation end, -      final Reference collection_in +      final Reference collection     ) -   throws Throwable +   throws ParsingError     { -      final Type type; -      final SubList parent; - -      parent = SubList.build(origin, start, end, collection_in, null); - -      type = collection_in.get_type(); +      RecurrentChecks.assert_can_be_used_as(start, Type.INT); +      RecurrentChecks.assert_can_be_used_as(end, Type.INT); +      RecurrentChecks.assert_is_a_collection(collection); -      return new SubListComputation(parent, type); +      return new SubListComputation(origin, start, end, collection);     }     /**** Accessors ************************************************************/ @@ -66,9 +66,19 @@ public class SubListComputation extends Computation        cv.visit_sublist(this);     } -   public SubList get_instruction () +   public Reference get_collection ()     { -      return instruction; +      return collection; +   } + +   public Computation get_start_index () +   { +      return start; +   } + +   public Computation get_end_index () +   { +      return end;     }     /**** Misc. ****************************************************************/ @@ -77,9 +87,12 @@ public class SubListComputation extends Computation     {        final StringBuilder sb = new StringBuilder(); -      sb.append("(ComputationOf "); -      sb.append(instruction.toString()); - +      sb.append("(SubList "); +      sb.append(start.toString()); +      sb.append(" "); +      sb.append(end.toString()); +      sb.append(" "); +      sb.append(collection.toString());        sb.append(")");        return sb.toString(); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/SwitchValue.java b/src/core/src/tonkadur/fate/v1/lang/computation/SwitchValue.java index 3f22e51..e49525d 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/SwitchValue.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/SwitchValue.java @@ -1,22 +1,17 @@  package tonkadur.fate.v1.lang.computation;  import java.util.List; -import java.util.Collections;  import tonkadur.functional.Cons; -import tonkadur.error.ErrorManager; -  import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; +import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class SwitchValue extends Computation  { @@ -58,10 +53,7 @@ public class SwitchValue extends Computation        final List<Cons<Computation, Computation>> branches,        final Computation default_value     ) -   throws -      InvalidTypeException, -      ConflictingTypeException, -      IncomparableTypeException +   throws ParsingError     {        final Type target_type;        final Type first_type; @@ -73,97 +65,10 @@ public class SwitchValue extends Computation        for (final Cons<Computation, Computation> entry: branches)        { -         if (!entry.get_car().get_type().can_be_used_as(target_type)) -         { -            ErrorManager.handle -            ( -               new InvalidTypeException -               ( -                  entry.get_car().get_origin(), -                  entry.get_car().get_type(), -                  Collections.singleton(target_type) -               ) -            ); -         } - -         if (entry.get_cdr().get_type().equals(hint)) -         { -            continue; -         } - -         candidate_hint = entry.get_cdr().get_type().try_merging_with(hint); - -         if (candidate_hint != null) -         { -            hint = candidate_hint; - -            continue; -         } - -         ErrorManager.handle -         ( -            new ConflictingTypeException -            ( -               entry.get_cdr().get_origin(), -               entry.get_cdr().get_type(), -               first_type -            ) -         ); - -         hint = (Type) hint.generate_comparable_to(entry.get_cdr().get_type()); - -         if (hint.equals(Type.ANY)) -         { -            ErrorManager.handle -            ( -               new IncomparableTypeException -               ( -                  entry.get_cdr().get_origin(), -                  entry.get_cdr().get_type(), -                  first_type -               ) -            ); -         } -      } - -      if (default_value.get_type().equals(hint)) -      { -         return new SwitchValue(origin, hint, target, branches, default_value); -      } - -      candidate_hint = default_value.get_type().try_merging_with(hint); - -      if (candidate_hint != null) -      { -         hint = candidate_hint; - -         return new SwitchValue(origin, hint, target, branches, default_value); +         hint = RecurrentChecks.assert_can_be_used_as(entry.get_car(), hint);        } -      ErrorManager.handle -      ( -         new ConflictingTypeException -         ( -            default_value.get_origin(), -            default_value.get_type(), -            first_type -         ) -      ); - -      hint = (Type) hint.generate_comparable_to(default_value.get_type()); - -      if (hint.equals(Type.ANY)) -      { -         ErrorManager.handle -         ( -            new IncomparableTypeException -            ( -               default_value.get_origin(), -               default_value.get_type(), -               first_type -            ) -         ); -      } +      hint = RecurrentChecks.assert_can_be_used_as(default_value, hint);        return new SwitchValue(origin, hint, target, branches, default_value);     } 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 df3c324..9829d37 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java @@ -1,26 +1,16 @@  package tonkadur.fate.v1.lang.computation; -import java.util.ArrayList;  import java.util.List;  import tonkadur.parser.Origin;  import tonkadur.parser.ParsingError; -import tonkadur.functional.Merge; - -import tonkadur.error.ErrorManager; - -import tonkadur.fate.v1.error.IncompatibleTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidArityException; -  import tonkadur.fate.v1.lang.TextEffect; -import tonkadur.fate.v1.lang.type.Type; -  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.RichTextNode;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks;  public class TextWithEffect extends RichTextNode  { @@ -61,79 +51,14 @@ public class TextWithEffect extends RichTextNode        final List<Computation> parameters,        final RichTextNode text     ) -   throws Throwable +   throws ParsingError     { -      final List<Type> signature; - -      signature = effect.get_signature(); - -      if (parameters.size() != signature.size()) -      { -         ErrorManager.handle -         ( -            new InvalidArityException -            ( -               origin, -               parameters.size(), -               signature.size(), -               signature.size() -            ) -         ); -      } - -      (new Merge<Type,Computation,Boolean>() -      { -         @Override -         public Boolean risky_lambda (final Type t, final Computation p) -         throws ParsingError -         { -            if ((t == null) || (p == null)) -            { -               return Boolean.FALSE; -            } -            else -            { -               final Type hint; - -               if (p.get_type().can_be_used_as(t)) -               { -                  return Boolean.TRUE; -               } - -               if (p.get_type().try_merging_with(t) != null) -               { -                  return Boolean.TRUE; -               } - -               ErrorManager.handle -               ( -                  new IncompatibleTypeException -                  ( -                     p.get_origin(), -                     p.get_type(), -                     t -                  ) -               ); - -               hint = (Type) p.get_type().generate_comparable_to(t); - -               if (hint.equals(Type.ANY)) -               { -                  ErrorManager.handle -                  ( -                     new IncomparableTypeException -                     ( -                        p.get_origin(), -                        p.get_type(), -                        t -                     ) -                  ); -               } - -               return Boolean.FALSE; -            } -         } -      }).risky_merge(signature, parameters); +      RecurrentChecks.assert_computations_matches_signature +      ( +         origin, +         parameters, +         effect.get_signature() +      );        return new TextWithEffect(origin, effect, parameters, text);     } diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java index 791e193..e7dadb8 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java @@ -74,7 +74,6 @@ public class AddElement extends Instruction     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(AddElement");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElementsOf.java b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElementsOf.java index 0b4f378..2ffde59 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElementsOf.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElementsOf.java @@ -83,7 +83,6 @@ public class AddElementsOf extends Instruction     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(AddElementsOf");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java index b8ef9de..5384baa 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java @@ -75,7 +75,6 @@ public class RemoveAllOfElement extends Instruction     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(RemoveAllOfElement");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java index ac4d093..040ef99 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java @@ -74,7 +74,6 @@ public class RemoveElement extends Instruction     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(RemoveElement");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElementAt.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElementAt.java index 750dafe..a036970 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElementAt.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElementAt.java @@ -78,7 +78,6 @@ public class RemoveElementAt extends Instruction     {        final StringBuilder sb = new StringBuilder(); -      sb.append(origin.toString());        sb.append("(RemoveElementAt");        sb.append(System.lineSeparator());        sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java b/src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java index 52fe607..43ed6f6 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java @@ -420,6 +420,38 @@ public class RecurrentChecks        );     } +   public static void assert_lambda_matches_computations +   ( +      final Computation l, +      final List<Computation> c +   ) +   throws ParsingError +   { +      assert_is_a_lambda_function(l); +      assert_computations_matches_signature +      ( +         l.get_origin(), +         c, +         ((LambdaType) l.get_type()).get_signature() +      ); +   } + +   public static void assert_lambda_matches_types +   ( +      final Computation l, +      final List<Type> c +   ) +   throws ParsingError +   { +      assert_is_a_lambda_function(l); +      assert_types_matches_signature +      ( +         l.get_origin(), +         c, +         ((LambdaType) l.get_type()).get_signature() +      ); +   } +     public static void assert_lambda_matches_types     (        final Computation l, diff --git a/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java b/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java index 95ff963..443bc84 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java @@ -1,6 +1,7 @@  package tonkadur.fate.v1.lang.type;  import tonkadur.error.ErrorManager; +import tonkadur.parser.ParsingError;  import tonkadur.parser.Origin; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index 1c11821..91ce261 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -85,7 +85,8 @@ LAMBDA_KW: L_PAREN 'lambda' SEP+;  EVAL_KW: L_PAREN 'eval'('uate'?) SEP+;  CLAMP_KW: L_PAREN ('clamp') SEP+;  MODULO_KW: L_PAREN ('modulo'|'%'|'mod') SEP+; -MERGE_KW : L_PAREN 'merge' SEP+; +MERGE_TO_LIST_KW : L_PAREN 'merge'US'to'US'list' SEP+; +MERGE_TO_SET_KW : L_PAREN 'merge'US'to'US'set' SEP+;  IMP_MERGE_KW : L_PAREN 'merge!' SEP+;  NEWLINE_KW: L_PAREN 'newline)';  NEW_KW: L_PAREN ('new'|'reserve'|'create') SEP+; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index 43d284b..95127e5 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -3510,10 +3510,34 @@ returns [Computation result]           );     } +   | MERGE_TO_LIST_KW +         fun=value WS+ +         inr0=value_reference WS+ +         inr1=value_reference WS* +      R_PAREN +   { +      $result = +         MergeComputation.build +         ( +            CONTEXT.get_origin_at +            ( +               ($MERGE_TO_LIST_KW.getLine()), +               ($MERGE_TO_LIST_KW.getCharPositionInLine()) +            ), +            ($fun.result), +            ($inr0.result), +            null, +            ($inr1.result), +            null, +            false +         ); +   } -   | MERGE_KW +   | MERGE_TO_LIST_KW           fun=value WS+ +         def0=value WS+           inr0=value_reference WS+ +         def1=value WS+           inr1=value_reference WS*        R_PAREN     { @@ -3522,18 +3546,42 @@ returns [Computation result]           (              CONTEXT.get_origin_at              ( -               ($MERGE_KW.getLine()), -               ($MERGE_KW.getCharPositionInLine()) +               ($MERGE_TO_LIST_KW.getLine()), +               ($MERGE_TO_LIST_KW.getCharPositionInLine()) +            ), +            ($fun.result), +            ($inr0.result), +            ($def0.result), +            ($inr1.result), +            ($def1.result), +            false +         ); +   } + +   | MERGE_TO_SET_KW +         fun=value WS+ +         inr0=value_reference WS+ +         inr1=value_reference WS* +      R_PAREN +   { +      $result = +         MergeComputation.build +         ( +            CONTEXT.get_origin_at +            ( +               ($MERGE_TO_SET_KW.getLine()), +               ($MERGE_TO_SET_KW.getCharPositionInLine())              ),              ($fun.result),              ($inr0.result),              null,              ($inr1.result), -            null +            null, +            true           );     } -   | MERGE_KW +   | MERGE_TO_SET_KW           fun=value WS+           def0=value WS+           inr0=value_reference WS+ @@ -3546,14 +3594,15 @@ returns [Computation result]           (              CONTEXT.get_origin_at              ( -               ($MERGE_KW.getLine()), -               ($MERGE_KW.getCharPositionInLine()) +               ($MERGE_TO_SET_KW.getLine()), +               ($MERGE_TO_SET_KW.getCharPositionInLine())              ),              ($fun.result),              ($inr0.result),              ($def0.result),              ($inr1.result), -            ($def1.result) +            ($def1.result), +            true           );     } | 


