| 1 | package SPVM::Resource::Coro; | ||
| 2 | |||
| 3 | 1 | our $VERSION = "0.002"; | |
| 4 | |||
| 5 | 1 | 1; | |
| 6 | |||
| 7 | =encoding utf8 | ||
| 8 | |||
| 9 | =head1 Name | ||
| 10 | |||
| 11 | SPVM::Resource::Coro - libcoro Resources | ||
| 12 | |||
| 13 | =head1 Description | ||
| 14 | |||
| 15 | Resource::Coro class in L<SPVM> is a L<resource|SPVM::Document::Resource> class for libcoro. | ||
| 16 | |||
| 17 | =head1 Usage | ||
| 18 | |||
| 19 | MyClass.config: | ||
| 20 | |||
| 21 | my $config = SPVM::Builder::Config->new_c99; | ||
| 22 | |||
| 23 | $config->use_resource('Resource::Coro'); | ||
| 24 | |||
| 25 | $config->add_define(@{$config->get_resource('Resource::Coro')->config->defines}); | ||
| 26 | |||
| 27 | $config; | ||
| 28 | |||
| 29 | MyClass.c: | ||
| 30 | |||
| 31 | #include "spvm_native.h" | ||
| 32 | #include "coro.h" | ||
| 33 | |||
| 34 | int32_t SPVM__MyClass__test(SPVM_ENV* env, SPVM_VALUE* stack) { | ||
| 35 | |||
| 36 | coro_context ctx; | ||
| 37 | |||
| 38 | return 0; | ||
| 39 | } | ||
| 40 | |||
| 41 | =head1 Original Product | ||
| 42 | |||
| 43 | L<libcoro|http://software.schmorp.de/pkg/libcoro.html> | ||
| 44 | |||
| 45 | =head1 Original Product Version | ||
| 46 | |||
| 47 | Use the code bundled in L<Coro 6.57|https://metacpan.org/release/MLEHMANN/Coro-6.57> on CPAN. | ||
| 48 | |||
| 49 | =head1 Language | ||
| 50 | |||
| 51 | C language | ||
| 52 | |||
| 53 | =head1 Language Standard | ||
| 54 | |||
| 55 | C99 | ||
| 56 | |||
| 57 | =head1 Header Files | ||
| 58 | |||
| 59 | =over 2 | ||
| 60 | |||
| 61 | =item * C<coro.h> | ||
| 62 | |||
| 63 | =back | ||
| 64 | |||
| 65 | =head1 Source Files | ||
| 66 | |||
| 67 | =over 2 | ||
| 68 | |||
| 69 | =item * C<coro.c> | ||
| 70 | |||
| 71 | =back | ||
| 72 | |||
| 73 | =head1 Compiler Flags | ||
| 74 | |||
| 75 | The compiler flags are automatically configured based on the OS and its environment to ensure the correct context switching mechanism (e.g., C, C<setjmp/longjmp>, or C). | ||
| 76 | |||
| 77 | Typical flags include: | ||
| 78 | |||
| 79 | =over 2 | ||
| 80 | |||
| 81 | =item * C<-DCORO_UCONTEXT> (used when C<ucontext.h> is available) | ||
| 82 | |||
| 83 | =item * C<-DCORO_SJLJ> (used for C<setjmp/longjmp> based switching) | ||
| 84 | |||
| 85 | =item * C<-DCORO_ASM> (used for assembly-based switching) | ||
| 86 | |||
| 87 | =item * C<-DCORO_PTHREAD> (used when C are required) | ||
| 88 | |||
| 89 | =item * C<-D_FORTIFY_SOURCE=0> (often required for C<setjmp/longjmp> stability) | ||
| 90 | |||
| 91 | =back | ||
| 92 | |||
| 93 | The actual flags applied are determined at build-time by detecting the target platform and specific system requirements (such as thread support and stack alignment). | ||
| 94 | |||
| 95 | Flags starting with C<-D> can be retrieved from C<defines> field without the -D prefix. | ||
| 96 | |||
| 97 | =head1 How to Create Resource | ||
| 98 | |||
| 99 | =head2 Donwload | ||
| 100 | |||
| 101 | mkdir -p .tmp | ||
| 102 | curl -L https://cpan.metacpan.org/authors/id/M/ML/MLEHMANN/Coro-6.57.tar.gz | tar -xz -C .tmp | ||
| 103 | |||
| 104 | =head2 Extracting Source Files | ||
| 105 | |||
| 106 | cp .tmp/Coro-6.57/Coro/libcoro/coro.h lib/SPVM/Resource/Coro.native/include/ | ||
| 107 | |||
| 108 | =head2 Extracting Header Files | ||
| 109 | |||
| 110 | cp .tmp/Coro-6.57/Coro/libcoro/coro.c lib/SPVM/Resource/Coro.native/src/ | ||
| 111 | |||
| 112 | =head2 Apply Patch | ||
| 113 | |||
| 114 | patch -p1 < coro_fix.patch | ||
| 115 | |||
| 116 | =head1 Repository | ||
| 117 | |||
| 118 | L<SPVM::Resource::Coro - Github|https://github.com/yuki-kimoto/SPVM-Resource-Coro> | ||
| 119 | |||
| 120 | =head1 Author | ||
| 121 | |||
| 122 | Yuki Kimoto C<kimoto.yuki@gmail.com> | ||
| 123 | |||
| 124 | =head1 Copyright & License | ||
| 125 | |||
| 126 | Copyright (c) 2026 Yuki Kimoto | ||
| 127 | |||
| 128 | MIT License | ||
| 129 |