How robust is INCLUDE

Liste des GroupesRevenir à cl forth 
Sujet : How robust is INCLUDE
De : mhx (at) *nospam* iae.nl (mhx)
Groupes : comp.lang.forth
Date : 19. Dec 2024, 16:22:39
Autres entêtes
Organisation : novaBBS
Message-ID : <e2087f81f803be03f7b87c51f0e4cc8a@www.novabbs.com>
User-Agent : Rocksolid Light
I wonder if the following code is (partially) ANS compatible, and
if it is easy to understand what it does, especially the word MAIN3.
Can it be written in a completely standard way?
What I need is a word that is passed parameters that define an index
into an array that is not allotted yet. So neither the index nor the
base address
can be pre-computed. When the word executes (after much more code which
finally sets up the data), it should access the array to fetch a byte at
the indexed position.
The way I've set it up, the user of the program edits a file to allocate
the data and define a function that does the fetching.
If your Forth lacks >S S> S , leave them away or replace with >R R> R@
FORTH> MAIN3
one, two, three  = 1 2 3 \ 1 2 3
result = 123
MAIN3 compiled a noname $013454C0 ok
FORTH> $013454C0 idis
$013454C0  : [trashed]
$013454CA  movzx         rbx, $01345086 byte-offset
$013454D1  push          rbx
$013454D2  ;
FORTH> $01345086 c@ . 123  ok
-marcel
---
\ in THIS file
CREATE myinsert
," ] CR DUP . R@ . S .  one . two . three . one two * three * DUP TO
result ["
: MAIN0 ( -- )
  1 2 3 0 LOCALS| result three two one |
  4 >S 5 >R 6
  [ myinsert COUNT EVALUATE ] ( compile time, locals accessible )
  CR ." myinsert compiled  `one two * three * DUP TO result` "
  CR ." stack            = "    . ." \ 6"
  CR ." R>               = " R> . ." \ 5"
  CR ." S>               = " S> . ." \ 4"
  CR ." one, two, three  = " one . two . three . ." \ 1 2 3"
  CR ." MAIN0 does `one two * three *` = " 0DEC.R
           ." , result = " result . ;
\ in file inside1.frt
\ ] CR DUP . R@ . S .  one . two . three . one two * three * DUP TO
result [
: MAIN1 ( -- )
  1 2 3 0 LOCALS| result three two one |
  4 >S 5 >R 6
  [ S" inside1.frt" INCLUDED ]  ( at compile time, locals accessible )
  CR ." inside1.frt compiled  `one two * three * DUP TO result` "
  CR ." stack            = "    . ." \ 6"
  CR ." R>               = " R> . ." \ 5"
  CR ." S>               = " S> . ." \ 4"
  CR ." one, two, three  = " one . two . three . ." \ 1 2 3"
  CR ." MAIN1 does `one two * three *` = " 0DEC.R
           ." , result = " result . ;
\ in file inside2.frt
\ CR .( I see ) DUP . .( on the stack, ) S .
\    .( on the S-stack, locals one/two/three = ) OVER . 2 PICK . 3 PICK

Date Sujet#  Auteur
19 Dec 24 * How robust is INCLUDE5mhx
20 Dec 24 +- Re: How robust is INCLUDE1Anton Ertl
20 Dec 24 +* Re: How robust is INCLUDE2minforth
20 Dec 24 i`- Re: How robust is INCLUDE1mhx
29 Jan 25 `- Re: How robust is INCLUDE1Ruvim

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal