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
16fd3566
Commit
16fd3566
authored
Oct 31, 2008
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for the basic type "bool".
R=r DELTA=51 (51 added, 0 deleted, 0 changed) OCL=18283 CL=18290
parent
613a5c8b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
0 deletions
+51
-0
src/lib/reflect/cast_amd64.s
src/lib/reflect/cast_amd64.s
+10
-0
src/lib/reflect/gencast.sh
src/lib/reflect/gencast.sh
+1
-0
src/lib/reflect/test.go
src/lib/reflect/test.go
+3
-0
src/lib/reflect/tostring.go
src/lib/reflect/tostring.go
+6
-0
src/lib/reflect/type.go
src/lib/reflect/type.go
+4
-0
src/lib/reflect/value.go
src/lib/reflect/value.go
+27
-0
No files found.
src/lib/reflect/cast_amd64.s
View file @
16fd3566
...
...
@@ -161,3 +161,13 @@ TEXT reflect·PtrStringToAddr(SB),7,$-8
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrBool
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrBoolToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
src/lib/reflect/gencast.sh
View file @
16fd3566
...
...
@@ -36,4 +36,5 @@ Float32
Float64
Float80
String
Bool
!
src/lib/reflect/test.go
View file @
16fd3566
...
...
@@ -77,6 +77,8 @@ func valuedump(s, t string) {
v
.
(
reflect
.
Float64Value
)
.
Put
(
64.0
);
case
reflect
.
StringKind
:
v
.
(
reflect
.
StringValue
)
.
Put
(
"stringy cheese"
);
case
reflect
.
BoolKind
:
v
.
(
reflect
.
BoolValue
)
.
Put
(
true
);
}
assert
(
reflect
.
ValueToString
(
v
),
t
);
}
...
...
@@ -132,6 +134,7 @@ func main() {
valuedump
(
"float32"
,
"+3.200000e+01"
);
valuedump
(
"float64"
,
"+6.400000e+01"
);
valuedump
(
"string"
,
"stringy cheese"
);
valuedump
(
"bool"
,
"true"
);
valuedump
(
"*int8"
,
"*int8(0)"
);
valuedump
(
"**int8"
,
"**int8(0)"
);
valuedump
(
"[5]int32"
,
"[5]int32{0, 0, 0, 0, 0}"
);
...
...
src/lib/reflect/tostring.go
View file @
16fd3566
...
...
@@ -162,6 +162,12 @@ func ValueToString(val Value) string {
return
"float80"
;
case
StringKind
:
return
val
.
(
StringValue
)
.
Get
();
case
BoolKind
:
if
val
.
(
BoolValue
)
.
Get
()
{
return
"true"
}
else
{
return
"false"
}
case
PtrKind
:
v
:=
val
.
(
PtrValue
);
return
TypeToString
(
typ
,
false
)
+
"("
+
integer
(
int64
(
v
.
Get
()))
+
")"
;
...
...
src/lib/reflect/type.go
View file @
16fd3566
...
...
@@ -16,6 +16,7 @@ export func typestrings() string // implemented in C; declared here
export
const
(
MissingKind
=
iota
;
ArrayKind
;
BoolKind
;
ChanKind
;
FloatKind
;
Float32Kind
;
...
...
@@ -82,6 +83,7 @@ func NewBasicType(name string, kind int, size uint64) Type {
// Prebuilt basic types
export
var
(
Missing
=
NewBasicType
(
MissingString
,
MissingKind
,
1
);
Bool
=
NewBasicType
(
"bool"
,
BoolKind
,
1
);
// TODO: need to know how big a bool is
Int
=
NewBasicType
(
"int"
,
IntKind
,
4
);
// TODO: need to know how big an int is
Int8
=
NewBasicType
(
"int8"
,
Int8Kind
,
1
);
Int16
=
NewBasicType
(
"int16"
,
Int16Kind
,
2
);
...
...
@@ -409,6 +411,7 @@ func init() {
types
[
"float64"
]
=
&
Float64
;
types
[
"float80"
]
=
&
Float80
;
types
[
"string"
]
=
&
String
;
types
[
"bool"
]
=
&
Bool
;
// Basics get prebuilt stubs
MissingStub
=
NewStubType
(
MissingString
,
Missing
);
...
...
@@ -428,6 +431,7 @@ func init() {
basicstub
[
"float64"
]
=
NewStubType
(
"float64"
,
Float64
);
basicstub
[
"float80"
]
=
NewStubType
(
"float80"
,
Float80
);
basicstub
[
"string"
]
=
NewStubType
(
"string"
,
String
);
basicstub
[
"bool"
]
=
NewStubType
(
"bool"
,
Bool
);
Unlock
();
}
...
...
src/lib/reflect/value.go
View file @
16fd3566
...
...
@@ -58,6 +58,7 @@ func AddrToPtrFloat32(Addr) *float32
func
AddrToPtrFloat64
(
Addr
)
*
float64
func
AddrToPtrFloat80
(
Addr
)
*
float80
func
AddrToPtrString
(
Addr
)
*
string
func
AddrToPtrBool
(
Addr
)
*
bool
// -- Int
...
...
@@ -438,6 +439,31 @@ func (v *StringValueStruct) Put(s string) {
*
AddrToPtrString
(
v
.
addr
)
=
s
}
// -- Bool
export
type
BoolValue
interface
{
Kind
()
int
;
Get
()
bool
;
Put
(
bool
);
Type
()
Type
;
}
type
BoolValueStruct
struct
{
CommonV
}
func
BoolCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
BoolValueStruct
{
CommonV
{
BoolKind
,
typ
,
addr
}
}
}
func
(
v
*
BoolValueStruct
)
Get
()
bool
{
return
*
AddrToPtrBool
(
v
.
addr
)
}
func
(
v
*
BoolValueStruct
)
Put
(
b
bool
)
{
*
AddrToPtrBool
(
v
.
addr
)
=
b
}
// -- Pointer
export
type
PtrValue
interface
{
...
...
@@ -665,6 +691,7 @@ func init() {
creator
[
Float64Kind
]
=
&
Float64Creator
;
creator
[
Float80Kind
]
=
&
Float80Creator
;
creator
[
StringKind
]
=
&
StringCreator
;
creator
[
BoolKind
]
=
&
BoolCreator
;
creator
[
PtrKind
]
=
&
PtrCreator
;
creator
[
ArrayKind
]
=
&
ArrayCreator
;
creator
[
MapKind
]
=
&
MapCreator
;
...
...
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