Repository navigation
Description
GlowScript embeds RapydScript-NG 0.7.22. The build's rs_commit_sha is 6dc47bb, which isn't in upstream's history, so it was probably built from a fork. Upstream (kovidgoyal/rapydscript-ng) is at 0.8.7, and since then has merged:
30626e5(Bump jinja2 from 3.1.2 to 3.1.6 #193): randint fixed for negative ranges. We carry this as Fix random.randint() with negative numbers #215 /b8a6fa1.165020b: randint now raisesTypeErrorfor non-integers andValueErrorwhenb < a, as Python does.67b56d2:randrange()fixed for ranges larger than 2**31. We still have this bug.
This issue tracks refreshing to current upstream instead of patching one function at a time.
Who consumes this compiler
Three deployments, two copies:
| Site | Compiler copy | Notes |
|---|---|---|
| glowscript.org | lib/rapydscript/compiler.js + package/RScompiler.3.2.min.js here |
also GlowScriptOffline/ |
| webvpython.org | vpython/rsWVPRunner (gs://rswvprunner) |
flaskHost sends every non-wasm program to this runner |
| trinket (Web VPython 3.2.3) | the same rsWVPRunner build | sha256-pinned in trinket's Dockerfile (RSCOMPILER_SHA256, GLOWSCRIPT_PACKAGE_BUILD) |
rsWVPRunner's lib/rapydscript/compiler.js and lib/compiling/GScompiler.js are byte-identical to the copies here, so a refresh lands here first and then gets copied over. After that: rebuild rsWVPRunner's package, redeploy, and update trinket's pins (a picup PR).
What a refresh involves
The procedure is in the build notes in lib/compiling/GScompiler.js. Upstream builds don't include GlowScript's own changes, so each has to be reapplied:
vec == vec/vec != vecinρσ_equals/ρσ_not_equals(compiler.js ×2 each, runtime.js ×1 each).pop→.pypoprenames (GScompiler.js rewrites user.popcalls)- the randrange replacement (possibly obsolete now that upstream has it)
- anything else carried in the 0.7.22 build that isn't in those notes. Diffing our compiler.js against a clean upstream 0.7.22 build will show this, and that diff should be done first.
Decisions to make
- randint and randrange raising errors. Matching Python means
randint(0, n/2)with an oddnraises an error where it used to return a value silently. That's more correct, but it can break existing student programs. Options: take it as is, take it with a deprecation period, or keep our one-line version. - 0.7 → 0.8 changes in general. Review upstream's changelog between 0.7.22 and 0.8.7 for language and runtime changes that affect VPython programs.
Testing plan
- Compile and run the Demos (and
GlowScriptOffline/Demos) with the old and new compilers, and compare output and errors. - Run randint/randrange histograms over negative, mixed-sign, single-value and > 2**31 ranges. The harness used for Fix random.randint() with negative numbers #215 drives GlowScriptOffline with Playwright.
- Before glowscript.org, test on rsWVPRunner with a webvpython.org staging host and on trinket's two trials.
Until the refresh is done, we could port the randrange > 2**31 fix (67b56d2) the same way #215 ported randint.
🤖 Generated with Claude Code
Activity
sspickle commentedon Nov 1, 2026
Two more differences from Python, found while testing #170 (PR #223). Both come from RapydScript itself, not from GlowScript's preprocessing. They behave the same before and after #223, so #223 left them alone:
7 % -3-21%compiles to the JS remainder, whose sign follows the dividend, not the divisor. Same for-7 % 3(Python2, GlowScript-1).2**-1**20.50.25(2**-1)**2instead of Python's2**(-(1**2)). Plain-10**2is correct (-100).I haven't checked whether upstream 0.8.7 changes either one. When this refresh happens, add both to the test list. The 39-case negative-sign check used for #223 could be extended to cover them.
🤖 Generated with Claude Code