-
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
Tokenizer hash table #10
Open
nickd4
wants to merge
22
commits into
uho:master
Choose a base branch
from
nickd4:tokenizer_hash_table
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)
nickd4
force-pushed
the
tokenizer_hash_table
branch
2 times, most recently
from
May 1, 2022 00:30
6488759
to
913f5dd
Compare
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 implements a new hash table arrangement in
seedForth-tokenizer.fs
. If I understand the previous code correctly, I think it makes a bit of a simplification in that it allocates a large hash table to make collisions unlikely, but can't then handle collisions.So with the new method I have allocated a 1024-entry symbol table and I'm using closed hashing, in which a CRC function gives the preferred entry for a given symbol, but if that entry is occupied by another symbol it looks circularly for a free entry.
The main reason why I wanted to make this change is so that the tokenizer can be self-hosting on Z80, which does not have the memory for a large hash table. With the new way, there's no reliance on 32-bit arithmetic either, which is useful for Z80.
The choice of a 1024-entry table is due to a change I made in the last PR which freed up token 3 for additional token space:
It would of course be easy to make the table larger on a target like i386 that can support it. If so, then the current CRC10 could be changed to say CRC12 or CRC16 (I really hate the idea of calculating a CRC and then masking it off to lose its properties!).
Note: There are minor bugs in this PR, as follows:
gforth
inMakefile
instead of$(HOSTFORTH)
. It is fixed in Z80 port (cleaned up version) #12 so I have not fixed it here.Macro
andend-macro
, and could be reused by accident, though it would be unlikely. It is fixed in New definer syntax #16 so I have not fixed it here.If you do want the fixed version of this PR see the branch
tokenizer_hash_table1
in my github account. I wouldn't recommend using that branch though, because it will cause conflicts later when mergining #12, #16 and others.