Title: Fix two #223 regressions: "-(x+1)**2" sign and "- -x" as "--x" by sspickle · Pull Request #225 · vpython/glowscript · GitHub
Open Graph Title: Fix two #223 regressions: "-(x+1)**2" sign and "- -x" as "--x" by sspickle · Pull Request #225 · vpython/glowscript
X Title: Fix two #223 regressions: "-(x+1)**2" sign and "- -x" as "--x" by sspickle · Pull Request #225 · vpython/glowscript
Description: Fixes two regressions from #223 (#170). Before #223, the preprocessor's "-" → "-1*" rewrite hid two RapydScript bugs, and removing it exposed both. glowscript.org has been rolled back to the version before #223 (20261101t092705) until this is merged. 1. -(x+1)**2 came out positive RapydScript's parser gave unary operators higher precedence than **, so -x**2 parsed as (-x)**2. The output stage then turned that back into -Math.pow(x, 2), but only when the unary had no parentheses. Everything else came out with the wrong sign: Python with #223 this PR -(x+1)**2 (x = 5) -36 36 -36 -(x)**2 -25 25 -25 -(2)**2 -4 4 -4 - -x**2 25 -25 25 exp(-(x-3)**2/8) 0.61 1.65 0.61 Fix (61d0edf): maybe_unary now parses Python's primary ** factor itself. After an atom, ** takes the next unary expression as its right operand. That makes ** bind tighter than a unary operator on its left, and makes it group right to left. That also fixes two items from #224: 2**3**2 (was 64, now 512) and 2**-1**2 (was 0.25, now 0.5). Reported upstream as kovidgoyal/rapydscript-ng#195; Kovid fixed it the same way in kovidgoyal/rapydscript-ng@50aa052 (Nov 3). 2. - -x compiled to --x RapydScript printed a unary operator directly against its operand, so - -x became --x. In JavaScript that's a pre-decrement: it gives the wrong value and changes x. - -3 was a syntax error, so the program didn't compile at all. Fix (b185ec0): print_unary_prefix now adds a space when a sign operator follows another sign operator. Upstream fixed this the same day as kovidgoyal/rapydscript-ng#194 (ec30155). Testing tests/test_compiler.py compiles 31 expressions with the bundled compiler under node and compares each result with CPython: 10 repeated-sign cases and 21 power/unary cases. Before the fixes, 4 and 9 of them fail. After, all pass. It skips if node isn't installed, and python -m pytest --noconftest tests/test_compiler.py runs it without the Flask app. Through GlowScriptOffline: Check Before #223 #223 This PR 122-row arithmetic table, rows differing from CPython 34 15 13 Power table (17 rows) all match 8 wrong all match #170 39-case program 0 failures 23 bundled demos all run The 13 rows still differing are the known %, round-half, bool and e items from #224. **kwargs in calls and definitions, comprehensions, and conditionals containing ** all behave as before. The same compiler is on vpython/rsWVPRunner#5, and the trinket trials will run it as rsWVPRunner v3.2.4-rc3. 🤖 Generated with Claude Code
Open Graph Description: Fixes two regressions from #223 (#170). Before #223, the preprocessor's "-" → "-1*" rewrite hid two RapydScript bugs, and removing it exposed both. glowscript.org has been r...
X Description: Fixes two regressions from #223 (#170). Before #223, the preprocessor's "-" → "-1*" rewrite hid two RapydScript bugs, and removing it exposed both. glows...
Opengraph URL: https://github.com/vpython/glowscript/pull/225
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d7d8982d-53e6-0619-c78d-9efd47de6d9f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9104:BCAF9:1BCB9:27C86:6B007D7F |
| html-safe-nonce | 33d005229cf89e0be6bbf34618447d934edff9d4a3d12afbeb3ab84c60abb474 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTA0OkJDQUY5OjFCQ0I5OjI3Qzg2OjZCMDA3RDdGIiwidmlzaXRvcl9pZCI6IjY5MzgxNTM0MTk0NDE5OTUxMzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 473869fdda80f08e37296a97362c815cc5b0e93e49d953ee2551a077edc8c048 |
| hovercard-subject-tag | pull_request:5135387868 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/vpython/glowscript/pull/225/files |
| twitter:image | https://avatars.githubusercontent.com/u/1708412?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1708412?s=400&v=4 |
| og:image:alt | Fixes two regressions from #223 (#170). Before #223, the preprocessor's "-" → "-1*" rewrite hid two RapydScript bugs, and removing it exposed both. glowscript.org has been r... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 82c186f13e104004ab7bdb779f3195e59dd38bfde531aaa74b76470fc2462b83 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/vpython/glowscript git https://github.com/vpython/glowscript.git |
| octolytics-dimension-user_id | 1280757 |
| octolytics-dimension-user_login | vpython |
| octolytics-dimension-repository_id | 187905631 |
| octolytics-dimension-repository_nwo | vpython/glowscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 187905631 |
| octolytics-dimension-repository_network_root_nwo | vpython/glowscript |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d1bc2aa1939001689f5ce935982c10a6138f745c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width