Re: Novice - Yeah, see my SEE SEE
- From: MarkWills <markrobertwills@xxxxxxxxxxx>
- Date: Fri, 5 Mar 2010 11:21:45 -0800 (PST)
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.
.
- Follow-Ups:
- Re: Novice - Yeah, see my SEE SEE
- From: Fanzo
- Re: Novice - Yeah, see my SEE SEE
- From: Coos Haak
- Re: Novice - Yeah, see my SEE SEE
- References:
- Novice - Yeah, see my SEE SEE
- From: Fanzo
- Re: Novice - Yeah, see my SEE SEE
- From: MarkWills
- Re: Novice - Yeah, see my SEE SEE
- From: Rod Pemberton
- Re: Novice - Yeah, see my SEE SEE
- From: Josh Grams
- Re: Novice - Yeah, see my SEE SEE
- From: Rod Pemberton
- Re: Novice - Yeah, see my SEE SEE
- From: Bruce McFarling
- Re: Novice - Yeah, see my SEE SEE
- From: Rod Pemberton
- Re: Novice - Yeah, see my SEE SEE
- From: Bruce McFarling
- Novice - Yeah, see my SEE SEE
- Prev by Date: Re: Allocating Structures on Return Stack
- Next by Date: Re: Novice - Yeah, see my SEE SEE
- Previous by thread: Re: Novice - Yeah, see my SEE SEE
- Next by thread: Re: Novice - Yeah, see my SEE SEE
- Index(es):
Relevant Pages
|