@@ -23,11 +23,7 @@ struct Compiler {
2323}
2424
2525/// Compile a given sourcecode into a bytecode object.
26- pub fn compile (
27- source : & str ,
28- mode : & Mode ,
29- source_path : Option < String > ,
30- ) -> Result < CodeObject , CompileError > {
26+ pub fn compile ( source : & str , mode : & Mode , source_path : String ) -> Result < CodeObject , CompileError > {
3127 match mode {
3228 Mode :: Exec => {
3329 let ast = parser:: parse_program ( source) ?;
@@ -46,11 +42,11 @@ pub fn compile(
4642
4743/// A helper function for the shared code of the different compile functions
4844fn with_compiler (
49- source_path : Option < String > ,
45+ source_path : String ,
5046 f : impl FnOnce ( & mut Compiler ) -> Result < ( ) , CompileError > ,
5147) -> Result < CodeObject , CompileError > {
5248 let mut compiler = Compiler :: new ( ) ;
53- compiler. source_path = source_path;
49+ compiler. source_path = Some ( source_path) ;
5450 compiler. push_new_code_object ( "<module>" . to_string ( ) ) ;
5551 f ( & mut compiler) ?;
5652 let code = compiler. pop_code_object ( ) ;
@@ -59,10 +55,7 @@ fn with_compiler(
5955}
6056
6157/// Compile a standard Python program to bytecode
62- pub fn compile_program (
63- ast : ast:: Program ,
64- source_path : Option < String > ,
65- ) -> Result < CodeObject , CompileError > {
58+ pub fn compile_program ( ast : ast:: Program , source_path : String ) -> Result < CodeObject , CompileError > {
6659 with_compiler ( source_path, |compiler| {
6760 let symbol_table = make_symbol_table ( & ast) ?;
6861 compiler. compile_program ( & ast, symbol_table)
@@ -72,7 +65,7 @@ pub fn compile_program(
7265/// Compile a single Python expression to bytecode
7366pub fn compile_statement_eval (
7467 statement : Vec < ast:: LocatedStatement > ,
75- source_path : Option < String > ,
68+ source_path : String ,
7669) -> Result < CodeObject , CompileError > {
7770 with_compiler ( source_path, |compiler| {
7871 let symbol_table = statements_to_symbol_table ( & statement) ?;
@@ -83,7 +76,7 @@ pub fn compile_statement_eval(
8376/// Compile a Python program to bytecode for the context of a REPL
8477pub fn compile_program_single (
8578 ast : ast:: Program ,
86- source_path : Option < String > ,
79+ source_path : String ,
8780) -> Result < CodeObject , CompileError > {
8881 with_compiler ( source_path, |compiler| {
8982 let symbol_table = make_symbol_table ( & ast) ?;
@@ -126,7 +119,7 @@ impl Compiler {
126119 Varargs :: None ,
127120 Vec :: new ( ) ,
128121 Varargs :: None ,
129- self . source_path . clone ( ) ,
122+ self . source_path . clone ( ) . unwrap ( ) ,
130123 line_number,
131124 obj_name,
132125 ) ) ;
@@ -603,7 +596,7 @@ impl Compiler {
603596 Varargs :: from ( & args. vararg ) ,
604597 args. kwonlyargs . iter ( ) . map ( |a| a. arg . clone ( ) ) . collect ( ) ,
605598 Varargs :: from ( & args. kwarg ) ,
606- self . source_path . clone ( ) ,
599+ self . source_path . clone ( ) . unwrap ( ) ,
607600 line_number,
608601 name. to_string ( ) ,
609602 ) ) ;
@@ -856,7 +849,7 @@ impl Compiler {
856849 Varargs :: None ,
857850 vec ! [ ] ,
858851 Varargs :: None ,
859- self . source_path . clone ( ) ,
852+ self . source_path . clone ( ) . unwrap ( ) ,
860853 line_number,
861854 name. to_string ( ) ,
862855 ) ) ;
@@ -1578,7 +1571,7 @@ impl Compiler {
15781571 Varargs :: None ,
15791572 vec ! [ ] ,
15801573 Varargs :: None ,
1581- self . source_path . clone ( ) ,
1574+ self . source_path . clone ( ) . unwrap ( ) ,
15821575 line_number,
15831576 name. clone ( ) ,
15841577 ) ) ;
0 commit comments