5252 erase /0 ,
5353 erase /1 ,
5454 function_exported /3 ,
55+ is_builtin /3 ,
5556 loaded /0 ,
5657 module_loaded /1 ,
5758 display /1 ,
7172 binary_to_integer /1 ,
7273 binary_to_integer /2 ,
7374 binary_to_list /1 ,
75+ bitstring_to_list /1 ,
7476 atom_to_binary /1 ,
7577 atom_to_binary /2 ,
7678 atom_to_list /1 ,
123125 garbage_collect /1 ,
124126 binary_to_term /1 ,
125127 term_to_binary /1 ,
128+ term_to_binary /2 ,
126129 split_binary /2 ,
127130 crc32 /1 ,
128131 crc32 /2 ,
187190 atomvm_heap_growth_strategy / 0 ,
188191 stacktrace / 0 ,
189192 stacktrace_extrainfo / 0 ,
190- raise_stacktrace / 0
193+ raise_stacktrace / 0 ,
194+ term_to_binary_option / 0
191195]).
192196
193197-type atom_encoding () :: latin1 | utf8 | unicode .
206210
207211-type demonitor_option () :: flush | {flush , boolean ()} | info | {info , boolean ()}.
208212
213+ -type term_to_binary_option () ::
214+ compressed
215+ | {compressed , Level :: 0 ..9 }
216+ | deterministic
217+ | {minor_version , Version :: 0 ..2 }.
218+
209219-type atomvm_heap_growth_strategy () ::
210220 bounded_free
211221 | minimum
@@ -686,6 +696,27 @@ erase(_Key) ->
686696function_exported (_Module , _Function , _Arity ) ->
687697 erlang :nif_error (undefined ).
688698
699+ % %-----------------------------------------------------------------------------
700+ % % @param Module module name
701+ % % @param Function function name
702+ % % @param Arity function arity
703+ % % @returns `true' if `Module:Function/Arity' is a builtin, `false' otherwise.
704+ % % @doc Determine whether a function is implemented natively (as a BIF or a
705+ % % NIF) by AtomVM. As on BEAM, this reflects functions "implemented in
706+ % % C" rather than in Erlang, but it is answered against AtomVM's own
707+ % % registry. It therefore differs from BEAM whenever the two virtual
708+ % % machines disagree on whether a given function is native: for
709+ % % example `erlang:atom_to_binary/1' is native on AtomVM but
710+ % % Erlang-implemented on BEAM, while `erlang:md5/1' is a BEAM BIF that
711+ % % AtomVM implements in Erlang. An arity that no builtin has (including a
712+ % % negative integer) returns `false'. Raises `badarg' if `Module' or
713+ % % `Function' is not an atom, or `Arity' is not an integer.
714+ % % @end
715+ % %-----------------------------------------------------------------------------
716+ -spec is_builtin (Module :: module (), Function :: atom (), Arity :: arity ()) -> boolean ().
717+ is_builtin (_Module , _Function , _Arity ) ->
718+ erlang :nif_error (undefined ).
719+
689720% %-----------------------------------------------------------------------------
690721% % @returns list of loaded modules
691722% % @doc Returns all loaded modules.
@@ -900,6 +931,20 @@ binary_to_integer(_Binary, _Base) ->
900931binary_to_list (_Binary ) ->
901932 erlang :nif_error (undefined ).
902933
934+ % %-----------------------------------------------------------------------------
935+ % % @param Bitstring Bitstring to convert to list
936+ % % @returns a list of bytes from the bitstring
937+ % % @doc Convert a bitstring to a list of bytes.
938+ % %
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'.
942+ % % @end
943+ % %-----------------------------------------------------------------------------
944+ -spec bitstring_to_list (Bitstring :: bitstring ()) -> [byte ()].
945+ bitstring_to_list (_Bitstring ) ->
946+ erlang :nif_error (undefined ).
947+
903948% %-----------------------------------------------------------------------------
904949% % @param Atom Atom to convert
905950% % @returns a binary with the atom's name
@@ -1555,10 +1600,8 @@ garbage_collect(_Pid) ->
15551600% %-----------------------------------------------------------------------------
15561601% % @returns A term decoded from passed binary
15571602% % @param Binary binary to decode
1558- % % @doc Decode a term that was previously encodes with `term_to_binary/1'
1603+ % % @doc Decode a term that was previously encoded with `term_to_binary/1'.
15591604% % This function should be mostly compatible with its Erlang/OTP counterpart.
1560- % % Unlike modern Erlang/OTP, resources are currently serialized as empty
1561- % % binaries and cannot be unserialized.
15621605% % @end
15631606% %-----------------------------------------------------------------------------
15641607-spec binary_to_term (Binary :: binary ()) -> any ().
@@ -1570,14 +1613,42 @@ binary_to_term(_Binary) ->
15701613% % @param Term term to encode
15711614% % @doc Encode a term to a binary that can later be decoded with `binary_to_term/1'.
15721615% % This function should be mostly compatible with its Erlang/OTP counterpart.
1573- % % Unlike modern Erlang/OTP, resources are currently serialized as empty
1574- % % binaries.
15751616% % @end
15761617% %-----------------------------------------------------------------------------
15771618-spec term_to_binary (Term :: any ()) -> binary ().
15781619term_to_binary (_Term ) ->
15791620 erlang :nif_error (undefined ).
15801621
1622+ % %-----------------------------------------------------------------------------
1623+ % % @returns A binary encoding passed term.
1624+ % % @param Term term to encode
1625+ % % @param Options encoding options
1626+ % % @doc Encode a term to a binary that can later be decoded with `binary_to_term/1'.
1627+ % %
1628+ % % The following options are accepted:
1629+ % % <ul>
1630+ % % <li>`compressed' and `{compressed, Level}' (`Level' from 0 to 9): accepted
1631+ % % for compatibility but ignored. AtomVM's encoding is always
1632+ % % uncompressed; the resulting binary is still a valid external term that
1633+ % % `binary_to_term/1' can decode.</li>
1634+ % % <li>`deterministic': accepted for compatibility. AtomVM's encoding is
1635+ % % already deterministic, so this option has no effect.</li>
1636+ % % <li>`{minor_version, Version}' (`Version' from 0 to 2): accepted for
1637+ % % compatibility. AtomVM always encodes floats using the `NEW_FLOAT_EXT'
1638+ % % representation (minor version 1 and later).</li>
1639+ % % </ul>
1640+ % %
1641+ % % Unlike Erlang/OTP, the `local' option is not supported: AtomVM never emits
1642+ % % the node-local `LOCAL_EXT' encoding. Passing `local', or any other unknown
1643+ % % option, raises a `badarg' error.
1644+ % %
1645+ % % This function should be mostly compatible with its Erlang/OTP counterpart.
1646+ % % @end
1647+ % %-----------------------------------------------------------------------------
1648+ -spec term_to_binary (Term :: any (), Options :: [term_to_binary_option ()]) -> binary ().
1649+ term_to_binary (_Term , _Options ) ->
1650+ erlang :nif_error (undefined ).
1651+
15811652% %-----------------------------------------------------------------------------
15821653% % @returns A tuple with two subbinaries
15831654% % @param Bin binary to split
0 commit comments