[retroforth] Re: 7.5 Development

  • From: Stefan Schmiedl <s@xxxxxx>
  • To: retroforth@xxxxxxxxxxxxx
  • Date: Thu, 21 Oct 2004 18:20:37 +0200

Charles Childers (2004-10-21 10:01):

> 
> >>* Should the interpreter stop executing when it encounters an unknown 
> >>word, or report the error and continue?
> >>    
> >>
> >
> >How about a variable controlling this behaviour?
> >  
> >
> That is doable, but it would complicate the interpret routine quite a bit.

?

        interpret:
        .o:     call query    ; ( Get a WORD )
        .word:  upsh 32       ; ( Push a <SPACE> onto the stack )
                call parse    ; ( Parse until we find <SPACE> )
                jnz .find     ; ( Look for the end of the line )
                drop          ; ( DROP two numbers )
                drop          ;
                jmp .o        ; ( Loop back to start if no words found
        )
        .find:  call find     ; ( See if we can find the word )
                jnc .exec     ; ( Yes? Interpret it )
                call number   ; ( No? Then make it a number )
                jnc .word     ; ( Loop back )

Here we know that it's neither known nor a number.
So let's do a
                call barf
where barf does something like
   : unknown  barf? @ 0;  ." Help!" ;

                drop          ; ( Drop two numbers )
                drop          ;
                jmp .o        ; ( And Loop back )
        .exec:  upop edi      ; ( This is where we actually call the )
                call edi      ; ( words we find )
                jmp .word     ; ( And Loop back )
        next

> 
> >do we have defer? would be another way to solve to the first
> >problem.
> >  
> >
> Here are definitions for defer:
> 
> : is here >r h0 ! 32 parse find compile r> h0 ! ;
> : defer create here 5 - h0 ! $90909090 , $90 1, $c3 1, ;
> 
> They aren't in the core though (I don't see a need for revectored words 
> in the core, especially since they're quite easy to add).

They might be easy to add, but not for me ... I don't get how
they work ... lack of assembly knowledge, probably.

> How would they 
> help solve the problem with interpret?

It's even better if you have a deferred word in there,
because then the action taken can be adjusted by the user,
nothing is hardcoded. I agree that it's a violation of
early binding, but a convenient one :-)

SwiftForth has something like this, which allows you
to define a sensible "default action" for this case.

If you're counting words, you could use

: counter  $create 1 , does> dup @ 1+ swap ! ;
' counter is barf

after factoring $create out of create, of course.

Default behaviour would need to be 2drop.

> 
> --
> Charles
> 

-- 
Stefan Schmiedl
+-------------------------------+----------------------------------------+
|Approximity GmbH               | EDV-Beratung Schmiedl                  |
|http://www.approximity.com     | Am Bräuweiher 4, 93499 Zandt, Germany  |
|mailto:stefan@xxxxxxxxxxxxxxx  | Tel. (09944) 3068-98, Fax -97          |
+-------------------------------+----------------------------------------+

Other related posts: