mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 01:30:22 +00:00
Add .frt samples for Forth.
This commit is contained in:
8
samples/Forth/bitmap.frt
Normal file
8
samples/Forth/bitmap.frt
Normal file
@@ -0,0 +1,8 @@
|
||||
\ Bit arrays.
|
||||
: bits ( u1 -- u2 ) 7 + 3 rshift ;
|
||||
: bitmap ( u "name" -- ) create bits here over erase allot
|
||||
does> ( u -- a x ) over 3 rshift + 1 rot 7 and lshift ;
|
||||
: bit@ ( a x -- f ) swap c@ and ;
|
||||
: 1bit ( a x -- ) over c@ or swap c! ;
|
||||
: 0bit ( a x -- ) invert over c@ and swap c! ;
|
||||
: bit! ( f a x -- ) rot if 1bit else 0bit then ;
|
||||
7
samples/Forth/enum.frt
Normal file
7
samples/Forth/enum.frt
Normal file
@@ -0,0 +1,7 @@
|
||||
\ Implements ENUM.
|
||||
|
||||
\ Double DOES>!
|
||||
: enum create 0 , does> create dup @ 1 rot +! , does> @ ;
|
||||
|
||||
\ But this is simpler.
|
||||
: enum create 0 , does> dup @ constant 1 swap +! ;
|
||||
8
samples/Forth/macros.frt
Normal file
8
samples/Forth/macros.frt
Normal file
@@ -0,0 +1,8 @@
|
||||
\ Simplifies compiling words.
|
||||
|
||||
: [[ ; immediate
|
||||
: '<> >in @ ' swap >in ! <> ;
|
||||
: (]]) begin dup '<> while postpone postpone repeat drop ;
|
||||
: ]] ['] [[ (]]) ; immediate
|
||||
|
||||
( Usage: : foo ]] dup * [[ ; immediate : bar 42 foo . ; )
|
||||
Reference in New Issue
Block a user