Re: Source code generation using Python

2008-12-08 Thread Jorgen Grahn
On Sat, 6 Dec 2008 13:47:26 -0800 (PST), ats [EMAIL PROTECTED] wrote:
 Hello,

 This is my first posting to a Python group (and I'm starting with
 Python seriously only now) , so bear with me if I make some mistakes.

 I want to generate 3 different versions of a C++ source code,
 basically injecting different flavours of inline assembler depending
 on target compiler/CPU.

 Code generation should be integrated into a 'master source file' which
 is the processed and generates the right code for GCC / MSVC or other
 cases. Something like:

   int FastAdd( int t1, int t2 ){
 int r;
 ##if USE_INLINE_ASM
   #ARG( eax, t1)
   #ARG( ebx, t2)
   #ASM( add, ebx, eax )
   #RES( eax, r )
 ##else
   r = t1+t2;
 ##endif
 return r;
   }

You didn't say explicitly, so I have to ask: is there a reason you
cannot use the C++ preprocessor? It does exactly what you describe,
and would be the least surprising solution to the readers.

/Jorgen

-- 
  // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se  R'lyeh wgah'nagl fhtagn!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Source code generation using Python

2008-12-07 Thread Alia Khouri
 Any suggestions?


I've happily used Cheetah with Leo (http://webpages.charter.net/
edreamleo/front.html) to organise and script my code generation needs,
but you may also be happy with cog (http://nedbatchelder.com/code/
cog/).

AK

--
http://mail.python.org/mailman/listinfo/python-list


Re: Source code generation using Python

2008-12-07 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

ats wrote:
 I want to generate 3 different versions of a C++ source code,
 basically injecting different flavours of inline assembler depending
 on target compiler/CPU.

Are you aware that there are also packages that let you generate and
call C code from Python on the fly?  I find it most productive to write
my code in all Python first and to also develop a comprehensive test
suite.  Then profile and replace selected portions with lower level C
code with the tests being able to confirm your code is correct.

Here are some packages that take an alternate approach:

http://www.cs.tut.fi/~ask/cinpy/
http://code.google.com/p/shedskin/
http://pyinline.sourceforge.net/
http://scipy.org/Weave
http://mdevan.nfshost.com/llvm-py/

I like LLVM the most.

Roger
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkk8MkUACgkQmOOfHg372QRhsgCcCUzWHAHmjC1490yYba7c9Xrt
DxMAnj/Ur2GoJkQgMrx65hYEqPwKLdVV
=CvGB
-END PGP SIGNATURE-

--
http://mail.python.org/mailman/listinfo/python-list


Source code generation using Python

2008-12-06 Thread ats
Hello,

This is my first posting to a Python group (and I'm starting with
Python seriously only now) , so bear with me if I make some mistakes.

I want to generate 3 different versions of a C++ source code,
basically injecting different flavours of inline assembler depending
on target compiler/CPU.

Code generation should be integrated into a 'master source file' which
is the processed and generates the right code for GCC / MSVC or other
cases. Something like:

  int FastAdd( int t1, int t2 ){
int r;
##if USE_INLINE_ASM
  #ARG( eax, t1)
  #ARG( ebx, t2)
  #ASM( add, ebx, eax )
  #RES( eax, r )
##else
  r = t1+t2;
##endif
return r;
  }

On processing, given constant USE_INLINE_ASM (or not) the right code
is generated to a target file, which goes into the build process.

I was looking for packages that can do this and came up with some
candidates:

 - empy - http://www.alcyone.com/pyos/empy/ - It looks like it could
do the job, but appears non-maintained since 2003.
- Cheetah - Looks like more of a tool to do fix replacements of code
snippets.

There is some logic going on in the ARG, ASM and RES sections,
so I need to link code generation with true Python functions.

The situation is really quite similar to HTML/PHP except, here we
would have C++/Python.

Any suggestions?

Thanks,
//Arne S.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Source code generation using Python

2008-12-06 Thread Philip Semanchuk


On Dec 6, 2008, at 4:47 PM, ats wrote:


Hello,

This is my first posting to a Python group (and I'm starting with
Python seriously only now) , so bear with me if I make some mistakes.

I want to generate 3 different versions of a C++ source code,
basically injecting different flavours of inline assembler depending
on target compiler/CPU.

Code generation should be integrated into a 'master source file' which
is the processed and generates the right code for GCC / MSVC or other
cases. Something like:

 int FastAdd( int t1, int t2 ){
   int r;
   ##if USE_INLINE_ASM
 #ARG( eax, t1)
 #ARG( ebx, t2)
 #ASM( add, ebx, eax )
 #RES( eax, r )
   ##else
 r = t1+t2;
   ##endif
   return r;
 }

On processing, given constant USE_INLINE_ASM (or not) the right code
is generated to a target file, which goes into the build process.

I was looking for packages that can do this and came up with some
candidates:

- empy - http://www.alcyone.com/pyos/empy/ - It looks like it could
do the job, but appears non-maintained since 2003.
- Cheetah - Looks like more of a tool to do fix replacements of code
snippets.


There is some logic going on in the ARG, ASM and RES sections,
so I need to link code generation with true Python functions.


Hi Arne,
There are *lots* of packages for Python that replace chunks of  
predefined templates. Most are HTML-focused, some more so than others.  
I've used Mako (http://www.makotemplates.org/) to generate both HTML  
and Apache config files. It could certainly do C++. Some alternatives  
to Mako are mentioned in the documentation -- Kid, Genshi and Cheetah.


Rather than invite a flame war as to which is a better templating  
engine, I'll just say that I'm happy with how Mako addresses *my*  
needs. =) Good luck finding something that addresses yours.


Cheers
Philip





The situation is really quite similar to HTML/PHP except, here we
would have C++/Python.

Any suggestions?

Thanks,
//Arne S.
--
http://mail.python.org/mailman/listinfo/python-list


--
http://mail.python.org/mailman/listinfo/python-list


Re: Source code generation using Python

2008-12-06 Thread ats
On Dec 6, 11:19 pm, Philip Semanchuk [EMAIL PROTECTED] wrote:
 On Dec 6, 2008, at 4:47 PM, ats wrote:



  Hello,

  This is my first posting to a Python group (and I'm starting with
  Python seriously only now) , so bear with me if I make some mistakes.

  I want to generate 3 different versions of a C++ source code,
  basically injecting different flavours of inline assembler depending
  on target compiler/CPU.

  Code generation should be integrated into a 'master source file' which
  is the processed and generates the right code for GCC / MSVC or other
  cases. Something like:

   int FastAdd( int t1, int t2 ){
     int r;
     ##if USE_INLINE_ASM
       #ARG( eax, t1)
       #ARG( ebx, t2)
       #ASM( add, ebx, eax )
       #RES( eax, r )
     ##else
       r = t1+t2;
     ##endif
     return r;
   }

  On processing, given constant USE_INLINE_ASM (or not) the right code
  is generated to a target file, which goes into the build process.

  I was looking for packages that can do this and came up with some
  candidates:

  - empy -http://www.alcyone.com/pyos/empy/- It looks like it could
  do the job, but appears non-maintained since 2003.
  - Cheetah - Looks like more of a tool to do fix replacements of code
  snippets.

  There is some logic going on in the ARG, ASM and RES sections,
  so I need to link code generation with true Python functions.

 Hi Arne,
 There are *lots* of packages for Python that replace chunks of  
 predefined templates. Most are HTML-focused, some more so than others.  
 I've used Mako (http://www.makotemplates.org/) to generate both HTML  
 and Apache config files. It could certainly do C++. Some alternatives  
 to Mako are mentioned in the documentation -- Kid, Genshi and Cheetah.

 Rather than invite a flame war as to which is a better templating  
 engine, I'll just say that I'm happy with how Mako addresses *my*  
 needs. =) Good luck finding something that addresses yours.

 Cheers
 Philip



  The situation is really quite similar to HTML/PHP except, here we
  would have C++/Python.

  Any suggestions?

  Thanks,
  //Arne S.
  --
 http://mail.python.org/mailman/listinfo/python-list



Thanks, Mako looks neat.

Regards
// Arne S.
--
http://mail.python.org/mailman/listinfo/python-list