summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/SizeOperator.java97
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/meta/ComputationVisitor.java3
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/type/Type.java2
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateLexer.g416
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateParser.g4118
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java17
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java61
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/MacroManager.java7
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java28
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/CountOccurrences.java11
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/InsertAt.java6
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAllOf.java88
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/ReverseList.java16
13 files changed, 370 insertions, 100 deletions
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/SizeOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/SizeOperator.java
new file mode 100644
index 0000000..9882b31
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/SizeOperator.java
@@ -0,0 +1,97 @@
+package tonkadur.fate.v1.lang.computation;
+
+import tonkadur.error.ErrorManager;
+
+import tonkadur.parser.Origin;
+
+import tonkadur.fate.v1.error.InvalidTypeException;
+
+import tonkadur.fate.v1.lang.type.CollectionType;
+import tonkadur.fate.v1.lang.type.Type;
+
+import tonkadur.fate.v1.lang.meta.ComputationVisitor;
+import tonkadur.fate.v1.lang.meta.Computation;
+
+public class SizeOperator extends Computation
+{
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final Computation collection;
+
+ /***************************************************************************/
+ /**** PROTECTED ************************************************************/
+ /***************************************************************************/
+ /**** Constructors *********************************************************/
+ protected SizeOperator
+ (
+ final Origin origin,
+ final Computation collection
+ )
+ {
+ super(origin, Type.INT);
+
+ this.collection = collection;
+ }
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+ /**** Constructors *********************************************************/
+ public static SizeOperator build
+ (
+ final Origin origin,
+ final Computation collection
+ )
+ throws InvalidTypeException
+ {
+
+ if (!(collection.get_type() instanceof CollectionType))
+ {
+ ErrorManager.handle
+ (
+ new InvalidTypeException
+ (
+ collection.get_origin(),
+ collection.get_type(),
+ Type.COLLECTION_TYPES
+ )
+ );
+ }
+
+ return new SizeOperator(origin, collection);
+ }
+
+ /**** Accessors ************************************************************/
+ @Override
+ public void get_visited_by (final ComputationVisitor cv)
+ throws Throwable
+ {
+ cv.visit_size_operator(this);
+ }
+
+ public Computation get_collection ()
+ {
+ return collection;
+ }
+
+ /**** Misc. ****************************************************************/
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb = new StringBuilder();
+
+ sb.append(origin.toString());
+ sb.append("(SizeOperator");
+ sb.append(System.lineSeparator());
+ sb.append(System.lineSeparator());
+
+ sb.append("collection:");
+ sb.append(System.lineSeparator());
+ sb.append(collection.toString());
+
+ sb.append(")");
+
+ return sb.toString();
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/ComputationVisitor.java b/src/core/src/tonkadur/fate/v1/lang/meta/ComputationVisitor.java
index 203289e..d2c4ff0 100644
--- a/src/core/src/tonkadur/fate/v1/lang/meta/ComputationVisitor.java
+++ b/src/core/src/tonkadur/fate/v1/lang/meta/ComputationVisitor.java
@@ -40,6 +40,9 @@ public interface ComputationVisitor
public void visit_index_of_operator (final IndexOfOperator n)
throws Throwable;
+ public void visit_size_operator (final SizeOperator n)
+ throws Throwable;
+
public void visit_macro_value_call (final MacroValueCall n)
throws Throwable;
diff --git a/src/core/src/tonkadur/fate/v1/lang/type/Type.java b/src/core/src/tonkadur/fate/v1/lang/type/Type.java
index 71bf900..f848047 100644
--- a/src/core/src/tonkadur/fate/v1/lang/type/Type.java
+++ b/src/core/src/tonkadur/fate/v1/lang/type/Type.java
@@ -52,7 +52,7 @@ public class Type extends DeclaredEntity
INT = new Type(base, null, "int");
LIST = new Type(base, null, "list");
REF = new Type(base, null, "ref");
- RICH_TEXT = new Type(base, null, "rich text");
+ RICH_TEXT = new Type(base, null, "text");
SET = new Type(base, null, "set");
STRING = new Type(base, null, "string");
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
index 2759c92..2690cdf 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
@@ -16,7 +16,7 @@ R_PAREN: ')';
ABS_KW: L_PAREN 'abs'('olute'?) SEP+;
ACCESS_KW: L_PAREN 'access' SEP+;
-ADD_KW: L_PAREN 'add' SEP+;
+ADD_KW: L_PAREN 'add'(US'element')? SEP+;
AND_KW: L_PAREN ('and'|'/\\') SEP+;
ASSERT_KW: L_PAREN 'assert' SEP+;
AT_KW: L_PAREN 'at' SEP+;
@@ -27,10 +27,10 @@ COND_KW: L_PAREN 'cond' SEP+;
COUNT_KW: L_PAREN 'count' SEP+;
DECLARE_ALIAS_TYPE_KW:
L_PAREN ((('declare'|'define'|'def')US('sub'US)?'type')|'typedef') SEP+;
-DECLARE_DICT_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'dict'(US'type')? SEP+;
+DECLARE_DICT_TYPE_KW: L_PAREN ('declare'|'define'|'def')US('dict'|'struct')(US'type')? SEP+;
DECLARE_EVENT_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'event'(US'type')? SEP+;
DECLARE_LIST_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'list'(US'type')? SEP+;
-DECLARE_REF_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'ref'(US'type')? SEP+;
+DECLARE_REF_TYPE_KW: L_PAREN ('declare'|'define'|'def')US(('ref'('erence'?))|'ptr'|'pointer')(US'type')? SEP+;
DECLARE_SET_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'set'(US'type')? SEP+;
DECLARE_TEXT_EFFECT_KW: L_PAREN ('declare'|'define'|'def')US'text'US'effect' SEP+;
DECLARE_VARIABLE_KW: L_PAREN ('declare'|'define'|'def')US'var'('iable')? SEP+;
@@ -71,22 +71,26 @@ MODULO_KW: L_PAREN ('modulo'|'%'|'mod') SEP+;
NEWLINE_KW: L_PAREN 'newline)';
NEW_KW: L_PAREN ('new'|'reserve'|'create') SEP+;
NOT_KW: L_PAREN ('not'|'~'|'!') SEP+;
-ONE_IN_KW: L_PAREN 'one'US'in' SEP+;
+ONE_IN_KW: L_PAREN ('exactly'US)?'one'(US'in')? SEP+;
OR_KW: L_PAREN ('or'|'\\/') SEP+;
+RICH_TEXT_KW: L_PAREN (('rich'US)?'text') SEP+;
PARAMETER_KW: L_PAREN ('param'|'parameter'|'par') SEP+;
PLAYER_CHOICE_KW: L_PAREN ('choice'|'user'US'choice'|'player'US'choice') SEP+;
PLUS_KW: L_PAREN ('plus'|'+') SEP+;
POWER_KW: L_PAREN ('power'|'^'|'**'|'pow') SEP+;
RANDOM_KW: L_PAREN ('random'|'rand'|'rnd') SEP+;
-REF_KW: L_PAREN 'ref' SEP+;
+REF_KW: L_PAREN (('ref'('erence'?))|'ptr') SEP+;
REMOVE_ALL_KW: L_PAREN 'remove'US'all' SEP+;
+REVERSE_KW: L_PAREN 'reverse'(US'list')? SEP+;
REMOVE_ONE_KW: L_PAREN 'remove'US'one' SEP+;
-REMOVE_AT_KW: L_PAREN ('remove'US'at'|'rm'|'del'|'delete') SEP+;
+REMOVE_AT_KW: L_PAREN ('remove'US('elem'('ent')?US)?'at'|'rm'|'del'|'delete') SEP+;
REQUIRE_EXTENSION_KW: L_PAREN 'require'US'extension' SEP+;
REQUIRE_KW: L_PAREN 'require' SEP+;
SEQUENCE_KW: L_PAREN 'seq'('uence')? SEP+;
SET_FIELDS_KW: L_PAREN 'set'US'fields' SEP+;
SET_KW: L_PAREN 'set' SEP+;
+LIST_KW: L_PAREN 'list' SEP+;
+SIZE_KW: L_PAREN 'size' SEP+;
SWITCH_KW: L_PAREN 'switch' SEP+;
TIMES_KW: L_PAREN ('times'|'*') SEP+;
TRUE_KW: L_PAREN 'true)';
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
index ecf0c0d..22915e8 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
@@ -675,6 +675,20 @@ returns [Instruction result]
);
}
+ | REVERSE_KW value_reference WS* R_PAREN
+ {
+ $result =
+ ReverseList.build
+ (
+ CONTEXT.get_origin_at
+ (
+ ($REVERSE_KW.getLine()),
+ ($REVERSE_KW.getCharPositionInLine())
+ ),
+ ($value_reference.result)
+ );
+ }
+
| SET_KW value_reference WS+ value WS* R_PAREN
{
$result =
@@ -1333,7 +1347,7 @@ text
returns [RichTextNode result]:
sentence
{
- $result = ($sentence.result);
+ $result = ValueToRichText.build(($sentence.result));
}
| ENABLE_TEXT_EFFECT_KW WORD WS+ paragraph WS* R_PAREN
@@ -1431,7 +1445,7 @@ catch [final Throwable e]
}
sentence
-returns [RichTextNode result]
+returns [Computation result]
@init
{
final StringBuilder string_builder = new StringBuilder();
@@ -1451,17 +1465,14 @@ returns [RichTextNode result]
)*
{
$result =
- ValueToRichText.build
+ Constant.build_string
(
- Constant.build_string
+ CONTEXT.get_origin_at
(
- CONTEXT.get_origin_at
- (
- ($first_word.getLine()),
- ($first_word.getCharPositionInLine())
- ),
- string_builder.toString()
- )
+ ($first_word.getLine()),
+ ($first_word.getCharPositionInLine())
+ ),
+ string_builder.toString()
);
}
;
@@ -1493,6 +1504,68 @@ returns [Type result]
($WORD.text)
);
}
+
+ | REF_KW type WS* R_PAREN
+ {
+ final Origin start_origin;
+
+ start_origin =
+ CONTEXT.get_origin_at
+ (
+ ($REF_KW.getLine()),
+ ($REF_KW.getCharPositionInLine())
+ );
+
+ $result =
+ new RefType
+ (
+ start_origin,
+ ($type.result),
+ ("anonymous (" + ($type.result).get_name() + ") ref type")
+ );
+ }
+
+ | SET_KW type WS* R_PAREN
+ {
+ final Origin start_origin;
+
+ start_origin =
+ CONTEXT.get_origin_at
+ (
+ ($SET_KW.getLine()),
+ ($SET_KW.getCharPositionInLine())
+ );
+
+ $result =
+ CollectionType.build
+ (
+ start_origin,
+ ($type.result),
+ true,
+ ("anonymous (" + ($type.result).get_name() + ") set type")
+ );
+ }
+
+ | LIST_KW type WS* R_PAREN
+ {
+ final Origin start_origin;
+
+ start_origin =
+ CONTEXT.get_origin_at
+ (
+ ($LIST_KW.getLine()),
+ ($LIST_KW.getCharPositionInLine())
+ );
+
+ $result =
+ CollectionType.build
+ (
+ start_origin,
+ ($type.result),
+ false,
+ ("anonymous (" + ($type.result).get_name() + ") list type")
+ );
+ }
;
catch [final Throwable e]
{
@@ -1849,6 +1922,20 @@ returns [Computation result]:
);
}
+ | SIZE_KW value_reference WS* R_PAREN
+ {
+ $result =
+ SizeOperator.build
+ (
+ CONTEXT.get_origin_at
+ (
+ ($SIZE_KW.getLine()),
+ ($SIZE_KW.getCharPositionInLine())
+ ),
+ ($value_reference.result)
+ );
+ }
+
| NEW_KW WORD WS* R_PAREN
{
final Origin origin;
@@ -2097,7 +2184,12 @@ returns [Computation result]
/* TODO: temporarily disable an compiler error category */
}
- | L_PAREN WS+ paragraph WS* R_PAREN
+ | L_PAREN WS+ sentence WS* R_PAREN
+ {
+ $result = ($sentence.result);
+ }
+
+ | RICH_TEXT_KW paragraph WS* R_PAREN
{
$result = ($paragraph.result);
}
@@ -2403,7 +2495,7 @@ returns [Reference result]
);
}
- | ACCESS_KW value_reference value R_PAREN
+ | ACCESS_KW value_reference WS+ value R_PAREN
{
$result =
Access.build
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 c9740f8..ae89702 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
@@ -1102,6 +1102,23 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
System.err.println("[P] Unknown Fate operator '" + fate_op_name+ "'.");
}
}
+ @Override
+ public void visit_size_operator
+ (
+ final tonkadur.fate.v1.lang.computation.SizeOperator n
+ )
+ throws Throwable
+ {
+ final ComputationCompiler cc;
+
+ cc = new ComputationCompiler(compiler);
+
+ n.get_collection().get_visited_by(cc);
+
+ result_as_computation = new Size(cc.get_ref());
+
+ cc.release_variables();
+ }
@Override
public void visit_index_of_operator
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 d05a280..3ae8a3a 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
@@ -767,6 +767,17 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
final Computation value_of_index;
final Type member_type;
+ /*
+ * (declare_variable int index)
+ * (declare_variable int collection_size)
+ *
+ * (set index 0)
+ * (set collection_size (size collection))
+ *
+ * (declare_variable <E> current_value)
+ * <add_wild_parameter current_value>
+ * ...
+ */
cc = new ComputationCompiler(compiler);
new_body = new ArrayList<Instruction>();
@@ -801,20 +812,6 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
current_value
);
- for
- (
- final tonkadur.fate.v1.lang.meta.Instruction fate_instr: n.get_body()
- )
- {
- final InstructionCompiler ic;
-
- ic = new InstructionCompiler(compiler);
-
- fate_instr.get_visited_by(ic);
-
- new_body.add(ic.get_result());
- }
-
new_body.add
(
new SetValue
@@ -832,6 +829,20 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
)
);
+ for
+ (
+ final tonkadur.fate.v1.lang.meta.Instruction fate_instr: n.get_body()
+ )
+ {
+ final InstructionCompiler ic;
+
+ ic = new InstructionCompiler(compiler);
+
+ fate_instr.get_visited_by(ic);
+
+ new_body.add(ic.get_result());
+ }
+
new_body.add
(
new SetValue(index, Operation.plus(Constant.ONE, value_of_index))
@@ -1414,16 +1425,17 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
elem_cc = new ComputationCompiler(compiler);
collection_cc = new ComputationCompiler(compiler);
+ collection_size = compiler.anonymous_variables().reserve(Type.INT);
+
+ n.get_element().get_visited_by(elem_cc);
+ n.get_collection().get_visited_by(collection_cc);
+
elem =
compiler.anonymous_variables().reserve
(
elem_cc.get_computation().get_type()
);
- collection_size = compiler.anonymous_variables().reserve(Type.INT);
-
- n.get_element().get_visited_by(elem_cc);
- n.get_collection().get_visited_by(collection_cc);
if (elem_cc.has_init())
{
@@ -1567,12 +1579,6 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
elem_cc = new ComputationCompiler(compiler);
collection_cc = new ComputationCompiler(compiler);
- 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);
@@ -1580,6 +1586,13 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
n.get_element().get_visited_by(elem_cc);
n.get_collection().get_visited_by(collection_cc);
+ elem =
+ compiler.anonymous_variables().reserve
+ (
+ elem_cc.get_computation().get_type()
+ );
+
+
if (elem_cc.has_init())
{
result.add(elem_cc.get_init());
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/MacroManager.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/MacroManager.java
index fe2ab67..436c221 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/MacroManager.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/MacroManager.java
@@ -27,6 +27,8 @@ public class MacroManager
return;
}
+
+ wild_parameters.put(name, ref);
}
public void remove_wild_parameter (final String name)
@@ -74,7 +76,10 @@ public class MacroManager
if (result == null)
{
- result = context_stack.peek().get(parameter);
+ if (!context_stack.isEmpty())
+ {
+ result = context_stack.peek().get(parameter);
+ }
if (result == null)
{
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 f2c8572..741b4e9 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/BinarySearch.java
@@ -37,6 +37,7 @@ public class BinarySearch
* (declare_variable <E> .midval)
*
* (set result_found false)
+ * (set result_index 0)
* (set .bot 0)
* (set .top (- collection_size 1))
*
@@ -104,6 +105,7 @@ public class BinarySearch
value_of_top = new ValueOf(top);
value_of_midval = new ValueOf(midval);
+ result.add(new SetValue(result_index, Constant.ZERO));
result.add(new SetValue(result_was_found, Constant.FALSE));
result.add(new SetValue(bot, Constant.ZERO));
result.add
@@ -230,6 +232,32 @@ public class BinarySearch
)
);
+ /* Without this, you'll replace the value and move it to the right,
+ * regardless of where you 'target' stands in relation to it.
+ */
+ result.add
+ (
+ If.generate
+ (
+ anonymous_variables,
+ assembler,
+ Operation.and
+ (
+ Operation.and
+ (
+ Operation.not(new ValueOf(result_was_found)),
+ Operation.greater_than(target, value_of_midval)
+ ),
+ Operation.greater_than(collection_size, Constant.ZERO)
+ ),
+ new SetValue
+ (
+ result_index,
+ Operation.plus(value_of_result_index, Constant.ONE)
+ )
+ )
+ );
+
anonymous_variables.release(bot);
anonymous_variables.release(top);
anonymous_variables.release(midval);
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/CountOccurrences.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/CountOccurrences.java
index 5987c61..a6e817a 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/CountOccurrences.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/CountOccurrences.java
@@ -70,7 +70,10 @@ public class CountOccurrences
result.add(new SetValue(count, Constant.ZERO));
result.add(new SetValue(index, collection_size));
- while_body.add(new SetValue(index, Operation.minus(index, Constant.ONE)));
+ while_body.add
+ (
+ new SetValue(index, Operation.minus(value_of_index, Constant.ONE))
+ );
while_body.add
(
If.generate
@@ -90,7 +93,11 @@ public class CountOccurrences
),
target
),
- new SetValue(count, Operation.plus(count, Constant.ONE))
+ new SetValue
+ (
+ count,
+ Operation.plus(new ValueOf(count), Constant.ONE)
+ )
)
);
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/InsertAt.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/InsertAt.java
index 48debc0..c634685 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/InsertAt.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/InsertAt.java
@@ -35,7 +35,7 @@ public class InsertAt
* (set .end collection_size)
*
* <while
- * (> .index .end)
+ * (< .index .end)
*
* (set .prev (- (val .collection_size) 1))
* (set collection[.end] (val collection[.prev]))
@@ -107,7 +107,7 @@ public class InsertAt
while_body.add(new SetValue(end, value_of_prev));
/*
- * (while (> .index .end)
+ * (while (< .index .end)
* (set .prev (- (val .collection_size) 1))
* (set collection[.end] (val collection[.prev]))
* (set .end (val .prev))
@@ -119,7 +119,7 @@ public class InsertAt
(
anonymous_variables,
assembler,
- Operation.greater_than(value_of_index, value_of_end),
+ Operation.less_than(value_of_index, value_of_end),
assembler.merge(while_body)
)
);
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAllOf.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAllOf.java
index bd30ff1..23bea3a 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAllOf.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/RemoveAllOf.java
@@ -39,18 +39,18 @@ public class RemoveAllOf
*
* <while (< (var .index) (var .end))
* ;; while_body0
+ * <if (= element (var collection[.index]))
+ * ;; if_body
+ * (set .found (+ (var .found) 1))
+ * (set .end (- (var .end) 1))
+ * >
* <if (> (var .found) 0)
- * <if (= element (var collection[.index]))
- * ;; if_false_true_body
- * (set .found (+ (var .found) 1))
- * (set .end (- (var .end) 1))
- * >
- * (set
- * collection[.index]
- * (var collection[(+ (var .index) (var .found))])
- * )
+ * (set
+ * collection[.index]
+ * (var collection[(+ (var .index) (var .found))])
+ * )
* >
- * (set index ((val .index) + 1))
+ * (set index (+ (val .index) 1))
* )
*
* (while (> (var .found) 0)
@@ -69,8 +69,7 @@ public class RemoveAllOf
)
{
final List<Instruction> result;
- final List<Instruction> while_body0, while_body1, if_false_body;
- final List<Instruction> if_false_true_body;
+ final List<Instruction> while_body0, while_body1, if_body;
final Type element_type;
final Ref index, found, end;
final Computation value_of_index, value_of_found, value_of_end;
@@ -81,8 +80,7 @@ public class RemoveAllOf
while_body0 = new ArrayList<Instruction>();
while_body1 = new ArrayList<Instruction>();
- if_false_body = new ArrayList<Instruction>();
- if_false_true_body = new ArrayList<Instruction>();
+ if_body = new ArrayList<Instruction>();
element_type = element.get_type();
@@ -122,50 +120,35 @@ public class RemoveAllOf
* (set .end (- (var .end) 1))
* )
*/
- if_false_true_body.add
+ if_body.add
(
new SetValue(found, Operation.plus(value_of_found, Constant.ONE))
);
- if_false_true_body.add
+ if_body.add
(
- new SetValue(found, Operation.minus(value_of_found, Constant.ONE))
+ new SetValue(end, Operation.minus(value_of_end, Constant.ONE))
);
- if_false_body.add
+ while_body0.add
(
+ /* <if (= element (var collection[.index])) */
If.generate
(
anonymous_variables,
assembler,
Operation.equals(element, new ValueOf(collection_at_index)),
- assembler.merge(if_false_true_body)
+ assembler.merge(if_body)
)
);
/*
- * (set
- * collection[.index]
- * (var collection[(+ (var .index) (var .found))])
- * )
+ * <if (> (var .found) 0)
+ * (set
+ * collection[.index]
+ * (var collection[(+ (var .index) (var .found))])
+ * )
+ * >
*/
- if_false_body.add
- (
- new SetValue
- (
- collection_at_index,
- new RelativeRef
- (
- collection,
- new Cast
- (
- Operation.plus(value_of_index, value_of_found),
- Type.STRING
- ),
- element_type
- )
- )
- );
-
while_body0.add
(
If.generate
@@ -173,10 +156,27 @@ public class RemoveAllOf
anonymous_variables,
assembler,
value_of_found_greater_than_0,
- assembler.merge(if_false_body)
+ new SetValue
+ (
+ collection_at_index,
+ new ValueOf
+ (
+ new RelativeRef
+ (
+ collection,
+ new Cast
+ (
+ Operation.plus(value_of_index, value_of_found),
+ Type.STRING
+ ),
+ element_type
+ )
+ )
+ )
)
);
+ /* (set index (+ (val .index) 1)) */
while_body0.add
(
new SetValue(index, Operation.plus(value_of_index, Constant.ONE))
@@ -188,11 +188,13 @@ public class RemoveAllOf
(
anonymous_variables,
assembler,
+ /* <while (< (var .index) (var .end)) */
Operation.less_than(value_of_index, value_of_end),
assembler.merge(while_body0)
)
);
+ /* (remove collection[(+ (var .end) (var .found))]) */
while_body1.add
(
new Remove
@@ -209,6 +211,7 @@ public class RemoveAllOf
)
)
);
+ /* (set .found (- (var .found) 1)) */
while_body1.add
(
new SetValue(found, Operation.minus(value_of_found, Constant.ONE))
@@ -220,6 +223,7 @@ public class RemoveAllOf
(
anonymous_variables,
assembler,
+ /* (while (> (var .found) 0) */
value_of_found_greater_than_0,
assembler.merge(while_body1)
)
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/ReverseList.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/ReverseList.java
index 226e86a..a393fc8 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/ReverseList.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/ReverseList.java
@@ -39,8 +39,8 @@ public class ReverseList
* (set .buffer collection[.top])
* (set collection[.top] collection[.bot])
* (set collection[.bot] .buffer)
- * (set .bot (+ 1 (var .bot)))
- * (set .top (- 1 (var .top)))
+ * (set .bot (+ (var .bot) 1))
+ * (set .top (- (var .top) 1))
* )
*/
public static Instruction generate
@@ -111,16 +111,16 @@ public class ReverseList
new SetValue(collection_at_bot, new ValueOf(buffer))
);
- /* (set .bot (+ 1 (var .bot))) */
+ /* (set .bot (+ (var .bot) 1)) */
while_body.add
(
- new SetValue(bot, Operation.plus(Constant.ONE, value_of_bot))
+ new SetValue(bot, Operation.plus(value_of_bot, Constant.ONE))
);
- /* (set .top (- 1 (var .top))) */
+ /* (set .top (- (var .top) 1)) */
while_body.add
(
- new SetValue(top, Operation.minus(Constant.ONE, value_of_top))
+ new SetValue(top, Operation.minus(value_of_top, Constant.ONE))
);
/*
@@ -128,8 +128,8 @@ public class ReverseList
* (set .buffer collection[.top])
* (set collection[.top] collection[.bot])
* (set collection[.bot] .buffer)
- * (set .bot (+ 1 (var .bot)))
- * (set .top (- 1 (var .top)))
+ * (set .bot (+ (var .bot) 1))
+ * (set .top (- (var .top) 1))
* )
*/
result.add