nomen-lang 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOMEN_AGENTS.md +235 -0
- package/core/System/Ansi.nm +150 -0
- package/core/System/Array.nm +358 -0
- package/core/System/BigInt.nm +887 -0
- package/core/System/Buffer.nm +526 -0
- package/core/System/Channel.nm +198 -0
- package/core/System/ClassBuffer.nm +229 -0
- package/core/System/Console.nm +211 -0
- package/core/System/Controls/Button.nm +138 -0
- package/core/System/Controls/CheckBox.nm +158 -0
- package/core/System/Controls/Container.nm +1562 -0
- package/core/System/Controls/Control.nm +28 -0
- package/core/System/Controls/Geometry.nm +101 -0
- package/core/System/Controls/Layout.nm +228 -0
- package/core/System/Controls/LayoutParams.nm +50 -0
- package/core/System/Controls/Text.nm +129 -0
- package/core/System/Controls/TextBox.nm +157 -0
- package/core/System/Controls/Window.nm +280 -0
- package/core/System/Disposable.nm +8 -0
- package/core/System/Enumerable.nm +10 -0
- package/core/System/Equatable.nm +10 -0
- package/core/System/Graph.nm +68 -0
- package/core/System/Hashable.nm +13 -0
- package/core/System/Init.nm +21 -0
- package/core/System/LinkedList.nm +64 -0
- package/core/System/List.nm +44 -0
- package/core/System/Map.nm +153 -0
- package/core/System/Math.nm +54 -0
- package/core/System/Mutex.nm +78 -0
- package/core/System/Nursery.nm +27 -0
- package/core/System/Sendable.nm +9 -0
- package/core/System/Set.nm +97 -0
- package/core/System/Stream/Directory.nm +176 -0
- package/core/System/Stream/File.nm +432 -0
- package/core/System/Stream/Http.nm +453 -0
- package/core/System/String.nm +154 -0
- package/core/System/StringBuilder.nm +249 -0
- package/core/System/Stringable.nm +8 -0
- package/core/System/Task.nm +263 -0
- package/core/System/Test.nm +241 -0
- package/core/System/Text/Json.nm +377 -0
- package/core/System/Text/JsonTree.nm +187 -0
- package/core/System/Text/Regex.nm +655 -0
- package/core/System/Time.nm +112 -0
- package/core/System/Tree.nm +70 -0
- package/core/System/Viewable.nm +27 -0
- package/core/System/bool.nm +66 -0
- package/core/System/char.nm +42 -0
- package/core/System/float.nm +43 -0
- package/core/System/int.nm +54 -0
- package/core/System/int64.nm +42 -0
- package/core/System/int8.nm +42 -0
- package/core/System/uint.nm +42 -0
- package/core/System/uint64.nm +42 -0
- package/core/System/uint8.nm +42 -0
- package/core/docs/System/Ansi.md +40 -0
- package/core/docs/System/Array.md +16 -0
- package/core/docs/System/BigInt.md +30 -0
- package/core/docs/System/Buffer.md +31 -0
- package/core/docs/System/Channel.md +10 -0
- package/core/docs/System/ClassBuffer.md +15 -0
- package/core/docs/System/Console.md +13 -0
- package/core/docs/System/Controls/Button.md +12 -0
- package/core/docs/System/Controls/CheckBox.md +15 -0
- package/core/docs/System/Controls/Container.md +82 -0
- package/core/docs/System/Controls/Control.md +5 -0
- package/core/docs/System/Controls/Geometry.md +26 -0
- package/core/docs/System/Controls/Layout.md +37 -0
- package/core/docs/System/Controls/LayoutParams.md +13 -0
- package/core/docs/System/Controls/Text.md +12 -0
- package/core/docs/System/Controls/TextBox.md +13 -0
- package/core/docs/System/Controls/Window.md +20 -0
- package/core/docs/System/Disposable.md +5 -0
- package/core/docs/System/Enumerable.md +5 -0
- package/core/docs/System/Graph.md +17 -0
- package/core/docs/System/Init.md +9 -0
- package/core/docs/System/LinkedList.md +16 -0
- package/core/docs/System/List.md +13 -0
- package/core/docs/System/Map.md +14 -0
- package/core/docs/System/Math.md +11 -0
- package/core/docs/System/Mutex.md +10 -0
- package/core/docs/System/Nursery.md +5 -0
- package/core/docs/System/Sendable.md +5 -0
- package/core/docs/System/Set.md +14 -0
- package/core/docs/System/Stream/Directory.md +12 -0
- package/core/docs/System/Stream/File.md +21 -0
- package/core/docs/System/String.md +14 -0
- package/core/docs/System/StringBuilder.md +12 -0
- package/core/docs/System/Stringable.md +5 -0
- package/core/docs/System/Task.md +15 -0
- package/core/docs/System/Text/Json.md +12 -0
- package/core/docs/System/Text/JsonTree.md +21 -0
- package/core/docs/System/Text/Regex.md +12 -0
- package/core/docs/System/Time.md +11 -0
- package/core/docs/System/Tree.md +18 -0
- package/core/docs/System/Viewable.md +5 -0
- package/core/docs/System/bool.md +9 -0
- package/core/docs/System/char.md +9 -0
- package/core/docs/System/float.md +9 -0
- package/core/docs/System/int.md +10 -0
- package/core/docs/System/int64.md +9 -0
- package/core/docs/System/int8.md +9 -0
- package/core/docs/System/uint.md +9 -0
- package/core/docs/System/uint64.md +9 -0
- package/core/docs/System/uint8.md +9 -0
- package/core/package.jsonc +4 -0
- package/dist/index.mjs +417 -5490
- package/package.json +33 -30
- package/src/args.ts +171 -0
- package/src/index.ts +53 -104
- package/src/init.ts +128 -0
- package/src/test.ts +6 -2
- package/test/fixtures/build/calc.test +0 -0
- package/test/fixtures/build/calc.test.c +0 -969
- package/test/fixtures/build/main.h +0 -170
- package/test/fixtures/calc.test.nm +0 -32
- package/tsconfig.json +0 -21
- package/vite.config.ts +0 -7
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wall-clock time and sleeping.
|
|
3
|
+
*
|
|
4
|
+
* All members are static — no instance is constructed.
|
|
5
|
+
*
|
|
6
|
+
* const uint64 started = Time.now_ms() // wall-clock ms since the epoch
|
|
7
|
+
* const uint64 unix = Time.now_unix() // Unix seconds
|
|
8
|
+
* const uint64 t = Time.now_ns() // wall-clock ns since the epoch
|
|
9
|
+
* Time.sleep_ms(50) // sleep 50 ms
|
|
10
|
+
**/
|
|
11
|
+
pub struct Time {
|
|
12
|
+
// (static) Wall-clock milliseconds since the Unix epoch.
|
|
13
|
+
pub func now_ms = (out uint64) {
|
|
14
|
+
```
|
|
15
|
+
#arch: c
|
|
16
|
+
#scope: file
|
|
17
|
+
#include <time.h>
|
|
18
|
+
```
|
|
19
|
+
```
|
|
20
|
+
#arch: c
|
|
21
|
+
struct timespec ts;
|
|
22
|
+
clock_gettime(CLOCK_REALTIME, &ts);
|
|
23
|
+
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
|
|
24
|
+
```
|
|
25
|
+
```
|
|
26
|
+
#arch: aarch64
|
|
27
|
+
sub sp, sp, #160
|
|
28
|
+
mov x0, #0
|
|
29
|
+
mov x1, sp
|
|
30
|
+
bl _clock_gettime
|
|
31
|
+
ldr x0, [sp, #0]
|
|
32
|
+
mov x1, #1000
|
|
33
|
+
mul x0, x0, x1
|
|
34
|
+
ldr x1, [sp, #8]
|
|
35
|
+
ldr x2, =1000000
|
|
36
|
+
udiv x1, x1, x2
|
|
37
|
+
add x0, x0, x1
|
|
38
|
+
add sp, sp, #160
|
|
39
|
+
b .return_Time_now_ms
|
|
40
|
+
```
|
|
41
|
+
return 0
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// (static) Wall-clock nanoseconds since the Unix epoch. Uses the same
|
|
45
|
+
// CLOCK_REALTIME source as `now_ms` (portable across macOS and Linux,
|
|
46
|
+
// where the CLOCK_MONOTONIC id differs) but keeps the full nanosecond
|
|
47
|
+
// resolution, which `Tester.bench` needs to time short function bodies.
|
|
48
|
+
// Seconds since the epoch times 1e9 stays well inside uint64 range.
|
|
49
|
+
pub func now_ns = (out uint64) {
|
|
50
|
+
```
|
|
51
|
+
#arch: c
|
|
52
|
+
struct timespec ts;
|
|
53
|
+
clock_gettime(CLOCK_REALTIME, &ts);
|
|
54
|
+
return (uint64_t)ts.tv_sec * 1000000000 + (uint64_t)ts.tv_nsec;
|
|
55
|
+
```
|
|
56
|
+
```
|
|
57
|
+
#arch: aarch64
|
|
58
|
+
sub sp, sp, #160
|
|
59
|
+
mov x0, #0
|
|
60
|
+
mov x1, sp
|
|
61
|
+
bl _clock_gettime
|
|
62
|
+
ldr x0, [sp, #0]
|
|
63
|
+
ldr x1, =1000000000
|
|
64
|
+
mul x0, x0, x1
|
|
65
|
+
ldr x1, [sp, #8]
|
|
66
|
+
add x0, x0, x1
|
|
67
|
+
add sp, sp, #160
|
|
68
|
+
b .return_Time_now_ns
|
|
69
|
+
```
|
|
70
|
+
return 0
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// (static) Wall-clock seconds since the Unix epoch.
|
|
74
|
+
pub func now_unix = (out uint64) {
|
|
75
|
+
```
|
|
76
|
+
#arch: c
|
|
77
|
+
return (uint64_t)time(NULL);
|
|
78
|
+
```
|
|
79
|
+
```
|
|
80
|
+
#arch: aarch64
|
|
81
|
+
mov x0, #0
|
|
82
|
+
bl _time
|
|
83
|
+
```
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// (static) Block the calling task for `ms` milliseconds. Uses nanosleep,
|
|
87
|
+
// so it is not capped at the 32-bit usleep range.
|
|
88
|
+
pub func sleep_ms = (uint64 ms) {
|
|
89
|
+
```
|
|
90
|
+
#arch: c
|
|
91
|
+
struct timespec ts;
|
|
92
|
+
ts.tv_sec = ms / 1000;
|
|
93
|
+
ts.tv_nsec = (long)(ms % 1000) * 1000000;
|
|
94
|
+
nanosleep(&ts, NULL);
|
|
95
|
+
```
|
|
96
|
+
```
|
|
97
|
+
#arch: aarch64
|
|
98
|
+
sub sp, sp, #16
|
|
99
|
+
mov x1, #1000
|
|
100
|
+
udiv x2, x0, x1
|
|
101
|
+
msub x3, x2, x1, x0
|
|
102
|
+
str x2, [sp, #0]
|
|
103
|
+
mul x3, x3, x1
|
|
104
|
+
mul x3, x3, x1
|
|
105
|
+
str x3, [sp, #8]
|
|
106
|
+
mov x0, sp
|
|
107
|
+
mov x1, #0
|
|
108
|
+
bl _nanosleep
|
|
109
|
+
add sp, sp, #16
|
|
110
|
+
```
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Arena-backed binary tree. Values, left/right child indices, and parent indices
|
|
2
|
+
// live in flat Buffers, so there is a single owner and cleanup is a flat free.
|
|
3
|
+
// Node identifiers are stable int indices (read `count` before `add`); -1 means
|
|
4
|
+
// "no child" / "no parent".
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A tree of values connected by parent/child links
|
|
8
|
+
**/
|
|
9
|
+
pub struct Tree<T>: Enumerable {
|
|
10
|
+
var Buffer<T> values = Buffer<T>()
|
|
11
|
+
var lefts = Buffer<int>()
|
|
12
|
+
var rights = Buffer<int>()
|
|
13
|
+
var parents = Buffer<int>()
|
|
14
|
+
var count = 0
|
|
15
|
+
|
|
16
|
+
pub func add = (ref self, mov T value) {
|
|
17
|
+
const int idx = self.count
|
|
18
|
+
self.values.grow_int(idx + 1)
|
|
19
|
+
const int v = value
|
|
20
|
+
self.values.store_int(idx, v)
|
|
21
|
+
self.lefts.grow_int(idx + 1)
|
|
22
|
+
self.lefts.store_int(idx, -1)
|
|
23
|
+
self.rights.grow_int(idx + 1)
|
|
24
|
+
self.rights.store_int(idx, -1)
|
|
25
|
+
self.parents.grow_int(idx + 1)
|
|
26
|
+
self.parents.store_int(idx, -1)
|
|
27
|
+
self.count = self.count + 1
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub func set_left = (ref self, int idx, int left) {
|
|
31
|
+
self.lefts.store_int(idx, left)
|
|
32
|
+
self.parents.store_int(left, idx)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
pub func set_right = (ref self, int idx, int right) {
|
|
36
|
+
self.rights.store_int(idx, right)
|
|
37
|
+
self.parents.store_int(right, idx)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pub func left = (self, int idx, out int: out >= -1 && out < self.count) {
|
|
41
|
+
return self.lefts.load_int(idx)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
pub func right = (self, int idx, out int: out >= -1 && out < self.count) {
|
|
45
|
+
return self.rights.load_int(idx)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
pub func parent_of = (self, int idx, out int: out >= -1 && out < self.count) {
|
|
49
|
+
return self.parents.load_int(idx)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
pub func first = (self: self.count > 0, out T) {
|
|
53
|
+
return self.values.load_int(0)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub func at = (self, int idx: idx >= 0 && idx < self.count, out T) {
|
|
57
|
+
return self.values.load_int(idx)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
pub func count_nodes = (self, int idx, out int) {
|
|
61
|
+
if idx == -1 {
|
|
62
|
+
return 0
|
|
63
|
+
}
|
|
64
|
+
return 1 + self.count_nodes(self.left(idx)) + self.count_nodes(self.right(idx))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub func length = (self, out int) {
|
|
68
|
+
return self.count
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Marker trait for containers that can be borrowed as a non-owning `view T`
|
|
2
|
+
// slice via a `slice(start, end, out view T)` method. Conforming types
|
|
3
|
+
// implement slice — almost always by delegating to an internal Buffer's slice
|
|
4
|
+
// (`return self.items.slice(start, end)`), so no #arch code is needed in user
|
|
5
|
+
// types. The resulting view supports `.length` and `.at(i)`; the element type
|
|
6
|
+
// is the one named in the view (e.g. `view User`).
|
|
7
|
+
//
|
|
8
|
+
// Generic trait conformance is now parsed and checked by the compiler
|
|
9
|
+
// (`trait Foo<T>` + `struct C: Foo<ConcreteType>`), so a type MAY parameterise
|
|
10
|
+
// the trait and name its element type: `pub struct UserList: Viewable<User>`.
|
|
11
|
+
// `Viewable` itself stays a plain marker today — the core `Array<T>` and
|
|
12
|
+
// `List<T>` conformers and the SPEC examples all use the bare `: Viewable`
|
|
13
|
+
// form, and migrating them to `: Viewable<Elem>` is a separate library/spec
|
|
14
|
+
// change. The slice method is still declared with its concrete element view:
|
|
15
|
+
//
|
|
16
|
+
// pub struct UserList: Viewable {
|
|
17
|
+
// var Buffer<User> items = Buffer<User>()
|
|
18
|
+
// pub func slice = (self, int start, int end, out view User) {
|
|
19
|
+
// return self.items.slice(start, end)
|
|
20
|
+
// }
|
|
21
|
+
// }
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A trait for containers that can be borrowed as a non-owning `view T` slice
|
|
25
|
+
**/
|
|
26
|
+
pub trait Viewable {
|
|
27
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A boolean value (`true` or `false`)
|
|
3
|
+
**/
|
|
4
|
+
pub struct bool: Stringable {
|
|
5
|
+
/**
|
|
6
|
+
* Converts this boolean to a string value (`"true"` or `"false"`)
|
|
7
|
+
*
|
|
8
|
+
* @param self: the boolean
|
|
9
|
+
* @out string: the boolean as a string value (`"true"` or `"false"`)
|
|
10
|
+
**/
|
|
11
|
+
pub func to_string = (self, out string) {
|
|
12
|
+
```
|
|
13
|
+
#arch: c
|
|
14
|
+
int length = snprintf(NULL, 0, "%s", self ? "true" : "false");
|
|
15
|
+
char* str = malloc(length + 1);
|
|
16
|
+
snprintf(str, length + 1, "%s", self ? "true" : "false");
|
|
17
|
+
return str;
|
|
18
|
+
```
|
|
19
|
+
```
|
|
20
|
+
#arch: aarch64
|
|
21
|
+
sub sp, sp, #128
|
|
22
|
+
str x0, [sp, #0]
|
|
23
|
+
str x1, [sp, #8]
|
|
24
|
+
str x2, [sp, #16]
|
|
25
|
+
str x3, [sp, #24]
|
|
26
|
+
mov x0, xzr
|
|
27
|
+
mov x1, xzr
|
|
28
|
+
cbz x19, .Lfalse_bool
|
|
29
|
+
adr x2, .Lfmt_bool_true
|
|
30
|
+
mov x3, x19
|
|
31
|
+
bl _snprintf
|
|
32
|
+
add x0, x0, #1
|
|
33
|
+
str x0, [sp, #64]
|
|
34
|
+
bl _malloc
|
|
35
|
+
str x0, [sp, #72]
|
|
36
|
+
ldr x0, [sp, #72]
|
|
37
|
+
ldr x1, [sp, #64]
|
|
38
|
+
adr x2, .Lfmt_bool_true
|
|
39
|
+
mov x3, x19
|
|
40
|
+
bl _snprintf
|
|
41
|
+
ldr x0, [sp, #72]
|
|
42
|
+
add sp, sp, #128
|
|
43
|
+
b .Lend_bool_to_string
|
|
44
|
+
.Lfalse_bool:
|
|
45
|
+
adr x2, .Lfmt_bool_false
|
|
46
|
+
mov x3, x19
|
|
47
|
+
bl _snprintf
|
|
48
|
+
add x0, x0, #1
|
|
49
|
+
str x0, [sp, #64]
|
|
50
|
+
bl _malloc
|
|
51
|
+
str x0, [sp, #72]
|
|
52
|
+
ldr x0, [sp, #72]
|
|
53
|
+
ldr x1, [sp, #64]
|
|
54
|
+
adr x2, .Lfmt_bool_false
|
|
55
|
+
mov x3, x19
|
|
56
|
+
bl _snprintf
|
|
57
|
+
ldr x0, [sp, #72]
|
|
58
|
+
add sp, sp, #128
|
|
59
|
+
b .Lend_bool_to_string
|
|
60
|
+
.Lfmt_bool_true: .asciz "true"
|
|
61
|
+
.Lfmt_bool_false: .asciz "false"
|
|
62
|
+
.p2align 2
|
|
63
|
+
.Lend_bool_to_string:
|
|
64
|
+
```
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single character
|
|
3
|
+
**/
|
|
4
|
+
pub struct char: Stringable {
|
|
5
|
+
pub func to_string = (self, out string) {
|
|
6
|
+
```
|
|
7
|
+
#arch: c
|
|
8
|
+
int length = snprintf(NULL, 0, "%c", self);
|
|
9
|
+
char* str = malloc(length + 1);
|
|
10
|
+
snprintf(str, length + 1, "%c", self);
|
|
11
|
+
return str;
|
|
12
|
+
```
|
|
13
|
+
```
|
|
14
|
+
#arch: aarch64
|
|
15
|
+
sub sp, sp, #128
|
|
16
|
+
str x0, [sp, #0]
|
|
17
|
+
str x1, [sp, #8]
|
|
18
|
+
str x2, [sp, #16]
|
|
19
|
+
str x3, [sp, #24]
|
|
20
|
+
mov x0, xzr
|
|
21
|
+
mov x1, xzr
|
|
22
|
+
adr x2, .Lfmt_char_c
|
|
23
|
+
mov x3, x19
|
|
24
|
+
bl _snprintf
|
|
25
|
+
add x0, x0, #1
|
|
26
|
+
str x0, [sp, #64]
|
|
27
|
+
bl _malloc
|
|
28
|
+
str x0, [sp, #72]
|
|
29
|
+
ldr x0, [sp, #72]
|
|
30
|
+
ldr x1, [sp, #64]
|
|
31
|
+
adr x2, .Lfmt_char_c
|
|
32
|
+
mov x3, x19
|
|
33
|
+
bl _snprintf
|
|
34
|
+
ldr x0, [sp, #72]
|
|
35
|
+
add sp, sp, #128
|
|
36
|
+
b .Lend_char_to_string
|
|
37
|
+
.Lfmt_char_c: .asciz "%c"
|
|
38
|
+
.p2align 2
|
|
39
|
+
.Lend_char_to_string:
|
|
40
|
+
```
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A double-precision (64-bit) floating-point number
|
|
3
|
+
**/
|
|
4
|
+
pub struct float: Stringable {
|
|
5
|
+
pub func to_string = (self, out string) {
|
|
6
|
+
```
|
|
7
|
+
#arch: c
|
|
8
|
+
int length = snprintf(NULL, 0, "%f", self);
|
|
9
|
+
char* str = malloc(length + 1);
|
|
10
|
+
snprintf(str, length + 1, "%f", self);
|
|
11
|
+
return str;
|
|
12
|
+
```
|
|
13
|
+
```
|
|
14
|
+
#arch: aarch64
|
|
15
|
+
sub sp, sp, #128
|
|
16
|
+
str x0, [sp, #0]
|
|
17
|
+
str x1, [sp, #8]
|
|
18
|
+
str x2, [sp, #16]
|
|
19
|
+
str x3, [sp, #24]
|
|
20
|
+
str d0, [sp, #64]
|
|
21
|
+
mov x0, xzr
|
|
22
|
+
mov x1, xzr
|
|
23
|
+
adr x2, .Lfmt_float_f
|
|
24
|
+
fmov d0, x19
|
|
25
|
+
bl _snprintf
|
|
26
|
+
add x0, x0, #1
|
|
27
|
+
str x0, [sp, #64]
|
|
28
|
+
bl _malloc
|
|
29
|
+
str x0, [sp, #72]
|
|
30
|
+
ldr x0, [sp, #72]
|
|
31
|
+
ldr x1, [sp, #64]
|
|
32
|
+
adr x2, .Lfmt_float_f
|
|
33
|
+
fmov d0, x19
|
|
34
|
+
bl _snprintf
|
|
35
|
+
ldr x0, [sp, #72]
|
|
36
|
+
add sp, sp, #128
|
|
37
|
+
b .Lend_float_to_string
|
|
38
|
+
.Lfmt_float_f: .asciz "%f"
|
|
39
|
+
.p2align 2
|
|
40
|
+
.Lend_float_to_string:
|
|
41
|
+
```
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A signed integer — the default integer type
|
|
3
|
+
**/
|
|
4
|
+
pub struct int: Stringable {
|
|
5
|
+
pub func to_string = (self, out string) {
|
|
6
|
+
```
|
|
7
|
+
#arch: c
|
|
8
|
+
int length = snprintf(NULL, 0, "%ld", self);
|
|
9
|
+
char* str = malloc(length + 1);
|
|
10
|
+
snprintf(str, length + 1, "%ld", self);
|
|
11
|
+
return str;
|
|
12
|
+
```
|
|
13
|
+
```
|
|
14
|
+
#arch: aarch64
|
|
15
|
+
sub sp, sp, #128
|
|
16
|
+
str x0, [sp, #0]
|
|
17
|
+
str x1, [sp, #8]
|
|
18
|
+
str x2, [sp, #16]
|
|
19
|
+
str x3, [sp, #24]
|
|
20
|
+
mov x0, xzr
|
|
21
|
+
mov x1, xzr
|
|
22
|
+
adr x2, .Lfmt_int_ld
|
|
23
|
+
mov x3, x19
|
|
24
|
+
bl _snprintf
|
|
25
|
+
add x0, x0, #1
|
|
26
|
+
str x0, [sp, #64]
|
|
27
|
+
bl _malloc
|
|
28
|
+
str x0, [sp, #72]
|
|
29
|
+
ldr x0, [sp, #72]
|
|
30
|
+
ldr x1, [sp, #64]
|
|
31
|
+
adr x2, .Lfmt_int_ld
|
|
32
|
+
mov x3, x19
|
|
33
|
+
bl _snprintf
|
|
34
|
+
ldr x0, [sp, #72]
|
|
35
|
+
add sp, sp, #128
|
|
36
|
+
b .Lend_int_to_string
|
|
37
|
+
.Lfmt_int_ld: .asciz "%ld"
|
|
38
|
+
.p2align 2
|
|
39
|
+
.Lend_int_to_string:
|
|
40
|
+
```
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Parse a base-10 integer from a string.
|
|
44
|
+
pub func parse = (string s, out int) {
|
|
45
|
+
```
|
|
46
|
+
#arch: c
|
|
47
|
+
return atoi(s);
|
|
48
|
+
```
|
|
49
|
+
```
|
|
50
|
+
#arch: aarch64
|
|
51
|
+
bl _atoi
|
|
52
|
+
```
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A 64-bit signed integer
|
|
3
|
+
**/
|
|
4
|
+
pub struct int64: Stringable {
|
|
5
|
+
pub func to_string = (self, out string) {
|
|
6
|
+
```
|
|
7
|
+
#arch: c
|
|
8
|
+
int length = snprintf(NULL, 0, "%lld", self);
|
|
9
|
+
char* str = malloc(length + 1);
|
|
10
|
+
snprintf(str, length + 1, "%lld", self);
|
|
11
|
+
return str;
|
|
12
|
+
```
|
|
13
|
+
```
|
|
14
|
+
#arch: aarch64
|
|
15
|
+
sub sp, sp, #128
|
|
16
|
+
str x0, [sp, #0]
|
|
17
|
+
str x1, [sp, #8]
|
|
18
|
+
str x2, [sp, #16]
|
|
19
|
+
str x3, [sp, #24]
|
|
20
|
+
mov x0, xzr
|
|
21
|
+
mov x1, xzr
|
|
22
|
+
adr x2, .Lfmt_int64_lld
|
|
23
|
+
mov x3, x19
|
|
24
|
+
bl _snprintf
|
|
25
|
+
add x0, x0, #1
|
|
26
|
+
str x0, [sp, #64]
|
|
27
|
+
bl _malloc
|
|
28
|
+
str x0, [sp, #72]
|
|
29
|
+
ldr x0, [sp, #72]
|
|
30
|
+
ldr x1, [sp, #64]
|
|
31
|
+
adr x2, .Lfmt_int64_lld
|
|
32
|
+
mov x3, x19
|
|
33
|
+
bl _snprintf
|
|
34
|
+
ldr x0, [sp, #72]
|
|
35
|
+
add sp, sp, #128
|
|
36
|
+
b .Lend_int64_to_string
|
|
37
|
+
.Lfmt_int64_lld: .asciz "%lld"
|
|
38
|
+
.p2align 2
|
|
39
|
+
.Lend_int64_to_string:
|
|
40
|
+
```
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An 8-bit signed integer
|
|
3
|
+
**/
|
|
4
|
+
pub struct int8: Stringable {
|
|
5
|
+
pub func to_string = (self, out string) {
|
|
6
|
+
```
|
|
7
|
+
#arch: c
|
|
8
|
+
int length = snprintf(NULL, 0, "%d", self);
|
|
9
|
+
char* str = malloc(length + 1);
|
|
10
|
+
snprintf(str, length + 1, "%d", self);
|
|
11
|
+
return str;
|
|
12
|
+
```
|
|
13
|
+
```
|
|
14
|
+
#arch: aarch64
|
|
15
|
+
sub sp, sp, #128
|
|
16
|
+
str x0, [sp, #0]
|
|
17
|
+
str x1, [sp, #8]
|
|
18
|
+
str x2, [sp, #16]
|
|
19
|
+
str x3, [sp, #24]
|
|
20
|
+
mov x0, xzr
|
|
21
|
+
mov x1, xzr
|
|
22
|
+
adr x2, .Lfmt_int8_d
|
|
23
|
+
mov x3, x19
|
|
24
|
+
bl _snprintf
|
|
25
|
+
add x0, x0, #1
|
|
26
|
+
str x0, [sp, #64]
|
|
27
|
+
bl _malloc
|
|
28
|
+
str x0, [sp, #72]
|
|
29
|
+
ldr x0, [sp, #72]
|
|
30
|
+
ldr x1, [sp, #64]
|
|
31
|
+
adr x2, .Lfmt_int8_d
|
|
32
|
+
mov x3, x19
|
|
33
|
+
bl _snprintf
|
|
34
|
+
ldr x0, [sp, #72]
|
|
35
|
+
add sp, sp, #128
|
|
36
|
+
b .Lend_int8_to_string
|
|
37
|
+
.Lfmt_int8_d: .asciz "%d"
|
|
38
|
+
.p2align 2
|
|
39
|
+
.Lend_int8_to_string:
|
|
40
|
+
```
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An unsigned integer
|
|
3
|
+
**/
|
|
4
|
+
pub struct uint: Stringable {
|
|
5
|
+
pub func to_string = (self, out string) {
|
|
6
|
+
```
|
|
7
|
+
#arch: c
|
|
8
|
+
int length = snprintf(NULL, 0, "%ld", self);
|
|
9
|
+
char* str = malloc(length + 1);
|
|
10
|
+
snprintf(str, length + 1, "%ld", self);
|
|
11
|
+
return str;
|
|
12
|
+
```
|
|
13
|
+
```
|
|
14
|
+
#arch: aarch64
|
|
15
|
+
sub sp, sp, #128
|
|
16
|
+
str x0, [sp, #0]
|
|
17
|
+
str x1, [sp, #8]
|
|
18
|
+
str x2, [sp, #16]
|
|
19
|
+
str x3, [sp, #24]
|
|
20
|
+
mov x0, xzr
|
|
21
|
+
mov x1, xzr
|
|
22
|
+
adr x2, .Lfmt_uint_ld
|
|
23
|
+
mov x3, x19
|
|
24
|
+
bl _snprintf
|
|
25
|
+
add x0, x0, #1
|
|
26
|
+
str x0, [sp, #64]
|
|
27
|
+
bl _malloc
|
|
28
|
+
str x0, [sp, #72]
|
|
29
|
+
ldr x0, [sp, #72]
|
|
30
|
+
ldr x1, [sp, #64]
|
|
31
|
+
adr x2, .Lfmt_uint_ld
|
|
32
|
+
mov x3, x19
|
|
33
|
+
bl _snprintf
|
|
34
|
+
ldr x0, [sp, #72]
|
|
35
|
+
add sp, sp, #128
|
|
36
|
+
b .Lend_uint_to_string
|
|
37
|
+
.Lfmt_uint_ld: .asciz "%ld"
|
|
38
|
+
.p2align 2
|
|
39
|
+
.Lend_uint_to_string:
|
|
40
|
+
```
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A 64-bit unsigned integer
|
|
3
|
+
**/
|
|
4
|
+
pub struct uint64: Stringable {
|
|
5
|
+
pub func to_string = (self, out string) {
|
|
6
|
+
```
|
|
7
|
+
#arch: c
|
|
8
|
+
int length = snprintf(NULL, 0, "%llu", self);
|
|
9
|
+
char* str = malloc(length + 1);
|
|
10
|
+
snprintf(str, length + 1, "%llu", self);
|
|
11
|
+
return str;
|
|
12
|
+
```
|
|
13
|
+
```
|
|
14
|
+
#arch: aarch64
|
|
15
|
+
sub sp, sp, #128
|
|
16
|
+
str x0, [sp, #0]
|
|
17
|
+
str x1, [sp, #8]
|
|
18
|
+
str x2, [sp, #16]
|
|
19
|
+
str x3, [sp, #24]
|
|
20
|
+
mov x0, xzr
|
|
21
|
+
mov x1, xzr
|
|
22
|
+
adr x2, .Lfmt_uint64_llu
|
|
23
|
+
mov x3, x19
|
|
24
|
+
bl _snprintf
|
|
25
|
+
add x0, x0, #1
|
|
26
|
+
str x0, [sp, #64]
|
|
27
|
+
bl _malloc
|
|
28
|
+
str x0, [sp, #72]
|
|
29
|
+
ldr x0, [sp, #72]
|
|
30
|
+
ldr x1, [sp, #64]
|
|
31
|
+
adr x2, .Lfmt_uint64_llu
|
|
32
|
+
mov x3, x19
|
|
33
|
+
bl _snprintf
|
|
34
|
+
ldr x0, [sp, #72]
|
|
35
|
+
add sp, sp, #128
|
|
36
|
+
b .Lend_uint64_to_string
|
|
37
|
+
.Lfmt_uint64_llu: .asciz "%llu"
|
|
38
|
+
.p2align 2
|
|
39
|
+
.Lend_uint64_to_string:
|
|
40
|
+
```
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An 8-bit unsigned integer
|
|
3
|
+
**/
|
|
4
|
+
pub struct uint8: Stringable {
|
|
5
|
+
pub func to_string = (self, out string) {
|
|
6
|
+
```
|
|
7
|
+
#arch: c
|
|
8
|
+
int length = snprintf(NULL, 0, "%d", self);
|
|
9
|
+
char* str = malloc(length + 1);
|
|
10
|
+
snprintf(str, length + 1, "%d", self);
|
|
11
|
+
return str;
|
|
12
|
+
```
|
|
13
|
+
```
|
|
14
|
+
#arch: aarch64
|
|
15
|
+
sub sp, sp, #128
|
|
16
|
+
str x0, [sp, #0]
|
|
17
|
+
str x1, [sp, #8]
|
|
18
|
+
str x2, [sp, #16]
|
|
19
|
+
str x3, [sp, #24]
|
|
20
|
+
mov x0, xzr
|
|
21
|
+
mov x1, xzr
|
|
22
|
+
adr x2, .Lfmt_uint8_d
|
|
23
|
+
mov x3, x19
|
|
24
|
+
bl _snprintf
|
|
25
|
+
add x0, x0, #1
|
|
26
|
+
str x0, [sp, #64]
|
|
27
|
+
bl _malloc
|
|
28
|
+
str x0, [sp, #72]
|
|
29
|
+
ldr x0, [sp, #72]
|
|
30
|
+
ldr x1, [sp, #64]
|
|
31
|
+
adr x2, .Lfmt_uint8_d
|
|
32
|
+
mov x3, x19
|
|
33
|
+
bl _snprintf
|
|
34
|
+
ldr x0, [sp, #72]
|
|
35
|
+
add sp, sp, #128
|
|
36
|
+
b .Lend_uint8_to_string
|
|
37
|
+
.Lfmt_uint8_d: .asciz "%d"
|
|
38
|
+
.p2align 2
|
|
39
|
+
.Lend_uint8_to_string:
|
|
40
|
+
```
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Ansi
|
|
2
|
+
|
|
3
|
+
## `struct Ansi`
|
|
4
|
+
|
|
5
|
+
Helpers for styling terminal output with ANSI escape codes
|
|
6
|
+
|
|
7
|
+
**Members:**
|
|
8
|
+
|
|
9
|
+
- `bold(string s) -> string`
|
|
10
|
+
- `dim(string s) -> string`
|
|
11
|
+
- `italic(string s) -> string`
|
|
12
|
+
- `underline(string s) -> string`
|
|
13
|
+
- `blink(string s) -> string`
|
|
14
|
+
- `reverse(string s) -> string`
|
|
15
|
+
- `hidden(string s) -> string`
|
|
16
|
+
- `strikethrough(string s) -> string`
|
|
17
|
+
- `black(string s) -> string`
|
|
18
|
+
- `red(string s) -> string`
|
|
19
|
+
- `green(string s) -> string`
|
|
20
|
+
- `yellow(string s) -> string`
|
|
21
|
+
- `blue(string s) -> string`
|
|
22
|
+
- `magenta(string s) -> string`
|
|
23
|
+
- `cyan(string s) -> string`
|
|
24
|
+
- `white(string s) -> string`
|
|
25
|
+
- `bright_black(string s) -> string`
|
|
26
|
+
- `bright_red(string s) -> string`
|
|
27
|
+
- `bright_green(string s) -> string`
|
|
28
|
+
- `bright_yellow(string s) -> string`
|
|
29
|
+
- `bright_blue(string s) -> string`
|
|
30
|
+
- `bright_magenta(string s) -> string`
|
|
31
|
+
- `bright_cyan(string s) -> string`
|
|
32
|
+
- `bright_white(string s) -> string`
|
|
33
|
+
- `bg_black(string s) -> string`
|
|
34
|
+
- `bg_red(string s) -> string`
|
|
35
|
+
- `bg_green(string s) -> string`
|
|
36
|
+
- `bg_yellow(string s) -> string`
|
|
37
|
+
- `bg_blue(string s) -> string`
|
|
38
|
+
- `bg_magenta(string s) -> string`
|
|
39
|
+
- `bg_cyan(string s) -> string`
|
|
40
|
+
- `bg_white(string s) -> string`
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Array
|
|
2
|
+
|
|
3
|
+
## `struct Array<T>`
|
|
4
|
+
|
|
5
|
+
A fixed-length array of values, created with a literal (`[1, 2, 3]`) and addressable by index
|
|
6
|
+
|
|
7
|
+
**Members:**
|
|
8
|
+
|
|
9
|
+
- `at(int index) -> T`
|
|
10
|
+
- `first() -> T`
|
|
11
|
+
- `set(int index, T value)`
|
|
12
|
+
- `at_end() -> T`
|
|
13
|
+
- `slice(int start, int end) -> view T`
|
|
14
|
+
- `with(T value, int count) -> T[]`
|
|
15
|
+
- `add(Array other) -> Array`
|
|
16
|
+
- `mul(int other) -> Array`
|