News for hackers. Stuff that matters.
Re:Show HN: Compiler Fundamentals – Closure Conversion by rain1 on Saturday February 16, 2019 @05:13AM (#19178006)
I took the essence of closure conversion and implemented it as a single file racket script with explanation in comments and examples.

The idea is that this should help someone if they are a beginner wanting to implement a language that has lambda. Or anybody who is curious how a compiler might implement lambda.

Re:Show HN: Compiler Fundamentals – Closure Conversion by tinco on Saturday February 16, 2019 @08:27PM (#19182051)
Lisps look so magical. I wish it were more accepted in the web application industry to pick a lisps for implementing services. I love my Ruby, and my Go, but it would be fun to experiment with a lisp some time.
Re:Show HN: Compiler Fundamentals – Closure Conversion by blevs on Saturday February 16, 2019 @10:41PM (#19182556)
Clojure and Clojurescript are both amazing. If you have the time they are absolutely worth playing around with.
Re:Show HN: Compiler Fundamentals – Closure Conversion by sinistersnare on Saturday February 16, 2019 @05:53PM (#19181450)
I also made a closure converting pass to my compiler (in racket also!)

Here's mine: https://github.com/sinistersnare/SinScheme/blob/master/src/r...

Re:Show HN: Compiler Fundamentals – Closure Conversion by abecedarius on Saturday February 16, 2019 @11:02PM (#19182611)
Yet another: this is the whole compiler, but for a simpler language and target. https://github.com/darius/squeam/blob/master/eg/lambdacompil...

It's in my own Scheme variant, I'm afraid. I guess I should translate it to something people know. But, for example

    ;; Variable reference
    (to (var-ref<- v)
      (make ({.free-vars} (set<- v))
            ({.compile s k} (cons (s v) k))))
turns a source-code variable access into an AST object with two methods: 1. The free-variable set of this AST has just that one variable. 2. To compile this to bytecode, given a scope s and following code k, ask the scope what instruction to emit for this variable, and prepend that to k. (In general k is passed in for the sake of tail-call optimization, on line 33.)
Re:Show HN: Compiler Fundamentals – Closure Conversion by rurban on Monday February 18, 2019 @12:40PM (#19192450)
Re:Show HN: Compiler Fundamentals – Closure Conversion by disconcision on Monday February 18, 2019 @12:25AM (#19188806)
this is just a tiny nitpick but I'm wondering why you didn't use pattern matching? if you just wanted to stay schemey then disregard but you could skip the entire shapes section and the rest of the code would still be terser, e.g.

    ((begin? exp)
    `(begin . ,(mapply cc (cdr exp) sc)))
would become

    [`(begin ,xs ...)
     `(begin ,@(mapply cc xs sc))]
or if you're feeling fancy

    (define cc-sc (curryr cc sc))

    [`(begin ,(app cc-sc xs) ...) `(begin ,@xs)]