mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
begin folding the aa: words into a: (a:left, a:right, a:middle, a:length)
FossilOrigin-Name: c9ee0961c3a638beccc4d5c56d854acc065e43d597d92b6931356ad314a226b7
This commit is contained in:
parent
9be4e94b8d
commit
32bb71502e
4 changed files with 818 additions and 846 deletions
|
@ -1427,6 +1427,10 @@ dictionary header by the `d:xt` field.
|
|||
[ swap &nip dip ] &drop choose ] d:for-each drop ;
|
||||
~~~
|
||||
|
||||
~~~
|
||||
:gc (q-) &Heap swap v:preserve ;
|
||||
~~~
|
||||
|
||||
## Arrays
|
||||
|
||||
RETRO provides words for statically sized arrays. They are
|
||||
|
@ -1445,6 +1449,19 @@ we wrap this as `a:length`:
|
|||
:a:length (a-n) fetch ;
|
||||
~~~
|
||||
|
||||
To extract portions of an array, I provide `a:left`, `a:right`,
|
||||
and `a:middle`.
|
||||
|
||||
~~~
|
||||
:a:middle (afl-a)
|
||||
here [ dup , [ n:inc + ] dip
|
||||
here swap copy ] dip ;
|
||||
|
||||
:a:left (an-a) #0 swap a:middle ;
|
||||
:a:right (an-a) over a:length over - swap a:middle ;
|
||||
~~~
|
||||
|
||||
|
||||
The first couple of words are used to create arrays. The first,
|
||||
`a:counted-results` executes a quote which returns values
|
||||
and a count. It then creates an array with the provided data.
|
||||
|
@ -1632,31 +1649,6 @@ I'm defining a new `a:make` which wraps these.
|
|||
:} (-a) |] |dip |depth |swap |- |n:dec |] |a:make ; immediate
|
||||
~~~
|
||||
|
||||
To extract portions of an array, I provide `a:left`, `a:right`,
|
||||
and `a:middle`.
|
||||
|
||||
~~~
|
||||
{{
|
||||
:bounds? (an-anf) over a:length over lt? ;
|
||||
:copy (a-a) fetch-next , ;
|
||||
:to-end (a-a) dup a:length + n:inc ;
|
||||
---reveal---
|
||||
:a:left (an-a)
|
||||
bounds? [ drop-pair #-1 ] if;
|
||||
here over , [ &n:inc dip © times drop ] dip ;
|
||||
|
||||
:a:right (an-a)
|
||||
bounds? [ drop-pair #-1 ] if;
|
||||
here over , [ swap to-end over - swap © times drop ] dip ;
|
||||
|
||||
:a:middle (afl-a)
|
||||
&over dip swap over (abc-abcac
|
||||
bounds? [ drop-pair drop #-1 ] if; drop-pair
|
||||
dup-pair swap - n:inc
|
||||
here over , [ nip [ + n:inc ] dip © times drop ] dip ;
|
||||
}}
|
||||
~~~
|
||||
|
||||
For comparing arrays, use `a:eq?`. This is written in assembly
|
||||
to aid in performance and reduce size.
|
||||
|
||||
|
|
|
@ -33,16 +33,9 @@ null terminated. The `as` strings are length-prefixed instead.)
|
|||
|
||||
:as:map aa:map ;
|
||||
|
||||
:aa:middle (afl-a)
|
||||
here [ dup comma [ n:inc n:add ] dip
|
||||
here swap copy ] dip dup &Free store s:temp ;
|
||||
|
||||
:aa:left (an-a) #0 swap aa:middle ;
|
||||
:aa:right (an-a) over s:length over n:sub swap aa:middle ;
|
||||
|
||||
:as:left aa:left ;
|
||||
:as:right aa:right ;
|
||||
:as:middle aa:middle ;
|
||||
:as:left a:left ;
|
||||
:as:right a:right ;
|
||||
:as:middle a:middle ;
|
||||
|
||||
{{
|
||||
'Count var
|
||||
|
@ -72,7 +65,6 @@ null terminated. The `as` strings are length-prefixed instead.)
|
|||
|
||||
:as:filter aa:filter ;
|
||||
|
||||
:aa:length fetch ;
|
||||
:as:length fetch ;
|
||||
|
||||
:aa:th n:inc n:add ;
|
||||
|
@ -83,7 +75,7 @@ null terminated. The `as` strings are length-prefixed instead.)
|
|||
:as:store as:th store ;
|
||||
|
||||
:aa:first (a-n) #0 a:fetch ;
|
||||
:aa:last (a-n) dup aa:length n:dec aa:fetch ;
|
||||
:aa:last (a-n) dup a:length n:dec aa:fetch ;
|
||||
|
||||
:as:first aa:first ;
|
||||
:as:last aa:last ;
|
||||
|
@ -129,7 +121,7 @@ null terminated. The `as` strings are length-prefixed instead.)
|
|||
:as:eq? (ss-f) aa:eq? ;
|
||||
:as:-eq? (ss-f) aa:-eq? ;
|
||||
|
||||
:aa:dup here [ dup aa:length comma &comma a:for-each ] dip ;
|
||||
:aa:dup here [ dup a:length comma &comma a:for-each ] dip ;
|
||||
:as:dup aa:dup ;
|
||||
|
||||
:as:temp ;
|
||||
|
|
BIN
ngaImage
BIN
ngaImage
Binary file not shown.
1604
vm/nga-c/image.c
1604
vm/nga-c/image.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue