aboutsummaryrefslogtreecommitdiff
path: root/std/prelude/mem.pk
diff options
context:
space:
mode:
Diffstat (limited to 'std/prelude/mem.pk')
-rw-r--r--std/prelude/mem.pk35
1 files changed, 35 insertions, 0 deletions
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] =
+ ...