[zopeorg-checkins] CVS: Products/PythonMethod/zbytecodehacks/doc - Makefile:1.1 bch.tex:1.1

Sidnei da Silva sidnei at x3ng.com.br
Fri May 30 11:17:50 EDT 2003


Update of /cvs-zopeorg/Products/PythonMethod/zbytecodehacks/doc
In directory cvs.zope.org:/tmp/cvs-serv19195/PythonMethod/zbytecodehacks/doc

Added Files:
	Makefile bch.tex 
Log Message:
Adding products needed for migration of NZO

=== Added File Products/PythonMethod/zbytecodehacks/doc/Makefile ===
PAPER=--a4

all: bch.ps bch.pdf bch bch.txt

MKHOWTO=TEXINPUTS=/usr/lib/texmf/texmf/tex/latex/latex2html: mkhowto
ADDRESS='Send comments to <A HREF="mailto:mwh21 at cam.ac.uk">mwh21 at cam.ac.uk</A>'


bch html: bch.tex
	$(MKHOWTO) --html $(PAPER) -a $(ADDRESS) bch.tex
	mkdir bch/diagrams
	cp diagrams/*.jpg bch/diagrams 
bch.pdf pdf: bch.tex
	$(MKHOWTO) --pdf $(PAPER) bch.tex
bch.ps ps: bch.tex
	$(MKHOWTO) --ps $(PAPER) bch.tex
bch.txt text: bch.tex
	$(MKHOWTO) --text $(PAPER) bch.tex

tarball: html
	tar chozf bytecodehacks-doc.tar.gz bch

clean:
	$(RM) -r bch bch.ps bch.pdf bch.txt *~ *.tar.gz core *.how *.l2h *.idx *.aux *.log *.syn *.toc *.ind

release: tarball
	scp bytecodehacks-doc.tar.gz mwh at starship.python.net:~mwh/ftp/bytecodehacks-doc-$$(cat ../version).tar.gz
	


=== Added File Products/PythonMethod/zbytecodehacks/doc/bch.tex === (1411/1511 lines abridged)
\documentclass{howto}

\usepackage{graphicx}
\usepackage{html}

\makeindex

\title{Bytecodehacks}

\release{\input{../version}}

\author{Michael Hudson}
\authoraddress{mwh21 at cam.ac.uk}

\begin{document}
\maketitle

\ifhtml
\chapter*{Front Matter\label{front}}
\fi

%\begin{copyright}
These routines are placed in the public domain; downloaded them?
They're yours. I'd be offended if you passed them off as your own work,
but I'm not going to sue.
%\end{copyright}

\begin{abstract}
\noindent
This package contains a library of routines for editing the bytecodes
executed by the Python virtual machine, and a set of routines that use
the library to do unlikely things to Python functions and methods,
such as locally binding references and inlining functions.
\end{abstract}

\tableofcontents

This document describes how to use the bytecodehacks package to do
unlikely things in Python.

\section{Back end}

The bits you need to know how to use to write your own bytecodehacks,
or understand how the ones supplied actually do their stuff.

I presuppose quite a detailed knowledge of the Python interpreter. If
you don't know what the \module{new} or \module{dis} modules do,
you're not likely to understand what goes on here.

When I talk of ``user'' code in this section I mean code that uses the

[-=- -=- -=- 1411 lines omitted -=- -=- -=-]

come from the overhead of the former allocating lots and lots of stack
frames, rather than the legendarily large Python function-call
overhead. This could be because \function{make_tail_recursive}
generates rather terrible code to save off some parameters while the
others are being calculated. It wouldn't take much to improve this,
but I don't have the stamina right now.

On my machine, for smallish values of \var{n} (which means less than a
thousand) \function{factr} runs in about 90\% of the time of
\function{facr}. This gets (much) better as \var{n} increases,
although this is very memory bound - and so not very predictable or
consistent. Depends how much swapping has to be done.

For what it's worth an explicitly iterative version 

\begin{verbatim}
def faci(n):
    p = 1l; c = 1;
    while c <= n:
        p = c*p
        c = c+1
    return p
\end{verbatim}

runs a few percent faster than \function{factr}.


\section{The code generating stuff}

The \refmodule{ops} module is an autogenerated file. The code in
\module{bytecodehacks.code_gen} is responsible for generating this
file.

There is a tiny script in \file{bytecodehacks/code_gen/regen} that
regenerates \file{ops.py}. I have a symlink to it on my \code{\$PATH};
you may want to do the same if you're hacking on bytecodehacks.

\module{write_ops} does most of the legwork. The \method{execute}
methods of all the bytecodes are listed in the file
\file{op_execute_methods} and extracted from said file by
\module{opexfuncread}.

The code isn't pretty or very general, but it works well enough. I
hope it's also fairly easy to understand, because I don't feel like
writing detailed documentation right now...

\input{bch.ind}

\end{document}






More information about the zopeorg-checkins mailing list