This just made my day. I'm the author of Scheme for Max, an extension to the Max music programming environment that puts the s7 Scheme interpreter in it for scripting note-event level code (not dsp). It would be fantastic to also be able to use a subset of Scheme for generating DSP level code, where speed would be more important than dynamic typing or continuations/tco/etc. I will be watching this closely!
what do you think about pre-scheme?
Crunch – a Scheme compiler with a minimal runtime
31–40 of 73 posts
Re: Crunch – a Scheme compiler with a minimal runtime
#32For Common Lispers such as myself, who are vaguely aware of developments in the Scheme space: the most important difference between CRUNCH and Chicken appears to be that, while both compile down to C/object code, CRUNCH is additionally targeting a statically-typed subset of Scheme. Opinion: this is great. The aversion of Lispers to static types is historical rather than intrinsic and reflects the relative difference…
What are the main differences between OcamML and a statically typed Lisp?
To be honest, I'd kill for a Lisp that had the same type system as OCaml, but I suspect the closes we'll get is basically Rust (whose macro system is quite good).
Re: Crunch – a Scheme compiler with a minimal runtime
#33The very first rudimentary standalone example: (define (main) (display "Hello world\n")) Doesn't compile, but instead gives error: Error: main: global variable `scheme#display' has unknown type
(import (chicken bitwise) (chicken fixnum))
(define (popcount32 x) ; From "Hacker's Delight"
; (assume
(let ((x (fx- x (bitwise-and (arithmetic-shift x -1) #x55555555))))
(let ((x (fx+ (bitwise-and x #x33333333)
(bitwise-and (arithmetic-shift x -2) #x33333333))))
(let ((x (bitwise-and (fx+ x (arithmetic-shift x -4)) #x0F0F0F0F)))
(let ((x (fx+ x (arithmetic-shift x -8))))
(let ((x (fx+ x (arithmetic-shift x -16))))
(bitwise-and x #x0000003F)))))))
Turns into somewhat redundant C, looks much like transliterated bytecode, e.g. long v17 = 0;
// ...
// popcnt.scm:7
v17 = 0;
// ...
// popcnt.scm:7
v17 = (t37 & 252645135);
// popcount32
// popcnt.scm:8
t40 = crunch_arithmetic_shift(v17, -8);
Interesting find in the (small) crunch.h is #ifdef CRUNCH_FREESTANDING
#include
#include
#include
#include "crunch-environment.h"
#else
// loads of stuff
though I haven't found crunch-environment.h in the source yetRe: Crunch – a Scheme compiler with a minimal runtime
#34The freestanding macro suggests most of the heavy lifting is done. Stuff the GPU targets will struggle with in no particular order:
- setjmp / longjmp
- signals (if used?)
- threads
- fast alloc/free
- stack will be smaller than chicken expects
I don't know how to do signals. The rest are merely difficult.
Re: Crunch – a Scheme compiler with a minimal runtime
#35Earlier quoted context omitted.
From the article: > What is needed is a small, portable compiler that generates more or less "natural" C code with minimal dependencies and runtime system that supports at least the basic constructs of the language and that puts an emphasis on producing efficient code, even if some of the more powerful features of Scheme are not available. Since C doesn't support continuations, it is not possible to have continuation…
> Since C doesn't support continuations, it is not possible to have continuations and at the same time generate "natural" C code. Since CHICKEN actually does this, I'll add the proviso of "without a GC or costly runtime".
Regardless of what we call the style, it isn't simple any more.
For people interested in the internals of Chicken Scheme (I suspect sctb already knows):
Re: Crunch – a Scheme compiler with a minimal runtime
#36Earlier quoted context omitted.
What are the main differences between OcamML and a statically typed Lisp?
Type inference is probably the biggest thing. You would need explicit "phases" to expand macros, disallow macro expansion at runtime, and implement bi-directional type inference HM-style to get even close to what OCaml has. To be honest, I'd kill for a Lisp that had the same type system as OCaml, but I suspect the closes we'll get is basically Rust (whose macro system is quite good).
There's also the plait language which says its type system is similar to ML: https://docs.racket-lang.org/plait/index.html
And Hackett, inspired by Haskell: https://lexi-lambda.github.io/hackett/
And Common Lisp has coalton: https://coalton-lang.github.io/
Re: Crunch – a Scheme compiler with a minimal runtime
#37The very first rudimentary standalone example: (define (main) (display "Hello world\n")) Doesn't compile, but instead gives error: Error: main: global variable `scheme#display' has unknown type
The popcount example does compile, if you drop the "assume" form, (import (chicken bitwise) (chicken fixnum)) (define (popcount32 x) ; From "Hacker's Delight" ; (assume (let ((x (fx- x (bitwise-and (arithmetic-shift x -1) #x55555555)))) (let ((x (fx+ (bitwise-and x #x33333333) (bitwise-and (arithmetic-shift x -2) #x33333333)))) (let ((x (bitwise-and (fx+ x (arithmetic-shift x -4)) #x0F0F0F0F))) (let ((x (fx+ x (arith…
Re: Crunch – a Scheme compiler with a minimal runtime
#38Earlier quoted context omitted.
What are the main differences between OcamML and a statically typed Lisp?
Type inference is probably the biggest thing. You would need explicit "phases" to expand macros, disallow macro expansion at runtime, and implement bi-directional type inference HM-style to get even close to what OCaml has. To be honest, I'd kill for a Lisp that had the same type system as OCaml, but I suspect the closes we'll get is basically Rust (whose macro system is quite good).
Re: Crunch – a Scheme compiler with a minimal runtime
#39For Common Lispers such as myself, who are vaguely aware of developments in the Scheme space: the most important difference between CRUNCH and Chicken appears to be that, while both compile down to C/object code, CRUNCH is additionally targeting a statically-typed subset of Scheme. Opinion: this is great. The aversion of Lispers to static types is historical rather than intrinsic and reflects the relative difference…
What are the main differences between OcamML and a statically typed Lisp?
Re: Crunch – a Scheme compiler with a minimal runtime
#40Earlier quoted context omitted.
Type inference is probably the biggest thing. You would need explicit "phases" to expand macros, disallow macro expansion at runtime, and implement bi-directional type inference HM-style to get even close to what OCaml has. To be honest, I'd kill for a Lisp that had the same type system as OCaml, but I suspect the closes we'll get is basically Rust (whose macro system is quite good).
Racket has Typed Racket, which while not Hindley-Miller can do some type inference. There's also the plait language which says its type system is similar to ML: https://docs.racket-lang.org/plait/index.html And Hackett, inspired by Haskell: https://lexi-lambda.github.io/hackett/ And Common Lisp has coalton: https://coalton-lang.github.io/