1997Q2/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: Execution -->
<!--X-From-R13: Xrss Yrffryzna <wrssxNgrargjbex.pbz> -->
<!--X-Date: from babe.globecomm.net [207.51.48.8] by mx3.ibm.net id 860723409.72886&#45;1 Fri Apr 11 01:50:09 1997 -->
<!--X-Message-Id: 3.0.32.19970410185848.0072d224#mail,tenetwork.com -->
<!--X-Content-Type: text/plain -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, Re: Execution</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:jeffk#tenetwork,com">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00077.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00079.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00077.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00079.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00078">Author</A>
&nbsp;|&nbsp;<A HREF="#00078">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00078">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>Re: Execution</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#null,net">mud-dev#null,net</A></LI>
<LI><em>Subject</em>: Re: Execution</LI>
<LI><em>From</em>: Jeff Kesselman &lt;<A HREF="mailto:jeffk#tenetwork,com">jeffk#tenetwork,com</A>&gt;</LI>
<LI><em>Date</em>: Thu, 10 Apr 1997 18:58:48 -0700</LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
You left out a true virtual machine with a compiled assembly code i nits
own assembly langauge (typicly a stack machine of soem kind).

These VMs come in two varietoes these days, traditional stack machines liek
the old pascal P system, adn object orienetd stack machiens like the JAVA
machine (and  my Kelvin VM).


JK

At 07:43 AM 4/10/97 MST, you wrote:
&gt;:&gt; Perhaps we can come up with a gradient (I'm sure this has been done
before!)
&gt;:&gt; and we can all point to where we are on it:
&gt;:&gt;
&gt;:&gt; 1.  native machine code
&gt;:&gt; 2.  threaded code
&gt;:&gt; 3.  bytecode
&gt;:&gt; 4.  parse tree traversal
&gt;:&gt; 5.  pre-tokenized interpretation
&gt;:&gt; 6.  straight text interpretation
&gt;:
&gt;:Would anyone be able to give a short description of all of these?
&gt;:(Especially threaded and bytecode) I have been trying to find out about
&gt;:threads - i got the pthreads lib for linux, the docs for that are
&gt;:impossible to understand without *some* kind of prior knowledge of what
&gt;:threads are - I have heard that the linux port of it isnt very 
&gt;:good/stable/efficient and martin keegan has gone so far as to advise not
&gt;:to use them under any kind of unix..
&gt;
&gt;[snip]
&gt;
&gt;:Has anyone ever done an analysis comparing the above 6 methods? It would
&gt;:be interesting to look at.
&gt;
&gt;Weeeell, since I opened this can of worms... First, note that I completely
&gt;made up the above list - it is not official in any way! Second, the
&gt;'threading' referred to has nothing to do with threads of execution. Sorry.
&gt;Take *all* of this stuff with lots of grains of salt. I've only ever done
&gt;4 and 6, myself. Oh, and a bit of 2 many many years ago.
&gt;
&gt;- native machine code: that produced by compilers like C, C++, assemblers
&gt;    Stuff that runs directly on the CPU using native CPU instructions.
&gt;
&gt;- threaded code: the usual example here is the language Forth. There are
&gt;    variants of this, but here is one. Stuff in memory is typically a
&gt;    sequence of addresses, with a few non-addresses mixed in. The addresses
&gt;    are pointers into the code of the support framework for the language.
&gt;    The system will have a central core, consisting of half a dozen or
&gt;    less instructions, that just reads the next pointer in the sequence,
&gt;    and branches to it. That sequence will do its thing, perhaps reading
&gt;    a word of data from the sequence, then branching back to the central
&gt;    core to allow the next operation.  E.g.
&gt;
&gt;	if a &lt; 0 then
&gt;	    Print("negative\n");
&gt;	else
&gt;	    Print("positive\n");
&gt;	fi;
&gt;
&gt;    could be represented as:
&gt;
&gt;	@pushvar	primitive: push value onto stack
&gt;	A		value: address of variable who's value to push
&gt;	@pushconst	primitive: push constant value onto stack
&gt;	0		value: the constant 0
&gt;	@&lt;		primitive: pop 2 args, compare, push 1 if '&lt;' else 0
&gt;	@if		primitive: the 'if' handler
&gt;	@label1 	value: address of 'else' part
&gt;	@pushconst
&gt;	'negative'	value: the address of the string constant
&gt;	@printstring	primitive: the thing that prints a string
&gt;	@branch 	primitive: branch to the indicated place
&gt;	@label2 	value: the address to branch to
&gt;label1: @pushconst
&gt;	'positive'	value: the address of the string constant
&gt;	@printstring
&gt;label2:
&gt;
&gt;    So, you have to sort of 'compile' to this stuff, but it is a lot
&gt;    easier than compiling to true native code. You don't care about the
&gt;    details of instruction formats and stuff, you don't have to worry about
&gt;    linking, and you don't have to worry about object file formats.
&gt;
&gt;    Other forms of threaded code have actual instruction sequences instead
&gt;    of the above type of sequence. Subroutine call instructions are used to
&gt;    get to the primitives, and they can use the return address to know
&gt;    where their operands are.
&gt;
&gt;- bytecode: this is conceptually easier, but still has lots of variations
&gt;    possible. You compile to something like the above, but just use
&gt;    (typically) single-byte codes to represent which primitive you want
&gt;    to use. E.g. for our example:
&gt;
&gt;	00: &lt;numeric code for PUSHVAR&gt;
&gt;	01: &lt;some pointer to 'a'
&gt;	05: &lt;numeric code for PUSHCONST&gt;
&gt;	06: 0 (4 bytes)
&gt;	10: &lt;numeric code for LESSTHAN&gt;
&gt;	11: &lt;numeric code for IF&gt;
&gt;	12: 9 (2 bytes)
&gt;	14: &lt;numeric code for PUSHCONST&gt;
&gt;	15: &lt;pointer to string&gt;
&gt;	19: &lt;numeric code for PRINTSTRING&gt;
&gt;	20: &lt;numeric code for BRANCH&gt;
&gt;	21: 6 (2 bytes)
&gt;	23: &lt;numeric code for PUSHCONST&gt;
&gt;	24: &lt;pointer to string&gt;
&gt;	28: &lt;numeric code for PRINTSTRING&gt;
&gt;	29:
&gt;
&gt;    The 'interpreter' of these bytecodes can be written in assembler, or
&gt;    in some higher level language like C. Again, you sort of have to
&gt;    compile to this stuff, but its fairly easy compilation.
&gt;
&gt;- parse tree traversal: (I use this). This is just a bunch of malloc'ed
&gt;    memory, containing records of a union type, that have a type code
&gt;    saying what they are (like the bytecode codes), plus pointers to
&gt;    further records, or some constant values. Rough ASCII art follows:
&gt;
&gt;			------------------------
&gt;			| IF |	   |	 |     |
&gt;			------------------------
&gt;			       /      |       \
&gt;			      /       |        \
&gt;			     /	      | 	\
&gt;		    ---------	 -----------   -----------
&gt;		    |&lt;|  |  |	 |PSTR| ptr|   |PSTR| ptr|
&gt;		    ---------	 -----------   -----------
&gt;		      /   |
&gt;		     /	  |
&gt;	     -------- ---------
&gt;	     |VAR| a| |CONST|0|
&gt;	     -------- ---------
&gt;
&gt;    Just some kind of direct 'parse tree' of the program. The two parts
&gt;    of the 'if' would often be nodes representing a sequence of other
&gt;    nodes, terminated by one with a nil pointer (linked list of things
&gt;    to do). The interpreter just does a recursive preorder (do the left
&gt;    most node first) traversal of the tree, executing as it goes. For
&gt;    an 'if', it evaluates the condition, and decides which of the two
&gt;    subparts of the 'if' to execute. The overhead here is all of the
&gt;    extra recursive calls of the interpreting routine. This structure
&gt;    is fairly easy to work with, however, such as being 'pretty printed'
&gt;    back out to ASCII form.
&gt;
&gt;- pre-tokenized interpretation: the program has been turned into a
&gt;    sequence of codes and constants, like in bytecodes, but it hasn't
&gt;    necessarily been fully checked for consistency. So, the interpreter
&gt;    must continually check that the next codes make sense. Also, the
&gt;    names of variables, etc. probably haven't been looked up yet (they
&gt;    are just stored as ASCII strings), so the interpreter has to go
&gt;    find what they refer to (if they are in fact valid!)
&gt;
&gt;- straight text: as above, but no pre-tokenization into chunks has been
&gt;    done. All of the work of scanning the input is done over and over
&gt;    again as the code is re-used. Quite slow, but doesn't require the
&gt;    design of any extra data structures, magic codes, etc.
&gt;
&gt;Whew! I'm now 15 minutes late for my bus - hopefully I'll catch the next one!
&gt;
&gt;--
&gt;Chris Gray   cg#ami-cg,GraySage.Edmonton.AB.CA
&gt;
&gt;


