Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!ut-emx!ibmchs!auschs!cello!ranger.austin.ibm.com!jat From: jat@ranger.austin.ibm.com (Johnny Tamplin) Newsgroups: comp.lang.c++ Subject: Re: operator functions and classes (was Re: Time to standardize "true" and "false") Message-ID: <1819@cello.UUCP> Date: 16 Oct 89 18:58:53 GMT References: <4625b766.20b6d@apollo.HP.COM> <6590293@hplsla.HP.COM> Sender: news@cello.UUCP Lines: 26 If you look through the old V7 docs, there is a paper talking about PCC. It discusses that when evaluating an expression, it has three modes: evaluating a=b*3+c; if(!a) { ... gets parsed as follows: EvalSideEffect(a=b*3+c) Assign(a,EvalValue(b*3+c)) Assign(a,b*3+c) EvalConditional(!a,truelabel,falselabel) EvalConditional(a,falselabel,truelabel) Notice that the negate operator is evaluated at compile time by reversing the sense of the test, so that in a conditional, !!a is exactly a. If the same expression is being evaluated for value, code will be generated for it. It is not a lot of code to do this -- in fact, it sort of falls out rather easily. You have 3 big switch statements which call various other functions to actually generate code for the operators. I have written several "quickie" code generators this way (although I usually add evaluate for address to make things more straightforward), and the code isn't terribly bad without any optimization other than peephole. Of course, this doesn't get near the code generated by sophisticated optimizations such as those in gcc.