Re: Binary Decimals in Python
On 3/30/2010 11:13 AM, aditya wrote: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instead. Is this by design? It seems to me that this is not the correct behavior. Well technically that would be a 'radix point', not a decimal point. But I think the problem is that computers don't store fractional values that way internally. They either use floating or fixed point math. You would never look at raw binary data on a computer and see something like '1010.1010', and no one would write it that way, and no language (that I know of) would accept that as a valid value if you did something like x = 0b1010.1010 So in that sense, it might not be an intentional oversight, but it's not a very practical or useful feature. -- http://mail.python.org/mailman/listinfo/python-list
Re: Binary Decimals in Python
Doh! Well the problem is that int's are integers. So yeah, you can't even do that with normal value int ('2.1') will also throw an error. And floats don't support radix conversion, because no-one really writes numbers that way. (At least computer programmers...) On 3/30/2010 11:43 AM, Shashwat Anand wrote: The conversion is not supported for decimal integers AFAIK, however '0b123.456' is always valid. I guess you can always get a decimal number convertor onto Python-recipes On Tue, Mar 30, 2010 at 9:05 PM, Grant Olson k...@grant-olson.net mailto:k...@grant-olson.net wrote: On 3/30/2010 11:13 AM, aditya wrote: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instead. Is this by design? It seems to me that this is not the correct behavior. Well technically that would be a 'radix point', not a decimal point. But I think the problem is that computers don't store fractional values that way internally. They either use floating or fixed point math. You would never look at raw binary data on a computer and see something like '1010.1010', and no one would write it that way, and no language (that I know of) would accept that as a valid value if you did something like x = 0b1010.1010 So in that sense, it might not be an intentional oversight, but it's not a very practical or useful feature. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
ANN: Pyasm version 0.3
Pyasm is a full-featured dynamic assembler written entirely in Python. By dynamic, I mean that it can be used to generate and execute machine code in python at runtime without requiring the generation of object files and linkage. It essentially allow 'inline' assembly in python modules on x86 platforms. In addition, pyasm can generate COFF format object files, which may be of interest to anyone writing a compiler in python. More details and downloads are available at: http://www.grant-olson.net/python/pyasm The 0.3 release is long overdue. It includes: + A binary installer for python 2.6. The previous binary installer was python 2.4. + Automatic mapping of python structure values in the assembler. For Example, assuming EAX is a pointer to a string, MOV [EAX+PyString_ob_sval],0x42424242 will change the first four letters of the string to B's + The assembler now supports implicit string creation: PUSH 'foo\n\0' + The ability to build and test with the mingw toolset on windows. This previously required an MSVC toolset. Thanks to Markus Läll for sorting this out. -Grant -- http://mail.python.org/mailman/listinfo/python-list
Compyler 0.1
Compyler is a pre-alpha x86 native code compiler. So far it can generate primitive .pyds but not standalone executables. It can run some simple test cases including pystones (although there is a memory leak there). And no, I don't expect it'll ever be much faster than Cpython wink. I was primarily interested in being able to distribute low-footprint standalone executables written in python and code obfustication. The basic approach taken by compyler is to transliterate python bytecode into x86 assembly, instead of trying to generate assembly from the syntax tree. This is basically abandonware. I haven't touched this in six months, but did do a lot of up front work. I basically wanted to release it before my hardrive blows up in case anyone was looking for prior art. The code also contains a version of pyasm that has some more patches and features than the official distribution if you're one of pyasm's 3 users. More info can be found at: http://members.verizon.net/~olsongt/compyler/index.html -Grant -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Compyler 0.1
Compyler is a pre-alpha x86 native code compiler. So far it can generate primitive .pyds but not standalone executables. It can run some simple test cases including pystones (although there is a memory leak there). And no, I don't expect it'll ever be much faster than Cpython wink. I was primarily interested in being able to distribute low-footprint standalone executables written in python and code obfustication. The basic approach taken by compyler is to transliterate python bytecode into x86 assembly, instead of trying to generate assembly from the syntax tree. This is basically abandonware. I haven't touched this in six months, but did do a lot of up front work. I basically wanted to release it before my hardrive blows up in case anyone was looking for prior art. The code also contains a version of pyasm that has some more patches and features than the official distribution if you're one of pyasm's 3 users. More info can be found at: http://members.verizon.net/~olsongt/compyler/index.html -Grant -- http://mail.python.org/mailman/listinfo/python-list
Does the world need another v0.1 python compiler?
I'm feeling a little guilty here. I spent a lot of my free time last year working on an x86 compiler for python. I made a reasonable amount of progress, but my interests wandered off into other areas. I basically just got bored and stopped working on the thing maybe 6 months ago. So today, I went to the directory that contains all of my source checkouts, and saw this v 0.1 compiler just sitting out there AGAIN. It's not that I don't want to release the code, but it's just not in quite good enough shape to just throw out there and hope that other people pick up and get things working. I've seen more than a few half-assed compiler implementations out there and part of me thinks I'd just be wasting my time by just zipping up what I have and throwing it out there. Also, I don't really expect any significant speed increases, which seems to be what people want out of a compiler, but was primarily interested in creating standalone .exes without the need for a 'runtime environment' (whatever that means). There might be a little speed increase from unrolling the eval loop, but nothing too serious. The basic approach I took was compiling to bytecode, and then transliterating python bytecode to x86 asm. And it is working a little bit. There is a slightly modified version of the CPython interpreter that introduces xfunction and xcode objects, that basically act the same as function and code objects, but run native code. I've successfully generated some very simple .pyds that can be imported into this interpreter. I also have some tests that test each bytecode on a small scale and they all seem to be working. I can just barely run pystones. The biggest problem right now seems to be that reference counting isn't adding up, resulting in some serious performance degradation. On the downside, right now it's Windows only. There's nothing inherently windows specific, but I don't have anything to build on other platforms. It also assumes you've got the visual studio toolchain. So like I said, I feel a little guilty about keeping this thing hostage on my systems at home. On the other hand, if anyone else is interested, they're going to need to be a VERY early adopter. Does anyone have any serious interest in taking a look? -Grant -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyasm 0.2 - dynamic x86 assembler for python
PyASM by Grant Olson olsongt at verizon.net = PyASM is a dynamic x86 assembler for python. By dynamic, I mean that it can be used to generate inline assembly functions in python at runtime without requiring object file generation or linkage. New in version 0.2 -- + Linux Support. Will work in Linux environments as well as Windows. + Simplified Interface. You only need to use one function to generate code. + Preliminary Documentation. More information and downloads are available on my homepage: http://mysite.verizon.net/olsongt # ## helloWorld.py ## assembly hello world script # -- http://mail.python.org/mailman/listinfo/python-list
Safe string escaping?
I have a data file that has lines like foo\n\0 where the \n\0 is acutally backslash+n+backslash+0. I.E. a repr of the string from python would be foo\\n\\0. I'm trying to convert this string into one that contains actual newlines and whatnot. I feel like there has to be a better and safer way to do this than eval('%s' % foo\\n\\0) but I'm not finding it. Any tips would be appreciated, Grant -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyasm 0.1 - x86 assembler for Python
pyasm 0.1 - x86 assembler for Python This release is for early adopters only. It is not properly packaged and doesn't have very good documentation. It is however a functional assembler that should be of interest to some people. Current output targets include Windows-style COFF files that can be subsequently linked to produce executables, and more interestingly output can target memory in an existing Python process and binding within a Python namespace. That's right, you can now generate dynamic inline assembly straight from Python! A simple hello world function implementation is listed at the end of this message. The files test\test_object_creation.py and test\test_winmem.py in the distribution probably give the best examples of usage. Future plans include targeting ELF file formats and Linux memory at runtime, and of course real documentation. The package is available at: http://mysite.verizon.net/olsongt/pyasm-0.1.zip Enjoy, -Grant # # PYTHON HELLO WORLD IN ASSEMBLY # import pyasm.winmem from pyasm.x86asm import assembler, CDECL from pyasm.x86cpToMemory import CpToMemory nonePointer = id(None) a = assembler() a.ADStr(hello_world, Hello world!\n\0) a.AP(test_print, CDECL) a.AddLocal(self) a.AddLocal(args) #a.AI(INT 3) a.AI(PUSH hello_world) a.AI(CALL PySys_WriteStdout) #a.AI(INT 3) a.AI(MOV EAX,%s % id(None)) a.AI(ADD [EAX],0x1) #refcount manipulation a.EP() mem = CpToMemory(a.Compile(),pyasm.winmem) mem.MakeMemory() mem.BindPythonFunctions(globals()) test_print() # calls the assembly function -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN] pyasm 0.1 - x86 assembler for Python
pyasm 0.1 - x86 assembler for Python This release is for early adopters only. It is not properly packaged and doesn't have very good documentation. It is however a functional assembler that should be of interest to some people. Current output targets include Windows-style COFF files that can be subsequently linked to produce executables, and more interestingly output can target memory in an existing Python process and binding within a Python namespace. That's right, you can now generate dynamic inline assembly straight from Python! A simple hello world function implementation is listed at the end of this message. The files test\test_object_creation.py and test\test_winmem.py in the distribution probably give the best examples of usage. Future plans include targeting ELF file formats and Linux memory at runtime, and of course real documentation. The package is available at: http://mysite.verizon.net/olsongt/pyasm-0.1.zip Enjoy, -Grant # # PYTHON HELLO WORLD IN ASSEMBLY # import pyasm.winmem from pyasm.x86asm import assembler, CDECL from pyasm.x86cpToMemory import CpToMemory nonePointer = id(None) a = assembler() a.ADStr(hello_world, Hello world!\n\0) a.AP(test_print, CDECL) a.AddLocal(self) a.AddLocal(args) #a.AI(INT 3) a.AI(PUSH hello_world) a.AI(CALL PySys_WriteStdout) #a.AI(INT 3) a.AI(MOV EAX,%s % id(None)) a.AI(ADD [EAX],0x1) #refcount manipulation a.EP() mem = CpToMemory(a.Compile(),pyasm.winmem) mem.MakeMemory() mem.BindPythonFunctions(globals()) test_print() # calls the assembly function -- http://mail.python.org/mailman/listinfo/python-list