Deutsch   English   Français   Italiano  
<slrn1028oma.22hk.anthk@openbsd.home.localhost>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: anthk <anthk@openbsd.home>
Newsgroups: comp.lang.forth
Subject: SUBLEQ and EForth
Date: Wed, 14 May 2025 09:31:12 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 93
Message-ID: <slrn1028oma.22hk.anthk@openbsd.home.localhost>
Injection-Date: Wed, 14 May 2025 11:31:12 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e32319b20dfb1e254981a76c7bf64c1";
	logging-data="2562281"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18YY3kJSXcFvWn2uEWbX94H"
User-Agent: slrn/1.0.3 (OpenBSD)
Cancel-Lock: sha1:z08qAgmqXuFSsjc8xL/MWNo3aYM=
Bytes: 3864

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.