473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

PyAsm

Hi!

What about an interface like this:

------------------------------
@pyasm
def hello_world(*some_args):
"""
!CHARS hello_str 'Hello world!\n\0'

!PROC hello_world PYTHON
!ARG self
!ARG args

PUSH hello_str
CALL PySys_WriteStdout
ADD ESP, 0x4
MOV EAX,PyNone
ADD [EAX],1
!ENDPROC
"""

hello_world(1,2,3)
------------------------------

Meaning: Put the assembler into the doc-string of a function. Then use a
decorator to run the assembler on the function's __doc__ string and build an
assembly function that takes the same arguments to make the assembly function
directly callable.

Maybe the decorator line has to look like this:
@pyasm(globals())
or something like that, I can't tell. I don't think it would be much work to
implement this.

Stefan
Jul 18 '05 #1
5 3165

"Stefan Behnel" <st******************@web.de> wrote in message news:d0**********@lnx107.hrz.tu-darmstadt.de...
Meaning: Put the assembler into the doc-string of a function.


That has several issues. One is that you can't do string operations with
it. Say you wanted some %d, %s etc in the string. If you use a documentation
generator (eg epydoc) then the code becomes the API documentation for the
function. Finally it bloats binary distributions. For example BitPim
is 7-10MB binary distribution, full compressed with all doc strings
removed. Including doc strings adds another 3MB to the compressed binary
size!

Instead I would suggest looking at the compile/eval/exec builtins in Python
for inspiration. You can give a string to compile and it gives you something
you can execute later in varying contexts.

Roger
Jul 18 '05 #2
Hey Roger,

I didn't realize that Stefan replied to the list and sent a private
email reply. There seemed to be a lag in google groups today. I
basically told him that I might be crazy enough to write an assembler
in python, but I'm not crazy enough to start using those function
decorators.

I'm working more on the backend stuff now but I was considering adding
the hook. I never realized that you couldn't use string interpolation
on a docstring, so that's probably the showstopper. I don't want to
take that functionality away.

I was thinking that the decorator could cheat and just swallow the
originating docstring when returning the assembly function.
Introspection based tools (which I'm assuming epydoc is) would only see
the new docstrings on the assembly function. Not that I have docstring
functionality built in yet but it's on the todo list. Size also isn't
an issue because I'm currently using a string anyway. But lack of
string interpolation is an issue.

-Grant

P.S. Where'd you get that cool source code formatter for BitPim ;-)

Jul 18 '05 #3
On 10 Mar 2005 12:35:36 -0800, ol*****@verizon.net <ol*****@verizon.net> wrote:
Hey Roger,

I didn't realize that Stefan replied to the list and sent a private
email reply. There seemed to be a lag in google groups today. I
basically told him that I might be crazy enough to write an assembler
in python, but I'm not crazy enough to start using those function
decorators.

I'm working more on the backend stuff now but I was considering adding
the hook. I never realized that you couldn't use string interpolation
on a docstring, so that's probably the showstopper. I don't want to
take that functionality away.

I was thinking that the decorator could cheat and just swallow the
originating docstring when returning the assembly function.
Introspection based tools (which I'm assuming epydoc is) would only see
the new docstrings on the assembly function. Not that I have docstring
functionality built in yet but it's on the todo list. Size also isn't
an issue because I'm currently using a string anyway. But lack of
string interpolation is an issue.


Have you seen PyPy? They already have the ability to turn a native
python function into pyrex and compile it on the fly.

Stephen.
Jul 18 '05 #4
Won't docstrings be removed in optimised bytecode ? that would stuff
things up.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

Jul 18 '05 #5
I haven't checked PyPy out lately. I was under the impression the
Pyrex/C backend was still doing static compilation. Guess I'll have to
take a look.

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Cesar Andres Roldan Garcia | last post by:
Hi How can I control an ALU from a PC using Python? Thanks! Hola... Como puedo controlar la ALU de un PC usando Pyhton?
19
by: citronelu | last post by:
Is it possible to execute a binary string stored within a python script as executable code ? The script is run under Windows, and the binary code (a full executable file) is stored in a variable...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.