Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
03c619f
Rearrange website directory and change webpack config
coolreader18 Dec 19, 2018
4c32693
Switch to using one workspace, move profile to root Cargo.toml
coolreader18 Dec 18, 2018
ca30ebc
Genericize the wasm lib to not be specifically for the demo
coolreader18 Dec 22, 2018
2ea9dca
Add example, change some stuff in the demo to align with example
coolreader18 Dec 23, 2018
d54d2b1
Make scripts executable
coolreader18 Dec 23, 2018
840c507
Improve UX for demo
coolreader18 Dec 23, 2018
ab23f2c
Use str.format for the demo
coolreader18 Dec 23, 2018
24507de
Re-add conflicting files
coolreader18 Dec 24, 2018
ffcd40b
Remove conflicting files
coolreader18 Dec 24, 2018
d1d9585
Change the instances of Fn(..) -> PyResult to a RustPyFunc trait alias
coolreader18 Dec 24, 2018
63b3f3e
Fix blanket impl of RustPyFunc
coolreader18 Dec 24, 2018
132930e
Allow passing closures from JS to python via `vars`
coolreader18 Dec 26, 2018
e0959b9
Implement error conversion for js_to_py
coolreader18 Dec 26, 2018
94d6a91
Fix js_to_py with JS `undefined`
coolreader18 Dec 26, 2018
c38796b
Add some documentation for functions on the demo site
coolreader18 Dec 26, 2018
877206d
Switch from shell to npm scripts for demo using webpack and @wasm-too…
coolreader18 Dec 27, 2018
2968982
Change README portion for compiling wasm
coolreader18 Dec 27, 2018
ada92d3
Add conflicting files
coolreader18 Dec 19, 2018
dfadd03
Remove (now outdated) previously conflicting files
coolreader18 Dec 27, 2018
396842e
Readd conflicting files
coolreader18 Dec 19, 2018
8303743
Remove RustPyFunc trait, just use Fn(..) everywhere
coolreader18 Dec 27, 2018
1f02cc0
Squash all demo commits onto one branch
coolreader18 Dec 28, 2018
4cc7f5a
Merge #console and #code styles
coolreader18 Dec 28, 2018
b277280
Add README and manifest fields for the WASM library
coolreader18 Dec 28, 2018
1d5df41
Add doc comments and typescript custom section
coolreader18 Dec 28, 2018
36997e1
Comment out WB's TS definitions using a hack
coolreader18 Dec 28, 2018
d7fdc5c
Fix typescript hack
coolreader18 Dec 28, 2018
e65639f
Remove yarn.lock
coolreader18 Dec 29, 2018
231e3f2
Export PyEvalOptions in typescript defs
coolreader18 Dec 29, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Genericize the wasm lib to not be specifically for the demo
This included changing RustObjectKind::RustFunction.function to be
a `Box<Fn()>` instead of a `fn()` to support closures.
  • Loading branch information
coolreader18 committed Dec 24, 2018
commit ca30ebcf5d0fffd0fa80e3b9b728b5f37cde01fd
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.1"
authors = ["Windel Bouwman", "Shing Lyu <shing.lyu@gmail.com>"]

[workspace]
members = [".", "vm", "wasm", "parser"]
members = [".", "vm", "wasm/lib", "parser"]

[dependencies]
log="0.4.1"
Expand Down
2 changes: 1 addition & 1 deletion vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ impl Frame {
bytecode::Instruction::LoadBuildClass => {
let rustfunc = PyObject::new(
PyObjectKind::RustFunction {
function: builtins::builtin_build_class_,
function: Box::new(builtins::builtin_build_class_),
},
vm.ctx.type_type(),
);
Expand Down
33 changes: 26 additions & 7 deletions vm/src/pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,24 @@ impl PyContext {
)
}

pub fn new_rustfunc(&self, function: RustPyFunc) -> PyObjectRef {
pub fn new_rustfunc<F: 'static + Fn(&mut VirtualMachine, PyFuncArgs) -> PyResult>(
&self,
function: F,
) -> PyObjectRef {
PyObject::new(
PyObjectKind::RustFunction { function: function },
PyObjectKind::RustFunction {
function: Box::new(function),
},
self.function_type(),
)
}

pub fn new_rustfunc_from_box(
&self,
function: Box<(Fn(&mut VirtualMachine, PyFuncArgs) -> PyResult)>,
) -> PyObjectRef {
PyObject::new(
PyObjectKind::RustFunction { function },
self.function_type(),
)
}
Expand All @@ -463,7 +478,10 @@ impl PyContext {
PyObject::new(PyObjectKind::Frame { frame: frame }, self.frame_type())
}

pub fn new_property(&self, function: RustPyFunc) -> PyObjectRef {
pub fn new_property<F: 'static + Fn(&mut VirtualMachine, PyFuncArgs) -> PyResult>(
&self,
function: F,
) -> PyObjectRef {
let fget = self.new_rustfunc(function);
let py_obj = PyObject::new(
PyObjectKind::Instance {
Expand Down Expand Up @@ -505,7 +523,10 @@ impl PyContext {
)
}

pub fn new_member_descriptor(&self, function: RustPyFunc) -> PyObjectRef {
pub fn new_member_descriptor<F: 'static + Fn(&mut VirtualMachine, PyFuncArgs) -> PyResult>(
&self,
function: F,
) -> PyObjectRef {
let dict = self.new_dict();
self.set_item(&dict, "function", self.new_rustfunc(function));
self.new_instance(dict, self.member_descriptor_type())
Expand Down Expand Up @@ -762,8 +783,6 @@ impl PyFuncArgs {
}
}

type RustPyFunc = fn(vm: &mut VirtualMachine, PyFuncArgs) -> PyResult;

/// Rather than determining the type of a python object, this enum is more
/// a holder for the rust payload of a python object. It is more a carrier
/// of rust data for a particular python object. Determine the python type
Expand Down Expand Up @@ -840,7 +859,7 @@ pub enum PyObjectKind {
dict: PyObjectRef,
},
RustFunction {
function: RustPyFunc,
function: Box<(Fn(&mut VirtualMachine, PyFuncArgs) -> PyResult)>,
},
}

Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl VirtualMachine {
pub fn invoke(&mut self, func_ref: PyObjectRef, args: PyFuncArgs) -> PyResult {
trace!("Invoke: {:?} {:?}", func_ref, args);
match func_ref.borrow().kind {
PyObjectKind::RustFunction { function } => function(self, args),
PyObjectKind::RustFunction { ref function } => function(self, args),
PyObjectKind::Function {
ref code,
ref scope,
Expand Down
10 changes: 3 additions & 7 deletions wasm/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
wasm-pack build --debug && \
cd pkg && \
npm link && \
cd ../app && \
npm install && \
npm link rustpython_wasm && \
node_modules/.bin/webpack-dev-server
set -e
(cd lib; wasm-pack build --debug)
(cd demo; npm install && node_modules/.bin/webpack-dev-server)
File renamed without changes.
File renamed without changes.
Loading