Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "Rod Pemberton" Newsgroups: comp.lang.forth Subject: Re: ?DUP Date: Wed, 30 Oct 2013 08:03:49 -0400 Organization: Aioe.org NNTP Server Lines: 72 Message-ID: References: <3_idnWekjL7WAPbPnZ2dnUVZ_qmdnZ2d@supernews.com> <2013Oct26.154815@mips.complang.tuwien.ac.at> <2013Oct27.134114@mips.complang.tuwien.ac.at> <6YadnfY509sEiPDPnZ2dnUVZ_hadnZ2d@supernews.com> <2013Oct28.161930@mips.complang.tuwien.ac.at> <2013Oct29.125121@mips.complang.tuwien.ac.at> <2013Oct30.092213@mips.complang.tuwien.ac.at> NNTP-Posting-Host: CNsg4fVcCsvs3UaOgZtQCw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.forth:26758 On Wed, 30 Oct 2013 04:22:13 -0400, Anton Ertl wrote: > Andrew Haley writes: >> Anton Ertl wrote: >>> Not "optimizing" ROT would not simplify the compiler. >> >> Why not? Surely if you don't recognize ROT, but simply code >> it as a call to a definition, the optimizer is simpler. > > Even a definition of ROT as a colon definition would result in > optimizing ROT. Are you two talking about different things here? ISTM, that Anton is discussing optimization down to the assembly level for a Forth that compiles, but Andrew might be discussing optimization which stops at the level of low-level words, e.g., for a thread-code interpreted Forth. In one case, everything is optimized, both high- and low-level Forth words. In the other, just the high-level words. > And it's not really simpler than a more direct > definition of ROT: > > Colon definition: > > : myrot >r swap r> swap ; > > A direct definition would look maybe like this: > > c: rot rot ; : rot rot ; > Interesting, but is there really a need for "c:" definition? I.e., if you're just defining "rot" to be "rot", what's the purpose of "c:" ? Symbolic? Anyway, how ROT is defined depends on what you have available. If you have >R and SWAP , then ">R SWAP >R SWAP" works. Of course, you could also implement ROT in assembly or C, etc as a low-level word. Or, you could use one of many other high-level definitions: : ROT 2 ROLL ; : ROT TUCK 2SWAP DROP ; : ROT NUP 2SWAP DROP ; : ROT >R SWAP >R 2R> ; : ROT >R 2>R R> 2R> ; etc... E.g., ROT using one register A: : ROT >R >R A! R> R> A@ ; : ROT A! SWAP A@ SWAP ; E.g., ROT using two registers A and B: : ROT A! B! >R B@ A@ R> ; If you have more precise stack control, other definitions are possible, but likely longer sequences. Of course, you really want to pick whatever is fastest, or that which optimizes the best, not necessarily that which is the shortest. That could mean using operations that you wouldn't normally choose. Rod Pemberton