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

(* StructTuple
  {
    name := "Foo";
    const_params := [];
    ty_params := [];
    fields := [];
  } *)

(* StructTuple
  {
    name := "Bar";
    const_params := [];
    ty_params := [];
    fields := [];
  } *)

(* StructTuple
  {
    name := "FooBar";
    const_params := [];
    ty_params := [];
    fields := [];
  } *)

Module Impl_core_fmt_Debug_for_operator_overloading_FooBar.
  Definition Self : Ty.t := Ty.path "operator_overloading::FooBar".
  
  (* Debug *)
  Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; f ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let f := M.alloc (| f |) in
        M.call_closure (|
          M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [] |),
          [ M.read (| f |); M.read (| Value.String "FooBar" |) ]
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "core::fmt::Debug"
      Self
      (* Trait polymorphic types *) []
      (* Instance *) [ ("fmt", InstanceField.Method fmt) ].
End Impl_core_fmt_Debug_for_operator_overloading_FooBar.

(* StructTuple
  {
    name := "BarFoo";
    const_params := [];
    ty_params := [];
    fields := [];
  } *)

Module Impl_core_fmt_Debug_for_operator_overloading_BarFoo.
  Definition Self : Ty.t := Ty.path "operator_overloading::BarFoo".
  
  (* Debug *)
  Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; f ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let f := M.alloc (| f |) in
        M.call_closure (|
          M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [] |),
          [ M.read (| f |); M.read (| Value.String "BarFoo" |) ]
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "core::fmt::Debug"
      Self
      (* Trait polymorphic types *) []
      (* Instance *) [ ("fmt", InstanceField.Method fmt) ].
End Impl_core_fmt_Debug_for_operator_overloading_BarFoo.

Module Impl_core_ops_arith_Add_operator_overloading_Bar_for_operator_overloading_Foo.
  Definition Self : Ty.t := Ty.path "operator_overloading::Foo".
  
  (*     type Output = FooBar; *)
  Definition _Output : Ty.t := Ty.path "operator_overloading::FooBar".
  
  (*
      fn add(self, _rhs: Bar) -> FooBar {
          println!("> Foo.add(Bar) was called");
  
          FooBar
      }
  *)
  Definition add (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; _rhs ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let _rhs := M.alloc (| _rhs |) in
        M.read (|
          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_const",
                        []
                      |),
                      [
                        M.alloc (|
                          Value.Array [ M.read (| Value.String "> Foo.add(Bar) was called
" |) ]
                        |)
                      ]
                    |)
                  ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |) in
          M.alloc (| Value.StructTuple "operator_overloading::FooBar" [] |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "core::ops::arith::Add"
      Self
      (* Trait polymorphic types *) [ (* Rhs *) Ty.path "operator_overloading::Bar" ]
      (* Instance *) [ ("Output", InstanceField.Ty _Output); ("add", InstanceField.Method add) ].
End Impl_core_ops_arith_Add_operator_overloading_Bar_for_operator_overloading_Foo.

Module Impl_core_ops_arith_Add_operator_overloading_Foo_for_operator_overloading_Bar.
  Definition Self : Ty.t := Ty.path "operator_overloading::Bar".
  
  (*     type Output = BarFoo; *)
  Definition _Output : Ty.t := Ty.path "operator_overloading::BarFoo".
  
  (*
      fn add(self, _rhs: Foo) -> BarFoo {
          println!("> Bar.add(Foo) was called");
  
          BarFoo
      }
  *)
  Definition add (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; _rhs ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let _rhs := M.alloc (| _rhs |) in
        M.read (|
          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_const",
                        []
                      |),
                      [
                        M.alloc (|
                          Value.Array [ M.read (| Value.String "> Bar.add(Foo) was called
" |) ]
                        |)
                      ]
                    |)
                  ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |) in
          M.alloc (| Value.StructTuple "operator_overloading::BarFoo" [] |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "core::ops::arith::Add"
      Self
      (* Trait polymorphic types *) [ (* Rhs *) Ty.path "operator_overloading::Foo" ]
      (* Instance *) [ ("Output", InstanceField.Ty _Output); ("add", InstanceField.Method add) ].
End Impl_core_ops_arith_Add_operator_overloading_Foo_for_operator_overloading_Bar.

(*
fn main() {
    println!("Foo + Bar = {:?}", Foo + Bar);
    println!("Bar + Foo = {:?}", Bar + Foo);
}
*)
Definition main (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
  match ε, τ, α with
  | [], [], [] =>
    ltac:(M.monadic
      (M.read (|
        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 "Foo + Bar = " |); M.read (| Value.String "
" |)
                          ]
                      |);
                      M.alloc (|
                        Value.Array
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "core::fmt::rt::Argument",
                                "new_debug",
                                [ Ty.path "operator_overloading::FooBar" ]
                              |),
                              [
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_trait_method (|
                                      "core::ops::arith::Add",
                                      Ty.path "operator_overloading::Foo",
                                      [ Ty.path "operator_overloading::Bar" ],
                                      "add",
                                      []
                                    |),
                                    [
                                      Value.StructTuple "operator_overloading::Foo" [];
                                      Value.StructTuple "operator_overloading::Bar" []
                                    ]
                                  |)
                                |)
                              ]
                            |)
                          ]
                      |)
                    ]
                  |)
                ]
              |)
            |) in
          M.alloc (| Value.Tuple [] |) 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 "Bar + Foo = " |); M.read (| Value.String "
" |)
                          ]
                      |);
                      M.alloc (|
                        Value.Array
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "core::fmt::rt::Argument",
                                "new_debug",
                                [ Ty.path "operator_overloading::BarFoo" ]
                              |),
                              [
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_trait_method (|
                                      "core::ops::arith::Add",
                                      Ty.path "operator_overloading::Bar",
                                      [ Ty.path "operator_overloading::Foo" ],
                                      "add",
                                      []
                                    |),
                                    [
                                      Value.StructTuple "operator_overloading::Bar" [];
                                      Value.StructTuple "operator_overloading::Foo" []
                                    ]
                                  |)
                                |)
                              ]
                            |)
                          ]
                      |)
                    ]
                  |)
                ]
              |)
            |) in
          M.alloc (| Value.Tuple [] |) in
        M.alloc (| Value.Tuple [] |)
      |)))
  | _, _, _ => M.impossible "wrong number of arguments"
  end.

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