@@ -137,6 +137,7 @@ impl<O: OutputStream> Compiler<O> {
137137 fn push_new_code_object ( & mut self , obj_name : String ) {
138138 let line_number = self . get_source_line_number ( ) ;
139139 self . push_output ( CodeObject :: new (
140+ Default :: default ( ) ,
140141 Vec :: new ( ) ,
141142 Varargs :: None ,
142143 Vec :: new ( ) ,
@@ -595,11 +596,7 @@ impl<O: OutputStream> Compiler<O> {
595596 Ok ( ( ) )
596597 }
597598
598- fn enter_function (
599- & mut self ,
600- name : & str ,
601- args : & ast:: Parameters ,
602- ) -> Result < bytecode:: FunctionOpArg , CompileError > {
599+ fn enter_function ( & mut self , name : & str , args : & ast:: Parameters ) -> Result < ( ) , CompileError > {
603600 let have_defaults = !args. defaults . is_empty ( ) ;
604601 if have_defaults {
605602 // Construct a tuple:
@@ -633,8 +630,17 @@ impl<O: OutputStream> Compiler<O> {
633630 } ) ;
634631 }
635632
633+ let mut flags = bytecode:: CodeFlags :: default ( ) ;
634+ if have_defaults {
635+ flags |= bytecode:: CodeFlags :: HAS_DEFAULTS ;
636+ }
637+ if num_kw_only_defaults > 0 {
638+ flags |= bytecode:: CodeFlags :: HAS_KW_ONLY_DEFAULTS ;
639+ }
640+
636641 let line_number = self . get_source_line_number ( ) ;
637642 self . push_output ( CodeObject :: new (
643+ flags,
638644 args. args . iter ( ) . map ( |a| a. arg . clone ( ) ) . collect ( ) ,
639645 compile_varargs ( & args. vararg ) ,
640646 args. kwonlyargs . iter ( ) . map ( |a| a. arg . clone ( ) ) . collect ( ) ,
@@ -645,15 +651,7 @@ impl<O: OutputStream> Compiler<O> {
645651 ) ) ;
646652 self . enter_scope ( ) ;
647653
648- let mut flags = bytecode:: FunctionOpArg :: default ( ) ;
649- if have_defaults {
650- flags |= bytecode:: FunctionOpArg :: HAS_DEFAULTS ;
651- }
652- if num_kw_only_defaults > 0 {
653- flags |= bytecode:: FunctionOpArg :: HAS_KW_ONLY_DEFAULTS ;
654- }
655-
656- Ok ( flags)
654+ Ok ( ( ) )
657655 }
658656
659657 fn prepare_decorators (
@@ -813,7 +811,7 @@ impl<O: OutputStream> Compiler<O> {
813811
814812 self . prepare_decorators ( decorator_list) ?;
815813
816- let mut flags = self . enter_function ( name, args) ?;
814+ self . enter_function ( name, args) ?;
817815
818816 let ( body, doc_str) = get_doc ( body) ;
819817
@@ -832,7 +830,7 @@ impl<O: OutputStream> Compiler<O> {
832830 }
833831 }
834832
835- let code = self . pop_code_object ( ) ;
833+ let mut code = self . pop_code_object ( ) ;
836834 self . leave_scope ( ) ;
837835
838836 // Prepare type annotations:
@@ -864,7 +862,7 @@ impl<O: OutputStream> Compiler<O> {
864862 }
865863
866864 if num_annotations > 0 {
867- flags |= bytecode:: FunctionOpArg :: HAS_ANNOTATIONS ;
865+ code . flags |= bytecode:: CodeFlags :: HAS_ANNOTATIONS ;
868866 self . emit ( Instruction :: BuildMap {
869867 size : num_annotations,
870868 unpack : false ,
@@ -884,7 +882,7 @@ impl<O: OutputStream> Compiler<O> {
884882 } ) ;
885883
886884 // Turn code object into function object:
887- self . emit ( Instruction :: MakeFunction { flags } ) ;
885+ self . emit ( Instruction :: MakeFunction ) ;
888886 self . store_docstring ( doc_str) ;
889887 self . apply_decorators ( decorator_list) ;
890888
@@ -915,6 +913,7 @@ impl<O: OutputStream> Compiler<O> {
915913 self . emit ( Instruction :: LoadBuildClass ) ;
916914 let line_number = self . get_source_line_number ( ) ;
917915 self . push_output ( CodeObject :: new (
916+ Default :: default ( ) ,
918917 vec ! [ ] ,
919918 Varargs :: None ,
920919 vec ! [ ] ,
@@ -950,7 +949,8 @@ impl<O: OutputStream> Compiler<O> {
950949 } ) ;
951950 self . emit ( Instruction :: ReturnValue ) ;
952951
953- let code = self . pop_code_object ( ) ;
952+ let mut code = self . pop_code_object ( ) ;
953+ code. flags &= !bytecode:: CodeFlags :: NEW_LOCALS ;
954954 self . leave_scope ( ) ;
955955
956956 self . emit ( Instruction :: LoadConst {
@@ -965,9 +965,7 @@ impl<O: OutputStream> Compiler<O> {
965965 } ) ;
966966
967967 // Turn code object into function object:
968- self . emit ( Instruction :: MakeFunction {
969- flags : bytecode:: FunctionOpArg :: default ( ) & !bytecode:: FunctionOpArg :: NEW_LOCALS ,
970- } ) ;
968+ self . emit ( Instruction :: MakeFunction ) ;
971969
972970 self . emit ( Instruction :: LoadConst {
973971 value : bytecode:: Constant :: String {
@@ -1615,7 +1613,7 @@ impl<O: OutputStream> Compiler<O> {
16151613 Lambda { args, body } => {
16161614 let name = "<lambda>" . to_string ( ) ;
16171615 // no need to worry about the self.loop_depth because there are no loops in lambda expressions
1618- let flags = self . enter_function ( & name, args) ?;
1616+ self . enter_function ( & name, args) ?;
16191617 self . compile_expression ( body) ?;
16201618 self . emit ( Instruction :: ReturnValue ) ;
16211619 let code = self . pop_code_object ( ) ;
@@ -1629,7 +1627,7 @@ impl<O: OutputStream> Compiler<O> {
16291627 value : bytecode:: Constant :: String { value : name } ,
16301628 } ) ;
16311629 // Turn code object into function object:
1632- self . emit ( Instruction :: MakeFunction { flags } ) ;
1630+ self . emit ( Instruction :: MakeFunction ) ;
16331631 }
16341632 Comprehension { kind, generators } => {
16351633 self . compile_comprehension ( kind, generators) ?;
@@ -1810,6 +1808,7 @@ impl<O: OutputStream> Compiler<O> {
18101808 let line_number = self . get_source_line_number ( ) ;
18111809 // Create magnificent function <listcomp>:
18121810 self . push_output ( CodeObject :: new (
1811+ Default :: default ( ) ,
18131812 vec ! [ ".0" . to_string( ) ] ,
18141813 Varargs :: None ,
18151814 vec ! [ ] ,
@@ -1945,9 +1944,7 @@ impl<O: OutputStream> Compiler<O> {
19451944 } ) ;
19461945
19471946 // Turn code object into function object:
1948- self . emit ( Instruction :: MakeFunction {
1949- flags : bytecode:: FunctionOpArg :: default ( ) ,
1950- } ) ;
1947+ self . emit ( Instruction :: MakeFunction ) ;
19511948
19521949 // Evaluate iterated item:
19531950 self . compile_expression ( & generators[ 0 ] . iter ) ?;
0 commit comments