| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-12-23 03:20:52 +0100 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-12-23 03:20:52 +0100 | 
| commit | 0269c0a2943e443179ae6261b265aa06998451f7 (patch) | |
| tree | d92372b294b02ab79bae7f74ad7da97ba5c58979 /src/core | |
| parent | 6c8463a40e8072f1e182e778726602ebd67affcf (diff) | |
Parenthesis, merge stuff, main param goes last.
Diffstat (limited to 'src/core')
6 files changed, 271 insertions, 189 deletions
| diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/IndexedMerge.java b/src/core/src/tonkadur/fate/v1/lang/instruction/IndexedMerge.java index 96cfefc..060438c 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/IndexedMerge.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/IndexedMerge.java @@ -35,10 +35,10 @@ public class IndexedMerge extends Instruction     (        final Origin origin,        final Computation lambda_function, -      final Reference collection, -      final Computation default_a,        final Computation collection_in_b,        final Computation default_b, +      final Reference collection, +      final Computation default_a,        final List<Computation> extra_params     )     { @@ -60,10 +60,10 @@ public class IndexedMerge extends Instruction     (        final Origin origin,        final Computation lambda_function, -      final Reference collection, -      final Computation default_a,        final Computation collection_in_b,        final Computation default_b, +      final Reference collection, +      final Computation default_a,        final List<Computation> extra_params     )     throws Throwable @@ -123,10 +123,10 @@ public class IndexedMerge extends Instruction           (              origin,              lambda_function, -            collection, -            default_a,              collection_in_b,              default_b, +            collection, +            default_a,              extra_params           );     } @@ -144,22 +144,22 @@ public class IndexedMerge extends Instruction        return lambda_function;     } -   public Computation get_default_a () +   public Computation get_main_default ()     {        return default_a;     } -   public Computation get_collection_in_b () +   public Computation get_secondary_collection ()     {        return collection_in_b;     } -   public Computation get_default_b () +   public Computation get_secondary_default ()     {        return default_b;     } -   public Reference get_collection () +   public Reference get_main_collection ()     {        return collection;     } diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/Merge.java b/src/core/src/tonkadur/fate/v1/lang/instruction/Merge.java index f2396a9..9a40f2f 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/Merge.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/Merge.java @@ -35,10 +35,10 @@ public class Merge extends Instruction     (        final Origin origin,        final Computation lambda_function, -      final Reference collection, -      final Computation default_a,        final Computation collection_in_b,        final Computation default_b, +      final Reference collection, +      final Computation default_a,        final List<Computation> extra_params     )     { @@ -60,10 +60,10 @@ public class Merge extends Instruction     (        final Origin origin,        final Computation lambda_function, -      final Reference collection, -      final Computation default_a,        final Computation collection_in_b,        final Computation default_b, +      final Reference collection, +      final Computation default_a,        final List<Computation> extra_params     )     throws Throwable @@ -117,10 +117,10 @@ public class Merge extends Instruction           (              origin,              lambda_function, -            collection, -            default_a,              collection_in_b,              default_b, +            collection, +            default_a,              extra_params           );     } @@ -138,22 +138,22 @@ public class Merge extends Instruction        return lambda_function;     } -   public Computation get_default_a () +   public Computation get_main_default ()     {        return default_a;     } -   public Computation get_collection_in_b () +   public Computation get_secondary_collection ()     {        return collection_in_b;     } -   public Computation get_default_b () +   public Computation get_secondary_default ()     {        return default_b;     } -   public Reference get_collection () +   public Reference get_main_collection ()     {        return collection;     } diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index 10bb692..b7b64dd 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -8,6 +8,7 @@ lexer grammar FateLexer;  fragment SEP: [ \t\r\n]+;  fragment US: '_'?; +  WS: SEP;  L_PAREN: '('; @@ -162,6 +163,9 @@ VISIT_KW: L_PAREN ('call'|'visit')(US(('seq'('uence'?))|('proc'('edure'?))))? SE  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()])|'\\)'|'\\(')+; +WORD: ((~([ \t\r\n()]))|'(lp)'|'(rp)')+ +   { +      setText(getText().replaceAll("\\(lp\\)", "(").replaceAll("\\(rp\\)", ")")); +   };  COMMENT: WS* ';' .*? '\n' -> channel(HIDDEN); diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index d16dfb2..16a9472 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -977,8 +977,8 @@ returns [Instruction result]     | IMP_MERGE_KW           fun=non_text_value WS+ -         value_reference WS+ -         inv1=non_text_value WS* +         inv1=non_text_value WS+ +         value_reference WS*        R_PAREN     {        $result = @@ -990,18 +990,18 @@ returns [Instruction result]                 ($IMP_MERGE_KW.getCharPositionInLine())              ),              ($fun.result), -            ($value_reference.result), -            null,              ($inv1.result),              null, +            ($value_reference.result), +            null,              new ArrayList()           );     }     | IMP_MERGE_KW           fun=non_text_value WS+ -         value_reference WS+           inv1=non_text_value WS+ +         value_reference WS+           value_list WS*        R_PAREN     { @@ -1014,18 +1014,18 @@ returns [Instruction result]                 ($IMP_MERGE_KW.getCharPositionInLine())              ),              ($fun.result), -            ($value_reference.result), -            null,              ($inv1.result),              null, +            ($value_reference.result), +            null,              ($value_list.result)           );     }     | IMP_INDEXED_MERGE_KW           fun=non_text_value WS+ -         value_reference WS+ -         inv1=non_text_value WS* +         inv1=non_text_value WS+ +         value_reference WS*        R_PAREN     {        $result = @@ -1037,18 +1037,18 @@ returns [Instruction result]                 ($IMP_INDEXED_MERGE_KW.getCharPositionInLine())              ),              ($fun.result), -            ($value_reference.result), -            null,              ($inv1.result),              null, +            ($value_reference.result), +            null,              new ArrayList()           );     }     | IMP_INDEXED_MERGE_KW           fun=non_text_value WS+ -         value_reference WS+           inv1=non_text_value WS+ +         value_reference WS+           value_list WS*        R_PAREN     { @@ -1061,20 +1061,20 @@ returns [Instruction result]                 ($IMP_INDEXED_MERGE_KW.getCharPositionInLine())              ),              ($fun.result), -            ($value_reference.result), -            null,              ($inv1.result),              null, +            ($value_reference.result), +            null,              ($value_list.result)           );     }     | SAFE_IMP_MERGE_KW        fun=non_text_value WS+ -      def0=value WS+ -      value_reference WS+        def1=value WS+ -      inv1=non_text_value WS* +      inv1=non_text_value WS+ +      def0=value WS+ +      value_reference WS*        R_PAREN     {        $result = @@ -1086,20 +1086,20 @@ returns [Instruction result]                 ($SAFE_IMP_MERGE_KW.getCharPositionInLine())              ),              ($fun.result), -            ($value_reference.result), -            ($def0.result),              ($inv1.result),              ($def1.result), +            ($value_reference.result), +            ($def0.result),              new ArrayList()           );     }     | SAFE_IMP_MERGE_KW        fun=non_text_value WS+ -      def0=value WS+ -      value_reference WS+        def1=value WS+        inv1=non_text_value WS+ +      def0=value WS+ +      value_reference WS+        value_list WS*        R_PAREN     { @@ -1112,20 +1112,20 @@ returns [Instruction result]                 ($SAFE_IMP_MERGE_KW.getCharPositionInLine())              ),              ($fun.result), -            ($value_reference.result), -            ($def0.result),              ($inv1.result),              ($def1.result), +            ($value_reference.result), +            ($def0.result),              ($value_list.result)           );     }     | SAFE_IMP_INDEXED_MERGE_KW        fun=non_text_value WS+ -      def0=value WS+ -      value_reference WS+        def1=value WS+ -      inv1=non_text_value WS* +      inv1=non_text_value WS+ +      def0=value WS+ +      value_reference WS*        R_PAREN     {        $result = @@ -1137,20 +1137,20 @@ returns [Instruction result]                 ($SAFE_IMP_INDEXED_MERGE_KW.getCharPositionInLine())              ),              ($fun.result), -            ($value_reference.result), -            ($def0.result),              ($inv1.result),              ($def1.result), +            ($value_reference.result), +            ($def0.result),              new ArrayList()           );     }     | SAFE_IMP_INDEXED_MERGE_KW        fun=non_text_value WS+ -      def0=value WS+ -      value_reference WS+        def1=value WS+        inv1=non_text_value WS+ +      def0=value WS+ +      value_reference WS+        value_list WS*        R_PAREN     { @@ -1163,10 +1163,10 @@ returns [Instruction result]                 ($SAFE_IMP_INDEXED_MERGE_KW.getCharPositionInLine())              ),              ($fun.result), -            ($value_reference.result), -            ($def0.result),              ($inv1.result),              ($def1.result), +            ($value_reference.result), +            ($def0.result),              ($value_list.result)           );     } @@ -3743,7 +3743,7 @@ returns [Computation result]           );     } -   | ACCESS_KW collection=non_text_value WS+ index=non_text_value WS* R_PAREN +   | ACCESS_KW index=non_text_value WS+ collection=non_text_value WS* R_PAREN     {        $result =           Access.build @@ -3758,7 +3758,7 @@ returns [Computation result]           );     } -   | ACCESS_POINTER_KW value_reference WS+ non_text_value WS* R_PAREN +   | ACCESS_POINTER_KW non_text_value WS+ value_reference WS* R_PAREN     {        $result =           AccessPointer.build @@ -3773,7 +3773,7 @@ returns [Computation result]           );     } -   | FIELD_ACCESS_KW non_text_value WS+ WORD WS* R_PAREN +   | FIELD_ACCESS_KW WORD WS+ non_text_value WS* R_PAREN     {        $result =           FieldAccess.build @@ -5115,7 +5115,7 @@ returns [Reference result]           );     } -   | FIELD_KW value_reference WS+ WORD WS* R_PAREN +   | FIELD_KW WORD WS+ value_reference WS* R_PAREN     {        $result =           FieldReference.build 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 19baae7..5986682 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 @@ -749,17 +749,18 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor     throws Throwable     {        final Register holder; -      final ComputationCompiler lambda_cc, default_a_cc, default_b_cc; +      final ComputationCompiler lambda_cc; +      final ComputationCompiler main_default_cc, secondary_default_cc;        final List<Computation> params;        final List<ComputationCompiler> param_cc_list; -      final ComputationCompiler collection_cc, in_collection_b_cc; +      final ComputationCompiler main_collection_cc, secondary_collection_cc;        params = new ArrayList<Computation>();        param_cc_list = new ArrayList<ComputationCompiler>();        lambda_cc = new ComputationCompiler(compiler); -      default_a_cc = new ComputationCompiler(compiler); -      default_b_cc = new ComputationCompiler(compiler); +      main_default_cc = new ComputationCompiler(compiler); +      secondary_default_cc = new ComputationCompiler(compiler);        n.get_lambda_function().get_visited_by(lambda_cc); @@ -768,43 +769,47 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor           result.add(lambda_cc.get_init());        } -      collection_cc = new ComputationCompiler(compiler); +      main_collection_cc = new ComputationCompiler(compiler); -      n.get_collection().get_visited_by(collection_cc); +      n.get_main_collection().get_visited_by(main_collection_cc); -      if (collection_cc.has_init()) +      if (main_collection_cc.has_init())        { -         result.add(collection_cc.get_init()); +         result.add(main_collection_cc.get_init());        } -      n.get_default_a().get_visited_by(default_a_cc); +      n.get_main_default().get_visited_by(main_default_cc); -      default_a_cc.generate_address(); +      main_default_cc.generate_address(); -      if (default_a_cc.has_init()) +      if (main_default_cc.has_init())        { -         result.add(default_a_cc.get_init()); +         result.add(main_default_cc.get_init());        } -      n.get_default_b().get_visited_by(default_b_cc); +      n.get_secondary_default().get_visited_by(secondary_default_cc); -      default_b_cc.generate_address(); +      secondary_default_cc.generate_address(); -      if (default_b_cc.has_init()) +      if (secondary_default_cc.has_init())        { -         result.add(default_b_cc.get_init()); +         result.add(secondary_default_cc.get_init());        }        holder =           compiler.registers().reserve           ( -            collection_cc.get_computation().get_type(), +            main_collection_cc.get_computation().get_type(),              result           );        result.add        ( -         new SetValue(holder.get_address(), collection_cc.get_computation()) +         new SetValue +         ( +            holder.get_address(), +            main_collection_cc.get_computation() +         )        );        result.add @@ -813,17 +818,17 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor           (              compiler.registers(),              compiler.assembler(), -            collection_cc.get_address() +            main_collection_cc.get_address()           )        ); -      in_collection_b_cc = new ComputationCompiler(compiler); +      secondary_collection_cc = new ComputationCompiler(compiler); -      n.get_collection_in_b().get_visited_by(in_collection_b_cc); +      n.get_secondary_collection().get_visited_by(secondary_collection_cc); -      if (in_collection_b_cc.has_init()) +      if (secondary_collection_cc.has_init())        { -         result.add(in_collection_b_cc.get_init()); +         result.add(secondary_collection_cc.get_init());        }        for @@ -858,23 +863,23 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor              compiler.registers(),              compiler.assembler(),              lambda_cc.get_computation(), -            default_a_cc.get_computation(), +            secondary_default_cc.get_computation(), +            secondary_collection_cc.get_address(), +            main_default_cc.get_computation(),              holder.get_address(), -            default_b_cc.get_computation(), -            in_collection_b_cc.get_address(), -            collection_cc.get_address(), +            main_collection_cc.get_address(),              (                 (tonkadur.fate.v1.lang.type.CollectionType) -               n.get_collection().get_type() +               n.get_main_collection().get_type()              ).is_set(),              params           )        ); -      collection_cc.release_registers(result); -      in_collection_b_cc.release_registers(result); -      default_a_cc.release_registers(result); -      default_b_cc.release_registers(result); +      main_collection_cc.release_registers(result); +      secondary_collection_cc.release_registers(result); +      main_default_cc.release_registers(result); +      secondary_default_cc.release_registers(result);        compiler.registers().release(holder, result);        for (final ComputationCompiler cc: param_cc_list) @@ -892,7 +897,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor     {        /* This is one dangerous operation to do in-place, so we don't. */ -      if (n.get_default_a() != null) +      if (n.get_main_default() != null)        {           visit_merge_with_defaults(n);           return; @@ -902,7 +907,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor        final ComputationCompiler lambda_cc;        final List<Computation> params;        final List<ComputationCompiler> param_cc_list; -      final ComputationCompiler collection_cc, in_collection_b_cc; +      final ComputationCompiler main_collection_cc, secondary_collection_cc;        params = new ArrayList<Computation>();        param_cc_list = new ArrayList<ComputationCompiler>(); @@ -916,25 +921,29 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor           result.add(lambda_cc.get_init());        } -      collection_cc = new ComputationCompiler(compiler); +      main_collection_cc = new ComputationCompiler(compiler); -      n.get_collection().get_visited_by(collection_cc); +      n.get_main_collection().get_visited_by(main_collection_cc); -      if (collection_cc.has_init()) +      if (main_collection_cc.has_init())        { -         result.add(collection_cc.get_init()); +         result.add(main_collection_cc.get_init());        }        holder =           compiler.registers().reserve           ( -            collection_cc.get_computation().get_type(), +            main_collection_cc.get_computation().get_type(),              result           );        result.add        ( -         new SetValue(holder.get_address(), collection_cc.get_computation()) +         new SetValue +         ( +            holder.get_address(), +            main_collection_cc.get_computation() +         )        );        result.add @@ -943,18 +952,17 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor           (              compiler.registers(),              compiler.assembler(), -            collection_cc.get_address() +            main_collection_cc.get_address()           )        ); +      secondary_collection_cc = new ComputationCompiler(compiler); -      in_collection_b_cc = new ComputationCompiler(compiler); - -      n.get_collection_in_b().get_visited_by(in_collection_b_cc); +      n.get_secondary_collection().get_visited_by(secondary_collection_cc); -      if (in_collection_b_cc.has_init()) +      if (secondary_collection_cc.has_init())        { -         result.add(in_collection_b_cc.get_init()); +         result.add(secondary_collection_cc.get_init());        }        for @@ -989,19 +997,19 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor              compiler.registers(),              compiler.assembler(),              lambda_cc.get_computation(), +            secondary_collection_cc.get_address(),              holder.get_address(), -            in_collection_b_cc.get_address(), -            collection_cc.get_address(), +            main_collection_cc.get_address(),              (                 (tonkadur.fate.v1.lang.type.CollectionType) -               n.get_collection().get_type() +               n.get_main_collection().get_type()              ).is_set(),              params           )        ); -      collection_cc.release_registers(result); -      in_collection_b_cc.release_registers(result); +      main_collection_cc.release_registers(result); +      secondary_collection_cc.release_registers(result);        compiler.registers().release(holder, result);        for (final ComputationCompiler cc: param_cc_list) @@ -1017,17 +1025,18 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor     throws Throwable     {        final Register holder; -      final ComputationCompiler lambda_cc, default_a_cc, default_b_cc; +      final ComputationCompiler lambda_cc; +      final ComputationCompiler main_default_cc, secondary_default_cc;        final List<Computation> params;        final List<ComputationCompiler> param_cc_list; -      final ComputationCompiler collection_cc, in_collection_b_cc; +      final ComputationCompiler main_collection_cc, secondary_collection_cc;        params = new ArrayList<Computation>();        param_cc_list = new ArrayList<ComputationCompiler>();        lambda_cc = new ComputationCompiler(compiler); -      default_a_cc = new ComputationCompiler(compiler); -      default_b_cc = new ComputationCompiler(compiler); +      main_default_cc = new ComputationCompiler(compiler); +      secondary_default_cc = new ComputationCompiler(compiler);        n.get_lambda_function().get_visited_by(lambda_cc); @@ -1036,43 +1045,47 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor           result.add(lambda_cc.get_init());        } -      collection_cc = new ComputationCompiler(compiler); +      main_collection_cc = new ComputationCompiler(compiler); -      n.get_collection().get_visited_by(collection_cc); +      n.get_main_collection().get_visited_by(main_collection_cc); -      if (collection_cc.has_init()) +      if (main_collection_cc.has_init())        { -         result.add(collection_cc.get_init()); +         result.add(main_collection_cc.get_init());        } -      n.get_default_a().get_visited_by(default_a_cc); +      n.get_main_default().get_visited_by(main_default_cc); -      default_a_cc.generate_address(); +      main_default_cc.generate_address(); -      if (default_a_cc.has_init()) +      if (main_default_cc.has_init())        { -         result.add(default_a_cc.get_init()); +         result.add(main_default_cc.get_init());        } -      n.get_default_b().get_visited_by(default_b_cc); +      n.get_secondary_default().get_visited_by(secondary_default_cc); -      default_b_cc.generate_address(); +      secondary_default_cc.generate_address(); -      if (default_b_cc.has_init()) +      if (secondary_default_cc.has_init())        { -         result.add(default_b_cc.get_init()); +         result.add(secondary_default_cc.get_init());        }        holder =           compiler.registers().reserve           ( -            collection_cc.get_computation().get_type(), +            main_collection_cc.get_computation().get_type(),              result           );        result.add        ( -         new SetValue(holder.get_address(), collection_cc.get_computation()) +         new SetValue +         ( +            holder.get_address(), +            main_collection_cc.get_computation() +         )        );        result.add @@ -1081,17 +1094,17 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor           (              compiler.registers(),              compiler.assembler(), -            collection_cc.get_address() +            main_collection_cc.get_address()           )        ); -      in_collection_b_cc = new ComputationCompiler(compiler); +      secondary_collection_cc = new ComputationCompiler(compiler); -      n.get_collection_in_b().get_visited_by(in_collection_b_cc); +      n.get_secondary_collection().get_visited_by(secondary_collection_cc); -      if (in_collection_b_cc.has_init()) +      if (secondary_collection_cc.has_init())        { -         result.add(in_collection_b_cc.get_init()); +         result.add(secondary_collection_cc.get_init());        }        for @@ -1126,23 +1139,23 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor              compiler.registers(),              compiler.assembler(),              lambda_cc.get_computation(), -            default_a_cc.get_computation(), +            secondary_default_cc.get_computation(), +            secondary_collection_cc.get_address(), +            main_default_cc.get_computation(),              holder.get_address(), -            default_b_cc.get_computation(), -            in_collection_b_cc.get_address(), -            collection_cc.get_address(), +            main_collection_cc.get_address(),              (                 (tonkadur.fate.v1.lang.type.CollectionType) -               n.get_collection().get_type() +               n.get_main_collection().get_type()              ).is_set(),              params           )        ); -      collection_cc.release_registers(result); -      in_collection_b_cc.release_registers(result); -      default_a_cc.release_registers(result); -      default_b_cc.release_registers(result); +      main_collection_cc.release_registers(result); +      secondary_collection_cc.release_registers(result); +      main_default_cc.release_registers(result); +      secondary_default_cc.release_registers(result);        compiler.registers().release(holder, result);        for (final ComputationCompiler cc: param_cc_list) @@ -1158,7 +1171,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor     )     throws Throwable     { -      if (n.get_default_a() != null) +      if (n.get_main_default() != null)        {           visit_indexed_merge_with_defaults(n);           return; @@ -1169,7 +1182,7 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor        final ComputationCompiler lambda_cc;        final List<Computation> params;        final List<ComputationCompiler> param_cc_list; -      final ComputationCompiler collection_cc, in_collection_b_cc; +      final ComputationCompiler main_collection_cc, secondary_collection_cc;        params = new ArrayList<Computation>();        param_cc_list = new ArrayList<ComputationCompiler>(); @@ -1183,25 +1196,29 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor           result.add(lambda_cc.get_init());        } -      collection_cc = new ComputationCompiler(compiler); +      main_collection_cc = new ComputationCompiler(compiler); -      n.get_collection().get_visited_by(collection_cc); +      n.get_main_collection().get_visited_by(main_collection_cc); -      if (collection_cc.has_init()) +      if (main_collection_cc.has_init())        { -         result.add(collection_cc.get_init()); +         result.add(main_collection_cc.get_init());        }        holder =           compiler.registers().reserve           ( -            collection_cc.get_computation().get_type(), +            main_collection_cc.get_computation().get_type(),              result           );        result.add        ( -         new SetValue(holder.get_address(), collection_cc.get_computation()) +         new SetValue +         ( +            holder.get_address(), +            main_collection_cc.get_computation() +         )        );        result.add @@ -1210,17 +1227,17 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor           (              compiler.registers(),              compiler.assembler(), -            collection_cc.get_address() +            main_collection_cc.get_address()           )        ); -      in_collection_b_cc = new ComputationCompiler(compiler); +      secondary_collection_cc = new ComputationCompiler(compiler); -      n.get_collection_in_b().get_visited_by(in_collection_b_cc); +      n.get_secondary_collection().get_visited_by(secondary_collection_cc); -      if (in_collection_b_cc.has_init()) +      if (secondary_collection_cc.has_init())        { -         result.add(in_collection_b_cc.get_init()); +         result.add(secondary_collection_cc.get_init());        }        for @@ -1255,19 +1272,19 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor              compiler.registers(),              compiler.assembler(),              lambda_cc.get_computation(), +            secondary_collection_cc.get_address(),              holder.get_address(), -            in_collection_b_cc.get_address(), -            collection_cc.get_address(), +            main_collection_cc.get_address(),              (                 (tonkadur.fate.v1.lang.type.CollectionType) -               n.get_collection().get_type() +               n.get_main_collection().get_type()              ).is_set(),              params           )        ); -      collection_cc.release_registers(result); -      in_collection_b_cc.release_registers(result); +      main_collection_cc.release_registers(result); +      secondary_collection_cc.release_registers(result);        compiler.registers().release(holder, result);        for (final ComputationCompiler cc: param_cc_list) diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/IndexedMergeLambda.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/IndexedMergeLambda.java index e1e4e4f..818fde6 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/util/IndexedMergeLambda.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/IndexedMergeLambda.java @@ -201,17 +201,22 @@ public class IndexedMergeLambda        final List<Computation> extra_params     )     { -      final List<Instruction> result, while_body; -      final Register iterator_a, iterator_b; +      final List<Instruction> result, while_body, oob_a_body, oob_b_body; +      final Register iterator_a, iterator_b, oob_a, oob_b;        final Register collection_a_size, collection_b_size;        final Register storage;        result = new ArrayList<Instruction>();        while_body = new ArrayList<Instruction>(); +      oob_a_body = new ArrayList<Instruction>(); +      oob_b_body = new ArrayList<Instruction>();        iterator_a = registers.reserve(Type.INT, result);        iterator_b = registers.reserve(Type.INT, result); +      oob_a = registers.reserve(Type.BOOL, result); +      oob_b = registers.reserve(Type.BOOL, result); +        collection_a_size = registers.reserve(Type.INT, result);        collection_b_size = registers.reserve(Type.INT, result); @@ -243,16 +248,39 @@ public class IndexedMergeLambda           )        ); -      extra_params.add +      result.add        ( -         0, -         new IfElseComputation +         new SetValue           ( -            Operation.less_than +            oob_a.get_address(), +            Operation.greater_equal_than +            ( +               iterator_a.get_value(), +               collection_a_size.get_value() +            ) +         ) +      ); + +      result.add +      ( +         new SetValue +         ( +            oob_b.get_address(), +            Operation.greater_equal_than              (                 iterator_b.get_value(),                 collection_b_size.get_value() -            ), +            ) +         ) +      ); + +      extra_params.add +      ( +         0, +         new IfElseComputation +         ( +            oob_b.get_value(), +            default_b,              new ValueOf              (                 new RelativeAddress @@ -263,8 +291,7 @@ public class IndexedMergeLambda                       (MapType) collection_in_b.get_target_type()                    ).get_member_type()                 ) -            ), -            default_b +            )           )        ); @@ -275,11 +302,8 @@ public class IndexedMergeLambda           0,           new IfElseComputation           ( -            Operation.less_than -            ( -               iterator_a.get_value(), -               collection_a_size.get_value() -            ), +            oob_a.get_value(), +            default_a,              new ValueOf              (                 new RelativeAddress @@ -290,8 +314,7 @@ public class IndexedMergeLambda                       (MapType) collection_in_a.get_target_type()                    ).get_member_type()                 ) -            ), -            default_a +            )           )        ); @@ -324,7 +347,7 @@ public class IndexedMergeLambda           )        ); -      while_body.add +      oob_a_body.add        (           new SetValue           ( @@ -333,7 +356,20 @@ public class IndexedMergeLambda           )        ); -      while_body.add +      oob_a_body.add +      ( +         new SetValue +         ( +            oob_a.get_address(), +            Operation.greater_equal_than +            ( +               iterator_a.get_value(), +               collection_a_size.get_value() +            ) +         ) +      ); + +      oob_b_body.add        (           new SetValue           ( @@ -342,31 +378,56 @@ public class IndexedMergeLambda           )        ); +      oob_b_body.add +      ( +         new SetValue +         ( +            oob_b.get_address(), +            Operation.greater_equal_than +            ( +               iterator_b.get_value(), +               collection_b_size.get_value() +            ) +         ) +      ); + +      while_body.add +      ( +         If.generate +         ( +            registers, +            assembler, +            Operation.not(oob_a.get_value()), +            assembler.merge(oob_a_body) +         ) +      ); + +      while_body.add +      ( +         If.generate +         ( +            registers, +            assembler, +            Operation.not(oob_b.get_value()), +            assembler.merge(oob_b_body) +         ) +      ); +        result.add        (           While.generate           (              registers,              assembler, -            Operation.or -            ( -               Operation.less_than -               ( -                  iterator_a.get_value(), -                  collection_a_size.get_value() -               ), -               Operation.less_than -               ( -                  iterator_b.get_value(), -                  collection_b_size.get_value() -               ) -            ), +            Operation.not(Operation.and(oob_a.get_value(), oob_b.get_value())),              assembler.merge(while_body)           )        );        registers.release(iterator_a, result);        registers.release(iterator_b, result); +      registers.release(oob_a, result); +      registers.release(oob_b, result);        registers.release(collection_a_size, result);        registers.release(collection_b_size, result);        registers.release(storage, result); | 


