Author |
Topic: BB4W FORTH Thoughts... (Read 1227 times) |
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #7 on: Sep 6th, 2009, 8:29pm » |
|
Quote:| Be aware of this from a Forth blog: |
|
I was already aware of that (and the compatibility problems with HERE, ALLOT, CREATE). Unfortunately ROT and -ROT can't straightforwardly be corrected, because they're used extensively in jonesforth.f.
In principle it would be possible to change the primitives, and then edit every occurrence in jonesforth.f, but then it would be incompatible with every other implementation of JonesForth. This would cause problems updating to a later version, if one was ever released by Richard Jones.
Not being a Forth enthusiast, I don't really understand why the mistakes went uncorrected up to version 45, and still haven't been. I can only assume that the language isn't as standardised as some, and that users cope with this kind of thing.
It would appear that JonesForth was written by somebody who knew (at the start) virtually nothing about Forth. As a result the implementation is faulty in several respects, and wastefully inefficient in others. Unfortunately it's the only 'free' IA-32 implementation of Forth that I know of.
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #8 on: Sep 6th, 2009, 8:31pm » |
|
Quote:| So typing GetTickCount would execute the relevant item putting the returns on the FORTH stack ? |
|
No, you'd have to do:
Code: (with my proposal of adding SYSADDR and SYSCALL words).
Richard.
|
|
Logged
|
|
|
|
afarlie
New Member
member is offline


Posts: 18
|
 |
