aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-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
4 files changed, 40 insertions, 11 deletions
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