|
155 | 155 | hd/1, |
156 | 156 | is_atom/1, |
157 | 157 | is_binary/1, |
| 158 | + is_bitstring/1, |
158 | 159 | is_boolean/1, |
159 | 160 | is_float/1, |
160 | 161 | is_function/1, |
@@ -933,15 +934,16 @@ binary_to_list(_Binary) -> |
933 | 934 |
|
934 | 935 | %%----------------------------------------------------------------------------- |
935 | 936 | %% @param Bitstring Bitstring to convert to list |
936 | | -%% @returns a list of bytes from the bitstring |
| 937 | +%% @returns a list of bytes, with a final element holding the trailing bits if |
| 938 | +%% `Bitstring' is not a whole number of bytes |
937 | 939 | %% @doc Convert a bitstring to a list of bytes. |
938 | 940 | %% |
939 | | -%% Unlike Erlang/OTP, AtomVM only supports byte-aligned bitstrings (binaries), |
940 | | -%% so the returned list never has a trailing bitstring and this function |
941 | | -%% behaves like `binary_to_list/1'. |
| 941 | +%% If the number of bits in `Bitstring' is not divisible by `8', the |
| 942 | +%% last element of the list is a bitstring containing the trailing |
| 943 | +%% `1..7' bits, e.g. `bitstring_to_list(<<1:1>>)' returns `[<<1:1>>]'. |
942 | 944 | %% @end |
943 | 945 | %%----------------------------------------------------------------------------- |
944 | | --spec bitstring_to_list(Bitstring :: bitstring()) -> [byte()]. |
| 946 | +-spec bitstring_to_list(Bitstring :: bitstring()) -> [byte() | bitstring()]. |
945 | 947 | bitstring_to_list(_Bitstring) -> |
946 | 948 | erlang:nif_error(undefined). |
947 | 949 |
|
@@ -1973,6 +1975,19 @@ is_atom(_Term) -> |
1973 | 1975 | is_binary(_Term) -> |
1974 | 1976 | erlang:nif_error(undefined). |
1975 | 1977 |
|
| 1978 | +%%----------------------------------------------------------------------------- |
| 1979 | +%% @param Term the term to test |
| 1980 | +%% @returns `true' if `Term' is a bitstring; `false', otherwise. |
| 1981 | +%% @doc Return `true' if `Term' is a bitstring (including a binary); |
| 1982 | +%% `false', otherwise. |
| 1983 | +%% |
| 1984 | +%% This function may be used in a guard expression. |
| 1985 | +%% @end |
| 1986 | +%%----------------------------------------------------------------------------- |
| 1987 | +-spec is_bitstring(Term :: term()) -> boolean(). |
| 1988 | +is_bitstring(_Term) -> |
| 1989 | + erlang:nif_error(undefined). |
| 1990 | + |
1976 | 1991 | %%----------------------------------------------------------------------------- |
1977 | 1992 | %% @param Term the term to test |
1978 | 1993 | %% @returns `true' if `Term' is a boolean (`true' or `false'); `false', otherwise. |
|
0 commit comments