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
89ac5618
Commit
89ac5618
authored
Sep 29, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
toward methods on any type
R=r OCL=16068 CL=16068
parent
3a884d76
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
35 deletions
+76
-35
obj.c
src/cmd/6g/obj.c
+13
-2
dcl.c
src/cmd/gc/dcl.c
+10
-1
go.h
src/cmd/gc/go.h
+8
-0
go.y
src/cmd/gc/go.y
+7
-3
subr.c
src/cmd/gc/subr.c
+22
-0
walk.c
src/cmd/gc/walk.c
+0
-22
iface.c
src/runtime/iface.c
+16
-7
No files found.
src/cmd/6g/obj.c
View file @
89ac5618
...
...
@@ -591,13 +591,15 @@ dumpsignatures(void)
a
=
lsort
(
a
,
sigcmp
);
ot
=
0
;
// first field of an interface signature
// contains the count and is not a real entry
if
(
et
==
TINTER
)
{
o
=
0
;
for
(
b
=
a
;
b
!=
nil
;
b
=
b
->
link
)
o
++
;
// sigi[0].name = ""
ot
=
rnd
(
ot
,
maxround
);
ot
=
rnd
(
ot
,
maxround
);
// array of structures
p
=
pc
;
gins
(
ADATA
,
N
,
N
);
p
->
from
=
at
;
...
...
@@ -636,7 +638,7 @@ dumpsignatures(void)
for
(
b
=
a
;
b
!=
nil
;
b
=
b
->
link
)
{
// sigx[++].name = "fieldname"
ot
=
rnd
(
ot
,
maxround
);
ot
=
rnd
(
ot
,
maxround
);
// array of structures
p
=
pc
;
gins
(
ADATA
,
N
,
N
);
p
->
from
=
at
;
...
...
@@ -669,6 +671,15 @@ dumpsignatures(void)
p
->
to
.
offset
=
b
->
offset
;
ot
+=
wi
;
}
else
{
// leave space for 3 ints
// offset, algorithm and width
ot
=
rnd
(
ot
,
wi
);
ot
+=
wi
;
ot
=
rnd
(
ot
,
wi
);
ot
+=
wi
;
ot
=
rnd
(
ot
,
wi
);
ot
+=
wi
;
// sigs[++].fun = &method
ot
=
rnd
(
ot
,
widthptr
);
p
=
pc
;
...
...
src/cmd/gc/dcl.c
View file @
89ac5618
...
...
@@ -237,7 +237,7 @@ methodname(Node *n, Type *t)
return
newname
(
lookup
(
namebuf
));
bad:
yyerror
(
"illegal <this>
pointer
: %T"
,
t
);
yyerror
(
"illegal <this>
type
: %T"
,
t
);
return
n
;
}
...
...
@@ -272,6 +272,15 @@ addmethod(Node *n, Type *t, int local)
if
(
pa
==
T
)
goto
bad
;
switch
(
algtype
(
pa
))
{
default:
goto
bad
;
case
ASIMP
:
case
APTR
:
case
ASTRING
:
break
;
}
// optionally rip off ptr to type
ptr
=
0
;
if
(
isptr
[
pa
->
etype
])
{
...
...
src/cmd/gc/go.h
View file @
89ac5618
...
...
@@ -34,6 +34,13 @@ enum
PRIME7
=
10067
,
PRIME8
=
10079
,
PRIME9
=
10091
,
AUNK
=
100
,
// these values are known by runtime
ASIMP
=
0
,
ASTRING
,
APTR
,
AINTER
,
};
/*
...
...
@@ -553,6 +560,7 @@ Node* nod(int, Node*, Node*);
Node
*
list
(
Node
*
,
Node
*
);
Type
*
typ
(
int
);
Dcl
*
dcl
(
void
);
int
algtype
(
Type
*
);
Node
*
rev
(
Node
*
);
Node
*
unrev
(
Node
*
);
void
dodump
(
Node
*
,
int
);
...
...
src/cmd/gc/go.y
View file @
89ac5618
...
...
@@ -1258,9 +1258,13 @@ structdcl:
}
|
new_name
{
//
must
be
a
latype
//
must
be
latype
$$
=
nod
(
ODCLFIELD
,
N
,
N
);
$$->
type
=
$
1
;
$$->
type
=
$
1
->
sym
->
otype
;
if
($
1
->
sym
->
lexical
!= LATYPE) {
yyerror
(
"unnamed structure field must be a type"
);
$$->
type
=
types
[
TINT32
];
};
}
|
LIMPORT
structdcl
{
...
...
@@ -1691,7 +1695,7 @@ hidden_importfield:
*
to
check
whether
the
rest
of
the
grammar
is
free
of
*
reduce
/
reduce
conflicts
,
comment
this
section
out
by
*
removing
the
slash
on
the
next
line
.
*
/
*
lpack
:
LATYPE
{
...
...
src/cmd/gc/subr.c
View file @
89ac5618
...
...
@@ -280,6 +280,28 @@ nod(int op, Node *nleft, Node *nright)
return
n
;
}
int
algtype
(
Type
*
t
)
{
int
a
;
a
=
AUNK
;
if
(
issimple
[
t
->
etype
])
a
=
ASIMP
;
// simple mem
else
if
(
isptrto
(
t
,
TSTRING
))
a
=
ASTRING
;
// string
else
if
(
isptr
[
t
->
etype
])
a
=
APTR
;
// pointer
else
if
(
isinter
(
t
))
a
=
AINTER
;
// interface
// else
// fatal("algtype: cant find type %T", t);
return
a
;
}
Node
*
list
(
Node
*
a
,
Node
*
b
)
{
...
...
src/cmd/gc/walk.c
View file @
89ac5618
...
...
@@ -1884,28 +1884,6 @@ bad:
return
T
;
}
static
int
algtype
(
Type
*
t
)
{
int
a
;
a
=
100
;
if
(
issimple
[
t
->
etype
])
a
=
0
;
// simple mem
else
if
(
isptrto
(
t
,
TSTRING
))
a
=
1
;
// string
else
if
(
isptr
[
t
->
etype
])
a
=
2
;
// pointer
else
if
(
isinter
(
t
))
a
=
3
;
// interface
else
fatal
(
"algtype: cant find type %T"
,
t
);
return
a
;
}
Node
*
mapop
(
Node
*
n
,
int
top
)
{
...
...
src/runtime/iface.c
View file @
89ac5618
...
...
@@ -14,6 +14,9 @@ struct Sigt
{
byte
*
name
;
uint32
hash
;
uint32
offset
;
// offset of substruct
uint32
width
;
// width of type
uint32
elemalg
;
// algorithm of type
void
(
*
fun
)(
void
);
};
...
...
@@ -21,7 +24,7 @@ struct Sigi
{
byte
*
name
;
uint32
hash
;
uint32
offset
;
uint32
perm
;
// location of fun in Sigt
};
struct
Map
...
...
@@ -44,7 +47,7 @@ printsigi(Sigi *si)
sys
·
printpointer
(
si
);
prints
(
"{"
);
n
=
si
[
0
].
offset
;
n
=
si
[
0
].
perm
;
// first entry has size
for
(
i
=
1
;
i
<
n
;
i
++
)
{
name
=
si
[
i
].
name
;
if
(
name
==
nil
)
{
...
...
@@ -56,9 +59,9 @@ printsigi(Sigi *si)
prints
(
"]
\"
"
);
prints
((
int8
*
)
name
);
prints
(
"
\"
"
);
sys
·
printint
(
si
[
i
].
hash
);
sys
·
printint
(
si
[
i
].
hash
%
999
);
prints
(
"/"
);
sys
·
printint
(
si
[
i
].
offset
);
sys
·
printint
(
si
[
i
].
perm
);
}
prints
(
"}"
);
}
...
...
@@ -80,7 +83,13 @@ printsigt(Sigt *st)
prints
(
"]
\"
"
);
prints
((
int8
*
)
name
);
prints
(
"
\"
"
);
sys
·
printint
(
st
[
i
].
hash
);
sys
·
printint
(
st
[
i
].
hash
%
999
);
prints
(
"/"
);
sys
·
printint
(
st
[
i
].
offset
);
prints
(
","
);
sys
·
printint
(
st
[
i
].
width
);
prints
(
","
);
sys
·
printint
(
st
[
i
].
elemalg
);
prints
(
"/"
);
sys
·
printpointer
(
st
[
i
].
fun
);
}
...
...
@@ -117,7 +126,7 @@ hashmap(Sigi *si, Sigt *st)
}
}
ni
=
si
[
0
].
offset
;
// first word
has size
ni
=
si
[
0
].
perm
;
// first entry
has size
m
=
mal
(
sizeof
(
*
m
)
+
ni
*
sizeof
(
m
->
fun
[
0
]));
m
->
sigi
=
si
;
m
->
sigt
=
st
;
...
...
@@ -157,7 +166,7 @@ loop2:
goto
loop2
;
}
m
->
fun
[
si
[
ni
].
offset
]
=
st
[
nt
].
fun
;
m
->
fun
[
si
[
ni
].
perm
]
=
st
[
nt
].
fun
;
ni
++
;
goto
loop1
;
}
...
...
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