(module env (export get get_result get_option has get_or get_i32_result get_i32_option get_i32_or_zero get_i32_or get_u32_result get_u32_option get_u32_or_zero get_u32_or get_i64_result get_i64_option get_i64_or_zero get_i64_or get_u64_result get_u64_option get_u64_or_zero get_u64_or get_f64_result get_f64_option get_f64_or_zero get_f64_or get_bool_result get_bool_option get_bool_or_false get_bool_or))

(import 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))

(import string (parse_i32_result parse_u32_result parse_i64_result parse_u64_result parse_f64_result parse_bool_result))

(fn get ((name string)) -> string
  (std.env.get name))

(fn get_result ((name string)) -> (result string i32)
  (std.env.get_result name))

(fn get_option ((name string)) -> (option string)
  (ok_or_none_string (get_result name)))

(fn has ((name string)) -> bool
  (match (get_result name)
    ((ok payload)
      true)
    ((err code)
      false)))

(fn get_or ((name string) (fallback string)) -> string
  (match (get_result name)
    ((ok payload)
      payload)
    ((err code)
      fallback)))

(fn get_i32_result ((name string)) -> (result i32 i32)
  (match (get_result name)
    ((ok text)
      (parse_i32_result text))
    ((err code)
      (err i32 i32 code))))

(fn get_i32_option ((name string)) -> (option i32)
  (ok_or_none_i32 (get_i32_result name)))

(fn get_i32_or_zero ((name string)) -> i32
  (match (get_i32_result name)
    ((ok value)
      value)
    ((err code)
      0)))

(fn get_i32_or ((name string) (fallback i32)) -> i32
  (match (get_i32_result name)
    ((ok value)
      value)
    ((err code)
      fallback)))

(fn get_u32_result ((name string)) -> (result u32 i32)
  (match (get_result name)
    ((ok text)
      (parse_u32_result text))
    ((err code)
      (err u32 i32 code))))

(fn get_u32_option ((name string)) -> (option u32)
  (ok_or_none_u32 (get_u32_result name)))

(fn get_u32_or_zero ((name string)) -> u32
  (match (get_u32_result name)
    ((ok value)
      value)
    ((err code)
      0u32)))

(fn get_u32_or ((name string) (fallback u32)) -> u32
  (match (get_u32_result name)
    ((ok value)
      value)
    ((err code)
      fallback)))

(fn get_i64_result ((name string)) -> (result i64 i32)
  (match (get_result name)
    ((ok text)
      (parse_i64_result text))
    ((err code)
      (err i64 i32 code))))

(fn get_i64_option ((name string)) -> (option i64)
  (ok_or_none_i64 (get_i64_result name)))

(fn get_i64_or_zero ((name string)) -> i64
  (match (get_i64_result name)
    ((ok value)
      value)
    ((err code)
      0i64)))

(fn get_i64_or ((name string) (fallback i64)) -> i64
  (match (get_i64_result name)
    ((ok value)
      value)
    ((err code)
      fallback)))

(fn get_u64_result ((name string)) -> (result u64 i32)
  (match (get_result name)
    ((ok text)
      (parse_u64_result text))
    ((err code)
      (err u64 i32 code))))

(fn get_u64_option ((name string)) -> (option u64)
  (ok_or_none_u64 (get_u64_result name)))

(fn get_u64_or_zero ((name string)) -> u64
  (match (get_u64_result name)
    ((ok value)
      value)
    ((err code)
      0u64)))

(fn get_u64_or ((name string) (fallback u64)) -> u64
  (match (get_u64_result name)
    ((ok value)
      value)
    ((err code)
      fallback)))

(fn get_f64_result ((name string)) -> (result f64 i32)
  (match (get_result name)
    ((ok text)
      (parse_f64_result text))
    ((err code)
      (err f64 i32 code))))

(fn get_f64_option ((name string)) -> (option f64)
  (ok_or_none_f64 (get_f64_result name)))

(fn get_f64_or_zero ((name string)) -> f64
  (match (get_f64_result name)
    ((ok value)
      value)
    ((err code)
      0.0)))

(fn get_f64_or ((name string) (fallback f64)) -> f64
  (match (get_f64_result name)
    ((ok value)
      value)
    ((err code)
      fallback)))

(fn get_bool_result ((name string)) -> (result bool i32)
  (match (get_result name)
    ((ok text)
      (parse_bool_result text))
    ((err code)
      (err bool i32 code))))

(fn get_bool_option ((name string)) -> (option bool)
  (ok_or_none_bool (get_bool_result name)))

(fn get_bool_or_false ((name string)) -> bool
  (match (get_bool_result name)
    ((ok value)
      value)
    ((err code)
      false)))

(fn get_bool_or ((name string) (fallback bool)) -> bool
  (match (get_bool_result name)
    ((ok value)
      value)
    ((err code)
      fallback)))
