@@ -127,16 +127,20 @@ pub fn compile_top(
127127 }
128128}
129129
130- macro_rules! compile_impl {
131- ( $ast: expr, $source_path: expr, $opts: expr, $st: ident, $compile: ident) => { {
132- let symbol_table = match $st( $ast) {
133- Ok ( x) => x,
134- Err ( e) => return Err ( e. into_compile_error( $source_path) ) ,
135- } ;
136- with_compiler( $source_path, $opts, |compiler| {
137- compiler. $compile( $ast, symbol_table)
138- } )
139- } } ;
130+ fn compile_impl < Ast : ?Sized > (
131+ ast : & Ast ,
132+ source_path : String ,
133+ opts : CompileOpts ,
134+ make_symbol_table : fn ( & Ast ) -> Result < SymbolTable , symboltable:: SymbolTableError > ,
135+ compile : fn ( & mut Compiler , & Ast , SymbolTable ) -> CompileResult < ( ) > ,
136+ ) -> CompileResult < CodeObject > {
137+ let symbol_table = match make_symbol_table ( ast) {
138+ Ok ( x) => x,
139+ Err ( e) => return Err ( e. into_compile_error ( source_path) ) ,
140+ } ;
141+ with_compiler ( source_path, opts, |compiler| {
142+ compile ( compiler, ast, symbol_table)
143+ } )
140144}
141145
142146/// Compile a standard Python program to bytecode
@@ -145,7 +149,13 @@ pub fn compile_program(
145149 source_path : String ,
146150 opts : CompileOpts ,
147151) -> CompileResult < CodeObject > {
148- compile_impl ! ( ast, source_path, opts, make_symbol_table, compile_program)
152+ compile_impl (
153+ ast,
154+ source_path,
155+ opts,
156+ make_symbol_table,
157+ Compiler :: compile_program,
158+ )
149159}
150160
151161/// Compile a Python program to bytecode for the context of a REPL
@@ -154,12 +164,12 @@ pub fn compile_program_single(
154164 source_path : String ,
155165 opts : CompileOpts ,
156166) -> CompileResult < CodeObject > {
157- compile_impl ! (
167+ compile_impl (
158168 ast,
159169 source_path,
160170 opts,
161171 make_symbol_table,
162- compile_program_single
172+ Compiler :: compile_program_single,
163173 )
164174}
165175
@@ -168,7 +178,13 @@ pub fn compile_expression(
168178 source_path : String ,
169179 opts : CompileOpts ,
170180) -> CompileResult < CodeObject > {
171- compile_impl ! ( ast, source_path, opts, make_symbol_table_expr, compile_eval)
181+ compile_impl (
182+ ast,
183+ source_path,
184+ opts,
185+ make_symbol_table_expr,
186+ Compiler :: compile_eval,
187+ )
172188}
173189
174190impl Compiler {
0 commit comments