-
Notifications
You must be signed in to change notification settings - Fork 0
/
int64.go
115 lines (91 loc) · 1.83 KB
/
int64.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package value
import (
"encoding/binary"
"fmt"
"strconv"
"github.com/cespare/xxhash/v2"
)
var Int64Class *Class // ::Std::Int64
// Elk's Int64 value
type Int64 int64
func (i Int64) Class() *Class {
return Int64Class
}
func (Int64) DirectClass() *Class {
return Int64Class
}
func (Int64) SingletonClass() *Class {
return nil
}
// Convert to Elk String.
func (i Int64) ToString() String {
return String(strconv.FormatInt(int64(i), 10))
}
// Convert to Elk SmallInt.
func (i Int64) ToSmallInt() SmallInt {
return SmallInt(i)
}
// Convert to Elk Float.
func (i Int64) ToFloat() Float {
return Float(i)
}
// Convert to Elk Float64.
func (i Int64) ToFloat64() Float64 {
return Float64(i)
}
// Convert to Elk Float32.
func (i Int64) ToFloat32() Float32 {
return Float32(i)
}
// Convert to Elk Int32.
func (i Int64) ToInt32() Int32 {
return Int32(i)
}
// Convert to Elk Int16.
func (i Int64) ToInt16() Int16 {
return Int16(i)
}
// Convert to Elk Int8.
func (i Int64) ToInt8() Int8 {
return Int8(i)
}
// Convert to Elk UInt64.
func (i Int64) ToUInt64() UInt64 {
return UInt64(i)
}
// Convert to Elk UInt32.
func (i Int64) ToUInt32() UInt32 {
return UInt32(i)
}
// Convert to Elk UInt16.
func (i Int64) ToUInt16() UInt16 {
return UInt16(i)
}
// Convert to Elk UInt8.
func (i Int64) ToUInt8() UInt8 {
return UInt8(i)
}
func (i Int64) Copy() Value {
return i
}
func (i Int64) Inspect() string {
return fmt.Sprintf("%di64", i)
}
func (i Int64) InstanceVariables() SymbolMap {
return nil
}
func (i Int64) Hash() UInt64 {
d := xxhash.New()
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, uint64(i))
d.Write(b)
return UInt64(d.Sum64())
}
func initInt64() {
Int64Class = NewClassWithOptions(
ClassWithParent(NumericClass),
ClassWithSealed(),
ClassWithNoInstanceVariables(),
)
StdModule.AddConstantString("Int64", Int64Class)
}