From 87b9279f325872615cb11adfad7dbf9c2d35b712 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Thu, 13 Aug 2020 20:45:34 +0200 Subject: Adding most of the Fate stuff. --- .../v1/error/DuplicateLocalVariableException.java | 51 +++ .../fate/v1/error/NotAValueMacroException.java | 53 --- .../fate/v1/error/NotInAMacroException.java | 41 -- .../fate/v1/error/UnknownParameterException.java | 68 ---- .../v1/error/UnknownVariableScopeException.java | 55 --- src/core/src/tonkadur/fate/v1/lang/Macro.java | 167 -------- src/core/src/tonkadur/fate/v1/lang/Sequence.java | 10 +- src/core/src/tonkadur/fate/v1/lang/Variable.java | 21 +- .../src/tonkadur/fate/v1/lang/VariableScope.java | 88 ----- src/core/src/tonkadur/fate/v1/lang/World.java | 29 +- .../fate/v1/lang/computation/LambdaEvaluation.java | 204 ++++++++++ .../fate/v1/lang/computation/LambdaExpression.java | 83 ++++ .../fate/v1/lang/computation/MacroValueCall.java | 193 --------- .../v1/lang/computation/ParameterReference.java | 53 --- .../tonkadur/fate/v1/lang/instruction/Done.java | 37 ++ .../fate/v1/lang/instruction/LocalVariable.java | 57 +++ .../fate/v1/lang/instruction/MacroCall.java | 175 --------- .../fate/v1/lang/instruction/SequenceCall.java | 24 +- .../fate/v1/lang/instruction/SequenceJump.java | 73 ++++ .../fate/v1/lang/meta/ComputationVisitor.java | 8 +- .../fate/v1/lang/meta/InstructionVisitor.java | 12 +- .../tonkadur/fate/v1/lang/meta/TypedEntryList.java | 111 ------ .../tonkadur/fate/v1/lang/meta/VariableList.java | 72 ++++ .../src/tonkadur/fate/v1/lang/type/LambdaType.java | 163 ++++++++ src/core/src/tonkadur/fate/v1/lang/type/Type.java | 3 + src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 | 12 +- src/core/src/tonkadur/fate/v1/parser/FateParser.g4 | 157 ++------ .../wyrd/v1/compiler/fate/v1/Compiler.java | 36 +- .../v1/compiler/fate/v1/ComputationCompiler.java | 389 +++++++++--------- .../v1/compiler/fate/v1/InstructionCompiler.java | 437 ++++++++++----------- .../wyrd/v1/compiler/fate/v1/MacroManager.java | 24 +- .../wyrd/v1/compiler/fate/v1/TypeCompiler.java | 8 +- .../v1/compiler/util/AnonymousVariableManager.java | 147 ------- .../wyrd/v1/compiler/util/BinarySearch.java | 65 ++- .../src/tonkadur/wyrd/v1/compiler/util/Clear.java | 31 +- .../wyrd/v1/compiler/util/CountOccurrences.java | 37 +- .../wyrd/v1/compiler/util/FunctionContext.java | 9 - .../src/tonkadur/wyrd/v1/compiler/util/If.java | 4 +- .../src/tonkadur/wyrd/v1/compiler/util/IfElse.java | 4 +- .../tonkadur/wyrd/v1/compiler/util/InsertAt.java | 50 +-- .../wyrd/v1/compiler/util/IterativeSearch.java | 20 +- .../src/tonkadur/wyrd/v1/compiler/util/NOP.java | 4 +- .../wyrd/v1/compiler/util/RemoveAllOf.java | 85 ++-- .../tonkadur/wyrd/v1/compiler/util/RemoveAt.java | 52 +-- .../wyrd/v1/compiler/util/ReverseList.java | 71 ++-- .../src/tonkadur/wyrd/v1/compiler/util/While.java | 6 +- .../compiler/util/registers/RegisterContext.java | 140 ++++--- .../compiler/util/registers/RegisterManager.java | 63 ++- .../util/registers/StackableRegisterContext.java | 183 ++++----- src/core/src/tonkadur/wyrd/v1/lang/Register.java | 68 ++++ src/core/src/tonkadur/wyrd/v1/lang/Variable.java | 42 -- src/core/src/tonkadur/wyrd/v1/lang/World.java | 19 +- .../tonkadur/wyrd/v1/lang/computation/Address.java | 61 +++ .../src/tonkadur/wyrd/v1/lang/computation/Ref.java | 61 --- .../wyrd/v1/lang/computation/RelativeAddress.java | 60 +++ .../wyrd/v1/lang/computation/RelativeRef.java | 60 --- .../tonkadur/wyrd/v1/lang/computation/Size.java | 6 +- .../tonkadur/wyrd/v1/lang/computation/ValueOf.java | 2 +- .../tonkadur/wyrd/v1/lang/instruction/Remove.java | 14 +- .../wyrd/v1/lang/instruction/SetValue.java | 14 +- .../wyrd/v1/lang/meta/ComputationVisitor.java | 4 +- 61 files changed, 1935 insertions(+), 2361 deletions(-) create mode 100644 src/core/src/tonkadur/fate/v1/error/DuplicateLocalVariableException.java delete mode 100644 src/core/src/tonkadur/fate/v1/error/NotAValueMacroException.java delete mode 100644 src/core/src/tonkadur/fate/v1/error/NotInAMacroException.java delete mode 100644 src/core/src/tonkadur/fate/v1/error/UnknownParameterException.java delete mode 100644 src/core/src/tonkadur/fate/v1/error/UnknownVariableScopeException.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/Macro.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/VariableScope.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/LambdaEvaluation.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/LambdaExpression.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/MacroValueCall.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/ParameterReference.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/instruction/Done.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/instruction/LocalVariable.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/instruction/MacroCall.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/instruction/SequenceJump.java delete mode 100644 src/core/src/tonkadur/fate/v1/lang/meta/TypedEntryList.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/meta/VariableList.java create mode 100644 src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java create mode 100644 src/core/src/tonkadur/wyrd/v1/lang/Register.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/lang/Variable.java create mode 100644 src/core/src/tonkadur/wyrd/v1/lang/computation/Address.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java create mode 100644 src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeAddress.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeRef.java diff --git a/src/core/src/tonkadur/fate/v1/error/DuplicateLocalVariableException.java b/src/core/src/tonkadur/fate/v1/error/DuplicateLocalVariableException.java new file mode 100644 index 0000000..fb168ef --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/error/DuplicateLocalVariableException.java @@ -0,0 +1,51 @@ +package tonkadur.fate.v1.error; + +import tonkadur.error.ErrorLevel; + +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; + +import tonkadur.fate.v1.lang.Variable; + +public class DuplicateLocalVariableException extends ParsingError +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Variable original_var; + protected final Variable new_var; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + public DuplicateLocalVariableException + ( + final Variable original_var, + final Variable new_var + ) + { + super(ErrorLevel.ERROR, ErrorCategory.INVALID_USE, new_var.get_origin()); + + this.original_var = original_var; + this.new_var = new_var; + } + + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append(origin.toString()); + sb.append(" "); + sb.append(error_category.toString()); + sb.append(System.lineSeparator()); + + sb.append("Local variable name '"); + sb.append(original_var.get_name()); + sb.append("' already in use. It was originally reserved at "); + sb.append(original_var.get_origin().get_location().toString()); + sb.append("."); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/error/NotAValueMacroException.java b/src/core/src/tonkadur/fate/v1/error/NotAValueMacroException.java deleted file mode 100644 index b235ad9..0000000 --- a/src/core/src/tonkadur/fate/v1/error/NotAValueMacroException.java +++ /dev/null @@ -1,53 +0,0 @@ -package tonkadur.fate.v1.error; - -import tonkadur.error.ErrorLevel; - -import tonkadur.parser.Origin; -import tonkadur.parser.ParsingError; - -public class NotAValueMacroException extends ParsingError -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final String macro_name; - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - public NotAValueMacroException (final Origin origin, final String macro_name) - { - super - ( - ErrorLevel.ERROR, - ErrorCategory.INVALID_USE, - origin - ); - - this.macro_name = macro_name; - } - - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append(" "); - sb.append(error_category.toString()); - sb.append(System.lineSeparator()); - - sb.append("Macro '"); - sb.append(macro_name); - sb.append - ( - "' is not defined as a single value and thus cannot be used as one." - ); - sb.append(System.lineSeparator()); - sb.append("Does it contain instructions?"); - sb.append(System.lineSeparator()); - sb.append("Is it a sequence of multiple values?"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/error/NotInAMacroException.java b/src/core/src/tonkadur/fate/v1/error/NotInAMacroException.java deleted file mode 100644 index 2bb1ed2..0000000 --- a/src/core/src/tonkadur/fate/v1/error/NotInAMacroException.java +++ /dev/null @@ -1,41 +0,0 @@ -package tonkadur.fate.v1.error; - -import tonkadur.error.ErrorLevel; - -import tonkadur.parser.Origin; -import tonkadur.parser.ParsingError; - -public class NotInAMacroException extends ParsingError -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - public NotInAMacroException (final Origin origin) - { - super - ( - ErrorLevel.ERROR, - ErrorCategory.INVALID_USE, - origin - ); - } - - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append(" "); - sb.append(error_category.toString()); - sb.append(System.lineSeparator()); - - sb.append("This can only be done/used in a macro."); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/error/UnknownParameterException.java b/src/core/src/tonkadur/fate/v1/error/UnknownParameterException.java deleted file mode 100644 index 6e09bee..0000000 --- a/src/core/src/tonkadur/fate/v1/error/UnknownParameterException.java +++ /dev/null @@ -1,68 +0,0 @@ -package tonkadur.fate.v1.error; - -import tonkadur.error.ErrorLevel; - -import tonkadur.parser.Origin; -import tonkadur.parser.ParsingError; - -import tonkadur.fate.v1.lang.meta.TypedEntryList; - -public class UnknownParameterException extends ParsingError -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final TypedEntryList available_parameters; - protected final String parameter_name; - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - public UnknownParameterException - ( - final Origin origin, - final String parameter_name, - final TypedEntryList available_parameters - ) - { - super - ( - ErrorLevel.ERROR, - ErrorCategory.UNKNOWN, - origin - ); - - this.parameter_name = parameter_name; - this.available_parameters = available_parameters; - } - - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append(" "); - sb.append(error_category.toString()); - sb.append(System.lineSeparator()); - - sb.append("Unknown parameter '"); - sb.append(parameter_name); - sb.append("'. "); - sb.append(System.lineSeparator()); - sb.append("Available parameters:'"); - - for - ( - final TypedEntryList.TypedEntry param: - available_parameters.get_entries() - ) - { - sb.append(System.lineSeparator()); - sb.append("- "); - sb.append(param.get_name()); - } - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/error/UnknownVariableScopeException.java b/src/core/src/tonkadur/fate/v1/error/UnknownVariableScopeException.java deleted file mode 100644 index 129a789..0000000 --- a/src/core/src/tonkadur/fate/v1/error/UnknownVariableScopeException.java +++ /dev/null @@ -1,55 +0,0 @@ -package tonkadur.fate.v1.error; - -import tonkadur.error.ErrorLevel; - -import tonkadur.parser.Origin; -import tonkadur.parser.ParsingError; - -import tonkadur.fate.v1.lang.VariableScope; - -public class UnknownVariableScopeException extends ParsingError -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final String name; - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - public UnknownVariableScopeException - ( - final Origin origin, - final String name - ) - { - super(ErrorLevel.ERROR, ErrorCategory.INVALID_USE, origin); - this.name = name; - } - - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append(origin.toString()); - sb.append(" "); - sb.append(error_category.toString()); - sb.append(System.lineSeparator()); - - sb.append("Unknown variable scope '"); - sb.append(name); - sb.append("'."); - sb.append(System.lineSeparator()); - sb.append("Available fields are:"); - - for (final String scope: VariableScope.get_available_scopes()) - { - sb.append(System.lineSeparator()); - sb.append("- "); - sb.append(scope); - } - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/Macro.java b/src/core/src/tonkadur/fate/v1/lang/Macro.java deleted file mode 100644 index c4c4dc4..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/Macro.java +++ /dev/null @@ -1,167 +0,0 @@ -package tonkadur.fate.v1.lang; - -import java.util.ArrayList; -import java.util.List; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.meta.DeclaredEntity; -import tonkadur.fate.v1.lang.meta.Instruction; -import tonkadur.fate.v1.lang.meta.TypedEntryList; -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.computation.Cast; -import tonkadur.fate.v1.lang.computation.ValueToRichText; - -public class Macro extends DeclaredEntity -{ - @Override - public /* static */ String get_type_name () - { - return "Macro"; - } - - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Instruction root; - protected final TypedEntryList parameters; - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - - /**** Constructors *********************************************************/ - public Macro - ( - final Origin origin, - final Instruction root, - final TypedEntryList parameters, - final String name - ) - { - super(origin, name); - - this.root = root; - this.parameters = parameters; - } - - /**** Accessors ************************************************************/ - public TypedEntryList get_parameters () - { - return parameters; - } - - public Instruction get_root () - { - return root; - } - - public List get_signature () - { - final List result; - - result = new ArrayList(); - - for (final TypedEntryList.TypedEntry entry: parameters.get_entries()) - { - result.add(entry.get_type()); - } - - return result; - } - - public Computation get_value_node_representation () - { - final Cast result_cast; - InstructionList root_as_il; - Instruction instr; - Computation result; - - if (!(root instanceof InstructionList)) - { - return null; - } - - root_as_il = (InstructionList) root; - - if (root_as_il.get_instructions().size() != 1) - { - return null; - } - - instr = root_as_il.get_instructions().get(0); - - if (!(instr instanceof Display)) - { - return null; - } - - result = ((Display) instr).get_content(); - - if (!(result instanceof ValueToRichText)) - { - return result; - } - - result = ((ValueToRichText) result).get_value(); - - if (!(result instanceof Cast)) - { - return result; - } - - result_cast = (Cast) result; - - if (result_cast.is_autogenerated()) - { - return result_cast.get_parent(); - } - else - { - return result; - } - } - /**** Compatibility ********************************************************/ - - /* - * This is for the very special case where a type is used despite not being - * even a sub-type of the expected one. Using this rather expensive function, - * the most restrictive shared type will be returned. If no such type exists, - * the ANY time is returned. - */ - @Override - public DeclaredEntity generate_comparable_to (final DeclaredEntity de) - { - return null; - } - - - /**** Misc. ****************************************************************/ - @Override - public boolean is_incompatible_with_declaration (final DeclaredEntity de) - { - return true; - } - - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append("(Macro "); - sb.append(name); - sb.append(")"); - - return sb.toString(); - } - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ -} diff --git a/src/core/src/tonkadur/fate/v1/lang/Sequence.java b/src/core/src/tonkadur/fate/v1/lang/Sequence.java index 5b97e5c..34b1dc5 100644 --- a/src/core/src/tonkadur/fate/v1/lang/Sequence.java +++ b/src/core/src/tonkadur/fate/v1/lang/Sequence.java @@ -30,6 +30,7 @@ public class Sequence extends DeclaredEntity /**** MEMBERS **************************************************************/ /***************************************************************************/ protected final Instruction root; + protected final List signature; /***************************************************************************/ /**** PUBLIC ***************************************************************/ @@ -40,12 +41,14 @@ public class Sequence extends DeclaredEntity ( final Origin origin, final Instruction root, - final String name + final String name, + final List signature ) { super(origin, name); this.root = root; + this.signature = signature; } /**** Accessors ************************************************************/ @@ -54,6 +57,11 @@ public class Sequence extends DeclaredEntity return root; } + public List get_signature () + { + return signature; + } + /**** Compatibility ********************************************************/ /* diff --git a/src/core/src/tonkadur/fate/v1/lang/Variable.java b/src/core/src/tonkadur/fate/v1/lang/Variable.java index b81d2bf..3a8b761 100644 --- a/src/core/src/tonkadur/fate/v1/lang/Variable.java +++ b/src/core/src/tonkadur/fate/v1/lang/Variable.java @@ -23,7 +23,6 @@ public class Variable extends DeclaredEntity new Variable ( Origin.BASE_LANGUAGE, - VariableScope.ANY, Type.ANY, /* * Use of a space necessary to avoid conflicting with a user created @@ -48,7 +47,6 @@ public class Variable extends DeclaredEntity /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final VariableScope scope; protected final Type type; /***************************************************************************/ @@ -59,14 +57,12 @@ public class Variable extends DeclaredEntity public Variable ( final Origin origin, - final VariableScope scope, final Type type, final String name ) { super(origin, name); - this.scope = scope; this.type = type; } @@ -76,15 +72,9 @@ public class Variable extends DeclaredEntity return type; } - public VariableScope get_scope () - { - return scope; - } - @Override public DeclaredEntity generate_comparable_to (final DeclaredEntity de) { - final VariableScope new_scope; final Type new_type; final Variable v; @@ -95,10 +85,9 @@ public class Variable extends DeclaredEntity v = (Variable) de; - new_scope = scope.generate_compatible_with(v.scope); new_type = (Type) type.generate_comparable_to(v.type); - return new Variable(origin, new_scope, new_type, name); + return new Variable(origin, new_type, name); } /**** Misc. ****************************************************************/ @@ -111,11 +100,7 @@ public class Variable extends DeclaredEntity v = (Variable) de; - return - ( - (!scope.equals(v.scope)) - || !type.can_be_used_as(v.type) - ); + return !type.can_be_used_as(v.type); } return true; @@ -127,8 +112,6 @@ public class Variable extends DeclaredEntity final StringBuilder sb = new StringBuilder(); sb.append("("); - sb.append(scope.toString()); - sb.append(" "); sb.append(type.get_name()); sb.append(" Variable "); sb.append(name); diff --git a/src/core/src/tonkadur/fate/v1/lang/VariableScope.java b/src/core/src/tonkadur/fate/v1/lang/VariableScope.java deleted file mode 100644 index 7f42fa6..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/VariableScope.java +++ /dev/null @@ -1,88 +0,0 @@ -package tonkadur.fate.v1.lang; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.HashSet; - -/* - * Yes, it *could* have been an enum. Except that you can't extend enums, making - * them inadequate for anything that has even the slightest chance of needing to - * be extended at some point in the future. In other words, they're inadequate - * for anything but very rare corner cases (days in week, for example). - * Tonkadur wants extension support, ergo, no enums in Tonkadur. - * - * The use of a collection to decode them stems from the same reason (can't - * override static methods). - */ -public class VariableScope -{ - public static final VariableScope ANY; - - protected static final Map from_name; - public static final VariableScope LOCAL; - public static final VariableScope GLOBAL; - - static - { - from_name = new HashMap(); - - ANY = new VariableScope("unknown scope", null); - GLOBAL = new VariableScope("global", null); - LOCAL = new VariableScope("local", GLOBAL); - } - - public static VariableScope value_of (final String string) - { - return from_name.get(string); - } - - public static Set get_available_scopes () - { - return from_name.keySet(); - } - - protected final String name; - protected final Set more_restrictive_than; - - protected VariableScope (final String name, final VariableScope parent) - { - this.name = name; - - more_restrictive_than = new HashSet(); - - if (parent != null) - { - more_restrictive_than.addAll(parent.more_restrictive_than); - more_restrictive_than.add(parent); - } - - from_name.put(name, this); - } - - public VariableScope generate_compatible_with (final VariableScope other) - { - if (other.equals(this)) - { - return this; - } - - if (other.more_restrictive_than.contains(this)) - { - if (this.more_restrictive_than.contains(other)) - { - return ANY; - } - - return other; - } - - return this; - } - - @Override - public String toString () - { - return name; - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/World.java b/src/core/src/tonkadur/fate/v1/lang/World.java index 7b15f3f..a7da2f0 100644 --- a/src/core/src/tonkadur/fate/v1/lang/World.java +++ b/src/core/src/tonkadur/fate/v1/lang/World.java @@ -31,14 +31,13 @@ public class World protected final Set loaded_files; protected final Set required_extensions; - protected final Map> sequence_calls; + protected final Map> sequence_uses; protected final Map extension_value_nodes; protected final Map extension_instructions; protected final Map extension_first_level_instructions; protected final DeclarationCollection event_collection; - protected final DeclarationCollection macro_collection; protected final DeclarationCollection sequence_collection; protected final DeclarationCollection text_effect_collection; protected final DeclarationCollection type_collection; @@ -56,7 +55,7 @@ public class World loaded_files = new HashSet(); required_extensions = new HashSet(); - sequence_calls = new HashMap>(); + sequence_uses = new HashMap>(); extension_value_nodes = new HashMap(); extension_instructions = new HashMap(); extension_first_level_instructions = @@ -64,7 +63,6 @@ public class World event_collection = new DeclarationCollection(Event.value_on_missing()); - macro_collection = new DeclarationCollection(null); sequence_collection = new DeclarationCollection(null); text_effect_collection = @@ -115,18 +113,18 @@ public class World /**** Sequence Calls ****/ public void add_sequence_call (final Origin origin, final String sequence) { - List list_of_calls; + List list_of_uses; - list_of_calls = sequence_calls.get(sequence); + list_of_uses = sequence_uses.get(sequence); - if (list_of_calls == null) + if (list_of_uses == null) { - list_of_calls = new ArrayList(); + list_of_uses = new ArrayList(); - sequence_calls.put(sequence, list_of_calls); + sequence_uses.put(sequence, list_of_uses); } - list_of_calls.add(origin); + list_of_uses.add(origin); } /**** Extension Stuff ****/ @@ -155,11 +153,6 @@ public class World return event_collection; } - public DeclarationCollection macros () - { - return macro_collection; - } - public DeclarationCollection sequences () { return sequence_collection; @@ -198,7 +191,7 @@ public class World is_sane = true; - is_sane = assert_sane_sequence_calls() & is_sane; + is_sane = assert_sane_sequence_uses() & is_sane; return is_sane; } @@ -284,7 +277,7 @@ public class World } } - protected boolean assert_sane_sequence_calls () + protected boolean assert_sane_sequence_uses () throws UnknownSequenceException { boolean is_sane; @@ -294,7 +287,7 @@ public class World for ( final Map.Entry> entry: - sequence_calls.entrySet() + sequence_uses.entrySet() ) { if (!sequences().has(entry.getKey())) diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/LambdaEvaluation.java b/src/core/src/tonkadur/fate/v1/lang/computation/LambdaEvaluation.java new file mode 100644 index 0000000..9bdc731 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/LambdaEvaluation.java @@ -0,0 +1,204 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.ArrayList; +import java.util.Collections; +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.InvalidTypeException; + +import tonkadur.fate.v1.lang.type.Type; +import tonkadur.fate.v1.lang.type.LambdaType; + +import tonkadur.fate.v1.lang.meta.ComputationVisitor; +import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.Reference; + +public class LambdaEvaluation extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Reference lambda_function; + protected final List parameters; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected LambdaEvaluation + ( + final Origin origin, + final Reference lambda_function, + final List parameters, + final Type act_as + ) + { + super(origin, act_as); + + this.lambda_function = lambda_function; + this.parameters = parameters; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static LambdaEvaluation build + ( + final Origin origin, + final Reference reference, + final List parameters + ) + throws Throwable + { + final Type var_type; + final LambdaType lambda_type; + final List signature; + + var_type = reference.get_type(); + + if (!(var_type instanceof LambdaType)) + { + ErrorManager.handle + ( + new InvalidTypeException + ( + origin, + var_type, + Collections.singleton(Type.LAMBDA) + ) + ); + + return null; + } + + lambda_type = (LambdaType) var_type; + + signature = lambda_type.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 LambdaEvaluation + ( + origin, + reference, + parameters, + lambda_type.get_return_type() + ); + } + + /**** Accessors ************************************************************/ + @Override + public void get_visited_by (final ComputationVisitor cv) + throws Throwable + { + cv.visit_lambda_evaluation(this); + } + + public Reference get_lambda_function_reference () + { + return lambda_function; + } + + public List get_parameters () + { + return parameters; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(LambdaEvaluation ("); + sb.append(lambda_function.toString()); + + 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/LambdaExpression.java b/src/core/src/tonkadur/fate/v1/lang/computation/LambdaExpression.java new file mode 100644 index 0000000..6c99aa4 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/LambdaExpression.java @@ -0,0 +1,83 @@ +package tonkadur.fate.v1.lang.computation; + +import java.util.List; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.ComputationVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +import tonkadur.fate.v1.lang.Variable; + +public class LambdaExpression extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation function; + protected final List parameters; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public LambdaExpression + ( + final Origin origin, + final List parameters, + final Computation function + ) + { + super(origin, function.get_type()); + + this.function = function; + this.parameters = parameters; + } + + /**** Accessors ************************************************************/ + @Override + public void get_visited_by (final ComputationVisitor cv) + throws Throwable + { + cv.visit_lambda_expression(this); + } + + public Computation get_lambda_function () + { + return function; + } + + public List get_parameters () + { + return parameters; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(LambdaExpression ("); + + for (final Variable param: parameters) + { + sb.append("("); + sb.append(param.get_type()); + sb.append(" "); + sb.append(param.get_name()); + sb.append(")"); + } + sb.append(") "); + + sb.append(function.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 deleted file mode 100644 index 5e4cdfd..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/computation/MacroValueCall.java +++ /dev/null @@ -1,193 +0,0 @@ -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.ComputationVisitor; -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 get_visited_by (final ComputationVisitor cv) - throws Throwable - { - cv.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/ParameterReference.java b/src/core/src/tonkadur/fate/v1/lang/computation/ParameterReference.java deleted file mode 100644 index 6266c7c..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/computation/ParameterReference.java +++ /dev/null @@ -1,53 +0,0 @@ -package tonkadur.fate.v1.lang.computation; - -import tonkadur.parser.Origin; - -import tonkadur.fate.v1.lang.meta.ComputationVisitor; -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 get_visited_by (final ComputationVisitor cv) - throws Throwable - { - cv.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/instruction/Done.java b/src/core/src/tonkadur/fate/v1/lang/instruction/Done.java new file mode 100644 index 0000000..ada3b7c --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/Done.java @@ -0,0 +1,37 @@ +package tonkadur.fate.v1.lang.instruction; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.InstructionVisitor; +import tonkadur.fate.v1.lang.meta.Instruction; + +public class Done extends Instruction +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public Done (final Origin origin) + { + super(origin); + } + + /**** Accessors ************************************************************/ + @Override + public void get_visited_by (final InstructionVisitor iv) + throws Throwable + { + iv.visit_done(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + return "(Done)"; + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/LocalVariable.java b/src/core/src/tonkadur/fate/v1/lang/instruction/LocalVariable.java new file mode 100644 index 0000000..7a87d7d --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/LocalVariable.java @@ -0,0 +1,57 @@ +package tonkadur.fate.v1.lang.instruction; + +import tonkadur.fate.v1.lang.meta.InstructionVisitor; +import tonkadur.fate.v1.lang.meta.Instruction; + +import tonkadur.fate.v1.lang.Variable; + +public class LocalVariable extends Instruction +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Variable variable; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected LocalVariable (final Variable variable) + { + super(variable.get_origin()); + + this.variable = variable; + } + + + /**** Accessors ************************************************************/ + @Override + public void get_visited_by (final InstructionVisitor iv) + throws Throwable + { + iv.visit_local_variable(this); + } + + public Variable get_variable () + { + return variable; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(LocalVariable "); + sb.append(variable.toString()); + + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/MacroCall.java b/src/core/src/tonkadur/fate/v1/lang/instruction/MacroCall.java deleted file mode 100644 index c3c3b44..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/MacroCall.java +++ /dev/null @@ -1,175 +0,0 @@ -package tonkadur.fate.v1.lang.instruction; - -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.Macro; - -import tonkadur.fate.v1.lang.type.Type; - -import tonkadur.fate.v1.lang.meta.InstructionVisitor; -import tonkadur.fate.v1.lang.meta.Instruction; -import tonkadur.fate.v1.lang.meta.Computation; - -public class MacroCall extends Instruction -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Macro macro; - protected final List parameters; - - /***************************************************************************/ - /**** PROTECTED ************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - protected MacroCall - ( - final Origin origin, - final Macro macro, - final List parameters - ) - { - super(origin); - - this.macro = macro; - this.parameters = parameters; - } - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public static MacroCall build - ( - final Origin origin, - final Macro macro, - final List parameters - ) - throws Throwable - { - final List type_checks; - final List signature; - - 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 MacroCall(origin, macro, parameters); - } - - /**** Accessors ************************************************************/ - @Override - public void get_visited_by (final InstructionVisitor iv) - throws Throwable - { - iv.visit_macro_call(this); - } - - public Macro get_macro () - { - return macro; - } - - public List get_parameters () - { - return parameters; - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb = new StringBuilder(); - - sb.append("(MacroCall ("); - 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/instruction/SequenceCall.java b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java index 6ea696d..c65f490 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceCall.java @@ -1,7 +1,10 @@ package tonkadur.fate.v1.lang.instruction; +import java.util.List; + import tonkadur.parser.Origin; +import tonkadur.fate.v1.lang.meta.Computation; import tonkadur.fate.v1.lang.meta.InstructionVisitor; import tonkadur.fate.v1.lang.meta.Instruction; @@ -10,17 +13,24 @@ public class SequenceCall extends Instruction /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ + protected final List parameters; protected final String sequence_name; /***************************************************************************/ /**** PUBLIC ***************************************************************/ /***************************************************************************/ /**** Constructors *********************************************************/ - public SequenceCall (final Origin origin, final String sequence_name) + public SequenceCall + ( + final Origin origin, + final String sequence_name, + final List parameters + ) { super(origin); this.sequence_name = sequence_name; + this.parameters = parameters; } /**** Accessors ************************************************************/ @@ -36,6 +46,11 @@ public class SequenceCall extends Instruction return sequence_name; } + public List get_parameters () + { + return parameters; + } + /**** Misc. ****************************************************************/ @Override public String toString () @@ -44,6 +59,13 @@ public class SequenceCall extends Instruction sb.append("(SequenceCall "); sb.append(sequence_name); + + for (final Computation c: parameters) + { + sb.append(" "); + sb.append(c.toString()); + } + sb.append(")"); return sb.toString(); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceJump.java b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceJump.java new file mode 100644 index 0000000..fb95d84 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/SequenceJump.java @@ -0,0 +1,73 @@ +package tonkadur.fate.v1.lang.instruction; + +import java.util.List; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.InstructionVisitor; +import tonkadur.fate.v1.lang.meta.Instruction; + +public class SequenceJump extends Instruction +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final List parameters; + protected final String sequence_name; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public SequenceJump + ( + final Origin origin, + final String sequence_name, + final List parameters + ) + { + super(origin); + + this.sequence_name = sequence_name; + this.parameters = parameters; + } + + /**** Accessors ************************************************************/ + @Override + public void get_visited_by (final InstructionVisitor iv) + throws Throwable + { + iv.visit_sequence_jump(this); + } + + public String get_sequence_name () + { + return sequence_name; + } + + public List get_parameters () + { + return parameters; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(SequenceJump "); + sb.append(sequence_name); + + for (final Computation c: parameters) + { + sb.append(" "); + sb.append(c.toString()); + } + + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/ComputationVisitor.java b/src/core/src/tonkadur/fate/v1/lang/meta/ComputationVisitor.java index d2c4ff0..0b992cb 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/ComputationVisitor.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/ComputationVisitor.java @@ -43,7 +43,10 @@ public interface ComputationVisitor public void visit_size_operator (final SizeOperator n) throws Throwable; - public void visit_macro_value_call (final MacroValueCall n) + public void visit_lambda_expression (final LambdaExpression n) + throws Throwable; + + public void visit_lambda_evaluation (final LambdaEvaluation n) throws Throwable; public void visit_newline (final Newline n) @@ -55,9 +58,6 @@ public interface ComputationVisitor public void visit_paragraph (final Paragraph n) throws Throwable; - public void visit_parameter_reference (final ParameterReference n) - throws Throwable; - public void visit_ref_operator (final RefOperator n) throws Throwable; diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java b/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java index 3f4f973..afaa151 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java @@ -17,6 +17,9 @@ public interface InstructionVisitor public void visit_end (final End n) throws Throwable; + public void visit_done (final Done n) + throws Throwable; + public void visit_free (final Free n) throws Throwable; @@ -62,9 +65,6 @@ public interface InstructionVisitor public void visit_instruction_list (final InstructionList n) throws Throwable; - public void visit_macro_call (final MacroCall n) - throws Throwable; - public void visit_player_choice (final PlayerChoice n) throws Throwable; @@ -80,6 +80,12 @@ public interface InstructionVisitor public void visit_sequence_call (final SequenceCall n) throws Throwable; + public void visit_sequence_jump (final SequenceJump n) + throws Throwable; + + public void visit_local_variable (final LocalVariable n) + throws Throwable; + public void visit_set_value (final SetValue n) throws Throwable; } diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/TypedEntryList.java b/src/core/src/tonkadur/fate/v1/lang/meta/TypedEntryList.java deleted file mode 100644 index d9cee24..0000000 --- a/src/core/src/tonkadur/fate/v1/lang/meta/TypedEntryList.java +++ /dev/null @@ -1,111 +0,0 @@ -package tonkadur.fate.v1.lang.meta; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import tonkadur.parser.Origin; - -import tonkadur.error.ErrorManager; - -import tonkadur.fate.v1.error.DuplicateFieldException; - -import tonkadur.fate.v1.lang.type.Type; - -public class TypedEntryList -{ - protected final Map as_map; - protected final List as_list; - - public TypedEntryList () - { - as_map = new HashMap(); - as_list = new ArrayList(); - } - - public void remove (final String name) - { - TypedEntry previous_entry; - - previous_entry = as_map.get(name); - - as_list.remove(previous_entry); - as_map.remove(name); - } - - public void add - ( - final Origin origin, - final Type type, - final String name - ) - throws DuplicateFieldException - { - TypedEntry previous_entry; - - previous_entry = as_map.get(name); - - if (previous_entry != null) - { - ErrorManager.handle - ( - new DuplicateFieldException - ( - origin, - previous_entry.get_origin(), - name - ) - ); - } - - previous_entry = new TypedEntry(origin, type, name); - - as_map.put(name, previous_entry); - as_list.add(previous_entry); - } - - public List get_entries () - { - return as_list; - } - - public Map as_map () - { - return as_map; - } - - public static class TypedEntry - { - protected final Origin origin; - protected final Type type; - protected final String name; - - protected TypedEntry - ( - final Origin origin, - final Type type, - final String name - ) - { - this.origin = origin; - this.type = type; - this.name = name; - } - - public String get_name () - { - return name; - } - - public Type get_type () - { - return type; - } - - public Origin get_origin () - { - return origin; - } - } -} diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/VariableList.java b/src/core/src/tonkadur/fate/v1/lang/meta/VariableList.java new file mode 100644 index 0000000..dbf9286 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/meta/VariableList.java @@ -0,0 +1,72 @@ +package tonkadur.fate.v1.lang.meta; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import tonkadur.parser.Origin; + +import tonkadur.error.ErrorManager; + +import tonkadur.fate.v1.error.DuplicateFieldException; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.Variable; + +public class VariableList +{ + protected final Map as_map; + protected final List as_list; + + public VariableList () + { + as_map = new HashMap(); + as_list = new ArrayList(); + } + + public void remove (final String name) + { + final Variable previous_entry; + + previous_entry = as_map.get(name); + + as_list.remove(previous_entry); + as_map.remove(name); + } + + public void add (final Variable entry) + throws DuplicateFieldException + { + final Variable previous_entry; + + previous_entry = as_map.get(entry.get_name()); + + if (previous_entry != null) + { + ErrorManager.handle + ( + new DuplicateFieldException + ( + entry.get_origin(), + previous_entry.get_origin(), + entry.get_name() + ) + ); + } + + as_map.put(entry.get_name(), entry); + as_list.add(entry); + } + + public List get_entries () + { + return as_list; + } + + public Map as_map () + { + return as_map; + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java b/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java new file mode 100644 index 0000000..0ca9c48 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java @@ -0,0 +1,163 @@ +package tonkadur.fate.v1.lang.type; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.DeclaredEntity; + +public class LambdaType extends Type +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final List signature; + protected final Type return_type; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + + /**** Constructors *********************************************************/ + public LambdaType + ( + final Origin origin, + final Type return_type, + final String name, + final List signature + ) + { + super(origin, null, name); + + this.signature = signature; + this.return_type = return_type; + } + + /**** Accessors ************************************************************/ + public Type get_return_type () + { + return return_type; + } + + public List get_signature () + { + return signature; + } + + /**** Compatibility ********************************************************/ + @Override + public boolean can_be_used_as (final Type t) + { + if (t instanceof LambdaType) + { + final Iterator i0, i1; + final LambdaType lt; + + lt = (LambdaType) t; + + if + ( + signature.size() != lt.signature.size() + || !return_type.can_be_used_as(lt.return_type) + ) + { + return false; + } + + i0 = signature.iterator(); + i1 = lt.signature.iterator(); + + while(i0.hasNext()) + { + if (!i0.next().can_be_used_as(i1.next())) + { + return false; + } + } + + return true; + } + + return false; + } + + /* + * This is for the very special case where a type is used despite not being + * even a sub-type of the expected one. Using this rather expensive function, + * the most restrictive shared type will be returned. If no such type exists, + * the ANY time is returned. + */ + @Override + public DeclaredEntity generate_comparable_to (final DeclaredEntity de) + { + final Iterator i0, i1; + final List resulting_signature; + final Type resulting_return_type; + final LambdaType lt; + + if (!(de instanceof LambdaType)) + { + return Type.ANY; + } + + lt = (LambdaType) de; + + if (lt.signature.size() != signature.size()) + { + return Type.ANY; + } + + resulting_signature = new ArrayList(); + resulting_return_type = + (Type) return_type.generate_comparable_to(lt.return_type); + + i0 = signature.iterator(); + i1 = lt.signature.iterator(); + + while(i0.hasNext()) + { + resulting_signature.add + ( + (Type) i0.next().generate_comparable_to(i1.next()) + ); + } + + return + new LambdaType + ( + get_origin(), + resulting_return_type, + name, + resulting_signature + ); + } + + @Override + public Type get_act_as_type () + { + return Type.LAMBDA; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(Lambda "); + sb.append(return_type.toString()); + sb.append(" ("); + + for (final Type t: signature) + { + sb.append(t.get_name()); + } + + sb.append("))::"); + sb.append(name); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/type/Type.java b/src/core/src/tonkadur/fate/v1/lang/type/Type.java index f848047..92ff859 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/Type.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/Type.java @@ -24,6 +24,7 @@ public class Type extends DeclaredEntity public static final Type DICT; public static final Type FLOAT; public static final Type INT; + public static final Type LAMBDA; public static final Type LIST; public static final Type REF; public static final Type RICH_TEXT; @@ -50,6 +51,7 @@ public class Type extends DeclaredEntity DICT = new Type(base, null, "dict"); FLOAT = new Type(base, null, "float"); INT = new Type(base, null, "int"); + LAMBDA = new Type(base, null, "lambda"); LIST = new Type(base, null, "list"); REF = new Type(base, null, "ref"); RICH_TEXT = new Type(base, null, "text"); @@ -62,6 +64,7 @@ public class Type extends DeclaredEntity ALL_TYPES.add(DICT); ALL_TYPES.add(FLOAT); ALL_TYPES.add(INT); + ALL_TYPES.add(LAMBDA); ALL_TYPES.add(LIST); ALL_TYPES.add(REF); ALL_TYPES.add(RICH_TEXT); diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index 2690cdf..a4cdb76 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -29,12 +29,8 @@ DECLARE_ALIAS_TYPE_KW: L_PAREN ((('declare'|'define'|'def')US('sub'US)?'type')|'typedef') SEP+; DECLARE_DICT_TYPE_KW: L_PAREN ('declare'|'define'|'def')US('dict'|'struct')(US'type')? SEP+; DECLARE_EVENT_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'event'(US'type')? SEP+; -DECLARE_LIST_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'list'(US'type')? SEP+; -DECLARE_REF_TYPE_KW: L_PAREN ('declare'|'define'|'def')US(('ref'('erence'?))|'ptr'|'pointer')(US'type')? SEP+; -DECLARE_SET_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'set'(US'type')? SEP+; DECLARE_TEXT_EFFECT_KW: L_PAREN ('declare'|'define'|'def')US'text'US'effect' SEP+; DECLARE_VARIABLE_KW: L_PAREN ('declare'|'define'|'def')US'var'('iable')? SEP+; -DEFINE_MACRO_KW: L_PAREN ('declare'|'define'|'def')US'macro' SEP+; DEFINE_SEQUENCE_KW: L_PAREN ('declare'|'define'|'def')US'seq'('uence')? SEP+; DIVIDE_KW: L_PAREN ('divide'|'/'|'div') SEP+; DO_WHILE_KW: L_PAREN ('do'US'while') SEP+; @@ -56,7 +52,6 @@ GREATER_EQUAL_THAN_KW: L_PAREN ('greater'US'equal'US'than'|'>='|'ge') SEP+; GREATER_THAN_KW: L_PAREN ('greater'US'than'|'>'|'gt') SEP+; IF_ELSE_KW: L_PAREN ('if'US'else') SEP+; IF_KW: L_PAREN 'if' SEP+; -IMACRO_KW: L_PAREN 'macro' SEP+; IMPLIES_KW: L_PAREN ('implies'|'=>'|'->') SEP+; INCLUDE_KW: L_PAREN 'include' SEP+; INDEX_OF_KW: L_PAREN ('index'US'of') SEP+; @@ -66,6 +61,8 @@ LOWER_THAN_KW: L_PAREN ('lower'US'than'|'<'|'lt') SEP+; MINUS_KW: L_PAREN ('minus'|'-') SEP+; MIN_KW: L_PAREN ('min'('imum'?)) SEP+; MAX_KW: L_PAREN ('max'('imum'?)) SEP+; +LAMBDA_KW: L_PAREN 'lambda' SEP+; +EVAL_KW: L_PAREN 'eval'('uate'?) SEP+; CLAMP_KW: L_PAREN ('clamp') SEP+; MODULO_KW: L_PAREN ('modulo'|'%'|'mod') SEP+; NEWLINE_KW: L_PAREN 'newline)'; @@ -74,7 +71,6 @@ NOT_KW: L_PAREN ('not'|'~'|'!') SEP+; ONE_IN_KW: L_PAREN ('exactly'US)?'one'(US'in')? SEP+; OR_KW: L_PAREN ('or'|'\\/') SEP+; RICH_TEXT_KW: L_PAREN (('rich'US)?'text') SEP+; -PARAMETER_KW: L_PAREN ('param'|'parameter'|'par') SEP+; PLAYER_CHOICE_KW: L_PAREN ('choice'|'user'US'choice'|'player'US'choice') SEP+; PLUS_KW: L_PAREN ('plus'|'+') SEP+; POWER_KW: L_PAREN ('power'|'^'|'**'|'pow') SEP+; @@ -94,9 +90,11 @@ SIZE_KW: L_PAREN 'size' SEP+; SWITCH_KW: L_PAREN 'switch' SEP+; TIMES_KW: L_PAREN ('times'|'*') SEP+; TRUE_KW: L_PAREN 'true)'; +DONE_KW: L_PAREN 'done)'; VAL_KW: L_PAREN ('val'|'value') SEP+; VARIABLE_KW: L_PAREN ('variable'|'var') SEP+; -VMACRO_KW: L_PAREN 'vmacro' SEP+; +VISIT_KW: L_PAREN ('call'|'visit')(US(('seq'('uence'?))|('proc'('edure'?))))? SEP+; +CONTINUE_AS_KW: L_PAREN (('continue'US('as'|'to'|'with'))|('jump'(US'to')?)|('go'US'to')|'exec')(US(('seq'('uence'?))|('proc'('edure'?))))? SEP+; WHILE_KW: L_PAREN 'while' SEP+; WORD: (~([ \t\r\n()])|'\\)'|'\\(')+; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index 22915e8..312ffef 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -27,9 +27,7 @@ options import tonkadur.fate.v1.error.IllegalReferenceNameException; import tonkadur.fate.v1.error.InvalidTypeException; - import tonkadur.fate.v1.error.NotInAMacroException; import tonkadur.fate.v1.error.UnknownExtensionContentException; - import tonkadur.fate.v1.error.UnknownParameterException; import tonkadur.fate.v1.error.UnknownVariableScopeException; import tonkadur.fate.v1.lang.*; @@ -43,8 +41,7 @@ options { Context CONTEXT; World WORLD; - TypedEntryList PARAMETERS; - List> ODD_VARS; + Deque> LOCAL_VARIABLES; int BREAKABLE_LEVELS; } @@ -56,9 +53,10 @@ fate_file [Context context, World world] { CONTEXT = context; WORLD = world; - PARAMETERS = null; - ODD_VARS = new ArrayList>(); + LOCAL_VARIABLES = new ArrayDeque>(); BREAKABLE_LEVELS = 0; + + LOCAL_VARIABLES.push(new HashMap()); } : WS* FATE_VERSION_KW WORD WS* R_PAREN WS* @@ -100,6 +98,18 @@ returns [List result] first_level_fate_instr: DEFINE_SEQUENCE_KW new_reference_name + ( + L_PAREN WS+ variable_list WS* R_PAREN + { + final Map variable_map; + + variable_map = new HashMap(); + + variable_map.putAll(($variable_list.result).as_map()); + + LOCAL_VARIABLES.push(variable_map); + } + ) pre_sequence_point=WS+ general_fate_sequence WS* @@ -131,27 +141,17 @@ first_level_fate_instr: sequence_origin, ($general_fate_sequence.result) ), - ($new_reference_name.result) + ($new_reference_name.result), + ($variable_list.result) ); WORLD.sequences().add(new_sequence); + LOCAL_VARIABLES.pop(); } | DECLARE_VARIABLE_KW type WS+ - name=new_reference_name - WS* - R_PAREN - { - final Origin start_origin, type_origin; - final Variable new_variable; - - start_origin = - CONTEXT.get_origin_at - ( - ($DECLARE_VARIABLE_KW.getLine()), - ($DECLARE_VARIABLE_KW.getCharPositionInLine()) ); new_variable = @@ -2498,8 +2498,6 @@ returns [Reference result] | ACCESS_KW value_reference WS+ value R_PAREN { $result = - Access.build - ( CONTEXT.get_origin_at ( ($ACCESS_KW.getLine()), @@ -2510,10 +2508,10 @@ returns [Reference result] ); } - | VARIABLE_KW WORD WS* R_PAREN + | (WORD | (VARIABLE_KW WORD WS* R_PAREN)) { final Origin target_var_origin; - final Variable target_var; + Variable target_var; final String[] subrefs; subrefs = ($WORD.text).split("\\."); @@ -2525,119 +2523,12 @@ returns [Reference result] ($WORD.getCharPositionInLine()) ); - target_var = WORLD.variables().get(target_var_origin, subrefs[0]); - - $result = - new VariableReference - ( - CONTEXT.get_origin_at - ( - ($VARIABLE_KW.getLine()), - ($VARIABLE_KW.getCharPositionInLine()) - ), - target_var - ); + target_var = LOCAL_VARIABLE.peekFirst().get(subrefs[0]); - if (subrefs.length > 1) + if (target_var == null) { - final List subrefs_list; - - subrefs_list = new ArrayList(Arrays.asList(subrefs)); - - subrefs_list.remove(0); - - $result = - FieldReference.build - ( - target_var_origin, - ($result), - subrefs_list - ); + target_var = WORLD.variables().get(target_var_origin, subrefs[0]); } - } - - | PARAMETER_KW WORD WS* R_PAREN - { - final Origin origin; - - origin = - CONTEXT.get_origin_at - ( - ($PARAMETER_KW.getLine()), - ($PARAMETER_KW.getCharPositionInLine()) - ); - - if (PARAMETERS == null) - { - ErrorManager.handle - ( - new NotInAMacroException(origin) - ); - } - else - { - final TypedEntryList.TypedEntry param; - final String[] subrefs; - - subrefs = ($WORD.text).split("\\."); - - param = PARAMETERS.as_map().get(subrefs[0]); - - if (param == null) - { - ErrorManager.handle - ( - new UnknownParameterException(origin, subrefs[0], PARAMETERS) - ); - - $result = new ParameterReference(origin, Type.ANY, ($WORD.text)); - } - else - { - $result = - new ParameterReference - ( - origin, - param.get_type(), - ($WORD.text) - ); - - if (subrefs.length > 1) - { - final List subrefs_list; - - subrefs_list = new ArrayList(Arrays.asList(subrefs)); - - subrefs_list.remove(0); - - $result = - FieldReference.build - ( - origin, - ($result), - subrefs_list - ); - } - } - } - } - - | WORD - { - final Origin target_var_origin; - final Variable target_var; - final String[] subrefs; - - subrefs = ($WORD.text).split("\\."); - - target_var_origin = - CONTEXT.get_origin_at - ( - ($WORD.getLine()), - ($WORD.getCharPositionInLine()) - ); - - target_var = WORLD.variables().get(target_var_origin, subrefs[0]); $result = new VariableReference diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java index 037a705..c88b8be 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java @@ -1,15 +1,14 @@ package tonkadur.wyrd.v1.compiler.fate.v1; -import tonkadur.wyrd.v1.compiler.util.AnonymousVariableManager; +import tonkadur.wyrd.v1.compiler.util.RegisterManager; import tonkadur.wyrd.v1.compiler.util.InstructionManager; -import tonkadur.wyrd.v1.lang.Variable; +import tonkadur.wyrd.v1.lang.Register; import tonkadur.wyrd.v1.lang.World; public class Compiler { - protected final AnonymousVariableManager anonymous_variables; - protected final MacroManager macro_manager; + protected final RegisterManager registers; protected final InstructionManager assembler; protected final World wyrd_world; @@ -27,13 +26,13 @@ public class Compiler compiler.compile_extensions(fate_world); compiler.compile_types(fate_world); - compiler.compile_variables(fate_world); + compiler.compile_registers(fate_world); compiler.compile_main_sequence(fate_world); compiler.compile_sequences(fate_world); - compiler.add_anonymous_variables(); + compiler.add_registers(); return compiler.wyrd_world; } @@ -43,7 +42,7 @@ public class Compiler this.wyrd_world = wyrd_world; macro_manager = new MacroManager(); - anonymous_variables = new AnonymousVariableManager(); + registers = new RegisterManager(); assembler = new InstructionManager(); } @@ -74,7 +73,7 @@ public class Compiler } } - protected void compile_variables + protected void compile_registers ( final tonkadur.fate.v1.lang.World fate_world ) @@ -82,11 +81,11 @@ public class Compiler { for ( - final tonkadur.fate.v1.lang.Variable variable: - fate_world.variables().get_all() + final tonkadur.fate.v1.lang.Register register: + fate_world.registers().get_all() ) { - VariableCompiler.compile(this, variable); + RegisterCompiler.compile(this, register); } } @@ -119,12 +118,17 @@ public class Compiler ); } - protected void add_anonymous_variables () + protected void add_registers () throws Throwable { - for (final Variable variable: anonymous_variables.get_all_variables()) + for (final DictType type: registers.get_context_structures_types()) { - wyrd_world.add_variable(variable); + wyrd_world.add_dict_type(type); + } + + for (final Register register: registers.get_base_registers()) + { + wyrd_world.add_register(register); } } @@ -133,9 +137,9 @@ public class Compiler return wyrd_world; } - public AnonymousVariableManager anonymous_variables () + public RegisterManager registers () { - return anonymous_variables; + return registers; } public InstructionManager assembler () diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java index 7a9d223..afd53c2 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java @@ -33,18 +33,18 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor { protected final Compiler compiler; protected final List init_instructions; - protected final List reserved_variables; + protected final Collection reserved_registers; protected boolean instructions_were_generated; protected Computation result_as_computation; - protected Ref result_as_ref; + protected Address result_as_address; public ComputationCompiler (final Compiler compiler) { this.compiler = compiler; - reserved_variables = new ArrayList(); + reserved_registers = new ArrayList(); init_instructions = new ArrayList(); - result_as_ref = null; + result_as_address = null; result_as_computation = null; instructions_were_generated = false; } @@ -74,69 +74,68 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor } else { - result_as_computation = new ValueOf(result_as_ref); + result_as_computation = new ValueOf(result_as_address); return result_as_computation; } } - public Ref get_ref () + public Address get_address () { - if (result_as_ref == null) + if (result_as_address == null) { System.err.println("[P] Missing generate_ref()!"); } - return result_as_ref; + return result_as_address; } - public void generate_ref () + public void generate_address () { - if ((!instructions_were_generated) && (result_as_ref == null)) + if ((!instructions_were_generated) && (result_as_address == null)) { - final Ref result; + final Address result; - result = reserve(result_as_computation.get_type()); + result = reserve(result_as_computation.get_type()).get_address(); init_instructions.add ( new SetValue(result, result_as_computation) ); - - result_as_ref = result; + result_as_address = result; } } - public void release_variables () + public void release_registers () { - for (final Ref ref: reserved_variables) + for (final Register reg: reserved_registers) { - compiler.anonymous_variables().release(ref); + compiler.registers().release(reg); } } protected void assimilate (final ComputationCompiler cc) { init_instructions.addAll(cc.init_instructions); - reserved_variables.addAll(cc.reserved_variables); + reserved_registers.addAll(cc.reserved_registers); } - protected Ref reserve (final Type t) + protected Register reserve (final Type t) { - final Ref result; + final Register result; - result = compiler.anonymous_variables().reserve(t); + result = compiler.registers().reserve(t); - reserved_variables.add(result); + reserved_registers.add(result); return result; } @Override - public void visit_at_reference + public void visit_at_address ( - final tonkadur.fate.v1.lang.computation.AtReference n + final tonkadur.fate.v1.lang.computation.AtAddress n ) throws Throwable { @@ -148,17 +147,17 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor assimilate(n_cc); - result_as_ref = - new Ref + result_as_address = + new Address ( n_cc.get_computation(), TypeCompiler.compile ( compiler, ( - (tonkadur.fate.v1.lang.type.RefType) + (tonkadur.fate.v1.lang.type.AddressType) n.get_parent().get_type() - ).get_referenced_type() + ).get_addressd_type() ) ); } @@ -225,8 +224,8 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor is_safe = is_safe && !cond_cc.has_init() && !val_cc.has_init(); - reserved_variables.addAll(cond_cc.reserved_variables); - reserved_variables.addAll(val_cc.reserved_variables); + reserved_registers.addAll(cond_cc.reserved_registers); + reserved_registers.addAll(val_cc.reserved_registers); cc_list.add(new Cons(cond_cc, val_cc)); } @@ -259,7 +258,8 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor else { final Iterator> it; - final Ref result; + final Register result_register; + final Address result_address; Cons next; List new_value, new_cond; Instruction prev_branch; @@ -269,6 +269,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor next = it.next(); result = reserve(next.get_cdr().get_computation().get_type()); + result_as_address = result.get_address(); new_value = new ArrayList(); @@ -277,7 +278,10 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor new_value.add(next.get_cdr().get_init()); } - new_value.add(new SetValue(result, next.get_cdr().get_computation())); + new_value.add + ( + new SetValue(result_as_address, next.get_cdr().get_computation()) + ); prev_branch = compiler.assembler().merge(new_value); @@ -300,14 +304,14 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor new_value.add ( - new SetValue(result, next.get_cdr().get_computation()) + new SetValue(result_as_address, next.get_cdr().get_computation()) ); new_cond.add ( IfElse.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), next.get_car().get_computation(), compiler.assembler().merge(new_value), @@ -320,7 +324,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor init_instructions.add(prev_branch); - result_as_computation = new ValueOf(result); + result_as_computation = result.get_value(); } } @@ -354,7 +358,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor n.get_collection().get_visited_by(collection_compiler); n.get_element().get_visited_by(element_compiler); - collection_compiler.generate_ref(); + collection_compiler.generate_address(); assimilate(collection_compiler); assimilate(element_compiler); @@ -367,7 +371,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ).is_set() ) { - final Ref was_found, index, element; + final Register was_found, index, element; was_found = reserve(Type.BOOLEAN); index = reserve(Type.INT); @@ -375,62 +379,72 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor init_instructions.add ( - new SetValue(element, element_compiler.get_computation()) + new SetValue + ( + element.get_address(), + element_compiler.get_computation() + ) ); init_instructions.add ( BinarySearch.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - new ValueOf(element), - new Size(collection_compiler.get_ref()), - collection_compiler.get_ref(), - was_found, - index + element.get_value(), + new Size(collection_compiler.get_address()), + collection_compiler.get_address(), + was_found.get_address(), + index.get_address() ) ); result_as_computation = new IfElseComputation ( - new ValueOf(was_found), + was_found.get_value(), Constant.ONE, Constant.ZERO ); } else { - final Ref element; + final Register result, element; + + result = reserve(Type.INT); - result_as_ref = reserve(Type.INT); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); element = reserve(element_compiler.get_computation().get_type()); init_instructions.add ( - new SetValue(element, element_compiler.get_computation()) + new SetValue + ( + element.get_address(), + element_compiler.get_computation() + ) ); init_instructions.add ( CountOccurrences.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - new ValueOf(element), - new Size(collection_compiler.get_ref()), - collection_compiler.get_ref(), - result_as_ref + element.get_value(), + new Size(collection_compiler.get_address()), + collection_compiler.get_address(), + result_as_address ) ); - result_as_computation = new ValueOf(result_as_ref); } } @Override - public void visit_field_reference + public void visit_field_address ( - final tonkadur.fate.v1.lang.computation.FieldReference n + final tonkadur.fate.v1.lang.computation.FieldAddress n ) throws Throwable { @@ -442,10 +456,10 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor assimilate(n_cc); - result_as_ref = - new RelativeRef + result_as_address = + new RelativeAddress ( - n_cc.get_ref(), + n_cc.get_address(), new Constant(Type.STRING, n.get_field_name()), TypeCompiler.compile ( @@ -487,10 +501,10 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor * on the interpreter. * * Instead, we just convert the ifelse into an instruction-based - * equivalent and store the result in an anonymous variable to be used + * equivalent and store the result in an anonymous register to be used * here. */ - final Ref if_else_result; + final Register if_else_result; final List if_true_branch; final List if_false_branch; @@ -511,12 +525,20 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor if_true_branch.add ( - new SetValue(if_else_result, if_true_cc.get_computation()) + new SetValue + ( + if_else_result.get_address(), + if_true_cc.get_computation() + ) ); if_false_branch.add ( - new SetValue(if_else_result, if_false_cc.get_computation()) + new SetValue + ( + if_else_result.get_addresss(), + if_false_cc.get_computation() + ) ); if (cond_cc.has_init()) @@ -528,7 +550,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ( IfElse.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), cond_cc.get_computation(), compiler.assembler().merge(if_true_branch), @@ -536,11 +558,12 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ) ); - reserved_variables.addAll(cond_cc.reserved_variables); - reserved_variables.addAll(if_true_cc.reserved_variables); - reserved_variables.addAll(if_false_cc.reserved_variables); + reserved_registers.addAll(cond_cc.reserved_registers); + reserved_registers.addAll(if_true_cc.reserved_registers); + reserved_registers.addAll(if_false_cc.reserved_registers); - result_as_computation = new ValueOf(if_else_result); + result_as_computation = if_else_result.get_value(); + result_as_address = if_else_result.get_address(); } else { @@ -565,6 +588,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ) throws Throwable { + final Register result; final ComputationCompiler collection_compiler, element_compiler; collection_compiler = new ComputationCompiler(compiler); @@ -578,7 +602,9 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor assimilate(collection_compiler); assimilate(element_compiler); - result_as_ref = reserve(Type.BOOLEAN); + result = reserve(Type.BOOLEAN); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); if ( @@ -588,95 +614,63 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ).is_set() ) { - final Ref index, element; + final Register index, element; index = reserve(Type.INT); element = reserve(element_compiler.get_computation().get_type()); init_instructions.add ( - new SetValue(element, element_compiler.get_computation()) + new SetValue + ( + element.get_address(), + element_compiler.get_computation() + ) ); init_instructions.add ( BinarySearch.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - new ValueOf(element), - new Size(collection_compiler.get_ref()), - collection_compiler.get_ref(), - result_as_ref, - index + element.get_value(), + new Size(collection_compiler.get_address()), + collection_compiler.get_address(), + result_as_address, + index.get_address(); ) ); - result_as_computation = new ValueOf(result_as_ref); } else { - final Ref index, element; + final Register index, element; index = reserve(Type.INT); element = reserve(element_compiler.get_computation().get_type()); - result_as_ref = reserve(Type.BOOLEAN); - init_instructions.add ( - new SetValue(element, element_compiler.get_computation()) + new SetValue + ( + element.get_address(), + element_compiler.get_computation() + ) ); init_instructions.add ( IterativeSearch.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - new ValueOf(element), - new Size(collection_compiler.get_ref()), - collection_compiler.get_ref(), - result_as_ref, - index + element.get_value(), + new Size(collection_compiler.get_address()), + collection_compiler.get_address(), + result_as_address, + index.get_address() ) ); - - result_as_computation = new ValueOf(result_as_ref); - } - } - - @Override - public void visit_macro_value_call - ( - final tonkadur.fate.v1.lang.computation.MacroValueCall n - ) - throws Throwable - { - final List parameters; - - parameters = new ArrayList(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation fate_computation: - n.get_parameters() - ) - { - final ComputationCompiler cc; - - cc = new ComputationCompiler(compiler); - - fate_computation.get_visited_by(cc); - - cc.generate_ref(); - - assimilate(cc); - - parameters.add(cc.get_ref()); } - - compiler.macros().push(n.get_macro(), parameters); - n.get_actual_value_node().get_visited_by(this); - compiler.macros().pop(); } @Override @@ -789,13 +783,16 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ) ) { - final Ref candidate; - final Computation value_of_candidate; + final Register candidate; candidate = reserve(operands.get(0).get_type()); - value_of_candidate = new ValueOf(candidate); + result_as_address = candidate.get_address(); + result_as_computation = candidate.get_value(); - init_instructions.add(new SetValue(candidate, operands.get(0))); + init_instructions.add + ( + new SetValue(result_as_address, operands.get(0)) + ); for (final Computation operand: operands) { @@ -803,18 +800,16 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ( new SetValue ( - candidate, + result_as_address, new IfElseComputation ( - Operation.less_than(value_of_candidate, operand), - value_of_candidate, + Operation.less_than(result_as_computation, operand), + result_as_computation, operand ) ) ); } - - result_as_computation = value_of_candidate; } else if ( @@ -824,13 +819,16 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ) ) { - final Ref candidate; - final Computation value_of_candidate; + final Register candidate; candidate = reserve(operands.get(0).get_type()); - value_of_candidate = new ValueOf(candidate); + result_as_address = candidate.get_address(); + result_as_computation = candidate.get_value(); - init_instructions.add(new SetValue(candidate, operands.get(0))); + init_instructions.add + ( + new SetValue(result_as_address, operands.get(0)) + ); for (final Computation operand: operands) { @@ -838,18 +836,16 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ( new SetValue ( - candidate, + result_as_address, new IfElseComputation ( - Operation.greater_than(value_of_candidate, operand), - value_of_candidate, + Operation.greater_than(result_as_computation, operand), + result_as_computation, operand ) ) ); } - - result_as_computation = value_of_candidate; } else if ( @@ -889,18 +885,19 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ) { final Type t; - final Ref candidate; - final Computation value_of_candidate; + final Register candidate; + final Computation result_as_computation; t = operands.get(2).get_type(); candidate = reserve(t); - value_of_candidate = new ValueOf(candidate); + result_as_address = candidate.get_address(); + result_as_computation = candidate.get_value(); init_instructions.add ( new SetValue ( - candidate, + result_as_address, new IfElseComputation ( Operation.greater_than(operands.get(2), operands.get(1)), @@ -913,17 +910,15 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ( new SetValue ( - candidate, + result_as_address, new IfElseComputation ( - Operation.less_than(value_of_candidate, operands.get(0)), + Operation.less_than(result_as_computation, operands.get(0)), operands.get(0), - value_of_candidate + result_as_computation ) ) ); - - result_as_computation = value_of_candidate; } else if ( @@ -1105,6 +1100,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor System.err.println("[P] Unknown Fate operator '" + fate_op_name+ "'."); } } + @Override public void visit_size_operator ( @@ -1120,7 +1116,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor assimilate(cc); - result_as_computation = new Size(cc.get_ref()); + result_as_computation = new Size(cc.get_address()); } @Override @@ -1131,11 +1127,14 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor throws Throwable { final ComputationCompiler elem_cc, collection_cc; - final Ref result, result_found; + final Register result, result_found; result = reserve(Type.INT); result_found = reserve(Type.BOOLEAN); + result_as_address = result.get_address(); + result_as_computation = result.get_value(); + elem_cc = new ComputationCompiler(compiler); collection_cc = new ComputationCompiler(compiler); @@ -1149,17 +1148,15 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ( IterativeSearch.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), elem_cc.get_computation(), - new Size(collection_cc.get_ref()), - collection_cc.get_ref(), - result_found, - result + new Size(collection_cc.get_address()), + collection_cc.get_address(), + result_found.get_address(), + result_as_address ) ); - - result_as_ref = result; } @Override @@ -1180,22 +1177,22 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ) throws Throwable { - final ComputationCompiler i_cc, n_cc; + final ComputationCompiler extra_address_cc, base_address_cc; - n_cc = new ComputationCompiler(compiler); - i_cc = new ComputationCompiler(compiler); + base_address_cc = new ComputationCompiler(compiler); + extra_address_cc = new ComputationCompiler(compiler); - n.get_parent().get_visited_by(n_cc); - n.get_index().get_visited_by(i_cc); + n.get_parent().get_visited_by(base_address_cc); + n.get_index().get_visited_by(extra_address_cc); - assimilate(n_cc); - assimilate(i_cc); + assimilate(base_address_cc); + assimilate(extra_address_cc); - result_as_ref = - new RelativeRef + result_as_address = + new RelativeAddress ( - n_cc.get_ref(), - new Cast(i_cc.get_computation(), Type.STRING), + base_address_cc.get_address(), + new Cast(extra_address_cc.get_computation(), Type.STRING), TypeCompiler.compile ( compiler, @@ -1249,19 +1246,9 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor } @Override - public void visit_parameter_reference - ( - final tonkadur.fate.v1.lang.computation.ParameterReference n - ) - throws Throwable - { - result_as_ref = compiler.macros().get_parameter_ref(n.get_name()); - } - - @Override - public void visit_ref_operator + public void visit_address_operator ( - final tonkadur.fate.v1.lang.computation.RefOperator n + final tonkadur.fate.v1.lang.computation.AddressOperator n ) throws Throwable { @@ -1273,7 +1260,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor assimilate(n_cc); - result_as_computation = n_cc.result_as_ref; + result_as_computation = n_cc.get_address() } @Override @@ -1338,6 +1325,26 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor new RichText(Collections.singletonList(cc.get_computation())); } + @Override + public void visit_lambda_expression + ( + final tonkadur.fate.v1.lang.computation.LambdaExpression n + ) + throws Throwable + { + /* TODO */ + } + + @Override + public void visit_lambda_evaluation + ( + final tonkadur.fate.v1.lang.computation.LambdaEvaluation n + ) + throws Throwable + { + /* TODO */ + } + @Override public void visit_variable_reference ( @@ -1345,9 +1352,15 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ) throws Throwable { - result_as_ref = - compiler.world().get_variable(n.get_variable().get_name()).get_ref(); + final Register register; + + register = + compiler.registers().get_register + ( + n.get_variable().get_name() + ); - result_as_computation = new ValueOf(result_as_ref); + result_as_address = register.get_address(); + result_as_computation = register.get_value(); } } 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 index 3bbde05..f088c1d 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java @@ -19,8 +19,8 @@ import tonkadur.wyrd.v1.lang.type.MapType; 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.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; import tonkadur.wyrd.v1.lang.computation.Size; import tonkadur.wyrd.v1.lang.computation.ValueOf; @@ -34,7 +34,6 @@ import tonkadur.wyrd.v1.lang.instruction.ResolveChoices; import tonkadur.wyrd.v1.lang.instruction.SetPC; import tonkadur.wyrd.v1.lang.instruction.SetValue; -import tonkadur.wyrd.v1.compiler.util.AnonymousVariableManager; import tonkadur.wyrd.v1.compiler.util.BinarySearch; import tonkadur.wyrd.v1.compiler.util.InsertAt; import tonkadur.wyrd.v1.compiler.util.If; @@ -85,58 +84,54 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor * * ) */ - final ComputationCompiler element_compiler, reference_compiler; - final Ref element, collection, collection_size; - final Ref element_found, element_index; + final ComputationCompiler element_compiler, address_compiler; + final Address element, collection; + final Register collection_size, element_found, element_index; final Type element_type; - final Computation value_of_element, value_of_collection_size; element_compiler = new ComputationCompiler(compiler); ae.get_element().get_visited_by(element_compiler); + element_compiler.generate_address(); + if (element_compiler.has_init()) { result.add(element_compiler.get_init()); } element_type = element_compiler.get_computation().get_type(); - element = compiler.anonymous_variables().reserve(element_type); - result.add(new SetValue(element, element_compiler.get_computation())); - element_compiler.release_variables(); + element = element_compiler.get_address(); - reference_compiler = new ComputationCompiler(compiler); - ae.get_collection().get_visited_by(reference_compiler); + address_compiler = new ComputationCompiler(compiler); + ae.get_collection().get_visited_by(address_compiler); - if (reference_compiler.has_init()) + if (address_compiler.has_init()) { - result.add(reference_compiler.get_init()); + result.add(address_compiler.get_init()); } - collection = reference_compiler.get_ref(); - - element_found = compiler.anonymous_variables().reserve(Type.BOOLEAN); - element_index = compiler.anonymous_variables().reserve(Type.INT); - collection_size = compiler.anonymous_variables().reserve(Type.INT); + collection = address_compiler.get_address(); - value_of_element = new ValueOf(element); - value_of_collection_size = new ValueOf(collection_size); + element_found = compiler.registers().reserve(Type.BOOLEAN); + element_index = compiler.registers().reserve(Type.INT); + collection_size = compiler.registers().reserve(Type.INT); result.add ( - new SetValue(collection_size, new Size(collection)) + new SetValue(collection_size.get_address(), new Size(collection)) ); result.add ( BinarySearch.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - value_of_element, - value_of_collection_size, + new ValueOf(element), + collection_size.get_value(), collection, - element_found, - element_index + element_found.get_address(), + element_index.get_address() ) ); @@ -144,27 +139,27 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( If.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - Operation.not(new ValueOf(element_found)), + Operation.not(element_found.get_value()), InsertAt.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - element_index, - value_of_element, - value_of_collection_size, + element_index.get_address(), + new ValueOf(element), + collection_size.get_value(), collection ) ) ); - compiler.anonymous_variables().release(element); - compiler.anonymous_variables().release(element_found); - compiler.anonymous_variables().release(element_index); - compiler.anonymous_variables().release(collection_size); + compiler.registers().release(element_found); + compiler.registers().release(element_index); + compiler.registers().release(collection_size); - reference_compiler.release_variables(); + element_compiler.release_variables(); + address_compiler.release_variables(); } protected void add_element_to_list @@ -179,25 +174,25 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor * * Wyrd: * (set - * (relative_ref collection ( (cast int string (size collection)) )) + * (relative_address collection ( (cast int string (size collection)) )) * (element) * ) */ - final Ref collection_as_ref; - final ComputationCompiler element_compiler, reference_compiler; + final Address collection_as_address; + final ComputationCompiler element_compiler, address_compiler; element_compiler = new ComputationCompiler(compiler); ae.get_element().get_visited_by(element_compiler); - reference_compiler = new ComputationCompiler(compiler); + address_compiler = new ComputationCompiler(compiler); - ae.get_collection().get_visited_by(reference_compiler); + ae.get_collection().get_visited_by(address_compiler); - if (reference_compiler.has_init()) + if (address_compiler.has_init()) { - result.add(reference_compiler.get_init()); + result.add(address_compiler.get_init()); } if (element_compiler.has_init()) @@ -205,18 +200,18 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor result.add(element_compiler.get_init()); } - collection_as_ref = reference_compiler.get_ref(); + collection_as_address = address_compiler.get_address(); result.add ( new SetValue ( - new RelativeRef + new RelativeAddress ( - collection_as_ref, + collection_as_address, new Cast ( - new Size(collection_as_ref), + new Size(collection_as_address), Type.STRING ), element_compiler.get_computation().get_type() @@ -225,10 +220,20 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ) ); - reference_compiler.release_variables(); + address_compiler.release_variables(); element_compiler.release_variables(); } + @Override + public void visit_local_variable + ( + final tonkadur.fate.v1.lang.instruction.LocalVariable n + ) + throws Throwable + { + /* TODO */ + } + @Override public void visit_add_element ( @@ -314,32 +319,32 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor * * Wyrd: */ - final ComputationCompiler reference_compiler; - final Ref collection_ref; + final ComputationCompiler address_compiler; + final Address collection_address; - reference_compiler = new ComputationCompiler(compiler); + address_compiler = new ComputationCompiler(compiler); - c.get_collection().get_visited_by(reference_compiler); + c.get_collection().get_visited_by(address_compiler); - if (reference_compiler.has_init()) + if (address_compiler.has_init()) { - result.add(reference_compiler.get_init()); + result.add(address_compiler.get_init()); } - collection_ref = reference_compiler.get_ref(); + collection_address = address_compiler.get_address(); result.add ( Clear.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - new Size(collection_ref), - collection_ref + new Size(collection_address), + collection_address ) ); - reference_compiler.release_variables(); + address_compiler.release_variables(); } public void visit_reverse_list @@ -353,32 +358,32 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor * * Wyrd: */ - final ComputationCompiler reference_compiler; - final Ref collection_ref; + final ComputationCompiler address_compiler; + final Address collection_address; - reference_compiler = new ComputationCompiler(compiler); + address_compiler = new ComputationCompiler(compiler); - n.get_collection().get_visited_by(reference_compiler); + n.get_collection().get_visited_by(address_compiler); - if (reference_compiler.has_init()) + if (address_compiler.has_init()) { - result.add(reference_compiler.get_init()); + result.add(address_compiler.get_init()); } - collection_ref = reference_compiler.get_ref(); + collection_address = address_compiler.get_address(); result.add ( ReverseList.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - new Size(collection_ref), - collection_ref + new Size(collection_address), + collection_address ) ); - reference_compiler.release_variables(); + address_compiler.release_variables(); } @Override @@ -413,7 +418,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor * > * > */ - Ref anon; + Address anon; final List < Cons @@ -442,14 +447,14 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor n.get_target().get_visited_by(target_cc); - target_cc.generate_ref(); + target_cc.generate_address(); if (target_cc.has_init()) { result.add(target_cc.get_init()); } - anon = target_cc.get_ref(); + anon = target_cc.get_address(); value_of_anon = new ValueOf(anon); for @@ -481,7 +486,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( IfElse.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), Operation.equals(value_of_anon, cc.get_computation()), ic.get_result(), @@ -527,26 +532,26 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor throws Throwable { final ComputationCompiler cc; - final Ref target; + final Address target; cc = new ComputationCompiler(compiler); - n.get_reference().get_visited_by(cc); + n.get_address().get_visited_by(cc); if (cc.has_init()) { result.add(cc.get_init()); } - target = cc.get_ref(); + target = cc.get_address(); if (target == null) { System.err.println ( "[P] Argument in (free " - + n.get_reference() - + ") did not compile to a reference." + + n.get_address() + + ") did not compile to a address." ); } @@ -591,7 +596,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( While.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), cc.get_init(), cc.get_computation(), @@ -609,7 +614,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( While.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), cc.get_computation(), compiler.assembler().merge(body) @@ -661,13 +666,13 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( While.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), compiler.assembler().merge(pre_cond_instructions), cc.get_computation(), NOP.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler() ) ), @@ -724,7 +729,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( While.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), cc.get_init(), cc.get_computation(), @@ -742,7 +747,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( While.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), cc.get_computation(), compiler.assembler().merge(body) @@ -763,9 +768,8 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor final String end_of_loop_label; final ComputationCompiler cc; final List new_body; - final Ref index, current_value, collection_size; - final Ref collection; - final Computation value_of_index; + final Register index, collection_size, current_value; + final Address collection; final Type member_type; /* @@ -782,8 +786,8 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor cc = new ComputationCompiler(compiler); new_body = new ArrayList(); - index = compiler.anonymous_variables().reserve(Type.INT); - collection_size = compiler.anonymous_variables().reserve(Type.INT); + index = compiler.registers().reserve(Type.INT); + collection_size = compiler.registers().reserve(Type.INT); result.add(new SetValue(index, Constant.ZERO)); @@ -794,36 +798,33 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor result.add(cc.get_init()); } - collection = cc.get_ref(); + collection = cc.get_address(); - result.add(new SetValue(collection_size, new Size(collection))); - - value_of_index = new ValueOf(index); + result.add + ( + new SetValue(collection_size.get_address(), new Size(collection)) + ); member_type = ((MapType) collection.get_target_type()).get_member_type(); - current_value = compiler.anonymous_variables().reserve(member_type); + current_value = compiler.registers().reserve(member_type); end_of_loop_label = compiler.assembler().generate_label(""); compiler.assembler().push_context_label("breakable", end_of_loop_label); - compiler.macros().add_wild_parameter - ( - n.get_parameter_name(), - current_value - ); + compiler.registers().bind(current_value, n.get_parameter_name()); new_body.add ( new SetValue ( - current_value, + current_value.get_address(), new ValueOf ( - new RelativeRef + new RelativeAddress ( collection, - new Cast(value_of_index, Type.STRING), + new Cast(index.get_value(), Type.STRING), member_type ) ) @@ -846,7 +847,11 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor new_body.add ( - new SetValue(index, Operation.plus(Constant.ONE, value_of_index)) + new SetValue + ( + index.get_address(), + Operation.plus(Constant.ONE, index.get_value()) + ) ); result.add @@ -855,24 +860,24 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( While.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), Operation.less_than ( - value_of_index, - new ValueOf(collection_size) + index.get_value(), + collection_size.get_value() ), compiler.assembler.merge(new_body) ), end_of_loop_label ) ); - compiler.macros().remove_wild_parameter(n.get_parameter_name()); + compiler.registers().unbind(n.get_parameter_name()); compiler.assembler().pop_context_label("breakable"); - compiler.anonymous_variables().release(index); - compiler.anonymous_variables().release(current_value); - compiler.anonymous_variables().release(collection_size); + compiler.registers().release(index); + compiler.registers().release(current_value); + compiler.registers().release(collection_size); } @Override @@ -883,18 +888,18 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor throws Throwable { final ComputationCompiler index_cc, collection_cc; - final Ref collection, collection_size; - final Computation value_of_collection_size; + final Address collection; + final Register collection_size; index_cc = new ComputationCompiler(compiler); collection_cc = new ComputationCompiler(compiler); - collection_size = compiler.anonymous_variables().reserve(Type.INT); + collection_size = compiler.registers().reserve(Type.INT); n.get_index().get_visited_by(index_cc); n.get_collection().get_visited_by(collection_cc); - index_cc.generate_ref(); + index_cc.generate_address(); if (index_cc.has_init()) { @@ -906,25 +911,26 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor result.add(collection_cc.get_init()); } - collection = collection_cc.get_ref(); - - value_of_collection_size = new ValueOf(collection_size); + collection = collection_cc.get_address(); - result.add(new SetValue(collection_size, new Size(collection))); + result.add + ( + new SetValue(collection_size.get_address(), new Size(collection)) + ); result.add ( RemoveAt.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - index_cc.get_ref(), - value_of_collection_size, + index_cc.get_address(), + collection_size.get_value(), collection ) ); - compiler.anonymous_variables().release(collection_size); + compiler.registers().release(collection_size); index_cc.release_variables(); collection_cc.release_variables(); @@ -980,7 +986,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( NOP.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler() ) ); @@ -1014,7 +1020,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( IfElse.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), cc.get_computation(), ic.get_result(), @@ -1111,7 +1117,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( IfElse.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), cc.get_computation(), if_true_ic.get_result(), @@ -1152,7 +1158,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( If.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), cc.get_computation(), if_true_ic.get_result() @@ -1191,54 +1197,13 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor } @Override - public void visit_macro_call + public void visit_done ( - final tonkadur.fate.v1.lang.instruction.MacroCall n + final tonkadur.fate.v1.lang.instruction.Done n ) throws Throwable { - /* - * Fate: (macro c0 ... cn) - * - * Wyrd - */ - final List cc_list; - final List parameters; - - cc_list = new ArrayList(); - parameters = new ArrayList(); - - for - ( - final tonkadur.fate.v1.lang.meta.Computation fate_computation: - n.get_parameters() - ) - { - final ComputationCompiler cc; - - cc = new ComputationCompiler(compiler); - - fate_computation.get_visited_by(cc); - - cc.generate_ref(); - - if (cc.has_init()) - { - result.add(cc.get_init()); - } - - cc_list.add(cc); - parameters.add(cc.get_ref()); - } - - compiler.macros().push(n.get_macro(), parameters); - n.get_macro().get_root().get_visited_by(this); - compiler.macros().pop(); - - for (final ComputationCompiler cc: cc_list) - { - cc.release_variables(); - } + /* TODO */ } @Override @@ -1421,22 +1386,18 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor * > */ final ComputationCompiler elem_cc, collection_cc; - final Ref elem, collection_size, collection; + final Register collection_size; + final Address elem, collection; elem_cc = new ComputationCompiler(compiler); collection_cc = new ComputationCompiler(compiler); - collection_size = compiler.anonymous_variables().reserve(Type.INT); + collection_size = compiler.registers().reserve(Type.INT); n.get_element().get_visited_by(elem_cc); n.get_collection().get_visited_by(collection_cc); - elem = - compiler.anonymous_variables().reserve - ( - elem_cc.get_computation().get_type() - ); - + elem_cc.generate_address(); if (elem_cc.has_init()) { @@ -1448,13 +1409,10 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor result.add(collection_cc.get_init()); } - collection = collection_cc.get_ref(); + collection = collection_cc.get_address(); - result.add(new SetValue(elem, elem_cc.get_computation())); result.add(new SetValue(collection_size, new Size(collection))); - elem_cc.release_variables(); - if ( ( @@ -1464,10 +1422,10 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ) { final Computation value_of_elem, value_of_collection_size; - final Ref index, found; + final Register index, found; - index = compiler.anonymous_variables().reserve(Type.INT); - found = compiler.anonymous_variables().reserve(Type.BOOLEAN); + index = compiler.registers().reserve(Type.INT); + found = compiler.registers().reserve(Type.BOOLEAN); value_of_elem = new ValueOf(elem); value_of_collection_size = new ValueOf(collection_size); @@ -1476,36 +1434,38 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( BinarySearch.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - value_of_elem, + new ValueOf(elem), value_of_collection_size, collection, - found, - index + found.get_address(), + index.get_address() ) ); + elem_cc.release_variables(); + result.add ( If.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - new ValueOf(found), + found.get_value(), RemoveAt.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - index, + index.get_address(), value_of_collection_size, collection ) ) ); - compiler.anonymous_variables().release(index); - compiler.anonymous_variables().release(found); + compiler.registers().release(index); + compiler.registers().release(found); } else { @@ -1513,19 +1473,20 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( RemoveAllOf.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), new ValueOf(elem), new ValueOf(collection_size), collection ) ); + + elem_cc.release_variables(); } collection_cc.release_variables(); - compiler.anonymous_variables().release(elem); - compiler.anonymous_variables().release(collection_size); + compiler.registers().release(collection_size); } @Override @@ -1573,26 +1534,21 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor * ) */ final ComputationCompiler elem_cc, collection_cc; - final Ref elem, collection_size, found, index; - final Ref collection; + final Register collection_size, found, index; + final Address elem, collection; final Computation value_of_collection_size; elem_cc = new ComputationCompiler(compiler); collection_cc = new ComputationCompiler(compiler); - collection_size = compiler.anonymous_variables().reserve(Type.INT); - found = compiler.anonymous_variables().reserve(Type.BOOLEAN); - index = compiler.anonymous_variables().reserve(Type.INT); + collection_size = compiler.registers().reserve(Type.INT); + found = compiler.registers().reserve(Type.BOOLEAN); + index = compiler.registers().reserve(Type.INT); n.get_element().get_visited_by(elem_cc); n.get_collection().get_visited_by(collection_cc); - elem = - compiler.anonymous_variables().reserve - ( - elem_cc.get_computation().get_type() - ); - + elem_cc.generate_address(); if (elem_cc.has_init()) { @@ -1604,7 +1560,8 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor result.add(collection_cc.get_init()); } - collection = collection_cc.get_ref(); + elem = elem_cc.get_address(); + collection = collection_cc.get_address(); value_of_collection_size = new ValueOf(collection_size); @@ -1625,13 +1582,13 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( BinarySearch.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), new ValueOf(elem), value_of_collection_size, collection, - found, - index + found.get_address(), + index.get_address() ) ); } @@ -1641,40 +1598,40 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ( IterativeSearch.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), new ValueOf(elem), value_of_collection_size, collection, - found, - index + found.get_address(), + index.get_address() ) ); } - compiler.anonymous_variables().release(elem); + compiler.registers().release(elem); result.add ( If.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), new ValueOf(found), RemoveAt.generate ( - compiler.anonymous_variables(), + compiler.registers(), compiler.assembler(), - index, + index.get_address(), value_of_collection_size, collection ) ) ); - compiler.anonymous_variables().release(index); - compiler.anonymous_variables().release(found); - compiler.anonymous_variables().release(collection_size); + compiler.registers().release(index); + compiler.registers().release(found); + compiler.registers().release(collection_size); collection_cc.release_variables(); } @@ -1685,6 +1642,16 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor final tonkadur.fate.v1.lang.instruction.SequenceCall n ) throws Throwable + { + /* TODO */ + } + + @Override + public void visit_sequence_jump + ( + final tonkadur.fate.v1.lang.instruction.SequenceJump n + ) + throws Throwable { /* * Fate: (sequence_call string) @@ -1709,13 +1676,13 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor throws Throwable { /* - * Fate: (set_value ref value) - * Wyrd: (set_value ref value) + * Fate: (set_value address value) + * Wyrd: (set_value address value) */ - final ComputationCompiler value_cc, ref_cc; + final ComputationCompiler value_cc, address_cc; value_cc = new ComputationCompiler(compiler); - ref_cc = new ComputationCompiler(compiler); + address_cc = new ComputationCompiler(compiler); n.get_value().get_visited_by(value_cc); @@ -1724,19 +1691,19 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor result.add(value_cc.get_init()); } - n.get_reference().get_visited_by(ref_cc); + n.get_address().get_visited_by(address_cc); - if (ref_cc.has_init()) + if (address_cc.has_init()) { - result.add(ref_cc.get_init()); + result.add(address_cc.get_init()); } result.add ( - new SetValue(ref_cc.get_ref(), value_cc.get_computation()) + new SetValue(address_cc.get_address(), value_cc.get_computation()) ); value_cc.release_variables(); - ref_cc.release_variables(); + address_cc.release_variables(); } } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/MacroManager.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/MacroManager.java index 436c221..e471f28 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/MacroManager.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/MacroManager.java @@ -6,20 +6,20 @@ import java.util.List; import java.util.Map; import java.util.Stack; -import tonkadur.wyrd.v1.lang.computation.Ref; +import tonkadur.wyrd.v1.lang.computation.Address; public class MacroManager { - protected final Map wild_parameters; - protected final Stack> context_stack; + protected final Map wild_parameters; + protected final Stack> context_stack; public MacroManager () { - wild_parameters = new HashMap(); - context_stack = new Stack>(); + wild_parameters = new HashMap(); + context_stack = new Stack>(); } - public void add_wild_parameter (final String name, final Ref ref) + public void add_wild_parameter (final String name, final Address ref) { if (wild_parameters.containsKey(name)) { @@ -44,14 +44,14 @@ public class MacroManager public void push ( final tonkadur.fate.v1.lang.Macro macro, - final List parameter_refs + final List
parameter_refs ) { - final Iterator pri; + final Iterator
pri; final Iterator pre; - final Map parameters; + final Map parameters; - parameters = new HashMap(); + parameters = new HashMap(); pri = parameter_refs.iterator(); pre = macro.get_parameters().get_entries().iterator(); @@ -68,9 +68,9 @@ public class MacroManager context_stack.push(parameters); } - public Ref get_parameter_ref (final String parameter) + public Address get_parameter_ref (final String parameter) { - Ref result; + Address result; result = wild_parameters.get(parameter); 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 index 61bcd14..b433002 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java @@ -42,7 +42,7 @@ public class TypeCompiler ); } - if (fate_type instanceof tonkadur.fate.v1.lang.type.RefType) + if (fate_type instanceof tonkadur.fate.v1.lang.type.AddressType) { return new PointerType @@ -51,7 +51,7 @@ public class TypeCompiler ( compiler, ( - (tonkadur.fate.v1.lang.type.RefType) + (tonkadur.fate.v1.lang.type.AddressType) fate_type ).get_referenced_type() ) @@ -166,7 +166,7 @@ public class TypeCompiler return MapType.MAP_TO_RICH_TEXT; } - if (fate_content_type instanceof tonkadur.fate.v1.lang.type.RefType) + if (fate_content_type instanceof tonkadur.fate.v1.lang.type.AddressType) { return new MapType @@ -177,7 +177,7 @@ public class TypeCompiler ( compiler, ( - (tonkadur.fate.v1.lang.type.RefType) + (tonkadur.fate.v1.lang.type.AddressType) fate_content_type ).get_referenced_type() ) diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java deleted file mode 100644 index 12fde67..0000000 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java +++ /dev/null @@ -1,147 +0,0 @@ -package tonkadur.wyrd.v1.compiler.util; - -import java.util.Map; -import java.util.HashMap; -import java.util.Collection; -import java.util.List; -import java.util.ArrayList; - -import tonkadur.functional.Cons; - -import tonkadur.wyrd.v1.lang.Variable; - -import tonkadur.wyrd.v1.lang.meta.Computation; - -import tonkadur.wyrd.v1.lang.computation.Ref; -import tonkadur.wyrd.v1.lang.computation.Constant; - -import tonkadur.wyrd.v1.lang.type.Type; - - -public class RegisterManager -{ - protected static final String name_prefix = ".anon."; - protected final Map context_by_name; - protected final Deque context; - protected final RegisterContext base_context; - - public RegisterManager () - { - base_context = new RegisterContext("base context", false); - - context_by_name = new HashMap(); - context = new ArrayDeque(); - - context_by_name.put("base context", base_context); - context.push(base_context); - } - - public Ref reserve (final Type t) - { - - } - - protected static class RegisterContext - { - protected final String name; - protected final boolean is_stackable; - protected final Map register_by_name; - protected final Map register_by_type; - protected int generated_variables; - - public RegisterContext (final String name, final boolean is_stackable) - { - this.name = name; - this.is_stackable = is_stackable; - - register_by_name = new HashMap(); - register_by_type = new HashMap(); - - generated_variables = 0; - } - - public Collection get_all_variables () - { - final Collection result; - - result = new ArrayList(); - - for (final Cons variable: by_name.values()) - { - result.add(variable.get_cdr()); - } - - return result; - } - - public Ref reserve (final Type t) - { - final String name; - final Ref result; - final Variable new_variable; - final Cons status; - 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_car(Boolean.TRUE); - - return result; - } - } - - name = (name_prefix + Integer.toString(generated_variables++)); - new_variable = new Variable(name, "local", t); - status = new Cons(Boolean.TRUE, new_variable); - - list.add(status); - - by_name.put(name, status); - - return new_variable.get_ref(); - } - - public void release (final Ref r) - { - final Computation c; - final String name; - - c = r.get_address(); - - if (!(c instanceof Constant)) - { - System.err.println - ( - "[P] Anonymous Variable '" - + r.toString() - + "' is not at constant address." - ); - - return; - } - - name = ((Constant) c).get_as_string(); - - by_name.get(name).set_car(Boolean.FALSE); - } - - protected static class Register - { - protected boolean is_in_use; - protected Variable variable; - } - } -} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java index 741b4e9..b17104a 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java @@ -12,13 +12,15 @@ import tonkadur.wyrd.v1.lang.meta.Computation; 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.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; import tonkadur.wyrd.v1.lang.computation.Size; import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class BinarySearch { @@ -75,44 +77,39 @@ public class BinarySearch */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Computation target, final Computation collection_size, - final Ref collection, - final Ref result_was_found, - final Ref result_index + final Address collection, + final Address result_was_found, + final Address result_index ) { final List result, while_body; - final Ref bot, top, midval; + final Register bot, top, midval; final Type element_type; final Computation value_of_result_index; - final Computation value_of_bot, value_of_top, value_of_midval; result = new ArrayList(); while_body = new ArrayList(); element_type = target.get_type(); - bot = anonymous_variables.reserve(Type.INT); - top = anonymous_variables.reserve(Type.INT); - midval = anonymous_variables.reserve(element_type); + bot = registers.reserve(Type.INT); + top = registers.reserve(Type.INT); + midval = registers.reserve(element_type); value_of_result_index = new ValueOf(result_index); - value_of_bot = new ValueOf(bot); - value_of_top = new ValueOf(top); - value_of_midval = new ValueOf(midval); - result.add(new SetValue(result_index, Constant.ZERO)); result.add(new SetValue(result_was_found, Constant.FALSE)); - result.add(new SetValue(bot, Constant.ZERO)); + result.add(new SetValue(bot.get_address(), Constant.ZERO)); result.add ( new SetValue ( - top, + top.get_address(), Operation.minus(collection_size, Constant.ONE) ) ); @@ -139,14 +136,14 @@ public class BinarySearch result_index, Operation.plus ( - value_of_bot, + bot.get_value(), new Cast ( Operation.divide ( new Cast ( - Operation.minus(value_of_top, value_of_bot), + Operation.minus(top.get_value(), bot.get_value()), Type.FLOAT ), new Constant(Type.FLOAT, "2.0") @@ -162,10 +159,10 @@ public class BinarySearch ( new SetValue ( - midval, + midval.get_address(), new ValueOf ( - new RelativeRef + new RelativeAddress ( collection, new Cast(value_of_result_index, Type.STRING), @@ -194,22 +191,22 @@ public class BinarySearch ( IfElse.generate ( - anonymous_variables, + registers, assembler, - Operation.less_than(value_of_midval, target), + Operation.less_than(midval.get_value(), target), new SetValue ( - bot, + bot.get_address(), Operation.plus(value_of_result_index, Constant.ONE) ), IfElse.generate ( - anonymous_variables, + registers, assembler, - Operation.greater_than(value_of_midval, target), + Operation.greater_than(midval.get_value(), target), new SetValue ( - top, + top.get_address(), Operation.minus(value_of_result_index, Constant.ONE) ), new SetValue(result_was_found, Constant.TRUE) @@ -221,12 +218,12 @@ public class BinarySearch ( While.generate ( - anonymous_variables, + registers, assembler, Operation.and ( Operation.not(new ValueOf(result_was_found)), - Operation.less_equal_than(value_of_bot, value_of_top) + Operation.less_equal_than(bot.get_value(), top.get_value()) ), assembler.merge(while_body) ) @@ -239,14 +236,14 @@ public class BinarySearch ( If.generate ( - anonymous_variables, + registers, assembler, Operation.and ( Operation.and ( Operation.not(new ValueOf(result_was_found)), - Operation.greater_than(target, value_of_midval) + Operation.greater_than(target, midval.get_value()) ), Operation.greater_than(collection_size, Constant.ZERO) ), @@ -258,9 +255,9 @@ public class BinarySearch ) ); - anonymous_variables.release(bot); - anonymous_variables.release(top); - anonymous_variables.release(midval); + registers.release(bot); + registers.release(top); + registers.release(midval); return assembler.merge(result); } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/Clear.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/Clear.java index f28f229..9ec6b4f 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/Clear.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/Clear.java @@ -13,13 +13,15 @@ import tonkadur.wyrd.v1.lang.meta.Computation; 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.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.instruction.SetValue; import tonkadur.wyrd.v1.lang.instruction.Remove; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class Clear { /* Utility Class */ @@ -40,16 +42,15 @@ public class Clear */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Computation collection_size, - final Ref collection + final Address collection ) { final List result, while_body; final Type element_type; - final Ref iterator; - final Computation value_of_iterator; + final Register iterator; result = new ArrayList(); while_body = new ArrayList(); @@ -57,20 +58,20 @@ public class Clear element_type = ((MapType) collection.get_target_type()).get_member_type(); - iterator = anonymous_variables.reserve(Type.INT); + iterator = registers.reserve(Type.INT); value_of_iterator = new ValueOf(iterator); /* (set .iterator collection_size) */ - result.add(new SetValue(iterator, collection_size)); + result.add(new SetValue(iterator.get_address(), collection_size)); /* (set .iterator (- (val .iterator) 1)) */ while_body.add ( new SetValue ( - iterator, - Operation.minus(value_of_iterator, Constant.ONE) + iterator.get_address(), + Operation.minus(iterator.get_value(), Constant.ONE) ) ); @@ -79,10 +80,10 @@ public class Clear ( new Remove ( - new RelativeRef + new RelativeAddress ( collection, - new Cast(value_of_iterator, Type.STRING), + new Cast(iterator.get_value(), Type.STRING), element_type ) ) @@ -92,14 +93,14 @@ public class Clear ( While.generate ( - anonymous_variables, + registers, assembler, - Operation.greater_than(value_of_iterator, Constant.ZERO), + Operation.greater_than(iterator.get_value(), Constant.ZERO), assembler.merge(while_body) ) ); - anonymous_variables.release(iterator); + registers.release(iterator); return assembler.merge(result); } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/CountOccurrences.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/CountOccurrences.java index a6e817a..1f8571a 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/CountOccurrences.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/CountOccurrences.java @@ -11,12 +11,14 @@ import tonkadur.wyrd.v1.lang.meta.Instruction; 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.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class CountOccurrences { @@ -45,49 +47,50 @@ public class CountOccurrences */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Computation target, final Computation collection_size, - final Ref collection, - final Ref count + final Address collection, + final Address count ) { final List result, while_body; final Type target_type; - final Ref index; - final Computation value_of_index; + final Register index; result = new ArrayList(); while_body = new ArrayList(); target_type = target.get_type(); - index = anonymous_variables.reserve(Type.INT); - - value_of_index = new ValueOf(index); + index = registers.reserve(Type.INT); result.add(new SetValue(count, Constant.ZERO)); - result.add(new SetValue(index, collection_size)); + result.add(new SetValue(index.get_address(), collection_size)); while_body.add ( - new SetValue(index, Operation.minus(value_of_index, Constant.ONE)) + new SetValue + ( + index.get_addresss(), + Operation.minus(index.get_value(), Constant.ONE) + ) ); while_body.add ( If.generate ( - anonymous_variables, + registers, assembler, Operation.equals ( new ValueOf ( - new RelativeRef + new RelativeAddress ( collection, - new Cast(value_of_index, Type.STRING), + new Cast(index.get_value(), Type.STRING), target_type ) ), @@ -105,9 +108,9 @@ public class CountOccurrences ( While.generate ( - anonymous_variables, + registers, assembler, - Operation.greater_than(value_of_index, Constant.ZERO), + Operation.greater_than(index.get_value(), Constant.ZERO), assembler.merge(while_body) ) ); diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/FunctionContext.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/FunctionContext.java index 7b9dbc2..e69de29 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/FunctionContext.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/FunctionContext.java @@ -1,9 +0,0 @@ -package tonkadur.wyrd.v1.compiler.util; - -public class FunctionContext -{ - protected final List registers; - protected final Map parameters; - protected final Type result_type; - -} diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/If.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/If.java index 9f20e30..512a61d 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/If.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/If.java @@ -10,6 +10,8 @@ import tonkadur.wyrd.v1.lang.computation.IfElseComputation; import tonkadur.wyrd.v1.lang.instruction.SetPC; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class If { /* @@ -22,7 +24,7 @@ public class If */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Computation condition, final Instruction if_true diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/IfElse.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/IfElse.java index a4ac2e2..42e7609 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/IfElse.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/IfElse.java @@ -10,6 +10,8 @@ import tonkadur.wyrd.v1.lang.computation.IfElseComputation; import tonkadur.wyrd.v1.lang.instruction.SetPC; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class IfElse { /* @@ -25,7 +27,7 @@ public class IfElse */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Computation condition, final Instruction if_true, diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/InsertAt.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/InsertAt.java index c634685..fa3a112 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/InsertAt.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/InsertAt.java @@ -12,12 +12,14 @@ import tonkadur.wyrd.v1.lang.meta.Computation; 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.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class InsertAt { /* Utility Class */ @@ -46,38 +48,40 @@ public class InsertAt */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, - final Ref index, + final Address index, final Computation element, final Computation collection_size, - final Ref collection + final Address collection ) { final List result, while_body; final Type element_type; - final Ref prev, end; - final Computation value_of_prev, value_of_index, value_of_end; + final Register prev, end; + final Computation value_of_index; result = new ArrayList(); while_body = new ArrayList(); element_type = element.get_type(); - prev = anonymous_variables.reserve(Type.INT); - end = anonymous_variables.reserve(Type.INT); + prev = registers.reserve(Type.INT); + end = registers.reserve(Type.INT); - value_of_prev = new ValueOf(prev); value_of_index = new ValueOf(index); - value_of_end = new ValueOf(end); /* (set .end collection_size) */ - result.add(new SetValue(end, collection_size)); + result.add(new SetValue(end.get_address(), collection_size)); /* (set .prev (- (val .end) 1)) */ while_body.add ( - new SetValue(prev, Operation.minus(value_of_end, Constant.ONE)) + new SetValue + ( + prev.get_address(), + Operation.minus(end.get_value(), Constant.ONE) + ) ); /* (set collection[.end] (val collection[.prev])) */ @@ -85,18 +89,18 @@ public class InsertAt ( new SetValue ( - new RelativeRef + new RelativeAddress ( collection, - new Cast(value_of_end, Type.STRING), + new Cast(end.get_value(), Type.STRING), element_type ), new ValueOf ( - new RelativeRef + new RelativeAddress ( collection, - new Cast(value_of_prev, Type.STRING), + new Cast(prev.get_value(), Type.STRING), element_type ) ) @@ -104,7 +108,7 @@ public class InsertAt ); /* (set .end (val .prev)) */ - while_body.add(new SetValue(end, value_of_prev)); + while_body.add(new SetValue(end.get_address(), prev.get_value())); /* * (while (< .index .end) @@ -117,9 +121,9 @@ public class InsertAt ( While.generate ( - anonymous_variables, + registers, assembler, - Operation.less_than(value_of_index, value_of_end), + Operation.less_than(value_of_index, end.get_value()), assembler.merge(while_body) ) ); @@ -129,7 +133,7 @@ public class InsertAt ( new SetValue ( - new RelativeRef + new RelativeAddress ( collection, new Cast(value_of_index, Type.STRING), @@ -139,8 +143,8 @@ public class InsertAt ) ); - anonymous_variables.release(end); - anonymous_variables.release(prev); + registers.release(end); + registers.release(prev); return assembler.merge(result); } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/IterativeSearch.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/IterativeSearch.java index 4098b19..53785a7 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/IterativeSearch.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/IterativeSearch.java @@ -12,12 +12,14 @@ import tonkadur.wyrd.v1.lang.meta.Instruction; 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.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class IterativeSearch { @@ -51,13 +53,13 @@ public class IterativeSearch */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Computation target, final Computation collection_size, - final Ref collection, - final Ref result_was_found, - final Ref result_index + final Address collection, + final Address result_was_found, + final Address result_index ) { final List result; @@ -84,7 +86,7 @@ public class IterativeSearch ( While.generate ( - anonymous_variables, + registers, assembler, Operation.and ( @@ -106,13 +108,13 @@ public class IterativeSearch */ IfElse.generate ( - anonymous_variables, + registers, assembler, Operation.equals ( new ValueOf ( - new RelativeRef + new RelativeAddress ( collection, new Cast(value_of_result_index, Type.STRING), diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/NOP.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/NOP.java index 6f26506..8b38e10 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/NOP.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/NOP.java @@ -4,6 +4,8 @@ import tonkadur.wyrd.v1.lang.meta.Instruction; import tonkadur.wyrd.v1.lang.instruction.SetPC; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class NOP { /* @@ -11,7 +13,7 @@ public class NOP */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler ) { diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAllOf.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAllOf.java index 23bea3a..43716a1 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAllOf.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAllOf.java @@ -12,13 +12,15 @@ import tonkadur.wyrd.v1.lang.meta.Instruction; 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.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.instruction.Remove; import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class RemoveAllOf { /* Utility Class */ @@ -61,20 +63,19 @@ public class RemoveAllOf */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Computation element, final Computation collection_size, - final Ref collection + final Address collection ) { final List result; final List while_body0, while_body1, if_body; final Type element_type; - final Ref index, found, end; - final Computation value_of_index, value_of_found, value_of_end; + final Register index, found, end; final Computation value_of_found_greater_than_0; - final Ref collection_at_index; + final Address collection_at_index; result = new ArrayList(); @@ -84,29 +85,25 @@ public class RemoveAllOf element_type = element.get_type(); - index = anonymous_variables.reserve(Type.INT); - found = anonymous_variables.reserve(Type.INT); - end = anonymous_variables.reserve(Type.INT); - - value_of_index = new ValueOf(index); - value_of_found = new ValueOf(found); - value_of_end = new ValueOf(end); + index = registers.reserve(Type.INT); + found = registers.reserve(Type.INT); + end = registers.reserve(Type.INT); value_of_found_greater_than_0 = - Operation.greater_than(value_of_found, Constant.ZERO); + Operation.greater_than(found.get_value(), Constant.ZERO); collection_at_index = - new RelativeRef + new RelativeAddress ( collection, - new Cast(value_of_index, Type.STRING), + new Cast(index.get_value(), Type.STRING), element_type ); /* (set .index 0) */ - result.add(new SetValue(index, Constant.ZERO)); + result.add(new SetValue(index.get_address(), Constant.ZERO)); /* (set .found 0) */ - result.add(new SetValue(found, Constant.ZERO)); + result.add(new SetValue(found.get_address(), Constant.ZERO)); /* (set .end (- (collection_size) 1) */ result.add @@ -122,11 +119,19 @@ public class RemoveAllOf */ if_body.add ( - new SetValue(found, Operation.plus(value_of_found, Constant.ONE)) + new SetValue + ( + found.get_address(), + Operation.plus(found.get_value(), Constant.ONE) + ) ); if_body.add ( - new SetValue(end, Operation.minus(value_of_end, Constant.ONE)) + new SetValue + ( + end.get_address(), + Operation.minus(end.get_value(), Constant.ONE) + ) ); while_body0.add @@ -134,7 +139,7 @@ public class RemoveAllOf /* (var .found) 0) */ value_of_found_greater_than_0, @@ -229,9 +242,9 @@ public class RemoveAllOf ) ); - anonymous_variables.release(index); - anonymous_variables.release(found); - anonymous_variables.release(end); + registers.release(index); + registers.release(found); + registers.release(end); return assembler.merge(result); } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAt.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAt.java index 5fc7489..c5fb725 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAt.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAt.java @@ -13,13 +13,15 @@ import tonkadur.wyrd.v1.lang.meta.Computation; 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.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.instruction.SetValue; import tonkadur.wyrd.v1.lang.instruction.Remove; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class RemoveAt { /* Utility Class */ @@ -45,19 +47,18 @@ public class RemoveAt */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, - final Ref index, + final Address index, final Computation collection_size, - final Ref collection + final Address collection ) { final List result, while_body; final Type element_type; - final Ref next, end; + final Register next, end; final Computation value_of_index; - final Computation value_of_next, value_of_end; - final Ref collection_at_index; + final Address collection_at_index; result = new ArrayList(); while_body = new ArrayList(); @@ -65,16 +66,13 @@ public class RemoveAt element_type = ((MapType) collection.get_target_type()).get_member_type(); - next = anonymous_variables.reserve(Type.INT); - end = anonymous_variables.reserve(Type.INT); + next = registers.reserve(Type.INT); + end = registers.reserve(Type.INT); value_of_index = new ValueOf(index); - value_of_next = new ValueOf(next); - value_of_end = new ValueOf(end); - collection_at_index = - new RelativeRef + new RelativeAddress ( collection, new Cast(value_of_index, Type.STRING), @@ -84,13 +82,21 @@ public class RemoveAt /* (set .end (- (collection_size) 1) */ result.add ( - new SetValue(end, Operation.minus(collection_size, Constant.ONE)) + new SetValue + ( + end.get_address(), + Operation.minus(collection_size, Constant.ONE) + ) ); /* (set .next (+ (val index) 1)) */ while_body.add ( - new SetValue(next, Operation.plus(value_of_index, Constant.ONE)) + new SetValue + ( + next.get_address(), + Operation.plus(value_of_index, Constant.ONE) + ) ); /* (set collection[index] (val collection[.next])) */ @@ -101,10 +107,10 @@ public class RemoveAt collection_at_index, new ValueOf ( - new RelativeRef + new RelativeAddress ( collection, - new Cast(value_of_next, Type.STRING), + new Cast(next.get_value(), Type.STRING), element_type ) ) @@ -112,7 +118,7 @@ public class RemoveAt ); /* (set .end (val .next)) */ - while_body.add(new SetValue(index, value_of_next)); + while_body.add(new SetValue(index, next.get_value())); /* * (while (< (var index) (var .end)) @@ -125,9 +131,9 @@ public class RemoveAt ( While.generate ( - anonymous_variables, + registers, assembler, - Operation.less_than(value_of_index, value_of_end), + Operation.less_than(value_of_index, end.get_value()), assembler.merge(while_body) ) ); @@ -135,8 +141,8 @@ public class RemoveAt /* (remove collection[index]) */ result.add(new Remove(collection_at_index)); - anonymous_variables.release(end); - anonymous_variables.release(next); + registers.release(end); + registers.release(next); return assembler.merge(result); } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/ReverseList.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/ReverseList.java index a393fc8..d83aff3 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/ReverseList.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/ReverseList.java @@ -13,12 +13,14 @@ import tonkadur.wyrd.v1.lang.meta.Computation; 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.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class ReverseList { /* Utility Class */ @@ -28,7 +30,7 @@ public class ReverseList * (Computation int collection_size) * (declare_variable global collection) * - * (declare_variable E .buffer + * (declare_variable E .buffer) * (declare_variable int .top) * (declare_variable int .bot) * @@ -45,17 +47,16 @@ public class ReverseList */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Computation collection_size, - final Ref collection + final Address collection ) { final List result, while_body; final Type element_type; - final Ref buffer, top, bot; - final Computation value_of_top, value_of_bot; - final Ref collection_at_top, collection_at_bot; + final Register buffer, top, bot; + final Address collection_at_top, collection_at_bot; result = new ArrayList(); while_body = new ArrayList(); @@ -63,41 +64,45 @@ public class ReverseList element_type = ((MapType) collection.get_target_type()).get_member_type(); - buffer = anonymous_variables.reserve(element_type); - top = anonymous_variables.reserve(Type.INT); - bot = anonymous_variables.reserve(Type.INT); - - value_of_top = new ValueOf(top); - value_of_bot = new ValueOf(bot); + buffer = registers.reserve(element_type); + top = registers.reserve(Type.INT); + bot = registers.reserve(Type.INT); collection_at_top = - new RelativeRef + new RelativeAddress ( collection, - new Cast(value_of_top, Type.STRING), + new Cast(top.get_value(), Type.STRING), element_type ); collection_at_bot = - new RelativeRef + new RelativeAddress ( collection, - new Cast(value_of_bot, Type.STRING), + new Cast(bot.get_value(), Type.STRING), element_type ); /* (set .top (- (collection_size) 1)) */ result.add ( - new SetValue(top, Operation.minus(collection_size, Constant.ONE)) + new SetValue + ( + top.get_address(), + Operation.minus(collection_size, Constant.ONE) + ) ); /* (set .bot 0) */ - result.add(new SetValue(bot, Constant.ZERO)); + result.add(new SetValue(bot.get_address(), Constant.ZERO)); /* (set .buffer collection[.top]) */ - while_body.add(new SetValue(buffer, new ValueOf(collection_at_top))); + while_body.add + ( + new SetValue(buffer.get_address(), new ValueOf(collection_at_top)) + ); /* (set collection[.top] collection[.bot]) */ while_body.add @@ -108,19 +113,27 @@ public class ReverseList /* (set collection[.bot] .buffer) */ while_body.add ( - new SetValue(collection_at_bot, new ValueOf(buffer)) + new SetValue(collection_at_bot, buffer.get_value()) ); /* (set .bot (+ (var .bot) 1)) */ while_body.add ( - new SetValue(bot, Operation.plus(value_of_bot, Constant.ONE)) + new SetValue + ( + bot.get_address(), + Operation.plus(bot.get_value(), Constant.ONE) + ) ); /* (set .top (- (var .top) 1)) */ while_body.add ( - new SetValue(top, Operation.minus(value_of_top, Constant.ONE)) + new SetValue + ( + top.get_address(), + Operation.minus(top.get_value(), Constant.ONE) + ) ); /* @@ -136,16 +149,16 @@ public class ReverseList ( While.generate ( - anonymous_variables, + registers, assembler, - Operation.less_than(value_of_bot, value_of_top), + Operation.less_than(bot.get_value(), top.get_value()), assembler.merge(while_body) ) ); - anonymous_variables.release(buffer); - anonymous_variables.release(top); - anonymous_variables.release(bot); + registers.release(buffer); + registers.release(top); + registers.release(bot); return assembler.merge(result); } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/While.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/While.java index c2e7d16..054173d 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/While.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/While.java @@ -10,6 +10,8 @@ import tonkadur.wyrd.v1.lang.computation.IfElseComputation; import tonkadur.wyrd.v1.lang.instruction.SetPC; +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + public class While { /* @@ -24,7 +26,7 @@ public class While */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Computation condition, final Instruction while_body @@ -81,7 +83,7 @@ public class While */ public static Instruction generate ( - final AnonymousVariableManager anonymous_variables, + final RegisterManager registers, final InstructionManager assembler, final Instruction cond_init, final Computation condition, diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterContext.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterContext.java index 06ca608..1689231 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterContext.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterContext.java @@ -1,4 +1,4 @@ -package tonkadur.wyrd.v1.compiler.util; +package tonkadur.wyrd.v1.compiler.util.registers; import java.util.Map; import java.util.HashMap; @@ -6,92 +6,144 @@ import java.util.Collection; import java.util.List; import java.util.ArrayList; -import tonkadur.functional.Cons; - -import tonkadur.wyrd.v1.lang.Variable; - -import tonkadur.wyrd.v1.lang.meta.Computation; - -import tonkadur.wyrd.v1.lang.computation.Ref; -import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.Register; import tonkadur.wyrd.v1.lang.type.Type; - -public class RegisterManager +class RegisterContext { protected static final String name_prefix = ".anon."; protected final String name; protected final Map register_by_name; - protected final Map register_by_type; - protected int generated_variables; + protected final Map aliased_registers; + protected final Map anonymous_register_by_type; + protected int generated_registers; public RegisterContext (final String name) { this.name = name; register_by_name = new HashMap(); - register_by_type = new HashMap(); + aliased_registers = new HashMap(); + anonymous_register_by_type = new HashMap(); - generated_variables = 0; + generated_registers = 0; } - public Collection get_all_variables () + public Collection get_all_registers () { - final Collection result; - - result = new ArrayList(); - - for (final Cons variable: by_name.values()) - { - result.add(variable.get_cdr()); - } - - return result; + return register_by_name.values(); } public Register reserve (final Type t) { final String name; final Register result; - final Variable new_variable; - final Cons status; - List> list; + List list; - list = by_type.get(t); + list = anonymous_register_by_type.get(t); if (list == null) { - list = new ArrayList>(); + list = new ArrayList(); - by_type.put(t, list); + anonymous_register_by_type.put(t, list); } - for (final Cons entry: list) + for (final register r: list) { - if (!entry.get_car()) + if (!entry.get_is_in_use()) { - result = entry.get_cdr().get_ref(); - - entry.set_car(Boolean.TRUE); + r.set_is_in_use(true); - return result; + return r; } } - name = (name_prefix + Integer.toString(generated_variables++)); - new_variable = new Variable(name, "local", t); - status = new Cons(Boolean.TRUE, new_variable); + name = (name_prefix + Integer.toString(generated_registers++)); + + result = create_register(t, "local", name); - list.add(status); + result.set_is_in_use(true); - by_name.put(name, status); + list.add(result); - return new_variable.get_ref(); + register_by_name.put(name, result); + + return result; + } + + public Register reserve (final Type t, final String scope, final String name) + { + final Register result; + + result = create_register(t, scope, name); + + if (register_by_name.get(name) != null) + { + System.err.println + ( + "[P] Register '" + + name + + "' has multiple declarations within the same context." + ); + } + + register_by_name.put(name, result); + + result.set_is_in_use(true); + + return result; + } + + public void bind (final Register reg, final String name) + { + if (aliased_registers.containsKey(name)) + { + System.err.println + ( + "[P] Duplicate binding for register '" + + name + + "' in context '" + + this.name + + "'." + ); + } + + aliased_registers.put(name, reg); + } + + public void unbind (final String name) + { + aliased_registers.remove(name); + } + + public Register get_register (final String name) + { + final Register result; + + result = aliased_registers.get(name); + + if (result != null) + { + return result; + } + + return register_by_name.get(name); } public void release (final Register r) { r.set_is_in_use(false); } + + protected Register create_register + ( + final Type t, + final String scope, + final String name + ) + { + return new Register(t, scope, name); + } } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterManager.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterManager.java index 1519f01..dffb52a 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterManager.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/RegisterManager.java @@ -1,4 +1,4 @@ -package tonkadur.wyrd.v1.compiler.util; +package tonkadur.wyrd.v1.compiler.util.registers; import java.util.Map; import java.util.HashMap; @@ -8,11 +8,11 @@ import java.util.ArrayList; import tonkadur.functional.Cons; -import tonkadur.wyrd.v1.lang.Variable; +import tonkadur.wyrd.v1.lang.Register; import tonkadur.wyrd.v1.lang.meta.Computation; -import tonkadur.wyrd.v1.lang.computation.Ref; +import tonkadur.wyrd.v1.lang.computation.Address; import tonkadur.wyrd.v1.lang.computation.Constant; import tonkadur.wyrd.v1.lang.type.Type; @@ -20,18 +20,20 @@ import tonkadur.wyrd.v1.lang.type.Type; public class RegisterManager { - protected final Map context_by_name; + protected static final String context_name_prefix = ".context."; + protected final Map context_by_name; protected final Deque context; protected final RegisterContext base_context; + protected int created_contexts; public RegisterManager () { - base_context = new RegisterContext("base context", false); + base_context = new RegisterContext("base context"); context_by_name = new HashMap(); context = new ArrayDeque(); + created_contexts = 0; - context_by_name.put("base context", base_context); context.push(base_context); } @@ -45,6 +47,11 @@ public class RegisterManager context.peekFirst().release(r); } + public String create_stackable_context_name () + { + return context_name_prefix + (created_contexts++); + } + public void create_stackable_context (final String context_name) { final StackableRegisterContext result; @@ -54,14 +61,33 @@ public class RegisterManager context_by_name.put(result); } - public void add_context_variable (final Type t, final String variable_name) + public void register (final Type t, final String register_name) { context.peekFirst().reserve(t, name); } - public Register get_context_variable (final String variable_name) + public void bind (final String name, final Register register) + { + context.peekFirst().bind(name, register); + } + + public void unbind (final String name) { - context.peekFirst().get_variable(name); + context.peekFirst().unbind(name); + } + + public Register get_context_register (final String register_name) + { + final Register result; + + result = context.peekFirst().get_register(name); + + if (result == null) + { + return base_context.get_register(name); + } + + return result; } public List get_enter_context_instructions @@ -80,15 +106,22 @@ public class RegisterManager return context_by_name.get(context_name).get_leave_instructions(); } - public Collection get_generated_types () + public Collection get_context_structure_types () { - /* TODO */ - return null; + final Collection result; + + result = new ArrayList(); + + for (final StackableRegisterContext src: register_by_name.values()) + { + result.add(src.get_structure_type()); + } + + return result; } - public Collection get_generated_variables () + public Collection get_base_registers () { - /* TODO */ - return null; + return base_context.get_all_registers(); } } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/StackableRegisterContext.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/StackableRegisterContext.java index 12fde67..193315b 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/StackableRegisterContext.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/registers/StackableRegisterContext.java @@ -1,4 +1,4 @@ -package tonkadur.wyrd.v1.compiler.util; +package tonkadur.wyrd.v1.compiler.util.registers; import java.util.Map; import java.util.HashMap; @@ -12,136 +12,89 @@ import tonkadur.wyrd.v1.lang.Variable; import tonkadur.wyrd.v1.lang.meta.Computation; -import tonkadur.wyrd.v1.lang.computation.Ref; +import tonkadur.wyrd.v1.lang.computation.Address; import tonkadur.wyrd.v1.lang.computation.Constant; import tonkadur.wyrd.v1.lang.type.Type; -public class RegisterManager +class StackableRegisterContext extends RegisterContext { - protected static final String name_prefix = ".anon."; - protected final Map context_by_name; - protected final Deque context; - protected final RegisterContext base_context; - - public RegisterManager () - { - base_context = new RegisterContext("base context", false); - - context_by_name = new HashMap(); - context = new ArrayDeque(); - - context_by_name.put("base context", base_context); - context.push(base_context); - } - - public Ref reserve (final Type t) + protected final Map context_structure_fields; + protected final DictType context_structure; + protected final Register context_stack_level; + protected final Register context_stacks; + protected final Address current_context_address; + + public StackableRegisterContext + ( + final RegisterContext base_context, + final String context_name + ) { - + super(context_name); + + context_structure_fields = new HashMap(); + + context_structure = new DictType(context_name, context_structure_fields); + + context_stack_level = base_context.reserve(Type.INT); + context_stacks = + base_context.reserve + ( + new MapType(new PointerType(context_structure)) + ); + + current_context_address = + new RelativeAddress + ( + context_stacks.get_address(), + new Cast(context_stack_level.get_value(), Type.STRING), + new PointerType(context_structure) + ); } - protected static class RegisterContext + @Override + protected Register generate_register + ( + final Type t, + final String scope, + final String name + ) { - protected final String name; - protected final boolean is_stackable; - protected final Map register_by_name; - protected final Map register_by_type; - protected int generated_variables; + final Register result; - public RegisterContext (final String name, final boolean is_stackable) + if (context_structure.get(name) != null) { - this.name = name; - this.is_stackable = is_stackable; - - register_by_name = new HashMap(); - register_by_type = new HashMap(); - - generated_variables = 0; - } - - public Collection get_all_variables () - { - final Collection result; - - result = new ArrayList(); - - for (final Cons variable: by_name.values()) - { - result.add(variable.get_cdr()); - } - - return result; - } - - public Ref reserve (final Type t) - { - final String name; - final Ref result; - final Variable new_variable; - final Cons status; - 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_car(Boolean.TRUE); - - return result; - } - } - - name = (name_prefix + Integer.toString(generated_variables++)); - new_variable = new Variable(name, "local", t); - status = new Cons(Boolean.TRUE, new_variable); - - list.add(status); - - by_name.put(name, status); - - return new_variable.get_ref(); + System.err.println + ( + "[P] Duplicate register '" + + name + + "' in stackable context " + + this.name + + "." + ); } - public void release (final Ref r) - { - final Computation c; - final String name; + context_structure.put(name, t); - c = r.get_address(); - - if (!(c instanceof Constant)) - { - System.err.println + return + new Register + ( + new RelativeAddress ( - "[P] Anonymous Variable '" - + r.toString() - + "' is not at constant address." - ); - - return; - } - - name = ((Constant) c).get_as_string(); - - by_name.get(name).set_car(Boolean.FALSE); - } + current_context_address, + new Constant(Type.STRING, name), + t + ), + t, + scope, + name + ); + } - protected static class Register - { - protected boolean is_in_use; - protected Variable variable; - } + public DictType get_structure_type () + { + return context_structure; } } diff --git a/src/core/src/tonkadur/wyrd/v1/lang/Register.java b/src/core/src/tonkadur/wyrd/v1/lang/Register.java new file mode 100644 index 0000000..4f1c671 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/lang/Register.java @@ -0,0 +1,68 @@ +package tonkadur.wyrd.v1.lang; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.Address; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +public class Register +{ + protected final Type type; + protected final String scope; + protected final String name; + protected final Address address; + protected final Computation value; + + public Register (final Type type, final String scope, final String name) + { + this.name = name; + this.scope = scope; + this.type = type; + + address = new Address(new Constant(Type.STRING, name), type); + value = new ValueOf(address); + } + + public Register + ( + final Address address, + final Type type, + final String scope, + final String name + ) + { + this.address = address; + this.name = name; + this.scope = scope; + this.type = type; + + value = new ValueOf(address); + } + + public Type get_type () + { + return type; + } + + public String get_name () + { + return name; + } + + public String get_scope () + { + return scope; + } + + public Address get_address () + { + return address; + } + + public Computation get_value () + { + return value; + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/Variable.java b/src/core/src/tonkadur/wyrd/v1/lang/Variable.java deleted file mode 100644 index 7117b89..0000000 --- a/src/core/src/tonkadur/wyrd/v1/lang/Variable.java +++ /dev/null @@ -1,42 +0,0 @@ -package tonkadur.wyrd.v1.lang; - -import java.util.Collections; - -import tonkadur.wyrd.v1.lang.type.Type; - -import tonkadur.wyrd.v1.lang.computation.Constant; -import tonkadur.wyrd.v1.lang.computation.Ref; - -public class Variable -{ - protected final String scope; - protected final String name; - protected final Type type; - - public Variable (final String name, final String scope, final Type type) - { - this.name = name; - this.scope = scope; - this.type = type; - } - - public String get_name () - { - return name; - } - - public String get_scope () - { - return scope; - } - - public Type get_type () - { - return type; - } - - public Ref get_ref () - { - return new Ref(new Constant(Type.STRING, name), type); - } -} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/World.java b/src/core/src/tonkadur/wyrd/v1/lang/World.java index 3649756..dd7e07a 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/World.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/World.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import tonkadur.wyrd.v1.lang.Variable; +import tonkadur.wyrd.v1.lang.Register; import tonkadur.wyrd.v1.lang.type.DictType; @@ -17,7 +17,7 @@ public class World { protected final Set required_extensions; - protected final Map variables; + protected final Collection registers; protected final Map sequence_labels; protected final Map dict_types; @@ -30,7 +30,7 @@ public class World { required_extensions = new HashSet(); - variables = new HashMap(); + registers = new HashMap(); sequence_labels = new HashMap(); dict_types = new HashMap(); dict_types_in_order = new ArrayList(); @@ -64,19 +64,14 @@ public class World dict_types_in_order.add(dict_type); } - public Variable get_variable (final String name) + public Collection get_registers () { - return variables.get(name); + return registers; } - public Map get_variables () + public void add_register (final Register register) { - return variables; - } - - public void add_variable (final Variable variable) - { - variables.put(variable.get_name(), variable); + registers.add(register); } public void add_sequence_label (final String name, final Integer line) diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/Address.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/Address.java new file mode 100644 index 0000000..8abb75c --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/Address.java @@ -0,0 +1,61 @@ +package tonkadur.wyrd.v1.lang.computation; + +import tonkadur.wyrd.v1.lang.type.Type; +import tonkadur.wyrd.v1.lang.type.PointerType; + +import tonkadur.wyrd.v1.lang.meta.Computation; +import tonkadur.wyrd.v1.lang.meta.ComputationVisitor; + +public class Address extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation address; + protected final Type target_type; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public Address (final Computation address, final Type target_type) + { + super(new PointerType(target_type)); + + this.address = address; + this.target_type = target_type; + } + + /**** Accessors ************************************************************/ + public Computation get_address () + { + return address; + } + + public Type get_target_type () + { + return target_type; + } + + @Override + public void get_visited_by (final ComputationVisitor cv) + throws Throwable + { + cv.visit_address(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb; + + sb = new StringBuilder(); + + sb.append("(Address "); + sb.append(address.toString()); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java deleted file mode 100644 index 7e4f3ea..0000000 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java +++ /dev/null @@ -1,61 +0,0 @@ -package tonkadur.wyrd.v1.lang.computation; - -import tonkadur.wyrd.v1.lang.type.Type; -import tonkadur.wyrd.v1.lang.type.PointerType; - -import tonkadur.wyrd.v1.lang.meta.Computation; -import tonkadur.wyrd.v1.lang.meta.ComputationVisitor; - -public class Ref extends Computation -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Computation address; - protected final Type target_type; - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public Ref (final Computation address, final Type target_type) - { - super(new PointerType(target_type)); - - this.address = address; - this.target_type = target_type; - } - - /**** Accessors ************************************************************/ - public Computation get_address () - { - return address; - } - - public Type get_target_type () - { - return target_type; - } - - @Override - public void get_visited_by (final ComputationVisitor cv) - throws Throwable - { - cv.visit_ref(this); - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb; - - sb = new StringBuilder(); - - sb.append("(Ref "); - sb.append(address.toString()); - sb.append(")"); - - return sb.toString(); - } -} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeAddress.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeAddress.java new file mode 100644 index 0000000..b9268f4 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeAddress.java @@ -0,0 +1,60 @@ +package tonkadur.wyrd.v1.lang.computation; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.meta.Computation; +import tonkadur.wyrd.v1.lang.meta.ComputationVisitor; + +public class RelativeAddress extends Address +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation member; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public RelativeAddress + ( + final Address parent, + final Computation member, + final Type target_type + ) + { + super(parent, target_type); + + this.member = member; + } + + /**** Accessors ************************************************************/ + public Computation get_member () + { + return member; + } + + @Override + public void get_visited_by (final ComputationVisitor cv) + throws Throwable + { + cv.visit_relative_address(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb; + + sb = new StringBuilder(); + + sb.append("(RelativeAddress "); + sb.append(address.toString()); + sb.append("."); + sb.append(member.toString()); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeRef.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeRef.java deleted file mode 100644 index b37ab86..0000000 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/RelativeRef.java +++ /dev/null @@ -1,60 +0,0 @@ -package tonkadur.wyrd.v1.lang.computation; - -import tonkadur.wyrd.v1.lang.type.Type; - -import tonkadur.wyrd.v1.lang.meta.Computation; -import tonkadur.wyrd.v1.lang.meta.ComputationVisitor; - -public class RelativeRef extends Ref -{ - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Computation member; - - /***************************************************************************/ - /**** PUBLIC ***************************************************************/ - /***************************************************************************/ - /**** Constructors *********************************************************/ - public RelativeRef - ( - final Ref parent, - final Computation member, - final Type target_type - ) - { - super(parent, target_type); - - this.member = member; - } - - /**** Accessors ************************************************************/ - public Computation get_member () - { - return member; - } - - @Override - public void get_visited_by (final ComputationVisitor cv) - throws Throwable - { - cv.visit_relative_ref(this); - } - - /**** Misc. ****************************************************************/ - @Override - public String toString () - { - final StringBuilder sb; - - sb = new StringBuilder(); - - sb.append("(RelativeRef "); - sb.append(address.toString()); - sb.append("."); - sb.append(member.toString()); - sb.append(")"); - - return sb.toString(); - } -} 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 4f56656..b242612 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/Size.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/Size.java @@ -10,13 +10,13 @@ public class Size extends Computation /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final Ref collection; + protected final Address collection; /***************************************************************************/ /**** PUBLIC ***************************************************************/ /***************************************************************************/ /**** Constructors *********************************************************/ - public Size (final Ref collection) + public Size (final Address collection) { super(Type.INT); @@ -24,7 +24,7 @@ public class Size extends Computation } /**** Accessors ************************************************************/ - public Ref get_collection () + public Address 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 365fdf2..7c02b91 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/ValueOf.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/ValueOf.java @@ -23,7 +23,7 @@ public class ValueOf extends Computation this.parent = parent; } - public ValueOf (final Ref parent) + public ValueOf (final Address parent) { super(parent.get_target_type()); diff --git a/src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java b/src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java index 97e046b..68b25ef 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java @@ -1,6 +1,6 @@ package tonkadur.wyrd.v1.lang.instruction; -import tonkadur.wyrd.v1.lang.computation.Ref; +import tonkadur.wyrd.v1.lang.computation.Address; import tonkadur.wyrd.v1.lang.meta.Instruction; import tonkadur.wyrd.v1.lang.meta.InstructionVisitor; @@ -10,21 +10,21 @@ public class Remove extends Instruction /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final Ref reference; + protected final Address address; /***************************************************************************/ /**** PUBLIC ***************************************************************/ /***************************************************************************/ /**** Constructors *********************************************************/ - public Remove (final Ref reference) + public Remove (final Address address) { - this.reference = reference; + this.address = address; } /**** Accessors ************************************************************/ - public Ref get_reference () + public Address get_address () { - return reference; + return address; } @Override @@ -43,7 +43,7 @@ public class Remove extends Instruction sb = new StringBuilder(); sb.append("(Remove "); - sb.append(reference.toString()); + sb.append(address.toString()); sb.append(")"); return sb.toString(); 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 a850094..4b66fbe 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java @@ -1,6 +1,6 @@ package tonkadur.wyrd.v1.lang.instruction; -import tonkadur.wyrd.v1.lang.computation.Ref; +import tonkadur.wyrd.v1.lang.computation.Address; import tonkadur.wyrd.v1.lang.meta.Computation; import tonkadur.wyrd.v1.lang.meta.Instruction; @@ -11,23 +11,23 @@ public class SetValue extends Instruction /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final Ref reference; + protected final Address address; protected final Computation value; /***************************************************************************/ /**** PUBLIC ***************************************************************/ /***************************************************************************/ /**** Constructors *********************************************************/ - public SetValue (final Ref reference, final Computation value) + public SetValue (final Address address, final Computation value) { - this.reference = reference; + this.address = address; this.value = value; } /**** Accessors ************************************************************/ - public Ref get_reference () + public Address get_address () { - return reference; + return address; } public Computation get_value () @@ -51,7 +51,7 @@ public class SetValue extends Instruction sb = new StringBuilder(); sb.append("(SetValue "); - sb.append(reference.toString()); + sb.append(address.toString()); sb.append(" "); sb.append(value.toString()); sb.append(")"); diff --git a/src/core/src/tonkadur/wyrd/v1/lang/meta/ComputationVisitor.java b/src/core/src/tonkadur/wyrd/v1/lang/meta/ComputationVisitor.java index e0944a4..fdfdc1b 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/meta/ComputationVisitor.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/meta/ComputationVisitor.java @@ -25,10 +25,10 @@ public interface ComputationVisitor public void visit_operation (final Operation n) throws Throwable; - public void visit_ref (final Ref n) + public void visit_address (final Address n) throws Throwable; - public void visit_relative_ref (final RelativeRef n) + public void visit_relative_address (final RelativeAddress n) throws Throwable; public void visit_rich_text (final RichText n) -- cgit v1.2.3-70-g09d2