> load Asm.sbx
> run Say.asm
wrote Say.sbx: program 46, data 93, labels 7
> load Say.sbx
> run built by the machine itself
it says: built by the machine itself
The machine assembles an application and then runs what it built. Say,
greet and Files all come out byte for byte identical to the C assembler's,
and Tests/native.sh checks all three on every run alongside the boot image
M1 already covered.
WHAT IT TOOK, and it was more than #Include and #Base:
#Include The reader is a stack of readers. The current file's whole
state goes aside - buffer and all, 292 bytes - the new one
opens, and the end of it pops the old one back. A file goes in
once; including it twice does nothing, which is what lets two
libraries depend on a third. The list is forgotten between the
passes, because the second has to walk the same tree.
#Base Cursors start there, so labels hold the addresses the program
will really have. A program that says where it goes gets the
SBEX header and a .sbx name; one that says nothing gets SPBT
and .bin. A program that bases one segment and leaves the
other unbased with content in it is refused.
#Reserve Runs of zeroes, moved over in the first pass and written in
#Align the second. How many an #Align comes to depends on where the
cursor has reached, which is why both passes keep a cursor.
#Vectors Names are read and numbered, pinned where the source pins
them, so SWI osPrintString resolves. Every application needs
this - a program that calls a service names a vector declared
in a file it includes.
THE TWO PASSES ARE NOW ONE LOOP, walked twice, with Emitting the only
difference. They have to agree about the length of every token, and the way
they stop agreeing is by being two pieces of code that drifted apart -
which is the exact shape of the bug this assembler found in the C one.
Sharing the body means there is nothing to drift. What is left is checked
anyway: the second pass compares its own totals against the first's and
refuses to write the file if they differ.
THE BUG WORTH RECORDING. The tokenizer holds one character of lookahead,
and at an #Include that character belongs to the file being put aside. It
was carried across and handed back on the way out, which is wrong: a file
runs out in the middle of whatever the tokenizer happens to be doing, so
the character arrives in the middle of a word. `start:` came back as `s`
and then `tart:` - and the result assembled into a perfectly plausible
file. The fix is to undo the read instead, so the character is simply still
there when the file is opened again and the question of when to hand it
back never arises.
Three smaller ones, all old friends: three places took the CONTENTS of a
buffer where they wanted its ADDRESS; vecTakeAuto returned its answer in A,
which a RET puts back; and pass two re-declared every vector because only
the label table was being skipped on the second walk.
sameText moved down into numbers.asm from the label table - four parts want
it now, and a reader test that includes neither labels nor tokens has to
build on its own.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
121 lines
4.4 KiB
Makefile
121 lines
4.4 KiB
Makefile
# SplitBit Programs Makefile
|
|
# Anachronaut
|
|
#
|
|
# Builds every SplitBit program into build/, and keeps track of which libraries
|
|
# each one includes so that editing a library reassembles whatever depends on it.
|
|
#
|
|
# make Assemble everything.
|
|
# make clean Throw away build/.
|
|
# make run-hello Assemble and run one program.
|
|
|
|
ASM ?= ../Assembler
|
|
EMU ?= ../SplitBit
|
|
BUILD ?= build
|
|
|
|
# Libraries are included by bare name, so the assembler is told where to find them.
|
|
# CosmOS owns the filesystem library and the service names, so it is a place to look too.
|
|
INCLUDES = -I Libraries -I CosmOS/Source
|
|
|
|
# The programs worth building. Files in Libraries/ are left out because they have no
|
|
# entry point of their own, and the ones in testPrograms/ are covered by 'make test'
|
|
# in the parent directory.
|
|
PROGRAMS = \
|
|
CosmOS/Source/cosmos.asm \
|
|
hello.asm \
|
|
printHello.asm \
|
|
inputTest.asm \
|
|
replCalculator.asm \
|
|
Fibonacci/8bitFibonacci.asm \
|
|
Fibonacci/16bitFibonacci.asm \
|
|
Fibonacci/32bitFibonacci.asm \
|
|
primeSieve/8bitSieve.asm \
|
|
primeSieve/16bitSegmentedSieve.asm \
|
|
primeSieve/16bitSegmentedSieveModern.asm \
|
|
gameOfLife/16x16Life.asm \
|
|
gameOfLife/16x16LifeModern.asm
|
|
|
|
BINARIES = $(PROGRAMS:%.asm=$(BUILD)/%.bin)
|
|
DEPENDENCIES = $(BINARIES:.bin=.d)
|
|
|
|
all: $(BINARIES)
|
|
|
|
# -M writes out which source files went into the binary, in the form of a make rule.
|
|
$(BUILD)/%.bin: %.asm
|
|
@mkdir -p $(@D)
|
|
$(ASM) $(INCLUDES) -M $(@:.bin=.d) -o $@ $<
|
|
|
|
# Assemble and run a single program, as in 'make run-hello'.
|
|
run-%: $(BUILD)/%.bin
|
|
$(EMU) $<
|
|
|
|
# ---- CosmOS ----
|
|
#
|
|
# make cosmos Assemble the system and everything it can load.
|
|
# make cosmos-disk ... and put the loadable programs on a disk image.
|
|
# make run-cosmos ... and boot the machine with that disk in the drive.
|
|
#
|
|
# Programs in Apps/ say where they live with #Base, so the assembler writes them out as
|
|
# loadable programs rather than as boot images. They are named .sbx to keep that
|
|
# difference visible: a .bin is something the machine boots, a .sbx is something a
|
|
# running system loads.
|
|
|
|
DISKTOOL ?= ../SplitDisk
|
|
COSMOS = $(BUILD)/CosmOS/Source/cosmos.bin
|
|
APPS = $(patsubst CosmOS/Apps/%.asm,$(BUILD)/CosmOS/Apps/%.sbx,$(wildcard CosmOS/Apps/*.asm))
|
|
COSMOS_DISK = $(BUILD)/cosmos.img
|
|
DEPENDENCIES += $(APPS:.sbx=.d)
|
|
|
|
$(BUILD)/CosmOS/Apps/%.sbx: CosmOS/Apps/%.asm
|
|
@mkdir -p $(@D)
|
|
$(ASM) $(INCLUDES) -M $(@:.sbx=.d) -o $@ $<
|
|
|
|
# The assembler that runs on the machine. It is not in Apps/ because it is not one file:
|
|
# it has a directory of its own, the way the C assembler does. Its own pieces are found
|
|
# beside it without being told, since an include is looked for next to the file that asked
|
|
# for it before anywhere else; only services.asm needs the include path.
|
|
NATIVE_ASM = $(BUILD)/CosmOS/Assembler/Asm.sbx
|
|
DEPENDENCIES += $(NATIVE_ASM:.sbx=.d)
|
|
|
|
$(NATIVE_ASM): CosmOS/Assembler/Asm.asm
|
|
@mkdir -p $(@D)
|
|
$(ASM) $(INCLUDES) -M $(@:.sbx=.d) -o $@ $<
|
|
|
|
cosmos: $(COSMOS) $(APPS) $(NATIVE_ASM)
|
|
|
|
# Made from scratch every time, so that what is on it is what is in Apps/ now and not
|
|
# also whatever used to be.
|
|
$(COSMOS_DISK): $(APPS) $(NATIVE_ASM) hello.asm testPrograms/stringKeyword.asm \
|
|
CosmOS/Apps/Say.asm CosmOS/Source/services.asm
|
|
@mkdir -p $(@D)
|
|
rm -f $@
|
|
$(DISKTOOL) format $@ 2048 4
|
|
@for app in $(APPS); do $(DISKTOOL) put $@ $$app; done
|
|
$(DISKTOOL) put $@ $(NATIVE_ASM)
|
|
@# SOURCE goes on as well, because an assembler with nothing to assemble is a
|
|
@# demonstration of nothing. hello.asm and strings.asm are boot images built from one
|
|
@# file; Say.asm is an application, which needs the include and the service names.
|
|
@#
|
|
@# Assembling Say.asm writes Say.sbx over the one the host tool put there, so the
|
|
@# machine ends up running a program it built itself.
|
|
$(DISKTOOL) put $@ hello.asm
|
|
$(DISKTOOL) put $@ testPrograms/stringKeyword.asm strings.asm
|
|
$(DISKTOOL) put $@ CosmOS/Apps/Say.asm
|
|
$(DISKTOOL) put $@ CosmOS/Source/services.asm
|
|
|
|
# The system as well as the disk. Building only the image leaves whatever cosmos.bin was
|
|
# there before, or none at all, and then the disk is booted with a system that does not
|
|
# match the programs on it.
|
|
cosmos-disk: $(COSMOS) $(COSMOS_DISK)
|
|
|
|
run-cosmos: $(COSMOS) $(COSMOS_DISK)
|
|
$(EMU) --disk $(COSMOS_DISK) $(COSMOS)
|
|
|
|
clean:
|
|
rm -rf $(BUILD)
|
|
|
|
# Pull in the dependency rules written by -M above, so that touching a library
|
|
# reassembles every program that includes it.
|
|
-include $(DEPENDENCIES)
|
|
|
|
.PHONY: all clean cosmos cosmos-disk run-cosmos
|