Mercurial > python-compiler.rs
changeset 87:624393ed3b0b
Don’t cast anything to str, except Num for now.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 22 Jun 2016 23:05:24 +0100 |
parents | a7b1db623f41 |
children | 5923cd4bfc36 |
files | src/ast_convert.rs |
diffstat | 1 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -4,6 +4,10 @@ use cpython::{Python, PyObject, PyBool, use cpython::ObjectProtocol; //for call method fn get_str(py: Python, object: PyObject) -> String { + object.extract(py).unwrap() +} + +fn convert_to_str(py: Python, object: PyObject) -> String { let pystring = object.str(py).unwrap(); let mut string = pystring.to_string(py).unwrap(); string.to_mut().to_string() @@ -384,7 +388,9 @@ fn parse_expr(py: Python, ast: PyObject) expr::NameConstant(constant) } else if is_instance(&ast, &num_type) { let n = ast.getattr(py, "n").unwrap(); - let n = get_str(py, n); + // FIXME: we should convert these to either bigint, double or complex. + // TODO: find a suitable bigint library. + let n = convert_to_str(py, n); expr::Num(n) } else if is_instance(&ast, &str_type) { let s = ast.getattr(py, "s").unwrap();