-
Notifications
You must be signed in to change notification settings - Fork 8
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
Simplify bootstrapping #11
Open
nickd4
wants to merge
25
commits into
uho:master
Choose a base branch
from
nickd4:simplify_bootstrapping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…to bss rather than text section which avoids the need to call mprotect(), rename things
… be wrapped with PROGRAM / END, also removes automatic bye token that was generated by END
…time.seedsource, so that we can run textual forth code without the tests or the banner
… writes to stderr, fix self-hosted tokenizer termination issue (was debugged with eemit)
…ng the nonstandard words on top of gForth's standard words, produces redefinition warnings
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change attempts to simplify bootstrapping from gForth/SwiftForth, noting that I don't have SwiftForth and only test gForth.
With the original bootstrapping method, we were creating a very authentic preForth environment within the host Forth, by creating a new wordlist and then loading the entire preForth runtime system into it, except for a few essential "borrowed" words.
The files that controlled this process were
load-i386-preForth.fs
,load-preForth.fs
andborrow.fs
. Collectively they were quite complicated, and not being an experienced Forth programmer I didn't understand the details of borrowing in particular.There was also another thing that I found confusing, which is the way that
load-preForth.fs
was definingpre
andcode
so they skip their body. Initially I thought, shouldn't it be echoing the body to the output, instead of skipping it? But after a bit of thought I worked out the reason: Under an interpretive Forth system, you would expect a word likepre
orcode
to be defined and then executed. But since preForth is only compiled, it's not possible to execute a word that was defined in the same run. Instead the words likepre
andcode
have to be already defined and part of the compiler that is compiling the source. So this leads to the unusual pattern wherepre
andcode
are first executed, and then later on, compiled to use in next stage. And this indirectly explains whypre
andcode
are being ignored in the initial bootstrap, as we are only compiling them. (!)Thinking about it some more, I realized that the more elegant way of handling this situation is not to include the
pre
andcode
definitions in the initial bootstrap at all (rather than defining them to no-ops and then including them). Or in other words, we can use the primitives supplied by the host Forth instead of the asm primitives, in the bootstrap compile run. So we can omit the filepreForth-i386-rts.pre
from the bootstrap compile run. And the same logic applies to most of the high-level Forth code inpreForth-rts.pre
, it's already available in the host Forth with a few exceptions likecase?
,tab
,*10
and stack strings.Therefore, my new approach to bootstrapping is to split out the nonstandard words from
preForth-rts.pre
intopreForth-rts-nonstandard.pre
so that they can be used for the bootstrap compile run, whilstpreForth-i386-rts.pre
andpreForth-rts.pre
are omitted. I also have an extremely cut down version ofborrow.fs
/load-preForth.fs
which I callpreForth-bootstrap.fs
. All this does is to deal with the tail call syntax which is nonstandard. So all of the nonstandard parts are now in eitherpreForth-bootstrap.fs
orpreForth-rts-nonstandard.pre
, with the former being not needed under pure preForth and the latter needed.I also have an extremely cut down version of
load-i386-preForth.fs
which I callpreForth-cold.fs
and all this does is to callcold
and thenbye
(mirroring what the main function does in compiled preForth asm code). The actual including of sources for the bootstrap compile run is now done from the gForth command line (I assume / hope this will also work for SwiftForth).Thus the bootstrap compile command is now:
Note that redefinition warnings are generated for some words like
cold
that have different meanings under the host Forth than the preForth compiler. I could suppress these, as was done in the originalload-preForth.fs
, but I thought it not necessary. If the initial bootstrap process is a bit ugly it does not really matter, as once bootstrapped you can use the preForth way instead.Once again, the changeset will look larger than it really is, so please merge the previous PRs then have github recalculate it.