Skip to content

Instantly share code, notes, and snippets.

@crcx
Forked from lsparrish/gist:255163
Created December 13, 2009 01:19
Show Gist options
  • Save crcx/255190 to your computer and use it in GitHub Desktop.
Save crcx/255190 to your computer and use it in GitHub Desktop.
: :create ( $- )
push :: save string pointer
here last dup @ , ! :: start new header, pointing to here
['] .data , :: class of .data
here 0 , :: xt = 0 (patched later)
pop dup getLength here :: get length of string, setup for copy
swap dup allot :: but first, allocate space for the name
copy 0 , :: copy name to allocated space, terminate string properly
here swap ! ; :: go back and patch the xt to point to here
: t s" test" :create ;
t words
: append ( $$-$ )
swap
here push
here over getLength dup allot copy
here over getLength dup allot copy
0 , pop ;
: prepend ( $$-$ ) swap append ;
: paren-wrap ( $-$ ) s" (" prepend s" )" append ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment