4 ms·
I believe MIT Scheme compiled directly to C by intermingling switch statements and gotos to emulate its call stack. Problem was, as programs grew, compile times
by glouwbug 1y ago
I believe MIT Scheme compiled directly to C by intermingling switch statements and gotos to emulate its call stack. Problem was, as programs grew, compile times weren't linear. I gave it a shot once, it was a somewhat spiritual experience:
https://github.com/glouw/switch https://github.com/glouw/switch
- kkylin 1y agoThanks! Do you mean MIT Scheme's C backend? I've used MIT Scheme on and off for a long time and have never touched the C backend & have no idea how it works, so this is interesting. (MIT Scheme also has a native code compiler for Intel CPUs, which seems to be what most users of MIT Scheme (an admittedly small community) actually use.)
- glouwbug 1y agoIf you'd like to define the backend like this, it's the easiest way to compile to C; we're just repurposing C as a general-purpose assembler: https://glouw.com/2023/11/07/Switch.html https://glouw.com/2023/11/07/Switch.html I believe MIT-scheme took it a step further with gnu extensions which allowed you to take the address of a label like &&label, which allowed for function pointers: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
- f1shy 1y agoI think a very rudimentary implementation (which is easy to understand) is in the SICP book
- soegaard 1y agoEven MIT Scheme was used with SICP, the Scheme implementation in the book is different from MIT Scheme. MIT Scheme was for a long period one of the leading Scheme implementations. It lacks support for Apple Silicon, so it is not as popular now, as it once was. https://www.gnu.org/software/mit-scheme/ https://www.gnu.org/software/mit-scheme/
- f1shy 1y agoYes. In Apple the memory can be writable XOR executable. MIT scheme needs to write on pages that will execute, so it will trigger the MMU..
- anthk 1y agoInstall chicken scheme. Then: sudo chicken-install srfi-203 sudo chicken-install srfi-216 At ~/.csirc put: (import scheme) (import (srfi 203)) (import (srfi 216)) Now you can do nearly all the execises.
- shawn_w 1y agoI don't see anything in the manual about MIT scheme compiling to C, just to its own native code object files and some portable bytecode... https://www.gnu.org/software/mit-scheme/documentation/stable/mit-scheme-user/Compilation-Procedures.html https://www.gnu.org/software/mit-scheme/documentation/stable...
- aag 1y agoIt's there, but the documentation is weak. The release notes from long ago when that back end was released are here, and give some detail: https://share.google/xmUnDhC7lndujD7TI https://share.google/xmUnDhC7lndujD7TI