Re: BB4W FORTH Thoughts...
« Reply #9 on: Sep 6th, 2009, 9:37pm » |
|
on Sep 6th, 2009, 8:29pm, Richard Russell wrote:I was already aware of that (and the compatibility problems with HERE, ALLOT, CREATE). Unfortunately ROT and -ROT can't straightforwardly be corrected, because they're used extensively in jonesforth.f.
....
It would appear that JonesForth was written by somebody who knew (at the start) virtually nothing about Forth. As a result the implementation is faulty in several respects, and wastefully inefficient in others. Unfortunately it's the only 'free' IA-32 implementation of Forth that I know of.
Richard. |
|
on Sep 6th, 2009, 8:29pm, Richard Russell wrote: Unfortunately it's the only 'free' IA-32 implementation of Forth that I know of. |
|
In terms of other 'free'-ish FORTH's around there are :
gForth http://www.jwdt.com/~paysan/gforth.html - GNU Forth implementation ( which being GNU is assumed to be GPL)
There is also Win32Forth (http://win32forth.sourceforge.net/) which also has a Yahoo group - here (http://tech.groups.yahoo.com/group/win32forth/)
It may be possible to patch Win32Forth to use oswrch or to use Win32Forth as reference for someone willing to fix JonesForth's shortcomings.
There are also seemingly a number of freeware and proprietary systems targeting both i386 and ARM (There are some fairly developed FORTH's for RISC OS if anyones interested.)
Obviously these may not implement their output via oswrch, or use the intended SYSADDR and SYSCALL words that were being considered for addition to the JonesForth port.
if anyone is still bothered at this point, the 'standard' for ANS FORTH appears to have been archived here... "http://www.taygeta.com/forth/dpans.htm".
|
| « Last Edit: Sep 6th, 2009, 9:48pm by afarlie » |
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #10 on: Sep 6th, 2009, 10:01pm » |
|
Quote:| gForth... There is also Win32Forth |
|
I'm pretty sure they're both written in C (or C++), so not really relevant to the current discussion.
Quote:| There are also seemingly a number of freeware and proprietary systems targeting both i386 and ARM |
|
In the context of Forth, i386 may mean 16-bit (i.e. MS-DOS), so again not really relevant to BB4W; and of course ARM code is totally incompatible.
Let's not lose sight of the fact that we are here primarily discussing BBC BASIC, not Forth! This is not the place to talk about Forth in general, or other ways in which to get Forth working under Windows.
I still see some benefits of a BBC BASIC-hosted Forth, principally the VDU drivers which give easy access to a graphical output capability. At the moment that means JonesForth, for good or ill.
If the consensus of opinion is that the shortcomings of JonesForth make it unacceptable, I suggest we draw this to a close. Those interested more in Forth than in BBC BASIC are requested to take their discussions elsewhere.
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #11 on: Sep 7th, 2009, 12:27pm » |
|
Rich Jones, the author of JonesForth, has contacted me to ask if he can link to the BBC BASIC version on his site! I've responded, for the moment, to the effect that it isn't appropriate to promote it until issues such as the ROT/-ROT reversal are addressed.
I've also asked questions on comp.lang.forth, where one correspondent has described JonesForth as "pretty hopeless".
So I still don't know what is the best course of action. It would seem a shame to abandon the considerable work I have done so far, but if JonesForth is incapable of becoming a 'useful' Forth implementation then I don't want to waste my time expending extra effort.
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #12 on: Sep 8th, 2009, 3:51pm » |
|
Quote:My thinking about API access was similar to yours, but I'd envisaged just a single word, e.g. SYSADDR, which would be used as follows: S" GetTickCount" S" kernel32" SYSADDR |
|
That appears to be impossible (in Jonesforth at least) because there's only one buffer for strings, so "GetTickCount" immediately gets overwritten with "kernel32".
I can split the LoadLibrary and GetProcAddress into separate words, as somebody suggested, but I need a word for FreeLibrary as well:
Code:Z" kernel32.dll" LoadLibrary DUP
Z" GetTickCount" GetProcAddress
CONSTANT GetTickCount
GetTickCount SYSCALL .
6491875
GetTickCount SYSCALL .
6499843
FreeLibrary
It works, as you can see (this is a snapshot of the actual output), but it's messy. Can anybody think of a nicer way?
Richard.
|
| « Last Edit: Sep 8th, 2009, 9:48pm by admin » |
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #14 on: Sep 14th, 2009, 2:15pm » |
|
I have uploaded the latest version (0.22) of BB4Wforth:
http://groups.yahoo.com/group/bb4w/files/Miscellaneous/forth.zip
Changes in this version include:
1. The following standard Forth words, which work incorrectly in Jonesforth (v45), have been corrected: ROT, -ROT, ALLOT, DEPTH, HERE, MOD, / and U. (etc.)
2. The following standard Forth words, which aren't present at all in Jonesforth (v45) have been added: ROLL, DO, ?DO, LOOP, +LOOP, I, J, LEAVE, UNLOOP, <BUILDS, DOES>
3. The following custom Forth words (specific to this version) have been added: ERR, OSCLI, SYSCALL, HWND, VERSION$, LoadLibrary, FreeLibrary, GetProcAddress, EMIT16, XY, MODE, CLS, CLG, COLOUR, GCOL, ORIGIN, PLOT, MOVE, DRAW, FILL, MOVEBY, DRAWBY, EXEC
4. Operation of the following Forth words has been slightly modified: DEPTH, .S
Also supplied is the program fern.f which is a Forth version of the FERN.BBC graphics demo supplied with BB4W (translating it into Forth with virtually zero knowledge of the language was interesting!):
Code:\ 'Fake' fractal fern
\ Original QBASIC program published in PC Magazine
\ BB4Wforth version by Richard Russell, 14-Sep-2009
VARIABLE RND
: RANDOM ( n -- u ) RND @ 134775813 * 1 + DUP RND ! SWAP U/MOD DROP 1 + ;
: FERN
8 MODE
2 0 GCOL
0 0 ( X Y )
80000 1 DO ( Loop 80000 times )
100 RANDOM
DUP 10 <= IF DROP
SWAP DROP 0 SWAP 16 * 100 /
ELSE
DUP 86 <= IF DROP
2DUP 2DUP ( X Y X Y X Y )
4 * 100 / SWAP 85 * 100 / + ( X Y X Y x )
-ROT ( X Y x X Y )
85 * 100 / SWAP 4 * 100 / - 160 + ( X Y x y )
2SWAP 2DROP
ELSE
DUP 93 <= IF DROP
2DUP 2DUP ( X Y X Y X Y )
-26 * 100 / SWAP 20 * 100 / + ( X Y X Y x )
-ROT ( X Y x X Y )
22 * 100 / SWAP 23 * 100 / + 160 + ( X Y x y )
2SWAP 2DROP
ELSE DROP
2DUP 2DUP ( X Y X Y X Y )
28 * 100 / SWAP 15 * 100 / - ( X Y X Y x )
-ROT ( X Y x X Y )
24 * 100 / SWAP 26 * 100 / + 44 + ( X Y x y )
2SWAP 2DROP
THEN
THEN
THEN
2DUP SWAP 600 + SWAP 2DUP MOVE DRAW
LOOP
2DROP
." OK"
;
FERN You can run the program from BB4Wforth using the command:
Code: As this thread has gone very quiet, I would value any feedback, bug reports etc. to indicate that somebody out there is appreciative of my efforts!
Richard.
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: BB4W FORTH Thoughts...
« Reply #15 on: Sep 14th, 2009, 3:04pm » |
|
on Sep 14th, 2009, 2:15pm, Richard Russell wrote:I have uploaded the latest version (0.22) of BB4Wforth:
[As this thread has gone very quiet, I would value any feedback, bug reports etc. to indicate that somebody out there is appreciative of my efforts!
Richard. |
|
Richard, yes, this is very much appreciated.
I tested yesterday some programs from the Forth book from Leo Brody, using BB4WForth, and that went fine. Now even with graphics.
Note: See also http://www.techworld.com.au/article/250530/-z_programming_languages_forth which might be an interesting read.
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
afarlie
New Member
member is offline


Posts: 18
|
 |
Re: BB4W FORTH Thoughts...
« Reply #16 on: Sep 14th, 2009, 3:06pm » |
|
on Sep 14th, 2009, 2:15pm, Richard Russell wrote:
Perhaps this thread should now be entitled BB4th? 
Fern examples works as intended.
In terms of EMIT16 the U/MOD word wasn't something I knew about, but my graphics code was planning on doing that as well.
I'll post my graphics code later, (the reason for ROLL) was to do with some VDU commands like viewports which need a rectangle (i.e 2 XY pairs rather than a single)
Having an indication of a stack underflow is useful. 
Quote:Changes in this version include:
1. The following standard Forth words, which work incorrectly in Jonesforth (v45), have been corrected: ROT, -ROT, ALLOT, DEPTH, HERE, MOD, / and U. (etc.)
2. The following standard Forth words, which aren't present at all in Jonesforth (v45) have been added: ROLL, DO, ?DO, LOOP, +LOOP, I, J, LEAVE, UNLOOP, <BUILDS, DOES>
|
|
I will have to do some reading to understand these in more depth.
Quote:3. The following custom Forth words (specific to this version) have been added: ERR, OSCLI, SYSCALL, HWND, VERSION$, LoadLibrary, FreeLibrary, GetProcAddress, EMIT16, XY, MODE, CLS, CLG, COLOUR, GCOL, ORIGIN, PLOT, MOVE, DRAW, FILL, MOVEBY, DRAWBY, EXEC
|
|
And the documentation is remarkably clear .
It' should not be that hard to add more advanced commands..
Digging out the MIDITEST example is something else I might look at, given that there isn't an AMPLE like system on Windows... (Reimplementing all of AMPLE is beyond me, (some of it being Intterurpt driven 6502 code, but I could at least have a go at seeing if something is possible with simple MIDI maybe...)
Quote:4. Operation of the following Forth words has been slightly modified: DEPTH, .S |
|
I assume what this now does is explained in the code? I must go and read it 
The Fern demo worked fine for me 
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #17 on: Sep 14th, 2009, 4:45pm » |
|
Quote:| I assume what this now does is explained in the code? |
|
Nope, no explanations! You'll have to find out by experiment what the difference is; sorry. This was a 'minimum effort' exercise which has already taken up more of my time than I intended.
Richard.
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: BB4W FORTH Thoughts...
« Reply #18 on: Sep 14th, 2009, 5:17pm » |
|
I have put on my wish list (to maybe todo one time) and am playing with the thought to create a Forth implementation in pure BBCBASIC for Windows (thus not assembler).
Maybe base it on some existing BASIC implementation somewhere to be found.
There is or there seems to be no Backus Naur Form or formal syntax for Forth. If that would have existed that would maybe have made the implementation a little bit more streamlined and to be created more automated.
But I might diverge soon, as usual.
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: BB4W FORTH Thoughts...
« Reply #19 on: Sep 14th, 2009, 6:51pm » |
|
For those wanting maybe to compare the Forth source code in fern.f versus an equivalent BBCBASIC, here an approximate equivalent.
MODE 8 GCOL 0, 2 VDU 29, 639; 0; X = 0: Y = 0 COLOUR 15 PRINT TAB( 1, 1 ); "Fractal Fern" PRINT TAB( 1, 2 ); "from PC Magazine" FOR I = 1 TO 40000 : R = RND( 1 ) : IF (R <= .01) THEN A = 0: B = 0: C = 0: D = .16: E = 0: F = 0 ELSEIF R > .01 AND R <= .86 THEN; A = .85: B = .04: C = -.04: D = .85: E = 0: F = 1.6 ELSEIF R > .86 AND R <= .93 THEN; A = .2: B = -.26: C = .23: D = .22: E = 0: F = 1.6 ELSE A = -.15: B = .28: C = .26: D = .24: E = 0: F = .44 ENDIF : NEWX = (A * X) + (B * Y) + E NEWY = (C * X) + (D * Y) + F : PLOT 69, 100 * X, 100 * Y : X = NEWX: Y = NEWY : NEXT I : END
|
|
Logged
|
|
|
|
David Williams
Developer
member is offline

meh

Gender: 
Posts: 452
|
 |
Re: BB4W FORTH Thoughts...
« Reply #20 on: Sep 14th, 2009, 8:11pm » |
|
on Sep 14th, 2009, 6:51pm, knudvaneeden wrote:| For those wanting maybe to compare the Forth source code in fern.f versus an equivalent BBCBASIC, here an approximate equivalent. |
|
Didn't Richard do a one-line version of that program?
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #21 on: Sep 14th, 2009, 9:23pm » |
|
Quote:| Didn't Richard do a one-line version of that program? |
|
Indeed so:
Code:MODE8:GCOL2:OFF:x=0:y=0:FORI=1TO80000:r=RND(1):s=r>.1:t=r>.86:u=r>.93:A=-.86*s+.65*t+.35*u:B=-.04*s+.3*t-.54*u:C=.04*s-.27*t-.01*u:D=.16-.69*s+.63*t-.02*u:F=-1.6*s+1.16*u:z=A*x+B*y:y=C*x+D*y+F:x=z:LINE600+96*x,32+96*y,600+96*x,32+96*y:NEXT Richard.
|
|
Logged
|
|
|
|
|