In article <nnd$23e6e7e7$28df6727@b48c89f815d28223>,
none) (albert <albert@cherry.> wrote:
In article <[email protected]>,
Marcel Hendrix <[email protected]> wrote:
iForth is since long prepared for separated data and code, but I never enabled
it because I would mean introducing new/non-standard words for CREATE .. >>DOES> and , C, etc.. Maybe in next year's release.
I can't see that one has to introduce non-standard words.
Also the changes to CODE ENDCODE ;CODE doesn't seem to be
a bug deal either. But you are right, only do it, if it has
benefits.
I have done it. The benefits are general cleaner code and
a preparation in case we are in fact forced to separate for
the newest arm apple computers.
As you know the ciforth's are generated with one source file
regulated by macro's using m4. This is i86 and AMD only.
An addition for separating the code and data sections must
make the main builds for windows and linux, i.e. the following
tests must pass:
make testlina64
make testlina32
make testwina64
make testwina32
These are build with fasm, one of the four assemblers foreseen.
The additions are added to the gnu assembler version.
That is regulated by the same lina64.cfg control file, but
the target in the Makefile is .s.
The first step is the addition of a rule to prelude.m4
define( {_SEPARATED_}, _no)dnl
If you want a feature only with separated code and data you
can do
_SEPARATED({ POP BX _C{ GET INCREMENT} })
and it makes a difference only with
define( {_SEPARATED_}, _yes)dnl
Important to note that ciforth is a compiler factory.
It generates an assembler file, that is passed to the engineer,
comparable to the infamous FIGFORTH listings.
He is not even aware that a facility to separate existed in the
first place. For now the test are bound to pass,
because the assembler file manufactured has not even changed.
The modifications to a code definition as an example to DROP
(the fields are cdflnsx, code data flag link name source extra)
Prior the assumption was made that the code (first field) is
directly after the header.
In the generic file there is only:
CODE_HEADER({DROP},{DROP})
POP AX
_NEXT
DROP:
---- DQ DROP+HEADSIZE -
| DQ DROP+HEADSIZE
| DQ 0x0
| DQ OVER
| DQ N_DROP
| DQ 0
| DQ 0
|
------> POP RAX
LODSQ ; NEXT
JMP QWORD[RAX]
This must be changed to a proper label:
DROP:
DQ X_DROP
DQ DROP+HEADSIZE
DQ 0x0
DQ OVER
DQ N_DROP
DQ 0
DQ 0
X_DROP:
POP RAX
LODSQ ; NEXT
JMP QWORD[RAX]
Or the last part if _SEPARATED_
.section .forthx
POP RAX
LODSQ ; NEXT
JMP QWORD[RAX]
.section .forthd
IN the file header.m4 we changed the macro's
CODE_HEADER and _NEXT . That is all.
At the end of the _NEXT macro we add _DATA_ to switch to the
data segment.
At the end of CODE_HEADER macro we add _TEXT_ to switch to the
code segment.
Nobody knows how the _TEXT_ switching code looks like.
That is assembler dependant. Luckily that is separated
out in the gas.m4 file.
At the expense of few lines changed in the m4 files,
the bulk of the work is done.
There remains situations like the following where
an extra _TEXT_ has be inserted because _NEXT switches to
_DATA_ mode:
XCHG RPO,SPO _C{ GET PARAMETER STACK}
_NEXT
******* _TEXT_
QXDO1: MOV HIP,AX
_NEXT
This _TEXT_ can be added to the generic file. It does no
harm for the fasm compiler, as long as an appropriate _TEXT_
is defined in the fasm.m4 macro file. It does nothing.
At this stage all tests must pass.
In the next stage we handle the defining words.
They use R> to fill in the code field
because that points to the low level code following,
but that is not longer true in general.
The changes are not large. Replace R> by a literal such
as DOCOL. Don't forget put a _TEXT_ in front of the
DOCOL: label.
I have bored you enough. Bottom line there is now a gnu assembler version
of lina64 that has its code and data separate.
Unsurprisingly the difference in speed is unnoticeable. All code
in ciforth is in the innermost cache anyway.
And a last remark. Is the generic file now approaching its collapse
with all the edits?
Far from it. The changes made to the generic file add to the quality.
The R> trick for defining words saves a NEXT and a cell in one definition.
That could be worth it ... in the early 80's.
The (;CODE) word saves 2 cells in 5 cases and eats up a name, 2 cells,
and a header, 7 cells.
You can't use it without ;CODE and the documentation is awkward.
And of course it can't be used with separated sections.
;CODE and (;CODE) are eliminated, at the cost of 6 cells
in file size.
Now look what the definition of CONSTANT has become after
eliminating ;CODE
: CONSTANT NAME (CREATE) LATEST >DFA ! DOCON LATEST CFA ! ;
Get a name, use it to create a header, get a stack time to store
in the data field of the latest definition, store DOCON as the
code for the latest definitions.
The decompilation tools has become simpler because (;CODE) was
a weird exception.
-marcel
Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)