From 2c9508ab8a94d3826b8e2fe8bc92f91ef02334d1 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sun, 26 Jul 2020 00:59:52 +0200 Subject: Working on the Wyrd compiler... --- src/core/src/tonkadur/fate/v1/lang/Macro.java | 20 +- src/core/src/tonkadur/fate/v1/lang/Sequence.java | 8 +- src/core/src/tonkadur/fate/v1/lang/World.java | 18 +- .../fate/v1/lang/computation/AtReference.java | 109 ++++ .../tonkadur/fate/v1/lang/computation/Cast.java | 200 +++++++ .../fate/v1/lang/computation/CondValue.java | 156 ++++++ .../fate/v1/lang/computation/Constant.java | 110 ++++ .../fate/v1/lang/computation/CountOperator.java | 159 ++++++ .../fate/v1/lang/computation/FieldReference.java | 149 ++++++ .../fate/v1/lang/computation/IfElseValue.java | 164 ++++++ .../fate/v1/lang/computation/IsMemberOperator.java | 159 ++++++ .../fate/v1/lang/computation/MacroValueCall.java | 193 +++++++ .../tonkadur/fate/v1/lang/computation/Newline.java | 33 ++ .../fate/v1/lang/computation/Operation.java | 178 +++++++ .../fate/v1/lang/computation/Operator.java | 137 +++++ .../fate/v1/lang/computation/Paragraph.java | 67 +++ .../v1/lang/computation/ParameterReference.java | 53 ++ .../fate/v1/lang/computation/RefOperator.java | 54 ++ .../fate/v1/lang/computation/TextWithEffect.java | 185 +++++++ .../fate/v1/lang/computation/ValueToRichText.java | 88 +++ .../v1/lang/computation/VariableReference.java | 76 +++ .../fate/v1/lang/instruction/AddElement.java | 28 +- .../tonkadur/fate/v1/lang/instruction/Assert.java | 14 +- .../tonkadur/fate/v1/lang/instruction/Clear.java | 14 +- .../fate/v1/lang/instruction/CondInstruction.java | 18 +- .../tonkadur/fate/v1/lang/instruction/Display.java | 4 +- .../fate/v1/lang/instruction/EventCall.java | 20 +- .../v1/lang/instruction/IfElseInstruction.java | 30 +- .../fate/v1/lang/instruction/IfInstruction.java | 22 +- .../fate/v1/lang/instruction/InstructionList.java | 12 +- .../fate/v1/lang/instruction/MacroCall.java | 20 +- .../fate/v1/lang/instruction/PlayerChoice.java | 12 +- .../fate/v1/lang/instruction/PlayerChoiceList.java | 12 +- .../v1/lang/instruction/RemoveAllOfElement.java | 18 +- .../fate/v1/lang/instruction/RemoveElement.java | 18 +- .../fate/v1/lang/instruction/SequenceCall.java | 4 +- .../fate/v1/lang/instruction/SetValue.java | 18 +- .../tonkadur/fate/v1/lang/meta/Computation.java | 47 ++ .../fate/v1/lang/meta/ExtensionComputation.java | 39 ++ .../fate/v1/lang/meta/ExtensionInstruction.java | 6 +- .../fate/v1/lang/meta/ExtensionValueNode.java | 39 -- .../tonkadur/fate/v1/lang/meta/Instruction.java | 60 +++ .../fate/v1/lang/meta/InstructionNode.java | 60 --- .../tonkadur/fate/v1/lang/meta/NodeVisitor.java | 2 +- .../src/tonkadur/fate/v1/lang/meta/Reference.java | 2 +- .../tonkadur/fate/v1/lang/meta/RichTextNode.java | 2 +- .../src/tonkadur/fate/v1/lang/meta/ValueNode.java | 47 -- .../fate/v1/lang/valued_node/AtReference.java | 109 ---- .../tonkadur/fate/v1/lang/valued_node/Cast.java | 200 ------- .../fate/v1/lang/valued_node/CondValue.java | 156 ------ .../fate/v1/lang/valued_node/Constant.java | 110 ---- .../fate/v1/lang/valued_node/CountOperator.java | 159 ------ .../fate/v1/lang/valued_node/FieldReference.java | 149 ------ .../fate/v1/lang/valued_node/IfElseValue.java | 164 ------ .../fate/v1/lang/valued_node/IsMemberOperator.java | 159 ------ .../fate/v1/lang/valued_node/MacroValueCall.java | 193 ------- .../tonkadur/fate/v1/lang/valued_node/Newline.java | 33 -- .../fate/v1/lang/valued_node/Operation.java | 178 ------- .../fate/v1/lang/valued_node/Operator.java | 143 ----- .../fate/v1/lang/valued_node/Paragraph.java | 67 --- .../v1/lang/valued_node/ParameterReference.java | 53 -- .../fate/v1/lang/valued_node/RefOperator.java | 54 -- .../fate/v1/lang/valued_node/TextWithEffect.java | 185 ------- .../fate/v1/lang/valued_node/ValueToRichText.java | 88 --- .../v1/lang/valued_node/VariableReference.java | 76 --- src/core/src/tonkadur/fate/v1/parser/FateParser.g4 | 56 +- .../wyrd/v1/compiler/fate/v1/Compiler.java | 104 ++++ .../v1/compiler/fate/v1/ComputationCompiler.java | 190 +++++++ .../wyrd/v1/compiler/fate/v1/FateVisitor.java | 298 +++++++++++ .../v1/compiler/fate/v1/InstructionCompiler.java | 587 +++++++++++++++++++++ .../wyrd/v1/compiler/fate/v1/SequenceCompiler.java | 48 ++ .../wyrd/v1/compiler/fate/v1/TypeCompiler.java | 149 ++++++ .../wyrd/v1/compiler/fate/v1/VariableCompiler.java | 42 ++ .../v1/compiler/util/AnonymousVariableManager.java | 76 +++ .../wyrd/v1/compiler/util/BinarySearch.java | 212 ++++++++ src/core/src/tonkadur/wyrd/v1/lang/Variable.java | 10 + .../wyrd/v1/lang/computation/AbsoluteRef.java | 39 -- .../wyrd/v1/lang/computation/Constant.java | 9 + .../wyrd/v1/lang/computation/Operation.java | 173 +++++- .../src/tonkadur/wyrd/v1/lang/computation/Ref.java | 39 ++ .../wyrd/v1/lang/computation/RelativeRef.java | 26 +- .../tonkadur/wyrd/v1/lang/computation/Size.java | 9 +- .../tonkadur/wyrd/v1/lang/computation/ValueOf.java | 7 + .../tonkadur/wyrd/v1/lang/instruction/Remove.java | 36 ++ .../wyrd/v1/lang/instruction/SetValue.java | 8 +- .../wyrd/v1/visitor/fate/v1/FateVisitor.java | 304 ----------- 86 files changed, 4598 insertions(+), 2984 deletions(-) create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/AtReference.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/Cast.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/CondValue.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/Constant.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/IfElseValue.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/MacroValueCall.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/Newline.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/Operation.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/Operator.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/Paragraph.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/ParameterReference.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/RefOperator.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/ValueToRichText.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/VariableReference.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/meta/Computation.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/meta/ExtensionComputation.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/meta/ExtensionValueNode.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/meta/Instruction.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/meta/InstructionNode.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/meta/ValueNode.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/AtReference.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/Cast.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/CondValue.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/Constant.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/CountOperator.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/FieldReference.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/IfElseValue.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/IsMemberOperator.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/MacroValueCall.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/Newline.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/Operation.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/Operator.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/Paragraph.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/ParameterReference.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/RefOperator.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/TextWithEffect.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/ValueToRichText.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/valued_node/VariableReference.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/FateVisitor.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/SequenceCompiler.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/VariableCompiler.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/lang/computation/AbsoluteRef.java create mode 100644 src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java create mode 100644 src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/visitor/fate/v1/FateVisitor.java diff --git a/src/core/src/tonkadur/fate/v1/lang/Macro.java b/src/core/src/tonkadur/fate/v1/lang/Macro.java index fd81db1..c4c4dc4 100644 --- a/src/core/src/tonkadur/fate/v1/lang/Macro.java +++ b/src/core/src/tonkadur/fate/v1/lang/Macro.java @@ -6,17 +6,17 @@ import java.util.List; import tonkadur.parser.Origin; import tonkadur.fate.v1.lang.meta.DeclaredEntity; -import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.Instruction; import tonkadur.fate.v1.lang.meta.TypedEntryList; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Computation; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.instruction.Display; import tonkadur.fate.v1.lang.instruction.InstructionList; -import tonkadur.fate.v1.lang.valued_node.Cast; -import tonkadur.fate.v1.lang.valued_node.ValueToRichText; +import tonkadur.fate.v1.lang.computation.Cast; +import tonkadur.fate.v1.lang.computation.ValueToRichText; public class Macro extends DeclaredEntity { @@ -29,7 +29,7 @@ public class Macro extends DeclaredEntity /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final InstructionNode root; + protected final Instruction root; protected final TypedEntryList parameters; /***************************************************************************/ @@ -40,7 +40,7 @@ public class Macro extends DeclaredEntity public Macro ( final Origin origin, - final InstructionNode root, + final Instruction root, final TypedEntryList parameters, final String name ) @@ -57,7 +57,7 @@ public class Macro extends DeclaredEntity return parameters; } - public InstructionNode get_root () + public Instruction get_root () { return root; } @@ -76,12 +76,12 @@ public class Macro extends DeclaredEntity return result; } - public ValueNode get_value_node_representation () + public Computation get_value_node_representation () { final Cast result_cast; InstructionList root_as_il; - InstructionNode instr; - ValueNode result; + Instruction instr; + Computation result; if (!(root instanceof InstructionList)) { diff --git a/src/core/src/tonkadur/fate/v1/lang/Sequence.java b/src/core/src/tonkadur/fate/v1/lang/Sequence.java index 8029c61..5b97e5c 100644 --- a/src/core/src/tonkadur/fate/v1/lang/Sequence.java +++ b/src/core/src/tonkadur/fate/v1/lang/Sequence.java @@ -16,7 +16,7 @@ import tonkadur.parser.Origin; import tonkadur.fate.v1.error.InvalidTypeException; import tonkadur.fate.v1.lang.meta.DeclaredEntity; -import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.Instruction; public class Sequence extends DeclaredEntity { @@ -29,7 +29,7 @@ public class Sequence extends DeclaredEntity /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final InstructionNode root; + protected final Instruction root; /***************************************************************************/ /**** PUBLIC ***************************************************************/ @@ -39,7 +39,7 @@ public class Sequence extends DeclaredEntity public Sequence ( final Origin origin, - final InstructionNode root, + final Instruction root, final String name ) { @@ -49,7 +49,7 @@ public class Sequence extends DeclaredEntity } /**** Accessors ************************************************************/ - public InstructionNode get_root () + public Instruction get_root () { return root; } diff --git a/src/core/src/tonkadur/fate/v1/lang/World.java b/src/core/src/tonkadur/fate/v1/lang/World.java index 3afd60a..d6c8ac0 100644 --- a/src/core/src/tonkadur/fate/v1/lang/World.java +++ b/src/core/src/tonkadur/fate/v1/lang/World.java @@ -18,8 +18,8 @@ import tonkadur.fate.v1.error.UnknownSequenceException; import tonkadur.fate.v1.lang.meta.DeclarationCollection; import tonkadur.fate.v1.lang.meta.ExtensionInstruction; -import tonkadur.fate.v1.lang.meta.ExtensionValueNode; -import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.ExtensionComputation; +import tonkadur.fate.v1.lang.meta.Instruction; import tonkadur.fate.v1.lang.type.Type; @@ -32,7 +32,7 @@ public class World protected final Set required_extensions; protected final Map> sequence_calls; - protected final Map extension_value_nodes; + protected final Map extension_value_nodes; protected final Map extension_instructions; protected final Map extension_first_level_instructions; @@ -44,7 +44,7 @@ public class World protected final DeclarationCollection type_collection; protected final DeclarationCollection variable_collection; - protected final List global_instructions; + protected final List global_instructions; /***************************************************************************/ /**** PUBLIC ***************************************************************/ @@ -57,7 +57,7 @@ public class World required_extensions = new HashSet(); sequence_calls = new HashMap>(); - extension_value_nodes = new HashMap(); + extension_value_nodes = new HashMap(); extension_instructions = new HashMap(); extension_first_level_instructions = new HashMap(); @@ -76,7 +76,7 @@ public class World add_base_types(); - global_instructions = new ArrayList(); + global_instructions = new ArrayList(); } /**** Accessors ************************************************************/ @@ -142,7 +142,7 @@ public class World return extension_first_level_instructions; } - public Map extension_value_nodes + public Map extension_value_nodes ( ) { @@ -180,12 +180,12 @@ public class World return variable_collection; } - public void add_global_instruction (final InstructionNode instruction) + public void add_global_instruction (final Instruction instruction) { global_instructions.add(instruction); } - public List get_global_instructions () + public List get_global_instructions () { return global_instructions; } diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/AtReference.java b/src/core/src/tonkadur/fate/v1/lang/computation/AtReference.java new file mode 100644 index 0000000..176b50c --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/AtReference.java @@ -0,0 +1,109 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.Collections; + +import tonkadur.parser.Origin; + +import tonkadur.error.ErrorManager; + +import tonkadur.fate.v1.error.InvalidTypeException; +import tonkadur.fate.v1.error.UnknownDictionaryFieldException; + +import tonkadur.fate.v1.lang.Variable; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Reference; + +import tonkadur.fate.v1.lang.type.RefType; +import tonkadur.fate.v1.lang.type.Type; + +public class AtReference extends Reference +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Reference parent; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + protected AtReference + ( + final Origin origin, + final Type reported_type, + final Reference parent + ) + { + super(origin, reported_type, ("(At " + parent.get_name() + ")")); + + this.parent = parent; + } + /**** Constructors *********************************************************/ + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static AtReference build + ( + final Origin origin, + final Reference parent + ) + throws + InvalidTypeException + { + Type current_type; + + current_type = parent.get_type(); + + if (!(current_type instanceof RefType)) + { + ErrorManager.handle + ( + new InvalidTypeException + ( + origin, + current_type, + Collections.singleton(Type.REF), + parent.get_name() + ) + ); + + current_type = Type.ANY; + } + else + { + current_type = ((RefType) current_type).get_referenced_type(); + } + + return new AtReference(origin, current_type, parent); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_at_reference(this); + } + + public Reference get_parent () + { + return parent; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(AtReference ("); + sb.append(type.get_name()); + sb.append(") "); + sb.append(parent.get_name()); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Cast.java b/src/core/src/tonkadur/fate/v1/lang/computation/Cast.java new file mode 100644 index 0000000..54b5c30 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/Cast.java @@ -0,0 +1,200 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import tonkadur.error.ErrorManager; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.IncompatibleTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +public class Cast extends Computation +{ + protected static final Map> allowed_type_changes; + + static + { + allowed_type_changes = new HashMap>(); + + allowed_type_changes.put + ( + Type.INT, + Type.NUMBER_TYPES + ); + + allowed_type_changes.put + ( + Type.FLOAT, + Type.NUMBER_TYPES + ); + + allowed_type_changes.put + ( + Type.DICT, + Collections.emptySet() + ); + + allowed_type_changes.put + ( + Type.SET, + Collections.emptySet() + ); + + allowed_type_changes.put + ( + Type.LIST, + Collections.emptySet() + ); + + allowed_type_changes.put + ( + Type.BOOLEAN, + Collections.emptySet() + ); + + allowed_type_changes.put + ( + Type.ANY, + Collections.singleton(Type.ANY) + ); + + allowed_type_changes.put + ( + Type.STRING, + Type.SIMPLE_BASE_TYPES + ); + } + + public static Collection get_allowed_casts_to (final Type t) + { + return allowed_type_changes.get(t); + } + + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation value; + protected final boolean is_autogenerated; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected Cast + ( + final Origin origin, + final Type to, + final Computation value, + final boolean is_autogenerated + ) + { + super(origin, to); + this.value = value; + this.is_autogenerated = is_autogenerated; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static Cast build + ( + final Origin origin, + final Type to, + final Computation value, + final boolean is_autogenerated + ) + throws + IncompatibleTypeException, + IncomparableTypeException + { + final Type hint; + + if + ( + (value.get_type().can_be_used_as(to)) + || + ( + (to.is_base_type()) + && + ( + allowed_type_changes.get(to).contains + ( + value.get_type().get_base_type() + ) + ) + ) + ) + { + return new Cast(origin, to, value, is_autogenerated); + } + + hint = (Type) value.get_type().generate_comparable_to(to); + + if (hint.equals(Type.ANY)) + { + ErrorManager.handle + ( + new IncompatibleTypeException(origin, value.get_type(), to) + ); + + ErrorManager.handle + ( + new IncomparableTypeException(origin, value.get_type(), to) + ); + } + else + { + ErrorManager.handle + ( + new IncompatibleTypeException(origin, value.get_type(), to, hint) + ); + } + + return new Cast(origin, hint, value, is_autogenerated); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_cast(this); + } + + public Computation get_parent () + { + return value; + } + + public boolean is_autogenerated () + { + return is_autogenerated; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("(Cast ("); + sb.append(type.get_name()); + sb.append(") "); + sb.append(value.toString()); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/CondValue.java b/src/core/src/tonkadur/fate/v1/lang/computation/CondValue.java new file mode 100644 index 0000000..e8afd21 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/CondValue.java @@ -0,0 +1,156 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.List; +import java.util.Collections; + +import tonkadur.functional.Cons; + +import tonkadur.error.ErrorManager; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.ConflictingTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; +import tonkadur.fate.v1.error.InvalidTypeException; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +public class CondValue extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final List> branches; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected CondValue + ( + final Origin origin, + final Type return_type, + final List> branches + ) + { + super(origin, return_type); + + this.branches = branches; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static CondValue build + ( + final Origin origin, + final List> branches + ) + throws + InvalidTypeException, + ConflictingTypeException, + IncomparableTypeException + { + final Type first_type; + Type candidate_hint, hint; + + first_type = branches.get(0).get_cdr().get_type(); + hint = first_type; + + for (final Cons entry: branches) + { + if (!entry.get_car().get_type().can_be_used_as(Type.BOOLEAN)) + { + ErrorManager.handle + ( + new InvalidTypeException + ( + entry.get_car().get_origin(), + entry.get_car().get_type(), + Collections.singleton(Type.BOOLEAN) + ) + ); + } + + if (entry.get_cdr().get_type().equals(hint)) + { + continue; + } + + candidate_hint = entry.get_cdr().get_type().try_merging_with(hint); + + if (candidate_hint != null) + { + hint = candidate_hint; + + continue; + } + + ErrorManager.handle + ( + new ConflictingTypeException + ( + entry.get_cdr().get_origin(), + entry.get_cdr().get_type(), + first_type + ) + ); + + hint = (Type) hint.generate_comparable_to(entry.get_cdr().get_type()); + + if (hint.equals(Type.ANY)) + { + ErrorManager.handle + ( + new IncomparableTypeException + ( + entry.get_cdr().get_origin(), + entry.get_cdr().get_type(), + first_type + ) + ); + } + } + + return new CondValue(origin, hint, branches); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_cond_value(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("(CondValue"); + sb.append(System.lineSeparator()); + + for (final Cons entry: branches) + { + sb.append(System.lineSeparator()); + sb.append("Condition:"); + sb.append(System.lineSeparator()); + sb.append(entry.get_car().toString()); + sb.append(System.lineSeparator()); + sb.append("Value:"); + sb.append(entry.get_cdr().toString()); + sb.append(System.lineSeparator()); + } + + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Constant.java b/src/core/src/tonkadur/fate/v1/lang/computation/Constant.java new file mode 100644 index 0000000..56f79f1 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/Constant.java @@ -0,0 +1,110 @@ +package tonkadur.fate.v1.lang.computation; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +public class Constant extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final String as_string; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected Constant + ( + final Origin origin, + final Type result_type, + final String as_string + ) + { + super(origin, result_type); + + this.as_string = as_string; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static Constant build_boolean + ( + final Origin origin, + final boolean value + ) + { + return new Constant(origin, Type.BOOLEAN, value ? "true" : "false"); + } + + public static Constant build_string + ( + final Origin origin, + final String value + ) + { + return new Constant(origin, Type.STRING, value); + } + + public static Constant build (final Origin origin, final String as_string) + { + try + { + Integer.valueOf(as_string); + + return new Constant(origin, Type.INT, as_string); + } + catch (final NumberFormatException nfe) + { + /* That's fine, we're just testing... */ + } + + try + { + Float.valueOf(as_string); + + return new Constant(origin, Type.FLOAT, as_string); + } + catch (final NumberFormatException nfe) + { + /* That's fine, we're just testing... */ + } + + return new Constant(origin, Type.STRING, as_string); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_constant(this); + } + + public String get_value_as_string () + { + return as_string; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("("); + sb.append(type.get_name()); + sb.append(" Constant "); + sb.append(as_string); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java new file mode 100644 index 0000000..0c26abc --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java @@ -0,0 +1,159 @@ +package tonkadur.fate.v1.lang.computation; + +import tonkadur.error.ErrorManager; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.ConflictingTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; +import tonkadur.fate.v1.error.InvalidTypeException; + +import tonkadur.fate.v1.lang.type.CollectionType; +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +public class CountOperator extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation element; + protected final Computation collection; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected CountOperator + ( + final Origin origin, + final Computation element, + final Computation collection + ) + { + super(origin, Type.INT); + + this.collection = collection; + this.element = element; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static CountOperator build + ( + final Origin origin, + final Computation element, + final Computation collection + ) + throws + InvalidTypeException, + ConflictingTypeException, + IncomparableTypeException + { + final Type hint; + final Type collection_type; + final CollectionType collection_true_type; + final Type collection_element_type; + + collection_type = collection.get_type(); + + if + ( + !Type.COLLECTION_TYPES.contains(collection_type.get_base_type()) + || !(collection_type instanceof CollectionType) + ) + { + ErrorManager.handle + ( + new InvalidTypeException + ( + collection.get_origin(), + collection.get_type(), + Type.COLLECTION_TYPES + ) + ); + } + + collection_true_type = (CollectionType) collection_type; + collection_element_type = collection_true_type.get_content_type(); + + if + ( + element.get_type().can_be_used_as(collection_element_type) + || + (element.get_type().try_merging_with(collection_element_type) != null) + ) + { + return new CountOperator(origin, element, collection); + } + + ErrorManager.handle + ( + new ConflictingTypeException + ( + element.get_origin(), + element.get_type(), + collection_element_type + ) + ); + + hint = + (Type) element.get_type().generate_comparable_to + ( + collection_element_type + ); + + if (hint.equals(Type.ANY)) + { + ErrorManager.handle + ( + new IncomparableTypeException + ( + element.get_origin(), + element.get_type(), + collection_element_type + ) + ); + } + + return new CountOperator(origin, element, collection); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_count_operator(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("(CountOperator"); + sb.append(System.lineSeparator()); + sb.append(System.lineSeparator()); + + sb.append("element:"); + sb.append(System.lineSeparator()); + sb.append(element.toString()); + sb.append(System.lineSeparator()); + sb.append(System.lineSeparator()); + + sb.append("collection:"); + sb.append(System.lineSeparator()); + sb.append(collection.toString()); + + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java b/src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java new file mode 100644 index 0000000..635e372 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java @@ -0,0 +1,149 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.Collections; +import java.util.List; + +import tonkadur.parser.Origin; + +import tonkadur.error.ErrorManager; + +import tonkadur.fate.v1.error.InvalidTypeException; +import tonkadur.fate.v1.error.UnknownDictionaryFieldException; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Reference; + +import tonkadur.fate.v1.lang.type.DictType; +import tonkadur.fate.v1.lang.type.Type; + +public class FieldReference extends Reference +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Reference parent; + protected final String field_name; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected FieldReference + ( + final Origin origin, + final Reference parent, + final Type type, + final String field_name + ) + { + super(origin, type, (parent.get_name() + "." + field_name)); + + this.parent = parent; + this.field_name = field_name; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static FieldReference build + ( + final Origin origin, + Reference parent, + final String field + ) + throws + InvalidTypeException, + UnknownDictionaryFieldException + { + Type current_type; + + current_type = parent.get_type(); + + if (current_type.get_base_type().equals(Type.REF)) + { + parent = AtReference.build(origin, parent); + current_type = parent.get_type(); + } + + if (!(current_type instanceof DictType)) + { + ErrorManager.handle + ( + new InvalidTypeException + ( + origin, + current_type, + Collections.singleton(Type.DICT), + parent.get_name() + ) + ); + + current_type = Type.ANY; + } + else + { + current_type = ((DictType) current_type).get_field_type(origin, field); + } + + return new FieldReference(origin, parent, current_type, field); + } + + public static FieldReference build + ( + final Origin origin, + Reference parent, + final List field_sequence + ) + throws + InvalidTypeException, + UnknownDictionaryFieldException + { + for (final String field: field_sequence) + { + parent = build(origin, parent, field); + } + + if (parent instanceof FieldReference) + { + return (FieldReference) parent; + } + else + { + return null; + } + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_field_reference(this); + } + + public String get_field_name () + { + return field_name; + } + + public Reference get_parent () + { + return parent; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(FieldReference ("); + sb.append(type.get_name()); + sb.append(") "); + sb.append(name); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/IfElseValue.java b/src/core/src/tonkadur/fate/v1/lang/computation/IfElseValue.java new file mode 100644 index 0000000..97fe315 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/IfElseValue.java @@ -0,0 +1,164 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.Collections; + +import tonkadur.error.ErrorManager; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.ConflictingTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; +import tonkadur.fate.v1.error.InvalidTypeException; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +public class IfElseValue extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation condition; + protected final Computation if_true; + protected final Computation if_false; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected IfElseValue + ( + final Origin origin, + final Type return_type, + final Computation condition, + final Computation if_true, + final Computation if_false + ) + { + super(origin, return_type); + + this.condition = condition; + this.if_true = if_true; + this.if_false = if_false; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static IfElseValue build + ( + final Origin origin, + final Computation condition, + final Computation if_true, + final Computation if_false + ) + throws + InvalidTypeException, + ConflictingTypeException, + IncomparableTypeException + { + Type hint; + final Type if_true_type; + final Type if_false_type; + + if (!condition.get_type().can_be_used_as(Type.BOOLEAN)) + { + ErrorManager.handle + ( + new InvalidTypeException + ( + condition.get_origin(), + condition.get_type(), + Collections.singleton(Type.BOOLEAN) + ) + ); + } + + if_true_type = if_true.get_type(); + if_false_type = if_false.get_type(); + + if (if_true_type.equals(if_false_type)) + { + return + new IfElseValue(origin, if_true_type, condition, if_true, if_false); + } + + hint = if_true_type.try_merging_with(if_false_type); + + if (hint != null) + { + return new IfElseValue(origin, hint, condition, if_true, if_false); + } + + ErrorManager.handle + ( + new ConflictingTypeException + ( + if_false.get_origin(), + if_false_type, + if_true_type + ) + ); + + hint = + (Type) if_false_type.generate_comparable_to(if_true_type); + + if (hint.equals(Type.ANY)) + { + ErrorManager.handle + ( + new IncomparableTypeException + ( + if_false.get_origin(), + if_false_type, + if_true_type + ) + ); + } + + return new IfElseValue(origin, hint, condition, if_true, if_false); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_if_else_value(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("(IfElseValue"); + sb.append(System.lineSeparator()); + sb.append(System.lineSeparator()); + + sb.append("Condition:"); + sb.append(System.lineSeparator()); + sb.append(condition.toString()); + + sb.append(System.lineSeparator()); + sb.append(System.lineSeparator()); + sb.append("If true:"); + sb.append(System.lineSeparator()); + sb.append(if_true.toString()); + + sb.append(System.lineSeparator()); + sb.append(System.lineSeparator()); + sb.append("If false:"); + sb.append(System.lineSeparator()); + sb.append(if_false.toString()); + + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java new file mode 100644 index 0000000..8e4aeb3 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java @@ -0,0 +1,159 @@ +package tonkadur.fate.v1.lang.computation; + +import tonkadur.error.ErrorManager; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.ConflictingTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; +import tonkadur.fate.v1.error.InvalidTypeException; + +import tonkadur.fate.v1.lang.type.CollectionType; +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +public class IsMemberOperator extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation element; + protected final Computation collection; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected IsMemberOperator + ( + final Origin origin, + final Computation element, + final Computation collection + ) + { + super(origin, Type.BOOLEAN); + + this.collection = collection; + this.element = element; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static IsMemberOperator build + ( + final Origin origin, + final Computation element, + final Computation collection + ) + throws + InvalidTypeException, + ConflictingTypeException, + IncomparableTypeException + { + final Type hint; + final Type collection_type; + final CollectionType collection_true_type; + final Type collection_element_type; + + collection_type = collection.get_type(); + + if + ( + !Type.COLLECTION_TYPES.contains(collection_type.get_base_type()) + || !(collection_type instanceof CollectionType) + ) + { + ErrorManager.handle + ( + new InvalidTypeException + ( + collection.get_origin(), + collection.get_type(), + Type.COLLECTION_TYPES + ) + ); + } + + collection_true_type = (CollectionType) collection_type; + collection_element_type = collection_true_type.get_content_type(); + + if + ( + element.get_type().can_be_used_as(collection_element_type) + || + (element.get_type().try_merging_with(collection_element_type) != null) + ) + { + return new IsMemberOperator(origin, element, collection); + } + + ErrorManager.handle + ( + new ConflictingTypeException + ( + element.get_origin(), + element.get_type(), + collection_element_type + ) + ); + + hint = + (Type) element.get_type().generate_comparable_to + ( + collection_element_type + ); + + if (hint.equals(Type.ANY)) + { + ErrorManager.handle + ( + new IncomparableTypeException + ( + element.get_origin(), + element.get_type(), + collection_element_type + ) + ); + } + + return new IsMemberOperator(origin, element, collection); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_is_member_operator(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("(IsMemberOperator"); + sb.append(System.lineSeparator()); + sb.append(System.lineSeparator()); + + sb.append("element:"); + sb.append(System.lineSeparator()); + sb.append(element.toString()); + sb.append(System.lineSeparator()); + sb.append(System.lineSeparator()); + + sb.append("collection:"); + sb.append(System.lineSeparator()); + sb.append(collection.toString()); + + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/MacroValueCall.java b/src/core/src/tonkadur/fate/v1/lang/computation/MacroValueCall.java new file mode 100644 index 0000000..83b16d4 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/MacroValueCall.java @@ -0,0 +1,193 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.ArrayList; +import java.util.List; + +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; + +import tonkadur.functional.Merge; + +import tonkadur.error.ErrorManager; + +import tonkadur.fate.v1.error.IncompatibleTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; +import tonkadur.fate.v1.error.InvalidArityException; +import tonkadur.fate.v1.error.NotAValueMacroException; + +import tonkadur.fate.v1.lang.Macro; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +public class MacroValueCall extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Macro macro; + protected final Computation act_as; + protected final List parameters; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected MacroValueCall + ( + final Origin origin, + final Macro macro, + final List parameters, + final Computation act_as + ) + { + super(origin, act_as.get_type()); + + this.macro = macro; + this.parameters = parameters; + this.act_as = act_as; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static MacroValueCall build + ( + final Origin origin, + final Macro macro, + final List parameters + ) + throws Throwable + { + Computation act_as; + final List signature; + + act_as = macro.get_value_node_representation(); + + if (act_as == null) + { + ErrorManager.handle + ( + new NotAValueMacroException(origin, macro.get_name()) + ); + } + + signature = macro.get_signature(); + + if (parameters.size() != signature.size()) + { + ErrorManager.handle + ( + new InvalidArityException + ( + origin, + parameters.size(), + signature.size(), + signature.size() + ) + ); + } + + (new Merge() + { + @Override + public Boolean risky_lambda (final Type t, final Computation p) + throws ParsingError + { + if ((t == null) || (p == null)) + { + return Boolean.FALSE; + } + else + { + final Type hint; + + if (p.get_type().can_be_used_as(t)) + { + return Boolean.TRUE; + } + + if (p.get_type().try_merging_with(t) != null) + { + return Boolean.TRUE; + } + + ErrorManager.handle + ( + new IncompatibleTypeException + ( + p.get_origin(), + p.get_type(), + t + ) + ); + + hint = (Type) p.get_type().generate_comparable_to(t); + + if (hint.equals(Type.ANY)) + { + ErrorManager.handle + ( + new IncomparableTypeException + ( + p.get_origin(), + p.get_type(), + t + ) + ); + } + + return Boolean.FALSE; + } + } + }).risky_merge(signature, parameters); + + return new MacroValueCall(origin, macro, parameters, act_as); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_macro_value_call(this); + } + + public Macro get_macro () + { + return macro; + } + + public Computation get_actual_value_node () + { + return act_as; + } + + public List get_parameters () + { + return parameters; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(MacroValueCall ("); + sb.append(macro.get_name()); + + for (final Computation param: parameters) + { + sb.append(" "); + sb.append(param.toString()); + } + + sb.append("))"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Newline.java b/src/core/src/tonkadur/fate/v1/lang/computation/Newline.java new file mode 100644 index 0000000..13b9671 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/Newline.java @@ -0,0 +1,33 @@ +package tonkadur.fate.v1.lang.computation; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.RichTextNode; + +public class Newline extends RichTextNode +{ + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public Newline (final Origin origin) + { + super(origin); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_newline(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + return "(Newline)"; + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Operation.java b/src/core/src/tonkadur/fate/v1/lang/computation/Operation.java new file mode 100644 index 0000000..44f2a45 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/Operation.java @@ -0,0 +1,178 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.Collection; +import java.util.List; + +import tonkadur.error.ErrorManager; + +import tonkadur.parser.Origin; + +//import tonkadur.fate.v1.error.ConflictingTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; +import tonkadur.fate.v1.error.IncompatibleTypeException; +import tonkadur.fate.v1.error.InvalidArityException; +import tonkadur.fate.v1.error.InvalidTypeException; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +public class Operation extends Computation +{ + protected final Operator operator; + protected final List operands; + + protected Operation + ( + final Origin origin, + final Type result_type, + final Operator operator, + final List operands + ) + { + super(origin, result_type); + + this.operator = operator; + this.operands = operands; + } + + public static Operation build + ( + final Origin origin, + final Operator operator, + final List operands + ) + throws + //ConflictingTypeException, + IncomparableTypeException, + IncompatibleTypeException, + InvalidArityException, + InvalidTypeException + { + final Collection allowed_base_types; + final int operator_max_arity; + final int operator_min_arity; + final int operands_size; + Type computed_type, previous_computed_type; + + allowed_base_types = operator.get_allowed_base_types(); + operator_max_arity = operator.get_maximum_arity(); + operator_min_arity = operator.get_minimum_arity(); + operands_size = operands.size(); + + if + ( + (operands_size < operator_min_arity) + || + ( + (operator_max_arity != 0) + && (operator_max_arity < operands_size) + ) + ) + { + ErrorManager.handle + ( + new InvalidArityException + ( + origin, + operands_size, + operator_min_arity, + operator_max_arity + ) + ); + } + + computed_type = operands.get(0).get_type(); + + for (final Computation operand: operands) + { + final Type operand_type; + + operand_type = operand.get_type(); + + if (!allowed_base_types.contains(operand_type.get_base_type())) + { + ErrorManager.handle + ( + new InvalidTypeException + ( + operand.get_origin(), + operand_type, + allowed_base_types + ) + ); + } + + /* + + if (computed_type.equals(operand_type)) + { + continue; + } + + ErrorManager.handle + ( + new ConflictingTypeException + ( + operand.get_origin(), + operand_type, + computed_type + ) + ); + + */ + + if (operand_type.can_be_used_as(computed_type)) + { + continue; + } + + previous_computed_type = computed_type; + computed_type = computed_type.try_merging_with(operand_type); + + if (computed_type != null) + { + continue; + } + + ErrorManager.handle + ( + new IncompatibleTypeException + ( + operand.get_origin(), + operand_type, + previous_computed_type + ) + ); + + computed_type = + (Type) previous_computed_type.generate_comparable_to(operand_type); + + if (computed_type.equals(Type.ANY)) + { + ErrorManager.handle + ( + new IncomparableTypeException + ( + operand.get_origin(), + operand_type, + previous_computed_type + ) + ); + } + } + + computed_type = operator.transform_type(computed_type); + + return new Operation(origin, computed_type, operator, operands); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_operation(this); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Operator.java b/src/core/src/tonkadur/fate/v1/lang/computation/Operator.java new file mode 100644 index 0000000..5cda7c2 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/Operator.java @@ -0,0 +1,137 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.Collections; +import java.util.Set; + +import tonkadur.fate.v1.lang.type.Type; + +/* + * Yes, it *could* have been an enum. In fact, it used to be one. Except that + * unless you want to ensure coverage of all cases in a switch, Java enums are + * clearly inferior to classes in everyway. Having this be a class will, at + * the very least, let you extend it to add new operators in extensions. + */ +public class Operator +{ + public static final Operator PLUS; + public static final Operator MINUS; + public static final Operator TIMES; + public static final Operator DIVIDE; + public static final Operator POWER; + public static final Operator RANDOM; + + public static final Operator AND; + public static final Operator OR; + public static final Operator NOT; + public static final Operator IMPLIES; + public static final Operator ONE_IN; + + public static final Operator EQUALS; + + public static final Operator LOWER_THAN; + public static final Operator LOWER_EQUAL_THAN; + public static final Operator GREATER_EQUAL_THAN; + public static final Operator GREATER_THAN; + + + static + { + PLUS = new Operator("+", 2, 0, Type.NUMBER_TYPES, null); + MINUS = new Operator("-", 2, 0, Type.NUMBER_TYPES, null); + TIMES = new Operator("*", 2, 0, Type.NUMBER_TYPES, null); + DIVIDE = new Operator("/", 2, 2, Type.NUMBER_TYPES, null); + POWER = new Operator("^", 2, 2, Type.NUMBER_TYPES, null); + RANDOM = + new Operator("rand", 2, 2, Collections.singleton(Type.INT), null); + + AND = + new Operator("and", 2, 0, Collections.singleton(Type.BOOLEAN), null); + OR = + new Operator("or", 2, 0, Collections.singleton(Type.BOOLEAN), null); + NOT = + new Operator("not", 1, 1, Collections.singleton(Type.BOOLEAN), null); + IMPLIES = + new Operator + ( + "implies", + 2, + 2, + Collections.singleton(Type.BOOLEAN), + null + ); + ONE_IN = + new Operator + ( + "one_in", + 1, + 0, + Collections.singleton(Type.BOOLEAN), + null + ); + + EQUALS = + new Operator("equals", 2, 0, Type.SIMPLE_BASE_TYPES, Type.BOOLEAN); + LOWER_THAN = + new Operator("<", 2, 2, Type.SIMPLE_BASE_TYPES, Type.BOOLEAN); + LOWER_EQUAL_THAN = + new Operator("=<", 2, 2, Type.SIMPLE_BASE_TYPES, Type.BOOLEAN); + GREATER_EQUAL_THAN = + new Operator(">=", 2, 2, Type.SIMPLE_BASE_TYPES, Type.BOOLEAN); + GREATER_THAN = + new Operator(">", 2, 2, Type.SIMPLE_BASE_TYPES, Type.BOOLEAN); + } + + final protected String name; + final protected int min_arity; + final protected int max_arity; + final protected Set valid_input_types; + final protected Type output_type_transform; + + protected Operator + ( + final String name, + final int min_arity, + final int max_arity, + final Set valid_input_types, + final Type output_type_transform + ) + { + this.name = name; + this.min_arity = min_arity; + this.max_arity = max_arity; + this.valid_input_types = valid_input_types; + + this.output_type_transform = output_type_transform; + } + + public Set get_allowed_base_types () + { + return valid_input_types; + } + + public int get_minimum_arity () + { + return min_arity; + } + + public int get_maximum_arity () + { + return max_arity; + } + + public Type transform_type (final Type in) + { + if (output_type_transform == null) + { + return in; + } + + return output_type_transform; + } + + @Override + public String toString () + { + return name; + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Paragraph.java b/src/core/src/tonkadur/fate/v1/lang/computation/Paragraph.java new file mode 100644 index 0000000..0d1b8ce --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/Paragraph.java @@ -0,0 +1,67 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.List; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.RichTextNode; + +public class Paragraph extends RichTextNode +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final List content; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public Paragraph + ( + final Origin origin, + final List content + ) + { + super(origin); + + this.content = content; + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_paragraph(this); + } + + public List get_content () + { + return content; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(Paragraph "); + + for (final RichTextNode text: content) + { + sb.append(content.toString()); + } + + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/ParameterReference.java b/src/core/src/tonkadur/fate/v1/lang/computation/ParameterReference.java new file mode 100644 index 0000000..06cf523 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/ParameterReference.java @@ -0,0 +1,53 @@ +package tonkadur.fate.v1.lang.computation; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Reference; + +import tonkadur.fate.v1.lang.type.Type; + +public class ParameterReference extends Reference +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public ParameterReference + ( + final Origin origin, + final Type reported_type, + final String parameter_name + ) + { + super(origin, reported_type, parameter_name); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_parameter_reference(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("(ParameterReference ("); + sb.append(type.get_name()); + sb.append(") "); + sb.append(name); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/RefOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/RefOperator.java new file mode 100644 index 0000000..edbcc29 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/RefOperator.java @@ -0,0 +1,54 @@ +package tonkadur.fate.v1.lang.computation; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.type.RefType; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Reference; +import tonkadur.fate.v1.lang.meta.Computation; + +public class RefOperator extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Reference referred; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public RefOperator (final Origin origin, final Reference referred) + { + super(origin, new RefType(origin, referred.get_type(), "auto generated")); + this.referred = referred; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_ref_operator(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("(Ref "); + sb.append(referred.get_name()); + sb.append(") "); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java b/src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java new file mode 100644 index 0000000..7be47c1 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/TextWithEffect.java @@ -0,0 +1,185 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.ArrayList; +import java.util.List; + +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; + +import tonkadur.functional.Merge; + +import tonkadur.error.ErrorManager; + +import tonkadur.fate.v1.error.IncompatibleTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; +import tonkadur.fate.v1.error.InvalidArityException; + +import tonkadur.fate.v1.lang.TextEffect; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.RichTextNode; +import tonkadur.fate.v1.lang.meta.Computation; + +public class TextWithEffect extends RichTextNode +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final TextEffect effect; + protected final List parameters; + protected final RichTextNode text; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected TextWithEffect + ( + final Origin origin, + final TextEffect effect, + final List parameters, + final RichTextNode text + ) + { + super(origin); + + this.effect = effect; + this.parameters = parameters; + this.text = text; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static TextWithEffect build + ( + final Origin origin, + final TextEffect effect, + final List parameters, + final RichTextNode text + ) + throws Throwable + { + final List signature; + + signature = effect.get_signature(); + + if (parameters.size() != signature.size()) + { + ErrorManager.handle + ( + new InvalidArityException + ( + origin, + parameters.size(), + signature.size(), + signature.size() + ) + ); + } + + (new Merge() + { + @Override + public Boolean risky_lambda (final Type t, final Computation p) + throws ParsingError + { + if ((t == null) || (p == null)) + { + return Boolean.FALSE; + } + else + { + final Type hint; + + if (p.get_type().can_be_used_as(t)) + { + return Boolean.TRUE; + } + + if (p.get_type().try_merging_with(t) != null) + { + return Boolean.TRUE; + } + + ErrorManager.handle + ( + new IncompatibleTypeException + ( + p.get_origin(), + p.get_type(), + t + ) + ); + + hint = (Type) p.get_type().generate_comparable_to(t); + + if (hint.equals(Type.ANY)) + { + ErrorManager.handle + ( + new IncomparableTypeException + ( + p.get_origin(), + p.get_type(), + t + ) + ); + } + + return Boolean.FALSE; + } + } + }).risky_merge(signature, parameters); + + return new TextWithEffect(origin, effect, parameters, text); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_text_with_effect(this); + } + + public TextEffect get_effect () + { + return effect; + } + + public List get_parameters () + { + return parameters; + } + + public RichTextNode get_text () + { + return text; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(TextWithEffect ("); + sb.append(effect.get_name()); + + for (final Computation param: parameters) + { + sb.append(" "); + sb.append(param.toString()); + } + + sb.append(") "); + sb.append(text.toString()); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/ValueToRichText.java b/src/core/src/tonkadur/fate/v1/lang/computation/ValueToRichText.java new file mode 100644 index 0000000..917f4ad --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/ValueToRichText.java @@ -0,0 +1,88 @@ +package tonkadur.fate.v1.lang.computation; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.IncompatibleTypeException; +import tonkadur.fate.v1.error.IncomparableTypeException; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.RichTextNode; +import tonkadur.fate.v1.lang.meta.Computation; + +public class ValueToRichText extends RichTextNode +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation value; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected ValueToRichText (final Computation value) + { + super(value.get_origin()); + + this.value = value; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static ValueToRichText build (final Computation value) + throws + IncompatibleTypeException, + IncomparableTypeException + { + final Type value_base_type; + + value_base_type = value.get_type().get_base_type(); + + if (value_base_type.equals(Type.STRING)) + { + return new ValueToRichText(value); + } + + return + new ValueToRichText + ( + Cast.build + ( + value.get_origin(), + Type.STRING, + value, + true + ) + ); + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_value_to_rich_text(this); + } + + public Computation get_value () + { + return value; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(ValueToRichText "); + sb.append(value.toString()); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/VariableReference.java b/src/core/src/tonkadur/fate/v1/lang/computation/VariableReference.java new file mode 100644 index 0000000..d8522c2 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/VariableReference.java @@ -0,0 +1,76 @@ +package tonkadur.fate.v1.lang.computation; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.Variable; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; +import tonkadur.fate.v1.lang.meta.Reference; + +import tonkadur.fate.v1.lang.type.Type; + +public class VariableReference extends Reference +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Variable variable; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + protected VariableReference + ( + final Origin origin, + final Type reported_type, + final Variable variable + ) + { + super(origin, reported_type, variable.get_name()); + this.variable = variable; + } + /**** Constructors *********************************************************/ + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public VariableReference + ( + final Origin origin, + final Variable variable + ) + { + super(origin, variable.get_type(), variable.get_name()); + this.variable = variable; + } + + /**** Accessors ************************************************************/ + @Override + public void visit (final NodeVisitor nv) + throws Throwable + { + nv.visit_variable_reference(this); + } + + public Variable get_variable () + { + return variable; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("(VariableReference ("); + sb.append(type.get_name()); + sb.append(") "); + sb.append(variable.get_name()); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java index 455d241..759a882 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java @@ -12,16 +12,16 @@ import tonkadur.fate.v1.lang.type.CollectionType; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class AddElement extends InstructionNode +public class AddElement extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final ValueNode element; - protected final ValueNode collection; + protected final Computation element; + protected final Computation collection; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -30,8 +30,8 @@ public class AddElement extends InstructionNode protected AddElement ( final Origin origin, - final ValueNode element, - final ValueNode collection + final Computation element, + final Computation collection ) { super(origin); @@ -47,8 +47,8 @@ public class AddElement extends InstructionNode public static AddElement build ( final Origin origin, - final ValueNode element, - final ValueNode collection + final Computation element, + final Computation collection ) throws InvalidTypeException, @@ -132,6 +132,16 @@ public class AddElement extends InstructionNode nv.visit_add_element(this); } + public Computation get_collection () + { + return collection; + } + + public Computation get_element () + { + return element + } + /**** Misc. ****************************************************************/ @Override public String toString () diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/Assert.java b/src/core/src/tonkadur/fate/v1/lang/instruction/Assert.java index 8cb3fae..8e7dbc5 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/Assert.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/Assert.java @@ -11,15 +11,15 @@ import tonkadur.fate.v1.error.InvalidTypeException; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class Assert extends InstructionNode +public class Assert extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final ValueNode condition; + protected final Computation condition; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -28,7 +28,7 @@ public class Assert extends InstructionNode protected Assert ( final Origin origin, - final ValueNode condition + final Computation condition ) { super(origin); @@ -43,7 +43,7 @@ public class Assert extends InstructionNode public static Assert build ( final Origin origin, - final ValueNode condition + final Computation condition ) throws InvalidTypeException { @@ -71,7 +71,7 @@ public class Assert extends InstructionNode nv.visit_assert(this); } - public ValueNode get_condition () + public Computation get_condition () { return condition; } diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java b/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java index af39742..e414e19 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java @@ -10,15 +10,15 @@ import tonkadur.fate.v1.lang.type.CollectionType; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class Clear extends InstructionNode +public class Clear extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final ValueNode collection; + protected final Computation collection; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -27,7 +27,7 @@ public class Clear extends InstructionNode protected Clear ( final Origin origin, - final ValueNode collection + final Computation collection ) { super(origin); @@ -42,7 +42,7 @@ public class Clear extends InstructionNode public static Clear build ( final Origin origin, - final ValueNode collection + final Computation collection ) throws InvalidTypeException { @@ -73,7 +73,7 @@ public class Clear extends InstructionNode nv.visit_clear(this); } - public ValueNode get_collection () + public Computation get_collection () { return collection; } diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/CondInstruction.java b/src/core/src/tonkadur/fate/v1/lang/instruction/CondInstruction.java index 6caa16f..1fd1bce 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/CondInstruction.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/CondInstruction.java @@ -14,15 +14,15 @@ import tonkadur.fate.v1.error.InvalidTypeException; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class CondInstruction extends InstructionNode +public class CondInstruction extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final List> branches; + protected final List> branches; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -31,7 +31,7 @@ public class CondInstruction extends InstructionNode protected CondInstruction ( final Origin origin, - final List> branches + final List> branches ) { super(origin); @@ -46,11 +46,11 @@ public class CondInstruction extends InstructionNode public static CondInstruction build ( final Origin origin, - final List> branches + final List> branches ) throws InvalidTypeException { - for (final Cons branch: branches) + for (final Cons branch: branches) { if (!branch.get_car().get_type().get_base_type().equals(Type.BOOLEAN)) { @@ -77,7 +77,7 @@ public class CondInstruction extends InstructionNode nv.visit_cond_instruction(this); } - public List> get_branches () + public List> get_branches () { return branches; } @@ -91,7 +91,7 @@ public class CondInstruction extends InstructionNode sb.append("(CondInstruction"); sb.append(System.lineSeparator()); - for (final Cons branch: branches) + for (final Cons branch: branches) { sb.append(System.lineSeparator()); sb.append("if:"); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/Display.java b/src/core/src/tonkadur/fate/v1/lang/instruction/Display.java index e383a0d..24fc27d 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/Display.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/Display.java @@ -9,10 +9,10 @@ import tonkadur.parser.Origin; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.Instruction; import tonkadur.fate.v1.lang.meta.RichTextNode; -public class Display extends InstructionNode +public class Display extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/EventCall.java b/src/core/src/tonkadur/fate/v1/lang/instruction/EventCall.java index 3e57471..e9bf5f9 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/EventCall.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/EventCall.java @@ -19,16 +19,16 @@ import tonkadur.fate.v1.lang.Event; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class EventCall extends InstructionNode +public class EventCall extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ protected final Event event; - protected final List parameters; + protected final List parameters; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -38,7 +38,7 @@ public class EventCall extends InstructionNode ( final Origin origin, final Event event, - final List parameters + final List parameters ) { super(origin); @@ -55,7 +55,7 @@ public class EventCall extends InstructionNode ( final Origin origin, final Event event, - final List parameters + final List parameters ) throws Throwable { @@ -78,10 +78,10 @@ public class EventCall extends InstructionNode ); } - (new Merge() + (new Merge() { @Override - public Boolean risky_lambda (final Type t, final ValueNode p) + public Boolean risky_lambda (final Type t, final Computation p) throws ParsingError { if ((t == null) || (p == null)) @@ -148,7 +148,7 @@ public class EventCall extends InstructionNode return event; } - public List get_parameters () + public List get_parameters () { return parameters; } @@ -162,7 +162,7 @@ public class EventCall extends InstructionNode sb.append("(EventCall ("); sb.append(event.get_name()); - for (final ValueNode param: parameters) + for (final Computation param: parameters) { sb.append(" "); sb.append(param.toString()); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/IfElseInstruction.java b/src/core/src/tonkadur/fate/v1/lang/instruction/IfElseInstruction.java index cb4596e..c07a8d6 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/IfElseInstruction.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/IfElseInstruction.java @@ -11,17 +11,17 @@ import tonkadur.fate.v1.error.InvalidTypeException; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class IfElseInstruction extends InstructionNode +public class IfElseInstruction extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final ValueNode condition; - protected final InstructionNode if_true; - protected final InstructionNode if_false; + protected final Computation condition; + protected final Instruction if_true; + protected final Instruction if_false; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -30,9 +30,9 @@ public class IfElseInstruction extends InstructionNode protected IfElseInstruction ( final Origin origin, - final ValueNode condition, - final InstructionNode if_true, - final InstructionNode if_false + final Computation condition, + final Instruction if_true, + final Instruction if_false ) { super(origin); @@ -49,9 +49,9 @@ public class IfElseInstruction extends InstructionNode public static IfElseInstruction build ( final Origin origin, - final ValueNode condition, - final InstructionNode if_true, - final InstructionNode if_false + final Computation condition, + final Instruction if_true, + final Instruction if_false ) throws InvalidTypeException { @@ -79,17 +79,17 @@ public class IfElseInstruction extends InstructionNode nv.visit_if_else_instruction(this); } - public ValueNode get_condition () + public Computation get_condition () { return condition; } - public InstructionNode get_if_true () + public Instruction get_if_true () { return if_true; } - public InstructionNode get_if_false () + public Instruction get_if_false () { return if_false; } diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/IfInstruction.java b/src/core/src/tonkadur/fate/v1/lang/instruction/IfInstruction.java index b1b37b3..7dfe376 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/IfInstruction.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/IfInstruction.java @@ -11,16 +11,16 @@ import tonkadur.fate.v1.error.InvalidTypeException; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class IfInstruction extends InstructionNode +public class IfInstruction extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final ValueNode condition; - protected final InstructionNode if_true; + protected final Computation condition; + protected final Instruction if_true; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -29,8 +29,8 @@ public class IfInstruction extends InstructionNode protected IfInstruction ( final Origin origin, - final ValueNode condition, - final InstructionNode if_true + final Computation condition, + final Instruction if_true ) { super(origin); @@ -46,8 +46,8 @@ public class IfInstruction extends InstructionNode public static IfInstruction build ( final Origin origin, - final ValueNode condition, - final InstructionNode if_true + final Computation condition, + final Instruction if_true ) throws InvalidTypeException { @@ -75,12 +75,12 @@ public class IfInstruction extends InstructionNode nv.visit_if_instruction(this); } - public ValueNode get_condition () + public Computation get_condition () { return condition; } - public InstructionNode get_if_true () + public Instruction get_if_true () { return if_true; } diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/InstructionList.java b/src/core/src/tonkadur/fate/v1/lang/instruction/InstructionList.java index df77bbe..658fa58 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/InstructionList.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/InstructionList.java @@ -5,14 +5,14 @@ import java.util.List; import tonkadur.parser.Origin; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.Instruction; -public class InstructionList extends InstructionNode +public class InstructionList extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final List instructions; + protected final List instructions; /***************************************************************************/ /**** PUBLIC ***************************************************************/ @@ -21,7 +21,7 @@ public class InstructionList extends InstructionNode public InstructionList ( final Origin origin, - final List instructions + final List instructions ) { super(origin); @@ -37,7 +37,7 @@ public class InstructionList extends InstructionNode nv.visit_instruction_list(this); } - public List get_instructions () + public List get_instructions () { return instructions; } @@ -52,7 +52,7 @@ public class InstructionList extends InstructionNode sb.append(System.lineSeparator()); - for (final InstructionNode instruction: instructions) + for (final Instruction instruction: instructions) { sb.append(instruction.toString()); sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/MacroCall.java b/src/core/src/tonkadur/fate/v1/lang/instruction/MacroCall.java index 95a1d51..3588f65 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/MacroCall.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/MacroCall.java @@ -19,16 +19,16 @@ import tonkadur.fate.v1.lang.Macro; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class MacroCall extends InstructionNode +public class MacroCall extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ protected final Macro macro; - protected final List parameters; + protected final List parameters; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -38,7 +38,7 @@ public class MacroCall extends InstructionNode ( final Origin origin, final Macro macro, - final List parameters + final List parameters ) { super(origin); @@ -55,7 +55,7 @@ public class MacroCall extends InstructionNode ( final Origin origin, final Macro macro, - final List parameters + final List parameters ) throws Throwable { @@ -78,10 +78,10 @@ public class MacroCall extends InstructionNode ); } - (new Merge() + (new Merge() { @Override - public Boolean risky_lambda (final Type t, final ValueNode p) + public Boolean risky_lambda (final Type t, final Computation p) throws ParsingError { if ((t == null) || (p == null)) @@ -148,7 +148,7 @@ public class MacroCall extends InstructionNode return macro; } - public List get_parameters () + public List get_parameters () { return parameters; } @@ -162,7 +162,7 @@ public class MacroCall extends InstructionNode sb.append("(MacroCall ("); sb.append(macro.get_name()); - for (final ValueNode param: parameters) + for (final Computation param: parameters) { sb.append(" "); sb.append(param.toString()); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/PlayerChoice.java b/src/core/src/tonkadur/fate/v1/lang/instruction/PlayerChoice.java index e57fe2a..fdebb80 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/PlayerChoice.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/PlayerChoice.java @@ -7,16 +7,16 @@ import tonkadur.parser.Origin; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.Instruction; import tonkadur.fate.v1.lang.meta.RichTextNode; -public class PlayerChoice extends InstructionNode +public class PlayerChoice extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ protected final RichTextNode text; - protected final List effects; + protected final List effects; /***************************************************************************/ /**** PUBLIC ***************************************************************/ @@ -26,7 +26,7 @@ public class PlayerChoice extends InstructionNode ( final Origin origin, final RichTextNode text, - final List effects + final List effects ) { super(origin); @@ -49,7 +49,7 @@ public class PlayerChoice extends InstructionNode return text; } - public List get_effects () + public List get_effects () { return effects; } @@ -64,7 +64,7 @@ public class PlayerChoice extends InstructionNode sb.append(System.lineSeparator()); sb.append(text.toString()); - for (final InstructionNode effect: effects) + for (final Instruction effect: effects) { sb.append(System.lineSeparator()); sb.append(effect.toString()); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/PlayerChoiceList.java b/src/core/src/tonkadur/fate/v1/lang/instruction/PlayerChoiceList.java index 3efb72f..f9841fd 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/PlayerChoiceList.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/PlayerChoiceList.java @@ -5,14 +5,14 @@ import java.util.List; import tonkadur.parser.Origin; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.Instruction; -public class PlayerChoiceList extends InstructionNode +public class PlayerChoiceList extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final List choices; + protected final List choices; /***************************************************************************/ /**** PUBLIC ***************************************************************/ @@ -21,7 +21,7 @@ public class PlayerChoiceList extends InstructionNode public PlayerChoiceList ( final Origin origin, - final List choices + final List choices ) { super(origin); @@ -37,7 +37,7 @@ public class PlayerChoiceList extends InstructionNode nv.visit_player_choice_list(this); } - public List get_choices () + public List get_choices () { return choices; } @@ -52,7 +52,7 @@ public class PlayerChoiceList extends InstructionNode sb.append(System.lineSeparator()); - for (final InstructionNode choice: choices) + for (final Instruction choice: choices) { sb.append(choice.toString()); sb.append(System.lineSeparator()); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java index 5e51e8c..f8568a0 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java @@ -12,16 +12,16 @@ import tonkadur.fate.v1.lang.type.CollectionType; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class RemoveAllOfElement extends InstructionNode +public class RemoveAllOfElement extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final ValueNode element; - protected final ValueNode collection; + protected final Computation element; + protected final Computation collection; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -30,8 +30,8 @@ public class RemoveAllOfElement extends InstructionNode protected RemoveAllOfElement ( final Origin origin, - final ValueNode element, - final ValueNode collection + final Computation element, + final Computation collection ) { super(origin); @@ -47,8 +47,8 @@ public class RemoveAllOfElement extends InstructionNode public static RemoveAllOfElement build ( final Origin origin, - final ValueNode element, - final ValueNode collection + final Computation element, + final Computation collection ) throws InvalidTypeException, diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java index 3ae0122..bc93e6a 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java @@ -12,16 +12,16 @@ import tonkadur.fate.v1.lang.type.CollectionType; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class RemoveElement extends InstructionNode +public class RemoveElement extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final ValueNode element; - protected final ValueNode collection; + protected final Computation element; + protected final Computation collection; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -30,8 +30,8 @@ public class RemoveElement extends InstructionNode protected RemoveElement ( final Origin origin, - final ValueNode element, - final ValueNode collection + final Computation element, + final Computation collection ) { super(origin); @@ -47,8 +47,8 @@ public class RemoveElement extends InstructionNode public static RemoveElement build ( final Origin origin, - final ValueNode element, - final ValueNode collection + final Computation element, + final Computation collection ) throws InvalidTypeException, diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java index a1be965..fefe8d8 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java @@ -3,9 +3,9 @@ package tonkadur.fate.v1.lang.instruction; import tonkadur.parser.Origin; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.Instruction; -public class SequenceCall extends InstructionNode +public class SequenceCall extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/SetValue.java b/src/core/src/tonkadur/fate/v1/lang/instruction/SetValue.java index f0aa20c..1d840e6 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/SetValue.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/SetValue.java @@ -11,16 +11,16 @@ import tonkadur.fate.v1.error.InvalidTypeException; import tonkadur.fate.v1.lang.type.Type; import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.InstructionNode; -import tonkadur.fate.v1.lang.meta.ValueNode; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; -public class SetValue extends InstructionNode +public class SetValue extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final ValueNode element; - protected final ValueNode value_reference; + protected final Computation element; + protected final Computation value_reference; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -29,8 +29,8 @@ public class SetValue extends InstructionNode protected SetValue ( final Origin origin, - final ValueNode element, - final ValueNode value_reference + final Computation element, + final Computation value_reference ) { super(origin); @@ -46,8 +46,8 @@ public class SetValue extends InstructionNode public static SetValue build ( final Origin origin, - final ValueNode element, - final ValueNode value_reference + final Computation element, + final Computation value_reference ) throws InvalidTypeException, diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java b/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java new file mode 100644 index 0000000..f7dbcd3 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java @@ -0,0 +1,47 @@ +package tonkadur.fate.v1.lang.meta; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.type.Type; + +public abstract class Computation extends Node +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Type type; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected Computation (final Origin origin, final Type type) + { + super(origin); + + this.type = type; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Accessors ************************************************************/ + public Type get_type () + { + return type; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("("); + sb.append(type.get_name()); + sb.append(" Value Node)"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionComputation.java b/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionComputation.java new file mode 100644 index 0000000..465aed7 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionComputation.java @@ -0,0 +1,39 @@ +package tonkadur.fate.v1.lang.meta; + +import java.util.List; + +import tonkadur.parser.Context; +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.World; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.meta.Computation; + +public class ExtensionComputation extends Computation +{ + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected ExtensionComputation + ( + final Origin origin, + final Type result_type + ) + { + super(origin, result_type); + } + + public ExtensionComputation build + ( + final World world, + final Context context, + final Origin origin, + final List parameters + ) + { + return new ExtensionComputation(Origin.BASE_LANGUAGE, Type.ANY); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionInstruction.java b/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionInstruction.java index 349731f..939e151 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionInstruction.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionInstruction.java @@ -9,9 +9,9 @@ import tonkadur.fate.v1.lang.World; import tonkadur.fate.v1.lang.type.Type; -import tonkadur.fate.v1.lang.meta.InstructionNode; +import tonkadur.fate.v1.lang.meta.Instruction; -public class ExtensionInstruction extends InstructionNode +public class ExtensionInstruction extends Instruction { /***************************************************************************/ /**** PUBLIC ***************************************************************/ @@ -27,7 +27,7 @@ public class ExtensionInstruction extends InstructionNode final World world, final Context context, final Origin origin, - final List parameters + final List parameters ) { return new ExtensionInstruction(Origin.BASE_LANGUAGE); diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionValueNode.java b/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionValueNode.java deleted file mode 100644 index 57addaf..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/meta/ExtensionValueNode.java +++ /dev/null @@ -1,39 +0,0 @@ -package tonkadur.fate.v1.lang.meta; - -import java.util.List; - -import tonkadur.parser.Context; -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.World; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class ExtensionValueNode extends ValueNode -{ - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected ExtensionValueNode - ( - final Origin origin, - final Type result_type - ) - { - super(origin, result_type); - } - - public ExtensionValueNode build - ( - final World world, - final Context context, - final Origin origin, - final List parameters - ) - { - return new ExtensionValueNode(Origin.BASE_LANGUAGE, Type.ANY); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/Instruction.java b/src/core/src/tonkadur/fate/v1/lang/meta/Instruction.java new file mode 100644 index 0000000..f77206a --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/meta/Instruction.java @@ -0,0 +1,60 @@ +package tonkadur.fate.v1.lang.meta; + +import java.util.Collection; +import java.util.HashSet; + +import tonkadur.parser.Origin; + +public abstract class Instruction extends Node +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Collection parents; + protected Instruction child; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected Instruction (final Origin origin) + { + super(origin); + + parents = new HashSet(); + child = null; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Accessors ************************************************************/ + public void link_parent (final Instruction parent) + { + parent.child = this; + + parents.add(parent); + } + + public Collection get_parents () + { + return parents; + } + + public Instruction get_child () + { + return child; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append("(Instruction)"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/InstructionNode.java b/src/core/src/tonkadur/fate/v1/lang/meta/InstructionNode.java deleted file mode 100644 index 3587152..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/meta/InstructionNode.java +++ /dev/null @@ -1,60 +0,0 @@ -package tonkadur.fate.v1.lang.meta; - -import java.util.Collection; -import java.util.HashSet; - -import tonkadur.parser.Origin; - -public abstract class InstructionNode extends Node -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Collection parents; - protected InstructionNode child; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected InstructionNode (final Origin origin) - { - super(origin); - - parents = new HashSet(); - child = null; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Accessors ************************************************************/ - public void link_parent (final InstructionNode parent) - { - parent.child = this; - - parents.add(parent); - } - - public Collection get_parents () - { - return parents; - } - - public InstructionNode get_child () - { - return child; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("(Instruction)"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/NodeVisitor.java b/src/core/src/tonkadur/fate/v1/lang/meta/NodeVisitor.java index 3b9527c..f294da5 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/NodeVisitor.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/NodeVisitor.java @@ -3,7 +3,7 @@ package tonkadur.fate.v1.lang.meta; import tonkadur.fate.v1.lang.World; import tonkadur.fate.v1.lang.instruction.*; -import tonkadur.fate.v1.lang.valued_node.*; +import tonkadur.fate.v1.lang.computation.*; public interface NodeVisitor { diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/Reference.java b/src/core/src/tonkadur/fate/v1/lang/meta/Reference.java index 285dac7..52f9057 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/Reference.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/Reference.java @@ -4,7 +4,7 @@ import tonkadur.parser.Origin; import tonkadur.fate.v1.lang.type.Type; -public abstract class Reference extends ValueNode +public abstract class Reference extends Computation { /***************************************************************************/ /**** MEMBERS **************************************************************/ diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/RichTextNode.java b/src/core/src/tonkadur/fate/v1/lang/meta/RichTextNode.java index 7a4a44d..1afd6fe 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/RichTextNode.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/RichTextNode.java @@ -5,7 +5,7 @@ import tonkadur.parser.Origin; import tonkadur.fate.v1.lang.type.Type; -public abstract class RichTextNode extends ValueNode +public abstract class RichTextNode extends Computation { /***************************************************************************/ /**** PROTECTED ************************************************************/ diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/ValueNode.java b/src/core/src/tonkadur/fate/v1/lang/meta/ValueNode.java deleted file mode 100644 index f1a8b64..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/meta/ValueNode.java +++ /dev/null @@ -1,47 +0,0 @@ -package tonkadur.fate.v1.lang.meta; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.type.Type; - -public abstract class ValueNode extends Node -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Type type; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected ValueNode (final Origin origin, final Type type) - { - super(origin); - - this.type = type; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Accessors ************************************************************/ - public Type get_type () - { - return type; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("("); - sb.append(type.get_name()); - sb.append(" Value Node)"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/AtReference.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/AtReference.java deleted file mode 100644 index 1a8d9a3..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/AtReference.java +++ /dev/null @@ -1,109 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.Collections; - -import tonkadur.parser.Origin; - -import tonkadur.error.ErrorManager; - -import tonkadur.fate.v1.error.InvalidTypeException; -import tonkadur.fate.v1.error.UnknownDictionaryFieldException; - -import tonkadur.fate.v1.lang.Variable; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.Reference; - -import tonkadur.fate.v1.lang.type.RefType; -import tonkadur.fate.v1.lang.type.Type; - -public class AtReference extends Reference -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Reference parent; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - protected AtReference - ( - final Origin origin, - final Type reported_type, - final Reference parent - ) - { - super(origin, reported_type, ("(At " + parent.get_name() + ")")); - - this.parent = parent; - } - /**** Constructors *********************************************************/ - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static AtReference build - ( - final Origin origin, - final Reference parent - ) - throws - InvalidTypeException - { - Type current_type; - - current_type = parent.get_type(); - - if (!(current_type instanceof RefType)) - { - ErrorManager.handle - ( - new InvalidTypeException - ( - origin, - current_type, - Collections.singleton(Type.REF), - parent.get_name() - ) - ); - - current_type = Type.ANY; - } - else - { - current_type = ((RefType) current_type).get_referenced_type(); - } - - return new AtReference(origin, current_type, parent); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_at_reference(this); - } - - public Reference get_parent () - { - return parent; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append("(AtReference ("); - sb.append(type.get_name()); - sb.append(") "); - sb.append(parent.get_name()); - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/Cast.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/Cast.java deleted file mode 100644 index 41e0ebb..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/Cast.java +++ /dev/null @@ -1,200 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import tonkadur.error.ErrorManager; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.IncompatibleTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class Cast extends ValueNode -{ - protected static final Map> allowed_type_changes; - - static - { - allowed_type_changes = new HashMap>(); - - allowed_type_changes.put - ( - Type.INT, - Type.NUMBER_TYPES - ); - - allowed_type_changes.put - ( - Type.FLOAT, - Type.NUMBER_TYPES - ); - - allowed_type_changes.put - ( - Type.DICT, - Collections.emptySet() - ); - - allowed_type_changes.put - ( - Type.SET, - Collections.emptySet() - ); - - allowed_type_changes.put - ( - Type.LIST, - Collections.emptySet() - ); - - allowed_type_changes.put - ( - Type.BOOLEAN, - Collections.emptySet() - ); - - allowed_type_changes.put - ( - Type.ANY, - Collections.singleton(Type.ANY) - ); - - allowed_type_changes.put - ( - Type.STRING, - Type.SIMPLE_BASE_TYPES - ); - } - - public static Collection get_allowed_casts_to (final Type t) - { - return allowed_type_changes.get(t); - } - - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final ValueNode value; - protected final boolean is_autogenerated; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected Cast - ( - final Origin origin, - final Type to, - final ValueNode value, - final boolean is_autogenerated - ) - { - super(origin, to); - this.value = value; - this.is_autogenerated = is_autogenerated; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static Cast build - ( - final Origin origin, - final Type to, - final ValueNode value, - final boolean is_autogenerated - ) - throws - IncompatibleTypeException, - IncomparableTypeException - { - final Type hint; - - if - ( - (value.get_type().can_be_used_as(to)) - || - ( - (to.is_base_type()) - && - ( - allowed_type_changes.get(to).contains - ( - value.get_type().get_base_type() - ) - ) - ) - ) - { - return new Cast(origin, to, value, is_autogenerated); - } - - hint = (Type) value.get_type().generate_comparable_to(to); - - if (hint.equals(Type.ANY)) - { - ErrorManager.handle - ( - new IncompatibleTypeException(origin, value.get_type(), to) - ); - - ErrorManager.handle - ( - new IncomparableTypeException(origin, value.get_type(), to) - ); - } - else - { - ErrorManager.handle - ( - new IncompatibleTypeException(origin, value.get_type(), to, hint) - ); - } - - return new Cast(origin, hint, value, is_autogenerated); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_cast(this); - } - - public ValueNode get_parent () - { - return value; - } - - public boolean is_autogenerated () - { - return is_autogenerated; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("(Cast ("); - sb.append(type.get_name()); - sb.append(") "); - sb.append(value.toString()); - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/CondValue.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/CondValue.java deleted file mode 100644 index 60b60c3..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/CondValue.java +++ /dev/null @@ -1,156 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.List; -import java.util.Collections; - -import tonkadur.functional.Cons; - -import tonkadur.error.ErrorManager; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class CondValue extends ValueNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final List> branches; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected CondValue - ( - final Origin origin, - final Type return_type, - final List> branches - ) - { - super(origin, return_type); - - this.branches = branches; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static CondValue build - ( - final Origin origin, - final List> branches - ) - throws - InvalidTypeException, - ConflictingTypeException, - IncomparableTypeException - { - final Type first_type; - Type candidate_hint, hint; - - first_type = branches.get(0).get_cdr().get_type(); - hint = first_type; - - for (final Cons entry: branches) - { - if (!entry.get_car().get_type().can_be_used_as(Type.BOOLEAN)) - { - ErrorManager.handle - ( - new InvalidTypeException - ( - entry.get_car().get_origin(), - entry.get_car().get_type(), - Collections.singleton(Type.BOOLEAN) - ) - ); - } - - if (entry.get_cdr().get_type().equals(hint)) - { - continue; - } - - candidate_hint = entry.get_cdr().get_type().try_merging_with(hint); - - if (candidate_hint != null) - { - hint = candidate_hint; - - continue; - } - - ErrorManager.handle - ( - new ConflictingTypeException - ( - entry.get_cdr().get_origin(), - entry.get_cdr().get_type(), - first_type - ) - ); - - hint = (Type) hint.generate_comparable_to(entry.get_cdr().get_type()); - - if (hint.equals(Type.ANY)) - { - ErrorManager.handle - ( - new IncomparableTypeException - ( - entry.get_cdr().get_origin(), - entry.get_cdr().get_type(), - first_type - ) - ); - } - } - - return new CondValue(origin, hint, branches); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_cond_value(this); - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("(CondValue"); - sb.append(System.lineSeparator()); - - for (final Cons entry: branches) - { - sb.append(System.lineSeparator()); - sb.append("Condition:"); - sb.append(System.lineSeparator()); - sb.append(entry.get_car().toString()); - sb.append(System.lineSeparator()); - sb.append("Value:"); - sb.append(entry.get_cdr().toString()); - sb.append(System.lineSeparator()); - } - - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/Constant.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/Constant.java deleted file mode 100644 index abfe38d..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/Constant.java +++ /dev/null @@ -1,110 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class Constant extends ValueNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final String as_string; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected Constant - ( - final Origin origin, - final Type result_type, - final String as_string - ) - { - super(origin, result_type); - - this.as_string = as_string; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static Constant build_boolean - ( - final Origin origin, - final boolean value - ) - { - return new Constant(origin, Type.BOOLEAN, value ? "true" : "false"); - } - - public static Constant build_string - ( - final Origin origin, - final String value - ) - { - return new Constant(origin, Type.STRING, value); - } - - public static Constant build (final Origin origin, final String as_string) - { - try - { - Integer.valueOf(as_string); - - return new Constant(origin, Type.INT, as_string); - } - catch (final NumberFormatException nfe) - { - /* That's fine, we're just testing... */ - } - - try - { - Float.valueOf(as_string); - - return new Constant(origin, Type.FLOAT, as_string); - } - catch (final NumberFormatException nfe) - { - /* That's fine, we're just testing... */ - } - - return new Constant(origin, Type.STRING, as_string); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_constant(this); - } - - public String get_value_as_string () - { - return as_string; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("("); - sb.append(type.get_name()); - sb.append(" Constant "); - sb.append(as_string); - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/CountOperator.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/CountOperator.java deleted file mode 100644 index cbf014c..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/CountOperator.java +++ /dev/null @@ -1,159 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import tonkadur.error.ErrorManager; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.CollectionType; -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class CountOperator extends ValueNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final ValueNode element; - protected final ValueNode collection; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected CountOperator - ( - final Origin origin, - final ValueNode element, - final ValueNode collection - ) - { - super(origin, Type.INT); - - this.collection = collection; - this.element = element; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static CountOperator build - ( - final Origin origin, - final ValueNode element, - final ValueNode collection - ) - throws - InvalidTypeException, - ConflictingTypeException, - IncomparableTypeException - { - final Type hint; - final Type collection_type; - final CollectionType collection_true_type; - final Type collection_element_type; - - collection_type = collection.get_type(); - - if - ( - !Type.COLLECTION_TYPES.contains(collection_type.get_base_type()) - || !(collection_type instanceof CollectionType) - ) - { - ErrorManager.handle - ( - new InvalidTypeException - ( - collection.get_origin(), - collection.get_type(), - Type.COLLECTION_TYPES - ) - ); - } - - collection_true_type = (CollectionType) collection_type; - collection_element_type = collection_true_type.get_content_type(); - - if - ( - element.get_type().can_be_used_as(collection_element_type) - || - (element.get_type().try_merging_with(collection_element_type) != null) - ) - { - return new CountOperator(origin, element, collection); - } - - ErrorManager.handle - ( - new ConflictingTypeException - ( - element.get_origin(), - element.get_type(), - collection_element_type - ) - ); - - hint = - (Type) element.get_type().generate_comparable_to - ( - collection_element_type - ); - - if (hint.equals(Type.ANY)) - { - ErrorManager.handle - ( - new IncomparableTypeException - ( - element.get_origin(), - element.get_type(), - collection_element_type - ) - ); - } - - return new CountOperator(origin, element, collection); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_count_operator(this); - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("(CountOperator"); - sb.append(System.lineSeparator()); - sb.append(System.lineSeparator()); - - sb.append("element:"); - sb.append(System.lineSeparator()); - sb.append(element.toString()); - sb.append(System.lineSeparator()); - sb.append(System.lineSeparator()); - - sb.append("collection:"); - sb.append(System.lineSeparator()); - sb.append(collection.toString()); - - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/FieldReference.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/FieldReference.java deleted file mode 100644 index ac855bc..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/FieldReference.java +++ /dev/null @@ -1,149 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.Collections; -import java.util.List; - -import tonkadur.parser.Origin; - -import tonkadur.error.ErrorManager; - -import tonkadur.fate.v1.error.InvalidTypeException; -import tonkadur.fate.v1.error.UnknownDictionaryFieldException; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.Reference; - -import tonkadur.fate.v1.lang.type.DictType; -import tonkadur.fate.v1.lang.type.Type; - -public class FieldReference extends Reference -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Reference parent; - protected final String field_name; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected FieldReference - ( - final Origin origin, - final Reference parent, - final Type type, - final String field_name - ) - { - super(origin, type, (parent.get_name() + "." + field_name)); - - this.parent = parent; - this.field_name = field_name; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static FieldReference build - ( - final Origin origin, - Reference parent, - final String field - ) - throws - InvalidTypeException, - UnknownDictionaryFieldException - { - Type current_type; - - current_type = parent.get_type(); - - if (current_type.get_base_type().equals(Type.REF)) - { - parent = AtReference.build(origin, parent); - current_type = parent.get_type(); - } - - if (!(current_type instanceof DictType)) - { - ErrorManager.handle - ( - new InvalidTypeException - ( - origin, - current_type, - Collections.singleton(Type.DICT), - parent.get_name() - ) - ); - - current_type = Type.ANY; - } - else - { - current_type = ((DictType) current_type).get_field_type(origin, field); - } - - return new FieldReference(origin, parent, current_type, field); - } - - public static FieldReference build - ( - final Origin origin, - Reference parent, - final List field_sequence - ) - throws - InvalidTypeException, - UnknownDictionaryFieldException - { - for (final String field: field_sequence) - { - parent = build(origin, parent, field); - } - - if (parent instanceof FieldReference) - { - return (FieldReference) parent; - } - else - { - return null; - } - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_field_reference(this); - } - - public String get_field_name () - { - return field_name; - } - - public Reference get_parent () - { - return parent; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append("(FieldReference ("); - sb.append(type.get_name()); - sb.append(") "); - sb.append(name); - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/IfElseValue.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/IfElseValue.java deleted file mode 100644 index 8850966..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/IfElseValue.java +++ /dev/null @@ -1,164 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.Collections; - -import tonkadur.error.ErrorManager; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class IfElseValue extends ValueNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final ValueNode condition; - protected final ValueNode if_true; - protected final ValueNode if_false; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected IfElseValue - ( - final Origin origin, - final Type return_type, - final ValueNode condition, - final ValueNode if_true, - final ValueNode if_false - ) - { - super(origin, return_type); - - this.condition = condition; - this.if_true = if_true; - this.if_false = if_false; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static IfElseValue build - ( - final Origin origin, - final ValueNode condition, - final ValueNode if_true, - final ValueNode if_false - ) - throws - InvalidTypeException, - ConflictingTypeException, - IncomparableTypeException - { - Type hint; - final Type if_true_type; - final Type if_false_type; - - if (!condition.get_type().can_be_used_as(Type.BOOLEAN)) - { - ErrorManager.handle - ( - new InvalidTypeException - ( - condition.get_origin(), - condition.get_type(), - Collections.singleton(Type.BOOLEAN) - ) - ); - } - - if_true_type = if_true.get_type(); - if_false_type = if_false.get_type(); - - if (if_true_type.equals(if_false_type)) - { - return - new IfElseValue(origin, if_true_type, condition, if_true, if_false); - } - - hint = if_true_type.try_merging_with(if_false_type); - - if (hint != null) - { - return new IfElseValue(origin, hint, condition, if_true, if_false); - } - - ErrorManager.handle - ( - new ConflictingTypeException - ( - if_false.get_origin(), - if_false_type, - if_true_type - ) - ); - - hint = - (Type) if_false_type.generate_comparable_to(if_true_type); - - if (hint.equals(Type.ANY)) - { - ErrorManager.handle - ( - new IncomparableTypeException - ( - if_false.get_origin(), - if_false_type, - if_true_type - ) - ); - } - - return new IfElseValue(origin, hint, condition, if_true, if_false); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_if_else_value(this); - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("(IfElseValue"); - sb.append(System.lineSeparator()); - sb.append(System.lineSeparator()); - - sb.append("Condition:"); - sb.append(System.lineSeparator()); - sb.append(condition.toString()); - - sb.append(System.lineSeparator()); - sb.append(System.lineSeparator()); - sb.append("If true:"); - sb.append(System.lineSeparator()); - sb.append(if_true.toString()); - - sb.append(System.lineSeparator()); - sb.append(System.lineSeparator()); - sb.append("If false:"); - sb.append(System.lineSeparator()); - sb.append(if_false.toString()); - - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/IsMemberOperator.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/IsMemberOperator.java deleted file mode 100644 index e4411ce..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/IsMemberOperator.java +++ /dev/null @@ -1,159 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import tonkadur.error.ErrorManager; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.CollectionType; -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class IsMemberOperator extends ValueNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final ValueNode element; - protected final ValueNode collection; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected IsMemberOperator - ( - final Origin origin, - final ValueNode element, - final ValueNode collection - ) - { - super(origin, Type.BOOLEAN); - - this.collection = collection; - this.element = element; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static IsMemberOperator build - ( - final Origin origin, - final ValueNode element, - final ValueNode collection - ) - throws - InvalidTypeException, - ConflictingTypeException, - IncomparableTypeException - { - final Type hint; - final Type collection_type; - final CollectionType collection_true_type; - final Type collection_element_type; - - collection_type = collection.get_type(); - - if - ( - !Type.COLLECTION_TYPES.contains(collection_type.get_base_type()) - || !(collection_type instanceof CollectionType) - ) - { - ErrorManager.handle - ( - new InvalidTypeException - ( - collection.get_origin(), - collection.get_type(), - Type.COLLECTION_TYPES - ) - ); - } - - collection_true_type = (CollectionType) collection_type; - collection_element_type = collection_true_type.get_content_type(); - - if - ( - element.get_type().can_be_used_as(collection_element_type) - || - (element.get_type().try_merging_with(collection_element_type) != null) - ) - { - return new IsMemberOperator(origin, element, collection); - } - - ErrorManager.handle - ( - new ConflictingTypeException - ( - element.get_origin(), - element.get_type(), - collection_element_type - ) - ); - - hint = - (Type) element.get_type().generate_comparable_to - ( - collection_element_type - ); - - if (hint.equals(Type.ANY)) - { - ErrorManager.handle - ( - new IncomparableTypeException - ( - element.get_origin(), - element.get_type(), - collection_element_type - ) - ); - } - - return new IsMemberOperator(origin, element, collection); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_is_member_operator(this); - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("(IsMemberOperator"); - sb.append(System.lineSeparator()); - sb.append(System.lineSeparator()); - - sb.append("element:"); - sb.append(System.lineSeparator()); - sb.append(element.toString()); - sb.append(System.lineSeparator()); - sb.append(System.lineSeparator()); - - sb.append("collection:"); - sb.append(System.lineSeparator()); - sb.append(collection.toString()); - - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/MacroValueCall.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/MacroValueCall.java deleted file mode 100644 index 32e29ef..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/MacroValueCall.java +++ /dev/null @@ -1,193 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.ArrayList; -import java.util.List; - -import tonkadur.parser.Origin; -import tonkadur.parser.ParsingError; - -import tonkadur.functional.Merge; - -import tonkadur.error.ErrorManager; - -import tonkadur.fate.v1.error.IncompatibleTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidArityException; -import tonkadur.fate.v1.error.NotAValueMacroException; - -import tonkadur.fate.v1.lang.Macro; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class MacroValueCall extends ValueNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Macro macro; - protected final ValueNode act_as; - protected final List parameters; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected MacroValueCall - ( - final Origin origin, - final Macro macro, - final List parameters, - final ValueNode act_as - ) - { - super(origin, act_as.get_type()); - - this.macro = macro; - this.parameters = parameters; - this.act_as = act_as; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static MacroValueCall build - ( - final Origin origin, - final Macro macro, - final List parameters - ) - throws Throwable - { - ValueNode act_as; - final List signature; - - act_as = macro.get_value_node_representation(); - - if (act_as == null) - { - ErrorManager.handle - ( - new NotAValueMacroException(origin, macro.get_name()) - ); - } - - signature = macro.get_signature(); - - if (parameters.size() != signature.size()) - { - ErrorManager.handle - ( - new InvalidArityException - ( - origin, - parameters.size(), - signature.size(), - signature.size() - ) - ); - } - - (new Merge() - { - @Override - public Boolean risky_lambda (final Type t, final ValueNode p) - throws ParsingError - { - if ((t == null) || (p == null)) - { - return Boolean.FALSE; - } - else - { - final Type hint; - - if (p.get_type().can_be_used_as(t)) - { - return Boolean.TRUE; - } - - if (p.get_type().try_merging_with(t) != null) - { - return Boolean.TRUE; - } - - ErrorManager.handle - ( - new IncompatibleTypeException - ( - p.get_origin(), - p.get_type(), - t - ) - ); - - hint = (Type) p.get_type().generate_comparable_to(t); - - if (hint.equals(Type.ANY)) - { - ErrorManager.handle - ( - new IncomparableTypeException - ( - p.get_origin(), - p.get_type(), - t - ) - ); - } - - return Boolean.FALSE; - } - } - }).risky_merge(signature, parameters); - - return new MacroValueCall(origin, macro, parameters, act_as); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_macro_value_call(this); - } - - public Macro get_macro () - { - return macro; - } - - public ValueNode get_actual_value_node () - { - return act_as; - } - - public List get_parameters () - { - return parameters; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append("(MacroValueCall ("); - sb.append(macro.get_name()); - - for (final ValueNode param: parameters) - { - sb.append(" "); - sb.append(param.toString()); - } - - sb.append("))"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/Newline.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/Newline.java deleted file mode 100644 index 5698dc3..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/Newline.java +++ /dev/null @@ -1,33 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.RichTextNode; - -public class Newline extends RichTextNode -{ - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public Newline (final Origin origin) - { - super(origin); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_newline(this); - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - return "(Newline)"; - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/Operation.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/Operation.java deleted file mode 100644 index 00331df..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/Operation.java +++ /dev/null @@ -1,178 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.Collection; -import java.util.List; - -import tonkadur.error.ErrorManager; - -import tonkadur.parser.Origin; - -//import tonkadur.fate.v1.error.ConflictingTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.IncompatibleTypeException; -import tonkadur.fate.v1.error.InvalidArityException; -import tonkadur.fate.v1.error.InvalidTypeException; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class Operation extends ValueNode -{ - protected final Operator operator; - protected final List operands; - - protected Operation - ( - final Origin origin, - final Type result_type, - final Operator operator, - final List operands - ) - { - super(origin, result_type); - - this.operator = operator; - this.operands = operands; - } - - public static Operation build - ( - final Origin origin, - final Operator operator, - final List operands - ) - throws - //ConflictingTypeException, - IncomparableTypeException, - IncompatibleTypeException, - InvalidArityException, - InvalidTypeException - { - final Collection allowed_base_types; - final int operator_max_arity; - final int operator_min_arity; - final int operands_size; - Type computed_type, previous_computed_type; - - allowed_base_types = operator.get_allowed_base_types(); - operator_max_arity = operator.get_maximum_arity(); - operator_min_arity = operator.get_minimum_arity(); - operands_size = operands.size(); - - if - ( - (operands_size < operator_min_arity) - || - ( - (operator_max_arity != 0) - && (operator_max_arity < operands_size) - ) - ) - { - ErrorManager.handle - ( - new InvalidArityException - ( - origin, - operands_size, - operator_min_arity, - operator_max_arity - ) - ); - } - - computed_type = operands.get(0).get_type(); - - for (final ValueNode operand: operands) - { - final Type operand_type; - - operand_type = operand.get_type(); - - if (!allowed_base_types.contains(operand_type.get_base_type())) - { - ErrorManager.handle - ( - new InvalidTypeException - ( - operand.get_origin(), - operand_type, - allowed_base_types - ) - ); - } - - /* - - if (computed_type.equals(operand_type)) - { - continue; - } - - ErrorManager.handle - ( - new ConflictingTypeException - ( - operand.get_origin(), - operand_type, - computed_type - ) - ); - - */ - - if (operand_type.can_be_used_as(computed_type)) - { - continue; - } - - previous_computed_type = computed_type; - computed_type = computed_type.try_merging_with(operand_type); - - if (computed_type != null) - { - continue; - } - - ErrorManager.handle - ( - new IncompatibleTypeException - ( - operand.get_origin(), - operand_type, - previous_computed_type - ) - ); - - computed_type = - (Type) previous_computed_type.generate_comparable_to(operand_type); - - if (computed_type.equals(Type.ANY)) - { - ErrorManager.handle - ( - new IncomparableTypeException - ( - operand.get_origin(), - operand_type, - previous_computed_type - ) - ); - } - } - - computed_type = operator.transform_type(computed_type); - - return new Operation(origin, computed_type, operator, operands); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_operation(this); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/Operator.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/Operator.java deleted file mode 100644 index 7f1db14..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/Operator.java +++ /dev/null @@ -1,143 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.Collections; -import java.util.Set; - -import tonkadur.fate.v1.lang.type.Type; - -/* - * Yes, it *could* have been an enum. In fact, it used to be one. Except that - * unless you want to ensure coverage of all cases in a switch, Java enums are - * clearly inferior to classes in everyway. Having this be a class will, at - * the very least, let you extend it to add new operators in extensions. - */ -public class Operator -{ - public static final Operator PLUS; - public static final Operator MINUS; - public static final Operator TIMES; - public static final Operator DIVIDE; - public static final Operator POWER; - public static final Operator RANDOM; - - public static final Operator AND; - public static final Operator OR; - public static final Operator NOT; - public static final Operator IMPLIES; - public static final Operator ONE_IN; - - public static final Operator EQUALS; - - public static final Operator LOWER_THAN; - public static final Operator LOWER_EQUAL_THAN; - public static final Operator GREATER_EQUAL_THAN; - public static final Operator GREATER_THAN; - - - static - { - PLUS = new Operator("+", 2, 0, Type.NUMBER_TYPES, null); - MINUS = new Operator("-", 2, 0, Type.NUMBER_TYPES, null); - TIMES = new Operator("*", 2, 0, Type.NUMBER_TYPES, null); - DIVIDE = new Operator("/", 2, 2, Type.NUMBER_TYPES, null); - POWER = new Operator("^", 2, 2, Type.NUMBER_TYPES, null); - RANDOM = - new Operator("rand", 2, 2, Collections.singleton(Type.INT), null); - - AND = - new Operator("and", 2, 0, Collections.singleton(Type.BOOLEAN), null); - OR = - new Operator("or", 2, 0, Collections.singleton(Type.BOOLEAN), null); - NOT = - new Operator("not", 1, 1, Collections.singleton(Type.BOOLEAN), null); - IMPLIES = - new Operator - ( - "implies", - 2, - 2, - Collections.singleton(Type.BOOLEAN), - null - ); - ONE_IN = - new Operator - ( - "one_in", - 1, - 0, - Collections.singleton(Type.BOOLEAN), - null - ); - - EQUALS = - new Operator - ( - "equals", - 2, - 0, - Type.SIMPLE_BASE_TYPES, - Type.BOOLEAN - ); - - LOWER_THAN = new Operator("<", 2, 2, Type.NUMBER_TYPES, Type.BOOLEAN); - LOWER_EQUAL_THAN = - new Operator("=<", 2, 2, Type.NUMBER_TYPES, Type.BOOLEAN); - GREATER_EQUAL_THAN = - new Operator(">=", 2, 2, Type.NUMBER_TYPES, Type.BOOLEAN); - GREATER_THAN = new Operator(">", 2, 2, Type.NUMBER_TYPES, Type.BOOLEAN); - } - - final protected String name; - final protected int min_arity; - final protected int max_arity; - final protected Set valid_input_types; - final protected Type output_type_transform; - - protected Operator - ( - final String name, - final int min_arity, - final int max_arity, - final Set valid_input_types, - final Type output_type_transform - ) - { - this.name = name; - this.min_arity = min_arity; - this.max_arity = max_arity; - this.valid_input_types = valid_input_types; - - this.output_type_transform = output_type_transform; - } - - public Set get_allowed_base_types () - { - return valid_input_types; - } - - public int get_minimum_arity () - { - return min_arity; - } - - public int get_maximum_arity () - { - return max_arity; - } - - public Type transform_type (final Type in) - { - if (output_type_transform == null) - { - return in; - } - - return output_type_transform; - } - - @Override - public String toString () - { - return name; - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/Paragraph.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/Paragraph.java deleted file mode 100644 index 5b022f9..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/Paragraph.java +++ /dev/null @@ -1,67 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.List; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.RichTextNode; - -public class Paragraph extends RichTextNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final List content; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public Paragraph - ( - final Origin origin, - final List content - ) - { - super(origin); - - this.content = content; - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_paragraph(this); - } - - public List get_content () - { - return content; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append("(Paragraph "); - - for (final RichTextNode text: content) - { - sb.append(content.toString()); - } - - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/ParameterReference.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/ParameterReference.java deleted file mode 100644 index 6f6b2cf..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/ParameterReference.java +++ /dev/null @@ -1,53 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.Reference; - -import tonkadur.fate.v1.lang.type.Type; - -public class ParameterReference extends Reference -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public ParameterReference - ( - final Origin origin, - final Type reported_type, - final String parameter_name - ) - { - super(origin, reported_type, parameter_name); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_parameter_reference(this); - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("(ParameterReference ("); - sb.append(type.get_name()); - sb.append(") "); - sb.append(name); - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/RefOperator.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/RefOperator.java deleted file mode 100644 index 27f9474..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/RefOperator.java +++ /dev/null @@ -1,54 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.type.RefType; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.Reference; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class RefOperator extends ValueNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Reference referred; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public RefOperator (final Origin origin, final Reference referred) - { - super(origin, new RefType(origin, referred.get_type(), "auto generated")); - this.referred = referred; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_ref_operator(this); - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("(Ref "); - sb.append(referred.get_name()); - sb.append(") "); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/TextWithEffect.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/TextWithEffect.java deleted file mode 100644 index 457258a..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/TextWithEffect.java +++ /dev/null @@ -1,185 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import java.util.ArrayList; -import java.util.List; - -import tonkadur.parser.Origin; -import tonkadur.parser.ParsingError; - -import tonkadur.functional.Merge; - -import tonkadur.error.ErrorManager; - -import tonkadur.fate.v1.error.IncompatibleTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; -import tonkadur.fate.v1.error.InvalidArityException; - -import tonkadur.fate.v1.lang.TextEffect; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.RichTextNode; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class TextWithEffect extends RichTextNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final TextEffect effect; - protected final List parameters; - protected final RichTextNode text; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected TextWithEffect - ( - final Origin origin, - final TextEffect effect, - final List parameters, - final RichTextNode text - ) - { - super(origin); - - this.effect = effect; - this.parameters = parameters; - this.text = text; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static TextWithEffect build - ( - final Origin origin, - final TextEffect effect, - final List parameters, - final RichTextNode text - ) - throws Throwable - { - final List signature; - - signature = effect.get_signature(); - - if (parameters.size() != signature.size()) - { - ErrorManager.handle - ( - new InvalidArityException - ( - origin, - parameters.size(), - signature.size(), - signature.size() - ) - ); - } - - (new Merge() - { - @Override - public Boolean risky_lambda (final Type t, final ValueNode p) - throws ParsingError - { - if ((t == null) || (p == null)) - { - return Boolean.FALSE; - } - else - { - final Type hint; - - if (p.get_type().can_be_used_as(t)) - { - return Boolean.TRUE; - } - - if (p.get_type().try_merging_with(t) != null) - { - return Boolean.TRUE; - } - - ErrorManager.handle - ( - new IncompatibleTypeException - ( - p.get_origin(), - p.get_type(), - t - ) - ); - - hint = (Type) p.get_type().generate_comparable_to(t); - - if (hint.equals(Type.ANY)) - { - ErrorManager.handle - ( - new IncomparableTypeException - ( - p.get_origin(), - p.get_type(), - t - ) - ); - } - - return Boolean.FALSE; - } - } - }).risky_merge(signature, parameters); - - return new TextWithEffect(origin, effect, parameters, text); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_text_with_effect(this); - } - - public TextEffect get_effect () - { - return effect; - } - - public List get_parameters () - { - return parameters; - } - - public RichTextNode get_text () - { - return text; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append("(TextWithEffect ("); - sb.append(effect.get_name()); - - for (final ValueNode param: parameters) - { - sb.append(" "); - sb.append(param.toString()); - } - - sb.append(") "); - sb.append(text.toString()); - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/ValueToRichText.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/ValueToRichText.java deleted file mode 100644 index 1a84986..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/ValueToRichText.java +++ /dev/null @@ -1,88 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.error.IncompatibleTypeException; -import tonkadur.fate.v1.error.IncomparableTypeException; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.RichTextNode; -import tonkadur.fate.v1.lang.meta.ValueNode; - -public class ValueToRichText extends RichTextNode -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final ValueNode value; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected ValueToRichText (final ValueNode value) - { - super(value.get_origin()); - - this.value = value; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static ValueToRichText build (final ValueNode value) - throws - IncompatibleTypeException, - IncomparableTypeException - { - final Type value_base_type; - - value_base_type = value.get_type().get_base_type(); - - if (value_base_type.equals(Type.STRING)) - { - return new ValueToRichText(value); - } - - return - new ValueToRichText - ( - Cast.build - ( - value.get_origin(), - Type.STRING, - value, - true - ) - ); - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_value_to_rich_text(this); - } - - public ValueNode get_value () - { - return value; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append("(ValueToRichText "); - sb.append(value.toString()); - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/valued_node/VariableReference.java b/src/core/src/tonkadur/fate/v1/lang/valued_node/VariableReference.java deleted file mode 100644 index 877bcf1..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/valued_node/VariableReference.java +++ /dev/null @@ -1,76 +0,0 @@ -package tonkadur.fate.v1.lang.valued_node; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.Variable; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; -import tonkadur.fate.v1.lang.meta.Reference; - -import tonkadur.fate.v1.lang.type.Type; - -public class VariableReference extends Reference -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Variable variable; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - protected VariableReference - ( - final Origin origin, - final Type reported_type, - final Variable variable - ) - { - super(origin, reported_type, variable.get_name()); - this.variable = variable; - } - /**** Constructors *********************************************************/ - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public VariableReference - ( - final Origin origin, - final Variable variable - ) - { - super(origin, variable.get_type(), variable.get_name()); - this.variable = variable; - } - - /**** Accessors ************************************************************/ - @Override - public void visit (final NodeVisitor nv) - throws Throwable - { - nv.visit_variable_reference(this); - } - - public Variable get_variable () - { - return variable; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append("(VariableReference ("); - sb.append(type.get_name()); - sb.append(") "); - sb.append(variable.get_name()); - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index f9d9638..b77ad98 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -35,7 +35,7 @@ options import tonkadur.fate.v1.lang.instruction.*; import tonkadur.fate.v1.lang.meta.*; import tonkadur.fate.v1.lang.type.*; - import tonkadur.fate.v1.lang.valued_node.*; + import tonkadur.fate.v1.lang.computation.*; } @members @@ -76,10 +76,10 @@ fate_file [Context context, World world] ; general_fate_sequence -returns [List result] +returns [List result] @init { - $result = new ArrayList(); + $result = new ArrayList(); } : (WS* @@ -556,7 +556,7 @@ catch [final Throwable e] /* Trying to get rule priorities right */ general_fate_instr -returns [InstructionNode result] +returns [Instruction result] : L_PAREN WS+ general_fate_sequence WS* R_PAREN { @@ -649,7 +649,7 @@ returns [InstructionNode result] | SET_FIELDS_KW value_reference WS* field_value_list WS* R_PAREN { final Origin origin; - final List operations; + final List operations; origin = CONTEXT.get_origin_at @@ -658,11 +658,11 @@ returns [InstructionNode result] ($SET_FIELDS_KW.getCharPositionInLine()) ); - operations = new ArrayList(); + operations = new ArrayList(); for ( - final Cons> entry: + final Cons> entry: ($field_value_list.result) ) { @@ -727,7 +727,7 @@ returns [InstructionNode result] ( origin, event, - new ArrayList() + new ArrayList() ); } @@ -907,10 +907,10 @@ catch [final Throwable e] } instr_cond_list -returns [List> result] +returns [List> result] @init { - $result = new ArrayList>(); + $result = new ArrayList>(); } : ( @@ -925,10 +925,10 @@ returns [List> result] ; player_choice_list -returns [List result] +returns [List result] @init { - $result = new ArrayList(); + $result = new ArrayList(); } : (WS* @@ -942,7 +942,7 @@ returns [List result] ; player_choice -returns [InstructionNode result] +returns [Instruction result] : start_p=L_PAREN WS* L_PAREN WS* paragraph WS* R_PAREN WS+ @@ -1024,10 +1024,10 @@ catch [final Throwable e] } player_choice_cond_list -returns [List> result] +returns [List> result] @init { - $result = new ArrayList>(); + $result = new ArrayList>(); } : ( @@ -1148,7 +1148,7 @@ returns [RichTextNode result]: ($WORD.getCharPositionInLine()) ), effect, - new ArrayList(), + new ArrayList(), ($paragraph.result) ); } @@ -1356,10 +1356,10 @@ catch [final Throwable e] } field_value_list -returns [List>> result] +returns [List>> result] @init { - $result = new ArrayList>>(); + $result = new ArrayList>>(); } : ( @@ -1428,7 +1428,7 @@ catch [final Throwable e] /**** VALUES ******************************************************************/ /******************************************************************************/ boolean_expression -returns [ValueNode result]: +returns [Computation result]: TRUE_KW { $result = @@ -1635,7 +1635,7 @@ catch [final Throwable e] } math_expression -returns [ValueNode result]: +returns [Computation result]: PLUS_KW value_list WS* R_PAREN { $result = @@ -1754,7 +1754,7 @@ catch [final Throwable e] } value -returns [ValueNode result] +returns [Computation result] : WORD { @@ -1799,7 +1799,7 @@ returns [ValueNode result] ($WORD.getCharPositionInLine()) ), effect, - new ArrayList(), + new ArrayList(), ($paragraph.result) ); } @@ -1870,7 +1870,7 @@ catch [final Throwable e] } non_text_value -returns [ValueNode result] +returns [Computation result] : IF_ELSE_KW cond=value WS+ if_true=value WS+ if_false=value WS* R_PAREN { @@ -1957,7 +1957,7 @@ returns [ValueNode result] | EXTENSION_VALUE_KW WORD WS+ value_list WS* R_PAREN { final Origin origin; - final ExtensionValueNode value; + final ExtensionComputation value; origin = CONTEXT.get_origin_at @@ -2231,10 +2231,10 @@ catch [final Throwable e] } value_cond_list -returns [List> result] +returns [List> result] @init { - $result = new ArrayList>(); + $result = new ArrayList>(); } : ( @@ -2248,10 +2248,10 @@ returns [List> result] ; value_list -returns [List result] +returns [List result] @init { - $result = new ArrayList(); + $result = new ArrayList(); } : ( 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 new file mode 100644 index 0000000..39707da --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java @@ -0,0 +1,104 @@ +package tonkadur.wyrd.v1.compiler.fate.v1; + +import tonkadur.error.Error; + +import tonkadur.wyrd.v1.lang.World; + +public class Compiler +{ + /* Utility Class */ + private Compiler () { } + + public static World compile (final tonkadur.fate.v1.lang.World fate_world) + throws Error + { + final World wyrd_world; + + wyrd_world = new World(); + + compile_extensions(fate_world, wyrd_world); + compile_types(fate_world, wyrd_world); + compile_variables(fate_world, wyrd_world); + compile_sequences(fate_world, wyrd_world); + compile_main_sequence(fate_world, wyrd_world); + + return wyrd_world; + } + + protected static void compile_extensions + ( + final tonkadur.fate.v1.lang.World fate_world, + final World wyrd_world + ) + { + for (final String extension: fate_world.get_required_extensions()) + { + wyrd_world.add_required_extension(extension); + } + } + + protected static void compile_types + ( + final tonkadur.fate.v1.lang.World fate_world, + final World wyrd_world + ) + throws Error + { + for + ( + final tonkadur.fate.v1.lang.type.Type type: + fate_world.types().get_all() + ) + { + TypeCompiler.compile(type, wyrd_world); + } + } + + protected static void compile_variables + ( + final tonkadur.fate.v1.lang.World fate_world, + final World wyrd_world + ) + throws Error + { + for + ( + final tonkadur.fate.v1.lang.Variable variable: + fate_world.variables().get_all() + ) + { + VariableCompiler.compile(variable, wyrd_world); + } + } + + protected static void compile_sequences + ( + final tonkadur.fate.v1.lang.World fate_world, + final World wyrd_world + ) + throws Error + { + for + ( + final tonkadur.fate.v1.lang.Sequence sequence: + fate_world.sequences().get_all() + ) + { + SequenceCompiler.compile(sequence, wyrd_world); + } + } + + protected static void compile_main_sequence + ( + final tonkadur.fate.v1.lang.World fate_world, + final World wyrd_world + ) + throws Error + { + SequenceCompiler.compile_main_sequence + ( + fate_world.get_global_instructions(), + wyrd_world + ); + } +} 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 new file mode 100644 index 0000000..af82748 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java @@ -0,0 +1,190 @@ +package tonkadur.wyrd.v1.compiler.fate.v1; + +import tonkadur.error.Error; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.World; + +public class ComputationCompiler extends FateVisitor +{ + protected final World wyrd_world; + protected final List pre_computation_instructions; + + public ComputationCompiler (final World wyrd_world) + { + this.wyrd_world = wyrd_world; + + pre_computation_instructions = new ArrayList(); + } + + @Override + public void visit_at_reference + ( + final tonkadur.fate.v1.lang.valued_node.AtReference n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_cast + ( + final tonkadur.fate.v1.lang.valued_node.Cast n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_cond_value + ( + final tonkadur.fate.v1.lang.valued_node.CondValue n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_constant + ( + final tonkadur.fate.v1.lang.valued_node.Constant n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_count_operator + ( + final tonkadur.fate.v1.lang.valued_node.CountOperator n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_field_reference + ( + final tonkadur.fate.v1.lang.valued_node.FieldReference n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_if_else_value + ( + final tonkadur.fate.v1.lang.valued_node.IfElseValue n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_is_member_operator + ( + final tonkadur.fate.v1.lang.valued_node.IsMemberOperator n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_macro_value_call + ( + final tonkadur.fate.v1.lang.valued_node.MacroValueCall n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_newline + ( + final tonkadur.fate.v1.lang.valued_node.Newline n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_operation + ( + final tonkadur.fate.v1.lang.valued_node.Operation n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_paragraph + ( + final tonkadur.fate.v1.lang.valued_node.Paragraph n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_parameter_reference + ( + final tonkadur.fate.v1.lang.valued_node.ParameterReference n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_ref_operator + ( + final tonkadur.fate.v1.lang.valued_node.RefOperator n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_text_with_effect + ( + final tonkadur.fate.v1.lang.valued_node.TextWithEffect n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_value_to_rich_text + ( + final tonkadur.fate.v1.lang.valued_node.ValueToRichText n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_variable_reference + ( + final tonkadur.fate.v1.lang.valued_node.VariableReference n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/FateVisitor.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/FateVisitor.java new file mode 100644 index 0000000..c84d5e7 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/FateVisitor.java @@ -0,0 +1,298 @@ +package tonkadur.wyrd.v1.compiler.fate.v1; + +import tonkadur.wyrd.v1.error.UnhandledASTElementException; + +import tonkadur.fate.v1.lang.meta.NodeVisitor; + +public abstract class FateVisitor implements NodeVisitor +{ + /* Instruction Nodes */ + public void visit_add_element + ( + final tonkadur.fate.v1.lang.instruction.AddElement ae + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_assert (final tonkadur.fate.v1.lang.instruction.Assert a) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_clear (final tonkadur.fate.v1.lang.instruction.Clear c) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_cond_instruction + ( + final tonkadur.fate.v1.lang.instruction.CondInstruction ci + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_display (final tonkadur.fate.v1.lang.instruction.Display n) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_event_call + ( + final tonkadur.fate.v1.lang.instruction.EventCall n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_if_else_instruction + ( + final tonkadur.fate.v1.lang.instruction.IfElseInstruction n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_if_instruction + ( + final tonkadur.fate.v1.lang.instruction.IfInstruction n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_instruction_list + ( + final tonkadur.fate.v1.lang.instruction.InstructionList n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_macro_call + ( + final tonkadur.fate.v1.lang.instruction.MacroCall n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_player_choice + ( + final tonkadur.fate.v1.lang.instruction.PlayerChoice n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_player_choice_list + ( + final tonkadur.fate.v1.lang.instruction.PlayerChoiceList n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_remove_all_of_element + ( + final tonkadur.fate.v1.lang.instruction.RemoveAllOfElement n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_remove_element + ( + final tonkadur.fate.v1.lang.instruction.RemoveElement n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_sequence_call + ( + final tonkadur.fate.v1.lang.instruction.SequenceCall n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_set_value + ( + final tonkadur.fate.v1.lang.instruction.SetValue n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + /* Valued Nodes */ + public void visit_at_reference + ( + final tonkadur.fate.v1.lang.valued_node.AtReference n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_cast + ( + final tonkadur.fate.v1.lang.valued_node.Cast n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_cond_value + ( + final tonkadur.fate.v1.lang.valued_node.CondValue n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_constant + ( + final tonkadur.fate.v1.lang.valued_node.Constant n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_count_operator + ( + final tonkadur.fate.v1.lang.valued_node.CountOperator n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_field_reference + ( + final tonkadur.fate.v1.lang.valued_node.FieldReference n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_if_else_value + ( + final tonkadur.fate.v1.lang.valued_node.IfElseValue n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_is_member_operator + ( + final tonkadur.fate.v1.lang.valued_node.IsMemberOperator n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_macro_value_call + ( + final tonkadur.fate.v1.lang.valued_node.MacroValueCall n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_newline + ( + final tonkadur.fate.v1.lang.valued_node.Newline n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_operation + ( + final tonkadur.fate.v1.lang.valued_node.Operation n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_paragraph + ( + final tonkadur.fate.v1.lang.valued_node.Paragraph n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_parameter_reference + ( + final tonkadur.fate.v1.lang.valued_node.ParameterReference n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_ref_operator + ( + final tonkadur.fate.v1.lang.valued_node.RefOperator n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_text_with_effect + ( + final tonkadur.fate.v1.lang.valued_node.TextWithEffect n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_value_to_rich_text + ( + final tonkadur.fate.v1.lang.valued_node.ValueToRichText n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + public void visit_variable_reference + ( + final tonkadur.fate.v1.lang.valued_node.VariableReference n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java new file mode 100644 index 0000000..2e49ae9 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java @@ -0,0 +1,587 @@ +package tonkadur.wyrd.v1.compiler.fate.v1; + +import tonkadur.error.Error; + +import tonkadur.wyrd.v1.lang.meta.Instruction; + +import tonkadur.wyrd.v1.lang.World; + +public class InstructionCompiler extends FateVisitor +{ + protected final AnonymousVariableManager anonymous_variables; + protected final World wyrd_world; + protected final List result; + + public InstructionCompiler + ( + final AnonymousVariableManager anonymous_variables, + final World wyrd_world + ) + { + this.anonymous_variables = anonymous_variables; + this.wyrd_world = wyrd_world; + result = new ArrayList(); + } + + public InstructionCompiler + ( + final AnonymousVariableManager anonymous_variables, + final World wyrd_world, + final List result + ) + { + this.anonymous_variables = anonymous_variables; + this.wyrd_world = wyrd_world; + this.result = result; + } + + protected static void add_element_to_set + ( + final tonkadur.fate.v1.lang.instruction.AddElement ae + ) + throws Throwable + { + /* + * Fate: + * (add_element element collection) + * + * Wyrd: + * (declare_variable local .anon0) + * (set .anon0 element) + * (declare_variable local boolean .found) + * + * (ifelse (var .found) + * (nop) + * (set .end (size collection)) + * + * (while (> .index .end) + * (set .next (- (val .end) 1)) + * (set collection[.index] collection[.next]) + * (set .end (val .next)) + * ) + * ) + */ + final Ref element_as_ref, collection_as_ref, collection_size_as_ref; + final Ref element_found, element_index, collection_size, next_index; + final ComputationCompiler element_compiler, reference_compiler; + final Type element_type; + final List while_body, else_branch; + + /**** Getting the Element as a ref ****/ + element_compiler = + new ComputationCompiler + ( + anonymous_variables, + wyrd_world + ); + + ae.get_element().visit(element_compiler); + + result.addAll(element_compiler.get_pre_instructions()); + + element_type = element_compiler.get_computation().get_type(); + + element_as_ref = anonymous_variable.reserve(element_type); + + result.add + ( + new SetValue(element_as_ref, element_compiler.get_computation()) + ); + + /**** Getting the Collection as a ref ****/ + reference_compiler = + new ComputationCompiler + ( + anonymous_variables, + wyrd_world + ); + + ae.get_collection().visit(reference_compiler); + + result.addAll(reference_compiler.get_pre_instructions()); + + if (!(reference_compiler.get_computation() instanceof Ref)) + { + /* TODO: error. */ + } + + collection_as_ref = (Ref) reference_compiler.get_computation(); + + /**** Finding the element in the collection ****/ + element_found = anonymous_variable.reserve(Type.BOOLEAN); + element_index = anonymous_variable.reserve(Type.INT); + collection_size = anonymous_variable.reserve(Type.INT); + next_index = anonymous_variable.reserve(Type.INT); + + result.add + ( + new SetValue(collection_size, new Size(collection_as_ref)) + ); + + result.addAll + ( + BinarySearch.generate + ( + anonymous_variables, + element_as_ref, + collection_as_ref, + collection_size, + element_found, + element_index + ) + ); + + while_body = new ArrayList(); + + while_body.add + ( + new SetValue + ( + next_index, + Operation.minus + ( + new ValueOf(collection_size), + new Constant(Type.INT, "1") + ) + ) + ); + + while_body.add + ( + new SetValue + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast + ( + new ValueOf(collection_size), + Type.STRING + ) + ), + element_type + ), + new ValueOf + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast + ( + new ValueOf(next), + Type.STRING + ) + ), + element_type + ) + ) + ) + ); + + while_body.add + ( + new SetValue + ( + collection_size, + new ValueOf(next) + ) + ); + + else_branch = new ArrayList(); + + else_branch.add + ( + new While + ( + Operation.less_than + ( + new ValueOf(element_index), + new ValueOf(collection_size) + ), + while_body + ) + ); + + else_branch.add + ( + new SetValue + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast + ( + new ValueOf(element_index), + Type.STRING + ) + ), + element_type + ), + new ValueOf(element_as_ref) + ) + ); + + result.add + ( + new IfElseInstruction + ( + new ValueOf(element_found), + new NOP(), + else_branch + ) + ); + + anonymous_variables.release(element_as_ref); + anonymous_variables.release(element_found); + anonymous_variables.release(element_index); + anonymous_variables.release(collection_size); + anonymous_variables.release(next_index); + + reference_compiler.free_anonymous_variables(); + element_compiler.free_anonymous_variables(); + } + + protected static void add_element_to_list + ( + final tonkadur.fate.v1.lang.instruction.AddElement ae + ) + throws Throwable + { + /* + * Fate: + * (add_element element collection) + * + * Wyrd: + * (set + * (relative_ref collection ( (cast int string (size collection)) )) + * (element) + * ) + */ + final Ref collection_as_ref; + final ComputationCompiler element_compiler, reference_compiler; + + element_compiler = + new ComputationCompiler + ( + anonymous_variables, + wyrd_world + ); + + ae.get_element().visit(element_compiler); + + reference_compiler = + new ComputationCompiler + ( + anonymous_variables, + wyrd_world + ); + + ae.get_collection().visit(reference_compiler); + + if (!(reference_compiler.get_computation() instanceof Ref)) + { + /* TODO: error. */ + } + + collection_as_ref = (Ref) reference_compiler.get_computation(); + + result.addAll(reference_compiler.get_pre_instructions()); + result.addAll(element_compiler.get_pre_instructions()); + result.add + ( + new SetValue + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast + ( + new Size(reference_compiler.get_computation()), + Type.STRING + ) + ) + ) + element_compiler.get_computation() + ) + ); + + reference_compiler.free_anonymous_variables(); + element_compiler.free_anonymous_variables(); + } + + @Override + public void visit_add_element + ( + final tonkadur.fate.v1.lang.instruction.AddElement ae + ) + throws Throwable + { + final tonkadur.fate.v1.lang.type.Type collection_type; + final tonkadur.fate.v1.lang.type.CollectionType collection_true_type; + + collection_type = ae.get_collection.get_type(); + + if + ( + !(collection_type instanceof tonkadur.fate.v1.lang.type.CollectionType) + ) + { + /* TODO: error */ + } + + collection_true_type = + (tonkadur.fate.v1.lang.type.CollectionType) collection_type; + + if (collection_true_type.is_set()) + { + add_element_to_set(ae); + } + else + { + add_element_to_list(ae); + } + } + + @Override + public void visit_assert (final tonkadur.fate.v1.lang.instruction.Assert a) + throws Throwable + { + final ComputationCompiler cc; + + cc = new ComputationCompiler(wyrd_world); + + a.get_condition().visit(cc); + + result.addAll(cc.get_pre_instructions()); + result.add(new Assert(cc.get_computation())); + + cc.free_anonymous_variables(); + } + + @Override + public void visit_clear (final tonkadur.fate.v1.lang.instruction.Clear c) + throws Throwable + { + final ComputationCompiler reference_compiler; + final Ref iterator, collection_ref; + final List while_body; + + reference_compiler = + new ComputationCompiler(anonymous_variables, wyrd_world); + + c.get_collection().visit(reference_compiler); + + iterator = anonymous_variables.reserve(Type.INT); + + if (!(reference_compiler.get_computation() instanceof Ref)) + { + /* TODO: error. */ + } + + collection_ref = (Ref) reference_compiler.get_computation(); + + while_body.add + ( + new Remove(new ValueOf(iterator), collection_ref) + ); + + while_body.add + ( + new SetValue + ( + iterator, + Operation.minus(new ValueOf(iterator), new Constant(Type.INT, "1")) + ) + ); + + result.add + ( + new While + ( + Operation.greater_equal_than + ( + new ValueOf(iterator), + new Constant(Type.INT, "0") + ), + while_body + ) + ); + + anonymous_variables.release(iterator); + } + + @Override + public void visit_cond_instruction + ( + final tonkadur.fate.v1.lang.instruction.CondInstruction ci + ) + throws Throwable + { + InstructionCompiler ic; + ComputationCompiler cc; + List previous_else_branch; + List current_else_branch; + + previous_else_branch = results; + + for + ( + final + Cons + < + tonkadur.fate.v1.lang.instruction.meta.Computation, + tonkadur.fate.v1.lang.instruction.meta.Instruction + > + branch: + ci.get_branches() + ) + { + current_else_branch = new ArrayList(); + + ic = new InstructionCompiler(anonymous_variables, wyrd_world); + cc = new ComputationCompiler(anonymous_variables, wyrd_world); + + branch.get_car().visit(cc); + + previous_else_branch.addAll(cc.get_pre_instructions()); + previous_else_branch.add + ( + new IfElseInstruction + ( + cc.get_computation(), + ic.get_result(), + current_else_branch + ) + ); + + previous_else_branch = current_else_branch; + } + + previous_else_branch.add(Collections.singleton(new NOP()); + } + + @Override + public void visit_display (final tonkadur.fate.v1.lang.instruction.Display n) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_event_call + ( + final tonkadur.fate.v1.lang.instruction.EventCall n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_if_else_instruction + ( + final tonkadur.fate.v1.lang.instruction.IfElseInstruction n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_if_instruction + ( + final tonkadur.fate.v1.lang.instruction.IfInstruction n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_instruction_list + ( + final tonkadur.fate.v1.lang.instruction.InstructionList n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_macro_call + ( + final tonkadur.fate.v1.lang.instruction.MacroCall n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_player_choice + ( + final tonkadur.fate.v1.lang.instruction.PlayerChoice n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_player_choice_list + ( + final tonkadur.fate.v1.lang.instruction.PlayerChoiceList n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_remove_all_of_element + ( + final tonkadur.fate.v1.lang.instruction.RemoveAllOfElement n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_remove_element + ( + final tonkadur.fate.v1.lang.instruction.RemoveElement n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_sequence_call + ( + final tonkadur.fate.v1.lang.instruction.SequenceCall n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } + + @Override + public void visit_set_value + ( + final tonkadur.fate.v1.lang.instruction.SetValue n + ) + throws Throwable + { + throw new UnhandledASTElementException(); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/SequenceCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/SequenceCompiler.java new file mode 100644 index 0000000..d5fd3e2 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/SequenceCompiler.java @@ -0,0 +1,48 @@ +package tonkadur.wyrd.v1.compiler.fate.v1; + +import tonkadur.error.Error; + +import tonkadur.wyrd.v1.lang.Sequence; + +import tonkadur.wyrd.v1.lang.World; + +public class SequenceCompiler +{ + /* Utility Class */ + private SequenceCompiler () { } + + public static Sequence compile + ( + tonkadur.fate.v1.lang.Sequence fate_sequence, + final World wyrd_world + ) + throws Error + { + Sequence result; + + result = wyrd_world.get_sequence(fate_sequence.get_name()); + + if (result != null) + { + return result; + } + + /* TODO */ + result = null; + + wyrd_world.add_sequence(result); + + return result; + } + + public static List compile_main_sequence + ( + List fate_instruction_list, + final World wyrd_world + ) + throws Error + { + /* TODO */ + return null; + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java new file mode 100644 index 0000000..b77824f --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java @@ -0,0 +1,149 @@ +package tonkadur.wyrd.v1.compiler.fate.v1; + +import tonkadur.error.Error; + +import tonkadur.wyrd.v1.lang.type.*; + +import tonkadur.wyrd.v1.lang.World; + + +public class TypeCompiler +{ + /* Utility Class */ + private TypeCompiler () { } + + public static Type compile + ( + tonkadur.fate.v1.lang.type.Type fate_type, + final World wyrd_world + ) + throws Error + { + if (fate_type instanceof tonkadur.fate.v1.lang.type.DictType) + { + return + compile_dict_type + ( + (tonkadur.fate.v1.lang.type.DictType) fate_type, + wyrd_world + ); + } + + if (fate_type instanceof tonkadur.fate.v1.lang.type.CollectionType) + { + return + compile_collection_type + ( + (tonkadur.fate.v1.lang.type.CollectionType) fate_type, + wyrd_world + ); + } + + if (fate_type instanceof tonkadur.fate.v1.lang.type.RefType) + { + return Type.POINTER; + } + + fate_type = fate_type.get_base_type(); + + if (fate_type.equals(tonkadur.fate.v1.lang.type.BOOLEAN)) + { + return Type.BOOLEAN; + } + + if (fate_type.equals(tonkadur.fate.v1.lang.type.FLOAT)) + { + return Type.FLOAT; + } + + if (fate_type.equals(tonkadur.fate.v1.lang.type.INT)) + { + return Type.INT; + } + + if (fate_type.equals(tonkadur.fate.v1.lang.type.RICH_TEXT)) + { + return Type.RICH_TEXT; + } + + if (fate_type.equals(tonkadur.fate.v1.lang.type.STRING)) + { + return Type.STRING; + } + + /* TODO: throw error. */ + return null; + } + + protected static Type compile_dict_type + ( + final tonkadur.fate.v1.lang.type.DictType fate_dict_type, + final World wyrd_world + ) + throws Error + { + DictType result; + final Map fields; + + result = wyrd_world.get_dict_type(fate_dict_type.get_name()); + + if (result != null) + { + return result; + } + + fields = new HashMap(); + + for + ( + final Map.Entry field: + fate_dict_type.get_fields() + ) + { + fields.put(field.getKey(), compile(field.getValue(), wyrd_world)); + } + + result = new DictType(fate_dict_type.get_name(), fields); + + wyrd_world.add_dict_type(result); + + return result; + } + + protected static Type compile_collection_type + ( + final tonkadur.fate.v1.lang.type.CollectionType fate_collection_type, + final World wyrd_world + ) + throws Error + { + final tonkadur.fate.v1.lang.type.Type fate_content_type; + + fate_content_type = + fate_collection_type.get_content_type().get_base_type(); + + if (fate_content_type.equals(tonkadur.fate.v1.lang.type.BOOLEAN)) + { + return MapType.MAP_TO_BOOLEAN; + } + + if (fate_content_type.equals(tonkadur.fate.v1.lang.type.FLOAT)) + { + return MapType.MAP_TO_FLOAT; + } + + if (fate_content_type.equals(tonkadur.fate.v1.lang.type.INT)) + { + return MapType.MAP_TO_INT; + } + + if (fate_content_type.equals(tonkadur.fate.v1.lang.type.STRING)) + { + return MapType.MAP_TO_STRING; + } + + /* TODO: error */ + + return null; + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/VariableCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/VariableCompiler.java new file mode 100644 index 0000000..6078d54 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/VariableCompiler.java @@ -0,0 +1,42 @@ +package tonkadur.wyrd.v1.compiler.fate.v1; + +import tonkadur.error.Error; + +import tonkadur.wyrd.v1.lang.Variable; + +import tonkadur.wyrd.v1.lang.World; + +public class VariableCompiler +{ + /* Utility Class */ + private VariableCompiler () { } + + public static Variable compile + ( + tonkadur.fate.v1.lang.Variable fate_variable, + final World wyrd_world + ) + throws Error + { + Variable result; + + result = wyrd_world.get_variable(fate_variable.get_name()); + + if (result != null) + { + return result; + } + + result = + new Variable + ( + fate_variable.get_name(), + fate_variable.get_scope().toString(), + TypeCompiler.compile(fate_variable.get_type()) + ); + + wyrd_world.add_variable(result); + + return result; + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java new file mode 100644 index 0000000..14719c2 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java @@ -0,0 +1,76 @@ +package tonkadur.wyrd.v1.compiler.util; + +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; + +import tonkadur.functional.Cons; + +import tonkadur.wyrd.v1.lang.Type; +import tonkadur.wyrd.v1.lang.Variable; + +public class AnonymousVariableManager +{ + protected static final String name_prefix = ".anon."; + + protected final Map> by_name; + protected final Map>> by_type; + protected int generated_variables; + + public AnonymousVariableManager () + { + by_name = new HashMap>(); + by_type = new HashMap>>(); + generated_variables = 0; + } + + public Ref reserve (final Type t) + { + final Ref result; + final Variable new_variable; + List> list; + + list = by_type.get(t); + + if (list == null) + { + list = new ArrayList>(); + + by_type.put(t, list); + } + + for (final Cons entry: list) + { + if (!entry.get_car()) + { + result = entry.get_cdr().get_ref(); + + entry.set_cdr(Boolean.TRUE); + + return result; + } + } + + new_variable = + new Variable + ( + (name_prefix + Integer.toString(generated_variables)), + "local", + t + ); + + list.add(new Cons(Boolean.TRUE, new_variable)); + + return new_variable.get_ref(); + } + + public void release (final Ref r) + { + final String name; + + name = r.get_accesses().get(0).get_as_string(); + + by_name.get(name).set_car(Boolean.FALSE); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java new file mode 100644 index 0000000..6c731b9 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java @@ -0,0 +1,212 @@ +package tonkadur.wyrd.v1.compiler.util; + +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.computation.Cast; +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.Operation; +import tonkadur.wyrd.v1.lang.computation.Ref; +import tonkadur.wyrd.v1.lang.computation.ValueOf; + +import tonkadur.wyrd.v1.lang.instruction.IfElseInstruction; +import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.lang.instruction.While; + +public class BinarySearch +{ + /* + (set .found false) + (declare_variable local int .top) + (set .top (- (size collection) 1)) + (declare_variable local int .bot) + (set .bot 0) + (declare_variable local int .mid) + (declare_variable local .midval) + (while (and (not (var .found)) (<= (variable .bot) (variable .top))) + (set .mid + (+ + (variable .bot) + (cast float int + (/ + (cast int float (- (variable .top) (variable .bot))) + 2.0 + ) + ) + ) + ) + (set .midval + (value_of + (relative_ref collection ( (cast int string .mid) )) + ) + ) + (ifelse (< (variable .midval) (variable .anon1)) + (set .bot (+ (var .mid) 1)) + (ifelse (> (var .midval) (variable .anon1)) + (set .top (- (var .mid) 1)) + (set .found true) + ) + ) + ) + */ + public static List generate + ( + final AnonymousVariableManager anonymous_variables, + final Ref target, + final Ref collection, + final Ref collection_size_or_null, + final Ref result_was_found_holder, + final Ref result_index_holder + ) + { + final List result, while_body; + final Ref top, bot, midval; + + result = new ArrayList(); + while_body = new ArrayList(); + + top = anonymous_variables.reserve(Type.INT); + bot = anonymous_variables.reserve(Type.INT); + midval = anonymous_variables.reserve(target.get_type()); + + result.add(new SetValue(result_holder, Constant.FALSE)); + result.add + ( + new SetValue + ( + top, + Operation.minus + ( + ( + (collection_size_or_null == null) ? + new Size(collection) : new ValueOf(collection_size_or_null) + ), + new Constant(Type.INT, "1") + ) + ) + ); + result.add + ( + new SetValue(bot, new Constant(Type.INT, "0")) + ); + + while_body.add + ( + new SetValue + ( + result_index_holder, + Operation.plus + ( + new ValueOf(bot) + new Cast + ( + Operation.divide + ( + new Cast + ( + Operation.minus + ( + new ValueOf(top) + new ValueOf(bot) + ) + Type.FLOAT + ), + 2 + ) + Type.INT + ) + ) + ) + ); + while_body.add + ( + new SetValue + ( + midval, + new ValueOf + ( + new RelativeRef + ( + collection, + Collections.singletonList + ( + new Cast(new ValueOf(result_index_holder), Type.STRING) + ) + ) + ) + ) + ); + while_body.add + ( + new IfElseInstruction + ( + Operation.less_than(new ValueOf(midval), new ValueOf(target)), + Collections.singletonList + ( + new SetValue + ( + bot, + Operation.plus + ( + new ValueOf(result_index_holder), + new Constant(Type.INT, "1") + ) + ) + ), + Collections.singletonList + ( + new IfElseInstruction + ( + Operation.greater_than + ( + new ValueOf(midval), + new ValueOf(target) + ), + Collections.singletonList + ( + new SetValue + ( + top, + Operation.minus + ( + new ValueOf(result_index_holder), + new Constant(Type.INT, "1") + ) + ) + ), + Collections.singletonList + ( + new SetValue(result_holder, Constant.TRUE) + ) + ) + ) + ) + ); + + result.add + ( + new While + ( + Operation.and + ( + Operation.not(new ValueOf(result_holder)), + Operation.less_equal_than + ( + new ValueOf(bot), + new ValueOf(top) + ) + ), + while_body + ) + ); + + anonymous_variables.release(top); + anonymous_variables.release(bot); + anonymous_variables.release(midval); + + return result; + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/Variable.java b/src/core/src/tonkadur/wyrd/v1/lang/Variable.java index 2ee4495..25bd2e1 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/Variable.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/Variable.java @@ -29,4 +29,14 @@ public class Variable { return type; } + + public Ref get_ref () + { + return + new Ref + ( + Collections.singletonList(new Constant(Type.STRING, name)), + type + ); + } } diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/AbsoluteRef.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/AbsoluteRef.java deleted file mode 100644 index f0d6009..0000000 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/AbsoluteRef.java +++ /dev/null @@ -1,39 +0,0 @@ -package tonkadur.wyrd.v1.lang.computation; - -import java.util.List; - -import tonkadur.wyrd.v1.lang.type.Type; - -import tonkadur.wyrd.v1.lang.meta.Computation; - -public class AbsoluteRef extends Computation -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final List accesses; - protected final Type target_type; - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public AbsoluteRef (final List accesses, final Type target_type) - { - super(Type.POINTER); - - this.accesses = accesses; - this.target_type = target_type; - } - - /**** Accessors ************************************************************/ - public List get_accesses () - { - return accesses; - } - - public Type get_target_type () - { - return target_type; - } -} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/Constant.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/Constant.java index 283f567..c54923d 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/Constant.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/Constant.java @@ -6,6 +6,15 @@ import tonkadur.wyrd.v1.lang.meta.Computation; public class Constant extends Computation { + public static final Constant TRUE; + public static final Constant FALSE; + + static + { + TRUE = new Constant(Type.BOOLEAN, "true"); + FALSE = new Constant(Type.BOOLEAN, "false"); + } + /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/Operation.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/Operation.java index 994138a..a680188 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/Operation.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/Operation.java @@ -8,11 +8,165 @@ import tonkadur.wyrd.v1.lang.meta.Computation; public class Operation extends Computation { + /* Math operations *********************************************************/ + public static final String DIVIDE = "divide"; + public static final String MINUS = "minus"; + public static final String PLUS = "plus"; + public static final String POWER = "power"; + public static final String RANDOM = "rand"; + public static final String TIMES = "times"; + + /* Logic operations ********************************************************/ + public static final String AND = "and"; + public static final String OR = "or"; + public static final String NOT = "not"; + public static final String IMPLIES = "implies"; + + /* Comparison operations ***************************************************/ + public static final String LESS_THAN = "less_than"; + public static final String LESS_EQUAL_THAN = "less_equal_than"; + public static final String EQUALS = "equals"; + public static final String GREATER_EQUAL_THAN = "greater_equal_than"; + public static final String GREATER_THAN = "greather_than"; + + public static Operation divide + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(DIVIDE, param_a.get_type(), param_a, param_b); + } + + public static Operation minus + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(MINUS, param_a.get_type(), param_a, param_b); + } + + public static Operation plus + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(PLUS, param_a.get_type(), param_a, param_b); + } + + public static Operation times + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(TIMES, param_a.get_type(), param_a, param_b); + } + + public static Operation power + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(POWER, param_a.get_type(), param_a, param_b); + } + + public static Operation rand + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(RAND, Type.INT, param_a, param_b); + } + + /* Logic operations ********************************************************/ + public static Operation and + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(AND, Type.BOOLEAN, param_a, param_b); + } + + public static Operation or + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(OR, Type.BOOLEAN, param_a, param_b); + } + + public static Operation not (final Computation param_a) + { + return new Operation(NOT, Type.BOOLEAN, param_a, null); + } + + public static Operation implies + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(IMPLIES, Type.BOOLEAN, param_a, param_b); + } + + /* Comparison operations ***************************************************/ + public static Operation less_than + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(LESS_THAN, Type.BOOLEAN, param_a, param_b); + } + + public static Operation less_equal_than + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(LESS_EQUAL_THAN, Type.BOOLEAN, param_a, param_b); + } + public static Operation equals + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(EQUALS, Type.BOOLEAN, param_a, param_b); + } + + public static Operation greater_than + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(GREATER_THAN, Type.BOOLEAN, param_a, param_b); + } + + public static Operation greater_equal_than + ( + final Computation param_a, + final Computation param_b + ) + { + return new Operation(GREATER_EQUAL_THAN, Type.BOOLEAN, param_a, param_b); + } + /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ protected final String operator; - protected final List parameters; + protected final Computation param_a; + protected final Computation param_b; /***************************************************************************/ /**** PUBLIC ***************************************************************/ @@ -20,20 +174,27 @@ public class Operation extends Computation /**** Constructors *********************************************************/ public Operation ( - final Type result_type, final String operator, - final List parameters + final Type result_type, + final Computation param_a, + final Computation param_b ) { super(result_type); this.operator = operator; - this.parameters = parameters; + this.param_a = param_a; + this.param_b = param_b; } /**** Accessors ************************************************************/ - public List get_parameters () + public Computation get_first_parameter () + { + return param_a; + } + + public Computation get_secomd_parameter () { - return parameters; + return param_b; } } diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java new file mode 100644 index 0000000..69aa905 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java @@ -0,0 +1,39 @@ +package tonkadur.wyrd.v1.lang.computation; + +import java.util.List; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +public class Ref extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final List accesses; + protected final Type target_type; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public Ref (final List accesses, final Type target_type) + { + super(Type.POINTER); + + this.accesses = accesses; + this.target_type = target_type; + } + + /**** Accessors ************************************************************/ + public List get_accesses () + { + return accesses; + } + + public Type get_target_type () + { + return target_type; + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeRef.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeRef.java index 2de3a5d..bc39075 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeRef.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeRef.java @@ -6,14 +6,12 @@ import tonkadur.wyrd.v1.lang.type.Type; import tonkadur.wyrd.v1.lang.meta.Computation; -public class RelativeRef extends Computation +public class RelativeRef extends Ref { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final Computation parent; - protected final List accesses; - protected final Type target_type; + protected final Ref parent; /***************************************************************************/ /**** PUBLIC ***************************************************************/ @@ -21,31 +19,19 @@ public class RelativeRef extends Computation /**** Constructors *********************************************************/ public RelativeRef ( - final Computation parent, - final List accesses, + final Ref parent, + final List accesses, final Type target_type ) { - super(Type.POINTER); + super(accesses, target_type); this.parent = parent; - this.accesses = accesses; - this.target_type = target_type; } /**** Accessors ************************************************************/ - public Computation get_parent () + public Ref get_parent () { return parent; } - - public List get_accesses () - { - return accesses; - } - - public Type get_target_type () - { - return target_type; - } } diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/Size.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/Size.java index 22286d6..5559d0a 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/Size.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/Size.java @@ -9,16 +9,13 @@ public class Size extends Computation /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final Computation collection; + protected final Ref collection; /***************************************************************************/ /**** PUBLIC ***************************************************************/ /***************************************************************************/ /**** Constructors *********************************************************/ - public Size - ( - final Computation collection - ) + public Size (final Ref collection) { super(Type.INT); @@ -26,7 +23,7 @@ public class Size extends Computation } /**** Accessors ************************************************************/ - public Computation get_collection () + public Ref get_collection () { return collection; } diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/ValueOf.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/ValueOf.java index 7d214d8..c48c4e5 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/ValueOf.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/ValueOf.java @@ -22,6 +22,13 @@ public class ValueOf extends Computation this.parent = parent; } + public ValueOf (final Ref parent) + { + super(parent.get_target_type()); + + this.parent = parent; + } + /**** Accessors ************************************************************/ public Computation get_parent () { diff --git a/src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java b/src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java new file mode 100644 index 0000000..6fb5e33 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java @@ -0,0 +1,36 @@ +package tonkadur.wyrd.v1.lang.computation; + +import tonkadur.wyrd.v1.lang.computation.Ref; + +import tonkadur.wyrd.v1.lang.meta.Instruction; +import tonkadur.wyrd.v1.lang.meta.Computation; + +public class Remove extends Instruction +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation index; + protected final Ref reference; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public Remove (final Computation index, final Ref reference) + { + this.index = index; + this.reference = reference; + } + + /**** Accessors ************************************************************/ + public Computation get_index () + { + return index; + } + + public Ref get_reference () + { + return reference; + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java b/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java index 5842874..af6dc77 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java @@ -1,5 +1,7 @@ package tonkadur.wyrd.v1.lang.computation; +import tonkadur.wyrd.v1.lang.computation.Ref; + import tonkadur.wyrd.v1.lang.meta.Instruction; import tonkadur.wyrd.v1.lang.meta.Computation; @@ -8,21 +10,21 @@ public class SetValue extends Instruction /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final Computation reference; + protected final Ref reference; protected final Computation value; /***************************************************************************/ /**** PUBLIC ***************************************************************/ /***************************************************************************/ /**** Constructors *********************************************************/ - public SetValue (final Computation reference, final Computation value) + public SetValue (final Ref reference, final Computation value) { this.reference = reference; this.value = value; } /**** Accessors ************************************************************/ - public Computation get_reference () + public Ref get_reference () { return reference; } diff --git a/src/core/src/tonkadur/wyrd/v1/visitor/fate/v1/FateVisitor.java b/src/core/src/tonkadur/wyrd/v1/visitor/fate/v1/FateVisitor.java deleted file mode 100644 index ecdce81..0000000 --- a/src/core/src/tonkadur/wyrd/v1/visitor/fate/v1/FateVisitor.java +++ /dev/null @@ -1,304 +0,0 @@ -package tonkadur.wyrd.v1.visitor.fate.v1; - -import tonkadur.wyrd.v1.error.UnhandledASTElementException; - -import tonkadur.fate.v1.lang.meta.NodeVisitor; - -public abstract class FateVisitor implements NodeVisitor -{ - public void visit_world (final tonkadur.fate.v1.lang.World w) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - /* Instruction Nodes */ - public void visit_add_element - ( - final tonkadur.fate.v1.lang.instruction.AddElement ae - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_assert (final tonkadur.fate.v1.lang.instruction.Assert a) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_clear (final tonkadur.fate.v1.lang.instruction.Clear c) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_cond_instruction - ( - final tonkadur.fate.v1.lang.instruction.CondInstruction ci - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_display (final tonkadur.fate.v1.lang.instruction.Display n) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_event_call - ( - final tonkadur.fate.v1.lang.instruction.EventCall n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_if_else_instruction - ( - final tonkadur.fate.v1.lang.instruction.IfElseInstruction n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_if_instruction - ( - final tonkadur.fate.v1.lang.instruction.IfInstruction n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_instruction_list - ( - final tonkadur.fate.v1.lang.instruction.InstructionList n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_macro_call - ( - final tonkadur.fate.v1.lang.instruction.MacroCall n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_player_choice - ( - final tonkadur.fate.v1.lang.instruction.PlayerChoice n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_player_choice_list - ( - final tonkadur.fate.v1.lang.instruction.PlayerChoiceList n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_remove_all_of_element - ( - final tonkadur.fate.v1.lang.instruction.RemoveAllOfElement n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_remove_element - ( - final tonkadur.fate.v1.lang.instruction.RemoveElement n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_sequence_call - ( - final tonkadur.fate.v1.lang.instruction.SequenceCall n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_set_value - ( - final tonkadur.fate.v1.lang.instruction.SetValue n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - /* Valued Nodes */ - public void visit_at_reference - ( - final tonkadur.fate.v1.lang.valued_node.AtReference n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_cast - ( - final tonkadur.fate.v1.lang.valued_node.Cast n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_cond_value - ( - final tonkadur.fate.v1.lang.valued_node.CondValue n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_constant - ( - final tonkadur.fate.v1.lang.valued_node.Constant n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_count_operator - ( - final tonkadur.fate.v1.lang.valued_node.CountOperator n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_field_reference - ( - final tonkadur.fate.v1.lang.valued_node.FieldReference n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_if_else_value - ( - final tonkadur.fate.v1.lang.valued_node.IfElseValue n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_is_member_operator - ( - final tonkadur.fate.v1.lang.valued_node.IsMemberOperator n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_macro_value_call - ( - final tonkadur.fate.v1.lang.valued_node.MacroValueCall n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_newline - ( - final tonkadur.fate.v1.lang.valued_node.Newline n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_operation - ( - final tonkadur.fate.v1.lang.valued_node.Operation n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_paragraph - ( - final tonkadur.fate.v1.lang.valued_node.Paragraph n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_parameter_reference - ( - final tonkadur.fate.v1.lang.valued_node.ParameterReference n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_ref_operator - ( - final tonkadur.fate.v1.lang.valued_node.RefOperator n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_text_with_effect - ( - final tonkadur.fate.v1.lang.valued_node.TextWithEffect n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_value_to_rich_text - ( - final tonkadur.fate.v1.lang.valued_node.ValueToRichText n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } - - public void visit_variable_reference - ( - final tonkadur.fate.v1.lang.valued_node.VariableReference n - ) - throws Throwable - { - throw new UnhandledASTElementException(); - } -} -- cgit v1.2.3-70-g09d2