It's mainly code cleanup, I did this because I created a Z80 port and in the process of writing the Z80 code I noticed various things that I wanted to change. You can see the Z80 port at https://github.com/nickd4/preForth/tree/z80_port and it works well but it also needs code cleanup which I will do soon. Eventually I'd like the master branch to build all ports under distinct filenames, and possibly build some other support files like the assembler and emulator (which are needed for bootstrapping).
So for the time being I'm simply submitting improvements to the i386 port. They are well summarized by the commit messages, which I have listed in the below list along with some further explanatory text about each change and why I wanted to make it.
Add .gitignore, rationalize make clean, remove a gforth warning in tokenizer. To avoid the warning, in the tokenizer I renamed number? to process-number? following the convention of process-digit? which is used by process-number?.
Remove .$(UNIXFLAVOUR) extension and file copies in favour of ifeq. Unfortunately this is a GNU make extension. I am not sure if you were supporting BSD make in the Darwin version. GNU make is well supported on Darwin, so I believe this change is worthwhile, as it makes the build process somewhat simpler.
Remove redundant stuff in the preForth-generated asm code. Symbols like _O and last which were never referenced, obviously they were used in a previous version.
Use tabs in preForth-i386-rts.pre and seedForth-i386.pre, improve consistency between these files. For instance, the 0< was returning 1 for true in preForth but -1 for true in seedForth. The changes were pretty minor though.
Rationalize how cr is emitted in generated preForth code, make DB/DD lowercase. I made cr be emitted at the end of each line rather than the start. This allowed me to improve the appearance of the generated code a bit, e.g. where the symbols like _dropX are defined that mark the start of the data field.
Rationalize the sections in assembly output, make code be compiled into bss rather than text section which avoids the need to call mprotect(), rename things. I also removed unnecessary padding, for instance there was 16 bytes of padding after each stack which does not appear to be needed, and the dummy word after _memtop is also not needed. (fasm allows to define a label by itself, unlike masm which requires a data label to be followed by a sizing directive like db).
Split seedForth-i386.pre into machine dependent/less machine dependent portions. This mirrors the structure of preForth to some extent.
Split seedForth-i386.pre further into header and body portions. This is basically so that when the common code is eliminated between seedForth and preForth (the interpreter and primitive asm words), seedForth can still have its own header comment, and can define the head and mem sizes at the top of the file.
Remove duplicated code in seedForth-i386.pre, take from preForth-i386-rts.pre. This saves a fair bit of code and avoids risk of them desynchronizing again.
Thanks for creating preForth/seedForth, they are really brilliant. A while ago I was trying to port hForth (an MS-DOS Forth) or one of its relatives to Z80, but I became discouraged because of the large amount of hand-compiling of high-level Forth words I would need to do for initial bootstrap, plus the issue of retargeting the 8086 Forth assembler to Z80. Your ideas neatly solve both problems and meant I could get the Z80 Forth up and running within a day or two -- including the time taken to convert things from indirect threaded to direct threaded (good for Z80 but less good for i386) and experiment with dodoes and so on.
hi, I've been hacking on this as instructed :)
It's mainly code cleanup, I did this because I created a Z80 port and in the process of writing the Z80 code I noticed various things that I wanted to change. You can see the Z80 port at https://github.com/nickd4/preForth/tree/z80_port and it works well but it also needs code cleanup which I will do soon. Eventually I'd like the master branch to build all ports under distinct filenames, and possibly build some other support files like the assembler and emulator (which are needed for bootstrapping).
So for the time being I'm simply submitting improvements to the i386 port. They are well summarized by the commit messages, which I have listed in the below list along with some further explanatory text about each change and why I wanted to make it.
.gitignore
, rationalizemake clean
, remove agforth
warning in tokenizer. To avoid the warning, in the tokenizer I renamednumber?
toprocess-number?
following the convention ofprocess-digit?
which is used byprocess-number?
..$(UNIXFLAVOUR)
extension and file copies in favour ofifeq
. Unfortunately this is a GNUmake
extension. I am not sure if you were supporting BSDmake
in the Darwin version. GNUmake
is well supported on Darwin, so I believe this change is worthwhile, as it makes the build process somewhat simpler._O
andlast
which were never referenced, obviously they were used in a previous version.preForth-i386-rts.pre
andseedForth-i386.pre
, improve consistency between these files. For instance, the0<
was returning1
for true in preForth but-1
for true in seedForth. The changes were pretty minor though.cr
is emitted in generated preForth code, makeDB
/DD
lowercase. I madecr
be emitted at the end of each line rather than the start. This allowed me to improve the appearance of the generated code a bit, e.g. where the symbols like_dropX
are defined that mark the start of the data field.bss
rather thantext
section which avoids the need to callmprotect()
, rename things. I also removed unnecessary padding, for instance there was 16 bytes of padding after each stack which does not appear to be needed, and the dummy word after_memtop
is also not needed. (fasm
allows to define a label by itself, unlikemasm
which requires a data label to be followed by a sizing directive likedb
).seedForth-i386.pre
into machine dependent/less machine dependent portions. This mirrors the structure of preForth to some extent.seedForth-i386.pre
further into header and body portions. This is basically so that when the common code is eliminated between seedForth and preForth (the interpreter and primitive asm words), seedForth can still have its own header comment, and can define thehead
andmem
sizes at the top of the file.seedForth-i386.pre
, take frompreForth-i386-rts.pre
. This saves a fair bit of code and avoids risk of them desynchronizing again.Thanks for creating preForth/seedForth, they are really brilliant. A while ago I was trying to port hForth (an MS-DOS Forth) or one of its relatives to Z80, but I became discouraged because of the large amount of hand-compiling of high-level Forth words I would need to do for initial bootstrap, plus the issue of retargeting the 8086 Forth assembler to Z80. Your ideas neatly solve both problems and meant I could get the Z80 Forth up and running within a day or two -- including the time taken to convert things from indirect threaded to direct threaded (good for Z80 but less good for i386) and experiment with
dodoes
and so on.