Skip to content

Commit

Permalink
enhancements to AOT/gen-class
Browse files Browse the repository at this point in the history
AOT now only produces __init.class by default, load uses that class only
must have at least (:gen-class) ns clause to create named class for ns
gen-class can now be called stand-alone
new options allow for control of mapping to implementing namespace,
name of class, loading of implementing namespace, and method name prefix
(doc ns) and (doc gen-class) and http://clojure.org/compilation for details
  • Loading branch information
richhickey committed Nov 29, 2008
1 parent 09c2d0d commit a4f9236
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 347 deletions.
32 changes: 21 additions & 11 deletions src/clj/clojure/core.clj
Expand Up @@ -6,7 +6,7 @@
; the terms of this license.
; You must not remove this notice, or any other, from this software.

(in-ns 'clojure.core)
(ns clojure.core)

(def
#^{:arglists '([& items])
Expand Down Expand Up @@ -3081,34 +3081,43 @@
[fmt & args]
(print (apply format fmt args)))

(def gen-class)

(defmacro ns
"Sets *ns* to the namespace named by name (unevaluated), creating it
if needed. references can be zero or more of: (:refer-clojure ...)
(:require ...) (:use ...) (:import ...) (:load ...) (:gen-class)
with the syntax of refer-clojure/require/use/import/load/gen-class
respectively, except the arguments are unevaluated and need not be
quoted, and the :gen-class clause does not take a name (since the
class name corresponds to the ns name). If :refer-clojure is not
used, a default (refer 'clojure) is used. The :gen-class directive
is ignored when not compiling. If :gen-class is not specified, when
compiled the generated class will have only main. Use of ns is
preferred to individual calls to in-ns/require/use/import:
(ns foo
quoted. (:gen-class ...), when supplied, defaults to :name
corresponding to the ns name, :main true, :impl-ns same as ns, and
:init-impl-ns true. All options of gen-class are
supported. The :gen-class directive is ignored when not
compiling. If :gen-class is not supplied, when compiled only an
nsname__init.class will be generated. If :refer-clojure is not used, a
default (refer 'clojure) is used. Use of ns is preferred to
individual calls to in-ns/require/use/import:
(ns foo.bar
(:refer-clojure :exclude [ancestors printf])
(:require (clojure.contrib sql sql.tests))
(:use (my.lib this that))
(:import (java.util Date Timer Random)
(java.sql Connection Statement))
(:load \"/mystuff/foo.clj\"))"
(java.sql Connection Statement)))"

[name & references]
(let [process-reference
(fn [[kname & args]]
`(~(symbol "clojure.core" (clojure.core/name kname))
~@(map #(list 'quote %) args)))
gen-class-clause (first (filter #(= :gen-class (first %)) references))
gen-class-call
(when gen-class-clause
(list* `gen-class :name (.replace (str name) \- \_) :impl-ns name :main true (rest gen-class-clause)))
references (remove #(= :gen-class (first %)) references)]
`(do
(clojure.core/in-ns '~name)
~@(when gen-class-call (list gen-class-call))
~@(when (and (not= name 'clojure.core) (not-any? #(= :refer-clojure (first %)) references))
`((clojure.core/refer '~'clojure.core)))
~@(map process-reference references))))
Expand Down Expand Up @@ -3313,6 +3322,7 @@
:reload-all implies :reload and also forces loading of all libs that the
identified libs directly or indirectly load via require or use
:verbose triggers printing information about each load, alias, and refer"

[& args]
(apply load-libs :require args))

Expand Down

0 comments on commit a4f9236

Please sign in to comment.