</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00077.html">Re: Execution</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00079.html">Re: Execution</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00077.html">Re: Execution</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00079.html">Re: Execution</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00078"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00078"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>Re: short absence</STRONG>, <EM>(continued)</EM>
<ul compact>
<LI><strong><A NAME="00116" HREF="msg00116.html">Re: short absence</A></strong>, 
coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Mon 14 Apr 1997, 00:01 GMT
</LI>
</ul>
</LI>
<LI><strong><A NAME="00082" HREF="msg00082.html">Hello!</A></strong>, 
Ross Nicoll <a href="mailto:rnicoll#lostics,thenet.co.uk">rnicoll#lostics,thenet.co.uk</a>, Fri 11 Apr 1997, 22:14 GMT
<LI><strong><A NAME="00075" HREF="msg00075.html">Execution</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Thu 10 Apr 1997, 21:46 GMT
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00077" HREF="msg00077.html">Re: Execution</A></strong>, 
Furball <a href="mailto:K.L.Lo-94#student,lut.ac.uk">K.L.Lo-94#student,lut.ac.uk</a>, Fri 11 Apr 1997, 01:37 GMT
</LI>
<LI><strong><A NAME="00078" HREF="msg00078.html">Re: Execution</A></strong>, 
Jeff Kesselman <a href="mailto:jeffk#tenetwork,com">jeffk#tenetwork,com</a>, Fri 11 Apr 1997, 08:50 GMT
</LI>
<LI><strong><A NAME="00079" HREF="msg00079.html">Re: Execution</A></strong>, 
Cynbe ru Taren <a href="mailto:cynbe#laurel,actlab.utexas.edu">cynbe#laurel,actlab.utexas.edu</a>, Fri 11 Apr 1997, 10:47 GMT
</LI>
<LI><strong><A NAME="00081" HREF="msg00081.html">Re: Execution</A></strong>, 
Jeff Kesselman <a href="mailto:jeffk#tenetwork,com">jeffk#tenetwork,com</a>, Fri 11 Apr 1997, 13:11 GMT
</LI>
<LI><strong><A NAME="00084" HREF="msg00084.html">Re: Execution</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sat 12 Apr 1997, 02:10 GMT
</LI>
<LI><strong><A NAME="00085" HREF="msg00085.html">Re: Execution</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sat 12 Apr 1997, 02:16 GMT
</LI>
</UL>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>