vetriselvi / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

Compile functions that don't need actual arguments #68

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I think we can compile the uncalled function when the type inference can 
be successfully finished, e.g. from the default parameters

jason-sles11-64:~/tools/shedskin-r1442 # cat test1.py
print 'hello, world!'

class aclass(object):
        def __init__ (self):
                print 'test init'
        def hello(self):
                print 'haha'
jason-sles11-64:~/tools/shedskin-r1442 # shedskin -e test1.py
*** SHED SKIN Python-to-C++ Compiler 0.5 ***
Copyright 2005-2010 Mark Dufour; License GNU GPL version 3 (See LICENSE)

[iterative type analysis..]
**
iterations: 2 templates: 35
[generating c++ code..]
*WARNING* test1.py:6: function (class aclass, 'hello') not called!
*WARNING* test1.py:4: function (class aclass, '__init__') not called!
jason-sles11-64:~/tools/shedskin-r1442 # make
g++  -O2 -msse2 -fomit-frame-pointer -pipe -Wno-deprecated  -I. -
I/usr/local/lib/python2.6/site-packages/shedskin/lib -g -fPIC -D__SS_BIND -
I/usr/local/include/python2.6 -I/usr/local/include/python2.6 
test1.cpp /usr/local/lib/python2.6/site-
packages/shedskin/lib/builtin.cpp /usr/local/lib/python2.6/site-
packages/shedskin/lib/re.cpp -lgc -lpcre  -shared -Xlinker -export-
dynamic -lpthread -ldl  -lutil -lm -lpython2.6 -
L/usr/local/lib/python2.6/config -o test1.so
jason-sles11-64:~/tools/shedskin-r1442 # python
Python 2.6.5 (r265:79063, May  6 2010, 18:09:23)
[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "/etc/pythonstart", line 7, in <module>
    import readline
ImportError: No module named readline
>>> import test1
hello, world!
>>> a=test1.aclass()
>>> a
<test1.aclass object at 0x7f0f2a1b00d8>
>>> a.hello()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'test1.aclass' object has no attribute 'hello'
>>>

Original issue reported on code.google.com by jason.mi...@gmail.com on 6 May 2010 at 2:04

GoogleCodeExporter commented 9 years ago
interesting suggestion, thanks. I'm not sure if it's possible, and it would 
only work
for a limited number of cases, but I will think about it a bit..

Original comment by mark.duf...@gmail.com on 7 May 2010 at 9:30

GoogleCodeExporter commented 9 years ago
marking this a defect. if a function can be called without actual arguments, I 
guess we should always try and compile it.

Original comment by mark.duf...@gmail.com on 27 Oct 2010 at 1:30

GoogleCodeExporter commented 9 years ago

Original comment by mark.duf...@gmail.com on 27 Oct 2010 at 2:14

GoogleCodeExporter commented 9 years ago

Original comment by mark.duf...@gmail.com on 27 Oct 2010 at 2:15

GoogleCodeExporter commented 9 years ago

Original comment by mark.duf...@gmail.com on 25 Jun 2011 at 8:15