File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5
- refs/heads/try: ec9c68c1df2ab657e630993d34c859d8bcb3f18e
5
+ refs/heads/try: 6e20ffeb8d6be059ee717993fc7ad2bcd86a0b13
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
8
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ enum TypeDesc = {
16
16
// Remaining fields not listed
17
17
} ;
18
18
19
+ /// The representation of a Rust closure
20
+ struct Closure {
21
+ code : * ( ) ;
22
+ env : * ( ) ;
23
+ }
24
+
19
25
#[ abi = "cdecl" ]
20
26
extern mod rustrt {
21
27
pure fn shape_log_str ( t : * sys:: TypeDesc , data : * ( ) ) -> ~str ;
@@ -138,6 +144,27 @@ mod tests {
138
144
assert pref_align_of :: < uint > ( ) == 8 u;
139
145
assert pref_align_of :: < * uint > ( ) == 8 u;
140
146
}
147
+
148
+ #[ test]
149
+ fn synthesize_closure ( ) unsafe {
150
+ let x = 10 ;
151
+ let f: fn ( int ) -> int = |y| x + y;
152
+
153
+ assert f( 20 ) == 30 ;
154
+
155
+ let original_closure: Closure = unsafe :: transmute ( f) ;
156
+
157
+ let actual_function_pointer = original_closure. code ;
158
+ let environment = original_closure. env ;
159
+
160
+ let new_closure = Closure {
161
+ code : actual_function_pointer,
162
+ env : environment
163
+ } ;
164
+
165
+ let new_f: fn ( int ) -> int = unsafe :: transmute ( new_closure) ;
166
+ assert new_f( 20 ) == 30 ;
167
+ }
141
168
}
142
169
143
170
// Local Variables:
You can’t perform that action at this time.
0 commit comments