Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

No man is an island if he's on at least one mailing list.


devel / comp.lang.forth / Re: Single-pass or multi-pass Forth compiler

SubjectAuthor
* Single-pass or multi-pass Forth compilerminf...@arcor.de
+* Re: Single-pass or multi-pass Forth compilerJan Coombs
|`- Re: Single-pass or multi-pass Forth compilerminf...@arcor.de
+* Re: Single-pass or multi-pass Forth compilerAnton Ertl
|`* Re: Single-pass or multi-pass Forth compilerminf...@arcor.de
| `* Re: Single-pass or multi-pass Forth compilerAnton Ertl
|  `- Re: Single-pass or multi-pass Forth compilerminf...@arcor.de
+- Re: Single-pass or multi-pass Forth compilerHans Bezemer
+* Re: Single-pass or multi-pass Forth compilerMarcel Hendrix
|+- Re: Single-pass or multi-pass Forth compilerminf...@arcor.de
|`- Re: Single-pass or multi-pass Forth compilernone
+* Re: Single-pass or multi-pass Forth compilerGerry Jackson
|`* Re: Single-pass or multi-pass Forth compilerminf...@arcor.de
| `* Re: Single-pass or multi-pass Forth compilerGerry Jackson
|  `- Re: Single-pass or multi-pass Forth compilerminf...@arcor.de
+- Re: Single-pass or multi-pass Forth compilerLars Brinkhoff
+- Re: Single-pass or multi-pass Forth compilernone
+- Re: Single-pass or multi-pass Forth compilerdxforth
`* Re: Single-pass or multi-pass Forth compilerMatthias Koch
 `* Re: Single-pass or multi-pass Forth compilerminf...@arcor.de
  `* Re: Single-pass or multi-pass Forth compilerMatthias Koch
   `* Re: Single-pass or multi-pass Forth compilerminf...@arcor.de
    +* Re: Single-pass or multi-pass Forth compilerminf...@arcor.de
    |`- Re: Single-pass or multi-pass Forth compilerMatthias Koch
    `- Re: Single-pass or multi-pass Forth compilerMatthias Koch

1
Single-pass or multi-pass Forth compiler

<74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22017&group=comp.lang.forth#22017

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a0c:80c3:0:b0:531:ad72:d8b8 with SMTP id 61-20020a0c80c3000000b00531ad72d8b8mr3485452qvb.3.1673869826896;
Mon, 16 Jan 2023 03:50:26 -0800 (PST)
X-Received: by 2002:a25:e7d2:0:b0:7c0:46a9:5e62 with SMTP id
e201-20020a25e7d2000000b007c046a95e62mr2392959ybh.245.1673869826732; Mon, 16
Jan 2023 03:50:26 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 16 Jan 2023 03:50:26 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:376:196b:6f51:c972:c255;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:376:196b:6f51:c972:c255
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
Subject: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Mon, 16 Jan 2023 11:50:26 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1707
 by: minf...@arcor.de - Mon, 16 Jan 2023 11:50 UTC

Historically Forth features a single-pass compiler that is triggered e.g.
when the interpreter hits a : colon. Some control flows require code
back-patching to resolve jump targets. This can be awkward.

OTOH by going over the code in several passes offers easy paths for
simplification and optimization. e.g.
- elimination of comments
- resolving of labels for jump targets
- intermediate language e.g. program as database of instruction lists
- peephole optimization, superinstructions
- tail call elimination

Is there any Forth out there that compiles high-level definitions in this way?
Anybody willing to share some other experience in this field?

Re: Single-pass or multi-pass Forth compiler

<20230116142659.02d22a71@t530>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22020&group=comp.lang.forth#22020

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: jan4comp...@murray-microft.co.uk (Jan Coombs)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Mon, 16 Jan 2023 14:26:59 +0000
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <20230116142659.02d22a71@t530>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: reader01.eternal-september.org; posting-host="2cc2dd2ac24d61fda3c1560b60d9e509";
logging-data="2881674"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2WPJPrgjIsiB4iE10xaTluQLc6ygWCzs="
Cancel-Lock: sha1:1oRH9D3HwQeF4iN7t4c00sKzLqs=
X-Newsreader: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu)
 by: Jan Coombs - Mon, 16 Jan 2023 14:26 UTC

On Mon, 16 Jan 2023 03:50:26 -0800 (PST)
"minf...@arcor.de" <minforth@arcor.de> wrote:

> - intermediate language e.g. program as database of instruction lists

Maybe this one in 'Holon Forth' and 'Fifth':

Planet Holonforth Wolf Wejgaard EuroForth 2016
http://www.euroforth.org/ef16/papers/wejgaard.pdf

1989-09-00 Paper presented at the EuroFORML conference 1989
Not Screens nor Files but Words Wolf Wejgaard
https://holonforth.com/ef89.html

Further papers at:
https://www.holonforth.com/papers.html

Ref to Fifth was in:
A Fresh Look at the Forth Dictionary
Wolf Wejgaard
Presented at the EuroFORTH conference 1995
https://www.holonforth.com/ef95.html

Jan Coombs
--

Re: Single-pass or multi-pass Forth compiler

<2023Jan16.172717@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22022&group=comp.lang.forth#22022

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Mon, 16 Jan 2023 16:27:17 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 38
Message-ID: <2023Jan16.172717@mips.complang.tuwien.ac.at>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
Injection-Info: reader01.eternal-september.org; posting-host="4c7b5b5cfc50f86fce324c1120302d3a";
logging-data="2938002"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8MULuSzaxdlVDWL4htj2C"
Cancel-Lock: sha1:q3sLz+H7gxMRdap8wJ2OcNdk00Y=
X-newsreader: xrn 10.11
 by: Anton Ertl - Mon, 16 Jan 2023 16:27 UTC

"minf...@arcor.de" <minforth@arcor.de> writes:
>Historically Forth features a single-pass compiler that is triggered e.g.
>when the interpreter hits a : colon. Some control flows require code
>back-patching to resolve jump targets. This can be awkward.
>
>OTOH by going over the code in several passes offers easy paths for
>simplification and optimization. e.g.
>- elimination of comments
>- resolving of labels for jump targets
>- intermediate language e.g. program as database of instruction lists
>- peephole optimization, superinstructions
>- tail call elimination
>
>Is there any Forth out there that compiles high-level definitions in this way?
>Anybody willing to share some other experience in this field?

Passes in the original sense have gone out of fashion once RAM sizes
were big enough. Compilers often have intermediate representations
for purposes such as analysis and optimization, and for modularization
purposes.

iForth and VFX have an intermediate representation that they use for
inlining. AFAIK they don't use it for elimination of comments, jump
target resolution, peephole optimization, superinstructions, or
tail-call elimination.

Gforth uses the threaded-code representation (and its relocatable
variant) either directly, or as a step to a mixture of native code and
threaded-code. It also buffers the threaded code for a straight-line
piece of code before generating native code, to allow better code
generation.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2022: https://euro.theforth.net

Re: Single-pass or multi-pass Forth compiler

<36e0fc27-1063-454c-9f97-7be1fa21cd57n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22023&group=comp.lang.forth#22023

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:29d1:b0:706:7088:1fe9 with SMTP id s17-20020a05620a29d100b0070670881fe9mr236638qkp.11.1673887387270;
Mon, 16 Jan 2023 08:43:07 -0800 (PST)
X-Received: by 2002:a81:4e4f:0:b0:3ba:721f:b37c with SMTP id
c76-20020a814e4f000000b003ba721fb37cmr6239162ywb.457.1673887387047; Mon, 16
Jan 2023 08:43:07 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 16 Jan 2023 08:43:06 -0800 (PST)
In-Reply-To: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <36e0fc27-1063-454c-9f97-7be1fa21cd57n@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Mon, 16 Jan 2023 16:43:07 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2417
 by: Hans Bezemer - Mon, 16 Jan 2023 16:43 UTC

On Monday, January 16, 2023 at 12:50:28 PM UTC+1, minf...@arcor.de wrote:
> OTOH by going over the code in several passes offers easy paths for
> simplification and optimization. e.g.
> - elimination of comments
I can't think of a Forth compiler that DOESN'T. It simply ignores the stuff:

: \ blk @ IF >in @ c/l /f 1+ c/l * >in ! EXIT THEN source >in ! drop ; immediate

> - resolving of labels for jump targets
Again - I can't think of a Forth compiler that doesn't. References are placed on
some stack and used as target addresses when jumping back or as source
addresses to be patched later when jumping forward.

> - peephole optimization, superinstructions
4tH has a peephole optimizer used for strength reduction, constant folding and
dead code elimination. It only looks back a single instruction, but can in some
circumstances work recursive.

> - tail call elimination
4tH's optimizer does that one as well.
> Is there any Forth out there that compiles high-level definitions in this way?
> Anybody willing to share some other experience in this field?
It works fine and transparent - unless you insist to meddle with the return stack
in non-portable ways.

https://sourceforge.net/p/forth-4th/wiki/Optimization/

Hans Bezemer

Re: Single-pass or multi-pass Forth compiler

<c211daee-ca84-4ec0-993d-c0982b238d9an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22024&group=comp.lang.forth#22024

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:2008:b0:706:5745:924f with SMTP id c8-20020a05620a200800b007065745924fmr169072qka.214.1673890768714;
Mon, 16 Jan 2023 09:39:28 -0800 (PST)
X-Received: by 2002:a81:6c4c:0:b0:4dc:f746:7851 with SMTP id
h73-20020a816c4c000000b004dcf7467851mr13597ywc.175.1673890768487; Mon, 16 Jan
2023 09:39:28 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 16 Jan 2023 09:39:28 -0800 (PST)
In-Reply-To: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f14:600:40b2:c413:58f3:153d;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f14:600:40b2:c413:58f3:153d
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c211daee-ca84-4ec0-993d-c0982b238d9an@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: mhx...@iae.nl (Marcel Hendrix)
Injection-Date: Mon, 16 Jan 2023 17:39:28 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2205
 by: Marcel Hendrix - Mon, 16 Jan 2023 17:39 UTC

On Monday, January 16, 2023 at 12:50:28 PM UTC+1, minf...@arcor.de wrote:
> Historically Forth features a single-pass compiler that is triggered e.g.
> when the interpreter hits a : colon. Some control flows require code
> back-patching to resolve jump targets. This can be awkward.
>
> OTOH by going over the code in several passes offers easy paths for
> simplification and optimization. e.g.
[..]
> Is there any Forth out there that compiles high-level definitions in this way?

Using an intermediate representation is far more powerful, as one can
do recursive 'context-sensitive' inlining (delay compiling as long as possible).

In iForth's iSPICE package I'll eventually use run-time code generation (e.g.
to eliminate pointer-chasing). This delays instruction selection to the limit.
However, it only works if the target application is sufficiently unsophisticated,
or has predictable execution behavior (like SPICE). I'm sure that there would
be many snags would I try it for Forth itself.

-marcel

Re: Single-pass or multi-pass Forth compiler

<50158838-6b0c-4dd5-98a4-6f7d314c0664n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22025&group=comp.lang.forth#22025

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:1026:b0:706:91a1:e215 with SMTP id a6-20020a05620a102600b0070691a1e215mr417qkk.350.1673897373839;
Mon, 16 Jan 2023 11:29:33 -0800 (PST)
X-Received: by 2002:a25:3089:0:b0:7d5:b865:6f59 with SMTP id
w131-20020a253089000000b007d5b8656f59mr111144ybw.5.1673897373491; Mon, 16 Jan
2023 11:29:33 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 16 Jan 2023 11:29:33 -0800 (PST)
In-Reply-To: <20230116142659.02d22a71@t530>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:373:e933:e078:2fe8:fa96;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:373:e933:e078:2fe8:fa96
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com> <20230116142659.02d22a71@t530>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <50158838-6b0c-4dd5-98a4-6f7d314c0664n@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Mon, 16 Jan 2023 19:29:33 +0000
Content-Type: text/plain; charset="UTF-8"
 by: minf...@arcor.de - Mon, 16 Jan 2023 19:29 UTC

Jan Coombs schrieb am Montag, 16. Januar 2023 um 16:05:04 UTC+1:
> On Mon, 16 Jan 2023 03:50:26 -0800 (PST)
> "minf...@arcor.de" <minf...@arcor.de> wrote:
>
> > - intermediate language e.g. program as database of instruction lists
> Maybe this one in 'Holon Forth' and 'Fifth':
>
> Planet Holonforth Wolf Wejgaard EuroForth 2016
> http://www.euroforth.org/ef16/papers/wejgaard.pdf
>
> 1989-09-00 Paper presented at the EuroFORML conference 1989
> Not Screens nor Files but Words Wolf Wejgaard
> https://holonforth.com/ef89.html
>
> Further papers at:
> https://www.holonforth.com/papers.html
>
> Ref to Fifth was in:
> A Fresh Look at the Forth Dictionary
> Wolf Wejgaard
> Presented at the EuroFORTH conference 1995
> https://www.holonforth.com/ef95.html

