Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Power is danger. -- The Centurion, "Balance of Terror", stardate 1709.2


devel / comp.lang.forth / Re: Uses for "exec" (swap P and R)

SubjectAuthor
* Uses for "exec" (swap P and R)Brad Eckert
+* Re: Uses for "exec" (swap P and R)Anton Ertl
|`- Re: Uses for "exec" (swap P and R)none
`- Re: Uses for "exec" (swap P and R)none

1
Uses for "exec" (swap P and R)

<8d85f5cc-62b5-436c-b594-5ba0a6d68fc6n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:c88:b0:4ac:a119:7ddf with SMTP id r8-20020a0562140c8800b004aca1197ddfmr27057317qvr.126.1664389033218;
Wed, 28 Sep 2022 11:17:13 -0700 (PDT)
X-Received: by 2002:a25:37cb:0:b0:6b1:db19:83cf with SMTP id
e194-20020a2537cb000000b006b1db1983cfmr33628537yba.391.1664389032947; Wed, 28
Sep 2022 11:17:12 -0700 (PDT)
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: Wed, 28 Sep 2022 11:17:12 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=72.217.63.66; posting-account=6GCGIQoAAAAyO8IjR_VTwqiqLwx0Q_G8
NNTP-Posting-Host: 72.217.63.66
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8d85f5cc-62b5-436c-b594-5ba0a6d68fc6n@googlegroups.com>
Subject: Uses for "exec" (swap P and R)
From: hwfw...@gmail.com (Brad Eckert)
Injection-Date: Wed, 28 Sep 2022 18:17:13 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1329
 by: Brad Eckert - Wed, 28 Sep 2022 18:17 UTC

I notice that the GreenArrays chips have an opcode called "exec" that swaps the P and R registers. I suppose this is for "execute", which would be a "push exec" macro. One could just as easily call a word "execute" whose definition is

: execute push ;

Are there other tricks that "exec" can do besides slightly improving "execute"?

--
Brad

Re: Uses for "exec" (swap P and R)

<2022Sep28.204717@mips.complang.tuwien.ac.at>

  copy mid

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

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!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: Uses for "exec" (swap P and R)
Date: Wed, 28 Sep 2022 18:47:17 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 36
Message-ID: <2022Sep28.204717@mips.complang.tuwien.ac.at>
References: <8d85f5cc-62b5-436c-b594-5ba0a6d68fc6n@googlegroups.com>
Injection-Info: reader01.eternal-september.org; posting-host="77314c2d927712b96e759d2407bf3ba6";
logging-data="458113"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192pHGxw87Q1QqNIfeYs4/z"
Cancel-Lock: sha1:27479LRW+jLx/9fnP29qpcyyWF8=
X-newsreader: xrn 10.11
 by: Anton Ertl - Wed, 28 Sep 2022 18:47 UTC

Brad Eckert <hwfwguy@gmail.com> writes:
>I notice that the GreenArrays chips have an opcode called "exec" that swaps the P and R registers.

So in more traditional terms I guess this is:

: exec r> r> swap >r >r ;

>Are there other tricks that "exec" can do besides slightly improving "execute"?

A number of people have used return-address-manipulating words for
implementing control-flow in some form. E.g., I remember Bernd
Paysan's LIST>, which is used like this:

: foo ... ( list ) list> code ;

where CODE is executed once for every element of the list, and that
element is pushed before every time. IIRC he also had a word that
changed the standard output device to stderr, and when the colon
definition ended, the standard output device was changed back. These
days we instead pass an xt (e.g., of a quotation) to a word that
executes the xt: once per stack element in case of the LIST>
replacement, or that changes the user output device, then executes the
xt, then changes it back afterwards.

So while return-address manipulation has a certain cuteness factor, it
can be replaced with standard code, and I guess that's why the
suggestions to standardize it never led to a Forth 200x proposal (I
remember something that was close to what one would expect in such a
proposal, but I think that was before Forth 200x started).

- 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: Uses for "exec" (swap P and R)

<nnd$47b89db2$604c711c@daee6df67fba91de>

  copy mid

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

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
References: <8d85f5cc-62b5-436c-b594-5ba0a6d68fc6n@googlegroups.com> <2022Sep28.204717@mips.complang.tuwien.ac.at>
Subject: Re: Uses for "exec" (swap P and R)
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: alb...@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$47b89db2$604c711c@daee6df67fba91de>
Organization: KPN B.V.
Date: Thu, 29 Sep 2022 10:49:02 +0200
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe006.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 93
Injection-Date: Thu, 29 Sep 2022 10:49:02 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 4082
 by: none - Thu, 29 Sep 2022 08:49 UTC

In article <2022Sep28.204717@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>Brad Eckert <hwfwguy@gmail.com> writes:
>>I notice that the GreenArrays chips have an opcode called "exec" that swaps the P and R registers.
>
>So in more traditional terms I guess this is:
>
>: exec r> r> swap >r >r ;

This is an inexpensive code word in 80i86
CODE_HEADER({CO},{CO})
XCHG HIP,[RPO]
_NEXT
HIP is mapped onto SI, RPO is mapped onto BP
High lever Interpreter Pointer, Return stack POinter.
(In this implementation in ciforth).

The name CO (coroutine) is way better that EXEC.

>
>>Are there other tricks that "exec" can do besides slightly improving
>> "execute"?
>
>A number of people have used return-address-manipulating words for
>implementing control-flow in some form. E.g., I remember Bernd
>Paysan's LIST>, which is used like this:
>
>: foo ... ( list ) list> code ;
>
>where CODE is executed once for every element of the list, and that
>element is pushed before every time. IIRC he also had a word that
>changed the standard output device to stderr, and when the colon
>definition ended, the standard output device was changed back. These
>days we instead pass an xt (e.g., of a quotation) to a word that
>executes the xt: once per stack element in case of the LIST>
>replacement, or that changes the user output device, then executes the
>xt, then changes it back afterwards.
>
>So while return-address manipulation has a certain cuteness factor, it
>can be replaced with standard code, and I guess that's why the
>suggestions to standardize it never led to a Forth 200x proposal (I
>remember something that was close to what one would expect in such a
>proposal, but I think that was before Forth 200x started).

Many never appreciated that it is in fact a coroutine call.
So abstracts away any return address manipulation.

\ : CO R> R> SWAP >R >R ; if missing.
\ For WID, yield a next DEA (namefield) for each coroutine call,
\ then zero.
[ ">LFA @" turns a name token into the next name token. ]
: FOR-WORDS BEGIN DUP CO >LFA @ DUP 0= UNTIL ;

\ Print all words in the context dictionary.
: WORDS CONTEXT @ FOR-WORDS BEGIN DUP WHILE ID. CO REPEAT DROP ;

It is bang for the buck, adding CO is merely one code word with
one instruction.
You could have passed `ID. to a looping construct
but then you have to store the xt temporarily. And what if you
want to put a carriage return after each ID. ?

This is the description in the glossary of ciforth:
-----------------------------------------------------------
CO

STACKEFFECT:

DESCRIPTION:

Return to the caller, suspending interpretation of the current
definition, such that when the caller exits, this definition is
resumed.
The return stack must not be engaged, such as between >R and R> , or
DO and LOOP .

GLOSSARY INDEX

SEE ALSO: CONTROL EXIT
-----------------------------------------------------------

Note how the description is concise, compelling and clear.

>
>- anton

Groetjes Albert
--
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Re: Uses for "exec" (swap P and R)

<nnd$0844448d$58bf5175@24593b359966b9da>

  copy mid

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

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
References: <8d85f5cc-62b5-436c-b594-5ba0a6d68fc6n@googlegroups.com>
Subject: Re: Uses for "exec" (swap P and R)
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: alb...@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$0844448d$58bf5175@24593b359966b9da>
Organization: KPN B.V.
Date: Thu, 29 Sep 2022 11:42:39 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe005.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 70
Injection-Date: Thu, 29 Sep 2022 11:42:39 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2830
 by: none - Thu, 29 Sep 2022 09:42 UTC

In article <8d85f5cc-62b5-436c-b594-5ba0a6d68fc6n@googlegroups.com>,
Brad Eckert <hwfwguy@gmail.com> wrote:
>I notice that the GreenArrays chips have an opcode called "exec" that
>swaps the P and R registers. I suppose this is for "execute", which
>would be a "push exec" macro. One could just as easily call a word
>"execute" whose definition is
>
>: execute push ;
>
>Are there other tricks that "exec" can do besides slightly improving "execute"?

Once you realize that it implements the well known concept of
coroutines a flurry of uses arises; it is a respectable technique
rather than a trick.
A better name is CO.
"
Return to the caller, suspending interpretation of the current
definition, such that when the caller exits, this definition is
resumed.
"
A few examples:

VARIABLE (BASE)
\ Switch to hex for the duration of the definition.
: HEX: BASE @ (BASE) ! HEX CO (BASE) @ BASE ! ;
\ Some care is needed if you want to use the return stack.
: HEX: R> BASE @ >R >R HEX CO R> BASE ! ;
: DEC: R> BASE @ >R >R DECIMAL CO R> BASE ! ;

\ For WID, yield a next DEA (namefield) for each coroutine call,
\ then zero.
: FOR-WORDS BEGIN DUP CO >LFA @ DUP 0= UNTIL ;
\ Print all words in the context dictionary.
: WORDS CONTEXT @ FOR-WORDS BEGIN DUP WHILE ID. CO REPEAT DROP ;

It comes indispensable once you have added decorators to your
Forth. (An idea I took from Python).
It is best shown by example:

OK : add + ;
OK : before "before the stack is " TYPE .S ;
OK
'before 'add decorated \ `add is decorated by `before .
OK
1 2 add
before the stack is
S[ 1 2 ] OK

: before&after "before the stack is " TYPE .S CO
" after the stack is " TYPE .S ;
OK
'add undecorated
OK
'before&after 'add decorated
OK
1000 100 add
before the stack is
S[ 3 1000 100 ] after the stack is
S[ 3 1100 ] OK
>
>--
>Brad

Groetjes Albert
--
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor