Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stdlib] Add examples for env_get_int and sizeof #3593

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 parameterizing SIMD vector sizes.
"""

@parameter
Expand Down