summaryrefslogtreecommitdiff
path: root/libbio/puti.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-13 00:46:24 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-13 00:46:24 -0700
commit20bb032dc16ab0a0a20e9a5705738c797ac4b3da (patch)
tree015f8be7a1d1d99e09e682c35956538ebb57cf50 /libbio/puti.myr
parentac02d84497997778d2c9680f5c7fc26b9814f62c (diff)
downloadmc-20bb032dc16ab0a0a20e9a5705738c797ac4b3da.tar.gz
Add code to subdir in preparation for merging with mc.
Diffstat (limited to 'libbio/puti.myr')
-rw-r--r--libbio/puti.myr62
1 files changed, 62 insertions, 0 deletions
diff --git a/libbio/puti.myr b/libbio/puti.myr
new file mode 100644
index 0000000..efb79c2
--- /dev/null
+++ b/libbio/puti.myr
@@ -0,0 +1,62 @@
+use std
+
+use "bio.use"
+
+pkg bio =
+ /* unsigned big endian */
+ generic putbe8 : (f : file#, v : @a::(numeric,integral) -> std.size)
+ generic putbe16 : (f : file#, v : @a::(numeric,integral) -> std.size)
+ generic putbe32 : (f : file#, v : @a::(numeric,integral) -> std.size)
+ generic putbe64 : (f : file#, v : @a::(numeric,integral) -> std.size)
+
+ /* unsigned little endian */
+ generic putle8 : (f : file#, v : @a::(numeric,integral) -> std.size)
+ generic putle16 : (f : file#, v : @a::(numeric,integral) -> std.size)
+ generic putle32 : (f : file#, v : @a::(numeric,integral) -> std.size)
+ generic putle64 : (f : file#, v : @a::(numeric,integral) -> std.size)
+;;
+
+generic putbe8 = {f, v; -> putbe(f, v castto(uint64), 1)}
+generic putbe16 = {f, v; -> putbe(f, v castto(uint64), 2)}
+generic putbe32 = {f, v; -> putbe(f, v castto(uint64), 4)}
+generic putbe64 = {f, v; -> putbe(f, v castto(uint64), 8)}
+
+generic putle8 = {f, v; -> putle(f, v castto(uint64), 1)}
+generic putle16 = {f, v; -> putle(f, v castto(uint64), 2)}
+generic putle32 = {f, v; -> putle(f, v castto(uint64), 4)}
+generic putle64 = {f, v; -> putle(f, v castto(uint64), 8)}
+
+const putle = {f, v, n
+ var buf : byte[8]
+
+ if !ensurewrite(f, n)
+ -> 0
+ ;;
+ buf[0] = (v >> 0) & 0xff castto(byte)
+ buf[1] = (v >> 8) & 0xff castto(byte)
+ buf[2] = (v >> 16) & 0xff castto(byte)
+ buf[3] = (v >> 24) & 0xff castto(byte)
+ buf[4] = (v >> 32) & 0xff castto(byte)
+ buf[5] = (v >> 40) & 0xff castto(byte)
+ buf[6] = (v >> 48) & 0xff castto(byte)
+ buf[7] = (v >> 56) & 0xff castto(byte)
+ write(f, buf[:n])
+}
+
+const putbe = {f, v, n
+ var buf : byte[8]
+
+ if !ensurewrite(f, n)
+ -> 0
+ ;;
+ buf[0] = (v >> 56) & 0xff castto(byte)
+ buf[1] = (v >> 48) & 0xff castto(byte)
+ buf[2] = (v >> 40) & 0xff castto(byte)
+ buf[3] = (v >> 32) & 0xff castto(byte)
+ buf[4] = (v >> 24) & 0xff castto(byte)
+ buf[5] = (v >> 16) & 0xff castto(byte)
+ buf[6] = (v >> 8) & 0xff castto(byte)
+ buf[7] = (v >> 0) & 0xff castto(byte)
+ write(f, buf[8-n:])
+}
+