Skip to content

Instantly share code, notes, and snippets.

View Abhiroop's full-sized avatar
:electron:
"Syntactic sugar causes cancer of the semicolon."

Abhiroop Sarkar Abhiroop

:electron:
"Syntactic sugar causes cancer of the semicolon."
View GitHub Profile
; Emulating cps call using LLVM Coroutines
; RUN: opt coro-cps.ll -O2 -enable-coroutines -S
define void @f(i32 %arg) {
entry:
%bar.ret.addr = alloca i32
%id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
%size = call i32 @llvm.coro.size.i32()
%alloc = call i8* @malloc(i32 %size)
%hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %alloc)
@jozefg
jozefg / closconv.lhs
Last active March 5, 2024 11:52
Tutorial on Closure Conversion and Lambda Lifting
This is my short-ish tutorial on how to implement closures in
a simple functional language: Foo.
First, some boilerplate.
> {-# LANGUAGE DeriveFunctor, TypeFamilies #-}
> import Control.Applicative
> import Control.Monad.Gen
> import Control.Monad.Writer
> import Data.Functor.Foldable