-
Notifications
You must be signed in to change notification settings - Fork 0
/
int32.go
115 lines (91 loc) · 1.82 KB
/
int32.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 Int32Class *Class // ::Std::Int32
// Elk's Int32 value
type Int32 int32
func (i Int32) Class() *Class {
return Int32Class
}
func (Int32) DirectClass() *Class {
return Int32Class
}
func (Int32) SingletonClass() *Class {
return nil
}
// Convert to Elk String.
func (i Int32) ToString() String {
return String(strconv.Itoa(int(i)))
}
// Convert to Elk SmallInt.
func (i Int32) ToSmallInt() SmallInt {
return SmallInt(i)
}
// Convert to Elk Float.
func (i Int32) ToFloat() Float {
return Float(i)
}
// Convert to Elk Float64.
func (i Int32) ToFloat64() Float64 {
return Float64(i)
}
// Convert to Elk Float32.
func (i Int32) ToFloat32() Float32 {
return Float32(i)
}
// Convert to Elk Int64.
func (i Int32) ToInt64() Int64 {
return Int64(i)
}
// Convert to Elk Int16.
func (i Int32) ToInt16() Int16 {
return Int16(i)
}
// Convert to Elk Int8.
func (i Int32) ToInt8() Int8 {
return Int8(i)
}
// Convert to Elk UInt64.
func (i Int32) ToUInt64() UInt64 {
return UInt64(i)
}
// Convert to Elk UInt32.
func (i Int32) ToUInt32() UInt32 {
return UInt32(i)
}
// Convert to Elk UInt16.
func (i Int32) ToUInt16() UInt16 {
return UInt16(i)
}
// Convert to Elk UInt8.
func (i Int32) ToUInt8() UInt8 {
return UInt8(i)
}
func (i Int32) Copy() Value {
return i
}
func (i Int32) Inspect() string {
return fmt.Sprintf("%di32", i)
}
func (i Int32) InstanceVariables() SymbolMap {
return nil
}
func (i Int32) Hash() UInt64 {
d := xxhash.New()
b := make([]byte, 4)
binary.LittleEndian.PutUint32(b, uint32(i))
d.Write(b)
return UInt64(d.Sum64())
}
func initInt32() {
Int32Class = NewClassWithOptions(
ClassWithParent(NumericClass),
ClassWithSealed(),
ClassWithNoInstanceVariables(),
)
StdModule.AddConstantString("Int32", Int32Class)
}