Re: Lexical variables, scratchpads, closures, ...

2002-08-04 Thread Jerome Vouillon
On Fri, Aug 02, 2002 at 09:06:31PM +0100, Nicholas Clark wrote: On Fri, Aug 02, 2002 at 06:43:49PM +0200, Jerome Vouillon wrote: Allocating a hash will certainly remain a lot more expensive than allocating an array. And we are going to allocate pads pretty often... Are we? Or are we

Re: Lexical variables, scratchpads, closures, ...

2002-08-03 Thread Simon Cozens
[EMAIL PROTECTED] (Dave Mitchell) writes: Or would that make access by name too slow? It's how Perl5 does it (very roughly speaking) This is a reminder that people new to developing VMs may find it useful to leaf through http://www.netthink.co.uk/downloads/internals.pdf and

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Jerome Vouillon
On Thu, Aug 01, 2002 at 10:57:34AM -0700, Sean O'Rourke wrote: My naive implementation would have an array of hashes for each sub, with one entry for each level of scope within. I would use an array of arrays or a linked-list of arrays. This is hardly more difficult to implement (you just

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Nicholas Clark
On Fri, Aug 02, 2002 at 05:20:45PM +0200, Jerome Vouillon wrote: On Thu, Aug 01, 2002 at 10:57:34AM -0700, Sean O'Rourke wrote: My naive implementation would have an array of hashes for each sub, with one entry for each level of scope within. I would use an array of arrays or a

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Sean O'Rourke
On Fri, 2 Aug 2002, Jerome Vouillon wrote: On Thu, Aug 01, 2002 at 10:57:34AM -0700, Sean O'Rourke wrote: My naive implementation would have an array of hashes for each sub, with one entry for each level of scope within. I would use an array of arrays or a linked-list of arrays. This is

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Jerome Vouillon
On Fri, Aug 02, 2002 at 08:50:27AM -0700, Sean O'Rourke wrote: On Fri, 2 Aug 2002, Jerome Vouillon wrote: On Thu, Aug 01, 2002 at 10:57:34AM -0700, Sean O'Rourke wrote: My naive implementation would have an array of hashes for each sub, with one entry for each level of scope within.

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Sean O'Rourke
On Fri, 2 Aug 2002, Melvin Smith wrote: At 08:50 AM 8/2/2002 -0700, Sean O'Rourke wrote: Without performance numbers, this is hard to test, but it can potentially turn a single a = b + c, which is just add P0, P1, P2 if a, b, and c have been referenced, into a hideous five instructions:

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Melvin Smith
At 06:14 PM 8/1/2002 +0200, Jerome Vouillon wrote: Melvin, I think it would really help if you could explain us how you would compile this code. Also, you should describe precisely what invoke and new_pad (and maybe the other scratchpad-related opcodes) do as far as scratchpads are concerned.

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Melvin Smith
At 08:50 AM 8/2/2002 -0700, Sean O'Rourke wrote: Without performance numbers, this is hard to test, but it can potentially turn a single a = b + c, which is just add P0, P1, P2 if a, b, and c have been referenced, into a hideous five instructions: fetch_lex P0, 'a' # Because how we store

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Jonathan Sillito
On Fri, 2002-08-02 at 10:43, Jerome Vouillon wrote: Sure, you need a hash. But this can be a statically allocated hash, mapping variable names to indices. Could two parallel arrays work? One stores the lexicals (accessed by index) and the other stores the names of the lexicals. Then to access

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Dave Mitchell
On Fri, Aug 02, 2002 at 11:15:09AM -0600, Jonathan Sillito wrote: Could two parallel arrays work? One stores the lexicals (accessed by index) and the other stores the names of the lexicals. Then to access a lexical by name involves a sequential search through the (probably not large) array of

Re: Lexical variables, scratchpads, closures, ...

2002-08-02 Thread Melvin Smith
At 06:14 PM 8/1/2002 +0200, Jerome Vouillon wrote: On Wed, Jul 31, 2002 at 11:40:39AM -0600, Jonathan Sillito wrote: So here is my take on a slightly simpler example: sub foo { my $x = 13; return sub { print $x\n; }; } $foo() Melvin, I think it would really help if

