Skip to content

Commit

Permalink
Exposing 'recur' as a top-level CTCO expression.
Browse files Browse the repository at this point in the history
Updating the parser to accept the 'recur' form, adding unrecurify to
the list of passes performed by the ctco macro, and correcting a bug
in the implementation of load-tramp for the Recur record.
  • Loading branch information
cjfrisz committed Oct 19, 2012
1 parent eb10ccc commit b93f0bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/ctco/core.clj
Expand Up @@ -37,6 +37,7 @@
proto/PCpsSrs (proto/cps-srs expr (gensym "k"))
:else (throw (Exception. (str "unexpected expression " expr)))))]
(let [new-expr (-> (parse/parse expr)
(proto/unrecurify nil)
apply-cps
proto/thunkify
(proto/load-tramp tramp)
Expand Down
9 changes: 6 additions & 3 deletions src/ctco/expr/recur.clj
Expand Up @@ -3,7 +3,7 @@
;; Written by Chris Frisz
;;
;; Created 16 Apr 2012
;; Last modified 14 Oct 2012
;; Last modified 19 Oct 2012
;;
;; Defines the Recur record type and operations for representing
;; 'recur' expressions in the Clojure TCO compiler.
Expand All @@ -28,12 +28,15 @@
;;----------------------------------------------------------------------

(ns ctco.expr.recur
(:require [ctco.protocol :as proto]))
(:require [ctco.expr.app]
[ctco.protocol :as proto])
(:import [ctco.expr.app
App]))

(defrecord Recur [arg*]
proto/PLoadTrampoline
(load-tramp [this tramp]
(proto/walk-expr this f nil))
(proto/walk-expr this #(proto/load-tramp % tramp) nil))

proto/PUnparse
(unparse [this]
Expand Down
14 changes: 11 additions & 3 deletions src/ctco/parse.clj
Expand Up @@ -12,13 +12,11 @@
(:use [clojure.core.match
:only (match)])
(:require [ctco.expr
app simple def fn if let simple-op]
app def fn if let recur simple simple-op]
[ctco.protocol :as proto]
[ctco.util :as util])
(:import [ctco.expr.app
App]
[ctco.expr.simple
Simple]
[ctco.expr.def
DefSrs DefTriv]
[ctco.expr.fn
Expand All @@ -27,6 +25,10 @@
IfCps IfSrs IfTriv]
[ctco.expr.let
LetCps LetSrs LetTriv]
[ctco.expr.recur
Recur]
[ctco.expr.simple
Simple]
[ctco.expr.simple_op
SimpleOpCps SimpleOpSrs SimpleOpTriv]))

Expand Down Expand Up @@ -96,6 +98,11 @@
(LetSrs. BIND* BODY)
(LetTriv. BIND* BODY))))

(defn- parse-recur
"Helper function for parse that handles 'recur' expressions."
[expr*]
(Recur. (mapv parse expr*)))

(defn- parse-core
"Takes a sequence representing a Clojure expression (generally passed from a
macro) and returns the parsed representation of the expression if it is a core
Expand All @@ -111,6 +118,7 @@
[(['fn (name :guard symbol?) & body*] :seq)] (parse-fn name body*)
[(['if test conseq alt] :seq)] (parse-if test conseq alt)
[(['let bind* body] :seq)] (parse-let bind* body)
[(['recur & expr*] :seq)] (parse-recur expr*)
:else false))

(defn- parse-defn
Expand Down

0 comments on commit b93f0bb

Please sign in to comment.