2000Q1/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: [MUD&#45;Dev] Storing tokens with flex &#38; bison -->
<!--X-From-R13: ptNnzv&#45;pt.UenlEntr.Sqzbagba.OP.QO -->
<!--X-Date: Mon, 03 Jan 2000 23:07:17 &#45;0800 -->
<!--X-Message-Id: 200001040255.TAA02589@ami&#45;cg.GraySage.Edmonton.AB.CA -->
<!--X-Content-Type: text/plain -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, Re: [MUD-Dev] Storing tokens with flex &amp; bison</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">
</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="msg00047.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00049.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00045.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00068.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00048">Author</A>
&nbsp;|&nbsp;<A HREF="#00048">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00048">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>Re: [MUD-Dev] Storing tokens with flex &amp; bison</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Subject</em>: Re: [MUD-Dev] Storing tokens with flex &amp; bison</LI>
<LI><em>From</em>: <A HREF="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</A></LI>
<LI><em>Date</em>: Mon, 3 Jan 2000 19:55:00 -0700</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
[Jon A. Lambert:]

&gt; Not to belabor the point, since I think we're in agreement although coming from
&gt; different angles.  The interesting thing about Crenshaw's toy compiler is that it's a 
&gt; single phase compiler.   The AST is the current state of the compiler's run-time 
&gt; stack and code generation is done as it parser executes.   Admittedly this 
&gt; limits your optimizing options since the AST disappears when the parsing is
&gt; complete.  It is rather elegantly simple though.

I'm guilty of never actually going to read the Crenshaw stuff. I think my
excuse was that for some reason I didn't end up with a full set of articles
at the time.

That same one-phase technique is exactly what I use in my Draco compiler
and in my Toy compiler. Definitely works well, especially if you are
memory-tight, like I was on CP/M systems.

&gt; I thought I'd include another example clipped from the Crenshaw tutorial for the 
&gt; benefit of anyone else reading.   He also discusses the unary negate optimization 
&gt; you mention above elsewhere. 
&gt;
&gt; ---cut---
&gt; There is  a concept in compiler theory called "lazy" translation.

[...]

OK, now I understand the relevance of the term "lazy" translation. I've
seen similar terms used for other things, and that was likely getting me
down the wrong path. I understand the technique.

&gt; As you can see Crenshaw is in conflict with your .sig ---
&gt; He designs in inefficiency in and removes it later... ;-)

Hmm. :-) A peephole optimizer is a prime example of that, although it is
more a matter of removing inefficiency efficiently!

&gt; Hmm, I was thinking in terms of how many instructions my VM will be traversing 
&gt; rather than how the hardware is going to handle those instructions. 
&gt; Now I could implement my VM class as a 3 register machine using the
&gt; members:

Ah, OK. That makes sense. If your register count is small, that works fine.
Now reminded, my 8080 emulator on x86 simply used the one-byte opcode as
a direct index into a 256 entry dispatch table.

&gt; &gt;From the bytecode angle the register is an intrinsic part of the opcode, that is
&gt; it is determined at compilation time.  Now push() and pop() operations 
&gt; in the VM are going to be to checking for a stack overflow or underflow, no?

Actually, no. If you don't allow users to directly generate byte-code, and
you are careful with your compiler, there is never any need to check for
stack underflow. (Well, my interpreter checks the SP after a 'return'
instruction to see if it should return from this level of execution.)
Stack overflow can be handled by a combination of a few checks at run-time
(e.g. at function entry), and compilation checks. This is the exact code for
integer addition from my sources:

	CASE(bc_add) {
	    ULONG_T ul;

	    ul = *sp++;
	    *sp += ul;
	    BREAK;
	}

Macros 'CASE' and 'BREAK' allow the code to compile either using the
gcc dynamic goto stuff, or not. Note: use lots of small scopes and very
local variables like this, so that the compiler can do maximum re-use of
the limited X86 register set.

&gt; I don't know.  It may be something worth revisiting.  
&gt; Besides is there anything more swell than a VM that looks like a 6502? :-)

I decline comment. :-)

&gt; I guess this might lead to the question of whether it is better to have more 
&gt; or less opcodes for your VM's instruction set.  I will note that the Java VM 
&gt; has quite a boatload of special case opcodes, it even distinguishes between 
&gt; pushing an int and pushing a constant one or zero.  So is it better to accomplish 
&gt; something by generating a longer series of simple bytecode operations, or 
&gt; implement a lot of special purpose bytecodes?

I say go for the special-case ones. I have some like 'pshz', 'psh1', etc.
They are very easy to do and use, and can have a noticeable speedup. I'm
real tempted to go add 'add1' and 'sub1', as in our earlier discussion,
to see what effect they have. Should take about 15 minutes.

