MCPcopy Index your code
hub / github.com/RustPython/RustPython / main

Function main

example_projects/wasm32_without_js/wasm-runtime/src/main.rs:87–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

85}
86
87fn main() {
88 let mut store = Store::default();
89 let module = Module::new(
90 &store,
91 &std::fs::read(&std::env::args().nth(1).unwrap()).unwrap(),
92 )
93 .unwrap();
94
95 // Prepare initial KV store with Python code
96 let mut initial_kv = HashMap::new();
97 initial_kv.insert(
98 b"code".to_vec(),
99 b"a=10;b='str';f'{a}{b}'".to_vec(), // Python code to execute
100 );
101
102 let env = FunctionEnv::new(
103 &mut store,
104 Ctx {
105 kv: initial_kv,
106 mem: None,
107 },
108 );
109 let imports = imports! {
110 "env" => {
111 "kv_get" => Function::new_typed_with_env(&mut store, &env, kv_get),
112 "kv_put" => Function::new_typed_with_env(&mut store, &env, kv_put),
113 // "get_code" => Function::new_typed_with_env(&mut store, &env, get_code),
114 "print" => Function::new_typed_with_env(&mut store, &env, print),
115 }
116 };
117 let inst = Instance::new(&mut store, &module, &imports).unwrap();
118 env.as_mut(&mut store).mem = inst.exports.get_memory("memory").ok().cloned();
119 let res = inst
120 .exports
121 .get_function("eval")
122 .unwrap()
123 // TODO: actually pass source code
124 .call(&mut store, &[wasmer::Value::I32(0), wasmer::Value::I32(0)])
125 .unwrap();
126 println!(
127 "Result: {}",
128 match res[0] {
129 Value::I32(v) => v,
130 _ => -1,
131 }
132 );
133}

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
to_vecMethod · 0.80
okMethod · 0.80
get_functionMethod · 0.80
readFunction · 0.50
unwrapMethod · 0.45
insertMethod · 0.45
as_mutMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected