@@ -42,6 +42,37 @@ pub fn more_refs_0(x1: i32, x2: i32, r1: Ptr<i32>, r2: Ptr<i32>) {
4242 let __rhs = ( rx2. read ( ) ) ;
4343 r1. write ( __rhs) ;
4444}
45+ #[ derive( Default ) ]
46+ pub struct Val {
47+ pub x : Value < i32 > ,
48+ }
49+ impl Clone for Val {
50+ fn clone ( & self ) -> Self {
51+ let __this: Value < Val > = Rc :: new ( RefCell :: new ( Self {
52+ x : Rc :: new ( RefCell :: new ( ( * self . x . borrow ( ) ) ) ) ,
53+ } ) ) ;
54+ let this: Ptr < Val > = __this. as_pointer ( ) ;
55+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
56+ }
57+ }
58+ impl ByteRepr for Val {
59+ fn byte_size ( ) -> usize {
60+ 4
61+ }
62+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
63+ ( * self . x . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..4 ] ) ;
64+ }
65+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
66+ Self {
67+ x : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 0 ..4 ] ) ) ) ,
68+ }
69+ }
70+ }
71+ pub fn sum_1 ( a : Val , b : Val ) -> i32 {
72+ let a: Value < Val > = Rc :: new ( RefCell :: new ( a) ) ;
73+ let b: Value < Val > = Rc :: new ( RefCell :: new ( b) ) ;
74+ return ( ( * ( * a. borrow ( ) ) . x . borrow ( ) ) + ( * ( * b. borrow ( ) ) . x . borrow ( ) ) ) ;
75+ }
4576pub fn main ( ) {
4677 __cpp2rust_init_globals ( ) ;
4778 std:: process:: exit ( main_0 ( ) ) ;
@@ -51,6 +82,32 @@ fn main_0() -> i32 {
5182 let x2: Value < i32 > = Rc :: new ( RefCell :: new ( 2 ) ) ;
5283 ( { more_refs_0 ( 3 , 4 , x1. as_pointer ( ) , x2. as_pointer ( ) ) } ) ;
5384 assert ! ( ( ( ( * x1. borrow( ) ) + ( * x2. borrow( ) ) ) == 21 ) ) ;
85+ let v: Value < Val > = Rc :: new ( RefCell :: new ( Val {
86+ x : Rc :: new ( RefCell :: new ( 5 ) ) ,
87+ } ) ) ;
88+ let acc: Value < i32 > = Rc :: new ( RefCell :: new (
89+ ( {
90+ let _a: Val = ( * v. borrow ( ) ) . clone ( ) ;
91+ let _b: Val = ( * v. borrow ( ) ) . clone ( ) ;
92+ sum_1 ( _a, _b)
93+ } ) ,
94+ ) ) ;
95+ ( * acc. borrow_mut ( ) ) += ( {
96+ let _a: Val = ( * v. borrow ( ) ) . clone ( ) ;
97+ let _b: Val = ( * v. borrow ( ) ) . clone ( ) ;
98+ sum_1 ( _a, _b)
99+ } ) ;
100+ ( * acc. borrow_mut ( ) ) += ( {
101+ let _a: Val = ( * v. borrow ( ) ) . clone ( ) ;
102+ let _b: Val = ( * v. borrow ( ) ) . clone ( ) ;
103+ sum_1 ( _a, _b)
104+ } ) ;
105+ ( * acc. borrow_mut ( ) ) += ( {
106+ let _a: Val = ( * v. borrow ( ) ) . clone ( ) ;
107+ let _b: Val = ( * v. borrow ( ) ) . clone ( ) ;
108+ sum_1 ( _a, _b)
109+ } ) ;
110+ assert ! ( ( ( * acc. borrow( ) ) == 40 ) ) ;
54111 return 0 ;
55112}
56113pub fn __cpp2rust_init_globals ( ) { }
0 commit comments