(* Generated by coq-of-rust *)
Require Import CoqOfRust.CoqOfRust.

(* StructRecord
  {
    name := "Val";
    const_params := [];
    ty_params := [];
    fields := [ ("val", Ty.path "f64") ];
  } *)

(* StructRecord
  {
    name := "GenVal";
    const_params := [];
    ty_params := [ "T" ];
    fields := [ ("gen_val", T) ];
  } *)

Module Impl_generics_implementation_Val.
  Definition Self : Ty.t := Ty.path "generics_implementation::Val".
  
  (*
      fn value(&self) -> &f64 {
          &self.val
      }
  *)
  Definition value (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        M.SubPointer.get_struct_record_field (|
          M.read (| self |),
          "generics_implementation::Val",
          "val"
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_value : M.IsAssociatedFunction Self "value" value.
End Impl_generics_implementation_Val.

Module Impl_generics_implementation_GenVal_T.
  Definition Self (T : Ty.t) : Ty.t :=
    Ty.apply (Ty.path "generics_implementation::GenVal") [] [ T ].
  
  (*
      fn value(&self) -> &T {
          &self.gen_val
      }
  *)
  Definition value (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    let Self : Ty.t := Self T in
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        M.SubPointer.get_struct_record_field (|
          M.read (| self |),
          "generics_implementation::GenVal",
          "gen_val"
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_value :
    forall (T : Ty.t),
    M.IsAssociatedFunction (Self T) "value" (value T).
End Impl_generics_implementation_GenVal_T.

(*
fn main() {
    let x = Val { val: 3.0 };
    let y = GenVal { gen_val: 3i32 };

    println!("{}, {}", x.value(), y.value());
}
*)
Definition main (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
  match ε, τ, α with
  | [], [], [] =>
    ltac:(M.monadic
      (M.read (|
        let~ x :=
          M.alloc (|
            Value.StructRecord
              "generics_implementation::Val"
              [ ("val", M.read (| UnsupportedLiteral |)) ]
          |) in
        let~ y :=
          M.alloc (|
            Value.StructRecord
              "generics_implementation::GenVal"
              [ ("gen_val", Value.Integer IntegerKind.I32 3) ]
          |) in
        let~ _ :=
          let~ _ :=
            M.alloc (|
              M.call_closure (|
                M.get_function (| "std::io::stdio::_print", [] |),
                [
                  M.call_closure (|
                    M.get_associated_function (| Ty.path "core::fmt::Arguments", "new_v1", [] |),
                    [
                      M.alloc (|
                        Value.Array
                          [
                            M.read (| Value.String "" |);
                            M.read (| Value.String ", " |);
                            M.read (| Value.String "
" |)
                          ]
                      |);
                      M.alloc (|
                        Value.Array
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "core::fmt::rt::Argument",
                                "new_display",
                                [ Ty.apply (Ty.path "&") [] [ Ty.path "f64" ] ]
                              |),
                              [
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.path "generics_implementation::Val",
                                      "value",
                                      []
                                    |),
                                    [ x ]
                                  |)
                                |)
                              ]
                            |);
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "core::fmt::rt::Argument",
                                "new_display",
                                [ Ty.apply (Ty.path "&") [] [ Ty.path "i32" ] ]
                              |),
                              [
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply
                                        (Ty.path "generics_implementation::GenVal")
                                        []
                                        [ Ty.path "i32" ],
                                      "value",
                                      []
                                    |),
                                    [ y ]
                                  |)
                                |)
                              ]
                            |)
                          ]
                      |)
                    ]
                  |)
                ]
              |)
            |) in
          M.alloc (| Value.Tuple [] |) in
        M.alloc (| Value.Tuple [] |)
      |)))
  | _, _, _ => M.impossible "wrong number of arguments"
  end.

Axiom Function_main : M.IsFunction "generics_implementation::main" main.
