summaryrefslogtreecommitdiff
path: root/src/nbc/binary.sml
blob: af5acd5f7e25a234a6c8ed60766d020113633c40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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