@@ -12,7 +12,7 @@ pub struct S {
1212 pub self__ : Value < Ptr < S > > ,
1313}
1414impl S {
15- pub fn S ( a : i32 ) -> Self {
15+ pub fn S1 ( a : i32 ) -> Self {
1616 let a: Value < i32 > = Rc :: new ( RefCell :: new ( a) ) ;
1717 let __this: Value < S > = Rc :: new ( RefCell :: new ( Self {
1818 a_ : Rc :: new ( RefCell :: new ( ( * a. borrow ( ) ) ) ) ,
@@ -21,6 +21,21 @@ impl S {
2121 let this: Ptr < S > = __this. as_pointer ( ) ;
2222 Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
2323 }
24+ pub fn S2 ( a : i32 , other : Ptr < S > ) -> Self {
25+ let a: Value < i32 > = Rc :: new ( RefCell :: new ( a) ) ;
26+ let other: Value < Ptr < S > > = Rc :: new ( RefCell :: new ( other) ) ;
27+ let __this: Value < S > = Rc :: new ( RefCell :: new ( Self {
28+ a_ : Rc :: new ( RefCell :: new ( ( * a. borrow ( ) ) ) ) ,
29+ self__ : Rc :: new ( RefCell :: new ( Ptr :: < S > :: null ( ) ) ) ,
30+ } ) ) ;
31+ let this: Ptr < S > = __this. as_pointer ( ) ;
32+ if ( this == ( * other. borrow ( ) ) ) {
33+ ( * ( * this. upgrade ( ) . deref ( ) ) . self__ . borrow_mut ( ) ) = Ptr :: < S > :: null ( ) ;
34+ } else {
35+ ( * ( * this. upgrade ( ) . deref ( ) ) . self__ . borrow_mut ( ) ) = ( * other. borrow ( ) ) . clone ( ) ;
36+ }
37+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
38+ }
2439}
2540impl Clone for S {
2641 fn clone ( & self ) -> Self {
@@ -92,7 +107,7 @@ pub fn main() {
92107 std:: process:: exit ( main_0 ( ) ) ;
93108}
94109fn main_0 ( ) -> i32 {
95- let s: Value < S > = Rc :: new ( RefCell :: new ( S :: S ( { 1 } ) ) ) ;
110+ let s: Value < S > = Rc :: new ( RefCell :: new ( S :: S1 ( { 1 } ) ) ) ;
96111 let ref_: Ptr < S > = ( { SImpl :: returns_this_reference ( & s. as_pointer ( ) ) } ) ;
97112 ( * ( * ref_. upgrade ( ) . deref ( ) ) . a_ . borrow_mut ( ) ) . postfix_inc ( ) ;
98113 assert ! ( ( ( * ( * s. borrow( ) ) . a_. borrow( ) ) == 2 ) ) ;
@@ -122,22 +137,22 @@ fn main_0() -> i32 {
122137 assert ! ( ( ( * ( * d. borrow( ) ) . a_. borrow( ) ) == 6 ) ) ;
123138 let cr: Ptr < S > = ( { SImpl :: cref ( & s. as_pointer ( ) ) } ) ;
124139 assert ! ( ( ( * ( * cr. upgrade( ) . deref( ) ) . a_. borrow( ) ) == 9 ) ) ;
125- let t: Value < S > = Rc :: new ( RefCell :: new ( S :: S ( { 0 } ) ) ) ;
140+ let t: Value < S > = Rc :: new ( RefCell :: new ( S :: S1 ( { 0 } ) ) ) ;
126141 assert ! (
127142 ( {
128143 let _o: Ptr <S > = ( s. as_pointer( ) ) ;
129144 SImpl :: is( & s. as_pointer( ) , _o)
130145 } )
131146 ) ;
132147 assert ! ( !( { SImpl :: is( & s. as_pointer( ) , ( t. as_pointer( ) ) , ) } ) ) ;
133- let p: Value < Ptr < S > > = Rc :: new ( RefCell :: new ( Ptr :: alloc ( S :: S ( { 1 } ) ) ) ) ;
148+ let p: Value < Ptr < S > > = Rc :: new ( RefCell :: new ( Ptr :: alloc ( S :: S1 ( { 1 } ) ) ) ) ;
134149 let q: Value < Ptr < S > > = Rc :: new ( RefCell :: new (
135150 ( { SImpl :: returns_this_pointer ( & ( * p. borrow ( ) ) ) } ) ,
136151 ) ) ;
137152 ( * ( * ( * q. borrow ( ) ) . upgrade ( ) . deref ( ) ) . a_ . borrow_mut ( ) ) . postfix_inc ( ) ;
138153 assert ! ( ( ( * ( * ( * p. borrow( ) ) . upgrade( ) . deref( ) ) . a_. borrow( ) ) == 2 ) ) ;
139154 ( * p. borrow ( ) ) . delete ( ) ;
140- let h: Value < Ptr < S > > = Rc :: new ( RefCell :: new ( Ptr :: alloc ( S :: S ( { 5 } ) ) ) ) ;
155+ let h: Value < Ptr < S > > = Rc :: new ( RefCell :: new ( Ptr :: alloc ( S :: S1 ( { 5 } ) ) ) ) ;
141156 ( { SImpl :: destroy ( & ( * h. borrow ( ) ) ) } ) ;
142157 ( { SImpl :: reset ( & s. as_pointer ( ) ) } ) ;
143158 assert ! ( ( ( * ( * s. borrow( ) ) . a_. borrow( ) ) == 0 ) ) ;
@@ -156,7 +171,7 @@ fn main_0() -> i32 {
156171 } ) as i32 )
157172 == ( false as i32 ) )
158173 ) ;
159- let other: Value < S > = Rc :: new ( RefCell :: new ( S :: S ( { 22 } ) ) ) ;
174+ let other: Value < S > = Rc :: new ( RefCell :: new ( S :: S1 ( { 22 } ) ) ) ;
160175 assert ! (
161176 ( ( ( { SImpl :: copy_if_different( & s. as_pointer( ) , ( other. as_pointer( ) ) , ) } ) as i32 )
162177 == ( true as i32 ) )
@@ -166,6 +181,11 @@ fn main_0() -> i32 {
166181 let _lhs = ( * ( * s. borrow( ) ) . self__. borrow( ) ) . clone( ) ;
167182 _lhs == ( * ( * other. borrow( ) ) . self__. borrow( ) ) . clone( )
168183 } ) ;
184+ let u: Value < S > = Rc :: new ( RefCell :: new ( S :: S2 ( { 1 } , { ( s. as_pointer ( ) ) } ) ) ) ;
185+ assert ! ( {
186+ let _lhs = ( * ( * u. borrow( ) ) . self__. borrow( ) ) . clone( ) ;
187+ _lhs == ( s. as_pointer( ) )
188+ } ) ;
169189 return 0 ;
170190}
171191pub trait SImpl {
@@ -222,7 +242,7 @@ impl SImpl for Ptr<S> {
222242 ( * self ) . delete ( ) ;
223243 }
224244 fn reset ( & self ) {
225- ( * self ) . write ( S :: S ( { 0 } ) ) ;
245+ ( * self ) . write ( S :: S1 ( { 0 } ) ) ;
226246 }
227247 fn copy_if_different_const ( & self , other : Ptr < S > ) -> bool {
228248 let other: Value < Ptr < S > > = Rc :: new ( RefCell :: new ( other) ) ;
0 commit comments