Main Page | Report this Page
Computers Forum Index  »  Computer Languages (Forth)  »  Why are there 2 sections: code and header?...
Page 1 of 1    

Why are there 2 sections: code and header?...

Author Message
Helmut Giese...
Posted: Sun Jan 10, 2010 1:53 am
Guest
Hello out there,
just wondering: In pForth (a C based Forth) there is a section called
'header' and another one called 'code', and I find something similar
in an assembler based version for eForth: some parts go into the code
segment, some other into the data segment.

What is the reason for this separation? Eventually they both end up
either in RAM (in an OS based system) or in ROM (which is what I am
currently aiming for).
I am considering to just lumping the two together. However, before
investing too much work, I would like to know if there are any caveats
this way.
Thanks for any advice and best regards
Helmut Giese
 
Anton Ertl...
Posted: Sun Jan 10, 2010 1:56 am
Guest
Helmut Giese <hgiese at (no spam) ratiosoft.com> writes:
Quote:
Hello out there,
just wondering: In pForth (a C based Forth) there is a section called
'header' and another one called 'code', and I find something similar
in an assembler based version for eForth: some parts go into the code
segment, some other into the data segment.

What is the reason for this separation?

I don't know about pForth and eForth, but an idea that has been
mentioned several times is to throw away the headers after compilation
in memory-starved systems; you can then still run the program as long
as it doesn't access anything from the headers (e.g., no FIND at
run-time).

It requires a separation of compilation from run-time, though,
contrary to the spirit of Forth.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2009: http://www.euroforth.org/ef09/
 
Helmut Giese...
Posted: Sun Jan 10, 2010 3:58 am
Guest
Hi Anton,
Quote:
Helmut Giese <hgiese at (no spam) ratiosoft.com> writes:
Hello out there,
just wondering: In pForth (a C based Forth) there is a section called
'header' and another one called 'code', and I find something similar
in an assembler based version for eForth: some parts go into the code
segment, some other into the data segment.

What is the reason for this separation?

I don't know about pForth and eForth, but an idea that has been
mentioned several times is to throw away the headers after compilation
in memory-starved systems; you can then still run the program as long
as it doesn't access anything from the headers (e.g., no FIND at
run-time).
which would mean that you couldn't compile any new words, right? Thus

it would "only" be usable as a "turn-key" system then.

Quote:
It requires a separation of compilation from run-time, though,
contrary to the spirit of Forth.
Well, specific requirements often win over the 'spirit'.


Thanks for the info and best regards
Helmut Giese
 
Coos Haak...
Posted: Sun Jan 10, 2010 5:17 am
Guest
Op Sat, 09 Jan 2010 21:53:50 +0100 schreef Helmut Giese:

Quote:
Hello out there,
just wondering: In pForth (a C based Forth) there is a section called
'header' and another one called 'code', and I find something similar
in an assembler based version for eForth: some parts go into the code
segment, some other into the data segment.

What is the reason for this separation? Eventually they both end up
either in RAM (in an OS based system) or in ROM (which is what I am
currently aiming for).
I am considering to just lumping the two together. However, before
investing too much work, I would like to know if there are any caveats
this way.
Thanks for any advice and best regards
Helmut Giese

One reason is space: in my 16 bit CHForth I use five sections.
One has code, the second the headers, the third colon definitions, the
fourth strings and the fifth the stacks.
This way I have about 50 Kb free in eacht of the three first sections.
And I can throw the headers away in a turnkey program.
Segments, as this is MSDOS based.

--
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html
 
Ed...
Posted: Sun Jan 10, 2010 6:16 am
Guest
Helmut Giese wrote:
Quote:
Hi Anton,
Helmut Giese <hgiese at (no spam) ratiosoft.com> writes:
Hello out there,
just wondering: In pForth (a C based Forth) there is a section called
'header' and another one called 'code', and I find something similar
in an assembler based version for eForth: some parts go into the code
segment, some other into the data segment.

What is the reason for this separation?

I don't know about pForth and eForth, but an idea that has been
mentioned several times is to throw away the headers after compilation
in memory-starved systems; you can then still run the program as long
as it doesn't access anything from the headers (e.g., no FIND at
run-time).
which would mean that you couldn't compile any new words, right? Thus
it would "only" be usable as a "turn-key" system then.

It requires a separation of compilation from run-time, though,
contrary to the spirit of Forth.
Well, specific requirements often win over the 'spirit'.

Indeed. Not many applications I've seen (embedded or otherwise)
require a compiler on board.

The ability of a forth compiler to strip out the compiler from a
turnkeyed app is a feature. No doubt there many things contrary
to the spirit of forth, but I'd be amazed if this was one of them.
 
John Passaniti...
Posted: Sun Jan 10, 2010 8:54 am
Guest
On Jan 9, 9:27 pm, "Ed" <nos... at (no spam) invalid.com> wrote:
Quote:
Indeed.  Not many applications I've seen (embedded or otherwise)
require a compiler on board.

Sure, but having a compiler does give you options.

For example, I worked on an environmental monitoring and control
system that had sense and control modules connected over a bus to a
central processor board. When the system shipped, it was going to
know about three modules, but some time later, they planned on having
several other modules. To handle this in a seamless way for the end
user, all modules were self-describing and could download code to the
central processor when they were discovered. That code could
"upgrade" the central processor's code to allow new protocols, new
user interfaces, and other arbitrary features. The system wasn't in
Forth (it was Lua), but it would have worked the same if the system
was in Forth.

A more common use for leaving the compiler in an embedded system is
simply to have a back door to address system problems that you didn't
anticipate. One system I worked on had a built-in firmware update
facility that had a serious problem and could result in bricking the
system. So using a back door to an embedded Forth, I was able to
bootstrap a functioning firmware update utility and save the day.

But yes, there are certainly times when stripping the compiler from
the application is needed. But even then, I usually still allow some
minimal bootstrap mechanism (like the "three instruction Forth" idea)
so I can push code into a sealed system and execute it. Then I'll
bootstrap a full Forth.

Quote:
The ability of a forth compiler to strip out the compiler from a
turnkeyed app is a feature.  No doubt there many things contrary
to the spirit of forth, but I'd be amazed if this was one of them.

Whenever someone says something is "contrary to the spirit of Forth",
that is someone who either is pushing an agenda, or has a fixed notion
of what "the spirit of Forth" is.
 
Michael...
Posted: Sun Jan 10, 2010 2:25 pm
Guest
On Jan 10, 9:54 am, John Passaniti <john.passan... at (no spam) gmail.com> wrote:
...
(like the "three instruction Forth" idea)

Is there a link where I could find more about this idea?

m
 
Albert van der Horst...
Posted: Sun Jan 10, 2010 4:21 pm
Guest
In article <sgqhk5dobp0jqhnk8dk9nas9svpchs80an at (no spam) 4ax.com>,
Helmut Giese <hgiese at (no spam) ratiosoft.com> wrote:
Quote:
Hello out there,
just wondering: In pForth (a C based Forth) there is a section called
'header' and another one called 'code', and I find something similar
in an assembler based version for eForth: some parts go into the code
segment, some other into the data segment.

What is the reason for this separation? Eventually they both end up
either in RAM (in an OS based system) or in ROM (which is what I am
currently aiming for).
I am considering to just lumping the two together. However, before
investing too much work, I would like to know if there are any caveats
this way.
Thanks for any advice and best regards

Keeping code and data separate is practically required for some
processors like the ATMEGA (in the Arduino boards).
It is also a habit in c-code, and serves well for optimising
and protection in the context of Unix like systems.
Once you have it, you can choose to not use it.
This results in the situation that it is present where it is
not used, with no harm done.

(In one of my Forth's, intended for 6809, the system can be
configured to be in ROM, with variable data in RAM,
or totally in RAM. You need sections to handle this.)

Quote:
Helmut Giese

Groetjes Albert

--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at (no spam) spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
 
John Passaniti...
Posted: Sun Jan 10, 2010 7:41 pm
Guest
On Jan 10, 9:25 am, Michael <michael.ka... at (no spam) onlinehome.de> wrote:
Quote:
On Jan 10, 9:54 am, John Passaniti <john.passan... at (no spam) gmail.com> wrote:
..
(like the "three instruction Forth" idea)

