Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #3625
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Date | 2011-06-29 13:24 +0100 |
| Message-ID | <2011062913245221545-chrishinsley@gmailcom> (permalink) |
| References | <2011062814435882049-chrishinsley@gmailcom> <2011Jun29.132533@mips.complang.tuwien.ac.at> |
| Subject | Re: macro expansion ? |
On 2011-06-29 12:25:33 +0100, Anton Ertl said: > Chris Hinsley <chris.hinsley@gmail.com> writes: >> From the recent thread on IMMEDIATE I quote this word: >> >> \ macros >> : MACRO ( "name" <ccccc"> -- ) >> CREATE ," IMMEDIATE DOES> COUNT EVALUATE ; >> >> When I first added this word to my Forth project I belived it would >> allow me to define words that were 'macro expanded' in a text >> substitution manner. > > In some sense, which is why it is a bad idea. > >> Is this indead the case ? The call to EVALUATE made me think this would >> act as if it was text substitution rather than just a IMMIDEATE word >> that would execute during compilation. > > It's an immediate word that executes during compilation, so the text > substitution part happens during compilation. Leave away the > IMMEDIATE and you get a word where the text substitution happens at > run-time. That is (for both), in the usual case. When you tick or > POSTPONE the word, you get something STATE-dependend (because the text > interpreter used by EVALUIATE is STATE-dependend), and the behaviour > you intended will probably only happen in one of the two states. > > There are also other dependencies in this kind of word: dependence on > BASE, on the search order, on the words in the wordlists on the search > order, and other global state. > > It's very easy to write buggy programs with these kinds of words, and > hard to test for that stuff, so I call this concept bugros. > > As an illustration of one of the dangers: > > decimal > macro ten 10 " > > hex > : foo ten ; > decimal > > foo . > >> My intention was somthing that >> would be expanded during compilation and therefore may get optimised as >> inlined code into the word curently deing defined, so no subroutine >> call overhead. > > If you want optimization, get an optimizing compiler and write colon > defintions. The compiler will inline the colon definitions by itself. > You will get better performance and fewer bugs. > > - anton OK, I'm convinced this MACRO word does more harm that good. I don't agree that I should have to have an optimizing compiler to produce good code ! For my specific example about surface to surface blit routines, it's perfectly possible to do them without an optimizing compiler provided you have a good technique for source generation. I'm only asking for somthing that I could achive in a macro assembler, I wouldn't have thought that was asking too much of Forth. I guess the best way to go on this is to write an IMMEDIATE word that compiles the inner loop of the blit directly, takes the surface types as compile time paramaters and just places the code in the dictionary directly. Chris
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 14:43 +0100
Re: macro expansion ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-06-28 10:58 -0500
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 18:34 +0100
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 18:51 +0100
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 19:02 +0100
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 19:11 +0100
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 19:17 +0100
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 19:47 +0100
Re: macro expansion ? Josh Grams <josh@qualdan.com> - 2011-06-29 15:34 +0000
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 19:21 +0100
Re: macro expansion ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-06-29 03:15 -0500
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 13:11 +0100
Re: macro expansion ? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-06-29 17:17 +0100
Re: macro expansion ? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-06-29 18:09 +0100
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 19:32 +0100
Re: macro expansion ? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-07-02 08:48 +0100
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 00:44 +0100
Re: macro expansion ? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-06-29 20:39 +0100
Re: macro expansion ? Elizabeth D Rather <erather@forth.com> - 2011-06-28 08:59 -1000
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 20:39 +0100
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 21:34 +0100
Re: macro expansion ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-06-29 03:26 -0500
Re: macro expansion ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-06-29 11:25 +0000
Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 13:24 +0100
Re: macro expansion ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-07-03 14:02 +0000
Re: macro expansion ? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-06-29 18:48 +0000
Re: macro expansion ? BruceMcF <agila61@netscape.net> - 2011-06-30 11:11 -0700
Re: macro expansion ? Ian Osgood <iano@quirkster.com> - 2011-07-02 16:22 -0700
Re: macro expansion ? Hugh Aguilar <hughaguilar96@yahoo.com> - 2011-07-05 17:35 -0700
csiph-web