diff --git a/src/libAtomVM/CMakeLists.txt b/src/libAtomVM/CMakeLists.txt index 23739c4663..5bc938e75d 100644 --- a/src/libAtomVM/CMakeLists.txt +++ b/src/libAtomVM/CMakeLists.txt @@ -31,6 +31,7 @@ set(HEADER_FILES context.h debug.h defaultatoms.h + defaultatoms.def dictionary.h erl_nif.h erl_nif_priv.h diff --git a/src/libAtomVM/defaultatoms.c b/src/libAtomVM/defaultatoms.c index c6a66d166d..d0ea624d97 100644 --- a/src/libAtomVM/defaultatoms.c +++ b/src/libAtomVM/defaultatoms.c @@ -21,307 +21,25 @@ #include "defaultatoms.h" #include -static const char *const false_atom = "\x05" "false"; -static const char *const true_atom = "\x04" "true"; +// About X macro: https://en.wikipedia.org/wiki/X_macro -static const char *const ok_atom = "\x2" "ok"; -static const char *const error_atom = "\x5" "error"; +#define X(name, lenstr, str) \ + static const char *const name ## _str = lenstr str; -static const char *const undefined_atom = "\x9" "undefined"; +#include "defaultatoms.def" -static const char *const badarg_atom = "\x6" "badarg"; -static const char *const badarith_atom = "\x08" "badarith"; -static const char *const badarity_atom = "\x08" "badarity"; -static const char *const badfun_atom = "\x06" "badfun"; -static const char *const system_limit_atom = "\xC" "system_limit"; -static const char *const function_clause_atom = "\x0F" "function_clause"; -static const char *const try_clause_atom = "\xA" "try_clause"; -static const char *const out_of_memory_atom = "\xD" "out_of_memory"; -static const char *const overflow_atom = "\x8" "overflow"; - -static const char *const flush_atom = "\x5" "flush"; -static const char *const heap_size_atom = "\x9" "heap_size"; -static const char *const latin1_atom = "\x6" "latin1"; -static const char *const max_heap_size_atom ="\xD" "max_heap_size"; -static const char *const memory_atom = "\x6" "memory"; -static const char *const message_queue_len_atom = "\x11" "message_queue_len"; -static const char *const puts_atom = "\x4" "puts"; -static const char *const stack_size_atom = "\xA" "stack_size"; -static const char *const min_heap_size_atom ="\xD" "min_heap_size"; -static const char *const process_count_atom = "\xD" "process_count"; -static const char *const port_count_atom = "\xA" "port_count"; -static const char *const atom_count_atom = "\xA" "atom_count"; -static const char *const system_architecture_atom = "\x13" "system_architecture"; -static const char *const wordsize_atom = "\x8" "wordsize"; - -static const char *const decimals_atom = "\x8" "decimals"; -static const char *const scientific_atom = "\xA" "scientific"; -static const char *const compact_atom = "\x7" "compact"; - -static const char *const badmatch_atom = "\x8" "badmatch"; -static const char *const case_clause_atom = "\xB" "case_clause"; -static const char *const if_clause_atom = "\x9" "if_clause"; -static const char *const throw_atom = "\x5" "throw"; -static const char *const low_entropy_atom = "\xB" "low_entropy"; -static const char *const unsupported_atom = "\xB" "unsupported"; -static const char *const used_atom = "\x4" "used"; -static const char *const all_atom = "\x3" "all"; -static const char *const start_atom = "\x5" "start"; - -static const char *const undef_atom = "\x5" "undef"; -static const char *const vm_abort_atom = "\x8" "vm_abort"; - -static const char *const link_atom = "\x4" "link"; -static const char *const monitor_atom = "\x7" "monitor"; -static const char *const normal_atom = "\x6" "normal"; -static const char *const down_atom = "\x4" "DOWN"; -static const char *const process_atom = "\x7" "process"; -static const char *const nocatch_atom = "\x7" "nocatch"; -static const char *const refc_binary_info_atom = "\x10" "refc_binary_info"; -static const char *const noproc_atom = "\x6" "noproc"; -static const char *const trap_exit_atom = "\x9" "trap_exit"; -static const char *const exit_atom = "\x4" "EXIT"; - -static const char *const badmap_atom = "\x6" "badmap"; -static const char *const badkey_atom = "\x6" "badkey"; -static const char *const none_atom = "\x4" "none"; - -static const char *const io_request_atom = "\xA" "io_request"; -static const char *const io_reply_atom = "\x8" "io_reply"; -static const char *const put_chars_atom = "\x9" "put_chars"; - -static const char *const lowercase_exit_atom = "\x4" "exit"; -static const char *const atomvm_version_atom = "\xE" "atomvm_version"; - -static const char *const second_atom = "\x6" "second"; -static const char *const millisecond_atom = "\xB" "millisecond"; -static const char *const microsecond_atom = "\xB" "microsecond"; - -static const char *const infinity_atom = "\x8" "infinity"; -static const char *const timeout_value_atom = "\xD" "timeout_value"; - -static const char *const schedulers_atom = "\xA" "schedulers"; -static const char *const schedulers_online_atom = "\x11" "schedulers_online"; - -static const char *const append_atom = "\x6" "append"; -static const char *const private_append_atom = "\xE" "private_append"; -static const char *const binary_atom = "\x6" "binary"; -static const char *const integer_atom = "\x7" "integer"; -static const char *const little_atom = "\x6" "little"; -static const char *const native_atom = "\x6" "native"; -static const char *const string_atom = "\x6" "string"; -static const char *const utf8_atom = "\x4" "utf8"; -static const char *const utf16_atom = "\x5" "utf16"; -static const char *const utf32_atom = "\x5" "utf32"; -static const char *const badrecord_atom = "\x9" "badrecord"; - -static const char *const copy_atom = "\x4" "copy"; -static const char *const reuse_atom = "\x5" "reuse"; -static const char *const ensure_at_least_atom = "\xF" "ensure_at_least"; -static const char *const ensure_exactly_atom = "\xE" "ensure_exactly"; -static const char *const skip_atom = "\x4" "skip"; -static const char *const get_tail_atom = "\x8" "get_tail"; -static const char *const equal_colon_equal_atom = "\x3" "=:="; -static const char *const signed_atom = "\x6" "signed"; - -static const char *const machine_atom = "\x7" "machine"; -static const char *const avm_floatsize_atom = "\xD" "avm_floatsize"; - -static const char *const close_atom = "\x5" "close"; -static const char *const closed_atom = "\x6" "closed"; -static const char *const port_atom = "\x4" "port"; - -static const char *const info_atom = "\x4" "info"; - -static const char *const module_atom = "\x06" "module"; - -static const char *const select_atom = "\x6" "select"; -static const char *const ready_input_atom = "\xB" "ready_input"; -static const char *const ready_output_atom = "\xC" "ready_output"; - -static const char *const attributes_atom = "\xA" "attributes"; -static const char *const compile_atom = "\x7" "compile"; -static const char *const exports_atom = "\x7" "exports"; - -static const char *const incomplete_atom = "\xA" "incomplete"; - -static const char *const kill_atom = "\x4" "kill"; -static const char *const killed_atom = "\x6" "killed"; -static const char *const links_atom = "\x5" "links"; - -static const char *const total_heap_size_atom = "\xF" "total_heap_size"; -static const char *const atomvm_heap_growth_atom = "\x12" "atomvm_heap_growth"; -static const char *const bounded_free_atom = "\xC" "bounded_free"; -static const char *const minimum_atom = "\x7" "minimum"; -static const char *const fibonacci_atom = "\x9" "fibonacci"; - -static const char *const call_atom = "\x5" "$call"; -static const char *const cast_atom = "\x5" "$cast"; - -static const char *const unicode_atom = "\x7" "unicode"; - -static const char *const global_atom = "\x6" "global"; -static const char *const type_atom = "\x4" "type"; -static const char *const name_atom = "\x4" "name"; -static const char *const arity_atom = "\x5" "arity"; -static const char *const external_atom = "\x8" "external"; -static const char *const local_atom = "\x5" "local"; - -static const char *const registered_name_atom = "\xF" "registered_name"; +#undef X void defaultatoms_init(GlobalContext *glb) { int ok = 1; - ok &= globalcontext_insert_atom(glb, false_atom) == FALSE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, true_atom) == TRUE_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, ok_atom) == OK_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, error_atom) == ERROR_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, undefined_atom) == UNDEFINED_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, badarg_atom) == BADARG_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, badarith_atom) == BADARITH_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, badarity_atom) == BADARITY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, badfun_atom) == BADFUN_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, function_clause_atom) == FUNCTION_CLAUSE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, try_clause_atom) == TRY_CLAUSE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, out_of_memory_atom) == OUT_OF_MEMORY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, overflow_atom) == OVERFLOW_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, system_limit_atom) == SYSTEM_LIMIT_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, flush_atom) == FLUSH_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, heap_size_atom) == HEAP_SIZE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, latin1_atom) == LATIN1_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, max_heap_size_atom) == MAX_HEAP_SIZE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, memory_atom) == MEMORY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, message_queue_len_atom) == MESSAGE_QUEUE_LEN_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, puts_atom) == PUTS_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, stack_size_atom) == STACK_SIZE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, min_heap_size_atom) == MIN_HEAP_SIZE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, process_count_atom) == PROCESS_COUNT_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, port_count_atom) == PORT_COUNT_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, atom_count_atom) == ATOM_COUNT_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, system_architecture_atom) == SYSTEM_ARCHITECTURE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, wordsize_atom) == WORDSIZE_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, decimals_atom) == DECIMALS_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, scientific_atom) == SCIENTIFIC_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, compact_atom) == COMPACT_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, badmatch_atom) == BADMATCH_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, case_clause_atom) == CASE_CLAUSE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, if_clause_atom) == IF_CLAUSE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, throw_atom) == THROW_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, low_entropy_atom) == LOW_ENTROPY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, unsupported_atom) == UNSUPPORTED_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, used_atom) == USED_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, all_atom) == ALL_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, start_atom) == START_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, undef_atom) == UNDEF_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, vm_abort_atom) == VM_ABORT_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, link_atom) == LINK_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, monitor_atom) == MONITOR_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, normal_atom) == NORMAL_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, down_atom) == DOWN_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, process_atom) == PROCESS_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, nocatch_atom) == NOCATCH_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, refc_binary_info_atom) == REFC_BINARY_INFO_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, noproc_atom) == NOPROC_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, trap_exit_atom) == TRAP_EXIT_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, exit_atom) == EXIT_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, badmap_atom) == BADMAP_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, badkey_atom) == BADKEY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, none_atom) == NONE_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, io_request_atom) == IO_REQUEST_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, io_reply_atom) == IO_REPLY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, put_chars_atom) == PUT_CHARS_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, lowercase_exit_atom) == LOWERCASE_EXIT_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, atomvm_version_atom) == ATOMVM_VERSION_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, second_atom) == SECOND_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, millisecond_atom) == MILLISECOND_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, microsecond_atom) == MICROSECOND_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, infinity_atom) == INFINITY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, timeout_value_atom) == TIMEOUT_VALUE_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, schedulers_atom) == SCHEDULERS_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, schedulers_online_atom) == SCHEDULERS_ONLINE_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, append_atom) == APPEND_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, private_append_atom) == PRIVATE_APPEND_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, binary_atom) == BINARY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, integer_atom) == INTEGER_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, little_atom) == LITTLE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, native_atom) == NATIVE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, string_atom) == STRING_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, utf8_atom) == UTF8_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, utf16_atom) == UTF16_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, utf32_atom) == UTF32_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, badrecord_atom) == BADRECORD_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, copy_atom) == COPY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, reuse_atom) == REUSE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, ensure_at_least_atom) == ENSURE_AT_LEAST_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, ensure_exactly_atom) == ENSURE_EXACTLY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, skip_atom) == SKIP_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, get_tail_atom) == GET_TAIL_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, equal_colon_equal_atom) == EQUAL_COLON_EQUAL_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, signed_atom) == SIGNED_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, machine_atom) == MACHINE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, avm_floatsize_atom) == AVM_FLOATSIZE_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, close_atom) == CLOSE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, closed_atom) == CLOSED_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, port_atom) == PORT_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, info_atom) == INFO_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, module_atom) == MODULE_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, select_atom) == SELECT_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, ready_input_atom) == READY_INPUT_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, ready_output_atom) == READY_OUTPUT_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, attributes_atom) == ATTRIBUTES_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, compile_atom) == COMPILE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, exports_atom) == EXPORTS_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, incomplete_atom) == INCOMPLETE_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, kill_atom) == KILL_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, killed_atom) == KILLED_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, links_atom) == LINKS_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, total_heap_size_atom) == TOTAL_HEAP_SIZE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, atomvm_heap_growth_atom) == ATOMVM_HEAP_GROWTH_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, bounded_free_atom) == BOUNDED_FREE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, minimum_atom) == MINIMUM_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, fibonacci_atom) == FIBONACCI_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, call_atom) == CALL_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, cast_atom) == CAST_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, unicode_atom) == UNICODE_ATOM_INDEX; - - ok &= globalcontext_insert_atom(glb, global_atom) == GLOBAL_ATOM_INDEX; + #define X(name, lenstr, str) \ + ok &= globalcontext_insert_atom(glb, name ## _str) == name ## _INDEX; - ok &= globalcontext_insert_atom(glb, type_atom) == TYPE_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, name_atom) == NAME_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, arity_atom) == ARITY_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, external_atom) == EXTERNAL_ATOM_INDEX; - ok &= globalcontext_insert_atom(glb, local_atom) == LOCAL_ATOM_INDEX; + #include "defaultatoms.def" - ok &= globalcontext_insert_atom(glb, registered_name_atom) == REGISTERED_NAME_ATOM_INDEX; + #undef X if (!ok) { AVM_ABORT(); diff --git a/src/libAtomVM/defaultatoms.def b/src/libAtomVM/defaultatoms.def new file mode 100644 index 0000000000..782995c884 --- /dev/null +++ b/src/libAtomVM/defaultatoms.def @@ -0,0 +1,167 @@ +/* + * This file is part of AtomVM. + * + * Copyright 2019-2024 Davide Bettio + * + * 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 + */ + +X(FALSE_ATOM, "\x05", "false") +X(TRUE_ATOM, "\x04", "true") + +X(OK_ATOM, "\x2", "ok") +X(ERROR_ATOM, "\x5", "error") + +X(UNDEFINED_ATOM, "\x9", "undefined") + +X(BADARG_ATOM, "\x6", "badarg") +X(BADARITH_ATOM, "\x08", "badarith") +X(BADARITY_ATOM, "\x08", "badarity") +X(BADFUN_ATOM, "\x06", "badfun") +X(SYSTEM_LIMIT_ATOM, "\xC", "system_limit") +X(FUNCTION_CLAUSE_ATOM, "\xF", "function_clause") +X(TRY_CLAUSE_ATOM, "\xA", "try_clause") +X(OUT_OF_MEMORY_ATOM, "\xD", "out_of_memory") +X(OVERFLOW_ATOM, "\x8", "overflow") + +X(FLUSH_ATOM, "\x5", "flush") +X(HEAP_SIZE_ATOM, "\x9", "heap_size") +X(LATIN1_ATOM, "\x6", "latin1") +X(MAX_HEAP_SIZE_ATOM, "\xD", "max_heap_size") +X(MEMORY_ATOM, "\x6", "memory") +X(MESSAGE_QUEUE_LEN_ATOM, "\x11", "message_queue_len") +X(PUTS_ATOM, "\x4", "puts") +X(STACK_SIZE_ATOM, "\xA", "stack_size") +X(MIN_HEAP_SIZE_ATOM, "\xD", "min_heap_size") +X(PROCESS_COUNT_ATOM, "\xD", "process_count") +X(PORT_COUNT_ATOM, "\xA", "port_count") +X(ATOM_COUNT_ATOM, "\xA", "atom_count") +X(SYSTEM_ARCHITECTURE_ATOM, "\x13", "system_architecture") +X(WORDSIZE_ATOM, "\x8", "wordsize") + +X(DECIMALS_ATOM, "\x8", "decimals") +X(SCIENTIFIC_ATOM, "\xA", "scientific") +X(COMPACT_ATOM, "\x7", "compact") + +X(BADMATCH_ATOM, "\x8", "badmatch") +X(CASE_CLAUSE_ATOM, "\xB", "case_clause") +X(IF_CLAUSE_ATOM, "\x9", "if_clause") +X(THROW_ATOM, "\x5", "throw") +X(LOW_ENTROPY_ATOM, "\xB", "low_entropy") +X(UNSUPPORTED_ATOM, "\xB", "unsupported") +X(USED_ATOM, "\x4", "used") +X(ALL_ATOM, "\x3", "all") +X(START_ATOM, "\x5", "start") + +X(UNDEF_ATOM, "\x5", "undef") +X(VM_ABORT_ATOM, "\x8", "vm_abort") + +X(LINK_ATOM, "\x4", "link") +X(MONITOR_ATOM, "\x7", "monitor") +X(NORMAL_ATOM, "\x6", "normal") +X(DOWN_ATOM, "\x4", "DOWN") +X(PROCESS_ATOM, "\x7", "process") +X(NOCATCH_ATOM, "\x7", "nocatch") +X(REFC_BINARY_INFO_ATOM, "\x10", "refc_binary_info") +X(NOPROC_ATOM, "\x6", "noproc") +X(TRAP_EXIT_ATOM, "\x9", "trap_exit") +X(EXIT_ATOM, "\x4", "EXIT") + +X(BADMAP_ATOM, "\x6", "badmap") +X(BADKEY_ATOM, "\x6", "badkey") +X(NONE_ATOM, "\x4", "none") + +X(IO_REQUEST_ATOM, "\xA", "io_request") +X(IO_REPLY_ATOM, "\x8", "io_reply") +X(PUT_CHARS_ATOM, "\x9", "put_chars") + +X(LOWERCASE_EXIT_ATOM, "\x4", "exit") +X(ATOMVM_VERSION_ATOM, "\xE", "atomvm_version") + +X(SECOND_ATOM, "\x6", "second") +X(MILLISECOND_ATOM, "\xB", "millisecond") +X(MICROSECOND_ATOM, "\xB", "microsecond") + +X(INFINITY_ATOM, "\x8", "infinity") +X(TIMEOUT_VALUE_ATOM, "\xD", "timeout_value") + +X(SCHEDULERS_ATOM, "\xA", "schedulers") +X(SCHEDULERS_ONLINE_ATOM, "\x11", "schedulers_online") + +X(APPEND_ATOM, "\x6", "append") +X(PRIVATE_APPEND_ATOM, "\xE", "private_append") +X(BINARY_ATOM, "\x6", "binary") +X(INTEGER_ATOM, "\x7", "integer") +X(LITTLE_ATOM, "\x6", "little") +X(NATIVE_ATOM, "\x6", "native") +X(STRING_ATOM, "\x6", "string") +X(UTF8_ATOM, "\x4", "utf8") +X(UTF16_ATOM, "\x5", "utf16") +X(UTF32_ATOM, "\x5", "utf32") +X(BADRECORD_ATOM, "\x9", "badrecord") + +X(COPY_ATOM, "\x4", "copy") +X(REUSE_ATOM, "\x5", "reuse") +X(ENSURE_AT_LEAST_ATOM, "\xF", "ensure_at_least") +X(ENSURE_EXACTLY_ATOM, "\xE", "ensure_exactly") +X(SKIP_ATOM, "\x4", "skip") +X(GET_TAIL_ATOM, "\x8", "get_tail") +X(EQUAL_COLON_EQUAL_ATOM, "\x3", "=:=") +X(SIGNED_ATOM, "\x6", "signed") + +X(MACHINE_ATOM, "\x7", "machine") +X(AVM_FLOATSIZE_ATOM, "\xD", "avm_floatsize") + +X(CLOSE_ATOM, "\x5", "close") +X(CLOSED_ATOM, "\x6", "closed") +X(PORT_ATOM, "\x4", "port") + +X(INFO_ATOM, "\x4", "info") + +X(MODULE_ATOM, "\x6", "module") + +X(SELECT_ATOM, "\x6", "select") +X(READY_INPUT_ATOM, "\xB", "ready_input") +X(READY_OUTPUT_ATOM, "\xC", "ready_output") + +X(ATTRIBUTES_ATOM, "\xA", "attributes") +X(COMPILE_ATOM, "\x7", "compile") +X(EXPORTS_ATOM, "\x7", "exports") + +X(INCOMPLETE_ATOM, "\xA", "incomplete") + +X(KILL_ATOM, "\x4", "kill") +X(KILLED_ATOM, "\x6", "killed") +X(LINKS_ATOM, "\x5", "links") + +X(TOTAL_HEAP_SIZE_ATOM, "\xF", "total_heap_size") +X(ATOMVM_HEAP_GROWTH_ATOM, "\x12", "atomvm_heap_growth") +X(BOUNDED_FREE_ATOM, "\xC", "bounded_free") +X(MINIMUM_ATOM, "\x7", "minimum") +X(FIBONACCI_ATOM, "\x9", "fibonacci") + +X(CALL_ATOM, "\x5", "$call") +X(CAST_ATOM, "\x5", "$cast") + +X(UNICODE_ATOM, "\x7", "unicode") + +X(GLOBAL_ATOM, "\x6", "global") +X(TYPE_ATOM, "\x4", "type") +X(NAME_ATOM, "\x4", "name") +X(ARITY_ATOM, "\x5", "arity") +X(EXTERNAL_ATOM, "\x8", "external") +X(LOCAL_ATOM, "\x5", "local") + +X(REGISTERED_NAME_ATOM, "\xF", "registered_name") diff --git a/src/libAtomVM/defaultatoms.h b/src/libAtomVM/defaultatoms.h index 06bac94590..2624439882 100644 --- a/src/libAtomVM/defaultatoms.h +++ b/src/libAtomVM/defaultatoms.h @@ -27,160 +27,19 @@ extern "C" { #endif -#define FALSE_ATOM_INDEX 0 -#define TRUE_ATOM_INDEX 1 - -#define OK_ATOM_INDEX 2 -#define ERROR_ATOM_INDEX 3 - -#define UNDEFINED_ATOM_INDEX 4 - -#define BADARG_ATOM_INDEX 5 -#define BADARITH_ATOM_INDEX 6 -#define BADARITY_ATOM_INDEX 7 -#define BADFUN_ATOM_INDEX 8 -#define FUNCTION_CLAUSE_ATOM_INDEX 9 -#define TRY_CLAUSE_ATOM_INDEX 10 -#define OUT_OF_MEMORY_ATOM_INDEX 11 -#define OVERFLOW_ATOM_INDEX 12 -#define SYSTEM_LIMIT_ATOM_INDEX 13 - -#define FLUSH_ATOM_INDEX 14 -#define HEAP_SIZE_ATOM_INDEX 15 -#define LATIN1_ATOM_INDEX 16 -#define MAX_HEAP_SIZE_ATOM_INDEX 17 -#define MEMORY_ATOM_INDEX 18 -#define MESSAGE_QUEUE_LEN_ATOM_INDEX 19 -#define PUTS_ATOM_INDEX 20 -#define STACK_SIZE_ATOM_INDEX 21 -#define MIN_HEAP_SIZE_ATOM_INDEX 22 - -#define PROCESS_COUNT_ATOM_INDEX 23 -#define PORT_COUNT_ATOM_INDEX 24 -#define ATOM_COUNT_ATOM_INDEX 25 -#define SYSTEM_ARCHITECTURE_ATOM_INDEX 26 -#define WORDSIZE_ATOM_INDEX 27 - -#define DECIMALS_ATOM_INDEX 28 -#define SCIENTIFIC_ATOM_INDEX 29 -#define COMPACT_ATOM_INDEX 30 - -#define BADMATCH_ATOM_INDEX 31 -#define CASE_CLAUSE_ATOM_INDEX 32 -#define IF_CLAUSE_ATOM_INDEX 33 -#define THROW_ATOM_INDEX 34 -#define LOW_ENTROPY_ATOM_INDEX 35 -#define UNSUPPORTED_ATOM_INDEX 36 -#define USED_ATOM_INDEX 37 -#define ALL_ATOM_INDEX 38 -#define START_ATOM_INDEX 39 - -#define UNDEF_ATOM_INDEX 40 -#define VM_ABORT_ATOM_INDEX 41 - -#define LINK_ATOM_INDEX 42 -#define MONITOR_ATOM_INDEX 43 -#define NORMAL_ATOM_INDEX 44 -#define DOWN_ATOM_INDEX 45 -#define PROCESS_ATOM_INDEX 46 -#define NOCATCH_ATOM_INDEX 47 - -#define REFC_BINARY_INFO_ATOM_INDEX 48 - -#define NOPROC_ATOM_INDEX 49 -#define TRAP_EXIT_ATOM_INDEX 50 -#define EXIT_ATOM_INDEX 51 - -#define BADMAP_ATOM_INDEX 52 -#define BADKEY_ATOM_INDEX 53 -#define NONE_ATOM_INDEX 54 - -#define IO_REQUEST_ATOM_INDEX 55 -#define IO_REPLY_ATOM_INDEX 56 -#define PUT_CHARS_ATOM_INDEX 57 - -#define LOWERCASE_EXIT_ATOM_INDEX 58 -#define ATOMVM_VERSION_ATOM_INDEX 59 - -#define SECOND_ATOM_INDEX 60 -#define MILLISECOND_ATOM_INDEX 61 -#define MICROSECOND_ATOM_INDEX 62 - -#define INFINITY_ATOM_INDEX 63 -#define TIMEOUT_VALUE_ATOM_INDEX 64 - -#define SCHEDULERS_ATOM_INDEX 65 -#define SCHEDULERS_ONLINE_ATOM_INDEX 66 - -#define APPEND_ATOM_INDEX 67 -#define PRIVATE_APPEND_ATOM_INDEX 68 -#define BINARY_ATOM_INDEX 69 -#define INTEGER_ATOM_INDEX 70 -#define LITTLE_ATOM_INDEX 71 -#define NATIVE_ATOM_INDEX 72 -#define STRING_ATOM_INDEX 73 -#define UTF8_ATOM_INDEX 74 -#define UTF16_ATOM_INDEX 75 -#define UTF32_ATOM_INDEX 76 -#define BADRECORD_ATOM_INDEX 77 - -#define COPY_ATOM_INDEX 78 -#define REUSE_ATOM_INDEX 79 -#define ENSURE_AT_LEAST_ATOM_INDEX 80 -#define ENSURE_EXACTLY_ATOM_INDEX 81 -#define SKIP_ATOM_INDEX 82 -#define GET_TAIL_ATOM_INDEX 83 -#define EQUAL_COLON_EQUAL_ATOM_INDEX 84 -#define SIGNED_ATOM_INDEX 85 - -#define MACHINE_ATOM_INDEX 86 -#define AVM_FLOATSIZE_ATOM_INDEX 87 - -#define CLOSE_ATOM_INDEX 88 -#define CLOSED_ATOM_INDEX 89 -#define PORT_ATOM_INDEX 90 - -#define INFO_ATOM_INDEX 91 - -#define MODULE_ATOM_INDEX 92 - -#define SELECT_ATOM_INDEX 93 -#define READY_INPUT_ATOM_INDEX 94 -#define READY_OUTPUT_ATOM_INDEX 95 - -#define ATTRIBUTES_ATOM_INDEX 96 -#define COMPILE_ATOM_INDEX 97 -#define EXPORTS_ATOM_INDEX 98 - -#define INCOMPLETE_ATOM_INDEX 99 - -#define KILL_ATOM_INDEX 100 -#define KILLED_ATOM_INDEX 101 -#define LINKS_ATOM_INDEX 102 - -#define TOTAL_HEAP_SIZE_ATOM_INDEX 103 -#define ATOMVM_HEAP_GROWTH_ATOM_INDEX 104 -#define BOUNDED_FREE_ATOM_INDEX 105 -#define MINIMUM_ATOM_INDEX 106 -#define FIBONACCI_ATOM_INDEX 107 - -#define CALL_ATOM_INDEX 108 -#define CAST_ATOM_INDEX 109 - -#define UNICODE_ATOM_INDEX 110 - -#define GLOBAL_ATOM_INDEX 111 +// About X macro: https://en.wikipedia.org/wiki/X_macro -#define TYPE_ATOM_INDEX 112 -#define NAME_ATOM_INDEX 113 -#define ARITY_ATOM_INDEX 114 -#define EXTERNAL_ATOM_INDEX 115 -#define LOCAL_ATOM_INDEX 116 +#define X(name, lenstr, str) \ + name ## _INDEX, -#define REGISTERED_NAME_ATOM_INDEX 117 +enum { + #include "defaultatoms.def" -// Defines the first index for platform specific atoms, should always be last in the list -#define PLATFORM_ATOMS_BASE_INDEX 118 + // The first index for platform specific atoms, should always be last in the list + PLATFORM_ATOMS_BASE_INDEX +}; + +#undef X #define FALSE_ATOM TERM_FROM_ATOM_INDEX(FALSE_ATOM_INDEX) #define TRUE_ATOM TERM_FROM_ATOM_INDEX(TRUE_ATOM_INDEX)