I seem to remember Holon running on DOS. Last time I looked I got the impression
that it was a nice mixture of Tcl and Forth, with most fun parts included from Tcl libraries.
Good work, not criticizing, but running an interpreter through another interpreter
seemed rather heavy to me.

Nevertheless the "modules/groups/dictionary/words in a database" is an appealing
concept.

Re: Single-pass or multi-pass Forth compiler

<6ce36efc-fcd6-4758-a9f6-388d1cdc3616n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22026&group=comp.lang.forth#22026

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:4b5a:0:b0:3b6:32fa:23e3 with SMTP id e26-20020ac84b5a000000b003b632fa23e3mr5577qts.132.1673898434088;
Mon, 16 Jan 2023 11:47:14 -0800 (PST)
X-Received: by 2002:a81:351:0:b0:36c:aaa6:e571 with SMTP id
78-20020a810351000000b0036caaa6e571mr38287ywd.467.1673898433916; Mon, 16 Jan
2023 11:47:13 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 16 Jan 2023 11:47:13 -0800 (PST)
In-Reply-To: <c211daee-ca84-4ec0-993d-c0982b238d9an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:373:e933:e078:2fe8:fa96;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:373:e933:e078:2fe8:fa96
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com> <c211daee-ca84-4ec0-993d-c0982b238d9an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6ce36efc-fcd6-4758-a9f6-388d1cdc3616n@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Mon, 16 Jan 2023 19:47:14 +0000
Content-Type: text/plain; charset="UTF-8"
 by: minf...@arcor.de - Mon, 16 Jan 2023 19:47 UTC

Marcel Hendrix schrieb am Montag, 16. Januar 2023 um 18:39:29 UTC+1:
> On Monday, January 16, 2023 at 12:50:28 PM UTC+1, minf...@arcor.de wrote:
> > Historically Forth features a single-pass compiler that is triggered e.g.
> > when the interpreter hits a : colon. Some control flows require code
> > back-patching to resolve jump targets. This can be awkward.
> >
> > OTOH by going over the code in several passes offers easy paths for
> > simplification and optimization. e.g.
> [..]
> > Is there any Forth out there that compiles high-level definitions in this way?
> Using an intermediate representation is far more powerful, as one can
> do recursive 'context-sensitive' inlining (delay compiling as long as possible).
>
> In iForth's iSPICE package I'll eventually use run-time code generation (e.g.
> to eliminate pointer-chasing). This delays instruction selection to the limit.
> However, it only works if the target application is sufficiently unsophisticated,
> or has predictable execution behavior (like SPICE). I'm sure that there would
> be many snags would I try it for Forth itself.
>

Interesting. I never considered lazy evaluation for Forth.

Without climbing up to Haskell's heights, there are simple "lazy evaluators in Python
(copied from Stackoverflow):
######
In a nutshell, lazy evaluation means that the object is evaluated when it is needed,
not when it is created.
In Python 2, range will return a list - this means that if you give it a large number,
it will calculate the range and return at the time of creation:
>>> i = range(100)
>>> type(i)
<type 'list'>
In Python 3, however you get a special range object:
>>> i = range(100)
>>> type(i)
<class 'range'>
Only when you consume it, will it actually be evaluated - in other words, it will only return
the numbers in the range when you actually need them.
######

As knee reflex ISTM to have many similarities with returning macros. It would be
quite easy in Forth to return xt's of words containing EVALUATEs or [[ ]] gforthisms
for delayed evaluation.

Re: Single-pass or multi-pass Forth compiler

<tq4c31$2s2lt$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22027&group=comp.lang.forth#22027

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: do-not-...@swldwa.uk (Gerry Jackson)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Mon, 16 Jan 2023 20:29:23 +0000
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <tq4c31$2s2lt$1@dont-email.me>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 16 Jan 2023 20:29:21 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="724cb4a03281c587b86c173a9ca95710";
logging-data="3017405"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+OVleEdzCFyDLy1E5nIXvUbQmP+otVSb8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:dp9Co11ubCaZisCybKGS8xDrZKk=
In-Reply-To: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
 by: Gerry Jackson - Mon, 16 Jan 2023 20:29 UTC

On 16/01/2023 11:50, minf...@arcor.de wrote:
> Historically Forth features a single-pass compiler that is triggered e.g.
> when the interpreter hits a : colon. Some control flows require code
> back-patching to resolve jump targets. This can be awkward.
>
> OTOH by going over the code in several passes offers easy paths for
> simplification and optimization. e.g.
> - elimination of comments
> - resolving of labels for jump targets
> - intermediate language e.g. program as database of instruction lists
> - peephole optimization, superinstructions
> - tail call elimination
>
> Is there any Forth out there that compiles high-level definitions in this way?
> Anybody willing to share some other experience in this field?

My sytem, that has never been released (and won't be), which was
developed from about 2005, compiles Forth code to an intermediate form,
carries out some optimisations, then generates the executable code. I
did it this way (I think) to:
- widen the range of optimisations beyond simple peephole optimisation
- making it more readily portable to different processors and OS's (one
front end, n back ends).
- generating different types of executable code including machine code.

and probably other reasons that I've forgotten.

I did peephole optimisations and super-instructions but then found other
things took priority e.g. using the system, so I've never got round to
getting on with other aims.

It did make things such as quotations easier as it just involves
suspending the outer definition, compiling the quotation, then resuming
the suspended definition. Nested as much as desired.

It enabled me to experiment with other capabilities such as nested colon
definitions, declaration of variables inside a definition, different
entry points, not that I've used them for real.

--
Gerry

Re: Single-pass or multi-pass Forth compiler

<7wbkmxekaz.fsf@junk.nocrew.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22028&group=comp.lang.forth#22028

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
From: lars.s...@nocrew.org (Lars Brinkhoff)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Organization: nocrew
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
Date: Tue, 17 Jan 2023 06:39:48 +0000
Message-ID: <7wbkmxekaz.fsf@junk.nocrew.org>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
Cancel-Lock: sha1:KxS9nOOc+lrrdgplB/+OeuurcRA=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 1
NNTP-Posting-Host: c2f354ad.news.sunsite.dk
X-Trace: 1673937588 news.sunsite.dk 700 lars@junk.nocrew.org/51.15.56.219:49596
X-Complaints-To: staff@sunsite.dk
 by: Lars Brinkhoff - Tue, 17 Jan 2023 06:39 UTC

Leeloo says: multipass.

Re: Single-pass or multi-pass Forth compiler

<nnd$0b4b8699$683fe4d2@cc14b5c88c47adf5>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22029&group=comp.lang.forth#22029

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com> <c211daee-ca84-4ec0-993d-c0982b238d9an@googlegroups.com>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: alb...@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$0b4b8699$683fe4d2@cc14b5c88c47adf5>
Organization: KPN B.V.
Date: Tue, 17 Jan 2023 08:36:02 +0100
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 28
Injection-Date: Tue, 17 Jan 2023 08:36:02 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2037
 by: none - Tue, 17 Jan 2023 07:36 UTC

In article <c211daee-ca84-4ec0-993d-c0982b238d9an@googlegroups.com>,
Marcel Hendrix <mhx@iae.nl> wrote:
>On Monday, January 16, 2023 at 12:50:28 PM UTC+1, minf...@arcor.de wrote:
>> Historically Forth features a single-pass compiler that is triggered e.g.
>> when the interpreter hits a : colon. Some control flows require code
>> back-patching to resolve jump targets. This can be awkward.
>>
>> OTOH by going over the code in several passes offers easy paths for
>> simplification and optimization. e.g.
>[..]
>> Is there any Forth out there that compiles high-level definitions in this way?
>
>Using an intermediate representation is far more powerful, as one can
>do recursive 'context-sensitive' inlining (delay compiling as long as possible).
>
>In iForth's iSPICE package I'll eventually use run-time code generation (e.g.
>to eliminate pointer-chasing). This delays instruction selection to the limit.

What is "pointer chasing"?

>
>-marcel
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: Single-pass or multi-pass Forth compiler

<nnd$4477b3d3$7a91ba48@af525fc01a17fc1f>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22030&group=comp.lang.forth#22030

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: alb...@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$4477b3d3$7a91ba48@af525fc01a17fc1f>
Organization: KPN B.V.
Date: Tue, 17 Jan 2023 08:50:42 +0100
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 48
Injection-Date: Tue, 17 Jan 2023 08:50:42 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2644
 by: none - Tue, 17 Jan 2023 07:50 UTC

In article <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>,
minf...@arcor.de <minforth@arcor.de> wrote:
>Historically Forth features a single-pass compiler that is triggered e.g.
>when the interpreter hits a : colon. Some control flows require code
>back-patching to resolve jump targets. This can be awkward.
>
>OTOH by going over the code in several passes offers easy paths for
>simplification and optimization. e.g.
>- elimination of comments
>- resolving of labels for jump targets
>- intermediate language e.g. program as database of instruction lists
>- peephole optimization, superinstructions
>- tail call elimination

My optimiser goes through the steps (experimental)

1. find stack effect for all primitive words (through a sophisticated
assembler analysis) ( + stack effects properties)
2. find stack effects for other words, ( + stack effects properties)
3. optimise words from the bottom up,high level, a generalisation of
constant folding
4. inline the machine code. A number of blocks that jumps to each
other results
5. optimise the blocks, individually and as a whole.

It results (in some examples) to a speed up comparably to gforth
versus mpeforth.

Highly experimental.

>
>Is there any Forth out there that compiles high-level definitions in this way?
>Anybody willing to share some other experience in this field?

Go to my site below. forthlectures.html View lecture 5.
(This has been announced several times.)

Tail call elimination?
If you're programming for speed, you probably avoid tail calls.
(Not that it is hard to do.)

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: Single-pass or multi-pass Forth compiler

<6e2b9bd4-3cc6-4f6c-8190-698c0ac911d4n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22031&group=comp.lang.forth#22031

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:831e:b0:6fa:f354:939f with SMTP id pa30-20020a05620a831e00b006faf354939fmr86101qkn.57.1673943092423;
Tue, 17 Jan 2023 00:11:32 -0800 (PST)
X-Received: by 2002:a0d:d714:0:b0:4db:5cc8:f392 with SMTP id
z20-20020a0dd714000000b004db5cc8f392mr300695ywd.166.1673943092183; Tue, 17
Jan 2023 00:11:32 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 17 Jan 2023 00:11:31 -0800 (PST)
In-Reply-To: <tq4c31$2s2lt$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:373:e933:e078:2fe8:fa96;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:373:e933:e078:2fe8:fa96
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com> <tq4c31$2s2lt$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6e2b9bd4-3cc6-4f6c-8190-698c0ac911d4n@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Tue, 17 Jan 2023 08:11:32 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2539
 by: minf...@arcor.de - Tue, 17 Jan 2023 08:11 UTC

Gerry Jackson schrieb am Montag, 16. Januar 2023 um 21:29:24 UTC+1:
> My sytem, that has never been released (and won't be), which was
> developed from about 2005, compiles Forth code to an intermediate form,
> carries out some optimisations, then generates the executable code. I
> did it this way (I think) to:
> - widen the range of optimisations beyond simple peephole optimisation
> - making it more readily portable to different processors and OS's (one
> front end, n back ends).
> - generating different types of executable code including machine code.
>
> and probably other reasons that I've forgotten.
>
> I did peephole optimisations and super-instructions but then found other
> things took priority e.g. using the system, so I've never got round to
> getting on with other aims.
>
> It did make things such as quotations easier as it just involves
> suspending the outer definition, compiling the quotation, then resuming
> the suspended definition. Nested as much as desired.

So it compiles the innermost definitions/quotations first before compiling
outer definitions?

The "classic" way is to jump over quotations, nesting included.
From the reference test:
T{ : q1 [: 1 ;] ; q1 EXECUTE -> 1 }T
T{ : q2 [: [: 2 ;] ;] ; q2 EXECUTE EXECUTE -> 2 }T

Did you experiment with enclosures?

Re: Single-pass or multi-pass Forth compiler

<78580af1-c0fe-4148-9e6e-7ee9c16105ean@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22032&group=comp.lang.forth#22032

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a37:de0f:0:b0:705:b29d:c666 with SMTP id h15-20020a37de0f000000b00705b29dc666mr111179qkj.462.1673943821749;
Tue, 17 Jan 2023 00:23:41 -0800 (PST)
X-Received: by 2002:a25:77cd:0:b0:7e7:f947:e079 with SMTP id
s196-20020a2577cd000000b007e7f947e079mr322721ybc.237.1673943821572; Tue, 17
Jan 2023 00:23:41 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 17 Jan 2023 00:23:41 -0800 (PST)
In-Reply-To: <2023Jan16.172717@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:373:e933:e078:2fe8:fa96;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:373:e933:e078:2fe8:fa96
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com> <2023Jan16.172717@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <78580af1-c0fe-4148-9e6e-7ee9c16105ean@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Tue, 17 Jan 2023 08:23:41 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1986
 by: minf...@arcor.de - Tue, 17 Jan 2023 08:23 UTC

Anton Ertl schrieb am Montag, 16. Januar 2023 um 17:41:20 UTC+1:
> iForth and VFX have an intermediate representation that they use for
> inlining. AFAIK they don't use it for elimination of comments, jump
> target resolution, peephole optimization, superinstructions, or
> tail-call elimination.
>
> Gforth uses the threaded-code representation (and its relocatable
> variant) either directly, or as a step to a mixture of native code and
> threaded-code. It also buffers the threaded code for a straight-line
> piece of code before generating native code, to allow better code
> generation.

The VFX docs speak of code inlining vs source inlining, the latter now
improved through tokenizing. This looks similar to gforth's inlining method.

Re: Single-pass or multi-pass Forth compiler

<2023Jan17.100814@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22033&group=comp.lang.forth#22033

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Tue, 17 Jan 2023 09:08:14 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 34
Message-ID: <2023Jan17.100814@mips.complang.tuwien.ac.at>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com> <2023Jan16.172717@mips.complang.tuwien.ac.at> <78580af1-c0fe-4148-9e6e-7ee9c16105ean@googlegroups.com>
Injection-Info: reader01.eternal-september.org; posting-host="cb960b47f56641b95c92a42c60b8850d";
logging-data="3335600"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WRjEf+37P6L8tnAD+FJrX"
Cancel-Lock: sha1:XtFHEqypp2CilRQ0Z+P/aqQnKrk=
X-newsreader: xrn 10.11
 by: Anton Ertl - Tue, 17 Jan 2023 09:08 UTC

"minf...@arcor.de" <minforth@arcor.de> writes:
>Anton Ertl schrieb am Montag, 16. Januar 2023 um 17:41:20 UTC+1:
>> iForth and VFX have an intermediate representation that they use for
>> inlining. AFAIK they don't use it for elimination of comments, jump
>> target resolution, peephole optimization, superinstructions, or
>> tail-call elimination.
>>
>> Gforth uses the threaded-code representation (and its relocatable
>> variant) either directly, or as a step to a mixture of native code and
>> threaded-code. It also buffers the threaded code for a straight-line
>> piece of code before generating native code, to allow better code
>> generation.
>
>The VFX docs speak of code inlining vs source inlining, the latter now
>improved through tokenizing.

The original source inliner of VFX had the same correctness problem as
EVALUATE-based macros. AFAIK The "tokenizing" resolves the names,
BASE etc. when the code is tokenized and therefore does not have this
problem.

>This looks similar to gforth's inlining method.

Gforth currently does not inline colon definitions. The native-code
approach has been called "selective inlining" (of primitives) by
Piumarta, and is probably similar to what VFX documents as "code
inlining", but I normally don't call it inlining.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2022: https://euro.theforth.net

Re: Single-pass or multi-pass Forth compiler

<16de36b8-6ea6-4fcc-8622-d02e44d09922n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22034&group=comp.lang.forth#22034

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:707:0:b0:3ab:f6eb:5a48 with SMTP id g7-20020ac80707000000b003abf6eb5a48mr48374qth.612.1673949702565;
Tue, 17 Jan 2023 02:01:42 -0800 (PST)
X-Received: by 2002:a0d:d714:0:b0:4db:5cc8:f392 with SMTP id
z20-20020a0dd714000000b004db5cc8f392mr344786ywd.166.1673949702174; Tue, 17
Jan 2023 02:01:42 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 17 Jan 2023 02:01:41 -0800 (PST)
In-Reply-To: <2023Jan17.100814@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:373:e933:e078:2fe8:fa96;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:373:e933:e078:2fe8:fa96
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
<2023Jan16.172717@mips.complang.tuwien.ac.at> <78580af1-c0fe-4148-9e6e-7ee9c16105ean@googlegroups.com>
<2023Jan17.100814@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <16de36b8-6ea6-4fcc-8622-d02e44d09922n@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Tue, 17 Jan 2023 10:01:42 +0000
Content-Type: text/plain; charset="UTF-8"
 by: minf...@arcor.de - Tue, 17 Jan 2023 10:01 UTC

Anton Ertl schrieb am Dienstag, 17. Januar 2023 um 10:14:42 UTC+1:
> "minf...@arcor.de" <minf...@arcor.de> writes:
> >Anton Ertl schrieb am Montag, 16. Januar 2023 um 17:41:20 UTC+1:
> >> iForth and VFX have an intermediate representation that they use for
> >> inlining. AFAIK they don't use it for elimination of comments, jump
> >> target resolution, peephole optimization, superinstructions, or
> >> tail-call elimination.
> >>
> >> Gforth uses the threaded-code representation (and its relocatable
> >> variant) either directly, or as a step to a mixture of native code and
> >> threaded-code. It also buffers the threaded code for a straight-line
> >> piece of code before generating native code, to allow better code
> >> generation.
> >
> >The VFX docs speak of code inlining vs source inlining, the latter now
> >improved through tokenizing.
> The original source inliner of VFX had the same correctness problem as
> EVALUATE-based macros. AFAIK The "tokenizing" resolves the names,
> BASE etc. when the code is tokenized and therefore does not have this
> problem.

Macro correctness is an interesting topic as it can depend on changed
machine states. Off topic, but correct selection of what has to be included
in saved closure enviroments falls into the same problem category.

I wonder if the Holon approach (keeping everything in a realtime source
database) did not suffer from the same dilemma.

Re: Single-pass or multi-pass Forth compiler

<tq5svr$1gd6$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22035&group=comp.lang.forth#22035

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Tue, 17 Jan 2023 21:23:54 +1100
Organization: Aioe.org NNTP Server
Message-ID: <tq5svr$1gd6$1@gioia.aioe.org>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="49574"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Tue, 17 Jan 2023 10:23 UTC

On 16/01/2023 10:50 pm, minf...@arcor.de wrote:
> Historically Forth features a single-pass compiler that is triggered e.g.
> when the interpreter hits a : colon. Some control flows require code
> back-patching to resolve jump targets. This can be awkward.

m/c assemblers went from two-pass to one-pass. Trust forth to want to go
in the opposite direction :)

Re: Single-pass or multi-pass Forth compiler

<tq5ubt$360nt$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22036&group=comp.lang.forth#22036

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: do-not-...@swldwa.uk (Gerry Jackson)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Tue, 17 Jan 2023 10:47:26 +0000
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <tq5ubt$360nt$1@dont-email.me>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
<tq4c31$2s2lt$1@dont-email.me>
<6e2b9bd4-3cc6-4f6c-8190-698c0ac911d4n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 17 Jan 2023 10:47:25 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f02247eec0d083a74d6b4f399c9b28da";
logging-data="3343101"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18abjI2QifTMiweDXYrP3u5hiI8ATFRKYA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:OWHL+uVTedk/XwoiGOXAQiZHT68=
In-Reply-To: <6e2b9bd4-3cc6-4f6c-8190-698c0ac911d4n@googlegroups.com>
 by: Gerry Jackson - Tue, 17 Jan 2023 10:47 UTC

