mitra42 / webForth

Forth for the web - implemented in JS and other web technologies
https://www.mitra.biz/forth/console.html
GNU Affero General Public License v3.0
27 stars 1 forks source link

Arduino - backport to main branch #60

Closed mitra42 closed 3 years ago

mitra42 commented 3 years ago

Currently it only runs out the eprom branch, backporting is a little complex

mitra42 commented 3 years ago

Doing this in the Eprom branch ... partially added a Romable16_16 class

Part of the JS backport should be looking for efficiency issues, especially using both Forth and JS stacks. For example fetch pops stuff off Forth stack, then passes as argument to Mfetch to m.fetchCell which passes the address to ramAddr for conversion and then passes to cellRamFetch. Some of these steps could be eliminated.

On Arduino its already simpler

fetch() { SPpush(Mfetch(SPpop())) }
CELLTYPE Mfetch(const CELLTYPE byteAddr) { return (byteAddr >= RAM0) ? cellRamFetch(RAMADDR(byteAddr)) : cellRomFetch(ROMADDR(byteAddr)) ; }
#define RAMADDR(x) ((x ^ RAM0) >> CELLSHIFT)
CELLTYPE cellRamFetch(const CELLTYPE cellAddr) {  return ram[cellAddr]; };

But really that wants to be closer to

fetch() {
 const CELLTYPE a = ram[SP];
 ram[SP] = (a & RAM0) ? ram[(a ^ RAM0) >> CELLSHIFT] : rom[a]
}

Then Mfetch(a) gets replaced in some cases with fetch() if the arguments are anywhere near the stack or just with

Mfetch(a) { return (a & RAM0) ? ram[(a ^ RAM0) >> CELLSHIFT] : rom[a] }

Worth further thought that this last line might not be that different from the code actually output since a smart compiler probably optimises cellRamFetch (or I could use a #define)

mitra42 commented 3 years ago
mitra42 commented 3 years ago

Backport is done - but only for Cell=2 mem=16, would be good to add the others in the Rommable format and then remove the Mem versions.