p4_bracket_defined_p4_bracket_not_p4_cpu_nr_p4_dot_h2_p4_fetch_from_p4_fetch_from_execution_p4_goto_cpu_RT_p4_immediate_bit_p4_into_p4_into_execution_p4_into_local_execution_p4_load_cpus_p4_loadf_p4_make_p4_make_to_execution_p4_make_to_local_execution_p4_prefix_begin_p4_prefix_end_p4_prefix_end_doubled_p4_printf_p4_semicolon_and_p4_semicolon_and_execution_p4_smart_interpret_initp4_smart_interpret_init_p4_smart_interpret_off_p4_smart_interpret_on_p4_smudge_bit_p4_sprintf_p4_store_to_p4_tick_from_p4_to_compilep4_to_compile_p4_var_p4_zero_local_RT_p4_callp4_compile1p4_compile2p4_forget_loadfp4_forget_wordp4_goto_cpup4_header_fromp4_herewordp4_make_headp4_outfp4_outsp4_parsewordp4_smart_interpret_charp4_store_c_stringp4_bracket_defined_ : [DEFINED] word ( -- nfa|0 ) immediate ' [IF][IFDEF] word[DEFINED] word [IF]reference: ../src/yours.c:0803
p4_bracket_not_ : [NOT] ( a -- a' ) 0= [IF][IFNOT] [DEFINED][DEFINED] word [NOT] [IF][IFNOTDEF] wordreference: ../src/yours.c:0821
p4_cpu_nr_ : CPU# ( -- )reference: ../src/yours.c:0379
p4_dot_h2_ : .H2 ( value -- )0x0 -> 00 0xf -> 0f 0x12 -> 12 0x123 -> 0123 0x1234 -> 1234 0x12345 -> 012345
reference: ../src/yours.c:0523
p4_fetch_from_ : @> name ( -- value ) VARIABLE VALUE LVALUE LOCALS| VAR DEFER DOER DOES>reference: ../src/yours.c:0199
p4_fetch_from_execution_ : ((@>)) ( -- value ) @>reference: ../src/yours.c:0186
p4_goto_cpu_RT_ : GOTO-CPU ( nr -- )reference: ../src/yours.c:0346
p4_immediate_bit_ : (IMMEDIATE#) ( -- bit-mask ) " my-word" FIND IF >FFA C@ (IMMEDIATE#) AND
IF ." immediate" THEN ELSE DROP THEN
reference: ../src/yours.c:0100
p4_into_ : INTO word ( -- pfa ) LOCALS| VARTO AINTO A !reference: ../src/yours.c:0733
p4_into_execution_ : ((INTO)) INTOreference: ../src/yours.c:0710
p4_into_local_execution_ : ((INTO-)) ( -- value ) INTOreference: ../src/yours.c:0718
p4_load_cpus_ : <<CPU>> ( -- )reference: ../src/yours.c:0357
p4_loadf_ : LOADF filename ( -- ) INCLUDE MARKER LOADED FORGETreference: ../src/yours.c:0552
p4_make_ : MAKE word ... ;AND ( -- ) MAKE ;AND MAKE DOER DEFER NOOP MAKE LOCALS| VARreference: ../src/yours.c:0617
p4_make_to_execution_ : ((MAKE)) MAKEreference: ../src/yours.c:0593
p4_make_to_local_execution_ : ((MAKE-)) MAKEreference: ../src/yours.c:0583
p4_prefix_begin_ : ($ word ( -- cs-token ) compile-only ) >COMPILE($ IF ($ 0= A1 @ )) ($ THEN ." hello " )Note that an opening simple
(reference: ../src/yours.c:0152
p4_prefix_end_ : ) ( cs-token -- ) ($ >COMPILEreference: ../src/yours.c:0163
p4_prefix_end_doubled_ : )) ( cs-token cs-token -- ) ($ >COMPILE simulate:
: )) [COMPILE] ) [COMPILE] ) ; IMMEDIATE
reference: ../src/yours.c:0175
p4_printf_ : PRINTF ( args ... format$ -- ) SPRINTF SPRINTFreference: ../src/yours.c:0507
p4_semicolon_and_ : ;AND ( -- ) MAKE ;AND EXIT MAKEreference: ../src/yours.c:0653
p4_semicolon_and_execution_ : (;AND) ;ANDreference: ../src/yours.c:0640
p4_smart_interpret_init :reference: ../src/yours.c:0280
p4_smart_interpret_init_ : SMART-INTERPRET-INITIMMEDIATEDEFER SMART-INTERPRET-INIT"hello"" hello"\if-unix\if-unknownreference: ../src/yours.c:0298
p4_smart_interpret_off_ : SMART-INTERPRET-OFF INTERPRET SMART-INTERPRET-INITreference: ../src/yours.c:0317
p4_smart_interpret_on_ : SMART-INTERPRET-ON INTERPRET SMART-INTERPRET-INITreference: ../src/yours.c:0327
p4_smudge_bit_ : (SMUDGE#) ( -- bit-mask ) " my-word" FIND IF >FFA C@ (SMUDGE#) AND
IF ." smudge" THEN ELSE DROP THEN
reference: ../src/yours.c:0110
p4_sprintf_ : SPRINTF ( args ... format$ dest$ -- len-dest ) variable A 256 ALLOT 15 " example" " the %#s value is %i" A 1+ SPRINTF A C! A COUNT TYPE
reference: ../src/yours.c:0497
p4_store_to_ : !> name ( value -- ) TOreference: ../src/yours.c:0696
p4_tick_from_ : '> name ( -- xt ) ' [']reference: ../src/yours.c:0679
p4_to_compilereference: ../src/yours.c:0137
p4_to_compile_ : >COMPILE ( xt -- ) POSTPONE IF THEN POSTPONE COMPILE [COMPILE] INTERPRETreference: ../src/yours.c:0135
p4_var_ : VAR name ( -- ) VALUE LVALUE VALUE LVALUEreference: ../src/yours.c:0780
p4_zero_local_RT_ : ((0LVALUE)) VARreference: ../src/yours.c:0769
p4_call : >COMPILE POSTPONEreference: ../src/yours.c:0124
p4_compile1reference: ../src/yours.c:0752
p4_compile2reference: ../src/yours.c:0745
p4_forget_loadfreference: ../src/yours.c:0539
p4_forget_wordreference: ../src/yours.c:0562
p4_goto_cpureference: ../src/yours.c:0348
p4_header_from :reference: ../src/yours.c:0272
p4_herewordreference: ../src/yours.c:0221
p4_make_head :To make a new primitive Forth word, you have to write a C function of type
static void name_(void)
Use the preprocessor macro
FCode (p4_name)
to provide the prototype with the underscore appended to the name. The underscore helps to avoid name clashes with names and keywords of the C language.
If you want to call such a primitive from C-source you must of course append the underscore to the name in the function call yourself. If you want to call it from another input file then you must leave out the `static' keyword in the function definition, which is what the alternative macro
code (name)
does. Both are of course nothing but shortcuts to ease input of all those words.
Having defined a primitive you must add it to the forth dictionary in order to make it visible to Forth. At the end of each input file defining forth primitives you'll find a table declared with the macro
LISTWORDS (wordset_name) = { ... };
This declares a vector of some type and shows how to continue with the initialization of the vector. Each vector element registers a forth word for loading into the dictionary at startup. In p4th the dictionary is not an initialized C structure but it is built from such structures -- like the one described here -- at startup.
To enter words into this table there are several macros, all for brevity named with two uppercase letters. Using such a macro adds one more element to the list of initializers following the LISTWORDS declaration. Besides primitives you can enter variables and constants to the dictionary this way.
CO (NAME, c-name) a primitive, not immediate CI (NAME, c-name) an immediate primitive CS (NAME, c-name) a primitive with separate execution and compilation semantics, see examples in core.c (if, case etc.) and macros in p4_comp.h and -- good luck :-) OV (NAME) a normal variable OC (NAME, value) a normal constant OL (NAME, value) a normal value IV (NAME) an immediate variable IC (NAME, value) an immediate constant IL (NAME, value) an immediate value
reference: ../src/yours.c:0367
p4_outfreference: ../src/yours.c:0533
p4_outsreference: ../src/yours.c:0511
p4_parsewordreference: ../src/yours.c:0808
p4_smart_interpret_char :reference: ../src/yours.c:0248
p4_store_c_stringreference: ../src/yours.c:0559