Skip to content

Commit

Permalink
Merge pull request #253 from EpitechPromo2027/jabolol/macro-docs
Browse files Browse the repository at this point in the history
fix: improve `macros` docs with example
  • Loading branch information
Jabolol authored Jan 19, 2025
2 parents 30de054 + 141fe49 commit c97087e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/developer-manual/advanced/cross-platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ While Frost aims for platform independence, be aware of:
Use Frost's conditional compilation features to handle platform-specific code:

```frost
?defined(OS_LINUX)
?defined(__APPLE__)
% Linux-specific code
?else
% Code for other platforms
Expand Down
20 changes: 14 additions & 6 deletions docs/user-manual/basic-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ For instance, you can define a macro for a specific platform in a module:

```frost
sockaddr_in :: struct {
?defined(OS_LINUX)
?defined(__APPLE__)
sin_len -> byte
sin_family -> byte
?else
Expand All @@ -371,18 +371,26 @@ sockaddr_in :: struct {
}
```

And then define the platform in the main file, and import the code resulting in
the correct struct definition:
Frost supports macros that are available in the current user's environment. This
means that you can define a macro in the command line and use it in your code.

For example, to enable the `__APPLE__` macro, you can compile the code with:

```bash
__APPLE__=1 frostc -i source.ff -o output.ll
```

This will enable the `__APPLE__` macro in the code, and the compiler will
evaluate the conditionals accordingly, using the correct struct definition.

```frost
?set(OS_LINUX)
import "custom/socket.ff"
main: never -> int = {
sockaddr: sockaddr_in
sockaddr.len = 16
sockaddr.sin_family = 2
sockaddr.len = @byte(16)
sockaddr.sin_family = @byte(2)
% ...
}
```
Expand Down

0 comments on commit c97087e

Please sign in to comment.