Move source code here.

This commit is contained in:
Michael Zhang 2021-12-08 00:33:28 -06:00
parent 1ff3f37eb8
commit fcd1561f7b
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
11 changed files with 265 additions and 12 deletions

5
.gitignore vendored
View file

@ -1 +1,6 @@
*.agdai
*.blg
*.pdf
/gentex
/agda.sty
/main.log

View file

@ -1,2 +0,0 @@
watch:
watchexec -e tex -- tectonic main.tex

16
Makefile Normal file
View file

@ -0,0 +1,16 @@
SOURCE_MODULES := $(shell find src/Project -name "*.agda" -exec basename {} \;)
GENERATED_TEX := $(patsubst %.agda, gentex/Project/%.tex, $(SOURCE_MODULES))
gentex/Project/%.tex: src/Project/%.agda
agda --latex-dir=gentex --latex $<
agda.sty: $(GENERATED_TEX)
cp gentex/agda.sty agda.sty
main.pdf: main.tex agda.sty
tectonic --keep-logs main.tex
watch:
watchexec -e tex -- make main.pdf
.PHONY: watch

BIN
cesk.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View file

@ -0,0 +1,3 @@
name: csci8980-project
depend: standard-library
include: ./src

View file

@ -1,22 +1,49 @@
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{agda}
\usepackage{caption}
\usepackage{catchfilebetweentags}
\usepackage{cite}
\usepackage{newunicodechar}
\usepackage{url}
\usetheme{CambridgeUS}
\usecolortheme{lily}
\setbeamercovered{transparent}
\usepackage{tikz}
\usetikzlibrary{positioning}
%Information to be included in the title page:
\title{Sample title}
\author{Anonymous}
\institute{Overleaf}
\date{2021}
\titlegraphic{
\centering
\includegraphics[width=.3\textwidth,height=.5\textheight]{cesk.png}
}
\title{First class continuations with CEK machines in Agda}
\author{Michael Zhang}
\date{}
\begin{document}
\frame{\titlepage}
\section{Primer on CESK}
\begin{frame}
\frametitle{Sample frame title}
This is some text in the first frame. This is some text in the first frame. This is some text in the first frame.
\frametitle{What is a CESK machine?}
\begin{itemize}[<+->]
\item Abstract machine for interpreters, introduced by Matthias Felleisen.
\item Stands for $C$ontrol, $E$nvironment, $S$tore, $K$ontinuation.
\item Based on Matt Might's blog post on CESK machines \cite{might-cesk}.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{How does it work?}
\begin{itemize}[<+->]
\item
\end{itemize}
\end{frame}
\begin{frame}
@ -27,16 +54,31 @@ This is some text in the first frame. This is some text in the first frame. This
\node[draw, align=left, squarednode](ceskState){
C = $\lambda x . (\lambda y . x + y)$ \\
$E$ = [] \\
$S$ = [] \\
$\kappa$ = halt
};
\node[squarednode](ceskState2)[right=of ceskState]{CESK};
\node[squarednode](ceskState2)[right=of ceskState]{CEK};
%lines
\draw[->] (ceskState.east) -- (ceskState2.west);
\end{tikzpicture}
\end{frame}
\section{Implementation}
\begin{frame}
\frametitle{Hellosu}
\include{./gentex/Project/Cesk.tex}
\end{frame}
\section{Conclusion}
\begin{frame}
\frametitle{Resources}
\bibliography{res}{}
\bibliographystyle{plain}
\end{frame}
\end{document}
% vim: set sw=2 :

21
res.bib Normal file
View file

