Skip to content

Commit

Permalink
Fixes can't rock with pronouns
Browse files Browse the repository at this point in the history
Fixes #359

* Evaluate all elements (e.g. pronouns) first, BEFORE allocating/assigning the array - because allocation/assignment updates the pronoun subject so `it` points to the array after it's done, and if one of the elements is a pronoun, this will create an infinite loop. Eval()ing all the elements first fixes this.
  • Loading branch information
dylanbeattie committed Dec 16, 2024
1 parent 233241f commit b04e314
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
14 changes: 6 additions & 8 deletions Starship/Rockstar.Engine/RockstarEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,14 @@ private Result Dequeue(Dequeue dequeue) {

private Result Enlist(Enlist e) {
var scope = e.Expressions.Any() ? Scope.Global : Scope.Local;
var value = Lookup(e.Variable, scope);
if (value is Strïng s) {
foreach (var expr in e.Expressions) s.Append(Eval(expr));
return new(s);
}
if (value is not Arräy array) {
array = value == Mysterious.Instance ? new Arräy() : new(value);
var target = Lookup(e.Variable, scope);
var values = e.Expressions.Select(Eval).ToArray();
if (target is Strïng s) return new(s.Append(values));
if (target is not Arräy array) {
array = target == Mysterious.Instance ? new Arräy() : new(target);
SetVariable(e.Variable, array, Scope.Local);
}
foreach (var expr in e.Expressions) array.Push(Eval(expr));
foreach (var value in values) array.Push(value);
return new(array);
}

Expand Down
5 changes: 5 additions & 0 deletions Starship/Rockstar.Engine/Values/Strïng.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public Value ToCharCodes() {
};
}

public Value Append(params Value[] values) {
foreach (var value in values) this.Append(value);
return this;
}

public Value Append(Value v) {
if (v is Numbër number) {
this.Value += (char) number.IntegerValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ for x in 3
n=0
r at i=0

print r (prints: [ 0 ])
print r (prints: [ 0 ])


foo is 1
shout it (prints: 1)
rock bar with it
shout bar (prints: [ 1 ])

0 comments on commit b04e314

Please sign in to comment.