expose bulitins items on builtins module and hide submodules

This commit is contained in:
Jeong YunWon committed 2020-10-12 11:43:24 +09:00
1 parent 9e6dfca9e9
commit ca9326f95d
13 files changed
+102 -62

No files matched your search

+3 -3
View File
@@ -73,7 +73,7 @@ pub(crate) fn impl_pyimpl(
fn impl_extend_class(
ctx: &::rustpython_vm::pyobject::PyContext,
class: &::rustpython_vm::builtins::pytype::PyTypeRef,
class: &::rustpython_vm::builtins::PyTypeRef,
) {
#getset_impl
#extend_impl
@@ -100,7 +100,7 @@ pub(crate) fn impl_pyimpl(
parse_quote! {
fn __extend_py_class(
ctx: &::rustpython_vm::pyobject::PyContext,
class: &::rustpython_vm::builtins::pytype::PyTypeRef,
class: &::rustpython_vm::builtins::PyTypeRef,
) {
#getset_impl
#extend_impl
@@ -162,7 +162,7 @@ fn generate_class_def(
let base_class = if is_pystruct {
quote! {
fn base_class(ctx: &::rustpython_vm::pyobject::PyContext) -> ::rustpython_vm::builtins::pytype::PyTypeRef {
fn base_class(ctx: &::rustpython_vm::pyobject::PyContext) -> ::rustpython_vm::builtins::PyTypeRef {
ctx.types.tuple_type.clone()
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ macro_rules! add_python_function {
$scope.globals.set_item(
def.obj_name.as_str(),
$vm.ctx.new_pyfunction(
vm::builtins::code::PyCode::new(*def.clone()).into_ref(&$vm),
vm::builtins::PyCode::new(*def.clone()).into_ref(&$vm),
$scope.clone(),
None,
None,
+2 -2
View File
@@ -7,7 +7,7 @@ extern crate log;
use clap::{App, AppSettings, Arg, ArgMatches};
use rustpython_compiler::compile;
use rustpython_vm::{
builtins::{int::PyInt, pytype},
builtins::{isinstance, PyInt},
exceptions::print_exception,
match_class,
pyobject::{BorrowValue, ItemProtocol, PyResult},
@@ -67,7 +67,7 @@ fn main() {
// See if any exception leaked out:
let exitcode = match res {
Ok(()) => 0,
Err(err) if pytype::isinstance(&err, &vm.ctx.exceptions.system_exit) => {
Err(err) if isinstance(&err, &vm.ctx.exceptions.system_exit) => {
let args = err.args();
match args.borrow_value().len() {
0 => 0,
+2 -2
View File
@@ -4,7 +4,7 @@ use rustpython_compiler::{compile, error::CompileError, error::CompileErrorType}
use rustpython_parser::error::{LexicalErrorType, ParseErrorType};
use rustpython_vm::readline::{Readline, ReadlineResult};
use rustpython_vm::{
builtins::pytype,
builtins::isinstance,
exceptions::{print_exception, PyBaseExceptionRef},
pyobject::{BorrowValue, PyResult},
scope::Scope,
@@ -127,7 +127,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
};
if let Err(exc) = result {
if pytype::isinstance(&exc, &vm.ctx.exceptions.system_exit) {
if isinstance(&exc, &vm.ctx.exceptions.system_exit) {
repl.save_history(&repl_history_path).unwrap();
return Err(exc);
}
+1 -1
View File
@@ -1,4 +1,4 @@
use rustpython_vm::builtins::pystr::PyStrRef;
use rustpython_vm::builtins::PyStrRef;
use rustpython_vm::pyobject::{BorrowValue, PyIterable, PyResult, TryFromObject};
use rustpython_vm::scope::{NameProtocol, Scope};
use rustpython_vm::VirtualMachine;
+80 -40
View File
@@ -1,45 +1,85 @@
//! This package contains the python basic/builtin types
pub mod asyncgenerator;
pub mod builtinfunc;
pub mod bytearray;
pub mod bytes;
pub mod classmethod;
pub mod code;
pub mod complex;
pub mod coroutine;
pub mod dict;
pub mod enumerate;
pub mod filter;
pub mod float;
pub mod frame;
pub mod function;
pub mod generator;
pub mod getset;
pub mod int;
pub mod iter;
pub mod list;
pub mod map;
pub mod mappingproxy;
pub mod memory;
pub mod module;
pub mod namespace;
pub mod object;
pub mod property;
pub mod pybool;
pub mod pystr;
pub mod pysuper;
pub mod pytype;
pub mod range;
pub mod set;
pub mod singletons;
pub mod slice;
pub mod staticmethod;
pub mod traceback;
pub mod tuple;
pub mod weakproxy;
pub mod weakref;
pub mod zip;
pub(crate) mod asyncgenerator;
pub use asyncgenerator::*;
pub(crate) mod builtinfunc;
pub use builtinfunc::*;
pub(crate) mod bytearray;
pub use bytearray::*;
pub(crate) mod bytes;
pub use bytes::*;
pub(crate) mod classmethod;
pub use classmethod::*;
pub(crate) mod code;
pub use code::*;
pub(crate) mod complex;
pub use complex::*;
pub(crate) mod coroutine;
pub use coroutine::*;
pub(crate) mod dict;
pub use dict::*;
pub(crate) mod enumerate;
pub use enumerate::*;
pub(crate) mod filter;
pub use filter::*;
pub(crate) mod float;
pub use float::*;
pub(crate) mod frame;
pub use frame::*;
pub(crate) mod function;
pub use function::*;
pub(crate) mod generator;
pub use generator::*;
pub(crate) mod getset;
pub use getset::*;
pub(crate) mod int;
pub use int::*;
pub(crate) mod iter;
pub use iter::*;
pub(crate) mod list;
pub use list::*;
pub(crate) mod map;
pub use map::*;
pub(crate) mod mappingproxy;
pub use mappingproxy::*;
pub(crate) mod memory;
pub use memory::*;
pub(crate) mod module;
pub use module::*;
pub(crate) mod namespace;
pub use namespace::*;
pub(crate) mod object;
pub use object::*;
pub(crate) mod property;
pub use property::*;
pub(crate) mod pybool;
pub use pybool::*;
pub(crate) mod pystr;
pub use pystr::*;
pub(crate) mod pysuper;
pub use pysuper::*;
pub(crate) mod pytype;
pub use pytype::*;
pub(crate) mod range;
pub use range::*;
pub(crate) mod set;
pub use set::*;
pub(crate) mod singletons;
pub use singletons::*;
pub(crate) mod slice;
pub use slice::*;
pub(crate) mod staticmethod;
pub use staticmethod::*;
pub(crate) mod traceback;
pub use traceback::*;
pub(crate) mod tuple;
pub use tuple::*;
pub(crate) mod weakproxy;
pub use weakproxy::*;
pub(crate) mod weakref;
pub use weakref::*;
pub(crate) mod zip;
pub use zip::*;
mod make_module;
pub use make_module::*;
+3 -3
View File
@@ -119,9 +119,9 @@ impl PyRange {
}
}
pub fn get_value(obj: &PyObjectRef) -> PyRange {
obj.payload::<PyRange>().unwrap().clone()
}
// pub fn get_value(obj: &PyObjectRef) -> PyRange {
// obj.payload::<PyRange>().unwrap().clone()
// }
pub fn init(context: &PyContext) {
PyRange::extend_class(context, &context.types.range_type);
+4 -4
View File
@@ -97,8 +97,8 @@ macro_rules! py_namespace {
/// use num_traits::Zero;
///
/// use rustpython_vm::match_class;
/// use rustpython_vm::builtins::float::PyFloat;
/// use rustpython_vm::builtins::int::PyInt;
/// use rustpython_vm::builtins::PyFloat;
/// use rustpython_vm::builtins::PyInt;
/// use rustpython_vm::pyobject::PyValue;
///
/// # rustpython_vm::Interpreter::default().enter(|vm| {
@@ -122,8 +122,8 @@ macro_rules! py_namespace {
/// use num_traits::Zero;
///
/// use rustpython_vm::match_class;
/// use rustpython_vm::builtins::float::PyFloat;
/// use rustpython_vm::builtins::int::PyInt;
/// use rustpython_vm::builtins::PyFloat;
/// use rustpython_vm::builtins::PyInt;
/// use rustpython_vm::pyobject::{PyValue, BorrowValue};
///
/// # rustpython_vm::Interpreter::default().enter(|vm| {
+1 -1
View File
@@ -1189,7 +1189,7 @@ impl<A: IntoPyObject, B: IntoPyObject> IntoPyObject for Either<A, B> {
///
/// ```
/// use rustpython_vm::VirtualMachine;
/// use rustpython_vm::builtins::{pystr::PyStrRef, int::PyIntRef};
/// use rustpython_vm::builtins::{PyStrRef, PyIntRef};
/// use rustpython_vm::pyobject::Either;
///
/// fn do_something(arg: Either<PyIntRef, PyStrRef>, vm: &VirtualMachine) {
+1 -1
View File
@@ -4,7 +4,7 @@ use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::{future_to_promise, JsFuture};
use rustpython_vm::builtins::{dict::PyDictRef, pystr::PyStrRef, pytype::PyTypeRef};
use rustpython_vm::builtins::{PyDictRef, PyStrRef, PyTypeRef};
use rustpython_vm::common::rc::PyRc;
use rustpython_vm::function::OptionalArg;
use rustpython_vm::import::import_file;
+2 -2
View File
@@ -3,7 +3,7 @@ use wasm_bindgen::{closure::Closure, prelude::*, JsCast};
use rustpython_compiler::error::{CompileError, CompileErrorType};
use rustpython_parser::error::ParseErrorType;
use rustpython_vm::builtins::pytype;
use rustpython_vm::builtins::isinstance;
use rustpython_vm::byteslike::PyBytesLike;
use rustpython_vm::exceptions::PyBaseExceptionRef;
use rustpython_vm::function::FuncArgs;
@@ -67,7 +67,7 @@ pub fn js_err_to_py_err(vm: &VirtualMachine, js_err: &JsValue) -> PyBaseExceptio
pub fn py_to_js(vm: &VirtualMachine, py_obj: PyObjectRef) -> JsValue {
if let Some(ref wasm_id) = vm.wasm_id {
if pytype::isinstance(&py_obj, &vm.ctx.types.function_type) {
if isinstance(&py_obj, &vm.ctx.types.function_type) {
let wasm_vm = WASMVirtualMachine {
id: wasm_id.clone(),
};
+1 -1
View File
@@ -1,5 +1,5 @@
use js_sys::{Array, Object, Reflect};
use rustpython_vm::builtins::{float::PyFloatRef, pystr::PyStrRef, pytype::PyTypeRef};
use rustpython_vm::builtins::{PyFloatRef, PyStrRef, PyTypeRef};
use rustpython_vm::common::rc::PyRc;
use rustpython_vm::exceptions::PyBaseExceptionRef;
use rustpython_vm::function::Args;
+1 -1
View File
@@ -6,7 +6,7 @@
use web_sys::{self, console};
use rustpython_vm::builtins::pystr::PyStrRef;
use rustpython_vm::builtins::PyStrRef;
use rustpython_vm::pyobject::{BorrowValue, PyObjectRef, PyResult};
use rustpython_vm::VirtualMachine;