SUBLEQ and EForth

Liste des GroupesRevenir à cl forth 
Sujet : SUBLEQ and EForth
De : anthk (at) *nospam* openbsd.home (anthk)
Groupes : comp.lang.forth
Date : 14. May 2025, 10:31:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <slrn1028oma.22hk.anthk@openbsd.home.localhost>
User-Agent : slrn/1.0.3 (OpenBSD)
SUBLEQ from this author it's a 16 bit virtual machine with just one instruction:

https://github.com/howerj/sublec

subtract 'a' from 'b', store it under 'b' and if it's equal or less
than 0, jump to whatever address it's being pointed at 'c'.

https://en.wikipedia.org/wiki/One-instruction_set_computer

The programmer wrote an Eforth image runnable under Subleq.

This is a whole subleq program in C:

#include <stdio.h>
int main
(int x, char **v) {
FILE           *f = fopen(v[1], "r");
short p = 0, m[1 << 16], *i = m;
while (fscanf(f, "%hd", i++) > 0);
for (; p >= 0;) {
int a = m[p++], b = m[p++], c = m[p++];
a < 0 ? m[b] =
getchar() : b < 0 ? putchar(m[a]) : (m[b] -= m[a]) <= 0 ? p = c : 0;
}
}

Here's the subleq image: https://raw.githubusercontent.com/howerj/subleq/master/subleq.dec

Run it as ./subleq ./subleq.dec

It you want speed, there's muxleq, which runs a lot faster than subleq.
Muxleq multiplexes instructions. Again:

https://github.com/howerj/muxleq

He created a book too, but I didn't get it yet, altough
subleq.fth and muxleq.fth are highly documented.

If you want float numbers support among other nice addons,
edit the fth files (the opt.* parts at the beginning)
 and redo the image. For instance:

1 constant opt.control

will add do...loop support instead of just the eforth words
with for...next (which can be added to pforth too).

Regenerate it:

./subleq ./sublec.dec < sublec.fth > new.fth

It will last for LONG on older machines; so you maybe
ask someone to recreate the SUBLEQ image for you.

Under muxleq the generation speed will be a bit faster.

The overall speed with Muxleq under an ATOM can be taken
as a machine between a Altair 8800/S100 BUS machine with CP/M
and a boosted up Jupiter ACE. Not bad at all.

Subleq (even muxleq) emulators are very slow under Perl and
Python implementations, and the Forth one it's even slower
under PForth, but it might run fast enough under GForth or
some optimized ANS Forth for Windows:

https://github.com/howerj/subleq-forth

As a hint, I compiled C muxleq like this:

cc -o muxleq muxleq.c -ffast-math -O3 -march=atom

because the float numbers are not done with
the system math library at all.

Finally, there's an EForth+Subleq port as an OS,
from a bootable X86 image. I'd guess a PentiumIII
would be needed to get usable speeds (if not more):

https://github.com/pbrochard/subleq-eForthOS

Obviously it can't compare to a bare X86 bootable Forth
or CiForth under SVARDOS, but maybe running SUBLEQ
natively gets somehow to 386 or low end 486 speeds
under a Pentium III.

It's an interesting concept to get a mega-portable
Forth, because a Subleq interpreter can run everywhere
with very few lines, even AWK.

But forget about performance under pre SSE2 machines
or non C/ASM SUBLEQ virtual machines and any other
SUBLEQ implementation than MUXLEQ. SUBLEQ it's usable
but MUXLEQ with just two lines more gets a big boost.

Date Sujet#  Auteur
14 May 25 * SUBLEQ and EForth4anthk
14 May 25 `* Re: SUBLEQ and EForth3Hans Bezemer
15 May 25  +- Re: SUBLEQ and EForth1anthk
17 May 25  `- Re: SUBLEQ and EForth1anthk

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal