aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJJ2024-01-28 05:47:54 +0000
committerJJ2024-01-28 05:47:54 +0000
commit6da57c3a2c5c222591b0994acce79183b81d7f99 (patch)
tree7bb503ddac1a50d742ac1950a012dfb9adbc9e64
parentfde7a1311543badd1052a757d1e2c68272be1188 (diff)
std: rename std.pointers to std.mem
-rw-r--r--docs/ERRORS.md2
-rw-r--r--std/prelude/format.pk7
-rw-r--r--std/prelude/io.pk2
-rw-r--r--std/prelude/mem.pk35
-rw-r--r--std/prelude/pointers.pk7
5 files changed, 41 insertions, 12 deletions
diff --git a/docs/ERRORS.md b/docs/ERRORS.md
index a6e7a6a..4f99e7c 100644
--- a/docs/ERRORS.md
+++ b/docs/ERRORS.md
@@ -72,7 +72,7 @@ finally:
...
```
-This creates a distinction between two types of error handling, working in sync: functional error handling with [Option](https://en.wikipedia.org/wiki/Option_type) and [Result](https://en.wikipedia.org/wiki/Result_type) types, and object-oriented error handling with [catchable exceptions](https://en.wikipedia.org/wiki/Exception_handling). These styles may be swapped between with minimal syntax overhead. Libraries, however, should universally use `Option`/`Result`, as this provides the best support for both styles.
+This creates a distinction between two types of error handling, working in sync: functional error handling with [Option](https://en.wikipedia.org/wiki/Option_type) and [Result](https://en.wikipedia.org/wiki/Result_type) types, and object-oriented error handling with [catchable exceptions](https://en.wikipedia.org/wiki/Exception_handling). These styles may be swapped between with minimal syntactic overhead. Libraries, however, should universally use `Option`/`Result`, as this provides the best support for both styles.
<!-- [nullable types](https://en.wikipedia.org/wiki/Nullable_type)?? -->
diff --git a/std/prelude/format.pk b/std/prelude/format.pk
index 4f4746d..7cc1d81 100644
--- a/std/prelude/format.pk
+++ b/std/prelude/format.pk
@@ -47,7 +47,8 @@ pub macro fmt(self: static[str], args: varargs[Display]): str =
if parts.len != args.len + 1:
macro_error("wrong number of arguments")
use std.ast
- result = parts.get(0)!
+ var res = parts.get(0)!
for i, arg in args:
- result &= quote(`parts` & str(`arg`) &) # fixme
- result &= parts.last()!
+ res &= quote(`parts` & str(`arg`) &) # fixme
+ res &= parts.last()!
+ res
diff --git a/std/prelude/io.pk b/std/prelude/io.pk
index 7a3f059..002cc31 100644
--- a/std/prelude/io.pk
+++ b/std/prelude/io.pk
@@ -1,4 +1,4 @@
-## std.io: Platform-independent I/O constructs. Mostly revolve around files.
+## std.io: Platform-independent I/O constructs. Mostly revolves around files.
## This module is imported by default.
# reference: https://nim-lang.org/docs/syncio.html
# reference: https://doc.rust-lang.org/stable/std/io/
diff --git a/std/prelude/mem.pk b/std/prelude/mem.pk
new file mode 100644
index 0000000..79c524b
--- /dev/null
+++ b/std/prelude/mem.pk
@@ -0,0 +1,35 @@
+## std.mem: Unsafe functions for working with raw memory.
+
+## Raw pointers. Extremely unsafe.
+## While they are removed from the memory model by default (and hence can
+## cause undefined behavior), pointers must know what *type* they point at.
+## This cuts down on errors somewhat - not much, but somewhat.
+pub type ptr[T] =
+ addr: uint
+## Heap-allocated, memory-safe references.
+pub type ref[T]
+pub type unique[T]
+
+## Sets the sizeof(T) bytes following data + offset * sizeof(T) to T.
+## Extremely unsafe.
+pub func raw_set[T](data: ptr[T], val: T, offset: uint = 0) =
+ ...
+
+## Gets the value at data + offset * sizeof(T), and interprets it as type T.
+## Extremely unsafe.
+pub func raw_get[T](data: ptr[T], offset: uint = 0) =
+ ...
+
+## Returns a pointer offset by offset * sizeof(T).
+## Extremely unsafe.
+pub func raw_offset[T](data: ptr[T], offset: uint): ptr[T] =
+ ...
+
+pub func malloc[T](size: uint = sizeof(T)): ptr[T] =
+ ...
+
+pub func calloc[T](size: uint = sizeof(T)): ptr[T] =
+ ...
+
+pub func realloc[T](data: ptr[T]): ptr[T] =
+ ...
diff --git a/std/prelude/pointers.pk b/std/prelude/pointers.pk
deleted file mode 100644
index e2a95cf..0000000
--- a/std/prelude/pointers.pk
+++ /dev/null
@@ -1,7 +0,0 @@
-## std.pointers: Pointer arithmetic. Unsafe.
-
-pub type ptr[T]
-pub type ref[T]
-pub type unique[T]
-
-# idk what goes here