public
Description: Clojure is a dynamic programming language that targets the Java Virtual Machine.
Homepage: http://clojure.org/
Clone URL: git://github.com/kevinoneill/clojure.git
AOT compiler support
breaking change to load - no longer takes extension
load will load from classfile if newer than source
to compile, source dir and compile dir must be in classpath
(compile 'my.cool.ns)
will compile my/cool/ns.clj and anything it loads directly or indirectly

git-svn-id: https://clojure.svn.sourceforge.net/svnroot/clojure/trunk@1094 
b4165764-bd0f-0410-b771-ab16a44d2305
rhickey (author)
Wed Nov 12 12:59:16 -0800 2008
commit  c4fc278f714d6911db9d7542d728036d479bb1cd
tree    acdc0626c3db3b79d1ab1557993e232db7e094b7
parent  b997c95fe841eee53a28b74bbe614ffca63166aa
...
3163
3164
3165
3166
 
3167
3168
3169
...
3171
3172
3173
3174
 
3175
3176
3177
3178
3179
3180
 
 
3181
3182
3183
...
3340
3341
3342
3343
 
 
 
 
 
3344
3345
3346
...
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
 
 
 
 
 
 
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
...
3163
3164
3165
 
3166
3167
3168
3169
...
3171
3172
3173
 
3174
3175
3176
 
 
 
 
3177
3178
3179
3180
3181
...
3338
3339
3340
 
3341
3342
3343
3344
3345
3346
3347
3348
...
3484
3485
3486
 
 
3487
 
3488
 
3489
 
 
 
 
 
 
 
 
 
3490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3491
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3492
3493
3494
3495
3496
3497
3498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -3163,7 +3163,7 @@
0
     (cons x coll)
0
     (concat x coll)))
0
 
0
-(defn- root-directory
0
+(defn- root-resource
0
   "Returns the root directory path for a lib"
0
   [lib]
0
   (str \/
0
@@ -3171,13 +3171,11 @@
0
            (replace \- \_)
0
            (replace \. \/))))
0
 
0
-(defn- root-resource
0
+(defn- root-directory
0
   "Returns the root resource path for a lib"
0
   [lib]
0
-  (let [d (root-directory lib)
0
-        i (inc (.lastIndexOf d (int \/)))
0
-        leaf (.substring d i)]
0
-    (str d \/ leaf ".clj")))
0
+  (let [d (root-resource lib)]
0
+    (subs d 0 (.lastIndexOf d "/"))))
0
 
0
 (def load)
0
 
0
@@ -3340,7 +3338,11 @@
0
                 "cannot load '%s' again while it is loading"
0
                 path)
0
       (binding [*pending-paths* (conj *pending-paths* path)]
0
-        (.loadResourceScript clojure.lang.RT (.substring path 1))))))
0
+        (clojure.lang.RT/load  (.substring path 1))))))
0
+
0
+(defn compile [lib]
0
+  (binding [*compile-files* true]
0
+    (load-one lib true true)))
0
 
0
 ;;;;;;;;;;;;; nested associative ops ;;;;;;;;;;;
0
 
0
@@ -3482,615 +3484,15 @@
0
   "defs the supplied var names with no bindings, useful for making forward declarations."
0
   [& names] `(do ~@(map #(list 'def %) names)))
0
 
0
-(defn compile [libsym]
0
-  (clojure.lang.RT/compileLib (str libsym)))
0
 
0
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; printing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0
 
0
-(import '(java.io Writer))
0
 
0
-(def
0
- #^{:doc "*print-length* controls how many items of each collection the
0
-  printer will print. If it is bound to logical false, there is no
0
-  limit. Otherwise, it must be bound to an integer indicating the maximum
0
-  number of items of each collection to print. If a collection contains
0
-  more items, the printer will print items up to the limit followed by
0
-  '...' to represent the remaining items. The root binding is nil
0
-  indicating no limit."}
0
- *print-length* nil)
0
 
0
-(def
0
- #^{:doc "*print-level* controls how many levels deep the printer will
0
-  print nested objects. If it is bound to logical false, there is no
0
-  limit. Otherwise, it must be bound to an integer indicating the maximum
0
-  level to print. Each argument to print is at level 0; if an argument is a
0
-  collection, its items are at level 1; and so on. If an object is a
0
-  collection and is at a level greater than or equal to the value bound to
0
-  *print-level*, the printer prints '#' to represent it. The root binding
0
-  is nil indicating no limit."}
0
-*print-level* nil)
0
-
0
-(defn- print-sequential [#^String begin, print-one, #^String sep, #^String end, sequence, #^Writer w]
0
-  (binding [*print-level* (and (not *print-dup*) *print-level* (dec *print-level*))]
0
-    (if (and *print-level* (neg? *print-level*))
0
-      (.write w "#")
0
-      (do
0
-        (.write w begin)
0
-        (when-let [xs (seq sequence)]
0
-          (if (and (not *print-dup*) *print-length*)
0
-            (loop [[x & xs] xs
0
-                   print-length *print-length*]
0
-              (if (zero? print-length)
0
-                (.write w "...")
0
-                (do
0
-                  (print-one x w)
0
-                  (when xs
0
-                    (.write w sep)
0
-                    (recur xs (dec print-length))))))
0
-            (loop [[x & xs] xs]
0
-              (print-one x w)
0
-              (when xs
0
-                (.write w sep)
0
-                (recur xs)))))
0
-        (.write w end)))))
0
-
0
-(defn- print-meta [o, #^Writer w]
0
-  (when-let [m (meta o)]
0
-    (when (and (pos? (count m))
0
-               (or *print-dup*
0
-                   (and *print-meta* *print-readably*)))
0
-      (.write w "#^")
0
-      (if (and (= (count m) 1) (:tag m))
0
-          (pr-on (:tag m) w)
0
-          (pr-on m w))
0
-      (.write w " "))))
0
-
0
-(defmethod print-method nil [o, #^Writer w]
0
-  (.write w "nil"))
0
-
0
-(defmethod print-dup nil [o w] (print-method o w))
0
-
0
-(defn print-ctor [o print-args #^Writer w]
0
-  (.write w "#=(")
0
-  (.write w (.getName #^Class (class o)))
0
-  (.write w ". ")
0
-  (print-args o w)
0
-  (.write w ")"))
0
-
0
-(defmethod print-method :default [o, #^Writer w]
0
-  (.write w "#<")
0
-  (.write w (.getSimpleName (class o)))
0
-  (.write w " ")
0
-  (.write w (str o))
0
-  (.write w ">"))
0
-
0
-(defmethod print-method clojure.lang.Keyword [o, #^Writer w]
0
-  (.write w (str o)))
0
-
0
-(defmethod print-dup clojure.lang.Keyword [o w] (print-method o w))
0
-
0
-(defmethod print-method Number [o, #^Writer w]
0
-  (.write w (str o)))
0
-
0
-(defmethod print-dup Number [o, #^Writer w]
0
-  (print-ctor o
0
-              (fn [o w]
0
-                  (print-dup (str o) w))
0
-              w))
0
-
0
-(defmethod print-dup clojure.lang.AFn [o, #^Writer w]
0
-  (print-ctor o (fn [o w]) w))
0
-
0
-(prefer-method print-dup clojure.lang.IPersistentCollection clojure.lang.AFn)
0
-(prefer-method print-dup java.util.Map clojure.lang.AFn)
0
-(prefer-method print-dup java.util.Collection clojure.lang.AFn)
0
-
0
-(defmethod print-method Boolean [o, #^Writer w]
0
-  (.write w (str o)))
0
-
0
-(defmethod print-dup Boolean [o w] (print-method o w))
0
-
0
-(defn print-simple [o, #^Writer w]
0
-  (print-meta o w)
0
-  (.write w (str o)))
0
-
0
-(defmethod print-method clojure.lang.Symbol [o, #^Writer w]
0
-  (print-simple o w))
0
-
0
-(defmethod print-dup clojure.lang.Symbol [o w] (print-method o w))
0
-
0
-(defmethod print-method clojure.lang.Var [o, #^Writer w]
0
-  (print-simple o w))
0
-
0
-(defmethod print-dup clojure.lang.Var [#^clojure.lang.Var o, #^Writer w]
0
-  (.write w (str "#=(var " (.name (.ns o)) "/" (.sym o) ")")))
0
-
0
-(defmethod print-method clojure.lang.ISeq [o, #^Writer w]
0
-  (print-meta o w)
0
-  (print-sequential "(" pr-on " " ")" o w))
0
-
0
-(defmethod print-dup clojure.lang.ISeq [o w] (print-method o w))
0
-
0
-(defmethod print-method clojure.lang.IPersistentList [o, #^Writer w]
0
-  (print-meta o w)
0
-  (print-sequential "(" print-method " " ")" o w))
0
-
0
-(prefer-method print-method clojure.lang.IPersistentList clojure.lang.ISeq)
0
-
0
-(defmethod print-method java.util.Collection [o, #^Writer w]
0
- (print-ctor o #(print-sequential "[" print-method " " "]" %1 %2) w))
0
-
0
-(prefer-method print-method clojure.lang.IPersistentCollection java.util.Collection)
0
-
0
-(defmethod print-dup java.util.Collection [o, #^Writer w]
0
- (print-ctor o #(print-sequential "[" print-dup " " "]" %1 %2) w))
0
-
0
-(defmethod print-dup clojure.lang.IPersistentCollection [o, #^Writer w]
0
-  (print-meta o w)
0
-  (.write w "#=(")
0
-  (.write w (.getName #^Class (class o)))
0
-  (.write w "/create ")
0
-  (print-sequential "[" print-dup " " "]" o w)
0
-  (.write w ")"))
0
-
0
-(prefer-method print-dup clojure.lang.IPersistentCollection java.util.Collection)
0
-
0
-(def #^{:tag String 
0
-        :doc "Returns escape string for char or nil if none"}
0
-  char-escape-string
0
-    {\newline "\\n"
0
-     \tab  "\\t"
0
-     \return "\\r"
0
-     \" "\\\""
0
-     \\  "\\\\"
0
-     \formfeed "\\f"
0
-     \backspace "\\b"})
0
-
0
-(defmethod print-method String [#^String s, #^Writer w]
0
-  (if (or *print-dup* *print-readably*)
0
-    (do (.append w \")
0
-      (dotimes [n (count s)]
0
-        (let [c (.charAt s n)
0
-              e (char-escape-string c)]
0
-          (if e (.write w e) (.append w c))))
0
-      (.append w \"))
0
-    (.write w s))
0
-  nil)
0
 
0
-(defmethod print-dup String [s w] (print-method s w))
0
-
0
-(defmethod print-method clojure.lang.IPersistentVector [v, #^Writer w]
0
-  (print-meta v w)
0
-  (print-sequential "[" pr-on " " "]" v w))
0
-
0
-(defn- print-map [m print-one w]
0
-  (print-sequential 
0
-   "{"
0
-   (fn [e  #^Writer w] 
0
-     (do (print-one (key e) w) (.append w \space) (print-one (val e) w)))
0
-   ", "
0
-   "}"
0
-   (seq m) w))
0
-
0
-(defmethod print-method clojure.lang.IPersistentMap [m, #^Writer w]
0
-  (print-meta m w)
0
-  (print-map m pr-on w))
0
-
0
-(defmethod print-method java.util.Map [m, #^Writer w]
0
-  (print-ctor m #(print-map (seq %1) print-method %2) w))
0
-
0
-(prefer-method print-method clojure.lang.IPersistentMap java.util.Map)
0
-
0
-(defmethod print-dup java.util.Map [m, #^Writer w]
0
-  (print-ctor m #(print-map (seq %1) print-dup %2) w))
0
-
0
-(defmethod print-dup clojure.lang.IPersistentMap [m, #^Writer w]
0
-  (print-meta m w)
0
-  (.write w "#=(")
0
-  (.write w (.getName (class m)))
0
-  (.write w "/create ")
0
-  (print-map m print-dup w)
0
-  (.write w ")"))
0
-
0
-(prefer-method print-dup clojure.lang.IPersistentCollection java.util.Map)
0
-
0
-(defmethod print-method clojure.lang.IPersistentSet [s, #^Writer w]
0
-  (print-meta s w)
0
-  (print-sequential "#{" pr-on " " "}" (seq s) w))
0
-
0
-(defmethod print-method java.util.Set [s, #^Writer w]
0
-  (print-ctor s
0
-              #(print-sequential "#{" print-method " " "}" (seq %1) %2)
0
-              w))
0
-
0
-;(prefer-method print-method clojure.lang.IPersistentSet java.util.Set)
0
-
0
-(def #^{:tag String 
0
-        :doc "Returns name string for char or nil if none"} 
0
- char-name-string
0
-   {\newline "newline"
0
-    \tab "tab"
0
-    \space "space"
0
-    \backspace "backspace"
0
-    \formfeed "formfeed"
0
-    \return "return"})
0
-
0
-(defmethod print-method java.lang.Character [#^Character c, #^Writer w]
0
-  (if (or *print-dup* *print-readably*)
0
-    (do (.append w \\)
0
-        (let [n (char-name-string c)]
0
-          (if n (.write w n) (.append w c))))
0
-    (.append w c))
0
-  nil)
0
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; helper files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0
+
0
+(load "core-proxy")
0
+(load "core-print")
0
+(load "genclass")
0
+
0
 
0
-(defmethod print-dup java.lang.Character [c w] (print-method c w))
0
-(defmethod print-dup java.lang.Integer [o w] (print-method o w))
0
-(defmethod print-dup java.lang.Double [o w] (print-method o w))
0
-(defmethod print-dup clojure.lang.Ratio [o w] (print-method o w))
0
-(defmethod print-dup java.math.BigDecimal [o w] (print-method o w))
0
-(defmethod print-dup clojure.lang.PersistentHashMap [o w] (print-method o w))
0
-(defmethod print-dup clojure.lang.PersistentHashSet [o w] (print-method o w))
0
-(defmethod print-dup clojure.lang.PersistentVector [o w] (print-method o w))
0
-
0
-(def primitives-classnames
0
-  {Float/TYPE "Float/TYPE"
0
-   Integer/TYPE "Integer/TYPE"
0
-   Long/TYPE "Long/TYPE"
0
-   Boolean/TYPE "Boolean/TYPE"
0
-   Character/TYPE "Character/TYPE"
0
-   Double/TYPE "Double/TYPE"
0
-   Byte/TYPE "Byte/TYPE"
0
-   Short/TYPE "Short/TYPE"})
0
-
0
-(defmethod print-method Class [#^Class c, #^Writer w]
0
-  (.write w (.getName c)))
0
-
0
-(defmethod print-dup Class [#^Class c, #^Writer w]
0
-  (cond
0
-    (.isPrimitive c) (do
0
-                       (.write w "#=(identity ")
0
-                       (.write w #^String (primitives-classnames c))
0
-                       (.write w ")"))
0
-    (.isArray c) (do
0
-                   (.write w "#=(java.lang.Class/forName \"")
0
-                   (.write w (.getName c))
0
-                   (.write w "\")"))
0
-    :else (do
0
-            (.write w "#=")
0
-            (.write w (.getName c)))))
0
-
0
-(defmethod print-method java.math.BigDecimal [b, #^Writer w]
0
-  (.write w (str b))
0
-  (.write w "M"))
0
-
0
-(defmethod print-method java.util.regex.Pattern [p #^Writer w]
0
-  (.write w "#\"")
0
-  (loop [[#^Character c & r :as s] (seq (.pattern #^java.util.regex.Pattern p))
0
-         qmode false]
0
-    (when s
0
-      (cond
0
-        (= c \\) (let [[#^Character c2 & r2] r]
0
-                   (.append w \\)
0
-                   (.append w c2)
0
-                   (if qmode
0
-                      (recur r2 (not= c2 \E))
0
-                      (recur r2 (= c2 \Q))))
0
-        (= c \") (do
0
-                   (if qmode
0
-                     (.write w "\\E\\\"\\Q")
0
-                     (.write w "\\\""))
0
-                   (recur r qmode))
0
-        :else    (do
0
-                   (.append w c)
0
-                   (recur r qmode)))))
0
-  (.append w \"))
0
-
0
-(defmethod print-dup java.util.regex.Pattern [p #^Writer w] (print-method p w))
0
-
0
-(defmethod print-dup clojure.lang.Namespace [#^clojure.lang.Namespace n #^Writer w]
0
-  (.write w "#=(find-ns ")
0
-  (print-dup (.name n) w)
0
-  (.write w ")"))
0
-
0
-(def #^{:private true} print-initialized true)
0
-
0
-
0
-;;;;;;;;;;;;;;;;;;;;;;;;;;;; proxy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0
-
0
-(import
0
- '(clojure.asm ClassWriter ClassVisitor Opcodes Type) 
0
- '(java.lang.reflect Modifier Constructor)
0
- '(clojure.asm.commons Method GeneratorAdapter)
0
- '(clojure.lang IProxy Reflector DynamicClassLoader IPersistentMap PersistentHashMap RT))
0
-
0
-(def *proxy-classes* (ref {}))
0
-
0
-(defn method-sig [#^java.lang.reflect.Method meth]
0
-  [(. meth (getName)) (seq (. meth (getParameterTypes))) (. meth getReturnType)])
0
-
0
-(defn get-proxy-class 
0
-  "Takes an optional single class followed by zero or more
0
-  interfaces. If not supplied class defaults to Object.  Creates an
0
-  returns an instance of a proxy class derived from the supplied
0
-  classes. The resulting value is cached and used for any subsequent
0
-  requests for the same class set. Returns a Class object."  
0
-  [& bases]
0
-    (let [bases (if (. (first bases) (isInterface))
0
-                  (cons Object bases)
0
-                  bases)
0
-          [super & interfaces] bases]
0
-      (or (get @*proxy-classes* bases)
0
-          (let [cv (new ClassWriter (. ClassWriter COMPUTE_MAXS))
0
-                cname (str "clojure/lang/" (gensym "Proxy__"))
0
-                ctype (. Type (getObjectType cname))
0
-                iname (fn [c] (.. Type (getType c) (getInternalName)))
0
-                fmap "__clojureFnMap"
0
-                totype (fn [c] (. Type (getType c)))
0
-                to-types (fn [cs] (if (pos? (count cs))
0
-                                    (into-array (map totype cs))
0
-                                    (make-array Type 0)))
0
-                super-type (totype super)
0
-                map-type (totype PersistentHashMap)
0
-                ifn-type (totype clojure.lang.IFn)
0
-                obj-type (totype Object)
0
-                sym-type (totype clojure.lang.Symbol)
0
-                rt-type  (totype clojure.lang.RT)
0
-                ex-type  (totype java.lang.UnsupportedOperationException)
0
-                gen-method
0
-                (fn [#^java.lang.reflect.Method meth else-gen]
0
-                  (let [pclasses (. meth (getParameterTypes))
0
-                        ptypes (to-types pclasses)
0
-                        rtype (totype (. meth (getReturnType)))
0
-                        m (new Method (. meth (getName)) rtype ptypes)
0
-                        gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)
0
-                        else-label (. gen (newLabel))
0
-                        end-label (. gen (newLabel))
0
-                        decl-type (. Type (getType (. meth (getDeclaringClass))))]
0
-                    (. gen (visitCode))
0
-                    (. gen (loadThis))
0
-                    (. gen (getField ctype fmap map-type))
0
-                                        ;get symbol corresponding to name
0
-                    (. gen (push (. meth (getName))))
0
-                    (. gen (invokeStatic sym-type (. Method (getMethod "clojure.lang.Symbol create(String)"))))
0
-                                        ;lookup fn in map
0
-                    (. gen (invokeStatic rt-type (. Method (getMethod "Object get(Object, Object)"))))
0
-                    (. gen (dup))
0
-                    (. gen (ifNull else-label))
0
-                                        ;if found
0
-                    (. gen (loadThis))
0
-                                        ;box args
0
-                    (dotimes [i (count ptypes)]
0
-                      (. gen (loadArg i))
0
-                      (. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i))))
0
-                                        ;call fn
0
-                    (. gen (invokeInterface ifn-type (new Method "invoke" obj-type 
0
-                                                          (into-array (cons obj-type 
0
-                                                                            (replicate (count ptypes) obj-type))))))
0
-                                        ;unbox return
0
-                    (. gen (unbox rtype))
0
-                    (when (= (. rtype (getSort)) (. Type VOID))
0
-                      (. gen (pop)))
0
-                    (. gen (goTo end-label))
0
-                    
0
-                                        ;else call supplied alternative generator
0
-                    (. gen (mark else-label))
0
-                    (. gen (pop))
0
-                    
0
-                    (else-gen gen m)
0
-                    
0
-                    (. gen (mark end-label))
0
-                    (. gen (returnValue))
0
-                    (. gen (endMethod))))]
0
-            
0
-                                        ;start class definition
0
-            (. cv (visit (. Opcodes V1_5) (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_SUPER))
0
-                         cname nil (iname super) 
0
-                         (into-array (map iname (cons IProxy interfaces)))))
0
-                                        ;add field for fn mappings
0
-            (. cv (visitField (+ (. Opcodes ACC_PRIVATE) (. Opcodes ACC_VOLATILE))
0
-                              fmap (. map-type (getDescriptor)) nil nil))          
0
-                                        ;add ctors matching/calling super's
0
-            (doseq [#^Constructor ctor (. super (getDeclaredConstructors))]
0
-              (when-not (. Modifier (isPrivate (. ctor (getModifiers))))
0
-                (let [ptypes (to-types (. ctor (getParameterTypes)))
0
-                      m (new Method "<init>" (. Type VOID_TYPE) ptypes)
0
-                      gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
0
-                  (. gen (visitCode))
0
-                                        ;call super ctor
0
-                  (. gen (loadThis))
0
-                  (. gen (dup))
0
-                  (. gen (loadArgs))
0
-                  (. gen (invokeConstructor super-type m))
0
-                                        ;init fmap
0
-                  (. gen (getStatic map-type "EMPTY" map-type))
0
-                  (. gen (putField ctype fmap map-type))
0
-                  
0
-                  (. gen (returnValue))
0
-                  (. gen (endMethod)))))
0
-                                        ;add IProxy methods
0
-            (let [m (. Method (getMethod "void __updateClojureFnMappings(clojure.lang.IPersistentMap)"))
0
-                  gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
0
-              (. gen (visitCode))
0
-              (. gen (loadThis))
0
-              (. gen (dup))
0
-              (. gen (getField ctype fmap map-type))
0
-              (. gen (loadArgs))
0
-              (. gen (invokeInterface (totype clojure.lang.IPersistentCollection)
0
-                                      (. Method (getMethod "clojure.lang.IPersistentCollection cons(Object)"))))
0
-              (. gen (checkCast map-type))
0
-              (. gen (putField ctype fmap map-type))
0
-              
0
-              (. gen (returnValue))
0
-              (. gen (endMethod)))
0
-            (let [m (. Method (getMethod "clojure.lang.IPersistentMap __getClojureFnMappings()"))
0
-                  gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
0
-              (. gen (visitCode))
0
-              (. gen (loadThis))
0
-              (. gen (getField ctype fmap map-type))
0
-              (. gen (returnValue))
0
-              (. gen (endMethod)))
0
-            
0
-                                        ;calc set of supers' non-private instance methods
0
-            (let [mm (loop [mm {} considered #{} c super]
0
-                       (if c
0
-                         (let [[mm considered]
0
-                               (loop [mm mm 
0
-                                      considered considered 
0
-                                      meths (concat 
0
-                                             (seq (. c (getDeclaredMethods)))
0
-                                             (seq (. c (getMethods))))]
0
-                                 (if meths 
0
-                                   (let [#^java.lang.reflect.Method meth (first meths)
0
-                                         mods (. meth (getModifiers))
0
-                                         mk (method-sig meth)]
0
-                                     (if (or (considered mk)
0
-                                             (. Modifier (isPrivate mods)) 
0
-                                             (. Modifier (isStatic mods))
0
-                                             (. Modifier (isFinal mods))
0
-                                             (= "finalize" (.getName meth)))
0
-                                       (recur mm (conj considered mk) (rest meths))
0
-                                       (recur (assoc mm mk meth) (conj considered mk) (rest meths))))
0
-                                   [mm considered]))]
0
-                           (recur mm considered (. c (getSuperclass))))
0
-                         mm))]
0
-                                        ;add methods matching supers', if no mapping -> call super
0
-              (doseq [#^java.lang.reflect.Method meth (vals mm)]
0
-                     (gen-method meth 
0
-                                 (fn [gen m]
0
-                                   (. gen (loadThis))
0
-                                        ;push args
0
-                                   (. gen (loadArgs))
0
-                                        ;call super
0
-                                   (. gen (visitMethodInsn (. Opcodes INVOKESPECIAL) 
0
-                                                           (. super-type (getInternalName))
0
-                                                           (. m (getName))
0
-                                                           (. m (getDescriptor)))))))
0
-              
0
-                                        ;add methods matching interfaces', if no mapping -> throw
0
-              (doseq [#^Class iface interfaces]
0
-                (doseq [#^java.lang.reflect.Method meth (. iface (getMethods))]
0
-                   (when-not (contains? mm (method-sig meth))
0
-                     (gen-method meth 
0
-                                 (fn [gen m]
0
-                                   (. gen (throwException ex-type (. m (getName))))))))))
0
-
0
-                                        ;finish class def
0
-            (. cv (visitEnd))
0
-                                        ;generate, cache and return class object
0
-            (let [loader (. RT ROOT_CLASSLOADER)
0
-                  c (. loader (defineClass (. cname (replace "/" ".")) 
0
-                                (. cv (toByteArray))))]
0
-              (sync nil (commute *proxy-classes* assoc bases c))
0
-              c)))))
0
-
0
-(defn construct-proxy
0
-  "Takes a proxy class and any arguments for its superclass ctor and
0
-  creates and returns an instance of the proxy."  
0
-  [c & ctor-args]
0
-    (. Reflector (invokeConstructor c (to-array ctor-args))))
0
-
0
-(defn update-proxy
0
-  "Takes a proxy instance and a map of symbols (whose names must
0
-  correspond to methods of the proxy superclass/superinterfaces) to
0
-  fns (which must take arguments matching the corresponding method,
0
-  plus an additional (explicit) first arg corresponding to this, and
0
-  updates (via assoc) the proxy's fn map. nil can be passed instead of
0
-  a fn, in which case the corresponding method will revert to the
0
-  default behavior. Note that this function can be used to update the
0
-  behavior of an existing instance without changing its identity."
0
-  [#^IProxy proxy mappings]
0
-    (. proxy (__updateClojureFnMappings mappings)))
0
-
0
-(defn proxy-mappings
0
-  "Takes a proxy instance and returns the proxy's fn map."
0
-  [#^IProxy proxy]
0
-    (. proxy (__getClojureFnMappings)))
0
-
0
-(defmacro proxy
0
-  "class-and-interfaces - a vector of class names
0
-
0
-  args - a (possibly empty) vector of arguments to the superclass
0
-  constructor.
0
-
0
-  f => (name [params*] body) or
0
-  (name ([params*] body) ([params+] body) ...)
0
-
0
-  Expands to code which creates a instance of a proxy class that
0
-  implements the named class/interface(s) by calling the supplied
0
-  fns. A single class, if provided, must be first. If not provided it
0
-  defaults to Object.
0
-
0
-  The interfaces names must be valid interface types. If a method fn
0
-  is not provided for a class method, the superclass methd will be
0
-  called. If a method fn is not provided for an interface method, an
0
-  UnsupportedOperationException will be thrown should it be
0
-  called. Method fns are closures and can capture the environment in
0
-  which proxy is called. Each method fn takes an additional implicit
0
-  first arg, which is bound to 'this. Note that while method fns can
0
-  be provided to override protected methods, they have no other access
0
-  to protected members, nor to super, as these capabilities cannot be
0
-  proxied."
0
-  [class-and-interfaces args & fs]
0
-  `(let [pc# (get-proxy-class ~@class-and-interfaces)
0
-         p# (construct-proxy pc# ~@args)]   
0
-     (update-proxy p#
0
-       ~(loop [fmap {} fs fs]
0
-          (if fs
0
-            (let [[sym & meths] (first fs)
0
-                  meths (if (vector? (first meths))
0
-                          (list meths)
0
-                          meths)
0
-                  meths (map (fn [[params & body]]
0
-                               (cons (apply vector 'this params) body))
0
-                             meths)]
0
-              (recur (assoc fmap (list `quote (symbol (name sym))) (cons `fn meths)) (rest fs)))
0
-            fmap)))
0
-     p#))
0
-
0
-(defn proxy-call-with-super [call this meth]
0
- (let [m (proxy-mappings this)]
0
-    (update-proxy this (assoc m meth nil))
0
-    (let [ret (call)]
0
-      (update-proxy this m)
0
-      ret)))
0
-
0
-(defmacro proxy-super 
0
-  "Use to call a superclass method in the body of a proxy method. 
0
-  Note, expansion captures 'this"
0
-  [meth & args]
0
- `(proxy-call-with-super (fn [] (. ~'this ~meth ~@args))  ~'this '~(symbol (name meth))))
0
-
0
-(defn bean
0
-  "Takes a Java object and returns a read-only implementation of the
0
-  map abstraction based upon its JavaBean properties."
0
-  [#^Object x]
0
-  (let [c (. x (getClass))
0
-  pmap (reduce (fn [m #^java.beans.PropertyDescriptor pd]
0
-       (let [name (. pd (getName))
0
-             method (. pd (getReadMethod))]
0
-         (if (and method (zero? (alength (. method (getParameterTypes)))))
0
-           (assoc m (keyword name) (fn [] (. method (invoke x nil))))
0
-           m)))
0
-         {}
0
-         (seq (.. java.beans.Introspector
0
-            (getBeanInfo c)
0
-            (getPropertyDescriptors))))
0
-  v (fn [k] ((pmap k)))
0
-        snapshot (fn []
0
-                   (reduce (fn [m e]
0
-                             (assoc m (key e) ((val e))))
0
-                           {} (seq pmap)))]
0
-    (proxy [clojure.lang.APersistentMap]
0
-           []
0
-      (containsKey [k] (contains? pmap k))
0
-      (entryAt [k] (when (contains? pmap k) (new clojure.lang.MapEntry k (v k))))
0
-      (valAt ([k] (v k))
0
-       ([k default] (if (contains? pmap k) (v k) default)))
0
-      (cons [m] (conj (snapshot) m))
0
-      (count [] (count pmap))
0
-      (assoc [k v] (assoc (snapshot) k v))
0
-      (without [k] (dissoc (snapshot) k))
0
-      (seq [] ((fn thisfn [pseq]
0
-      (when pseq
0
-        (lazy-cons (new clojure.lang.MapEntry (first pseq) (v (first pseq)))
0
-             (thisfn (rest pseq))))) (keys pmap))))))
...
4471
4472
4473
4474
4475
 
4476
4477
4478
...
4471
4472
4473
 
 
4474
4475
4476
4477
0
@@ -4471,8 +4471,7 @@ public static Object compile(Reader rdr, String sourcePath, String sourceName) t
0
              LINE_AFTER, pushbackReader.getLineNumber(),
0
              CONSTANTS, PersistentVector.EMPTY,
0
              KEYWORDS, PersistentHashMap.EMPTY,
0
-             VARS, PersistentHashMap.EMPTY,
0
-             COMPILE_FILES, RT.T
0
+             VARS, PersistentHashMap.EMPTY
0
       ));
0
 
0
   try
...
368
369
370
371
372
 
 
 
 
 
 
 
 
373
374
375
...
392
393
394
395
396
397
398
399
400
401
 
402
403
404
405
 
 
 
 
 
 
 
 
 
 
406
407
408
 
409
410
411
412
413
414
 
 
 
 
 
 
 
415
416
417
...
424
425
426
427
 
428
429
430
...
433
434
435
436
 
 
 
 
437
438
439
440
 
441
 
442
443
444
445
446
 
 
 
 
447
448
449
...
368
369
370
 
 
371
372
373
374
375
376
377
378
379
380
381
...
398
399
400
 
 
 
401
 
 
 
402
403
404
405
 
406
407
408
409
410
411
412
413
414
415
416
417
 
418
419
420
 
 
 
 
421
422
423
424
425
426
427
428
429
430
...
437
438
439
 
440
441
442
443
...
446
447
448
 
449
450
451
452
453
454
 
 
455
456
457
458
 
 
 
 
459
460
461
462
463
464
465
0
@@ -368,8 +368,14 @@ public static void loadResourceScript(Class c, String name, boolean failIfNotFou
0
   InputStream ins = baseLoader().getResourceAsStream(name);
0
   if(ins != null)
0
     {
0
-    Compiler.load(new InputStreamReader(ins, UTF8), name, file);
0
-    ins.close();
0
+    try
0
+      {
0
+      Compiler.load(new InputStreamReader(ins, UTF8), name, file);
0
+      }
0
+    finally
0
+      {
0
+      ins.close();
0
+      }
0
     }
0
   else if(failIfNotFound)
0
     {
0
@@ -392,26 +398,33 @@ static public long lastModified(URL url,String libfile) throws Exception{
0
     return f.lastModified();
0
     }
0
 }
0
-static public void loadLib(String lib) throws Exception{
0
-  loadLib(lib, true);
0
-}
0
 
0
-static public void compileLib(String lib) throws Exception{
0
-  String libpath = lib.replace('.', '/');
0
-  String cljfile = libpath + ".clj";
0
+static void compile(String cljfile) throws Exception{
0
   InputStream ins = baseLoader().getResourceAsStream(cljfile);
0
   if(ins != null)
0
     {
0
-    Compiler.compile(new InputStreamReader(ins, UTF8), cljfile, cljfile.substring(cljfile.lastIndexOf("/")));
0
+    try
0
+      {
0
+      Compiler.compile(new InputStreamReader(ins, UTF8), cljfile,
0
+                       cljfile.substring(1 + cljfile.lastIndexOf("/")));
0
+      }
0
+    finally
0
+      {
0
+      ins.close();
0
+      }
0
+
0
     }
0
   else
0
-    throw new FileNotFoundException("Could not locate Clojure resource on classpath: " + lib);
0
+    throw new FileNotFoundException("Could not locate Clojure resource on classpath: " + cljfile);
0
 }
0
 
0
-static public void loadLib(String lib, boolean failIfNotFound) throws Exception{
0
-  String libpath = lib.replace('.', '/');
0
-  String classfile = libpath + ".class";
0
-  String cljfile = libpath + ".clj";
0
+static public void load(String scriptbase) throws Exception{
0
+  load(scriptbase, true);
0
+}
0
+
0
+static public void load(String scriptbase, boolean failIfNotFound) throws Exception{
0
+  String classfile = scriptbase + ".class";
0
+  String cljfile = scriptbase + ".clj";
0
   URL classURL = baseLoader().getResource(classfile);
0
   URL cljURL = baseLoader().getResource(cljfile);
0
 
0
@@ -424,7 +437,7 @@ static public void loadLib(String lib, boolean failIfNotFound) throws Exception{
0
       Var.pushThreadBindings(
0
           RT.map(CURRENT_NS, CURRENT_NS.get(),
0
                  WARN_ON_REFLECTION, WARN_ON_REFLECTION.get()));
0
-      Reflector.invokeStaticMethod(classForName(lib), "load", EMPTY_ARRAY);
0
+      Reflector.invokeStaticMethod(classForName(scriptbase.replace('/','.')), "load", EMPTY_ARRAY);
0
       }
0
     finally
0
       {
0
@@ -433,17 +446,20 @@ static public void loadLib(String lib, boolean failIfNotFound) throws Exception{
0
     }
0
   else if(cljURL != null)
0
     {
0
-    loadResourceScript(RT.class, cljfile);
0
+    if (booleanCast(Compiler.COMPILE_FILES.get()))
0
+      compile(cljfile);
0
+    else
0
+      loadResourceScript(RT.class, cljfile);
0
     }
0
   else if(failIfNotFound)
0
-    throw new FileNotFoundException("Could not locate Clojure resource on classpath: " + lib);
0
-
0
+    throw new FileNotFoundException(String.format("Could not locate %s or %s on classpath: ", classfile, cljfile));
0
 }
0
+
0
 static void doInit() throws Exception{
0
-  loadLib("clojure.core");
0
-  loadLib("clojure.zip",false);
0
-  loadLib("clojure.xml",false);
0
-  loadLib("clojure.set",false);
0
+  load("clojure/core");
0
+  load("clojure/zip",false);
0
+  load("clojure/xml",false);
0
+  load("clojure/set",false);
0
 //  try
0
 //    {
0
 //    Reflector.invokeStaticMethod("clojure.core", "load", EMPTY_ARRAY);

Comments