Writing a bytecode interpreter (for TeX dvi files)

J

Jonathan Fine

I'm writing some routines for handling dvi files.
In case you didn't know, these are TeX's typeset output.

These are binary files containing opcodes.
I wish to write one or more dvi opcode interpreters.

Are there any tools or good examples to follow for
writing a bytecode interpreter?

I am already aware of opcode.py and other modules in
Python Language Services, in the Library Reference.

Thanks.
 
A

Andreas Lobinger

Aloha,

Jonathan said:
I'm writing some routines for handling dvi files.
In case you didn't know, these are TeX's typeset output.
These are binary files containing opcodes.
I wish to write one or more dvi opcode interpreters.
Are there any tools or good examples to follow for
writing a bytecode interpreter?

As far as i know, dvi is a very straight forward format, commands
followed by parameters, no conditionals, no loops.
For similar designs i used something like the following approach:

s = file('a.dvi','r').read() # read complete file to string

while s:
command = ord(s[0])

if command < 128:
#typeset command
s = s[1:]
elif command = 139:
#bop command
param = s[:40]
#interpret param
c = struct.unpack('D',param[:3])
#consume s
s = s[41:]
else:
#undefined command
s = s[1:]

You can work directly on strings, or convert to a list. If you don't
want long if/elif lists, you can use a dict as a dispatcher (python
cookbook has an example?). For most of the commands you can use
a lookup table for the parameter list length.
TeX §591 claims, that dvi is stricly interpretable from front to end.
The description in Tex§585++ can be transcripted to struct definitions
easily.

Wishing a happy day
LOBI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top