Skip to content

Commit

Permalink
Change “shuffle stopping” behaviour so its stop element is always the…
Browse files Browse the repository at this point in the history
… last one, non-shuffled
  • Loading branch information
joethephish committed Jun 6, 2019
1 parent 35f1656 commit 7e52394
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions compiler/ParsedHierarchy/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ public override Runtime.Object GenerateRuntimeObject ()
// Create point to return to when sequence is complete
var postShuffleNoOp = Runtime.ControlCommand.NoOp();

// When visitIndex == seqElementCount, we skip the shuffle
if ( once )
// When visitIndex == lastIdx, we skip the shuffle
if ( once || stopping )
{
// if( visitIndex == seqElementCount ) -> skipShuffle
// if( visitIndex == lastIdx ) -> skipShuffle
int lastIdx = stopping ? sequenceElements.Count - 1 : sequenceElements.Count;
container.AddContent(Runtime.ControlCommand.Duplicate());
container.AddContent(new Runtime.IntValue(sequenceElements.Count));
container.AddContent(new Runtime.IntValue(lastIdx));
container.AddContent(Runtime.NativeFunctionCall.CallWithName("=="));

var skipShuffleDivert = new Runtime.Divert();
Expand All @@ -116,9 +117,11 @@ public override Runtime.Object GenerateRuntimeObject ()
}

// This one's a bit more complex! Choose the index at runtime.
container.AddContent (new Runtime.IntValue (sequenceElements.Count));
var elementCountToShuffle = sequenceElements.Count;
if (stopping) elementCountToShuffle--;
container.AddContent (new Runtime.IntValue (elementCountToShuffle));
container.AddContent (Runtime.ControlCommand.SequenceShuffleIndex ());
if (once) container.AddContent(postShuffleNoOp);
if (once || stopping) container.AddContent(postShuffleNoOp);
}

container.AddContent (Runtime.ControlCommand.EvalEnd ());
Expand Down
3 changes: 2 additions & 1 deletion tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ ~ SEED_RANDOM(1)
{stopping shuffle:
- one
- two
- final
}
== function f_shuffle_once ==
Expand All @@ -246,7 +247,7 @@ ~ SEED_RANDOM(1)
";

Story story = CompileString(storyStr);
Assert.AreEqual("Once: one two\nStopping: one two two two\nDefault: one two two two\nCycle: one two one two\nShuffle: two one two one\nShuffle stopping: one two two two\nShuffle once: two one\n", story.ContinueMaximally());
Assert.AreEqual("Once: one two\nStopping: one two two two\nDefault: one two two two\nCycle: one two one two\nShuffle: two one two one\nShuffle stopping: one two final final\nShuffle once: two one\n", story.ContinueMaximally());
}


Expand Down

0 comments on commit 7e52394

Please sign in to comment.