-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy patherlang.erl
More file actions
1545 lines (1425 loc) · 63.1 KB
/
erlang.erl
File metadata and controls
1545 lines (1425 loc) · 63.1 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%
% This file is part of AtomVM.
%
% Copyright 2018 Fred Dushin <fred@dushin.net>
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
%
%%-----------------------------------------------------------------------------
%% @doc An implementation of the Erlang/OTP erlang module, for functions
%% that are not already defined as NIFs.
%% @end
%%-----------------------------------------------------------------------------
-module(erlang).
-export([
apply/2,
apply/3,
start_timer/3, start_timer/4,
cancel_timer/1,
send_after/3,
process_info/2,
system_info/1,
system_flag/2,
md5/1,
is_map/1,
is_map_key/2,
is_record/2,
map_size/1,
map_get/2,
monotonic_time/1,
min/2,
max/2,
memory/1,
nif_error/1,
get/0,
get/1,
put/2,
erase/0,
erase/1,
function_exported/3,
module_loaded/1,
display/1,
list_to_atom/1,
list_to_existing_atom/1,
list_to_binary/1,
list_to_integer/1,
list_to_integer/2,
list_to_tuple/1,
iolist_size/1,
iolist_to_binary/1,
binary_to_atom/1,
binary_to_atom/2,
binary_to_integer/1,
binary_to_integer/2,
binary_to_list/1,
atom_to_binary/1,
atom_to_binary/2,
atom_to_list/1,
float_to_binary/1,
float_to_binary/2,
float_to_list/1,
float_to_list/2,
fun_info/1,
fun_info/2,
integer_to_binary/1,
integer_to_binary/2,
integer_to_list/1,
integer_to_list/2,
fun_to_list/1,
pid_to_list/1,
port_to_list/1,
ref_to_list/1,
register/2,
unregister/1,
whereis/1,
spawn/1,
spawn/3,
spawn_link/1,
spawn_link/3,
spawn_monitor/1,
spawn_monitor/3,
spawn_opt/2,
spawn_opt/4,
link/1,
unlink/1,
make_ref/0,
send/2,
monitor/2,
demonitor/1,
demonitor/2,
exit/1,
exit/2,
open_port/2,
system_time/1,
group_leader/0,
group_leader/2,
process_flag/2,
get_module_info/1,
get_module_info/2,
processes/0,
is_process_alive/1,
garbage_collect/0,
garbage_collect/1,
binary_to_term/1,
term_to_binary/1,
split_binary/2,
timestamp/0,
universaltime/0,
localtime/0,
setnode/2,
setnode/3,
is_alive/0,
get_cookie/0,
get_cookie/1,
set_cookie/1,
set_cookie/2,
dist_ctrl_get_data_notification/1,
dist_ctrl_get_data/1,
dist_ctrl_put_data/2,
unique_integer/0,
unique_integer/1,
bump_reductions/1
]).
-export_type([
time_unit/0,
timestamp/0
]).
%%
%% TODO Correct the following bugs
%% * cancel_timer should be renamed cancel, per the OTP documentation
%% * return value needs to be {ok, cancel} or {error, Reason}
%% * review API documentation for timer functions in this module
%%
-type atom_encoding() :: latin1 | utf8 | unicode.
-type mem_type() :: binary.
-type time_unit() :: second | millisecond | microsecond.
-type timestamp() :: {
MegaSecs :: non_neg_integer(), Secs :: non_neg_integer(), MicroSecs :: non_neg_integer
}.
-type float_format_option() ::
{decimals, Decimals :: 0..57}
| {scientific, Decimals :: 0..57}
| compact.
-type demonitor_option() :: flush | {flush, boolean()} | info | {info, boolean()}.
-type heap_growth_strategy() ::
bounded_free
| minimum
| fibonacci.
-type spawn_option() ::
{min_heap_size, pos_integer()}
| {max_heap_size, pos_integer()}
| {atomvm_heap_growth, heap_growth_strategy()}
| link
| monitor.
-type send_destination() ::
pid()
| port()
| atom().
% Current type until we make these references
-type resource() :: binary().
%%-----------------------------------------------------------------------------
%% @param Time time in milliseconds after which to send the timeout message.
%% @param Dest Pid or server name to which to send the timeout message.
%% @param Msg Message to send to Dest after Time ms.
%% @returns a reference that can be used to cancel the timer, if desired.
%% @doc Start a timer, and send {timeout, TimerRef, Msg} to Dest after
%% Time ms, where TimerRef is the reference returned from this function.
%% @end
%%-----------------------------------------------------------------------------
-spec start_timer(Time :: non_neg_integer(), Dest :: pid() | atom(), Msg :: term()) -> reference().
start_timer(Time, Dest, Msg) ->
start_timer(Time, Dest, Msg, []).
%%-----------------------------------------------------------------------------
%% @hidden
%% @param Time time in milliseconds after which to send the timeout message.
%% @param Dest Pid or server name to which to send the timeout message.
%% @param Msg Message to send to Dest after Time ms.
%% @param Options options
%% @returns a reference that can be used to cancel the timer, if desired.
%% @doc Start a timer, and send {timeout, TimerRef, Msg} to Dest after
%% Time ms, where TimerRef is the reference returned from this function.
%%
%% <em><b>Note.</b> The Options argument is currently ignored.</em>
%%-----------------------------------------------------------------------------
-spec start_timer(
Time :: non_neg_integer(), Dest :: pid() | atom(), Msg :: term(), _Options :: list()
) -> reference().
start_timer(Time, Dest, Msg, _Options) ->
timer_manager:start_timer(Time, Dest, Msg).
%%-----------------------------------------------------------------------------
%% @hidden
%% @param Time time in milliseconds after which to send the timeout message.
%% @param Dest Pid or server name to which to send the timeout message.
%% @param Msg Message to send to Dest after Time ms.
%% @param Options options
%% @returns a reference that can be used to cancel the timer, if desired.
%% @doc Start a timer, and send {timeout, TimerRef, Msg} to Dest after
%% Time ms, where TimerRef is the reference returned from this function.
%%
%% <em><b>Note.</b> The Options argument is currently ignored.</em>
%%-----------------------------------------------------------------------------
-spec cancel_timer(TimerRef :: reference()) -> ok.
cancel_timer(TimerRef) ->
timer_manager:cancel_timer(TimerRef).
%%-----------------------------------------------------------------------------
%% @param Time time in milliseconds after which to send the message.
%% @param Dest Pid or server name to which to send the message.
%% @param Msg Message to send to Dest after Time ms.
%% @returns a reference that can be used to cancel the timer, if desired.
%% @doc Send Msg to Dest after Time ms.
%% @end
%%-----------------------------------------------------------------------------
-spec send_after(Time :: non_neg_integer(), Dest :: pid() | atom(), Msg :: term()) -> reference().
send_after(Time, Dest, Msg) ->
timer_manager:send_after(Time, Dest, Msg).
%%-----------------------------------------------------------------------------
%% @param Pid the process pid.
%% @param Key key used to find process information.
%% @returns process information for the specified pid defined by the specified key.
%% @doc Return process information.
%%
%% This function returns information about the specified process.
%% The type of information returned is dependent on the specified key.
%%
%% The following keys are supported:
%% <ul>
%% <li><b>heap_size</b> the number of words used in the heap (integer), including the stack but excluding fragments</li>
%% <li><b>total_heap_size</b> the number of words used in the heap (integer) including fragments</li>
%% <li><b>registered_name</b> - returns `{registered_name, RegisteredName}' where `RegisteredName' is the registered name of the port or process. If the port/process has no registered name, `[]' is returned</li>
%% <li><b>stack_size</b> the number of words used in the stack (integer)</li>
%% <li><b>message_queue_len</b> the number of messages enqueued for the process (integer)</li>
%% <li><b>memory</b> the estimated total number of bytes in use by the process (integer)</li>
%% <li><b>links</b> the list of linked processes</li>
%% <li><b>monitored_by</b> the list of processes, NIF resources or ports that monitor the process</li>
%% </ul>
%% Specifying an unsupported term or atom raises a bad_arg error.
%%
%% @end
%%-----------------------------------------------------------------------------
-spec process_info
(Pid :: pid(), heap_size) -> {heap_size, non_neg_integer()};
(Pid :: pid(), total_heap_size) -> {total_heap_size, non_neg_integer()};
(Pid :: pid(), registered_name) -> {registered_name, term()} | [];
(Pid :: pid(), stack_size) -> {stack_size, non_neg_integer()};
(Pid :: pid(), message_queue_len) -> {message_queue_len, non_neg_integer()};
(Pid :: pid(), memory) -> {memory, non_neg_integer()};
(Pid :: pid(), links) -> {links, [pid()]};
(Pid :: pid(), monitored_by) -> {monitored_by, [pid() | resource() | port()]};
(Pid :: pid(), reductions) -> {reductions, [non_neg_integer()]}.
process_info(_Pid, _Key) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Key key used to find system information.
%% @returns system information defined by the specified key.
%% @doc Return system information.
%%
%% This function returns information about the system on which AtomVM is
%% running. The type of information returned is dependent on the specified key.
%%
%% The following keys are supported on all platforms:
%% <ul>
%% <li><b>process_count</b> the number of processes running in the node (integer)</li>
%% <li><b>port_count</b> the number of ports running in the node (integer)</li>
%% <li><b>atom_count</b> the number of atoms currently allocated (integer)</li>
%% <li><b>system_architecture</b> the processor and OS architecture (binary)</li>
%% <li><b>version</b> the version of the AtomVM executable image (binary)</li>
%% <li><b>wordsize</b> the number of bytes in a machine word on the current platform (integer)</li>
%% <li><b>schedulers</b> the number of schedulers, equal to the number of online processors (integer)</li>
%% <li><b>schedulers_online</b> the current number of schedulers (integer)</li>
%% </ul>
%% The following keys are supported on the ESP32 platform:
%% <ul>
%% <li><b>esp32_free_heap_size</b> the number of (noncontiguous) free bytes in the ESP32 heap (integer)</li>
%% <li><b>esp32_largest_free_block</b> the number of the largest contiguous free bytes in the ESP32 heap (integer)</li>
%% <li><b>esp32_minimum_free_size</b> the smallest number of free bytes in the ESP32 heap since boot (integer)</li>
%% <li><b>esp32_chip_info</b> Details about the model and capabilities of the ESP32 device (map)</li>
%% </ul>
%%
%% Additional keys may be supported on some platforms that are not documented here.
%%
%% Specifying an unsupported atom key will results in returning the atom 'undefined'.
%%
%% Specifying a term that is not an atom will result in a bad_arg error.
%%
%% @end
%%-----------------------------------------------------------------------------
-spec system_info(Key :: atom()) -> term().
system_info(_Key) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Key key used to change system flag.
%% @param Value value to change
%% @returns previous value of the flag.
%% @doc Update system flags.
%%
%% This function allows to modify system flags at runtime.
%%
%% The following key is supported on SMP builds:
%% <ul>
%% <li><b>schedulers_online</b> the number of schedulers online</li>
%% </ul>
%%
%% Specifying an unsupported atom key will result in a bad_arg error.
%% Specifying a term that is not an atom will result in a bad_arg error.
%%
%% @end
%%-----------------------------------------------------------------------------
-spec system_flag(Key :: atom(), term()) -> term().
system_flag(_Key, _Value) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Data data to compute hash of, as a binary.
%% @returns the md5 hash of the input Data, as a 16-byte binary.
%% @doc Computes the MD5 hash of an input binary, as defined by
%% https://www.ietf.org/rfc/rfc1321.txt
%% @end
%%-----------------------------------------------------------------------------
-spec md5(Data :: binary()) -> binary().
md5(Data) when is_binary(Data) ->
crypto:hash(md5, Data).
%%-----------------------------------------------------------------------------
%% @param Module Name of module
%% @param Function Exported function name
%% @param Args Parameters to pass to function (max 6)
%% @returns Returns the result of Module:Function(Args).
%% @doc Returns the result of applying Function in Module to Args. The applied
%% function must be exported from Module. The arity of the function is the
%% length of Args. Example:
%% ```> apply(lists, reverse, [[a, b, c]]).
%% [c,b,a]
%% > apply(erlang, atom_to_list, ['AtomVM']).
%% "AtomVM"'''
%% If the number of arguments are known at compile time, the call is better
%% written as Module:Function(Arg1, Arg2, ..., ArgN).
%% @end
%%-----------------------------------------------------------------------------
-spec apply(Module :: module(), Function :: function(), Args :: [term()]) -> term().
apply(Module, Function, Args) ->
case Args of
[] ->
Module:Function();
[Arg1] ->
Module:Function(Arg1);
[Arg1, Arg2] ->
Module:Function(Arg1, Arg2);
[Arg1, Arg2, Arg3] ->
Module:Function(Arg1, Arg2, Arg3);
[Arg1, Arg2, Arg3, Arg4] ->
Module:Function(Arg1, Arg2, Arg3, Arg4);
[Arg1, Arg2, Arg3, Arg4, Arg5] ->
Module:Function(Arg1, Arg2, Arg3, Arg4, Arg5);
[Arg1, Arg2, Arg3, Arg4, Arg5, Arg6] ->
Module:Function(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
_ ->
error(badarg)
end.
%%-----------------------------------------------------------------------------
%% @param Function Function to call
%% @param Args Parameters to pass to function (max 6)
%% @returns Returns the result of Function(Args).
%% @doc Returns the result of applying Function to Args. The arity of the
%% function is the length of Args. Example:
%% ```> apply(fun(R) -> lists:reverse(R) end, [[a, b, c]]).
%% [c,b,a]
%% > apply(fun erlang:atom_to_list/1, ['AtomVM']).
%% "AtomVM"'''
%% If the number of arguments are known at compile time, the call is better
%% written as Function(Arg1, Arg2, ..., ArgN).
%% @end
%%-----------------------------------------------------------------------------
-spec apply(Function :: fun(), Args :: [term()]) -> term().
apply(Function, Args) ->
case Args of
[] ->
Function();
[Arg1] ->
Function(Arg1);
[Arg1, Arg2] ->
Function(Arg1, Arg2);
[Arg1, Arg2, Arg3] ->
Function(Arg1, Arg2, Arg3);
[Arg1, Arg2, Arg3, Arg4] ->
Function(Arg1, Arg2, Arg3, Arg4);
[Arg1, Arg2, Arg3, Arg4, Arg5] ->
Function(Arg1, Arg2, Arg3, Arg4, Arg5);
[Arg1, Arg2, Arg3, Arg4, Arg5, Arg6] ->
Function(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
_ ->
error(badarg)
end.
%%-----------------------------------------------------------------------------
%% @param Map the map to test
%% @returns `true' if `Map' is a map; `false', otherwise.
%% @doc Return `true' if `Map' is a map; `false', otherwise.
%%
%% This function may be used in a guard expression.
%% @end
%%-----------------------------------------------------------------------------
-spec is_map(Map :: map()) -> boolean().
is_map(_Map) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Term
%% @param RecordTag atom representing tuple tag
%%
%% @doc Returns true if Term is a tuple and its first element is RecordTag, false otherwise.
%% @end
%%-----------------------------------------------------------------------------
-spec is_record(Term :: term(), RecordTag :: atom()) -> boolean().
is_record(_Term, _RecordTag) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Map the map
%% @returns the size of the map
%% @doc Returns the size of (i.e., the number of entries in) the map
%%
%% This function raises a `{badmap, Map}' error if `Map' is not a map.
%%
%% This function may be used in a guard expression.
%% @end
%%-----------------------------------------------------------------------------
-spec map_size(Map :: map()) -> non_neg_integer().
map_size(_Map) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Key the key to get
%% @param Map the map from which to get the value
%% @returns the value in `Map' associated with `Key', if it exists.
%% @doc Get the value in `Map' associated with `Key', if it exists.
%%
%% This function raises a `{badkey, Key}' error if 'Key' does not occur in
%% `Map' or a `{badmap, Map}' if `Map' is not a map.
%%
%% This function may be used in a guard expression.
%% @end
%%-----------------------------------------------------------------------------
-spec map_get(Key :: term(), Map :: map()) -> Value :: term().
map_get(_Key, _Map) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Key the key
%% @param Map the map
%% @returns `true' if `Key' is associated with a value in `Map'; `false', otherwise.
%% @doc Return `true' if `Key' is associated with a value in `Map'; `false', otherwise.
%%
%% This function raises a `{badmap, Map}' error if `Map' is not a map.
%%
%% This function may be used in a guard expression.
%% @end
%%-----------------------------------------------------------------------------
-spec is_map_key(Key :: term(), Map :: map()) -> boolean().
is_map_key(_Key, _Map) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param A any term
%% @param B any term
%% @returns `A' if `A < B'; `B', otherwise.
%% @doc Return the minimum value of two terms
%%
%% Terms are compared using `<' and follow the ordering principles defined in
%% https://www.erlang.org/doc/reference_manual/expressions.html#term-comparisons
%% @end
%%-----------------------------------------------------------------------------
-spec min(A :: any(), B :: any()) -> any().
min(_A, _B) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param A any term
%% @param B any term
%% @returns `A' if `A > B'; `B', otherwise.
%% @doc Return the maximum value of two terms
%%
%% Terms are compared using `>' and follow the ordering principles defined in
%% https://www.erlang.org/doc/reference_manual/expressions.html#term-comparisons
%% @end
%%-----------------------------------------------------------------------------
-spec max(A :: any(), B :: any()) -> any().
max(_A, _B) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Type the type of memory to request
%% @returns the amount of memory (in bytes) used of the specified type
%% @doc Return the amount of memory (in bytes) used of the specified type
%%
%% @end
%%-----------------------------------------------------------------------------
-spec memory(Type :: mem_type()) -> non_neg_integer().
memory(_Type) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Unit time unit
%% @returns monotonic time in the specified units
%% @doc Return the monotonic time in the specified units.
%%
%% Monotonic time varies from system to system, and should not be used
%% to determine, for example the wall clock time.
%%
%% Instead, monotonic time should be used to compute time differences,
%% where the function is guaranteed to return a (not necessarily strictly)
%% monotonically increasing value.
%%
%% For example, on ESP32 system, monotonic time is reported as the difference from
%% the current time and the time the ESP32 device was started, whereas on UNIX
%% systems the value may vary among UNIX systems (e.g., Linux, macOS, FreeBSD).
%% @end
%%-----------------------------------------------------------------------------
-spec monotonic_time(Unit :: time_unit()) -> integer().
monotonic_time(_Unit) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @returns the process directory
%% @doc Return all values from the process dictionary
%% @end
%%-----------------------------------------------------------------------------
-spec get() -> [{any(), any()}].
get() ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Key key in the process dictionary
%% @returns value associated with this key or undefined
%% @doc Return a value associated with a given key in the process dictionary
%% @end
%%-----------------------------------------------------------------------------
-spec get(Key :: any()) -> any().
get(_Key) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Key key to add to the process dictionary
%% @param Value value to store in the process dictionary
%% @returns the previous value associated with this key or undefined
%% @doc Store a value with a given key in the process dictionary.
%% @end
%%-----------------------------------------------------------------------------
-spec put(Key :: any(), Value :: any()) -> any().
put(_Key, _Value) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @returns the previous process dictionary.
%% @doc Erase all keys from the process dictionary.
%% @end
%%-----------------------------------------------------------------------------
-spec erase() -> [{any(), any()}].
erase() ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Key key to erase from the process dictionary
%% @returns the previous value associated with this key or undefined
%% @doc Erase a key from the process dictionary.
%% @end
%%-----------------------------------------------------------------------------
-spec erase(Key :: any()) -> any().
erase(_Key) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Module module to test
%% @param Function function to test
%% @param Arity arity to test
%% @returns `true' if Module exports a Function with this Arity
%% @doc Determine if a function is exported
%% @end
%%-----------------------------------------------------------------------------
-spec function_exported(Module :: module(), Function :: atom(), Arity :: arity()) -> boolean().
function_exported(_Module, _Function, _Arity) ->
erlang:nif_error(undefined).
%% @param Module name of module
%% @returns boolean
%% @doc Returns true if module is loaded without attempting to do it.
%% @end
-spec module_loaded(Module :: atom()) -> boolean().
module_loaded(_Module) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Term term to print
%% @returns `true'
%% @doc Print a term to stdout.
%% @end
%%-----------------------------------------------------------------------------
-spec display(Term :: any()) -> true.
display(_Term) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param String string to convert to an atom
%% @returns an atom from the string
%% @see list_to_existing_atom/1
%% @doc Convert a string into an atom.
%% Unlike Erlang/OTP 20+, atoms are limited to ISO-8859-1 characters. The VM
%% currently aborts if passed unicode characters.
%% Atoms are also limited to 255 characters. Errors with system_limit_atom if
%% the passed string is longer.
%% @end
%%-----------------------------------------------------------------------------
-spec list_to_atom(String :: string()) -> atom().
list_to_atom(_String) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param String string to convert to an atom
%% @returns an atom from the string
%% @see list_to_atom/1
%% @doc Convert a string into an atom.
%% This function will error with badarg if the atom does not exist
%% @end
%%-----------------------------------------------------------------------------
-spec list_to_existing_atom(String :: string()) -> atom().
list_to_existing_atom(_String) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param IOList iolist to convert to binary
%% @returns a binary composed of bytes and binaries from the list
%% @doc Convert a list into a binary.
%% Errors with `badarg' if the list is not an iolist.
%% @end
%%-----------------------------------------------------------------------------
-spec list_to_binary(IOList :: iolist()) -> binary().
list_to_binary(_IOList) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param String string to convert to integer
%% @returns an integer value from its string representation
%% @doc Convert a string (list of characters) to integer.
%% Errors with `badarg' if the string is not a representation of an integer.
%% @end
%%-----------------------------------------------------------------------------
-spec list_to_integer(String :: string()) -> integer().
list_to_integer(_String) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param String string to convert to integer
%% @param Base string to convert to integer
%% @returns an integer value from its string representation
%% @doc Convert a string (list of characters) to integer in specified base.
%% Errors with `badarg' if the string is not a representation of an integer or
%% the base is out of bounds.
%% @end
%%-----------------------------------------------------------------------------
-spec list_to_integer(String :: string(), Base :: 2..36) -> integer().
list_to_integer(_String, _Base) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param List list to convert to tuple
%% @returns a tuple with elements of the list
%% @doc Convert a list to a tuple with the same size.
%% @end
%%-----------------------------------------------------------------------------
-spec list_to_tuple(List :: [any()]) -> tuple().
list_to_tuple(_List) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @equiv byte_size(iolist_to_binary(IOList))
%% @param IOList IO list to compute the binary size of
%% @returns the number of bytes of IOList if it was convered to `binary()'
%% @doc Compute the length in bytes of the IO list or `binary()'
%% @end
%%-----------------------------------------------------------------------------
-spec iolist_size(IOList :: iodata()) -> non_neg_integer().
iolist_size(_IOList) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param IOList IO list to convert to binary
%% @returns a binary with the bytes of the IO list
%% @doc Convert an IO list to binary.
%% @end
%%-----------------------------------------------------------------------------
-spec iolist_to_binary(IOList :: iodata()) -> binary().
iolist_to_binary(_IOList) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Binary Binary to convert to atom
%% @returns an atom from passed binary
%% @doc Convert a binary to atom, defaults to utf8.
%% @end
%%-----------------------------------------------------------------------------
-spec binary_to_atom(Binary :: binary()) -> atom().
binary_to_atom(_Binary) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Binary Binary to convert to atom
%% @param Encoding encoding for conversion (any of latin1, utf8 or unicode)
%% @returns an atom from passed binary
%% @doc Convert a binary to atom.
%% @end
%%-----------------------------------------------------------------------------
-spec binary_to_atom(Binary :: binary(), Encoding :: atom_encoding()) -> atom().
binary_to_atom(_Binary, _Encoding) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Binary Binary to parse for integer
%% @returns the integer represented by the binary
%% @doc Parse the text in a given binary as an integer.
%% @end
%%-----------------------------------------------------------------------------
-spec binary_to_integer(Binary :: binary()) -> integer().
binary_to_integer(_Binary) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Binary Binary to parse for integer
%% @returns the integer represented by the binary
%% @doc Parse the text in a given binary as an integer.
%% @end
%%-----------------------------------------------------------------------------
-spec binary_to_integer(Binary :: binary(), Base :: 2..36) -> integer().
binary_to_integer(_Binary, _Base) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Binary Binary to convert to list
%% @returns a list of bytes from the binary
%% @doc Convert a binary to a list of bytes.
%% @end
%%-----------------------------------------------------------------------------
-spec binary_to_list(Binary :: binary()) -> [byte()].
binary_to_list(_Binary) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Atom Atom to convert
%% @returns a binary with the atom's name
%% @doc Convert an atom to a binary, defaults to utf8.
%% Only latin1 encoding is supported.
%% @end
%%-----------------------------------------------------------------------------
-spec atom_to_binary(Atom :: atom()) -> binary().
atom_to_binary(_Atom) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Atom Atom to convert
%% @param Encoding Encoding for conversion (any of latin1, utf8 or unicode)
%% @returns a binary with the atom's name
%% @doc Convert an atom to a binary.
%% Only latin1 encoding is supported.
%% @end
%%-----------------------------------------------------------------------------
-spec atom_to_binary(Atom :: atom(), Encoding :: atom_encoding()) -> binary().
atom_to_binary(_Atom, _Encoding) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Atom Atom to convert
%% @returns a string with the atom's name
%% @doc Convert an atom to a string.
%% @end
%%-----------------------------------------------------------------------------
-spec atom_to_list(Atom :: atom()) -> string().
atom_to_list(_Atom) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Float Float to convert
%% @returns a binary with a text representation of the float
%% @doc Convert a float to a binary.
%% @end
%%-----------------------------------------------------------------------------
-spec float_to_binary(Float :: float()) -> binary().
float_to_binary(_Float) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Float Float to convert
%% @param Options Options for conversion
%% @returns a binary with a text representation of the float
%% @doc Convert a float to a binary.
%% @end
%%-----------------------------------------------------------------------------
-spec float_to_binary(Float :: float(), Options :: [float_format_option()]) -> binary().
float_to_binary(_Float, _Options) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Float Float to convert
%% @returns a string with a text representation of the float
%% @doc Convert a float to a string.
%% @end
%%-----------------------------------------------------------------------------
-spec float_to_list(Float :: float()) -> string().
float_to_list(_Float) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Float Float to convert
%% @param Options Options for conversion
%% @returns a string with a text representation of the float
%% @doc Convert a float to a string.
%% @end
%%-----------------------------------------------------------------------------
-spec float_to_list(Float :: float(), Options :: [float_format_option()]) -> string().
float_to_list(_Float, _Options) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Fun Function to get information about
%% @returns Requested information about the function as a list of tuples.
%% @doc Returns information about the function `Fun' in unspecified order.
%% @end
%%-----------------------------------------------------------------------------
fun_info(Fun) ->
Items = [module, name, arity, type, env],
lists:map(
fun(Item) ->
erlang:fun_info(Fun, Item)
end,
Items
).
%%-----------------------------------------------------------------------------
%% @param Fun Function to get information about
%% @param Info A list of atoms specifying the information to return.
%% Available atoms are: module, name, arity, type
%% @returns Requested information about the function as a list of tuples.
%% @doc Returns information about the function `Fun' in unspecified order.
%% @end
%%-----------------------------------------------------------------------------
fun_info(_Fun, _Info) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Integer integer to convert to a binary
%% @returns a binary with a text representation of the integer
%% @doc Convert an integer to a binary.
%% @end
%%-----------------------------------------------------------------------------
-spec integer_to_binary(Integer :: integer()) -> binary().
integer_to_binary(_Integer) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Integer integer to convert to a binary
%% @param Base base for representation
%% @returns a binary with a text representation of the integer
%% @doc Convert an integer to a binary.
%% @end
%%-----------------------------------------------------------------------------
-spec integer_to_binary(Integer :: integer(), Base :: 2..36) -> binary().
integer_to_binary(_Integer, _Base) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Integer integer to convert to a string
%% @returns a string representation of the integer
%% @doc Convert an integer to a string.
%% @end
%%-----------------------------------------------------------------------------
-spec integer_to_list(Integer :: integer()) -> string().
integer_to_list(_Integer) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Integer integer to convert to a string
%% @param Base base for representation
%% @returns a string representation of the integer
%% @doc Convert an integer to a string.
%% @end
%%-----------------------------------------------------------------------------
-spec integer_to_list(Integer :: integer(), Base :: 2..36) -> string().
integer_to_list(_Integer, _Base) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Fun function to convert to a string
%% @returns a string representation of the function
%% @doc Create a string representing a function.
%% @end
%%-----------------------------------------------------------------------------
-spec fun_to_list(Fun :: function()) -> string().
fun_to_list(_Fun) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Pid pid to convert to a string
%% @returns a string representation of the pid
%% @doc Create a string representing a pid.
%% @end
%%-----------------------------------------------------------------------------
-spec pid_to_list(Pid :: pid()) -> string().
pid_to_list(_Pid) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Port port to convert to a string
%% @returns a string representation of the port
%% @doc Create a string representing a port.
%% @end
%%-----------------------------------------------------------------------------
-spec port_to_list(Port :: port()) -> string().
port_to_list(_Port) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Ref reference to convert to a string
%% @returns a string representation of the reference
%% @doc Create a string representing a reference.
%% @end
%%-----------------------------------------------------------------------------
-spec ref_to_list(Ref :: reference()) -> string().
ref_to_list(_Ref) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Name name of the process to register
%% @param PidOrPort pid or port of the process to register
%% @returns `true'
%% @doc Register a name for a given process.
%% Errors with `badarg' if the name is already registered or if the process
%% is already registered.
%% @end
%%-----------------------------------------------------------------------------
-spec register(Name :: atom(), PidOrPort :: pid() | port()) -> true.
register(_Name, _PidOrPort) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Name name to unregister
%% @returns `true'
%% @doc Lookup a process by name.
%% Unlike Erlang/OTP, ports are not distinguished from processes.
%% Errors with `badarg' if the name is not registered.
%% @end
%%-----------------------------------------------------------------------------
-spec unregister(Name :: atom()) -> true.
unregister(_Name) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Name name of the process to locate
%% @returns `undefined' or the pid of the registered process
%% @doc Lookup a process by name.
%% @end
%%-----------------------------------------------------------------------------
-spec whereis(Name :: atom()) -> pid() | port() | undefined.
whereis(_Name) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Function function to create a process from
%% @returns pid of the new process
%% @doc Create a new process
%% @end
%%-----------------------------------------------------------------------------
-spec spawn(Function :: function()) -> pid().