Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf2e60b2

Browse files
committed
Add initial platform module.
1 parenta6341d3 commitf2e60b2

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 aboutcustomizing 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+
externcrate rustc_version_runtime;
2+
3+
usecrate::pyobject::{PyContext,PyFuncArgs,PyObjectRef,PyResult};
4+
usecrate::VirtualMachine;
5+
6+
pubfnmk_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+
fnplatform_python_implementation(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
15+
arg_check!(vm, args);
16+
Ok(vm.new_str("RustPython".to_string()))
17+
}
18+
19+
fnplatform_python_version(vm:&mutVirtualMachine,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+
fnplatform_python_compiler(vm:&mutVirtualMachine,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)

[8]ページ先頭

©2009-2025 Movatter.jp