~repos /plum

#treesitter#compiler#wasm

git clone https://pyrossh.dev/repos/plum.git

A statically typed, imperative programming language inspired by rust, python


b0127295 pyrossh

1 year ago
new syn
example/fn.palm CHANGED
@@ -1,7 +1,25 @@
1
1
  module lambda
2
2
 
3
+ // binary, bool, int, float, str, decimal, time
4
+ // [] for slices []int []str
5
+ // {} for maps [int]int [str]str
6
+ // ? for optional int? str?
7
+ // ! for error types int!, str!
8
+ // nil for optional assignment
9
+
10
+ // 2.0
11
+ // |> math.sqrt()
12
+ // |> math.log()
13
+ // |> math.round()
14
+
3
15
  alias MapCallback = fn(v: a): v
4
16
 
17
+ trait Comparable<a>:
18
+ fn compare(left: a, right: a): bool
19
+
20
+ trait Stringable:
21
+ fn to_str() str
22
+
5
23
  enum Temperature(celsius(float) | fahrenheit(float)) =
6
24
  fn str(self) =
7
25
  match self
@@ -10,6 +28,25 @@ enum Temperature(celsius(float) | fahrenheit(float)) =
10
28
  Temperature::fahrenheit(t) && t > 86 -> "${t}F is above 86 fahrenheit"
11
29
  Temperature::fahrenheit(t) -> "${t}F is below 86 fahrenheit"
12
30
 
31
+ struct str(data: Pointer<u16>, length: int)
32
+ // where is Comparable, Stringable
33
+ fn reverse() =
34
+ let start = 0
35
+ let end = this.length - 1
36
+ let result = []
37
+ while (start < end) ||
38
+ const temp = this[start]
39
+ this[start] = this[end]
40
+ this[end] = temp
41
+ end = end - 1
42
+ start = start + 1
43
+
44
+ fn parse_int(): int! =
45
+ return 0
46
+
47
+ fn parse_float(): float! =
48
+ return 0.0
49
+
13
50
  struct Cat(name: str, age: int) =
14
51
  fn fullname() =
15
52
  name + age.str()
@@ -85,4 +122,201 @@ struct CounterController(db: DB)
85
122
  fn decrement(id: str) =
86
123
  counter <- fetch counterId
87
124
  updatedCounter <- counter |> decrementField #count |> updateRecord
