<!-- MHonArc v2.4.4 --> <!--X-Subject: Re: [MUD-Dev] Storing tokens with flex & bison --> <!--X-From-R13: ptNnzv-pt.UenlEntr.Sqzbagba.OP.QO --> <!--X-Date: Wed, 19 Jan 2000 19:04:37 -0800 --> <!--X-Message-Id: 200001200259.TAA16069@ami-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 & 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> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] <br clear=all><hr> <!--X-Body-Begin--> <!--X-User-Header--> <!--X-User-Header-End--> <!--X-TopPNI--> Date: [ <a href="msg00175.html">Previous</a> | <a href="msg00176.html">Next</a> ] Thread: [ <a href="msg00156.html">Previous</a> | <a href="">Next</a> ] Index: [ <A HREF="author.html#00174">Author</A> | <A HREF="#00174">Date</A> | <A HREF="thread.html#00174">Thread</A> ] <!--X-TopPNI-End--> <!--X-MsgBody--> <!--X-Subject-Header-Begin--> <H1>Re: [MUD-Dev] Storing tokens with flex & 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 & 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:] > >Unfortunately, there was no noticeable change in run speed with or without > >them. However, with this version of gcc/egcs and RedHat Linux, the tests > >all run slower than on the previous version (same machine). Grrrrrr! > Hmm.. on its face, you would think it would be an operation that would occur > frequently in loop blocks. A few instructions saved in each iteration should > 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'. > class TMVar { > Type type; > union { > int i; > float f; > TMError e; > TMString s; > TMBuffer b; > TMList l; > TMQueue q; > TMArray a; > TMObject o; > TMKA k; > TMMethod m; > } value; > } > It's bytecode that has been compiled by a PRS compiler. Er, PRS? > 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. > Anyways I came across this notion of split-phase construction and > 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. > So the new operator is overloaded (short circuited) to return a > pointer to "value". It does nothing, ergo no allocation is done > at all, yet the constructors are called. :-) But with inlining and heavy optimization, even that might go away. > And here is the TMVar default constructor: > inline TMVar::TMVar(Type t = NUM) : type(t) { > switch(t) { > case NUM: > *(int*)value = 0; > case STRING: > new(value) TMString; > case LIST: > new(value) TMList; > ... 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(<field-name>) <typename> do!!? Treat me as completely C++ illiterate. This is likely too basic for the list, so feel free to educate me privately. > So there's my explanation for all the fugly casting that's going on below > and the unusual use of the new() operator. The rest I followed - a fascinating look at higher level ways of doing things. > Another danger to earlier is in returning references to variables > created on the stack. Pretty much the same as the C error of returning > pointers to locals. I would _never_ever do that. <grin> 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 & 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 & bison</STRONG>, <EM>(continued)</EM> <ul compact> <LI><strong><A NAME="00116" HREF="msg00116.html">Re: [MUD-Dev] Storing tokens with flex & 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 & 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 & 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 & 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 & 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> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] </center> <hr> </body> </html>