On 17/01/2023 08:11, minf...@arcor.de wrote:
> Gerry Jackson schrieb am Montag, 16. Januar 2023 um 21:29:24 UTC+1:
>> My sytem, that has never been released (and won't be), which was
>> developed from about 2005, compiles Forth code to an intermediate form,
>> carries out some optimisations, then generates the executable code. I
>> did it this way (I think) to:
>> - widen the range of optimisations beyond simple peephole optimisation
>> - making it more readily portable to different processors and OS's (one
>> front end, n back ends).
>> - generating different types of executable code including machine code.
>>
>> and probably other reasons that I've forgotten.
>>
>> I did peephole optimisations and super-instructions but then found other
>> things took priority e.g. using the system, so I've never got round to
>> getting on with other aims.
>>
>> It did make things such as quotations easier as it just involves
>> suspending the outer definition, compiling the quotation, then resuming
>> the suspended definition. Nested as much as desired.
>
> So it compiles the innermost definitions/quotations first before compiling
> outer definitions?
>
> The "classic" way is to jump over quotations, nesting included.

Yes a crude, but effective, solution imposed by the traditional single
pass compilation.

> From the reference test:
> T{ : q1 [: 1 ;] ; q1 EXECUTE -> 1 }T
> T{ : q2 [: [: 2 ;] ;] ; q2 EXECUTE EXECUTE -> 2 }T
>
> Did you experiment with enclosures?

Not with the built in quotations. But before quotations were
standardised I did develop an ANS Forth implementation of closures in
2011 that I can let you have if you are interested.

--
Gerry

Re: Single-pass or multi-pass Forth compiler

<fd0db699-99d1-4cb9-a21b-3fd53fa835acn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22037&group=comp.lang.forth#22037

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a37:5d7:0:b0:706:702e:bab7 with SMTP id 206-20020a3705d7000000b00706702ebab7mr110512qkf.579.1673957937501;
Tue, 17 Jan 2023 04:18:57 -0800 (PST)
X-Received: by 2002:a25:77cd:0:b0:7e7:f947:e079 with SMTP id
s196-20020a2577cd000000b007e7f947e079mr391843ybc.237.1673957937348; Tue, 17
Jan 2023 04:18:57 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 17 Jan 2023 04:18:57 -0800 (PST)
In-Reply-To: <tq5ubt$360nt$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:373:e933:e078:2fe8:fa96;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:373:e933:e078:2fe8:fa96
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
<tq4c31$2s2lt$1@dont-email.me> <6e2b9bd4-3cc6-4f6c-8190-698c0ac911d4n@googlegroups.com>
<tq5ubt$360nt$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fd0db699-99d1-4cb9-a21b-3fd53fa835acn@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Tue, 17 Jan 2023 12:18:57 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3213
 by: minf...@arcor.de - Tue, 17 Jan 2023 12:18 UTC

Gerry Jackson schrieb am Dienstag, 17. Januar 2023 um 11:47:27 UTC+1:
> On 17/01/2023 08:11, minf...@arcor.de wrote:
> > Gerry Jackson schrieb am Montag, 16. Januar 2023 um 21:29:24 UTC+1:
> >> My sytem, that has never been released (and won't be), which was
> >> developed from about 2005, compiles Forth code to an intermediate form,
> >> carries out some optimisations, then generates the executable code. I
> >> did it this way (I think) to:
> >> - widen the range of optimisations beyond simple peephole optimisation
> >> - making it more readily portable to different processors and OS's (one
> >> front end, n back ends).
> >> - generating different types of executable code including machine code.
> >>
> >> and probably other reasons that I've forgotten.
> >>
> >> I did peephole optimisations and super-instructions but then found other
> >> things took priority e.g. using the system, so I've never got round to
> >> getting on with other aims.
> >>
> >> It did make things such as quotations easier as it just involves
> >> suspending the outer definition, compiling the quotation, then resuming
> >> the suspended definition. Nested as much as desired.
> >
> > So it compiles the innermost definitions/quotations first before compiling
> > outer definitions?
> >
> > The "classic" way is to jump over quotations, nesting included.
> Yes a crude, but effective, solution imposed by the traditional single
> pass compilation.
> > From the reference test:
> > T{ : q1 [: 1 ;] ; q1 EXECUTE -> 1 }T
> > T{ : q2 [: [: 2 ;] ;] ; q2 EXECUTE EXECUTE -> 2 }T
> >
> > Did you experiment with enclosures?
> Not with the built in quotations. But before quotations were
> standardised I did develop an ANS Forth implementation of closures in
> 2011 that I can let you have if you are interested.

Thank you for your kind offer! I just sent you a private mail.

Re: Single-pass or multi-pass Forth compiler

<tq6dgt$39ce9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22038&group=comp.lang.forth#22038

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: m.c...@gmx.net (Matthias Koch)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Tue, 17 Jan 2023 16:06:05 +0100
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <tq6dgt$39ce9$1@dont-email.me>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 17 Jan 2023 15:06:05 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="af335227db8291a74bc08c0334dbb44d";
logging-data="3453385"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18I31pusHd6KtXyytUK4HrX"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Cancel-Lock: sha1:qZsZxK9z28rTIe3nCm0RmArBHcY=
In-Reply-To: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
Content-Language: de-DE
 by: Matthias Koch - Tue, 17 Jan 2023 15:06 UTC

I found multiple passes necessary in Mecrisp-Across to re-join different control flow branches that use a different local register allocation without relying on canonical fallback. If the number of stack elements held in registers at the joint differ, one needs to use the smaller number of stack elements, which may require additional passes to achieve.

Using the larger number of elements causes non-existing elements to be popped from the stack, at least temporarily. Of course, in valid Forth code, these elements will be pushed back, but may cause reads/writes beyond the beginning of the stack area in memory. Simply adding a guard space at the beginning of the stack would be a solution to keep it single-pass, but in combination with nested interrupts, this may be riscy. I solved this with multiple passes in the compiler, and generate elegant code along the way.

Note this compiler is capable of register allocation across ?dup and similiar constructs.

Re: Single-pass or multi-pass Forth compiler

