We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parent1c37625 commit72d53feCopy full SHA for 72d53fe
wasm/Cargo.toml
@@ -1,14 +1,20 @@
1
[package]
2
name ="rustpython_wasm"
3
version ="0.1.0"
4
-authors = ["rmliddle <ryan@rmliddle.com>"]
+authors = ["Ryan Liddle <ryan@rmliddle.com>"]
5
+
6
+[lib]
7
+crate-type = ["cdylib","rlib"]
8
9
[workspace]
10
members = []
11
12
[dependencies]
13
rustpython_parser = {path ="../parser"}
14
rustpython_vm = {path ="../vm"}
15
+cfg-if ="0.1.2"
16
+wasm-bindgen ="0.2"
17
18
19
[profile.release]
-opt-level ='s'
20
+opt-level ="s"
wasm/app/bootstrap.js
@@ -0,0 +1,5 @@
+// A dependency graph that contains any wasm must all be imported
+// asynchronously. This `bootstrap.js` file does the single async import, so
+// that no one else needs to worry about it again.
+import("./index.js")
+.catch(e=>console.error("Error importing `index.js`:",e));
wasm/app/index.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+<metacharset="utf-8">
+<title>Hello wasm-pack!</title>
+</head>
+<body>
+<scriptsrc="./bootstrap.js"></script>
+</body>
+</html>
wasm/app/index.js
@@ -0,0 +1,3 @@
+import*asrpfrom"rustpython_wasm";
+rp.run_code("print('Hello Python!')\n");
wasm/app/package.json
@@ -0,0 +1,27 @@
+{
+"name":"app",
+"version":"1.0.0",
+"description":"",
+"main":"index.js",
+"dependencies": {
+"hello-wasm-pack":"^0.1.0",
+"webpack":"^4.16.3",
+"webpack-cli":"^3.1.0",
+"webpack-dev-server":"^3.1.5",
+"copy-webpack-plugin":"^4.5.2"
+ },
+"devDependencies": {},
+"scripts": {
+"test":"echo\"Error: no test specified\" && exit 1"
+"repository": {
+"type":"git",
+"url":"git+https://github.com/RustPython/RustPython.git"
21
+"author":"Ryan Liddle",
22
+"license":"MIT",
23
+"bugs": {
24
+"url":"https://github.com/RustPython/RustPython/issues"
25
26
+"homepage":"https://github.com/RustPython/RustPython#readme"
27
+}
wasm/app/webpack.config.js
@@ -0,0 +1,14 @@
+constCopyWebpackPlugin=require("copy-webpack-plugin");
+constpath=require('path');
+module.exports={
+entry:"./bootstrap.js",
+output:{
+path:path.resolve(__dirname,"dist"),
+filename:"bootstrap.js",
+},
+mode:"development",
+plugins:[
+newCopyWebpackPlugin(['index.html'])
+],
+};
wasm/src/lib.rs
@@ -0,0 +1,28 @@
+externcrate rustpython_vm;
+externcrate wasm_bindgen;
+use wasm_bindgen::prelude::*;
+use rustpython_vm::VirtualMachine;
+use rustpython_vm::compile;
+#[wasm_bindgen]
+extern"C"{
+// Use `js_namespace` here to bind `console.log(..)` instead of just
+// `log(..)`
+#[wasm_bindgen(js_namespace = console)]
+fnlog(s:&str);
+pubfnrun_code(source:&str) ->(){
+//add hash in here
+log("Running RustPython");
+log(&source.to_string());
+letmut vm =VirtualMachine::new();
+let code_obj = compile::compile(&mut vm,&source.to_string(), compile::Mode::Exec,None);
+let builtins = vm.get_builtin_scope();
+let vars = vm.context().new_scope(Some(builtins));
+match vm.run_code_obj(code_obj.unwrap(), vars){
+Ok(_value) =>log("Execution successful"),
+Err(_) =>log("Execution failed")
28