-
Notifications
You must be signed in to change notification settings - Fork 1
Description
It is annoying and error prone to write ITC (the colon word equivalent in assembler) by hand. It is highly useful to have a tool that can take a forth colon word definition and spit out the ITC version of the same. To do this with an external tool means you will have to replicate the AmForth compiler logic to a significant degree, and then you're stuck maintaining two separate versions of the compiler. What would it take to be able to use the AmForth compiler for this?
A colon word ITC is for the most part a list of word XTs. In ITC it usually looks like .word XT_..... We don't have the symbols in AmForth but the addresses that the compiler generates must match the symbols that we get from the linker (only for words that are already in ITC!!!). If we could put the compiler into a "transpiling" mode where it would print out the equivalent ITC as it was compiling, it could easily emit some notation like xt 0xAAAAAAAA for each XT it compiles.
We would need the xt indication in order to distinguish XTs from other literal values. Jump addresses would be another possibility, although we my be able to emit numeric assembler labels directly for branches ( 1: and 1f or 1b )
We can take this intermediate notation of the compiled word and run it through an external tool that will replace all the xt AAAAAAAA with .word XT_SYMBOL based on the symbol table that we're already producing when we build amforth. The symbol table will only have words that are already in ITC, so transpiling a word that uses other words that were compiled dynamically will result in some xt addresses that we won't be able to resolve. This means that transpiling a set of words into ITC would have to be gradual process of moving words into ITC in layers, but could still be. pretty reasonable process.
How feasible is this?