yours definitions



p4_bracket_defined_ : [DEFINED] word ( -- nfa|0 ) immediate

does check for the word using find (so it does not throw like ' ) and puts it on stack. As it is immediate it does work in compile-mode too, so it places its argument in the cs-stack then. This is most useful with a directly following [IF] clause, so that sth. like an [IFDEF] word can be simulated through [DEFINED] word [IF]

reference: ../src/yours.c:0803

p4_bracket_not_ : [NOT] ( a -- a' )

executes 0= but this word is immediate so that it does affect the cs-stack while compiling rather than compiling anything. This is useful just before words like [IF] to provide semantics of an [IFNOT]. It is most useful in conjunction with " [DEFINED] word" as it the sequence "[DEFINED] word [NOT] [IF]" can simulate "[IFNOTDEF] word"

reference: ../src/yours.c:0821

p4_cpu_nr_ : CPU# ( -- )

the goto-cpu feature will vanish. It is used to create a multi-forth in a non-threaded environment. This word returns the number of the cpu-dictionary that is currently in use.

reference: ../src/yours.c:0379

p4_dot_h2_ : .H2 ( value -- )

print hexadecimal, but with per-byte 0-padding
   0x0     -> 00
   0xf     -> 0f
   0x12    -> 12
   0x123   -> 0123
   0x1234  -> 1234
   0x12345 -> 012345

reference: ../src/yours.c:0523

p4_fetch_from_ : @> name ( -- value )

does fetch the value from the PFA of the named item, which may be about everything, including a VARIABLE , VALUE LVALUE , LOCALS| , VAR , DEFER , DOER , DOES> and more.

reference: ../src/yours.c:0199

p4_fetch_from_execution_ : ((@>)) ( -- value )

execution compiled by @>

reference: ../src/yours.c:0186

p4_goto_cpu_RT_ : GOTO-CPU ( nr -- )

the goto-cpu feature will vanish. It is used to create a multi-forth in a non-threaded environment. This word used the number and switches the QUIT-interpret loop to use the other cpu's dictionary.

reference: ../src/yours.c:0346

p4_immediate_bit_ : (IMMEDIATE#) ( -- bit-mask )

returns the bit-mask to check if a found word is immediate
    " my-word" FIND IF >FFA C@ (IMMEDIATE#) AND 
                       IF ." immediate" THEN ELSE DROP THEN

reference: ../src/yours.c:0100

p4_into_ : INTO word ( -- pfa )

will return the parameter-field address of the following word. Unlike others, this word will also return the address of LOCALS| and local VAR - so in fact a TO A and INTO A ! are the same. This word is most useful when calling C-exported function with a temporary local-VAR as a return-place argument - so the address of a local has to be given as an arg. Beware that you should not try to save the address anywhere else, since a local's address does always depend of the RP-depth.

reference: ../src/yours.c:0733

p4_into_execution_ : ((INTO))

execution compiled by INTO

reference: ../src/yours.c:0710

p4_into_local_execution_ : ((INTO-)) ( -- value )

execution compiled by INTO

reference: ../src/yours.c:0718

p4_load_cpus_ : <<CPU>> ( -- )

the goto-cpu feature will vanish. It had been used to create a multi-forth in a non-threaded environment. This word creates a number of CPU*-immediates that will switch the QUIT-interpret loop to use the other cpu's dictionary.

reference: ../src/yours.c:0357

p4_loadf_ : LOADF filename ( -- )

loads a file just like INCLUDE but does also put a MARKER in the LOADED dictionary that you can do a FORGET on to kill everything being loaded from that file.

reference: ../src/yours.c:0552

p4_make_ : MAKE word ... ;AND ( -- )

make a seperated piece of code between MAKE and ;AND and on execution of the MAKE the named word is twisted to point to this piece of code. The word is usually a DOER but the current implementation works on DEFER just as well, just as it does on other words who expect to find an execution-token in its PFA. You could even create a colon-word that starts with NOOP and can then make that colon-word be prefixed with the execution of the code piece. This MAKE does even work on LOCALS| and VAR but it is uncertain what that is good for.

reference: ../src/yours.c:0617

p4_make_to_execution_ : ((MAKE))

compiled by MAKE

reference: ../src/yours.c:0593

p4_make_to_local_execution_ : ((MAKE-))

compiled by MAKE

reference: ../src/yours.c:0583

p4_prefix_begin_ : ($ word ( -- cs-token ) compile-only

takes the execution token of the following word and saves it on the compile-stack. The correspondig closing ) will then feed it into >COMPILE - so this pair of word provides you with a prefix-operation syntax that you may have been seen in lisp-like languages.
   ($ IF ($ 0= A1 @ )) ($ THEN ." hello " )
Note that an opening simple ( paren is a comment.

reference: ../src/yours.c:0152

p4_prefix_end_ : ) ( cs-token -- )

takes the execution-token from ($ and compiles it using >COMPILE

reference: ../src/yours.c:0163

p4_prefix_end_doubled_ : )) ( cs-token cs-token -- )

takes two execution-tokens from two of ($ and compiles them on after another using >COMPILE
 simulate:
    : )) [COMPILE] ) [COMPILE] ) ; IMMEDIATE

reference: ../src/yours.c:0175

p4_printf_ : PRINTF ( args ... format$ -- )

uses SPRINTF to print to a temporary 256-char buffer and prints it to stdout afterwards. See the example at SPRINTF of what it does internally.

reference: ../src/yours.c:0507

p4_semicolon_and_ : ;AND ( -- )

For the code piece between MAKE and ;AND , this word will do just an EXIT . For the code outside of the MAKE construct a branch-around must be resolved then.

reference: ../src/yours.c:0653

p4_semicolon_and_execution_ : (;AND)

compiled by ;AND

reference: ../src/yours.c:0640

p4_smart_interpret_init :

reference: ../src/yours.c:0280

p4_smart_interpret_init_ : SMART-INTERPRET-INIT

creates a set of interpret-words that are used in the inner interpreter, so if a word is unknown to the interpreter-loop it will use the first char of that word, attach it to an "interpret-" prefix, and tries to use that IMMEDIATE-DEFER-word on the rest of the word. This SMART-INTERPRET-INIT will set up words like interpret-" so you can write "hello" instead of " hello" and it creates interpret-\ so that words like \if-unix are ignoring the line if the word \if-unknown is unknown in itself. This is usually not activated on startup.

reference: ../src/yours.c:0298

p4_smart_interpret_off_ : SMART-INTERPRET-OFF

disables the SMART-INTERPRET extension in INTERPRET , see SMART-INTERPRET-INIT

reference: ../src/yours.c:0317

p4_smart_interpret_on_ : SMART-INTERPRET-ON

enables the SMART-INTERPRET extension in INTERPRET , see SMART-INTERPRET-INIT - the default for smart-interpret is always off

reference: ../src/yours.c:0327

p4_smudge_bit_ : (SMUDGE#) ( -- bit-mask )

returns the bit-mask to check if a found word is smudge
    " 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 )

just like the standard sprintf() function in C, but the format is a counted string and accepts %#s to be the format-symbol for a forth-counted string. The result is a zeroterminated string at dest$ having a length being returned. To create a forth-counted string, you could use:
   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 -- )

actually a synonym for TO but very common amongst forth interpreters

reference: ../src/yours.c:0696

p4_tick_from_ : '> name ( -- xt )

get the execution-token, ie the CFA, of the word following. This word is fully state-smart while the ANSI standard words namely ' and ['] are not.

reference: ../src/yours.c:0679

p4_to_compile

reference: ../src/yours.c:0137

p4_to_compile_ : >COMPILE ( xt -- )

does the work of POSTPONE on the execution token that you got from somewhere else - so it checks if the name (that correspond to the execution-token argument) is actually immediate, so it has to be executed to compile something, e.g. IF or THEN - see also POSTPONE , COMPILE , [COMPILE] , INTERPRET

reference: ../src/yours.c:0135

p4_var_ : VAR name ( -- )

a fully state-smart version, that does either create a VALUE or LVALUE and does always initialize it with null - so unlike either VALUE and LVALUE this word does not take any stack-argument. The name itself stems from javascript.

reference: ../src/yours.c:0780

p4_zero_local_RT_ : ((0LVALUE))

compiled by VAR

reference: ../src/yours.c:0769

p4_call :

see >COMPILE and POSTPONE

reference: ../src/yours.c:0124

p4_compile1

reference: ../src/yours.c:0752

p4_compile2

reference: ../src/yours.c:0745

p4_forget_loadf

reference: ../src/yours.c:0539

p4_forget_word

reference: ../src/yours.c:0562

p4_goto_cpu

reference: ../src/yours.c:0348

p4_header_from :

reference: ../src/yours.c:0272

p4_hereword

reference: ../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_outf

reference: ../src/yours.c:0533

p4_outs

reference: ../src/yours.c:0511

p4_parseword

reference: ../src/yours.c:0808

p4_smart_interpret_char :

reference: ../src/yours.c:0248

p4_store_c_string

reference: ../src/yours.c:0559