@@ -47,6 +47,68 @@ impl ByteRepr for S {
4747 }
4848 }
4949}
50+ #[ derive( ) ]
51+ pub struct Point {
52+ pub x : Value < i32 > ,
53+ pub y : Value < i32 > ,
54+ }
55+ impl Point {
56+ pub fn Point1 ( x : i32 , y : i32 ) -> Self {
57+ let x: Value < i32 > = Rc :: new ( RefCell :: new ( x) ) ;
58+ let y: Value < i32 > = Rc :: new ( RefCell :: new ( y) ) ;
59+ let __this: Value < Point > = Rc :: new ( RefCell :: new ( Self {
60+ x : Rc :: new ( RefCell :: new ( ( * x. borrow ( ) ) ) ) ,
61+ y : Rc :: new ( RefCell :: new ( ( * y. borrow ( ) ) ) ) ,
62+ } ) ) ;
63+ let this: Ptr < Point > = __this. as_pointer ( ) ;
64+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
65+ }
66+ pub fn Point2 ( v : i32 ) -> Self {
67+ let v: Value < i32 > = Rc :: new ( RefCell :: new ( v) ) ;
68+ let __this: Value < Point > = Rc :: new ( RefCell :: new ( Point :: Point1 ( { ( * v. borrow ( ) ) } , {
69+ ( ( * v. borrow ( ) ) + 1 )
70+ } ) ) ) ;
71+ let this: Ptr < Point > = __this. as_pointer ( ) ;
72+ ( * ( * this. upgrade ( ) . deref ( ) ) . y . borrow_mut ( ) ) *= 10 ;
73+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
74+ }
75+ pub fn Point3 ( ) -> Self {
76+ let __this: Value < Point > = Rc :: new ( RefCell :: new ( Point :: Point2 ( { 4 } ) ) ) ;
77+ let this: Ptr < Point > = __this. as_pointer ( ) ;
78+ ( * ( * this. upgrade ( ) . deref ( ) ) . x . borrow_mut ( ) ) += 100 ;
79+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
80+ }
81+ }
82+ impl Clone for Point {
83+ fn clone ( & self ) -> Self {
84+ let __this: Value < Point > = Rc :: new ( RefCell :: new ( Self {
85+ x : Rc :: new ( RefCell :: new ( ( * self . x . borrow ( ) ) ) ) ,
86+ y : Rc :: new ( RefCell :: new ( ( * self . y . borrow ( ) ) ) ) ,
87+ } ) ) ;
88+ let this: Ptr < Point > = __this. as_pointer ( ) ;
89+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
90+ }
91+ }
92+ impl Default for Point {
93+ fn default ( ) -> Self {
94+ { Point :: Point3 ( ) }
95+ }
96+ }
97+ impl ByteRepr for Point {
98+ fn byte_size ( ) -> usize {
99+ 8
100+ }
101+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
102+ ( * self . x . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..4 ] ) ;
103+ ( * self . y . borrow ( ) ) . to_bytes ( & mut buf[ 4 ..8 ] ) ;
104+ }
105+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
106+ Self {
107+ x : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 0 ..4 ] ) ) ) ,
108+ y : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 4 ..8 ] ) ) ) ,
109+ }
110+ }
111+ }
50112pub fn main ( ) {
51113 __cpp2rust_init_globals ( ) ;
52114 std:: process:: exit ( main_0 ( ) ) ;
@@ -59,6 +121,12 @@ fn main_0() -> i32 {
59121 assert ! ( ( total_0. with( |rc| rc. borrow( ) . clone( ) ) == 8 ) ) ;
60122 }
61123 assert ! ( ( total_0. with( |rc| rc. borrow( ) . clone( ) ) == 18 ) ) ;
124+ let p: Value < Point > = Rc :: new ( RefCell :: new ( Point :: Point3 ( ) ) ) ;
125+ assert ! ( ( ( * ( * p. borrow( ) ) . x. borrow( ) ) == 104 ) ) ;
126+ assert ! ( ( ( * ( * p. borrow( ) ) . y. borrow( ) ) == 50 ) ) ;
127+ let q: Value < Point > = Rc :: new ( RefCell :: new ( Point :: Point2 ( { 7 } ) ) ) ;
128+ assert ! ( ( ( * ( * q. borrow( ) ) . x. borrow( ) ) == 7 ) ) ;
129+ assert ! ( ( ( * ( * q. borrow( ) ) . y. borrow( ) ) == 80 ) ) ;
62130 return 0 ;
63131}
64132pub trait SImpl {
0 commit comments