@@ -435,9 +435,11 @@ func (c *compiler) Jump(Op vm.OpCode, Dest *Label) {
435
435
c .OpCodes .Add (instr )
436
436
}
437
437
438
- /* The test for LOCAL must come before the test for FREE in order to
439
- handle classes where name is both local and free. The local var is
440
- a method and the free var is a free var referenced within a method.
438
+ /*
439
+ The test for LOCAL must come before the test for FREE in order to
440
+
441
+ handle classes where name is both local and free. The local var is
442
+ a method and the free var is a free var referenced within a method.
441
443
*/
442
444
func (c * compiler ) getRefType (name string ) symtable.Scope {
443
445
if c .scopeType == compilerScopeClass && name == "__class__" {
@@ -666,27 +668,31 @@ func (c *compiler) class(Ast ast.Ast, class *ast.ClassDef) {
666
668
}
667
669
668
670
/*
669
- Implements the with statement from PEP 343.
670
-
671
- The semantics outlined in that PEP are as follows:
672
-
673
- with EXPR as VAR:
674
- BLOCK
675
-
676
- It is implemented roughly as:
677
-
678
- context = EXPR
679
- exit = context.__exit__ # not calling it
680
- value = context.__enter__()
681
- try:
682
- VAR = value # if VAR present in the syntax
683
- BLOCK
684
- finally:
685
- if an exception was raised:
686
- exc = copy of (exception, instance, traceback)
687
- else:
688
- exc = (None, None, None)
689
- exit(*exc)
671
+ Implements the with statement from PEP 343.
672
+
673
+ The semantics outlined in that PEP are as follows:
674
+
675
+ with EXPR as VAR:
676
+
677
+ BLOCK
678
+
679
+ It is implemented roughly as:
680
+
681
+ context = EXPR
682
+ exit = context.__exit__ # not calling it
683
+ value = context.__enter__()
684
+ try:
685
+
686
+ VAR = value # if VAR present in the syntax
687
+ BLOCK
688
+
689
+ finally:
690
+
691
+ if an exception was raised:
692
+ exc = copy of (exception, instance, traceback)
693
+ else:
694
+ exc = (None, None, None)
695
+ exit(*exc)
690
696
*/
691
697
func (c * compiler ) with (node * ast.With , pos int ) {
692
698
item := node .Items [pos ]
@@ -728,37 +734,38 @@ func (c *compiler) with(node *ast.With, pos int) {
728
734
c .Op (vm .END_FINALLY )
729
735
}
730
736
731
- /* Code generated for "try: <body> finally: <finalbody>" is as follows:
732
-
733
- SETUP_FINALLY L
734
- <code for body>
735
- POP_BLOCK
736
- LOAD_CONST <None>
737
- L: <code for finalbody>
738
- END_FINALLY
739
-
740
- The special instructions use the block stack. Each block
741
- stack entry contains the instruction that created it (here
742
- SETUP_FINALLY), the level of the value stack at the time the
743
- block stack entry was created, and a label (here L).
744
-
745
- SETUP_FINALLY:
746
- Pushes the current value stack level and the label
747
- onto the block stack.
748
- POP_BLOCK:
749
- Pops en entry from the block stack, and pops the value
750
- stack until its level is the same as indicated on the
751
- block stack. (The label is ignored.)
752
- END_FINALLY:
753
- Pops a variable number of entries from the *value* stack
754
- and re-raises the exception they specify. The number of
755
- entries popped depends on the (pseudo) exception type.
756
-
757
- The block stack is unwound when an exception is raised:
758
- when a SETUP_FINALLY entry is found, the exception is pushed
759
- onto the value stack (and the exception condition is cleared),
760
- and the interpreter jumps to the label gotten from the block
761
- stack.
737
+ /*
738
+ Code generated for "try: <body> finally: <finalbody>" is as follows:
739
+
740
+ SETUP_FINALLY L
741
+ <code for body>
742
+ POP_BLOCK
743
+ LOAD_CONST <None>
744
+ L: <code for finalbody>
745
+ END_FINALLY
746
+
747
+ The special instructions use the block stack. Each block
748
+ stack entry contains the instruction that created it (here
749
+ SETUP_FINALLY), the level of the value stack at the time the
750
+ block stack entry was created, and a label (here L).
751
+
752
+ SETUP_FINALLY:
753
+ Pushes the current value stack level and the label
754
+ onto the block stack.
755
+ POP_BLOCK:
756
+ Pops en entry from the block stack, and pops the value
757
+ stack until its level is the same as indicated on the
758
+ block stack. (The label is ignored.)
759
+ END_FINALLY:
760
+ Pops a variable number of entries from the *value* stack
761
+ and re-raises the exception they specify. The number of
762
+ entries popped depends on the (pseudo) exception type.
763
+
764
+ The block stack is unwound when an exception is raised:
765
+ when a SETUP_FINALLY entry is found, the exception is pushed
766
+ onto the value stack (and the exception condition is cleared),
767
+ and the interpreter jumps to the label gotten from the block
768
+ stack.
762
769
*/
763
770
func (c * compiler ) tryFinally (node * ast.Try ) {
764
771
end := new (Label )
@@ -780,35 +787,36 @@ func (c *compiler) tryFinally(node *ast.Try) {
780
787
}
781
788
782
789
/*
783
- Code generated for "try: S except E1 as V1: S1 except E2 as V2: S2 ...":
784
- (The contents of the value stack is shown in [], with the top
785
- at the right; 'tb' is trace-back info, 'val' the exception's
786
- associated value, and 'exc' the exception.)
787
-
788
- Value stack Label Instruction Argument
789
- [] SETUP_EXCEPT L1
790
- [] <code for S>
791
- [] POP_BLOCK
792
- [] JUMP_FORWARD L0
793
-
794
- [tb, val, exc] L1: DUP )
795
- [tb, val, exc, exc] <evaluate E1> )
796
- [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1
797
- [tb, val, exc, 1-or-0] POP_JUMP_IF_FALSE L2 )
798
- [tb, val, exc] POP
799
- [tb, val] <assign to V1> (or POP if no V1)
800
- [tb] POP
801
- [] <code for S1>
802
- JUMP_FORWARD L0
803
-
804
- [tb, val, exc] L2: DUP
805
- .............................etc.......................
806
-
807
- [tb, val, exc] Ln+1: END_FINALLY # re-raise exception
808
-
809
- [] L0: <next statement>
810
-
811
- Of course, parts are not generated if Vi or Ei is not present.
790
+ Code generated for "try: S except E1 as V1: S1 except E2 as V2: S2 ...":
791
+ (The contents of the value stack is shown in [], with the top
792
+ at the right; 'tb' is trace-back info, 'val' the exception's
793
+ associated value, and 'exc' the exception.)
794
+
795
+ Value stack Label Instruction Argument
796
+ [] SETUP_EXCEPT L1
797
+ [] <code for S>
798
+ [] POP_BLOCK
799
+ [] JUMP_FORWARD L0
800
+
801
+ [tb, val, exc] L1: DUP )
802
+ [tb, val, exc, exc] <evaluate E1> )
803
+ [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1
804
+ [tb, val, exc, 1-or-0] POP_JUMP_IF_FALSE L2 )
805
+ [tb, val, exc] POP
806
+ [tb, val] <assign to V1> (or POP if no V1)
807
+ [tb] POP
808
+ [] <code for S1>
809
+
810
+ JUMP_FORWARD L0
811
+
812
+ [tb, val, exc] L2: DUP
813
+ .............................etc.......................
814
+
815
+ [tb, val, exc] Ln+1: END_FINALLY # re-raise exception
816
+
817
+ [] L0: <next statement>
818
+
819
+ Of course, parts are not generated if Vi or Ei is not present.
812
820
*/
813
821
func (c * compiler ) tryExcept (node * ast.Try ) {
814
822
c .loops .Push (loop {Type : exceptLoop })
@@ -897,11 +905,13 @@ func (c *compiler) try(node *ast.Try) {
897
905
}
898
906
}
899
907
900
- /* The IMPORT_NAME opcode was already generated. This function
901
- merely needs to bind the result to a name.
908
+ /*
909
+ The IMPORT_NAME opcode was already generated. This function
910
+
911
+ merely needs to bind the result to a name.
902
912
903
- If there is a dot in name, we need to split it and emit a
904
- LOAD_ATTR for each name.
913
+ If there is a dot in name, we need to split it and emit a
914
+ LOAD_ATTR for each name.
905
915
*/
906
916
func (c * compiler ) importAs (name ast.Identifier , asname ast.Identifier ) {
907
917
attrs := strings .Split (string (name ), "." )
@@ -913,12 +923,14 @@ func (c *compiler) importAs(name ast.Identifier, asname ast.Identifier) {
913
923
c .NameOp (string (asname ), ast .Store )
914
924
}
915
925
916
- /* The Import node stores a module name like a.b.c as a single
917
- string. This is convenient for all cases except
918
- import a.b.c as d
919
- where we need to parse that string to extract the individual
920
- module names.
921
- XXX Perhaps change the representation to make this case simpler?
926
+ /*
927
+ The Import node stores a module name like a.b.c as a single
928
+
929
+ string. This is convenient for all cases except
930
+ import a.b.c as d
931
+ where we need to parse that string to extract the individual
932
+ module names.
933
+ XXX Perhaps change the representation to make this case simpler?
922
934
*/
923
935
func (c * compiler ) import_ (node * ast.Import ) {
924
936
//n = asdl_seq_LEN(s.v.Import.names);
@@ -1394,7 +1406,9 @@ func (c *compiler) callHelper(n int, Args []ast.Expr, Keywords []*ast.Keyword, S
1394
1406
c .OpArg (op , uint32 (args + kwargs << 8 ))
1395
1407
}
1396
1408
1397
- /* List and set comprehensions and generator expressions work by creating a
1409
+ /*
1410
+ List and set comprehensions and generator expressions work by creating a
1411
+
1398
1412
nested function to perform the actual iteration. This means that the
1399
1413
iteration variables don't leak into the current scope.
1400
1414
The defined function is called immediately following its definition, with the
0 commit comments