Re: Novice - Yeah, see my SEE SEE



On Mar 5, 6:54 pm, Bruce McFarling <agil...@xxxxxxxxxxxx> wrote:
On Mar 5, 3:20 am, "Rod Pemberton" <do_not_h...@xxxxxxxxxxxx> wrote:

When you have a "FORTH in FORTH" which is built up from small set of
primitives (or low-level words), how do you redefine the primitive in terms
of other existing FORTH words?

Why do you want to?


Indeed. In my hobby Forth, I have done pretty much everything in
assembler, for two reasons:

1) The words execute faster
2) I'm better at assembler than Forth ;-)

The *exception* is immediate words. I coded most of those, if not all,
in forth. These are things like IF..THEN BEGIN WHILE REPEAT etc... Ok,
they run a little slower, but the hit is at compile time, not
execution time.

Not sure if it's worth pointing out or not, but there are two ways of
writing Forth in Forth (maybe more)

1) Have the Forth code stored as regular ASCII in a big data block
that is compiled (as if it was entered at the keyboard) at startup

2) Write your 'forth' code in terms of the symbolic addresses of your
Forth words at the source code level.

Here's my IF..THEN :


; IF statement, executes the code between IF and THEN if the flag is
true (>0)
ifh data exitfh,>8002 ; note immediate flag
text 'IF'
if data docol,compile,zbrnch,here_,fetch,lit,0,comma,exit
;]

; THEN ( addr -- )
; marks the end of an IF block
thenh data ifh,>8004 ; note immediate flag
text 'THEN'
then data docol,dup,here_,fetch,swap,sub,swap,store,exit

Here, you see the header structure:
First entry: Pointer to previous word in the dictionary
Second entry: Length of the word ( > means 'hex' in 9900 parlance, and
the MSB is set ti indicate an immediate word)
Third entry: The text representation of the word
Fourth entry: the code of the word itself, written as references to
the executable sections of the other words. So, looking at THEN:

then data docol,dup,here_,fetch,swap,sub,swap,store,exit

In 'real' Forth, it would be

: THEN DUP HERE @ SWAP - SWAP ! ;

Basically, I'm writing pre-compiled Forth, in terms of their symbolic
addresses. Works nicely in an assembler environment, I'm not sure it's
that simple in a C environment...

Mark.
.



Relevant Pages

  • Re: Novice - Yeah, see my SEE SEE
    ... primitives, how do you redefine the primitive in terms ... The words execute faster ... I'm better at assembler than Forth;-) ... First entry: Pointer to previous word in the dictionary ...
    (comp.lang.forth)
  • Re: Novice - Yeah, see my SEE SEE
    ... primitives, how do you redefine the primitive in terms ... The words execute faster ... I'm better at assembler than Forth;-) ... _ ADDR PREV; ...
    (comp.lang.forth)
  • Re: yet another Forth: vmForth
    ... and MidLevel and HLL all Integrated in the Kernel. ... VM assembler and simulator from within the simulator for testing :-) ... higher level Forth constructs, like jz/jnz, lit, execute, call and jump. ... Compiles VM assembler mnemonics into the VM memory. ...
    (comp.lang.forth)
  • Re: URGENT
    ... But I've got a pretty good imagination, and may be able to "see" how they'd look in a debugger without actually doing it. ... But as best as I can imagine how the'd work in RosAsm, ... Run the Assembler and this file to read its Source. ... hit (compile & execute in Debugger mode) and then ...
    (alt.lang.asm)
  • yet another Forth: vmForth
    ... higher level Forth constructs, like jz/jnz, lit, execute, call and jump. ... Compiles VM assembler mnemonics into the VM memory. ... (xt is address of type flag) ...
    (comp.lang.forth)