Jump to content
  • Advertisement
Sign in to follow this  
daerid

Python (or python-like) to Native code?

This topic is 5408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was just checking out boo and OCaml and was wondering... Boo compiles down to MSIL to be run by the .NET runtime. OCaml compiles down to byte-code, but can also be compiled down to native machine code. Couldn't the same concepts be used to compile a Python-like language down to native code? Sure, you'd lose a lot of core language features, but then again, it wouldn't really be Python, more Python-inspired. Comments?

Share this post


Link to post
Share on other sites
Advertisement
Technically, it's possible, but since pretty much everything in python is dynamic it wouldn't be as fast as you might think--I'd say less than twice as fast. If you're trying to make your python program run faster you might want to look into psyco. If you want to compile it to bytecode so you're users don't need the interpretter, you're outa luck :/ The closest thing would be py2exe, which doesn't compile it, but it bundles everything your program requires into one handy exe for Windows. People with unix usually have python already installed, so you don't have to worry about them.

Share this post


Link to post
Share on other sites
I'm not trying to make my python programs run faster, I'm trying to use a python-like syntax to compile a program to native x86 code (specifically, a Win32 PE) that doesn't require a runtime to execute.

I'm not saying make Python natively compilable. I'm talking about a language that compiles down to native x86 code that has a python-inspired syntax

Share this post


Link to post
Share on other sites
Quote:
Original post by daerid
Couldn't the same concepts be used to compile a Python-like language down to native code?
Aren't boo and OCaml proof of concept already?

I don't get it. What exactly do you want to do? Syntax is a non-issue; the reason Python isn't currently compiled to native code is a combination of its reliance on a runtime and facility: it was easier to implement a portable bytecode environment than to optimize compilers for various architectures.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Quote:
Original post by daerid
Couldn't the same concepts be used to compile a Python-like language down to native code?
Aren't boo and OCaml proof of concept already?

I don't get it. What exactly do you want to do? Syntax is a non-issue; the reason Python isn't currently compiled to native code is a combination of its reliance on a runtime and facility: it was easier to implement a portable bytecode environment than to optimize compilers for various architectures.


My main reasoning is that I write a lot of quick and dirty utilities, and I'd prefer to do it in a language that's similar to python's. However, I don't want to have to jump through hoops to get these programs to run on any other machine. I just want to write code, compile to .exe, copy to target machine and go.

Share this post


Link to post
Share on other sites
There's no reason it couldn't be done. It's just a matter of somebody itching enough to exert the (considerable) effort of scratching. :)

I have some ideas for exactly such a thing, but, alas, time is finite. (maybe I can weasel it in by implementing it as a credit for class)

In the meantime, you can try IronPython, which is currently only alpha, but can create .NET executables which are as freestanding as .NET gets.

Share this post


Link to post
Share on other sites
Quote:
Original post by daerid
However, I don't want to have to jump through hoops to get these programs to run on any other machine. I just want to write code, compile to .exe, copy to target machine and go.
So if speed isn't really the issue here, why not just use py2exe?

Share this post


Link to post
Share on other sites
Quote:
Original post by bytecoder
Technically, it's possible, but since pretty much everything in python is dynamic it wouldn't be as fast as you might think--I'd say less than twice as fast. [...]
Lisp is pretty dynamic (iirc more so than python) and there are very good compilers(in the speed sense - imo they are lacking in other ways but that is another discussion) for it. It just takes tons of work such that very very few good compilers are free.

Share this post


Link to post
Share on other sites
Quote:
Original post by civguy
Quote:
Original post by daerid
However, I don't want to have to jump through hoops to get these programs to run on any other machine. I just want to write code, compile to .exe, copy to target machine and go.
So if speed isn't really the issue here, why not just use py2exe?


Because I followed the directions to a T, and ended up with an .exe that wouldn't run when I dropped it onto a fresh Windows 2000 server.

Besides, people... I don't necessarily want dynamic. I just want something that looks like Python, that's functional and has type-inferrence. Hmm... I'm going to see if I can't whip up a design spec.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!