@grain/stdlib 0.7.1 → 0.7.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.7.2](https://github.com/grain-lang/grain/compare/stdlib-v0.7.1...stdlib-v0.7.2) (2026-02-08)
4
+
5
+
6
+ ### Features
7
+
8
+ * **compiler:** Use Binaryen's bulk memory polyfill ([#2334](https://github.com/grain-lang/grain/issues/2334)) ([1c5478e](https://github.com/grain-lang/grain/commit/1c5478e22a2cca7ff9f5198b768a2aa3c23fd4cf))
9
+ * **stdlib:** Standardize `path` module examples ([#2325](https://github.com/grain-lang/grain/issues/2325)) ([c6e3cb0](https://github.com/grain-lang/grain/commit/c6e3cb052e5ec69be8037dc63bf39ee2630bbccc))
10
+
3
11
  ## [0.7.1](https://github.com/grain-lang/grain/compare/stdlib-v0.7.0...stdlib-v0.7.1) (2025-07-01)
4
12
 
5
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grain/stdlib",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "The standard library for the Grain language.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://grain-lang.org",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {},
35
35
  "devDependencies": {
36
- "del-cli": "^4.0.1"
36
+ "del-cli": "^7.0.0"
37
37
  },
38
38
  "pkg": {
39
39
  "assets": "**/*.gr"
package/path.gr CHANGED
@@ -17,6 +17,7 @@
17
17
  * - The path segment `.` indicates the relative "current" directory of a path, and `..` indicates the parent directory of a path
18
18
  *
19
19
  * @example from "path" include Path
20
+ * @example let p = Path.fromString("./tmp/file.txt")
20
21
  *
21
22
  * @since v0.5.5
22
23
  */
@@ -88,49 +89,53 @@ and record TBase<a> {
88
89
  }
89
90
  /**
90
91
  * Represents an absolute path's anchor point.
92
+ *
93
+ * @since v0.5.5
91
94
  */
92
95
  and provide enum AbsoluteRoot {
93
96
  Root,
94
97
  Drive(Char),
95
98
  }
96
99
 
97
- // Dummy record names put here just to distinguish the two. These could be
98
- // replaced with opaque types if they get added to the language
99
100
  /**
100
101
  * Represents a relative path.
102
+ *
103
+ * @since v0.5.5
101
104
  */
102
- abstract record Relative {
103
- _rel: Void,
104
- }
105
+ abstract type Relative = Void
105
106
 
106
107
  /**
107
108
  * Represents an absolute path.
109
+ *
110
+ * @since v0.5.5
108
111
  */
109
- abstract record Absolute {
110
- _abs: Void,
111
- }
112
+ abstract type Absolute = Void
112
113
 
113
114
  /**
114
115
  * Represents a path referencing a file.
116
+ *
117
+ * @since v0.5.5
115
118
  */
116
- abstract record File {
117
- _file: Void,
118
- }
119
+ abstract type File = Void
119
120
 
120
121
  /**
121
122
  * Represents a path referencing a directory.
123
+ *
124
+ * @since v0.5.5
122
125
  */
123
- abstract record Directory {
124
- _directory: Void,
125
- }
126
+ abstract type Directory = Void
126
127
 
127
128
  /**
128
129
  * Represents a path typed on (`Absolute` or `Relative`) and (`File` or
129
130
  * `Directory`)
131
+ *
132
+ * @since v0.5.5
130
133
  */
131
134
  abstract type rec TypedPath<a, b> = (TBase<a>, TFileType<b>, List<String>)
132
135
  /**
133
136
  * Represents a system path.
137
+ *
138
+ * @since v0.5.5
134
139
  */
135
140
  and provide enum Path {
136
141
  AbsoluteFile(TypedPath<Absolute, File>),
@@ -141,6 +146,8 @@ and provide enum Path {
141
146
 
142
147
  /**
143
148
  * Represents a platform-specific path encoding scheme.
149
+ *
150
+ * @since v0.5.5
144
151
  */
145
152
  provide enum Platform {
146
153
  Windows,
@@ -149,6 +156,8 @@ provide enum Platform {
149
156
 
150
157
  /**
151
158
  * Represents an error that can occur when finding a property of a path.
159
+ *
160
+ * @since v0.5.5
152
161
  */
153
162
  provide enum PathOperationError {
154
163
  IncompatiblePathType,
@@ -156,6 +165,8 @@ provide enum PathOperationError {
156
165
 
157
166
  /**
158
167
  * Represents an error that can occur when appending paths.
168
+ *
169
+ * @since v0.5.5
159
170
  */
160
171
  provide enum AppendError {
161
172
  AppendToFile,
@@ -164,6 +175,8 @@ provide enum AppendError {
164
175
 
165
176
  /**
166
177
  * Represents the status of an ancestry check between two paths.
178
+ *
179
+ * @since v0.5.5
167
180
  */
168
181
  provide enum AncestryStatus {
169
182
  Descendant,
@@ -175,6 +188,8 @@ provide enum AncestryStatus {
175
188
  /**
176
189
  * Represents an error that can occur when the types of paths are incompatible
177
190
  * for an operation.
191
+ *
192
+ * @since v0.5.5
178
193
  */
179
194
  provide enum IncompatibilityError {
180
195
  DifferentRoots,
@@ -183,6 +198,8 @@ provide enum IncompatibilityError {
183
198
 
184
199
  /**
185
200
  * Represents possible errors for the `relativeTo` operation.
201
+ *
202
+ * @since v0.5.5
186
203
  */
187
204
  provide enum RelativizationError {
188
205
  Incompatible(IncompatibilityError),
@@ -375,10 +392,10 @@ let fromStringHelper = (pathStr, platform) => {
375
392
  * @param platform: The platform whose path separators should be used for parsing
376
393
  * @returns The path wrapped with details encoded within the type
377
394
  *
378
- * @example fromString("file.txt") // a relative Path referencing the file ./file.txt
379
- * @example fromString(".") // a relative Path referencing the current directory
380
- * @example fromString("/bin/", Posix) // an absolute Path referencing the directory /bin/
381
- * @example fromString("C:\\file.txt", Windows) // a relative Path referencing the file C:\file.txt
395
+ * @example Path.fromString("file.txt") // a relative Path referencing the file ./file.txt
396
+ * @example Path.fromString(".") // a relative Path referencing the current directory
397
+ * @example Path.fromString("/bin/", Path.Posix) // an absolute Path referencing the directory /bin/
398
+ * @example Path.fromString("C:\\file.txt", Path.Windows) // a relative Path referencing the file C:\file.txt
382
399
  *
383
400
  * @since v0.5.5
384
401
  * @history v0.6.0: Merged with `fromPlatformString`; modified signature to accept platform
@@ -423,9 +440,9 @@ let toStringHelper = (path, platform) => {
423
440
  * @param platform: The `Platform` to use to represent the path as a string
424
441
  * @returns A string representing the given path
425
442
  *
426
- * @example toString(fromString("/file.txt")) == "/file.txt"
427
- * @example toString(fromString("dir/"), Posix) == "./dir/"
428
- * @example toString(fromString("C:/file.txt"), Windows) == "C:\\file.txt"
443
+ * @example Path.toString(Path.fromString("/file.txt")) == "/file.txt"
444
+ * @example Path.toString(Path.fromString("dir/"), Path.Posix) == "./dir/"
445
+ * @example Path.toString(Path.fromString("C:/file.txt"), Path.Windows) == "C:\\file.txt"
429
446
  *
430
447
  * @since v0.5.5
431
448
  * @history v0.6.0: Merged with `toPlatformString`; modified signature to accept platform
@@ -440,8 +457,8 @@ provide let toString = (path, platform=Posix) => {
440
457
  * @param path: The path to inspect
441
458
  * @returns `true` if the path is a directory path or `false` otherwise
442
459
  *
443
- * @example isDirectory(fromString("file.txt")) == false
444
- * @example isDirectory(fromString("/bin/")) == true
460
+ * @example Path.isDirectory(Path.fromString("file.txt")) == false
461
+ * @example Path.isDirectory(Path.fromString("/bin/")) == true
445
462
  *
446
463
  * @since v0.5.5
447
464
  */
@@ -456,8 +473,8 @@ provide let isDirectory = path => {
456
473
  * @param path: The path to inspect
457
474
  * @returns `true` if the path is absolute or `false` otherwise
458
475
  *
459
- * @example isAbsolute(fromString("/Users/me")) == true
460
- * @example isAbsolute(fromString("./file.txt")) == false
476
+ * @example Path.isAbsolute(Path.fromString("/Users/me")) == true
477
+ * @example Path.isAbsolute(Path.fromString("./file.txt")) == false
461
478
  */
462
479
  provide let isAbsolute = path => {
463
480
  let (base, _, _) = pathInfo(path)
@@ -490,9 +507,9 @@ let rec appendHelper = (path: PathInfo, toAppend: PathInfo) =>
490
507
  * @param toAppend: The relative path to append
491
508
  * @returns `Ok(path)` combining the base and appended paths or `Err(err)` if the paths are incompatible
492
509
  *
493
- * @example append(fromString("./dir/"), fromString("file.txt")) == Ok(fromString("./dir/file.txt"))
494
- * @example append(fromString("a.txt"), fromString("b.sh")) == Err(AppendToFile) // cannot append to file path
495
- * @example append(fromString("./dir/"), fromString("/dir2")) == Err(AppendAbsolute) // cannot append an absolute path
510
+ * @example Path.append(Path.fromString("./dir/"), Path.fromString("file.txt")) == Ok(Path.fromString("./dir/file.txt"))
511
+ * @example Path.append(Path.fromString("a.txt"), Path.fromString("b.sh")) == Err(Path.AppendToFile) // cannot append to file path
512
+ * @example Path.append(Path.fromString("./dir/"), Path.fromString("/dir2")) == Err(Path.AppendAbsolute) // cannot append an absolute path
496
513
  *
497
514
  * @since v0.5.5
498
515
  */
@@ -547,21 +564,21 @@ let relativeToHelper = (source: PathInfo, dest: PathInfo) => {
547
564
  * path from the source path.
548
565
  *
549
566
  * If the source and destination are incompatible in their bases, the result
550
- * will be `Err(IncompatibilityError)`.
567
+ * will be `Err(Path.IncompatibilityError)`.
551
568
  *
552
569
  * If the route to the destination cannot be concretely determined from the
553
- * source, the result will be `Err(ImpossibleRelativization)`.
570
+ * source, the result will be `Err(Path.ImpossibleRelativization)`.
554
571
  *
555
572
  * @param source: The source path
556
573
  * @param dest: The destination path to resolve
557
574
  * @returns `Ok(path)` containing the relative path if successfully resolved or `Err(err)` otherwise
558
575
  *
559
- * @example relativeTo(fromString("/usr"), fromString("/usr/bin")) == Ok(fromString("./bin"))
560
- * @example relativeTo(fromString("/home/me"), fromString("/home/me")) == Ok(fromString("."))
561
- * @example relativeTo(fromString("/file.txt"), fromString("/etc/")) == Ok(fromString("../etc/"))
562
- * @example relativeTo(fromString(".."), fromString("../../thing")) Ok(fromString("../thing"))
563
- * @example relativeTo(fromString("/usr/bin"), fromString("C:/Users")) == Err(Incompatible(DifferentRoots))
564
- * @example relativeTo(fromString("../here"), fromString("./there")) == Err(ImpossibleRelativization)
576
+ * @example Path.relativeTo(Path.fromString("/usr"), Path.fromString("/usr/bin")) == Ok(Path.fromString("./bin"))
577
+ * @example Path.relativeTo(Path.fromString("/home/me"), Path.fromString("/home/me")) == Ok(Path.fromString("."))
578
+ * @example Path.relativeTo(Path.fromString("/file.txt"), Path.fromString("/etc/")) == Ok(Path.fromString("../etc/"))
579
+ * @example Path.relativeTo(Path.fromString(".."), Path.fromString("../../thing")) Ok(Path.fromString("../thing"))
580
+ * @example Path.relativeTo(Path.fromString("/usr/bin"), Path.fromString("C:/Users")) == Err(Path.Incompatible(Path.DifferentRoots))
581
+ * @example Path.relativeTo(Path.fromString("../here"), Path.fromString("./there")) == Err(Path.ImpossibleRelativization)
565
582
  *
566
583
  * @since v0.5.5
567
584
  */
@@ -595,16 +612,16 @@ let ancestryHelper = (base: PathInfo, path: PathInfo) => {
595
612
  }
596
613
 
597
614
  /**
598
- * Determines the relative ancestry betwen two paths.
615
+ * Determines the relative ancestry between two paths.
599
616
  *
600
617
  * @param base: The first path to consider
601
618
  * @param path: The second path to consider
602
619
  * @returns `Ok(ancestryStatus)` with the relative ancestry between the paths if they are compatible or `Err(err)` if they are incompatible
603
620
  *
604
- * @example ancestry(fromString("/usr"), fromString("/usr/bin/bash")) == Ok(Ancestor)
605
- * @example ancestry(fromString("/Users/me"), fromString("/Users")) == Ok(Descendant)
606
- * @example ancestry(fromString("/usr"), fromString("/etc")) == Ok(Neither)
607
- * @example ancestry(fromString("C:/dir1"), fromString("/dir2")) == Err(DifferentRoots)
621
+ * @example Path.ancestry(Path.fromString("/usr"), Path.fromString("/usr/bin/bash")) == Ok(Path.Ancestor)
622
+ * @example Path.ancestry(Path.fromString("/Users/me"), Path.fromString("/Users")) == Ok(Path.Descendant)
623
+ * @example Path.ancestry(Path.fromString("/usr"), Path.fromString("/etc")) == Ok(Path.Neither)
624
+ * @example Path.ancestry(Path.fromString("C:/dir1"), Path.fromString("/dir2")) == Err(Path.DifferentRoots)
608
625
  *
609
626
  * @since v0.5.5
610
627
  */
@@ -631,8 +648,8 @@ let parentHelper = (path: PathInfo) => match (path) {
631
648
  * @param path: The path to inspect
632
649
  * @returns A path corresponding to the parent directory of the given path
633
650
  *
634
- * @example parent(fromString("./dir/inner")) == fromString("./dir/")
635
- * @example parent(fromString("/")) == fromString("/")
651
+ * @example Path.parent(Path.fromString("./dir/inner")) == Path.fromString("./dir/")
652
+ * @example Path.parent(Path.fromString("/")) == Path.fromString("/")
636
653
  *
637
654
  * @since v0.5.5
638
655
  */
@@ -651,8 +668,8 @@ let basenameHelper = (path: PathInfo) => match (path) {
651
668
  * @param path: The path to inspect
652
669
  * @returns `Some(path)` containing the basename of the path or `None` if the path does not have one
653
670
  *
654
- * @example basename(fromString("./dir/file.txt")) == Some("file.txt")
655
- * @example basename(fromString(".."))) == None
671
+ * @example Path.basename(Path.fromString("./dir/file.txt")) == Some("file.txt")
672
+ * @example Path.basename(Path.fromString(".."))) == None
656
673
  *
657
674
  * @since v0.5.5
658
675
  */
@@ -682,10 +699,10 @@ let stemExtHelper = (path: PathInfo) => match (path) {
682
699
  * @param path: The path to inspect
683
700
  * @returns `Ok(path)` containing the stem of the file path or `Err(err)` if the path is a directory path
684
701
  *
685
- * @example stem(fromString("file.txt")) == Ok("file")
686
- * @example stem(fromString(".gitignore")) == Ok(".gitignore")
687
- * @example stem(fromString(".a.tar.gz")) == Ok(".a")
688
- * @example stem(fromString("/dir/")) == Err(IncompatiblePathType) // can only take stem of a file path
702
+ * @example Path.stem(Path.fromString("file.txt")) == Ok("file")
703
+ * @example Path.stem(Path.fromString(".gitignore")) == Ok(".gitignore")
704
+ * @example Path.stem(Path.fromString(".a.tar.gz")) == Ok(".a")
705
+ * @example Path.stem(Path.fromString("/dir/")) == Err(Path.IncompatiblePathType) // can only take stem of a file path
689
706
  *
690
707
  * @since v0.5.5
691
708
  */
@@ -705,10 +722,10 @@ provide let stem = (path: Path) => {
705
722
  * @param path: The path to inspect
706
723
  * @returns `Ok(path)` containing the extension of the file path or `Err(err)` if the path is a directory path
707
724
  *
708
- * @example extension(fromString("file.txt")) == Ok(".txt")
709
- * @example extension(fromString(".gitignore")) == Ok("")
710
- * @example extension(fromString(".a.tar.gz")) == Ok(".tar.gz")
711
- * @example extension(fromString("/dir/")) == Err(IncompatiblePathType) // can only take extension of a file path
725
+ * @example Path.extension(Path.fromString("file.txt")) == Ok(".txt")
726
+ * @example Path.extension(Path.fromString(".gitignore")) == Ok("")
727
+ * @example Path.extension(Path.fromString(".a.tar.gz")) == Ok(".tar.gz")
728
+ * @example Path.extension(Path.fromString("/dir/")) == Err(Path.IncompatiblePathType) // can only take extension of a file path
712
729
  *
713
730
  * @since v0.5.5
714
731
  */
@@ -728,10 +745,10 @@ provide let extension = (path: Path) => {
728
745
  * @param path: The path to modify
729
746
  * @returns The path with the extension removed
730
747
  *
731
- * @example removeExtension(fromString("file.txt")) == fromString("file")
732
- * @example removeExtension(fromString(".gitignore")) == fromString(".gitignore")
733
- * @example removeExtension(fromString("./dir/file")) == fromString("dir/file")
734
- * @example removeExtension(fromString("./dir/")) == fromString("dir/")
748
+ * @example Path.removeExtension(Path.fromString("file.txt")) == Path.fromString("file")
749
+ * @example Path.removeExtension(Path.fromString(".gitignore")) == Path.fromString(".gitignore")
750
+ * @example Path.removeExtension(Path.fromString("./dir/file")) == Path.fromString("dir/file")
751
+ * @example Path.removeExtension(Path.fromString("./dir/")) == Path.fromString("dir/")
735
752
  *
736
753
  * @since v7.0.0
737
754
  */
@@ -752,11 +769,11 @@ provide let removeExtension = (path: Path) => {
752
769
  * @param extension: The new extension
753
770
  * @returns The modified path
754
771
  *
755
- * @example updateExtension(fromString("file.txt"), "ext") == fromString("file.ext")
756
- * @example updateExtension(fromString("file.txt"), "") == fromString("file.")
757
- * @example updateExtension(fromString(".gitignore"), "ext") == fromString(".gitignore.ext")
758
- * @example updateExtension(fromString("./dir/file"), "ext") == fromString("dir/file.ext")
759
- * @example updateExtension(fromString("./dir/"), "ext") == fromString("dir/")
772
+ * @example Path.updateExtension(Path.fromString("file.txt"), "ext") == Path.fromString("file.ext")
773
+ * @example Path.updateExtension(Path.fromString("file.txt"), "") == Path.fromString("file.")
774
+ * @example Path.updateExtension(Path.fromString(".gitignore"), "ext") == Path.fromString(".gitignore.ext")
775
+ * @example Path.updateExtension(Path.fromString("./dir/file"), "ext") == Path.fromString("dir/file.ext")
776
+ * @example Path.updateExtension(Path.fromString("./dir/"), "ext") == Path.fromString("dir/")
760
777
  *
761
778
  * @since v7.0.0
762
779
  */
@@ -782,9 +799,9 @@ let rootHelper = (path: PathInfo) => match (path) {
782
799
  * @param path: The path to inspect
783
800
  * @returns `Ok(root)` containing the root of the path or `Err(err)` if the path is a relative path
784
801
  *
785
- * @example root(fromString("C:/Users/me/")) == Ok(Drive('C'))
786
- * @example root(fromString("/home/me/")) == Ok(Root)
787
- * @example root(fromString("./file.txt")) == Err(IncompatiblePathType)
802
+ * @example Path.root(Path.fromString("C:/Users/me/")) == Ok(Path.Drive('C'))
803
+ * @example Path.root(Path.fromString("/home/me/")) == Ok(Path.Root)
804
+ * @example Path.root(Path.fromString("./file.txt")) == Err(Path.IncompatiblePathType)
788
805
  *
789
806
  * @since v0.5.5
790
807
  */
package/path.md CHANGED
@@ -28,12 +28,21 @@ No other changes yet.
28
28
  from "path" include Path
29
29
  ```
30
30
 
31
+ ```grain
32
+ let p = Path.fromString("./tmp/file.txt")
33
+ ```
34
+
31
35
  ## Types
32
36
 
33
37
  Type declarations included in the Path module.
34
38
 
35
39
  ### Path.**AbsoluteRoot**
36
40
 
41
+ <details disabled>
42
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
43
+ No other changes yet.
44
+ </details>
45
+
37
46
  ```grain
38
47
  enum AbsoluteRoot {
39
48
  Root,
@@ -45,6 +54,11 @@ Represents an absolute path's anchor point.
45
54
 
46
55
  ### Path.**Relative**
47
56
 
57
+ <details disabled>
58
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
59
+ No other changes yet.
60
+ </details>
61
+
48
62
  ```grain
49
63
  type Relative
50
64
  ```
@@ -53,6 +67,11 @@ Represents a relative path.
53
67
 
54
68
  ### Path.**Absolute**
55
69
 
70
+ <details disabled>
71
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
72
+ No other changes yet.
73
+ </details>
74
+
56
75
  ```grain
57
76
  type Absolute
58
77
  ```
@@ -61,6 +80,11 @@ Represents an absolute path.
61
80
 
62
81
  ### Path.**File**
63
82
 
83
+ <details disabled>
84
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
85
+ No other changes yet.
86
+ </details>
87
+
64
88
  ```grain
65
89
  type File
66
90
  ```
@@ -69,6 +93,11 @@ Represents a path referencing a file.
69
93
 
70
94
  ### Path.**Directory**
71
95
 
96
+ <details disabled>
97
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
98
+ No other changes yet.
99
+ </details>
100
+
72
101
  ```grain
73
102
  type Directory
74
103
  ```
@@ -77,6 +106,11 @@ Represents a path referencing a directory.
77
106
 
78
107
  ### Path.**TypedPath**
79
108
 
109
+ <details disabled>
110
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
111
+ No other changes yet.
112
+ </details>
113
+
80
114
  ```grain
81
115
  type TypedPath<a, b>
82
116
  ```
@@ -86,6 +120,11 @@ Represents a path typed on (`Absolute` or `Relative`) and (`File` or
86
120
 
87
121
  ### Path.**Path**
88
122
 
123
+ <details disabled>
124
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
125
+ No other changes yet.
126
+ </details>
127
+
89
128
  ```grain
90
129
  enum Path {
91
130
  AbsoluteFile(TypedPath<Absolute, File>),
@@ -99,6 +138,11 @@ Represents a system path.
99
138
 
100
139
  ### Path.**Platform**
101
140
 
141
+ <details disabled>
142
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
143
+ No other changes yet.
144
+ </details>
145
+
102
146
  ```grain
103
147
  enum Platform {
104
148
  Windows,
@@ -110,6 +154,11 @@ Represents a platform-specific path encoding scheme.
110
154
 
111
155
  ### Path.**PathOperationError**
112
156
 
157
+ <details disabled>
158
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
159
+ No other changes yet.
160
+ </details>
161
+
113
162
  ```grain
114
163
  enum PathOperationError {
115
164
  IncompatiblePathType,
@@ -120,6 +169,11 @@ Represents an error that can occur when finding a property of a path.
120
169
 
121
170
  ### Path.**AppendError**
122
171
 
172
+ <details disabled>
173
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
174
+ No other changes yet.
175
+ </details>
176
+
123
177
  ```grain
124
178
  enum AppendError {
125
179
  AppendToFile,
@@ -131,6 +185,11 @@ Represents an error that can occur when appending paths.
131
185
 
132
186
  ### Path.**AncestryStatus**
133
187
 
188
+ <details disabled>
189
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
190
+ No other changes yet.
191
+ </details>
192
+
134
193
  ```grain
135
194
  enum AncestryStatus {
136
195
  Descendant,
@@ -144,6 +203,11 @@ Represents the status of an ancestry check between two paths.
144
203
 
145
204
  ### Path.**IncompatibilityError**
146
205
 
206
+ <details disabled>
207
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
208
+ No other changes yet.
209
+ </details>
210
+
147
211
  ```grain
148
212
  enum IncompatibilityError {
149
213
  DifferentRoots,
@@ -156,6 +220,11 @@ for an operation.
156
220
 
157
221
  ### Path.**RelativizationError**
158
222
 
223
+ <details disabled>
224
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
225
+ No other changes yet.
226
+ </details>
227
+
159
228
  ```grain
160
229
  enum RelativizationError {
161
230
  Incompatible(IncompatibilityError),
@@ -208,19 +277,19 @@ Returns:
208
277
  Examples:
209
278
 
210
279
  ```grain
211
- fromString("file.txt") // a relative Path referencing the file ./file.txt
280
+ Path.fromString("file.txt") // a relative Path referencing the file ./file.txt
212
281
  ```
213
282
 
214
283
  ```grain
215
- fromString(".") // a relative Path referencing the current directory
284
+ Path.fromString(".") // a relative Path referencing the current directory
216
285
  ```
217
286
 
218
287
  ```grain
219
- fromString("/bin/", Posix) // an absolute Path referencing the directory /bin/
288
+ Path.fromString("/bin/", Path.Posix) // an absolute Path referencing the directory /bin/
220
289
  ```
221
290
 
222
291
  ```grain
223
- fromString("C:\\file.txt", Windows) // a relative Path referencing the file C:\file.txt
292
+ Path.fromString("C:\\file.txt", Path.Windows) // a relative Path referencing the file C:\file.txt
224
293
  ```
225
294
 
226
295
  ### Path.**toString**
@@ -261,15 +330,15 @@ Returns:
261
330
  Examples:
262
331
 
263
332
  ```grain
264
- toString(fromString("/file.txt")) == "/file.txt"
333
+ Path.toString(Path.fromString("/file.txt")) == "/file.txt"
265
334
  ```
266
335
 
267
336
  ```grain
268
- toString(fromString("dir/"), Posix) == "./dir/"
337
+ Path.toString(Path.fromString("dir/"), Path.Posix) == "./dir/"
269
338
  ```
270
339
 
271
340
  ```grain
272
- toString(fromString("C:/file.txt"), Windows) == "C:\\file.txt"
341
+ Path.toString(Path.fromString("C:/file.txt"), Path.Windows) == "C:\\file.txt"
273
342
  ```
274
343
 
275
344
  ### Path.**isDirectory**
@@ -300,11 +369,11 @@ Returns:
300
369
  Examples:
301
370
 
302
371
  ```grain
303
- isDirectory(fromString("file.txt")) == false
372
+ Path.isDirectory(Path.fromString("file.txt")) == false
304
373
  ```
305
374
 
306
375
  ```grain
307
- isDirectory(fromString("/bin/")) == true
376
+ Path.isDirectory(Path.fromString("/bin/")) == true
308
377
  ```
309
378
 
310
379
  ### Path.**isAbsolute**
@@ -330,11 +399,11 @@ Returns:
330
399
  Examples:
331
400
 
332
401
  ```grain
333
- isAbsolute(fromString("/Users/me")) == true
402
+ Path.isAbsolute(Path.fromString("/Users/me")) == true
334
403
  ```
335
404
 
336
405
  ```grain
337
- isAbsolute(fromString("./file.txt")) == false
406
+ Path.isAbsolute(Path.fromString("./file.txt")) == false
338
407
  ```
339
408
 
340
409
  ### Path.**append**
@@ -366,15 +435,15 @@ Returns:
366
435
  Examples:
367
436
 
368
437
  ```grain
369
- append(fromString("./dir/"), fromString("file.txt")) == Ok(fromString("./dir/file.txt"))
438
+ Path.append(Path.fromString("./dir/"), Path.fromString("file.txt")) == Ok(Path.fromString("./dir/file.txt"))
370
439
  ```
371
440
 
372
441
  ```grain
373
- append(fromString("a.txt"), fromString("b.sh")) == Err(AppendToFile) // cannot append to file path
442
+ Path.append(Path.fromString("a.txt"), Path.fromString("b.sh")) == Err(Path.AppendToFile) // cannot append to file path
374
443
  ```
375
444
 
376
445
  ```grain
377
- append(fromString("./dir/"), fromString("/dir2")) == Err(AppendAbsolute) // cannot append an absolute path
446
+ Path.append(Path.fromString("./dir/"), Path.fromString("/dir2")) == Err(Path.AppendAbsolute) // cannot append an absolute path
378
447
  ```
379
448
 
380
449
  ### Path.**relativeTo**
@@ -392,10 +461,10 @@ Attempts to construct a new relative path which will lead to the destination
392
461
  path from the source path.
393
462
 
394
463
  If the source and destination are incompatible in their bases, the result
395
- will be `Err(IncompatibilityError)`.
464
+ will be `Err(Path.IncompatibilityError)`.
396
465
 
397
466
  If the route to the destination cannot be concretely determined from the
398
- source, the result will be `Err(ImpossibleRelativization)`.
467
+ source, the result will be `Err(Path.ImpossibleRelativization)`.
399
468
 
400
469
  Parameters:
401
470
 
@@ -413,27 +482,27 @@ Returns:
413
482
  Examples:
414
483
 
415
484
  ```grain
416
- relativeTo(fromString("/usr"), fromString("/usr/bin")) == Ok(fromString("./bin"))
485
+ Path.relativeTo(Path.fromString("/usr"), Path.fromString("/usr/bin")) == Ok(Path.fromString("./bin"))
417
486
  ```
418
487
 
419
488
  ```grain
420
- relativeTo(fromString("/home/me"), fromString("/home/me")) == Ok(fromString("."))
489
+ Path.relativeTo(Path.fromString("/home/me"), Path.fromString("/home/me")) == Ok(Path.fromString("."))
421
490
  ```
422
491
 
423
492
  ```grain
424
- relativeTo(fromString("/file.txt"), fromString("/etc/")) == Ok(fromString("../etc/"))
493
+ Path.relativeTo(Path.fromString("/file.txt"), Path.fromString("/etc/")) == Ok(Path.fromString("../etc/"))
425
494
  ```
426
495
 
427
496
  ```grain
428
- relativeTo(fromString(".."), fromString("../../thing")) Ok(fromString("../thing"))
497
+ Path.relativeTo(Path.fromString(".."), Path.fromString("../../thing")) Ok(Path.fromString("../thing"))
429
498
  ```
430
499
 
431
500
  ```grain
432
- relativeTo(fromString("/usr/bin"), fromString("C:/Users")) == Err(Incompatible(DifferentRoots))
501
+ Path.relativeTo(Path.fromString("/usr/bin"), Path.fromString("C:/Users")) == Err(Path.Incompatible(Path.DifferentRoots))
433
502
  ```
434
503
 
435
504
  ```grain
436
- relativeTo(fromString("../here"), fromString("./there")) == Err(ImpossibleRelativization)
505
+ Path.relativeTo(Path.fromString("../here"), Path.fromString("./there")) == Err(Path.ImpossibleRelativization)
437
506
  ```
438
507
 
439
508
  ### Path.**ancestry**
@@ -448,7 +517,7 @@ ancestry:
448
517
  (base: Path, path: Path) => Result<AncestryStatus, IncompatibilityError>
449
518
  ```
450
519
 
451
- Determines the relative ancestry betwen two paths.
520
+ Determines the relative ancestry between two paths.
452
521
 
453
522
  Parameters:
454
523
 
@@ -466,19 +535,19 @@ Returns:
466
535
  Examples:
467
536
 
468
537
  ```grain
469
- ancestry(fromString("/usr"), fromString("/usr/bin/bash")) == Ok(Ancestor)
538
+ Path.ancestry(Path.fromString("/usr"), Path.fromString("/usr/bin/bash")) == Ok(Path.Ancestor)
470
539
  ```
471
540
 
472
541
  ```grain
473
- ancestry(fromString("/Users/me"), fromString("/Users")) == Ok(Descendant)
542
+ Path.ancestry(Path.fromString("/Users/me"), Path.fromString("/Users")) == Ok(Path.Descendant)
474
543
  ```
475
544
 
476
545
  ```grain
477
- ancestry(fromString("/usr"), fromString("/etc")) == Ok(Neither)
546
+ Path.ancestry(Path.fromString("/usr"), Path.fromString("/etc")) == Ok(Path.Neither)
478
547
  ```
479
548
 
480
549
  ```grain
481
- ancestry(fromString("C:/dir1"), fromString("/dir2")) == Err(DifferentRoots)
550
+ Path.ancestry(Path.fromString("C:/dir1"), Path.fromString("/dir2")) == Err(Path.DifferentRoots)
482
551
  ```
483
552
 
484
553
  ### Path.**parent**
@@ -509,11 +578,11 @@ Returns:
509
578
  Examples:
510
579
 
511
580
  ```grain
512
- parent(fromString("./dir/inner")) == fromString("./dir/")
581
+ Path.parent(Path.fromString("./dir/inner")) == Path.fromString("./dir/")
513
582
  ```
514
583
 
515
584
  ```grain
516
- parent(fromString("/")) == fromString("/")
585
+ Path.parent(Path.fromString("/")) == Path.fromString("/")
517
586
  ```
518
587
 
519
588
  ### Path.**basename**
@@ -544,11 +613,11 @@ Returns:
544
613
  Examples:
545
614
 
546
615
  ```grain
547
- basename(fromString("./dir/file.txt")) == Some("file.txt")
616
+ Path.basename(Path.fromString("./dir/file.txt")) == Some("file.txt")
548
617
  ```
549
618
 
550
619
  ```grain
551
- basename(fromString(".."))) == None
620
+ Path.basename(Path.fromString(".."))) == None
552
621
  ```
553
622
 
554
623
  ### Path.**stem**
@@ -579,19 +648,19 @@ Returns:
579
648
  Examples:
580
649
 
581
650
  ```grain
582
- stem(fromString("file.txt")) == Ok("file")
651
+ Path.stem(Path.fromString("file.txt")) == Ok("file")
583
652
  ```
584
653
 
585
654
  ```grain
586
- stem(fromString(".gitignore")) == Ok(".gitignore")
655
+ Path.stem(Path.fromString(".gitignore")) == Ok(".gitignore")
587
656
  ```
588
657
 
589
658
  ```grain
590
- stem(fromString(".a.tar.gz")) == Ok(".a")
659
+ Path.stem(Path.fromString(".a.tar.gz")) == Ok(".a")
591
660
  ```
592
661
 
593
662
  ```grain
594
- stem(fromString("/dir/")) == Err(IncompatiblePathType) // can only take stem of a file path
663
+ Path.stem(Path.fromString("/dir/")) == Err(Path.IncompatiblePathType) // can only take stem of a file path
595
664
  ```
596
665
 
597
666
  ### Path.**extension**
@@ -622,19 +691,19 @@ Returns:
622
691
  Examples:
623
692
 
624
693
  ```grain
625
- extension(fromString("file.txt")) == Ok(".txt")
694
+ Path.extension(Path.fromString("file.txt")) == Ok(".txt")
626
695
  ```
627
696
 
628
697
  ```grain
629
- extension(fromString(".gitignore")) == Ok("")
698
+ Path.extension(Path.fromString(".gitignore")) == Ok("")
630
699
  ```
631
700
 
632
701
  ```grain
633
- extension(fromString(".a.tar.gz")) == Ok(".tar.gz")
702
+ Path.extension(Path.fromString(".a.tar.gz")) == Ok(".tar.gz")
634
703
  ```
635
704
 
636
705
  ```grain
637
- extension(fromString("/dir/")) == Err(IncompatiblePathType) // can only take extension of a file path
706
+ Path.extension(Path.fromString("/dir/")) == Err(Path.IncompatiblePathType) // can only take extension of a file path
638
707
  ```
639
708
 
640
709
  ### Path.**removeExtension**
@@ -665,19 +734,19 @@ Returns:
665
734
  Examples:
666
735
 
667
736
  ```grain
668
- removeExtension(fromString("file.txt")) == fromString("file")
737
+ Path.removeExtension(Path.fromString("file.txt")) == Path.fromString("file")
669
738
  ```
670
739
 
671
740
  ```grain
672
- removeExtension(fromString(".gitignore")) == fromString(".gitignore")
741
+ Path.removeExtension(Path.fromString(".gitignore")) == Path.fromString(".gitignore")
673
742
  ```
674
743
 
675
744
  ```grain
676
- removeExtension(fromString("./dir/file")) == fromString("dir/file")
745
+ Path.removeExtension(Path.fromString("./dir/file")) == Path.fromString("dir/file")
677
746
  ```
678
747
 
679
748
  ```grain
680
- removeExtension(fromString("./dir/")) == fromString("dir/")
749
+ Path.removeExtension(Path.fromString("./dir/")) == Path.fromString("dir/")
681
750
  ```
682
751
 
683
752
  ### Path.**updateExtension**
@@ -709,23 +778,23 @@ Returns:
709
778
  Examples:
710
779
 
711
780
  ```grain
712
- updateExtension(fromString("file.txt"), "ext") == fromString("file.ext")
781
+ Path.updateExtension(Path.fromString("file.txt"), "ext") == Path.fromString("file.ext")
713
782
  ```
714
783
 
715
784
  ```grain
716
- updateExtension(fromString("file.txt"), "") == fromString("file.")
785
+ Path.updateExtension(Path.fromString("file.txt"), "") == Path.fromString("file.")
717
786
  ```
718
787
 
719
788
  ```grain
720
- updateExtension(fromString(".gitignore"), "ext") == fromString(".gitignore.ext")
789
+ Path.updateExtension(Path.fromString(".gitignore"), "ext") == Path.fromString(".gitignore.ext")
721
790
  ```
722
791
 
723
792
  ```grain
724
- updateExtension(fromString("./dir/file"), "ext") == fromString("dir/file.ext")
793
+ Path.updateExtension(Path.fromString("./dir/file"), "ext") == Path.fromString("dir/file.ext")
725
794
  ```
726
795
 
727
796
  ```grain
728
- updateExtension(fromString("./dir/"), "ext") == fromString("dir/")
797
+ Path.updateExtension(Path.fromString("./dir/"), "ext") == Path.fromString("dir/")
729
798
  ```
730
799
 
731
800
  ### Path.**root**
@@ -756,14 +825,14 @@ Returns:
756
825
  Examples:
757
826
 
758
827
  ```grain
759
- root(fromString("C:/Users/me/")) == Ok(Drive('C'))
828
+ Path.root(Path.fromString("C:/Users/me/")) == Ok(Path.Drive('C'))
760
829
  ```
761
830
 
762
831
  ```grain
763
- root(fromString("/home/me/")) == Ok(Root)
832
+ Path.root(Path.fromString("/home/me/")) == Ok(Path.Root)
764
833
  ```
765
834
 
766
835
  ```grain
767
- root(fromString("./file.txt")) == Err(IncompatiblePathType)
836
+ Path.root(Path.fromString("./file.txt")) == Err(Path.IncompatiblePathType)
768
837
  ```
769
838
 
@@ -15,20 +15,7 @@ provide { malloc, free, incRef, decRef }
15
15
  * @param src: The source memory region
16
16
  * @param length: The length of the memory region to copy
17
17
  */
18
- provide let copy = (dest, src, length) => {
19
- if (dest != src) {
20
- if (dest < src) {
21
- for (let mut i = 0n; i < length; i += 1n) {
22
- WasmI32.store8(dest, WasmI32.load8U(src, i), i)
23
- }
24
- } else {
25
- // Copy backwards to ensure we do not overwrite on overlapping regions
26
- for (let mut n = length; n > 0n; n -= 1n) {
27
- WasmI32.store8(dest + n - 1n, WasmI32.load8U(src + n - 1n, 0n), 0n)
28
- }
29
- }
30
- }
31
- }
18
+ provide primitive copy = "@wasm.memory_copy"
32
19
 
33
20
  /**
34
21
  * Fills the given memory region with the given 1-byte value. Values larger than 1 byte will be truncated.
@@ -37,10 +24,6 @@ provide let copy = (dest, src, length) => {
37
24
  * @param value: The value to fill the memory region with
38
25
  * @param length: The length of the memory region to fill
39
26
  */
40
- provide let fill = (dest, value, length) => {
41
- for (let mut i = 0n; i < length; i += 1n) {
42
- WasmI32.store8(dest, value, i)
43
- }
44
- }
27
+ provide primitive fill = "@wasm.memory_fill"
45
28
 
46
29
  provide primitive compare = "@wasm.memory_compare"