├── .gitignore ├── .idea └── libraries │ ├── Maven__org_clojure_data_generators_0_1_2.xml │ └── Maven__org_clojure_test_generative_0_4_0.xml ├── CONTRIBUTING.md ├── KNOWN_ISSUES ├── antsetup.sh ├── build.clj ├── build.xml ├── changes.md ├── clojure.iml ├── doc └── clojure │ └── pprint │ ├── CommonLispFormat.markdown │ └── PrettyPrinting.markdown ├── epl-v10.html ├── pom.xml ├── readme.md ├── release.sh ├── src ├── assembly │ ├── distribution.xml │ └── slim.xml ├── clj │ └── clojure │ │ ├── core.clj │ │ ├── core │ │ ├── protocols.clj │ │ └── reducers.clj │ │ ├── core_deftype.clj │ │ ├── core_objc.clj │ │ ├── core_print.clj │ │ ├── core_proxy.clj │ │ ├── data.clj │ │ ├── edn.clj │ │ ├── genclass.clj │ │ ├── gvec.clj │ │ ├── inspector.clj │ │ ├── instant.clj │ │ ├── java │ │ ├── browse.clj │ │ ├── browse_ui.clj │ │ ├── io.clj │ │ ├── javadoc.clj │ │ └── shell.clj │ │ ├── main.clj │ │ ├── parallel.clj │ │ ├── pprint.clj │ │ ├── pprint │ │ ├── cl_format.clj │ │ ├── column_writer.clj │ │ ├── dispatch.clj │ │ ├── pprint_base.clj │ │ ├── pretty_writer.clj │ │ ├── print_table.clj │ │ └── utilities.clj │ │ ├── reflect.clj │ │ ├── reflect │ │ └── java.clj │ │ ├── remoterepl.clj │ │ ├── repl.clj │ │ ├── set.clj │ │ ├── stacktrace.clj │ │ ├── string.clj │ │ ├── template.clj │ │ ├── test.clj │ │ ├── test │ │ ├── junit.clj │ │ └── tap.clj │ │ ├── uuid.clj │ │ ├── walk.clj │ │ ├── xml.clj │ │ └── zip.clj ├── ffi │ ├── ffi.h │ ├── ffi_arm64.h │ ├── ffi_armv7.h │ ├── ffi_common.h │ ├── ffi_i386.h │ ├── ffi_x86_64.h │ ├── fficonfig.h │ ├── fficonfig_arm64.h │ ├── fficonfig_armv7.h │ ├── fficonfig_i386.h │ ├── fficonfig_x86_64.h │ ├── ffitarget.h │ ├── ffitarget_arm64.h │ ├── ffitarget_armv7.h │ ├── ffitarget_i386.h │ ├── ffitarget_x86_64.h │ └── libffi.a ├── jvm │ ├── clojure │ │ ├── asm │ │ │ ├── AnnotationVisitor.java │ │ │ ├── AnnotationWriter.java │ │ │ ├── Attribute.java │ │ │ ├── ByteVector.java │ │ │ ├── ClassReader.java │ │ │ ├── ClassVisitor.java │ │ │ ├── ClassWriter.java │ │ │ ├── Context.java │ │ │ ├── Edge.java │ │ │ ├── FieldVisitor.java │ │ │ ├── FieldWriter.java │ │ │ ├── Frame.java │ │ │ ├── Handle.java │ │ │ ├── Handler.java │ │ │ ├── Item.java │ │ │ ├── Label.java │ │ │ ├── MethodVisitor.java │ │ │ ├── MethodWriter.java │ │ │ ├── Opcodes.java │ │ │ ├── Type.java │ │ │ ├── commons │ │ │ │ ├── AdviceAdapter.java │ │ │ │ ├── AnalyzerAdapter.java │ │ │ │ ├── CodeSizeEvaluator.java │ │ │ │ ├── GeneratorAdapter.java │ │ │ │ ├── InstructionAdapter.java │ │ │ │ ├── LocalVariablesSorter.java │ │ │ │ ├── Method.java │ │ │ │ ├── SerialVersionUIDAdder.java │ │ │ │ ├── StaticInitMerger.java │ │ │ │ ├── TableSwitchGenerator.java │ │ │ │ └── package.html │ │ │ └── package.html │ │ ├── java │ │ │ └── api │ │ │ │ ├── Clojure.java │ │ │ │ └── package.html │ │ ├── lang │ │ │ ├── AFn.java │ │ │ ├── AFunction.java │ │ │ ├── AMapEntry.java │ │ │ ├── APersistentMap.java │ │ │ ├── APersistentSet.java │ │ │ ├── APersistentVector.java │ │ │ ├── ARef.java │ │ │ ├── AReference.java │ │ │ ├── ASeq.java │ │ │ ├── ATransientMap.java │ │ │ ├── ATransientSet.java │ │ │ ├── Agent.java │ │ │ ├── ArityException.java │ │ │ ├── ArrayChunk.java │ │ │ ├── ArrayIter.java │ │ │ ├── ArraySeq.java │ │ │ ├── Associative.java │ │ │ ├── Atom.java │ │ │ ├── BigInt.java │ │ │ ├── Binding.java │ │ │ ├── Box.java │ │ │ ├── ChunkBuffer.java │ │ │ ├── ChunkedCons.java │ │ │ ├── Compile.java │ │ │ ├── Compiler.java │ │ │ ├── Cons.java │ │ │ ├── Counted.java │ │ │ ├── Cycle.java │ │ │ ├── Delay.java │ │ │ ├── DynamicClassLoader.java │ │ │ ├── EdnReader.java │ │ │ ├── EnumerationSeq.java │ │ │ ├── ExceptionInfo.java │ │ │ ├── Fn.java │ │ │ ├── FnLoaderThunk.java │ │ │ ├── IAtom.java │ │ │ ├── IBlockingDeref.java │ │ │ ├── IChunk.java │ │ │ ├── IChunkedSeq.java │ │ │ ├── IDeref.java │ │ │ ├── IEditableCollection.java │ │ │ ├── IExceptionInfo.java │ │ │ ├── IFn.java │ │ │ ├── IHashEq.java │ │ │ ├── IKeywordLookup.java │ │ │ ├── ILookup.java │ │ │ ├── ILookupSite.java │ │ │ ├── ILookupThunk.java │ │ │ ├── IMapEntry.java │ │ │ ├── IMapIterable.java │ │ │ ├── IMeta.java │ │ │ ├── IObj.java │ │ │ ├── IPending.java │ │ │ ├── IPersistentCollection.java │ │ │ ├── IPersistentList.java │ │ │ ├── IPersistentMap.java │ │ │ ├── IPersistentSet.java │ │ │ ├── IPersistentStack.java │ │ │ ├── IPersistentVector.java │ │ │ ├── IProxy.java │ │ │ ├── IRecord.java │ │ │ ├── IReduce.java │ │ │ ├── IReduceInit.java │ │ │ ├── IRef.java │ │ │ ├── IReference.java │ │ │ ├── ISeq.java │ │ │ ├── ITransientAssociative.java │ │ │ ├── ITransientCollection.java │ │ │ ├── ITransientMap.java │ │ │ ├── ITransientSet.java │ │ │ ├── ITransientVector.java │ │ │ ├── IType.java │ │ │ ├── IllegalAccessError.java │ │ │ ├── Indexed.java │ │ │ ├── IndexedSeq.java │ │ │ ├── Intrinsics.java │ │ │ ├── Iterate.java │ │ │ ├── IteratorSeq.java │ │ │ ├── Keyword.java │ │ │ ├── KeywordLookupSite.java │ │ │ ├── LazilyPersistentVector.java │ │ │ ├── LazySeq.java │ │ │ ├── LineNumberingPushbackReader.java │ │ │ ├── LispReader.java │ │ │ ├── LockingTransaction.java │ │ │ ├── LongRange.java │ │ │ ├── MapEntry.java │ │ │ ├── MapEquivalence.java │ │ │ ├── MethodImplCache.java │ │ │ ├── MultiFn.java │ │ │ ├── Murmur3.java │ │ │ ├── Named.java │ │ │ ├── Namespace.java │ │ │ ├── Numbers.java │ │ │ ├── Obj.java │ │ │ ├── ObjC.java │ │ │ ├── ObjCClass.java │ │ │ ├── PersistentArrayMap.java │ │ │ ├── PersistentHashMap.java │ │ │ ├── PersistentHashSet.java │ │ │ ├── PersistentList.java │ │ │ ├── PersistentQueue.java │ │ │ ├── PersistentStructMap.java │ │ │ ├── PersistentTreeMap.java │ │ │ ├── PersistentTreeSet.java │ │ │ ├── PersistentVector.java │ │ │ ├── ProxyHandler.java │ │ │ ├── RT.java │ │ │ ├── Range.java │ │ │ ├── Ratio.java │ │ │ ├── ReaderConditional.java │ │ │ ├── RecordIterator.java │ │ │ ├── Reduced.java │ │ │ ├── Ref.java │ │ │ ├── Reflector.java │ │ │ ├── RemoteRef.java │ │ │ ├── RemoteRepl.java │ │ │ ├── Repeat.java │ │ │ ├── RestFn.java │ │ │ ├── RestFnWithMeta.java │ │ │ ├── Reversible.java │ │ │ ├── Selector.java │ │ │ ├── SeqEnumeration.java │ │ │ ├── SeqIterator.java │ │ │ ├── Seqable.java │ │ │ ├── Sequential.java │ │ │ ├── Settable.java │ │ │ ├── Sorted.java │ │ │ ├── SourceGenIntrinsics.java │ │ │ ├── SourceWriter.java │ │ │ ├── StringEscapeUtils.java │ │ │ ├── StringSeq.java │ │ │ ├── Symbol.java │ │ │ ├── TaggedLiteral.java │ │ │ ├── ThreadFactory.java │ │ │ ├── TransactionalHashMap.java │ │ │ ├── TransformerIterator.java │ │ │ ├── URLClassLoader.java │ │ │ ├── Util.java │ │ │ ├── Var.java │ │ │ ├── Volatile.java │ │ │ ├── WarnBoxedMath.java │ │ │ ├── XMLHandler.java │ │ │ └── package.html │ │ └── main.java │ └── com │ │ └── google │ │ └── j2objc │ │ └── annotations │ │ └── ReflectionSupport.java ├── objc │ ├── Cst502Socket.h │ ├── Cst502Socket.m │ ├── NSCommon.h │ ├── NSCommon.m │ ├── NSProxyImpl.h │ ├── NSProxyImpl.m │ ├── NSSocketImpl.h │ ├── NSSocketImpl.m │ ├── NSTypeImpl.h │ ├── NSTypeImpl.m │ ├── ReplClient.h │ ├── ReplClient.m │ ├── WeakRef.h │ └── WeakRef.m ├── resources │ └── clojure │ │ └── version.properties └── script │ ├── run_test.clj │ └── run_test_generative.clj └── test ├── clojure ├── test_clojure │ ├── agents.clj │ ├── annotations.clj │ ├── annotations │ │ ├── java_5.clj │ │ └── java_6.clj │ ├── api.clj │ ├── atoms.clj │ ├── clojure_set.clj │ ├── clojure_walk.clj │ ├── clojure_xml.clj │ ├── clojure_zip.clj │ ├── compilation.clj │ ├── compilation │ │ ├── examples.clj │ │ └── line_number_examples.clj │ ├── control.clj │ ├── data.clj │ ├── data_structures.clj │ ├── def.clj │ ├── delays.clj │ ├── edn.clj │ ├── errors.clj │ ├── evaluation.clj │ ├── fn.clj │ ├── for.clj │ ├── genclass.clj │ ├── genclass │ │ └── examples.clj │ ├── generators.clj │ ├── java │ │ ├── io.clj │ │ ├── javadoc.clj │ │ └── shell.clj │ ├── java_interop.clj │ ├── keywords.clj │ ├── logic.clj │ ├── macros.clj │ ├── main.clj │ ├── metadata.clj │ ├── multimethods.clj │ ├── ns_libs.clj │ ├── numbers.clj │ ├── other_functions.clj │ ├── parallel.clj │ ├── pprint.clj │ ├── pprint │ │ ├── test_cl_format.clj │ │ ├── test_helper.clj │ │ └── test_pretty.clj │ ├── predicates.clj │ ├── printer.clj │ ├── protocols.clj │ ├── protocols │ │ ├── examples.clj │ │ ├── hash_collisions.clj │ │ └── more_examples.clj │ ├── reader.cljc │ ├── reducers.clj │ ├── reflect.clj │ ├── refs.clj │ ├── repl.clj │ ├── repl │ │ └── example.clj │ ├── rt.clj │ ├── sequences.clj │ ├── serialization.clj │ ├── special.clj │ ├── string.clj │ ├── test.clj │ ├── test_fixtures.clj │ ├── transducers.clj │ ├── transients.clj │ ├── try_catch.clj │ ├── vars.clj │ ├── vectors.clj │ └── volatiles.clj └── test_helper.clj ├── java ├── clojure │ └── test │ │ └── ReflectorTryCatchFixture.java ├── compilation │ └── TestDispatch.java └── java │ └── util │ └── jar │ ├── JarEntry.java │ └── JarFile.java └── objc ├── NSCommonTest.h └── NSCommonTest.m /.gitignore: -------------------------------------------------------------------------------- 1 | *.jar 2 | target 3 | clojure.iws 4 | clojure.ipr 5 | nbproject/private/ 6 | maven-classpath 7 | maven-classpath.properties 8 | coclojure/* 9 | .settings/* 10 | .classpath 11 | .project 12 | xcode 13 | .idea/ 14 | 15 | settings.xml 16 | 17 | upload-github.sh 18 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_clojure_data_generators_0_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_clojure_test_generative_0_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | If you'd like to submit a patch, please follow the [contributing guidelines](http://clojure.org/contributing). 2 | -------------------------------------------------------------------------------- /KNOWN_ISSUES: -------------------------------------------------------------------------------- 1 | - Dividing by zero doesn't throw an exception in objc, it fails with EXC_ARITHMETIC 2 | - NullPointerException and ClassCastException are not reliable, as they are emulated by j2objc 3 | - Empty regular expressions throw an exception 4 | - pr-str a date have a bad Timezone format: https://code.google.com/p/j2objc/issues/detail?id=321 -------------------------------------------------------------------------------- /antsetup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mvn -q dependency:build-classpath -Dmdep.outputFile=maven-classpath 4 | cat <maven-classpath.properties 5 | maven.compile.classpath=`cat maven-classpath` 6 | maven.test.classpath=`cat maven-classpath` 7 | EOF 8 | echo "Wrote maven-classpath.properties for standalone ant use" 9 | -------------------------------------------------------------------------------- /clojure.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # clojure-objc 2 | 3 | A Clojure compiler that targets objc runtimes. 4 | 5 | * Write native apps in Clojure 6 | * Strong iOS support 7 | * Future proof: shares 99.99% of the code base with clojure for the jvm 8 | * Distribute clojure-objc libs using maven 9 | * Most existing Clojure libs should just work 10 | * ObjC interop 11 | * C interop 12 | * ObjC subclassing 13 | * REPL! 14 | 15 | ![alt usage guide](https://github.com/galdolber/clojure-objc-sample/raw/master/ios.gif) 16 | 17 | ## Leiningen plugin 18 | 19 | https://github.com/galdolber/lein-objcbuild 20 | 21 | ## Dependency 22 | 23 | [![Clojars Project](http://clojars.org/galdolber/clojure-objc/latest-version.svg)](http://clojars.org/galdolber/clojure-objc) 24 | 25 | ## Memory management 26 | 27 | All generated code manage memory automagically, but if you alloc with interop you need to release! 28 | 29 | ## ObjC interop 30 | 31 | ;; calling objc methods 32 | (defn say-hi [name] 33 | (-> ($ UIAlertView) 34 | ($ :alloc) 35 | ($ :initWithTitle (str "Hello " name) 36 | :message "Hi! from clojure" 37 | :delegate nil 38 | :cancelButtonTitle "Cancelar" 39 | :otherButtonTitles nil) 40 | ($ :autorelease) 41 | ($ :show))) 42 | 43 | ;; extend objc class 44 | (defnstype UIKitController UIViewController 45 | ([^:id self :initWith ^:id [view s]] 46 | (doto ($$ self :init) 47 | ($ :setView ($ view :retain)) 48 | (objc-set! :scope s) 49 | (#(post-notification ($ % :view) :init))))) 50 | 51 | ;; c interop 52 | (defc NSLog :void [:id &]) ; & for variadic 53 | (NSLog "%@ %@ %d" "Hello" "World" 13) 54 | 55 | ;; proxy objc class 56 | (nsproxy 57 | ([^:bool self :textFieldShouldReturn ^:id field] 58 | ($ field :resignFirstResponder) 59 | true)) 60 | 61 | ## Presentations 62 | 63 | http://www.slideshare.net/GalDolber/clojureobjc-47500127 64 | 65 | ## Discuss 66 | 67 | https://groups.google.com/d/forum/clojure-objc-discuss 68 | 69 | ## How to build dist 70 | 71 | lein exec build.clj 72 | 73 | ## License 74 | 75 | Portions of this project derived from Clojure: 76 | Copyright © 2006-2015 Rich Hickey 77 | 78 | Original code and Clojure modifications: 79 | Copyright © 2014-2015 Gal Dolber 80 | 81 | Both are distributed under the Eclipse Public License either version 1.0 or (at your option) any later version. 82 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | export KEEP_META=false 2 | rm -Rf target/release 3 | mkdir target/release 4 | cp target/libclojure-objc.a target/release/ 5 | cp $J2OBJC_HOME/lib/libjre_emul.a target/release/ 6 | cp src/ffi/libffi.a target/release/ 7 | mkdir target/release/include 8 | rsync -a $J2OBJC_HOME/include target/release 9 | rsync -a target/include target/release 10 | cp $J2OBJC_HOME/j2objc target/release/ 11 | mkdir target/release/lib 12 | cp $J2OBJC_HOME/lib/j2objc_annotations.jar target/release/lib 13 | cp $J2OBJC_HOME/lib/j2objc.jar target/release/lib 14 | cp $J2OBJC_HOME/lib/jre_emul.jar target/release/lib 15 | cd ./target/release 16 | zip -r ../release.zip . 17 | -------------------------------------------------------------------------------- /src/assembly/distribution.xml: -------------------------------------------------------------------------------- 1 | 2 | distribution 3 | 4 | zip 5 | 6 | 7 | 8 | src 9 | src 10 | 11 | 12 | doc 13 | doc 14 | 15 | 16 | test 17 | test 18 | 19 | 20 | target 21 | / 22 | false 23 | 24 | *.jar 25 | 26 | 27 | 28 | 29 | 30 | pom.xml 31 | 32 | 33 | build.xml 34 | 35 | 36 | readme.txt 37 | true 38 | 39 | 40 | changes.md 41 | 42 | 43 | clojure.iml 44 | 45 | 46 | epl-v10.html 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/assembly/slim.xml: -------------------------------------------------------------------------------- 1 | 2 | slim 3 | 4 | jar 5 | 6 | false 7 | 8 | 9 | src/clj 10 | / 11 | 12 | 13 | src/resources 14 | / 15 | true 16 | 17 | 18 | target/classes/clojure/asm 19 | clojure/asm 20 | 21 | 22 | target/classes/clojure/lang 23 | clojure/lang 24 | 25 | 26 | 27 | 28 | target/classes/clojure/main.class 29 | clojure 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/clj/clojure/edn.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^{:doc "edn reading." 10 | :author "Rich Hickey"} 11 | clojure.edn 12 | (:refer-clojure :exclude [read read-string])) 13 | 14 | (defn read 15 | "Reads the next object from stream, which must be an instance of 16 | java.io.PushbackReader or some derivee. stream defaults to the 17 | current value of *in*. 18 | 19 | Reads data in the edn format (subset of Clojure data): 20 | http://edn-format.org 21 | 22 | opts is a map that can include the following keys: 23 | :eof - value to return on end-of-file. When not supplied, eof throws an exception. 24 | :readers - a map of tag symbols to data-reader functions to be considered before default-data-readers. 25 | When not supplied, only the default-data-readers will be used. 26 | :default - A function of two args, that will, if present and no reader is found for a tag, 27 | be called with the tag and the value." 28 | 29 | {:added "1.5"} 30 | ([] 31 | (read *in*)) 32 | ([stream] 33 | (read {} stream)) 34 | ([opts stream] 35 | (clojure.lang.EdnReader/read stream opts))) 36 | 37 | (defn read-string 38 | "Reads one object from the string s. Returns nil when s is nil or empty. 39 | 40 | Reads data in the edn format (subset of Clojure data): 41 | http://edn-format.org 42 | 43 | opts is a map as per clojure.edn/read" 44 | {:added "1.5"} 45 | ([s] (read-string {:eof nil} s)) 46 | ([opts s] (when s (clojure.lang.EdnReader/readString s opts)))) -------------------------------------------------------------------------------- /src/clj/clojure/java/browse_ui.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns 10 | ^{:author "Christophe Grand", 11 | :doc "Helper namespace for clojure.java.browse. 12 | Prevents console apps from becoming GUI unnecessarily."} 13 | clojure.java.browse-ui) 14 | 15 | (defn- open-url-in-swing 16 | [url] 17 | (let [htmlpane (javax.swing.JEditorPane. url)] 18 | (.setEditable htmlpane false) 19 | (.addHyperlinkListener htmlpane 20 | (proxy [javax.swing.event.HyperlinkListener] [] 21 | (hyperlinkUpdate [^javax.swing.event.HyperlinkEvent e] 22 | (when (= (.getEventType e) (. javax.swing.event.HyperlinkEvent$EventType ACTIVATED)) 23 | (if (instance? javax.swing.text.html.HTMLFrameHyperlinkEvent e) 24 | (-> htmlpane .getDocument (.processHTMLFrameHyperlinkEvent e)) 25 | (.setPage htmlpane (.getURL e))))))) 26 | (doto (javax.swing.JFrame.) 27 | (.setContentPane (javax.swing.JScrollPane. htmlpane)) 28 | (.setBounds 32 32 700 900) 29 | (.show)))) 30 | 31 | -------------------------------------------------------------------------------- /src/clj/clojure/pprint.clj: -------------------------------------------------------------------------------- 1 | ;;; pprint.clj -- Pretty printer and Common Lisp compatible format function (cl-format) for Clojure 2 | 3 | ; Copyright (c) Rich Hickey. All rights reserved. 4 | ; The use and distribution terms for this software are covered by the 5 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 6 | ; which can be found in the file epl-v10.html at the root of this distribution. 7 | ; By using this software in any fashion, you are agreeing to be bound by 8 | ; the terms of this license. 9 | ; You must not remove this notice, or any other, from this software. 10 | 11 | ;; Author: Tom Faulhaber 12 | ;; April 3, 2009 13 | 14 | (ns 15 | ^{:author "Tom Faulhaber", 16 | :doc "A Pretty Printer for Clojure 17 | 18 | clojure.pprint implements a flexible system for printing structured data 19 | in a pleasing, easy-to-understand format. Basic use of the pretty printer is 20 | simple, just call pprint instead of println. More advanced users can use 21 | the building blocks provided to create custom output formats. 22 | 23 | Out of the box, pprint supports a simple structured format for basic data 24 | and a specialized format for Clojure source code. More advanced formats, 25 | including formats that don't look like Clojure data at all like XML and 26 | JSON, can be rendered by creating custom dispatch functions. 27 | 28 | In addition to the pprint function, this module contains cl-format, a text 29 | formatting function which is fully compatible with the format function in 30 | Common Lisp. Because pretty printing directives are directly integrated with 31 | cl-format, it supports very concise custom dispatch. It also provides 32 | a more powerful alternative to Clojure's standard format function. 33 | 34 | See documentation for pprint and cl-format for more information or 35 | complete documentation on the the clojure web site on github.", 36 | :added "1.2"} 37 | clojure.pprint 38 | (:refer-clojure :exclude (deftype)) 39 | (:use [clojure.walk :only [walk]])) 40 | 41 | 42 | (load "pprint/utilities") 43 | (load "pprint/column_writer") 44 | (load "pprint/pretty_writer") 45 | (load "pprint/pprint_base") 46 | (load "pprint/cl_format") 47 | (load "pprint/dispatch") 48 | (load "pprint/print_table") 49 | 50 | nil 51 | -------------------------------------------------------------------------------- /src/clj/clojure/pprint/print_table.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (in-ns 'clojure.pprint) 10 | 11 | (defn print-table 12 | "Prints a collection of maps in a textual table. Prints table headings 13 | ks, and then a line of output for each row, corresponding to the keys 14 | in ks. If ks are not specified, use the keys of the first item in rows." 15 | {:added "1.3"} 16 | ([ks rows] 17 | (when (seq rows) 18 | (let [widths (map 19 | (fn [k] 20 | (apply max (count (str k)) (map #(count (str (get % k))) rows))) 21 | ks) 22 | spacers (map #(apply str (repeat % "-")) widths) 23 | fmts (map #(str "%" % "s") widths) 24 | fmt-row (fn [leader divider trailer row] 25 | (str leader 26 | (apply str (interpose divider 27 | (for [[col fmt] (map vector (map #(get row %) ks) fmts)] 28 | (format fmt (str col))))) 29 | trailer))] 30 | (println) 31 | (println (fmt-row "| " " | " " |" (zipmap ks ks))) 32 | (println (fmt-row "|-" "-+-" "-|" (zipmap ks spacers))) 33 | (doseq [row rows] 34 | (println (fmt-row "| " " | " " |" row)))))) 35 | ([rows] (print-table (keys (first rows)) rows))) 36 | -------------------------------------------------------------------------------- /src/clj/clojure/stacktrace.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;; stacktrace.clj: print Clojure-centric stack traces 10 | 11 | ;; by Stuart Sierra 12 | ;; January 6, 2009 13 | 14 | (ns ^{:doc "Print stack traces oriented towards Clojure, not Java." 15 | :author "Stuart Sierra"} 16 | clojure.stacktrace) 17 | 18 | (defn root-cause 19 | "Returns the last 'cause' Throwable in a chain of Throwables." 20 | {:added "1.1"} 21 | [^Throwable tr] 22 | (if-let [cause (.getCause tr)] 23 | (recur cause) 24 | tr)) 25 | 26 | (defn print-trace-element 27 | "Prints a Clojure-oriented view of one element in a stack trace." 28 | {:added "1.1"} 29 | [^StackTraceElement e] 30 | (let [class (.getClassName e) 31 | method (.getMethodName e)] 32 | (let [match (re-matches #"^([A-Za-z0-9_.-]+)\$(\w+)__\d+$" (str class))] 33 | (if (and match (= "invoke" method)) 34 | (apply printf "%s/%s" (rest match)) 35 | (printf "%s.%s" class method)))) 36 | (printf " (%s:%d)" (or (.getFileName e) "") (.getLineNumber e))) 37 | 38 | (defn print-throwable 39 | "Prints the class and message of a Throwable." 40 | {:added "1.1"} 41 | [^Throwable tr] 42 | (printf "%s: %s" (.getName (class tr)) (.getMessage tr))) 43 | 44 | (defn print-stack-trace 45 | "Prints a Clojure-oriented stack trace of tr, a Throwable. 46 | Prints a maximum of n stack frames (default: unlimited). 47 | Does not print chained exceptions (causes)." 48 | {:added "1.1"} 49 | ([tr] (print-stack-trace tr nil)) 50 | ([^Throwable tr n] 51 | (let [^StackTraceElement st (.getStackTrace tr)] 52 | (print-throwable tr) 53 | (newline) 54 | (print " at ") 55 | (if-let [e (first st)] 56 | (print-trace-element e) 57 | (print "[empty stack trace]")) 58 | (newline) 59 | (doseq [e (if (nil? n) 60 | (rest st) 61 | (take (dec n) (rest st)))] 62 | (print " ") 63 | (print-trace-element e) 64 | (newline))))) 65 | 66 | (defn print-cause-trace 67 | "Like print-stack-trace but prints chained exceptions (causes)." 68 | {:added "1.1"} 69 | ([^Throwable tr] (print-cause-trace tr nil)) 70 | ([^Throwable tr n] 71 | (print-stack-trace tr n) 72 | (when-let [cause (.getCause tr)] 73 | (print "Caused by: " ) 74 | (recur cause n)))) 75 | 76 | (defn e 77 | "REPL utility. Prints a brief stack trace for the root cause of the 78 | most recent exception." 79 | {:added "1.1"} 80 | [] 81 | (print-stack-trace (root-cause *e) 8)) 82 | -------------------------------------------------------------------------------- /src/clj/clojure/template.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;; template.clj - anonymous functions that pre-evaluate sub-expressions 10 | 11 | ;; By Stuart Sierra 12 | ;; June 23, 2009 13 | 14 | ;; CHANGE LOG 15 | ;; 16 | ;; June 23, 2009: complete rewrite, eliminated _1,_2,... argument 17 | ;; syntax 18 | ;; 19 | ;; January 20, 2009: added "template?" and checks for valid template 20 | ;; expressions. 21 | ;; 22 | ;; December 15, 2008: first version 23 | 24 | (ns ^{:doc "Macros that expand to repeated copies of a template expression." 25 | :author "Stuart Sierra"} 26 | clojure.template 27 | (:require [clojure.walk :as walk])) 28 | 29 | (defn apply-template 30 | "For use in macros. argv is an argument list, as in defn. expr is 31 | a quoted expression using the symbols in argv. values is a sequence 32 | of values to be used for the arguments. 33 | 34 | apply-template will recursively replace argument symbols in expr 35 | with their corresponding values, returning a modified expr. 36 | 37 | Example: (apply-template '[x] '(+ x x) '[2]) 38 | ;=> (+ 2 2)" 39 | [argv expr values] 40 | (assert (vector? argv)) 41 | (assert (every? symbol? argv)) 42 | (walk/prewalk-replace (zipmap argv values) expr)) 43 | 44 | (defmacro do-template 45 | "Repeatedly copies expr (in a do block) for each group of arguments 46 | in values. values are automatically partitioned by the number of 47 | arguments in argv, an argument vector as in defn. 48 | 49 | Example: (macroexpand '(do-template [x y] (+ y x) 2 4 3 5)) 50 | ;=> (do (+ 4 2) (+ 5 3))" 51 | [argv expr & values] 52 | (let [c (count argv)] 53 | `(do ~@(map (fn [a] (apply-template argv expr a)) 54 | (partition c values))))) 55 | -------------------------------------------------------------------------------- /src/clj/clojure/uuid.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.uuid) 10 | 11 | (defn- default-uuid-reader [form] 12 | {:pre [(string? form)]} 13 | (java.util.UUID/fromString form)) 14 | 15 | (defmethod print-method java.util.UUID [uuid ^java.io.Writer w] 16 | (.write w (str "#uuid \"" (str uuid) "\""))) 17 | 18 | (defmethod print-dup java.util.UUID [o w] 19 | (print-method o w)) 20 | -------------------------------------------------------------------------------- /src/ffi/ffi.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | #include "ffi_arm64.h" 4 | 5 | 6 | #endif 7 | #ifdef __i386__ 8 | 9 | #include "ffi_i386.h" 10 | 11 | 12 | #endif 13 | #ifdef __arm__ 14 | 15 | #include "ffi_armv7.h" 16 | 17 | 18 | #endif 19 | #ifdef __x86_64__ 20 | 21 | #include "ffi_x86_64.h" 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/ffi/fficonfig.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | #include 4 | 5 | 6 | #endif 7 | #ifdef __i386__ 8 | 9 | #include 10 | 11 | 12 | #endif 13 | #ifdef __arm__ 14 | 15 | #include 16 | 17 | 18 | #endif 19 | #ifdef __x86_64__ 20 | 21 | #include 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/ffi/ffitarget.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | #include "ffitarget_arm64.h" 4 | 5 | 6 | #endif 7 | #ifdef __i386__ 8 | 9 | #include "ffitarget_i386.h" 10 | 11 | 12 | #endif 13 | #ifdef __arm__ 14 | 15 | #include "ffitarget_armv7.h" 16 | 17 | 18 | #endif 19 | #ifdef __x86_64__ 20 | 21 | #include "ffitarget_x86_64.h" 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/ffi/ffitarget_arm64.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | ``Software''), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23 | 24 | #ifndef LIBFFI_TARGET_H 25 | #define LIBFFI_TARGET_H 26 | 27 | #ifndef LIBFFI_H 28 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 29 | #endif 30 | 31 | #ifndef LIBFFI_ASM 32 | typedef unsigned long ffi_arg; 33 | typedef signed long ffi_sarg; 34 | 35 | typedef enum ffi_abi 36 | { 37 | FFI_FIRST_ABI = 0, 38 | FFI_SYSV, 39 | FFI_LAST_ABI, 40 | FFI_DEFAULT_ABI = FFI_SYSV 41 | } ffi_abi; 42 | #endif 43 | 44 | /* ---- Definitions for closures ----------------------------------------- */ 45 | 46 | #define FFI_CLOSURES 1 47 | #define FFI_TRAMPOLINE_SIZE 36 48 | #define FFI_NATIVE_RAW_API 0 49 | 50 | /* ---- Internal ---- */ 51 | 52 | 53 | #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_flags 54 | 55 | #define AARCH64_FFI_WITH_V_BIT 0 56 | 57 | #define AARCH64_N_XREG 32 58 | #define AARCH64_N_VREG 32 59 | #define AARCH64_CALL_CONTEXT_SIZE (AARCH64_N_XREG * 8 + AARCH64_N_VREG * 16) 60 | 61 | #endif 62 | 63 | 64 | #endif -------------------------------------------------------------------------------- /src/ffi/ffitarget_armv7.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm__ 2 | 3 | /* -----------------------------------------------------------------*-C-*- 4 | ffitarget.h - Copyright (c) 2012 Anthony Green 5 | Copyright (c) 2010 CodeSourcery 6 | Copyright (c) 1996-2003 Red Hat, Inc. 7 | 8 | Target configuration macros for ARM. 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining 11 | a copy of this software and associated documentation files (the 12 | ``Software''), to deal in the Software without restriction, including 13 | without limitation the rights to use, copy, modify, merge, publish, 14 | distribute, sublicense, and/or sell copies of the Software, and to 15 | permit persons to whom the Software is furnished to do so, subject to 16 | the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included 19 | in all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 25 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 26 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 | DEALINGS IN THE SOFTWARE. 29 | 30 | ----------------------------------------------------------------------- */ 31 | 32 | #ifndef LIBFFI_TARGET_H 33 | #define LIBFFI_TARGET_H 34 | 35 | #ifndef LIBFFI_H 36 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 37 | #endif 38 | 39 | #ifndef LIBFFI_ASM 40 | typedef unsigned long ffi_arg; 41 | typedef signed long ffi_sarg; 42 | 43 | typedef enum ffi_abi { 44 | FFI_FIRST_ABI = 0, 45 | FFI_SYSV, 46 | FFI_VFP, 47 | FFI_LAST_ABI, 48 | #ifdef __ARM_PCS_VFP 49 | FFI_DEFAULT_ABI = FFI_VFP, 50 | #else 51 | FFI_DEFAULT_ABI = FFI_SYSV, 52 | #endif 53 | } ffi_abi; 54 | #endif 55 | 56 | #define FFI_EXTRA_CIF_FIELDS \ 57 | int vfp_used; \ 58 | short vfp_reg_free, vfp_nargs; \ 59 | signed char vfp_args[16] \ 60 | 61 | /* Internally used. */ 62 | #define FFI_TYPE_STRUCT_VFP_FLOAT (FFI_TYPE_LAST + 1) 63 | #define FFI_TYPE_STRUCT_VFP_DOUBLE (FFI_TYPE_LAST + 2) 64 | 65 | #define FFI_TARGET_SPECIFIC_VARIADIC 66 | 67 | /* ---- Definitions for closures ----------------------------------------- */ 68 | 69 | #define FFI_CLOSURES 1 70 | #define FFI_TRAMPOLINE_SIZE 20 71 | #define FFI_NATIVE_RAW_API 0 72 | 73 | #endif 74 | 75 | 76 | #endif -------------------------------------------------------------------------------- /src/ffi/libffi.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/galdolber/clojure-objc/a56dca4ea3825e1c7d57a822f3996dbbb3620cff/src/ffi/libffi.a -------------------------------------------------------------------------------- /src/jvm/clojure/asm/commons/TableSwitchGenerator.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package clojure.asm.commons; 31 | 32 | import clojure.asm.Label; 33 | 34 | /** 35 | * A code generator for switch statements. 36 | * 37 | * @author Juozas Baliuka 38 | * @author Chris Nokleberg 39 | * @author Eric Bruneton 40 | */ 41 | public interface TableSwitchGenerator { 42 | 43 | /** 44 | * Generates the code for a switch case. 45 | * 46 | * @param key 47 | * the switch case key. 48 | * @param end 49 | * a label that corresponds to the end of the switch statement. 50 | */ 51 | void generateCase(int key, Label end); 52 | 53 | /** 54 | * Generates the code for the default switch case. 55 | */ 56 | void generateDefault(); 57 | } 58 | -------------------------------------------------------------------------------- /src/jvm/clojure/asm/commons/package.html: -------------------------------------------------------------------------------- 1 | 2 | 31 | 32 | Provides some useful class and method adapters. The preferred way of using 33 | these adapters is by chaining them together and to custom adapters (instead of 34 | inheriting from them). Indeed this approach provides more combination 35 | possibilities than inheritance. For instance, suppose you want to implement an 36 | adapter MyAdapter than needs sorted local variables and intermediate stack map 37 | frame values taking into account the local variables sort. By using inheritance, 38 | this would require MyAdapter to extend AnalyzerAdapter, itself extending 39 | LocalVariablesSorter. But AnalyzerAdapter is not a subclass of 40 | LocalVariablesSorter, so this is not possible. On the contrary, by using 41 | delegation, you can make LocalVariablesSorter delegate to AnalyzerAdapter, 42 | itself delegating to MyAdapter. In this case AnalyzerAdapter computes 43 | intermediate frames based on the output of LocalVariablesSorter, and MyAdapter 44 | can add new locals by calling the newLocal method on LocalVariablesSorter, and 45 | can get the stack map frame state before each instruction by reading the locals 46 | and stack fields in AnalyzerAdapter (this requires references from MyAdapter 47 | back to LocalVariablesSorter and AnalyzerAdapter). 48 | -------------------------------------------------------------------------------- /src/jvm/clojure/java/api/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | Clojure interop from Java. 14 | 15 |

The clojure.java.api package provides a minimal interface to bootstrap 16 | Clojure access from other JVM languages. It does this by providing: 17 |

18 | 19 |
    20 |
  1. The ability to use Clojure's namespaces to locate an arbitrary 21 | var, returning the 22 | var's clojure.lang.IFn interface.
  2. 23 |
  3. A convenience method read for reading data using 24 | Clojure's edn reader
  4. 25 |
26 | 27 |

IFns provide complete access to 28 | Clojure's APIs. 29 | You can also access any other library written in Clojure, after adding 30 | either its source or compiled form to the classpath.

31 | 32 |

The public Java API for Clojure consists of the following classes 33 | and interfaces: 34 |

35 | 36 |
    37 |
  1. clojure.java.api.Clojure
  2. 38 |
  3. clojure.lang.IFn
  4. 39 |
40 | 41 |

All other Java classes should be treated as implementation details, 42 | and applications should avoid relying on them.

43 | 44 |

To lookup and call a Clojure function: 45 |

46 | IFn plus = Clojure.var("clojure.core", "+");
47 | plus.invoke(1, 2);
48 | 
49 |

50 | 51 |

Functions in clojure.core are automatically loaded. Other 52 | namespaces can be loaded via require: 53 |

54 | IFn require = Clojure.var("clojure.core", "require");
55 | require.invoke(Clojure.read("clojure.set"));
56 | 
57 |

