Proposal: word PERFORM

Informal

This page is dedicated to discussing this specific proposal

ContributeContributions

agsbavatar of 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

# ----------

pdaavatar of pda

From the description in proposal section, the execution should be ' NAME_OF_WORD PERFORM rather than PERFORM ' NAME_OF_WORD

Anyway I don't see the reason for this new word, you already can execute a native word with EXECUTE, the aleged reason to be an alternative to CODE / END-CODE is related to definition rather than execution and thus the responsability relies in word " : " or some other word similar to CODE / END-CODE so , why reinvent the wheel ?

AntonErtlavatar of AntonErtl

It is not clear what the problem is that you want to solve.

A word defined with code ... end-code can be executed. It has to be defined in a system-specific way with a system-specific way to end the word and proceed to the code behind it; in a threaded-code system, code words end in the NEXT sequence, in a native-code system, they usually end with a kind of return-from-subroutine instruction.

You seem to want to define words that are invoked with jalr and that return to the instruction behind the jalr instruction, i.e., that end in a return-from-subroutine instruction, and want to call them in a threaded code system. It's not clear why you want to do that.

You might be interested in "ABI-CODE: Increasing the portability of assembly language words", but despite the fact that abi-code is in Gforth, I don't think there is enough common practice (or usage) to merit standardization at this time. If you implement abi-code, it becomes more common. But abi-code words can be executed and do not need a separate word for that purpose.

Reply New Version