From anton Wed May 26 21:27:12 1999 X-newsreader: xrn 9.01-beta-3 From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Subject: Re: "It's not Forth" SVFig Talk Path: a0.complang.tuwien.ac.at!anton Newsgroups: comp.lang.forth Distribution: Followup-To: References: <7hq5c8$1id$1@news.smart.net> <7hsku7$ra5$3@news1.cableinet.co.uk> <374796a4.6830363@news.skynet.be> <7hu96k$n24@sjx-ixn6.ix.netcom.com> <3744b557.14689856@news.skynet.be> <7huepb$k1n@dfw-ixnews11.ix.netcom.com> <3744D393.7339D3A@cc.newcastle.edu.au> <7i3cj9$rjt@dfw-ixnews5.ix.netcom.com> <7i3mp2$ccv$1@news.tuwien.ac.at> <7i3oga$39m@dfw-ixnews9.ix.netcom.com> <7i9fsi$bq9$1@news.tuwien.ac.at> <7i9qj5$d8j@sjx-ixn5.ix.netcom.com> Organization: Institut fuer Computersprachen, Technische Universitaet Wien Keywords: In article <7i9qj5$d8j@sjx-ixn5.ix.netcom.com>, Jonah Thomas writes: > anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote: > > >No ] -> execute > >prefix ] -> compile > >prefix ]] -> postpone > > >More is not needed, because we can postpone postponing words to > >achieve more. > > Yes! So we need no STATE at all. Yes, that's what I like about it. > We need only two immediate words > that can be built into the compiler, and everything else just does > its thing, either it executes, or ] compiles it, or ]] postpones it. With ] and ]] these words need not even be immediate, because everything is interpreted anyway. However, I don't like parsing words, so I prefer these as interpreter prefixes. Since we have only depth 0-2 of ]] (not infinite depth), we can simply use different letters for prefixes: [ -> execute _ -> compile ] -> postpone For experimentation I built a little program that patches the Gforth text interpreter: : doword ( ... xt c -- ... ) case '[ of execute endof '_ of compile, endof '] of postpone (compile) , endof -13 throw endcase ; : ]literal[ ( n -- ; compiles: -- n ) postpone literal ; : donumber ( n c -- ? ) case '[ of endof '_ of postpone literal endof '] of postpone literal postpone ]literal[ endof -13 throw endcase ; : newparser ( c-addr u -- ) over c@ >r 1 /string 2dup find-name ?dup-if ( c-addr1 u1 nt R: c ) nip nip name>comp drop r> doword else ( c-addr1 u1 R: c ) snumber? -1 = if \ just handle single numbers for now r> donumber else -13 throw endif endif ; : substituteword ( xt1 xt2 -- ) \ xt1 is substituted by xt2 over >body ! dodefer: swap code-address! ; ' compiler ' newparser substituteword ' interpreter ' newparser substituteword >From this point on everything needs to use prefixes. To see how this looks I have translated a POSTPONE-heavy program to this notation. The original: 200 constant row-size row-size cells constant row-byte-size : gen-innerproduct ( a[row][*] -- xt ) \ xt is of type ( b[*][column] -- n ) \ this would be a candidate for using ]] ... [[ >r :noname r> 0 POSTPONE literal POSTPONE SWAP row-size 0 do POSTPONE dup POSTPONE @ dup @ POSTPONE literal POSTPONE * POSTPONE under+ POSTPONE cell+ row-byte-size + loop drop POSTPONE drop POSTPONE ; ; And here's the new version: [5 [constant row-size [row-size [cells [constant row-byte-size [: gen-innerproduct [( a[row][*] -- xt ) [\ xt is of type ( b[*][column] -- n ) [\ this would be a candidate for using ]] ... [[ _>r _:noname _r> ]0 ]SWAP _row-size _0 [do ]dup ]@ _dup _@ _literal ]* ]under+ ]cell+ _row-byte-size _+ [loop _drop ]drop _; [; This is a kind of best case, but I think I could get used to this. > I thought I understood from Jeff Fox that the existing ColorForth > doesn't do it that way. Probably; it just inspired this idea that I find exciting. - anton -- M. Anton Ertl Some things have to be seen to be believed anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen http://www.complang.tuwien.ac.at/anton/home.html