Re: Lexical variables, scratchpads, closures, ...

2002-08-01 Thread Jerome Vouillon
On Wed, Jul 31, 2002 at 11:22:56PM -0400, Melvin Smith wrote: At 06:25 PM 7/31/2002 +0200, Jerome Vouillon wrote: Closures A subroutine must have access to the scratchpads of all the englobing blocks. As the scratchpads are linked, it is sufficient to add a pointer to the

Re: Lexical variables, scratchpads, closures, ...

2002-08-01 Thread Jerome Vouillon
On Wed, Jul 31, 2002 at 11:40:39AM -0600, Jonathan Sillito wrote: So here is my take on a slightly simpler example: sub foo { my $x = 13; return sub { print $x\n; }; } $foo() Melvin, I think it would really help if you could explain us how you would compile this code.

Re: Lexical variables, scratchpads, closures, ...

2002-08-01 Thread Melvin Smith
Jerome Vouillon writes: On Wed, Jul 31, 2002 at 11:22:56PM -0400, Melvin Smith wrote: At 06:25 PM 7/31/2002 +0200, Jerome Vouillon wrote: Closures A subroutine must have access to the scratchpads of all the englobing blocks. As the scratchpads are linked, it is sufficient to add a

Re: Lexical variables, scratchpads, closures, ...

2002-08-01 Thread Sean O'Rourke
On Thu, 1 Aug 2002, Jerome Vouillon wrote: On Wed, Jul 31, 2002 at 11:22:56PM -0400, Melvin Smith wrote: We chose to implement the access as ops, and you prefer using a PMC Array directly. I can at least see one advantage to the explicit ops: they don't require a register to use them in

Re: Lexical variables, scratchpads, closures, ...

2002-08-01 Thread Sean O'Rourke
On Thu, 1 Aug 2002, Melvin Smith wrote: Jerome Vouillon writes: On Wed, Jul 31, 2002 at 11:22:56PM -0400, Melvin Smith wrote: And they need to be COW, as closures have access to their own copies of lexicals. I asked Jonathan to reuse the stack code I had already written because it was

Re: Lexical variables, scratchpads, closures, ...

2002-08-01 Thread Dan Sugalski
At 11:22 PM -0400 7/31/02, Melvin Smith wrote: Conclusion It seems to me that to implement lexical variables, we only need to implement the set_pmc method and to extend the Sub class so that it contains both a code pointer and a scratchpad. I agree with you. It can be done without

Lexical variables, scratchpads, closures, ...

2002-07-31 Thread Jerome Vouillon
Let us think a bit about the implementation of lexical variables. Assignement First, let us consider how to compile a variable assignement such as: $x = $y where both $x and $y are lexical variables. At first, one may think that this can be compiled simply into a register

Re: Lexical variables, scratchpads, closures, ...

2002-07-31 Thread Jonathan Sillito
On Wed, 2002-07-31 at 10:25, Jerome Vouillon wrote: Let us think a bit about the implementation of lexical variables. Thanks for spelling this out in such detail. Here is a variation based on the lexical ops (new_pad, pop_pad, store_lex, find_lex) committed yesterday. Note that lexical pads

Re: Lexical variables, scratchpads, closures, ...

2002-07-31 Thread Jonathan Sillito
On Wed, 2002-07-31 at 13:49, Jerome Vouillon wrote: On Wed, Jul 31, 2002 at 11:40:39AM -0600, Jonathan Sillito wrote: new_pad # push this on the lexical stack # some constant descriptor should also be passed # to the new_pad op which would then know about

Re: Lexical variables, scratchpads, closures, ...

2002-07-31 Thread Melvin Smith
At 06:25 PM 7/31/2002 +0200, Jerome Vouillon wrote: Scratchpads We need to allocate an area in the heap for each lexical variable. Instead of allocating this area one variable at a time, we can allocate a single scratchpad value for all variables of a block: this is more efficient.