Skip to content

Commit

Permalink
[stdlib] Add examples for env_get_int and sizeof
Browse files Browse the repository at this point in the history
Signed-off-by: rd4com <144297616+rd4com@users.noreply.github.com>
  • Loading branch information
rd4com committed Oct 3, 2024
1 parent 93004e6 commit f804d30
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions stdlib/src/sys/info.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,22 @@ fn sizeof[
Returns:
The size of the type in bytes.
Example:
```mojo
from sys.info import sizeof
def main():
print(
sizeof[UInt8]() == 1,
sizeof[UInt16]() == 2,
sizeof[Int32]() == 4,
sizeof[Float64]() == 8,
sizeof[
SIMD[DType.uint8, 4]
]() == 4,
)
```
Note: `align_of` is in same module.
"""
alias mlir_type = __mlir_attr[
`#kgen.param.expr<rebind, #kgen.type<!kgen.paramref<`,
Expand Down
21 changes: 21 additions & 0 deletions stdlib/src/sys/param_env.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ fn env_get_int[name: StringLiteral, default: Int]() -> Int:
Returns:
An integer parameter value.
Example:
```mojo
from sys.param_env import env_get_int
def main():
alias number = env_get_int[
"favorite_number",
1 # Default value
]()
parametrized[number]()
fn parametrized[num: Int]():
print(num)
```
If the program is `app.mojo`:
- `mojo run -D favorite_number=2 app.mojo`
- `mojo run -D app.mojo`
Note: useful for parametrizing SIMD vector sizes.
"""

@parameter
Expand Down

0 comments on commit f804d30

Please sign in to comment.