CargoCult interpreter
CargoCult interpreter
I've started (and stopped) writing a bytecode-interpreted small language for a few years now. I call the language "Cargo Cult" mainly because it's a cool-sounding name.
But... its specs are kind of hazy. The bytecode interpreter is bog-standard, but the language it compiles to is fluid: it changes based largely on my whims.
So, what better way to start again than to target an 8 bit architecture, says I. Forces me into constraints.
Here's kind of what I'm aiming for in CargoCult 1.0. I *think* the key difference between it and a structured BASIC is the array notation and use, which is more or less borrowed from Perl. That, and the importance of the newline character in block declarations and endings.
fn int buildZones totalSectors, startTrack, @zones
for |index| 0..@zones.length
my track = 1 + GLOBAL.totalTracks + startTrack;
my sectorCount = @zones[index][1];
my endTrack = 1 + GLOBAL.totalTracks + @zones[index][0];
GLOBAL.totalTracks += @zones[index][0];
for |jdex| track..endTrack
GLOBAL.@trackOffset[ jdex ] = totalSectors * 0x100;
GLOBAL.@sectorOffset[ jdex ] = totalSectors;
GLOBAL.@sectorsInTrack[ jdex ] = sectorCount;
totalSectors += sectorCount;
endfor
endfor
return totalSectors;
endfn