| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
29 files changed, 501 insertions, 102 deletions
| diff --git a/src/core/src/tonkadur/Main.java b/src/core/src/tonkadur/Main.java index ace2e5e..4385fa5 100644 --- a/src/core/src/tonkadur/Main.java +++ b/src/core/src/tonkadur/Main.java @@ -5,6 +5,7 @@ import java.util.List;  import java.io.IOException;  import tonkadur.parser.Origin; +import tonkadur.parser.Context;  import tonkadur.fate.v1.parser.ParserData; @@ -61,7 +62,11 @@ public class Main           parser_data.add_file_content           (              Origin.BASE_LANGUAGE, -            RuntimeParameters.get_input_file() +            Files.resolve_filename +            ( +               Context.BASE_LANGUAGE, +               RuntimeParameters.get_input_file() +            )           );           System.out.println("Parsing completed."); diff --git a/src/core/src/tonkadur/TonkadurPlugin.java b/src/core/src/tonkadur/TonkadurPlugin.java index 3b3be93..969ac1b 100644 --- a/src/core/src/tonkadur/TonkadurPlugin.java +++ b/src/core/src/tonkadur/TonkadurPlugin.java @@ -30,8 +30,6 @@ public abstract class TonkadurPlugin     public static void register_as_loadable_superclass (final Class c)     { -      System.out.println("[D] Will load subclasses of " + c.getName() + "..."); -        LOADABLE_SUPERCLASSES.add(c);     } @@ -110,15 +108,6 @@ public abstract class TonkadurPlugin              {                 if (superclass.isAssignableFrom(c) && !c.equals(superclass))                 { -                  System.out.println -                  ( -                     "[D] Registering class " -                     + candidate -                     + " as a " -                     + superclass.getName() -                     + "..." -                  ); -                    superclass.getDeclaredMethod                    (                       "register", diff --git a/src/core/src/tonkadur/fate/v1/lang/Variable.java b/src/core/src/tonkadur/fate/v1/lang/Variable.java index bb72565..2d4dbcb 100644 --- a/src/core/src/tonkadur/fate/v1/lang/Variable.java +++ b/src/core/src/tonkadur/fate/v1/lang/Variable.java @@ -12,6 +12,7 @@ import tonkadur.parser.Origin;  import tonkadur.fate.v1.lang.meta.DeclaredEntity;  import tonkadur.fate.v1.lang.type.Type; +import tonkadur.fate.v1.lang.type.FutureType;  public class Variable extends DeclaredEntity  { @@ -73,6 +74,11 @@ public class Variable extends DeclaredEntity     /**** Accessors ************************************************************/     public Type get_type ()     { +      if (type instanceof FutureType) +      { +         return ((FutureType) type).get_current_type(); +      } +        return type;     } diff --git a/src/core/src/tonkadur/fate/v1/lang/World.java b/src/core/src/tonkadur/fate/v1/lang/World.java index a5f1bbe..bc85e83 100644 --- a/src/core/src/tonkadur/fate/v1/lang/World.java +++ b/src/core/src/tonkadur/fate/v1/lang/World.java @@ -27,6 +27,7 @@ import tonkadur.fate.v1.lang.meta.Instruction;  import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.type.ConsType; +import tonkadur.fate.v1.lang.type.PointerType;  import tonkadur.fate.v1.lang.type.DictionaryType;  import tonkadur.fate.v1.lang.type.LambdaType;  import tonkadur.fate.v1.lang.type.SequenceType; @@ -328,6 +329,8 @@ public class World           type_collection.add(DictionaryType.ARCHETYPE); +         type_collection.add(PointerType.ARCHETYPE); +           type_collection.add(LambdaType.ARCHETYPE);           type_collection.add(SequenceType.ARCHETYPE); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java b/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java index d78dcc9..624d61b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java @@ -65,6 +65,11 @@ public class AmbiguousWord extends Computation     {        if (result == null)        { +         if (type instanceof FutureType) +         { +            return ((FutureType) type).get_current_type(); +         } +           return type;        } diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/Access.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/Access.java index 67335f3..ae63ef6 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/Access.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/Access.java @@ -38,6 +38,7 @@ public class Access extends GenericComputation        aliases.add("set:at_index");        aliases.add("set:atindex");        aliases.add("set:atIndex"); +      aliases.add("collection:access");        return aliases;     } @@ -97,7 +98,11 @@ public class Access extends GenericComputation           );        } -      if (alias.startsWith("set:")) +      if (alias.startsWith("collection:")) +      { +         RecurrentChecks.assert_is_a_collection(parent); +      } +      else if (alias.startsWith("set:"))        {           RecurrentChecks.assert_is_a_set(parent);        } @@ -106,7 +111,14 @@ public class Access extends GenericComputation           RecurrentChecks.assert_is_a_list(parent);        } -      return new Access(origin, parent, current_type, index); +      return +         new Access +         ( +            origin, +            parent, +            ((CollectionType) current_type).get_content_type(), +            index +         );     }     /***************************************************************************/ diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java index 996d9b3..8eb4328 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java @@ -44,16 +44,60 @@ public class AddElementComputation extends GenericComputation        final Computation element;        final Computation collection; -      if (call_parameters.size() != 2) +      if (call_parameters.size() < 2)        {           // TODO: Error. -         System.err.println("Wrong number of params at " + origin.toString()); +         System.err.println +         ( +            "Wrong number of params (" +            + (call_parameters.size()) +            + " given, 2 expected) at" +            + origin.toString() +         );           return null;        } -      element = call_parameters.get(0); -      collection = call_parameters.get(1); + +      if (call_parameters.size() > 2) +      { +         final int param_size; +         Computation temp_collection; +         List<Computation> temp_params; + +         param_size = call_parameters.size(); + +         temp_collection = call_parameters.get(param_size - 1); + +         temp_params = new ArrayList<Computation>(); +         temp_params.add(temp_collection); +         temp_params.add(temp_collection); + +         for +         ( +            final Computation addition: +               call_parameters.subList(0, (param_size - 2)) +         ) +         { +            temp_params.set(0, addition); + +            temp_collection = +               build +               ( +                  origin, +                  alias, +                  temp_params +               ); +         } + +         element = call_parameters.get(param_size - 2); +         collection = temp_collection; +      } +      else +      { +         element = call_parameters.get(0); +         collection = call_parameters.get(1); +      }        if (alias.startsWith("set:"))        { diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/BooleanComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/BooleanComputation.java new file mode 100644 index 0000000..ff607ef --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/BooleanComputation.java @@ -0,0 +1,59 @@ +package tonkadur.fate.v1.lang.computation.generic; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.ComputationVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.computation.GenericComputation; + +import tonkadur.fate.v1.lang.computation.Constant; + +public class BooleanComputation extends GenericComputation +{ +   public static Collection<String> get_aliases () +   { +      final Collection<String> aliases; + +      aliases = new ArrayList<String>(); + +      aliases.add("true"); +      aliases.add("false"); + +      return aliases; +   } + +   public static Computation build +   ( +      final Origin origin, +      final String alias, +      final List<Computation> call_parameters +   ) +   throws Throwable +   { +      if (call_parameters.size() != 0) +      { +         // TODO: Error. +         System.err.println("Wrong number of params at " + origin.toString()); + +         return null; +      } + +      return Constant.build_boolean(origin, alias.equals("true")); +   } + +   /***************************************************************************/ +   /**** PUBLIC ***************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +   private BooleanComputation (final Origin origin) +   { +      super(origin, Type.BOOL); +   } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/ConsComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/ConsComputation.java index 6f569a8..2b45b55 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/ConsComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/ConsComputation.java @@ -48,8 +48,8 @@ public class ConsComputation extends GenericComputation        car = call_parameters.get(0);        cdr = call_parameters.get(1); -      car.expect_non_string(); -      cdr.expect_non_string(); +      car.expect_string(); +      cdr.expect_string();        return new ConsComputation(origin, car, cdr);     } diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/IndexedSafeMergeComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/IndexedSafeMergeComputation.java index dc860f6..658b650 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/IndexedSafeMergeComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/IndexedSafeMergeComputation.java @@ -26,15 +26,6 @@ public class IndexedSafeMergeComputation extends GenericComputation        aliases = new ArrayList<String>(); -      aliases.add("list:indexed_merge"); -      aliases.add("list:indexedmerge"); -      aliases.add("list:indexedMerge"); -      aliases.add("list:imerge"); -      aliases.add("set:indexed_merge"); -      aliases.add("set:indexedmerge"); -      aliases.add("set:indexedMerge"); -      aliases.add("set:imerge"); -        aliases.add("list:indexed_safe_merge");        aliases.add("list:indexedsafemerge");        aliases.add("list:indexedSafeMerge"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/Operation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/Operation.java index 46effb9..fed2ea2 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/Operation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/Operation.java @@ -105,7 +105,10 @@ public class Operation extends GenericComputation        operator = Operator.ONE_IN;        ALIASED_OPERATOR.put("exactlyOneIn", operator);        ALIASED_OPERATOR.put("exactlyonein", operator); +      ALIASED_OPERATOR.put("exactlyOne", operator); +      ALIASED_OPERATOR.put("exactlyone", operator);        ALIASED_OPERATOR.put("exactly_one_in", operator); +      ALIASED_OPERATOR.put("exactly_one", operator);        ALIASED_OPERATOR.put("OneIn", operator);        ALIASED_OPERATOR.put("onein", operator);        ALIASED_OPERATOR.put("one_in", operator); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java b/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java index 29a0bd0..065c7db 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java @@ -101,8 +101,6 @@ public abstract class GenericInstruction extends Instruction              );        } -      System.out.println("Resolving GenericInstruction " + name + "..."); -        return           (Instruction) computation_class.getDeclaredMethod           ( diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java b/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java index 17b3ec3..62d88ed 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java @@ -4,6 +4,7 @@ import tonkadur.parser.Origin;  import tonkadur.parser.ParsingError;  import tonkadur.fate.v1.lang.type.Type; +import tonkadur.fate.v1.lang.type.FutureType;  public abstract class Computation extends Node  { @@ -35,6 +36,11 @@ public abstract class Computation extends Node     public Type get_type ()     { +      if (type instanceof FutureType) +      { +         return ((FutureType) type).get_current_type(); +      } +        return type;     } diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java b/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java index 365e70a..8fa713d 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java @@ -17,6 +17,9 @@ import tonkadur.fate.v1.lang.computation.Constant;  import tonkadur.fate.v1.lang.computation.FieldAccess;  import tonkadur.fate.v1.lang.computation.VariableReference; +import tonkadur.fate.v1.lang.computation.generic.AtReference; +import tonkadur.fate.v1.lang.computation.generic.Access; +  import tonkadur.fate.v1.lang.type.CollectionType;  import tonkadur.fate.v1.lang.type.PointerType;  import tonkadur.fate.v1.lang.type.StructType; @@ -33,7 +36,7 @@ public class VariableFromWord        final Origin origin,        final String word     ) -   throws ParsingError +   throws Throwable     {        final String[] subrefs;        Computation result; @@ -67,29 +70,44 @@ public class VariableFromWord              while (t instanceof PointerType)              {                 t = ((PointerType) t).get_referenced_type(); + +               result = +                  AtReference.build +                  ( +                     origin.with_hint(subref), +                     "at", +                     Collections.singletonList(result) +                  );              } -/* +              if (t instanceof CollectionType)              {                 result = -                  AccessAsReference.build +                  Access.build                    ( -                     origin, -                     result, -                     Constant.build(origin, subref) +                     origin.with_hint(subref), +                     "collection:access", +                     Arrays.asList +                     ( +                        new Computation[] +                        { +                           Constant.build(origin.with_hint(subref), subref), +                           result +                        } +                     )                    );              }              else if (t instanceof StructType)              {                 result = -                  FieldReference.build +                  FieldAccess.build                    ( -                     origin, +                     origin.with_hint(subref),                       result,                       Collections.singletonList(subref)                    );              } -            else */ +            else              {                 /* TODO: error */                 System.err.println("Unimplemented error in VariableFromWord."); 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 eb8b664..c3ffb35 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java @@ -1,5 +1,6 @@  package tonkadur.fate.v1.lang.type; +import java.util.List;  import java.util.Collections;  import tonkadur.error.ErrorManager; @@ -84,7 +85,16 @@ public class CollectionType extends Type     /**** Accessors ************************************************************/     public Type get_content_type ()     { -      return parameters.get(0); +      final Type result; + +      result = parameters.get(0); + +      if (result instanceof FutureType) +      { +         return ((FutureType) result).get_resolved_type(); +      } + +      return result;     }     public boolean is_set () @@ -102,7 +112,11 @@ public class CollectionType extends Type     @Override     public boolean can_be_used_as (final Type t)     { -      if (t instanceof CollectionType) +      if (t instanceof FutureType) +      { +         return can_be_used_as(((FutureType) t).get_resolved_type()); +      } +      else if (t instanceof CollectionType)        {           final CollectionType ct; @@ -198,4 +212,20 @@ public class CollectionType extends Type        this.is_set = is_set;     } + +   @Override +   public Type generate_variant +   ( +      final Origin origin, +      final List<Type> parameters +   ) +   throws Throwable +   { +      if (this.parameters.size() != parameters.size()) +      { +         // TODO: error; +      } + +      return new CollectionType(origin, parameters.get(0), is_set, name); +   }  } diff --git a/src/core/src/tonkadur/fate/v1/lang/type/ConsType.java b/src/core/src/tonkadur/fate/v1/lang/type/ConsType.java index 7fe5a34..6430494 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/ConsType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/ConsType.java @@ -1,6 +1,7 @@  package tonkadur.fate.v1.lang.type;  import java.util.Arrays; +import java.util.List;  import tonkadur.parser.Origin; @@ -39,22 +40,60 @@ public class ConsType extends Type        super(origin, null, name, Arrays.asList(new Type[]{car, cdr}));     } +   @Override +   public Type generate_variant +   ( +      final Origin origin, +      final List<Type> parameters +   ) +   throws Throwable +   { +      if (this.parameters.size() != parameters.size()) +      { +         // TODO: error; +      } + +      return new ConsType(origin, parameters.get(0), parameters.get(1), name); +   } +     /**** Accessors ************************************************************/     public Type get_car_type ()     { -      return parameters.get(0); +      final Type result; + +      result = parameters.get(0); + +      if (result instanceof FutureType) +      { +         return ((FutureType) result).get_resolved_type(); +      } + +      return result;     }     public Type get_cdr_type ()     { -      return parameters.get(1); +      final Type result; + +      result = parameters.get(1); + +      if (result instanceof FutureType) +      { +         return ((FutureType) result).get_resolved_type(); +      } + +      return result;     }     /**** Compatibility ********************************************************/     @Override     public boolean can_be_used_as (final Type t)     { -      if (t instanceof ConsType) +      if (t instanceof FutureType) +      { +         return can_be_used_as(((FutureType) t).get_resolved_type()); +      } +      else if (t instanceof ConsType)        {           final ConsType dt; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java b/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java index 18f0a0e..b4d227f 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java @@ -1,5 +1,8 @@  package tonkadur.fate.v1.lang.type; +import java.util.List; +import java.util.Arrays; +  import tonkadur.error.ErrorManager;  import tonkadur.parser.ParsingError; @@ -9,6 +12,8 @@ import tonkadur.fate.v1.error.InvalidTypeException;  import tonkadur.fate.v1.lang.meta.DeclaredEntity; +// TODO: implement. +// TODO: Use parameters list instead of separate type members.  public class DictionaryType extends Type  {     public static final DictionaryType ARCHETYPE; @@ -26,12 +31,6 @@ public class DictionaryType extends Type     }     /***************************************************************************/ -   /**** MEMBERS **************************************************************/ -   /***************************************************************************/ -   protected final Type key_type; -   protected final Type value_type; - -   /***************************************************************************/     /**** PUBLIC ***************************************************************/     /***************************************************************************/ @@ -60,12 +59,30 @@ public class DictionaryType extends Type     /**** Accessors ************************************************************/     public Type get_key_type ()     { -      return key_type; +      final Type result; + +      result = parameters.get(0); + +      if (result instanceof FutureType) +      { +         return ((FutureType) result).get_resolved_type(); +      } + +      return result;     }     public Type get_value_type ()     { -      return value_type; +      final Type result; + +      result = parameters.get(1); + +      if (result instanceof FutureType) +      { +         return ((FutureType) result).get_resolved_type(); +      } + +      return result;     }     @Override @@ -78,7 +95,11 @@ public class DictionaryType extends Type     @Override     public boolean can_be_used_as (final Type t)     { -      if (t instanceof DictionaryType) +      if (t instanceof FutureType) +      { +         return can_be_used_as(((FutureType) t).get_resolved_type()); +      } +      else if (t instanceof DictionaryType)        {           final DictionaryType ct; @@ -86,8 +107,8 @@ public class DictionaryType extends Type           return              ( -               key_type.can_be_used_as(ct.key_type) -               && value_type.can_be_used_as(ct.value_type) +               get_key_type().can_be_used_as(ct.get_key_type()) +               && get_value_type().can_be_used_as(ct.get_value_type())              );        } @@ -116,8 +137,8 @@ public class DictionaryType extends Type           new DictionaryType           (              get_origin(), -            ((Type) key_type.generate_comparable_to(ct.key_type)), -            ((Type) value_type.generate_comparable_to(ct.value_type)), +            ((Type) get_key_type().generate_comparable_to(ct.get_key_type())), +            ((Type) get_value_type().generate_comparable_to(ct.get_value_type())),              name           );     } @@ -127,7 +148,7 @@ public class DictionaryType extends Type     @Override     public Type generate_alias (final Origin origin, final String name)     { -      return new DictionaryType(origin, key_type, value_type, name); +      return new DictionaryType(origin, get_key_type(), get_value_type(), name);     }     @Override @@ -136,9 +157,9 @@ public class DictionaryType extends Type        final StringBuilder sb = new StringBuilder();        sb.append("(Dict "); -      sb.append(key_type.toString()); +      sb.append(get_key_type().toString());        sb.append(" "); -      sb.append(value_type.toString()); +      sb.append(get_value_type().toString());        sb.append(")::");        sb.append(name); @@ -158,9 +179,28 @@ public class DictionaryType extends Type        final String name     )     { -      super(origin, null, name); +      super(origin, null, name, Arrays.asList(new Type[]{key_type, value_type})); +   } -      this.key_type = key_type; -      this.value_type = value_type; +   public Type generate_variant +   ( +      final Origin origin, +      final List<Type> parameters +   ) +   throws Throwable +   { +      if (this.parameters.size() != parameters.size()) +      { +         // TODO: error; +      } + +      return +         new DictionaryType +         ( +            origin, +            parameters.get(0), +            parameters.get(1), +            name +         );     }  } diff --git a/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java b/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java index aed727f..919abd6 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java @@ -19,7 +19,7 @@ public class ExtraType extends Type     public ExtraType     (        final Origin origin, -      final ExtraType parent, +      final Type parent,        final String name,        final List<Type> parameters     ) @@ -27,13 +27,34 @@ public class ExtraType extends Type        super(origin, parent, name, parameters);     } +   @Override +   public Type generate_variant +   ( +      final Origin origin, +      final List<Type> parameters +   ) +   throws Throwable +   { +      if (this.parameters.size() != parameters.size()) +      { +         // TODO: error; +      } + +      return new ExtraType(origin, this, name, parameters); +   } + +     /**** Accessors ************************************************************/     /**** Compatibility ********************************************************/     @Override     public boolean can_be_used_as (final Type t)     { -      if (t instanceof ExtraType) +      if (t instanceof FutureType) +      { +         return can_be_used_as(((FutureType) t).get_resolved_type()); +      } +      else if (t instanceof ExtraType)        {           final ExtraType e; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/FutureType.java b/src/core/src/tonkadur/fate/v1/lang/type/FutureType.java index 5e0650b..f85053d 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/FutureType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/FutureType.java @@ -82,7 +82,6 @@ public class FutureType extends Type        FUTURE_TYPES.add(this);     } -     /**** Accessors ************************************************************/     public Type get_base_type ()     { @@ -98,6 +97,20 @@ public class FutureType extends Type        return resolved_type.get_act_as_type();     } +   public Type get_current_type () +   { +      if (resolved_type == null) +      { +         return this; +      } +      else if (resolved_type instanceof FutureType) +      { +         return ((FutureType) resolved_type).get_current_type(); +      } + +      return resolved_type; +   } +     public boolean is_base_type ()     {        assert_is_resolved(); diff --git a/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java b/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java index 1a6a111..df82195 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java @@ -50,7 +50,16 @@ public class LambdaType extends Type     /**** Accessors ************************************************************/     public Type get_return_type ()     { -      return return_type; +      final Type result; + +      result = return_type; + +      if (result instanceof FutureType) +      { +         return ((FutureType) result).get_resolved_type(); +      } + +      return result;     }     public List<Type> get_signature () @@ -62,7 +71,11 @@ public class LambdaType extends Type     @Override     public boolean can_be_used_as (final Type t)     { -      if (t instanceof LambdaType) +      if (t instanceof FutureType) +      { +         return can_be_used_as(((FutureType) t).get_resolved_type()); +      } +      else if (t instanceof LambdaType)        {           final Iterator<Type> i0, i1;           final LambdaType lt; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/PointerType.java b/src/core/src/tonkadur/fate/v1/lang/type/PointerType.java index db1a18a..daf5bc8 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/PointerType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/PointerType.java @@ -1,6 +1,7 @@  package tonkadur.fate.v1.lang.type;  import java.util.Collections; +import java.util.List;  import tonkadur.parser.Origin; @@ -37,20 +38,39 @@ public class PointerType extends Type        final String name     )     { -      super(origin, null, name, Collections.singletonList(referenced_type)); +      super +      ( +         origin, +         ((referenced_type == Type.ANY) ? null : ARCHETYPE), +         name, +         Collections.singletonList(referenced_type) +      );     }     /**** Accessors ************************************************************/     public Type get_referenced_type ()     { -      return parameters.get(0); +      final Type result; + +      result = parameters.get(0); + +      if (result instanceof FutureType) +      { +         return ((FutureType) result).get_resolved_type(); +      } + +      return result;     }     /**** Compatibility ********************************************************/     @Override     public boolean can_be_used_as (final Type t)     { -      if (t instanceof PointerType) +      if (t instanceof FutureType) +      { +         return can_be_used_as(((FutureType) t).get_resolved_type()); +      } +      else if (t instanceof PointerType)        {           final PointerType dt; @@ -80,6 +100,7 @@ public class PointerType extends Type        }        dt = (PointerType) de; +        resulting_referenced_type =           (Type) get_referenced_type().generate_comparable_to           ( @@ -103,6 +124,22 @@ public class PointerType extends Type     }     @Override +   public Type generate_variant +   ( +      final Origin origin, +      final List<Type> parameters +   ) +   throws Throwable +   { +      if (this.parameters.size() != 1) +      { +         // TODO: error; +      } + +      return new PointerType(origin, parameters.get(0), "auto gen"); +   } + +   @Override     public String toString ()     {        final StringBuilder sb = new StringBuilder(); diff --git a/src/core/src/tonkadur/fate/v1/lang/type/SequenceType.java b/src/core/src/tonkadur/fate/v1/lang/type/SequenceType.java index 0970a98..9adfa61 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/SequenceType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/SequenceType.java @@ -97,7 +97,11 @@ public class SequenceType extends Type     @Override     public boolean can_be_used_as (final Type t)     { -      if (t instanceof SequenceType) +      if (t instanceof FutureType) +      { +         return can_be_used_as(((FutureType) t).get_resolved_type()); +      } +      else if (t instanceof SequenceType)        {           final Iterator<Type> i0, i1;           final SequenceType lt; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/StructType.java b/src/core/src/tonkadur/fate/v1/lang/type/StructType.java index 1d9ab89..c46396b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/StructType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/StructType.java @@ -67,7 +67,11 @@ public class StructType extends Type     @Override     public boolean can_be_used_as (final Type t)     { -      if (t instanceof StructType) +      if (t instanceof FutureType) +      { +         return can_be_used_as(((FutureType) t).get_resolved_type()); +      } +      else if (t instanceof StructType)        {           final StructType dt; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/Type.java b/src/core/src/tonkadur/fate/v1/lang/type/Type.java index c1e074b..1bed5da 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/Type.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/Type.java @@ -155,7 +155,11 @@ public class Type extends DeclaredEntity     /**** Compatibility ********************************************************/     public boolean can_be_used_as (final Type t)     { -      if (!get_act_as_type().equals(t.get_act_as_type())) +      if (t instanceof FutureType) +      { +         return can_be_used_as(((FutureType) t).get_resolved_type()); +      } +      else if (!get_act_as_type().equals(t.get_act_as_type()))        {           return false;        } diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index 4c6a5d4..ca632dd 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -58,7 +58,7 @@ VISIT_KW:     (        ('call'|'visit') US ((('seq'|'Seq')'uence'?)|('proc'|'Proc')'edure'?)?     ) -   IMP; +   IMP SEP+;  CONTINUE_AS_KW:     L_PAREN @@ -78,7 +78,7 @@ CONTINUE_AS_KW:        )        (US ((('seq'|'Seq')'uence'?)|('proc'|'Proc')'edure'?))?     ) -   IMP; +   IMP SEP+;  VARIABLE_KW: L_PAREN ('variable'|'var') SEP+; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index 80e1213..aded279 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -640,6 +640,8 @@ returns [Instruction result]           elem_type = Type.ANY; +         ($coll.result).expect_non_string(); +           collection_type = ($coll.result).get_type();           /* FIXME: This doesn't let you use it with a Dict. */ @@ -961,11 +963,14 @@ returns [Instruction result]        }        else        { +         final String keyword; + +         keyword = ($VISIT_KW.text).trim();           $result =              GenericInstruction.build              (                 origin, -               ($VISIT_KW.text).substring(0, (($VISIT_KW.text).length() - 1)), +               keyword.substring(1, (keyword.length() - 1)),                 ($maybe_computation_list.result)              );        } @@ -1009,15 +1014,14 @@ returns [Instruction result]        }        else        { +         final String keyword; + +         keyword = ($CONTINUE_AS_KW.text).trim();           $result =              GenericInstruction.build              (                 origin, -               ($CONTINUE_AS_KW.text).substring -               ( -                  0, -                  (($CONTINUE_AS_KW.text).length() - 1) -               ), +               keyword.substring(1, (keyword.length() - 1)),                 ($maybe_computation_list.result)              );        } @@ -1427,6 +1431,8 @@ returns [Instruction result]           elem_type = Type.ANY; +         ($computation.result).expect_non_string(); +           collection_type = ($computation.result).get_type();           if (collection_type instanceof CollectionType) @@ -1647,11 +1653,9 @@ returns [Type result]        }     } -   | LAMBDA_KW type WS* L_PAREN maybe_type_list R_PAREN WS* R_PAREN +   | LAMBDA_KW type WS* L_PAREN no_space_maybe_type_list R_PAREN WS* R_PAREN     { -      final Type t; - -      t = +      $result =           new LambdaType           (              PARSER.get_origin_at @@ -1661,15 +1665,13 @@ returns [Type result]              ),              ($type.result),              "autogenerated lambda type", -            ($maybe_type_list.result) +            ($no_space_maybe_type_list.result)           );     } -   | SEQUENCE_KW maybe_type_list R_PAREN +   | SEQUENCE_KW no_space_maybe_type_list R_PAREN     { -      final Type t; - -      t = +      $result =           new SequenceType           (              PARSER.get_origin_at @@ -1678,7 +1680,7 @@ returns [Type result]                 ($SEQUENCE_KW.getCharPositionInLine())              ),              "autogenerated sequence type", -            ($maybe_type_list.result) +            ($no_space_maybe_type_list.result)           );     } @@ -1742,6 +1744,29 @@ returns [List<Type> result]     }  ; +no_space_maybe_type_list +returns [List<Type> result] +@init +{ +   $result = new ArrayList<Type>(); +} +: +   (WS* +      type +      { +         $result.add(($type.result)); +      } +   )* +   (WS+ +      type +      { +         $result.add(($type.result)); +      } +   )* +   { +   } +; +  let_variable_list  returns [List<Cons<Variable, Computation>> result]  @init @@ -2309,6 +2334,11 @@ returns [Computation result]           );     } +   | TEXT_KW paragraph WS* R_PAREN +   { +      $result = ($paragraph.result); +   } +     | ENABLE_TEXT_EFFECT_KW word WS+ paragraph WS* R_PAREN     {        final TextEffect effect; @@ -2368,7 +2398,7 @@ returns [Computation result]           );     } -   | IF_KW maybe_computation_list WS* R_PAREN +   | IF_KW computation_list WS* R_PAREN     {        $result =           GenericComputation.build @@ -2378,12 +2408,12 @@ returns [Computation result]                 ($IF_KW.getLine()),                 ($IF_KW.getCharPositionInLine())              ), -            ($IF_KW.text).substring(1), -            ($maybe_computation_list.result) +            ($IF_KW.text).substring(1).trim(), +            ($computation_list.result)           );     } -   | IF_ELSE_KW maybe_computation_list WS* R_PAREN +   | IF_ELSE_KW computation_list WS* R_PAREN     {        $result =           GenericComputation.build @@ -2393,8 +2423,8 @@ returns [Computation result]                 ($IF_ELSE_KW.getLine()),                 ($IF_ELSE_KW.getCharPositionInLine())              ), -            ($IF_ELSE_KW.text).substring(1), -            ($maybe_computation_list.result) +            ($IF_ELSE_KW.text).substring(1).trim(), +            ($computation_list.result)           );     }  ; @@ -2575,6 +2605,17 @@ word returns [String result, Origin origin]:           );     } +   | IMP_MARKER +   { +      $result = "!"; +      $origin = +         PARSER.get_origin_at +         ( +            ($IMP_MARKER.getLine()), +            ($IMP_MARKER.getCharPositionInLine()) +         ); +   } +     | IDENTIFIER_KW     {        $result = $IDENTIFIER_KW.text; diff --git a/src/core/src/tonkadur/fate/v1/parser/ParserData.java b/src/core/src/tonkadur/fate/v1/parser/ParserData.java index ce73193..7f1530d 100644 --- a/src/core/src/tonkadur/fate/v1/parser/ParserData.java +++ b/src/core/src/tonkadur/fate/v1/parser/ParserData.java @@ -202,7 +202,7 @@ public class ParserData        }     } -   public void add_file_content (final Origin origin, final String filename) +   public void add_file_content (final Origin origin, String filename)     throws IOException, ParsingError     {        final CommonTokenStream tokens; diff --git a/src/core/src/tonkadur/parser/Context.java b/src/core/src/tonkadur/parser/Context.java index f99ad2b..6f0a64c 100644 --- a/src/core/src/tonkadur/parser/Context.java +++ b/src/core/src/tonkadur/parser/Context.java @@ -13,7 +13,12 @@ public class Context     static     { -      BASE_LANGUAGE = new Context(null, "<Base Language>"); +      BASE_LANGUAGE = +         new Context +         ( +            Paths.get(System.getProperty("user.dir")), +            "<Base Language>" +         );     }     /***************************************************************************/ diff --git a/src/core/src/tonkadur/parser/Location.java b/src/core/src/tonkadur/parser/Location.java index af89e7b..1b4ae0a 100644 --- a/src/core/src/tonkadur/parser/Location.java +++ b/src/core/src/tonkadur/parser/Location.java @@ -1,6 +1,7 @@  package tonkadur.parser;  import java.nio.file.Path; +import java.nio.file.Paths;  public class Location  { @@ -11,7 +12,15 @@ public class Location     static     { -      BASE_LANGUAGE = new Location(true, null, "", -1, -1); +      BASE_LANGUAGE = +         new Location +         ( +            true, +            Paths.get(System.getProperty("user.dir")), +            "", +            -1, +            -1 +         );     }     /***************************************************************************/ | 


