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
50d0695c
Commit
50d0695c
authored
Dec 09, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use unsafe.pointer in reflection objects
R=rsc DELTA=326 (4 added, 259 deleted, 63 changed) OCL=20853 CL=20856
parent
4ad80467
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
313 deletions
+55
-313
src/lib/fmt/print.go
src/lib/fmt/print.go
+4
-4
src/lib/reflect/Makefile
src/lib/reflect/Makefile
+1
-2
src/lib/reflect/cast_amd64.s
src/lib/reflect/cast_amd64.s
+0
-193
src/lib/reflect/gencast.sh
src/lib/reflect/gencast.sh
+0
-42
src/lib/reflect/tostring.go
src/lib/reflect/tostring.go
+1
-1
src/lib/reflect/value.go
src/lib/reflect/value.go
+49
-71
No files found.
src/lib/fmt/print.go
View file @
50d0695c
...
@@ -272,10 +272,10 @@ func getFloat64(v reflect.Value) (val float64, ok bool) {
...
@@ -272,10 +272,10 @@ func getFloat64(v reflect.Value) (val float64, ok bool) {
return
0.0
,
false
;
return
0.0
,
false
;
}
}
func
getPtr
(
v
reflect
.
Value
)
(
val
uint
64
,
ok
bool
)
{
func
getPtr
(
v
reflect
.
Value
)
(
val
uint
ptr
,
ok
bool
)
{
switch
v
.
Kind
()
{
switch
v
.
Kind
()
{
case
reflect
.
PtrKind
:
case
reflect
.
PtrKind
:
return
v
.
(
reflect
.
PtrValue
)
.
Get
(
),
true
;
return
uintptr
(
v
.
(
reflect
.
PtrValue
)
),
true
;
}
}
return
0
,
false
;
return
0
,
false
;
}
}
...
@@ -356,7 +356,7 @@ func (p *P) printField(field reflect.Value) (was_string bool) {
...
@@ -356,7 +356,7 @@ func (p *P) printField(field reflect.Value) (was_string bool) {
}
else
{
}
else
{
p
.
add
(
'0'
);
p
.
add
(
'0'
);
p
.
add
(
'x'
);
p
.
add
(
'x'
);
s
=
p
.
fmt
.
uX64
(
v
)
.
str
();
s
=
p
.
fmt
.
uX64
(
uint64
(
v
)
)
.
str
();
}
}
}
}
case
reflect
.
StructKind
:
case
reflect
.
StructKind
:
...
@@ -555,7 +555,7 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
...
@@ -555,7 +555,7 @@ func (p *P) doprintf(format string, v reflect.StructValue) {
if
v
==
nil
{
if
v
==
nil
{
s
=
"<nil>"
s
=
"<nil>"
}
else
{
}
else
{
s
=
"0x"
+
p
.
fmt
.
uX64
(
v
)
.
str
()
s
=
"0x"
+
p
.
fmt
.
uX64
(
uint64
(
v
)
)
.
str
()
}
}
}
else
{
}
else
{
goto
badtype
goto
badtype
...
...
src/lib/reflect/Makefile
View file @
50d0695c
...
@@ -32,7 +32,6 @@ coverage: packages
...
@@ -32,7 +32,6 @@ coverage: packages
$(AS)
$*
.s
$(AS)
$*
.s
O1
=
\
O1
=
\
cast_
$(GOARCH)
.
$O
\
type.
$O
\
type.
$O
\
typestring.
$O
\
typestring.
$O
\
...
@@ -45,7 +44,7 @@ O3=\
...
@@ -45,7 +44,7 @@ O3=\
reflect.a
:
a1 a2 a3
reflect.a
:
a1 a2 a3
a1
:
$(O1)
a1
:
$(O1)
$(AR)
grc reflect.a
cast_
$(GOARCH)
.
$O
type.
$O
typestring.
$O
$(AR)
grc reflect.a type.
$O
typestring.
$O
rm
-f
$(O1)
rm
-f
$(O1)
a2
:
$(O2)
a2
:
$(O2)
...
...
src/lib/reflect/cast_amd64.s
deleted
100644 → 0
View file @
4ad80467
//
Conversion
operators
-
really
just
casts
//
**
*
Created
by
gencast
.
sh
-
Do
Not
Edit
***
TEXT
reflect
·
AddrToPtrAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrAddrToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrInt
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrIntToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrInt8
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrInt8ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrInt16
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrInt16ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrInt32
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrInt32ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrInt64
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrInt64ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrUint
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrUintToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrUint8
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrUint8ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrUint16
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrUint16ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrUint32
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrUint32ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrUint64
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrUint64ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrFloat
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrFloatToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrFloat32
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrFloat32ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrFloat64
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrFloat64ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrFloat80
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrFloat80ToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrString
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrStringToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
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
TEXT
reflect
·
AddrToPtrRuntimeArray
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrRuntimeArrayToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
AddrToPtrInterface
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
TEXT
reflect
·
PtrInterfaceToAddr
(
SB
),7,$-8
MOVQ
8
(
SP
),
AX
MOVQ
AX
,
16
(
SP
)
RET
src/lib/reflect/gencast.sh
deleted
100755 → 0
View file @
4ad80467
#!/bin/bash
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
awk
'
BEGIN {
print("// Conversion operators - really just casts")
print("// *** Created by gencast.sh - Do Not Edit ***\n")}
{
print("TEXT reflect·AddrToPtr" $0 "(SB),7,$-8")
print("\tMOVQ 8(SP), AX")
print("\tMOVQ AX, 16(SP)")
print("\tRET")
print("")
print("TEXT reflect·Ptr" $0 "ToAddr(SB),7,$-8")
print("\tMOVQ 8(SP), AX")
print("\tMOVQ AX, 16(SP)")
print("\tRET")
print("")
}
'
>
cast_
$GOARCH
.s <<
'!'
Addr
Int
Int8
Int16
Int32
Int64
Uint
Uint8
Uint16
Uint32
Uint64
Float
Float32
Float64
Float80
String
Bool
RuntimeArray
Interface
!
src/lib/reflect/tostring.go
View file @
50d0695c
...
@@ -171,7 +171,7 @@ func ValueToString(val Value) string {
...
@@ -171,7 +171,7 @@ func ValueToString(val Value) string {
}
}
case
PtrKind
:
case
PtrKind
:
v
:=
val
.
(
PtrValue
);
v
:=
val
.
(
PtrValue
);
return
TypeToString
(
typ
,
false
)
+
"("
+
integer
(
int64
(
v
.
Get
(
)))
+
")"
;
return
TypeToString
(
typ
,
false
)
+
"("
+
integer
(
int64
(
uintptr
(
v
.
Get
()
)))
+
")"
;
case
ArrayKind
:
case
ArrayKind
:
t
:=
typ
.
(
ArrayType
);
t
:=
typ
.
(
ArrayType
);
v
:=
val
.
(
ArrayValue
);
v
:=
val
.
(
ArrayValue
);
...
...
src/lib/reflect/value.go
View file @
50d0695c
...
@@ -9,34 +9,10 @@ package reflect
...
@@ -9,34 +9,10 @@ package reflect
import
(
import
(
"reflect"
;
"reflect"
;
"unsafe"
;
)
)
type
Addr
uint64
// TODO: where are ptrint/intptr etc?
type
Addr
unsafe
.
pointer
// TODO: where are ptrint/intptr etc?
// Conversion functions, implemented in assembler
type
RuntimeArray
struct
func
AddrToPtrAddr
(
Addr
)
*
Addr
func
AddrToPtrInt
(
Addr
)
*
int
func
AddrToPtrInt8
(
Addr
)
*
int8
func
AddrToPtrInt16
(
Addr
)
*
int16
func
AddrToPtrInt32
(
Addr
)
*
int32
func
AddrToPtrInt64
(
Addr
)
*
int64
func
AddrToPtrUint
(
Addr
)
*
uint
func
AddrToPtrUint8
(
Addr
)
*
uint8
func
PtrUint8ToAddr
(
*
uint8
)
Addr
func
AddrToPtrUint16
(
Addr
)
*
uint16
func
AddrToPtrUint32
(
Addr
)
*
uint32
func
AddrToPtrUint64
(
Addr
)
*
uint64
func
PtrUint64ToAddr
(
*
uint64
)
Addr
func
AddrToPtrFloat
(
Addr
)
*
float
func
AddrToPtrFloat32
(
Addr
)
*
float32
func
AddrToPtrFloat64
(
Addr
)
*
float64
func
AddrToPtrFloat80
(
Addr
)
*
float80
func
AddrToPtrString
(
Addr
)
*
string
func
AddrToPtrBool
(
Addr
)
*
bool
func
AddrToPtrRuntimeArray
(
Addr
)
*
RuntimeArray
func
PtrRuntimeArrayToAddr
(
*
RuntimeArray
)
Addr
func
AddrToPtrInterface
(
Addr
)
*
interface
{}
export
type
Value
interface
{
export
type
Value
interface
{
Kind
()
int
;
Kind
()
int
;
...
@@ -66,7 +42,7 @@ func (c *Common) Addr() Addr {
...
@@ -66,7 +42,7 @@ func (c *Common) Addr() Addr {
}
}
func
(
c
*
Common
)
Interface
()
interface
{}
{
func
(
c
*
Common
)
Interface
()
interface
{}
{
return
sys
.
unreflect
(
*
AddrToPtrAddr
(
c
.
addr
),
c
.
typ
.
String
());
return
sys
.
unreflect
(
uint64
(
uintptr
(
*
c
.
addr
.
(
*
Addr
))
),
c
.
typ
.
String
());
}
}
func
NewValueAddr
(
typ
Type
,
addr
Addr
)
Value
func
NewValueAddr
(
typ
Type
,
addr
Addr
)
Value
...
@@ -107,11 +83,11 @@ func IntCreator(typ Type, addr Addr) Value {
...
@@ -107,11 +83,11 @@ func IntCreator(typ Type, addr Addr) Value {
}
}
func
(
v
*
IntValueStruct
)
Get
()
int
{
func
(
v
*
IntValueStruct
)
Get
()
int
{
return
*
AddrToPtrInt
(
v
.
addr
)
return
*
v
.
addr
.
(
*
int
)
}
}
func
(
v
*
IntValueStruct
)
Set
(
i
int
)
{
func
(
v
*
IntValueStruct
)
Set
(
i
int
)
{
*
AddrToPtrInt
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
int
)
=
i
}
}
// -- Int8
// -- Int8
...
@@ -132,11 +108,11 @@ func Int8Creator(typ Type, addr Addr) Value {
...
@@ -132,11 +108,11 @@ func Int8Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Int8ValueStruct
)
Get
()
int8
{
func
(
v
*
Int8ValueStruct
)
Get
()
int8
{
return
*
AddrToPtrInt8
(
v
.
addr
)
return
*
v
.
addr
.
(
*
int8
)
}
}
func
(
v
*
Int8ValueStruct
)
Set
(
i
int8
)
{
func
(
v
*
Int8ValueStruct
)
Set
(
i
int8
)
{
*
AddrToPtrInt8
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
int8
)
=
i
}
}
// -- Int16
// -- Int16
...
@@ -157,11 +133,11 @@ func Int16Creator(typ Type, addr Addr) Value {
...
@@ -157,11 +133,11 @@ func Int16Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Int16ValueStruct
)
Get
()
int16
{
func
(
v
*
Int16ValueStruct
)
Get
()
int16
{
return
*
AddrToPtrInt16
(
v
.
addr
)
return
*
v
.
addr
.
(
*
int16
)
}
}
func
(
v
*
Int16ValueStruct
)
Set
(
i
int16
)
{
func
(
v
*
Int16ValueStruct
)
Set
(
i
int16
)
{
*
AddrToPtrInt16
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
int16
)
=
i
}
}
// -- Int32
// -- Int32
...
@@ -182,11 +158,11 @@ func Int32Creator(typ Type, addr Addr) Value {
...
@@ -182,11 +158,11 @@ func Int32Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Int32ValueStruct
)
Get
()
int32
{
func
(
v
*
Int32ValueStruct
)
Get
()
int32
{
return
*
AddrToPtrInt32
(
v
.
addr
)
return
*
v
.
addr
.
(
*
int32
)
}
}
func
(
v
*
Int32ValueStruct
)
Set
(
i
int32
)
{
func
(
v
*
Int32ValueStruct
)
Set
(
i
int32
)
{
*
AddrToPtrInt32
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
int32
)
=
i
}
}
// -- Int64
// -- Int64
...
@@ -207,11 +183,11 @@ func Int64Creator(typ Type, addr Addr) Value {
...
@@ -207,11 +183,11 @@ func Int64Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Int64ValueStruct
)
Get
()
int64
{
func
(
v
*
Int64ValueStruct
)
Get
()
int64
{
return
*
AddrToPtrInt64
(
v
.
addr
)
return
*
v
.
addr
.
(
*
int64
)
}
}
func
(
v
*
Int64ValueStruct
)
Set
(
i
int64
)
{
func
(
v
*
Int64ValueStruct
)
Set
(
i
int64
)
{
*
AddrToPtrInt64
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
int64
)
=
i
}
}
// -- Uint
// -- Uint
...
@@ -232,11 +208,11 @@ func UintCreator(typ Type, addr Addr) Value {
...
@@ -232,11 +208,11 @@ func UintCreator(typ Type, addr Addr) Value {
}
}
func
(
v
*
UintValueStruct
)
Get
()
uint
{
func
(
v
*
UintValueStruct
)
Get
()
uint
{
return
*
AddrToPtrUint
(
v
.
addr
)
return
*
v
.
addr
.
(
*
uint
)
}
}
func
(
v
*
UintValueStruct
)
Set
(
i
uint
)
{
func
(
v
*
UintValueStruct
)
Set
(
i
uint
)
{
*
AddrToPtrUint
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
uint
)
=
i
}
}
// -- Uint8
// -- Uint8
...
@@ -257,11 +233,11 @@ func Uint8Creator(typ Type, addr Addr) Value {
...
@@ -257,11 +233,11 @@ func Uint8Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Uint8ValueStruct
)
Get
()
uint8
{
func
(
v
*
Uint8ValueStruct
)
Get
()
uint8
{
return
*
AddrToPtrUint8
(
v
.
addr
)
return
*
v
.
addr
.
(
*
uint8
)
}
}
func
(
v
*
Uint8ValueStruct
)
Set
(
i
uint8
)
{
func
(
v
*
Uint8ValueStruct
)
Set
(
i
uint8
)
{
*
AddrToPtrUint8
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
uint8
)
=
i
}
}
// -- Uint16
// -- Uint16
...
@@ -282,11 +258,11 @@ func Uint16Creator(typ Type, addr Addr) Value {
...
@@ -282,11 +258,11 @@ func Uint16Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Uint16ValueStruct
)
Get
()
uint16
{
func
(
v
*
Uint16ValueStruct
)
Get
()
uint16
{
return
*
AddrToPtrUint16
(
v
.
addr
)
return
*
v
.
addr
.
(
*
uint16
)
}
}
func
(
v
*
Uint16ValueStruct
)
Set
(
i
uint16
)
{
func
(
v
*
Uint16ValueStruct
)
Set
(
i
uint16
)
{
*
AddrToPtrUint16
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
uint16
)
=
i
}
}
// -- Uint32
// -- Uint32
...
@@ -307,11 +283,11 @@ func Uint32Creator(typ Type, addr Addr) Value {
...
@@ -307,11 +283,11 @@ func Uint32Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Uint32ValueStruct
)
Get
()
uint32
{
func
(
v
*
Uint32ValueStruct
)
Get
()
uint32
{
return
*
AddrToPtrUint32
(
v
.
addr
)
return
*
v
.
addr
.
(
*
uint32
)
}
}
func
(
v
*
Uint32ValueStruct
)
Set
(
i
uint32
)
{
func
(
v
*
Uint32ValueStruct
)
Set
(
i
uint32
)
{
*
AddrToPtrUint32
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
uint32
)
=
i
}
}
// -- Uint64
// -- Uint64
...
@@ -332,11 +308,11 @@ func Uint64Creator(typ Type, addr Addr) Value {
...
@@ -332,11 +308,11 @@ func Uint64Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Uint64ValueStruct
)
Get
()
uint64
{
func
(
v
*
Uint64ValueStruct
)
Get
()
uint64
{
return
*
AddrToPtrUint64
(
v
.
addr
)
return
*
v
.
addr
.
(
*
uint64
)
}
}
func
(
v
*
Uint64ValueStruct
)
Set
(
i
uint64
)
{
func
(
v
*
Uint64ValueStruct
)
Set
(
i
uint64
)
{
*
AddrToPtrUint64
(
v
.
addr
)
=
i
*
v
.
addr
.
(
*
uint64
)
=
i
}
}
// -- Float
// -- Float
...
@@ -357,11 +333,11 @@ func FloatCreator(typ Type, addr Addr) Value {
...
@@ -357,11 +333,11 @@ func FloatCreator(typ Type, addr Addr) Value {
}
}
func
(
v
*
FloatValueStruct
)
Get
()
float
{
func
(
v
*
FloatValueStruct
)
Get
()
float
{
return
*
AddrToPtrFloat
(
v
.
addr
)
return
*
v
.
addr
.
(
*
float
)
}
}
func
(
v
*
FloatValueStruct
)
Set
(
f
float
)
{
func
(
v
*
FloatValueStruct
)
Set
(
f
float
)
{
*
AddrToPtrFloat
(
v
.
addr
)
=
f
*
v
.
addr
.
(
*
float
)
=
f
}
}
// -- Float32
// -- Float32
...
@@ -382,11 +358,11 @@ func Float32Creator(typ Type, addr Addr) Value {
...
@@ -382,11 +358,11 @@ func Float32Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Float32ValueStruct
)
Get
()
float32
{
func
(
v
*
Float32ValueStruct
)
Get
()
float32
{
return
*
AddrToPtrFloat32
(
v
.
addr
)
return
*
v
.
addr
.
(
*
float32
)
}
}
func
(
v
*
Float32ValueStruct
)
Set
(
f
float32
)
{
func
(
v
*
Float32ValueStruct
)
Set
(
f
float32
)
{
*
AddrToPtrFloat32
(
v
.
addr
)
=
f
*
v
.
addr
.
(
*
float32
)
=
f
}
}
// -- Float64
// -- Float64
...
@@ -407,11 +383,11 @@ func Float64Creator(typ Type, addr Addr) Value {
...
@@ -407,11 +383,11 @@ func Float64Creator(typ Type, addr Addr) Value {
}
}
func
(
v
*
Float64ValueStruct
)
Get
()
float64
{
func
(
v
*
Float64ValueStruct
)
Get
()
float64
{
return
*
AddrToPtrFloat64
(
v
.
addr
)
return
*
v
.
addr
.
(
*
float64
)
}
}
func
(
v
*
Float64ValueStruct
)
Set
(
f
float64
)
{
func
(
v
*
Float64ValueStruct
)
Set
(
f
float64
)
{
*
AddrToPtrFloat64
(
v
.
addr
)
=
f
*
v
.
addr
.
(
*
float64
)
=
f
}
}
// -- Float80
// -- Float80
...
@@ -434,12 +410,11 @@ func Float80Creator(typ Type, addr Addr) Value {
...
@@ -434,12 +410,11 @@ func Float80Creator(typ Type, addr Addr) Value {
/*
/*
BUG: can't gen code for float80s
BUG: can't gen code for float80s
func (v *Float80ValueStruct) Get() float80 {
func (v *Float80ValueStruct) Get() float80 {
return *AddrToPtrFloat80(v.addr)
return *v.addr.(*float80)
return 0;
}
}
func (v *Float80ValueStruct) Set(f float80) {
func (v *Float80ValueStruct) Set(f float80) {
*
AddrToPtrFloat80(v.addr
) = f
*
v.addr.(*float80
) = f
}
}
*/
*/
...
@@ -461,11 +436,11 @@ func StringCreator(typ Type, addr Addr) Value {
...
@@ -461,11 +436,11 @@ func StringCreator(typ Type, addr Addr) Value {
}
}
func
(
v
*
StringValueStruct
)
Get
()
string
{
func
(
v
*
StringValueStruct
)
Get
()
string
{
return
*
AddrToPtrString
(
v
.
addr
)
return
*
v
.
addr
.
(
*
string
)
}
}
func
(
v
*
StringValueStruct
)
Set
(
s
string
)
{
func
(
v
*
StringValueStruct
)
Set
(
s
string
)
{
*
AddrToPtrString
(
v
.
addr
)
=
s
*
v
.
addr
.
(
*
string
)
=
s
}
}
// -- Bool
// -- Bool
...
@@ -486,11 +461,11 @@ func BoolCreator(typ Type, addr Addr) Value {
...
@@ -486,11 +461,11 @@ func BoolCreator(typ Type, addr Addr) Value {
}
}
func
(
v
*
BoolValueStruct
)
Get
()
bool
{
func
(
v
*
BoolValueStruct
)
Get
()
bool
{
return
*
AddrToPtrBool
(
v
.
addr
)
return
*
v
.
addr
.
(
*
bool
)
}
}
func
(
v
*
BoolValueStruct
)
Set
(
b
bool
)
{
func
(
v
*
BoolValueStruct
)
Set
(
b
bool
)
{
*
AddrToPtrBool
(
v
.
addr
)
=
b
*
v
.
addr
.
(
*
bool
)
=
b
}
}
// -- Pointer
// -- Pointer
...
@@ -508,7 +483,7 @@ type PtrValueStruct struct {
...
@@ -508,7 +483,7 @@ type PtrValueStruct struct {
}
}
func
(
v
*
PtrValueStruct
)
Get
()
Addr
{
func
(
v
*
PtrValueStruct
)
Get
()
Addr
{
return
*
AddrToPtrAddr
(
v
.
a
ddr
)
return
*
v
.
addr
.
(
*
A
ddr
)
}
}
func
(
v
*
PtrValueStruct
)
Sub
()
Value
{
func
(
v
*
PtrValueStruct
)
Sub
()
Value
{
...
@@ -521,7 +496,7 @@ func (v *PtrValueStruct) SetSub(subv Value) {
...
@@ -521,7 +496,7 @@ func (v *PtrValueStruct) SetSub(subv Value) {
if
a
!=
b
{
if
a
!=
b
{
panicln
(
"reflect: incompatible types in PtrValue.SetSub:"
,
a
,
b
);
panicln
(
"reflect: incompatible types in PtrValue.SetSub:"
,
a
,
b
);
}
}
*
AddrToPtrAddr
(
v
.
a
ddr
)
=
subv
.
Addr
();
*
v
.
addr
.
(
*
A
ddr
)
=
subv
.
Addr
();
}
}
func
PtrCreator
(
typ
Type
,
addr
Addr
)
Value
{
func
PtrCreator
(
typ
Type
,
addr
Addr
)
Value
{
...
@@ -581,7 +556,8 @@ func (v *OpenArrayValueStruct) SetLen(len int) {
...
@@ -581,7 +556,8 @@ func (v *OpenArrayValueStruct) SetLen(len int) {
}
}
func
(
v
*
OpenArrayValueStruct
)
Elem
(
i
int
)
Value
{
func
(
v
*
OpenArrayValueStruct
)
Elem
(
i
int
)
Value
{
return
NewValueAddr
(
v
.
elemtype
,
v
.
array
.
data
+
Addr
(
i
*
v
.
elemsize
));
data_uint
:=
uintptr
(
v
.
array
.
data
)
+
uintptr
(
i
*
v
.
elemsize
);
return
NewValueAddr
(
v
.
elemtype
,
Addr
(
data_uint
));
}
}
type
FixedArrayValueStruct
struct
{
type
FixedArrayValueStruct
struct
{
...
@@ -607,7 +583,8 @@ func (v *FixedArrayValueStruct) SetLen(len int) {
...
@@ -607,7 +583,8 @@ func (v *FixedArrayValueStruct) SetLen(len int) {
}
}
func
(
v
*
FixedArrayValueStruct
)
Elem
(
i
int
)
Value
{
func
(
v
*
FixedArrayValueStruct
)
Elem
(
i
int
)
Value
{
return
NewValueAddr
(
v
.
elemtype
,
v
.
addr
+
Addr
(
i
*
v
.
elemsize
));
data_uint
:=
uintptr
(
v
.
addr
)
+
uintptr
(
i
*
v
.
elemsize
);
return
NewValueAddr
(
v
.
elemtype
,
Addr
(
data_uint
));
return
nil
return
nil
}
}
...
@@ -620,7 +597,7 @@ func ArrayCreator(typ Type, addr Addr) Value {
...
@@ -620,7 +597,7 @@ func ArrayCreator(typ Type, addr Addr) Value {
v
.
typ
=
typ
;
v
.
typ
=
typ
;
v
.
elemtype
=
arraytype
.
Elem
();
v
.
elemtype
=
arraytype
.
Elem
();
v
.
elemsize
=
v
.
elemtype
.
Size
();
v
.
elemsize
=
v
.
elemtype
.
Size
();
v
.
array
=
AddrToPtrRuntimeArray
(
addr
);
v
.
array
=
addr
.
(
*
RuntimeArray
);
return
v
;
return
v
;
}
}
v
:=
new
(
FixedArrayValueStruct
);
v
:=
new
(
FixedArrayValueStruct
);
...
@@ -702,7 +679,8 @@ func StructCreator(typ Type, addr Addr) Value {
...
@@ -702,7 +679,8 @@ func StructCreator(typ Type, addr Addr) Value {
v
:=
&
StructValueStruct
{
Common
{
StructKind
,
typ
,
addr
},
new
([]
Value
,
nfield
)
};
v
:=
&
StructValueStruct
{
Common
{
StructKind
,
typ
,
addr
},
new
([]
Value
,
nfield
)
};
for
i
:=
0
;
i
<
nfield
;
i
++
{
for
i
:=
0
;
i
<
nfield
;
i
++
{
name
,
ftype
,
str
,
offset
:=
t
.
Field
(
i
);
name
,
ftype
,
str
,
offset
:=
t
.
Field
(
i
);
v
.
field
[
i
]
=
NewValueAddr
(
ftype
,
addr
+
Addr
(
offset
));
addr_uint
:=
uintptr
(
addr
)
+
uintptr
(
offset
);
v
.
field
[
i
]
=
NewValueAddr
(
ftype
,
Addr
(
addr_uint
));
}
}
v
.
typ
=
typ
;
v
.
typ
=
typ
;
return
v
;
return
v
;
...
@@ -721,7 +699,7 @@ type InterfaceValueStruct struct {
...
@@ -721,7 +699,7 @@ type InterfaceValueStruct struct {
}
}
func
(
v
*
InterfaceValueStruct
)
Get
()
interface
{}
{
func
(
v
*
InterfaceValueStruct
)
Get
()
interface
{}
{
return
*
AddrToPtrInterface
(
v
.
addr
);
return
*
v
.
addr
.
(
*
interface
{})
}
}
func
InterfaceCreator
(
typ
Type
,
addr
Addr
)
Value
{
func
InterfaceCreator
(
typ
Type
,
addr
Addr
)
Value
{
...
@@ -799,7 +777,7 @@ export func NewInitValue(typ Type) Value {
...
@@ -799,7 +777,7 @@ export func NewInitValue(typ Type) Value {
size
=
1
;
size
=
1
;
}
}
data
:=
new
([]
uint8
,
size
);
data
:=
new
([]
uint8
,
size
);
return
NewValueAddr
(
typ
,
PtrUint8To
Addr
(
&
data
[
0
]));
return
NewValueAddr
(
typ
,
Addr
(
&
data
[
0
]));
}
}
/*
/*
...
@@ -821,11 +799,11 @@ export func NewOpenArrayValue(typ ArrayType, len, cap int) ArrayValue {
...
@@ -821,11 +799,11 @@ export func NewOpenArrayValue(typ ArrayType, len, cap int) ArrayValue {
size
=
1
;
size
=
1
;
}
}
data
:=
new
([]
uint8
,
size
);
data
:=
new
([]
uint8
,
size
);
array
.
data
=
PtrUint8To
Addr
(
&
data
[
0
]);
array
.
data
=
Addr
(
&
data
[
0
]);
array
.
len
=
uint32
(
len
);
array
.
len
=
uint32
(
len
);
array
.
cap
=
uint32
(
cap
);
array
.
cap
=
uint32
(
cap
);
return
NewValueAddr
(
typ
,
PtrRuntimeArrayTo
Addr
(
array
));
return
NewValueAddr
(
typ
,
Addr
(
array
));
}
}
export
func
NewValue
(
e
interface
{})
Value
{
export
func
NewValue
(
e
interface
{})
Value
{
...
@@ -841,5 +819,5 @@ export func NewValue(e interface {}) Value {
...
@@ -841,5 +819,5 @@ export func NewValue(e interface {}) Value {
// so we can modify the contents. Values contain pointers to 'values'.
// so we can modify the contents. Values contain pointers to 'values'.
ap
:=
new
(
uint64
);
ap
:=
new
(
uint64
);
*
ap
=
value
;
*
ap
=
value
;
return
NewValueAddr
(
*
p
,
PtrUint64ToAddr
(
ap
));
return
NewValueAddr
(
*
p
,
ap
.
(
Addr
));
}
}
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