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
a24a26c1
Commit
a24a26c1
authored
Sep 06, 2009
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more static init
almost done R=rsc OCL=34422 CL=34422
parent
18f2e360
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
6 deletions
+87
-6
walk.c
src/cmd/gc/walk.c
+87
-6
No files found.
src/cmd/gc/walk.c
View file @
a24a26c1
...
@@ -1977,6 +1977,8 @@ isliteral(Node *n)
...
@@ -1977,6 +1977,8 @@ isliteral(Node *n)
return
0
;
return
0
;
}
}
void
arraylit
(
Node
*
n
,
Node
*
var
,
int
pass
,
NodeList
**
init
);
void
void
structlit
(
Node
*
n
,
Node
*
var
,
int
pass
,
NodeList
**
init
)
structlit
(
Node
*
n
,
Node
*
var
,
int
pass
,
NodeList
**
init
)
{
{
...
@@ -1991,6 +1993,20 @@ structlit(Node *n, Node *var, int pass, NodeList **init)
...
@@ -1991,6 +1993,20 @@ structlit(Node *n, Node *var, int pass, NodeList **init)
index
=
r
->
left
;
index
=
r
->
left
;
value
=
r
->
right
;
value
=
r
->
right
;
switch
(
value
->
op
)
{
case
OARRAYLIT
:
if
(
value
->
type
->
bound
<
0
)
break
;
a
=
nod
(
ODOT
,
var
,
newname
(
index
->
sym
));
arraylit
(
value
,
a
,
pass
,
init
);
continue
;
case
OSTRUCTLIT
:
a
=
nod
(
ODOT
,
var
,
newname
(
index
->
sym
));
structlit
(
value
,
a
,
pass
,
init
);
continue
;
}
if
(
isliteral
(
value
))
{
if
(
isliteral
(
value
))
{
if
(
pass
==
2
)
if
(
pass
==
2
)
continue
;
continue
;
...
@@ -2026,6 +2042,20 @@ arraylit(Node *n, Node *var, int pass, NodeList **init)
...
@@ -2026,6 +2042,20 @@ arraylit(Node *n, Node *var, int pass, NodeList **init)
index
=
r
->
left
;
index
=
r
->
left
;
value
=
r
->
right
;
value
=
r
->
right
;
switch
(
value
->
op
)
{
case
OARRAYLIT
:
if
(
value
->
type
->
bound
<
0
)
break
;
a
=
nod
(
OINDEX
,
var
,
index
);
arraylit
(
value
,
a
,
pass
,
init
);
continue
;
case
OSTRUCTLIT
:
a
=
nod
(
OINDEX
,
var
,
index
);
structlit
(
value
,
a
,
pass
,
init
);
continue
;
}
if
(
isliteral
(
index
)
&&
isliteral
(
value
))
{
if
(
isliteral
(
index
)
&&
isliteral
(
value
))
{
if
(
pass
==
2
)
if
(
pass
==
2
)
continue
;
continue
;
...
@@ -2052,21 +2082,72 @@ slicelit(Node *n, Node *var, NodeList **init)
...
@@ -2052,21 +2082,72 @@ slicelit(Node *n, Node *var, NodeList **init)
{
{
Node
*
r
,
*
a
;
Node
*
r
,
*
a
;
NodeList
*
l
;
NodeList
*
l
;
Type
*
t
;
Node
*
vstat
,
*
vheap
;
Node
*
index
,
*
value
;
// slice
// make an array type
a
=
nod
(
OMAKE
,
N
,
N
);
t
=
shallow
(
n
->
type
);
a
->
list
=
list
(
list1
(
typenod
(
n
->
type
)),
n
->
right
);
t
->
bound
=
mpgetfix
(
n
->
right
->
val
.
u
.
xval
);
a
=
nod
(
OAS
,
var
,
a
);
t
->
width
=
0
;
dowidth
(
t
);
// make static initialized array
vstat
=
staticname
(
t
);
arraylit
(
n
,
vstat
,
1
,
init
);
// make new *array heap
vheap
=
nod
(
OXXX
,
N
,
N
);
tempname
(
vheap
,
ptrto
(
t
));
a
=
nod
(
ONEW
,
N
,
N
);
a
->
list
=
list1
(
typenod
(
t
));
a
=
nod
(
OAS
,
vheap
,
a
);
typecheck
(
&
a
,
Etop
);
typecheck
(
&
a
,
Etop
);
walkexpr
(
&
a
,
init
);
walkexpr
(
&
a
,
init
);
*
init
=
list
(
*
init
,
a
);
*
init
=
list
(
*
init
,
a
);
// copy static to heap
a
=
nod
(
OIND
,
vheap
,
N
);
a
=
nod
(
OAS
,
a
,
vstat
);
typecheck
(
&
a
,
Etop
);
walkexpr
(
&
a
,
init
);
*
init
=
list
(
*
init
,
a
);
// make slice out of heap
a
=
nod
(
OAS
,
var
,
vheap
);
typecheck
(
&
a
,
Etop
);
walkexpr
(
&
a
,
init
);
*
init
=
list
(
*
init
,
a
);
// put dynamics into slice
for
(
l
=
n
->
list
;
l
;
l
=
l
->
next
)
{
for
(
l
=
n
->
list
;
l
;
l
=
l
->
next
)
{
r
=
l
->
n
;
r
=
l
->
n
;
if
(
r
->
op
!=
OKEY
)
fatal
(
"slicelit: rhs not OKEY: %N"
,
r
);
index
=
r
->
left
;
value
=
r
->
right
;
switch
(
value
->
op
)
{
case
OARRAYLIT
:
if
(
value
->
type
->
bound
<
0
)
break
;
a
=
nod
(
OINDEX
,
var
,
index
);
arraylit
(
value
,
a
,
2
,
init
);
continue
;
case
OSTRUCTLIT
:
a
=
nod
(
OINDEX
,
var
,
index
);
structlit
(
value
,
a
,
2
,
init
);
continue
;
}
if
(
isliteral
(
index
)
&&
isliteral
(
value
))
continue
;
// build list of var[c] = expr
// build list of var[c] = expr
a
=
nod
(
OINDEX
,
var
,
r
->
left
);
a
=
nod
(
OINDEX
,
var
,
index
);
a
=
nod
(
OAS
,
a
,
r
->
right
);
a
=
nod
(
OAS
,
a
,
value
);
typecheck
(
&
a
,
Etop
);
typecheck
(
&
a
,
Etop
);
walkexpr
(
&
a
,
init
);
// add any assignments in r to top
walkexpr
(
&
a
,
init
);
// add any assignments in r to top
*
init
=
list
(
*
init
,
a
);
*
init
=
list
(
*
init
,
a
);
...
...
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