Completed FORTH command line arg printing and added comments
to document example better.
This commit is contained in:
parent
fdbb99aeeb
commit
b0196162a9
1 changed files with 20 additions and 4 deletions
|
|
@ -3,15 +3,31 @@
|
||||||
\ Sample Hello World! Forth script...
|
\ Sample Hello World! Forth script...
|
||||||
\
|
\
|
||||||
|
|
||||||
|
\ Define "verinfo"
|
||||||
: verinfo s" git describe --abbrev=7 --dirty --always --tags" system ;
|
: verinfo s" git describe --abbrev=7 --dirty --always --tags" system ;
|
||||||
|
|
||||||
|
\ Define "printargs"
|
||||||
|
: printargs
|
||||||
|
\ The argc variable contains the count of cmd line args
|
||||||
|
\ in gforth, so we put it's value (@) on the stack plus
|
||||||
|
\ the number one and test if the value is greater than one.
|
||||||
|
argc @ 1 > if
|
||||||
|
\ condition is true, so put the value of argc (@)
|
||||||
|
\ on the stack and the value one as the range of
|
||||||
|
\ our do loop - we don't pring arg 0 which is the
|
||||||
|
\ name of the program.
|
||||||
|
argc @ 1 do i arg type space loop cr
|
||||||
|
else
|
||||||
|
\ condition is false, so don't print anything
|
||||||
|
cr
|
||||||
|
then ;
|
||||||
|
|
||||||
|
|
||||||
\ Obligatory Hello World with some version info
|
\ Obligatory Hello World with some version info
|
||||||
.( Hello Forth World! Version: ) verinfo cr
|
.( Hello Forth World! Version: ) verinfo cr
|
||||||
|
|
||||||
|
|
||||||
\ Show list of command line arguments
|
\ Show list of command line arguments
|
||||||
: printargs
|
.( Command line args: ) printargs
|
||||||
argc @ 0 do i arg type cr loop ;
|
|
||||||
.( Command line args: ) cr
|
|
||||||
printargs
|
|
||||||
|
|
||||||
bye
|
bye
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue