Skip to content

Commit f2e60b2

Browse files
committed
Add initial platform module.
1 parent a6341d3 commit f2e60b2

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

Cargo.lock

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ serde_derive = "1.0.66"
1818
serde_json = "1.0.26"
1919
byteorder = "1.2.6"
2020
regex = "1"
21+
rustc_version_runtime = "0.1.*"
2122
statrs = "0.10.0"
2223
caseless = "0.2.1"
2324
unicode-segmentation = "1.2.1"

vm/src/stdlib/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod dis;
33
mod json;
44
mod keyword;
55
mod math;
6+
mod platform;
67
mod pystruct;
78
mod random;
89
mod re;
@@ -33,6 +34,7 @@ pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
3334
modules.insert("json".to_string(), Box::new(json::mk_module));
3435
modules.insert("keyword".to_string(), Box::new(keyword::mk_module));
3536
modules.insert("math".to_string(), Box::new(math::mk_module));
37+
modules.insert("platform".to_string(), Box::new(platform::mk_module));
3638
modules.insert("re".to_string(), Box::new(re::mk_module));
3739
modules.insert("random".to_string(), Box::new(random::mk_module));
3840
modules.insert("string".to_string(), Box::new(string::mk_module));

vm/src/stdlib/platform.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
extern crate rustc_version_runtime;
2+
3+
use crate::pyobject::{PyContext, PyFuncArgs, PyObjectRef, PyResult};
4+
use crate::VirtualMachine;
5+
6+
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
7+
py_module!(ctx, "platform", {
8+
"python_compiler" => ctx.new_rustfunc(platform_python_compiler),
9+
"python_implementation" => ctx.new_rustfunc(platform_python_implementation),
10+
"python_version" => ctx.new_rustfunc(platform_python_version),
11+
})
12+
}
13+
14+
fn platform_python_implementation(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
15+
arg_check!(vm, args);
16+
Ok(vm.new_str("RustPython".to_string()))
17+
}
18+
19+
fn platform_python_version(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
20+
arg_check!(vm, args);
21+
// TODO: fetch version from somewhere.
22+
Ok(vm.new_str("4.0.0".to_string()))
23+
}
24+
25+
fn platform_python_compiler(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
26+
arg_check!(vm, args);
27+
let version = rustc_version_runtime::version_meta();
28+
Ok(vm.new_str(format!("rustc {}", version.semver)))
29+
}

0 commit comments

Comments
 (0)