Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #17148
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Date | 2012-11-08 13:04 +0000 |
| Message-ID | <2012110813040151407-chrishinsley@gmailcom> (permalink) |
| References | <2012110713421835115-chrishinsley@gmailcom> <0185e315-1855-415d-b981-638e4a2dabe5@googlegroups.com> |
| Subject | Re: Genral advise and comments on callback style words |
On 2012-11-07 21:04:20 +0000, humptydumpty said: > On Wednesday, November 7, 2012 1:42:19 PM UTC, Chris Hinsley wrote: >> Folks I have implamented an Amiga style double linked list words set a >> >> few days back and I have an emueration word as follows: >> >> >> >> \ ( u xt lh -- ln | 0) >> >> \ xt api is ( u ln lh -- ln | 0 ) >> >> : LISTHEAD-ENUMERATE-FORWARDS >> >> 0 >R >> >> DUP LISTHEAD-GET-HEAD DUP >> >> BEGIN >> >> NIP DUP LISTNODE-GET-SUCC >> >> DUP >> >> WHILE >> >> 4 PICK 2 PICK 4 PICK >> >> 6 PICK EXECUTE DUP R! >> >> UNTIL THEN >> >> 2DROP 2DROP DROP >> >> R> >> >> ; >> >> >> >> This scans down the list until either it hits the end, or the callback >> >> for each node returns a value other than 0, that value is returned and >> >> the scan stops if it isn't 0 ! >> >> >> >> I'd like comments and advice on techniuqe, paticularly for things like >> >> the PICK stuff that gathers paramaters for each callback, and the use >> >> of the return stack for the returned value. Or if you just plain think >> >> I could code this a better way ! >> >> >> >> I'm not wanting to be pointed to "the novice package", thank you, but >> >> want this API as stated ! ;) >> >> >> >> Regards all >> >> >> >> Chris > > Hi! > > Building backward from EXECUTE and applying desired stack-effects, > I've got: > > : HEAD ( lh -- ln ) ; > : SUCC ( ln -- ln' ) ; > > > \ xt ( u ln lh--R|0 ) > : ENUMERATE ( u xt lh -- R|0 ) > ( u xt lh ) swap >R > ( u lh ) dup HEAD > ( u lh ln ) > BEGIN > ( u lh ln ) dup SUCC dup 0= > ( u lh ln ln' f ) IF RDROP 2drop 2drop 0 EXIT THEN > ( u lh ln ln' ) swap 2over > ( u lh ln' ln u lh ) rot swap R@ > ( u lh ln' u ln lh xt ) EXECUTE dup > ( u lh ln' R f=R ) IF RDROP nip nip nip EXIT THEN > ( u lh ln' R ) drop > ( u lh ln' ) AGAIN > ; > > Question: > what happens if `execute'-ing xt invalidate the succesor `ln'' ? See my follow up reply to my original posting about that. The callback _must_ be able to remove, if needed, the current list node, so the succeeding ln must be keeped safe before the callback. What are people thoughts on having EXIT or in this case multiple EXIT's in the middle of words ? It's not very 'stuctured', but maybe that dosn't matter. It could have a bad effect on simple inlineing Forth's ? ie, if inlining just copys the code of the word inline minus the 'ret' at the end ? I did think about having this double EXIT and IF,THEN stuff, but the idea of having 2 taken branches, asside from the loop repeat per iteration put me off. My posted version has 2 none taken branches, granted that the x86 branch predicter probably folds both these ways into the same thing these days, but other cpu's it might be an issue, certainly I've been brought up to think taken branches are a big no no :) > > Have a nice day, > humptydumpty
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 13:42 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 13:51 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 13:56 +0000
Re: Genral advise and comments on callback style words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-11-07 13:55 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:29 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:35 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:32 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:37 +0000
Re: Genral advise and comments on callback style words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-11-08 16:31 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 17:02 +0000
Re: Genral advise and comments on callback style words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-11-08 17:07 +0000
Re: Genral advise and comments on callback style words Mark Wills <forthfreak@gmail.com> - 2012-11-09 01:16 -0800
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:41 +0000
Re: Genral advise and comments on callback style words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-11-08 16:39 +0000
Re: Genral advise and comments on callback style words Brad Eckert <hwfwguy@gmail.com> - 2012-11-07 08:07 -0800
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 12:52 +0000
Re: Genral advise and comments on callback style words humptydumpty <ouatubi@gmail.com> - 2012-11-07 13:04 -0800
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 13:04 +0000
Re: Genral advise and comments on callback style words Mark Wills <forthfreak@gmail.com> - 2012-11-08 06:34 -0800
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:40 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 13:14 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 13:23 +0000
Re: Genral advise and comments on callback style words Ouatu Bogdan <ouatubi@gmail.com> - 2012-11-08 13:45 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 13:59 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:02 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 15:35 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 16:24 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 16:39 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 16:57 +0000
Re: Genral advise and comments on callback style words "Elizabeth D. Rather" <erather@forth.com> - 2012-11-08 07:56 -1000
Re: Genral advise and comments on callback style words Josh Grams <josh@qualdan.com> - 2012-11-08 13:54 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:06 +0000
Re: Genral advise and comments on callback style words Josh Grams <josh@qualdan.com> - 2012-11-08 18:04 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 19:36 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 19:38 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 19:42 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:11 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:31 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:51 +0000
Re: Genral advise and comments on callback style words Josh Grams <josh@qualdan.com> - 2012-11-08 18:23 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 19:57 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 20:04 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 20:17 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 20:29 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 20:50 +0000
csiph-web