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
88b5c5f0
Commit
88b5c5f0
authored
Jan 06, 2009
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make for slice/map/chan
new for pointers R=r OCL=22158 CL=22158
parent
1da03aae
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
16 deletions
+74
-16
go.h
src/cmd/gc/go.h
+2
-1
go.y
src/cmd/gc/go.y
+13
-2
lex.c
src/cmd/gc/lex.c
+1
-0
subr.c
src/cmd/gc/subr.c
+1
-0
walk.c
src/cmd/gc/walk.c
+57
-13
No files found.
src/cmd/gc/go.h
View file @
88b5c5f0
...
...
@@ -292,7 +292,7 @@ enum
OLIST
,
OCMP
,
OPTR
,
OARRAY
,
ORANGE
,
ORETURN
,
OFOR
,
OIF
,
OSWITCH
,
OAS
,
OASOP
,
OCASE
,
OXCASE
,
OFALL
,
OXFALL
,
OGOTO
,
OPROC
,
ONEW
,
OEMPTY
,
OSELECT
,
OGOTO
,
OPROC
,
O
MAKE
,
O
NEW
,
OEMPTY
,
OSELECT
,
OLEN
,
OCAP
,
OPANIC
,
OPANICN
,
OPRINT
,
OPRINTN
,
OTYPEOF
,
OOROR
,
...
...
@@ -789,6 +789,7 @@ int ascompat(Type*, Type*);
Node
*
prcompat
(
Node
*
,
int
);
Node
*
nodpanic
(
int32
);
Node
*
newcompat
(
Node
*
);
Node
*
makecompat
(
Node
*
);
Node
*
stringop
(
Node
*
,
int
);
Type
*
fixmap
(
Type
*
);
Node
*
mapop
(
Node
*
,
int
);
...
...
src/cmd/gc/go.y
View file @
88b5c5f0
...
...
@@ -18,8 +18,8 @@
%
token
<
sym
>
LPACKAGE
LIMPORT
LEXPORT
%
token
<
sym
>
LMAP
LCHAN
LINTERFACE
LFUNC
LSTRUCT
%
token
<
sym
>
LCOLAS
LFALL
LRETURN
LDDD
%
token
<
sym
>
L
NEW
L
LEN
LCAP
LTYPEOF
LPANIC
LPANICN
LPRINT
LPRINTN
%
token
<
sym
>
LVAR
LTYPE
LCONST
LCONVERT
LSELECT
%
token
<
sym
>
LLEN
LCAP
LTYPEOF
LPANIC
LPANICN
LPRINT
LPRINTN
%
token
<
sym
>
LVAR
LTYPE
LCONST
LCONVERT
LSELECT
LMAKE
LNEW
%
token
<
sym
>
LFOR
LIF
LELSE
LSWITCH
LCASE
LDEFAULT
%
token
<
sym
>
LBREAK
LCONTINUE
LGO
LGOTO
LRANGE
%
token
<
sym
>
LNIL
LTRUE
LFALSE
LIOTA
...
...
@@ -864,6 +864,16 @@ pexpr:
$$
=
nod
(
ONEW
,
$
5
,
N
);
$$->
type
=
$
3
;
}
|
LMAKE
'('
type
')'
{
$$
=
nod
(
OMAKE
,
N
,
N
);
$$->
type
=
$
3
;
}
|
LMAKE
'('
type
','
expr_list
')'
{
$$
=
nod
(
OMAKE
,
$
5
,
N
);
$$->
type
=
$
3
;
}
|
latype
'('
expr
')'
{
$$
=
nod
(
OCONV
,
$
3
,
N
);
...
...
@@ -980,6 +990,7 @@ sym3:
|
LPRINT
|
LPRINTN
|
LNEW
|
LMAKE
|
LBASETYPE
|
LTYPEOF
...
...
src/cmd/gc/lex.c
View file @
88b5c5f0
...
...
@@ -1064,6 +1064,7 @@ static struct
"import"
,
LIMPORT
,
Txxx
,
"interface"
,
LINTERFACE
,
Txxx
,
"iota"
,
LIOTA
,
Txxx
,
"make"
,
LMAKE
,
Txxx
,
"map"
,
LMAP
,
Txxx
,
"new"
,
LNEW
,
Txxx
,
"len"
,
LLEN
,
Txxx
,
...
...
src/cmd/gc/subr.c
View file @
88b5c5f0
...
...
@@ -708,6 +708,7 @@ opnames[] =
[
OVAR
]
=
"VAR"
,
[
OIMPORT
]
=
"IMPORT"
,
[
OXOR
]
=
"XOR"
,
[
OMAKE
]
=
"MAKE"
,
[
ONEW
]
=
"NEW"
,
[
OFALL
]
=
"FALL"
,
[
OXFALL
]
=
"XFALL"
,
...
...
src/cmd/gc/walk.c
View file @
88b5c5f0
...
...
@@ -590,7 +590,7 @@ loop:
}
}
// convert dynamic to static generated by ONEW
// convert dynamic to static generated by ONEW
/OMAKE
if
(
issarray
(
t
)
&&
isdarray
(
l
->
type
))
goto
ret
;
...
...
@@ -979,7 +979,7 @@ loop:
nvar
=
nod
(
0
,
N
,
N
);
tempname
(
nvar
,
t
);
nnew
=
nod
(
O
NEW
,
N
,
N
);
nnew
=
nod
(
O
MAKE
,
N
,
N
);
nnew
->
type
=
t
;
nnew
=
newcompat
(
nnew
);
...
...
@@ -1017,6 +1017,12 @@ loop:
n
->
type
=
t
->
type
;
goto
ret
;
case
OMAKE
:
if
(
top
!=
Erv
)
goto
nottop
;
indir
(
n
,
makecompat
(
n
));
goto
ret
;
case
ONEW
:
if
(
top
!=
Erv
)
goto
nottop
;
...
...
@@ -2014,7 +2020,7 @@ nodpanic(int32 lineno)
}
Node
*
new
compat
(
Node
*
n
)
make
compat
(
Node
*
n
)
{
Node
*
r
,
*
on
;
Type
*
t
,
*
t0
;
...
...
@@ -2026,21 +2032,24 @@ newcompat(Node *n)
if
(
t0
->
etype
==
TARRAY
)
return
arrayop
(
n
,
Erv
);
if
(
!
isptr
[
t0
->
etype
]
||
t0
->
type
==
T
)
if
(
!
isptr
[
t0
->
etype
])
goto
bad
;
t
=
t0
->
type
;
if
(
t
==
T
)
goto
bad
;
switch
(
t
->
etype
)
{
case
TSTRING
:
goto
bad
;
// the call looks like new(
map
[int]int)
// the call looks like new(
MAP
[int]int)
// but internally we see new(*MAP[int]int)
case
TMAP
:
r
=
mapop
(
n
,
Erv
);
break
;
// the call looks like new(
chan
int)
// the call looks like new(
CHAN
int)
// but internally we see new(*CHAN int)
case
TCHAN
:
r
=
chanop
(
n
,
Erv
);
...
...
@@ -2048,7 +2057,42 @@ newcompat(Node *n)
default:
if
(
n
->
left
!=
N
)
yyerror
(
"cannot new(%T, expr)"
,
t0
);
yyerror
(
"cannot make(%T, expr)"
,
t0
);
dowidth
(
t
);
on
=
syslook
(
"mal"
,
1
);
argtype
(
on
,
t
);
r
=
nodintconst
(
t
->
width
);
r
=
nod
(
OCALL
,
on
,
r
);
walktype
(
r
,
Erv
);
break
;
}
return
r
;
bad:
yyerror
(
"cannot make(%T)"
,
t0
);
return
n
;
}
Node
*
newcompat
(
Node
*
n
)
{
Node
*
r
,
*
on
;
Type
*
t
,
*
t0
;
t
=
n
->
type
;
if
(
t
==
T
)
goto
bad
;
switch
(
t
->
etype
)
{
case
TSTRING
:
case
TMAP
:
case
TCHAN
:
goto
bad
;
default:
if
(
n
->
left
!=
N
)
yyerror
(
"cannot new(%T, expr)"
,
t
);
dowidth
(
t
);
on
=
syslook
(
"mal"
,
1
);
argtype
(
on
,
t
);
...
...
@@ -2061,7 +2105,7 @@ newcompat(Node *n)
return
r
;
bad:
yyerror
(
"cannot new(%T)"
,
t
0
);
yyerror
(
"cannot new(%T)"
,
t
);
return
n
;
}
...
...
@@ -2224,7 +2268,7 @@ mapop(Node *n, int top)
default:
fatal
(
"mapop: unknown op %O"
,
n
->
op
);
case
O
NEW
:
case
O
MAKE
:
if
(
top
!=
Erv
)
goto
nottop
;
...
...
@@ -2436,7 +2480,7 @@ chanop(Node *n, int top)
default:
fatal
(
"chanop: unknown op %O"
,
n
->
op
);
case
O
NEW
:
case
O
MAKE
:
// newchan(elemsize int, elemalg int,
// hint int) (hmap *chan[any-1]);
...
...
@@ -2642,7 +2686,7 @@ arrayop(Node *n, int top)
n
->
right
=
r
;
return
n
;
case
O
NEW
:
case
O
MAKE
:
// newarray(nel int, max int, width int) (ary []any)
t
=
fixarray
(
n
->
type
);
if
(
t
==
T
)
...
...
@@ -3523,7 +3567,7 @@ arraylit(Node *n)
var
=
nod
(
OXXX
,
N
,
N
);
tempname
(
var
,
t
);
nnew
=
nod
(
O
NEW
,
N
,
N
);
nnew
=
nod
(
O
MAKE
,
N
,
N
);
nnew
->
type
=
t
;
nas
=
nod
(
OAS
,
var
,
nnew
);
...
...
@@ -3560,7 +3604,7 @@ maplit(Node *n)
var
=
nod
(
OXXX
,
N
,
N
);
tempname
(
var
,
t
);
a
=
nod
(
O
NEW
,
N
,
N
);
a
=
nod
(
O
MAKE
,
N
,
N
);
a
->
type
=
t
;
a
=
nod
(
OAS
,
var
,
a
);
addtop
=
list
(
addtop
,
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