Skip to content
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

Simplify bootstrapping #11

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
df227c7
Add .gitignore, rationalize make clean, remove a gforth warning in to…
nick-lifx Apr 22, 2022
56c4dcf
Remove .$(UNIXFLAVOUR) extension and file copies in favour of ifeq (G…
nick-lifx Apr 22, 2022
a2e4911
Remove redundant stuff in the preForth-generated asm code
nick-lifx Apr 22, 2022
cb3ba98
Use tabs in preForth-i386-rts.pre and seedForth-i386.pre, improve con…
nick-lifx Apr 22, 2022
fa4f0c2
Rationalize how cr is emitted in generated preForth code, make DB/DD …
nick-lifx Apr 22, 2022
927ca5a
Rationalize the sections in assembly output, make code be compiled in…
nick-lifx Apr 22, 2022
77b48fe
Split seedForth-i386.pre into machine dependent/less machine dependen…
nick-lifx Apr 22, 2022
f843d08
Split seedforth-i386.pre further into header and body portions
nick-lifx Apr 22, 2022
cdd8686
Remove duplicated code in seedForth-i386.pre, take from preForth-i386…
nick-lifx Apr 22, 2022
c962f42
Implement built-in "cat" functionality in preForth/seedForth for read…
nick-lifx Apr 23, 2022
ebf5bfa
Make key? use fdin instead of always STDIN_FILENO, and use poll() not…
nick-lifx Apr 23, 2022
d48d34a
Rationalize seedForth-tokenize.fs so that seedsource no longer has to…
nick-lifx Apr 23, 2022
375ab0f
Move most code from seedForthInteractive.seedsource into seedForthRun…
nick-lifx Apr 23, 2022
8da6c87
Rationalize how echo is handled during the seedForthInteractive loadi…
nick-lifx Apr 23, 2022
62bcae1
Split out control flow words and a few others from hi.forth into runt…
nick-lifx Apr 23, 2022
78426fc
Make ./seedForth-tokenizer self hosting (works, but hangs after token…
nick-lifx Apr 23, 2022
cbfdac8
Remap tokens so that EOT is no longer a seedForth token, detect EOT e…
nick-lifx Apr 24, 2022
caac682
Implement eot token similar to the old bye token (so we can compile b…
nick-lifx Apr 24, 2022
75138c3
Implement a new preForth/seedForth token eemit which is like emit but…
nick-lifx Apr 24, 2022
7115f49
Implement DO/?DO/LOOP, as experimental ?DO didn't have a correct comp…
nick-lifx Apr 24, 2022
03f5872
Add CRC10/ATM (bit reversed) table generator and evaluator
nick-lifx Apr 24, 2022
913f5dd
Modify tokenizer to use a 1024-entry symbol table with closed hashing…
nick-lifx Apr 24, 2022
4e4fa66
Move nonstandard words from preForth-rts.pre into preForth-rts-nonsta…
nick-lifx Apr 25, 2022
4add97d
Simplify bootstrapping by not creating a new wordlist and only defini…
nick-lifx Apr 25, 2022
12b1f58
Remove load-i386-preForth.fs, instead list the compiler sources on co…
nick-lifx Apr 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.asm
*.o
*.seed
/preForth/crc10.forth
/preForth/preForth
/preForth/seedForth
/preForth/__temp__.fs
154 changes: 113 additions & 41 deletions preForth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ HOSTFORTH=gforth
# ------------------------------------------------------------------------

.PHONY=all
all: preForth seedForth seedForthDemo.seed seedForthInteractive.seed
all: \
preForth \
seedForth \
seedForthDemo.seed \
seedForthBoot.seed \
seedForthInteractive.seed

.PHONY=test
test: runseedforthdemo runseedforthinteractive

.PHONY=runseedforthdemo
runseedforthdemo: seedForth seedForthDemo.seed
cat seedForthDemo.seed | ./seedForth
./seedForth seedForthDemo.seed

.PHONY=runseedfortinteractive
runseedforthinteractive: seedForth seedForthInteractive.seed
Expand All @@ -25,52 +30,87 @@ runseedforthinteractive: seedForth seedForthInteractive.seed
UNIXFLAVOUR=$(shell uname -s)
EXT=asm

seedForth-i386.asm: seedForth-i386.pre preForth
cat seedForth-i386.pre | ./preForth >seedForth-i386.asm

# preForth connected to stdin - output to preForth.asm
preForth.asm: preForth.pre preForth-i386-backend.pre load-i386-preForth.fs
cat preForth-i386-rts.pre preForth-rts.pre preForth-i386-backend.pre preForth.pre \
| $(HOSTFORTH) load-i386-preForth.fs >preForth.asm

preForth: preForth.$(UNIXFLAVOUR)
cp preForth.$(UNIXFLAVOUR) preForth

%.asm: %.pre preForth preForth-i386-rts.pre preForth-rts.pre
cat preForth-i386-rts.pre preForth-rts.pre $< | ./preForth >$@

%: %.$(UNIXFLAVOUR)
cp $< $@

preForth.asm: \
preForth-bootstrap.fs \
preForth-cold.fs \
preForth-i386-rts.pre \
preForth-rts-nonstandard.pre \
preForth-rts.pre \
preForth-i386-backend.pre \
preForth.pre
cat \
preForth-i386-rts.pre \
preForth-rts-nonstandard.pre \
preForth-rts.pre \
preForth-i386-backend.pre \
preForth.pre \
|$(HOSTFORTH) \
preForth-bootstrap.fs \
preForth-rts-nonstandard.pre \
preForth-i386-backend.pre \
preForth.pre \
preForth-cold.fs \
>$@

%.asm: \
%.pre \
preForth-i386-rts.pre \
preForth-rts-nonstandard.pre \
preForth-rts.pre \
preForth
./preForth \
preForth-i386-rts.pre \
preForth-rts-nonstandard.pre \
preForth-rts.pre \
$< \
>$@

ifeq ($(UNIXFLAVOUR),Linux)
# assemble and link executable on linux
%.Linux: %.asm
%: %.asm
fasm $< [email protected]
LDEMULATION=elf_i386 ld -arch i386 -o $@ \
-dynamic-linker /lib32/ld-linux.so.2 \
/usr/lib/i386-linux-gnu/crt1.o /usr/lib/i386-linux-gnu/crti.o \
[email protected] \
-lc /usr/lib/i386-linux-gnu/crtn.o
-dynamic-linker /lib32/ld-linux.so.2 \
/usr/lib/i386-linux-gnu/crt1.o /usr/lib/i386-linux-gnu/crti.o \
[email protected] \
-lc /usr/lib/i386-linux-gnu/crtn.o
# rm [email protected]

else
ifeq ($(UNIXFLAVOUR),Darwin)
# assemble and link executable on MacOS
%.Darwin: %.asm
%: %.asm
fasm $< [email protected]
objconv -fmacho32 -nu [email protected] $@_m.o
ld -arch i386 -macosx_version_min 10.6 -o $@ \
$@_m.o /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/crt1.o /usr/lib/libc.dylib
$@_m.o /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/crt1.o \
/usr/lib/libc.dylib
# rm [email protected] $@_m.o
endif
endif

# run preForth on its own source code to perform a bootstrap
# should produce identical results
bootstrap: preForth preForth-i386-backend.pre preForth.pre preForth.$(EXT)
cat preForth-i386-rts.pre preForth-rts.pre preForth-i386-backend.pre preForth.pre\
| ./preForth >preForth1.$(EXT)
bootstrap: \
preForth-i386-rts.pre \
preForth-rts-nonstandard.pre \
preForth-rts.pre \
preForth-i386-backend.pre \
preForth.pre \
preForth \
preForth.$(EXT)
./preForth \
preForth-i386-rts.pre \
preForth-rts-nonstandard.pre \
preForth-rts.pre \
preForth-i386-backend.pre \
preForth.pre \
>preForth1.$(EXT)
cmp preForth.$(EXT) preForth1.$(EXT)

# preForth connected to stdin - output to stdout
.PHONY=visible-bootstrap
visible-bootstrap: preForth preForth-i386-backend.pre preForth.pre
cat preForth-i386-backend.pre preForth.pre | ./preForth
./preForth preForth-i386-backend.pre preForth.pre

# ------------------------------------------------------------------------
# Docker support (for Linux version)
Expand All @@ -89,16 +129,48 @@ rundocker: docker-image
# ------------------------------------------------------------------------
# seedForth
# ------------------------------------------------------------------------
seedForth.$(EXT): seedForth-i386.pre preForth
cat seedForth-i386.pre | ./preForth >seedForth.$(EXT)

seedForth: seedForth.$(UNIXFLAVOUR)
cp seedForth.$(UNIXFLAVOUR) seedForth

%.seed: %.seedsource seedForth-tokenizer.fs
gforth seedForth-tokenizer.fs $<

seedForth.$(EXT): \
seedForth-i386-header.pre \
preForth-i386-rts.pre \
seedForth-i386.pre \
seedForth.pre \
preForth
./preForth \
seedForth-i386-header.pre \
preForth-i386-rts.pre \
seedForth-i386.pre \
seedForth.pre \
>seedForth.$(EXT)

# a little ugly, because gforth insists upon echoing anything read from
# stdin, and also does not allow parsing words to cross a file boundary,
# so we will concatenate the tokenizer and source into a *.fs file first
seedForthDemo.seed: crc10.forth seedForth-tokenizer.fs seedForthDemo.seedsource
cat $^ >__temp__.fs
gforth __temp__.fs -e bye >$@
rm __temp__.fs

seedForthBoot.seed: \
crc10.forth \
seedForth-tokenizer.fs \
seedForthRuntime.seedsource \
seedForthBoot.seedsource
cat $^ >__temp__.fs
gforth __temp__.fs -e bye >$@
rm __temp__.fs

seedForthInteractive.seed: \
crc10.forth \
seedForth-tokenizer.fs \
seedForthRuntime.seedsource \
seedForthInteractive.seedsource
cat $^ >__temp__.fs
gforth __temp__.fs -e bye >$@
rm __temp__.fs

crc10.forth: crc10_gen.forth
gforth $^ -e bye >$@

.PHONY=clean
clean:
rm -f *.asm *.o *.fas *.s *.c *.Darwin *.Linux preForthdemo preForth forth seedForth seedForthDemo.seed seedForthInteractive.seed
rm -f *.asm *.o *.seed preForthdemo preForth seedForth __temp__.fs
56 changes: 0 additions & 56 deletions preForth/borrow.fs

This file was deleted.

50 changes: 50 additions & 0 deletions preForth/crc10_gen.forth
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
\ run this as follows:
\ ./seedForth seedForthBoot.seed runtime.forth crc10_gen.forth >crc10.forth

817 Constant poly \ CRC-10/ATM, truncated polynomial 0x233, bit reversed 0x331

\ we don't want MS-DOS style line endings in the generated CRC table file
: lf 10 emit ;

: gen
." Create crc10_tab" lf
256 0 ?DO
I 8 0 ?DO
\ split into LSB and the remaining bits
\ in seedForth: 2 u/mod swap
\ in gForth: 2 /mod swap
dup 1 rshift swap 1 and

IF poly xor THEN
LOOP
. ',' emit
I 7 and 7 = IF lf ELSE space THEN
LOOP
lf
." : crc10 ( addr len crc -- crc )" lf
." swap 0 ?DO ( addr crc )" lf
." \ retrieve next character" lf
." over I + c@" lf
lf
." \ xor into low bits of crc" lf
." xor" lf
lf
." \ separate into table index and remaining bits" lf
." \ 256 u/mod swap" lf
." dup 8 rshift swap 255 and" lf
lf
." \ look up new bits from table" lf
." cells crc10_tab + @" lf
lf
." \ combine with remaining (shifted right) bits" lf
." xor" lf
." LOOP" lf
." nip" lf
." ;" lf
lf
." \ testing:" lf
." \ Create hello 104 c, 101 c, 108 c, 108 c, 111 c," lf
." \ hello 5 1023 crc10 . ;" lf
;

gen
Loading