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: Wed, 19 Jan 2000 19:04:37 &#45;0800 -->
<!--X-Message-Id: 200001200259.TAA16069@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="msg00175.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00176.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00156.html">Previous</a>
&nbsp;|&nbsp;<a href="">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00174">Author</A>
&nbsp;|&nbsp;<A HREF="#00174">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00174">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>: Wed, 19 Jan 2000 19:59:33 -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; &gt;Unfortunately, there was no noticeable change in run speed with or without
&gt; &gt;them. However, with this version of gcc/egcs and RedHat Linux, the tests
&gt; &gt;all run slower than on the previous version (same machine). Grrrrrr!

&gt; Hmm.. on its face, you would think it would be an operation that would occur
&gt; frequently in loop blocks.  A few instructions saved in each iteration should
&gt; in theory add up fast.

That was my hope. I'm sure there is *some* speedup, but it wasn't visible
in 30 second runs, with granularity 1 second. I think the main jump-table
overhead overwhelms the difference between 'add1' and 'psh1; add'.

&gt; class TMVar {
&gt;    Type type;
&gt;    union {
&gt;       int       i;
&gt;       float     f;
&gt;       TMError   e;
&gt;       TMString  s;
&gt;       TMBuffer  b;
&gt;       TMList    l;
&gt;       TMQueue   q;
&gt;       TMArray   a;
&gt;       TMObject  o;
&gt;       TMKA     k;
&gt;       TMMethod m;
&gt;    } value;
&gt; }

&gt; It's bytecode that has been compiled by a PRS compiler.

Er, PRS?

&gt; The big union is reminiscent of Bison/Yacc tokens (and CoolMUD too).

Just about anything that tokenizes. My 'QValue_t' (don't ask about the
'Q' - its historic) is just a union like that. I cheat and store the
type as the top 6 bits of the values. All values are DB references, other
than 'int' and 'fixed', which I cheat on. That causes my limit of 64 million
database entities.

&gt; Anyways I came across this notion of split-phase construction and
&gt; split-phase destruction as documented by James Coplien I believe.

...

Definitely interesting. It had never occurred to me that C++ won't let
you have a union of classes, but it sortof makes sense to me.

&gt; So the new operator is overloaded (short circuited) to return a 
&gt; pointer to "value".  It does nothing, ergo no allocation is done
&gt; at all, yet the constructors are called.  :-)

But with inlining and heavy optimization, even that might go away.

&gt; And here is the TMVar default constructor:

&gt; inline TMVar::TMVar(Type t = NUM) : type(t) {
&gt;    switch(t) {
&gt;       case NUM:
&gt;          *(int*)value = 0;
&gt;       case STRING:
&gt;          new(value) TMString;
&gt;       case LIST:
&gt;          new(value) TMList;
&gt;       ... etc...

Er, doncha need some 'break's in there? That's my type of bug!

Plus, you are answering my question with another one. What's the syntax:

    new(&lt;field-name&gt;) &lt;typename&gt;

do!!? Treat me as completely C++ illiterate. This is likely too basic for
the list, so feel free to educate me privately.

&gt; So there's my explanation for all the fugly casting that's going on below 
&gt; and the unusual use of the new() operator.

The rest I followed - a fascinating look at higher level ways of doing
things.

&gt; Another danger to earlier is in returning references to variables 
&gt; created on the stack.  Pretty much the same as the C error of returning
&gt; pointers to locals.  I would _never_ever do that.  &lt;grin&gt;

Me neither! For instance, I absolutely do not know that that can stomp the
return address, resulting in the program branching off into the middle of
some other unsuspecting routine.

-- 
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="msg00175.html">Re[2]: [MUD-Dev] Community Relations</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00176.html">Re: [MUD-Dev] Community Relations</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00156.html">Re: [MUD-Dev] Storing tokens with flex &amp; bison</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00174"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00174"><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>
<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>
<LI><strong><A NAME="00148" HREF="msg00148.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, 04:32 GMT
</LI>
<LI><strong><A NAME="00156" HREF="msg00156.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>, Wed 19 Jan 2000, 14:58 GMT
</LI>
<LI><strong><A NAME="00174" HREF="msg00174.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>, Thu 20 Jan 2000, 03:04 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>