nxu/arg-demo.tal

44 lines
1.3 KiB
Tal

( program demonstrating how to use arg.tal )
( )
( by d_m )
( )
( this program just parses the given arguments, )
( says how many arguments were provided, and )
( prints each argument with its index. )
|0100
;callback ;on-stdin arg/init BRK
( this needs to end in BRK )
@on-stdin ( -> BRK )
BRK
( this needs to return, i.e. end in JMP2r )
@callback ( -> )
;arg/count LDA LIT "0 ADD
;message/num STA
;message emit
;arg/count LDA #00 ( count^ 0^ )
&loop ( count^ i^ )
GTHk ?&ok ( count^ i^ )
POP2 #010f DEO JMP2r ( ; exit )
&ok ( count^ i^ )
DUP LIT "0 ADD #18 DEO ( count^ i^ ; index )
LIT ": #18 DEO ( count^ i^ ; index )
#2018 DEO ( count^ i^ ; space )
DUP arg/read emit ( count^ i^ s* ; string )
#0a18 DEO ( count^ i^ ; newline )
INC !&loop ( count^ i+1^ )
( this is used to print null-terminated strings )
@emit ( buf* -> )
LITr 18 ( buf* [dev^] )
&lp LDAk ?&k POP2 POPr JMP2r ( )
&k LDAk STHkr DEO INC2 !&lp ( buf+1* [dev^] )
( message to print )
@message "found 20 &num "X 20 "arguments 0a 00
( include arg.tal library )
~arg.tal