├── coq ├── #basic.v# ├── #Lvl1.v# ├── Cases.v ├── Term.v ├── README ├── Util.v ├── Subs.v ├── TermFaithful.v ├── Unify.v ├── Macro.v └── Env.v ├── .gitignore ├── prototype ├── utility.rkt ├── demo.rkt ├── lang-min-macros-cps.rkt ├── misc │ ├── stepper-approach-4.rkt │ ├── stepper-approach-1.rkt │ ├── stepper-approach-3.rkt │ └── stepper-approach-2.rkt ├── performance.txt ├── lang-min-macros-church.rkt ├── resugar-redex.rkt ├── resugar.rkt ├── r6rs-macros.scm ├── lang-min-macros.rkt ├── r6rs-macros.rkt ├── macro.rkt ├── lang-min.rkt └── tests.rkt ├── confection ├── Makefile ├── test.grammar ├── README.md ├── Main.hs ├── Grammar.hs ├── Parse.hs ├── Show.hs ├── Test.hs └── Pattern.hs ├── racket ├── grammar.rkt ├── benchmark.txt ├── benchmark.rkt ├── demo.rkt ├── term.rkt ├── racket.grammar ├── test-racket-stepper.rkt ├── utility.rkt └── convert.rkt └── README /coq/#basic.v#: -------------------------------------------------------------------------------- 1 | Require Import Util. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.vo 2 | *.glob 3 | *.v.d 4 | *~ 5 | *.hi 6 | *.o -------------------------------------------------------------------------------- /prototype/utility.rkt: -------------------------------------------------------------------------------- 1 | (module utility racket 2 | (provide (all-from-out "../racket/utility.rkt")) 3 | (require "../racket/utility.rkt")) -------------------------------------------------------------------------------- /confection/Makefile: -------------------------------------------------------------------------------- 1 | 2 | build: 3 | ghc -fwarn-incomplete-patterns --make Main.hs -o Confection 4 | 5 | test: 6 | ghc -fwarn-incomplete-patterns --make Test.hs -o Test 7 | ./Test 8 | -------------------------------------------------------------------------------- /racket/grammar.rkt: -------------------------------------------------------------------------------- 1 | #lang ragg 2 | 3 | term: (node | list | STRING) [tags] 4 | node: LABEL "(" terms ")" 5 | list: "[" terms "]" 6 | terms: [ term ("," term)* ] 7 | 8 | tags: "{" "[" tag ("," tag)* "]" "}" 9 | tag: "Head" "(" LABEL "," NUMBER "," term ")" 10 | | "Body" | "Alien" | "!Body" -------------------------------------------------------------------------------- /confection/test.grammar: -------------------------------------------------------------------------------- 1 | core 2 | values 3 | CNum : Int -> Expr; 4 | constructors 5 | Plus : Expr * Expr -> Expr; 6 | surface 7 | values 8 | SNum : Int -> Expr; 9 | constructors 10 | Inc : Expr -> Expr; 11 | rules 12 | Inc(n) -> Plus(n, CNum(1)); 13 | SNum(n) -> CNum(n) fresh unused; 14 | -------------------------------------------------------------------------------- /racket/benchmark.txt: -------------------------------------------------------------------------------- 1 | Native results from benchmark.rkt: 2 | 3 | 4 | WITH RESUGARING: 5 | 6 | Big-stack factorial: 7 | cpu time: 420 real time: 465 gc time: 120 8 | 9 | Small-stack factorial: 10 | cpu time: 332 real time: 336 gc time: 68 11 | 12 | 13 | WITHOUT RESUGARING: 14 | 15 | Big-stack factorial: 16 | cpu time: 376 real time: 375 gc time: 136 17 | ratio: 112% 18 | 19 | Small-stack factorial: 20 | cpu time: 296 real time: 300 gc time: 48 21 | ratio: 112% 22 | -------------------------------------------------------------------------------- /coq/#Lvl1.v#: -------------------------------------------------------------------------------- 1 | Require Import Util. 2 | Require Import Coq.Arith.EqNat. 3 | 4 | Definition vid := nat. 5 | Definition nid := nat. 6 | 7 | Inductive term := 8 | | var : vid -> term 9 | | node : nid -> list term -> term. 10 | 11 | Inductive macro := 12 | | transf : term -> term -> macro. 13 | 14 | Inductive env := 15 | | mtEnv : env 16 | | bind : vid -> term -> env -> env. 17 | 18 | Fixpoint lookup (v : vid) (e : env) : option term := 19 | match e with 20 | | mtEnv => None 21 | | bind v' t e => 22 | if beq_nat v v' 23 | then Some t 24 | else lookup v e 25 | end. 26 | 27 | Fixpoint subs (e : env) (t : term) : option term := 28 | match t with 29 | | var v => lookup v e 30 | | node l ts => -------------------------------------------------------------------------------- /confection/README.md: -------------------------------------------------------------------------------- 1 | # Confection # 2 | 3 | Usage: Resugarer grammar-file 4 | 5 | Begins an interactive session. 6 | 7 | Commands: 8 | 9 | * `desugar *term*` 10 | * `resugar *term*` 11 | 12 | Responses: 13 | 14 | * `success: *term*` 15 | * `failure: *message*` 16 | * `error: *message*` 17 | 18 | * Failure indicates that a resugaring failed for benign reasons. 19 | * Error indicates that something went wrong, 20 | probably because of a malformed input term. 21 | * Messages are free-form strings for human reading. 22 | 23 | 24 | `term`s have the following grammar (a subset of Stratego ATerm grammar): 25 | 26 | term ::= | | 27 | |