Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Callstack manipulation?

by plobsing (Friar)
on Nov 02, 2008 at 04:02 UTC ( [id://720918]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Callstack manipulation?
in thread Callstack manipulation?

I'm sorry, I don't really know Coro all that well. Consulting the docs, it says that a coroutine consists of:

  • a callchain
  • a set of lexical variables
  • a C stack
  • @_, $_, $@, and $/

Everything else is shared. I don't see how you could get around having the first three items kept seperate. The fourth item is likely to be small compared to the others.

In terms of actually cloning the perl interpreter, a quick test (given bellow) shows that a new callchain is created rather than cloning the current one. So I guess I wouldn't describe the action as cloning

Some benchmarking would probably be worthwhile to determine how much Coro actually costs in terms of time and space required. From there you can determine whether or not Coro is practical or not for your problem.

use strict; use warnings; use Carp 'carp'; use Coro; $\ = $/; sub A { my $a = 1; async { print $a++; carp; cede; print $a++; } print $a++; carp; cede; print $a++; } A;

Replies are listed 'Best First'.
Re^4: Callstack manipulation?
by LanX (Saint) on Nov 02, 2008 at 12:57 UTC
    Hi plobsing,

    thanks a lot for your help! : )

    I should mention that Moritz already implemented gather&take using coro http://search.cpan.org/~moritz/Perl6-GatherTake/ ...but he doesn't give the impression to be very convinced about the outcome.

    Nevertheless I just wanted to give a motivation for a more fundamental question:

    Are there any opcodes allowing to manipulate the call stack?

    Popping and pushing the stack gives an approach to a whole bunch of Assembler techniques (and pitfalls of course ;)

      > Are there any opcodes allowing to manipulate the call stack?

      Ok, at least one can manipulate the stack with XS, I found some examples in Advanced Perl Programming, describing macros to do so!

      8 )

      (over 10 years old but still an interesting read *)

      UPDATES:

    • Concerning coro: AFAIS the coroutines get separated lexical variable spaces, complicating a Gather/Take-Algorithm to access "surrounding" variables.
    • * I was talking about the first edition!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://720918]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found