summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/Makefile2
-rw-r--r--src/core/src/tonkadur/Main.java48
-rw-r--r--src/core/src/tonkadur/TonkadurPlugin.java129
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/Operator.java9
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/ReverseList.java0
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateParser.g41
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java13
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java144
-rw-r--r--src/json-export/Makefile97
-rw-r--r--src/json-export/src/Manifest.txt2
-rw-r--r--src/json-export/src/tonkadur/plugin/JSONExport.java12
11 files changed, 448 insertions, 9 deletions
diff --git a/src/core/Makefile b/src/core/Makefile
index ffca63b..9f7314c 100644
--- a/src/core/Makefile
+++ b/src/core/Makefile
@@ -63,6 +63,7 @@ $(STANDALONE): $(TMP_DIR) $(TARGET) $(ANTLR_JAR)
unzip -d $(TMP_DIR) -uo $(TARGET)
unzip -d $(TMP_DIR) -uo $(ANTLR_JAR)
$(JAR) -cvfm $@ $(MANIFEST) -C $(TMP_DIR) .
+ cp $@ $(LIB_DIR)/$@
ifeq ($(INSTALL_DIR),${CURDIR})
$(TARGET): $(ANTLR_JAR) $(JAVA_SOURCES) $(CLASSES) $(MANIFEST)
@@ -79,6 +80,7 @@ clean:
rm -rf $(filter-out $(ANTLR_SOURCES),$(wildcard $(ANTLR_SOURCES:.g4=*)))
rm -rf $(BIN_DIR)/*
rm -rf $(TARGET) $(STANDALONE)
+ rm -rf $(LIB_DIR)/$(STANDALONE)
# Pattern rules can be used to generate multiple target in a single action.
%Lexer.java %Parser.java: $(ANTLR_SOURCES)
diff --git a/src/core/src/tonkadur/Main.java b/src/core/src/tonkadur/Main.java
index f1eedb0..cf8a8ae 100644
--- a/src/core/src/tonkadur/Main.java
+++ b/src/core/src/tonkadur/Main.java
@@ -1,5 +1,7 @@
package tonkadur;
+import java.util.List;
+
import java.io.IOException;
import tonkadur.parser.Context;
@@ -12,14 +14,28 @@ public class Main
private Main () {};
public static void main (final String[] args)
+ throws Throwable
{
+ final List<TonkadurPlugin> plugins;
final tonkadur.fate.v1.lang.World fate_world;
- tonkadur.wyrd.v1.lang.World wyrd_world;
+ final tonkadur.wyrd.v1.lang.World wyrd_world;
final Context context;
+ plugins = TonkadurPlugin.get_plugins();
+
+ for (final TonkadurPlugin tp: plugins)
+ {
+ tp.initialize(args);
+ }
+
fate_world = new tonkadur.fate.v1.lang.World();
context = Context.build(args[0]);
+ for (final TonkadurPlugin tp: plugins)
+ {
+ tp.pre_fate_parsing(fate_world, context);
+ }
+
try
{
Utils.add_file_content
@@ -39,11 +55,25 @@ public class Main
e.printStackTrace();
}
- wyrd_world = null;
+ for (final TonkadurPlugin tp: plugins)
+ {
+ tp.post_fate_parsing(fate_world);
+ }
+
+ wyrd_world = new tonkadur.wyrd.v1.lang.World();
+
+ for (final TonkadurPlugin tp: plugins)
+ {
+ tp.pre_wyrd_compile(wyrd_world);
+ }
+
try
{
- wyrd_world =
- tonkadur.wyrd.v1.compiler.fate.v1.Compiler.compile(fate_world);
+ tonkadur.wyrd.v1.compiler.fate.v1.Compiler.compile
+ (
+ fate_world,
+ wyrd_world
+ );
System.out.println("Compilation completed.");
}
@@ -53,6 +83,11 @@ public class Main
e.printStackTrace();
}
+ for (final TonkadurPlugin tp: plugins)
+ {
+ tp.post_wyrd_compile(wyrd_world);
+ }
+
for
(
final tonkadur.wyrd.v1.lang.meta.Instruction line:
@@ -61,5 +96,10 @@ public class Main
{
System.out.println(line.toString());
}
+
+ for (final TonkadurPlugin tp: plugins)
+ {
+ tp.finalize();
+ }
}
}
diff --git a/src/core/src/tonkadur/TonkadurPlugin.java b/src/core/src/tonkadur/TonkadurPlugin.java
new file mode 100644
index 0000000..2df21d0
--- /dev/null
+++ b/src/core/src/tonkadur/TonkadurPlugin.java
@@ -0,0 +1,129 @@
+package tonkadur;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import tonkadur.parser.Context;
+
+public abstract class TonkadurPlugin
+{
+ public static List<TonkadurPlugin> get_plugins ()
+ {
+ final List<TonkadurPlugin> plugins;
+ final Enumeration<JarEntry> entries;
+ JarFile current_jar;
+
+ plugins = new ArrayList<TonkadurPlugin>();
+
+ current_jar = null;
+
+ try
+ {
+ current_jar =
+ new JarFile
+ (
+ TonkadurPlugin.class.getProtectionDomain
+ (
+ ).getCodeSource().getLocation().getFile()
+ );
+ }
+ catch (final Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ if (current_jar == null)
+ {
+ return null;
+ }
+ entries = current_jar.entries();
+
+ while (entries.hasMoreElements())
+ {
+ final JarEntry candidate;
+ String candidate_name;
+
+ candidate = entries.nextElement();
+ candidate_name = candidate.getName();
+
+ if
+ (
+ !candidate_name.endsWith(".class")
+ || !candidate_name.startsWith("tonkadur/plugin/")
+ )
+ {
+ continue;
+ }
+
+ candidate_name =
+ candidate_name.replace
+ (
+ '/',
+ '.'
+ ).substring(0, (candidate_name.length() - 6));
+
+ try
+ {
+ plugins.add
+ (
+ (TonkadurPlugin) Class.forName(candidate_name).newInstance()
+ );
+ }
+ catch (final Throwable e)
+ {
+ System.err.println
+ (
+ "Could not load plugin "
+ + candidate_name
+ + ": "
+ );
+ e.printStackTrace();
+ }
+ }
+
+ return plugins;
+ }
+
+ public void initialize (final String[] args)
+ throws Throwable
+ {
+
+ }
+
+ public void pre_fate_parsing
+ (
+ final tonkadur.fate.v1.lang.World fate_world,
+ final Context context
+ )
+ throws Throwable
+ {
+
+ }
+
+ public void post_fate_parsing (final tonkadur.fate.v1.lang.World fate_world)
+ throws Throwable
+ {
+
+ }
+
+ public void pre_wyrd_compile (final tonkadur.wyrd.v1.lang.World wyrd_world)
+ throws Throwable
+ {
+
+ }
+
+ public void post_wyrd_compile (final tonkadur.wyrd.v1.lang.World wyrd_world)
+ throws Throwable
+ {
+
+ }
+
+ public void finalize ()
+ throws Throwable
+ {
+
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Operator.java b/src/core/src/tonkadur/fate/v1/lang/computation/Operator.java
index 12b3283..fff66a1 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/Operator.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/Operator.java
@@ -19,6 +19,10 @@ public class Operator
public static final Operator DIVIDE;
public static final Operator MODULO;
public static final Operator POWER;
+ public static final Operator MIN;
+ public static final Operator MAX;
+ public static final Operator CLAMP;
+ public static final Operator ABS;
public static final Operator RANDOM;
public static final Operator AND;
@@ -43,6 +47,11 @@ public class Operator
DIVIDE = new Operator("/", 2, 2, Type.NUMBER_TYPES, null);
POWER = new Operator("^", 2, 2, Type.NUMBER_TYPES, null);
MODULO = new Operator("%", 2, 2, Collections.singleton(Type.INT), null);
+ MIN = new Operator("min", 2, 0, Type.NUMBER_TYPES, null);
+ MAX = new Operator("max", 2, 0, Type.NUMBER_TYPES, null);
+ CLAMP = new Operator("clamp", 3, 3, Type.NUMBER_TYPES, null);
+ ABS = new Operator("abs", 1, 1, Type.NUMBER_TYPES, null);
+
RANDOM =
new Operator("rand", 2, 2, Collections.singleton(Type.INT), null);
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/ReverseList.java b/src/core/src/tonkadur/fate/v1/lang/instruction/ReverseList.java
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/lang/instruction/ReverseList.java
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
index 52722df..c8e42a6 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
@@ -599,7 +599,6 @@ returns [Instruction result]
| END_KW
{
- /* TODO */
$result =
new End
(
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java
index d516cb3..4a315e1 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java
@@ -13,12 +13,16 @@ public class Compiler
protected final World wyrd_world;
- public static World compile (final tonkadur.fate.v1.lang.World fate_world)
+ public static World compile
+ (
+ final tonkadur.fate.v1.lang.World fate_world,
+ final World wyrd_world
+ )
throws Throwable
{
final Compiler compiler;
- compiler = new Compiler();
+ compiler = new Compiler(wyrd_world);
compiler.compile_extensions(fate_world);
compiler.compile_types(fate_world);
@@ -31,12 +35,13 @@ public class Compiler
return compiler.wyrd_world;
}
- protected Compiler ()
+ protected Compiler (final World wyrd_world)
{
+ this.wyrd_world = wyrd_world;
+
macro_manager = new MacroManager();
anonymous_variables = new AnonymousVariableManager();
assembler = new InstructionManager();
- wyrd_world = new World();
}
protected void compile_extensions
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java
index 121eda7..f3e5ae1 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java
@@ -782,6 +782,150 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
fate_op_name.equals
(
+ tonkadur.fate.v1.lang.computation.Operator.MIN.get_name()
+ )
+ )
+ {
+ final Ref candidate;
+ final Computation value_of_candidate;
+
+ candidate = reserve(operands.get(0).get_type());
+ value_of_candidate = new ValueOf(candidate);
+
+ init_instructions.add(new SetValue(candidate, operands.get(0)));
+
+ for (final Computation operand: operands)
+ {
+ init_instructions.add
+ (
+ new SetValue
+ (
+ candidate,
+ new IfElseComputation
+ (
+ Operation.less_than(value_of_candidate, operand),
+ value_of_candidate,
+ operand
+ )
+ )
+ );
+ }
+
+ result_as_computation = value_of_candidate;
+ }
+ else if
+ (
+ fate_op_name.equals
+ (
+ tonkadur.fate.v1.lang.computation.Operator.MAX.get_name()
+ )
+ )
+ {
+ final Ref candidate;
+ final Computation value_of_candidate;
+
+ candidate = reserve(operands.get(0).get_type());
+ value_of_candidate = new ValueOf(candidate);
+
+ init_instructions.add(new SetValue(candidate, operands.get(0)));
+
+ for (final Computation operand: operands)
+ {
+ init_instructions.add
+ (
+ new SetValue
+ (
+ candidate,
+ new IfElseComputation
+ (
+ Operation.greater_than(value_of_candidate, operand),
+ value_of_candidate,
+ operand
+ )
+ )
+ );
+ }
+
+ result_as_computation = value_of_candidate;
+ }
+ else if
+ (
+ fate_op_name.equals
+ (
+ tonkadur.fate.v1.lang.computation.Operator.ABS.get_name()
+ )
+ )
+ {
+ final Computation zero, minus_one;
+
+ if (operands.get(2).get_type().equals(Type.INT))
+ {
+ zero = Constant.ZERO;
+ minus_one = new Constant(Type.INT, "-1");
+ }
+ else
+ {
+ zero = new Constant(Type.FLOAT, "0.0");
+ minus_one = new Constant(Type.FLOAT, "-1.0");
+ }
+
+ result_as_computation =
+ new IfElseComputation
+ (
+ Operation.greater_than(zero, operands.get(0)),
+ Operation.times(minus_one, operands.get(0)),
+ operands.get(0)
+ );
+ }
+ else if
+ (
+ fate_op_name.equals
+ (
+ tonkadur.fate.v1.lang.computation.Operator.CLAMP.get_name()
+ )
+ )
+ {
+ final Type t;
+ final Ref candidate;
+ final Computation value_of_candidate;
+
+ t = operands.get(2).get_type();
+ candidate = reserve(t);
+ value_of_candidate = new ValueOf(candidate);
+
+ init_instructions.add
+ (
+ new SetValue
+ (
+ candidate,
+ new IfElseComputation
+ (
+ Operation.greater_than(operands.get(2), operands.get(1)),
+ operands.get(1),
+ operands.get(2)
+ )
+ )
+ );
+ init_instructions.add
+ (
+ new SetValue
+ (
+ candidate,
+ new IfElseComputation
+ (
+ Operation.less_than(value_of_candidate, operands.get(0)),
+ operands.get(0),
+ value_of_candidate
+ )
+ )
+ );
+
+ result_as_computation = value_of_candidate;
+ }
+ else if
+ (
+ fate_op_name.equals
+ (
tonkadur.fate.v1.lang.computation.Operator.MODULO.get_name()
)
)
diff --git a/src/json-export/Makefile b/src/json-export/Makefile
new file mode 100644
index 0000000..afe05e5
--- /dev/null
+++ b/src/json-export/Makefile
@@ -0,0 +1,97 @@
+## Parameters ##################################################################
+SRC_DIR ?= ${CURDIR}/src
+BIN_DIR ?= ${CURDIR}/bin
+LIB_DIR ?= ${CURDIR}/../../lib
+TMP_DIR ?= /tmp/tonkadir-json/
+
+TARGET ?= tonkadur_json_export_lib.jar
+STANDALONE ?= tonkadur_json_export_standalone.jar
+
+#### Where to get the missing Jar files.
+JAR_SOURCE ?= "https://noot-noot.org/jar_dist/"
+
+#### Binaries
+###### JAR binary
+JAR ?= jar
+
+###### JRE binary
+JAVA ?= java
+
+###### JDK binary
+JAVAC ?= javac
+
+###### JSON-SIMPLE
+JSON_SIMPLE_JAR ?= $(LIB_DIR)/json-simple-1.1.1.jar
+TONKADUR_CORE_JAR ?= $(LIB_DIR)/tonkadur_core_standalone.jar
+
+##### Downloader
+DOWNLOADER ?= wget
+
+## Parameters Sanity Check #####################################################
+ifeq ($(strip $(JAVA)),)
+$(error No Java executable defined as parameter.)
+endif
+
+ifeq ($(strip $(JAVAC)),)
+$(error No Java compiler defined as parameter.)
+endif
+
+ifeq ($(strip $(JSON_SIMPLE_JAR)),)
+$(error No JSON_SIMPLE_JAR defined as parameter.)
+endif
+
+ifeq ($(strip $(TONKADUR_CORE_JAR)),)
+$(error No TONKADUR_CORE_JAR defined as parameter.)
+endif
+
+## Java Config #################################################################
+ifeq ($(strip $(CLASSPATH)),)
+CLASSPATH = "$(SRC_DIR):$(BIN_DIR):$(JSON_SIMPLE_JAR):$(TONKADUR_CORE_JAR)"
+else
+CLASSPATH = "$(CLASSPATH):$(SRC_DIR):$(BIN_DIR):$(JSON_SIMPLE_JAR):$(TONKADUR_CORE_JAR)"
+endif
+
+MANIFEST ?= $(SRC_DIR)/Manifest.txt
+
+## Makefile Magic ##############################################################
+JAVA_NAMED_FILES = $(shell find $(SRC_DIR) -iname \*.java)
+JAVA_SOURCES = $(JAVA_NAMED_FILES)
+CLASSES = $(patsubst $(SRC_DIR)/%.java,$(BIN_DIR)/%.class,$(JAVA_SOURCES))
+
+## Makefile Rules ##############################################################
+$(STANDALONE): $(TMP_DIR) $(TARGET) $(JSON_SIMPLE_JAR) $(TONKADUR_CORE_JAR)
+ unzip -d $(TMP_DIR) -uo $(TARGET)
+ unzip -d $(TMP_DIR) -uo $(TONKADUR_CORE_JAR)
+ unzip -d $(TMP_DIR) -uo $(JSON_SIMPLE_JAR)
+ $(JAR) -cvfm $@ $(MANIFEST) -C $(TMP_DIR) .
+
+$(TARGET): $(JAVA_SOURCES) $(CLASSES) $(MANIFEST)
+ rm -f $(TARGET) $(INSTALL_DIR)/$@
+ $(JAR) cf $@ -C $(BIN_DIR) .
+
+clean:
+ rm -rf $(BIN_DIR)/*
+ rm -rf $(STANDALONE) $(TARGET)
+ rm -rf $(LIB_DIR)/$(STANDALONE)
+
+# Pattern rules can be used to generate multiple target in a single action.
+$(CLASSES): $(BIN_DIR)/%.class: $(SRC_DIR)/%.java $(BIN_DIR)
+ $(JAVAC) -cp $(CLASSPATH) -d $(BIN_DIR) $<
+
+%.jar:
+ $(MAKE) $(LIB_DIR)
+ echo "Attempting to download missing jar '$@'..."
+ cd $(LIB_DIR); $(DOWNLOADER) "$(JAR_SOURCE)/$(notdir $@)"
+
+$(TMP_DIR):
+ mkdir -p $@
+
+$(LIB_DIR):
+ mkdir -p $@
+
+$(BIN_DIR):
+ mkdir -p $@
+
+##### For my private use...
+publish: $(STANDALONE)
+ scp $^ dreamhost:~/noot-noot/jar_dist/
diff --git a/src/json-export/src/Manifest.txt b/src/json-export/src/Manifest.txt
new file mode 100644
index 0000000..ef7c812
--- /dev/null
+++ b/src/json-export/src/Manifest.txt
@@ -0,0 +1,2 @@
+Main-Class: tonkadur.Main
+
diff --git a/src/json-export/src/tonkadur/plugin/JSONExport.java b/src/json-export/src/tonkadur/plugin/JSONExport.java
new file mode 100644
index 0000000..33bf141
--- /dev/null
+++ b/src/json-export/src/tonkadur/plugin/JSONExport.java
@@ -0,0 +1,12 @@
+package tonkadur.plugin;
+
+import tonkadur.TonkadurPlugin;
+
+public class JSONExport extends TonkadurPlugin
+{
+ @Override
+ public void initialize (final String[] args)
+ {
+ System.out.println("JSONExport plugin initialized.");
+ }
+}