From aba1daf67447ff60b7a424dae0460558d029b5f0 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 10 Aug 2018 12:32:53 -0400 Subject: [PATCH 01/10] Remove unused import (and rustfmt all imports) in vm.rs --- vm/src/vm.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 3233eb379..0f46ee679 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -10,23 +10,14 @@ use std::ops::Deref; use super::builtins; use super::bytecode; -use super::frame::{Block, Frame, copy_code}; +use super::frame::{copy_code, Block, Frame}; use super::import::import; use super::objlist; use super::objstr; use super::objtype; use super::pyobject::{ - AttributeProtocol, - DictProtocol, - IdProtocol, - ParentProtocol, - PyContext, - PyFuncArgs, - PyObject, - PyObjectKind, - PyObjectRef, - PyResult, - Scope, + AttributeProtocol, DictProtocol, IdProtocol, ParentProtocol, PyContext, PyFuncArgs, PyObject, + PyObjectKind, PyObjectRef, PyResult, }; use super::sysmodule; From 976a3f7a035ebdc29100775204072772d5fdf339 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 10 Aug 2018 12:34:01 -0400 Subject: [PATCH 02/10] Remove unused VirtualMachine.call function --- vm/src/vm.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 0f46ee679..8f0f5ad47 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -33,13 +33,6 @@ pub struct VirtualMachine { } impl VirtualMachine { - fn call(&mut self, f: PyObjectRef) -> PyResult { - let args = PyFuncArgs { - args: Vec::new(), - }; - self.invoke(f, args) - } - pub fn run_code_obj(&mut self, code: PyObjectRef, scope: PyObjectRef) -> PyResult { let frame = Frame::new(code, scope); self.run_frame(frame) From d8cd5a3361a800ba2ea44f4f95dcadbdffc31d06 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 10 Aug 2018 12:39:17 -0400 Subject: [PATCH 03/10] Enforce zero arguments to locals --- vm/src/builtins.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index 3d6a6b44e..b4663ddf8 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -161,10 +161,12 @@ fn builtin_len(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { // builtin_list fn builtin_locals(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { + if args.args.len() != 0 { + panic!("locals() doesn't take any arguments"); + } Ok(vm.get_locals()) } - pub fn builtin_print(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { trace!("print called with {:?}", args); for a in args.args { From 20737f77acd1c34eb75bd6c9079b851950c1fa55 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 10 Aug 2018 15:49:14 -0400 Subject: [PATCH 04/10] Remove duplicated match arm from PyObject::eq --- vm/src/pyobject.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 76d442d8c..10c6f5d8a 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -630,9 +630,6 @@ impl PartialEq for PyObject { curr_frame.stack.push(Rc::new(NativeType::Boolean(v2f == v1f))); }, */ - (PyObjectKind::String { value: ref v1s }, &PyObjectKind::String { value: ref v2s }) => { - v2s == v1s - } (PyObjectKind::List { elements: ref l1 }, PyObjectKind::List { elements: ref l2 }) | ( PyObjectKind::Tuple { elements: ref l1 }, From d8d9eb80876ab35a67e106a0717a93d6379abe50 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 10 Aug 2018 15:51:13 -0400 Subject: [PATCH 05/10] Silence a variety of unused argument warnings --- vm/src/builtins.rs | 3 ++- vm/src/compile.rs | 21 ++++++++++++++------- vm/src/objdict.rs | 8 +++++++- vm/src/objint.rs | 3 ++- vm/src/objlist.rs | 3 ++- vm/src/pyobject.rs | 2 +- vm/src/vm.rs | 2 +- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index b4663ddf8..2de1c9cff 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -28,7 +28,8 @@ fn dir_locals(vm: &mut VirtualMachine) -> PyObjectRef { get_locals(vm) } -fn dir_object(vm: &mut VirtualMachine, obj: PyObjectRef) -> PyObjectRef { +fn dir_object(vm: &mut VirtualMachine, _obj: PyObjectRef) -> PyObjectRef { + // TODO: Implement dir for objects let d = vm.new_dict(); d } diff --git a/vm/src/compile.rs b/vm/src/compile.rs index b9fe4c291..7bc4b8509 100644 --- a/vm/src/compile.rs +++ b/vm/src/compile.rs @@ -156,7 +156,12 @@ impl Compiler { } self.set_label(end_label); } - ast::Statement::While { test, body, orelse } => { + ast::Statement::While { + test, + body, + orelse: _, + } => { + // TODO: Handle while-loop else clauses let start_label = self.new_label(); let end_label = self.new_label(); self.emit(Instruction::SetupLoop { @@ -173,15 +178,16 @@ impl Compiler { }); self.set_label(end_label); } - ast::Statement::With { items, body } => { + ast::Statement::With { items: _, body: _ } => { // TODO } ast::Statement::For { target, iter, body, - orelse, + orelse: _, } => { + // TODO: Handle for loop else clauses // The thing iterated: for i in iter { self.compile_expression(i); @@ -347,8 +353,8 @@ impl Compiler { self.compile_op(op); self.compile_store(target); } - ast::Statement::Delete { targets } => { - // Remove the given names from the scope + ast::Statement::Delete { targets: _ } => { + // TODO: Remove the given names from the scope // self.emit(Instruction::DeleteName); } ast::Statement::Pass => { @@ -409,8 +415,9 @@ impl Compiler { self.compile_test(b, not_label); } ast::BooleanOperator::Or => { + // TODO: Implement boolean or // TODO: implement short circuit code by fiddeling with the labels - let end_label1 = self.new_label(); + self.new_label(); self.compile_test(a, not_label); self.compile_test(b, not_label); panic!("Not impl"); @@ -437,7 +444,7 @@ impl Compiler { } self.emit(Instruction::CallFunction { count: count }); } - ast::Expression::BoolOp { a, op, b } => { + ast::Expression::BoolOp { a: _, op: _, b: _ } => { let not_label = self.new_label(); let end_label = self.new_label(); self.compile_test(expression, not_label); diff --git a/vm/src/objdict.rs b/vm/src/objdict.rs index 3c1578bc0..0b5fbc443 100644 --- a/vm/src/objdict.rs +++ b/vm/src/objdict.rs @@ -1,7 +1,13 @@ use super::pyobject::{PyObjectRef, PyResult}; use super::vm::VirtualMachine; -pub fn set_item(vm: &mut VirtualMachine, d: PyObjectRef, idx: PyObjectRef, obj: PyObjectRef) -> PyResult { +pub fn set_item( + vm: &mut VirtualMachine, + _d: PyObjectRef, + _idx: PyObjectRef, + _obj: PyObjectRef, +) -> PyResult { + // TODO: Implement objdict::set_item Ok(vm.get_none()) } diff --git a/vm/src/objint.rs b/vm/src/objint.rs index c818ad74e..ccf23a7d7 100644 --- a/vm/src/objint.rs +++ b/vm/src/objint.rs @@ -2,7 +2,8 @@ use super::pyobject::{PyObject, PyObjectKind, PyObjectRef, PyFuncArgs}; use super::vm::VirtualMachine; use std::collections::HashMap; -fn str(vm: &mut VirtualMachine, args: PyFuncArgs) -> Result { +fn str(vm: &mut VirtualMachine, _args: PyFuncArgs) -> Result { + // TODO: Implement objint::str Ok(vm.new_str("todo".to_string())) } diff --git a/vm/src/objlist.rs b/vm/src/objlist.rs index 081bba021..67d075b33 100644 --- a/vm/src/objlist.rs +++ b/vm/src/objlist.rs @@ -22,7 +22,8 @@ pub fn set_item( } } -pub fn append(vm: &mut VirtualMachine, l: PyObjectRef, other: PyObjectRef) -> PyResult { +pub fn append(vm: &mut VirtualMachine, _l: PyObjectRef, _other: PyObjectRef) -> PyResult { + // TODO: Implement objlist::append Ok(vm.get_none()) } diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 10c6f5d8a..1a3174280 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -434,7 +434,7 @@ impl PyObject { PyObjectKind::Code { code: _ } => format!(""), PyObjectKind::Function { code: _, scope: _ } => format!(""), PyObjectKind::RustFunction { function: _ } => format!(""), - PyObjectKind::Module { ref name, ref dict } => format!("", name), + PyObjectKind::Module { ref name, dict: _ } => format!("", name), PyObjectKind::Scope { ref scope } => format!("", scope), PyObjectKind::Slice { ref start, diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 8f0f5ad47..6f18094f7 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -686,7 +686,7 @@ impl VirtualMachine { None } bytecode::Instruction::MakeFunction => { - let qualified_name = self.pop_value(); + let _qualified_name = self.pop_value(); let code_obj = self.pop_value(); // pop argc arguments // argument: name, args, globals From 340d90a3f9502bfcb259b1ddee0dbaf0fd50ffc4 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 10 Aug 2018 15:56:28 -0400 Subject: [PATCH 06/10] Refactor push_code_object to push_new_code_object The argument wasn't being used by the current implementation, so drop it. --- vm/src/compile.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/src/compile.rs b/vm/src/compile.rs index 7bc4b8509..e49fb6969 100644 --- a/vm/src/compile.rs +++ b/vm/src/compile.rs @@ -16,7 +16,7 @@ struct Compiler { pub fn compile(vm: &mut VirtualMachine, source: &String, mode: Mode) -> Result { let mut compiler = Compiler::new(); - compiler.push_code_object(CodeObject::new(Vec::new())); + compiler.push_new_code_object(); match mode { Mode::Exec => match parser::parse_program(source) { Ok(ast) => { @@ -77,7 +77,7 @@ impl Compiler { } } - fn push_code_object(&mut self, code_object: CodeObject) { + fn push_new_code_object(&mut self) { self.code_object_stack.push(CodeObject::new(Vec::new())); } From a15007f10ddab294b68d37ea9b1e40b84eb8a0e7 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 10 Aug 2018 16:11:58 -0400 Subject: [PATCH 07/10] Remove the unused and empy objint::add function --- vm/src/objint.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/vm/src/objint.rs b/vm/src/objint.rs index ccf23a7d7..a238c2b43 100644 --- a/vm/src/objint.rs +++ b/vm/src/objint.rs @@ -7,8 +7,6 @@ fn str(vm: &mut VirtualMachine, _args: PyFuncArgs) -> Result Date: Fri, 10 Aug 2018 16:12:39 -0400 Subject: [PATCH 08/10] Rename objlist::append as it is unused --- vm/src/objlist.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/src/objlist.rs b/vm/src/objlist.rs index 67d075b33..b3eb90b5a 100644 --- a/vm/src/objlist.rs +++ b/vm/src/objlist.rs @@ -22,7 +22,7 @@ pub fn set_item( } } -pub fn append(vm: &mut VirtualMachine, _l: PyObjectRef, _other: PyObjectRef) -> PyResult { +pub fn _append(vm: &mut VirtualMachine, _l: PyObjectRef, _other: PyObjectRef) -> PyResult { // TODO: Implement objlist::append Ok(vm.get_none()) } @@ -31,6 +31,6 @@ pub fn append(vm: &mut VirtualMachine, _l: PyObjectRef, _other: PyObjectRef) -> pub fn make_type() -> PyObjectRef { // dict.insert("__set_item__".to_string(), set_item); - dict.insert("append".to_string(), append) + dict.insert("append".to_string(), _append) } */ From ede453334916d69ff7e7416133a97f3a7be5c205 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 10 Aug 2018 16:13:14 -0400 Subject: [PATCH 09/10] Rename objdict::_set_item as it is unused --- vm/src/objdict.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/src/objdict.rs b/vm/src/objdict.rs index 0b5fbc443..8781777f8 100644 --- a/vm/src/objdict.rs +++ b/vm/src/objdict.rs @@ -1,7 +1,7 @@ use super::pyobject::{PyObjectRef, PyResult}; use super::vm::VirtualMachine; -pub fn set_item( +pub fn _set_item( vm: &mut VirtualMachine, _d: PyObjectRef, _idx: PyObjectRef, @@ -14,6 +14,6 @@ pub fn set_item( /* TODO: pub fn make_type() -> PyObjectRef { - // dict.insert("__set_item__".to_string(), set_item); + // dict.insert("__set_item__".to_string(), _set_item); } */ From 0b5248827b23fe8ae94f2cfceba8f807958c9d62 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 10 Aug 2018 16:27:09 -0400 Subject: [PATCH 10/10] Allow TryExcept to be dead code (for now) TryExcept is referenced by code, so I don't want to rename it, but it's never constructed so it still produces a warning. --- vm/src/frame.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vm/src/frame.rs b/vm/src/frame.rs index cab37ca3a..cdc91fcc6 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -9,6 +9,9 @@ pub enum Block { start: bytecode::Label, end: bytecode::Label, }, + // TODO: Remove this allow once TryExcept is in use + #[allow(dead_code)] + // TODO: Implement try/except blocks TryExcept, }