Show HN: Bootstrapping a compiler from raw machine code
github.com3 pointsby nineties0 comments
$ ./planck
kHtketkltkltkotk tkWtkotkrtkltkdtk!tk:k0-tQ
bootstrap.fs self-extends this. After running bootstrap.fs, the Hello World program can be written like this: $ ./planck < bootstrap.fs
." Hello World!" cr
At the beginning of bootstrap.fs, you can only use one-letter words, so the code
is difficult to read as shown below. $ head bootstrap.fs
h@l@h@!h@C+h!k1k0-h@$k:k0-h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!
h@l@h@!h@C+h!k1k0-h@$k h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!
h@l@ h@!h@C+h! k1k0-h@$ k\h@k1k0-+$ h@C+h!
i h@!h@C+h!
kkf h@!h@C+h!
kLf h@!h@C+h!
k:k0- h@!h@C+h!
k=f h@!h@C+h!
kJf h@!h@C+h!
However, at the end, you can write a normal Forth program as follows.
In this way, the interpreter and the language are self-extended during the
execution of the script. $ tail bootstrap.fs
next-arg dup argv @ !
included
else
." Welcome to PlanckForth " version type
." [" runtime type ." ]" cr
copyright
." Type 'bye' to exit." cr
s" /dev/tty" included
then
; execute
Various functionalities like compile mode, immediate mode, control-flow structures, literals, variables, constants, file I/O, heap memory, etc. will be available after running bootstrap.fs. $ ./planck
kHtketkltkltkotk tkWtkotkrtkltkdtk!tk:k0-tQ
bootstrap.fs self-extends this. After running bootstrap.fs, the Hello World program can be written like this $ ./planck < bootstrap.fs
." Hello World!" cr
At the beginning of bootstrap.fs, you can only use one-letter words, so the code
is difficult to read as shown below. $ head bootstrap.fs
h@l@h@!h@C+h!k1k0-h@$k:k0-h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!
h@l@h@!h@C+h!k1k0-h@$k h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!
h@l@ h@!h@C+h! k1k0-h@$ k\h@k1k0-+$ h@C+h!
i h@!h@C+h!
kkf h@!h@C+h!
kLf h@!h@C+h!
k:k0- h@!h@C+h!
k=f h@!h@C+h!
kJf h@!h@C+h!
However, at the end, you can write a normal Forth program as follows.
In this way, the interpreter and the language are extended during the execution of the single script. $ tail bootstrap.fs
next-arg dup argv @ !
included
else
." Welcome to PlanckForth " version type
." [" runtime type ." ]" cr
copyright
." Type 'bye' to exit." cr
s" /dev/tty" included
then
; execute
Various functionalities like compile mode, immediate mode, control-flow structures, literals, variables, constants, file I/O, heap memory, etc. will be available after running bootstrap.fs.
So
is wrong. The below is correct.