News for hackers. Stuff that matters.
Re:Jonesforth – A sometimes minimal FORTH compiler and tutor... by listic on Tuesday September 08, 2015 @06:00PM (#10188439)
> Now some easy FORTH primitives. These are written in assembly for speed.

To think again, shouldn't a modern C/C++ compiler be able to produce better code than this assembly without the intrinsic unportability? Let's take, e.g. SWAP

    defcode "SWAP",4,,SWAP
    pop %eax		// swap top two elements on stack
    pop %ebx
    push %eax
    push %ebx
    NEXT
(and NEXT is)

    /* NEXT macro. */
    .macro NEXT
    lodsl
    jmp *(%eax)
    .endm
This won't really be blazing fast, or will it?
Re:Jonesforth – A sometimes minimal FORTH compiler and tutor... by rwmj on Tuesday September 08, 2015 @06:05PM (#10188461)
The NEXT macro and terrible use of the stack is kind of integral to threaded code. I'll let you read the tutorial to find out why :-)

In general you shouldn't expect FORTH to be fast -- it uses the stack far too much and the way it does branching kills branch prediction on modern CPUs.

However it is very small and a lot of fun to write. If you are looking for a system that can run on baremetal and where you can completely understand the system from top to bottom, then that's FORTH for you.

Compared to C, FORTH has an extensible syntax and features like exceptions. Compared to FORTH, C is a lot easier to write significant programs in.

Re:Jonesforth – A sometimes minimal FORTH compiler and tutor... by listic on Tuesday September 08, 2015 @06:13PM (#10188499)
I am nodding along, but we can't say we write in assembly for speed, if we don't achieve much of it, can we? Especially if portable C turns out to not actually be slower.
Re:Jonesforth – A sometimes minimal FORTH compiler and tutor... by rwmj on Tuesday September 08, 2015 @06:22PM (#10188531)
Yeah I'm not going to defend FORTH as a practical language -- it's annoying to write significant programs in it. However it does fit in a smaller space than C (probably).

I'm currently writing an ML derivative language for smaller systems and I hope that'll be practical while at the same time being a better alternative to C.

Re:Jonesforth – A sometimes minimal FORTH compiler and tutor... by sitkack on Wednesday September 09, 2015 @01:05AM (#10189789)
Have you looked at ATS? http://www.ats-lang.org/
Re:Jonesforth – A sometimes minimal FORTH compiler and tutor... by rwmj on Wednesday September 09, 2015 @07:21AM (#10190771)
Not until now. I was writing a language because it's fun, not because it's intended to be useful though.
Re:Jonesforth – A sometimes minimal FORTH compiler and tutor... by kryptiskt on Tuesday September 08, 2015 @06:22PM (#10188530)
This style of threaded code shines in making it compact. So it's useful for bootloaders and other very constrained environments.