Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

*** NEW POINTERS ***

1 view
Skip to first unread message

Jason Damisch

unread,
Sep 4, 2007, 8:32:04 PM9/4/07
to
\ ***** NEW POINTERS *****

\ Jason Damisch 2007

\ this is very flexable and neat

: <:POINTER>

\ ( vector index -- vector index )

CREATE \ create the pointer

2DUP SWAP , , \ dup the stuff on the stack and give it to
the new constant

CELL + \ bump up the index on the stack

;

: :POINTER

<:POINTER>

DOES>

2@ EXECUTE

;

: START

0

;

: FINISH

\ ( vector index -- )

2DROP

;

: MORE

\ ( #bytes -- )

CELL NEGATE + \ get rid of the cell index

+ \ give it any specific index

;

\ Here are some **examples** of use

\ this will add the index to anything on the stack

' +

START

:POINTER FRED

:POINTER WILMA

:POINTER BARNEY

:POINTER BETTY

FINISH

\ one way to use this with a single array

10 CONSTANT /ROW

CREATE ARRAY

/ROW 6 * CELLS ALLOT

:NONAME ARRAY + ;

START

:POINTER PEABODY /ROW MORE

:POINTER SHERMAN /ROW MORE

:POINTER ROCKY /ROW MORE

:POINTER BULLWINKLE /ROW MORE

:POINTER BORIS /ROW MORE

:POINTER NATASHA /ROW MORE

FINISH

\ data segments each of who's elements are of nonuniform size

' +

START

:POINTER A 3 MORE

:POINTER B 7 MORE

:POINTER C 8 MORE

:POINTER D 9 MORE

:POINTER E 2 MORE

FINISH

\ more complex array indexing

5 CONSTANT #ROWS 10 CONSTANT #COLLUMNS

#COLLUMNS CELLS CONSTANT /ROW

CREATE TABLE

#ROWS #COLLUMNS * CELLS ALLOT

\ collumn -- adr

:NONAME SWAP CELLS + TABLE + ;

START

:POINTER PORTLAND /ROW MORE

:POINTER SALEM /ROW MORE

:POINTER CORVALLIS /ROW MORE

:POINTER EUGENE /ROW MORE

:POINTER SPRINGFIELD /ROW MORE

FINISH

\ the possibilites are practically endless

\ I know it might be a little more typing at

\ compile time with MORE but then again it

\ can be faster at execute time :^)

Jenny Brien

unread,
Sep 8, 2007, 1:17:13 PM9/8/07
to
On Sep 5, 1:32 am, Jason Damisch <jasondami...@yahoo.com> wrote:
> \ ***** NEW POINTERS *****
>
> \ Jason Damisch 2007
>
> \ this is very flexable and neat
>
Yes, for this purpose I have long used:

: [] DUP CONSTANT ;

which possibly gives the most results per length of code.

>
> \ one way to use this with a single array
>
> 10 CONSTANT /ROW
>
> CREATE ARRAY
>
> /ROW 6 * CELLS ALLOT
>
>

The pointer addresses here can be calculated at compile time:

ARRAY
[] PEABODY /ROW +
[] SHERMAN /ROW +
etc..
DROP

Which is fine if you have just one instance of an array, otherwise you
begin your declaration at 0 and explicitly add the named offset: e.g.

anotherarray SHERMAN +

> \ data segments each of who's elements are of nonuniform size
>

No problem, just change the size added as required.

0
[] A CELL+
[] B 2 CELLS +
[] C 3 CELLS +
[] D 4 CELLS +
CONSTANT /ROW
>
> \ more complex array indexing
>
CREATE TABLE 5 /ROW * ALLOT

The rows of the table could then be individually named as in the
example above, and individual items accessed thus:

SALEM B +

or randomly by row index:

n /ROW * TABLE + C +

or step through all entries with a loop:

TABLE C + 5 0 DO
DUP do-something
/ROW +LOOP
DROP


hel...@gmail.com

unread,
Sep 8, 2007, 1:31:48 PM9/8/07
to
On Sep 8, 7:17 pm, Jenny Brien <jennybr...@googlemail.com> wrote:
> On Sep 5, 1:32 am, Jason Damisch <jasondami...@yahoo.com> wrote:> \ ***** NEW POINTERS *****
>
> > \ Jason Damisch 2007
>
> > \ this is very flexable and neat
>
> Yes, for this purpose I have long used:
>
> : [] DUP CONSTANT ;
>
> which possibly gives the most results per length of code.

Ah, well. Also very nice. But you know that the "pointers" are not
only about array indices? For me they look a little bit like OO-stuff.
One part is something like a "DEFER" and so you can use it in much
more interesting places than your [] ...

-Helmar

Jason Damisch

unread,
Sep 17, 2007, 5:24:24 PM9/17/07
to
\ Jenny, I was inspired to change my code baised upon what you
presented.

\ ***** NEW POINTERS *****
\ Jason Damisch 2007

\ this is very flexable and neat

\ this word is to facilitate less typing for the array indexing when
we create pointers
\ the name of [] saves on typing, but :POINTER actually gave a clue to
the newbies
\ the EXECUTE inside of the pointers is to facilitate somthing with
light shades of OOP

: []
\ ( vector incrementor index -- vector incrementor


index )
CREATE \ create the pointer

ROT DUP , -ROT \ give the vector to the new constant
DUP , \ give the index to the new constant
OVER EXECUTE \ bump up the index, not yet knowing what that
will be
DOES> 2@ EXECUTE
;


\ Here are some **examples** of use


\ this will add the index to anything on the stack

' +
' CELL+
0
[] FRED
[] WILMA
[] BARNEY
[] BETTY
3DROP \ HI

\ byte array

10 CONSTANT /ROW
CREATE ARRAY

/ROW 6 * ALLOT

' NOOP
:NONAME /ROW + ;
ARRAY
[] PEABODY
[] SHERMAN
[] ROCKY
[] BULLWINKLE
[] BORIS
[] NATASHA
3DROP

\ data segments each of who's elements are of nonuniform size

' +
:NONAME BL WORD COUNT NUMBER CELLS + ;
0
[] A 3
[] B 7
[] C 8
[] D 9
[] E 2
3DROP

\ more complex array indexing

5 CONSTANT #ROWS 10 CONSTANT #COLLUMNS
#COLLUMNS CELLS CONSTANT /ROW
CREATE TABLE
#ROWS #COLLUMNS * CELLS ALLOT

\ collumn -- adr
:NONAME SWAP CELLS + ;
:NONAME /ROW + ;
TABLE
[] PORTLAND
[] SALEM
[] CORVALLIS
[] EUGENE
[] SPRINGFIELD
3DROP

0 new messages