Forth Foundation Library

30 views
Skip to first unread message

The Beez

unread,
Apr 16, 2025, 8:31:41 AMApr 16
to 4tH-compiler
Hi 4tH-ers!

As I've always said - "we're a sailing club and we go where the winds blow". In the past I've picked up a handful of FFL modules, mostly because it featured functionality we didn't have and because they were relative easy to convert.

Now, recently I came across those again - and it triggered my attention. So I picked up a few more modules and converted them. Which was much easier as I thought as long as you didn't fiddle too much with 'em. In essence they're decently written in the sense they're not too hard to port.

And you can do so quickly, because each comes with a test program. And that one works even better on 4tH than the official ANS-Forth ones. So, crank out the oddities of a module, test it and we're done. Doing it that way - I can easily do two a day. No sweat.

So far I've added a few additional ones to the 4tH library. I don't know how long this will keep me interested, but every single one is a win, I guess.

Now - be assured that these are not the kind of libraries I'd like to see. These ones are real whoppers, easily amounting to thousand or more opcodes. And also the style differs from mine. It's not my way of coding. But still, if it helps to extend the possibilities 4tH offers - why not. In the end, the choice is your.

Dick has stopped updating the library, so in essence it is dead code. But it's interesting to read his note. He knows 4tH, but dismisses it because "it lacks ANS words". That's not completely true. They are there, but in library form. And I need to add in quite a few libs in general to get them to compile and run. But they DO run.

I got quite a few in the repository now. The modules themselves retained their original names (up to now) and can be found in the library. You'll find the test programs in the demo directory.

Code in SVN.

Hans Bezemer

The Beez

unread,
Apr 17, 2025, 9:15:55 AMApr 17
to 4tH-compiler
Wow...

Like I said - I've been doing some FFL conversions - and since the "complex number module" didn't have too many dependencies, I thought "let's do that one". I thought I'd crash and burn completely once the test program ran, and all it said was:

$ pp4th -x cpx_test.4pp
Testing: cpx
$ _

I even faked an error to check I was not dreaming:

$ pp4th -x cpx_test.4pp
Testing: cpx
float stack contents mismatch:   expecting 1.902976700000000000000000000000000000 and found -1.90297670599501626511304974657454469
$ _

Considering the preamble was like this:

[UNDEFINED] cpx.version [IF]
  [DEFINED] ZenFP       [IF] [ABORT] [THEN]  \ we require ANS floats!
[UNDEFINED] fsincos     [IF] include lib/fsinfcos.4th [THEN]  
[UNDEFINED] fexp        [IF] include lib/fexp.4th     [THEN]
[UNDEFINED] fln         [IF] include lib/flnflog.4th  [THEN]
[UNDEFINED] fatan2      [IF] include lib/fatan2.4th   [THEN]
[UNDEFINED] represent   [IF] include lib/represnt.4th [THEN]
[UNDEFINED] allocate    [IF] include lib/memcell.4th  [THEN]  
[UNDEFINED] fs>         [IF] include lib/fstack.4th   [THEN]
[UNDEFINED] f>r         [IF]
  32 FLOATS CELL+ ARRAY (fstk) LATEST FSTACK
  : f>r (fstk) >fs ;
  : fr> (fstk) fs> ;
  : fr@ (fstk) fs@ ;
[THEN]
( lots of other things)
[THEN]

That's a LOT of words. That's a LOT of places where things can go wrong. I even faked a FP stack. But it went fine. First try. Can't believe it. We got complex numbers.

Hans Bezemer

The Beez

unread,
Apr 28, 2025, 12:42:28 PMApr 28
to 4tH-compiler
Hi 4tH-ers!

Gee, I thought "Let's start with "a" and work my way down." Well, that was a bummer. The first one was a binary tree - and it was like unfolding a Matryoshka - every time you thought "That must be enough nesting" another one popped up. For some reason I reached the end of the barrel and was able to perform the tests - and then another module was required. With its own test.

Finally, at the end of the afternoon, it compiled and ran. Okay, the heap was too small, but that was easily fixed. 64K did it. So I could add a carload of modules. Nice. I also added a section on it in the manual, although I didn't go into great depth. Still, it all has to be added to the reference chapter. But that's another story.

Finally, some commands couldn't be implemented in 4tH, but of course, PP4tH has no problems here. So I added a FFL.4PP to the library. If you want to do vanilla FFL, you can.

Hans Bezemer
Reply all
Reply to author
Forward
0 new messages