inexorabletash / jslogo

Logo in JavaScript
https://calormen.com/jslogo
Other
368 stars 146 forks source link

forgeting space around variables silently crashes JSlogo interpreter #125

Closed mnalis closed 4 years ago

mnalis commented 4 years ago

for example, paste the code:

to toranj :d :a
make "b :d
while [ or :b > 0 :b = 0 ] [
  repeat 4 [ fd :b rt 90 ]
  pu fd :b rt 90 fd :a / 2 pd

  pr :b
  make "b :b-:a
  pr :b
  lt 90
]
end

ct cs pd pr "start  toranj 50 20 pr "end

and click Run button. Button will change to "Stop", and program will draw a square and execute everything up to and including first pr :b, but executing will then halt silently (without any error) on make "b :b-:a so second pr :b will never execute (nor will rest of loop iterations).

Button in JSLogo will continue showing Stop. When Stop button is pressed, trying to run anything else will silently fail (see issue https://github.com/inexorabletash/jslogo/issues/124). After that only way to make JSLogo start executing commands again is to refresh the browser window (F5 or ctrl-r).

If line make "b :b-:a is corrected to make "b :b - :a (spaces added around minus sign) in newly opened window, the program works just fine.

Probably JSLogo should accept that line without space (like FMS Logo does, for example), or it should show an error like it does when you try to access nonexistant variable (instead of silently crashing the interpreter as it does now).

inexorabletash commented 4 years ago

Thanks. This is probably a place where a promise rejection is getting dropped rather than propagating out (the code is pre-async/await)

inexorabletash commented 4 years ago

This was a bug in WHILE where termination wasn't handled. Thanks for the report!