@@ -706,13 +706,34 @@ impl Compiler {
706
706
line_number,
707
707
name. to_string ( ) ,
708
708
) ) ;
709
- self . compile_statements ( body) ?;
709
+
710
+ let doc = get_doc ( body) ;
711
+ let ( new_body, doc_str) = match doc {
712
+ Some ( val) => {
713
+ if let Some ( ( _, body_rest) ) = body. split_first ( ) {
714
+ ( body_rest, val)
715
+ } else {
716
+ ( body, "" . to_string ( ) )
717
+ }
718
+ }
719
+ None => ( body, "" . to_string ( ) ) ,
720
+ } ;
721
+
722
+ self . compile_statements ( new_body) ?;
710
723
self . emit ( Instruction :: LoadConst {
711
724
value : bytecode:: Constant :: None ,
712
725
} ) ;
713
726
self . emit ( Instruction :: ReturnValue ) ;
714
727
715
728
let code = self . pop_code_object ( ) ;
729
+
730
+ // function doc
731
+ self . emit ( Instruction :: LoadConst {
732
+ value : bytecode:: Constant :: String {
733
+ value : "" . to_string ( ) ,
734
+ } ,
735
+ } ) ;
736
+
716
737
self . emit ( Instruction :: LoadConst {
717
738
value : bytecode:: Constant :: Code {
718
739
code : Box :: new ( code) ,
@@ -735,6 +756,11 @@ impl Compiler {
735
756
} ,
736
757
} ) ;
737
758
759
+ // class doc
760
+ self . emit ( Instruction :: LoadConst {
761
+ value : bytecode:: Constant :: String { value : doc_str } ,
762
+ } ) ;
763
+
738
764
for base in bases {
739
765
self . compile_expression ( base) ?;
740
766
}
@@ -759,11 +785,11 @@ impl Compiler {
759
785
} ,
760
786
} ) ;
761
787
self . emit ( Instruction :: CallFunction {
762
- typ : CallType :: Keyword ( 2 + keywords. len ( ) + bases. len ( ) ) ,
788
+ typ : CallType :: Keyword ( 3 + keywords. len ( ) + bases. len ( ) ) ,
763
789
} ) ;
764
790
} else {
765
791
self . emit ( Instruction :: CallFunction {
766
- typ : CallType :: Positional ( 2 + bases. len ( ) ) ,
792
+ typ : CallType :: Positional ( 3 + bases. len ( ) ) ,
767
793
} ) ;
768
794
}
769
795
@@ -1142,6 +1168,14 @@ impl Compiler {
1142
1168
self . compile_expression ( body) ?;
1143
1169
self . emit ( Instruction :: ReturnValue ) ;
1144
1170
let code = self . pop_code_object ( ) ;
1171
+
1172
+ // function doc
1173
+ self . emit ( Instruction :: LoadConst {
1174
+ value : bytecode:: Constant :: String {
1175
+ value : "" . to_string ( ) ,
1176
+ } ,
1177
+ } ) ;
1178
+
1145
1179
self . emit ( Instruction :: LoadConst {
1146
1180
value : bytecode:: Constant :: Code {
1147
1181
code : Box :: new ( code) ,
@@ -1428,6 +1462,13 @@ impl Compiler {
1428
1462
// Fetch code for listcomp function:
1429
1463
let code = self . pop_code_object ( ) ;
1430
1464
1465
+ // function doc
1466
+ self . emit ( Instruction :: LoadConst {
1467
+ value : bytecode:: Constant :: String {
1468
+ value : "" . to_string ( ) ,
1469
+ } ,
1470
+ } ) ;
1471
+
1431
1472
// List comprehension code:
1432
1473
self . emit ( Instruction :: LoadConst {
1433
1474
value : bytecode:: Constant :: Code {
0 commit comments