@ -0,0 +1,21 @@
@phdthesis{
felleisen-cesk,
author = "Matthias Felleisen",
howpublished = {\url{https://www2.ccs.neu.edu/racket/pubs/dissertation-felleisen.pdf}},
}
@misc{
might-cesk,
author = "Matt Might",
title = "Writing an interpreter, CESK-style",
howpublished = {\url{https://matt.might.net/articles/cesk-machines}},
}
@misc{
source-code,
author = "Michael Zhang",
title = "First class continuations with CEK machines in Agda",
howpublished = {\url{https://git.sr.ht/~mzhang/csci8980-f21-project}},
}
@comment vim: set sw=2 :

40
src/Project/Cesk.agda Normal file
View file

@ -0,0 +1,40 @@
{-# OPTIONS --allow-incomplete-matches --allow-unsolved-metas #-}
module Project.Cesk where
open import Data.Product renaming (_,_ to ⦅_,_⦆)
open import Project.Definitions using (Aexp; Exp; Env; State; Letk; Kont; Value; Type; atomic; kont; letk; lookup; call/cc; case; mkState; halt; `; _,_; _k⇒_; _⇒_; _∋_; _·_; _∘_; _[__]; )
open import Project.Util using (_$_)
open import Project.Do using (StepResult; part; done; do-kont; do-apply)
open Aexp
open Value
open State
astep : {Γ A} Aexp Γ A Env Γ Value A
astep zero _ = zero
astep (suc c) e = suc $ astep c e
astep (` id) e = lookup e id
astep (ƛ body) e = clo body e
inject : (A : Type) Exp A State A
inject A C = mkState A C halt
step : { : Type} State StepResult
step (mkState Tc Γ (case c cz cs) E K) with astep c E , astep cs E
... | zero , _ = part $ mkState Tc Γ cz E K
... | suc n , clo {Γc} cc cloE =
part $ mkState Tc (Γc , `) cc (cloE [ ` n ]) K
step (mkState Tc Γ (C₁ · C₂) E K) =
let C₁ = astep C₁ E in
let C₂ = astep C₂ E in
do-apply C₁ C₂ K
step (mkState Tc Γ (atomic x) E K) with K
... | halt = done $ astep x E
... | kont l = part $ do-kont l $ astep x E
step (mkState Tc Γ (call/cc C) E K) =
part $ mkState ({! !} k⇒ {! !}) Γ {! !} {! !} {! !}
-- 3 + (call/cc k . k 2 + k 4)
-- (k . k 2 + k 4) (\x . 3 + x)
-- ((\x . 3 + x) 2 + (\x . 3 + x) 4)

View file

@ -0,0 +1,101 @@
module Project.Definitions where
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Nat using (; zero; suc)
open import Data.Product renaming (_,_ to _ʻ_)
open import Project.Util using (_$_)
infix 4 _∋_
infix 4 _·_
infixl 6 _,_
infixr 7 _⇒_
data Type : Set where
_⇒_ : Type Type Type
_k⇒_ : Type Type Type
` : Type
data Context : Set where
: Context
_,_ : Context Type Context
data Value : Type Set
data Env : Context Set where
: Env
_[__] : {Γ} Env Γ (A : Type) Value A Env (Γ , A)
data _∋_ : Context Type Set where
zero : {Γ A} Γ , A A
suc : {Γ A B} Γ A Γ , B A
lookup : {Γ A} Env Γ Γ A Value A
lookup ()
lookup (env [ A x ]) zero = x
lookup (env [ A x ]) (suc id) = lookup env id
data Aexp Context : Type Set
data Exp Context : Type Set
data Aexp Γ where
-- Natural numbers
zero : Aexp Γ `
suc : Aexp Γ ` Aexp Γ `
-- Functions
`_ : {A} Γ A Aexp Γ A
ƛ : {B} {A : Type} Exp (Γ , A) B Aexp Γ (A B)
data Exp Γ where
-- Atomic expressions
atomic : {A} Aexp Γ A Exp Γ A
-- Natural numbers
case : {A} Aexp Γ ` Exp Γ A Aexp Γ (` A) Exp Γ A
-- Functions
_·_ : {A B} Aexp Γ (A B) Aexp Γ A Exp Γ B
_∘_ : {A B} Aexp Γ (A k⇒ B) Exp Γ B
-- Call/cc
call/cc : { A B} Exp Γ (A B) Exp Γ
data Kont ( : Type) : Type Set
data Value where
-- Natural numbers
zero : Value `
suc : Value ` Value `
-- Functions
clo : {Γ} {A B : Type} Exp (Γ , A) B Env Γ Value (A B)
-- Call/CC
kont : { Ti Tc} Kont Tc Value (Ti k⇒ Tc)
record Letk (Tv : Type) : Set
record Letk Tv where
inductive
constructor letk
field
{Tc} : Type
Γ : Context
C : Exp (Γ , Tv) Tc
E : Env Γ
K : Kont Tc
data Kont where
halt : Kont
kont : {Tc} Letk Tc Kont Tc
-- A is the type of C
-- B is the eventual type
record State ( : Type) : Set where
constructor mkState
field
Tc : Type
Γ : Context
C : Exp Γ Tc
E : Env Γ
K : Kont Tc

21
src/Project/Do.agda Normal file
View file

@ -0,0 +1,21 @@
module Project.Do where
open import Project.Definitions using (Letk; Kont; Exp; Value; State; Type; kont; halt; letk; clo; zero; suc; mkState; `_; `; _·_; _⇒_; _,_; _[__])
open import Project.Util using (_$_)
data StepResult (A : Type) : Set where
part : State A StepResult A
done : Value A StepResult A
-- Apply the continuation to the value, resulting in a state.
do-kont : {Tv } (L : Letk Tv ) Value Tv State
do-kont {Tv} {} (letk {Tc} Γ C E k) v =
let Γ′ = Γ , Tv in
let E = E [ Tv v ] in
mkState Tc Γ′ C E k
do-apply : {A B } Value (A B) Value A Kont B StepResult
do-apply (clo {Γ} {A} {B} body e) v k =
let Γ′ = Γ , A in
let E = e [ A v ] in
part $ mkState B Γ′ body E k

6
src/Project/Util.agda Normal file
View file

@ -0,0 +1,6 @@
module Project.Util where
infixr 0 _$_
_$_ : {a b : Set} (a b) a b
f $ x = f x