diff options
author | metagn <metagngn@gmail.com> | 2022-12-13 23:20:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-13 21:20:55 +0100 |
commit | 9a50033d5b09ec3263a53bd2bb4182a8a50e6f4d (patch) | |
tree | 20810da72f31c577f858446c669afad45058abaa /doc | |
parent | 2564b5c938602e4f8820d2ed2b778c6d4f1d0cd5 (diff) | |
download | Nim-9a50033d5b09ec3263a53bd2bb4182a8a50e6f4d.tar.gz |
generic `define` pragma + string alias (#20979)
* generic `define` pragma + string alias * clean * add tests and document * remove char/float, minimize changelog
Diffstat (limited to 'doc')
-rw-r--r-- | doc/manual.md | 18 | ||||
-rw-r--r-- | doc/manual_experimental.md | 23 |
2 files changed, 41 insertions, 0 deletions
diff --git a/doc/manual.md b/doc/manual.md index bd2cf8568..0a295fdb5 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -8049,6 +8049,24 @@ used. To see if a value was provided, `defined(FooBar)` can be used. The syntax `-d:flag`:option: is actually just a shortcut for `-d:flag=true`:option:. +These pragmas also accept an optional string argument for qualified +define names. + + ```nim + const FooBar {.intdefine: "package.FooBar".}: int = 5 + echo FooBar + ``` + + ```cmd + nim c -d:package.FooBar=42 foobar.nim + ``` + +This helps disambiguate define names in different packages. + +See also the [generic `define` pragma](manual_experimental.html#generic-define-pragma) +for a version of these pragmas that detects the type of the define based on +the constant value. + User-defined pragmas ==================== diff --git a/doc/manual_experimental.md b/doc/manual_experimental.md index 6f5906019..2a56c1354 100644 --- a/doc/manual_experimental.md +++ b/doc/manual_experimental.md @@ -65,6 +65,29 @@ However, a `void` type cannot be inferred in generic code: The `void` type is only valid for parameters and return types; other symbols cannot have the type `void`. +Generic `define` pragma +======================= + +Aside the [typed define pragmas for constants](manual.html#implementation-specific-pragmas-compileminustime-define-pragmas), +there is a generic `{.define.}` pragma that interprets the value of the define +based on the type of the constant value. + + ```nim + const foo {.define: "package.foo".} = 123 + const bar {.define: "package.bar".} = false + ``` + + ```cmd + nim c -d:package.foo=456 -d:package.bar foobar.nim + ``` + +The following types are supported: + +* `string` and `cstring` +* Signed and unsigned integer types +* `bool` +* Enums + Top-down type inference ======================= |