slovo/lib/std/process.slo
2026-05-22 08:38:43 +02:00

175 lines
4.4 KiB
Plaintext

(module process (export argc arg arg_result arg_option has_arg arg_or arg_or_empty arg_i32_result arg_i32_option arg_i32_or_zero arg_i32_or arg_u32_result arg_u32_option arg_u32_or_zero arg_u32_or arg_i64_result arg_i64_option arg_i64_or_zero arg_i64_or arg_u64_result arg_u64_option arg_u64_or_zero arg_u64_or arg_f64_result arg_f64_option arg_f64_or_zero arg_f64_or arg_bool_result arg_bool_option arg_bool_or_false arg_bool_or))
(import std.result (ok_or_none_string ok_or_none_i32 ok_or_none_u32 ok_or_none_i64 ok_or_none_u64 ok_or_none_f64 ok_or_none_bool))
(fn argc () -> i32
(std.process.argc))
(fn arg ((index i32)) -> string
(std.process.arg index))
(fn arg_result ((index i32)) -> (result string i32)
(std.process.arg_result index))
(fn arg_option ((index i32)) -> (option string)
(ok_or_none_string (arg_result index)))
(fn has_arg ((index i32)) -> bool
(if (< index 0)
false
(< index (std.process.argc))))
(fn arg_or ((index i32) (fallback string)) -> string
(match (arg_result index)
((ok payload)
payload)
((err code)
fallback)))
(fn arg_or_empty ((index i32)) -> string
(arg_or index ""))
(fn arg_i32_result ((index i32)) -> (result i32 i32)
(match (arg_result index)
((ok text)
(std.string.parse_i32_result text))
((err code)
(err i32 i32 code))))
(fn arg_i32_option ((index i32)) -> (option i32)
(ok_or_none_i32 (arg_i32_result index)))
(fn arg_i32_or_zero ((index i32)) -> i32
(match (arg_i32_result index)
((ok value)
value)
((err code)
0)))
(fn arg_i32_or ((index i32) (fallback i32)) -> i32
(match (arg_i32_result index)
((ok value)
value)
((err code)
fallback)))
(fn arg_u32_result ((index i32)) -> (result u32 i32)
(match (arg_result index)
((ok text)
(std.string.parse_u32_result text))
((err code)
(err u32 i32 code))))
(fn arg_u32_option ((index i32)) -> (option u32)
(ok_or_none_u32 (arg_u32_result index)))
(fn arg_u32_or_zero ((index i32)) -> u32
(match (arg_u32_result index)
((ok value)
value)
((err code)
0u32)))
(fn arg_u32_or ((index i32) (fallback u32)) -> u32
(match (arg_u32_result index)
((ok value)
value)
((err code)
fallback)))
(fn arg_i64_result ((index i32)) -> (result i64 i32)
(match (arg_result index)
((ok text)
(std.string.parse_i64_result text))
((err code)
(err i64 i32 code))))
(fn arg_i64_option ((index i32)) -> (option i64)
(ok_or_none_i64 (arg_i64_result index)))
(fn arg_i64_or_zero ((index i32)) -> i64
(match (arg_i64_result index)
((ok value)
value)
((err code)
0i64)))
(fn arg_i64_or ((index i32) (fallback i64)) -> i64
(match (arg_i64_result index)
((ok value)
value)
((err code)
fallback)))
(fn arg_u64_result ((index i32)) -> (result u64 i32)
(match (arg_result index)
((ok text)
(std.string.parse_u64_result text))
((err code)
(err u64 i32 code))))
(fn arg_u64_option ((index i32)) -> (option u64)
(ok_or_none_u64 (arg_u64_result index)))
(fn arg_u64_or_zero ((index i32)) -> u64
(match (arg_u64_result index)
((ok value)
value)
((err code)
0u64)))
(fn arg_u64_or ((index i32) (fallback u64)) -> u64
(match (arg_u64_result index)
((ok value)
value)
((err code)
fallback)))
(fn arg_f64_result ((index i32)) -> (result f64 i32)
(match (arg_result index)
((ok text)
(std.string.parse_f64_result text))
((err code)
(err f64 i32 code))))
(fn arg_f64_option ((index i32)) -> (option f64)
(ok_or_none_f64 (arg_f64_result index)))
(fn arg_f64_or_zero ((index i32)) -> f64
(match (arg_f64_result index)
((ok value)
value)
((err code)
0.0)))
(fn arg_f64_or ((index i32) (fallback f64)) -> f64
(match (arg_f64_result index)
((ok value)
value)
((err code)
fallback)))
(fn arg_bool_result ((index i32)) -> (result bool i32)
(match (arg_result index)
((ok text)
(std.string.parse_bool_result text))
((err code)
(err bool i32 code))))
(fn arg_bool_option ((index i32)) -> (option bool)
(ok_or_none_bool (arg_bool_result index)))
(fn arg_bool_or_false ((index i32)) -> bool
(match (arg_bool_result index)
((ok value)
value)
((err code)
false)))
(fn arg_bool_or ((index i32) (fallback bool)) -> bool
(match (arg_bool_result index)
((ok value)
value)
((err code)
fallback)))