Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I386 improvements #8

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

I386 improvements #8

wants to merge 9 commits into from

Conversation

nickd4
Copy link

@nickd4 nickd4 commented Apr 22, 2022

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.

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants