Skip to content

Commit 38b2e3c

Browse files
committed
all: apply gofmt
Signed-off-by: Sebastien Binet <[email protected]>
1 parent 01af0fe commit 38b2e3c

File tree

12 files changed

+335
-295
lines changed

12 files changed

+335
-295
lines changed

compile/compile.go

+109-95
Original file line numberDiff line numberDiff line change
@@ -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
*/
442444
func (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
*/
691697
func (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
*/
763770
func (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
*/
813821
func (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
*/
906916
func (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
*/
923935
func (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+
13981412
nested function to perform the actual iteration. This means that the
13991413
iteration variables don't leak into the current scope.
14001414
The defined function is called immediately following its definition, with the

parser/y.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/exception.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func ExceptionGivenMatches(err, exc Object) bool {
330330

331331
// IsException matches the result of recover to an exception
332332
//
333-
// For use to catch a single python exception from go code
333+
// # For use to catch a single python exception from go code
334334
//
335335
// It can be an instance or the class itself
336336
func IsException(exception *Type, r interface{}) bool {

py/frame.go

+26-24
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,18 @@ func (f *Frame) PopBlock() {
158158
}
159159
}
160160

161-
/* Convert between "fast" version of locals and dictionary version.
161+
/*
162+
Convert between "fast" version of locals and dictionary version.
162163
163-
map and values are input arguments. map is a tuple of strings.
164-
values is an array of PyObject*. At index i, map[i] is the name of
165-
the variable with value values[i]. The function copies the first
166-
nmap variable from map/values into dict. If values[i] is NULL,
167-
the variable is deleted from dict.
164+
map and values are input arguments. map is a tuple of strings.
165+
values is an array of PyObject*. At index i, map[i] is the name of
166+
the variable with value values[i]. The function copies the first
167+
nmap variable from map/values into dict. If values[i] is NULL,
168+
the variable is deleted from dict.
168169
169-
If deref is true, then the values being copied are cell variables
170-
and the value is extracted from the cell variable before being put
171-
in dict.
170+
If deref is true, then the values being copied are cell variables
171+
and the value is extracted from the cell variable before being put
172+
in dict.
172173
*/
173174
func map_to_dict(mapping []string, nmap int, dict StringDict, values []Object, deref bool) {
174175
for j := nmap - 1; j >= 0; j-- {
@@ -189,25 +190,26 @@ func map_to_dict(mapping []string, nmap int, dict StringDict, values []Object, d
189190
}
190191
}
191192

192-
/* Copy values from the "locals" dict into the fast locals.
193+
/*
194+
Copy values from the "locals" dict into the fast locals.
193195
194-
dict is an input argument containing string keys representing
195-
variables names and arbitrary PyObject* as values.
196+
dict is an input argument containing string keys representing
197+
variables names and arbitrary PyObject* as values.
196198
197-
mapping and values are input arguments. mapping is a tuple of strings.
198-
values is an array of PyObject*. At index i, mapping[i] is the name of
199-
the variable with value values[i]. The function copies the first
200-
nmap variable from mapping/values into dict. If values[i] is nil,
201-
the variable is deleted from dict.
199+
mapping and values are input arguments. mapping is a tuple of strings.
200+
values is an array of PyObject*. At index i, mapping[i] is the name of
201+
the variable with value values[i]. The function copies the first
202+
nmap variable from mapping/values into dict. If values[i] is nil,
203+
the variable is deleted from dict.
202204
203-
If deref is true, then the values being copied are cell variables
204-
and the value is extracted from the cell variable before being put
205-
in dict. If clear is true, then variables in mapping but not in dict
206-
are set to nil in mapping; if clear is false, variables missing in
207-
dict are ignored.
205+
If deref is true, then the values being copied are cell variables
206+
and the value is extracted from the cell variable before being put
207+
in dict. If clear is true, then variables in mapping but not in dict
208+
are set to nil in mapping; if clear is false, variables missing in
209+
dict are ignored.
208210
209-
Exceptions raised while modifying the dict are silently ignored,
210-
because there is no good way to report them.
211+
Exceptions raised while modifying the dict are silently ignored,
212+
because there is no good way to report them.
211213
*/
212214
func dict_to_map(mapping []string, nmap int, dict StringDict, values []Object, deref bool, clear bool) {
213215
for j := nmap - 1; j >= 0; j-- {

0 commit comments

Comments
 (0)