|
6 | 6 | * https://github.com/micropython/micropython/blob/master/py/compile.c
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -extern crate rustpython_parser; |
10 |
| - |
11 |
| -use self::rustpython_parser::{ast, parser}; |
12 | 9 | use super::bytecode::{self, CallType, CodeObject, Instruction};
|
13 | 10 | use super::pyobject::{PyObject, PyObjectKind, PyResult};
|
14 | 11 | use super::vm::VirtualMachine;
|
| 12 | +use num_complex::Complex64; |
| 13 | +use rustpython_parser::{ast, parser}; |
15 | 14 |
|
16 | 15 | struct Compiler {
|
17 | 16 | code_object_stack: Vec<CodeObject>,
|
@@ -846,6 +845,9 @@ impl Compiler {
|
846 | 845 | let const_value = match value {
|
847 | 846 | ast::Number::Integer { value } => bytecode::Constant::Integer { value: *value },
|
848 | 847 | ast::Number::Float { value } => bytecode::Constant::Float { value: *value },
|
| 848 | + ast::Number::Complex { real, imag } => bytecode::Constant::Complex { |
| 849 | + value: Complex64::new(*real, *imag), |
| 850 | + }, |
849 | 851 | };
|
850 | 852 | self.emit(Instruction::LoadConst { value: const_value });
|
851 | 853 | }
|
@@ -1301,8 +1303,8 @@ mod tests {
|
1301 | 1303 | use super::bytecode::CodeObject;
|
1302 | 1304 | use super::bytecode::Constant::*;
|
1303 | 1305 | use super::bytecode::Instruction::*;
|
1304 |
| - use super::rustpython_parser::parser; |
1305 | 1306 | use super::Compiler;
|
| 1307 | + use rustpython_parser::parser; |
1306 | 1308 | fn compile_exec(source: &str) -> CodeObject {
|
1307 | 1309 | let mut compiler = Compiler::new();
|
1308 | 1310 | compiler.push_new_code_object(Option::None, "<module>".to_string());
|
|
0 commit comments