- ABORT
- ABORT"
- ABS
- ACCEPT
- ACTION-OF
- AGAIN
- ALIGN
- ALIGNED
- ALLOT
- AND
- BASE
- BEGIN
- BL
- BUFFER:
- [
- [CHAR]
- [COMPILE]
- [']
- CASE
- C,
- CELL+
- CELLS
- C@
- CHAR
- CHAR+
- CHARS
- COMPILE,
- CONSTANT
- COUNT
- CR
- CREATE
- C!
- :
- :NONAME
- ,
- C"
- DECIMAL
- DEFER
- DEFER@
- DEFER!
- DEPTH
- DO
- DOES>
- DROP
- DUP
- /
- /MOD
- .R
- .(
- ."
- ELSE
- EMIT
- ENDCASE
- ENDOF
- ENVIRONMENT?
- ERASE
- EVALUATE
- EXECUTE
- EXIT
- =
- FALSE
- FILL
- FIND
- FM/MOD
- @
- HERE
- HEX
- HOLD
- HOLDS
- I
- IF
- IMMEDIATE
- INVERT
- IS
- J
- KEY
- LEAVE
- LITERAL
- LOOP
- LSHIFT
- MARKER
- MAX
- MIN
- MOD
- MOVE
- M*
- -
- NEGATE
- NIP
- OF
- OR
- OVER
- 1-
- 1+
- PAD
- PARSE-NAME
- PARSE
- PICK
- POSTPONE
- +
- +LOOP
- +!
- QUIT
- RECURSE
- REFILL
- REPEAT
- RESTORE-INPUT
- R@
- ROLL
- ROT
- RSHIFT
- R>
- SAVE-INPUT
- SIGN
- SM/REM
- SOURCE-ID
- SOURCE
- SPACE
- SPACES
- STATE
- SWAP
- ;
- S\"
- S"
- S>D
- !
- THEN
- TO
- TRUE
- TUCK
- TYPE
- '
- *
- */
- */MOD
- 2DROP
- 2DUP
- 2/
- 2@
- 2OVER
- 2R@
- 2R>
- 2SWAP
- 2!
- 2*
- 2>R
- U.R
- UM/MOD
- UM*
- UNLOOP
- UNTIL
- UNUSED
- U.
- U<
- U>
- VALUE
- VARIABLE
- WHILE
- WITHIN
- WORD
- XOR
- 0=
- 0<
- 0>
- 0<>
- \
- .
- <
- >
- <>
- #>
- <#
- #
- #S
- (
- ?DO
- ?DUP
- >BODY
- >IN
- >NUMBER
- >R
6.1.0710 ALLOT CORE
If n is greater than zero, reserve n address units of data space. If n is less than zero, release | n | address units of data space. If n is zero, leave the data-space pointer unchanged.
If the data-space pointer is aligned and n is a multiple of the size of a cell when ALLOT begins execution, it will remain aligned when ALLOT finishes execution.
If the data-space pointer is character aligned and n is a multiple of the size of a character when ALLOT begins execution, it will remain character aligned when ALLOT finishes execution.
See:
Testing:
ContributeContributions
TG9541 [190] ALLOT in ROMable systemsRequest for clarification2021-04-18 09:07:57
Problem statement
ALLOT
assumes that the data space for mutable data and for compiled code is one and the same. This is a problem for ROMable systems (i.e. the dictionary is compiled to ROM).
Examples:
The compilation semantic of CREATE
doesn't indicate whether "data space" should be mutable or not. The problem could potentially be solved by ALLOT
(usage of which implies that data should be mutable).
Data Space is mutable
\ define a standard variable
VARIABLE x
\ create an array
CREATE array 10 ALLOT
:
#### Data Space is immutable:
\ the 10 first prime numbers CREATE primes 2 , 3 , 5 , 7, 11 , 13 , 17 , 19 , 23 , 29 ,
\ defining word for a table based interpolation using @inter : INTER ( u[x y] u "<spaces>name" -- ) CREATE DUP , 0 DO SWAP , , LOOP DOES> @inter ;
### Discussion
The problem of defining the intent of memory allotment could potentially be solved by `ALLOT` (assuming that it indicates that data should be mutable). This is, however, not compliant with the standard definition of that word. In fact the test defined in `ALLOT` (which is normative, I suppose) is based with the assumption that the dictionary is in RAM:
HERE 1 ALLOT HERE CONSTANT 2NDA CONSTANT 1STA T{ 1STA 2NDA U< -> <TRUE> }T \ HERE MUST GROW WITH ALLOT T{ 1STA 1+ -> 2NDA }T \ ... BY ONE ADDRESS UNIT ( MISSING TEST: NEGATIVE ALLOT )
It's also possible to use `VARIABLE` to indicate the intent of a data space allotment:
\ define a mutable array with 10 chars VARIABLE carray 4 CELLS ALLOT
This idiomatic definition of mutable arrays appears not to be precluded by the tests in the standard:
T{ VARIABLE V1 -> }T T{ 123 V1 ! -> }T T{ V1 @ -> 123 }T
```
FlashForth uses data space prefixes (i.e. ram
, eeprom
) to solve the problem. This requires, however, to first amend any source code, including code from a packet repository.
The solution in STM8 eForth is to use the (known) compilation target semantics of the Forth system (i.e. RAM
or NVM
for "Non Volatile Memory") to compile to ROM or to RAM (executable data space), ALLOT
memory beneath the code or in a RAM block reserved for mutable data , and to compile a matching run-time word (either dovar
or dovarptr
).
To sum it up:
- the tests given in
ALLOT
assume an implementation that's not ROMable - in ROMable systems "data space" is ambiguous with respect to use cases of
CREATE
- there is a potential to infer the intended properties of the data space from the idiomatic use which might be used to write portable code
It's of course also possible to define ROMable systems as out-of-scope for a Forth Standard (and maybe in the scope of a different standard?).
Clarification or guidance is highly appreciated.