Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
e73674b2
Commit
e73674b2
authored
Mar 31, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code to assign nil to an interface
without conversions SVN=114453
parent
5918f80f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
11 deletions
+54
-11
src/c/gen.c
src/c/gen.c
+18
-10
src/c/gen.h
src/c/gen.h
+1
-1
src/c/go.h
src/c/go.h
+1
-0
src/c/gsubr.c
src/c/gsubr.c
+1
-0
src/c/obj.c
src/c/obj.c
+21
-0
src/c/subr.c
src/c/subr.c
+12
-0
No files found.
src/c/gen.c
View file @
e73674b2
...
...
@@ -827,19 +827,19 @@ loop:
break
;
case
PAS_SINGLE
:
// single return val used in expr
if
(
nr
==
N
)
{
if
(
nr
==
N
||
isnil
(
nr
)
)
{
if
(
nl
->
addable
)
{
gopcodet
(
PSTOREZ
,
nl
->
type
,
nl
);
break
;
}
agen
(
nl
);
gopcodet
(
PSTOREZI
P
,
nl
->
type
,
N
);
gopcodet
(
PSTOREZI
,
nl
->
type
,
N
);
break
;
}
if
(
nl
->
addable
)
{
cgen
(
nr
);
genconv
(
nl
->
type
,
nr
->
type
);
genconv
(
nl
,
nr
);
gopcodet
(
PSTORE
,
nl
->
type
,
nl
);
break
;
}
...
...
@@ -851,7 +851,7 @@ loop:
}
if
(
!
usesptr
(
nr
))
{
cgen
(
nr
);
genconv
(
nl
->
type
,
nr
->
type
);
genconv
(
nl
,
nr
);
agen
(
nl
);
gopcodet
(
PSTOREI
,
nr
->
type
,
N
);
break
;
...
...
@@ -860,7 +860,7 @@ loop:
r
=
tempname
(
ptrto
(
nl
->
type
));
gopcode
(
PSTORE
,
PTADDR
,
r
);
cgen
(
nr
);
genconv
(
nl
->
type
,
nr
->
type
);
genconv
(
nl
,
nr
);
gopcode
(
PLOAD
,
PTADDR
,
r
);
gopcodet
(
PSTOREI
,
nl
->
type
,
N
);
break
;
...
...
@@ -964,7 +964,7 @@ cgen_ret(Node *n)
gopcodet
(
PSTOREI
,
arg
->
type
,
arg
);
}
else
{
cgen
(
arg
);
genconv
(
f
->
type
,
arg
->
type
);
genconv
(
f
,
arg
);
gopcode
(
PLOAD
,
PTADDR
,
a
->
nname
);
gopcode
(
PADDO
,
PTADDR
,
f
->
nname
);
gopcodet
(
PSTOREI
,
f
->
type
,
N
);
...
...
@@ -1010,7 +1010,7 @@ cgen_call(Node *n, int toss)
gopcodet
(
PSTOREI
,
at
->
type
,
ae
);
}
else
{
cgen
(
ae
);
genconv
(
at
->
type
,
ae
->
typ
e
);
genconv
(
at
,
a
e
);
gopcode
(
PADDR
,
PTADDR
,
sn
);
gopcode
(
PADDO
,
PTADDR
,
at
->
nname
);
gopcodet
(
PSTOREI
,
at
->
type
,
N
);
...
...
@@ -1120,9 +1120,13 @@ genprint(Node *n)
int
needconvert
(
Node
*
tl
,
Node
*
tr
)
{
if
(
isinter
(
tl
))
if
(
isptrto
(
tr
,
TSTRUCT
)
||
isinter
(
tr
)
)
if
(
isinter
(
tl
))
{
if
(
isptrto
(
tr
,
TSTRUCT
))
return
1
;
if
(
isinter
(
tr
))
return
1
;
return
0
;
}
if
(
isptrto
(
tl
,
TSTRUCT
))
if
(
isinter
(
tr
))
return
1
;
...
...
@@ -1130,8 +1134,12 @@ needconvert(Node *tl, Node *tr)
}
void
genconv
(
Node
*
tl
,
Node
*
t
r
)
genconv
(
Node
*
l
,
Node
*
r
)
{
Node
*
tl
,
*
tr
;
tl
=
l
->
type
;
tr
=
r
->
type
;
if
(
needconvert
(
tl
,
tr
))
gopcode
(
PCONV
,
PTNIL
,
nod
(
OCONV
,
tl
,
tr
));
}
...
...
src/c/gen.h
View file @
e73674b2
...
...
@@ -103,7 +103,7 @@ enum
PLOAD
,
PLOADI
,
PSTORE
,
PSTOREI
,
PSTOREZ
,
PSTOREZI
P
,
PSTOREZ
,
PSTOREZI
,
PCONV
,
PADDR
,
PADDO
,
PINDEX
,
PINDEXZ
,
PSLICE
,
...
...
src/c/go.h
View file @
e73674b2
...
...
@@ -395,6 +395,7 @@ Node* unrev(Node*);
void
dodump
(
Node
*
,
int
);
void
dump
(
char
*
,
Node
*
);
Node
*
aindex
(
Node
*
,
Node
*
);
int
isnil
(
Node
*
);
int
isptrto
(
Node
*
,
int
);
int
isinter
(
Node
*
);
int
isbytearray
(
Node
*
);
...
...
src/c/gsubr.c
View file @
e73674b2
...
...
@@ -236,6 +236,7 @@ pnames[] =
[
PSTORE
]
=
"STORE"
,
[
PSTOREI
]
=
"STOREI"
,
[
PSTOREZ
]
=
"STOREZ"
,
[
PSTOREZI
]
=
"STOREZI"
,
[
PCONV
]
=
"CONV"
,
[
PADDR
]
=
"ADDR"
,
[
PADDO
]
=
"ADDO"
,
...
...
src/c/obj.c
View file @
e73674b2
...
...
@@ -243,6 +243,27 @@ obj1(Prog *p)
}
break
;
case
PSTOREZI
:
switch
(
p
->
pt
)
{
default:
Bprint
(
bout
,
"
\t
*(%Q*)%R = 0;
\n
"
,
p
->
pt
,
PTADDR
);
break
;
case
PTARRAY
:
case
PTSTRUCT
:
Bprint
(
bout
,
"
\t
memset((%Q*)%R, 0, sizeof((%Q*)%R));
\n
"
,
p
->
pt
,
PTADDR
,
p
->
pt
,
PTADDR
);
break
;
case
PTINTER
:
Bprint
(
bout
,
"
\t
((%Q*)%R)->s = 0; ((%Q*)%R)->m = 0;
\n
"
,
p
->
pt
,
PTADDR
,
p
->
pt
,
PTADDR
);
break
;
case
PTSTRING
:
Bprint
(
bout
,
"
\t
(%Q*)%R = &nilstring;
\n
"
,
p
->
pt
,
PTADDR
);
break
;
}
break
;
case
PCONV
:
doconv
(
p
);
break
;
...
...
src/c/subr.c
View file @
e73674b2
...
...
@@ -997,6 +997,18 @@ out:
return
fmtstrcpy
(
fp
,
buf
);
}
int
isnil
(
Node
*
n
)
{
if
(
n
==
N
)
return
0
;
if
(
n
->
op
!=
OLITERAL
)
return
0
;
if
(
n
->
val
.
ctype
!=
CTNIL
)
return
0
;
return
1
;
}
int
isptrto
(
Node
*
t
,
int
et
)
{
...
...
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