Proposal: word PERFORM
This page is dedicated to discussing this specific proposal
ContributeContributions
agsb
[428] word PERFORMProposal2026-04-23 13:03:44
Author:
Alvaro Gomes Sobral Barcellos
Change Log:
None
Problem:
How execute words defined only with native code ?
Use a new word PERFORM as alternative for CODE END-CODE.
Proposal
A proposed word PERFORM, to take a address of top of stack (TOS) and make a native "link and jump" to that address, execute that native code then return to continue at next forth word. Like EXECUTE, but doing an execute of native code instead of Forth code.
Typical use:
A pure native code word could be defined with
: NAME_OF_WORD $hexcode , $hexcode , ( etc ) $hexcode , ;
Where $hexcode is the hexadecimal representation of opcode and operands.
That word could be executed with: PERFORM ' NAME_OF_WORD
Reference implementation:
The word PERFORM must be defined using native code.
Using RiscV, s0 is the data stack pointer, s1 is the return stack pointer,
#----------
#header_of_word ( depends on implementation )
#----------
# take TOS value
lw a0, 0 (s0)
# pull, update stack pointer
addi s0, s0, -4
# link to ra and jump to absolute address
jalr ra, 0 (a0)
# go to next word
j next
# ---------- elsewhere
# header of word
#----------
# address (xt)
# ( some native code )
# that ends with jalr r0, 0 (ra) same as ret
ret
# ----------