| summaryrefslogtreecommitdiff |
diff options
20 files changed, 1006 insertions, 124 deletions
diff --git a/src/core/src/tonkadur/fate/v1/lang/Variable.java b/src/core/src/tonkadur/fate/v1/lang/Variable.java index dfd6c04..b81d2bf 100644 --- a/src/core/src/tonkadur/fate/v1/lang/Variable.java +++ b/src/core/src/tonkadur/fate/v1/lang/Variable.java @@ -76,6 +76,11 @@ public class Variable extends DeclaredEntity return type; } + public VariableScope get_scope () + { + return scope; + } + @Override public DeclaredEntity generate_comparable_to (final DeclaredEntity de) { diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java index 759a882..a3ff50c 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java @@ -139,7 +139,7 @@ public class AddElement extends Instruction public Computation get_element () { - return element + return element; } /**** Misc. ****************************************************************/ diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java index bc93e6a..d02e3b2 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java @@ -132,6 +132,16 @@ public class RemoveElement extends Instruction nv.visit_remove_element(this); } + public Computation get_element () + { + return element; + } + + public Computation get_collection () + { + return collection; + } + /**** Misc. ****************************************************************/ @Override public String toString () diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/SetValue.java b/src/core/src/tonkadur/fate/v1/lang/instruction/SetValue.java index 1d840e6..0ea9a98 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/SetValue.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/SetValue.java @@ -110,6 +110,16 @@ public class SetValue extends Instruction nv.visit_set_value(this); } + public Computation get_value () + { + return element; + } + + public Computation get_reference () + { + return value_reference; + } + /**** Misc. ****************************************************************/ @Override public String toString () diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index 3288598..6c12fa4 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -31,8 +31,10 @@ DECLARE_TEXT_EFFECT_KW: L_PAREN ('declare'|'define'|'def')'_text_effect' SEP+; DECLARE_VARIABLE_KW: L_PAREN ('declare'|'define'|'def')'_var'('iable')? SEP+; DEFINE_MACRO_KW: L_PAREN ('declare'|'define'|'def')'_macro' SEP+; DEFINE_SEQUENCE_KW: L_PAREN ('declare'|'define'|'def')'_sequence' SEP+; +DELETE_KW: L_PAREN 'delete' SEP+; DIVIDE_KW: L_PAREN ('divide'|'/'|'div') SEP+; ENABLE_TEXT_EFFECT_KW: L_PAREN 'text_effect' SEP+; +END_KW: L_PAREN 'end)'; EQUALS_KW: L_PAREN ('equals'|'='|'=='|'eq') SEP+; EVENT_KW: L_PAREN 'event' SEP+; EXTENSION_FIRST_LEVEL_KW: L_PAREN '@'; @@ -45,15 +47,15 @@ GREATER_EQUAL_THAN_KW: L_PAREN ('greater_equal_than'|'>='|'ge') SEP+; GREATER_THAN_KW: L_PAREN ('greater_than'|'>'|'gt') SEP+; IF_ELSE_KW: L_PAREN ('if_else'|'ifelse') 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+; IS_MEMBER_KW: L_PAREN ('is_member'|'contains') SEP+; LOWER_EQUAL_THAN_KW: L_PAREN ('lower_equal_than'|'=<'|'<='|'le') SEP+; LOWER_THAN_KW: L_PAREN ('lower_than'|'<'|'lt') SEP+; -IMACRO_KW: L_PAREN 'imacro' SEP+; -VMACRO_KW: L_PAREN 'vmacro' SEP+; MINUS_KW: L_PAREN ('minus'|'-') SEP+; NEWLINE_KW: L_PAREN 'newline)'; +NEW_KW: L_PAREN 'new' SEP+; NOT_KW: L_PAREN ('not'|'~'|'!') SEP+; ONE_IN_KW: L_PAREN 'one_in' SEP+; OR_KW: L_PAREN ('or'|'\\/') SEP+; @@ -74,6 +76,7 @@ TIMES_KW: L_PAREN ('times'|'*') SEP+; TRUE_KW: L_PAREN 'true)'; VAL_KW: L_PAREN ('val'|'value') SEP+; VARIABLE_KW: L_PAREN ('variable'|'var') SEP+; +VMACRO_KW: L_PAREN 'vmacro' SEP+; WORD: (~([ \t\r\n()])|'\\)'|'\\(')+; 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 af82748..817403e 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 @@ -8,20 +8,51 @@ import tonkadur.wyrd.v1.lang.World; public class ComputationCompiler extends FateVisitor { + protected final MacroManager macro_manager; + protected final AnonymousVariableManager anonymous_variables; protected final World wyrd_world; protected final List<Instruction> pre_computation_instructions; + protected final List<Ref> allocated_variables; + protected Computation result; - public ComputationCompiler (final World wyrd_world) + public ComputationCompiler + ( + final MacroManager macro_manager, + final AnonymousVariableManager anonymous_variables, + final World wyrd_world + ) { + this.macro_manager = macro_manager; + this.anonymous_variables = anonymous_variables; this.wyrd_world = wyrd_world; + allocated_variables = new ArrayList<Ref>(); pre_computation_instructions = new ArrayList<Instruction>(); + result = null; + } + + public List<Instruction> get_pre_instructions () + { + return pre_computation_instructions; + } + + public Computation get_computation () + { + return result; + } + + public void free_anonymous_variables () + { + for (final Ref ref: allocated_variables) + { + anonymous_variables.release(ref); + } } @Override public void visit_at_reference ( - final tonkadur.fate.v1.lang.valued_node.AtReference n + final tonkadur.fate.v1.lang.computation.AtReference n ) throws Throwable { @@ -31,7 +62,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_cast ( - final tonkadur.fate.v1.lang.valued_node.Cast n + final tonkadur.fate.v1.lang.computation.Cast n ) throws Throwable { @@ -41,7 +72,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_cond_value ( - final tonkadur.fate.v1.lang.valued_node.CondValue n + final tonkadur.fate.v1.lang.computation.CondValue n ) throws Throwable { @@ -51,7 +82,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_constant ( - final tonkadur.fate.v1.lang.valued_node.Constant n + final tonkadur.fate.v1.lang.computation.Constant n ) throws Throwable { @@ -61,7 +92,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_count_operator ( - final tonkadur.fate.v1.lang.valued_node.CountOperator n + final tonkadur.fate.v1.lang.computation.CountOperator n ) throws Throwable { @@ -71,7 +102,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_field_reference ( - final tonkadur.fate.v1.lang.valued_node.FieldReference n + final tonkadur.fate.v1.lang.computation.FieldReference n ) throws Throwable { @@ -81,7 +112,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_if_else_value ( - final tonkadur.fate.v1.lang.valued_node.IfElseValue n + final tonkadur.fate.v1.lang.computation.IfElseValue n ) throws Throwable { @@ -91,7 +122,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_is_member_operator ( - final tonkadur.fate.v1.lang.valued_node.IsMemberOperator n + final tonkadur.fate.v1.lang.computation.IsMemberOperator n ) throws Throwable { @@ -101,7 +132,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_macro_value_call ( - final tonkadur.fate.v1.lang.valued_node.MacroValueCall n + final tonkadur.fate.v1.lang.computation.MacroValueCall n ) throws Throwable { @@ -111,7 +142,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_newline ( - final tonkadur.fate.v1.lang.valued_node.Newline n + final tonkadur.fate.v1.lang.computation.Newline n ) throws Throwable { @@ -121,7 +152,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_operation ( - final tonkadur.fate.v1.lang.valued_node.Operation n + final tonkadur.fate.v1.lang.computation.Operation n ) throws Throwable { @@ -131,7 +162,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_paragraph ( - final tonkadur.fate.v1.lang.valued_node.Paragraph n + final tonkadur.fate.v1.lang.computation.Paragraph n ) throws Throwable { @@ -141,7 +172,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_parameter_reference ( - final tonkadur.fate.v1.lang.valued_node.ParameterReference n + final tonkadur.fate.v1.lang.computation.ParameterReference n ) throws Throwable { @@ -151,7 +182,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_ref_operator ( - final tonkadur.fate.v1.lang.valued_node.RefOperator n + final tonkadur.fate.v1.lang.computation.RefOperator n ) throws Throwable { @@ -161,7 +192,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_text_with_effect ( - final tonkadur.fate.v1.lang.valued_node.TextWithEffect n + final tonkadur.fate.v1.lang.computation.TextWithEffect n ) throws Throwable { @@ -171,7 +202,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_value_to_rich_text ( - final tonkadur.fate.v1.lang.valued_node.ValueToRichText n + final tonkadur.fate.v1.lang.computation.ValueToRichText n ) throws Throwable { @@ -181,7 +212,7 @@ public class ComputationCompiler extends FateVisitor @Override public void visit_variable_reference ( - final tonkadur.fate.v1.lang.valued_node.VariableReference n + final tonkadur.fate.v1.lang.computation.VariableReference n ) throws Throwable { diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/FateVisitor.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/FateVisitor.java index c84d5e7..f6af43d 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/FateVisitor.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/FateVisitor.java @@ -145,7 +145,7 @@ public abstract class FateVisitor implements NodeVisitor /* Valued Nodes */ public void visit_at_reference ( - final tonkadur.fate.v1.lang.valued_node.AtReference n + final tonkadur.fate.v1.lang.computation.AtReference n ) throws Throwable { @@ -154,7 +154,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_cast ( - final tonkadur.fate.v1.lang.valued_node.Cast n + final tonkadur.fate.v1.lang.computation.Cast n ) throws Throwable { @@ -163,7 +163,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_cond_value ( - final tonkadur.fate.v1.lang.valued_node.CondValue n + final tonkadur.fate.v1.lang.computation.CondValue n ) throws Throwable { @@ -172,7 +172,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_constant ( - final tonkadur.fate.v1.lang.valued_node.Constant n + final tonkadur.fate.v1.lang.computation.Constant n ) throws Throwable { @@ -181,7 +181,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_count_operator ( - final tonkadur.fate.v1.lang.valued_node.CountOperator n + final tonkadur.fate.v1.lang.computation.CountOperator n ) throws Throwable { @@ -190,7 +190,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_field_reference ( - final tonkadur.fate.v1.lang.valued_node.FieldReference n + final tonkadur.fate.v1.lang.computation.FieldReference n ) throws Throwable { @@ -199,7 +199,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_if_else_value ( - final tonkadur.fate.v1.lang.valued_node.IfElseValue n + final tonkadur.fate.v1.lang.computation.IfElseValue n ) throws Throwable { @@ -208,7 +208,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_is_member_operator ( - final tonkadur.fate.v1.lang.valued_node.IsMemberOperator n + final tonkadur.fate.v1.lang.computation.IsMemberOperator n ) throws Throwable { @@ -217,7 +217,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_macro_value_call ( - final tonkadur.fate.v1.lang.valued_node.MacroValueCall n + final tonkadur.fate.v1.lang.computation.MacroValueCall n ) throws Throwable { @@ -226,7 +226,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_newline ( - final tonkadur.fate.v1.lang.valued_node.Newline n + final tonkadur.fate.v1.lang.computation.Newline n ) throws Throwable { @@ -235,7 +235,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_operation ( - final tonkadur.fate.v1.lang.valued_node.Operation n + final tonkadur.fate.v1.lang.computation.Operation n ) throws Throwable { @@ -244,7 +244,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_paragraph ( - final tonkadur.fate.v1.lang.valued_node.Paragraph n + final tonkadur.fate.v1.lang.computation.Paragraph n ) throws Throwable { @@ -253,7 +253,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_parameter_reference ( - final tonkadur.fate.v1.lang.valued_node.ParameterReference n + final tonkadur.fate.v1.lang.computation.ParameterReference n ) throws Throwable { @@ -262,7 +262,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_ref_operator ( - final tonkadur.fate.v1.lang.valued_node.RefOperator n + final tonkadur.fate.v1.lang.computation.RefOperator n ) throws Throwable { @@ -271,7 +271,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_text_with_effect ( - final tonkadur.fate.v1.lang.valued_node.TextWithEffect n + final tonkadur.fate.v1.lang.computation.TextWithEffect n ) throws Throwable { @@ -280,7 +280,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_value_to_rich_text ( - final tonkadur.fate.v1.lang.valued_node.ValueToRichText n + final tonkadur.fate.v1.lang.computation.ValueToRichText n ) throws Throwable { @@ -289,7 +289,7 @@ public abstract class FateVisitor implements NodeVisitor public void visit_variable_reference ( - final tonkadur.fate.v1.lang.valued_node.VariableReference n + final tonkadur.fate.v1.lang.computation.VariableReference n ) throws Throwable { 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 2e49ae9..0f24995 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 @@ -1,23 +1,59 @@ package tonkadur.wyrd.v1.compiler.fate.v1; +/* TODO: clean this up, way too many `new ...` could be reused. */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import tonkadur.error.Error; -import tonkadur.wyrd.v1.lang.meta.Instruction; +import tonkadur.functional.Cons; import tonkadur.wyrd.v1.lang.World; +import tonkadur.wyrd.v1.lang.meta.Computation; +import tonkadur.wyrd.v1.lang.meta.Instruction; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.computation.Cast; +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.Operation; +import tonkadur.wyrd.v1.lang.computation.Ref; +import tonkadur.wyrd.v1.lang.computation.RelativeRef; +import tonkadur.wyrd.v1.lang.computation.Size; +import tonkadur.wyrd.v1.lang.computation.ValueOf; + +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.SetValue; +import tonkadur.wyrd.v1.lang.instruction.While; + +import tonkadur.wyrd.v1.compiler.util.BinarySearch; +import tonkadur.wyrd.v1.compiler.util.AnonymousVariableManager; + public class InstructionCompiler extends FateVisitor { protected final AnonymousVariableManager anonymous_variables; protected final World wyrd_world; + protected final MacroManager macro_manager; protected final List<Instruction> result; public InstructionCompiler ( + final MacroManager macro_manager, final AnonymousVariableManager anonymous_variables, final World wyrd_world ) { + this.macro_manager = macro_manager; this.anonymous_variables = anonymous_variables; this.wyrd_world = wyrd_world; result = new ArrayList<Instruction>(); @@ -25,17 +61,61 @@ public class InstructionCompiler extends FateVisitor public InstructionCompiler ( + final MacroManager macro_manager, final AnonymousVariableManager anonymous_variables, final World wyrd_world, final List<Instruction> result ) { + this.macro_manager = macro_manager; this.anonymous_variables = anonymous_variables; this.wyrd_world = wyrd_world; this.result = result; } - protected static void add_element_to_set + protected List<Instruction> get_result () + { + return result; + } + + protected ComputationCompiler new_computation_compiler () + { + return + new ComputationCompiler + ( + macro_manager, + anonymous_variables, + wyrd_world + ); + } + + protected InstructionCompiler new_instruction_compiler () + { + return + new InstructionCompiler + ( + macro_manager, + anonymous_variables, + wyrd_world + ); + } + + protected InstructionCompiler new_instruction_compiler + ( + final List<Instruction> result + ) + { + return + new InstructionCompiler + ( + macro_manager, + anonymous_variables, + wyrd_world, + result + ); + } + + protected void add_element_to_set ( final tonkadur.fate.v1.lang.instruction.AddElement ae ) @@ -68,12 +148,7 @@ public class InstructionCompiler extends FateVisitor final List<Instruction> while_body, else_branch; /**** Getting the Element as a ref ****/ - element_compiler = - new ComputationCompiler - ( - anonymous_variables, - wyrd_world - ); + element_compiler = new_computation_compiler(); ae.get_element().visit(element_compiler); @@ -89,12 +164,7 @@ public class InstructionCompiler extends FateVisitor ); /**** Getting the Collection as a ref ****/ - reference_compiler = - new ComputationCompiler - ( - anonymous_variables, - wyrd_world - ); + reference_compiler = new_computation_compiler(); ae.get_collection().visit(reference_compiler); @@ -247,7 +317,7 @@ public class InstructionCompiler extends FateVisitor element_compiler.free_anonymous_variables(); } - protected static void add_element_to_list + protected void add_element_to_list ( final tonkadur.fate.v1.lang.instruction.AddElement ae ) @@ -266,21 +336,11 @@ public class InstructionCompiler extends FateVisitor final Ref collection_as_ref; final ComputationCompiler element_compiler, reference_compiler; - element_compiler = - new ComputationCompiler - ( - anonymous_variables, - wyrd_world - ); + element_compiler = new_computation_compiler(); ae.get_element().visit(element_compiler); - reference_compiler = - new ComputationCompiler - ( - anonymous_variables, - wyrd_world - ); + reference_compiler = new_computation_compiler(); ae.get_collection().visit(reference_compiler); @@ -308,7 +368,7 @@ public class InstructionCompiler extends FateVisitor Type.STRING ) ) - ) + ), element_compiler.get_computation() ) ); @@ -327,7 +387,7 @@ public class InstructionCompiler extends FateVisitor final tonkadur.fate.v1.lang.type.Type collection_type; final tonkadur.fate.v1.lang.type.CollectionType collection_true_type; - collection_type = ae.get_collection.get_type(); + collection_type = ae.get_collection().get_type(); if ( @@ -356,7 +416,7 @@ public class InstructionCompiler extends FateVisitor { final ComputationCompiler cc; - cc = new ComputationCompiler(wyrd_world); + cc = new_computation_compiler(); a.get_condition().visit(cc); @@ -374,11 +434,12 @@ public class InstructionCompiler extends FateVisitor final Ref iterator, collection_ref; final List<Instruction> while_body; - reference_compiler = - new ComputationCompiler(anonymous_variables, wyrd_world); + reference_compiler = new_computation_compiler(); c.get_collection().visit(reference_compiler); + result.addAll(reference_compiler.get_pre_instructions()); + iterator = anonymous_variables.reserve(Type.INT); if (!(reference_compiler.get_computation() instanceof Ref)) @@ -390,7 +451,17 @@ public class InstructionCompiler extends FateVisitor while_body.add ( - new Remove(new ValueOf(iterator), collection_ref) + new Remove + ( + new RelativeRef + ( + collection_ref, + Collections.singletonList + ( + new Cast(new ValueOf(iterator), Type.STRING) + ) + ) + ) ); while_body.add @@ -416,6 +487,7 @@ public class InstructionCompiler extends FateVisitor ); anonymous_variables.release(iterator); + reference_compiler.free_anonymous_variables(); } @Override @@ -437,8 +509,8 @@ public class InstructionCompiler extends FateVisitor final Cons < - tonkadur.fate.v1.lang.instruction.meta.Computation, - tonkadur.fate.v1.lang.instruction.meta.Instruction + tonkadur.fate.v1.lang.meta.Computation, + tonkadur.fate.v1.lang.meta.Instruction > branch: ci.get_branches() @@ -446,8 +518,8 @@ public class InstructionCompiler extends FateVisitor { current_else_branch = new ArrayList<Instruction>(); - ic = new InstructionCompiler(anonymous_variables, wyrd_world); - cc = new ComputationCompiler(anonymous_variables, wyrd_world); + ic = new_instruction_compiler(); + cc = new_computation_compiler(); branch.get_car().visit(cc); @@ -463,16 +535,27 @@ public class InstructionCompiler extends FateVisitor ); previous_else_branch = current_else_branch; + + cc.free_anonymous_variables(); } - previous_else_branch.add(Collections.singleton(new NOP()); + previous_else_branch.add(Collections.singleton(new NOP())); } @Override public void visit_display (final tonkadur.fate.v1.lang.instruction.Display n) throws Throwable { - throw new UnhandledASTElementException(); + final ComputationCompiler cc; + + cc = new_computation_compiler(); + + n.get_content.visit(cc); + + result.addAll(cc.get_pre_instructions()); + result.add(new Display(cc.get_computation())); + + cc.free_anonymous_variables(); } @Override @@ -482,7 +565,39 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + final List<ComputationCompiler> cc_list; + final List<Computation> parameters; + + cc_list = new ArrayList<ComputationCompiler>(); + parameters = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation fate_computation: + n.get_parameters() + ) + { + final ComputationCompiler cc; + + cc = new_computation_compiler(); + + fate_computation.visit(cc); + + result.addAll(cc.get_pre_instructions()); + + cc_list.add(cc); + parameters.add(cc.get_computation()); + } + + result.add + ( + new EventCall(n.get_event().get_name(), cc.get_computation()) + ); + + for (final ComputationCompiler cc: cc_list) + { + cc.free_anonymous_variables(); + } } @Override @@ -492,7 +607,30 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + final ComputationCompiler cc; + final InstructionCompiler if_true_ic; + final InstructionCompiler if_false_ic; + + cc = new_computation_compiler(); + if_true_ic = new_instruction_compiler(); + if_false_ic = new_instruction_compiler(); + + n.get_condition.visit(cc); + n.get_if_true().visit(if_true_ic); + n.get_if_false().visit(if_false_ic); + + result.addAll(cc.get_pre_instructions()); + result.add + ( + new IfElseInstruction + ( + cc.get_computation(), + if_true_ic.get_result(), + if_false_ic.get_result() + ) + ); + + cc.free_anonymous_variables(); } @Override @@ -502,7 +640,27 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + final ComputationCompiler cc; + final InstructionCompiler if_true_ic; + + cc = new_computation_compiler(); + if_true_ic = new_instruction_compiler(); + + n.get_condition.visit(cc); + n.get_if_true().visit(if_true_ic); + + result.addAll(cc.get_pre_instructions()); + result.add + ( + new IfElseInstruction + ( + cc.get_computation(), + if_true_ic.get_result(), + Collections.singletonList(new NOP()) + ) + ); + + cc.free_anonymous_variables(); } @Override @@ -512,7 +670,20 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + for + ( + final tonkadur.fate.v1.lang.meta.Instruction fate_instruction: + n.get_content() + ) + { + final InstructionCompiler ic; + + ic = new_instruction_compiler(); + + fate_instruction.visit(ic); + + result.addAll(ic.get_result()); + } } @Override @@ -522,7 +693,42 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + final tonkadur.fate.v1.lang.meta.Instruction fate_macro_root; + final List<ComputationCompiler> cc_list; + final List<Computation> parameters; + + cc_list = new ArrayList<ComputationCompiler>(); + parameters = new ArrayList<Computation>(); + + for + ( + final tonkadur.fate.v1.lang.meta.Computation fate_computation: + n.get_parameters() + ) + { + final ComputationCompiler cc; + + cc = new_computation_compiler(); + + fate_computation.visit(cc); + + result.addAll(cc.get_pre_instructions()); + + cc_list.add(cc); + parameters.add(cc.get_computation()); + } + + fate_macro_root = + macro_manager.push_context(n.get_name(), cc.get_computation()); + + fate_macro_root.visit(this); + + for (final ComputationCompiler cc: cc_list) + { + cc.free_anonymous_variables(); + } + + macro_manager.pop_context(); } @Override @@ -532,7 +738,28 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + final ComputationCompiler cc; + final InstructionCompiler ic; + + cc = new_computation_compiler(); + ic = new_instruction_compiler(); + + n.get_text().visit(cc); + + result.addAll(cc.get_pre_instructions()); + + for + ( + final tonkadur.fate.v1.lang.meta.Instruction fate_instruction: + n.get_effects() + ) + { + fate_instruction.visit(ic); + } + + result.add(new AddChoice(cc.get_computation(), ic.get_result())); + + cc.free_anonymous_variables(); } @Override @@ -542,7 +769,16 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + for + ( + final tonkadur.fate.v1.lang.meta.Instruction fate_instruction: + n.get_choices() + ) + { + fate_instruction.visit(this); + } + + fate_instruction.add(new ResolveChoices()); } @Override @@ -552,7 +788,233 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + /* + * Fate: + * (remove_all_of element collection) + * + * Wyrd: + * (declare_variable int .index) + * (declare_variable int .limit) + * (declare_variable <element_type> .elem) + * (declare_variable int .found) + * (set .index 0) + * (set .limit (- (size collection) 1)) + * (set .elem element) ;; avoid re-computing element + * (set .found 0) + * (while (< .index .limit) + * (ifelse (= (var .found) 0) + * ( + * (nop) + * ) + * ( + * (ifelse (= (var .elem) (var collection[.index])) + * (set .found (+ (var .found) 1)) + * (nop) + * ) + * (set + * collection[.index] + * (var collection[(+ (var .index) (var .found))]) + * ) + * ) + * ) + * (set .index (+ (var .index) 1)) + * ) + * (while (> (var .found) 0) + * (set .found (- (var .found) 1)) + * (remove collection[(- (var .limit) (var .found))]) + * ) + */ + final ComputationCompiler elem_cc, collection_cc; + final Ref index, limit, elem, found; + final Ref collection_as_ref; + final List<Instruction> while_body, while_body2, if_false_body; + + elem_cc = new_computation_compiler(); + collection_cc = new_computation_compiler(); + + while_body = new ArrayList<Instruction>(); + while_body2 = new ArrayList<Instruction>(); + if_false_body = new ArrayList<Instruction>(); + + /* Get element with a minimum of anonymous variables */ + n.get_element().visit(elem_cc); + + result.addAll(elem_cc.get_pre_instructions()); + + elem = anonymous_variable.reserve(elem_cc.get_computation().get_type()); + + result.add(new SetValue(elem, elem_cc.get_computation())); + + elem_cc.free_anonymous_variables(); + /****/ + + n.get_collection().visit(collection_cc); + + if (!(collection_cc.get_computation() instanceof Ref)) + { + /* TODO: error. */ + } + + result.addAll(collection_cc.get_pre_instructions()); + + collection_as_ref = (Ref) collection_cc.get_computation(); + + index = anonymous_variable.reserve(Type.INT); + limit = anonymous_variable.reserve(Type.INT); + found = anonymous_variable.reserve(Type.INT); + + result.addAll(collection_cc.get_pre_instructions()); + + result.add(new SetValue(index, new Constant(Type.INT, "0"))); + result.add + ( + new SetValue + ( + limit, + Operation.minus + ( + new Size(collection_as_ref), + new Constant(Type.INT, "1") + ) + ) + ); + result.add(new SetValue(found, new Constant(Type.INT, "0"))); + + if_false_body.add + ( + new IfElseInstruction + ( + Operation.equals + ( + new ValueOf(elem), + new ValueOf + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast(new ValueOf(index), Type.STRING) + ) + ) + ) + ), + Collections.singletonList + ( + new SetValue + ( + found, + Operation.plus + ( + new ValueOf(found), + new Constant(Type.INT, "1") + ) + ) + ), + new NOP() + ) + ); + + if_false_body.add + ( + new SetValue + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast(new ValueOf(index), Type.STRING) + ) + ), + new ValueOf + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast + ( + Operation.plus(new ValueOf(index), new ValueOf(found)), + Type.STRING + ) + ) + ) + ) + ) + ); + + while_body.add + ( + new IfElseInstruction + ( + Operation.equal(new ValueOf(found), new Constant(Type.INT, "0")), + Collections.singletonList(new NOP()), + if_false_body + ) + ); + + while_body.add + ( + new SetValue + ( + index, + Operation.plus(new ValueOf(index), new Constant(Type.INT, "1")) + ) + ); + + result.add + ( + new While + ( + Operation.less_than(new ValueOf(index), new ValueOf(limit)), + while_body + ) + ); + + while_body2.add + ( + new SetValue + ( + found, + Operation.minus(new ValueOf(found), new Constant(Type.INT, "1")) + ) + ); + + while_body2.add + ( + new Remove + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast + ( + Operation.minus(new ValueOf(limit), new ValueOf(found)), + Type.STRING + ) + ) + ) + ) + ); + + result.add + ( + new While + ( + Operation.greater_than + ( + new ValueOf(found), + new Constant(Type.INT, "0") + ), + while_body2 + ) + ); + + collection_cc.free_anonymous_variables(); } @Override @@ -562,7 +1024,247 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + /* + * Fate: + * (remove_element element collection) + * + * Wyrd: + * (declare_variable int .index) + * (declare_variable int .limit) + * (declare_variable <element_type> .elem) + * (declare_variable boolean .found) + * (declare_variable int .next) + * (set .index 0) + * (set .limit (- (size collection) 1)) + * (set .elem element) ;; avoid re-computing element + * (set .found false) + * (while (< .index .limit) + * (set .next (+ (var index) 1)) + * (ifelse (var .found) + * ( + * (set collection[.index] (var collection[.next])) + * ) + * (ifelse (= (var .elem) (var collection[.index])) + * (;; if_true_body + * (set .found true) + * (set collection[.index] (var collection[.next])) + * ) + * (nop) + * ) + * ) + * (set .index (var .next)) + * ) + * (ifelse (or (var .found) (= (var .elem) (var collection[.index]))) + * (remove collection[.limit]) + * (nop) + * ) + */ + final ComputationCompiler elem_cc, collection_cc; + final Ref index, limit, elem, found, next; + final Ref collection_as_ref; + final List<Instruction> while_body, if_true_body; + + elem_cc = new_computation_compiler(); + collection_cc = new_computation_compiler(); + + while_body = new ArrayList<Instruction>(); + if_true_body = new ArrayList<Instruction>(); + + /* Minimize variable usage for element ***********/ + n.get_element().visit(elem_cc); + + result.addAll(elem_cc.get_pre_instructions()); + + elem = anonymous_variable.reserve(elem_cc.get_computation().get_type()); + + result.add(new SetValue(elem, elem_cc.get_computation())); + + elem_cc.free_anonymous_variables(); + /***********/ + + n.get_collection().visit(collection_cc); + + result.addAll(collection_cc.get_pre_instructions()); + + if (!(collection_cc.get_computation() instanceof Ref)) + { + /* TODO: error. */ + } + + collection_as_ref = (Ref) collection_cc.get_computation(); + + index = anonymous_variable.reserve(Type.INT); + limit = anonymous_variable.reserve(Type.INT); + found = anonymous_variable.reserve(Type.BOOLEAN); + next = anonymous_variable.reserve(Type.INT); + + result.add(new SetValue(index, new Constant(Type.INT, "0"))); + result.add + ( + new SetValue + ( + limit, + Operation.minus + ( + new Size(collection_as_ref), + new Constant(Type.INT, "1") + ) + ) + ); + result.add(new SetValue(found, Constant.FALSE)); + + if_true_branch.add(new SetValue(found, Constant.TRUE)); + if_true_branch.add + ( + new SetValue + ( + /* collection[.index] */ + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast(newValueOf(index), Type.STRING) + ) + ), + /* (var collection[.next]) */ + new ValueOf + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast(new ValueOf(next), Type.STRING) + ) + ) + ) + ) + ); + + while_body.add + ( + new SetValue + ( + next, + Operation.plus + ( + new ValueOf(index), + new Constant(Type.INT, "1") + ) + ) + ); + + while_body.add + ( + new IfElseInstruction + ( + new ValueOf(found), + Collections.singletonList + ( + new SetValue + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast(newValueOf(index), Type.STRING) + ) + ), + new ValueOf + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast(new ValueOf(next), Type.STRING) + ) + ) + ) + ) + ), + Collections.singletonList + ( + new IfElseInstruction + ( + Operation.equals + ( + new ValueOf(elem), + new ValueOf + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast(newValueOf(index), Type.STRING) + ) + ) + ) + ), + if_true_branch, + Collections.singleton(new NOP()) + ) + ) + ) + ); + + result.add + ( + new While + ( + Operation.less_than(new ValueOf(index), new ValueOf(limit)), + while_body + ) + ); + + result.add + ( + new IfElseInstruction + ( + Operation.or + ( + new ValueOf(found), + Operation.equals + ( + new ValueOf(elem), + new ValueOf + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast(newValueOf(index), Type.STRING) + ) + ) + ) + ) + ), + new Remove + ( + new RelativeRef + ( + collection_as_ref, + Collections.singletonList + ( + new Cast(newValueOf(limit), Type.STRING) + ) + ) + ), + new NOP() + ) + ); + + collection_cc.free_anonymous_variables(); + + anonymous_variables.release(index); + anonymous_variables.release(limit); + anonymous_variables.release(elem); + anonymous_variables.release(found); + anonymous_variables.release(next); } @Override @@ -572,7 +1274,11 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + /* + * Fate: (sequence_call <string>) + * Wyrd: (sequence_call <string>) + */ + result.add(new SequenceCall(n.get_sequence_name())); } @Override @@ -582,6 +1288,27 @@ public class InstructionCompiler extends FateVisitor ) throws Throwable { - throw new UnhandledASTElementException(); + /* + * Fate: (set_value ref value) + * Wyrd: (set_value ref value) + */ + final ComputationCompiler value_cc, ref_cc; + + value_cc = new_computation_compiler(); + ref_cc = new_computation_compiler(); + + n.get_value().visit(value_cc); + result.addAll(value_cc.get_pre_instructions()); + + n.get_reference().visit(ref_cc); + result.addAll(ref_cc.get_pre_instructions()); + + result.add + ( + new SetValue(ref_cc.get_computation(), value_cc.get_computation()) + ); + + element_cc.free_anonymous_variables(); + ref_cc.free_anonymous_variables(); } } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/SequenceCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/SequenceCompiler.java index d5fd3e2..242ec7e 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/SequenceCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/SequenceCompiler.java @@ -1,9 +1,13 @@ package tonkadur.wyrd.v1.compiler.fate.v1; +import java.util.List; + import tonkadur.error.Error; import tonkadur.wyrd.v1.lang.Sequence; +import tonkadur.wyrd.v1.lang.meta.Instruction; + import tonkadur.wyrd.v1.lang.World; public class SequenceCompiler 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 b77824f..e51e581 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 @@ -1,5 +1,8 @@ package tonkadur.wyrd.v1.compiler.fate.v1; +import java.util.HashMap; +import java.util.Map; + import tonkadur.error.Error; import tonkadur.wyrd.v1.lang.type.*; @@ -46,27 +49,27 @@ public class TypeCompiler fate_type = fate_type.get_base_type(); - if (fate_type.equals(tonkadur.fate.v1.lang.type.BOOLEAN)) + if (fate_type.equals(tonkadur.fate.v1.lang.type.Type.BOOLEAN)) { return Type.BOOLEAN; } - if (fate_type.equals(tonkadur.fate.v1.lang.type.FLOAT)) + if (fate_type.equals(tonkadur.fate.v1.lang.type.Type.FLOAT)) { return Type.FLOAT; } - if (fate_type.equals(tonkadur.fate.v1.lang.type.INT)) + if (fate_type.equals(tonkadur.fate.v1.lang.type.Type.INT)) { return Type.INT; } - if (fate_type.equals(tonkadur.fate.v1.lang.type.RICH_TEXT)) + if (fate_type.equals(tonkadur.fate.v1.lang.type.Type.RICH_TEXT)) { return Type.RICH_TEXT; } - if (fate_type.equals(tonkadur.fate.v1.lang.type.STRING)) + if (fate_type.equals(tonkadur.fate.v1.lang.type.Type.STRING)) { return Type.STRING; } @@ -122,22 +125,22 @@ public class TypeCompiler fate_content_type = fate_collection_type.get_content_type().get_base_type(); - if (fate_content_type.equals(tonkadur.fate.v1.lang.type.BOOLEAN)) + if (fate_content_type.equals(tonkadur.fate.v1.lang.type.Type.BOOLEAN)) { return MapType.MAP_TO_BOOLEAN; } - if (fate_content_type.equals(tonkadur.fate.v1.lang.type.FLOAT)) + if (fate_content_type.equals(tonkadur.fate.v1.lang.type.Type.FLOAT)) { return MapType.MAP_TO_FLOAT; } - if (fate_content_type.equals(tonkadur.fate.v1.lang.type.INT)) + if (fate_content_type.equals(tonkadur.fate.v1.lang.type.Type.INT)) { return MapType.MAP_TO_INT; } - if (fate_content_type.equals(tonkadur.fate.v1.lang.type.STRING)) + if (fate_content_type.equals(tonkadur.fate.v1.lang.type.Type.STRING)) { return MapType.MAP_TO_STRING; } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/VariableCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/VariableCompiler.java index 6078d54..832827f 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/VariableCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/VariableCompiler.java @@ -32,7 +32,7 @@ public class VariableCompiler ( fate_variable.get_name(), fate_variable.get_scope().toString(), - TypeCompiler.compile(fate_variable.get_type()) + TypeCompiler.compile(fate_variable.get_type(), wyrd_world) ); wyrd_world.add_variable(result); diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java index 14719c2..bedf5e1 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java @@ -7,9 +7,16 @@ import java.util.ArrayList; import tonkadur.functional.Cons; -import tonkadur.wyrd.v1.lang.Type; 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 AnonymousVariableManager { protected static final String name_prefix = ".anon."; @@ -46,7 +53,7 @@ public class AnonymousVariableManager { result = entry.get_cdr().get_ref(); - entry.set_cdr(Boolean.TRUE); + entry.set_car(Boolean.TRUE); return result; } @@ -67,9 +74,19 @@ public class AnonymousVariableManager public void release (final Ref r) { + final Computation c; final String name; - name = r.get_accesses().get(0).get_as_string(); + c = r.get_accesses().get(0); + + if (!(c instanceof Constant)) + { + /* TODO: error */ + + return; + } + + name = ((Constant) c).get_as_string(); by_name.get(name).set_car(Boolean.FALSE); } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java index 6c731b9..8e2f926 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java @@ -6,10 +6,14 @@ import java.util.Collections; import tonkadur.wyrd.v1.lang.type.Type; +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.Size; import tonkadur.wyrd.v1.lang.computation.ValueOf; import tonkadur.wyrd.v1.lang.instruction.IfElseInstruction; @@ -64,15 +68,18 @@ public class BinarySearch { final List<Instruction> result, while_body; final Ref top, bot, midval; + final Type element_type; result = new ArrayList<Instruction>(); while_body = new ArrayList<Instruction>(); + element_type = target.get_type(); + top = anonymous_variables.reserve(Type.INT); bot = anonymous_variables.reserve(Type.INT); - midval = anonymous_variables.reserve(target.get_type()); + midval = anonymous_variables.reserve(element_type); - result.add(new SetValue(result_holder, Constant.FALSE)); + result.add(new SetValue(result_was_found_holder, Constant.FALSE)); result.add ( new SetValue @@ -100,7 +107,7 @@ public class BinarySearch result_index_holder, Operation.plus ( - new ValueOf(bot) + new ValueOf(bot), new Cast ( Operation.divide @@ -109,13 +116,13 @@ public class BinarySearch ( Operation.minus ( - new ValueOf(top) + new ValueOf(top), new ValueOf(bot) - ) + ), Type.FLOAT ), - 2 - ) + new Constant(Type.FLOAT, "2.0") + ), Type.INT ) ) @@ -134,7 +141,8 @@ public class BinarySearch Collections.singletonList ( new Cast(new ValueOf(result_index_holder), Type.STRING) - ) + ), + element_type ) ) ) @@ -179,7 +187,7 @@ public class BinarySearch ), Collections.singletonList ( - new SetValue(result_holder, Constant.TRUE) + new SetValue(result_was_found_holder, Constant.TRUE) ) ) ) @@ -192,7 +200,7 @@ public class BinarySearch ( Operation.and ( - Operation.not(new ValueOf(result_holder)), + Operation.not(new ValueOf(result_was_found_holder)), Operation.less_equal_than ( new ValueOf(bot), diff --git a/src/core/src/tonkadur/wyrd/v1/lang/Variable.java b/src/core/src/tonkadur/wyrd/v1/lang/Variable.java index 25bd2e1..fee6ca4 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/Variable.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/Variable.java @@ -1,7 +1,12 @@ 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; diff --git a/src/core/src/tonkadur/wyrd/v1/lang/World.java b/src/core/src/tonkadur/wyrd/v1/lang/World.java index 08ba218..3cb0397 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/World.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/World.java @@ -22,6 +22,9 @@ public class World protected final Map<String, Sequence> sequences; protected final Map<String, DictType> dict_types; + /* This solves the issue of using other yet undefined dict types. */ + protected final List<DictType> dict_types_in_order; + protected final List<Instruction> global_instructions; public World () @@ -31,7 +34,39 @@ public class World variables = new HashMap<String, Variable>(); sequences = new HashMap<String, Sequence>(); dict_types = new HashMap<String, DictType>(); + dict_types_in_order = new ArrayList<DictType>(); global_instructions = new ArrayList<Instruction>(); } + + public DictType get_dict_type (final String name) + { + return dict_types.get(name); + } + + public void add_dict_type (final DictType dict_type) + { + dict_types.put(dict_type.get_name(), dict_type); + dict_types_in_order.add(dict_type); + } + + public Variable get_variable (final String name) + { + return variables.get(name); + } + + public void add_variable (final Variable variable) + { + variables.put(variable.get_name(), variable); + } + + public Sequence get_sequence (final String name) + { + return sequences.get(name); + } + + public void add_sequence (final Sequence sequence) + { + sequences.put(sequence.get_name(), sequence); + } } diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/New.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/New.java new file mode 100644 index 0000000..e7b3ba1 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/New.java @@ -0,0 +1,32 @@ +package tonkadur.wyrd.v1.lang.computation; + +import java.util.List; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.meta.Computation; + +public class New extends Computation +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Type target_type; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public New (final Type target_type) + { + super(Type.POINTER); + + this.target_type = target_type; + } + + /**** Accessors ************************************************************/ + public Type get_target_type () + { + return target_type; + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/Operation.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/Operation.java index a680188..6d6f6d6 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/computation/Operation.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/Operation.java @@ -13,7 +13,7 @@ public class Operation extends Computation public static final String MINUS = "minus"; public static final String PLUS = "plus"; public static final String POWER = "power"; - public static final String RANDOM = "rand"; + public static final String RAND = "rand"; public static final String TIMES = "times"; /* Logic operations ********************************************************/ diff --git a/src/core/src/tonkadur/wyrd/v1/lang/instruction/IfElseInstruction.java b/src/core/src/tonkadur/wyrd/v1/lang/instruction/IfElseInstruction.java index 3ea99f3..800eded 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/instruction/IfElseInstruction.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/IfElseInstruction.java @@ -1,4 +1,4 @@ -package tonkadur.wyrd.v1.lang.computation; +package tonkadur.wyrd.v1.lang.instruction; import java.util.List; 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 6fb5e33..f6c3aaf 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/Remove.java @@ -1,34 +1,26 @@ -package tonkadur.wyrd.v1.lang.computation; +package tonkadur.wyrd.v1.lang.instruction; import tonkadur.wyrd.v1.lang.computation.Ref; import tonkadur.wyrd.v1.lang.meta.Instruction; -import tonkadur.wyrd.v1.lang.meta.Computation; public class Remove extends Instruction { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ - protected final Computation index; protected final Ref reference; /***************************************************************************/ /**** PUBLIC ***************************************************************/ /***************************************************************************/ /**** Constructors *********************************************************/ - public Remove (final Computation index, final Ref reference) + public Remove (final Ref reference) { - this.index = index; this.reference = reference; } /**** Accessors ************************************************************/ - public Computation get_index () - { - return index; - } - public Ref get_reference () { return reference; diff --git a/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java b/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java index af6dc77..783be4c 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/SetValue.java @@ -1,4 +1,4 @@ -package tonkadur.wyrd.v1.lang.computation; +package tonkadur.wyrd.v1.lang.instruction; import tonkadur.wyrd.v1.lang.computation.Ref; |


