ANS Tester 
Author Message
 ANS Tester

I am writing an implementation of ANS forth and after running tester.fr and
core.fr I have some failure with does> behaviour. The test that fails is:

{ : WEIRD: CREATE DOES> 1 + DOES> 2 + ; -> }
{ WEIRD: W1 -> }
{ ' W1 >BODY -> HERE }
{ W1 -> HERE 1 + }
{ W1 -> HERE 2 + }

It is not clear to me what weird: is supposed to do. The two does is strange to
me. Could SO explain that?

Thanks,
Daniel.



Mon, 17 Jan 2000 03:00:00 GMT  
 ANS Tester


Quote:
ANDRE) writes:
>I am writing an implementation of ANS forth and after running
>tester.fr and core.fr I have some failure with does> behaviour. The
>test that fails is:
>{ : WEIRD: CREATE DOES> 1 + DOES> 2 + ; -> }
>{ WEIRD: W1 -> }
>{ ' W1 >BODY -> HERE }
>{ W1 -> HERE 1 + }
>{ W1 -> HERE 2 + }
>It is not clear to me what weird: is supposed to do. The two does is
>strange to me. Could SO explain that?

It's subtle.  When W1 is defined, the code it gets is:

( aa ) 1+ DOES> 2 + ;

This is the DOES> body code that W1 will execute.  Since no space was
allotted after the CREATE up to now, ' W1 >BODY should point to HERE .

The first time you execute W1 it takes its base address ( HERE) and
adds 1 to it.  That leaves HERE 1+ on the stack.  Then it does DOES>
and changes the definition of the last defined word, which this time
happens to be W1. So now the code that W1 gets is

( aa ) 2 + ;

So from now on if you do W1 it will give you the base address + 2,
( HERE 2 +)

It can't change itself again, and you can't make a new definition to
change it-- as soon as you make a new definition W1 won't be the latest
one and DOES> will never again work on it.  ( Unless you do FORGET or
MARKER to erase everything past it.)  But if you have an old definition
that does DOES> without CREATE then the old definition can redefine W1



Mon, 17 Jan 2000 03:00:00 GMT  
 ANS Tester


Quote:
ANDRE) writes:
>I am writing an implementation of ANS forth and after running
>tester.fr and core.fr I have some failure with does> behaviour. The
>test that fails is:
>{ : WEIRD: CREATE DOES> 1 + DOES> 2 + ; -> }
>{ WEIRD: W1 -> }
>{ ' W1 >BODY -> HERE }
>{ W1 -> HERE 1 + }
>{ W1 -> HERE 2 + }
>It is not clear to me what weird: is supposed to do. The two does is
>strange to me. Could SO explain that?

OK.  When W1 is defined, it hasn't had any space alloted yet so it
points to HERE .  The code that gets linked to it is basically

:NONAME 1 + DOES> 2 + ;

So the first time W1 gets executed, that code starts with HERE on the
stack and adds 1 to it.  Then it does DOES> and modifies the last
created command, which happens to be W1 .  So now the code that's
linked to W1 is basically

:NONAME 2 + ;

So the second time W1 gets executed, it starts with HERE and adds 2 to
it.  Now it's stable.  W1 can't change itself again, and you can't
define a new word that will change it -- as soon as you define a new
word then W1 is not the last one and DOES> doesn't work on it.  An old
previously-defined word that has DOES> but not CREATE could change W1
again, though, as long as nothing else has been defined on top of it.

It probably isn't very useful to go to a lot of trouble defining a word
that changes its own behavior the first time it's run.  But you can use
multiple DOES> to make defining words that define defining words.



Mon, 17 Jan 2000 03:00:00 GMT  
 ANS Tester

Quote:


> ANDRE) writes:

> >I am writing an implementation of ANS forth and after running
> >tester.fr and core.fr I have some failure with does> behaviour. The
> >test that fails is:

> >{ : WEIRD: CREATE DOES> 1 + DOES> 2 + ; -> }
> >{ WEIRD: W1 -> }
> >{ ' W1 >BODY -> HERE }
> >{ W1 -> HERE 1 + }
> >{ W1 -> HERE 2 + }

<snip> ( an excellent explaination on how the above code works )

Quote:
> It probably isn't very useful to go to a lot of trouble defining a word
> that changes its own behavior the first time it's run.  But you can use
> multiple DOES> to make defining words that define defining words.

Jonah, what I am very interested in is; if you could give an example of
multiple DOES> to define defining words.  How would you use such a word?


Tue, 18 Jan 2000 03:00:00 GMT  
 ANS Tester


Quote:
>> >I am writing an implementation of ANS forth and after running
>> >tester.fr and core.fr I have some failure with does> behaviour. The
>> >test that fails is:
>> >{ : WEIRD: CREATE DOES> 1 + DOES> 2 + ; -> }
>> >{ WEIRD: W1 -> }
>> >{ ' W1 >BODY -> HERE }
>> >{ W1 -> HERE 1 + }
>> >{ W1 -> HERE 2 + }
>I find the standard unclear on this.  It says append the execution
>semantics, and it also says replace the execution semantics.
>I have always assumed it meant replace.  In which case the first
>DOES> would modify the CREATEd word and replace its action with
>the specificed initialization and run time semantics 1 +
>I would assume that the second would also modify the created word
>and replace its action with the specified initialization and
>run time semantics 2 + ;
>On the other hand if instead of replacing the action of the
>created word it truely appended the action then I would assume
>that the runtime action action would be the initialization code
>that places the PFA on the stack followed by 1 + followed by
>the initialization again followed by 2 + ;
>I don't see why it would execute 1 + the first time and then
>2 + the second time.  What would make the compiled code exit
>the word after the 1 + and then restart at the second
>initialization?
>Is this the common interpretation for what the standard means?
>{ W1 -> HERE 1 + }  { W1 -> HERE 2 + }  

I'm not certain what about common interpretation, but here's the way I
understood it from John Rible (If I misunderstood it was entirely my
failure to understand, and not his failure to communicate.)

When you compile a definition that contains DOES> that definition ends
with the DOES> .  DOES> compiles code that will do something.  A new
unnamed definition then starts, and the run-time action of DOES> is to
*do something about* that new code.

When the definition containing DOES> runs, the action that DOES>
compiled is to replace the action of the latest definition, using the
code that came after the DOES> .

Then when the child runs, it does the code that came after DOES> .

The stack diagrams are consistent with this.

So if you have

: CHANGER  FOO DOES> BAR DOES> SNA ;

the first DOES> compiles something at the end of CHANGER and the 2nd
DOES> compiles at the end of the code after the first DOES>

: CHANGER
   FOO ( colon-sys1 ) DOES>
   BAR ( colon-sys2 ) DOES> SNA ( colon-sys3 ) ;

CREATE BOH CHANGER

This makes BOH do BAR and then the code that the 2nd DOES> compiled.

CREATE ICA BOH

This makes ICA do SNA .

I'm not absolutely certain that this was the intention, but it's
workable and since it fits the test suite I expect it was at least John
Hayes's intention.



Tue, 18 Jan 2000 03:00:00 GMT  
 ANS Tester


writes

Quote:
>>It is not clear to me what weird: is supposed to do. The two does is
>>strange to me. Could SO explain that?

>OK.  When W1 is defined, it hasn't had any space alloted yet so it
>points to HERE .

[explanation snipped]

Thanks Jet for explaining so clearly.  I didn't understand this bit of
tester.fr either, but didn't have the wit to ask.

Bye for now                                                      
                                           ____/  /  __  /   /   /   /   /
Chris Jakeman                             /      /  /  _/   /   /   /  /
                                         __/    /  / __    /   /   /_/
at Peterborough, a cathedral            /      /  /   /   /   /   /  \
city 80 miles north of London.       __/    __/  ____/    ___/ __/   _\  
Where do you come from?          
                              Forth Interest Group United Kingdom Chapter
Voice +44 (0)1733 753489      at http://www.forth.org/fig/uk/homepage.htm



Tue, 18 Jan 2000 03:00:00 GMT  
 ANS Tester


Quote:


>> It probably isn't very useful to go to a lot of trouble defining a
>> word that changes its own behavior the first time it's run.  But
>> you can use multiple DOES> to make defining words that define
>> defining words.
>Jonah, what I am very interested in is; if you could give an example
>of multiple DOES> to define defining words.  How would you use such a
>word?

OK, first off, remember that you never _have_ to use DOES> .  Anything
you can do with CREATE DOES> you can do some other way though often
more tediously.  Similarly, anything you can do with multiple DOES> you
can do without them, so it becomes a style thing.  You want to consider
the bother of writing and testing, and the concerns of maintenance.
That last may be why it isn't done more often.

What CREATE DOES> gives you is a way to link up multiple instances of a
data structure, with a single piece of code.  If you only want to do
that with a couple of instances, you can just do it.

CREATE MY-STRUCTURE 17 CELLS ALLOT
: MY-ARRAY CELLS MY-STRUCTURE + ;


MAKE-ARRAY MY-ARRAY

It's only when you have enough instances to matter that CREATE DOES>
gives you an advantage.

Similarly, then, if you use CREATE DOES> to build a defining word, the
value comes when you have a whole class of defining words that use the
same code but different data when they define words.

The method is sometimes used in assemblers.

{
( 1st pass )
\ commands do A0 [BX] etc to get a 4-bit pattern to add to a
\  command-specific bit-pattern.)
( add to bits 0-3 )

A0 COMMAND CAT,
B0 COMMAND BOG,
\ etc.

( add to bits 3-6 )

A0 COMMAND2 RAT,
B0 COMMAND2 BUG,
\ etc.

( add to bits 8-11 )

\ This is workable, but we have a lot of little snippets of code that
\ differ only by a constant.

\ -------------------
( 2nd pass )

0 A0 COMMAND CAT,
0 B0 COMMAND BOG,
3 A0 COMMAND RAT,
3 B0 COMMAND BUG,
8 A0 COMMAND FOO,
etc.

\ This is workable, but now we have a lot of data to keep track of.

\ -------------------
( 3rd pass )

: MAKE-COMMAND

0 MAKE-COMMAND COMMAND1
3 MAKE-COMMAND COMMAND2
8 MAKE-COMMAND COMMAND3

A0 COMMAND1 CAT,
B0 COMMAND1 BOG,

A0 COMMAND2 RAT,
B0 COMMAND2 BUG,
etc.

\ This is workable, but now we've hidden what we're doing so that
\ somebody who tries to read the code will actually have to think.

Quote:
}

So that's it.  When you notice yourself making multiple compiling words
that are all similar, or making complex compiling words that fit a
pattern, you could use a compiling word to build them instead.  It can
make your code simpler, but first you have to notice the good pattern.


Tue, 18 Jan 2000 03:00:00 GMT  
 ANS Tester

Quote:
> >I am writing an implementation of ANS forth and after running
> >tester.fr and core.fr I have some failure with does> behaviour. The
> >test that fails is:

> >{ : WEIRD: CREATE DOES> 1 + DOES> 2 + ; -> }
> >{ WEIRD: W1 -> }
> >{ ' W1 >BODY -> HERE }
> >{ W1 -> HERE 1 + }
> >{ W1 -> HERE 2 + }

I find the standard unclear on this.  It says append the execution
semantics, and it also says replace the execution semantics.
I have always assumed it meant replace.  In which case the first
DOES> would modify the CREATEd word and replace its action with
the specificed initialization and run time semantics 1 +

I would assume that the second would also modify the created word
and replace its action with the specified initialization and
run time semantics 2 + ;

On the other hand if instead of replacing the action of the
created word it truely appended the action then I would assume
that the runtime action action would be the initialization code
that places the PFA on the stack followed by 1 + followed by
the initialization again followed by 2 + ;

I don't see why it would execute 1 + the first time and then
2 + the second time.  What would make the compiled code exit
the word after the 1 + and then restart at the second
initialization?

Is this the common interpretation for what the standard means?
{ W1 -> HERE 1 + }  { W1 -> HERE 2 + }  

--
Jeff Fox

http://www.dnai.com/~jfox/



Tue, 18 Jan 2000 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. SMALLTALK APP TESTER $$$$ SMALLTALK APP. TESTER

2. ANS Forth in ANS Forth?

3. Seeking beta testers for Smalltalk ODBMS

4. VisualWorks Testers Needed!

5. Looking for VW/SmallTalk UI Regression Tester

6. Looking for testers of the Newsgroup server

7. SUnit Users: Looking for SUnit Browser Pre-release Testers

8. Space-switch Program Call (PC) Beta Testers

9. BETA TESTERS WANTED to test new Java Applet

10. Beta Testers wanted for Smalltalk Assessment

11. Be a Beta Tester!

12. QA TESTERS NEEDED- RTP AREA

 

 
Powered by phpBB® Forum Software