Is there a link where I could find more about this idea?

Google works.

What people call a "three instruction Forth" is really nothing more
than a way to remotely load memory, read memory, and call a routine.

Calling such a thing a Forth requires a insanely distorted stretch of
the imagination, but the name has been around for years.
 
Helmut Giese...
Posted: Sun Jan 10, 2010 11:52 pm
Guest
Thanks to all who responded - the issue is now much clearer for me
(I'll keep those 2 sections).
Best regards
Helmut Giese
 
Bernd Paysan...
Posted: Mon Jan 11, 2010 2:20 am
Guest
John Passaniti wrote:
Quote:
What people call a "three instruction Forth" is really nothing more
than a way to remotely load memory, read memory, and call a routine.

Calling such a thing a Forth requires a insanely distorted stretch of
the imagination, but the name has been around for years.

Indeed - in this case (load/store/call), it's rather distorted, since
the interface is really not very Forth-like. Egmont Woizel used a
different interface: There you also had three instructions, but they
were

2KEYS
,
EXECUTE

2KEYS reads a 16 bit word from the serial port (these embedded
processors are usually 16 bit), , compiles them to the dictionary, and
EXECUTE performs a call (EXECUTE actually is implicit, since the serial
handler does BEGIN 2KEYS EXECUTE AGAIN in a loop). These words all use
the stack. at (no spam) is usually defined first in the bootstrap process. To
compile a 16 bit number into the dictionary, you send

<2keys> <literal> <,>

over the wire.

--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://www.jwdt.com/~paysan/
 
Ed...
Posted: Wed Jan 13, 2010 5:18 am
Guest
John Passaniti wrote:
Quote:
On Jan 9, 9:27 pm, "Ed" <nos... at (no spam) invalid.com> wrote:
...
The ability of a forth compiler to strip out the compiler from a
turnkeyed app is a feature. No doubt there many things contrary
to the spirit of forth, but I'd be amazed if this was one of them.

Whenever someone says something is "contrary to the spirit of Forth",
that is someone who either is pushing an agenda, or has a fixed notion
of what "the spirit of Forth" is.

Neither is necessarily diabolical. An agenda could be something
as simple as wanting to determine the facts of a matter. Similarly,
having a "fixed notion" is fine (even unavoidable), provided one is
prepared to correct it should better information come to light.

To define "the spirit of Forth" one would need to compile a list of
properties and aims of forth that *differentiated* it from other
languages. Unfortunately forth is often described in such vague
and general terms that it could apply to almost any language. e.g.
what language doesn't seek to be efficient, powerful, interactive etc.

One must applaud those who've thought about what forth is and
said "I don't like the way forth does certain things" and then gone
off and designed their own forth-like language.
 
m_l_g3...
Posted: Thu Jan 14, 2010 3:46 pm
Guest
On 9 янв, 23:53, Helmut Giese <hgi... at (no spam) ratiosoft.com> wrote:
Quote:
Hello out there,
just wondering: In pForth (a C based Forth) there is a section called
'header' and another one called 'code', and I find something similar
in an assembler based version for eForth: some parts go into the code
segment, some other into the data segment.

What is the reason for this separation? Eventually they both end up
either in RAM (in an OS based system) or in ROM (which is what I am
currently aiming for).
I am considering to just lumping the two together. However, before
investing too much work, I would like to know if there are any caveats
this way.
Thanks for any advice and best regards
Helmut Giese

On Intel processors, writing to the data space is ok, but writing to
the code space would cause a considerable delay, because the processor
will discard a lot of stuff (from caches and pipelines) trying to
behave correctly in the case that you have modified the executable
code.

Stephen Pelc reported that a global variable allocated near a
procedure can cause the procedure to execute about 10 times slower.

As to the names section, this is done to make it easier to throw
the names away if they are not required.
 
Michael...
Posted: Fri Jan 15, 2010 12:27 am
Guest
On 10 Jan., 22:20, Bernd Paysan <bernd.pay... at (no spam) gmx.de> wrote:
...
Quote:
2KEYS
,
EXECUTE
...


I see. Thanks.

Michael
 
 
Page 1 of 1    
All times are GMT
The time now is Wed Jan 02, 1980 3:39 am