472,801 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

A historical question

Hi.

I'd like to know when python started working with bytecode.
It seems natural that in the first python implementations
code was really interpreted : executed directly.

As a result, in the first days, when the py-programmer
said:

def foo ():
print 'foo'

python stored the function body and executed it each time
foo was called. In some time it was decided to compile
this to bytecode, optimize it and call the bytecode instead.

Is it so?

I am very curious.
Gerald
Jul 18 '05 #1
8 1610
Jerald <jf*@freemail.gr> wrote in news:ch***********@ulysses.noc.ntua.gr:
Hi.

I'd like to know when python started working with bytecode.
It seems natural that in the first python implementations
code was really interpreted : executed directly.

As a result, in the first days, when the py-programmer
said:

def foo ():
print 'foo'

python stored the function body and executed it each time
foo was called. In some time it was decided to compile
this to bytecode, optimize it and call the bytecode instead.

Is it so?


According to Google, in April 1994 Guido posted complaining about some of the
inefficiencies in the bytecode interpreter:

http://groups.google.co.uk/groups?se...40voorn.cwi.nl

I doubt very much whether there has ever been any implemention of Python that
didn't use a bytecode of some form. It would be a very perverse way to try to
write a language.
Jul 18 '05 #2
Jerald wrote:
I'd like to know when python started working with bytecode.
It seems natural that in the first python implementations
code was really interpreted : executed directly.


Why does that seem natural to you?

-Peter
Jul 18 '05 #3
Unless I'm mistaken it is nearly impossible to
"execute" any software without translating the
source into some intermediate (read bytecode) set
of tokens and operators. All interpreters must
parse the source code and create some structured
representation (even if it is only internal) that
is normally VERY different from the source code
itself. Some interpreters never save out this
"byte code", but it exists nevertheless.

Larry Bates
Syscon, Inc.

"Jerald" <jf*@freemail.gr> wrote in message
news:ch***********@ulysses.noc.ntua.gr...
Hi.

I'd like to know when python started working with bytecode.
It seems natural that in the first python implementations
code was really interpreted : executed directly.

As a result, in the first days, when the py-programmer
said:

def foo ():
print 'foo'

python stored the function body and executed it each time
foo was called. In some time it was decided to compile
this to bytecode, optimize it and call the bytecode instead.

Is it so?

I am very curious.
Gerald

Jul 18 '05 #4
"Larry Bates" <lb****@swamisoft.com> wrote in message
news:M5********************@comcast.com...
Unless I'm mistaken it is nearly impossible to
"execute" any software without translating the
source into some intermediate (read bytecode) set
of tokens and operators. All interpreters must
parse the source code and create some structured
representation (even if it is only internal) that
is normally VERY different from the source code
itself. Some interpreters never save out this
"byte code", but it exists nevertheless.

Larry Bates
Syscon, Inc.

"Jerald" <jf*@freemail.gr> wrote in message
news:ch***********@ulysses.noc.ntua.gr...
Hi.

I'd like to know when python started working with bytecode.
It seems natural that in the first python implementations
code was really interpreted : executed directly.

As a result, in the first days, when the py-programmer
said:

def foo ():
print 'foo'

python stored the function body and executed it each time
foo was called. In some time it was decided to compile
this to bytecode, optimize it and call the bytecode instead.

Is it so?

I am very curious.
Gerald


Agreed. However, we should also consider that "compiled" excutable images
in machine language are simply bytecodes to the processor microcode.

Now... If we had a processor for which we could write microcode to execute
Python or Parrot bytecode, ...
Jul 18 '05 #5
On Wed, 08 Sep 2004 14:20:40 -0700, Jerald <jf*@freemail.gr> wrote:
I'd like to know when python started working with bytecode.
It seems natural that in the first python implementations
code was really interpreted : executed directly.


I assume that you expect direct execution to be the easiest way to
start implementing a new language. However, that's far from true. It's
actually pretty difficult to execut programs in procedural languages
*without* some form of intermediate code, and almost all computer
languages are compiled at some level before execution. The only
situation where direct execution makes sense is in the case of simple
command line interfaces; some simple shell script languages may be
still executed this way, but that's an exception to the rule. Even old
languages such as BASIC used to be compiled to some form of
intermediate code -- a similar concept to Python's bytecode, but much
simpler.

You may think that to create a virtual machine or compiler for a new
language is a hard task. But there is a huge body of theorethical
knowledge regarding all the pieces of software required to implement a
new computer language that can be used for this purpose. There is no
need to reinvent the wheel here. Concepts such as language parser,
intermediate code generator, optimizer, etc -- they're all quite old
and well understood. Automatic tools and code generators can be used,
given the language definition, to create a basic compiler for it. Of
course, there are a few areas with hot new advancements, but the
basics are already solidly understood.

The most dificult part is not implementing the basic compiler or
virtual machine. The hardest part is coming up with a clear and
powerful language design. That's where Python really shines.

--
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: ca********@gmail.com
mail: ca********@yahoo.com
Jul 18 '05 #6
Carlos Ribeiro wrote:
On Wed, 08 Sep 2004 14:20:40 -0700, Jerald <jf*@freemail.gr> wrote:
I'd like to know when python started working with bytecode.
It seems natural that in the first python implementations
code was really interpreted : executed directly.


I assume that you expect direct execution to be the easiest way to
start implementing a new language. However, that's far from true. It's
actually pretty difficult to execut programs in procedural languages
*without* some form of intermediate code, and almost all computer
languages are compiled at some level before execution. The only
situation where direct execution makes sense is in the case of simple
command line interfaces; some simple shell script languages may be
still executed this way, but that's an exception to the rule. Even old
languages such as BASIC used to be compiled to some form of
intermediate code -- a similar concept to Python's bytecode, but much
simpler.


This is not, as far as I know, true. At least, not for the
general case, although certain specific implementations of
BASIC may have worked this way.

If you are thinking, for example, of how the early BASICs
on things like the Apple ][ and the PET computers worked,
you are misinterpreting (no pun intended) what actually
happened, IMHO.

The only "compilation" that went on was actually called
"tokenization", and that meant only that keywords such
as PRINT were turned into single-byte values that corresponded
directly to the keyword in the source. The rest of the
source was left as-is, including the quotation marks around
strings, variable names, etc. I think whitespace was
generally compressed (i.e. multiple spaces in places where it
wasn't syntactically meaningful were turned into one or none)
but this and the tokenization was more for memory conservation
than for anything else.

I guess one could call this "compilation"... I wouldn't.
In fact, I think in general compilation is a process which
is not 100% reversible, whereas tokenization in the form
BASIC did it was (whitespace aside).

-Peter
Jul 18 '05 #7
On Wed, 08 Sep 2004 11:59:38 -0400, Peter Hansen <pe***@engcorp.com> wrote:
Carlos Ribeiro wrote:
... Even old
languages such as BASIC used to be compiled to some form of
intermediate code -- a similar concept to Python's bytecode, but much
simpler.


<snip>

The only "compilation" that went on was actually called
"tokenization", and that meant only that keywords such
as PRINT were turned into single-byte values that corresponded
directly to the keyword in the source.


You're right -- I oversimplified my explanation to reinforce the fact
that few systems ever run the program directly from the source code,
as the original poster implied in his question. Tokenization is only
the first step. But as a generic (and simple) explanation, its result
is conceptually one step closer to Python's (or Java's) bytecode than
the original (textual) program source.
--
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: ca********@gmail.com
mail: ca********@yahoo.com
Jul 18 '05 #8

"Duncan Booth" <du**********@invalid.invalid> wrote in message
news:Xn***************************@127.0.0.1...
Jerald <jf*@freemail.gr> wrote in news:ch***********@ulysses.noc.ntua.gr:
<snip original post>
According to Google, in April 1994 Guido posted complaining about some of
the
inefficiencies in the bytecode interpreter:

http://groups.google.co.uk/groups?se...40voorn.cwi.nl

I doubt very much whether there has ever been any implemention of Python
that
didn't use a bytecode of some form. It would be a very perverse way to try
to
write a language.


From some things I read about Parrot, I'm under the impression that Ruby
(and Perl, partially) don't (yet) use bytecodes (at least internally - they
may be used as an external representation). Instead, the program is parsed
into an abstract syntax tree and the program is interpreted by walking the
tree. See http://en.wikipedia.org/wiki/Interpreted_language . The same
method would probably work with Python.
Jul 18 '05 #9

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

Similar topics

5
by: Robert AH Prins | last post by:
Hi all, A number of questions: 1) I'm in the process of converting some historical type-written newsletters to HTML and one of the things that came up while doing so was the fact that some...
1
by: rottytooth | last post by:
A general data design question: We have data which changes every week. We had considered seperating historical records and current records into two different tables with the same columns, but...
1
by: ά | last post by:
hi, now, i don't know how to ask a historical query? which command? thanks! __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam...
3
by: Erwin | last post by:
I have a work assignment in which I have to put a historical archive within access which can be used for trendlines etc. It contains data about month, service percentages and numbers. Within a...
2
by: igendreau | last post by:
I need to have a form where my users can enter job info. One thing they need to enter is "Regular Hours". What I need to do is then calculate "Regular Cost" which =Regular Hours x Regular Rate...
1
by: sbowman | last post by:
I'm in the process of creating a monthly reporting database. I've worked out all the queries which are all counts of particular field values. I need to store these values in a table for historical...
16
by: scott | last post by:
I am looking for a copy of Turbo C 1.5 from 1987 for some historical research I'm doing into computing from that time period.
46
by: Sensei | last post by:
I was having an interesting discussion about the ANSI C and some ``weird inconsistencies'', or at least what at first sight can be seen as an imbalance. I hope someone can satisfy my curiosity. ...
11
by: David Mathog | last post by:
In the beginning (Kernighan & Ritchie 1978) there was fprintf, and unix write, but no fwrite. That is, no portable C method for writing binary data, only system calls which were OS specific. At...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.