Merge pull request #56 from OddBloke/warnings

Fix all current warnings
This commit is contained in:
cthulahoops authored and GitHub committed 2018-08-10 22:02:32 +01:00
commit 8bda921856
8 files changed
+42 -42

No files matched your search

+5 -2
View File
@@ -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 {
+16 -9
View File
@@ -16,7 +16,7 @@ struct Compiler {
pub fn compile(vm: &mut VirtualMachine, source: &String, mode: Mode) -> Result<PyObjectRef, String> {
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);
+3
View File
@@ -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,
}
+8 -2
View File
@@ -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);
}
*/
+2 -3
View File
@@ -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<PyObjectRef, PyObjectRef> {
fn str(vm: &mut VirtualMachine, _args: PyFuncArgs) -> Result<PyObjectRef, PyObjectRef> {
// 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);
+3 -2
View File
@@ -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)
}
*/
+1 -4
View File
@@ -434,7 +434,7 @@ impl PyObject {
PyObjectKind::Code { code: _ } => format!("<code>"),
PyObjectKind::Function { code: _, scope: _ } => format!("<func>"),
PyObjectKind::RustFunction { function: _ } => format!("<rustfunc>"),
PyObjectKind::Module { ref name, ref dict } => format!("<module '{}'>", name),
PyObjectKind::Module { ref name, dict: _ } => format!("<module '{}'>", name),
PyObjectKind::Scope { ref scope } => format!("<scope '{:?}'>", 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 },
+4 -20
View File
@@ -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