Skip to content

Instantly share code, notes, and snippets.

View shhyou's full-sized avatar
💭
Alive

shuhung shhyou

💭
Alive
View GitHub Profile
@shhyou
shhyou / CPSTrans.hs
Last active January 1, 2016 00:18
CPS transformation, typed in Haskell
{-# LANGUAGE GADTs, FlexibleContexts #-}
module CPSTrans where
import Control.Monad
import Control.Monad.Identity
import Control.Monad.State
import Control.Applicative hiding (Const)
data Expr where
@shhyou
shhyou / Makefile
Created December 23, 2013 14:11
compiler13hw-root-makefile
AOUT = parser
ifeq ($(findstring $(OS), Windows_NT), Windows_NT)
export EXE := .exe
unam := $(shell uname 2>&1)
HOST_OS := unknown
ifeq ($(findstring MINGW, $(unam)), MINGW)
HOST_OS := mingw
@shhyou
shhyou / lamint.cpp
Created December 23, 2013 15:44
A badly-written memory-leaking lambda calculus interpreter in C++
#include<cstdio>
#include<map>
#include<string>
#include<functional>
#include<stdexcept>
#include<memory>
using std::map;
using std::string;
using std::function;
@shhyou
shhyou / idris-printf.idr
Last active January 2, 2016 12:09
Idris printf test
module Main
(>>) : Monad m => m a -> m b -> m b
(>>) m1 m2 = m1 >>= \_ => m2
data Fmt : Type where
FmtInt : Fmt
FmtDbl : Fmt
FmtStr : Fmt
FmtIgn : (x : Char) -> Fmt
@shhyou
shhyou / gist:8318357
Last active January 2, 2016 14:39
Cannot load dynamic library on Windows
____ __ _
/ _/___/ /____(_)____
/ // __ / ___/ / ___/ Version 0.9.10.1
_/ // /_/ / / / (__ ) http://www.idris-lang.org/
/___/\__,_/_/ /_/____/ Type :? for help
Idris> :dynamic msvcrt.dll
0?!D)brary: invalid argument (~
Idris> :dynamic msvcrt
Idris>
@shhyou
shhyou / cps-with-if.ss
Last active January 3, 2016 03:29
cps with if
(load "match-case-simple.ss")
(define operators '(+ - * /))
(define fresh
(let ([cnt 0])
(lambda (s)
(set! cnt (+ cnt 1))
(string->symbol (string-append s (number->string cnt))))))
@shhyou
shhyou / scoped-type-var.idr
Last active January 4, 2016 09:19
Scoped type variables in Idris
module Test
ap1 : (a, b : Type) -> (a -> b) -> a -> b
ap1 a b f x = f (apply id x)
where apply : (b -> b) -> b -> b
apply g y = g (g (g y))
ap2 : (a, b : Type) -> (a -> b) -> a -> b
ap2 a b f x = f (apply id x)
where apply : (a -> a) -> a -> a
global _start
[BITS 32]
_start:
mov ecx, 20000000
call _func
_func:
pop eax
sub esp, 4
dec ecx
jz .exit
global _start
[BITS 32]
_start:
mov ecx, 10000000
_loop:
call _func
loop _loop
finish:
xor eax,eax
xor ebx,ebx
global _start
[BITS 32]
_start:
xor eax,eax
call _func
mov ecx, 200
_loop:
mov eax, 100000
call _func
loop _loop