/
format.gleam
197 lines (168 loc) Β· 3.25 KB
/
format.gleam
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import gleam/string
/// Numerical formats for tensors.
///
/// Each `Format` uses a set number of bits to represent every `Float`-like or
/// `Int`-like value.
///
pub opaque type Format(a) {
Format(a)
}
/// A 32-bit floating point type, argamak's standard for working with floats.
///
pub type Float32 {
Float32
}
/// Creates a 32-bit floating point `Format`, argamak's standard for working
/// with floats.
///
pub fn float32() -> Format(Float32) {
Format(Float32)
}
/// A 32-bit signed integer type, argamak's standard for working with ints.
///
pub type Int32 {
Int32
}
/// Creates a 32-bit signed integer `Format`, argamak's standard for working
/// with ints.
///
pub fn int32() -> Format(Int32) {
Format(Int32)
}
@target(erlang)
/// A 64-bit floating point type.
///
pub type Float64 {
Float64
}
@target(erlang)
/// Creates a 64-bit floating point `Format`.
///
pub fn float64() -> Format(Float64) {
Format(Float64)
}
@target(erlang)
/// A 64-bit signed integer type.
///
pub type Int64 {
Int64
}
@target(erlang)
/// Creates a 64-bit signed integer `Format`.
///
pub fn int64() -> Format(Int64) {
Format(Int64)
}
@target(erlang)
/// A 64-bit unsigned integer type.
///
pub type Uint64 {
Uint64
}
@target(erlang)
/// Creates a 64-bit unsigned integer `Format`.
///
pub fn uint64() -> Format(Uint64) {
Format(Uint64)
}
@target(erlang)
/// A 32-bit unsigned integer type.
///
pub type Uint32 {
Uint32
}
@target(erlang)
/// Creates a 32-bit unsigned integer `Format`.
///
pub fn uint32() -> Format(Uint32) {
Format(Uint32)
}
@target(erlang)
/// A 16-bit brain floating point type.
///
pub type Bfloat16 {
Bfloat16
}
@target(erlang)
/// Creates a 16-bit brain floating point `Format`.
///
pub fn bfloat16() -> Format(Bfloat16) {
Format(Bfloat16)
}
@target(erlang)
/// A 16-bit floating point type.
///
pub type Float16 {
Float16
}
@target(erlang)
/// Creates a 16-bit floating point `Format`.
///
pub fn float16() -> Format(Float16) {
Format(Float16)
}
@target(erlang)
/// A 16-bit signed integer type.
///
pub type Int16 {
Int16
}
@target(erlang)
/// Creates a 16-bit signed integer `Format`.
///
pub fn int16() -> Format(Int16) {
Format(Int16)
}
@target(erlang)
/// A 16-bit unsigned integer type.
///
pub type Uint16 {
Uint16
}
@target(erlang)
/// Creates a 16-bit unsigned integer `Format`.
///
pub fn uint16() -> Format(Uint16) {
Format(Uint16)
}
@target(erlang)
/// An 8-bit signed integer type.
///
pub type Int8 {
Int8
}
@target(erlang)
/// Creates an 8-bit signed integer `Format`.
///
pub fn int8() -> Format(Int8) {
Format(Int8)
}
@target(erlang)
/// An 8-bit unsigned integer type.
///
pub type Uint8 {
Uint8
}
@target(erlang)
/// Creates an 8-bit unsigned integer `Format`.
///
pub fn uint8() -> Format(Uint8) {
Format(Uint8)
}
/// A type for `Native` format representations.
///
pub type Native
/// Converts a given `Format` into its native representation.
///
pub fn to_native(format: Format(a)) -> Native {
let Format(x) = format
do_to_native(x)
}
@external(erlang, "argamak_ffi", "format_to_native")
@external(javascript, "../argamak_ffi.mjs", "format_to_native")
fn do_to_native(format: a) -> Native
/// Converts a `Format` into a `String`.
///
pub fn to_string(format: Format(a)) -> String {
string.inspect(format)
}