&gt; I don't think speed of compilation is really an issue at least in the context of 
&gt; a mud server's internal programming language.  Typically in an LP, Moo, Cold,
&gt; Muck, etc. you are compiling rather small pieces of method code or single objects
&gt; so you can add as many phases or passes to the compilation as you need.
&gt; Of course online compilation should be multitasked and handled just like any 
&gt; other mud event especially if you have a user programmable setup.

Well, when you have a system that works well, you tend to use it a lot.
I've gotten into the habit of changing one line of scenario source and then
recompiling all 20,000 lines, rather than making the change online! Too
many times I've forgotten to make the change in the master sources.

&gt; Other than me tripping over terminology again, I still don't agree with the
&gt; following:
&gt;
&gt; ---&gt;Byte-code execution really only makes sense, I believe, for a strongly
&gt; typed language. If run-time checks and conversions are needed, they will
&gt; likely cost far more time than the basic interpretation of the code, and
&gt; so going to byte-code instead of staying with something more direct, could
&gt; be a waste of time, in that byte-code won't speed execution up much.
&gt;
&gt; I agree that overhead is higher, I still think it's less than direct
&gt; interpretation.

I don't understand your sentence, I'm afraid. The overhead of byte-code
execution is less than that of direct interpretation, certainly. Otherwise
no-one, myself included, would bother with byte-code. My point, however,
is that if the overheads of non-static typing are significant, then going
to byte-code could be rather pointless, since it might gain only a few
percent speedup. With strong typing, there is virtually no run-time
overhead for type-checking sorts of things, so going from direct
interpration to byte-code is almost certainly a big win. This is just
a case of one of the general rules concerning speeding programs up: fix
the big things first, then the little things.

&gt; It looks like what one would do with a strongly-typed system.  All the  
&gt; complexity and overhead is hiding under the covers of C++. 
&gt;
&gt; Var&amp; Var::operator=(const Var&amp; value);  
&gt; friend Var operator+(const Var&amp; v1,const Var&amp; v2) throw(TypeError);
&gt;
&gt; You'll find all the switches, if-else chains, and conversion exceptions in 
&gt; those functions.  Yes it's overhead but it is not complex.  Maintenance, 
&gt; debugging and readability are very good.  At least I think so.

Any idea how much overhead? Just guessing, comparing my snippet of source
against what you are showing here, I'd guess a factor of 25 or more. That
is actually *more* than I had thought. And heaven help you if you end
up with some temporary copies of variables because of problems with
reference parameters! I have practically zero experience with C++, so
the presense of all those '&amp;'s would make me *very* nervous about that.

-- 
Don't design inefficiency in - it'll happen in the implementation.

Chris Gray     cg#ami-cg,GraySage.Edmonton.AB.CA
               <A  HREF="http://www.GraySage.Edmonton.AB.CA/cg/">http://www.GraySage.Edmonton.AB.CA/cg/</A>



_______________________________________________
MUD-Dev maillist  -  MUD-Dev#kanga,nu
<A  HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A>

</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="msg00047.html">[MUD-Dev] For those interested in parsers and compilers</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00049.html">[MUD-Dev] EQ packet analyzer is gone?</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00045.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00068.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00048"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00048"><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: [MUD-Dev] Storing tokens with flex &amp; bison</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<LI><strong><A NAME="00120" HREF="msg00120.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></strong>, 
J C Lawrence <a href="mailto:claw#kanga,nu">claw#kanga,nu</a>, Tue 18 Jan 2000, 08:47 GMT
</LI>
</ul>
<LI><strong><A NAME="00030" HREF="msg00030.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Mon 03 Jan 2000, 05:23 GMT
</LI>
<LI><strong><A NAME="00032" HREF="msg00032.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></strong>, 
cg <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Mon 03 Jan 2000, 06:20 GMT
</LI>
<LI><strong><A NAME="00045" HREF="msg00045.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Mon 03 Jan 2000, 23:01 GMT
</LI>
<LI><strong><A NAME="00048" HREF="msg00048.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></strong>, 
cg <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 04 Jan 2000, 07:07 GMT
</LI>
<LI><strong><A NAME="00068" HREF="msg00068.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></strong>, 
cg <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sat 08 Jan 2000, 04:27 GMT
<UL>
<LI><strong><A NAME="00069" HREF="msg00069.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></strong>, 
Chris Jones <a href="mailto:cjones#v-wave,com">cjones#v-wave,com</a>, Sat 08 Jan 2000, 07:19 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00116" HREF="msg00116.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Tue 18 Jan 2000, 07:01 GMT
</LI>
<LI><strong><A NAME="00145" HREF="msg00145.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></strong>, 
cg <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Wed 19 Jan 2000, 03:32 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>