by pyinstallwoes · 4y ago · 0 comments
Because of the way pointers are used, Forth is both compiled and not compiled.
> After the fetch and store operations are redefined for the code space, the compiler, assembler, etc. are recompiled using the new definitions of fetch and store. This effectively reuses all the code of the compiler and interpreter. Then, the Forth system's code is compiled, but this version is stored in the buffer. The buffer in memory is written to disk, and ways are provided to load it temporarily into memory for testing. When the new version appears to work, it is written over the previous version.
Your quote looks like its about bootstrapping the Forth ecosystem. After writing fetch and store operations in native assembly, you can bootstrap the forth system that is logical. This is the way Chuck Moore first used Forth anyways. He had no interpreter/compiler back than, he wrote some functions to aid him circumvent assembly and make his code portable. It is genius, but I think it's still interpreted.
You can compile python to bytecode and run it in python's vm, does this mean your python code is compiled. IMHO no, it is compiled for the python vm and python vm interprets it. Same thing applies to Forth.
Forth is interpreted, even if you compile and package it in a standalone executable binary.
I think it is easier to say forth is closer to compiled. I can kind of imagine each user defined word being translated into assembly. With lisp I am speechles.
As to your speechlessness regarding compiled Lisp, here's a quick example:
CL-USER> (defun foo (n)
(+ 1 n))
FOO
CL-USER> (disassemble #'foo)
; disassembly for FOO
; Size: 35 bytes. Origin: #x53641724 ; FOO
; 24: 498B4510 MOV RAX, [R13+16] ; thread.binding-stack-pointer
; 28: 488945F8 MOV [RBP-8], RAX
; 2C: BF02000000 MOV EDI, 2
; 31: 488BD3 MOV RDX, RBX
; 34: FF14250001A052 CALL QWORD PTR [#x52A00100] ; SB-VM::GENERIC-+
; 3B: 488B5DF0 MOV RBX, [RBP-16]
; 3F: 488BE5 MOV RSP, RBP
; 42: F8 CLC
; 43: 5D POP RBP
; 44: C3 RET
; 45: CC10 INT3 16 ; Invalid argument count trap
NIL
CL-USER>
(SBCL was used for the above)