Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
beee6915
Commit
beee6915
authored
Oct 21, 2008
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite &Point{1, 2} as allocation
R=ken OCL=17592 CL=17592
parent
2c3ddf5e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
18 deletions
+39
-18
go.y
src/cmd/gc/go.y
+0
-4
walk.c
src/cmd/gc/walk.c
+30
-0
addr.go
test/addr.go
+0
-9
complit.go
test/complit.go
+9
-0
golden.out
test/golden.out
+0
-5
No files found.
src/cmd/gc/go.y
View file @
beee6915
...
...
@@ -754,8 +754,6 @@ uexpr:
}
|
'&'
uexpr
{
if
($
2
->
op
==
OCONV
&&
!func)
yyerror
(
"& of composite literal at top level"
);
$$
=
nod
(
OADDR
,
$
2
,
N
);
}
|
'+'
uexpr
...
...
@@ -1186,13 +1184,11 @@ xfndcl:
{
maxarg
=
0
;
stksize
=
0
;
func
++;
}
fndcl
fnbody
{
$$
=
$
3
;
$$->
nbody
=
$
4
;
funcbody
($$);
func
--;
}
fndcl
:
...
...
src/cmd/gc/walk.c
View file @
beee6915
...
...
@@ -895,6 +895,36 @@ loop:
case
OADDR
:
if
(
top
!=
Erv
)
goto
nottop
;
if
(
n
->
left
->
op
==
OCONV
&&
iscomposite
(
n
->
left
->
type
))
{
// turn &Point{1, 2} into allocation.
// initialize with
// nvar := new(Point);
// *nvar = Point{1, 2};
// and replace expression with nvar
// TODO(rsc): might do a better job (fewer copies) later
Node
*
nnew
,
*
nvar
,
*
nas
;
walktype
(
n
->
left
,
Elv
);
if
(
n
->
left
==
N
)
goto
ret
;
nvar
=
nod
(
0
,
N
,
N
);
tempname
(
nvar
,
ptrto
(
n
->
left
->
type
));
nnew
=
nod
(
ONEW
,
N
,
N
);
nnew
->
type
=
nvar
->
type
;
nnew
=
newcompat
(
nnew
);
nas
=
nod
(
OAS
,
nvar
,
nnew
);
addtop
=
list
(
addtop
,
nas
);
nas
=
nod
(
OAS
,
nod
(
OIND
,
nvar
,
N
),
n
->
left
);
addtop
=
list
(
addtop
,
nas
);
indir
(
n
,
nvar
);
goto
ret
;
}
walktype
(
n
->
left
,
Elv
);
if
(
n
->
left
==
N
)
goto
ret
;
...
...
test/addr.go
deleted
100644 → 0
View file @
2c3ddf5e
// errchk $G $D/$F.go
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
var
a
=
&
[]
int
{
1
,
2
};
// ERROR "composite"
test/complit.go
View file @
beee6915
...
...
@@ -22,6 +22,11 @@ func eq(a *[]*R) {
}
}
type
P
struct
{
a
,
b
int
};
func
NewP
(
a
,
b
int
)
*
P
{
return
&
P
{
a
,
b
}
}
func
main
()
{
var
t
T
;
t
=
T
{
0
,
7.2
,
"hi"
,
&
t
};
...
...
@@ -57,4 +62,8 @@ func main() {
if
len
(
m
)
!=
3
{
panic
(
"m"
)
}
eq
(
&
[]
*
R
{
itor
(
0
),
itor
(
1
),
itor
(
2
),
itor
(
3
),
itor
(
4
),
itor
(
5
)});
p1
:=
NewP
(
1
,
2
);
p2
:=
NewP
(
1
,
2
);
if
p1
==
p2
{
panic
(
"NewP"
)
}
}
test/golden.out
View file @
beee6915
...
...
@@ -129,11 +129,6 @@ found 2, expected 1
panic on line 74 PC=xxx
BUG wrong result
=========== bugs/bug097.go
panic on line 76 PC=xxx
BUG wrong result
=========== bugs/bug098.go
bugs/bug098.go:10: illegal types for operand: AS
*M
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment