On Sun, 23 Mar 2008 21:31:37 -0400, "Robert Miller"
<rsmiller@[EMAIL PROTECTED]
> wrote:
>Unfortunately, the Forth I'm using (SwiftX for the TI msp430) apparently
>doesn't include the optional ANSI locals word set. I can envision a
variant
>using VARIABLE declarations for x, y, xx, and xy but that would
permanantly
>allocate scarce (in my application ) RAM.
A few years ago we used our PowerView embedded GUI as a test case for
"delocalling" some old code. What we found was that you use locals
when:
a) you have unstructured data
b) you intrinsically have more data items than fit comfortably
on the stack.
In a graphics environment, you do not have unstructured data, you
have a collection of points. Especially if you are building a GUI
you have a collection of horizontal and vertical lines. For most
displays, it is worth optimising the line draw routine for these
two cases.
: h-line \ x y len --
: v-line \ x y len --
: rect \ x y w h --
\ *G Draw a rectangle at *\i{x,y} with width and height *\i{w,h}.
2>r \ -- x y ; R: -- w h
\ 1st vertical: x y h v-line
2dup r@[EMAIL PROTECTED]
v-line
\ 2nd vertical: x+w y h v-line
2dup swap 2r@[EMAIL PROTECTED]
-- x y y x w h ; R: -- w h
-rot + -rot v-line
\ horizontal: x y+h w h-line
2dup r> + r@[EMAIL PROTECTED]
h-line \ -- x y ; R: -- w
\ horizontal: x y w h-line
r> h-line
;
The higher level code can now deal with everything in terms of
rectangle or line structures passed by address. You can use
a word to unpack the structure.
: rect>coords \ rect -- x y w h
For NCC compilers, the overhead of unpacking the structure is
balanced by the reduction in stack shuffling. Phrases of the
form:
dup lit + @[EMAIL PROTECTED]
generate one instruction, just as a stack fetch or
save will.
Stephen
--
Stephen Pelc, stephenXXX@[EMAIL PROTECTED]
Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com
- free VFX Forth downloads


|