summaryrefslogtreecommitdiff
path: root/lib/std/endian.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-08-26 12:20:58 -0700
committerOri Bernstein <ori@eigenstate.org>2015-08-26 12:20:58 -0700
commit2bc852bda98762d3bc01548bf972e3f1b137fbfb (patch)
tree74831deed3c9057c5fe0cbb8790d220e855bc792 /lib/std/endian.myr
parent3de952510eb2a23350d24ed926f19c0cf72a12f2 (diff)
downloadmc-2bc852bda98762d3bc01548bf972e3f1b137fbfb.tar.gz
Move Myrddin libs to lib/ subdirectory.
Diffstat (limited to 'lib/std/endian.myr')
-rw-r--r--lib/std/endian.myr32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/std/endian.myr b/lib/std/endian.myr
new file mode 100644
index 0000000..8bac74f
--- /dev/null
+++ b/lib/std/endian.myr
@@ -0,0 +1,32 @@
+pkg std =
+ generic hosttonet : (v : @a -> @a)
+ generic nettohost : (v : @a -> @a)
+;;
+
+/* FIXME: we only support little endian platforms right now,
+ so we assume a little endian machine. FIX THIS. */
+generic hosttonet = {v : @a::(integral,numeric)
+ var i
+ var ret
+
+ ret = 0
+ for i = 0; i < sizeof(@a); i++
+ ret <<= 8
+ ret |= v & 0xff
+ v >>= 8
+ ;;
+ -> ret
+}
+
+generic nettohost = {v : @a::(integral,numeric)
+ var i
+ var ret
+
+ ret = 0
+ for i = 0; i < sizeof(@a); i++
+ ret <<= 8
+ ret |= v & 0xff
+ v >>= 8
+ ;;
+ -> ret
+}