crow/pointer.crow (source)
Functions dealing with pointers and low-level memory issues.
any-const-pointer alias
nat8*any-mut-pointer alias
nat8 mut*as-const[t] t*(a t mut*) bare, unsafe
Treats a mutable pointer as constant.
as-mut[t] t mut*(a t*) bare, unsafe
Treats a constant pointer as mutable.
Do not actually write to it.
null[t] t*() bare, unsafe
Null pointer.
null[t] t mut*() bare, unsafe
null[r, p] function r(p)() bare, unsafe
new[t] t*() bare, unsafe
Same as null.
new[t] t mut*() bare, unsafe
*[t] t(a t*) bare, unsafe
*a reads the value pointed to by a.
*[t] t(a t mut*) bare, unsafe
set-deref[t] void(a t mut*, value t) bare, unsafe
*a := value writes value to the place pointed to be a.
subscript[t] t(a t*, n nat64) bare, unsafe
a[n] is the same as *(a + n).
subscript[t] t(a t mut*, n nat64) bare, unsafe
set-subscript[t] void(a t mut*, n nat64, value t) bare, unsafe
a[n] := value is the same as *(a + n) := value.
==[t] bool(a t*, b t*) bare, unsafe
true iff the two pointers are identical.
(That means: false if they point to equal values but are different pointers.)
==[t] bool(a t mut*, b t mut*) bare, unsafe
==[r, p] bool(a function r(p), b function r(p)) bare, unsafe
+[t] t*(a t*, offset nat64) bare, unsafe
Advance the pointer past offset values of type a.
Like in C, the address increases by offset * size-of@t.
+[t] t mut*(a t mut*, offset nat64) bare, unsafe
-[t] t*(a t*, offset nat64) bare, unsafe
Back up the pointer by offset values of type a.
-[t] t mut*(a t mut*, offset nat64) bare, unsafe
-[t] nat64(a t*, b t*) bare, unsafe
Get the difference between two pointers, measured in strides of a.
This is undefined behavior if a < b or if size-of@t == 0.
-[t] nat64(a t mut*, b t mut*) bare, unsafe
<=>[t] comparison(a t*, b t*) bare, unsafe
Same as a.to::nat64 <=> b.to::nat64.
<=>[t] comparison(a t mut*, b t mut*) bare, unsafe
size-of[t] nat64() bare, unsafe
Number of bytes taken up by a type.
You'll need to manually supply a type argument, as in size-of@nat.
If a is a reference type, this is just the size of a pointer.
Similarly, this is the same for all array types,
regardless of the number of size of the array elements.
pointer-cast[out, in] out*(a in*) bare, unsafe
Change the type of the pointee. This is like a pointer cast (out*) a in C.
At a low level, this is just an identity function; it just changes the type.
pointer-cast[out, in] out mut*(a in mut*) bare, unsafe
to[t] nat64(a t*) bare, unsafe
Raw address of a pointer.
to[t] nat64(a t mut*) bare, unsafe
to-const-pointer[t] t*(a nat64) bare, unsafe
Get a pointer from a raw address.
to-mut-pointer[t] t mut*(a nat64) bare, unsafe
swap[t] void(a t mut*, b t mut*) bare, unsafe
Swap the value pointed to be 'a' with the value pointed to by 'b'.
as-fun-pointer[r, p] function r(p)(a nat8*) bare, unsafe
reference-equal[t] bool(a t, b t) bare, unsafe
True if two references have the same pointer.
Contrast with a == b which can also be true for different pointers with equal contents.
mem-copy[t] void(dest t mut*, src t*, size nat64) bare, unsafe
Unlike 'mem-move', this does not handle 'dest' and 'src' overlapping
mem-move[t] void(dest t mut*, src t*, size nat64) bare, unsafe
Unlike 'mem-copy', this handles 'dest' and 'src' overlapping
mem-clear[t] void(dest t mut*, size nat64) bare, unsafe
Set a range to 0
const-pointer[t] builtin
A raw pointer. Equivalent to const a* in C.
The garbage collector does not trace raw pointers.
If a is a reference type, a* is a pointer to a pointer.
This is a read-only reference.
The pointee is not immutable; it could be modified if there are other references to it.
mut-pointer[t] builtin
This is like const-pointer but supports writing to the contents.
gc-safe-value[t] t() bare, unsafe
Returns a value which the GC will ignore.
This is 'null' for pointers, or an arbitrary value for non-pointer types.
In JS, this always the JS 'null' value.