# HG changeset patch # Parent 256a83a960ce84da47c9cbb4113a26fdf25da428 Implement the echo command in forth and an example of a built-in command in forth. diff -r 256a83a960ce sys/boot/forth/loader.4th --- a/sys/boot/forth/loader.4th +++ b/sys/boot/forth/loader.4th @@ -120,10 +120,28 @@ only forth also support-functions also b ?dup 0= if 0 1 autoboot then ; +\ ***** echo4th +\ +\ Echo the command arguments back. +\ NB: Not too useful, except as an example of argument parsing in FORTH +\ for new built-in comands. +: echo4th + \ First argument is 0 when we're interprated. See support.4th + \ for get_arguments reading the rest of the line and parsing it + 0= if ( interpreted ) get_arguments then + \ stack: argN lenN ... arg1 len1 N + 0 do \ loop 0 to N - 1 + type \ Pop length and address off and print it. + 32 emit \ followed by a space + loop + cr +; + also forth definitions also builtins builtin: boot builtin: boot-conf +builtin: echo4th only forth definitions also support-functions @@ -245,4 +263,3 @@ include /boot/check-password.4th ; immediate \ interpret immediately for access to `source' (aka tib) only forth also -