From f04286b4df82517e79ef3c9844f60293eccd2323 Mon Sep 17 00:00:00 2001 From: Maurits van Riezen <12109031+mousetail@users.noreply.github.com> Date: Tue, 18 Jun 2024 10:17:52 +0200 Subject: [PATCH] Using `g` with negative indicies should return zero, not clamp See https://tio.run/##S8sszvj/38BQF4jS86z//wcA --- src/scripts/interpreter.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/scripts/interpreter.ts b/src/scripts/interpreter.ts index 235f2ec..dfb338a 100644 --- a/src/scripts/interpreter.ts +++ b/src/scripts/interpreter.ts @@ -224,14 +224,8 @@ const commands: {[k: string]: (o: ProgramState) => void} = { }, 'g': (o) => { let [y, x] = [o.number_implementation.toIndex(pop(o)), o.number_implementation.toIndex(pop(o))]; - if (x < 0) { - x = 0; - } - if (y < 0) { - y = 0; - } - - if (y < o.program.length && x < o.program[y].length) { + + if (x >= 0 && y >= 0 && y < o.program.length && x < o.program[y].length) { push( o, o.program[y][x] @@ -307,4 +301,4 @@ export function step(o: AnyTypeProgramState) { } else { _step(o) } -} \ No newline at end of file +}