Contributing

AtomVM is open to any contribution.

Pull requests, bug reports and feature requests are welcome.

However before contributing, please read carefully our Code of Conduct and the following contribution guidelines.

Please, also make sure to understand the Apache 2.0 license and the Developer Certificate of Origin.

Last but not least, do not use GitHub issues for vulnerability reports, read instead the security policy for instructions.

Coding Style

For all source code modules:

  • Remove all trailing whitespace

  • Newlines (\n) at end of file

  • Use line ending conventions appropriate for the platform (e.g., \n on UNIX-like systems)

C Code

C source code style is enforced with clang-format-13. To automatically fix a file, run:

clang-format-13 --style=file -i file.c

Indentation

Good:

void f(bool reverse)
{
    if (reverse) {
        puts("!dlroW olleH");
    } else {
        puts("Hello world");
    }
}

Bad:

void f(bool reverse) {
    if (reverse)
        puts ("!dlroW olleH");
    else
        puts ("Hello world");
}

Naming Conventions

  • Struct names are PascalCase (e.g. Context)

  • Scalar types are lower case (e.g. term)

  • All other names (e.g. functions and variables) are snake_case (e.g. term_is_integer)

  • Always prefix exported function names with the module in which they are defined (e.g. term_is_nil, term_is_integer, context_new, context_destroy)

Other Coding Conventions

  • Pointers (*) should be with the variable name rather than with the type (e.g. char *name, not char* name)

  • Avoid long lines, use intermediate variables with meaningful names.

  • Function definitions should be separated by 1 empty line

Function declarations should be structured as follows:

func(main_input, additional_inputs, main_output, additional_outputs, opts, [context])

where context is a context structure (such as Context or GlobalContext).

Any functions that are not exported should be qualified with the static keyword.

Functions that return booleans should be named is_something (or possibly module_is_something, if the function is exported).

C header modules (.h) should be organized as follows:

+-------------------
| Copyright Header
|
| #ifdef MODULE__H__
| #define MODULE__H__
|
| #ifdef __cplusplus
| extern "C" {
| #endif
|
| #includes (alphabetical)
|
| #defines
|
| type definitions
|
| function declarations
|
| #ifdef __cplusplus
| }
| #endif
|
| #endif
+-------------------
 module.h

C source modules (.c) should be organized as follows:

+-------------------
| Copyright Header
|
| #includes (alphabetical)
|
| #defines
|
| type definitions
|
| forward declarations (only if necessary)
|
| function definitions
|   dependent static functions first
|   exported functions and entrypoints last
+-------------------
 module.c

Erlang Code

Erlang source code style is enforced using erlfmt.

Elixir Code

Just use Elixir formatter enforced style.