[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trying to extend gforth's outer interpreter
From: |
Tristan Williams |
Subject: |
Re: Trying to extend gforth's outer interpreter |
Date: |
Mon, 22 Aug 2022 20:52:28 +0100 |
On 01Apr22 13:18, Anton Ertl wrote:
> On Fri, Apr 01, 2022 at 09:51:09AM +0100, Tristan Williams wrote:
> > Hello,
> >
> > I am trying to extend gforth's outer interpreter so that how numbers
> > are treated is dependent on which mode (indicated by the value of
> > mode?) my program is in. In the code below, if mode? is true the
> > number is just dropped, otherwise it should be treated as usual and
> > placed on the host data stack. This seems to work if I type
> > definitions in interactively at the terminal, but if I include them at
> > the end of the source file or interactively using include "filename"
> > it does not. What am I doing wrong?
>
> You hook into 'quit, which is only used for text-interpretation of
> terminal input.
>
> If you use a recent development version of Gforth, the way to go is to
> define a new number recognizer, and replace the default number
> recognizer REC-NUM with the new one (or just insert the new one in
> front of REC-NUM in the recognizer stack). The documentation is not
> finished yet, but look at the source of REC-NUM, and use
> GET-RECOGNIZERS and SET-RECOGNIZERS to change the recognizer stack.
>
> If you use Gforth-0.7, things are more complex: You need to replace
> INTERPRETER1 and COMPILER1. These are not hooks, so you need to patch
> the existing colon definitions. To do that, use:
>
> : >colon-body ( xt -- addr )
> dup @ docol: <> -12 and throw >body ;
>
> : >prim-code ( xt -- x )
> \ converts xt of a primitive into a form usable in the code of
> \ colon definitions on the current engine
> threading-method 0= IF @ THEN ;
>
> : replace-word ( xt1 xt2 -- ) \ gforth
> \G make xt2 do xt1, both need to be colon definitions
> swap >colon-body ['] branch >prim-code rot >colon-body 2! ;
>
> - anton
>
Hello Anton,
A small update. I was able to use custom recognizers in Gforth to help
extend my structured Forth cross-assembler for a PIC16F183X3 to a
Forth cross-compiler. They make switching between its two modes
of operation (assembler or Forth) much more manageable. Thank you.
Tristan
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Trying to extend gforth's outer interpreter,
Tristan Williams <=