From 141fe4935720ea0ab2aac1acc4fe117c6ef27fb4 Mon Sep 17 00:00:00 2001 From: Javier R Date: Sun, 19 Jan 2025 21:49:02 +0100 Subject: [PATCH] fix: improve `macros` docs with example --- .../advanced/cross-platform.md | 2 +- docs/user-manual/basic-concepts.md | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/developer-manual/advanced/cross-platform.md b/docs/developer-manual/advanced/cross-platform.md index 4c91024..81f5e64 100644 --- a/docs/developer-manual/advanced/cross-platform.md +++ b/docs/developer-manual/advanced/cross-platform.md @@ -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 diff --git a/docs/user-manual/basic-concepts.md b/docs/user-manual/basic-concepts.md index cbd6e40..cca2605 100644 --- a/docs/user-manual/basic-concepts.md +++ b/docs/user-manual/basic-concepts.md @@ -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 @@ -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) % ... } ```