Re: Mr Parrot's Neighborhood
At 1:46 PM -0500 1/13/04, Melvin Smith wrote: At 11:18 PM 1/12/2004 -0500, Michal Wallace wrote: On Mon, 12 Jan 2004, Luke Palmer wrote: A continuation is one snapshot -- it never changes, it never runs. To invoke the continuation is to take you back to that snapshot and start running from there. To invoke it a second time is exactly like invoking it the first time. Thanks. I'd heard this a million times but putting it this way made it click for me. One important addition: While continuations are snapshots of execution context (execution path and variables), they are not snapshots of values. References to globals or lexicals will be restored as the snapshot, but their values can change. As will references to strings and PMCs that are on the stacks but not in globals or lexicals. Unfortunately ints and floats on the stacks *are* snapshots, which is somewhat problematic in some cases. -- Dan --it's like this--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: Mr Parrot's Neighborhood
At 3:56 PM + 1/13/04, Tim Bunce wrote: On Tue, Jan 13, 2004 at 10:01:32AM +0100, Leopold Toetsch wrote: Michal Wallace [EMAIL PROTECTED] wrote: Here's my guess: [lots of good stuff from leo] Is there a Parrot Architecture Overview document that summarises this kind of high-level view with links to the deeper docs? If not it would be great to have. I'll see if I can dig up some text to put in. I've written the doc a dozen times or more so far, but it's all been in presentations and articles. (It's going to be a documentation week, I can tell) I'll assume everyone (including CVS) can handle PNG images, since I think I may need some diagrams. -- Dan --it's like this--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: Mr Parrot's Neighborhood
Michal Wallace [EMAIL PROTECTED] wrote: A .pcc_sub isn't an object, just a little segment of the list of instructions. A pcc_sub *is* an object: find_global P0, _the_sub invokecc print back\n end .pcc_sub _the_sub: print in sub\n invoke P1 You can store it away, pass it around and so on. My problem is that I don't know what a Control stack, pad stack, user stack, and warnings are. Here's my guess: ControlStack { This is another set of smaller papers. One box each. if Mr. Parrot meets a ret op, he takes the top sheet and goes to whatever address is on it. Yes, its used for C-like function calls, where the return address is on the control stack. But more importantly: the control stack has exception handlers on it. If you install an exception handler, its pushed onto the control stack. If an exception is thrown, the handler is popped off that stack and control transfers to the handler subroutine. When we call a Sub, we write the return address on the top sheet. Same with a closure. No. Subs and Closures are invoked, no control stack is involved ** I don't understand what happens here when we call a continuation. Same here. PadStack { Hmm. Does this mean lexical pads? Yep. C { my $i; } would create/push a new lexical pad with that variable name inside. UserStack { By process of elimination, this would be the eight register stacks? No. Its an intermediate store to save registers. Its used: a) for C-style function calls b) to get at return results, if the caller did save all 32 registers: pushp # save P0..P31 to register frame invoke # call a sub - result in P5 save P5 # save P5 onto user stack popp# restore P0-P31 from register frames restore P5 # pop off result from user stack Warnings { ** Beats me. Is this for holding exception handlers? This are the warning flags. When you call a sub and that turns off warnings, the warning flags are restored to the original state, when the sub returns. Final questions: What's a context? The context holds pointers to all these stacks and structures. The semantics of the different Sub types define, how to deal with items in the context. E.g. a Closure has the callers pad stack in its context, so that a Closure can access lexicals of the caller. How would I picture Eval? Does that involve building new houses? A new street with new houses. For a sub, he just writes a return address on the control stack No, not for Parrot Calling Conventions. A Sub is an object. Again: We have 2 calling conventions: 1) C-style 2) PCC Only 1) is using return addresses pushed onto the Control Stack. The class tree in subs.pod is confusing to me: Sub Closure Continuation Coroutine Eval RetContinuation These are all for 2) - no pushed return address is involved. Michal J Wallace leo
Re: Mr Parrot's Neighborhood
On Tue, Jan 13, 2004 at 10:01:32AM +0100, Leopold Toetsch wrote: Michal Wallace [EMAIL PROTECTED] wrote: Here's my guess: [lots of good stuff from leo] Is there a Parrot Architecture Overview document that summarises this kind of high-level view with links to the deeper docs? If not it would be great to have. Tim.
Re: Mr Parrot's Neighborhood
At 11:18 PM 1/12/2004 -0500, Michal Wallace wrote: On Mon, 12 Jan 2004, Luke Palmer wrote: A continuation is one snapshot -- it never changes, it never runs. To invoke the continuation is to take you back to that snapshot and start running from there. To invoke it a second time is exactly like invoking it the first time. Thanks. I'd heard this a million times but putting it this way made it click for me. One important addition: While continuations are snapshots of execution context (execution path and variables), they are not snapshots of values. References to globals or lexicals will be restored as the snapshot, but their values can change. -Melvin
Mr Parrot's Neighborhood
On Mon, 12 Jan 2004, Luke Palmer wrote: Well... A Coroutine is a pausable, resumable continuation, right? Or basically a closure with a continuation inside it. Both of those sentences seem wildly redundant to me. I think we might be stuck on vocabulary. We're surely both understanding the same thing in different ways. Yes. I was understanding it in the wrong way. :) A continuation is one snapshot -- it never changes, it never runs. To invoke the continuation is to take you back to that snapshot and start running from there. To invoke it a second time is exactly like invoking it the first time. Thanks. I'd heard this a million times but putting it this way made it click for me. I've been thinking about continuations as if they were like python functions. In python, functions are objects. You can define them interactively at the prompt and then look inside them and see some representation of their bytecode. But with parrot, there's just one big long line of instructions. A .pcc_sub isn't an object, just a little segment of the list of instructions. Okay... Here's a metaphor I'm working on to try and help me understand how to picture all this. It's not finished (see the end). Feedback appreciated: === MR PARROT'S NEIGHBORHOOD Mr Parrot lives on a very long street. Each house on the street contains an opcode. His job is to go door to door and follow the instructions of the little ops. Mr Parrot carries with him as much paper as he can carry. Each sheet has 16 boxes on it, and he has eight different stacks of them: int 0..15 int 16..31 num 0..15 num 16..31 str 0..15 str 16..31 # should be string, I know pmc 0..15 pmc 16..31 He also has about a zillion pockets on him. He can put things in his pockets (and of course keep track of where they are by writing it down in a pmc box). Every once in a while, he goes through his pockets and throws out anything he doesn't need anymore. So starts at the first address, performs the instruction, and then goes to whatever that opcode says. She might ask him to write a number down in one of the boxes (set I0, 3) or to copy one box to another (set I0, I1) or an object to keep track of, or something equally simple. Usually when he's done with the op, he just goes next door, but sometimes the op tells him to go somewhere else, either explicitly (goto label) or based on the values in the boxes (le I0, I1, label) or the objects in his pockets (le P0, P1, label). Often, an op will tell him to copy the top sheet on one (or some or all) of the stacks and put the copy on top (push) or throw away the top sheet (pop). He gets really mad if you tell him to throw away the last sheet, or if a stack gets so big he can't carry it anymore. Every once in a while, the op will tell Mr. Parrot to do something like this: - make copies of all your stacks of paper - put the copies inside a briefcase - write this delivery address on the briefcase - (possibly) write a return address on the briefcase - put the briefcase in your pocket Is that an accurate portrayal of a continuation? ## Now... I only described the register stacks. In docs/pmc/subs.pod it lays out the differences between the different kinds of Subs. It has this table: Subtype ControlstackPadStack UserStack Warnings Sub- - - C Closure- C - C Continuation C C C C Coroutine C C C C RetContinuationX X X X C ... COWed copy is in context X ... is in context - ... isn't. My problem is that I don't know what a Control stack, pad stack, user stack, and warnings are. Here's my guess: ControlStack { This is another set of smaller papers. One box each. if Mr. Parrot meets a ret op, he takes the top sheet and goes to whatever address is on it. When we call a Sub, we write the return address on the top sheet. Same with a closure. ** I don't understand what happens here when we call a continuation. } PadStack { Hmm. Does this mean lexical pads? In which case, it's a list of friendly names that he uses to remind him which box or pocket a particular thing is in. } UserStack { By process of elimination, this would be the eight register stacks? } Warnings { ** Beats me. Is this for holding exception handlers? } Final questions: What's a context? How would I picture Eval? Does that involve building new houses? A coroutine is like a variable that holds continuations, and updates itself whenever it yields. I guess that's the best way I can put it with my affliction