88
- respondHtml $ counterView updatedCounter
125
+ respondHtml $ counterView updatedCounter
126
+
127
+ module palm
128
+
129
+ primitive int is Stringable {
130
+ fn add(y: int) {
131
+ @"llvm.uadd.with.overflow.i32"(this, y)
132
+ }
133
+ fn sub() {
134
+ }
135
+
136
+ fn minus() {
137
+ }
138
+
139
+ fn str() {
140
+ if (this == 0) {
141
+ return "0";
142
+ }
143
+ let result = str(31)
144
+ let i = 0
145
+ let num = this
146
+ while (num != 0) {
147
+ const rem = num % 10
148
+ result.push((rem > 9) ? (rem - 10) + 'a' : rem + '0')
149
+ num = num / 10
150
+ }
151
+ if (this < 0) {
152
+ result.push("-")
153
+ }
154
+ return result.reverse()
155
+ }
156
+
157
+
158
+ // fn str() {
159
+ // ipart = (int)n
160
+ // fpart = n - (float)ipart
161
+ // // convert integer part to string
162
+ // int i = intToStr(ipart, res, 0)
163
+
164
+ // // check for display option after point
165
+ // if (afterpoint != 0) {
166
+ // res[i] = '.'; // add dot
167
+
168
+ // // Get the value of fraction part upto given no.
169
+ // // of points after dot. The third parameter
170
+ // // is needed to handle cases like 233.007
171
+ // fpart = fpart * pow(10, afterpoint);
172
+
173
+ // intToStr((int)fpart, res + i + 1, afterpoint);
174
+ // }
175
+ // }
176
+ }
177
+
178
+ entity decimal {
179
+ mantissa: int
180
+ exponent: float
181
+ }
182
+
183
+ enum List
184
+ | first
185
+ | link(first: a, rest: List<a>)
186
+
187
+ fn sum():
188
+ case this:
189
+ | first => 0
190
+ | link(a, res) => a + sum(res)
191
+ end
192
+ end
193
+ end
194
+
195
+ enitity List<a> {
196
+ data: Pointer
197
+ length: int
198
+
199
+ fn construct(items ...a) {
200
+ repeat(items) |item| {
201
+ data.alloc(item)
202
+ }
203
+ }
204
+ }
205
+
206
+ enum List<a> {
207
+ first
208
+ link(first: a, rest: List<a>)
209
+
210
+ fn op_brackets(items ...a) {
211
+ l = link(items[0])
212
+ range(items.length-2) |i| {
213
+ l.rest = link(items[i+1])
214
+ }
215
+ return l
216
+ }
217
+
218
+ fn sum() {
219
+ match this {
220
+ first => 0
221
+ link(a, res) => a + sum(res)
222
+ }
223
+ }
224
+ }
225
+
226
+ test("List") |t| {
227
+ fn sum(l: List<int>) int {
228
+ return l.reduce(|it| it.value, 0)
229
+ }
230
+
231
+ sum(empty) is 0
232
+ sum(link(1, link(2, link(3, empty)))) is 6
233
+ sum([1, 2, 3]) is 6
234
+ }
235
+
236
+ enum Tree<a> {
237
+ leaf
238
+ node(value: a, left: Tree<a>, right: Tree<a>)
239
+ }
240
+
241
+ fn main() int {
242
+ repeat(10) |i| {
243
+ println(i)
244
+ }
245
+ range(10, 20) |i| {
246
+ println(i)
247
+ }
248
+ }
249
+
250
+
251
+
252
+
253
+
254
+ // fn decrement() {
255
+ // println("decrementing")
256
+ // Cat(...c, age: c.age + 1)
257
+ // }
258
+
259
+ // fn add(x: Int, y: Int) -> Int {
260
+ // x + y
261
+ // }
262
+
263
+ // list
264
+ // .map(|it| it + 1)
265
+ // .each(|_| println("it", it))
266
+
267
+ // test "enum ordinal value" {
268
+ // expect(Value.zero).to_equal(0);
269
+ // expect(Value.one).to_equal(1);
270
+ // expect(Value.two).to_equal(2);
271
+ // }
272
+
273
+ // test("enum ordinal value") |t| {
274
+ // expect(Value.zero).to_equal(0);
275
+ // expect(Value.one).to_equal(1);
276
+ // expect(Value.two).to_equal(2);
277
+ // }
278
+
279
+ // group("Group 1") |g| {
280
+ // test("Test 1") |t| {
281
+
282
+ // }
283
+ // }
284
+
285
+ // bench("1231") |t, n| {
286
+ // }
287
+
288
+ // tree = {
289
+ // value: "Fred",
290
+ // left: {
291
+ // value: "Jim",
292
+ // },
293
+ // right: {
294
+ // value: "Shiela",
295
+ // left: {
296
+ // value: "Alice",
297
+ // },
298
+ // right: {
299
+ // value: "Bob"
300
+ // },
301
+ // },
302
+ // }
303
+
304
+ // Node "Fred" (Node "Jim" Leaf Leaf)
305
+ // (Node "Sheila" (Node "Alice" Leaf Leaf)
306
+ // (Node "Bob" Leaf Leaf))
307
+
308
+
309
+
310
+
311
+
312
+ fun sum(a: Int64, b: Int64): Int64 = a + b
313
+
314
+ fun describe(pet: Pet): String = if pet
315
+ ... is Cat(let name, let lives) { "cat $name has $lives lives" }
316
+ ... is Dog(let name, let years) { "dog $name is $years of age" }
317
+
318
+ List(Cat("Molly", 9), Dog("Fenton", 6))
319
+ .retain(|p| p.name.size > 5)
320
+ .map (|p| describe(p))
321
+ .each (|d| println(d))
322
+ // → dog Fenton is 6 years of age
example/sample.palm DELETED
@@ -1,419 +0,0 @@
1
- module palm
2
-
3
- // byte, *byte, bool, int, float, str, decimal, time
4
- // [] for slices []int []str
5
- // {} for maps [int]int [str]str
6
- // ? for optional int? str?
7
- // ! for error types int!, str!
8
- // nil
9
-
10
- // match a {
11
- // 1, 2, 3 => 0,
12
- // 5...100 => 1,
13
- // else => 9,
14
- // _ => 10
15
- // }
16
-
17
- trait Comparable<a>:
18
- fn compare(left: a, right: a): bool
19
-
20
- trait Stringable:
21
- fn str() str
22
-
23
- entity arr<A>:
24
- val data: *A
25
- val length: int
26
-
27
- fn map(cb: fn(v: A) A):
28
- return cb(a)
29
-
30
- fn each():
31
- pass
32
-
33
- entity number is Comparable, Stringable {
34
- fn sqrt() {
35
- }
36
- fn abs() {
37
- }
38
- fn acos() {
39
- }
40
- fn acosh() {
41
- }
42
- fn asin() {
43
- }
44
- fn asinh() {
45
- }
46
- }
47
-
48
- alias list<a, n : int> = {
49
- data : a[n],
50
- length : uint32
51
- }
52
-
53
-
54
- primitive math {
55
- fn sqrt() {
56
- }
57
-
58
- fn log() {
59
- }
60
-
61
- fn round() {
62
- }
63
- }
64
-
65
- 2.0
66
- |> math.sqrt()
67
- |> math.log()
68
- |> math.round()
69
-
70
- var nn = 2.0
71
-
72
- entity str is Comparable, Stringable {
73
- val data: *u16
74
- val length: int
75
-
76
- // fn reverse() {
77
- // let start = 0
78
- // let end = this.length - 1
79
- // let result = []
80
- // while (start < end) {
81
- // const temp = this[start]
82
- // this[start] = this[end]
83
- // this[end] = temp
84
- // end = end - 1
85
- // start = start + 1
86
- // }
87
- // }
88
-
89
- fn to_int() int! {
90
- if (fail) {
91
- throw errors.int_parse;
92
- }
93
- return 0
94
- }
95
-
96
- fn to_float() float! {
97
- if (fail) {
98
- throw errors.float_parse;
99
- }
100
- return 0.0
101
- }
102
- }
103
-
104
- primitive int is Stringable {
105
- fn add(y: int) {
106
- @"llvm.uadd.with.overflow.i32"(this, y)
107
- }
108
- fn sub() {
109
- }
110
-
111
- fn minus() {
112
- }
113
-
114
- fn str() {
115
- if (this == 0) {
116
- return "0";
117
- }
118
- let result = str(31)
119
- let i = 0
120
- let num = this
121
- while (num != 0) {
122
- const rem = num % 10
123
- result.push((rem > 9) ? (rem - 10) + 'a' : rem + '0')
124
- num = num / 10
125
- }
126
- if (this < 0) {
127
- result.push("-")
128
- }
129
- return result.reverse()
130
- }
131
-
132
- fn str() {
133
- }
134
- }
135
-
136
- primitive float is Stringable {
137
- fn add() {
138
- }
139
- fn sub() {
140
- }
141
- fn minus() {
142
- }
143
-
144
- // fn str() {
145
- // ipart = (int)n
146
- // fpart = n - (float)ipart
147
- // // convert integer part to string
148
- // int i = intToStr(ipart, res, 0)
149
-
150
- // // check for display option after point
151
- // if (afterpoint != 0) {
152
- // res[i] = '.'; // add dot
153
-
154
- // // Get the value of fraction part upto given no.
155
- // // of points after dot. The third parameter
156
- // // is needed to handle cases like 233.007
157
- // fpart = fpart * pow(10, afterpoint);
158
-
159
- // intToStr((int)fpart, res + i + 1, afterpoint);
160
- // }
161
- // }
162
- }
163
-
164
- entity decimal {
165
- mantissa: int
166
- exponent: float
167
- }
168
-
169
- fn println() bool? {
170
- }
171
-
172
- // value Email(str) {
173
- // fn parse() {
174
-
175
- // }
176
- // }
177
-
178
- entity Cat<a> {
179
- first_name: str
180
- middle_name: str
181
- last_name: str
182
-
183
- fn is_equal(other: bool) -> bool {
184
- const dest = "123"
185
- println("123")
186
- // return this == other
187
- }
188
- }
189
-
190
- extension CatExtn on Cat<a> {
191
- fn fullname() {
192
- // return "first_name $middle_name $lastname"
193
- }
194
- }
195
-
196
- trait IO {
197
- fn read()
198
- fn write()
199
- }
200
-
201
- // entity EdgeInsets {
202
- // top, left, bottom, right: float
203
-
204
- // // static fn symmetric(horizontal: double = 0, vertical: double = 0) {
205
- // // return EdgeInsets(left = horizontal, right = horizontal, top = vertical, bottom = vertical)
206
- // // }
207
-
208
- // // static fn only(top: double = 0, left: double = 0, bottom: double = 0, right: double = 0) {
209
- // // return EdgeInsets(top, left, bottom, right)
210
- // // }
211
- // }
212
-
213
- enum bool {
214
- false
215
- true
216
-
217
- fn op_eq(y: bool) bool {
218
- this == y;
219
- }
220
- fn op_ne(y: bool) bool {
221
- this != y
222
- }
223
- fn op_and(y: bool) bool {
224
- this and y
225
- }
226
- fn op_or(y: bool) bool {
227
- this or y
228
- }
229
- fn op_xor(y: bool) bool {
230
- this xor y
231
- }
232
- fn op_not() bool {
233
- !this
234
- }
235
-
236
- fn str() str {
237
- println("123")
238
- // println(1 + 2 + 4 + 5.33 + 7.8km)
239
- }
240
- }
241
-
242
- enum Color {
243
- red
244
- green
245
- blue
246
-
247
- fn log() {
248
- println("log")
249
- }
250
-
251
- fn str() str {
252
- println("Str")
253
- }
254
-
255
- fn where_is() int {
256
- // match a {
257
- // 1, 2, 3 => 0,
258
- // 5...100 => 1,
259
- // else => 9,
260
- // _ => 10
261
- // }
262
- }
263
- }
264
-
265
- enum List
266
- | first
267
- | link(first: a, rest: List<a>)
268
-
269
- fn sum():
270
- case this:
271
- | first => 0
272
- | link(a, res) => a + sum(res)
273
- end
274
- end
275
- end
276
-
277
- enitity List<a> {
278
- data: Pointer
279
- length: int
280
-
281
- fn construct(items ...a) {
282
- repeat(items) |item| {
283
- data.alloc(item)
284
- }
285
- }
286
- }
287
-
288
- enum List<a> {
289
- first
290
- link(first: a, rest: List<a>)
291
-
292
- fn op_brackets(items ...a) {
293
- l = link(items[0])
294
- range(items.length-2) |i| {
295
- l.rest = link(items[i+1])
296
- }
297
- return l
298
- }
299
-
300
- fn sum() {
301
- match this {
302
- first => 0
303
- link(a, res) => a + sum(res)
304
- }
305
- }
306
- }
307
-
308
- test("List") |t| {
309
- fn sum(l: List<int>) int {
310
- return l.reduce(|it| it.value, 0)
311
- }
312
-
313
- sum(empty) is 0
314
- sum(link(1, link(2, link(3, empty)))) is 6
315
- sum([1, 2, 3]) is 6
316
- }
317
-
318
- enum Tree<a> {
319
- leaf
320
- node(value: a, left: Tree<a>, right: Tree<a>)
321
- }
322
-
323
- fn main() int {
324
- repeat(10) |i| {
325
- println(i)
326
- }
327
- range(10, 20) |i| {
328
- println(i)
329
- }
330
- }
331
-
332
-
333
-
334
-
335
-
336
- // fn decrement() {
337
- // println("decrementing")
338
- // Cat(...c, age: c.age + 1)
339
- // }
340
-
341
- // fn add(x: Int, y: Int) -> Int {
342
- // x + y
343
- // }
344
-
345
- // list
346
- // .map(|it| it + 1)
347
- // .each(|_| println("it", it))
348
-
349
- // test "enum ordinal value" {
350
- // expect(Value.zero).to_equal(0);
351
- // expect(Value.one).to_equal(1);
352
- // expect(Value.two).to_equal(2);
353
- // }
354
-
355
- // test("enum ordinal value") |t| {
356
- // expect(Value.zero).to_equal(0);
357
- // expect(Value.one).to_equal(1);
358
- // expect(Value.two).to_equal(2);
359
- // }
360
-
361
- // group("Group 1") |g| {
362
- // test("Test 1") |t| {
363
-
364
- // }
365
- // }
366
-
367
- // bench("1231") |t, n| {
368
- // }
369
-
370
- // tree = {
371
- // value: "Fred",
372
- // left: {
373
- // value: "Jim",
374
- // },
375
- // right: {
376
- // value: "Shiela",
377
- // left: {
378
- // value: "Alice",
379
- // },
380
- // right: {
381
- // value: "Bob"
382
- // },
383
- // },
384
- // }
385
-
386
- // Node "Fred" (Node "Jim" Leaf Leaf)
387
- // (Node "Sheila" (Node "Alice" Leaf Leaf)
388
- // (Node "Bob" Leaf Leaf))
389
-
390
-
391
-
392
-
393
-
394
- class Cat(let name: String, let lives: Int64)
395
- class Dog(let name: String, let years: Int64)
396
- union Pet of Cat, Dog
397
-
398
-
399
- class Person(
400
- let firstName: String,
401
- let lastName: String,
402
- var age: Int64
403
- ) {
404
- fun fullName(): String = "${self.firstName} ${self.lastName}"
405
- }
406
-
407
- fun sum(a: Int64, b: Int64): Int64 = a + b
408
-
409
- 2.0.sqrt()
410
-
411
- fun describe(pet: Pet): String = if pet
412
- ... is Cat(let name, let lives) { "cat $name has $lives lives" }
413
- ... is Dog(let name, let years) { "dog $name is $years of age" }
414
-
415
- List(Cat("Molly", 9), Dog("Fenton", 6))
416
- .retain(|p| p.name.size > 5)
417
- .map (|p| describe(p))
418
- .each (|d| println(d))
419
- // → dog Fenton is 6 years of age
example/std/float.mi DELETED
@@ -1,97 +0,0 @@
1
- module std
2
-
3
- primitive float =
4
- E = 2.718f // Represents Euler's number, the base of natural logarithms, e
5
- LN10 = 2.302f // Represents the natural logarithm of 10
6
- LN2 = 0.693f // Represents the natural logarithm of 2
7
- LOG10E = 0.434f // Represents the base 10 logarithm of e
8
- LOG2E = 1.442f // Represents the base 2 logarithm of e
9
- PI = 3.14159f // Represents the ratio of the circumference of a circle to its diameter
10
- SQRT1_2 = 0.707f // Represents the square root of 1/2
11
- SQRT2 = 1.414f // Represents the square root of 2
12
-
13
- EPSILON = 2.220446049250313e-16f // Represents the difference between 1 and the smallest floating point number greater than 1
14
- // MAX_SAFE_INTEGER
15
- // MAX_VALUE
16
- // MIN_SAFE_INTEGER
17
- // MIN_VALUE
18
- // NEGATIVE_INFINITY
19
- // POSITIVE_INFINITY
20
-
21
- // Returns the absolute value of a number
22
- fn abs(v: float) = a < 0 ? -a : a
23
-
24
- fn acos(v: float) = 0f
25
- fn acosh(v: float) = 0f
26
- fn asin(v: float) = 0f
27
- fn asinh(v: float) = 0f
28
- fn atan(v: float) = 0f
29
- fn atan2(v: float) = 0f
30
- fn atanh(v: float) = 0f
31
- fn cbrt(v: float) = 0f
32
- fn ceil(v: float) = 0f
33
- fn clz32(v: float) = 0f
34
- fn cos(v: float) = 0f
35
- fn cosh(v: float) = 0f
36
- fn exp(v: float) = 0f
37
- fn to_int(): int = 0
38
- fn to_str(): str = ""
39
-
40
- fn random(): float =
41
- 0.0f
42
-
43
- fn parse(s: str) =
44
- 0.0f
45
-
46
- fn is_int(): bool = true
47
-
48
-
49
- // Check whether this number is finite, ie not +/-infinity and not NaN.
50
- fn is_finite(): bool = true
51
- // True if exponent is not all 1s
52
- // (bits() and 0x7FF0_0000_0000_0000) != 0x7FF0_0000_0000_0000
53
-
54
- // Check whether this number is +/-infinity
55
- fn is_infinite(): Bool =>
56
- // True if exponent is all 1s and mantissa is 0
57
- ((bits() and 0x7FF0_0000_0000_0000) == 0x7FF0_0000_0000_0000) and // exp
58
- ((bits() and 0x000F_FFFF_FFFF_FFFF) == 0) // mantissa
59
-
60
- // Check whether this number is NaN.
61
- fn is_nan(): Bool =>
62
- // True if exponent is all 1s and mantissa is non-0
63
- ((bits() and 0x7FF0_0000_0000_0000) == 0x7FF0_0000_0000_0000) and // exp
64
- ((bits() and 0x000F_FFFF_FFFF_FFFF) != 0) // mantissa
65
-
66
- fn to_exponential(v: float): str = ""
67
-
68
- fn to_fixed(v: float): str = ""
69
-
70
- fn to_precision(v: float): str = ""
71
-
72
-
73
- fn abs(): F64 = @"llvm.fabs.f64"(this)
74
- fn ceil(): F64 = @"llvm.ceil.f64"(this)
75
- fn floor(): F64 = @"llvm.floor.f64"(this)
76
- fn round(): F64 = @"llvm.round.f64"(this)
77
- fn trunc(): F64 = @"llvm.trunc.f64"(this)
78
-
79
- fun log(): F64 => @"llvm.log.f64"(this)
80
- fun log2(): F64 => @"llvm.log2.f64"(this)
81
- fun log10(): F64 => @"llvm.log10.f64"(this)
82
- fun logb(): F64 => @logb(this)
83
-
84
- fun pow(y: F64): F64 => @"llvm.pow.f64"(this, y)
85
- fun powi(y: I32): F64 =>
86
- ifdef windows then
87
- pow(y.f64())
88
- else
89
- @"llvm.powi.f64"(this, y)
90
- end
91
-
92
- fun sqrt(): F64 =>
93
- if this < 0.0 then
94
- _nan()
95
- else
96
- @"llvm.sqrt.f64"(this)
97
- end
example/std/map.mi CHANGED
@@ -0,0 +1,14 @@
1
+ map
2
+
3
+ entity Map()
4
+
5
+ fn new() =
6
+ alloc Map
7
+
8
+ fn get()
9
+
10
+ fn set()
11
+
12
+ fn
13
+
14
+
example/std/math.mi ADDED
@@ -0,0 +1,95 @@
1
+ module math
2
+
3
+ E = 2.718f // Represents Euler's number, the base of natural logarithms, e
4
+ LN10 = 2.302f // Represents the natural logarithm of 10
5
+ LN2 = 0.693f // Represents the natural logarithm of 2
6
+ LOG10E = 0.434f // Represents the base 10 logarithm of e
7
+ LOG2E = 1.442f // Represents the base 2 logarithm of e
8
+ PI = 3.14159f // Represents the ratio of the circumference of a circle to its diameter
9
+ SQRT1_2 = 0.707f // Represents the square root of 1/2
10
+ SQRT2 = 1.414f // Represents the square root of 2
11
+ EPSILON = 2.220446049250313e-16f // Represents the difference between 1 and the smallest floating point number greater than 1
12
+ MAX_SAFE_INTEGER
13
+ MAX_VALUE
14
+ MIN_SAFE_INTEGER
15
+ MIN_VALUE
16
+ NEGATIVE_INFINITY
17
+ POSITIVE_INFINITY
18
+
19
+ // Returns the absolute value of a number
20
+ abs: fn(v: float): float = a < 0 ? -a : a
21
+
22
+ acos: fn(v: float) = 0f
23
+ fn acosh(v: float) = 0f
24
+ fn asin(v: float) = 0f
25
+ fn asinh(v: float) = 0f
26
+ fn atan(v: float) = 0f
27
+ fn atan2(v: float) = 0f
28
+ fn atanh(v: float) = 0f
29
+ fn cbrt(v: float) = 0f
30
+ fn ceil(v: float) = 0f
31
+ fn clz32(v: float) = 0f
32
+ fn cos(v: float) = 0f
33
+ fn cosh(v: float) = 0f
34
+ fn exp(v: float) = 0f
35
+ fn to_int(): int = 0
36
+ fn to_str(): str = ""
37
+
38
+ random: fn(): float =
39
+ 0.0f
40
+
41
+ fn parse(s: str) =
42
+ 0.0f
43
+
44
+ fn is_int(): bool = true
45
+
46
+
47
+ // Check whether this number is finite, ie not +/-infinity and not NaN.
48
+ fn is_finite(): bool = true
49
+ // True if exponent is not all 1s
50
+ // (bits() and 0x7FF0_0000_0000_0000) != 0x7FF0_0000_0000_0000
51
+
52
+ // Check whether this number is +/-infinity
53
+ fn is_infinite(): Bool =>
54
+ // True if exponent is all 1s and mantissa is 0
55
+ ((bits() and 0x7FF0_0000_0000_0000) == 0x7FF0_0000_0000_0000) and // exp
56
+ ((bits() and 0x000F_FFFF_FFFF_FFFF) == 0) // mantissa
57
+
58
+ // Check whether this number is NaN.
59
+ fn is_nan(): Bool =>
60
+ // True if exponent is all 1s and mantissa is non-0
61
+ ((bits() and 0x7FF0_0000_0000_0000) == 0x7FF0_0000_0000_0000) and // exp
62
+ ((bits() and 0x000F_FFFF_FFFF_FFFF) != 0) // mantissa
63
+
64
+ fn to_exponential(v: float): str = ""
65
+
66
+ fn to_fixed(v: float): str = ""
67
+
68
+ fn to_precision(v: float): str = ""
69
+
70
+
71
+ fn abs(): F64 = @"llvm.fabs.f64"(this)
72
+ fn ceil(): F64 = @"llvm.ceil.f64"(this)
73
+ fn floor(): F64 = @"llvm.floor.f64"(this)
74
+ fn round(): F64 = @"llvm.round.f64"(this)
75
+ fn trunc(): F64 = @"llvm.trunc.f64"(this)
76
+
77
+ fun log(): F64 => @"llvm.log.f64"(this)
78
+ fun log2(): F64 => @"llvm.log2.f64"(this)
79
+ fun log10(): F64 => @"llvm.log10.f64"(this)
80
+ fun logb(): F64 => @logb(this)
81
+
82
+ fun pow(y: F64): F64 => @"llvm.pow.f64"(this, y)
83
+ fun powi(y: I32): F64 =>
84
+ ifdef windows then
85
+ pow(y.f64())
86
+ else
87
+ @"llvm.powi.f64"(this, y)
88
+ end
89
+
90
+ fun sqrt(): F64 =>
91
+ if this < 0.0 then
92
+ _nan()
93
+ else
94
+ @"llvm.sqrt.f64"(this)
95
+ end