Author: | Charles Childers |
---|---|
Version: | 2009.12.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( This is an implementation of crc's ifExists which demonstrates the ) | |
( parsing of curly braces for the conditional evaluation of text. ) | |
{{ | |
: cut ( a-a ) | |
dup getLength over + 1- dup @ 32 =if | |
0 swap ! else drop then ; | |
: "cut ( c"-a ) accept tib tempString cut ; | |
: '{ ( "-a ) char: { "cut ; | |
: '} ( "-a ) char: } "cut ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) | |
( For loop with an index that counts from zero, placed on the ) | |
( top of the stack with each iteration. Uses NORS to keep ) | |
( track of the original value, so nexti must be used to clean ) | |
( up when loop is complete. ) | |
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) | |
: fori ` dup ` push ` for ` pop ` pop ` 2dup | |
` push ` push ` swap ` - ; compile-only | |
: nexti ` next ` pop ` drop ; compile-only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( This is an attempt at creating some rather sophisticated macros ) | |
( using fori/nexti. It does not work yet. ) | |
{{ | |
variable addr | |
: pad ( - ) addr @ @ 6 for dup base @ r pow <if 32 emit then next ; | |
: .wrap ( - ) ." ( " later ." )" ; | |
: .name ( a- ) .wrap d->name type ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( Stack and list manipulation. ) | |
: allot heap +! ; | |
: -allot heap -! ; | |
: sav ` dup ` push ; immediate | |
: tempsave ( ?n- ) for here r 1- + ! next ; | |
: tempload ( n-? ) for here r 1- + @ next ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( A macro for appending code blocks. ) | |
{{ | |
: prepend ( $$-$ ) here -rot 2 for dup here swap getLength dup allot copy next 0 , ; | |
: $space ( $-$ ) s" " prepend ; | |
---reveal--- | |
: append-block 32 accept tib @ char: { =if | |
char: } accept tib tempString keepString literal, | |
` $space ` swap ` prepend then ; compile-only | |
: code ( "- ) ` append-block ` dup ` getLength ` eval ; compile-only | |
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: | char: | accept ; | |
{{ | |
| find $- ::: true if $ is a word. | | |
| accept c"- ::: parsed text (delimited by c) goes at tib | | |
| tib -$ ::: used to access text after parsing. | | |
| nip xy-y ::: shorthand for swap drop | | |
| dup n-nn ::: duplicate top of stack | | |
| char: "-c ::: macro, gets a char at compile time. | | |
| if f- ::: jump to then if flag is false (at execute time) | | |
| then - ::: macro for the place that if jumps to when flag is false. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) | |
( do ... until ) | |
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) | |
( Value n is taken from the stack and stored to a virtual ) | |
( variable. When this number is equal to the TOS at the time ) | |
( until is executed, the loop terminates. ) | |
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) | |
{{ | |
: skipped-nop ( - ) 8 , here 2 + , 0 , ; |
The program:
( buffering input ) {{ 64 constant width 4 constant lines variable num