From 2f5f679d61daaa677f5185b47e0a13b5eea8833f Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Tue, 14 Feb 2023 14:56:46 -0800 Subject: [PATCH] No negative shift values. --- implementations/Nim/joy.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/implementations/Nim/joy.nim b/implementations/Nim/joy.nim index 8570b98..199441a 100644 --- a/implementations/Nim/joy.nim +++ b/implementations/Nim/joy.nim @@ -519,6 +519,8 @@ proc joy_eval(sym: string, stack: JoyListType, expression: JoyListType, dictiona # > Nim Error: cannot instantiate: 'toInt[int]'; got 1 typeof(s) but expected 0 # So just convert to string and back to int, and hope for the best... let n = parseInt($a) + if n < 0: + raise newException(ValueError, "Negative shift count.") let i = b shl n return (push_int(i, s1), expression, dictionary) @@ -526,6 +528,8 @@ proc joy_eval(sym: string, stack: JoyListType, expression: JoyListType, dictiona let (a, s0) = pop_int(stack) let (b, s1) = pop_int(s0) let n = parseInt($a) + if n < 0: + raise newException(ValueError, "Negative shift count.") let i = b shr n return (push_int(i, s1), expression, dictionary)