1*7c3d14c8STreehugger Robot //
2*7c3d14c8STreehugger Robot // The LLVM Compiler Infrastructure
3*7c3d14c8STreehugger Robot //
4*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
5*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
6*7c3d14c8STreehugger Robot
7*7c3d14c8STreehugger Robot // CONFIG
8*7c3d14c8STreehugger Robot
9*7c3d14c8STreehugger Robot
10*7c3d14c8STreehugger Robot #include <stdio.h>
11*7c3d14c8STreehugger Robot #include <stdbool.h>
12*7c3d14c8STreehugger Robot #include <stdlib.h>
13*7c3d14c8STreehugger Robot #include <Block.h>
14*7c3d14c8STreehugger Robot
15*7c3d14c8STreehugger Robot int
main(int argc,char * argv[])16*7c3d14c8STreehugger Robot main(int argc, char *argv[])
17*7c3d14c8STreehugger Robot {
18*7c3d14c8STreehugger Robot __block int var = 0;
19*7c3d14c8STreehugger Robot void (^b)(void) = ^{ var++; };
20*7c3d14c8STreehugger Robot
21*7c3d14c8STreehugger Robot //sanity(b);
22*7c3d14c8STreehugger Robot b();
23*7c3d14c8STreehugger Robot printf("%s: success!\n", argv[0]);
24*7c3d14c8STreehugger Robot return 0;
25*7c3d14c8STreehugger Robot }
26*7c3d14c8STreehugger Robot
27*7c3d14c8STreehugger Robot
28*7c3d14c8STreehugger Robot #if 1
29*7c3d14c8STreehugger Robot /* replicated internal data structures: BEWARE, MAY CHANGE!!! */
30*7c3d14c8STreehugger Robot
31*7c3d14c8STreehugger Robot enum {
32*7c3d14c8STreehugger Robot BLOCK_REFCOUNT_MASK = (0xffff),
33*7c3d14c8STreehugger Robot BLOCK_NEEDS_FREE = (1 << 24),
34*7c3d14c8STreehugger Robot BLOCK_HAS_COPY_DISPOSE = (1 << 25),
35*7c3d14c8STreehugger Robot BLOCK_NO_COPY = (1 << 26), // interim byref: no copies allowed
36*7c3d14c8STreehugger Robot BLOCK_IS_GC = (1 << 27),
37*7c3d14c8STreehugger Robot BLOCK_IS_GLOBAL = (1 << 28),
38*7c3d14c8STreehugger Robot };
39*7c3d14c8STreehugger Robot
40*7c3d14c8STreehugger Robot struct byref_id {
41*7c3d14c8STreehugger Robot struct byref_id *forwarding;
42*7c3d14c8STreehugger Robot int flags;//refcount;
43*7c3d14c8STreehugger Robot int size;
44*7c3d14c8STreehugger Robot void (*byref_keep)(struct byref_id *dst, struct byref_id *src);
45*7c3d14c8STreehugger Robot void (*byref_destroy)(struct byref_id *);
46*7c3d14c8STreehugger Robot int var;
47*7c3d14c8STreehugger Robot };
48*7c3d14c8STreehugger Robot struct Block_basic2 {
49*7c3d14c8STreehugger Robot void *isa;
50*7c3d14c8STreehugger Robot int Block_flags; // int32_t
51*7c3d14c8STreehugger Robot int Block_size; // XXX should be packed into Block_flags
52*7c3d14c8STreehugger Robot void (*Block_invoke)(void *);
53*7c3d14c8STreehugger Robot void (*Block_copy)(void *dst, void *src);
54*7c3d14c8STreehugger Robot void (*Block_dispose)(void *);
55*7c3d14c8STreehugger Robot struct byref_id *ref;
56*7c3d14c8STreehugger Robot };
57*7c3d14c8STreehugger Robot
sanity(void * arg)58*7c3d14c8STreehugger Robot void sanity(void *arg) {
59*7c3d14c8STreehugger Robot struct Block_basic2 *bb = (struct Block_basic2 *)arg;
60*7c3d14c8STreehugger Robot if ( ! (bb->Block_flags & BLOCK_HAS_COPY_DISPOSE)) {
61*7c3d14c8STreehugger Robot printf("missing copy/dispose helpers for byref data\n");
62*7c3d14c8STreehugger Robot exit(1);
63*7c3d14c8STreehugger Robot }
64*7c3d14c8STreehugger Robot struct byref_id *ref = bb->ref;
65*7c3d14c8STreehugger Robot if (ref->forwarding != ref) {
66*7c3d14c8STreehugger Robot printf("forwarding pointer should be %p but is %p\n", ref, ref->forwarding);
67*7c3d14c8STreehugger Robot exit(1);
68*7c3d14c8STreehugger Robot }
69*7c3d14c8STreehugger Robot }
70*7c3d14c8STreehugger Robot #endif
71*7c3d14c8STreehugger Robot
72*7c3d14c8STreehugger Robot
73*7c3d14c8STreehugger Robot
74