summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/src/tonkadur/Main.java12
-rw-r--r--src/core/src/tonkadur/RuntimeParameters.java36
-rw-r--r--src/core/src/tonkadur/TonkadurPlugin.java168
-rw-r--r--src/core/src/tonkadur/fate/v1/Base.java8
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java2
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java174
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/generic/AddressOperator.java65
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/generic/AtReference.java102
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/generic/LambdaEvaluation.java96
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/generic/Operation.java580
-rw-r--r--src/core/src/tonkadur/plugin/base/BaseLanguage.java47
11 files changed, 445 insertions, 845 deletions
diff --git a/src/core/src/tonkadur/Main.java b/src/core/src/tonkadur/Main.java
index a9c53d9..ace2e5e 100644
--- a/src/core/src/tonkadur/Main.java
+++ b/src/core/src/tonkadur/Main.java
@@ -20,22 +20,24 @@ public class Main
final tonkadur.fate.v1.lang.World fate_world;
final tonkadur.wyrd.v1.lang.World wyrd_world;
final ParserData parser_data;
+ final boolean valid_use;
tonkadur.fate.v1.Base.initialize();
tonkadur.wyrd.v1.Base.initialize();
+ TonkadurPlugin.load_special_classes();
- if (!RuntimeParameters.parse_options(args))
- {
- plugins = TonkadurPlugin.get_plugins();
+ valid_use = RuntimeParameters.parse_options(args);
+
+ plugins = TonkadurPlugin.get_plugins();
+ if (!valid_use)
+ {
RuntimeParameters.print_usage(plugins);
return;
}
- plugins = TonkadurPlugin.get_plugins();
-
for (final TonkadurPlugin tp: plugins)
{
tp.initialize(args);
diff --git a/src/core/src/tonkadur/RuntimeParameters.java b/src/core/src/tonkadur/RuntimeParameters.java
index 1ecf107..5a4d073 100644
--- a/src/core/src/tonkadur/RuntimeParameters.java
+++ b/src/core/src/tonkadur/RuntimeParameters.java
@@ -7,13 +7,14 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.jar.JarFile;
+
import tonkadur.error.ErrorCategory;
public class RuntimeParameters
{
protected static final String version;
protected static final List<String> include_directories;
- protected static final List<String> jar_files;
protected static final Collection<ErrorCategory> disabled_errors;
protected static final Collection<ErrorCategory> tolerated_errors;
protected static boolean consider_warnings_as_errors;
@@ -23,7 +24,6 @@ public class RuntimeParameters
{
version = "0.9.2";
include_directories = new ArrayList<String>();
- jar_files = new ArrayList<String>();
disabled_errors = new HashSet<ErrorCategory>();
tolerated_errors = new HashSet<ErrorCategory>();
consider_warnings_as_errors = false;
@@ -49,11 +49,6 @@ public class RuntimeParameters
return include_directories;
}
- public static List<String> get_jar_plugins ()
- {
- return jar_files;
- }
-
public static String get_input_file ()
{
return target_file;
@@ -90,7 +85,7 @@ public class RuntimeParameters
);
System.out.println
(
- " -p|--plugin <jar>\tLoads 'tonkadur.plugin.*' classes from file."
+ " -p|--plugin <jar>\tLoads plugin classes from jar file."
);
System.out.println
(
@@ -138,12 +133,35 @@ public class RuntimeParameters
}
else if (option.equals("-p") || option.equals("--plugin"))
{
+ final String jar_name;
+
if (!options_it.hasNext())
{
return false;
}
- jar_files.add(options_it.next());
+ jar_name = options_it.next();
+
+ try
+ {
+ System.out.println("[D] Loading jar '" + jar_name +"'...");
+
+ TonkadurPlugin.load_all_relevant_classes_in
+ (
+ new JarFile(jar_name)
+ );
+ }
+ catch (final Throwable t)
+ {
+ System.err.println
+ (
+ "[F] Unable to load plugin jar '" + jar_name + "':"
+ );
+
+ t.printStackTrace();
+
+ System.exit(-1);
+ }
}
else if (option.equals("-te") || option.equals("--tolerate-error"))
{
diff --git a/src/core/src/tonkadur/TonkadurPlugin.java b/src/core/src/tonkadur/TonkadurPlugin.java
index d7151aa..cf086e8 100644
--- a/src/core/src/tonkadur/TonkadurPlugin.java
+++ b/src/core/src/tonkadur/TonkadurPlugin.java
@@ -17,17 +17,51 @@ import tonkadur.parser.Context;
public abstract class TonkadurPlugin
{
- public static List<Class> get_classes_in
+ protected static final List<Class> LOADABLE_SUPERCLASSES;
+ protected static final List<TonkadurPlugin> TONKADUR_PLUGINS;
+
+ static
+ {
+ LOADABLE_SUPERCLASSES = new ArrayList<Class>();
+ TONKADUR_PLUGINS = new ArrayList<TonkadurPlugin>();
+
+ register_as_loadable_superclass(TonkadurPlugin.class);
+ }
+
+ public static void register_as_loadable_superclass (final Class c)
+ {
+ LOADABLE_SUPERCLASSES.add(c);
+ }
+
+ public static void register (final Class c)
+ {
+ try
+ {
+ TONKADUR_PLUGINS.add
+ (
+ (TonkadurPlugin) c.getConstructor().newInstance()
+ );
+ }
+ catch (final Throwable t)
+ {
+ System.err.println
+ (
+ "[E] Unable to create an instance of Tonkadur Plugin class '"
+ + c.getName()
+ + "':"
+ );
+
+ t.printStackTrace();
+ }
+ }
+
+ public static void load_all_relevant_classes_in
(
- final JarFile current_jar,
- final String folder_path
+ final JarFile current_jar
)
{
- final List<Class> result;
final Enumeration<JarEntry> entries;
- result = new ArrayList<Class>();
-
entries = current_jar.entries();
while (entries.hasMoreElements())
@@ -38,11 +72,7 @@ public abstract class TonkadurPlugin
candidate = entries.nextElement();
candidate_name = candidate.getName();
- if
- (
- !candidate_name.endsWith(".class")
- || !candidate_name.startsWith(folder_path)
- )
+ if (!candidate_name.endsWith(".class"))
{
continue;
}
@@ -54,12 +84,11 @@ public abstract class TonkadurPlugin
'.'
).substring(0, (candidate_name.length() - 6));
- System.out.println("[D] Loading class " + candidate + "...");
-
try
{
- result.add
- (
+ final Class c;
+
+ c =
Class.forName
(
candidate_name,
@@ -69,86 +98,57 @@ public abstract class TonkadurPlugin
new URL[]{new File(current_jar.getName()).toURI().toURL()},
TonkadurPlugin.class.getClassLoader()
)
- )
- );
- }
- catch (final Throwable e)
- {
- System.err.println
- (
- "Could not load class "
- + candidate_name
- + ": "
- );
- e.printStackTrace();
- }
- }
+ );
- return result;
- }
-
- public static void initialize_classes_in
- (
- final JarFile current_jar,
- final String folder_path
- )
- throws Throwable
- {
- // This already initializes the classes.
- get_classes_in(current_jar, folder_path);
- }
-
- public static List<TonkadurPlugin> extract_plugins_from
- (
- final JarFile current_jar
- )
- {
- final List<TonkadurPlugin> plugins;
-
- plugins = new ArrayList<TonkadurPlugin>();
+ for (final Class superclass: LOADABLE_SUPERCLASSES)
+ {
+ if (superclass.isAssignableFrom(c) && !c.equals(superclass))
+ {
+ System.out.println
+ (
+ "[D] Registering class "
+ + candidate
+ + " as a "
+ + superclass.getName()
+ + "..."
+ );
+
+ superclass.getDeclaredMethod
+ (
+ "register",
+ Class.class
+ ).invoke(/*object = */ null, c);
- for (final Class c: get_classes_in(current_jar, "tonkadur/plugin"))
- {
- try
- {
- plugins.add
- (
- (TonkadurPlugin) c.newInstance()
- );
+ break;
+ }
+ }
}
catch (final Throwable e)
{
System.err.println
(
- "Could not load plugin "
- + c.getName()
+ "[E] Could not load class "
+ + candidate_name
+ ": "
);
e.printStackTrace();
}
}
-
- return plugins;
}
- public static List<TonkadurPlugin> get_plugins ()
+ public static void load_special_classes ()
{
- final List<TonkadurPlugin> plugins;
-
- plugins = new ArrayList<TonkadurPlugin>();
+ System.out.println("[D] Loading special classes from main jar...");
try
{
- plugins.addAll
+ load_all_relevant_classes_in
(
- extract_plugins_from
+ new JarFile
(
- new JarFile
+ TonkadurPlugin.class.getProtectionDomain
(
- TonkadurPlugin.class.getProtectionDomain
- (
- ).getCodeSource().getLocation().getFile()
- )
+ ).getCodeSource().getLocation().getFile()
)
);
}
@@ -156,23 +156,11 @@ public abstract class TonkadurPlugin
{
e.printStackTrace();
}
+ }
- for (final String jar_name: RuntimeParameters.get_jar_plugins())
- {
- try
- {
- plugins.addAll
- (
- extract_plugins_from(new JarFile(jar_name))
- );
- }
- catch (final Exception e)
- {
- e.printStackTrace();
- }
- }
-
- return plugins;
+ public static List<TonkadurPlugin> get_plugins ()
+ {
+ return TONKADUR_PLUGINS;
}
public void initialize (final String[] args)
diff --git a/src/core/src/tonkadur/fate/v1/Base.java b/src/core/src/tonkadur/fate/v1/Base.java
index 4dfa199..34f844f 100644
--- a/src/core/src/tonkadur/fate/v1/Base.java
+++ b/src/core/src/tonkadur/fate/v1/Base.java
@@ -1,11 +1,19 @@
package tonkadur.fate.v1;
+import tonkadur.TonkadurPlugin;
+
import tonkadur.fate.v1.error.ErrorCategory;
+import tonkadur.fate.v1.lang.computation.GenericComputation;
+import tonkadur.fate.v1.lang.instruction.GenericInstruction;
+
public class Base
{
public static void initialize ()
{
ErrorCategory.initialize();
+
+ TonkadurPlugin.register_as_loadable_superclass(GenericInstruction.class);
+ TonkadurPlugin.register_as_loadable_superclass(GenericComputation.class);
}
}
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 43d733a..e228e37 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/ExtraComputationInstance.java
@@ -27,7 +27,7 @@ public class ExtraComputationInstance extends GenericComputation
final List<Computation> parameters
)
{
- super(origin, computation.get_returned_type(), computation.get_name());
+ super(origin, computation.get_returned_type());
this.computation = computation;
this.parameters = 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 84b5739..dc01b94 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java
@@ -19,12 +19,61 @@ public class GenericComputation extends Computation
/***************************************************************************/
/**** STATIC ***************************************************************/
/***************************************************************************/
- protected static final Map<String, Cons<GenericComputation, Object>>
- REGISTERED;
+ protected static final Map<String, Class> REGISTERED;
static
{
- REGISTERED = new HashMap<String, Cons<GenericComputation, Object>>();
+ REGISTERED = new HashMap<String, Class>();
+ }
+
+ public static void register (final Class c)
+ {
+ try
+ {
+ for
+ (
+ final String alias:
+ (List<String>) c.getMethod("get_aliases").invoke
+ (
+ /* object = */null
+ )
+ )
+ {
+ final Class previous_entry;
+
+ previous_entry = REGISTERED.get(alias);
+
+ if (previous_entry != null)
+ {
+ // TODO Exception handling.
+ new Exception
+ (
+ "[F] Unable to add alias for Generic Fate Computation '"
+ + alias
+ + "' from class '"
+ + c.getName()
+ + "': it has already been claimed by class '"
+ + previous_entry.getName()
+ + "'."
+ );
+
+ System.exit(-1);
+ }
+
+ REGISTERED.put(alias, c);
+ }
+ }
+ catch (final Throwable t)
+ {
+ System.err.println
+ (
+ "Could not register Generic Fate Computation class '"
+ + c.getName()
+ + "': "
+ );
+
+ t.printStackTrace();
+ }
}
public static GenericComputation build
@@ -35,103 +84,44 @@ public class GenericComputation extends Computation
)
throws Throwable
{
- final Cons<GenericComputation, 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 Computation '"
+ + name
+ + "'."
+ );
}
- return target.get_car().build(origin, call_parameters, target.get_cdr());
+ return
+ (GenericComputation) 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 GenericComputation
- (
- final Origin origin,
- final Type type,
- final String name
- )
+ protected GenericComputation (final Origin origin, final Type type)
{
super(origin, type);
-
- this.name = name;
- }
-
- protected GenericComputation build
- (
- final Origin origin,
- final List<Computation> call_parameters,
- final Object constructor_parameter
- )
- throws Throwable
- {
- throw
- new Exception
- (
- "Missing build function for GenericComputation '"
- + 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 GenericComputation 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 ComputationVisitor cv)
@@ -139,24 +129,4 @@ public class GenericComputation extends Computation
{
cv.visit_generic_computation(this);
}
-
- public String get_name ()
- {
- return name;
- }
-
- /**** Misc. ****************************************************************/
- @Override
- public String toString ()
- {
- final StringBuilder sb = new StringBuilder();
-
- sb.append("(GenericInstruction (");
- sb.append(type.get_name());
- sb.append(") ");
- sb.append(get_name());
- sb.append(")");
-
- return sb.toString();
- }
}
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddressOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddressOperator.java
index 36b1e7f..bad9e0e 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddressOperator.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddressOperator.java
@@ -1,6 +1,7 @@
package tonkadur.fate.v1.lang.computation.generic;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import tonkadur.parser.Origin;
@@ -16,18 +17,9 @@ import tonkadur.fate.v1.lang.computation.Constant;
public class AddressOperator extends GenericComputation
{
- protected static final AddressOperator ARCHETYPE;
-
- static
+ public static Collection<String> get_aliases ()
{
- final List<String> aliases;
-
- ARCHETYPE =
- new AddressOperator
- (
- Origin.BASE_LANGUAGE,
- Constant.build_boolean(Origin.BASE_LANGUAGE, true)
- );
+ final Collection<String> aliases;
aliases = new ArrayList<String>();
@@ -52,16 +44,28 @@ public class AddressOperator extends GenericComputation
aliases.add("reference");
aliases.add("ref");
- try
- {
- ARCHETYPE.register(aliases, null);
- }
- catch (final Exception e)
+ return aliases;
+ }
+
+ public static GenericComputation build
+ (
+ final Origin origin,
+ final String _alias,
+ final List<Computation> call_parameters
+ )
+ throws Throwable
+ {
+ if (call_parameters.size() != 1)
{
- e.printStackTrace();
+ // TODO: Error.
+ System.err.println("Wrong number of params at " + origin.toString());
- System.exit(-1);
+ return null;
}
+
+ call_parameters.get(0).expect_non_string();
+
+ return new AddressOperator(origin, call_parameters.get(0));
}
/***************************************************************************/
@@ -70,10 +74,6 @@ public class AddressOperator extends GenericComputation
protected final Computation referred;
/***************************************************************************/
- /**** PROTECTED ************************************************************/
- /***************************************************************************/
-
- /***************************************************************************/
/**** PUBLIC ***************************************************************/
/***************************************************************************/
/**** Constructors *********************************************************/
@@ -82,31 +82,12 @@ public class AddressOperator extends GenericComputation
super
(
origin,
- new PointerType(origin, referred.get_type(), "auto generated"),
- "address_of"
+ new PointerType(origin, referred.get_type(), "auto generated")
);
this.referred = referred;
}
- @Override
- public GenericComputation build
- (
- final Origin origin,
- final List<Computation> call_parameters,
- final Object _registered_parameter
- )
- throws Throwable
- {
- if (call_parameters.size() != 1)
- {
- // TODO: Error.
- }
-
- call_parameters.get(0).expect_non_string();
-
- return new AddressOperator(origin, call_parameters.get(0));
- }
/**** Accessors ************************************************************/
public Computation get_target ()
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AtReference.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AtReference.java
index fd7b617..58711b7 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AtReference.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AtReference.java
@@ -1,8 +1,9 @@
package tonkadur.fate.v1.lang.computation.generic;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.ArrayList;
import tonkadur.parser.Origin;
@@ -25,76 +26,22 @@ import tonkadur.fate.v1.lang.computation.GenericComputation;
public class AtReference extends GenericComputation
{
- protected static final AtReference ARCHETYPE;
-
- static
+ public static Collection<String> get_aliases ()
{
- final List<String> aliases;
-
- ARCHETYPE =
- new AtReference
- (
- Origin.BASE_LANGUAGE,
- Type.INT,
- new Default
- (
- Origin.BASE_LANGUAGE,
- new PointerType
- (
- Origin.BASE_LANGUAGE,
- Type.INT,
- "(ptr int)"
- )
- )
- );
+ final Collection<String> aliases;
aliases = new ArrayList<String>();
aliases.add("at");
- try
- {
- ARCHETYPE.register(aliases, null);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
- }
-
- /***************************************************************************/
- /**** MEMBERS **************************************************************/
- /***************************************************************************/
- protected final Computation parent;
-
- /***************************************************************************/
- /**** PROTECTED ************************************************************/
- /***************************************************************************/
- protected AtReference
- (
- final Origin origin,
- final Type reported_type,
- final Computation parent
- )
- {
- super(origin, reported_type, "at");
-
- this.parent = parent;
+ return aliases;
}
- /**** Constructors *********************************************************/
- /***************************************************************************/
- /**** PUBLIC ***************************************************************/
- /***************************************************************************/
- /**** Constructors *********************************************************/
- @Override
- public GenericComputation build
+ public static GenericComputation build
(
final Origin origin,
- final List<Computation> call_parameters,
- final Object _registered_parameter
+ final String _alias,
+ final List<Computation> call_parameters
)
throws Throwable
{
@@ -103,11 +50,14 @@ public class AtReference extends GenericComputation
if (call_parameters.size() != 1)
{
// TODO: Error.
+ System.err.println("Wrong number of params at " + origin.toString());
+
+ return null;
}
call_parameters.get(0).expect_non_string();
- current_type = parent.get_type();
+ current_type = call_parameters.get(0).get_type();
if (!(current_type instanceof PointerType))
{
@@ -128,8 +78,34 @@ public class AtReference extends GenericComputation
current_type = ((PointerType) current_type).get_referenced_type();
}
- return new AtReference(origin, current_type, parent);
+ return new AtReference(origin, current_type, call_parameters.get(0));
+ }
+
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final Computation parent;
+
+ /***************************************************************************/
+ /**** PROTECTED ************************************************************/
+ /***************************************************************************/
+ protected AtReference
+ (
+ final Origin origin,
+ final Type reported_type,
+ final Computation parent
+ )
+ {
+ super(origin, reported_type);
+
+ this.parent = parent;
}
+ /**** Constructors *********************************************************/
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+ /**** Constructors *********************************************************/
/**** Accessors ************************************************************/
public Computation get_parent ()
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/LambdaEvaluation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/LambdaEvaluation.java
index ce1157c..f1af59f 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/LambdaEvaluation.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/LambdaEvaluation.java
@@ -1,7 +1,8 @@
package tonkadur.fate.v1.lang.computation.generic;
-import java.util.List;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
import tonkadur.parser.Origin;
import tonkadur.parser.ParsingError;
@@ -19,72 +20,24 @@ import tonkadur.fate.v1.lang.computation.GenericComputation;
public class LambdaEvaluation extends GenericComputation
{
- protected static final LambdaEvaluation ARCHETYPE;
-
- static
+ public static Collection<String> get_aliases ()
{
- final List<String> aliases;
-
- ARCHETYPE =
- new LambdaEvaluation
- (
- Origin.BASE_LANGUAGE,
- null,
- null,
- Type.BOOL
- );
+ final Collection<String> aliases;
aliases = new ArrayList<String>();
aliases.add("eval");
aliases.add("evaluate");
- try
- {
- ARCHETYPE.register(aliases, null);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
+ return aliases;
}
- /***************************************************************************/
- /**** MEMBERS **************************************************************/
- /***************************************************************************/
- protected final Computation lambda_function;
- protected final List<Computation> parameters;
-
- /***************************************************************************/
- /**** PROTECTED ************************************************************/
- /***************************************************************************/
/**** Constructors *********************************************************/
- protected LambdaEvaluation
+ public static GenericComputation build
(
final Origin origin,
- final Computation lambda_function,
- final List<Computation> parameters,
- final Type act_as
- )
- {
- super(origin, act_as, "eval");
-
- this.lambda_function = lambda_function;
- this.parameters = parameters;
- }
-
- /***************************************************************************/
- /**** PUBLIC ***************************************************************/
- /***************************************************************************/
- /**** Constructors *********************************************************/
- @Override
- public GenericComputation build
- (
- final Origin origin,
- final List<Computation> call_parameters,
- final Object _registered_parameter
+ final String _alias,
+ final List<Computation> call_parameters
)
throws Throwable
{
@@ -94,6 +47,9 @@ public class LambdaEvaluation extends GenericComputation
if (call_parameters.size() < 1)
{
// TODO: Error.
+ System.err.println("Wrong number of params at " + origin.toString());
+
+ return null;
}
lambda_function = call_parameters.get(0);
@@ -125,11 +81,39 @@ public class LambdaEvaluation extends GenericComputation
(
origin,
lambda_function,
- parameters,
+ call_parameters,
(((LambdaType) lambda_function.get_type()).get_return_type())
);
}
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final Computation lambda_function;
+ protected final List<Computation> parameters;
+
+ /***************************************************************************/
+ /**** PROTECTED ************************************************************/
+ /***************************************************************************/
+ /**** Constructors *********************************************************/
+ protected LambdaEvaluation
+ (
+ final Origin origin,
+ final Computation lambda_function,
+ final List<Computation> parameters,
+ final Type act_as
+ )
+ {
+ super(origin, act_as);
+
+ this.lambda_function = lambda_function;
+ this.parameters = parameters;
+ }
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+
/**** Accessors ************************************************************/
public Computation get_lambda_function ()
{
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 1183c8c..62dcaea 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
@@ -1,8 +1,10 @@
package tonkadur.fate.v1.lang.computation.generic;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
import tonkadur.error.ErrorManager;
@@ -26,459 +28,154 @@ import tonkadur.fate.v1.lang.computation.Constant;
public class Operation extends GenericComputation
{
- protected static final Operation ARCHETYPE;
+ protected static final Map<String, Operator> ALIASED_OPERATOR;
static
{
- final List<Computation> operands;
- List<String> aliases;
-
- operands = new ArrayList<Computation>();
-
- operands.add
- (
- Constant.build_boolean
- (
- Origin.BASE_LANGUAGE,
- false
- )
- );
-
- operands.add(operands.get(0));
-
- ARCHETYPE =
- new Operation
- (
- Origin.BASE_LANGUAGE,
- Type.BOOL,
- Operator.AND,
- operands
- );
-
- /**** PLUS **************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("+");
- aliases.add("plus");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.PLUS);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** MINUS *************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("-");
- aliases.add("minus");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.MINUS);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** TIMES *************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("*");
- aliases.add("times");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.TIMES);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** DIVIDE ************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("/");
- aliases.add("div");
- aliases.add("divide");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.DIVIDE);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** POWER *************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("**");
- aliases.add("^");
- aliases.add("pow");
- aliases.add("power");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.POWER);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** MODULO ************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("%");
- aliases.add("mod");
- aliases.add("modulo");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.MODULO);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** MIN ***************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("min");
- aliases.add("minimum");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.MIN);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** MAX ***************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("max");
- aliases.add("maximum");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.MAX);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** CLAMP *************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("clamp");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.CLAMP);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** ABS ***************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("abs");
- aliases.add("absolute");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.ABS);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** RANDOM ************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("rnd");
- aliases.add("rand");
- aliases.add("random");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.RANDOM);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** AND ***************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("and");
- aliases.add("/\\");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.AND);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** OR ****************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("or");
- aliases.add("\\/");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.OR);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** NOT ***************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("not");
- aliases.add("~");
- aliases.add("!");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.NOT);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** IMPLIES ***********************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("implies");
- aliases.add("=>");
- aliases.add("->");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.IMPLIES);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** ONE IN ************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("exactlyOneIn");
- aliases.add("exactlyonein");
- aliases.add("exactly_one_in");
- aliases.add("OneIn");
- aliases.add("onein");
- aliases.add("one_in");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.ONE_IN);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** EQUALS ************************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("equals");
- aliases.add("eq");
- aliases.add("=");
- aliases.add("==");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.EQUALS);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** LOWER THAN ********************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("lowerThan");
- aliases.add("lowerthan");
- aliases.add("lower_than");
- aliases.add("lt");
- aliases.add("<");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.LOWER_THAN);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** LOWER EQUAL THAN **************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("lowerEqualThan");
- aliases.add("lowerequalthan");
- aliases.add("lower_equal_than");
- aliases.add("le");
- aliases.add("<=");
- aliases.add("=<");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.LOWER_EQUAL_THAN);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** GREATER EQUAL THAN **************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("greaterEqualThan");
- aliases.add("greaterequalthan");
- aliases.add("greater_equal_than");
- aliases.add("ge");
- aliases.add(">=");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.GREATER_EQUAL_THAN);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
-
- /**** GREATER THAN ******************************************************/
- aliases = new ArrayList<String>();
-
- aliases.add("greaterThan");
- aliases.add("greaterthan");
- aliases.add("greater_than");
- aliases.add("gt");
- aliases.add(">");
-
- try
- {
- ARCHETYPE.register(aliases, Operator.GREATER_THAN);
- }
- catch (final Exception e)
- {
- e.printStackTrace();
-
- System.exit(-1);
- }
+ Operator operator;
+
+ ALIASED_OPERATOR = new HashMap<String, Operator>();
+
+ operator = Operator.PLUS;
+ ALIASED_OPERATOR.put("+", operator);
+ ALIASED_OPERATOR.put("plus", operator);
+
+ operator = Operator.MINUS;
+ ALIASED_OPERATOR.put("-", operator);
+ ALIASED_OPERATOR.put("minus", operator);
+
+ operator = Operator.TIMES;
+ ALIASED_OPERATOR.put("*", operator);
+ ALIASED_OPERATOR.put("times", operator);
+
+ operator = Operator.DIVIDE;
+ ALIASED_OPERATOR.put("/", operator);
+ ALIASED_OPERATOR.put("div", operator);
+ ALIASED_OPERATOR.put("divide", operator);
+
+ operator = Operator.POWER;
+ ALIASED_OPERATOR.put("**", operator);
+ ALIASED_OPERATOR.put("^", operator);
+ ALIASED_OPERATOR.put("pow", operator);
+ ALIASED_OPERATOR.put("power", operator);
+
+ operator = Operator.MODULO;
+ ALIASED_OPERATOR.put("%", operator);
+ ALIASED_OPERATOR.put("mod", operator);
+ ALIASED_OPERATOR.put("modulo", operator);
+
+ operator = Operator.MIN;
+ ALIASED_OPERATOR.put("min", operator);
+ ALIASED_OPERATOR.put("minimum", operator);
+
+ operator = Operator.MAX;
+ ALIASED_OPERATOR.put("max", operator);
+ ALIASED_OPERATOR.put("maximum", operator);
+
+ operator = Operator.CLAMP;
+ ALIASED_OPERATOR.put("clamp", operator);
+
+ operator = Operator.ABS;
+ ALIASED_OPERATOR.put("abs", operator);
+ ALIASED_OPERATOR.put("absolute", operator);
+
+ operator = Operator.RANDOM;
+ ALIASED_OPERATOR.put("rnd", operator);
+ ALIASED_OPERATOR.put("rand", operator);
+ ALIASED_OPERATOR.put("random", operator);
+
+ operator = Operator.AND;
+ ALIASED_OPERATOR.put("and", operator);
+ ALIASED_OPERATOR.put("/\\", operator);
+
+ operator = Operator.OR;
+ ALIASED_OPERATOR.put("or", operator);
+ ALIASED_OPERATOR.put("\\/", operator);
+
+ operator = Operator.NOT;
+ ALIASED_OPERATOR.put("not", operator);
+ ALIASED_OPERATOR.put("~", operator);
+ ALIASED_OPERATOR.put("!", operator);
+
+ operator = Operator.IMPLIES;
+ ALIASED_OPERATOR.put("implies", operator);
+ ALIASED_OPERATOR.put("=>", operator);
+ ALIASED_OPERATOR.put("->", operator);
+
+ operator = Operator.ONE_IN;
+ ALIASED_OPERATOR.put("exactlyOneIn", operator);
+ ALIASED_OPERATOR.put("exactlyonein", operator);
+ ALIASED_OPERATOR.put("exactly_one_in", operator);
+ ALIASED_OPERATOR.put("OneIn", operator);
+ ALIASED_OPERATOR.put("onein", operator);
+ ALIASED_OPERATOR.put("one_in", operator);
+
+ operator = Operator.EQUALS;
+ ALIASED_OPERATOR.put("equals", operator);
+ ALIASED_OPERATOR.put("eq", operator);
+ ALIASED_OPERATOR.put("=", operator);
+ ALIASED_OPERATOR.put("==", operator);
+
+ operator = Operator.LOWER_THAN;
+ ALIASED_OPERATOR.put("lowerThan", operator);
+ ALIASED_OPERATOR.put("lowerthan", operator);
+ ALIASED_OPERATOR.put("lower_than", operator);
+ ALIASED_OPERATOR.put("lt", operator);
+ ALIASED_OPERATOR.put("<", operator);
+
+ operator = Operator.LOWER_EQUAL_THAN;
+ ALIASED_OPERATOR.put("lowerEqualThan", operator);
+ ALIASED_OPERATOR.put("lowerequalthan", operator);
+ ALIASED_OPERATOR.put("lower_equal_than", operator);
+ ALIASED_OPERATOR.put("le", operator);
+ ALIASED_OPERATOR.put("<=", operator);
+ ALIASED_OPERATOR.put("=<", operator);
+
+ operator = Operator.GREATER_THAN;
+ ALIASED_OPERATOR.put("greaterEqualThan", operator);
+ ALIASED_OPERATOR.put("greaterequalthan", operator);
+ ALIASED_OPERATOR.put("greater_equal_than", operator);
+ ALIASED_OPERATOR.put("ge", operator);
+ ALIASED_OPERATOR.put(">=", operator);
+
+ operator = Operator.GREATER_THAN;
+ ALIASED_OPERATOR.put("greaterThan", operator);
+ ALIASED_OPERATOR.put("greaterthan", operator);
+ ALIASED_OPERATOR.put("greater_than", operator);
+ ALIASED_OPERATOR.put("gt", operator);
+ ALIASED_OPERATOR.put(">", operator);
}
- /***************************************************************************/
- /**** MEMBERS **************************************************************/
- /***************************************************************************/
- protected final Operator operator;
- protected final List<Computation> operands;
+ public static Collection<String> get_aliases ()
+ {
+ return ALIASED_OPERATOR.keySet();
+ }
- /***************************************************************************/
- /**** PROTECTED ************************************************************/
- /***************************************************************************/
- protected Operation
+ public static GenericComputation build
(
final Origin origin,
- final Type result_type,
- final Operator operator,
+ final String alias,
final List<Computation> operands
)
+ throws Throwable
{
- super(origin, result_type, "+");
-
- this.operator = operator;
- this.operands = operands;
+ return build(origin, ALIASED_OPERATOR.get(alias), operands);
}
- @Override
- public GenericComputation build
+ public static GenericComputation build
(
final Origin origin,
- final List<Computation> operands,
- final Object registered_parameter
+ final Operator operator,
+ final List<Computation> operands
)
throws Throwable
{
- final Operator operator;
final Collection<Type> allowed_base_types;
final int operator_max_arity;
final int operator_min_arity;
final int operands_size;
Type computed_type, previous_computed_type;
- operator = (Operator) registered_parameter;
-
allowed_base_types = operator.get_allowed_base_types();
operator_max_arity = operator.get_maximum_arity();
operator_min_arity = operator.get_minimum_arity();
@@ -596,6 +293,29 @@ public class Operation extends GenericComputation
return new Operation(origin, computed_type, operator, operands);
}
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final Operator operator;
+ protected final List<Computation> operands;
+
+ /***************************************************************************/
+ /**** PROTECTED ************************************************************/
+ /***************************************************************************/
+ protected Operation
+ (
+ final Origin origin,
+ final Type result_type,
+ final Operator operator,
+ final List<Computation> operands
+ )
+ {
+ super(origin, result_type);
+
+ this.operator = operator;
+ this.operands = operands;
+ }
+
/**** Accessors ************************************************************/
public Operator get_operator ()
{
diff --git a/src/core/src/tonkadur/plugin/base/BaseLanguage.java b/src/core/src/tonkadur/plugin/base/BaseLanguage.java
deleted file mode 100644
index 9ef4278..0000000
--- a/src/core/src/tonkadur/plugin/base/BaseLanguage.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package tonkadur.plugin.base;
-
-import java.util.jar.JarFile;
-
-import tonkadur.TonkadurPlugin;
-
-public class BaseLanguage extends TonkadurPlugin
-{
- @Override
- public void initialize (final String[] args)
- throws Throwable
- {
- final JarFile base_jar;
-
- base_jar =
- new JarFile
- (
- BaseLanguage.class.getProtectionDomain
- (
- ).getCodeSource().getLocation().getFile()
- );
-
- TonkadurPlugin.initialize_classes_in
- (
- base_jar,
- "tonkadur/fate/v1/lang/computation/generic"
- );
-
- TonkadurPlugin.initialize_classes_in
- (
- base_jar,
- "tonkadur/fate/v1/lang/instruction/generic"
- );
-
- TonkadurPlugin.initialize_classes_in
- (
- base_jar,
- "tonkadur/wyrd/v1/compiler/fate/v1/computation/generic"
- );
-
- TonkadurPlugin.initialize_classes_in
- (
- base_jar,
- "tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic"
- );
- }
-}