Help writing compiler 
Author Message
 Help writing compiler

Okay, as a little fun project for myself (thanks to Elizabeth for her book I
am feeling really good about my forth skills) I've decided to write a Forth
compiler for the 6502 processor (for Atari 2600 games).

Basically, my "stump" that I am having trouble getting over is the use of
the words CODE ASSEMBLER END-CODE and NEXT.

My basic concept of the compiler is that it only uses these words, CREATE
DOES> and a couple others, combined with the instruction set of the
processor to make the language. And to make all the core words, I just use
CODE and the opcode words.

Is this right? If it is, I am having trouble understanding how to go about
doing this "properly". I can easily create my own form, but I want to stay
strict to ANS FORTH. I think a simple example is all I need, so I will write
out a simple problem and see what advice comes from it :)

For those that don't know, the 6502 is a early, simple version of the 68000.

Example: Using the CODE <opcodes> END-CODE to write a routine for the word +

CODE + ( n n -- n )
  \ Pull stack value into accumulator
  PLA

  \ Transfer stack pointer into X
  TSX

  \ Add memory (zero-page, X) to accumulator
  0 X ADC x

  \ Store accumulator (zero-page indexed X)
  0 X STA

  \ Return from subroutine
  RTS
END-CODE

Is this [concept] right? Also, I know there are words S) ) # etc. that are
supposed to describe the opcode type (immediate, absolute, etc.) Do I make
all these words myself for this particular processor? Or are there ANS FORTH
words for these?

Any help is appreciated. Thanks!

Jeff



Tue, 09 Sep 2003 05:05:20 GMT  
 Help writing compiler

Quote:
>Okay, as a little fun project for myself (thanks to Elizabeth for her book I
>am feeling really good about my forth skills) I've decided to write a Forth
>compiler for the 6502 processor (for Atari 2600 games).

>Basically, my "stump" that I am having trouble getting over is the use of
>the words CODE ASSEMBLER END-CODE and NEXT.

>My basic concept of the compiler is that it only uses these words, CREATE
>DOES> and a couple others, combined with the instruction set of the
>processor to make the language. And to make all the core words, I just use
>CODE and the opcode words.

>Is this right? If it is, I am having trouble understanding how to go about
>doing this "properly". I can easily create my own form, but I want to stay
>strict to ANS FORTH. I think a simple example is all I need, so I will write
>out a simple problem and see what advice comes from it :)

There are several different threading schemes extant. The anatomy of a
word depends on how the inner interpreter, if it exists, handles words.

What 6502 Forths have you looked at? One favorite was "Blazin' Forth".

Also of note, from my H3sm sources...

I had a copy of J. Brien's "Build Your Own Forth" webpage in my
/usr/src/H3m . (original URL is
"http://www.users.zetnet.co.uk/aborigine/byof.htm")

ALSO, look at eforth, and if you have a few bucks hit Offete Enterprises
books list.

Rick Hohensee
www.clienux.com



Tue, 09 Sep 2003 09:37:01 GMT  
 Help writing compiler

Quote:

> Okay, as a little fun project for myself (thanks to Elizabeth for her
> book I am feeling really good about my forth skills) I've decided to
> write a Forth compiler for the 6502 processor (for Atari 2600 games).
> Basically, my "stump" that I am having trouble getting over is the
> use of the words CODE ASSEMBLER END-CODE and NEXT.

ASSEMBLER is for scoping.  Say you want to write an assembler, and the
commands for the assembler are written in Forth.  Maybe you want a
command named # .  But there's already a Forth command named # which
does something else.  If your assembler commands go into the ASSEMBLER
wordlist then the system will know which one you want -- when you do
CODE ir will look for assembler commands and not otherwise, unless you
tell it otherwise.  People don't always use it.  Pygmy Forth dumps all
the assembler words into the regular wordlist, and I used to have
occasional trouble with BL .  BL is a constant that gives you the
literal for the blank character, but in that '86 assembler it is a
constant that represents the low byte of the BX register.  Decimal 24
instead of 32.  I'd forget the assembler was loaded and write a
perfectly normal forth word and it would fail, BL WORD etc would use up
the whole line.

