Permalink
Browse files

Changing naming of "Atomic" to "Simple."

The use of the name "Atomic" for simple, non-composite expressions was
similar to the "atom" datatype in Clojure. All instances of "Atomic"
have been replaced with "Simple."

This is a simple renaming change that should be backwrads compatible
for all programs using the "ctco" macro.
  • Loading branch information...
1 parent c9704c3 commit 7606a9a7fb5b3d4aaf270123c0a6a76c31928416 @cjfrisz committed Aug 27, 2012
View
@@ -11,3 +11,7 @@ classes/
# Target directory (why did this suddenly appear?)
target/
+
+# pom files created by deploying jars
+pom.xml
+pom.xml.asc
View
@@ -3,14 +3,16 @@
;; Written by Chris Frisz
;;
;; Created 4 Feb 2012
-;; Last modified 18 Aug 2012
+;; Last modified 21 Aug 2012
;;
;; Project declaration for clojure-tco.
;;----------------------------------------------------------------------
(defproject ctco "0.2.1"
:description "Improving Clojure's support for constant-space tail calls."
- :url "https://github.com/cjfrisz/clojure-tco.git"
+ :url "https://github.com/cjfrisz/clojure-tco"
+ :license {:name "The MIT License"
+ :url "http://opensource.org/licenses/MIT"}
:dependencies [[org.clojure/clojure
"1.5.0-alpha3"]
[org.clojure/core.match
View
@@ -3,7 +3,7 @@
;; Written by Chris Frisz
;;
;; Created 11 Apr 2012
-;; Last modified 17 Aug 2012
+;; Last modified 21 Aug 2012
;;
;; Defines the ctco macro which acts as the driver for the Clojure TCO
;; compiler. The macro parses the initial expression, and applies the
@@ -16,18 +16,15 @@
;;----------------------------------------------------------------------
(ns ctco.core
- (:require [ctco.expr
- [cont defn fn]]
+ (:require #_[ctco.expr [cont defn]]
[ctco.mini-passes :as mp]
[ctco.parse :as parse]
[ctco.protocol :as proto]
[ctco.util :as util])
(:import [ctco.expr.cont
Cont AppContAbs]
[ctco.expr.defn
- Defn]
- [ctco.expr.fn
- Fn]))
+ Defn]))
(defmacro ctco
"Entry-point for the TCO compiler. Takes a Clojure expression and
@@ -51,14 +48,14 @@
(wrap-expr [expr]
(if (instance? Defn expr)
expr
- (let [k (util/new-var 'k)
- app (AppContAbs. apply-k k expr)]
- (Cont. k app))))]
- (proto/emit (-> (parse/parse expr)
- apply-cps
- (proto/abstract-k apply-k)
- proto/thunkify
- wrap-expr
- (mp/overload tramp)
- (mp/make-apply-k apply-k)
- (mp/make-trampoline tramp))))))
+ (let [k (util/new-var 'k)]
+ (Cont. k (AppContAbs. apply-k k expr)))))]
+ (-> (parse/parse expr)
+ apply-cps
+ (proto/abstract-k apply-k)
+ proto/thunkify
+ wrap-expr
+ (mp/overload tramp)
+ (mp/make-apply-k apply-k)
+ (mp/make-trampoline tramp)
+ proto/emit))))
@@ -3,11 +3,11 @@
;; Written by Chris Frisz
;;
;; Created 4 Apr 2012
-;; Last modified 26 Apr 2012
+;; Last modified 21 Aug 2012
;;
;; Defines the Defn record type for 'defn' expressions in the TCO
;; compiler. It supports multiple arity definitions and represents
-;; them as a vector of Fn records.
+;; them as a vector of FnBody records.
;;
;; Defn implements the following protocols:
;;
@@ -37,7 +37,7 @@
fn thunk]
[ctco.protocol :as proto])
(:import [ctco.expr.fn
- Fn]
+ FnBody]
[ctco.expr.thunk
Thunk]))
View
@@ -3,16 +3,16 @@
;; Written by Chris Frisz
;;
;; Created 30 Mar 2012
-;; Last modified 26 Apr 2012
+;; Last modified 21 Aug 2012
;;
-;; Defines the Fn record type for representing 'fn' expressions in the
+;; Defines the FnBody record type for representing 'fn' expressions in the
;; Clojure TCO compiler.
;;
;; It implements the following protocols:
;;
;; PAbstractK:
;; Recursively applies abstract-k to the body expression,
-;; returning a new Fn record.
+;; returning a new FnBody record.
;;
;; PEmit:
;; Emits (recursively) the syntax for the expression as
@@ -24,7 +24,7 @@
;; additional 'k' argument for the continuation.
;;
;; PThunkify:
-;; Simply calls thunkify on the body and returns a new Fn
+;; Simply calls thunkify on the body and returns a new FnBody
;; record with that body value.
;;----------------------------------------------------------------------
@@ -38,11 +38,11 @@
[ctco.expr.thunk
Thunk]))
-(defrecord Fn [fml* body]
+(defrecord FnBody [fml* body]
proto/PAbstractK
(abstract-k [this app-k]
(let [BODY (proto/abstract-k (:body this) app-k)]
- (Fn. (:fml* this) BODY)))
+ (FnBody. (:fml* this) BODY)))
proto/PEmit
(emit [this]
@@ -57,9 +57,9 @@
BODY (condp extends? (type (:body this))
proto/PCpsTriv (AppCont. k (proto/cps-triv body))
proto/PCpsSrs (proto/cps-srs body k))]
- (Fn. FML* BODY))))
+ (FnBody. FML* BODY))))
proto/PThunkify
(thunkify [this]
(let [BODY (proto/thunkify (:body this))]
- (Fn. (:fml* this) BODY))))
+ (FnBody. (:fml* this) BODY))))
@@ -1,32 +1,32 @@
;;----------------------------------------------------------------------
-;; File atomic.clj
+;; File simple.clj
;; Written by Chris Frisz
;;
;; Created 30 Mar 2012
-;; Last modified 26 Apr 2012
+;; Last modified 26 Aug 2012
;;
-;; Defines the Atomic record type for atomic expressions (e.g.
+;; Defines the Simple record type for simple expressions (e.g.
;; numbers, booleans, symbols, etc.) in the CTCO compiler.
;;
;; It implements the following records:
;;
;; PAbstractK:
-;; Simply returns the Atomic.
+;; Simply returns the Simple.
;;
;; PCpsTriv:
-;; Simply returns the Atomic.
+;; Simply returns the Simple.
;;
;; PEmit:
-;; Returns the syntax for the Atomic.
+;; Returns the syntax for the Simple.
;;
;; PThunkify:
-;; Simply returns the Atomic.
+;; Simply returns the Simple.
;;----------------------------------------------------------------------
-(ns ctco.expr.atomic
+(ns ctco.expr.simple
(:require [ctco.protocol :as proto]))
-(defrecord Atomic [val]
+(defrecord Simple [val]
proto/PAbstractK
(abstract-k [this _] this)
@@ -3,7 +3,7 @@
;; Written by Chris Frisz
;;
;; Created 4 Apr 2012
-;; Last modified 26 Apr 2012
+;; Last modified 21 Aug 2012
;;
;; Defines the Thunk record type for representing thunks (functions of
;; zero arguments) in the Clojure TCO compiler. These are used to
@@ -18,8 +18,8 @@
;;
;; PEmit:
;; Emits (recursively) the syntax for the expression as
-;; `(fn [] ~body), using anonymous 'fn' expressions to
-;; represent thunks.
+;; `(with-meta (fn [] ~body) {:thunk true}), using
+;; anonymous 'fn' expressions to represent thunks.
;;----------------------------------------------------------------------
(ns ctco.expr.thunk
@@ -34,4 +34,4 @@
proto/PEmit
(emit [this]
(let [BODY (proto/emit (:body this))]
- `(with-meta (fn [] ~BODY) {:thunk true}))))
+ `(with-meta (fn [] ~BODY) {:thunk true}))))
@@ -3,7 +3,7 @@
;; Written by Chris Frisz
;;
;; Created 14 Apr 2012
-;; Last modified 15 Jul 2012
+;; Last modified 26 Aug 2012
;;
;; Defines the small, one-time code transformations for the TCO
;; compiler. These include the following:
@@ -14,14 +14,14 @@
(ns ctco.mini-passes
(:require [ctco.expr
- app atomic fn defn do if let recur simple-op]
+ app simple fn defn do if let recur simple-op]
[ctco.util :as util])
(:import [ctco.expr.app
App]
- [ctco.expr.atomic
- Atomic]
+ [ctco.expr.simple
+ Simple]
[ctco.expr.fn
- Fn]
+ FnBody]
[ctco.expr.defn
Defn]
[ctco.expr.do
@@ -57,10 +57,10 @@
(if (instance? Defn expr)
(let [fml* (:fml* (first (:func* expr)))
fml-bl* (vec (butlast fml*))
- rand* (conj fml-bl* (Atomic. 'nil))
+ rand* (conj fml-bl* (Simple. 'nil))
init-call (App. (:name expr) rand*)
tramp-call (App. tramp [init-call])
- func* (vec (cons (Fn. fml-bl* tramp-call) (:func* expr)))]
+ func* (vec (cons (FnBody. fml-bl* tramp-call) (:func* expr)))]
(Defn. (:name expr) func*))
expr))
@@ -76,7 +76,7 @@
(let [test (SimpleOpCps. 'fn? [kont])
conseq (App. kont [arg])
body (IfCps. test conseq arg)
- init (Fn. [kont arg] body)
+ init (FnBody. [kont arg] body)
bind* [apply-k init]]
(LetCps. bind* expr))))
@@ -88,8 +88,8 @@
expression is emitted."
[expr tramp]
(let [thunk (util/new-var 'thunk)
- test (SimpleOpCps. 'get [(SimpleOpCps. 'meta [thunk]) (Atomic. :thunk)])
+ test (SimpleOpCps. 'get [(SimpleOpCps. 'meta [thunk]) (Simple. :thunk)])
conseq (Recur. [(App. thunk [])])
body (IfCps. test conseq thunk)
- init (Fn. [thunk] body)]
+ init (FnBody. [thunk] body)]
(LetCps. [tramp init] expr)))
View
@@ -3,7 +3,7 @@
;; Written by Chris Frisz
;;
;; Created 10 Apr 2012
-;; Last modified 18 Aug 2012
+;; Last modified 26 Aug 2012
;;
;; Defines the parser for the Clojure TCO compiler.
;;----------------------------------------------------------------------
@@ -12,17 +12,17 @@
(:use [clojure.core.match
:only (match)])
(:require [ctco.expr
- app atomic defn fn if let simple-op]
+ app simple defn fn if let simple-op]
[ctco.protocol :as proto]
[ctco.util :as util])
(:import [ctco.expr.app
App]
- [ctco.expr.atomic
- Atomic]
+ [ctco.expr.simple
+ Simple]
[ctco.expr.defn
Defn]
[ctco.expr.fn
- Fn]
+ FnBody]
[ctco.expr.if
IfCps IfSrs IfTriv]
[ctco.expr.let
@@ -39,16 +39,16 @@
records."
[expr]
(match [expr]
- [nil] (Atomic. nil)
- [(:or true false)] (Atomic. expr)
- [(n :guard number?)] (Atomic. n)
- [(['quote s] :seq)] (Atomic. `(quote ~s))
- [(v :guard symbol?)] (Atomic. v)
- [(s :guard string?)] (Atomic. s)
- [(k :guard keyword?)] (Atomic. k)
+ [nil] (Simple. nil)
+ [(:or true false)] (Simple. expr)
+ [(n :guard number?)] (Simple. n)
+ [(['quote s] :seq)] (Simple. `(quote ~s))
+ [(v :guard symbol?)] (Simple. v)
+ [(s :guard string?)] (Simple. s)
+ [(k :guard keyword?)] (Simple. k)
[(['fn fml* body] :seq)] (parse-fn fml* body)
- [(['defn name (fml* :guard vector?) body] :seq)] (let [func* `((~fml* ~body))]
- (parse-defn name func*))
+ [(['defn name (fml* :guard vector?) body] :seq)] (parse-defn name
+ `((~fml* ~body)))
[(['defn name & func*] :seq)] (parse-defn name func*)
[(['if test conseq alt] :seq)] (parse-if test conseq alt)
[(['cond & clause*] :seq)] (parse-cond clause*)
@@ -60,10 +60,7 @@
(defn- parse-fn
"Helper function for parse that handles 'fn' expressions."
[fml* body]
- (let [FML* (map parse fml*)
- FML* (into [] FML*)
- BODY (parse body)]
- (Fn. FML* BODY)))
+ (FnBody. (vec (map parse fml*)) (parse body)))
(defn- parse-defn
"Helper function for parse that handles 'defn' expression."
@@ -75,7 +72,7 @@
body (first (nfirst func*))
func (parse-fn fml* body)]
(recur (next func*) (conj out* func)))))]
- (let [NAME (Atomic. name)
+ (let [NAME (Simple. name)
FUNC* (parse-func* func* [])]
(Defn. NAME FUNC*))))
@@ -103,7 +100,7 @@
(IfTriv. test conseq rst))
RCLAUSE* (nnext rclause*)]
(recur RCLAUSE* RST))))]
- (parse-rclause* (reverse clause*) (Atomic. nil))))
+ (parse-rclause* (reverse clause*) (Simple. nil))))
(defn- parse-let
"Helper function for parse that handles 'let' expressions."
@@ -127,7 +124,6 @@
(defn- parse-app
"Helper function for parse that handles application."
[rator rand*]
- (let [RATOR (parse rator)
- RAND* (vec (map parse rand*))]
- (App. RATOR RAND*)))
+ (App. (parse rator) (vec (map parse rand*))))
+
Oops, something went wrong. Retry.

0 comments on commit 7606a9a

Please sign in to comment.