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
47975235
Commit
47975235
authored
Aug 12, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bugs in const/case
R=r DELTA=138 (75 added, 12 deleted, 51 changed) OCL=14129 CL=14131
parent
9b1e6fdd
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
121 additions
and
58 deletions
+121
-58
src/cmd/6g/gen.c
src/cmd/6g/gen.c
+2
-3
src/cmd/gc/const.c
src/cmd/gc/const.c
+14
-6
src/cmd/gc/go.h
src/cmd/gc/go.h
+2
-0
src/cmd/gc/go.y
src/cmd/gc/go.y
+43
-9
src/cmd/gc/lex.c
src/cmd/gc/lex.c
+1
-1
src/cmd/gc/mparith1.c
src/cmd/gc/mparith1.c
+22
-0
src/cmd/gc/subr.c
src/cmd/gc/subr.c
+1
-1
src/cmd/gc/walk.c
src/cmd/gc/walk.c
+1
-1
test/ken/rob2.go
test/ken/rob2.go
+35
-37
No files found.
src/cmd/6g/gen.c
View file @
47975235
...
@@ -455,10 +455,9 @@ swgen(Node *n)
...
@@ -455,10 +455,9 @@ swgen(Node *n)
}
}
// put in the break between cases
// put in the break between cases
if
(
any
)
{
if
(
any
)
patch
(
gbranch
(
AJMP
,
T
),
breakpc
);
patch
(
gbranch
(
AJMP
,
T
),
breakpc
);
any
=
0
;
any
=
1
;
}
// over case expressions
// over case expressions
c2
=
listfirst
(
&
save2
,
&
c1
->
left
);
c2
=
listfirst
(
&
save2
,
&
c1
->
left
);
...
...
src/cmd/gc/const.c
View file @
47975235
...
@@ -63,12 +63,16 @@ convlit(Node *n, Type *t)
...
@@ -63,12 +63,16 @@ convlit(Node *n, Type *t)
break
;
break
;
}
}
if
(
isfloat
[
et
])
{
if
(
isfloat
[
et
])
{
Mpint
*
xv
;
// int to float
// int to float
if
(
mpcmpfltflt
(
n
->
val
.
u
.
fval
,
minfltval
[
et
])
<
0
)
xv
=
n
->
val
.
u
.
xval
;
if
(
mpcmpfixflt
(
xv
,
minfltval
[
et
])
<
0
)
goto
bad2
;
goto
bad2
;
if
(
mpcmpf
ltflt
(
n
->
val
.
u
.
fval
,
maxfltval
[
et
])
>
0
)
if
(
mpcmpf
ixflt
(
xv
,
maxfltval
[
et
])
>
0
)
goto
bad2
;
goto
bad2
;
mpmovefixflt
(
n
->
val
.
u
.
fval
,
n
->
val
.
u
.
xval
);
n
->
val
.
u
.
fval
=
mal
(
sizeof
(
*
n
->
val
.
u
.
fval
));
mpmovefixflt
(
n
->
val
.
u
.
fval
,
xv
);
n
->
val
.
ctype
=
CTFLT
;
n
->
val
.
ctype
=
CTFLT
;
break
;
break
;
}
}
...
@@ -76,12 +80,16 @@ convlit(Node *n, Type *t)
...
@@ -76,12 +80,16 @@ convlit(Node *n, Type *t)
case
Wlitfloat
:
case
Wlitfloat
:
if
(
isint
[
et
])
{
if
(
isint
[
et
])
{
Mpflt
*
fv
;
// float to int
// float to int
if
(
mpcmpfixfix
(
n
->
val
.
u
.
xval
,
minintval
[
et
])
<
0
)
fv
=
n
->
val
.
u
.
fval
;
if
(
mpcmpfltfix
(
fv
,
minintval
[
et
])
<
0
)
goto
bad2
;
goto
bad2
;
if
(
mpcmpf
ixfix
(
n
->
val
.
u
.
xval
,
maxintval
[
et
])
>
0
)
if
(
mpcmpf
ltfix
(
fv
,
maxintval
[
et
])
>
0
)
goto
bad2
;
goto
bad2
;
mpmovefltfix
(
n
->
val
.
u
.
xval
,
n
->
val
.
u
.
fval
);
n
->
val
.
u
.
xval
=
mal
(
sizeof
(
*
n
->
val
.
u
.
xval
));
mpmovefltfix
(
n
->
val
.
u
.
xval
,
fv
);
n
->
val
.
ctype
=
CTINT
;
n
->
val
.
ctype
=
CTINT
;
break
;
break
;
}
}
...
...
src/cmd/gc/go.h
View file @
47975235
...
@@ -471,6 +471,8 @@ void mkpackage(char*);
...
@@ -471,6 +471,8 @@ void mkpackage(char*);
/*
/*
* mparith1.c
* mparith1.c
*/
*/
int
mpcmpfixflt
(
Mpint
*
a
,
Mpflt
*
b
);
int
mpcmpfltfix
(
Mpflt
*
a
,
Mpint
*
b
);
int
mpcmpfixfix
(
Mpint
*
a
,
Mpint
*
b
);
int
mpcmpfixfix
(
Mpint
*
a
,
Mpint
*
b
);
int
mpcmpfixc
(
Mpint
*
b
,
vlong
c
);
int
mpcmpfixc
(
Mpint
*
b
,
vlong
c
);
int
mpcmpfltflt
(
Mpflt
*
a
,
Mpflt
*
b
);
int
mpcmpfltflt
(
Mpflt
*
a
,
Mpflt
*
b
);
...
...
src/cmd/gc/go.y
View file @
47975235
...
@@ -708,7 +708,7 @@ pexpr:
...
@@ -708,7 +708,7 @@ pexpr:
{
{
$$
=
$
2
;
$$
=
$
2
;
}
}
|
pexpr
'.'
sym
1
|
pexpr
'.'
sym
2
{
{
$$
=
nod
(
ODOT
,
$
1
,
newname
($
3
));
$$
=
nod
(
ODOT
,
$
1
,
newname
($
3
));
}
}
...
@@ -812,13 +812,13 @@ name_name:
...
@@ -812,13 +812,13 @@ name_name:
}
}
new_name
:
new_name
:
sym
2
sym
1
{
{
$$
=
newname
($
1
);
$$
=
newname
($
1
);
}
}
new_type
:
new_type
:
sym
2
sym
1
{
{
$$
=
newtype
($
1
);
$$
=
newtype
($
1
);
}
}
...
@@ -832,17 +832,36 @@ sym:
...
@@ -832,17 +832,36 @@ sym:
sym1
:
sym1
:
sym
sym
|
key1
|
key1
|
key2
sym2
:
sym2
:
sym
sym
|
key1
|
key2
|
key2
/*
/*
*
keywords
that
we
can
*
keywords
that
we
can
>>>>
ORIGINAL
go
/
src
/
cmd
/
gc
/
go
.
y
#
8
====
THEIRS
go
/
src
/
cmd
/
gc
/
go
.
y
#
9
*
use
as
field
names
*
use
as
field
names
====
YOURS
go
/
src
/
cmd
/
gc
/
go
.
y
*
use
a
variable
/
type
names
<<<<
*/
*/
key1
:
key1
:
LNIL
|
LTRUE
|
LFALSE
|
LIOTA
|
LLEN
|
LPANIC
|
LPRINT
|
LNEW
|
LBASETYPE
/*
*
keywords
that
we
can
*/
key2
:
LPACKAGE
LPACKAGE
|
LIMPORT
|
LIMPORT
|
LEXPORT
|
LEXPORT
...
@@ -871,8 +890,21 @@ key1:
...
@@ -871,8 +890,21 @@ key1:
|
LRANGE
|
LRANGE
|
LIGNORE
|
LIGNORE
/*
>>>>
ORIGINAL
go
/
src
/
cmd
/
gc
/
go
.
y
#
8
*
keywords
that
we
can
*
use
a
variable
/
type
names
*/
key2
:
LNIL
|
LTRUE
|
LFALSE
|
LIOTA
|
LLEN
|
LPANIC
|
LPRINT
|
LNEW
|
LBASETYPE
====
THEIRS
go
/
src
/
cmd
/
gc
/
go
.
y
#
9
*
use
as
variable
/
type
names
*
use
as
variable
/
type
names
*/
*/
key2
:
key2
:
...
@@ -886,6 +918,8 @@ key2:
...
@@ -886,6 +918,8 @@ key2:
|
LNEW
|
LNEW
|
LBASETYPE
|
LBASETYPE
====
YOURS
src
/
cmd
/
gc
/
go
.
y
<<<<
name
:
name
:
lname
lname
{
{
...
@@ -1394,7 +1428,7 @@ export:
...
@@ -1394,7 +1428,7 @@ export:
{
{
exportsym
($
1
);
exportsym
($
1
);
}
}
|
sym
'.'
sym
1
|
sym
'.'
sym
2
{
{
exportsym
(
pkglookup
($
3
->
name
,
$
1
->
name
));
exportsym
(
pkglookup
($
3
->
name
,
$
1
->
name
));
}
}
...
@@ -1578,7 +1612,7 @@ hidden_import:
...
@@ -1578,7 +1612,7 @@ hidden_import:
}
}
isym
:
isym
:
sym
'.'
sym
1
sym
'.'
sym
2
{
{
$$
=
nod
(
OIMPORT
,
N
,
N
);
$$
=
nod
(
OIMPORT
,
N
,
N
);
$$->
osym
=
$
1
;
$$->
osym
=
$
1
;
...
@@ -1586,7 +1620,7 @@ isym:
...
@@ -1586,7 +1620,7 @@ isym:
$$->
sym
=
$
3
;
$$->
sym
=
$
3
;
renamepkg
($$);
renamepkg
($$);
}
}
|
'('
sym
')'
sym
'.'
sym
1
|
'('
sym
')'
sym
'.'
sym
2
{
{
$$
=
nod
(
OIMPORT
,
N
,
N
);
$$
=
nod
(
OIMPORT
,
N
,
N
);
$$->
osym
=
$
2
;
$$->
osym
=
$
2
;
...
...
src/cmd/gc/lex.c
View file @
47975235
...
@@ -1022,8 +1022,8 @@ void
...
@@ -1022,8 +1022,8 @@ void
lexinit
(
void
)
lexinit
(
void
)
{
{
int
i
,
etype
,
lex
;
int
i
,
etype
,
lex
;
Sym
*
s
;
Type
*
t
;
Type
*
t
;
Sym
*
s
;
besetptr
();
besetptr
();
...
...
src/cmd/gc/mparith1.c
View file @
47975235
...
@@ -6,6 +6,28 @@
...
@@ -6,6 +6,28 @@
/// uses arihmetic
/// uses arihmetic
int
mpcmpfixflt
(
Mpint
*
a
,
Mpflt
*
b
)
{
char
buf
[
500
];
Mpflt
c
;
sprint
(
buf
,
"%B"
,
a
);
mpatoflt
(
&
c
,
buf
);
return
mpcmpfltflt
(
&
c
,
b
);
}
int
mpcmpfltfix
(
Mpflt
*
a
,
Mpint
*
b
)
{
char
buf
[
500
];
Mpflt
c
;
sprint
(
buf
,
"%B"
,
b
);
mpatoflt
(
&
c
,
buf
);
return
mpcmpfltflt
(
a
,
&
c
);
}
int
int
mpcmpfixfix
(
Mpint
*
a
,
Mpint
*
b
)
mpcmpfixfix
(
Mpint
*
a
,
Mpint
*
b
)
{
{
...
...
src/cmd/gc/subr.c
View file @
47975235
...
@@ -1064,7 +1064,7 @@ Nconv(Fmt *fp)
...
@@ -1064,7 +1064,7 @@ Nconv(Fmt *fp)
snprint
(
buf1
,
sizeof
(
buf1
),
"S
\"
%Z
\"
"
,
n
->
val
.
u
.
sval
);
snprint
(
buf1
,
sizeof
(
buf1
),
"S
\"
%Z
\"
"
,
n
->
val
.
u
.
sval
);
break
;
break
;
case
CTBOOL
:
case
CTBOOL
:
snprint
(
buf1
,
sizeof
(
buf1
),
"B%
ll
d"
,
n
->
val
.
u
.
bval
);
snprint
(
buf1
,
sizeof
(
buf1
),
"B%d"
,
n
->
val
.
u
.
bval
);
break
;
break
;
case
CTNIL
:
case
CTNIL
:
snprint
(
buf1
,
sizeof
(
buf1
),
"N"
);
snprint
(
buf1
,
sizeof
(
buf1
),
"N"
);
...
...
src/cmd/gc/walk.c
View file @
47975235
...
@@ -1399,11 +1399,11 @@ Node*
...
@@ -1399,11 +1399,11 @@ Node*
prcompat
(
Node
*
n
)
prcompat
(
Node
*
n
)
{
{
Node
*
l
,
*
r
;
Node
*
l
,
*
r
;
Node
*
on
;
Type
*
t
;
Type
*
t
;
Iter
save
;
Iter
save
;
int
w
;
int
w
;
char
*
name
;
char
*
name
;
Node
*
on
;
r
=
N
;
r
=
N
;
l
=
listfirst
(
&
save
,
&
n
);
l
=
listfirst
(
&
save
,
&
n
);
...
...
test/ken/rob2.go
View file @
47975235
...
@@ -162,35 +162,34 @@ func NextToken()
...
@@ -162,35 +162,34 @@ func NextToken()
c
=
Get
();
c
=
Get
();
}
}
switch
c
{
switch
c
{
case
EOF
:
case
EOF
:
token
=
EOF
;
token
=
EOF
;
case
'('
:
case
'('
,
')'
:
case
')'
:
token
=
c
;
token
=
c
;
break
;
break
;
default
:
default
:
for
i
=
0
;
i
<
100
-
1
;
{
// sizeof tokenbuf - 1
for
i
=
0
;
i
<
100
-
1
;
{
// sizeof tokenbuf - 1
tokenbuf
[
i
]
=
convert
(
byte
,
c
);
tokenbuf
[
i
]
=
convert
(
byte
,
c
);
i
=
i
+
1
;
i
=
i
+
1
;
c
=
Get
();
c
=
Get
();
if
c
==
EOF
{
if
c
==
EOF
{
break
;
break
;
}
if
WhiteSpace
(
c
)
||
c
==
')'
{
peekc
=
c
;
break
;
}
}
if
i
>=
100
-
1
{
// sizeof tokenbuf - 1
panic
(
"atom too long
\n
"
);
}
}
tokenlen
=
i
;
if
WhiteSpace
(
c
)
||
c
==
')'
{
tokenbuf
[
i
]
=
nilchar
;
peekc
=
c
;
if
'0'
<=
tokenbuf
[
0
]
&&
tokenbuf
[
0
]
<=
'9'
{
break
;
token
=
'0'
;
}
else
{
token
=
'A'
;
}
}
}
if
i
>=
100
-
1
{
// sizeof tokenbuf - 1
panic
(
"atom too long
\n
"
);
}
tokenlen
=
i
;
tokenbuf
[
i
]
=
nilchar
;
if
'0'
<=
tokenbuf
[
0
]
&&
tokenbuf
[
0
]
<=
'9'
{
token
=
'0'
;
}
else
{
token
=
'A'
;
}
}
}
}
}
...
@@ -267,16 +266,15 @@ func Parse() *Slist
...
@@ -267,16 +266,15 @@ func Parse() *Slist
}
else
{
}
else
{
// Atom
// Atom
switch
token
{
switch
token
{
case
EOF
:
case
EOF
:
return
nil
;
return
nil
;
case
'0'
:
case
'0'
:
slist
=
atom
(
atoi
());
slist
=
atom
(
atoi
());
case
'"'
:
case
'"'
,
'A'
:
case
'A'
:
slist
=
atom
(
0
);
slist
=
atom
(
0
);
default
:
default
:
slist
=
nil
;
slist
=
nil
;
print
(
"unknown token: "
,
token
,
"
\n
"
);
print
(
"unknown token"
);
// token, tokenbuf);
}
}
NextToken
();
NextToken
();
return
slist
;
return
slist
;
...
...
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