Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #36327
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Reducing C, |
| Date | 2015-02-06 13:21 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mb2f3l$3sa$1@dont-email.me> (permalink) |
| References | (12 earlier) <b4ebcb11-81f3-4089-a7cb-e0602d06a329@googlegroups.com> <2c91cd7b-ee3c-4cd3-8b6c-c60359c2e30d@googlegroups.com> <ecf877f9-6ace-4c19-b3e0-dff8f646511e@googlegroups.com> <mau1mi$n61$1@dont-email.me> <00e9d284-41f6-4247-bcc7-5904e9b6786d@googlegroups.com> |
on 05/02/2015 14:45:36, wrote: > Hi Alex, > > A sentinel makes the code vulnerable. > It gives the code an extra rule. > A coder could forget to put the sentinel on the stack or > the sentinel could inadvertently be removed from the stack. > > Jos > There are lots of things that could create problems; an intervening definition, an erroneous DROP or two or simply forgetting to write it. A mnemonic might help. : starting-here -1 ; starting-here 10 20 30 40 create test as-cstring But now it's beginning to look like COBOL. > On 4 february 2015 22:08:06 UTC+1 Alex McDonald wrote: >> on 04/02/2015 15:12:05, wrote: >> > Agreeing with Alex meant for me the way the allocated space was >> > filled. Restricting to ANS only is IMO a waste of time. >> > However I should have included a definition of lcount. >> > >> > Refactoring ;bytes sounds attractive. >> > But it seems the new definitions can only be used in ;bytes >> > and no where else. >> > New names like allocate-bytes and fill-allocated-bytes >> > don't look right for me. >> > >> > After reading the mail of Alex and your comment >> > my code has been changed to: >> > >> > [UNDEFINED] lcount [IF] >> >: lcount ( adr - adr' cnt ) dup @ swap cell+ swap ; >> > [THEN] >> > >> >: ;bytes ( numbers... -- ) >> > depth last @ name> >body tuck @ - dup 0= abort" Empty stack" >> > dup >r swap ! here r@ allot >> > dup r> + 1- >> > do i c! -1 +loop >> > does> lcount ; >> > >> >: long$: \ compiletime: ( "name" - ) runtime: ( - Adr #items ) >> > create depth , ; \ map: n... >> > >> > long$: &test2 ( - adr #bytes ) char H char E char Y char ! ;bytes >> > >> > cr &test2 type cr .s >> > >> > >> > long$: &test3 >> > 8 0 13 3 10 2 7 >> > 9 5 12 4 1 6 10 ;bytes >> > >> > &test3 dump cr .s >> > >> >> I'm not convinced this is the way to go. The syntax seems clunky. How >> about using a sentinel; -1 seems appropriate here. Factoring is required. >> The syntax for this is >> >> -1 ( the sentinel ) >> <some stack contents> >> create <name> as-cstring >> >> STC Experimental 32bit: 0.06.07 Build: 135 >> here 256 dup allot + constant c-buff ok >> ok >> : as-cstring ( -1 cn .. c0 -- ) >> \ build counted string cn|..|c0, stop at sentinel -1 >> \ move from stack to temp buffer from high to low >> c-buff >> begin over 1+ while >> 1- dup -rot c! >> repeat >> \ allot space for the c string >> dup negate c-buff + >> here over 1+ allot >> \ set c-string length >> 2dup c! >> \ initialise from buffer >> 1+ swap move >> drop >> does> count >> ; ok >> ok >> 20 >> -1 10 20 30 create test as-cstring ok[1] >> ok[1] >> s [1] 20 ok[1] >> test dump >> 80522D | 0A 14 1E |...| ok[1] > >
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Reducing C, josv@planet.nl - 2015-01-28 04:07 -0800
Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-01-28 05:02 -0800
Re: Reducing C, Howerd <howerdo@yahoo.co.uk> - 2015-01-28 07:42 -0800
Re: Reducing C, josv@planet.nl - 2015-01-28 08:17 -0800
Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-01-29 03:37 +1100
Re: Reducing C, visualforth@rocketmail.com - 2015-01-28 12:53 -0800
Re: Reducing C, humptydumpty <ouatubi@gmail.com> - 2015-01-28 14:03 -0800
Re: Reducing C, humptydumpty <ouatubi@gmail.com> - 2015-01-28 20:39 -0800
Re: Reducing C, humptydumpty <ouatubi@gmail.com> - 2015-01-28 20:51 -0800
Re: Reducing C, josv@planet.nl - 2015-01-29 06:28 -0800
Re: Reducing C, hughaguilar96@gmail.com - 2015-01-29 21:18 -0800
Re: Reducing C, josv@planet.nl - 2015-01-30 05:38 -0800
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-01-30 15:11 +0000
Re: Reducing C, josv@planet.nl - 2015-01-30 08:34 -0800
Re: Reducing C, hughaguilar96@gmail.com - 2015-01-31 20:26 -0800
Re: Reducing C, josv@planet.nl - 2015-02-01 11:16 -0800
Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-02 11:03 +1100
Re: Reducing C, "Elizabeth D. Rather" <erather@forth.com> - 2015-02-01 14:13 -1000
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-01 17:22 -0800
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-01 17:36 -0800
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-02 11:40 +0000
Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-02-02 05:24 -0800
Netiquette was: Re: Reducing C, albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-02-02 13:40 +0000
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-02 15:08 +0000
Politeness, was Re: Reducing C, "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-02-02 19:30 -0500
Re: Politeness, was Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-03 01:57 +0100
Re: Politeness, was Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-03 11:59 +0000
Re: Reducing C, josv@planet.nl - 2015-02-03 02:31 -0800
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-03 12:06 +0000
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-03 19:47 +0000
Re: Reducing C, josv@planet.nl - 2015-02-03 14:06 -0800
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-03 21:19 -0800
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-04 12:10 +0000
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-04 18:22 -0800
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-04 19:04 -0800
Re: Reducing C, stephen@mpeforth.com (Stephen Pelc) - 2015-02-05 11:33 +0000
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-05 19:39 -0800
Re: Reducing C, stephen@mpeforth.com (Stephen Pelc) - 2015-02-06 11:50 +0000
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-06 11:28 -0800
Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-02-05 04:37 -0800
Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-06 21:47 +1100
Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-13 09:45 +1100
Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-02-13 05:24 -0800
Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-15 13:53 +1100
Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-02-16 01:07 -0800
Re: Reducing C, anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-02-16 15:02 +0000
Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-19 14:22 +1100
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-05 13:18 +0000
Re: Reducing C, josv@planet.nl - 2015-02-05 07:02 -0800
Re: Reducing C, josv@planet.nl - 2015-02-05 07:14 -0800
Re: Reducing C, josv@planet.nl - 2015-02-07 07:12 -0800
Re: Reducing C, josv@planet.nl - 2015-02-04 07:12 -0800
Re: Reducing C, november.nihal@gmail.com - 2015-02-04 09:38 -0800
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-04 21:08 +0000
Re: Reducing C, josv@planet.nl - 2015-02-05 06:45 -0800
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-06 13:21 +0000
Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-05 17:36 +0100
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-05 17:06 +0000
Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-05 18:17 +0100
Re: Reducing C, "Elizabeth D. Rather" <erather@forth.com> - 2015-02-05 10:40 -1000
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-05 20:25 -0800
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-06 11:39 +0000
Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-06 12:48 +0100
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-06 17:28 -0800
Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-07 12:38 +0100
Re: Reducing C, albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-02-06 14:40 +0000
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-06 18:33 -0800
Re: Reducing C, anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-02-06 13:49 +0000
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-06 14:15 +0000
Re: Reducing C, hughaguilar96@gmail.com - 2015-02-03 21:23 -0800
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-04 12:41 +0000
Re: Reducing C, "WJ" <w_a_x_man@yahoo.com> - 2015-02-04 18:19 +0000
Re: Reducing C, "WJ" <w_a_x_man@yahoo.com> - 2015-02-04 20:54 +0000
Re: Reducing C, "WJ" <w_a_x_man@yahoo.com> - 2015-02-04 09:41 +0000
Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-04 12:54 +0000
csiph-web