CODE tells the Forth system to start building a new Forth definition
that's written in assembler.  It will need a regular Forth header and it
will need to save whatever registers etc the Forth needs, and then jump
to or call your code.  Also it will get ready to use your assembler.
Needless to say, the details of how to do all this vary a lot depending
on your Forth system and your assembler.  If you want to wind up with a
program that's all assembler then in the end you won't need the Forth
headers, but while you're  testing your code why not enjoy the
advantages of calling it from Forth?

This assumes your assembler is written for the same machine your Forth
is running on.  If not, you could assemble your program, save it to a
file, download it to your test system, run it there, and see whether you
notice any bugs.  A slow process.  You might get things working quicker
if you have an emulator for your chip written in Forth so you can test
things on the spot.  But it's always possible the emulator has some
bugs.  One alternative is to get Forth running on your chip.  If you can
get a serial line running then you can add code definitions in to the
other chip's Forth and test them easily on the real thing.  But of
course if what you're trying to do is build a Forth compiler then you
have to be mostly done before this works very well....  The fewer code
words you *have* to have working before your Forth runs, the easier it
is to get it running.  You can replace Forth definitions with code
definitions later when it all works.  I don't know what the minimum
number of code definitions is.  eForth used to do it with 31 things
written in assembler plus a few ystem calls for EMIT KEY etc.  I've
heard claims of 15, 11, 9 etc for the minimum number, but for the lowest
number you might find yourself doing + by incrementing repeatedly.  

Or you could get just enough code running on your test sustem to handle
a serial line, plus a few defined commands.  Those commands could
download code, download data to a stack, execute code, upload the chip's
data stack to the serial line, etc.  Then you could have your assembler
donload each code definition to the test system and keep track of where
it is in memory.  You could execute code definitions on the chip and get
the results from the serial line back at your Forth on a different
system.  You could start out with a program that ran in Forth on your
system, and move it a step at a time to code on the other chip.  

So as you can see there isn't a whole lot of standardisation about it
all.

END-CODE typically says to stop using the assembler commands.  Note that
it isn't included in the standard.  Your assembly code will end with a
jump or return or something, you can't depend on END-CODE to know how
you want to end things.  

NEXT or NEXT, or NXT, etc puts in all the code it takes to return to
Forth.  It might restore registers or stacks etc.  Sometimes it also
does everything that END-CODE does so you won't need END-CODE when you
do NEXT .  If your assembler lets you jump to a label instead of
returning to Forth then you don't want to do NEXT every time, but
sometimes you'll want it.  Again, no standardisation.

Quote:
> My basic concept of the compiler is that it only uses these words,
> CREATE DOES> and a couple others, combined with the instruction set
> of the processor to make the language. And to make all the core
> words, I just use CODE and the opcode words.
> Is this right? If it is, I am having trouble understanding how to go
> about doing this "properly". I can easily create my own form, but I
> want to stay strict to ANS FORTH. I think a simple example is all I
> need, so I will write out a simple problem and see what advice comes
> from it :)

There's no standard ANS way to write an assembler, and there's no
standard ANS way to write a Forth compiler.  

Quote:
> Example: Using the CODE <opcodes> END-CODE to write a routine for the
> word +
> CODE + ( n n -- n )
>   \ Pull stack value into accumulator
>   PLA
>   \ Transfer stack pointer into X
>   TSX
>   \ Add memory (zero-page, X) to accumulator
>   0 X ADC x
>   \ Store accumulator (zero-page indexed X)
>   0 X STA
>   \ Return from subroutine
>   RTS
> END-CODE
> Is this [concept] right? Also, I know there are words S) ) # etc.
> that are supposed to describe the opcode type (immediate, absolute,
> etc.) Do I make all these words myself for this particular processor?
> Or are there ANS FORTH words for these?

No ANS Forth words.  Look at what your assembler does and use whatever
it gives you, however you need.  If it doesn't give you everything you
need, improve it.


Tue, 09 Sep 2003 10:24:03 GMT  
 Help writing compiler
On Thu, 22 Mar 2001 14:05:20 -0700, "Jeff Massung"

Quote:

>Okay, as a little fun project for myself (thanks to Elizabeth for her book I
>am feeling really good about my forth skills) I've decided to write a Forth
>compiler for the 6502 processor (for Atari 2600 games).

You should try to get a figforth source listing for 6502 processors.
I don't have a URL but perhaps someone else could help.
Otherwise you'll probably never be programming games but debugging
your compiler, but that can be fun too, depending on the taste
and available time to kill.
Andreas


Tue, 09 Sep 2003 16:07:43 GMT  
 Help writing compiler

Quote:

> Okay, as a little fun project for myself (thanks to Elizabeth for her book I
> am feeling really good about my forth skills) I've decided to write a Forth
> compiler for the 6502 processor (for Atari 2600 games).

> Basically, my "stump" that I am having trouble getting over is the use of
> the words CODE ASSEMBLER END-CODE and NEXT.

> My basic concept of the compiler is that it only uses these words, CREATE
> DOES> and a couple others, combined with the instruction set of the
> processor to make the language. And to make all the core words, I just use
> CODE and the opcode words.

> Is this right? If it is, I am having trouble understanding how to go about
> doing this "properly". I can easily create my own form, but I want to stay
> strict to ANS FORTH. I think a simple example is all I need, so I will write
> out a simple problem and see what advice comes from it :)

I implemented a subroutine threaded Forth for the 6502 a couple of years
ago.
The first thing you have to do is think about which threading model you
want
to use, then how you want to allocate registers.

Then you can start implementing it.

I used plain assembler for it, didn't use Forth.
Once you get the hang of it, it's much fun.

To get a feel for it, start with simple words like +
then get into the Forth oriented words (more or less in this order)
EXECUTE , ALLOT FIND COMPILE QUIT CREATE DOES>

Once you've implemented these, you should be able to see how to do the
other
words.



Tue, 09 Sep 2003 20:00:31 GMT  
 Help writing compiler
Jeff,

The assembly listing of even a Z-80 Forth kernel will give you a pretty
good idea of how to go about setting one up on another 8 bitter. I know
that there are some around; somewhere, I have a yellowed and brittle
fan-fold printout.

I also have a SYM-1 with a Forth tape for it, an AIM-65 with Forth in
ROM, and a couple of 65F11s around, including one with Horne Forth on
floppy. I'd be willing to arrange a loan of any of these. They're just
taking up room.

Jerry
--
Engineering is the art of making what you want from things you can get.
-----------------------------------------------------------------------

Quote:


> > Okay, as a little fun project for myself (thanks to Elizabeth for her book I
> > am feeling really good about my forth skills) I've decided to write a Forth
> > compiler for the 6502 processor (for Atari 2600 games).

> > Basically, my "stump" that I am having trouble getting over is the use of
> > the words CODE ASSEMBLER END-CODE and NEXT.

> > My basic concept of the compiler is that it only uses these words, CREATE
> > DOES> and a couple others, combined with the instruction set of the
> > processor to make the language. And to make all the core words, I just use
> > CODE and the opcode words.

> > Is this right? If it is, I am having trouble understanding how to go about
> > doing this "properly". I can easily create my own form, but I want to stay
> > strict to ANS FORTH. I think a simple example is all I need, so I will write
> > out a simple problem and see what advice comes from it :)

> I implemented a subroutine threaded Forth for the 6502 a couple of years
> ago.
> The first thing you have to do is think about which threading model you
> want
> to use, then how you want to allocate registers.

> Then you can start implementing it.

> I used plain assembler for it, didn't use Forth.
> Once you get the hang of it, it's much fun.

> To get a feel for it, start with simple words like +
> then get into the Forth oriented words (more or less in this order)
> EXECUTE , ALLOT FIND COMPILE QUIT CREATE DOES>

> Once you've implemented these, you should be able to see how to do the
> other
> words.



Wed, 10 Sep 2003 00:43:31 GMT  
 Help writing compiler

Quote:

>The assembly listing of even a Z-80 Forth kernel will give you a pretty
>good idea of how to go about setting one up on another 8 bitter. I know
>that there are some around; somewhere, I have a yellowed and brittle
>fan-fold printout.

I agree. I chose the 6502 just because I know the instruction set well, and
there are a plethora of Atari 2600 emulators out there to test my compiler
with.

