* stage1 * compiler pass build * introduce rustpython-compiler-source * stage2 * fixup * pass compile * Fix hello world compiler test * Fix code generation for if-elif-else statement * Fix code generation for lambda expression * Fix code generation for integers * Fix code generation for fstrings * Fix code generation for if statement * Fix code generation for if statement * Fix code generation for if statement * Fix code generation for fstring * Fix code generation for class definition * Replace feature flags * Initialize frozen core modules * Allow __future__ import after module doc comment * Disable ast module * Commit remaining fixes for compile errors in examples * Fix some warnings * Update ast stdlib module * Update ast stdlib module * Update ast stdlib module * Update ast stdlib module * Update ast stdlib module * Split ast stdlib module into files * Fix codegen for positional arguments with defaults * Update ast stdlib module * Update ast stdlib module * Extract string and constant handling from expression.rs * Always add required fields to AST nodes * Compile doc strings correctly again * Enable "ast" Cargo feature by default * Refactor compilation of big integer literal * Update ast stdlib module * Update ast stdlib module * Update ast stdlib module * Reset barebones example * Fix some left-over warnings * Undo accidential change * Adapt shell to ruff parser * Pin parser to v0.4.10 * fix clippy * Add TODO about interactive mode * Fix compilation of complex number expression * Remove moved code * Update test case to ruff v0.4.10 * Apply suggestion Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com> * Apply suggestion Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com> * Fix compilation of fstring expression * Fix compilation of fstring expression * Fix wasm compile errors * Attach correct source locations to ast objects * Fix some more wasm compile errors * Consider compile mode and enable AST stdlib module again * Fix incorrect AST source location end column * Fix compile error if "compiler" feature is not enabled * Fix regrtests * Fix some test_ast tests * Add source range to type ignore * Fix incompatibility with Rust 2024 edition * Fix todos by implementing missing ast conversions and deleting unused code * Appease clippy * Fix remaining ast tests * Fix remaining ast tests * Mark/fix remaining tests * Fix more * Hacky windows fix --------- Co-authored-by: Kangzhi Shi <shikangzhi@gmail.com> Co-authored-by: Jeong YunWon <jeong@youknowone.org> Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com> Co-authored-by: Noa <coolreader18@gmail.com>
Compiling to webassembly
At this stage RustPython only has preliminary support for web assembly. The instructions here are intended for developers or those wishing to run a toy example.
Setup
To get started, install
wasm-pack and npm.
(wasm-bindgen
should be installed by wasm-pack. if not, install it yourself)
Build
Move into the wasm directory. This directory contains a library crate for
interop with python to rust to js and back in wasm/lib, the demo website found
at https://rustpython.github.io/demo in wasm/demo, and an example of how to
use the crate as a library in one's own JS app in wasm/example.
cd wasm
Go to the demo directory. This is the best way of seeing the changes made to
either the library or the JS demo, as the rustpython_wasm module is set to the
global JS variable rp on the website.
cd demo
Now, start the webpack development server. It'll compile the crate and then the demo app. This will likely take a long time, both the wasm-pack portion and the webpack portion (from after it says "Your crate has been correctly compiled"), so be patient.
npm run dev
You can now open the webpage on https://localhost:8080 and Python code in either the text box or browser devtools with:
rp.pyEval(
`
print(js_vars['a'] * 9)
`,
{
vars: {
a: 9,
},
},
);
Alternatively, you can run npm run build to build the app once, without
watching for changes, or npm run dist to build the app in release mode, both
for the crate and webpack.
Updating the demo
If you wish to update the WebAssembly demo,
open a pull request
to merge main into the release branch. This will trigger a Travis build
that updates the demo page.