473,480 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Writing a bytecode interpreter (for TeX dvi files)

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.

--
Jonathan
http://texd.sourceforge.net

Jul 19 '05 #1
1 2030
Aloha,

Jonathan Fine wrote:
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

Jul 19 '05 #2

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

Similar topics

0
2952
by: John Doe | last post by:
Hello, I'm currently working on a little tool that would benefit from having a little embedded script language. Although I have C++ source code available for such a script language, I have 2...
8
3096
by: Rim | last post by:
Hi, How can I control the location of the bytecode files? The reason I ask is I want to place the bytecode in a directory different than source code for backup reasons. Our backup system is...
46
6192
by: Jon Perez | last post by:
Can one run a 1.5 .pyc file with the 2.x version interpreters and vice versa? How about running a 2.x .pyc using a 2.y interpreter?
6
4885
by: Benjamin Scherrey | last post by:
I'm curious as to how difficult it would be to take a string that contains compiled bytecode, load it into memory, give it a function name then execute that function. I'm thinking of a database...
1
3089
by: Bo Jacobsen | last post by:
I have a number of files compiled to bytecode using py_compile.compile(). The .pyc files can be invoked by python directly ($python file.pyc), but "loading" them by execfile just throws an...
33
1956
by: Maurice LING | last post by:
Hi, I've been using Python for about 2 years now, for my honours project and now my postgrad project. I must say that I am loving it more and more now. From my knowledge, Python bytecodes are...
4
2202
by: Ben | last post by:
Does anyone have any experience using the TrueType bytecode interpreter to display fonts in PHP under Windows? I'm running Windows XP, PHP 4.3.11, GD 2.0.28 with FreeType enabled. It all works...
16
1547
by: inhahe | last post by:
Can anyone give me pointers/instructions/a template for writing a Python extension in assembly (or better, HLA)?
0
7039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
2992
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
176
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.