mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Add zero for other StdInt types
This commit is contained in:
parent
99795abe8e
commit
32b61fbced
@ -29,6 +29,7 @@
|
||||
(register copy (Fn [&Int8] Int8))
|
||||
|
||||
(defn prn [a] (Int8.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Int8)))
|
||||
)
|
||||
@ -59,6 +60,7 @@
|
||||
(register copy (Fn [&Int16] Int16))
|
||||
|
||||
(defn prn [a] (Int16.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Int16)))
|
||||
)
|
||||
@ -89,6 +91,7 @@
|
||||
(register copy (Fn [&Int32] Int32))
|
||||
|
||||
(defn prn [a] (Int32.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Int32)))
|
||||
)
|
||||
@ -119,6 +122,7 @@
|
||||
(register copy (Fn [&Int64] Int64))
|
||||
|
||||
(defn prn [a] (Int64.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Int64)))
|
||||
)
|
||||
@ -149,6 +153,7 @@
|
||||
(register copy (Fn [&Uint8] Uint8))
|
||||
|
||||
(defn prn [a] (Uint8.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Uint8)))
|
||||
)
|
||||
|
17
scratch
Normal file
17
scratch
Normal file
@ -0,0 +1,17 @@
|
||||
(defn safe-to-int16 [m m2]
|
||||
(match m
|
||||
(Maybe.Just b)
|
||||
(match m2
|
||||
(Maybe.Just bb) (Maybe.Just (to-int16 b bb))
|
||||
(Maybe.Nothing) (Maybe.Nothing))
|
||||
(Maybe.Nothing) (Maybe.Nothing)))
|
||||
|
||||
(doc bytes->int16
|
||||
"Interprets the first two bytes in a byte sequence as an int16 value.")
|
||||
(sig bytes->int16 (Fn [Order (Ref (Array Byte) a)] (Maybe Int)))
|
||||
(defn bytes->int16 [order bs]
|
||||
(let [first-byte (Array.nth bs 0)
|
||||
second-byte (Array.nth bs 1)]
|
||||
(match order
|
||||
(Order.LittleEndian) (safe-to-int16 first-byte second-byte)
|
||||
(Order.BigEndian) (safe-to-int16 second-byte first-byte))))
|
Loading…
Reference in New Issue
Block a user