programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Code Snippet

From: Charles Melice <mail_at_forthcad.com>
Date: Wed, 5 Nov 2003 15:04:33 +0100

Simple but usefull...

Charles
_______________________

\ R-ALLOC-N ( size n -- n*addr )
\ -------------------------------
\ Allocates a count of n*size byte on the return stack
\ and returns n consecutives addresses fields.

: make-fields ( size n addr -- n*addr' )
    swap 0 ?DO ( size addr) tuck over + LOOP 2drop ;

: R-ALLOC-N ( size n -- n*addr )
    postpone 2dup
    postpone *
    postpone r-alloc
    postpone make-fields ; immediate

\\ test

: rect. ( rect -- )
    @+ . @+ . @+ . ? ;
(
struct
    1 cell field rect.left
    1 cell field rect.top
    1 cell field rect.right
    1 cell field rect.bottom
end-struct RECT-STRUCT
)
4 cells constant RECT-SIZE

: test
    RECT-SIZE 3 r-alloc-n locals| rect3 rect2 rect1 |
    1 2 3 4 rect1 !rect
    5 6 7 8 rect2 !rect
    9 10 11 12 rect3 !rect
    rect1 rect.
    rect2 @rect rect1 !rect
    rect1 rect.
    rect3 @rect rect1 !rect
    rect1 rect. ;

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Wed Nov 05 2003 - 06:10:33 PST

This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:34 PST