Skip to content

Commit 4c0a14b

Browse files
committed
debug
1 parent 72eb542 commit 4c0a14b

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

vm/src/vm/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,9 @@ impl Context {
268268
CONTEXT.get_or_init(|| PyRc::new(Self::init_genesis()))
269269
}
270270

271-
fn init_genesis() -> Self {
272-
flame_guard!("init Context");
271+
pub fn init_genesis() -> Self {
272+
// flame_guard!("init Context");
273+
273274
let types = TypeZoo::init();
274275
let exceptions = exceptions::ExceptionZoo::init();
275276

vm/src/vm/interpreter.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ impl Interpreter {
5656
Self { vm }
5757
}
5858

59+
pub fn debug_init<F>(settings: Settings, init: F) -> Result<Self, i32>
60+
where
61+
F: FnOnce(&mut VirtualMachine),
62+
{
63+
// return Err(100);
64+
let ctx = Context::init_genesis();
65+
return Err(99);
66+
// crate::types::TypeZoo::extend(ctx);
67+
// crate::exceptions::ExceptionZoo::extend(ctx);
68+
// let mut vm = VirtualMachine::new(settings, ctx.clone());
69+
// init(&mut vm);
70+
// vm.initialize();
71+
// Ok(Self { vm })
72+
}
73+
5974
/// Run a function with the main virtual machine and return a PyResult of the result.
6075
///
6176
/// To enter vm context multiple times or to avoid buffer/exception management, this function is preferred.

wasm/wasm-unknown-test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ crate-type = ["cdylib"]
88

99
[dependencies]
1010
getrandom = "0.3"
11-
rustpython-vm = { path = "../../vm", default-features = false, features = ["compiler"] }
11+
rustpython-vm = { path = "../../vm", default-features = false, features = ["compiler", "freeze-stdlib", "stdio"] }
1212

1313
[workspace]
1414

wasm/wasm-unknown-test/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustpython_vm::{Interpreter, eval};
1+
use rustpython_vm::{eval, Interpreter};
22

33
#[unsafe(no_mangle)]
44
pub unsafe extern "Rust" fn eval(s: *const u8, l: usize) -> u32 {
@@ -17,3 +17,23 @@ unsafe extern "Rust" fn __getrandom_v03_custom(
1717
) -> Result<(), getrandom::Error> {
1818
Err(getrandom::Error::UNSUPPORTED)
1919
}
20+
21+
#[unsafe(no_mangle)]
22+
pub unsafe extern "Rust" fn process() -> i32 {
23+
let mut settings = rustpython_vm::Settings::default();
24+
settings.path_list = vec!["Lib".into()];
25+
26+
println!("10");
27+
eprintln!("20");
28+
29+
let interpreter = match Interpreter::debug_init(settings, |vm| {}) {
30+
Ok(interpreter) => interpreter,
31+
Err(code) => return code,
32+
};
33+
return 30;
34+
interpreter.enter(|vm| {
35+
40
36+
// // let res = eval::eval(vm, src, vm.new_scope_with_builtins(), "<string>").unwrap();
37+
// // res.try_into_value(vm).unwrap()
38+
})
39+
}

0 commit comments

Comments
 (0)