@@ -435,9 +435,11 @@ func (c *compiler) Jump(Op vm.OpCode, Dest *Label) {
435435 c .OpCodes .Add (instr )
436436}
437437
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.
441443*/
442444func (c * compiler ) getRefType (name string ) symtable.Scope {
443445 if c .scopeType == compilerScopeClass && name == "__class__" {
@@ -666,27 +668,31 @@ func (c *compiler) class(Ast ast.Ast, class *ast.ClassDef) {
666668}
667669
668670/*
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)
690696*/
691697func (c * compiler ) with (node * ast.With , pos int ) {
692698 item := node .Items [pos ]
@@ -728,37 +734,38 @@ func (c *compiler) with(node *ast.With, pos int) {
728734 c .Op (vm .END_FINALLY )
729735}
730736
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.
762769*/
763770func (c * compiler ) tryFinally (node * ast.Try ) {
764771 end := new (Label )
@@ -780,35 +787,36 @@ func (c *compiler) tryFinally(node *ast.Try) {
780787}
781788
782789/*
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.
812820*/
813821func (c * compiler ) tryExcept (node * ast.Try ) {
814822 c .loops .Push (loop {Type : exceptLoop })
@@ -897,11 +905,13 @@ func (c *compiler) try(node *ast.Try) {
897905 }
898906}
899907
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.
902912
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.
905915*/
906916func (c * compiler ) importAs (name ast.Identifier , asname ast.Identifier ) {
907917 attrs := strings .Split (string (name ), "." )
@@ -913,12 +923,14 @@ func (c *compiler) importAs(name ast.Identifier, asname ast.Identifier) {
913923 c .NameOp (string (asname ), ast .Store )
914924}
915925
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?
922934*/
923935func (c * compiler ) import_ (node * ast.Import ) {
924936 //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
13941406 c .OpArg (op , uint32 (args + kwargs << 8 ))
13951407}
13961408
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+
13981412nested function to perform the actual iteration. This means that the
13991413iteration variables don't leak into the current scope.
14001414The defined function is called immediately following its definition, with the
0 commit comments