summaryrefslogtreecommitdiff
path: root/lib/std/slcp.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/slcp.myr')
-rw-r--r--lib/std/slcp.myr26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/std/slcp.myr b/lib/std/slcp.myr
new file mode 100644
index 0000000..1035a29
--- /dev/null
+++ b/lib/std/slcp.myr
@@ -0,0 +1,26 @@
+use "die.use"
+use "types.use"
+
+pkg std =
+ generic slcp : (a : @a[:], b : @a[:] -> void)
+;;
+
+generic slcp = {a : @a[:], b : @a[:]
+ var i
+ var addr_a, addr_b
+
+ assert(a.len == b.len, "arguments to slcp() must be of equal length")
+
+ addr_a = a castto(@a#) castto(intptr)
+ addr_b = b castto(@a#) castto(intptr)
+ if addr_a <= addr_b
+ for i = 0; i < a.len; i++
+ a[i] = b[i]
+ ;;
+ else
+ for i = a.len; i > 0; i--
+ a[i - 1] = b[i - 1]
+ ;;
+ ;;
+
+}