ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/State.xs
(Generate patch)

Comparing Coro/Coro/State.xs (file contents):
Revision 1.16 by root, Wed Jul 25 04:26:55 2001 UTC vs.
Revision 1.19 by root, Sun Jul 29 01:11:41 2001 UTC

53 53
54 void *sptr; 54 void *sptr;
55 long ssize; /* positive == mmap, otherwise malloc */ 55 long ssize; /* positive == mmap, otherwise malloc */
56} coro_stack; 56} coro_stack;
57 57
58static coro_stack main_stack = { 1, 0, 0 };
59
60struct coro { 58struct coro {
61 /* the optional C context */ 59 /* the optional C context */
62 coro_stack *stack; 60 coro_stack *stack;
63 void *cursp; 61 void *cursp;
64 int gencnt; 62 int gencnt;
68 SV *defsv; 66 SV *defsv;
69 SV *errsv; 67 SV *errsv;
70 68
71 /* saved global state not related to stacks */ 69 /* saved global state not related to stacks */
72 U8 dowarn; 70 U8 dowarn;
71 I32 in_eval;
73 72
74 /* the stacks and related info (callchain etc..) */ 73 /* the stacks and related info (callchain etc..) */
75 PERL_SI *curstackinfo; 74 PERL_SI *curstackinfo;
76 AV *curstack; 75 AV *curstack;
77 AV *mainstack; 76 AV *mainstack;
95 I32 savestack_max; 94 I32 savestack_max;
96 OP **retstack; 95 OP **retstack;
97 I32 retstack_ix; 96 I32 retstack_ix;
98 I32 retstack_max; 97 I32 retstack_max;
99 COP *curcop; 98 COP *curcop;
100 JMPENV start_env;
101 JMPENV *top_env; 99 JMPENV *top_env;
102 100
103 /* data associated with this coroutine (initial args) */ 101 /* data associated with this coroutine (initial args) */
104 AV *args; 102 AV *args;
105}; 103};
290 288
291static void 289static void
292load_state(pTHX_ Coro__State c) 290load_state(pTHX_ Coro__State c)
293{ 291{
294 PL_dowarn = c->dowarn; 292 PL_dowarn = c->dowarn;
293 PL_in_eval = c->in_eval;
295 294
296 PL_curstackinfo = c->curstackinfo; 295 PL_curstackinfo = c->curstackinfo;
297 PL_curstack = c->curstack; 296 PL_curstack = c->curstack;
298 PL_mainstack = c->mainstack; 297 PL_mainstack = c->mainstack;
299 PL_stack_sp = c->stack_sp; 298 PL_stack_sp = c->stack_sp;
316 PL_savestack_max = c->savestack_max; 315 PL_savestack_max = c->savestack_max;
317 PL_retstack = c->retstack; 316 PL_retstack = c->retstack;
318 PL_retstack_ix = c->retstack_ix; 317 PL_retstack_ix = c->retstack_ix;
319 PL_retstack_max = c->retstack_max; 318 PL_retstack_max = c->retstack_max;
320 PL_curcop = c->curcop; 319 PL_curcop = c->curcop;
321 PL_start_env = c->start_env;
322 PL_top_env = c->top_env; 320 PL_top_env = c->top_env;
323 321
324 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); 322 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav);
325 if (c->defsv) REPLACE_SV (DEFSV , c->defsv); 323 if (c->defsv) REPLACE_SV (DEFSV , c->defsv);
326 if (c->errsv) REPLACE_SV (ERRSV , c->errsv); 324 if (c->errsv) REPLACE_SV (ERRSV , c->errsv);
425 /* but if it's missing the defav contents magically get replaced sometimes */ 423 /* but if it's missing the defav contents magically get replaced sometimes */
426 if (c->defav) 424 if (c->defav)
427 av_reify (c->defav); 425 av_reify (c->defav);
428 426
429 c->dowarn = PL_dowarn; 427 c->dowarn = PL_dowarn;
428 c->in_eval = PL_in_eval;
430 429
431 c->curstackinfo = PL_curstackinfo; 430 c->curstackinfo = PL_curstackinfo;
432 c->curstack = PL_curstack; 431 c->curstack = PL_curstack;
433 c->mainstack = PL_mainstack; 432 c->mainstack = PL_mainstack;
434 c->stack_sp = PL_stack_sp; 433 c->stack_sp = PL_stack_sp;
451 c->savestack_max = PL_savestack_max; 450 c->savestack_max = PL_savestack_max;
452 c->retstack = PL_retstack; 451 c->retstack = PL_retstack;
453 c->retstack_ix = PL_retstack_ix; 452 c->retstack_ix = PL_retstack_ix;
454 c->retstack_max = PL_retstack_max; 453 c->retstack_max = PL_retstack_max;
455 c->curcop = PL_curcop; 454 c->curcop = PL_curcop;
456 c->start_env = PL_start_env;
457 c->top_env = PL_top_env; 455 c->top_env = PL_top_env;
458} 456}
459 457
460/* 458/*
461 * allocate various perl stacks. This is an exact copy 459 * allocate various perl stacks. This is an exact copy
553 stack->usecnt = 1; 551 stack->usecnt = 1;
554 stack->gencnt = ctx->gencnt = 0; 552 stack->gencnt = ctx->gencnt = 0;
555 if (alloc) 553 if (alloc)
556 { 554 {
557#ifdef HAVE_MMAP 555#ifdef HAVE_MMAP
558 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write */ 556 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */
559 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0); 557 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
560 if (stack->sptr == (void *)-1) 558 if (stack->sptr == (void *)-1)
561#endif 559#endif
562 { 560 {
563 /*FIXME*//*D*//* reasonable stack size! */ 561 /*FIXME*//*D*//* reasonable stack size! */
605 dSP; 603 dSP;
606 Coro__State ctx = (Coro__State)arg; 604 Coro__State ctx = (Coro__State)arg;
607 SV *sub_init = (SV*)get_cv(SUB_INIT, FALSE); 605 SV *sub_init = (SV*)get_cv(SUB_INIT, FALSE);
608 606
609 coro_init_stacks (aTHX); 607 coro_init_stacks (aTHX);
610 JMPENV_BOOTSTRAP;
611 SPAGAIN;
612
613 /*PL_curcop = 0;*/ 608 /*PL_curcop = 0;*/
609 /*PL_in_eval = PL_in_eval;*/ /* inherit */
614 SvREFCNT_dec (GvAV (PL_defgv)); 610 SvREFCNT_dec (GvAV (PL_defgv));
615 GvAV (PL_defgv) = ctx->args; 611 GvAV (PL_defgv) = ctx->args;
616 612
613 SPAGAIN;
614
617 if (ctx->stack) 615 if (ctx->stack)
618 { 616 {
619 ctx->cursp = 0; 617 ctx->cursp = 0;
620 618
621 PUSHMARK(SP); 619 PUSHMARK(SP);
622 PUTBACK; 620 PUTBACK;
623 (void) call_sv (sub_init, G_VOID|G_NOARGS); 621 (void) call_sv (sub_init, G_VOID|G_NOARGS|G_EVAL);
622
623 if (SvTRUE (ERRSV))
624 croak (NULL);
625 else
624 croak ("FATAL: CCTXT coroutine returned!"); 626 croak ("FATAL: CCTXT coroutine returned!");
625 } 627 }
626 else 628 else
627 { 629 {
628 UNOP myop; 630 UNOP myop;
629 631
656 /* 658 /*
657 * this is a _very_ stripped down perl interpreter ;) 659 * this is a _very_ stripped down perl interpreter ;)
658 */ 660 */
659 Coro__State ctx = (Coro__State)arg; 661 Coro__State ctx = (Coro__State)arg;
660 662
663 /*FIXME*//* must set up top_env here */
661 ctx->cursp = 0; 664 ctx->cursp = 0;
662 PL_op = PL_op->op_next; 665 PL_op = PL_op->op_next;
663 CALLRUNOPS(aTHX); 666 CALLRUNOPS(aTHX);
664 /*NORETURN*/ 667
665 abort (); 668 abort ();
666} 669}
667 670
668STATIC void 671STATIC void
669transfer(pTHX_ struct coro *prev, struct coro *next, int flags) 672transfer(pTHX_ struct coro *prev, struct coro *next, int flags)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines