Skip to content

Refresh embedded RapydScript-NG (0.7.22 → upstream 0.8.7+) #217

Open

Description

@sspickle

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:

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 != vec in ρσ_equals / ρσ_not_equals (compiler.js ×2 each, runtime.js ×1 each)
  • .pop → .pypop renames (GScompiler.js rewrites user .pop calls)
  • 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

  1. randint and randrange raising errors. Matching Python means randint(0, n/2) with an odd n raises 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.
  2. 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

  1. sspickle commented on Nov 1, 2026

    @sspickle
    CollaboratorAuthor

    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:

    Expression Python GlowScript now Cause
    7 % -3 -2 1 % compiles to the JS remainder, whose sign follows the dividend, not the divisor. Same for -7 % 3 (Python 2, GlowScript -1).
    2**-1**2 0.5 0.25 Unary minus inside an exponent binds as (2**-1)**2 instead of Python's 2**(-(1**2)). Plain -10**2 is 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions