Skip to content

Instantly share code, notes, and snippets.

@theoknock
Last active August 27, 2022 23:45
Show Gist options
  • Save theoknock/db22b4cc253cf49f26fe6e21f3655223 to your computer and use it in GitHub Desktop.
Save theoknock/db22b4cc253cf49f26fe6e21f3655223 to your computer and use it in GitHub Desktop.
Copying blocks (unfinished)
typedef const void (^ const __strong object_block)(const bool);
object_block object_blk = ^ (const bool b) {
printf("object_blk state == %s\n", (b) ? "TRUE" : "FALSE");
};
object_block object_blk_2 = ^ (const bool b) {
printf("object_blk_2 state == %s\n", (b) ? "TRUE" : "FALSE");
};
object_block object_blk_3 = ^ (const bool b) {
printf("object_blk_3 state == %s\n", (b) ? "TRUE" : "FALSE");
};
typedef const typeof(object_block *) retained_object;
object_block (^ const __strong object_block_store)(object_block) = ^ (object_block blk_ref) {
return ^ (retained_object retained_blk) {
Block_release(retained_blk);
return (object_block)*retained_blk;
}(Block_copy(&blk_ref));
};
static void (^(^objects_iterator)(const unsigned long))(object_block) = ^ (const unsigned long count) {
typedef typeof(const id *) retained_objects[count];
typeof(retained_objects) retained_objects_ptr[count];
return ^ (const id * _Nonnull retained_objects_t) {
static unsigned long object_index = 0;
return ^ (object_block object) {
^ (unsigned long * object_index_t) {
^ (const id * _Nonnull retained_objects_t) {
((object_block)(*((id * const)retained_objects_t + *object_index_t)))(*object_index_t % 2);
(*object_index_t = *object_index_t + 1);
}(^ const id * _Nonnull (const id * _Nonnull retained_objects_t) {
*((id * const)retained_objects_t + *object_index_t) = (id)(object_block_store(object));
printf("write pointer == %p\n", (*((id * const)retained_objects_t + *object_index_t)));
return (const id *)(retained_objects_t);
}((const id *)(retained_objects_t)));
}(&object_index);
};
}((const id *)&retained_objects_ptr);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment