Separated headers
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.forth Profile…
 Up
Separated headers         


Author: Maki
Date: Apr 21, 2008 03:48

I have recently cross-compiled my first forth system (subroutine threads),
and now I want to separate headers from code. Current header arrangement
looks like this:
[link][flags][count][name] code
I guess I need one more pointer in the header like this:
[link][flags][count][name][code_ptr] which will connect header to
definition.

Questions:

1. What is the best way to handle allocation in name dictionary? My current
thought is to revector dp with words like:
PROGRAM HERE ( returns dp from program code dictionary)
NAMES HERE ( returns dp from name dictionary)

2. Implementation of word >name is trickier. It appears that >name now
should use FIND to go back to name field.

Are there any other pitfalls that I should pay attention to when doing this?
Any advices an comments appreciated.
Best regards,
M.
Show full article (0.85Kb)
16 Comments
Re: Separated headers         


Author: Alex McDonald
Date: Apr 21, 2008 05:30

On Apr 21, 11:48 am, "Maki" wrote:
> I have recently cross-compiled my first forth system (subroutine threads),
> and now I want to separate headers from code. Current header arrangement
> looks like this:
> [link][flags][count][name] code
> I guess I need one more pointer in the header like this:
> [link][flags][count][name][code_ptr] which will connect header to
> definition.
>
> Questions:
>
> 1. What is the best way to handle allocation in name dictionary? My current
> thought is to revector dp with words like:
> PROGRAM HERE ( returns dp from program code dictionary)
> NAMES HERE ( returns dp from name dictionary)
>
> 2. Implementation of word >name is trickier. It appears that >name now
> should use FIND to go back to name field.
>
> Are there any other pitfalls that I should pay attention to when doing this? ...
Show full article (5.95Kb)
no comments
Re: Separated headers         


Author: m_l_g3
Date: Apr 21, 2008 07:38

On Apr 21, 2:48 pm, "Maki" wrote:
> I have recently cross-compiled my first forth system (subroutine threads),
> and now I want to separate headers from code. Current header arrangement
> looks like this:
> [link][flags][count][name] code
> I guess I need one more pointer in the header like this:
> [link][flags][count][name][code_ptr] which will connect header to
> definition.

[link][flags][code_ptr][count][name]
because name is variable length
>
> Questions:
>
> 1. What is the best way to handle allocation in name dictionary? My current
> thought is to revector dp with words like:
> PROGRAM HERE ( returns dp from program code dictionary)
> NAMES HERE ( returns dp from name dictionary)
Show full article (2.07Kb)
no comments
Re: Separated headers         


Author: Bruce McFarling
Date: Apr 21, 2008 08:10

On Apr 21, 10:38 am, m_l_g3 yahoo.com> wrote:
> An alternative is
> : N-HERE N-DP @ ;;
> : N-ALLOT N-DP +! ;
> etc.
> I do not know which one is best (a global switch or wordset
> duplication).

If the header space is only used for headers, and builds down toward
the codespace, would you need an N-ALLOT? For ALLOT-HEADER, it looks
to me like maybe you just need LAST-NAME and THIS-NAME ...

: ALLOT-HEADER ( -- ) LAST-NAME @ HEADER-SIZE - THIS-NAME ! ;

... with mingled headers, maybe ...

: ALLOT-HEADER (
-- ) HERE THIS-NAME ! HEADER-SIZE ALLOT ;

... but I'll note that hForth has a compact wordset that works for
both mingled and separate headers, so if doing it from scratch, I'd
use that wordset.
no comments
Re: Separated headers         


Author: Maki
Date: Apr 21, 2008 11:27

> [link][flags][code_ptr][count][name]
> because name is variable length

Good point.
>>
>> 2. Implementation of word >name is trickier. It appears that >name now
>> should use FIND to go back to name field.
>
> It's not really find... I promise, you will enjoy coding.

Silly me. Ofcourse not FIND.
> And even a better one is the word that determines in which
> definition the address is. (Say, you want to print the return stack in
> case of errors).
> You will need an array of pointers to the last word in each chain of
> each word list.
> Relative links in name fields are probably worth doing it.

Code and headers aren't relocatable so I can use absolute links.
Show full article (0.71Kb)
no comments
Re: Separated headers         


Author: Maki
Date: Apr 21, 2008 11:39

>
> The header structure;
>
> [ link field ] -4 4 lfa
> [ ' compile, ] +0 4 ct token -- compile,
> +---- [ xt ptr field ] 4 4 xt-ptr
> | [ ' comp ] 8 4 ct token -- comp field
> | [ file field ] 12 4 ffa
> | [ view field ] 16 2 vfa
> | [ stk effects ] 18 2 ste
> | [ optimize field ] 20 2 ofa
> | [ count byte ] 22 1 nfa
> | [ the name letters ] 23 n
> | [ alignment bytes ] 0 to 3 bytes for name alignment
> |
> |
> | [ ct-ptr ] -4 4 ptr to ct token pair
> +---> [ xt field ] +0 xt code field (the xt)
> ...
Show full article (1.07Kb)
no comments
Re: Separated headers         


Author: Maki
Date: Apr 21, 2008 12:02

>> [link][flags][code_ptr][count][name]
>> because name is variable length
>
> Good point.
>

Even better:
[code_ptr][link][flags][count][name]
This layout gives me compatibility with FIND that is coded with no
separation in mind.
It appears that I have to change only >name.

Regards,
M.
no comments
Re: Separated headers         


Author: Alex McDonald
Date: Apr 21, 2008 14:38

On Apr 21, 7:39 pm, "Maki" wrote:
>
>
>
>
>> The header structure;
>
>> [ link field ] -4 4 lfa
>> [ ' compile, ] +0 4 ct token -- compile,
>> +---- [ xt ptr field ] 4 4 xt-ptr
>> | [ ' comp ] 8 4 ct token -- comp field
>> | [ file field ] 12 4 ffa
>> | [ view field ] 16 2 vfa
>> | [ stk effects ] 18 2 ste
>> | [ optimize field ] 20 2 ofa
>> | [ count byte ] 22 1 nfa
>> | [ the name letters ] 23 n
>> | [ alignment bytes ] 0 to 3 bytes for name alignment
>> |
>> | ...
Show full article (1.34Kb)
no comments
Re: Separated headers         


Author: Maki
Date: Apr 21, 2008 15:45

> Then just search the dictionary for the XT; simple and fast enough,
> given that the (marginal) overhead is compile time only.
>
> --
> Regards
> Alex McDonald

I did it like that. Also changed FIND a little bit and recoded HEADER,
>NAME, NAME> and also implemented revectoring of dp.

Thanks,
M.
no comments
Re: Separated headers         


Author: mark4
Date: Apr 21, 2008 19:54

On Apr 21, 3:48 am, "Maki" wrote:
> I have recently cross-compiled my first forth system (subroutine threads),
> and now I want to separate headers from code. Current header arrangement
> looks like this:
> [link][flags][count][name] code
> I guess I need one more pointer in the header like this:
> [link][flags][count][name][code_ptr] which will connect header to
> definition.
>
> Questions:
>
> 1. What is the best way to handle allocation in name dictionary? My current
> thought is to revector dp with words like:
> PROGRAM HERE ( returns dp from program code dictionary)
> NAMES HERE ( returns dp from name dictionary)
>
> 2. Implementation of word >name is trickier. It appears that >name now
> should use FIND to go back to name field.
>
> Are there any other pitfalls that I should pay attention to when doing this? ...
Show full article (1.25Kb)
no comments
1 2