<e164b28e-e685-45c1-ab34-536604eeadd1n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22040&group=comp.lang.forth#22040

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:5683:b0:531:ad72:d8b8 with SMTP id lm3-20020a056214568300b00531ad72d8b8mr298739qvb.3.1674035643705;
Wed, 18 Jan 2023 01:54:03 -0800 (PST)
X-Received: by 2002:a25:d401:0:b0:7e1:b147:4e22 with SMTP id
m1-20020a25d401000000b007e1b1474e22mr937023ybf.81.1674035643377; Wed, 18 Jan
2023 01:54:03 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 18 Jan 2023 01:54:03 -0800 (PST)
In-Reply-To: <tq6dgt$39ce9$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:3a6:896d:1601:e0a8:ad32;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:3a6:896d:1601:e0a8:ad32
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com> <tq6dgt$39ce9$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e164b28e-e685-45c1-ab34-536604eeadd1n@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Wed, 18 Jan 2023 09:54:03 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2547
 by: minf...@arcor.de - Wed, 18 Jan 2023 09:54 UTC

Matthias Koch schrieb am Dienstag, 17. Januar 2023 um 16:06:07 UTC+1:
> I found multiple passes necessary in Mecrisp-Across to re-join different control flow branches that use a different local register allocation without relying on canonical fallback. If the number of stack elements held in registers at the joint differ, one needs to use the smaller number of stack elements, which may require additional passes to achieve.
>
> Using the larger number of elements causes non-existing elements to be popped from the stack, at least temporarily. Of course, in valid Forth code, these elements will be pushed back, but may cause reads/writes beyond the beginning of the stack area in memory. Simply adding a guard space at the beginning of the stack would be a solution to keep it single-pass, but in combination with nested interrupts, this may be riscy. I solved this with multiple passes in the compiler, and generate elegant code along the way.
>
> Note this compiler is capable of register allocation across ?dup and similiar constructs.

Looks like some 'spill and iterate' algorithm. Did you consider spilling costs?
I imagine that moves between registers and memory take MUCH more time
than some little register reshuffling at control flow joints.

Re: Single-pass or multi-pass Forth compiler

<tq8gtj$rlhp$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22041&group=comp.lang.forth#22041

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: m.c...@gmx.net (Matthias Koch)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Wed, 18 Jan 2023 11:16:18 +0100
Organization: A noiseless patient Spider
Lines: 2
Message-ID: <tq8gtj$rlhp$1@dont-email.me>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
<tq6dgt$39ce9$1@dont-email.me>
<e164b28e-e685-45c1-ab34-536604eeadd1n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 18 Jan 2023 10:16:19 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="6866a4ccd1217431661f9f7bfe668b4d";
logging-data="906809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+OsWgKgyuvOnEIWi08ANTu"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Cancel-Lock: sha1:Q9jc/HbximE9sPblWtmzNqYN7Iw=
Content-Language: de-DE
In-Reply-To: <e164b28e-e685-45c1-ab34-536604eeadd1n@googlegroups.com>
 by: Matthias Koch - Wed, 18 Jan 2023 10:16 UTC

Can you point me to a text describing the solution or existing implementation? I am reshuffling registers as much as possible without spilling them to the stack, but I do not know on how to handle the situation without partial spilling (and subsequent reshuffling of the common numer of elements in registers) when I have a larger total amount of stack elements in registers than in the other branch, as different branches may have different depth stack effects, and these elements do not exist on the stack at all for one of the two branches.

Re: Single-pass or multi-pass Forth compiler

<3093090e-dd2a-4552-b62d-7f0ef042451en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22042&group=comp.lang.forth#22042

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:2085:b0:706:7238:77f6 with SMTP id e5-20020a05620a208500b00706723877f6mr346214qka.691.1674040665023;
Wed, 18 Jan 2023 03:17:45 -0800 (PST)
X-Received: by 2002:a5b:750:0:b0:73e:1951:3e92 with SMTP id
s16-20020a5b0750000000b0073e19513e92mr728218ybq.388.1674040664769; Wed, 18
Jan 2023 03:17:44 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 18 Jan 2023 03:17:44 -0800 (PST)
In-Reply-To: <tq8gtj$rlhp$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:3a6:896d:1601:e0a8:ad32;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:3a6:896d:1601:e0a8:ad32
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
<tq6dgt$39ce9$1@dont-email.me> <e164b28e-e685-45c1-ab34-536604eeadd1n@googlegroups.com>
<tq8gtj$rlhp$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3093090e-dd2a-4552-b62d-7f0ef042451en@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Wed, 18 Jan 2023 11:17:45 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2908
 by: minf...@arcor.de - Wed, 18 Jan 2023 11:17 UTC

Matthias Koch schrieb am Mittwoch, 18. Januar 2023 um 11:16:21 UTC+1:
> Can you point me to a text describing the solution or existing implementation? I am reshuffling registers as much as possible without spilling them to the stack, but I do not know on how to handle the situation without partial spilling (and subsequent reshuffling of the common numer of elements in registers) when I have a larger total amount of stack elements in registers than in the other branch, as different branches may have different depth stack effects, and these elements do not exist on the stack at all for one of the two branches.

I am certainly much less experienced than you are in this field. I just happen to know
that Chaitin's algortihm includes spilling until new liveliness analysis comes up with
an acceptably colored graph. But AFAIK optimal spilling is still a thing for heuristics
or brute force iteration. Until today there is no known 'formula' for it.

Hence my question out of curiosity whether you have gained new insights. It had not
been clear whether you do liveliness analysis at all.

Add to this that spilling costs are not constant, given the caching effects in many CPUs.
I found only one lecture note that at least mentions this (but does not deal with it later on):
https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/lectures/17/Slides17.pdf

Of course it remains also a design decision of where for a small Forth compiler for
embedded systems reasonable usability ends and where overkill starts.

Re: Single-pass or multi-pass Forth compiler

<78673e23-c35f-40e2-82ba-308d04abfe12n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22043&group=comp.lang.forth#22043

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:4b57:0:b0:3a9:68ba:4c10 with SMTP id e23-20020ac84b57000000b003a968ba4c10mr205541qts.676.1674042419810;
Wed, 18 Jan 2023 03:46:59 -0800 (PST)
X-Received: by 2002:a81:6c4c:0:b0:4dc:f746:7851 with SMTP id
h73-20020a816c4c000000b004dcf7467851mr672328ywc.175.1674042419475; Wed, 18
Jan 2023 03:46:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 18 Jan 2023 03:46:59 -0800 (PST)
In-Reply-To: <3093090e-dd2a-4552-b62d-7f0ef042451en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f23:3a6:896d:1601:e0a8:ad32;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f23:3a6:896d:1601:e0a8:ad32
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
<tq6dgt$39ce9$1@dont-email.me> <e164b28e-e685-45c1-ab34-536604eeadd1n@googlegroups.com>
<tq8gtj$rlhp$1@dont-email.me> <3093090e-dd2a-4552-b62d-7f0ef042451en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <78673e23-c35f-40e2-82ba-308d04abfe12n@googlegroups.com>
Subject: Re: Single-pass or multi-pass Forth compiler
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Wed, 18 Jan 2023 11:46:59 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3340
 by: minf...@arcor.de - Wed, 18 Jan 2023 11:46 UTC

