44
55use std:: char;
66use std:: io:: { self , Write } ;
7+ use std:: str;
78
89use num_bigint:: Sign ;
910use num_traits:: { Signed , Zero } ;
1011
1112use crate :: compile;
1213use crate :: obj:: objbool;
14+ use crate :: obj:: objbytes:: PyBytesRef ;
1315use crate :: obj:: objcode:: PyCodeRef ;
1416use crate :: obj:: objdict:: PyDictRef ;
1517use crate :: obj:: objint:: { self , PyIntRef } ;
@@ -20,7 +22,7 @@ use crate::obj::objtype::{self, PyClassRef};
2022use crate :: frame:: Scope ;
2123use crate :: function:: { single_or_tuple_any, Args , KwArgs , OptionalArg , PyFuncArgs } ;
2224use crate :: pyobject:: {
23- IdProtocol , IntoPyObject , ItemProtocol , PyIterable , PyObjectRef , PyResult , PyValue ,
25+ Either , IdProtocol , IntoPyObject , ItemProtocol , PyIterable , PyObjectRef , PyResult , PyValue ,
2426 TryFromObject , TypeProtocol ,
2527} ;
2628use crate :: vm:: VirtualMachine ;
@@ -78,13 +80,19 @@ fn builtin_chr(i: u32, vm: &VirtualMachine) -> PyResult<String> {
7880}
7981
8082fn builtin_compile (
81- source : PyStringRef ,
83+ source : Either < PyStringRef , PyBytesRef > ,
8284 filename : PyStringRef ,
8385 mode : PyStringRef ,
8486 vm : & VirtualMachine ,
8587) -> PyResult < PyCodeRef > {
88+ // TODO: compile::compile should probably get bytes
89+ let source = match source {
90+ Either :: A ( string) => string. value . to_string ( ) ,
91+ Either :: B ( bytes) => str:: from_utf8 ( & bytes) . unwrap ( ) . to_string ( ) ,
92+ } ;
93+
8694 // TODO: fix this newline bug:
87- let source = format ! ( "{}\n " , & source. value ) ;
95+ let source = format ! ( "{}\n " , source) ;
8896
8997 let mode = {
9098 let mode = & mode. value ;
0 commit comments