Live data from Hacker News

Show HN: PlanckForth – Bootstrapping an interpreter from handwritten 1kb binary

github.com

11–20 of 20 posts

Re: Show HN: PlanckForth – Bootstrapping an interpreter from handwritten 1kb binary

#13
post #9
post #7

@nineties, I'm curious why you included things like 'mul', 'divmod', 'and', 'or' in the initial instruction set? These can all be composed, so would make your initial ELF binary a bit smaller.

I’d bet it was just because those are easy; there is a machine instruction to compute them. Might as well use it and have one less subroutine to define later.

Thank you db48x. Yes, that's the reason. I added them to the first dictionary since these instructions are very simple even when writing in machine language.

In case of mod and divmod, implementing them with add, sub and loop has a serious performance issue. Replacing it with shift operations, bit operations, add, sub and loops could be an option.

Re: Show HN: PlanckForth – Bootstrapping an interpreter from handwritten 1kb binary

#14
post #10

bootstrap.fs is a thing of beauty https://github.com/nineties/planckforth/blob/main/bootstrap.... It starts off looking like line noise (the very simple interpreter defined in hex) and gradually turns into the forth we know and love. Fantastic!

I love that the first thing added is support for comments, followed by a comment explaining that we just added comments and how it did so.

"Before I can explain anything, I have to implement the ability to explain things and then explain that I just added the ability to explain things."

Re: Show HN: PlanckForth – Bootstrapping an interpreter from handwritten 1kb binary

#17

Does the "metacircular" part just mean that the compiler can use definitions it's already compiled in the current pass?

No, it more or less means that a language is described in (part of) the language itself. And before you ask, no, it's not quite the same as self-hosting (good question though). The latter is more associated with compilers that can take a source file and produce another compiler. The former is often more like an interpreter that provides support for part of a language, but those part are enough to define support for the rest of the language.

So in this case, the base implementation starts with support for only a subset of the Forth language, picked for being either essential or much more performant when implemented "natively" in the binary. A subset of this subset is then used to construct support for the rest of the language. This is very typical for Forth- and Lisp-like languages.

[0] https://en.wikipedia.org/wiki/Meta-circular_evaluator

[1] https://en.wikipedia.org/wiki/Self-hosting_(compilers)

Re: Show HN: PlanckForth – Bootstrapping an interpreter from handwritten 1kb binary

#18
Sorry. I found a bug in the *Hello World* program I posted above. The Q operation requires an integer argument, an exit status.

So

    kHtketkltkltkotk tkWtkotkrtkltkdtk!tk:k0-tQ
is wrong. The below is correct.

    kHtketkltkltkotk tkWtkotkrtkltkdtk!tk:k0-tk0k0-Q

Re: Show HN: PlanckForth – Bootstrapping an interpreter from handwritten 1kb binary

#19

Does the "metacircular" part just mean that the compiler can use definitions it's already compiled in the current pass?

No, it more or less means that a language is described in (part of) the language itself. And before you ask, no, it's not quite the same as self-hosting (good question though). The latter is more associated with compilers that can take a source file and produce another compiler. The former is often more like an interpreter that provides support for part of a language, but those part are enough to define support for t…

It would be more accurate to describe a metacompiler as a cross compiler to the machine an interpreted Forth is implemented on.

I recommend Moving Forth [1] for the full explanation. (That's the part that addresses metacompliers, the rest is still quite a great book.)

[1] https://www.bradrodriguez.com/papers/moving4.htm

Re: Show HN: PlanckForth – Bootstrapping an interpreter from handwritten 1kb binary

#20
post #10

bootstrap.fs is a thing of beauty https://github.com/nineties/planckforth/blob/main/bootstrap.... It starts off looking like line noise (the very simple interpreter defined in hex) and gradually turns into the forth we know and love. Fantastic!

I love that the first thing added is support for comments, followed by a comment explaining that we just added comments and how it did so. "Before I can explain anything, I have to implement the ability to explain things and then explain that I just added the ability to explain things."

It is most certainly inspired, in style, by JonesForth [1] which is a classic moment in the "Programming Pedagogy Hall of Fame."

[1] https://github.com/nornagon/jonesforth/blob/master/jonesfort...

[2] https://github.com/nornagon/jonesforth/blob/master/jonesfort...

Post reply on HN