| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/core')
10 files changed, 231 insertions, 274 deletions
| diff --git a/src/core/src/tonkadur/RuntimeParameters.java b/src/core/src/tonkadur/RuntimeParameters.java index 5a4d073..d62263d 100644 --- a/src/core/src/tonkadur/RuntimeParameters.java +++ b/src/core/src/tonkadur/RuntimeParameters.java @@ -85,7 +85,7 @@ public class RuntimeParameters        );        System.out.println        ( -         " -p|--plugin <jar>\tLoads plugin classes from jar file." +         " -p|--plugin <jar>\t\tLoads plugin classes from jar file."        );        System.out.println        ( diff --git a/src/core/src/tonkadur/TonkadurPlugin.java b/src/core/src/tonkadur/TonkadurPlugin.java index cf086e8..3b3be93 100644 --- a/src/core/src/tonkadur/TonkadurPlugin.java +++ b/src/core/src/tonkadur/TonkadurPlugin.java @@ -30,6 +30,8 @@ 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);     } @@ -72,7 +74,11 @@ public abstract class TonkadurPlugin           candidate = entries.nextElement();           candidate_name = candidate.getName(); -         if (!candidate_name.endsWith(".class")) +         if +         ( +            !candidate_name.endsWith(".class") +            || candidate_name.startsWith("org/antlr/") +         )           {              continue;           } diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java b/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java index e228e37..cbd0b6b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java @@ -11,7 +11,7 @@ import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.ExtraComputation;  import tonkadur.fate.v1.lang.meta.RecurrentChecks; -public class ExtraComputationInstance extends GenericComputation +public class ExtraComputationInstance extends Computation  {     protected final ExtraComputation computation;     protected final List<Computation> parameters; diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java index dc01b94..935e195 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java @@ -14,7 +14,7 @@ import tonkadur.fate.v1.lang.type.Type;  import tonkadur.fate.v1.lang.meta.ComputationVisitor;  import tonkadur.fate.v1.lang.meta.Computation; -public class GenericComputation extends Computation +public abstract class GenericComputation extends Computation  {     /***************************************************************************/     /**** STATIC ***************************************************************/ @@ -33,7 +33,7 @@ public class GenericComputation extends Computation           for           (              final String alias: -               (List<String>) c.getMethod("get_aliases").invoke +               (Collection<String>) c.getMethod("get_aliases").invoke                 (                    /* object = */null                 ) @@ -46,7 +46,7 @@ public class GenericComputation extends Computation              if (previous_entry != null)              {                 // TODO Exception handling. -               new Exception +               throw new Exception                 (                    "[F] Unable to add alias for Generic Fate Computation '"                    + alias @@ -56,8 +56,6 @@ public class GenericComputation extends Computation                    + previous_entry.getName()                    + "'."                 ); - -               System.exit(-1);              }              REGISTERED.put(alias, c); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/ExtraInstructionInstance.java b/src/core/src/tonkadur/fate/v1/lang/instruction/ExtraInstructionInstance.java index e485ffa..2a5a13e 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/ExtraInstructionInstance.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/ExtraInstructionInstance.java @@ -12,7 +12,7 @@ import tonkadur.fate.v1.lang.meta.InstructionVisitor;  import tonkadur.fate.v1.lang.meta.ExtraInstruction;  import tonkadur.fate.v1.lang.meta.RecurrentChecks; -public class ExtraInstructionInstance extends GenericInstruction +public class ExtraInstructionInstance extends Instruction  {     protected final ExtraInstruction instruction;     protected final List<Computation> parameters; @@ -28,7 +28,7 @@ public class ExtraInstructionInstance extends GenericInstruction        final List<Computation> parameters     )     { -      super(origin, instruction.get_name()); +      super(origin);        this.instruction = instruction;        this.parameters = parameters; 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 0035ac0..5483f5a 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java @@ -11,21 +11,68 @@ import tonkadur.functional.Cons;  import tonkadur.fate.v1.lang.type.Type; -import tonkadur.fate.v1.lang.meta.InstructionVisitor; -import tonkadur.fate.v1.lang.meta.Instruction;  import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.InstructionVisitor; -public class GenericInstruction extends Instruction +public abstract class GenericInstruction extends Instruction  {     /***************************************************************************/     /**** STATIC ***************************************************************/     /***************************************************************************/ -   protected static final Map<String, Cons<GenericInstruction, Object>> -      REGISTERED; +   protected static final Map<String, Class> REGISTERED;     static     { -      REGISTERED = new HashMap<String, Cons<GenericInstruction, Object>>(); +      REGISTERED = new HashMap<String, Class>(); +   } + +   public static void register (final Class c) +   { +      try +      { +         for +         ( +            final String alias: +               (Collection<String>) c.getMethod("get_aliases").invoke +               ( +                  /* object = */null +               ) +         ) +         { +            final Class previous_entry; + +            previous_entry = REGISTERED.get(alias); + +            if (previous_entry != null) +            { +               // TODO Exception handling. +               throw new Exception +               ( +                  "[F] Unable to add alias for Generic Fate Instruction '" +                  + alias +                  + "' from class '" +                  + c.getName() +                  + "': it has already been claimed by class '" +                  + previous_entry.getName() +                  + "'." +               ); +            } + +            REGISTERED.put(alias, c); +         } +      } +      catch (final Throwable t) +      { +         System.err.println +         ( +            "Could not register Generic Fate Instruction class '" +            + c.getName() +            + "': " +         ); + +         t.printStackTrace(); +      }     }     public static GenericInstruction build @@ -36,102 +83,44 @@ public class GenericInstruction extends Instruction     )     throws Throwable     { -      final Cons<GenericInstruction, Object> target; +      final Class computation_class; -      target = REGISTERED.get(name); +      computation_class = REGISTERED.get(name); -      if (target == null) +      if (computation_class == null)        { -         // TODO Exception handling. +         // TODO use a separate class for this. +         throw +            new Exception +            ( +               "[E] Unknown Generic Fate Instruction '" +               + name +               + "'." +            );        } -      return target.get_car().build(origin, call_parameters, target.get_cdr()); +      return +         (GenericInstruction) computation_class.getDeclaredMethod +         ( +            "build", +            Origin.class, +            String.class, +            List.class +         ).invoke(/* object = */ null, origin, name, call_parameters);     }     /***************************************************************************/ -   /**** MEMBERS **************************************************************/ -   /***************************************************************************/ -   protected final String name; - -   /***************************************************************************/     /**** PROTECTED ************************************************************/     /***************************************************************************/     /**** Constructors *********************************************************/ -   protected GenericInstruction -   ( -      final Origin origin, -      final String name -   ) +   protected GenericInstruction (final Origin origin)     {        super(origin); - -      this.name = name; -   } - -   protected GenericInstruction build -   ( -      final Origin origin, -      final List<Computation> call_parameters, -      final Object constructor_parameter -   ) -   throws Throwable -   { -      throw -         new Exception -         ( -            "Missing build function for GenericInstruction '" -            + name -            + "'." -         ); -   } - -   protected void register -   ( -      final String name, -      final Object constructor_parameter -   ) -   throws Exception -   { -      if (REGISTERED.containsKey(name)) -      { -         // TODO Exception handling. -         new Exception -         ( -            "There already is a GenericInstruction with the name '" -            + name -            + "'." -         ); - -         return; -      } - -      REGISTERED.put(name, new Cons(this, constructor_parameter)); -   } - -   protected void register (final Object constructor_parameter) -   throws Exception -   { -      register(get_name(), constructor_parameter); -   } - -   protected void register -   ( -      final Collection<String> names, -      final Object constructor_parameter -   ) -   throws Exception -   { -      for (final String name: names) -      { -         register(name, constructor_parameter); -      }     }     /***************************************************************************/     /**** PUBLIC ***************************************************************/     /***************************************************************************/ -   /**** Constructors *********************************************************/ -     /**** Accessors ************************************************************/     @Override     public void get_visited_by (final InstructionVisitor cv) @@ -139,22 +128,4 @@ public class GenericInstruction extends Instruction     {        cv.visit_generic_instruction(this);     } - -   public String get_name () -   { -      return name; -   } - -   /**** Misc. ****************************************************************/ -   @Override -   public String toString () -   { -      final StringBuilder sb = new StringBuilder(); - -      sb.append("(GenericInstruction "); -      sb.append(get_name()); -      sb.append(")"); - -      return sb.toString(); -   }  } diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Allocate.java b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Allocate.java index cc159f5..feaf65b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Allocate.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Allocate.java @@ -2,6 +2,7 @@ package tonkadur.fate.v1.lang.instruction.generic;  import java.util.ArrayList;  import java.util.Collections; +import java.util.Collection;  import java.util.List;  import tonkadur.error.ErrorManager; @@ -20,85 +21,47 @@ import tonkadur.fate.v1.lang.instruction.GenericInstruction;  public class Allocate extends GenericInstruction  { -   protected static final Allocate ARCHETYPE; - -   static +   public static Collection<String> get_aliases ()     {        final List<String> aliases;        aliases = new ArrayList<String>(); -      ARCHETYPE = -         new Allocate -         ( -            Origin.BASE_LANGUAGE, -            null, -            null -         ); -        aliases.add("allocate");        aliases.add("alloc");        aliases.add("malloc"); -      aliases.add("malloc");        aliases.add("new");        aliases.add("create"); -      try -      { -         ARCHETYPE.register(aliases, null); -      } -      catch (final Exception e) -      { -         e.printStackTrace(); - -         System.exit(-1); -      } -   } - -   /***************************************************************************/ -   /**** MEMBERS **************************************************************/ -   /***************************************************************************/ -   protected final Computation target; -   protected final Type allocated_type; - -   /***************************************************************************/ -   /**** PROTECTED ************************************************************/ -   /***************************************************************************/ -   /**** Constructors *********************************************************/ -   protected Allocate -   ( -      final Origin origin, -      final Type allocated_type, -      final Computation target -   ) -   { -      super(origin, "allocate"); - -      this.allocated_type = allocated_type; -      this.target = target; +      return aliases;     } -   /***************************************************************************/ -   /**** PUBLIC ***************************************************************/ -   /***************************************************************************/ -   /**** Constructors *********************************************************/ -   @Override -   public GenericInstruction build +   public static GenericInstruction build     (        final Origin origin, -      final List<Computation> call_parameters, -      final Object _constructor_parameter +      final String _alias, +      final List<Computation> call_parameters     )     throws Throwable     { +      final Computation target;        final Type target_type;        if (call_parameters.size() != 1)        { -         // Error. +         // TODO: Error. +         System.err.print +         ( +            "[E] Wrong number of arguments at " +            + origin.toString() +         ); + +         return null;        } -      call_parameters.get(0).expect_non_string(); +      target = call_parameters.get(0); + +      target.expect_non_string();        target_type = target.get_type(); @@ -129,6 +92,34 @@ public class Allocate extends GenericInstruction        return new Allocate(origin, Type.ANY, target);     } +   /***************************************************************************/ +   /**** MEMBERS **************************************************************/ +   /***************************************************************************/ +   protected final Computation target; +   protected final Type allocated_type; + +   /***************************************************************************/ +   /**** PROTECTED ************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +   protected Allocate +   ( +      final Origin origin, +      final Type allocated_type, +      final Computation target +   ) +   { +      super(origin); + +      this.allocated_type = allocated_type; +      this.target = target; +   } + +   /***************************************************************************/ +   /**** PUBLIC ***************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +     /**** Accessors ************************************************************/     public Computation get_target ()     { diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Clear.java b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Clear.java index 2c42c91..12da2cb 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Clear.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Clear.java @@ -1,7 +1,8 @@  package tonkadur.fate.v1.lang.instruction.generic; -import java.util.List;  import java.util.ArrayList; +import java.util.List; +import java.util.Collection;  import tonkadur.parser.Origin;  import tonkadur.parser.ParsingError; @@ -13,14 +14,10 @@ import tonkadur.fate.v1.lang.instruction.GenericInstruction;  public class Clear extends GenericInstruction  { -   protected static final Clear ARCHETYPE; - -   static +   public static Collection<String> get_aliases ()     {        final List<String> aliases; -      ARCHETYPE = new Clear(Origin.BASE_LANGUAGE, null); -        aliases = new ArrayList<String>();        aliases.add("clear"); @@ -32,16 +29,36 @@ public class Clear extends GenericInstruction        aliases.add("set:clear");        aliases.add("set:empty"); -      try +      return aliases; +   } + +   public static GenericInstruction build +   ( +      final Origin origin, +      final String alias_, +      final List<Computation> call_parameters +   ) +   throws Throwable +   { +      final Computation collection; + +      if (call_parameters.size() != 1)        { -         ARCHETYPE.register(aliases, null); +         // TODO: Error. +         System.err.print +         ( +            "[E] Wrong number of arguments at " +            + origin.toString() +         );        } -      catch (final Exception e) -      { -         e.printStackTrace(); -         System.exit(-1); -      } +      collection = call_parameters.get(0); + +      collection.expect_non_string(); + +      RecurrentChecks.assert_is_a_collection(collection); + +      return new Clear(origin, collection);     }     /***************************************************************************/ @@ -59,7 +76,7 @@ public class Clear extends GenericInstruction        final Computation collection     )     { -      super(origin, "clear"); +      super(origin);        this.collection = collection;     } @@ -68,30 +85,6 @@ public class Clear extends GenericInstruction     /**** PUBLIC ***************************************************************/     /***************************************************************************/     /**** Constructors *********************************************************/ -   @Override -   public GenericInstruction build -   ( -      final Origin origin, -      final List<Computation> call_parameters, -      final Object _constructor_parameter -   ) -   throws Throwable -   { -      final Computation collection; - -      if (call_parameters.size() != 1) -      { -         // Error. -      } - -      collection = call_parameters.get(0); - -      collection.expect_non_string(); - -      RecurrentChecks.assert_is_a_collection(collection); - -      return new Clear(origin, collection); -   }     /**** Accessors ************************************************************/     public Computation get_collection () diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Free.java b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Free.java index cc1eb50..4fd8241 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Free.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/Free.java @@ -1,8 +1,9 @@  package tonkadur.fate.v1.lang.instruction.generic; -import java.util.List;  import java.util.ArrayList; +import java.util.Collection;  import java.util.Collections; +import java.util.List;  import tonkadur.error.ErrorManager; @@ -19,64 +20,23 @@ import tonkadur.fate.v1.lang.instruction.GenericInstruction;  public class Free extends GenericInstruction  { -   protected static final Free ARCHETYPE; - -   static +   public static Collection<String> get_aliases ()     {        final List<String> aliases;        aliases = new ArrayList<String>(); - -      ARCHETYPE = -         new Free -         ( -            Origin.BASE_LANGUAGE, -            null -         ); -        aliases.add("free");        aliases.add("delete");        aliases.add("destroy"); -      try -      { -         ARCHETYPE.register(aliases, null); -      } -      catch (final Exception e) -      { -         e.printStackTrace(); - -         System.exit(-1); -      } +      return aliases;     } -   /***************************************************************************/ -   /**** MEMBERS **************************************************************/ -   /***************************************************************************/ -   protected final Computation value_reference; - -   /***************************************************************************/ -   /**** PROTECTED ************************************************************/ -   /***************************************************************************/ -   /**** Constructors *********************************************************/ - -   /***************************************************************************/ -   /**** PUBLIC ***************************************************************/ -   /***************************************************************************/ -   /**** Constructors *********************************************************/ -   protected Free (final Origin origin, final Computation value_reference) -   { -      super(origin, "free"); - -      this.value_reference = value_reference; -   } - -   @Override -   public GenericInstruction build +   public static GenericInstruction build     (        final Origin origin, -      final List<Computation> call_parameters, -      final Object _constructor_parameter +      final String alias_, +      final List<Computation> call_parameters     )     throws Throwable     { @@ -85,7 +45,12 @@ public class Free extends GenericInstruction        if (call_parameters.size() != 1)        { -         // Error. +         // TODO: Error. +         System.err.print +         ( +            "[E] Wrong number of arguments at " +            + origin.toString() +         );        }        call_parameters.get(0).expect_non_string(); @@ -115,6 +80,27 @@ public class Free extends GenericInstruction        return new Free(origin, target);     } +   /***************************************************************************/ +   /**** MEMBERS **************************************************************/ +   /***************************************************************************/ +   protected final Computation value_reference; + +   /***************************************************************************/ +   /**** PROTECTED ************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ + +   /***************************************************************************/ +   /**** PUBLIC ***************************************************************/ +   /***************************************************************************/ +   /**** Constructors *********************************************************/ +   protected Free (final Origin origin, final Computation value_reference) +   { +      super(origin); + +      this.value_reference = value_reference; +   } +     /**** Accessors ************************************************************/     public Computation get_reference ()     { diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/GenericComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/GenericComputationCompiler.java index 6b08383..a5ae047 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/GenericComputationCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/computation/GenericComputationCompiler.java @@ -8,11 +8,38 @@ import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler;  public abstract class GenericComputationCompiler extends ComputationCompiler  { -   protected static final Map<String, Class> ARCHETYPES; +   protected static final Map<Class, Class> COMPILERS;     static     { -      ARCHETYPES = new HashMap<String, Class>(); +      COMPILERS = new HashMap<Class, Class>(); +   } + +   public static void register (final Class c) +   { +      try +      { +         COMPILERS.put +         ( +            (Class) c.getDeclaredMethod("get_target_class").invoke +            ( +               /* object  = */ null +            ), +            c +         ); +      } +      catch (final Throwable t) +      { +         System.err.println +         ( +            "[F] Could not get target class for Wyrd Generic Computation" +            + " Compiler '" +            + c.getName() +            + "':" +         ); + +         t.printStackTrace(); +      }     }     public static ComputationCompiler handle @@ -25,7 +52,7 @@ public abstract class GenericComputationCompiler extends ComputationCompiler        final Class registered_class;        final GenericComputationCompiler gcc; -      registered_class = ARCHETYPES.get(computation.get_name()); +      registered_class = COMPILERS.get(computation.getClass());        if (registered_class == null)        { @@ -33,26 +60,13 @@ public abstract class GenericComputationCompiler extends ComputationCompiler           (              "[F] No Wyrd compilation process registered for generic Fate "              + " computation \"" -            + computation.get_name() +            + computation.getClass().getName()              + "\"."           );           System.exit(-1);        } -      if (!GenericComputationCompiler.class.isAssignableFrom(registered_class)) -      { -         System.err.println -         ( -            "[F] The class registered to compile generic Fate " -            + " computation \"" -            + computation.get_name() -            + "\" to Wyrd does not extend the GenericComputationCompiler class." -         ); - -         System.exit(-1); -      } -        gcc =           (GenericComputationCompiler)           registered_class.getDeclaredConstructor(Compiler.class).newInstance @@ -65,13 +79,11 @@ public abstract class GenericComputationCompiler extends ComputationCompiler        return gcc;     } -   protected void compile +   protected abstract void compile     (        final tonkadur.fate.v1.lang.computation.GenericComputation computation     ) -   throws Throwable -   { -   } +   throws Throwable;     protected GenericComputationCompiler (final Compiler compiler)     { | 


