Skip to content

Commit 09998f0

Browse files
committed
---
yaml --- r: 28152 b: refs/heads/try c: 6e20ffe h: refs/heads/master v: v3
1 parent c362431 commit 09998f0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5-
refs/heads/try: ec9c68c1df2ab657e630993d34c859d8bcb3f18e
5+
refs/heads/try: 6e20ffeb8d6be059ee717993fc7ad2bcd86a0b13
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df

branches/try/src/libcore/sys.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ enum TypeDesc = {
1616
// Remaining fields not listed
1717
};
1818

19+
/// The representation of a Rust closure
20+
struct Closure {
21+
code: *();
22+
env: *();
23+
}
24+
1925
#[abi = "cdecl"]
2026
extern mod rustrt {
2127
pure fn shape_log_str(t: *sys::TypeDesc, data: *()) -> ~str;
@@ -138,6 +144,27 @@ mod tests {
138144
assert pref_align_of::<uint>() == 8u;
139145
assert pref_align_of::<*uint>() == 8u;
140146
}
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+
}
141168
}
142169

143170
// Local Variables:

0 commit comments

Comments
 (0)