|
| 1 | +<!-- |
| 2 | + Copyright 2025 AtomVM Contributors |
| 3 | +
|
| 4 | + SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later |
| 5 | +--> |
| 6 | + |
| 7 | +# Stubbed Functions |
| 8 | + |
| 9 | +AtomVM implements stub functions for certain BEAM operations that are either not applicable to |
| 10 | +embedded environments, not yet implemented, or intentionally left as no-ops for compatibility |
| 11 | +reasons. These functions allow BEAM code that references them to load and execute without errors, |
| 12 | +even though the actual functionality may not be present. |
| 13 | + |
| 14 | +## Purpose of Stubbed Functions |
| 15 | + |
| 16 | +Stubbed functions serve several purposes in AtomVM: |
| 17 | + |
| 18 | +1. **Compatibility**: Allow BEAM modules that use these functions to work anyway |
| 19 | +2. **Environment Differences**: Functions that make no sense in embedded contexts (or in AtomVM) |
| 20 | +but are required for code compatibility |
| 21 | +3. **Performance**: Operations that would be too expensive on microcontrollers and are safely |
| 22 | +ignored |
| 23 | + |
| 24 | +## List of Stubbed Functions |
| 25 | + |
| 26 | +The following functions are currently stubbed in AtomVM and always return a fixed value: |
| 27 | + |
| 28 | +<!-- |
| 29 | +### Foo Bar Functions |
| 30 | +
|
| 31 | +| Module | Function | Return Value | Notes | |
| 32 | +|--------|----------|--------------|-------| |
| 33 | +| `erlang` | `foo/0` | `[]` | Not applicable on AtomVM | |
| 34 | +--> |
| 35 | + |
| 36 | +## Important Considerations |
| 37 | + |
| 38 | +When using AtomVM, be aware that stubbed functions will not provide the functionality you might |
| 39 | +expect from BEAM. Code that relies on these functions for critical behavior will need to be adapted |
| 40 | +for the AtomVM environment. |
| 41 | + |
| 42 | +## Detecting Stubbed Functions |
| 43 | + |
| 44 | +To write portable code that works on both BEAM and AtomVM, you can detect the runtime environment: |
| 45 | + |
| 46 | +```erlang |
| 47 | +case erlang:system_info(machine) of |
| 48 | + "BEAM" -> |
| 49 | + %% Use full functionality |
| 50 | + full_implementation(); |
| 51 | + "ATOM" -> |
| 52 | + %% Use alternative approach or skip |
| 53 | + alternative_implementation() |
| 54 | +end |
| 55 | +``` |
| 56 | + |
| 57 | +## Future Implementations |
| 58 | + |
| 59 | +Some stubbed functions may be implemented in future versions of AtomVM. Use |
| 60 | +[GitHub issues](https://github.com/atomvm/AtomVM/issues) for providing any kind of feedback. |
0 commit comments