From 44deeb7463e63eea1f7c6724dda2d12885c2b1e8 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Wed, 29 Jul 2020 19:11:34 +0200 Subject: ... --- .../tonkadur/fate/v1/lang/meta/Instruction.java | 22 - .../wyrd/v1/compiler/fate/v1/Compiler.java | 101 ++-- .../v1/compiler/fate/v1/ComputationCompiler.java | 33 +- .../v1/compiler/fate/v1/InstructionCompiler.java | 561 ++++++++------------- .../wyrd/v1/compiler/fate/v1/MacroManager.java | 2 +- .../wyrd/v1/compiler/fate/v1/SequenceCompiler.java | 68 ++- .../wyrd/v1/compiler/fate/v1/TypeCompiler.java | 30 +- .../wyrd/v1/compiler/fate/v1/VariableCompiler.java | 27 +- .../wyrd/v1/compiler/util/BinarySearch.java | 91 ++-- .../src/tonkadur/wyrd/v1/compiler/util/Clear.java | 113 +++++ .../src/tonkadur/wyrd/v1/compiler/util/If.java | 67 +++ .../src/tonkadur/wyrd/v1/compiler/util/IfElse.java | 78 +++ .../tonkadur/wyrd/v1/compiler/util/InsertAt.java | 21 +- .../wyrd/v1/compiler/util/InstructionManager.java | 255 ++++++++++ .../wyrd/v1/compiler/util/IterativeSearch.java | 87 ++-- .../src/tonkadur/wyrd/v1/compiler/util/NOP.java | 37 ++ .../wyrd/v1/compiler/util/RemoveAllOf.java | 64 ++- .../tonkadur/wyrd/v1/compiler/util/RemoveAt.java | 13 +- .../src/tonkadur/wyrd/v1/compiler/util/While.java | 71 +++ src/core/src/tonkadur/wyrd/v1/lang/Sequence.java | 27 - src/core/src/tonkadur/wyrd/v1/lang/World.java | 22 +- .../wyrd/v1/lang/instruction/AddChoice.java | 8 +- .../v1/lang/instruction/IfElseInstruction.java | 50 -- .../src/tonkadur/wyrd/v1/lang/instruction/NOP.java | 19 - .../wyrd/v1/lang/instruction/SequenceCall.java | 26 - .../tonkadur/wyrd/v1/lang/instruction/SetPC.java | 27 + .../tonkadur/wyrd/v1/lang/instruction/While.java | 40 -- 27 files changed, 1168 insertions(+), 792 deletions(-) create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/util/Clear.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/util/If.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/util/IfElse.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/util/InstructionManager.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/util/NOP.java create mode 100644 src/core/src/tonkadur/wyrd/v1/compiler/util/While.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/lang/Sequence.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/lang/instruction/IfElseInstruction.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/lang/instruction/NOP.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/lang/instruction/SequenceCall.java create mode 100644 src/core/src/tonkadur/wyrd/v1/lang/instruction/SetPC.java delete mode 100644 src/core/src/tonkadur/wyrd/v1/lang/instruction/While.java diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/Instruction.java b/src/core/src/tonkadur/fate/v1/lang/meta/Instruction.java index 457c355..7782a97 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/Instruction.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/Instruction.java @@ -10,8 +10,6 @@ public abstract class Instruction extends Node /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final Collection parents; - protected Instruction child; /***************************************************************************/ /**** PROTECTED ************************************************************/ @@ -20,9 +18,6 @@ public abstract class Instruction extends Node protected Instruction (final Origin origin) { super(origin); - - parents = new HashSet(); - child = null; } /***************************************************************************/ @@ -35,23 +30,6 @@ public abstract class Instruction extends Node } - public void link_parent (final Instruction parent) - { - parent.child = this; - - parents.add(parent); - } - - public Collection get_parents () - { - return parents; - } - - public Instruction get_child () - { - return child; - } - /**** Misc. ****************************************************************/ @Override public String toString () 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 39707da..d516cb3 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,34 +1,47 @@ package tonkadur.wyrd.v1.compiler.fate.v1; -import tonkadur.error.Error; +import tonkadur.wyrd.v1.compiler.util.AnonymousVariableManager; +import tonkadur.wyrd.v1.compiler.util.InstructionManager; import tonkadur.wyrd.v1.lang.World; public class Compiler { - /* Utility Class */ - private Compiler () { } + protected final AnonymousVariableManager anonymous_variables; + protected final MacroManager macro_manager; + protected final InstructionManager assembler; + protected final World wyrd_world; + public static World compile (final tonkadur.fate.v1.lang.World fate_world) - throws Error + throws Throwable { - final World wyrd_world; + final Compiler compiler; - wyrd_world = new World(); + compiler = new Compiler(); - compile_extensions(fate_world, wyrd_world); - compile_types(fate_world, wyrd_world); - compile_variables(fate_world, wyrd_world); - compile_sequences(fate_world, wyrd_world); - compile_main_sequence(fate_world, wyrd_world); + compiler.compile_extensions(fate_world); + compiler.compile_types(fate_world); + compiler.compile_variables(fate_world); - return wyrd_world; + compiler.compile_main_sequence(fate_world); + + compiler.compile_sequences(fate_world); + + return compiler.wyrd_world; } - protected static void compile_extensions + protected Compiler () + { + macro_manager = new MacroManager(); + anonymous_variables = new AnonymousVariableManager(); + assembler = new InstructionManager(); + wyrd_world = new World(); + } + + protected void compile_extensions ( - final tonkadur.fate.v1.lang.World fate_world, - final World wyrd_world + final tonkadur.fate.v1.lang.World fate_world ) { for (final String extension: fate_world.get_required_extensions()) @@ -37,12 +50,11 @@ public class Compiler } } - protected static void compile_types + protected void compile_types ( - final tonkadur.fate.v1.lang.World fate_world, - final World wyrd_world + final tonkadur.fate.v1.lang.World fate_world ) - throws Error + throws Throwable { for ( @@ -50,16 +62,15 @@ public class Compiler fate_world.types().get_all() ) { - TypeCompiler.compile(type, wyrd_world); + TypeCompiler.compile(this, type); } } - protected static void compile_variables + protected void compile_variables ( - final tonkadur.fate.v1.lang.World fate_world, - final World wyrd_world + final tonkadur.fate.v1.lang.World fate_world ) - throws Error + throws Throwable { for ( @@ -67,16 +78,15 @@ public class Compiler fate_world.variables().get_all() ) { - VariableCompiler.compile(variable, wyrd_world); + VariableCompiler.compile(this, variable); } } - protected static void compile_sequences + protected void compile_sequences ( - final tonkadur.fate.v1.lang.World fate_world, - final World wyrd_world + final tonkadur.fate.v1.lang.World fate_world ) - throws Error + throws Throwable { for ( @@ -84,21 +94,40 @@ public class Compiler fate_world.sequences().get_all() ) { - SequenceCompiler.compile(sequence, wyrd_world); + SequenceCompiler.compile(this, sequence); } } - protected static void compile_main_sequence + protected void compile_main_sequence ( - final tonkadur.fate.v1.lang.World fate_world, - final World wyrd_world + final tonkadur.fate.v1.lang.World fate_world ) - throws Error + throws Throwable { SequenceCompiler.compile_main_sequence ( - fate_world.get_global_instructions(), - wyrd_world + this, + fate_world.get_global_instructions() ); } + + public World world () + { + return wyrd_world; + } + + public AnonymousVariableManager anonymous_variables () + { + return anonymous_variables; + } + + public InstructionManager assembler () + { + return assembler; + } + + public MacroManager macros () + { + return macro_manager; + } } 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 ebfc865..1cc3af8 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 @@ -13,14 +13,10 @@ import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.World; -import tonkadur.wyrd.v1.compiler.util.AnonymousVariableManager; - public class ComputationCompiler implements tonkadur.fate.v1.lang.meta.ComputationVisitor { - protected final MacroManager macro_manager; - protected final AnonymousVariableManager anonymous_variables; - protected final World wyrd_world; + protected final Compiler compiler; protected final List pre_computation_instructions; protected final List allocated_variables; protected final boolean expect_ref; @@ -29,15 +25,11 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor public ComputationCompiler ( - final MacroManager macro_manager, - final AnonymousVariableManager anonymous_variables, - final World wyrd_world, + final Compiler compiler, final boolean expect_ref ) { - this.macro_manager = macro_manager; - this.anonymous_variables = anonymous_variables; - this.wyrd_world = wyrd_world; + this.compiler = compiler; this.expect_ref = expect_ref; allocated_variables = new ArrayList(); @@ -46,9 +38,9 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor result_as_computation = null; } - public List get_pre_instructions () + public Instruction get_init () { - return pre_computation_instructions; + return compiler.assembler().merge(pre_computation_instructions); } public Computation get_computation () @@ -67,6 +59,11 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor public Ref get_ref () { + if ((result_as_ref == null) && (result_as_computation != null)) + { + generate_ref(); + } + return result_as_ref; } @@ -74,18 +71,22 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor { final Ref result; - result = anonymous_variables.reserve(result_as_computation.get_type()); + result = + compiler.anonymous_variables().reserve + ( + result_as_computation.get_type() + ); allocated_variables.add(result); result_as_ref = result; } - public void free_anonymous_variables () + public void release_variables () { for (final Ref ref: allocated_variables) { - anonymous_variables.release(ref); + compiler.anonymous_variables().release(ref); } } 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 914a836..b4038dd 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 @@ -29,17 +29,20 @@ import tonkadur.wyrd.v1.lang.instruction.AddChoice; import tonkadur.wyrd.v1.lang.instruction.Assert; import tonkadur.wyrd.v1.lang.instruction.Display; import tonkadur.wyrd.v1.lang.instruction.EventCall; -import tonkadur.wyrd.v1.lang.instruction.IfElseInstruction; -import tonkadur.wyrd.v1.lang.instruction.NOP; import tonkadur.wyrd.v1.lang.instruction.Remove; import tonkadur.wyrd.v1.lang.instruction.ResolveChoices; -import tonkadur.wyrd.v1.lang.instruction.SequenceCall; +import tonkadur.wyrd.v1.lang.instruction.SetPC; import tonkadur.wyrd.v1.lang.instruction.SetValue; -import tonkadur.wyrd.v1.lang.instruction.While; 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; +import tonkadur.wyrd.v1.compiler.util.IfElse; +import tonkadur.wyrd.v1.compiler.util.InstructionManager; +import tonkadur.wyrd.v1.compiler.util.NOP; +import tonkadur.wyrd.v1.compiler.util.While; +import tonkadur.wyrd.v1.compiler.util.Clear; import tonkadur.wyrd.v1.compiler.util.IterativeSearch; import tonkadur.wyrd.v1.compiler.util.RemoveAllOf; import tonkadur.wyrd.v1.compiler.util.RemoveAt; @@ -47,82 +50,28 @@ import tonkadur.wyrd.v1.compiler.util.RemoveAt; public class InstructionCompiler implements tonkadur.fate.v1.lang.meta.InstructionVisitor { - protected final AnonymousVariableManager anonymous_variables; - protected final World wyrd_world; - protected final MacroManager macro_manager; + protected final Compiler compiler; protected final List result; - public InstructionCompiler - ( - final MacroManager macro_manager, - final AnonymousVariableManager anonymous_variables, - final World wyrd_world - ) + public InstructionCompiler (final Compiler compiler) { - this.macro_manager = macro_manager; - this.anonymous_variables = anonymous_variables; - this.wyrd_world = wyrd_world; + this.compiler = compiler; result = new ArrayList(); } public InstructionCompiler ( - final MacroManager macro_manager, - final AnonymousVariableManager anonymous_variables, - final World wyrd_world, + final Compiler compiler, final List result ) { - this.macro_manager = macro_manager; - this.anonymous_variables = anonymous_variables; - this.wyrd_world = wyrd_world; + this.compiler = compiler; this.result = result; } - protected List get_result () - { - return result; - } - - protected ComputationCompiler new_computation_compiler - ( - final boolean expect_ref - ) - { - return - new ComputationCompiler - ( - macro_manager, - anonymous_variables, - wyrd_world, - expect_ref - ); - } - - protected InstructionCompiler new_instruction_compiler () - { - return - new InstructionCompiler - ( - macro_manager, - anonymous_variables, - wyrd_world - ); - } - - protected InstructionCompiler new_instruction_compiler - ( - final List result - ) + protected Instruction get_result () { - return - new InstructionCompiler - ( - macro_manager, - anonymous_variables, - wyrd_world, - result - ); + return compiler.assembler().merge(result); } protected void add_element_to_set @@ -145,174 +94,76 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor * * ) */ - /* - final Ref element_as_ref, collection_as_ref, collection_size_as_ref; - final Ref element_found, element_index, collection_size, next_index; final ComputationCompiler element_compiler, reference_compiler; + final Ref element, collection, collection_size; + final Ref element_found, element_index; final Type element_type; - final List while_body, else_branch; - - element_compiler = new_computation_compiler(false); + final Computation value_of_element, value_of_collection_size; + element_compiler = new ComputationCompiler(compiler, false); ae.get_element().get_visited_by(element_compiler); - - result.addAll(element_compiler.get_pre_instructions()); - + 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_as_ref = anonymous_variable.reserve(element_type); - - result.add - ( - new SetValue(element_as_ref, element_compiler.get_computation()) - ); - - reference_compiler = new_computation_compiler(true); - + reference_compiler = new ComputationCompiler(compiler, true); ae.get_collection().get_visited_by(reference_compiler); + result.add(reference_compiler.get_init()); + collection = reference_compiler.get_ref(); - result.addAll(reference_compiler.get_pre_instructions()); + 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_as_ref = reference_compiler.get_ref(); - - element_found = anonymous_variable.reserve(Type.BOOLEAN); - element_index = anonymous_variable.reserve(Type.INT); - collection_size = anonymous_variable.reserve(Type.INT); - next_index = anonymous_variable.reserve(Type.INT); + value_of_element = new ValueOf(element); + value_of_collection_size = new ValueOf(collection_size); result.add ( - new SetValue(collection_size, new Size(collection_as_ref)) + new SetValue(collection_size, new Size(collection)) ); - result.addAll + result.add ( BinarySearch.generate ( - anonymous_variables, - element_as_ref, - collection_as_ref, - collection_size, + compiler.anonymous_variables(), + compiler.assembler(), + value_of_element, + value_of_collection_size, + collection, element_found, element_index ) ); - while_body = new ArrayList(); - - while_body.add - ( - new SetValue - ( - next_index, - Operation.minus - ( - new ValueOf(collection_size), - new Constant(Type.INT, "1") - ) - ) - ); - - while_body.add + result.add ( - new SetValue + If.generate ( - new RelativeRef - ( - collection_as_ref, - Collections.singletonList - ( - new Cast - ( - new ValueOf(collection_size), - Type.STRING - ) - ), - element_type - ), - new ValueOf + compiler.anonymous_variables(), + compiler.assembler(), + Operation.not(new ValueOf(element_found)), + InsertAt.generate ( - new RelativeRef - ( - collection_as_ref, - Collections.singletonList - ( - new Cast - ( - new ValueOf(next), - Type.STRING - ) - ), - element_type - ) + compiler.anonymous_variables(), + compiler.assembler(), + element_index, + value_of_element, + value_of_collection_size, + collection ) ) ); - while_body.add - ( - new SetValue - ( - collection_size, - new ValueOf(next) - ) - ); - - else_branch = new ArrayList(); - - else_branch.add - ( - new While - ( - Operation.less_than - ( - new ValueOf(element_index), - new ValueOf(collection_size) - ), - while_body - ) - ); - - else_branch.add - ( - new SetValue - ( - new RelativeRef - ( - collection_as_ref, - Collections.singletonList - ( - new Cast - ( - new ValueOf(element_index), - Type.STRING - ) - ), - element_type - ), - new ValueOf(element_as_ref) - ) - ); - - result.add - ( - new IfElseInstruction - ( - new ValueOf(element_found), - new NOP(), - else_branch - ) - ); - - anonymous_variables.release(element_as_ref); - anonymous_variables.release(element_found); - anonymous_variables.release(element_index); - anonymous_variables.release(collection_size); - anonymous_variables.release(next_index); + compiler.anonymous_variables().release(element); + compiler.anonymous_variables().release(element_found); + compiler.anonymous_variables().release(element_index); + compiler.anonymous_variables().release(collection_size); - reference_compiler.free_anonymous_variables(); - element_compiler.free_anonymous_variables(); - */ + reference_compiler.release_variables(); } protected void add_element_to_list @@ -334,18 +185,18 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor final Ref collection_as_ref; final ComputationCompiler element_compiler, reference_compiler; - element_compiler = new_computation_compiler(false); + element_compiler = new ComputationCompiler(compiler, false); ae.get_element().get_visited_by(element_compiler); - reference_compiler = new_computation_compiler(true); + reference_compiler = new ComputationCompiler(compiler, true); ae.get_collection().get_visited_by(reference_compiler); collection_as_ref = reference_compiler.get_ref(); - result.addAll(reference_compiler.get_pre_instructions()); - result.addAll(element_compiler.get_pre_instructions()); + result.add(reference_compiler.get_init()); + result.add(element_compiler.get_init()); result.add ( new SetValue @@ -367,8 +218,8 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ) ); - reference_compiler.free_anonymous_variables(); - element_compiler.free_anonymous_variables(); + reference_compiler.release_variables(); + element_compiler.release_variables(); } @Override @@ -415,14 +266,14 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor */ final ComputationCompiler cc; - cc = new_computation_compiler(false); + cc = new ComputationCompiler(compiler, false); a.get_condition().get_visited_by(cc); - result.addAll(cc.get_pre_instructions()); + result.add(cc.get_init()); result.add(new Assert(cc.get_computation())); - cc.free_anonymous_variables(); + cc.release_variables(); } @Override @@ -432,64 +283,30 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor /* * Fate: (clear collection) * - * Wyrd: - * + * Wyrd: */ - /* final ComputationCompiler reference_compiler; - final Ref iterator, collection_ref; - final List while_body; + final Ref collection_ref; - reference_compiler = new_computation_compiler(true); + reference_compiler = new ComputationCompiler(compiler, true); c.get_collection().get_visited_by(reference_compiler); - result.addAll(reference_compiler.get_pre_instructions()); - - iterator = anonymous_variables.reserve(Type.INT); - collection_ref = reference_compiler.get_ref(); - while_body.add - ( - new Remove - ( - new RelativeRef - ( - collection_ref, - Collections.singletonList - ( - new Cast(new ValueOf(iterator), Type.STRING) - ) - ) - ) - ); - - while_body.add - ( - new SetValue - ( - iterator, - Operation.minus(new ValueOf(iterator), new Constant(Type.INT, "1")) - ) - ); - + result.add(reference_compiler.get_init()); result.add ( - new While + Clear.generate ( - Operation.greater_equal_than - ( - new ValueOf(iterator), - new Constant(Type.INT, "0") - ), - while_body + compiler.anonymous_variables(), + compiler.assembler(), + new Size(collection_ref), + collection_ref ) ); - anonymous_variables.release(iterator); - reference_compiler.free_anonymous_variables(); - */ + reference_compiler.release_variables(); } @Override @@ -508,16 +325,16 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor * ) * * Wyrd: - * (ifelse c0 + * + * > + * > + * > */ InstructionCompiler ic; ComputationCompiler cc; @@ -540,28 +357,37 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor { current_else_branch = new ArrayList(); - ic = new_instruction_compiler(); - cc = new_computation_compiler(false); + ic = new InstructionCompiler(compiler); + cc = new ComputationCompiler(compiler, false); branch.get_car().get_visited_by(cc); - previous_else_branch.addAll(cc.get_pre_instructions()); + previous_else_branch.add(cc.get_init()); previous_else_branch.add ( - new IfElseInstruction + IfElse.generate ( + compiler.anonymous_variables(), + compiler.assembler(), cc.get_computation(), ic.get_result(), - current_else_branch + compiler.assembler().merge(current_else_branch) ) ); previous_else_branch = current_else_branch; - cc.free_anonymous_variables(); + cc.release_variables(); } - previous_else_branch.add(new NOP()); + previous_else_branch.add + ( + NOP.generate + ( + compiler.anonymous_variables(), + compiler.assembler() + ) + ); } @Override @@ -575,14 +401,14 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor */ final ComputationCompiler cc; - cc = new_computation_compiler(false); + cc = new ComputationCompiler(compiler, false); n.get_content().get_visited_by(cc); - result.addAll(cc.get_pre_instructions()); + result.add(cc.get_init()); result.add(new Display(Collections.singletonList(cc.get_computation()))); - cc.free_anonymous_variables(); + cc.release_variables(); } @Override @@ -611,11 +437,11 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor { final ComputationCompiler cc; - cc = new_computation_compiler(false); + cc = new ComputationCompiler(compiler, false); fate_computation.get_visited_by(cc); - result.addAll(cc.get_pre_instructions()); + result.add(cc.get_init()); cc_list.add(cc); parameters.add(cc.get_computation()); @@ -625,7 +451,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor for (final ComputationCompiler cc: cc_list) { - cc.free_anonymous_variables(); + cc.release_variables(); } } @@ -645,26 +471,28 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor final InstructionCompiler if_true_ic; final InstructionCompiler if_false_ic; - cc = new_computation_compiler(false); - if_true_ic = new_instruction_compiler(); - if_false_ic = new_instruction_compiler(); + cc = new ComputationCompiler(compiler, false); + if_true_ic = new InstructionCompiler(compiler); + if_false_ic = new InstructionCompiler(compiler); n.get_condition().get_visited_by(cc); n.get_if_true().get_visited_by(if_true_ic); n.get_if_false().get_visited_by(if_false_ic); - result.addAll(cc.get_pre_instructions()); + result.add(cc.get_init()); result.add ( - new IfElseInstruction + IfElse.generate ( + compiler.anonymous_variables(), + compiler.assembler(), cc.get_computation(), if_true_ic.get_result(), if_false_ic.get_result() ) ); - cc.free_anonymous_variables(); + cc.release_variables(); } @Override @@ -682,24 +510,25 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor final ComputationCompiler cc; final InstructionCompiler if_true_ic; - cc = new_computation_compiler(false); - if_true_ic = new_instruction_compiler(); + cc = new ComputationCompiler(compiler, false); + if_true_ic = new InstructionCompiler(compiler); n.get_condition().get_visited_by(cc); n.get_if_true().get_visited_by(if_true_ic); - result.addAll(cc.get_pre_instructions()); + result.add(cc.get_init()); result.add ( - new IfElseInstruction + If.generate ( + compiler.anonymous_variables(), + compiler.assembler(), cc.get_computation(), - if_true_ic.get_result(), - Collections.singletonList(new NOP()) + if_true_ic.get_result() ) ); - cc.free_anonymous_variables(); + cc.release_variables(); } @Override @@ -722,11 +551,11 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor { final InstructionCompiler ic; - ic = new_instruction_compiler(); + ic = new InstructionCompiler(compiler); fate_instruction.get_visited_by(ic); - result.addAll(ic.get_result()); + result.add(ic.get_result()); } } @@ -756,23 +585,23 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor { final ComputationCompiler cc; - cc = new_computation_compiler(true); + cc = new ComputationCompiler(compiler, true); fate_computation.get_visited_by(cc); - result.addAll(cc.get_pre_instructions()); + result.add(cc.get_init()); cc_list.add(cc); parameters.add(cc.get_ref()); } - macro_manager.push(n.get_macro(), parameters); + compiler.macros().push(n.get_macro(), parameters); n.get_macro().get_root().get_visited_by(this); - macro_manager.pop(); + compiler.macros().pop(); for (final ComputationCompiler cc: cc_list) { - cc.free_anonymous_variables(); + cc.release_variables(); } } @@ -791,12 +620,12 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor final ComputationCompiler cc; final InstructionCompiler ic; - cc = new_computation_compiler(false); - ic = new_instruction_compiler(); + cc = new ComputationCompiler(compiler, false); + ic = new InstructionCompiler(compiler); n.get_text().get_visited_by(cc); - result.addAll(cc.get_pre_instructions()); + result.add(cc.get_init()); for ( @@ -809,7 +638,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor result.add(new AddChoice(cc.get_computation(), ic.get_result())); - cc.free_anonymous_variables(); + cc.release_variables(); } @Override @@ -881,24 +710,29 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor final ComputationCompiler elem_cc, collection_cc; final Ref elem, collection_size, collection; - elem_cc = new_computation_compiler(false); - collection_cc = new_computation_compiler(true); + elem_cc = new ComputationCompiler(compiler, false); + collection_cc = new ComputationCompiler(compiler, true); + + elem = + compiler.anonymous_variables().reserve + ( + elem_cc.get_computation().get_type() + ); - elem = anonymous_variables.reserve(elem_cc.get_computation().get_type()); - collection_size = anonymous_variables.reserve(Type.INT); + collection_size = compiler.anonymous_variables().reserve(Type.INT); n.get_element().get_visited_by(elem_cc); n.get_collection().get_visited_by(collection_cc); - result.addAll(elem_cc.get_pre_instructions()); - result.addAll(collection_cc.get_pre_instructions()); + result.add(elem_cc.get_init()); + result.add(collection_cc.get_init()); collection = collection_cc.get_ref(); result.add(new SetValue(elem, elem_cc.get_computation())); result.add(new SetValue(collection_size, new Size(collection))); - elem_cc.free_anonymous_variables(); + elem_cc.release_variables(); if ( @@ -911,17 +745,18 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor final Computation value_of_elem, value_of_collection_size; final Ref index, found; - index = anonymous_variables.reserve(Type.INT); - found = anonymous_variables.reserve(Type.BOOLEAN); + index = compiler.anonymous_variables().reserve(Type.INT); + found = compiler.anonymous_variables().reserve(Type.BOOLEAN); value_of_elem = new ValueOf(elem); value_of_collection_size = new ValueOf(collection_size); - result.addAll + result.add ( BinarySearch.generate ( - anonymous_variables, + compiler.anonymous_variables(), + compiler.assembler(), value_of_elem, value_of_collection_size, collection, @@ -932,30 +767,33 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor result.add ( - new IfElseInstruction + If.generate ( + compiler.anonymous_variables(), + compiler.assembler(), new ValueOf(found), RemoveAt.generate ( - anonymous_variables, + compiler.anonymous_variables(), + compiler.assembler(), index, value_of_collection_size, collection - ), - Collections.singletonList(new NOP()) + ) ) ); - anonymous_variables.release(index); - anonymous_variables.release(found); + compiler.anonymous_variables().release(index); + compiler.anonymous_variables().release(found); } else { - result.addAll + result.add ( RemoveAllOf.generate ( - anonymous_variables, + compiler.anonymous_variables(), + compiler.assembler(), new ValueOf(elem), new ValueOf(collection_size), collection @@ -963,10 +801,10 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ); } - collection_cc.free_anonymous_variables(); + collection_cc.release_variables(); - anonymous_variables.release(elem); - anonymous_variables.release(collection_size); + compiler.anonymous_variables().release(elem); + compiler.anonymous_variables().release(collection_size); } @Override @@ -1018,19 +856,24 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor final Ref collection; final Computation value_of_collection_size; - elem_cc = new_computation_compiler(false); - collection_cc = new_computation_compiler(true); + elem_cc = new ComputationCompiler(compiler, false); + collection_cc = new ComputationCompiler(compiler, true); - elem = anonymous_variables.reserve(elem_cc.get_computation().get_type()); - collection_size = anonymous_variables.reserve(Type.INT); - found = anonymous_variables.reserve(Type.BOOLEAN); - index = anonymous_variables.reserve(Type.INT); + elem = + compiler.anonymous_variables().reserve + ( + elem_cc.get_computation().get_type() + ); + + collection_size = compiler.anonymous_variables().reserve(Type.INT); + found = compiler.anonymous_variables().reserve(Type.BOOLEAN); + index = compiler.anonymous_variables().reserve(Type.INT); n.get_element().get_visited_by(elem_cc); n.get_collection().get_visited_by(collection_cc); - result.addAll(elem_cc.get_pre_instructions()); - result.addAll(collection_cc.get_pre_instructions()); + result.add(elem_cc.get_init()); + result.add(collection_cc.get_init()); collection = collection_cc.get_ref(); @@ -1039,7 +882,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor result.add(new SetValue(elem, elem_cc.get_computation())); result.add(new SetValue(collection_size, new Size(collection))); - elem_cc.free_anonymous_variables(); + elem_cc.release_variables(); if ( @@ -1049,11 +892,12 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ).is_set() ) { - result.addAll + result.add ( BinarySearch.generate ( - anonymous_variables, + compiler.anonymous_variables(), + compiler.assembler(), new ValueOf(elem), value_of_collection_size, collection, @@ -1064,11 +908,12 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor } else { - result.addAll + result.add ( IterativeSearch.generate ( - anonymous_variables, + compiler.anonymous_variables(), + compiler.assembler(), new ValueOf(elem), value_of_collection_size, collection, @@ -1078,29 +923,31 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor ); } - anonymous_variables.release(elem); + compiler.anonymous_variables().release(elem); result.add ( - new IfElseInstruction + If.generate ( + compiler.anonymous_variables(), + compiler.assembler(), new ValueOf(found), RemoveAt.generate ( - anonymous_variables, + compiler.anonymous_variables(), + compiler.assembler(), index, value_of_collection_size, collection - ), - Collections.singletonList(new NOP()) + ) ) ); - anonymous_variables.release(index); - anonymous_variables.release(found); - anonymous_variables.release(collection_size); + compiler.anonymous_variables().release(index); + compiler.anonymous_variables().release(found); + compiler.anonymous_variables().release(collection_size); - collection_cc.free_anonymous_variables(); + collection_cc.release_variables(); } @Override @@ -1111,10 +958,18 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor throws Throwable { /* - * Fate: (sequence_call ) - * Wyrd: (sequence_call ) + * Fate: (sequence_call string) + * Wyrd: (set_pc