58 | 59 |

IFns can be passed to higher order functions, e.g. the 60 | example below passes plus to read: 61 |

62 | IFn map = Clojure.var("clojure.core", "map");
63 | IFn inc = Clojure.var("clojure.core", "inc");
64 | map.invoke(inc, Clojure.read("[1 2 3]"));
65 | 
66 |

67 | 68 |

Most IFns in Clojure refer to functions. A few, however, refer to 69 | non-function data values. To access these, use deref 70 | instead of fn:

71 | 72 |
73 | IFn printLength = Clojure.var("clojure.core", "*print-length*");
74 | IFn deref = Clojure.var("clojure.core", "deref");
75 | deref.invoke(printLength);
76 | 
77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/AFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 16, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | import java.util.Comparator; 17 | 18 | public abstract class AFunction extends AFn implements IObj, Comparator, Fn, Serializable { 19 | 20 | public volatile MethodImplCache __methodImplCache; 21 | 22 | public IPersistentMap meta(){ 23 | return null; 24 | } 25 | 26 | public IObj withMeta(final IPersistentMap meta){ 27 | return new RestFnWithMeta(this, meta); 28 | } 29 | 30 | public int compare(Object o1, Object o2){ 31 | Object o = invoke(o1, o2); 32 | 33 | if(o instanceof Boolean) 34 | { 35 | if(RT.booleanCast(o)) 36 | return -1; 37 | return RT.booleanCast(invoke(o2,o1))? 1 : 0; 38 | } 39 | 40 | Number n = (Number) o; 41 | return n.intValue(); 42 | } 43 | 44 | @Override 45 | public boolean equals(Object f) { 46 | return this == f; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ARef.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jan 1, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Map; 16 | 17 | public abstract class ARef extends AReference implements IRef{ 18 | protected volatile IFn validator = null; 19 | private volatile IPersistentMap watches = PersistentHashMap.EMPTY; 20 | 21 | public ARef(){ 22 | super(); 23 | } 24 | 25 | public ARef(IPersistentMap meta){ 26 | super(meta); 27 | } 28 | 29 | void validate(IFn vf, Object val){ 30 | try 31 | { 32 | if(vf != null && !RT.booleanCast(vf.invoke(val))) 33 | throw new IllegalStateException("Invalid reference state"); 34 | } 35 | catch(RuntimeException re) 36 | { 37 | throw re; 38 | } 39 | catch(Exception e) 40 | { 41 | throw new IllegalStateException("Invalid reference state", e); 42 | } 43 | } 44 | 45 | void validate(Object val){ 46 | validate(validator, val); 47 | } 48 | 49 | public void setValidator(IFn vf){ 50 | validate(vf, deref()); 51 | validator = vf; 52 | } 53 | 54 | public IFn getValidator(){ 55 | return validator; 56 | } 57 | 58 | public IPersistentMap getWatches(){ 59 | return watches; 60 | } 61 | 62 | synchronized public IRef addWatch(Object key, IFn callback){ 63 | watches = watches.assoc(key, callback); 64 | return this; 65 | } 66 | 67 | synchronized public IRef removeWatch(Object key){ 68 | watches = watches.without(key); 69 | return this; 70 | } 71 | 72 | public void notifyWatches(Object oldval, Object newval){ 73 | IPersistentMap ws = watches; 74 | if(ws.count() > 0) 75 | { 76 | for(ISeq s = ws.seq(); s != null; s = s.next()) 77 | { 78 | Map.Entry e = (Map.Entry) s.first(); 79 | IFn fn = (IFn) e.getValue(); 80 | if(fn != null) 81 | fn.invoke(e.getKey(), this, oldval, newval); 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/AReference.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public class AReference implements IReference { 16 | private IPersistentMap _meta; 17 | 18 | public AReference() { 19 | this(null); 20 | } 21 | 22 | public AReference(IPersistentMap meta) { 23 | _meta = meta; 24 | } 25 | 26 | synchronized public IPersistentMap meta() { 27 | return _meta; 28 | } 29 | 30 | synchronized public IPersistentMap alterMeta(IFn alter, ISeq args) { 31 | _meta = (IPersistentMap) alter.applyTo(new Cons(_meta, args)); 32 | return _meta; 33 | } 34 | 35 | synchronized public IPersistentMap resetMeta(IPersistentMap m) { 36 | _meta = m; 37 | return m; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ATransientMap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | import java.util.Map; 14 | 15 | import clojure.lang.PersistentHashMap.INode; 16 | 17 | abstract class ATransientMap extends AFn implements ITransientMap { 18 | abstract void ensureEditable(); 19 | abstract ITransientMap doAssoc(Object key, Object val); 20 | abstract ITransientMap doWithout(Object key); 21 | abstract Object doValAt(Object key, Object notFound); 22 | abstract int doCount(); 23 | abstract IPersistentMap doPersistent(); 24 | 25 | public ITransientMap conj(Object o) { 26 | ensureEditable(); 27 | if(o instanceof Map.Entry) 28 | { 29 | Map.Entry e = (Map.Entry) o; 30 | 31 | return assoc(e.getKey(), e.getValue()); 32 | } 33 | else if(o instanceof IPersistentVector) 34 | { 35 | IPersistentVector v = (IPersistentVector) o; 36 | if(v.count() != 2) 37 | throw new IllegalArgumentException("Vector arg to map conj must be a pair"); 38 | return assoc(v.nth(0), v.nth(1)); 39 | } 40 | 41 | ITransientMap ret = this; 42 | for(ISeq es = RT.seq(o); es != null; es = es.next()) 43 | { 44 | Map.Entry e = (Map.Entry) es.first(); 45 | ret = ret.assoc(e.getKey(), e.getValue()); 46 | } 47 | return ret; 48 | } 49 | 50 | public final Object invoke(Object arg1) { 51 | return valAt(arg1); 52 | } 53 | 54 | public final Object invoke(Object arg1, Object notFound) { 55 | return valAt(arg1, notFound); 56 | } 57 | 58 | public final Object valAt(Object key) { 59 | return valAt(key, null); 60 | } 61 | 62 | public final ITransientMap assoc(Object key, Object val) { 63 | ensureEditable(); 64 | return doAssoc(key, val); 65 | } 66 | 67 | public final ITransientMap without(Object key) { 68 | ensureEditable(); 69 | return doWithout(key); 70 | } 71 | 72 | public final IPersistentMap persistent() { 73 | ensureEditable(); 74 | return doPersistent(); 75 | } 76 | 77 | public final Object valAt(Object key, Object notFound) { 78 | ensureEditable(); 79 | return doValAt(key, notFound); 80 | } 81 | 82 | public final int count() { 83 | ensureEditable(); 84 | return doCount(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ATransientSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public abstract class ATransientSet extends AFn implements ITransientSet{ 16 | volatile ITransientMap impl; 17 | 18 | ATransientSet(ITransientMap impl) { 19 | this.impl = impl; 20 | } 21 | 22 | public int count() { 23 | return impl.count(); 24 | } 25 | 26 | public ITransientSet conj(Object val) { 27 | ITransientMap m = impl.assoc(val, val); 28 | if (m != impl) this.impl = m; 29 | return this; 30 | } 31 | 32 | public boolean contains(Object key) { 33 | return this != impl.valAt(key, this); 34 | } 35 | 36 | public ITransientSet disjoin(Object key) { 37 | ITransientMap m = impl.without(key); 38 | if (m != impl) this.impl = m; 39 | return this; 40 | } 41 | 42 | public Object get(Object key) { 43 | return impl.valAt(key); 44 | } 45 | 46 | public Object invoke(Object key, Object notFound) { 47 | return impl.valAt(key, notFound); 48 | } 49 | 50 | public Object invoke(Object key) { 51 | return impl.valAt(key); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ArityException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | /** 14 | * @since 1.3 15 | */ 16 | public class ArityException extends IllegalArgumentException { 17 | 18 | final public int actual; 19 | 20 | final public String name; 21 | 22 | public ArityException(int actual, String name) { 23 | this(actual, name, null); 24 | } 25 | 26 | public ArityException(int actual, String name, Throwable cause) { 27 | super("Wrong number of args (" + actual + ") passed to: " + name, cause); 28 | this.actual = actual; 29 | this.name = name; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ArrayChunk.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 24, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | 17 | public final class ArrayChunk implements IChunk, Serializable { 18 | 19 | final Object[] array; 20 | final int off; 21 | final int end; 22 | 23 | public ArrayChunk(Object[] array){ 24 | this(array, 0, array.length); 25 | } 26 | 27 | public ArrayChunk(Object[] array, int off){ 28 | this(array, off, array.length); 29 | } 30 | 31 | public ArrayChunk(Object[] array, int off, int end){ 32 | this.array = array; 33 | this.off = off; 34 | this.end = end; 35 | } 36 | 37 | public Object nth(int i){ 38 | return array[off + i]; 39 | } 40 | 41 | public Object nth(int i, Object notFound){ 42 | if(i >= 0 && i < count()) 43 | return nth(i); 44 | return notFound; 45 | } 46 | 47 | public int count(){ 48 | return end - off; 49 | } 50 | 51 | public IChunk dropFirst(){ 52 | if(off==end) 53 | throw new IllegalStateException("dropFirst of empty chunk"); 54 | return new ArrayChunk(array, off + 1, end); 55 | } 56 | 57 | public Object reduce(IFn f, Object start) { 58 | Object ret = f.invoke(start, array[off]); 59 | if(RT.isReduced(ret)) 60 | return ret; 61 | for(int x = off + 1; x < end; x++) 62 | { 63 | ret = f.invoke(ret, array[x]); 64 | if(RT.isReduced(ret)) 65 | return ret; 66 | } 67 | return ret; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Associative.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | /** 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | */ 12 | public interface Associative extends IPersistentCollection, ILookup{ 13 | boolean containsKey(Object key); 14 | 15 | IMapEntry entryAt(Object key); 16 | 17 | Associative assoc(Object key, Object val); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Atom.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jan 1, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.concurrent.atomic.AtomicReference; 16 | 17 | final public class Atom extends ARef implements IAtom{ 18 | final AtomicReference state; 19 | 20 | public Atom(Object state){ 21 | this.state = new AtomicReference(state); 22 | } 23 | 24 | public Atom(Object state, IPersistentMap meta){ 25 | super(meta); 26 | this.state = new AtomicReference(state); 27 | } 28 | 29 | public Object deref(){ 30 | return state.get(); 31 | } 32 | 33 | public Object swap(IFn f) { 34 | for(; ;) 35 | { 36 | Object v = deref(); 37 | Object newv = f.invoke(v); 38 | validate(newv); 39 | if(state.compareAndSet(v, newv)) 40 | { 41 | notifyWatches(v, newv); 42 | return newv; 43 | } 44 | } 45 | } 46 | 47 | public Object swap(IFn f, Object arg) { 48 | for(; ;) 49 | { 50 | Object v = deref(); 51 | Object newv = f.invoke(v, arg); 52 | validate(newv); 53 | if(state.compareAndSet(v, newv)) 54 | { 55 | notifyWatches(v, newv); 56 | return newv; 57 | } 58 | } 59 | } 60 | 61 | public Object swap(IFn f, Object arg1, Object arg2) { 62 | for(; ;) 63 | { 64 | Object v = deref(); 65 | Object newv = f.invoke(v, arg1, arg2); 66 | validate(newv); 67 | if(state.compareAndSet(v, newv)) 68 | { 69 | notifyWatches(v, newv); 70 | return newv; 71 | } 72 | } 73 | } 74 | 75 | public Object swap(IFn f, Object x, Object y, ISeq args) { 76 | for(; ;) 77 | { 78 | Object v = deref(); 79 | Object newv = f.applyTo(RT.listStar(v, x, y, args)); 80 | validate(newv); 81 | if(state.compareAndSet(v, newv)) 82 | { 83 | notifyWatches(v, newv); 84 | return newv; 85 | } 86 | } 87 | } 88 | 89 | public boolean compareAndSet(Object oldv, Object newv){ 90 | validate(newv); 91 | boolean ret = state.compareAndSet(oldv, newv); 92 | if(ret) 93 | notifyWatches(oldv, newv); 94 | return ret; 95 | } 96 | 97 | public Object reset(Object newval){ 98 | Object oldval = state.get(); 99 | validate(newval); 100 | state.set(newval); 101 | notifyWatches(oldval, newval); 102 | return newval; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Binding.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | public class Binding{ 14 | public T val; 15 | public final Binding rest; 16 | 17 | public Binding(T val){ 18 | this.val = val; 19 | this.rest = null; 20 | } 21 | 22 | public Binding(T val, Binding rest){ 23 | this.val = val; 24 | this.rest = rest; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Box.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 27, 2006 8:40:19 PM */ 12 | 13 | package clojure.lang; 14 | 15 | public class Box{ 16 | 17 | public Object val; 18 | 19 | public Box(Object val){ 20 | this.val = val; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ChunkBuffer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 26, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | final public class ChunkBuffer implements Counted{ 16 | Object[] buffer; 17 | int end; 18 | 19 | public ChunkBuffer(int capacity){ 20 | buffer = new Object[capacity]; 21 | end = 0; 22 | } 23 | 24 | public void add(Object o){ 25 | buffer[end++] = o; 26 | } 27 | 28 | public IChunk chunk(){ 29 | ArrayChunk ret = new ArrayChunk(buffer, 0, end); 30 | buffer = null; 31 | return ret; 32 | } 33 | 34 | public int count(){ 35 | return end; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ChunkedCons.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 25, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | final public class ChunkedCons extends ASeq implements IChunkedSeq{ 16 | 17 | final IChunk chunk; 18 | final ISeq _more; 19 | 20 | ChunkedCons(IPersistentMap meta, IChunk chunk, ISeq more){ 21 | super(meta); 22 | this.chunk = chunk; 23 | this._more = more; 24 | } 25 | 26 | public ChunkedCons(IChunk chunk, ISeq more){ 27 | this(null,chunk, more); 28 | } 29 | 30 | public Obj withMeta(IPersistentMap meta){ 31 | if(meta != _meta) 32 | return new ChunkedCons(meta, chunk, _more); 33 | return this; 34 | } 35 | 36 | public Object first(){ 37 | return chunk.nth(0); 38 | } 39 | 40 | public ISeq next(){ 41 | if(chunk.count() > 1) 42 | return new ChunkedCons(chunk.dropFirst(), _more); 43 | return chunkedNext(); 44 | } 45 | 46 | public ISeq more(){ 47 | if(chunk.count() > 1) 48 | return new ChunkedCons(chunk.dropFirst(), _more); 49 | if(_more == null) 50 | return PersistentList.EMPTY; 51 | return _more; 52 | } 53 | 54 | public IChunk chunkedFirst(){ 55 | return chunk; 56 | } 57 | 58 | public ISeq chunkedNext(){ 59 | return chunkedMore().seq(); 60 | } 61 | 62 | public ISeq chunkedMore(){ 63 | if(_more == null) 64 | return PersistentList.EMPTY; 65 | return _more; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Cons.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 25, 2006 11:01:29 AM */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | 17 | final public class Cons extends ASeq implements Serializable { 18 | 19 | private final Object _first; 20 | private final ISeq _more; 21 | 22 | public Cons(Object first, ISeq _more){ 23 | this._first = first; 24 | this._more = _more; 25 | } 26 | 27 | 28 | public Cons(IPersistentMap meta, Object _first, ISeq _more){ 29 | super(meta); 30 | this._first = _first; 31 | this._more = _more; 32 | } 33 | 34 | public Object first(){ 35 | return _first; 36 | } 37 | 38 | public ISeq next(){ 39 | return more().seq(); 40 | } 41 | 42 | public ISeq more(){ 43 | if(_more == null) 44 | return PersistentList.EMPTY; 45 | return _more; 46 | } 47 | 48 | public int count(){ 49 | return 1 + RT.count(_more); 50 | } 51 | 52 | public Cons withMeta(IPersistentMap meta){ 53 | return new Cons(meta, _first, _more); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Counted.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | /** 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | */ 12 | 13 | /* A class that implements Counted promises that it is a collection 14 | * that implement a constant-time count() */ 15 | 16 | public interface Counted { 17 | int count(); 18 | } 19 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Cycle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | /* Alex Miller, Dec 5, 2014 */ 14 | 15 | public class Cycle extends ASeq implements IReduce, IPending { 16 | 17 | private final ISeq all; // never null 18 | private final ISeq prev; 19 | private volatile ISeq _current; // lazily realized 20 | private volatile ISeq _next; // cached 21 | 22 | private Cycle(ISeq all, ISeq prev, ISeq current){ 23 | this.all = all; 24 | this.prev = prev; 25 | this._current = current; 26 | } 27 | 28 | private Cycle(IPersistentMap meta, ISeq all, ISeq prev, ISeq current, ISeq next){ 29 | super(meta); 30 | this.all = all; 31 | this.prev = prev; 32 | this._current = current; 33 | this._next = next; 34 | } 35 | 36 | public static ISeq create(ISeq vals){ 37 | if(vals == null) 38 | return PersistentList.EMPTY; 39 | return new Cycle(vals, null, vals); 40 | } 41 | 42 | // realization for use of current 43 | private ISeq current() { 44 | if(_current == null) { 45 | ISeq current = prev.next(); 46 | _current = (current == null) ? all : current; 47 | } 48 | return _current; 49 | } 50 | 51 | public boolean isRealized() { 52 | return _current != null; 53 | } 54 | 55 | public Object first(){ 56 | return current().first(); 57 | } 58 | 59 | public ISeq next(){ 60 | if(_next == null) 61 | _next = new Cycle(all, current(), null); 62 | return _next; 63 | } 64 | 65 | public Cycle withMeta(IPersistentMap meta){ 66 | return new Cycle(meta, all, prev, _current, _next); 67 | } 68 | 69 | public Object reduce(IFn f){ 70 | ISeq s = current(); 71 | Object ret = s.first(); 72 | while(true) { 73 | s = s.next(); 74 | if(s == null) 75 | s = all; 76 | ret = f.invoke(ret, s.first()); 77 | if(RT.isReduced(ret)) 78 | return ((IDeref)ret).deref(); 79 | } 80 | } 81 | 82 | public Object reduce(IFn f, Object start){ 83 | Object ret = start; 84 | ISeq s = current(); 85 | while(true){ 86 | ret = f.invoke(ret, s.first()); 87 | if(RT.isReduced(ret)) 88 | return ((IDeref)ret).deref(); 89 | s = s.next(); 90 | if(s == null) 91 | s = all; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Delay.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jun 28, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public class Delay implements IDeref, IPending{ 16 | Object val; 17 | Throwable exception; 18 | IFn fn; 19 | 20 | public Delay(IFn fn){ 21 | this.fn = fn; 22 | this.val = null; 23 | this.exception = null; 24 | } 25 | 26 | static public Object force(Object x) { 27 | return (x instanceof Delay) ? 28 | ((Delay) x).deref() 29 | : x; 30 | } 31 | 32 | synchronized public Object deref() { 33 | if(fn != null) 34 | { 35 | try 36 | { 37 | val = fn.invoke(); 38 | } 39 | catch(Throwable t) 40 | { 41 | exception = t; 42 | } 43 | fn = null; 44 | } 45 | if(exception != null) 46 | throw Util.sneakyThrow(exception); 47 | return val; 48 | } 49 | 50 | synchronized public boolean isRealized(){ 51 | return fn == null; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/EnumerationSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.IOException; 16 | import java.io.NotSerializableException; 17 | import java.util.Enumeration; 18 | 19 | public class EnumerationSeq extends ASeq{ 20 | final Enumeration iter; 21 | final State state; 22 | 23 | static class State{ 24 | volatile Object val; 25 | volatile Object _rest; 26 | } 27 | 28 | public static EnumerationSeq create(Enumeration iter){ 29 | if(iter.hasMoreElements()) 30 | return new EnumerationSeq(iter); 31 | return null; 32 | } 33 | 34 | EnumerationSeq(Enumeration iter){ 35 | this.iter = iter; 36 | state = new State(); 37 | this.state.val = state; 38 | this.state._rest = state; 39 | } 40 | 41 | EnumerationSeq(IPersistentMap meta, Enumeration iter, State state){ 42 | super(meta); 43 | this.iter = iter; 44 | this.state = state; 45 | } 46 | 47 | public Object first(){ 48 | if(state.val == state) 49 | synchronized(state) 50 | { 51 | if(state.val == state) 52 | state.val = iter.nextElement(); 53 | } 54 | return state.val; 55 | } 56 | 57 | public ISeq next(){ 58 | if(state._rest == state) 59 | synchronized(state) 60 | { 61 | if(state._rest == state) 62 | { 63 | first(); 64 | state._rest = create(iter); 65 | } 66 | } 67 | return (ISeq) state._rest; 68 | } 69 | 70 | public EnumerationSeq withMeta(IPersistentMap meta){ 71 | return new EnumerationSeq(meta, iter, state); 72 | } 73 | 74 | private void writeObject (java.io.ObjectOutputStream out) throws IOException { 75 | throw new NotSerializableException(getClass().getName()); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ExceptionInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | /** 14 | * Exception that carries data (a map) as additional payload. Clojure programs that need 15 | * richer semantics for exceptions should use this in lieu of defining project-specific 16 | * exception classes. 17 | */ 18 | public class ExceptionInfo extends RuntimeException implements IExceptionInfo { 19 | public final IPersistentMap data; 20 | 21 | public ExceptionInfo(String s, IPersistentMap data) { 22 | super(s); 23 | if (data instanceof IPersistentMap) { 24 | this.data = data; 25 | } else { 26 | throw new IllegalArgumentException("Additional data must be a persistent map: " + data); 27 | } 28 | } 29 | 30 | public ExceptionInfo(String s, IPersistentMap data, Throwable throwable) { 31 | super(s, throwable); 32 | this.data = data; 33 | } 34 | 35 | public IPersistentMap getData() { 36 | return data; 37 | } 38 | 39 | public String toString() { 40 | return "clojure.lang.ExceptionInfo: " + getMessage() + " " + data.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Fn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 25, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface Fn{ 16 | } 17 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/FnLoaderThunk.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich 2/28/11 */ 12 | 13 | package clojure.lang; 14 | 15 | public class FnLoaderThunk extends RestFn{ 16 | 17 | final Var v; 18 | final ClassLoader loader; 19 | final String fnClassName; 20 | IFn fn; 21 | 22 | public FnLoaderThunk(Var v, String fnClassName){ 23 | this.v = v; 24 | this.loader = (ClassLoader) RT.FN_LOADER_VAR.get(); 25 | this.fnClassName = fnClassName; 26 | fn = null; 27 | } 28 | 29 | public Object invoke(Object arg1) { 30 | load(); 31 | return fn.invoke(arg1); 32 | } 33 | 34 | public Object invoke(Object arg1, Object arg2) { 35 | load(); 36 | return fn.invoke(arg1,arg2); 37 | } 38 | 39 | public Object invoke(Object arg1, Object arg2, Object arg3) { 40 | load(); 41 | return fn.invoke(arg1,arg2,arg3); 42 | } 43 | 44 | protected Object doInvoke(Object args) { 45 | load(); 46 | return fn.applyTo((ISeq) args); 47 | } 48 | 49 | private void load() { 50 | if(fn == null) 51 | { 52 | try 53 | { 54 | fn = (IFn) Class.forName(fnClassName,true,loader).newInstance(); 55 | } 56 | catch(Exception e) 57 | { 58 | throw Util.sneakyThrow(e); 59 | } 60 | v.root = fn; 61 | } 62 | } 63 | 64 | public int getRequiredArity(){ 65 | return 0; 66 | } 67 | 68 | public IObj withMeta(IPersistentMap meta){ 69 | return this; 70 | } 71 | 72 | public IPersistentMap meta(){ 73 | return null; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IAtom.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Aug 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IAtom{ 16 | Object swap(IFn f); 17 | 18 | Object swap(IFn f, Object arg); 19 | 20 | Object swap(IFn f, Object arg1, Object arg2); 21 | 22 | Object swap(IFn f, Object x, Object y, ISeq args); 23 | 24 | boolean compareAndSet(Object oldv, Object newv); 25 | 26 | Object reset(Object newval); 27 | } 28 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IBlockingDeref.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich 3/18/11 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IBlockingDeref{ 16 | Object deref(long ms, Object timeoutValue) ; 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IChunk.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jun 18, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IChunk extends Indexed{ 16 | 17 | IChunk dropFirst(); 18 | 19 | Object reduce(IFn f, Object start) ; 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IChunkedSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 24, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IChunkedSeq extends ISeq, Sequential { 16 | 17 | IChunk chunkedFirst() ; 18 | 19 | ISeq chunkedNext() ; 20 | 21 | ISeq chunkedMore() ; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IDeref.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Feb 9, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IDeref{ 16 | Object deref() ; 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IEditableCollection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IEditableCollection{ 16 | ITransientCollection asTransient(); 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IExceptionInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | /** 14 | * Interface for exceptions that carry data (a map) as additional payload. Clojure 15 | * programs that need richer semantics for exceptions should use this in lieu of 16 | * defining project-specific exception classes. 17 | */ 18 | public interface IExceptionInfo { 19 | public IPersistentMap getData(); 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IHashEq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich 10/23/11 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IHashEq{ 16 | int hasheq(); 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IKeywordLookup.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Oct 31, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IKeywordLookup{ 16 | ILookupThunk getLookupThunk(Keyword k); 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ILookup.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Aug 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ILookup{ 16 | Object valAt(Object key); 17 | 18 | Object valAt(Object key, Object notFound); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ILookupSite.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ILookupSite{ 16 | 17 | ILookupThunk fault(Object target); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ILookupThunk.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ILookupThunk{ 16 | 17 | Object get(Object target); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IMapEntry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | import java.util.Map; 14 | 15 | public interface IMapEntry extends Map.Entry{ 16 | Object key(); 17 | 18 | Object val(); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IMapIterable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* Alex Miller Dec 3, 2014 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Iterator; 16 | 17 | /** 18 | * Indicate a map can provide more efficient key and val iterators. 19 | */ 20 | public interface IMapIterable { 21 | 22 | Iterator keyIterator(); 23 | 24 | Iterator valIterator(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IMeta.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IMeta { 16 | IPersistentMap meta(); 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IObj.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | 14 | public interface IObj extends IMeta { 15 | 16 | public IObj withMeta(IPersistentMap meta); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPending.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | public interface IPending{ 14 | boolean isRealized(); 15 | } 16 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentCollection.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | /** 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | */ 12 | 13 | 14 | public interface IPersistentCollection extends Seqable { 15 | 16 | int count(); 17 | 18 | IPersistentCollection cons(Object o); 19 | 20 | IPersistentCollection empty(); 21 | 22 | boolean equiv(Object o); 23 | } 24 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentList.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | 14 | public interface IPersistentList extends Sequential, IPersistentStack{ 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentMap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | 14 | public interface IPersistentMap extends Iterable, Associative, Counted{ 15 | 16 | 17 | IPersistentMap assoc(Object key, Object val); 18 | 19 | IPersistentMap assocEx(Object key, Object val) ; 20 | 21 | IPersistentMap without(Object key) ; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IPersistentSet extends IPersistentCollection, Counted{ 16 | public IPersistentSet disjoin(Object key) ; 17 | public boolean contains(Object key); 18 | public Object get(Object key); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentStack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Sep 19, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IPersistentStack extends IPersistentCollection{ 16 | Object peek(); 17 | 18 | IPersistentStack pop(); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentVector.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | /** 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | */ 12 | 13 | public interface IPersistentVector extends Associative, Sequential, IPersistentStack, Reversible, Indexed{ 14 | int length(); 15 | 16 | IPersistentVector assocN(int i, Object val); 17 | 18 | IPersistentVector cons(Object o); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IProxy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Feb 27, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IProxy{ 16 | 17 | public void __initClojureFnMappings(IPersistentMap m); 18 | public void __updateClojureFnMappings(IPersistentMap m); 19 | public IPersistentMap __getClojureFnMappings(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IRecord.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | public interface IRecord { 14 | } 15 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IReduce.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jun 11, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IReduce extends IReduceInit{ 16 | Object reduce(IFn f) ; 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IReduceInit.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | public interface IReduceInit{ 14 | Object reduce(IFn f, Object start) ; 15 | } 16 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IRef.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 18, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IRef extends IDeref{ 16 | 17 | void setValidator(IFn vf); 18 | 19 | IFn getValidator(); 20 | 21 | IPersistentMap getWatches(); 22 | 23 | IRef addWatch(Object key, IFn callback); 24 | 25 | IRef removeWatch(Object key); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IReference.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IReference extends IMeta { 16 | IPersistentMap alterMeta(IFn alter, ISeq args) ; 17 | IPersistentMap resetMeta(IPersistentMap m); 18 | } 19 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ISeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | /** 14 | * A persistent, functional, sequence interface 15 | *

16 | * ISeqs are immutable values, i.e. neither first(), nor rest() changes 17 | * or invalidates the ISeq 18 | */ 19 | public interface ISeq extends IPersistentCollection { 20 | 21 | Object first(); 22 | 23 | ISeq next(); 24 | 25 | ISeq more(); 26 | 27 | ISeq cons(Object o); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientAssociative.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientAssociative extends ITransientCollection, ILookup{ 16 | 17 | ITransientAssociative assoc(Object key, Object val); 18 | } 19 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientCollection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientCollection{ 16 | 17 | ITransientCollection conj(Object val); 18 | 19 | IPersistentCollection persistent(); 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientMap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientMap extends ITransientAssociative, Counted{ 16 | 17 | ITransientMap assoc(Object key, Object val); 18 | 19 | ITransientMap without(Object key); 20 | 21 | IPersistentMap persistent(); 22 | } 23 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientSet extends ITransientCollection, Counted{ 16 | public ITransientSet disjoin(Object key) ; 17 | public boolean contains(Object key); 18 | public Object get(Object key); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientVector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientVector extends ITransientAssociative, Indexed{ 16 | 17 | ITransientVector assocN(int i, Object val); 18 | 19 | ITransientVector pop(); 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | public interface IType { 14 | } 15 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IllegalAccessError.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | import java.lang.RuntimeException; 4 | import java.lang.String; 5 | 6 | public class IllegalAccessError extends RuntimeException { 7 | 8 | public IllegalAccessError(String msg) { 9 | super(msg); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Indexed.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 24, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface Indexed extends Counted{ 16 | Object nth(int i); 17 | 18 | Object nth(int i, Object notFound); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IndexedSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | public interface IndexedSeq extends ISeq, Sequential, Counted{ 14 | 15 | public int index(); 16 | } 17 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Iterate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | /* Alex Miller, Dec 5, 2014 */ 14 | 15 | public class Iterate extends ASeq implements IReduce, IPending { 16 | 17 | private static final Object UNREALIZED_SEED = new Object(); 18 | private final IFn f; // never null 19 | private final Object prevSeed; 20 | private volatile Object _seed; // lazily realized 21 | private volatile ISeq _next; // cached 22 | 23 | private Iterate(IFn f, Object prevSeed, Object seed){ 24 | this.f = f; 25 | this.prevSeed = prevSeed; 26 | this._seed = seed; 27 | } 28 | 29 | private Iterate(IPersistentMap meta, IFn f, Object prevSeed, Object seed, ISeq next){ 30 | super(meta); 31 | this.f = f; 32 | this.prevSeed = prevSeed; 33 | this._seed = seed; 34 | this._next = next; 35 | } 36 | 37 | public static ISeq create(IFn f, Object seed){ 38 | return new Iterate(f, null, seed); 39 | } 40 | 41 | public boolean isRealized() { 42 | return _seed != UNREALIZED_SEED; 43 | } 44 | 45 | public Object first(){ 46 | if(_seed == UNREALIZED_SEED) { 47 | _seed = f.invoke(prevSeed); 48 | } 49 | return _seed; 50 | } 51 | 52 | public ISeq next(){ 53 | if(_next == null) { 54 | _next = new Iterate(f, first(), UNREALIZED_SEED); 55 | } 56 | return _next; 57 | } 58 | 59 | public Iterate withMeta(IPersistentMap meta){ 60 | return new Iterate(meta, f, prevSeed, _seed, _next); 61 | } 62 | 63 | public Object reduce(IFn rf){ 64 | Object first = first(); 65 | Object ret = first; 66 | Object v = f.invoke(first); 67 | while(true){ 68 | ret = rf.invoke(ret, v); 69 | if(RT.isReduced(ret)) 70 | return ((IDeref)ret).deref(); 71 | v = f.invoke(v); 72 | } 73 | } 74 | 75 | public Object reduce(IFn rf, Object start){ 76 | Object ret = start; 77 | Object v = first(); 78 | while(true){ 79 | ret = rf.invoke(ret, v); 80 | if(RT.isReduced(ret)) 81 | return ((IDeref)ret).deref(); 82 | v = f.invoke(v); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IteratorSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | import java.io.IOException; 14 | import java.io.NotSerializableException; 15 | import java.util.Iterator; 16 | 17 | public class IteratorSeq extends ASeq{ 18 | final Iterator iter; 19 | final State state; 20 | 21 | static class State{ 22 | volatile Object val; 23 | volatile Object _rest; 24 | } 25 | 26 | public static IteratorSeq create(Iterator iter){ 27 | if(iter.hasNext()) 28 | return new IteratorSeq(iter); 29 | return null; 30 | } 31 | 32 | IteratorSeq(Iterator iter){ 33 | this.iter = iter; 34 | state = new State(); 35 | this.state.val = state; 36 | this.state._rest = state; 37 | } 38 | 39 | IteratorSeq(IPersistentMap meta, Iterator iter, State state){ 40 | super(meta); 41 | this.iter = iter; 42 | this.state = state; 43 | } 44 | 45 | public Object first(){ 46 | if(state.val == state) 47 | synchronized(state) 48 | { 49 | if(state.val == state) 50 | state.val = iter.next(); 51 | } 52 | return state.val; 53 | } 54 | 55 | public ISeq next(){ 56 | if(state._rest == state) 57 | synchronized(state) 58 | { 59 | if(state._rest == state) 60 | { 61 | first(); 62 | state._rest = create(iter); 63 | } 64 | } 65 | return (ISeq) state._rest; 66 | } 67 | 68 | public IteratorSeq withMeta(IPersistentMap meta){ 69 | return new IteratorSeq(meta, iter, state); 70 | } 71 | 72 | private void writeObject (java.io.ObjectOutputStream out) throws IOException { 73 | throw new NotSerializableException(getClass().getName()); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/KeywordLookupSite.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public final class KeywordLookupSite implements ILookupSite, ILookupThunk{ 16 | 17 | final Keyword k; 18 | 19 | public KeywordLookupSite(Keyword k){ 20 | this.k = k; 21 | } 22 | 23 | public ILookupThunk fault(Object target){ 24 | if(target instanceof IKeywordLookup) 25 | { 26 | return install(target); 27 | } 28 | else if(target instanceof ILookup) 29 | { 30 | return ilookupThunk(target.getClass()); 31 | } 32 | return this; 33 | } 34 | 35 | public Object get(Object target){ 36 | if(target instanceof IKeywordLookup || target instanceof ILookup) 37 | return this; 38 | return RT.get(target,k); 39 | } 40 | 41 | private ILookupThunk ilookupThunk(final Class c){ 42 | return new ILookupThunk(){ 43 | public Object get(Object target){ 44 | if(target != null && target.getClass() == c) 45 | return ((ILookup) target).valAt(k); 46 | return this; 47 | } 48 | }; 49 | } 50 | 51 | private ILookupThunk install(Object target){ 52 | ILookupThunk t = ((IKeywordLookup)target).getLookupThunk(k); 53 | if(t != null) 54 | return t; 55 | return ilookupThunk(target.getClass()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/LazilyPersistentVector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 14, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public class LazilyPersistentVector{ 16 | 17 | 18 | static public IPersistentVector createOwning(Object... items){ 19 | if(items.length == 0) 20 | return PersistentVector.EMPTY; 21 | else if(items.length <= 32) 22 | return new PersistentVector(items.length, 5, PersistentVector.EMPTY_NODE,items); 23 | return PersistentVector.create(items); 24 | } 25 | 26 | static public IPersistentVector create(Object obj){ 27 | if(obj instanceof IReduceInit) 28 | return PersistentVector.create((IReduceInit) obj); 29 | else if(obj instanceof ISeq) 30 | return PersistentVector.create(RT.seq(obj)); 31 | else if(obj instanceof Iterable) 32 | return PersistentVector.create((Iterable)obj); 33 | else 34 | return createOwning(RT.toArray(obj)); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/LineNumberingPushbackReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | import java.io.PushbackReader; 14 | import java.io.Reader; 15 | import java.io.LineNumberReader; 16 | import java.io.IOException; 17 | 18 | 19 | public class LineNumberingPushbackReader extends PushbackReader{ 20 | 21 | // This class is a PushbackReader that wraps a LineNumberReader. The code 22 | // here to handle line terminators only mentions '\n' because 23 | // LineNumberReader collapses all occurrences of CR, LF, and CRLF into a 24 | // single '\n'. 25 | 26 | private static final int newline = (int) '\n'; 27 | 28 | private boolean _atLineStart = true; 29 | private boolean _prev; 30 | private int _columnNumber = 1; 31 | 32 | public LineNumberingPushbackReader(Reader r){ 33 | super(new LineNumberReader(r)); 34 | } 35 | 36 | public LineNumberingPushbackReader(Reader r, int size){ 37 | super(new LineNumberReader(r, size)); 38 | } 39 | 40 | public int getLineNumber(){ 41 | return ((LineNumberReader) in).getLineNumber() + 1; 42 | } 43 | 44 | public void setLineNumber(int line) { ((LineNumberReader) in).setLineNumber(line - 1); } 45 | 46 | public int getColumnNumber(){ 47 | return _columnNumber; 48 | } 49 | 50 | public int read() throws IOException{ 51 | int c = super.read(); 52 | _prev = _atLineStart; 53 | if((c == newline) || (c == -1)) 54 | { 55 | _atLineStart = true; 56 | _columnNumber = 1; 57 | } 58 | else 59 | { 60 | _atLineStart = false; 61 | _columnNumber++; 62 | } 63 | return c; 64 | } 65 | 66 | public void unread(int c) throws IOException{ 67 | super.unread(c); 68 | _atLineStart = _prev; 69 | _columnNumber--; 70 | } 71 | 72 | public String readLine() throws IOException{ 73 | int c = read(); 74 | String line; 75 | switch (c) { 76 | case -1: 77 | line = null; 78 | break; 79 | case newline: 80 | line = ""; 81 | break; 82 | default: 83 | String first = String.valueOf((char) c); 84 | String rest = ((LineNumberReader)in).readLine(); 85 | line = (rest == null) ? first : first + rest; 86 | _prev = false; 87 | _atLineStart = true; 88 | _columnNumber = 1; 89 | break; 90 | } 91 | return line; 92 | } 93 | 94 | public boolean atLineStart(){ 95 | return _atLineStart; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/MapEntry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | import java.util.Iterator; 14 | 15 | public class MapEntry extends AMapEntry{ 16 | final Object _key; 17 | final Object _val; 18 | 19 | public MapEntry(Object key, Object val){ 20 | this._key = key; 21 | this._val = val; 22 | } 23 | 24 | public Object key(){ 25 | return _key; 26 | } 27 | 28 | public Object val(){ 29 | return _val; 30 | } 31 | 32 | public Object getKey(){ 33 | return key(); 34 | } 35 | 36 | public Object getValue(){ 37 | return val(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/MapEquivalence.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Aug 4, 2010 */ 12 | 13 | package clojure.lang; 14 | 15 | //marker interface 16 | public interface MapEquivalence{ 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/MethodImplCache.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 8, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Map; 16 | 17 | public final class MethodImplCache{ 18 | 19 | static public class Entry{ 20 | final public Class c; 21 | final public IFn fn; 22 | 23 | public Entry(Class c, IFn fn){ 24 | this.c = c; 25 | this.fn = fn; 26 | } 27 | } 28 | 29 | public final IPersistentMap protocol; 30 | public final Keyword methodk; 31 | public final int shift; 32 | public final int mask; 33 | public final Object[] table; //[class, entry. class, entry ...] 34 | public final Map map; 35 | 36 | Entry mre = null; 37 | 38 | public MethodImplCache(IPersistentMap protocol, Keyword methodk){ 39 | this(protocol, methodk, 0, 0, RT.EMPTY_ARRAY); 40 | } 41 | 42 | public MethodImplCache(IPersistentMap protocol, Keyword methodk, int shift, int mask, Object[] table){ 43 | this.protocol = protocol; 44 | this.methodk = methodk; 45 | this.shift = shift; 46 | this.mask = mask; 47 | this.table = table; 48 | this.map = null; 49 | } 50 | 51 | public MethodImplCache(IPersistentMap protocol, Keyword methodk, Map map){ 52 | this.protocol = protocol; 53 | this.methodk = methodk; 54 | this.shift = 0; 55 | this.mask = 0; 56 | this.table = null; 57 | this.map = map; 58 | } 59 | 60 | public IFn fnFor(Class c){ 61 | Entry last = mre; 62 | if(last != null && last.c == c) 63 | return last.fn; 64 | return findFnFor(c); 65 | } 66 | 67 | IFn findFnFor(Class c){ 68 | if (map != null) 69 | { 70 | Entry e = (Entry) map.get(c); 71 | mre = e; 72 | return e != null ? e.fn : null; 73 | } 74 | else 75 | { 76 | int idx = ((Util.hash(c) >> shift) & mask) << 1; 77 | if(idx < table.length && table[idx] == c) 78 | { 79 | Entry e = ((Entry) table[idx + 1]); 80 | mre = e; 81 | return e != null ? e.fn : null; 82 | } 83 | return null; 84 | } 85 | } 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Named.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Sep 20, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface Named{ 16 | String getNamespace(); 17 | 18 | String getName(); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Obj.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 25, 2006 3:44:58 PM */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | 17 | public abstract class Obj implements IObj, Serializable { 18 | 19 | final IPersistentMap _meta; 20 | 21 | public Obj(IPersistentMap meta){ 22 | this._meta = meta; 23 | } 24 | 25 | public Obj(){ 26 | _meta = null; 27 | } 28 | 29 | final public IPersistentMap meta(){ 30 | return _meta; 31 | } 32 | 33 | abstract public Obj withMeta(IPersistentMap meta); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ObjC.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | public class ObjC { 4 | 5 | public static boolean objc = false; 6 | 7 | public static void setObjC() { 8 | objc = true; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ObjCClass.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | public class ObjCClass { 4 | 5 | private final String name; 6 | 7 | public ObjCClass(String name) { 8 | this.name = name; 9 | } 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/PersistentTreeSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Comparator; 16 | 17 | public class PersistentTreeSet extends APersistentSet implements IObj, Reversible, Sorted{ 18 | static public final PersistentTreeSet EMPTY = new PersistentTreeSet(null, PersistentTreeMap.EMPTY); 19 | final IPersistentMap _meta; 20 | 21 | 22 | static public PersistentTreeSet create(ISeq items){ 23 | PersistentTreeSet ret = EMPTY; 24 | for(; items != null; items = items.next()) 25 | { 26 | ret = (PersistentTreeSet) ret.cons(items.first()); 27 | } 28 | return ret; 29 | } 30 | 31 | static public PersistentTreeSet create(Comparator comp, ISeq items){ 32 | PersistentTreeSet ret = new PersistentTreeSet(null, new PersistentTreeMap(null, comp)); 33 | for(; items != null; items = items.next()) 34 | { 35 | ret = (PersistentTreeSet) ret.cons(items.first()); 36 | } 37 | return ret; 38 | } 39 | 40 | PersistentTreeSet(IPersistentMap meta, IPersistentMap impl){ 41 | super(impl); 42 | this._meta = meta; 43 | } 44 | 45 | public IPersistentSet disjoin(Object key) { 46 | if(contains(key)) 47 | return new PersistentTreeSet(meta(),impl.without(key)); 48 | return this; 49 | } 50 | 51 | public IPersistentSet cons(Object o){ 52 | if(contains(o)) 53 | return this; 54 | return new PersistentTreeSet(meta(),impl.assoc(o,o)); 55 | } 56 | 57 | public IPersistentCollection empty(){ 58 | return new PersistentTreeSet(meta(),(PersistentTreeMap)impl.empty()); 59 | } 60 | 61 | public ISeq rseq() { 62 | return APersistentMap.KeySeq.create(((Reversible) impl).rseq()); 63 | } 64 | 65 | public PersistentTreeSet withMeta(IPersistentMap meta){ 66 | return new PersistentTreeSet(meta, impl); 67 | } 68 | 69 | public Comparator comparator(){ 70 | return ((Sorted)impl).comparator(); 71 | } 72 | 73 | public Object entryKey(Object entry){ 74 | return entry; 75 | } 76 | 77 | public ISeq seq(boolean ascending){ 78 | PersistentTreeMap m = (PersistentTreeMap) impl; 79 | return RT.keys(m.seq(ascending)); 80 | } 81 | 82 | public ISeq seqFrom(Object key, boolean ascending){ 83 | PersistentTreeMap m = (PersistentTreeMap) impl; 84 | return RT.keys(m.seqFrom(key,ascending)); 85 | } 86 | 87 | public IPersistentMap meta(){ 88 | return _meta; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ProxyHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Oct 4, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.lang.reflect.InvocationHandler; 16 | import java.lang.reflect.Method; 17 | 18 | public class ProxyHandler implements InvocationHandler{ 19 | //method-name-string->fn 20 | final IPersistentMap fns; 21 | 22 | 23 | public ProxyHandler(IPersistentMap fns){ 24 | this.fns = fns; 25 | } 26 | 27 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable{ 28 | Class rt = method.getReturnType(); 29 | IFn fn = (IFn) fns.valAt(method.getName()); 30 | if(fn == null) 31 | { 32 | if(rt == Void.TYPE) 33 | return null; 34 | else if(method.getName().equals("equals")) 35 | { 36 | return proxy == args[0]; 37 | } 38 | else if(method.getName().equals("hashCode")) 39 | { 40 | return System.identityHashCode(proxy); 41 | } 42 | else if(method.getName().equals("toString")) 43 | { 44 | return "Proxy: " + System.identityHashCode(proxy); 45 | } 46 | throw new UnsupportedOperationException(); 47 | } 48 | Object ret = fn.applyTo(ArraySeq.create(args)); 49 | if(rt == Void.TYPE) 50 | return null; 51 | else if(rt.isPrimitive()) 52 | { 53 | if(rt == Character.TYPE) 54 | return ret; 55 | else if(rt == Integer.TYPE) 56 | return ((Number) ret).intValue(); 57 | else if(rt == Long.TYPE) 58 | return ((Number) ret).longValue(); 59 | else if(rt == Float.TYPE) 60 | return ((Number) ret).floatValue(); 61 | else if(rt == Double.TYPE) 62 | return ((Number) ret).doubleValue(); 63 | else if(rt == Boolean.TYPE && !(ret instanceof Boolean)) 64 | return ret == null ? Boolean.FALSE : Boolean.TRUE; 65 | else if(rt == Byte.TYPE) 66 | return (byte) ((Number) ret).intValue(); 67 | else if(rt == Short.TYPE) 68 | return (short) ((Number) ret).intValue(); 69 | } 70 | return ret; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Ratio.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.math.BigInteger; 16 | import java.math.BigDecimal; 17 | import java.math.MathContext; 18 | 19 | public class Ratio extends Number implements Comparable{ 20 | final public BigInteger numerator; 21 | final public BigInteger denominator; 22 | 23 | public Ratio(BigInteger numerator, BigInteger denominator){ 24 | this.numerator = numerator; 25 | this.denominator = denominator; 26 | } 27 | 28 | public boolean equals(Object arg0){ 29 | return arg0 != null 30 | && arg0 instanceof Ratio 31 | && ((Ratio) arg0).numerator.equals(numerator) 32 | && ((Ratio) arg0).denominator.equals(denominator); 33 | } 34 | 35 | public int hashCode(){ 36 | return Util.hash(numerator) ^ Util.hash(denominator); 37 | } 38 | 39 | public String toString(){ 40 | return numerator.toString() + "/" + denominator.toString(); 41 | } 42 | 43 | public int intValue(){ 44 | return (int) doubleValue(); 45 | } 46 | 47 | public long longValue(){ 48 | return bigIntegerValue().longValue(); 49 | } 50 | 51 | public float floatValue(){ 52 | return (float)doubleValue(); 53 | } 54 | 55 | public double doubleValue(){ 56 | return decimalValue(MathContext.DECIMAL64).doubleValue(); 57 | } 58 | 59 | public BigDecimal decimalValue(){ 60 | return decimalValue(MathContext.UNLIMITED); 61 | } 62 | 63 | public BigDecimal decimalValue(MathContext mc){ 64 | BigDecimal numerator = new BigDecimal(this.numerator); 65 | BigDecimal denominator = new BigDecimal(this.denominator); 66 | 67 | return numerator.divide(denominator, mc); 68 | } 69 | 70 | public BigInteger bigIntegerValue(){ 71 | return numerator.divide(denominator); 72 | } 73 | 74 | public int compareTo(Object o){ 75 | Number other = (Number)o; 76 | return Numbers.compare(this, other); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ReaderConditional.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | public class ReaderConditional implements ILookup { 14 | 15 | public static final Keyword FORM_KW = Keyword.intern("form"); 16 | public static final Keyword SPLICING_KW = Keyword.intern("splicing?"); 17 | 18 | public final Object form; 19 | public final Boolean splicing; 20 | 21 | public static ReaderConditional create(Object form, boolean splicing) { 22 | return new ReaderConditional(form, splicing); 23 | } 24 | 25 | private ReaderConditional(Object form, boolean splicing){ 26 | this.form = form; 27 | this.splicing = splicing; 28 | } 29 | 30 | 31 | public Object valAt(Object key) { 32 | return valAt(key, null); 33 | } 34 | 35 | public Object valAt(Object key, Object notFound) { 36 | if (FORM_KW.equals(key)) { 37 | return this.form; 38 | } else if (SPLICING_KW.equals(key)) { 39 | return this.splicing; 40 | } else { 41 | return notFound; 42 | } 43 | } 44 | 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | if (this == o) return true; 49 | if (o == null || getClass() != o.getClass()) return false; 50 | 51 | ReaderConditional that = (ReaderConditional) o; 52 | 53 | if (form != null ? !form.equals(that.form) : that.form != null) return false; 54 | if (splicing != null ? !splicing.equals(that.splicing) : that.splicing != null) 55 | return false; 56 | return true; 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | int result = Util.hash(form); 62 | result = 31 * result + Util.hash(splicing); 63 | return result; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/RecordIterator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | /* ghadi shayban Sep 24, 2014 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Iterator; 16 | 17 | public final class RecordIterator implements Iterator { 18 | 19 | int i = 0; 20 | final int basecnt; 21 | final ILookup rec; 22 | final IPersistentVector basefields; 23 | final Iterator extmap; 24 | 25 | public RecordIterator (ILookup rec, IPersistentVector basefields, Iterator extmap) { 26 | this.rec = rec; 27 | this.basefields = basefields; 28 | this.basecnt = basefields.count(); 29 | this.extmap = extmap; 30 | } 31 | 32 | public boolean hasNext() { 33 | if (i < basecnt) { 34 | return true; 35 | } else { 36 | return extmap.hasNext(); 37 | } 38 | } 39 | 40 | public Object next() { 41 | if (i < basecnt) { 42 | Object k = basefields.nth(i); 43 | i++; 44 | return new MapEntry(k, rec.valAt(k)); 45 | } else { 46 | return extmap.next(); 47 | } 48 | } 49 | 50 | public void remove() { 51 | throw new UnsupportedOperationException(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Reduced.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | public final class Reduced implements IDeref{ 14 | Object val; 15 | 16 | public Reduced(Object val){ 17 | this.val = val; 18 | } 19 | 20 | public Object deref(){ 21 | return val; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/RemoteRepl.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | import java.io.IOException; 4 | 5 | /*-[ 6 | #include "ReplClient.h" 7 | ]-*/ 8 | 9 | public class RemoteRepl { 10 | 11 | public static boolean connected; 12 | 13 | static Var callRemoteSel = RT.var("clojure.remoterepl", "call-remote"); 14 | static Var listen = RT.var("clojure.remoterepl", "listen"); 15 | 16 | public static Object callRemote(Object o, Object seq) { 17 | if (RemoteRepl.connected) { 18 | if (ObjC.objc) { 19 | return callRemoteSelNative(o, RT.seq(seq)); 20 | } else { 21 | if (o == null) { 22 | throw new NullPointerException(); 23 | } 24 | return callRemoteSel.invoke(o, RT.seq(seq)); 25 | } 26 | } else { 27 | //throw new RuntimeException("RemoteRepl not connected"); 28 | return null; 29 | } 30 | } 31 | 32 | private native static Object callRemoteSelNative(Object o, ISeq seq) /*-[ 33 | return [ReplClient callRemote:o args:seq]; 34 | ]-*/; 35 | 36 | public static void setConnected(boolean connected) { 37 | RemoteRepl.connected = connected; 38 | RemoteRef.reset(); 39 | } 40 | 41 | public static void listen() { 42 | try { 43 | RT.load("clojure/remoterepl"); 44 | listen.invoke(); 45 | } catch (Exception e) { 46 | throw Util.sneakyThrow(e); 47 | } 48 | } 49 | 50 | public native static void connect(String host, String port) /*-[ 51 | [ReplClient connect:host]; 52 | ]-*/; 53 | 54 | public static native Object safetry(AFn fn) /*-[ 55 | @try { 56 | return [fn invoke]; 57 | } 58 | @catch (NSException *exception) { 59 | NSLog(@"%@", [exception callStackSymbols]); 60 | return nil; 61 | } 62 | ]-*/; 63 | } 64 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Repeat.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | /* Alex Miller, Dec 5, 2014 */ 14 | 15 | public class Repeat extends ASeq implements IReduce { 16 | 17 | private static final long INFINITE = -1; 18 | 19 | private final long count; // always INFINITE or >0 20 | private final Object val; 21 | private volatile ISeq _next; // cached 22 | 23 | private Repeat(long count, Object val){ 24 | this.count = count; 25 | this.val = val; 26 | } 27 | 28 | private Repeat(IPersistentMap meta, long count, Object val){ 29 | super(meta); 30 | this.count = count; 31 | this.val = val; 32 | } 33 | 34 | public static Repeat create(Object val){ 35 | return new Repeat(INFINITE, val); 36 | } 37 | 38 | public static ISeq create(long count, Object val){ 39 | if(count <= 0) 40 | return PersistentList.EMPTY; 41 | return new Repeat(count, val); 42 | } 43 | 44 | public Object first(){ 45 | return val; 46 | } 47 | 48 | public ISeq next() { 49 | if(_next == null) { 50 | if(count > 1) 51 | _next = new Repeat(count - 1, val); 52 | else if(count == INFINITE) 53 | _next = this; 54 | } 55 | return _next; 56 | } 57 | 58 | public Repeat withMeta(IPersistentMap meta){ 59 | return new Repeat(meta, count, val); 60 | } 61 | 62 | public Object reduce(IFn f){ 63 | Object ret = val; 64 | if(count == INFINITE) { 65 | while(true){ 66 | ret = f.invoke(ret, val); 67 | if(RT.isReduced(ret)) 68 | return ((IDeref)ret).deref(); 69 | } 70 | } else { 71 | for(long i=1; i 0) { 18 | sb.append(new String(new char[tab]).replace("\0", " ")); 19 | } 20 | sb.append(l).append("\n"); 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return sb.toString(); 26 | } 27 | 28 | public void println() { 29 | sb.append("\n"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/StringSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 6, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public class StringSeq extends ASeq implements IndexedSeq{ 16 | public final CharSequence s; 17 | public final int i; 18 | 19 | static public StringSeq create(CharSequence s){ 20 | if(s.length() == 0) 21 | return null; 22 | return new StringSeq(null, s, 0); 23 | } 24 | 25 | StringSeq(IPersistentMap meta, CharSequence s, int i){ 26 | super(meta); 27 | this.s = s; 28 | this.i = i; 29 | } 30 | 31 | public Obj withMeta(IPersistentMap meta){ 32 | if(meta == meta()) 33 | return this; 34 | return new StringSeq(meta, s, i); 35 | } 36 | 37 | public Object first(){ 38 | return Character.valueOf(s.charAt(i)); 39 | } 40 | 41 | public ISeq next(){ 42 | if(i + 1 < s.length()) 43 | return new StringSeq(_meta, s, i + 1); 44 | return null; 45 | } 46 | 47 | public int index(){ 48 | return i; 49 | } 50 | 51 | public int count(){ 52 | return s.length() - i; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/TaggedLiteral.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | public class TaggedLiteral implements ILookup { 14 | 15 | public static final Keyword TAG_KW = Keyword.intern("tag"); 16 | public static final Keyword FORM_KW = Keyword.intern("form"); 17 | 18 | public final Symbol tag; 19 | public final Object form; 20 | 21 | public static TaggedLiteral create(Symbol tag, Object form) { 22 | return new TaggedLiteral(tag, form); 23 | } 24 | 25 | private TaggedLiteral(Symbol tag, Object form){ 26 | this.tag = tag; 27 | this.form = form; 28 | } 29 | 30 | public Object valAt(Object key) { 31 | return valAt(key, null); 32 | } 33 | 34 | public Object valAt(Object key, Object notFound) { 35 | if (FORM_KW.equals(key)) { 36 | return this.form; 37 | } else if (TAG_KW.equals(key)) { 38 | return this.tag; 39 | } else { 40 | return notFound; 41 | } 42 | } 43 | 44 | @Override 45 | public boolean equals(Object o) { 46 | if (this == o) return true; 47 | if (o == null || getClass() != o.getClass()) return false; 48 | 49 | TaggedLiteral that = (TaggedLiteral) o; 50 | 51 | if (form != null ? !form.equals(that.form) : that.form != null) return false; 52 | if (tag != null ? !tag.equals(that.tag) : that.tag != null) return false; 53 | 54 | return true; 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | int result = Util.hash(tag); 60 | result = 31 * result + Util.hash(form); 61 | return result; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ThreadFactory.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | public interface ThreadFactory { 4 | Thread newThread(java.lang.Runnable runnable); 5 | } 6 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/URLClassLoader.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | import java.net.URL; 4 | 5 | public class URLClassLoader extends ClassLoader { 6 | 7 | public URLClassLoader(URL[] emptyUrls, ClassLoader classLoader) { 8 | super(classLoader); 9 | } 10 | 11 | public void addURL(URL url) { 12 | throw new RuntimeException(url.toString()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Volatile.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | final public class Volatile implements IDeref { 14 | 15 | volatile Object val; 16 | 17 | public Volatile(Object val){ 18 | this.val = val; 19 | } 20 | 21 | public Object deref() { 22 | return val; 23 | } 24 | 25 | public Object reset(Object newval) { 26 | return this.val = newval; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/WarnBoxedMath.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.RetentionPolicy; 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Target; 17 | 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Target(ElementType.METHOD) 20 | public @interface WarnBoxedMath { 21 | boolean value() default true; 22 | } 23 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/XMLHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 17, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | import org.xml.sax.Attributes; 16 | import org.xml.sax.ContentHandler; 17 | import org.xml.sax.Locator; 18 | import org.xml.sax.SAXException; 19 | import org.xml.sax.helpers.DefaultHandler; 20 | 21 | public class XMLHandler extends DefaultHandler{ 22 | ContentHandler h; 23 | 24 | 25 | public XMLHandler(ContentHandler h){ 26 | this.h = h; 27 | } 28 | 29 | public void setDocumentLocator(Locator locator){ 30 | h.setDocumentLocator(locator); 31 | } 32 | 33 | public void startDocument() throws SAXException{ 34 | h.startDocument(); 35 | } 36 | 37 | public void endDocument() throws SAXException{ 38 | h.endDocument(); 39 | } 40 | 41 | public void startPrefixMapping(String prefix, String uri) throws SAXException{ 42 | h.startPrefixMapping(prefix, uri); 43 | } 44 | 45 | public void endPrefixMapping(String prefix) throws SAXException{ 46 | h.endPrefixMapping(prefix); 47 | } 48 | 49 | public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException{ 50 | h.startElement(uri, localName, qName, atts); 51 | } 52 | 53 | public void endElement(String uri, String localName, String qName) throws SAXException{ 54 | h.endElement(uri, localName, qName); 55 | } 56 | 57 | public void characters(char ch[], int start, int length) throws SAXException{ 58 | h.characters(ch, start, length); 59 | } 60 | 61 | public void ignorableWhitespace(char ch[], int start, int length) throws SAXException{ 62 | h.ignorableWhitespace(ch, start, length); 63 | } 64 | 65 | public void processingInstruction(String target, String data) throws SAXException{ 66 | h.processingInstruction(target, data); 67 | } 68 | 69 | public void skippedEntity(String name) throws SAXException{ 70 | h.skippedEntity(name); 71 | } 72 | 73 | /* 74 | public static void main(String[] args){ 75 | try 76 | { 77 | ContentHandler dummy = new DefaultHandler(); 78 | SAXParserFactory f = SAXParserFactory.newInstance(); 79 | //f.setNamespaceAware(true); 80 | SAXParser p = f.newSAXParser(); 81 | p.parse("http://arstechnica.com/journals.rssx",new XMLHandler(dummy)); 82 | } 83 | catch(Exception e) 84 | { 85 | e.printStackTrace(); 86 | } 87 | } 88 | //*/ 89 | } 90 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | Clojure language implementation. 14 | 15 |

The clojure.lang package holds the implementation for Clojure. 16 | The only class considered part of the public API is 17 | {@link clojure.lang.IFn}. All other classes should be considered 18 | implementation details.

19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/jvm/clojure/main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure; 12 | 13 | import clojure.lang.RT; 14 | import clojure.lang.Symbol; 15 | import clojure.lang.Var; 16 | 17 | public class main{ 18 | 19 | final static private Symbol CLOJURE_MAIN = Symbol.intern("clojure.main"); 20 | final static private Var REQUIRE = RT.var("clojure.core", "require"); 21 | final static private Var MAIN = RT.var("clojure.main", "main"); 22 | 23 | public static void main(String[] args) { 24 | REQUIRE.invoke(CLOJURE_MAIN); 25 | MAIN.applyTo(RT.seq(args)); 26 | } 27 | } -------------------------------------------------------------------------------- /src/jvm/com/google/j2objc/annotations/ReflectionSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package com.google.j2objc.annotations; 16 | 17 | import java.lang.annotation.ElementType; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | /** 23 | * Annotation that specifies the level of reflection support for a particular 24 | * class. 25 | * 26 | * @author Keith Stanger 27 | */ 28 | @Target({ ElementType.TYPE, ElementType.PACKAGE }) 29 | @Retention(RetentionPolicy.SOURCE) 30 | public @interface ReflectionSupport { 31 | 32 | /** 33 | * Enumerates the available levels of reflection support. 34 | */ 35 | enum Level { 36 | /* 37 | * No metadata is emitted, so reflection support is limited to the 38 | * information that can be obtained from the Objective-C runtime. 39 | */ 40 | NATIVE_ONLY, 41 | /* 42 | * Additional metadata is emitted, allowing for full reflection support. 43 | */ 44 | FULL 45 | } 46 | 47 | Level value(); 48 | } -------------------------------------------------------------------------------- /src/objc/Cst502Socket.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Cst502Socket.m - Simple objective-c class for manipulating stream sockets. 3 | * Purpose: demonstrate stream sockets in Objective-C. 4 | * These examples are buildable on MacOSX and GNUstep on top of Windows7 5 | * Cst502 Emerging Languages and Programming Technologies 6 | * See http://pooh.poly.asu.edu/Cst502 7 | * @author Tim Lindquist (Tim.Lindquist@asu.edu), ASU Polytechnic, Engineering 8 | * @version December 2011 9 | */ 10 | #import 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #if defined(WINGS) 20 | #define _WIN32_WINNT 0x0501 21 | #include 22 | #include 23 | #else 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #endif /* !WINGS */ 32 | #define BACKLOG 10 /* queue size for pending connect requests */ 33 | #define MAXDATASIZE 4096 /* 4K bytes maximum with a single receive */ 34 | 35 | /** 36 | * Cst502Socket.h - objective-c class for manipulating stream sockets. 37 | * Purpose: demonstrate stream sockets in Objective-C. 38 | * These examples are buildable on MacOSX and GNUstep on top of Windows7 39 | * Cst502 Emerging Languages and Programming Technologies 40 | * See http://pooh.poly.asu.edu/Cst502 41 | * @author Tim Lindquist (Tim.Lindquist@asu.edu), ASU Polytechnic, Engineering 42 | * @version December 2011 43 | * based on the simple server and client sockets in C by Jeez. 44 | */ 45 | 46 | @interface Cst502ServerSocket : NSObject { 47 | int sockfd, new_fd, rv; 48 | BOOL connected; 49 | struct addrinfo hints, *servinfo, *p; 50 | struct sockaddr_storage their_addr; 51 | socklen_t sin_size; 52 | struct in_addr address; 53 | } 54 | - (id) initWithPort: (NSString*) port; 55 | - (BOOL) accept; 56 | - (int) sendBytes: (char*) byteMsg OfLength: (int) msgLength Index: (int) at; 57 | - (NSString*) receiveBytes: (char*) byteMsg 58 | maxBytes: (int) max 59 | beginAt: (int) at; 60 | - (BOOL) close; 61 | @end 62 | 63 | @interface Cst502ClientSocket : NSObject { 64 | BOOL connected; 65 | int sockfd, numbytes, rv; 66 | struct addrinfo hints, *servinfo, *p; 67 | NSString *hostName, *portNum; 68 | char s[INET6_ADDRSTRLEN]; 69 | } 70 | - (id) initWithHost: (NSString*) host portNumber: (NSString*) port; 71 | - (BOOL) connect; 72 | - (int) sendBytes: (char*) byteMsg OfLength: (int) msgLength Index: (int) at; 73 | - (NSString*) receiveBytes: (char*) byteMsg 74 | maxBytes: (int) max 75 | beginAt: (int) at; 76 | - (void) sendString: (NSString*)s; 77 | - (BOOL) close; 78 | @end 79 | 80 | -------------------------------------------------------------------------------- /src/objc/NSProxyImpl.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "clojure/lang/APersistentMap.h" 3 | 4 | @interface NSProxyImpl: NSObject 5 | 6 | - (id) initWithClass:(NSString*)clazz map:(ClojureLangAPersistentMap*) m; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /src/objc/NSSocketImpl.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSSocketImpl.h 3 | // sample 4 | // 5 | // Created by Gal Dolber on 2/1/14. 6 | // Copyright (c) 2014 clojure-objc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSSocketImpl : NSObject 12 | 13 | - (id) initWithHost:(NSString*)hostName withPort:(NSString*)portNum; 14 | 15 | - (id) read; 16 | 17 | - (void) println: (NSString*) s; 18 | 19 | -(void)close; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /src/objc/NSSocketImpl.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSSocketImpl.m 3 | // sample 4 | // 5 | // Created by Gal Dolber on 2/1/14. 6 | // Copyright (c) 2014 clojure-objc. All rights reserved. 7 | // 8 | 9 | #import "NSSocketImpl.h" 10 | #import "clojure/lang/RT.h" 11 | #import "clojure/lang/Var.h" 12 | #import "clojure/lang/Selector.h" 13 | #import "clojure/lang/ISeq.h" 14 | #import "clojure/lang/ObjC.h" 15 | #import "clojure/lang/Selector.h" 16 | #import "Cst502Socket.h" 17 | #import 18 | 19 | @implementation NSSocketImpl { 20 | Cst502ClientSocket* cs; 21 | } 22 | 23 | - (id) initWithHost:(NSString*)hostName withPort:(NSString*)portNum { 24 | self = [super init]; 25 | if (self) { 26 | cs = [[Cst502ClientSocket alloc] initWithHost: hostName 27 | portNumber: portNum]; 28 | [self reconnect]; 29 | } 30 | return self; 31 | } 32 | 33 | - (void) reconnect { 34 | while(![cs connect]) { 35 | NSLog(@"Error connecting... will try again in 5 second"); 36 | [NSThread sleepForTimeInterval:5]; 37 | } 38 | } 39 | 40 | - (id) read { 41 | fflush (stdout); 42 | char *buf = malloc(12); 43 | NSString *a = [[cs receiveBytes:buf maxBytes:12 beginAt:0] stringByTrimmingCharactersInSet: 44 | [NSCharacterSet whitespaceCharacterSet]]; 45 | /*if ([@"" isEqualToString:a]) { 46 | [self reconnect]; 47 | return [self read]; 48 | }*/ 49 | int size = [a intValue] + 2; 50 | free(buf); 51 | buf = malloc(size); 52 | a = [cs receiveBytes:buf maxBytes:size beginAt:0]; 53 | free(buf); 54 | return a; 55 | } 56 | 57 | - (void) println: (NSString*) s { 58 | [cs sendString: s]; 59 | fflush (stdout); 60 | } 61 | 62 | -(void)dealloc { 63 | [cs release]; 64 | [super dealloc]; 65 | } 66 | 67 | -(void)close { 68 | [cs close]; 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /src/objc/NSTypeImpl.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSTypeImpl.h 3 | // sample 4 | // 5 | // Created by Gal Dolber on 2/4/14. 6 | // Copyright (c) 2014 clojure-objc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "clojure/lang/APersistentMap.h" 11 | #import "clojure/lang/PersistentVector.h" 12 | #import "clojure/lang/PersistentHashMap.h" 13 | 14 | @interface NSTypeImpl : NSObject 15 | 16 | +(Class) makeClassWithName:(NSString*)name superclass:(NSString*)s map:(ClojureLangAPersistentMap*)m; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /src/objc/ReplClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReplClient.h 3 | // mpos 4 | // 5 | // Created by Gal Dolber on 4/12/14. 6 | // Copyright (c) 2014 zuldi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ReplClient : NSObject 12 | 13 | +(void) connect: (NSString*) host; 14 | +(id) callRemote:(id)sel args:(id)args; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/objc/WeakRef.h: -------------------------------------------------------------------------------- 1 | // 2 | // WeakRef.h 3 | // sample 4 | // 5 | // Created by Gal Dolber on 2/14/14. 6 | // Copyright (c) 2014 clojure-objc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WeakRef : NSObject 12 | 13 | -(id)initWith:(id)o; 14 | 15 | -(id)deref; 16 | 17 | +(WeakRef*)from:(id)o; 18 | 19 | -(BOOL)isEqual:(id)f; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /src/objc/WeakRef.m: -------------------------------------------------------------------------------- 1 | // 2 | // WeakRef.m 3 | // sample 4 | // 5 | // Created by Gal Dolber on 2/14/14. 6 | // Copyright (c) 2014 clojure-objc. All rights reserved. 7 | // 8 | 9 | #import "WeakRef.h" 10 | #import "clojure/lang/RT.h" 11 | #import "clojure/lang/Var.h" 12 | #import "clojure/lang/PersistentHashMap.h" 13 | #import "clojure/lang/Atom.h" 14 | 15 | @implementation WeakRef { 16 | NSValue *val; 17 | } 18 | 19 | -(id)initWith:(id)o { 20 | self = [super init]; 21 | if (self) { 22 | val = [[NSValue valueWithNonretainedObject:o] retain]; 23 | } 24 | return self; 25 | } 26 | 27 | -(id)deref { 28 | return [val nonretainedObjectValue]; 29 | } 30 | 31 | +(WeakRef*)from:(id)o { 32 | return [[[WeakRef alloc] initWith:o] autorelease]; 33 | } 34 | 35 | - (BOOL)isEqual:(id)f { 36 | if (f != nil && [f isKindOfClass:[WeakRef class]]) { 37 | return [[(WeakRef*)f deref] isEqual:[self deref]]; 38 | } 39 | return NO; 40 | } 41 | 42 | -(NSString *)description { 43 | return [[val nonretainedObjectValue] description]; 44 | } 45 | 46 | -(void)dealloc { 47 | [val release]; 48 | [super dealloc]; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /src/resources/clojure/version.properties: -------------------------------------------------------------------------------- 1 | version=${version} -------------------------------------------------------------------------------- /src/script/run_test.clj: -------------------------------------------------------------------------------- 1 | (System/setProperty "java.awt.headless" "true") 2 | (require 3 | '[clojure.test :as test] 4 | '[clojure.tools.namespace.find :as ns]) 5 | (def namespaces (ns/find-namespaces-in-dir (java.io.File. "test"))) 6 | (doseq [ns namespaces] (require ns)) 7 | (let [summary (apply test/run-tests namespaces)] 8 | (System/exit (if (test/successful? summary) 0 -1))) 9 | -------------------------------------------------------------------------------- /src/script/run_test_generative.clj: -------------------------------------------------------------------------------- 1 | (System/setProperty "java.awt.headless" "true") 2 | (when-not (System/getProperty "clojure.test.generative.msec") 3 | (System/setProperty "clojure.test.generative.msec" "60000")) 4 | (require '[clojure.test.generative.runner :as runner]) 5 | (runner/-main "test") 6 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/annotations.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;; Authors: Stuart Halloway, Rich Hickey 10 | 11 | (ns clojure.test-clojure.annotations 12 | (:use clojure.test)) 13 | 14 | (case (System/getProperty "java.specification.version") 15 | "1.6" (load "annotations/java_6") 16 | nil) 17 | 18 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/annotations/java_5.clj: -------------------------------------------------------------------------------- 1 | ;; java 5 annotation tests 2 | (in-ns 'clojure.test-clojure.annotations) 3 | 4 | (import [java.lang.annotation Annotation Retention RetentionPolicy Target ElementType]) 5 | (definterface Foo (foo [])) 6 | 7 | (deftype #^{Deprecated true 8 | Retention RetentionPolicy/RUNTIME} 9 | Bar [#^int a 10 | #^{:tag int 11 | Deprecated true 12 | Retention RetentionPolicy/RUNTIME} b] 13 | Foo (#^{Deprecated true 14 | Retention RetentionPolicy/RUNTIME} 15 | foo [this] 42)) 16 | 17 | (defn annotation->map 18 | "Converts a Java annotation (which conceals data) 19 | into a map (which makes is usable). Not lazy. 20 | Works recursively. Returns non-annotations unscathed." 21 | [#^java.lang.annotation.Annotation o] 22 | (cond 23 | (instance? Annotation o) 24 | (let [type (.annotationType o) 25 | itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation)) 26 | data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))] 27 | (into 28 | {:annotationType (.annotationType o)} 29 | (map 30 | (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))]) 31 | data-methods))) 32 | (or (sequential? o) (.isArray (class o))) 33 | (map annotation->map o) 34 | :else o)) 35 | 36 | (def expected-annotations 37 | #{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME} 38 | {:annotationType java.lang.Deprecated}}) 39 | 40 | (deftest test-annotations-on-type 41 | (is (= 42 | expected-annotations 43 | (into #{} (map annotation->map (.getAnnotations Bar)))))) 44 | 45 | (deftest test-annotations-on-field 46 | (is (= 47 | expected-annotations 48 | (into #{} (map annotation->map (.getAnnotations (.getField Bar "b"))))))) 49 | 50 | (deftest test-annotations-on-method 51 | (is (= 52 | expected-annotations 53 | (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil))))))) 54 | 55 | (gen-class :name foo.Bar 56 | :extends clojure.lang.Box 57 | :constructors {^{Deprecated true} [Object] [Object]} 58 | :init init 59 | :prefix "foo") 60 | 61 | (defn foo-init [obj] 62 | [[obj] nil]) 63 | 64 | (deftest test-annotations-on-constructor 65 | (is (some #(instance? Deprecated %) 66 | (for [ctor (.getConstructors (Class/forName "foo.Bar")) 67 | annotation (.getAnnotations ctor)] 68 | annotation)))) 69 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/api.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.test-clojure.api 10 | (:require [clojure.test.generative :refer (defspec)] 11 | [clojure.test-clojure.generators :as cgen]) 12 | (:import clojure.lang.IFn 13 | clojure.java.api.Clojure 14 | clojure.lang.Var)) 15 | 16 | (set! *warn-on-reflection* true) 17 | 18 | (defn roundtrip 19 | "Print an object and read it back with Clojure/read" 20 | [o] 21 | (binding [*print-length* nil 22 | *print-dup* nil 23 | *print-level* nil] 24 | (Clojure/read (pr-str o)))) 25 | 26 | (defn api-var-str 27 | [^Var v] 28 | (Clojure/var (str (.name (.ns v))) 29 | (str (.sym v)))) 30 | 31 | (defn api-var 32 | [^Var v] 33 | (Clojure/var (.name (.ns v)) 34 | (.sym v))) 35 | 36 | (defspec api-can-read 37 | roundtrip 38 | [^{:tag cgen/ednable} o] 39 | (when-not (= o %) 40 | (throw (ex-info "Value cannot roundtrip with Clojure/read" {:printed o :read %})))) 41 | 42 | (defspec api-can-find-var 43 | api-var 44 | [^{:tag cgen/var} v] 45 | (when-not (= v %) 46 | (throw (ex-info "Var cannot roundtrip through Clojure/var" {:from v :to %})))) 47 | 48 | (defspec api-can-find-var-str 49 | api-var-str 50 | [^{:tag cgen/var} v] 51 | (when-not (= v %) 52 | (throw (ex-info "Var cannot roundtrip strings through Clojure/var" {:from v :to %})))) 53 | 54 | 55 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/atoms.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;Author: Frantisek Sodomka 10 | 11 | (ns clojure.test-clojure.atoms 12 | (:use clojure.test)) 13 | 14 | ; http://clojure.org/atoms 15 | 16 | ; atom 17 | ; deref, @-reader-macro 18 | ; swap! reset! 19 | ; compare-and-set! 20 | 21 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/clojure_walk.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.clojure-walk 2 | (:require [clojure.walk :as w]) 3 | (:use clojure.test)) 4 | 5 | (deftest t-prewalk-replace 6 | (is (= (w/prewalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)]) 7 | [:b {:b :b} (list 3 :c :b)]))) 8 | 9 | (deftest t-postwalk-replace 10 | (is (= (w/postwalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)]) 11 | [:b {:b :b} (list 3 :c :b)]))) 12 | 13 | (deftest t-stringify-keys 14 | (is (= (w/stringify-keys {:a 1, nil {:b 2 :c 3}, :d 4}) 15 | {"a" 1, nil {"b" 2 "c" 3}, "d" 4}))) 16 | 17 | (deftest t-prewalk-order 18 | (is (= (let [a (atom [])] 19 | (w/prewalk (fn [form] (swap! a conj form) form) 20 | [1 2 {:a 3} (list 4 [5])]) 21 | @a) 22 | [[1 2 {:a 3} (list 4 [5])] 23 | 1 2 {:a 3} [:a 3] :a 3 (list 4 [5]) 24 | 4 [5] 5]))) 25 | 26 | (deftest t-postwalk-order 27 | (is (= (let [a (atom [])] 28 | (w/postwalk (fn [form] (swap! a conj form) form) 29 | [1 2 {:a 3} (list 4 [5])]) 30 | @a) 31 | [1 2 32 | :a 3 [:a 3] {:a 3} 33 | 4 5 [5] (list 4 [5]) 34 | [1 2 {:a 3} (list 4 [5])]]))) 35 | 36 | (defrecord Foo [a b c]) 37 | 38 | (deftest walk 39 | "Checks that walk returns the correct result and type of collection" 40 | (let [colls ['(1 2 3) 41 | [1 2 3] 42 | #{1 2 3} 43 | (sorted-set-by > 1 2 3) 44 | {:a 1, :b 2, :c 3} 45 | (sorted-map-by > 1 10, 2 20, 3 30) 46 | (->Foo 1 2 3) 47 | (map->Foo {:a 1 :b 2 :c 3 :extra 4})]] 48 | (doseq [c colls] 49 | (let [walked (w/walk identity identity c)] 50 | (is (= c walked)) 51 | (is (= (type c) (type walked))) 52 | (if (map? c) 53 | (is (= (w/walk #(update-in % [1] inc) #(reduce + (vals %)) c) 54 | (reduce + (map (comp inc val) c)))) 55 | (is (= (w/walk inc #(reduce + %) c) 56 | (reduce + (map inc c))))) 57 | (when (or (instance? clojure.lang.PersistentTreeMap c) 58 | (instance? clojure.lang.PersistentTreeSet c)) 59 | (is (= (.comparator c) (.comparator walked)))))))) 60 | 61 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/clojure_xml.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.clojure-xml 13 | (:use clojure.test) 14 | (:require [clojure.xml :as xml])) 15 | 16 | 17 | ; parse 18 | 19 | ; emit-element 20 | ; emit 21 | 22 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/clojure_zip.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.clojure-zip 13 | (:use clojure.test) 14 | (:require [clojure.zip :as zip])) 15 | 16 | 17 | ; zipper 18 | ; 19 | ; seq-zip 20 | ; vector-zip 21 | ; xml-zip 22 | ; 23 | ; node 24 | ; branch? 25 | ; children 26 | ; make-node 27 | ; path 28 | ; lefts 29 | ; rights 30 | ; down 31 | ; up 32 | ; root 33 | ; right 34 | ; rightmost 35 | ; left 36 | ; leftmost 37 | ; 38 | ; insert-left 39 | ; insert-right 40 | ; replace 41 | ; edit 42 | ; insert-child 43 | ; append-child 44 | ; next 45 | ; prev 46 | ; end? 47 | ; remove 48 | 49 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/compilation/examples.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Rich Hickey. All rights reserved. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.test-clojure.compilation.examples) 10 | 11 | (eval '(deftype X [])) 12 | (deftype T []) 13 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/data.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.test-clojure.data 10 | (:use clojure.data clojure.test) 11 | (import java.util.HashSet)) 12 | 13 | (deftest diff-test 14 | (are [d x y] (= d (diff x y)) 15 | [nil nil nil] nil nil 16 | [1 2 nil] 1 2 17 | [nil nil [1 2 3]] [1 2 3] '(1 2 3) 18 | [1 [:a :b] nil] 1 [:a :b] 19 | [{:a 1} :b nil] {:a 1} :b 20 | [:team #{:p1 :p2} nil] :team #{:p1 :p2} 21 | [{0 :a} [:a] nil] {0 :a} [:a] 22 | [nil [nil 2] [1]] [1] [1 2] 23 | [nil nil [1 2]] [1 2] (into-array [1 2]) 24 | [#{:a} #{:b} #{:c :d}] #{:a :c :d} #{:b :c :d} 25 | [nil nil {:a 1}] {:a 1} {:a 1} 26 | [{:a #{2}} {:a #{4}} {:a #{3}}] {:a #{2 3}} {:a #{3 4}} 27 | [#{1} #{3} #{2}] (HashSet. [1 2]) (HashSet. [2 3]) 28 | [nil nil [1 2]] [1 2] (into-array [1 2]) 29 | [nil nil [1 2]] (into-array [1 2]) [1 2] 30 | [{:a {:c [1]}} {:a {:c [0]}} {:a {:c [nil 2] :b 1}}] {:a {:b 1 :c [1 2]}} {:a {:b 1 :c [0 2]}} 31 | [{:a nil} {:a false} {:b nil :c false}] {:a nil :b nil :c false} {:a false :b nil :c false})) 32 | 33 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/delays.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.delays 2 | (:use clojure.test)) 3 | 4 | (deftest calls-once 5 | (let [a (atom 0) 6 | d (delay (swap! a inc))] 7 | (is (= 0 @a)) 8 | (is (= 1 @d)) 9 | (is (= 1 @d)) 10 | (is (= 1 @a)))) 11 | 12 | (deftest saves-exceptions 13 | (let [f #(do (throw (Exception. "broken")) 14 | 1) 15 | d (delay (f)) 16 | try-call #(try 17 | @d 18 | (catch Exception e e)) 19 | first-result (try-call)] 20 | (is (instance? Exception first-result)) 21 | (is (identical? first-result (try-call))))) 22 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/edn.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Stuart Halloway 10 | 11 | 12 | (ns clojure.test-clojure.edn 13 | (:require [clojure.test.generative :refer (defspec)] 14 | [clojure.test-clojure.generators :as cgen] 15 | [clojure.edn :as edn])) 16 | 17 | (defn roundtrip 18 | "Print an object and read it back as edn. Returns rather than throws 19 | any exceptions." 20 | [o] 21 | (binding [*print-length* nil 22 | *print-dup* nil 23 | *print-level* nil] 24 | (try 25 | (-> o pr-str edn/read-string) 26 | (catch Throwable t t)))) 27 | 28 | (defspec types-that-should-roundtrip 29 | roundtrip 30 | [^{:tag cgen/ednable} o] 31 | (when-not (= o %) 32 | (throw (ex-info "Value cannot roundtrip, see ex-data" {:printed o :read %})))) 33 | 34 | (defspec types-that-should-not-roundtrip 35 | roundtrip 36 | [^{:tag cgen/non-ednable} o] 37 | (when-not (instance? Throwable %) 38 | (throw (ex-info "edn/read should have thrown, see ex-data" {:printed o :read %})))) 39 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/fn.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Ambrose Bonnaire-Sergeant 10 | 11 | (ns clojure.test-clojure.fn 12 | (:use clojure.test)) 13 | 14 | (deftest fn-error-checking 15 | (testing "bad arglist" 16 | (is (fails-with-cause? java.lang.IllegalArgumentException 17 | #"Parameter declaration a should be a vector" 18 | (eval '(fn "a" a))))) 19 | 20 | (testing "treat first param as args" 21 | (is (fails-with-cause? java.lang.IllegalArgumentException 22 | #"Parameter declaration a should be a vector" 23 | (eval '(fn "a" []))))) 24 | 25 | (testing "looks like listy signature, but malformed declaration" 26 | (is (fails-with-cause? java.lang.IllegalArgumentException 27 | #"Parameter declaration 1 should be a vector" 28 | (eval '(fn (1)))))) 29 | 30 | (testing "checks each signature" 31 | (is (fails-with-cause? java.lang.IllegalArgumentException 32 | #"Parameter declaration a should be a vector" 33 | (eval '(fn 34 | ([a] 1) 35 | ("a" 2)))))) 36 | 37 | (testing "correct name but invalid args" 38 | (is (fails-with-cause? java.lang.IllegalArgumentException 39 | #"Parameter declaration a should be a vector" 40 | (eval '(fn a "a"))))) 41 | 42 | (testing "first sig looks multiarity, rest of sigs should be lists" 43 | (is (fails-with-cause? java.lang.IllegalArgumentException 44 | #"Invalid signature \[a b\] should be a list" 45 | (eval '(fn a 46 | ([a] 1) 47 | [a b]))))) 48 | 49 | (testing "missing parameter declaration" 50 | (is (fails-with-cause? java.lang.IllegalArgumentException 51 | #"Parameter declaration missing" 52 | (eval '(fn a)))) 53 | (is (fails-with-cause? java.lang.IllegalArgumentException 54 | #"Parameter declaration missing" 55 | (eval '(fn)))))) 56 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/java/javadoc.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.test-clojure.java.javadoc 10 | (:use clojure.test 11 | [clojure.java.javadoc :as j]) 12 | (:import (java.io File))) 13 | 14 | (deftest javadoc-url-test 15 | (testing "for a core api" 16 | (binding [*feeling-lucky* false] 17 | (are [x y] (= x (#'j/javadoc-url y)) 18 | nil "foo.Bar" 19 | (str *core-java-api* "java/lang/String.html") "java.lang.String"))) 20 | (testing "for a remote javadoc" 21 | (binding [*remote-javadocs* (ref (sorted-map "java." "http://example.com/"))] 22 | (is (= "http://example.com/java/lang/Number.html" (#'j/javadoc-url "java.lang.Number")))))) 23 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/java/shell.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.test-clojure.java.shell 10 | (:use clojure.test 11 | [clojure.java.shell :as sh]) 12 | (:import (java.io File))) 13 | 14 | (def platform-enc (.name (java.nio.charset.Charset/defaultCharset))) 15 | (def default-enc "UTF-8") 16 | 17 | (deftest test-parse-args 18 | (are [x y] (= x y) 19 | [[] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args []) 20 | [["ls"] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args ["ls"]) 21 | [["ls" "-l"] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args ["ls" "-l"]) 22 | [["ls"] {:in-enc default-enc :out-enc "ISO-8859-1" :dir nil :env nil}] (#'sh/parse-args ["ls" :out-enc "ISO-8859-1"]) 23 | [[] {:in-enc platform-enc :out-enc platform-enc :dir nil :env nil}] (#'sh/parse-args [:in-enc platform-enc :out-enc platform-enc]))) 24 | 25 | (deftest test-with-sh-dir 26 | (are [x y] (= x y) 27 | nil *sh-dir* 28 | "foo" (with-sh-dir "foo" *sh-dir*))) 29 | 30 | (deftest test-with-sh-env 31 | (are [x y] (= x y) 32 | nil *sh-env* 33 | {:KEY "VAL"} (with-sh-env {:KEY "VAL"} *sh-env*))) 34 | 35 | (deftest test-as-env-strings 36 | (are [x y] (= x y) 37 | nil (#'sh/as-env-strings nil) 38 | ["FOO=BAR"] (seq (#'sh/as-env-strings {"FOO" "BAR"})) 39 | ["FOO_SYMBOL=BAR"] (seq (#'sh/as-env-strings {'FOO_SYMBOL "BAR"})) 40 | ["FOO_KEYWORD=BAR"] (seq (#'sh/as-env-strings {:FOO_KEYWORD "BAR"})))) 41 | 42 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/keywords.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.test-clojure.keywords 10 | (:use clojure.test)) 11 | 12 | (let [this-ns (str (.name *ns*))] 13 | (deftest test-find-keyword 14 | :foo 15 | ::foo 16 | (let [absent-keyword-sym (gensym "absent-keyword-sym")] 17 | (are [result lookup] (= result (find-keyword lookup)) 18 | :foo :foo 19 | :foo 'foo 20 | :foo "foo" 21 | nil absent-keyword-sym 22 | nil (str absent-keyword-sym)) 23 | (are [result lookup] (= result (find-keyword this-ns lookup)) 24 | ::foo "foo" 25 | nil (str absent-keyword-sym))))) 26 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/macros.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | (ns clojure.test-clojure.macros 12 | (:use clojure.test)) 13 | 14 | ; http://clojure.org/macros 15 | 16 | ; -> 17 | ; defmacro definline macroexpand-1 macroexpand 18 | 19 | 20 | ;; -> and ->> should not be dependent on the meaning of their arguments 21 | 22 | (defmacro c 23 | [arg] 24 | (if (= 'b (first arg)) 25 | :foo 26 | :bar)) 27 | 28 | (deftest ->test 29 | (let [a 2, b identity] 30 | (is (= (-> a b c) 31 | (c (b a)))))) 32 | 33 | (deftest ->>test 34 | (let [a 2, b identity] 35 | (is (= (->> a b c) 36 | (c (b a)))))) 37 | 38 | (deftest ->metadata-test 39 | (testing "a trivial form" 40 | (is (= {:hardy :har :har :-D} 41 | (meta (macroexpand-1 (list `-> (with-meta 42 | 'quoted-symbol 43 | {:hardy :har :har :-D}))))))) 44 | (testing "a nontrivial form" 45 | (let [a (with-meta 'a {:foo :bar}) 46 | b (with-meta '(b c d) {:bar :baz}) 47 | e (with-meta 'e {:baz :quux}) 48 | expanded (macroexpand-1 (list `-> a b e))] 49 | (is (= expanded '(e (b a c d)))) 50 | (is (= {:baz :quux} (meta (first expanded)))) 51 | (is (= {:bar :baz} (meta (second expanded)))) 52 | (is (= {:foo :bar} (meta (second (second expanded)))))))) 53 | 54 | 55 | (deftest ->>metadata-test 56 | (testing "a trivial form" 57 | (is (= {:hardy :har :har :-D} 58 | (meta (macroexpand-1 (list `->> (with-meta 59 | 'quoted-symbol 60 | {:hardy :har :har :-D}))))))) 61 | (testing "a non-trivial form" 62 | (let [a (with-meta 'a {:foo :bar}) 63 | b (with-meta '(b c d) {:bar :baz}) 64 | e (with-meta 'e {:baz :quux}) 65 | expanded (macroexpand-1 (list `->> a b e))] 66 | (is (= expanded '(e (b c d a)))) 67 | (is (= {:baz :quux} (meta (first expanded)))) 68 | (is (= {:bar :baz} (meta (second expanded)))) 69 | (is (= {:foo :bar} (meta (last (second expanded)))))))) 70 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/main.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Stuart Halloway 10 | 11 | 12 | (ns clojure.test-clojure.main 13 | (:use clojure.test 14 | [clojure.test-helper :only [platform-newlines]]) 15 | (:require [clojure.main :as main])) 16 | 17 | (deftest eval-opt 18 | (testing "evals and prints forms" 19 | (is (= (platform-newlines "2\n4\n") (with-out-str (#'clojure.main/eval-opt "(+ 1 1) (+ 2 2)"))))) 20 | 21 | (testing "skips printing nils" 22 | (is (= (platform-newlines ":a\n:c\n") (with-out-str (#'clojure.main/eval-opt ":a nil :c"))))) 23 | 24 | (testing "does not block access to *in* (#299)" 25 | (with-in-str "(+ 1 1)" 26 | (is (= (platform-newlines "(+ 1 1)\n") (with-out-str (#'clojure.main/eval-opt "(read)"))))))) 27 | 28 | (defmacro with-err-str 29 | "Evaluates exprs in a context in which *err* is bound to a fresh 30 | StringWriter. Returns the string created by any nested printing 31 | calls." 32 | [& body] 33 | `(let [s# (new java.io.StringWriter) 34 | p# (new java.io.PrintWriter s#)] 35 | (binding [*err* p#] 36 | ~@body 37 | (str s#)))) 38 | 39 | (defn run-repl-and-return-err 40 | "Run repl, swallowing stdout and returing stderr." 41 | [in-str] 42 | (with-err-str 43 | (with-out-str 44 | (with-in-str in-str 45 | (main/repl))))) 46 | 47 | ;argh - test fragility, please fix 48 | #_(deftest repl-exception-safety 49 | (testing "catches and prints exception on bad equals" 50 | (is (re-matches #"java\.lang\.NullPointerException\r?\n" 51 | (run-repl-and-return-err 52 | "(proxy [Object] [] (equals [o] (.toString nil)))"))))) 53 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/parallel.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.parallel 13 | (:use clojure.test)) 14 | 15 | ;; !! Tests for the parallel library will be in a separate file clojure_parallel.clj !! 16 | 17 | ; future-call 18 | ; future 19 | ; pmap 20 | ; pcalls 21 | ; pvalues 22 | 23 | 24 | ;; pmap 25 | ;; 26 | (deftest pmap-does-its-thing 27 | ;; regression fixed in r1218; was OutOfMemoryError 28 | (is (= '(1) (pmap inc [0])))) 29 | 30 | 31 | (def ^:dynamic *test-value* 1) 32 | 33 | (deftest future-fn-properly-retains-conveyed-bindings 34 | (let [a (atom [])] 35 | (binding [*test-value* 2] 36 | @(future (dotimes [_ 3] 37 | ;; we need some binding to trigger binding pop 38 | (binding [*print-dup* false] 39 | (swap! a conj *test-value*)))) 40 | (is (= [2 2 2] @a))))) 41 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/pprint.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;; Author: Tom Faulhaber 10 | 11 | (ns clojure.test-clojure.pprint 12 | (:refer-clojure :exclude [format]) 13 | (:require [clojure.string :as str]) 14 | (:use [clojure.test :only (deftest is are run-tests)] 15 | [clojure.test-helper :only [platform-newlines]] 16 | clojure.test-clojure.pprint.test-helper 17 | clojure.pprint)) 18 | 19 | (load "pprint/test_cl_format") 20 | (load "pprint/test_pretty") 21 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/pprint/test_helper.clj: -------------------------------------------------------------------------------- 1 | ;;; test_helper.clj -- part of the pretty printer for Clojure 2 | 3 | ; Copyright (c) Rich Hickey. All rights reserved. 4 | ; The use and distribution terms for this software are covered by the 5 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 6 | ; which can be found in the file epl-v10.html at the root of this distribution. 7 | ; By using this software in any fashion, you are agreeing to be bound by 8 | ; the terms of this license. 9 | ; You must not remove this notice, or any other, from this software. 10 | 11 | ;; Author: Tom Faulhaber 12 | ;; April 3, 2009 13 | 14 | 15 | ;; This is just a macro to make my tests a little cleaner 16 | 17 | (ns clojure.test-clojure.pprint.test-helper 18 | (:use [clojure.test :only (deftest is)] 19 | [clojure.test-helper :only [platform-newlines]])) 20 | 21 | (defn- back-match [x y] (re-matches y x)) 22 | 23 | (defmacro simple-tests [name & test-pairs] 24 | `(deftest ~name 25 | ~@(for [[x y] (partition 2 test-pairs)] 26 | (cond 27 | (instance? java.util.regex.Pattern y) 28 | `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y)) 29 | (instance? java.lang.String y) `(is (= ~x (platform-newlines ~y))) 30 | :else `(is (= ~x ~y)))))) 31 | 32 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/protocols/examples.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.protocols.examples) 2 | 3 | (defprotocol ExampleProtocol 4 | "example protocol used by clojure tests" 5 | 6 | (foo [a] "method with one arg") 7 | (bar [a b] "method with two args") 8 | (^String baz [a] [a b] "method with multiple arities") 9 | (with-quux [a] "method name with a hyphen")) 10 | 11 | (defprotocol MarkerProtocol 12 | "a protocol with no methods") 13 | 14 | (defprotocol MarkerProtocol2) 15 | 16 | (definterface ExampleInterface 17 | (hinted [^int i]) 18 | (hinted [^String s])) 19 | 20 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/protocols/more_examples.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.protocols.more-examples) 2 | 3 | (defprotocol SimpleProtocol 4 | "example protocol used by clojure tests. Note that 5 | foo collides with examples/ExampleProtocol." 6 | 7 | (foo [a] "")) 8 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/reflect.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.reflect 2 | (:use clojure.data [clojure.reflect :as reflect] clojure.test clojure.pprint) 3 | (:import [clojure.reflect AsmReflector JavaReflector])) 4 | 5 | (defn nodiff 6 | [x y] 7 | (let [[x-only y-only common] (diff x y)] 8 | (when (or x-only y-only) 9 | (is false (with-out-str (pprint {:x-only x-only 10 | :y-only y-only 11 | :common common})))))) 12 | 13 | #_(deftest compare-reflect-and-asm 14 | (let [cl (.getContextClassLoader (Thread/currentThread)) 15 | asm-reflector (AsmReflector. cl) 16 | java-reflector (JavaReflector. cl)] 17 | (doseq [classname '[java.lang.Runnable 18 | java.lang.Object 19 | java.io.FileInputStream 20 | clojure.lang.Compiler 21 | clojure.lang.PersistentVector 22 | java.lang.SuppressWarnings]] 23 | (nodiff (type-reflect classname :reflector asm-reflector) 24 | (type-reflect classname :reflector java-reflector))))) 25 | 26 | (deftest field-descriptor->class-symbol-test 27 | (are [s d] (= s (@#'reflect/field-descriptor->class-symbol d)) 28 | 'clojure.asm.Type<><> "[[Lclojure/asm/Type;" 29 | 'int "I" 30 | 'java.lang.Object "Ljava.lang.Object;")) 31 | 32 | (deftest internal-name->class-symbol-test 33 | (are [s n] (= s (@#'reflect/internal-name->class-symbol n)) 34 | 'java.lang.Exception "java/lang/Exception")) 35 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/refs.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.refs 13 | (:use clojure.test)) 14 | 15 | ; http://clojure.org/refs 16 | 17 | ; ref 18 | ; deref, @-reader-macro 19 | ; dosync io! 20 | ; ensure ref-set alter commute 21 | ; set-validator get-validator 22 | 23 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/repl.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.repl 2 | (:use clojure.test 3 | clojure.repl 4 | [clojure.test-helper :only [platform-newlines]] 5 | clojure.test-clojure.repl.example) 6 | (:require [clojure.string :as str])) 7 | 8 | (deftest test-doc 9 | (testing "with namespaces" 10 | (is (= "clojure.pprint" 11 | (second (str/split-lines (with-out-str (doc clojure.pprint)))))))) 12 | 13 | (deftest test-source 14 | (is (= "(defn foo [])" (source-fn 'clojure.test-clojure.repl.example/foo))) 15 | (is (= (platform-newlines "(defn foo [])\n") (with-out-str (source clojure.test-clojure.repl.example/foo)))) 16 | (is (nil? (source-fn 'non-existent-fn)))) 17 | 18 | (deftest test-source-read-eval-unknown 19 | (is (thrown? IllegalStateException (binding [*read-eval* :unknown] (source reduce))))) 20 | 21 | (deftest test-source-read-eval-false 22 | (is (binding [*read-eval* false] (with-out-str (source reduce))))) 23 | 24 | (deftest test-dir 25 | (is (thrown? Exception (dir-fn 'non-existent-ns))) 26 | (is (= '[bar foo] (dir-fn 'clojure.test-clojure.repl.example))) 27 | (is (= (platform-newlines "bar\nfoo\n") (with-out-str (dir clojure.test-clojure.repl.example))))) 28 | 29 | (deftest test-apropos 30 | (testing "with a regular expression" 31 | (is (= '[clojure.core/defmacro] (apropos #"^defmacro$"))) 32 | (is (some #{'clojure.core/defmacro} (apropos #"def.acr."))) 33 | (is (= [] (apropos #"nothing-has-this-name")))) 34 | 35 | (testing "with a string" 36 | (is (some #{'clojure.core/defmacro} (apropos "defmacro"))) 37 | (is (some #{'clojure.core/defmacro} (apropos "efmac"))) 38 | (is (= [] (apropos "nothing-has-this-name")))) 39 | 40 | (testing "with a symbol" 41 | (is (some #{'clojure.core/defmacro} (apropos 'defmacro))) 42 | (is (some #{'clojure.core/defmacro} (apropos 'efmac))) 43 | (is (= [] (apropos 'nothing-has-this-name))))) 44 | 45 | 46 | (defmacro call-ns 47 | "Call ns with a unique namespace name. Return the result of calling ns" 48 | [] `(ns a#)) 49 | (defmacro call-ns-sym 50 | "Call ns wih a unique namespace name. Return the namespace symbol." 51 | [] `(do (ns a#) 'a#)) 52 | 53 | (deftest test-dynamic-ns 54 | (testing "a call to ns returns nil" 55 | (is (= nil (call-ns)))) 56 | (testing "requiring a dynamically created ns should not throw an exception" 57 | (is (= nil (let [a (call-ns-sym)] (require a)))))) 58 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/repl/example.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.repl.example) 2 | 3 | ;; sample namespace for repl tests, don't add anything here 4 | (defn foo []) 5 | (defn bar []) 6 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/special.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | ;; 12 | ;; Test special forms, macros and metadata 13 | ;; 14 | 15 | (ns clojure.test-clojure.special 16 | (:use clojure.test)) 17 | 18 | ; http://clojure.org/special_forms 19 | 20 | ; let, letfn 21 | ; quote 22 | ; var 23 | ; fn 24 | 25 | (deftest multiple-keys-in-destructuring 26 | (let [foo (fn [& {:keys [x]}] x) 27 | bar (fn [& options] (apply foo :x :b options))] 28 | (is (= (bar) :b)) 29 | (is (= (bar :x :a) :a)))) 30 | 31 | (deftest empty-list-with-:as-destructuring 32 | (let [{:as x} '()] 33 | (is (= {} x)))) 34 | 35 | (deftest keywords-in-destructuring 36 | (let [{:keys [:a :b]} {:a 1 :b 2}] 37 | (is (= 1 a)) 38 | (is (= 2 b)))) 39 | 40 | (deftest namespaced-keywords-in-destructuring 41 | (let [{:keys [:a/b :c/d]} {:a/b 1 :c/d 2}] 42 | (is (= 1 b)) 43 | (is (= 2 d)))) 44 | 45 | (deftest namespaced-keys-in-destructuring 46 | (let [{:keys [a/b c/d]} {:a/b 1 :c/d 2}] 47 | (is (= 1 b)) 48 | (is (= 2 d)))) 49 | 50 | (deftest namespaced-syms-in-destructuring 51 | (let [{:syms [a/b c/d]} {'a/b 1 'c/d 2}] 52 | (is (= 1 b)) 53 | (is (= 2 d)))) 54 | 55 | (deftest keywords-not-allowed-in-let-bindings 56 | (is (thrown-with-msg? Exception #"Unsupported binding key: :a" 57 | (eval '(let [:a 1] a)))) 58 | (is (thrown-with-msg? Exception #"Unsupported binding key: :a/b" 59 | (eval '(let [:a/b 1] b))))) 60 | 61 | (require '[clojure.string :as s]) 62 | (deftest resolve-keyword-ns-alias-in-destructuring 63 | (let [{:keys [::s/x ::s/y]} {:clojure.string/x 1 :clojure.string/y 2}] 64 | (is (= x 1)) 65 | (is (= y 2)))) 66 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/test_fixtures.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | ; 9 | ;;; test_fixtures.clj: unit tests for fixtures in test.clj 10 | 11 | ;; by Stuart Sierra 12 | ;; March 28, 2009 13 | 14 | (ns clojure.test-clojure.test-fixtures 15 | (:use clojure.test)) 16 | 17 | (declare ^:dynamic *a* ^:dynamic *b* ^:dynamic *c* ^:dynamic *d*) 18 | 19 | (def ^:dynamic *n* 0) 20 | 21 | (defn fixture-a [f] 22 | (binding [*a* 3] (f))) 23 | 24 | (defn fixture-b [f] 25 | (binding [*b* 5] (f))) 26 | 27 | (defn fixture-c [f] 28 | (binding [*c* 7] (f))) 29 | 30 | (defn fixture-d [f] 31 | (binding [*d* 11] (f))) 32 | 33 | (defn inc-n-fixture [f] 34 | (binding [*n* (inc *n*)] (f))) 35 | 36 | (def side-effects (atom 0)) 37 | (defn side-effecting-fixture [f] 38 | (swap! side-effects inc) 39 | (f)) 40 | 41 | (use-fixtures :once fixture-a fixture-b) 42 | 43 | (use-fixtures :each fixture-c fixture-d inc-n-fixture side-effecting-fixture) 44 | (use-fixtures :each fixture-c fixture-d inc-n-fixture side-effecting-fixture) 45 | 46 | (deftest can-use-once-fixtures 47 | (is (= 3 *a*)) 48 | (is (= 5 *b*))) 49 | 50 | (deftest can-use-each-fixtures 51 | (is (= 7 *c*)) 52 | (is (= 11 *d*))) 53 | 54 | (deftest use-fixtures-replaces 55 | (is (= *n* 1))) 56 | 57 | (deftest can-run-a-single-test-with-fixtures 58 | ;; We have to use a side-effecting fixture to test that the fixtures are 59 | ;; running, in order to distinguish fixtures run because of our call to 60 | ;; test-vars below from the same fixtures running prior to this test 61 | (let [side-effects-so-far @side-effects 62 | reported (atom [])] 63 | (binding [report (fn [m] (swap! reported conj (:type m)))] 64 | (test-vars [#'can-use-each-fixtures])) 65 | (is (= [:begin-test-var :pass :pass :end-test-var] @reported)) 66 | (is (= (inc side-effects-so-far) @side-effects)))) 67 | 68 | (defn should-not-trigger-fixtures []) 69 | 70 | (deftest a-var-lacking-test-meta-should-not-trigger-fixtures 71 | (let [side-effects-so-far @side-effects] 72 | (test-vars [#'should-not-trigger-fixtures]) 73 | (is (= side-effects-so-far @side-effects)))) 74 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/transients.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.transients 2 | (:use clojure.test)) 3 | 4 | (deftest popping-off 5 | (testing "across a node boundary" 6 | (are [n] 7 | (let [v (-> (range n) vec)] 8 | (= (subvec v 0 (- n 2)) (-> v transient pop! pop! persistent!))) 9 | 33 (+ 32 (inc (* 32 32))) (+ 32 (inc (* 32 32 32))))) 10 | (testing "off the end" 11 | (is (thrown-with-msg? IllegalStateException #"Can't pop empty vector" 12 | (-> [] transient pop!)))) 13 | (testing "copying array from a non-editable when put in tail position") 14 | (is (= 31 (let [pv (vec (range 34))] 15 | (-> pv transient pop! pop! pop! (conj! 42)) 16 | (nth pv 31))))) 17 | 18 | (defn- hash-obj [hash] 19 | (reify Object (hashCode [this] hash))) 20 | 21 | (deftest dissocing 22 | (testing "dissocing colliding keys" 23 | (is (= [0 {}] (let [ks (concat (range 7) [(hash-obj 42) (hash-obj 42)]) 24 | m (zipmap ks ks) 25 | dm (persistent! (reduce dissoc! (transient m) (keys m)))] 26 | [(count dm) dm]))))) 27 | 28 | (deftest test-disj! 29 | (testing "disjoin multiple items in one call" 30 | (is (= #{5 20} (-> #{5 10 15 20} transient (disj! 10 15) persistent!))))) 31 | 32 | (deftest empty-transient 33 | (is (= false (.contains (transient #{}) :bogus-key)))) 34 | 35 | (deftest persistent-assoc-on-collision 36 | (testing "Persistent assoc on a collision node which underwent a transient dissoc" 37 | (let [a (reify Object (hashCode [_] 42)) 38 | b (reify Object (hashCode [_] 42))] 39 | (is (= (-> #{a b} transient (disj! a) persistent! (conj a)) 40 | (-> #{a b} transient (disj! a) persistent! (conj a))))))) 41 | 42 | (deftest transient-mod-after-persistent 43 | (let [v [1 2 3] 44 | t (transient v) 45 | t2 (conj! t 4) 46 | p (persistent! t2)] 47 | (is (= [1 2 3 4] p)) 48 | (is (thrown? IllegalAccessError (conj! t2 5))))) 49 | 50 | (deftest transient-mod-ok-across-threads 51 | (let [v [1 2 3] 52 | t (transient v) 53 | t2 @(future (conj! t 4)) 54 | p (persistent! t2)] 55 | (is (= [1 2 3 4] p)))) 56 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/try_catch.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Paul M Bauer 10 | 11 | (ns clojure.test-clojure.try-catch 12 | (:use clojure.test) 13 | (:import [clojure.test ReflectorTryCatchFixture 14 | ReflectorTryCatchFixture$Cookies])) 15 | 16 | (defn- get-exception [expression] 17 | (try (eval expression) 18 | nil 19 | (catch java.lang.Throwable t 20 | t))) 21 | 22 | (deftest catch-receives-checked-exception-from-eval 23 | (are [expression expected-exception] (= expected-exception 24 | (type (get-exception expression))) 25 | "Eh, I'm pretty safe" nil 26 | '(java.io.FileReader. "CAFEBABEx0/idonotexist") java.io.FileNotFoundException)) 27 | 28 | 29 | (defn fail [x] 30 | (ReflectorTryCatchFixture/fail x)) 31 | 32 | (defn make-instance [] 33 | (ReflectorTryCatchFixture.)) 34 | 35 | (deftest catch-receives-checked-exception-from-reflective-call 36 | (is (thrown-with-msg? ReflectorTryCatchFixture$Cookies #"Long" (fail 1))) 37 | (is (thrown-with-msg? ReflectorTryCatchFixture$Cookies #"Double" (fail 1.0))) 38 | (is (thrown-with-msg? ReflectorTryCatchFixture$Cookies #"Wrapped" 39 | (.failWithCause (make-instance) 1.0)))) 40 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/volatiles.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;Author: Alex Miller 10 | 11 | (ns clojure.test-clojure.volatiles 12 | (:use clojure.test)) 13 | 14 | (deftest volatile-basics 15 | (let [vol (volatile! "abc")] 16 | (is (volatile? vol)) 17 | (is (= "abc" @vol)) 18 | (is (= "def" (vreset! vol "def"))) 19 | (is (= "def" @vol)))) 20 | 21 | (deftest volatile-vswap! 22 | (let [vol (volatile! 10)] 23 | (is (= 11 (vswap! vol inc))) 24 | (is (= 11 @vol))) 25 | (let [vol (volatile! 10)] 26 | (is (= 20 (vswap! vol + 10))) 27 | (is (= 20 @vol))) 28 | (let [vol (volatile! 10)] 29 | (is (= 25 (vswap! vol + 10 5))) 30 | (is (= 25 @vol)))) 31 | 32 | -------------------------------------------------------------------------------- /test/java/clojure/test/ReflectorTryCatchFixture.java: -------------------------------------------------------------------------------- 1 | package clojure.test; 2 | 3 | public class ReflectorTryCatchFixture { 4 | 5 | public static void fail(Long x) throws Cookies { 6 | throw new Cookies("Long"); 7 | } 8 | 9 | public static void fail(Double y) throws Cookies { 10 | throw new Cookies("Double"); 11 | } 12 | 13 | public void failWithCause(Double y) throws Cookies { 14 | throw new Cookies("Wrapped", new Cookies("Cause")); 15 | } 16 | 17 | public static class Cookies extends Exception { 18 | public Cookies(String msg, Throwable cause) { super(msg, cause); } 19 | public Cookies(String msg) { super(msg); } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /test/java/compilation/TestDispatch.java: -------------------------------------------------------------------------------- 1 | package compilation; 2 | 3 | public class TestDispatch { 4 | public static String someMethod (int a, int b) { 5 | return "(int, int)"; 6 | } 7 | 8 | public static String someMethod (int a, long b) { 9 | return "(int, long)"; 10 | } 11 | 12 | public static String someMethod (long a, long b) { 13 | return "(long, long)"; 14 | } 15 | } -------------------------------------------------------------------------------- /test/java/java/util/jar/JarEntry.java: -------------------------------------------------------------------------------- 1 | package java.util.jar; 2 | 3 | public class JarEntry { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /test/java/java/util/jar/JarFile.java: -------------------------------------------------------------------------------- 1 | // Empty stub to run tests 2 | package java.util.jar; 3 | 4 | import java.io.File; 5 | import java.io.InputStream; 6 | import java.util.Enumeration; 7 | import java.util.zip.ZipEntry; 8 | 9 | 10 | public class JarFile { 11 | 12 | public JarFile(File file) { 13 | throw new RuntimeException(); 14 | } 15 | 16 | public Enumeration entries() { 17 | throw new RuntimeException(); 18 | } 19 | 20 | public InputStream getInputStream(ZipEntry zipEntry) { 21 | throw new RuntimeException(); 22 | } 23 | 24 | public ZipEntry getEntry(String string) { 25 | throw new RuntimeException(); 26 | } 27 | } -------------------------------------------------------------------------------- /test/objc/NSCommonTest.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSCommonTest.h 3 | // mpos 4 | // 5 | // Created by Gal Dolber on 4/10/14. 6 | // Copyright (c) 2014 zuldi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSCommonTest : NSObject 12 | 13 | + (void) runtests; 14 | 15 | @end 16 | --------------------------------------------------------------------------------