mirror of
https://github.com/forth-ev/VolksForth.git
synced 2024-11-29 05:49:26 +00:00
20 lines
359 B
Forth
20 lines
359 B
Forth
\ Arrays with bounds checking
|
|
|
|
| : (ARRAYERROR
|
|
ABORT" Array out of bounds!" ;
|
|
|
|
: ARRAY ( size -- )
|
|
CREATE DUP , 2* ALLOT
|
|
DOES> ( i -- addr )
|
|
OVER 0< (ARRAYERROR
|
|
2DUP @ 1- - 0> (ARRAYERROR
|
|
SWAP 1+ 2* + ;
|
|
|
|
: CARRAY ( size -- )
|
|
CREATE DUP , ALLOT
|
|
DOES> ( i -- addr )
|
|
OVER 0< (ARRAYERROR
|
|
2DUP @ 1- - 0> (ARRAYERROR
|
|
+ 1+ ;
|
|
|