Skip to content

Instantly share code, notes, and snippets.

@fogus
Forked from Chouser/gist:20f114d9c53a647f2c12
Last active August 29, 2015 14:16
Show Gist options
  • Save fogus/6873451f58fd6bc7edd8 to your computer and use it in GitHub Desktop.
Save fogus/6873451f58fd6bc7edd8 to your computer and use it in GitHub Desktop.
: site-counter ( literal-int -- int )
here cell - { addr } \ store in 'addr' the address of the literal int preceding this in the user's code
postpone dup \ compile code to ...dup the int at the top of the data stack
postpone 1+ \ ...increment it
addr postpone literal \ ...push the above 'addr' onto the data stack
postpone ! \ ...copy the incremented value INTO THE USERS CODE
; immediate \ do all this at compile time
\ Now for a "normal" word defintion
: bar ( -- )
0 site-counter \ push zero onto the data stack and attach a counter
100 site-counter \ push 100 onto the data stack and attach a different counter to it
. . \ print the two values on the stack
;
bar
\=> 100 0 ok
bar
\=> 101 1 ok
bar
\=> 102 2 ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment