Re: [pirate] Re: Python PMC's

2005-08-24 Thread Kevin Tew
I agree this following would be cool.
However in the general case this type of code inference is HARD to do.
I believe that the optimizations you are looking for would require a
combination of type inference and graph reduction.
PyPy may be the eventual answer.
Don't get me wrong, I think it is great and the long term goal.
As soon as we compile and run correctly, I'm all about optimizations.

Good Insight Michal,
Kevin,

Michal Wallace wrote:
 Hey Sam,
I agree with what you're saying in this
thread. This is slightly off topic, but
I wanted to point something out.

In general, python has so many places
where things have to be dynamic that you 
really can't know this kind of thing at 
compile time, especially if you allow for 
eval/exec, or if you allow the code to be 
used as a module. 

However if you treat the code as a closed 
system, *and* you have access to python at 
compile time, then we can optimize away a 
lot of these questions.

For example, in your original code:

  def f(x,y):
return y

  class Foo:
f = f
def g(self,y):
  return y

  foo = Foo()

  g=foo.g

  print f(0,1)
  print foo.f(2)
  print g(3)


Once you know how python works, it's *obvious* 
that this prints 1,2,3. I see no reason why the 
compiler couldn't figure this out up front just 
by walking the tree.

In fact, a good optimizing compiler would see the
return y lines and just get rid of those methods
completely. 

I'd like to allow for the ability to do certain 
optimizations like this up front, sacrificing 
flexibility for speed. I know there are many
programs that won't allow for this, but for the
ones that do, I'd like to be able to do a sort
of static compile like this. 

In other words, sometimes a python-like language
is a desirable thing. (But of course this should
all be optional so that we can also be 100%
python compatible)

Sincerely,
 
Michal J Wallace
Sabren Enterprises, Inc.
-
contact: [EMAIL PROTECTED]
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
-

___
pirate mailing list
[EMAIL PROTECTED]
http://cornerhost.com/mailman/listinfo/pirate
  



Re: [pirate] Re: Python PMC's

2005-08-24 Thread Michal Wallace
On Wed, 24 Aug 2005, Sam Ruby wrote:

[huge cut]
 
 Below is from the sample that Leo provided.
 
  #  print foo.f(2)
  
  # emulate python find_name, which checks attributes too
  push_eh m_nf
  $P0 = foo.f(2)
  clear_eh
  goto m_f
  m_nf:
  # getattribute would also check if __get__ is there
  $P1 = getattribute foo, f
  $P0 = foo.$P1(2)
  m_f:
  print_item $P0
  print_newline
 
 Note that the code above would need to be emitted for *every* method
 call, as there is no way of knowing at compile time what property you
 will get and how it is defined.


Hey Sam,

I agree with what you're saying in this
thread. This is slightly off topic, but
I wanted to point something out.

In general, python has so many places
where things have to be dynamic that you 
really can't know this kind of thing at 
compile time, especially if you allow for 
eval/exec, or if you allow the code to be 
used as a module. 

However if you treat the code as a closed 
system, *and* you have access to python at 
compile time, then we can optimize away a 
lot of these questions.

For example, in your original code:

  def f(x,y):
return y

  class Foo:
f = f
def g(self,y):
  return y

  foo = Foo()

  g=foo.g

  print f(0,1)
  print foo.f(2)
  print g(3)


Once you know how python works, it's *obvious* 
that this prints 1,2,3. I see no reason why the 
compiler couldn't figure this out up front just 
by walking the tree.

In fact, a good optimizing compiler would see the
return y lines and just get rid of those methods
completely. 

I'd like to allow for the ability to do certain 
optimizations like this up front, sacrificing 
flexibility for speed. I know there are many
programs that won't allow for this, but for the
ones that do, I'd like to be able to do a sort
of static compile like this. 

In other words, sometimes a python-like language
is a desirable thing. (But of course this should
all be optional so that we can also be 100%
python compatible)

Sincerely,
 
Michal J Wallace
Sabren Enterprises, Inc.
-
contact: [EMAIL PROTECTED]
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
-