I looked at the Z-80, because in the end I thought it would be really nice
to write Gameboy games in Forth (the GB runs off a modified Z80). If you
could scan that brittle printout and post it somewhere, I'd be forever
grateful.

Quote:
>I also have a SYM-1 with a Forth tape for it, an AIM-65 with Forth in
>ROM, and a couple of 65F11s around, including one with Horne Forth on
>floppy. I'd be willing to arrange a loan of any of these. They're just
>taking up room.

Please feel free to post them somewhere -- I'd love to have a look and learn
:).

Also, to everyone else, I appreciate the help so far. I'd like to reiterate
a little of what I have learned and make sure I understand it correctly:

* There are TWO (maybe more?) dictionaries in a FORTH compiler: the FORTH
dictionary and the ASSEMBLER dictionary.

* Typically, the FORTH dictionary is used first... ie if the word entered
exists in it, that is what is run, otherwise a search in the ASSEMBLER
dictionary is done.

* Using the words CODE and ASSEMBLER toggles that so that the ASSEMBLER
dictionary is used first. END-CODE and NEXT just put it back the way it was.

* There are no "predefined" words in a FORTH compiler implementation. So if
I write a compiler for the 6502, I could create my own words for the
ASSEMBLER dictionary and use them as I see fit.

I just have one more (hopefully) simple question:

I don't fully understand NEXT. I know I don't only because everything I read
tells me to make it inline because it is called so many times, however, in
my experience with Forth, I have never used it. Is it build in to just about
every word somehow?



Wed, 10 Sep 2003 02:43:14 GMT  
 Help writing compiler
I also had one other question I forgot. It was the word COMPILE,. With this
word, if I had the following:

CODE -
  PLA TSX 0 ,X DBC 0 ,Y STA
END-CODE

And now I want to make the word < but I don't want to JUMP to the word - do
I use COMPILE, to make it inline (ie it will just insert the - instructions
in the < subroutine)?

CODE <
  ' - COMPILE, \ More stuff here
END-CODE

Jeff



Wed, 10 Sep 2003 02:49:35 GMT  
 Help writing compiler

Quote:


>>The assembly listing of even a Z-80 Forth kernel will give you a pretty
>>good idea of how to go about setting one up on another 8 bitter. I know
>>that there are some around; somewhere, I have a yellowed and brittle
>>fan-fold printout.

>I agree. I chose the 6502 just because I know the instruction set well, and
>there are a plethora of Atari 2600 emulators out there to test my compiler
>with.

>I looked at the Z-80, because in the end I thought it would be really nice
>to write Gameboy games in Forth (the GB runs off a modified Z80). If you
>could scan that brittle printout and post it somewhere, I'd be forever
>grateful.

>>I also have a SYM-1 with a Forth tape for it, an AIM-65 with Forth in
>>ROM, and a couple of 65F11s around, including one with Horne Forth on
>>floppy. I'd be willing to arrange a loan of any of these. They're just
>>taking up room.

>Please feel free to post them somewhere -- I'd love to have a look and learn
>:).

>Also, to everyone else, I appreciate the help so far. I'd like to reiterate
>a little of what I have learned and make sure I understand it correctly:

>* There are TWO (maybe more?) dictionaries in a FORTH compiler: the FORTH
>dictionary and the ASSEMBLER dictionary.

>* Typically, the FORTH dictionary is used first... ie if the word entered
>exists in it, that is what is run, otherwise a search in the ASSEMBLER
>dictionary is done.

>* Using the words CODE and ASSEMBLER toggles that so that the ASSEMBLER
>dictionary is used first. END-CODE and NEXT just put it back the way it was.

>* There are no "predefined" words in a FORTH compiler implementation. So if
>I write a compiler for the 6502, I could create my own words for the
>ASSEMBLER dictionary and use them as I see fit.

>I just have one more (hopefully) simple question:

>I don't fully understand NEXT. I know I don't only because everything I read
>tells me to make it inline because it is called so many times, however, in
>my experience with Forth, I have never used it. Is it build in to just about
>every word somehow?

On a real CPU the program counter is incremented or otherwise bumped to
point at the next instruction implicitly. On x86 in fact the only way I
know of to get ahold of the current IP is with a call and a pop. In a virtual
machine you have to bump IP by hand. Threading schemes vary. My VMST method is
fugly, and it's 5 386 instructions when C is done with it.

Then there's W. The Working Variable. Most schemes need to keep track of where
they've been with that. Again, see J. Brien's page.

In subroutine threading your NEXT is an RTS/RET, because every xt is
preceded by a CALL opcode. That's a moderate size hit and usually a big
speed win. On a tiny machine you take the speed hit, which is what classico
Forths did. There are other trade-offs. I suspect STC inlines trivially, for
example.

I wrote a Forth-like, not a Forth, so I can't respond to your
COMPILE question :o)

Rick Hohensee
www.clienux.com



Wed, 10 Sep 2003 07:11:36 GMT  
 Help writing compiler

Quote:

> * There are TWO (maybe more?) dictionaries in a FORTH compiler: the
> FORTH dictionary and the ASSEMBLER dictionary.

Yes.  You don't have to have an assembler vocabulary unless you want
one.  You could have an EDITOR vocabulary etc if you want them.  You can
put the assembler words in the regular Forth vocabulary if you want, but
you're likely to get some name conflicts.

Quote:
> * Typically, the FORTH dictionary is used first... ie if the word
> entered exists in it, that is what is run, otherwise a search in the
> ASSEMBLER dictionary is done.

Or you could search one and not the other.  If you aren't in the middle
of building a CODE definition you probably aren't going to want
assembler words; they'll be mistakes.  If you want to use some Forth
words to manipulate addresses or labels or whatever during a CODE
definition you might want to switch vocabularies completely instead of
use the Forth words that happen not to have the same names as assembler
words.  Or do it the way you said, lots of ways will mostly work.

Quote:
> * Using the words CODE and ASSEMBLER toggles that so that the
> ASSEMBLER dictionary is used first. END-CODE and NEXT just put it
> back the way it was.

NEXT might do more than that.

Quote:
> * There are no "predefined" words in a FORTH compiler implementation.
> So if I write a compiler for the 6502, I could create my own words
> for the ASSEMBLER dictionary and use them as I see fit.

Yes!

Quote:
> I don't fully understand NEXT. I know I don't only because everything
> I read tells me to make it inline because it is called so many times,
> however, in my experience with Forth, I have never used it. Is it
> build in to just about every word somehow?

Forth has a data stack.  You might want to use a register for the stack
pointer, if you can spare one.  Forth often runs faster when the
top-of-stack is kept in a register -- if you can spare a register for
that.  Forth also has a return stack pointer, likely another register.
And an instruction pointer that remembers for you how far you've gotten
in the current definition, and depending on how you arrange things that
might not be the program counter that's already reseerved, it might need
yet another register.

When you do assembly routines you may not have enough good registers
left to do everything you want.  So at the start of your assembly code
you'll probably want to save the value in the registers that you'll want
to re-use.  And when you finish your CODE routine you'll want to restore
them all so the Forth can work right.  Plus there might be something
else; if your IP isn't the built-in program counter then you'll want
your own special return that puts the incremented return stack value
into IP.  That's what NEXT does.

But you might set up your assembler so a given CODE word just jumps to
another assembler routine, and in that case you won't want to restore
things; it isn't time.  So END-CODE doesn't do that.

Anyway, you can set it up however you want, you don't have to follow any
traditions.



Wed, 10 Sep 2003 08:21:58 GMT  
 Help writing compiler


Quote:

> There are several different threading schemes extant. The anatomy of a
> word depends on how the inner interpreter, if it exists, handles words.

...

> Also of note, from my H3sm sources...

> I had a copy of J. Brien's "Build Your Own Forth" webpage in my
> /usr/src/H3m . (original URL is
> "http://www.users.zetnet.co.uk/aborigine/byof.htm")

It's been a long time since I did any work on that, and the old website is
now defunct, but it is available at www.forth.org.uk/byof.htm . It gives, I
hope, a good idea of the various ways an ANs kernel can be implemented, but
doesn't really deal with the outer interpreter/compiler.  That's quite
tricky if you're bringing up Forth on a new chip.  There's no ANS standard
way to do this - you can write it in assembler, or Forth, or whatever you
like - just as long as the result can produce Standard code.

If you already have a working Forth system, there are a couple of exercises
that will ease you into it gradually:

1:  Write a parasitic outer interpreter/compiler which uses an entirely
separate dictionary mechanism to compile/execute existing xts.

2:  Write a new inner interpreter for the same chip, using a different
threading mechanism.  This enables you to build a seperate system in its own
codespace, while still testing each word interactively. I did this for a
direct-threaded Z80, built using F83 (Forthwrite 92, August 1997).

The trick is to devise a host word TEXECUTE that will execute a target xt
and return.

And from thence, having defined the runtime words (EXIT) (LIT) DOCOLON
DOCREATE DOCONSTANT and DODOES> as target code

: TDEF     \ ++ define a host word with a target body
   tlabel    \ store the target code address


  tcompile,    \  compile xt in target space
  ELSE texecute THEN ;

Now you can write defining words in terms of TDEF. For example:

T:  tdef
              \ tcompile target docolon (indirect threading)
             \ call or jump docolon (direct threading)
             \ or nothing (subroutine threading)
     tstate on ;
: T;  tstate off (EXIT) ;

These are host words, compiling target code. As far as the target is
concerned though, they are all immediate words which execute or compile
themselves according to TSTATE.  Thus, a host word can never be accidently
compiled in a target definition, or vice versa.  For now IMMEDIATE target
words are host words that compile runtime code.

For example:  : LIT  (LIT) t,  ;

Since we are still using the host outer interpreter, this must follow any
number in the T:  ... T; definition to compile it as a target literal.

These T-words are used to build and test the target system until you have
enough to build an outer interpreter in target space, which is exactly the
problem you solved in stage one.

--
Jenny  Brien
http://www.forth.org.uk
Home of the Fig UK website



Wed, 10 Sep 2003 06:36:35 GMT  
 Help writing compiler

Quote:

>  ...

> Also, to everyone else, I appreciate the help so far. I'd like to reiterate
> a little of what I have learned and make sure I understand it correctly:

> * There are TWO (maybe more?) dictionaries in a FORTH compiler: the FORTH
> dictionary and the ASSEMBLER dictionary.

There can be as many as you would reasonably want. Look up the words
VOCABULARY CURRENT CONTEXT ONLY and others you find along the way.

Quote:

> * Typically, the FORTH dictionary is used first... ie if the word entered
> exists in it, that is what is run, otherwise a search in the ASSEMBLER
> dictionary is done.

The search order can be varied. See the above words. The actual
vocabularies can be mingled in a single wordlist. Each vocabulary is a
linkd list, and the listscan be intertwined.

Quote:

> * Using the words CODE and ASSEMBLER toggles that so that the ASSEMBLER
> dictionary is used first. END-CODE and NEXT just put it back the way it was.

END-CODE does that and other jobs (link fixups, maybe more). NEXT (or
jmp NEXT) is just an instruction.

Quote:

> * There are no "predefined" words in a FORTH compiler implementation. So if
> I write a compiler for the 6502, I could create my own words for the
> ASSEMBLER dictionary and use them as I see fit.

> I just have one more (hopefully) simple question:

> I don't fully understand NEXT. I know I don't only because everything I read
> tells me to make it inline because it is called so many times, however, in
> my experience with Forth, I have never used it. Is it build in to just about
> every word somehow?

There is an inner interpreter that executes each component word of a
definition in turn. NEXT is a component's way to tell the system that it
is finished and that the next component should be called. If that next
component is ' ; ', the inner interpreter gets the next word. (It works.
Trust!) One can't be more specific without deciding on an actual
threading scheme. There are several to choose from, and the "best"
depends on the processor architecture and maybe also on a trade-off
between speed and simplicity. (Another way to look at NEXT is that with
subroutine threading, it reduces to RTS, RET, or whatever op code pops
the calling address off the return stack and goes there.)

It is easier to take one apart than to design one from scratch, but you
can cobble something together and figure out what is missing when it
doesn't work smoothly. There's a nice book, author forgotten: "Threaded
Interpreted Languages" that would tell you what you need to know, but
there are plenty of knowledgable people here (I'm not one of them) who
can give you all the details you need. You might start with Anton Ertl's
paper in threading methods.
http://www.complang.tuwien.ac.at/forth/threaded-code.html
--
Engineering is the art of making what you want from things you can get.
-----------------------------------------------------------------------



Wed, 10 Sep 2003 22:00:25 GMT  
 Help writing compiler


Quote:
>I had a copy of J. Brien's "Build Your Own Forth" webpage in my
>/usr/src/H3m . (original URL is
>"http://www.users.zetnet.co.uk/aborigine/byof.htm")

This is on the FIG UK web site which moved to http://forth.org.uk some
time back.

Bye for now                       ____/  /  __  /   /   /   /   /
                                 /      /  /  _/   /   /   /  /
Chris Jakeman                   __/    /  / __    /   /   /_/
                               /      /  /   /   /   /   /  \
[To reply, please           __/    __/  ____/    ___/ __/   _\
 unspam my address]
                           Forth Interest Group United Kingdom
Voice +44 (0)1733 753489   chapter at http://forth.org.uk

Bye for now                       ____/  /  __  /   /   /   /   /
                                 /      /  /  _/   /   /   /  /
Chris Jakeman                   __/    /  / __    /   /   /_/
                               /      /  /   /   /   /   /  \
[To reply, please           __/    __/  ____/    ___/ __/   _\
 unspam my address]
                           Forth Interest Group United Kingdom
Voice +44 (0)1733 753489   chapter at http://forth.org.uk



Thu, 11 Sep 2003 06:20:25 GMT  
 Help writing compiler
Quote:

>      [snip...]     [snip...]     [snip...]

> There is an inner interpreter that executes each component word of a
> definition in turn. NEXT is a component's way to tell the system that it
> is finished and that the next component should be called. If that next
> component is ' ; ', the inner interpreter gets the next word. (It works.
> Trust!) One can't be more specific without deciding on an actual
> threading scheme. There are several to choose from, and the "best"
> depends on the processor architecture and maybe also on a trade-off
> between speed and simplicity. (Another way to look at NEXT is that with
> subroutine threading, it reduces to RTS, RET, or whatever op code pops
> the calling address off the return stack and goes there.)

> It is easier to take one apart than to design one from scratch, but you
> can cobble something together and figure out what is missing when it
> doesn't work smoothly. There's a nice book, author forgotten: "Threaded
> Interpreted Languages" that would tell you what you need to know, but
> there are plenty of knowledgable people here (I'm not one of them) who
> can give you all the details you need. You might start with Anton Ertl's
> paper in threading methods.
> http://www.complang.tuwien.ac.at/forth/threaded-code.html

Here is the bibliographic info for the book you mentioned:

_Threaded Interpretive Langauges_, by R. G. Loeliger, BYTE Books,
Peterborough, NH, 1981, ISBN:  0-07-038360-X

You should be able to get this book through interlibrary loan, since it
is out of print. Or you could go to a used book WEB site like:

                <http://www.abebooks.com/>
                <http://www.libras.com/>
                <http://www.half.com/>

Be sure and search through the listings for the lowest price, as
the prices tend to vary greatly.

--
+-------------------------------------------------------------+

+-------------------------------------------------------------+



Thu, 11 Sep 2003 08:43:17 GMT  
 Help writing compiler

Quote:

>            <http://www.libras.com/>

Do you mean Alibris <http://www.alibris.com/>?  The above site doesn't
exist, AFAIK.

--
- Adrian



Thu, 11 Sep 2003 20:19:26 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Help wanted on reading/writing disk and writing your own OS

2. Help wanted on reading/writing disk and writing your own OS

3. Writing an Eiffel compiler as a course project?

4. Writing an Eiffel compiler

5. Anyone ever write a compiler in LabVIEW

6. looking for C compiler written in Forth

7. Writing compiler

8. Newsgroups for C++ Programmers Using Borland's Compiler Writing Programs for windows 95

9. A simple SSA-based compiler written in Dylan

10. Pascal Compiler Written in Oberon

11. Other languages compilers written in Oberon

12. Writing a COBOL Compiler

 

 
Powered by phpBB® Forum Software