Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #19852
| Newsgroups | comp.lang.forth |
|---|---|
| Subject | Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect |
| References | (13 earlier) <5123a5ea.565124042@192.168.0.50> <slrnki7h7p.1ri.zbigniew2011REMOVE@Tichy.myhome.org> <slrnki7jv3.3h6.zbigniew2011REMOVE@Tichy.myhome.org> <76fb1365-ed26-43e7-8452-98579a49b5e0@hl5g2000vbb.googlegroups.com> <slrnki9gu3.76c.zbigniew2011REMOVE@Tichy.myhome.org> |
| From | Lars Brinkhoff <lars.spam@nocrew.org> |
| Organization | nocrew |
| Date | 2013-02-20 20:15 +0100 |
| Message-ID | <85y5eiokyu.fsf@junk.nocrew.org> (permalink) |
Zbiggy wrote:
> Mark Wills wrote:
> > My goodness! So much code to determine the cell size!
> > Why not simply: HERE 0 , HERE SWAP - .
>
> we are using kForth - and we've got no HERE at our disposal.
And apparently 1 ALIGNED 0 ALIGNED - doesn't fly either.
I see the challenge here is relying on a minimum of system-provided
facilities, and assuming as little as possible about the number
representation. Because of all those, you know, nines-complement
decimal machines out there. (Seriously, those ClearPath mainfraimes
are not far away from that.)
My long-winded attempt is based on doing unsigned arithmetic on cell-
and char-sized values. Unfortunately, it relies on numbers
overflowing the usual way, so it's not quite satisfactory. Also, I
imagine there may be some Forths without unsigned arithmetic.
\ Apply xt on u1, and repeat on the result as long as it
\ keeps getting larger. Return the next last result.
: maximise ( u1 xt -- u2 )
>r 0 swap begin 2dup u< while
nip dup r@ execute
repeat r> 2drop ;
\ Assume there is no :noname, so define these separately.
: 2*1+ ( u -- 2u+1 ) 2* 1+ ;
variable temp
: c1+ ( c -- c+1 ) 1+ temp c! temp c@ ;
\ Compute the maximum unsigned value for a cell.
: ucell-max ( -- u )
\ First, fill with binary ones.
1 ['] 2*1+ maximise
\ Second, make it work on grisly non-binary machines.
['] 1+ maximise ;
\ Compute the maximum (unsigned?) value for a cell.
: char-max ( -- u ) 1 ['] c1+ maximise ;
\ Assume there is no um/mod, so simulate plain single-word division.
: u/ ( u1 u2 -- u1/u2 ) 0 swap um/mod nip ;
\ Start with ucell-max, and repeatedly divide by char-max+1.
: /cell ( -- u )
\ Doesn't work when cell-max = ucell-max, so check for that explicitly.
char-max ucell-max = if 1 exit then
char-max 1+ >r
1 ucell-max begin dup r@ u> while
r@ u/ swap 1+ swap
repeat r> 2drop ;
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can i (easily) implement cell+ and cells in an Forth83 - like dialect cybercow222@gmail.com - 2013-02-18 04:57 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-18 14:17 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-18 14:18 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-18 21:57 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 00:10 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 00:15 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-18 18:39 -0500
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Elizabeth D. Rather" <erather@forth.com> - 2013-02-18 22:04 -1000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-19 08:39 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 13:21 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-19 13:12 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 14:29 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 14:54 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-19 16:25 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 18:29 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 19:16 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <forthfreak@gmail.com> - 2013-02-20 01:07 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 12:36 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Lars Brinkhoff <lars.spam@nocrew.org> - 2013-02-20 20:15 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 20:31 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-20 16:08 -0500
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-20 10:06 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 12:32 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-20 06:55 -0600
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 14:03 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-20 07:48 -0600
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-20 15:30 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-19 18:08 -0500
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-19 16:55 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 18:42 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-19 18:08 -0500
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 00:20 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-20 16:08 -0500
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-18 13:38 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-18 15:39 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-18 14:50 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Elizabeth D. Rather" <erather@forth.com> - 2013-02-18 08:56 -1000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <forthfreak@gmail.com> - 2013-02-18 06:38 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect cybercow222@gmail.com - 2013-02-18 06:00 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Matthias Koch <matthias.koch@hot.uni-hannover.de> - 2013-02-18 15:01 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <forthfreak@gmail.com> - 2013-02-18 06:40 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect awegel@arcor.de (Alex Wegel) - 2013-02-21 10:42 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-02-21 12:19 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-21 14:08 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-21 15:56 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Coos Haak <chforth@hccnet.nl> - 2013-02-21 16:31 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Elizabeth D. Rather" <erather@forth.com> - 2013-02-18 11:26 -1000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect cybercow222@gmail.com - 2013-02-20 04:39 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 13:59 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-20 15:35 +0000
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <markrobertwills@yahoo.co.uk> - 2013-02-20 08:21 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Coos Haak <chforth@hccnet.nl> - 2013-02-21 01:06 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <markrobertwills@yahoo.co.uk> - 2013-02-20 23:04 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect awegel@arcor.de (Alex Wegel) - 2013-02-21 10:42 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2013-02-23 15:14 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Paul Rubin <no.email@nospam.invalid> - 2013-02-23 15:33 -0800
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Coos Haak <chforth@hccnet.nl> - 2013-02-24 00:46 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Coos Haak <chforth@hccnet.nl> - 2013-02-24 01:00 +0100
Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2013-02-24 13:33 -0800
csiph-web