Skip to content

Commit 003afe8

Browse files
committed
Merge pull request #1945 from bettio/stubbed-functions-doc
doc: add page for stubbed functions These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 0f80cf6 + 0e5c4b0 commit 003afe8

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

doc/src/differences-with-beam.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ changes.
8181
Please check AtomVM's [standard library documentation](./apidocs/erlang/estdlib/README.md) to find out differences
8282
and limitations of each module.
8383

84+
See also [stubbed functions](./stubbed-functions.md) list.
85+
8486
### OTP architecture
8587

8688
Support for OTP applications is currently very limited. `gen_server`, `gen_statem` and `supervisor`

doc/src/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ AtomVM includes many advanced features, including process spawning, monitoring,
3030
network-programming-guide
3131
distributed-erlang
3232
differences-with-beam
33+
stubbed-functions
3334
build-instructions
3435
atomvm-internals
3536
memory-management

doc/src/stubbed-functions.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)