From f453c749ecbb457cc03b53354d07f938feccce4b Mon Sep 17 00:00:00 2001 From: Windel Bouwman Date: Fri, 31 Aug 2018 20:31:25 +0200 Subject: [PATCH] Move builtin types to own directory --- vm/src/builtins.rs | 4 ++-- vm/src/exceptions.rs | 2 +- vm/src/lib.rs | 7 +------ vm/src/obj/mod.rs | 6 ++++++ vm/src/{ => obj}/objdict.rs | 8 ++++---- vm/src/{ => obj}/objfloat.rs | 8 ++++---- vm/src/{ => obj}/objint.rs | 8 ++++---- vm/src/{ => obj}/objlist.rs | 10 +++++----- vm/src/{ => obj}/objstr.rs | 10 +++++----- vm/src/{ => obj}/objtype.rs | 8 ++++---- vm/src/objbool.rs | 2 +- vm/src/objobject.rs | 4 ++-- vm/src/pyobject.rs | 12 ++++++------ vm/src/stdlib/json.rs | 3 ++- vm/src/vm.rs | 8 ++++---- 15 files changed, 51 insertions(+), 49 deletions(-) create mode 100644 vm/src/obj/mod.rs rename vm/src/{ => obj}/objdict.rs (97%) rename vm/src/{ => obj}/objfloat.rs (97%) rename vm/src/{ => obj}/objint.rs (98%) rename vm/src/{ => obj}/objlist.rs (97%) rename vm/src/{ => obj}/objstr.rs (96%) rename vm/src/{ => obj}/objtype.rs (99%) diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index 295f8e049..788a4452e 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -4,9 +4,9 @@ use std::collections::HashMap; use std::io::{self, Write}; use super::compile; +use super::obj::objstr; +use super::obj::objtype; use super::objbool; -use super::objstr; -use super::objtype; use super::pyobject::{ AttributeProtocol, DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, Scope, TypeProtocol, diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index de0970456..6eeeee5d4 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -1,4 +1,4 @@ -use super::objstr; +use super::obj::objstr; use super::pyobject::{ create_type, AttributeProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, }; diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 56a0a50a0..b979ac9b0 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -20,16 +20,11 @@ pub mod eval; mod exceptions; mod frame; mod import; +mod obj; mod objbool; -mod objdict; -mod objfloat; mod objfunction; -mod objint; -mod objlist; mod objobject; mod objsequence; -mod objstr; -mod objtype; pub mod pyobject; pub mod stdlib; mod sysmodule; diff --git a/vm/src/obj/mod.rs b/vm/src/obj/mod.rs new file mode 100644 index 000000000..36c28bd50 --- /dev/null +++ b/vm/src/obj/mod.rs @@ -0,0 +1,6 @@ +pub mod objdict; +pub mod objfloat; +pub mod objint; +pub mod objlist; +pub mod objstr; +pub mod objtype; diff --git a/vm/src/objdict.rs b/vm/src/obj/objdict.rs similarity index 97% rename from vm/src/objdict.rs rename to vm/src/obj/objdict.rs index ece1df349..4d3ba8a19 100644 --- a/vm/src/objdict.rs +++ b/vm/src/obj/objdict.rs @@ -1,10 +1,10 @@ -use super::objstr; -use super::objtype; -use super::pyobject::{ +use super::super::pyobject::{ AttributeProtocol, PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, TypeProtocol, }; -use super::vm::VirtualMachine; +use super::super::vm::VirtualMachine; +use super::objstr; +use super::objtype; use std::collections::HashMap; pub fn _set_item( diff --git a/vm/src/objfloat.rs b/vm/src/obj/objfloat.rs similarity index 97% rename from vm/src/objfloat.rs rename to vm/src/obj/objfloat.rs index 72890d687..c03839f23 100644 --- a/vm/src/objfloat.rs +++ b/vm/src/obj/objfloat.rs @@ -1,9 +1,9 @@ -use super::objint; -use super::objtype; -use super::pyobject::{ +use super::super::pyobject::{ AttributeProtocol, PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol, }; -use super::vm::VirtualMachine; +use super::super::vm::VirtualMachine; +use super::objint; +use super::objtype; fn str(vm: &mut VirtualMachine, args: PyFuncArgs) -> Result { arg_check!(vm, args, required = [(float, Some(vm.ctx.float_type()))]); diff --git a/vm/src/objint.rs b/vm/src/obj/objint.rs similarity index 98% rename from vm/src/objint.rs rename to vm/src/obj/objint.rs index 5f97590b5..ed5b23bc0 100644 --- a/vm/src/objint.rs +++ b/vm/src/obj/objint.rs @@ -1,9 +1,9 @@ -use super::objfloat; -use super::objtype; -use super::pyobject::{ +use super::super::pyobject::{ AttributeProtocol, PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol, }; -use super::vm::VirtualMachine; +use super::super::vm::VirtualMachine; +use super::objfloat; +use super::objtype; fn str(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { arg_check!(vm, args, required = [(int, Some(vm.ctx.int_type()))]); diff --git a/vm/src/objlist.rs b/vm/src/obj/objlist.rs similarity index 97% rename from vm/src/objlist.rs rename to vm/src/obj/objlist.rs index 48169c6fc..983418271 100644 --- a/vm/src/objlist.rs +++ b/vm/src/obj/objlist.rs @@ -1,10 +1,10 @@ -use super::objsequence::PySliceableSequence; -use super::objstr; -use super::objtype; -use super::pyobject::{ +use super::super::objsequence::PySliceableSequence; +use super::super::pyobject::{ AttributeProtocol, PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol, }; -use super::vm::VirtualMachine; +use super::super::vm::VirtualMachine; +use super::objstr; +use super::objtype; // set_item: pub fn set_item( diff --git a/vm/src/objstr.rs b/vm/src/obj/objstr.rs similarity index 96% rename from vm/src/objstr.rs rename to vm/src/obj/objstr.rs index 3ec633b36..330074ada 100644 --- a/vm/src/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -1,10 +1,10 @@ -use super::objint; -use super::objsequence::PySliceableSequence; -use super::objtype; -use super::pyobject::{ +use super::super::objsequence::PySliceableSequence; +use super::super::pyobject::{ AttributeProtocol, PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol, }; -use super::vm::VirtualMachine; +use super::super::vm::VirtualMachine; +use super::objint; +use super::objtype; pub fn init(context: &PyContext) { let ref str_type = context.str_type; diff --git a/vm/src/objtype.rs b/vm/src/obj/objtype.rs similarity index 99% rename from vm/src/objtype.rs rename to vm/src/obj/objtype.rs index c429e0e26..ec157c26a 100644 --- a/vm/src/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -1,10 +1,10 @@ -use super::objdict; -use super::objtype; // Required for arg_check! to use isinstance -use super::pyobject::{ +use super::super::pyobject::{ AttributeProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, ToRust, TypeProtocol, }; -use super::vm::VirtualMachine; +use super::super::vm::VirtualMachine; +use super::objdict; +use super::objtype; // Required for arg_check! to use isinstance /* * The magical type type diff --git a/vm/src/objbool.rs b/vm/src/objbool.rs index 5ace3f217..95c126e7d 100644 --- a/vm/src/objbool.rs +++ b/vm/src/objbool.rs @@ -1,4 +1,4 @@ -use super::objtype; +use super::obj::objtype; use super::pyobject::{ AttributeProtocol, PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol, }; diff --git a/vm/src/objobject.rs b/vm/src/objobject.rs index 898880a71..3dbcf388c 100644 --- a/vm/src/objobject.rs +++ b/vm/src/objobject.rs @@ -1,5 +1,5 @@ -use super::objdict; -use super::objtype; +use super::obj::objdict; +use super::obj::objtype; use super::pyobject::{ AttributeProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, TypeProtocol, diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 62417b1d1..c54208508 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -1,14 +1,14 @@ use super::bytecode; use super::exceptions; +use super::obj::objdict; +use super::obj::objfloat; +use super::obj::objint; +use super::obj::objlist; +use super::obj::objstr; +use super::obj::objtype; use super::objbool; -use super::objdict; -use super::objfloat; use super::objfunction; -use super::objint; -use super::objlist; use super::objobject; -use super::objstr; -use super::objtype; use super::vm::VirtualMachine; use std::cell::RefCell; use std::cmp::Ordering; diff --git a/vm/src/stdlib/json.rs b/vm/src/stdlib/json.rs index d771cc907..d9a847cb3 100644 --- a/vm/src/stdlib/json.rs +++ b/vm/src/stdlib/json.rs @@ -6,12 +6,13 @@ use serde::de::Visitor; use serde::ser::{SerializeMap, SerializeSeq}; use serde_json; +use super::super::obj::{objdict, objfloat, objint, objlist, objstr, objtype}; use super::super::pyobject::{ DictProtocol, PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, TypeProtocol, }; use super::super::VirtualMachine; -use super::super::{objbool, objdict, objfloat, objint, objlist, objsequence, objstr, objtype}; +use super::super::{objbool, objsequence}; // We need to have a VM available to serialise a PyObject based on its subclass, so we implement // PyObject serialisation via a proxy object which holds a reference to a VM diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 5ab9acd2d..213160120 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -15,11 +15,11 @@ use super::builtins; use super::bytecode; use super::frame::{copy_code, Block, Frame}; use super::import::import; +use super::obj::objlist; +use super::obj::objstr; +use super::obj::objtype; use super::objbool; -use super::objlist; use super::objobject; -use super::objstr; -use super::objtype; use super::pyobject::{ AttributeProtocol, DictProtocol, IdProtocol, ParentProtocol, PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, @@ -969,7 +969,7 @@ impl VirtualMachine { #[cfg(test)] mod tests { - use super::super::objint; + use super::super::obj::objint; use super::objstr; use super::VirtualMachine;