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

(* StructTuple
  {
    name := "SomeType";
    const_params := [];
    ty_params := [];
    fields := [ Ty.path "u32" ];
  } *)

(* StructTuple
  {
    name := "OtherType";
    const_params := [];
    ty_params := [];
    fields := [ Ty.path "bool" ];
  } *)

Module Impl_functions_order_SomeType.
  Definition Self : Ty.t := Ty.path "functions_order::SomeType".
  
  (*
      pub fn meth1(self) {
          self.meth2();
      }
  *)
  Definition meth1 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        M.read (|
          let~ _ :=
            M.alloc (|
              M.call_closure (|
                M.get_associated_function (| Ty.path "functions_order::SomeType", "meth2", [] |),
                [ M.read (| self |) ]
              |)
            |) in
          M.alloc (| Value.Tuple [] |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_meth1 : M.IsAssociatedFunction Self "meth1" meth1.
  
  (*     fn meth2(self) {} *)
  Definition meth2 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        Value.Tuple []))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_meth2 : M.IsAssociatedFunction Self "meth2" meth2.
End Impl_functions_order_SomeType.

(*
fn depends_on_trait_impl(u: u32, b: bool) {
    OtherType(b).some_trait_foo();
    SomeType(u).some_trait_foo();
}
*)
Definition depends_on_trait_impl (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
  match ε, τ, α with
  | [], [], [ u; b ] =>
    ltac:(M.monadic
      (let u := M.alloc (| u |) in
      let b := M.alloc (| b |) in
      M.read (|
        let~ _ :=
          M.alloc (|
            M.call_closure (|
              M.get_trait_method (|
                "functions_order::SomeTrait",
                Ty.path "functions_order::OtherType",
                [],
                "some_trait_foo",
                []
              |),
              [ M.alloc (| Value.StructTuple "functions_order::OtherType" [ M.read (| b |) ] |) ]
            |)
          |) in
        let~ _ :=
          M.alloc (|
            M.call_closure (|
              M.get_trait_method (|
                "functions_order::SomeTrait",
                Ty.path "functions_order::SomeType",
                [],
                "some_trait_foo",
                []
              |),
              [ M.alloc (| Value.StructTuple "functions_order::SomeType" [ M.read (| u |) ] |) ]
            |)
          |) in
        M.alloc (| Value.Tuple [] |)
      |)))
  | _, _, _ => M.impossible "wrong number of arguments"
  end.

Axiom Function_depends_on_trait_impl :
  M.IsFunction "functions_order::depends_on_trait_impl" depends_on_trait_impl.

(* Trait *)
(* Empty module 'SomeTrait' *)

Module Impl_functions_order_SomeTrait_for_functions_order_SomeType.
  Definition Self : Ty.t := Ty.path "functions_order::SomeType".
  
  (*
      fn some_trait_foo(&self) {
          self.some_trait_bar()
      }
  *)
  Definition some_trait_foo (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        M.call_closure (|
          M.get_trait_method (|
            "functions_order::SomeTrait",
            Ty.path "functions_order::SomeType",
            [],
            "some_trait_bar",
            []
          |),
          [ M.read (| self |) ]
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  (*     fn some_trait_bar(&self) {} *)
  Definition some_trait_bar (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        Value.Tuple []))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "functions_order::SomeTrait"
      Self
      (* Trait polymorphic types *) []
      (* Instance *)
      [
        ("some_trait_foo", InstanceField.Method some_trait_foo);
        ("some_trait_bar", InstanceField.Method some_trait_bar)
      ].
End Impl_functions_order_SomeTrait_for_functions_order_SomeType.

Module Impl_functions_order_SomeTrait_for_functions_order_OtherType.
  Definition Self : Ty.t := Ty.path "functions_order::OtherType".
  
  (*     fn some_trait_foo(&self) {} *)
  Definition some_trait_foo (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        Value.Tuple []))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  (*     fn some_trait_bar(&self) {} *)
  Definition some_trait_bar (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        Value.Tuple []))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "functions_order::SomeTrait"
      Self
      (* Trait polymorphic types *) []
      (* Instance *)
      [
        ("some_trait_foo", InstanceField.Method some_trait_foo);
        ("some_trait_bar", InstanceField.Method some_trait_bar)
      ].
End Impl_functions_order_SomeTrait_for_functions_order_OtherType.

Module inner_mod.
  (*
      pub fn bar() {
          // functions_order::inner_mod::bar
          tar();
      }
  *)
  Definition bar (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [] =>
      ltac:(M.monadic
        (M.read (|
          let~ _ :=
            M.alloc (|
              M.call_closure (| M.get_function (| "functions_order::inner_mod::tar", [] |), [] |)
            |) in
          M.alloc (| Value.Tuple [] |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Function_bar : M.IsFunction "functions_order::inner_mod::bar" bar.
  
  (*     fn tar() {} *)
  Definition tar (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [] => ltac:(M.monadic (Value.Tuple []))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Function_tar : M.IsFunction "functions_order::inner_mod::tar" tar.
  
  Module nested_mod.
    (*
            pub fn tick() {
                tack();
            }
    *)
    Definition tick (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      match ε, τ, α with
      | [], [], [] =>
        ltac:(M.monadic
          (M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "functions_order::inner_mod::nested_mod::tack", [] |),
                  []
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Function_tick : M.IsFunction "functions_order::inner_mod::nested_mod::tick" tick.
    
    (*         fn tack() {} *)
    Definition tack (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      match ε, τ, α with
      | [], [], [] => ltac:(M.monadic (Value.Tuple []))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Function_tack : M.IsFunction "functions_order::inner_mod::nested_mod::tack" tack.
  End nested_mod.
End inner_mod.

(*
fn main() {
    // functions_order::main
    foo();
    inner_mod::bar();
    SomeType(0).meth1();
}
*)
Definition main (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
  match ε, τ, α with
  | [], [], [] =>
    ltac:(M.monadic
      (M.read (|
        let~ _ :=
          M.alloc (| M.call_closure (| M.get_function (| "functions_order::foo", [] |), [] |) |) in
        let~ _ :=
          M.alloc (|
            M.call_closure (| M.get_function (| "functions_order::inner_mod::bar", [] |), [] |)
          |) in
        let~ _ :=
          M.alloc (|
            M.call_closure (|
              M.get_associated_function (| Ty.path "functions_order::SomeType", "meth1", [] |),
              [ Value.StructTuple "functions_order::SomeType" [ Value.Integer IntegerKind.U32 0 ] ]
            |)
          |) in
        M.alloc (| Value.Tuple [] |)
      |)))
  | _, _, _ => M.impossible "wrong number of arguments"
  end.

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

(* fn foo() {} *)
Definition foo (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
  match ε, τ, α with
  | [], [], [] => ltac:(M.monadic (Value.Tuple []))
  | _, _, _ => M.impossible "wrong number of arguments"
  end.

Axiom Function_foo : M.IsFunction "functions_order::foo" foo.
