(module json (export quote_string null_value bool_value i32_value u32_value i64_value u64_value f64_value field_string field_bool field_i32 field_u32 field_i64 field_u64 field_f64 field_null array0 array1 array2 array3 object0 object1 object2 object3))

(fn quote_string ((value string)) -> string
  (std.json.quote_string value))

(fn null_value () -> string
  "null")

(fn bool_value ((value bool)) -> string
  (if value
    "true"
    "false"))

(fn i32_value ((value i32)) -> string
  (std.num.i32_to_string value))

(fn u32_value ((value u32)) -> string
  (std.num.u32_to_string value))

(fn i64_value ((value i64)) -> string
  (std.num.i64_to_string value))

(fn u64_value ((value u64)) -> string
  (std.num.u64_to_string value))

(fn f64_value ((value f64)) -> string
  (std.num.f64_to_string value))

(fn field_fragment ((name string) (encoded_value string)) -> string
  (std.string.concat (std.string.concat (quote_string name) ":") encoded_value))

(fn field_string ((name string) (value string)) -> string
  (field_fragment name (quote_string value)))

(fn field_bool ((name string) (value bool)) -> string
  (field_fragment name (bool_value value)))

(fn field_i32 ((name string) (value i32)) -> string
  (field_fragment name (i32_value value)))

(fn field_u32 ((name string) (value u32)) -> string
  (field_fragment name (u32_value value)))

(fn field_i64 ((name string) (value i64)) -> string
  (field_fragment name (i64_value value)))

(fn field_u64 ((name string) (value u64)) -> string
  (field_fragment name (u64_value value)))

(fn field_f64 ((name string) (value f64)) -> string
  (field_fragment name (f64_value value)))

(fn field_null ((name string)) -> string
  (field_fragment name (null_value)))

(fn array0 () -> string
  "[]")

(fn array1 ((first string)) -> string
  (std.string.concat (std.string.concat "[" first) "]"))

(fn array2 ((first string) (second string)) -> string
  (std.string.concat (std.string.concat (std.string.concat (std.string.concat "[" first) ",") second) "]"))

(fn array3 ((first string) (second string) (third string)) -> string
  (std.string.concat (std.string.concat (std.string.concat (std.string.concat (std.string.concat (std.string.concat "[" first) ",") second) ",") third) "]"))

(fn object0 () -> string
  "{}")

(fn object1 ((first string)) -> string
  (std.string.concat (std.string.concat "{" first) "}"))

(fn object2 ((first string) (second string)) -> string
  (std.string.concat (std.string.concat (std.string.concat (std.string.concat "{" first) ",") second) "}"))

(fn object3 ((first string) (second string) (third string)) -> string
  (std.string.concat (std.string.concat (std.string.concat (std.string.concat (std.string.concat (std.string.concat "{" first) ",") second) ",") third) "}"))
