Attempt to reduce the size of the pyobject.rs files by splitting out builtin types.

This commit is contained in:
Windel Bouwman
2019-08-14 17:48:54 +02:00
parent 11cbf556e5
commit d06dec77ea
42 changed files with 477 additions and 418 deletions

View File

@@ -1,6 +1,7 @@
use crate::obj::objstr::PyStringRef;
use crate::py_serde;
use crate::pyobject::{create_type, ItemProtocol, PyObjectRef, PyResult};
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult};
use crate::types::create_type;
use crate::VirtualMachine;
use serde_json;
@@ -39,7 +40,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
// TODO: Make this a proper type with a constructor
let json_decode_error = create_type(
"JSONDecodeError",
&ctx.type_type,
&ctx.types.type_type,
&ctx.exceptions.exception_type,
);

View File

@@ -191,7 +191,7 @@ fn math_trunc(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
fn math_ceil(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(value, None)]);
if objtype::isinstance(value, &vm.ctx.float_type) {
if objtype::isinstance(value, &vm.ctx.float_type()) {
let v = objfloat::get_value(value);
Ok(vm.ctx.new_float(v.ceil()))
} else {
@@ -201,7 +201,7 @@ fn math_ceil(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
fn math_floor(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(value, None)]);
if objtype::isinstance(value, &vm.ctx.float_type) {
if objtype::isinstance(value, &vm.ctx.float_type()) {
let v = objfloat::get_value(value);
Ok(vm.ctx.new_float(v.floor()))
} else {

View File

@@ -1,6 +1,7 @@
use crate::function::OptionalArg;
use crate::obj::{objbytes::PyBytesRef, objint::PyIntRef};
use crate::pyobject::{create_type, ItemProtocol, PyObjectRef, PyResult};
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult};
use crate::types::create_type;
use crate::vm::VirtualMachine;
use adler32::RollingAdler32 as Adler32;
@@ -18,7 +19,11 @@ const DEF_BUF_SIZE: usize = 16 * 1024;
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
let ctx = &vm.ctx;
let zlib_error = create_type("error", &ctx.type_type, &ctx.exceptions.exception_type);
let zlib_error = create_type(
"error",
&ctx.types.type_type,
&ctx.exceptions.exception_type,
);
py_module!(vm, "zlib", {
"crc32" => ctx.new_rustfunc(zlib_crc32),