diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index 3d6a6b44e..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 } @@ -161,10 +162,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 { diff --git a/vm/src/compile.rs b/vm/src/compile.rs index b9fe4c291..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())); } @@ -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/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, } diff --git a/vm/src/objdict.rs b/vm/src/objdict.rs index 3c1578bc0..8781777f8 100644 --- a/vm/src/objdict.rs +++ b/vm/src/objdict.rs @@ -1,13 +1,19 @@ 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()) } /* TODO: pub fn make_type() -> PyObjectRef { - // dict.insert("__set_item__".to_string(), set_item); + // dict.insert("__set_item__".to_string(), _set_item); } */ diff --git a/vm/src/objint.rs b/vm/src/objint.rs index c818ad74e..a238c2b43 100644 --- a/vm/src/objint.rs +++ b/vm/src/objint.rs @@ -2,12 +2,11 @@ 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())) } -fn add() {} - /* fn set_attr(a: &mut PyObjectRef, name: String, b: PyObjectRef) { a.borrow().dict.insert(name, b); diff --git a/vm/src/objlist.rs b/vm/src/objlist.rs index 081bba021..b3eb90b5a 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()) } @@ -30,6 +31,6 @@ pub fn append(vm: &mut VirtualMachine, l: PyObjectRef, other: PyObjectRef) -> Py 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) } */ diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 76d442d8c..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, @@ -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 }, diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 3233eb379..6f18094f7 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; @@ -42,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) @@ -702,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