minf...@arcor.de schrieb am Mittwoch, 18. Januar 2023 um 12:17:46 UTC+1:
> Matthias Koch schrieb am Mittwoch, 18. Januar 2023 um 11:16:21 UTC+1:
> > Can you point me to a text describing the solution or existing implementation? I am reshuffling registers as much as possible without spilling them to the stack, but I do not know on how to handle the situation without partial spilling (and subsequent reshuffling of the common numer of elements in registers) when I have a larger total amount of stack elements in registers than in the other branch, as different branches may have different depth stack effects, and these elements do not exist on the stack at all for one of the two branches.
> I am certainly much less experienced than you are in this field. I just happen to know
> that Chaitin's algortihm includes spilling until new liveliness analysis comes up with
> an acceptably colored graph. But AFAIK optimal spilling is still a thing for heuristics
> or brute force iteration. Until today there is no known 'formula' for it.
>
> Hence my question out of curiosity whether you have gained new insights. It had not
> been clear whether you do liveliness analysis at all.
>
> Add to this that spilling costs are not constant, given the caching effects in many CPUs.
> I found only one lecture note that at least mentions this (but does not deal with it later on):
> https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/lectures/17/Slides17.pdf
>
> Of course it remains also a design decision of where for a small Forth compiler for
> embedded systems reasonable usability ends and where overkill starts.

P.S. since you won't do graph coloring, perhaps this paper may be of more interest because
it also treats with data flow analysis:
http://www.christianwimmer.at/Publications/Wimmer10a/Wimmer10a.pdf

Re: Single-pass or multi-pass Forth compiler

<tq8nkc$ssfh$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22044&group=comp.lang.forth#22044

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: m.c...@gmx.net (Matthias Koch)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Wed, 18 Jan 2023 13:10:52 +0100
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <tq8nkc$ssfh$1@dont-email.me>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
<tq6dgt$39ce9$1@dont-email.me>
<e164b28e-e685-45c1-ab34-536604eeadd1n@googlegroups.com>
<tq8gtj$rlhp$1@dont-email.me>
<3093090e-dd2a-4552-b62d-7f0ef042451en@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 18 Jan 2023 12:10:52 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="6866a4ccd1217431661f9f7bfe668b4d";
logging-data="946673"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+r1uMZ+rctjTAgJwSb2CtH"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Cancel-Lock: sha1:vxnDRAJalWH4Ie15XnrNo3hQ6YA=
In-Reply-To: <3093090e-dd2a-4552-b62d-7f0ef042451en@googlegroups.com>
Content-Language: de-DE
 by: Matthias Koch - Wed, 18 Jan 2023 12:10 UTC

These slides are a very nice intro to register allocation difficulties - but register spilling therein happens when "we have more elements than registers", whereas in Mecrisp-Across I have enough registers for most of the reasonable code. For example, 2OVER gets 6 deep, so for an embedded MSP430 Forth, it is OK to start spilling at 10 elements deep because of lack of registers. The variable liveness analysis is a different kind of beast than a stack. I do not try to perform liveness analysis at all.

What I do is: When stack elements are handled first time, these are popped from the stack(s) and put in registers, and the compiler tries to keep these in registers unless forced to get back to canonical state by non-optimiseable structures.

This is done in Mecrisp-Stellaris RA (data stack only) and Mecrisp-Quintus with the loadable Acrobatics compiler extension (both data and return stack) which is written in Forth itself, my recommendation if you want a starting point. These do canonical fallback when encountering control structures.

Mecrisp-Across is one step ahead and keeps the current set of registers when control flow forks execution, and tries to re-merge the two resulting register sets at the joint, if possible by reshuffling one of the branches to get back to a common register set. When not, it spills the additional elements from the larger branch (which may require an additional pass in my compiler), and reshuffles the remaining ones. This is not done because of lack of registers, but because of the nature of the stacks and the limited scope of the compiler. At the end of a definition, or before an unknown immediate word is executed, a full canonical fallback is done.

A curious mind one out there wrote a nice blog post analysing the output of the Mecrisp-Across compiler:

https://joldosh.blogspot.com/2019/12/optimized-msp430-assembly-in-mecrisp.html

Certainly there is no caching, as I am targeting tiny classic MSP430 chips like the MSP430F2012 with Mecrisp-Across, therefore register spills are the same cost under all circumstances.

Caching effects apply when running Mecrisp-Stellaris or Mecrisp-Quintus hosted on ARM/RISC-V/MIPS Linux (and thanks to Robert Clausecker FreeBSD), but the family of Mecrisp Forths is designed for deep embedded and the hosted ports are not the main focus of my efforts.

Re: Single-pass or multi-pass Forth compiler

<tq8o1t$ssfh$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22045&group=comp.lang.forth#22045

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: m.c...@gmx.net (Matthias Koch)
Newsgroups: comp.lang.forth
Subject: Re: Single-pass or multi-pass Forth compiler
Date: Wed, 18 Jan 2023 13:18:05 +0100
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <tq8o1t$ssfh$2@dont-email.me>
References: <74bc3d99-4179-47d7-bcd2-42114b39feb9n@googlegroups.com>
<tq6dgt$39ce9$1@dont-email.me>
<e164b28e-e685-45c1-ab34-536604eeadd1n@googlegroups.com>
<tq8gtj$rlhp$1@dont-email.me>
<3093090e-dd2a-4552-b62d-7f0ef042451en@googlegroups.com>
<78673e23-c35f-40e2-82ba-308d04abfe12n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 18 Jan 2023 12:18:06 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="6866a4ccd1217431661f9f7bfe668b4d";
logging-data="946673"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/LPIb5DMMPAP8as6KtOkX4"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Cancel-Lock: sha1:3b+2MpwhHWaq/8i8QP76F+g71no=
Content-Language: de-DE
In-Reply-To: <78673e23-c35f-40e2-82ba-308d04abfe12n@googlegroups.com>
 by: Matthias Koch - Wed, 18 Jan 2023 12:18 UTC

> P.S. since you won't do graph coloring, perhaps this paper may be of more interest because
> it also treats with data flow analysis:
> http://www.christianwimmer.at/Publications/Wimmer10a/Wimmer10a.pdf

Thanks, looks nice!
By the way, I do not even use SSA intermediate form.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor