aboutsummaryrefslogtreecommitdiff
path: root/src/nbc/binary.sml
diff options
context:
space:
mode:
authorCalvin <calvin@EESI>2013-03-15 15:26:20 -0400
committerCalvin <calvin@EESI>2013-03-15 15:26:20 -0400
commitb632667ce57af89691407bb8668e1512775278ae (patch)
treeb5742cef185f1cc4a7ba6005b5b4116ce7558a01 /src/nbc/binary.sml
parent39e39f82cc38d71018882b0aaaf58255858a7c56 (diff)
nbc added
Diffstat (limited to 'src/nbc/binary.sml')
-rw-r--r--src/nbc/binary.sml26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/nbc/binary.sml b/src/nbc/binary.sml
new file mode 100644
index 0000000..af5acd5
--- /dev/null
+++ b/src/nbc/binary.sml
@@ -0,0 +1,26 @@
+signature BINARY = sig
+ val fromInt32: int -> Word8Vector.vector
+ val fromInt16: int -> Word8Vector.vector
+ val fromReal: real -> Word8Vector.vector
+end
+
+structure Binary :> BINARY = struct
+ val word8VectorFromArray = Word8ArraySlice.vector o Word8ArraySlice.full
+ fun fromInt32 i =
+ let
+ val array = Word8Array.array (PackWord32Little.bytesPerElem, 0w0)
+ val word = LargeWord.fromInt i
+ in
+ PackWord32Little.update (array, 0, word)
+ ; word8VectorFromArray array
+ end
+ fun fromInt16 i =
+ let
+ val array = Word8Array.array (PackWord16Little.bytesPerElem, 0w0)
+ val word = LargeWord.fromInt i
+ in
+ PackWord16Little.update (array, 0, word)
+ ; word8VectorFromArray array
+ end
+ val fromReal = PackRealLittle.toBytes
+end