Mercurial > lasercutter
changeset 11:f952052e37b7
trying a fix.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 24 Aug 2010 19:06:45 -0400 |
parents | ef7dbbd6452c |
children | aadb93318584 |
files | graster/.#signer4laser2x1.png.raster.gmask graster/config.yml graster/graster-example.tgz graster/graster/.git/HEAD graster/graster/.git/config graster/graster/.git/description graster/graster/.git/hooks/applypatch-msg.sample graster/graster/.git/hooks/commit-msg.sample graster/graster/.git/hooks/post-commit.sample graster/graster/.git/hooks/post-receive.sample graster/graster/.git/hooks/post-update.sample graster/graster/.git/hooks/pre-applypatch.sample graster/graster/.git/hooks/pre-commit.sample graster/graster/.git/hooks/pre-rebase.sample graster/graster/.git/hooks/prepare-commit-msg.sample graster/graster/.git/hooks/update.sample graster/graster/.git/index graster/graster/.git/info/exclude graster/graster/.git/logs/HEAD graster/graster/.git/logs/refs/heads/master graster/graster/.git/objects/pack/pack-5656912d40e5e13e8ad82152331d45add23e8aac.idx graster/graster/.git/objects/pack/pack-5656912d40e5e13e8ad82152331d45add23e8aac.pack graster/graster/.git/packed-refs graster/graster/.git/refs/heads/master graster/graster/.git/refs/remotes/origin/HEAD graster/graster/.gitignore graster/graster/README.rdoc graster/graster/RMagick-2.13.1.tar.bz2 graster/graster/Rakefile graster/graster/VERSION graster/graster/bin/graster graster/graster/bin/gtile graster/graster/config/graster.yml graster/graster/graster.gemspec graster/graster/lib/graster.rb graster/graster/lib/graster/.#gmask_file.rb graster/graster/lib/graster/gcode_file.rb graster/graster/lib/graster/gmask_file.rb graster/graster/lib/graster/image.rb graster/graster/lib/graster/runner.rb graster/graster/rmagick-2.13.1.gem graster/graster/tile.rb graster/hacklab-engraver/.git/HEAD graster/hacklab-engraver/.git/config graster/hacklab-engraver/.git/description graster/hacklab-engraver/.git/hooks/applypatch-msg.sample graster/hacklab-engraver/.git/hooks/commit-msg.sample graster/hacklab-engraver/.git/hooks/post-commit.sample graster/hacklab-engraver/.git/hooks/post-receive.sample graster/hacklab-engraver/.git/hooks/post-update.sample graster/hacklab-engraver/.git/hooks/pre-applypatch.sample graster/hacklab-engraver/.git/hooks/pre-commit.sample graster/hacklab-engraver/.git/hooks/pre-rebase.sample graster/hacklab-engraver/.git/hooks/prepare-commit-msg.sample graster/hacklab-engraver/.git/hooks/update.sample graster/hacklab-engraver/.git/index graster/hacklab-engraver/.git/info/exclude graster/hacklab-engraver/.git/logs/HEAD graster/hacklab-engraver/.git/logs/refs/heads/master graster/hacklab-engraver/.git/objects/00/e8b290d784d38f4cd0495586799e98fea4f45f graster/hacklab-engraver/.git/objects/02/c08b67e102c8ccddc18c609ec20f71a0468312 graster/hacklab-engraver/.git/objects/07/05d4debff7c18448ab48687ff7a997b6c8d0d0 graster/hacklab-engraver/.git/objects/0d/302940f5c0a80d8a7b8aaafc1fe3c9107e552d graster/hacklab-engraver/.git/objects/0e/25a9d0927364ec790df38694f6ea69cea9b258 graster/hacklab-engraver/.git/objects/11/0bc5a919d55e758d621465e69162d0a2e3de5b graster/hacklab-engraver/.git/objects/11/67088b7086fdd400154e86e0c76e02af95671b graster/hacklab-engraver/.git/objects/12/8ad1461fb3754cf6702d55f8e050b4036f8af8 graster/hacklab-engraver/.git/objects/17/44d6833bb0fa3a15e249a4faad29fab8f3bd80 graster/hacklab-engraver/.git/objects/20/ca6409cbd455fcbae06ffd177553857e43adcb graster/hacklab-engraver/.git/objects/21/7eaf716ea5a987d79407eaac7dc853b279c3d5 graster/hacklab-engraver/.git/objects/25/1c450dde1eeab662d00967bb41f13a12ceadc3 graster/hacklab-engraver/.git/objects/27/2b76446d8d70feddc23fe033994eae0ae54be7 graster/hacklab-engraver/.git/objects/2b/2693d5073f492ac90963f33a8452a31bbcf6bb graster/hacklab-engraver/.git/objects/37/c611a4fe5ebcf722cfb0370d42eb714b52af1e graster/hacklab-engraver/.git/objects/39/5d366090051b462e9f6be2003791a40e969c86 graster/hacklab-engraver/.git/objects/39/e4809471abf02fc5d1922bd32d0d14400aaeca graster/hacklab-engraver/.git/objects/3d/3c25ca420571813c3729711741718994c2988f graster/hacklab-engraver/.git/objects/3d/c982cae4470a7c3b324027d05b2c377878e388 graster/hacklab-engraver/.git/objects/48/0396695515689f1ac537c08480180970892e9d graster/hacklab-engraver/.git/objects/4a/654eac48d62e718b71c65eabd923b916ff7acb graster/hacklab-engraver/.git/objects/4e/bf8847d4464aabff8af13901492405f4ebd687 graster/hacklab-engraver/.git/objects/4f/b9341cc80ee60a78fb335bb4c951f3b1ba510f graster/hacklab-engraver/.git/objects/54/162a6c26dfa90d099aa06fadefd17cd4483394 graster/hacklab-engraver/.git/objects/54/c13cded8582bdd8bf57e2c58618a8be9d09732 graster/hacklab-engraver/.git/objects/57/273524331dcfcbb7256dd9ce8e3124e7d6408f graster/hacklab-engraver/.git/objects/58/94622e9772e7b5e4c26a7c4cf4379c82b81fd4 graster/hacklab-engraver/.git/objects/60/1f78eb56a2fbefb77a5f2fe9bd9a8af9486f22 graster/hacklab-engraver/.git/objects/6d/b2a0702414b2f7d4a54181fe45e9093a41e1bd graster/hacklab-engraver/.git/objects/70/26e67d5af2e7a87b28c6fe30d4c826696f2ef9 graster/hacklab-engraver/.git/objects/78/ccf41fc1c708e90f7f3b2b758a47bc5b96a226 graster/hacklab-engraver/.git/objects/7d/faf00af8b5ae18e4627c3afbb3847e7d488ae6 graster/hacklab-engraver/.git/objects/83/53fdf7673f571b8c01ef7a8bbc6f7d4eea7516 graster/hacklab-engraver/.git/objects/8d/fb8f06ad6c2bb6176e6b18865771d1dd176e19 graster/hacklab-engraver/.git/objects/96/0fe8e35f5f8bb29285df579ab915502a33f693 graster/hacklab-engraver/.git/objects/9b/0b4108a8f35a21daad3d5940943cbf312ab5c7 graster/hacklab-engraver/.git/objects/9d/c2be4daee1228bd8aab2b90952d626be419b0c graster/hacklab-engraver/.git/objects/a1/99207599f3af94759497e848fef2883df8a76b graster/hacklab-engraver/.git/objects/ac/ae4229fe68fd4923d125246686c852d5ff2753 graster/hacklab-engraver/.git/objects/af/33204aebd30798d911f9ec8b6a5698726b60b5 graster/hacklab-engraver/.git/objects/b3/0bed63de14c07bd564eac82fe54f010bf92832 graster/hacklab-engraver/.git/objects/cc/b6e0ad8e62b83d682cd474a2b4216f3b70fd8c graster/hacklab-engraver/.git/objects/d1/3c62bbf9d08745832b0a4c58d43f668eb3e207 graster/hacklab-engraver/.git/objects/da/a8c4c5d9403e3de6de63bf00d963522725ba18 graster/hacklab-engraver/.git/objects/dc/37075577db6f593d8a5c6e60e081e138477e8a graster/hacklab-engraver/.git/objects/de/bcc458e2f4f7f49261278ea90701db1bbc9611 graster/hacklab-engraver/.git/objects/e2/46361935fe95d0e4629abdaa1e48b8d09f3eee graster/hacklab-engraver/.git/objects/e4/d9a3115b00e8960dd5555a488b8778b095e8c1 graster/hacklab-engraver/.git/objects/e8/ff6ce26c2cd4370986e0cfc5beb41c0a39c061 graster/hacklab-engraver/.git/objects/ec/0de6b82e3ba8dc08be4a1d41ad756f1da012fd graster/hacklab-engraver/.git/objects/f0/2a7c6678d381e90f39fd7f5b6a1a7e7c53d523 graster/hacklab-engraver/.git/objects/f5/326e4e272b2b6e7018cc0ab02aa5782d9c9fcc graster/hacklab-engraver/.git/objects/f6/f4f18f2b41ec1c9cfcea1e6c74c6e9da89fb03 graster/hacklab-engraver/.git/objects/f7/5c96c6ae9db0be0f79a7e05eb01379bc9a64ac graster/hacklab-engraver/.git/objects/fd/c9663091370e717dc46ca5c52db6b4c7313730 graster/hacklab-engraver/.git/objects/fe/62c30f734c6223bc20d82619baca9da73a3a8a graster/hacklab-engraver/.git/packed-refs graster/hacklab-engraver/.git/refs/heads/master graster/hacklab-engraver/.git/refs/remotes/origin/HEAD graster/hacklab-engraver/.gitignore graster/hacklab-engraver/M101 graster/hacklab-engraver/README graster/hacklab-engraver/custom.hal graster/hacklab-engraver/custom_postgui.hal graster/hacklab-engraver/emc.nml graster/hacklab-engraver/hacklab-engraver3.hal graster/hacklab-engraver/hacklab-engraver3.ini graster/hacklab-engraver/probe-results.txt graster/hacklab-engraver/tool.tbl graster/lasercheck.tgz graster/signer4laser2x1.png graster/signer4laser2x1.png.cut.ngc graster/signer4laser2x1.png.raster.gmask graster/signer4laser2x1.png.raster.ngc graster/test.png src/clojure/asm/AnnotationVisitor.java src/clojure/asm/AnnotationWriter.java src/clojure/asm/Attribute.java src/clojure/asm/ByteVector.java src/clojure/asm/ClassAdapter.java src/clojure/asm/ClassReader.java src/clojure/asm/ClassVisitor.java src/clojure/asm/ClassWriter.java src/clojure/asm/Edge.java src/clojure/asm/FieldVisitor.java src/clojure/asm/FieldWriter.java src/clojure/asm/Frame.java src/clojure/asm/Handler.java src/clojure/asm/Item.java src/clojure/asm/Label.java src/clojure/asm/MethodAdapter.java src/clojure/asm/MethodVisitor.java src/clojure/asm/MethodWriter.java src/clojure/asm/Opcodes.java src/clojure/asm/Type.java src/clojure/asm/commons/AdviceAdapter.java src/clojure/asm/commons/AnalyzerAdapter.java src/clojure/asm/commons/CodeSizeEvaluator.java src/clojure/asm/commons/EmptyVisitor.java src/clojure/asm/commons/GeneratorAdapter.java src/clojure/asm/commons/LocalVariablesSorter.java src/clojure/asm/commons/Method.java src/clojure/asm/commons/SerialVersionUIDAdder.java src/clojure/asm/commons/StaticInitMerger.java src/clojure/asm/commons/TableSwitchGenerator.java src/clojure/asm/commons/package.html src/clojure/asm/package.html src/clojure/contrib/accumulators.clj src/clojure/contrib/agent_utils.clj src/clojure/contrib/apply_macro.clj src/clojure/contrib/base64.clj src/clojure/contrib/classpath.clj src/clojure/contrib/combinatorics.clj src/clojure/contrib/command_line.clj src/clojure/contrib/complex_numbers.clj src/clojure/contrib/cond.clj src/clojure/contrib/condition.clj src/clojure/contrib/condition/Condition.clj src/clojure/contrib/core.clj src/clojure/contrib/dataflow.clj src/clojure/contrib/datalog.clj src/clojure/contrib/datalog/database.clj src/clojure/contrib/datalog/literals.clj src/clojure/contrib/datalog/magic.clj src/clojure/contrib/datalog/rules.clj src/clojure/contrib/datalog/softstrat.clj src/clojure/contrib/datalog/util.clj src/clojure/contrib/def.clj src/clojure/contrib/duck_streams.clj src/clojure/contrib/error_kit.clj src/clojure/contrib/except.clj src/clojure/contrib/fcase.clj src/clojure/contrib/find_namespaces.clj src/clojure/contrib/fnmap.clj src/clojure/contrib/fnmap/PersistentFnMap.clj src/clojure/contrib/gen_html_docs.clj src/clojure/contrib/generic.clj src/clojure/contrib/generic/arithmetic.clj src/clojure/contrib/generic/collection.clj src/clojure/contrib/generic/comparison.clj src/clojure/contrib/generic/functor.clj src/clojure/contrib/generic/math_functions.clj src/clojure/contrib/graph.clj src/clojure/contrib/greatest_least.clj src/clojure/contrib/http/agent.clj src/clojure/contrib/http/connection.clj src/clojure/contrib/import_static.clj src/clojure/contrib/io.clj src/clojure/contrib/jar.clj src/clojure/contrib/java_utils.clj src/clojure/contrib/javadoc.clj src/clojure/contrib/javadoc/browse.clj src/clojure/contrib/javadoc/browse_ui.clj src/clojure/contrib/jmx.clj src/clojure/contrib/jmx/Bean.clj src/clojure/contrib/jmx/client.clj src/clojure/contrib/jmx/data.clj src/clojure/contrib/jmx/server.clj src/clojure/contrib/json.clj src/clojure/contrib/lazy_seqs.clj src/clojure/contrib/lazy_xml.clj src/clojure/contrib/lazy_xml/with_pull.clj src/clojure/contrib/logging.clj src/clojure/contrib/macro_utils.clj src/clojure/contrib/macros.clj src/clojure/contrib/map_utils.clj src/clojure/contrib/math.clj src/clojure/contrib/miglayout.clj src/clojure/contrib/miglayout/internal.clj src/clojure/contrib/mmap.clj src/clojure/contrib/mock.clj src/clojure/contrib/mock.clj.rej src/clojure/contrib/mock/test_adapter.clj src/clojure/contrib/monadic_io_streams.clj src/clojure/contrib/monads.clj src/clojure/contrib/ns_utils.clj src/clojure/contrib/pprint.clj src/clojure/contrib/pprint/cl_format.clj src/clojure/contrib/pprint/column_writer.clj src/clojure/contrib/pprint/dispatch.clj src/clojure/contrib/pprint/pprint_base.clj src/clojure/contrib/pprint/pretty_writer.clj src/clojure/contrib/pprint/utilities.clj src/clojure/contrib/probabilities/finite_distributions.clj src/clojure/contrib/probabilities/monte_carlo.clj src/clojure/contrib/probabilities/random_numbers.clj src/clojure/contrib/profile.clj src/clojure/contrib/properties.clj src/clojure/contrib/prxml.clj src/clojure/contrib/reflect.clj src/clojure/contrib/repl_ln.clj src/clojure/contrib/repl_utils.clj src/clojure/contrib/repl_utils/javadoc.clj src/clojure/contrib/seq.clj src/clojure/contrib/seq_utils.clj src/clojure/contrib/server_socket.clj src/clojure/contrib/set.clj src/clojure/contrib/shell.clj src/clojure/contrib/shell_out.clj src/clojure/contrib/singleton.clj src/clojure/contrib/sql.clj src/clojure/contrib/sql/internal.clj src/clojure/contrib/str_utils.clj src/clojure/contrib/str_utils2.clj src/clojure/contrib/stream_utils.clj src/clojure/contrib/string.clj src/clojure/contrib/strint.clj src/clojure/contrib/swing_utils.clj src/clojure/contrib/test_contrib/accumulators/examples.clj src/clojure/contrib/test_contrib/condition/example.clj src/clojure/contrib/test_contrib/datalog/example.clj src/clojure/contrib/test_contrib/datalog/tests/test.clj src/clojure/contrib/test_contrib/datalog/tests/test_database.clj src/clojure/contrib/test_contrib/datalog/tests/test_literals.clj src/clojure/contrib/test_contrib/datalog/tests/test_magic.clj src/clojure/contrib/test_contrib/datalog/tests/test_rules.clj src/clojure/contrib/test_contrib/datalog/tests/test_softstrat.clj src/clojure/contrib/test_contrib/datalog/tests/test_util.clj src/clojure/contrib/test_contrib/miglayout/example.clj src/clojure/contrib/test_contrib/mock/test_adapter.clj src/clojure/contrib/test_contrib/monads/examples.clj src/clojure/contrib/test_contrib/pprint/examples/hexdump.clj src/clojure/contrib/test_contrib/pprint/examples/json.clj src/clojure/contrib/test_contrib/pprint/examples/multiply.clj src/clojure/contrib/test_contrib/pprint/examples/props.clj src/clojure/contrib/test_contrib/pprint/examples/show_doc.clj src/clojure/contrib/test_contrib/pprint/examples/xml.clj src/clojure/contrib/test_contrib/pprint/test_cl_format.clj src/clojure/contrib/test_contrib/pprint/test_helper.clj src/clojure/contrib/test_contrib/pprint/test_pretty.clj src/clojure/contrib/test_contrib/probabilities/examples_finite_distributions.clj src/clojure/contrib/test_contrib/probabilities/examples_monte_carlo.clj src/clojure/contrib/test_contrib/stream_utils/examples.clj src/clojure/contrib/test_contrib/test_complex_numbers.clj src/clojure/contrib/test_contrib/test_core.clj src/clojure/contrib/test_contrib/test_dataflow.clj src/clojure/contrib/test_contrib/test_def.clj src/clojure/contrib/test_contrib/test_fnmap.clj src/clojure/contrib/test_contrib/test_graph.clj src/clojure/contrib/test_contrib/test_greatest_least.clj src/clojure/contrib/test_contrib/test_io.clj src/clojure/contrib/test_contrib/test_jmx.clj src/clojure/contrib/test_contrib/test_json.clj src/clojure/contrib/test_contrib/test_lazy_seqs.clj src/clojure/contrib/test_contrib/test_load_all.clj src/clojure/contrib/test_contrib/test_macro_utils.clj src/clojure/contrib/test_contrib/test_math.clj src/clojure/contrib/test_contrib/test_miglayout.clj src/clojure/contrib/test_contrib/test_mock.clj src/clojure/contrib/test_contrib/test_monads.clj src/clojure/contrib/test_contrib/test_profile.clj src/clojure/contrib/test_contrib/test_properties.clj src/clojure/contrib/test_contrib/test_prxml.clj src/clojure/contrib/test_contrib/test_repl_utils.clj src/clojure/contrib/test_contrib/test_seq.clj src/clojure/contrib/test_contrib/test_shell.clj src/clojure/contrib/test_contrib/test_sql.clj src/clojure/contrib/test_contrib/test_string.clj src/clojure/contrib/test_contrib/test_strint.clj src/clojure/contrib/test_contrib/test_trace.clj src/clojure/contrib/test_contrib/test_with_ns.clj src/clojure/contrib/test_contrib/types/examples.clj src/clojure/contrib/test_is.clj src/clojure/contrib/trace.clj src/clojure/contrib/types.clj src/clojure/contrib/with_ns.clj src/clojure/contrib/zip_filter.clj src/clojure/contrib/zip_filter/xml.clj src/clojure/core.clj src/clojure/core/protocols.clj src/clojure/core_deftype.clj src/clojure/core_print.clj src/clojure/core_proxy.clj src/clojure/genclass.clj src/clojure/gvec.clj src/clojure/inspector.clj src/clojure/java/browse.clj src/clojure/java/browse_ui.clj src/clojure/java/io.clj src/clojure/java/javadoc.clj src/clojure/java/shell.clj src/clojure/lang/AFn.java src/clojure/lang/AFunction.java src/clojure/lang/AMapEntry.java src/clojure/lang/APersistentMap.java src/clojure/lang/APersistentSet.java src/clojure/lang/APersistentVector.java src/clojure/lang/ARef.java src/clojure/lang/AReference.java src/clojure/lang/ASeq.java src/clojure/lang/ATransientMap.java src/clojure/lang/ATransientSet.java src/clojure/lang/Agent.java src/clojure/lang/ArrayChunk.java src/clojure/lang/ArraySeq.java src/clojure/lang/Associative.java src/clojure/lang/Atom.java src/clojure/lang/Binding.java src/clojure/lang/Box.java src/clojure/lang/ChunkBuffer.java src/clojure/lang/ChunkedCons.java src/clojure/lang/Compile.java src/clojure/lang/Compiler.java src/clojure/lang/Cons.java src/clojure/lang/Counted.java src/clojure/lang/Delay.java src/clojure/lang/DynamicClassLoader.java src/clojure/lang/EnumerationSeq.java src/clojure/lang/Fn.java src/clojure/lang/IChunk.java src/clojure/lang/IChunkedSeq.java src/clojure/lang/IDeref.java src/clojure/lang/IEditableCollection.java src/clojure/lang/IFn.java src/clojure/lang/IKeywordLookup.java src/clojure/lang/ILookup.java src/clojure/lang/ILookupHost.java src/clojure/lang/ILookupSite.java src/clojure/lang/ILookupThunk.java src/clojure/lang/IMapEntry.java src/clojure/lang/IMeta.java src/clojure/lang/IObj.java src/clojure/lang/IPersistentCollection.java src/clojure/lang/IPersistentList.java src/clojure/lang/IPersistentMap.java src/clojure/lang/IPersistentSet.java src/clojure/lang/IPersistentStack.java src/clojure/lang/IPersistentVector.java src/clojure/lang/IProxy.java src/clojure/lang/IReduce.java src/clojure/lang/IRef.java src/clojure/lang/IReference.java src/clojure/lang/ISeq.java src/clojure/lang/ITransientAssociative.java src/clojure/lang/ITransientCollection.java src/clojure/lang/ITransientMap.java src/clojure/lang/ITransientSet.java src/clojure/lang/ITransientVector.java src/clojure/lang/Indexed.java src/clojure/lang/IndexedSeq.java src/clojure/lang/IteratorSeq.java src/clojure/lang/Keyword.java src/clojure/lang/KeywordLookupSite.java src/clojure/lang/LazilyPersistentVector.java src/clojure/lang/LazySeq.java src/clojure/lang/LineNumberingPushbackReader.java src/clojure/lang/LispReader.java src/clojure/lang/LockingTransaction.java src/clojure/lang/MapEntry.java src/clojure/lang/MapEquivalence.java src/clojure/lang/MethodImplCache.java src/clojure/lang/MultiFn.java src/clojure/lang/Named.java src/clojure/lang/Namespace.java src/clojure/lang/Numbers.java src/clojure/lang/Obj.java src/clojure/lang/PersistentArrayMap.java src/clojure/lang/PersistentHashMap.java src/clojure/lang/PersistentHashSet.java src/clojure/lang/PersistentList.java src/clojure/lang/PersistentQueue.java src/clojure/lang/PersistentStructMap.java src/clojure/lang/PersistentTreeMap.java src/clojure/lang/PersistentTreeSet.java src/clojure/lang/PersistentVector.java src/clojure/lang/ProxyHandler.java src/clojure/lang/RT.java src/clojure/lang/Range.java src/clojure/lang/Ratio.java src/clojure/lang/Ref.java src/clojure/lang/Reflector.java src/clojure/lang/Repl.java src/clojure/lang/RestFn.java src/clojure/lang/Reversible.java src/clojure/lang/Script.java src/clojure/lang/SeqEnumeration.java src/clojure/lang/SeqIterator.java src/clojure/lang/Seqable.java src/clojure/lang/Sequential.java src/clojure/lang/Settable.java src/clojure/lang/Sorted.java src/clojure/lang/StringSeq.java src/clojure/lang/Symbol.java src/clojure/lang/TransactionalHashMap.java src/clojure/lang/Util.java src/clojure/lang/Var.java src/clojure/lang/XMLHandler.java src/clojure/main.clj src/clojure/main.java src/clojure/parallel.clj src/clojure/pprint.clj src/clojure/pprint/cl_format.clj src/clojure/pprint/column_writer.clj src/clojure/pprint/dispatch.clj src/clojure/pprint/pprint_base.clj src/clojure/pprint/pretty_writer.clj src/clojure/pprint/utilities.clj src/clojure/repl.clj src/clojure/set.clj src/clojure/stacktrace.clj src/clojure/string.clj src/clojure/template.clj src/clojure/test.clj src/clojure/test/junit.clj src/clojure/test/tap.clj src/clojure/test_clojure.clj src/clojure/test_clojure/agents.clj src/clojure/test_clojure/annotations.clj src/clojure/test_clojure/annotations/java_5.clj src/clojure/test_clojure/annotations/java_6_and_later.clj src/clojure/test_clojure/atoms.clj src/clojure/test_clojure/clojure_set.clj src/clojure/test_clojure/clojure_xml.clj src/clojure/test_clojure/clojure_zip.clj src/clojure/test_clojure/compilation.clj src/clojure/test_clojure/control.clj src/clojure/test_clojure/data_structures.clj src/clojure/test_clojure/def.clj src/clojure/test_clojure/evaluation.clj src/clojure/test_clojure/for.clj src/clojure/test_clojure/genclass.clj src/clojure/test_clojure/genclass/examples.clj src/clojure/test_clojure/helpers.clj src/clojure/test_clojure/java/io.clj src/clojure/test_clojure/java/javadoc.clj src/clojure/test_clojure/java/shell.clj src/clojure/test_clojure/java_interop.clj src/clojure/test_clojure/logic.clj src/clojure/test_clojure/macros.clj src/clojure/test_clojure/main.clj src/clojure/test_clojure/metadata.clj src/clojure/test_clojure/multimethods.clj src/clojure/test_clojure/ns_libs.clj src/clojure/test_clojure/numbers.clj src/clojure/test_clojure/other_functions.clj src/clojure/test_clojure/parallel.clj src/clojure/test_clojure/pprint.clj src/clojure/test_clojure/pprint/test_cl_format.clj src/clojure/test_clojure/pprint/test_helper.clj src/clojure/test_clojure/pprint/test_pretty.clj src/clojure/test_clojure/predicates.clj src/clojure/test_clojure/printer.clj src/clojure/test_clojure/protocols.clj src/clojure/test_clojure/protocols/examples.clj src/clojure/test_clojure/protocols/more_examples.clj src/clojure/test_clojure/reader.clj src/clojure/test_clojure/refs.clj src/clojure/test_clojure/repl.clj src/clojure/test_clojure/repl/example.clj src/clojure/test_clojure/rt.clj src/clojure/test_clojure/sequences.clj src/clojure/test_clojure/serialization.clj src/clojure/test_clojure/special.clj src/clojure/test_clojure/string.clj src/clojure/test_clojure/test.clj src/clojure/test_clojure/test_fixtures.clj src/clojure/test_clojure/transients.clj src/clojure/test_clojure/vars.clj src/clojure/test_clojure/vectors.clj src/clojure/walk.clj src/clojure/xml.clj src/clojure/zip.clj src/laser/rasterize.clj src/laser/rubyisms.clj |
diffstat | 523 files changed, 14013 insertions(+), 96539 deletions(-) [+] |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/graster/.#signer4laser2x1.png.raster.gmask Tue Aug 24 19:06:45 2010 -0400 1.3 @@ -0,0 +1,1 @@ 1.4 +r@RLM.8437:1282362081 1.5 \ No newline at end of file
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/graster/config.yml Tue Aug 24 19:06:45 2010 -0400 2.3 @@ -0,0 +1,10 @@ 2.4 +feed: 120 2.5 +dpi: [500, 500] 2.6 +offset: [1.0, 1.0] 2.7 +cut_feed: 20 2.8 +on_range: [0.0, 0.5] 2.9 +corner_radius: 0 2.10 +overshoot: 0.5 2.11 +tile_size: [false, false] 2.12 +repeat: [1, 1] 2.13 +tile_spacing: [0.125, 0.125]
3.1 Binary file graster/graster-example.tgz has changed
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/graster/graster/.git/HEAD Tue Aug 24 19:06:45 2010 -0400 4.3 @@ -0,0 +1,1 @@ 4.4 +ref: refs/heads/master
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/graster/graster/.git/config Tue Aug 24 19:06:45 2010 -0400 5.3 @@ -0,0 +1,11 @@ 5.4 +[core] 5.5 + repositoryformatversion = 0 5.6 + filemode = true 5.7 + bare = false 5.8 + logallrefupdates = true 5.9 +[remote "origin"] 5.10 + fetch = +refs/heads/*:refs/remotes/origin/* 5.11 + url = http://github.com/jedediah/graster.git 5.12 +[branch "master"] 5.13 + remote = origin 5.14 + merge = refs/heads/master
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/graster/graster/.git/description Tue Aug 24 19:06:45 2010 -0400 6.3 @@ -0,0 +1,1 @@ 6.4 +Unnamed repository; edit this file 'description' to name the repository.
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/graster/graster/.git/hooks/applypatch-msg.sample Tue Aug 24 19:06:45 2010 -0400 7.3 @@ -0,0 +1,15 @@ 7.4 +#!/bin/sh 7.5 +# 7.6 +# An example hook script to check the commit log message taken by 7.7 +# applypatch from an e-mail message. 7.8 +# 7.9 +# The hook should exit with non-zero status after issuing an 7.10 +# appropriate message if it wants to stop the commit. The hook is 7.11 +# allowed to edit the commit message file. 7.12 +# 7.13 +# To enable this hook, rename this file to "applypatch-msg". 7.14 + 7.15 +. git-sh-setup 7.16 +test -x "$GIT_DIR/hooks/commit-msg" && 7.17 + exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"} 7.18 +:
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/graster/graster/.git/hooks/commit-msg.sample Tue Aug 24 19:06:45 2010 -0400 8.3 @@ -0,0 +1,24 @@ 8.4 +#!/bin/sh 8.5 +# 8.6 +# An example hook script to check the commit log message. 8.7 +# Called by git-commit with one argument, the name of the file 8.8 +# that has the commit message. The hook should exit with non-zero 8.9 +# status after issuing an appropriate message if it wants to stop the 8.10 +# commit. The hook is allowed to edit the commit message file. 8.11 +# 8.12 +# To enable this hook, rename this file to "commit-msg". 8.13 + 8.14 +# Uncomment the below to add a Signed-off-by line to the message. 8.15 +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg 8.16 +# hook is more suited to it. 8.17 +# 8.18 +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') 8.19 +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" 8.20 + 8.21 +# This example catches duplicate Signed-off-by lines. 8.22 + 8.23 +test "" = "$(grep '^Signed-off-by: ' "$1" | 8.24 + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { 8.25 + echo >&2 Duplicate Signed-off-by lines. 8.26 + exit 1 8.27 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/graster/graster/.git/hooks/post-commit.sample Tue Aug 24 19:06:45 2010 -0400 9.3 @@ -0,0 +1,8 @@ 9.4 +#!/bin/sh 9.5 +# 9.6 +# An example hook script that is called after a successful 9.7 +# commit is made. 9.8 +# 9.9 +# To enable this hook, rename this file to "post-commit". 9.10 + 9.11 +: Nothing
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/graster/graster/.git/hooks/post-receive.sample Tue Aug 24 19:06:45 2010 -0400 10.3 @@ -0,0 +1,15 @@ 10.4 +#!/bin/sh 10.5 +# 10.6 +# An example hook script for the "post-receive" event. 10.7 +# 10.8 +# The "post-receive" script is run after receive-pack has accepted a pack 10.9 +# and the repository has been updated. It is passed arguments in through 10.10 +# stdin in the form 10.11 +# <oldrev> <newrev> <refname> 10.12 +# For example: 10.13 +# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master 10.14 +# 10.15 +# see contrib/hooks/ for a sample, or uncomment the next line and 10.16 +# rename the file to "post-receive". 10.17 + 10.18 +#. /usr/share/doc/git-core/contrib/hooks/post-receive-email
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/graster/graster/.git/hooks/post-update.sample Tue Aug 24 19:06:45 2010 -0400 11.3 @@ -0,0 +1,8 @@ 11.4 +#!/bin/sh 11.5 +# 11.6 +# An example hook script to prepare a packed repository for use over 11.7 +# dumb transports. 11.8 +# 11.9 +# To enable this hook, rename this file to "post-update". 11.10 + 11.11 +exec git-update-server-info
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/graster/graster/.git/hooks/pre-applypatch.sample Tue Aug 24 19:06:45 2010 -0400 12.3 @@ -0,0 +1,14 @@ 12.4 +#!/bin/sh 12.5 +# 12.6 +# An example hook script to verify what is about to be committed 12.7 +# by applypatch from an e-mail message. 12.8 +# 12.9 +# The hook should exit with non-zero status after issuing an 12.10 +# appropriate message if it wants to stop the commit. 12.11 +# 12.12 +# To enable this hook, rename this file to "pre-applypatch". 12.13 + 12.14 +. git-sh-setup 12.15 +test -x "$GIT_DIR/hooks/pre-commit" && 12.16 + exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} 12.17 +:
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/graster/graster/.git/hooks/pre-commit.sample Tue Aug 24 19:06:45 2010 -0400 13.3 @@ -0,0 +1,46 @@ 13.4 +#!/bin/sh 13.5 +# 13.6 +# An example hook script to verify what is about to be committed. 13.7 +# Called by git-commit with no arguments. The hook should 13.8 +# exit with non-zero status after issuing an appropriate message if 13.9 +# it wants to stop the commit. 13.10 +# 13.11 +# To enable this hook, rename this file to "pre-commit". 13.12 + 13.13 +if git-rev-parse --verify HEAD >/dev/null 2>&1 13.14 +then 13.15 + against=HEAD 13.16 +else 13.17 + # Initial commit: diff against an empty tree object 13.18 + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 13.19 +fi 13.20 + 13.21 +# If you want to allow non-ascii filenames set this variable to true. 13.22 +allownonascii=$(git config hooks.allownonascii) 13.23 + 13.24 +# Cross platform projects tend to avoid non-ascii filenames; prevent 13.25 +# them from being added to the repository. We exploit the fact that the 13.26 +# printable range starts at the space character and ends with tilde. 13.27 +if [ "$allownonascii" != "true" ] && 13.28 + # Note that the use of brackets around a tr range is ok here, (it's 13.29 + # even required, for portability to Solaris 10's /usr/bin/tr), since 13.30 + # the square bracket bytes happen to fall in the designated range. 13.31 + test "$(git diff --cached --name-only --diff-filter=A -z $against | 13.32 + LC_ALL=C tr -d '[ -~]\0')" 13.33 +then 13.34 + echo "Error: Attempt to add a non-ascii file name." 13.35 + echo 13.36 + echo "This can cause problems if you want to work" 13.37 + echo "with people on other platforms." 13.38 + echo 13.39 + echo "To be portable it is advisable to rename the file ..." 13.40 + echo 13.41 + echo "If you know what you are doing you can disable this" 13.42 + echo "check using:" 13.43 + echo 13.44 + echo " git config hooks.allownonascii true" 13.45 + echo 13.46 + exit 1 13.47 +fi 13.48 + 13.49 +exec git diff-index --check --cached $against --
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/graster/graster/.git/hooks/pre-rebase.sample Tue Aug 24 19:06:45 2010 -0400 14.3 @@ -0,0 +1,169 @@ 14.4 +#!/bin/sh 14.5 +# 14.6 +# Copyright (c) 2006, 2008 Junio C Hamano 14.7 +# 14.8 +# The "pre-rebase" hook is run just before "git-rebase" starts doing 14.9 +# its job, and can prevent the command from running by exiting with 14.10 +# non-zero status. 14.11 +# 14.12 +# The hook is called with the following parameters: 14.13 +# 14.14 +# $1 -- the upstream the series was forked from. 14.15 +# $2 -- the branch being rebased (or empty when rebasing the current branch). 14.16 +# 14.17 +# This sample shows how to prevent topic branches that are already 14.18 +# merged to 'next' branch from getting rebased, because allowing it 14.19 +# would result in rebasing already published history. 14.20 + 14.21 +publish=next 14.22 +basebranch="$1" 14.23 +if test "$#" = 2 14.24 +then 14.25 + topic="refs/heads/$2" 14.26 +else 14.27 + topic=`git symbolic-ref HEAD` || 14.28 + exit 0 ;# we do not interrupt rebasing detached HEAD 14.29 +fi 14.30 + 14.31 +case "$topic" in 14.32 +refs/heads/??/*) 14.33 + ;; 14.34 +*) 14.35 + exit 0 ;# we do not interrupt others. 14.36 + ;; 14.37 +esac 14.38 + 14.39 +# Now we are dealing with a topic branch being rebased 14.40 +# on top of master. Is it OK to rebase it? 14.41 + 14.42 +# Does the topic really exist? 14.43 +git show-ref -q "$topic" || { 14.44 + echo >&2 "No such branch $topic" 14.45 + exit 1 14.46 +} 14.47 + 14.48 +# Is topic fully merged to master? 14.49 +not_in_master=`git-rev-list --pretty=oneline ^master "$topic"` 14.50 +if test -z "$not_in_master" 14.51 +then 14.52 + echo >&2 "$topic is fully merged to master; better remove it." 14.53 + exit 1 ;# we could allow it, but there is no point. 14.54 +fi 14.55 + 14.56 +# Is topic ever merged to next? If so you should not be rebasing it. 14.57 +only_next_1=`git-rev-list ^master "^$topic" ${publish} | sort` 14.58 +only_next_2=`git-rev-list ^master ${publish} | sort` 14.59 +if test "$only_next_1" = "$only_next_2" 14.60 +then 14.61 + not_in_topic=`git-rev-list "^$topic" master` 14.62 + if test -z "$not_in_topic" 14.63 + then 14.64 + echo >&2 "$topic is already up-to-date with master" 14.65 + exit 1 ;# we could allow it, but there is no point. 14.66 + else 14.67 + exit 0 14.68 + fi 14.69 +else 14.70 + not_in_next=`git-rev-list --pretty=oneline ^${publish} "$topic"` 14.71 + perl -e ' 14.72 + my $topic = $ARGV[0]; 14.73 + my $msg = "* $topic has commits already merged to public branch:\n"; 14.74 + my (%not_in_next) = map { 14.75 + /^([0-9a-f]+) /; 14.76 + ($1 => 1); 14.77 + } split(/\n/, $ARGV[1]); 14.78 + for my $elem (map { 14.79 + /^([0-9a-f]+) (.*)$/; 14.80 + [$1 => $2]; 14.81 + } split(/\n/, $ARGV[2])) { 14.82 + if (!exists $not_in_next{$elem->[0]}) { 14.83 + if ($msg) { 14.84 + print STDERR $msg; 14.85 + undef $msg; 14.86 + } 14.87 + print STDERR " $elem->[1]\n"; 14.88 + } 14.89 + } 14.90 + ' "$topic" "$not_in_next" "$not_in_master" 14.91 + exit 1 14.92 +fi 14.93 + 14.94 +exit 0 14.95 + 14.96 +################################################################ 14.97 + 14.98 +This sample hook safeguards topic branches that have been 14.99 +published from being rewound. 14.100 + 14.101 +The workflow assumed here is: 14.102 + 14.103 + * Once a topic branch forks from "master", "master" is never 14.104 + merged into it again (either directly or indirectly). 14.105 + 14.106 + * Once a topic branch is fully cooked and merged into "master", 14.107 + it is deleted. If you need to build on top of it to correct 14.108 + earlier mistakes, a new topic branch is created by forking at 14.109 + the tip of the "master". This is not strictly necessary, but 14.110 + it makes it easier to keep your history simple. 14.111 + 14.112 + * Whenever you need to test or publish your changes to topic 14.113 + branches, merge them into "next" branch. 14.114 + 14.115 +The script, being an example, hardcodes the publish branch name 14.116 +to be "next", but it is trivial to make it configurable via 14.117 +$GIT_DIR/config mechanism. 14.118 + 14.119 +With this workflow, you would want to know: 14.120 + 14.121 +(1) ... if a topic branch has ever been merged to "next". Young 14.122 + topic branches can have stupid mistakes you would rather 14.123 + clean up before publishing, and things that have not been 14.124 + merged into other branches can be easily rebased without 14.125 + affecting other people. But once it is published, you would 14.126 + not want to rewind it. 14.127 + 14.128 +(2) ... if a topic branch has been fully merged to "master". 14.129 + Then you can delete it. More importantly, you should not 14.130 + build on top of it -- other people may already want to 14.131 + change things related to the topic as patches against your 14.132 + "master", so if you need further changes, it is better to 14.133 + fork the topic (perhaps with the same name) afresh from the 14.134 + tip of "master". 14.135 + 14.136 +Let's look at this example: 14.137 + 14.138 + o---o---o---o---o---o---o---o---o---o "next" 14.139 + / / / / 14.140 + / a---a---b A / / 14.141 + / / / / 14.142 + / / c---c---c---c B / 14.143 + / / / \ / 14.144 + / / / b---b C \ / 14.145 + / / / / \ / 14.146 + ---o---o---o---o---o---o---o---o---o---o---o "master" 14.147 + 14.148 + 14.149 +A, B and C are topic branches. 14.150 + 14.151 + * A has one fix since it was merged up to "next". 14.152 + 14.153 + * B has finished. It has been fully merged up to "master" and "next", 14.154 + and is ready to be deleted. 14.155 + 14.156 + * C has not merged to "next" at all. 14.157 + 14.158 +We would want to allow C to be rebased, refuse A, and encourage 14.159 +B to be deleted. 14.160 + 14.161 +To compute (1): 14.162 + 14.163 + git-rev-list ^master ^topic next 14.164 + git-rev-list ^master next 14.165 + 14.166 + if these match, topic has not merged in next at all. 14.167 + 14.168 +To compute (2): 14.169 + 14.170 + git-rev-list master..topic 14.171 + 14.172 + if this is empty, it is fully merged to "master".
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/graster/graster/.git/hooks/prepare-commit-msg.sample Tue Aug 24 19:06:45 2010 -0400 15.3 @@ -0,0 +1,36 @@ 15.4 +#!/bin/sh 15.5 +# 15.6 +# An example hook script to prepare the commit log message. 15.7 +# Called by git-commit with the name of the file that has the 15.8 +# commit message, followed by the description of the commit 15.9 +# message's source. The hook's purpose is to edit the commit 15.10 +# message file. If the hook fails with a non-zero status, 15.11 +# the commit is aborted. 15.12 +# 15.13 +# To enable this hook, rename this file to "prepare-commit-msg". 15.14 + 15.15 +# This hook includes three examples. The first comments out the 15.16 +# "Conflicts:" part of a merge commit. 15.17 +# 15.18 +# The second includes the output of "git diff --name-status -r" 15.19 +# into the message, just before the "git status" output. It is 15.20 +# commented because it doesn't cope with --amend or with squashed 15.21 +# commits. 15.22 +# 15.23 +# The third example adds a Signed-off-by line to the message, that can 15.24 +# still be edited. This is rarely a good idea. 15.25 + 15.26 +case "$2,$3" in 15.27 + merge,) 15.28 + perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; 15.29 + 15.30 +# ,|template,) 15.31 +# perl -i.bak -pe ' 15.32 +# print "\n" . `git diff --cached --name-status -r` 15.33 +# if /^#/ && $first++ == 0' "$1" ;; 15.34 + 15.35 + *) ;; 15.36 +esac 15.37 + 15.38 +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') 15.39 +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/graster/graster/.git/hooks/update.sample Tue Aug 24 19:06:45 2010 -0400 16.3 @@ -0,0 +1,128 @@ 16.4 +#!/bin/sh 16.5 +# 16.6 +# An example hook script to blocks unannotated tags from entering. 16.7 +# Called by git-receive-pack with arguments: refname sha1-old sha1-new 16.8 +# 16.9 +# To enable this hook, rename this file to "update". 16.10 +# 16.11 +# Config 16.12 +# ------ 16.13 +# hooks.allowunannotated 16.14 +# This boolean sets whether unannotated tags will be allowed into the 16.15 +# repository. By default they won't be. 16.16 +# hooks.allowdeletetag 16.17 +# This boolean sets whether deleting tags will be allowed in the 16.18 +# repository. By default they won't be. 16.19 +# hooks.allowmodifytag 16.20 +# This boolean sets whether a tag may be modified after creation. By default 16.21 +# it won't be. 16.22 +# hooks.allowdeletebranch 16.23 +# This boolean sets whether deleting branches will be allowed in the 16.24 +# repository. By default they won't be. 16.25 +# hooks.denycreatebranch 16.26 +# This boolean sets whether remotely creating branches will be denied 16.27 +# in the repository. By default this is allowed. 16.28 +# 16.29 + 16.30 +# --- Command line 16.31 +refname="$1" 16.32 +oldrev="$2" 16.33 +newrev="$3" 16.34 + 16.35 +# --- Safety check 16.36 +if [ -z "$GIT_DIR" ]; then 16.37 + echo "Don't run this script from the command line." >&2 16.38 + echo " (if you want, you could supply GIT_DIR then run" >&2 16.39 + echo " $0 <ref> <oldrev> <newrev>)" >&2 16.40 + exit 1 16.41 +fi 16.42 + 16.43 +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then 16.44 + echo "Usage: $0 <ref> <oldrev> <newrev>" >&2 16.45 + exit 1 16.46 +fi 16.47 + 16.48 +# --- Config 16.49 +allowunannotated=$(git config --bool hooks.allowunannotated) 16.50 +allowdeletebranch=$(git config --bool hooks.allowdeletebranch) 16.51 +denycreatebranch=$(git config --bool hooks.denycreatebranch) 16.52 +allowdeletetag=$(git config --bool hooks.allowdeletetag) 16.53 +allowmodifytag=$(git config --bool hooks.allowmodifytag) 16.54 + 16.55 +# check for no description 16.56 +projectdesc=$(sed -e '1q' "$GIT_DIR/description") 16.57 +case "$projectdesc" in 16.58 +"Unnamed repository"* | "") 16.59 + echo "*** Project description file hasn't been set" >&2 16.60 + exit 1 16.61 + ;; 16.62 +esac 16.63 + 16.64 +# --- Check types 16.65 +# if $newrev is 0000...0000, it's a commit to delete a ref. 16.66 +zero="0000000000000000000000000000000000000000" 16.67 +if [ "$newrev" = "$zero" ]; then 16.68 + newrev_type=delete 16.69 +else 16.70 + newrev_type=$(git-cat-file -t $newrev) 16.71 +fi 16.72 + 16.73 +case "$refname","$newrev_type" in 16.74 + refs/tags/*,commit) 16.75 + # un-annotated tag 16.76 + short_refname=${refname##refs/tags/} 16.77 + if [ "$allowunannotated" != "true" ]; then 16.78 + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 16.79 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 16.80 + exit 1 16.81 + fi 16.82 + ;; 16.83 + refs/tags/*,delete) 16.84 + # delete tag 16.85 + if [ "$allowdeletetag" != "true" ]; then 16.86 + echo "*** Deleting a tag is not allowed in this repository" >&2 16.87 + exit 1 16.88 + fi 16.89 + ;; 16.90 + refs/tags/*,tag) 16.91 + # annotated tag 16.92 + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 16.93 + then 16.94 + echo "*** Tag '$refname' already exists." >&2 16.95 + echo "*** Modifying a tag is not allowed in this repository." >&2 16.96 + exit 1 16.97 + fi 16.98 + ;; 16.99 + refs/heads/*,commit) 16.100 + # branch 16.101 + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then 16.102 + echo "*** Creating a branch is not allowed in this repository" >&2 16.103 + exit 1 16.104 + fi 16.105 + ;; 16.106 + refs/heads/*,delete) 16.107 + # delete branch 16.108 + if [ "$allowdeletebranch" != "true" ]; then 16.109 + echo "*** Deleting a branch is not allowed in this repository" >&2 16.110 + exit 1 16.111 + fi 16.112 + ;; 16.113 + refs/remotes/*,commit) 16.114 + # tracking branch 16.115 + ;; 16.116 + refs/remotes/*,delete) 16.117 + # delete tracking branch 16.118 + if [ "$allowdeletebranch" != "true" ]; then 16.119 + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 16.120 + exit 1 16.121 + fi 16.122 + ;; 16.123 + *) 16.124 + # Anything else (is there anything else?) 16.125 + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 16.126 + exit 1 16.127 + ;; 16.128 +esac 16.129 + 16.130 +# --- Finished 16.131 +exit 0
17.1 Binary file graster/graster/.git/index has changed
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/graster/graster/.git/info/exclude Tue Aug 24 19:06:45 2010 -0400 18.3 @@ -0,0 +1,6 @@ 18.4 +# git-ls-files --others --exclude-from=.git/info/exclude 18.5 +# Lines that start with '#' are comments. 18.6 +# For a project mostly in C, the following would be a good set of 18.7 +# exclude patterns (uncomment them if you want to use them): 18.8 +# *.[oa] 18.9 +# *~
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/graster/graster/.git/logs/HEAD Tue Aug 24 19:06:45 2010 -0400 19.3 @@ -0,0 +1,1 @@ 19.4 +0000000000000000000000000000000000000000 ab8a364c0ac60270552542e41675a32a71a22ac8 Robert McIntyre <r@RLM.(none)> 1282257434 -0400 clone: from http://github.com/jedediah/graster.git
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/graster/graster/.git/logs/refs/heads/master Tue Aug 24 19:06:45 2010 -0400 20.3 @@ -0,0 +1,1 @@ 20.4 +0000000000000000000000000000000000000000 ab8a364c0ac60270552542e41675a32a71a22ac8 Robert McIntyre <r@RLM.(none)> 1282257434 -0400 clone: from http://github.com/jedediah/graster.git
21.1 Binary file graster/graster/.git/objects/pack/pack-5656912d40e5e13e8ad82152331d45add23e8aac.idx has changed
22.1 Binary file graster/graster/.git/objects/pack/pack-5656912d40e5e13e8ad82152331d45add23e8aac.pack has changed
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/graster/graster/.git/packed-refs Tue Aug 24 19:06:45 2010 -0400 23.3 @@ -0,0 +1,2 @@ 23.4 +# pack-refs with: peeled 23.5 +ab8a364c0ac60270552542e41675a32a71a22ac8 refs/remotes/origin/master
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/graster/graster/.git/refs/heads/master Tue Aug 24 19:06:45 2010 -0400 24.3 @@ -0,0 +1,1 @@ 24.4 +ab8a364c0ac60270552542e41675a32a71a22ac8
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/graster/graster/.git/refs/remotes/origin/HEAD Tue Aug 24 19:06:45 2010 -0400 25.3 @@ -0,0 +1,1 @@ 25.4 +ref: refs/remotes/origin/master
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/graster/graster/.gitignore Tue Aug 24 19:06:45 2010 -0400 26.3 @@ -0,0 +1,4 @@ 26.4 +*.ngc 26.5 +*.png 26.6 +*.raw 26.7 +*.pal
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/graster/graster/README.rdoc Tue Aug 24 19:06:45 2010 -0400 27.3 @@ -0,0 +1,1 @@ 27.4 += Graster 27.5 \ No newline at end of file
28.1 Binary file graster/graster/RMagick-2.13.1.tar.bz2 has changed
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/graster/graster/Rakefile Tue Aug 24 19:06:45 2010 -0400 29.3 @@ -0,0 +1,24 @@ 29.4 +begin 29.5 + require 'jeweler' 29.6 + Jeweler::Tasks.new do |s| 29.7 + s.name = "graster" 29.8 + s.description = s.summary = "G Raster!" 29.9 + s.email = "joshbuddy@gmail.com" 29.10 + s.homepage = "http://github.com/joshbuddy/graster" 29.11 + s.authors = ["Jedediah Smith", "Joshua Hull"] 29.12 + s.files = FileList["[A-Z]*", "{lib,bin}/**/*"] 29.13 + s.add_dependency 'rmagick' 29.14 + s.rubyforge_project = 'graster' 29.15 + end 29.16 + Jeweler::GemcutterTasks.new 29.17 +rescue LoadError 29.18 + puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" 29.19 +end 29.20 + 29.21 +require 'rake/rdoctask' 29.22 +desc "Generate documentation" 29.23 +Rake::RDocTask.new do |rd| 29.24 + rd.main = "README.rdoc" 29.25 + rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") 29.26 + rd.rdoc_dir = 'rdoc' 29.27 +end
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/graster/graster/VERSION Tue Aug 24 19:06:45 2010 -0400 30.3 @@ -0,0 +1,1 @@ 30.4 +0.0.7
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/graster/graster/bin/graster Tue Aug 24 19:06:45 2010 -0400 31.3 @@ -0,0 +1,9 @@ 31.4 +#!/usr/bin/env ruby 31.5 +# Tokyo cache cow command line interface script. 31.6 +# Run <tt>tokyo_cache_cow -h</tt> to get more usage. 31.7 +require File.dirname(__FILE__) + '/../lib/graster' 31.8 + 31.9 +Graster::Runner.new(ARGV).start! 31.10 + 31.11 + 31.12 +
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/graster/graster/bin/gtile Tue Aug 24 19:06:45 2010 -0400 32.3 @@ -0,0 +1,74 @@ 32.4 +#!/usr/bin/env ruby -rubygems 32.5 +# Tokyo cache cow command line interface script. 32.6 +# Run <tt>tokyo_cache_cow -h</tt> to get more usage. 32.7 +require File.dirname(__FILE__) + '/../lib/graster' 32.8 + 32.9 +unless ARGV.size == 5 32.10 + puts "usage: ruby tile.rb <input-gcode-file> <tile-width> <tile-height> <horiz-count> <vert-count>" 32.11 + exit(1) 32.12 +end 32.13 + 32.14 +def parse_line line 32.15 + nc = {} 32.16 + line.gsub(/\([^)]*\)/,'').upcase.scan(/([A-Z])\s*([0-9\.]+)?/).each {|code| nc[code[0].intern] = (code[1] && code[1].to_f) } 32.17 + nc 32.18 +end 32.19 + 32.20 +def gcode ncs 32.21 + ncs = [ncs] unless ncs.is_a? Array 32.22 + ncs.reduce('') {|a,nc| a << (nc.map {|k,v| "#{k}#{v}" }.join(' ') + "\n") } 32.23 +end 32.24 + 32.25 +tile_width = ARGV[1].to_f 32.26 +tile_height = ARGV[2].to_f 32.27 +horiz_count = ARGV[3].to_i 32.28 +vert_count = ARGV[4].to_i 32.29 + 32.30 +header = [] 32.31 +body = [] 32.32 +footer = [] 32.33 +state = :header 32.34 + 32.35 + 32.36 +File.open ARGV[0] do |io| 32.37 + io.each_line do |line| 32.38 + if (nc = parse_line(line)) != {} 32.39 + case state 32.40 + when :header 32.41 + if nc[:G] == 0 || nc[:G] == 1 32.42 + state = :body 32.43 + body << nc 32.44 + else 32.45 + header << nc 32.46 + end 32.47 + 32.48 + when :body 32.49 + if nc[:G] == 0 || nc[:G] == 1 32.50 + body << nc 32.51 + else 32.52 + state = :footer 32.53 + footer << nc 32.54 + end 32.55 + 32.56 + when :footer 32.57 + footer << nc 32.58 + end 32.59 + end # case 32.60 + 32.61 + end # io.each_line 32.62 +end # File.open 32.63 + 32.64 +print gcode(header) 32.65 + 32.66 +vert_count.times do |yc| 32.67 + horiz_count.times do |xc| 32.68 + body.each do |nc| 32.69 + nc = nc.dup 32.70 + nc[:X] += xc*tile_width if nc[:X] 32.71 + nc[:Y] += yc*tile_height if nc[:Y] 32.72 + print gcode(nc) 32.73 + end 32.74 + end 32.75 +end 32.76 + 32.77 +print gcode(footer)
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/graster/graster/config/graster.yml Tue Aug 24 19:06:45 2010 -0400 33.3 @@ -0,0 +1,10 @@ 33.4 +dpi: [500, 500] 33.5 +on_range: [0.0, 0.5] 33.6 +overshoot: 0.5 33.7 +offset: [1.0, 1.0] 33.8 +repeat: [1, 1] 33.9 +tile_size: [false, false] 33.10 +tile_spacing: [0.125, 0.125] 33.11 +feed: 120 33.12 +cut_feed: 20 33.13 +corner_radius: 0
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/graster/graster/graster.gemspec Tue Aug 24 19:06:45 2010 -0400 34.3 @@ -0,0 +1,51 @@ 34.4 +# Generated by jeweler 34.5 +# DO NOT EDIT THIS FILE DIRECTLY 34.6 +# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command 34.7 +# -*- encoding: utf-8 -*- 34.8 + 34.9 +Gem::Specification.new do |s| 34.10 + s.name = %q{graster} 34.11 + s.version = "0.0.7" 34.12 + 34.13 + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 34.14 + s.authors = ["Jedediah Smith", "Joshua Hull"] 34.15 + s.date = %q{2009-12-18} 34.16 + s.description = %q{G Raster!} 34.17 + s.email = %q{joshbuddy@gmail.com} 34.18 + s.executables = ["graster", "gtile"] 34.19 + s.extra_rdoc_files = [ 34.20 + "README.rdoc" 34.21 + ] 34.22 + s.files = [ 34.23 + "README.rdoc", 34.24 + "Rakefile", 34.25 + "VERSION", 34.26 + "bin/graster", 34.27 + "bin/gtile", 34.28 + "lib/graster.rb", 34.29 + "lib/graster/gcode_file.rb", 34.30 + "lib/graster/gmask_file.rb", 34.31 + "lib/graster/image.rb", 34.32 + "lib/graster/runner.rb" 34.33 + ] 34.34 + s.homepage = %q{http://github.com/joshbuddy/graster} 34.35 + s.rdoc_options = ["--charset=UTF-8"] 34.36 + s.require_paths = ["lib"] 34.37 + s.rubyforge_project = %q{graster} 34.38 + s.rubygems_version = %q{1.3.5} 34.39 + s.summary = %q{G Raster!} 34.40 + 34.41 + if s.respond_to? :specification_version then 34.42 + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION 34.43 + s.specification_version = 3 34.44 + 34.45 + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then 34.46 + s.add_runtime_dependency(%q<rmagick>, [">= 0"]) 34.47 + else 34.48 + s.add_dependency(%q<rmagick>, [">= 0"]) 34.49 + end 34.50 + else 34.51 + s.add_dependency(%q<rmagick>, [">= 0"]) 34.52 + end 34.53 +end 34.54 +
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/graster/graster/lib/graster.rb Tue Aug 24 19:06:45 2010 -0400 35.3 @@ -0,0 +1,328 @@ 35.4 +#!/usr/bin/env ruby 35.5 + 35.6 +require 'rubygems' 35.7 +require 'yaml' 35.8 +require 'RMagick' 35.9 + 35.10 +class Graster 35.11 + 35.12 + autoload :Runner, File.join(File.dirname(__FILE__), 'graster', 'runner') 35.13 + autoload :Image, File.join(File.dirname(__FILE__), 'graster', 'image') 35.14 + autoload :GcodeFile, File.join(File.dirname(__FILE__), 'graster', 'gcode_file') 35.15 + autoload :GmaskFile, File.join(File.dirname(__FILE__), 'graster', 'gmask_file') 35.16 + 35.17 + ROOT2 = Math.sqrt(2) 35.18 + 35.19 + OPTIONS = { 35.20 + :dpi => [[Float],"X,Y","Dots per inch of your device"], 35.21 + :on_range => [[Float], 35.22 + "MIN,MAX","Luminosity range for which the", 35.23 + "laser should be on"], 35.24 + :overshoot => [Float,"INCHES", 35.25 + "Distance the X axis should travel", 35.26 + "past the outer boundaries of the outer", 35.27 + "images. This needs to be wide enough", 35.28 + "so that the X axis doesn't start", 35.29 + "decelerating until after it has", 35.30 + "cleared the image"], 35.31 + :offset => [[Float],"X,Y", 35.32 + "Location for the bottom left corner", 35.33 + "of the bottom left tile. The X", 35.34 + "component of this setting must be", 35.35 + "equal to or greater than overshoot"], 35.36 + :repeat => [[Integer],"X,Y", 35.37 + "Number of times to repeat the image", 35.38 + "in the X and Y axes, respectively.", 35.39 + "Size of the tile(s) inches. Any nil", 35.40 + "value is calculated from the size of", 35.41 + "the bitmap"], 35.42 + :tile_spacing => [[Float],"X,Y", 35.43 + "X,Y gap between repeated tiles in", 35.44 + "inches"], 35.45 + :feed => [Float,"N", 35.46 + "Speed to move the X axis while", 35.47 + "burning, in inches/minute"], 35.48 + :cut_feed => [Float,"N", 35.49 + "Speed at which to cut out tiles"], 35.50 + :corner_radius => [Float,"N", 35.51 + "Radius of rounded corners for", 35.52 + "cutout, 0 for pointy corners"] 35.53 + } 35.54 + 35.55 + DEFAULTS = { 35.56 + :dpi => [500,500], # X,Y dots per inch of your device 35.57 + :on_range => [0.0,0.5], # Luminosity range for which the laser should be on 35.58 + :overshoot => 0.5, # Distance the X axis should travel past the outer boundaries of the outer images. 35.59 + # This needs to be wide enough so that the X axis doesn't start decelerating 35.60 + # until after it has cleared the image. 35.61 + :offset => [1.0,1.0], # X,Y location for the bottom left corner of the bottom left tile. 35.62 + # The X component of this setting must be equal to or greater than :overshoot. 35.63 + :repeat => [1,1], # Number of times to repeat the image in the X and Y axes, respectively. 35.64 + :tile_size => [false,false], # Size of the tile(s) inches. Any nil value is calculated from 35.65 + # the size of the bitmap. 35.66 + :tile_spacing => [0.125,0.125], # X,Y gap between repeated tiles in inches 35.67 + :feed => 120, # Speed to move the X axis while burning, in inches/minute 35.68 + :cut_feed => 20, # Speed at which to cut out tiles 35.69 + :corner_radius => 0 # Radius of rounded corners for cutout, 0 for pointy corners 35.70 + } 35.71 + 35.72 + class InvalidConfig < Exception; end 35.73 + def update_config 35.74 + @scale = @config[:dpi].map{|n| 1.0/n } 35.75 + @offset = @config[:offset] 35.76 + 35.77 + if @image 35.78 + 2.times {|i| @config[:tile_size][i] ||= @image.size[i]*@scale[i] } 35.79 + @tile_interval = [] 35.80 + 2.times {|i| 35.81 + @tile_interval << @config[:tile_size][i] + @config[:tile_spacing][i] 35.82 + } 35.83 + @tile_interval 35.84 + end 35.85 + 35.86 + @on_range = Range.new Image.f_to_pix(@config[:on_range].first), 35.87 + Image.f_to_pix(@config[:on_range].last) 35.88 + end 35.89 + 35.90 + def validate_config 35.91 + raise InvalidConfig.new "X offset (#{@config[:offset][0]}) must be greater or equal to overshoot (#{@config[:overshoot]})" 35.92 + end 35.93 + 35.94 + def config= h 35.95 + @config = {} 35.96 + DEFAULTS.each {|k,v| @config[k] = h[k] || v } 35.97 + update_config 35.98 + return h 35.99 + end 35.100 + 35.101 + def merge_config h 35.102 + @config ||= DEFAULTS.dup 35.103 + h.each {|k,v| @config[k] = v if DEFAULTS[k] } 35.104 + update_config 35.105 + return h 35.106 + end 35.107 + 35.108 + attr_reader :config 35.109 + 35.110 + def image= img 35.111 + debug "image set to #{img.filename} #{img.size.inspect} #{img.pixels.size} pixels" 35.112 + @image = img 35.113 + @image.build_spans @on_range 35.114 + update_config 35.115 + build_tiled_rows 35.116 + return img 35.117 + end 35.118 + 35.119 + attr_reader :image 35.120 + 35.121 + def try_load_config_file pn 35.122 + if File.exist?(pn) 35.123 + c = {} 35.124 + YAML.load_file(pn).each {|k,v| c[k.intern] = v } 35.125 + return c 35.126 + end 35.127 + end 35.128 + 35.129 + def try_load_default_config_file 35.130 + try_load_config_file './graster.yml' 35.131 + end 35.132 + 35.133 + def load_config_file pn 35.134 + try_load_config_file pn or raise "config file not found '#{pn}'" 35.135 + end 35.136 + 35.137 + def load_image_file pn 35.138 + self.image = Image.from_file(pn) 35.139 + end 35.140 + 35.141 + # convert tile + pixel coordinates to inches 35.142 + def axis_inches axis, tile, pixel 35.143 + @offset[axis] + tile*@tile_interval[axis] + pixel*@scale[axis] 35.144 + end 35.145 + 35.146 + def x_inches tile, pixel 35.147 + axis_inches 0, tile, pixel 35.148 + end 35.149 + 35.150 + def y_inches tile, pixel 35.151 + axis_inches 1, tile, pixel 35.152 + end 35.153 + 35.154 + # return a complete tiled row of spans converted to inches 35.155 + def tiled_row_spans y, forward=true 35.156 + spans = @image.spans[y] 35.157 + return spans if spans.empty? 35.158 + tiled_spans = [] 35.159 + 35.160 + if forward 35.161 + @config[:repeat][0].times do |tile| 35.162 + spans.each do |span| 35.163 + tiled_spans << [x_inches(tile,span[0]), x_inches(tile,span[1])] 35.164 + end 35.165 + end 35.166 + else 35.167 + (0...@config[:repeat][0]).to_a.reverse.each do |tile| 35.168 + spans.reverse.each do |span| 35.169 + tiled_spans << [x_inches(tile,span[1]), x_inches(tile,span[0])] 35.170 + end 35.171 + end 35.172 + end 35.173 + 35.174 + return tiled_spans 35.175 + end 35.176 + 35.177 + def build_tiled_rows 35.178 + forward = false 35.179 + @tiled_rows = [] 35.180 + @image.size[1].times {|y| @tiled_rows << tiled_row_spans(y, (forward = !forward)) } 35.181 + end 35.182 + 35.183 + # generate a unique id for this job 35.184 + def job_hash 35.185 + [@image,@config].hash 35.186 + end 35.187 + 35.188 + # render a complete tiled image to gcode and gmask streams 35.189 + def render_tiled_image gcode, gmask 35.190 + debug "rendering tiled image" 35.191 + job_id = job_hash 35.192 + hyst = -@scale[0]/2 35.193 + gcode.comment "raster gcode for job #{job_id}" 35.194 + gcode.comment "image: #{@image.filename} #{@image.size.inspect}" 35.195 + gcode.comment "config: #{@config.inspect}" 35.196 + 35.197 + gcode.preamble :feed => @config[:feed], :mask => true 35.198 + gmask.preamble 35.199 + 35.200 + @config[:repeat][1].times do |ytile| 35.201 + debug "begin tile row #{ytile}" 35.202 + ypix = 0 35.203 + (0...@tiled_rows).each do |spans| 35.204 + debug "pixel row #{ypix} is empty" if spans.empty? 35.205 + unless spans.empty? 35.206 + yinches = y_inches(ytile, ypix) 35.207 + forward = spans[0][0] < spans[-1][1] 35.208 + dir = forward ? 1 : -1 35.209 + 35.210 + debug "pixel row #{ypix} at #{yinches} inches going #{forward ? 'forward' : 'backward'} with #{spans.size} spans" 35.211 + 35.212 + gcode.g0 :x => spans[0][0] - dir*@config[:overshoot], :y => yinches 35.213 + gcode.g1 :x => spans[-1][1] + dir*@config[:overshoot], :y => yinches 35.214 + gmask.begin_row forward 35.215 + # G0 X0.606 Y1.976 35.216 + # G1 X3.396 Y1.976 35.217 + # G0 X3.392 Y1.978 35.218 + # G1 X0.610 Y1.978 35.219 + # G0 X0.614 Y1.980 35.220 + # G1 X3.388 Y1.980 35.221 + 35.222 + spans.each {|span| gmask.span forward, span[0]+hyst, span[1]+hyst } 35.223 + end # unless spans.empty? 35.224 + ypix += 1 35.225 + end # @image.each_row 35.226 + debug "end tile row #{ytile}" 35.227 + end # @config[:repeat][i].times 35.228 + 35.229 + gcode.epilogue 35.230 + end # def render_tiled_image 35.231 + 35.232 + # cut out the tile with bottom left at x,y 35.233 + def render_cut gcode, x, y 35.234 + radius = @config[:corner_radius] 35.235 + left = x 35.236 + bottom = y 35.237 + right = x+@config[:tile_size][0] 35.238 + top = y+@config[:tile_size][1] 35.239 + 35.240 + gcode.instance_eval do 35.241 + if radius && radius > 0 35.242 + jog :x => left, :y => bottom+radius 35.243 + move :x => left, :y => top-radius, :laser => true 35.244 + turn_cw :x => left+radius, :y => top, :i => radius 35.245 + move :x => right-radius, :y => top 35.246 + turn_cw :x => right, :y => top-radius, :j => -radius 35.247 + move :x => right, :y => bottom+radius 35.248 + turn_cw :x => right-radius, :y => bottom, :i => -radius 35.249 + move :x => left+radius, :y => bottom 35.250 + turn_cw :x => left, :y => bottom+radius, :j => radius 35.251 + nc :laser => false 35.252 + else 35.253 + jog :x => left, :y => bottom 35.254 + move :x => left, :y => top, :laser => true 35.255 + move :x => right, :y => top 35.256 + move :x => right, :y => bottom 35.257 + move :x => left, :y => bottom 35.258 + nc :laser => false 35.259 + end 35.260 + end 35.261 + end 35.262 + 35.263 + # render gcode to cut out the tiles 35.264 + def render_all_cuts gcode 35.265 + gcode.preamble :feed => @config[:cut_feed] 35.266 + @config[:repeat][1].times do |ytile| 35.267 + @config[:repeat][0].times do |xtile| 35.268 + render_cut gcode, x_inches(xtile, 0), y_inches(ytile, 0) 35.269 + end 35.270 + end 35.271 + gcode.epilogue 35.272 + end 35.273 + 35.274 + def render_all gcode, gmask, cuts 35.275 + render_tiled_image gcode, gmask 35.276 + render_all_cuts cuts 35.277 + end 35.278 + 35.279 + def open_gcode_file &block 35.280 + io = GcodeFile.open "#{@image.filename}.raster.ngc", "w", &block 35.281 + end 35.282 + 35.283 + def open_gmask_file &block 35.284 + io = GmaskFile.open "#{@image.filename}.raster.gmask", "w", &block 35.285 + end 35.286 + 35.287 + def open_cut_file &block 35.288 + io = GcodeFile.open "#{@image.filename}.cut.ngc", "w", &block 35.289 + end 35.290 + 35.291 + def generate_all_files 35.292 + open_gcode_file do |gcode| 35.293 + open_gmask_file do |gmask| 35.294 + render_tiled_image gcode, gmask 35.295 + end 35.296 + end 35.297 + 35.298 + open_cut_file do |cut| 35.299 + render_all_cuts cut 35.300 + end 35.301 + end 35.302 + 35.303 + def config_to_yaml 35.304 + @config.map {|k,v| "#{k}: #{v.inspect}\n" }.join 35.305 + end 35.306 + 35.307 + def debug msg 35.308 + STDERR.puts msg if @debug 35.309 + end 35.310 + 35.311 + def initialize opts={} 35.312 + self.config = DEFAULTS.dup 35.313 + 35.314 + if opts[:config_file] 35.315 + self.merge_config load_config_file opts[:config_file] 35.316 + elsif opts[:default_config_file] && c = try_load_default_config_file 35.317 + self.merge_config c 35.318 + end 35.319 + 35.320 + self.merge_config opts[:config] if opts[:config] 35.321 + 35.322 + @debug = opts[:debug] 35.323 + 35.324 + if opts[:image] 35.325 + image = opts[:image] 35.326 + elsif opts[:image_file] 35.327 + load_image_file opts[:image_file] 35.328 + end 35.329 + end 35.330 + 35.331 +end # class Graster
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/graster/graster/lib/graster/.#gmask_file.rb Tue Aug 24 19:06:45 2010 -0400 36.3 @@ -0,0 +1,1 @@ 36.4 +r@RLM.2766:1282362081 36.5 \ No newline at end of file
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/graster/graster/lib/graster/gcode_file.rb Tue Aug 24 19:06:45 2010 -0400 37.3 @@ -0,0 +1,71 @@ 37.4 +class Graster 37.5 + class GcodeFile < File 37.6 + def preamble opts 37.7 + @laser = false 37.8 + self << "M63 P0\nG61\nF#{opts[:feed] || 60}\n" 37.9 + self << "M101\n" if opts[:mask] 37.10 + self << "M3 S1\n" 37.11 + end 37.12 + 37.13 + def epilogue 37.14 + self << "M63 P0\nM5\nM2\n" 37.15 + end 37.16 + 37.17 + PRIORITY = [:g,:x,:y,:z,:w,:i,:j,:k,:m,:p,:s] 37.18 + 37.19 + def nc codes 37.20 + codes = codes.dup 37.21 + 37.22 + if codes[:laser] == true && !@laser 37.23 + @laser = true 37.24 + codes.merge!(:m => 62, :p => 0) 37.25 + elsif codes[:laser] == false && @laser 37.26 + @laser = false 37.27 + codes.merge!(:m => 63, :p => 0) 37.28 + end 37.29 + 37.30 + codes.delete :laser 37.31 + 37.32 + self << codes.sort {|(k1,v1),(k2,v2)| 37.33 + PRIORITY.index(k1) <=> PRIORITY.index(k2) 37.34 + }.map {|k,v| 37.35 + if v.is_a? Integer 37.36 + "#{k.to_s.upcase}#{v}" 37.37 + elsif v.is_a? Float 37.38 + "#{k.to_s.upcase}%0.3f" % v 37.39 + else 37.40 + k.to_s.upcase 37.41 + end 37.42 + }.join(' ') + "\n" 37.43 + end 37.44 + 37.45 + def g0 codes 37.46 + nc({:g => 0}.merge codes) 37.47 + end 37.48 + alias_method :jog, :g0 37.49 + 37.50 + def g1 codes 37.51 + nc({:g => 1}.merge codes) 37.52 + end 37.53 + alias_method :move, :g1 37.54 + 37.55 + def g2 codes 37.56 + nc codes.merge(:g => 2) 37.57 + end 37.58 + alias_method :turn_cw, :g2 37.59 + 37.60 + def g3 codes 37.61 + nc codes.merge(:g => 3) 37.62 + end 37.63 + alias_method :turn_ccw, :g3 37.64 + 37.65 + def comment txt 37.66 + txt = txt.gsub(/\(\)/,'') 37.67 + self << "(#{txt})\n" 37.68 + end 37.69 + 37.70 + def puts *a 37.71 + self.puts *a 37.72 + end 37.73 + end 37.74 +end
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/graster/graster/lib/graster/gmask_file.rb Tue Aug 24 19:06:45 2010 -0400 38.3 @@ -0,0 +1,24 @@ 38.4 +class Graster 38.5 + class GmaskFile < File 38.6 + def preamble 38.7 + self << "1 0 0 0\n" 38.8 + end 38.9 + 38.10 + def begin_row forward 38.11 + @begin_row = true 38.12 + end 38.13 + 38.14 + def span forward, x1, x2 38.15 + if forward 38.16 + self << "0 0 0 %0.3f\n" % x1 if @begin_row 38.17 + self << "0 0 1 %0.3f\n" % x1 38.18 + self << "0 1 1 %0.3f\n" % x2 38.19 + else 38.20 + self << "0 0 1 %0.3f\n" % x1 if @begin_row 38.21 + self << "0 0 0 %0.3f\n" % x1 38.22 + self << "0 1 0 %0.3f\n" % x2 38.23 + end 38.24 + @begin_row = false 38.25 + end 38.26 + end 38.27 +end 38.28 \ No newline at end of file
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/graster/graster/lib/graster/image.rb Tue Aug 24 19:06:45 2010 -0400 39.3 @@ -0,0 +1,83 @@ 39.4 +class Graster 39.5 + class Image 39.6 + PROPS = [:filename,:size,:pixels] 39.7 + 39.8 + def initialize(props) 39.9 + PROPS.each do |p| 39.10 + raise "required image property :#{p} missing" unless props[p] 39.11 + instance_variable_set "@#{p}", props[p] 39.12 + end 39.13 + end 39.14 + 39.15 + PROPS.each{|p| attr_reader p } 39.16 + 39.17 + def self.from_file pathname 39.18 + raise "file not found #{pathname}" unless File.exist? pathname 39.19 + img = Magick::Image.read(pathname) 39.20 + raise "bad image data in #{pathname}" unless img = img[0] 39.21 + new :filename => File.basename(pathname), 39.22 + :size => [img.columns,img.rows], 39.23 + :pixels => img.export_pixels(0,0,img.columns,img.rows,"I") 39.24 + end 39.25 + 39.26 + # get pixel(s) from x,y coords 39.27 + # 0,0 is bottom,left 39.28 + # image[x,y] => pixel at x,y 39.29 + # image[y] => row at y 39.30 + def [] y, x=nil 39.31 + if x 39.32 + @pixels[(@size[1]-y)*@size[0]+x] 39.33 + else 39.34 + @pixels[(@size[1]-y)*@size[0],@size[0]] 39.35 + end 39.36 + end 39.37 + 39.38 + def each_row &block 39.39 + @pixels.chars.each_slice(@size[0]).each_with_index &block 39.40 + end 39.41 + 39.42 + # "encode" a float 0..1 to a pixel 39.43 + def self.f_to_pix f 39.44 + (f*65535).round 39.45 + end 39.46 + 39.47 + # "decode" an encoded pixel to a float 0..1 39.48 + def self.pix_to_f pix 39.49 + pix/65535.0 39.50 + end 39.51 + 39.52 + 39.53 + # convert bitmap data to spans (or runs) of contiguous pixels 39.54 + # also invert the Y axis 39.55 + def build_spans on_range 39.56 + # TODO: rewrite in terms of each_row 39.57 + @spans = Array.new @size[1] 39.58 + 39.59 + @size[1].times do |y| 39.60 + spans = [] 39.61 + left = (@size[1]-y-1)*@size[0] 39.62 + start = nil 39.63 + 39.64 + @size[0].times do |x| 39.65 + d = on_range.include?(@pixels[left+x]) 39.66 + 39.67 + if !start && d 39.68 + start = x 39.69 + elsif start && !d 39.70 + spans << [start, x] 39.71 + start = nil 39.72 + end 39.73 + end 39.74 + 39.75 + spans << [start, @size[0]] if start 39.76 + @spans[y] = spans 39.77 + end 39.78 + end 39.79 + 39.80 + attr_reader :spans 39.81 + 39.82 + def hash 39.83 + [@pixels,@width,@height].hash 39.84 + end 39.85 + end 39.86 +end 39.87 \ No newline at end of file
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/graster/graster/lib/graster/runner.rb Tue Aug 24 19:06:45 2010 -0400 40.3 @@ -0,0 +1,66 @@ 40.4 +require 'optparse' 40.5 + 40.6 +class Graster 40.7 + class Runner 40.8 + 40.9 + attr_reader :options, :args, :opts 40.10 + 40.11 + def initialize(args) 40.12 + @args = args 40.13 + @options = { :default_config_file => true } 40.14 + @opts = OptionParser.new do |opts| 40.15 + opts.banner = "Usage: graster [options] image" 40.16 + 40.17 + opts.on "-c", "--config FILE", "Use specified configuration file.", 40.18 + "The default is ./graster.yml" do |c| 40.19 + @options[:config_file] = c 40.20 + end 40.21 + 40.22 + opts.on "-g", "--generate", "generate a configuration file with","defaults" do 40.23 + @options[:generate_config] = true 40.24 + end 40.25 + 40.26 + opts.on "-d", "--debug", "Dump useless debug info" do 40.27 + @options[:debug] = true 40.28 + end 40.29 + 40.30 + Graster::OPTIONS.each do |key,info| 40.31 + type,sym,*desc = info 40.32 + 40.33 + if type.is_a? Array 40.34 + cast = type[0].name.intern 40.35 + type = Array 40.36 + else 40.37 + cast = type.name.intern 40.38 + end 40.39 + 40.40 + opts.on "--#{key.to_s.gsub /_/, '-'} #{sym}", type, *desc do |x| 40.41 + @options[:config] ||= {} 40.42 + if type == Array 40.43 + x = x.map {|s| Kernel.send(cast,s) } 40.44 + else 40.45 + x = Kernel.send(cast,x) 40.46 + end 40.47 + 40.48 + @options[:config][key] = x 40.49 + end 40.50 + end 40.51 + end 40.52 + 40.53 + @opts.parse!(args) 40.54 + end 40.55 + 40.56 + def start! 40.57 + if @options[:generate_config] 40.58 + print Graster.new(@options).config_to_yaml 40.59 + else 40.60 + unless options[:image_file] = args.shift 40.61 + puts @opts 40.62 + exit 1 40.63 + end 40.64 + 40.65 + Graster.new(options).generate_all_files 40.66 + end 40.67 + end 40.68 + end 40.69 +end 40.70 \ No newline at end of file
41.1 Binary file graster/graster/rmagick-2.13.1.gem has changed
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/graster/graster/tile.rb Tue Aug 24 19:06:45 2010 -0400 42.3 @@ -0,0 +1,2 @@ 42.4 +#!/usr/bin/ruby 42.5 +
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/graster/hacklab-engraver/.git/HEAD Tue Aug 24 19:06:45 2010 -0400 43.3 @@ -0,0 +1,1 @@ 43.4 +ref: refs/heads/master
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/graster/hacklab-engraver/.git/config Tue Aug 24 19:06:45 2010 -0400 44.3 @@ -0,0 +1,11 @@ 44.4 +[core] 44.5 + repositoryformatversion = 0 44.6 + filemode = true 44.7 + bare = false 44.8 + logallrefupdates = true 44.9 +[remote "origin"] 44.10 + fetch = +refs/heads/*:refs/remotes/origin/* 44.11 + url = http://github.com/jedediah/hacklab-engraver.git 44.12 +[branch "master"] 44.13 + remote = origin 44.14 + merge = refs/heads/master
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/graster/hacklab-engraver/.git/description Tue Aug 24 19:06:45 2010 -0400 45.3 @@ -0,0 +1,1 @@ 45.4 +Unnamed repository; edit this file 'description' to name the repository.
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/graster/hacklab-engraver/.git/hooks/applypatch-msg.sample Tue Aug 24 19:06:45 2010 -0400 46.3 @@ -0,0 +1,15 @@ 46.4 +#!/bin/sh 46.5 +# 46.6 +# An example hook script to check the commit log message taken by 46.7 +# applypatch from an e-mail message. 46.8 +# 46.9 +# The hook should exit with non-zero status after issuing an 46.10 +# appropriate message if it wants to stop the commit. The hook is 46.11 +# allowed to edit the commit message file. 46.12 +# 46.13 +# To enable this hook, rename this file to "applypatch-msg". 46.14 + 46.15 +. git-sh-setup 46.16 +test -x "$GIT_DIR/hooks/commit-msg" && 46.17 + exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"} 46.18 +:
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/graster/hacklab-engraver/.git/hooks/commit-msg.sample Tue Aug 24 19:06:45 2010 -0400 47.3 @@ -0,0 +1,24 @@ 47.4 +#!/bin/sh 47.5 +# 47.6 +# An example hook script to check the commit log message. 47.7 +# Called by git-commit with one argument, the name of the file 47.8 +# that has the commit message. The hook should exit with non-zero 47.9 +# status after issuing an appropriate message if it wants to stop the 47.10 +# commit. The hook is allowed to edit the commit message file. 47.11 +# 47.12 +# To enable this hook, rename this file to "commit-msg". 47.13 + 47.14 +# Uncomment the below to add a Signed-off-by line to the message. 47.15 +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg 47.16 +# hook is more suited to it. 47.17 +# 47.18 +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') 47.19 +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" 47.20 + 47.21 +# This example catches duplicate Signed-off-by lines. 47.22 + 47.23 +test "" = "$(grep '^Signed-off-by: ' "$1" | 47.24 + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { 47.25 + echo >&2 Duplicate Signed-off-by lines. 47.26 + exit 1 47.27 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/graster/hacklab-engraver/.git/hooks/post-commit.sample Tue Aug 24 19:06:45 2010 -0400 48.3 @@ -0,0 +1,8 @@ 48.4 +#!/bin/sh 48.5 +# 48.6 +# An example hook script that is called after a successful 48.7 +# commit is made. 48.8 +# 48.9 +# To enable this hook, rename this file to "post-commit". 48.10 + 48.11 +: Nothing
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/graster/hacklab-engraver/.git/hooks/post-receive.sample Tue Aug 24 19:06:45 2010 -0400 49.3 @@ -0,0 +1,15 @@ 49.4 +#!/bin/sh 49.5 +# 49.6 +# An example hook script for the "post-receive" event. 49.7 +# 49.8 +# The "post-receive" script is run after receive-pack has accepted a pack 49.9 +# and the repository has been updated. It is passed arguments in through 49.10 +# stdin in the form 49.11 +# <oldrev> <newrev> <refname> 49.12 +# For example: 49.13 +# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master 49.14 +# 49.15 +# see contrib/hooks/ for a sample, or uncomment the next line and 49.16 +# rename the file to "post-receive". 49.17 + 49.18 +#. /usr/share/doc/git-core/contrib/hooks/post-receive-email
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/graster/hacklab-engraver/.git/hooks/post-update.sample Tue Aug 24 19:06:45 2010 -0400 50.3 @@ -0,0 +1,8 @@ 50.4 +#!/bin/sh 50.5 +# 50.6 +# An example hook script to prepare a packed repository for use over 50.7 +# dumb transports. 50.8 +# 50.9 +# To enable this hook, rename this file to "post-update". 50.10 + 50.11 +exec git-update-server-info
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/graster/hacklab-engraver/.git/hooks/pre-applypatch.sample Tue Aug 24 19:06:45 2010 -0400 51.3 @@ -0,0 +1,14 @@ 51.4 +#!/bin/sh 51.5 +# 51.6 +# An example hook script to verify what is about to be committed 51.7 +# by applypatch from an e-mail message. 51.8 +# 51.9 +# The hook should exit with non-zero status after issuing an 51.10 +# appropriate message if it wants to stop the commit. 51.11 +# 51.12 +# To enable this hook, rename this file to "pre-applypatch". 51.13 + 51.14 +. git-sh-setup 51.15 +test -x "$GIT_DIR/hooks/pre-commit" && 51.16 + exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} 51.17 +:
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/graster/hacklab-engraver/.git/hooks/pre-commit.sample Tue Aug 24 19:06:45 2010 -0400 52.3 @@ -0,0 +1,46 @@ 52.4 +#!/bin/sh 52.5 +# 52.6 +# An example hook script to verify what is about to be committed. 52.7 +# Called by git-commit with no arguments. The hook should 52.8 +# exit with non-zero status after issuing an appropriate message if 52.9 +# it wants to stop the commit. 52.10 +# 52.11 +# To enable this hook, rename this file to "pre-commit". 52.12 + 52.13 +if git-rev-parse --verify HEAD >/dev/null 2>&1 52.14 +then 52.15 + against=HEAD 52.16 +else 52.17 + # Initial commit: diff against an empty tree object 52.18 + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 52.19 +fi 52.20 + 52.21 +# If you want to allow non-ascii filenames set this variable to true. 52.22 +allownonascii=$(git config hooks.allownonascii) 52.23 + 52.24 +# Cross platform projects tend to avoid non-ascii filenames; prevent 52.25 +# them from being added to the repository. We exploit the fact that the 52.26 +# printable range starts at the space character and ends with tilde. 52.27 +if [ "$allownonascii" != "true" ] && 52.28 + # Note that the use of brackets around a tr range is ok here, (it's 52.29 + # even required, for portability to Solaris 10's /usr/bin/tr), since 52.30 + # the square bracket bytes happen to fall in the designated range. 52.31 + test "$(git diff --cached --name-only --diff-filter=A -z $against | 52.32 + LC_ALL=C tr -d '[ -~]\0')" 52.33 +then 52.34 + echo "Error: Attempt to add a non-ascii file name." 52.35 + echo 52.36 + echo "This can cause problems if you want to work" 52.37 + echo "with people on other platforms." 52.38 + echo 52.39 + echo "To be portable it is advisable to rename the file ..." 52.40 + echo 52.41 + echo "If you know what you are doing you can disable this" 52.42 + echo "check using:" 52.43 + echo 52.44 + echo " git config hooks.allownonascii true" 52.45 + echo 52.46 + exit 1 52.47 +fi 52.48 + 52.49 +exec git diff-index --check --cached $against --
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/graster/hacklab-engraver/.git/hooks/pre-rebase.sample Tue Aug 24 19:06:45 2010 -0400 53.3 @@ -0,0 +1,169 @@ 53.4 +#!/bin/sh 53.5 +# 53.6 +# Copyright (c) 2006, 2008 Junio C Hamano 53.7 +# 53.8 +# The "pre-rebase" hook is run just before "git-rebase" starts doing 53.9 +# its job, and can prevent the command from running by exiting with 53.10 +# non-zero status. 53.11 +# 53.12 +# The hook is called with the following parameters: 53.13 +# 53.14 +# $1 -- the upstream the series was forked from. 53.15 +# $2 -- the branch being rebased (or empty when rebasing the current branch). 53.16 +# 53.17 +# This sample shows how to prevent topic branches that are already 53.18 +# merged to 'next' branch from getting rebased, because allowing it 53.19 +# would result in rebasing already published history. 53.20 + 53.21 +publish=next 53.22 +basebranch="$1" 53.23 +if test "$#" = 2 53.24 +then 53.25 + topic="refs/heads/$2" 53.26 +else 53.27 + topic=`git symbolic-ref HEAD` || 53.28 + exit 0 ;# we do not interrupt rebasing detached HEAD 53.29 +fi 53.30 + 53.31 +case "$topic" in 53.32 +refs/heads/??/*) 53.33 + ;; 53.34 +*) 53.35 + exit 0 ;# we do not interrupt others. 53.36 + ;; 53.37 +esac 53.38 + 53.39 +# Now we are dealing with a topic branch being rebased 53.40 +# on top of master. Is it OK to rebase it? 53.41 + 53.42 +# Does the topic really exist? 53.43 +git show-ref -q "$topic" || { 53.44 + echo >&2 "No such branch $topic" 53.45 + exit 1 53.46 +} 53.47 + 53.48 +# Is topic fully merged to master? 53.49 +not_in_master=`git-rev-list --pretty=oneline ^master "$topic"` 53.50 +if test -z "$not_in_master" 53.51 +then 53.52 + echo >&2 "$topic is fully merged to master; better remove it." 53.53 + exit 1 ;# we could allow it, but there is no point. 53.54 +fi 53.55 + 53.56 +# Is topic ever merged to next? If so you should not be rebasing it. 53.57 +only_next_1=`git-rev-list ^master "^$topic" ${publish} | sort` 53.58 +only_next_2=`git-rev-list ^master ${publish} | sort` 53.59 +if test "$only_next_1" = "$only_next_2" 53.60 +then 53.61 + not_in_topic=`git-rev-list "^$topic" master` 53.62 + if test -z "$not_in_topic" 53.63 + then 53.64 + echo >&2 "$topic is already up-to-date with master" 53.65 + exit 1 ;# we could allow it, but there is no point. 53.66 + else 53.67 + exit 0 53.68 + fi 53.69 +else 53.70 + not_in_next=`git-rev-list --pretty=oneline ^${publish} "$topic"` 53.71 + perl -e ' 53.72 + my $topic = $ARGV[0]; 53.73 + my $msg = "* $topic has commits already merged to public branch:\n"; 53.74 + my (%not_in_next) = map { 53.75 + /^([0-9a-f]+) /; 53.76 + ($1 => 1); 53.77 + } split(/\n/, $ARGV[1]); 53.78 + for my $elem (map { 53.79 + /^([0-9a-f]+) (.*)$/; 53.80 + [$1 => $2]; 53.81 + } split(/\n/, $ARGV[2])) { 53.82 + if (!exists $not_in_next{$elem->[0]}) { 53.83 + if ($msg) { 53.84 + print STDERR $msg; 53.85 + undef $msg; 53.86 + } 53.87 + print STDERR " $elem->[1]\n"; 53.88 + } 53.89 + } 53.90 + ' "$topic" "$not_in_next" "$not_in_master" 53.91 + exit 1 53.92 +fi 53.93 + 53.94 +exit 0 53.95 + 53.96 +################################################################ 53.97 + 53.98 +This sample hook safeguards topic branches that have been 53.99 +published from being rewound. 53.100 + 53.101 +The workflow assumed here is: 53.102 + 53.103 + * Once a topic branch forks from "master", "master" is never 53.104 + merged into it again (either directly or indirectly). 53.105 + 53.106 + * Once a topic branch is fully cooked and merged into "master", 53.107 + it is deleted. If you need to build on top of it to correct 53.108 + earlier mistakes, a new topic branch is created by forking at 53.109 + the tip of the "master". This is not strictly necessary, but 53.110 + it makes it easier to keep your history simple. 53.111 + 53.112 + * Whenever you need to test or publish your changes to topic 53.113 + branches, merge them into "next" branch. 53.114 + 53.115 +The script, being an example, hardcodes the publish branch name 53.116 +to be "next", but it is trivial to make it configurable via 53.117 +$GIT_DIR/config mechanism. 53.118 + 53.119 +With this workflow, you would want to know: 53.120 + 53.121 +(1) ... if a topic branch has ever been merged to "next". Young 53.122 + topic branches can have stupid mistakes you would rather 53.123 + clean up before publishing, and things that have not been 53.124 + merged into other branches can be easily rebased without 53.125 + affecting other people. But once it is published, you would 53.126 + not want to rewind it. 53.127 + 53.128 +(2) ... if a topic branch has been fully merged to "master". 53.129 + Then you can delete it. More importantly, you should not 53.130 + build on top of it -- other people may already want to 53.131 + change things related to the topic as patches against your 53.132 + "master", so if you need further changes, it is better to 53.133 + fork the topic (perhaps with the same name) afresh from the 53.134 + tip of "master". 53.135 + 53.136 +Let's look at this example: 53.137 + 53.138 + o---o---o---o---o---o---o---o---o---o "next" 53.139 + / / / / 53.140 + / a---a---b A / / 53.141 + / / / / 53.142 + / / c---c---c---c B / 53.143 + / / / \ / 53.144 + / / / b---b C \ / 53.145 + / / / / \ / 53.146 + ---o---o---o---o---o---o---o---o---o---o---o "master" 53.147 + 53.148 + 53.149 +A, B and C are topic branches. 53.150 + 53.151 + * A has one fix since it was merged up to "next". 53.152 + 53.153 + * B has finished. It has been fully merged up to "master" and "next", 53.154 + and is ready to be deleted. 53.155 + 53.156 + * C has not merged to "next" at all. 53.157 + 53.158 +We would want to allow C to be rebased, refuse A, and encourage 53.159 +B to be deleted. 53.160 + 53.161 +To compute (1): 53.162 + 53.163 + git-rev-list ^master ^topic next 53.164 + git-rev-list ^master next 53.165 + 53.166 + if these match, topic has not merged in next at all. 53.167 + 53.168 +To compute (2): 53.169 + 53.170 + git-rev-list master..topic 53.171 + 53.172 + if this is empty, it is fully merged to "master".
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/graster/hacklab-engraver/.git/hooks/prepare-commit-msg.sample Tue Aug 24 19:06:45 2010 -0400 54.3 @@ -0,0 +1,36 @@ 54.4 +#!/bin/sh 54.5 +# 54.6 +# An example hook script to prepare the commit log message. 54.7 +# Called by git-commit with the name of the file that has the 54.8 +# commit message, followed by the description of the commit 54.9 +# message's source. The hook's purpose is to edit the commit 54.10 +# message file. If the hook fails with a non-zero status, 54.11 +# the commit is aborted. 54.12 +# 54.13 +# To enable this hook, rename this file to "prepare-commit-msg". 54.14 + 54.15 +# This hook includes three examples. The first comments out the 54.16 +# "Conflicts:" part of a merge commit. 54.17 +# 54.18 +# The second includes the output of "git diff --name-status -r" 54.19 +# into the message, just before the "git status" output. It is 54.20 +# commented because it doesn't cope with --amend or with squashed 54.21 +# commits. 54.22 +# 54.23 +# The third example adds a Signed-off-by line to the message, that can 54.24 +# still be edited. This is rarely a good idea. 54.25 + 54.26 +case "$2,$3" in 54.27 + merge,) 54.28 + perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; 54.29 + 54.30 +# ,|template,) 54.31 +# perl -i.bak -pe ' 54.32 +# print "\n" . `git diff --cached --name-status -r` 54.33 +# if /^#/ && $first++ == 0' "$1" ;; 54.34 + 54.35 + *) ;; 54.36 +esac 54.37 + 54.38 +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') 54.39 +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/graster/hacklab-engraver/.git/hooks/update.sample Tue Aug 24 19:06:45 2010 -0400 55.3 @@ -0,0 +1,128 @@ 55.4 +#!/bin/sh 55.5 +# 55.6 +# An example hook script to blocks unannotated tags from entering. 55.7 +# Called by git-receive-pack with arguments: refname sha1-old sha1-new 55.8 +# 55.9 +# To enable this hook, rename this file to "update". 55.10 +# 55.11 +# Config 55.12 +# ------ 55.13 +# hooks.allowunannotated 55.14 +# This boolean sets whether unannotated tags will be allowed into the 55.15 +# repository. By default they won't be. 55.16 +# hooks.allowdeletetag 55.17 +# This boolean sets whether deleting tags will be allowed in the 55.18 +# repository. By default they won't be. 55.19 +# hooks.allowmodifytag 55.20 +# This boolean sets whether a tag may be modified after creation. By default 55.21 +# it won't be. 55.22 +# hooks.allowdeletebranch 55.23 +# This boolean sets whether deleting branches will be allowed in the 55.24 +# repository. By default they won't be. 55.25 +# hooks.denycreatebranch 55.26 +# This boolean sets whether remotely creating branches will be denied 55.27 +# in the repository. By default this is allowed. 55.28 +# 55.29 + 55.30 +# --- Command line 55.31 +refname="$1" 55.32 +oldrev="$2" 55.33 +newrev="$3" 55.34 + 55.35 +# --- Safety check 55.36 +if [ -z "$GIT_DIR" ]; then 55.37 + echo "Don't run this script from the command line." >&2 55.38 + echo " (if you want, you could supply GIT_DIR then run" >&2 55.39 + echo " $0 <ref> <oldrev> <newrev>)" >&2 55.40 + exit 1 55.41 +fi 55.42 + 55.43 +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then 55.44 + echo "Usage: $0 <ref> <oldrev> <newrev>" >&2 55.45 + exit 1 55.46 +fi 55.47 + 55.48 +# --- Config 55.49 +allowunannotated=$(git config --bool hooks.allowunannotated) 55.50 +allowdeletebranch=$(git config --bool hooks.allowdeletebranch) 55.51 +denycreatebranch=$(git config --bool hooks.denycreatebranch) 55.52 +allowdeletetag=$(git config --bool hooks.allowdeletetag) 55.53 +allowmodifytag=$(git config --bool hooks.allowmodifytag) 55.54 + 55.55 +# check for no description 55.56 +projectdesc=$(sed -e '1q' "$GIT_DIR/description") 55.57 +case "$projectdesc" in 55.58 +"Unnamed repository"* | "") 55.59 + echo "*** Project description file hasn't been set" >&2 55.60 + exit 1 55.61 + ;; 55.62 +esac 55.63 + 55.64 +# --- Check types 55.65 +# if $newrev is 0000...0000, it's a commit to delete a ref. 55.66 +zero="0000000000000000000000000000000000000000" 55.67 +if [ "$newrev" = "$zero" ]; then 55.68 + newrev_type=delete 55.69 +else 55.70 + newrev_type=$(git-cat-file -t $newrev) 55.71 +fi 55.72 + 55.73 +case "$refname","$newrev_type" in 55.74 + refs/tags/*,commit) 55.75 + # un-annotated tag 55.76 + short_refname=${refname##refs/tags/} 55.77 + if [ "$allowunannotated" != "true" ]; then 55.78 + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 55.79 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 55.80 + exit 1 55.81 + fi 55.82 + ;; 55.83 + refs/tags/*,delete) 55.84 + # delete tag 55.85 + if [ "$allowdeletetag" != "true" ]; then 55.86 + echo "*** Deleting a tag is not allowed in this repository" >&2 55.87 + exit 1 55.88 + fi 55.89 + ;; 55.90 + refs/tags/*,tag) 55.91 + # annotated tag 55.92 + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 55.93 + then 55.94 + echo "*** Tag '$refname' already exists." >&2 55.95 + echo "*** Modifying a tag is not allowed in this repository." >&2 55.96 + exit 1 55.97 + fi 55.98 + ;; 55.99 + refs/heads/*,commit) 55.100 + # branch 55.101 + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then 55.102 + echo "*** Creating a branch is not allowed in this repository" >&2 55.103 + exit 1 55.104 + fi 55.105 + ;; 55.106 + refs/heads/*,delete) 55.107 + # delete branch 55.108 + if [ "$allowdeletebranch" != "true" ]; then 55.109 + echo "*** Deleting a branch is not allowed in this repository" >&2 55.110 + exit 1 55.111 + fi 55.112 + ;; 55.113 + refs/remotes/*,commit) 55.114 + # tracking branch 55.115 + ;; 55.116 + refs/remotes/*,delete) 55.117 + # delete tracking branch 55.118 + if [ "$allowdeletebranch" != "true" ]; then 55.119 + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 55.120 + exit 1 55.121 + fi 55.122 + ;; 55.123 + *) 55.124 + # Anything else (is there anything else?) 55.125 + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 55.126 + exit 1 55.127 + ;; 55.128 +esac 55.129 + 55.130 +# --- Finished 55.131 +exit 0
56.1 Binary file graster/hacklab-engraver/.git/index has changed
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 57.2 +++ b/graster/hacklab-engraver/.git/info/exclude Tue Aug 24 19:06:45 2010 -0400 57.3 @@ -0,0 +1,6 @@ 57.4 +# git-ls-files --others --exclude-from=.git/info/exclude 57.5 +# Lines that start with '#' are comments. 57.6 +# For a project mostly in C, the following would be a good set of 57.7 +# exclude patterns (uncomment them if you want to use them): 57.8 +# *.[oa] 57.9 +# *~
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 58.2 +++ b/graster/hacklab-engraver/.git/logs/HEAD Tue Aug 24 19:06:45 2010 -0400 58.3 @@ -0,0 +1,1 @@ 58.4 +0000000000000000000000000000000000000000 4a654eac48d62e718b71c65eabd923b916ff7acb Robert McIntyre <r@RLM.(none)> 1282265224 -0400 clone: from http://github.com/jedediah/hacklab-engraver.git
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 59.2 +++ b/graster/hacklab-engraver/.git/logs/refs/heads/master Tue Aug 24 19:06:45 2010 -0400 59.3 @@ -0,0 +1,1 @@ 59.4 +0000000000000000000000000000000000000000 4a654eac48d62e718b71c65eabd923b916ff7acb Robert McIntyre <r@RLM.(none)> 1282265224 -0400 clone: from http://github.com/jedediah/hacklab-engraver.git
60.1 Binary file graster/hacklab-engraver/.git/objects/00/e8b290d784d38f4cd0495586799e98fea4f45f has changed
61.1 Binary file graster/hacklab-engraver/.git/objects/02/c08b67e102c8ccddc18c609ec20f71a0468312 has changed
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 62.2 +++ b/graster/hacklab-engraver/.git/objects/07/05d4debff7c18448ab48687ff7a997b6c8d0d0 Tue Aug 24 19:06:45 2010 -0400 62.3 @@ -0,0 +1,1 @@ 62.4 +xÎAnà @Ñ®9Å,ÓEªaÀÁHU•u·9Á02IŒ-‡¨êíkå=À×û²Ìsí@nxë›*¸¨~ÄèƒåTŠÙF¢”eÌÖ{Df6+oÚ:„Q¤x[ÄJÀQ#–P\¢†‘}H2¤xb¢“ágŸ– 62.5 ¾5k®<Áeg'ø¼j>ÿÔvûý8´¥éûXÚ‹ŽŽ¸sF^‹]ÿ›Új¯|‡™7x<×uÙºùn]JN 62.6 \ No newline at end of file
63.1 Binary file graster/hacklab-engraver/.git/objects/0d/302940f5c0a80d8a7b8aaafc1fe3c9107e552d has changed
64.1 Binary file graster/hacklab-engraver/.git/objects/0e/25a9d0927364ec790df38694f6ea69cea9b258 has changed
65.1 Binary file graster/hacklab-engraver/.git/objects/11/0bc5a919d55e758d621465e69162d0a2e3de5b has changed
66.1 Binary file graster/hacklab-engraver/.git/objects/11/67088b7086fdd400154e86e0c76e02af95671b has changed
67.1 Binary file graster/hacklab-engraver/.git/objects/12/8ad1461fb3754cf6702d55f8e050b4036f8af8 has changed
68.1 Binary file graster/hacklab-engraver/.git/objects/17/44d6833bb0fa3a15e249a4faad29fab8f3bd80 has changed
69.1 Binary file graster/hacklab-engraver/.git/objects/20/ca6409cbd455fcbae06ffd177553857e43adcb has changed
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 70.2 +++ b/graster/hacklab-engraver/.git/objects/21/7eaf716ea5a987d79407eaac7dc853b279c3d5 Tue Aug 24 19:06:45 2010 -0400 70.3 @@ -0,0 +1,1 @@ 70.4 +xUÔ1n1Ñ´ëS䆸G+Ë×qm ÷ï²HsܱR~Ø×ûçõ]g_g:Æ}üýn×MhššNMKÓCÓÖôìÓV}«¾UߪoÕ·ê[õúîõT¯§z=Õë©^Oõzª×S½žêõ”êGý¿|¢]’£¸³ŸçsÞÎDËDËDËDËDËDËDËLå§žbª>UŸªOÕ§êSõ©ºF³T_ª/Õ—êKõ¥úR]#„Âa„0B!ŒFýåýåývF¿ÑogôÛývF¿ÑoGì¸Ø}>HR‡Ô!uHR‡Ô!uHR‡Ô!uHR‡Ô!uHR‡Ô!uHR‡Ô!uHR‡Ô!uHR‡Ô!uHÝõ-ùü·¿7á™ 70.5 \ No newline at end of file
71.1 Binary file graster/hacklab-engraver/.git/objects/25/1c450dde1eeab662d00967bb41f13a12ceadc3 has changed
72.1 Binary file graster/hacklab-engraver/.git/objects/27/2b76446d8d70feddc23fe033994eae0ae54be7 has changed
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 73.2 +++ b/graster/hacklab-engraver/.git/objects/2b/2693d5073f492ac90963f33a8452a31bbcf6bb Tue Aug 24 19:06:45 2010 -0400 73.3 @@ -0,0 +1,3 @@ 73.4 +xUÑnÚ0Ý3_q¥¾lR©(ÓZiB+Bj%RPAÚsÕ‰™í v_?;¶x8RüP×N|Îñ=ç†5¡k£ðKï^©ÀGÀ,á)±CÈb.Á–2ˆ ×hÉ.Îs$üâ|£^b(£9!q¶)ã.b&îzrë©Øn‘qEgµ±úÜ—»ÏTž<<ý[îçXˆ±ÜÿJÉæ›œ×%Þ 73.5 Dè÷ûŠaE÷}‚$æ™”OaMzOêFšeJíÙX>GÓH® Mb²;ñþêµÀ¼kçЬÃïA«Éâç(Fð±ašd)bQpóšž\$a0¸WÀÜÎ%³Ü×$ƒ’)cÒ‹Êp‘¸n24§5ɰB 73.6 +,°,è9B,Uæ«,¼Ì!¡¹`”d·ª¸/sysA)™d•ÚJ—(usÅoolçrSîkQ÷Q†d)ªÅu“¸n>RÌrh’Q•D†hÁh‚œc=¨:Àú´úë 73.7 +ì|¯5rddci†´¦ÆäEÖë-T&O`µ„Îæ“_3ùü2›o¿õ![´ðNÿg×Ar%–.d|´Å¹’Åî/Õ-òyŠ\ÈoÆ[×z5t¡Õ‡ÒŒËŒÚúø91Úõ ÙËB+Ú"YÑv݈ìea{ä¶Z×5+ä6ú#opäôóãrÐ6¡YZ¨dÚh€êo¯BÛp¸r7¬!ûÚŠn‡ìSè뚥èÊ÷®m¯EºYNë&èVÍr‚òö2ÑvKh_kµ¾^¶ýòÕ²ØïøÉEš¼ëhwêc 73.8 º;kÐÝùX…îÔÇ:´O;z¤ïѲ§³ 73.9 \ No newline at end of file
74.1 Binary file graster/hacklab-engraver/.git/objects/37/c611a4fe5ebcf722cfb0370d42eb714b52af1e has changed
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 75.2 +++ b/graster/hacklab-engraver/.git/objects/39/5d366090051b462e9f6be2003791a40e969c86 Tue Aug 24 19:06:45 2010 -0400 75.3 @@ -0,0 +1,3 @@ 75.4 +x 75.5 Ì=Â0Pæžâ“zØXÙ@bäùq‰%ÇF‰CTNO—7¾(q9_O+šddÂn£!îVùG÷ÛÉj 75.6 š; 75.7 +5ZV¼ 75.8 +wl,„É"PsD‚}©ÍÆî¤˜åà¨Ð†¢;}’é†ð¬Ë3M) 75.9 \ No newline at end of file
76.1 Binary file graster/hacklab-engraver/.git/objects/39/e4809471abf02fc5d1922bd32d0d14400aaeca has changed
77.1 Binary file graster/hacklab-engraver/.git/objects/3d/3c25ca420571813c3729711741718994c2988f has changed
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 78.2 +++ b/graster/hacklab-engraver/.git/objects/3d/c982cae4470a7c3b324027d05b2c377878e388 Tue Aug 24 19:06:45 2010 -0400 78.3 @@ -0,0 +1,2 @@ 78.4 +xŽ=n!…SsŠ)í"°0€Y©Ó¦s7,C;Ö.–åÛåi^óþ¾¹ké _úÆJ¡“ÞÇ!˜S2R*kØ#ËÙ 78.5 Ñ”ƒE§¢¸ÑƵåiÒÒÇ4I| 78.6 +JåÀ³Hƒw#ÊhÝûÒ6øäÄ©Ð_ãv÷§G©×çÛ¡¶ÊÇ(m¬4.( 78.7 ¯rü‹ù±ó¿Êâ¾3œáÒÊ€½µò€ø¡}¬}Sg(uïL Z†µõáŒøbSì 78.8 \ No newline at end of file
79.1 Binary file graster/hacklab-engraver/.git/objects/48/0396695515689f1ac537c08480180970892e9d has changed
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 80.2 +++ b/graster/hacklab-engraver/.git/objects/4a/654eac48d62e718b71c65eabd923b916ff7acb Tue Aug 24 19:06:45 2010 -0400 80.3 @@ -0,0 +1,1 @@ 80.4 +x¥ŽANÅ0DYç¹ÀGŽÇ®„è_³åNâÐ"ú‹úÂÛÓœ€ÝÌèÍhê¾mëð(éaf)ÔDК3-9c˜2—’BQVÓV£ûÔÃnß’‰˜[ɦØD©fË` ÁB”Äl¢|†ÐY¬PVìÅzaVêØm*mRÑ>%ÉÑé×XöÿX³¶êâ_Ï›‹zÿõ×ûúa·jo‡}ßë¾=û€$‚üÀéYö¿7ϳû£OYà 80.5 \ No newline at end of file
81.1 Binary file graster/hacklab-engraver/.git/objects/4e/bf8847d4464aabff8af13901492405f4ebd687 has changed
82.1 Binary file graster/hacklab-engraver/.git/objects/4f/b9341cc80ee60a78fb335bb4c951f3b1ba510f has changed
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 83.2 +++ b/graster/hacklab-engraver/.git/objects/54/162a6c26dfa90d099aa06fadefd17cd4483394 Tue Aug 24 19:06:45 2010 -0400 83.3 @@ -0,0 +1,2 @@ 83.4 +xUÔKrB1ÑL«È 83.5 +(ë¶Ÿq¶Ã˜ªìBå£f¦QKæÀýñy¯3ëí¬UǸŽ×çòœ¢ MSÓ©iiºiÚš>ú´UߪoÕ·ê[õúV}«¾{=Õë©^Oõzª×S½žêõT¯§z=¥zÆQ/Ÿ|ïR?ßC’#×±o·œ—3Ñ.Ñ.Ñ.Ñ.Ñ.Ñ.Ñ.S/1õSõ©úT}ª>UŸªOÕe02˜¥úR}©¾T_ª/Õ—ê2ŒF#ƒ‘ÁÈ`d02Èè/Ïè/Ïè·3úíŒ~;£ßÎè·3úíŒ~;/u¿¿~žêþÿ:¤©Cê:¤©Cê:¤©Cê:¤©Cê:¤©Cê:¤©Cê:¤©Cê:¤©Cê:ºº/ìÒ^ 83.6 \ No newline at end of file
84.1 Binary file graster/hacklab-engraver/.git/objects/54/c13cded8582bdd8bf57e2c58618a8be9d09732 has changed
85.1 Binary file graster/hacklab-engraver/.git/objects/57/273524331dcfcbb7256dd9ce8e3124e7d6408f has changed
86.1 Binary file graster/hacklab-engraver/.git/objects/58/94622e9772e7b5e4c26a7c4cf4379c82b81fd4 has changed
87.1 Binary file graster/hacklab-engraver/.git/objects/60/1f78eb56a2fbefb77a5f2fe9bd9a8af9486f22 has changed
88.1 Binary file graster/hacklab-engraver/.git/objects/6d/b2a0702414b2f7d4a54181fe45e9093a41e1bd has changed
89.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 89.2 +++ b/graster/hacklab-engraver/.git/objects/70/26e67d5af2e7a87b28c6fe30d4c826696f2ef9 Tue Aug 24 19:06:45 2010 -0400 89.3 @@ -0,0 +1,3 @@ 89.4 +xEŽ» 89.5 +Â@EóÒhi#X 89.6 X|`»ÙL²›Ù°;1į7Äæ§8çÖ>ÔØ›¥X?6„9ŒvLzþPƒKq… 89.7 }o¤Ip)Ëqwôg,PÇ -{‚‰„8 89.8 +L«N(^å 89.9 çG‰-¯–Õü<UŒß-º¤&jZ½?ÏÄÞC‚¢&„7Å)²* &·Ìrq$¥Áia:Ã’}ÛúF] 89.10 \ No newline at end of file
90.1 Binary file graster/hacklab-engraver/.git/objects/78/ccf41fc1c708e90f7f3b2b758a47bc5b96a226 has changed
91.1 Binary file graster/hacklab-engraver/.git/objects/7d/faf00af8b5ae18e4627c3afbb3847e7d488ae6 has changed
92.1 Binary file graster/hacklab-engraver/.git/objects/83/53fdf7673f571b8c01ef7a8bbc6f7d4eea7516 has changed
93.1 Binary file graster/hacklab-engraver/.git/objects/8d/fb8f06ad6c2bb6176e6b18865771d1dd176e19 has changed
94.1 Binary file graster/hacklab-engraver/.git/objects/96/0fe8e35f5f8bb29285df579ab915502a33f693 has changed
95.1 Binary file graster/hacklab-engraver/.git/objects/9b/0b4108a8f35a21daad3d5940943cbf312ab5c7 has changed
96.1 Binary file graster/hacklab-engraver/.git/objects/9d/c2be4daee1228bd8aab2b90952d626be419b0c has changed
97.1 Binary file graster/hacklab-engraver/.git/objects/a1/99207599f3af94759497e848fef2883df8a76b has changed
98.1 Binary file graster/hacklab-engraver/.git/objects/ac/ae4229fe68fd4923d125246686c852d5ff2753 has changed
99.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 99.2 +++ b/graster/hacklab-engraver/.git/objects/af/33204aebd30798d911f9ec8b6a5698726b60b5 Tue Aug 24 19:06:45 2010 -0400 99.3 @@ -0,0 +1,3 @@ 99.4 +x•ÎMjÃ0@á®uŠY¦Ð†ÑÏØ”Òe®1’Fµ‰eY¿!9AwoóàKÖu€qúetÀlч…²ÇìyŽž™KÒEl 99.5 +g!2Yýp—}@˜°ˆK…ŠÑã)šÇ ‰Ð°µe 99.6 +Vñm,Ã…ÓuãË3¾6>¤ŸO{Ûåõ´q„nžôïèUzø†üÿT•+”õWŽ7XZHõ¼ß{½ÛÕö†L 99.7 \ No newline at end of file
100.1 Binary file graster/hacklab-engraver/.git/objects/b3/0bed63de14c07bd564eac82fe54f010bf92832 has changed
101.1 Binary file graster/hacklab-engraver/.git/objects/cc/b6e0ad8e62b83d682cd474a2b4216f3b70fd8c has changed
102.1 Binary file graster/hacklab-engraver/.git/objects/d1/3c62bbf9d08745832b0a4c58d43f668eb3e207 has changed
103.1 Binary file graster/hacklab-engraver/.git/objects/da/a8c4c5d9403e3de6de63bf00d963522725ba18 has changed
104.1 Binary file graster/hacklab-engraver/.git/objects/dc/37075577db6f593d8a5c6e60e081e138477e8a has changed
105.1 Binary file graster/hacklab-engraver/.git/objects/de/bcc458e2f4f7f49261278ea90701db1bbc9611 has changed
106.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 106.2 +++ b/graster/hacklab-engraver/.git/objects/e2/46361935fe95d0e4629abdaa1e48b8d09f3eee Tue Aug 24 19:06:45 2010 -0400 106.3 @@ -0,0 +1,5 @@ 106.4 +x•AŽÂ0EYç^Âä¶IM$„fÉ5Ç¡M[¥óÌœ€ÝÛü§ÿdÉy¬ÐZÚÕ¢ 106.5 +- 106.6 +÷½„hKX±O)6DÎugGj;ŽÌÊEç 106.7 +‰œø^zVÅDžIÑiÀ¦#Ä¿},†ŸuX 106.8 +ÜX¸ÿð3ñ¦å´Ÿ—YWhZ×¢µ¾!8¢E4ò÷¯ê÷K“Ÿ2À˜×¥¼4½ðöÑlïLÎã|‡MʸVóȬPD 106.9 \ No newline at end of file
107.1 Binary file graster/hacklab-engraver/.git/objects/e4/d9a3115b00e8960dd5555a488b8778b095e8c1 has changed
108.1 Binary file graster/hacklab-engraver/.git/objects/e8/ff6ce26c2cd4370986e0cfc5beb41c0a39c061 has changed
109.1 Binary file graster/hacklab-engraver/.git/objects/ec/0de6b82e3ba8dc08be4a1d41ad756f1da012fd has changed
110.1 Binary file graster/hacklab-engraver/.git/objects/f0/2a7c6678d381e90f39fd7f5b6a1a7e7c53d523 has changed
111.1 Binary file graster/hacklab-engraver/.git/objects/f5/326e4e272b2b6e7018cc0ab02aa5782d9c9fcc has changed
112.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 112.2 +++ b/graster/hacklab-engraver/.git/objects/f6/f4f18f2b41ec1c9cfcea1e6c74c6e9da89fb03 Tue Aug 24 19:06:45 2010 -0400 112.3 @@ -0,0 +1,2 @@ 112.4 +x•KŽÂ0DYû½ ö?‘š%×h·;!"d{î?NÀ®¤ÒS½âmY¦ÆùC+",&ÉÁfÑŽ1¦ìƒâÎâÝ€ÓЛÎõ¤"kƒ!s‚Å^ÛˆuÌì“gor 112.5 +Éq´{cQÑ_»onÄ™\îŸð;S•rþY·UŽWлˆÁÐE„:DÅo¿&ß“j,T_ྼÁy\¨> î'i™Ö*—éÙÔ?2ÏMÅ 112.6 \ No newline at end of file
113.1 Binary file graster/hacklab-engraver/.git/objects/f7/5c96c6ae9db0be0f79a7e05eb01379bc9a64ac has changed
114.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 114.2 +++ b/graster/hacklab-engraver/.git/objects/fd/c9663091370e717dc46ca5c52db6b4c7313730 Tue Aug 24 19:06:45 2010 -0400 114.3 @@ -0,0 +1,3 @@ 114.4 +x•Ž;Â0©}Š-¡ Úø/B”œní¬•#ÇÜŸN@õ¦Í‹yšÆ 114.5 +Úá®h5qßÚ®MÁxgcê<êÞ¹D‚ƒEÓ%âDêÅEæ 114.6 +¦'Ò‘ÅZì£ F[Ô¾Gt4Þ“'1DŠßuÈnOp~p}ò"¥ÙÏy–ÃeÍ[§±[-8¢ETqûWåS 114.7 y¸CÍ€ 114.8 ¶ß•yy:lYÈ)©È¡LÍ 114.9 \ No newline at end of file
115.1 Binary file graster/hacklab-engraver/.git/objects/fe/62c30f734c6223bc20d82619baca9da73a3a8a has changed
116.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 116.2 +++ b/graster/hacklab-engraver/.git/packed-refs Tue Aug 24 19:06:45 2010 -0400 116.3 @@ -0,0 +1,2 @@ 116.4 +# pack-refs with: peeled 116.5 +4a654eac48d62e718b71c65eabd923b916ff7acb refs/remotes/origin/master
117.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 117.2 +++ b/graster/hacklab-engraver/.git/refs/heads/master Tue Aug 24 19:06:45 2010 -0400 117.3 @@ -0,0 +1,1 @@ 117.4 +4a654eac48d62e718b71c65eabd923b916ff7acb
118.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 118.2 +++ b/graster/hacklab-engraver/.git/refs/remotes/origin/HEAD Tue Aug 24 19:06:45 2010 -0400 118.3 @@ -0,0 +1,1 @@ 118.4 +ref: refs/remotes/origin/master
119.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 119.2 +++ b/graster/hacklab-engraver/.gitignore Tue Aug 24 19:06:45 2010 -0400 119.3 @@ -0,0 +1,5 @@ 119.4 +/junk 119.5 +.scope.cfg 119.6 +autosave.halscope 119.7 +emc.var 119.8 +emc.var.bak
120.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 120.2 +++ b/graster/hacklab-engraver/M101 Tue Aug 24 19:06:45 2010 -0400 120.3 @@ -0,0 +1,85 @@ 120.4 +#!/usr/bin/python 120.5 + 120.6 +# === Graster Streaming Script === 120.7 +# 120.8 +# This script is invoked by g-code M101 at the 120.9 +# beginning of every graster job. It figures out 120.10 +# the name of the mask file and forks a process 120.11 +# to stream it to the HAL while AXIS executes the 120.12 +# motion code. 120.13 +# 120.14 +# This file must be symlinked to the ~/emc2/nc_files dir 120.15 + 120.16 +import emc, os, sys, threading, gtk, time, popen2, signal, select 120.17 + 120.18 +os.chdir("/home/hacklab/emc2/configs/hacklab-engraver3") 120.19 +ini = emc.ini("hacklab-engraver3.ini") 120.20 +emc.nmlfile = ini.find("EMC","NML_FILE") 120.21 +s = emc.stat() 120.22 +s.poll() 120.23 +ngc = s.file 120.24 +(base,ext) = os.path.splitext(ngc) 120.25 +gmask = base+".gmask" 120.26 +if not os.path.exists(gmask): 120.27 + gmask = ngc+".gmask" 120.28 + if not os.path.exists(gmask): 120.29 + os.system('zenity --error --text "Mask file \''+base+'.gmask\' not found. Laser disabled for this job."') 120.30 + sys.exit(os.EX_NOINPUT) 120.31 + 120.32 + 120.33 +def make_pbar(): 120.34 + (path,fn) = os.path.split(gmask) 120.35 + message = "Streaming '"+fn+"'\n\n" + \ 120.36 + "This dialog should complete and close itself some time before\n" + \ 120.37 + "your job is done. If you stop the job, wait for this dialog\n" + \ 120.38 + "to go away before starting another one. If it won't go away,\n" + \ 120.39 + "click 'Cancel' and kill any processes containing 'M101'.\n" 120.40 + return popen2.Popen3('zenity --progress --auto-close --auto-kill --title "Graster Streamer" --text "'+message+'"') 120.41 + 120.42 +pbar = make_pbar() 120.43 + 120.44 +total_lines = 0 120.45 +fd = open(gmask,'r') 120.46 +for x in fd.readlines(): 120.47 + total_lines += 1 120.48 +fd.close() 120.49 + 120.50 +total_lines = float(total_lines) 120.51 +count = 0 120.52 + 120.53 +print "Streaming '"+gmask+"'..." 120.54 +pid = os.fork() 120.55 + 120.56 +if pid: 120.57 + time.sleep(2) 120.58 + sys.exit(os.EX_OK) 120.59 +else: 120.60 + os.setsid() 120.61 + fin = open(gmask,'r') 120.62 + fout = os.popen('halstreamer','w') 120.63 + try: 120.64 + for line in fin.readlines(): 120.65 + #r,w,e = select.select((),(fout,),(fout,),0.1) 120.66 + if pbar.poll() != -1: raise 120.67 + 120.68 + #if len(w) > 0: 120.69 + fout.write(line) 120.70 + count += 1 120.71 + #elif len(e) > 0: 120.72 + # os.system("zenity --error --text 'Error writing to halstreamer. Job may not finish.'") 120.73 + # raise 120.74 + 120.75 + pbar.tochild.write(str(int(100.0*count/total_lines))+"\n") 120.76 + 120.77 + finally: 120.78 + print "...cleaning up..." 120.79 + #fin.close() 120.80 + #fout.close() 120.81 + pbar.tochild.close() 120.82 + pbar.fromchild.close() 120.83 + #os.kill(pbar.pid,signal.SIGINT) 120.84 + #os.kill(pbar.pid,signal.SIGKILL) 120.85 + print "...done!" 120.86 + os._exit(os.EX_OK) 120.87 + #sys.exit(os.EX_OK) 120.88 +
121.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 121.2 +++ b/graster/hacklab-engraver/README Tue Aug 24 19:06:45 2010 -0400 121.3 @@ -0,0 +1,1 @@ 121.4 +Generated by stepconf at Sat Mar 21 03:02:15 2009
122.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 122.2 +++ b/graster/hacklab-engraver/custom.hal Tue Aug 24 19:06:45 2010 -0400 122.3 @@ -0,0 +1,2 @@ 122.4 +# Include your customized HAL commands here 122.5 +# This file will not be overwritten when you run stepconf again
123.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 123.2 +++ b/graster/hacklab-engraver/custom_postgui.hal Tue Aug 24 19:06:45 2010 -0400 123.3 @@ -0,0 +1,4 @@ 123.4 +# Include your customized HAL commands here 123.5 +# The commands in this file are run after the AXIS GUI (including PyVCP panel) 123.6 +# starts 123.7 +# This file will not be overwritten when you run stepconf again
124.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 124.2 +++ b/graster/hacklab-engraver/emc.nml Tue Aug 24 19:06:45 2010 -0400 124.3 @@ -0,0 +1,47 @@ 124.4 + 124.5 +# Note: emcsvr is the master for all NML channels, and therefore is the 124.6 +# first to start. 124.7 + 124.8 +# Buffers 124.9 +# Name Type Host size neut? (old) buffer# MP --- 124.10 + 124.11 +# Top-level buffers to EMC 124.12 +B emcCommand SHMEM localhost 8192 0 0 1 16 1001 TCP=5005 xdr 124.13 +B emcStatus SHMEM localhost 10240 0 0 2 16 1002 TCP=5005 xdr 124.14 +B emcError SHMEM localhost 8192 0 0 3 16 1003 TCP=5005 xdr queue 124.15 + 124.16 +# These are for the IO controller, EMCIO 124.17 +B toolCmd SHMEM localhost 1024 0 0 4 16 1004 TCP=5005 xdr 124.18 +B toolSts SHMEM localhost 8192 0 0 5 16 1005 TCP=5005 xdr 124.19 + 124.20 +# Processes 124.21 +# Name Buffer Type Host Ops server? timeout master? cnum 124.22 + 124.23 +P emc emcCommand LOCAL localhost RW 0 1.0 0 0 124.24 +P emc emcStatus LOCAL localhost W 0 1.0 0 0 124.25 +P emc emcError LOCAL localhost W 0 1.0 0 0 124.26 +P emc toolCmd LOCAL localhost W 0 1.0 0 0 124.27 +P emc toolSts LOCAL localhost R 0 1.0 0 0 124.28 + 124.29 +P emcsvr emcCommand LOCAL localhost W 1 1.0 1 2 124.30 +P emcsvr emcStatus LOCAL localhost R 1 1.0 1 2 124.31 +P emcsvr emcError LOCAL localhost R 1 1.0 1 2 124.32 +P emcsvr toolCmd LOCAL localhost W 1 1.0 1 2 124.33 +P emcsvr toolSts LOCAL localhost R 1 1.0 1 2 124.34 +P emcsvr default LOCAL localhost RW 1 1.0 1 2 124.35 + 124.36 +P tool emcError LOCAL localhost W 0 1.0 0 3 124.37 +P tool toolCmd LOCAL localhost RW 0 1.0 0 3 124.38 +P tool toolSts LOCAL localhost W 0 1.0 0 3 124.39 + 124.40 +P xemc emcCommand LOCAL localhost W 0 10.0 0 10 124.41 +P xemc emcStatus LOCAL localhost R 0 10.0 0 10 124.42 +P xemc emcError LOCAL localhost R 0 10.0 0 10 124.43 +P xemc toolCmd LOCAL localhost W 0 10.0 0 10 124.44 +P xemc toolSts LOCAL localhost R 0 10.0 0 10 124.45 + 124.46 +P keystick emcCommand LOCAL localhost W 0 10.0 0 10 124.47 +P keystick emcStatus LOCAL localhost R 0 10.0 0 10 124.48 +P keystick emcError LOCAL localhost R 0 10.0 0 10 124.49 +P keystick toolCmd LOCAL localhost W 0 10.0 0 10 124.50 +P keystick toolSts LOCAL localhost R 0 10.0 0 10
125.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 125.2 +++ b/graster/hacklab-engraver/hacklab-engraver3.hal Tue Aug 24 19:06:45 2010 -0400 125.3 @@ -0,0 +1,233 @@ 125.4 +# Generated by stepconf at Sun Mar 8 21:32:59 2009 125.5 +# If you make changes to this file, they will be 125.6 +# overwritten when you run stepconf again 125.7 + 125.8 +loadrt threads name1=mask-thread period1=100000 125.9 + 125.10 +loadrt trivkins 125.11 +loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD traj_period_nsec=[EMCMOT]SERVO_PERIOD key=[EMCMOT]SHMEM_KEY num_joints=[TRAJ]AXES 125.12 +loadrt probe_parport 125.13 +loadrt hal_parport cfg=0x378 125.14 +setp parport.0.reset-time 100000 125.15 +loadrt stepgen step_type=0,0,0,0 125.16 +loadrt charge_pump 125.17 + 125.18 + 125.19 +# Boring components that emc makes me load explicitly because it is a cunt 125.20 +loadrt comp names=comp-mask-lte,comp-discrete-z 125.21 +loadrt not names=not-mask-ffw,not-mask-not-empty 125.22 +loadrt xor2 names=xor2-mask-test 125.23 +loadrt and2 names=and2-mask-forward,and2-laser-mask,and2-laser-final 125.24 +loadrt or2 names=or2-mask-command-done,or2-mask-not-ffw,or2-mask-read,or2-laser-gcode,or2-laser-fine 125.25 + 125.26 + 125.27 +# Fast thread for generating signals 125.28 +addf parport.0.read base-thread 125.29 +addf stepgen.make-pulses base-thread 125.30 +addf parport.0.write base-thread 125.31 +addf parport.0.reset base-thread 125.32 +addf charge-pump base-thread 125.33 + 125.34 +# Slow thread for logic (more logic components are added further down) 125.35 +addf stepgen.capture-position servo-thread 125.36 +addf motion-command-handler servo-thread 125.37 +addf motion-controller servo-thread 125.38 +addf stepgen.update-freq servo-thread 125.39 + 125.40 + 125.41 +################################################################################### 125.42 +# Raster Mask - stream in laser on/off commands behind AXIS's back 125.43 +# Input stream format: reset beam xop xarg 125.44 +# reset: 0=mask command 1=reset (begin mask sequence with "1 0 0 0", every other command starts with 0) 125.45 +# beam: 0=off 1=on 125.46 +# xop: X axis comparison operation 0=less-or-equal 1=greater 125.47 +# xarg: X axis comparison operand 125.48 + 125.49 +loadrt streamer depth=256 cfg="bbbf" 125.50 +net mask-reset <= streamer.0.pin.0 125.51 +net mask-beam <= streamer.0.pin.1 125.52 +net mask-xop <= streamer.0.pin.2 125.53 +net mask-xarg <= streamer.0.pin.3 125.54 +net mask-empty <= streamer.0.empty 125.55 +net mask-read => streamer.0.enable 125.56 + 125.57 +# hardware reported X axis position 125.58 +net motion-xpos-fb <= axis.0.joint-pos-fb 125.59 + 125.60 +# mask-lte <= motion-xpos-fb < mask-xarg 125.61 +addf comp-mask-lte mask-thread 125.62 +net motion-xpos-fb => comp-mask-lte.in0 125.63 +net mask-xarg => comp-mask-lte.in1 125.64 +net mask-lte <= comp-mask-lte.out 125.65 + 125.66 +# mask-test <= mask-xop ^ mask-lte 125.67 +addf xor2-mask-test mask-thread 125.68 +net mask-xop => xor2-mask-test.in0 125.69 +net mask-lte => xor2-mask-test.in1 125.70 +net mask-test <= xor2-mask-test.out 125.71 + 125.72 +# if job is running, read only if test is true or reset 125.73 +# if job is not running, read until reset 125.74 +# mask-read <= (laser-coarse && (mask-test || mask-reset)) || !(laser-coarse || mask-reset) 125.75 + 125.76 +addf or2-mask-command-done mask-thread 125.77 +net mask-test => or2-mask-command-done.in0 125.78 +net mask-reset => or2-mask-command-done.in1 125.79 +net mask-command-done <= or2-mask-command-done.out 125.80 + 125.81 +addf and2-mask-forward mask-thread 125.82 +net laser-coarse => and2-mask-forward.in0 125.83 +net mask-command-done => and2-mask-forward.in1 125.84 +net mask-forward <= and2-mask-forward.out 125.85 + 125.86 +addf or2-mask-not-ffw mask-thread 125.87 +net laser-coarse => or2-mask-not-ffw.in0 125.88 +net mask-reset => or2-mask-not-ffw.in1 125.89 +net mask-not-ffw <= or2-mask-not-ffw.out 125.90 + 125.91 +addf not-mask-ffw mask-thread 125.92 +net mask-not-ffw => not-mask-ffw.in 125.93 +net mask-ffw <= not-mask-ffw.out 125.94 + 125.95 +addf or2-mask-read mask-thread 125.96 +net mask-forward => or2-mask-read.in0 125.97 +net mask-ffw => or2-mask-read.in1 125.98 +net mask-read <= or2-mask-read.out 125.99 + 125.100 +# laser-mask <= mask-not-empty && mask-beam 125.101 +addf not-mask-not-empty mask-thread 125.102 +net mask-empty => not-mask-not-empty.in 125.103 +net mask-not-empty <= not-mask-not-empty.out 125.104 + 125.105 +addf and2-laser-mask mask-thread 125.106 +net mask-beam => and2-laser-mask.in0 125.107 +net mask-not-empty => and2-laser-mask.in1 125.108 +net laser-mask <= and2-laser-mask.out 125.109 + 125.110 +addf streamer.0 mask-thread 125.111 + 125.112 +# Raster Mask - end 125.113 +####################################################################### 125.114 + 125.115 +# coarse laser control, wired to spindle on/off (M3/M5), not realtime 125.116 +net laser-coarse <= motion.spindle-on 125.117 + 125.118 +# fine laser control, wired to digital output 0 (M62 P0/M63 P0), realtime 125.119 +net laser-gate <= motion.digital-out-00 125.120 + 125.121 +# legacy laser control, wired to Z < 0, can be used instead of M62/M63 125.122 +addf comp-discrete-z servo-thread 125.123 +net motion-zpos-fb <= axis.2.joint-pos-fb 125.124 +net motion-zpos-fb => comp-discrete-z.in0 125.125 +setp comp-discrete-z.in1 0 125.126 +net discrete-z <= comp-discrete-z.out 125.127 + 125.128 +# laser-final <= laser-coarse & (laser-gate | discrete-z | laser-mask) 125.129 +addf or2-laser-gcode mask-thread 125.130 +net laser-gate => or2-laser-gcode.in0 125.131 +net discrete-z => or2-laser-gcode.in1 125.132 +net laser-gcode <= or2-laser-gcode.out 125.133 + 125.134 +addf or2-laser-fine mask-thread 125.135 +net laser-gcode => or2-laser-fine.in0 125.136 +net laser-mask => or2-laser-fine.in1 125.137 +net laser-fine <= or2-laser-fine.out 125.138 + 125.139 +addf and2-laser-final mask-thread 125.140 +net laser-fine => and2-laser-final.in0 125.141 +net laser-coarse => and2-laser-final.in1 125.142 +net laser-final <= and2-laser-final.out 125.143 + 125.144 +# laser-final => hardware 125.145 +net laser-final => parport.0.pin-01-out 125.146 + 125.147 +# make Z and W axes always homed 125.148 +#setp axis.2.homed 1 # Z 125.149 +#setp axis.8.homed 1 # W 125.150 + 125.151 +net xdir => parport.0.pin-02-out 125.152 +net xstep => parport.0.pin-03-out 125.153 +setp parport.0.pin-03-out-reset 1 125.154 +net ydir => parport.0.pin-04-out 125.155 +net ystep => parport.0.pin-05-out 125.156 +setp parport.0.pin-05-out-reset 1 125.157 +net wdir => parport.0.pin-06-out 125.158 +net wstep => parport.0.pin-07-out 125.159 +setp parport.0.pin-07-out-reset 1 125.160 + 125.161 +# invert ydir 125.162 +#setp parport.0.pin-04-out-invert 1 125.163 + 125.164 + 125.165 +net xenable => parport.0.pin-14-out 125.166 + 125.167 +net home-x <= parport.0.pin-10-in 125.168 +net home-y <= parport.0.pin-12-in 125.169 +net estop-ext <= parport.0.pin-15-in 125.170 + 125.171 +setp stepgen.0.position-scale [AXIS_0]SCALE 125.172 +setp stepgen.0.steplen 15200 125.173 +setp stepgen.0.stepspace 15200 125.174 +setp stepgen.0.dirhold 15200 125.175 +setp stepgen.0.dirsetup 15200 125.176 +setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL 125.177 +net xpos-cmd axis.0.motor-pos-cmd => stepgen.0.position-cmd 125.178 +net xpos-fb stepgen.0.position-fb => axis.0.motor-pos-fb 125.179 +net xstep <= stepgen.0.step 125.180 +net xdir <= stepgen.0.dir 125.181 +net xenable axis.0.amp-enable-out => stepgen.0.enable 125.182 +net home-x => axis.0.home-sw-in 125.183 + 125.184 +setp stepgen.1.position-scale [AXIS_1]SCALE 125.185 +setp stepgen.1.steplen 15200 125.186 +setp stepgen.1.stepspace 15200 125.187 +setp stepgen.1.dirhold 15200 125.188 +setp stepgen.1.dirsetup 15200 125.189 +setp stepgen.1.maxaccel [AXIS_1]STEPGEN_MAXACCEL 125.190 +net ypos-cmd axis.1.motor-pos-cmd => stepgen.1.position-cmd 125.191 +net ypos-fb stepgen.1.position-fb => axis.1.motor-pos-fb 125.192 +net ystep <= stepgen.1.step 125.193 +net ydir <= stepgen.1.dir 125.194 +net yenable axis.1.amp-enable-out => stepgen.1.enable 125.195 +net home-y => axis.1.home-sw-in 125.196 + 125.197 +setp stepgen.2.position-scale [AXIS_2]SCALE 125.198 +setp stepgen.2.steplen 1 125.199 +setp stepgen.2.stepspace 0 125.200 +setp stepgen.2.dirhold 15200 125.201 +setp stepgen.2.dirsetup 15200 125.202 +setp stepgen.2.maxaccel [AXIS_2]STEPGEN_MAXACCEL 125.203 +net zpos-cmd axis.2.motor-pos-cmd => stepgen.2.position-cmd 125.204 +net zpos-fb stepgen.2.position-fb => axis.2.motor-pos-fb 125.205 +net zstep <= stepgen.2.step 125.206 +net zdir <= stepgen.2.dir 125.207 +net zenable axis.2.amp-enable-out => stepgen.2.enable 125.208 +net home-z => axis.2.home-sw-in 125.209 + 125.210 +setp stepgen.3.position-scale [AXIS_8]SCALE 125.211 +setp stepgen.3.steplen 1 125.212 +setp stepgen.3.stepspace 0 125.213 +setp stepgen.3.dirhold 15200 125.214 +setp stepgen.3.dirsetup 15200 125.215 +setp stepgen.3.maxaccel [AXIS_8]STEPGEN_MAXACCEL 125.216 +net wpos-cmd axis.8.motor-pos-cmd => stepgen.3.position-cmd 125.217 +net wpos-fb stepgen.3.position-fb => axis.8.motor-pos-fb 125.218 +net wstep <= stepgen.3.step 125.219 +net wdir <= stepgen.3.dir 125.220 +net wenable axis.8.amp-enable-out => stepgen.3.enable 125.221 +net home-w => axis.8.home-sw-in 125.222 + 125.223 +net estop-out <= iocontrol.0.user-enable-out 125.224 +net estop-ext => iocontrol.0.emc-enable-in 125.225 + 125.226 +loadusr -W hal_manualtoolchange 125.227 +net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change 125.228 +net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed 125.229 +net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number 125.230 +net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared 125.231 + 125.232 +# connect the charge pump signal to an output 125.233 +net charge-pump <= charge-pump.out 125.234 +setp parport.0.pin-17-out-reset 1 125.235 +net charge-pump => parport.0.pin-17-out 125.236 +setp charge-pump.enable 1
126.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 126.2 +++ b/graster/hacklab-engraver/hacklab-engraver3.ini Tue Aug 24 19:06:45 2010 -0400 126.3 @@ -0,0 +1,124 @@ 126.4 +# Generated by stepconf at Sun Mar 8 21:32:59 2009 126.5 +# If you make changes to this file, they will be 126.6 +# overwritten when you run stepconf again 126.7 + 126.8 +[EMC] 126.9 +MACHINE = hacklab-engraver3 126.10 +NML_FILE = emc.nml 126.11 +DEBUG = 0 126.12 + 126.13 +[DISPLAY] 126.14 +DISPLAY = axis 126.15 +EDITOR = gedit 126.16 +POSITION_OFFSET = RELATIVE 126.17 +POSITION_FEEDBACK = ACTUAL 126.18 +MAX_FEED_OVERRIDE = 2 126.19 +INTRO_GRAPHIC = emc2.gif 126.20 +INTRO_TIME = 5 126.21 +PROGRAM_PREFIX = /home/hacklab/emc2/nc_files 126.22 +INCREMENTS = 1.0in .1in .05in .01in .005in .001in .0005in 126.23 + 126.24 +[TASK] 126.25 +TASK = milltask 126.26 +CYCLE_TIME = 0.010 126.27 + 126.28 +[RS274NGC] 126.29 +PARAMETER_FILE = emc.var 126.30 + 126.31 +[EMCMOT] 126.32 +EMCMOT = motmod 126.33 +SHMEM_KEY = 111 126.34 +COMM_TIMEOUT = 1.0 126.35 +COMM_WAIT = 0.010 126.36 +BASE_PERIOD = 100000 126.37 +#SERVO_PERIOD = 200000 126.38 +SERVO_PERIOD = 1000000 126.39 + 126.40 + 126.41 +[HAL] 126.42 +HALFILE = hacklab-engraver3.hal 126.43 +HALFILE = custom.hal 126.44 +POSTGUI_HALFILE = custom_postgui.hal 126.45 +HALUI = halui 126.46 + 126.47 +[TRAJ] 126.48 +AXES = 9 126.49 +COORDINATES = X Y Z W 126.50 +LINEAR_UNITS = inch 126.51 +ANGULAR_UNITS = degree 126.52 +CYCLE_TIME = 0.010 126.53 +DEFAULT_VELOCITY = 6.00 126.54 +MAX_LINEAR_VELOCITY = 300.00 126.55 + 126.56 +[EMCIO] 126.57 +EMCIO = io 126.58 +CYCLE_TIME = 0.100 126.59 +TOOL_TABLE = tool.tbl 126.60 + 126.61 +[AXIS_0] 126.62 +TYPE = LINEAR 126.63 +HOME = 23.5 126.64 +MAX_VELOCITY = 5 126.65 +MAX_ACCELERATION = 20.0 126.66 +STEPGEN_MAXACCEL = 25.0 126.67 +SCALE = 500.0 126.68 +FERROR = 0.05 126.69 +MIN_FERROR = 0.01 126.70 +MIN_LIMIT = 0.0 126.71 +MAX_LIMIT = 23.5 126.72 +HOME_OFFSET = 22.95 126.73 +HOME_SEARCH_VEL = -6 126.74 +HOME_LATCH_VEL = -0.100000 126.75 +HOME_SEQUENCE = 1 126.76 + 126.77 +[AXIS_1] 126.78 +TYPE = LINEAR 126.79 +HOME = 18.05 126.80 +MAX_VELOCITY = 5.0 126.81 +MAX_ACCELERATION = 20.0 126.82 +STEPGEN_MAXACCEL = 25.0 126.83 +#MAX_ACCELERATION = 200.0 126.84 +#STEPGEN_MAXACCEL = 250.0 126.85 +SCALE = 500.0 126.86 +FERROR = 0.05 126.87 +MIN_FERROR = 0.01 126.88 +MIN_LIMIT = 0 126.89 +MAX_LIMIT = 18.05 126.90 +HOME_OFFSET = 16.7 126.91 +HOME_SEARCH_VEL = -5 126.92 +HOME_LATCH_VEL = -0.100000 126.93 +HOME_SEQUENCE = 0 126.94 + 126.95 +[AXIS_2] 126.96 +TYPE = LINEAR 126.97 +HOME = 0.01 126.98 +MAX_VELOCITY = 2000.0 126.99 +MAX_ACCELERATION = 2000.0 126.100 +STEPGEN_MAXACCEL = 3000.0 126.101 +SCALE = 1.0 126.102 +FERROR = 0.0 126.103 +MIN_FERROR = 0.01 126.104 +MIN_LIMIT = -4.0 126.105 +MAX_LIMIT = 4 126.106 +HOME_OFFSET = 0 126.107 +HOME_SEARCH_VEL = 0 126.108 +HOME_LATCH_VEL = 0 126.109 +HOME_SEQUENCE = 2 126.110 + 126.111 +[AXIS_8] 126.112 +TYPE = LINEAR 126.113 +HOME = 0.0 126.114 +MAX_VELOCITY = 0.250 126.115 +MAX_ACCELERATION = 10.0 126.116 +STEPGEN_MAXACCEL = 10.0 126.117 +#MAX_ACCELERATION = 300.0 126.118 +#STEPGEN_MAXACCEL = 370.5 126.119 +SCALE = 2000.0 126.120 +FERROR = 0.05 126.121 +MIN_FERROR = 0.01 126.122 +MIN_LIMIT = -4 126.123 +MAX_LIMIT = 4 126.124 +HOME_OFFSET = 0 126.125 +HOME_SEARCH_VEL = 0 126.126 +HOME_LATCH_VEL = 0 126.127 +HOME_SEQUENCE = 3
127.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 127.2 +++ b/graster/hacklab-engraver/probe-results.txt Tue Aug 24 19:06:45 2010 -0400 127.3 @@ -0,0 +1,9 @@ 127.4 +0.000000 0.000000 -0.076762 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 127.5 +0.000000 0.000000 -0.076762 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 127.6 +0.000000 0.000000 -0.076762 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 127.7 +0.000000 0.000000 -0.076762 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 127.8 +0.000000 0.000000 -0.076762 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 127.9 +0.000000 0.000000 -0.076762 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 127.10 +0.000000 0.000000 -0.076762 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 127.11 +0.000000 0.000000 -0.076762 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 127.12 +0.000000 0.000000 -0.076762 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
128.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 128.2 +++ b/graster/hacklab-engraver/tool.tbl Tue Aug 24 19:06:45 2010 -0400 128.3 @@ -0,0 +1,8 @@ 128.4 +POC FMS LEN DIAM COMMENT 128.5 + 128.6 +1 1 0.5 0.0625 first tool 128.7 +2 2 0.7 0.125 128.8 +3 3 0.5 1.25 128.9 +4 4 0.7 1.0 128.10 +5 5 0 0.5 128.11 +32 32 0.5 0.0 last tool
129.1 Binary file graster/lasercheck.tgz has changed
130.1 Binary file graster/signer4laser2x1.png has changed
131.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 131.2 +++ b/graster/signer4laser2x1.png.cut.ngc Tue Aug 24 19:06:45 2010 -0400 131.3 @@ -0,0 +1,13 @@ 131.4 +M63 P0 131.5 +G61 131.6 +F20 131.7 +M3 S1 131.8 +G0 X1.000 Y1.000 131.9 +G1 X1.000 Y2.066 M62 P0 131.10 +G1 X3.000 Y2.066 131.11 +G1 X3.000 Y1.000 131.12 +G1 X1.000 Y1.000 131.13 +M63 P0 131.14 +M63 P0 131.15 +M5 131.16 +M2
132.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 132.2 +++ b/graster/signer4laser2x1.png.raster.gmask Tue Aug 24 19:06:45 2010 -0400 132.3 @@ -0,0 +1,10808 @@ 132.4 +1 0 0 0 132.5 +0 0 1 2.881 132.6 +0 0 0 2.881 132.7 +0 1 0 2.863 132.8 +0 0 0 2.769 132.9 +0 1 0 2.751 132.10 +0 0 0 2.729 132.11 +0 1 0 2.617 132.12 +0 0 0 2.593 132.13 +0 1 0 2.561 132.14 +0 0 0 2.463 132.15 +0 1 0 2.445 132.16 +0 0 0 2.385 132.17 +0 1 0 2.317 132.18 +0 0 0 2.253 132.19 +0 1 0 2.233 132.20 +0 0 0 2.177 132.21 +0 1 0 2.113 132.22 +0 0 0 1.979 132.23 +0 1 0 1.869 132.24 +0 0 0 1.843 132.25 +0 1 0 1.825 132.26 +0 0 0 1.731 132.27 +0 1 0 1.713 132.28 +0 0 0 1.647 132.29 +0 1 0 1.585 132.30 +0 0 0 1.493 132.31 +0 1 0 1.427 132.32 +0 0 0 1.369 132.33 +0 1 0 1.259 132.34 +0 0 0 1.207 132.35 +0 1 0 1.143 132.36 +0 0 0 1.135 132.37 +0 0 1 1.135 132.38 +0 1 1 1.217 132.39 +0 0 1 1.259 132.40 +0 1 1 1.371 132.41 +0 0 1 1.419 132.42 +0 1 1 1.503 132.43 +0 0 1 1.575 132.44 +0 1 1 1.657 132.45 +0 0 1 1.713 132.46 +0 1 1 1.733 132.47 +0 0 1 1.823 132.48 +0 1 1 1.843 132.49 +0 0 1 1.867 132.50 +0 1 1 1.979 132.51 +0 0 1 2.105 132.52 +0 1 1 2.187 132.53 +0 0 1 2.233 132.54 +0 1 1 2.253 132.55 +0 0 1 2.309 132.56 +0 1 1 2.393 132.57 +0 0 1 2.445 132.58 +0 1 1 2.463 132.59 +0 0 1 2.559 132.60 +0 1 1 2.593 132.61 +0 0 1 2.617 132.62 +0 1 1 2.729 132.63 +0 0 1 2.751 132.64 +0 1 1 2.771 132.65 +0 0 1 2.861 132.66 +0 1 1 2.881 132.67 +0 0 1 2.881 132.68 +0 0 0 2.881 132.69 +0 1 0 2.861 132.70 +0 0 0 2.771 132.71 +0 1 0 2.751 132.72 +0 0 0 2.729 132.73 +0 1 0 2.617 132.74 +0 0 0 2.593 132.75 +0 1 0 2.557 132.76 +0 0 0 2.463 132.77 +0 1 0 2.445 132.78 +0 0 0 2.401 132.79 +0 1 0 2.303 132.80 +0 0 0 2.253 132.81 +0 1 0 2.233 132.82 +0 0 0 2.193 132.83 +0 1 0 2.099 132.84 +0 0 0 1.979 132.85 +0 1 0 1.867 132.86 +0 0 0 1.843 132.87 +0 1 0 1.823 132.88 +0 0 0 1.733 132.89 +0 1 0 1.713 132.90 +0 0 0 1.663 132.91 +0 1 0 1.569 132.92 +0 0 0 1.509 132.93 +0 1 0 1.413 132.94 +0 0 0 1.371 132.95 +0 1 0 1.259 132.96 +0 0 0 1.221 132.97 +0 1 0 1.129 132.98 +0 0 0 1.125 132.99 +0 0 1 1.125 132.100 +0 1 1 1.227 132.101 +0 0 1 1.259 132.102 +0 1 1 1.371 132.103 +0 0 1 1.409 132.104 +0 1 1 1.513 132.105 +0 0 1 1.565 132.106 +0 1 1 1.667 132.107 +0 0 1 1.713 132.108 +0 1 1 1.733 132.109 +0 0 1 1.823 132.110 +0 1 1 1.843 132.111 +0 0 1 1.867 132.112 +0 1 1 1.979 132.113 +0 0 1 2.095 132.114 +0 1 1 2.197 132.115 +0 0 1 2.233 132.116 +0 1 1 2.253 132.117 +0 0 1 2.297 132.118 +0 1 1 2.405 132.119 +0 0 1 2.445 132.120 +0 1 1 2.463 132.121 +0 0 1 2.557 132.122 +0 1 1 2.593 132.123 +0 0 1 2.617 132.124 +0 1 1 2.729 132.125 +0 0 1 2.751 132.126 +0 1 1 2.771 132.127 +0 0 1 2.861 132.128 +0 1 1 2.881 132.129 +0 0 1 2.881 132.130 +0 0 0 2.881 132.131 +0 1 0 2.861 132.132 +0 0 0 2.771 132.133 +0 1 0 2.751 132.134 +0 0 0 2.729 132.135 +0 1 0 2.617 132.136 +0 0 0 2.593 132.137 +0 1 0 2.555 132.138 +0 0 0 2.463 132.139 +0 1 0 2.445 132.140 +0 0 0 2.407 132.141 +0 1 0 2.295 132.142 +0 0 0 2.253 132.143 +0 1 0 2.233 132.144 +0 0 0 2.199 132.145 +0 1 0 2.093 132.146 +0 0 0 1.979 132.147 +0 1 0 1.867 132.148 +0 0 0 1.843 132.149 +0 1 0 1.823 132.150 +0 0 0 1.733 132.151 +0 1 0 1.713 132.152 +0 0 0 1.671 132.153 +0 1 0 1.561 132.154 +0 0 0 1.517 132.155 +0 1 0 1.405 132.156 +0 0 0 1.371 132.157 +0 1 0 1.259 132.158 +0 0 0 1.229 132.159 +0 1 0 1.123 132.160 +0 0 0 1.121 132.161 +0 0 1 1.121 132.162 +0 1 1 1.231 132.163 +0 0 1 1.259 132.164 +0 1 1 1.371 132.165 +0 0 1 1.403 132.166 +0 1 1 1.519 132.167 +0 0 1 1.559 132.168 +0 1 1 1.673 132.169 +0 0 1 1.713 132.170 +0 1 1 1.733 132.171 +0 0 1 1.823 132.172 +0 1 1 1.843 132.173 +0 0 1 1.867 132.174 +0 1 1 1.979 132.175 +0 0 1 2.091 132.176 +0 1 1 2.201 132.177 +0 0 1 2.233 132.178 +0 1 1 2.253 132.179 +0 0 1 2.291 132.180 +0 1 1 2.411 132.181 +0 0 1 2.445 132.182 +0 1 1 2.463 132.183 +0 0 1 2.555 132.184 +0 1 1 2.593 132.185 +0 0 1 2.617 132.186 +0 1 1 2.729 132.187 +0 0 1 2.751 132.188 +0 1 1 2.771 132.189 +0 0 1 2.861 132.190 +0 1 1 2.881 132.191 +0 0 1 2.881 132.192 +0 0 0 2.881 132.193 +0 1 0 2.861 132.194 +0 0 0 2.771 132.195 +0 1 0 2.751 132.196 +0 0 0 2.729 132.197 +0 1 0 2.617 132.198 +0 0 0 2.593 132.199 +0 1 0 2.553 132.200 +0 0 0 2.463 132.201 +0 1 0 2.445 132.202 +0 0 0 2.411 132.203 +0 1 0 2.289 132.204 +0 0 0 2.253 132.205 +0 1 0 2.233 132.206 +0 0 0 2.203 132.207 +0 1 0 2.089 132.208 +0 0 0 1.979 132.209 +0 1 0 1.867 132.210 +0 0 0 1.843 132.211 +0 1 0 1.823 132.212 +0 0 0 1.733 132.213 +0 1 0 1.713 132.214 +0 0 0 1.675 132.215 +0 1 0 1.557 132.216 +0 0 0 1.519 132.217 +0 1 0 1.401 132.218 +0 0 0 1.371 132.219 +0 1 0 1.259 132.220 +0 0 0 1.233 132.221 +0 1 0 1.119 132.222 +0 0 0 1.117 132.223 +0 0 1 1.117 132.224 +0 1 1 1.235 132.225 +0 0 1 1.259 132.226 +0 1 1 1.371 132.227 +0 0 1 1.399 132.228 +0 1 1 1.521 132.229 +0 0 1 1.555 132.230 +0 1 1 1.677 132.231 +0 0 1 1.713 132.232 +0 1 1 1.733 132.233 +0 0 1 1.823 132.234 +0 1 1 1.843 132.235 +0 0 1 1.867 132.236 +0 1 1 1.979 132.237 +0 0 1 2.087 132.238 +0 1 1 2.205 132.239 +0 0 1 2.233 132.240 +0 1 1 2.253 132.241 +0 0 1 2.289 132.242 +0 1 1 2.413 132.243 +0 0 1 2.445 132.244 +0 1 1 2.463 132.245 +0 0 1 2.551 132.246 +0 1 1 2.593 132.247 +0 0 1 2.617 132.248 +0 1 1 2.729 132.249 +0 0 1 2.751 132.250 +0 1 1 2.771 132.251 +0 0 1 2.861 132.252 +0 1 1 2.881 132.253 +0 0 1 2.881 132.254 +0 0 0 2.881 132.255 +0 1 0 2.861 132.256 +0 0 0 2.771 132.257 +0 1 0 2.751 132.258 +0 0 0 2.729 132.259 +0 1 0 2.617 132.260 +0 0 0 2.593 132.261 +0 1 0 2.551 132.262 +0 0 0 2.463 132.263 +0 1 0 2.445 132.264 +0 0 0 2.413 132.265 +0 1 0 2.379 132.266 +0 0 0 2.327 132.267 +0 1 0 2.287 132.268 +0 0 0 2.253 132.269 +0 1 0 2.233 132.270 +0 0 0 2.205 132.271 +0 1 0 2.171 132.272 +0 0 0 2.121 132.273 +0 1 0 2.087 132.274 +0 0 0 1.979 132.275 +0 1 0 1.867 132.276 +0 0 0 1.843 132.277 +0 1 0 1.823 132.278 +0 0 0 1.733 132.279 +0 1 0 1.713 132.280 +0 0 0 1.677 132.281 +0 1 0 1.641 132.282 +0 0 0 1.591 132.283 +0 1 0 1.555 132.284 +0 0 0 1.521 132.285 +0 1 0 1.485 132.286 +0 0 0 1.437 132.287 +0 1 0 1.397 132.288 +0 0 0 1.369 132.289 +0 1 0 1.259 132.290 +0 0 0 1.235 132.291 +0 1 0 1.199 132.292 +0 0 0 1.151 132.293 +0 1 0 1.117 132.294 +0 0 0 1.115 132.295 +0 0 1 1.115 132.296 +0 1 1 1.141 132.297 +0 0 1 1.211 132.298 +0 1 1 1.237 132.299 +0 0 1 1.259 132.300 +0 1 1 1.279 132.301 +0 0 1 1.397 132.302 +0 1 1 1.427 132.303 +0 0 1 1.495 132.304 +0 1 1 1.523 132.305 +0 0 1 1.553 132.306 +0 1 1 1.581 132.307 +0 0 1 1.651 132.308 +0 1 1 1.679 132.309 +0 0 1 1.713 132.310 +0 1 1 1.733 132.311 +0 0 1 1.823 132.312 +0 1 1 1.843 132.313 +0 0 1 1.867 132.314 +0 1 1 1.887 132.315 +0 0 1 2.085 132.316 +0 1 1 2.111 132.317 +0 0 1 2.181 132.318 +0 1 1 2.207 132.319 +0 0 1 2.233 132.320 +0 1 1 2.253 132.321 +0 0 1 2.285 132.322 +0 1 1 2.315 132.323 +0 0 1 2.387 132.324 +0 1 1 2.415 132.325 +0 0 1 2.445 132.326 +0 1 1 2.463 132.327 +0 0 1 2.549 132.328 +0 1 1 2.571 132.329 +0 0 1 2.573 132.330 +0 1 1 2.593 132.331 +0 0 1 2.617 132.332 +0 1 1 2.637 132.333 +0 0 1 2.751 132.334 +0 1 1 2.771 132.335 +0 0 1 2.861 132.336 +0 1 1 2.881 132.337 +0 0 1 2.881 132.338 +0 0 0 2.881 132.339 +0 1 0 2.861 132.340 +0 0 0 2.771 132.341 +0 1 0 2.751 132.342 +0 0 0 2.637 132.343 +0 1 0 2.617 132.344 +0 0 0 2.593 132.345 +0 1 0 2.573 132.346 +0 0 0 2.571 132.347 +0 1 0 2.549 132.348 +0 0 0 2.463 132.349 +0 1 0 2.445 132.350 +0 0 0 2.415 132.351 +0 1 0 2.393 132.352 +0 0 0 2.309 132.353 +0 1 0 2.285 132.354 +0 0 0 2.253 132.355 +0 1 0 2.233 132.356 +0 0 0 2.207 132.357 +0 1 0 2.185 132.358 +0 0 0 2.107 132.359 +0 1 0 2.085 132.360 +0 0 0 1.887 132.361 +0 1 0 1.867 132.362 +0 0 0 1.843 132.363 +0 1 0 1.823 132.364 +0 0 0 1.733 132.365 +0 1 0 1.713 132.366 +0 0 0 1.679 132.367 +0 1 0 1.655 132.368 +0 0 0 1.577 132.369 +0 1 0 1.551 132.370 +0 0 0 1.523 132.371 +0 1 0 1.499 132.372 +0 0 0 1.421 132.373 +0 1 0 1.395 132.374 +0 0 0 1.279 132.375 +0 1 0 1.259 132.376 +0 0 0 1.237 132.377 +0 1 0 1.215 132.378 +0 0 0 1.137 132.379 +0 1 0 1.115 132.380 +0 0 0 1.113 132.381 +0 0 1 1.113 132.382 +0 1 1 1.135 132.383 +0 0 1 1.217 132.384 +0 1 1 1.239 132.385 +0 0 1 1.259 132.386 +0 1 1 1.279 132.387 +0 0 1 1.395 132.388 +0 1 1 1.419 132.389 +0 0 1 1.501 132.390 +0 1 1 1.525 132.391 +0 0 1 1.551 132.392 +0 1 1 1.573 132.393 +0 0 1 1.657 132.394 +0 1 1 1.681 132.395 +0 0 1 1.713 132.396 +0 1 1 1.733 132.397 +0 0 1 1.823 132.398 +0 1 1 1.843 132.399 +0 0 1 1.867 132.400 +0 1 1 1.887 132.401 +0 0 1 2.083 132.402 +0 1 1 2.105 132.403 +0 0 1 2.187 132.404 +0 1 1 2.209 132.405 +0 0 1 2.233 132.406 +0 1 1 2.253 132.407 +0 0 1 2.283 132.408 +0 1 1 2.305 132.409 +0 0 1 2.395 132.410 +0 1 1 2.417 132.411 +0 0 1 2.445 132.412 +0 1 1 2.463 132.413 +0 0 1 2.547 132.414 +0 1 1 2.569 132.415 +0 0 1 2.573 132.416 +0 1 1 2.593 132.417 +0 0 1 2.617 132.418 +0 1 1 2.637 132.419 +0 0 1 2.751 132.420 +0 1 1 2.771 132.421 +0 0 1 2.861 132.422 +0 1 1 2.881 132.423 +0 0 1 2.881 132.424 +0 0 0 2.881 132.425 +0 1 0 2.861 132.426 +0 0 0 2.771 132.427 +0 1 0 2.751 132.428 +0 0 0 2.637 132.429 +0 1 0 2.617 132.430 +0 0 0 2.593 132.431 +0 1 0 2.573 132.432 +0 0 0 2.567 132.433 +0 1 0 2.545 132.434 +0 0 0 2.463 132.435 +0 1 0 2.445 132.436 +0 0 0 2.417 132.437 +0 1 0 2.397 132.438 +0 0 0 2.303 132.439 +0 1 0 2.283 132.440 +0 0 0 2.253 132.441 +0 1 0 2.233 132.442 +0 0 0 2.209 132.443 +0 1 0 2.189 132.444 +0 0 0 2.105 132.445 +0 1 0 2.083 132.446 +0 0 0 1.887 132.447 +0 1 0 1.867 132.448 +0 0 0 1.843 132.449 +0 1 0 1.823 132.450 +0 0 0 1.733 132.451 +0 1 0 1.713 132.452 +0 0 0 1.681 132.453 +0 1 0 1.659 132.454 +0 0 0 1.573 132.455 +0 1 0 1.551 132.456 +0 0 0 1.525 132.457 +0 1 0 1.503 132.458 +0 0 0 1.417 132.459 +0 1 0 1.393 132.460 +0 0 0 1.279 132.461 +0 1 0 1.259 132.462 +0 0 0 1.239 132.463 +0 1 0 1.219 132.464 +0 0 0 1.135 132.465 +0 1 0 1.113 132.466 +0 0 0 1.113 132.467 +0 0 1 1.113 132.468 +0 1 1 1.133 132.469 +0 0 1 1.219 132.470 +0 1 1 1.239 132.471 +0 0 1 1.259 132.472 +0 1 1 1.279 132.473 +0 0 1 1.393 132.474 +0 1 1 1.415 132.475 +0 0 1 1.505 132.476 +0 1 1 1.525 132.477 +0 0 1 1.549 132.478 +0 1 1 1.571 132.479 +0 0 1 1.661 132.480 +0 1 1 1.681 132.481 +0 0 1 1.713 132.482 +0 1 1 1.733 132.483 +0 0 1 1.823 132.484 +0 1 1 1.843 132.485 +0 0 1 1.867 132.486 +0 1 1 1.887 132.487 +0 0 1 2.083 132.488 +0 1 1 2.103 132.489 +0 0 1 2.189 132.490 +0 1 1 2.209 132.491 +0 0 1 2.233 132.492 +0 1 1 2.253 132.493 +0 0 1 2.283 132.494 +0 1 1 2.303 132.495 +0 0 1 2.397 132.496 +0 1 1 2.417 132.497 +0 0 1 2.445 132.498 +0 1 1 2.463 132.499 +0 0 1 2.545 132.500 +0 1 1 2.567 132.501 +0 0 1 2.573 132.502 +0 1 1 2.593 132.503 +0 0 1 2.617 132.504 +0 1 1 2.637 132.505 +0 0 1 2.751 132.506 +0 1 1 2.771 132.507 +0 0 1 2.861 132.508 +0 1 1 2.881 132.509 +0 0 1 2.881 132.510 +0 0 0 2.881 132.511 +0 1 0 2.861 132.512 +0 0 0 2.771 132.513 +0 1 0 2.751 132.514 +0 0 0 2.637 132.515 +0 1 0 2.617 132.516 +0 0 0 2.593 132.517 +0 1 0 2.573 132.518 +0 0 0 2.565 132.519 +0 1 0 2.543 132.520 +0 0 0 2.463 132.521 +0 1 0 2.445 132.522 +0 0 0 2.417 132.523 +0 1 0 2.399 132.524 +0 0 0 2.301 132.525 +0 1 0 2.281 132.526 +0 0 0 2.253 132.527 +0 1 0 2.233 132.528 +0 0 0 2.209 132.529 +0 1 0 2.191 132.530 +0 0 0 2.103 132.531 +0 1 0 2.083 132.532 +0 0 0 1.887 132.533 +0 1 0 1.867 132.534 +0 0 0 1.843 132.535 +0 1 0 1.823 132.536 +0 0 0 1.733 132.537 +0 1 0 1.713 132.538 +0 0 0 1.683 132.539 +0 1 0 1.661 132.540 +0 0 0 1.569 132.541 +0 1 0 1.549 132.542 +0 0 0 1.525 132.543 +0 1 0 1.505 132.544 +0 0 0 1.413 132.545 +0 1 0 1.393 132.546 +0 0 0 1.279 132.547 +0 1 0 1.259 132.548 +0 0 0 1.239 132.549 +0 1 0 1.219 132.550 +0 0 0 1.133 132.551 +0 1 0 1.113 132.552 +0 0 0 1.111 132.553 +0 0 1 1.111 132.554 +0 1 1 1.131 132.555 +0 0 1 1.221 132.556 +0 1 1 1.239 132.557 +0 0 1 1.259 132.558 +0 1 1 1.279 132.559 +0 0 1 1.393 132.560 +0 1 1 1.413 132.561 +0 0 1 1.505 132.562 +0 1 1 1.525 132.563 +0 0 1 1.549 132.564 +0 1 1 1.569 132.565 +0 0 1 1.663 132.566 +0 1 1 1.683 132.567 +0 0 1 1.713 132.568 +0 1 1 1.733 132.569 +0 0 1 1.823 132.570 +0 1 1 1.843 132.571 +0 0 1 1.867 132.572 +0 1 1 1.887 132.573 +0 0 1 2.083 132.574 +0 1 1 2.101 132.575 +0 0 1 2.191 132.576 +0 1 1 2.211 132.577 +0 0 1 2.233 132.578 +0 1 1 2.253 132.579 +0 0 1 2.281 132.580 +0 1 1 2.301 132.581 +0 0 1 2.399 132.582 +0 1 1 2.419 132.583 +0 0 1 2.445 132.584 +0 1 1 2.463 132.585 +0 0 1 2.541 132.586 +0 1 1 2.565 132.587 +0 0 1 2.573 132.588 +0 1 1 2.593 132.589 +0 0 1 2.617 132.590 +0 1 1 2.637 132.591 +0 0 1 2.751 132.592 +0 1 1 2.771 132.593 +0 0 1 2.861 132.594 +0 1 1 2.881 132.595 +0 0 1 2.881 132.596 +0 0 0 2.881 132.597 +0 1 0 2.861 132.598 +0 0 0 2.771 132.599 +0 1 0 2.751 132.600 +0 0 0 2.637 132.601 +0 1 0 2.617 132.602 +0 0 0 2.593 132.603 +0 1 0 2.573 132.604 +0 0 0 2.563 132.605 +0 1 0 2.541 132.606 +0 0 0 2.463 132.607 +0 1 0 2.445 132.608 +0 0 0 2.419 132.609 +0 1 0 2.399 132.610 +0 0 0 2.299 132.611 +0 1 0 2.281 132.612 +0 0 0 2.253 132.613 +0 1 0 2.233 132.614 +0 0 0 2.211 132.615 +0 1 0 2.191 132.616 +0 0 0 2.101 132.617 +0 1 0 2.081 132.618 +0 0 0 1.887 132.619 +0 1 0 1.867 132.620 +0 0 0 1.843 132.621 +0 1 0 1.823 132.622 +0 0 0 1.733 132.623 +0 1 0 1.713 132.624 +0 0 0 1.683 132.625 +0 1 0 1.663 132.626 +0 0 0 1.569 132.627 +0 1 0 1.549 132.628 +0 0 0 1.527 132.629 +0 1 0 1.507 132.630 +0 0 0 1.413 132.631 +0 1 0 1.391 132.632 +0 0 0 1.279 132.633 +0 1 0 1.259 132.634 +0 0 0 1.241 132.635 +0 1 0 1.221 132.636 +0 0 0 1.131 132.637 +0 1 0 1.111 132.638 +0 0 0 1.111 132.639 +0 0 1 1.111 132.640 +0 1 1 1.131 132.641 +0 0 1 1.221 132.642 +0 1 1 1.241 132.643 +0 0 1 1.259 132.644 +0 1 1 1.279 132.645 +0 0 1 1.391 132.646 +0 1 1 1.411 132.647 +0 0 1 1.507 132.648 +0 1 1 1.527 132.649 +0 0 1 1.549 132.650 +0 1 1 1.569 132.651 +0 0 1 1.663 132.652 +0 1 1 1.683 132.653 +0 0 1 1.713 132.654 +0 1 1 1.733 132.655 +0 0 1 1.823 132.656 +0 1 1 1.843 132.657 +0 0 1 1.867 132.658 +0 1 1 1.887 132.659 +0 0 1 2.081 132.660 +0 1 1 2.101 132.661 +0 0 1 2.191 132.662 +0 1 1 2.211 132.663 +0 0 1 2.233 132.664 +0 1 1 2.253 132.665 +0 0 1 2.281 132.666 +0 1 1 2.299 132.667 +0 0 1 2.401 132.668 +0 1 1 2.419 132.669 +0 0 1 2.445 132.670 +0 1 1 2.463 132.671 +0 0 1 2.539 132.672 +0 1 1 2.561 132.673 +0 0 1 2.573 132.674 +0 1 1 2.593 132.675 +0 0 1 2.617 132.676 +0 1 1 2.637 132.677 +0 0 1 2.751 132.678 +0 1 1 2.771 132.679 +0 0 1 2.861 132.680 +0 1 1 2.881 132.681 +0 0 1 2.881 132.682 +0 0 0 2.881 132.683 +0 1 0 2.861 132.684 +0 0 0 2.771 132.685 +0 1 0 2.751 132.686 +0 0 0 2.637 132.687 +0 1 0 2.617 132.688 +0 0 0 2.593 132.689 +0 1 0 2.573 132.690 +0 0 0 2.561 132.691 +0 1 0 2.539 132.692 +0 0 0 2.463 132.693 +0 1 0 2.445 132.694 +0 0 0 2.419 132.695 +0 1 0 2.401 132.696 +0 0 0 2.299 132.697 +0 1 0 2.281 132.698 +0 0 0 2.253 132.699 +0 1 0 2.233 132.700 +0 0 0 2.211 132.701 +0 1 0 2.191 132.702 +0 0 0 2.101 132.703 +0 1 0 2.081 132.704 +0 0 0 1.887 132.705 +0 1 0 1.867 132.706 +0 0 0 1.843 132.707 +0 1 0 1.823 132.708 +0 0 0 1.733 132.709 +0 1 0 1.713 132.710 +0 0 0 1.683 132.711 +0 1 0 1.663 132.712 +0 0 0 1.567 132.713 +0 1 0 1.547 132.714 +0 0 0 1.527 132.715 +0 1 0 1.507 132.716 +0 0 0 1.411 132.717 +0 1 0 1.391 132.718 +0 0 0 1.279 132.719 +0 1 0 1.259 132.720 +0 0 0 1.241 132.721 +0 1 0 1.221 132.722 +0 0 0 1.131 132.723 +0 1 0 1.111 132.724 +0 0 0 1.111 132.725 +0 0 1 1.111 132.726 +0 1 1 1.131 132.727 +0 0 1 1.221 132.728 +0 1 1 1.241 132.729 +0 0 1 1.259 132.730 +0 1 1 1.279 132.731 +0 0 1 1.391 132.732 +0 1 1 1.411 132.733 +0 0 1 1.507 132.734 +0 1 1 1.527 132.735 +0 0 1 1.547 132.736 +0 1 1 1.567 132.737 +0 0 1 1.665 132.738 +0 1 1 1.683 132.739 +0 0 1 1.713 132.740 +0 1 1 1.733 132.741 +0 0 1 1.823 132.742 +0 1 1 1.843 132.743 +0 0 1 1.867 132.744 +0 1 1 1.887 132.745 +0 0 1 2.081 132.746 +0 1 1 2.101 132.747 +0 0 1 2.193 132.748 +0 1 1 2.211 132.749 +0 0 1 2.233 132.750 +0 1 1 2.253 132.751 +0 0 1 2.279 132.752 +0 1 1 2.297 132.753 +0 0 1 2.401 132.754 +0 1 1 2.419 132.755 +0 0 1 2.445 132.756 +0 1 1 2.463 132.757 +0 0 1 2.537 132.758 +0 1 1 2.559 132.759 +0 0 1 2.573 132.760 +0 1 1 2.593 132.761 +0 0 1 2.617 132.762 +0 1 1 2.637 132.763 +0 0 1 2.751 132.764 +0 1 1 2.771 132.765 +0 0 1 2.861 132.766 +0 1 1 2.881 132.767 +0 0 1 2.881 132.768 +0 0 0 2.881 132.769 +0 1 0 2.861 132.770 +0 0 0 2.771 132.771 +0 1 0 2.751 132.772 +0 0 0 2.637 132.773 +0 1 0 2.617 132.774 +0 0 0 2.593 132.775 +0 1 0 2.573 132.776 +0 0 0 2.557 132.777 +0 1 0 2.535 132.778 +0 0 0 2.463 132.779 +0 1 0 2.445 132.780 +0 0 0 2.419 132.781 +0 1 0 2.401 132.782 +0 0 0 2.297 132.783 +0 1 0 2.279 132.784 +0 0 0 2.253 132.785 +0 1 0 2.233 132.786 +0 0 0 2.211 132.787 +0 1 0 2.193 132.788 +0 0 0 2.101 132.789 +0 1 0 2.081 132.790 +0 0 0 1.887 132.791 +0 1 0 1.867 132.792 +0 0 0 1.843 132.793 +0 1 0 1.823 132.794 +0 0 0 1.733 132.795 +0 1 0 1.713 132.796 +0 0 0 1.685 132.797 +0 1 0 1.665 132.798 +0 0 0 1.567 132.799 +0 1 0 1.547 132.800 +0 0 0 1.527 132.801 +0 1 0 1.507 132.802 +0 0 0 1.411 132.803 +0 1 0 1.391 132.804 +0 0 0 1.279 132.805 +0 1 0 1.259 132.806 +0 0 0 1.241 132.807 +0 1 0 1.223 132.808 +0 0 0 1.131 132.809 +0 1 0 1.111 132.810 +0 0 0 1.111 132.811 +0 0 1 1.111 132.812 +0 1 1 1.131 132.813 +0 0 1 1.223 132.814 +0 1 1 1.241 132.815 +0 0 1 1.259 132.816 +0 1 1 1.279 132.817 +0 0 1 1.389 132.818 +0 1 1 1.411 132.819 +0 0 1 1.507 132.820 +0 1 1 1.527 132.821 +0 0 1 1.547 132.822 +0 1 1 1.567 132.823 +0 0 1 1.665 132.824 +0 1 1 1.685 132.825 +0 0 1 1.713 132.826 +0 1 1 1.733 132.827 +0 0 1 1.823 132.828 +0 1 1 1.843 132.829 +0 0 1 1.867 132.830 +0 1 1 1.887 132.831 +0 0 1 2.081 132.832 +0 1 1 2.101 132.833 +0 0 1 2.193 132.834 +0 1 1 2.211 132.835 +0 0 1 2.233 132.836 +0 1 1 2.253 132.837 +0 0 1 2.279 132.838 +0 1 1 2.297 132.839 +0 0 1 2.401 132.840 +0 1 1 2.419 132.841 +0 0 1 2.445 132.842 +0 1 1 2.463 132.843 +0 0 1 2.535 132.844 +0 1 1 2.557 132.845 +0 0 1 2.573 132.846 +0 1 1 2.593 132.847 +0 0 1 2.617 132.848 +0 1 1 2.637 132.849 +0 0 1 2.751 132.850 +0 1 1 2.771 132.851 +0 0 1 2.861 132.852 +0 1 1 2.881 132.853 +0 0 1 2.881 132.854 +0 0 0 2.881 132.855 +0 1 0 2.861 132.856 +0 0 0 2.771 132.857 +0 1 0 2.751 132.858 +0 0 0 2.637 132.859 +0 1 0 2.617 132.860 +0 0 0 2.593 132.861 +0 1 0 2.573 132.862 +0 0 0 2.555 132.863 +0 1 0 2.533 132.864 +0 0 0 2.463 132.865 +0 1 0 2.445 132.866 +0 0 0 2.419 132.867 +0 1 0 2.401 132.868 +0 0 0 2.297 132.869 +0 1 0 2.279 132.870 +0 0 0 2.253 132.871 +0 1 0 2.233 132.872 +0 0 0 2.211 132.873 +0 1 0 2.193 132.874 +0 0 0 2.101 132.875 +0 1 0 2.081 132.876 +0 0 0 1.887 132.877 +0 1 0 1.867 132.878 +0 0 0 1.843 132.879 +0 1 0 1.823 132.880 +0 0 0 1.733 132.881 +0 1 0 1.713 132.882 +0 0 0 1.685 132.883 +0 1 0 1.665 132.884 +0 0 0 1.567 132.885 +0 1 0 1.547 132.886 +0 0 0 1.527 132.887 +0 1 0 1.507 132.888 +0 0 0 1.411 132.889 +0 1 0 1.389 132.890 +0 0 0 1.279 132.891 +0 1 0 1.259 132.892 +0 0 0 1.241 132.893 +0 1 0 1.223 132.894 +0 0 0 1.131 132.895 +0 1 0 1.111 132.896 +0 0 0 1.111 132.897 +0 0 1 1.111 132.898 +0 1 1 1.131 132.899 +0 0 1 1.223 132.900 +0 1 1 1.241 132.901 +0 0 1 1.259 132.902 +0 1 1 1.279 132.903 +0 0 1 1.389 132.904 +0 1 1 1.409 132.905 +0 0 1 1.507 132.906 +0 1 1 1.527 132.907 +0 0 1 1.547 132.908 +0 1 1 1.567 132.909 +0 0 1 1.665 132.910 +0 1 1 1.685 132.911 +0 0 1 1.713 132.912 +0 1 1 1.733 132.913 +0 0 1 1.823 132.914 +0 1 1 1.843 132.915 +0 0 1 1.867 132.916 +0 1 1 1.887 132.917 +0 0 1 2.081 132.918 +0 1 1 2.101 132.919 +0 0 1 2.193 132.920 +0 1 1 2.211 132.921 +0 0 1 2.233 132.922 +0 1 1 2.253 132.923 +0 0 1 2.279 132.924 +0 1 1 2.297 132.925 +0 0 1 2.401 132.926 +0 1 1 2.421 132.927 +0 0 1 2.445 132.928 +0 1 1 2.463 132.929 +0 0 1 2.531 132.930 +0 1 1 2.555 132.931 +0 0 1 2.573 132.932 +0 1 1 2.593 132.933 +0 0 1 2.617 132.934 +0 1 1 2.637 132.935 +0 0 1 2.751 132.936 +0 1 1 2.771 132.937 +0 0 1 2.861 132.938 +0 1 1 2.881 132.939 +0 0 1 2.881 132.940 +0 0 0 2.881 132.941 +0 1 0 2.861 132.942 +0 0 0 2.771 132.943 +0 1 0 2.751 132.944 +0 0 0 2.637 132.945 +0 1 0 2.617 132.946 +0 0 0 2.593 132.947 +0 1 0 2.573 132.948 +0 0 0 2.553 132.949 +0 1 0 2.531 132.950 +0 0 0 2.463 132.951 +0 1 0 2.445 132.952 +0 0 0 2.421 132.953 +0 1 0 2.401 132.954 +0 0 0 2.297 132.955 +0 1 0 2.279 132.956 +0 0 0 2.253 132.957 +0 1 0 2.233 132.958 +0 0 0 2.211 132.959 +0 1 0 2.193 132.960 +0 0 0 2.101 132.961 +0 1 0 2.081 132.962 +0 0 0 1.887 132.963 +0 1 0 1.867 132.964 +0 0 0 1.843 132.965 +0 1 0 1.823 132.966 +0 0 0 1.733 132.967 +0 1 0 1.713 132.968 +0 0 0 1.685 132.969 +0 1 0 1.665 132.970 +0 0 0 1.567 132.971 +0 1 0 1.547 132.972 +0 0 0 1.527 132.973 +0 1 0 1.507 132.974 +0 0 0 1.409 132.975 +0 1 0 1.389 132.976 +0 0 0 1.279 132.977 +0 1 0 1.259 132.978 +0 0 0 1.241 132.979 +0 1 0 1.223 132.980 +0 0 0 1.129 132.981 +0 1 0 1.111 132.982 +0 0 0 1.111 132.983 +0 0 1 1.111 132.984 +0 1 1 1.129 132.985 +0 0 1 1.223 132.986 +0 1 1 1.241 132.987 +0 0 1 1.259 132.988 +0 1 1 1.279 132.989 +0 0 1 1.389 132.990 +0 1 1 1.409 132.991 +0 0 1 1.507 132.992 +0 1 1 1.527 132.993 +0 0 1 1.547 132.994 +0 1 1 1.567 132.995 +0 0 1 1.665 132.996 +0 1 1 1.685 132.997 +0 0 1 1.713 132.998 +0 1 1 1.733 132.999 +0 0 1 1.823 132.1000 +0 1 1 1.843 132.1001 +0 0 1 1.867 132.1002 +0 1 1 1.887 132.1003 +0 0 1 2.081 132.1004 +0 1 1 2.101 132.1005 +0 0 1 2.193 132.1006 +0 1 1 2.211 132.1007 +0 0 1 2.233 132.1008 +0 1 1 2.253 132.1009 +0 0 1 2.277 132.1010 +0 1 1 2.297 132.1011 +0 0 1 2.401 132.1012 +0 1 1 2.421 132.1013 +0 0 1 2.445 132.1014 +0 1 1 2.463 132.1015 +0 0 1 2.529 132.1016 +0 1 1 2.551 132.1017 +0 0 1 2.573 132.1018 +0 1 1 2.593 132.1019 +0 0 1 2.617 132.1020 +0 1 1 2.637 132.1021 +0 0 1 2.751 132.1022 +0 1 1 2.771 132.1023 +0 0 1 2.861 132.1024 +0 1 1 2.881 132.1025 +0 0 1 2.881 132.1026 +0 0 0 2.881 132.1027 +0 1 0 2.861 132.1028 +0 0 0 2.771 132.1029 +0 1 0 2.751 132.1030 +0 0 0 2.637 132.1031 +0 1 0 2.617 132.1032 +0 0 0 2.593 132.1033 +0 1 0 2.573 132.1034 +0 0 0 2.551 132.1035 +0 1 0 2.529 132.1036 +0 0 0 2.463 132.1037 +0 1 0 2.445 132.1038 +0 0 0 2.421 132.1039 +0 1 0 2.401 132.1040 +0 0 0 2.297 132.1041 +0 1 0 2.277 132.1042 +0 0 0 2.253 132.1043 +0 1 0 2.233 132.1044 +0 0 0 2.211 132.1045 +0 1 0 2.193 132.1046 +0 0 0 2.101 132.1047 +0 1 0 2.081 132.1048 +0 0 0 1.887 132.1049 +0 1 0 1.867 132.1050 +0 0 0 1.843 132.1051 +0 1 0 1.823 132.1052 +0 0 0 1.733 132.1053 +0 1 0 1.713 132.1054 +0 0 0 1.685 132.1055 +0 1 0 1.665 132.1056 +0 0 0 1.567 132.1057 +0 1 0 1.547 132.1058 +0 0 0 1.527 132.1059 +0 1 0 1.507 132.1060 +0 0 0 1.409 132.1061 +0 1 0 1.389 132.1062 +0 0 0 1.279 132.1063 +0 1 0 1.259 132.1064 +0 0 0 1.241 132.1065 +0 1 0 1.223 132.1066 +0 0 0 1.129 132.1067 +0 1 0 1.111 132.1068 +0 0 0 1.223 132.1069 +0 0 1 1.223 132.1070 +0 1 1 1.241 132.1071 +0 0 1 1.259 132.1072 +0 1 1 1.279 132.1073 +0 0 1 1.389 132.1074 +0 1 1 1.409 132.1075 +0 0 1 1.507 132.1076 +0 1 1 1.527 132.1077 +0 0 1 1.547 132.1078 +0 1 1 1.567 132.1079 +0 0 1 1.665 132.1080 +0 1 1 1.685 132.1081 +0 0 1 1.713 132.1082 +0 1 1 1.733 132.1083 +0 0 1 1.823 132.1084 +0 1 1 1.843 132.1085 +0 0 1 1.867 132.1086 +0 1 1 1.887 132.1087 +0 0 1 2.193 132.1088 +0 1 1 2.211 132.1089 +0 0 1 2.233 132.1090 +0 1 1 2.253 132.1091 +0 0 1 2.277 132.1092 +0 1 1 2.297 132.1093 +0 0 1 2.401 132.1094 +0 1 1 2.421 132.1095 +0 0 1 2.445 132.1096 +0 1 1 2.463 132.1097 +0 0 1 2.527 132.1098 +0 1 1 2.549 132.1099 +0 0 1 2.573 132.1100 +0 1 1 2.593 132.1101 +0 0 1 2.617 132.1102 +0 1 1 2.637 132.1103 +0 0 1 2.751 132.1104 +0 1 1 2.771 132.1105 +0 0 1 2.859 132.1106 +0 1 1 2.881 132.1107 +0 0 1 2.881 132.1108 +0 0 0 2.881 132.1109 +0 1 0 2.859 132.1110 +0 0 0 2.771 132.1111 +0 1 0 2.751 132.1112 +0 0 0 2.637 132.1113 +0 1 0 2.617 132.1114 +0 0 0 2.593 132.1115 +0 1 0 2.573 132.1116 +0 0 0 2.549 132.1117 +0 1 0 2.525 132.1118 +0 0 0 2.463 132.1119 +0 1 0 2.445 132.1120 +0 0 0 2.421 132.1121 +0 1 0 2.401 132.1122 +0 0 0 2.295 132.1123 +0 1 0 2.277 132.1124 +0 0 0 2.253 132.1125 +0 1 0 2.233 132.1126 +0 0 0 2.211 132.1127 +0 1 0 2.193 132.1128 +0 0 0 1.887 132.1129 +0 1 0 1.867 132.1130 +0 0 0 1.843 132.1131 +0 1 0 1.821 132.1132 +0 0 0 1.733 132.1133 +0 1 0 1.713 132.1134 +0 0 0 1.685 132.1135 +0 1 0 1.665 132.1136 +0 0 0 1.567 132.1137 +0 1 0 1.547 132.1138 +0 0 0 1.527 132.1139 +0 1 0 1.507 132.1140 +0 0 0 1.409 132.1141 +0 1 0 1.389 132.1142 +0 0 0 1.279 132.1143 +0 1 0 1.259 132.1144 +0 0 0 1.241 132.1145 +0 1 0 1.223 132.1146 +0 0 0 1.223 132.1147 +0 0 1 1.223 132.1148 +0 1 1 1.241 132.1149 +0 0 1 1.259 132.1150 +0 1 1 1.279 132.1151 +0 0 1 1.389 132.1152 +0 1 1 1.409 132.1153 +0 0 1 1.547 132.1154 +0 1 1 1.567 132.1155 +0 0 1 1.665 132.1156 +0 1 1 1.685 132.1157 +0 0 1 1.713 132.1158 +0 1 1 1.733 132.1159 +0 0 1 1.821 132.1160 +0 1 1 1.841 132.1161 +0 0 1 1.867 132.1162 +0 1 1 1.887 132.1163 +0 0 1 2.193 132.1164 +0 1 1 2.211 132.1165 +0 0 1 2.233 132.1166 +0 1 1 2.253 132.1167 +0 0 1 2.277 132.1168 +0 1 1 2.295 132.1169 +0 0 1 2.401 132.1170 +0 1 1 2.421 132.1171 +0 0 1 2.445 132.1172 +0 1 1 2.463 132.1173 +0 0 1 2.525 132.1174 +0 1 1 2.547 132.1175 +0 0 1 2.573 132.1176 +0 1 1 2.593 132.1177 +0 0 1 2.617 132.1178 +0 1 1 2.637 132.1179 +0 0 1 2.751 132.1180 +0 1 1 2.771 132.1181 +0 0 1 2.859 132.1182 +0 1 1 2.879 132.1183 +0 0 1 2.879 132.1184 +0 0 0 2.879 132.1185 +0 1 0 2.857 132.1186 +0 0 0 2.771 132.1187 +0 1 0 2.751 132.1188 +0 0 0 2.637 132.1189 +0 1 0 2.617 132.1190 +0 0 0 2.593 132.1191 +0 1 0 2.573 132.1192 +0 0 0 2.545 132.1193 +0 1 0 2.523 132.1194 +0 0 0 2.463 132.1195 +0 1 0 2.445 132.1196 +0 0 0 2.421 132.1197 +0 1 0 2.401 132.1198 +0 0 0 2.295 132.1199 +0 1 0 2.277 132.1200 +0 0 0 2.253 132.1201 +0 1 0 2.233 132.1202 +0 0 0 2.211 132.1203 +0 1 0 2.193 132.1204 +0 0 0 1.887 132.1205 +0 1 0 1.867 132.1206 +0 0 0 1.841 132.1207 +0 1 0 1.819 132.1208 +0 0 0 1.733 132.1209 +0 1 0 1.713 132.1210 +0 0 0 1.685 132.1211 +0 1 0 1.665 132.1212 +0 0 0 1.567 132.1213 +0 1 0 1.547 132.1214 +0 0 0 1.409 132.1215 +0 1 0 1.387 132.1216 +0 0 0 1.279 132.1217 +0 1 0 1.259 132.1218 +0 0 0 1.241 132.1219 +0 1 0 1.221 132.1220 +0 0 0 1.221 132.1221 +0 0 1 1.221 132.1222 +0 1 1 1.241 132.1223 +0 0 1 1.259 132.1224 +0 1 1 1.279 132.1225 +0 0 1 1.387 132.1226 +0 1 1 1.409 132.1227 +0 0 1 1.547 132.1228 +0 1 1 1.567 132.1229 +0 0 1 1.665 132.1230 +0 1 1 1.685 132.1231 +0 0 1 1.713 132.1232 +0 1 1 1.733 132.1233 +0 0 1 1.817 132.1234 +0 1 1 1.841 132.1235 +0 0 1 1.867 132.1236 +0 1 1 1.887 132.1237 +0 0 1 2.191 132.1238 +0 1 1 2.211 132.1239 +0 0 1 2.233 132.1240 +0 1 1 2.253 132.1241 +0 0 1 2.277 132.1242 +0 1 1 2.295 132.1243 +0 0 1 2.401 132.1244 +0 1 1 2.421 132.1245 +0 0 1 2.445 132.1246 +0 1 1 2.463 132.1247 +0 0 1 2.523 132.1248 +0 1 1 2.545 132.1249 +0 0 1 2.573 132.1250 +0 1 1 2.593 132.1251 +0 0 1 2.617 132.1252 +0 1 1 2.637 132.1253 +0 0 1 2.751 132.1254 +0 1 1 2.771 132.1255 +0 0 1 2.855 132.1256 +0 1 1 2.879 132.1257 +0 0 1 2.877 132.1258 +0 0 0 2.877 132.1259 +0 1 0 2.853 132.1260 +0 0 0 2.771 132.1261 +0 1 0 2.751 132.1262 +0 0 0 2.637 132.1263 +0 1 0 2.617 132.1264 +0 0 0 2.593 132.1265 +0 1 0 2.573 132.1266 +0 0 0 2.543 132.1267 +0 1 0 2.521 132.1268 +0 0 0 2.463 132.1269 +0 1 0 2.445 132.1270 +0 0 0 2.421 132.1271 +0 1 0 2.401 132.1272 +0 0 0 2.295 132.1273 +0 1 0 2.277 132.1274 +0 0 0 2.253 132.1275 +0 1 0 2.233 132.1276 +0 0 0 2.211 132.1277 +0 1 0 2.191 132.1278 +0 0 0 1.887 132.1279 +0 1 0 1.867 132.1280 +0 0 0 1.839 132.1281 +0 1 0 1.815 132.1282 +0 0 0 1.733 132.1283 +0 1 0 1.713 132.1284 +0 0 0 1.685 132.1285 +0 1 0 1.665 132.1286 +0 0 0 1.567 132.1287 +0 1 0 1.547 132.1288 +0 0 0 1.409 132.1289 +0 1 0 1.387 132.1290 +0 0 0 1.279 132.1291 +0 1 0 1.259 132.1292 +0 0 0 1.241 132.1293 +0 1 0 1.221 132.1294 +0 0 0 1.221 132.1295 +0 0 1 1.221 132.1296 +0 1 1 1.241 132.1297 +0 0 1 1.259 132.1298 +0 1 1 1.279 132.1299 +0 0 1 1.387 132.1300 +0 1 1 1.409 132.1301 +0 0 1 1.547 132.1302 +0 1 1 1.567 132.1303 +0 0 1 1.665 132.1304 +0 1 1 1.685 132.1305 +0 0 1 1.713 132.1306 +0 1 1 1.733 132.1307 +0 0 1 1.813 132.1308 +0 1 1 1.839 132.1309 +0 0 1 1.867 132.1310 +0 1 1 1.887 132.1311 +0 0 1 2.191 132.1312 +0 1 1 2.211 132.1313 +0 0 1 2.233 132.1314 +0 1 1 2.253 132.1315 +0 0 1 2.277 132.1316 +0 1 1 2.295 132.1317 +0 0 1 2.401 132.1318 +0 1 1 2.421 132.1319 +0 0 1 2.445 132.1320 +0 1 1 2.463 132.1321 +0 0 1 2.519 132.1322 +0 1 1 2.543 132.1323 +0 0 1 2.573 132.1324 +0 1 1 2.593 132.1325 +0 0 1 2.617 132.1326 +0 1 1 2.637 132.1327 +0 0 1 2.751 132.1328 +0 1 1 2.771 132.1329 +0 0 1 2.851 132.1330 +0 1 1 2.877 132.1331 +0 0 1 2.875 132.1332 +0 0 0 2.875 132.1333 +0 1 0 2.847 132.1334 +0 0 0 2.771 132.1335 +0 1 0 2.751 132.1336 +0 0 0 2.637 132.1337 +0 1 0 2.617 132.1338 +0 0 0 2.593 132.1339 +0 1 0 2.573 132.1340 +0 0 0 2.541 132.1341 +0 1 0 2.519 132.1342 +0 0 0 2.463 132.1343 +0 1 0 2.445 132.1344 +0 0 0 2.421 132.1345 +0 1 0 2.401 132.1346 +0 0 0 2.295 132.1347 +0 1 0 2.277 132.1348 +0 0 0 2.253 132.1349 +0 1 0 2.233 132.1350 +0 0 0 2.211 132.1351 +0 1 0 2.189 132.1352 +0 0 0 1.887 132.1353 +0 1 0 1.867 132.1354 +0 0 0 1.837 132.1355 +0 1 0 1.809 132.1356 +0 0 0 1.733 132.1357 +0 1 0 1.713 132.1358 +0 0 0 1.685 132.1359 +0 1 0 1.665 132.1360 +0 0 0 1.567 132.1361 +0 1 0 1.547 132.1362 +0 0 0 1.409 132.1363 +0 1 0 1.387 132.1364 +0 0 0 1.279 132.1365 +0 1 0 1.259 132.1366 +0 0 0 1.239 132.1367 +0 1 0 1.219 132.1368 +0 0 0 1.219 132.1369 +0 0 1 1.219 132.1370 +0 1 1 1.239 132.1371 +0 0 1 1.259 132.1372 +0 1 1 1.279 132.1373 +0 0 1 1.387 132.1374 +0 1 1 1.409 132.1375 +0 0 1 1.547 132.1376 +0 1 1 1.567 132.1377 +0 0 1 1.665 132.1378 +0 1 1 1.685 132.1379 +0 0 1 1.713 132.1380 +0 1 1 1.733 132.1381 +0 0 1 1.799 132.1382 +0 1 1 1.835 132.1383 +0 0 1 1.867 132.1384 +0 1 1 1.887 132.1385 +0 0 1 2.189 132.1386 +0 1 1 2.209 132.1387 +0 0 1 2.233 132.1388 +0 1 1 2.253 132.1389 +0 0 1 2.277 132.1390 +0 1 1 2.295 132.1391 +0 0 1 2.347 132.1392 +0 1 1 2.421 132.1393 +0 0 1 2.445 132.1394 +0 1 1 2.463 132.1395 +0 0 1 2.517 132.1396 +0 1 1 2.539 132.1397 +0 0 1 2.573 132.1398 +0 1 1 2.593 132.1399 +0 0 1 2.617 132.1400 +0 1 1 2.637 132.1401 +0 0 1 2.751 132.1402 +0 1 1 2.771 132.1403 +0 0 1 2.837 132.1404 +0 1 1 2.873 132.1405 +0 0 1 2.871 132.1406 +0 0 0 2.871 132.1407 +0 1 0 2.751 132.1408 +0 0 0 2.637 132.1409 +0 1 0 2.617 132.1410 +0 0 0 2.593 132.1411 +0 1 0 2.573 132.1412 +0 0 0 2.539 132.1413 +0 1 0 2.517 132.1414 +0 0 0 2.463 132.1415 +0 1 0 2.445 132.1416 +0 0 0 2.421 132.1417 +0 1 0 2.345 132.1418 +0 0 0 2.295 132.1419 +0 1 0 2.277 132.1420 +0 0 0 2.253 132.1421 +0 1 0 2.233 132.1422 +0 0 0 2.209 132.1423 +0 1 0 2.187 132.1424 +0 0 0 1.887 132.1425 +0 1 0 1.867 132.1426 +0 0 0 1.833 132.1427 +0 1 0 1.713 132.1428 +0 0 0 1.685 132.1429 +0 1 0 1.665 132.1430 +0 0 0 1.567 132.1431 +0 1 0 1.547 132.1432 +0 0 0 1.409 132.1433 +0 1 0 1.387 132.1434 +0 0 0 1.279 132.1435 +0 1 0 1.259 132.1436 +0 0 0 1.239 132.1437 +0 1 0 1.217 132.1438 +0 0 0 1.213 132.1439 +0 0 1 1.213 132.1440 +0 1 1 1.239 132.1441 +0 0 1 1.259 132.1442 +0 1 1 1.279 132.1443 +0 0 1 1.387 132.1444 +0 1 1 1.409 132.1445 +0 0 1 1.547 132.1446 +0 1 1 1.567 132.1447 +0 0 1 1.665 132.1448 +0 1 1 1.685 132.1449 +0 0 1 1.713 132.1450 +0 1 1 1.829 132.1451 +0 0 1 1.867 132.1452 +0 1 1 1.887 132.1453 +0 0 1 2.183 132.1454 +0 1 1 2.209 132.1455 +0 0 1 2.233 132.1456 +0 1 1 2.253 132.1457 +0 0 1 2.277 132.1458 +0 1 1 2.295 132.1459 +0 0 1 2.345 132.1460 +0 1 1 2.421 132.1461 +0 0 1 2.445 132.1462 +0 1 1 2.463 132.1463 +0 0 1 2.515 132.1464 +0 1 1 2.537 132.1465 +0 0 1 2.573 132.1466 +0 1 1 2.593 132.1467 +0 0 1 2.617 132.1468 +0 1 1 2.637 132.1469 +0 0 1 2.751 132.1470 +0 1 1 2.867 132.1471 +0 0 1 2.863 132.1472 +0 0 0 2.863 132.1473 +0 1 0 2.751 132.1474 +0 0 0 2.637 132.1475 +0 1 0 2.617 132.1476 +0 0 0 2.593 132.1477 +0 1 0 2.573 132.1478 +0 0 0 2.537 132.1479 +0 1 0 2.513 132.1480 +0 0 0 2.463 132.1481 +0 1 0 2.445 132.1482 +0 0 0 2.421 132.1483 +0 1 0 2.345 132.1484 +0 0 0 2.295 132.1485 +0 1 0 2.277 132.1486 +0 0 0 2.253 132.1487 +0 1 0 2.233 132.1488 +0 0 0 2.207 132.1489 +0 1 0 2.179 132.1490 +0 0 0 1.887 132.1491 +0 1 0 1.867 132.1492 +0 0 0 1.825 132.1493 +0 1 0 1.713 132.1494 +0 0 0 1.685 132.1495 +0 1 0 1.665 132.1496 +0 0 0 1.567 132.1497 +0 1 0 1.547 132.1498 +0 0 0 1.407 132.1499 +0 1 0 1.387 132.1500 +0 0 0 1.279 132.1501 +0 1 0 1.259 132.1502 +0 0 0 1.237 132.1503 +0 1 0 1.209 132.1504 +0 0 0 1.197 132.1505 +0 0 1 1.197 132.1506 +0 1 1 1.237 132.1507 +0 0 1 1.259 132.1508 +0 1 1 1.279 132.1509 +0 0 1 1.387 132.1510 +0 1 1 1.407 132.1511 +0 0 1 1.547 132.1512 +0 1 1 1.567 132.1513 +0 0 1 1.665 132.1514 +0 1 1 1.685 132.1515 +0 0 1 1.713 132.1516 +0 1 1 1.819 132.1517 +0 0 1 1.867 132.1518 +0 1 1 1.887 132.1519 +0 0 1 2.167 132.1520 +0 1 1 2.207 132.1521 +0 0 1 2.233 132.1522 +0 1 1 2.253 132.1523 +0 0 1 2.277 132.1524 +0 1 1 2.295 132.1525 +0 0 1 2.345 132.1526 +0 1 1 2.421 132.1527 +0 0 1 2.445 132.1528 +0 1 1 2.463 132.1529 +0 0 1 2.513 132.1530 +0 1 1 2.535 132.1531 +0 0 1 2.573 132.1532 +0 1 1 2.593 132.1533 +0 0 1 2.617 132.1534 +0 1 1 2.637 132.1535 +0 0 1 2.751 132.1536 +0 1 1 2.857 132.1537 +0 0 1 2.863 132.1538 +0 0 0 2.863 132.1539 +0 1 0 2.751 132.1540 +0 0 0 2.637 132.1541 +0 1 0 2.617 132.1542 +0 0 0 2.593 132.1543 +0 1 0 2.573 132.1544 +0 0 0 2.533 132.1545 +0 1 0 2.511 132.1546 +0 0 0 2.463 132.1547 +0 1 0 2.445 132.1548 +0 0 0 2.421 132.1549 +0 1 0 2.345 132.1550 +0 0 0 2.295 132.1551 +0 1 0 2.277 132.1552 +0 0 0 2.253 132.1553 +0 1 0 2.233 132.1554 +0 0 0 2.207 132.1555 +0 1 0 2.125 132.1556 +0 0 0 1.887 132.1557 +0 1 0 1.867 132.1558 +0 0 0 1.825 132.1559 +0 1 0 1.713 132.1560 +0 0 0 1.685 132.1561 +0 1 0 1.665 132.1562 +0 0 0 1.567 132.1563 +0 1 0 1.547 132.1564 +0 0 0 1.407 132.1565 +0 1 0 1.387 132.1566 +0 0 0 1.279 132.1567 +0 1 0 1.259 132.1568 +0 0 0 1.237 132.1569 +0 1 0 1.155 132.1570 +0 0 0 1.143 132.1571 +0 0 1 1.143 132.1572 +0 1 1 1.235 132.1573 +0 0 1 1.259 132.1574 +0 1 1 1.367 132.1575 +0 0 1 1.387 132.1576 +0 1 1 1.407 132.1577 +0 0 1 1.547 132.1578 +0 1 1 1.567 132.1579 +0 0 1 1.665 132.1580 +0 1 1 1.685 132.1581 +0 0 1 1.713 132.1582 +0 1 1 1.829 132.1583 +0 0 1 1.867 132.1584 +0 1 1 1.975 132.1585 +0 0 1 2.113 132.1586 +0 1 1 2.205 132.1587 +0 0 1 2.233 132.1588 +0 1 1 2.253 132.1589 +0 0 1 2.277 132.1590 +0 1 1 2.295 132.1591 +0 0 1 2.345 132.1592 +0 1 1 2.421 132.1593 +0 0 1 2.445 132.1594 +0 1 1 2.463 132.1595 +0 0 1 2.509 132.1596 +0 1 1 2.533 132.1597 +0 0 1 2.573 132.1598 +0 1 1 2.593 132.1599 +0 0 1 2.617 132.1600 +0 1 1 2.725 132.1601 +0 0 1 2.751 132.1602 +0 1 1 2.867 132.1603 +0 0 1 2.871 132.1604 +0 0 0 2.871 132.1605 +0 1 0 2.751 132.1606 +0 0 0 2.725 132.1607 +0 1 0 2.617 132.1608 +0 0 0 2.593 132.1609 +0 1 0 2.573 132.1610 +0 0 0 2.531 132.1611 +0 1 0 2.509 132.1612 +0 0 0 2.463 132.1613 +0 1 0 2.445 132.1614 +0 0 0 2.421 132.1615 +0 1 0 2.345 132.1616 +0 0 0 2.295 132.1617 +0 1 0 2.277 132.1618 +0 0 0 2.253 132.1619 +0 1 0 2.233 132.1620 +0 0 0 2.203 132.1621 +0 1 0 2.107 132.1622 +0 0 0 1.975 132.1623 +0 1 0 1.867 132.1624 +0 0 0 1.833 132.1625 +0 1 0 1.713 132.1626 +0 0 0 1.685 132.1627 +0 1 0 1.665 132.1628 +0 0 0 1.567 132.1629 +0 1 0 1.547 132.1630 +0 0 0 1.407 132.1631 +0 1 0 1.387 132.1632 +0 0 0 1.367 132.1633 +0 1 0 1.259 132.1634 +0 0 0 1.233 132.1635 +0 1 0 1.137 132.1636 +0 0 0 1.133 132.1637 +0 0 1 1.133 132.1638 +0 1 1 1.231 132.1639 +0 0 1 1.259 132.1640 +0 1 1 1.367 132.1641 +0 0 1 1.387 132.1642 +0 1 1 1.407 132.1643 +0 0 1 1.547 132.1644 +0 1 1 1.567 132.1645 +0 0 1 1.665 132.1646 +0 1 1 1.685 132.1647 +0 0 1 1.713 132.1648 +0 1 1 1.835 132.1649 +0 0 1 1.867 132.1650 +0 1 1 1.975 132.1651 +0 0 1 2.103 132.1652 +0 1 1 2.201 132.1653 +0 0 1 2.233 132.1654 +0 1 1 2.253 132.1655 +0 0 1 2.277 132.1656 +0 1 1 2.295 132.1657 +0 0 1 2.347 132.1658 +0 1 1 2.419 132.1659 +0 0 1 2.445 132.1660 +0 1 1 2.463 132.1661 +0 0 1 2.507 132.1662 +0 1 1 2.529 132.1663 +0 0 1 2.573 132.1664 +0 1 1 2.593 132.1665 +0 0 1 2.617 132.1666 +0 1 1 2.725 132.1667 +0 0 1 2.751 132.1668 +0 1 1 2.873 132.1669 +0 0 1 2.875 132.1670 +0 0 0 2.875 132.1671 +0 1 0 2.843 132.1672 +0 0 0 2.771 132.1673 +0 1 0 2.751 132.1674 +0 0 0 2.725 132.1675 +0 1 0 2.617 132.1676 +0 0 0 2.593 132.1677 +0 1 0 2.573 132.1678 +0 0 0 2.529 132.1679 +0 1 0 2.507 132.1680 +0 0 0 2.463 132.1681 +0 1 0 2.445 132.1682 +0 0 0 2.295 132.1683 +0 1 0 2.277 132.1684 +0 0 0 2.253 132.1685 +0 1 0 2.233 132.1686 +0 0 0 2.199 132.1687 +0 1 0 2.099 132.1688 +0 0 0 1.975 132.1689 +0 1 0 1.867 132.1690 +0 0 0 1.837 132.1691 +0 1 0 1.805 132.1692 +0 0 0 1.733 132.1693 +0 1 0 1.713 132.1694 +0 0 0 1.685 132.1695 +0 1 0 1.665 132.1696 +0 0 0 1.567 132.1697 +0 1 0 1.547 132.1698 +0 0 0 1.407 132.1699 +0 1 0 1.387 132.1700 +0 0 0 1.367 132.1701 +0 1 0 1.259 132.1702 +0 0 0 1.229 132.1703 +0 1 0 1.129 132.1704 +0 0 0 1.127 132.1705 +0 0 1 1.127 132.1706 +0 1 1 1.225 132.1707 +0 0 1 1.259 132.1708 +0 1 1 1.367 132.1709 +0 0 1 1.387 132.1710 +0 1 1 1.407 132.1711 +0 0 1 1.547 132.1712 +0 1 1 1.567 132.1713 +0 0 1 1.665 132.1714 +0 1 1 1.685 132.1715 +0 0 1 1.713 132.1716 +0 1 1 1.733 132.1717 +0 0 1 1.813 132.1718 +0 1 1 1.839 132.1719 +0 0 1 1.867 132.1720 +0 1 1 1.975 132.1721 +0 0 1 2.097 132.1722 +0 1 1 2.195 132.1723 +0 0 1 2.233 132.1724 +0 1 1 2.253 132.1725 +0 0 1 2.277 132.1726 +0 1 1 2.295 132.1727 +0 0 1 2.445 132.1728 +0 1 1 2.463 132.1729 +0 0 1 2.505 132.1730 +0 1 1 2.527 132.1731 +0 0 1 2.573 132.1732 +0 1 1 2.593 132.1733 +0 0 1 2.617 132.1734 +0 1 1 2.725 132.1735 +0 0 1 2.751 132.1736 +0 1 1 2.771 132.1737 +0 0 1 2.851 132.1738 +0 1 1 2.877 132.1739 +0 0 1 2.879 132.1740 +0 0 0 2.879 132.1741 +0 1 0 2.855 132.1742 +0 0 0 2.771 132.1743 +0 1 0 2.751 132.1744 +0 0 0 2.725 132.1745 +0 1 0 2.617 132.1746 +0 0 0 2.593 132.1747 +0 1 0 2.573 132.1748 +0 0 0 2.527 132.1749 +0 1 0 2.503 132.1750 +0 0 0 2.463 132.1751 +0 1 0 2.445 132.1752 +0 0 0 2.295 132.1753 +0 1 0 2.277 132.1754 +0 0 0 2.253 132.1755 +0 1 0 2.233 132.1756 +0 0 0 2.189 132.1757 +0 1 0 2.093 132.1758 +0 0 0 1.975 132.1759 +0 1 0 1.867 132.1760 +0 0 0 1.841 132.1761 +0 1 0 1.817 132.1762 +0 0 0 1.733 132.1763 +0 1 0 1.713 132.1764 +0 0 0 1.685 132.1765 +0 1 0 1.665 132.1766 +0 0 0 1.567 132.1767 +0 1 0 1.547 132.1768 +0 0 0 1.407 132.1769 +0 1 0 1.387 132.1770 +0 0 0 1.367 132.1771 +0 1 0 1.259 132.1772 +0 0 0 1.219 132.1773 +0 1 0 1.123 132.1774 +0 0 0 1.121 132.1775 +0 0 1 1.121 132.1776 +0 1 1 1.211 132.1777 +0 0 1 1.259 132.1778 +0 1 1 1.367 132.1779 +0 0 1 1.387 132.1780 +0 1 1 1.407 132.1781 +0 0 1 1.547 132.1782 +0 1 1 1.567 132.1783 +0 0 1 1.665 132.1784 +0 1 1 1.685 132.1785 +0 0 1 1.713 132.1786 +0 1 1 1.733 132.1787 +0 0 1 1.819 132.1788 +0 1 1 1.841 132.1789 +0 0 1 1.867 132.1790 +0 1 1 1.975 132.1791 +0 0 1 2.091 132.1792 +0 1 1 2.181 132.1793 +0 0 1 2.233 132.1794 +0 1 1 2.253 132.1795 +0 0 1 2.277 132.1796 +0 1 1 2.295 132.1797 +0 0 1 2.445 132.1798 +0 1 1 2.463 132.1799 +0 0 1 2.503 132.1800 +0 1 1 2.525 132.1801 +0 0 1 2.573 132.1802 +0 1 1 2.593 132.1803 +0 0 1 2.617 132.1804 +0 1 1 2.725 132.1805 +0 0 1 2.751 132.1806 +0 1 1 2.771 132.1807 +0 0 1 2.857 132.1808 +0 1 1 2.879 132.1809 +0 0 1 2.881 132.1810 +0 0 0 2.881 132.1811 +0 1 0 2.859 132.1812 +0 0 0 2.771 132.1813 +0 1 0 2.751 132.1814 +0 0 0 2.725 132.1815 +0 1 0 2.617 132.1816 +0 0 0 2.593 132.1817 +0 1 0 2.573 132.1818 +0 0 0 2.523 132.1819 +0 1 0 2.501 132.1820 +0 0 0 2.463 132.1821 +0 1 0 2.445 132.1822 +0 0 0 2.295 132.1823 +0 1 0 2.277 132.1824 +0 0 0 2.253 132.1825 +0 1 0 2.233 132.1826 +0 0 0 2.169 132.1827 +0 1 0 2.091 132.1828 +0 0 0 1.975 132.1829 +0 1 0 1.867 132.1830 +0 0 0 1.843 132.1831 +0 1 0 1.821 132.1832 +0 0 0 1.733 132.1833 +0 1 0 1.713 132.1834 +0 0 0 1.685 132.1835 +0 1 0 1.665 132.1836 +0 0 0 1.567 132.1837 +0 1 0 1.547 132.1838 +0 0 0 1.407 132.1839 +0 1 0 1.387 132.1840 +0 0 0 1.367 132.1841 +0 1 0 1.259 132.1842 +0 0 0 1.199 132.1843 +0 1 0 1.121 132.1844 +0 0 0 1.119 132.1845 +0 0 1 1.119 132.1846 +0 1 1 1.169 132.1847 +0 0 1 1.259 132.1848 +0 1 1 1.279 132.1849 +0 0 1 1.387 132.1850 +0 1 1 1.407 132.1851 +0 0 1 1.547 132.1852 +0 1 1 1.567 132.1853 +0 0 1 1.665 132.1854 +0 1 1 1.685 132.1855 +0 0 1 1.713 132.1856 +0 1 1 1.733 132.1857 +0 0 1 1.823 132.1858 +0 1 1 1.843 132.1859 +0 0 1 1.867 132.1860 +0 1 1 1.889 132.1861 +0 0 1 2.089 132.1862 +0 1 1 2.139 132.1863 +0 0 1 2.233 132.1864 +0 1 1 2.253 132.1865 +0 0 1 2.277 132.1866 +0 1 1 2.295 132.1867 +0 0 1 2.445 132.1868 +0 1 1 2.463 132.1869 +0 0 1 2.499 132.1870 +0 1 1 2.523 132.1871 +0 0 1 2.573 132.1872 +0 1 1 2.593 132.1873 +0 0 1 2.617 132.1874 +0 1 1 2.637 132.1875 +0 0 1 2.751 132.1876 +0 1 1 2.771 132.1877 +0 0 1 2.861 132.1878 +0 1 1 2.881 132.1879 +0 0 1 2.881 132.1880 +0 0 0 2.881 132.1881 +0 1 0 2.861 132.1882 +0 0 0 2.771 132.1883 +0 1 0 2.751 132.1884 +0 0 0 2.637 132.1885 +0 1 0 2.617 132.1886 +0 0 0 2.593 132.1887 +0 1 0 2.573 132.1888 +0 0 0 2.521 132.1889 +0 1 0 2.499 132.1890 +0 0 0 2.463 132.1891 +0 1 0 2.445 132.1892 +0 0 0 2.295 132.1893 +0 1 0 2.277 132.1894 +0 0 0 2.253 132.1895 +0 1 0 2.233 132.1896 +0 0 0 2.119 132.1897 +0 1 0 2.087 132.1898 +0 0 0 1.887 132.1899 +0 1 0 1.867 132.1900 +0 0 0 1.843 132.1901 +0 1 0 1.823 132.1902 +0 0 0 1.733 132.1903 +0 1 0 1.713 132.1904 +0 0 0 1.685 132.1905 +0 1 0 1.665 132.1906 +0 0 0 1.567 132.1907 +0 1 0 1.547 132.1908 +0 0 0 1.407 132.1909 +0 1 0 1.387 132.1910 +0 0 0 1.279 132.1911 +0 1 0 1.259 132.1912 +0 0 0 1.149 132.1913 +0 1 0 1.117 132.1914 +0 0 0 1.117 132.1915 +0 0 1 1.117 132.1916 +0 1 1 1.141 132.1917 +0 0 1 1.259 132.1918 +0 1 1 1.279 132.1919 +0 0 1 1.387 132.1920 +0 1 1 1.407 132.1921 +0 0 1 1.547 132.1922 +0 1 1 1.567 132.1923 +0 0 1 1.665 132.1924 +0 1 1 1.685 132.1925 +0 0 1 1.713 132.1926 +0 1 1 1.733 132.1927 +0 0 1 1.825 132.1928 +0 1 1 1.845 132.1929 +0 0 1 1.867 132.1930 +0 1 1 1.887 132.1931 +0 0 1 2.087 132.1932 +0 1 1 2.111 132.1933 +0 0 1 2.233 132.1934 +0 1 1 2.253 132.1935 +0 0 1 2.277 132.1936 +0 1 1 2.295 132.1937 +0 0 1 2.445 132.1938 +0 1 1 2.463 132.1939 +0 0 1 2.497 132.1940 +0 1 1 2.521 132.1941 +0 0 1 2.573 132.1942 +0 1 1 2.593 132.1943 +0 0 1 2.617 132.1944 +0 1 1 2.637 132.1945 +0 0 1 2.751 132.1946 +0 1 1 2.771 132.1947 +0 0 1 2.863 132.1948 +0 1 1 2.881 132.1949 +0 0 1 2.883 132.1950 +0 0 0 2.883 132.1951 +0 1 0 2.863 132.1952 +0 0 0 2.771 132.1953 +0 1 0 2.751 132.1954 +0 0 0 2.637 132.1955 +0 1 0 2.617 132.1956 +0 0 0 2.593 132.1957 +0 1 0 2.573 132.1958 +0 0 0 2.519 132.1959 +0 1 0 2.497 132.1960 +0 0 0 2.463 132.1961 +0 1 0 2.445 132.1962 +0 0 0 2.295 132.1963 +0 1 0 2.277 132.1964 +0 0 0 2.253 132.1965 +0 1 0 2.233 132.1966 +0 0 0 2.107 132.1967 +0 1 0 2.085 132.1968 +0 0 0 1.887 132.1969 +0 1 0 1.867 132.1970 +0 0 0 1.845 132.1971 +0 1 0 1.825 132.1972 +0 0 0 1.733 132.1973 +0 1 0 1.713 132.1974 +0 0 0 1.685 132.1975 +0 1 0 1.665 132.1976 +0 0 0 1.567 132.1977 +0 1 0 1.547 132.1978 +0 0 0 1.407 132.1979 +0 1 0 1.387 132.1980 +0 0 0 1.279 132.1981 +0 1 0 1.259 132.1982 +0 0 0 1.137 132.1983 +0 1 0 1.115 132.1984 +0 0 0 1.115 132.1985 +0 0 1 1.115 132.1986 +0 1 1 1.135 132.1987 +0 0 1 1.259 132.1988 +0 1 1 1.279 132.1989 +0 0 1 1.387 132.1990 +0 1 1 1.407 132.1991 +0 0 1 1.547 132.1992 +0 1 1 1.567 132.1993 +0 0 1 1.665 132.1994 +0 1 1 1.685 132.1995 +0 0 1 1.713 132.1996 +0 1 1 1.733 132.1997 +0 0 1 1.827 132.1998 +0 1 1 1.845 132.1999 +0 0 1 1.867 132.2000 +0 1 1 1.887 132.2001 +0 0 1 2.085 132.2002 +0 1 1 2.105 132.2003 +0 0 1 2.233 132.2004 +0 1 1 2.253 132.2005 +0 0 1 2.277 132.2006 +0 1 1 2.295 132.2007 +0 0 1 2.445 132.2008 +0 1 1 2.463 132.2009 +0 0 1 2.495 132.2010 +0 1 1 2.517 132.2011 +0 0 1 2.573 132.2012 +0 1 1 2.593 132.2013 +0 0 1 2.617 132.2014 +0 1 1 2.637 132.2015 +0 0 1 2.751 132.2016 +0 1 1 2.771 132.2017 +0 0 1 2.863 132.2018 +0 1 1 2.883 132.2019 +0 0 1 2.883 132.2020 +0 0 0 2.883 132.2021 +0 1 0 2.865 132.2022 +0 0 0 2.771 132.2023 +0 1 0 2.751 132.2024 +0 0 0 2.637 132.2025 +0 1 0 2.617 132.2026 +0 0 0 2.593 132.2027 +0 1 0 2.573 132.2028 +0 0 0 2.517 132.2029 +0 1 0 2.493 132.2030 +0 0 0 2.463 132.2031 +0 1 0 2.445 132.2032 +0 0 0 2.295 132.2033 +0 1 0 2.277 132.2034 +0 0 0 2.253 132.2035 +0 1 0 2.233 132.2036 +0 0 0 2.103 132.2037 +0 1 0 2.085 132.2038 +0 0 0 1.887 132.2039 +0 1 0 1.867 132.2040 +0 0 0 1.845 132.2041 +0 1 0 1.827 132.2042 +0 0 0 1.733 132.2043 +0 1 0 1.713 132.2044 +0 0 0 1.685 132.2045 +0 1 0 1.665 132.2046 +0 0 0 1.567 132.2047 +0 1 0 1.547 132.2048 +0 0 0 1.407 132.2049 +0 1 0 1.387 132.2050 +0 0 0 1.279 132.2051 +0 1 0 1.259 132.2052 +0 0 0 1.133 132.2053 +0 1 0 1.115 132.2054 +0 0 0 1.113 132.2055 +0 0 1 1.113 132.2056 +0 1 1 1.133 132.2057 +0 0 1 1.259 132.2058 +0 1 1 1.279 132.2059 +0 0 1 1.387 132.2060 +0 1 1 1.407 132.2061 +0 0 1 1.547 132.2062 +0 1 1 1.567 132.2063 +0 0 1 1.665 132.2064 +0 1 1 1.685 132.2065 +0 0 1 1.713 132.2066 +0 1 1 1.733 132.2067 +0 0 1 1.827 132.2068 +0 1 1 1.845 132.2069 +0 0 1 1.867 132.2070 +0 1 1 1.887 132.2071 +0 0 1 2.083 132.2072 +0 1 1 2.103 132.2073 +0 0 1 2.233 132.2074 +0 1 1 2.253 132.2075 +0 0 1 2.277 132.2076 +0 1 1 2.295 132.2077 +0 0 1 2.445 132.2078 +0 1 1 2.463 132.2079 +0 0 1 2.493 132.2080 +0 1 1 2.515 132.2081 +0 0 1 2.573 132.2082 +0 1 1 2.593 132.2083 +0 0 1 2.617 132.2084 +0 1 1 2.637 132.2085 +0 0 1 2.751 132.2086 +0 1 1 2.771 132.2087 +0 0 1 2.865 132.2088 +0 1 1 2.883 132.2089 +0 0 1 2.883 132.2090 +0 0 0 2.883 132.2091 +0 1 0 2.865 132.2092 +0 0 0 2.771 132.2093 +0 1 0 2.751 132.2094 +0 0 0 2.637 132.2095 +0 1 0 2.617 132.2096 +0 0 0 2.593 132.2097 +0 1 0 2.573 132.2098 +0 0 0 2.515 132.2099 +0 1 0 2.491 132.2100 +0 0 0 2.463 132.2101 +0 1 0 2.445 132.2102 +0 0 0 2.295 132.2103 +0 1 0 2.277 132.2104 +0 0 0 2.253 132.2105 +0 1 0 2.233 132.2106 +0 0 0 2.103 132.2107 +0 1 0 2.083 132.2108 +0 0 0 1.887 132.2109 +0 1 0 1.867 132.2110 +0 0 0 1.845 132.2111 +0 1 0 1.827 132.2112 +0 0 0 1.733 132.2113 +0 1 0 1.713 132.2114 +0 0 0 1.685 132.2115 +0 1 0 1.665 132.2116 +0 0 0 1.567 132.2117 +0 1 0 1.547 132.2118 +0 0 0 1.407 132.2119 +0 1 0 1.387 132.2120 +0 0 0 1.279 132.2121 +0 1 0 1.259 132.2122 +0 0 0 1.133 132.2123 +0 1 0 1.113 132.2124 +0 0 0 1.113 132.2125 +0 0 1 1.113 132.2126 +0 1 1 1.131 132.2127 +0 0 1 1.259 132.2128 +0 1 1 1.279 132.2129 +0 0 1 1.387 132.2130 +0 1 1 1.407 132.2131 +0 0 1 1.547 132.2132 +0 1 1 1.567 132.2133 +0 0 1 1.665 132.2134 +0 1 1 1.685 132.2135 +0 0 1 1.713 132.2136 +0 1 1 1.733 132.2137 +0 0 1 1.827 132.2138 +0 1 1 1.845 132.2139 +0 0 1 1.867 132.2140 +0 1 1 1.887 132.2141 +0 0 1 2.083 132.2142 +0 1 1 2.101 132.2143 +0 0 1 2.233 132.2144 +0 1 1 2.253 132.2145 +0 0 1 2.277 132.2146 +0 1 1 2.297 132.2147 +0 0 1 2.445 132.2148 +0 1 1 2.463 132.2149 +0 0 1 2.491 132.2150 +0 1 1 2.513 132.2151 +0 0 1 2.573 132.2152 +0 1 1 2.593 132.2153 +0 0 1 2.617 132.2154 +0 1 1 2.637 132.2155 +0 0 1 2.751 132.2156 +0 1 1 2.771 132.2157 +0 0 1 2.865 132.2158 +0 1 1 2.883 132.2159 +0 0 1 2.883 132.2160 +0 0 0 2.883 132.2161 +0 1 0 2.865 132.2162 +0 0 0 2.771 132.2163 +0 1 0 2.751 132.2164 +0 0 0 2.637 132.2165 +0 1 0 2.617 132.2166 +0 0 0 2.593 132.2167 +0 1 0 2.573 132.2168 +0 0 0 2.511 132.2169 +0 1 0 2.489 132.2170 +0 0 0 2.463 132.2171 +0 1 0 2.445 132.2172 +0 0 0 2.297 132.2173 +0 1 0 2.277 132.2174 +0 0 0 2.253 132.2175 +0 1 0 2.233 132.2176 +0 0 0 2.101 132.2177 +0 1 0 2.083 132.2178 +0 0 0 1.887 132.2179 +0 1 0 1.867 132.2180 +0 0 0 1.845 132.2181 +0 1 0 1.827 132.2182 +0 0 0 1.733 132.2183 +0 1 0 1.713 132.2184 +0 0 0 1.685 132.2185 +0 1 0 1.665 132.2186 +0 0 0 1.567 132.2187 +0 1 0 1.547 132.2188 +0 0 0 1.407 132.2189 +0 1 0 1.387 132.2190 +0 0 0 1.279 132.2191 +0 1 0 1.259 132.2192 +0 0 0 1.131 132.2193 +0 1 0 1.113 132.2194 +0 0 0 1.113 132.2195 +0 0 1 1.113 132.2196 +0 1 1 1.131 132.2197 +0 0 1 1.259 132.2198 +0 1 1 1.279 132.2199 +0 0 1 1.387 132.2200 +0 1 1 1.407 132.2201 +0 0 1 1.547 132.2202 +0 1 1 1.567 132.2203 +0 0 1 1.665 132.2204 +0 1 1 1.685 132.2205 +0 0 1 1.713 132.2206 +0 1 1 1.733 132.2207 +0 0 1 1.827 132.2208 +0 1 1 1.847 132.2209 +0 0 1 1.867 132.2210 +0 1 1 1.887 132.2211 +0 0 1 2.083 132.2212 +0 1 1 2.101 132.2213 +0 0 1 2.233 132.2214 +0 1 1 2.253 132.2215 +0 0 1 2.277 132.2216 +0 1 1 2.297 132.2217 +0 0 1 2.445 132.2218 +0 1 1 2.463 132.2219 +0 0 1 2.487 132.2220 +0 1 1 2.511 132.2221 +0 0 1 2.573 132.2222 +0 1 1 2.593 132.2223 +0 0 1 2.617 132.2224 +0 1 1 2.637 132.2225 +0 0 1 2.751 132.2226 +0 1 1 2.771 132.2227 +0 0 1 2.865 132.2228 +0 1 1 2.883 132.2229 +0 0 1 2.883 132.2230 +0 0 0 2.883 132.2231 +0 1 0 2.865 132.2232 +0 0 0 2.771 132.2233 +0 1 0 2.751 132.2234 +0 0 0 2.637 132.2235 +0 1 0 2.617 132.2236 +0 0 0 2.593 132.2237 +0 1 0 2.573 132.2238 +0 0 0 2.509 132.2239 +0 1 0 2.487 132.2240 +0 0 0 2.463 132.2241 +0 1 0 2.445 132.2242 +0 0 0 2.297 132.2243 +0 1 0 2.277 132.2244 +0 0 0 2.253 132.2245 +0 1 0 2.233 132.2246 +0 0 0 2.101 132.2247 +0 1 0 2.083 132.2248 +0 0 0 1.887 132.2249 +0 1 0 1.867 132.2250 +0 0 0 1.847 132.2251 +0 1 0 1.827 132.2252 +0 0 0 1.733 132.2253 +0 1 0 1.713 132.2254 +0 0 0 1.685 132.2255 +0 1 0 1.665 132.2256 +0 0 0 1.567 132.2257 +0 1 0 1.547 132.2258 +0 0 0 1.407 132.2259 +0 1 0 1.387 132.2260 +0 0 0 1.279 132.2261 +0 1 0 1.259 132.2262 +0 0 0 1.131 132.2263 +0 1 0 1.113 132.2264 +0 0 0 1.113 132.2265 +0 0 1 1.113 132.2266 +0 1 1 1.131 132.2267 +0 0 1 1.259 132.2268 +0 1 1 1.279 132.2269 +0 0 1 1.387 132.2270 +0 1 1 1.407 132.2271 +0 0 1 1.505 132.2272 +0 1 1 1.525 132.2273 +0 0 1 1.547 132.2274 +0 1 1 1.567 132.2275 +0 0 1 1.665 132.2276 +0 1 1 1.685 132.2277 +0 0 1 1.713 132.2278 +0 1 1 1.733 132.2279 +0 0 1 1.827 132.2280 +0 1 1 1.847 132.2281 +0 0 1 1.867 132.2282 +0 1 1 1.887 132.2283 +0 0 1 2.083 132.2284 +0 1 1 2.101 132.2285 +0 0 1 2.233 132.2286 +0 1 1 2.253 132.2287 +0 0 1 2.277 132.2288 +0 1 1 2.297 132.2289 +0 0 1 2.445 132.2290 +0 1 1 2.463 132.2291 +0 0 1 2.485 132.2292 +0 1 1 2.507 132.2293 +0 0 1 2.573 132.2294 +0 1 1 2.593 132.2295 +0 0 1 2.617 132.2296 +0 1 1 2.637 132.2297 +0 0 1 2.751 132.2298 +0 1 1 2.771 132.2299 +0 0 1 2.865 132.2300 +0 1 1 2.883 132.2301 +0 0 1 2.883 132.2302 +0 0 0 2.883 132.2303 +0 1 0 2.865 132.2304 +0 0 0 2.771 132.2305 +0 1 0 2.751 132.2306 +0 0 0 2.637 132.2307 +0 1 0 2.617 132.2308 +0 0 0 2.593 132.2309 +0 1 0 2.573 132.2310 +0 0 0 2.507 132.2311 +0 1 0 2.485 132.2312 +0 0 0 2.463 132.2313 +0 1 0 2.445 132.2314 +0 0 0 2.421 132.2315 +0 1 0 2.401 132.2316 +0 0 0 2.297 132.2317 +0 1 0 2.277 132.2318 +0 0 0 2.253 132.2319 +0 1 0 2.233 132.2320 +0 0 0 2.101 132.2321 +0 1 0 2.083 132.2322 +0 0 0 1.887 132.2323 +0 1 0 1.867 132.2324 +0 0 0 1.847 132.2325 +0 1 0 1.827 132.2326 +0 0 0 1.733 132.2327 +0 1 0 1.713 132.2328 +0 0 0 1.685 132.2329 +0 1 0 1.665 132.2330 +0 0 0 1.567 132.2331 +0 1 0 1.547 132.2332 +0 0 0 1.525 132.2333 +0 1 0 1.505 132.2334 +0 0 0 1.407 132.2335 +0 1 0 1.387 132.2336 +0 0 0 1.279 132.2337 +0 1 0 1.259 132.2338 +0 0 0 1.131 132.2339 +0 1 0 1.111 132.2340 +0 0 0 1.111 132.2341 +0 0 1 1.111 132.2342 +0 1 1 1.131 132.2343 +0 0 1 1.259 132.2344 +0 1 1 1.279 132.2345 +0 0 1 1.387 132.2346 +0 1 1 1.407 132.2347 +0 0 1 1.505 132.2348 +0 1 1 1.525 132.2349 +0 0 1 1.547 132.2350 +0 1 1 1.567 132.2351 +0 0 1 1.665 132.2352 +0 1 1 1.685 132.2353 +0 0 1 1.713 132.2354 +0 1 1 1.733 132.2355 +0 0 1 1.827 132.2356 +0 1 1 1.847 132.2357 +0 0 1 1.867 132.2358 +0 1 1 1.887 132.2359 +0 0 1 2.081 132.2360 +0 1 1 2.101 132.2361 +0 0 1 2.233 132.2362 +0 1 1 2.253 132.2363 +0 0 1 2.277 132.2364 +0 1 1 2.297 132.2365 +0 0 1 2.401 132.2366 +0 1 1 2.421 132.2367 +0 0 1 2.445 132.2368 +0 1 1 2.463 132.2369 +0 0 1 2.483 132.2370 +0 1 1 2.505 132.2371 +0 0 1 2.573 132.2372 +0 1 1 2.593 132.2373 +0 0 1 2.617 132.2374 +0 1 1 2.637 132.2375 +0 0 1 2.751 132.2376 +0 1 1 2.771 132.2377 +0 0 1 2.865 132.2378 +0 1 1 2.883 132.2379 +0 0 1 2.883 132.2380 +0 0 0 2.883 132.2381 +0 1 0 2.865 132.2382 +0 0 0 2.771 132.2383 +0 1 0 2.751 132.2384 +0 0 0 2.637 132.2385 +0 1 0 2.617 132.2386 +0 0 0 2.593 132.2387 +0 1 0 2.573 132.2388 +0 0 0 2.505 132.2389 +0 1 0 2.481 132.2390 +0 0 0 2.463 132.2391 +0 1 0 2.445 132.2392 +0 0 0 2.421 132.2393 +0 1 0 2.401 132.2394 +0 0 0 2.297 132.2395 +0 1 0 2.277 132.2396 +0 0 0 2.253 132.2397 +0 1 0 2.233 132.2398 +0 0 0 2.209 132.2399 +0 1 0 2.189 132.2400 +0 0 0 2.101 132.2401 +0 1 0 2.081 132.2402 +0 0 0 1.887 132.2403 +0 1 0 1.867 132.2404 +0 0 0 1.847 132.2405 +0 1 0 1.827 132.2406 +0 0 0 1.733 132.2407 +0 1 0 1.713 132.2408 +0 0 0 1.685 132.2409 +0 1 0 1.665 132.2410 +0 0 0 1.567 132.2411 +0 1 0 1.547 132.2412 +0 0 0 1.525 132.2413 +0 1 0 1.505 132.2414 +0 0 0 1.409 132.2415 +0 1 0 1.387 132.2416 +0 0 0 1.279 132.2417 +0 1 0 1.259 132.2418 +0 0 0 1.239 132.2419 +0 1 0 1.219 132.2420 +0 0 0 1.131 132.2421 +0 1 0 1.111 132.2422 +0 0 0 1.111 132.2423 +0 0 1 1.111 132.2424 +0 1 1 1.131 132.2425 +0 0 1 1.219 132.2426 +0 1 1 1.239 132.2427 +0 0 1 1.259 132.2428 +0 1 1 1.279 132.2429 +0 0 1 1.389 132.2430 +0 1 1 1.409 132.2431 +0 0 1 1.505 132.2432 +0 1 1 1.525 132.2433 +0 0 1 1.547 132.2434 +0 1 1 1.567 132.2435 +0 0 1 1.665 132.2436 +0 1 1 1.685 132.2437 +0 0 1 1.713 132.2438 +0 1 1 1.733 132.2439 +0 0 1 1.827 132.2440 +0 1 1 1.847 132.2441 +0 0 1 1.867 132.2442 +0 1 1 1.887 132.2443 +0 0 1 2.083 132.2444 +0 1 1 2.101 132.2445 +0 0 1 2.189 132.2446 +0 1 1 2.209 132.2447 +0 0 1 2.233 132.2448 +0 1 1 2.253 132.2449 +0 0 1 2.279 132.2450 +0 1 1 2.297 132.2451 +0 0 1 2.401 132.2452 +0 1 1 2.421 132.2453 +0 0 1 2.445 132.2454 +0 1 1 2.463 132.2455 +0 0 1 2.481 132.2456 +0 1 1 2.503 132.2457 +0 0 1 2.573 132.2458 +0 1 1 2.593 132.2459 +0 0 1 2.617 132.2460 +0 1 1 2.637 132.2461 +0 0 1 2.751 132.2462 +0 1 1 2.771 132.2463 +0 0 1 2.865 132.2464 +0 1 1 2.883 132.2465 +0 0 1 2.883 132.2466 +0 0 0 2.883 132.2467 +0 1 0 2.865 132.2468 +0 0 0 2.771 132.2469 +0 1 0 2.751 132.2470 +0 0 0 2.637 132.2471 +0 1 0 2.617 132.2472 +0 0 0 2.593 132.2473 +0 1 0 2.573 132.2474 +0 0 0 2.501 132.2475 +0 1 0 2.479 132.2476 +0 0 0 2.463 132.2477 +0 1 0 2.445 132.2478 +0 0 0 2.421 132.2479 +0 1 0 2.401 132.2480 +0 0 0 2.297 132.2481 +0 1 0 2.279 132.2482 +0 0 0 2.253 132.2483 +0 1 0 2.233 132.2484 +0 0 0 2.209 132.2485 +0 1 0 2.189 132.2486 +0 0 0 2.101 132.2487 +0 1 0 2.083 132.2488 +0 0 0 1.887 132.2489 +0 1 0 1.867 132.2490 +0 0 0 1.845 132.2491 +0 1 0 1.827 132.2492 +0 0 0 1.733 132.2493 +0 1 0 1.713 132.2494 +0 0 0 1.685 132.2495 +0 1 0 1.665 132.2496 +0 0 0 1.567 132.2497 +0 1 0 1.547 132.2498 +0 0 0 1.525 132.2499 +0 1 0 1.505 132.2500 +0 0 0 1.409 132.2501 +0 1 0 1.389 132.2502 +0 0 0 1.279 132.2503 +0 1 0 1.259 132.2504 +0 0 0 1.239 132.2505 +0 1 0 1.219 132.2506 +0 0 0 1.131 132.2507 +0 1 0 1.111 132.2508 +0 0 0 1.113 132.2509 +0 0 1 1.113 132.2510 +0 1 1 1.131 132.2511 +0 0 1 1.219 132.2512 +0 1 1 1.239 132.2513 +0 0 1 1.259 132.2514 +0 1 1 1.279 132.2515 +0 0 1 1.389 132.2516 +0 1 1 1.409 132.2517 +0 0 1 1.505 132.2518 +0 1 1 1.525 132.2519 +0 0 1 1.547 132.2520 +0 1 1 1.567 132.2521 +0 0 1 1.665 132.2522 +0 1 1 1.685 132.2523 +0 0 1 1.713 132.2524 +0 1 1 1.733 132.2525 +0 0 1 1.827 132.2526 +0 1 1 1.845 132.2527 +0 0 1 1.867 132.2528 +0 1 1 1.887 132.2529 +0 0 1 2.083 132.2530 +0 1 1 2.101 132.2531 +0 0 1 2.189 132.2532 +0 1 1 2.209 132.2533 +0 0 1 2.233 132.2534 +0 1 1 2.253 132.2535 +0 0 1 2.279 132.2536 +0 1 1 2.297 132.2537 +0 0 1 2.401 132.2538 +0 1 1 2.421 132.2539 +0 0 1 2.445 132.2540 +0 1 1 2.463 132.2541 +0 0 1 2.479 132.2542 +0 1 1 2.501 132.2543 +0 0 1 2.573 132.2544 +0 1 1 2.593 132.2545 +0 0 1 2.617 132.2546 +0 1 1 2.637 132.2547 +0 0 1 2.751 132.2548 +0 1 1 2.771 132.2549 +0 0 1 2.865 132.2550 +0 1 1 2.883 132.2551 +0 0 1 2.883 132.2552 +0 0 0 2.883 132.2553 +0 1 0 2.865 132.2554 +0 0 0 2.771 132.2555 +0 1 0 2.751 132.2556 +0 0 0 2.637 132.2557 +0 1 0 2.617 132.2558 +0 0 0 2.593 132.2559 +0 1 0 2.573 132.2560 +0 0 0 2.499 132.2561 +0 1 0 2.477 132.2562 +0 0 0 2.463 132.2563 +0 1 0 2.445 132.2564 +0 0 0 2.421 132.2565 +0 1 0 2.401 132.2566 +0 0 0 2.299 132.2567 +0 1 0 2.279 132.2568 +0 0 0 2.253 132.2569 +0 1 0 2.233 132.2570 +0 0 0 2.207 132.2571 +0 1 0 2.189 132.2572 +0 0 0 2.101 132.2573 +0 1 0 2.083 132.2574 +0 0 0 1.887 132.2575 +0 1 0 1.867 132.2576 +0 0 0 1.845 132.2577 +0 1 0 1.827 132.2578 +0 0 0 1.733 132.2579 +0 1 0 1.713 132.2580 +0 0 0 1.685 132.2581 +0 1 0 1.665 132.2582 +0 0 0 1.567 132.2583 +0 1 0 1.547 132.2584 +0 0 0 1.525 132.2585 +0 1 0 1.505 132.2586 +0 0 0 1.409 132.2587 +0 1 0 1.389 132.2588 +0 0 0 1.279 132.2589 +0 1 0 1.259 132.2590 +0 0 0 1.237 132.2591 +0 1 0 1.219 132.2592 +0 0 0 1.131 132.2593 +0 1 0 1.113 132.2594 +0 0 0 1.113 132.2595 +0 0 1 1.113 132.2596 +0 1 1 1.131 132.2597 +0 0 1 1.219 132.2598 +0 1 1 1.237 132.2599 +0 0 1 1.259 132.2600 +0 1 1 1.279 132.2601 +0 0 1 1.389 132.2602 +0 1 1 1.409 132.2603 +0 0 1 1.505 132.2604 +0 1 1 1.525 132.2605 +0 0 1 1.547 132.2606 +0 1 1 1.567 132.2607 +0 0 1 1.665 132.2608 +0 1 1 1.685 132.2609 +0 0 1 1.713 132.2610 +0 1 1 1.733 132.2611 +0 0 1 1.827 132.2612 +0 1 1 1.845 132.2613 +0 0 1 1.867 132.2614 +0 1 1 1.887 132.2615 +0 0 1 2.083 132.2616 +0 1 1 2.101 132.2617 +0 0 1 2.189 132.2618 +0 1 1 2.207 132.2619 +0 0 1 2.233 132.2620 +0 1 1 2.253 132.2621 +0 0 1 2.279 132.2622 +0 1 1 2.299 132.2623 +0 0 1 2.401 132.2624 +0 1 1 2.419 132.2625 +0 0 1 2.445 132.2626 +0 1 1 2.463 132.2627 +0 0 1 2.475 132.2628 +0 1 1 2.499 132.2629 +0 0 1 2.573 132.2630 +0 1 1 2.593 132.2631 +0 0 1 2.617 132.2632 +0 1 1 2.637 132.2633 +0 0 1 2.751 132.2634 +0 1 1 2.771 132.2635 +0 0 1 2.863 132.2636 +0 1 1 2.883 132.2637 +0 0 1 2.883 132.2638 +0 0 0 2.883 132.2639 +0 1 0 2.863 132.2640 +0 0 0 2.771 132.2641 +0 1 0 2.751 132.2642 +0 0 0 2.637 132.2643 +0 1 0 2.617 132.2644 +0 0 0 2.593 132.2645 +0 1 0 2.573 132.2646 +0 0 0 2.497 132.2647 +0 1 0 2.475 132.2648 +0 0 0 2.463 132.2649 +0 1 0 2.445 132.2650 +0 0 0 2.419 132.2651 +0 1 0 2.399 132.2652 +0 0 0 2.299 132.2653 +0 1 0 2.281 132.2654 +0 0 0 2.253 132.2655 +0 1 0 2.233 132.2656 +0 0 0 2.207 132.2657 +0 1 0 2.187 132.2658 +0 0 0 2.101 132.2659 +0 1 0 2.083 132.2660 +0 0 0 1.887 132.2661 +0 1 0 1.867 132.2662 +0 0 0 1.845 132.2663 +0 1 0 1.825 132.2664 +0 0 0 1.733 132.2665 +0 1 0 1.713 132.2666 +0 0 0 1.685 132.2667 +0 1 0 1.665 132.2668 +0 0 0 1.567 132.2669 +0 1 0 1.547 132.2670 +0 0 0 1.525 132.2671 +0 1 0 1.505 132.2672 +0 0 0 1.411 132.2673 +0 1 0 1.389 132.2674 +0 0 0 1.279 132.2675 +0 1 0 1.259 132.2676 +0 0 0 1.237 132.2677 +0 1 0 1.217 132.2678 +0 0 0 1.131 132.2679 +0 1 0 1.113 132.2680 +0 0 0 1.113 132.2681 +0 0 1 1.113 132.2682 +0 1 1 1.131 132.2683 +0 0 1 1.217 132.2684 +0 1 1 1.237 132.2685 +0 0 1 1.259 132.2686 +0 1 1 1.279 132.2687 +0 0 1 1.389 132.2688 +0 1 1 1.411 132.2689 +0 0 1 1.505 132.2690 +0 1 1 1.523 132.2691 +0 0 1 1.547 132.2692 +0 1 1 1.567 132.2693 +0 0 1 1.665 132.2694 +0 1 1 1.685 132.2695 +0 0 1 1.713 132.2696 +0 1 1 1.733 132.2697 +0 0 1 1.825 132.2698 +0 1 1 1.845 132.2699 +0 0 1 1.867 132.2700 +0 1 1 1.887 132.2701 +0 0 1 2.083 132.2702 +0 1 1 2.101 132.2703 +0 0 1 2.187 132.2704 +0 1 1 2.207 132.2705 +0 0 1 2.233 132.2706 +0 1 1 2.253 132.2707 +0 0 1 2.281 132.2708 +0 1 1 2.299 132.2709 +0 0 1 2.399 132.2710 +0 1 1 2.419 132.2711 +0 0 1 2.445 132.2712 +0 1 1 2.463 132.2713 +0 0 1 2.473 132.2714 +0 1 1 2.495 132.2715 +0 0 1 2.573 132.2716 +0 1 1 2.593 132.2717 +0 0 1 2.617 132.2718 +0 1 1 2.637 132.2719 +0 0 1 2.751 132.2720 +0 1 1 2.771 132.2721 +0 0 1 2.863 132.2722 +0 1 1 2.883 132.2723 +0 0 1 2.881 132.2724 +0 0 0 2.881 132.2725 +0 1 0 2.863 132.2726 +0 0 0 2.771 132.2727 +0 1 0 2.751 132.2728 +0 0 0 2.637 132.2729 +0 1 0 2.617 132.2730 +0 0 0 2.593 132.2731 +0 1 0 2.573 132.2732 +0 0 0 2.495 132.2733 +0 1 0 2.473 132.2734 +0 0 0 2.463 132.2735 +0 1 0 2.445 132.2736 +0 0 0 2.419 132.2737 +0 1 0 2.399 132.2738 +0 0 0 2.301 132.2739 +0 1 0 2.281 132.2740 +0 0 0 2.253 132.2741 +0 1 0 2.233 132.2742 +0 0 0 2.207 132.2743 +0 1 0 2.187 132.2744 +0 0 0 2.103 132.2745 +0 1 0 2.083 132.2746 +0 0 0 1.887 132.2747 +0 1 0 1.867 132.2748 +0 0 0 1.845 132.2749 +0 1 0 1.825 132.2750 +0 0 0 1.733 132.2751 +0 1 0 1.713 132.2752 +0 0 0 1.685 132.2753 +0 1 0 1.665 132.2754 +0 0 0 1.567 132.2755 +0 1 0 1.547 132.2756 +0 0 0 1.523 132.2757 +0 1 0 1.503 132.2758 +0 0 0 1.411 132.2759 +0 1 0 1.389 132.2760 +0 0 0 1.279 132.2761 +0 1 0 1.259 132.2762 +0 0 0 1.237 132.2763 +0 1 0 1.217 132.2764 +0 0 0 1.133 132.2765 +0 1 0 1.113 132.2766 +0 0 0 1.113 132.2767 +0 0 1 1.113 132.2768 +0 1 1 1.133 132.2769 +0 0 1 1.217 132.2770 +0 1 1 1.237 132.2771 +0 0 1 1.259 132.2772 +0 1 1 1.279 132.2773 +0 0 1 1.391 132.2774 +0 1 1 1.413 132.2775 +0 0 1 1.503 132.2776 +0 1 1 1.523 132.2777 +0 0 1 1.547 132.2778 +0 1 1 1.567 132.2779 +0 0 1 1.665 132.2780 +0 1 1 1.685 132.2781 +0 0 1 1.713 132.2782 +0 1 1 1.733 132.2783 +0 0 1 1.823 132.2784 +0 1 1 1.843 132.2785 +0 0 1 1.867 132.2786 +0 1 1 1.887 132.2787 +0 0 1 2.083 132.2788 +0 1 1 2.103 132.2789 +0 0 1 2.187 132.2790 +0 1 1 2.207 132.2791 +0 0 1 2.233 132.2792 +0 1 1 2.253 132.2793 +0 0 1 2.281 132.2794 +0 1 1 2.301 132.2795 +0 0 1 2.399 132.2796 +0 1 1 2.419 132.2797 +0 0 1 2.445 132.2798 +0 1 1 2.463 132.2799 +0 0 1 2.471 132.2800 +0 1 1 2.493 132.2801 +0 0 1 2.573 132.2802 +0 1 1 2.593 132.2803 +0 0 1 2.617 132.2804 +0 1 1 2.637 132.2805 +0 0 1 2.751 132.2806 +0 1 1 2.771 132.2807 +0 0 1 2.861 132.2808 +0 1 1 2.881 132.2809 +0 0 1 2.881 132.2810 +0 0 0 2.881 132.2811 +0 1 0 2.861 132.2812 +0 0 0 2.771 132.2813 +0 1 0 2.751 132.2814 +0 0 0 2.637 132.2815 +0 1 0 2.617 132.2816 +0 0 0 2.593 132.2817 +0 1 0 2.573 132.2818 +0 0 0 2.493 132.2819 +0 1 0 2.469 132.2820 +0 0 0 2.463 132.2821 +0 1 0 2.445 132.2822 +0 0 0 2.419 132.2823 +0 1 0 2.397 132.2824 +0 0 0 2.303 132.2825 +0 1 0 2.283 132.2826 +0 0 0 2.253 132.2827 +0 1 0 2.233 132.2828 +0 0 0 2.207 132.2829 +0 1 0 2.185 132.2830 +0 0 0 2.105 132.2831 +0 1 0 2.085 132.2832 +0 0 0 1.887 132.2833 +0 1 0 1.867 132.2834 +0 0 0 1.843 132.2835 +0 1 0 1.823 132.2836 +0 0 0 1.733 132.2837 +0 1 0 1.713 132.2838 +0 0 0 1.685 132.2839 +0 1 0 1.665 132.2840 +0 0 0 1.567 132.2841 +0 1 0 1.547 132.2842 +0 0 0 1.523 132.2843 +0 1 0 1.503 132.2844 +0 0 0 1.413 132.2845 +0 1 0 1.391 132.2846 +0 0 0 1.279 132.2847 +0 1 0 1.259 132.2848 +0 0 0 1.237 132.2849 +0 1 0 1.215 132.2850 +0 0 0 1.135 132.2851 +0 1 0 1.115 132.2852 +0 0 0 1.115 132.2853 +0 0 1 1.115 132.2854 +0 1 1 1.135 132.2855 +0 0 1 1.215 132.2856 +0 1 1 1.235 132.2857 +0 0 1 1.259 132.2858 +0 1 1 1.279 132.2859 +0 0 1 1.393 132.2860 +0 1 1 1.415 132.2861 +0 0 1 1.501 132.2862 +0 1 1 1.523 132.2863 +0 0 1 1.547 132.2864 +0 1 1 1.567 132.2865 +0 0 1 1.665 132.2866 +0 1 1 1.685 132.2867 +0 0 1 1.713 132.2868 +0 1 1 1.733 132.2869 +0 0 1 1.821 132.2870 +0 1 1 1.843 132.2871 +0 0 1 1.867 132.2872 +0 1 1 1.887 132.2873 +0 0 1 2.085 132.2874 +0 1 1 2.105 132.2875 +0 0 1 2.185 132.2876 +0 1 1 2.205 132.2877 +0 0 1 2.233 132.2878 +0 1 1 2.253 132.2879 +0 0 1 2.283 132.2880 +0 1 1 2.305 132.2881 +0 0 1 2.397 132.2882 +0 1 1 2.419 132.2883 +0 0 1 2.445 132.2884 +0 1 1 2.463 132.2885 +0 0 1 2.469 132.2886 +0 1 1 2.491 132.2887 +0 0 1 2.573 132.2888 +0 1 1 2.593 132.2889 +0 0 1 2.617 132.2890 +0 1 1 2.637 132.2891 +0 0 1 2.751 132.2892 +0 1 1 2.771 132.2893 +0 0 1 2.859 132.2894 +0 1 1 2.879 132.2895 +0 0 1 2.879 132.2896 +0 0 0 2.879 132.2897 +0 1 0 2.857 132.2898 +0 0 0 2.771 132.2899 +0 1 0 2.751 132.2900 +0 0 0 2.637 132.2901 +0 1 0 2.617 132.2902 +0 0 0 2.593 132.2903 +0 1 0 2.573 132.2904 +0 0 0 2.489 132.2905 +0 1 0 2.467 132.2906 +0 0 0 2.463 132.2907 +0 1 0 2.445 132.2908 +0 0 0 2.417 132.2909 +0 1 0 2.395 132.2910 +0 0 0 2.307 132.2911 +0 1 0 2.285 132.2912 +0 0 0 2.253 132.2913 +0 1 0 2.233 132.2914 +0 0 0 2.205 132.2915 +0 1 0 2.183 132.2916 +0 0 0 2.107 132.2917 +0 1 0 2.085 132.2918 +0 0 0 1.887 132.2919 +0 1 0 1.867 132.2920 +0 0 0 1.841 132.2921 +0 1 0 1.819 132.2922 +0 0 0 1.733 132.2923 +0 1 0 1.713 132.2924 +0 0 0 1.685 132.2925 +0 1 0 1.665 132.2926 +0 0 0 1.567 132.2927 +0 1 0 1.547 132.2928 +0 0 0 1.521 132.2929 +0 1 0 1.499 132.2930 +0 0 0 1.417 132.2931 +0 1 0 1.393 132.2932 +0 0 0 1.279 132.2933 +0 1 0 1.259 132.2934 +0 0 0 1.235 132.2935 +0 1 0 1.213 132.2936 +0 0 0 1.137 132.2937 +0 1 0 1.115 132.2938 +0 0 0 1.117 132.2939 +0 0 1 1.117 132.2940 +0 1 1 1.141 132.2941 +0 0 1 1.211 132.2942 +0 1 1 1.235 132.2943 +0 0 1 1.259 132.2944 +0 1 1 1.279 132.2945 +0 0 1 1.395 132.2946 +0 1 1 1.421 132.2947 +0 0 1 1.497 132.2948 +0 1 1 1.521 132.2949 +0 0 1 1.547 132.2950 +0 1 1 1.567 132.2951 +0 0 1 1.665 132.2952 +0 1 1 1.685 132.2953 +0 0 1 1.713 132.2954 +0 1 1 1.733 132.2955 +0 0 1 1.815 132.2956 +0 1 1 1.841 132.2957 +0 0 1 1.867 132.2958 +0 1 1 1.887 132.2959 +0 0 1 2.087 132.2960 +0 1 1 2.111 132.2961 +0 0 1 2.181 132.2962 +0 1 1 2.205 132.2963 +0 0 1 2.233 132.2964 +0 1 1 2.253 132.2965 +0 0 1 2.285 132.2966 +0 1 1 2.309 132.2967 +0 0 1 2.391 132.2968 +0 1 1 2.417 132.2969 +0 0 1 2.445 132.2970 +0 1 1 2.463 132.2971 +0 0 1 2.467 132.2972 +0 1 1 2.489 132.2973 +0 0 1 2.573 132.2974 +0 1 1 2.593 132.2975 +0 0 1 2.617 132.2976 +0 1 1 2.637 132.2977 +0 0 1 2.751 132.2978 +0 1 1 2.771 132.2979 +0 0 1 2.853 132.2980 +0 1 1 2.879 132.2981 +0 0 1 2.877 132.2982 +0 0 0 2.877 132.2983 +0 1 0 2.845 132.2984 +0 0 0 2.771 132.2985 +0 1 0 2.751 132.2986 +0 0 0 2.637 132.2987 +0 1 0 2.617 132.2988 +0 0 0 2.593 132.2989 +0 1 0 2.573 132.2990 +0 0 0 2.487 132.2991 +0 1 0 2.445 132.2992 +0 0 0 2.417 132.2993 +0 1 0 2.385 132.2994 +0 0 0 2.317 132.2995 +0 1 0 2.287 132.2996 +0 0 0 2.253 132.2997 +0 1 0 2.233 132.2998 +0 0 0 2.203 132.2999 +0 1 0 2.175 132.3000 +0 0 0 2.117 132.3001 +0 1 0 2.087 132.3002 +0 0 0 1.887 132.3003 +0 1 0 1.867 132.3004 +0 0 0 1.839 132.3005 +0 1 0 1.807 132.3006 +0 0 0 1.733 132.3007 +0 1 0 1.713 132.3008 +0 0 0 1.685 132.3009 +0 1 0 1.665 132.3010 +0 0 0 1.567 132.3011 +0 1 0 1.547 132.3012 +0 0 0 1.519 132.3013 +0 1 0 1.493 132.3014 +0 0 0 1.429 132.3015 +0 1 0 1.397 132.3016 +0 0 0 1.279 132.3017 +0 1 0 1.259 132.3018 +0 0 0 1.233 132.3019 +0 1 0 1.205 132.3020 +0 0 0 1.147 132.3021 +0 1 0 1.117 132.3022 +0 0 0 1.119 132.3023 +0 0 1 1.119 132.3024 +0 1 1 1.159 132.3025 +0 0 1 1.195 132.3026 +0 1 1 1.233 132.3027 +0 0 1 1.259 132.3028 +0 1 1 1.371 132.3029 +0 0 1 1.397 132.3030 +0 1 1 1.443 132.3031 +0 0 1 1.483 132.3032 +0 1 1 1.519 132.3033 +0 0 1 1.547 132.3034 +0 1 1 1.567 132.3035 +0 0 1 1.665 132.3036 +0 1 1 1.685 132.3037 +0 0 1 1.713 132.3038 +0 1 1 1.839 132.3039 +0 0 1 1.867 132.3040 +0 1 1 1.979 132.3041 +0 0 1 2.089 132.3042 +0 1 1 2.129 132.3043 +0 0 1 2.165 132.3044 +0 1 1 2.203 132.3045 +0 0 1 2.233 132.3046 +0 1 1 2.253 132.3047 +0 0 1 2.287 132.3048 +0 1 1 2.329 132.3049 +0 0 1 2.371 132.3050 +0 1 1 2.415 132.3051 +0 0 1 2.445 132.3052 +0 1 1 2.485 132.3053 +0 0 1 2.573 132.3054 +0 1 1 2.593 132.3055 +0 0 1 2.617 132.3056 +0 1 1 2.729 132.3057 +0 0 1 2.751 132.3058 +0 1 1 2.877 132.3059 +0 0 1 2.875 132.3060 +0 0 0 2.875 132.3061 +0 1 0 2.751 132.3062 +0 0 0 2.729 132.3063 +0 1 0 2.617 132.3064 +0 0 0 2.593 132.3065 +0 1 0 2.573 132.3066 +0 0 0 2.485 132.3067 +0 1 0 2.445 132.3068 +0 0 0 2.413 132.3069 +0 1 0 2.289 132.3070 +0 0 0 2.253 132.3071 +0 1 0 2.233 132.3072 +0 0 0 2.201 132.3073 +0 1 0 2.089 132.3074 +0 0 0 1.979 132.3075 +0 1 0 1.867 132.3076 +0 0 0 1.837 132.3077 +0 1 0 1.713 132.3078 +0 0 0 1.685 132.3079 +0 1 0 1.665 132.3080 +0 0 0 1.567 132.3081 +0 1 0 1.547 132.3082 +0 0 0 1.517 132.3083 +0 1 0 1.399 132.3084 +0 0 0 1.371 132.3085 +0 1 0 1.259 132.3086 +0 0 0 1.231 132.3087 +0 1 0 1.119 132.3088 +0 0 0 1.121 132.3089 +0 0 1 1.121 132.3090 +0 1 1 1.231 132.3091 +0 0 1 1.259 132.3092 +0 1 1 1.371 132.3093 +0 0 1 1.403 132.3094 +0 1 1 1.517 132.3095 +0 0 1 1.547 132.3096 +0 1 1 1.567 132.3097 +0 0 1 1.665 132.3098 +0 1 1 1.685 132.3099 +0 0 1 1.713 132.3100 +0 1 1 1.835 132.3101 +0 0 1 1.867 132.3102 +0 1 1 1.979 132.3103 +0 0 1 2.091 132.3104 +0 1 1 2.201 132.3105 +0 0 1 2.233 132.3106 +0 1 1 2.253 132.3107 +0 0 1 2.291 132.3108 +0 1 1 2.413 132.3109 +0 0 1 2.445 132.3110 +0 1 1 2.483 132.3111 +0 0 1 2.573 132.3112 +0 1 1 2.593 132.3113 +0 0 1 2.617 132.3114 +0 1 1 2.729 132.3115 +0 0 1 2.751 132.3116 +0 1 1 2.873 132.3117 +0 0 1 2.871 132.3118 +0 0 0 2.871 132.3119 +0 1 0 2.751 132.3120 +0 0 0 2.729 132.3121 +0 1 0 2.617 132.3122 +0 0 0 2.593 132.3123 +0 1 0 2.573 132.3124 +0 0 0 2.483 132.3125 +0 1 0 2.445 132.3126 +0 0 0 2.411 132.3127 +0 1 0 2.293 132.3128 +0 0 0 2.253 132.3129 +0 1 0 2.233 132.3130 +0 0 0 2.199 132.3131 +0 1 0 2.093 132.3132 +0 0 0 1.979 132.3133 +0 1 0 1.867 132.3134 +0 0 0 1.833 132.3135 +0 1 0 1.713 132.3136 +0 0 0 1.685 132.3137 +0 1 0 1.665 132.3138 +0 0 0 1.567 132.3139 +0 1 0 1.547 132.3140 +0 0 0 1.515 132.3141 +0 1 0 1.405 132.3142 +0 0 0 1.371 132.3143 +0 1 0 1.259 132.3144 +0 0 0 1.229 132.3145 +0 1 0 1.123 132.3146 +0 0 0 1.125 132.3147 +0 0 1 1.125 132.3148 +0 1 1 1.227 132.3149 +0 0 1 1.259 132.3150 +0 1 1 1.371 132.3151 +0 0 1 1.407 132.3152 +0 1 1 1.513 132.3153 +0 0 1 1.547 132.3154 +0 1 1 1.567 132.3155 +0 0 1 1.665 132.3156 +0 1 1 1.685 132.3157 +0 0 1 1.713 132.3158 +0 1 1 1.831 132.3159 +0 0 1 1.867 132.3160 +0 1 1 1.979 132.3161 +0 0 1 2.095 132.3162 +0 1 1 2.197 132.3163 +0 0 1 2.233 132.3164 +0 1 1 2.253 132.3165 +0 0 1 2.297 132.3166 +0 1 1 2.409 132.3167 +0 0 1 2.445 132.3168 +0 1 1 2.481 132.3169 +0 0 1 2.573 132.3170 +0 1 1 2.593 132.3171 +0 0 1 2.617 132.3172 +0 1 1 2.729 132.3173 +0 0 1 2.751 132.3174 +0 1 1 2.867 132.3175 +0 0 1 2.863 132.3176 +0 0 0 2.863 132.3177 +0 1 0 2.751 132.3178 +0 0 0 2.729 132.3179 +0 1 0 2.617 132.3180 +0 0 0 2.593 132.3181 +0 1 0 2.573 132.3182 +0 0 0 2.479 132.3183 +0 1 0 2.445 132.3184 +0 0 0 2.405 132.3185 +0 1 0 2.301 132.3186 +0 0 0 2.253 132.3187 +0 1 0 2.233 132.3188 +0 0 0 2.193 132.3189 +0 1 0 2.099 132.3190 +0 0 0 1.979 132.3191 +0 1 0 1.867 132.3192 +0 0 0 1.827 132.3193 +0 1 0 1.713 132.3194 +0 0 0 1.685 132.3195 +0 1 0 1.665 132.3196 +0 0 0 1.567 132.3197 +0 1 0 1.547 132.3198 +0 0 0 1.509 132.3199 +0 1 0 1.411 132.3200 +0 0 0 1.371 132.3201 +0 1 0 1.259 132.3202 +0 0 0 1.223 132.3203 +0 1 0 1.129 132.3204 +0 0 0 1.133 132.3205 +0 0 1 1.133 132.3206 +0 1 1 1.219 132.3207 +0 0 1 1.259 132.3208 +0 1 1 1.371 132.3209 +0 0 1 1.417 132.3210 +0 1 1 1.505 132.3211 +0 0 1 1.547 132.3212 +0 1 1 1.567 132.3213 +0 0 1 1.665 132.3214 +0 1 1 1.685 132.3215 +0 0 1 1.713 132.3216 +0 1 1 1.821 132.3217 +0 0 1 1.867 132.3218 +0 1 1 1.979 132.3219 +0 0 1 2.103 132.3220 +0 1 1 2.189 132.3221 +0 0 1 2.233 132.3222 +0 1 1 2.253 132.3223 +0 0 1 2.307 132.3224 +0 1 1 2.401 132.3225 +0 0 1 2.445 132.3226 +0 1 1 2.479 132.3227 +0 0 1 2.573 132.3228 +0 1 1 2.593 132.3229 +0 0 1 2.617 132.3230 +0 1 1 2.729 132.3231 +0 0 1 2.751 132.3232 +0 1 1 2.859 132.3233 +0 0 1 2.851 132.3234 +0 0 0 2.851 132.3235 +0 1 0 2.751 132.3236 +0 0 0 2.729 132.3237 +0 1 0 2.617 132.3238 +0 0 0 2.593 132.3239 +0 1 0 2.573 132.3240 +0 0 0 2.477 132.3241 +0 1 0 2.445 132.3242 +0 0 0 2.395 132.3243 +0 1 0 2.313 132.3244 +0 0 0 2.253 132.3245 +0 1 0 2.233 132.3246 +0 0 0 2.183 132.3247 +0 1 0 2.109 132.3248 +0 0 0 1.979 132.3249 +0 1 0 1.867 132.3250 +0 0 0 1.815 132.3251 +0 1 0 1.713 132.3252 +0 0 0 1.685 132.3253 +0 1 0 1.665 132.3254 +0 0 0 1.567 132.3255 +0 1 0 1.547 132.3256 +0 0 0 1.499 132.3257 +0 1 0 1.425 132.3258 +0 0 0 1.371 132.3259 +0 1 0 1.259 132.3260 +0 0 0 1.213 132.3261 +0 1 0 1.139 132.3262 +0 0 0 1.153 132.3263 +0 0 1 1.153 132.3264 +0 1 1 1.199 132.3265 +0 0 1 1.441 132.3266 +0 1 1 1.487 132.3267 +0 0 1 2.123 132.3268 +0 1 1 2.169 132.3269 +0 0 1 2.327 132.3270 +0 1 1 2.379 132.3271 +0 0 0 1.121 132.3272 +0 0 1 1.121 132.3273 +0 1 1 2.879 132.3274 +0 0 1 2.885 132.3275 +0 0 0 2.885 132.3276 +0 1 0 1.115 132.3277 +0 0 0 1.109 132.3278 +0 0 1 1.109 132.3279 +0 1 1 2.891 132.3280 +0 0 1 2.895 132.3281 +0 0 0 2.895 132.3282 +0 1 0 1.105 132.3283 +0 0 0 1.101 132.3284 +0 0 1 1.101 132.3285 +0 1 1 2.899 132.3286 +0 0 1 2.901 132.3287 +0 0 0 2.901 132.3288 +0 1 0 1.099 132.3289 +0 0 0 1.095 132.3290 +0 0 1 1.095 132.3291 +0 1 1 2.905 132.3292 +0 0 1 2.907 132.3293 +0 0 0 2.907 132.3294 +0 1 0 1.093 132.3295 +0 0 0 1.091 132.3296 +0 0 1 1.091 132.3297 +0 1 1 1.121 132.3298 +0 0 1 2.879 132.3299 +0 1 1 2.909 132.3300 +0 0 1 2.911 132.3301 +0 0 0 2.911 132.3302 +0 1 0 2.885 132.3303 +0 0 0 1.115 132.3304 +0 1 0 1.089 132.3305 +0 0 0 1.089 132.3306 +0 0 1 1.089 132.3307 +0 1 1 1.111 132.3308 +0 0 1 2.889 132.3309 +0 1 1 2.913 132.3310 +0 0 1 2.915 132.3311 +0 0 0 2.915 132.3312 +0 1 0 2.891 132.3313 +0 0 0 1.109 132.3314 +0 1 0 1.087 132.3315 +0 0 0 1.085 132.3316 +0 0 1 1.085 132.3317 +0 1 1 1.105 132.3318 +0 0 1 2.895 132.3319 +0 1 1 2.915 132.3320 +0 0 1 2.917 132.3321 +0 0 0 2.917 132.3322 +0 1 0 2.897 132.3323 +0 0 0 1.103 132.3324 +0 1 0 1.083 132.3325 +0 0 0 1.083 132.3326 +0 0 1 1.083 132.3327 +0 1 1 1.101 132.3328 +0 0 1 2.899 132.3329 +0 1 1 2.919 132.3330 +0 0 1 2.919 132.3331 +0 0 0 2.919 132.3332 +0 1 0 2.901 132.3333 +0 0 0 1.099 132.3334 +0 1 0 1.081 132.3335 +0 0 0 1.081 132.3336 +0 0 1 1.081 132.3337 +0 1 1 1.099 132.3338 +0 0 1 2.903 132.3339 +0 1 1 2.921 132.3340 +0 0 1 2.921 132.3341 +0 0 0 2.921 132.3342 +0 1 0 2.903 132.3343 +0 0 0 1.097 132.3344 +0 1 0 1.079 132.3345 +0 0 0 1.079 132.3346 +0 0 1 1.079 132.3347 +0 1 1 1.095 132.3348 +0 0 1 2.905 132.3349 +0 1 1 2.921 132.3350 +0 0 1 2.923 132.3351 +0 0 0 2.923 132.3352 +0 1 0 2.907 132.3353 +0 0 0 1.095 132.3354 +0 1 0 1.077 132.3355 +0 0 0 1.077 132.3356 +0 0 1 1.077 132.3357 +0 1 1 1.093 132.3358 +0 0 1 2.907 132.3359 +0 1 1 2.923 132.3360 +0 0 1 2.923 132.3361 +0 0 0 2.923 132.3362 +0 1 0 2.907 132.3363 +0 0 0 1.093 132.3364 +0 1 0 1.077 132.3365 +0 0 0 1.077 132.3366 +0 0 1 1.077 132.3367 +0 1 1 1.091 132.3368 +0 0 1 2.909 132.3369 +0 1 1 2.925 132.3370 +0 0 1 2.925 132.3371 +0 0 0 2.925 132.3372 +0 1 0 2.909 132.3373 +0 0 0 1.091 132.3374 +0 1 0 1.075 132.3375 +0 0 0 1.075 132.3376 +0 0 1 1.075 132.3377 +0 1 1 1.091 132.3378 +0 0 1 2.909 132.3379 +0 1 1 2.925 132.3380 +0 0 1 2.925 132.3381 +0 0 0 2.925 132.3382 +0 1 0 2.909 132.3383 +0 0 0 1.091 132.3384 +0 1 0 1.075 132.3385 +0 0 0 1.075 132.3386 +0 0 1 1.075 132.3387 +0 1 1 1.091 132.3388 +0 0 1 2.911 132.3389 +0 1 1 2.925 132.3390 +0 0 1 2.925 132.3391 +0 0 0 2.925 132.3392 +0 1 0 2.911 132.3393 +0 0 0 1.089 132.3394 +0 1 0 1.075 132.3395 +0 0 0 1.075 132.3396 +0 0 1 1.075 132.3397 +0 1 1 1.089 132.3398 +0 0 1 2.911 132.3399 +0 1 1 2.925 132.3400 +0 0 1 2.925 132.3401 +0 0 0 2.925 132.3402 +0 1 0 2.911 132.3403 +0 0 0 1.089 132.3404 +0 1 0 1.075 132.3405 +0 0 0 1.075 132.3406 +0 0 1 1.075 132.3407 +0 1 1 1.089 132.3408 +0 0 1 2.911 132.3409 +0 1 1 2.925 132.3410 +0 0 1 2.925 132.3411 +0 0 0 2.925 132.3412 +0 1 0 2.911 132.3413 +0 0 0 1.089 132.3414 +0 1 0 1.075 132.3415 +0 0 0 1.075 132.3416 +0 0 1 1.075 132.3417 +0 1 1 1.089 132.3418 +0 0 1 2.911 132.3419 +0 1 1 2.925 132.3420 +0 0 1 2.925 132.3421 +0 0 0 2.925 132.3422 +0 1 0 2.911 132.3423 +0 0 0 1.089 132.3424 +0 1 0 1.075 132.3425 +0 0 0 1.075 132.3426 +0 0 1 1.075 132.3427 +0 1 1 1.089 132.3428 +0 0 1 2.911 132.3429 +0 1 1 2.925 132.3430 +0 0 1 2.925 132.3431 +0 0 0 2.925 132.3432 +0 1 0 2.911 132.3433 +0 0 0 1.089 132.3434 +0 1 0 1.075 132.3435 +0 0 0 1.075 132.3436 +0 0 1 1.075 132.3437 +0 1 1 1.089 132.3438 +0 0 1 2.911 132.3439 +0 1 1 2.925 132.3440 +0 0 1 2.925 132.3441 +0 0 0 2.925 132.3442 +0 1 0 2.911 132.3443 +0 0 0 1.089 132.3444 +0 1 0 1.075 132.3445 +0 0 0 1.075 132.3446 +0 0 1 1.075 132.3447 +0 1 1 1.089 132.3448 +0 0 1 2.911 132.3449 +0 1 1 2.925 132.3450 +0 0 1 2.925 132.3451 +0 0 0 2.925 132.3452 +0 1 0 2.911 132.3453 +0 0 0 1.089 132.3454 +0 1 0 1.075 132.3455 +0 0 0 1.075 132.3456 +0 0 1 1.075 132.3457 +0 1 1 1.089 132.3458 +0 0 1 2.911 132.3459 +0 1 1 2.925 132.3460 +0 0 1 2.925 132.3461 +0 0 0 2.925 132.3462 +0 1 0 2.911 132.3463 +0 0 0 1.089 132.3464 +0 1 0 1.075 132.3465 +0 0 0 1.075 132.3466 +0 0 1 1.075 132.3467 +0 1 1 1.089 132.3468 +0 0 1 2.911 132.3469 +0 1 1 2.925 132.3470 +0 0 1 2.925 132.3471 +0 0 0 2.925 132.3472 +0 1 0 2.911 132.3473 +0 0 0 1.089 132.3474 +0 1 0 1.075 132.3475 +0 0 0 1.075 132.3476 +0 0 1 1.075 132.3477 +0 1 1 1.089 132.3478 +0 0 1 2.911 132.3479 +0 1 1 2.925 132.3480 +0 0 1 2.925 132.3481 +0 0 0 2.925 132.3482 +0 1 0 2.911 132.3483 +0 0 0 1.089 132.3484 +0 1 0 1.075 132.3485 +0 0 0 1.075 132.3486 +0 0 1 1.075 132.3487 +0 1 1 1.089 132.3488 +0 0 1 2.911 132.3489 +0 1 1 2.925 132.3490 +0 0 1 2.925 132.3491 +0 0 0 2.925 132.3492 +0 1 0 2.911 132.3493 +0 0 0 1.089 132.3494 +0 1 0 1.075 132.3495 +0 0 0 1.075 132.3496 +0 0 1 1.075 132.3497 +0 1 1 1.089 132.3498 +0 0 1 2.911 132.3499 +0 1 1 2.925 132.3500 +0 0 1 2.925 132.3501 +0 0 0 2.925 132.3502 +0 1 0 2.911 132.3503 +0 0 0 1.089 132.3504 +0 1 0 1.075 132.3505 +0 0 0 1.075 132.3506 +0 0 1 1.075 132.3507 +0 1 1 1.089 132.3508 +0 0 1 2.911 132.3509 +0 1 1 2.925 132.3510 +0 0 1 2.925 132.3511 +0 0 0 2.925 132.3512 +0 1 0 2.911 132.3513 +0 0 0 1.089 132.3514 +0 1 0 1.075 132.3515 +0 0 0 1.075 132.3516 +0 0 1 1.075 132.3517 +0 1 1 1.089 132.3518 +0 0 1 2.911 132.3519 +0 1 1 2.925 132.3520 +0 0 1 2.925 132.3521 +0 0 0 2.925 132.3522 +0 1 0 2.911 132.3523 +0 0 0 1.089 132.3524 +0 1 0 1.075 132.3525 +0 0 0 1.075 132.3526 +0 0 1 1.075 132.3527 +0 1 1 1.089 132.3528 +0 0 1 2.911 132.3529 +0 1 1 2.925 132.3530 +0 0 1 2.925 132.3531 +0 0 0 2.925 132.3532 +0 1 0 2.911 132.3533 +0 0 0 1.089 132.3534 +0 1 0 1.075 132.3535 +0 0 0 1.075 132.3536 +0 0 1 1.075 132.3537 +0 1 1 1.089 132.3538 +0 0 1 2.911 132.3539 +0 1 1 2.925 132.3540 +0 0 1 2.925 132.3541 +0 0 0 2.925 132.3542 +0 1 0 2.911 132.3543 +0 0 0 1.089 132.3544 +0 1 0 1.075 132.3545 +0 0 0 1.075 132.3546 +0 0 1 1.075 132.3547 +0 1 1 1.089 132.3548 +0 0 1 2.911 132.3549 +0 1 1 2.925 132.3550 +0 0 1 2.925 132.3551 +0 0 0 2.925 132.3552 +0 1 0 2.911 132.3553 +0 0 0 1.089 132.3554 +0 1 0 1.075 132.3555 +0 0 0 1.075 132.3556 +0 0 1 1.075 132.3557 +0 1 1 1.089 132.3558 +0 0 1 2.911 132.3559 +0 1 1 2.925 132.3560 +0 0 1 2.925 132.3561 +0 0 0 2.925 132.3562 +0 1 0 2.911 132.3563 +0 0 0 1.089 132.3564 +0 1 0 1.075 132.3565 +0 0 0 1.075 132.3566 +0 0 1 1.075 132.3567 +0 1 1 1.089 132.3568 +0 0 1 2.911 132.3569 +0 1 1 2.925 132.3570 +0 0 1 2.925 132.3571 +0 0 0 2.925 132.3572 +0 1 0 2.911 132.3573 +0 0 0 1.089 132.3574 +0 1 0 1.075 132.3575 +0 0 0 1.075 132.3576 +0 0 1 1.075 132.3577 +0 1 1 1.089 132.3578 +0 0 1 2.911 132.3579 +0 1 1 2.925 132.3580 +0 0 1 2.925 132.3581 +0 0 0 2.925 132.3582 +0 1 0 2.911 132.3583 +0 0 0 2.277 132.3584 +0 1 0 2.179 132.3585 +0 0 0 1.089 132.3586 +0 1 0 1.075 132.3587 +0 0 0 1.075 132.3588 +0 0 1 1.075 132.3589 +0 1 1 1.089 132.3590 +0 0 1 1.219 132.3591 +0 1 1 1.427 132.3592 +0 0 1 1.635 132.3593 +0 1 1 1.713 132.3594 +0 0 1 1.871 132.3595 +0 1 1 1.997 132.3596 +0 0 1 2.161 132.3597 +0 1 1 2.295 132.3598 +0 0 1 2.911 132.3599 +0 1 1 2.925 132.3600 +0 0 1 2.925 132.3601 +0 0 0 2.925 132.3602 +0 1 0 2.911 132.3603 +0 0 0 2.309 132.3604 +0 1 0 2.149 132.3605 +0 0 0 2.001 132.3606 +0 1 0 1.867 132.3607 +0 0 0 1.715 132.3608 +0 1 0 1.631 132.3609 +0 0 0 1.451 132.3610 +0 1 0 1.215 132.3611 +0 0 0 1.089 132.3612 +0 1 0 1.075 132.3613 +0 0 0 1.075 132.3614 +0 0 1 1.075 132.3615 +0 1 1 1.089 132.3616 +0 0 1 1.215 132.3617 +0 1 1 1.467 132.3618 +0 0 1 1.631 132.3619 +0 1 1 1.717 132.3620 +0 0 1 1.865 132.3621 +0 1 1 2.003 132.3622 +0 0 1 2.139 132.3623 +0 1 1 2.321 132.3624 +0 0 1 2.911 132.3625 +0 1 1 2.925 132.3626 +0 0 1 2.925 132.3627 +0 0 0 2.925 132.3628 +0 1 0 2.911 132.3629 +0 0 0 2.329 132.3630 +0 1 0 2.131 132.3631 +0 0 0 2.003 132.3632 +0 1 0 1.863 132.3633 +0 0 0 1.717 132.3634 +0 1 0 1.629 132.3635 +0 0 0 1.475 132.3636 +0 1 0 1.213 132.3637 +0 0 0 1.089 132.3638 +0 1 0 1.075 132.3639 +0 0 0 1.075 132.3640 +0 0 1 1.075 132.3641 +0 1 1 1.089 132.3642 +0 0 1 1.213 132.3643 +0 1 1 1.483 132.3644 +0 0 1 1.629 132.3645 +0 1 1 1.719 132.3646 +0 0 1 1.863 132.3647 +0 1 1 2.003 132.3648 +0 0 1 2.125 132.3649 +0 1 1 2.335 132.3650 +0 0 1 2.417 132.3651 +0 1 1 2.507 132.3652 +0 0 1 2.715 132.3653 +0 1 1 2.805 132.3654 +0 0 1 2.911 132.3655 +0 1 1 2.925 132.3656 +0 0 1 2.925 132.3657 +0 0 0 2.925 132.3658 +0 1 0 2.911 132.3659 +0 0 0 2.807 132.3660 +0 1 0 2.713 132.3661 +0 0 0 2.509 132.3662 +0 1 0 2.415 132.3663 +0 0 0 2.341 132.3664 +0 1 0 2.119 132.3665 +0 0 0 2.003 132.3666 +0 1 0 1.861 132.3667 +0 0 0 1.719 132.3668 +0 1 0 1.629 132.3669 +0 0 0 1.491 132.3670 +0 1 0 1.213 132.3671 +0 0 0 1.089 132.3672 +0 1 0 1.075 132.3673 +0 0 0 1.075 132.3674 +0 0 1 1.075 132.3675 +0 1 1 1.089 132.3676 +0 0 1 1.213 132.3677 +0 1 1 1.495 132.3678 +0 0 1 1.629 132.3679 +0 1 1 1.719 132.3680 +0 0 1 1.861 132.3681 +0 1 1 2.003 132.3682 +0 0 1 2.115 132.3683 +0 1 1 2.209 132.3684 +0 0 1 2.245 132.3685 +0 1 1 2.347 132.3686 +0 0 1 2.415 132.3687 +0 1 1 2.511 132.3688 +0 0 1 2.711 132.3689 +0 1 1 2.807 132.3690 +0 0 1 2.911 132.3691 +0 1 1 2.925 132.3692 +0 0 1 2.925 132.3693 +0 0 0 2.925 132.3694 +0 1 0 2.911 132.3695 +0 0 0 2.809 132.3696 +0 1 0 2.709 132.3697 +0 0 0 2.513 132.3698 +0 1 0 2.415 132.3699 +0 0 0 2.351 132.3700 +0 1 0 2.279 132.3701 +0 0 0 2.177 132.3702 +0 1 0 2.111 132.3703 +0 0 0 2.003 132.3704 +0 1 0 1.859 132.3705 +0 0 0 1.719 132.3706 +0 1 0 1.629 132.3707 +0 0 0 1.499 132.3708 +0 1 0 1.213 132.3709 +0 0 0 1.089 132.3710 +0 1 0 1.075 132.3711 +0 0 0 1.075 132.3712 +0 0 1 1.075 132.3713 +0 1 1 1.089 132.3714 +0 0 1 1.213 132.3715 +0 1 1 1.229 132.3716 +0 0 1 1.439 132.3717 +0 1 1 1.505 132.3718 +0 0 1 1.629 132.3719 +0 1 1 1.645 132.3720 +0 0 1 1.703 132.3721 +0 1 1 1.719 132.3722 +0 0 1 1.859 132.3723 +0 1 1 1.877 132.3724 +0 0 1 1.989 132.3725 +0 1 1 2.003 132.3726 +0 0 1 2.107 132.3727 +0 1 1 2.157 132.3728 +0 0 1 2.301 132.3729 +0 1 1 2.355 132.3730 +0 0 1 2.415 132.3731 +0 1 1 2.515 132.3732 +0 0 1 2.707 132.3733 +0 1 1 2.807 132.3734 +0 0 1 2.911 132.3735 +0 1 1 2.925 132.3736 +0 0 1 2.925 132.3737 +0 0 0 2.925 132.3738 +0 1 0 2.911 132.3739 +0 0 0 2.807 132.3740 +0 1 0 2.705 132.3741 +0 0 0 2.517 132.3742 +0 1 0 2.415 132.3743 +0 0 0 2.359 132.3744 +0 1 0 2.311 132.3745 +0 0 0 2.147 132.3746 +0 1 0 2.103 132.3747 +0 0 0 2.003 132.3748 +0 1 0 1.989 132.3749 +0 0 0 1.875 132.3750 +0 1 0 1.857 132.3751 +0 0 0 1.719 132.3752 +0 1 0 1.703 132.3753 +0 0 0 1.645 132.3754 +0 1 0 1.629 132.3755 +0 0 0 1.509 132.3756 +0 1 0 1.457 132.3757 +0 0 0 1.229 132.3758 +0 1 0 1.213 132.3759 +0 0 0 1.089 132.3760 +0 1 0 1.075 132.3761 +0 0 0 1.075 132.3762 +0 0 1 1.075 132.3763 +0 1 1 1.089 132.3764 +0 0 1 1.213 132.3765 +0 1 1 1.229 132.3766 +0 0 1 1.467 132.3767 +0 1 1 1.511 132.3768 +0 0 1 1.629 132.3769 +0 1 1 1.645 132.3770 +0 0 1 1.703 132.3771 +0 1 1 1.719 132.3772 +0 0 1 1.857 132.3773 +0 1 1 1.873 132.3774 +0 0 1 1.989 132.3775 +0 1 1 2.003 132.3776 +0 0 1 2.101 132.3777 +0 1 1 2.139 132.3778 +0 0 1 2.321 132.3779 +0 1 1 2.361 132.3780 +0 0 1 2.417 132.3781 +0 1 1 2.519 132.3782 +0 0 1 2.703 132.3783 +0 1 1 2.805 132.3784 +0 0 1 2.911 132.3785 +0 1 1 2.925 132.3786 +0 0 1 2.925 132.3787 +0 0 0 2.925 132.3788 +0 1 0 2.911 132.3789 +0 0 0 2.805 132.3790 +0 1 0 2.701 132.3791 +0 0 0 2.521 132.3792 +0 1 0 2.417 132.3793 +0 0 0 2.363 132.3794 +0 1 0 2.329 132.3795 +0 0 0 2.131 132.3796 +0 1 0 2.097 132.3797 +0 0 0 2.003 132.3798 +0 1 0 1.989 132.3799 +0 0 0 1.873 132.3800 +0 1 0 1.855 132.3801 +0 0 0 1.719 132.3802 +0 1 0 1.703 132.3803 +0 0 0 1.645 132.3804 +0 1 0 1.629 132.3805 +0 0 0 1.515 132.3806 +0 1 0 1.477 132.3807 +0 0 0 1.229 132.3808 +0 1 0 1.213 132.3809 +0 0 0 1.089 132.3810 +0 1 0 1.075 132.3811 +0 0 0 1.075 132.3812 +0 0 1 1.075 132.3813 +0 1 1 1.089 132.3814 +0 0 1 1.213 132.3815 +0 1 1 1.229 132.3816 +0 0 1 1.483 132.3817 +0 1 1 1.517 132.3818 +0 0 1 1.629 132.3819 +0 1 1 1.645 132.3820 +0 0 1 1.703 132.3821 +0 1 1 1.719 132.3822 +0 0 1 1.855 132.3823 +0 1 1 1.871 132.3824 +0 0 1 1.989 132.3825 +0 1 1 2.003 132.3826 +0 0 1 2.095 132.3827 +0 1 1 2.125 132.3828 +0 0 1 2.335 132.3829 +0 1 1 2.365 132.3830 +0 0 1 2.419 132.3831 +0 1 1 2.439 132.3832 +0 0 1 2.503 132.3833 +0 1 1 2.523 132.3834 +0 0 1 2.699 132.3835 +0 1 1 2.721 132.3836 +0 0 1 2.783 132.3837 +0 1 1 2.803 132.3838 +0 0 1 2.911 132.3839 +0 1 1 2.925 132.3840 +0 0 1 2.925 132.3841 +0 0 0 2.925 132.3842 +0 1 0 2.911 132.3843 +0 0 0 2.801 132.3844 +0 1 0 2.785 132.3845 +0 0 0 2.719 132.3846 +0 1 0 2.699 132.3847 +0 0 0 2.523 132.3848 +0 1 0 2.503 132.3849 +0 0 0 2.439 132.3850 +0 1 0 2.421 132.3851 +0 0 0 2.367 132.3852 +0 1 0 2.339 132.3853 +0 0 0 2.121 132.3854 +0 1 0 2.093 132.3855 +0 0 0 2.003 132.3856 +0 1 0 1.989 132.3857 +0 0 0 1.871 132.3858 +0 1 0 1.853 132.3859 +0 0 0 1.719 132.3860 +0 1 0 1.703 132.3861 +0 0 0 1.645 132.3862 +0 1 0 1.629 132.3863 +0 0 0 1.521 132.3864 +0 1 0 1.489 132.3865 +0 0 0 1.229 132.3866 +0 1 0 1.213 132.3867 +0 0 0 1.089 132.3868 +0 1 0 1.075 132.3869 +0 0 0 1.075 132.3870 +0 0 1 1.075 132.3871 +0 1 1 1.089 132.3872 +0 0 1 1.213 132.3873 +0 1 1 1.229 132.3874 +0 0 1 1.493 132.3875 +0 1 1 1.523 132.3876 +0 0 1 1.629 132.3877 +0 1 1 1.645 132.3878 +0 0 1 1.703 132.3879 +0 1 1 1.719 132.3880 +0 0 1 1.853 132.3881 +0 1 1 1.869 132.3882 +0 0 1 1.989 132.3883 +0 1 1 2.003 132.3884 +0 0 1 2.091 132.3885 +0 1 1 2.117 132.3886 +0 0 1 2.345 132.3887 +0 1 1 2.369 132.3888 +0 0 1 2.421 132.3889 +0 1 1 2.439 132.3890 +0 0 1 2.505 132.3891 +0 1 1 2.525 132.3892 +0 0 1 2.697 132.3893 +0 1 1 2.717 132.3894 +0 0 1 2.783 132.3895 +0 1 1 2.801 132.3896 +0 0 1 2.911 132.3897 +0 1 1 2.925 132.3898 +0 0 1 2.925 132.3899 +0 0 0 2.925 132.3900 +0 1 0 2.911 132.3901 +0 0 0 2.799 132.3902 +0 1 0 2.781 132.3903 +0 0 0 2.715 132.3904 +0 1 0 2.695 132.3905 +0 0 0 2.527 132.3906 +0 1 0 2.507 132.3907 +0 0 0 2.441 132.3908 +0 1 0 2.423 132.3909 +0 0 0 2.371 132.3910 +0 1 0 2.349 132.3911 +0 0 0 2.113 132.3912 +0 1 0 2.089 132.3913 +0 0 0 2.003 132.3914 +0 1 0 1.989 132.3915 +0 0 0 1.869 132.3916 +0 1 0 1.851 132.3917 +0 0 0 1.719 132.3918 +0 1 0 1.703 132.3919 +0 0 0 1.645 132.3920 +0 1 0 1.629 132.3921 +0 0 0 1.525 132.3922 +0 1 0 1.499 132.3923 +0 0 0 1.229 132.3924 +0 1 0 1.213 132.3925 +0 0 0 1.089 132.3926 +0 1 0 1.075 132.3927 +0 0 0 1.075 132.3928 +0 0 1 1.075 132.3929 +0 1 1 1.089 132.3930 +0 0 1 1.213 132.3931 +0 1 1 1.229 132.3932 +0 0 1 1.501 132.3933 +0 1 1 1.527 132.3934 +0 0 1 1.629 132.3935 +0 1 1 1.645 132.3936 +0 0 1 1.703 132.3937 +0 1 1 1.719 132.3938 +0 0 1 1.851 132.3939 +0 1 1 1.867 132.3940 +0 0 1 1.989 132.3941 +0 1 1 2.003 132.3942 +0 0 1 2.089 132.3943 +0 1 1 2.111 132.3944 +0 0 1 2.351 132.3945 +0 1 1 2.373 132.3946 +0 0 1 2.425 132.3947 +0 1 1 2.443 132.3948 +0 0 1 2.509 132.3949 +0 1 1 2.529 132.3950 +0 0 1 2.693 132.3951 +0 1 1 2.713 132.3952 +0 0 1 2.779 132.3953 +0 1 1 2.797 132.3954 +0 0 1 2.911 132.3955 +0 1 1 2.925 132.3956 +0 0 1 2.925 132.3957 +0 0 0 2.925 132.3958 +0 1 0 2.911 132.3959 +0 0 0 2.797 132.3960 +0 1 0 2.779 132.3961 +0 0 0 2.711 132.3962 +0 1 0 2.691 132.3963 +0 0 0 2.531 132.3964 +0 1 0 2.511 132.3965 +0 0 0 2.443 132.3966 +0 1 0 2.425 132.3967 +0 0 0 2.375 132.3968 +0 1 0 2.353 132.3969 +0 0 0 2.107 132.3970 +0 1 0 2.087 132.3971 +0 0 0 2.003 132.3972 +0 1 0 1.989 132.3973 +0 0 0 1.867 132.3974 +0 1 0 1.849 132.3975 +0 0 0 1.719 132.3976 +0 1 0 1.703 132.3977 +0 0 0 1.645 132.3978 +0 1 0 1.629 132.3979 +0 0 0 1.529 132.3980 +0 1 0 1.505 132.3981 +0 0 0 1.229 132.3982 +0 1 0 1.213 132.3983 +0 0 0 1.089 132.3984 +0 1 0 1.075 132.3985 +0 0 0 1.075 132.3986 +0 0 1 1.075 132.3987 +0 1 1 1.089 132.3988 +0 0 1 1.213 132.3989 +0 1 1 1.229 132.3990 +0 0 1 1.509 132.3991 +0 1 1 1.531 132.3992 +0 0 1 1.629 132.3993 +0 1 1 1.645 132.3994 +0 0 1 1.703 132.3995 +0 1 1 1.719 132.3996 +0 0 1 1.849 132.3997 +0 1 1 1.865 132.3998 +0 0 1 1.989 132.3999 +0 1 1 2.003 132.4000 +0 0 1 2.085 132.4001 +0 1 1 2.105 132.4002 +0 0 1 2.357 132.4003 +0 1 1 2.375 132.4004 +0 0 1 2.427 132.4005 +0 1 1 2.445 132.4006 +0 0 1 2.513 132.4007 +0 1 1 2.533 132.4008 +0 0 1 2.689 132.4009 +0 1 1 2.709 132.4010 +0 0 1 2.777 132.4011 +0 1 1 2.795 132.4012 +0 0 1 2.911 132.4013 +0 1 1 2.925 132.4014 +0 0 1 2.925 132.4015 +0 0 0 2.925 132.4016 +0 1 0 2.911 132.4017 +0 0 0 2.793 132.4018 +0 1 0 2.775 132.4019 +0 0 0 2.707 132.4020 +0 1 0 2.687 132.4021 +0 0 0 2.535 132.4022 +0 1 0 2.515 132.4023 +0 0 0 2.447 132.4024 +0 1 0 2.429 132.4025 +0 0 0 2.377 132.4026 +0 1 0 2.357 132.4027 +0 0 0 2.103 132.4028 +0 1 0 2.083 132.4029 +0 0 0 2.003 132.4030 +0 1 0 1.989 132.4031 +0 0 0 1.865 132.4032 +0 1 0 1.847 132.4033 +0 0 0 1.719 132.4034 +0 1 0 1.703 132.4035 +0 0 0 1.645 132.4036 +0 1 0 1.629 132.4037 +0 0 0 1.533 132.4038 +0 1 0 1.511 132.4039 +0 0 0 1.229 132.4040 +0 1 0 1.213 132.4041 +0 0 0 1.089 132.4042 +0 1 0 1.075 132.4043 +0 0 0 1.075 132.4044 +0 0 1 1.075 132.4045 +0 1 1 1.089 132.4046 +0 0 1 1.213 132.4047 +0 1 1 1.229 132.4048 +0 0 1 1.513 132.4049 +0 1 1 1.535 132.4050 +0 0 1 1.629 132.4051 +0 1 1 1.645 132.4052 +0 0 1 1.703 132.4053 +0 1 1 1.719 132.4054 +0 0 1 1.847 132.4055 +0 1 1 1.863 132.4056 +0 0 1 1.989 132.4057 +0 1 1 2.003 132.4058 +0 0 1 2.083 132.4059 +0 1 1 2.101 132.4060 +0 0 1 2.359 132.4061 +0 1 1 2.379 132.4062 +0 0 1 2.431 132.4063 +0 1 1 2.449 132.4064 +0 0 1 2.517 132.4065 +0 1 1 2.537 132.4066 +0 0 1 2.685 132.4067 +0 1 1 2.705 132.4068 +0 0 1 2.775 132.4069 +0 1 1 2.793 132.4070 +0 0 1 2.911 132.4071 +0 1 1 2.925 132.4072 +0 0 1 2.925 132.4073 +0 0 0 2.925 132.4074 +0 1 0 2.911 132.4075 +0 0 0 2.791 132.4076 +0 1 0 2.773 132.4077 +0 0 0 2.703 132.4078 +0 1 0 2.683 132.4079 +0 0 0 2.539 132.4080 +0 1 0 2.519 132.4081 +0 0 0 2.449 132.4082 +0 1 0 2.431 132.4083 +0 0 0 2.379 132.4084 +0 1 0 2.361 132.4085 +0 0 0 2.099 132.4086 +0 1 0 2.081 132.4087 +0 0 0 2.003 132.4088 +0 1 0 1.989 132.4089 +0 0 0 1.863 132.4090 +0 1 0 1.845 132.4091 +0 0 0 1.719 132.4092 +0 1 0 1.703 132.4093 +0 0 0 1.645 132.4094 +0 1 0 1.629 132.4095 +0 0 0 1.535 132.4096 +0 1 0 1.515 132.4097 +0 0 0 1.229 132.4098 +0 1 0 1.213 132.4099 +0 0 0 1.089 132.4100 +0 1 0 1.075 132.4101 +0 0 0 1.075 132.4102 +0 0 1 1.075 132.4103 +0 1 1 1.089 132.4104 +0 0 1 1.213 132.4105 +0 1 1 1.229 132.4106 +0 0 1 1.517 132.4107 +0 1 1 1.537 132.4108 +0 0 1 1.629 132.4109 +0 1 1 1.645 132.4110 +0 0 1 1.703 132.4111 +0 1 1 1.719 132.4112 +0 0 1 1.845 132.4113 +0 1 1 1.861 132.4114 +0 0 1 1.989 132.4115 +0 1 1 2.003 132.4116 +0 0 1 2.081 132.4117 +0 1 1 2.099 132.4118 +0 0 1 2.363 132.4119 +0 1 1 2.381 132.4120 +0 0 1 2.433 132.4121 +0 1 1 2.451 132.4122 +0 0 1 2.521 132.4123 +0 1 1 2.541 132.4124 +0 0 1 2.683 132.4125 +0 1 1 2.703 132.4126 +0 0 1 2.771 132.4127 +0 1 1 2.789 132.4128 +0 0 1 2.911 132.4129 +0 1 1 2.925 132.4130 +0 0 1 2.925 132.4131 +0 0 0 2.925 132.4132 +0 1 0 2.911 132.4133 +0 0 0 2.787 132.4134 +0 1 0 2.771 132.4135 +0 0 0 2.701 132.4136 +0 1 0 2.681 132.4137 +0 0 0 2.543 132.4138 +0 1 0 2.523 132.4139 +0 0 0 2.453 132.4140 +0 1 0 2.435 132.4141 +0 0 0 2.381 132.4142 +0 1 0 2.363 132.4143 +0 0 0 2.097 132.4144 +0 1 0 2.079 132.4145 +0 0 0 2.003 132.4146 +0 1 0 1.989 132.4147 +0 0 0 1.861 132.4148 +0 1 0 1.843 132.4149 +0 0 0 1.719 132.4150 +0 1 0 1.703 132.4151 +0 0 0 1.645 132.4152 +0 1 0 1.629 132.4153 +0 0 0 1.539 132.4154 +0 1 0 1.519 132.4155 +0 0 0 1.229 132.4156 +0 1 0 1.213 132.4157 +0 0 0 1.089 132.4158 +0 1 0 1.075 132.4159 +0 0 0 1.075 132.4160 +0 0 1 1.075 132.4161 +0 1 1 1.089 132.4162 +0 0 1 1.213 132.4163 +0 1 1 1.229 132.4164 +0 0 1 1.521 132.4165 +0 1 1 1.539 132.4166 +0 0 1 1.629 132.4167 +0 1 1 1.645 132.4168 +0 0 1 1.703 132.4169 +0 1 1 1.719 132.4170 +0 0 1 1.841 132.4171 +0 1 1 1.859 132.4172 +0 0 1 1.989 132.4173 +0 1 1 2.003 132.4174 +0 0 1 2.079 132.4175 +0 1 1 2.095 132.4176 +0 0 1 2.365 132.4177 +0 1 1 2.381 132.4178 +0 0 1 2.435 132.4179 +0 1 1 2.453 132.4180 +0 0 1 2.523 132.4181 +0 1 1 2.543 132.4182 +0 0 1 2.679 132.4183 +0 1 1 2.699 132.4184 +0 0 1 2.769 132.4185 +0 1 1 2.787 132.4186 +0 0 1 2.911 132.4187 +0 1 1 2.925 132.4188 +0 0 1 2.925 132.4189 +0 0 0 2.925 132.4190 +0 1 0 2.911 132.4191 +0 0 0 2.785 132.4192 +0 1 0 2.767 132.4193 +0 0 0 2.697 132.4194 +0 1 0 2.677 132.4195 +0 0 0 2.545 132.4196 +0 1 0 2.525 132.4197 +0 0 0 2.455 132.4198 +0 1 0 2.437 132.4199 +0 0 0 2.383 132.4200 +0 1 0 2.367 132.4201 +0 0 0 2.095 132.4202 +0 1 0 2.077 132.4203 +0 0 0 2.003 132.4204 +0 1 0 1.989 132.4205 +0 0 0 1.859 132.4206 +0 1 0 1.841 132.4207 +0 0 0 1.719 132.4208 +0 1 0 1.703 132.4209 +0 0 0 1.645 132.4210 +0 1 0 1.629 132.4211 +0 0 0 1.541 132.4212 +0 1 0 1.523 132.4213 +0 0 0 1.229 132.4214 +0 1 0 1.213 132.4215 +0 0 0 1.089 132.4216 +0 1 0 1.075 132.4217 +0 0 0 1.075 132.4218 +0 0 1 1.075 132.4219 +0 1 1 1.089 132.4220 +0 0 1 1.213 132.4221 +0 1 1 1.229 132.4222 +0 0 1 1.525 132.4223 +0 1 1 1.541 132.4224 +0 0 1 1.629 132.4225 +0 1 1 1.645 132.4226 +0 0 1 1.703 132.4227 +0 1 1 1.719 132.4228 +0 0 1 1.839 132.4229 +0 1 1 1.857 132.4230 +0 0 1 1.989 132.4231 +0 1 1 2.003 132.4232 +0 0 1 2.077 132.4233 +0 1 1 2.093 132.4234 +0 0 1 2.367 132.4235 +0 1 1 2.383 132.4236 +0 0 1 2.439 132.4237 +0 1 1 2.457 132.4238 +0 0 1 2.527 132.4239 +0 1 1 2.547 132.4240 +0 0 1 2.675 132.4241 +0 1 1 2.695 132.4242 +0 0 1 2.765 132.4243 +0 1 1 2.783 132.4244 +0 0 1 2.911 132.4245 +0 1 1 2.925 132.4246 +0 0 1 2.925 132.4247 +0 0 0 2.925 132.4248 +0 1 0 2.911 132.4249 +0 0 0 2.783 132.4250 +0 1 0 2.765 132.4251 +0 0 0 2.693 132.4252 +0 1 0 2.673 132.4253 +0 0 0 2.549 132.4254 +0 1 0 2.529 132.4255 +0 0 0 2.457 132.4256 +0 1 0 2.439 132.4257 +0 0 0 2.385 132.4258 +0 1 0 2.367 132.4259 +0 0 0 2.093 132.4260 +0 1 0 2.077 132.4261 +0 0 0 2.003 132.4262 +0 1 0 1.989 132.4263 +0 0 0 1.857 132.4264 +0 1 0 1.839 132.4265 +0 0 0 1.719 132.4266 +0 1 0 1.703 132.4267 +0 0 0 1.645 132.4268 +0 1 0 1.629 132.4269 +0 0 0 1.543 132.4270 +0 1 0 1.525 132.4271 +0 0 0 1.229 132.4272 +0 1 0 1.213 132.4273 +0 0 0 1.089 132.4274 +0 1 0 1.075 132.4275 +0 0 0 1.075 132.4276 +0 0 1 1.075 132.4277 +0 1 1 1.089 132.4278 +0 0 1 1.213 132.4279 +0 1 1 1.229 132.4280 +0 0 1 1.527 132.4281 +0 1 1 1.543 132.4282 +0 0 1 1.629 132.4283 +0 1 1 1.645 132.4284 +0 0 1 1.703 132.4285 +0 1 1 1.719 132.4286 +0 0 1 1.837 132.4287 +0 1 1 1.855 132.4288 +0 0 1 1.989 132.4289 +0 1 1 2.003 132.4290 +0 0 1 2.075 132.4291 +0 1 1 2.091 132.4292 +0 0 1 2.211 132.4293 +0 1 1 2.259 132.4294 +0 0 1 2.369 132.4295 +0 1 1 2.385 132.4296 +0 0 1 2.441 132.4297 +0 1 1 2.459 132.4298 +0 0 1 2.531 132.4299 +0 1 1 2.551 132.4300 +0 0 1 2.671 132.4301 +0 1 1 2.691 132.4302 +0 0 1 2.763 132.4303 +0 1 1 2.781 132.4304 +0 0 1 2.911 132.4305 +0 1 1 2.925 132.4306 +0 0 1 2.925 132.4307 +0 0 0 2.925 132.4308 +0 1 0 2.911 132.4309 +0 0 0 2.779 132.4310 +0 1 0 2.761 132.4311 +0 0 0 2.689 132.4312 +0 1 0 2.669 132.4313 +0 0 0 2.553 132.4314 +0 1 0 2.533 132.4315 +0 0 0 2.461 132.4316 +0 1 0 2.443 132.4317 +0 0 0 2.385 132.4318 +0 1 0 2.369 132.4319 +0 0 0 2.277 132.4320 +0 1 0 2.185 132.4321 +0 0 0 2.091 132.4322 +0 1 0 2.075 132.4323 +0 0 0 2.003 132.4324 +0 1 0 1.989 132.4325 +0 0 0 1.855 132.4326 +0 1 0 1.837 132.4327 +0 0 0 1.719 132.4328 +0 1 0 1.703 132.4329 +0 0 0 1.645 132.4330 +0 1 0 1.629 132.4331 +0 0 0 1.545 132.4332 +0 1 0 1.527 132.4333 +0 0 0 1.229 132.4334 +0 1 0 1.213 132.4335 +0 0 0 1.089 132.4336 +0 1 0 1.075 132.4337 +0 0 0 1.075 132.4338 +0 0 1 1.075 132.4339 +0 1 1 1.089 132.4340 +0 0 1 1.213 132.4341 +0 1 1 1.229 132.4342 +0 0 1 1.529 132.4343 +0 1 1 1.545 132.4344 +0 0 1 1.629 132.4345 +0 1 1 1.645 132.4346 +0 0 1 1.703 132.4347 +0 1 1 1.719 132.4348 +0 0 1 1.835 132.4349 +0 1 1 1.853 132.4350 +0 0 1 1.989 132.4351 +0 1 1 2.003 132.4352 +0 0 1 2.075 132.4353 +0 1 1 2.091 132.4354 +0 0 1 2.171 132.4355 +0 1 1 2.289 132.4356 +0 0 1 2.371 132.4357 +0 1 1 2.387 132.4358 +0 0 1 2.443 132.4359 +0 1 1 2.461 132.4360 +0 0 1 2.535 132.4361 +0 1 1 2.555 132.4362 +0 0 1 2.667 132.4363 +0 1 1 2.687 132.4364 +0 0 1 2.761 132.4365 +0 1 1 2.779 132.4366 +0 0 1 2.911 132.4367 +0 1 1 2.925 132.4368 +0 0 1 2.925 132.4369 +0 0 0 2.925 132.4370 +0 1 0 2.911 132.4371 +0 0 0 2.777 132.4372 +0 1 0 2.759 132.4373 +0 0 0 2.685 132.4374 +0 1 0 2.665 132.4375 +0 0 0 2.557 132.4376 +0 1 0 2.537 132.4377 +0 0 0 2.463 132.4378 +0 1 0 2.445 132.4379 +0 0 0 2.387 132.4380 +0 1 0 2.371 132.4381 +0 0 0 2.295 132.4382 +0 1 0 2.165 132.4383 +0 0 0 2.089 132.4384 +0 1 0 2.073 132.4385 +0 0 0 2.003 132.4386 +0 1 0 1.989 132.4387 +0 0 0 1.853 132.4388 +0 1 0 1.835 132.4389 +0 0 0 1.719 132.4390 +0 1 0 1.703 132.4391 +0 0 0 1.645 132.4392 +0 1 0 1.629 132.4393 +0 0 0 1.547 132.4394 +0 1 0 1.529 132.4395 +0 0 0 1.415 132.4396 +0 1 0 1.291 132.4397 +0 0 0 1.229 132.4398 +0 1 0 1.213 132.4399 +0 0 0 1.089 132.4400 +0 1 0 1.075 132.4401 +0 0 0 1.075 132.4402 +0 0 1 1.075 132.4403 +0 1 1 1.089 132.4404 +0 0 1 1.213 132.4405 +0 1 1 1.229 132.4406 +0 0 1 1.289 132.4407 +0 1 1 1.429 132.4408 +0 0 1 1.531 132.4409 +0 1 1 1.547 132.4410 +0 0 1 1.629 132.4411 +0 1 1 1.645 132.4412 +0 0 1 1.703 132.4413 +0 1 1 1.719 132.4414 +0 0 1 1.833 132.4415 +0 1 1 1.851 132.4416 +0 0 1 1.989 132.4417 +0 1 1 2.003 132.4418 +0 0 1 2.073 132.4419 +0 1 1 2.089 132.4420 +0 0 1 2.159 132.4421 +0 1 1 2.299 132.4422 +0 0 1 2.371 132.4423 +0 1 1 2.387 132.4424 +0 0 1 2.447 132.4425 +0 1 1 2.465 132.4426 +0 0 1 2.539 132.4427 +0 1 1 2.559 132.4428 +0 0 1 2.665 132.4429 +0 1 1 2.685 132.4430 +0 0 1 2.757 132.4431 +0 1 1 2.775 132.4432 +0 0 1 2.911 132.4433 +0 1 1 2.925 132.4434 +0 0 1 2.925 132.4435 +0 0 0 2.925 132.4436 +0 1 0 2.911 132.4437 +0 0 0 2.775 132.4438 +0 1 0 2.757 132.4439 +0 0 0 2.683 132.4440 +0 1 0 2.663 132.4441 +0 0 0 2.561 132.4442 +0 1 0 2.541 132.4443 +0 0 0 2.467 132.4444 +0 1 0 2.449 132.4445 +0 0 0 2.387 132.4446 +0 1 0 2.373 132.4447 +0 0 0 2.303 132.4448 +0 1 0 2.155 132.4449 +0 0 0 2.089 132.4450 +0 1 0 2.073 132.4451 +0 0 0 2.003 132.4452 +0 1 0 1.989 132.4453 +0 0 0 1.931 132.4454 +0 1 0 1.917 132.4455 +0 0 0 1.849 132.4456 +0 1 0 1.833 132.4457 +0 0 0 1.719 132.4458 +0 1 0 1.703 132.4459 +0 0 0 1.645 132.4460 +0 1 0 1.629 132.4461 +0 0 0 1.547 132.4462 +0 1 0 1.531 132.4463 +0 0 0 1.439 132.4464 +0 1 0 1.287 132.4465 +0 0 0 1.229 132.4466 +0 1 0 1.213 132.4467 +0 0 0 1.089 132.4468 +0 1 0 1.075 132.4469 +0 0 0 1.075 132.4470 +0 0 1 1.075 132.4471 +0 1 1 1.089 132.4472 +0 0 1 1.213 132.4473 +0 1 1 1.229 132.4474 +0 0 1 1.287 132.4475 +0 1 1 1.445 132.4476 +0 0 1 1.531 132.4477 +0 1 1 1.549 132.4478 +0 0 1 1.629 132.4479 +0 1 1 1.645 132.4480 +0 0 1 1.703 132.4481 +0 1 1 1.719 132.4482 +0 0 1 1.831 132.4483 +0 1 1 1.849 132.4484 +0 0 1 1.915 132.4485 +0 1 1 1.931 132.4486 +0 0 1 1.989 132.4487 +0 1 1 2.003 132.4488 +0 0 1 2.071 132.4489 +0 1 1 2.089 132.4490 +0 0 1 2.153 132.4491 +0 1 1 2.305 132.4492 +0 0 1 2.373 132.4493 +0 1 1 2.389 132.4494 +0 0 1 2.449 132.4495 +0 1 1 2.467 132.4496 +0 0 1 2.541 132.4497 +0 1 1 2.561 132.4498 +0 0 1 2.661 132.4499 +0 1 1 2.681 132.4500 +0 0 1 2.755 132.4501 +0 1 1 2.773 132.4502 +0 0 1 2.911 132.4503 +0 1 1 2.925 132.4504 +0 0 1 2.925 132.4505 +0 0 0 2.925 132.4506 +0 1 0 2.911 132.4507 +0 0 0 2.771 132.4508 +0 1 0 2.753 132.4509 +0 0 0 2.679 132.4510 +0 1 0 2.659 132.4511 +0 0 0 2.563 132.4512 +0 1 0 2.543 132.4513 +0 0 0 2.469 132.4514 +0 1 0 2.451 132.4515 +0 0 0 2.389 132.4516 +0 1 0 2.373 132.4517 +0 0 0 2.307 132.4518 +0 1 0 2.151 132.4519 +0 0 0 2.087 132.4520 +0 1 0 2.071 132.4521 +0 0 0 2.003 132.4522 +0 1 0 1.989 132.4523 +0 0 0 1.933 132.4524 +0 1 0 1.915 132.4525 +0 0 0 1.847 132.4526 +0 1 0 1.831 132.4527 +0 0 0 1.719 132.4528 +0 1 0 1.703 132.4529 +0 0 0 1.645 132.4530 +0 1 0 1.629 132.4531 +0 0 0 1.549 132.4532 +0 1 0 1.533 132.4533 +0 0 0 1.449 132.4534 +0 1 0 1.287 132.4535 +0 0 0 1.229 132.4536 +0 1 0 1.213 132.4537 +0 0 0 1.089 132.4538 +0 1 0 1.075 132.4539 +0 0 0 1.075 132.4540 +0 0 1 1.075 132.4541 +0 1 1 1.089 132.4542 +0 0 1 1.213 132.4543 +0 1 1 1.229 132.4544 +0 0 1 1.287 132.4545 +0 1 1 1.455 132.4546 +0 0 1 1.533 132.4547 +0 1 1 1.549 132.4548 +0 0 1 1.629 132.4549 +0 1 1 1.645 132.4550 +0 0 1 1.703 132.4551 +0 1 1 1.719 132.4552 +0 0 1 1.829 132.4553 +0 1 1 1.847 132.4554 +0 0 1 1.913 132.4555 +0 1 1 1.933 132.4556 +0 0 1 1.989 132.4557 +0 1 1 2.003 132.4558 +0 0 1 2.071 132.4559 +0 1 1 2.087 132.4560 +0 0 1 2.149 132.4561 +0 1 1 2.199 132.4562 +0 0 1 2.267 132.4563 +0 1 1 2.309 132.4564 +0 0 1 2.373 132.4565 +0 1 1 2.389 132.4566 +0 0 1 2.453 132.4567 +0 1 1 2.471 132.4568 +0 0 1 2.545 132.4569 +0 1 1 2.565 132.4570 +0 0 1 2.657 132.4571 +0 1 1 2.677 132.4572 +0 0 1 2.753 132.4573 +0 1 1 2.771 132.4574 +0 0 1 2.911 132.4575 +0 1 1 2.925 132.4576 +0 0 1 2.925 132.4577 +0 0 0 2.925 132.4578 +0 1 0 2.911 132.4579 +0 0 0 2.769 132.4580 +0 1 0 2.751 132.4581 +0 0 0 2.675 132.4582 +0 1 0 2.655 132.4583 +0 0 0 2.567 132.4584 +0 1 0 2.547 132.4585 +0 0 0 2.471 132.4586 +0 1 0 2.453 132.4587 +0 0 0 2.389 132.4588 +0 1 0 2.375 132.4589 +0 0 0 2.311 132.4590 +0 1 0 2.281 132.4591 +0 0 0 2.181 132.4592 +0 1 0 2.149 132.4593 +0 0 0 2.087 132.4594 +0 1 0 2.071 132.4595 +0 0 0 2.003 132.4596 +0 1 0 1.989 132.4597 +0 0 0 1.933 132.4598 +0 1 0 1.913 132.4599 +0 0 0 1.845 132.4600 +0 1 0 1.829 132.4601 +0 0 0 1.719 132.4602 +0 1 0 1.703 132.4603 +0 0 0 1.645 132.4604 +0 1 0 1.629 132.4605 +0 0 0 1.549 132.4606 +0 1 0 1.535 132.4607 +0 0 0 1.457 132.4608 +0 1 0 1.287 132.4609 +0 0 0 1.229 132.4610 +0 1 0 1.213 132.4611 +0 0 0 1.089 132.4612 +0 1 0 1.075 132.4613 +0 0 0 1.075 132.4614 +0 0 1 1.075 132.4615 +0 1 1 1.089 132.4616 +0 0 1 1.213 132.4617 +0 1 1 1.229 132.4618 +0 0 1 1.287 132.4619 +0 1 1 1.461 132.4620 +0 0 1 1.535 132.4621 +0 1 1 1.551 132.4622 +0 0 1 1.629 132.4623 +0 1 1 1.645 132.4624 +0 0 1 1.703 132.4625 +0 1 1 1.719 132.4626 +0 0 1 1.827 132.4627 +0 1 1 1.845 132.4628 +0 0 1 1.911 132.4629 +0 1 1 1.933 132.4630 +0 0 1 1.989 132.4631 +0 1 1 2.003 132.4632 +0 0 1 2.071 132.4633 +0 1 1 2.087 132.4634 +0 0 1 2.147 132.4635 +0 1 1 2.171 132.4636 +0 0 1 2.287 132.4637 +0 1 1 2.313 132.4638 +0 0 1 2.375 132.4639 +0 1 1 2.391 132.4640 +0 0 1 2.455 132.4641 +0 1 1 2.473 132.4642 +0 0 1 2.549 132.4643 +0 1 1 2.569 132.4644 +0 0 1 2.653 132.4645 +0 1 1 2.673 132.4646 +0 0 1 2.749 132.4647 +0 1 1 2.767 132.4648 +0 0 1 2.911 132.4649 +0 1 1 2.925 132.4650 +0 0 1 2.925 132.4651 +0 0 0 2.925 132.4652 +0 1 0 2.911 132.4653 +0 0 0 2.765 132.4654 +0 1 0 2.747 132.4655 +0 0 0 2.671 132.4656 +0 1 0 2.651 132.4657 +0 0 0 2.571 132.4658 +0 1 0 2.551 132.4659 +0 0 0 2.475 132.4660 +0 1 0 2.457 132.4661 +0 0 0 2.391 132.4662 +0 1 0 2.375 132.4663 +0 0 0 2.313 132.4664 +0 1 0 2.293 132.4665 +0 0 0 2.165 132.4666 +0 1 0 2.145 132.4667 +0 0 0 2.085 132.4668 +0 1 0 2.071 132.4669 +0 0 0 2.003 132.4670 +0 1 0 1.989 132.4671 +0 0 0 1.933 132.4672 +0 1 0 1.911 132.4673 +0 0 0 1.843 132.4674 +0 1 0 1.827 132.4675 +0 0 0 1.719 132.4676 +0 1 0 1.703 132.4677 +0 0 0 1.645 132.4678 +0 1 0 1.629 132.4679 +0 0 0 1.551 132.4680 +0 1 0 1.535 132.4681 +0 0 0 1.463 132.4682 +0 1 0 1.421 132.4683 +0 0 0 1.303 132.4684 +0 1 0 1.287 132.4685 +0 0 0 1.229 132.4686 +0 1 0 1.213 132.4687 +0 0 0 1.089 132.4688 +0 1 0 1.075 132.4689 +0 0 0 1.075 132.4690 +0 0 1 1.075 132.4691 +0 1 1 1.089 132.4692 +0 0 1 1.213 132.4693 +0 1 1 1.229 132.4694 +0 0 1 1.287 132.4695 +0 1 1 1.303 132.4696 +0 0 1 1.431 132.4697 +0 1 1 1.467 132.4698 +0 0 1 1.535 132.4699 +0 1 1 1.551 132.4700 +0 0 1 1.629 132.4701 +0 1 1 1.645 132.4702 +0 0 1 1.703 132.4703 +0 1 1 1.719 132.4704 +0 0 1 1.825 132.4705 +0 1 1 1.843 132.4706 +0 0 1 1.909 132.4707 +0 1 1 1.933 132.4708 +0 0 1 1.989 132.4709 +0 1 1 2.003 132.4710 +0 0 1 2.069 132.4711 +0 1 1 2.085 132.4712 +0 0 1 2.145 132.4713 +0 1 1 2.163 132.4714 +0 0 1 2.297 132.4715 +0 1 1 2.315 132.4716 +0 0 1 2.375 132.4717 +0 1 1 2.391 132.4718 +0 0 1 2.457 132.4719 +0 1 1 2.475 132.4720 +0 0 1 2.553 132.4721 +0 1 1 2.573 132.4722 +0 0 1 2.649 132.4723 +0 1 1 2.669 132.4724 +0 0 1 2.747 132.4725 +0 1 1 2.765 132.4726 +0 0 1 2.911 132.4727 +0 1 1 2.925 132.4728 +0 0 1 2.925 132.4729 +0 0 0 2.925 132.4730 +0 1 0 2.911 132.4731 +0 0 0 2.763 132.4732 +0 1 0 2.745 132.4733 +0 0 0 2.667 132.4734 +0 1 0 2.647 132.4735 +0 0 0 2.575 132.4736 +0 1 0 2.555 132.4737 +0 0 0 2.477 132.4738 +0 1 0 2.459 132.4739 +0 0 0 2.391 132.4740 +0 1 0 2.375 132.4741 +0 0 0 2.315 132.4742 +0 1 0 2.299 132.4743 +0 0 0 2.161 132.4744 +0 1 0 2.145 132.4745 +0 0 0 2.085 132.4746 +0 1 0 2.069 132.4747 +0 0 0 2.003 132.4748 +0 1 0 1.989 132.4749 +0 0 0 1.933 132.4750 +0 1 0 1.909 132.4751 +0 0 0 1.841 132.4752 +0 1 0 1.825 132.4753 +0 0 0 1.719 132.4754 +0 1 0 1.703 132.4755 +0 0 0 1.645 132.4756 +0 1 0 1.629 132.4757 +0 0 0 1.553 132.4758 +0 1 0 1.537 132.4759 +0 0 0 1.467 132.4760 +0 1 0 1.439 132.4761 +0 0 0 1.303 132.4762 +0 1 0 1.287 132.4763 +0 0 0 1.229 132.4764 +0 1 0 1.213 132.4765 +0 0 0 1.089 132.4766 +0 1 0 1.075 132.4767 +0 0 0 1.075 132.4768 +0 0 1 1.075 132.4769 +0 1 1 1.089 132.4770 +0 0 1 1.213 132.4771 +0 1 1 1.229 132.4772 +0 0 1 1.287 132.4773 +0 1 1 1.303 132.4774 +0 0 1 1.443 132.4775 +0 1 1 1.469 132.4776 +0 0 1 1.537 132.4777 +0 1 1 1.553 132.4778 +0 0 1 1.629 132.4779 +0 1 1 1.645 132.4780 +0 0 1 1.703 132.4781 +0 1 1 1.719 132.4782 +0 0 1 1.823 132.4783 +0 1 1 1.841 132.4784 +0 0 1 1.909 132.4785 +0 1 1 1.933 132.4786 +0 0 1 1.989 132.4787 +0 1 1 2.003 132.4788 +0 0 1 2.069 132.4789 +0 1 1 2.085 132.4790 +0 0 1 2.143 132.4791 +0 1 1 2.161 132.4792 +0 0 1 2.299 132.4793 +0 1 1 2.317 132.4794 +0 0 1 2.375 132.4795 +0 1 1 2.391 132.4796 +0 0 1 2.461 132.4797 +0 1 1 2.479 132.4798 +0 0 1 2.557 132.4799 +0 1 1 2.577 132.4800 +0 0 1 2.645 132.4801 +0 1 1 2.665 132.4802 +0 0 1 2.743 132.4803 +0 1 1 2.761 132.4804 +0 0 1 2.911 132.4805 +0 1 1 2.925 132.4806 +0 0 1 2.925 132.4807 +0 0 0 2.925 132.4808 +0 1 0 2.911 132.4809 +0 0 0 2.761 132.4810 +0 1 0 2.743 132.4811 +0 0 0 2.665 132.4812 +0 1 0 2.643 132.4813 +0 0 0 2.579 132.4814 +0 1 0 2.559 132.4815 +0 0 0 2.479 132.4816 +0 1 0 2.461 132.4817 +0 0 0 2.393 132.4818 +0 1 0 2.377 132.4819 +0 0 0 2.317 132.4820 +0 1 0 2.301 132.4821 +0 0 0 2.159 132.4822 +0 1 0 2.143 132.4823 +0 0 0 2.085 132.4824 +0 1 0 2.069 132.4825 +0 0 0 2.003 132.4826 +0 1 0 1.989 132.4827 +0 0 0 1.933 132.4828 +0 1 0 1.907 132.4829 +0 0 0 1.839 132.4830 +0 1 0 1.823 132.4831 +0 0 0 1.719 132.4832 +0 1 0 1.703 132.4833 +0 0 0 1.645 132.4834 +0 1 0 1.629 132.4835 +0 0 0 1.553 132.4836 +0 1 0 1.537 132.4837 +0 0 0 1.471 132.4838 +0 1 0 1.449 132.4839 +0 0 0 1.303 132.4840 +0 1 0 1.287 132.4841 +0 0 0 1.229 132.4842 +0 1 0 1.213 132.4843 +0 0 0 1.089 132.4844 +0 1 0 1.075 132.4845 +0 0 0 1.075 132.4846 +0 0 1 1.075 132.4847 +0 1 1 1.089 132.4848 +0 0 1 1.213 132.4849 +0 1 1 1.229 132.4850 +0 0 1 1.287 132.4851 +0 1 1 1.303 132.4852 +0 0 1 1.451 132.4853 +0 1 1 1.473 132.4854 +0 0 1 1.537 132.4855 +0 1 1 1.553 132.4856 +0 0 1 1.629 132.4857 +0 1 1 1.645 132.4858 +0 0 1 1.703 132.4859 +0 1 1 1.719 132.4860 +0 0 1 1.821 132.4861 +0 1 1 1.839 132.4862 +0 0 1 1.907 132.4863 +0 1 1 1.933 132.4864 +0 0 1 1.989 132.4865 +0 1 1 2.003 132.4866 +0 0 1 2.069 132.4867 +0 1 1 2.085 132.4868 +0 0 1 2.143 132.4869 +0 1 1 2.159 132.4870 +0 0 1 2.301 132.4871 +0 1 1 2.319 132.4872 +0 0 1 2.377 132.4873 +0 1 1 2.393 132.4874 +0 0 1 2.463 132.4875 +0 1 1 2.481 132.4876 +0 0 1 2.561 132.4877 +0 1 1 2.581 132.4878 +0 0 1 2.643 132.4879 +0 1 1 2.663 132.4880 +0 0 1 2.741 132.4881 +0 1 1 2.759 132.4882 +0 0 1 2.911 132.4883 +0 1 1 2.925 132.4884 +0 0 1 2.925 132.4885 +0 0 0 2.925 132.4886 +0 1 0 2.911 132.4887 +0 0 0 2.757 132.4888 +0 1 0 2.739 132.4889 +0 0 0 2.661 132.4890 +0 1 0 2.641 132.4891 +0 0 0 2.581 132.4892 +0 1 0 2.561 132.4893 +0 0 0 2.483 132.4894 +0 1 0 2.465 132.4895 +0 0 0 2.393 132.4896 +0 1 0 2.377 132.4897 +0 0 0 2.319 132.4898 +0 1 0 2.303 132.4899 +0 0 0 2.157 132.4900 +0 1 0 2.141 132.4901 +0 0 0 2.083 132.4902 +0 1 0 2.069 132.4903 +0 0 0 2.003 132.4904 +0 1 0 1.989 132.4905 +0 0 0 1.933 132.4906 +0 1 0 1.905 132.4907 +0 0 0 1.837 132.4908 +0 1 0 1.821 132.4909 +0 0 0 1.719 132.4910 +0 1 0 1.703 132.4911 +0 0 0 1.645 132.4912 +0 1 0 1.629 132.4913 +0 0 0 1.555 132.4914 +0 1 0 1.539 132.4915 +0 0 0 1.475 132.4916 +0 1 0 1.453 132.4917 +0 0 0 1.303 132.4918 +0 1 0 1.287 132.4919 +0 0 0 1.229 132.4920 +0 1 0 1.213 132.4921 +0 0 0 1.089 132.4922 +0 1 0 1.075 132.4923 +0 0 0 1.075 132.4924 +0 0 1 1.075 132.4925 +0 1 1 1.089 132.4926 +0 0 1 1.213 132.4927 +0 1 1 1.229 132.4928 +0 0 1 1.287 132.4929 +0 1 1 1.303 132.4930 +0 0 1 1.457 132.4931 +0 1 1 1.475 132.4932 +0 0 1 1.539 132.4933 +0 1 1 1.555 132.4934 +0 0 1 1.629 132.4935 +0 1 1 1.645 132.4936 +0 0 1 1.703 132.4937 +0 1 1 1.719 132.4938 +0 0 1 1.819 132.4939 +0 1 1 1.837 132.4940 +0 0 1 1.905 132.4941 +0 1 1 1.933 132.4942 +0 0 1 1.989 132.4943 +0 1 1 2.003 132.4944 +0 0 1 2.069 132.4945 +0 1 1 2.083 132.4946 +0 0 1 2.141 132.4947 +0 1 1 2.157 132.4948 +0 0 1 2.303 132.4949 +0 1 1 2.319 132.4950 +0 0 1 2.377 132.4951 +0 1 1 2.393 132.4952 +0 0 1 2.467 132.4953 +0 1 1 2.485 132.4954 +0 0 1 2.563 132.4955 +0 1 1 2.583 132.4956 +0 0 1 2.639 132.4957 +0 1 1 2.659 132.4958 +0 0 1 2.739 132.4959 +0 1 1 2.755 132.4960 +0 0 1 2.911 132.4961 +0 1 1 2.925 132.4962 +0 0 1 2.925 132.4963 +0 0 0 2.925 132.4964 +0 1 0 2.911 132.4965 +0 0 0 2.755 132.4966 +0 1 0 2.737 132.4967 +0 0 0 2.657 132.4968 +0 1 0 2.637 132.4969 +0 0 0 2.585 132.4970 +0 1 0 2.565 132.4971 +0 0 0 2.485 132.4972 +0 1 0 2.467 132.4973 +0 0 0 2.393 132.4974 +0 1 0 2.377 132.4975 +0 0 0 2.319 132.4976 +0 1 0 2.303 132.4977 +0 0 0 2.157 132.4978 +0 1 0 2.141 132.4979 +0 0 0 2.083 132.4980 +0 1 0 2.069 132.4981 +0 0 0 2.003 132.4982 +0 1 0 1.989 132.4983 +0 0 0 1.933 132.4984 +0 1 0 1.903 132.4985 +0 0 0 1.835 132.4986 +0 1 0 1.817 132.4987 +0 0 0 1.719 132.4988 +0 1 0 1.703 132.4989 +0 0 0 1.645 132.4990 +0 1 0 1.629 132.4991 +0 0 0 1.555 132.4992 +0 1 0 1.539 132.4993 +0 0 0 1.477 132.4994 +0 1 0 1.457 132.4995 +0 0 0 1.303 132.4996 +0 1 0 1.287 132.4997 +0 0 0 1.229 132.4998 +0 1 0 1.213 132.4999 +0 0 0 1.089 132.5000 +0 1 0 1.075 132.5001 +0 0 0 1.075 132.5002 +0 0 1 1.075 132.5003 +0 1 1 1.089 132.5004 +0 0 1 1.213 132.5005 +0 1 1 1.229 132.5006 +0 0 1 1.287 132.5007 +0 1 1 1.303 132.5008 +0 0 1 1.459 132.5009 +0 1 1 1.477 132.5010 +0 0 1 1.539 132.5011 +0 1 1 1.555 132.5012 +0 0 1 1.629 132.5013 +0 1 1 1.645 132.5014 +0 0 1 1.703 132.5015 +0 1 1 1.719 132.5016 +0 0 1 1.817 132.5017 +0 1 1 1.835 132.5018 +0 0 1 1.903 132.5019 +0 1 1 1.931 132.5020 +0 0 1 1.989 132.5021 +0 1 1 2.003 132.5022 +0 0 1 2.067 132.5023 +0 1 1 2.083 132.5024 +0 0 1 2.141 132.5025 +0 1 1 2.157 132.5026 +0 0 1 2.305 132.5027 +0 1 1 2.319 132.5028 +0 0 1 2.377 132.5029 +0 1 1 2.393 132.5030 +0 0 1 2.469 132.5031 +0 1 1 2.487 132.5032 +0 0 1 2.567 132.5033 +0 1 1 2.587 132.5034 +0 0 1 2.635 132.5035 +0 1 1 2.655 132.5036 +0 0 1 2.735 132.5037 +0 1 1 2.753 132.5038 +0 0 1 2.911 132.5039 +0 1 1 2.925 132.5040 +0 0 1 2.925 132.5041 +0 0 0 2.925 132.5042 +0 1 0 2.911 132.5043 +0 0 0 2.753 132.5044 +0 1 0 2.735 132.5045 +0 0 0 2.653 132.5046 +0 1 0 2.633 132.5047 +0 0 0 2.589 132.5048 +0 1 0 2.569 132.5049 +0 0 0 2.489 132.5050 +0 1 0 2.471 132.5051 +0 0 0 2.393 132.5052 +0 1 0 2.377 132.5053 +0 0 0 2.321 132.5054 +0 1 0 2.305 132.5055 +0 0 0 2.155 132.5056 +0 1 0 2.141 132.5057 +0 0 0 2.083 132.5058 +0 1 0 2.067 132.5059 +0 0 0 2.003 132.5060 +0 1 0 1.989 132.5061 +0 0 0 1.931 132.5062 +0 1 0 1.901 132.5063 +0 0 0 1.833 132.5064 +0 1 0 1.815 132.5065 +0 0 0 1.719 132.5066 +0 1 0 1.703 132.5067 +0 0 0 1.645 132.5068 +0 1 0 1.629 132.5069 +0 0 0 1.555 132.5070 +0 1 0 1.539 132.5071 +0 0 0 1.479 132.5072 +0 1 0 1.461 132.5073 +0 0 0 1.303 132.5074 +0 1 0 1.287 132.5075 +0 0 0 1.229 132.5076 +0 1 0 1.213 132.5077 +0 0 0 1.089 132.5078 +0 1 0 1.075 132.5079 +0 0 0 1.075 132.5080 +0 0 1 1.075 132.5081 +0 1 1 1.089 132.5082 +0 0 1 1.213 132.5083 +0 1 1 1.229 132.5084 +0 0 1 1.287 132.5085 +0 1 1 1.303 132.5086 +0 0 1 1.463 132.5087 +0 1 1 1.479 132.5088 +0 0 1 1.541 132.5089 +0 1 1 1.555 132.5090 +0 0 1 1.629 132.5091 +0 1 1 1.645 132.5092 +0 0 1 1.703 132.5093 +0 1 1 1.719 132.5094 +0 0 1 1.815 132.5095 +0 1 1 1.833 132.5096 +0 0 1 1.901 132.5097 +0 1 1 1.931 132.5098 +0 0 1 1.989 132.5099 +0 1 1 2.003 132.5100 +0 0 1 2.067 132.5101 +0 1 1 2.083 132.5102 +0 0 1 2.139 132.5103 +0 1 1 2.155 132.5104 +0 0 1 2.305 132.5105 +0 1 1 2.321 132.5106 +0 0 1 2.377 132.5107 +0 1 1 2.393 132.5108 +0 0 1 2.471 132.5109 +0 1 1 2.489 132.5110 +0 0 1 2.571 132.5111 +0 1 1 2.591 132.5112 +0 0 1 2.631 132.5113 +0 1 1 2.651 132.5114 +0 0 1 2.733 132.5115 +0 1 1 2.751 132.5116 +0 0 1 2.911 132.5117 +0 1 1 2.925 132.5118 +0 0 1 2.925 132.5119 +0 0 0 2.925 132.5120 +0 1 0 2.911 132.5121 +0 0 0 2.749 132.5122 +0 1 0 2.731 132.5123 +0 0 0 2.649 132.5124 +0 1 0 2.629 132.5125 +0 0 0 2.593 132.5126 +0 1 0 2.573 132.5127 +0 0 0 2.491 132.5128 +0 1 0 2.473 132.5129 +0 0 0 2.393 132.5130 +0 1 0 2.379 132.5131 +0 0 0 2.321 132.5132 +0 1 0 2.305 132.5133 +0 0 0 2.155 132.5134 +0 1 0 2.139 132.5135 +0 0 0 2.083 132.5136 +0 1 0 2.067 132.5137 +0 0 0 2.003 132.5138 +0 1 0 1.989 132.5139 +0 0 0 1.931 132.5140 +0 1 0 1.899 132.5141 +0 0 0 1.831 132.5142 +0 1 0 1.815 132.5143 +0 0 0 1.719 132.5144 +0 1 0 1.703 132.5145 +0 0 0 1.645 132.5146 +0 1 0 1.629 132.5147 +0 0 0 1.557 132.5148 +0 1 0 1.541 132.5149 +0 0 0 1.479 132.5150 +0 1 0 1.463 132.5151 +0 0 0 1.303 132.5152 +0 1 0 1.287 132.5153 +0 0 0 1.229 132.5154 +0 1 0 1.213 132.5155 +0 0 0 1.089 132.5156 +0 1 0 1.075 132.5157 +0 0 0 1.075 132.5158 +0 0 1 1.075 132.5159 +0 1 1 1.089 132.5160 +0 0 1 1.213 132.5161 +0 1 1 1.229 132.5162 +0 0 1 1.287 132.5163 +0 1 1 1.303 132.5164 +0 0 1 1.463 132.5165 +0 1 1 1.481 132.5166 +0 0 1 1.541 132.5167 +0 1 1 1.557 132.5168 +0 0 1 1.629 132.5169 +0 1 1 1.645 132.5170 +0 0 1 1.703 132.5171 +0 1 1 1.719 132.5172 +0 0 1 1.813 132.5173 +0 1 1 1.831 132.5174 +0 0 1 1.899 132.5175 +0 1 1 1.931 132.5176 +0 0 1 1.989 132.5177 +0 1 1 2.003 132.5178 +0 0 1 2.067 132.5179 +0 1 1 2.083 132.5180 +0 0 1 2.139 132.5181 +0 1 1 2.155 132.5182 +0 0 1 2.305 132.5183 +0 1 1 2.321 132.5184 +0 0 1 2.379 132.5185 +0 1 1 2.393 132.5186 +0 0 1 2.475 132.5187 +0 1 1 2.493 132.5188 +0 0 1 2.575 132.5189 +0 1 1 2.595 132.5190 +0 0 1 2.627 132.5191 +0 1 1 2.647 132.5192 +0 0 1 2.729 132.5193 +0 1 1 2.747 132.5194 +0 0 1 2.911 132.5195 +0 1 1 2.925 132.5196 +0 0 1 2.925 132.5197 +0 0 0 2.925 132.5198 +0 1 0 2.911 132.5199 +0 0 0 2.747 132.5200 +0 1 0 2.729 132.5201 +0 0 0 2.647 132.5202 +0 1 0 2.625 132.5203 +0 0 0 2.597 132.5204 +0 1 0 2.577 132.5205 +0 0 0 2.493 132.5206 +0 1 0 2.475 132.5207 +0 0 0 2.393 132.5208 +0 1 0 2.379 132.5209 +0 0 0 2.321 132.5210 +0 1 0 2.305 132.5211 +0 0 0 2.155 132.5212 +0 1 0 2.139 132.5213 +0 0 0 2.083 132.5214 +0 1 0 2.067 132.5215 +0 0 0 2.003 132.5216 +0 1 0 1.989 132.5217 +0 0 0 1.931 132.5218 +0 1 0 1.897 132.5219 +0 0 0 1.829 132.5220 +0 1 0 1.811 132.5221 +0 0 0 1.719 132.5222 +0 1 0 1.703 132.5223 +0 0 0 1.645 132.5224 +0 1 0 1.629 132.5225 +0 0 0 1.557 132.5226 +0 1 0 1.541 132.5227 +0 0 0 1.481 132.5228 +0 1 0 1.465 132.5229 +0 0 0 1.303 132.5230 +0 1 0 1.287 132.5231 +0 0 0 1.229 132.5232 +0 1 0 1.213 132.5233 +0 0 0 1.089 132.5234 +0 1 0 1.075 132.5235 +0 0 0 1.075 132.5236 +0 0 1 1.075 132.5237 +0 1 1 1.089 132.5238 +0 0 1 1.213 132.5239 +0 1 1 1.229 132.5240 +0 0 1 1.287 132.5241 +0 1 1 1.303 132.5242 +0 0 1 1.465 132.5243 +0 1 1 1.481 132.5244 +0 0 1 1.541 132.5245 +0 1 1 1.557 132.5246 +0 0 1 1.629 132.5247 +0 1 1 1.645 132.5248 +0 0 1 1.703 132.5249 +0 1 1 1.719 132.5250 +0 0 1 1.811 132.5251 +0 1 1 1.829 132.5252 +0 0 1 1.897 132.5253 +0 1 1 1.931 132.5254 +0 0 1 1.989 132.5255 +0 1 1 2.003 132.5256 +0 0 1 2.067 132.5257 +0 1 1 2.083 132.5258 +0 0 1 2.139 132.5259 +0 1 1 2.155 132.5260 +0 0 1 2.305 132.5261 +0 1 1 2.321 132.5262 +0 0 1 2.379 132.5263 +0 1 1 2.393 132.5264 +0 0 1 2.477 132.5265 +0 1 1 2.495 132.5266 +0 0 1 2.579 132.5267 +0 1 1 2.599 132.5268 +0 0 1 2.625 132.5269 +0 1 1 2.645 132.5270 +0 0 1 2.727 132.5271 +0 1 1 2.745 132.5272 +0 0 1 2.911 132.5273 +0 1 1 2.925 132.5274 +0 0 1 2.925 132.5275 +0 0 0 2.925 132.5276 +0 1 0 2.911 132.5277 +0 0 0 2.743 132.5278 +0 1 0 2.725 132.5279 +0 0 0 2.643 132.5280 +0 1 0 2.623 132.5281 +0 0 0 2.601 132.5282 +0 1 0 2.579 132.5283 +0 0 0 2.497 132.5284 +0 1 0 2.479 132.5285 +0 0 0 2.393 132.5286 +0 1 0 2.379 132.5287 +0 0 0 2.321 132.5288 +0 1 0 2.307 132.5289 +0 0 0 2.155 132.5290 +0 1 0 2.139 132.5291 +0 0 0 2.083 132.5292 +0 1 0 2.067 132.5293 +0 0 0 2.003 132.5294 +0 1 0 1.989 132.5295 +0 0 0 1.931 132.5296 +0 1 0 1.915 132.5297 +0 0 0 1.913 132.5298 +0 1 0 1.897 132.5299 +0 0 0 1.827 132.5300 +0 1 0 1.809 132.5301 +0 0 0 1.719 132.5302 +0 1 0 1.703 132.5303 +0 0 0 1.645 132.5304 +0 1 0 1.629 132.5305 +0 0 0 1.557 132.5306 +0 1 0 1.543 132.5307 +0 0 0 1.481 132.5308 +0 1 0 1.467 132.5309 +0 0 0 1.303 132.5310 +0 1 0 1.287 132.5311 +0 0 0 1.229 132.5312 +0 1 0 1.213 132.5313 +0 0 0 1.089 132.5314 +0 1 0 1.075 132.5315 +0 0 0 1.075 132.5316 +0 0 1 1.075 132.5317 +0 1 1 1.089 132.5318 +0 0 1 1.213 132.5319 +0 1 1 1.229 132.5320 +0 0 1 1.287 132.5321 +0 1 1 1.303 132.5322 +0 0 1 1.467 132.5323 +0 1 1 1.483 132.5324 +0 0 1 1.543 132.5325 +0 1 1 1.557 132.5326 +0 0 1 1.629 132.5327 +0 1 1 1.645 132.5328 +0 0 1 1.703 132.5329 +0 1 1 1.719 132.5330 +0 0 1 1.809 132.5331 +0 1 1 1.827 132.5332 +0 0 1 1.895 132.5333 +0 1 1 1.913 132.5334 +0 0 1 1.915 132.5335 +0 1 1 1.931 132.5336 +0 0 1 1.989 132.5337 +0 1 1 2.003 132.5338 +0 0 1 2.067 132.5339 +0 1 1 2.083 132.5340 +0 0 1 2.139 132.5341 +0 1 1 2.155 132.5342 +0 0 1 2.307 132.5343 +0 1 1 2.321 132.5344 +0 0 1 2.379 132.5345 +0 1 1 2.395 132.5346 +0 0 1 2.481 132.5347 +0 1 1 2.497 132.5348 +0 0 1 2.581 132.5349 +0 1 1 2.601 132.5350 +0 0 1 2.621 132.5351 +0 1 1 2.641 132.5352 +0 0 1 2.725 132.5353 +0 1 1 2.743 132.5354 +0 0 1 2.911 132.5355 +0 1 1 2.925 132.5356 +0 0 1 2.925 132.5357 +0 0 0 2.925 132.5358 +0 1 0 2.911 132.5359 +0 0 0 2.741 132.5360 +0 1 0 2.723 132.5361 +0 0 0 2.639 132.5362 +0 1 0 2.619 132.5363 +0 0 0 2.603 132.5364 +0 1 0 2.583 132.5365 +0 0 0 2.499 132.5366 +0 1 0 2.481 132.5367 +0 0 0 2.395 132.5368 +0 1 0 2.379 132.5369 +0 0 0 2.321 132.5370 +0 1 0 2.307 132.5371 +0 0 0 2.155 132.5372 +0 1 0 2.139 132.5373 +0 0 0 2.083 132.5374 +0 1 0 2.067 132.5375 +0 0 0 2.003 132.5376 +0 1 0 1.989 132.5377 +0 0 0 1.931 132.5378 +0 1 0 1.915 132.5379 +0 0 0 1.911 132.5380 +0 1 0 1.895 132.5381 +0 0 0 1.825 132.5382 +0 1 0 1.807 132.5383 +0 0 0 1.719 132.5384 +0 1 0 1.703 132.5385 +0 0 0 1.645 132.5386 +0 1 0 1.629 132.5387 +0 0 0 1.559 132.5388 +0 1 0 1.543 132.5389 +0 0 0 1.483 132.5390 +0 1 0 1.467 132.5391 +0 0 0 1.303 132.5392 +0 1 0 1.287 132.5393 +0 0 0 1.229 132.5394 +0 1 0 1.213 132.5395 +0 0 0 1.089 132.5396 +0 1 0 1.075 132.5397 +0 0 0 1.075 132.5398 +0 0 1 1.075 132.5399 +0 1 1 1.089 132.5400 +0 0 1 1.213 132.5401 +0 1 1 1.229 132.5402 +0 0 1 1.287 132.5403 +0 1 1 1.303 132.5404 +0 0 1 1.467 132.5405 +0 1 1 1.483 132.5406 +0 0 1 1.543 132.5407 +0 1 1 1.559 132.5408 +0 0 1 1.629 132.5409 +0 1 1 1.645 132.5410 +0 0 1 1.703 132.5411 +0 1 1 1.719 132.5412 +0 0 1 1.807 132.5413 +0 1 1 1.823 132.5414 +0 0 1 1.893 132.5415 +0 1 1 1.911 132.5416 +0 0 1 1.915 132.5417 +0 1 1 1.931 132.5418 +0 0 1 1.989 132.5419 +0 1 1 2.003 132.5420 +0 0 1 2.067 132.5421 +0 1 1 2.083 132.5422 +0 0 1 2.139 132.5423 +0 1 1 2.155 132.5424 +0 0 1 2.307 132.5425 +0 1 1 2.321 132.5426 +0 0 1 2.379 132.5427 +0 1 1 2.395 132.5428 +0 0 1 2.483 132.5429 +0 1 1 2.501 132.5430 +0 0 1 2.585 132.5431 +0 1 1 2.605 132.5432 +0 0 1 2.617 132.5433 +0 1 1 2.637 132.5434 +0 0 1 2.721 132.5435 +0 1 1 2.739 132.5436 +0 0 1 2.911 132.5437 +0 1 1 2.925 132.5438 +0 0 1 2.925 132.5439 +0 0 0 2.925 132.5440 +0 1 0 2.911 132.5441 +0 0 0 2.739 132.5442 +0 1 0 2.721 132.5443 +0 0 0 2.635 132.5444 +0 1 0 2.615 132.5445 +0 0 0 2.607 132.5446 +0 1 0 2.587 132.5447 +0 0 0 2.503 132.5448 +0 1 0 2.485 132.5449 +0 0 0 2.395 132.5450 +0 1 0 2.379 132.5451 +0 0 0 2.321 132.5452 +0 1 0 2.307 132.5453 +0 0 0 2.155 132.5454 +0 1 0 2.139 132.5455 +0 0 0 2.083 132.5456 +0 1 0 2.067 132.5457 +0 0 0 2.003 132.5458 +0 1 0 1.989 132.5459 +0 0 0 1.931 132.5460 +0 1 0 1.915 132.5461 +0 0 0 1.909 132.5462 +0 1 0 1.893 132.5463 +0 0 0 1.823 132.5464 +0 1 0 1.805 132.5465 +0 0 0 1.719 132.5466 +0 1 0 1.703 132.5467 +0 0 0 1.645 132.5468 +0 1 0 1.629 132.5469 +0 0 0 1.559 132.5470 +0 1 0 1.543 132.5471 +0 0 0 1.485 132.5472 +0 1 0 1.469 132.5473 +0 0 0 1.303 132.5474 +0 1 0 1.287 132.5475 +0 0 0 1.229 132.5476 +0 1 0 1.213 132.5477 +0 0 0 1.089 132.5478 +0 1 0 1.075 132.5479 +0 0 0 1.075 132.5480 +0 0 1 1.075 132.5481 +0 1 1 1.089 132.5482 +0 0 1 1.213 132.5483 +0 1 1 1.229 132.5484 +0 0 1 1.287 132.5485 +0 1 1 1.303 132.5486 +0 0 1 1.469 132.5487 +0 1 1 1.485 132.5488 +0 0 1 1.543 132.5489 +0 1 1 1.559 132.5490 +0 0 1 1.629 132.5491 +0 1 1 1.645 132.5492 +0 0 1 1.703 132.5493 +0 1 1 1.719 132.5494 +0 0 1 1.805 132.5495 +0 1 1 1.821 132.5496 +0 0 1 1.891 132.5497 +0 1 1 1.909 132.5498 +0 0 1 1.915 132.5499 +0 1 1 1.931 132.5500 +0 0 1 1.989 132.5501 +0 1 1 2.003 132.5502 +0 0 1 2.067 132.5503 +0 1 1 2.083 132.5504 +0 0 1 2.139 132.5505 +0 1 1 2.155 132.5506 +0 0 1 2.307 132.5507 +0 1 1 2.321 132.5508 +0 0 1 2.379 132.5509 +0 1 1 2.395 132.5510 +0 0 1 2.485 132.5511 +0 1 1 2.503 132.5512 +0 0 1 2.589 132.5513 +0 1 1 2.609 132.5514 +0 0 1 2.615 132.5515 +0 1 1 2.633 132.5516 +0 0 1 2.719 132.5517 +0 1 1 2.737 132.5518 +0 0 1 2.911 132.5519 +0 1 1 2.925 132.5520 +0 0 1 2.925 132.5521 +0 0 0 2.925 132.5522 +0 1 0 2.911 132.5523 +0 0 0 2.735 132.5524 +0 1 0 2.717 132.5525 +0 0 0 2.631 132.5526 +0 1 0 2.617 132.5527 +0 0 0 2.611 132.5528 +0 1 0 2.591 132.5529 +0 0 0 2.505 132.5530 +0 1 0 2.487 132.5531 +0 0 0 2.395 132.5532 +0 1 0 2.379 132.5533 +0 0 0 2.321 132.5534 +0 1 0 2.307 132.5535 +0 0 0 2.155 132.5536 +0 1 0 2.137 132.5537 +0 0 0 2.085 132.5538 +0 1 0 2.067 132.5539 +0 0 0 2.003 132.5540 +0 1 0 1.989 132.5541 +0 0 0 1.931 132.5542 +0 1 0 1.915 132.5543 +0 0 0 1.907 132.5544 +0 1 0 1.891 132.5545 +0 0 0 1.821 132.5546 +0 1 0 1.803 132.5547 +0 0 0 1.719 132.5548 +0 1 0 1.703 132.5549 +0 0 0 1.645 132.5550 +0 1 0 1.629 132.5551 +0 0 0 1.559 132.5552 +0 1 0 1.543 132.5553 +0 0 0 1.485 132.5554 +0 1 0 1.469 132.5555 +0 0 0 1.303 132.5556 +0 1 0 1.287 132.5557 +0 0 0 1.229 132.5558 +0 1 0 1.213 132.5559 +0 0 0 1.089 132.5560 +0 1 0 1.075 132.5561 +0 0 0 1.075 132.5562 +0 0 1 1.075 132.5563 +0 1 1 1.089 132.5564 +0 0 1 1.213 132.5565 +0 1 1 1.229 132.5566 +0 0 1 1.287 132.5567 +0 1 1 1.303 132.5568 +0 0 1 1.469 132.5569 +0 1 1 1.485 132.5570 +0 0 1 1.543 132.5571 +0 1 1 1.559 132.5572 +0 0 1 1.629 132.5573 +0 1 1 1.645 132.5574 +0 0 1 1.703 132.5575 +0 1 1 1.719 132.5576 +0 0 1 1.803 132.5577 +0 1 1 1.819 132.5578 +0 0 1 1.889 132.5579 +0 1 1 1.907 132.5580 +0 0 1 1.915 132.5581 +0 1 1 1.931 132.5582 +0 0 1 1.989 132.5583 +0 1 1 2.003 132.5584 +0 0 1 2.067 132.5585 +0 1 1 2.153 132.5586 +0 0 1 2.307 132.5587 +0 1 1 2.321 132.5588 +0 0 1 2.379 132.5589 +0 1 1 2.395 132.5590 +0 0 1 2.489 132.5591 +0 1 1 2.507 132.5592 +0 0 1 2.593 132.5593 +0 1 1 2.613 132.5594 +0 0 1 2.619 132.5595 +0 1 1 2.629 132.5596 +0 0 1 2.717 132.5597 +0 1 1 2.735 132.5598 +0 0 1 2.911 132.5599 +0 1 1 2.925 132.5600 +0 0 1 2.925 132.5601 +0 0 0 2.925 132.5602 +0 1 0 2.911 132.5603 +0 0 0 2.733 132.5604 +0 1 0 2.715 132.5605 +0 0 0 2.629 132.5606 +0 1 0 2.621 132.5607 +0 0 0 2.615 132.5608 +0 1 0 2.595 132.5609 +0 0 0 2.507 132.5610 +0 1 0 2.489 132.5611 +0 0 0 2.395 132.5612 +0 1 0 2.379 132.5613 +0 0 0 2.321 132.5614 +0 1 0 2.307 132.5615 +0 0 0 2.153 132.5616 +0 1 0 2.067 132.5617 +0 0 0 2.003 132.5618 +0 1 0 1.989 132.5619 +0 0 0 1.931 132.5620 +0 1 0 1.915 132.5621 +0 0 0 1.905 132.5622 +0 1 0 1.889 132.5623 +0 0 0 1.819 132.5624 +0 1 0 1.801 132.5625 +0 0 0 1.719 132.5626 +0 1 0 1.703 132.5627 +0 0 0 1.645 132.5628 +0 1 0 1.629 132.5629 +0 0 0 1.559 132.5630 +0 1 0 1.545 132.5631 +0 0 0 1.485 132.5632 +0 1 0 1.469 132.5633 +0 0 0 1.303 132.5634 +0 1 0 1.287 132.5635 +0 0 0 1.229 132.5636 +0 1 0 1.213 132.5637 +0 0 0 1.089 132.5638 +0 1 0 1.075 132.5639 +0 0 0 1.075 132.5640 +0 0 1 1.075 132.5641 +0 1 1 1.089 132.5642 +0 0 1 1.213 132.5643 +0 1 1 1.229 132.5644 +0 0 1 1.287 132.5645 +0 1 1 1.303 132.5646 +0 0 1 1.471 132.5647 +0 1 1 1.485 132.5648 +0 0 1 1.545 132.5649 +0 1 1 1.561 132.5650 +0 0 1 1.629 132.5651 +0 1 1 1.645 132.5652 +0 0 1 1.703 132.5653 +0 1 1 1.719 132.5654 +0 0 1 1.801 132.5655 +0 1 1 1.817 132.5656 +0 0 1 1.887 132.5657 +0 1 1 1.905 132.5658 +0 0 1 1.915 132.5659 +0 1 1 1.931 132.5660 +0 0 1 1.989 132.5661 +0 1 1 2.003 132.5662 +0 0 1 2.067 132.5663 +0 1 1 2.153 132.5664 +0 0 1 2.307 132.5665 +0 1 1 2.321 132.5666 +0 0 1 2.379 132.5667 +0 1 1 2.395 132.5668 +0 0 1 2.491 132.5669 +0 1 1 2.509 132.5670 +0 0 1 2.597 132.5671 +0 1 1 2.617 132.5672 +0 0 1 2.621 132.5673 +0 1 1 2.627 132.5674 +0 0 1 2.713 132.5675 +0 1 1 2.731 132.5676 +0 0 1 2.911 132.5677 +0 1 1 2.925 132.5678 +0 0 1 2.925 132.5679 +0 0 0 2.925 132.5680 +0 1 0 2.911 132.5681 +0 0 0 2.729 132.5682 +0 1 0 2.711 132.5683 +0 0 0 2.617 132.5684 +0 1 0 2.599 132.5685 +0 0 0 2.511 132.5686 +0 1 0 2.493 132.5687 +0 0 0 2.395 132.5688 +0 1 0 2.379 132.5689 +0 0 0 2.321 132.5690 +0 1 0 2.307 132.5691 +0 0 0 2.153 132.5692 +0 1 0 2.067 132.5693 +0 0 0 2.003 132.5694 +0 1 0 1.989 132.5695 +0 0 0 1.931 132.5696 +0 1 0 1.915 132.5697 +0 0 0 1.903 132.5698 +0 1 0 1.887 132.5699 +0 0 0 1.817 132.5700 +0 1 0 1.799 132.5701 +0 0 0 1.719 132.5702 +0 1 0 1.703 132.5703 +0 0 0 1.645 132.5704 +0 1 0 1.629 132.5705 +0 0 0 1.561 132.5706 +0 1 0 1.545 132.5707 +0 0 0 1.487 132.5708 +0 1 0 1.471 132.5709 +0 0 0 1.303 132.5710 +0 1 0 1.287 132.5711 +0 0 0 1.229 132.5712 +0 1 0 1.213 132.5713 +0 0 0 1.089 132.5714 +0 1 0 1.075 132.5715 +0 0 0 1.075 132.5716 +0 0 1 1.075 132.5717 +0 1 1 1.089 132.5718 +0 0 1 1.213 132.5719 +0 1 1 1.229 132.5720 +0 0 1 1.287 132.5721 +0 1 1 1.303 132.5722 +0 0 1 1.471 132.5723 +0 1 1 1.487 132.5724 +0 0 1 1.545 132.5725 +0 1 1 1.561 132.5726 +0 0 1 1.629 132.5727 +0 1 1 1.645 132.5728 +0 0 1 1.703 132.5729 +0 1 1 1.719 132.5730 +0 0 1 1.799 132.5731 +0 1 1 1.815 132.5732 +0 0 1 1.885 132.5733 +0 1 1 1.903 132.5734 +0 0 1 1.915 132.5735 +0 1 1 1.931 132.5736 +0 0 1 1.989 132.5737 +0 1 1 2.003 132.5738 +0 0 1 2.067 132.5739 +0 1 1 2.153 132.5740 +0 0 1 2.307 132.5741 +0 1 1 2.321 132.5742 +0 0 1 2.379 132.5743 +0 1 1 2.395 132.5744 +0 0 1 2.493 132.5745 +0 1 1 2.511 132.5746 +0 0 1 2.599 132.5747 +0 1 1 2.619 132.5748 +0 0 1 2.711 132.5749 +0 1 1 2.729 132.5750 +0 0 1 2.911 132.5751 +0 1 1 2.925 132.5752 +0 0 1 2.925 132.5753 +0 0 0 2.925 132.5754 +0 1 0 2.911 132.5755 +0 0 0 2.727 132.5756 +0 1 0 2.709 132.5757 +0 0 0 2.621 132.5758 +0 1 0 2.601 132.5759 +0 0 0 2.513 132.5760 +0 1 0 2.495 132.5761 +0 0 0 2.395 132.5762 +0 1 0 2.379 132.5763 +0 0 0 2.321 132.5764 +0 1 0 2.305 132.5765 +0 0 0 2.153 132.5766 +0 1 0 2.069 132.5767 +0 0 0 2.003 132.5768 +0 1 0 1.989 132.5769 +0 0 0 1.931 132.5770 +0 1 0 1.915 132.5771 +0 0 0 1.903 132.5772 +0 1 0 1.885 132.5773 +0 0 0 1.815 132.5774 +0 1 0 1.797 132.5775 +0 0 0 1.719 132.5776 +0 1 0 1.703 132.5777 +0 0 0 1.645 132.5778 +0 1 0 1.629 132.5779 +0 0 0 1.561 132.5780 +0 1 0 1.545 132.5781 +0 0 0 1.487 132.5782 +0 1 0 1.471 132.5783 +0 0 0 1.303 132.5784 +0 1 0 1.287 132.5785 +0 0 0 1.229 132.5786 +0 1 0 1.213 132.5787 +0 0 0 1.089 132.5788 +0 1 0 1.075 132.5789 +0 0 0 1.075 132.5790 +0 0 1 1.075 132.5791 +0 1 1 1.089 132.5792 +0 0 1 1.213 132.5793 +0 1 1 1.229 132.5794 +0 0 1 1.287 132.5795 +0 1 1 1.303 132.5796 +0 0 1 1.471 132.5797 +0 1 1 1.487 132.5798 +0 0 1 1.545 132.5799 +0 1 1 1.561 132.5800 +0 0 1 1.629 132.5801 +0 1 1 1.645 132.5802 +0 0 1 1.703 132.5803 +0 1 1 1.719 132.5804 +0 0 1 1.797 132.5805 +0 1 1 1.813 132.5806 +0 0 1 1.883 132.5807 +0 1 1 1.901 132.5808 +0 0 1 1.915 132.5809 +0 1 1 1.931 132.5810 +0 0 1 1.989 132.5811 +0 1 1 2.003 132.5812 +0 0 1 2.071 132.5813 +0 1 1 2.151 132.5814 +0 0 1 2.305 132.5815 +0 1 1 2.321 132.5816 +0 0 1 2.379 132.5817 +0 1 1 2.395 132.5818 +0 0 1 2.497 132.5819 +0 1 1 2.515 132.5820 +0 0 1 2.603 132.5821 +0 1 1 2.623 132.5822 +0 0 1 2.707 132.5823 +0 1 1 2.725 132.5824 +0 0 1 2.911 132.5825 +0 1 1 2.925 132.5826 +0 0 1 2.925 132.5827 +0 0 0 2.925 132.5828 +0 1 0 2.911 132.5829 +0 0 0 2.725 132.5830 +0 1 0 2.707 132.5831 +0 0 0 2.625 132.5832 +0 1 0 2.605 132.5833 +0 0 0 2.599 132.5834 +0 1 0 2.597 132.5835 +0 0 0 2.515 132.5836 +0 1 0 2.499 132.5837 +0 0 0 2.395 132.5838 +0 1 0 2.379 132.5839 +0 0 0 2.321 132.5840 +0 1 0 2.305 132.5841 +0 0 0 2.003 132.5842 +0 1 0 1.989 132.5843 +0 0 0 1.931 132.5844 +0 1 0 1.915 132.5845 +0 0 0 1.901 132.5846 +0 1 0 1.883 132.5847 +0 0 0 1.813 132.5848 +0 1 0 1.795 132.5849 +0 0 0 1.719 132.5850 +0 1 0 1.703 132.5851 +0 0 0 1.645 132.5852 +0 1 0 1.629 132.5853 +0 0 0 1.561 132.5854 +0 1 0 1.545 132.5855 +0 0 0 1.487 132.5856 +0 1 0 1.471 132.5857 +0 0 0 1.303 132.5858 +0 1 0 1.287 132.5859 +0 0 0 1.229 132.5860 +0 1 0 1.213 132.5861 +0 0 0 1.089 132.5862 +0 1 0 1.075 132.5863 +0 0 0 1.075 132.5864 +0 0 1 1.075 132.5865 +0 1 1 1.089 132.5866 +0 0 1 1.213 132.5867 +0 1 1 1.229 132.5868 +0 0 1 1.287 132.5869 +0 1 1 1.303 132.5870 +0 0 1 1.473 132.5871 +0 1 1 1.487 132.5872 +0 0 1 1.545 132.5873 +0 1 1 1.561 132.5874 +0 0 1 1.629 132.5875 +0 1 1 1.645 132.5876 +0 0 1 1.703 132.5877 +0 1 1 1.719 132.5878 +0 0 1 1.795 132.5879 +0 1 1 1.811 132.5880 +0 0 1 1.883 132.5881 +0 1 1 1.899 132.5882 +0 0 1 1.915 132.5883 +0 1 1 1.931 132.5884 +0 0 1 1.989 132.5885 +0 1 1 2.003 132.5886 +0 0 1 2.305 132.5887 +0 1 1 2.321 132.5888 +0 0 1 2.379 132.5889 +0 1 1 2.393 132.5890 +0 0 1 2.499 132.5891 +0 1 1 2.517 132.5892 +0 0 1 2.595 132.5893 +0 1 1 2.601 132.5894 +0 0 1 2.607 132.5895 +0 1 1 2.627 132.5896 +0 0 1 2.705 132.5897 +0 1 1 2.723 132.5898 +0 0 1 2.911 132.5899 +0 1 1 2.925 132.5900 +0 0 1 2.925 132.5901 +0 0 0 2.925 132.5902 +0 1 0 2.911 132.5903 +0 0 0 2.721 132.5904 +0 1 0 2.703 132.5905 +0 0 0 2.629 132.5906 +0 1 0 2.609 132.5907 +0 0 0 2.603 132.5908 +0 1 0 2.593 132.5909 +0 0 0 2.519 132.5910 +0 1 0 2.501 132.5911 +0 0 0 2.393 132.5912 +0 1 0 2.379 132.5913 +0 0 0 2.321 132.5914 +0 1 0 2.305 132.5915 +0 0 0 2.003 132.5916 +0 1 0 1.989 132.5917 +0 0 0 1.931 132.5918 +0 1 0 1.915 132.5919 +0 0 0 1.899 132.5920 +0 1 0 1.881 132.5921 +0 0 0 1.811 132.5922 +0 1 0 1.793 132.5923 +0 0 0 1.719 132.5924 +0 1 0 1.703 132.5925 +0 0 0 1.645 132.5926 +0 1 0 1.629 132.5927 +0 0 0 1.561 132.5928 +0 1 0 1.545 132.5929 +0 0 0 1.487 132.5930 +0 1 0 1.473 132.5931 +0 0 0 1.303 132.5932 +0 1 0 1.287 132.5933 +0 0 0 1.229 132.5934 +0 1 0 1.213 132.5935 +0 0 0 1.089 132.5936 +0 1 0 1.075 132.5937 +0 0 0 1.075 132.5938 +0 0 1 1.075 132.5939 +0 1 1 1.089 132.5940 +0 0 1 1.213 132.5941 +0 1 1 1.229 132.5942 +0 0 1 1.287 132.5943 +0 1 1 1.303 132.5944 +0 0 1 1.473 132.5945 +0 1 1 1.487 132.5946 +0 0 1 1.547 132.5947 +0 1 1 1.561 132.5948 +0 0 1 1.629 132.5949 +0 1 1 1.645 132.5950 +0 0 1 1.703 132.5951 +0 1 1 1.719 132.5952 +0 0 1 1.791 132.5953 +0 1 1 1.809 132.5954 +0 0 1 1.881 132.5955 +0 1 1 1.897 132.5956 +0 0 1 1.915 132.5957 +0 1 1 1.931 132.5958 +0 0 1 1.989 132.5959 +0 1 1 2.003 132.5960 +0 0 1 2.305 132.5961 +0 1 1 2.319 132.5962 +0 0 1 2.379 132.5963 +0 1 1 2.393 132.5964 +0 0 1 2.503 132.5965 +0 1 1 2.519 132.5966 +0 0 1 2.593 132.5967 +0 1 1 2.605 132.5968 +0 0 1 2.611 132.5969 +0 1 1 2.631 132.5970 +0 0 1 2.703 132.5971 +0 1 1 2.721 132.5972 +0 0 1 2.911 132.5973 +0 1 1 2.925 132.5974 +0 0 1 2.925 132.5975 +0 0 0 2.925 132.5976 +0 1 0 2.911 132.5977 +0 0 0 2.719 132.5978 +0 1 0 2.701 132.5979 +0 0 0 2.631 132.5980 +0 1 0 2.613 132.5981 +0 0 0 2.607 132.5982 +0 1 0 2.591 132.5983 +0 0 0 2.521 132.5984 +0 1 0 2.503 132.5985 +0 0 0 2.393 132.5986 +0 1 0 2.379 132.5987 +0 0 0 2.319 132.5988 +0 1 0 2.303 132.5989 +0 0 0 2.003 132.5990 +0 1 0 1.989 132.5991 +0 0 0 1.931 132.5992 +0 1 0 1.915 132.5993 +0 0 0 1.897 132.5994 +0 1 0 1.879 132.5995 +0 0 0 1.809 132.5996 +0 1 0 1.791 132.5997 +0 0 0 1.719 132.5998 +0 1 0 1.703 132.5999 +0 0 0 1.645 132.6000 +0 1 0 1.629 132.6001 +0 0 0 1.561 132.6002 +0 1 0 1.547 132.6003 +0 0 0 1.487 132.6004 +0 1 0 1.473 132.6005 +0 0 0 1.303 132.6006 +0 1 0 1.287 132.6007 +0 0 0 1.229 132.6008 +0 1 0 1.213 132.6009 +0 0 0 1.089 132.6010 +0 1 0 1.075 132.6011 +0 0 0 1.075 132.6012 +0 0 1 1.075 132.6013 +0 1 1 1.089 132.6014 +0 0 1 1.213 132.6015 +0 1 1 1.229 132.6016 +0 0 1 1.287 132.6017 +0 1 1 1.303 132.6018 +0 0 1 1.473 132.6019 +0 1 1 1.489 132.6020 +0 0 1 1.547 132.6021 +0 1 1 1.561 132.6022 +0 0 1 1.629 132.6023 +0 1 1 1.645 132.6024 +0 0 1 1.703 132.6025 +0 1 1 1.719 132.6026 +0 0 1 1.791 132.6027 +0 1 1 1.807 132.6028 +0 0 1 1.879 132.6029 +0 1 1 1.895 132.6030 +0 0 1 1.915 132.6031 +0 1 1 1.931 132.6032 +0 0 1 1.989 132.6033 +0 1 1 2.003 132.6034 +0 0 1 2.303 132.6035 +0 1 1 2.319 132.6036 +0 0 1 2.379 132.6037 +0 1 1 2.393 132.6038 +0 0 1 2.505 132.6039 +0 1 1 2.523 132.6040 +0 0 1 2.589 132.6041 +0 1 1 2.607 132.6042 +0 0 1 2.615 132.6043 +0 1 1 2.633 132.6044 +0 0 1 2.699 132.6045 +0 1 1 2.717 132.6046 +0 0 1 2.911 132.6047 +0 1 1 2.925 132.6048 +0 0 1 2.925 132.6049 +0 0 0 2.925 132.6050 +0 1 0 2.911 132.6051 +0 0 0 2.717 132.6052 +0 1 0 2.699 132.6053 +0 0 0 2.635 132.6054 +0 1 0 2.615 132.6055 +0 0 0 2.607 132.6056 +0 1 0 2.587 132.6057 +0 0 0 2.525 132.6058 +0 1 0 2.507 132.6059 +0 0 0 2.393 132.6060 +0 1 0 2.377 132.6061 +0 0 0 2.319 132.6062 +0 1 0 2.301 132.6063 +0 0 0 2.003 132.6064 +0 1 0 1.989 132.6065 +0 0 0 1.931 132.6066 +0 1 0 1.915 132.6067 +0 0 0 1.895 132.6068 +0 1 0 1.877 132.6069 +0 0 0 1.807 132.6070 +0 1 0 1.789 132.6071 +0 0 0 1.719 132.6072 +0 1 0 1.703 132.6073 +0 0 0 1.645 132.6074 +0 1 0 1.629 132.6075 +0 0 0 1.561 132.6076 +0 1 0 1.547 132.6077 +0 0 0 1.489 132.6078 +0 1 0 1.473 132.6079 +0 0 0 1.303 132.6080 +0 1 0 1.287 132.6081 +0 0 0 1.229 132.6082 +0 1 0 1.213 132.6083 +0 0 0 1.089 132.6084 +0 1 0 1.075 132.6085 +0 0 0 1.075 132.6086 +0 0 1 1.075 132.6087 +0 1 1 1.089 132.6088 +0 0 1 1.213 132.6089 +0 1 1 1.229 132.6090 +0 0 1 1.287 132.6091 +0 1 1 1.303 132.6092 +0 0 1 1.473 132.6093 +0 1 1 1.489 132.6094 +0 0 1 1.547 132.6095 +0 1 1 1.563 132.6096 +0 0 1 1.629 132.6097 +0 1 1 1.645 132.6098 +0 0 1 1.703 132.6099 +0 1 1 1.719 132.6100 +0 0 1 1.787 132.6101 +0 1 1 1.805 132.6102 +0 0 1 1.877 132.6103 +0 1 1 1.893 132.6104 +0 0 1 1.915 132.6105 +0 1 1 1.931 132.6106 +0 0 1 1.989 132.6107 +0 1 1 2.003 132.6108 +0 0 1 2.301 132.6109 +0 1 1 2.317 132.6110 +0 0 1 2.377 132.6111 +0 1 1 2.393 132.6112 +0 0 1 2.507 132.6113 +0 1 1 2.525 132.6114 +0 0 1 2.585 132.6115 +0 1 1 2.605 132.6116 +0 0 1 2.617 132.6117 +0 1 1 2.637 132.6118 +0 0 1 2.697 132.6119 +0 1 1 2.715 132.6120 +0 0 1 2.911 132.6121 +0 1 1 2.925 132.6122 +0 0 1 2.925 132.6123 +0 0 0 2.925 132.6124 +0 1 0 2.911 132.6125 +0 0 0 2.713 132.6126 +0 1 0 2.695 132.6127 +0 0 0 2.639 132.6128 +0 1 0 2.619 132.6129 +0 0 0 2.603 132.6130 +0 1 0 2.583 132.6131 +0 0 0 2.527 132.6132 +0 1 0 2.509 132.6133 +0 0 0 2.393 132.6134 +0 1 0 2.377 132.6135 +0 0 0 2.317 132.6136 +0 1 0 2.299 132.6137 +0 0 0 2.003 132.6138 +0 1 0 1.989 132.6139 +0 0 0 1.931 132.6140 +0 1 0 1.915 132.6141 +0 0 0 1.893 132.6142 +0 1 0 1.875 132.6143 +0 0 0 1.805 132.6144 +0 1 0 1.787 132.6145 +0 0 0 1.719 132.6146 +0 1 0 1.703 132.6147 +0 0 0 1.645 132.6148 +0 1 0 1.629 132.6149 +0 0 0 1.563 132.6150 +0 1 0 1.547 132.6151 +0 0 0 1.489 132.6152 +0 1 0 1.473 132.6153 +0 0 0 1.303 132.6154 +0 1 0 1.287 132.6155 +0 0 0 1.229 132.6156 +0 1 0 1.213 132.6157 +0 0 0 1.089 132.6158 +0 1 0 1.075 132.6159 +0 0 0 1.075 132.6160 +0 0 1 1.075 132.6161 +0 1 1 1.089 132.6162 +0 0 1 1.213 132.6163 +0 1 1 1.229 132.6164 +0 0 1 1.287 132.6165 +0 1 1 1.303 132.6166 +0 0 1 1.473 132.6167 +0 1 1 1.489 132.6168 +0 0 1 1.547 132.6169 +0 1 1 1.563 132.6170 +0 0 1 1.629 132.6171 +0 1 1 1.645 132.6172 +0 0 1 1.703 132.6173 +0 1 1 1.719 132.6174 +0 0 1 1.785 132.6175 +0 1 1 1.803 132.6176 +0 0 1 1.875 132.6177 +0 1 1 1.891 132.6178 +0 0 1 1.915 132.6179 +0 1 1 1.931 132.6180 +0 0 1 1.989 132.6181 +0 1 1 2.003 132.6182 +0 0 1 2.295 132.6183 +0 1 1 2.315 132.6184 +0 0 1 2.377 132.6185 +0 1 1 2.393 132.6186 +0 0 1 2.511 132.6187 +0 1 1 2.529 132.6188 +0 0 1 2.621 132.6189 +0 1 1 2.641 132.6190 +0 0 1 2.693 132.6191 +0 1 1 2.711 132.6192 +0 0 1 2.911 132.6193 +0 1 1 2.925 132.6194 +0 0 1 2.925 132.6195 +0 0 0 2.925 132.6196 +0 1 0 2.911 132.6197 +0 0 0 2.711 132.6198 +0 1 0 2.693 132.6199 +0 0 0 2.643 132.6200 +0 1 0 2.623 132.6201 +0 0 0 2.529 132.6202 +0 1 0 2.511 132.6203 +0 0 0 2.393 132.6204 +0 1 0 2.377 132.6205 +0 0 0 2.315 132.6206 +0 1 0 2.291 132.6207 +0 0 0 2.003 132.6208 +0 1 0 1.989 132.6209 +0 0 0 1.931 132.6210 +0 1 0 1.915 132.6211 +0 0 0 1.891 132.6212 +0 1 0 1.873 132.6213 +0 0 0 1.803 132.6214 +0 1 0 1.785 132.6215 +0 0 0 1.719 132.6216 +0 1 0 1.703 132.6217 +0 0 0 1.645 132.6218 +0 1 0 1.629 132.6219 +0 0 0 1.563 132.6220 +0 1 0 1.547 132.6221 +0 0 0 1.489 132.6222 +0 1 0 1.473 132.6223 +0 0 0 1.303 132.6224 +0 1 0 1.287 132.6225 +0 0 0 1.229 132.6226 +0 1 0 1.213 132.6227 +0 0 0 1.089 132.6228 +0 1 0 1.075 132.6229 +0 0 0 1.075 132.6230 +0 0 1 1.075 132.6231 +0 1 1 1.089 132.6232 +0 0 1 1.213 132.6233 +0 1 1 1.229 132.6234 +0 0 1 1.287 132.6235 +0 1 1 1.303 132.6236 +0 0 1 1.473 132.6237 +0 1 1 1.489 132.6238 +0 0 1 1.547 132.6239 +0 1 1 1.563 132.6240 +0 0 1 1.629 132.6241 +0 1 1 1.645 132.6242 +0 0 1 1.703 132.6243 +0 1 1 1.719 132.6244 +0 0 1 1.783 132.6245 +0 1 1 1.801 132.6246 +0 0 1 1.873 132.6247 +0 1 1 1.889 132.6248 +0 0 1 1.915 132.6249 +0 1 1 1.931 132.6250 +0 0 1 1.989 132.6251 +0 1 1 2.003 132.6252 +0 0 1 2.281 132.6253 +0 1 1 2.313 132.6254 +0 0 1 2.377 132.6255 +0 1 1 2.393 132.6256 +0 0 1 2.513 132.6257 +0 1 1 2.531 132.6258 +0 0 1 2.579 132.6259 +0 1 1 2.619 132.6260 +0 0 1 2.625 132.6261 +0 1 1 2.645 132.6262 +0 0 1 2.691 132.6263 +0 1 1 2.709 132.6264 +0 0 1 2.911 132.6265 +0 1 1 2.925 132.6266 +0 0 1 2.925 132.6267 +0 0 0 2.925 132.6268 +0 1 0 2.911 132.6269 +0 0 0 2.707 132.6270 +0 1 0 2.691 132.6271 +0 0 0 2.645 132.6272 +0 1 0 2.627 132.6273 +0 0 0 2.621 132.6274 +0 1 0 2.577 132.6275 +0 0 0 2.533 132.6276 +0 1 0 2.515 132.6277 +0 0 0 2.393 132.6278 +0 1 0 2.377 132.6279 +0 0 0 2.313 132.6280 +0 1 0 2.269 132.6281 +0 0 0 2.003 132.6282 +0 1 0 1.989 132.6283 +0 0 0 1.931 132.6284 +0 1 0 1.915 132.6285 +0 0 0 1.889 132.6286 +0 1 0 1.871 132.6287 +0 0 0 1.801 132.6288 +0 1 0 1.783 132.6289 +0 0 0 1.719 132.6290 +0 1 0 1.703 132.6291 +0 0 0 1.645 132.6292 +0 1 0 1.629 132.6293 +0 0 0 1.563 132.6294 +0 1 0 1.547 132.6295 +0 0 0 1.489 132.6296 +0 1 0 1.473 132.6297 +0 0 0 1.303 132.6298 +0 1 0 1.287 132.6299 +0 0 0 1.229 132.6300 +0 1 0 1.213 132.6301 +0 0 0 1.089 132.6302 +0 1 0 1.075 132.6303 +0 0 0 1.075 132.6304 +0 0 1 1.075 132.6305 +0 1 1 1.089 132.6306 +0 0 1 1.213 132.6307 +0 1 1 1.229 132.6308 +0 0 1 1.287 132.6309 +0 1 1 1.303 132.6310 +0 0 1 1.475 132.6311 +0 1 1 1.489 132.6312 +0 0 1 1.547 132.6313 +0 1 1 1.563 132.6314 +0 0 1 1.629 132.6315 +0 1 1 1.645 132.6316 +0 0 1 1.703 132.6317 +0 1 1 1.719 132.6318 +0 0 1 1.781 132.6319 +0 1 1 1.799 132.6320 +0 0 1 1.871 132.6321 +0 1 1 1.887 132.6322 +0 0 1 1.915 132.6323 +0 1 1 1.931 132.6324 +0 0 1 1.989 132.6325 +0 1 1 2.003 132.6326 +0 0 1 2.243 132.6327 +0 1 1 2.311 132.6328 +0 0 1 2.375 132.6329 +0 1 1 2.391 132.6330 +0 0 1 2.517 132.6331 +0 1 1 2.533 132.6332 +0 0 1 2.575 132.6333 +0 1 1 2.623 132.6334 +0 0 1 2.629 132.6335 +0 1 1 2.647 132.6336 +0 0 1 2.689 132.6337 +0 1 1 2.707 132.6338 +0 0 1 2.911 132.6339 +0 1 1 2.925 132.6340 +0 0 1 2.925 132.6341 +0 0 0 2.925 132.6342 +0 1 0 2.911 132.6343 +0 0 0 2.705 132.6344 +0 1 0 2.687 132.6345 +0 0 0 2.647 132.6346 +0 1 0 2.629 132.6347 +0 0 0 2.625 132.6348 +0 1 0 2.573 132.6349 +0 0 0 2.535 132.6350 +0 1 0 2.517 132.6351 +0 0 0 2.391 132.6352 +0 1 0 2.375 132.6353 +0 0 0 2.307 132.6354 +0 1 0 2.207 132.6355 +0 0 0 2.003 132.6356 +0 1 0 1.989 132.6357 +0 0 0 1.931 132.6358 +0 1 0 1.915 132.6359 +0 0 0 1.887 132.6360 +0 1 0 1.869 132.6361 +0 0 0 1.797 132.6362 +0 1 0 1.781 132.6363 +0 0 0 1.719 132.6364 +0 1 0 1.703 132.6365 +0 0 0 1.645 132.6366 +0 1 0 1.629 132.6367 +0 0 0 1.563 132.6368 +0 1 0 1.547 132.6369 +0 0 0 1.489 132.6370 +0 1 0 1.475 132.6371 +0 0 0 1.303 132.6372 +0 1 0 1.287 132.6373 +0 0 0 1.229 132.6374 +0 1 0 1.213 132.6375 +0 0 0 1.089 132.6376 +0 1 0 1.075 132.6377 +0 0 0 1.075 132.6378 +0 0 1 1.075 132.6379 +0 1 1 1.089 132.6380 +0 0 1 1.213 132.6381 +0 1 1 1.229 132.6382 +0 0 1 1.287 132.6383 +0 1 1 1.303 132.6384 +0 0 1 1.475 132.6385 +0 1 1 1.489 132.6386 +0 0 1 1.547 132.6387 +0 1 1 1.563 132.6388 +0 0 1 1.629 132.6389 +0 1 1 1.645 132.6390 +0 0 1 1.703 132.6391 +0 1 1 1.719 132.6392 +0 0 1 1.779 132.6393 +0 1 1 1.797 132.6394 +0 0 1 1.869 132.6395 +0 1 1 1.885 132.6396 +0 0 1 1.915 132.6397 +0 1 1 1.931 132.6398 +0 0 1 1.989 132.6399 +0 1 1 2.003 132.6400 +0 0 1 2.185 132.6401 +0 1 1 2.305 132.6402 +0 0 1 2.375 132.6403 +0 1 1 2.391 132.6404 +0 0 1 2.519 132.6405 +0 1 1 2.537 132.6406 +0 0 1 2.571 132.6407 +0 1 1 2.625 132.6408 +0 0 1 2.631 132.6409 +0 1 1 2.649 132.6410 +0 0 1 2.685 132.6411 +0 1 1 2.703 132.6412 +0 0 1 2.911 132.6413 +0 1 1 2.925 132.6414 +0 0 1 2.925 132.6415 +0 0 0 2.925 132.6416 +0 1 0 2.911 132.6417 +0 0 0 2.703 132.6418 +0 1 0 2.685 132.6419 +0 0 0 2.649 132.6420 +0 1 0 2.633 132.6421 +0 0 0 2.627 132.6422 +0 1 0 2.569 132.6423 +0 0 0 2.537 132.6424 +0 1 0 2.521 132.6425 +0 0 0 2.391 132.6426 +0 1 0 2.375 132.6427 +0 0 0 2.301 132.6428 +0 1 0 2.169 132.6429 +0 0 0 2.003 132.6430 +0 1 0 1.989 132.6431 +0 0 0 1.931 132.6432 +0 1 0 1.915 132.6433 +0 0 0 1.885 132.6434 +0 1 0 1.867 132.6435 +0 0 0 1.797 132.6436 +0 1 0 1.779 132.6437 +0 0 0 1.719 132.6438 +0 1 0 1.703 132.6439 +0 0 0 1.645 132.6440 +0 1 0 1.629 132.6441 +0 0 0 1.563 132.6442 +0 1 0 1.549 132.6443 +0 0 0 1.489 132.6444 +0 1 0 1.475 132.6445 +0 0 0 1.303 132.6446 +0 1 0 1.287 132.6447 +0 0 0 1.229 132.6448 +0 1 0 1.213 132.6449 +0 0 0 1.089 132.6450 +0 1 0 1.075 132.6451 +0 0 0 1.075 132.6452 +0 0 1 1.075 132.6453 +0 1 1 1.089 132.6454 +0 0 1 1.213 132.6455 +0 1 1 1.229 132.6456 +0 0 1 1.287 132.6457 +0 1 1 1.303 132.6458 +0 0 1 1.475 132.6459 +0 1 1 1.489 132.6460 +0 0 1 1.549 132.6461 +0 1 1 1.563 132.6462 +0 0 1 1.629 132.6463 +0 1 1 1.645 132.6464 +0 0 1 1.703 132.6465 +0 1 1 1.719 132.6466 +0 0 1 1.777 132.6467 +0 1 1 1.795 132.6468 +0 0 1 1.867 132.6469 +0 1 1 1.883 132.6470 +0 0 1 1.915 132.6471 +0 1 1 1.931 132.6472 +0 0 1 1.989 132.6473 +0 1 1 2.003 132.6474 +0 0 1 2.155 132.6475 +0 1 1 2.297 132.6476 +0 0 1 2.375 132.6477 +0 1 1 2.389 132.6478 +0 0 1 2.521 132.6479 +0 1 1 2.539 132.6480 +0 0 1 2.567 132.6481 +0 1 1 2.629 132.6482 +0 0 1 2.635 132.6483 +0 1 1 2.649 132.6484 +0 0 1 2.653 132.6485 +0 1 1 2.655 132.6486 +0 0 1 2.683 132.6487 +0 1 1 2.701 132.6488 +0 0 1 2.911 132.6489 +0 1 1 2.925 132.6490 +0 0 1 2.925 132.6491 +0 0 0 2.925 132.6492 +0 1 0 2.911 132.6493 +0 0 0 2.699 132.6494 +0 1 0 2.681 132.6495 +0 0 0 2.657 132.6496 +0 1 0 2.653 132.6497 +0 0 0 2.649 132.6498 +0 1 0 2.635 132.6499 +0 0 0 2.629 132.6500 +0 1 0 2.565 132.6501 +0 0 0 2.541 132.6502 +0 1 0 2.523 132.6503 +0 0 0 2.389 132.6504 +0 1 0 2.373 132.6505 +0 0 0 2.291 132.6506 +0 1 0 2.145 132.6507 +0 0 0 2.003 132.6508 +0 1 0 1.989 132.6509 +0 0 0 1.931 132.6510 +0 1 0 1.915 132.6511 +0 0 0 1.883 132.6512 +0 1 0 1.865 132.6513 +0 0 0 1.793 132.6514 +0 1 0 1.777 132.6515 +0 0 0 1.719 132.6516 +0 1 0 1.703 132.6517 +0 0 0 1.645 132.6518 +0 1 0 1.629 132.6519 +0 0 0 1.563 132.6520 +0 1 0 1.549 132.6521 +0 0 0 1.489 132.6522 +0 1 0 1.475 132.6523 +0 0 0 1.303 132.6524 +0 1 0 1.287 132.6525 +0 0 0 1.229 132.6526 +0 1 0 1.213 132.6527 +0 0 0 1.089 132.6528 +0 1 0 1.075 132.6529 +0 0 0 1.075 132.6530 +0 0 1 1.075 132.6531 +0 1 1 1.089 132.6532 +0 0 1 1.213 132.6533 +0 1 1 1.229 132.6534 +0 0 1 1.287 132.6535 +0 1 1 1.303 132.6536 +0 0 1 1.475 132.6537 +0 1 1 1.489 132.6538 +0 0 1 1.549 132.6539 +0 1 1 1.563 132.6540 +0 0 1 1.629 132.6541 +0 1 1 1.645 132.6542 +0 0 1 1.703 132.6543 +0 1 1 1.719 132.6544 +0 0 1 1.775 132.6545 +0 1 1 1.793 132.6546 +0 0 1 1.865 132.6547 +0 1 1 1.881 132.6548 +0 0 1 1.915 132.6549 +0 1 1 1.931 132.6550 +0 0 1 1.989 132.6551 +0 1 1 2.003 132.6552 +0 0 1 2.137 132.6553 +0 1 1 2.281 132.6554 +0 0 1 2.373 132.6555 +0 1 1 2.389 132.6556 +0 0 1 2.525 132.6557 +0 1 1 2.543 132.6558 +0 0 1 2.563 132.6559 +0 1 1 2.585 132.6560 +0 0 1 2.635 132.6561 +0 1 1 2.649 132.6562 +0 0 1 2.653 132.6563 +0 1 1 2.659 132.6564 +0 0 1 2.681 132.6565 +0 1 1 2.697 132.6566 +0 0 1 2.911 132.6567 +0 1 1 2.925 132.6568 +0 0 1 2.925 132.6569 +0 0 0 2.925 132.6570 +0 1 0 2.911 132.6571 +0 0 0 2.697 132.6572 +0 1 0 2.679 132.6573 +0 0 0 2.661 132.6574 +0 1 0 2.653 132.6575 +0 0 0 2.649 132.6576 +0 1 0 2.635 132.6577 +0 0 0 2.581 132.6578 +0 1 0 2.561 132.6579 +0 0 0 2.543 132.6580 +0 1 0 2.525 132.6581 +0 0 0 2.389 132.6582 +0 1 0 2.373 132.6583 +0 0 0 2.263 132.6584 +0 1 0 2.129 132.6585 +0 0 0 2.003 132.6586 +0 1 0 1.989 132.6587 +0 0 0 1.931 132.6588 +0 1 0 1.915 132.6589 +0 0 0 1.881 132.6590 +0 1 0 1.863 132.6591 +0 0 0 1.791 132.6592 +0 1 0 1.775 132.6593 +0 0 0 1.719 132.6594 +0 1 0 1.703 132.6595 +0 0 0 1.645 132.6596 +0 1 0 1.629 132.6597 +0 0 0 1.563 132.6598 +0 1 0 1.549 132.6599 +0 0 0 1.489 132.6600 +0 1 0 1.475 132.6601 +0 0 0 1.303 132.6602 +0 1 0 1.287 132.6603 +0 0 0 1.229 132.6604 +0 1 0 1.213 132.6605 +0 0 0 1.089 132.6606 +0 1 0 1.075 132.6607 +0 0 0 1.075 132.6608 +0 0 1 1.075 132.6609 +0 1 1 1.089 132.6610 +0 0 1 1.213 132.6611 +0 1 1 1.229 132.6612 +0 0 1 1.287 132.6613 +0 1 1 1.303 132.6614 +0 0 1 1.475 132.6615 +0 1 1 1.491 132.6616 +0 0 1 1.549 132.6617 +0 1 1 1.563 132.6618 +0 0 1 1.629 132.6619 +0 1 1 1.645 132.6620 +0 0 1 1.703 132.6621 +0 1 1 1.719 132.6622 +0 0 1 1.773 132.6623 +0 1 1 1.791 132.6624 +0 0 1 1.863 132.6625 +0 1 1 1.879 132.6626 +0 0 1 1.915 132.6627 +0 1 1 1.931 132.6628 +0 0 1 1.989 132.6629 +0 1 1 2.003 132.6630 +0 0 1 2.121 132.6631 +0 1 1 2.231 132.6632 +0 0 1 2.371 132.6633 +0 1 1 2.387 132.6634 +0 0 1 2.527 132.6635 +0 1 1 2.545 132.6636 +0 0 1 2.559 132.6637 +0 1 1 2.579 132.6638 +0 0 1 2.635 132.6639 +0 1 1 2.649 132.6640 +0 0 1 2.653 132.6641 +0 1 1 2.663 132.6642 +0 0 1 2.677 132.6643 +0 1 1 2.695 132.6644 +0 0 1 2.911 132.6645 +0 1 1 2.925 132.6646 +0 0 1 2.925 132.6647 +0 0 0 2.925 132.6648 +0 1 0 2.911 132.6649 +0 0 0 2.693 132.6650 +0 1 0 2.677 132.6651 +0 0 0 2.665 132.6652 +0 1 0 2.653 132.6653 +0 0 0 2.649 132.6654 +0 1 0 2.635 132.6655 +0 0 0 2.589 132.6656 +0 1 0 2.585 132.6657 +0 0 0 2.579 132.6658 +0 1 0 2.557 132.6659 +0 0 0 2.547 132.6660 +0 1 0 2.529 132.6661 +0 0 0 2.387 132.6662 +0 1 0 2.371 132.6663 +0 0 0 2.205 132.6664 +0 1 0 2.117 132.6665 +0 0 0 2.003 132.6666 +0 1 0 1.989 132.6667 +0 0 0 1.931 132.6668 +0 1 0 1.915 132.6669 +0 0 0 1.879 132.6670 +0 1 0 1.861 132.6671 +0 0 0 1.789 132.6672 +0 1 0 1.773 132.6673 +0 0 0 1.719 132.6674 +0 1 0 1.703 132.6675 +0 0 0 1.645 132.6676 +0 1 0 1.629 132.6677 +0 0 0 1.563 132.6678 +0 1 0 1.549 132.6679 +0 0 0 1.491 132.6680 +0 1 0 1.475 132.6681 +0 0 0 1.303 132.6682 +0 1 0 1.287 132.6683 +0 0 0 1.229 132.6684 +0 1 0 1.213 132.6685 +0 0 0 1.089 132.6686 +0 1 0 1.075 132.6687 +0 0 0 1.075 132.6688 +0 0 1 1.075 132.6689 +0 1 1 1.089 132.6690 +0 0 1 1.213 132.6691 +0 1 1 1.229 132.6692 +0 0 1 1.287 132.6693 +0 1 1 1.303 132.6694 +0 0 1 1.475 132.6695 +0 1 1 1.491 132.6696 +0 0 1 1.549 132.6697 +0 1 1 1.563 132.6698 +0 0 1 1.629 132.6699 +0 1 1 1.645 132.6700 +0 0 1 1.703 132.6701 +0 1 1 1.719 132.6702 +0 0 1 1.771 132.6703 +0 1 1 1.789 132.6704 +0 0 1 1.861 132.6705 +0 1 1 1.877 132.6706 +0 0 1 1.915 132.6707 +0 1 1 1.931 132.6708 +0 0 1 1.989 132.6709 +0 1 1 2.003 132.6710 +0 0 1 2.111 132.6711 +0 1 1 2.181 132.6712 +0 0 1 2.369 132.6713 +0 1 1 2.387 132.6714 +0 0 1 2.529 132.6715 +0 1 1 2.547 132.6716 +0 0 1 2.557 132.6717 +0 1 1 2.577 132.6718 +0 0 1 2.581 132.6719 +0 1 1 2.589 132.6720 +0 0 1 2.635 132.6721 +0 1 1 2.649 132.6722 +0 0 1 2.653 132.6723 +0 1 1 2.667 132.6724 +0 0 1 2.675 132.6725 +0 1 1 2.693 132.6726 +0 0 1 2.911 132.6727 +0 1 1 2.925 132.6728 +0 0 1 2.925 132.6729 +0 0 0 2.925 132.6730 +0 1 0 2.911 132.6731 +0 0 0 2.691 132.6732 +0 1 0 2.673 132.6733 +0 0 0 2.667 132.6734 +0 1 0 2.653 132.6735 +0 0 0 2.649 132.6736 +0 1 0 2.635 132.6737 +0 0 0 2.589 132.6738 +0 1 0 2.581 132.6739 +0 0 0 2.575 132.6740 +0 1 0 2.555 132.6741 +0 0 0 2.549 132.6742 +0 1 0 2.531 132.6743 +0 0 0 2.385 132.6744 +0 1 0 2.369 132.6745 +0 0 0 2.165 132.6746 +0 1 0 2.107 132.6747 +0 0 0 2.003 132.6748 +0 1 0 1.989 132.6749 +0 0 0 1.931 132.6750 +0 1 0 1.915 132.6751 +0 0 0 1.877 132.6752 +0 1 0 1.859 132.6753 +0 0 0 1.787 132.6754 +0 1 0 1.771 132.6755 +0 0 0 1.719 132.6756 +0 1 0 1.703 132.6757 +0 0 0 1.645 132.6758 +0 1 0 1.629 132.6759 +0 0 0 1.565 132.6760 +0 1 0 1.549 132.6761 +0 0 0 1.491 132.6762 +0 1 0 1.475 132.6763 +0 0 0 1.303 132.6764 +0 1 0 1.287 132.6765 +0 0 0 1.229 132.6766 +0 1 0 1.213 132.6767 +0 0 0 1.089 132.6768 +0 1 0 1.075 132.6769 +0 0 0 1.075 132.6770 +0 0 1 1.075 132.6771 +0 1 1 1.089 132.6772 +0 0 1 1.213 132.6773 +0 1 1 1.229 132.6774 +0 0 1 1.287 132.6775 +0 1 1 1.303 132.6776 +0 0 1 1.475 132.6777 +0 1 1 1.491 132.6778 +0 0 1 1.549 132.6779 +0 1 1 1.565 132.6780 +0 0 1 1.629 132.6781 +0 1 1 1.645 132.6782 +0 0 1 1.703 132.6783 +0 1 1 1.719 132.6784 +0 0 1 1.769 132.6785 +0 1 1 1.787 132.6786 +0 0 1 1.859 132.6787 +0 1 1 1.877 132.6788 +0 0 1 1.915 132.6789 +0 1 1 1.931 132.6790 +0 0 1 1.989 132.6791 +0 1 1 2.003 132.6792 +0 0 1 2.103 132.6793 +0 1 1 2.155 132.6794 +0 0 1 2.369 132.6795 +0 1 1 2.385 132.6796 +0 0 1 2.533 132.6797 +0 1 1 2.547 132.6798 +0 0 1 2.553 132.6799 +0 1 1 2.573 132.6800 +0 0 1 2.579 132.6801 +0 1 1 2.589 132.6802 +0 0 1 2.635 132.6803 +0 1 1 2.649 132.6804 +0 0 1 2.653 132.6805 +0 1 1 2.667 132.6806 +0 0 1 2.673 132.6807 +0 1 1 2.689 132.6808 +0 0 1 2.911 132.6809 +0 1 1 2.925 132.6810 +0 0 1 2.925 132.6811 +0 0 0 2.925 132.6812 +0 1 0 2.911 132.6813 +0 0 0 2.689 132.6814 +0 1 0 2.671 132.6815 +0 0 0 2.665 132.6816 +0 1 0 2.653 132.6817 +0 0 0 2.649 132.6818 +0 1 0 2.635 132.6819 +0 0 0 2.589 132.6820 +0 1 0 2.577 132.6821 +0 0 0 2.571 132.6822 +0 1 0 2.551 132.6823 +0 0 0 2.545 132.6824 +0 1 0 2.535 132.6825 +0 0 0 2.385 132.6826 +0 1 0 2.367 132.6827 +0 0 0 2.143 132.6828 +0 1 0 2.101 132.6829 +0 0 0 2.003 132.6830 +0 1 0 1.989 132.6831 +0 0 0 1.931 132.6832 +0 1 0 1.915 132.6833 +0 0 0 1.875 132.6834 +0 1 0 1.857 132.6835 +0 0 0 1.785 132.6836 +0 1 0 1.767 132.6837 +0 0 0 1.719 132.6838 +0 1 0 1.703 132.6839 +0 0 0 1.645 132.6840 +0 1 0 1.629 132.6841 +0 0 0 1.565 132.6842 +0 1 0 1.549 132.6843 +0 0 0 1.491 132.6844 +0 1 0 1.475 132.6845 +0 0 0 1.303 132.6846 +0 1 0 1.287 132.6847 +0 0 0 1.229 132.6848 +0 1 0 1.213 132.6849 +0 0 0 1.089 132.6850 +0 1 0 1.075 132.6851 +0 0 0 1.075 132.6852 +0 0 1 1.075 132.6853 +0 1 1 1.089 132.6854 +0 0 1 1.213 132.6855 +0 1 1 1.229 132.6856 +0 0 1 1.287 132.6857 +0 1 1 1.303 132.6858 +0 0 1 1.475 132.6859 +0 1 1 1.491 132.6860 +0 0 1 1.549 132.6861 +0 1 1 1.565 132.6862 +0 0 1 1.629 132.6863 +0 1 1 1.645 132.6864 +0 0 1 1.703 132.6865 +0 1 1 1.719 132.6866 +0 0 1 1.767 132.6867 +0 1 1 1.785 132.6868 +0 0 1 1.857 132.6869 +0 1 1 1.873 132.6870 +0 0 1 1.915 132.6871 +0 1 1 1.931 132.6872 +0 0 1 1.989 132.6873 +0 1 1 2.003 132.6874 +0 0 1 2.097 132.6875 +0 1 1 2.135 132.6876 +0 0 1 2.365 132.6877 +0 1 1 2.383 132.6878 +0 0 1 2.535 132.6879 +0 1 1 2.543 132.6880 +0 0 1 2.549 132.6881 +0 1 1 2.569 132.6882 +0 0 1 2.575 132.6883 +0 1 1 2.589 132.6884 +0 0 1 2.635 132.6885 +0 1 1 2.649 132.6886 +0 0 1 2.653 132.6887 +0 1 1 2.663 132.6888 +0 0 1 2.669 132.6889 +0 1 1 2.687 132.6890 +0 0 1 2.911 132.6891 +0 1 1 2.925 132.6892 +0 0 1 2.925 132.6893 +0 0 0 2.925 132.6894 +0 1 0 2.911 132.6895 +0 0 0 2.685 132.6896 +0 1 0 2.667 132.6897 +0 0 0 2.663 132.6898 +0 1 0 2.655 132.6899 +0 0 0 2.649 132.6900 +0 1 0 2.635 132.6901 +0 0 0 2.589 132.6902 +0 1 0 2.575 132.6903 +0 0 0 2.567 132.6904 +0 1 0 2.547 132.6905 +0 0 0 2.541 132.6906 +0 1 0 2.537 132.6907 +0 0 0 2.383 132.6908 +0 1 0 2.365 132.6909 +0 0 0 2.129 132.6910 +0 1 0 2.095 132.6911 +0 0 0 2.003 132.6912 +0 1 0 1.989 132.6913 +0 0 0 1.931 132.6914 +0 1 0 1.915 132.6915 +0 0 0 1.873 132.6916 +0 1 0 1.855 132.6917 +0 0 0 1.783 132.6918 +0 1 0 1.767 132.6919 +0 0 0 1.719 132.6920 +0 1 0 1.703 132.6921 +0 0 0 1.645 132.6922 +0 1 0 1.629 132.6923 +0 0 0 1.565 132.6924 +0 1 0 1.549 132.6925 +0 0 0 1.491 132.6926 +0 1 0 1.475 132.6927 +0 0 0 1.303 132.6928 +0 1 0 1.287 132.6929 +0 0 0 1.229 132.6930 +0 1 0 1.213 132.6931 +0 0 0 1.089 132.6932 +0 1 0 1.075 132.6933 +0 0 0 1.075 132.6934 +0 0 1 1.075 132.6935 +0 1 1 1.089 132.6936 +0 0 1 1.213 132.6937 +0 1 1 1.229 132.6938 +0 0 1 1.287 132.6939 +0 1 1 1.303 132.6940 +0 0 1 1.475 132.6941 +0 1 1 1.491 132.6942 +0 0 1 1.549 132.6943 +0 1 1 1.565 132.6944 +0 0 1 1.629 132.6945 +0 1 1 1.645 132.6946 +0 0 1 1.703 132.6947 +0 1 1 1.719 132.6948 +0 0 1 1.765 132.6949 +0 1 1 1.783 132.6950 +0 0 1 1.855 132.6951 +0 1 1 1.871 132.6952 +0 0 1 1.915 132.6953 +0 1 1 1.931 132.6954 +0 0 1 1.989 132.6955 +0 1 1 2.003 132.6956 +0 0 1 2.093 132.6957 +0 1 1 2.123 132.6958 +0 0 1 2.363 132.6959 +0 1 1 2.381 132.6960 +0 0 1 2.537 132.6961 +0 1 1 2.541 132.6962 +0 0 1 2.545 132.6963 +0 1 1 2.565 132.6964 +0 0 1 2.575 132.6965 +0 1 1 2.589 132.6966 +0 0 1 2.635 132.6967 +0 1 1 2.649 132.6968 +0 0 1 2.657 132.6969 +0 1 1 2.661 132.6970 +0 0 1 2.667 132.6971 +0 1 1 2.685 132.6972 +0 0 1 2.911 132.6973 +0 1 1 2.925 132.6974 +0 0 1 2.925 132.6975 +0 0 0 2.925 132.6976 +0 1 0 2.911 132.6977 +0 0 0 2.683 132.6978 +0 1 0 2.665 132.6979 +0 0 0 2.649 132.6980 +0 1 0 2.635 132.6981 +0 0 0 2.589 132.6982 +0 1 0 2.575 132.6983 +0 0 0 2.563 132.6984 +0 1 0 2.543 132.6985 +0 0 0 2.381 132.6986 +0 1 0 2.361 132.6987 +0 0 0 2.117 132.6988 +0 1 0 2.091 132.6989 +0 0 0 2.003 132.6990 +0 1 0 1.989 132.6991 +0 0 0 1.931 132.6992 +0 1 0 1.915 132.6993 +0 0 0 1.871 132.6994 +0 1 0 1.853 132.6995 +0 0 0 1.781 132.6996 +0 1 0 1.765 132.6997 +0 0 0 1.719 132.6998 +0 1 0 1.703 132.6999 +0 0 0 1.645 132.7000 +0 1 0 1.629 132.7001 +0 0 0 1.565 132.7002 +0 1 0 1.549 132.7003 +0 0 0 1.491 132.7004 +0 1 0 1.475 132.7005 +0 0 0 1.303 132.7006 +0 1 0 1.287 132.7007 +0 0 0 1.229 132.7008 +0 1 0 1.213 132.7009 +0 0 0 1.089 132.7010 +0 1 0 1.075 132.7011 +0 0 0 1.075 132.7012 +0 0 1 1.075 132.7013 +0 1 1 1.089 132.7014 +0 0 1 1.213 132.7015 +0 1 1 1.229 132.7016 +0 0 1 1.287 132.7017 +0 1 1 1.303 132.7018 +0 0 1 1.475 132.7019 +0 1 1 1.491 132.7020 +0 0 1 1.549 132.7021 +0 1 1 1.565 132.7022 +0 0 1 1.629 132.7023 +0 1 1 1.645 132.7024 +0 0 1 1.703 132.7025 +0 1 1 1.719 132.7026 +0 0 1 1.763 132.7027 +0 1 1 1.781 132.7028 +0 0 1 1.853 132.7029 +0 1 1 1.869 132.7030 +0 0 1 1.915 132.7031 +0 1 1 1.931 132.7032 +0 0 1 1.989 132.7033 +0 1 1 2.003 132.7034 +0 0 1 2.089 132.7035 +0 1 1 2.113 132.7036 +0 0 1 2.359 132.7037 +0 1 1 2.379 132.7038 +0 0 1 2.543 132.7039 +0 1 1 2.561 132.7040 +0 0 1 2.575 132.7041 +0 1 1 2.589 132.7042 +0 0 1 2.635 132.7043 +0 1 1 2.649 132.7044 +0 0 1 2.663 132.7045 +0 1 1 2.681 132.7046 +0 0 1 2.911 132.7047 +0 1 1 2.925 132.7048 +0 0 1 2.925 132.7049 +0 0 0 2.925 132.7050 +0 1 0 2.911 132.7051 +0 0 0 2.679 132.7052 +0 1 0 2.661 132.7053 +0 0 0 2.649 132.7054 +0 1 0 2.635 132.7055 +0 0 0 2.589 132.7056 +0 1 0 2.575 132.7057 +0 0 0 2.559 132.7058 +0 1 0 2.541 132.7059 +0 0 0 2.377 132.7060 +0 1 0 2.357 132.7061 +0 0 0 2.111 132.7062 +0 1 0 2.087 132.7063 +0 0 0 2.003 132.7064 +0 1 0 1.989 132.7065 +0 0 0 1.931 132.7066 +0 1 0 1.915 132.7067 +0 0 0 1.869 132.7068 +0 1 0 1.851 132.7069 +0 0 0 1.779 132.7070 +0 1 0 1.761 132.7071 +0 0 0 1.719 132.7072 +0 1 0 1.703 132.7073 +0 0 0 1.645 132.7074 +0 1 0 1.629 132.7075 +0 0 0 1.565 132.7076 +0 1 0 1.549 132.7077 +0 0 0 1.491 132.7078 +0 1 0 1.475 132.7079 +0 0 0 1.303 132.7080 +0 1 0 1.287 132.7081 +0 0 0 1.229 132.7082 +0 1 0 1.213 132.7083 +0 0 0 1.089 132.7084 +0 1 0 1.075 132.7085 +0 0 0 1.075 132.7086 +0 0 1 1.075 132.7087 +0 1 1 1.089 132.7088 +0 0 1 1.213 132.7089 +0 1 1 1.229 132.7090 +0 0 1 1.287 132.7091 +0 1 1 1.303 132.7092 +0 0 1 1.475 132.7093 +0 1 1 1.491 132.7094 +0 0 1 1.549 132.7095 +0 1 1 1.565 132.7096 +0 0 1 1.629 132.7097 +0 1 1 1.645 132.7098 +0 0 1 1.703 132.7099 +0 1 1 1.719 132.7100 +0 0 1 1.761 132.7101 +0 1 1 1.779 132.7102 +0 0 1 1.851 132.7103 +0 1 1 1.867 132.7104 +0 0 1 1.915 132.7105 +0 1 1 1.931 132.7106 +0 0 1 1.989 132.7107 +0 1 1 2.003 132.7108 +0 0 1 2.085 132.7109 +0 1 1 2.107 132.7110 +0 0 1 2.355 132.7111 +0 1 1 2.377 132.7112 +0 0 1 2.539 132.7113 +0 1 1 2.557 132.7114 +0 0 1 2.575 132.7115 +0 1 1 2.589 132.7116 +0 0 1 2.635 132.7117 +0 1 1 2.649 132.7118 +0 0 1 2.659 132.7119 +0 1 1 2.679 132.7120 +0 0 1 2.911 132.7121 +0 1 1 2.925 132.7122 +0 0 1 2.925 132.7123 +0 0 0 2.925 132.7124 +0 1 0 2.911 132.7125 +0 0 0 2.685 132.7126 +0 1 0 2.683 132.7127 +0 0 0 2.677 132.7128 +0 1 0 2.657 132.7129 +0 0 0 2.649 132.7130 +0 1 0 2.635 132.7131 +0 0 0 2.589 132.7132 +0 1 0 2.575 132.7133 +0 0 0 2.565 132.7134 +0 1 0 2.561 132.7135 +0 0 0 2.555 132.7136 +0 1 0 2.539 132.7137 +0 0 0 2.375 132.7138 +0 1 0 2.351 132.7139 +0 0 0 2.105 132.7140 +0 1 0 2.085 132.7141 +0 0 0 2.003 132.7142 +0 1 0 1.989 132.7143 +0 0 0 1.931 132.7144 +0 1 0 1.915 132.7145 +0 0 0 1.867 132.7146 +0 1 0 1.849 132.7147 +0 0 0 1.777 132.7148 +0 1 0 1.759 132.7149 +0 0 0 1.719 132.7150 +0 1 0 1.703 132.7151 +0 0 0 1.645 132.7152 +0 1 0 1.629 132.7153 +0 0 0 1.565 132.7154 +0 1 0 1.549 132.7155 +0 0 0 1.491 132.7156 +0 1 0 1.475 132.7157 +0 0 0 1.303 132.7158 +0 1 0 1.287 132.7159 +0 0 0 1.229 132.7160 +0 1 0 1.213 132.7161 +0 0 0 1.089 132.7162 +0 1 0 1.075 132.7163 +0 0 0 1.075 132.7164 +0 0 1 1.075 132.7165 +0 1 1 1.089 132.7166 +0 0 1 1.213 132.7167 +0 1 1 1.229 132.7168 +0 0 1 1.287 132.7169 +0 1 1 1.303 132.7170 +0 0 1 1.475 132.7171 +0 1 1 1.491 132.7172 +0 0 1 1.549 132.7173 +0 1 1 1.565 132.7174 +0 0 1 1.629 132.7175 +0 1 1 1.645 132.7176 +0 0 1 1.703 132.7177 +0 1 1 1.719 132.7178 +0 0 1 1.759 132.7179 +0 1 1 1.777 132.7180 +0 0 1 1.849 132.7181 +0 1 1 1.865 132.7182 +0 0 1 1.915 132.7183 +0 1 1 1.931 132.7184 +0 0 1 1.989 132.7185 +0 1 1 2.003 132.7186 +0 0 1 2.083 132.7187 +0 1 1 2.103 132.7188 +0 0 1 2.349 132.7189 +0 1 1 2.373 132.7190 +0 0 1 2.537 132.7191 +0 1 1 2.555 132.7192 +0 0 1 2.561 132.7193 +0 1 1 2.567 132.7194 +0 0 1 2.575 132.7195 +0 1 1 2.589 132.7196 +0 0 1 2.635 132.7197 +0 1 1 2.649 132.7198 +0 0 1 2.655 132.7199 +0 1 1 2.675 132.7200 +0 0 1 2.681 132.7201 +0 1 1 2.685 132.7202 +0 0 1 2.911 132.7203 +0 1 1 2.925 132.7204 +0 0 1 2.925 132.7205 +0 0 0 2.925 132.7206 +0 1 0 2.911 132.7207 +0 0 0 2.687 132.7208 +0 1 0 2.679 132.7209 +0 0 0 2.673 132.7210 +0 1 0 2.653 132.7211 +0 0 0 2.647 132.7212 +0 1 0 2.635 132.7213 +0 0 0 2.589 132.7214 +0 1 0 2.575 132.7215 +0 0 0 2.569 132.7216 +0 1 0 2.559 132.7217 +0 0 0 2.553 132.7218 +0 1 0 2.535 132.7219 +0 0 0 2.371 132.7220 +0 1 0 2.343 132.7221 +0 0 0 2.101 132.7222 +0 1 0 2.083 132.7223 +0 0 0 2.003 132.7224 +0 1 0 1.989 132.7225 +0 0 0 1.931 132.7226 +0 1 0 1.915 132.7227 +0 0 0 1.865 132.7228 +0 1 0 1.847 132.7229 +0 0 0 1.775 132.7230 +0 1 0 1.757 132.7231 +0 0 0 1.719 132.7232 +0 1 0 1.703 132.7233 +0 0 0 1.645 132.7234 +0 1 0 1.629 132.7235 +0 0 0 1.565 132.7236 +0 1 0 1.549 132.7237 +0 0 0 1.491 132.7238 +0 1 0 1.475 132.7239 +0 0 0 1.303 132.7240 +0 1 0 1.287 132.7241 +0 0 0 1.229 132.7242 +0 1 0 1.213 132.7243 +0 0 0 1.089 132.7244 +0 1 0 1.075 132.7245 +0 0 0 1.075 132.7246 +0 0 1 1.075 132.7247 +0 1 1 1.089 132.7248 +0 0 1 1.213 132.7249 +0 1 1 1.229 132.7250 +0 0 1 1.287 132.7251 +0 1 1 1.303 132.7252 +0 0 1 1.475 132.7253 +0 1 1 1.491 132.7254 +0 0 1 1.549 132.7255 +0 1 1 1.565 132.7256 +0 0 1 1.629 132.7257 +0 1 1 1.645 132.7258 +0 0 1 1.703 132.7259 +0 1 1 1.719 132.7260 +0 0 1 1.757 132.7261 +0 1 1 1.773 132.7262 +0 0 1 1.847 132.7263 +0 1 1 1.863 132.7264 +0 0 1 1.915 132.7265 +0 1 1 1.931 132.7266 +0 0 1 1.989 132.7267 +0 1 1 2.003 132.7268 +0 0 1 2.081 132.7269 +0 1 1 2.099 132.7270 +0 0 1 2.339 132.7271 +0 1 1 2.369 132.7272 +0 0 1 2.535 132.7273 +0 1 1 2.551 132.7274 +0 0 1 2.557 132.7275 +0 1 1 2.571 132.7276 +0 0 1 2.575 132.7277 +0 1 1 2.589 132.7278 +0 0 1 2.635 132.7279 +0 1 1 2.645 132.7280 +0 0 1 2.651 132.7281 +0 1 1 2.671 132.7282 +0 0 1 2.677 132.7283 +0 1 1 2.689 132.7284 +0 0 1 2.911 132.7285 +0 1 1 2.925 132.7286 +0 0 1 2.925 132.7287 +0 0 0 2.925 132.7288 +0 1 0 2.911 132.7289 +0 0 0 2.689 132.7290 +0 1 0 2.675 132.7291 +0 0 0 2.669 132.7292 +0 1 0 2.649 132.7293 +0 0 0 2.643 132.7294 +0 1 0 2.635 132.7295 +0 0 0 2.589 132.7296 +0 1 0 2.575 132.7297 +0 0 0 2.571 132.7298 +0 1 0 2.555 132.7299 +0 0 0 2.551 132.7300 +0 1 0 2.533 132.7301 +0 0 0 2.367 132.7302 +0 1 0 2.333 132.7303 +0 0 0 2.097 132.7304 +0 1 0 2.081 132.7305 +0 0 0 2.003 132.7306 +0 1 0 1.989 132.7307 +0 0 0 1.931 132.7308 +0 1 0 1.915 132.7309 +0 0 0 1.863 132.7310 +0 1 0 1.845 132.7311 +0 0 0 1.773 132.7312 +0 1 0 1.755 132.7313 +0 0 0 1.719 132.7314 +0 1 0 1.703 132.7315 +0 0 0 1.645 132.7316 +0 1 0 1.629 132.7317 +0 0 0 1.565 132.7318 +0 1 0 1.549 132.7319 +0 0 0 1.491 132.7320 +0 1 0 1.475 132.7321 +0 0 0 1.303 132.7322 +0 1 0 1.287 132.7323 +0 0 0 1.229 132.7324 +0 1 0 1.213 132.7325 +0 0 0 1.089 132.7326 +0 1 0 1.075 132.7327 +0 0 0 1.075 132.7328 +0 0 1 1.075 132.7329 +0 1 1 1.089 132.7330 +0 0 1 1.213 132.7331 +0 1 1 1.229 132.7332 +0 0 1 1.287 132.7333 +0 1 1 1.303 132.7334 +0 0 1 1.475 132.7335 +0 1 1 1.491 132.7336 +0 0 1 1.549 132.7337 +0 1 1 1.565 132.7338 +0 0 1 1.629 132.7339 +0 1 1 1.645 132.7340 +0 0 1 1.703 132.7341 +0 1 1 1.719 132.7342 +0 0 1 1.755 132.7343 +0 1 1 1.773 132.7344 +0 0 1 1.845 132.7345 +0 1 1 1.861 132.7346 +0 0 1 1.915 132.7347 +0 1 1 1.931 132.7348 +0 0 1 1.989 132.7349 +0 1 1 2.003 132.7350 +0 0 1 2.079 132.7351 +0 1 1 2.097 132.7352 +0 0 1 2.323 132.7353 +0 1 1 2.365 132.7354 +0 0 1 2.531 132.7355 +0 1 1 2.549 132.7356 +0 0 1 2.555 132.7357 +0 1 1 2.571 132.7358 +0 0 1 2.575 132.7359 +0 1 1 2.589 132.7360 +0 0 1 2.635 132.7361 +0 1 1 2.641 132.7362 +0 0 1 2.647 132.7363 +0 1 1 2.669 132.7364 +0 0 1 2.673 132.7365 +0 1 1 2.691 132.7366 +0 0 1 2.911 132.7367 +0 1 1 2.925 132.7368 +0 0 1 2.925 132.7369 +0 0 0 2.925 132.7370 +0 1 0 2.911 132.7371 +0 0 0 2.693 132.7372 +0 1 0 2.675 132.7373 +0 0 0 2.667 132.7374 +0 1 0 2.647 132.7375 +0 0 0 2.641 132.7376 +0 1 0 2.635 132.7377 +0 0 0 2.589 132.7378 +0 1 0 2.575 132.7379 +0 0 0 2.571 132.7380 +0 1 0 2.555 132.7381 +0 0 0 2.547 132.7382 +0 1 0 2.529 132.7383 +0 0 0 2.361 132.7384 +0 1 0 2.315 132.7385 +0 0 0 2.095 132.7386 +0 1 0 2.079 132.7387 +0 0 0 2.003 132.7388 +0 1 0 1.989 132.7389 +0 0 0 1.931 132.7390 +0 1 0 1.915 132.7391 +0 0 0 1.861 132.7392 +0 1 0 1.843 132.7393 +0 0 0 1.771 132.7394 +0 1 0 1.753 132.7395 +0 0 0 1.719 132.7396 +0 1 0 1.703 132.7397 +0 0 0 1.645 132.7398 +0 1 0 1.629 132.7399 +0 0 0 1.565 132.7400 +0 1 0 1.549 132.7401 +0 0 0 1.491 132.7402 +0 1 0 1.475 132.7403 +0 0 0 1.303 132.7404 +0 1 0 1.287 132.7405 +0 0 0 1.229 132.7406 +0 1 0 1.213 132.7407 +0 0 0 1.089 132.7408 +0 1 0 1.075 132.7409 +0 0 0 1.075 132.7410 +0 0 1 1.075 132.7411 +0 1 1 1.089 132.7412 +0 0 1 1.213 132.7413 +0 1 1 1.229 132.7414 +0 0 1 1.287 132.7415 +0 1 1 1.303 132.7416 +0 0 1 1.475 132.7417 +0 1 1 1.491 132.7418 +0 0 1 1.549 132.7419 +0 1 1 1.565 132.7420 +0 0 1 1.629 132.7421 +0 1 1 1.645 132.7422 +0 0 1 1.703 132.7423 +0 1 1 1.719 132.7424 +0 0 1 1.753 132.7425 +0 1 1 1.769 132.7426 +0 0 1 1.843 132.7427 +0 1 1 1.859 132.7428 +0 0 1 1.915 132.7429 +0 1 1 1.931 132.7430 +0 0 1 1.989 132.7431 +0 1 1 2.003 132.7432 +0 0 1 2.077 132.7433 +0 1 1 2.095 132.7434 +0 0 1 2.305 132.7435 +0 1 1 2.359 132.7436 +0 0 1 2.529 132.7437 +0 1 1 2.547 132.7438 +0 0 1 2.557 132.7439 +0 1 1 2.571 132.7440 +0 0 1 2.575 132.7441 +0 1 1 2.589 132.7442 +0 0 1 2.635 132.7443 +0 1 1 2.639 132.7444 +0 0 1 2.645 132.7445 +0 1 1 2.665 132.7446 +0 0 1 2.677 132.7447 +0 1 1 2.693 132.7448 +0 0 1 2.911 132.7449 +0 1 1 2.925 132.7450 +0 0 1 2.925 132.7451 +0 0 0 2.925 132.7452 +0 1 0 2.911 132.7453 +0 0 0 2.695 132.7454 +0 1 0 2.677 132.7455 +0 0 0 2.663 132.7456 +0 1 0 2.643 132.7457 +0 0 0 2.589 132.7458 +0 1 0 2.575 132.7459 +0 0 0 2.571 132.7460 +0 1 0 2.559 132.7461 +0 0 0 2.545 132.7462 +0 1 0 2.527 132.7463 +0 0 0 2.353 132.7464 +0 1 0 2.289 132.7465 +0 0 0 2.093 132.7466 +0 1 0 2.077 132.7467 +0 0 0 2.003 132.7468 +0 1 0 1.989 132.7469 +0 0 0 1.931 132.7470 +0 1 0 1.915 132.7471 +0 0 0 1.859 132.7472 +0 1 0 1.841 132.7473 +0 0 0 1.769 132.7474 +0 1 0 1.751 132.7475 +0 0 0 1.719 132.7476 +0 1 0 1.703 132.7477 +0 0 0 1.645 132.7478 +0 1 0 1.629 132.7479 +0 0 0 1.565 132.7480 +0 1 0 1.549 132.7481 +0 0 0 1.491 132.7482 +0 1 0 1.475 132.7483 +0 0 0 1.303 132.7484 +0 1 0 1.287 132.7485 +0 0 0 1.229 132.7486 +0 1 0 1.213 132.7487 +0 0 0 1.089 132.7488 +0 1 0 1.075 132.7489 +0 0 0 1.075 132.7490 +0 0 1 1.075 132.7491 +0 1 1 1.089 132.7492 +0 0 1 1.213 132.7493 +0 1 1 1.229 132.7494 +0 0 1 1.287 132.7495 +0 1 1 1.303 132.7496 +0 0 1 1.475 132.7497 +0 1 1 1.491 132.7498 +0 0 1 1.549 132.7499 +0 1 1 1.565 132.7500 +0 0 1 1.629 132.7501 +0 1 1 1.645 132.7502 +0 0 1 1.703 132.7503 +0 1 1 1.719 132.7504 +0 0 1 1.751 132.7505 +0 1 1 1.767 132.7506 +0 0 1 1.841 132.7507 +0 1 1 1.857 132.7508 +0 0 1 1.915 132.7509 +0 1 1 1.931 132.7510 +0 0 1 1.989 132.7511 +0 1 1 2.003 132.7512 +0 0 1 2.077 132.7513 +0 1 1 2.093 132.7514 +0 0 1 2.273 132.7515 +0 1 1 2.349 132.7516 +0 0 1 2.525 132.7517 +0 1 1 2.543 132.7518 +0 0 1 2.561 132.7519 +0 1 1 2.571 132.7520 +0 0 1 2.575 132.7521 +0 1 1 2.589 132.7522 +0 0 1 2.641 132.7523 +0 1 1 2.661 132.7524 +0 0 1 2.679 132.7525 +0 1 1 2.697 132.7526 +0 0 1 2.911 132.7527 +0 1 1 2.925 132.7528 +0 0 1 2.925 132.7529 +0 0 0 2.925 132.7530 +0 1 0 2.911 132.7531 +0 0 0 2.699 132.7532 +0 1 0 2.681 132.7533 +0 0 0 2.659 132.7534 +0 1 0 2.639 132.7535 +0 0 0 2.589 132.7536 +0 1 0 2.575 132.7537 +0 0 0 2.571 132.7538 +0 1 0 2.563 132.7539 +0 0 0 2.543 132.7540 +0 1 0 2.525 132.7541 +0 0 0 2.345 132.7542 +0 1 0 2.245 132.7543 +0 0 0 2.091 132.7544 +0 1 0 2.075 132.7545 +0 0 0 2.003 132.7546 +0 1 0 1.989 132.7547 +0 0 0 1.931 132.7548 +0 1 0 1.915 132.7549 +0 0 0 1.857 132.7550 +0 1 0 1.839 132.7551 +0 0 0 1.767 132.7552 +0 1 0 1.749 132.7553 +0 0 0 1.719 132.7554 +0 1 0 1.703 132.7555 +0 0 0 1.645 132.7556 +0 1 0 1.629 132.7557 +0 0 0 1.565 132.7558 +0 1 0 1.549 132.7559 +0 0 0 1.489 132.7560 +0 1 0 1.475 132.7561 +0 0 0 1.303 132.7562 +0 1 0 1.287 132.7563 +0 0 0 1.229 132.7564 +0 1 0 1.213 132.7565 +0 0 0 1.089 132.7566 +0 1 0 1.075 132.7567 +0 0 0 1.075 132.7568 +0 0 1 1.075 132.7569 +0 1 1 1.089 132.7570 +0 0 1 1.213 132.7571 +0 1 1 1.229 132.7572 +0 0 1 1.287 132.7573 +0 1 1 1.303 132.7574 +0 0 1 1.475 132.7575 +0 1 1 1.489 132.7576 +0 0 1 1.549 132.7577 +0 1 1 1.565 132.7578 +0 0 1 1.629 132.7579 +0 1 1 1.645 132.7580 +0 0 1 1.703 132.7581 +0 1 1 1.719 132.7582 +0 0 1 1.749 132.7583 +0 1 1 1.765 132.7584 +0 0 1 1.839 132.7585 +0 1 1 1.855 132.7586 +0 0 1 1.915 132.7587 +0 1 1 1.931 132.7588 +0 0 1 1.989 132.7589 +0 1 1 2.003 132.7590 +0 0 1 2.075 132.7591 +0 1 1 2.091 132.7592 +0 0 1 2.213 132.7593 +0 1 1 2.339 132.7594 +0 0 1 2.523 132.7595 +0 1 1 2.541 132.7596 +0 0 1 2.565 132.7597 +0 1 1 2.571 132.7598 +0 0 1 2.575 132.7599 +0 1 1 2.589 132.7600 +0 0 1 2.593 132.7601 +0 1 1 2.657 132.7602 +0 0 1 2.681 132.7603 +0 1 1 2.699 132.7604 +0 0 1 2.911 132.7605 +0 1 1 2.925 132.7606 +0 0 1 2.925 132.7607 +0 0 0 2.925 132.7608 +0 1 0 2.911 132.7609 +0 0 0 2.701 132.7610 +0 1 0 2.683 132.7611 +0 0 0 2.655 132.7612 +0 1 0 2.593 132.7613 +0 0 0 2.589 132.7614 +0 1 0 2.575 132.7615 +0 0 0 2.571 132.7616 +0 1 0 2.567 132.7617 +0 0 0 2.539 132.7618 +0 1 0 2.521 132.7619 +0 0 0 2.331 132.7620 +0 1 0 2.195 132.7621 +0 0 0 2.091 132.7622 +0 1 0 2.075 132.7623 +0 0 0 2.003 132.7624 +0 1 0 1.989 132.7625 +0 0 0 1.931 132.7626 +0 1 0 1.915 132.7627 +0 0 0 1.855 132.7628 +0 1 0 1.837 132.7629 +0 0 0 1.765 132.7630 +0 1 0 1.747 132.7631 +0 0 0 1.719 132.7632 +0 1 0 1.703 132.7633 +0 0 0 1.645 132.7634 +0 1 0 1.629 132.7635 +0 0 0 1.565 132.7636 +0 1 0 1.549 132.7637 +0 0 0 1.489 132.7638 +0 1 0 1.475 132.7639 +0 0 0 1.303 132.7640 +0 1 0 1.287 132.7641 +0 0 0 1.229 132.7642 +0 1 0 1.213 132.7643 +0 0 0 1.089 132.7644 +0 1 0 1.075 132.7645 +0 0 0 1.075 132.7646 +0 0 1 1.075 132.7647 +0 1 1 1.089 132.7648 +0 0 1 1.213 132.7649 +0 1 1 1.229 132.7650 +0 0 1 1.287 132.7651 +0 1 1 1.303 132.7652 +0 0 1 1.475 132.7653 +0 1 1 1.489 132.7654 +0 0 1 1.549 132.7655 +0 1 1 1.565 132.7656 +0 0 1 1.629 132.7657 +0 1 1 1.645 132.7658 +0 0 1 1.703 132.7659 +0 1 1 1.719 132.7660 +0 0 1 1.747 132.7661 +0 1 1 1.763 132.7662 +0 0 1 1.835 132.7663 +0 1 1 1.853 132.7664 +0 0 1 1.915 132.7665 +0 1 1 1.931 132.7666 +0 0 1 1.989 132.7667 +0 1 1 2.003 132.7668 +0 0 1 2.073 132.7669 +0 1 1 2.089 132.7670 +0 0 1 2.181 132.7671 +0 1 1 2.325 132.7672 +0 0 1 2.521 132.7673 +0 1 1 2.537 132.7674 +0 0 1 2.575 132.7675 +0 1 1 2.589 132.7676 +0 0 1 2.595 132.7677 +0 1 1 2.653 132.7678 +0 0 1 2.685 132.7679 +0 1 1 2.703 132.7680 +0 0 1 2.911 132.7681 +0 1 1 2.925 132.7682 +0 0 1 2.925 132.7683 +0 0 0 2.925 132.7684 +0 1 0 2.911 132.7685 +0 0 0 2.703 132.7686 +0 1 0 2.685 132.7687 +0 0 0 2.651 132.7688 +0 1 0 2.597 132.7689 +0 0 0 2.591 132.7690 +0 1 0 2.575 132.7691 +0 0 0 2.537 132.7692 +0 1 0 2.519 132.7693 +0 0 0 2.313 132.7694 +0 1 0 2.171 132.7695 +0 0 0 2.089 132.7696 +0 1 0 2.073 132.7697 +0 0 0 2.003 132.7698 +0 1 0 1.989 132.7699 +0 0 0 1.931 132.7700 +0 1 0 1.915 132.7701 +0 0 0 1.853 132.7702 +0 1 0 1.835 132.7703 +0 0 0 1.763 132.7704 +0 1 0 1.745 132.7705 +0 0 0 1.719 132.7706 +0 1 0 1.703 132.7707 +0 0 0 1.645 132.7708 +0 1 0 1.629 132.7709 +0 0 0 1.565 132.7710 +0 1 0 1.549 132.7711 +0 0 0 1.489 132.7712 +0 1 0 1.475 132.7713 +0 0 0 1.303 132.7714 +0 1 0 1.287 132.7715 +0 0 0 1.229 132.7716 +0 1 0 1.213 132.7717 +0 0 0 1.089 132.7718 +0 1 0 1.075 132.7719 +0 0 0 1.075 132.7720 +0 0 1 1.075 132.7721 +0 1 1 1.089 132.7722 +0 0 1 1.213 132.7723 +0 1 1 1.229 132.7724 +0 0 1 1.287 132.7725 +0 1 1 1.303 132.7726 +0 0 1 1.475 132.7727 +0 1 1 1.489 132.7728 +0 0 1 1.549 132.7729 +0 1 1 1.565 132.7730 +0 0 1 1.629 132.7731 +0 1 1 1.645 132.7732 +0 0 1 1.703 132.7733 +0 1 1 1.719 132.7734 +0 0 1 1.745 132.7735 +0 1 1 1.761 132.7736 +0 0 1 1.835 132.7737 +0 1 1 1.851 132.7738 +0 0 1 1.915 132.7739 +0 1 1 1.931 132.7740 +0 0 1 1.989 132.7741 +0 1 1 2.003 132.7742 +0 0 1 2.073 132.7743 +0 1 1 2.089 132.7744 +0 0 1 2.165 132.7745 +0 1 1 2.301 132.7746 +0 0 1 2.517 132.7747 +0 1 1 2.535 132.7748 +0 0 1 2.575 132.7749 +0 1 1 2.593 132.7750 +0 0 1 2.599 132.7751 +0 1 1 2.649 132.7752 +0 0 1 2.687 132.7753 +0 1 1 2.705 132.7754 +0 0 1 2.911 132.7755 +0 1 1 2.925 132.7756 +0 0 1 2.925 132.7757 +0 0 0 2.925 132.7758 +0 1 0 2.911 132.7759 +0 0 0 2.707 132.7760 +0 1 0 2.689 132.7761 +0 0 0 2.647 132.7762 +0 1 0 2.599 132.7763 +0 0 0 2.595 132.7764 +0 1 0 2.575 132.7765 +0 0 0 2.533 132.7766 +0 1 0 2.517 132.7767 +0 0 0 2.289 132.7768 +0 1 0 2.159 132.7769 +0 0 0 2.089 132.7770 +0 1 0 2.073 132.7771 +0 0 0 2.003 132.7772 +0 1 0 1.989 132.7773 +0 0 0 1.931 132.7774 +0 1 0 1.915 132.7775 +0 0 0 1.851 132.7776 +0 1 0 1.833 132.7777 +0 0 0 1.761 132.7778 +0 1 0 1.743 132.7779 +0 0 0 1.719 132.7780 +0 1 0 1.703 132.7781 +0 0 0 1.645 132.7782 +0 1 0 1.629 132.7783 +0 0 0 1.565 132.7784 +0 1 0 1.549 132.7785 +0 0 0 1.489 132.7786 +0 1 0 1.475 132.7787 +0 0 0 1.303 132.7788 +0 1 0 1.287 132.7789 +0 0 0 1.229 132.7790 +0 1 0 1.213 132.7791 +0 0 0 1.089 132.7792 +0 1 0 1.075 132.7793 +0 0 0 1.075 132.7794 +0 0 1 1.075 132.7795 +0 1 1 1.089 132.7796 +0 0 1 1.213 132.7797 +0 1 1 1.229 132.7798 +0 0 1 1.287 132.7799 +0 1 1 1.303 132.7800 +0 0 1 1.475 132.7801 +0 1 1 1.489 132.7802 +0 0 1 1.549 132.7803 +0 1 1 1.565 132.7804 +0 0 1 1.629 132.7805 +0 1 1 1.645 132.7806 +0 0 1 1.703 132.7807 +0 1 1 1.719 132.7808 +0 0 1 1.743 132.7809 +0 1 1 1.759 132.7810 +0 0 1 1.833 132.7811 +0 1 1 1.849 132.7812 +0 0 1 1.915 132.7813 +0 1 1 1.931 132.7814 +0 0 1 1.989 132.7815 +0 1 1 2.003 132.7816 +0 0 1 2.071 132.7817 +0 1 1 2.087 132.7818 +0 0 1 2.157 132.7819 +0 1 1 2.265 132.7820 +0 0 1 2.515 132.7821 +0 1 1 2.533 132.7822 +0 0 1 2.577 132.7823 +0 1 1 2.597 132.7824 +0 0 1 2.601 132.7825 +0 1 1 2.645 132.7826 +0 0 1 2.689 132.7827 +0 1 1 2.707 132.7828 +0 0 1 2.911 132.7829 +0 1 1 2.925 132.7830 +0 0 1 2.925 132.7831 +0 0 0 2.925 132.7832 +0 1 0 2.911 132.7833 +0 0 0 2.709 132.7834 +0 1 0 2.691 132.7835 +0 0 0 2.641 132.7836 +0 1 0 2.605 132.7837 +0 0 0 2.597 132.7838 +0 1 0 2.579 132.7839 +0 0 0 2.531 132.7840 +0 1 0 2.513 132.7841 +0 0 0 2.233 132.7842 +0 1 0 2.155 132.7843 +0 0 0 2.087 132.7844 +0 1 0 2.071 132.7845 +0 0 0 2.003 132.7846 +0 1 0 1.989 132.7847 +0 0 0 1.931 132.7848 +0 1 0 1.915 132.7849 +0 0 0 1.849 132.7850 +0 1 0 1.831 132.7851 +0 0 0 1.759 132.7852 +0 1 0 1.741 132.7853 +0 0 0 1.719 132.7854 +0 1 0 1.703 132.7855 +0 0 0 1.645 132.7856 +0 1 0 1.629 132.7857 +0 0 0 1.565 132.7858 +0 1 0 1.549 132.7859 +0 0 0 1.489 132.7860 +0 1 0 1.473 132.7861 +0 0 0 1.303 132.7862 +0 1 0 1.287 132.7863 +0 0 0 1.229 132.7864 +0 1 0 1.213 132.7865 +0 0 0 1.089 132.7866 +0 1 0 1.075 132.7867 +0 0 0 1.075 132.7868 +0 0 1 1.075 132.7869 +0 1 1 1.089 132.7870 +0 0 1 1.213 132.7871 +0 1 1 1.229 132.7872 +0 0 1 1.287 132.7873 +0 1 1 1.303 132.7874 +0 0 1 1.473 132.7875 +0 1 1 1.489 132.7876 +0 0 1 1.549 132.7877 +0 1 1 1.565 132.7878 +0 0 1 1.629 132.7879 +0 1 1 1.645 132.7880 +0 0 1 1.703 132.7881 +0 1 1 1.719 132.7882 +0 0 1 1.741 132.7883 +0 1 1 1.759 132.7884 +0 0 1 1.829 132.7885 +0 1 1 1.847 132.7886 +0 0 1 1.915 132.7887 +0 1 1 1.931 132.7888 +0 0 1 1.989 132.7889 +0 1 1 2.003 132.7890 +0 0 1 2.071 132.7891 +0 1 1 2.087 132.7892 +0 0 1 2.153 132.7893 +0 1 1 2.211 132.7894 +0 0 1 2.511 132.7895 +0 1 1 2.529 132.7896 +0 0 1 2.579 132.7897 +0 1 1 2.599 132.7898 +0 0 1 2.693 132.7899 +0 1 1 2.711 132.7900 +0 0 1 2.911 132.7901 +0 1 1 2.925 132.7902 +0 0 1 2.925 132.7903 +0 0 0 2.925 132.7904 +0 1 0 2.911 132.7905 +0 0 0 2.711 132.7906 +0 1 0 2.693 132.7907 +0 0 0 2.601 132.7908 +0 1 0 2.581 132.7909 +0 0 0 2.529 132.7910 +0 1 0 2.511 132.7911 +0 0 0 2.191 132.7912 +0 1 0 2.151 132.7913 +0 0 0 2.087 132.7914 +0 1 0 2.071 132.7915 +0 0 0 2.003 132.7916 +0 1 0 1.989 132.7917 +0 0 0 1.931 132.7918 +0 1 0 1.915 132.7919 +0 0 0 1.847 132.7920 +0 1 0 1.829 132.7921 +0 0 0 1.757 132.7922 +0 1 0 1.741 132.7923 +0 0 0 1.717 132.7924 +0 1 0 1.703 132.7925 +0 0 0 1.645 132.7926 +0 1 0 1.629 132.7927 +0 0 0 1.565 132.7928 +0 1 0 1.549 132.7929 +0 0 0 1.489 132.7930 +0 1 0 1.473 132.7931 +0 0 0 1.303 132.7932 +0 1 0 1.287 132.7933 +0 0 0 1.229 132.7934 +0 1 0 1.213 132.7935 +0 0 0 1.089 132.7936 +0 1 0 1.075 132.7937 +0 0 0 1.075 132.7938 +0 0 1 1.075 132.7939 +0 1 1 1.089 132.7940 +0 0 1 1.213 132.7941 +0 1 1 1.229 132.7942 +0 0 1 1.287 132.7943 +0 1 1 1.303 132.7944 +0 0 1 1.473 132.7945 +0 1 1 1.489 132.7946 +0 0 1 1.549 132.7947 +0 1 1 1.565 132.7948 +0 0 1 1.629 132.7949 +0 1 1 1.645 132.7950 +0 0 1 1.703 132.7951 +0 1 1 1.717 132.7952 +0 0 1 1.739 132.7953 +0 1 1 1.757 132.7954 +0 0 1 1.827 132.7955 +0 1 1 1.845 132.7956 +0 0 1 1.915 132.7957 +0 1 1 1.931 132.7958 +0 0 1 1.989 132.7959 +0 1 1 2.003 132.7960 +0 0 1 2.071 132.7961 +0 1 1 2.087 132.7962 +0 0 1 2.151 132.7963 +0 1 1 2.179 132.7964 +0 0 1 2.509 132.7965 +0 1 1 2.527 132.7966 +0 0 1 2.583 132.7967 +0 1 1 2.603 132.7968 +0 0 1 2.619 132.7969 +0 1 1 2.639 132.7970 +0 0 1 2.695 132.7971 +0 1 1 2.713 132.7972 +0 0 1 2.911 132.7973 +0 1 1 2.925 132.7974 +0 0 1 2.925 132.7975 +0 0 0 2.925 132.7976 +0 1 0 2.911 132.7977 +0 0 0 2.715 132.7978 +0 1 0 2.697 132.7979 +0 0 0 2.637 132.7980 +0 1 0 2.617 132.7981 +0 0 0 2.605 132.7982 +0 1 0 2.585 132.7983 +0 0 0 2.525 132.7984 +0 1 0 2.507 132.7985 +0 0 0 2.171 132.7986 +0 1 0 2.149 132.7987 +0 0 0 2.085 132.7988 +0 1 0 2.071 132.7989 +0 0 0 2.003 132.7990 +0 1 0 1.989 132.7991 +0 0 0 1.931 132.7992 +0 1 0 1.915 132.7993 +0 0 0 1.845 132.7994 +0 1 0 1.827 132.7995 +0 0 0 1.755 132.7996 +0 1 0 1.739 132.7997 +0 0 0 1.717 132.7998 +0 1 0 1.703 132.7999 +0 0 0 1.645 132.8000 +0 1 0 1.629 132.8001 +0 0 0 1.565 132.8002 +0 1 0 1.549 132.8003 +0 0 0 1.489 132.8004 +0 1 0 1.473 132.8005 +0 0 0 1.303 132.8006 +0 1 0 1.287 132.8007 +0 0 0 1.229 132.8008 +0 1 0 1.213 132.8009 +0 0 0 1.089 132.8010 +0 1 0 1.075 132.8011 +0 0 0 1.075 132.8012 +0 0 1 1.075 132.8013 +0 1 1 1.089 132.8014 +0 0 1 1.213 132.8015 +0 1 1 1.229 132.8016 +0 0 1 1.287 132.8017 +0 1 1 1.303 132.8018 +0 0 1 1.473 132.8019 +0 1 1 1.489 132.8020 +0 0 1 1.549 132.8021 +0 1 1 1.565 132.8022 +0 0 1 1.629 132.8023 +0 1 1 1.645 132.8024 +0 0 1 1.703 132.8025 +0 1 1 1.717 132.8026 +0 0 1 1.737 132.8027 +0 1 1 1.755 132.8028 +0 0 1 1.825 132.8029 +0 1 1 1.843 132.8030 +0 0 1 1.915 132.8031 +0 1 1 1.931 132.8032 +0 0 1 1.989 132.8033 +0 1 1 2.003 132.8034 +0 0 1 2.071 132.8035 +0 1 1 2.085 132.8036 +0 0 1 2.149 132.8037 +0 1 1 2.167 132.8038 +0 0 1 2.507 132.8039 +0 1 1 2.525 132.8040 +0 0 1 2.587 132.8041 +0 1 1 2.607 132.8042 +0 0 1 2.615 132.8043 +0 1 1 2.635 132.8044 +0 0 1 2.699 132.8045 +0 1 1 2.717 132.8046 +0 0 1 2.911 132.8047 +0 1 1 2.925 132.8048 +0 0 1 2.925 132.8049 +0 0 0 2.925 132.8050 +0 1 0 2.911 132.8051 +0 0 0 2.717 132.8052 +0 1 0 2.699 132.8053 +0 0 0 2.633 132.8054 +0 1 0 2.615 132.8055 +0 0 0 2.609 132.8056 +0 1 0 2.589 132.8057 +0 0 0 2.523 132.8058 +0 1 0 2.505 132.8059 +0 0 0 2.165 132.8060 +0 1 0 2.147 132.8061 +0 0 0 2.085 132.8062 +0 1 0 2.069 132.8063 +0 0 0 2.003 132.8064 +0 1 0 1.989 132.8065 +0 0 0 1.931 132.8066 +0 1 0 1.915 132.8067 +0 0 0 1.843 132.8068 +0 1 0 1.825 132.8069 +0 0 0 1.753 132.8070 +0 1 0 1.737 132.8071 +0 0 0 1.717 132.8072 +0 1 0 1.703 132.8073 +0 0 0 1.645 132.8074 +0 1 0 1.629 132.8075 +0 0 0 1.565 132.8076 +0 1 0 1.549 132.8077 +0 0 0 1.489 132.8078 +0 1 0 1.473 132.8079 +0 0 0 1.303 132.8080 +0 1 0 1.287 132.8081 +0 0 0 1.229 132.8082 +0 1 0 1.213 132.8083 +0 0 0 1.089 132.8084 +0 1 0 1.075 132.8085 +0 0 0 1.075 132.8086 +0 0 1 1.075 132.8087 +0 1 1 1.089 132.8088 +0 0 1 1.213 132.8089 +0 1 1 1.229 132.8090 +0 0 1 1.287 132.8091 +0 1 1 1.303 132.8092 +0 0 1 1.473 132.8093 +0 1 1 1.489 132.8094 +0 0 1 1.549 132.8095 +0 1 1 1.565 132.8096 +0 0 1 1.629 132.8097 +0 1 1 1.645 132.8098 +0 0 1 1.703 132.8099 +0 1 1 1.717 132.8100 +0 0 1 1.735 132.8101 +0 1 1 1.753 132.8102 +0 0 1 1.823 132.8103 +0 1 1 1.841 132.8104 +0 0 1 1.915 132.8105 +0 1 1 1.931 132.8106 +0 0 1 1.989 132.8107 +0 1 1 2.003 132.8108 +0 0 1 2.069 132.8109 +0 1 1 2.085 132.8110 +0 0 1 2.147 132.8111 +0 1 1 2.163 132.8112 +0 0 1 2.503 132.8113 +0 1 1 2.521 132.8114 +0 0 1 2.591 132.8115 +0 1 1 2.611 132.8116 +0 0 1 2.615 132.8117 +0 1 1 2.633 132.8118 +0 0 1 2.701 132.8119 +0 1 1 2.719 132.8120 +0 0 1 2.911 132.8121 +0 1 1 2.925 132.8122 +0 0 1 2.925 132.8123 +0 0 0 2.925 132.8124 +0 1 0 2.911 132.8125 +0 0 0 2.721 132.8126 +0 1 0 2.703 132.8127 +0 0 0 2.631 132.8128 +0 1 0 2.617 132.8129 +0 0 0 2.611 132.8130 +0 1 0 2.593 132.8131 +0 0 0 2.519 132.8132 +0 1 0 2.503 132.8133 +0 0 0 2.163 132.8134 +0 1 0 2.147 132.8135 +0 0 0 2.085 132.8136 +0 1 0 2.069 132.8137 +0 0 0 2.003 132.8138 +0 1 0 1.989 132.8139 +0 0 0 1.931 132.8140 +0 1 0 1.915 132.8141 +0 0 0 1.841 132.8142 +0 1 0 1.823 132.8143 +0 0 0 1.751 132.8144 +0 1 0 1.735 132.8145 +0 0 0 1.717 132.8146 +0 1 0 1.703 132.8147 +0 0 0 1.645 132.8148 +0 1 0 1.629 132.8149 +0 0 0 1.565 132.8150 +0 1 0 1.549 132.8151 +0 0 0 1.489 132.8152 +0 1 0 1.473 132.8153 +0 0 0 1.303 132.8154 +0 1 0 1.287 132.8155 +0 0 0 1.229 132.8156 +0 1 0 1.213 132.8157 +0 0 0 1.089 132.8158 +0 1 0 1.075 132.8159 +0 0 0 1.075 132.8160 +0 0 1 1.075 132.8161 +0 1 1 1.089 132.8162 +0 0 1 1.213 132.8163 +0 1 1 1.229 132.8164 +0 0 1 1.287 132.8165 +0 1 1 1.303 132.8166 +0 0 1 1.473 132.8167 +0 1 1 1.487 132.8168 +0 0 1 1.549 132.8169 +0 1 1 1.565 132.8170 +0 0 1 1.629 132.8171 +0 1 1 1.645 132.8172 +0 0 1 1.703 132.8173 +0 1 1 1.717 132.8174 +0 0 1 1.735 132.8175 +0 1 1 1.751 132.8176 +0 0 1 1.821 132.8177 +0 1 1 1.839 132.8178 +0 0 1 1.915 132.8179 +0 1 1 1.931 132.8180 +0 0 1 1.989 132.8181 +0 1 1 2.003 132.8182 +0 0 1 2.069 132.8183 +0 1 1 2.085 132.8184 +0 0 1 2.145 132.8185 +0 1 1 2.161 132.8186 +0 0 1 2.501 132.8187 +0 1 1 2.519 132.8188 +0 0 1 2.593 132.8189 +0 1 1 2.613 132.8190 +0 0 1 2.619 132.8191 +0 1 1 2.629 132.8192 +0 0 1 2.703 132.8193 +0 1 1 2.721 132.8194 +0 0 1 2.911 132.8195 +0 1 1 2.925 132.8196 +0 0 1 2.925 132.8197 +0 0 0 2.925 132.8198 +0 1 0 2.911 132.8199 +0 0 0 2.723 132.8200 +0 1 0 2.705 132.8201 +0 0 0 2.627 132.8202 +0 1 0 2.621 132.8203 +0 0 0 2.615 132.8204 +0 1 0 2.595 132.8205 +0 0 0 2.517 132.8206 +0 1 0 2.499 132.8207 +0 0 0 2.161 132.8208 +0 1 0 2.145 132.8209 +0 0 0 2.085 132.8210 +0 1 0 2.069 132.8211 +0 0 0 2.003 132.8212 +0 1 0 1.989 132.8213 +0 0 0 1.931 132.8214 +0 1 0 1.915 132.8215 +0 0 0 1.839 132.8216 +0 1 0 1.821 132.8217 +0 0 0 1.749 132.8218 +0 1 0 1.733 132.8219 +0 0 0 1.717 132.8220 +0 1 0 1.703 132.8221 +0 0 0 1.645 132.8222 +0 1 0 1.629 132.8223 +0 0 0 1.565 132.8224 +0 1 0 1.549 132.8225 +0 0 0 1.487 132.8226 +0 1 0 1.473 132.8227 +0 0 0 1.303 132.8228 +0 1 0 1.287 132.8229 +0 0 0 1.229 132.8230 +0 1 0 1.213 132.8231 +0 0 0 1.089 132.8232 +0 1 0 1.075 132.8233 +0 0 0 1.075 132.8234 +0 0 1 1.075 132.8235 +0 1 1 1.089 132.8236 +0 0 1 1.213 132.8237 +0 1 1 1.229 132.8238 +0 0 1 1.287 132.8239 +0 1 1 1.303 132.8240 +0 0 1 1.473 132.8241 +0 1 1 1.487 132.8242 +0 0 1 1.549 132.8243 +0 1 1 1.563 132.8244 +0 0 1 1.629 132.8245 +0 1 1 1.645 132.8246 +0 0 1 1.703 132.8247 +0 1 1 1.717 132.8248 +0 0 1 1.733 132.8249 +0 1 1 1.749 132.8250 +0 0 1 1.819 132.8251 +0 1 1 1.837 132.8252 +0 0 1 1.915 132.8253 +0 1 1 1.931 132.8254 +0 0 1 1.989 132.8255 +0 1 1 2.003 132.8256 +0 0 1 2.069 132.8257 +0 1 1 2.085 132.8258 +0 0 1 2.145 132.8259 +0 1 1 2.161 132.8260 +0 0 1 2.499 132.8261 +0 1 1 2.515 132.8262 +0 0 1 2.597 132.8263 +0 1 1 2.617 132.8264 +0 0 1 2.623 132.8265 +0 1 1 2.625 132.8266 +0 0 1 2.707 132.8267 +0 1 1 2.725 132.8268 +0 0 1 2.911 132.8269 +0 1 1 2.925 132.8270 +0 0 1 2.925 132.8271 +0 0 0 2.925 132.8272 +0 1 0 2.911 132.8273 +0 0 0 2.725 132.8274 +0 1 0 2.709 132.8275 +0 0 0 2.619 132.8276 +0 1 0 2.599 132.8277 +0 0 0 2.515 132.8278 +0 1 0 2.497 132.8279 +0 0 0 2.161 132.8280 +0 1 0 2.145 132.8281 +0 0 0 2.085 132.8282 +0 1 0 2.069 132.8283 +0 0 0 2.003 132.8284 +0 1 0 1.989 132.8285 +0 0 0 1.931 132.8286 +0 1 0 1.915 132.8287 +0 0 0 1.835 132.8288 +0 1 0 1.819 132.8289 +0 0 0 1.747 132.8290 +0 1 0 1.731 132.8291 +0 0 0 1.717 132.8292 +0 1 0 1.703 132.8293 +0 0 0 1.645 132.8294 +0 1 0 1.629 132.8295 +0 0 0 1.563 132.8296 +0 1 0 1.549 132.8297 +0 0 0 1.487 132.8298 +0 1 0 1.473 132.8299 +0 0 0 1.303 132.8300 +0 1 0 1.287 132.8301 +0 0 0 1.229 132.8302 +0 1 0 1.213 132.8303 +0 0 0 1.089 132.8304 +0 1 0 1.075 132.8305 +0 0 0 1.075 132.8306 +0 0 1 1.075 132.8307 +0 1 1 1.089 132.8308 +0 0 1 1.213 132.8309 +0 1 1 1.229 132.8310 +0 0 1 1.287 132.8311 +0 1 1 1.303 132.8312 +0 0 1 1.471 132.8313 +0 1 1 1.487 132.8314 +0 0 1 1.549 132.8315 +0 1 1 1.563 132.8316 +0 0 1 1.629 132.8317 +0 1 1 1.645 132.8318 +0 0 1 1.703 132.8319 +0 1 1 1.717 132.8320 +0 0 1 1.731 132.8321 +0 1 1 1.747 132.8322 +0 0 1 1.817 132.8323 +0 1 1 1.835 132.8324 +0 0 1 1.915 132.8325 +0 1 1 1.931 132.8326 +0 0 1 1.989 132.8327 +0 1 1 2.003 132.8328 +0 0 1 2.069 132.8329 +0 1 1 2.083 132.8330 +0 0 1 2.145 132.8331 +0 1 1 2.159 132.8332 +0 0 1 2.495 132.8333 +0 1 1 2.513 132.8334 +0 0 1 2.601 132.8335 +0 1 1 2.621 132.8336 +0 0 1 2.709 132.8337 +0 1 1 2.727 132.8338 +0 0 1 2.911 132.8339 +0 1 1 2.925 132.8340 +0 0 1 2.925 132.8341 +0 0 0 2.925 132.8342 +0 1 0 2.911 132.8343 +0 0 0 2.729 132.8344 +0 1 0 2.711 132.8345 +0 0 0 2.623 132.8346 +0 1 0 2.603 132.8347 +0 0 0 2.511 132.8348 +0 1 0 2.493 132.8349 +0 0 0 2.159 132.8350 +0 1 0 2.143 132.8351 +0 0 0 2.083 132.8352 +0 1 0 2.069 132.8353 +0 0 0 2.003 132.8354 +0 1 0 1.989 132.8355 +0 0 0 1.931 132.8356 +0 1 0 1.915 132.8357 +0 0 0 1.835 132.8358 +0 1 0 1.817 132.8359 +0 0 0 1.747 132.8360 +0 1 0 1.729 132.8361 +0 0 0 1.717 132.8362 +0 1 0 1.703 132.8363 +0 0 0 1.645 132.8364 +0 1 0 1.629 132.8365 +0 0 0 1.563 132.8366 +0 1 0 1.549 132.8367 +0 0 0 1.487 132.8368 +0 1 0 1.471 132.8369 +0 0 0 1.303 132.8370 +0 1 0 1.287 132.8371 +0 0 0 1.229 132.8372 +0 1 0 1.213 132.8373 +0 0 0 1.089 132.8374 +0 1 0 1.075 132.8375 +0 0 0 1.075 132.8376 +0 0 1 1.075 132.8377 +0 1 1 1.089 132.8378 +0 0 1 1.213 132.8379 +0 1 1 1.229 132.8380 +0 0 1 1.287 132.8381 +0 1 1 1.303 132.8382 +0 0 1 1.471 132.8383 +0 1 1 1.487 132.8384 +0 0 1 1.547 132.8385 +0 1 1 1.563 132.8386 +0 0 1 1.629 132.8387 +0 1 1 1.645 132.8388 +0 0 1 1.703 132.8389 +0 1 1 1.717 132.8390 +0 0 1 1.729 132.8391 +0 1 1 1.745 132.8392 +0 0 1 1.815 132.8393 +0 1 1 1.833 132.8394 +0 0 1 1.915 132.8395 +0 1 1 1.931 132.8396 +0 0 1 1.989 132.8397 +0 1 1 2.003 132.8398 +0 0 1 2.069 132.8399 +0 1 1 2.083 132.8400 +0 0 1 2.143 132.8401 +0 1 1 2.159 132.8402 +0 0 1 2.493 132.8403 +0 1 1 2.511 132.8404 +0 0 1 2.605 132.8405 +0 1 1 2.625 132.8406 +0 0 1 2.711 132.8407 +0 1 1 2.729 132.8408 +0 0 1 2.911 132.8409 +0 1 1 2.925 132.8410 +0 0 1 2.925 132.8411 +0 0 0 2.925 132.8412 +0 1 0 2.911 132.8413 +0 0 0 2.731 132.8414 +0 1 0 2.713 132.8415 +0 0 0 2.627 132.8416 +0 1 0 2.605 132.8417 +0 0 0 2.601 132.8418 +0 1 0 2.597 132.8419 +0 0 0 2.509 132.8420 +0 1 0 2.491 132.8421 +0 0 0 2.159 132.8422 +0 1 0 2.143 132.8423 +0 0 0 2.083 132.8424 +0 1 0 2.069 132.8425 +0 0 0 2.003 132.8426 +0 1 0 1.989 132.8427 +0 0 0 1.931 132.8428 +0 1 0 1.915 132.8429 +0 0 0 1.833 132.8430 +0 1 0 1.815 132.8431 +0 0 0 1.745 132.8432 +0 1 0 1.727 132.8433 +0 0 0 1.717 132.8434 +0 1 0 1.703 132.8435 +0 0 0 1.645 132.8436 +0 1 0 1.629 132.8437 +0 0 0 1.563 132.8438 +0 1 0 1.547 132.8439 +0 0 0 1.487 132.8440 +0 1 0 1.471 132.8441 +0 0 0 1.303 132.8442 +0 1 0 1.287 132.8443 +0 0 0 1.229 132.8444 +0 1 0 1.213 132.8445 +0 0 0 1.089 132.8446 +0 1 0 1.075 132.8447 +0 0 0 1.075 132.8448 +0 0 1 1.075 132.8449 +0 1 1 1.089 132.8450 +0 0 1 1.213 132.8451 +0 1 1 1.229 132.8452 +0 0 1 1.287 132.8453 +0 1 1 1.303 132.8454 +0 0 1 1.471 132.8455 +0 1 1 1.487 132.8456 +0 0 1 1.547 132.8457 +0 1 1 1.563 132.8458 +0 0 1 1.629 132.8459 +0 1 1 1.645 132.8460 +0 0 1 1.703 132.8461 +0 1 1 1.717 132.8462 +0 0 1 1.727 132.8463 +0 1 1 1.743 132.8464 +0 0 1 1.813 132.8465 +0 1 1 1.831 132.8466 +0 0 1 1.915 132.8467 +0 1 1 1.931 132.8468 +0 0 1 1.989 132.8469 +0 1 1 2.003 132.8470 +0 0 1 2.069 132.8471 +0 1 1 2.083 132.8472 +0 0 1 2.143 132.8473 +0 1 1 2.159 132.8474 +0 0 1 2.301 132.8475 +0 1 1 2.383 132.8476 +0 0 1 2.489 132.8477 +0 1 1 2.507 132.8478 +0 0 1 2.595 132.8479 +0 1 1 2.601 132.8480 +0 0 1 2.607 132.8481 +0 1 1 2.627 132.8482 +0 0 1 2.715 132.8483 +0 1 1 2.733 132.8484 +0 0 1 2.911 132.8485 +0 1 1 2.925 132.8486 +0 0 1 2.925 132.8487 +0 0 0 2.925 132.8488 +0 1 0 2.911 132.8489 +0 0 0 2.735 132.8490 +0 1 0 2.717 132.8491 +0 0 0 2.629 132.8492 +0 1 0 2.609 132.8493 +0 0 0 2.603 132.8494 +0 1 0 2.593 132.8495 +0 0 0 2.507 132.8496 +0 1 0 2.489 132.8497 +0 0 0 2.385 132.8498 +0 1 0 2.299 132.8499 +0 0 0 2.159 132.8500 +0 1 0 2.143 132.8501 +0 0 0 2.083 132.8502 +0 1 0 2.069 132.8503 +0 0 0 2.003 132.8504 +0 1 0 1.989 132.8505 +0 0 0 1.931 132.8506 +0 1 0 1.915 132.8507 +0 0 0 1.829 132.8508 +0 1 0 1.813 132.8509 +0 0 0 1.743 132.8510 +0 1 0 1.725 132.8511 +0 0 0 1.717 132.8512 +0 1 0 1.703 132.8513 +0 0 0 1.645 132.8514 +0 1 0 1.629 132.8515 +0 0 0 1.563 132.8516 +0 1 0 1.547 132.8517 +0 0 0 1.487 132.8518 +0 1 0 1.471 132.8519 +0 0 0 1.303 132.8520 +0 1 0 1.287 132.8521 +0 0 0 1.229 132.8522 +0 1 0 1.213 132.8523 +0 0 0 1.089 132.8524 +0 1 0 1.075 132.8525 +0 0 0 1.075 132.8526 +0 0 1 1.075 132.8527 +0 1 1 1.089 132.8528 +0 0 1 1.213 132.8529 +0 1 1 1.229 132.8530 +0 0 1 1.287 132.8531 +0 1 1 1.303 132.8532 +0 0 1 1.469 132.8533 +0 1 1 1.485 132.8534 +0 0 1 1.547 132.8535 +0 1 1 1.563 132.8536 +0 0 1 1.629 132.8537 +0 1 1 1.645 132.8538 +0 0 1 1.703 132.8539 +0 1 1 1.717 132.8540 +0 0 1 1.725 132.8541 +0 1 1 1.741 132.8542 +0 0 1 1.811 132.8543 +0 1 1 1.829 132.8544 +0 0 1 1.915 132.8545 +0 1 1 1.931 132.8546 +0 0 1 1.989 132.8547 +0 1 1 2.003 132.8548 +0 0 1 2.069 132.8549 +0 1 1 2.083 132.8550 +0 0 1 2.143 132.8551 +0 1 1 2.159 132.8552 +0 0 1 2.299 132.8553 +0 1 1 2.385 132.8554 +0 0 1 2.487 132.8555 +0 1 1 2.505 132.8556 +0 0 1 2.591 132.8557 +0 1 1 2.605 132.8558 +0 0 1 2.611 132.8559 +0 1 1 2.631 132.8560 +0 0 1 2.717 132.8561 +0 1 1 2.735 132.8562 +0 0 1 2.911 132.8563 +0 1 1 2.925 132.8564 +0 0 1 2.925 132.8565 +0 0 0 2.925 132.8566 +0 1 0 2.911 132.8567 +0 0 0 2.737 132.8568 +0 1 0 2.719 132.8569 +0 0 0 2.633 132.8570 +0 1 0 2.613 132.8571 +0 0 0 2.607 132.8572 +0 1 0 2.589 132.8573 +0 0 0 2.503 132.8574 +0 1 0 2.485 132.8575 +0 0 0 2.385 132.8576 +0 1 0 2.299 132.8577 +0 0 0 2.159 132.8578 +0 1 0 2.143 132.8579 +0 0 0 2.083 132.8580 +0 1 0 2.069 132.8581 +0 0 0 2.003 132.8582 +0 1 0 1.989 132.8583 +0 0 0 1.931 132.8584 +0 1 0 1.915 132.8585 +0 0 0 1.827 132.8586 +0 1 0 1.811 132.8587 +0 0 0 1.741 132.8588 +0 1 0 1.723 132.8589 +0 0 0 1.717 132.8590 +0 1 0 1.703 132.8591 +0 0 0 1.645 132.8592 +0 1 0 1.629 132.8593 +0 0 0 1.563 132.8594 +0 1 0 1.547 132.8595 +0 0 0 1.485 132.8596 +0 1 0 1.469 132.8597 +0 0 0 1.303 132.8598 +0 1 0 1.287 132.8599 +0 0 0 1.229 132.8600 +0 1 0 1.213 132.8601 +0 0 0 1.089 132.8602 +0 1 0 1.075 132.8603 +0 0 0 1.075 132.8604 +0 0 1 1.075 132.8605 +0 1 1 1.089 132.8606 +0 0 1 1.213 132.8607 +0 1 1 1.229 132.8608 +0 0 1 1.287 132.8609 +0 1 1 1.303 132.8610 +0 0 1 1.469 132.8611 +0 1 1 1.485 132.8612 +0 0 1 1.547 132.8613 +0 1 1 1.561 132.8614 +0 0 1 1.629 132.8615 +0 1 1 1.645 132.8616 +0 0 1 1.703 132.8617 +0 1 1 1.717 132.8618 +0 0 1 1.723 132.8619 +0 1 1 1.741 132.8620 +0 0 1 1.809 132.8621 +0 1 1 1.827 132.8622 +0 0 1 1.915 132.8623 +0 1 1 1.931 132.8624 +0 0 1 1.989 132.8625 +0 1 1 2.003 132.8626 +0 0 1 2.069 132.8627 +0 1 1 2.083 132.8628 +0 0 1 2.143 132.8629 +0 1 1 2.159 132.8630 +0 0 1 2.297 132.8631 +0 1 1 2.385 132.8632 +0 0 1 2.485 132.8633 +0 1 1 2.501 132.8634 +0 0 1 2.587 132.8635 +0 1 1 2.607 132.8636 +0 0 1 2.615 132.8637 +0 1 1 2.635 132.8638 +0 0 1 2.721 132.8639 +0 1 1 2.739 132.8640 +0 0 1 2.911 132.8641 +0 1 1 2.925 132.8642 +0 0 1 2.925 132.8643 +0 0 0 2.925 132.8644 +0 1 0 2.911 132.8645 +0 0 0 2.739 132.8646 +0 1 0 2.721 132.8647 +0 0 0 2.637 132.8648 +0 1 0 2.617 132.8649 +0 0 0 2.605 132.8650 +0 1 0 2.585 132.8651 +0 0 0 2.501 132.8652 +0 1 0 2.483 132.8653 +0 0 0 2.385 132.8654 +0 1 0 2.297 132.8655 +0 0 0 2.159 132.8656 +0 1 0 2.143 132.8657 +0 0 0 2.083 132.8658 +0 1 0 2.069 132.8659 +0 0 0 2.003 132.8660 +0 1 0 1.989 132.8661 +0 0 0 1.931 132.8662 +0 1 0 1.915 132.8663 +0 0 0 1.825 132.8664 +0 1 0 1.809 132.8665 +0 0 0 1.739 132.8666 +0 1 0 1.723 132.8667 +0 0 0 1.717 132.8668 +0 1 0 1.703 132.8669 +0 0 0 1.645 132.8670 +0 1 0 1.629 132.8671 +0 0 0 1.561 132.8672 +0 1 0 1.547 132.8673 +0 0 0 1.485 132.8674 +0 1 0 1.469 132.8675 +0 0 0 1.303 132.8676 +0 1 0 1.287 132.8677 +0 0 0 1.229 132.8678 +0 1 0 1.213 132.8679 +0 0 0 1.089 132.8680 +0 1 0 1.075 132.8681 +0 0 0 1.075 132.8682 +0 0 1 1.075 132.8683 +0 1 1 1.089 132.8684 +0 0 1 1.213 132.8685 +0 1 1 1.229 132.8686 +0 0 1 1.287 132.8687 +0 1 1 1.303 132.8688 +0 0 1 1.469 132.8689 +0 1 1 1.485 132.8690 +0 0 1 1.545 132.8691 +0 1 1 1.561 132.8692 +0 0 1 1.629 132.8693 +0 1 1 1.645 132.8694 +0 0 1 1.703 132.8695 +0 1 1 1.717 132.8696 +0 0 1 1.721 132.8697 +0 1 1 1.739 132.8698 +0 0 1 1.807 132.8699 +0 1 1 1.825 132.8700 +0 0 1 1.915 132.8701 +0 1 1 1.931 132.8702 +0 0 1 1.989 132.8703 +0 1 1 2.003 132.8704 +0 0 1 2.069 132.8705 +0 1 1 2.083 132.8706 +0 0 1 2.143 132.8707 +0 1 1 2.159 132.8708 +0 0 1 2.297 132.8709 +0 1 1 2.385 132.8710 +0 0 1 2.481 132.8711 +0 1 1 2.499 132.8712 +0 0 1 2.583 132.8713 +0 1 1 2.603 132.8714 +0 0 1 2.619 132.8715 +0 1 1 2.639 132.8716 +0 0 1 2.723 132.8717 +0 1 1 2.741 132.8718 +0 0 1 2.911 132.8719 +0 1 1 2.925 132.8720 +0 0 1 2.925 132.8721 +0 0 0 2.925 132.8722 +0 1 0 2.911 132.8723 +0 0 0 2.743 132.8724 +0 1 0 2.725 132.8725 +0 0 0 2.641 132.8726 +0 1 0 2.621 132.8727 +0 0 0 2.601 132.8728 +0 1 0 2.581 132.8729 +0 0 0 2.497 132.8730 +0 1 0 2.481 132.8731 +0 0 0 2.385 132.8732 +0 1 0 2.369 132.8733 +0 0 0 2.313 132.8734 +0 1 0 2.297 132.8735 +0 0 0 2.159 132.8736 +0 1 0 2.143 132.8737 +0 0 0 2.083 132.8738 +0 1 0 2.069 132.8739 +0 0 0 2.003 132.8740 +0 1 0 1.989 132.8741 +0 0 0 1.931 132.8742 +0 1 0 1.915 132.8743 +0 0 0 1.823 132.8744 +0 1 0 1.807 132.8745 +0 0 0 1.737 132.8746 +0 1 0 1.721 132.8747 +0 0 0 1.717 132.8748 +0 1 0 1.703 132.8749 +0 0 0 1.645 132.8750 +0 1 0 1.629 132.8751 +0 0 0 1.561 132.8752 +0 1 0 1.545 132.8753 +0 0 0 1.483 132.8754 +0 1 0 1.467 132.8755 +0 0 0 1.303 132.8756 +0 1 0 1.287 132.8757 +0 0 0 1.229 132.8758 +0 1 0 1.213 132.8759 +0 0 0 1.089 132.8760 +0 1 0 1.075 132.8761 +0 0 0 1.075 132.8762 +0 0 1 1.075 132.8763 +0 1 1 1.089 132.8764 +0 0 1 1.213 132.8765 +0 1 1 1.229 132.8766 +0 0 1 1.287 132.8767 +0 1 1 1.303 132.8768 +0 0 1 1.467 132.8769 +0 1 1 1.483 132.8770 +0 0 1 1.545 132.8771 +0 1 1 1.561 132.8772 +0 0 1 1.629 132.8773 +0 1 1 1.645 132.8774 +0 0 1 1.703 132.8775 +0 1 1 1.717 132.8776 +0 0 1 1.719 132.8777 +0 1 1 1.737 132.8778 +0 0 1 1.805 132.8779 +0 1 1 1.823 132.8780 +0 0 1 1.915 132.8781 +0 1 1 1.931 132.8782 +0 0 1 1.989 132.8783 +0 1 1 2.003 132.8784 +0 0 1 2.069 132.8785 +0 1 1 2.083 132.8786 +0 0 1 2.143 132.8787 +0 1 1 2.159 132.8788 +0 0 1 2.297 132.8789 +0 1 1 2.313 132.8790 +0 0 1 2.369 132.8791 +0 1 1 2.385 132.8792 +0 0 1 2.479 132.8793 +0 1 1 2.497 132.8794 +0 0 1 2.579 132.8795 +0 1 1 2.599 132.8796 +0 0 1 2.623 132.8797 +0 1 1 2.643 132.8798 +0 0 1 2.725 132.8799 +0 1 1 2.743 132.8800 +0 0 1 2.911 132.8801 +0 1 1 2.925 132.8802 +0 0 1 2.925 132.8803 +0 0 0 2.925 132.8804 +0 1 0 2.911 132.8805 +0 0 0 2.745 132.8806 +0 1 0 2.727 132.8807 +0 0 0 2.645 132.8808 +0 1 0 2.623 132.8809 +0 0 0 2.599 132.8810 +0 1 0 2.579 132.8811 +0 0 0 2.495 132.8812 +0 1 0 2.477 132.8813 +0 0 0 2.385 132.8814 +0 1 0 2.369 132.8815 +0 0 0 2.313 132.8816 +0 1 0 2.297 132.8817 +0 0 0 2.159 132.8818 +0 1 0 2.143 132.8819 +0 0 0 2.083 132.8820 +0 1 0 2.069 132.8821 +0 0 0 2.003 132.8822 +0 1 0 1.989 132.8823 +0 0 0 1.931 132.8824 +0 1 0 1.915 132.8825 +0 0 0 1.821 132.8826 +0 1 0 1.805 132.8827 +0 0 0 1.735 132.8828 +0 1 0 1.719 132.8829 +0 0 0 1.717 132.8830 +0 1 0 1.701 132.8831 +0 0 0 1.645 132.8832 +0 1 0 1.629 132.8833 +0 0 0 1.561 132.8834 +0 1 0 1.545 132.8835 +0 0 0 1.483 132.8836 +0 1 0 1.467 132.8837 +0 0 0 1.303 132.8838 +0 1 0 1.287 132.8839 +0 0 0 1.229 132.8840 +0 1 0 1.213 132.8841 +0 0 0 1.089 132.8842 +0 1 0 1.075 132.8843 +0 0 0 1.075 132.8844 +0 0 1 1.075 132.8845 +0 1 1 1.089 132.8846 +0 0 1 1.213 132.8847 +0 1 1 1.229 132.8848 +0 0 1 1.287 132.8849 +0 1 1 1.303 132.8850 +0 0 1 1.467 132.8851 +0 1 1 1.483 132.8852 +0 0 1 1.545 132.8853 +0 1 1 1.561 132.8854 +0 0 1 1.629 132.8855 +0 1 1 1.645 132.8856 +0 0 1 1.701 132.8857 +0 1 1 1.735 132.8858 +0 0 1 1.803 132.8859 +0 1 1 1.821 132.8860 +0 0 1 1.915 132.8861 +0 1 1 1.931 132.8862 +0 0 1 1.989 132.8863 +0 1 1 2.003 132.8864 +0 0 1 2.069 132.8865 +0 1 1 2.083 132.8866 +0 0 1 2.143 132.8867 +0 1 1 2.159 132.8868 +0 0 1 2.297 132.8869 +0 1 1 2.313 132.8870 +0 0 1 2.369 132.8871 +0 1 1 2.385 132.8872 +0 0 1 2.475 132.8873 +0 1 1 2.493 132.8874 +0 0 1 2.577 132.8875 +0 1 1 2.597 132.8876 +0 0 1 2.625 132.8877 +0 1 1 2.647 132.8878 +0 0 1 2.729 132.8879 +0 1 1 2.747 132.8880 +0 0 1 2.911 132.8881 +0 1 1 2.925 132.8882 +0 0 1 2.925 132.8883 +0 0 0 2.925 132.8884 +0 1 0 2.911 132.8885 +0 0 0 2.747 132.8886 +0 1 0 2.729 132.8887 +0 0 0 2.647 132.8888 +0 1 0 2.627 132.8889 +0 0 0 2.595 132.8890 +0 1 0 2.575 132.8891 +0 0 0 2.493 132.8892 +0 1 0 2.475 132.8893 +0 0 0 2.385 132.8894 +0 1 0 2.369 132.8895 +0 0 0 2.313 132.8896 +0 1 0 2.297 132.8897 +0 0 0 2.159 132.8898 +0 1 0 2.143 132.8899 +0 0 0 2.083 132.8900 +0 1 0 2.069 132.8901 +0 0 0 2.003 132.8902 +0 1 0 1.989 132.8903 +0 0 0 1.931 132.8904 +0 1 0 1.915 132.8905 +0 0 0 1.819 132.8906 +0 1 0 1.803 132.8907 +0 0 0 1.733 132.8908 +0 1 0 1.701 132.8909 +0 0 0 1.645 132.8910 +0 1 0 1.629 132.8911 +0 0 0 1.559 132.8912 +0 1 0 1.543 132.8913 +0 0 0 1.481 132.8914 +0 1 0 1.465 132.8915 +0 0 0 1.303 132.8916 +0 1 0 1.287 132.8917 +0 0 0 1.229 132.8918 +0 1 0 1.213 132.8919 +0 0 0 1.089 132.8920 +0 1 0 1.075 132.8921 +0 0 0 1.075 132.8922 +0 0 1 1.075 132.8923 +0 1 1 1.089 132.8924 +0 0 1 1.213 132.8925 +0 1 1 1.229 132.8926 +0 0 1 1.287 132.8927 +0 1 1 1.303 132.8928 +0 0 1 1.465 132.8929 +0 1 1 1.481 132.8930 +0 0 1 1.543 132.8931 +0 1 1 1.559 132.8932 +0 0 1 1.629 132.8933 +0 1 1 1.645 132.8934 +0 0 1 1.701 132.8935 +0 1 1 1.733 132.8936 +0 0 1 1.801 132.8937 +0 1 1 1.819 132.8938 +0 0 1 1.915 132.8939 +0 1 1 1.931 132.8940 +0 0 1 1.989 132.8941 +0 1 1 2.003 132.8942 +0 0 1 2.069 132.8943 +0 1 1 2.083 132.8944 +0 0 1 2.143 132.8945 +0 1 1 2.159 132.8946 +0 0 1 2.297 132.8947 +0 1 1 2.313 132.8948 +0 0 1 2.369 132.8949 +0 1 1 2.385 132.8950 +0 0 1 2.473 132.8951 +0 1 1 2.491 132.8952 +0 0 1 2.573 132.8953 +0 1 1 2.593 132.8954 +0 0 1 2.629 132.8955 +0 1 1 2.649 132.8956 +0 0 1 2.731 132.8957 +0 1 1 2.749 132.8958 +0 0 1 2.911 132.8959 +0 1 1 2.925 132.8960 +0 0 1 2.925 132.8961 +0 0 0 2.925 132.8962 +0 1 0 2.911 132.8963 +0 0 0 2.751 132.8964 +0 1 0 2.733 132.8965 +0 0 0 2.651 132.8966 +0 1 0 2.631 132.8967 +0 0 0 2.591 132.8968 +0 1 0 2.571 132.8969 +0 0 0 2.489 132.8970 +0 1 0 2.471 132.8971 +0 0 0 2.385 132.8972 +0 1 0 2.369 132.8973 +0 0 0 2.311 132.8974 +0 1 0 2.295 132.8975 +0 0 0 2.159 132.8976 +0 1 0 2.143 132.8977 +0 0 0 2.085 132.8978 +0 1 0 2.069 132.8979 +0 0 0 2.003 132.8980 +0 1 0 1.989 132.8981 +0 0 0 1.931 132.8982 +0 1 0 1.915 132.8983 +0 0 0 1.817 132.8984 +0 1 0 1.801 132.8985 +0 0 0 1.733 132.8986 +0 1 0 1.701 132.8987 +0 0 0 1.645 132.8988 +0 1 0 1.629 132.8989 +0 0 0 1.559 132.8990 +0 1 0 1.543 132.8991 +0 0 0 1.481 132.8992 +0 1 0 1.463 132.8993 +0 0 0 1.303 132.8994 +0 1 0 1.287 132.8995 +0 0 0 1.229 132.8996 +0 1 0 1.213 132.8997 +0 0 0 1.089 132.8998 +0 1 0 1.075 132.8999 +0 0 0 1.075 132.9000 +0 0 1 1.075 132.9001 +0 1 1 1.089 132.9002 +0 0 1 1.213 132.9003 +0 1 1 1.229 132.9004 +0 0 1 1.287 132.9005 +0 1 1 1.303 132.9006 +0 0 1 1.463 132.9007 +0 1 1 1.479 132.9008 +0 0 1 1.543 132.9009 +0 1 1 1.559 132.9010 +0 0 1 1.629 132.9011 +0 1 1 1.645 132.9012 +0 0 1 1.701 132.9013 +0 1 1 1.731 132.9014 +0 0 1 1.799 132.9015 +0 1 1 1.817 132.9016 +0 0 1 1.915 132.9017 +0 1 1 1.931 132.9018 +0 0 1 1.989 132.9019 +0 1 1 2.003 132.9020 +0 0 1 2.069 132.9021 +0 1 1 2.085 132.9022 +0 0 1 2.145 132.9023 +0 1 1 2.159 132.9024 +0 0 1 2.295 132.9025 +0 1 1 2.311 132.9026 +0 0 1 2.369 132.9027 +0 1 1 2.385 132.9028 +0 0 1 2.471 132.9029 +0 1 1 2.489 132.9030 +0 0 1 2.569 132.9031 +0 1 1 2.589 132.9032 +0 0 1 2.633 132.9033 +0 1 1 2.653 132.9034 +0 0 1 2.735 132.9035 +0 1 1 2.753 132.9036 +0 0 1 2.911 132.9037 +0 1 1 2.925 132.9038 +0 0 1 2.925 132.9039 +0 0 0 2.925 132.9040 +0 1 0 2.911 132.9041 +0 0 0 2.753 132.9042 +0 1 0 2.735 132.9043 +0 0 0 2.655 132.9044 +0 1 0 2.635 132.9045 +0 0 0 2.587 132.9046 +0 1 0 2.567 132.9047 +0 0 0 2.487 132.9048 +0 1 0 2.469 132.9049 +0 0 0 2.385 132.9050 +0 1 0 2.369 132.9051 +0 0 0 2.311 132.9052 +0 1 0 2.295 132.9053 +0 0 0 2.159 132.9054 +0 1 0 2.145 132.9055 +0 0 0 2.085 132.9056 +0 1 0 2.069 132.9057 +0 0 0 2.003 132.9058 +0 1 0 1.989 132.9059 +0 0 0 1.931 132.9060 +0 1 0 1.915 132.9061 +0 0 0 1.815 132.9062 +0 1 0 1.799 132.9063 +0 0 0 1.731 132.9064 +0 1 0 1.701 132.9065 +0 0 0 1.645 132.9066 +0 1 0 1.629 132.9067 +0 0 0 1.559 132.9068 +0 1 0 1.543 132.9069 +0 0 0 1.479 132.9070 +0 1 0 1.461 132.9071 +0 0 0 1.303 132.9072 +0 1 0 1.287 132.9073 +0 0 0 1.229 132.9074 +0 1 0 1.213 132.9075 +0 0 0 1.089 132.9076 +0 1 0 1.075 132.9077 +0 0 0 1.075 132.9078 +0 0 1 1.075 132.9079 +0 1 1 1.089 132.9080 +0 0 1 1.213 132.9081 +0 1 1 1.229 132.9082 +0 0 1 1.287 132.9083 +0 1 1 1.303 132.9084 +0 0 1 1.461 132.9085 +0 1 1 1.479 132.9086 +0 0 1 1.541 132.9087 +0 1 1 1.557 132.9088 +0 0 1 1.629 132.9089 +0 1 1 1.645 132.9090 +0 0 1 1.701 132.9091 +0 1 1 1.729 132.9092 +0 0 1 1.797 132.9093 +0 1 1 1.815 132.9094 +0 0 1 1.915 132.9095 +0 1 1 1.931 132.9096 +0 0 1 1.989 132.9097 +0 1 1 2.003 132.9098 +0 0 1 2.069 132.9099 +0 1 1 2.085 132.9100 +0 0 1 2.145 132.9101 +0 1 1 2.161 132.9102 +0 0 1 2.295 132.9103 +0 1 1 2.311 132.9104 +0 0 1 2.369 132.9105 +0 1 1 2.385 132.9106 +0 0 1 2.467 132.9107 +0 1 1 2.485 132.9108 +0 0 1 2.565 132.9109 +0 1 1 2.585 132.9110 +0 0 1 2.637 132.9111 +0 1 1 2.657 132.9112 +0 0 1 2.737 132.9113 +0 1 1 2.755 132.9114 +0 0 1 2.911 132.9115 +0 1 1 2.925 132.9116 +0 0 1 2.925 132.9117 +0 0 0 2.925 132.9118 +0 1 0 2.911 132.9119 +0 0 0 2.757 132.9120 +0 1 0 2.739 132.9121 +0 0 0 2.659 132.9122 +0 1 0 2.639 132.9123 +0 0 0 2.583 132.9124 +0 1 0 2.563 132.9125 +0 0 0 2.485 132.9126 +0 1 0 2.467 132.9127 +0 0 0 2.385 132.9128 +0 1 0 2.369 132.9129 +0 0 0 2.311 132.9130 +0 1 0 2.295 132.9131 +0 0 0 2.161 132.9132 +0 1 0 2.145 132.9133 +0 0 0 2.085 132.9134 +0 1 0 2.069 132.9135 +0 0 0 2.003 132.9136 +0 1 0 1.989 132.9137 +0 0 0 1.931 132.9138 +0 1 0 1.915 132.9139 +0 0 0 1.813 132.9140 +0 1 0 1.797 132.9141 +0 0 0 1.729 132.9142 +0 1 0 1.701 132.9143 +0 0 0 1.645 132.9144 +0 1 0 1.629 132.9145 +0 0 0 1.557 132.9146 +0 1 0 1.541 132.9147 +0 0 0 1.477 132.9148 +0 1 0 1.459 132.9149 +0 0 0 1.303 132.9150 +0 1 0 1.287 132.9151 +0 0 0 1.229 132.9152 +0 1 0 1.213 132.9153 +0 0 0 1.089 132.9154 +0 1 0 1.075 132.9155 +0 0 0 1.075 132.9156 +0 0 1 1.075 132.9157 +0 1 1 1.089 132.9158 +0 0 1 1.213 132.9159 +0 1 1 1.229 132.9160 +0 0 1 1.287 132.9161 +0 1 1 1.303 132.9162 +0 0 1 1.457 132.9163 +0 1 1 1.477 132.9164 +0 0 1 1.541 132.9165 +0 1 1 1.557 132.9166 +0 0 1 1.629 132.9167 +0 1 1 1.645 132.9168 +0 0 1 1.701 132.9169 +0 1 1 1.727 132.9170 +0 0 1 1.795 132.9171 +0 1 1 1.813 132.9172 +0 0 1 1.915 132.9173 +0 1 1 1.931 132.9174 +0 0 1 1.989 132.9175 +0 1 1 2.003 132.9176 +0 0 1 2.069 132.9177 +0 1 1 2.085 132.9178 +0 0 1 2.145 132.9179 +0 1 1 2.163 132.9180 +0 0 1 2.293 132.9181 +0 1 1 2.309 132.9182 +0 0 1 2.369 132.9183 +0 1 1 2.385 132.9184 +0 0 1 2.465 132.9185 +0 1 1 2.483 132.9186 +0 0 1 2.561 132.9187 +0 1 1 2.581 132.9188 +0 0 1 2.641 132.9189 +0 1 1 2.661 132.9190 +0 0 1 2.739 132.9191 +0 1 1 2.757 132.9192 +0 0 1 2.911 132.9193 +0 1 1 2.925 132.9194 +0 0 1 2.925 132.9195 +0 0 0 2.925 132.9196 +0 1 0 2.911 132.9197 +0 0 0 2.759 132.9198 +0 1 0 2.741 132.9199 +0 0 0 2.663 132.9200 +0 1 0 2.643 132.9201 +0 0 0 2.581 132.9202 +0 1 0 2.561 132.9203 +0 0 0 2.481 132.9204 +0 1 0 2.463 132.9205 +0 0 0 2.385 132.9206 +0 1 0 2.369 132.9207 +0 0 0 2.309 132.9208 +0 1 0 2.293 132.9209 +0 0 0 2.163 132.9210 +0 1 0 2.147 132.9211 +0 0 0 2.085 132.9212 +0 1 0 2.069 132.9213 +0 0 0 2.003 132.9214 +0 1 0 1.989 132.9215 +0 0 0 1.931 132.9216 +0 1 0 1.915 132.9217 +0 0 0 1.811 132.9218 +0 1 0 1.795 132.9219 +0 0 0 1.727 132.9220 +0 1 0 1.701 132.9221 +0 0 0 1.645 132.9222 +0 1 0 1.629 132.9223 +0 0 0 1.555 132.9224 +0 1 0 1.541 132.9225 +0 0 0 1.475 132.9226 +0 1 0 1.455 132.9227 +0 0 0 1.303 132.9228 +0 1 0 1.287 132.9229 +0 0 0 1.229 132.9230 +0 1 0 1.213 132.9231 +0 0 0 1.089 132.9232 +0 1 0 1.075 132.9233 +0 0 0 1.075 132.9234 +0 0 1 1.075 132.9235 +0 1 1 1.089 132.9236 +0 0 1 1.213 132.9237 +0 1 1 1.229 132.9238 +0 0 1 1.287 132.9239 +0 1 1 1.303 132.9240 +0 0 1 1.451 132.9241 +0 1 1 1.473 132.9242 +0 0 1 1.539 132.9243 +0 1 1 1.555 132.9244 +0 0 1 1.629 132.9245 +0 1 1 1.645 132.9246 +0 0 1 1.701 132.9247 +0 1 1 1.725 132.9248 +0 0 1 1.793 132.9249 +0 1 1 1.811 132.9250 +0 0 1 1.915 132.9251 +0 1 1 1.931 132.9252 +0 0 1 1.989 132.9253 +0 1 1 2.003 132.9254 +0 0 1 2.071 132.9255 +0 1 1 2.085 132.9256 +0 0 1 2.147 132.9257 +0 1 1 2.163 132.9258 +0 0 1 2.293 132.9259 +0 1 1 2.309 132.9260 +0 0 1 2.369 132.9261 +0 1 1 2.385 132.9262 +0 0 1 2.463 132.9263 +0 1 1 2.479 132.9264 +0 0 1 2.559 132.9265 +0 1 1 2.579 132.9266 +0 0 1 2.645 132.9267 +0 1 1 2.665 132.9268 +0 0 1 2.743 132.9269 +0 1 1 2.761 132.9270 +0 0 1 2.911 132.9271 +0 1 1 2.925 132.9272 +0 0 1 2.925 132.9273 +0 0 0 2.925 132.9274 +0 1 0 2.911 132.9275 +0 0 0 2.761 132.9276 +0 1 0 2.743 132.9277 +0 0 0 2.667 132.9278 +0 1 0 2.645 132.9279 +0 0 0 2.577 132.9280 +0 1 0 2.557 132.9281 +0 0 0 2.479 132.9282 +0 1 0 2.461 132.9283 +0 0 0 2.385 132.9284 +0 1 0 2.369 132.9285 +0 0 0 2.307 132.9286 +0 1 0 2.291 132.9287 +0 0 0 2.165 132.9288 +0 1 0 2.147 132.9289 +0 0 0 2.085 132.9290 +0 1 0 2.071 132.9291 +0 0 0 2.003 132.9292 +0 1 0 1.989 132.9293 +0 0 0 1.931 132.9294 +0 1 0 1.915 132.9295 +0 0 0 1.809 132.9296 +0 1 0 1.791 132.9297 +0 0 0 1.725 132.9298 +0 1 0 1.701 132.9299 +0 0 0 1.645 132.9300 +0 1 0 1.629 132.9301 +0 0 0 1.555 132.9302 +0 1 0 1.539 132.9303 +0 0 0 1.473 132.9304 +0 1 0 1.447 132.9305 +0 0 0 1.303 132.9306 +0 1 0 1.287 132.9307 +0 0 0 1.229 132.9308 +0 1 0 1.213 132.9309 +0 0 0 1.089 132.9310 +0 1 0 1.075 132.9311 +0 0 0 1.075 132.9312 +0 0 1 1.075 132.9313 +0 1 1 1.089 132.9314 +0 0 1 1.213 132.9315 +0 1 1 1.229 132.9316 +0 0 1 1.287 132.9317 +0 1 1 1.303 132.9318 +0 0 1 1.443 132.9319 +0 1 1 1.471 132.9320 +0 0 1 1.537 132.9321 +0 1 1 1.555 132.9322 +0 0 1 1.629 132.9323 +0 1 1 1.645 132.9324 +0 0 1 1.701 132.9325 +0 1 1 1.723 132.9326 +0 0 1 1.791 132.9327 +0 1 1 1.809 132.9328 +0 0 1 1.915 132.9329 +0 1 1 1.931 132.9330 +0 0 1 1.989 132.9331 +0 1 1 2.003 132.9332 +0 0 1 2.071 132.9333 +0 1 1 2.087 132.9334 +0 0 1 2.149 132.9335 +0 1 1 2.167 132.9336 +0 0 1 2.291 132.9337 +0 1 1 2.307 132.9338 +0 0 1 2.369 132.9339 +0 1 1 2.383 132.9340 +0 0 1 2.459 132.9341 +0 1 1 2.477 132.9342 +0 0 1 2.555 132.9343 +0 1 1 2.575 132.9344 +0 0 1 2.647 132.9345 +0 1 1 2.667 132.9346 +0 0 1 2.745 132.9347 +0 1 1 2.763 132.9348 +0 0 1 2.911 132.9349 +0 1 1 2.925 132.9350 +0 0 1 2.925 132.9351 +0 0 0 2.925 132.9352 +0 1 0 2.911 132.9353 +0 0 0 2.765 132.9354 +0 1 0 2.747 132.9355 +0 0 0 2.669 132.9356 +0 1 0 2.649 132.9357 +0 0 0 2.573 132.9358 +0 1 0 2.553 132.9359 +0 0 0 2.475 132.9360 +0 1 0 2.457 132.9361 +0 0 0 2.383 132.9362 +0 1 0 2.369 132.9363 +0 0 0 2.307 132.9364 +0 1 0 2.289 132.9365 +0 0 0 2.169 132.9366 +0 1 0 2.149 132.9367 +0 0 0 2.087 132.9368 +0 1 0 2.071 132.9369 +0 0 0 2.003 132.9370 +0 1 0 1.989 132.9371 +0 0 0 1.931 132.9372 +0 1 0 1.915 132.9373 +0 0 0 1.807 132.9374 +0 1 0 1.791 132.9375 +0 0 0 1.723 132.9376 +0 1 0 1.701 132.9377 +0 0 0 1.645 132.9378 +0 1 0 1.629 132.9379 +0 0 0 1.553 132.9380 +0 1 0 1.537 132.9381 +0 0 0 1.469 132.9382 +0 1 0 1.435 132.9383 +0 0 0 1.303 132.9384 +0 1 0 1.287 132.9385 +0 0 0 1.229 132.9386 +0 1 0 1.213 132.9387 +0 0 0 1.089 132.9388 +0 1 0 1.075 132.9389 +0 0 0 1.075 132.9390 +0 0 1 1.075 132.9391 +0 1 1 1.089 132.9392 +0 0 1 1.213 132.9393 +0 1 1 1.229 132.9394 +0 0 1 1.287 132.9395 +0 1 1 1.303 132.9396 +0 0 1 1.425 132.9397 +0 1 1 1.467 132.9398 +0 0 1 1.537 132.9399 +0 1 1 1.553 132.9400 +0 0 1 1.629 132.9401 +0 1 1 1.645 132.9402 +0 0 1 1.701 132.9403 +0 1 1 1.723 132.9404 +0 0 1 1.789 132.9405 +0 1 1 1.807 132.9406 +0 0 1 1.915 132.9407 +0 1 1 1.931 132.9408 +0 0 1 1.989 132.9409 +0 1 1 2.003 132.9410 +0 0 1 2.071 132.9411 +0 1 1 2.087 132.9412 +0 0 1 2.151 132.9413 +0 1 1 2.173 132.9414 +0 0 1 2.287 132.9415 +0 1 1 2.305 132.9416 +0 0 1 2.367 132.9417 +0 1 1 2.383 132.9418 +0 0 1 2.457 132.9419 +0 1 1 2.475 132.9420 +0 0 1 2.551 132.9421 +0 1 1 2.571 132.9422 +0 0 1 2.651 132.9423 +0 1 1 2.671 132.9424 +0 0 1 2.747 132.9425 +0 1 1 2.765 132.9426 +0 0 1 2.911 132.9427 +0 1 1 2.925 132.9428 +0 0 1 2.925 132.9429 +0 0 0 2.925 132.9430 +0 1 0 2.911 132.9431 +0 0 0 2.767 132.9432 +0 1 0 2.749 132.9433 +0 0 0 2.673 132.9434 +0 1 0 2.653 132.9435 +0 0 0 2.569 132.9436 +0 1 0 2.549 132.9437 +0 0 0 2.473 132.9438 +0 1 0 2.455 132.9439 +0 0 0 2.383 132.9440 +0 1 0 2.367 132.9441 +0 0 0 2.305 132.9442 +0 1 0 2.283 132.9443 +0 0 0 2.179 132.9444 +0 1 0 2.153 132.9445 +0 0 0 2.087 132.9446 +0 1 0 2.071 132.9447 +0 0 0 2.003 132.9448 +0 1 0 1.989 132.9449 +0 0 0 1.931 132.9450 +0 1 0 1.915 132.9451 +0 0 0 1.805 132.9452 +0 1 0 1.789 132.9453 +0 0 0 1.721 132.9454 +0 1 0 1.701 132.9455 +0 0 0 1.645 132.9456 +0 1 0 1.629 132.9457 +0 0 0 1.553 132.9458 +0 1 0 1.535 132.9459 +0 0 0 1.465 132.9460 +0 1 0 1.287 132.9461 +0 0 0 1.229 132.9462 +0 1 0 1.213 132.9463 +0 0 0 1.089 132.9464 +0 1 0 1.075 132.9465 +0 0 0 1.075 132.9466 +0 0 1 1.075 132.9467 +0 1 1 1.089 132.9468 +0 0 1 1.213 132.9469 +0 1 1 1.229 132.9470 +0 0 1 1.287 132.9471 +0 1 1 1.461 132.9472 +0 0 1 1.535 132.9473 +0 1 1 1.551 132.9474 +0 0 1 1.629 132.9475 +0 1 1 1.645 132.9476 +0 0 1 1.701 132.9477 +0 1 1 1.721 132.9478 +0 0 1 1.787 132.9479 +0 1 1 1.805 132.9480 +0 0 1 1.915 132.9481 +0 1 1 1.931 132.9482 +0 0 1 1.989 132.9483 +0 1 1 2.003 132.9484 +0 0 1 2.071 132.9485 +0 1 1 2.087 132.9486 +0 0 1 2.153 132.9487 +0 1 1 2.189 132.9488 +0 0 1 2.275 132.9489 +0 1 1 2.303 132.9490 +0 0 1 2.367 132.9491 +0 1 1 2.383 132.9492 +0 0 1 2.453 132.9493 +0 1 1 2.471 132.9494 +0 0 1 2.547 132.9495 +0 1 1 2.567 132.9496 +0 0 1 2.655 132.9497 +0 1 1 2.675 132.9498 +0 0 1 2.751 132.9499 +0 1 1 2.769 132.9500 +0 0 1 2.911 132.9501 +0 1 1 2.925 132.9502 +0 0 1 2.925 132.9503 +0 0 0 2.925 132.9504 +0 1 0 2.911 132.9505 +0 0 0 2.771 132.9506 +0 1 0 2.753 132.9507 +0 0 0 2.677 132.9508 +0 1 0 2.657 132.9509 +0 0 0 2.565 132.9510 +0 1 0 2.545 132.9511 +0 0 0 2.471 132.9512 +0 1 0 2.453 132.9513 +0 0 0 2.383 132.9514 +0 1 0 2.367 132.9515 +0 0 0 2.301 132.9516 +0 1 0 2.261 132.9517 +0 0 0 2.205 132.9518 +0 1 0 2.155 132.9519 +0 0 0 2.089 132.9520 +0 1 0 2.073 132.9521 +0 0 0 2.003 132.9522 +0 1 0 1.989 132.9523 +0 0 0 1.931 132.9524 +0 1 0 1.915 132.9525 +0 0 0 1.803 132.9526 +0 1 0 1.785 132.9527 +0 0 0 1.719 132.9528 +0 1 0 1.701 132.9529 +0 0 0 1.645 132.9530 +0 1 0 1.629 132.9531 +0 0 0 1.551 132.9532 +0 1 0 1.535 132.9533 +0 0 0 1.457 132.9534 +0 1 0 1.287 132.9535 +0 0 0 1.229 132.9536 +0 1 0 1.213 132.9537 +0 0 0 1.089 132.9538 +0 1 0 1.075 132.9539 +0 0 0 1.075 132.9540 +0 0 1 1.075 132.9541 +0 1 1 1.089 132.9542 +0 0 1 1.213 132.9543 +0 1 1 1.229 132.9544 +0 0 1 1.287 132.9545 +0 1 1 1.455 132.9546 +0 0 1 1.533 132.9547 +0 1 1 1.549 132.9548 +0 0 1 1.629 132.9549 +0 1 1 1.645 132.9550 +0 0 1 1.701 132.9551 +0 1 1 1.719 132.9552 +0 0 1 1.785 132.9553 +0 1 1 1.803 132.9554 +0 0 1 1.915 132.9555 +0 1 1 1.931 132.9556 +0 0 1 1.989 132.9557 +0 1 1 2.003 132.9558 +0 0 1 2.073 132.9559 +0 1 1 2.089 132.9560 +0 0 1 2.157 132.9561 +0 1 1 2.301 132.9562 +0 0 1 2.367 132.9563 +0 1 1 2.381 132.9564 +0 0 1 2.451 132.9565 +0 1 1 2.469 132.9566 +0 0 1 2.543 132.9567 +0 1 1 2.563 132.9568 +0 0 1 2.659 132.9569 +0 1 1 2.679 132.9570 +0 0 1 2.753 132.9571 +0 1 1 2.771 132.9572 +0 0 1 2.911 132.9573 +0 1 1 2.925 132.9574 +0 0 1 2.925 132.9575 +0 0 0 2.925 132.9576 +0 1 0 2.911 132.9577 +0 0 0 2.773 132.9578 +0 1 0 2.755 132.9579 +0 0 0 2.681 132.9580 +0 1 0 2.661 132.9581 +0 0 0 2.561 132.9582 +0 1 0 2.541 132.9583 +0 0 0 2.467 132.9584 +0 1 0 2.449 132.9585 +0 0 0 2.381 132.9586 +0 1 0 2.365 132.9587 +0 0 0 2.299 132.9588 +0 1 0 2.161 132.9589 +0 0 0 2.089 132.9590 +0 1 0 2.073 132.9591 +0 0 0 2.003 132.9592 +0 1 0 1.989 132.9593 +0 0 0 1.931 132.9594 +0 1 0 1.915 132.9595 +0 0 0 1.801 132.9596 +0 1 0 1.785 132.9597 +0 0 0 1.717 132.9598 +0 1 0 1.701 132.9599 +0 0 0 1.645 132.9600 +0 1 0 1.629 132.9601 +0 0 0 1.549 132.9602 +0 1 0 1.533 132.9603 +0 0 0 1.449 132.9604 +0 1 0 1.287 132.9605 +0 0 0 1.229 132.9606 +0 1 0 1.213 132.9607 +0 0 0 1.089 132.9608 +0 1 0 1.075 132.9609 +0 0 0 1.075 132.9610 +0 0 1 1.075 132.9611 +0 1 1 1.089 132.9612 +0 0 1 1.213 132.9613 +0 1 1 1.229 132.9614 +0 0 1 1.287 132.9615 +0 1 1 1.443 132.9616 +0 0 1 1.531 132.9617 +0 1 1 1.549 132.9618 +0 0 1 1.629 132.9619 +0 1 1 1.645 132.9620 +0 0 1 1.703 132.9621 +0 1 1 1.717 132.9622 +0 0 1 1.783 132.9623 +0 1 1 1.801 132.9624 +0 0 1 1.915 132.9625 +0 1 1 1.931 132.9626 +0 0 1 1.989 132.9627 +0 1 1 2.003 132.9628 +0 0 1 2.073 132.9629 +0 1 1 2.089 132.9630 +0 0 1 2.163 132.9631 +0 1 1 2.297 132.9632 +0 0 1 2.365 132.9633 +0 1 1 2.381 132.9634 +0 0 1 2.449 132.9635 +0 1 1 2.467 132.9636 +0 0 1 2.541 132.9637 +0 1 1 2.561 132.9638 +0 0 1 2.663 132.9639 +0 1 1 2.683 132.9640 +0 0 1 2.757 132.9641 +0 1 1 2.773 132.9642 +0 0 1 2.911 132.9643 +0 1 1 2.925 132.9644 +0 0 1 2.925 132.9645 +0 0 0 2.925 132.9646 +0 1 0 2.911 132.9647 +0 0 0 2.775 132.9648 +0 1 0 2.757 132.9649 +0 0 0 2.685 132.9650 +0 1 0 2.663 132.9651 +0 0 0 2.559 132.9652 +0 1 0 2.539 132.9653 +0 0 0 2.465 132.9654 +0 1 0 2.447 132.9655 +0 0 0 2.381 132.9656 +0 1 0 2.365 132.9657 +0 0 0 2.293 132.9658 +0 1 0 2.167 132.9659 +0 0 0 2.091 132.9660 +0 1 0 2.075 132.9661 +0 0 0 2.003 132.9662 +0 1 0 1.989 132.9663 +0 0 0 1.931 132.9664 +0 1 0 1.915 132.9665 +0 0 0 1.799 132.9666 +0 1 0 1.781 132.9667 +0 0 0 1.715 132.9668 +0 1 0 1.705 132.9669 +0 0 0 1.645 132.9670 +0 1 0 1.629 132.9671 +0 0 0 1.547 132.9672 +0 1 0 1.531 132.9673 +0 0 0 1.435 132.9674 +0 1 0 1.289 132.9675 +0 0 0 1.229 132.9676 +0 1 0 1.213 132.9677 +0 0 0 1.089 132.9678 +0 1 0 1.075 132.9679 +0 0 0 1.075 132.9680 +0 0 1 1.075 132.9681 +0 1 1 1.089 132.9682 +0 0 1 1.213 132.9683 +0 1 1 1.229 132.9684 +0 0 1 1.291 132.9685 +0 1 1 1.417 132.9686 +0 0 1 1.529 132.9687 +0 1 1 1.547 132.9688 +0 0 1 1.629 132.9689 +0 1 1 1.645 132.9690 +0 0 1 1.781 132.9691 +0 1 1 1.799 132.9692 +0 0 1 1.915 132.9693 +0 1 1 1.931 132.9694 +0 0 1 1.989 132.9695 +0 1 1 2.003 132.9696 +0 0 1 2.075 132.9697 +0 1 1 2.091 132.9698 +0 0 1 2.173 132.9699 +0 1 1 2.289 132.9700 +0 0 1 2.363 132.9701 +0 1 1 2.381 132.9702 +0 0 1 2.445 132.9703 +0 1 1 2.463 132.9704 +0 0 1 2.537 132.9705 +0 1 1 2.557 132.9706 +0 0 1 2.665 132.9707 +0 1 1 2.685 132.9708 +0 0 1 2.759 132.9709 +0 1 1 2.777 132.9710 +0 0 1 2.911 132.9711 +0 1 1 2.925 132.9712 +0 0 1 2.925 132.9713 +0 0 0 2.925 132.9714 +0 1 0 2.911 132.9715 +0 0 0 2.779 132.9716 +0 1 0 2.761 132.9717 +0 0 0 2.687 132.9718 +0 1 0 2.667 132.9719 +0 0 0 2.555 132.9720 +0 1 0 2.535 132.9721 +0 0 0 2.461 132.9722 +0 1 0 2.443 132.9723 +0 0 0 2.379 132.9724 +0 1 0 2.363 132.9725 +0 0 0 2.283 132.9726 +0 1 0 2.179 132.9727 +0 0 0 2.091 132.9728 +0 1 0 2.075 132.9729 +0 0 0 2.003 132.9730 +0 1 0 1.989 132.9731 +0 0 0 1.931 132.9732 +0 1 0 1.915 132.9733 +0 0 0 1.797 132.9734 +0 1 0 1.779 132.9735 +0 0 0 1.645 132.9736 +0 1 0 1.629 132.9737 +0 0 0 1.545 132.9738 +0 1 0 1.529 132.9739 +0 0 0 1.229 132.9740 +0 1 0 1.213 132.9741 +0 0 0 1.089 132.9742 +0 1 0 1.075 132.9743 +0 0 0 1.075 132.9744 +0 0 1 1.075 132.9745 +0 1 1 1.089 132.9746 +0 0 1 1.213 132.9747 +0 1 1 1.229 132.9748 +0 0 1 1.527 132.9749 +0 1 1 1.545 132.9750 +0 0 1 1.629 132.9751 +0 1 1 1.645 132.9752 +0 0 1 1.779 132.9753 +0 1 1 1.797 132.9754 +0 0 1 1.915 132.9755 +0 1 1 1.931 132.9756 +0 0 1 1.989 132.9757 +0 1 1 2.003 132.9758 +0 0 1 2.077 132.9759 +0 1 1 2.093 132.9760 +0 0 1 2.189 132.9761 +0 1 1 2.275 132.9762 +0 0 1 2.363 132.9763 +0 1 1 2.379 132.9764 +0 0 1 2.443 132.9765 +0 1 1 2.461 132.9766 +0 0 1 2.533 132.9767 +0 1 1 2.553 132.9768 +0 0 1 2.669 132.9769 +0 1 1 2.689 132.9770 +0 0 1 2.761 132.9771 +0 1 1 2.779 132.9772 +0 0 1 2.911 132.9773 +0 1 1 2.925 132.9774 +0 0 1 2.925 132.9775 +0 0 0 2.925 132.9776 +0 1 0 2.911 132.9777 +0 0 0 2.781 132.9778 +0 1 0 2.763 132.9779 +0 0 0 2.691 132.9780 +0 1 0 2.671 132.9781 +0 0 0 2.551 132.9782 +0 1 0 2.531 132.9783 +0 0 0 2.459 132.9784 +0 1 0 2.441 132.9785 +0 0 0 2.379 132.9786 +0 1 0 2.361 132.9787 +0 0 0 2.253 132.9788 +0 1 0 2.213 132.9789 +0 0 0 2.093 132.9790 +0 1 0 2.077 132.9791 +0 0 0 2.003 132.9792 +0 1 0 1.989 132.9793 +0 0 0 1.931 132.9794 +0 1 0 1.915 132.9795 +0 0 0 1.795 132.9796 +0 1 0 1.777 132.9797 +0 0 0 1.645 132.9798 +0 1 0 1.629 132.9799 +0 0 0 1.543 132.9800 +0 1 0 1.525 132.9801 +0 0 0 1.229 132.9802 +0 1 0 1.213 132.9803 +0 0 0 1.089 132.9804 +0 1 0 1.075 132.9805 +0 0 0 1.075 132.9806 +0 0 1 1.075 132.9807 +0 1 1 1.089 132.9808 +0 0 1 1.213 132.9809 +0 1 1 1.229 132.9810 +0 0 1 1.523 132.9811 +0 1 1 1.543 132.9812 +0 0 1 1.629 132.9813 +0 1 1 1.645 132.9814 +0 0 1 1.777 132.9815 +0 1 1 1.795 132.9816 +0 0 1 1.915 132.9817 +0 1 1 1.931 132.9818 +0 0 1 1.989 132.9819 +0 1 1 2.003 132.9820 +0 0 1 2.077 132.9821 +0 1 1 2.095 132.9822 +0 0 1 2.361 132.9823 +0 1 1 2.377 132.9824 +0 0 1 2.439 132.9825 +0 1 1 2.457 132.9826 +0 0 1 2.529 132.9827 +0 1 1 2.549 132.9828 +0 0 1 2.673 132.9829 +0 1 1 2.693 132.9830 +0 0 1 2.765 132.9831 +0 1 1 2.783 132.9832 +0 0 1 2.911 132.9833 +0 1 1 2.925 132.9834 +0 0 1 2.925 132.9835 +0 0 0 2.925 132.9836 +0 1 0 2.911 132.9837 +0 0 0 2.783 132.9838 +0 1 0 2.767 132.9839 +0 0 0 2.695 132.9840 +0 1 0 2.675 132.9841 +0 0 0 2.547 132.9842 +0 1 0 2.527 132.9843 +0 0 0 2.457 132.9844 +0 1 0 2.439 132.9845 +0 0 0 2.377 132.9846 +0 1 0 2.361 132.9847 +0 0 0 2.095 132.9848 +0 1 0 2.079 132.9849 +0 0 0 2.003 132.9850 +0 1 0 1.989 132.9851 +0 0 0 1.931 132.9852 +0 1 0 1.915 132.9853 +0 0 0 1.793 132.9854 +0 1 0 1.775 132.9855 +0 0 0 1.645 132.9856 +0 1 0 1.629 132.9857 +0 0 0 1.541 132.9858 +0 1 0 1.523 132.9859 +0 0 0 1.229 132.9860 +0 1 0 1.213 132.9861 +0 0 0 1.089 132.9862 +0 1 0 1.075 132.9863 +0 0 0 1.075 132.9864 +0 0 1 1.075 132.9865 +0 1 1 1.089 132.9866 +0 0 1 1.213 132.9867 +0 1 1 1.229 132.9868 +0 0 1 1.521 132.9869 +0 1 1 1.539 132.9870 +0 0 1 1.629 132.9871 +0 1 1 1.645 132.9872 +0 0 1 1.775 132.9873 +0 1 1 1.791 132.9874 +0 0 1 1.915 132.9875 +0 1 1 1.931 132.9876 +0 0 1 1.989 132.9877 +0 1 1 2.003 132.9878 +0 0 1 2.079 132.9879 +0 1 1 2.097 132.9880 +0 0 1 2.359 132.9881 +0 1 1 2.375 132.9882 +0 0 1 2.437 132.9883 +0 1 1 2.455 132.9884 +0 0 1 2.525 132.9885 +0 1 1 2.545 132.9886 +0 0 1 2.677 132.9887 +0 1 1 2.697 132.9888 +0 0 1 2.767 132.9889 +0 1 1 2.785 132.9890 +0 0 1 2.911 132.9891 +0 1 1 2.925 132.9892 +0 0 1 2.925 132.9893 +0 0 0 2.925 132.9894 +0 1 0 2.911 132.9895 +0 0 0 2.787 132.9896 +0 1 0 2.769 132.9897 +0 0 0 2.699 132.9898 +0 1 0 2.679 132.9899 +0 0 0 2.543 132.9900 +0 1 0 2.523 132.9901 +0 0 0 2.453 132.9902 +0 1 0 2.435 132.9903 +0 0 0 2.375 132.9904 +0 1 0 2.357 132.9905 +0 0 0 2.097 132.9906 +0 1 0 2.081 132.9907 +0 0 0 2.003 132.9908 +0 1 0 1.989 132.9909 +0 0 0 1.931 132.9910 +0 1 0 1.915 132.9911 +0 0 0 1.791 132.9912 +0 1 0 1.773 132.9913 +0 0 0 1.645 132.9914 +0 1 0 1.629 132.9915 +0 0 0 1.539 132.9916 +0 1 0 1.519 132.9917 +0 0 0 1.229 132.9918 +0 1 0 1.213 132.9919 +0 0 0 1.089 132.9920 +0 1 0 1.075 132.9921 +0 0 0 1.075 132.9922 +0 0 1 1.075 132.9923 +0 1 1 1.089 132.9924 +0 0 1 1.213 132.9925 +0 1 1 1.229 132.9926 +0 0 1 1.517 132.9927 +0 1 1 1.537 132.9928 +0 0 1 1.629 132.9929 +0 1 1 1.645 132.9930 +0 0 1 1.773 132.9931 +0 1 1 1.791 132.9932 +0 0 1 1.915 132.9933 +0 1 1 1.931 132.9934 +0 0 1 1.989 132.9935 +0 1 1 2.003 132.9936 +0 0 1 2.081 132.9937 +0 1 1 2.099 132.9938 +0 0 1 2.357 132.9939 +0 1 1 2.375 132.9940 +0 0 1 2.435 132.9941 +0 1 1 2.453 132.9942 +0 0 1 2.523 132.9943 +0 1 1 2.543 132.9944 +0 0 1 2.681 132.9945 +0 1 1 2.701 132.9946 +0 0 1 2.771 132.9947 +0 1 1 2.787 132.9948 +0 0 1 2.911 132.9949 +0 1 1 2.925 132.9950 +0 0 1 2.925 132.9951 +0 0 0 2.925 132.9952 +0 1 0 2.911 132.9953 +0 0 0 2.789 132.9954 +0 1 0 2.771 132.9955 +0 0 0 2.703 132.9956 +0 1 0 2.681 132.9957 +0 0 0 2.541 132.9958 +0 1 0 2.521 132.9959 +0 0 0 2.451 132.9960 +0 1 0 2.433 132.9961 +0 0 0 2.373 132.9962 +0 1 0 2.355 132.9963 +0 0 0 2.101 132.9964 +0 1 0 2.083 132.9965 +0 0 0 2.003 132.9966 +0 1 0 1.989 132.9967 +0 0 0 1.931 132.9968 +0 1 0 1.915 132.9969 +0 0 0 1.789 132.9970 +0 1 0 1.771 132.9971 +0 0 0 1.645 132.9972 +0 1 0 1.629 132.9973 +0 0 0 1.535 132.9974 +0 1 0 1.515 132.9975 +0 0 0 1.229 132.9976 +0 1 0 1.213 132.9977 +0 0 0 1.089 132.9978 +0 1 0 1.075 132.9979 +0 0 0 1.075 132.9980 +0 0 1 1.075 132.9981 +0 1 1 1.089 132.9982 +0 0 1 1.213 132.9983 +0 1 1 1.229 132.9984 +0 0 1 1.513 132.9985 +0 1 1 1.535 132.9986 +0 0 1 1.629 132.9987 +0 1 1 1.645 132.9988 +0 0 1 1.771 132.9989 +0 1 1 1.787 132.9990 +0 0 1 1.915 132.9991 +0 1 1 1.931 132.9992 +0 0 1 1.989 132.9993 +0 1 1 2.003 132.9994 +0 0 1 2.083 132.9995 +0 1 1 2.101 132.9996 +0 0 1 2.355 132.9997 +0 1 1 2.373 132.9998 +0 0 1 2.431 132.9999 +0 1 1 2.449 132.10000 +0 0 1 2.519 132.10001 +0 1 1 2.539 132.10002 +0 0 1 2.683 132.10003 +0 1 1 2.703 132.10004 +0 0 1 2.773 132.10005 +0 1 1 2.791 132.10006 +0 0 1 2.911 132.10007 +0 1 1 2.925 132.10008 +0 0 1 2.925 132.10009 +0 0 0 2.925 132.10010 +0 1 0 2.911 132.10011 +0 0 0 2.791 132.10012 +0 1 0 2.775 132.10013 +0 0 0 2.705 132.10014 +0 1 0 2.685 132.10015 +0 0 0 2.537 132.10016 +0 1 0 2.517 132.10017 +0 0 0 2.449 132.10018 +0 1 0 2.431 132.10019 +0 0 0 2.371 132.10020 +0 1 0 2.353 132.10021 +0 0 0 2.103 132.10022 +0 1 0 2.085 132.10023 +0 0 0 2.003 132.10024 +0 1 0 1.989 132.10025 +0 0 0 1.931 132.10026 +0 1 0 1.915 132.10027 +0 0 0 1.787 132.10028 +0 1 0 1.769 132.10029 +0 0 0 1.645 132.10030 +0 1 0 1.629 132.10031 +0 0 0 1.533 132.10032 +0 1 0 1.511 132.10033 +0 0 0 1.229 132.10034 +0 1 0 1.213 132.10035 +0 0 0 1.089 132.10036 +0 1 0 1.075 132.10037 +0 0 0 1.075 132.10038 +0 0 1 1.075 132.10039 +0 1 1 1.089 132.10040 +0 0 1 1.213 132.10041 +0 1 1 1.229 132.10042 +0 0 1 1.507 132.10043 +0 1 1 1.531 132.10044 +0 0 1 1.629 132.10045 +0 1 1 1.645 132.10046 +0 0 1 1.769 132.10047 +0 1 1 1.785 132.10048 +0 0 1 1.915 132.10049 +0 1 1 1.931 132.10050 +0 0 1 1.989 132.10051 +0 1 1 2.003 132.10052 +0 0 1 2.085 132.10053 +0 1 1 2.105 132.10054 +0 0 1 2.351 132.10055 +0 1 1 2.369 132.10056 +0 0 1 2.429 132.10057 +0 1 1 2.447 132.10058 +0 0 1 2.515 132.10059 +0 1 1 2.535 132.10060 +0 0 1 2.687 132.10061 +0 1 1 2.707 132.10062 +0 0 1 2.775 132.10063 +0 1 1 2.793 132.10064 +0 0 1 2.911 132.10065 +0 1 1 2.925 132.10066 +0 0 1 2.925 132.10067 +0 0 0 2.925 132.10068 +0 1 0 2.911 132.10069 +0 0 0 2.795 132.10070 +0 1 0 2.777 132.10071 +0 0 0 2.709 132.10072 +0 1 0 2.689 132.10073 +0 0 0 2.533 132.10074 +0 1 0 2.513 132.10075 +0 0 0 2.445 132.10076 +0 1 0 2.427 132.10077 +0 0 0 2.369 132.10078 +0 1 0 2.349 132.10079 +0 0 0 2.107 132.10080 +0 1 0 2.087 132.10081 +0 0 0 2.003 132.10082 +0 1 0 1.989 132.10083 +0 0 0 1.931 132.10084 +0 1 0 1.915 132.10085 +0 0 0 1.785 132.10086 +0 1 0 1.767 132.10087 +0 0 0 1.645 132.10088 +0 1 0 1.629 132.10089 +0 0 0 1.529 132.10090 +0 1 0 1.505 132.10091 +0 0 0 1.229 132.10092 +0 1 0 1.213 132.10093 +0 0 0 1.089 132.10094 +0 1 0 1.075 132.10095 +0 0 0 1.075 132.10096 +0 0 1 1.075 132.10097 +0 1 1 1.089 132.10098 +0 0 1 1.213 132.10099 +0 1 1 1.229 132.10100 +0 0 1 1.501 132.10101 +0 1 1 1.527 132.10102 +0 0 1 1.629 132.10103 +0 1 1 1.645 132.10104 +0 0 1 1.767 132.10105 +0 1 1 1.783 132.10106 +0 0 1 1.915 132.10107 +0 1 1 1.931 132.10108 +0 0 1 1.989 132.10109 +0 1 1 2.003 132.10110 +0 0 1 2.089 132.10111 +0 1 1 2.109 132.10112 +0 0 1 2.347 132.10113 +0 1 1 2.367 132.10114 +0 0 1 2.425 132.10115 +0 1 1 2.443 132.10116 +0 0 1 2.511 132.10117 +0 1 1 2.531 132.10118 +0 0 1 2.691 132.10119 +0 1 1 2.711 132.10120 +0 0 1 2.779 132.10121 +0 1 1 2.797 132.10122 +0 0 1 2.911 132.10123 +0 1 1 2.925 132.10124 +0 0 1 2.925 132.10125 +0 0 0 2.925 132.10126 +0 1 0 2.911 132.10127 +0 0 0 2.797 132.10128 +0 1 0 2.779 132.10129 +0 0 0 2.713 132.10130 +0 1 0 2.693 132.10131 +0 0 0 2.529 132.10132 +0 1 0 2.509 132.10133 +0 0 0 2.443 132.10134 +0 1 0 2.425 132.10135 +0 0 0 2.365 132.10136 +0 1 0 2.343 132.10137 +0 0 0 2.113 132.10138 +0 1 0 2.091 132.10139 +0 0 0 2.003 132.10140 +0 1 0 1.989 132.10141 +0 0 0 1.931 132.10142 +0 1 0 1.915 132.10143 +0 0 0 1.783 132.10144 +0 1 0 1.765 132.10145 +0 0 0 1.645 132.10146 +0 1 0 1.629 132.10147 +0 0 0 1.525 132.10148 +0 1 0 1.499 132.10149 +0 0 0 1.229 132.10150 +0 1 0 1.213 132.10151 +0 0 0 1.089 132.10152 +0 1 0 1.075 132.10153 +0 0 0 1.075 132.10154 +0 0 1 1.075 132.10155 +0 1 1 1.089 132.10156 +0 0 1 1.213 132.10157 +0 1 1 1.229 132.10158 +0 0 1 1.493 132.10159 +0 1 1 1.523 132.10160 +0 0 1 1.629 132.10161 +0 1 1 1.645 132.10162 +0 0 1 1.765 132.10163 +0 1 1 1.781 132.10164 +0 0 1 1.915 132.10165 +0 1 1 1.931 132.10166 +0 0 1 1.989 132.10167 +0 1 1 2.003 132.10168 +0 0 1 2.091 132.10169 +0 1 1 2.115 132.10170 +0 0 1 2.341 132.10171 +0 1 1 2.365 132.10172 +0 0 1 2.423 132.10173 +0 1 1 2.441 132.10174 +0 0 1 2.507 132.10175 +0 1 1 2.527 132.10176 +0 0 1 2.695 132.10177 +0 1 1 2.715 132.10178 +0 0 1 2.781 132.10179 +0 1 1 2.799 132.10180 +0 0 1 2.911 132.10181 +0 1 1 2.925 132.10182 +0 0 1 2.925 132.10183 +0 0 0 2.925 132.10184 +0 1 0 2.911 132.10185 +0 0 0 2.801 132.10186 +0 1 0 2.783 132.10187 +0 0 0 2.717 132.10188 +0 1 0 2.697 132.10189 +0 0 0 2.525 132.10190 +0 1 0 2.505 132.10191 +0 0 0 2.439 132.10192 +0 1 0 2.423 132.10193 +0 0 0 2.363 132.10194 +0 1 0 2.337 132.10195 +0 0 0 2.119 132.10196 +0 1 0 2.093 132.10197 +0 0 0 2.003 132.10198 +0 1 0 1.989 132.10199 +0 0 0 1.931 132.10200 +0 1 0 1.915 132.10201 +0 0 0 1.781 132.10202 +0 1 0 1.763 132.10203 +0 0 0 1.645 132.10204 +0 1 0 1.629 132.10205 +0 0 0 1.519 132.10206 +0 1 0 1.489 132.10207 +0 0 0 1.229 132.10208 +0 1 0 1.213 132.10209 +0 0 0 1.089 132.10210 +0 1 0 1.075 132.10211 +0 0 0 1.075 132.10212 +0 0 1 1.075 132.10213 +0 1 1 1.089 132.10214 +0 0 1 1.213 132.10215 +0 1 1 1.229 132.10216 +0 0 1 1.485 132.10217 +0 1 1 1.517 132.10218 +0 0 1 1.629 132.10219 +0 1 1 1.645 132.10220 +0 0 1 1.763 132.10221 +0 1 1 1.779 132.10222 +0 0 1 1.915 132.10223 +0 1 1 1.931 132.10224 +0 0 1 1.989 132.10225 +0 1 1 2.003 132.10226 +0 0 1 2.095 132.10227 +0 1 1 2.123 132.10228 +0 0 1 2.333 132.10229 +0 1 1 2.361 132.10230 +0 0 1 2.421 132.10231 +0 1 1 2.439 132.10232 +0 0 1 2.503 132.10233 +0 1 1 2.523 132.10234 +0 0 1 2.699 132.10235 +0 1 1 2.719 132.10236 +0 0 1 2.783 132.10237 +0 1 1 2.801 132.10238 +0 0 1 2.911 132.10239 +0 1 1 2.925 132.10240 +0 0 1 2.925 132.10241 +0 0 0 2.925 132.10242 +0 1 0 2.911 132.10243 +0 0 0 2.803 132.10244 +0 1 0 2.783 132.10245 +0 0 0 2.721 132.10246 +0 1 0 2.701 132.10247 +0 0 0 2.523 132.10248 +0 1 0 2.501 132.10249 +0 0 0 2.439 132.10250 +0 1 0 2.419 132.10251 +0 0 0 2.359 132.10252 +0 1 0 2.329 132.10253 +0 0 0 2.129 132.10254 +0 1 0 2.097 132.10255 +0 0 0 2.003 132.10256 +0 1 0 1.989 132.10257 +0 0 0 1.931 132.10258 +0 1 0 1.915 132.10259 +0 0 0 1.779 132.10260 +0 1 0 1.761 132.10261 +0 0 0 1.645 132.10262 +0 1 0 1.629 132.10263 +0 0 0 1.515 132.10264 +0 1 0 1.479 132.10265 +0 0 0 1.229 132.10266 +0 1 0 1.213 132.10267 +0 0 0 1.089 132.10268 +0 1 0 1.075 132.10269 +0 0 0 1.075 132.10270 +0 0 1 1.075 132.10271 +0 1 1 1.089 132.10272 +0 0 1 1.213 132.10273 +0 1 1 1.229 132.10274 +0 0 1 1.471 132.10275 +0 1 1 1.511 132.10276 +0 0 1 1.629 132.10277 +0 1 1 1.645 132.10278 +0 0 1 1.761 132.10279 +0 1 1 1.777 132.10280 +0 0 1 1.915 132.10281 +0 1 1 1.931 132.10282 +0 0 1 1.989 132.10283 +0 1 1 2.003 132.10284 +0 0 1 2.101 132.10285 +0 1 1 2.135 132.10286 +0 0 1 2.323 132.10287 +0 1 1 2.357 132.10288 +0 0 1 2.417 132.10289 +0 1 1 2.521 132.10290 +0 0 1 2.703 132.10291 +0 1 1 2.805 132.10292 +0 0 1 2.911 132.10293 +0 1 1 2.925 132.10294 +0 0 1 2.925 132.10295 +0 0 0 2.925 132.10296 +0 1 0 2.911 132.10297 +0 0 0 2.805 132.10298 +0 1 0 2.703 132.10299 +0 0 0 2.519 132.10300 +0 1 0 2.417 132.10301 +0 0 0 2.353 132.10302 +0 1 0 2.317 132.10303 +0 0 0 2.141 132.10304 +0 1 0 2.103 132.10305 +0 0 0 2.003 132.10306 +0 1 0 1.989 132.10307 +0 0 0 1.931 132.10308 +0 1 0 1.915 132.10309 +0 0 0 1.777 132.10310 +0 1 0 1.759 132.10311 +0 0 0 1.645 132.10312 +0 1 0 1.629 132.10313 +0 0 0 1.509 132.10314 +0 1 0 1.465 132.10315 +0 0 0 1.229 132.10316 +0 1 0 1.213 132.10317 +0 0 0 1.089 132.10318 +0 1 0 1.075 132.10319 +0 0 0 1.075 132.10320 +0 0 1 1.075 132.10321 +0 1 1 1.089 132.10322 +0 0 1 1.213 132.10323 +0 1 1 1.229 132.10324 +0 0 1 1.451 132.10325 +0 1 1 1.505 132.10326 +0 0 1 1.629 132.10327 +0 1 1 1.645 132.10328 +0 0 1 1.759 132.10329 +0 1 1 1.775 132.10330 +0 0 1 1.915 132.10331 +0 1 1 1.931 132.10332 +0 0 1 1.989 132.10333 +0 1 1 2.003 132.10334 +0 0 1 2.105 132.10335 +0 1 1 2.151 132.10336 +0 0 1 2.307 132.10337 +0 1 1 2.351 132.10338 +0 0 1 2.415 132.10339 +0 1 1 2.517 132.10340 +0 0 1 2.705 132.10341 +0 1 1 2.807 132.10342 +0 0 1 2.911 132.10343 +0 1 1 2.925 132.10344 +0 0 1 2.925 132.10345 +0 0 0 2.925 132.10346 +0 1 0 2.911 132.10347 +0 0 0 2.807 132.10348 +0 1 0 2.707 132.10349 +0 0 0 2.515 132.10350 +0 1 0 2.415 132.10351 +0 0 0 2.347 132.10352 +0 1 0 2.295 132.10353 +0 0 0 2.163 132.10354 +0 1 0 2.109 132.10355 +0 0 0 2.003 132.10356 +0 1 0 1.989 132.10357 +0 0 0 1.931 132.10358 +0 1 0 1.915 132.10359 +0 0 0 1.775 132.10360 +0 1 0 1.757 132.10361 +0 0 0 1.645 132.10362 +0 1 0 1.629 132.10363 +0 0 0 1.501 132.10364 +0 1 0 1.433 132.10365 +0 0 0 1.229 132.10366 +0 1 0 1.213 132.10367 +0 0 0 1.089 132.10368 +0 1 0 1.075 132.10369 +0 0 0 1.075 132.10370 +0 0 1 1.075 132.10371 +0 1 1 1.089 132.10372 +0 0 1 1.213 132.10373 +0 1 1 1.497 132.10374 +0 0 1 1.629 132.10375 +0 1 1 1.773 132.10376 +0 0 1 1.915 132.10377 +0 1 1 2.003 132.10378 +0 0 1 2.113 132.10379 +0 1 1 2.177 132.10380 +0 0 1 2.281 132.10381 +0 1 1 2.345 132.10382 +0 0 1 2.415 132.10383 +0 1 1 2.513 132.10384 +0 0 1 2.709 132.10385 +0 1 1 2.809 132.10386 +0 0 1 2.911 132.10387 +0 1 1 2.925 132.10388 +0 0 1 2.925 132.10389 +0 0 0 2.925 132.10390 +0 1 0 2.911 132.10391 +0 0 0 2.807 132.10392 +0 1 0 2.711 132.10393 +0 0 0 2.511 132.10394 +0 1 0 2.415 132.10395 +0 0 0 2.339 132.10396 +0 1 0 2.237 132.10397 +0 0 0 2.223 132.10398 +0 1 0 2.117 132.10399 +0 0 0 2.003 132.10400 +0 1 0 1.915 132.10401 +0 0 0 1.773 132.10402 +0 1 0 1.629 132.10403 +0 0 0 1.491 132.10404 +0 1 0 1.213 132.10405 +0 0 0 1.089 132.10406 +0 1 0 1.075 132.10407 +0 0 0 1.075 132.10408 +0 0 1 1.075 132.10409 +0 1 1 1.089 132.10410 +0 0 1 1.213 132.10411 +0 1 1 1.485 132.10412 +0 0 1 1.629 132.10413 +0 1 1 1.771 132.10414 +0 0 1 1.915 132.10415 +0 1 1 2.003 132.10416 +0 0 1 2.123 132.10417 +0 1 1 2.335 132.10418 +0 0 1 2.415 132.10419 +0 1 1 2.509 132.10420 +0 0 1 2.713 132.10421 +0 1 1 2.807 132.10422 +0 0 1 2.911 132.10423 +0 1 1 2.925 132.10424 +0 0 1 2.925 132.10425 +0 0 0 2.925 132.10426 +0 1 0 2.911 132.10427 +0 0 0 2.805 132.10428 +0 1 0 2.715 132.10429 +0 0 0 2.507 132.10430 +0 1 0 2.417 132.10431 +0 0 0 2.329 132.10432 +0 1 0 2.127 132.10433 +0 0 0 2.003 132.10434 +0 1 0 1.915 132.10435 +0 0 0 1.771 132.10436 +0 1 0 1.629 132.10437 +0 0 0 1.479 132.10438 +0 1 0 1.213 132.10439 +0 0 0 1.089 132.10440 +0 1 0 1.075 132.10441 +0 0 0 1.075 132.10442 +0 0 1 1.075 132.10443 +0 1 1 1.089 132.10444 +0 0 1 1.213 132.10445 +0 1 1 1.471 132.10446 +0 0 1 1.629 132.10447 +0 1 1 1.769 132.10448 +0 0 1 1.915 132.10449 +0 1 1 2.003 132.10450 +0 0 1 2.135 132.10451 +0 1 1 2.323 132.10452 +0 0 1 2.911 132.10453 +0 1 1 2.925 132.10454 +0 0 1 2.925 132.10455 +0 0 0 2.925 132.10456 +0 1 0 2.911 132.10457 +0 0 0 2.315 132.10458 +0 1 0 2.143 132.10459 +0 0 0 2.003 132.10460 +0 1 0 1.915 132.10461 +0 0 0 1.769 132.10462 +0 1 0 1.631 132.10463 +0 0 0 1.461 132.10464 +0 1 0 1.215 132.10465 +0 0 0 1.089 132.10466 +0 1 0 1.075 132.10467 +0 0 0 1.075 132.10468 +0 0 1 1.075 132.10469 +0 1 1 1.089 132.10470 +0 0 1 1.215 132.10471 +0 1 1 1.451 132.10472 +0 0 1 1.631 132.10473 +0 1 1 1.767 132.10474 +0 0 1 1.917 132.10475 +0 1 1 2.001 132.10476 +0 0 1 2.151 132.10477 +0 1 1 2.307 132.10478 +0 0 1 2.911 132.10479 +0 1 1 2.925 132.10480 +0 0 1 2.925 132.10481 +0 0 0 2.925 132.10482 +0 1 0 2.911 132.10483 +0 0 0 2.293 132.10484 +0 1 0 2.165 132.10485 +0 0 0 1.997 132.10486 +0 1 0 1.921 132.10487 +0 0 0 1.763 132.10488 +0 1 0 1.635 132.10489 +0 0 0 1.423 132.10490 +0 1 0 1.219 132.10491 +0 0 0 1.089 132.10492 +0 1 0 1.075 132.10493 +0 0 0 1.075 132.10494 +0 0 1 1.075 132.10495 +0 1 1 1.089 132.10496 +0 0 1 2.185 132.10497 +0 1 1 2.273 132.10498 +0 0 1 2.911 132.10499 +0 1 1 2.925 132.10500 +0 0 1 2.925 132.10501 +0 0 0 2.925 132.10502 +0 1 0 2.911 132.10503 +0 0 0 1.089 132.10504 +0 1 0 1.075 132.10505 +0 0 0 1.075 132.10506 +0 0 1 1.075 132.10507 +0 1 1 1.089 132.10508 +0 0 1 2.911 132.10509 +0 1 1 2.925 132.10510 +0 0 1 2.925 132.10511 +0 0 0 2.925 132.10512 +0 1 0 2.911 132.10513 +0 0 0 1.089 132.10514 +0 1 0 1.075 132.10515 +0 0 0 1.075 132.10516 +0 0 1 1.075 132.10517 +0 1 1 1.089 132.10518 +0 0 1 2.911 132.10519 +0 1 1 2.925 132.10520 +0 0 1 2.925 132.10521 +0 0 0 2.925 132.10522 +0 1 0 2.911 132.10523 +0 0 0 1.089 132.10524 +0 1 0 1.075 132.10525 +0 0 0 1.075 132.10526 +0 0 1 1.075 132.10527 +0 1 1 1.089 132.10528 +0 0 1 2.911 132.10529 +0 1 1 2.925 132.10530 +0 0 1 2.925 132.10531 +0 0 0 2.925 132.10532 +0 1 0 2.911 132.10533 +0 0 0 1.089 132.10534 +0 1 0 1.075 132.10535 +0 0 0 1.075 132.10536 +0 0 1 1.075 132.10537 +0 1 1 1.089 132.10538 +0 0 1 2.911 132.10539 +0 1 1 2.925 132.10540 +0 0 1 2.925 132.10541 +0 0 0 2.925 132.10542 +0 1 0 2.911 132.10543 +0 0 0 1.089 132.10544 +0 1 0 1.075 132.10545 +0 0 0 1.075 132.10546 +0 0 1 1.075 132.10547 +0 1 1 1.089 132.10548 +0 0 1 2.911 132.10549 +0 1 1 2.925 132.10550 +0 0 1 2.925 132.10551 +0 0 0 2.925 132.10552 +0 1 0 2.911 132.10553 +0 0 0 1.089 132.10554 +0 1 0 1.075 132.10555 +0 0 0 1.075 132.10556 +0 0 1 1.075 132.10557 +0 1 1 1.089 132.10558 +0 0 1 2.911 132.10559 +0 1 1 2.925 132.10560 +0 0 1 2.925 132.10561 +0 0 0 2.925 132.10562 +0 1 0 2.911 132.10563 +0 0 0 1.089 132.10564 +0 1 0 1.075 132.10565 +0 0 0 1.075 132.10566 +0 0 1 1.075 132.10567 +0 1 1 1.089 132.10568 +0 0 1 2.911 132.10569 +0 1 1 2.925 132.10570 +0 0 1 2.925 132.10571 +0 0 0 2.925 132.10572 +0 1 0 2.911 132.10573 +0 0 0 1.089 132.10574 +0 1 0 1.075 132.10575 +0 0 0 1.075 132.10576 +0 0 1 1.075 132.10577 +0 1 1 1.089 132.10578 +0 0 1 2.911 132.10579 +0 1 1 2.925 132.10580 +0 0 1 2.925 132.10581 +0 0 0 2.925 132.10582 +0 1 0 2.911 132.10583 +0 0 0 1.089 132.10584 +0 1 0 1.075 132.10585 +0 0 0 1.075 132.10586 +0 0 1 1.075 132.10587 +0 1 1 1.089 132.10588 +0 0 1 2.911 132.10589 +0 1 1 2.925 132.10590 +0 0 1 2.925 132.10591 +0 0 0 2.925 132.10592 +0 1 0 2.911 132.10593 +0 0 0 1.089 132.10594 +0 1 0 1.075 132.10595 +0 0 0 1.075 132.10596 +0 0 1 1.075 132.10597 +0 1 1 1.089 132.10598 +0 0 1 2.911 132.10599 +0 1 1 2.925 132.10600 +0 0 1 2.925 132.10601 +0 0 0 2.925 132.10602 +0 1 0 2.911 132.10603 +0 0 0 1.089 132.10604 +0 1 0 1.075 132.10605 +0 0 0 1.075 132.10606 +0 0 1 1.075 132.10607 +0 1 1 1.089 132.10608 +0 0 1 2.911 132.10609 +0 1 1 2.925 132.10610 +0 0 1 2.925 132.10611 +0 0 0 2.925 132.10612 +0 1 0 2.911 132.10613 +0 0 0 1.089 132.10614 +0 1 0 1.075 132.10615 +0 0 0 1.075 132.10616 +0 0 1 1.075 132.10617 +0 1 1 1.089 132.10618 +0 0 1 2.911 132.10619 +0 1 1 2.925 132.10620 +0 0 1 2.925 132.10621 +0 0 0 2.925 132.10622 +0 1 0 2.911 132.10623 +0 0 0 1.089 132.10624 +0 1 0 1.075 132.10625 +0 0 0 1.075 132.10626 +0 0 1 1.075 132.10627 +0 1 1 1.089 132.10628 +0 0 1 2.911 132.10629 +0 1 1 2.925 132.10630 +0 0 1 2.925 132.10631 +0 0 0 2.925 132.10632 +0 1 0 2.911 132.10633 +0 0 0 1.089 132.10634 +0 1 0 1.075 132.10635 +0 0 0 1.075 132.10636 +0 0 1 1.075 132.10637 +0 1 1 1.089 132.10638 +0 0 1 2.911 132.10639 +0 1 1 2.925 132.10640 +0 0 1 2.925 132.10641 +0 0 0 2.925 132.10642 +0 1 0 2.911 132.10643 +0 0 0 1.089 132.10644 +0 1 0 1.075 132.10645 +0 0 0 1.075 132.10646 +0 0 1 1.075 132.10647 +0 1 1 1.089 132.10648 +0 0 1 2.911 132.10649 +0 1 1 2.925 132.10650 +0 0 1 2.925 132.10651 +0 0 0 2.925 132.10652 +0 1 0 2.911 132.10653 +0 0 0 1.089 132.10654 +0 1 0 1.075 132.10655 +0 0 0 1.075 132.10656 +0 0 1 1.075 132.10657 +0 1 1 1.089 132.10658 +0 0 1 2.911 132.10659 +0 1 1 2.925 132.10660 +0 0 1 2.925 132.10661 +0 0 0 2.925 132.10662 +0 1 0 2.911 132.10663 +0 0 0 1.089 132.10664 +0 1 0 1.075 132.10665 +0 0 0 1.075 132.10666 +0 0 1 1.075 132.10667 +0 1 1 1.089 132.10668 +0 0 1 2.911 132.10669 +0 1 1 2.925 132.10670 +0 0 1 2.925 132.10671 +0 0 0 2.925 132.10672 +0 1 0 2.911 132.10673 +0 0 0 1.089 132.10674 +0 1 0 1.075 132.10675 +0 0 0 1.075 132.10676 +0 0 1 1.075 132.10677 +0 1 1 1.089 132.10678 +0 0 1 2.911 132.10679 +0 1 1 2.925 132.10680 +0 0 1 2.925 132.10681 +0 0 0 2.925 132.10682 +0 1 0 2.911 132.10683 +0 0 0 1.089 132.10684 +0 1 0 1.075 132.10685 +0 0 0 1.075 132.10686 +0 0 1 1.075 132.10687 +0 1 1 1.089 132.10688 +0 0 1 2.911 132.10689 +0 1 1 2.925 132.10690 +0 0 1 2.925 132.10691 +0 0 0 2.925 132.10692 +0 1 0 2.911 132.10693 +0 0 0 1.091 132.10694 +0 1 0 1.075 132.10695 +0 0 0 1.075 132.10696 +0 0 1 1.075 132.10697 +0 1 1 1.091 132.10698 +0 0 1 2.909 132.10699 +0 1 1 2.925 132.10700 +0 0 1 2.925 132.10701 +0 0 0 2.925 132.10702 +0 1 0 2.909 132.10703 +0 0 0 1.091 132.10704 +0 1 0 1.075 132.10705 +0 0 0 1.075 132.10706 +0 0 1 1.075 132.10707 +0 1 1 1.091 132.10708 +0 0 1 2.909 132.10709 +0 1 1 2.925 132.10710 +0 0 1 2.925 132.10711 +0 0 0 2.925 132.10712 +0 1 0 2.909 132.10713 +0 0 0 1.091 132.10714 +0 1 0 1.077 132.10715 +0 0 0 1.077 132.10716 +0 0 1 1.077 132.10717 +0 1 1 1.093 132.10718 +0 0 1 2.907 132.10719 +0 1 1 2.923 132.10720 +0 0 1 2.923 132.10721 +0 0 0 2.923 132.10722 +0 1 0 2.907 132.10723 +0 0 0 1.093 132.10724 +0 1 0 1.077 132.10725 +0 0 0 1.077 132.10726 +0 0 1 1.077 132.10727 +0 1 1 1.095 132.10728 +0 0 1 2.907 132.10729 +0 1 1 2.923 132.10730 +0 0 1 2.921 132.10731 +0 0 0 2.921 132.10732 +0 1 0 2.905 132.10733 +0 0 0 1.095 132.10734 +0 1 0 1.079 132.10735 +0 0 0 1.079 132.10736 +0 0 1 1.079 132.10737 +0 1 1 1.097 132.10738 +0 0 1 2.903 132.10739 +0 1 1 2.921 132.10740 +0 0 1 2.921 132.10741 +0 0 0 2.921 132.10742 +0 1 0 2.903 132.10743 +0 0 0 1.099 132.10744 +0 1 0 1.081 132.10745 +0 0 0 1.081 132.10746 +0 0 1 1.081 132.10747 +0 1 1 1.099 132.10748 +0 0 1 2.901 132.10749 +0 1 1 2.919 132.10750 +0 0 1 2.919 132.10751 +0 0 0 2.919 132.10752 +0 1 0 2.899 132.10753 +0 0 0 1.101 132.10754 +0 1 0 1.083 132.10755 +0 0 0 1.083 132.10756 +0 0 1 1.083 132.10757 +0 1 1 1.103 132.10758 +0 0 1 2.897 132.10759 +0 1 1 2.917 132.10760 +0 0 1 2.915 132.10761 +0 0 0 2.915 132.10762 +0 1 0 2.895 132.10763 +0 0 0 1.105 132.10764 +0 1 0 1.085 132.10765 +0 0 0 1.087 132.10766 +0 0 1 1.087 132.10767 +0 1 1 1.109 132.10768 +0 0 1 2.891 132.10769 +0 1 1 2.915 132.10770 +0 0 1 2.913 132.10771 +0 0 0 2.913 132.10772 +0 1 0 2.889 132.10773 +0 0 0 1.111 132.10774 +0 1 0 1.087 132.10775 +0 0 0 1.089 132.10776 +0 0 1 1.089 132.10777 +0 1 1 1.115 132.10778 +0 0 1 2.885 132.10779 +0 1 1 2.911 132.10780 +0 0 1 2.909 132.10781 +0 0 0 2.909 132.10782 +0 1 0 2.879 132.10783 +0 0 0 1.121 132.10784 +0 1 0 1.091 132.10785 +0 0 0 1.093 132.10786 +0 0 1 1.093 132.10787 +0 1 1 2.907 132.10788 +0 0 1 2.905 132.10789 +0 0 0 2.905 132.10790 +0 1 0 1.097 132.10791 +0 0 0 1.099 132.10792 +0 0 1 1.099 132.10793 +0 1 1 2.901 132.10794 +0 0 1 2.899 132.10795 +0 0 0 2.899 132.10796 +0 1 0 1.101 132.10797 +0 0 0 1.105 132.10798 +0 0 1 1.105 132.10799 +0 1 1 2.895 132.10800 +0 0 1 2.891 132.10801 +0 0 0 2.891 132.10802 +0 1 0 1.109 132.10803 +0 0 0 1.113 132.10804 +0 0 1 1.113 132.10805 +0 1 1 2.887 132.10806 +0 0 1 2.877 132.10807 +0 0 0 2.877 132.10808 +0 1 0 1.123 132.10809 +0 0 0 0.999 132.10810 +0 0 1 0.999 132.10811 +0 1 1 2.999
133.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 133.2 +++ b/graster/signer4laser2x1.png.raster.ngc Tue Aug 24 19:06:45 2010 -0400 133.3 @@ -0,0 +1,857 @@ 133.4 +(raster gcode for job 3162202862410280766) 133.5 +(image: signer4laser2x1.png [1000, 533]) 133.6 +(config: {:feed=>120, :dpi=>[500, 500], :offset=>[1.0, 1.0], :cut_feed=>20, :on_range=>[0.0, 0.5], :corner_radius=>0, :overshoot=>0.5, :tile_size=>[2.0, 1.066], :repeat=>[1, 1], :tile_spacing=>[0.125, 0.125]}) 133.7 +M63 P0 133.8 +G61 133.9 +F120 133.10 +M101 133.11 +M3 S1 133.12 +G0 X3.382 Y1.066 133.13 +G1 X0.644 Y1.066 133.14 +G0 X0.636 Y1.068 133.15 +G1 X3.382 Y1.068 133.16 +G0 X3.382 Y1.070 133.17 +G1 X0.630 Y1.070 133.18 +G0 X0.626 Y1.072 133.19 +G1 X3.382 Y1.072 133.20 +G0 X3.382 Y1.074 133.21 +G1 X0.624 Y1.074 133.22 +G0 X0.622 Y1.076 133.23 +G1 X3.382 Y1.076 133.24 +G0 X3.382 Y1.078 133.25 +G1 X0.620 Y1.078 133.26 +G0 X0.618 Y1.080 133.27 +G1 X3.382 Y1.080 133.28 +G0 X3.382 Y1.082 133.29 +G1 X0.618 Y1.082 133.30 +G0 X0.616 Y1.084 133.31 +G1 X3.382 Y1.084 133.32 +G0 X3.382 Y1.086 133.33 +G1 X0.616 Y1.086 133.34 +G0 X0.614 Y1.088 133.35 +G1 X3.382 Y1.088 133.36 +G0 X3.382 Y1.090 133.37 +G1 X0.614 Y1.090 133.38 +G0 X0.614 Y1.092 133.39 +G1 X3.382 Y1.092 133.40 +G0 X3.382 Y1.094 133.41 +G1 X0.614 Y1.094 133.42 +G0 X0.612 Y1.096 133.43 +G1 X3.382 Y1.096 133.44 +G0 X3.382 Y1.098 133.45 +G1 X0.612 Y1.098 133.46 +G0 X0.612 Y1.100 133.47 +G1 X3.382 Y1.100 133.48 +G0 X3.382 Y1.102 133.49 +G1 X0.612 Y1.102 133.50 +G0 X0.612 Y1.104 133.51 +G1 X3.382 Y1.104 133.52 +G0 X3.382 Y1.106 133.53 +G1 X0.612 Y1.106 133.54 +G0 X0.612 Y1.108 133.55 +G1 X3.382 Y1.108 133.56 +G0 X3.382 Y1.110 133.57 +G1 X0.612 Y1.110 133.58 +G0 X0.612 Y1.112 133.59 +G1 X3.382 Y1.112 133.60 +G0 X3.382 Y1.114 133.61 +G1 X0.612 Y1.114 133.62 +G0 X0.612 Y1.116 133.63 +G1 X3.382 Y1.116 133.64 +G0 X3.382 Y1.118 133.65 +G1 X0.612 Y1.118 133.66 +G0 X0.724 Y1.120 133.67 +G1 X3.382 Y1.120 133.68 +G0 X3.382 Y1.122 133.69 +G1 X0.724 Y1.122 133.70 +G0 X0.724 Y1.124 133.71 +G1 X3.380 Y1.124 133.72 +G0 X3.380 Y1.126 133.73 +G1 X0.722 Y1.126 133.74 +G0 X0.722 Y1.128 133.75 +G1 X3.380 Y1.128 133.76 +G0 X3.378 Y1.130 133.77 +G1 X0.722 Y1.130 133.78 +G0 X0.722 Y1.132 133.79 +G1 X3.378 Y1.132 133.80 +G0 X3.376 Y1.134 133.81 +G1 X0.720 Y1.134 133.82 +G0 X0.720 Y1.136 133.83 +G1 X3.374 Y1.136 133.84 +G0 X3.372 Y1.138 133.85 +G1 X0.718 Y1.138 133.86 +G0 X0.714 Y1.140 133.87 +G1 X3.368 Y1.140 133.88 +G0 X3.364 Y1.142 133.89 +G1 X0.710 Y1.142 133.90 +G0 X0.698 Y1.144 133.91 +G1 X3.358 Y1.144 133.92 +G0 X3.364 Y1.146 133.93 +G1 X0.656 Y1.146 133.94 +G0 X0.644 Y1.148 133.95 +G1 X3.368 Y1.148 133.96 +G0 X3.372 Y1.150 133.97 +G1 X0.638 Y1.150 133.98 +G0 X0.634 Y1.152 133.99 +G1 X3.374 Y1.152 133.100 +G0 X3.376 Y1.154 133.101 +G1 X0.630 Y1.154 133.102 +G0 X0.628 Y1.156 133.103 +G1 X3.378 Y1.156 133.104 +G0 X3.380 Y1.158 133.105 +G1 X0.624 Y1.158 133.106 +G0 X0.622 Y1.160 133.107 +G1 X3.380 Y1.160 133.108 +G0 X3.382 Y1.162 133.109 +G1 X0.622 Y1.162 133.110 +G0 X0.620 Y1.164 133.111 +G1 X3.382 Y1.164 133.112 +G0 X3.382 Y1.166 133.113 +G1 X0.618 Y1.166 133.114 +G0 X0.618 Y1.168 133.115 +G1 X3.382 Y1.168 133.116 +G0 X3.384 Y1.170 133.117 +G1 X0.616 Y1.170 133.118 +G0 X0.616 Y1.172 133.119 +G1 X3.384 Y1.172 133.120 +G0 X3.384 Y1.174 133.121 +G1 X0.616 Y1.174 133.122 +G0 X0.614 Y1.176 133.123 +G1 X3.384 Y1.176 133.124 +G0 X3.384 Y1.178 133.125 +G1 X0.614 Y1.178 133.126 +G0 X0.614 Y1.180 133.127 +G1 X3.384 Y1.180 133.128 +G0 X3.384 Y1.182 133.129 +G1 X0.614 Y1.182 133.130 +G0 X0.614 Y1.184 133.131 +G1 X3.384 Y1.184 133.132 +G0 X3.384 Y1.186 133.133 +G1 X0.614 Y1.186 133.134 +G0 X0.614 Y1.188 133.135 +G1 X3.384 Y1.188 133.136 +G0 X3.384 Y1.190 133.137 +G1 X0.612 Y1.190 133.138 +G0 X0.612 Y1.192 133.139 +G1 X3.384 Y1.192 133.140 +G0 X3.384 Y1.194 133.141 +G1 X0.612 Y1.194 133.142 +G0 X0.612 Y1.196 133.143 +G1 X3.384 Y1.196 133.144 +G0 X3.384 Y1.198 133.145 +G1 X0.612 Y1.198 133.146 +G0 X0.614 Y1.200 133.147 +G1 X3.384 Y1.200 133.148 +G0 X3.384 Y1.202 133.149 +G1 X0.614 Y1.202 133.150 +G0 X0.614 Y1.204 133.151 +G1 X3.384 Y1.204 133.152 +G0 X3.384 Y1.206 133.153 +G1 X0.614 Y1.206 133.154 +G0 X0.614 Y1.208 133.155 +G1 X3.384 Y1.208 133.156 +G0 X3.382 Y1.210 133.157 +G1 X0.614 Y1.210 133.158 +G0 X0.614 Y1.212 133.159 +G1 X3.382 Y1.212 133.160 +G0 X3.382 Y1.214 133.161 +G1 X0.616 Y1.214 133.162 +G0 X0.616 Y1.216 133.163 +G1 X3.380 Y1.216 133.164 +G0 X3.380 Y1.218 133.165 +G1 X0.616 Y1.218 133.166 +G0 X0.618 Y1.220 133.167 +G1 X3.380 Y1.220 133.168 +G0 X3.378 Y1.222 133.169 +G1 X0.618 Y1.222 133.170 +G0 X0.620 Y1.224 133.171 +G1 X3.378 Y1.224 133.172 +G0 X3.376 Y1.226 133.173 +G1 X0.620 Y1.226 133.174 +G0 X0.622 Y1.228 133.175 +G1 X3.374 Y1.228 133.176 +G0 X3.372 Y1.230 133.177 +G1 X0.624 Y1.230 133.178 +G0 X0.626 Y1.232 133.179 +G1 X3.368 Y1.232 133.180 +G0 X3.364 Y1.234 133.181 +G1 X0.630 Y1.234 133.182 +G0 X0.634 Y1.236 133.183 +G1 X3.360 Y1.236 133.184 +G0 X3.352 Y1.238 133.185 +G1 X0.640 Y1.238 133.186 +G0 X0.654 Y1.240 133.187 +G1 X2.880 Y1.240 133.188 +G0 X0.622 Y1.316 133.189 +G1 X3.380 Y1.316 133.190 +G0 X3.386 Y1.318 133.191 +G1 X0.616 Y1.318 133.192 +G0 X0.610 Y1.320 133.193 +G1 X3.392 Y1.320 133.194 +G0 X3.396 Y1.322 133.195 +G1 X0.606 Y1.322 133.196 +G0 X0.602 Y1.324 133.197 +G1 X3.400 Y1.324 133.198 +G0 X3.402 Y1.326 133.199 +G1 X0.600 Y1.326 133.200 +G0 X0.596 Y1.328 133.201 +G1 X3.406 Y1.328 133.202 +G0 X3.408 Y1.330 133.203 +G1 X0.594 Y1.330 133.204 +G0 X0.592 Y1.332 133.205 +G1 X3.410 Y1.332 133.206 +G0 X3.412 Y1.334 133.207 +G1 X0.590 Y1.334 133.208 +G0 X0.590 Y1.336 133.209 +G1 X3.414 Y1.336 133.210 +G0 X3.416 Y1.338 133.211 +G1 X0.588 Y1.338 133.212 +G0 X0.586 Y1.340 133.213 +G1 X3.416 Y1.340 133.214 +G0 X3.418 Y1.342 133.215 +G1 X0.584 Y1.342 133.216 +G0 X0.584 Y1.344 133.217 +G1 X3.420 Y1.344 133.218 +G0 X3.420 Y1.346 133.219 +G1 X0.582 Y1.346 133.220 +G0 X0.582 Y1.348 133.221 +G1 X3.422 Y1.348 133.222 +G0 X3.422 Y1.350 133.223 +G1 X0.580 Y1.350 133.224 +G0 X0.580 Y1.352 133.225 +G1 X3.422 Y1.352 133.226 +G0 X3.424 Y1.354 133.227 +G1 X0.578 Y1.354 133.228 +G0 X0.578 Y1.356 133.229 +G1 X3.424 Y1.356 133.230 +G0 X3.424 Y1.358 133.231 +G1 X0.578 Y1.358 133.232 +G0 X0.578 Y1.360 133.233 +G1 X3.426 Y1.360 133.234 +G0 X3.426 Y1.362 133.235 +G1 X0.576 Y1.362 133.236 +G0 X0.576 Y1.364 133.237 +G1 X3.426 Y1.364 133.238 +G0 X3.426 Y1.366 133.239 +G1 X0.576 Y1.366 133.240 +G0 X0.576 Y1.368 133.241 +G1 X3.426 Y1.368 133.242 +G0 X3.426 Y1.370 133.243 +G1 X0.576 Y1.370 133.244 +G0 X0.576 Y1.372 133.245 +G1 X3.426 Y1.372 133.246 +G0 X3.426 Y1.374 133.247 +G1 X0.576 Y1.374 133.248 +G0 X0.576 Y1.376 133.249 +G1 X3.426 Y1.376 133.250 +G0 X3.426 Y1.378 133.251 +G1 X0.576 Y1.378 133.252 +G0 X0.576 Y1.380 133.253 +G1 X3.426 Y1.380 133.254 +G0 X3.426 Y1.382 133.255 +G1 X0.576 Y1.382 133.256 +G0 X0.576 Y1.384 133.257 +G1 X3.426 Y1.384 133.258 +G0 X3.426 Y1.386 133.259 +G1 X0.576 Y1.386 133.260 +G0 X0.576 Y1.388 133.261 +G1 X3.426 Y1.388 133.262 +G0 X3.426 Y1.390 133.263 +G1 X0.576 Y1.390 133.264 +G0 X0.576 Y1.392 133.265 +G1 X3.426 Y1.392 133.266 +G0 X3.426 Y1.394 133.267 +G1 X0.576 Y1.394 133.268 +G0 X0.576 Y1.396 133.269 +G1 X3.426 Y1.396 133.270 +G0 X3.426 Y1.398 133.271 +G1 X0.576 Y1.398 133.272 +G0 X0.576 Y1.400 133.273 +G1 X3.426 Y1.400 133.274 +G0 X3.426 Y1.402 133.275 +G1 X0.576 Y1.402 133.276 +G0 X0.576 Y1.404 133.277 +G1 X3.426 Y1.404 133.278 +G0 X3.426 Y1.406 133.279 +G1 X0.576 Y1.406 133.280 +G0 X0.576 Y1.408 133.281 +G1 X3.426 Y1.408 133.282 +G0 X3.426 Y1.410 133.283 +G1 X0.576 Y1.410 133.284 +G0 X0.576 Y1.412 133.285 +G1 X3.426 Y1.412 133.286 +G0 X3.426 Y1.414 133.287 +G1 X0.576 Y1.414 133.288 +G0 X0.576 Y1.416 133.289 +G1 X3.426 Y1.416 133.290 +G0 X3.426 Y1.418 133.291 +G1 X0.576 Y1.418 133.292 +G0 X0.576 Y1.420 133.293 +G1 X3.426 Y1.420 133.294 +G0 X3.426 Y1.422 133.295 +G1 X0.576 Y1.422 133.296 +G0 X0.576 Y1.424 133.297 +G1 X3.426 Y1.424 133.298 +G0 X3.426 Y1.426 133.299 +G1 X0.576 Y1.426 133.300 +G0 X0.576 Y1.428 133.301 +G1 X3.426 Y1.428 133.302 +G0 X3.426 Y1.430 133.303 +G1 X0.576 Y1.430 133.304 +G0 X0.576 Y1.432 133.305 +G1 X3.426 Y1.432 133.306 +G0 X3.426 Y1.434 133.307 +G1 X0.576 Y1.434 133.308 +G0 X0.576 Y1.436 133.309 +G1 X3.426 Y1.436 133.310 +G0 X3.426 Y1.438 133.311 +G1 X0.576 Y1.438 133.312 +G0 X0.576 Y1.440 133.313 +G1 X3.426 Y1.440 133.314 +G0 X3.426 Y1.442 133.315 +G1 X0.576 Y1.442 133.316 +G0 X0.576 Y1.444 133.317 +G1 X3.426 Y1.444 133.318 +G0 X3.426 Y1.446 133.319 +G1 X0.576 Y1.446 133.320 +G0 X0.576 Y1.448 133.321 +G1 X3.426 Y1.448 133.322 +G0 X3.426 Y1.450 133.323 +G1 X0.576 Y1.450 133.324 +G0 X0.576 Y1.452 133.325 +G1 X3.426 Y1.452 133.326 +G0 X3.426 Y1.454 133.327 +G1 X0.576 Y1.454 133.328 +G0 X0.576 Y1.456 133.329 +G1 X3.426 Y1.456 133.330 +G0 X3.426 Y1.458 133.331 +G1 X0.576 Y1.458 133.332 +G0 X0.576 Y1.460 133.333 +G1 X3.426 Y1.460 133.334 +G0 X3.426 Y1.462 133.335 +G1 X0.576 Y1.462 133.336 +G0 X0.576 Y1.464 133.337 +G1 X3.426 Y1.464 133.338 +G0 X3.426 Y1.466 133.339 +G1 X0.576 Y1.466 133.340 +G0 X0.576 Y1.468 133.341 +G1 X3.426 Y1.468 133.342 +G0 X3.426 Y1.470 133.343 +G1 X0.576 Y1.470 133.344 +G0 X0.576 Y1.472 133.345 +G1 X3.426 Y1.472 133.346 +G0 X3.426 Y1.474 133.347 +G1 X0.576 Y1.474 133.348 +G0 X0.576 Y1.476 133.349 +G1 X3.426 Y1.476 133.350 +G0 X3.426 Y1.478 133.351 +G1 X0.576 Y1.478 133.352 +G0 X0.576 Y1.480 133.353 +G1 X3.426 Y1.480 133.354 +G0 X3.426 Y1.482 133.355 +G1 X0.576 Y1.482 133.356 +G0 X0.576 Y1.484 133.357 +G1 X3.426 Y1.484 133.358 +G0 X3.426 Y1.486 133.359 +G1 X0.576 Y1.486 133.360 +G0 X0.576 Y1.488 133.361 +G1 X3.426 Y1.488 133.362 +G0 X3.426 Y1.490 133.363 +G1 X0.576 Y1.490 133.364 +G0 X0.576 Y1.492 133.365 +G1 X3.426 Y1.492 133.366 +G0 X3.426 Y1.494 133.367 +G1 X0.576 Y1.494 133.368 +G0 X0.576 Y1.496 133.369 +G1 X3.426 Y1.496 133.370 +G0 X3.426 Y1.498 133.371 +G1 X0.576 Y1.498 133.372 +G0 X0.576 Y1.500 133.373 +G1 X3.426 Y1.500 133.374 +G0 X3.426 Y1.502 133.375 +G1 X0.576 Y1.502 133.376 +G0 X0.576 Y1.504 133.377 +G1 X3.426 Y1.504 133.378 +G0 X3.426 Y1.506 133.379 +G1 X0.576 Y1.506 133.380 +G0 X0.576 Y1.508 133.381 +G1 X3.426 Y1.508 133.382 +G0 X3.426 Y1.510 133.383 +G1 X0.576 Y1.510 133.384 +G0 X0.576 Y1.512 133.385 +G1 X3.426 Y1.512 133.386 +G0 X3.426 Y1.514 133.387 +G1 X0.576 Y1.514 133.388 +G0 X0.576 Y1.516 133.389 +G1 X3.426 Y1.516 133.390 +G0 X3.426 Y1.518 133.391 +G1 X0.576 Y1.518 133.392 +G0 X0.576 Y1.520 133.393 +G1 X3.426 Y1.520 133.394 +G0 X3.426 Y1.522 133.395 +G1 X0.576 Y1.522 133.396 +G0 X0.576 Y1.524 133.397 +G1 X3.426 Y1.524 133.398 +G0 X3.426 Y1.526 133.399 +G1 X0.576 Y1.526 133.400 +G0 X0.576 Y1.528 133.401 +G1 X3.426 Y1.528 133.402 +G0 X3.426 Y1.530 133.403 +G1 X0.576 Y1.530 133.404 +G0 X0.576 Y1.532 133.405 +G1 X3.426 Y1.532 133.406 +G0 X3.426 Y1.534 133.407 +G1 X0.576 Y1.534 133.408 +G0 X0.576 Y1.536 133.409 +G1 X3.426 Y1.536 133.410 +G0 X3.426 Y1.538 133.411 +G1 X0.576 Y1.538 133.412 +G0 X0.576 Y1.540 133.413 +G1 X3.426 Y1.540 133.414 +G0 X3.426 Y1.542 133.415 +G1 X0.576 Y1.542 133.416 +G0 X0.576 Y1.544 133.417 +G1 X3.426 Y1.544 133.418 +G0 X3.426 Y1.546 133.419 +G1 X0.576 Y1.546 133.420 +G0 X0.576 Y1.548 133.421 +G1 X3.426 Y1.548 133.422 +G0 X3.426 Y1.550 133.423 +G1 X0.576 Y1.550 133.424 +G0 X0.576 Y1.552 133.425 +G1 X3.426 Y1.552 133.426 +G0 X3.426 Y1.554 133.427 +G1 X0.576 Y1.554 133.428 +G0 X0.576 Y1.556 133.429 +G1 X3.426 Y1.556 133.430 +G0 X3.426 Y1.558 133.431 +G1 X0.576 Y1.558 133.432 +G0 X0.576 Y1.560 133.433 +G1 X3.426 Y1.560 133.434 +G0 X3.426 Y1.562 133.435 +G1 X0.576 Y1.562 133.436 +G0 X0.576 Y1.564 133.437 +G1 X3.426 Y1.564 133.438 +G0 X3.426 Y1.566 133.439 +G1 X0.576 Y1.566 133.440 +G0 X0.576 Y1.568 133.441 +G1 X3.426 Y1.568 133.442 +G0 X3.426 Y1.570 133.443 +G1 X0.576 Y1.570 133.444 +G0 X0.576 Y1.572 133.445 +G1 X3.426 Y1.572 133.446 +G0 X3.426 Y1.574 133.447 +G1 X0.576 Y1.574 133.448 +G0 X0.576 Y1.576 133.449 +G1 X3.426 Y1.576 133.450 +G0 X3.426 Y1.578 133.451 +G1 X0.576 Y1.578 133.452 +G0 X0.576 Y1.580 133.453 +G1 X3.426 Y1.580 133.454 +G0 X3.426 Y1.582 133.455 +G1 X0.576 Y1.582 133.456 +G0 X0.576 Y1.584 133.457 +G1 X3.426 Y1.584 133.458 +G0 X3.426 Y1.586 133.459 +G1 X0.576 Y1.586 133.460 +G0 X0.576 Y1.588 133.461 +G1 X3.426 Y1.588 133.462 +G0 X3.426 Y1.590 133.463 +G1 X0.576 Y1.590 133.464 +G0 X0.576 Y1.592 133.465 +G1 X3.426 Y1.592 133.466 +G0 X3.426 Y1.594 133.467 +G1 X0.576 Y1.594 133.468 +G0 X0.576 Y1.596 133.469 +G1 X3.426 Y1.596 133.470 +G0 X3.426 Y1.598 133.471 +G1 X0.576 Y1.598 133.472 +G0 X0.576 Y1.600 133.473 +G1 X3.426 Y1.600 133.474 +G0 X3.426 Y1.602 133.475 +G1 X0.576 Y1.602 133.476 +G0 X0.576 Y1.604 133.477 +G1 X3.426 Y1.604 133.478 +G0 X3.426 Y1.606 133.479 +G1 X0.576 Y1.606 133.480 +G0 X0.576 Y1.608 133.481 +G1 X3.426 Y1.608 133.482 +G0 X3.426 Y1.610 133.483 +G1 X0.576 Y1.610 133.484 +G0 X0.576 Y1.612 133.485 +G1 X3.426 Y1.612 133.486 +G0 X3.426 Y1.614 133.487 +G1 X0.576 Y1.614 133.488 +G0 X0.576 Y1.616 133.489 +G1 X3.426 Y1.616 133.490 +G0 X3.426 Y1.618 133.491 +G1 X0.576 Y1.618 133.492 +G0 X0.576 Y1.620 133.493 +G1 X3.426 Y1.620 133.494 +G0 X3.426 Y1.622 133.495 +G1 X0.576 Y1.622 133.496 +G0 X0.576 Y1.624 133.497 +G1 X3.426 Y1.624 133.498 +G0 X3.426 Y1.626 133.499 +G1 X0.576 Y1.626 133.500 +G0 X0.576 Y1.628 133.501 +G1 X3.426 Y1.628 133.502 +G0 X3.426 Y1.630 133.503 +G1 X0.576 Y1.630 133.504 +G0 X0.576 Y1.632 133.505 +G1 X3.426 Y1.632 133.506 +G0 X3.426 Y1.634 133.507 +G1 X0.576 Y1.634 133.508 +G0 X0.576 Y1.636 133.509 +G1 X3.426 Y1.636 133.510 +G0 X3.426 Y1.638 133.511 +G1 X0.576 Y1.638 133.512 +G0 X0.576 Y1.640 133.513 +G1 X3.426 Y1.640 133.514 +G0 X3.426 Y1.642 133.515 +G1 X0.576 Y1.642 133.516 +G0 X0.576 Y1.644 133.517 +G1 X3.426 Y1.644 133.518 +G0 X3.426 Y1.646 133.519 +G1 X0.576 Y1.646 133.520 +G0 X0.576 Y1.648 133.521 +G1 X3.426 Y1.648 133.522 +G0 X3.426 Y1.650 133.523 +G1 X0.576 Y1.650 133.524 +G0 X0.576 Y1.652 133.525 +G1 X3.426 Y1.652 133.526 +G0 X3.426 Y1.654 133.527 +G1 X0.576 Y1.654 133.528 +G0 X0.576 Y1.656 133.529 +G1 X3.426 Y1.656 133.530 +G0 X3.426 Y1.658 133.531 +G1 X0.576 Y1.658 133.532 +G0 X0.576 Y1.660 133.533 +G1 X3.426 Y1.660 133.534 +G0 X3.426 Y1.662 133.535 +G1 X0.576 Y1.662 133.536 +G0 X0.576 Y1.664 133.537 +G1 X3.426 Y1.664 133.538 +G0 X3.426 Y1.666 133.539 +G1 X0.576 Y1.666 133.540 +G0 X0.576 Y1.668 133.541 +G1 X3.426 Y1.668 133.542 +G0 X3.426 Y1.670 133.543 +G1 X0.576 Y1.670 133.544 +G0 X0.576 Y1.672 133.545 +G1 X3.426 Y1.672 133.546 +G0 X3.426 Y1.674 133.547 +G1 X0.576 Y1.674 133.548 +G0 X0.576 Y1.676 133.549 +G1 X3.426 Y1.676 133.550 +G0 X3.426 Y1.678 133.551 +G1 X0.576 Y1.678 133.552 +G0 X0.576 Y1.680 133.553 +G1 X3.426 Y1.680 133.554 +G0 X3.426 Y1.682 133.555 +G1 X0.576 Y1.682 133.556 +G0 X0.576 Y1.684 133.557 +G1 X3.426 Y1.684 133.558 +G0 X3.426 Y1.686 133.559 +G1 X0.576 Y1.686 133.560 +G0 X0.576 Y1.688 133.561 +G1 X3.426 Y1.688 133.562 +G0 X3.426 Y1.690 133.563 +G1 X0.576 Y1.690 133.564 +G0 X0.576 Y1.692 133.565 +G1 X3.426 Y1.692 133.566 +G0 X3.426 Y1.694 133.567 +G1 X0.576 Y1.694 133.568 +G0 X0.576 Y1.696 133.569 +G1 X3.426 Y1.696 133.570 +G0 X3.426 Y1.698 133.571 +G1 X0.576 Y1.698 133.572 +G0 X0.576 Y1.700 133.573 +G1 X3.426 Y1.700 133.574 +G0 X3.426 Y1.702 133.575 +G1 X0.576 Y1.702 133.576 +G0 X0.576 Y1.704 133.577 +G1 X3.426 Y1.704 133.578 +G0 X3.426 Y1.706 133.579 +G1 X0.576 Y1.706 133.580 +G0 X0.576 Y1.708 133.581 +G1 X3.426 Y1.708 133.582 +G0 X3.426 Y1.710 133.583 +G1 X0.576 Y1.710 133.584 +G0 X0.576 Y1.712 133.585 +G1 X3.426 Y1.712 133.586 +G0 X3.426 Y1.714 133.587 +G1 X0.576 Y1.714 133.588 +G0 X0.576 Y1.716 133.589 +G1 X3.426 Y1.716 133.590 +G0 X3.426 Y1.718 133.591 +G1 X0.576 Y1.718 133.592 +G0 X0.576 Y1.720 133.593 +G1 X3.426 Y1.720 133.594 +G0 X3.426 Y1.722 133.595 +G1 X0.576 Y1.722 133.596 +G0 X0.576 Y1.724 133.597 +G1 X3.426 Y1.724 133.598 +G0 X3.426 Y1.726 133.599 +G1 X0.576 Y1.726 133.600 +G0 X0.576 Y1.728 133.601 +G1 X3.426 Y1.728 133.602 +G0 X3.426 Y1.730 133.603 +G1 X0.576 Y1.730 133.604 +G0 X0.576 Y1.732 133.605 +G1 X3.426 Y1.732 133.606 +G0 X3.426 Y1.734 133.607 +G1 X0.576 Y1.734 133.608 +G0 X0.576 Y1.736 133.609 +G1 X3.426 Y1.736 133.610 +G0 X3.426 Y1.738 133.611 +G1 X0.576 Y1.738 133.612 +G0 X0.576 Y1.740 133.613 +G1 X3.426 Y1.740 133.614 +G0 X3.426 Y1.742 133.615 +G1 X0.576 Y1.742 133.616 +G0 X0.576 Y1.744 133.617 +G1 X3.426 Y1.744 133.618 +G0 X3.426 Y1.746 133.619 +G1 X0.576 Y1.746 133.620 +G0 X0.576 Y1.748 133.621 +G1 X3.426 Y1.748 133.622 +G0 X3.426 Y1.750 133.623 +G1 X0.576 Y1.750 133.624 +G0 X0.576 Y1.752 133.625 +G1 X3.426 Y1.752 133.626 +G0 X3.426 Y1.754 133.627 +G1 X0.576 Y1.754 133.628 +G0 X0.576 Y1.756 133.629 +G1 X3.426 Y1.756 133.630 +G0 X3.426 Y1.758 133.631 +G1 X0.576 Y1.758 133.632 +G0 X0.576 Y1.760 133.633 +G1 X3.426 Y1.760 133.634 +G0 X3.426 Y1.762 133.635 +G1 X0.576 Y1.762 133.636 +G0 X0.576 Y1.764 133.637 +G1 X3.426 Y1.764 133.638 +G0 X3.426 Y1.766 133.639 +G1 X0.576 Y1.766 133.640 +G0 X0.576 Y1.768 133.641 +G1 X3.426 Y1.768 133.642 +G0 X3.426 Y1.770 133.643 +G1 X0.576 Y1.770 133.644 +G0 X0.576 Y1.772 133.645 +G1 X3.426 Y1.772 133.646 +G0 X3.426 Y1.774 133.647 +G1 X0.576 Y1.774 133.648 +G0 X0.576 Y1.776 133.649 +G1 X3.426 Y1.776 133.650 +G0 X3.426 Y1.778 133.651 +G1 X0.576 Y1.778 133.652 +G0 X0.576 Y1.780 133.653 +G1 X3.426 Y1.780 133.654 +G0 X3.426 Y1.782 133.655 +G1 X0.576 Y1.782 133.656 +G0 X0.576 Y1.784 133.657 +G1 X3.426 Y1.784 133.658 +G0 X3.426 Y1.786 133.659 +G1 X0.576 Y1.786 133.660 +G0 X0.576 Y1.788 133.661 +G1 X3.426 Y1.788 133.662 +G0 X3.426 Y1.790 133.663 +G1 X0.576 Y1.790 133.664 +G0 X0.576 Y1.792 133.665 +G1 X3.426 Y1.792 133.666 +G0 X3.426 Y1.794 133.667 +G1 X0.576 Y1.794 133.668 +G0 X0.576 Y1.796 133.669 +G1 X3.426 Y1.796 133.670 +G0 X3.426 Y1.798 133.671 +G1 X0.576 Y1.798 133.672 +G0 X0.576 Y1.800 133.673 +G1 X3.426 Y1.800 133.674 +G0 X3.426 Y1.802 133.675 +G1 X0.576 Y1.802 133.676 +G0 X0.576 Y1.804 133.677 +G1 X3.426 Y1.804 133.678 +G0 X3.426 Y1.806 133.679 +G1 X0.576 Y1.806 133.680 +G0 X0.576 Y1.808 133.681 +G1 X3.426 Y1.808 133.682 +G0 X3.426 Y1.810 133.683 +G1 X0.576 Y1.810 133.684 +G0 X0.576 Y1.812 133.685 +G1 X3.426 Y1.812 133.686 +G0 X3.426 Y1.814 133.687 +G1 X0.576 Y1.814 133.688 +G0 X0.576 Y1.816 133.689 +G1 X3.426 Y1.816 133.690 +G0 X3.426 Y1.818 133.691 +G1 X0.576 Y1.818 133.692 +G0 X0.576 Y1.820 133.693 +G1 X3.426 Y1.820 133.694 +G0 X3.426 Y1.822 133.695 +G1 X0.576 Y1.822 133.696 +G0 X0.576 Y1.824 133.697 +G1 X3.426 Y1.824 133.698 +G0 X3.426 Y1.826 133.699 +G1 X0.576 Y1.826 133.700 +G0 X0.576 Y1.828 133.701 +G1 X3.426 Y1.828 133.702 +G0 X3.426 Y1.830 133.703 +G1 X0.576 Y1.830 133.704 +G0 X0.576 Y1.832 133.705 +G1 X3.426 Y1.832 133.706 +G0 X3.426 Y1.834 133.707 +G1 X0.576 Y1.834 133.708 +G0 X0.576 Y1.836 133.709 +G1 X3.426 Y1.836 133.710 +G0 X3.426 Y1.838 133.711 +G1 X0.576 Y1.838 133.712 +G0 X0.576 Y1.840 133.713 +G1 X3.426 Y1.840 133.714 +G0 X3.426 Y1.842 133.715 +G1 X0.576 Y1.842 133.716 +G0 X0.576 Y1.844 133.717 +G1 X3.426 Y1.844 133.718 +G0 X3.426 Y1.846 133.719 +G1 X0.576 Y1.846 133.720 +G0 X0.576 Y1.848 133.721 +G1 X3.426 Y1.848 133.722 +G0 X3.426 Y1.850 133.723 +G1 X0.576 Y1.850 133.724 +G0 X0.576 Y1.852 133.725 +G1 X3.426 Y1.852 133.726 +G0 X3.426 Y1.854 133.727 +G1 X0.576 Y1.854 133.728 +G0 X0.576 Y1.856 133.729 +G1 X3.426 Y1.856 133.730 +G0 X3.426 Y1.858 133.731 +G1 X0.576 Y1.858 133.732 +G0 X0.576 Y1.860 133.733 +G1 X3.426 Y1.860 133.734 +G0 X3.426 Y1.862 133.735 +G1 X0.576 Y1.862 133.736 +G0 X0.576 Y1.864 133.737 +G1 X3.426 Y1.864 133.738 +G0 X3.426 Y1.866 133.739 +G1 X0.576 Y1.866 133.740 +G0 X0.576 Y1.868 133.741 +G1 X3.426 Y1.868 133.742 +G0 X3.426 Y1.870 133.743 +G1 X0.576 Y1.870 133.744 +G0 X0.576 Y1.872 133.745 +G1 X3.426 Y1.872 133.746 +G0 X3.426 Y1.874 133.747 +G1 X0.576 Y1.874 133.748 +G0 X0.576 Y1.876 133.749 +G1 X3.426 Y1.876 133.750 +G0 X3.426 Y1.878 133.751 +G1 X0.576 Y1.878 133.752 +G0 X0.576 Y1.880 133.753 +G1 X3.426 Y1.880 133.754 +G0 X3.426 Y1.882 133.755 +G1 X0.576 Y1.882 133.756 +G0 X0.576 Y1.884 133.757 +G1 X3.426 Y1.884 133.758 +G0 X3.426 Y1.886 133.759 +G1 X0.576 Y1.886 133.760 +G0 X0.576 Y1.888 133.761 +G1 X3.426 Y1.888 133.762 +G0 X3.426 Y1.890 133.763 +G1 X0.576 Y1.890 133.764 +G0 X0.576 Y1.892 133.765 +G1 X3.426 Y1.892 133.766 +G0 X3.426 Y1.894 133.767 +G1 X0.576 Y1.894 133.768 +G0 X0.576 Y1.896 133.769 +G1 X3.426 Y1.896 133.770 +G0 X3.426 Y1.898 133.771 +G1 X0.576 Y1.898 133.772 +G0 X0.576 Y1.900 133.773 +G1 X3.426 Y1.900 133.774 +G0 X3.426 Y1.902 133.775 +G1 X0.576 Y1.902 133.776 +G0 X0.576 Y1.904 133.777 +G1 X3.426 Y1.904 133.778 +G0 X3.426 Y1.906 133.779 +G1 X0.576 Y1.906 133.780 +G0 X0.576 Y1.908 133.781 +G1 X3.426 Y1.908 133.782 +G0 X3.426 Y1.910 133.783 +G1 X0.576 Y1.910 133.784 +G0 X0.576 Y1.912 133.785 +G1 X3.426 Y1.912 133.786 +G0 X3.426 Y1.914 133.787 +G1 X0.576 Y1.914 133.788 +G0 X0.576 Y1.916 133.789 +G1 X3.426 Y1.916 133.790 +G0 X3.426 Y1.918 133.791 +G1 X0.576 Y1.918 133.792 +G0 X0.576 Y1.920 133.793 +G1 X3.426 Y1.920 133.794 +G0 X3.426 Y1.922 133.795 +G1 X0.576 Y1.922 133.796 +G0 X0.576 Y1.924 133.797 +G1 X3.426 Y1.924 133.798 +G0 X3.426 Y1.926 133.799 +G1 X0.576 Y1.926 133.800 +G0 X0.576 Y1.928 133.801 +G1 X3.426 Y1.928 133.802 +G0 X3.426 Y1.930 133.803 +G1 X0.576 Y1.930 133.804 +G0 X0.576 Y1.932 133.805 +G1 X3.426 Y1.932 133.806 +G0 X3.426 Y1.934 133.807 +G1 X0.576 Y1.934 133.808 +G0 X0.576 Y1.936 133.809 +G1 X3.426 Y1.936 133.810 +G0 X3.426 Y1.938 133.811 +G1 X0.578 Y1.938 133.812 +G0 X0.578 Y1.940 133.813 +G1 X3.424 Y1.940 133.814 +G0 X3.424 Y1.942 133.815 +G1 X0.578 Y1.942 133.816 +G0 X0.578 Y1.944 133.817 +G1 X3.424 Y1.944 133.818 +G0 X3.422 Y1.946 133.819 +G1 X0.580 Y1.946 133.820 +G0 X0.580 Y1.948 133.821 +G1 X3.422 Y1.948 133.822 +G0 X3.422 Y1.950 133.823 +G1 X0.582 Y1.950 133.824 +G0 X0.582 Y1.952 133.825 +G1 X3.420 Y1.952 133.826 +G0 X3.420 Y1.954 133.827 +G1 X0.584 Y1.954 133.828 +G0 X0.584 Y1.956 133.829 +G1 X3.418 Y1.956 133.830 +G0 X3.416 Y1.958 133.831 +G1 X0.586 Y1.958 133.832 +G0 X0.588 Y1.960 133.833 +G1 X3.416 Y1.960 133.834 +G0 X3.414 Y1.962 133.835 +G1 X0.588 Y1.962 133.836 +G0 X0.590 Y1.964 133.837 +G1 X3.412 Y1.964 133.838 +G0 X3.410 Y1.966 133.839 +G1 X0.592 Y1.966 133.840 +G0 X0.594 Y1.968 133.841 +G1 X3.408 Y1.968 133.842 +G0 X3.406 Y1.970 133.843 +G1 X0.598 Y1.970 133.844 +G0 X0.600 Y1.972 133.845 +G1 X3.402 Y1.972 133.846 +G0 X3.400 Y1.974 133.847 +G1 X0.602 Y1.974 133.848 +G0 X0.606 Y1.976 133.849 +G1 X3.396 Y1.976 133.850 +G0 X3.392 Y1.978 133.851 +G1 X0.610 Y1.978 133.852 +G0 X0.614 Y1.980 133.853 +G1 X3.388 Y1.980 133.854 +G0 X3.378 Y1.982 133.855 +G1 X0.624 Y1.982 133.856 +G0 X0.500 Y2.064 133.857 +G1 X3.500 Y2.064 133.858 +M63 P0 133.859 +M5 133.860 +M2
134.1 Binary file graster/test.png has changed
135.1 --- a/src/clojure/asm/AnnotationVisitor.java Sat Aug 21 06:25:44 2010 -0400 135.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 135.3 @@ -1,97 +0,0 @@ 135.4 -/*** 135.5 - * ASM: a very small and fast Java bytecode manipulation framework 135.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 135.7 - * All rights reserved. 135.8 - * 135.9 - * Redistribution and use in source and binary forms, with or without 135.10 - * modification, are permitted provided that the following conditions 135.11 - * are met: 135.12 - * 1. Redistributions of source code must retain the above copyright 135.13 - * notice, this list of conditions and the following disclaimer. 135.14 - * 2. Redistributions in binary form must reproduce the above copyright 135.15 - * notice, this list of conditions and the following disclaimer in the 135.16 - * documentation and/or other materials provided with the distribution. 135.17 - * 3. Neither the name of the copyright holders nor the names of its 135.18 - * contributors may be used to endorse or promote products derived from 135.19 - * this software without specific prior written permission. 135.20 - * 135.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 135.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 135.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 135.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 135.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 135.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 135.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 135.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 135.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 135.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 135.31 - * THE POSSIBILITY OF SUCH DAMAGE. 135.32 - */ 135.33 -package clojure.asm; 135.34 - 135.35 -/** 135.36 - * A visitor to visit a Java annotation. The methods of this interface must be 135.37 - * called in the following order: (<tt>visit<tt> | <tt>visitEnum<tt> | 135.38 - * <tt>visitAnnotation<tt> | <tt>visitArray<tt>)* <tt>visitEnd<tt>. 135.39 - * 135.40 - * @author Eric Bruneton 135.41 - * @author Eugene Kuleshov 135.42 - */ 135.43 -public interface AnnotationVisitor{ 135.44 - 135.45 -/** 135.46 - * Visits a primitive value of the annotation. 135.47 - * 135.48 - * @param name the value name. 135.49 - * @param value the actual value, whose type must be {@link Byte}, 135.50 - * {@link Boolean}, {@link Character}, {@link Short}, 135.51 - * {@link Integer}, {@link Long}, {@link Float}, {@link Double}, 135.52 - * {@link String} or {@link Type}. This value can also be an array 135.53 - * of byte, boolean, short, char, int, long, float or double values 135.54 - * (this is equivalent to using {@link #visitArray visitArray} and 135.55 - * visiting each array element in turn, but is more convenient). 135.56 - */ 135.57 -void visit(String name, Object value); 135.58 - 135.59 -/** 135.60 - * Visits an enumeration value of the annotation. 135.61 - * 135.62 - * @param name the value name. 135.63 - * @param desc the class descriptor of the enumeration class. 135.64 - * @param value the actual enumeration value. 135.65 - */ 135.66 -void visitEnum(String name, String desc, String value); 135.67 - 135.68 -/** 135.69 - * Visits a nested annotation value of the annotation. 135.70 - * 135.71 - * @param name the value name. 135.72 - * @param desc the class descriptor of the nested annotation class. 135.73 - * @return a visitor to visit the actual nested annotation value, or 135.74 - * <tt>null</tt> if this visitor is not interested in visiting 135.75 - * this nested annotation. <i>The nested annotation value must be 135.76 - * fully visited before calling other methods on this annotation 135.77 - * visitor</i>. 135.78 - */ 135.79 -AnnotationVisitor visitAnnotation(String name, String desc); 135.80 - 135.81 -/** 135.82 - * Visits an array value of the annotation. Note that arrays of primitive 135.83 - * types (such as byte, boolean, short, char, int, long, float or double) 135.84 - * can be passed as value to {@link #visit visit}. This is what 135.85 - * {@link ClassReader} does. 135.86 - * 135.87 - * @param name the value name. 135.88 - * @return a visitor to visit the actual array value elements, or 135.89 - * <tt>null</tt> if this visitor is not interested in visiting 135.90 - * these values. The 'name' parameters passed to the methods of this 135.91 - * visitor are ignored. <i>All the array values must be visited 135.92 - * before calling other methods on this annotation visitor</i>. 135.93 - */ 135.94 -AnnotationVisitor visitArray(String name); 135.95 - 135.96 -/** 135.97 - * Visits the end of the annotation. 135.98 - */ 135.99 -void visitEnd(); 135.100 -}
136.1 --- a/src/clojure/asm/AnnotationWriter.java Sat Aug 21 06:25:44 2010 -0400 136.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 136.3 @@ -1,357 +0,0 @@ 136.4 -/*** 136.5 - * ASM: a very small and fast Java bytecode manipulation framework 136.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 136.7 - * All rights reserved. 136.8 - * 136.9 - * Redistribution and use in source and binary forms, with or without 136.10 - * modification, are permitted provided that the following conditions 136.11 - * are met: 136.12 - * 1. Redistributions of source code must retain the above copyright 136.13 - * notice, this list of conditions and the following disclaimer. 136.14 - * 2. Redistributions in binary form must reproduce the above copyright 136.15 - * notice, this list of conditions and the following disclaimer in the 136.16 - * documentation and/or other materials provided with the distribution. 136.17 - * 3. Neither the name of the copyright holders nor the names of its 136.18 - * contributors may be used to endorse or promote products derived from 136.19 - * this software without specific prior written permission. 136.20 - * 136.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 136.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 136.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 136.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 136.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 136.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 136.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 136.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 136.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 136.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 136.31 - * THE POSSIBILITY OF SUCH DAMAGE. 136.32 - */ 136.33 -package clojure.asm; 136.34 - 136.35 -/** 136.36 - * An {@link AnnotationVisitor} that generates annotations in bytecode form. 136.37 - * 136.38 - * @author Eric Bruneton 136.39 - * @author Eugene Kuleshov 136.40 - */ 136.41 -final class AnnotationWriter implements AnnotationVisitor{ 136.42 - 136.43 -/** 136.44 - * The class writer to which this annotation must be added. 136.45 - */ 136.46 -private final ClassWriter cw; 136.47 - 136.48 -/** 136.49 - * The number of values in this annotation. 136.50 - */ 136.51 -private int size; 136.52 - 136.53 -/** 136.54 - * <tt>true<tt> if values are named, <tt>false</tt> otherwise. Annotation 136.55 - * writers used for annotation default and annotation arrays use unnamed 136.56 - * values. 136.57 - */ 136.58 -private final boolean named; 136.59 - 136.60 -/** 136.61 - * The annotation values in bytecode form. This byte vector only contains 136.62 - * the values themselves, i.e. the number of values must be stored as a 136.63 - * unsigned short just before these bytes. 136.64 - */ 136.65 -private final ByteVector bv; 136.66 - 136.67 -/** 136.68 - * The byte vector to be used to store the number of values of this 136.69 - * annotation. See {@link #bv}. 136.70 - */ 136.71 -private final ByteVector parent; 136.72 - 136.73 -/** 136.74 - * Where the number of values of this annotation must be stored in 136.75 - * {@link #parent}. 136.76 - */ 136.77 -private final int offset; 136.78 - 136.79 -/** 136.80 - * Next annotation writer. This field is used to store annotation lists. 136.81 - */ 136.82 -AnnotationWriter next; 136.83 - 136.84 -/** 136.85 - * Previous annotation writer. This field is used to store annotation lists. 136.86 - */ 136.87 -AnnotationWriter prev; 136.88 - 136.89 -// ------------------------------------------------------------------------ 136.90 -// Constructor 136.91 -// ------------------------------------------------------------------------ 136.92 - 136.93 -/** 136.94 - * Constructs a new {@link AnnotationWriter}. 136.95 - * 136.96 - * @param cw the class writer to which this annotation must be added. 136.97 - * @param named <tt>true<tt> if values are named, <tt>false</tt> otherwise. 136.98 - * @param bv where the annotation values must be stored. 136.99 - * @param parent where the number of annotation values must be stored. 136.100 - * @param offset where in <tt>parent</tt> the number of annotation values must 136.101 - * be stored. 136.102 - */ 136.103 -AnnotationWriter( 136.104 - final ClassWriter cw, 136.105 - final boolean named, 136.106 - final ByteVector bv, 136.107 - final ByteVector parent, 136.108 - final int offset){ 136.109 - this.cw = cw; 136.110 - this.named = named; 136.111 - this.bv = bv; 136.112 - this.parent = parent; 136.113 - this.offset = offset; 136.114 -} 136.115 - 136.116 -// ------------------------------------------------------------------------ 136.117 -// Implementation of the AnnotationVisitor interface 136.118 -// ------------------------------------------------------------------------ 136.119 - 136.120 -public void visit(final String name, final Object value){ 136.121 - ++size; 136.122 - if(named) 136.123 - { 136.124 - bv.putShort(cw.newUTF8(name)); 136.125 - } 136.126 - if(value instanceof String) 136.127 - { 136.128 - bv.put12('s', cw.newUTF8((String) value)); 136.129 - } 136.130 - else if(value instanceof Byte) 136.131 - { 136.132 - bv.put12('B', cw.newInteger(((Byte) value).byteValue()).index); 136.133 - } 136.134 - else if(value instanceof Boolean) 136.135 - { 136.136 - int v = ((Boolean) value).booleanValue() ? 1 : 0; 136.137 - bv.put12('Z', cw.newInteger(v).index); 136.138 - } 136.139 - else if(value instanceof Character) 136.140 - { 136.141 - bv.put12('C', cw.newInteger(((Character) value).charValue()).index); 136.142 - } 136.143 - else if(value instanceof Short) 136.144 - { 136.145 - bv.put12('S', cw.newInteger(((Short) value).shortValue()).index); 136.146 - } 136.147 - else if(value instanceof Type) 136.148 - { 136.149 - bv.put12('c', cw.newUTF8(((Type) value).getDescriptor())); 136.150 - } 136.151 - else if(value instanceof byte[]) 136.152 - { 136.153 - byte[] v = (byte[]) value; 136.154 - bv.put12('[', v.length); 136.155 - for(int i = 0; i < v.length; i++) 136.156 - { 136.157 - bv.put12('B', cw.newInteger(v[i]).index); 136.158 - } 136.159 - } 136.160 - else if(value instanceof boolean[]) 136.161 - { 136.162 - boolean[] v = (boolean[]) value; 136.163 - bv.put12('[', v.length); 136.164 - for(int i = 0; i < v.length; i++) 136.165 - { 136.166 - bv.put12('Z', cw.newInteger(v[i] ? 1 : 0).index); 136.167 - } 136.168 - } 136.169 - else if(value instanceof short[]) 136.170 - { 136.171 - short[] v = (short[]) value; 136.172 - bv.put12('[', v.length); 136.173 - for(int i = 0; i < v.length; i++) 136.174 - { 136.175 - bv.put12('S', cw.newInteger(v[i]).index); 136.176 - } 136.177 - } 136.178 - else if(value instanceof char[]) 136.179 - { 136.180 - char[] v = (char[]) value; 136.181 - bv.put12('[', v.length); 136.182 - for(int i = 0; i < v.length; i++) 136.183 - { 136.184 - bv.put12('C', cw.newInteger(v[i]).index); 136.185 - } 136.186 - } 136.187 - else if(value instanceof int[]) 136.188 - { 136.189 - int[] v = (int[]) value; 136.190 - bv.put12('[', v.length); 136.191 - for(int i = 0; i < v.length; i++) 136.192 - { 136.193 - bv.put12('I', cw.newInteger(v[i]).index); 136.194 - } 136.195 - } 136.196 - else if(value instanceof long[]) 136.197 - { 136.198 - long[] v = (long[]) value; 136.199 - bv.put12('[', v.length); 136.200 - for(int i = 0; i < v.length; i++) 136.201 - { 136.202 - bv.put12('J', cw.newLong(v[i]).index); 136.203 - } 136.204 - } 136.205 - else if(value instanceof float[]) 136.206 - { 136.207 - float[] v = (float[]) value; 136.208 - bv.put12('[', v.length); 136.209 - for(int i = 0; i < v.length; i++) 136.210 - { 136.211 - bv.put12('F', cw.newFloat(v[i]).index); 136.212 - } 136.213 - } 136.214 - else if(value instanceof double[]) 136.215 - { 136.216 - double[] v = (double[]) value; 136.217 - bv.put12('[', v.length); 136.218 - for(int i = 0; i < v.length; i++) 136.219 - { 136.220 - bv.put12('D', cw.newDouble(v[i]).index); 136.221 - } 136.222 - } 136.223 - else 136.224 - { 136.225 - Item i = cw.newConstItem(value); 136.226 - bv.put12(".s.IFJDCS".charAt(i.type), i.index); 136.227 - } 136.228 -} 136.229 - 136.230 -public void visitEnum( 136.231 - final String name, 136.232 - final String desc, 136.233 - final String value){ 136.234 - ++size; 136.235 - if(named) 136.236 - { 136.237 - bv.putShort(cw.newUTF8(name)); 136.238 - } 136.239 - bv.put12('e', cw.newUTF8(desc)).putShort(cw.newUTF8(value)); 136.240 -} 136.241 - 136.242 -public AnnotationVisitor visitAnnotation( 136.243 - final String name, 136.244 - final String desc){ 136.245 - ++size; 136.246 - if(named) 136.247 - { 136.248 - bv.putShort(cw.newUTF8(name)); 136.249 - } 136.250 - // write tag and type, and reserve space for values count 136.251 - bv.put12('@', cw.newUTF8(desc)).putShort(0); 136.252 - return new AnnotationWriter(cw, true, bv, bv, bv.length - 2); 136.253 -} 136.254 - 136.255 -public AnnotationVisitor visitArray(final String name){ 136.256 - ++size; 136.257 - if(named) 136.258 - { 136.259 - bv.putShort(cw.newUTF8(name)); 136.260 - } 136.261 - // write tag, and reserve space for array size 136.262 - bv.put12('[', 0); 136.263 - return new AnnotationWriter(cw, false, bv, bv, bv.length - 2); 136.264 -} 136.265 - 136.266 -public void visitEnd(){ 136.267 - if(parent != null) 136.268 - { 136.269 - byte[] data = parent.data; 136.270 - data[offset] = (byte) (size >>> 8); 136.271 - data[offset + 1] = (byte) size; 136.272 - } 136.273 -} 136.274 - 136.275 -// ------------------------------------------------------------------------ 136.276 -// Utility methods 136.277 -// ------------------------------------------------------------------------ 136.278 - 136.279 -/** 136.280 - * Returns the size of this annotation writer list. 136.281 - * 136.282 - * @return the size of this annotation writer list. 136.283 - */ 136.284 -int getSize(){ 136.285 - int size = 0; 136.286 - AnnotationWriter aw = this; 136.287 - while(aw != null) 136.288 - { 136.289 - size += aw.bv.length; 136.290 - aw = aw.next; 136.291 - } 136.292 - return size; 136.293 -} 136.294 - 136.295 -/** 136.296 - * Puts the annotations of this annotation writer list into the given byte 136.297 - * vector. 136.298 - * 136.299 - * @param out where the annotations must be put. 136.300 - */ 136.301 -void put(final ByteVector out){ 136.302 - int n = 0; 136.303 - int size = 2; 136.304 - AnnotationWriter aw = this; 136.305 - AnnotationWriter last = null; 136.306 - while(aw != null) 136.307 - { 136.308 - ++n; 136.309 - size += aw.bv.length; 136.310 - aw.visitEnd(); // in case user forgot to call visitEnd 136.311 - aw.prev = last; 136.312 - last = aw; 136.313 - aw = aw.next; 136.314 - } 136.315 - out.putInt(size); 136.316 - out.putShort(n); 136.317 - aw = last; 136.318 - while(aw != null) 136.319 - { 136.320 - out.putByteArray(aw.bv.data, 0, aw.bv.length); 136.321 - aw = aw.prev; 136.322 - } 136.323 -} 136.324 - 136.325 -/** 136.326 - * Puts the given annotation lists into the given byte vector. 136.327 - * 136.328 - * @param panns an array of annotation writer lists. 136.329 - * @param out where the annotations must be put. 136.330 - */ 136.331 -static void put(final AnnotationWriter[] panns, final ByteVector out){ 136.332 - int size = 1 + 2 * panns.length; 136.333 - for(int i = 0; i < panns.length; ++i) 136.334 - { 136.335 - size += panns[i] == null ? 0 : panns[i].getSize(); 136.336 - } 136.337 - out.putInt(size).putByte(panns.length); 136.338 - for(int i = 0; i < panns.length; ++i) 136.339 - { 136.340 - AnnotationWriter aw = panns[i]; 136.341 - AnnotationWriter last = null; 136.342 - int n = 0; 136.343 - while(aw != null) 136.344 - { 136.345 - ++n; 136.346 - aw.visitEnd(); // in case user forgot to call visitEnd 136.347 - aw.prev = last; 136.348 - last = aw; 136.349 - aw = aw.next; 136.350 - } 136.351 - out.putShort(n); 136.352 - aw = last; 136.353 - while(aw != null) 136.354 - { 136.355 - out.putByteArray(aw.bv.data, 0, aw.bv.length); 136.356 - aw = aw.prev; 136.357 - } 136.358 - } 136.359 -} 136.360 -}
137.1 --- a/src/clojure/asm/Attribute.java Sat Aug 21 06:25:44 2010 -0400 137.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 137.3 @@ -1,253 +0,0 @@ 137.4 -/*** 137.5 - * ASM: a very small and fast Java bytecode manipulation framework 137.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 137.7 - * All rights reserved. 137.8 - * 137.9 - * Redistribution and use in source and binary forms, with or without 137.10 - * modification, are permitted provided that the following conditions 137.11 - * are met: 137.12 - * 1. Redistributions of source code must retain the above copyright 137.13 - * notice, this list of conditions and the following disclaimer. 137.14 - * 2. Redistributions in binary form must reproduce the above copyright 137.15 - * notice, this list of conditions and the following disclaimer in the 137.16 - * documentation and/or other materials provided with the distribution. 137.17 - * 3. Neither the name of the copyright holders nor the names of its 137.18 - * contributors may be used to endorse or promote products derived from 137.19 - * this software without specific prior written permission. 137.20 - * 137.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 137.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 137.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 137.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 137.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 137.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 137.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 137.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 137.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 137.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 137.31 - * THE POSSIBILITY OF SUCH DAMAGE. 137.32 - */ 137.33 -package clojure.asm; 137.34 - 137.35 -/** 137.36 - * A non standard class, field, method or code attribute. 137.37 - * 137.38 - * @author Eric Bruneton 137.39 - * @author Eugene Kuleshov 137.40 - */ 137.41 -public class Attribute{ 137.42 - 137.43 -/** 137.44 - * The type of this attribute. 137.45 - */ 137.46 -public final String type; 137.47 - 137.48 -/** 137.49 - * The raw value of this attribute, used only for unknown attributes. 137.50 - */ 137.51 -byte[] value; 137.52 - 137.53 -/** 137.54 - * The next attribute in this attribute list. May be <tt>null</tt>. 137.55 - */ 137.56 -Attribute next; 137.57 - 137.58 -/** 137.59 - * Constructs a new empty attribute. 137.60 - * 137.61 - * @param type the type of the attribute. 137.62 - */ 137.63 -protected Attribute(final String type){ 137.64 - this.type = type; 137.65 -} 137.66 - 137.67 -/** 137.68 - * Returns <tt>true</tt> if this type of attribute is unknown. The default 137.69 - * implementation of this method always returns <tt>true</tt>. 137.70 - * 137.71 - * @return <tt>true</tt> if this type of attribute is unknown. 137.72 - */ 137.73 -public boolean isUnknown(){ 137.74 - return true; 137.75 -} 137.76 - 137.77 -/** 137.78 - * Returns <tt>true</tt> if this type of attribute is a code attribute. 137.79 - * 137.80 - * @return <tt>true</tt> if this type of attribute is a code attribute. 137.81 - */ 137.82 -public boolean isCodeAttribute(){ 137.83 - return false; 137.84 -} 137.85 - 137.86 -/** 137.87 - * Returns the labels corresponding to this attribute. 137.88 - * 137.89 - * @return the labels corresponding to this attribute, or <tt>null</tt> if 137.90 - * this attribute is not a code attribute that contains labels. 137.91 - */ 137.92 -protected Label[] getLabels(){ 137.93 - return null; 137.94 -} 137.95 - 137.96 -/** 137.97 - * Reads a {@link #type type} attribute. This method must return a <i>new</i> 137.98 - * {@link Attribute} object, of type {@link #type type}, corresponding to 137.99 - * the <tt>len</tt> bytes starting at the given offset, in the given class 137.100 - * reader. 137.101 - * 137.102 - * @param cr the class that contains the attribute to be read. 137.103 - * @param off index of the first byte of the attribute's content in {@link 137.104 - * ClassReader#b cr.b}. The 6 attribute header bytes, containing the 137.105 - * type and the length of the attribute, are not taken into account 137.106 - * here. 137.107 - * @param len the length of the attribute's content. 137.108 - * @param buf buffer to be used to call 137.109 - * {@link ClassReader#readUTF8 readUTF8}, 137.110 - * {@link ClassReader#readClass(int,char[]) readClass} or 137.111 - * {@link ClassReader#readConst readConst}. 137.112 - * @param codeOff index of the first byte of code's attribute content in 137.113 - * {@link ClassReader#b cr.b}, or -1 if the attribute to be read is 137.114 - * not a code attribute. The 6 attribute header bytes, containing the 137.115 - * type and the length of the attribute, are not taken into account 137.116 - * here. 137.117 - * @param labels the labels of the method's code, or <tt>null</tt> if the 137.118 - * attribute to be read is not a code attribute. 137.119 - * @return a <i>new</i> {@link Attribute} object corresponding to the given 137.120 - * bytes. 137.121 - */ 137.122 -protected Attribute read( 137.123 - final ClassReader cr, 137.124 - final int off, 137.125 - final int len, 137.126 - final char[] buf, 137.127 - final int codeOff, 137.128 - final Label[] labels){ 137.129 - Attribute attr = new Attribute(type); 137.130 - attr.value = new byte[len]; 137.131 - System.arraycopy(cr.b, off, attr.value, 0, len); 137.132 - return attr; 137.133 -} 137.134 - 137.135 -/** 137.136 - * Returns the byte array form of this attribute. 137.137 - * 137.138 - * @param cw the class to which this attribute must be added. This parameter 137.139 - * can be used to add to the constant pool of this class the items 137.140 - * that corresponds to this attribute. 137.141 - * @param code the bytecode of the method corresponding to this code 137.142 - * attribute, or <tt>null</tt> if this attribute is not a code 137.143 - * attributes. 137.144 - * @param len the length of the bytecode of the method corresponding to this 137.145 - * code attribute, or <tt>null</tt> if this attribute is not a code 137.146 - * attribute. 137.147 - * @param maxStack the maximum stack size of the method corresponding to 137.148 - * this code attribute, or -1 if this attribute is not a code 137.149 - * attribute. 137.150 - * @param maxLocals the maximum number of local variables of the method 137.151 - * corresponding to this code attribute, or -1 if this attribute is 137.152 - * not a code attribute. 137.153 - * @return the byte array form of this attribute. 137.154 - */ 137.155 -protected ByteVector write( 137.156 - final ClassWriter cw, 137.157 - final byte[] code, 137.158 - final int len, 137.159 - final int maxStack, 137.160 - final int maxLocals){ 137.161 - ByteVector v = new ByteVector(); 137.162 - v.data = value; 137.163 - v.length = value.length; 137.164 - return v; 137.165 -} 137.166 - 137.167 -/** 137.168 - * Returns the length of the attribute list that begins with this attribute. 137.169 - * 137.170 - * @return the length of the attribute list that begins with this attribute. 137.171 - */ 137.172 -final int getCount(){ 137.173 - int count = 0; 137.174 - Attribute attr = this; 137.175 - while(attr != null) 137.176 - { 137.177 - count += 1; 137.178 - attr = attr.next; 137.179 - } 137.180 - return count; 137.181 -} 137.182 - 137.183 -/** 137.184 - * Returns the size of all the attributes in this attribute list. 137.185 - * 137.186 - * @param cw the class writer to be used to convert the attributes into byte 137.187 - * arrays, with the {@link #write write} method. 137.188 - * @param code the bytecode of the method corresponding to these code 137.189 - * attributes, or <tt>null</tt> if these attributes are not code 137.190 - * attributes. 137.191 - * @param len the length of the bytecode of the method corresponding to 137.192 - * these code attributes, or <tt>null</tt> if these attributes are 137.193 - * not code attributes. 137.194 - * @param maxStack the maximum stack size of the method corresponding to 137.195 - * these code attributes, or -1 if these attributes are not code 137.196 - * attributes. 137.197 - * @param maxLocals the maximum number of local variables of the method 137.198 - * corresponding to these code attributes, or -1 if these attributes 137.199 - * are not code attributes. 137.200 - * @return the size of all the attributes in this attribute list. This size 137.201 - * includes the size of the attribute headers. 137.202 - */ 137.203 -final int getSize( 137.204 - final ClassWriter cw, 137.205 - final byte[] code, 137.206 - final int len, 137.207 - final int maxStack, 137.208 - final int maxLocals){ 137.209 - Attribute attr = this; 137.210 - int size = 0; 137.211 - while(attr != null) 137.212 - { 137.213 - cw.newUTF8(attr.type); 137.214 - size += attr.write(cw, code, len, maxStack, maxLocals).length + 6; 137.215 - attr = attr.next; 137.216 - } 137.217 - return size; 137.218 -} 137.219 - 137.220 -/** 137.221 - * Writes all the attributes of this attribute list in the given byte 137.222 - * vector. 137.223 - * 137.224 - * @param cw the class writer to be used to convert the attributes into byte 137.225 - * arrays, with the {@link #write write} method. 137.226 - * @param code the bytecode of the method corresponding to these code 137.227 - * attributes, or <tt>null</tt> if these attributes are not code 137.228 - * attributes. 137.229 - * @param len the length of the bytecode of the method corresponding to 137.230 - * these code attributes, or <tt>null</tt> if these attributes are 137.231 - * not code attributes. 137.232 - * @param maxStack the maximum stack size of the method corresponding to 137.233 - * these code attributes, or -1 if these attributes are not code 137.234 - * attributes. 137.235 - * @param maxLocals the maximum number of local variables of the method 137.236 - * corresponding to these code attributes, or -1 if these attributes 137.237 - * are not code attributes. 137.238 - * @param out where the attributes must be written. 137.239 - */ 137.240 -final void put( 137.241 - final ClassWriter cw, 137.242 - final byte[] code, 137.243 - final int len, 137.244 - final int maxStack, 137.245 - final int maxLocals, 137.246 - final ByteVector out){ 137.247 - Attribute attr = this; 137.248 - while(attr != null) 137.249 - { 137.250 - ByteVector b = attr.write(cw, code, len, maxStack, maxLocals); 137.251 - out.putShort(cw.newUTF8(attr.type)).putInt(b.length); 137.252 - out.putByteArray(b.data, 0, b.length); 137.253 - attr = attr.next; 137.254 - } 137.255 -} 137.256 -}
138.1 --- a/src/clojure/asm/ByteVector.java Sat Aug 21 06:25:44 2010 -0400 138.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 138.3 @@ -1,318 +0,0 @@ 138.4 -/*** 138.5 - * ASM: a very small and fast Java bytecode manipulation framework 138.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 138.7 - * All rights reserved. 138.8 - * 138.9 - * Redistribution and use in source and binary forms, with or without 138.10 - * modification, are permitted provided that the following conditions 138.11 - * are met: 138.12 - * 1. Redistributions of source code must retain the above copyright 138.13 - * notice, this list of conditions and the following disclaimer. 138.14 - * 2. Redistributions in binary form must reproduce the above copyright 138.15 - * notice, this list of conditions and the following disclaimer in the 138.16 - * documentation and/or other materials provided with the distribution. 138.17 - * 3. Neither the name of the copyright holders nor the names of its 138.18 - * contributors may be used to endorse or promote products derived from 138.19 - * this software without specific prior written permission. 138.20 - * 138.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 138.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 138.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 138.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 138.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 138.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 138.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 138.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 138.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 138.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 138.31 - * THE POSSIBILITY OF SUCH DAMAGE. 138.32 - */ 138.33 -package clojure.asm; 138.34 - 138.35 -/** 138.36 - * A dynamically extensible vector of bytes. This class is roughly equivalent to 138.37 - * a DataOutputStream on top of a ByteArrayOutputStream, but is more efficient. 138.38 - * 138.39 - * @author Eric Bruneton 138.40 - */ 138.41 -public class ByteVector{ 138.42 - 138.43 -/** 138.44 - * The content of this vector. 138.45 - */ 138.46 -byte[] data; 138.47 - 138.48 -/** 138.49 - * Actual number of bytes in this vector. 138.50 - */ 138.51 -int length; 138.52 - 138.53 -/** 138.54 - * Constructs a new {@link ByteVector ByteVector} with a default initial 138.55 - * size. 138.56 - */ 138.57 -public ByteVector(){ 138.58 - data = new byte[64]; 138.59 -} 138.60 - 138.61 -/** 138.62 - * Constructs a new {@link ByteVector ByteVector} with the given initial 138.63 - * size. 138.64 - * 138.65 - * @param initialSize the initial size of the byte vector to be constructed. 138.66 - */ 138.67 -public ByteVector(final int initialSize){ 138.68 - data = new byte[initialSize]; 138.69 -} 138.70 - 138.71 -/** 138.72 - * Puts a byte into this byte vector. The byte vector is automatically 138.73 - * enlarged if necessary. 138.74 - * 138.75 - * @param b a byte. 138.76 - * @return this byte vector. 138.77 - */ 138.78 -public ByteVector putByte(final int b){ 138.79 - int length = this.length; 138.80 - if(length + 1 > data.length) 138.81 - { 138.82 - enlarge(1); 138.83 - } 138.84 - data[length++] = (byte) b; 138.85 - this.length = length; 138.86 - return this; 138.87 -} 138.88 - 138.89 -/** 138.90 - * Puts two bytes into this byte vector. The byte vector is automatically 138.91 - * enlarged if necessary. 138.92 - * 138.93 - * @param b1 a byte. 138.94 - * @param b2 another byte. 138.95 - * @return this byte vector. 138.96 - */ 138.97 -ByteVector put11(final int b1, final int b2){ 138.98 - int length = this.length; 138.99 - if(length + 2 > data.length) 138.100 - { 138.101 - enlarge(2); 138.102 - } 138.103 - byte[] data = this.data; 138.104 - data[length++] = (byte) b1; 138.105 - data[length++] = (byte) b2; 138.106 - this.length = length; 138.107 - return this; 138.108 -} 138.109 - 138.110 -/** 138.111 - * Puts a short into this byte vector. The byte vector is automatically 138.112 - * enlarged if necessary. 138.113 - * 138.114 - * @param s a short. 138.115 - * @return this byte vector. 138.116 - */ 138.117 -public ByteVector putShort(final int s){ 138.118 - int length = this.length; 138.119 - if(length + 2 > data.length) 138.120 - { 138.121 - enlarge(2); 138.122 - } 138.123 - byte[] data = this.data; 138.124 - data[length++] = (byte) (s >>> 8); 138.125 - data[length++] = (byte) s; 138.126 - this.length = length; 138.127 - return this; 138.128 -} 138.129 - 138.130 -/** 138.131 - * Puts a byte and a short into this byte vector. The byte vector is 138.132 - * automatically enlarged if necessary. 138.133 - * 138.134 - * @param b a byte. 138.135 - * @param s a short. 138.136 - * @return this byte vector. 138.137 - */ 138.138 -ByteVector put12(final int b, final int s){ 138.139 - int length = this.length; 138.140 - if(length + 3 > data.length) 138.141 - { 138.142 - enlarge(3); 138.143 - } 138.144 - byte[] data = this.data; 138.145 - data[length++] = (byte) b; 138.146 - data[length++] = (byte) (s >>> 8); 138.147 - data[length++] = (byte) s; 138.148 - this.length = length; 138.149 - return this; 138.150 -} 138.151 - 138.152 -/** 138.153 - * Puts an int into this byte vector. The byte vector is automatically 138.154 - * enlarged if necessary. 138.155 - * 138.156 - * @param i an int. 138.157 - * @return this byte vector. 138.158 - */ 138.159 -public ByteVector putInt(final int i){ 138.160 - int length = this.length; 138.161 - if(length + 4 > data.length) 138.162 - { 138.163 - enlarge(4); 138.164 - } 138.165 - byte[] data = this.data; 138.166 - data[length++] = (byte) (i >>> 24); 138.167 - data[length++] = (byte) (i >>> 16); 138.168 - data[length++] = (byte) (i >>> 8); 138.169 - data[length++] = (byte) i; 138.170 - this.length = length; 138.171 - return this; 138.172 -} 138.173 - 138.174 -/** 138.175 - * Puts a long into this byte vector. The byte vector is automatically 138.176 - * enlarged if necessary. 138.177 - * 138.178 - * @param l a long. 138.179 - * @return this byte vector. 138.180 - */ 138.181 -public ByteVector putLong(final long l){ 138.182 - int length = this.length; 138.183 - if(length + 8 > data.length) 138.184 - { 138.185 - enlarge(8); 138.186 - } 138.187 - byte[] data = this.data; 138.188 - int i = (int) (l >>> 32); 138.189 - data[length++] = (byte) (i >>> 24); 138.190 - data[length++] = (byte) (i >>> 16); 138.191 - data[length++] = (byte) (i >>> 8); 138.192 - data[length++] = (byte) i; 138.193 - i = (int) l; 138.194 - data[length++] = (byte) (i >>> 24); 138.195 - data[length++] = (byte) (i >>> 16); 138.196 - data[length++] = (byte) (i >>> 8); 138.197 - data[length++] = (byte) i; 138.198 - this.length = length; 138.199 - return this; 138.200 -} 138.201 - 138.202 -/** 138.203 - * Puts an UTF8 string into this byte vector. The byte vector is 138.204 - * automatically enlarged if necessary. 138.205 - * 138.206 - * @param s a String. 138.207 - * @return this byte vector. 138.208 - */ 138.209 -public ByteVector putUTF8(final String s){ 138.210 - int charLength = s.length(); 138.211 - if(length + 2 + charLength > data.length) 138.212 - { 138.213 - enlarge(2 + charLength); 138.214 - } 138.215 - int len = length; 138.216 - byte[] data = this.data; 138.217 - // optimistic algorithm: instead of computing the byte length and then 138.218 - // serializing the string (which requires two loops), we assume the byte 138.219 - // length is equal to char length (which is the most frequent case), and 138.220 - // we start serializing the string right away. During the serialization, 138.221 - // if we find that this assumption is wrong, we continue with the 138.222 - // general method. 138.223 - data[len++] = (byte) (charLength >>> 8); 138.224 - data[len++] = (byte) charLength; 138.225 - for(int i = 0; i < charLength; ++i) 138.226 - { 138.227 - char c = s.charAt(i); 138.228 - if(c >= '\001' && c <= '\177') 138.229 - { 138.230 - data[len++] = (byte) c; 138.231 - } 138.232 - else 138.233 - { 138.234 - int byteLength = i; 138.235 - for(int j = i; j < charLength; ++j) 138.236 - { 138.237 - c = s.charAt(j); 138.238 - if(c >= '\001' && c <= '\177') 138.239 - { 138.240 - byteLength++; 138.241 - } 138.242 - else if(c > '\u07FF') 138.243 - { 138.244 - byteLength += 3; 138.245 - } 138.246 - else 138.247 - { 138.248 - byteLength += 2; 138.249 - } 138.250 - } 138.251 - data[length] = (byte) (byteLength >>> 8); 138.252 - data[length + 1] = (byte) byteLength; 138.253 - if(length + 2 + byteLength > data.length) 138.254 - { 138.255 - length = len; 138.256 - enlarge(2 + byteLength); 138.257 - data = this.data; 138.258 - } 138.259 - for(int j = i; j < charLength; ++j) 138.260 - { 138.261 - c = s.charAt(j); 138.262 - if(c >= '\001' && c <= '\177') 138.263 - { 138.264 - data[len++] = (byte) c; 138.265 - } 138.266 - else if(c > '\u07FF') 138.267 - { 138.268 - data[len++] = (byte) (0xE0 | c >> 12 & 0xF); 138.269 - data[len++] = (byte) (0x80 | c >> 6 & 0x3F); 138.270 - data[len++] = (byte) (0x80 | c & 0x3F); 138.271 - } 138.272 - else 138.273 - { 138.274 - data[len++] = (byte) (0xC0 | c >> 6 & 0x1F); 138.275 - data[len++] = (byte) (0x80 | c & 0x3F); 138.276 - } 138.277 - } 138.278 - break; 138.279 - } 138.280 - } 138.281 - length = len; 138.282 - return this; 138.283 -} 138.284 - 138.285 -/** 138.286 - * Puts an array of bytes into this byte vector. The byte vector is 138.287 - * automatically enlarged if necessary. 138.288 - * 138.289 - * @param b an array of bytes. May be <tt>null</tt> to put <tt>len</tt> 138.290 - * null bytes into this byte vector. 138.291 - * @param off index of the fist byte of b that must be copied. 138.292 - * @param len number of bytes of b that must be copied. 138.293 - * @return this byte vector. 138.294 - */ 138.295 -public ByteVector putByteArray(final byte[] b, final int off, final int len){ 138.296 - if(length + len > data.length) 138.297 - { 138.298 - enlarge(len); 138.299 - } 138.300 - if(b != null) 138.301 - { 138.302 - System.arraycopy(b, off, data, length, len); 138.303 - } 138.304 - length += len; 138.305 - return this; 138.306 -} 138.307 - 138.308 -/** 138.309 - * Enlarge this byte vector so that it can receive n more bytes. 138.310 - * 138.311 - * @param size number of additional bytes that this byte vector should be 138.312 - * able to receive. 138.313 - */ 138.314 -private void enlarge(final int size){ 138.315 - int length1 = 2 * data.length; 138.316 - int length2 = length + size; 138.317 - byte[] newData = new byte[length1 > length2 ? length1 : length2]; 138.318 - System.arraycopy(data, 0, newData, 0, length); 138.319 - data = newData; 138.320 -} 138.321 -}
139.1 --- a/src/clojure/asm/ClassAdapter.java Sat Aug 21 06:25:44 2010 -0400 139.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 139.3 @@ -1,115 +0,0 @@ 139.4 -/*** 139.5 - * ASM: a very small and fast Java bytecode manipulation framework 139.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 139.7 - * All rights reserved. 139.8 - * 139.9 - * Redistribution and use in source and binary forms, with or without 139.10 - * modification, are permitted provided that the following conditions 139.11 - * are met: 139.12 - * 1. Redistributions of source code must retain the above copyright 139.13 - * notice, this list of conditions and the following disclaimer. 139.14 - * 2. Redistributions in binary form must reproduce the above copyright 139.15 - * notice, this list of conditions and the following disclaimer in the 139.16 - * documentation and/or other materials provided with the distribution. 139.17 - * 3. Neither the name of the copyright holders nor the names of its 139.18 - * contributors may be used to endorse or promote products derived from 139.19 - * this software without specific prior written permission. 139.20 - * 139.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 139.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 139.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 139.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 139.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 139.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 139.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 139.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 139.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 139.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 139.31 - * THE POSSIBILITY OF SUCH DAMAGE. 139.32 - */ 139.33 -package clojure.asm; 139.34 - 139.35 -/** 139.36 - * An empty {@link ClassVisitor} that delegates to another {@link ClassVisitor}. 139.37 - * This class can be used as a super class to quickly implement usefull class 139.38 - * adapter classes, just by overriding the necessary methods. 139.39 - * 139.40 - * @author Eric Bruneton 139.41 - */ 139.42 -public class ClassAdapter implements ClassVisitor{ 139.43 - 139.44 -/** 139.45 - * The {@link ClassVisitor} to which this adapter delegates calls. 139.46 - */ 139.47 -protected ClassVisitor cv; 139.48 - 139.49 -/** 139.50 - * Constructs a new {@link ClassAdapter} object. 139.51 - * 139.52 - * @param cv the class visitor to which this adapter must delegate calls. 139.53 - */ 139.54 -public ClassAdapter(final ClassVisitor cv){ 139.55 - this.cv = cv; 139.56 -} 139.57 - 139.58 -public void visit( 139.59 - final int version, 139.60 - final int access, 139.61 - final String name, 139.62 - final String signature, 139.63 - final String superName, 139.64 - final String[] interfaces){ 139.65 - cv.visit(version, access, name, signature, superName, interfaces); 139.66 -} 139.67 - 139.68 -public void visitSource(final String source, final String debug){ 139.69 - cv.visitSource(source, debug); 139.70 -} 139.71 - 139.72 -public void visitOuterClass( 139.73 - final String owner, 139.74 - final String name, 139.75 - final String desc){ 139.76 - cv.visitOuterClass(owner, name, desc); 139.77 -} 139.78 - 139.79 -public AnnotationVisitor visitAnnotation( 139.80 - final String desc, 139.81 - final boolean visible){ 139.82 - return cv.visitAnnotation(desc, visible); 139.83 -} 139.84 - 139.85 -public void visitAttribute(final Attribute attr){ 139.86 - cv.visitAttribute(attr); 139.87 -} 139.88 - 139.89 -public void visitInnerClass( 139.90 - final String name, 139.91 - final String outerName, 139.92 - final String innerName, 139.93 - final int access){ 139.94 - cv.visitInnerClass(name, outerName, innerName, access); 139.95 -} 139.96 - 139.97 -public FieldVisitor visitField( 139.98 - final int access, 139.99 - final String name, 139.100 - final String desc, 139.101 - final String signature, 139.102 - final Object value){ 139.103 - return cv.visitField(access, name, desc, signature, value); 139.104 -} 139.105 - 139.106 -public MethodVisitor visitMethod( 139.107 - final int access, 139.108 - final String name, 139.109 - final String desc, 139.110 - final String signature, 139.111 - final String[] exceptions){ 139.112 - return cv.visitMethod(access, name, desc, signature, exceptions); 139.113 -} 139.114 - 139.115 -public void visitEnd(){ 139.116 - cv.visitEnd(); 139.117 -} 139.118 -}
140.1 --- a/src/clojure/asm/ClassReader.java Sat Aug 21 06:25:44 2010 -0400 140.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 140.3 @@ -1,2224 +0,0 @@ 140.4 -/*** 140.5 - * ASM: a very small and fast Java bytecode manipulation framework 140.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 140.7 - * All rights reserved. 140.8 - * 140.9 - * Redistribution and use in source and binary forms, with or without 140.10 - * modification, are permitted provided that the following conditions 140.11 - * are met: 140.12 - * 1. Redistributions of source code must retain the above copyright 140.13 - * notice, this list of conditions and the following disclaimer. 140.14 - * 2. Redistributions in binary form must reproduce the above copyright 140.15 - * notice, this list of conditions and the following disclaimer in the 140.16 - * documentation and/or other materials provided with the distribution. 140.17 - * 3. Neither the name of the copyright holders nor the names of its 140.18 - * contributors may be used to endorse or promote products derived from 140.19 - * this software without specific prior written permission. 140.20 - * 140.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 140.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 140.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 140.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 140.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 140.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 140.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 140.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 140.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 140.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 140.31 - * THE POSSIBILITY OF SUCH DAMAGE. 140.32 - */ 140.33 -package clojure.asm; 140.34 - 140.35 -import java.io.InputStream; 140.36 -import java.io.IOException; 140.37 - 140.38 -/** 140.39 - * A Java class parser to make a {@link ClassVisitor} visit an existing class. 140.40 - * This class parses a byte array conforming to the Java class file format and 140.41 - * calls the appropriate visit methods of a given class visitor for each field, 140.42 - * method and bytecode instruction encountered. 140.43 - * 140.44 - * @author Eric Bruneton 140.45 - * @author Eugene Kuleshov 140.46 - */ 140.47 -public class ClassReader{ 140.48 - 140.49 -/** 140.50 - * Flag to skip method code. If this class is set <code>CODE</code> 140.51 - * attribute won't be visited. This can be used, for example, to retrieve 140.52 - * annotations for methods and method parameters. 140.53 - */ 140.54 -public final static int SKIP_CODE = 1; 140.55 - 140.56 -/** 140.57 - * Flag to skip the debug information in the class. If this flag is set the 140.58 - * debug information of the class is not visited, i.e. the 140.59 - * {@link MethodVisitor#visitLocalVariable visitLocalVariable} and 140.60 - * {@link MethodVisitor#visitLineNumber visitLineNumber} methods will not be 140.61 - * called. 140.62 - */ 140.63 -public final static int SKIP_DEBUG = 2; 140.64 - 140.65 -/** 140.66 - * Flag to skip the stack map frames in the class. If this flag is set the 140.67 - * stack map frames of the class is not visited, i.e. the 140.68 - * {@link MethodVisitor#visitFrame visitFrame} method will not be called. 140.69 - * This flag is useful when the {@link ClassWriter#COMPUTE_FRAMES} option is 140.70 - * used: it avoids visiting frames that will be ignored and recomputed from 140.71 - * scratch in the class writer. 140.72 - */ 140.73 -public final static int SKIP_FRAMES = 4; 140.74 - 140.75 -/** 140.76 - * Flag to expand the stack map frames. By default stack map frames are 140.77 - * visited in their original format (i.e. "expanded" for classes whose 140.78 - * version is less than V1_6, and "compressed" for the other classes). If 140.79 - * this flag is set, stack map frames are always visited in expanded format 140.80 - * (this option adds a decompression/recompression step in ClassReader and 140.81 - * ClassWriter which degrades performances quite a lot). 140.82 - */ 140.83 -public final static int EXPAND_FRAMES = 8; 140.84 - 140.85 -/** 140.86 - * The class to be parsed. <i>The content of this array must not be 140.87 - * modified. This field is intended for {@link Attribute} sub classes, and 140.88 - * is normally not needed by class generators or adapters.</i> 140.89 - */ 140.90 -public final byte[] b; 140.91 - 140.92 -/** 140.93 - * The start index of each constant pool item in {@link #b b}, plus one. 140.94 - * The one byte offset skips the constant pool item tag that indicates its 140.95 - * type. 140.96 - */ 140.97 -private final int[] items; 140.98 - 140.99 -/** 140.100 - * The String objects corresponding to the CONSTANT_Utf8 items. This cache 140.101 - * avoids multiple parsing of a given CONSTANT_Utf8 constant pool item, 140.102 - * which GREATLY improves performances (by a factor 2 to 3). This caching 140.103 - * strategy could be extended to all constant pool items, but its benefit 140.104 - * would not be so great for these items (because they are much less 140.105 - * expensive to parse than CONSTANT_Utf8 items). 140.106 - */ 140.107 -private final String[] strings; 140.108 - 140.109 -/** 140.110 - * Maximum length of the strings contained in the constant pool of the 140.111 - * class. 140.112 - */ 140.113 -private final int maxStringLength; 140.114 - 140.115 -/** 140.116 - * Start index of the class header information (access, name...) in 140.117 - * {@link #b b}. 140.118 - */ 140.119 -public final int header; 140.120 - 140.121 -// ------------------------------------------------------------------------ 140.122 -// Constructors 140.123 -// ------------------------------------------------------------------------ 140.124 - 140.125 -/** 140.126 - * Constructs a new {@link ClassReader} object. 140.127 - * 140.128 - * @param b the bytecode of the class to be read. 140.129 - */ 140.130 -public ClassReader(final byte[] b){ 140.131 - this(b, 0, b.length); 140.132 -} 140.133 - 140.134 -/** 140.135 - * Constructs a new {@link ClassReader} object. 140.136 - * 140.137 - * @param b the bytecode of the class to be read. 140.138 - * @param off the start offset of the class data. 140.139 - * @param len the length of the class data. 140.140 - */ 140.141 -public ClassReader(final byte[] b, final int off, final int len){ 140.142 - this.b = b; 140.143 - // parses the constant pool 140.144 - items = new int[readUnsignedShort(off + 8)]; 140.145 - int n = items.length; 140.146 - strings = new String[n]; 140.147 - int max = 0; 140.148 - int index = off + 10; 140.149 - for(int i = 1; i < n; ++i) 140.150 - { 140.151 - items[i] = index + 1; 140.152 - int size; 140.153 - switch(b[index]) 140.154 - { 140.155 - case ClassWriter.FIELD: 140.156 - case ClassWriter.METH: 140.157 - case ClassWriter.IMETH: 140.158 - case ClassWriter.INT: 140.159 - case ClassWriter.FLOAT: 140.160 - case ClassWriter.NAME_TYPE: 140.161 - size = 5; 140.162 - break; 140.163 - case ClassWriter.LONG: 140.164 - case ClassWriter.DOUBLE: 140.165 - size = 9; 140.166 - ++i; 140.167 - break; 140.168 - case ClassWriter.UTF8: 140.169 - size = 3 + readUnsignedShort(index + 1); 140.170 - if(size > max) 140.171 - { 140.172 - max = size; 140.173 - } 140.174 - break; 140.175 - // case ClassWriter.CLASS: 140.176 - // case ClassWriter.STR: 140.177 - default: 140.178 - size = 3; 140.179 - break; 140.180 - } 140.181 - index += size; 140.182 - } 140.183 - maxStringLength = max; 140.184 - // the class header information starts just after the constant pool 140.185 - header = index; 140.186 -} 140.187 - 140.188 -/** 140.189 - * Returns the class's access flags (see {@link Opcodes}). This value may 140.190 - * not reflect Deprecated and Synthetic flags when bytecode is before 1.5 140.191 - * and those flags are represented by attributes. 140.192 - * 140.193 - * @return the class access flags 140.194 - * @see ClassVisitor#visit(int,int,String,String,String,String[]) 140.195 - */ 140.196 -public int getAccess(){ 140.197 - return readUnsignedShort(header); 140.198 -} 140.199 - 140.200 -/** 140.201 - * Returns the internal name of the class (see 140.202 - * {@link Type#getInternalName() getInternalName}). 140.203 - * 140.204 - * @return the internal class name 140.205 - * @see ClassVisitor#visit(int,int,String,String,String,String[]) 140.206 - */ 140.207 -public String getClassName(){ 140.208 - return readClass(header + 2, new char[maxStringLength]); 140.209 -} 140.210 - 140.211 -/** 140.212 - * Returns the internal of name of the super class (see 140.213 - * {@link Type#getInternalName() getInternalName}). For interfaces, the 140.214 - * super class is {@link Object}. 140.215 - * 140.216 - * @return the internal name of super class, or <tt>null</tt> for 140.217 - * {@link Object} class. 140.218 - * @see ClassVisitor#visit(int,int,String,String,String,String[]) 140.219 - */ 140.220 -public String getSuperName(){ 140.221 - int n = items[readUnsignedShort(header + 4)]; 140.222 - return n == 0 ? null : readUTF8(n, new char[maxStringLength]); 140.223 -} 140.224 - 140.225 -/** 140.226 - * Returns the internal names of the class's interfaces (see 140.227 - * {@link Type#getInternalName() getInternalName}). 140.228 - * 140.229 - * @return the array of internal names for all implemented interfaces or 140.230 - * <tt>null</tt>. 140.231 - * @see ClassVisitor#visit(int,int,String,String,String,String[]) 140.232 - */ 140.233 -public String[] getInterfaces(){ 140.234 - int index = header + 6; 140.235 - int n = readUnsignedShort(index); 140.236 - String[] interfaces = new String[n]; 140.237 - if(n > 0) 140.238 - { 140.239 - char[] buf = new char[maxStringLength]; 140.240 - for(int i = 0; i < n; ++i) 140.241 - { 140.242 - index += 2; 140.243 - interfaces[i] = readClass(index, buf); 140.244 - } 140.245 - } 140.246 - return interfaces; 140.247 -} 140.248 - 140.249 -/** 140.250 - * Copies the constant pool data into the given {@link ClassWriter}. Should 140.251 - * be called before the {@link #accept(ClassVisitor,int)} method. 140.252 - * 140.253 - * @param classWriter the {@link ClassWriter} to copy constant pool into. 140.254 - */ 140.255 -void copyPool(final ClassWriter classWriter){ 140.256 - char[] buf = new char[maxStringLength]; 140.257 - int ll = items.length; 140.258 - Item[] items2 = new Item[ll]; 140.259 - for(int i = 1; i < ll; i++) 140.260 - { 140.261 - int index = items[i]; 140.262 - int tag = b[index - 1]; 140.263 - Item item = new Item(i); 140.264 - int nameType; 140.265 - switch(tag) 140.266 - { 140.267 - case ClassWriter.FIELD: 140.268 - case ClassWriter.METH: 140.269 - case ClassWriter.IMETH: 140.270 - nameType = items[readUnsignedShort(index + 2)]; 140.271 - item.set(tag, 140.272 - readClass(index, buf), 140.273 - readUTF8(nameType, buf), 140.274 - readUTF8(nameType + 2, buf)); 140.275 - break; 140.276 - 140.277 - case ClassWriter.INT: 140.278 - item.set(readInt(index)); 140.279 - break; 140.280 - 140.281 - case ClassWriter.FLOAT: 140.282 - item.set(Float.intBitsToFloat(readInt(index))); 140.283 - break; 140.284 - 140.285 - case ClassWriter.NAME_TYPE: 140.286 - item.set(tag, 140.287 - readUTF8(index, buf), 140.288 - readUTF8(index + 2, buf), 140.289 - null); 140.290 - break; 140.291 - 140.292 - case ClassWriter.LONG: 140.293 - item.set(readLong(index)); 140.294 - ++i; 140.295 - break; 140.296 - 140.297 - case ClassWriter.DOUBLE: 140.298 - item.set(Double.longBitsToDouble(readLong(index))); 140.299 - ++i; 140.300 - break; 140.301 - 140.302 - case ClassWriter.UTF8: 140.303 - { 140.304 - String s = strings[i]; 140.305 - if(s == null) 140.306 - { 140.307 - index = items[i]; 140.308 - s = strings[i] = readUTF(index + 2, 140.309 - readUnsignedShort(index), 140.310 - buf); 140.311 - } 140.312 - item.set(tag, s, null, null); 140.313 - } 140.314 - break; 140.315 - 140.316 - // case ClassWriter.STR: 140.317 - // case ClassWriter.CLASS: 140.318 - default: 140.319 - item.set(tag, readUTF8(index, buf), null, null); 140.320 - break; 140.321 - } 140.322 - 140.323 - int index2 = item.hashCode % items2.length; 140.324 - item.next = items2[index2]; 140.325 - items2[index2] = item; 140.326 - } 140.327 - 140.328 - int off = items[1] - 1; 140.329 - classWriter.pool.putByteArray(b, off, header - off); 140.330 - classWriter.items = items2; 140.331 - classWriter.threshold = (int) (0.75d * ll); 140.332 - classWriter.index = ll; 140.333 -} 140.334 - 140.335 -/** 140.336 - * Constructs a new {@link ClassReader} object. 140.337 - * 140.338 - * @param is an input stream from which to read the class. 140.339 - * @throws IOException if a problem occurs during reading. 140.340 - */ 140.341 -public ClassReader(final InputStream is) throws IOException{ 140.342 - this(readClass(is)); 140.343 -} 140.344 - 140.345 -/** 140.346 - * Constructs a new {@link ClassReader} object. 140.347 - * 140.348 - * @param name the fully qualified name of the class to be read. 140.349 - * @throws IOException if an exception occurs during reading. 140.350 - */ 140.351 -public ClassReader(final String name) throws IOException{ 140.352 - this(ClassLoader.getSystemResourceAsStream(name.replace('.', '/') 140.353 - + ".class")); 140.354 -} 140.355 - 140.356 -/** 140.357 - * Reads the bytecode of a class. 140.358 - * 140.359 - * @param is an input stream from which to read the class. 140.360 - * @return the bytecode read from the given input stream. 140.361 - * @throws IOException if a problem occurs during reading. 140.362 - */ 140.363 -private static byte[] readClass(final InputStream is) throws IOException{ 140.364 - if(is == null) 140.365 - { 140.366 - throw new IOException("Class not found"); 140.367 - } 140.368 - byte[] b = new byte[is.available()]; 140.369 - int len = 0; 140.370 - while(true) 140.371 - { 140.372 - int n = is.read(b, len, b.length - len); 140.373 - if(n == -1) 140.374 - { 140.375 - if(len < b.length) 140.376 - { 140.377 - byte[] c = new byte[len]; 140.378 - System.arraycopy(b, 0, c, 0, len); 140.379 - b = c; 140.380 - } 140.381 - return b; 140.382 - } 140.383 - len += n; 140.384 - if(len == b.length) 140.385 - { 140.386 - byte[] c = new byte[b.length + 1000]; 140.387 - System.arraycopy(b, 0, c, 0, len); 140.388 - b = c; 140.389 - } 140.390 - } 140.391 -} 140.392 - 140.393 -// ------------------------------------------------------------------------ 140.394 -// Public methods 140.395 -// ------------------------------------------------------------------------ 140.396 - 140.397 -/** 140.398 - * Makes the given visitor visit the Java class of this {@link ClassReader}. 140.399 - * This class is the one specified in the constructor (see 140.400 - * {@link #ClassReader(byte[]) ClassReader}). 140.401 - * 140.402 - * @param classVisitor the visitor that must visit this class. 140.403 - * @param flags option flags that can be used to modify the default behavior 140.404 - * of this class. See {@link #SKIP_DEBUG}, {@link #EXPAND_FRAMES}. 140.405 - */ 140.406 -public void accept(final ClassVisitor classVisitor, final int flags){ 140.407 - accept(classVisitor, new Attribute[0], flags); 140.408 -} 140.409 - 140.410 -/** 140.411 - * Makes the given visitor visit the Java class of this {@link ClassReader}. 140.412 - * This class is the one specified in the constructor (see 140.413 - * {@link #ClassReader(byte[]) ClassReader}). 140.414 - * 140.415 - * @param classVisitor the visitor that must visit this class. 140.416 - * @param attrs prototypes of the attributes that must be parsed during the 140.417 - * visit of the class. Any attribute whose type is not equal to the 140.418 - * type of one the prototypes will not be parsed: its byte array 140.419 - * value will be passed unchanged to the ClassWriter. <i>This may 140.420 - * corrupt it if this value contains references to the constant pool, 140.421 - * or has syntactic or semantic links with a class element that has 140.422 - * been transformed by a class adapter between the reader and the 140.423 - * writer</i>. 140.424 - * @param flags option flags that can be used to modify the default behavior 140.425 - * of this class. See {@link #SKIP_DEBUG}, {@link #EXPAND_FRAMES}. 140.426 - */ 140.427 -public void accept( 140.428 - final ClassVisitor classVisitor, 140.429 - final Attribute[] attrs, 140.430 - final int flags){ 140.431 - byte[] b = this.b; // the bytecode array 140.432 - char[] c = new char[maxStringLength]; // buffer used to read strings 140.433 - int i, j, k; // loop variables 140.434 - int u, v, w; // indexes in b 140.435 - Attribute attr; 140.436 - 140.437 - int access; 140.438 - String name; 140.439 - String desc; 140.440 - String attrName; 140.441 - String signature; 140.442 - int anns = 0; 140.443 - int ianns = 0; 140.444 - Attribute cattrs = null; 140.445 - 140.446 - // visits the header 140.447 - u = header; 140.448 - access = readUnsignedShort(u); 140.449 - name = readClass(u + 2, c); 140.450 - v = items[readUnsignedShort(u + 4)]; 140.451 - String superClassName = v == 0 ? null : readUTF8(v, c); 140.452 - String[] implementedItfs = new String[readUnsignedShort(u + 6)]; 140.453 - w = 0; 140.454 - u += 8; 140.455 - for(i = 0; i < implementedItfs.length; ++i) 140.456 - { 140.457 - implementedItfs[i] = readClass(u, c); 140.458 - u += 2; 140.459 - } 140.460 - 140.461 - boolean skipCode = (flags & SKIP_CODE) != 0; 140.462 - boolean skipDebug = (flags & SKIP_DEBUG) != 0; 140.463 - boolean unzip = (flags & EXPAND_FRAMES) != 0; 140.464 - 140.465 - // skips fields and methods 140.466 - v = u; 140.467 - i = readUnsignedShort(v); 140.468 - v += 2; 140.469 - for(; i > 0; --i) 140.470 - { 140.471 - j = readUnsignedShort(v + 6); 140.472 - v += 8; 140.473 - for(; j > 0; --j) 140.474 - { 140.475 - v += 6 + readInt(v + 2); 140.476 - } 140.477 - } 140.478 - i = readUnsignedShort(v); 140.479 - v += 2; 140.480 - for(; i > 0; --i) 140.481 - { 140.482 - j = readUnsignedShort(v + 6); 140.483 - v += 8; 140.484 - for(; j > 0; --j) 140.485 - { 140.486 - v += 6 + readInt(v + 2); 140.487 - } 140.488 - } 140.489 - // reads the class's attributes 140.490 - signature = null; 140.491 - String sourceFile = null; 140.492 - String sourceDebug = null; 140.493 - String enclosingOwner = null; 140.494 - String enclosingName = null; 140.495 - String enclosingDesc = null; 140.496 - 140.497 - i = readUnsignedShort(v); 140.498 - v += 2; 140.499 - for(; i > 0; --i) 140.500 - { 140.501 - attrName = readUTF8(v, c); 140.502 - // tests are sorted in decreasing frequency order 140.503 - // (based on frequencies observed on typical classes) 140.504 - if(attrName.equals("SourceFile")) 140.505 - { 140.506 - sourceFile = readUTF8(v + 6, c); 140.507 - } 140.508 - else if(attrName.equals("InnerClasses")) 140.509 - { 140.510 - w = v + 6; 140.511 - } 140.512 - else if(attrName.equals("EnclosingMethod")) 140.513 - { 140.514 - enclosingOwner = readClass(v + 6, c); 140.515 - int item = readUnsignedShort(v + 8); 140.516 - if(item != 0) 140.517 - { 140.518 - enclosingName = readUTF8(items[item], c); 140.519 - enclosingDesc = readUTF8(items[item] + 2, c); 140.520 - } 140.521 - } 140.522 - else if(attrName.equals("Signature")) 140.523 - { 140.524 - signature = readUTF8(v + 6, c); 140.525 - } 140.526 - else if(attrName.equals("RuntimeVisibleAnnotations")) 140.527 - { 140.528 - anns = v + 6; 140.529 - } 140.530 - else if(attrName.equals("Deprecated")) 140.531 - { 140.532 - access |= Opcodes.ACC_DEPRECATED; 140.533 - } 140.534 - else if(attrName.equals("Synthetic")) 140.535 - { 140.536 - access |= Opcodes.ACC_SYNTHETIC; 140.537 - } 140.538 - else if(attrName.equals("SourceDebugExtension")) 140.539 - { 140.540 - int len = readInt(v + 2); 140.541 - sourceDebug = readUTF(v + 6, len, new char[len]); 140.542 - } 140.543 - else if(attrName.equals("RuntimeInvisibleAnnotations")) 140.544 - { 140.545 - ianns = v + 6; 140.546 - } 140.547 - else 140.548 - { 140.549 - attr = readAttribute(attrs, 140.550 - attrName, 140.551 - v + 6, 140.552 - readInt(v + 2), 140.553 - c, 140.554 - -1, 140.555 - null); 140.556 - if(attr != null) 140.557 - { 140.558 - attr.next = cattrs; 140.559 - cattrs = attr; 140.560 - } 140.561 - } 140.562 - v += 6 + readInt(v + 2); 140.563 - } 140.564 - // calls the visit method 140.565 - classVisitor.visit(readInt(4), 140.566 - access, 140.567 - name, 140.568 - signature, 140.569 - superClassName, 140.570 - implementedItfs); 140.571 - 140.572 - // calls the visitSource method 140.573 - if(!skipDebug && (sourceFile != null || sourceDebug != null)) 140.574 - { 140.575 - classVisitor.visitSource(sourceFile, sourceDebug); 140.576 - } 140.577 - 140.578 - // calls the visitOuterClass method 140.579 - if(enclosingOwner != null) 140.580 - { 140.581 - classVisitor.visitOuterClass(enclosingOwner, 140.582 - enclosingName, 140.583 - enclosingDesc); 140.584 - } 140.585 - 140.586 - // visits the class annotations 140.587 - for(i = 1; i >= 0; --i) 140.588 - { 140.589 - v = i == 0 ? ianns : anns; 140.590 - if(v != 0) 140.591 - { 140.592 - j = readUnsignedShort(v); 140.593 - v += 2; 140.594 - for(; j > 0; --j) 140.595 - { 140.596 - v = readAnnotationValues(v + 2, 140.597 - c, 140.598 - true, 140.599 - classVisitor.visitAnnotation(readUTF8(v, c), i != 0)); 140.600 - } 140.601 - } 140.602 - } 140.603 - 140.604 - // visits the class attributes 140.605 - while(cattrs != null) 140.606 - { 140.607 - attr = cattrs.next; 140.608 - cattrs.next = null; 140.609 - classVisitor.visitAttribute(cattrs); 140.610 - cattrs = attr; 140.611 - } 140.612 - 140.613 - // calls the visitInnerClass method 140.614 - if(w != 0) 140.615 - { 140.616 - i = readUnsignedShort(w); 140.617 - w += 2; 140.618 - for(; i > 0; --i) 140.619 - { 140.620 - classVisitor.visitInnerClass(readUnsignedShort(w) == 0 140.621 - ? null 140.622 - : readClass(w, c), readUnsignedShort(w + 2) == 0 140.623 - ? null 140.624 - : readClass(w + 2, c), readUnsignedShort(w + 4) == 0 140.625 - ? null 140.626 - : readUTF8(w + 4, c), 140.627 - readUnsignedShort(w + 6)); 140.628 - w += 8; 140.629 - } 140.630 - } 140.631 - 140.632 - // visits the fields 140.633 - i = readUnsignedShort(u); 140.634 - u += 2; 140.635 - for(; i > 0; --i) 140.636 - { 140.637 - access = readUnsignedShort(u); 140.638 - name = readUTF8(u + 2, c); 140.639 - desc = readUTF8(u + 4, c); 140.640 - // visits the field's attributes and looks for a ConstantValue 140.641 - // attribute 140.642 - int fieldValueItem = 0; 140.643 - signature = null; 140.644 - anns = 0; 140.645 - ianns = 0; 140.646 - cattrs = null; 140.647 - 140.648 - j = readUnsignedShort(u + 6); 140.649 - u += 8; 140.650 - for(; j > 0; --j) 140.651 - { 140.652 - attrName = readUTF8(u, c); 140.653 - // tests are sorted in decreasing frequency order 140.654 - // (based on frequencies observed on typical classes) 140.655 - if(attrName.equals("ConstantValue")) 140.656 - { 140.657 - fieldValueItem = readUnsignedShort(u + 6); 140.658 - } 140.659 - else if(attrName.equals("Signature")) 140.660 - { 140.661 - signature = readUTF8(u + 6, c); 140.662 - } 140.663 - else if(attrName.equals("Deprecated")) 140.664 - { 140.665 - access |= Opcodes.ACC_DEPRECATED; 140.666 - } 140.667 - else if(attrName.equals("Synthetic")) 140.668 - { 140.669 - access |= Opcodes.ACC_SYNTHETIC; 140.670 - } 140.671 - else if(attrName.equals("RuntimeVisibleAnnotations")) 140.672 - { 140.673 - anns = u + 6; 140.674 - } 140.675 - else if(attrName.equals("RuntimeInvisibleAnnotations")) 140.676 - { 140.677 - ianns = u + 6; 140.678 - } 140.679 - else 140.680 - { 140.681 - attr = readAttribute(attrs, 140.682 - attrName, 140.683 - u + 6, 140.684 - readInt(u + 2), 140.685 - c, 140.686 - -1, 140.687 - null); 140.688 - if(attr != null) 140.689 - { 140.690 - attr.next = cattrs; 140.691 - cattrs = attr; 140.692 - } 140.693 - } 140.694 - u += 6 + readInt(u + 2); 140.695 - } 140.696 - // visits the field 140.697 - FieldVisitor fv = classVisitor.visitField(access, 140.698 - name, 140.699 - desc, 140.700 - signature, 140.701 - fieldValueItem == 0 ? null : readConst(fieldValueItem, c)); 140.702 - // visits the field annotations and attributes 140.703 - if(fv != null) 140.704 - { 140.705 - for(j = 1; j >= 0; --j) 140.706 - { 140.707 - v = j == 0 ? ianns : anns; 140.708 - if(v != 0) 140.709 - { 140.710 - k = readUnsignedShort(v); 140.711 - v += 2; 140.712 - for(; k > 0; --k) 140.713 - { 140.714 - v = readAnnotationValues(v + 2, 140.715 - c, 140.716 - true, 140.717 - fv.visitAnnotation(readUTF8(v, c), j != 0)); 140.718 - } 140.719 - } 140.720 - } 140.721 - while(cattrs != null) 140.722 - { 140.723 - attr = cattrs.next; 140.724 - cattrs.next = null; 140.725 - fv.visitAttribute(cattrs); 140.726 - cattrs = attr; 140.727 - } 140.728 - fv.visitEnd(); 140.729 - } 140.730 - } 140.731 - 140.732 - // visits the methods 140.733 - i = readUnsignedShort(u); 140.734 - u += 2; 140.735 - for(; i > 0; --i) 140.736 - { 140.737 - int u0 = u + 6; 140.738 - access = readUnsignedShort(u); 140.739 - name = readUTF8(u + 2, c); 140.740 - desc = readUTF8(u + 4, c); 140.741 - signature = null; 140.742 - anns = 0; 140.743 - ianns = 0; 140.744 - int dann = 0; 140.745 - int mpanns = 0; 140.746 - int impanns = 0; 140.747 - cattrs = null; 140.748 - v = 0; 140.749 - w = 0; 140.750 - 140.751 - // looks for Code and Exceptions attributes 140.752 - j = readUnsignedShort(u + 6); 140.753 - u += 8; 140.754 - for(; j > 0; --j) 140.755 - { 140.756 - attrName = readUTF8(u, c); 140.757 - int attrSize = readInt(u + 2); 140.758 - u += 6; 140.759 - // tests are sorted in decreasing frequency order 140.760 - // (based on frequencies observed on typical classes) 140.761 - if(attrName.equals("Code")) 140.762 - { 140.763 - if(!skipCode) 140.764 - { 140.765 - v = u; 140.766 - } 140.767 - } 140.768 - else if(attrName.equals("Exceptions")) 140.769 - { 140.770 - w = u; 140.771 - } 140.772 - else if(attrName.equals("Signature")) 140.773 - { 140.774 - signature = readUTF8(u, c); 140.775 - } 140.776 - else if(attrName.equals("Deprecated")) 140.777 - { 140.778 - access |= Opcodes.ACC_DEPRECATED; 140.779 - } 140.780 - else if(attrName.equals("RuntimeVisibleAnnotations")) 140.781 - { 140.782 - anns = u; 140.783 - } 140.784 - else if(attrName.equals("AnnotationDefault")) 140.785 - { 140.786 - dann = u; 140.787 - } 140.788 - else if(attrName.equals("Synthetic")) 140.789 - { 140.790 - access |= Opcodes.ACC_SYNTHETIC; 140.791 - } 140.792 - else if(attrName.equals("RuntimeInvisibleAnnotations")) 140.793 - { 140.794 - ianns = u; 140.795 - } 140.796 - else if(attrName.equals("RuntimeVisibleParameterAnnotations")) 140.797 - { 140.798 - mpanns = u; 140.799 - } 140.800 - else if(attrName.equals("RuntimeInvisibleParameterAnnotations")) 140.801 - { 140.802 - impanns = u; 140.803 - } 140.804 - else 140.805 - { 140.806 - attr = readAttribute(attrs, 140.807 - attrName, 140.808 - u, 140.809 - attrSize, 140.810 - c, 140.811 - -1, 140.812 - null); 140.813 - if(attr != null) 140.814 - { 140.815 - attr.next = cattrs; 140.816 - cattrs = attr; 140.817 - } 140.818 - } 140.819 - u += attrSize; 140.820 - } 140.821 - // reads declared exceptions 140.822 - String[] exceptions; 140.823 - if(w == 0) 140.824 - { 140.825 - exceptions = null; 140.826 - } 140.827 - else 140.828 - { 140.829 - exceptions = new String[readUnsignedShort(w)]; 140.830 - w += 2; 140.831 - for(j = 0; j < exceptions.length; ++j) 140.832 - { 140.833 - exceptions[j] = readClass(w, c); 140.834 - w += 2; 140.835 - } 140.836 - } 140.837 - 140.838 - // visits the method's code, if any 140.839 - MethodVisitor mv = classVisitor.visitMethod(access, 140.840 - name, 140.841 - desc, 140.842 - signature, 140.843 - exceptions); 140.844 - 140.845 - if(mv != null) 140.846 - { 140.847 - /* 140.848 - * if the returned MethodVisitor is in fact a MethodWriter, it 140.849 - * means there is no method adapter between the reader and the 140.850 - * writer. If, in addition, the writer's constant pool was 140.851 - * copied from this reader (mw.cw.cr == this), and the signature 140.852 - * and exceptions of the method have not been changed, then it 140.853 - * is possible to skip all visit events and just copy the 140.854 - * original code of the method to the writer (the access, name 140.855 - * and descriptor can have been changed, this is not important 140.856 - * since they are not copied as is from the reader). 140.857 - */ 140.858 - if(mv instanceof MethodWriter) 140.859 - { 140.860 - MethodWriter mw = (MethodWriter) mv; 140.861 - if(mw.cw.cr == this) 140.862 - { 140.863 - if(signature == mw.signature) 140.864 - { 140.865 - boolean sameExceptions = false; 140.866 - if(exceptions == null) 140.867 - { 140.868 - sameExceptions = mw.exceptionCount == 0; 140.869 - } 140.870 - else 140.871 - { 140.872 - if(exceptions.length == mw.exceptionCount) 140.873 - { 140.874 - sameExceptions = true; 140.875 - for(j = exceptions.length - 1; j >= 0; --j) 140.876 - { 140.877 - w -= 2; 140.878 - if(mw.exceptions[j] != readUnsignedShort(w)) 140.879 - { 140.880 - sameExceptions = false; 140.881 - break; 140.882 - } 140.883 - } 140.884 - } 140.885 - } 140.886 - if(sameExceptions) 140.887 - { 140.888 - /* 140.889 - * we do not copy directly the code into 140.890 - * MethodWriter to save a byte array copy 140.891 - * operation. The real copy will be done in 140.892 - * ClassWriter.toByteArray(). 140.893 - */ 140.894 - mw.classReaderOffset = u0; 140.895 - mw.classReaderLength = u - u0; 140.896 - continue; 140.897 - } 140.898 - } 140.899 - } 140.900 - } 140.901 - 140.902 - if(dann != 0) 140.903 - { 140.904 - AnnotationVisitor dv = mv.visitAnnotationDefault(); 140.905 - readAnnotationValue(dann, c, null, dv); 140.906 - if(dv != null) 140.907 - { 140.908 - dv.visitEnd(); 140.909 - } 140.910 - } 140.911 - for(j = 1; j >= 0; --j) 140.912 - { 140.913 - w = j == 0 ? ianns : anns; 140.914 - if(w != 0) 140.915 - { 140.916 - k = readUnsignedShort(w); 140.917 - w += 2; 140.918 - for(; k > 0; --k) 140.919 - { 140.920 - w = readAnnotationValues(w + 2, 140.921 - c, 140.922 - true, 140.923 - mv.visitAnnotation(readUTF8(w, c), j != 0)); 140.924 - } 140.925 - } 140.926 - } 140.927 - if(mpanns != 0) 140.928 - { 140.929 - readParameterAnnotations(mpanns, c, true, mv); 140.930 - } 140.931 - if(impanns != 0) 140.932 - { 140.933 - readParameterAnnotations(impanns, c, false, mv); 140.934 - } 140.935 - while(cattrs != null) 140.936 - { 140.937 - attr = cattrs.next; 140.938 - cattrs.next = null; 140.939 - mv.visitAttribute(cattrs); 140.940 - cattrs = attr; 140.941 - } 140.942 - } 140.943 - 140.944 - if(mv != null && v != 0) 140.945 - { 140.946 - int maxStack = readUnsignedShort(v); 140.947 - int maxLocals = readUnsignedShort(v + 2); 140.948 - int codeLength = readInt(v + 4); 140.949 - v += 8; 140.950 - 140.951 - int codeStart = v; 140.952 - int codeEnd = v + codeLength; 140.953 - 140.954 - mv.visitCode(); 140.955 - 140.956 - // 1st phase: finds the labels 140.957 - int label; 140.958 - Label[] labels = new Label[codeLength + 1]; 140.959 - while(v < codeEnd) 140.960 - { 140.961 - int opcode = b[v] & 0xFF; 140.962 - switch(ClassWriter.TYPE[opcode]) 140.963 - { 140.964 - case ClassWriter.NOARG_INSN: 140.965 - case ClassWriter.IMPLVAR_INSN: 140.966 - v += 1; 140.967 - break; 140.968 - case ClassWriter.LABEL_INSN: 140.969 - label = v - codeStart + readShort(v + 1); 140.970 - if(labels[label] == null) 140.971 - { 140.972 - labels[label] = new Label(); 140.973 - } 140.974 - v += 3; 140.975 - break; 140.976 - case ClassWriter.LABELW_INSN: 140.977 - label = v - codeStart + readInt(v + 1); 140.978 - if(labels[label] == null) 140.979 - { 140.980 - labels[label] = new Label(); 140.981 - } 140.982 - v += 5; 140.983 - break; 140.984 - case ClassWriter.WIDE_INSN: 140.985 - opcode = b[v + 1] & 0xFF; 140.986 - if(opcode == Opcodes.IINC) 140.987 - { 140.988 - v += 6; 140.989 - } 140.990 - else 140.991 - { 140.992 - v += 4; 140.993 - } 140.994 - break; 140.995 - case ClassWriter.TABL_INSN: 140.996 - // skips 0 to 3 padding bytes 140.997 - w = v - codeStart; 140.998 - v = v + 4 - (w & 3); 140.999 - // reads instruction 140.1000 - label = w + readInt(v); 140.1001 - if(labels[label] == null) 140.1002 - { 140.1003 - labels[label] = new Label(); 140.1004 - } 140.1005 - j = readInt(v + 8) - readInt(v + 4) + 1; 140.1006 - v += 12; 140.1007 - for(; j > 0; --j) 140.1008 - { 140.1009 - label = w + readInt(v); 140.1010 - v += 4; 140.1011 - if(labels[label] == null) 140.1012 - { 140.1013 - labels[label] = new Label(); 140.1014 - } 140.1015 - } 140.1016 - break; 140.1017 - case ClassWriter.LOOK_INSN: 140.1018 - // skips 0 to 3 padding bytes 140.1019 - w = v - codeStart; 140.1020 - v = v + 4 - (w & 3); 140.1021 - // reads instruction 140.1022 - label = w + readInt(v); 140.1023 - if(labels[label] == null) 140.1024 - { 140.1025 - labels[label] = new Label(); 140.1026 - } 140.1027 - j = readInt(v + 4); 140.1028 - v += 8; 140.1029 - for(; j > 0; --j) 140.1030 - { 140.1031 - label = w + readInt(v + 4); 140.1032 - v += 8; 140.1033 - if(labels[label] == null) 140.1034 - { 140.1035 - labels[label] = new Label(); 140.1036 - } 140.1037 - } 140.1038 - break; 140.1039 - case ClassWriter.VAR_INSN: 140.1040 - case ClassWriter.SBYTE_INSN: 140.1041 - case ClassWriter.LDC_INSN: 140.1042 - v += 2; 140.1043 - break; 140.1044 - case ClassWriter.SHORT_INSN: 140.1045 - case ClassWriter.LDCW_INSN: 140.1046 - case ClassWriter.FIELDORMETH_INSN: 140.1047 - case ClassWriter.TYPE_INSN: 140.1048 - case ClassWriter.IINC_INSN: 140.1049 - v += 3; 140.1050 - break; 140.1051 - case ClassWriter.ITFMETH_INSN: 140.1052 - v += 5; 140.1053 - break; 140.1054 - // case MANA_INSN: 140.1055 - default: 140.1056 - v += 4; 140.1057 - break; 140.1058 - } 140.1059 - } 140.1060 - // parses the try catch entries 140.1061 - j = readUnsignedShort(v); 140.1062 - v += 2; 140.1063 - for(; j > 0; --j) 140.1064 - { 140.1065 - label = readUnsignedShort(v); 140.1066 - Label start = labels[label]; 140.1067 - if(start == null) 140.1068 - { 140.1069 - labels[label] = start = new Label(); 140.1070 - } 140.1071 - label = readUnsignedShort(v + 2); 140.1072 - Label end = labels[label]; 140.1073 - if(end == null) 140.1074 - { 140.1075 - labels[label] = end = new Label(); 140.1076 - } 140.1077 - label = readUnsignedShort(v + 4); 140.1078 - Label handler = labels[label]; 140.1079 - if(handler == null) 140.1080 - { 140.1081 - labels[label] = handler = new Label(); 140.1082 - } 140.1083 - int type = readUnsignedShort(v + 6); 140.1084 - if(type == 0) 140.1085 - { 140.1086 - mv.visitTryCatchBlock(start, end, handler, null); 140.1087 - } 140.1088 - else 140.1089 - { 140.1090 - mv.visitTryCatchBlock(start, 140.1091 - end, 140.1092 - handler, 140.1093 - readUTF8(items[type], c)); 140.1094 - } 140.1095 - v += 8; 140.1096 - } 140.1097 - // parses the local variable, line number tables, and code 140.1098 - // attributes 140.1099 - int varTable = 0; 140.1100 - int varTypeTable = 0; 140.1101 - int stackMap = 0; 140.1102 - int frameCount = 0; 140.1103 - int frameMode = 0; 140.1104 - int frameOffset = 0; 140.1105 - int frameLocalCount = 0; 140.1106 - int frameLocalDiff = 0; 140.1107 - int frameStackCount = 0; 140.1108 - Object[] frameLocal = null; 140.1109 - Object[] frameStack = null; 140.1110 - boolean zip = true; 140.1111 - cattrs = null; 140.1112 - j = readUnsignedShort(v); 140.1113 - v += 2; 140.1114 - for(; j > 0; --j) 140.1115 - { 140.1116 - attrName = readUTF8(v, c); 140.1117 - if(attrName.equals("LocalVariableTable")) 140.1118 - { 140.1119 - if(!skipDebug) 140.1120 - { 140.1121 - varTable = v + 6; 140.1122 - k = readUnsignedShort(v + 6); 140.1123 - w = v + 8; 140.1124 - for(; k > 0; --k) 140.1125 - { 140.1126 - label = readUnsignedShort(w); 140.1127 - if(labels[label] == null) 140.1128 - { 140.1129 - labels[label] = new Label(true); 140.1130 - } 140.1131 - label += readUnsignedShort(w + 2); 140.1132 - if(labels[label] == null) 140.1133 - { 140.1134 - labels[label] = new Label(true); 140.1135 - } 140.1136 - w += 10; 140.1137 - } 140.1138 - } 140.1139 - } 140.1140 - else if(attrName.equals("LocalVariableTypeTable")) 140.1141 - { 140.1142 - varTypeTable = v + 6; 140.1143 - } 140.1144 - else if(attrName.equals("LineNumberTable")) 140.1145 - { 140.1146 - if(!skipDebug) 140.1147 - { 140.1148 - k = readUnsignedShort(v + 6); 140.1149 - w = v + 8; 140.1150 - for(; k > 0; --k) 140.1151 - { 140.1152 - label = readUnsignedShort(w); 140.1153 - if(labels[label] == null) 140.1154 - { 140.1155 - labels[label] = new Label(true); 140.1156 - } 140.1157 - labels[label].line = readUnsignedShort(w + 2); 140.1158 - w += 4; 140.1159 - } 140.1160 - } 140.1161 - } 140.1162 - else if(attrName.equals("StackMapTable")) 140.1163 - { 140.1164 - if((flags & SKIP_FRAMES) == 0) 140.1165 - { 140.1166 - stackMap = v + 8; 140.1167 - frameCount = readUnsignedShort(v + 6); 140.1168 - } 140.1169 - /* 140.1170 - * here we do not extract the labels corresponding to 140.1171 - * the attribute content. This would require a full 140.1172 - * parsing of the attribute, which would need to be 140.1173 - * repeated in the second phase (see below). Instead the 140.1174 - * content of the attribute is read one frame at a time 140.1175 - * (i.e. after a frame has been visited, the next frame 140.1176 - * is read), and the labels it contains are also 140.1177 - * extracted one frame at a time. Thanks to the ordering 140.1178 - * of frames, having only a "one frame lookahead" is not 140.1179 - * a problem, i.e. it is not possible to see an offset 140.1180 - * smaller than the offset of the current insn and for 140.1181 - * which no Label exist. 140.1182 - */ 140.1183 - // TODO true for frame offsets, 140.1184 - // but for UNINITIALIZED type offsets? 140.1185 - } 140.1186 - else if(attrName.equals("StackMap")) 140.1187 - { 140.1188 - if((flags & SKIP_FRAMES) == 0) 140.1189 - { 140.1190 - stackMap = v + 8; 140.1191 - frameCount = readUnsignedShort(v + 6); 140.1192 - zip = false; 140.1193 - } 140.1194 - /* 140.1195 - * IMPORTANT! here we assume that the frames are 140.1196 - * ordered, as in the StackMapTable attribute, although 140.1197 - * this is not guaranteed by the attribute format. 140.1198 - */ 140.1199 - } 140.1200 - else 140.1201 - { 140.1202 - for(k = 0; k < attrs.length; ++k) 140.1203 - { 140.1204 - if(attrs[k].type.equals(attrName)) 140.1205 - { 140.1206 - attr = attrs[k].read(this, 140.1207 - v + 6, 140.1208 - readInt(v + 2), 140.1209 - c, 140.1210 - codeStart - 8, 140.1211 - labels); 140.1212 - if(attr != null) 140.1213 - { 140.1214 - attr.next = cattrs; 140.1215 - cattrs = attr; 140.1216 - } 140.1217 - } 140.1218 - } 140.1219 - } 140.1220 - v += 6 + readInt(v + 2); 140.1221 - } 140.1222 - 140.1223 - // 2nd phase: visits each instruction 140.1224 - if(stackMap != 0) 140.1225 - { 140.1226 - // creates the very first (implicit) frame from the method 140.1227 - // descriptor 140.1228 - frameLocal = new Object[maxLocals]; 140.1229 - frameStack = new Object[maxStack]; 140.1230 - if(unzip) 140.1231 - { 140.1232 - int local = 0; 140.1233 - if((access & Opcodes.ACC_STATIC) == 0) 140.1234 - { 140.1235 - if(name.equals("<init>")) 140.1236 - { 140.1237 - frameLocal[local++] = Opcodes.UNINITIALIZED_THIS; 140.1238 - } 140.1239 - else 140.1240 - { 140.1241 - frameLocal[local++] = readClass(header + 2, c); 140.1242 - } 140.1243 - } 140.1244 - j = 1; 140.1245 - loop: 140.1246 - while(true) 140.1247 - { 140.1248 - k = j; 140.1249 - switch(desc.charAt(j++)) 140.1250 - { 140.1251 - case'Z': 140.1252 - case'C': 140.1253 - case'B': 140.1254 - case'S': 140.1255 - case'I': 140.1256 - frameLocal[local++] = Opcodes.INTEGER; 140.1257 - break; 140.1258 - case'F': 140.1259 - frameLocal[local++] = Opcodes.FLOAT; 140.1260 - break; 140.1261 - case'J': 140.1262 - frameLocal[local++] = Opcodes.LONG; 140.1263 - break; 140.1264 - case'D': 140.1265 - frameLocal[local++] = Opcodes.DOUBLE; 140.1266 - break; 140.1267 - case'[': 140.1268 - while(desc.charAt(j) == '[') 140.1269 - { 140.1270 - ++j; 140.1271 - } 140.1272 - if(desc.charAt(j) == 'L') 140.1273 - { 140.1274 - ++j; 140.1275 - while(desc.charAt(j) != ';') 140.1276 - { 140.1277 - ++j; 140.1278 - } 140.1279 - } 140.1280 - frameLocal[local++] = desc.substring(k, ++j); 140.1281 - break; 140.1282 - case'L': 140.1283 - while(desc.charAt(j) != ';') 140.1284 - { 140.1285 - ++j; 140.1286 - } 140.1287 - frameLocal[local++] = desc.substring(k + 1, 140.1288 - j++); 140.1289 - break; 140.1290 - default: 140.1291 - break loop; 140.1292 - } 140.1293 - } 140.1294 - frameLocalCount = local; 140.1295 - } 140.1296 - /* 140.1297 - * for the first explicit frame the offset is not 140.1298 - * offset_delta + 1 but only offset_delta; setting the 140.1299 - * implicit frame offset to -1 allow the use of the 140.1300 - * "offset_delta + 1" rule in all cases 140.1301 - */ 140.1302 - frameOffset = -1; 140.1303 - } 140.1304 - v = codeStart; 140.1305 - Label l; 140.1306 - while(v < codeEnd) 140.1307 - { 140.1308 - w = v - codeStart; 140.1309 - 140.1310 - l = labels[w]; 140.1311 - if(l != null) 140.1312 - { 140.1313 - mv.visitLabel(l); 140.1314 - if(!skipDebug && l.line > 0) 140.1315 - { 140.1316 - mv.visitLineNumber(l.line, l); 140.1317 - } 140.1318 - } 140.1319 - 140.1320 - while(frameLocal != null 140.1321 - && (frameOffset == w || frameOffset == -1)) 140.1322 - { 140.1323 - // if there is a frame for this offset, 140.1324 - // makes the visitor visit it, 140.1325 - // and reads the next frame if there is one. 140.1326 - if(!zip || unzip) 140.1327 - { 140.1328 - mv.visitFrame(Opcodes.F_NEW, 140.1329 - frameLocalCount, 140.1330 - frameLocal, 140.1331 - frameStackCount, 140.1332 - frameStack); 140.1333 - } 140.1334 - else if(frameOffset != -1) 140.1335 - { 140.1336 - mv.visitFrame(frameMode, 140.1337 - frameLocalDiff, 140.1338 - frameLocal, 140.1339 - frameStackCount, 140.1340 - frameStack); 140.1341 - } 140.1342 - 140.1343 - if(frameCount > 0) 140.1344 - { 140.1345 - int tag, delta, n; 140.1346 - if(zip) 140.1347 - { 140.1348 - tag = b[stackMap++] & 0xFF; 140.1349 - } 140.1350 - else 140.1351 - { 140.1352 - tag = MethodWriter.FULL_FRAME; 140.1353 - frameOffset = -1; 140.1354 - } 140.1355 - frameLocalDiff = 0; 140.1356 - if(tag < MethodWriter.SAME_LOCALS_1_STACK_ITEM_FRAME) 140.1357 - { 140.1358 - delta = tag; 140.1359 - frameMode = Opcodes.F_SAME; 140.1360 - frameStackCount = 0; 140.1361 - } 140.1362 - else if(tag < MethodWriter.RESERVED) 140.1363 - { 140.1364 - delta = tag 140.1365 - - MethodWriter.SAME_LOCALS_1_STACK_ITEM_FRAME; 140.1366 - stackMap = readFrameType(frameStack, 140.1367 - 0, 140.1368 - stackMap, 140.1369 - c, 140.1370 - labels); 140.1371 - frameMode = Opcodes.F_SAME1; 140.1372 - frameStackCount = 1; 140.1373 - } 140.1374 - else 140.1375 - { 140.1376 - delta = readUnsignedShort(stackMap); 140.1377 - stackMap += 2; 140.1378 - if(tag == MethodWriter.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) 140.1379 - { 140.1380 - stackMap = readFrameType(frameStack, 140.1381 - 0, 140.1382 - stackMap, 140.1383 - c, 140.1384 - labels); 140.1385 - frameMode = Opcodes.F_SAME1; 140.1386 - frameStackCount = 1; 140.1387 - } 140.1388 - else if(tag >= MethodWriter.CHOP_FRAME 140.1389 - && tag < MethodWriter.SAME_FRAME_EXTENDED) 140.1390 - { 140.1391 - frameMode = Opcodes.F_CHOP; 140.1392 - frameLocalDiff = MethodWriter.SAME_FRAME_EXTENDED 140.1393 - - tag; 140.1394 - frameLocalCount -= frameLocalDiff; 140.1395 - frameStackCount = 0; 140.1396 - } 140.1397 - else if(tag == MethodWriter.SAME_FRAME_EXTENDED) 140.1398 - { 140.1399 - frameMode = Opcodes.F_SAME; 140.1400 - frameStackCount = 0; 140.1401 - } 140.1402 - else if(tag < MethodWriter.FULL_FRAME) 140.1403 - { 140.1404 - j = unzip ? frameLocalCount : 0; 140.1405 - for(k = tag 140.1406 - - MethodWriter.SAME_FRAME_EXTENDED; k > 0; k--) 140.1407 - { 140.1408 - stackMap = readFrameType(frameLocal, 140.1409 - j++, 140.1410 - stackMap, 140.1411 - c, 140.1412 - labels); 140.1413 - } 140.1414 - frameMode = Opcodes.F_APPEND; 140.1415 - frameLocalDiff = tag 140.1416 - - MethodWriter.SAME_FRAME_EXTENDED; 140.1417 - frameLocalCount += frameLocalDiff; 140.1418 - frameStackCount = 0; 140.1419 - } 140.1420 - else 140.1421 - { // if (tag == FULL_FRAME) { 140.1422 - frameMode = Opcodes.F_FULL; 140.1423 - n = frameLocalDiff = frameLocalCount = readUnsignedShort(stackMap); 140.1424 - stackMap += 2; 140.1425 - for(j = 0; n > 0; n--) 140.1426 - { 140.1427 - stackMap = readFrameType(frameLocal, 140.1428 - j++, 140.1429 - stackMap, 140.1430 - c, 140.1431 - labels); 140.1432 - } 140.1433 - n = frameStackCount = readUnsignedShort(stackMap); 140.1434 - stackMap += 2; 140.1435 - for(j = 0; n > 0; n--) 140.1436 - { 140.1437 - stackMap = readFrameType(frameStack, 140.1438 - j++, 140.1439 - stackMap, 140.1440 - c, 140.1441 - labels); 140.1442 - } 140.1443 - } 140.1444 - } 140.1445 - frameOffset += delta + 1; 140.1446 - if(labels[frameOffset] == null) 140.1447 - { 140.1448 - labels[frameOffset] = new Label(); 140.1449 - } 140.1450 - 140.1451 - --frameCount; 140.1452 - } 140.1453 - else 140.1454 - { 140.1455 - frameLocal = null; 140.1456 - } 140.1457 - } 140.1458 - 140.1459 - int opcode = b[v] & 0xFF; 140.1460 - switch(ClassWriter.TYPE[opcode]) 140.1461 - { 140.1462 - case ClassWriter.NOARG_INSN: 140.1463 - mv.visitInsn(opcode); 140.1464 - v += 1; 140.1465 - break; 140.1466 - case ClassWriter.IMPLVAR_INSN: 140.1467 - if(opcode > Opcodes.ISTORE) 140.1468 - { 140.1469 - opcode -= 59; // ISTORE_0 140.1470 - mv.visitVarInsn(Opcodes.ISTORE + (opcode >> 2), 140.1471 - opcode & 0x3); 140.1472 - } 140.1473 - else 140.1474 - { 140.1475 - opcode -= 26; // ILOAD_0 140.1476 - mv.visitVarInsn(Opcodes.ILOAD + (opcode >> 2), 140.1477 - opcode & 0x3); 140.1478 - } 140.1479 - v += 1; 140.1480 - break; 140.1481 - case ClassWriter.LABEL_INSN: 140.1482 - mv.visitJumpInsn(opcode, labels[w 140.1483 - + readShort(v + 1)]); 140.1484 - v += 3; 140.1485 - break; 140.1486 - case ClassWriter.LABELW_INSN: 140.1487 - mv.visitJumpInsn(opcode - 33, labels[w 140.1488 - + readInt(v + 1)]); 140.1489 - v += 5; 140.1490 - break; 140.1491 - case ClassWriter.WIDE_INSN: 140.1492 - opcode = b[v + 1] & 0xFF; 140.1493 - if(opcode == Opcodes.IINC) 140.1494 - { 140.1495 - mv.visitIincInsn(readUnsignedShort(v + 2), 140.1496 - readShort(v + 4)); 140.1497 - v += 6; 140.1498 - } 140.1499 - else 140.1500 - { 140.1501 - mv.visitVarInsn(opcode, 140.1502 - readUnsignedShort(v + 2)); 140.1503 - v += 4; 140.1504 - } 140.1505 - break; 140.1506 - case ClassWriter.TABL_INSN: 140.1507 - // skips 0 to 3 padding bytes 140.1508 - v = v + 4 - (w & 3); 140.1509 - // reads instruction 140.1510 - label = w + readInt(v); 140.1511 - int min = readInt(v + 4); 140.1512 - int max = readInt(v + 8); 140.1513 - v += 12; 140.1514 - Label[] table = new Label[max - min + 1]; 140.1515 - for(j = 0; j < table.length; ++j) 140.1516 - { 140.1517 - table[j] = labels[w + readInt(v)]; 140.1518 - v += 4; 140.1519 - } 140.1520 - mv.visitTableSwitchInsn(min, 140.1521 - max, 140.1522 - labels[label], 140.1523 - table); 140.1524 - break; 140.1525 - case ClassWriter.LOOK_INSN: 140.1526 - // skips 0 to 3 padding bytes 140.1527 - v = v + 4 - (w & 3); 140.1528 - // reads instruction 140.1529 - label = w + readInt(v); 140.1530 - j = readInt(v + 4); 140.1531 - v += 8; 140.1532 - int[] keys = new int[j]; 140.1533 - Label[] values = new Label[j]; 140.1534 - for(j = 0; j < keys.length; ++j) 140.1535 - { 140.1536 - keys[j] = readInt(v); 140.1537 - values[j] = labels[w + readInt(v + 4)]; 140.1538 - v += 8; 140.1539 - } 140.1540 - mv.visitLookupSwitchInsn(labels[label], 140.1541 - keys, 140.1542 - values); 140.1543 - break; 140.1544 - case ClassWriter.VAR_INSN: 140.1545 - mv.visitVarInsn(opcode, b[v + 1] & 0xFF); 140.1546 - v += 2; 140.1547 - break; 140.1548 - case ClassWriter.SBYTE_INSN: 140.1549 - mv.visitIntInsn(opcode, b[v + 1]); 140.1550 - v += 2; 140.1551 - break; 140.1552 - case ClassWriter.SHORT_INSN: 140.1553 - mv.visitIntInsn(opcode, readShort(v + 1)); 140.1554 - v += 3; 140.1555 - break; 140.1556 - case ClassWriter.LDC_INSN: 140.1557 - mv.visitLdcInsn(readConst(b[v + 1] & 0xFF, c)); 140.1558 - v += 2; 140.1559 - break; 140.1560 - case ClassWriter.LDCW_INSN: 140.1561 - mv.visitLdcInsn(readConst(readUnsignedShort(v + 1), 140.1562 - c)); 140.1563 - v += 3; 140.1564 - break; 140.1565 - case ClassWriter.FIELDORMETH_INSN: 140.1566 - case ClassWriter.ITFMETH_INSN: 140.1567 - int cpIndex = items[readUnsignedShort(v + 1)]; 140.1568 - String iowner = readClass(cpIndex, c); 140.1569 - cpIndex = items[readUnsignedShort(cpIndex + 2)]; 140.1570 - String iname = readUTF8(cpIndex, c); 140.1571 - String idesc = readUTF8(cpIndex + 2, c); 140.1572 - if(opcode < Opcodes.INVOKEVIRTUAL) 140.1573 - { 140.1574 - mv.visitFieldInsn(opcode, iowner, iname, idesc); 140.1575 - } 140.1576 - else 140.1577 - { 140.1578 - mv.visitMethodInsn(opcode, iowner, iname, idesc); 140.1579 - } 140.1580 - if(opcode == Opcodes.INVOKEINTERFACE) 140.1581 - { 140.1582 - v += 5; 140.1583 - } 140.1584 - else 140.1585 - { 140.1586 - v += 3; 140.1587 - } 140.1588 - break; 140.1589 - case ClassWriter.TYPE_INSN: 140.1590 - mv.visitTypeInsn(opcode, readClass(v + 1, c)); 140.1591 - v += 3; 140.1592 - break; 140.1593 - case ClassWriter.IINC_INSN: 140.1594 - mv.visitIincInsn(b[v + 1] & 0xFF, b[v + 2]); 140.1595 - v += 3; 140.1596 - break; 140.1597 - // case MANA_INSN: 140.1598 - default: 140.1599 - mv.visitMultiANewArrayInsn(readClass(v + 1, c), 140.1600 - b[v + 3] & 0xFF); 140.1601 - v += 4; 140.1602 - break; 140.1603 - } 140.1604 - } 140.1605 - l = labels[codeEnd - codeStart]; 140.1606 - if(l != null) 140.1607 - { 140.1608 - mv.visitLabel(l); 140.1609 - } 140.1610 - // visits the local variable tables 140.1611 - if(!skipDebug && varTable != 0) 140.1612 - { 140.1613 - int[] typeTable = null; 140.1614 - if(varTypeTable != 0) 140.1615 - { 140.1616 - k = readUnsignedShort(varTypeTable) * 3; 140.1617 - w = varTypeTable + 2; 140.1618 - typeTable = new int[k]; 140.1619 - while(k > 0) 140.1620 - { 140.1621 - typeTable[--k] = w + 6; // signature 140.1622 - typeTable[--k] = readUnsignedShort(w + 8); // index 140.1623 - typeTable[--k] = readUnsignedShort(w); // start 140.1624 - w += 10; 140.1625 - } 140.1626 - } 140.1627 - k = readUnsignedShort(varTable); 140.1628 - w = varTable + 2; 140.1629 - for(; k > 0; --k) 140.1630 - { 140.1631 - int start = readUnsignedShort(w); 140.1632 - int length = readUnsignedShort(w + 2); 140.1633 - int index = readUnsignedShort(w + 8); 140.1634 - String vsignature = null; 140.1635 - if(typeTable != null) 140.1636 - { 140.1637 - for(int a = 0; a < typeTable.length; a += 3) 140.1638 - { 140.1639 - if(typeTable[a] == start 140.1640 - && typeTable[a + 1] == index) 140.1641 - { 140.1642 - vsignature = readUTF8(typeTable[a + 2], c); 140.1643 - break; 140.1644 - } 140.1645 - } 140.1646 - } 140.1647 - mv.visitLocalVariable(readUTF8(w + 4, c), 140.1648 - readUTF8(w + 6, c), 140.1649 - vsignature, 140.1650 - labels[start], 140.1651 - labels[start + length], 140.1652 - index); 140.1653 - w += 10; 140.1654 - } 140.1655 - } 140.1656 - // visits the other attributes 140.1657 - while(cattrs != null) 140.1658 - { 140.1659 - attr = cattrs.next; 140.1660 - cattrs.next = null; 140.1661 - mv.visitAttribute(cattrs); 140.1662 - cattrs = attr; 140.1663 - } 140.1664 - // visits the max stack and max locals values 140.1665 - mv.visitMaxs(maxStack, maxLocals); 140.1666 - } 140.1667 - 140.1668 - if(mv != null) 140.1669 - { 140.1670 - mv.visitEnd(); 140.1671 - } 140.1672 - } 140.1673 - 140.1674 - // visits the end of the class 140.1675 - classVisitor.visitEnd(); 140.1676 -} 140.1677 - 140.1678 -/** 140.1679 - * Reads parameter annotations and makes the given visitor visit them. 140.1680 - * 140.1681 - * @param v start offset in {@link #b b} of the annotations to be read. 140.1682 - * @param buf buffer to be used to call {@link #readUTF8 readUTF8}, 140.1683 - * {@link #readClass(int,char[]) readClass} or 140.1684 - * {@link #readConst readConst}. 140.1685 - * @param visible <tt>true</tt> if the annotations to be read are visible 140.1686 - * at runtime. 140.1687 - * @param mv the visitor that must visit the annotations. 140.1688 - */ 140.1689 -private void readParameterAnnotations( 140.1690 - int v, 140.1691 - final char[] buf, 140.1692 - final boolean visible, 140.1693 - final MethodVisitor mv){ 140.1694 - int n = b[v++] & 0xFF; 140.1695 - for(int i = 0; i < n; ++i) 140.1696 - { 140.1697 - int j = readUnsignedShort(v); 140.1698 - v += 2; 140.1699 - for(; j > 0; --j) 140.1700 - { 140.1701 - v = readAnnotationValues(v + 2, 140.1702 - buf, 140.1703 - true, 140.1704 - mv.visitParameterAnnotation(i, 140.1705 - readUTF8(v, buf), 140.1706 - visible)); 140.1707 - } 140.1708 - } 140.1709 -} 140.1710 - 140.1711 -/** 140.1712 - * Reads the values of an annotation and makes the given visitor visit them. 140.1713 - * 140.1714 - * @param v the start offset in {@link #b b} of the values to be read 140.1715 - * (including the unsigned short that gives the number of values). 140.1716 - * @param buf buffer to be used to call {@link #readUTF8 readUTF8}, 140.1717 - * {@link #readClass(int,char[]) readClass} or 140.1718 - * {@link #readConst readConst}. 140.1719 - * @param named if the annotation values are named or not. 140.1720 - * @param av the visitor that must visit the values. 140.1721 - * @return the end offset of the annotation values. 140.1722 - */ 140.1723 -private int readAnnotationValues( 140.1724 - int v, 140.1725 - final char[] buf, 140.1726 - final boolean named, 140.1727 - final AnnotationVisitor av){ 140.1728 - int i = readUnsignedShort(v); 140.1729 - v += 2; 140.1730 - if(named) 140.1731 - { 140.1732 - for(; i > 0; --i) 140.1733 - { 140.1734 - v = readAnnotationValue(v + 2, buf, readUTF8(v, buf), av); 140.1735 - } 140.1736 - } 140.1737 - else 140.1738 - { 140.1739 - for(; i > 0; --i) 140.1740 - { 140.1741 - v = readAnnotationValue(v, buf, null, av); 140.1742 - } 140.1743 - } 140.1744 - if(av != null) 140.1745 - { 140.1746 - av.visitEnd(); 140.1747 - } 140.1748 - return v; 140.1749 -} 140.1750 - 140.1751 -/** 140.1752 - * Reads a value of an annotation and makes the given visitor visit it. 140.1753 - * 140.1754 - * @param v the start offset in {@link #b b} of the value to be read (<i>not 140.1755 - * including the value name constant pool index</i>). 140.1756 - * @param buf buffer to be used to call {@link #readUTF8 readUTF8}, 140.1757 - * {@link #readClass(int,char[]) readClass} or 140.1758 - * {@link #readConst readConst}. 140.1759 - * @param name the name of the value to be read. 140.1760 - * @param av the visitor that must visit the value. 140.1761 - * @return the end offset of the annotation value. 140.1762 - */ 140.1763 -private int readAnnotationValue( 140.1764 - int v, 140.1765 - final char[] buf, 140.1766 - final String name, 140.1767 - final AnnotationVisitor av){ 140.1768 - int i; 140.1769 - if(av == null) 140.1770 - { 140.1771 - switch(b[v] & 0xFF) 140.1772 - { 140.1773 - case'e': // enum_const_value 140.1774 - return v + 5; 140.1775 - case'@': // annotation_value 140.1776 - return readAnnotationValues(v + 3, buf, true, null); 140.1777 - case'[': // array_value 140.1778 - return readAnnotationValues(v + 1, buf, false, null); 140.1779 - default: 140.1780 - return v + 3; 140.1781 - } 140.1782 - } 140.1783 - switch(b[v++] & 0xFF) 140.1784 - { 140.1785 - case'I': // pointer to CONSTANT_Integer 140.1786 - case'J': // pointer to CONSTANT_Long 140.1787 - case'F': // pointer to CONSTANT_Float 140.1788 - case'D': // pointer to CONSTANT_Double 140.1789 - av.visit(name, readConst(readUnsignedShort(v), buf)); 140.1790 - v += 2; 140.1791 - break; 140.1792 - case'B': // pointer to CONSTANT_Byte 140.1793 - av.visit(name, 140.1794 - new Byte((byte) readInt(items[readUnsignedShort(v)]))); 140.1795 - v += 2; 140.1796 - break; 140.1797 - case'Z': // pointer to CONSTANT_Boolean 140.1798 - av.visit(name, readInt(items[readUnsignedShort(v)]) == 0 140.1799 - ? Boolean.FALSE 140.1800 - : Boolean.TRUE); 140.1801 - v += 2; 140.1802 - break; 140.1803 - case'S': // pointer to CONSTANT_Short 140.1804 - av.visit(name, 140.1805 - new Short((short) readInt(items[readUnsignedShort(v)]))); 140.1806 - v += 2; 140.1807 - break; 140.1808 - case'C': // pointer to CONSTANT_Char 140.1809 - av.visit(name, 140.1810 - new Character((char) readInt(items[readUnsignedShort(v)]))); 140.1811 - v += 2; 140.1812 - break; 140.1813 - case's': // pointer to CONSTANT_Utf8 140.1814 - av.visit(name, readUTF8(v, buf)); 140.1815 - v += 2; 140.1816 - break; 140.1817 - case'e': // enum_const_value 140.1818 - av.visitEnum(name, readUTF8(v, buf), readUTF8(v + 2, buf)); 140.1819 - v += 4; 140.1820 - break; 140.1821 - case'c': // class_info 140.1822 - av.visit(name, Type.getType(readUTF8(v, buf))); 140.1823 - v += 2; 140.1824 - break; 140.1825 - case'@': // annotation_value 140.1826 - v = readAnnotationValues(v + 2, 140.1827 - buf, 140.1828 - true, 140.1829 - av.visitAnnotation(name, readUTF8(v, buf))); 140.1830 - break; 140.1831 - case'[': // array_value 140.1832 - int size = readUnsignedShort(v); 140.1833 - v += 2; 140.1834 - if(size == 0) 140.1835 - { 140.1836 - return readAnnotationValues(v - 2, 140.1837 - buf, 140.1838 - false, 140.1839 - av.visitArray(name)); 140.1840 - } 140.1841 - switch(this.b[v++] & 0xFF) 140.1842 - { 140.1843 - case'B': 140.1844 - byte[] bv = new byte[size]; 140.1845 - for(i = 0; i < size; i++) 140.1846 - { 140.1847 - bv[i] = (byte) readInt(items[readUnsignedShort(v)]); 140.1848 - v += 3; 140.1849 - } 140.1850 - av.visit(name, bv); 140.1851 - --v; 140.1852 - break; 140.1853 - case'Z': 140.1854 - boolean[] zv = new boolean[size]; 140.1855 - for(i = 0; i < size; i++) 140.1856 - { 140.1857 - zv[i] = readInt(items[readUnsignedShort(v)]) != 0; 140.1858 - v += 3; 140.1859 - } 140.1860 - av.visit(name, zv); 140.1861 - --v; 140.1862 - break; 140.1863 - case'S': 140.1864 - short[] sv = new short[size]; 140.1865 - for(i = 0; i < size; i++) 140.1866 - { 140.1867 - sv[i] = (short) readInt(items[readUnsignedShort(v)]); 140.1868 - v += 3; 140.1869 - } 140.1870 - av.visit(name, sv); 140.1871 - --v; 140.1872 - break; 140.1873 - case'C': 140.1874 - char[] cv = new char[size]; 140.1875 - for(i = 0; i < size; i++) 140.1876 - { 140.1877 - cv[i] = (char) readInt(items[readUnsignedShort(v)]); 140.1878 - v += 3; 140.1879 - } 140.1880 - av.visit(name, cv); 140.1881 - --v; 140.1882 - break; 140.1883 - case'I': 140.1884 - int[] iv = new int[size]; 140.1885 - for(i = 0; i < size; i++) 140.1886 - { 140.1887 - iv[i] = readInt(items[readUnsignedShort(v)]); 140.1888 - v += 3; 140.1889 - } 140.1890 - av.visit(name, iv); 140.1891 - --v; 140.1892 - break; 140.1893 - case'J': 140.1894 - long[] lv = new long[size]; 140.1895 - for(i = 0; i < size; i++) 140.1896 - { 140.1897 - lv[i] = readLong(items[readUnsignedShort(v)]); 140.1898 - v += 3; 140.1899 - } 140.1900 - av.visit(name, lv); 140.1901 - --v; 140.1902 - break; 140.1903 - case'F': 140.1904 - float[] fv = new float[size]; 140.1905 - for(i = 0; i < size; i++) 140.1906 - { 140.1907 - fv[i] = Float.intBitsToFloat(readInt(items[readUnsignedShort(v)])); 140.1908 - v += 3; 140.1909 - } 140.1910 - av.visit(name, fv); 140.1911 - --v; 140.1912 - break; 140.1913 - case'D': 140.1914 - double[] dv = new double[size]; 140.1915 - for(i = 0; i < size; i++) 140.1916 - { 140.1917 - dv[i] = Double.longBitsToDouble(readLong(items[readUnsignedShort(v)])); 140.1918 - v += 3; 140.1919 - } 140.1920 - av.visit(name, dv); 140.1921 - --v; 140.1922 - break; 140.1923 - default: 140.1924 - v = readAnnotationValues(v - 3, 140.1925 - buf, 140.1926 - false, 140.1927 - av.visitArray(name)); 140.1928 - } 140.1929 - } 140.1930 - return v; 140.1931 -} 140.1932 - 140.1933 -private int readFrameType( 140.1934 - final Object[] frame, 140.1935 - final int index, 140.1936 - int v, 140.1937 - final char[] buf, 140.1938 - final Label[] labels){ 140.1939 - int type = b[v++] & 0xFF; 140.1940 - switch(type) 140.1941 - { 140.1942 - case 0: 140.1943 - frame[index] = Opcodes.TOP; 140.1944 - break; 140.1945 - case 1: 140.1946 - frame[index] = Opcodes.INTEGER; 140.1947 - break; 140.1948 - case 2: 140.1949 - frame[index] = Opcodes.FLOAT; 140.1950 - break; 140.1951 - case 3: 140.1952 - frame[index] = Opcodes.DOUBLE; 140.1953 - break; 140.1954 - case 4: 140.1955 - frame[index] = Opcodes.LONG; 140.1956 - break; 140.1957 - case 5: 140.1958 - frame[index] = Opcodes.NULL; 140.1959 - break; 140.1960 - case 6: 140.1961 - frame[index] = Opcodes.UNINITIALIZED_THIS; 140.1962 - break; 140.1963 - case 7: // Object 140.1964 - frame[index] = readClass(v, buf); 140.1965 - v += 2; 140.1966 - break; 140.1967 - default: // Uninitialized 140.1968 - int offset = readUnsignedShort(v); 140.1969 - if(labels[offset] == null) 140.1970 - { 140.1971 - labels[offset] = new Label(); 140.1972 - } 140.1973 - frame[index] = labels[offset]; 140.1974 - v += 2; 140.1975 - } 140.1976 - return v; 140.1977 -} 140.1978 - 140.1979 -/** 140.1980 - * Reads an attribute in {@link #b b}. 140.1981 - * 140.1982 - * @param attrs prototypes of the attributes that must be parsed during the 140.1983 - * visit of the class. Any attribute whose type is not equal to the 140.1984 - * type of one the prototypes is ignored (i.e. an empty 140.1985 - * {@link Attribute} instance is returned). 140.1986 - * @param type the type of the attribute. 140.1987 - * @param off index of the first byte of the attribute's content in 140.1988 - * {@link #b b}. The 6 attribute header bytes, containing the type 140.1989 - * and the length of the attribute, are not taken into account here 140.1990 - * (they have already been read). 140.1991 - * @param len the length of the attribute's content. 140.1992 - * @param buf buffer to be used to call {@link #readUTF8 readUTF8}, 140.1993 - * {@link #readClass(int,char[]) readClass} or 140.1994 - * {@link #readConst readConst}. 140.1995 - * @param codeOff index of the first byte of code's attribute content in 140.1996 - * {@link #b b}, or -1 if the attribute to be read is not a code 140.1997 - * attribute. The 6 attribute header bytes, containing the type and 140.1998 - * the length of the attribute, are not taken into account here. 140.1999 - * @param labels the labels of the method's code, or <tt>null</tt> if the 140.2000 - * attribute to be read is not a code attribute. 140.2001 - * @return the attribute that has been read, or <tt>null</tt> to skip this 140.2002 - * attribute. 140.2003 - */ 140.2004 -private Attribute readAttribute( 140.2005 - final Attribute[] attrs, 140.2006 - final String type, 140.2007 - final int off, 140.2008 - final int len, 140.2009 - final char[] buf, 140.2010 - final int codeOff, 140.2011 - final Label[] labels){ 140.2012 - for(int i = 0; i < attrs.length; ++i) 140.2013 - { 140.2014 - if(attrs[i].type.equals(type)) 140.2015 - { 140.2016 - return attrs[i].read(this, off, len, buf, codeOff, labels); 140.2017 - } 140.2018 - } 140.2019 - return new Attribute(type).read(this, off, len, null, -1, null); 140.2020 -} 140.2021 - 140.2022 -// ------------------------------------------------------------------------ 140.2023 -// Utility methods: low level parsing 140.2024 -// ------------------------------------------------------------------------ 140.2025 - 140.2026 -/** 140.2027 - * Returns the start index of the constant pool item in {@link #b b}, plus 140.2028 - * one. <i>This method is intended for {@link Attribute} sub classes, and is 140.2029 - * normally not needed by class generators or adapters.</i> 140.2030 - * 140.2031 - * @param item the index a constant pool item. 140.2032 - * @return the start index of the constant pool item in {@link #b b}, plus 140.2033 - * one. 140.2034 - */ 140.2035 -public int getItem(final int item){ 140.2036 - return items[item]; 140.2037 -} 140.2038 - 140.2039 -/** 140.2040 - * Reads a byte value in {@link #b b}. <i>This method is intended for 140.2041 - * {@link Attribute} sub classes, and is normally not needed by class 140.2042 - * generators or adapters.</i> 140.2043 - * 140.2044 - * @param index the start index of the value to be read in {@link #b b}. 140.2045 - * @return the read value. 140.2046 - */ 140.2047 -public int readByte(final int index){ 140.2048 - return b[index] & 0xFF; 140.2049 -} 140.2050 - 140.2051 -/** 140.2052 - * Reads an unsigned short value in {@link #b b}. <i>This method is 140.2053 - * intended for {@link Attribute} sub classes, and is normally not needed by 140.2054 - * class generators or adapters.</i> 140.2055 - * 140.2056 - * @param index the start index of the value to be read in {@link #b b}. 140.2057 - * @return the read value. 140.2058 - */ 140.2059 -public int readUnsignedShort(final int index){ 140.2060 - byte[] b = this.b; 140.2061 - return ((b[index] & 0xFF) << 8) | (b[index + 1] & 0xFF); 140.2062 -} 140.2063 - 140.2064 -/** 140.2065 - * Reads a signed short value in {@link #b b}. <i>This method is intended 140.2066 - * for {@link Attribute} sub classes, and is normally not needed by class 140.2067 - * generators or adapters.</i> 140.2068 - * 140.2069 - * @param index the start index of the value to be read in {@link #b b}. 140.2070 - * @return the read value. 140.2071 - */ 140.2072 -public short readShort(final int index){ 140.2073 - byte[] b = this.b; 140.2074 - return (short) (((b[index] & 0xFF) << 8) | (b[index + 1] & 0xFF)); 140.2075 -} 140.2076 - 140.2077 -/** 140.2078 - * Reads a signed int value in {@link #b b}. <i>This method is intended for 140.2079 - * {@link Attribute} sub classes, and is normally not needed by class 140.2080 - * generators or adapters.</i> 140.2081 - * 140.2082 - * @param index the start index of the value to be read in {@link #b b}. 140.2083 - * @return the read value. 140.2084 - */ 140.2085 -public int readInt(final int index){ 140.2086 - byte[] b = this.b; 140.2087 - return ((b[index] & 0xFF) << 24) | ((b[index + 1] & 0xFF) << 16) 140.2088 - | ((b[index + 2] & 0xFF) << 8) | (b[index + 3] & 0xFF); 140.2089 -} 140.2090 - 140.2091 -/** 140.2092 - * Reads a signed long value in {@link #b b}. <i>This method is intended 140.2093 - * for {@link Attribute} sub classes, and is normally not needed by class 140.2094 - * generators or adapters.</i> 140.2095 - * 140.2096 - * @param index the start index of the value to be read in {@link #b b}. 140.2097 - * @return the read value. 140.2098 - */ 140.2099 -public long readLong(final int index){ 140.2100 - long l1 = readInt(index); 140.2101 - long l0 = readInt(index + 4) & 0xFFFFFFFFL; 140.2102 - return (l1 << 32) | l0; 140.2103 -} 140.2104 - 140.2105 -/** 140.2106 - * Reads an UTF8 string constant pool item in {@link #b b}. <i>This method 140.2107 - * is intended for {@link Attribute} sub classes, and is normally not needed 140.2108 - * by class generators or adapters.</i> 140.2109 - * 140.2110 - * @param index the start index of an unsigned short value in {@link #b b}, 140.2111 - * whose value is the index of an UTF8 constant pool item. 140.2112 - * @param buf buffer to be used to read the item. This buffer must be 140.2113 - * sufficiently large. It is not automatically resized. 140.2114 - * @return the String corresponding to the specified UTF8 item. 140.2115 - */ 140.2116 -public String readUTF8(int index, final char[] buf){ 140.2117 - int item = readUnsignedShort(index); 140.2118 - String s = strings[item]; 140.2119 - if(s != null) 140.2120 - { 140.2121 - return s; 140.2122 - } 140.2123 - index = items[item]; 140.2124 - return strings[item] = readUTF(index + 2, readUnsignedShort(index), buf); 140.2125 -} 140.2126 - 140.2127 -/** 140.2128 - * Reads UTF8 string in {@link #b b}. 140.2129 - * 140.2130 - * @param index start offset of the UTF8 string to be read. 140.2131 - * @param utfLen length of the UTF8 string to be read. 140.2132 - * @param buf buffer to be used to read the string. This buffer must be 140.2133 - * sufficiently large. It is not automatically resized. 140.2134 - * @return the String corresponding to the specified UTF8 string. 140.2135 - */ 140.2136 -private String readUTF(int index, final int utfLen, final char[] buf){ 140.2137 - int endIndex = index + utfLen; 140.2138 - byte[] b = this.b; 140.2139 - int strLen = 0; 140.2140 - int c, d, e; 140.2141 - while(index < endIndex) 140.2142 - { 140.2143 - c = b[index++] & 0xFF; 140.2144 - switch(c >> 4) 140.2145 - { 140.2146 - case 0: 140.2147 - case 1: 140.2148 - case 2: 140.2149 - case 3: 140.2150 - case 4: 140.2151 - case 5: 140.2152 - case 6: 140.2153 - case 7: 140.2154 - // 0xxxxxxx 140.2155 - buf[strLen++] = (char) c; 140.2156 - break; 140.2157 - case 12: 140.2158 - case 13: 140.2159 - // 110x xxxx 10xx xxxx 140.2160 - d = b[index++]; 140.2161 - buf[strLen++] = (char) (((c & 0x1F) << 6) | (d & 0x3F)); 140.2162 - break; 140.2163 - default: 140.2164 - // 1110 xxxx 10xx xxxx 10xx xxxx 140.2165 - d = b[index++]; 140.2166 - e = b[index++]; 140.2167 - buf[strLen++] = (char) (((c & 0x0F) << 12) 140.2168 - | ((d & 0x3F) << 6) | (e & 0x3F)); 140.2169 - break; 140.2170 - } 140.2171 - } 140.2172 - return new String(buf, 0, strLen); 140.2173 -} 140.2174 - 140.2175 -/** 140.2176 - * Reads a class constant pool item in {@link #b b}. <i>This method is 140.2177 - * intended for {@link Attribute} sub classes, and is normally not needed by 140.2178 - * class generators or adapters.</i> 140.2179 - * 140.2180 - * @param index the start index of an unsigned short value in {@link #b b}, 140.2181 - * whose value is the index of a class constant pool item. 140.2182 - * @param buf buffer to be used to read the item. This buffer must be 140.2183 - * sufficiently large. It is not automatically resized. 140.2184 - * @return the String corresponding to the specified class item. 140.2185 - */ 140.2186 -public String readClass(final int index, final char[] buf){ 140.2187 - // computes the start index of the CONSTANT_Class item in b 140.2188 - // and reads the CONSTANT_Utf8 item designated by 140.2189 - // the first two bytes of this CONSTANT_Class item 140.2190 - return readUTF8(items[readUnsignedShort(index)], buf); 140.2191 -} 140.2192 - 140.2193 -/** 140.2194 - * Reads a numeric or string constant pool item in {@link #b b}. <i>This 140.2195 - * method is intended for {@link Attribute} sub classes, and is normally not 140.2196 - * needed by class generators or adapters.</i> 140.2197 - * 140.2198 - * @param item the index of a constant pool item. 140.2199 - * @param buf buffer to be used to read the item. This buffer must be 140.2200 - * sufficiently large. It is not automatically resized. 140.2201 - * @return the {@link Integer}, {@link Float}, {@link Long}, 140.2202 - * {@link Double}, {@link String} or {@link Type} corresponding to 140.2203 - * the given constant pool item. 140.2204 - */ 140.2205 -public Object readConst(final int item, final char[] buf){ 140.2206 - int index = items[item]; 140.2207 - switch(b[index - 1]) 140.2208 - { 140.2209 - case ClassWriter.INT: 140.2210 - return new Integer(readInt(index)); 140.2211 - case ClassWriter.FLOAT: 140.2212 - return new Float(Float.intBitsToFloat(readInt(index))); 140.2213 - case ClassWriter.LONG: 140.2214 - return new Long(readLong(index)); 140.2215 - case ClassWriter.DOUBLE: 140.2216 - return new Double(Double.longBitsToDouble(readLong(index))); 140.2217 - case ClassWriter.CLASS: 140.2218 - String s = readUTF8(index, buf); 140.2219 - return s.charAt(0) == '[' 140.2220 - ? Type.getType(s) 140.2221 - : Type.getObjectType(s); 140.2222 - // case ClassWriter.STR: 140.2223 - default: 140.2224 - return readUTF8(index, buf); 140.2225 - } 140.2226 -} 140.2227 -}
141.1 --- a/src/clojure/asm/ClassVisitor.java Sat Aug 21 06:25:44 2010 -0400 141.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 141.3 @@ -1,196 +0,0 @@ 141.4 -/*** 141.5 - * ASM: a very small and fast Java bytecode manipulation framework 141.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 141.7 - * All rights reserved. 141.8 - * 141.9 - * Redistribution and use in source and binary forms, with or without 141.10 - * modification, are permitted provided that the following conditions 141.11 - * are met: 141.12 - * 1. Redistributions of source code must retain the above copyright 141.13 - * notice, this list of conditions and the following disclaimer. 141.14 - * 2. Redistributions in binary form must reproduce the above copyright 141.15 - * notice, this list of conditions and the following disclaimer in the 141.16 - * documentation and/or other materials provided with the distribution. 141.17 - * 3. Neither the name of the copyright holders nor the names of its 141.18 - * contributors may be used to endorse or promote products derived from 141.19 - * this software without specific prior written permission. 141.20 - * 141.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 141.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 141.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 141.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 141.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 141.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 141.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 141.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 141.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 141.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 141.31 - * THE POSSIBILITY OF SUCH DAMAGE. 141.32 - */ 141.33 -package clojure.asm; 141.34 - 141.35 -/** 141.36 - * A visitor to visit a Java class. The methods of this interface must be called 141.37 - * in the following order: <tt>visit</tt> [ <tt>visitSource</tt> ] [ 141.38 - * <tt>visitOuterClass</tt> ] ( <tt>visitAnnotation</tt> | 141.39 - * <tt>visitAttribute</tt> )* (<tt>visitInnerClass</tt> | 141.40 - * <tt>visitField</tt> | <tt>visitMethod</tt> )* <tt>visitEnd</tt>. 141.41 - * 141.42 - * @author Eric Bruneton 141.43 - */ 141.44 -public interface ClassVisitor{ 141.45 - 141.46 -/** 141.47 - * Visits the header of the class. 141.48 - * 141.49 - * @param version the class version. 141.50 - * @param access the class's access flags (see {@link Opcodes}). This 141.51 - * parameter also indicates if the class is deprecated. 141.52 - * @param name the internal name of the class (see 141.53 - * {@link Type#getInternalName() getInternalName}). 141.54 - * @param signature the signature of this class. May be <tt>null</tt> if 141.55 - * the class is not a generic one, and does not extend or implement 141.56 - * generic classes or interfaces. 141.57 - * @param superName the internal of name of the super class (see 141.58 - * {@link Type#getInternalName() getInternalName}). For interfaces, 141.59 - * the super class is {@link Object}. May be <tt>null</tt>, but 141.60 - * only for the {@link Object} class. 141.61 - * @param interfaces the internal names of the class's interfaces (see 141.62 - * {@link Type#getInternalName() getInternalName}). May be 141.63 - * <tt>null</tt>. 141.64 - */ 141.65 -void visit( 141.66 - int version, 141.67 - int access, 141.68 - String name, 141.69 - String signature, 141.70 - String superName, 141.71 - String[] interfaces); 141.72 - 141.73 -/** 141.74 - * Visits the source of the class. 141.75 - * 141.76 - * @param source the name of the source file from which the class was 141.77 - * compiled. May be <tt>null</tt>. 141.78 - * @param debug additional debug information to compute the correspondance 141.79 - * between source and compiled elements of the class. May be 141.80 - * <tt>null</tt>. 141.81 - */ 141.82 -void visitSource(String source, String debug); 141.83 - 141.84 -/** 141.85 - * Visits the enclosing class of the class. This method must be called only 141.86 - * if the class has an enclosing class. 141.87 - * 141.88 - * @param owner internal name of the enclosing class of the class. 141.89 - * @param name the name of the method that contains the class, or 141.90 - * <tt>null</tt> if the class is not enclosed in a method of its 141.91 - * enclosing class. 141.92 - * @param desc the descriptor of the method that contains the class, or 141.93 - * <tt>null</tt> if the class is not enclosed in a method of its 141.94 - * enclosing class. 141.95 - */ 141.96 -void visitOuterClass(String owner, String name, String desc); 141.97 - 141.98 -/** 141.99 - * Visits an annotation of the class. 141.100 - * 141.101 - * @param desc the class descriptor of the annotation class. 141.102 - * @param visible <tt>true</tt> if the annotation is visible at runtime. 141.103 - * @return a visitor to visit the annotation values, or <tt>null</tt> if 141.104 - * this visitor is not interested in visiting this annotation. 141.105 - */ 141.106 -AnnotationVisitor visitAnnotation(String desc, boolean visible); 141.107 - 141.108 -/** 141.109 - * Visits a non standard attribute of the class. 141.110 - * 141.111 - * @param attr an attribute. 141.112 - */ 141.113 -void visitAttribute(Attribute attr); 141.114 - 141.115 -/** 141.116 - * Visits information about an inner class. This inner class is not 141.117 - * necessarily a member of the class being visited. 141.118 - * 141.119 - * @param name the internal name of an inner class (see 141.120 - * {@link Type#getInternalName() getInternalName}). 141.121 - * @param outerName the internal name of the class to which the inner class 141.122 - * belongs (see {@link Type#getInternalName() getInternalName}). May 141.123 - * be <tt>null</tt> for not member classes. 141.124 - * @param innerName the (simple) name of the inner class inside its 141.125 - * enclosing class. May be <tt>null</tt> for anonymous inner 141.126 - * classes. 141.127 - * @param access the access flags of the inner class as originally declared 141.128 - * in the enclosing class. 141.129 - */ 141.130 -void visitInnerClass( 141.131 - String name, 141.132 - String outerName, 141.133 - String innerName, 141.134 - int access); 141.135 - 141.136 -/** 141.137 - * Visits a field of the class. 141.138 - * 141.139 - * @param access the field's access flags (see {@link Opcodes}). This 141.140 - * parameter also indicates if the field is synthetic and/or 141.141 - * deprecated. 141.142 - * @param name the field's name. 141.143 - * @param desc the field's descriptor (see {@link Type Type}). 141.144 - * @param signature the field's signature. May be <tt>null</tt> if the 141.145 - * field's type does not use generic types. 141.146 - * @param value the field's initial value. This parameter, which may be 141.147 - * <tt>null</tt> if the field does not have an initial value, must 141.148 - * be an {@link Integer}, a {@link Float}, a {@link Long}, a 141.149 - * {@link Double} or a {@link String} (for <tt>int</tt>, 141.150 - * <tt>float</tt>, <tt>long</tt> or <tt>String</tt> fields 141.151 - * respectively). <i>This parameter is only used for static fields</i>. 141.152 - * Its value is ignored for non static fields, which must be 141.153 - * initialized through bytecode instructions in constructors or 141.154 - * methods. 141.155 - * @return a visitor to visit field annotations and attributes, or 141.156 - * <tt>null</tt> if this class visitor is not interested in 141.157 - * visiting these annotations and attributes. 141.158 - */ 141.159 -FieldVisitor visitField( 141.160 - int access, 141.161 - String name, 141.162 - String desc, 141.163 - String signature, 141.164 - Object value); 141.165 - 141.166 -/** 141.167 - * Visits a method of the class. This method <i>must</i> return a new 141.168 - * {@link MethodVisitor} instance (or <tt>null</tt>) each time it is 141.169 - * called, i.e., it should not return a previously returned visitor. 141.170 - * 141.171 - * @param access the method's access flags (see {@link Opcodes}). This 141.172 - * parameter also indicates if the method is synthetic and/or 141.173 - * deprecated. 141.174 - * @param name the method's name. 141.175 - * @param desc the method's descriptor (see {@link Type Type}). 141.176 - * @param signature the method's signature. May be <tt>null</tt> if the 141.177 - * method parameters, return type and exceptions do not use generic 141.178 - * types. 141.179 - * @param exceptions the internal names of the method's exception classes 141.180 - * (see {@link Type#getInternalName() getInternalName}). May be 141.181 - * <tt>null</tt>. 141.182 - * @return an object to visit the byte code of the method, or <tt>null</tt> 141.183 - * if this class visitor is not interested in visiting the code of 141.184 - * this method. 141.185 - */ 141.186 -MethodVisitor visitMethod( 141.187 - int access, 141.188 - String name, 141.189 - String desc, 141.190 - String signature, 141.191 - String[] exceptions); 141.192 - 141.193 -/** 141.194 - * Visits the end of the class. This method, which is the last one to be 141.195 - * called, is used to inform the visitor that all the fields and methods of 141.196 - * the class have been visited. 141.197 - */ 141.198 -void visitEnd(); 141.199 -}
142.1 --- a/src/clojure/asm/ClassWriter.java Sat Aug 21 06:25:44 2010 -0400 142.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 142.3 @@ -1,1415 +0,0 @@ 142.4 -/*** 142.5 - * ASM: a very small and fast Java bytecode manipulation framework 142.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 142.7 - * All rights reserved. 142.8 - * 142.9 - * Redistribution and use in source and binary forms, with or without 142.10 - * modification, are permitted provided that the following conditions 142.11 - * are met: 142.12 - * 1. Redistributions of source code must retain the above copyright 142.13 - * notice, this list of conditions and the following disclaimer. 142.14 - * 2. Redistributions in binary form must reproduce the above copyright 142.15 - * notice, this list of conditions and the following disclaimer in the 142.16 - * documentation and/or other materials provided with the distribution. 142.17 - * 3. Neither the name of the copyright holders nor the names of its 142.18 - * contributors may be used to endorse or promote products derived from 142.19 - * this software without specific prior written permission. 142.20 - * 142.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 142.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 142.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 142.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 142.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 142.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 142.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 142.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 142.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 142.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 142.31 - * THE POSSIBILITY OF SUCH DAMAGE. 142.32 - */ 142.33 -package clojure.asm; 142.34 - 142.35 -/** 142.36 - * A {@link ClassVisitor} that generates classes in bytecode form. More 142.37 - * precisely this visitor generates a byte array conforming to the Java class 142.38 - * file format. It can be used alone, to generate a Java class "from scratch", 142.39 - * or with one or more {@link ClassReader ClassReader} and adapter class visitor 142.40 - * to generate a modified class from one or more existing Java classes. 142.41 - * 142.42 - * @author Eric Bruneton 142.43 - */ 142.44 -public class ClassWriter implements ClassVisitor{ 142.45 - 142.46 -/** 142.47 - * Flag to automatically compute the maximum stack size and the maximum 142.48 - * number of local variables of methods. If this flag is set, then the 142.49 - * arguments of the {@link MethodVisitor#visitMaxs visitMaxs} method of the 142.50 - * {@link MethodVisitor} returned by the {@link #visitMethod visitMethod} 142.51 - * method will be ignored, and computed automatically from the signature and 142.52 - * the bytecode of each method. 142.53 - * 142.54 - * @see #ClassWriter(int) 142.55 - */ 142.56 -public final static int COMPUTE_MAXS = 1; 142.57 - 142.58 -/** 142.59 - * Flag to automatically compute the stack map frames of methods from 142.60 - * scratch. If this flag is set, then the calls to the 142.61 - * {@link MethodVisitor#visitFrame} method are ignored, and the stack map 142.62 - * frames are recomputed from the methods bytecode. The arguments of the 142.63 - * {@link MethodVisitor#visitMaxs visitMaxs} method are also ignored and 142.64 - * recomputed from the bytecode. In other words, computeFrames implies 142.65 - * computeMaxs. 142.66 - * 142.67 - * @see #ClassWriter(int) 142.68 - */ 142.69 -public final static int COMPUTE_FRAMES = 2; 142.70 - 142.71 -/** 142.72 - * The type of instructions without any argument. 142.73 - */ 142.74 -final static int NOARG_INSN = 0; 142.75 - 142.76 -/** 142.77 - * The type of instructions with an signed byte argument. 142.78 - */ 142.79 -final static int SBYTE_INSN = 1; 142.80 - 142.81 -/** 142.82 - * The type of instructions with an signed short argument. 142.83 - */ 142.84 -final static int SHORT_INSN = 2; 142.85 - 142.86 -/** 142.87 - * The type of instructions with a local variable index argument. 142.88 - */ 142.89 -final static int VAR_INSN = 3; 142.90 - 142.91 -/** 142.92 - * The type of instructions with an implicit local variable index argument. 142.93 - */ 142.94 -final static int IMPLVAR_INSN = 4; 142.95 - 142.96 -/** 142.97 - * The type of instructions with a type descriptor argument. 142.98 - */ 142.99 -final static int TYPE_INSN = 5; 142.100 - 142.101 -/** 142.102 - * The type of field and method invocations instructions. 142.103 - */ 142.104 -final static int FIELDORMETH_INSN = 6; 142.105 - 142.106 -/** 142.107 - * The type of the INVOKEINTERFACE instruction. 142.108 - */ 142.109 -final static int ITFMETH_INSN = 7; 142.110 - 142.111 -/** 142.112 - * The type of instructions with a 2 bytes bytecode offset label. 142.113 - */ 142.114 -final static int LABEL_INSN = 8; 142.115 - 142.116 -/** 142.117 - * The type of instructions with a 4 bytes bytecode offset label. 142.118 - */ 142.119 -final static int LABELW_INSN = 9; 142.120 - 142.121 -/** 142.122 - * The type of the LDC instruction. 142.123 - */ 142.124 -final static int LDC_INSN = 10; 142.125 - 142.126 -/** 142.127 - * The type of the LDC_W and LDC2_W instructions. 142.128 - */ 142.129 -final static int LDCW_INSN = 11; 142.130 - 142.131 -/** 142.132 - * The type of the IINC instruction. 142.133 - */ 142.134 -final static int IINC_INSN = 12; 142.135 - 142.136 -/** 142.137 - * The type of the TABLESWITCH instruction. 142.138 - */ 142.139 -final static int TABL_INSN = 13; 142.140 - 142.141 -/** 142.142 - * The type of the LOOKUPSWITCH instruction. 142.143 - */ 142.144 -final static int LOOK_INSN = 14; 142.145 - 142.146 -/** 142.147 - * The type of the MULTIANEWARRAY instruction. 142.148 - */ 142.149 -final static int MANA_INSN = 15; 142.150 - 142.151 -/** 142.152 - * The type of the WIDE instruction. 142.153 - */ 142.154 -final static int WIDE_INSN = 16; 142.155 - 142.156 -/** 142.157 - * The instruction types of all JVM opcodes. 142.158 - */ 142.159 -static byte[] TYPE; 142.160 - 142.161 -/** 142.162 - * The type of CONSTANT_Class constant pool items. 142.163 - */ 142.164 -final static int CLASS = 7; 142.165 - 142.166 -/** 142.167 - * The type of CONSTANT_Fieldref constant pool items. 142.168 - */ 142.169 -final static int FIELD = 9; 142.170 - 142.171 -/** 142.172 - * The type of CONSTANT_Methodref constant pool items. 142.173 - */ 142.174 -final static int METH = 10; 142.175 - 142.176 -/** 142.177 - * The type of CONSTANT_InterfaceMethodref constant pool items. 142.178 - */ 142.179 -final static int IMETH = 11; 142.180 - 142.181 -/** 142.182 - * The type of CONSTANT_String constant pool items. 142.183 - */ 142.184 -final static int STR = 8; 142.185 - 142.186 -/** 142.187 - * The type of CONSTANT_Integer constant pool items. 142.188 - */ 142.189 -final static int INT = 3; 142.190 - 142.191 -/** 142.192 - * The type of CONSTANT_Float constant pool items. 142.193 - */ 142.194 -final static int FLOAT = 4; 142.195 - 142.196 -/** 142.197 - * The type of CONSTANT_Long constant pool items. 142.198 - */ 142.199 -final static int LONG = 5; 142.200 - 142.201 -/** 142.202 - * The type of CONSTANT_Double constant pool items. 142.203 - */ 142.204 -final static int DOUBLE = 6; 142.205 - 142.206 -/** 142.207 - * The type of CONSTANT_NameAndType constant pool items. 142.208 - */ 142.209 -final static int NAME_TYPE = 12; 142.210 - 142.211 -/** 142.212 - * The type of CONSTANT_Utf8 constant pool items. 142.213 - */ 142.214 -final static int UTF8 = 1; 142.215 - 142.216 -/** 142.217 - * Normal type Item stored in the ClassWriter {@link ClassWriter#typeTable}, 142.218 - * instead of the constant pool, in order to avoid clashes with normal 142.219 - * constant pool items in the ClassWriter constant pool's hash table. 142.220 - */ 142.221 -final static int TYPE_NORMAL = 13; 142.222 - 142.223 -/** 142.224 - * Uninitialized type Item stored in the ClassWriter 142.225 - * {@link ClassWriter#typeTable}, instead of the constant pool, in order to 142.226 - * avoid clashes with normal constant pool items in the ClassWriter constant 142.227 - * pool's hash table. 142.228 - */ 142.229 -final static int TYPE_UNINIT = 14; 142.230 - 142.231 -/** 142.232 - * Merged type Item stored in the ClassWriter {@link ClassWriter#typeTable}, 142.233 - * instead of the constant pool, in order to avoid clashes with normal 142.234 - * constant pool items in the ClassWriter constant pool's hash table. 142.235 - */ 142.236 -final static int TYPE_MERGED = 15; 142.237 - 142.238 -/** 142.239 - * The class reader from which this class writer was constructed, if any. 142.240 - */ 142.241 -ClassReader cr; 142.242 - 142.243 -/** 142.244 - * Minor and major version numbers of the class to be generated. 142.245 - */ 142.246 -int version; 142.247 - 142.248 -/** 142.249 - * Index of the next item to be added in the constant pool. 142.250 - */ 142.251 -int index; 142.252 - 142.253 -/** 142.254 - * The constant pool of this class. 142.255 - */ 142.256 -ByteVector pool; 142.257 - 142.258 -/** 142.259 - * The constant pool's hash table data. 142.260 - */ 142.261 -Item[] items; 142.262 - 142.263 -/** 142.264 - * The threshold of the constant pool's hash table. 142.265 - */ 142.266 -int threshold; 142.267 - 142.268 -/** 142.269 - * A reusable key used to look for items in the {@link #items} hash table. 142.270 - */ 142.271 -Item key; 142.272 - 142.273 -/** 142.274 - * A reusable key used to look for items in the {@link #items} hash table. 142.275 - */ 142.276 -Item key2; 142.277 - 142.278 -/** 142.279 - * A reusable key used to look for items in the {@link #items} hash table. 142.280 - */ 142.281 -Item key3; 142.282 - 142.283 -/** 142.284 - * A type table used to temporarily store internal names that will not 142.285 - * necessarily be stored in the constant pool. This type table is used by 142.286 - * the control flow and data flow analysis algorithm used to compute stack 142.287 - * map frames from scratch. This array associates to each index <tt>i</tt> 142.288 - * the Item whose index is <tt>i</tt>. All Item objects stored in this 142.289 - * array are also stored in the {@link #items} hash table. These two arrays 142.290 - * allow to retrieve an Item from its index or, conversly, to get the index 142.291 - * of an Item from its value. Each Item stores an internal name in its 142.292 - * {@link Item#strVal1} field. 142.293 - */ 142.294 -Item[] typeTable; 142.295 - 142.296 -/** 142.297 - * Number of elements in the {@link #typeTable} array. 142.298 - */ 142.299 -private short typeCount; // TODO int? 142.300 - 142.301 -/** 142.302 - * The access flags of this class. 142.303 - */ 142.304 -private int access; 142.305 - 142.306 -/** 142.307 - * The constant pool item that contains the internal name of this class. 142.308 - */ 142.309 -private int name; 142.310 - 142.311 -/** 142.312 - * The internal name of this class. 142.313 - */ 142.314 -String thisName; 142.315 - 142.316 -/** 142.317 - * The constant pool item that contains the signature of this class. 142.318 - */ 142.319 -private int signature; 142.320 - 142.321 -/** 142.322 - * The constant pool item that contains the internal name of the super class 142.323 - * of this class. 142.324 - */ 142.325 -private int superName; 142.326 - 142.327 -/** 142.328 - * Number of interfaces implemented or extended by this class or interface. 142.329 - */ 142.330 -private int interfaceCount; 142.331 - 142.332 -/** 142.333 - * The interfaces implemented or extended by this class or interface. More 142.334 - * precisely, this array contains the indexes of the constant pool items 142.335 - * that contain the internal names of these interfaces. 142.336 - */ 142.337 -private int[] interfaces; 142.338 - 142.339 -/** 142.340 - * The index of the constant pool item that contains the name of the source 142.341 - * file from which this class was compiled. 142.342 - */ 142.343 -private int sourceFile; 142.344 - 142.345 -/** 142.346 - * The SourceDebug attribute of this class. 142.347 - */ 142.348 -private ByteVector sourceDebug; 142.349 - 142.350 -/** 142.351 - * The constant pool item that contains the name of the enclosing class of 142.352 - * this class. 142.353 - */ 142.354 -private int enclosingMethodOwner; 142.355 - 142.356 -/** 142.357 - * The constant pool item that contains the name and descriptor of the 142.358 - * enclosing method of this class. 142.359 - */ 142.360 -private int enclosingMethod; 142.361 - 142.362 -/** 142.363 - * The runtime visible annotations of this class. 142.364 - */ 142.365 -private AnnotationWriter anns; 142.366 - 142.367 -/** 142.368 - * The runtime invisible annotations of this class. 142.369 - */ 142.370 -private AnnotationWriter ianns; 142.371 - 142.372 -/** 142.373 - * The non standard attributes of this class. 142.374 - */ 142.375 -private Attribute attrs; 142.376 - 142.377 -/** 142.378 - * The number of entries in the InnerClasses attribute. 142.379 - */ 142.380 -private int innerClassesCount; 142.381 - 142.382 -/** 142.383 - * The InnerClasses attribute. 142.384 - */ 142.385 -private ByteVector innerClasses; 142.386 - 142.387 -/** 142.388 - * The fields of this class. These fields are stored in a linked list of 142.389 - * {@link FieldWriter} objects, linked to each other by their 142.390 - * {@link FieldWriter#next} field. This field stores the first element of 142.391 - * this list. 142.392 - */ 142.393 -FieldWriter firstField; 142.394 - 142.395 -/** 142.396 - * The fields of this class. These fields are stored in a linked list of 142.397 - * {@link FieldWriter} objects, linked to each other by their 142.398 - * {@link FieldWriter#next} field. This field stores the last element of 142.399 - * this list. 142.400 - */ 142.401 -FieldWriter lastField; 142.402 - 142.403 -/** 142.404 - * The methods of this class. These methods are stored in a linked list of 142.405 - * {@link MethodWriter} objects, linked to each other by their 142.406 - * {@link MethodWriter#next} field. This field stores the first element of 142.407 - * this list. 142.408 - */ 142.409 -MethodWriter firstMethod; 142.410 - 142.411 -/** 142.412 - * The methods of this class. These methods are stored in a linked list of 142.413 - * {@link MethodWriter} objects, linked to each other by their 142.414 - * {@link MethodWriter#next} field. This field stores the last element of 142.415 - * this list. 142.416 - */ 142.417 -MethodWriter lastMethod; 142.418 - 142.419 -/** 142.420 - * <tt>true</tt> if the maximum stack size and number of local variables 142.421 - * must be automatically computed. 142.422 - */ 142.423 -private boolean computeMaxs; 142.424 - 142.425 -/** 142.426 - * <tt>true</tt> if the stack map frames must be recomputed from scratch. 142.427 - */ 142.428 -private boolean computeFrames; 142.429 - 142.430 -/** 142.431 - * <tt>true</tt> if the stack map tables of this class are invalid. The 142.432 - * {@link MethodWriter#resizeInstructions} method cannot transform existing 142.433 - * stack map tables, and so produces potentially invalid classes when it is 142.434 - * executed. In this case the class is reread and rewritten with the 142.435 - * {@link #COMPUTE_FRAMES} option (the resizeInstructions method can resize 142.436 - * stack map tables when this option is used). 142.437 - */ 142.438 -boolean invalidFrames; 142.439 - 142.440 -// ------------------------------------------------------------------------ 142.441 -// Static initializer 142.442 -// ------------------------------------------------------------------------ 142.443 - 142.444 -/** 142.445 - * Computes the instruction types of JVM opcodes. 142.446 - */ 142.447 -static 142.448 - { 142.449 - int i; 142.450 - byte[] b = new byte[220]; 142.451 - String s = "AAAAAAAAAAAAAAAABCKLLDDDDDEEEEEEEEEEEEEEEEEEEEAAAAAAAADD" 142.452 - + "DDDEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" 142.453 - + "AAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAIIIIIIIIIIIIIIIIDNOAA" 142.454 - + "AAAAGGGGGGGHAFBFAAFFAAQPIIJJIIIIIIIIIIIIIIIIII"; 142.455 - for(i = 0; i < b.length; ++i) 142.456 - { 142.457 - b[i] = (byte) (s.charAt(i) - 'A'); 142.458 - } 142.459 - TYPE = b; 142.460 - 142.461 - // code to generate the above string 142.462 - // 142.463 - // // SBYTE_INSN instructions 142.464 - // b[Constants.NEWARRAY] = SBYTE_INSN; 142.465 - // b[Constants.BIPUSH] = SBYTE_INSN; 142.466 - // 142.467 - // // SHORT_INSN instructions 142.468 - // b[Constants.SIPUSH] = SHORT_INSN; 142.469 - // 142.470 - // // (IMPL)VAR_INSN instructions 142.471 - // b[Constants.RET] = VAR_INSN; 142.472 - // for (i = Constants.ILOAD; i <= Constants.ALOAD; ++i) { 142.473 - // b[i] = VAR_INSN; 142.474 - // } 142.475 - // for (i = Constants.ISTORE; i <= Constants.ASTORE; ++i) { 142.476 - // b[i] = VAR_INSN; 142.477 - // } 142.478 - // for (i = 26; i <= 45; ++i) { // ILOAD_0 to ALOAD_3 142.479 - // b[i] = IMPLVAR_INSN; 142.480 - // } 142.481 - // for (i = 59; i <= 78; ++i) { // ISTORE_0 to ASTORE_3 142.482 - // b[i] = IMPLVAR_INSN; 142.483 - // } 142.484 - // 142.485 - // // TYPE_INSN instructions 142.486 - // b[Constants.NEW] = TYPE_INSN; 142.487 - // b[Constants.ANEWARRAY] = TYPE_INSN; 142.488 - // b[Constants.CHECKCAST] = TYPE_INSN; 142.489 - // b[Constants.INSTANCEOF] = TYPE_INSN; 142.490 - // 142.491 - // // (Set)FIELDORMETH_INSN instructions 142.492 - // for (i = Constants.GETSTATIC; i <= Constants.INVOKESTATIC; ++i) { 142.493 - // b[i] = FIELDORMETH_INSN; 142.494 - // } 142.495 - // b[Constants.INVOKEINTERFACE] = ITFMETH_INSN; 142.496 - // 142.497 - // // LABEL(W)_INSN instructions 142.498 - // for (i = Constants.IFEQ; i <= Constants.JSR; ++i) { 142.499 - // b[i] = LABEL_INSN; 142.500 - // } 142.501 - // b[Constants.IFNULL] = LABEL_INSN; 142.502 - // b[Constants.IFNONNULL] = LABEL_INSN; 142.503 - // b[200] = LABELW_INSN; // GOTO_W 142.504 - // b[201] = LABELW_INSN; // JSR_W 142.505 - // // temporary opcodes used internally by ASM - see Label and 142.506 - // MethodWriter 142.507 - // for (i = 202; i < 220; ++i) { 142.508 - // b[i] = LABEL_INSN; 142.509 - // } 142.510 - // 142.511 - // // LDC(_W) instructions 142.512 - // b[Constants.LDC] = LDC_INSN; 142.513 - // b[19] = LDCW_INSN; // LDC_W 142.514 - // b[20] = LDCW_INSN; // LDC2_W 142.515 - // 142.516 - // // special instructions 142.517 - // b[Constants.IINC] = IINC_INSN; 142.518 - // b[Constants.TABLESWITCH] = TABL_INSN; 142.519 - // b[Constants.LOOKUPSWITCH] = LOOK_INSN; 142.520 - // b[Constants.MULTIANEWARRAY] = MANA_INSN; 142.521 - // b[196] = WIDE_INSN; // WIDE 142.522 - // 142.523 - // for (i = 0; i < b.length; ++i) { 142.524 - // System.err.print((char)('A' + b[i])); 142.525 - // } 142.526 - // System.err.println(); 142.527 - } 142.528 - 142.529 -// ------------------------------------------------------------------------ 142.530 -// Constructor 142.531 -// ------------------------------------------------------------------------ 142.532 - 142.533 -/** 142.534 - * Constructs a new {@link ClassWriter} object. 142.535 - * 142.536 - * @param flags option flags that can be used to modify the default behavior 142.537 - * of this class. See {@link #COMPUTE_MAXS}, {@link #COMPUTE_FRAMES}. 142.538 - */ 142.539 -public ClassWriter(final int flags){ 142.540 - index = 1; 142.541 - pool = new ByteVector(); 142.542 - items = new Item[256]; 142.543 - threshold = (int) (0.75d * items.length); 142.544 - key = new Item(); 142.545 - key2 = new Item(); 142.546 - key3 = new Item(); 142.547 - this.computeMaxs = (flags & COMPUTE_MAXS) != 0; 142.548 - this.computeFrames = (flags & COMPUTE_FRAMES) != 0; 142.549 -} 142.550 - 142.551 -/** 142.552 - * Constructs a new {@link ClassWriter} object and enables optimizations for 142.553 - * "mostly add" bytecode transformations. These optimizations are the 142.554 - * following: 142.555 - * <p/> 142.556 - * <ul> <li>The constant pool from the original class is copied as is in 142.557 - * the new class, which saves time. New constant pool entries will be added 142.558 - * at the end if necessary, but unused constant pool entries <i>won't be 142.559 - * removed</i>.</li> <li>Methods that are not transformed are copied as 142.560 - * is in the new class, directly from the original class bytecode (i.e. 142.561 - * without emitting visit events for all the method instructions), which 142.562 - * saves a <i>lot</i> of time. Untransformed methods are detected by the 142.563 - * fact that the {@link ClassReader} receives {@link MethodVisitor} objects 142.564 - * that come from a {@link ClassWriter} (and not from a custom 142.565 - * {@link ClassAdapter} or any other {@link ClassVisitor} instance).</li> 142.566 - * </ul> 142.567 - * 142.568 - * @param classReader the {@link ClassReader} used to read the original 142.569 - * class. It will be used to copy the entire constant pool from the 142.570 - * original class and also to copy other fragments of original 142.571 - * bytecode where applicable. 142.572 - * @param flags option flags that can be used to modify the default behavior 142.573 - * of this class. See {@link #COMPUTE_MAXS}, {@link #COMPUTE_FRAMES}. 142.574 - */ 142.575 -public ClassWriter(final ClassReader classReader, final int flags){ 142.576 - this(flags); 142.577 - classReader.copyPool(this); 142.578 - this.cr = classReader; 142.579 -} 142.580 - 142.581 -// ------------------------------------------------------------------------ 142.582 -// Implementation of the ClassVisitor interface 142.583 -// ------------------------------------------------------------------------ 142.584 - 142.585 -public void visit( 142.586 - final int version, 142.587 - final int access, 142.588 - final String name, 142.589 - final String signature, 142.590 - final String superName, 142.591 - final String[] interfaces){ 142.592 - this.version = version; 142.593 - this.access = access; 142.594 - this.name = newClass(name); 142.595 - thisName = name; 142.596 - if(signature != null) 142.597 - { 142.598 - this.signature = newUTF8(signature); 142.599 - } 142.600 - this.superName = superName == null ? 0 : newClass(superName); 142.601 - if(interfaces != null && interfaces.length > 0) 142.602 - { 142.603 - interfaceCount = interfaces.length; 142.604 - this.interfaces = new int[interfaceCount]; 142.605 - for(int i = 0; i < interfaceCount; ++i) 142.606 - { 142.607 - this.interfaces[i] = newClass(interfaces[i]); 142.608 - } 142.609 - } 142.610 -} 142.611 - 142.612 -public void visitSource(final String file, final String debug){ 142.613 - if(file != null) 142.614 - { 142.615 - sourceFile = newUTF8(file); 142.616 - } 142.617 - if(debug != null) 142.618 - { 142.619 - sourceDebug = new ByteVector().putUTF8(debug); 142.620 - } 142.621 -} 142.622 - 142.623 -public void visitOuterClass( 142.624 - final String owner, 142.625 - final String name, 142.626 - final String desc){ 142.627 - enclosingMethodOwner = newClass(owner); 142.628 - if(name != null && desc != null) 142.629 - { 142.630 - enclosingMethod = newNameType(name, desc); 142.631 - } 142.632 -} 142.633 - 142.634 -public AnnotationVisitor visitAnnotation( 142.635 - final String desc, 142.636 - final boolean visible){ 142.637 - ByteVector bv = new ByteVector(); 142.638 - // write type, and reserve space for values count 142.639 - bv.putShort(newUTF8(desc)).putShort(0); 142.640 - AnnotationWriter aw = new AnnotationWriter(this, true, bv, bv, 2); 142.641 - if(visible) 142.642 - { 142.643 - aw.next = anns; 142.644 - anns = aw; 142.645 - } 142.646 - else 142.647 - { 142.648 - aw.next = ianns; 142.649 - ianns = aw; 142.650 - } 142.651 - return aw; 142.652 -} 142.653 - 142.654 -public void visitAttribute(final Attribute attr){ 142.655 - attr.next = attrs; 142.656 - attrs = attr; 142.657 -} 142.658 - 142.659 -public void visitInnerClass( 142.660 - final String name, 142.661 - final String outerName, 142.662 - final String innerName, 142.663 - final int access){ 142.664 - if(innerClasses == null) 142.665 - { 142.666 - innerClasses = new ByteVector(); 142.667 - } 142.668 - ++innerClassesCount; 142.669 - innerClasses.putShort(name == null ? 0 : newClass(name)); 142.670 - innerClasses.putShort(outerName == null ? 0 : newClass(outerName)); 142.671 - innerClasses.putShort(innerName == null ? 0 : newUTF8(innerName)); 142.672 - innerClasses.putShort(access); 142.673 -} 142.674 - 142.675 -public FieldVisitor visitField( 142.676 - final int access, 142.677 - final String name, 142.678 - final String desc, 142.679 - final String signature, 142.680 - final Object value){ 142.681 - return new FieldWriter(this, access, name, desc, signature, value); 142.682 -} 142.683 - 142.684 -public MethodVisitor visitMethod( 142.685 - final int access, 142.686 - final String name, 142.687 - final String desc, 142.688 - final String signature, 142.689 - final String[] exceptions){ 142.690 - return new MethodWriter(this, 142.691 - access, 142.692 - name, 142.693 - desc, 142.694 - signature, 142.695 - exceptions, 142.696 - computeMaxs, 142.697 - computeFrames); 142.698 -} 142.699 - 142.700 -public void visitEnd(){ 142.701 -} 142.702 - 142.703 -// ------------------------------------------------------------------------ 142.704 -// Other public methods 142.705 -// ------------------------------------------------------------------------ 142.706 - 142.707 -/** 142.708 - * Returns the bytecode of the class that was build with this class writer. 142.709 - * 142.710 - * @return the bytecode of the class that was build with this class writer. 142.711 - */ 142.712 -public byte[] toByteArray(){ 142.713 - // computes the real size of the bytecode of this class 142.714 - int size = 24 + 2 * interfaceCount; 142.715 - int nbFields = 0; 142.716 - FieldWriter fb = firstField; 142.717 - while(fb != null) 142.718 - { 142.719 - ++nbFields; 142.720 - size += fb.getSize(); 142.721 - fb = fb.next; 142.722 - } 142.723 - int nbMethods = 0; 142.724 - MethodWriter mb = firstMethod; 142.725 - while(mb != null) 142.726 - { 142.727 - ++nbMethods; 142.728 - size += mb.getSize(); 142.729 - mb = mb.next; 142.730 - } 142.731 - int attributeCount = 0; 142.732 - if(signature != 0) 142.733 - { 142.734 - ++attributeCount; 142.735 - size += 8; 142.736 - newUTF8("Signature"); 142.737 - } 142.738 - if(sourceFile != 0) 142.739 - { 142.740 - ++attributeCount; 142.741 - size += 8; 142.742 - newUTF8("SourceFile"); 142.743 - } 142.744 - if(sourceDebug != null) 142.745 - { 142.746 - ++attributeCount; 142.747 - size += sourceDebug.length + 4; 142.748 - newUTF8("SourceDebugExtension"); 142.749 - } 142.750 - if(enclosingMethodOwner != 0) 142.751 - { 142.752 - ++attributeCount; 142.753 - size += 10; 142.754 - newUTF8("EnclosingMethod"); 142.755 - } 142.756 - if((access & Opcodes.ACC_DEPRECATED) != 0) 142.757 - { 142.758 - ++attributeCount; 142.759 - size += 6; 142.760 - newUTF8("Deprecated"); 142.761 - } 142.762 - if((access & Opcodes.ACC_SYNTHETIC) != 0 142.763 - && (version & 0xffff) < Opcodes.V1_5) 142.764 - { 142.765 - ++attributeCount; 142.766 - size += 6; 142.767 - newUTF8("Synthetic"); 142.768 - } 142.769 - if(innerClasses != null) 142.770 - { 142.771 - ++attributeCount; 142.772 - size += 8 + innerClasses.length; 142.773 - newUTF8("InnerClasses"); 142.774 - } 142.775 - if(anns != null) 142.776 - { 142.777 - ++attributeCount; 142.778 - size += 8 + anns.getSize(); 142.779 - newUTF8("RuntimeVisibleAnnotations"); 142.780 - } 142.781 - if(ianns != null) 142.782 - { 142.783 - ++attributeCount; 142.784 - size += 8 + ianns.getSize(); 142.785 - newUTF8("RuntimeInvisibleAnnotations"); 142.786 - } 142.787 - if(attrs != null) 142.788 - { 142.789 - attributeCount += attrs.getCount(); 142.790 - size += attrs.getSize(this, null, 0, -1, -1); 142.791 - } 142.792 - size += pool.length; 142.793 - // allocates a byte vector of this size, in order to avoid unnecessary 142.794 - // arraycopy operations in the ByteVector.enlarge() method 142.795 - ByteVector out = new ByteVector(size); 142.796 - out.putInt(0xCAFEBABE).putInt(version); 142.797 - out.putShort(index).putByteArray(pool.data, 0, pool.length); 142.798 - out.putShort(access).putShort(name).putShort(superName); 142.799 - out.putShort(interfaceCount); 142.800 - for(int i = 0; i < interfaceCount; ++i) 142.801 - { 142.802 - out.putShort(interfaces[i]); 142.803 - } 142.804 - out.putShort(nbFields); 142.805 - fb = firstField; 142.806 - while(fb != null) 142.807 - { 142.808 - fb.put(out); 142.809 - fb = fb.next; 142.810 - } 142.811 - out.putShort(nbMethods); 142.812 - mb = firstMethod; 142.813 - while(mb != null) 142.814 - { 142.815 - mb.put(out); 142.816 - mb = mb.next; 142.817 - } 142.818 - out.putShort(attributeCount); 142.819 - if(signature != 0) 142.820 - { 142.821 - out.putShort(newUTF8("Signature")).putInt(2).putShort(signature); 142.822 - } 142.823 - if(sourceFile != 0) 142.824 - { 142.825 - out.putShort(newUTF8("SourceFile")).putInt(2).putShort(sourceFile); 142.826 - } 142.827 - if(sourceDebug != null) 142.828 - { 142.829 - int len = sourceDebug.length - 2; 142.830 - out.putShort(newUTF8("SourceDebugExtension")).putInt(len); 142.831 - out.putByteArray(sourceDebug.data, 2, len); 142.832 - } 142.833 - if(enclosingMethodOwner != 0) 142.834 - { 142.835 - out.putShort(newUTF8("EnclosingMethod")).putInt(4); 142.836 - out.putShort(enclosingMethodOwner).putShort(enclosingMethod); 142.837 - } 142.838 - if((access & Opcodes.ACC_DEPRECATED) != 0) 142.839 - { 142.840 - out.putShort(newUTF8("Deprecated")).putInt(0); 142.841 - } 142.842 - if((access & Opcodes.ACC_SYNTHETIC) != 0 142.843 - && (version & 0xffff) < Opcodes.V1_5) 142.844 - { 142.845 - out.putShort(newUTF8("Synthetic")).putInt(0); 142.846 - } 142.847 - if(innerClasses != null) 142.848 - { 142.849 - out.putShort(newUTF8("InnerClasses")); 142.850 - out.putInt(innerClasses.length + 2).putShort(innerClassesCount); 142.851 - out.putByteArray(innerClasses.data, 0, innerClasses.length); 142.852 - } 142.853 - if(anns != null) 142.854 - { 142.855 - out.putShort(newUTF8("RuntimeVisibleAnnotations")); 142.856 - anns.put(out); 142.857 - } 142.858 - if(ianns != null) 142.859 - { 142.860 - out.putShort(newUTF8("RuntimeInvisibleAnnotations")); 142.861 - ianns.put(out); 142.862 - } 142.863 - if(attrs != null) 142.864 - { 142.865 - attrs.put(this, null, 0, -1, -1, out); 142.866 - } 142.867 - if(invalidFrames) 142.868 - { 142.869 - ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); 142.870 - new ClassReader(out.data).accept(cw, ClassReader.SKIP_FRAMES); 142.871 - return cw.toByteArray(); 142.872 - } 142.873 - return out.data; 142.874 -} 142.875 - 142.876 -// ------------------------------------------------------------------------ 142.877 -// Utility methods: constant pool management 142.878 -// ------------------------------------------------------------------------ 142.879 - 142.880 -/** 142.881 - * Adds a number or string constant to the constant pool of the class being 142.882 - * build. Does nothing if the constant pool already contains a similar item. 142.883 - * 142.884 - * @param cst the value of the constant to be added to the constant pool. 142.885 - * This parameter must be an {@link Integer}, a {@link Float}, a 142.886 - * {@link Long}, a {@link Double}, a {@link String} or a 142.887 - * {@link Type}. 142.888 - * @return a new or already existing constant item with the given value. 142.889 - */ 142.890 -Item newConstItem(final Object cst){ 142.891 - if(cst instanceof Integer) 142.892 - { 142.893 - int val = ((Integer) cst).intValue(); 142.894 - return newInteger(val); 142.895 - } 142.896 - else if(cst instanceof Byte) 142.897 - { 142.898 - int val = ((Byte) cst).intValue(); 142.899 - return newInteger(val); 142.900 - } 142.901 - else if(cst instanceof Character) 142.902 - { 142.903 - int val = ((Character) cst).charValue(); 142.904 - return newInteger(val); 142.905 - } 142.906 - else if(cst instanceof Short) 142.907 - { 142.908 - int val = ((Short) cst).intValue(); 142.909 - return newInteger(val); 142.910 - } 142.911 - else if(cst instanceof Boolean) 142.912 - { 142.913 - int val = ((Boolean) cst).booleanValue() ? 1 : 0; 142.914 - return newInteger(val); 142.915 - } 142.916 - else if(cst instanceof Float) 142.917 - { 142.918 - float val = ((Float) cst).floatValue(); 142.919 - return newFloat(val); 142.920 - } 142.921 - else if(cst instanceof Long) 142.922 - { 142.923 - long val = ((Long) cst).longValue(); 142.924 - return newLong(val); 142.925 - } 142.926 - else if(cst instanceof Double) 142.927 - { 142.928 - double val = ((Double) cst).doubleValue(); 142.929 - return newDouble(val); 142.930 - } 142.931 - else if(cst instanceof String) 142.932 - { 142.933 - return newString((String) cst); 142.934 - } 142.935 - else if(cst instanceof Type) 142.936 - { 142.937 - Type t = (Type) cst; 142.938 - return newClassItem(t.getSort() == Type.OBJECT 142.939 - ? t.getInternalName() 142.940 - : t.getDescriptor()); 142.941 - } 142.942 - else 142.943 - { 142.944 - throw new IllegalArgumentException("value " + cst); 142.945 - } 142.946 -} 142.947 - 142.948 -/** 142.949 - * Adds a number or string constant to the constant pool of the class being 142.950 - * build. Does nothing if the constant pool already contains a similar item. 142.951 - * <i>This method is intended for {@link Attribute} sub classes, and is 142.952 - * normally not needed by class generators or adapters.</i> 142.953 - * 142.954 - * @param cst the value of the constant to be added to the constant pool. 142.955 - * This parameter must be an {@link Integer}, a {@link Float}, a 142.956 - * {@link Long}, a {@link Double} or a {@link String}. 142.957 - * @return the index of a new or already existing constant item with the 142.958 - * given value. 142.959 - */ 142.960 -public int newConst(final Object cst){ 142.961 - return newConstItem(cst).index; 142.962 -} 142.963 - 142.964 -/** 142.965 - * Adds an UTF8 string to the constant pool of the class being build. Does 142.966 - * nothing if the constant pool already contains a similar item. <i>This 142.967 - * method is intended for {@link Attribute} sub classes, and is normally not 142.968 - * needed by class generators or adapters.</i> 142.969 - * 142.970 - * @param value the String value. 142.971 - * @return the index of a new or already existing UTF8 item. 142.972 - */ 142.973 -public int newUTF8(final String value){ 142.974 - key.set(UTF8, value, null, null); 142.975 - Item result = get(key); 142.976 - if(result == null) 142.977 - { 142.978 - pool.putByte(UTF8).putUTF8(value); 142.979 - result = new Item(index++, key); 142.980 - put(result); 142.981 - } 142.982 - return result.index; 142.983 -} 142.984 - 142.985 -/** 142.986 - * Adds a class reference to the constant pool of the class being build. 142.987 - * Does nothing if the constant pool already contains a similar item. 142.988 - * <i>This method is intended for {@link Attribute} sub classes, and is 142.989 - * normally not needed by class generators or adapters.</i> 142.990 - * 142.991 - * @param value the internal name of the class. 142.992 - * @return a new or already existing class reference item. 142.993 - */ 142.994 -Item newClassItem(final String value){ 142.995 - key2.set(CLASS, value, null, null); 142.996 - Item result = get(key2); 142.997 - if(result == null) 142.998 - { 142.999 - pool.put12(CLASS, newUTF8(value)); 142.1000 - result = new Item(index++, key2); 142.1001 - put(result); 142.1002 - } 142.1003 - return result; 142.1004 -} 142.1005 - 142.1006 -/** 142.1007 - * Adds a class reference to the constant pool of the class being build. 142.1008 - * Does nothing if the constant pool already contains a similar item. 142.1009 - * <i>This method is intended for {@link Attribute} sub classes, and is 142.1010 - * normally not needed by class generators or adapters.</i> 142.1011 - * 142.1012 - * @param value the internal name of the class. 142.1013 - * @return the index of a new or already existing class reference item. 142.1014 - */ 142.1015 -public int newClass(final String value){ 142.1016 - return newClassItem(value).index; 142.1017 -} 142.1018 - 142.1019 -/** 142.1020 - * Adds a field reference to the constant pool of the class being build. 142.1021 - * Does nothing if the constant pool already contains a similar item. 142.1022 - * 142.1023 - * @param owner the internal name of the field's owner class. 142.1024 - * @param name the field's name. 142.1025 - * @param desc the field's descriptor. 142.1026 - * @return a new or already existing field reference item. 142.1027 - */ 142.1028 -Item newFieldItem(final String owner, final String name, final String desc){ 142.1029 - key3.set(FIELD, owner, name, desc); 142.1030 - Item result = get(key3); 142.1031 - if(result == null) 142.1032 - { 142.1033 - put122(FIELD, newClass(owner), newNameType(name, desc)); 142.1034 - result = new Item(index++, key3); 142.1035 - put(result); 142.1036 - } 142.1037 - return result; 142.1038 -} 142.1039 - 142.1040 -/** 142.1041 - * Adds a field reference to the constant pool of the class being build. 142.1042 - * Does nothing if the constant pool already contains a similar item. 142.1043 - * <i>This method is intended for {@link Attribute} sub classes, and is 142.1044 - * normally not needed by class generators or adapters.</i> 142.1045 - * 142.1046 - * @param owner the internal name of the field's owner class. 142.1047 - * @param name the field's name. 142.1048 - * @param desc the field's descriptor. 142.1049 - * @return the index of a new or already existing field reference item. 142.1050 - */ 142.1051 -public int newField(final String owner, final String name, final String desc){ 142.1052 - return newFieldItem(owner, name, desc).index; 142.1053 -} 142.1054 - 142.1055 -/** 142.1056 - * Adds a method reference to the constant pool of the class being build. 142.1057 - * Does nothing if the constant pool already contains a similar item. 142.1058 - * 142.1059 - * @param owner the internal name of the method's owner class. 142.1060 - * @param name the method's name. 142.1061 - * @param desc the method's descriptor. 142.1062 - * @param itf <tt>true</tt> if <tt>owner</tt> is an interface. 142.1063 - * @return a new or already existing method reference item. 142.1064 - */ 142.1065 -Item newMethodItem( 142.1066 - final String owner, 142.1067 - final String name, 142.1068 - final String desc, 142.1069 - final boolean itf){ 142.1070 - int type = itf ? IMETH : METH; 142.1071 - key3.set(type, owner, name, desc); 142.1072 - Item result = get(key3); 142.1073 - if(result == null) 142.1074 - { 142.1075 - put122(type, newClass(owner), newNameType(name, desc)); 142.1076 - result = new Item(index++, key3); 142.1077 - put(result); 142.1078 - } 142.1079 - return result; 142.1080 -} 142.1081 - 142.1082 -/** 142.1083 - * Adds a method reference to the constant pool of the class being build. 142.1084 - * Does nothing if the constant pool already contains a similar item. 142.1085 - * <i>This method is intended for {@link Attribute} sub classes, and is 142.1086 - * normally not needed by class generators or adapters.</i> 142.1087 - * 142.1088 - * @param owner the internal name of the method's owner class. 142.1089 - * @param name the method's name. 142.1090 - * @param desc the method's descriptor. 142.1091 - * @param itf <tt>true</tt> if <tt>owner</tt> is an interface. 142.1092 - * @return the index of a new or already existing method reference item. 142.1093 - */ 142.1094 -public int newMethod( 142.1095 - final String owner, 142.1096 - final String name, 142.1097 - final String desc, 142.1098 - final boolean itf){ 142.1099 - return newMethodItem(owner, name, desc, itf).index; 142.1100 -} 142.1101 - 142.1102 -/** 142.1103 - * Adds an integer to the constant pool of the class being build. Does 142.1104 - * nothing if the constant pool already contains a similar item. 142.1105 - * 142.1106 - * @param value the int value. 142.1107 - * @return a new or already existing int item. 142.1108 - */ 142.1109 -Item newInteger(final int value){ 142.1110 - key.set(value); 142.1111 - Item result = get(key); 142.1112 - if(result == null) 142.1113 - { 142.1114 - pool.putByte(INT).putInt(value); 142.1115 - result = new Item(index++, key); 142.1116 - put(result); 142.1117 - } 142.1118 - return result; 142.1119 -} 142.1120 - 142.1121 -/** 142.1122 - * Adds a float to the constant pool of the class being build. Does nothing 142.1123 - * if the constant pool already contains a similar item. 142.1124 - * 142.1125 - * @param value the float value. 142.1126 - * @return a new or already existing float item. 142.1127 - */ 142.1128 -Item newFloat(final float value){ 142.1129 - key.set(value); 142.1130 - Item result = get(key); 142.1131 - if(result == null) 142.1132 - { 142.1133 - pool.putByte(FLOAT).putInt(key.intVal); 142.1134 - result = new Item(index++, key); 142.1135 - put(result); 142.1136 - } 142.1137 - return result; 142.1138 -} 142.1139 - 142.1140 -/** 142.1141 - * Adds a long to the constant pool of the class being build. Does nothing 142.1142 - * if the constant pool already contains a similar item. 142.1143 - * 142.1144 - * @param value the long value. 142.1145 - * @return a new or already existing long item. 142.1146 - */ 142.1147 -Item newLong(final long value){ 142.1148 - key.set(value); 142.1149 - Item result = get(key); 142.1150 - if(result == null) 142.1151 - { 142.1152 - pool.putByte(LONG).putLong(value); 142.1153 - result = new Item(index, key); 142.1154 - put(result); 142.1155 - index += 2; 142.1156 - } 142.1157 - return result; 142.1158 -} 142.1159 - 142.1160 -/** 142.1161 - * Adds a double to the constant pool of the class being build. Does nothing 142.1162 - * if the constant pool already contains a similar item. 142.1163 - * 142.1164 - * @param value the double value. 142.1165 - * @return a new or already existing double item. 142.1166 - */ 142.1167 -Item newDouble(final double value){ 142.1168 - key.set(value); 142.1169 - Item result = get(key); 142.1170 - if(result == null) 142.1171 - { 142.1172 - pool.putByte(DOUBLE).putLong(key.longVal); 142.1173 - result = new Item(index, key); 142.1174 - put(result); 142.1175 - index += 2; 142.1176 - } 142.1177 - return result; 142.1178 -} 142.1179 - 142.1180 -/** 142.1181 - * Adds a string to the constant pool of the class being build. Does nothing 142.1182 - * if the constant pool already contains a similar item. 142.1183 - * 142.1184 - * @param value the String value. 142.1185 - * @return a new or already existing string item. 142.1186 - */ 142.1187 -private Item newString(final String value){ 142.1188 - key2.set(STR, value, null, null); 142.1189 - Item result = get(key2); 142.1190 - if(result == null) 142.1191 - { 142.1192 - pool.put12(STR, newUTF8(value)); 142.1193 - result = new Item(index++, key2); 142.1194 - put(result); 142.1195 - } 142.1196 - return result; 142.1197 -} 142.1198 - 142.1199 -/** 142.1200 - * Adds a name and type to the constant pool of the class being build. Does 142.1201 - * nothing if the constant pool already contains a similar item. <i>This 142.1202 - * method is intended for {@link Attribute} sub classes, and is normally not 142.1203 - * needed by class generators or adapters.</i> 142.1204 - * 142.1205 - * @param name a name. 142.1206 - * @param desc a type descriptor. 142.1207 - * @return the index of a new or already existing name and type item. 142.1208 - */ 142.1209 -public int newNameType(final String name, final String desc){ 142.1210 - key2.set(NAME_TYPE, name, desc, null); 142.1211 - Item result = get(key2); 142.1212 - if(result == null) 142.1213 - { 142.1214 - put122(NAME_TYPE, newUTF8(name), newUTF8(desc)); 142.1215 - result = new Item(index++, key2); 142.1216 - put(result); 142.1217 - } 142.1218 - return result.index; 142.1219 -} 142.1220 - 142.1221 -/** 142.1222 - * Adds the given internal name to {@link #typeTable} and returns its index. 142.1223 - * Does nothing if the type table already contains this internal name. 142.1224 - * 142.1225 - * @param type the internal name to be added to the type table. 142.1226 - * @return the index of this internal name in the type table. 142.1227 - */ 142.1228 -int addType(final String type){ 142.1229 - key.set(TYPE_NORMAL, type, null, null); 142.1230 - Item result = get(key); 142.1231 - if(result == null) 142.1232 - { 142.1233 - result = addType(key); 142.1234 - } 142.1235 - return result.index; 142.1236 -} 142.1237 - 142.1238 -/** 142.1239 - * Adds the given "uninitialized" type to {@link #typeTable} and returns its 142.1240 - * index. This method is used for UNINITIALIZED types, made of an internal 142.1241 - * name and a bytecode offset. 142.1242 - * 142.1243 - * @param type the internal name to be added to the type table. 142.1244 - * @param offset the bytecode offset of the NEW instruction that created 142.1245 - * this UNINITIALIZED type value. 142.1246 - * @return the index of this internal name in the type table. 142.1247 - */ 142.1248 -int addUninitializedType(final String type, final int offset){ 142.1249 - key.type = TYPE_UNINIT; 142.1250 - key.intVal = offset; 142.1251 - key.strVal1 = type; 142.1252 - key.hashCode = 0x7FFFFFFF & (TYPE_UNINIT + type.hashCode() + offset); 142.1253 - Item result = get(key); 142.1254 - if(result == null) 142.1255 - { 142.1256 - result = addType(key); 142.1257 - } 142.1258 - return result.index; 142.1259 -} 142.1260 - 142.1261 -/** 142.1262 - * Adds the given Item to {@link #typeTable}. 142.1263 - * 142.1264 - * @param item the value to be added to the type table. 142.1265 - * @return the added Item, which a new Item instance with the same value as 142.1266 - * the given Item. 142.1267 - */ 142.1268 -private Item addType(final Item item){ 142.1269 - ++typeCount; 142.1270 - Item result = new Item(typeCount, key); 142.1271 - put(result); 142.1272 - if(typeTable == null) 142.1273 - { 142.1274 - typeTable = new Item[16]; 142.1275 - } 142.1276 - if(typeCount == typeTable.length) 142.1277 - { 142.1278 - Item[] newTable = new Item[2 * typeTable.length]; 142.1279 - System.arraycopy(typeTable, 0, newTable, 0, typeTable.length); 142.1280 - typeTable = newTable; 142.1281 - } 142.1282 - typeTable[typeCount] = result; 142.1283 - return result; 142.1284 -} 142.1285 - 142.1286 -/** 142.1287 - * Returns the index of the common super type of the two given types. This 142.1288 - * method calls {@link #getCommonSuperClass} and caches the result in the 142.1289 - * {@link #items} hash table to speedup future calls with the same 142.1290 - * parameters. 142.1291 - * 142.1292 - * @param type1 index of an internal name in {@link #typeTable}. 142.1293 - * @param type2 index of an internal name in {@link #typeTable}. 142.1294 - * @return the index of the common super type of the two given types. 142.1295 - */ 142.1296 -int getMergedType(final int type1, final int type2){ 142.1297 - key2.type = TYPE_MERGED; 142.1298 - key2.longVal = type1 | (((long) type2) << 32); 142.1299 - key2.hashCode = 0x7FFFFFFF & (TYPE_MERGED + type1 + type2); 142.1300 - Item result = get(key2); 142.1301 - if(result == null) 142.1302 - { 142.1303 - String t = typeTable[type1].strVal1; 142.1304 - String u = typeTable[type2].strVal1; 142.1305 - key2.intVal = addType(getCommonSuperClass(t, u)); 142.1306 - result = new Item((short) 0, key2); 142.1307 - put(result); 142.1308 - } 142.1309 - return result.intVal; 142.1310 -} 142.1311 - 142.1312 -/** 142.1313 - * Returns the common super type of the two given types. The default 142.1314 - * implementation of this method <i>loads<i> the two given classes and uses 142.1315 - * the java.lang.Class methods to find the common super class. It can be 142.1316 - * overriden to compute this common super type in other ways, in particular 142.1317 - * without actually loading any class, or to take into account the class 142.1318 - * that is currently being generated by this ClassWriter, which can of 142.1319 - * course not be loaded since it is under construction. 142.1320 - * 142.1321 - * @param type1 the internal name of a class. 142.1322 - * @param type2 the internal name of another class. 142.1323 - * @return the internal name of the common super class of the two given 142.1324 - * classes. 142.1325 - */ 142.1326 -protected String getCommonSuperClass(final String type1, final String type2){ 142.1327 - Class c, d; 142.1328 - try 142.1329 - { 142.1330 - c = Class.forName(type1.replace('/', '.')); 142.1331 - d = Class.forName(type2.replace('/', '.')); 142.1332 - } 142.1333 - catch(ClassNotFoundException e) 142.1334 - { 142.1335 - throw new RuntimeException(e); 142.1336 - } 142.1337 - if(c.isAssignableFrom(d)) 142.1338 - { 142.1339 - return type1; 142.1340 - } 142.1341 - if(d.isAssignableFrom(c)) 142.1342 - { 142.1343 - return type2; 142.1344 - } 142.1345 - if(c.isInterface() || d.isInterface()) 142.1346 - { 142.1347 - return "java/lang/Object"; 142.1348 - } 142.1349 - else 142.1350 - { 142.1351 - do 142.1352 - { 142.1353 - c = c.getSuperclass(); 142.1354 - } while(!c.isAssignableFrom(d)); 142.1355 - return c.getName().replace('.', '/'); 142.1356 - } 142.1357 -} 142.1358 - 142.1359 -/** 142.1360 - * Returns the constant pool's hash table item which is equal to the given 142.1361 - * item. 142.1362 - * 142.1363 - * @param key a constant pool item. 142.1364 - * @return the constant pool's hash table item which is equal to the given 142.1365 - * item, or <tt>null</tt> if there is no such item. 142.1366 - */ 142.1367 -private Item get(final Item key){ 142.1368 - Item i = items[key.hashCode % items.length]; 142.1369 - while(i != null && !key.isEqualTo(i)) 142.1370 - { 142.1371 - i = i.next; 142.1372 - } 142.1373 - return i; 142.1374 -} 142.1375 - 142.1376 -/** 142.1377 - * Puts the given item in the constant pool's hash table. The hash table 142.1378 - * <i>must</i> not already contains this item. 142.1379 - * 142.1380 - * @param i the item to be added to the constant pool's hash table. 142.1381 - */ 142.1382 -private void put(final Item i){ 142.1383 - if(index > threshold) 142.1384 - { 142.1385 - int ll = items.length; 142.1386 - int nl = ll * 2 + 1; 142.1387 - Item[] newItems = new Item[nl]; 142.1388 - for(int l = ll - 1; l >= 0; --l) 142.1389 - { 142.1390 - Item j = items[l]; 142.1391 - while(j != null) 142.1392 - { 142.1393 - int index = j.hashCode % newItems.length; 142.1394 - Item k = j.next; 142.1395 - j.next = newItems[index]; 142.1396 - newItems[index] = j; 142.1397 - j = k; 142.1398 - } 142.1399 - } 142.1400 - items = newItems; 142.1401 - threshold = (int) (nl * 0.75); 142.1402 - } 142.1403 - int index = i.hashCode % items.length; 142.1404 - i.next = items[index]; 142.1405 - items[index] = i; 142.1406 -} 142.1407 - 142.1408 -/** 142.1409 - * Puts one byte and two shorts into the constant pool. 142.1410 - * 142.1411 - * @param b a byte. 142.1412 - * @param s1 a short. 142.1413 - * @param s2 another short. 142.1414 - */ 142.1415 -private void put122(final int b, final int s1, final int s2){ 142.1416 - pool.put12(b, s1).putShort(s2); 142.1417 -} 142.1418 -}
143.1 --- a/src/clojure/asm/Edge.java Sat Aug 21 06:25:44 2010 -0400 143.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 143.3 @@ -1,75 +0,0 @@ 143.4 -/*** 143.5 - * ASM: a very small and fast Java bytecode manipulation framework 143.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 143.7 - * All rights reserved. 143.8 - * 143.9 - * Redistribution and use in source and binary forms, with or without 143.10 - * modification, are permitted provided that the following conditions 143.11 - * are met: 143.12 - * 1. Redistributions of source code must retain the above copyright 143.13 - * notice, this list of conditions and the following disclaimer. 143.14 - * 2. Redistributions in binary form must reproduce the above copyright 143.15 - * notice, this list of conditions and the following disclaimer in the 143.16 - * documentation and/or other materials provided with the distribution. 143.17 - * 3. Neither the name of the copyright holders nor the names of its 143.18 - * contributors may be used to endorse or promote products derived from 143.19 - * this software without specific prior written permission. 143.20 - * 143.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 143.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 143.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 143.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 143.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 143.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 143.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 143.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 143.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 143.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 143.31 - * THE POSSIBILITY OF SUCH DAMAGE. 143.32 - */ 143.33 -package clojure.asm; 143.34 - 143.35 -/** 143.36 - * An edge in the control flow graph of a method body. See {@link Label Label}. 143.37 - * 143.38 - * @author Eric Bruneton 143.39 - */ 143.40 -class Edge{ 143.41 - 143.42 -/** 143.43 - * Denotes a normal control flow graph edge. 143.44 - */ 143.45 -final static int NORMAL = 0; 143.46 - 143.47 -/** 143.48 - * Denotes a control flow graph edge corresponding to an exception handler. 143.49 - * More precisely any {@link Edge} whose {@link #info} is strictly positive 143.50 - * corresponds to an exception handler. The actual value of {@link #info} is 143.51 - * the index, in the {@link ClassWriter} type table, of the exception that 143.52 - * is catched. 143.53 - */ 143.54 -final static int EXCEPTION = 0x7FFFFFFF; 143.55 - 143.56 -/** 143.57 - * Information about this control flow graph edge. If 143.58 - * {@link ClassWriter#COMPUTE_MAXS} is used this field is the (relative) 143.59 - * stack size in the basic block from which this edge originates. This size 143.60 - * is equal to the stack size at the "jump" instruction to which this edge 143.61 - * corresponds, relatively to the stack size at the beginning of the 143.62 - * originating basic block. If {@link ClassWriter#COMPUTE_FRAMES} is used, 143.63 - * this field is the kind of this control flow graph edge (i.e. NORMAL or 143.64 - * EXCEPTION). 143.65 - */ 143.66 -int info; 143.67 - 143.68 -/** 143.69 - * The successor block of the basic block from which this edge originates. 143.70 - */ 143.71 -Label successor; 143.72 - 143.73 -/** 143.74 - * The next edge in the list of successors of the originating basic block. 143.75 - * See {@link Label#successors successors}. 143.76 - */ 143.77 -Edge next; 143.78 -}
144.1 --- a/src/clojure/asm/FieldVisitor.java Sat Aug 21 06:25:44 2010 -0400 144.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 144.3 @@ -1,64 +0,0 @@ 144.4 -/*** 144.5 - * ASM: a very small and fast Java bytecode manipulation framework 144.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 144.7 - * All rights reserved. 144.8 - * 144.9 - * Redistribution and use in source and binary forms, with or without 144.10 - * modification, are permitted provided that the following conditions 144.11 - * are met: 144.12 - * 1. Redistributions of source code must retain the above copyright 144.13 - * notice, this list of conditions and the following disclaimer. 144.14 - * 2. Redistributions in binary form must reproduce the above copyright 144.15 - * notice, this list of conditions and the following disclaimer in the 144.16 - * documentation and/or other materials provided with the distribution. 144.17 - * 3. Neither the name of the copyright holders nor the names of its 144.18 - * contributors may be used to endorse or promote products derived from 144.19 - * this software without specific prior written permission. 144.20 - * 144.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 144.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 144.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 144.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 144.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 144.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 144.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 144.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 144.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 144.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 144.31 - * THE POSSIBILITY OF SUCH DAMAGE. 144.32 - */ 144.33 -package clojure.asm; 144.34 - 144.35 -/** 144.36 - * A visitor to visit a Java field. The methods of this interface must be called 144.37 - * in the following order: ( <tt>visitAnnotation</tt> | 144.38 - * <tt>visitAttribute</tt> )* <tt>visitEnd</tt>. 144.39 - * 144.40 - * @author Eric Bruneton 144.41 - */ 144.42 -public interface FieldVisitor{ 144.43 - 144.44 -/** 144.45 - * Visits an annotation of the field. 144.46 - * 144.47 - * @param desc the class descriptor of the annotation class. 144.48 - * @param visible <tt>true</tt> if the annotation is visible at runtime. 144.49 - * @return a visitor to visit the annotation values, or <tt>null</tt> if 144.50 - * this visitor is not interested in visiting this annotation. 144.51 - */ 144.52 -AnnotationVisitor visitAnnotation(String desc, boolean visible); 144.53 - 144.54 -/** 144.55 - * Visits a non standard attribute of the field. 144.56 - * 144.57 - * @param attr an attribute. 144.58 - */ 144.59 -void visitAttribute(Attribute attr); 144.60 - 144.61 -/** 144.62 - * Visits the end of the field. This method, which is the last one to be 144.63 - * called, is used to inform the visitor that all the annotations and 144.64 - * attributes of the field have been visited. 144.65 - */ 144.66 -void visitEnd(); 144.67 -}
145.1 --- a/src/clojure/asm/FieldWriter.java Sat Aug 21 06:25:44 2010 -0400 145.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 145.3 @@ -1,290 +0,0 @@ 145.4 -/*** 145.5 - * ASM: a very small and fast Java bytecode manipulation framework 145.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 145.7 - * All rights reserved. 145.8 - * 145.9 - * Redistribution and use in source and binary forms, with or without 145.10 - * modification, are permitted provided that the following conditions 145.11 - * are met: 145.12 - * 1. Redistributions of source code must retain the above copyright 145.13 - * notice, this list of conditions and the following disclaimer. 145.14 - * 2. Redistributions in binary form must reproduce the above copyright 145.15 - * notice, this list of conditions and the following disclaimer in the 145.16 - * documentation and/or other materials provided with the distribution. 145.17 - * 3. Neither the name of the copyright holders nor the names of its 145.18 - * contributors may be used to endorse or promote products derived from 145.19 - * this software without specific prior written permission. 145.20 - * 145.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 145.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 145.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 145.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 145.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 145.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 145.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 145.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 145.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 145.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 145.31 - * THE POSSIBILITY OF SUCH DAMAGE. 145.32 - */ 145.33 -package clojure.asm; 145.34 - 145.35 -/** 145.36 - * An {@link FieldVisitor} that generates Java fields in bytecode form. 145.37 - * 145.38 - * @author Eric Bruneton 145.39 - */ 145.40 -final class FieldWriter implements FieldVisitor{ 145.41 - 145.42 -/** 145.43 - * Next field writer (see {@link ClassWriter#firstField firstField}). 145.44 - */ 145.45 -FieldWriter next; 145.46 - 145.47 -/** 145.48 - * The class writer to which this field must be added. 145.49 - */ 145.50 -private ClassWriter cw; 145.51 - 145.52 -/** 145.53 - * Access flags of this field. 145.54 - */ 145.55 -private int access; 145.56 - 145.57 -/** 145.58 - * The index of the constant pool item that contains the name of this 145.59 - * method. 145.60 - */ 145.61 -private int name; 145.62 - 145.63 -/** 145.64 - * The index of the constant pool item that contains the descriptor of this 145.65 - * field. 145.66 - */ 145.67 -private int desc; 145.68 - 145.69 -/** 145.70 - * The index of the constant pool item that contains the signature of this 145.71 - * field. 145.72 - */ 145.73 -private int signature; 145.74 - 145.75 -/** 145.76 - * The index of the constant pool item that contains the constant value of 145.77 - * this field. 145.78 - */ 145.79 -private int value; 145.80 - 145.81 -/** 145.82 - * The runtime visible annotations of this field. May be <tt>null</tt>. 145.83 - */ 145.84 -private AnnotationWriter anns; 145.85 - 145.86 -/** 145.87 - * The runtime invisible annotations of this field. May be <tt>null</tt>. 145.88 - */ 145.89 -private AnnotationWriter ianns; 145.90 - 145.91 -/** 145.92 - * The non standard attributes of this field. May be <tt>null</tt>. 145.93 - */ 145.94 -private Attribute attrs; 145.95 - 145.96 -// ------------------------------------------------------------------------ 145.97 -// Constructor 145.98 -// ------------------------------------------------------------------------ 145.99 - 145.100 -/** 145.101 - * Constructs a new {@link FieldWriter}. 145.102 - * 145.103 - * @param cw the class writer to which this field must be added. 145.104 - * @param access the field's access flags (see {@link Opcodes}). 145.105 - * @param name the field's name. 145.106 - * @param desc the field's descriptor (see {@link Type}). 145.107 - * @param signature the field's signature. May be <tt>null</tt>. 145.108 - * @param value the field's constant value. May be <tt>null</tt>. 145.109 - */ 145.110 -protected FieldWriter( 145.111 - final ClassWriter cw, 145.112 - final int access, 145.113 - final String name, 145.114 - final String desc, 145.115 - final String signature, 145.116 - final Object value){ 145.117 - if(cw.firstField == null) 145.118 - { 145.119 - cw.firstField = this; 145.120 - } 145.121 - else 145.122 - { 145.123 - cw.lastField.next = this; 145.124 - } 145.125 - cw.lastField = this; 145.126 - this.cw = cw; 145.127 - this.access = access; 145.128 - this.name = cw.newUTF8(name); 145.129 - this.desc = cw.newUTF8(desc); 145.130 - if(signature != null) 145.131 - { 145.132 - this.signature = cw.newUTF8(signature); 145.133 - } 145.134 - if(value != null) 145.135 - { 145.136 - this.value = cw.newConstItem(value).index; 145.137 - } 145.138 -} 145.139 - 145.140 -// ------------------------------------------------------------------------ 145.141 -// Implementation of the FieldVisitor interface 145.142 -// ------------------------------------------------------------------------ 145.143 - 145.144 -public AnnotationVisitor visitAnnotation( 145.145 - final String desc, 145.146 - final boolean visible){ 145.147 - ByteVector bv = new ByteVector(); 145.148 - // write type, and reserve space for values count 145.149 - bv.putShort(cw.newUTF8(desc)).putShort(0); 145.150 - AnnotationWriter aw = new AnnotationWriter(cw, true, bv, bv, 2); 145.151 - if(visible) 145.152 - { 145.153 - aw.next = anns; 145.154 - anns = aw; 145.155 - } 145.156 - else 145.157 - { 145.158 - aw.next = ianns; 145.159 - ianns = aw; 145.160 - } 145.161 - return aw; 145.162 -} 145.163 - 145.164 -public void visitAttribute(final Attribute attr){ 145.165 - attr.next = attrs; 145.166 - attrs = attr; 145.167 -} 145.168 - 145.169 -public void visitEnd(){ 145.170 -} 145.171 - 145.172 -// ------------------------------------------------------------------------ 145.173 -// Utility methods 145.174 -// ------------------------------------------------------------------------ 145.175 - 145.176 -/** 145.177 - * Returns the size of this field. 145.178 - * 145.179 - * @return the size of this field. 145.180 - */ 145.181 -int getSize(){ 145.182 - int size = 8; 145.183 - if(value != 0) 145.184 - { 145.185 - cw.newUTF8("ConstantValue"); 145.186 - size += 8; 145.187 - } 145.188 - if((access & Opcodes.ACC_SYNTHETIC) != 0 145.189 - && (cw.version & 0xffff) < Opcodes.V1_5) 145.190 - { 145.191 - cw.newUTF8("Synthetic"); 145.192 - size += 6; 145.193 - } 145.194 - if((access & Opcodes.ACC_DEPRECATED) != 0) 145.195 - { 145.196 - cw.newUTF8("Deprecated"); 145.197 - size += 6; 145.198 - } 145.199 - if(signature != 0) 145.200 - { 145.201 - cw.newUTF8("Signature"); 145.202 - size += 8; 145.203 - } 145.204 - if(anns != null) 145.205 - { 145.206 - cw.newUTF8("RuntimeVisibleAnnotations"); 145.207 - size += 8 + anns.getSize(); 145.208 - } 145.209 - if(ianns != null) 145.210 - { 145.211 - cw.newUTF8("RuntimeInvisibleAnnotations"); 145.212 - size += 8 + ianns.getSize(); 145.213 - } 145.214 - if(attrs != null) 145.215 - { 145.216 - size += attrs.getSize(cw, null, 0, -1, -1); 145.217 - } 145.218 - return size; 145.219 -} 145.220 - 145.221 -/** 145.222 - * Puts the content of this field into the given byte vector. 145.223 - * 145.224 - * @param out where the content of this field must be put. 145.225 - */ 145.226 -void put(final ByteVector out){ 145.227 - out.putShort(access).putShort(name).putShort(desc); 145.228 - int attributeCount = 0; 145.229 - if(value != 0) 145.230 - { 145.231 - ++attributeCount; 145.232 - } 145.233 - if((access & Opcodes.ACC_SYNTHETIC) != 0 145.234 - && (cw.version & 0xffff) < Opcodes.V1_5) 145.235 - { 145.236 - ++attributeCount; 145.237 - } 145.238 - if((access & Opcodes.ACC_DEPRECATED) != 0) 145.239 - { 145.240 - ++attributeCount; 145.241 - } 145.242 - if(signature != 0) 145.243 - { 145.244 - ++attributeCount; 145.245 - } 145.246 - if(anns != null) 145.247 - { 145.248 - ++attributeCount; 145.249 - } 145.250 - if(ianns != null) 145.251 - { 145.252 - ++attributeCount; 145.253 - } 145.254 - if(attrs != null) 145.255 - { 145.256 - attributeCount += attrs.getCount(); 145.257 - } 145.258 - out.putShort(attributeCount); 145.259 - if(value != 0) 145.260 - { 145.261 - out.putShort(cw.newUTF8("ConstantValue")); 145.262 - out.putInt(2).putShort(value); 145.263 - } 145.264 - if((access & Opcodes.ACC_SYNTHETIC) != 0 145.265 - && (cw.version & 0xffff) < Opcodes.V1_5) 145.266 - { 145.267 - out.putShort(cw.newUTF8("Synthetic")).putInt(0); 145.268 - } 145.269 - if((access & Opcodes.ACC_DEPRECATED) != 0) 145.270 - { 145.271 - out.putShort(cw.newUTF8("Deprecated")).putInt(0); 145.272 - } 145.273 - if(signature != 0) 145.274 - { 145.275 - out.putShort(cw.newUTF8("Signature")); 145.276 - out.putInt(2).putShort(signature); 145.277 - } 145.278 - if(anns != null) 145.279 - { 145.280 - out.putShort(cw.newUTF8("RuntimeVisibleAnnotations")); 145.281 - anns.put(out); 145.282 - } 145.283 - if(ianns != null) 145.284 - { 145.285 - out.putShort(cw.newUTF8("RuntimeInvisibleAnnotations")); 145.286 - ianns.put(out); 145.287 - } 145.288 - if(attrs != null) 145.289 - { 145.290 - attrs.put(cw, null, 0, -1, -1, out); 145.291 - } 145.292 -} 145.293 -}
146.1 --- a/src/clojure/asm/Frame.java Sat Aug 21 06:25:44 2010 -0400 146.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 146.3 @@ -1,1506 +0,0 @@ 146.4 -/*** 146.5 - * ASM: a very small and fast Java bytecode manipulation framework 146.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 146.7 - * All rights reserved. 146.8 - * 146.9 - * Redistribution and use in source and binary forms, with or without 146.10 - * modification, are permitted provided that the following conditions 146.11 - * are met: 146.12 - * 1. Redistributions of source code must retain the above copyright 146.13 - * notice, this list of conditions and the following disclaimer. 146.14 - * 2. Redistributions in binary form must reproduce the above copyright 146.15 - * notice, this list of conditions and the following disclaimer in the 146.16 - * documentation and/or other materials provided with the distribution. 146.17 - * 3. Neither the name of the copyright holders nor the names of its 146.18 - * contributors may be used to endorse or promote products derived from 146.19 - * this software without specific prior written permission. 146.20 - * 146.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 146.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 146.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 146.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 146.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 146.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 146.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 146.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 146.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 146.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 146.31 - * THE POSSIBILITY OF SUCH DAMAGE. 146.32 - */ 146.33 -package clojure.asm; 146.34 - 146.35 -/** 146.36 - * Information about the input and output stack map frames of a basic block. 146.37 - * 146.38 - * @author Eric Bruneton 146.39 - */ 146.40 -final class Frame{ 146.41 - 146.42 -/* 146.43 - * Frames are computed in a two steps process: during the visit of each 146.44 - * instruction, the state of the frame at the end of current basic block is 146.45 - * updated by simulating the action of the instruction on the previous state 146.46 - * of this so called "output frame". In visitMaxs, a fix point algorithm is 146.47 - * used to compute the "input frame" of each basic block, i.e. the stack map 146.48 - * frame at the begining of the basic block, starting from the input frame 146.49 - * of the first basic block (which is computed from the method descriptor), 146.50 - * and by using the previously computed output frames to compute the input 146.51 - * state of the other blocks. 146.52 - * 146.53 - * All output and input frames are stored as arrays of integers. Reference 146.54 - * and array types are represented by an index into a type table (which is 146.55 - * not the same as the constant pool of the class, in order to avoid adding 146.56 - * unnecessary constants in the pool - not all computed frames will end up 146.57 - * being stored in the stack map table). This allows very fast type 146.58 - * comparisons. 146.59 - * 146.60 - * Output stack map frames are computed relatively to the input frame of the 146.61 - * basic block, which is not yet known when output frames are computed. It 146.62 - * is therefore necessary to be able to represent abstract types such as 146.63 - * "the type at position x in the input frame locals" or "the type at 146.64 - * position x from the top of the input frame stack" or even "the type at 146.65 - * position x in the input frame, with y more (or less) array dimensions". 146.66 - * This explains the rather complicated type format used in output frames. 146.67 - * 146.68 - * This format is the following: DIM KIND VALUE (4, 4 and 24 bits). DIM is a 146.69 - * signed number of array dimensions (from -8 to 7). KIND is either BASE, 146.70 - * LOCAL or STACK. BASE is used for types that are not relative to the input 146.71 - * frame. LOCAL is used for types that are relative to the input local 146.72 - * variable types. STACK is used for types that are relative to the input 146.73 - * stack types. VALUE depends on KIND. For LOCAL types, it is an index in 146.74 - * the input local variable types. For STACK types, it is a position 146.75 - * relatively to the top of input frame stack. For BASE types, it is either 146.76 - * one of the constants defined in FrameVisitor, or for OBJECT and 146.77 - * UNINITIALIZED types, a tag and an index in the type table. 146.78 - * 146.79 - * Output frames can contain types of any kind and with a positive or 146.80 - * negative dimension (and even unassigned types, represented by 0 - which 146.81 - * does not correspond to any valid type value). Input frames can only 146.82 - * contain BASE types of positive or null dimension. In all cases the type 146.83 - * table contains only internal type names (array type descriptors are 146.84 - * forbidden - dimensions must be represented through the DIM field). 146.85 - * 146.86 - * The LONG and DOUBLE types are always represented by using two slots (LONG + 146.87 - * TOP or DOUBLE + TOP), for local variable types as well as in the operand 146.88 - * stack. This is necessary to be able to simulate DUPx_y instructions, 146.89 - * whose effect would be dependent on the actual type values if types were 146.90 - * always represented by a single slot in the stack (and this is not 146.91 - * possible, since actual type values are not always known - cf LOCAL and 146.92 - * STACK type kinds). 146.93 - */ 146.94 - 146.95 -/** 146.96 - * Mask to get the dimension of a frame type. This dimension is a signed 146.97 - * integer between -8 and 7. 146.98 - */ 146.99 -final static int DIM = 0xF0000000; 146.100 - 146.101 -/** 146.102 - * Constant to be added to a type to get a type with one more dimension. 146.103 - */ 146.104 -final static int ARRAY_OF = 0x10000000; 146.105 - 146.106 -/** 146.107 - * Constant to be added to a type to get a type with one less dimension. 146.108 - */ 146.109 -final static int ELEMENT_OF = 0xF0000000; 146.110 - 146.111 -/** 146.112 - * Mask to get the kind of a frame type. 146.113 - * 146.114 - * @see #BASE 146.115 - * @see #LOCAL 146.116 - * @see #STACK 146.117 - */ 146.118 -final static int KIND = 0xF000000; 146.119 - 146.120 -/** 146.121 - * Mask to get the value of a frame type. 146.122 - */ 146.123 -final static int VALUE = 0xFFFFFF; 146.124 - 146.125 -/** 146.126 - * Mask to get the kind of base types. 146.127 - */ 146.128 -final static int BASE_KIND = 0xFF00000; 146.129 - 146.130 -/** 146.131 - * Mask to get the value of base types. 146.132 - */ 146.133 -final static int BASE_VALUE = 0xFFFFF; 146.134 - 146.135 -/** 146.136 - * Kind of the types that are not relative to an input stack map frame. 146.137 - */ 146.138 -final static int BASE = 0x1000000; 146.139 - 146.140 -/** 146.141 - * Base kind of the base reference types. The BASE_VALUE of such types is an 146.142 - * index into the type table. 146.143 - */ 146.144 -final static int OBJECT = BASE | 0x700000; 146.145 - 146.146 -/** 146.147 - * Base kind of the uninitialized base types. The BASE_VALUE of such types 146.148 - * in an index into the type table (the Item at that index contains both an 146.149 - * instruction offset and an internal class name). 146.150 - */ 146.151 -final static int UNINITIALIZED = BASE | 0x800000; 146.152 - 146.153 -/** 146.154 - * Kind of the types that are relative to the local variable types of an 146.155 - * input stack map frame. The value of such types is a local variable index. 146.156 - */ 146.157 -private final static int LOCAL = 0x2000000; 146.158 - 146.159 -/** 146.160 - * Kind of the the types that are relative to the stack of an input stack 146.161 - * map frame. The value of such types is a position relatively to the top of 146.162 - * this stack. 146.163 - */ 146.164 -private final static int STACK = 0x3000000; 146.165 - 146.166 -/** 146.167 - * The TOP type. This is a BASE type. 146.168 - */ 146.169 -final static int TOP = BASE | 0; 146.170 - 146.171 -/** 146.172 - * The BOOLEAN type. This is a BASE type mainly used for array types. 146.173 - */ 146.174 -final static int BOOLEAN = BASE | 9; 146.175 - 146.176 -/** 146.177 - * The BYTE type. This is a BASE type mainly used for array types. 146.178 - */ 146.179 -final static int BYTE = BASE | 10; 146.180 - 146.181 -/** 146.182 - * The CHAR type. This is a BASE type mainly used for array types. 146.183 - */ 146.184 -final static int CHAR = BASE | 11; 146.185 - 146.186 -/** 146.187 - * The SHORT type. This is a BASE type mainly used for array types. 146.188 - */ 146.189 -final static int SHORT = BASE | 12; 146.190 - 146.191 -/** 146.192 - * The INTEGER type. This is a BASE type. 146.193 - */ 146.194 -final static int INTEGER = BASE | 1; 146.195 - 146.196 -/** 146.197 - * The FLOAT type. This is a BASE type. 146.198 - */ 146.199 -final static int FLOAT = BASE | 2; 146.200 - 146.201 -/** 146.202 - * The DOUBLE type. This is a BASE type. 146.203 - */ 146.204 -final static int DOUBLE = BASE | 3; 146.205 - 146.206 -/** 146.207 - * The LONG type. This is a BASE type. 146.208 - */ 146.209 -final static int LONG = BASE | 4; 146.210 - 146.211 -/** 146.212 - * The NULL type. This is a BASE type. 146.213 - */ 146.214 -final static int NULL = BASE | 5; 146.215 - 146.216 -/** 146.217 - * The UNINITIALIZED_THIS type. This is a BASE type. 146.218 - */ 146.219 -final static int UNINITIALIZED_THIS = BASE | 6; 146.220 - 146.221 -/** 146.222 - * The stack size variation corresponding to each JVM instruction. This 146.223 - * stack variation is equal to the size of the values produced by an 146.224 - * instruction, minus the size of the values consumed by this instruction. 146.225 - */ 146.226 -final static int[] SIZE; 146.227 - 146.228 -/** 146.229 - * Computes the stack size variation corresponding to each JVM instruction. 146.230 - */ 146.231 -static 146.232 - { 146.233 - int i; 146.234 - int[] b = new int[202]; 146.235 - String s = "EFFFFFFFFGGFFFGGFFFEEFGFGFEEEEEEEEEEEEEEEEEEEEDEDEDDDDD" 146.236 - + "CDCDEEEEEEEEEEEEEEEEEEEEBABABBBBDCFFFGGGEDCDCDCDCDCDCDCDCD" 146.237 - + "CDCEEEEDDDDDDDCDCDCEFEFDDEEFFDEDEEEBDDBBDDDDDDCCCCCCCCEFED" 146.238 - + "DDCDCDEEEEEEEEEEFEEEEEEDDEEDDEE"; 146.239 - for(i = 0; i < b.length; ++i) 146.240 - { 146.241 - b[i] = s.charAt(i) - 'E'; 146.242 - } 146.243 - SIZE = b; 146.244 - 146.245 - // code to generate the above string 146.246 - // 146.247 - // int NA = 0; // not applicable (unused opcode or variable size opcode) 146.248 - // 146.249 - // b = new int[] { 146.250 - // 0, //NOP, // visitInsn 146.251 - // 1, //ACONST_NULL, // - 146.252 - // 1, //ICONST_M1, // - 146.253 - // 1, //ICONST_0, // - 146.254 - // 1, //ICONST_1, // - 146.255 - // 1, //ICONST_2, // - 146.256 - // 1, //ICONST_3, // - 146.257 - // 1, //ICONST_4, // - 146.258 - // 1, //ICONST_5, // - 146.259 - // 2, //LCONST_0, // - 146.260 - // 2, //LCONST_1, // - 146.261 - // 1, //FCONST_0, // - 146.262 - // 1, //FCONST_1, // - 146.263 - // 1, //FCONST_2, // - 146.264 - // 2, //DCONST_0, // - 146.265 - // 2, //DCONST_1, // - 146.266 - // 1, //BIPUSH, // visitIntInsn 146.267 - // 1, //SIPUSH, // - 146.268 - // 1, //LDC, // visitLdcInsn 146.269 - // NA, //LDC_W, // - 146.270 - // NA, //LDC2_W, // - 146.271 - // 1, //ILOAD, // visitVarInsn 146.272 - // 2, //LLOAD, // - 146.273 - // 1, //FLOAD, // - 146.274 - // 2, //DLOAD, // - 146.275 - // 1, //ALOAD, // - 146.276 - // NA, //ILOAD_0, // - 146.277 - // NA, //ILOAD_1, // - 146.278 - // NA, //ILOAD_2, // - 146.279 - // NA, //ILOAD_3, // - 146.280 - // NA, //LLOAD_0, // - 146.281 - // NA, //LLOAD_1, // - 146.282 - // NA, //LLOAD_2, // - 146.283 - // NA, //LLOAD_3, // - 146.284 - // NA, //FLOAD_0, // - 146.285 - // NA, //FLOAD_1, // - 146.286 - // NA, //FLOAD_2, // - 146.287 - // NA, //FLOAD_3, // - 146.288 - // NA, //DLOAD_0, // - 146.289 - // NA, //DLOAD_1, // - 146.290 - // NA, //DLOAD_2, // - 146.291 - // NA, //DLOAD_3, // - 146.292 - // NA, //ALOAD_0, // - 146.293 - // NA, //ALOAD_1, // - 146.294 - // NA, //ALOAD_2, // - 146.295 - // NA, //ALOAD_3, // - 146.296 - // -1, //IALOAD, // visitInsn 146.297 - // 0, //LALOAD, // - 146.298 - // -1, //FALOAD, // - 146.299 - // 0, //DALOAD, // - 146.300 - // -1, //AALOAD, // - 146.301 - // -1, //BALOAD, // - 146.302 - // -1, //CALOAD, // - 146.303 - // -1, //SALOAD, // - 146.304 - // -1, //ISTORE, // visitVarInsn 146.305 - // -2, //LSTORE, // - 146.306 - // -1, //FSTORE, // - 146.307 - // -2, //DSTORE, // - 146.308 - // -1, //ASTORE, // - 146.309 - // NA, //ISTORE_0, // - 146.310 - // NA, //ISTORE_1, // - 146.311 - // NA, //ISTORE_2, // - 146.312 - // NA, //ISTORE_3, // - 146.313 - // NA, //LSTORE_0, // - 146.314 - // NA, //LSTORE_1, // - 146.315 - // NA, //LSTORE_2, // - 146.316 - // NA, //LSTORE_3, // - 146.317 - // NA, //FSTORE_0, // - 146.318 - // NA, //FSTORE_1, // - 146.319 - // NA, //FSTORE_2, // - 146.320 - // NA, //FSTORE_3, // - 146.321 - // NA, //DSTORE_0, // - 146.322 - // NA, //DSTORE_1, // - 146.323 - // NA, //DSTORE_2, // - 146.324 - // NA, //DSTORE_3, // - 146.325 - // NA, //ASTORE_0, // - 146.326 - // NA, //ASTORE_1, // - 146.327 - // NA, //ASTORE_2, // - 146.328 - // NA, //ASTORE_3, // - 146.329 - // -3, //IASTORE, // visitInsn 146.330 - // -4, //LASTORE, // - 146.331 - // -3, //FASTORE, // - 146.332 - // -4, //DASTORE, // - 146.333 - // -3, //AASTORE, // - 146.334 - // -3, //BASTORE, // - 146.335 - // -3, //CASTORE, // - 146.336 - // -3, //SASTORE, // - 146.337 - // -1, //POP, // - 146.338 - // -2, //POP2, // - 146.339 - // 1, //DUP, // - 146.340 - // 1, //DUP_X1, // - 146.341 - // 1, //DUP_X2, // - 146.342 - // 2, //DUP2, // - 146.343 - // 2, //DUP2_X1, // - 146.344 - // 2, //DUP2_X2, // - 146.345 - // 0, //SWAP, // - 146.346 - // -1, //IADD, // - 146.347 - // -2, //LADD, // - 146.348 - // -1, //FADD, // - 146.349 - // -2, //DADD, // - 146.350 - // -1, //ISUB, // - 146.351 - // -2, //LSUB, // - 146.352 - // -1, //FSUB, // - 146.353 - // -2, //DSUB, // - 146.354 - // -1, //IMUL, // - 146.355 - // -2, //LMUL, // - 146.356 - // -1, //FMUL, // - 146.357 - // -2, //DMUL, // - 146.358 - // -1, //IDIV, // - 146.359 - // -2, //LDIV, // - 146.360 - // -1, //FDIV, // - 146.361 - // -2, //DDIV, // - 146.362 - // -1, //IREM, // - 146.363 - // -2, //LREM, // - 146.364 - // -1, //FREM, // - 146.365 - // -2, //DREM, // - 146.366 - // 0, //INEG, // - 146.367 - // 0, //LNEG, // - 146.368 - // 0, //FNEG, // - 146.369 - // 0, //DNEG, // - 146.370 - // -1, //ISHL, // - 146.371 - // -1, //LSHL, // - 146.372 - // -1, //ISHR, // - 146.373 - // -1, //LSHR, // - 146.374 - // -1, //IUSHR, // - 146.375 - // -1, //LUSHR, // - 146.376 - // -1, //IAND, // - 146.377 - // -2, //LAND, // - 146.378 - // -1, //IOR, // - 146.379 - // -2, //LOR, // - 146.380 - // -1, //IXOR, // - 146.381 - // -2, //LXOR, // - 146.382 - // 0, //IINC, // visitIincInsn 146.383 - // 1, //I2L, // visitInsn 146.384 - // 0, //I2F, // - 146.385 - // 1, //I2D, // - 146.386 - // -1, //L2I, // - 146.387 - // -1, //L2F, // - 146.388 - // 0, //L2D, // - 146.389 - // 0, //F2I, // - 146.390 - // 1, //F2L, // - 146.391 - // 1, //F2D, // - 146.392 - // -1, //D2I, // - 146.393 - // 0, //D2L, // - 146.394 - // -1, //D2F, // - 146.395 - // 0, //I2B, // - 146.396 - // 0, //I2C, // - 146.397 - // 0, //I2S, // - 146.398 - // -3, //LCMP, // - 146.399 - // -1, //FCMPL, // - 146.400 - // -1, //FCMPG, // - 146.401 - // -3, //DCMPL, // - 146.402 - // -3, //DCMPG, // - 146.403 - // -1, //IFEQ, // visitJumpInsn 146.404 - // -1, //IFNE, // - 146.405 - // -1, //IFLT, // - 146.406 - // -1, //IFGE, // - 146.407 - // -1, //IFGT, // - 146.408 - // -1, //IFLE, // - 146.409 - // -2, //IF_ICMPEQ, // - 146.410 - // -2, //IF_ICMPNE, // - 146.411 - // -2, //IF_ICMPLT, // - 146.412 - // -2, //IF_ICMPGE, // - 146.413 - // -2, //IF_ICMPGT, // - 146.414 - // -2, //IF_ICMPLE, // - 146.415 - // -2, //IF_ACMPEQ, // - 146.416 - // -2, //IF_ACMPNE, // - 146.417 - // 0, //GOTO, // - 146.418 - // 1, //JSR, // - 146.419 - // 0, //RET, // visitVarInsn 146.420 - // -1, //TABLESWITCH, // visiTableSwitchInsn 146.421 - // -1, //LOOKUPSWITCH, // visitLookupSwitch 146.422 - // -1, //IRETURN, // visitInsn 146.423 - // -2, //LRETURN, // - 146.424 - // -1, //FRETURN, // - 146.425 - // -2, //DRETURN, // - 146.426 - // -1, //ARETURN, // - 146.427 - // 0, //RETURN, // - 146.428 - // NA, //GETSTATIC, // visitFieldInsn 146.429 - // NA, //PUTSTATIC, // - 146.430 - // NA, //GETFIELD, // - 146.431 - // NA, //PUTFIELD, // - 146.432 - // NA, //INVOKEVIRTUAL, // visitMethodInsn 146.433 - // NA, //INVOKESPECIAL, // - 146.434 - // NA, //INVOKESTATIC, // - 146.435 - // NA, //INVOKEINTERFACE, // - 146.436 - // NA, //UNUSED, // NOT VISITED 146.437 - // 1, //NEW, // visitTypeInsn 146.438 - // 0, //NEWARRAY, // visitIntInsn 146.439 - // 0, //ANEWARRAY, // visitTypeInsn 146.440 - // 0, //ARRAYLENGTH, // visitInsn 146.441 - // NA, //ATHROW, // - 146.442 - // 0, //CHECKCAST, // visitTypeInsn 146.443 - // 0, //INSTANCEOF, // - 146.444 - // -1, //MONITORENTER, // visitInsn 146.445 - // -1, //MONITOREXIT, // - 146.446 - // NA, //WIDE, // NOT VISITED 146.447 - // NA, //MULTIANEWARRAY, // visitMultiANewArrayInsn 146.448 - // -1, //IFNULL, // visitJumpInsn 146.449 - // -1, //IFNONNULL, // - 146.450 - // NA, //GOTO_W, // - 146.451 - // NA, //JSR_W, // - 146.452 - // }; 146.453 - // for (i = 0; i < b.length; ++i) { 146.454 - // System.err.print((char)('E' + b[i])); 146.455 - // } 146.456 - // System.err.println(); 146.457 - } 146.458 - 146.459 -/** 146.460 - * The label (i.e. basic block) to which these input and output stack map 146.461 - * frames correspond. 146.462 - */ 146.463 -Label owner; 146.464 - 146.465 -/** 146.466 - * The input stack map frame locals. 146.467 - */ 146.468 -int[] inputLocals; 146.469 - 146.470 -/** 146.471 - * The input stack map frame stack. 146.472 - */ 146.473 -int[] inputStack; 146.474 - 146.475 -/** 146.476 - * The output stack map frame locals. 146.477 - */ 146.478 -private int[] outputLocals; 146.479 - 146.480 -/** 146.481 - * The output stack map frame stack. 146.482 - */ 146.483 -private int[] outputStack; 146.484 - 146.485 -/** 146.486 - * Relative size of the output stack. The exact semantics of this field 146.487 - * depends on the algorithm that is used. 146.488 - * <p/> 146.489 - * When only the maximum stack size is computed, this field is the size of 146.490 - * the output stack relatively to the top of the input stack. 146.491 - * <p/> 146.492 - * When the stack map frames are completely computed, this field is the 146.493 - * actual number of types in {@link #outputStack}. 146.494 - */ 146.495 -private int outputStackTop; 146.496 - 146.497 -/** 146.498 - * Number of types that are initialized in the basic block. 146.499 - * 146.500 - * @see #initializations 146.501 - */ 146.502 -private int initializationCount; 146.503 - 146.504 -/** 146.505 - * The types that are initialized in the basic block. A constructor 146.506 - * invocation on an UNINITIALIZED or UNINITIALIZED_THIS type must replace 146.507 - * <i>every occurence</i> of this type in the local variables and in the 146.508 - * operand stack. This cannot be done during the first phase of the 146.509 - * algorithm since, during this phase, the local variables and the operand 146.510 - * stack are not completely computed. It is therefore necessary to store the 146.511 - * types on which constructors are invoked in the basic block, in order to 146.512 - * do this replacement during the second phase of the algorithm, where the 146.513 - * frames are fully computed. Note that this array can contain types that 146.514 - * are relative to input locals or to the input stack (see below for the 146.515 - * description of the algorithm). 146.516 - */ 146.517 -private int[] initializations; 146.518 - 146.519 -/** 146.520 - * Returns the output frame local variable type at the given index. 146.521 - * 146.522 - * @param local the index of the local that must be returned. 146.523 - * @return the output frame local variable type at the given index. 146.524 - */ 146.525 -private int get(final int local){ 146.526 - if(outputLocals == null || local >= outputLocals.length) 146.527 - { 146.528 - // this local has never been assigned in this basic block, 146.529 - // so it is still equal to its value in the input frame 146.530 - return LOCAL | local; 146.531 - } 146.532 - else 146.533 - { 146.534 - int type = outputLocals[local]; 146.535 - if(type == 0) 146.536 - { 146.537 - // this local has never been assigned in this basic block, 146.538 - // so it is still equal to its value in the input frame 146.539 - type = outputLocals[local] = LOCAL | local; 146.540 - } 146.541 - return type; 146.542 - } 146.543 -} 146.544 - 146.545 -/** 146.546 - * Sets the output frame local variable type at the given index. 146.547 - * 146.548 - * @param local the index of the local that must be set. 146.549 - * @param type the value of the local that must be set. 146.550 - */ 146.551 -private void set(final int local, final int type){ 146.552 - // creates and/or resizes the output local variables array if necessary 146.553 - if(outputLocals == null) 146.554 - { 146.555 - outputLocals = new int[10]; 146.556 - } 146.557 - int n = outputLocals.length; 146.558 - if(local >= n) 146.559 - { 146.560 - int[] t = new int[Math.max(local + 1, 2 * n)]; 146.561 - System.arraycopy(outputLocals, 0, t, 0, n); 146.562 - outputLocals = t; 146.563 - } 146.564 - // sets the local variable 146.565 - outputLocals[local] = type; 146.566 -} 146.567 - 146.568 -/** 146.569 - * Pushes a new type onto the output frame stack. 146.570 - * 146.571 - * @param type the type that must be pushed. 146.572 - */ 146.573 -private void push(final int type){ 146.574 - // creates and/or resizes the output stack array if necessary 146.575 - if(outputStack == null) 146.576 - { 146.577 - outputStack = new int[10]; 146.578 - } 146.579 - int n = outputStack.length; 146.580 - if(outputStackTop >= n) 146.581 - { 146.582 - int[] t = new int[Math.max(outputStackTop + 1, 2 * n)]; 146.583 - System.arraycopy(outputStack, 0, t, 0, n); 146.584 - outputStack = t; 146.585 - } 146.586 - // pushes the type on the output stack 146.587 - outputStack[outputStackTop++] = type; 146.588 - // updates the maximun height reached by the output stack, if needed 146.589 - int top = owner.inputStackTop + outputStackTop; 146.590 - if(top > owner.outputStackMax) 146.591 - { 146.592 - owner.outputStackMax = top; 146.593 - } 146.594 -} 146.595 - 146.596 -/** 146.597 - * Pushes a new type onto the output frame stack. 146.598 - * 146.599 - * @param cw the ClassWriter to which this label belongs. 146.600 - * @param desc the descriptor of the type to be pushed. Can also be a method 146.601 - * descriptor (in this case this method pushes its return type onto 146.602 - * the output frame stack). 146.603 - */ 146.604 -private void push(final ClassWriter cw, final String desc){ 146.605 - int type = type(cw, desc); 146.606 - if(type != 0) 146.607 - { 146.608 - push(type); 146.609 - if(type == LONG || type == DOUBLE) 146.610 - { 146.611 - push(TOP); 146.612 - } 146.613 - } 146.614 -} 146.615 - 146.616 -/** 146.617 - * Returns the int encoding of the given type. 146.618 - * 146.619 - * @param cw the ClassWriter to which this label belongs. 146.620 - * @param desc a type descriptor. 146.621 - * @return the int encoding of the given type. 146.622 - */ 146.623 -private int type(final ClassWriter cw, final String desc){ 146.624 - String t; 146.625 - int index = desc.charAt(0) == '(' ? desc.indexOf(')') + 1 : 0; 146.626 - switch(desc.charAt(index)) 146.627 - { 146.628 - case'V': 146.629 - return 0; 146.630 - case'Z': 146.631 - case'C': 146.632 - case'B': 146.633 - case'S': 146.634 - case'I': 146.635 - return INTEGER; 146.636 - case'F': 146.637 - return FLOAT; 146.638 - case'J': 146.639 - return LONG; 146.640 - case'D': 146.641 - return DOUBLE; 146.642 - case'L': 146.643 - // stores the internal name, not the descriptor! 146.644 - t = desc.substring(index + 1, desc.length() - 1); 146.645 - return OBJECT | cw.addType(t); 146.646 - // case '[': 146.647 - default: 146.648 - // extracts the dimensions and the element type 146.649 - int data; 146.650 - int dims = index + 1; 146.651 - while(desc.charAt(dims) == '[') 146.652 - { 146.653 - ++dims; 146.654 - } 146.655 - switch(desc.charAt(dims)) 146.656 - { 146.657 - case'Z': 146.658 - data = BOOLEAN; 146.659 - break; 146.660 - case'C': 146.661 - data = CHAR; 146.662 - break; 146.663 - case'B': 146.664 - data = BYTE; 146.665 - break; 146.666 - case'S': 146.667 - data = SHORT; 146.668 - break; 146.669 - case'I': 146.670 - data = INTEGER; 146.671 - break; 146.672 - case'F': 146.673 - data = FLOAT; 146.674 - break; 146.675 - case'J': 146.676 - data = LONG; 146.677 - break; 146.678 - case'D': 146.679 - data = DOUBLE; 146.680 - break; 146.681 - // case 'L': 146.682 - default: 146.683 - // stores the internal name, not the descriptor 146.684 - t = desc.substring(dims + 1, desc.length() - 1); 146.685 - data = OBJECT | cw.addType(t); 146.686 - } 146.687 - return (dims - index) << 28 | data; 146.688 - } 146.689 -} 146.690 - 146.691 -/** 146.692 - * Pops a type from the output frame stack and returns its value. 146.693 - * 146.694 - * @return the type that has been popped from the output frame stack. 146.695 - */ 146.696 -private int pop(){ 146.697 - if(outputStackTop > 0) 146.698 - { 146.699 - return outputStack[--outputStackTop]; 146.700 - } 146.701 - else 146.702 - { 146.703 - // if the output frame stack is empty, pops from the input stack 146.704 - return STACK | -(--owner.inputStackTop); 146.705 - } 146.706 -} 146.707 - 146.708 -/** 146.709 - * Pops the given number of types from the output frame stack. 146.710 - * 146.711 - * @param elements the number of types that must be popped. 146.712 - */ 146.713 -private void pop(final int elements){ 146.714 - if(outputStackTop >= elements) 146.715 - { 146.716 - outputStackTop -= elements; 146.717 - } 146.718 - else 146.719 - { 146.720 - // if the number of elements to be popped is greater than the number 146.721 - // of elements in the output stack, clear it, and pops the remaining 146.722 - // elements from the input stack. 146.723 - owner.inputStackTop -= elements - outputStackTop; 146.724 - outputStackTop = 0; 146.725 - } 146.726 -} 146.727 - 146.728 -/** 146.729 - * Pops a type from the output frame stack. 146.730 - * 146.731 - * @param desc the descriptor of the type to be popped. Can also be a method 146.732 - * descriptor (in this case this method pops the types corresponding 146.733 - * to the method arguments). 146.734 - */ 146.735 -private void pop(final String desc){ 146.736 - char c = desc.charAt(0); 146.737 - if(c == '(') 146.738 - { 146.739 - pop((MethodWriter.getArgumentsAndReturnSizes(desc) >> 2) - 1); 146.740 - } 146.741 - else if(c == 'J' || c == 'D') 146.742 - { 146.743 - pop(2); 146.744 - } 146.745 - else 146.746 - { 146.747 - pop(1); 146.748 - } 146.749 -} 146.750 - 146.751 -/** 146.752 - * Adds a new type to the list of types on which a constructor is invoked in 146.753 - * the basic block. 146.754 - * 146.755 - * @param var a type on a which a constructor is invoked. 146.756 - */ 146.757 -private void init(final int var){ 146.758 - // creates and/or resizes the initializations array if necessary 146.759 - if(initializations == null) 146.760 - { 146.761 - initializations = new int[2]; 146.762 - } 146.763 - int n = initializations.length; 146.764 - if(initializationCount >= n) 146.765 - { 146.766 - int[] t = new int[Math.max(initializationCount + 1, 2 * n)]; 146.767 - System.arraycopy(initializations, 0, t, 0, n); 146.768 - initializations = t; 146.769 - } 146.770 - // stores the type to be initialized 146.771 - initializations[initializationCount++] = var; 146.772 -} 146.773 - 146.774 -/** 146.775 - * Replaces the given type with the appropriate type if it is one of the 146.776 - * types on which a constructor is invoked in the basic block. 146.777 - * 146.778 - * @param cw the ClassWriter to which this label belongs. 146.779 - * @param t a type 146.780 - * @return t or, if t is one of the types on which a constructor is invoked 146.781 - * in the basic block, the type corresponding to this constructor. 146.782 - */ 146.783 -private int init(final ClassWriter cw, final int t){ 146.784 - int s; 146.785 - if(t == UNINITIALIZED_THIS) 146.786 - { 146.787 - s = OBJECT | cw.addType(cw.thisName); 146.788 - } 146.789 - else if((t & (DIM | BASE_KIND)) == UNINITIALIZED) 146.790 - { 146.791 - String type = cw.typeTable[t & BASE_VALUE].strVal1; 146.792 - s = OBJECT | cw.addType(type); 146.793 - } 146.794 - else 146.795 - { 146.796 - return t; 146.797 - } 146.798 - for(int j = 0; j < initializationCount; ++j) 146.799 - { 146.800 - int u = initializations[j]; 146.801 - int dim = u & DIM; 146.802 - int kind = u & KIND; 146.803 - if(kind == LOCAL) 146.804 - { 146.805 - u = dim + inputLocals[u & VALUE]; 146.806 - } 146.807 - else if(kind == STACK) 146.808 - { 146.809 - u = dim + inputStack[inputStack.length - (u & VALUE)]; 146.810 - } 146.811 - if(t == u) 146.812 - { 146.813 - return s; 146.814 - } 146.815 - } 146.816 - return t; 146.817 -} 146.818 - 146.819 -/** 146.820 - * Initializes the input frame of the first basic block from the method 146.821 - * descriptor. 146.822 - * 146.823 - * @param cw the ClassWriter to which this label belongs. 146.824 - * @param access the access flags of the method to which this label belongs. 146.825 - * @param args the formal parameter types of this method. 146.826 - * @param maxLocals the maximum number of local variables of this method. 146.827 - */ 146.828 -void initInputFrame( 146.829 - final ClassWriter cw, 146.830 - final int access, 146.831 - final Type[] args, 146.832 - final int maxLocals){ 146.833 - inputLocals = new int[maxLocals]; 146.834 - inputStack = new int[0]; 146.835 - int i = 0; 146.836 - if((access & Opcodes.ACC_STATIC) == 0) 146.837 - { 146.838 - if((access & MethodWriter.ACC_CONSTRUCTOR) == 0) 146.839 - { 146.840 - inputLocals[i++] = OBJECT | cw.addType(cw.thisName); 146.841 - } 146.842 - else 146.843 - { 146.844 - inputLocals[i++] = UNINITIALIZED_THIS; 146.845 - } 146.846 - } 146.847 - for(int j = 0; j < args.length; ++j) 146.848 - { 146.849 - int t = type(cw, args[j].getDescriptor()); 146.850 - inputLocals[i++] = t; 146.851 - if(t == LONG || t == DOUBLE) 146.852 - { 146.853 - inputLocals[i++] = TOP; 146.854 - } 146.855 - } 146.856 - while(i < maxLocals) 146.857 - { 146.858 - inputLocals[i++] = TOP; 146.859 - } 146.860 -} 146.861 - 146.862 -/** 146.863 - * Simulates the action of the given instruction on the output stack frame. 146.864 - * 146.865 - * @param opcode the opcode of the instruction. 146.866 - * @param arg the operand of the instruction, if any. 146.867 - * @param cw the class writer to which this label belongs. 146.868 - * @param item the operand of the instructions, if any. 146.869 - */ 146.870 -void execute( 146.871 - final int opcode, 146.872 - final int arg, 146.873 - final ClassWriter cw, 146.874 - final Item item){ 146.875 - int t1, t2, t3, t4; 146.876 - switch(opcode) 146.877 - { 146.878 - case Opcodes.NOP: 146.879 - case Opcodes.INEG: 146.880 - case Opcodes.LNEG: 146.881 - case Opcodes.FNEG: 146.882 - case Opcodes.DNEG: 146.883 - case Opcodes.I2B: 146.884 - case Opcodes.I2C: 146.885 - case Opcodes.I2S: 146.886 - case Opcodes.GOTO: 146.887 - case Opcodes.RETURN: 146.888 - break; 146.889 - case Opcodes.ACONST_NULL: 146.890 - push(NULL); 146.891 - break; 146.892 - case Opcodes.ICONST_M1: 146.893 - case Opcodes.ICONST_0: 146.894 - case Opcodes.ICONST_1: 146.895 - case Opcodes.ICONST_2: 146.896 - case Opcodes.ICONST_3: 146.897 - case Opcodes.ICONST_4: 146.898 - case Opcodes.ICONST_5: 146.899 - case Opcodes.BIPUSH: 146.900 - case Opcodes.SIPUSH: 146.901 - case Opcodes.ILOAD: 146.902 - push(INTEGER); 146.903 - break; 146.904 - case Opcodes.LCONST_0: 146.905 - case Opcodes.LCONST_1: 146.906 - case Opcodes.LLOAD: 146.907 - push(LONG); 146.908 - push(TOP); 146.909 - break; 146.910 - case Opcodes.FCONST_0: 146.911 - case Opcodes.FCONST_1: 146.912 - case Opcodes.FCONST_2: 146.913 - case Opcodes.FLOAD: 146.914 - push(FLOAT); 146.915 - break; 146.916 - case Opcodes.DCONST_0: 146.917 - case Opcodes.DCONST_1: 146.918 - case Opcodes.DLOAD: 146.919 - push(DOUBLE); 146.920 - push(TOP); 146.921 - break; 146.922 - case Opcodes.LDC: 146.923 - switch(item.type) 146.924 - { 146.925 - case ClassWriter.INT: 146.926 - push(INTEGER); 146.927 - break; 146.928 - case ClassWriter.LONG: 146.929 - push(LONG); 146.930 - push(TOP); 146.931 - break; 146.932 - case ClassWriter.FLOAT: 146.933 - push(FLOAT); 146.934 - break; 146.935 - case ClassWriter.DOUBLE: 146.936 - push(DOUBLE); 146.937 - push(TOP); 146.938 - break; 146.939 - case ClassWriter.CLASS: 146.940 - push(OBJECT | cw.addType("java/lang/Class")); 146.941 - break; 146.942 - // case ClassWriter.STR: 146.943 - default: 146.944 - push(OBJECT | cw.addType("java/lang/String")); 146.945 - } 146.946 - break; 146.947 - case Opcodes.ALOAD: 146.948 - push(get(arg)); 146.949 - break; 146.950 - case Opcodes.IALOAD: 146.951 - case Opcodes.BALOAD: 146.952 - case Opcodes.CALOAD: 146.953 - case Opcodes.SALOAD: 146.954 - pop(2); 146.955 - push(INTEGER); 146.956 - break; 146.957 - case Opcodes.LALOAD: 146.958 - case Opcodes.D2L: 146.959 - pop(2); 146.960 - push(LONG); 146.961 - push(TOP); 146.962 - break; 146.963 - case Opcodes.FALOAD: 146.964 - pop(2); 146.965 - push(FLOAT); 146.966 - break; 146.967 - case Opcodes.DALOAD: 146.968 - case Opcodes.L2D: 146.969 - pop(2); 146.970 - push(DOUBLE); 146.971 - push(TOP); 146.972 - break; 146.973 - case Opcodes.AALOAD: 146.974 - pop(1); 146.975 - t1 = pop(); 146.976 - push(ELEMENT_OF + t1); 146.977 - break; 146.978 - case Opcodes.ISTORE: 146.979 - case Opcodes.FSTORE: 146.980 - case Opcodes.ASTORE: 146.981 - t1 = pop(); 146.982 - set(arg, t1); 146.983 - if(arg > 0) 146.984 - { 146.985 - t2 = get(arg - 1); 146.986 - // if t2 is of kind STACK or LOCAL we cannot know its size! 146.987 - if(t2 == LONG || t2 == DOUBLE) 146.988 - { 146.989 - set(arg - 1, TOP); 146.990 - } 146.991 - } 146.992 - break; 146.993 - case Opcodes.LSTORE: 146.994 - case Opcodes.DSTORE: 146.995 - pop(1); 146.996 - t1 = pop(); 146.997 - set(arg, t1); 146.998 - set(arg + 1, TOP); 146.999 - if(arg > 0) 146.1000 - { 146.1001 - t2 = get(arg - 1); 146.1002 - // if t2 is of kind STACK or LOCAL we cannot know its size! 146.1003 - if(t2 == LONG || t2 == DOUBLE) 146.1004 - { 146.1005 - set(arg - 1, TOP); 146.1006 - } 146.1007 - } 146.1008 - break; 146.1009 - case Opcodes.IASTORE: 146.1010 - case Opcodes.BASTORE: 146.1011 - case Opcodes.CASTORE: 146.1012 - case Opcodes.SASTORE: 146.1013 - case Opcodes.FASTORE: 146.1014 - case Opcodes.AASTORE: 146.1015 - pop(3); 146.1016 - break; 146.1017 - case Opcodes.LASTORE: 146.1018 - case Opcodes.DASTORE: 146.1019 - pop(4); 146.1020 - break; 146.1021 - case Opcodes.POP: 146.1022 - case Opcodes.IFEQ: 146.1023 - case Opcodes.IFNE: 146.1024 - case Opcodes.IFLT: 146.1025 - case Opcodes.IFGE: 146.1026 - case Opcodes.IFGT: 146.1027 - case Opcodes.IFLE: 146.1028 - case Opcodes.IRETURN: 146.1029 - case Opcodes.FRETURN: 146.1030 - case Opcodes.ARETURN: 146.1031 - case Opcodes.TABLESWITCH: 146.1032 - case Opcodes.LOOKUPSWITCH: 146.1033 - case Opcodes.ATHROW: 146.1034 - case Opcodes.MONITORENTER: 146.1035 - case Opcodes.MONITOREXIT: 146.1036 - case Opcodes.IFNULL: 146.1037 - case Opcodes.IFNONNULL: 146.1038 - pop(1); 146.1039 - break; 146.1040 - case Opcodes.POP2: 146.1041 - case Opcodes.IF_ICMPEQ: 146.1042 - case Opcodes.IF_ICMPNE: 146.1043 - case Opcodes.IF_ICMPLT: 146.1044 - case Opcodes.IF_ICMPGE: 146.1045 - case Opcodes.IF_ICMPGT: 146.1046 - case Opcodes.IF_ICMPLE: 146.1047 - case Opcodes.IF_ACMPEQ: 146.1048 - case Opcodes.IF_ACMPNE: 146.1049 - case Opcodes.LRETURN: 146.1050 - case Opcodes.DRETURN: 146.1051 - pop(2); 146.1052 - break; 146.1053 - case Opcodes.DUP: 146.1054 - t1 = pop(); 146.1055 - push(t1); 146.1056 - push(t1); 146.1057 - break; 146.1058 - case Opcodes.DUP_X1: 146.1059 - t1 = pop(); 146.1060 - t2 = pop(); 146.1061 - push(t1); 146.1062 - push(t2); 146.1063 - push(t1); 146.1064 - break; 146.1065 - case Opcodes.DUP_X2: 146.1066 - t1 = pop(); 146.1067 - t2 = pop(); 146.1068 - t3 = pop(); 146.1069 - push(t1); 146.1070 - push(t3); 146.1071 - push(t2); 146.1072 - push(t1); 146.1073 - break; 146.1074 - case Opcodes.DUP2: 146.1075 - t1 = pop(); 146.1076 - t2 = pop(); 146.1077 - push(t2); 146.1078 - push(t1); 146.1079 - push(t2); 146.1080 - push(t1); 146.1081 - break; 146.1082 - case Opcodes.DUP2_X1: 146.1083 - t1 = pop(); 146.1084 - t2 = pop(); 146.1085 - t3 = pop(); 146.1086 - push(t2); 146.1087 - push(t1); 146.1088 - push(t3); 146.1089 - push(t2); 146.1090 - push(t1); 146.1091 - break; 146.1092 - case Opcodes.DUP2_X2: 146.1093 - t1 = pop(); 146.1094 - t2 = pop(); 146.1095 - t3 = pop(); 146.1096 - t4 = pop(); 146.1097 - push(t2); 146.1098 - push(t1); 146.1099 - push(t4); 146.1100 - push(t3); 146.1101 - push(t2); 146.1102 - push(t1); 146.1103 - break; 146.1104 - case Opcodes.SWAP: 146.1105 - t1 = pop(); 146.1106 - t2 = pop(); 146.1107 - push(t1); 146.1108 - push(t2); 146.1109 - break; 146.1110 - case Opcodes.IADD: 146.1111 - case Opcodes.ISUB: 146.1112 - case Opcodes.IMUL: 146.1113 - case Opcodes.IDIV: 146.1114 - case Opcodes.IREM: 146.1115 - case Opcodes.IAND: 146.1116 - case Opcodes.IOR: 146.1117 - case Opcodes.IXOR: 146.1118 - case Opcodes.ISHL: 146.1119 - case Opcodes.ISHR: 146.1120 - case Opcodes.IUSHR: 146.1121 - case Opcodes.L2I: 146.1122 - case Opcodes.D2I: 146.1123 - case Opcodes.FCMPL: 146.1124 - case Opcodes.FCMPG: 146.1125 - pop(2); 146.1126 - push(INTEGER); 146.1127 - break; 146.1128 - case Opcodes.LADD: 146.1129 - case Opcodes.LSUB: 146.1130 - case Opcodes.LMUL: 146.1131 - case Opcodes.LDIV: 146.1132 - case Opcodes.LREM: 146.1133 - case Opcodes.LAND: 146.1134 - case Opcodes.LOR: 146.1135 - case Opcodes.LXOR: 146.1136 - pop(4); 146.1137 - push(LONG); 146.1138 - push(TOP); 146.1139 - break; 146.1140 - case Opcodes.FADD: 146.1141 - case Opcodes.FSUB: 146.1142 - case Opcodes.FMUL: 146.1143 - case Opcodes.FDIV: 146.1144 - case Opcodes.FREM: 146.1145 - case Opcodes.L2F: 146.1146 - case Opcodes.D2F: 146.1147 - pop(2); 146.1148 - push(FLOAT); 146.1149 - break; 146.1150 - case Opcodes.DADD: 146.1151 - case Opcodes.DSUB: 146.1152 - case Opcodes.DMUL: 146.1153 - case Opcodes.DDIV: 146.1154 - case Opcodes.DREM: 146.1155 - pop(4); 146.1156 - push(DOUBLE); 146.1157 - push(TOP); 146.1158 - break; 146.1159 - case Opcodes.LSHL: 146.1160 - case Opcodes.LSHR: 146.1161 - case Opcodes.LUSHR: 146.1162 - pop(3); 146.1163 - push(LONG); 146.1164 - push(TOP); 146.1165 - break; 146.1166 - case Opcodes.IINC: 146.1167 - set(arg, INTEGER); 146.1168 - break; 146.1169 - case Opcodes.I2L: 146.1170 - case Opcodes.F2L: 146.1171 - pop(1); 146.1172 - push(LONG); 146.1173 - push(TOP); 146.1174 - break; 146.1175 - case Opcodes.I2F: 146.1176 - pop(1); 146.1177 - push(FLOAT); 146.1178 - break; 146.1179 - case Opcodes.I2D: 146.1180 - case Opcodes.F2D: 146.1181 - pop(1); 146.1182 - push(DOUBLE); 146.1183 - push(TOP); 146.1184 - break; 146.1185 - case Opcodes.F2I: 146.1186 - case Opcodes.ARRAYLENGTH: 146.1187 - case Opcodes.INSTANCEOF: 146.1188 - pop(1); 146.1189 - push(INTEGER); 146.1190 - break; 146.1191 - case Opcodes.LCMP: 146.1192 - case Opcodes.DCMPL: 146.1193 - case Opcodes.DCMPG: 146.1194 - pop(4); 146.1195 - push(INTEGER); 146.1196 - break; 146.1197 - case Opcodes.JSR: 146.1198 - case Opcodes.RET: 146.1199 - throw new RuntimeException("JSR/RET are not supported with computeFrames option"); 146.1200 - case Opcodes.GETSTATIC: 146.1201 - push(cw, item.strVal3); 146.1202 - break; 146.1203 - case Opcodes.PUTSTATIC: 146.1204 - pop(item.strVal3); 146.1205 - break; 146.1206 - case Opcodes.GETFIELD: 146.1207 - pop(1); 146.1208 - push(cw, item.strVal3); 146.1209 - break; 146.1210 - case Opcodes.PUTFIELD: 146.1211 - pop(item.strVal3); 146.1212 - pop(); 146.1213 - break; 146.1214 - case Opcodes.INVOKEVIRTUAL: 146.1215 - case Opcodes.INVOKESPECIAL: 146.1216 - case Opcodes.INVOKESTATIC: 146.1217 - case Opcodes.INVOKEINTERFACE: 146.1218 - pop(item.strVal3); 146.1219 - if(opcode != Opcodes.INVOKESTATIC) 146.1220 - { 146.1221 - t1 = pop(); 146.1222 - if(opcode == Opcodes.INVOKESPECIAL 146.1223 - && item.strVal2.charAt(0) == '<') 146.1224 - { 146.1225 - init(t1); 146.1226 - } 146.1227 - } 146.1228 - push(cw, item.strVal3); 146.1229 - break; 146.1230 - case Opcodes.NEW: 146.1231 - push(UNINITIALIZED | cw.addUninitializedType(item.strVal1, arg)); 146.1232 - break; 146.1233 - case Opcodes.NEWARRAY: 146.1234 - pop(); 146.1235 - switch(arg) 146.1236 - { 146.1237 - case Opcodes.T_BOOLEAN: 146.1238 - push(ARRAY_OF | BOOLEAN); 146.1239 - break; 146.1240 - case Opcodes.T_CHAR: 146.1241 - push(ARRAY_OF | CHAR); 146.1242 - break; 146.1243 - case Opcodes.T_BYTE: 146.1244 - push(ARRAY_OF | BYTE); 146.1245 - break; 146.1246 - case Opcodes.T_SHORT: 146.1247 - push(ARRAY_OF | SHORT); 146.1248 - break; 146.1249 - case Opcodes.T_INT: 146.1250 - push(ARRAY_OF | INTEGER); 146.1251 - break; 146.1252 - case Opcodes.T_FLOAT: 146.1253 - push(ARRAY_OF | FLOAT); 146.1254 - break; 146.1255 - case Opcodes.T_DOUBLE: 146.1256 - push(ARRAY_OF | DOUBLE); 146.1257 - break; 146.1258 - // case Opcodes.T_LONG: 146.1259 - default: 146.1260 - push(ARRAY_OF | LONG); 146.1261 - break; 146.1262 - } 146.1263 - break; 146.1264 - case Opcodes.ANEWARRAY: 146.1265 - String s = item.strVal1; 146.1266 - pop(); 146.1267 - if(s.charAt(0) == '[') 146.1268 - { 146.1269 - push(cw, "[" + s); 146.1270 - } 146.1271 - else 146.1272 - { 146.1273 - push(ARRAY_OF | OBJECT | cw.addType(s)); 146.1274 - } 146.1275 - break; 146.1276 - case Opcodes.CHECKCAST: 146.1277 - s = item.strVal1; 146.1278 - pop(); 146.1279 - if(s.charAt(0) == '[') 146.1280 - { 146.1281 - push(cw, s); 146.1282 - } 146.1283 - else 146.1284 - { 146.1285 - push(OBJECT | cw.addType(s)); 146.1286 - } 146.1287 - break; 146.1288 - // case Opcodes.MULTIANEWARRAY: 146.1289 - default: 146.1290 - pop(arg); 146.1291 - push(cw, item.strVal1); 146.1292 - break; 146.1293 - } 146.1294 -} 146.1295 - 146.1296 -/** 146.1297 - * Merges the input frame of the given basic block with the input and output 146.1298 - * frames of this basic block. Returns <tt>true</tt> if the input frame of 146.1299 - * the given label has been changed by this operation. 146.1300 - * 146.1301 - * @param cw the ClassWriter to which this label belongs. 146.1302 - * @param frame the basic block whose input frame must be updated. 146.1303 - * @param edge the kind of the {@link Edge} between this label and 'label'. 146.1304 - * See {@link Edge#info}. 146.1305 - * @return <tt>true</tt> if the input frame of the given label has been 146.1306 - * changed by this operation. 146.1307 - */ 146.1308 -boolean merge(final ClassWriter cw, final Frame frame, final int edge){ 146.1309 - boolean changed = false; 146.1310 - int i, s, dim, kind, t; 146.1311 - 146.1312 - int nLocal = inputLocals.length; 146.1313 - int nStack = inputStack.length; 146.1314 - if(frame.inputLocals == null) 146.1315 - { 146.1316 - frame.inputLocals = new int[nLocal]; 146.1317 - changed = true; 146.1318 - } 146.1319 - 146.1320 - for(i = 0; i < nLocal; ++i) 146.1321 - { 146.1322 - if(outputLocals != null && i < outputLocals.length) 146.1323 - { 146.1324 - s = outputLocals[i]; 146.1325 - if(s == 0) 146.1326 - { 146.1327 - t = inputLocals[i]; 146.1328 - } 146.1329 - else 146.1330 - { 146.1331 - dim = s & DIM; 146.1332 - kind = s & KIND; 146.1333 - if(kind == LOCAL) 146.1334 - { 146.1335 - t = dim + inputLocals[s & VALUE]; 146.1336 - } 146.1337 - else if(kind == STACK) 146.1338 - { 146.1339 - t = dim + inputStack[nStack - (s & VALUE)]; 146.1340 - } 146.1341 - else 146.1342 - { 146.1343 - t = s; 146.1344 - } 146.1345 - } 146.1346 - } 146.1347 - else 146.1348 - { 146.1349 - t = inputLocals[i]; 146.1350 - } 146.1351 - if(initializations != null) 146.1352 - { 146.1353 - t = init(cw, t); 146.1354 - } 146.1355 - changed |= merge(cw, t, frame.inputLocals, i); 146.1356 - } 146.1357 - 146.1358 - if(edge > 0) 146.1359 - { 146.1360 - for(i = 0; i < nLocal; ++i) 146.1361 - { 146.1362 - t = inputLocals[i]; 146.1363 - changed |= merge(cw, t, frame.inputLocals, i); 146.1364 - } 146.1365 - if(frame.inputStack == null) 146.1366 - { 146.1367 - frame.inputStack = new int[1]; 146.1368 - changed = true; 146.1369 - } 146.1370 - changed |= merge(cw, edge, frame.inputStack, 0); 146.1371 - return changed; 146.1372 - } 146.1373 - 146.1374 - int nInputStack = inputStack.length + owner.inputStackTop; 146.1375 - if(frame.inputStack == null) 146.1376 - { 146.1377 - frame.inputStack = new int[nInputStack + outputStackTop]; 146.1378 - changed = true; 146.1379 - } 146.1380 - 146.1381 - for(i = 0; i < nInputStack; ++i) 146.1382 - { 146.1383 - t = inputStack[i]; 146.1384 - if(initializations != null) 146.1385 - { 146.1386 - t = init(cw, t); 146.1387 - } 146.1388 - changed |= merge(cw, t, frame.inputStack, i); 146.1389 - } 146.1390 - for(i = 0; i < outputStackTop; ++i) 146.1391 - { 146.1392 - s = outputStack[i]; 146.1393 - dim = s & DIM; 146.1394 - kind = s & KIND; 146.1395 - if(kind == LOCAL) 146.1396 - { 146.1397 - t = dim + inputLocals[s & VALUE]; 146.1398 - } 146.1399 - else if(kind == STACK) 146.1400 - { 146.1401 - t = dim + inputStack[nStack - (s & VALUE)]; 146.1402 - } 146.1403 - else 146.1404 - { 146.1405 - t = s; 146.1406 - } 146.1407 - if(initializations != null) 146.1408 - { 146.1409 - t = init(cw, t); 146.1410 - } 146.1411 - changed |= merge(cw, t, frame.inputStack, nInputStack + i); 146.1412 - } 146.1413 - return changed; 146.1414 -} 146.1415 - 146.1416 -/** 146.1417 - * Merges the type at the given index in the given type array with the given 146.1418 - * type. Returns <tt>true</tt> if the type array has been modified by this 146.1419 - * operation. 146.1420 - * 146.1421 - * @param cw the ClassWriter to which this label belongs. 146.1422 - * @param t the type with which the type array element must be merged. 146.1423 - * @param types an array of types. 146.1424 - * @param index the index of the type that must be merged in 'types'. 146.1425 - * @return <tt>true</tt> if the type array has been modified by this 146.1426 - * operation. 146.1427 - */ 146.1428 -private boolean merge( 146.1429 - final ClassWriter cw, 146.1430 - int t, 146.1431 - final int[] types, 146.1432 - final int index){ 146.1433 - int u = types[index]; 146.1434 - if(u == t) 146.1435 - { 146.1436 - // if the types are equal, merge(u,t)=u, so there is no change 146.1437 - return false; 146.1438 - } 146.1439 - if((t & ~DIM) == NULL) 146.1440 - { 146.1441 - if(u == NULL) 146.1442 - { 146.1443 - return false; 146.1444 - } 146.1445 - t = NULL; 146.1446 - } 146.1447 - if(u == 0) 146.1448 - { 146.1449 - // if types[index] has never been assigned, merge(u,t)=t 146.1450 - types[index] = t; 146.1451 - return true; 146.1452 - } 146.1453 - int v; 146.1454 - if((u & BASE_KIND) == OBJECT || (u & DIM) != 0) 146.1455 - { 146.1456 - // if u is a reference type of any dimension 146.1457 - if(t == NULL) 146.1458 - { 146.1459 - // if t is the NULL type, merge(u,t)=u, so there is no change 146.1460 - return false; 146.1461 - } 146.1462 - else if((t & (DIM | BASE_KIND)) == (u & (DIM | BASE_KIND))) 146.1463 - { 146.1464 - if((u & BASE_KIND) == OBJECT) 146.1465 - { 146.1466 - // if t is also a reference type, and if u and t have the 146.1467 - // same dimension merge(u,t) = dim(t) | common parent of the 146.1468 - // element types of u and t 146.1469 - v = (t & DIM) | OBJECT 146.1470 - | cw.getMergedType(t & BASE_VALUE, u & BASE_VALUE); 146.1471 - } 146.1472 - else 146.1473 - { 146.1474 - // if u and t are array types, but not with the same element 146.1475 - // type, merge(u,t)=java/lang/Object 146.1476 - v = OBJECT | cw.addType("java/lang/Object"); 146.1477 - } 146.1478 - } 146.1479 - else if((t & BASE_KIND) == OBJECT || (t & DIM) != 0) 146.1480 - { 146.1481 - // if t is any other reference or array type, 146.1482 - // merge(u,t)=java/lang/Object 146.1483 - v = OBJECT | cw.addType("java/lang/Object"); 146.1484 - } 146.1485 - else 146.1486 - { 146.1487 - // if t is any other type, merge(u,t)=TOP 146.1488 - v = TOP; 146.1489 - } 146.1490 - } 146.1491 - else if(u == NULL) 146.1492 - { 146.1493 - // if u is the NULL type, merge(u,t)=t, 146.1494 - // or TOP if t is not a reference type 146.1495 - v = (t & BASE_KIND) == OBJECT || (t & DIM) != 0 ? t : TOP; 146.1496 - } 146.1497 - else 146.1498 - { 146.1499 - // if u is any other type, merge(u,t)=TOP whatever t 146.1500 - v = TOP; 146.1501 - } 146.1502 - if(u != v) 146.1503 - { 146.1504 - types[index] = v; 146.1505 - return true; 146.1506 - } 146.1507 - return false; 146.1508 -} 146.1509 -}
147.1 --- a/src/clojure/asm/Handler.java Sat Aug 21 06:25:44 2010 -0400 147.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 147.3 @@ -1,70 +0,0 @@ 147.4 -/*** 147.5 - * ASM: a very small and fast Java bytecode manipulation framework 147.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 147.7 - * All rights reserved. 147.8 - * 147.9 - * Redistribution and use in source and binary forms, with or without 147.10 - * modification, are permitted provided that the following conditions 147.11 - * are met: 147.12 - * 1. Redistributions of source code must retain the above copyright 147.13 - * notice, this list of conditions and the following disclaimer. 147.14 - * 2. Redistributions in binary form must reproduce the above copyright 147.15 - * notice, this list of conditions and the following disclaimer in the 147.16 - * documentation and/or other materials provided with the distribution. 147.17 - * 3. Neither the name of the copyright holders nor the names of its 147.18 - * contributors may be used to endorse or promote products derived from 147.19 - * this software without specific prior written permission. 147.20 - * 147.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 147.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 147.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 147.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 147.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 147.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 147.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 147.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 147.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 147.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 147.31 - * THE POSSIBILITY OF SUCH DAMAGE. 147.32 - */ 147.33 -package clojure.asm; 147.34 - 147.35 -/** 147.36 - * Information about an exception handler block. 147.37 - * 147.38 - * @author Eric Bruneton 147.39 - */ 147.40 -class Handler{ 147.41 - 147.42 -/** 147.43 - * Beginning of the exception handler's scope (inclusive). 147.44 - */ 147.45 -Label start; 147.46 - 147.47 -/** 147.48 - * End of the exception handler's scope (exclusive). 147.49 - */ 147.50 -Label end; 147.51 - 147.52 -/** 147.53 - * Beginning of the exception handler's code. 147.54 - */ 147.55 -Label handler; 147.56 - 147.57 -/** 147.58 - * Internal name of the type of exceptions handled by this handler, or 147.59 - * <tt>null</tt> to catch any exceptions. 147.60 - */ 147.61 -String desc; 147.62 - 147.63 -/** 147.64 - * Constant pool index of the internal name of the type of exceptions 147.65 - * handled by this handler, or 0 to catch any exceptions. 147.66 - */ 147.67 -int type; 147.68 - 147.69 -/** 147.70 - * Next exception handler block info. 147.71 - */ 147.72 -Handler next; 147.73 -}
148.1 --- a/src/clojure/asm/Item.java Sat Aug 21 06:25:44 2010 -0400 148.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 148.3 @@ -1,258 +0,0 @@ 148.4 -/*** 148.5 - * ASM: a very small and fast Java bytecode manipulation framework 148.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 148.7 - * All rights reserved. 148.8 - * 148.9 - * Redistribution and use in source and binary forms, with or without 148.10 - * modification, are permitted provided that the following conditions 148.11 - * are met: 148.12 - * 1. Redistributions of source code must retain the above copyright 148.13 - * notice, this list of conditions and the following disclaimer. 148.14 - * 2. Redistributions in binary form must reproduce the above copyright 148.15 - * notice, this list of conditions and the following disclaimer in the 148.16 - * documentation and/or other materials provided with the distribution. 148.17 - * 3. Neither the name of the copyright holders nor the names of its 148.18 - * contributors may be used to endorse or promote products derived from 148.19 - * this software without specific prior written permission. 148.20 - * 148.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 148.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 148.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 148.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 148.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 148.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 148.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 148.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 148.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 148.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 148.31 - * THE POSSIBILITY OF SUCH DAMAGE. 148.32 - */ 148.33 -package clojure.asm; 148.34 - 148.35 -/** 148.36 - * A constant pool item. Constant pool items can be created with the 'newXXX' 148.37 - * methods in the {@link ClassWriter} class. 148.38 - * 148.39 - * @author Eric Bruneton 148.40 - */ 148.41 -final class Item{ 148.42 - 148.43 -/** 148.44 - * Index of this item in the constant pool. 148.45 - */ 148.46 -int index; 148.47 - 148.48 -/** 148.49 - * Type of this constant pool item. A single class is used to represent all 148.50 - * constant pool item types, in order to minimize the bytecode size of this 148.51 - * package. The value of this field is one of {@link ClassWriter#INT}, 148.52 - * {@link ClassWriter#LONG}, {@link ClassWriter#FLOAT}, 148.53 - * {@link ClassWriter#DOUBLE}, {@link ClassWriter#UTF8}, 148.54 - * {@link ClassWriter#STR}, {@link ClassWriter#CLASS}, 148.55 - * {@link ClassWriter#NAME_TYPE}, {@link ClassWriter#FIELD}, 148.56 - * {@link ClassWriter#METH}, {@link ClassWriter#IMETH}. 148.57 - * <p/> 148.58 - * Special Item types are used for Items that are stored in the ClassWriter 148.59 - * {@link ClassWriter#typeTable}, instead of the constant pool, in order to 148.60 - * avoid clashes with normal constant pool items in the ClassWriter constant 148.61 - * pool's hash table. These special item types are 148.62 - * {@link ClassWriter#TYPE_NORMAL}, {@link ClassWriter#TYPE_UNINIT} and 148.63 - * {@link ClassWriter#TYPE_MERGED}. 148.64 - */ 148.65 -int type; 148.66 - 148.67 -/** 148.68 - * Value of this item, for an integer item. 148.69 - */ 148.70 -int intVal; 148.71 - 148.72 -/** 148.73 - * Value of this item, for a long item. 148.74 - */ 148.75 -long longVal; 148.76 - 148.77 -/** 148.78 - * First part of the value of this item, for items that do not hold a 148.79 - * primitive value. 148.80 - */ 148.81 -String strVal1; 148.82 - 148.83 -/** 148.84 - * Second part of the value of this item, for items that do not hold a 148.85 - * primitive value. 148.86 - */ 148.87 -String strVal2; 148.88 - 148.89 -/** 148.90 - * Third part of the value of this item, for items that do not hold a 148.91 - * primitive value. 148.92 - */ 148.93 -String strVal3; 148.94 - 148.95 -/** 148.96 - * The hash code value of this constant pool item. 148.97 - */ 148.98 -int hashCode; 148.99 - 148.100 -/** 148.101 - * Link to another constant pool item, used for collision lists in the 148.102 - * constant pool's hash table. 148.103 - */ 148.104 -Item next; 148.105 - 148.106 -/** 148.107 - * Constructs an uninitialized {@link Item}. 148.108 - */ 148.109 -Item(){ 148.110 -} 148.111 - 148.112 -/** 148.113 - * Constructs an uninitialized {@link Item} for constant pool element at 148.114 - * given position. 148.115 - * 148.116 - * @param index index of the item to be constructed. 148.117 - */ 148.118 -Item(final int index){ 148.119 - this.index = index; 148.120 -} 148.121 - 148.122 -/** 148.123 - * Constructs a copy of the given item. 148.124 - * 148.125 - * @param index index of the item to be constructed. 148.126 - * @param i the item that must be copied into the item to be constructed. 148.127 - */ 148.128 -Item(final int index, final Item i){ 148.129 - this.index = index; 148.130 - type = i.type; 148.131 - intVal = i.intVal; 148.132 - longVal = i.longVal; 148.133 - strVal1 = i.strVal1; 148.134 - strVal2 = i.strVal2; 148.135 - strVal3 = i.strVal3; 148.136 - hashCode = i.hashCode; 148.137 -} 148.138 - 148.139 -/** 148.140 - * Sets this item to an integer item. 148.141 - * 148.142 - * @param intVal the value of this item. 148.143 - */ 148.144 -void set(final int intVal){ 148.145 - this.type = ClassWriter.INT; 148.146 - this.intVal = intVal; 148.147 - this.hashCode = 0x7FFFFFFF & (type + intVal); 148.148 -} 148.149 - 148.150 -/** 148.151 - * Sets this item to a long item. 148.152 - * 148.153 - * @param longVal the value of this item. 148.154 - */ 148.155 -void set(final long longVal){ 148.156 - this.type = ClassWriter.LONG; 148.157 - this.longVal = longVal; 148.158 - this.hashCode = 0x7FFFFFFF & (type + (int) longVal); 148.159 -} 148.160 - 148.161 -/** 148.162 - * Sets this item to a float item. 148.163 - * 148.164 - * @param floatVal the value of this item. 148.165 - */ 148.166 -void set(final float floatVal){ 148.167 - this.type = ClassWriter.FLOAT; 148.168 - this.intVal = Float.floatToRawIntBits(floatVal); 148.169 - this.hashCode = 0x7FFFFFFF & (type + (int) floatVal); 148.170 -} 148.171 - 148.172 -/** 148.173 - * Sets this item to a double item. 148.174 - * 148.175 - * @param doubleVal the value of this item. 148.176 - */ 148.177 -void set(final double doubleVal){ 148.178 - this.type = ClassWriter.DOUBLE; 148.179 - this.longVal = Double.doubleToRawLongBits(doubleVal); 148.180 - this.hashCode = 0x7FFFFFFF & (type + (int) doubleVal); 148.181 -} 148.182 - 148.183 -/** 148.184 - * Sets this item to an item that do not hold a primitive value. 148.185 - * 148.186 - * @param type the type of this item. 148.187 - * @param strVal1 first part of the value of this item. 148.188 - * @param strVal2 second part of the value of this item. 148.189 - * @param strVal3 third part of the value of this item. 148.190 - */ 148.191 -void set( 148.192 - final int type, 148.193 - final String strVal1, 148.194 - final String strVal2, 148.195 - final String strVal3){ 148.196 - this.type = type; 148.197 - this.strVal1 = strVal1; 148.198 - this.strVal2 = strVal2; 148.199 - this.strVal3 = strVal3; 148.200 - switch(type) 148.201 - { 148.202 - case ClassWriter.UTF8: 148.203 - case ClassWriter.STR: 148.204 - case ClassWriter.CLASS: 148.205 - case ClassWriter.TYPE_NORMAL: 148.206 - hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()); 148.207 - return; 148.208 - case ClassWriter.NAME_TYPE: 148.209 - hashCode = 0x7FFFFFFF & (type + strVal1.hashCode() 148.210 - * strVal2.hashCode()); 148.211 - return; 148.212 - // ClassWriter.FIELD: 148.213 - // ClassWriter.METH: 148.214 - // ClassWriter.IMETH: 148.215 - default: 148.216 - hashCode = 0x7FFFFFFF & (type + strVal1.hashCode() 148.217 - * strVal2.hashCode() * strVal3.hashCode()); 148.218 - } 148.219 -} 148.220 - 148.221 -/** 148.222 - * Indicates if the given item is equal to this one. 148.223 - * 148.224 - * @param i the item to be compared to this one. 148.225 - * @return <tt>true</tt> if the given item if equal to this one, 148.226 - * <tt>false</tt> otherwise. 148.227 - */ 148.228 -boolean isEqualTo(final Item i){ 148.229 - if(i.type == type) 148.230 - { 148.231 - switch(type) 148.232 - { 148.233 - case ClassWriter.INT: 148.234 - case ClassWriter.FLOAT: 148.235 - return i.intVal == intVal; 148.236 - case ClassWriter.TYPE_MERGED: 148.237 - case ClassWriter.LONG: 148.238 - case ClassWriter.DOUBLE: 148.239 - return i.longVal == longVal; 148.240 - case ClassWriter.UTF8: 148.241 - case ClassWriter.STR: 148.242 - case ClassWriter.CLASS: 148.243 - case ClassWriter.TYPE_NORMAL: 148.244 - return i.strVal1.equals(strVal1); 148.245 - case ClassWriter.TYPE_UNINIT: 148.246 - return i.intVal == intVal && i.strVal1.equals(strVal1); 148.247 - case ClassWriter.NAME_TYPE: 148.248 - return i.strVal1.equals(strVal1) 148.249 - && i.strVal2.equals(strVal2); 148.250 - // ClassWriter.FIELD: 148.251 - // ClassWriter.METH: 148.252 - // ClassWriter.IMETH: 148.253 - default: 148.254 - return i.strVal1.equals(strVal1) 148.255 - && i.strVal2.equals(strVal2) 148.256 - && i.strVal3.equals(strVal3); 148.257 - } 148.258 - } 148.259 - return false; 148.260 -} 148.261 -}
149.1 --- a/src/clojure/asm/Label.java Sat Aug 21 06:25:44 2010 -0400 149.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 149.3 @@ -1,437 +0,0 @@ 149.4 -/*** 149.5 - * ASM: a very small and fast Java bytecode manipulation framework 149.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 149.7 - * All rights reserved. 149.8 - * 149.9 - * Redistribution and use in source and binary forms, with or without 149.10 - * modification, are permitted provided that the following conditions 149.11 - * are met: 149.12 - * 1. Redistributions of source code must retain the above copyright 149.13 - * notice, this list of conditions and the following disclaimer. 149.14 - * 2. Redistributions in binary form must reproduce the above copyright 149.15 - * notice, this list of conditions and the following disclaimer in the 149.16 - * documentation and/or other materials provided with the distribution. 149.17 - * 3. Neither the name of the copyright holders nor the names of its 149.18 - * contributors may be used to endorse or promote products derived from 149.19 - * this software without specific prior written permission. 149.20 - * 149.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 149.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 149.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 149.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 149.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 149.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 149.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 149.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 149.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 149.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 149.31 - * THE POSSIBILITY OF SUCH DAMAGE. 149.32 - */ 149.33 -package clojure.asm; 149.34 - 149.35 -/** 149.36 - * A label represents a position in the bytecode of a method. Labels are used 149.37 - * for jump, goto, and switch instructions, and for try catch blocks. 149.38 - * 149.39 - * @author Eric Bruneton 149.40 - */ 149.41 -public class Label{ 149.42 - 149.43 -/** 149.44 - * Indicates if this label is only used for debug attributes. Such a label 149.45 - * is not the start of a basic block, the target of a jump instruction, or 149.46 - * an exception handler. It can be safely ignored in control flow graph 149.47 - * analysis algorithms (for optimization purposes). 149.48 - */ 149.49 -final static int DEBUG = 1; 149.50 - 149.51 -/** 149.52 - * Indicates if the position of this label is known. 149.53 - */ 149.54 -final static int RESOLVED = 2; 149.55 - 149.56 -/** 149.57 - * Indicates if this label has been updated, after instruction resizing. 149.58 - */ 149.59 -final static int RESIZED = 4; 149.60 - 149.61 -/** 149.62 - * Indicates if this basic block has been pushed in the basic block stack. 149.63 - * See {@link MethodWriter#visitMaxs visitMaxs}. 149.64 - */ 149.65 -final static int PUSHED = 8; 149.66 - 149.67 -/** 149.68 - * Indicates if this label is the target of a jump instruction, or the start 149.69 - * of an exception handler. 149.70 - */ 149.71 -final static int TARGET = 16; 149.72 - 149.73 -/** 149.74 - * Indicates if a stack map frame must be stored for this label. 149.75 - */ 149.76 -final static int STORE = 32; 149.77 - 149.78 -/** 149.79 - * Indicates if this label corresponds to a reachable basic block. 149.80 - */ 149.81 -final static int REACHABLE = 64; 149.82 - 149.83 -/** 149.84 - * Indicates if this basic block ends with a JSR instruction. 149.85 - */ 149.86 -final static int JSR = 128; 149.87 - 149.88 -/** 149.89 - * Indicates if this basic block ends with a RET instruction. 149.90 - */ 149.91 -final static int RET = 256; 149.92 - 149.93 -/** 149.94 - * Field used to associate user information to a label. 149.95 - */ 149.96 -public Object info; 149.97 - 149.98 -/** 149.99 - * Flags that indicate the status of this label. 149.100 - * 149.101 - * @see #DEBUG 149.102 - * @see #RESOLVED 149.103 - * @see #RESIZED 149.104 - * @see #PUSHED 149.105 - * @see #TARGET 149.106 - * @see #STORE 149.107 - * @see #REACHABLE 149.108 - * @see #JSR 149.109 - * @see #RET 149.110 - */ 149.111 -int status; 149.112 - 149.113 -/** 149.114 - * The line number corresponding to this label, if known. 149.115 - */ 149.116 -int line; 149.117 - 149.118 -/** 149.119 - * The position of this label in the code, if known. 149.120 - */ 149.121 -int position; 149.122 - 149.123 -/** 149.124 - * Number of forward references to this label, times two. 149.125 - */ 149.126 -private int referenceCount; 149.127 - 149.128 -/** 149.129 - * Informations about forward references. Each forward reference is 149.130 - * described by two consecutive integers in this array: the first one is the 149.131 - * position of the first byte of the bytecode instruction that contains the 149.132 - * forward reference, while the second is the position of the first byte of 149.133 - * the forward reference itself. In fact the sign of the first integer 149.134 - * indicates if this reference uses 2 or 4 bytes, and its absolute value 149.135 - * gives the position of the bytecode instruction. 149.136 - */ 149.137 -private int[] srcAndRefPositions; 149.138 - 149.139 -// ------------------------------------------------------------------------ 149.140 - 149.141 -/* 149.142 - * Fields for the control flow and data flow graph analysis algorithms (used 149.143 - * to compute the maximum stack size or the stack map frames). A control 149.144 - * flow graph contains one node per "basic block", and one edge per "jump" 149.145 - * from one basic block to another. Each node (i.e., each basic block) is 149.146 - * represented by the Label object that corresponds to the first instruction 149.147 - * of this basic block. Each node also stores the list of its successors in 149.148 - * the graph, as a linked list of Edge objects. 149.149 - * 149.150 - * The control flow analysis algorithms used to compute the maximum stack 149.151 - * size or the stack map frames are similar and use two steps. The first 149.152 - * step, during the visit of each instruction, builds information about the 149.153 - * state of the local variables and the operand stack at the end of each 149.154 - * basic block, called the "output frame", <i>relatively</i> to the frame 149.155 - * state at the beginning of the basic block, which is called the "input 149.156 - * frame", and which is <i>unknown</i> during this step. The second step, 149.157 - * in {@link MethodWriter#visitMaxs}, is a fix point algorithm that 149.158 - * computes information about the input frame of each basic block, from the 149.159 - * input state of the first basic block (known from the method signature), 149.160 - * and by the using the previously computed relative output frames. 149.161 - * 149.162 - * The algorithm used to compute the maximum stack size only computes the 149.163 - * relative output and absolute input stack heights, while the algorithm 149.164 - * used to compute stack map frames computes relative output frames and 149.165 - * absolute input frames. 149.166 - */ 149.167 - 149.168 -/** 149.169 - * Start of the output stack relatively to the input stack. The exact 149.170 - * semantics of this field depends on the algorithm that is used. 149.171 - * <p/> 149.172 - * When only the maximum stack size is computed, this field is the number of 149.173 - * elements in the input stack. 149.174 - * <p/> 149.175 - * When the stack map frames are completely computed, this field is the 149.176 - * offset of the first output stack element relatively to the top of the 149.177 - * input stack. This offset is always negative or null. A null offset means 149.178 - * that the output stack must be appended to the input stack. A -n offset 149.179 - * means that the first n output stack elements must replace the top n input 149.180 - * stack elements, and that the other elements must be appended to the input 149.181 - * stack. 149.182 - */ 149.183 -int inputStackTop; 149.184 - 149.185 -/** 149.186 - * Maximum height reached by the output stack, relatively to the top of the 149.187 - * input stack. This maximum is always positive or null. 149.188 - */ 149.189 -int outputStackMax; 149.190 - 149.191 -/** 149.192 - * Information about the input and output stack map frames of this basic 149.193 - * block. This field is only used when {@link ClassWriter#COMPUTE_FRAMES} 149.194 - * option is used. 149.195 - */ 149.196 -Frame frame; 149.197 - 149.198 -/** 149.199 - * The successor of this label, in the order they are visited. This linked 149.200 - * list does not include labels used for debug info only. If 149.201 - * {@link ClassWriter#COMPUTE_FRAMES} option is used then, in addition, it 149.202 - * does not contain successive labels that denote the same bytecode position 149.203 - * (in this case only the first label appears in this list). 149.204 - */ 149.205 -Label successor; 149.206 - 149.207 -/** 149.208 - * The successors of this node in the control flow graph. These successors 149.209 - * are stored in a linked list of {@link Edge Edge} objects, linked to each 149.210 - * other by their {@link Edge#next} field. 149.211 - */ 149.212 -Edge successors; 149.213 - 149.214 -/** 149.215 - * The next basic block in the basic block stack. This stack is used in the 149.216 - * main loop of the fix point algorithm used in the second step of the 149.217 - * control flow analysis algorithms. 149.218 - * 149.219 - * @see MethodWriter#visitMaxs 149.220 - */ 149.221 -Label next; 149.222 - 149.223 -// ------------------------------------------------------------------------ 149.224 -// Constructor 149.225 -// ------------------------------------------------------------------------ 149.226 - 149.227 -/** 149.228 - * Constructs a new label. 149.229 - */ 149.230 -public Label(){ 149.231 -} 149.232 - 149.233 -/** 149.234 - * Constructs a new label. 149.235 - * 149.236 - * @param debug if this label is only used for debug attributes. 149.237 - */ 149.238 -Label(final boolean debug){ 149.239 - this.status = debug ? DEBUG : 0; 149.240 -} 149.241 - 149.242 -// ------------------------------------------------------------------------ 149.243 -// Methods to compute offsets and to manage forward references 149.244 -// ------------------------------------------------------------------------ 149.245 - 149.246 -/** 149.247 - * Returns the offset corresponding to this label. This offset is computed 149.248 - * from the start of the method's bytecode. <i>This method is intended for 149.249 - * {@link Attribute} sub classes, and is normally not needed by class 149.250 - * generators or adapters.</i> 149.251 - * 149.252 - * @return the offset corresponding to this label. 149.253 - * @throws IllegalStateException if this label is not resolved yet. 149.254 - */ 149.255 -public int getOffset(){ 149.256 - if((status & RESOLVED) == 0) 149.257 - { 149.258 - throw new IllegalStateException("Label offset position has not been resolved yet"); 149.259 - } 149.260 - return position; 149.261 -} 149.262 - 149.263 -/** 149.264 - * Puts a reference to this label in the bytecode of a method. If the 149.265 - * position of the label is known, the offset is computed and written 149.266 - * directly. Otherwise, a null offset is written and a new forward reference 149.267 - * is declared for this label. 149.268 - * 149.269 - * @param owner the code writer that calls this method. 149.270 - * @param out the bytecode of the method. 149.271 - * @param source the position of first byte of the bytecode instruction that 149.272 - * contains this label. 149.273 - * @param wideOffset <tt>true</tt> if the reference must be stored in 4 149.274 - * bytes, or <tt>false</tt> if it must be stored with 2 bytes. 149.275 - * @throws IllegalArgumentException if this label has not been created by 149.276 - * the given code writer. 149.277 - */ 149.278 -void put( 149.279 - final MethodWriter owner, 149.280 - final ByteVector out, 149.281 - final int source, 149.282 - final boolean wideOffset){ 149.283 - if((status & RESOLVED) != 0) 149.284 - { 149.285 - if(wideOffset) 149.286 - { 149.287 - out.putInt(position - source); 149.288 - } 149.289 - else 149.290 - { 149.291 - out.putShort(position - source); 149.292 - } 149.293 - } 149.294 - else 149.295 - { 149.296 - if(wideOffset) 149.297 - { 149.298 - addReference(-1 - source, out.length); 149.299 - out.putInt(-1); 149.300 - } 149.301 - else 149.302 - { 149.303 - addReference(source, out.length); 149.304 - out.putShort(-1); 149.305 - } 149.306 - } 149.307 -} 149.308 - 149.309 -/** 149.310 - * Adds a forward reference to this label. This method must be called only 149.311 - * for a true forward reference, i.e. only if this label is not resolved 149.312 - * yet. For backward references, the offset of the reference can be, and 149.313 - * must be, computed and stored directly. 149.314 - * 149.315 - * @param sourcePosition the position of the referencing instruction. This 149.316 - * position will be used to compute the offset of this forward 149.317 - * reference. 149.318 - * @param referencePosition the position where the offset for this forward 149.319 - * reference must be stored. 149.320 - */ 149.321 -private void addReference( 149.322 - final int sourcePosition, 149.323 - final int referencePosition){ 149.324 - if(srcAndRefPositions == null) 149.325 - { 149.326 - srcAndRefPositions = new int[6]; 149.327 - } 149.328 - if(referenceCount >= srcAndRefPositions.length) 149.329 - { 149.330 - int[] a = new int[srcAndRefPositions.length + 6]; 149.331 - System.arraycopy(srcAndRefPositions, 149.332 - 0, 149.333 - a, 149.334 - 0, 149.335 - srcAndRefPositions.length); 149.336 - srcAndRefPositions = a; 149.337 - } 149.338 - srcAndRefPositions[referenceCount++] = sourcePosition; 149.339 - srcAndRefPositions[referenceCount++] = referencePosition; 149.340 -} 149.341 - 149.342 -/** 149.343 - * Resolves all forward references to this label. This method must be called 149.344 - * when this label is added to the bytecode of the method, i.e. when its 149.345 - * position becomes known. This method fills in the blanks that where left 149.346 - * in the bytecode by each forward reference previously added to this label. 149.347 - * 149.348 - * @param owner the code writer that calls this method. 149.349 - * @param position the position of this label in the bytecode. 149.350 - * @param data the bytecode of the method. 149.351 - * @return <tt>true</tt> if a blank that was left for this label was to 149.352 - * small to store the offset. In such a case the corresponding jump 149.353 - * instruction is replaced with a pseudo instruction (using unused 149.354 - * opcodes) using an unsigned two bytes offset. These pseudo 149.355 - * instructions will need to be replaced with true instructions with 149.356 - * wider offsets (4 bytes instead of 2). This is done in 149.357 - * {@link MethodWriter#resizeInstructions}. 149.358 - * @throws IllegalArgumentException if this label has already been resolved, 149.359 - * or if it has not been created by the given code writer. 149.360 - */ 149.361 -boolean resolve( 149.362 - final MethodWriter owner, 149.363 - final int position, 149.364 - final byte[] data){ 149.365 - boolean needUpdate = false; 149.366 - this.status |= RESOLVED; 149.367 - this.position = position; 149.368 - int i = 0; 149.369 - while(i < referenceCount) 149.370 - { 149.371 - int source = srcAndRefPositions[i++]; 149.372 - int reference = srcAndRefPositions[i++]; 149.373 - int offset; 149.374 - if(source >= 0) 149.375 - { 149.376 - offset = position - source; 149.377 - if(offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) 149.378 - { 149.379 - /* 149.380 - * changes the opcode of the jump instruction, in order to 149.381 - * be able to find it later (see resizeInstructions in 149.382 - * MethodWriter). These temporary opcodes are similar to 149.383 - * jump instruction opcodes, except that the 2 bytes offset 149.384 - * is unsigned (and can therefore represent values from 0 to 149.385 - * 65535, which is sufficient since the size of a method is 149.386 - * limited to 65535 bytes). 149.387 - */ 149.388 - int opcode = data[reference - 1] & 0xFF; 149.389 - if(opcode <= Opcodes.JSR) 149.390 - { 149.391 - // changes IFEQ ... JSR to opcodes 202 to 217 149.392 - data[reference - 1] = (byte) (opcode + 49); 149.393 - } 149.394 - else 149.395 - { 149.396 - // changes IFNULL and IFNONNULL to opcodes 218 and 219 149.397 - data[reference - 1] = (byte) (opcode + 20); 149.398 - } 149.399 - needUpdate = true; 149.400 - } 149.401 - data[reference++] = (byte) (offset >>> 8); 149.402 - data[reference] = (byte) offset; 149.403 - } 149.404 - else 149.405 - { 149.406 - offset = position + source + 1; 149.407 - data[reference++] = (byte) (offset >>> 24); 149.408 - data[reference++] = (byte) (offset >>> 16); 149.409 - data[reference++] = (byte) (offset >>> 8); 149.410 - data[reference] = (byte) offset; 149.411 - } 149.412 - } 149.413 - return needUpdate; 149.414 -} 149.415 - 149.416 -/** 149.417 - * Returns the first label of the series to which this label belongs. For an 149.418 - * isolated label or for the first label in a series of successive labels, 149.419 - * this method returns the label itself. For other labels it returns the 149.420 - * first label of the series. 149.421 - * 149.422 - * @return the first label of the series to which this label belongs. 149.423 - */ 149.424 -Label getFirst(){ 149.425 - return frame == null ? this : frame.owner; 149.426 -} 149.427 - 149.428 -// ------------------------------------------------------------------------ 149.429 -// Overriden Object methods 149.430 -// ------------------------------------------------------------------------ 149.431 - 149.432 -/** 149.433 - * Returns a string representation of this label. 149.434 - * 149.435 - * @return a string representation of this label. 149.436 - */ 149.437 -public String toString(){ 149.438 - return "L" + System.identityHashCode(this); 149.439 -} 149.440 -}
150.1 --- a/src/clojure/asm/MethodAdapter.java Sat Aug 21 06:25:44 2010 -0400 150.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 150.3 @@ -1,186 +0,0 @@ 150.4 -/*** 150.5 - * ASM: a very small and fast Java bytecode manipulation framework 150.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 150.7 - * All rights reserved. 150.8 - * 150.9 - * Redistribution and use in source and binary forms, with or without 150.10 - * modification, are permitted provided that the following conditions 150.11 - * are met: 150.12 - * 1. Redistributions of source code must retain the above copyright 150.13 - * notice, this list of conditions and the following disclaimer. 150.14 - * 2. Redistributions in binary form must reproduce the above copyright 150.15 - * notice, this list of conditions and the following disclaimer in the 150.16 - * documentation and/or other materials provided with the distribution. 150.17 - * 3. Neither the name of the copyright holders nor the names of its 150.18 - * contributors may be used to endorse or promote products derived from 150.19 - * this software without specific prior written permission. 150.20 - * 150.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 150.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 150.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 150.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 150.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 150.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 150.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 150.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 150.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 150.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 150.31 - * THE POSSIBILITY OF SUCH DAMAGE. 150.32 - */ 150.33 -package clojure.asm; 150.34 - 150.35 -/** 150.36 - * An empty {@link MethodVisitor} that delegates to another 150.37 - * {@link MethodVisitor}. This class can be used as a super class to quickly 150.38 - * implement usefull method adapter classes, just by overriding the necessary 150.39 - * methods. 150.40 - * 150.41 - * @author Eric Bruneton 150.42 - */ 150.43 -public class MethodAdapter implements MethodVisitor{ 150.44 - 150.45 -/** 150.46 - * The {@link MethodVisitor} to which this adapter delegates calls. 150.47 - */ 150.48 -protected MethodVisitor mv; 150.49 - 150.50 -/** 150.51 - * Constructs a new {@link MethodAdapter} object. 150.52 - * 150.53 - * @param mv the code visitor to which this adapter must delegate calls. 150.54 - */ 150.55 -public MethodAdapter(final MethodVisitor mv){ 150.56 - this.mv = mv; 150.57 -} 150.58 - 150.59 -public AnnotationVisitor visitAnnotationDefault(){ 150.60 - return mv.visitAnnotationDefault(); 150.61 -} 150.62 - 150.63 -public AnnotationVisitor visitAnnotation( 150.64 - final String desc, 150.65 - final boolean visible){ 150.66 - return mv.visitAnnotation(desc, visible); 150.67 -} 150.68 - 150.69 -public AnnotationVisitor visitParameterAnnotation( 150.70 - final int parameter, 150.71 - final String desc, 150.72 - final boolean visible){ 150.73 - return mv.visitParameterAnnotation(parameter, desc, visible); 150.74 -} 150.75 - 150.76 -public void visitAttribute(final Attribute attr){ 150.77 - mv.visitAttribute(attr); 150.78 -} 150.79 - 150.80 -public void visitCode(){ 150.81 - mv.visitCode(); 150.82 -} 150.83 - 150.84 -public void visitFrame( 150.85 - final int type, 150.86 - final int nLocal, 150.87 - final Object[] local, 150.88 - final int nStack, 150.89 - final Object[] stack){ 150.90 - mv.visitFrame(type, nLocal, local, nStack, stack); 150.91 -} 150.92 - 150.93 -public void visitInsn(final int opcode){ 150.94 - mv.visitInsn(opcode); 150.95 -} 150.96 - 150.97 -public void visitIntInsn(final int opcode, final int operand){ 150.98 - mv.visitIntInsn(opcode, operand); 150.99 -} 150.100 - 150.101 -public void visitVarInsn(final int opcode, final int var){ 150.102 - mv.visitVarInsn(opcode, var); 150.103 -} 150.104 - 150.105 -public void visitTypeInsn(final int opcode, final String desc){ 150.106 - mv.visitTypeInsn(opcode, desc); 150.107 -} 150.108 - 150.109 -public void visitFieldInsn( 150.110 - final int opcode, 150.111 - final String owner, 150.112 - final String name, 150.113 - final String desc){ 150.114 - mv.visitFieldInsn(opcode, owner, name, desc); 150.115 -} 150.116 - 150.117 -public void visitMethodInsn( 150.118 - final int opcode, 150.119 - final String owner, 150.120 - final String name, 150.121 - final String desc){ 150.122 - mv.visitMethodInsn(opcode, owner, name, desc); 150.123 -} 150.124 - 150.125 -public void visitJumpInsn(final int opcode, final Label label){ 150.126 - mv.visitJumpInsn(opcode, label); 150.127 -} 150.128 - 150.129 -public void visitLabel(final Label label){ 150.130 - mv.visitLabel(label); 150.131 -} 150.132 - 150.133 -public void visitLdcInsn(final Object cst){ 150.134 - mv.visitLdcInsn(cst); 150.135 -} 150.136 - 150.137 -public void visitIincInsn(final int var, final int increment){ 150.138 - mv.visitIincInsn(var, increment); 150.139 -} 150.140 - 150.141 -public void visitTableSwitchInsn( 150.142 - final int min, 150.143 - final int max, 150.144 - final Label dflt, 150.145 - final Label labels[]){ 150.146 - mv.visitTableSwitchInsn(min, max, dflt, labels); 150.147 -} 150.148 - 150.149 -public void visitLookupSwitchInsn( 150.150 - final Label dflt, 150.151 - final int keys[], 150.152 - final Label labels[]){ 150.153 - mv.visitLookupSwitchInsn(dflt, keys, labels); 150.154 -} 150.155 - 150.156 -public void visitMultiANewArrayInsn(final String desc, final int dims){ 150.157 - mv.visitMultiANewArrayInsn(desc, dims); 150.158 -} 150.159 - 150.160 -public void visitTryCatchBlock( 150.161 - final Label start, 150.162 - final Label end, 150.163 - final Label handler, 150.164 - final String type){ 150.165 - mv.visitTryCatchBlock(start, end, handler, type); 150.166 -} 150.167 - 150.168 -public void visitLocalVariable( 150.169 - final String name, 150.170 - final String desc, 150.171 - final String signature, 150.172 - final Label start, 150.173 - final Label end, 150.174 - final int index){ 150.175 - mv.visitLocalVariable(name, desc, signature, start, end, index); 150.176 -} 150.177 - 150.178 -public void visitLineNumber(final int line, final Label start){ 150.179 - mv.visitLineNumber(line, start); 150.180 -} 150.181 - 150.182 -public void visitMaxs(final int maxStack, final int maxLocals){ 150.183 - mv.visitMaxs(maxStack, maxLocals); 150.184 -} 150.185 - 150.186 -public void visitEnd(){ 150.187 - mv.visitEnd(); 150.188 -} 150.189 -}
151.1 --- a/src/clojure/asm/MethodVisitor.java Sat Aug 21 06:25:44 2010 -0400 151.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 151.3 @@ -1,396 +0,0 @@ 151.4 -/*** 151.5 - * ASM: a very small and fast Java bytecode manipulation framework 151.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 151.7 - * All rights reserved. 151.8 - * 151.9 - * Redistribution and use in source and binary forms, with or without 151.10 - * modification, are permitted provided that the following conditions 151.11 - * are met: 151.12 - * 1. Redistributions of source code must retain the above copyright 151.13 - * notice, this list of conditions and the following disclaimer. 151.14 - * 2. Redistributions in binary form must reproduce the above copyright 151.15 - * notice, this list of conditions and the following disclaimer in the 151.16 - * documentation and/or other materials provided with the distribution. 151.17 - * 3. Neither the name of the copyright holders nor the names of its 151.18 - * contributors may be used to endorse or promote products derived from 151.19 - * this software without specific prior written permission. 151.20 - * 151.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 151.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 151.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 151.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 151.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 151.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 151.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 151.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 151.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 151.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 151.31 - * THE POSSIBILITY OF SUCH DAMAGE. 151.32 - */ 151.33 -package clojure.asm; 151.34 - 151.35 -/** 151.36 - * A visitor to visit a Java method. The methods of this interface must be 151.37 - * called in the following order: [ <tt>visitAnnotationDefault</tt> ] ( 151.38 - * <tt>visitAnnotation</tt> | <tt>visitParameterAnnotation</tt> | 151.39 - * <tt>visitAttribute</tt> )* [ <tt>visitCode</tt> ( <tt>visitFrame</tt> | 151.40 - * <tt>visit</tt><i>X</i>Insn</tt> | <tt>visitLabel</tt> | <tt>visitTryCatchBlock</tt> | 151.41 - * <tt>visitLocalVariable</tt> | <tt>visitLineNumber</tt>)* <tt>visitMaxs</tt> ] 151.42 - * <tt>visitEnd</tt>. In addition, the <tt>visit</tt><i>X</i>Insn</tt> 151.43 - * and <tt>visitLabel</tt> methods must be called in the sequential order of 151.44 - * the bytecode instructions of the visited code, <tt>visitTryCatchBlock</tt> 151.45 - * must be called <i>before</i> the labels passed as arguments have been 151.46 - * visited, and the <tt>visitLocalVariable</tt> and <tt>visitLineNumber</tt> 151.47 - * methods must be called <i>after</i> the labels passed as arguments have been 151.48 - * visited. 151.49 - * 151.50 - * @author Eric Bruneton 151.51 - */ 151.52 -public interface MethodVisitor{ 151.53 - 151.54 -// ------------------------------------------------------------------------- 151.55 -// Annotations and non standard attributes 151.56 -// ------------------------------------------------------------------------- 151.57 - 151.58 -/** 151.59 - * Visits the default value of this annotation interface method. 151.60 - * 151.61 - * @return a visitor to the visit the actual default value of this 151.62 - * annotation interface method, or <tt>null</tt> if this visitor 151.63 - * is not interested in visiting this default value. The 'name' 151.64 - * parameters passed to the methods of this annotation visitor are 151.65 - * ignored. Moreover, exacly one visit method must be called on this 151.66 - * annotation visitor, followed by visitEnd. 151.67 - */ 151.68 -AnnotationVisitor visitAnnotationDefault(); 151.69 - 151.70 -/** 151.71 - * Visits an annotation of this method. 151.72 - * 151.73 - * @param desc the class descriptor of the annotation class. 151.74 - * @param visible <tt>true</tt> if the annotation is visible at runtime. 151.75 - * @return a visitor to visit the annotation values, or <tt>null</tt> if 151.76 - * this visitor is not interested in visiting this annotation. 151.77 - */ 151.78 -AnnotationVisitor visitAnnotation(String desc, boolean visible); 151.79 - 151.80 -/** 151.81 - * Visits an annotation of a parameter this method. 151.82 - * 151.83 - * @param parameter the parameter index. 151.84 - * @param desc the class descriptor of the annotation class. 151.85 - * @param visible <tt>true</tt> if the annotation is visible at runtime. 151.86 - * @return a visitor to visit the annotation values, or <tt>null</tt> if 151.87 - * this visitor is not interested in visiting this annotation. 151.88 - */ 151.89 -AnnotationVisitor visitParameterAnnotation( 151.90 - int parameter, 151.91 - String desc, 151.92 - boolean visible); 151.93 - 151.94 -/** 151.95 - * Visits a non standard attribute of this method. 151.96 - * 151.97 - * @param attr an attribute. 151.98 - */ 151.99 -void visitAttribute(Attribute attr); 151.100 - 151.101 -/** 151.102 - * Starts the visit of the method's code, if any (i.e. non abstract method). 151.103 - */ 151.104 -void visitCode(); 151.105 - 151.106 -/** 151.107 - * Visits the current state of the local variables and operand stack 151.108 - * elements. This method must(*) be called <i>just before</i> any 151.109 - * instruction <b>i</b> that follows an unconditionnal branch instruction 151.110 - * such as GOTO or THROW, that is the target of a jump instruction, or that 151.111 - * starts an exception handler block. The visited types must describe the 151.112 - * values of the local variables and of the operand stack elements <i>just 151.113 - * before</i> <b>i</b> is executed. <br> <br> (*) this is mandatory only 151.114 - * for classes whose version is greater than or equal to 151.115 - * {@link Opcodes#V1_6 V1_6}. <br> <br> Packed frames are basically 151.116 - * "deltas" from the state of the previous frame (very first frame is 151.117 - * implicitly defined by the method's parameters and access flags): <ul> 151.118 - * <li>{@link Opcodes#F_SAME} representing frame with exactly the same 151.119 - * locals as the previous frame and with the empty stack.</li> <li>{@link Opcodes#F_SAME1} 151.120 - * representing frame with exactly the same locals as the previous frame and 151.121 - * with single value on the stack (<code>nStack</code> is 1 and 151.122 - * <code>stack[0]</code> contains value for the type of the stack item).</li> 151.123 - * <li>{@link Opcodes#F_APPEND} representing frame with current locals are 151.124 - * the same as the locals in the previous frame, except that additional 151.125 - * locals are defined (<code>nLocal</code> is 1, 2 or 3 and 151.126 - * <code>local</code> elements contains values representing added types).</li> 151.127 - * <li>{@link Opcodes#F_CHOP} representing frame with current locals are 151.128 - * the same as the locals in the previous frame, except that the last 1-3 151.129 - * locals are absent and with the empty stack (<code>nLocals</code> is 1, 151.130 - * 2 or 3). </li> <li>{@link Opcodes#F_FULL} representing complete frame 151.131 - * data.</li> </li> </ul> 151.132 - * 151.133 - * @param type the type of this stack map frame. Must be 151.134 - * {@link Opcodes#F_NEW} for expanded frames, or 151.135 - * {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND}, 151.136 - * {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or 151.137 - * {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed 151.138 - * frames. 151.139 - * @param nLocal the number of local variables in the visited frame. 151.140 - * @param local the local variable types in this frame. This array must not 151.141 - * be modified. Primitive types are represented by 151.142 - * {@link Opcodes#TOP}, {@link Opcodes#INTEGER}, 151.143 - * {@link Opcodes#FLOAT}, {@link Opcodes#LONG}, 151.144 - * {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or 151.145 - * {@link Opcodes#UNINITIALIZED_THIS} (long and double are 151.146 - * represented by a single element). Reference types are represented 151.147 - * by String objects (representing internal names, or type 151.148 - * descriptors for array types), and uninitialized types by Label 151.149 - * objects (this label designates the NEW instruction that created 151.150 - * this uninitialized value). 151.151 - * @param nStack the number of operand stack elements in the visited frame. 151.152 - * @param stack the operand stack types in this frame. This array must not 151.153 - * be modified. Its content has the same format as the "local" array. 151.154 - */ 151.155 -void visitFrame( 151.156 - int type, 151.157 - int nLocal, 151.158 - Object[] local, 151.159 - int nStack, 151.160 - Object[] stack); 151.161 - 151.162 -// ------------------------------------------------------------------------- 151.163 -// Normal instructions 151.164 -// ------------------------------------------------------------------------- 151.165 - 151.166 -/** 151.167 - * Visits a zero operand instruction. 151.168 - * 151.169 - * @param opcode the opcode of the instruction to be visited. This opcode is 151.170 - * either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2, 151.171 - * ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, 151.172 - * FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD, 151.173 - * DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE, 151.174 - * DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP, 151.175 - * DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD, 151.176 - * DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, 151.177 - * FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, 151.178 - * LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, 151.179 - * I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, 151.180 - * I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, 151.181 - * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, 151.182 - * MONITORENTER, or MONITOREXIT. 151.183 - */ 151.184 -void visitInsn(int opcode); 151.185 - 151.186 -/** 151.187 - * Visits an instruction with a single int operand. 151.188 - * 151.189 - * @param opcode the opcode of the instruction to be visited. This opcode is 151.190 - * either BIPUSH, SIPUSH or NEWARRAY. 151.191 - * @param operand the operand of the instruction to be visited.<br> When 151.192 - * opcode is BIPUSH, operand value should be between Byte.MIN_VALUE 151.193 - * and Byte.MAX_VALUE.<br> When opcode is SIPUSH, operand value 151.194 - * should be between Short.MIN_VALUE and Short.MAX_VALUE.<br> When 151.195 - * opcode is NEWARRAY, operand value should be one of 151.196 - * {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR}, 151.197 - * {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE}, 151.198 - * {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT}, 151.199 - * {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}. 151.200 - */ 151.201 -void visitIntInsn(int opcode, int operand); 151.202 - 151.203 -/** 151.204 - * Visits a local variable instruction. A local variable instruction is an 151.205 - * instruction that loads or stores the value of a local variable. 151.206 - * 151.207 - * @param opcode the opcode of the local variable instruction to be visited. 151.208 - * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, 151.209 - * LSTORE, FSTORE, DSTORE, ASTORE or RET. 151.210 - * @param var the operand of the instruction to be visited. This operand is 151.211 - * the index of a local variable. 151.212 - */ 151.213 -void visitVarInsn(int opcode, int var); 151.214 - 151.215 -/** 151.216 - * Visits a type instruction. A type instruction is an instruction that 151.217 - * takes a type descriptor as parameter. 151.218 - * 151.219 - * @param opcode the opcode of the type instruction to be visited. This 151.220 - * opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF. 151.221 - * @param desc the operand of the instruction to be visited. This operand is 151.222 - * must be a fully qualified class name in internal form, or the type 151.223 - * descriptor of an array type (see {@link Type Type}). 151.224 - */ 151.225 -void visitTypeInsn(int opcode, String desc); 151.226 - 151.227 -/** 151.228 - * Visits a field instruction. A field instruction is an instruction that 151.229 - * loads or stores the value of a field of an object. 151.230 - * 151.231 - * @param opcode the opcode of the type instruction to be visited. This 151.232 - * opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD. 151.233 - * @param owner the internal name of the field's owner class (see {@link 151.234 - * Type#getInternalName() getInternalName}). 151.235 - * @param name the field's name. 151.236 - * @param desc the field's descriptor (see {@link Type Type}). 151.237 - */ 151.238 -void visitFieldInsn(int opcode, String owner, String name, String desc); 151.239 - 151.240 -/** 151.241 - * Visits a method instruction. A method instruction is an instruction that 151.242 - * invokes a method. 151.243 - * 151.244 - * @param opcode the opcode of the type instruction to be visited. This 151.245 - * opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or 151.246 - * INVOKEINTERFACE. 151.247 - * @param owner the internal name of the method's owner class (see {@link 151.248 - * Type#getInternalName() getInternalName}). 151.249 - * @param name the method's name. 151.250 - * @param desc the method's descriptor (see {@link Type Type}). 151.251 - */ 151.252 -void visitMethodInsn(int opcode, String owner, String name, String desc); 151.253 - 151.254 -/** 151.255 - * Visits a jump instruction. A jump instruction is an instruction that may 151.256 - * jump to another instruction. 151.257 - * 151.258 - * @param opcode the opcode of the type instruction to be visited. This 151.259 - * opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, 151.260 - * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, 151.261 - * IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL. 151.262 - * @param label the operand of the instruction to be visited. This operand 151.263 - * is a label that designates the instruction to which the jump 151.264 - * instruction may jump. 151.265 - */ 151.266 -void visitJumpInsn(int opcode, Label label); 151.267 - 151.268 -/** 151.269 - * Visits a label. A label designates the instruction that will be visited 151.270 - * just after it. 151.271 - * 151.272 - * @param label a {@link Label Label} object. 151.273 - */ 151.274 -void visitLabel(Label label); 151.275 - 151.276 -// ------------------------------------------------------------------------- 151.277 -// Special instructions 151.278 -// ------------------------------------------------------------------------- 151.279 - 151.280 -/** 151.281 - * Visits a LDC instruction. 151.282 - * 151.283 - * @param cst the constant to be loaded on the stack. This parameter must be 151.284 - * a non null {@link Integer}, a {@link Float}, a {@link Long}, a 151.285 - * {@link Double} a {@link String} (or a {@link Type} for 151.286 - * <tt>.class</tt> constants, for classes whose version is 49.0 or 151.287 - * more). 151.288 - */ 151.289 -void visitLdcInsn(Object cst); 151.290 - 151.291 -/** 151.292 - * Visits an IINC instruction. 151.293 - * 151.294 - * @param var index of the local variable to be incremented. 151.295 - * @param increment amount to increment the local variable by. 151.296 - */ 151.297 -void visitIincInsn(int var, int increment); 151.298 - 151.299 -/** 151.300 - * Visits a TABLESWITCH instruction. 151.301 - * 151.302 - * @param min the minimum key value. 151.303 - * @param max the maximum key value. 151.304 - * @param dflt beginning of the default handler block. 151.305 - * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is 151.306 - * the beginning of the handler block for the <tt>min + i</tt> key. 151.307 - */ 151.308 -void visitTableSwitchInsn(int min, int max, Label dflt, Label labels[]); 151.309 - 151.310 -/** 151.311 - * Visits a LOOKUPSWITCH instruction. 151.312 - * 151.313 - * @param dflt beginning of the default handler block. 151.314 - * @param keys the values of the keys. 151.315 - * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is 151.316 - * the beginning of the handler block for the <tt>keys[i]</tt> key. 151.317 - */ 151.318 -void visitLookupSwitchInsn(Label dflt, int keys[], Label labels[]); 151.319 - 151.320 -/** 151.321 - * Visits a MULTIANEWARRAY instruction. 151.322 - * 151.323 - * @param desc an array type descriptor (see {@link Type Type}). 151.324 - * @param dims number of dimensions of the array to allocate. 151.325 - */ 151.326 -void visitMultiANewArrayInsn(String desc, int dims); 151.327 - 151.328 -// ------------------------------------------------------------------------- 151.329 -// Exceptions table entries, debug information, max stack and max locals 151.330 -// ------------------------------------------------------------------------- 151.331 - 151.332 -/** 151.333 - * Visits a try catch block. 151.334 - * 151.335 - * @param start beginning of the exception handler's scope (inclusive). 151.336 - * @param end end of the exception handler's scope (exclusive). 151.337 - * @param handler beginning of the exception handler's code. 151.338 - * @param type internal name of the type of exceptions handled by the 151.339 - * handler, or <tt>null</tt> to catch any exceptions (for "finally" 151.340 - * blocks). 151.341 - * @throws IllegalArgumentException if one of the labels has already been 151.342 - * visited by this visitor (by the {@link #visitLabel visitLabel} 151.343 - * method). 151.344 - */ 151.345 -void visitTryCatchBlock(Label start, Label end, Label handler, String type); 151.346 - 151.347 -/** 151.348 - * Visits a local variable declaration. 151.349 - * 151.350 - * @param name the name of a local variable. 151.351 - * @param desc the type descriptor of this local variable. 151.352 - * @param signature the type signature of this local variable. May be 151.353 - * <tt>null</tt> if the local variable type does not use generic 151.354 - * types. 151.355 - * @param start the first instruction corresponding to the scope of this 151.356 - * local variable (inclusive). 151.357 - * @param end the last instruction corresponding to the scope of this local 151.358 - * variable (exclusive). 151.359 - * @param index the local variable's index. 151.360 - * @throws IllegalArgumentException if one of the labels has not already 151.361 - * been visited by this visitor (by the 151.362 - * {@link #visitLabel visitLabel} method). 151.363 - */ 151.364 -void visitLocalVariable( 151.365 - String name, 151.366 - String desc, 151.367 - String signature, 151.368 - Label start, 151.369 - Label end, 151.370 - int index); 151.371 - 151.372 -/** 151.373 - * Visits a line number declaration. 151.374 - * 151.375 - * @param line a line number. This number refers to the source file from 151.376 - * which the class was compiled. 151.377 - * @param start the first instruction corresponding to this line number. 151.378 - * @throws IllegalArgumentException if <tt>start</tt> has not already been 151.379 - * visited by this visitor (by the {@link #visitLabel visitLabel} 151.380 - * method). 151.381 - */ 151.382 -void visitLineNumber(int line, Label start); 151.383 - 151.384 -/** 151.385 - * Visits the maximum stack size and the maximum number of local variables 151.386 - * of the method. 151.387 - * 151.388 - * @param maxStack maximum stack size of the method. 151.389 - * @param maxLocals maximum number of local variables for the method. 151.390 - */ 151.391 -void visitMaxs(int maxStack, int maxLocals); 151.392 - 151.393 -/** 151.394 - * Visits the end of the method. This method, which is the last one to be 151.395 - * called, is used to inform the visitor that all the annotations and 151.396 - * attributes of the method have been visited. 151.397 - */ 151.398 -void visitEnd(); 151.399 -}
152.1 --- a/src/clojure/asm/MethodWriter.java Sat Aug 21 06:25:44 2010 -0400 152.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 152.3 @@ -1,3029 +0,0 @@ 152.4 -/*** 152.5 - * ASM: a very small and fast Java bytecode manipulation framework 152.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 152.7 - * All rights reserved. 152.8 - * 152.9 - * Redistribution and use in source and binary forms, with or without 152.10 - * modification, are permitted provided that the following conditions 152.11 - * are met: 152.12 - * 1. Redistributions of source code must retain the above copyright 152.13 - * notice, this list of conditions and the following disclaimer. 152.14 - * 2. Redistributions in binary form must reproduce the above copyright 152.15 - * notice, this list of conditions and the following disclaimer in the 152.16 - * documentation and/or other materials provided with the distribution. 152.17 - * 3. Neither the name of the copyright holders nor the names of its 152.18 - * contributors may be used to endorse or promote products derived from 152.19 - * this software without specific prior written permission. 152.20 - * 152.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 152.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 152.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 152.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 152.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 152.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 152.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 152.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 152.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 152.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 152.31 - * THE POSSIBILITY OF SUCH DAMAGE. 152.32 - */ 152.33 -package clojure.asm; 152.34 - 152.35 -/** 152.36 - * A {@link MethodVisitor} that generates methods in bytecode form. Each visit 152.37 - * method of this class appends the bytecode corresponding to the visited 152.38 - * instruction to a byte vector, in the order these methods are called. 152.39 - * 152.40 - * @author Eric Bruneton 152.41 - * @author Eugene Kuleshov 152.42 - */ 152.43 -class MethodWriter implements MethodVisitor{ 152.44 - 152.45 -/** 152.46 - * Pseudo access flag used to denote constructors. 152.47 - */ 152.48 -final static int ACC_CONSTRUCTOR = 262144; 152.49 - 152.50 -/** 152.51 - * Frame has exactly the same locals as the previous stack map frame and 152.52 - * number of stack items is zero. 152.53 - */ 152.54 -final static int SAME_FRAME = 0; // to 63 (0-3f) 152.55 - 152.56 -/** 152.57 - * Frame has exactly the same locals as the previous stack map frame and 152.58 - * number of stack items is 1 152.59 - */ 152.60 -final static int SAME_LOCALS_1_STACK_ITEM_FRAME = 64; // to 127 (40-7f) 152.61 - 152.62 -/** 152.63 - * Reserved for future use 152.64 - */ 152.65 -final static int RESERVED = 128; 152.66 - 152.67 -/** 152.68 - * Frame has exactly the same locals as the previous stack map frame and 152.69 - * number of stack items is 1. Offset is bigger then 63; 152.70 - */ 152.71 -final static int SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED = 247; // f7 152.72 - 152.73 -/** 152.74 - * Frame where current locals are the same as the locals in the previous 152.75 - * frame, except that the k last locals are absent. The value of k is given 152.76 - * by the formula 251-frame_type. 152.77 - */ 152.78 -final static int CHOP_FRAME = 248; // to 250 (f8-fA) 152.79 - 152.80 -/** 152.81 - * Frame has exactly the same locals as the previous stack map frame and 152.82 - * number of stack items is zero. Offset is bigger then 63; 152.83 - */ 152.84 -final static int SAME_FRAME_EXTENDED = 251; // fb 152.85 - 152.86 -/** 152.87 - * Frame where current locals are the same as the locals in the previous 152.88 - * frame, except that k additional locals are defined. The value of k is 152.89 - * given by the formula frame_type-251. 152.90 - */ 152.91 -final static int APPEND_FRAME = 252; // to 254 // fc-fe 152.92 - 152.93 -/** 152.94 - * Full frame 152.95 - */ 152.96 -final static int FULL_FRAME = 255; // ff 152.97 - 152.98 -/** 152.99 - * Indicates that the stack map frames must be recomputed from scratch. In 152.100 - * this case the maximum stack size and number of local variables is also 152.101 - * recomputed from scratch. 152.102 - * 152.103 - * @see #compute 152.104 - */ 152.105 -private final static int FRAMES = 0; 152.106 - 152.107 -/** 152.108 - * Indicates that the maximum stack size and number of local variables must 152.109 - * be automatically computed. 152.110 - * 152.111 - * @see #compute 152.112 - */ 152.113 -private final static int MAXS = 1; 152.114 - 152.115 -/** 152.116 - * Indicates that nothing must be automatically computed. 152.117 - * 152.118 - * @see #compute 152.119 - */ 152.120 -private final static int NOTHING = 2; 152.121 - 152.122 -/** 152.123 - * Next method writer (see {@link ClassWriter#firstMethod firstMethod}). 152.124 - */ 152.125 -MethodWriter next; 152.126 - 152.127 -/** 152.128 - * The class writer to which this method must be added. 152.129 - */ 152.130 -ClassWriter cw; 152.131 - 152.132 -/** 152.133 - * Access flags of this method. 152.134 - */ 152.135 -private int access; 152.136 - 152.137 -/** 152.138 - * The index of the constant pool item that contains the name of this 152.139 - * method. 152.140 - */ 152.141 -private int name; 152.142 - 152.143 -/** 152.144 - * The index of the constant pool item that contains the descriptor of this 152.145 - * method. 152.146 - */ 152.147 -private int desc; 152.148 - 152.149 -/** 152.150 - * The descriptor of this method. 152.151 - */ 152.152 -private String descriptor; 152.153 - 152.154 -/** 152.155 - * The signature of this method. 152.156 - */ 152.157 -String signature; 152.158 - 152.159 -/** 152.160 - * If not zero, indicates that the code of this method must be copied from 152.161 - * the ClassReader associated to this writer in <code>cw.cr</code>. More 152.162 - * precisely, this field gives the index of the first byte to copied from 152.163 - * <code>cw.cr.b</code>. 152.164 - */ 152.165 -int classReaderOffset; 152.166 - 152.167 -/** 152.168 - * If not zero, indicates that the code of this method must be copied from 152.169 - * the ClassReader associated to this writer in <code>cw.cr</code>. More 152.170 - * precisely, this field gives the number of bytes to copied from 152.171 - * <code>cw.cr.b</code>. 152.172 - */ 152.173 -int classReaderLength; 152.174 - 152.175 -/** 152.176 - * Number of exceptions that can be thrown by this method. 152.177 - */ 152.178 -int exceptionCount; 152.179 - 152.180 -/** 152.181 - * The exceptions that can be thrown by this method. More precisely, this 152.182 - * array contains the indexes of the constant pool items that contain the 152.183 - * internal names of these exception classes. 152.184 - */ 152.185 -int[] exceptions; 152.186 - 152.187 -/** 152.188 - * The annotation default attribute of this method. May be <tt>null</tt>. 152.189 - */ 152.190 -private ByteVector annd; 152.191 - 152.192 -/** 152.193 - * The runtime visible annotations of this method. May be <tt>null</tt>. 152.194 - */ 152.195 -private AnnotationWriter anns; 152.196 - 152.197 -/** 152.198 - * The runtime invisible annotations of this method. May be <tt>null</tt>. 152.199 - */ 152.200 -private AnnotationWriter ianns; 152.201 - 152.202 -/** 152.203 - * The runtime visible parameter annotations of this method. May be 152.204 - * <tt>null</tt>. 152.205 - */ 152.206 -private AnnotationWriter[] panns; 152.207 - 152.208 -/** 152.209 - * The runtime invisible parameter annotations of this method. May be 152.210 - * <tt>null</tt>. 152.211 - */ 152.212 -private AnnotationWriter[] ipanns; 152.213 - 152.214 -/** 152.215 - * The non standard attributes of the method. 152.216 - */ 152.217 -private Attribute attrs; 152.218 - 152.219 -/** 152.220 - * The bytecode of this method. 152.221 - */ 152.222 -private ByteVector code = new ByteVector(); 152.223 - 152.224 -/** 152.225 - * Maximum stack size of this method. 152.226 - */ 152.227 -private int maxStack; 152.228 - 152.229 -/** 152.230 - * Maximum number of local variables for this method. 152.231 - */ 152.232 -private int maxLocals; 152.233 - 152.234 -/** 152.235 - * Number of stack map frames in the StackMapTable attribute. 152.236 - */ 152.237 -private int frameCount; 152.238 - 152.239 -/** 152.240 - * The StackMapTable attribute. 152.241 - */ 152.242 -private ByteVector stackMap; 152.243 - 152.244 -/** 152.245 - * The offset of the last frame that was written in the StackMapTable 152.246 - * attribute. 152.247 - */ 152.248 -private int previousFrameOffset; 152.249 - 152.250 -/** 152.251 - * The last frame that was written in the StackMapTable attribute. 152.252 - * 152.253 - * @see #frame 152.254 - */ 152.255 -private int[] previousFrame; 152.256 - 152.257 -/** 152.258 - * Index of the next element to be added in {@link #frame}. 152.259 - */ 152.260 -private int frameIndex; 152.261 - 152.262 -/** 152.263 - * The current stack map frame. The first element contains the offset of the 152.264 - * instruction to which the frame corresponds, the second element is the 152.265 - * number of locals and the third one is the number of stack elements. The 152.266 - * local variables start at index 3 and are followed by the operand stack 152.267 - * values. In summary frame[0] = offset, frame[1] = nLocal, frame[2] = 152.268 - * nStack, frame[3] = nLocal. All types are encoded as integers, with the 152.269 - * same format as the one used in {@link Label}, but limited to BASE types. 152.270 - */ 152.271 -private int[] frame; 152.272 - 152.273 -/** 152.274 - * Number of elements in the exception handler list. 152.275 - */ 152.276 -private int handlerCount; 152.277 - 152.278 -/** 152.279 - * The first element in the exception handler list. 152.280 - */ 152.281 -private Handler firstHandler; 152.282 - 152.283 -/** 152.284 - * The last element in the exception handler list. 152.285 - */ 152.286 -private Handler lastHandler; 152.287 - 152.288 -/** 152.289 - * Number of entries in the LocalVariableTable attribute. 152.290 - */ 152.291 -private int localVarCount; 152.292 - 152.293 -/** 152.294 - * The LocalVariableTable attribute. 152.295 - */ 152.296 -private ByteVector localVar; 152.297 - 152.298 -/** 152.299 - * Number of entries in the LocalVariableTypeTable attribute. 152.300 - */ 152.301 -private int localVarTypeCount; 152.302 - 152.303 -/** 152.304 - * The LocalVariableTypeTable attribute. 152.305 - */ 152.306 -private ByteVector localVarType; 152.307 - 152.308 -/** 152.309 - * Number of entries in the LineNumberTable attribute. 152.310 - */ 152.311 -private int lineNumberCount; 152.312 - 152.313 -/** 152.314 - * The LineNumberTable attribute. 152.315 - */ 152.316 -private ByteVector lineNumber; 152.317 - 152.318 -/** 152.319 - * The non standard attributes of the method's code. 152.320 - */ 152.321 -private Attribute cattrs; 152.322 - 152.323 -/** 152.324 - * Indicates if some jump instructions are too small and need to be resized. 152.325 - */ 152.326 -private boolean resize; 152.327 - 152.328 -/** 152.329 - * Indicates if the instructions contain at least one JSR instruction. 152.330 - */ 152.331 -private boolean jsr; 152.332 - 152.333 -// ------------------------------------------------------------------------ 152.334 - 152.335 -/* 152.336 - * Fields for the control flow graph analysis algorithm (used to compute the 152.337 - * maximum stack size). A control flow graph contains one node per "basic 152.338 - * block", and one edge per "jump" from one basic block to another. Each 152.339 - * node (i.e., each basic block) is represented by the Label object that 152.340 - * corresponds to the first instruction of this basic block. Each node also 152.341 - * stores the list of its successors in the graph, as a linked list of Edge 152.342 - * objects. 152.343 - */ 152.344 - 152.345 -/** 152.346 - * Indicates what must be automatically computed. 152.347 - * 152.348 - * @see FRAMES 152.349 - * @see MAXS 152.350 - * @see NOTHING 152.351 - */ 152.352 -private int compute; 152.353 - 152.354 -/** 152.355 - * A list of labels. This list is the list of basic blocks in the method, 152.356 - * i.e. a list of Label objects linked to each other by their 152.357 - * {@link Label#successor} field, in the order they are visited by 152.358 - * {@link visitLabel}, and starting with the first basic block. 152.359 - */ 152.360 -private Label labels; 152.361 - 152.362 -/** 152.363 - * The previous basic block. 152.364 - */ 152.365 -private Label previousBlock; 152.366 - 152.367 -/** 152.368 - * The current basic block. 152.369 - */ 152.370 -private Label currentBlock; 152.371 - 152.372 -/** 152.373 - * The (relative) stack size after the last visited instruction. This size 152.374 - * is relative to the beginning of the current basic block, i.e., the true 152.375 - * stack size after the last visited instruction is equal to the 152.376 - * {@link Label#inputStackTop beginStackSize} of the current basic block 152.377 - * plus <tt>stackSize</tt>. 152.378 - */ 152.379 -private int stackSize; 152.380 - 152.381 -/** 152.382 - * The (relative) maximum stack size after the last visited instruction. 152.383 - * This size is relative to the beginning of the current basic block, i.e., 152.384 - * the true maximum stack size after the last visited instruction is equal 152.385 - * to the {@link Label#inputStackTop beginStackSize} of the current basic 152.386 - * block plus <tt>stackSize</tt>. 152.387 - */ 152.388 -private int maxStackSize; 152.389 - 152.390 -// ------------------------------------------------------------------------ 152.391 -// Constructor 152.392 -// ------------------------------------------------------------------------ 152.393 - 152.394 -/** 152.395 - * Constructs a new {@link MethodWriter}. 152.396 - * 152.397 - * @param cw the class writer in which the method must be added. 152.398 - * @param access the method's access flags (see {@link Opcodes}). 152.399 - * @param name the method's name. 152.400 - * @param desc the method's descriptor (see {@link Type}). 152.401 - * @param signature the method's signature. May be <tt>null</tt>. 152.402 - * @param exceptions the internal names of the method's exceptions. May be 152.403 - * <tt>null</tt>. 152.404 - * @param computeMaxs <tt>true</tt> if the maximum stack size and number 152.405 - * of local variables must be automatically computed. 152.406 - * @param computeFrames <tt>true</tt> if the stack map tables must be 152.407 - * recomputed from scratch. 152.408 - */ 152.409 -MethodWriter( 152.410 - final ClassWriter cw, 152.411 - final int access, 152.412 - final String name, 152.413 - final String desc, 152.414 - final String signature, 152.415 - final String[] exceptions, 152.416 - final boolean computeMaxs, 152.417 - final boolean computeFrames){ 152.418 - if(cw.firstMethod == null) 152.419 - { 152.420 - cw.firstMethod = this; 152.421 - } 152.422 - else 152.423 - { 152.424 - cw.lastMethod.next = this; 152.425 - } 152.426 - cw.lastMethod = this; 152.427 - this.cw = cw; 152.428 - this.access = access; 152.429 - this.name = cw.newUTF8(name); 152.430 - this.desc = cw.newUTF8(desc); 152.431 - this.descriptor = desc; 152.432 - this.signature = signature; 152.433 - if(exceptions != null && exceptions.length > 0) 152.434 - { 152.435 - exceptionCount = exceptions.length; 152.436 - this.exceptions = new int[exceptionCount]; 152.437 - for(int i = 0; i < exceptionCount; ++i) 152.438 - { 152.439 - this.exceptions[i] = cw.newClass(exceptions[i]); 152.440 - } 152.441 - } 152.442 - this.compute = computeFrames ? FRAMES : (computeMaxs ? MAXS : NOTHING); 152.443 - if(computeMaxs || computeFrames) 152.444 - { 152.445 - if(computeFrames && name.equals("<init>")) 152.446 - { 152.447 - this.access |= ACC_CONSTRUCTOR; 152.448 - } 152.449 - // updates maxLocals 152.450 - int size = getArgumentsAndReturnSizes(descriptor) >> 2; 152.451 - if((access & Opcodes.ACC_STATIC) != 0) 152.452 - { 152.453 - --size; 152.454 - } 152.455 - maxLocals = size; 152.456 - // creates and visits the label for the first basic block 152.457 - labels = new Label(); 152.458 - labels.status |= Label.PUSHED; 152.459 - visitLabel(labels); 152.460 - } 152.461 -} 152.462 - 152.463 -// ------------------------------------------------------------------------ 152.464 -// Implementation of the MethodVisitor interface 152.465 -// ------------------------------------------------------------------------ 152.466 - 152.467 -public AnnotationVisitor visitAnnotationDefault(){ 152.468 - annd = new ByteVector(); 152.469 - return new AnnotationWriter(cw, false, annd, null, 0); 152.470 -} 152.471 - 152.472 -public AnnotationVisitor visitAnnotation( 152.473 - final String desc, 152.474 - final boolean visible){ 152.475 - ByteVector bv = new ByteVector(); 152.476 - // write type, and reserve space for values count 152.477 - bv.putShort(cw.newUTF8(desc)).putShort(0); 152.478 - AnnotationWriter aw = new AnnotationWriter(cw, true, bv, bv, 2); 152.479 - if(visible) 152.480 - { 152.481 - aw.next = anns; 152.482 - anns = aw; 152.483 - } 152.484 - else 152.485 - { 152.486 - aw.next = ianns; 152.487 - ianns = aw; 152.488 - } 152.489 - return aw; 152.490 -} 152.491 - 152.492 -public AnnotationVisitor visitParameterAnnotation( 152.493 - final int parameter, 152.494 - final String desc, 152.495 - final boolean visible){ 152.496 - ByteVector bv = new ByteVector(); 152.497 - // write type, and reserve space for values count 152.498 - bv.putShort(cw.newUTF8(desc)).putShort(0); 152.499 - AnnotationWriter aw = new AnnotationWriter(cw, true, bv, bv, 2); 152.500 - if(visible) 152.501 - { 152.502 - if(panns == null) 152.503 - { 152.504 - panns = new AnnotationWriter[Type.getArgumentTypes(descriptor).length]; 152.505 - } 152.506 - aw.next = panns[parameter]; 152.507 - panns[parameter] = aw; 152.508 - } 152.509 - else 152.510 - { 152.511 - if(ipanns == null) 152.512 - { 152.513 - ipanns = new AnnotationWriter[Type.getArgumentTypes(descriptor).length]; 152.514 - } 152.515 - aw.next = ipanns[parameter]; 152.516 - ipanns[parameter] = aw; 152.517 - } 152.518 - return aw; 152.519 -} 152.520 - 152.521 -public void visitAttribute(final Attribute attr){ 152.522 - if(attr.isCodeAttribute()) 152.523 - { 152.524 - attr.next = cattrs; 152.525 - cattrs = attr; 152.526 - } 152.527 - else 152.528 - { 152.529 - attr.next = attrs; 152.530 - attrs = attr; 152.531 - } 152.532 -} 152.533 - 152.534 -public void visitCode(){ 152.535 -} 152.536 - 152.537 -public void visitFrame( 152.538 - final int type, 152.539 - final int nLocal, 152.540 - final Object[] local, 152.541 - final int nStack, 152.542 - final Object[] stack){ 152.543 - if(compute == FRAMES) 152.544 - { 152.545 - return; 152.546 - } 152.547 - 152.548 - if(type == Opcodes.F_NEW) 152.549 - { 152.550 - startFrame(code.length, nLocal, nStack); 152.551 - for(int i = 0; i < nLocal; ++i) 152.552 - { 152.553 - if(local[i] instanceof String) 152.554 - { 152.555 - frame[frameIndex++] = Frame.OBJECT 152.556 - | cw.addType((String) local[i]); 152.557 - } 152.558 - else if(local[i] instanceof Integer) 152.559 - { 152.560 - frame[frameIndex++] = ((Integer) local[i]).intValue(); 152.561 - } 152.562 - else 152.563 - { 152.564 - frame[frameIndex++] = Frame.UNINITIALIZED 152.565 - | cw.addUninitializedType("", 152.566 - ((Label) local[i]).position); 152.567 - } 152.568 - } 152.569 - for(int i = 0; i < nStack; ++i) 152.570 - { 152.571 - if(stack[i] instanceof String) 152.572 - { 152.573 - frame[frameIndex++] = Frame.OBJECT 152.574 - | cw.addType((String) stack[i]); 152.575 - } 152.576 - else if(stack[i] instanceof Integer) 152.577 - { 152.578 - frame[frameIndex++] = ((Integer) stack[i]).intValue(); 152.579 - } 152.580 - else 152.581 - { 152.582 - frame[frameIndex++] = Frame.UNINITIALIZED 152.583 - | cw.addUninitializedType("", 152.584 - ((Label) stack[i]).position); 152.585 - } 152.586 - } 152.587 - endFrame(); 152.588 - } 152.589 - else 152.590 - { 152.591 - int delta; 152.592 - if(stackMap == null) 152.593 - { 152.594 - stackMap = new ByteVector(); 152.595 - delta = code.length; 152.596 - } 152.597 - else 152.598 - { 152.599 - delta = code.length - previousFrameOffset - 1; 152.600 - } 152.601 - 152.602 - switch(type) 152.603 - { 152.604 - case Opcodes.F_FULL: 152.605 - stackMap.putByte(FULL_FRAME) 152.606 - .putShort(delta) 152.607 - .putShort(nLocal); 152.608 - for(int i = 0; i < nLocal; ++i) 152.609 - { 152.610 - writeFrameType(local[i]); 152.611 - } 152.612 - stackMap.putShort(nStack); 152.613 - for(int i = 0; i < nStack; ++i) 152.614 - { 152.615 - writeFrameType(stack[i]); 152.616 - } 152.617 - break; 152.618 - case Opcodes.F_APPEND: 152.619 - stackMap.putByte(SAME_FRAME_EXTENDED + nLocal) 152.620 - .putShort(delta); 152.621 - for(int i = 0; i < nLocal; ++i) 152.622 - { 152.623 - writeFrameType(local[i]); 152.624 - } 152.625 - break; 152.626 - case Opcodes.F_CHOP: 152.627 - stackMap.putByte(SAME_FRAME_EXTENDED - nLocal) 152.628 - .putShort(delta); 152.629 - break; 152.630 - case Opcodes.F_SAME: 152.631 - if(delta < 64) 152.632 - { 152.633 - stackMap.putByte(delta); 152.634 - } 152.635 - else 152.636 - { 152.637 - stackMap.putByte(SAME_FRAME_EXTENDED).putShort(delta); 152.638 - } 152.639 - break; 152.640 - case Opcodes.F_SAME1: 152.641 - if(delta < 64) 152.642 - { 152.643 - stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME + delta); 152.644 - } 152.645 - else 152.646 - { 152.647 - stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) 152.648 - .putShort(delta); 152.649 - } 152.650 - writeFrameType(stack[0]); 152.651 - break; 152.652 - } 152.653 - 152.654 - previousFrameOffset = code.length; 152.655 - ++frameCount; 152.656 - } 152.657 -} 152.658 - 152.659 -public void visitInsn(final int opcode){ 152.660 - // adds the instruction to the bytecode of the method 152.661 - code.putByte(opcode); 152.662 - // update currentBlock 152.663 - // Label currentBlock = this.currentBlock; 152.664 - if(currentBlock != null) 152.665 - { 152.666 - if(compute == FRAMES) 152.667 - { 152.668 - currentBlock.frame.execute(opcode, 0, null, null); 152.669 - } 152.670 - else 152.671 - { 152.672 - // updates current and max stack sizes 152.673 - int size = stackSize + Frame.SIZE[opcode]; 152.674 - if(size > maxStackSize) 152.675 - { 152.676 - maxStackSize = size; 152.677 - } 152.678 - stackSize = size; 152.679 - } 152.680 - // if opcode == ATHROW or xRETURN, ends current block (no successor) 152.681 - if((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) 152.682 - || opcode == Opcodes.ATHROW) 152.683 - { 152.684 - noSuccessor(); 152.685 - } 152.686 - } 152.687 -} 152.688 - 152.689 -public void visitIntInsn(final int opcode, final int operand){ 152.690 - // Label currentBlock = this.currentBlock; 152.691 - if(currentBlock != null) 152.692 - { 152.693 - if(compute == FRAMES) 152.694 - { 152.695 - currentBlock.frame.execute(opcode, operand, null, null); 152.696 - } 152.697 - else if(opcode != Opcodes.NEWARRAY) 152.698 - { 152.699 - // updates current and max stack sizes only for NEWARRAY 152.700 - // (stack size variation = 0 for BIPUSH or SIPUSH) 152.701 - int size = stackSize + 1; 152.702 - if(size > maxStackSize) 152.703 - { 152.704 - maxStackSize = size; 152.705 - } 152.706 - stackSize = size; 152.707 - } 152.708 - } 152.709 - // adds the instruction to the bytecode of the method 152.710 - if(opcode == Opcodes.SIPUSH) 152.711 - { 152.712 - code.put12(opcode, operand); 152.713 - } 152.714 - else 152.715 - { // BIPUSH or NEWARRAY 152.716 - code.put11(opcode, operand); 152.717 - } 152.718 -} 152.719 - 152.720 -public void visitVarInsn(final int opcode, final int var){ 152.721 - // Label currentBlock = this.currentBlock; 152.722 - if(currentBlock != null) 152.723 - { 152.724 - if(compute == FRAMES) 152.725 - { 152.726 - currentBlock.frame.execute(opcode, var, null, null); 152.727 - } 152.728 - else 152.729 - { 152.730 - // updates current and max stack sizes 152.731 - if(opcode == Opcodes.RET) 152.732 - { 152.733 - // no stack change, but end of current block (no successor) 152.734 - currentBlock.status |= Label.RET; 152.735 - // save 'stackSize' here for future use 152.736 - // (see {@link #findSubroutineSuccessors}) 152.737 - currentBlock.inputStackTop = stackSize; 152.738 - noSuccessor(); 152.739 - } 152.740 - else 152.741 - { // xLOAD or xSTORE 152.742 - int size = stackSize + Frame.SIZE[opcode]; 152.743 - if(size > maxStackSize) 152.744 - { 152.745 - maxStackSize = size; 152.746 - } 152.747 - stackSize = size; 152.748 - } 152.749 - } 152.750 - } 152.751 - if(compute != NOTHING) 152.752 - { 152.753 - // updates max locals 152.754 - int n; 152.755 - if(opcode == Opcodes.LLOAD || opcode == Opcodes.DLOAD 152.756 - || opcode == Opcodes.LSTORE || opcode == Opcodes.DSTORE) 152.757 - { 152.758 - n = var + 2; 152.759 - } 152.760 - else 152.761 - { 152.762 - n = var + 1; 152.763 - } 152.764 - if(n > maxLocals) 152.765 - { 152.766 - maxLocals = n; 152.767 - } 152.768 - } 152.769 - // adds the instruction to the bytecode of the method 152.770 - if(var < 4 && opcode != Opcodes.RET) 152.771 - { 152.772 - int opt; 152.773 - if(opcode < Opcodes.ISTORE) 152.774 - { 152.775 - /* ILOAD_0 */ 152.776 - opt = 26 + ((opcode - Opcodes.ILOAD) << 2) + var; 152.777 - } 152.778 - else 152.779 - { 152.780 - /* ISTORE_0 */ 152.781 - opt = 59 + ((opcode - Opcodes.ISTORE) << 2) + var; 152.782 - } 152.783 - code.putByte(opt); 152.784 - } 152.785 - else if(var >= 256) 152.786 - { 152.787 - code.putByte(196 /* WIDE */).put12(opcode, var); 152.788 - } 152.789 - else 152.790 - { 152.791 - code.put11(opcode, var); 152.792 - } 152.793 - if(opcode >= Opcodes.ISTORE && compute == FRAMES && handlerCount > 0) 152.794 - { 152.795 - visitLabel(new Label()); 152.796 - } 152.797 -} 152.798 - 152.799 -public void visitTypeInsn(final int opcode, final String desc){ 152.800 - Item i = cw.newClassItem(desc); 152.801 - // Label currentBlock = this.currentBlock; 152.802 - if(currentBlock != null) 152.803 - { 152.804 - if(compute == FRAMES) 152.805 - { 152.806 - currentBlock.frame.execute(opcode, code.length, cw, i); 152.807 - } 152.808 - else if(opcode == Opcodes.NEW) 152.809 - { 152.810 - // updates current and max stack sizes only if opcode == NEW 152.811 - // (no stack change for ANEWARRAY, CHECKCAST, INSTANCEOF) 152.812 - int size = stackSize + 1; 152.813 - if(size > maxStackSize) 152.814 - { 152.815 - maxStackSize = size; 152.816 - } 152.817 - stackSize = size; 152.818 - } 152.819 - } 152.820 - // adds the instruction to the bytecode of the method 152.821 - code.put12(opcode, i.index); 152.822 -} 152.823 - 152.824 -public void visitFieldInsn( 152.825 - final int opcode, 152.826 - final String owner, 152.827 - final String name, 152.828 - final String desc){ 152.829 - Item i = cw.newFieldItem(owner, name, desc); 152.830 - // Label currentBlock = this.currentBlock; 152.831 - if(currentBlock != null) 152.832 - { 152.833 - if(compute == FRAMES) 152.834 - { 152.835 - currentBlock.frame.execute(opcode, 0, cw, i); 152.836 - } 152.837 - else 152.838 - { 152.839 - int size; 152.840 - // computes the stack size variation 152.841 - char c = desc.charAt(0); 152.842 - switch(opcode) 152.843 - { 152.844 - case Opcodes.GETSTATIC: 152.845 - size = stackSize + (c == 'D' || c == 'J' ? 2 : 1); 152.846 - break; 152.847 - case Opcodes.PUTSTATIC: 152.848 - size = stackSize + (c == 'D' || c == 'J' ? -2 : -1); 152.849 - break; 152.850 - case Opcodes.GETFIELD: 152.851 - size = stackSize + (c == 'D' || c == 'J' ? 1 : 0); 152.852 - break; 152.853 - // case Constants.PUTFIELD: 152.854 - default: 152.855 - size = stackSize + (c == 'D' || c == 'J' ? -3 : -2); 152.856 - break; 152.857 - } 152.858 - // updates current and max stack sizes 152.859 - if(size > maxStackSize) 152.860 - { 152.861 - maxStackSize = size; 152.862 - } 152.863 - stackSize = size; 152.864 - } 152.865 - } 152.866 - // adds the instruction to the bytecode of the method 152.867 - code.put12(opcode, i.index); 152.868 -} 152.869 - 152.870 -public void visitMethodInsn( 152.871 - final int opcode, 152.872 - final String owner, 152.873 - final String name, 152.874 - final String desc){ 152.875 - boolean itf = opcode == Opcodes.INVOKEINTERFACE; 152.876 - Item i = cw.newMethodItem(owner, name, desc, itf); 152.877 - int argSize = i.intVal; 152.878 - // Label currentBlock = this.currentBlock; 152.879 - if(currentBlock != null) 152.880 - { 152.881 - if(compute == FRAMES) 152.882 - { 152.883 - currentBlock.frame.execute(opcode, 0, cw, i); 152.884 - } 152.885 - else 152.886 - { 152.887 - /* 152.888 - * computes the stack size variation. In order not to recompute 152.889 - * several times this variation for the same Item, we use the 152.890 - * intVal field of this item to store this variation, once it 152.891 - * has been computed. More precisely this intVal field stores 152.892 - * the sizes of the arguments and of the return value 152.893 - * corresponding to desc. 152.894 - */ 152.895 - if(argSize == 0) 152.896 - { 152.897 - // the above sizes have not been computed yet, 152.898 - // so we compute them... 152.899 - argSize = getArgumentsAndReturnSizes(desc); 152.900 - // ... and we save them in order 152.901 - // not to recompute them in the future 152.902 - i.intVal = argSize; 152.903 - } 152.904 - int size; 152.905 - if(opcode == Opcodes.INVOKESTATIC) 152.906 - { 152.907 - size = stackSize - (argSize >> 2) + (argSize & 0x03) + 1; 152.908 - } 152.909 - else 152.910 - { 152.911 - size = stackSize - (argSize >> 2) + (argSize & 0x03); 152.912 - } 152.913 - // updates current and max stack sizes 152.914 - if(size > maxStackSize) 152.915 - { 152.916 - maxStackSize = size; 152.917 - } 152.918 - stackSize = size; 152.919 - } 152.920 - } 152.921 - // adds the instruction to the bytecode of the method 152.922 - if(itf) 152.923 - { 152.924 - if(argSize == 0) 152.925 - { 152.926 - argSize = getArgumentsAndReturnSizes(desc); 152.927 - i.intVal = argSize; 152.928 - } 152.929 - code.put12(Opcodes.INVOKEINTERFACE, i.index).put11(argSize >> 2, 0); 152.930 - } 152.931 - else 152.932 - { 152.933 - code.put12(opcode, i.index); 152.934 - } 152.935 -} 152.936 - 152.937 -public void visitJumpInsn(final int opcode, final Label label){ 152.938 - Label nextInsn = null; 152.939 - // Label currentBlock = this.currentBlock; 152.940 - if(currentBlock != null) 152.941 - { 152.942 - if(compute == FRAMES) 152.943 - { 152.944 - currentBlock.frame.execute(opcode, 0, null, null); 152.945 - // 'label' is the target of a jump instruction 152.946 - label.getFirst().status |= Label.TARGET; 152.947 - // adds 'label' as a successor of this basic block 152.948 - addSuccessor(Edge.NORMAL, label); 152.949 - if(opcode != Opcodes.GOTO) 152.950 - { 152.951 - // creates a Label for the next basic block 152.952 - nextInsn = new Label(); 152.953 - } 152.954 - } 152.955 - else 152.956 - { 152.957 - if(opcode == Opcodes.JSR) 152.958 - { 152.959 - jsr = true; 152.960 - currentBlock.status |= Label.JSR; 152.961 - addSuccessor(stackSize + 1, label); 152.962 - // creates a Label for the next basic block 152.963 - nextInsn = new Label(); 152.964 - /* 152.965 - * note that, by construction in this method, a JSR block 152.966 - * has at least two successors in the control flow graph: 152.967 - * the first one leads the next instruction after the JSR, 152.968 - * while the second one leads to the JSR target. 152.969 - */ 152.970 - } 152.971 - else 152.972 - { 152.973 - // updates current stack size (max stack size unchanged 152.974 - // because stack size variation always negative in this 152.975 - // case) 152.976 - stackSize += Frame.SIZE[opcode]; 152.977 - addSuccessor(stackSize, label); 152.978 - } 152.979 - } 152.980 - } 152.981 - // adds the instruction to the bytecode of the method 152.982 - if((label.status & Label.RESOLVED) != 0 152.983 - && label.position - code.length < Short.MIN_VALUE) 152.984 - { 152.985 - /* 152.986 - * case of a backward jump with an offset < -32768. In this case we 152.987 - * automatically replace GOTO with GOTO_W, JSR with JSR_W and IFxxx 152.988 - * <l> with IFNOTxxx <l'> GOTO_W <l>, where IFNOTxxx is the 152.989 - * "opposite" opcode of IFxxx (i.e., IFNE for IFEQ) and where <l'> 152.990 - * designates the instruction just after the GOTO_W. 152.991 - */ 152.992 - if(opcode == Opcodes.GOTO) 152.993 - { 152.994 - code.putByte(200); // GOTO_W 152.995 - } 152.996 - else if(opcode == Opcodes.JSR) 152.997 - { 152.998 - code.putByte(201); // JSR_W 152.999 - } 152.1000 - else 152.1001 - { 152.1002 - // if the IF instruction is transformed into IFNOT GOTO_W the 152.1003 - // next instruction becomes the target of the IFNOT instruction 152.1004 - if(nextInsn != null) 152.1005 - { 152.1006 - nextInsn.status |= Label.TARGET; 152.1007 - } 152.1008 - code.putByte(opcode <= 166 152.1009 - ? ((opcode + 1) ^ 1) - 1 152.1010 - : opcode ^ 1); 152.1011 - code.putShort(8); // jump offset 152.1012 - code.putByte(200); // GOTO_W 152.1013 - } 152.1014 - label.put(this, code, code.length - 1, true); 152.1015 - } 152.1016 - else 152.1017 - { 152.1018 - /* 152.1019 - * case of a backward jump with an offset >= -32768, or of a forward 152.1020 - * jump with, of course, an unknown offset. In these cases we store 152.1021 - * the offset in 2 bytes (which will be increased in 152.1022 - * resizeInstructions, if needed). 152.1023 - */ 152.1024 - code.putByte(opcode); 152.1025 - label.put(this, code, code.length - 1, false); 152.1026 - } 152.1027 - if(currentBlock != null) 152.1028 - { 152.1029 - if(nextInsn != null) 152.1030 - { 152.1031 - // if the jump instruction is not a GOTO, the next instruction 152.1032 - // is also a successor of this instruction. Calling visitLabel 152.1033 - // adds the label of this next instruction as a successor of the 152.1034 - // current block, and starts a new basic block 152.1035 - visitLabel(nextInsn); 152.1036 - } 152.1037 - if(opcode == Opcodes.GOTO) 152.1038 - { 152.1039 - noSuccessor(); 152.1040 - } 152.1041 - } 152.1042 -} 152.1043 - 152.1044 -public void visitLabel(final Label label){ 152.1045 - // resolves previous forward references to label, if any 152.1046 - resize |= label.resolve(this, code.length, code.data); 152.1047 - // updates currentBlock 152.1048 - if((label.status & Label.DEBUG) != 0) 152.1049 - { 152.1050 - return; 152.1051 - } 152.1052 - if(compute == FRAMES) 152.1053 - { 152.1054 - if(currentBlock != null) 152.1055 - { 152.1056 - if(label.position == currentBlock.position) 152.1057 - { 152.1058 - // successive labels, do not start a new basic block 152.1059 - currentBlock.status |= (label.status & Label.TARGET); 152.1060 - label.frame = currentBlock.frame; 152.1061 - return; 152.1062 - } 152.1063 - // ends current block (with one new successor) 152.1064 - addSuccessor(Edge.NORMAL, label); 152.1065 - } 152.1066 - // begins a new current block 152.1067 - currentBlock = label; 152.1068 - if(label.frame == null) 152.1069 - { 152.1070 - label.frame = new Frame(); 152.1071 - label.frame.owner = label; 152.1072 - } 152.1073 - // updates the basic block list 152.1074 - if(previousBlock != null) 152.1075 - { 152.1076 - if(label.position == previousBlock.position) 152.1077 - { 152.1078 - previousBlock.status |= (label.status & Label.TARGET); 152.1079 - label.frame = previousBlock.frame; 152.1080 - currentBlock = previousBlock; 152.1081 - return; 152.1082 - } 152.1083 - previousBlock.successor = label; 152.1084 - } 152.1085 - previousBlock = label; 152.1086 - } 152.1087 - else if(compute == MAXS) 152.1088 - { 152.1089 - if(currentBlock != null) 152.1090 - { 152.1091 - // ends current block (with one new successor) 152.1092 - currentBlock.outputStackMax = maxStackSize; 152.1093 - addSuccessor(stackSize, label); 152.1094 - } 152.1095 - // begins a new current block 152.1096 - currentBlock = label; 152.1097 - // resets the relative current and max stack sizes 152.1098 - stackSize = 0; 152.1099 - maxStackSize = 0; 152.1100 - // updates the basic block list 152.1101 - if(previousBlock != null) 152.1102 - { 152.1103 - previousBlock.successor = label; 152.1104 - } 152.1105 - previousBlock = label; 152.1106 - } 152.1107 -} 152.1108 - 152.1109 -public void visitLdcInsn(final Object cst){ 152.1110 - Item i = cw.newConstItem(cst); 152.1111 - // Label currentBlock = this.currentBlock; 152.1112 - if(currentBlock != null) 152.1113 - { 152.1114 - if(compute == FRAMES) 152.1115 - { 152.1116 - currentBlock.frame.execute(Opcodes.LDC, 0, cw, i); 152.1117 - } 152.1118 - else 152.1119 - { 152.1120 - int size; 152.1121 - // computes the stack size variation 152.1122 - if(i.type == ClassWriter.LONG || i.type == ClassWriter.DOUBLE) 152.1123 - { 152.1124 - size = stackSize + 2; 152.1125 - } 152.1126 - else 152.1127 - { 152.1128 - size = stackSize + 1; 152.1129 - } 152.1130 - // updates current and max stack sizes 152.1131 - if(size > maxStackSize) 152.1132 - { 152.1133 - maxStackSize = size; 152.1134 - } 152.1135 - stackSize = size; 152.1136 - } 152.1137 - } 152.1138 - // adds the instruction to the bytecode of the method 152.1139 - int index = i.index; 152.1140 - if(i.type == ClassWriter.LONG || i.type == ClassWriter.DOUBLE) 152.1141 - { 152.1142 - code.put12(20 /* LDC2_W */, index); 152.1143 - } 152.1144 - else if(index >= 256) 152.1145 - { 152.1146 - code.put12(19 /* LDC_W */, index); 152.1147 - } 152.1148 - else 152.1149 - { 152.1150 - code.put11(Opcodes.LDC, index); 152.1151 - } 152.1152 -} 152.1153 - 152.1154 -public void visitIincInsn(final int var, final int increment){ 152.1155 - if(currentBlock != null) 152.1156 - { 152.1157 - if(compute == FRAMES) 152.1158 - { 152.1159 - currentBlock.frame.execute(Opcodes.IINC, var, null, null); 152.1160 - } 152.1161 - } 152.1162 - if(compute != NOTHING) 152.1163 - { 152.1164 - // updates max locals 152.1165 - int n = var + 1; 152.1166 - if(n > maxLocals) 152.1167 - { 152.1168 - maxLocals = n; 152.1169 - } 152.1170 - } 152.1171 - // adds the instruction to the bytecode of the method 152.1172 - if((var > 255) || (increment > 127) || (increment < -128)) 152.1173 - { 152.1174 - code.putByte(196 /* WIDE */) 152.1175 - .put12(Opcodes.IINC, var) 152.1176 - .putShort(increment); 152.1177 - } 152.1178 - else 152.1179 - { 152.1180 - code.putByte(Opcodes.IINC).put11(var, increment); 152.1181 - } 152.1182 -} 152.1183 - 152.1184 -public void visitTableSwitchInsn( 152.1185 - final int min, 152.1186 - final int max, 152.1187 - final Label dflt, 152.1188 - final Label labels[]){ 152.1189 - // adds the instruction to the bytecode of the method 152.1190 - int source = code.length; 152.1191 - code.putByte(Opcodes.TABLESWITCH); 152.1192 - code.length += (4 - code.length % 4) % 4; 152.1193 - dflt.put(this, code, source, true); 152.1194 - code.putInt(min).putInt(max); 152.1195 - for(int i = 0; i < labels.length; ++i) 152.1196 - { 152.1197 - labels[i].put(this, code, source, true); 152.1198 - } 152.1199 - // updates currentBlock 152.1200 - visitSwitchInsn(dflt, labels); 152.1201 -} 152.1202 - 152.1203 -public void visitLookupSwitchInsn( 152.1204 - final Label dflt, 152.1205 - final int keys[], 152.1206 - final Label labels[]){ 152.1207 - // adds the instruction to the bytecode of the method 152.1208 - int source = code.length; 152.1209 - code.putByte(Opcodes.LOOKUPSWITCH); 152.1210 - code.length += (4 - code.length % 4) % 4; 152.1211 - dflt.put(this, code, source, true); 152.1212 - code.putInt(labels.length); 152.1213 - for(int i = 0; i < labels.length; ++i) 152.1214 - { 152.1215 - code.putInt(keys[i]); 152.1216 - labels[i].put(this, code, source, true); 152.1217 - } 152.1218 - // updates currentBlock 152.1219 - visitSwitchInsn(dflt, labels); 152.1220 -} 152.1221 - 152.1222 -private void visitSwitchInsn(final Label dflt, final Label[] labels){ 152.1223 - // Label currentBlock = this.currentBlock; 152.1224 - if(currentBlock != null) 152.1225 - { 152.1226 - if(compute == FRAMES) 152.1227 - { 152.1228 - currentBlock.frame.execute(Opcodes.LOOKUPSWITCH, 0, null, null); 152.1229 - // adds current block successors 152.1230 - addSuccessor(Edge.NORMAL, dflt); 152.1231 - dflt.getFirst().status |= Label.TARGET; 152.1232 - for(int i = 0; i < labels.length; ++i) 152.1233 - { 152.1234 - addSuccessor(Edge.NORMAL, labels[i]); 152.1235 - labels[i].getFirst().status |= Label.TARGET; 152.1236 - } 152.1237 - } 152.1238 - else 152.1239 - { 152.1240 - // updates current stack size (max stack size unchanged) 152.1241 - --stackSize; 152.1242 - // adds current block successors 152.1243 - addSuccessor(stackSize, dflt); 152.1244 - for(int i = 0; i < labels.length; ++i) 152.1245 - { 152.1246 - addSuccessor(stackSize, labels[i]); 152.1247 - } 152.1248 - } 152.1249 - // ends current block 152.1250 - noSuccessor(); 152.1251 - } 152.1252 -} 152.1253 - 152.1254 -public void visitMultiANewArrayInsn(final String desc, final int dims){ 152.1255 - Item i = cw.newClassItem(desc); 152.1256 - // Label currentBlock = this.currentBlock; 152.1257 - if(currentBlock != null) 152.1258 - { 152.1259 - if(compute == FRAMES) 152.1260 - { 152.1261 - currentBlock.frame.execute(Opcodes.MULTIANEWARRAY, dims, cw, i); 152.1262 - } 152.1263 - else 152.1264 - { 152.1265 - // updates current stack size (max stack size unchanged because 152.1266 - // stack size variation always negative or null) 152.1267 - stackSize += 1 - dims; 152.1268 - } 152.1269 - } 152.1270 - // adds the instruction to the bytecode of the method 152.1271 - code.put12(Opcodes.MULTIANEWARRAY, i.index).putByte(dims); 152.1272 -} 152.1273 - 152.1274 -public void visitTryCatchBlock( 152.1275 - final Label start, 152.1276 - final Label end, 152.1277 - final Label handler, 152.1278 - final String type){ 152.1279 - ++handlerCount; 152.1280 - Handler h = new Handler(); 152.1281 - h.start = start; 152.1282 - h.end = end; 152.1283 - h.handler = handler; 152.1284 - h.desc = type; 152.1285 - h.type = type != null ? cw.newClass(type) : 0; 152.1286 - if(lastHandler == null) 152.1287 - { 152.1288 - firstHandler = h; 152.1289 - } 152.1290 - else 152.1291 - { 152.1292 - lastHandler.next = h; 152.1293 - } 152.1294 - lastHandler = h; 152.1295 -} 152.1296 - 152.1297 -public void visitLocalVariable( 152.1298 - final String name, 152.1299 - final String desc, 152.1300 - final String signature, 152.1301 - final Label start, 152.1302 - final Label end, 152.1303 - final int index){ 152.1304 - if(signature != null) 152.1305 - { 152.1306 - if(localVarType == null) 152.1307 - { 152.1308 - localVarType = new ByteVector(); 152.1309 - } 152.1310 - ++localVarTypeCount; 152.1311 - localVarType.putShort(start.position) 152.1312 - .putShort(end.position - start.position) 152.1313 - .putShort(cw.newUTF8(name)) 152.1314 - .putShort(cw.newUTF8(signature)) 152.1315 - .putShort(index); 152.1316 - } 152.1317 - if(localVar == null) 152.1318 - { 152.1319 - localVar = new ByteVector(); 152.1320 - } 152.1321 - ++localVarCount; 152.1322 - localVar.putShort(start.position) 152.1323 - .putShort(end.position - start.position) 152.1324 - .putShort(cw.newUTF8(name)) 152.1325 - .putShort(cw.newUTF8(desc)) 152.1326 - .putShort(index); 152.1327 - if(compute != NOTHING) 152.1328 - { 152.1329 - // updates max locals 152.1330 - char c = desc.charAt(0); 152.1331 - int n = index + (c == 'J' || c == 'D' ? 2 : 1); 152.1332 - if(n > maxLocals) 152.1333 - { 152.1334 - maxLocals = n; 152.1335 - } 152.1336 - } 152.1337 -} 152.1338 - 152.1339 -public void visitLineNumber(final int line, final Label start){ 152.1340 - if(lineNumber == null) 152.1341 - { 152.1342 - lineNumber = new ByteVector(); 152.1343 - } 152.1344 - ++lineNumberCount; 152.1345 - lineNumber.putShort(start.position); 152.1346 - lineNumber.putShort(line); 152.1347 -} 152.1348 - 152.1349 -public void visitMaxs(final int maxStack, final int maxLocals){ 152.1350 - if(compute == FRAMES) 152.1351 - { 152.1352 - // completes the control flow graph with exception handler blocks 152.1353 - Handler handler = firstHandler; 152.1354 - while(handler != null) 152.1355 - { 152.1356 - Label l = handler.start.getFirst(); 152.1357 - Label h = handler.handler.getFirst(); 152.1358 - Label e = handler.end.getFirst(); 152.1359 - // computes the kind of the edges to 'h' 152.1360 - String t = handler.desc == null 152.1361 - ? "java/lang/Throwable" 152.1362 - : handler.desc; 152.1363 - int kind = Frame.OBJECT | cw.addType(t); 152.1364 - // h is an exception handler 152.1365 - h.status |= Label.TARGET; 152.1366 - // adds 'h' as a successor of labels between 'start' and 'end' 152.1367 - while(l != e) 152.1368 - { 152.1369 - // creates an edge to 'h' 152.1370 - Edge b = new Edge(); 152.1371 - b.info = kind; 152.1372 - b.successor = h; 152.1373 - // adds it to the successors of 'l' 152.1374 - b.next = l.successors; 152.1375 - l.successors = b; 152.1376 - // goes to the next label 152.1377 - l = l.successor; 152.1378 - } 152.1379 - handler = handler.next; 152.1380 - } 152.1381 - 152.1382 - // creates and visits the first (implicit) frame 152.1383 - Frame f = labels.frame; 152.1384 - Type[] args = Type.getArgumentTypes(descriptor); 152.1385 - f.initInputFrame(cw, access, args, this.maxLocals); 152.1386 - visitFrame(f); 152.1387 - 152.1388 - /* 152.1389 - * fix point algorithm: mark the first basic block as 'changed' 152.1390 - * (i.e. put it in the 'changed' list) and, while there are changed 152.1391 - * basic blocks, choose one, mark it as unchanged, and update its 152.1392 - * successors (which can be changed in the process). 152.1393 - */ 152.1394 - int max = 0; 152.1395 - Label changed = labels; 152.1396 - while(changed != null) 152.1397 - { 152.1398 - // removes a basic block from the list of changed basic blocks 152.1399 - Label l = changed; 152.1400 - changed = changed.next; 152.1401 - l.next = null; 152.1402 - f = l.frame; 152.1403 - // a reacheable jump target must be stored in the stack map 152.1404 - if((l.status & Label.TARGET) != 0) 152.1405 - { 152.1406 - l.status |= Label.STORE; 152.1407 - } 152.1408 - // all visited labels are reacheable, by definition 152.1409 - l.status |= Label.REACHABLE; 152.1410 - // updates the (absolute) maximum stack size 152.1411 - int blockMax = f.inputStack.length + l.outputStackMax; 152.1412 - if(blockMax > max) 152.1413 - { 152.1414 - max = blockMax; 152.1415 - } 152.1416 - // updates the successors of the current basic block 152.1417 - Edge e = l.successors; 152.1418 - while(e != null) 152.1419 - { 152.1420 - Label n = e.successor.getFirst(); 152.1421 - boolean change = f.merge(cw, n.frame, e.info); 152.1422 - if(change && n.next == null) 152.1423 - { 152.1424 - // if n has changed and is not already in the 'changed' 152.1425 - // list, adds it to this list 152.1426 - n.next = changed; 152.1427 - changed = n; 152.1428 - } 152.1429 - e = e.next; 152.1430 - } 152.1431 - } 152.1432 - this.maxStack = max; 152.1433 - 152.1434 - // visits all the frames that must be stored in the stack map 152.1435 - Label l = labels; 152.1436 - while(l != null) 152.1437 - { 152.1438 - f = l.frame; 152.1439 - if((l.status & Label.STORE) != 0) 152.1440 - { 152.1441 - visitFrame(f); 152.1442 - } 152.1443 - if((l.status & Label.REACHABLE) == 0) 152.1444 - { 152.1445 - // finds start and end of dead basic block 152.1446 - Label k = l.successor; 152.1447 - int start = l.position; 152.1448 - int end = (k == null ? code.length : k.position) - 1; 152.1449 - // if non empty basic block 152.1450 - if(end >= start) 152.1451 - { 152.1452 - // replaces instructions with NOP ... NOP ATHROW 152.1453 - for(int i = start; i < end; ++i) 152.1454 - { 152.1455 - code.data[i] = Opcodes.NOP; 152.1456 - } 152.1457 - code.data[end] = (byte) Opcodes.ATHROW; 152.1458 - // emits a frame for this unreachable block 152.1459 - startFrame(start, 0, 1); 152.1460 - frame[frameIndex++] = Frame.OBJECT 152.1461 - | cw.addType("java/lang/Throwable"); 152.1462 - endFrame(); 152.1463 - } 152.1464 - } 152.1465 - l = l.successor; 152.1466 - } 152.1467 - } 152.1468 - else if(compute == MAXS) 152.1469 - { 152.1470 - // completes the control flow graph with exception handler blocks 152.1471 - Handler handler = firstHandler; 152.1472 - while(handler != null) 152.1473 - { 152.1474 - Label l = handler.start; 152.1475 - Label h = handler.handler; 152.1476 - Label e = handler.end; 152.1477 - // adds 'h' as a successor of labels between 'start' and 'end' 152.1478 - while(l != e) 152.1479 - { 152.1480 - // creates an edge to 'h' 152.1481 - Edge b = new Edge(); 152.1482 - b.info = Edge.EXCEPTION; 152.1483 - b.successor = h; 152.1484 - // adds it to the successors of 'l' 152.1485 - if((l.status & Label.JSR) != 0) 152.1486 - { 152.1487 - // if l is a JSR block, adds b after the first two edges 152.1488 - // to preserve the hypothesis about JSR block successors 152.1489 - // order (see {@link #visitJumpInsn}) 152.1490 - b.next = l.successors.next.next; 152.1491 - l.successors.next.next = b; 152.1492 - } 152.1493 - else 152.1494 - { 152.1495 - b.next = l.successors; 152.1496 - l.successors = b; 152.1497 - } 152.1498 - // goes to the next label 152.1499 - l = l.successor; 152.1500 - } 152.1501 - handler = handler.next; 152.1502 - } 152.1503 - 152.1504 - if(jsr) 152.1505 - { 152.1506 - // completes the control flow graph with the RET successors 152.1507 - /* 152.1508 - * first step: finds the subroutines. This step determines, for 152.1509 - * each basic block, to which subroutine(s) it belongs, and 152.1510 - * stores this set as a bit set in the {@link Label#status} 152.1511 - * field. Subroutines are numbered with powers of two, from 152.1512 - * 0x1000 to 0x80000000 (so there must be at most 20 subroutines 152.1513 - * in a method). 152.1514 - */ 152.1515 - // finds the basic blocks that belong to the "main" subroutine 152.1516 - int id = 0x1000; 152.1517 - findSubroutine(labels, id); 152.1518 - // finds the basic blocks that belong to the real subroutines 152.1519 - Label l = labels; 152.1520 - while(l != null) 152.1521 - { 152.1522 - if((l.status & Label.JSR) != 0) 152.1523 - { 152.1524 - // the subroutine is defined by l's TARGET, not by l 152.1525 - Label subroutine = l.successors.next.successor; 152.1526 - // if this subroutine does not have an id yet... 152.1527 - if((subroutine.status & ~0xFFF) == 0) 152.1528 - { 152.1529 - // ...assigns it a new id and finds its basic blocks 152.1530 - id = id << 1; 152.1531 - findSubroutine(subroutine, id); 152.1532 - } 152.1533 - } 152.1534 - l = l.successor; 152.1535 - } 152.1536 - // second step: finds the successors of RET blocks 152.1537 - findSubroutineSuccessors(0x1000, new Label[10], 0); 152.1538 - } 152.1539 - 152.1540 - /* 152.1541 - * control flow analysis algorithm: while the block stack is not 152.1542 - * empty, pop a block from this stack, update the max stack size, 152.1543 - * compute the true (non relative) begin stack size of the 152.1544 - * successors of this block, and push these successors onto the 152.1545 - * stack (unless they have already been pushed onto the stack). 152.1546 - * Note: by hypothesis, the {@link Label#inputStackTop} of the 152.1547 - * blocks in the block stack are the true (non relative) beginning 152.1548 - * stack sizes of these blocks. 152.1549 - */ 152.1550 - int max = 0; 152.1551 - Label stack = labels; 152.1552 - while(stack != null) 152.1553 - { 152.1554 - // pops a block from the stack 152.1555 - Label l = stack; 152.1556 - stack = stack.next; 152.1557 - // computes the true (non relative) max stack size of this block 152.1558 - int start = l.inputStackTop; 152.1559 - int blockMax = start + l.outputStackMax; 152.1560 - // updates the global max stack size 152.1561 - if(blockMax > max) 152.1562 - { 152.1563 - max = blockMax; 152.1564 - } 152.1565 - // analyses the successors of the block 152.1566 - Edge b = l.successors; 152.1567 - if((l.status & Label.JSR) != 0) 152.1568 - { 152.1569 - // ignores the first edge of JSR blocks (virtual successor) 152.1570 - b = b.next; 152.1571 - } 152.1572 - while(b != null) 152.1573 - { 152.1574 - l = b.successor; 152.1575 - // if this successor has not already been pushed... 152.1576 - if((l.status & Label.PUSHED) == 0) 152.1577 - { 152.1578 - // computes its true beginning stack size... 152.1579 - l.inputStackTop = b.info == Edge.EXCEPTION ? 1 : start 152.1580 - + b.info; 152.1581 - // ...and pushes it onto the stack 152.1582 - l.status |= Label.PUSHED; 152.1583 - l.next = stack; 152.1584 - stack = l; 152.1585 - } 152.1586 - b = b.next; 152.1587 - } 152.1588 - } 152.1589 - this.maxStack = max; 152.1590 - } 152.1591 - else 152.1592 - { 152.1593 - this.maxStack = maxStack; 152.1594 - this.maxLocals = maxLocals; 152.1595 - } 152.1596 -} 152.1597 - 152.1598 -public void visitEnd(){ 152.1599 -} 152.1600 - 152.1601 -// ------------------------------------------------------------------------ 152.1602 -// Utility methods: control flow analysis algorithm 152.1603 -// ------------------------------------------------------------------------ 152.1604 - 152.1605 -/** 152.1606 - * Computes the size of the arguments and of the return value of a method. 152.1607 - * 152.1608 - * @param desc the descriptor of a method. 152.1609 - * @return the size of the arguments of the method (plus one for the 152.1610 - * implicit this argument), argSize, and the size of its return 152.1611 - * value, retSize, packed into a single int i = 152.1612 - * <tt>(argSize << 2) | retSize</tt> (argSize is therefore equal 152.1613 - * to <tt>i >> 2</tt>, and retSize to <tt>i & 0x03</tt>). 152.1614 - */ 152.1615 -static int getArgumentsAndReturnSizes(final String desc){ 152.1616 - int n = 1; 152.1617 - int c = 1; 152.1618 - while(true) 152.1619 - { 152.1620 - char car = desc.charAt(c++); 152.1621 - if(car == ')') 152.1622 - { 152.1623 - car = desc.charAt(c); 152.1624 - return n << 2 152.1625 - | (car == 'V' ? 0 : (car == 'D' || car == 'J' ? 2 : 1)); 152.1626 - } 152.1627 - else if(car == 'L') 152.1628 - { 152.1629 - while(desc.charAt(c++) != ';') 152.1630 - { 152.1631 - } 152.1632 - n += 1; 152.1633 - } 152.1634 - else if(car == '[') 152.1635 - { 152.1636 - while((car = desc.charAt(c)) == '[') 152.1637 - { 152.1638 - ++c; 152.1639 - } 152.1640 - if(car == 'D' || car == 'J') 152.1641 - { 152.1642 - n -= 1; 152.1643 - } 152.1644 - } 152.1645 - else if(car == 'D' || car == 'J') 152.1646 - { 152.1647 - n += 2; 152.1648 - } 152.1649 - else 152.1650 - { 152.1651 - n += 1; 152.1652 - } 152.1653 - } 152.1654 -} 152.1655 - 152.1656 -/** 152.1657 - * Adds a successor to the {@link #currentBlock currentBlock} block. 152.1658 - * 152.1659 - * @param info information about the control flow edge to be added. 152.1660 - * @param successor the successor block to be added to the current block. 152.1661 - */ 152.1662 -private void addSuccessor(final int info, final Label successor){ 152.1663 - // creates and initializes an Edge object... 152.1664 - Edge b = new Edge(); 152.1665 - b.info = info; 152.1666 - b.successor = successor; 152.1667 - // ...and adds it to the successor list of the currentBlock block 152.1668 - b.next = currentBlock.successors; 152.1669 - currentBlock.successors = b; 152.1670 -} 152.1671 - 152.1672 -/** 152.1673 - * Ends the current basic block. This method must be used in the case where 152.1674 - * the current basic block does not have any successor. 152.1675 - */ 152.1676 -private void noSuccessor(){ 152.1677 - if(compute == FRAMES) 152.1678 - { 152.1679 - Label l = new Label(); 152.1680 - l.frame = new Frame(); 152.1681 - l.frame.owner = l; 152.1682 - l.resolve(this, code.length, code.data); 152.1683 - previousBlock.successor = l; 152.1684 - previousBlock = l; 152.1685 - } 152.1686 - else 152.1687 - { 152.1688 - currentBlock.outputStackMax = maxStackSize; 152.1689 - } 152.1690 - currentBlock = null; 152.1691 -} 152.1692 - 152.1693 -/** 152.1694 - * Finds the basic blocks that belong to a given subroutine, and marks these 152.1695 - * blocks as belonging to this subroutine (by using {@link Label#status} as 152.1696 - * a bit set (see {@link #visitMaxs}). This recursive method follows the 152.1697 - * control flow graph to find all the blocks that are reachable from the 152.1698 - * given block WITHOUT following any JSR target. 152.1699 - * 152.1700 - * @param block a block that belongs to the subroutine 152.1701 - * @param id the id of this subroutine 152.1702 - */ 152.1703 -private void findSubroutine(final Label block, final int id){ 152.1704 - // if 'block' is already marked as belonging to subroutine 'id', returns 152.1705 - if((block.status & id) != 0) 152.1706 - { 152.1707 - return; 152.1708 - } 152.1709 - // marks 'block' as belonging to subroutine 'id' 152.1710 - block.status |= id; 152.1711 - // calls this method recursively on each successor, except JSR targets 152.1712 - Edge e = block.successors; 152.1713 - while(e != null) 152.1714 - { 152.1715 - // if 'block' is a JSR block, then 'block.successors.next' leads 152.1716 - // to the JSR target (see {@link #visitJumpInsn}) and must therefore 152.1717 - // not be followed 152.1718 - if((block.status & Label.JSR) == 0 || e != block.successors.next) 152.1719 - { 152.1720 - findSubroutine(e.successor, id); 152.1721 - } 152.1722 - e = e.next; 152.1723 - } 152.1724 -} 152.1725 - 152.1726 -/** 152.1727 - * Finds the successors of the RET blocks of the specified subroutine, and 152.1728 - * of any nested subroutine it calls. 152.1729 - * 152.1730 - * @param id id of the subroutine whose RET block successors must be found. 152.1731 - * @param JSRs the JSR blocks that were followed to reach this subroutine. 152.1732 - * @param nJSRs number of JSR blocks in the JSRs array. 152.1733 - */ 152.1734 -private void findSubroutineSuccessors( 152.1735 - final int id, 152.1736 - final Label[] JSRs, 152.1737 - final int nJSRs){ 152.1738 - // iterates over all the basic blocks... 152.1739 - Label l = labels; 152.1740 - while(l != null) 152.1741 - { 152.1742 - // for those that belong to subroutine 'id'... 152.1743 - if((l.status & id) != 0) 152.1744 - { 152.1745 - if((l.status & Label.JSR) != 0) 152.1746 - { 152.1747 - // finds the subroutine to which 'l' leads by following the 152.1748 - // second edge of l.successors (see {@link #visitJumpInsn}) 152.1749 - int nId = l.successors.next.successor.status & ~0xFFF; 152.1750 - if(nId != id) 152.1751 - { 152.1752 - // calls this method recursively with l pushed onto the 152.1753 - // JSRs stack to find the successors of the RET blocks 152.1754 - // of this nested subroutine 'nId' 152.1755 - JSRs[nJSRs] = l; 152.1756 - findSubroutineSuccessors(nId, JSRs, nJSRs + 1); 152.1757 - } 152.1758 - } 152.1759 - else if((l.status & Label.RET) != 0) 152.1760 - { 152.1761 - /* 152.1762 - * finds the JSR block in the JSRs stack that corresponds to 152.1763 - * this RET block, and updates the successors of this RET 152.1764 - * block accordingly. This corresponding JSR is the one that 152.1765 - * leads to the subroutine to which the RET block belongs. 152.1766 - * But the RET block can belong to several subroutines (if a 152.1767 - * nested subroutine returns to its parent subroutine 152.1768 - * implicitely, without a RET). So, in fact, the JSR that 152.1769 - * corresponds to this RET is the first block in the JSRs 152.1770 - * stack, starting from the bottom of the stack, that leads 152.1771 - * to a subroutine to which the RET block belongs. 152.1772 - */ 152.1773 - for(int i = 0; i < nJSRs; ++i) 152.1774 - { 152.1775 - int JSRstatus = JSRs[i].successors.next.successor.status; 152.1776 - if(((JSRstatus & ~0xFFF) & (l.status & ~0xFFF)) != 0) 152.1777 - { 152.1778 - Edge e = new Edge(); 152.1779 - e.info = l.inputStackTop; 152.1780 - e.successor = JSRs[i].successors.successor; 152.1781 - e.next = l.successors; 152.1782 - l.successors = e; 152.1783 - break; 152.1784 - } 152.1785 - } 152.1786 - } 152.1787 - } 152.1788 - l = l.successor; 152.1789 - } 152.1790 -} 152.1791 - 152.1792 -// ------------------------------------------------------------------------ 152.1793 -// Utility methods: stack map frames 152.1794 -// ------------------------------------------------------------------------ 152.1795 - 152.1796 -/** 152.1797 - * Visits a frame that has been computed from scratch. 152.1798 - * 152.1799 - * @param f the frame that must be visited. 152.1800 - */ 152.1801 -private void visitFrame(final Frame f){ 152.1802 - int i, t; 152.1803 - int nTop = 0; 152.1804 - int nLocal = 0; 152.1805 - int nStack = 0; 152.1806 - int[] locals = f.inputLocals; 152.1807 - int[] stacks = f.inputStack; 152.1808 - // computes the number of locals (ignores TOP types that are just after 152.1809 - // a LONG or a DOUBLE, and all trailing TOP types) 152.1810 - for(i = 0; i < locals.length; ++i) 152.1811 - { 152.1812 - t = locals[i]; 152.1813 - if(t == Frame.TOP) 152.1814 - { 152.1815 - ++nTop; 152.1816 - } 152.1817 - else 152.1818 - { 152.1819 - nLocal += nTop + 1; 152.1820 - nTop = 0; 152.1821 - } 152.1822 - if(t == Frame.LONG || t == Frame.DOUBLE) 152.1823 - { 152.1824 - ++i; 152.1825 - } 152.1826 - } 152.1827 - // computes the stack size (ignores TOP types that are just after 152.1828 - // a LONG or a DOUBLE) 152.1829 - for(i = 0; i < stacks.length; ++i) 152.1830 - { 152.1831 - t = stacks[i]; 152.1832 - ++nStack; 152.1833 - if(t == Frame.LONG || t == Frame.DOUBLE) 152.1834 - { 152.1835 - ++i; 152.1836 - } 152.1837 - } 152.1838 - // visits the frame and its content 152.1839 - startFrame(f.owner.position, nLocal, nStack); 152.1840 - for(i = 0; nLocal > 0; ++i, --nLocal) 152.1841 - { 152.1842 - t = locals[i]; 152.1843 - frame[frameIndex++] = t; 152.1844 - if(t == Frame.LONG || t == Frame.DOUBLE) 152.1845 - { 152.1846 - ++i; 152.1847 - } 152.1848 - } 152.1849 - for(i = 0; i < stacks.length; ++i) 152.1850 - { 152.1851 - t = stacks[i]; 152.1852 - frame[frameIndex++] = t; 152.1853 - if(t == Frame.LONG || t == Frame.DOUBLE) 152.1854 - { 152.1855 - ++i; 152.1856 - } 152.1857 - } 152.1858 - endFrame(); 152.1859 -} 152.1860 - 152.1861 -/** 152.1862 - * Starts the visit of a stack map frame. 152.1863 - * 152.1864 - * @param offset the offset of the instruction to which the frame 152.1865 - * corresponds. 152.1866 - * @param nLocal the number of local variables in the frame. 152.1867 - * @param nStack the number of stack elements in the frame. 152.1868 - */ 152.1869 -private void startFrame(final int offset, final int nLocal, final int nStack){ 152.1870 - int n = 3 + nLocal + nStack; 152.1871 - if(frame == null || frame.length < n) 152.1872 - { 152.1873 - frame = new int[n]; 152.1874 - } 152.1875 - frame[0] = offset; 152.1876 - frame[1] = nLocal; 152.1877 - frame[2] = nStack; 152.1878 - frameIndex = 3; 152.1879 -} 152.1880 - 152.1881 -/** 152.1882 - * Checks if the visit of the current frame {@link #frame} is finished, and 152.1883 - * if yes, write it in the StackMapTable attribute. 152.1884 - */ 152.1885 -private void endFrame(){ 152.1886 - if(previousFrame != null) 152.1887 - { // do not write the first frame 152.1888 - if(stackMap == null) 152.1889 - { 152.1890 - stackMap = new ByteVector(); 152.1891 - } 152.1892 - writeFrame(); 152.1893 - ++frameCount; 152.1894 - } 152.1895 - previousFrame = frame; 152.1896 - frame = null; 152.1897 -} 152.1898 - 152.1899 -/** 152.1900 - * Compress and writes the current frame {@link #frame} in the StackMapTable 152.1901 - * attribute. 152.1902 - */ 152.1903 -private void writeFrame(){ 152.1904 - int clocalsSize = frame[1]; 152.1905 - int cstackSize = frame[2]; 152.1906 - if((cw.version & 0xFFFF) < Opcodes.V1_6) 152.1907 - { 152.1908 - stackMap.putShort(frame[0]).putShort(clocalsSize); 152.1909 - writeFrameTypes(3, 3 + clocalsSize); 152.1910 - stackMap.putShort(cstackSize); 152.1911 - writeFrameTypes(3 + clocalsSize, 3 + clocalsSize + cstackSize); 152.1912 - return; 152.1913 - } 152.1914 - int localsSize = previousFrame[1]; 152.1915 - int type = FULL_FRAME; 152.1916 - int k = 0; 152.1917 - int delta; 152.1918 - if(frameCount == 0) 152.1919 - { 152.1920 - delta = frame[0]; 152.1921 - } 152.1922 - else 152.1923 - { 152.1924 - delta = frame[0] - previousFrame[0] - 1; 152.1925 - } 152.1926 - if(cstackSize == 0) 152.1927 - { 152.1928 - k = clocalsSize - localsSize; 152.1929 - switch(k) 152.1930 - { 152.1931 - case-3: 152.1932 - case-2: 152.1933 - case-1: 152.1934 - type = CHOP_FRAME; 152.1935 - localsSize = clocalsSize; 152.1936 - break; 152.1937 - case 0: 152.1938 - type = delta < 64 ? SAME_FRAME : SAME_FRAME_EXTENDED; 152.1939 - break; 152.1940 - case 1: 152.1941 - case 2: 152.1942 - case 3: 152.1943 - type = APPEND_FRAME; 152.1944 - break; 152.1945 - } 152.1946 - } 152.1947 - else if(clocalsSize == localsSize && cstackSize == 1) 152.1948 - { 152.1949 - type = delta < 63 152.1950 - ? SAME_LOCALS_1_STACK_ITEM_FRAME 152.1951 - : SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED; 152.1952 - } 152.1953 - if(type != FULL_FRAME) 152.1954 - { 152.1955 - // verify if locals are the same 152.1956 - int l = 3; 152.1957 - for(int j = 0; j < localsSize; j++) 152.1958 - { 152.1959 - if(frame[l] != previousFrame[l]) 152.1960 - { 152.1961 - type = FULL_FRAME; 152.1962 - break; 152.1963 - } 152.1964 - l++; 152.1965 - } 152.1966 - } 152.1967 - switch(type) 152.1968 - { 152.1969 - case SAME_FRAME: 152.1970 - stackMap.putByte(delta); 152.1971 - break; 152.1972 - case SAME_LOCALS_1_STACK_ITEM_FRAME: 152.1973 - stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME + delta); 152.1974 - writeFrameTypes(3 + clocalsSize, 4 + clocalsSize); 152.1975 - break; 152.1976 - case SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED: 152.1977 - stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) 152.1978 - .putShort(delta); 152.1979 - writeFrameTypes(3 + clocalsSize, 4 + clocalsSize); 152.1980 - break; 152.1981 - case SAME_FRAME_EXTENDED: 152.1982 - stackMap.putByte(SAME_FRAME_EXTENDED).putShort(delta); 152.1983 - break; 152.1984 - case CHOP_FRAME: 152.1985 - stackMap.putByte(SAME_FRAME_EXTENDED + k).putShort(delta); 152.1986 - break; 152.1987 - case APPEND_FRAME: 152.1988 - stackMap.putByte(SAME_FRAME_EXTENDED + k).putShort(delta); 152.1989 - writeFrameTypes(3 + localsSize, 3 + clocalsSize); 152.1990 - break; 152.1991 - // case FULL_FRAME: 152.1992 - default: 152.1993 - stackMap.putByte(FULL_FRAME) 152.1994 - .putShort(delta) 152.1995 - .putShort(clocalsSize); 152.1996 - writeFrameTypes(3, 3 + clocalsSize); 152.1997 - stackMap.putShort(cstackSize); 152.1998 - writeFrameTypes(3 + clocalsSize, 3 + clocalsSize + cstackSize); 152.1999 - } 152.2000 -} 152.2001 - 152.2002 -/** 152.2003 - * Writes some types of the current frame {@link #frame} into the 152.2004 - * StackMapTableAttribute. This method converts types from the format used 152.2005 - * in {@link Label} to the format used in StackMapTable attributes. In 152.2006 - * particular, it converts type table indexes to constant pool indexes. 152.2007 - * 152.2008 - * @param start index of the first type in {@link #frame} to write. 152.2009 - * @param end index of last type in {@link #frame} to write (exclusive). 152.2010 - */ 152.2011 -private void writeFrameTypes(final int start, final int end){ 152.2012 - for(int i = start; i < end; ++i) 152.2013 - { 152.2014 - int t = frame[i]; 152.2015 - int d = t & Frame.DIM; 152.2016 - if(d == 0) 152.2017 - { 152.2018 - int v = t & Frame.BASE_VALUE; 152.2019 - switch(t & Frame.BASE_KIND) 152.2020 - { 152.2021 - case Frame.OBJECT: 152.2022 - stackMap.putByte(7) 152.2023 - .putShort(cw.newClass(cw.typeTable[v].strVal1)); 152.2024 - break; 152.2025 - case Frame.UNINITIALIZED: 152.2026 - stackMap.putByte(8).putShort(cw.typeTable[v].intVal); 152.2027 - break; 152.2028 - default: 152.2029 - stackMap.putByte(v); 152.2030 - } 152.2031 - } 152.2032 - else 152.2033 - { 152.2034 - StringBuffer buf = new StringBuffer(); 152.2035 - d >>= 28; 152.2036 - while(d-- > 0) 152.2037 - { 152.2038 - buf.append('['); 152.2039 - } 152.2040 - if((t & Frame.BASE_KIND) == Frame.OBJECT) 152.2041 - { 152.2042 - buf.append('L'); 152.2043 - buf.append(cw.typeTable[t & Frame.BASE_VALUE].strVal1); 152.2044 - buf.append(';'); 152.2045 - } 152.2046 - else 152.2047 - { 152.2048 - switch(t & 0xF) 152.2049 - { 152.2050 - case 1: 152.2051 - buf.append('I'); 152.2052 - break; 152.2053 - case 2: 152.2054 - buf.append('F'); 152.2055 - break; 152.2056 - case 3: 152.2057 - buf.append('D'); 152.2058 - break; 152.2059 - case 9: 152.2060 - buf.append('Z'); 152.2061 - break; 152.2062 - case 10: 152.2063 - buf.append('B'); 152.2064 - break; 152.2065 - case 11: 152.2066 - buf.append('C'); 152.2067 - break; 152.2068 - case 12: 152.2069 - buf.append('S'); 152.2070 - break; 152.2071 - default: 152.2072 - buf.append('J'); 152.2073 - } 152.2074 - } 152.2075 - stackMap.putByte(7).putShort(cw.newClass(buf.toString())); 152.2076 - } 152.2077 - } 152.2078 -} 152.2079 - 152.2080 -private void writeFrameType(final Object type){ 152.2081 - if(type instanceof String) 152.2082 - { 152.2083 - stackMap.putByte(7).putShort(cw.newClass((String) type)); 152.2084 - } 152.2085 - else if(type instanceof Integer) 152.2086 - { 152.2087 - stackMap.putByte(((Integer) type).intValue()); 152.2088 - } 152.2089 - else 152.2090 - { 152.2091 - stackMap.putByte(8).putShort(((Label) type).position); 152.2092 - } 152.2093 -} 152.2094 - 152.2095 -// ------------------------------------------------------------------------ 152.2096 -// Utility methods: dump bytecode array 152.2097 -// ------------------------------------------------------------------------ 152.2098 - 152.2099 -/** 152.2100 - * Returns the size of the bytecode of this method. 152.2101 - * 152.2102 - * @return the size of the bytecode of this method. 152.2103 - */ 152.2104 -final int getSize(){ 152.2105 - if(classReaderOffset != 0) 152.2106 - { 152.2107 - return 6 + classReaderLength; 152.2108 - } 152.2109 - if(resize) 152.2110 - { 152.2111 - // replaces the temporary jump opcodes introduced by Label.resolve. 152.2112 - resizeInstructions(); 152.2113 - } 152.2114 - int size = 8; 152.2115 - if(code.length > 0) 152.2116 - { 152.2117 - cw.newUTF8("Code"); 152.2118 - size += 18 + code.length + 8 * handlerCount; 152.2119 - if(localVar != null) 152.2120 - { 152.2121 - cw.newUTF8("LocalVariableTable"); 152.2122 - size += 8 + localVar.length; 152.2123 - } 152.2124 - if(localVarType != null) 152.2125 - { 152.2126 - cw.newUTF8("LocalVariableTypeTable"); 152.2127 - size += 8 + localVarType.length; 152.2128 - } 152.2129 - if(lineNumber != null) 152.2130 - { 152.2131 - cw.newUTF8("LineNumberTable"); 152.2132 - size += 8 + lineNumber.length; 152.2133 - } 152.2134 - if(stackMap != null) 152.2135 - { 152.2136 - boolean zip = (cw.version & 0xFFFF) >= Opcodes.V1_6; 152.2137 - cw.newUTF8(zip ? "StackMapTable" : "StackMap"); 152.2138 - size += 8 + stackMap.length; 152.2139 - } 152.2140 - if(cattrs != null) 152.2141 - { 152.2142 - size += cattrs.getSize(cw, 152.2143 - code.data, 152.2144 - code.length, 152.2145 - maxStack, 152.2146 - maxLocals); 152.2147 - } 152.2148 - } 152.2149 - if(exceptionCount > 0) 152.2150 - { 152.2151 - cw.newUTF8("Exceptions"); 152.2152 - size += 8 + 2 * exceptionCount; 152.2153 - } 152.2154 - if((access & Opcodes.ACC_SYNTHETIC) != 0 152.2155 - && (cw.version & 0xffff) < Opcodes.V1_5) 152.2156 - { 152.2157 - cw.newUTF8("Synthetic"); 152.2158 - size += 6; 152.2159 - } 152.2160 - if((access & Opcodes.ACC_DEPRECATED) != 0) 152.2161 - { 152.2162 - cw.newUTF8("Deprecated"); 152.2163 - size += 6; 152.2164 - } 152.2165 - if(signature != null) 152.2166 - { 152.2167 - cw.newUTF8("Signature"); 152.2168 - cw.newUTF8(signature); 152.2169 - size += 8; 152.2170 - } 152.2171 - if(annd != null) 152.2172 - { 152.2173 - cw.newUTF8("AnnotationDefault"); 152.2174 - size += 6 + annd.length; 152.2175 - } 152.2176 - if(anns != null) 152.2177 - { 152.2178 - cw.newUTF8("RuntimeVisibleAnnotations"); 152.2179 - size += 8 + anns.getSize(); 152.2180 - } 152.2181 - if(ianns != null) 152.2182 - { 152.2183 - cw.newUTF8("RuntimeInvisibleAnnotations"); 152.2184 - size += 8 + ianns.getSize(); 152.2185 - } 152.2186 - if(panns != null) 152.2187 - { 152.2188 - cw.newUTF8("RuntimeVisibleParameterAnnotations"); 152.2189 - size += 7 + 2 * panns.length; 152.2190 - for(int i = panns.length - 1; i >= 0; --i) 152.2191 - { 152.2192 - size += panns[i] == null ? 0 : panns[i].getSize(); 152.2193 - } 152.2194 - } 152.2195 - if(ipanns != null) 152.2196 - { 152.2197 - cw.newUTF8("RuntimeInvisibleParameterAnnotations"); 152.2198 - size += 7 + 2 * ipanns.length; 152.2199 - for(int i = ipanns.length - 1; i >= 0; --i) 152.2200 - { 152.2201 - size += ipanns[i] == null ? 0 : ipanns[i].getSize(); 152.2202 - } 152.2203 - } 152.2204 - if(attrs != null) 152.2205 - { 152.2206 - size += attrs.getSize(cw, null, 0, -1, -1); 152.2207 - } 152.2208 - return size; 152.2209 -} 152.2210 - 152.2211 -/** 152.2212 - * Puts the bytecode of this method in the given byte vector. 152.2213 - * 152.2214 - * @param out the byte vector into which the bytecode of this method must be 152.2215 - * copied. 152.2216 - */ 152.2217 -final void put(final ByteVector out){ 152.2218 - out.putShort(access).putShort(name).putShort(desc); 152.2219 - if(classReaderOffset != 0) 152.2220 - { 152.2221 - out.putByteArray(cw.cr.b, classReaderOffset, classReaderLength); 152.2222 - return; 152.2223 - } 152.2224 - int attributeCount = 0; 152.2225 - if(code.length > 0) 152.2226 - { 152.2227 - ++attributeCount; 152.2228 - } 152.2229 - if(exceptionCount > 0) 152.2230 - { 152.2231 - ++attributeCount; 152.2232 - } 152.2233 - if((access & Opcodes.ACC_SYNTHETIC) != 0 152.2234 - && (cw.version & 0xffff) < Opcodes.V1_5) 152.2235 - { 152.2236 - ++attributeCount; 152.2237 - } 152.2238 - if((access & Opcodes.ACC_DEPRECATED) != 0) 152.2239 - { 152.2240 - ++attributeCount; 152.2241 - } 152.2242 - if(signature != null) 152.2243 - { 152.2244 - ++attributeCount; 152.2245 - } 152.2246 - if(annd != null) 152.2247 - { 152.2248 - ++attributeCount; 152.2249 - } 152.2250 - if(anns != null) 152.2251 - { 152.2252 - ++attributeCount; 152.2253 - } 152.2254 - if(ianns != null) 152.2255 - { 152.2256 - ++attributeCount; 152.2257 - } 152.2258 - if(panns != null) 152.2259 - { 152.2260 - ++attributeCount; 152.2261 - } 152.2262 - if(ipanns != null) 152.2263 - { 152.2264 - ++attributeCount; 152.2265 - } 152.2266 - if(attrs != null) 152.2267 - { 152.2268 - attributeCount += attrs.getCount(); 152.2269 - } 152.2270 - out.putShort(attributeCount); 152.2271 - if(code.length > 0) 152.2272 - { 152.2273 - int size = 12 + code.length + 8 * handlerCount; 152.2274 - if(localVar != null) 152.2275 - { 152.2276 - size += 8 + localVar.length; 152.2277 - } 152.2278 - if(localVarType != null) 152.2279 - { 152.2280 - size += 8 + localVarType.length; 152.2281 - } 152.2282 - if(lineNumber != null) 152.2283 - { 152.2284 - size += 8 + lineNumber.length; 152.2285 - } 152.2286 - if(stackMap != null) 152.2287 - { 152.2288 - size += 8 + stackMap.length; 152.2289 - } 152.2290 - if(cattrs != null) 152.2291 - { 152.2292 - size += cattrs.getSize(cw, 152.2293 - code.data, 152.2294 - code.length, 152.2295 - maxStack, 152.2296 - maxLocals); 152.2297 - } 152.2298 - out.putShort(cw.newUTF8("Code")).putInt(size); 152.2299 - out.putShort(maxStack).putShort(maxLocals); 152.2300 - out.putInt(code.length).putByteArray(code.data, 0, code.length); 152.2301 - out.putShort(handlerCount); 152.2302 - if(handlerCount > 0) 152.2303 - { 152.2304 - Handler h = firstHandler; 152.2305 - while(h != null) 152.2306 - { 152.2307 - out.putShort(h.start.position) 152.2308 - .putShort(h.end.position) 152.2309 - .putShort(h.handler.position) 152.2310 - .putShort(h.type); 152.2311 - h = h.next; 152.2312 - } 152.2313 - } 152.2314 - attributeCount = 0; 152.2315 - if(localVar != null) 152.2316 - { 152.2317 - ++attributeCount; 152.2318 - } 152.2319 - if(localVarType != null) 152.2320 - { 152.2321 - ++attributeCount; 152.2322 - } 152.2323 - if(lineNumber != null) 152.2324 - { 152.2325 - ++attributeCount; 152.2326 - } 152.2327 - if(stackMap != null) 152.2328 - { 152.2329 - ++attributeCount; 152.2330 - } 152.2331 - if(cattrs != null) 152.2332 - { 152.2333 - attributeCount += cattrs.getCount(); 152.2334 - } 152.2335 - out.putShort(attributeCount); 152.2336 - if(localVar != null) 152.2337 - { 152.2338 - out.putShort(cw.newUTF8("LocalVariableTable")); 152.2339 - out.putInt(localVar.length + 2).putShort(localVarCount); 152.2340 - out.putByteArray(localVar.data, 0, localVar.length); 152.2341 - } 152.2342 - if(localVarType != null) 152.2343 - { 152.2344 - out.putShort(cw.newUTF8("LocalVariableTypeTable")); 152.2345 - out.putInt(localVarType.length + 2).putShort(localVarTypeCount); 152.2346 - out.putByteArray(localVarType.data, 0, localVarType.length); 152.2347 - } 152.2348 - if(lineNumber != null) 152.2349 - { 152.2350 - out.putShort(cw.newUTF8("LineNumberTable")); 152.2351 - out.putInt(lineNumber.length + 2).putShort(lineNumberCount); 152.2352 - out.putByteArray(lineNumber.data, 0, lineNumber.length); 152.2353 - } 152.2354 - if(stackMap != null) 152.2355 - { 152.2356 - boolean zip = (cw.version & 0xFFFF) >= Opcodes.V1_6; 152.2357 - out.putShort(cw.newUTF8(zip ? "StackMapTable" : "StackMap")); 152.2358 - out.putInt(stackMap.length + 2).putShort(frameCount); 152.2359 - out.putByteArray(stackMap.data, 0, stackMap.length); 152.2360 - } 152.2361 - if(cattrs != null) 152.2362 - { 152.2363 - cattrs.put(cw, code.data, code.length, maxLocals, maxStack, out); 152.2364 - } 152.2365 - } 152.2366 - if(exceptionCount > 0) 152.2367 - { 152.2368 - out.putShort(cw.newUTF8("Exceptions")) 152.2369 - .putInt(2 * exceptionCount + 2); 152.2370 - out.putShort(exceptionCount); 152.2371 - for(int i = 0; i < exceptionCount; ++i) 152.2372 - { 152.2373 - out.putShort(exceptions[i]); 152.2374 - } 152.2375 - } 152.2376 - if((access & Opcodes.ACC_SYNTHETIC) != 0 152.2377 - && (cw.version & 0xffff) < Opcodes.V1_5) 152.2378 - { 152.2379 - out.putShort(cw.newUTF8("Synthetic")).putInt(0); 152.2380 - } 152.2381 - if((access & Opcodes.ACC_DEPRECATED) != 0) 152.2382 - { 152.2383 - out.putShort(cw.newUTF8("Deprecated")).putInt(0); 152.2384 - } 152.2385 - if(signature != null) 152.2386 - { 152.2387 - out.putShort(cw.newUTF8("Signature")) 152.2388 - .putInt(2) 152.2389 - .putShort(cw.newUTF8(signature)); 152.2390 - } 152.2391 - if(annd != null) 152.2392 - { 152.2393 - out.putShort(cw.newUTF8("AnnotationDefault")); 152.2394 - out.putInt(annd.length); 152.2395 - out.putByteArray(annd.data, 0, annd.length); 152.2396 - } 152.2397 - if(anns != null) 152.2398 - { 152.2399 - out.putShort(cw.newUTF8("RuntimeVisibleAnnotations")); 152.2400 - anns.put(out); 152.2401 - } 152.2402 - if(ianns != null) 152.2403 - { 152.2404 - out.putShort(cw.newUTF8("RuntimeInvisibleAnnotations")); 152.2405 - ianns.put(out); 152.2406 - } 152.2407 - if(panns != null) 152.2408 - { 152.2409 - out.putShort(cw.newUTF8("RuntimeVisibleParameterAnnotations")); 152.2410 - AnnotationWriter.put(panns, out); 152.2411 - } 152.2412 - if(ipanns != null) 152.2413 - { 152.2414 - out.putShort(cw.newUTF8("RuntimeInvisibleParameterAnnotations")); 152.2415 - AnnotationWriter.put(ipanns, out); 152.2416 - } 152.2417 - if(attrs != null) 152.2418 - { 152.2419 - attrs.put(cw, null, 0, -1, -1, out); 152.2420 - } 152.2421 -} 152.2422 - 152.2423 -// ------------------------------------------------------------------------ 152.2424 -// Utility methods: instruction resizing (used to handle GOTO_W and JSR_W) 152.2425 -// ------------------------------------------------------------------------ 152.2426 - 152.2427 -/** 152.2428 - * Resizes and replaces the temporary instructions inserted by 152.2429 - * {@link Label#resolve} for wide forward jumps, while keeping jump offsets 152.2430 - * and instruction addresses consistent. This may require to resize other 152.2431 - * existing instructions, or even to introduce new instructions: for 152.2432 - * example, increasing the size of an instruction by 2 at the middle of a 152.2433 - * method can increases the offset of an IFEQ instruction from 32766 to 152.2434 - * 32768, in which case IFEQ 32766 must be replaced with IFNEQ 8 GOTO_W 152.2435 - * 32765. This, in turn, may require to increase the size of another jump 152.2436 - * instruction, and so on... All these operations are handled automatically 152.2437 - * by this method. <p> <i>This method must be called after all the method 152.2438 - * that is being built has been visited</i>. In particular, the 152.2439 - * {@link Label Label} objects used to construct the method are no longer 152.2440 - * valid after this method has been called. 152.2441 - */ 152.2442 -private void resizeInstructions(){ 152.2443 - byte[] b = code.data; // bytecode of the method 152.2444 - int u, v, label; // indexes in b 152.2445 - int i, j; // loop indexes 152.2446 - /* 152.2447 - * 1st step: As explained above, resizing an instruction may require to 152.2448 - * resize another one, which may require to resize yet another one, and 152.2449 - * so on. The first step of the algorithm consists in finding all the 152.2450 - * instructions that need to be resized, without modifying the code. 152.2451 - * This is done by the following "fix point" algorithm: 152.2452 - * 152.2453 - * Parse the code to find the jump instructions whose offset will need 152.2454 - * more than 2 bytes to be stored (the future offset is computed from 152.2455 - * the current offset and from the number of bytes that will be inserted 152.2456 - * or removed between the source and target instructions). For each such 152.2457 - * instruction, adds an entry in (a copy of) the indexes and sizes 152.2458 - * arrays (if this has not already been done in a previous iteration!). 152.2459 - * 152.2460 - * If at least one entry has been added during the previous step, go 152.2461 - * back to the beginning, otherwise stop. 152.2462 - * 152.2463 - * In fact the real algorithm is complicated by the fact that the size 152.2464 - * of TABLESWITCH and LOOKUPSWITCH instructions depends on their 152.2465 - * position in the bytecode (because of padding). In order to ensure the 152.2466 - * convergence of the algorithm, the number of bytes to be added or 152.2467 - * removed from these instructions is over estimated during the previous 152.2468 - * loop, and computed exactly only after the loop is finished (this 152.2469 - * requires another pass to parse the bytecode of the method). 152.2470 - */ 152.2471 - int[] allIndexes = new int[0]; // copy of indexes 152.2472 - int[] allSizes = new int[0]; // copy of sizes 152.2473 - boolean[] resize; // instructions to be resized 152.2474 - int newOffset; // future offset of a jump instruction 152.2475 - 152.2476 - resize = new boolean[code.length]; 152.2477 - 152.2478 - // 3 = loop again, 2 = loop ended, 1 = last pass, 0 = done 152.2479 - int state = 3; 152.2480 - do 152.2481 - { 152.2482 - if(state == 3) 152.2483 - { 152.2484 - state = 2; 152.2485 - } 152.2486 - u = 0; 152.2487 - while(u < b.length) 152.2488 - { 152.2489 - int opcode = b[u] & 0xFF; // opcode of current instruction 152.2490 - int insert = 0; // bytes to be added after this instruction 152.2491 - 152.2492 - switch(ClassWriter.TYPE[opcode]) 152.2493 - { 152.2494 - case ClassWriter.NOARG_INSN: 152.2495 - case ClassWriter.IMPLVAR_INSN: 152.2496 - u += 1; 152.2497 - break; 152.2498 - case ClassWriter.LABEL_INSN: 152.2499 - if(opcode > 201) 152.2500 - { 152.2501 - // converts temporary opcodes 202 to 217, 218 and 152.2502 - // 219 to IFEQ ... JSR (inclusive), IFNULL and 152.2503 - // IFNONNULL 152.2504 - opcode = opcode < 218 ? opcode - 49 : opcode - 20; 152.2505 - label = u + readUnsignedShort(b, u + 1); 152.2506 - } 152.2507 - else 152.2508 - { 152.2509 - label = u + readShort(b, u + 1); 152.2510 - } 152.2511 - newOffset = getNewOffset(allIndexes, allSizes, u, label); 152.2512 - if(newOffset < Short.MIN_VALUE 152.2513 - || newOffset > Short.MAX_VALUE) 152.2514 - { 152.2515 - if(!resize[u]) 152.2516 - { 152.2517 - if(opcode == Opcodes.GOTO 152.2518 - || opcode == Opcodes.JSR) 152.2519 - { 152.2520 - // two additional bytes will be required to 152.2521 - // replace this GOTO or JSR instruction with 152.2522 - // a GOTO_W or a JSR_W 152.2523 - insert = 2; 152.2524 - } 152.2525 - else 152.2526 - { 152.2527 - // five additional bytes will be required to 152.2528 - // replace this IFxxx <l> instruction with 152.2529 - // IFNOTxxx <l'> GOTO_W <l>, where IFNOTxxx 152.2530 - // is the "opposite" opcode of IFxxx (i.e., 152.2531 - // IFNE for IFEQ) and where <l'> designates 152.2532 - // the instruction just after the GOTO_W. 152.2533 - insert = 5; 152.2534 - } 152.2535 - resize[u] = true; 152.2536 - } 152.2537 - } 152.2538 - u += 3; 152.2539 - break; 152.2540 - case ClassWriter.LABELW_INSN: 152.2541 - u += 5; 152.2542 - break; 152.2543 - case ClassWriter.TABL_INSN: 152.2544 - if(state == 1) 152.2545 - { 152.2546 - // true number of bytes to be added (or removed) 152.2547 - // from this instruction = (future number of padding 152.2548 - // bytes - current number of padding byte) - 152.2549 - // previously over estimated variation = 152.2550 - // = ((3 - newOffset%4) - (3 - u%4)) - u%4 152.2551 - // = (-newOffset%4 + u%4) - u%4 152.2552 - // = -(newOffset & 3) 152.2553 - newOffset = getNewOffset(allIndexes, allSizes, 0, u); 152.2554 - insert = -(newOffset & 3); 152.2555 - } 152.2556 - else if(!resize[u]) 152.2557 - { 152.2558 - // over estimation of the number of bytes to be 152.2559 - // added to this instruction = 3 - current number 152.2560 - // of padding bytes = 3 - (3 - u%4) = u%4 = u & 3 152.2561 - insert = u & 3; 152.2562 - resize[u] = true; 152.2563 - } 152.2564 - // skips instruction 152.2565 - u = u + 4 - (u & 3); 152.2566 - u += 4 * (readInt(b, u + 8) - readInt(b, u + 4) + 1) + 12; 152.2567 - break; 152.2568 - case ClassWriter.LOOK_INSN: 152.2569 - if(state == 1) 152.2570 - { 152.2571 - // like TABL_INSN 152.2572 - newOffset = getNewOffset(allIndexes, allSizes, 0, u); 152.2573 - insert = -(newOffset & 3); 152.2574 - } 152.2575 - else if(!resize[u]) 152.2576 - { 152.2577 - // like TABL_INSN 152.2578 - insert = u & 3; 152.2579 - resize[u] = true; 152.2580 - } 152.2581 - // skips instruction 152.2582 - u = u + 4 - (u & 3); 152.2583 - u += 8 * readInt(b, u + 4) + 8; 152.2584 - break; 152.2585 - case ClassWriter.WIDE_INSN: 152.2586 - opcode = b[u + 1] & 0xFF; 152.2587 - if(opcode == Opcodes.IINC) 152.2588 - { 152.2589 - u += 6; 152.2590 - } 152.2591 - else 152.2592 - { 152.2593 - u += 4; 152.2594 - } 152.2595 - break; 152.2596 - case ClassWriter.VAR_INSN: 152.2597 - case ClassWriter.SBYTE_INSN: 152.2598 - case ClassWriter.LDC_INSN: 152.2599 - u += 2; 152.2600 - break; 152.2601 - case ClassWriter.SHORT_INSN: 152.2602 - case ClassWriter.LDCW_INSN: 152.2603 - case ClassWriter.FIELDORMETH_INSN: 152.2604 - case ClassWriter.TYPE_INSN: 152.2605 - case ClassWriter.IINC_INSN: 152.2606 - u += 3; 152.2607 - break; 152.2608 - case ClassWriter.ITFMETH_INSN: 152.2609 - u += 5; 152.2610 - break; 152.2611 - // case ClassWriter.MANA_INSN: 152.2612 - default: 152.2613 - u += 4; 152.2614 - break; 152.2615 - } 152.2616 - if(insert != 0) 152.2617 - { 152.2618 - // adds a new (u, insert) entry in the allIndexes and 152.2619 - // allSizes arrays 152.2620 - int[] newIndexes = new int[allIndexes.length + 1]; 152.2621 - int[] newSizes = new int[allSizes.length + 1]; 152.2622 - System.arraycopy(allIndexes, 152.2623 - 0, 152.2624 - newIndexes, 152.2625 - 0, 152.2626 - allIndexes.length); 152.2627 - System.arraycopy(allSizes, 0, newSizes, 0, allSizes.length); 152.2628 - newIndexes[allIndexes.length] = u; 152.2629 - newSizes[allSizes.length] = insert; 152.2630 - allIndexes = newIndexes; 152.2631 - allSizes = newSizes; 152.2632 - if(insert > 0) 152.2633 - { 152.2634 - state = 3; 152.2635 - } 152.2636 - } 152.2637 - } 152.2638 - if(state < 3) 152.2639 - { 152.2640 - --state; 152.2641 - } 152.2642 - } while(state != 0); 152.2643 - 152.2644 - // 2nd step: 152.2645 - // copies the bytecode of the method into a new bytevector, updates the 152.2646 - // offsets, and inserts (or removes) bytes as requested. 152.2647 - 152.2648 - ByteVector newCode = new ByteVector(code.length); 152.2649 - 152.2650 - u = 0; 152.2651 - while(u < code.length) 152.2652 - { 152.2653 - int opcode = b[u] & 0xFF; 152.2654 - switch(ClassWriter.TYPE[opcode]) 152.2655 - { 152.2656 - case ClassWriter.NOARG_INSN: 152.2657 - case ClassWriter.IMPLVAR_INSN: 152.2658 - newCode.putByte(opcode); 152.2659 - u += 1; 152.2660 - break; 152.2661 - case ClassWriter.LABEL_INSN: 152.2662 - if(opcode > 201) 152.2663 - { 152.2664 - // changes temporary opcodes 202 to 217 (inclusive), 218 152.2665 - // and 219 to IFEQ ... JSR (inclusive), IFNULL and 152.2666 - // IFNONNULL 152.2667 - opcode = opcode < 218 ? opcode - 49 : opcode - 20; 152.2668 - label = u + readUnsignedShort(b, u + 1); 152.2669 - } 152.2670 - else 152.2671 - { 152.2672 - label = u + readShort(b, u + 1); 152.2673 - } 152.2674 - newOffset = getNewOffset(allIndexes, allSizes, u, label); 152.2675 - if(resize[u]) 152.2676 - { 152.2677 - // replaces GOTO with GOTO_W, JSR with JSR_W and IFxxx 152.2678 - // <l> with IFNOTxxx <l'> GOTO_W <l>, where IFNOTxxx is 152.2679 - // the "opposite" opcode of IFxxx (i.e., IFNE for IFEQ) 152.2680 - // and where <l'> designates the instruction just after 152.2681 - // the GOTO_W. 152.2682 - if(opcode == Opcodes.GOTO) 152.2683 - { 152.2684 - newCode.putByte(200); // GOTO_W 152.2685 - } 152.2686 - else if(opcode == Opcodes.JSR) 152.2687 - { 152.2688 - newCode.putByte(201); // JSR_W 152.2689 - } 152.2690 - else 152.2691 - { 152.2692 - newCode.putByte(opcode <= 166 152.2693 - ? ((opcode + 1) ^ 1) - 1 152.2694 - : opcode ^ 1); 152.2695 - newCode.putShort(8); // jump offset 152.2696 - newCode.putByte(200); // GOTO_W 152.2697 - // newOffset now computed from start of GOTO_W 152.2698 - newOffset -= 3; 152.2699 - } 152.2700 - newCode.putInt(newOffset); 152.2701 - } 152.2702 - else 152.2703 - { 152.2704 - newCode.putByte(opcode); 152.2705 - newCode.putShort(newOffset); 152.2706 - } 152.2707 - u += 3; 152.2708 - break; 152.2709 - case ClassWriter.LABELW_INSN: 152.2710 - label = u + readInt(b, u + 1); 152.2711 - newOffset = getNewOffset(allIndexes, allSizes, u, label); 152.2712 - newCode.putByte(opcode); 152.2713 - newCode.putInt(newOffset); 152.2714 - u += 5; 152.2715 - break; 152.2716 - case ClassWriter.TABL_INSN: 152.2717 - // skips 0 to 3 padding bytes 152.2718 - v = u; 152.2719 - u = u + 4 - (v & 3); 152.2720 - // reads and copies instruction 152.2721 - newCode.putByte(Opcodes.TABLESWITCH); 152.2722 - newCode.length += (4 - newCode.length % 4) % 4; 152.2723 - label = v + readInt(b, u); 152.2724 - u += 4; 152.2725 - newOffset = getNewOffset(allIndexes, allSizes, v, label); 152.2726 - newCode.putInt(newOffset); 152.2727 - j = readInt(b, u); 152.2728 - u += 4; 152.2729 - newCode.putInt(j); 152.2730 - j = readInt(b, u) - j + 1; 152.2731 - u += 4; 152.2732 - newCode.putInt(readInt(b, u - 4)); 152.2733 - for(; j > 0; --j) 152.2734 - { 152.2735 - label = v + readInt(b, u); 152.2736 - u += 4; 152.2737 - newOffset = getNewOffset(allIndexes, allSizes, v, label); 152.2738 - newCode.putInt(newOffset); 152.2739 - } 152.2740 - break; 152.2741 - case ClassWriter.LOOK_INSN: 152.2742 - // skips 0 to 3 padding bytes 152.2743 - v = u; 152.2744 - u = u + 4 - (v & 3); 152.2745 - // reads and copies instruction 152.2746 - newCode.putByte(Opcodes.LOOKUPSWITCH); 152.2747 - newCode.length += (4 - newCode.length % 4) % 4; 152.2748 - label = v + readInt(b, u); 152.2749 - u += 4; 152.2750 - newOffset = getNewOffset(allIndexes, allSizes, v, label); 152.2751 - newCode.putInt(newOffset); 152.2752 - j = readInt(b, u); 152.2753 - u += 4; 152.2754 - newCode.putInt(j); 152.2755 - for(; j > 0; --j) 152.2756 - { 152.2757 - newCode.putInt(readInt(b, u)); 152.2758 - u += 4; 152.2759 - label = v + readInt(b, u); 152.2760 - u += 4; 152.2761 - newOffset = getNewOffset(allIndexes, allSizes, v, label); 152.2762 - newCode.putInt(newOffset); 152.2763 - } 152.2764 - break; 152.2765 - case ClassWriter.WIDE_INSN: 152.2766 - opcode = b[u + 1] & 0xFF; 152.2767 - if(opcode == Opcodes.IINC) 152.2768 - { 152.2769 - newCode.putByteArray(b, u, 6); 152.2770 - u += 6; 152.2771 - } 152.2772 - else 152.2773 - { 152.2774 - newCode.putByteArray(b, u, 4); 152.2775 - u += 4; 152.2776 - } 152.2777 - break; 152.2778 - case ClassWriter.VAR_INSN: 152.2779 - case ClassWriter.SBYTE_INSN: 152.2780 - case ClassWriter.LDC_INSN: 152.2781 - newCode.putByteArray(b, u, 2); 152.2782 - u += 2; 152.2783 - break; 152.2784 - case ClassWriter.SHORT_INSN: 152.2785 - case ClassWriter.LDCW_INSN: 152.2786 - case ClassWriter.FIELDORMETH_INSN: 152.2787 - case ClassWriter.TYPE_INSN: 152.2788 - case ClassWriter.IINC_INSN: 152.2789 - newCode.putByteArray(b, u, 3); 152.2790 - u += 3; 152.2791 - break; 152.2792 - case ClassWriter.ITFMETH_INSN: 152.2793 - newCode.putByteArray(b, u, 5); 152.2794 - u += 5; 152.2795 - break; 152.2796 - // case MANA_INSN: 152.2797 - default: 152.2798 - newCode.putByteArray(b, u, 4); 152.2799 - u += 4; 152.2800 - break; 152.2801 - } 152.2802 - } 152.2803 - 152.2804 - // recomputes the stack map frames 152.2805 - if(frameCount > 0) 152.2806 - { 152.2807 - if(compute == FRAMES) 152.2808 - { 152.2809 - frameCount = 0; 152.2810 - stackMap = null; 152.2811 - previousFrame = null; 152.2812 - frame = null; 152.2813 - Frame f = new Frame(); 152.2814 - f.owner = labels; 152.2815 - Type[] args = Type.getArgumentTypes(descriptor); 152.2816 - f.initInputFrame(cw, access, args, maxLocals); 152.2817 - visitFrame(f); 152.2818 - Label l = labels; 152.2819 - while(l != null) 152.2820 - { 152.2821 - /* 152.2822 - * here we need the original label position. getNewOffset 152.2823 - * must therefore never have been called for this label. 152.2824 - */ 152.2825 - u = l.position - 3; 152.2826 - if((l.status & Label.STORE) != 0 || (u >= 0 && resize[u])) 152.2827 - { 152.2828 - getNewOffset(allIndexes, allSizes, l); 152.2829 - // TODO update offsets in UNINITIALIZED values 152.2830 - visitFrame(l.frame); 152.2831 - } 152.2832 - l = l.successor; 152.2833 - } 152.2834 - } 152.2835 - else 152.2836 - { 152.2837 - /* 152.2838 - * Resizing an existing stack map frame table is really hard. 152.2839 - * Not only the table must be parsed to update the offets, but 152.2840 - * new frames may be needed for jump instructions that were 152.2841 - * inserted by this method. And updating the offsets or 152.2842 - * inserting frames can change the format of the following 152.2843 - * frames, in case of packed frames. In practice the whole table 152.2844 - * must be recomputed. For this the frames are marked as 152.2845 - * potentially invalid. This will cause the whole class to be 152.2846 - * reread and rewritten with the COMPUTE_FRAMES option (see the 152.2847 - * ClassWriter.toByteArray method). This is not very efficient 152.2848 - * but is much easier and requires much less code than any other 152.2849 - * method I can think of. 152.2850 - */ 152.2851 - cw.invalidFrames = true; 152.2852 - } 152.2853 - } 152.2854 - // updates the exception handler block labels 152.2855 - Handler h = firstHandler; 152.2856 - while(h != null) 152.2857 - { 152.2858 - getNewOffset(allIndexes, allSizes, h.start); 152.2859 - getNewOffset(allIndexes, allSizes, h.end); 152.2860 - getNewOffset(allIndexes, allSizes, h.handler); 152.2861 - h = h.next; 152.2862 - } 152.2863 - // updates the instructions addresses in the 152.2864 - // local var and line number tables 152.2865 - for(i = 0; i < 2; ++i) 152.2866 - { 152.2867 - ByteVector bv = i == 0 ? localVar : localVarType; 152.2868 - if(bv != null) 152.2869 - { 152.2870 - b = bv.data; 152.2871 - u = 0; 152.2872 - while(u < bv.length) 152.2873 - { 152.2874 - label = readUnsignedShort(b, u); 152.2875 - newOffset = getNewOffset(allIndexes, allSizes, 0, label); 152.2876 - writeShort(b, u, newOffset); 152.2877 - label += readUnsignedShort(b, u + 2); 152.2878 - newOffset = getNewOffset(allIndexes, allSizes, 0, label) 152.2879 - - newOffset; 152.2880 - writeShort(b, u + 2, newOffset); 152.2881 - u += 10; 152.2882 - } 152.2883 - } 152.2884 - } 152.2885 - if(lineNumber != null) 152.2886 - { 152.2887 - b = lineNumber.data; 152.2888 - u = 0; 152.2889 - while(u < lineNumber.length) 152.2890 - { 152.2891 - writeShort(b, u, getNewOffset(allIndexes, 152.2892 - allSizes, 152.2893 - 0, 152.2894 - readUnsignedShort(b, u))); 152.2895 - u += 4; 152.2896 - } 152.2897 - } 152.2898 - // updates the labels of the other attributes 152.2899 - Attribute attr = cattrs; 152.2900 - while(attr != null) 152.2901 - { 152.2902 - Label[] labels = attr.getLabels(); 152.2903 - if(labels != null) 152.2904 - { 152.2905 - for(i = labels.length - 1; i >= 0; --i) 152.2906 - { 152.2907 - getNewOffset(allIndexes, allSizes, labels[i]); 152.2908 - } 152.2909 - } 152.2910 - attr = attr.next; 152.2911 - } 152.2912 - 152.2913 - // replaces old bytecodes with new ones 152.2914 - code = newCode; 152.2915 -} 152.2916 - 152.2917 -/** 152.2918 - * Reads an unsigned short value in the given byte array. 152.2919 - * 152.2920 - * @param b a byte array. 152.2921 - * @param index the start index of the value to be read. 152.2922 - * @return the read value. 152.2923 - */ 152.2924 -static int readUnsignedShort(final byte[] b, final int index){ 152.2925 - return ((b[index] & 0xFF) << 8) | (b[index + 1] & 0xFF); 152.2926 -} 152.2927 - 152.2928 -/** 152.2929 - * Reads a signed short value in the given byte array. 152.2930 - * 152.2931 - * @param b a byte array. 152.2932 - * @param index the start index of the value to be read. 152.2933 - * @return the read value. 152.2934 - */ 152.2935 -static short readShort(final byte[] b, final int index){ 152.2936 - return (short) (((b[index] & 0xFF) << 8) | (b[index + 1] & 0xFF)); 152.2937 -} 152.2938 - 152.2939 -/** 152.2940 - * Reads a signed int value in the given byte array. 152.2941 - * 152.2942 - * @param b a byte array. 152.2943 - * @param index the start index of the value to be read. 152.2944 - * @return the read value. 152.2945 - */ 152.2946 -static int readInt(final byte[] b, final int index){ 152.2947 - return ((b[index] & 0xFF) << 24) | ((b[index + 1] & 0xFF) << 16) 152.2948 - | ((b[index + 2] & 0xFF) << 8) | (b[index + 3] & 0xFF); 152.2949 -} 152.2950 - 152.2951 -/** 152.2952 - * Writes a short value in the given byte array. 152.2953 - * 152.2954 - * @param b a byte array. 152.2955 - * @param index where the first byte of the short value must be written. 152.2956 - * @param s the value to be written in the given byte array. 152.2957 - */ 152.2958 -static void writeShort(final byte[] b, final int index, final int s){ 152.2959 - b[index] = (byte) (s >>> 8); 152.2960 - b[index + 1] = (byte) s; 152.2961 -} 152.2962 - 152.2963 -/** 152.2964 - * Computes the future value of a bytecode offset. <p> Note: it is possible 152.2965 - * to have several entries for the same instruction in the <tt>indexes</tt> 152.2966 - * and <tt>sizes</tt>: two entries (index=a,size=b) and (index=a,size=b') 152.2967 - * are equivalent to a single entry (index=a,size=b+b'). 152.2968 - * 152.2969 - * @param indexes current positions of the instructions to be resized. Each 152.2970 - * instruction must be designated by the index of its <i>last</i> 152.2971 - * byte, plus one (or, in other words, by the index of the <i>first</i> 152.2972 - * byte of the <i>next</i> instruction). 152.2973 - * @param sizes the number of bytes to be <i>added</i> to the above 152.2974 - * instructions. More precisely, for each i < <tt>len</tt>, 152.2975 - * <tt>sizes</tt>[i] bytes will be added at the end of the 152.2976 - * instruction designated by <tt>indexes</tt>[i] or, if 152.2977 - * <tt>sizes</tt>[i] is negative, the <i>last</i> |<tt>sizes[i]</tt>| 152.2978 - * bytes of the instruction will be removed (the instruction size 152.2979 - * <i>must not</i> become negative or null). 152.2980 - * @param begin index of the first byte of the source instruction. 152.2981 - * @param end index of the first byte of the target instruction. 152.2982 - * @return the future value of the given bytecode offset. 152.2983 - */ 152.2984 -static int getNewOffset( 152.2985 - final int[] indexes, 152.2986 - final int[] sizes, 152.2987 - final int begin, 152.2988 - final int end){ 152.2989 - int offset = end - begin; 152.2990 - for(int i = 0; i < indexes.length; ++i) 152.2991 - { 152.2992 - if(begin < indexes[i] && indexes[i] <= end) 152.2993 - { 152.2994 - // forward jump 152.2995 - offset += sizes[i]; 152.2996 - } 152.2997 - else if(end < indexes[i] && indexes[i] <= begin) 152.2998 - { 152.2999 - // backward jump 152.3000 - offset -= sizes[i]; 152.3001 - } 152.3002 - } 152.3003 - return offset; 152.3004 -} 152.3005 - 152.3006 -/** 152.3007 - * Updates the offset of the given label. 152.3008 - * 152.3009 - * @param indexes current positions of the instructions to be resized. Each 152.3010 - * instruction must be designated by the index of its <i>last</i> 152.3011 - * byte, plus one (or, in other words, by the index of the <i>first</i> 152.3012 - * byte of the <i>next</i> instruction). 152.3013 - * @param sizes the number of bytes to be <i>added</i> to the above 152.3014 - * instructions. More precisely, for each i < <tt>len</tt>, 152.3015 - * <tt>sizes</tt>[i] bytes will be added at the end of the 152.3016 - * instruction designated by <tt>indexes</tt>[i] or, if 152.3017 - * <tt>sizes</tt>[i] is negative, the <i>last</i> |<tt>sizes[i]</tt>| 152.3018 - * bytes of the instruction will be removed (the instruction size 152.3019 - * <i>must not</i> become negative or null). 152.3020 - * @param label the label whose offset must be updated. 152.3021 - */ 152.3022 -static void getNewOffset( 152.3023 - final int[] indexes, 152.3024 - final int[] sizes, 152.3025 - final Label label){ 152.3026 - if((label.status & Label.RESIZED) == 0) 152.3027 - { 152.3028 - label.position = getNewOffset(indexes, sizes, 0, label.position); 152.3029 - label.status |= Label.RESIZED; 152.3030 - } 152.3031 -} 152.3032 -}
153.1 --- a/src/clojure/asm/Opcodes.java Sat Aug 21 06:25:44 2010 -0400 153.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 153.3 @@ -1,341 +0,0 @@ 153.4 -/*** 153.5 - * ASM: a very small and fast Java bytecode manipulation framework 153.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 153.7 - * All rights reserved. 153.8 - * 153.9 - * Redistribution and use in source and binary forms, with or without 153.10 - * modification, are permitted provided that the following conditions 153.11 - * are met: 153.12 - * 1. Redistributions of source code must retain the above copyright 153.13 - * notice, this list of conditions and the following disclaimer. 153.14 - * 2. Redistributions in binary form must reproduce the above copyright 153.15 - * notice, this list of conditions and the following disclaimer in the 153.16 - * documentation and/or other materials provided with the distribution. 153.17 - * 3. Neither the name of the copyright holders nor the names of its 153.18 - * contributors may be used to endorse or promote products derived from 153.19 - * this software without specific prior written permission. 153.20 - * 153.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 153.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 153.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 153.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 153.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 153.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 153.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 153.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 153.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 153.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 153.31 - * THE POSSIBILITY OF SUCH DAMAGE. 153.32 - */ 153.33 -package clojure.asm; 153.34 - 153.35 -/** 153.36 - * Defines the JVM opcodes, access flags and array type codes. This interface 153.37 - * does not define all the JVM opcodes because some opcodes are automatically 153.38 - * handled. For example, the xLOAD and xSTORE opcodes are automatically replaced 153.39 - * by xLOAD_n and xSTORE_n opcodes when possible. The xLOAD_n and xSTORE_n 153.40 - * opcodes are therefore not defined in this interface. Likewise for LDC, 153.41 - * automatically replaced by LDC_W or LDC2_W when necessary, WIDE, GOTO_W and 153.42 - * JSR_W. 153.43 - * 153.44 - * @author Eric Bruneton 153.45 - * @author Eugene Kuleshov 153.46 - */ 153.47 -public interface Opcodes{ 153.48 - 153.49 -// versions 153.50 - 153.51 -int V1_1 = 3 << 16 | 45; 153.52 -int V1_2 = 0 << 16 | 46; 153.53 -int V1_3 = 0 << 16 | 47; 153.54 -int V1_4 = 0 << 16 | 48; 153.55 -int V1_5 = 0 << 16 | 49; 153.56 -int V1_6 = 0 << 16 | 50; 153.57 - 153.58 -// access flags 153.59 - 153.60 -int ACC_PUBLIC = 0x0001; // class, field, method 153.61 -int ACC_PRIVATE = 0x0002; // class, field, method 153.62 -int ACC_PROTECTED = 0x0004; // class, field, method 153.63 -int ACC_STATIC = 0x0008; // field, method 153.64 -int ACC_FINAL = 0x0010; // class, field, method 153.65 -int ACC_SUPER = 0x0020; // class 153.66 -int ACC_SYNCHRONIZED = 0x0020; // method 153.67 -int ACC_VOLATILE = 0x0040; // field 153.68 -int ACC_BRIDGE = 0x0040; // method 153.69 -int ACC_VARARGS = 0x0080; // method 153.70 -int ACC_TRANSIENT = 0x0080; // field 153.71 -int ACC_NATIVE = 0x0100; // method 153.72 -int ACC_INTERFACE = 0x0200; // class 153.73 -int ACC_ABSTRACT = 0x0400; // class, method 153.74 -int ACC_STRICT = 0x0800; // method 153.75 -int ACC_SYNTHETIC = 0x1000; // class, field, method 153.76 -int ACC_ANNOTATION = 0x2000; // class 153.77 -int ACC_ENUM = 0x4000; // class(?) field inner 153.78 - 153.79 -// ASM specific pseudo access flags 153.80 - 153.81 -int ACC_DEPRECATED = 131072; // class, field, method 153.82 - 153.83 -// types for NEWARRAY 153.84 - 153.85 -int T_BOOLEAN = 4; 153.86 -int T_CHAR = 5; 153.87 -int T_FLOAT = 6; 153.88 -int T_DOUBLE = 7; 153.89 -int T_BYTE = 8; 153.90 -int T_SHORT = 9; 153.91 -int T_INT = 10; 153.92 -int T_LONG = 11; 153.93 - 153.94 -// stack map frame types 153.95 - 153.96 -/** 153.97 - * Represents an expanded frame. See {@link ClassReader#EXPAND_FRAMES}. 153.98 - */ 153.99 -int F_NEW = -1; 153.100 - 153.101 -/** 153.102 - * Represents a compressed frame with complete frame data. 153.103 - */ 153.104 -int F_FULL = 0; 153.105 - 153.106 -/** 153.107 - * Represents a compressed frame where locals are the same as the locals in 153.108 - * the previous frame, except that additional 1-3 locals are defined, and 153.109 - * with an empty stack. 153.110 - */ 153.111 -int F_APPEND = 1; 153.112 - 153.113 -/** 153.114 - * Represents a compressed frame where locals are the same as the locals in 153.115 - * the previous frame, except that the last 1-3 locals are absent and with 153.116 - * an empty stack. 153.117 - */ 153.118 -int F_CHOP = 2; 153.119 - 153.120 -/** 153.121 - * Represents a compressed frame with exactly the same locals as the 153.122 - * previous frame and with an empty stack. 153.123 - */ 153.124 -int F_SAME = 3; 153.125 - 153.126 -/** 153.127 - * Represents a compressed frame with exactly the same locals as the 153.128 - * previous frame and with a single value on the stack. 153.129 - */ 153.130 -int F_SAME1 = 4; 153.131 - 153.132 -Integer TOP = new Integer(0); 153.133 -Integer INTEGER = new Integer(1); 153.134 -Integer FLOAT = new Integer(2); 153.135 -Integer DOUBLE = new Integer(3); 153.136 -Integer LONG = new Integer(4); 153.137 -Integer NULL = new Integer(5); 153.138 -Integer UNINITIALIZED_THIS = new Integer(6); 153.139 - 153.140 -// opcodes // visit method (- = idem) 153.141 - 153.142 -int NOP = 0; // visitInsn 153.143 -int ACONST_NULL = 1; // - 153.144 -int ICONST_M1 = 2; // - 153.145 -int ICONST_0 = 3; // - 153.146 -int ICONST_1 = 4; // - 153.147 -int ICONST_2 = 5; // - 153.148 -int ICONST_3 = 6; // - 153.149 -int ICONST_4 = 7; // - 153.150 -int ICONST_5 = 8; // - 153.151 -int LCONST_0 = 9; // - 153.152 -int LCONST_1 = 10; // - 153.153 -int FCONST_0 = 11; // - 153.154 -int FCONST_1 = 12; // - 153.155 -int FCONST_2 = 13; // - 153.156 -int DCONST_0 = 14; // - 153.157 -int DCONST_1 = 15; // - 153.158 -int BIPUSH = 16; // visitIntInsn 153.159 -int SIPUSH = 17; // - 153.160 -int LDC = 18; // visitLdcInsn 153.161 -// int LDC_W = 19; // - 153.162 -// int LDC2_W = 20; // - 153.163 -int ILOAD = 21; // visitVarInsn 153.164 -int LLOAD = 22; // - 153.165 -int FLOAD = 23; // - 153.166 -int DLOAD = 24; // - 153.167 -int ALOAD = 25; // - 153.168 -// int ILOAD_0 = 26; // - 153.169 -// int ILOAD_1 = 27; // - 153.170 -// int ILOAD_2 = 28; // - 153.171 -// int ILOAD_3 = 29; // - 153.172 -// int LLOAD_0 = 30; // - 153.173 -// int LLOAD_1 = 31; // - 153.174 -// int LLOAD_2 = 32; // - 153.175 -// int LLOAD_3 = 33; // - 153.176 -// int FLOAD_0 = 34; // - 153.177 -// int FLOAD_1 = 35; // - 153.178 -// int FLOAD_2 = 36; // - 153.179 -// int FLOAD_3 = 37; // - 153.180 -// int DLOAD_0 = 38; // - 153.181 -// int DLOAD_1 = 39; // - 153.182 -// int DLOAD_2 = 40; // - 153.183 -// int DLOAD_3 = 41; // - 153.184 -// int ALOAD_0 = 42; // - 153.185 -// int ALOAD_1 = 43; // - 153.186 -// int ALOAD_2 = 44; // - 153.187 -// int ALOAD_3 = 45; // - 153.188 -int IALOAD = 46; // visitInsn 153.189 -int LALOAD = 47; // - 153.190 -int FALOAD = 48; // - 153.191 -int DALOAD = 49; // - 153.192 -int AALOAD = 50; // - 153.193 -int BALOAD = 51; // - 153.194 -int CALOAD = 52; // - 153.195 -int SALOAD = 53; // - 153.196 -int ISTORE = 54; // visitVarInsn 153.197 -int LSTORE = 55; // - 153.198 -int FSTORE = 56; // - 153.199 -int DSTORE = 57; // - 153.200 -int ASTORE = 58; // - 153.201 -// int ISTORE_0 = 59; // - 153.202 -// int ISTORE_1 = 60; // - 153.203 -// int ISTORE_2 = 61; // - 153.204 -// int ISTORE_3 = 62; // - 153.205 -// int LSTORE_0 = 63; // - 153.206 -// int LSTORE_1 = 64; // - 153.207 -// int LSTORE_2 = 65; // - 153.208 -// int LSTORE_3 = 66; // - 153.209 -// int FSTORE_0 = 67; // - 153.210 -// int FSTORE_1 = 68; // - 153.211 -// int FSTORE_2 = 69; // - 153.212 -// int FSTORE_3 = 70; // - 153.213 -// int DSTORE_0 = 71; // - 153.214 -// int DSTORE_1 = 72; // - 153.215 -// int DSTORE_2 = 73; // - 153.216 -// int DSTORE_3 = 74; // - 153.217 -// int ASTORE_0 = 75; // - 153.218 -// int ASTORE_1 = 76; // - 153.219 -// int ASTORE_2 = 77; // - 153.220 -// int ASTORE_3 = 78; // - 153.221 -int IASTORE = 79; // visitInsn 153.222 -int LASTORE = 80; // - 153.223 -int FASTORE = 81; // - 153.224 -int DASTORE = 82; // - 153.225 -int AASTORE = 83; // - 153.226 -int BASTORE = 84; // - 153.227 -int CASTORE = 85; // - 153.228 -int SASTORE = 86; // - 153.229 -int POP = 87; // - 153.230 -int POP2 = 88; // - 153.231 -int DUP = 89; // - 153.232 -int DUP_X1 = 90; // - 153.233 -int DUP_X2 = 91; // - 153.234 -int DUP2 = 92; // - 153.235 -int DUP2_X1 = 93; // - 153.236 -int DUP2_X2 = 94; // - 153.237 -int SWAP = 95; // - 153.238 -int IADD = 96; // - 153.239 -int LADD = 97; // - 153.240 -int FADD = 98; // - 153.241 -int DADD = 99; // - 153.242 -int ISUB = 100; // - 153.243 -int LSUB = 101; // - 153.244 -int FSUB = 102; // - 153.245 -int DSUB = 103; // - 153.246 -int IMUL = 104; // - 153.247 -int LMUL = 105; // - 153.248 -int FMUL = 106; // - 153.249 -int DMUL = 107; // - 153.250 -int IDIV = 108; // - 153.251 -int LDIV = 109; // - 153.252 -int FDIV = 110; // - 153.253 -int DDIV = 111; // - 153.254 -int IREM = 112; // - 153.255 -int LREM = 113; // - 153.256 -int FREM = 114; // - 153.257 -int DREM = 115; // - 153.258 -int INEG = 116; // - 153.259 -int LNEG = 117; // - 153.260 -int FNEG = 118; // - 153.261 -int DNEG = 119; // - 153.262 -int ISHL = 120; // - 153.263 -int LSHL = 121; // - 153.264 -int ISHR = 122; // - 153.265 -int LSHR = 123; // - 153.266 -int IUSHR = 124; // - 153.267 -int LUSHR = 125; // - 153.268 -int IAND = 126; // - 153.269 -int LAND = 127; // - 153.270 -int IOR = 128; // - 153.271 -int LOR = 129; // - 153.272 -int IXOR = 130; // - 153.273 -int LXOR = 131; // - 153.274 -int IINC = 132; // visitIincInsn 153.275 -int I2L = 133; // visitInsn 153.276 -int I2F = 134; // - 153.277 -int I2D = 135; // - 153.278 -int L2I = 136; // - 153.279 -int L2F = 137; // - 153.280 -int L2D = 138; // - 153.281 -int F2I = 139; // - 153.282 -int F2L = 140; // - 153.283 -int F2D = 141; // - 153.284 -int D2I = 142; // - 153.285 -int D2L = 143; // - 153.286 -int D2F = 144; // - 153.287 -int I2B = 145; // - 153.288 -int I2C = 146; // - 153.289 -int I2S = 147; // - 153.290 -int LCMP = 148; // - 153.291 -int FCMPL = 149; // - 153.292 -int FCMPG = 150; // - 153.293 -int DCMPL = 151; // - 153.294 -int DCMPG = 152; // - 153.295 -int IFEQ = 153; // visitJumpInsn 153.296 -int IFNE = 154; // - 153.297 -int IFLT = 155; // - 153.298 -int IFGE = 156; // - 153.299 -int IFGT = 157; // - 153.300 -int IFLE = 158; // - 153.301 -int IF_ICMPEQ = 159; // - 153.302 -int IF_ICMPNE = 160; // - 153.303 -int IF_ICMPLT = 161; // - 153.304 -int IF_ICMPGE = 162; // - 153.305 -int IF_ICMPGT = 163; // - 153.306 -int IF_ICMPLE = 164; // - 153.307 -int IF_ACMPEQ = 165; // - 153.308 -int IF_ACMPNE = 166; // - 153.309 -int GOTO = 167; // - 153.310 -int JSR = 168; // - 153.311 -int RET = 169; // visitVarInsn 153.312 -int TABLESWITCH = 170; // visiTableSwitchInsn 153.313 -int LOOKUPSWITCH = 171; // visitLookupSwitch 153.314 -int IRETURN = 172; // visitInsn 153.315 -int LRETURN = 173; // - 153.316 -int FRETURN = 174; // - 153.317 -int DRETURN = 175; // - 153.318 -int ARETURN = 176; // - 153.319 -int RETURN = 177; // - 153.320 -int GETSTATIC = 178; // visitFieldInsn 153.321 -int PUTSTATIC = 179; // - 153.322 -int GETFIELD = 180; // - 153.323 -int PUTFIELD = 181; // - 153.324 -int INVOKEVIRTUAL = 182; // visitMethodInsn 153.325 -int INVOKESPECIAL = 183; // - 153.326 -int INVOKESTATIC = 184; // - 153.327 -int INVOKEINTERFACE = 185; // - 153.328 -// int UNUSED = 186; // NOT VISITED 153.329 -int NEW = 187; // visitTypeInsn 153.330 -int NEWARRAY = 188; // visitIntInsn 153.331 -int ANEWARRAY = 189; // visitTypeInsn 153.332 -int ARRAYLENGTH = 190; // visitInsn 153.333 -int ATHROW = 191; // - 153.334 -int CHECKCAST = 192; // visitTypeInsn 153.335 -int INSTANCEOF = 193; // - 153.336 -int MONITORENTER = 194; // visitInsn 153.337 -int MONITOREXIT = 195; // - 153.338 -// int WIDE = 196; // NOT VISITED 153.339 -int MULTIANEWARRAY = 197; // visitMultiANewArrayInsn 153.340 -int IFNULL = 198; // visitJumpInsn 153.341 -int IFNONNULL = 199; // - 153.342 -// int GOTO_W = 200; // - 153.343 -// int JSR_W = 201; // - 153.344 -}
154.1 --- a/src/clojure/asm/Type.java Sat Aug 21 06:25:44 2010 -0400 154.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 154.3 @@ -1,872 +0,0 @@ 154.4 -/*** 154.5 - * ASM: a very small and fast Java bytecode manipulation framework 154.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 154.7 - * All rights reserved. 154.8 - * 154.9 - * Redistribution and use in source and binary forms, with or without 154.10 - * modification, are permitted provided that the following conditions 154.11 - * are met: 154.12 - * 1. Redistributions of source code must retain the above copyright 154.13 - * notice, this list of conditions and the following disclaimer. 154.14 - * 2. Redistributions in binary form must reproduce the above copyright 154.15 - * notice, this list of conditions and the following disclaimer in the 154.16 - * documentation and/or other materials provided with the distribution. 154.17 - * 3. Neither the name of the copyright holders nor the names of its 154.18 - * contributors may be used to endorse or promote products derived from 154.19 - * this software without specific prior written permission. 154.20 - * 154.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 154.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 154.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 154.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 154.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 154.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 154.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 154.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 154.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 154.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 154.31 - * THE POSSIBILITY OF SUCH DAMAGE. 154.32 - */ 154.33 -package clojure.asm; 154.34 - 154.35 -import java.lang.reflect.Constructor; 154.36 -import java.lang.reflect.Method; 154.37 - 154.38 -/** 154.39 - * A Java type. This class can be used to make it easier to manipulate type and 154.40 - * method descriptors. 154.41 - * 154.42 - * @author Eric Bruneton 154.43 - * @author Chris Nokleberg 154.44 - */ 154.45 -public class Type{ 154.46 - 154.47 -/** 154.48 - * The sort of the <tt>void</tt> type. See {@link #getSort getSort}. 154.49 - */ 154.50 -public final static int VOID = 0; 154.51 - 154.52 -/** 154.53 - * The sort of the <tt>boolean</tt> type. See {@link #getSort getSort}. 154.54 - */ 154.55 -public final static int BOOLEAN = 1; 154.56 - 154.57 -/** 154.58 - * The sort of the <tt>char</tt> type. See {@link #getSort getSort}. 154.59 - */ 154.60 -public final static int CHAR = 2; 154.61 - 154.62 -/** 154.63 - * The sort of the <tt>byte</tt> type. See {@link #getSort getSort}. 154.64 - */ 154.65 -public final static int BYTE = 3; 154.66 - 154.67 -/** 154.68 - * The sort of the <tt>short</tt> type. See {@link #getSort getSort}. 154.69 - */ 154.70 -public final static int SHORT = 4; 154.71 - 154.72 -/** 154.73 - * The sort of the <tt>int</tt> type. See {@link #getSort getSort}. 154.74 - */ 154.75 -public final static int INT = 5; 154.76 - 154.77 -/** 154.78 - * The sort of the <tt>float</tt> type. See {@link #getSort getSort}. 154.79 - */ 154.80 -public final static int FLOAT = 6; 154.81 - 154.82 -/** 154.83 - * The sort of the <tt>long</tt> type. See {@link #getSort getSort}. 154.84 - */ 154.85 -public final static int LONG = 7; 154.86 - 154.87 -/** 154.88 - * The sort of the <tt>double</tt> type. See {@link #getSort getSort}. 154.89 - */ 154.90 -public final static int DOUBLE = 8; 154.91 - 154.92 -/** 154.93 - * The sort of array reference types. See {@link #getSort getSort}. 154.94 - */ 154.95 -public final static int ARRAY = 9; 154.96 - 154.97 -/** 154.98 - * The sort of object reference type. See {@link #getSort getSort}. 154.99 - */ 154.100 -public final static int OBJECT = 10; 154.101 - 154.102 -/** 154.103 - * The <tt>void</tt> type. 154.104 - */ 154.105 -public final static Type VOID_TYPE = new Type(VOID); 154.106 - 154.107 -/** 154.108 - * The <tt>boolean</tt> type. 154.109 - */ 154.110 -public final static Type BOOLEAN_TYPE = new Type(BOOLEAN); 154.111 - 154.112 -/** 154.113 - * The <tt>char</tt> type. 154.114 - */ 154.115 -public final static Type CHAR_TYPE = new Type(CHAR); 154.116 - 154.117 -/** 154.118 - * The <tt>byte</tt> type. 154.119 - */ 154.120 -public final static Type BYTE_TYPE = new Type(BYTE); 154.121 - 154.122 -/** 154.123 - * The <tt>short</tt> type. 154.124 - */ 154.125 -public final static Type SHORT_TYPE = new Type(SHORT); 154.126 - 154.127 -/** 154.128 - * The <tt>int</tt> type. 154.129 - */ 154.130 -public final static Type INT_TYPE = new Type(INT); 154.131 - 154.132 -/** 154.133 - * The <tt>float</tt> type. 154.134 - */ 154.135 -public final static Type FLOAT_TYPE = new Type(FLOAT); 154.136 - 154.137 -/** 154.138 - * The <tt>long</tt> type. 154.139 - */ 154.140 -public final static Type LONG_TYPE = new Type(LONG); 154.141 - 154.142 -/** 154.143 - * The <tt>double</tt> type. 154.144 - */ 154.145 -public final static Type DOUBLE_TYPE = new Type(DOUBLE); 154.146 - 154.147 -// ------------------------------------------------------------------------ 154.148 -// Fields 154.149 -// ------------------------------------------------------------------------ 154.150 - 154.151 -/** 154.152 - * The sort of this Java type. 154.153 - */ 154.154 -private final int sort; 154.155 - 154.156 -/** 154.157 - * A buffer containing the descriptor of this Java type. This field is only 154.158 - * used for reference types. 154.159 - */ 154.160 -private char[] buf; 154.161 - 154.162 -/** 154.163 - * The offset of the descriptor of this Java type in {@link #buf buf}. This 154.164 - * field is only used for reference types. 154.165 - */ 154.166 -private int off; 154.167 - 154.168 -/** 154.169 - * The length of the descriptor of this Java type. 154.170 - */ 154.171 -private int len; 154.172 - 154.173 -// ------------------------------------------------------------------------ 154.174 -// Constructors 154.175 -// ------------------------------------------------------------------------ 154.176 - 154.177 -/** 154.178 - * Constructs a primitive type. 154.179 - * 154.180 - * @param sort the sort of the primitive type to be constructed. 154.181 - */ 154.182 -private Type(final int sort){ 154.183 - this.sort = sort; 154.184 - this.len = 1; 154.185 -} 154.186 - 154.187 -/** 154.188 - * Constructs a reference type. 154.189 - * 154.190 - * @param sort the sort of the reference type to be constructed. 154.191 - * @param buf a buffer containing the descriptor of the previous type. 154.192 - * @param off the offset of this descriptor in the previous buffer. 154.193 - * @param len the length of this descriptor. 154.194 - */ 154.195 -private Type(final int sort, final char[] buf, final int off, final int len){ 154.196 - this.sort = sort; 154.197 - this.buf = buf; 154.198 - this.off = off; 154.199 - this.len = len; 154.200 -} 154.201 - 154.202 -/** 154.203 - * Returns the Java type corresponding to the given type descriptor. 154.204 - * 154.205 - * @param typeDescriptor a type descriptor. 154.206 - * @return the Java type corresponding to the given type descriptor. 154.207 - */ 154.208 -public static Type getType(final String typeDescriptor){ 154.209 - return getType(typeDescriptor.toCharArray(), 0); 154.210 -} 154.211 - 154.212 -/** 154.213 - * Returns the Java type corresponding to the given class. 154.214 - * 154.215 - * @param c a class. 154.216 - * @return the Java type corresponding to the given class. 154.217 - */ 154.218 -public static Type getType(final Class c){ 154.219 - if(c.isPrimitive()) 154.220 - { 154.221 - if(c == Integer.TYPE) 154.222 - { 154.223 - return INT_TYPE; 154.224 - } 154.225 - else if(c == Void.TYPE) 154.226 - { 154.227 - return VOID_TYPE; 154.228 - } 154.229 - else if(c == Boolean.TYPE) 154.230 - { 154.231 - return BOOLEAN_TYPE; 154.232 - } 154.233 - else if(c == Byte.TYPE) 154.234 - { 154.235 - return BYTE_TYPE; 154.236 - } 154.237 - else if(c == Character.TYPE) 154.238 - { 154.239 - return CHAR_TYPE; 154.240 - } 154.241 - else if(c == Short.TYPE) 154.242 - { 154.243 - return SHORT_TYPE; 154.244 - } 154.245 - else if(c == Double.TYPE) 154.246 - { 154.247 - return DOUBLE_TYPE; 154.248 - } 154.249 - else if(c == Float.TYPE) 154.250 - { 154.251 - return FLOAT_TYPE; 154.252 - } 154.253 - else /* if (c == Long.TYPE) */ 154.254 - { 154.255 - return LONG_TYPE; 154.256 - } 154.257 - } 154.258 - else 154.259 - { 154.260 - return getType(getDescriptor(c)); 154.261 - } 154.262 -} 154.263 - 154.264 -/** 154.265 - * Returns the {@link Type#OBJECT} type for the given internal class name. 154.266 - * This is a shortcut method for <code>Type.getType("L"+name+";")</code>. 154.267 - * <i>Note that opposed to {@link Type#getType(String)}, this method takes 154.268 - * internal class names and not class descriptor.</i> 154.269 - * 154.270 - * @param name an internal class name. 154.271 - * @return the the {@link Type#OBJECT} type for the given class name. 154.272 - */ 154.273 -public static Type getObjectType(String name){ 154.274 - int l = name.length(); 154.275 - char[] buf = new char[l + 2]; 154.276 - buf[0] = 'L'; 154.277 - buf[l + 1] = ';'; 154.278 - name.getChars(0, l, buf, 1); 154.279 - return new Type(OBJECT, buf, 0, l + 2); 154.280 -} 154.281 - 154.282 -/** 154.283 - * Returns the Java types corresponding to the argument types of the given 154.284 - * method descriptor. 154.285 - * 154.286 - * @param methodDescriptor a method descriptor. 154.287 - * @return the Java types corresponding to the argument types of the given 154.288 - * method descriptor. 154.289 - */ 154.290 -public static Type[] getArgumentTypes(final String methodDescriptor){ 154.291 - char[] buf = methodDescriptor.toCharArray(); 154.292 - int off = 1; 154.293 - int size = 0; 154.294 - while(true) 154.295 - { 154.296 - char car = buf[off++]; 154.297 - if(car == ')') 154.298 - { 154.299 - break; 154.300 - } 154.301 - else if(car == 'L') 154.302 - { 154.303 - while(buf[off++] != ';') 154.304 - { 154.305 - } 154.306 - ++size; 154.307 - } 154.308 - else if(car != '[') 154.309 - { 154.310 - ++size; 154.311 - } 154.312 - } 154.313 - Type[] args = new Type[size]; 154.314 - off = 1; 154.315 - size = 0; 154.316 - while(buf[off] != ')') 154.317 - { 154.318 - args[size] = getType(buf, off); 154.319 - off += args[size].len; 154.320 - size += 1; 154.321 - } 154.322 - return args; 154.323 -} 154.324 - 154.325 -/** 154.326 - * Returns the Java types corresponding to the argument types of the given 154.327 - * method. 154.328 - * 154.329 - * @param method a method. 154.330 - * @return the Java types corresponding to the argument types of the given 154.331 - * method. 154.332 - */ 154.333 -public static Type[] getArgumentTypes(final Method method){ 154.334 - Class[] classes = method.getParameterTypes(); 154.335 - Type[] types = new Type[classes.length]; 154.336 - for(int i = classes.length - 1; i >= 0; --i) 154.337 - { 154.338 - types[i] = getType(classes[i]); 154.339 - } 154.340 - return types; 154.341 -} 154.342 - 154.343 -/** 154.344 - * Returns the Java type corresponding to the return type of the given 154.345 - * method descriptor. 154.346 - * 154.347 - * @param methodDescriptor a method descriptor. 154.348 - * @return the Java type corresponding to the return type of the given 154.349 - * method descriptor. 154.350 - */ 154.351 -public static Type getReturnType(final String methodDescriptor){ 154.352 - char[] buf = methodDescriptor.toCharArray(); 154.353 - return getType(buf, methodDescriptor.indexOf(')') + 1); 154.354 -} 154.355 - 154.356 -/** 154.357 - * Returns the Java type corresponding to the return type of the given 154.358 - * method. 154.359 - * 154.360 - * @param method a method. 154.361 - * @return the Java type corresponding to the return type of the given 154.362 - * method. 154.363 - */ 154.364 -public static Type getReturnType(final Method method){ 154.365 - return getType(method.getReturnType()); 154.366 -} 154.367 - 154.368 -/** 154.369 - * Returns the Java type corresponding to the given type descriptor. 154.370 - * 154.371 - * @param buf a buffer containing a type descriptor. 154.372 - * @param off the offset of this descriptor in the previous buffer. 154.373 - * @return the Java type corresponding to the given type descriptor. 154.374 - */ 154.375 -private static Type getType(final char[] buf, final int off){ 154.376 - int len; 154.377 - switch(buf[off]) 154.378 - { 154.379 - case'V': 154.380 - return VOID_TYPE; 154.381 - case'Z': 154.382 - return BOOLEAN_TYPE; 154.383 - case'C': 154.384 - return CHAR_TYPE; 154.385 - case'B': 154.386 - return BYTE_TYPE; 154.387 - case'S': 154.388 - return SHORT_TYPE; 154.389 - case'I': 154.390 - return INT_TYPE; 154.391 - case'F': 154.392 - return FLOAT_TYPE; 154.393 - case'J': 154.394 - return LONG_TYPE; 154.395 - case'D': 154.396 - return DOUBLE_TYPE; 154.397 - case'[': 154.398 - len = 1; 154.399 - while(buf[off + len] == '[') 154.400 - { 154.401 - ++len; 154.402 - } 154.403 - if(buf[off + len] == 'L') 154.404 - { 154.405 - ++len; 154.406 - while(buf[off + len] != ';') 154.407 - { 154.408 - ++len; 154.409 - } 154.410 - } 154.411 - return new Type(ARRAY, buf, off, len + 1); 154.412 - // case 'L': 154.413 - default: 154.414 - len = 1; 154.415 - while(buf[off + len] != ';') 154.416 - { 154.417 - ++len; 154.418 - } 154.419 - return new Type(OBJECT, buf, off, len + 1); 154.420 - } 154.421 -} 154.422 - 154.423 -// ------------------------------------------------------------------------ 154.424 -// Accessors 154.425 -// ------------------------------------------------------------------------ 154.426 - 154.427 -/** 154.428 - * Returns the sort of this Java type. 154.429 - * 154.430 - * @return {@link #VOID VOID}, {@link #BOOLEAN BOOLEAN}, 154.431 - * {@link #CHAR CHAR}, {@link #BYTE BYTE}, {@link #SHORT SHORT}, 154.432 - * {@link #INT INT}, {@link #FLOAT FLOAT}, {@link #LONG LONG}, 154.433 - * {@link #DOUBLE DOUBLE}, {@link #ARRAY ARRAY} or 154.434 - * {@link #OBJECT OBJECT}. 154.435 - */ 154.436 -public int getSort(){ 154.437 - return sort; 154.438 -} 154.439 - 154.440 -/** 154.441 - * Returns the number of dimensions of this array type. This method should 154.442 - * only be used for an array type. 154.443 - * 154.444 - * @return the number of dimensions of this array type. 154.445 - */ 154.446 -public int getDimensions(){ 154.447 - int i = 1; 154.448 - while(buf[off + i] == '[') 154.449 - { 154.450 - ++i; 154.451 - } 154.452 - return i; 154.453 -} 154.454 - 154.455 -/** 154.456 - * Returns the type of the elements of this array type. This method should 154.457 - * only be used for an array type. 154.458 - * 154.459 - * @return Returns the type of the elements of this array type. 154.460 - */ 154.461 -public Type getElementType(){ 154.462 - return getType(buf, off + getDimensions()); 154.463 -} 154.464 - 154.465 -/** 154.466 - * Returns the name of the class corresponding to this type. 154.467 - * 154.468 - * @return the fully qualified name of the class corresponding to this type. 154.469 - */ 154.470 -public String getClassName(){ 154.471 - switch(sort) 154.472 - { 154.473 - case VOID: 154.474 - return "void"; 154.475 - case BOOLEAN: 154.476 - return "boolean"; 154.477 - case CHAR: 154.478 - return "char"; 154.479 - case BYTE: 154.480 - return "byte"; 154.481 - case SHORT: 154.482 - return "short"; 154.483 - case INT: 154.484 - return "int"; 154.485 - case FLOAT: 154.486 - return "float"; 154.487 - case LONG: 154.488 - return "long"; 154.489 - case DOUBLE: 154.490 - return "double"; 154.491 - case ARRAY: 154.492 - StringBuffer b = new StringBuffer(getElementType().getClassName()); 154.493 - for(int i = getDimensions(); i > 0; --i) 154.494 - { 154.495 - b.append("[]"); 154.496 - } 154.497 - return b.toString(); 154.498 - // case OBJECT: 154.499 - default: 154.500 - return new String(buf, off + 1, len - 2).replace('/', '.'); 154.501 - } 154.502 -} 154.503 - 154.504 -/** 154.505 - * Returns the internal name of the class corresponding to this object type. 154.506 - * The internal name of a class is its fully qualified name, where '.' are 154.507 - * replaced by '/'. This method should only be used for an object type. 154.508 - * 154.509 - * @return the internal name of the class corresponding to this object type. 154.510 - */ 154.511 -public String getInternalName(){ 154.512 - return new String(buf, off + 1, len - 2); 154.513 -} 154.514 - 154.515 -// ------------------------------------------------------------------------ 154.516 -// Conversion to type descriptors 154.517 -// ------------------------------------------------------------------------ 154.518 - 154.519 -/** 154.520 - * Returns the descriptor corresponding to this Java type. 154.521 - * 154.522 - * @return the descriptor corresponding to this Java type. 154.523 - */ 154.524 -public String getDescriptor(){ 154.525 - StringBuffer buf = new StringBuffer(); 154.526 - getDescriptor(buf); 154.527 - return buf.toString(); 154.528 -} 154.529 - 154.530 -/** 154.531 - * Returns the descriptor corresponding to the given argument and return 154.532 - * types. 154.533 - * 154.534 - * @param returnType the return type of the method. 154.535 - * @param argumentTypes the argument types of the method. 154.536 - * @return the descriptor corresponding to the given argument and return 154.537 - * types. 154.538 - */ 154.539 -public static String getMethodDescriptor( 154.540 - final Type returnType, 154.541 - final Type[] argumentTypes){ 154.542 - StringBuffer buf = new StringBuffer(); 154.543 - buf.append('('); 154.544 - for(int i = 0; i < argumentTypes.length; ++i) 154.545 - { 154.546 - argumentTypes[i].getDescriptor(buf); 154.547 - } 154.548 - buf.append(')'); 154.549 - returnType.getDescriptor(buf); 154.550 - return buf.toString(); 154.551 -} 154.552 - 154.553 -/** 154.554 - * Appends the descriptor corresponding to this Java type to the given 154.555 - * string buffer. 154.556 - * 154.557 - * @param buf the string buffer to which the descriptor must be appended. 154.558 - */ 154.559 -private void getDescriptor(final StringBuffer buf){ 154.560 - switch(sort) 154.561 - { 154.562 - case VOID: 154.563 - buf.append('V'); 154.564 - return; 154.565 - case BOOLEAN: 154.566 - buf.append('Z'); 154.567 - return; 154.568 - case CHAR: 154.569 - buf.append('C'); 154.570 - return; 154.571 - case BYTE: 154.572 - buf.append('B'); 154.573 - return; 154.574 - case SHORT: 154.575 - buf.append('S'); 154.576 - return; 154.577 - case INT: 154.578 - buf.append('I'); 154.579 - return; 154.580 - case FLOAT: 154.581 - buf.append('F'); 154.582 - return; 154.583 - case LONG: 154.584 - buf.append('J'); 154.585 - return; 154.586 - case DOUBLE: 154.587 - buf.append('D'); 154.588 - return; 154.589 - // case ARRAY: 154.590 - // case OBJECT: 154.591 - default: 154.592 - buf.append(this.buf, off, len); 154.593 - } 154.594 -} 154.595 - 154.596 -// ------------------------------------------------------------------------ 154.597 -// Direct conversion from classes to type descriptors, 154.598 -// without intermediate Type objects 154.599 -// ------------------------------------------------------------------------ 154.600 - 154.601 -/** 154.602 - * Returns the internal name of the given class. The internal name of a 154.603 - * class is its fully qualified name, where '.' are replaced by '/'. 154.604 - * 154.605 - * @param c an object class. 154.606 - * @return the internal name of the given class. 154.607 - */ 154.608 -public static String getInternalName(final Class c){ 154.609 - return c.getName().replace('.', '/'); 154.610 -} 154.611 - 154.612 -/** 154.613 - * Returns the descriptor corresponding to the given Java type. 154.614 - * 154.615 - * @param c an object class, a primitive class or an array class. 154.616 - * @return the descriptor corresponding to the given class. 154.617 - */ 154.618 -public static String getDescriptor(final Class c){ 154.619 - StringBuffer buf = new StringBuffer(); 154.620 - getDescriptor(buf, c); 154.621 - return buf.toString(); 154.622 -} 154.623 - 154.624 -/** 154.625 - * Returns the descriptor corresponding to the given constructor. 154.626 - * 154.627 - * @param c a {@link Constructor Constructor} object. 154.628 - * @return the descriptor of the given constructor. 154.629 - */ 154.630 -public static String getConstructorDescriptor(final Constructor c){ 154.631 - Class[] parameters = c.getParameterTypes(); 154.632 - StringBuffer buf = new StringBuffer(); 154.633 - buf.append('('); 154.634 - for(int i = 0; i < parameters.length; ++i) 154.635 - { 154.636 - getDescriptor(buf, parameters[i]); 154.637 - } 154.638 - return buf.append(")V").toString(); 154.639 -} 154.640 - 154.641 -/** 154.642 - * Returns the descriptor corresponding to the given method. 154.643 - * 154.644 - * @param m a {@link Method Method} object. 154.645 - * @return the descriptor of the given method. 154.646 - */ 154.647 -public static String getMethodDescriptor(final Method m){ 154.648 - Class[] parameters = m.getParameterTypes(); 154.649 - StringBuffer buf = new StringBuffer(); 154.650 - buf.append('('); 154.651 - for(int i = 0; i < parameters.length; ++i) 154.652 - { 154.653 - getDescriptor(buf, parameters[i]); 154.654 - } 154.655 - buf.append(')'); 154.656 - getDescriptor(buf, m.getReturnType()); 154.657 - return buf.toString(); 154.658 -} 154.659 - 154.660 -/** 154.661 - * Appends the descriptor of the given class to the given string buffer. 154.662 - * 154.663 - * @param buf the string buffer to which the descriptor must be appended. 154.664 - * @param c the class whose descriptor must be computed. 154.665 - */ 154.666 -private static void getDescriptor(final StringBuffer buf, final Class c){ 154.667 - Class d = c; 154.668 - while(true) 154.669 - { 154.670 - if(d.isPrimitive()) 154.671 - { 154.672 - char car; 154.673 - if(d == Integer.TYPE) 154.674 - { 154.675 - car = 'I'; 154.676 - } 154.677 - else if(d == Void.TYPE) 154.678 - { 154.679 - car = 'V'; 154.680 - } 154.681 - else if(d == Boolean.TYPE) 154.682 - { 154.683 - car = 'Z'; 154.684 - } 154.685 - else if(d == Byte.TYPE) 154.686 - { 154.687 - car = 'B'; 154.688 - } 154.689 - else if(d == Character.TYPE) 154.690 - { 154.691 - car = 'C'; 154.692 - } 154.693 - else if(d == Short.TYPE) 154.694 - { 154.695 - car = 'S'; 154.696 - } 154.697 - else if(d == Double.TYPE) 154.698 - { 154.699 - car = 'D'; 154.700 - } 154.701 - else if(d == Float.TYPE) 154.702 - { 154.703 - car = 'F'; 154.704 - } 154.705 - else /* if (d == Long.TYPE) */ 154.706 - { 154.707 - car = 'J'; 154.708 - } 154.709 - buf.append(car); 154.710 - return; 154.711 - } 154.712 - else if(d.isArray()) 154.713 - { 154.714 - buf.append('['); 154.715 - d = d.getComponentType(); 154.716 - } 154.717 - else 154.718 - { 154.719 - buf.append('L'); 154.720 - String name = d.getName(); 154.721 - int len = name.length(); 154.722 - for(int i = 0; i < len; ++i) 154.723 - { 154.724 - char car = name.charAt(i); 154.725 - buf.append(car == '.' ? '/' : car); 154.726 - } 154.727 - buf.append(';'); 154.728 - return; 154.729 - } 154.730 - } 154.731 -} 154.732 - 154.733 -// ------------------------------------------------------------------------ 154.734 -// Corresponding size and opcodes 154.735 -// ------------------------------------------------------------------------ 154.736 - 154.737 -/** 154.738 - * Returns the size of values of this type. 154.739 - * 154.740 - * @return the size of values of this type, i.e., 2 for <tt>long</tt> and 154.741 - * <tt>double</tt>, and 1 otherwise. 154.742 - */ 154.743 -public int getSize(){ 154.744 - return sort == LONG || sort == DOUBLE ? 2 : 1; 154.745 -} 154.746 - 154.747 -/** 154.748 - * Returns a JVM instruction opcode adapted to this Java type. 154.749 - * 154.750 - * @param opcode a JVM instruction opcode. This opcode must be one of ILOAD, 154.751 - * ISTORE, IALOAD, IASTORE, IADD, ISUB, IMUL, IDIV, IREM, INEG, ISHL, 154.752 - * ISHR, IUSHR, IAND, IOR, IXOR and IRETURN. 154.753 - * @return an opcode that is similar to the given opcode, but adapted to 154.754 - * this Java type. For example, if this type is <tt>float</tt> and 154.755 - * <tt>opcode</tt> is IRETURN, this method returns FRETURN. 154.756 - */ 154.757 -public int getOpcode(final int opcode){ 154.758 - if(opcode == Opcodes.IALOAD || opcode == Opcodes.IASTORE) 154.759 - { 154.760 - switch(sort) 154.761 - { 154.762 - case BOOLEAN: 154.763 - case BYTE: 154.764 - return opcode + 5; 154.765 - case CHAR: 154.766 - return opcode + 6; 154.767 - case SHORT: 154.768 - return opcode + 7; 154.769 - case INT: 154.770 - return opcode; 154.771 - case FLOAT: 154.772 - return opcode + 2; 154.773 - case LONG: 154.774 - return opcode + 1; 154.775 - case DOUBLE: 154.776 - return opcode + 3; 154.777 - // case ARRAY: 154.778 - // case OBJECT: 154.779 - default: 154.780 - return opcode + 4; 154.781 - } 154.782 - } 154.783 - else 154.784 - { 154.785 - switch(sort) 154.786 - { 154.787 - case VOID: 154.788 - return opcode + 5; 154.789 - case BOOLEAN: 154.790 - case CHAR: 154.791 - case BYTE: 154.792 - case SHORT: 154.793 - case INT: 154.794 - return opcode; 154.795 - case FLOAT: 154.796 - return opcode + 2; 154.797 - case LONG: 154.798 - return opcode + 1; 154.799 - case DOUBLE: 154.800 - return opcode + 3; 154.801 - // case ARRAY: 154.802 - // case OBJECT: 154.803 - default: 154.804 - return opcode + 4; 154.805 - } 154.806 - } 154.807 -} 154.808 - 154.809 -// ------------------------------------------------------------------------ 154.810 -// Equals, hashCode and toString 154.811 -// ------------------------------------------------------------------------ 154.812 - 154.813 -/** 154.814 - * Tests if the given object is equal to this type. 154.815 - * 154.816 - * @param o the object to be compared to this type. 154.817 - * @return <tt>true</tt> if the given object is equal to this type. 154.818 - */ 154.819 -public boolean equals(final Object o){ 154.820 - if(this == o) 154.821 - { 154.822 - return true; 154.823 - } 154.824 - if(!(o instanceof Type)) 154.825 - { 154.826 - return false; 154.827 - } 154.828 - Type t = (Type) o; 154.829 - if(sort != t.sort) 154.830 - { 154.831 - return false; 154.832 - } 154.833 - if(sort == Type.OBJECT || sort == Type.ARRAY) 154.834 - { 154.835 - if(len != t.len) 154.836 - { 154.837 - return false; 154.838 - } 154.839 - for(int i = off, j = t.off, end = i + len; i < end; i++, j++) 154.840 - { 154.841 - if(buf[i] != t.buf[j]) 154.842 - { 154.843 - return false; 154.844 - } 154.845 - } 154.846 - } 154.847 - return true; 154.848 -} 154.849 - 154.850 -/** 154.851 - * Returns a hash code value for this type. 154.852 - * 154.853 - * @return a hash code value for this type. 154.854 - */ 154.855 -public int hashCode(){ 154.856 - int hc = 13 * sort; 154.857 - if(sort == Type.OBJECT || sort == Type.ARRAY) 154.858 - { 154.859 - for(int i = off, end = i + len; i < end; i++) 154.860 - { 154.861 - hc = 17 * (hc + buf[i]); 154.862 - } 154.863 - } 154.864 - return hc; 154.865 -} 154.866 - 154.867 -/** 154.868 - * Returns a string representation of this type. 154.869 - * 154.870 - * @return the descriptor of this type. 154.871 - */ 154.872 -public String toString(){ 154.873 - return getDescriptor(); 154.874 -} 154.875 -}
155.1 --- a/src/clojure/asm/commons/AdviceAdapter.java Sat Aug 21 06:25:44 2010 -0400 155.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 155.3 @@ -1,681 +0,0 @@ 155.4 -/*** 155.5 - * ASM: a very small and fast Java bytecode manipulation framework 155.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 155.7 - * All rights reserved. 155.8 - * 155.9 - * Redistribution and use in source and binary forms, with or without 155.10 - * modification, are permitted provided that the following conditions 155.11 - * are met: 155.12 - * 1. Redistributions of source code must retain the above copyright 155.13 - * notice, this list of conditions and the following disclaimer. 155.14 - * 2. Redistributions in binary form must reproduce the above copyright 155.15 - * notice, this list of conditions and the following disclaimer in the 155.16 - * documentation and/or other materials provided with the distribution. 155.17 - * 3. Neither the name of the copyright holders nor the names of its 155.18 - * contributors may be used to endorse or promote products derived from 155.19 - * this software without specific prior written permission. 155.20 - * 155.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 155.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 155.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 155.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 155.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 155.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 155.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 155.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 155.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 155.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 155.31 - * THE POSSIBILITY OF SUCH DAMAGE. 155.32 - */ 155.33 -package clojure.asm.commons; 155.34 - 155.35 -import java.util.ArrayList; 155.36 -import java.util.HashMap; 155.37 - 155.38 -import clojure.asm.Label; 155.39 -import clojure.asm.MethodVisitor; 155.40 -import clojure.asm.Opcodes; 155.41 -import clojure.asm.Type; 155.42 - 155.43 -/** 155.44 - * A {@link clojure.asm.MethodAdapter} to insert before, after and around 155.45 - * advices in methods and constructors. <p> The behavior for constructors is 155.46 - * like this: <ol> 155.47 - * <p/> 155.48 - * <li>as long as the INVOKESPECIAL for the object initialization has not been 155.49 - * reached, every bytecode instruction is dispatched in the ctor code visitor</li> 155.50 - * <p/> 155.51 - * <li>when this one is reached, it is only added in the ctor code visitor and 155.52 - * a JP invoke is added</li> 155.53 - * <p/> 155.54 - * <li>after that, only the other code visitor receives the instructions</li> 155.55 - * <p/> 155.56 - * </ol> 155.57 - * 155.58 - * @author Eugene Kuleshov 155.59 - * @author Eric Bruneton 155.60 - */ 155.61 -public abstract class AdviceAdapter extends GeneratorAdapter implements Opcodes{ 155.62 -private static final Object THIS = new Object(); 155.63 -private static final Object OTHER = new Object(); 155.64 - 155.65 -protected int methodAccess; 155.66 -protected String methodDesc; 155.67 - 155.68 -private boolean constructor; 155.69 -private boolean superInitialized; 155.70 -private ArrayList stackFrame; 155.71 -private HashMap branches; 155.72 - 155.73 -/** 155.74 - * Creates a new {@link AdviceAdapter}. 155.75 - * 155.76 - * @param mv the method visitor to which this adapter delegates calls. 155.77 - * @param access the method's access flags (see {@link Opcodes}). 155.78 - * @param name the method's name. 155.79 - * @param desc the method's descriptor (see {@link Type Type}). 155.80 - */ 155.81 -public AdviceAdapter( 155.82 - final MethodVisitor mv, 155.83 - final int access, 155.84 - final String name, 155.85 - final String desc){ 155.86 - super(mv, access, name, desc); 155.87 - methodAccess = access; 155.88 - methodDesc = desc; 155.89 - 155.90 - constructor = "<init>".equals(name); 155.91 -} 155.92 - 155.93 -public void visitCode(){ 155.94 - mv.visitCode(); 155.95 - if(!constructor) 155.96 - { 155.97 - superInitialized = true; 155.98 - onMethodEnter(); 155.99 - } 155.100 - else 155.101 - { 155.102 - stackFrame = new ArrayList(); 155.103 - branches = new HashMap(); 155.104 - } 155.105 -} 155.106 - 155.107 -public void visitLabel(final Label label){ 155.108 - mv.visitLabel(label); 155.109 - 155.110 - if(constructor && branches != null) 155.111 - { 155.112 - ArrayList frame = (ArrayList) branches.get(label); 155.113 - if(frame != null) 155.114 - { 155.115 - stackFrame = frame; 155.116 - branches.remove(label); 155.117 - } 155.118 - } 155.119 -} 155.120 - 155.121 -public void visitInsn(final int opcode){ 155.122 - if(constructor) 155.123 - { 155.124 - switch(opcode) 155.125 - { 155.126 - case RETURN: // empty stack 155.127 - onMethodExit(opcode); 155.128 - break; 155.129 - 155.130 - case IRETURN: // 1 before n/a after 155.131 - case FRETURN: // 1 before n/a after 155.132 - case ARETURN: // 1 before n/a after 155.133 - case ATHROW: // 1 before n/a after 155.134 - popValue(); 155.135 - popValue(); 155.136 - onMethodExit(opcode); 155.137 - break; 155.138 - 155.139 - case LRETURN: // 2 before n/a after 155.140 - case DRETURN: // 2 before n/a after 155.141 - popValue(); 155.142 - popValue(); 155.143 - onMethodExit(opcode); 155.144 - break; 155.145 - 155.146 - case NOP: 155.147 - case LALOAD: // remove 2 add 2 155.148 - case DALOAD: // remove 2 add 2 155.149 - case LNEG: 155.150 - case DNEG: 155.151 - case FNEG: 155.152 - case INEG: 155.153 - case L2D: 155.154 - case D2L: 155.155 - case F2I: 155.156 - case I2B: 155.157 - case I2C: 155.158 - case I2S: 155.159 - case I2F: 155.160 - case Opcodes.ARRAYLENGTH: 155.161 - break; 155.162 - 155.163 - case ACONST_NULL: 155.164 - case ICONST_M1: 155.165 - case ICONST_0: 155.166 - case ICONST_1: 155.167 - case ICONST_2: 155.168 - case ICONST_3: 155.169 - case ICONST_4: 155.170 - case ICONST_5: 155.171 - case FCONST_0: 155.172 - case FCONST_1: 155.173 - case FCONST_2: 155.174 - case F2L: // 1 before 2 after 155.175 - case F2D: 155.176 - case I2L: 155.177 - case I2D: 155.178 - pushValue(OTHER); 155.179 - break; 155.180 - 155.181 - case LCONST_0: 155.182 - case LCONST_1: 155.183 - case DCONST_0: 155.184 - case DCONST_1: 155.185 - pushValue(OTHER); 155.186 - pushValue(OTHER); 155.187 - break; 155.188 - 155.189 - case IALOAD: // remove 2 add 1 155.190 - case FALOAD: // remove 2 add 1 155.191 - case AALOAD: // remove 2 add 1 155.192 - case BALOAD: // remove 2 add 1 155.193 - case CALOAD: // remove 2 add 1 155.194 - case SALOAD: // remove 2 add 1 155.195 - case POP: 155.196 - case IADD: 155.197 - case FADD: 155.198 - case ISUB: 155.199 - case LSHL: // 3 before 2 after 155.200 - case LSHR: // 3 before 2 after 155.201 - case LUSHR: // 3 before 2 after 155.202 - case L2I: // 2 before 1 after 155.203 - case L2F: // 2 before 1 after 155.204 - case D2I: // 2 before 1 after 155.205 - case D2F: // 2 before 1 after 155.206 - case FSUB: 155.207 - case FMUL: 155.208 - case FDIV: 155.209 - case FREM: 155.210 - case FCMPL: // 2 before 1 after 155.211 - case FCMPG: // 2 before 1 after 155.212 - case IMUL: 155.213 - case IDIV: 155.214 - case IREM: 155.215 - case ISHL: 155.216 - case ISHR: 155.217 - case IUSHR: 155.218 - case IAND: 155.219 - case IOR: 155.220 - case IXOR: 155.221 - case MONITORENTER: 155.222 - case MONITOREXIT: 155.223 - popValue(); 155.224 - break; 155.225 - 155.226 - case POP2: 155.227 - case LSUB: 155.228 - case LMUL: 155.229 - case LDIV: 155.230 - case LREM: 155.231 - case LADD: 155.232 - case LAND: 155.233 - case LOR: 155.234 - case LXOR: 155.235 - case DADD: 155.236 - case DMUL: 155.237 - case DSUB: 155.238 - case DDIV: 155.239 - case DREM: 155.240 - popValue(); 155.241 - popValue(); 155.242 - break; 155.243 - 155.244 - case IASTORE: 155.245 - case FASTORE: 155.246 - case AASTORE: 155.247 - case BASTORE: 155.248 - case CASTORE: 155.249 - case SASTORE: 155.250 - case LCMP: // 4 before 1 after 155.251 - case DCMPL: 155.252 - case DCMPG: 155.253 - popValue(); 155.254 - popValue(); 155.255 - popValue(); 155.256 - break; 155.257 - 155.258 - case LASTORE: 155.259 - case DASTORE: 155.260 - popValue(); 155.261 - popValue(); 155.262 - popValue(); 155.263 - popValue(); 155.264 - break; 155.265 - 155.266 - case DUP: 155.267 - pushValue(peekValue()); 155.268 - break; 155.269 - 155.270 - case DUP_X1: 155.271 - // TODO optimize this 155.272 - { 155.273 - Object o1 = popValue(); 155.274 - Object o2 = popValue(); 155.275 - pushValue(o1); 155.276 - pushValue(o2); 155.277 - pushValue(o1); 155.278 - } 155.279 - break; 155.280 - 155.281 - case DUP_X2: 155.282 - // TODO optimize this 155.283 - { 155.284 - Object o1 = popValue(); 155.285 - Object o2 = popValue(); 155.286 - Object o3 = popValue(); 155.287 - pushValue(o1); 155.288 - pushValue(o3); 155.289 - pushValue(o2); 155.290 - pushValue(o1); 155.291 - } 155.292 - break; 155.293 - 155.294 - case DUP2: 155.295 - // TODO optimize this 155.296 - { 155.297 - Object o1 = popValue(); 155.298 - Object o2 = popValue(); 155.299 - pushValue(o2); 155.300 - pushValue(o1); 155.301 - pushValue(o2); 155.302 - pushValue(o1); 155.303 - } 155.304 - break; 155.305 - 155.306 - case DUP2_X1: 155.307 - // TODO optimize this 155.308 - { 155.309 - Object o1 = popValue(); 155.310 - Object o2 = popValue(); 155.311 - Object o3 = popValue(); 155.312 - pushValue(o2); 155.313 - pushValue(o1); 155.314 - pushValue(o3); 155.315 - pushValue(o2); 155.316 - pushValue(o1); 155.317 - } 155.318 - break; 155.319 - 155.320 - case DUP2_X2: 155.321 - // TODO optimize this 155.322 - { 155.323 - Object o1 = popValue(); 155.324 - Object o2 = popValue(); 155.325 - Object o3 = popValue(); 155.326 - Object o4 = popValue(); 155.327 - pushValue(o2); 155.328 - pushValue(o1); 155.329 - pushValue(o4); 155.330 - pushValue(o3); 155.331 - pushValue(o2); 155.332 - pushValue(o1); 155.333 - } 155.334 - break; 155.335 - 155.336 - case SWAP: 155.337 - { 155.338 - Object o1 = popValue(); 155.339 - Object o2 = popValue(); 155.340 - pushValue(o1); 155.341 - pushValue(o2); 155.342 - } 155.343 - break; 155.344 - } 155.345 - } 155.346 - else 155.347 - { 155.348 - switch(opcode) 155.349 - { 155.350 - case RETURN: 155.351 - case IRETURN: 155.352 - case FRETURN: 155.353 - case ARETURN: 155.354 - case LRETURN: 155.355 - case DRETURN: 155.356 - case ATHROW: 155.357 - onMethodExit(opcode); 155.358 - break; 155.359 - } 155.360 - } 155.361 - mv.visitInsn(opcode); 155.362 -} 155.363 - 155.364 -public void visitVarInsn(final int opcode, final int var){ 155.365 - super.visitVarInsn(opcode, var); 155.366 - 155.367 - if(constructor) 155.368 - { 155.369 - switch(opcode) 155.370 - { 155.371 - case ILOAD: 155.372 - case FLOAD: 155.373 - pushValue(OTHER); 155.374 - break; 155.375 - case LLOAD: 155.376 - case DLOAD: 155.377 - pushValue(OTHER); 155.378 - pushValue(OTHER); 155.379 - break; 155.380 - case ALOAD: 155.381 - pushValue(var == 0 ? THIS : OTHER); 155.382 - break; 155.383 - case ASTORE: 155.384 - case ISTORE: 155.385 - case FSTORE: 155.386 - popValue(); 155.387 - break; 155.388 - case LSTORE: 155.389 - case DSTORE: 155.390 - popValue(); 155.391 - popValue(); 155.392 - break; 155.393 - } 155.394 - } 155.395 -} 155.396 - 155.397 -public void visitFieldInsn( 155.398 - final int opcode, 155.399 - final String owner, 155.400 - final String name, 155.401 - final String desc){ 155.402 - mv.visitFieldInsn(opcode, owner, name, desc); 155.403 - 155.404 - if(constructor) 155.405 - { 155.406 - char c = desc.charAt(0); 155.407 - boolean longOrDouble = c == 'J' || c == 'D'; 155.408 - switch(opcode) 155.409 - { 155.410 - case GETSTATIC: 155.411 - pushValue(OTHER); 155.412 - if(longOrDouble) 155.413 - { 155.414 - pushValue(OTHER); 155.415 - } 155.416 - break; 155.417 - case PUTSTATIC: 155.418 - popValue(); 155.419 - if(longOrDouble) 155.420 - { 155.421 - popValue(); 155.422 - } 155.423 - break; 155.424 - case PUTFIELD: 155.425 - popValue(); 155.426 - if(longOrDouble) 155.427 - { 155.428 - popValue(); 155.429 - popValue(); 155.430 - } 155.431 - break; 155.432 - // case GETFIELD: 155.433 - default: 155.434 - if(longOrDouble) 155.435 - { 155.436 - pushValue(OTHER); 155.437 - } 155.438 - } 155.439 - } 155.440 -} 155.441 - 155.442 -public void visitIntInsn(final int opcode, final int operand){ 155.443 - mv.visitIntInsn(opcode, operand); 155.444 - 155.445 - if(constructor && opcode != NEWARRAY) 155.446 - { 155.447 - pushValue(OTHER); 155.448 - } 155.449 -} 155.450 - 155.451 -public void visitLdcInsn(final Object cst){ 155.452 - mv.visitLdcInsn(cst); 155.453 - 155.454 - if(constructor) 155.455 - { 155.456 - pushValue(OTHER); 155.457 - if(cst instanceof Double || cst instanceof Long) 155.458 - { 155.459 - pushValue(OTHER); 155.460 - } 155.461 - } 155.462 -} 155.463 - 155.464 -public void visitMultiANewArrayInsn(final String desc, final int dims){ 155.465 - mv.visitMultiANewArrayInsn(desc, dims); 155.466 - 155.467 - if(constructor) 155.468 - { 155.469 - for(int i = 0; i < dims; i++) 155.470 - { 155.471 - popValue(); 155.472 - } 155.473 - pushValue(OTHER); 155.474 - } 155.475 -} 155.476 - 155.477 -public void visitTypeInsn(final int opcode, final String name){ 155.478 - mv.visitTypeInsn(opcode, name); 155.479 - 155.480 - // ANEWARRAY, CHECKCAST or INSTANCEOF don't change stack 155.481 - if(constructor && opcode == NEW) 155.482 - { 155.483 - pushValue(OTHER); 155.484 - } 155.485 -} 155.486 - 155.487 -public void visitMethodInsn( 155.488 - final int opcode, 155.489 - final String owner, 155.490 - final String name, 155.491 - final String desc){ 155.492 - mv.visitMethodInsn(opcode, owner, name, desc); 155.493 - 155.494 - if(constructor) 155.495 - { 155.496 - Type[] types = Type.getArgumentTypes(desc); 155.497 - for(int i = 0; i < types.length; i++) 155.498 - { 155.499 - popValue(); 155.500 - if(types[i].getSize() == 2) 155.501 - { 155.502 - popValue(); 155.503 - } 155.504 - } 155.505 - switch(opcode) 155.506 - { 155.507 - // case INVOKESTATIC: 155.508 - // break; 155.509 - 155.510 - case INVOKEINTERFACE: 155.511 - case INVOKEVIRTUAL: 155.512 - popValue(); // objectref 155.513 - break; 155.514 - 155.515 - case INVOKESPECIAL: 155.516 - Object type = popValue(); // objectref 155.517 - if(type == THIS && !superInitialized) 155.518 - { 155.519 - onMethodEnter(); 155.520 - superInitialized = true; 155.521 - // once super has been initialized it is no longer 155.522 - // necessary to keep track of stack state 155.523 - constructor = false; 155.524 - } 155.525 - break; 155.526 - } 155.527 - 155.528 - Type returnType = Type.getReturnType(desc); 155.529 - if(returnType != Type.VOID_TYPE) 155.530 - { 155.531 - pushValue(OTHER); 155.532 - if(returnType.getSize() == 2) 155.533 - { 155.534 - pushValue(OTHER); 155.535 - } 155.536 - } 155.537 - } 155.538 -} 155.539 - 155.540 -public void visitJumpInsn(final int opcode, final Label label){ 155.541 - mv.visitJumpInsn(opcode, label); 155.542 - 155.543 - if(constructor) 155.544 - { 155.545 - switch(opcode) 155.546 - { 155.547 - case IFEQ: 155.548 - case IFNE: 155.549 - case IFLT: 155.550 - case IFGE: 155.551 - case IFGT: 155.552 - case IFLE: 155.553 - case IFNULL: 155.554 - case IFNONNULL: 155.555 - popValue(); 155.556 - break; 155.557 - 155.558 - case IF_ICMPEQ: 155.559 - case IF_ICMPNE: 155.560 - case IF_ICMPLT: 155.561 - case IF_ICMPGE: 155.562 - case IF_ICMPGT: 155.563 - case IF_ICMPLE: 155.564 - case IF_ACMPEQ: 155.565 - case IF_ACMPNE: 155.566 - popValue(); 155.567 - popValue(); 155.568 - break; 155.569 - 155.570 - case JSR: 155.571 - pushValue(OTHER); 155.572 - break; 155.573 - } 155.574 - addBranch(label); 155.575 - } 155.576 -} 155.577 - 155.578 -public void visitLookupSwitchInsn( 155.579 - final Label dflt, 155.580 - final int[] keys, 155.581 - final Label[] labels){ 155.582 - mv.visitLookupSwitchInsn(dflt, keys, labels); 155.583 - 155.584 - if(constructor) 155.585 - { 155.586 - popValue(); 155.587 - addBranches(dflt, labels); 155.588 - } 155.589 -} 155.590 - 155.591 -public void visitTableSwitchInsn( 155.592 - final int min, 155.593 - final int max, 155.594 - final Label dflt, 155.595 - final Label[] labels){ 155.596 - mv.visitTableSwitchInsn(min, max, dflt, labels); 155.597 - 155.598 - if(constructor) 155.599 - { 155.600 - popValue(); 155.601 - addBranches(dflt, labels); 155.602 - } 155.603 -} 155.604 - 155.605 -private void addBranches(final Label dflt, final Label[] labels){ 155.606 - addBranch(dflt); 155.607 - for(int i = 0; i < labels.length; i++) 155.608 - { 155.609 - addBranch(labels[i]); 155.610 - } 155.611 -} 155.612 - 155.613 -private void addBranch(final Label label){ 155.614 - if(branches.containsKey(label)) 155.615 - { 155.616 - return; 155.617 - } 155.618 - ArrayList frame = new ArrayList(); 155.619 - frame.addAll(stackFrame); 155.620 - branches.put(label, frame); 155.621 -} 155.622 - 155.623 -private Object popValue(){ 155.624 - return stackFrame.remove(stackFrame.size() - 1); 155.625 -} 155.626 - 155.627 -private Object peekValue(){ 155.628 - return stackFrame.get(stackFrame.size() - 1); 155.629 -} 155.630 - 155.631 -private void pushValue(final Object o){ 155.632 - stackFrame.add(o); 155.633 -} 155.634 - 155.635 -/** 155.636 - * Called at the beginning of the method or after super class class call in 155.637 - * the constructor. <br><br> 155.638 - * <p/> 155.639 - * <i>Custom code can use or change all the local variables, but should not 155.640 - * change state of the stack.</i> 155.641 - */ 155.642 -protected abstract void onMethodEnter(); 155.643 - 155.644 -/** 155.645 - * Called before explicit exit from the method using either return or throw. 155.646 - * Top element on the stack contains the return value or exception instance. 155.647 - * For example: 155.648 - * <p/> 155.649 - * <pre> 155.650 - * public void onMethodExit(int opcode) { 155.651 - * if(opcode==RETURN) { 155.652 - * visitInsn(ACONST_NULL); 155.653 - * } else if(opcode==ARETURN || opcode==ATHROW) { 155.654 - * dup(); 155.655 - * } else { 155.656 - * if(opcode==LRETURN || opcode==DRETURN) { 155.657 - * dup2(); 155.658 - * } else { 155.659 - * dup(); 155.660 - * } 155.661 - * box(Type.getReturnType(this.methodDesc)); 155.662 - * } 155.663 - * visitIntInsn(SIPUSH, opcode); 155.664 - * visitMethodInsn(INVOKESTATIC, owner, "onExit", "(Ljava/lang/Object;I)V"); 155.665 - * } 155.666 - * <p/> 155.667 - * // an actual call back method 155.668 - * public static void onExit(int opcode, Object param) { 155.669 - * ... 155.670 - * </pre> 155.671 - * <p/> 155.672 - * <br><br> 155.673 - * <p/> 155.674 - * <i>Custom code can use or change all the local variables, but should not 155.675 - * change state of the stack.</i> 155.676 - * 155.677 - * @param opcode one of the RETURN, IRETURN, FRETURN, ARETURN, LRETURN, 155.678 - * DRETURN or ATHROW 155.679 - */ 155.680 -protected abstract void onMethodExit(int opcode); 155.681 - 155.682 -// TODO onException, onMethodCall 155.683 - 155.684 -}
156.1 --- a/src/clojure/asm/commons/AnalyzerAdapter.java Sat Aug 21 06:25:44 2010 -0400 156.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 156.3 @@ -1,938 +0,0 @@ 156.4 -/*** 156.5 - * ASM: a very small and fast Java bytecode manipulation framework 156.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 156.7 - * All rights reserved. 156.8 - * 156.9 - * Redistribution and use in source and binary forms, with or without 156.10 - * modification, are permitted provided that the following conditions 156.11 - * are met: 156.12 - * 1. Redistributions of source code must retain the above copyright 156.13 - * notice, this list of conditions and the following disclaimer. 156.14 - * 2. Redistributions in binary form must reproduce the above copyright 156.15 - * notice, this list of conditions and the following disclaimer in the 156.16 - * documentation and/or other materials provided with the distribution. 156.17 - * 3. Neither the name of the copyright holders nor the names of its 156.18 - * contributors may be used to endorse or promote products derived from 156.19 - * this software without specific prior written permission. 156.20 - * 156.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 156.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 156.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 156.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 156.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 156.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 156.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 156.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 156.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 156.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 156.31 - * THE POSSIBILITY OF SUCH DAMAGE. 156.32 - */ 156.33 -package clojure.asm.commons; 156.34 - 156.35 -import java.util.ArrayList; 156.36 -import java.util.HashMap; 156.37 -import java.util.List; 156.38 -import java.util.Map; 156.39 - 156.40 -import clojure.asm.Label; 156.41 -import clojure.asm.MethodAdapter; 156.42 -import clojure.asm.MethodVisitor; 156.43 -import clojure.asm.Opcodes; 156.44 -import clojure.asm.Type; 156.45 - 156.46 -/** 156.47 - * A {@link MethodAdapter} that keeps track of stack map frame changes between 156.48 - * {@link #visitFrame(int,int,Object[],int,Object[]) visitFrame} calls. This 156.49 - * adapter must be used with the 156.50 - * {@link clojure.asm.ClassReader#EXPAND_FRAMES} option. Each visit<i>XXX</i> 156.51 - * instruction delegates to the next visitor in the chain, if any, and then 156.52 - * simulates the effect of this instruction on the stack map frame, represented 156.53 - * by {@link #locals} and {@link #stack}. The next visitor in the chain can get 156.54 - * the state of the stack map frame <i>before</i> each instruction by reading 156.55 - * the value of these fields in its visit<i>XXX</i> methods (this requires a 156.56 - * reference to the AnalyzerAdapter that is before it in the chain). 156.57 - * 156.58 - * @author Eric Bruneton 156.59 - */ 156.60 -public class AnalyzerAdapter extends MethodAdapter{ 156.61 - 156.62 -/** 156.63 - * <code>List</code> of the local variable slots for current execution 156.64 - * frame. Primitive types are represented by {@link Opcodes#TOP}, 156.65 - * {@link Opcodes#INTEGER}, {@link Opcodes#FLOAT}, {@link Opcodes#LONG}, 156.66 - * {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or 156.67 - * {@link Opcodes#UNINITIALIZED_THIS} (long and double are represented by a 156.68 - * two elements, the second one being TOP). Reference types are represented 156.69 - * by String objects (representing internal names, or type descriptors for 156.70 - * array types), and uninitialized types by Label objects (this label 156.71 - * designates the NEW instruction that created this uninitialized value). 156.72 - * This field is <tt>null</tt> for unreacheable instructions. 156.73 - */ 156.74 -public List locals; 156.75 - 156.76 -/** 156.77 - * <code>List</code> of the operand stack slots for current execution 156.78 - * frame. Primitive types are represented by {@link Opcodes#TOP}, 156.79 - * {@link Opcodes#INTEGER}, {@link Opcodes#FLOAT}, {@link Opcodes#LONG}, 156.80 - * {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or 156.81 - * {@link Opcodes#UNINITIALIZED_THIS} (long and double are represented by a 156.82 - * two elements, the second one being TOP). Reference types are represented 156.83 - * by String objects (representing internal names, or type descriptors for 156.84 - * array types), and uninitialized types by Label objects (this label 156.85 - * designates the NEW instruction that created this uninitialized value). 156.86 - * This field is <tt>null</tt> for unreacheable instructions. 156.87 - */ 156.88 -public List stack; 156.89 - 156.90 -/** 156.91 - * The labels that designate the next instruction to be visited. May be 156.92 - * <tt>null</tt>. 156.93 - */ 156.94 -private List labels; 156.95 - 156.96 -/** 156.97 - * Information about uninitialized types in the current execution frame. 156.98 - * This map associates internal names to Label objects. Each label 156.99 - * designates a NEW instruction that created the currently uninitialized 156.100 - * types, and the associated internal name represents the NEW operand, i.e. 156.101 - * the final, initialized type value. 156.102 - */ 156.103 -private Map uninitializedTypes; 156.104 - 156.105 -/** 156.106 - * The maximum stack size of this method. 156.107 - */ 156.108 -private int maxStack; 156.109 - 156.110 -/** 156.111 - * The maximum number of local variables of this method. 156.112 - */ 156.113 -private int maxLocals; 156.114 - 156.115 -/** 156.116 - * Creates a new {@link AnalyzerAdapter}. 156.117 - * 156.118 - * @param owner the owner's class name. 156.119 - * @param access the method's access flags (see {@link Opcodes}). 156.120 - * @param name the method's name. 156.121 - * @param desc the method's descriptor (see {@link Type Type}). 156.122 - * @param mv the method visitor to which this adapter delegates calls. May 156.123 - * be <tt>null</tt>. 156.124 - */ 156.125 -public AnalyzerAdapter( 156.126 - final String owner, 156.127 - final int access, 156.128 - final String name, 156.129 - final String desc, 156.130 - final MethodVisitor mv){ 156.131 - super(mv); 156.132 - locals = new ArrayList(); 156.133 - stack = new ArrayList(); 156.134 - uninitializedTypes = new HashMap(); 156.135 - 156.136 - if((access & Opcodes.ACC_STATIC) == 0) 156.137 - { 156.138 - if(name.equals("<init>")) 156.139 - { 156.140 - locals.add(Opcodes.UNINITIALIZED_THIS); 156.141 - } 156.142 - else 156.143 - { 156.144 - locals.add(owner); 156.145 - } 156.146 - } 156.147 - Type[] types = Type.getArgumentTypes(desc); 156.148 - for(int i = 0; i < types.length; ++i) 156.149 - { 156.150 - Type type = types[i]; 156.151 - switch(type.getSort()) 156.152 - { 156.153 - case Type.BOOLEAN: 156.154 - case Type.CHAR: 156.155 - case Type.BYTE: 156.156 - case Type.SHORT: 156.157 - case Type.INT: 156.158 - locals.add(Opcodes.INTEGER); 156.159 - break; 156.160 - case Type.FLOAT: 156.161 - locals.add(Opcodes.FLOAT); 156.162 - break; 156.163 - case Type.LONG: 156.164 - locals.add(Opcodes.LONG); 156.165 - locals.add(Opcodes.TOP); 156.166 - break; 156.167 - case Type.DOUBLE: 156.168 - locals.add(Opcodes.DOUBLE); 156.169 - locals.add(Opcodes.TOP); 156.170 - break; 156.171 - case Type.ARRAY: 156.172 - locals.add(types[i].getDescriptor()); 156.173 - break; 156.174 - // case Type.OBJECT: 156.175 - default: 156.176 - locals.add(types[i].getInternalName()); 156.177 - } 156.178 - } 156.179 -} 156.180 - 156.181 -public void visitFrame( 156.182 - final int type, 156.183 - final int nLocal, 156.184 - final Object[] local, 156.185 - final int nStack, 156.186 - final Object[] stack){ 156.187 - if(type != Opcodes.F_NEW) 156.188 - { // uncompressed frame 156.189 - throw new IllegalStateException("ClassReader.accept() should be called with EXPAND_FRAMES flag"); 156.190 - } 156.191 - 156.192 - if(mv != null) 156.193 - { 156.194 - mv.visitFrame(type, nLocal, local, nStack, stack); 156.195 - } 156.196 - 156.197 - if(this.locals != null) 156.198 - { 156.199 - this.locals.clear(); 156.200 - this.stack.clear(); 156.201 - } 156.202 - else 156.203 - { 156.204 - this.locals = new ArrayList(); 156.205 - this.stack = new ArrayList(); 156.206 - } 156.207 - visitFrameTypes(nLocal, local, this.locals); 156.208 - visitFrameTypes(nStack, stack, this.stack); 156.209 - maxStack = Math.max(maxStack, this.stack.size()); 156.210 -} 156.211 - 156.212 -private void visitFrameTypes( 156.213 - final int n, 156.214 - final Object[] types, 156.215 - final List result){ 156.216 - for(int i = 0; i < n; ++i) 156.217 - { 156.218 - Object type = types[i]; 156.219 - result.add(type); 156.220 - if(type == Opcodes.LONG || type == Opcodes.DOUBLE) 156.221 - { 156.222 - result.add(Opcodes.TOP); 156.223 - } 156.224 - } 156.225 -} 156.226 - 156.227 -public void visitInsn(final int opcode){ 156.228 - if(mv != null) 156.229 - { 156.230 - mv.visitInsn(opcode); 156.231 - } 156.232 - execute(opcode, 0, null); 156.233 - if((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) 156.234 - || opcode == Opcodes.ATHROW) 156.235 - { 156.236 - this.locals = null; 156.237 - this.stack = null; 156.238 - } 156.239 -} 156.240 - 156.241 -public void visitIntInsn(final int opcode, final int operand){ 156.242 - if(mv != null) 156.243 - { 156.244 - mv.visitIntInsn(opcode, operand); 156.245 - } 156.246 - execute(opcode, operand, null); 156.247 -} 156.248 - 156.249 -public void visitVarInsn(final int opcode, final int var){ 156.250 - if(mv != null) 156.251 - { 156.252 - mv.visitVarInsn(opcode, var); 156.253 - } 156.254 - execute(opcode, var, null); 156.255 -} 156.256 - 156.257 -public void visitTypeInsn(final int opcode, final String desc){ 156.258 - if(opcode == Opcodes.NEW) 156.259 - { 156.260 - if(labels == null) 156.261 - { 156.262 - Label l = new Label(); 156.263 - labels = new ArrayList(3); 156.264 - labels.add(l); 156.265 - if(mv != null) 156.266 - { 156.267 - mv.visitLabel(l); 156.268 - } 156.269 - } 156.270 - for(int i = 0; i < labels.size(); ++i) 156.271 - { 156.272 - uninitializedTypes.put(labels.get(i), desc); 156.273 - } 156.274 - } 156.275 - if(mv != null) 156.276 - { 156.277 - mv.visitTypeInsn(opcode, desc); 156.278 - } 156.279 - execute(opcode, 0, desc); 156.280 -} 156.281 - 156.282 -public void visitFieldInsn( 156.283 - final int opcode, 156.284 - final String owner, 156.285 - final String name, 156.286 - final String desc){ 156.287 - if(mv != null) 156.288 - { 156.289 - mv.visitFieldInsn(opcode, owner, name, desc); 156.290 - } 156.291 - execute(opcode, 0, desc); 156.292 -} 156.293 - 156.294 -public void visitMethodInsn( 156.295 - final int opcode, 156.296 - final String owner, 156.297 - final String name, 156.298 - final String desc){ 156.299 - if(mv != null) 156.300 - { 156.301 - mv.visitMethodInsn(opcode, owner, name, desc); 156.302 - } 156.303 - pop(desc); 156.304 - if(opcode != Opcodes.INVOKESTATIC) 156.305 - { 156.306 - Object t = pop(); 156.307 - if(opcode == Opcodes.INVOKESPECIAL && name.charAt(0) == '<') 156.308 - { 156.309 - Object u; 156.310 - if(t == Opcodes.UNINITIALIZED_THIS) 156.311 - { 156.312 - u = owner; 156.313 - } 156.314 - else 156.315 - { 156.316 - u = uninitializedTypes.get(t); 156.317 - } 156.318 - for(int i = 0; i < locals.size(); ++i) 156.319 - { 156.320 - if(locals.get(i) == t) 156.321 - { 156.322 - locals.set(i, u); 156.323 - } 156.324 - } 156.325 - for(int i = 0; i < stack.size(); ++i) 156.326 - { 156.327 - if(stack.get(i) == t) 156.328 - { 156.329 - stack.set(i, u); 156.330 - } 156.331 - } 156.332 - } 156.333 - } 156.334 - pushDesc(desc); 156.335 - labels = null; 156.336 -} 156.337 - 156.338 -public void visitJumpInsn(final int opcode, final Label label){ 156.339 - if(mv != null) 156.340 - { 156.341 - mv.visitJumpInsn(opcode, label); 156.342 - } 156.343 - execute(opcode, 0, null); 156.344 - if(opcode == Opcodes.GOTO) 156.345 - { 156.346 - this.locals = null; 156.347 - this.stack = null; 156.348 - } 156.349 -} 156.350 - 156.351 -public void visitLabel(final Label label){ 156.352 - if(mv != null) 156.353 - { 156.354 - mv.visitLabel(label); 156.355 - } 156.356 - if(labels == null) 156.357 - { 156.358 - labels = new ArrayList(3); 156.359 - } 156.360 - labels.add(label); 156.361 -} 156.362 - 156.363 -public void visitLdcInsn(final Object cst){ 156.364 - if(mv != null) 156.365 - { 156.366 - mv.visitLdcInsn(cst); 156.367 - } 156.368 - if(cst instanceof Integer) 156.369 - { 156.370 - push(Opcodes.INTEGER); 156.371 - } 156.372 - else if(cst instanceof Long) 156.373 - { 156.374 - push(Opcodes.LONG); 156.375 - push(Opcodes.TOP); 156.376 - } 156.377 - else if(cst instanceof Float) 156.378 - { 156.379 - push(Opcodes.FLOAT); 156.380 - } 156.381 - else if(cst instanceof Double) 156.382 - { 156.383 - push(Opcodes.DOUBLE); 156.384 - push(Opcodes.TOP); 156.385 - } 156.386 - else if(cst instanceof String) 156.387 - { 156.388 - push("java/lang/String"); 156.389 - } 156.390 - else if(cst instanceof Type) 156.391 - { 156.392 - push("java/lang/Class"); 156.393 - } 156.394 - else 156.395 - { 156.396 - throw new IllegalArgumentException(); 156.397 - } 156.398 - labels = null; 156.399 -} 156.400 - 156.401 -public void visitIincInsn(final int var, final int increment){ 156.402 - if(mv != null) 156.403 - { 156.404 - mv.visitIincInsn(var, increment); 156.405 - } 156.406 - execute(Opcodes.IINC, var, null); 156.407 -} 156.408 - 156.409 -public void visitTableSwitchInsn( 156.410 - final int min, 156.411 - final int max, 156.412 - final Label dflt, 156.413 - final Label labels[]){ 156.414 - if(mv != null) 156.415 - { 156.416 - mv.visitTableSwitchInsn(min, max, dflt, labels); 156.417 - } 156.418 - execute(Opcodes.TABLESWITCH, 0, null); 156.419 - this.locals = null; 156.420 - this.stack = null; 156.421 -} 156.422 - 156.423 -public void visitLookupSwitchInsn( 156.424 - final Label dflt, 156.425 - final int keys[], 156.426 - final Label labels[]){ 156.427 - if(mv != null) 156.428 - { 156.429 - mv.visitLookupSwitchInsn(dflt, keys, labels); 156.430 - } 156.431 - execute(Opcodes.LOOKUPSWITCH, 0, null); 156.432 - this.locals = null; 156.433 - this.stack = null; 156.434 -} 156.435 - 156.436 -public void visitMultiANewArrayInsn(final String desc, final int dims){ 156.437 - if(mv != null) 156.438 - { 156.439 - mv.visitMultiANewArrayInsn(desc, dims); 156.440 - } 156.441 - execute(Opcodes.MULTIANEWARRAY, dims, desc); 156.442 -} 156.443 - 156.444 -public void visitMaxs(final int maxStack, final int maxLocals){ 156.445 - if(mv != null) 156.446 - { 156.447 - this.maxStack = Math.max(this.maxStack, maxStack); 156.448 - this.maxLocals = Math.max(this.maxLocals, maxLocals); 156.449 - mv.visitMaxs(this.maxStack, this.maxLocals); 156.450 - } 156.451 -} 156.452 - 156.453 -// ------------------------------------------------------------------------ 156.454 - 156.455 -private Object get(final int local){ 156.456 - maxLocals = Math.max(maxLocals, local); 156.457 - return local < locals.size() ? locals.get(local) : Opcodes.TOP; 156.458 -} 156.459 - 156.460 -private void set(final int local, final Object type){ 156.461 - maxLocals = Math.max(maxLocals, local); 156.462 - while(local >= locals.size()) 156.463 - { 156.464 - locals.add(Opcodes.TOP); 156.465 - } 156.466 - locals.set(local, type); 156.467 -} 156.468 - 156.469 -private void push(final Object type){ 156.470 - stack.add(type); 156.471 - maxStack = Math.max(maxStack, stack.size()); 156.472 -} 156.473 - 156.474 -private void pushDesc(final String desc){ 156.475 - int index = desc.charAt(0) == '(' ? desc.indexOf(')') + 1 : 0; 156.476 - switch(desc.charAt(index)) 156.477 - { 156.478 - case'V': 156.479 - return; 156.480 - case'Z': 156.481 - case'C': 156.482 - case'B': 156.483 - case'S': 156.484 - case'I': 156.485 - push(Opcodes.INTEGER); 156.486 - return; 156.487 - case'F': 156.488 - push(Opcodes.FLOAT); 156.489 - return; 156.490 - case'J': 156.491 - push(Opcodes.LONG); 156.492 - push(Opcodes.TOP); 156.493 - return; 156.494 - case'D': 156.495 - push(Opcodes.DOUBLE); 156.496 - push(Opcodes.TOP); 156.497 - return; 156.498 - case'[': 156.499 - if(index == 0) 156.500 - { 156.501 - push(desc); 156.502 - } 156.503 - else 156.504 - { 156.505 - push(desc.substring(index, desc.length())); 156.506 - } 156.507 - break; 156.508 - // case 'L': 156.509 - default: 156.510 - if(index == 0) 156.511 - { 156.512 - push(desc.substring(1, desc.length() - 1)); 156.513 - } 156.514 - else 156.515 - { 156.516 - push(desc.substring(index + 1, desc.length() - 1)); 156.517 - } 156.518 - return; 156.519 - } 156.520 -} 156.521 - 156.522 -private Object pop(){ 156.523 - return stack.remove(stack.size() - 1); 156.524 -} 156.525 - 156.526 -private void pop(final int n){ 156.527 - int size = stack.size(); 156.528 - int end = size - n; 156.529 - for(int i = size - 1; i >= end; --i) 156.530 - { 156.531 - stack.remove(i); 156.532 - } 156.533 -} 156.534 - 156.535 -private void pop(final String desc){ 156.536 - char c = desc.charAt(0); 156.537 - if(c == '(') 156.538 - { 156.539 - int n = 0; 156.540 - Type[] types = Type.getArgumentTypes(desc); 156.541 - for(int i = 0; i < types.length; ++i) 156.542 - { 156.543 - n += types[i].getSize(); 156.544 - } 156.545 - pop(n); 156.546 - } 156.547 - else if(c == 'J' || c == 'D') 156.548 - { 156.549 - pop(2); 156.550 - } 156.551 - else 156.552 - { 156.553 - pop(1); 156.554 - } 156.555 -} 156.556 - 156.557 -private void execute(final int opcode, final int iarg, final String sarg){ 156.558 - if(this.locals == null) 156.559 - { 156.560 - return; 156.561 - } 156.562 - Object t1, t2, t3, t4; 156.563 - switch(opcode) 156.564 - { 156.565 - case Opcodes.NOP: 156.566 - case Opcodes.INEG: 156.567 - case Opcodes.LNEG: 156.568 - case Opcodes.FNEG: 156.569 - case Opcodes.DNEG: 156.570 - case Opcodes.I2B: 156.571 - case Opcodes.I2C: 156.572 - case Opcodes.I2S: 156.573 - case Opcodes.GOTO: 156.574 - case Opcodes.RETURN: 156.575 - break; 156.576 - case Opcodes.ACONST_NULL: 156.577 - push(Opcodes.NULL); 156.578 - break; 156.579 - case Opcodes.ICONST_M1: 156.580 - case Opcodes.ICONST_0: 156.581 - case Opcodes.ICONST_1: 156.582 - case Opcodes.ICONST_2: 156.583 - case Opcodes.ICONST_3: 156.584 - case Opcodes.ICONST_4: 156.585 - case Opcodes.ICONST_5: 156.586 - case Opcodes.BIPUSH: 156.587 - case Opcodes.SIPUSH: 156.588 - push(Opcodes.INTEGER); 156.589 - break; 156.590 - case Opcodes.LCONST_0: 156.591 - case Opcodes.LCONST_1: 156.592 - push(Opcodes.LONG); 156.593 - push(Opcodes.TOP); 156.594 - break; 156.595 - case Opcodes.FCONST_0: 156.596 - case Opcodes.FCONST_1: 156.597 - case Opcodes.FCONST_2: 156.598 - push(Opcodes.FLOAT); 156.599 - break; 156.600 - case Opcodes.DCONST_0: 156.601 - case Opcodes.DCONST_1: 156.602 - push(Opcodes.DOUBLE); 156.603 - push(Opcodes.TOP); 156.604 - break; 156.605 - case Opcodes.ILOAD: 156.606 - case Opcodes.FLOAD: 156.607 - case Opcodes.ALOAD: 156.608 - push(get(iarg)); 156.609 - break; 156.610 - case Opcodes.LLOAD: 156.611 - case Opcodes.DLOAD: 156.612 - push(get(iarg)); 156.613 - push(Opcodes.TOP); 156.614 - break; 156.615 - case Opcodes.IALOAD: 156.616 - case Opcodes.BALOAD: 156.617 - case Opcodes.CALOAD: 156.618 - case Opcodes.SALOAD: 156.619 - pop(2); 156.620 - push(Opcodes.INTEGER); 156.621 - break; 156.622 - case Opcodes.LALOAD: 156.623 - case Opcodes.D2L: 156.624 - pop(2); 156.625 - push(Opcodes.LONG); 156.626 - push(Opcodes.TOP); 156.627 - break; 156.628 - case Opcodes.FALOAD: 156.629 - pop(2); 156.630 - push(Opcodes.FLOAT); 156.631 - break; 156.632 - case Opcodes.DALOAD: 156.633 - case Opcodes.L2D: 156.634 - pop(2); 156.635 - push(Opcodes.DOUBLE); 156.636 - push(Opcodes.TOP); 156.637 - break; 156.638 - case Opcodes.AALOAD: 156.639 - pop(1); 156.640 - t1 = pop(); 156.641 - pushDesc(((String) t1).substring(1)); 156.642 - break; 156.643 - case Opcodes.ISTORE: 156.644 - case Opcodes.FSTORE: 156.645 - case Opcodes.ASTORE: 156.646 - t1 = pop(); 156.647 - set(iarg, t1); 156.648 - if(iarg > 0) 156.649 - { 156.650 - t2 = get(iarg - 1); 156.651 - if(t2 == Opcodes.LONG || t2 == Opcodes.DOUBLE) 156.652 - { 156.653 - set(iarg - 1, Opcodes.TOP); 156.654 - } 156.655 - } 156.656 - break; 156.657 - case Opcodes.LSTORE: 156.658 - case Opcodes.DSTORE: 156.659 - pop(1); 156.660 - t1 = pop(); 156.661 - set(iarg, t1); 156.662 - set(iarg + 1, Opcodes.TOP); 156.663 - if(iarg > 0) 156.664 - { 156.665 - t2 = get(iarg - 1); 156.666 - if(t2 == Opcodes.LONG || t2 == Opcodes.DOUBLE) 156.667 - { 156.668 - set(iarg - 1, Opcodes.TOP); 156.669 - } 156.670 - } 156.671 - break; 156.672 - case Opcodes.IASTORE: 156.673 - case Opcodes.BASTORE: 156.674 - case Opcodes.CASTORE: 156.675 - case Opcodes.SASTORE: 156.676 - case Opcodes.FASTORE: 156.677 - case Opcodes.AASTORE: 156.678 - pop(3); 156.679 - break; 156.680 - case Opcodes.LASTORE: 156.681 - case Opcodes.DASTORE: 156.682 - pop(4); 156.683 - break; 156.684 - case Opcodes.POP: 156.685 - case Opcodes.IFEQ: 156.686 - case Opcodes.IFNE: 156.687 - case Opcodes.IFLT: 156.688 - case Opcodes.IFGE: 156.689 - case Opcodes.IFGT: 156.690 - case Opcodes.IFLE: 156.691 - case Opcodes.IRETURN: 156.692 - case Opcodes.FRETURN: 156.693 - case Opcodes.ARETURN: 156.694 - case Opcodes.TABLESWITCH: 156.695 - case Opcodes.LOOKUPSWITCH: 156.696 - case Opcodes.ATHROW: 156.697 - case Opcodes.MONITORENTER: 156.698 - case Opcodes.MONITOREXIT: 156.699 - case Opcodes.IFNULL: 156.700 - case Opcodes.IFNONNULL: 156.701 - pop(1); 156.702 - break; 156.703 - case Opcodes.POP2: 156.704 - case Opcodes.IF_ICMPEQ: 156.705 - case Opcodes.IF_ICMPNE: 156.706 - case Opcodes.IF_ICMPLT: 156.707 - case Opcodes.IF_ICMPGE: 156.708 - case Opcodes.IF_ICMPGT: 156.709 - case Opcodes.IF_ICMPLE: 156.710 - case Opcodes.IF_ACMPEQ: 156.711 - case Opcodes.IF_ACMPNE: 156.712 - case Opcodes.LRETURN: 156.713 - case Opcodes.DRETURN: 156.714 - pop(2); 156.715 - break; 156.716 - case Opcodes.DUP: 156.717 - t1 = pop(); 156.718 - push(t1); 156.719 - push(t1); 156.720 - break; 156.721 - case Opcodes.DUP_X1: 156.722 - t1 = pop(); 156.723 - t2 = pop(); 156.724 - push(t1); 156.725 - push(t2); 156.726 - push(t1); 156.727 - break; 156.728 - case Opcodes.DUP_X2: 156.729 - t1 = pop(); 156.730 - t2 = pop(); 156.731 - t3 = pop(); 156.732 - push(t1); 156.733 - push(t3); 156.734 - push(t2); 156.735 - push(t1); 156.736 - break; 156.737 - case Opcodes.DUP2: 156.738 - t1 = pop(); 156.739 - t2 = pop(); 156.740 - push(t2); 156.741 - push(t1); 156.742 - push(t2); 156.743 - push(t1); 156.744 - break; 156.745 - case Opcodes.DUP2_X1: 156.746 - t1 = pop(); 156.747 - t2 = pop(); 156.748 - t3 = pop(); 156.749 - push(t2); 156.750 - push(t1); 156.751 - push(t3); 156.752 - push(t2); 156.753 - push(t1); 156.754 - break; 156.755 - case Opcodes.DUP2_X2: 156.756 - t1 = pop(); 156.757 - t2 = pop(); 156.758 - t3 = pop(); 156.759 - t4 = pop(); 156.760 - push(t2); 156.761 - push(t1); 156.762 - push(t4); 156.763 - push(t3); 156.764 - push(t2); 156.765 - push(t1); 156.766 - break; 156.767 - case Opcodes.SWAP: 156.768 - t1 = pop(); 156.769 - t2 = pop(); 156.770 - push(t1); 156.771 - push(t2); 156.772 - break; 156.773 - case Opcodes.IADD: 156.774 - case Opcodes.ISUB: 156.775 - case Opcodes.IMUL: 156.776 - case Opcodes.IDIV: 156.777 - case Opcodes.IREM: 156.778 - case Opcodes.IAND: 156.779 - case Opcodes.IOR: 156.780 - case Opcodes.IXOR: 156.781 - case Opcodes.ISHL: 156.782 - case Opcodes.ISHR: 156.783 - case Opcodes.IUSHR: 156.784 - case Opcodes.L2I: 156.785 - case Opcodes.D2I: 156.786 - case Opcodes.FCMPL: 156.787 - case Opcodes.FCMPG: 156.788 - pop(2); 156.789 - push(Opcodes.INTEGER); 156.790 - break; 156.791 - case Opcodes.LADD: 156.792 - case Opcodes.LSUB: 156.793 - case Opcodes.LMUL: 156.794 - case Opcodes.LDIV: 156.795 - case Opcodes.LREM: 156.796 - case Opcodes.LAND: 156.797 - case Opcodes.LOR: 156.798 - case Opcodes.LXOR: 156.799 - pop(4); 156.800 - push(Opcodes.LONG); 156.801 - push(Opcodes.TOP); 156.802 - break; 156.803 - case Opcodes.FADD: 156.804 - case Opcodes.FSUB: 156.805 - case Opcodes.FMUL: 156.806 - case Opcodes.FDIV: 156.807 - case Opcodes.FREM: 156.808 - case Opcodes.L2F: 156.809 - case Opcodes.D2F: 156.810 - pop(2); 156.811 - push(Opcodes.FLOAT); 156.812 - break; 156.813 - case Opcodes.DADD: 156.814 - case Opcodes.DSUB: 156.815 - case Opcodes.DMUL: 156.816 - case Opcodes.DDIV: 156.817 - case Opcodes.DREM: 156.818 - pop(4); 156.819 - push(Opcodes.DOUBLE); 156.820 - push(Opcodes.TOP); 156.821 - break; 156.822 - case Opcodes.LSHL: 156.823 - case Opcodes.LSHR: 156.824 - case Opcodes.LUSHR: 156.825 - pop(3); 156.826 - push(Opcodes.LONG); 156.827 - push(Opcodes.TOP); 156.828 - break; 156.829 - case Opcodes.IINC: 156.830 - set(iarg, Opcodes.INTEGER); 156.831 - break; 156.832 - case Opcodes.I2L: 156.833 - case Opcodes.F2L: 156.834 - pop(1); 156.835 - push(Opcodes.LONG); 156.836 - push(Opcodes.TOP); 156.837 - break; 156.838 - case Opcodes.I2F: 156.839 - pop(1); 156.840 - push(Opcodes.FLOAT); 156.841 - break; 156.842 - case Opcodes.I2D: 156.843 - case Opcodes.F2D: 156.844 - pop(1); 156.845 - push(Opcodes.DOUBLE); 156.846 - push(Opcodes.TOP); 156.847 - break; 156.848 - case Opcodes.F2I: 156.849 - case Opcodes.ARRAYLENGTH: 156.850 - case Opcodes.INSTANCEOF: 156.851 - pop(1); 156.852 - push(Opcodes.INTEGER); 156.853 - break; 156.854 - case Opcodes.LCMP: 156.855 - case Opcodes.DCMPL: 156.856 - case Opcodes.DCMPG: 156.857 - pop(4); 156.858 - push(Opcodes.INTEGER); 156.859 - break; 156.860 - case Opcodes.JSR: 156.861 - case Opcodes.RET: 156.862 - throw new RuntimeException("JSR/RET are not supported"); 156.863 - case Opcodes.GETSTATIC: 156.864 - pushDesc(sarg); 156.865 - break; 156.866 - case Opcodes.PUTSTATIC: 156.867 - pop(sarg); 156.868 - break; 156.869 - case Opcodes.GETFIELD: 156.870 - pop(1); 156.871 - pushDesc(sarg); 156.872 - break; 156.873 - case Opcodes.PUTFIELD: 156.874 - pop(sarg); 156.875 - pop(); 156.876 - break; 156.877 - case Opcodes.NEW: 156.878 - push(labels.get(0)); 156.879 - break; 156.880 - case Opcodes.NEWARRAY: 156.881 - pop(); 156.882 - switch(iarg) 156.883 - { 156.884 - case Opcodes.T_BOOLEAN: 156.885 - pushDesc("[Z"); 156.886 - break; 156.887 - case Opcodes.T_CHAR: 156.888 - pushDesc("[C"); 156.889 - break; 156.890 - case Opcodes.T_BYTE: 156.891 - pushDesc("[B"); 156.892 - break; 156.893 - case Opcodes.T_SHORT: 156.894 - pushDesc("[S"); 156.895 - break; 156.896 - case Opcodes.T_INT: 156.897 - pushDesc("[I"); 156.898 - break; 156.899 - case Opcodes.T_FLOAT: 156.900 - pushDesc("[F"); 156.901 - break; 156.902 - case Opcodes.T_DOUBLE: 156.903 - pushDesc("[D"); 156.904 - break; 156.905 - // case Opcodes.T_LONG: 156.906 - default: 156.907 - pushDesc("[J"); 156.908 - break; 156.909 - } 156.910 - break; 156.911 - case Opcodes.ANEWARRAY: 156.912 - pop(); 156.913 - if(sarg.charAt(0) == '[') 156.914 - { 156.915 - pushDesc("[" + sarg); 156.916 - } 156.917 - else 156.918 - { 156.919 - pushDesc("[L" + sarg + ";"); 156.920 - } 156.921 - break; 156.922 - case Opcodes.CHECKCAST: 156.923 - pop(); 156.924 - if(sarg.charAt(0) == '[') 156.925 - { 156.926 - pushDesc(sarg); 156.927 - } 156.928 - else 156.929 - { 156.930 - push(sarg); 156.931 - } 156.932 - break; 156.933 - // case Opcodes.MULTIANEWARRAY: 156.934 - default: 156.935 - pop(iarg); 156.936 - pushDesc(sarg); 156.937 - break; 156.938 - } 156.939 - labels = null; 156.940 -} 156.941 -}
157.1 --- a/src/clojure/asm/commons/CodeSizeEvaluator.java Sat Aug 21 06:25:44 2010 -0400 157.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 157.3 @@ -1,234 +0,0 @@ 157.4 -/*** 157.5 - * ASM: a very small and fast Java bytecode manipulation framework 157.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 157.7 - * All rights reserved. 157.8 - * 157.9 - * Redistribution and use in source and binary forms, with or without 157.10 - * modification, are permitted provided that the following conditions 157.11 - * are met: 157.12 - * 1. Redistributions of source code must retain the above copyright 157.13 - * notice, this list of conditions and the following disclaimer. 157.14 - * 2. Redistributions in binary form must reproduce the above copyright 157.15 - * notice, this list of conditions and the following disclaimer in the 157.16 - * documentation and/or other materials provided with the distribution. 157.17 - * 3. Neither the name of the copyright holders nor the names of its 157.18 - * contributors may be used to endorse or promote products derived from 157.19 - * this software without specific prior written permission. 157.20 - * 157.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 157.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 157.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 157.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 157.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 157.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 157.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 157.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 157.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 157.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 157.31 - * THE POSSIBILITY OF SUCH DAMAGE. 157.32 - */ 157.33 -package clojure.asm.commons; 157.34 - 157.35 -import clojure.asm.Label; 157.36 -import clojure.asm.MethodAdapter; 157.37 -import clojure.asm.MethodVisitor; 157.38 -import clojure.asm.Opcodes; 157.39 - 157.40 -/** 157.41 - * A {@link MethodAdapter} that can be used to approximate method size. 157.42 - * 157.43 - * @author Eugene Kuleshov 157.44 - */ 157.45 -public class CodeSizeEvaluator extends MethodAdapter implements Opcodes{ 157.46 - 157.47 -private int minSize; 157.48 - 157.49 -private int maxSize; 157.50 - 157.51 -public CodeSizeEvaluator(final MethodVisitor mv){ 157.52 - super(mv); 157.53 -} 157.54 - 157.55 -public int getMinSize(){ 157.56 - return this.minSize; 157.57 -} 157.58 - 157.59 -public int getMaxSize(){ 157.60 - return this.maxSize; 157.61 -} 157.62 - 157.63 -public void visitInsn(final int opcode){ 157.64 - minSize += 1; 157.65 - maxSize += 1; 157.66 - if(mv != null) 157.67 - { 157.68 - mv.visitInsn(opcode); 157.69 - } 157.70 -} 157.71 - 157.72 -public void visitIntInsn(final int opcode, final int operand){ 157.73 - if(opcode == SIPUSH) 157.74 - { 157.75 - minSize += 3; 157.76 - maxSize += 3; 157.77 - } 157.78 - else 157.79 - { 157.80 - minSize += 2; 157.81 - maxSize += 2; 157.82 - } 157.83 - if(mv != null) 157.84 - { 157.85 - mv.visitIntInsn(opcode, operand); 157.86 - } 157.87 -} 157.88 - 157.89 -public void visitVarInsn(final int opcode, final int var){ 157.90 - if(var < 4 && opcode != Opcodes.RET) 157.91 - { 157.92 - minSize += 1; 157.93 - maxSize += 1; 157.94 - } 157.95 - else if(var >= 256) 157.96 - { 157.97 - minSize += 4; 157.98 - maxSize += 4; 157.99 - } 157.100 - else 157.101 - { 157.102 - minSize += 2; 157.103 - maxSize += 2; 157.104 - } 157.105 - if(mv != null) 157.106 - { 157.107 - mv.visitVarInsn(opcode, var); 157.108 - } 157.109 -} 157.110 - 157.111 -public void visitTypeInsn(final int opcode, final String desc){ 157.112 - minSize += 3; 157.113 - maxSize += 3; 157.114 - if(mv != null) 157.115 - { 157.116 - mv.visitTypeInsn(opcode, desc); 157.117 - } 157.118 -} 157.119 - 157.120 -public void visitFieldInsn( 157.121 - final int opcode, 157.122 - final String owner, 157.123 - final String name, 157.124 - final String desc){ 157.125 - minSize += 3; 157.126 - maxSize += 3; 157.127 - if(mv != null) 157.128 - { 157.129 - mv.visitFieldInsn(opcode, owner, name, desc); 157.130 - } 157.131 -} 157.132 - 157.133 -public void visitMethodInsn( 157.134 - final int opcode, 157.135 - final String owner, 157.136 - final String name, 157.137 - final String desc){ 157.138 - if(opcode == INVOKEINTERFACE) 157.139 - { 157.140 - minSize += 5; 157.141 - maxSize += 5; 157.142 - } 157.143 - else 157.144 - { 157.145 - minSize += 3; 157.146 - maxSize += 3; 157.147 - } 157.148 - if(mv != null) 157.149 - { 157.150 - mv.visitMethodInsn(opcode, owner, name, desc); 157.151 - } 157.152 -} 157.153 - 157.154 -public void visitJumpInsn(final int opcode, final Label label){ 157.155 - minSize += 3; 157.156 - if(opcode == GOTO || opcode == JSR) 157.157 - { 157.158 - maxSize += 5; 157.159 - } 157.160 - else 157.161 - { 157.162 - maxSize += 8; 157.163 - } 157.164 - if(mv != null) 157.165 - { 157.166 - mv.visitJumpInsn(opcode, label); 157.167 - } 157.168 -} 157.169 - 157.170 -public void visitLdcInsn(final Object cst){ 157.171 - if(cst instanceof Long || cst instanceof Double) 157.172 - { 157.173 - minSize += 3; 157.174 - maxSize += 3; 157.175 - } 157.176 - else 157.177 - { 157.178 - minSize += 2; 157.179 - maxSize += 3; 157.180 - } 157.181 - if(mv != null) 157.182 - { 157.183 - mv.visitLdcInsn(cst); 157.184 - } 157.185 -} 157.186 - 157.187 -public void visitIincInsn(final int var, final int increment){ 157.188 - if(var > 255 || increment > 127 || increment < -128) 157.189 - { 157.190 - minSize += 6; 157.191 - maxSize += 6; 157.192 - } 157.193 - else 157.194 - { 157.195 - minSize += 3; 157.196 - maxSize += 3; 157.197 - } 157.198 - if(mv != null) 157.199 - { 157.200 - mv.visitIincInsn(var, increment); 157.201 - } 157.202 -} 157.203 - 157.204 -public void visitTableSwitchInsn( 157.205 - final int min, 157.206 - final int max, 157.207 - final Label dflt, 157.208 - final Label[] labels){ 157.209 - minSize += 13 + labels.length * 4; 157.210 - maxSize += 16 + labels.length * 4; 157.211 - if(mv != null) 157.212 - { 157.213 - mv.visitTableSwitchInsn(min, max, dflt, labels); 157.214 - } 157.215 -} 157.216 - 157.217 -public void visitLookupSwitchInsn( 157.218 - final Label dflt, 157.219 - final int[] keys, 157.220 - final Label[] labels){ 157.221 - minSize += 9 + keys.length * 8; 157.222 - maxSize += 12 + keys.length * 8; 157.223 - if(mv != null) 157.224 - { 157.225 - mv.visitLookupSwitchInsn(dflt, keys, labels); 157.226 - } 157.227 -} 157.228 - 157.229 -public void visitMultiANewArrayInsn(final String desc, final int dims){ 157.230 - minSize += 4; 157.231 - maxSize += 4; 157.232 - if(mv != null) 157.233 - { 157.234 - mv.visitMultiANewArrayInsn(desc, dims); 157.235 - } 157.236 -} 157.237 -}
158.1 --- a/src/clojure/asm/commons/EmptyVisitor.java Sat Aug 21 06:25:44 2010 -0400 158.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 158.3 @@ -1,221 +0,0 @@ 158.4 -/*** 158.5 - * ASM: a very small and fast Java bytecode manipulation framework 158.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 158.7 - * All rights reserved. 158.8 - * 158.9 - * Redistribution and use in source and binary forms, with or without 158.10 - * modification, are permitted provided that the following conditions 158.11 - * are met: 158.12 - * 1. Redistributions of source code must retain the above copyright 158.13 - * notice, this list of conditions and the following disclaimer. 158.14 - * 2. Redistributions in binary form must reproduce the above copyright 158.15 - * notice, this list of conditions and the following disclaimer in the 158.16 - * documentation and/or other materials provided with the distribution. 158.17 - * 3. Neither the name of the copyright holders nor the names of its 158.18 - * contributors may be used to endorse or promote products derived from 158.19 - * this software without specific prior written permission. 158.20 - * 158.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 158.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 158.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 158.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 158.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 158.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 158.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 158.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 158.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 158.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 158.31 - * THE POSSIBILITY OF SUCH DAMAGE. 158.32 - */ 158.33 -package clojure.asm.commons; 158.34 - 158.35 -import clojure.asm.AnnotationVisitor; 158.36 -import clojure.asm.Attribute; 158.37 -import clojure.asm.ClassVisitor; 158.38 -import clojure.asm.FieldVisitor; 158.39 -import clojure.asm.Label; 158.40 -import clojure.asm.MethodVisitor; 158.41 - 158.42 -/** 158.43 - * An empty implementation of the ASM visitor interfaces. 158.44 - * 158.45 - * @author Eric Bruneton 158.46 - */ 158.47 -public class EmptyVisitor implements 158.48 - ClassVisitor, 158.49 - FieldVisitor, 158.50 - MethodVisitor, 158.51 - AnnotationVisitor{ 158.52 - 158.53 -public void visit( 158.54 - final int version, 158.55 - final int access, 158.56 - final String name, 158.57 - final String signature, 158.58 - final String superName, 158.59 - final String[] interfaces){ 158.60 -} 158.61 - 158.62 -public void visitSource(final String source, final String debug){ 158.63 -} 158.64 - 158.65 -public void visitOuterClass( 158.66 - final String owner, 158.67 - final String name, 158.68 - final String desc){ 158.69 -} 158.70 - 158.71 -public AnnotationVisitor visitAnnotation( 158.72 - final String desc, 158.73 - final boolean visible){ 158.74 - return this; 158.75 -} 158.76 - 158.77 -public void visitAttribute(final Attribute attr){ 158.78 -} 158.79 - 158.80 -public void visitInnerClass( 158.81 - final String name, 158.82 - final String outerName, 158.83 - final String innerName, 158.84 - final int access){ 158.85 -} 158.86 - 158.87 -public FieldVisitor visitField( 158.88 - final int access, 158.89 - final String name, 158.90 - final String desc, 158.91 - final String signature, 158.92 - final Object value){ 158.93 - return this; 158.94 -} 158.95 - 158.96 -public MethodVisitor visitMethod( 158.97 - final int access, 158.98 - final String name, 158.99 - final String desc, 158.100 - final String signature, 158.101 - final String[] exceptions){ 158.102 - return this; 158.103 -} 158.104 - 158.105 -public void visitEnd(){ 158.106 -} 158.107 - 158.108 -public AnnotationVisitor visitAnnotationDefault(){ 158.109 - return this; 158.110 -} 158.111 - 158.112 -public AnnotationVisitor visitParameterAnnotation( 158.113 - final int parameter, 158.114 - final String desc, 158.115 - final boolean visible){ 158.116 - return this; 158.117 -} 158.118 - 158.119 -public void visitCode(){ 158.120 -} 158.121 - 158.122 -public void visitFrame( 158.123 - final int type, 158.124 - final int nLocal, 158.125 - final Object[] local, 158.126 - final int nStack, 158.127 - final Object[] stack){ 158.128 -} 158.129 - 158.130 -public void visitInsn(final int opcode){ 158.131 -} 158.132 - 158.133 -public void visitIntInsn(final int opcode, final int operand){ 158.134 -} 158.135 - 158.136 -public void visitVarInsn(final int opcode, final int var){ 158.137 -} 158.138 - 158.139 -public void visitTypeInsn(final int opcode, final String desc){ 158.140 -} 158.141 - 158.142 -public void visitFieldInsn( 158.143 - final int opcode, 158.144 - final String owner, 158.145 - final String name, 158.146 - final String desc){ 158.147 -} 158.148 - 158.149 -public void visitMethodInsn( 158.150 - final int opcode, 158.151 - final String owner, 158.152 - final String name, 158.153 - final String desc){ 158.154 -} 158.155 - 158.156 -public void visitJumpInsn(final int opcode, final Label label){ 158.157 -} 158.158 - 158.159 -public void visitLabel(final Label label){ 158.160 -} 158.161 - 158.162 -public void visitLdcInsn(final Object cst){ 158.163 -} 158.164 - 158.165 -public void visitIincInsn(final int var, final int increment){ 158.166 -} 158.167 - 158.168 -public void visitTableSwitchInsn( 158.169 - final int min, 158.170 - final int max, 158.171 - final Label dflt, 158.172 - final Label labels[]){ 158.173 -} 158.174 - 158.175 -public void visitLookupSwitchInsn( 158.176 - final Label dflt, 158.177 - final int keys[], 158.178 - final Label labels[]){ 158.179 -} 158.180 - 158.181 -public void visitMultiANewArrayInsn(final String desc, final int dims){ 158.182 -} 158.183 - 158.184 -public void visitTryCatchBlock( 158.185 - final Label start, 158.186 - final Label end, 158.187 - final Label handler, 158.188 - final String type){ 158.189 -} 158.190 - 158.191 -public void visitLocalVariable( 158.192 - final String name, 158.193 - final String desc, 158.194 - final String signature, 158.195 - final Label start, 158.196 - final Label end, 158.197 - final int index){ 158.198 -} 158.199 - 158.200 -public void visitLineNumber(final int line, final Label start){ 158.201 -} 158.202 - 158.203 -public void visitMaxs(final int maxStack, final int maxLocals){ 158.204 -} 158.205 - 158.206 -public void visit(final String name, final Object value){ 158.207 -} 158.208 - 158.209 -public void visitEnum( 158.210 - final String name, 158.211 - final String desc, 158.212 - final String value){ 158.213 -} 158.214 - 158.215 -public AnnotationVisitor visitAnnotation( 158.216 - final String name, 158.217 - final String desc){ 158.218 - return this; 158.219 -} 158.220 - 158.221 -public AnnotationVisitor visitArray(final String name){ 158.222 - return this; 158.223 -} 158.224 -}
159.1 --- a/src/clojure/asm/commons/GeneratorAdapter.java Sat Aug 21 06:25:44 2010 -0400 159.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 159.3 @@ -1,1533 +0,0 @@ 159.4 -/*** 159.5 - * ASM: a very small and fast Java bytecode manipulation framework 159.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 159.7 - * All rights reserved. 159.8 - * 159.9 - * Redistribution and use in source and binary forms, with or without 159.10 - * modification, are permitted provided that the following conditions 159.11 - * are met: 159.12 - * 1. Redistributions of source code must retain the above copyright 159.13 - * notice, this list of conditions and the following disclaimer. 159.14 - * 2. Redistributions in binary form must reproduce the above copyright 159.15 - * notice, this list of conditions and the following disclaimer in the 159.16 - * documentation and/or other materials provided with the distribution. 159.17 - * 3. Neither the name of the copyright holders nor the names of its 159.18 - * contributors may be used to endorse or promote products derived from 159.19 - * this software without specific prior written permission. 159.20 - * 159.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 159.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 159.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 159.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 159.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 159.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 159.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 159.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 159.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 159.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 159.31 - * THE POSSIBILITY OF SUCH DAMAGE. 159.32 - */ 159.33 -package clojure.asm.commons; 159.34 - 159.35 -import java.util.ArrayList; 159.36 -import java.util.Arrays; 159.37 -import java.util.List; 159.38 - 159.39 -import clojure.asm.ClassVisitor; 159.40 -import clojure.asm.Label; 159.41 -import clojure.asm.MethodVisitor; 159.42 -import clojure.asm.Opcodes; 159.43 -import clojure.asm.Type; 159.44 - 159.45 -/** 159.46 - * A {@link clojure.asm.MethodAdapter} with convenient methods to generate 159.47 - * code. For example, using this adapter, the class below 159.48 - * <p/> 159.49 - * <pre> 159.50 - * public class Example { 159.51 - * public static void main(String[] args) { 159.52 - * System.out.println("Hello world!"); 159.53 - * } 159.54 - * } 159.55 - * </pre> 159.56 - * <p/> 159.57 - * can be generated as follows: 159.58 - * <p/> 159.59 - * <pre> 159.60 - * ClassWriter cw = new ClassWriter(true); 159.61 - * cw.visit(V1_1, ACC_PUBLIC, "Example", null, "java/lang/Object", null); 159.62 - * <p/> 159.63 - * Method m = Method.getMethod("void <init> ()"); 159.64 - * GeneratorAdapter mg = new GeneratorAdapter(ACC_PUBLIC, m, null, null, cw); 159.65 - * mg.loadThis(); 159.66 - * mg.invokeConstructor(Type.getType(Object.class), m); 159.67 - * mg.returnValue(); 159.68 - * mg.endMethod(); 159.69 - * <p/> 159.70 - * m = Method.getMethod("void main (String[])"); 159.71 - * mg = new GeneratorAdapter(ACC_PUBLIC + ACC_STATIC, m, null, null, cw); 159.72 - * mg.getStatic(Type.getType(System.class), "out", Type.getType(PrintStream.class)); 159.73 - * mg.push("Hello world!"); 159.74 - * mg.invokeVirtual(Type.getType(PrintStream.class), Method.getMethod("void println (String)")); 159.75 - * mg.returnValue(); 159.76 - * mg.endMethod(); 159.77 - * <p/> 159.78 - * cw.visitEnd(); 159.79 - * </pre> 159.80 - * 159.81 - * @author Juozas Baliuka 159.82 - * @author Chris Nokleberg 159.83 - * @author Eric Bruneton 159.84 - */ 159.85 -public class GeneratorAdapter extends LocalVariablesSorter{ 159.86 - 159.87 -private final static Type BYTE_TYPE = Type.getObjectType("java/lang/Byte"); 159.88 - 159.89 -private final static Type BOOLEAN_TYPE = Type.getObjectType("java/lang/Boolean"); 159.90 - 159.91 -private final static Type SHORT_TYPE = Type.getObjectType("java/lang/Short"); 159.92 - 159.93 -private final static Type CHARACTER_TYPE = Type.getObjectType("java/lang/Character"); 159.94 - 159.95 -private final static Type INTEGER_TYPE = Type.getObjectType("java/lang/Integer"); 159.96 - 159.97 -private final static Type FLOAT_TYPE = Type.getObjectType("java/lang/Float"); 159.98 - 159.99 -private final static Type LONG_TYPE = Type.getObjectType("java/lang/Long"); 159.100 - 159.101 -private final static Type DOUBLE_TYPE = Type.getObjectType("java/lang/Double"); 159.102 - 159.103 -private final static Type NUMBER_TYPE = Type.getObjectType("java/lang/Number"); 159.104 - 159.105 -private final static Type OBJECT_TYPE = Type.getObjectType("java/lang/Object"); 159.106 - 159.107 -private final static Method BOOLEAN_VALUE = Method.getMethod("boolean booleanValue()"); 159.108 - 159.109 -private final static Method CHAR_VALUE = Method.getMethod("char charValue()"); 159.110 - 159.111 -private final static Method INT_VALUE = Method.getMethod("int intValue()"); 159.112 - 159.113 -private final static Method FLOAT_VALUE = Method.getMethod("float floatValue()"); 159.114 - 159.115 -private final static Method LONG_VALUE = Method.getMethod("long longValue()"); 159.116 - 159.117 -private final static Method DOUBLE_VALUE = Method.getMethod("double doubleValue()"); 159.118 - 159.119 -/** 159.120 - * Constant for the {@link #math math} method. 159.121 - */ 159.122 -public final static int ADD = Opcodes.IADD; 159.123 - 159.124 -/** 159.125 - * Constant for the {@link #math math} method. 159.126 - */ 159.127 -public final static int SUB = Opcodes.ISUB; 159.128 - 159.129 -/** 159.130 - * Constant for the {@link #math math} method. 159.131 - */ 159.132 -public final static int MUL = Opcodes.IMUL; 159.133 - 159.134 -/** 159.135 - * Constant for the {@link #math math} method. 159.136 - */ 159.137 -public final static int DIV = Opcodes.IDIV; 159.138 - 159.139 -/** 159.140 - * Constant for the {@link #math math} method. 159.141 - */ 159.142 -public final static int REM = Opcodes.IREM; 159.143 - 159.144 -/** 159.145 - * Constant for the {@link #math math} method. 159.146 - */ 159.147 -public final static int NEG = Opcodes.INEG; 159.148 - 159.149 -/** 159.150 - * Constant for the {@link #math math} method. 159.151 - */ 159.152 -public final static int SHL = Opcodes.ISHL; 159.153 - 159.154 -/** 159.155 - * Constant for the {@link #math math} method. 159.156 - */ 159.157 -public final static int SHR = Opcodes.ISHR; 159.158 - 159.159 -/** 159.160 - * Constant for the {@link #math math} method. 159.161 - */ 159.162 -public final static int USHR = Opcodes.IUSHR; 159.163 - 159.164 -/** 159.165 - * Constant for the {@link #math math} method. 159.166 - */ 159.167 -public final static int AND = Opcodes.IAND; 159.168 - 159.169 -/** 159.170 - * Constant for the {@link #math math} method. 159.171 - */ 159.172 -public final static int OR = Opcodes.IOR; 159.173 - 159.174 -/** 159.175 - * Constant for the {@link #math math} method. 159.176 - */ 159.177 -public final static int XOR = Opcodes.IXOR; 159.178 - 159.179 -/** 159.180 - * Constant for the {@link #ifCmp ifCmp} method. 159.181 - */ 159.182 -public final static int EQ = Opcodes.IFEQ; 159.183 - 159.184 -/** 159.185 - * Constant for the {@link #ifCmp ifCmp} method. 159.186 - */ 159.187 -public final static int NE = Opcodes.IFNE; 159.188 - 159.189 -/** 159.190 - * Constant for the {@link #ifCmp ifCmp} method. 159.191 - */ 159.192 -public final static int LT = Opcodes.IFLT; 159.193 - 159.194 -/** 159.195 - * Constant for the {@link #ifCmp ifCmp} method. 159.196 - */ 159.197 -public final static int GE = Opcodes.IFGE; 159.198 - 159.199 -/** 159.200 - * Constant for the {@link #ifCmp ifCmp} method. 159.201 - */ 159.202 -public final static int GT = Opcodes.IFGT; 159.203 - 159.204 -/** 159.205 - * Constant for the {@link #ifCmp ifCmp} method. 159.206 - */ 159.207 -public final static int LE = Opcodes.IFLE; 159.208 - 159.209 -/** 159.210 - * Access flags of the method visited by this adapter. 159.211 - */ 159.212 -private final int access; 159.213 - 159.214 -/** 159.215 - * Return type of the method visited by this adapter. 159.216 - */ 159.217 -private final Type returnType; 159.218 - 159.219 -/** 159.220 - * Argument types of the method visited by this adapter. 159.221 - */ 159.222 -private final Type[] argumentTypes; 159.223 - 159.224 -/** 159.225 - * Types of the local variables of the method visited by this adapter. 159.226 - */ 159.227 -private final List localTypes = new ArrayList(); 159.228 - 159.229 -/** 159.230 - * Creates a new {@link GeneratorAdapter}. 159.231 - * 159.232 - * @param mv the method visitor to which this adapter delegates calls. 159.233 - * @param access the method's access flags (see {@link Opcodes}). 159.234 - * @param name the method's name. 159.235 - * @param desc the method's descriptor (see {@link Type Type}). 159.236 - */ 159.237 -public GeneratorAdapter( 159.238 - final MethodVisitor mv, 159.239 - final int access, 159.240 - final String name, 159.241 - final String desc){ 159.242 - super(access, desc, mv); 159.243 - this.access = access; 159.244 - this.returnType = Type.getReturnType(desc); 159.245 - this.argumentTypes = Type.getArgumentTypes(desc); 159.246 -} 159.247 - 159.248 -/** 159.249 - * Creates a new {@link GeneratorAdapter}. 159.250 - * 159.251 - * @param access access flags of the adapted method. 159.252 - * @param method the adapted method. 159.253 - * @param mv the method visitor to which this adapter delegates calls. 159.254 - */ 159.255 -public GeneratorAdapter( 159.256 - final int access, 159.257 - final Method method, 159.258 - final MethodVisitor mv){ 159.259 - super(access, method.getDescriptor(), mv); 159.260 - this.access = access; 159.261 - this.returnType = method.getReturnType(); 159.262 - this.argumentTypes = method.getArgumentTypes(); 159.263 -} 159.264 - 159.265 -/** 159.266 - * Creates a new {@link GeneratorAdapter}. 159.267 - * 159.268 - * @param access access flags of the adapted method. 159.269 - * @param method the adapted method. 159.270 - * @param signature the signature of the adapted method (may be 159.271 - * <tt>null</tt>). 159.272 - * @param exceptions the exceptions thrown by the adapted method (may be 159.273 - * <tt>null</tt>). 159.274 - * @param cv the class visitor to which this adapter delegates calls. 159.275 - */ 159.276 -public GeneratorAdapter( 159.277 - final int access, 159.278 - final Method method, 159.279 - final String signature, 159.280 - final Type[] exceptions, 159.281 - final ClassVisitor cv){ 159.282 - this(access, method, cv.visitMethod(access, 159.283 - method.getName(), 159.284 - method.getDescriptor(), 159.285 - signature, 159.286 - getInternalNames(exceptions))); 159.287 -} 159.288 - 159.289 -/** 159.290 - * Returns the internal names of the given types. 159.291 - * 159.292 - * @param types a set of types. 159.293 - * @return the internal names of the given types. 159.294 - */ 159.295 -private static String[] getInternalNames(final Type[] types){ 159.296 - if(types == null) 159.297 - { 159.298 - return null; 159.299 - } 159.300 - String[] names = new String[types.length]; 159.301 - for(int i = 0; i < names.length; ++i) 159.302 - { 159.303 - names[i] = types[i].getInternalName(); 159.304 - } 159.305 - return names; 159.306 -} 159.307 - 159.308 -// ------------------------------------------------------------------------ 159.309 -// Instructions to push constants on the stack 159.310 -// ------------------------------------------------------------------------ 159.311 - 159.312 -/** 159.313 - * Generates the instruction to push the given value on the stack. 159.314 - * 159.315 - * @param value the value to be pushed on the stack. 159.316 - */ 159.317 -public void push(final boolean value){ 159.318 - push(value ? 1 : 0); 159.319 -} 159.320 - 159.321 -/** 159.322 - * Generates the instruction to push the given value on the stack. 159.323 - * 159.324 - * @param value the value to be pushed on the stack. 159.325 - */ 159.326 -public void push(final int value){ 159.327 - if(value >= -1 && value <= 5) 159.328 - { 159.329 - mv.visitInsn(Opcodes.ICONST_0 + value); 159.330 - } 159.331 - else if(value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) 159.332 - { 159.333 - mv.visitIntInsn(Opcodes.BIPUSH, value); 159.334 - } 159.335 - else if(value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) 159.336 - { 159.337 - mv.visitIntInsn(Opcodes.SIPUSH, value); 159.338 - } 159.339 - else 159.340 - { 159.341 - mv.visitLdcInsn(new Integer(value)); 159.342 - } 159.343 -} 159.344 - 159.345 -/** 159.346 - * Generates the instruction to push the given value on the stack. 159.347 - * 159.348 - * @param value the value to be pushed on the stack. 159.349 - */ 159.350 -public void push(final long value){ 159.351 - if(value == 0L || value == 1L) 159.352 - { 159.353 - mv.visitInsn(Opcodes.LCONST_0 + (int) value); 159.354 - } 159.355 - else 159.356 - { 159.357 - mv.visitLdcInsn(new Long(value)); 159.358 - } 159.359 -} 159.360 - 159.361 -/** 159.362 - * Generates the instruction to push the given value on the stack. 159.363 - * 159.364 - * @param value the value to be pushed on the stack. 159.365 - */ 159.366 -public void push(final float value){ 159.367 - int bits = Float.floatToIntBits(value); 159.368 - if(bits == 0L || bits == 0x3f800000 || bits == 0x40000000) 159.369 - { // 0..2 159.370 - mv.visitInsn(Opcodes.FCONST_0 + (int) value); 159.371 - } 159.372 - else 159.373 - { 159.374 - mv.visitLdcInsn(new Float(value)); 159.375 - } 159.376 -} 159.377 - 159.378 -/** 159.379 - * Generates the instruction to push the given value on the stack. 159.380 - * 159.381 - * @param value the value to be pushed on the stack. 159.382 - */ 159.383 -public void push(final double value){ 159.384 - long bits = Double.doubleToLongBits(value); 159.385 - if(bits == 0L || bits == 0x3ff0000000000000L) 159.386 - { // +0.0d and 1.0d 159.387 - mv.visitInsn(Opcodes.DCONST_0 + (int) value); 159.388 - } 159.389 - else 159.390 - { 159.391 - mv.visitLdcInsn(new Double(value)); 159.392 - } 159.393 -} 159.394 - 159.395 -/** 159.396 - * Generates the instruction to push the given value on the stack. 159.397 - * 159.398 - * @param value the value to be pushed on the stack. May be <tt>null</tt>. 159.399 - */ 159.400 -public void push(final String value){ 159.401 - if(value == null) 159.402 - { 159.403 - mv.visitInsn(Opcodes.ACONST_NULL); 159.404 - } 159.405 - else 159.406 - { 159.407 - mv.visitLdcInsn(value); 159.408 - } 159.409 -} 159.410 - 159.411 -/** 159.412 - * Generates the instruction to push the given value on the stack. 159.413 - * 159.414 - * @param value the value to be pushed on the stack. 159.415 - */ 159.416 -public void push(final Type value){ 159.417 - if(value == null) 159.418 - { 159.419 - mv.visitInsn(Opcodes.ACONST_NULL); 159.420 - } 159.421 - else 159.422 - { 159.423 - mv.visitLdcInsn(value); 159.424 - } 159.425 -} 159.426 - 159.427 -// ------------------------------------------------------------------------ 159.428 -// Instructions to load and store method arguments 159.429 -// ------------------------------------------------------------------------ 159.430 - 159.431 -/** 159.432 - * Returns the index of the given method argument in the frame's local 159.433 - * variables array. 159.434 - * 159.435 - * @param arg the index of a method argument. 159.436 - * @return the index of the given method argument in the frame's local 159.437 - * variables array. 159.438 - */ 159.439 -private int getArgIndex(final int arg){ 159.440 - int index = (access & Opcodes.ACC_STATIC) == 0 ? 1 : 0; 159.441 - for(int i = 0; i < arg; i++) 159.442 - { 159.443 - index += argumentTypes[i].getSize(); 159.444 - } 159.445 - return index; 159.446 -} 159.447 - 159.448 -/** 159.449 - * Generates the instruction to push a local variable on the stack. 159.450 - * 159.451 - * @param type the type of the local variable to be loaded. 159.452 - * @param index an index in the frame's local variables array. 159.453 - */ 159.454 -private void loadInsn(final Type type, final int index){ 159.455 - mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), index); 159.456 -} 159.457 - 159.458 -/** 159.459 - * Generates the instruction to store the top stack value in a local 159.460 - * variable. 159.461 - * 159.462 - * @param type the type of the local variable to be stored. 159.463 - * @param index an index in the frame's local variables array. 159.464 - */ 159.465 -private void storeInsn(final Type type, final int index){ 159.466 - mv.visitVarInsn(type.getOpcode(Opcodes.ISTORE), index); 159.467 -} 159.468 - 159.469 -/** 159.470 - * Generates the instruction to load 'this' on the stack. 159.471 - */ 159.472 -public void loadThis(){ 159.473 - if((access & Opcodes.ACC_STATIC) != 0) 159.474 - { 159.475 - throw new IllegalStateException("no 'this' pointer within static method"); 159.476 - } 159.477 - mv.visitVarInsn(Opcodes.ALOAD, 0); 159.478 -} 159.479 - 159.480 -/** 159.481 - * Generates the instruction to load the given method argument on the stack. 159.482 - * 159.483 - * @param arg the index of a method argument. 159.484 - */ 159.485 -public void loadArg(final int arg){ 159.486 - loadInsn(argumentTypes[arg], getArgIndex(arg)); 159.487 -} 159.488 - 159.489 -/** 159.490 - * Generates the instructions to load the given method arguments on the 159.491 - * stack. 159.492 - * 159.493 - * @param arg the index of the first method argument to be loaded. 159.494 - * @param count the number of method arguments to be loaded. 159.495 - */ 159.496 -public void loadArgs(final int arg, final int count){ 159.497 - int index = getArgIndex(arg); 159.498 - for(int i = 0; i < count; ++i) 159.499 - { 159.500 - Type t = argumentTypes[arg + i]; 159.501 - loadInsn(t, index); 159.502 - index += t.getSize(); 159.503 - } 159.504 -} 159.505 - 159.506 -/** 159.507 - * Generates the instructions to load all the method arguments on the stack. 159.508 - */ 159.509 -public void loadArgs(){ 159.510 - loadArgs(0, argumentTypes.length); 159.511 -} 159.512 - 159.513 -/** 159.514 - * Generates the instructions to load all the method arguments on the stack, 159.515 - * as a single object array. 159.516 - */ 159.517 -public void loadArgArray(){ 159.518 - push(argumentTypes.length); 159.519 - newArray(OBJECT_TYPE); 159.520 - for(int i = 0; i < argumentTypes.length; i++) 159.521 - { 159.522 - dup(); 159.523 - push(i); 159.524 - loadArg(i); 159.525 - box(argumentTypes[i]); 159.526 - arrayStore(OBJECT_TYPE); 159.527 - } 159.528 -} 159.529 - 159.530 -/** 159.531 - * Generates the instruction to store the top stack value in the given 159.532 - * method argument. 159.533 - * 159.534 - * @param arg the index of a method argument. 159.535 - */ 159.536 -public void storeArg(final int arg){ 159.537 - storeInsn(argumentTypes[arg], getArgIndex(arg)); 159.538 -} 159.539 - 159.540 -// ------------------------------------------------------------------------ 159.541 -// Instructions to load and store local variables 159.542 -// ------------------------------------------------------------------------ 159.543 - 159.544 -/** 159.545 - * Returns the type of the given local variable. 159.546 - * 159.547 - * @param local a local variable identifier, as returned by 159.548 - * {@link LocalVariablesSorter#newLocal(Type) newLocal()}. 159.549 - * @return the type of the given local variable. 159.550 - */ 159.551 -public Type getLocalType(final int local){ 159.552 - return (Type) localTypes.get(local - firstLocal); 159.553 -} 159.554 - 159.555 -protected void setLocalType(final int local, final Type type){ 159.556 - int index = local - firstLocal; 159.557 - while(localTypes.size() < index + 1) 159.558 - { 159.559 - localTypes.add(null); 159.560 - } 159.561 - localTypes.set(index, type); 159.562 -} 159.563 - 159.564 -/** 159.565 - * Generates the instruction to load the given local variable on the stack. 159.566 - * 159.567 - * @param local a local variable identifier, as returned by 159.568 - * {@link LocalVariablesSorter#newLocal(Type) newLocal()}. 159.569 - */ 159.570 -public void loadLocal(final int local){ 159.571 - loadInsn(getLocalType(local), local); 159.572 -} 159.573 - 159.574 -/** 159.575 - * Generates the instruction to load the given local variable on the stack. 159.576 - * 159.577 - * @param local a local variable identifier, as returned by 159.578 - * {@link LocalVariablesSorter#newLocal(Type) newLocal()}. 159.579 - * @param type the type of this local variable. 159.580 - */ 159.581 -public void loadLocal(final int local, final Type type){ 159.582 - setLocalType(local, type); 159.583 - loadInsn(type, local); 159.584 -} 159.585 - 159.586 -/** 159.587 - * Generates the instruction to store the top stack value in the given local 159.588 - * variable. 159.589 - * 159.590 - * @param local a local variable identifier, as returned by 159.591 - * {@link LocalVariablesSorter#newLocal(Type) newLocal()}. 159.592 - */ 159.593 -public void storeLocal(final int local){ 159.594 - storeInsn(getLocalType(local), local); 159.595 -} 159.596 - 159.597 -/** 159.598 - * Generates the instruction to store the top stack value in the given local 159.599 - * variable. 159.600 - * 159.601 - * @param local a local variable identifier, as returned by 159.602 - * {@link LocalVariablesSorter#newLocal(Type) newLocal()}. 159.603 - * @param type the type of this local variable. 159.604 - */ 159.605 -public void storeLocal(final int local, final Type type){ 159.606 - setLocalType(local, type); 159.607 - storeInsn(type, local); 159.608 -} 159.609 - 159.610 -/** 159.611 - * Generates the instruction to load an element from an array. 159.612 - * 159.613 - * @param type the type of the array element to be loaded. 159.614 - */ 159.615 -public void arrayLoad(final Type type){ 159.616 - mv.visitInsn(type.getOpcode(Opcodes.IALOAD)); 159.617 -} 159.618 - 159.619 -/** 159.620 - * Generates the instruction to store an element in an array. 159.621 - * 159.622 - * @param type the type of the array element to be stored. 159.623 - */ 159.624 -public void arrayStore(final Type type){ 159.625 - mv.visitInsn(type.getOpcode(Opcodes.IASTORE)); 159.626 -} 159.627 - 159.628 -// ------------------------------------------------------------------------ 159.629 -// Instructions to manage the stack 159.630 -// ------------------------------------------------------------------------ 159.631 - 159.632 -/** 159.633 - * Generates a POP instruction. 159.634 - */ 159.635 -public void pop(){ 159.636 - mv.visitInsn(Opcodes.POP); 159.637 -} 159.638 - 159.639 -/** 159.640 - * Generates a POP2 instruction. 159.641 - */ 159.642 -public void pop2(){ 159.643 - mv.visitInsn(Opcodes.POP2); 159.644 -} 159.645 - 159.646 -/** 159.647 - * Generates a DUP instruction. 159.648 - */ 159.649 -public void dup(){ 159.650 - mv.visitInsn(Opcodes.DUP); 159.651 -} 159.652 - 159.653 -/** 159.654 - * Generates a DUP2 instruction. 159.655 - */ 159.656 -public void dup2(){ 159.657 - mv.visitInsn(Opcodes.DUP2); 159.658 -} 159.659 - 159.660 -/** 159.661 - * Generates a DUP_X1 instruction. 159.662 - */ 159.663 -public void dupX1(){ 159.664 - mv.visitInsn(Opcodes.DUP_X1); 159.665 -} 159.666 - 159.667 -/** 159.668 - * Generates a DUP_X2 instruction. 159.669 - */ 159.670 -public void dupX2(){ 159.671 - mv.visitInsn(Opcodes.DUP_X2); 159.672 -} 159.673 - 159.674 -/** 159.675 - * Generates a DUP2_X1 instruction. 159.676 - */ 159.677 -public void dup2X1(){ 159.678 - mv.visitInsn(Opcodes.DUP2_X1); 159.679 -} 159.680 - 159.681 -/** 159.682 - * Generates a DUP2_X2 instruction. 159.683 - */ 159.684 -public void dup2X2(){ 159.685 - mv.visitInsn(Opcodes.DUP2_X2); 159.686 -} 159.687 - 159.688 -/** 159.689 - * Generates a SWAP instruction. 159.690 - */ 159.691 -public void swap(){ 159.692 - mv.visitInsn(Opcodes.SWAP); 159.693 -} 159.694 - 159.695 -/** 159.696 - * Generates the instructions to swap the top two stack values. 159.697 - * 159.698 - * @param prev type of the top - 1 stack value. 159.699 - * @param type type of the top stack value. 159.700 - */ 159.701 -public void swap(final Type prev, final Type type){ 159.702 - if(type.getSize() == 1) 159.703 - { 159.704 - if(prev.getSize() == 1) 159.705 - { 159.706 - swap(); // same as dupX1(), pop(); 159.707 - } 159.708 - else 159.709 - { 159.710 - dupX2(); 159.711 - pop(); 159.712 - } 159.713 - } 159.714 - else 159.715 - { 159.716 - if(prev.getSize() == 1) 159.717 - { 159.718 - dup2X1(); 159.719 - pop2(); 159.720 - } 159.721 - else 159.722 - { 159.723 - dup2X2(); 159.724 - pop2(); 159.725 - } 159.726 - } 159.727 -} 159.728 - 159.729 -// ------------------------------------------------------------------------ 159.730 -// Instructions to do mathematical and logical operations 159.731 -// ------------------------------------------------------------------------ 159.732 - 159.733 -/** 159.734 - * Generates the instruction to do the specified mathematical or logical 159.735 - * operation. 159.736 - * 159.737 - * @param op a mathematical or logical operation. Must be one of ADD, SUB, 159.738 - * MUL, DIV, REM, NEG, SHL, SHR, USHR, AND, OR, XOR. 159.739 - * @param type the type of the operand(s) for this operation. 159.740 - */ 159.741 -public void math(final int op, final Type type){ 159.742 - mv.visitInsn(type.getOpcode(op)); 159.743 -} 159.744 - 159.745 -/** 159.746 - * Generates the instructions to compute the bitwise negation of the top 159.747 - * stack value. 159.748 - */ 159.749 -public void not(){ 159.750 - mv.visitInsn(Opcodes.ICONST_1); 159.751 - mv.visitInsn(Opcodes.IXOR); 159.752 -} 159.753 - 159.754 -/** 159.755 - * Generates the instruction to increment the given local variable. 159.756 - * 159.757 - * @param local the local variable to be incremented. 159.758 - * @param amount the amount by which the local variable must be incremented. 159.759 - */ 159.760 -public void iinc(final int local, final int amount){ 159.761 - mv.visitIincInsn(local, amount); 159.762 -} 159.763 - 159.764 -/** 159.765 - * Generates the instructions to cast a numerical value from one type to 159.766 - * another. 159.767 - * 159.768 - * @param from the type of the top stack value 159.769 - * @param to the type into which this value must be cast. 159.770 - */ 159.771 -public void cast(final Type from, final Type to){ 159.772 - if(from != to) 159.773 - { 159.774 - if(from == Type.DOUBLE_TYPE) 159.775 - { 159.776 - if(to == Type.FLOAT_TYPE) 159.777 - { 159.778 - mv.visitInsn(Opcodes.D2F); 159.779 - } 159.780 - else if(to == Type.LONG_TYPE) 159.781 - { 159.782 - mv.visitInsn(Opcodes.D2L); 159.783 - } 159.784 - else 159.785 - { 159.786 - mv.visitInsn(Opcodes.D2I); 159.787 - cast(Type.INT_TYPE, to); 159.788 - } 159.789 - } 159.790 - else if(from == Type.FLOAT_TYPE) 159.791 - { 159.792 - if(to == Type.DOUBLE_TYPE) 159.793 - { 159.794 - mv.visitInsn(Opcodes.F2D); 159.795 - } 159.796 - else if(to == Type.LONG_TYPE) 159.797 - { 159.798 - mv.visitInsn(Opcodes.F2L); 159.799 - } 159.800 - else 159.801 - { 159.802 - mv.visitInsn(Opcodes.F2I); 159.803 - cast(Type.INT_TYPE, to); 159.804 - } 159.805 - } 159.806 - else if(from == Type.LONG_TYPE) 159.807 - { 159.808 - if(to == Type.DOUBLE_TYPE) 159.809 - { 159.810 - mv.visitInsn(Opcodes.L2D); 159.811 - } 159.812 - else if(to == Type.FLOAT_TYPE) 159.813 - { 159.814 - mv.visitInsn(Opcodes.L2F); 159.815 - } 159.816 - else 159.817 - { 159.818 - mv.visitInsn(Opcodes.L2I); 159.819 - cast(Type.INT_TYPE, to); 159.820 - } 159.821 - } 159.822 - else 159.823 - { 159.824 - if(to == Type.BYTE_TYPE) 159.825 - { 159.826 - mv.visitInsn(Opcodes.I2B); 159.827 - } 159.828 - else if(to == Type.CHAR_TYPE) 159.829 - { 159.830 - mv.visitInsn(Opcodes.I2C); 159.831 - } 159.832 - else if(to == Type.DOUBLE_TYPE) 159.833 - { 159.834 - mv.visitInsn(Opcodes.I2D); 159.835 - } 159.836 - else if(to == Type.FLOAT_TYPE) 159.837 - { 159.838 - mv.visitInsn(Opcodes.I2F); 159.839 - } 159.840 - else if(to == Type.LONG_TYPE) 159.841 - { 159.842 - mv.visitInsn(Opcodes.I2L); 159.843 - } 159.844 - else if(to == Type.SHORT_TYPE) 159.845 - { 159.846 - mv.visitInsn(Opcodes.I2S); 159.847 - } 159.848 - } 159.849 - } 159.850 -} 159.851 - 159.852 -// ------------------------------------------------------------------------ 159.853 -// Instructions to do boxing and unboxing operations 159.854 -// ------------------------------------------------------------------------ 159.855 - 159.856 -/** 159.857 - * Generates the instructions to box the top stack value. This value is 159.858 - * replaced by its boxed equivalent on top of the stack. 159.859 - * 159.860 - * @param type the type of the top stack value. 159.861 - */ 159.862 -public void box(final Type type){ 159.863 - if(type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) 159.864 - { 159.865 - return; 159.866 - } 159.867 - if(type == Type.VOID_TYPE) 159.868 - { 159.869 - push((String) null); 159.870 - } 159.871 - else 159.872 - { 159.873 - Type boxed = type; 159.874 - switch(type.getSort()) 159.875 - { 159.876 - case Type.BYTE: 159.877 - boxed = BYTE_TYPE; 159.878 - break; 159.879 - case Type.BOOLEAN: 159.880 - boxed = BOOLEAN_TYPE; 159.881 - break; 159.882 - case Type.SHORT: 159.883 - boxed = SHORT_TYPE; 159.884 - break; 159.885 - case Type.CHAR: 159.886 - boxed = CHARACTER_TYPE; 159.887 - break; 159.888 - case Type.INT: 159.889 - boxed = INTEGER_TYPE; 159.890 - break; 159.891 - case Type.FLOAT: 159.892 - boxed = FLOAT_TYPE; 159.893 - break; 159.894 - case Type.LONG: 159.895 - boxed = LONG_TYPE; 159.896 - break; 159.897 - case Type.DOUBLE: 159.898 - boxed = DOUBLE_TYPE; 159.899 - break; 159.900 - } 159.901 - newInstance(boxed); 159.902 - if(type.getSize() == 2) 159.903 - { 159.904 - // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o 159.905 - dupX2(); 159.906 - dupX2(); 159.907 - pop(); 159.908 - } 159.909 - else 159.910 - { 159.911 - // p -> po -> opo -> oop -> o 159.912 - dupX1(); 159.913 - swap(); 159.914 - } 159.915 - invokeConstructor(boxed, new Method("<init>", 159.916 - Type.VOID_TYPE, 159.917 - new Type[]{type})); 159.918 - } 159.919 -} 159.920 - 159.921 -/** 159.922 - * Generates the instructions to unbox the top stack value. This value is 159.923 - * replaced by its unboxed equivalent on top of the stack. 159.924 - * 159.925 - * @param type the type of the top stack value. 159.926 - */ 159.927 -public void unbox(final Type type){ 159.928 - Type t = NUMBER_TYPE; 159.929 - Method sig = null; 159.930 - switch(type.getSort()) 159.931 - { 159.932 - case Type.VOID: 159.933 - return; 159.934 - case Type.CHAR: 159.935 - t = CHARACTER_TYPE; 159.936 - sig = CHAR_VALUE; 159.937 - break; 159.938 - case Type.BOOLEAN: 159.939 - t = BOOLEAN_TYPE; 159.940 - sig = BOOLEAN_VALUE; 159.941 - break; 159.942 - case Type.DOUBLE: 159.943 - sig = DOUBLE_VALUE; 159.944 - break; 159.945 - case Type.FLOAT: 159.946 - sig = FLOAT_VALUE; 159.947 - break; 159.948 - case Type.LONG: 159.949 - sig = LONG_VALUE; 159.950 - break; 159.951 - case Type.INT: 159.952 - case Type.SHORT: 159.953 - case Type.BYTE: 159.954 - sig = INT_VALUE; 159.955 - } 159.956 - if(sig == null) 159.957 - { 159.958 - checkCast(type); 159.959 - } 159.960 - else 159.961 - { 159.962 - checkCast(t); 159.963 - invokeVirtual(t, sig); 159.964 - } 159.965 -} 159.966 - 159.967 -// ------------------------------------------------------------------------ 159.968 -// Instructions to jump to other instructions 159.969 -// ------------------------------------------------------------------------ 159.970 - 159.971 -/** 159.972 - * Creates a new {@link Label}. 159.973 - * 159.974 - * @return a new {@link Label}. 159.975 - */ 159.976 -public Label newLabel(){ 159.977 - return new Label(); 159.978 -} 159.979 - 159.980 -/** 159.981 - * Marks the current code position with the given label. 159.982 - * 159.983 - * @param label a label. 159.984 - */ 159.985 -public void mark(final Label label){ 159.986 - mv.visitLabel(label); 159.987 -} 159.988 - 159.989 -/** 159.990 - * Marks the current code position with a new label. 159.991 - * 159.992 - * @return the label that was created to mark the current code position. 159.993 - */ 159.994 -public Label mark(){ 159.995 - Label label = new Label(); 159.996 - mv.visitLabel(label); 159.997 - return label; 159.998 -} 159.999 - 159.1000 -/** 159.1001 - * Generates the instructions to jump to a label based on the comparison of 159.1002 - * the top two stack values. 159.1003 - * 159.1004 - * @param type the type of the top two stack values. 159.1005 - * @param mode how these values must be compared. One of EQ, NE, LT, GE, GT, 159.1006 - * LE. 159.1007 - * @param label where to jump if the comparison result is <tt>true</tt>. 159.1008 - */ 159.1009 -public void ifCmp(final Type type, final int mode, final Label label){ 159.1010 - int intOp = -1; 159.1011 - switch(type.getSort()) 159.1012 - { 159.1013 - case Type.LONG: 159.1014 - mv.visitInsn(Opcodes.LCMP); 159.1015 - break; 159.1016 - case Type.DOUBLE: 159.1017 - mv.visitInsn(Opcodes.DCMPG); 159.1018 - break; 159.1019 - case Type.FLOAT: 159.1020 - mv.visitInsn(Opcodes.FCMPG); 159.1021 - break; 159.1022 - case Type.ARRAY: 159.1023 - case Type.OBJECT: 159.1024 - switch(mode) 159.1025 - { 159.1026 - case EQ: 159.1027 - mv.visitJumpInsn(Opcodes.IF_ACMPEQ, label); 159.1028 - return; 159.1029 - case NE: 159.1030 - mv.visitJumpInsn(Opcodes.IF_ACMPNE, label); 159.1031 - return; 159.1032 - } 159.1033 - throw new IllegalArgumentException("Bad comparison for type " 159.1034 - + type); 159.1035 - default: 159.1036 - switch(mode) 159.1037 - { 159.1038 - case EQ: 159.1039 - intOp = Opcodes.IF_ICMPEQ; 159.1040 - break; 159.1041 - case NE: 159.1042 - intOp = Opcodes.IF_ICMPNE; 159.1043 - break; 159.1044 - case GE: 159.1045 - intOp = Opcodes.IF_ICMPGE; 159.1046 - break; 159.1047 - case LT: 159.1048 - intOp = Opcodes.IF_ICMPLT; 159.1049 - break; 159.1050 - case LE: 159.1051 - intOp = Opcodes.IF_ICMPLE; 159.1052 - break; 159.1053 - case GT: 159.1054 - intOp = Opcodes.IF_ICMPGT; 159.1055 - break; 159.1056 - } 159.1057 - mv.visitJumpInsn(intOp, label); 159.1058 - return; 159.1059 - } 159.1060 - int jumpMode = mode; 159.1061 - switch(mode) 159.1062 - { 159.1063 - case GE: 159.1064 - jumpMode = LT; 159.1065 - break; 159.1066 - case LE: 159.1067 - jumpMode = GT; 159.1068 - break; 159.1069 - } 159.1070 - mv.visitJumpInsn(jumpMode, label); 159.1071 -} 159.1072 - 159.1073 -/** 159.1074 - * Generates the instructions to jump to a label based on the comparison of 159.1075 - * the top two integer stack values. 159.1076 - * 159.1077 - * @param mode how these values must be compared. One of EQ, NE, LT, GE, GT, 159.1078 - * LE. 159.1079 - * @param label where to jump if the comparison result is <tt>true</tt>. 159.1080 - */ 159.1081 -public void ifICmp(final int mode, final Label label){ 159.1082 - ifCmp(Type.INT_TYPE, mode, label); 159.1083 -} 159.1084 - 159.1085 -/** 159.1086 - * Generates the instructions to jump to a label based on the comparison of 159.1087 - * the top integer stack value with zero. 159.1088 - * 159.1089 - * @param mode how these values must be compared. One of EQ, NE, LT, GE, GT, 159.1090 - * LE. 159.1091 - * @param label where to jump if the comparison result is <tt>true</tt>. 159.1092 - */ 159.1093 -public void ifZCmp(final int mode, final Label label){ 159.1094 - mv.visitJumpInsn(mode, label); 159.1095 -} 159.1096 - 159.1097 -/** 159.1098 - * Generates the instruction to jump to the given label if the top stack 159.1099 - * value is null. 159.1100 - * 159.1101 - * @param label where to jump if the condition is <tt>true</tt>. 159.1102 - */ 159.1103 -public void ifNull(final Label label){ 159.1104 - mv.visitJumpInsn(Opcodes.IFNULL, label); 159.1105 -} 159.1106 - 159.1107 -/** 159.1108 - * Generates the instruction to jump to the given label if the top stack 159.1109 - * value is not null. 159.1110 - * 159.1111 - * @param label where to jump if the condition is <tt>true</tt>. 159.1112 - */ 159.1113 -public void ifNonNull(final Label label){ 159.1114 - mv.visitJumpInsn(Opcodes.IFNONNULL, label); 159.1115 -} 159.1116 - 159.1117 -/** 159.1118 - * Generates the instruction to jump to the given label. 159.1119 - * 159.1120 - * @param label where to jump if the condition is <tt>true</tt>. 159.1121 - */ 159.1122 -public void goTo(final Label label){ 159.1123 - mv.visitJumpInsn(Opcodes.GOTO, label); 159.1124 -} 159.1125 - 159.1126 -/** 159.1127 - * Generates a RET instruction. 159.1128 - * 159.1129 - * @param local a local variable identifier, as returned by 159.1130 - * {@link LocalVariablesSorter#newLocal(Type) newLocal()}. 159.1131 - */ 159.1132 -public void ret(final int local){ 159.1133 - mv.visitVarInsn(Opcodes.RET, local); 159.1134 -} 159.1135 - 159.1136 -/** 159.1137 - * Generates the instructions for a switch statement. 159.1138 - * 159.1139 - * @param keys the switch case keys. 159.1140 - * @param generator a generator to generate the code for the switch cases. 159.1141 - */ 159.1142 -public void tableSwitch( 159.1143 - final int[] keys, 159.1144 - final TableSwitchGenerator generator){ 159.1145 - float density; 159.1146 - if(keys.length == 0) 159.1147 - { 159.1148 - density = 0; 159.1149 - } 159.1150 - else 159.1151 - { 159.1152 - density = (float) keys.length 159.1153 - / (keys[keys.length - 1] - keys[0] + 1); 159.1154 - } 159.1155 - tableSwitch(keys, generator, density >= 0.5f); 159.1156 -} 159.1157 - 159.1158 -/** 159.1159 - * Generates the instructions for a switch statement. 159.1160 - * 159.1161 - * @param keys the switch case keys. 159.1162 - * @param generator a generator to generate the code for the switch cases. 159.1163 - * @param useTable <tt>true</tt> to use a TABLESWITCH instruction, or 159.1164 - * <tt>false</tt> to use a LOOKUPSWITCH instruction. 159.1165 - */ 159.1166 -public void tableSwitch( 159.1167 - final int[] keys, 159.1168 - final TableSwitchGenerator generator, 159.1169 - final boolean useTable){ 159.1170 - for(int i = 1; i < keys.length; ++i) 159.1171 - { 159.1172 - if(keys[i] < keys[i - 1]) 159.1173 - { 159.1174 - throw new IllegalArgumentException("keys must be sorted ascending"); 159.1175 - } 159.1176 - } 159.1177 - Label def = newLabel(); 159.1178 - Label end = newLabel(); 159.1179 - if(keys.length > 0) 159.1180 - { 159.1181 - int len = keys.length; 159.1182 - int min = keys[0]; 159.1183 - int max = keys[len - 1]; 159.1184 - int range = max - min + 1; 159.1185 - if(useTable) 159.1186 - { 159.1187 - Label[] labels = new Label[range]; 159.1188 - Arrays.fill(labels, def); 159.1189 - for(int i = 0; i < len; ++i) 159.1190 - { 159.1191 - labels[keys[i] - min] = newLabel(); 159.1192 - } 159.1193 - mv.visitTableSwitchInsn(min, max, def, labels); 159.1194 - for(int i = 0; i < range; ++i) 159.1195 - { 159.1196 - Label label = labels[i]; 159.1197 - if(label != def) 159.1198 - { 159.1199 - mark(label); 159.1200 - generator.generateCase(i + min, end); 159.1201 - } 159.1202 - } 159.1203 - } 159.1204 - else 159.1205 - { 159.1206 - Label[] labels = new Label[len]; 159.1207 - for(int i = 0; i < len; ++i) 159.1208 - { 159.1209 - labels[i] = newLabel(); 159.1210 - } 159.1211 - mv.visitLookupSwitchInsn(def, keys, labels); 159.1212 - for(int i = 0; i < len; ++i) 159.1213 - { 159.1214 - mark(labels[i]); 159.1215 - generator.generateCase(keys[i], end); 159.1216 - } 159.1217 - } 159.1218 - } 159.1219 - mark(def); 159.1220 - generator.generateDefault(); 159.1221 - mark(end); 159.1222 -} 159.1223 - 159.1224 -/** 159.1225 - * Generates the instruction to return the top stack value to the caller. 159.1226 - */ 159.1227 -public void returnValue(){ 159.1228 - mv.visitInsn(returnType.getOpcode(Opcodes.IRETURN)); 159.1229 -} 159.1230 - 159.1231 -// ------------------------------------------------------------------------ 159.1232 -// Instructions to load and store fields 159.1233 -// ------------------------------------------------------------------------ 159.1234 - 159.1235 -/** 159.1236 - * Generates a get field or set field instruction. 159.1237 - * 159.1238 - * @param opcode the instruction's opcode. 159.1239 - * @param ownerType the class in which the field is defined. 159.1240 - * @param name the name of the field. 159.1241 - * @param fieldType the type of the field. 159.1242 - */ 159.1243 -private void fieldInsn( 159.1244 - final int opcode, 159.1245 - final Type ownerType, 159.1246 - final String name, 159.1247 - final Type fieldType){ 159.1248 - mv.visitFieldInsn(opcode, 159.1249 - ownerType.getInternalName(), 159.1250 - name, 159.1251 - fieldType.getDescriptor()); 159.1252 -} 159.1253 - 159.1254 -/** 159.1255 - * Generates the instruction to push the value of a static field on the 159.1256 - * stack. 159.1257 - * 159.1258 - * @param owner the class in which the field is defined. 159.1259 - * @param name the name of the field. 159.1260 - * @param type the type of the field. 159.1261 - */ 159.1262 -public void getStatic(final Type owner, final String name, final Type type){ 159.1263 - fieldInsn(Opcodes.GETSTATIC, owner, name, type); 159.1264 -} 159.1265 - 159.1266 -/** 159.1267 - * Generates the instruction to store the top stack value in a static field. 159.1268 - * 159.1269 - * @param owner the class in which the field is defined. 159.1270 - * @param name the name of the field. 159.1271 - * @param type the type of the field. 159.1272 - */ 159.1273 -public void putStatic(final Type owner, final String name, final Type type){ 159.1274 - fieldInsn(Opcodes.PUTSTATIC, owner, name, type); 159.1275 -} 159.1276 - 159.1277 -/** 159.1278 - * Generates the instruction to push the value of a non static field on the 159.1279 - * stack. 159.1280 - * 159.1281 - * @param owner the class in which the field is defined. 159.1282 - * @param name the name of the field. 159.1283 - * @param type the type of the field. 159.1284 - */ 159.1285 -public void getField(final Type owner, final String name, final Type type){ 159.1286 - fieldInsn(Opcodes.GETFIELD, owner, name, type); 159.1287 -} 159.1288 - 159.1289 -/** 159.1290 - * Generates the instruction to store the top stack value in a non static 159.1291 - * field. 159.1292 - * 159.1293 - * @param owner the class in which the field is defined. 159.1294 - * @param name the name of the field. 159.1295 - * @param type the type of the field. 159.1296 - */ 159.1297 -public void putField(final Type owner, final String name, final Type type){ 159.1298 - fieldInsn(Opcodes.PUTFIELD, owner, name, type); 159.1299 -} 159.1300 - 159.1301 -// ------------------------------------------------------------------------ 159.1302 -// Instructions to invoke methods 159.1303 -// ------------------------------------------------------------------------ 159.1304 - 159.1305 -/** 159.1306 - * Generates an invoke method instruction. 159.1307 - * 159.1308 - * @param opcode the instruction's opcode. 159.1309 - * @param type the class in which the method is defined. 159.1310 - * @param method the method to be invoked. 159.1311 - */ 159.1312 -private void invokeInsn( 159.1313 - final int opcode, 159.1314 - final Type type, 159.1315 - final Method method){ 159.1316 - String owner = type.getSort() == Type.ARRAY 159.1317 - ? type.getDescriptor() 159.1318 - : type.getInternalName(); 159.1319 - mv.visitMethodInsn(opcode, 159.1320 - owner, 159.1321 - method.getName(), 159.1322 - method.getDescriptor()); 159.1323 -} 159.1324 - 159.1325 -/** 159.1326 - * Generates the instruction to invoke a normal method. 159.1327 - * 159.1328 - * @param owner the class in which the method is defined. 159.1329 - * @param method the method to be invoked. 159.1330 - */ 159.1331 -public void invokeVirtual(final Type owner, final Method method){ 159.1332 - invokeInsn(Opcodes.INVOKEVIRTUAL, owner, method); 159.1333 -} 159.1334 - 159.1335 -/** 159.1336 - * Generates the instruction to invoke a constructor. 159.1337 - * 159.1338 - * @param type the class in which the constructor is defined. 159.1339 - * @param method the constructor to be invoked. 159.1340 - */ 159.1341 -public void invokeConstructor(final Type type, final Method method){ 159.1342 - invokeInsn(Opcodes.INVOKESPECIAL, type, method); 159.1343 -} 159.1344 - 159.1345 -/** 159.1346 - * Generates the instruction to invoke a static method. 159.1347 - * 159.1348 - * @param owner the class in which the method is defined. 159.1349 - * @param method the method to be invoked. 159.1350 - */ 159.1351 -public void invokeStatic(final Type owner, final Method method){ 159.1352 - invokeInsn(Opcodes.INVOKESTATIC, owner, method); 159.1353 -} 159.1354 - 159.1355 -/** 159.1356 - * Generates the instruction to invoke an interface method. 159.1357 - * 159.1358 - * @param owner the class in which the method is defined. 159.1359 - * @param method the method to be invoked. 159.1360 - */ 159.1361 -public void invokeInterface(final Type owner, final Method method){ 159.1362 - invokeInsn(Opcodes.INVOKEINTERFACE, owner, method); 159.1363 -} 159.1364 - 159.1365 -// ------------------------------------------------------------------------ 159.1366 -// Instructions to create objects and arrays 159.1367 -// ------------------------------------------------------------------------ 159.1368 - 159.1369 -/** 159.1370 - * Generates a type dependent instruction. 159.1371 - * 159.1372 - * @param opcode the instruction's opcode. 159.1373 - * @param type the instruction's operand. 159.1374 - */ 159.1375 -private void typeInsn(final int opcode, final Type type){ 159.1376 - String desc; 159.1377 - if(type.getSort() == Type.ARRAY) 159.1378 - { 159.1379 - desc = type.getDescriptor(); 159.1380 - } 159.1381 - else 159.1382 - { 159.1383 - desc = type.getInternalName(); 159.1384 - } 159.1385 - mv.visitTypeInsn(opcode, desc); 159.1386 -} 159.1387 - 159.1388 -/** 159.1389 - * Generates the instruction to create a new object. 159.1390 - * 159.1391 - * @param type the class of the object to be created. 159.1392 - */ 159.1393 -public void newInstance(final Type type){ 159.1394 - typeInsn(Opcodes.NEW, type); 159.1395 -} 159.1396 - 159.1397 -/** 159.1398 - * Generates the instruction to create a new array. 159.1399 - * 159.1400 - * @param type the type of the array elements. 159.1401 - */ 159.1402 -public void newArray(final Type type){ 159.1403 - int typ; 159.1404 - switch(type.getSort()) 159.1405 - { 159.1406 - case Type.BOOLEAN: 159.1407 - typ = Opcodes.T_BOOLEAN; 159.1408 - break; 159.1409 - case Type.CHAR: 159.1410 - typ = Opcodes.T_CHAR; 159.1411 - break; 159.1412 - case Type.BYTE: 159.1413 - typ = Opcodes.T_BYTE; 159.1414 - break; 159.1415 - case Type.SHORT: 159.1416 - typ = Opcodes.T_SHORT; 159.1417 - break; 159.1418 - case Type.INT: 159.1419 - typ = Opcodes.T_INT; 159.1420 - break; 159.1421 - case Type.FLOAT: 159.1422 - typ = Opcodes.T_FLOAT; 159.1423 - break; 159.1424 - case Type.LONG: 159.1425 - typ = Opcodes.T_LONG; 159.1426 - break; 159.1427 - case Type.DOUBLE: 159.1428 - typ = Opcodes.T_DOUBLE; 159.1429 - break; 159.1430 - default: 159.1431 - typeInsn(Opcodes.ANEWARRAY, type); 159.1432 - return; 159.1433 - } 159.1434 - mv.visitIntInsn(Opcodes.NEWARRAY, typ); 159.1435 -} 159.1436 - 159.1437 -// ------------------------------------------------------------------------ 159.1438 -// Miscelaneous instructions 159.1439 -// ------------------------------------------------------------------------ 159.1440 - 159.1441 -/** 159.1442 - * Generates the instruction to compute the length of an array. 159.1443 - */ 159.1444 -public void arrayLength(){ 159.1445 - mv.visitInsn(Opcodes.ARRAYLENGTH); 159.1446 -} 159.1447 - 159.1448 -/** 159.1449 - * Generates the instruction to throw an exception. 159.1450 - */ 159.1451 -public void throwException(){ 159.1452 - mv.visitInsn(Opcodes.ATHROW); 159.1453 -} 159.1454 - 159.1455 -/** 159.1456 - * Generates the instructions to create and throw an exception. The 159.1457 - * exception class must have a constructor with a single String argument. 159.1458 - * 159.1459 - * @param type the class of the exception to be thrown. 159.1460 - * @param msg the detailed message of the exception. 159.1461 - */ 159.1462 -public void throwException(final Type type, final String msg){ 159.1463 - newInstance(type); 159.1464 - dup(); 159.1465 - push(msg); 159.1466 - invokeConstructor(type, Method.getMethod("void <init> (String)")); 159.1467 - throwException(); 159.1468 -} 159.1469 - 159.1470 -/** 159.1471 - * Generates the instruction to check that the top stack value is of the 159.1472 - * given type. 159.1473 - * 159.1474 - * @param type a class or interface type. 159.1475 - */ 159.1476 -public void checkCast(final Type type){ 159.1477 - if(!type.equals(OBJECT_TYPE)) 159.1478 - { 159.1479 - typeInsn(Opcodes.CHECKCAST, type); 159.1480 - } 159.1481 -} 159.1482 - 159.1483 -/** 159.1484 - * Generates the instruction to test if the top stack value is of the given 159.1485 - * type. 159.1486 - * 159.1487 - * @param type a class or interface type. 159.1488 - */ 159.1489 -public void instanceOf(final Type type){ 159.1490 - typeInsn(Opcodes.INSTANCEOF, type); 159.1491 -} 159.1492 - 159.1493 -/** 159.1494 - * Generates the instruction to get the monitor of the top stack value. 159.1495 - */ 159.1496 -public void monitorEnter(){ 159.1497 - mv.visitInsn(Opcodes.MONITORENTER); 159.1498 -} 159.1499 - 159.1500 -/** 159.1501 - * Generates the instruction to release the monitor of the top stack value. 159.1502 - */ 159.1503 -public void monitorExit(){ 159.1504 - mv.visitInsn(Opcodes.MONITOREXIT); 159.1505 -} 159.1506 - 159.1507 -// ------------------------------------------------------------------------ 159.1508 -// Non instructions 159.1509 -// ------------------------------------------------------------------------ 159.1510 - 159.1511 -/** 159.1512 - * Marks the end of the visited method. 159.1513 - */ 159.1514 -public void endMethod(){ 159.1515 - if((access & Opcodes.ACC_ABSTRACT) == 0) 159.1516 - { 159.1517 - mv.visitMaxs(0, 0); 159.1518 - } 159.1519 - mv.visitEnd(); 159.1520 -} 159.1521 - 159.1522 -/** 159.1523 - * Marks the start of an exception handler. 159.1524 - * 159.1525 - * @param start beginning of the exception handler's scope (inclusive). 159.1526 - * @param end end of the exception handler's scope (exclusive). 159.1527 - * @param exception internal name of the type of exceptions handled by the 159.1528 - * handler. 159.1529 - */ 159.1530 -public void catchException( 159.1531 - final Label start, 159.1532 - final Label end, 159.1533 - final Type exception){ 159.1534 - mv.visitTryCatchBlock(start, end, mark(), exception.getInternalName()); 159.1535 -} 159.1536 -}
160.1 --- a/src/clojure/asm/commons/LocalVariablesSorter.java Sat Aug 21 06:25:44 2010 -0400 160.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 160.3 @@ -1,330 +0,0 @@ 160.4 -/*** 160.5 - * ASM: a very small and fast Java bytecode manipulation framework 160.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 160.7 - * All rights reserved. 160.8 - * 160.9 - * Redistribution and use in source and binary forms, with or without 160.10 - * modification, are permitted provided that the following conditions 160.11 - * are met: 160.12 - * 1. Redistributions of source code must retain the above copyright 160.13 - * notice, this list of conditions and the following disclaimer. 160.14 - * 2. Redistributions in binary form must reproduce the above copyright 160.15 - * notice, this list of conditions and the following disclaimer in the 160.16 - * documentation and/or other materials provided with the distribution. 160.17 - * 3. Neither the name of the copyright holders nor the names of its 160.18 - * contributors may be used to endorse or promote products derived from 160.19 - * this software without specific prior written permission. 160.20 - * 160.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 160.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 160.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 160.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 160.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 160.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 160.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 160.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 160.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 160.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 160.31 - * THE POSSIBILITY OF SUCH DAMAGE. 160.32 - */ 160.33 -package clojure.asm.commons; 160.34 - 160.35 -import clojure.asm.Label; 160.36 -import clojure.asm.MethodAdapter; 160.37 -import clojure.asm.MethodVisitor; 160.38 -import clojure.asm.Opcodes; 160.39 -import clojure.asm.Type; 160.40 - 160.41 -/** 160.42 - * A {@link MethodAdapter} that renumbers local variables in their order of 160.43 - * appearance. This adapter allows one to easily add new local variables to a 160.44 - * method. It may be used by inheriting from this class, but the preferred way 160.45 - * of using it is via delegation: the next visitor in the chain can indeed add 160.46 - * new locals when needed by calling {@link #newLocal} on this adapter (this 160.47 - * requires a reference back to this {@link LocalVariablesSorter}). 160.48 - * 160.49 - * @author Chris Nokleberg 160.50 - * @author Eugene Kuleshov 160.51 - * @author Eric Bruneton 160.52 - */ 160.53 -public class LocalVariablesSorter extends MethodAdapter{ 160.54 - 160.55 -private final static Type OBJECT_TYPE = Type.getObjectType("java/lang/Object"); 160.56 - 160.57 -/** 160.58 - * Mapping from old to new local variable indexes. A local variable at index 160.59 - * i of size 1 is remapped to 'mapping[2*i]', while a local variable at 160.60 - * index i of size 2 is remapped to 'mapping[2*i+1]'. 160.61 - */ 160.62 -private int[] mapping = new int[40]; 160.63 - 160.64 -/** 160.65 - * Array used to store stack map local variable types after remapping. 160.66 - */ 160.67 -private Object[] newLocals = new Object[20]; 160.68 - 160.69 -/** 160.70 - * Index of the first local variable, after formal parameters. 160.71 - */ 160.72 -protected final int firstLocal; 160.73 - 160.74 -/** 160.75 - * Index of the next local variable to be created by {@link #newLocal}. 160.76 - */ 160.77 -protected int nextLocal; 160.78 - 160.79 -/** 160.80 - * Indicates if at least one local variable has moved due to remapping. 160.81 - */ 160.82 -private boolean changed; 160.83 - 160.84 -/** 160.85 - * Creates a new {@link LocalVariablesSorter}. 160.86 - * 160.87 - * @param access access flags of the adapted method. 160.88 - * @param desc the method's descriptor (see {@link Type Type}). 160.89 - * @param mv the method visitor to which this adapter delegates calls. 160.90 - */ 160.91 -public LocalVariablesSorter( 160.92 - final int access, 160.93 - final String desc, 160.94 - final MethodVisitor mv){ 160.95 - super(mv); 160.96 - Type[] args = Type.getArgumentTypes(desc); 160.97 - nextLocal = (Opcodes.ACC_STATIC & access) != 0 ? 0 : 1; 160.98 - for(int i = 0; i < args.length; i++) 160.99 - { 160.100 - nextLocal += args[i].getSize(); 160.101 - } 160.102 - firstLocal = nextLocal; 160.103 -} 160.104 - 160.105 -public void visitVarInsn(final int opcode, final int var){ 160.106 - Type type; 160.107 - switch(opcode) 160.108 - { 160.109 - case Opcodes.LLOAD: 160.110 - case Opcodes.LSTORE: 160.111 - type = Type.LONG_TYPE; 160.112 - break; 160.113 - 160.114 - case Opcodes.DLOAD: 160.115 - case Opcodes.DSTORE: 160.116 - type = Type.DOUBLE_TYPE; 160.117 - break; 160.118 - 160.119 - case Opcodes.FLOAD: 160.120 - case Opcodes.FSTORE: 160.121 - type = Type.FLOAT_TYPE; 160.122 - break; 160.123 - 160.124 - case Opcodes.ILOAD: 160.125 - case Opcodes.ISTORE: 160.126 - type = Type.INT_TYPE; 160.127 - break; 160.128 - 160.129 - case Opcodes.ALOAD: 160.130 - case Opcodes.ASTORE: 160.131 - type = OBJECT_TYPE; 160.132 - break; 160.133 - 160.134 - // case RET: 160.135 - default: 160.136 - type = Type.VOID_TYPE; 160.137 - } 160.138 - mv.visitVarInsn(opcode, remap(var, type)); 160.139 -} 160.140 - 160.141 -public void visitIincInsn(final int var, final int increment){ 160.142 - mv.visitIincInsn(remap(var, Type.INT_TYPE), increment); 160.143 -} 160.144 - 160.145 -public void visitMaxs(final int maxStack, final int maxLocals){ 160.146 - mv.visitMaxs(maxStack, nextLocal); 160.147 -} 160.148 - 160.149 -public void visitLocalVariable( 160.150 - final String name, 160.151 - final String desc, 160.152 - final String signature, 160.153 - final Label start, 160.154 - final Label end, 160.155 - final int index){ 160.156 - int size = "J".equals(desc) || "D".equals(desc) ? 2 : 1; 160.157 - int newIndex = remap(index, size); 160.158 - mv.visitLocalVariable(name, desc, signature, start, end, newIndex); 160.159 -} 160.160 - 160.161 -public void visitFrame( 160.162 - final int type, 160.163 - final int nLocal, 160.164 - final Object[] local, 160.165 - final int nStack, 160.166 - final Object[] stack){ 160.167 - if(type != Opcodes.F_NEW) 160.168 - { // uncompressed frame 160.169 - throw new IllegalStateException("ClassReader.accept() should be called with EXPAND_FRAMES flag"); 160.170 - } 160.171 - 160.172 - if(!changed) 160.173 - { // optimization for the case where mapping = identity 160.174 - mv.visitFrame(type, nLocal, local, nStack, stack); 160.175 - return; 160.176 - } 160.177 - 160.178 - // creates a copy of newLocals 160.179 - Object[] oldLocals = new Object[newLocals.length]; 160.180 - System.arraycopy(newLocals, 0, oldLocals, 0, oldLocals.length); 160.181 - 160.182 - // copies types from 'local' to 'newLocals' 160.183 - // 'newLocals' already contains the variables added with 'newLocal' 160.184 - 160.185 - int index = 0; // old local variable index 160.186 - int number = 0; // old local variable number 160.187 - for(; number < nLocal; ++number) 160.188 - { 160.189 - Object t = local[number]; 160.190 - int size = t == Opcodes.LONG || t == Opcodes.DOUBLE ? 2 : 1; 160.191 - if(t != Opcodes.TOP) 160.192 - { 160.193 - setFrameLocal(remap(index, size), t); 160.194 - } 160.195 - index += size; 160.196 - } 160.197 - 160.198 - // removes TOP after long and double types as well as trailing TOPs 160.199 - 160.200 - index = 0; 160.201 - number = 0; 160.202 - for(int i = 0; index < newLocals.length; ++i) 160.203 - { 160.204 - Object t = newLocals[index++]; 160.205 - if(t != null && t != Opcodes.TOP) 160.206 - { 160.207 - newLocals[i] = t; 160.208 - number = i + 1; 160.209 - if(t == Opcodes.LONG || t == Opcodes.DOUBLE) 160.210 - { 160.211 - index += 1; 160.212 - } 160.213 - } 160.214 - else 160.215 - { 160.216 - newLocals[i] = Opcodes.TOP; 160.217 - } 160.218 - } 160.219 - 160.220 - // visits remapped frame 160.221 - mv.visitFrame(type, number, newLocals, nStack, stack); 160.222 - 160.223 - // restores original value of 'newLocals' 160.224 - newLocals = oldLocals; 160.225 -} 160.226 - 160.227 -// ------------- 160.228 - 160.229 -/** 160.230 - * Creates a new local variable of the given type. 160.231 - * 160.232 - * @param type the type of the local variable to be created. 160.233 - * @return the identifier of the newly created local variable. 160.234 - */ 160.235 -public int newLocal(final Type type){ 160.236 - Object t; 160.237 - switch(type.getSort()) 160.238 - { 160.239 - case Type.BOOLEAN: 160.240 - case Type.CHAR: 160.241 - case Type.BYTE: 160.242 - case Type.SHORT: 160.243 - case Type.INT: 160.244 - t = Opcodes.INTEGER; 160.245 - break; 160.246 - case Type.FLOAT: 160.247 - t = Opcodes.FLOAT; 160.248 - break; 160.249 - case Type.LONG: 160.250 - t = Opcodes.LONG; 160.251 - break; 160.252 - case Type.DOUBLE: 160.253 - t = Opcodes.DOUBLE; 160.254 - break; 160.255 - case Type.ARRAY: 160.256 - t = type.getDescriptor(); 160.257 - break; 160.258 - // case Type.OBJECT: 160.259 - default: 160.260 - t = type.getInternalName(); 160.261 - break; 160.262 - } 160.263 - int local = nextLocal; 160.264 - setLocalType(local, type); 160.265 - setFrameLocal(local, t); 160.266 - nextLocal += type.getSize(); 160.267 - return local; 160.268 -} 160.269 - 160.270 -/** 160.271 - * Sets the current type of the given local variable. The default 160.272 - * implementation of this method does nothing. 160.273 - * 160.274 - * @param local a local variable identifier, as returned by {@link #newLocal 160.275 - * newLocal()}. 160.276 - * @param type the type of the value being stored in the local variable 160.277 - */ 160.278 -protected void setLocalType(final int local, final Type type){ 160.279 -} 160.280 - 160.281 -private void setFrameLocal(final int local, final Object type){ 160.282 - int l = newLocals.length; 160.283 - if(local >= l) 160.284 - { 160.285 - Object[] a = new Object[Math.max(2 * l, local + 1)]; 160.286 - System.arraycopy(newLocals, 0, a, 0, l); 160.287 - newLocals = a; 160.288 - } 160.289 - newLocals[local] = type; 160.290 -} 160.291 - 160.292 -private int remap(final int var, final Type type){ 160.293 - if(var < firstLocal) 160.294 - { 160.295 - return var; 160.296 - } 160.297 - int key = 2 * var + type.getSize() - 1; 160.298 - int size = mapping.length; 160.299 - if(key >= size) 160.300 - { 160.301 - int[] newMapping = new int[Math.max(2 * size, key + 1)]; 160.302 - System.arraycopy(mapping, 0, newMapping, 0, size); 160.303 - mapping = newMapping; 160.304 - } 160.305 - int value = mapping[key]; 160.306 - if(value == 0) 160.307 - { 160.308 - value = nextLocal + 1; 160.309 - mapping[key] = value; 160.310 - setLocalType(nextLocal, type); 160.311 - nextLocal += type.getSize(); 160.312 - } 160.313 - if(value - 1 != var) 160.314 - { 160.315 - changed = true; 160.316 - } 160.317 - return value - 1; 160.318 -} 160.319 - 160.320 -private int remap(final int var, final int size){ 160.321 - if(var < firstLocal || !changed) 160.322 - { 160.323 - return var; 160.324 - } 160.325 - int key = 2 * var + size - 1; 160.326 - int value = key < mapping.length ? mapping[key] : 0; 160.327 - if(value == 0) 160.328 - { 160.329 - throw new IllegalStateException("Unknown local variable " + var); 160.330 - } 160.331 - return value - 1; 160.332 -} 160.333 -}
161.1 --- a/src/clojure/asm/commons/Method.java Sat Aug 21 06:25:44 2010 -0400 161.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 161.3 @@ -1,267 +0,0 @@ 161.4 -/*** 161.5 - * ASM: a very small and fast Java bytecode manipulation framework 161.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 161.7 - * All rights reserved. 161.8 - * 161.9 - * Redistribution and use in source and binary forms, with or without 161.10 - * modification, are permitted provided that the following conditions 161.11 - * are met: 161.12 - * 1. Redistributions of source code must retain the above copyright 161.13 - * notice, this list of conditions and the following disclaimer. 161.14 - * 2. Redistributions in binary form must reproduce the above copyright 161.15 - * notice, this list of conditions and the following disclaimer in the 161.16 - * documentation and/or other materials provided with the distribution. 161.17 - * 3. Neither the name of the copyright holders nor the names of its 161.18 - * contributors may be used to endorse or promote products derived from 161.19 - * this software without specific prior written permission. 161.20 - * 161.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 161.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 161.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 161.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 161.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 161.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 161.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 161.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 161.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 161.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 161.31 - * THE POSSIBILITY OF SUCH DAMAGE. 161.32 - */ 161.33 -package clojure.asm.commons; 161.34 - 161.35 -import java.util.HashMap; 161.36 -import java.util.Map; 161.37 - 161.38 -import clojure.asm.Type; 161.39 - 161.40 -/** 161.41 - * A named method descriptor. 161.42 - * 161.43 - * @author Juozas Baliuka 161.44 - * @author Chris Nokleberg 161.45 - * @author Eric Bruneton 161.46 - */ 161.47 -public class Method{ 161.48 - 161.49 -/** 161.50 - * The method name. 161.51 - */ 161.52 -private final String name; 161.53 - 161.54 -/** 161.55 - * The method descriptor. 161.56 - */ 161.57 -private final String desc; 161.58 - 161.59 -/** 161.60 - * Maps primitive Java type names to their descriptors. 161.61 - */ 161.62 -private final static Map DESCRIPTORS; 161.63 - 161.64 -static 161.65 - { 161.66 - DESCRIPTORS = new HashMap(); 161.67 - DESCRIPTORS.put("void", "V"); 161.68 - DESCRIPTORS.put("byte", "B"); 161.69 - DESCRIPTORS.put("char", "C"); 161.70 - DESCRIPTORS.put("double", "D"); 161.71 - DESCRIPTORS.put("float", "F"); 161.72 - DESCRIPTORS.put("int", "I"); 161.73 - DESCRIPTORS.put("long", "J"); 161.74 - DESCRIPTORS.put("short", "S"); 161.75 - DESCRIPTORS.put("boolean", "Z"); 161.76 - } 161.77 - 161.78 -/** 161.79 - * Creates a new {@link Method}. 161.80 - * 161.81 - * @param name the method's name. 161.82 - * @param desc the method's descriptor. 161.83 - */ 161.84 -public Method(final String name, final String desc){ 161.85 - this.name = name; 161.86 - this.desc = desc; 161.87 -} 161.88 - 161.89 -/** 161.90 - * Creates a new {@link Method}. 161.91 - * 161.92 - * @param name the method's name. 161.93 - * @param returnType the method's return type. 161.94 - * @param argumentTypes the method's argument types. 161.95 - */ 161.96 -public Method( 161.97 - final String name, 161.98 - final Type returnType, 161.99 - final Type[] argumentTypes){ 161.100 - this(name, Type.getMethodDescriptor(returnType, argumentTypes)); 161.101 -} 161.102 - 161.103 -/** 161.104 - * Returns a {@link Method} corresponding to the given Java method 161.105 - * declaration. 161.106 - * 161.107 - * @param method a Java method declaration, without argument names, of the 161.108 - * form "returnType name (argumentType1, ... argumentTypeN)", where 161.109 - * the types are in plain Java (e.g. "int", "float", 161.110 - * "java.util.List", ...). Classes of the java.lang package can be 161.111 - * specified by their unqualified name; all other classes names must 161.112 - * be fully qualified. 161.113 - * @return a {@link Method} corresponding to the given Java method 161.114 - * declaration. 161.115 - * @throws IllegalArgumentException if <code>method</code> could not get 161.116 - * parsed. 161.117 - */ 161.118 -public static Method getMethod(final String method) 161.119 - throws IllegalArgumentException{ 161.120 - return getMethod(method, false); 161.121 -} 161.122 - 161.123 -/** 161.124 - * Returns a {@link Method} corresponding to the given Java method 161.125 - * declaration. 161.126 - * 161.127 - * @param method a Java method declaration, without argument names, of the 161.128 - * form "returnType name (argumentType1, ... argumentTypeN)", where 161.129 - * the types are in plain Java (e.g. "int", "float", 161.130 - * "java.util.List", ...). Classes of the java.lang package may be 161.131 - * specified by their unqualified name, depending on the 161.132 - * defaultPackage argument; all other classes names must be fully 161.133 - * qualified. 161.134 - * @param defaultPackage true if unqualified class names belong to the 161.135 - * default package, or false if they correspond to java.lang classes. 161.136 - * For instance "Object" means "Object" if this option is true, or 161.137 - * "java.lang.Object" otherwise. 161.138 - * @return a {@link Method} corresponding to the given Java method 161.139 - * declaration. 161.140 - * @throws IllegalArgumentException if <code>method</code> could not get 161.141 - * parsed. 161.142 - */ 161.143 -public static Method getMethod( 161.144 - final String method, 161.145 - final boolean defaultPackage) throws IllegalArgumentException{ 161.146 - int space = method.indexOf(' '); 161.147 - int start = method.indexOf('(', space) + 1; 161.148 - int end = method.indexOf(')', start); 161.149 - if(space == -1 || start == -1 || end == -1) 161.150 - { 161.151 - throw new IllegalArgumentException(); 161.152 - } 161.153 - // TODO: Check validity of returnType, methodName and arguments. 161.154 - String returnType = method.substring(0, space); 161.155 - String methodName = method.substring(space + 1, start - 1).trim(); 161.156 - StringBuffer sb = new StringBuffer(); 161.157 - sb.append('('); 161.158 - int p; 161.159 - do 161.160 - { 161.161 - String s; 161.162 - p = method.indexOf(',', start); 161.163 - if(p == -1) 161.164 - { 161.165 - s = map(method.substring(start, end).trim(), defaultPackage); 161.166 - } 161.167 - else 161.168 - { 161.169 - s = map(method.substring(start, p).trim(), defaultPackage); 161.170 - start = p + 1; 161.171 - } 161.172 - sb.append(s); 161.173 - } while(p != -1); 161.174 - sb.append(')'); 161.175 - sb.append(map(returnType, defaultPackage)); 161.176 - return new Method(methodName, sb.toString()); 161.177 -} 161.178 - 161.179 -private static String map(final String type, final boolean defaultPackage){ 161.180 - if(type.equals("")) 161.181 - { 161.182 - return type; 161.183 - } 161.184 - 161.185 - StringBuffer sb = new StringBuffer(); 161.186 - int index = 0; 161.187 - while((index = type.indexOf("[]", index) + 1) > 0) 161.188 - { 161.189 - sb.append('['); 161.190 - } 161.191 - 161.192 - String t = type.substring(0, type.length() - sb.length() * 2); 161.193 - String desc = (String) DESCRIPTORS.get(t); 161.194 - if(desc != null) 161.195 - { 161.196 - sb.append(desc); 161.197 - } 161.198 - else 161.199 - { 161.200 - sb.append('L'); 161.201 - if(t.indexOf('.') < 0) 161.202 - { 161.203 - if(!defaultPackage) 161.204 - { 161.205 - sb.append("java/lang/"); 161.206 - } 161.207 - sb.append(t); 161.208 - } 161.209 - else 161.210 - { 161.211 - sb.append(t.replace('.', '/')); 161.212 - } 161.213 - sb.append(';'); 161.214 - } 161.215 - return sb.toString(); 161.216 -} 161.217 - 161.218 -/** 161.219 - * Returns the name of the method described by this object. 161.220 - * 161.221 - * @return the name of the method described by this object. 161.222 - */ 161.223 -public String getName(){ 161.224 - return name; 161.225 -} 161.226 - 161.227 -/** 161.228 - * Returns the descriptor of the method described by this object. 161.229 - * 161.230 - * @return the descriptor of the method described by this object. 161.231 - */ 161.232 -public String getDescriptor(){ 161.233 - return desc; 161.234 -} 161.235 - 161.236 -/** 161.237 - * Returns the return type of the method described by this object. 161.238 - * 161.239 - * @return the return type of the method described by this object. 161.240 - */ 161.241 -public Type getReturnType(){ 161.242 - return Type.getReturnType(desc); 161.243 -} 161.244 - 161.245 -/** 161.246 - * Returns the argument types of the method described by this object. 161.247 - * 161.248 - * @return the argument types of the method described by this object. 161.249 - */ 161.250 -public Type[] getArgumentTypes(){ 161.251 - return Type.getArgumentTypes(desc); 161.252 -} 161.253 - 161.254 -public String toString(){ 161.255 - return name + desc; 161.256 -} 161.257 - 161.258 -public boolean equals(final Object o){ 161.259 - if(!(o instanceof Method)) 161.260 - { 161.261 - return false; 161.262 - } 161.263 - Method other = (Method) o; 161.264 - return name.equals(other.name) && desc.equals(other.desc); 161.265 -} 161.266 - 161.267 -public int hashCode(){ 161.268 - return name.hashCode() ^ desc.hashCode(); 161.269 -} 161.270 -} 161.271 \ No newline at end of file
162.1 --- a/src/clojure/asm/commons/SerialVersionUIDAdder.java Sat Aug 21 06:25:44 2010 -0400 162.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 162.3 @@ -1,508 +0,0 @@ 162.4 -/*** 162.5 - * ASM: a very small and fast Java bytecode manipulation framework 162.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 162.7 - * All rights reserved. 162.8 - * 162.9 - * Redistribution and use in source and binary forms, with or without 162.10 - * modification, are permitted provided that the following conditions 162.11 - * are met: 162.12 - * 1. Redistributions of source code must retain the above copyright 162.13 - * notice, this list of conditions and the following disclaimer. 162.14 - * 2. Redistributions in binary form must reproduce the above copyright 162.15 - * notice, this list of conditions and the following disclaimer in the 162.16 - * documentation and/or other materials provided with the distribution. 162.17 - * 3. Neither the name of the copyright holders nor the names of its 162.18 - * contributors may be used to endorse or promote products derived from 162.19 - * this software without specific prior written permission. 162.20 - * 162.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 162.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 162.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 162.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 162.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 162.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 162.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 162.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 162.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 162.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 162.31 - * THE POSSIBILITY OF SUCH DAMAGE. 162.32 - */ 162.33 -package clojure.asm.commons; 162.34 - 162.35 -import java.io.ByteArrayOutputStream; 162.36 -import java.io.DataOutputStream; 162.37 -import java.io.IOException; 162.38 -import java.security.MessageDigest; 162.39 -import java.util.ArrayList; 162.40 -import java.util.Arrays; 162.41 -import java.util.Collection; 162.42 - 162.43 -import clojure.asm.ClassAdapter; 162.44 -import clojure.asm.ClassVisitor; 162.45 -import clojure.asm.FieldVisitor; 162.46 -import clojure.asm.MethodVisitor; 162.47 -import clojure.asm.Opcodes; 162.48 - 162.49 -/** 162.50 - * A {@link ClassAdapter} that adds a serial version unique identifier to a 162.51 - * class if missing. Here is typical usage of this class: 162.52 - * <p/> 162.53 - * <pre> 162.54 - * ClassWriter cw = new ClassWriter(...); 162.55 - * ClassVisitor sv = new SerialVersionUIDAdder(cw); 162.56 - * ClassVisitor ca = new MyClassAdapter(sv); 162.57 - * new ClassReader(orginalClass).accept(ca, false); 162.58 - * </pre> 162.59 - * <p/> 162.60 - * The SVUID algorithm can be found <a href= 162.61 - * "http://java.sun.com/j2se/1.4.2/docs/guide/serialization/spec/class.html" 162.62 - * >http://java.sun.com/j2se/1.4.2/docs/guide/serialization/spec/class.html</a>: 162.63 - * <p/> 162.64 - * <pre> 162.65 - * The serialVersionUID is computed using the signature of a stream of bytes 162.66 - * that reflect the class definition. The National Institute of Standards and 162.67 - * Technology (NIST) Secure Hash Algorithm (SHA-1) is used to compute a 162.68 - * signature for the stream. The first two 32-bit quantities are used to form a 162.69 - * 64-bit hash. A java.lang.DataOutputStream is used to convert primitive data 162.70 - * types to a sequence of bytes. The values input to the stream are defined by 162.71 - * the Java Virtual Machine (VM) specification for classes. 162.72 - * <p/> 162.73 - * The sequence of items in the stream is as follows: 162.74 - * <p/> 162.75 - * 1. The class name written using UTF encoding. 162.76 - * 2. The class modifiers written as a 32-bit integer. 162.77 - * 3. The name of each interface sorted by name written using UTF encoding. 162.78 - * 4. For each field of the class sorted by field name (except private static 162.79 - * and private transient fields): 162.80 - * 1. The name of the field in UTF encoding. 162.81 - * 2. The modifiers of the field written as a 32-bit integer. 162.82 - * 3. The descriptor of the field in UTF encoding 162.83 - * 5. If a class initializer exists, write out the following: 162.84 - * 1. The name of the method, <clinit>, in UTF encoding. 162.85 - * 2. The modifier of the method, java.lang.reflect.Modifier.STATIC, 162.86 - * written as a 32-bit integer. 162.87 - * 3. The descriptor of the method, ()V, in UTF encoding. 162.88 - * 6. For each non-private constructor sorted by method name and signature: 162.89 - * 1. The name of the method, <init>, in UTF encoding. 162.90 - * 2. The modifiers of the method written as a 32-bit integer. 162.91 - * 3. The descriptor of the method in UTF encoding. 162.92 - * 7. For each non-private method sorted by method name and signature: 162.93 - * 1. The name of the method in UTF encoding. 162.94 - * 2. The modifiers of the method written as a 32-bit integer. 162.95 - * 3. The descriptor of the method in UTF encoding. 162.96 - * 8. The SHA-1 algorithm is executed on the stream of bytes produced by 162.97 - * DataOutputStream and produces five 32-bit values sha[0..4]. 162.98 - * <p/> 162.99 - * 9. The hash value is assembled from the first and second 32-bit values of 162.100 - * the SHA-1 message digest. If the result of the message digest, the five 162.101 - * 32-bit words H0 H1 H2 H3 H4, is in an array of five int values named 162.102 - * sha, the hash value would be computed as follows: 162.103 - * <p/> 162.104 - * long hash = ((sha[0] >>> 24) & 0xFF) | 162.105 - * ((sha[0] >>> 16) & 0xFF) << 8 | 162.106 - * ((sha[0] >>> 8) & 0xFF) << 16 | 162.107 - * ((sha[0] >>> 0) & 0xFF) << 24 | 162.108 - * ((sha[1] >>> 24) & 0xFF) << 32 | 162.109 - * ((sha[1] >>> 16) & 0xFF) << 40 | 162.110 - * ((sha[1] >>> 8) & 0xFF) << 48 | 162.111 - * ((sha[1] >>> 0) & 0xFF) << 56; 162.112 - * </pre> 162.113 - * 162.114 - * @author Rajendra Inamdar, Vishal Vishnoi 162.115 - */ 162.116 -public class SerialVersionUIDAdder extends ClassAdapter{ 162.117 - 162.118 -/** 162.119 - * Flag that indicates if we need to compute SVUID. 162.120 - */ 162.121 -protected boolean computeSVUID; 162.122 - 162.123 -/** 162.124 - * Set to true if the class already has SVUID. 162.125 - */ 162.126 -protected boolean hasSVUID; 162.127 - 162.128 -/** 162.129 - * Classes access flags. 162.130 - */ 162.131 -protected int access; 162.132 - 162.133 -/** 162.134 - * Internal name of the class 162.135 - */ 162.136 -protected String name; 162.137 - 162.138 -/** 162.139 - * Interfaces implemented by the class. 162.140 - */ 162.141 -protected String[] interfaces; 162.142 - 162.143 -/** 162.144 - * Collection of fields. (except private static and private transient 162.145 - * fields) 162.146 - */ 162.147 -protected Collection svuidFields; 162.148 - 162.149 -/** 162.150 - * Set to true if the class has static initializer. 162.151 - */ 162.152 -protected boolean hasStaticInitializer; 162.153 - 162.154 -/** 162.155 - * Collection of non-private constructors. 162.156 - */ 162.157 -protected Collection svuidConstructors; 162.158 - 162.159 -/** 162.160 - * Collection of non-private methods. 162.161 - */ 162.162 -protected Collection svuidMethods; 162.163 - 162.164 -/** 162.165 - * Creates a new {@link SerialVersionUIDAdder}. 162.166 - * 162.167 - * @param cv a {@link ClassVisitor} to which this visitor will delegate 162.168 - * calls. 162.169 - */ 162.170 -public SerialVersionUIDAdder(final ClassVisitor cv){ 162.171 - super(cv); 162.172 - svuidFields = new ArrayList(); 162.173 - svuidConstructors = new ArrayList(); 162.174 - svuidMethods = new ArrayList(); 162.175 -} 162.176 - 162.177 -// ------------------------------------------------------------------------ 162.178 -// Overriden methods 162.179 -// ------------------------------------------------------------------------ 162.180 - 162.181 -/* 162.182 - * Visit class header and get class name, access , and intefraces 162.183 - * informatoin (step 1,2, and 3) for SVUID computation. 162.184 - */ 162.185 - 162.186 -public void visit( 162.187 - final int version, 162.188 - final int access, 162.189 - final String name, 162.190 - final String signature, 162.191 - final String superName, 162.192 - final String[] interfaces){ 162.193 - computeSVUID = (access & Opcodes.ACC_INTERFACE) == 0; 162.194 - 162.195 - if(computeSVUID) 162.196 - { 162.197 - this.name = name; 162.198 - this.access = access; 162.199 - this.interfaces = interfaces; 162.200 - } 162.201 - 162.202 - super.visit(version, access, name, signature, superName, interfaces); 162.203 -} 162.204 - 162.205 -/* 162.206 - * Visit the methods and get constructor and method information (step 5 and 162.207 - * 7). Also determince if there is a class initializer (step 6). 162.208 - */ 162.209 -public MethodVisitor visitMethod( 162.210 - final int access, 162.211 - final String name, 162.212 - final String desc, 162.213 - final String signature, 162.214 - final String[] exceptions){ 162.215 - if(computeSVUID) 162.216 - { 162.217 - if(name.equals("<clinit>")) 162.218 - { 162.219 - hasStaticInitializer = true; 162.220 - } 162.221 - /* 162.222 - * Remembers non private constructors and methods for SVUID 162.223 - * computation For constructor and method modifiers, only the 162.224 - * ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, 162.225 - * ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT and ACC_STRICT flags 162.226 - * are used. 162.227 - */ 162.228 - int mods = access 162.229 - & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE 162.230 - | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC 162.231 - | Opcodes.ACC_FINAL | Opcodes.ACC_SYNCHRONIZED 162.232 - | Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_STRICT); 162.233 - 162.234 - // all non private methods 162.235 - if((access & Opcodes.ACC_PRIVATE) == 0) 162.236 - { 162.237 - if(name.equals("<init>")) 162.238 - { 162.239 - svuidConstructors.add(new Item(name, mods, desc)); 162.240 - } 162.241 - else if(!name.equals("<clinit>")) 162.242 - { 162.243 - svuidMethods.add(new Item(name, mods, desc)); 162.244 - } 162.245 - } 162.246 - } 162.247 - 162.248 - return cv.visitMethod(access, name, desc, signature, exceptions); 162.249 -} 162.250 - 162.251 -/* 162.252 - * Gets class field information for step 4 of the alogrithm. Also determines 162.253 - * if the class already has a SVUID. 162.254 - */ 162.255 -public FieldVisitor visitField( 162.256 - final int access, 162.257 - final String name, 162.258 - final String desc, 162.259 - final String signature, 162.260 - final Object value){ 162.261 - if(computeSVUID) 162.262 - { 162.263 - if(name.equals("serialVersionUID")) 162.264 - { 162.265 - // since the class already has SVUID, we won't be computing it. 162.266 - computeSVUID = false; 162.267 - hasSVUID = true; 162.268 - } 162.269 - /* 162.270 - * Remember field for SVUID computation For field modifiers, only 162.271 - * the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, 162.272 - * ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when 162.273 - * computing serialVersionUID values. 162.274 - */ 162.275 - int mods = access 162.276 - & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE 162.277 - | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC 162.278 - | Opcodes.ACC_FINAL | Opcodes.ACC_VOLATILE | Opcodes.ACC_TRANSIENT); 162.279 - 162.280 - if((access & Opcodes.ACC_PRIVATE) == 0 162.281 - || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0) 162.282 - { 162.283 - svuidFields.add(new Item(name, mods, desc)); 162.284 - } 162.285 - } 162.286 - 162.287 - return super.visitField(access, name, desc, signature, value); 162.288 -} 162.289 - 162.290 -/* 162.291 - * Add the SVUID if class doesn't have one 162.292 - */ 162.293 -public void visitEnd(){ 162.294 - // compute SVUID and add it to the class 162.295 - if(computeSVUID && !hasSVUID) 162.296 - { 162.297 - try 162.298 - { 162.299 - cv.visitField(Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, 162.300 - "serialVersionUID", 162.301 - "J", 162.302 - null, 162.303 - new Long(computeSVUID())); 162.304 - } 162.305 - catch(Throwable e) 162.306 - { 162.307 - throw new RuntimeException("Error while computing SVUID for " 162.308 - + name, e); 162.309 - } 162.310 - } 162.311 - 162.312 - super.visitEnd(); 162.313 -} 162.314 - 162.315 -// ------------------------------------------------------------------------ 162.316 -// Utility methods 162.317 -// ------------------------------------------------------------------------ 162.318 - 162.319 -/** 162.320 - * Returns the value of SVUID if the class doesn't have one already. Please 162.321 - * note that 0 is returned if the class already has SVUID, thus use 162.322 - * <code>isHasSVUID</code> to determine if the class already had an SVUID. 162.323 - * 162.324 - * @return Returns the serial version UID 162.325 - * @throws IOException 162.326 - */ 162.327 -protected long computeSVUID() throws IOException{ 162.328 - ByteArrayOutputStream bos = null; 162.329 - DataOutputStream dos = null; 162.330 - long svuid = 0; 162.331 - 162.332 - try 162.333 - { 162.334 - bos = new ByteArrayOutputStream(); 162.335 - dos = new DataOutputStream(bos); 162.336 - 162.337 - /* 162.338 - * 1. The class name written using UTF encoding. 162.339 - */ 162.340 - dos.writeUTF(name.replace('/', '.')); 162.341 - 162.342 - /* 162.343 - * 2. The class modifiers written as a 32-bit integer. 162.344 - */ 162.345 - dos.writeInt(access 162.346 - & (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL 162.347 - | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT)); 162.348 - 162.349 - /* 162.350 - * 3. The name of each interface sorted by name written using UTF 162.351 - * encoding. 162.352 - */ 162.353 - Arrays.sort(interfaces); 162.354 - for(int i = 0; i < interfaces.length; i++) 162.355 - { 162.356 - dos.writeUTF(interfaces[i].replace('/', '.')); 162.357 - } 162.358 - 162.359 - /* 162.360 - * 4. For each field of the class sorted by field name (except 162.361 - * private static and private transient fields): 162.362 - * 162.363 - * 1. The name of the field in UTF encoding. 2. The modifiers of the 162.364 - * field written as a 32-bit integer. 3. The descriptor of the field 162.365 - * in UTF encoding 162.366 - * 162.367 - * Note that field signatutes are not dot separated. Method and 162.368 - * constructor signatures are dot separated. Go figure... 162.369 - */ 162.370 - writeItems(svuidFields, dos, false); 162.371 - 162.372 - /* 162.373 - * 5. If a class initializer exists, write out the following: 1. The 162.374 - * name of the method, <clinit>, in UTF encoding. 2. The modifier of 162.375 - * the method, java.lang.reflect.Modifier.STATIC, written as a 162.376 - * 32-bit integer. 3. The descriptor of the method, ()V, in UTF 162.377 - * encoding. 162.378 - */ 162.379 - if(hasStaticInitializer) 162.380 - { 162.381 - dos.writeUTF("<clinit>"); 162.382 - dos.writeInt(Opcodes.ACC_STATIC); 162.383 - dos.writeUTF("()V"); 162.384 - } // if.. 162.385 - 162.386 - /* 162.387 - * 6. For each non-private constructor sorted by method name and 162.388 - * signature: 1. The name of the method, <init>, in UTF encoding. 2. 162.389 - * The modifiers of the method written as a 32-bit integer. 3. The 162.390 - * descriptor of the method in UTF encoding. 162.391 - */ 162.392 - writeItems(svuidConstructors, dos, true); 162.393 - 162.394 - /* 162.395 - * 7. For each non-private method sorted by method name and 162.396 - * signature: 1. The name of the method in UTF encoding. 2. The 162.397 - * modifiers of the method written as a 32-bit integer. 3. The 162.398 - * descriptor of the method in UTF encoding. 162.399 - */ 162.400 - writeItems(svuidMethods, dos, true); 162.401 - 162.402 - dos.flush(); 162.403 - 162.404 - /* 162.405 - * 8. The SHA-1 algorithm is executed on the stream of bytes 162.406 - * produced by DataOutputStream and produces five 32-bit values 162.407 - * sha[0..4]. 162.408 - */ 162.409 - byte[] hashBytes = computeSHAdigest(bos.toByteArray()); 162.410 - 162.411 - /* 162.412 - * 9. The hash value is assembled from the first and second 32-bit 162.413 - * values of the SHA-1 message digest. If the result of the message 162.414 - * digest, the five 32-bit words H0 H1 H2 H3 H4, is in an array of 162.415 - * five int values named sha, the hash value would be computed as 162.416 - * follows: 162.417 - * 162.418 - * long hash = ((sha[0] >>> 24) & 0xFF) | ((sha[0] >>> 16) & 0xFF) << 162.419 - * 8 | ((sha[0] >>> 8) & 0xFF) << 16 | ((sha[0] >>> 0) & 0xFF) << 162.420 - * 24 | ((sha[1] >>> 24) & 0xFF) << 32 | ((sha[1] >>> 16) & 0xFF) << 162.421 - * 40 | ((sha[1] >>> 8) & 0xFF) << 48 | ((sha[1] >>> 0) & 0xFF) << 162.422 - * 56; 162.423 - */ 162.424 - for(int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) 162.425 - { 162.426 - svuid = (svuid << 8) | (hashBytes[i] & 0xFF); 162.427 - } 162.428 - } 162.429 - finally 162.430 - { 162.431 - // close the stream (if open) 162.432 - if(dos != null) 162.433 - { 162.434 - dos.close(); 162.435 - } 162.436 - } 162.437 - 162.438 - return svuid; 162.439 -} 162.440 - 162.441 -/** 162.442 - * Returns the SHA-1 message digest of the given value. 162.443 - * 162.444 - * @param value the value whose SHA message digest must be computed. 162.445 - * @return the SHA-1 message digest of the given value. 162.446 - */ 162.447 -protected byte[] computeSHAdigest(final byte[] value){ 162.448 - try 162.449 - { 162.450 - return MessageDigest.getInstance("SHA").digest(value); 162.451 - } 162.452 - catch(Exception e) 162.453 - { 162.454 - throw new UnsupportedOperationException(e); 162.455 - } 162.456 -} 162.457 - 162.458 -/** 162.459 - * Sorts the items in the collection and writes it to the data output stream 162.460 - * 162.461 - * @param itemCollection collection of items 162.462 - * @param dos a <code>DataOutputStream</code> value 162.463 - * @param dotted a <code>boolean</code> value 162.464 - * @throws IOException if an error occurs 162.465 - */ 162.466 -private void writeItems( 162.467 - final Collection itemCollection, 162.468 - final DataOutputStream dos, 162.469 - final boolean dotted) throws IOException{ 162.470 - int size = itemCollection.size(); 162.471 - Item items[] = (Item[]) itemCollection.toArray(new Item[size]); 162.472 - Arrays.sort(items); 162.473 - for(int i = 0; i < size; i++) 162.474 - { 162.475 - dos.writeUTF(items[i].name); 162.476 - dos.writeInt(items[i].access); 162.477 - dos.writeUTF(dotted 162.478 - ? items[i].desc.replace('/', '.') 162.479 - : items[i].desc); 162.480 - } 162.481 -} 162.482 - 162.483 -// ------------------------------------------------------------------------ 162.484 -// Inner classes 162.485 -// ------------------------------------------------------------------------ 162.486 - 162.487 -static class Item implements Comparable{ 162.488 - 162.489 - String name; 162.490 - 162.491 - int access; 162.492 - 162.493 - String desc; 162.494 - 162.495 - Item(final String name, final int access, final String desc){ 162.496 - this.name = name; 162.497 - this.access = access; 162.498 - this.desc = desc; 162.499 - } 162.500 - 162.501 - public int compareTo(final Object o){ 162.502 - Item other = (Item) o; 162.503 - int retVal = name.compareTo(other.name); 162.504 - if(retVal == 0) 162.505 - { 162.506 - retVal = desc.compareTo(other.desc); 162.507 - } 162.508 - return retVal; 162.509 - } 162.510 -} 162.511 -}
163.1 --- a/src/clojure/asm/commons/StaticInitMerger.java Sat Aug 21 06:25:44 2010 -0400 163.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 163.3 @@ -1,102 +0,0 @@ 163.4 -/*** 163.5 - * ASM: a very small and fast Java bytecode manipulation framework 163.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 163.7 - * All rights reserved. 163.8 - * 163.9 - * Redistribution and use in source and binary forms, with or without 163.10 - * modification, are permitted provided that the following conditions 163.11 - * are met: 163.12 - * 1. Redistributions of source code must retain the above copyright 163.13 - * notice, this list of conditions and the following disclaimer. 163.14 - * 2. Redistributions in binary form must reproduce the above copyright 163.15 - * notice, this list of conditions and the following disclaimer in the 163.16 - * documentation and/or other materials provided with the distribution. 163.17 - * 3. Neither the name of the copyright holders nor the names of its 163.18 - * contributors may be used to endorse or promote products derived from 163.19 - * this software without specific prior written permission. 163.20 - * 163.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 163.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 163.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 163.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 163.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 163.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 163.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 163.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 163.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 163.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 163.31 - * THE POSSIBILITY OF SUCH DAMAGE. 163.32 - */ 163.33 -package clojure.asm.commons; 163.34 - 163.35 -import clojure.asm.ClassAdapter; 163.36 -import clojure.asm.ClassVisitor; 163.37 -import clojure.asm.MethodVisitor; 163.38 -import clojure.asm.Opcodes; 163.39 - 163.40 -/** 163.41 - * A {@link ClassAdapter} that merges clinit methods into a single one. 163.42 - * 163.43 - * @author Eric Bruneton 163.44 - */ 163.45 -public class StaticInitMerger extends ClassAdapter{ 163.46 - 163.47 -private String name; 163.48 - 163.49 -private MethodVisitor clinit; 163.50 - 163.51 -private String prefix; 163.52 - 163.53 -private int counter; 163.54 - 163.55 -public StaticInitMerger(final String prefix, final ClassVisitor cv){ 163.56 - super(cv); 163.57 - this.prefix = prefix; 163.58 -} 163.59 - 163.60 -public void visit( 163.61 - final int version, 163.62 - final int access, 163.63 - final String name, 163.64 - final String signature, 163.65 - final String superName, 163.66 - final String[] interfaces){ 163.67 - cv.visit(version, access, name, signature, superName, interfaces); 163.68 - this.name = name; 163.69 -} 163.70 - 163.71 -public MethodVisitor visitMethod( 163.72 - final int access, 163.73 - final String name, 163.74 - final String desc, 163.75 - final String signature, 163.76 - final String[] exceptions){ 163.77 - MethodVisitor mv; 163.78 - if(name.equals("<clinit>")) 163.79 - { 163.80 - int a = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC; 163.81 - String n = prefix + counter++; 163.82 - mv = cv.visitMethod(a, n, desc, signature, exceptions); 163.83 - 163.84 - if(clinit == null) 163.85 - { 163.86 - clinit = cv.visitMethod(a, name, desc, null, null); 163.87 - } 163.88 - clinit.visitMethodInsn(Opcodes.INVOKESTATIC, this.name, n, desc); 163.89 - } 163.90 - else 163.91 - { 163.92 - mv = cv.visitMethod(access, name, desc, signature, exceptions); 163.93 - } 163.94 - return mv; 163.95 -} 163.96 - 163.97 -public void visitEnd(){ 163.98 - if(clinit != null) 163.99 - { 163.100 - clinit.visitInsn(Opcodes.RETURN); 163.101 - clinit.visitMaxs(0, 0); 163.102 - } 163.103 - cv.visitEnd(); 163.104 -} 163.105 -}
164.1 --- a/src/clojure/asm/commons/TableSwitchGenerator.java Sat Aug 21 06:25:44 2010 -0400 164.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 164.3 @@ -1,55 +0,0 @@ 164.4 -/*** 164.5 - * ASM: a very small and fast Java bytecode manipulation framework 164.6 - * Copyright (c) 2000-2005 INRIA, France Telecom 164.7 - * All rights reserved. 164.8 - * 164.9 - * Redistribution and use in source and binary forms, with or without 164.10 - * modification, are permitted provided that the following conditions 164.11 - * are met: 164.12 - * 1. Redistributions of source code must retain the above copyright 164.13 - * notice, this list of conditions and the following disclaimer. 164.14 - * 2. Redistributions in binary form must reproduce the above copyright 164.15 - * notice, this list of conditions and the following disclaimer in the 164.16 - * documentation and/or other materials provided with the distribution. 164.17 - * 3. Neither the name of the copyright holders nor the names of its 164.18 - * contributors may be used to endorse or promote products derived from 164.19 - * this software without specific prior written permission. 164.20 - * 164.21 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 164.22 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 164.23 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 164.24 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 164.25 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 164.26 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 164.27 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 164.28 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 164.29 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 164.30 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 164.31 - * THE POSSIBILITY OF SUCH DAMAGE. 164.32 - */ 164.33 -package clojure.asm.commons; 164.34 - 164.35 -import clojure.asm.Label; 164.36 - 164.37 -/** 164.38 - * A code generator for switch statements. 164.39 - * 164.40 - * @author Juozas Baliuka 164.41 - * @author Chris Nokleberg 164.42 - * @author Eric Bruneton 164.43 - */ 164.44 -public interface TableSwitchGenerator{ 164.45 - 164.46 -/** 164.47 - * Generates the code for a switch case. 164.48 - * 164.49 - * @param key the switch case key. 164.50 - * @param end a label that corresponds to the end of the switch statement. 164.51 - */ 164.52 -void generateCase(int key, Label end); 164.53 - 164.54 -/** 164.55 - * Generates the code for the default switch case. 164.56 - */ 164.57 -void generateDefault(); 164.58 -}
165.1 --- a/src/clojure/asm/commons/package.html Sat Aug 21 06:25:44 2010 -0400 165.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 165.3 @@ -1,48 +0,0 @@ 165.4 -<html> 165.5 -<!-- 165.6 - * ASM: a very small and fast Java bytecode manipulation framework 165.7 - * Copyright (c) 2000-2005 INRIA, France Telecom 165.8 - * All rights reserved. 165.9 - * 165.10 - * Redistribution and use in source and binary forms, with or without 165.11 - * modification, are permitted provided that the following conditions 165.12 - * are met: 165.13 - * 1. Redistributions of source code must retain the above copyright 165.14 - * notice, this list of conditions and the following disclaimer. 165.15 - * 2. Redistributions in binary form must reproduce the above copyright 165.16 - * notice, this list of conditions and the following disclaimer in the 165.17 - * documentation and/or other materials provided with the distribution. 165.18 - * 3. Neither the name of the copyright holders nor the names of its 165.19 - * contributors may be used to endorse or promote products derived from 165.20 - * this software without specific prior written permission. 165.21 - * 165.22 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 165.23 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 165.24 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 165.25 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 165.26 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 165.27 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 165.28 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 165.29 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 165.30 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 165.31 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 165.32 - * THE POSSIBILITY OF SUCH DAMAGE. 165.33 ---> 165.34 -<body> 165.35 -Provides some useful class and method adapters. <i>The preferred way of using 165.36 - these adapters is by chaining them together and to custom adapters (instead of 165.37 - inheriting from them)</i>. Indeed this approach provides more combination 165.38 -possibilities than inheritance. For instance, suppose you want to implement an 165.39 -adapter MyAdapter than needs sorted local variables and intermediate stack map 165.40 -frame values taking into account the local variables sort. By using inheritance, 165.41 -this would require MyAdapter to extend AnalyzerAdapter, itself extending 165.42 -LocalVariablesSorter. But AnalyzerAdapter is not a subclass of 165.43 -LocalVariablesSorter, so this is not possible. On the contrary, by using 165.44 -delegation, you can make LocalVariablesSorter delegate to AnalyzerAdapter, 165.45 -itself delegating to MyAdapter. In this case AnalyzerAdapter computes 165.46 -intermediate frames based on the output of LocalVariablesSorter, and MyAdapter 165.47 -can add new locals by calling the newLocal method on LocalVariablesSorter, and 165.48 -can get the stack map frame state before each instruction by reading the locals 165.49 -and stack fields in AnalyzerAdapter (this requires references from MyAdapter 165.50 -back to LocalVariablesSorter and AnalyzerAdapter). 165.51 -</body> 165.52 \ No newline at end of file
166.1 --- a/src/clojure/asm/package.html Sat Aug 21 06:25:44 2010 -0400 166.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 166.3 @@ -1,87 +0,0 @@ 166.4 -<html> 166.5 -<!-- 166.6 - * ASM: a very small and fast Java bytecode manipulation framework 166.7 - * Copyright (c) 2000-2005 INRIA, France Telecom 166.8 - * All rights reserved. 166.9 - * 166.10 - * Redistribution and use in source and binary forms, with or without 166.11 - * modification, are permitted provided that the following conditions 166.12 - * are met: 166.13 - * 1. Redistributions of source code must retain the above copyright 166.14 - * notice, this list of conditions and the following disclaimer. 166.15 - * 2. Redistributions in binary form must reproduce the above copyright 166.16 - * notice, this list of conditions and the following disclaimer in the 166.17 - * documentation and/or other materials provided with the distribution. 166.18 - * 3. Neither the name of the copyright holders nor the names of its 166.19 - * contributors may be used to endorse or promote products derived from 166.20 - * this software without specific prior written permission. 166.21 - * 166.22 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 166.23 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 166.24 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 166.25 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 166.26 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 166.27 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 166.28 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 166.29 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 166.30 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 166.31 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 166.32 - * THE POSSIBILITY OF SUCH DAMAGE. 166.33 ---> 166.34 -<body> 166.35 -Provides a small and fast bytecode manipulation framework. 166.36 - 166.37 -<p> 166.38 - The <a href="http://www.objectweb.org/asm">ASM</a> framework is organized 166.39 - around the {@link clojure.asm.ClassVisitor ClassVisitor}, 166.40 - {@link clojure.asm.FieldVisitor FieldVisitor} and 166.41 - {@link clojure.asm.MethodVisitor MethodVisitor} interfaces, which allow 166.42 - one to visit the fields and methods of a class, including the bytecode 166.43 - instructions of each method. 166.44 - 166.45 -<p> 166.46 - In addition to these main interfaces, ASM provides a {@link 166.47 - clojure.asm.ClassReader ClassReader} class, that can parse an 166.48 - existing class and make a given visitor visit it. ASM also provides 166.49 - a {@link clojure.asm.ClassWriter ClassWriter} class, which is 166.50 - a visitor that generates Java class files. 166.51 - 166.52 -<p> 166.53 - In order to generate a class from scratch, only the {@link 166.54 - clojure.asm.ClassWriter ClassWriter} class is necessary. Indeed, 166.55 - in order to generate a class, one must just call its visit<i>XXX</i> 166.56 - methods with the appropriate arguments to generate the desired fields 166.57 - and methods. See the "helloworld" example in the ASM distribution for 166.58 - more details about class generation. 166.59 - 166.60 -<p> 166.61 - In order to modify existing classes, one must use a {@link 166.62 - clojure.asm.ClassReader ClassReader} class to analyze 166.63 - the original class, a class modifier, and a {@link clojure.asm.ClassWriter 166.64 - ClassWriter} to construct the modified class. The class modifier 166.65 - is just a {@link clojure.asm.ClassVisitor ClassVisitor} 166.66 - that delegates most of the work to another {@link clojure.asm.ClassVisitor 166.67 - ClassVisitor}, but that sometimes changes some parameter values, 166.68 - or call additional methods, in order to implement the desired 166.69 - modification process. In order to make it easier to implement such 166.70 - class modifiers, ASM provides the {@link clojure.asm.ClassAdapter 166.71 - ClassAdapter} and {@link clojure.asm.MethodAdapter MethodAdapter} 166.72 - classes, which implement the {@link clojure.asm.ClassVisitor ClassVisitor} 166.73 - and {@link clojure.asm.MethodVisitor MethodVisitor} interfaces by 166.74 - delegating all work to other visitors. See the "adapt" example in the ASM 166.75 - distribution for more details about class modification. 166.76 - 166.77 -<p> 166.78 - The size of the core ASM library, <tt>asm.jar</tt>, is only 42KB, which is much 166.79 - smaller than the size of the 166.80 - <a href="http://jakarta.apache.org/bcel">BCEL</a> library (504KB), and than the 166.81 - size of the 166.82 - <a href="http://serp.sourceforge.net">SERP</a> library (150KB). ASM is also 166.83 - much faster than these tools. Indeed the overhead of a load time class 166.84 - transformation process is of the order of 60% with ASM, 700% or more with BCEL, 166.85 - and 1100% or more with SERP (see the <tt>test/perf</tt> directory in the ASM 166.86 - distribution)! 166.87 - 166.88 - @since ASM 1.3 166.89 -</body> 166.90 -</html>
167.1 --- a/src/clojure/contrib/accumulators.clj Sat Aug 21 06:25:44 2010 -0400 167.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 167.3 @@ -1,324 +0,0 @@ 167.4 -;; Accumulators 167.5 - 167.6 -;; by Konrad Hinsen 167.7 -;; last updated May 19, 2009 167.8 - 167.9 -;; This module defines various accumulators (list, vector, map, 167.10 -;; sum, product, counter, and combinations thereof) with a common 167.11 -;; interface defined by the multimethods add and combine. 167.12 -;; For each accumulator type, its empty value is defined in this module. 167.13 -;; Applications typically use this as a starting value and add data 167.14 -;; using the add multimethod. 167.15 - 167.16 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 167.17 -;; and distribution terms for this software are covered by the Eclipse 167.18 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 167.19 -;; which can be found in the file epl-v10.html at the root of this 167.20 -;; distribution. By using this software in any fashion, you are 167.21 -;; agreeing to be bound by the terms of this license. You must not 167.22 -;; remove this notice, or any other, from this software. 167.23 - 167.24 -(ns 167.25 - ^{:author "Konrad Hinsen" 167.26 - :doc "A generic accumulator interface and implementations of various 167.27 - accumulators."} 167.28 - clojure.contrib.accumulators 167.29 - (:refer-clojure :exclude (deftype)) 167.30 - (:use [clojure.contrib.types :only (deftype)]) 167.31 - (:use [clojure.contrib.def :only (defvar defvar- defmacro-)]) 167.32 - (:require [clojure.contrib.generic.arithmetic :as ga])) 167.33 - 167.34 -(defmulti add 167.35 - "Add item to the accumulator acc. The exact meaning of adding an 167.36 - an item depends on the type of the accumulator." 167.37 - {:arglists '([acc item])} 167.38 - (fn [acc item] (type acc))) 167.39 - 167.40 -(defn add-items 167.41 - "Add all elements of a collection coll to the accumulator acc." 167.42 - [acc items] 167.43 - (reduce add acc items)) 167.44 - 167.45 -(defmulti combine 167.46 - "Combine the values of the accumulators acc1 and acc2 into a 167.47 - single accumulator of the same type." 167.48 - {:arglists '([& accs])} 167.49 - (fn [& accs] (type (first accs)))) 167.50 - 167.51 -; 167.52 -; An ::accumulator type tag is attached to tbe built-in types 167.53 -; when used as accumulators, and new types are derived from it. 167.54 -; Multimethods add and combine for ::accumulator sub-dispatch on class. 167.55 -; We also define generic addition as the combine operation. 167.56 -; 167.57 -(let [meta-map {:type ::accumulator}] 167.58 - (defn- with-acc-tag 167.59 - [x] 167.60 - (with-meta x meta-map))) 167.61 - 167.62 -(defmethod add ::accumulator 167.63 - [a e] 167.64 - ((get-method add (class a)) a e)) 167.65 - 167.66 -(defmethod combine ::accumulator 167.67 - [& as] 167.68 - (apply (get-method combine (class (first as))) as)) 167.69 - 167.70 -(defmethod ga/+ ::accumulator 167.71 - [x y] 167.72 - (combine x y)) 167.73 - 167.74 -; 167.75 -; Vector accumulator 167.76 -; 167.77 -(defvar empty-vector (with-acc-tag []) 167.78 - "An empty vector accumulator. Adding an item appends it at the end.") 167.79 - 167.80 -(defmethod combine clojure.lang.IPersistentVector 167.81 - [& vs] 167.82 - (with-acc-tag (vec (apply concat vs)))) 167.83 - 167.84 -(defmethod add clojure.lang.IPersistentVector 167.85 - [v e] 167.86 - (with-acc-tag (conj v e))) 167.87 - 167.88 -; 167.89 -; List accumulator 167.90 -; 167.91 -(defvar empty-list (with-acc-tag '()) 167.92 - "An empty list accumulator. Adding an item appends it at the beginning.") 167.93 - 167.94 -(defmethod combine clojure.lang.IPersistentList 167.95 - [& vs] 167.96 - (with-acc-tag (apply concat vs))) 167.97 - 167.98 -(defmethod add clojure.lang.IPersistentList 167.99 - [v e] 167.100 - (with-acc-tag (conj v e))) 167.101 - 167.102 -; 167.103 -; Queue accumulator 167.104 -; 167.105 -(defvar empty-queue (with-acc-tag clojure.lang.PersistentQueue/EMPTY) 167.106 - "An empty queue accumulator. Adding an item appends it at the end.") 167.107 - 167.108 -(defmethod combine clojure.lang.PersistentQueue 167.109 - [& vs] 167.110 - (add-items (first vs) (apply concat (rest vs)))) 167.111 - 167.112 -(defmethod add clojure.lang.PersistentQueue 167.113 - [v e] 167.114 - (with-acc-tag (conj v e))) 167.115 - 167.116 -; 167.117 -; Set accumulator 167.118 -; 167.119 -(defvar empty-set (with-acc-tag #{}) 167.120 - "An empty set accumulator.") 167.121 - 167.122 -(defmethod combine (class empty-set) 167.123 - [& vs] 167.124 - (with-acc-tag (apply clojure.set/union vs))) 167.125 - 167.126 -(defmethod add (class empty-set) 167.127 - [v e] 167.128 - (with-acc-tag (conj v e))) 167.129 - 167.130 -; 167.131 -; String accumulator 167.132 -; 167.133 -(defvar empty-string "" 167.134 - "An empty string accumulator. Adding an item (string or character) 167.135 - appends it at the end.") 167.136 - 167.137 -(defmethod combine java.lang.String 167.138 - [& vs] 167.139 - (apply str vs)) 167.140 - 167.141 -(defmethod add java.lang.String 167.142 - [v e] 167.143 - (str v e)) 167.144 - 167.145 -; 167.146 -; Map accumulator 167.147 -; 167.148 -(defvar empty-map (with-acc-tag {}) 167.149 - "An empty map accumulator. Items to be added must be [key value] pairs.") 167.150 - 167.151 -(defmethod combine clojure.lang.IPersistentMap 167.152 - [& vs] 167.153 - (with-acc-tag (apply merge vs))) 167.154 - 167.155 -(defmethod add clojure.lang.IPersistentMap 167.156 - [v e] 167.157 - (with-acc-tag (conj v e))) 167.158 - 167.159 -; 167.160 -; Numerical accumulators: sum, product, minimum, maximum 167.161 -; 167.162 -(defmacro- defacc 167.163 - [name op empty doc-string] 167.164 - (let [type-tag (keyword (str *ns*) (str name)) 167.165 - empty-symbol (symbol (str "empty-" name))] 167.166 - `(let [op# ~op] 167.167 - (deftype ~type-tag ~name 167.168 - (fn [~'x] {:value ~'x}) 167.169 - (fn [~'x] (list (:value ~'x)))) 167.170 - (derive ~type-tag ::accumulator) 167.171 - (defvar ~empty-symbol (~name ~empty) ~doc-string) 167.172 - (defmethod combine ~type-tag [& vs#] 167.173 - (~name (apply op# (map :value vs#)))) 167.174 - (defmethod add ~type-tag [v# e#] 167.175 - (~name (op# (:value v#) e#)))))) 167.176 - 167.177 -(defacc sum + 0 167.178 - "An empty sum accumulator. Only numbers can be added.") 167.179 - 167.180 -(defacc product * 1 167.181 - "An empty sum accumulator. Only numbers can be added.") 167.182 - 167.183 -; The empty maximum accumulator should have value -infinity. 167.184 -; This is represented by nil and taken into account in an 167.185 -; adapted max function. In the minimum accumulator, nil is 167.186 -; similarly used to represent +infinity. 167.187 - 167.188 -(defacc maximum (fn [& xs] 167.189 - (when-let [xs (seq (filter identity xs))] 167.190 - (apply max xs))) 167.191 - nil 167.192 - "An empty maximum accumulator. Only numbers can be added.") 167.193 - 167.194 -(defacc minimum (fn [& xs] 167.195 - (when-let [xs (seq (filter identity xs))] 167.196 - (apply min xs))) 167.197 - nil 167.198 - "An empty minimum accumulator. Only numbers can be added.") 167.199 - 167.200 -; 167.201 -; Numeric min-max accumulator 167.202 -; (combination of minimum and maximum) 167.203 -; 167.204 -(deftype ::min-max min-max 167.205 - (fn [min max] {:min min :max max}) 167.206 - (fn [mm] (list (:min mm) (:max mm)))) 167.207 - 167.208 -(derive ::min-max ::accumulator) 167.209 - 167.210 -(defvar empty-min-max (min-max nil nil) 167.211 - "An empty min-max accumulator, combining minimum and maximum. 167.212 - Only numbers can be added.") 167.213 - 167.214 -(defmethod combine ::min-max 167.215 - [& vs] 167.216 - (let [total-min (apply min (map :min vs)) 167.217 - total-max (apply max (map :max vs))] 167.218 - (min-max total-min total-max))) 167.219 - 167.220 -(defmethod add ::min-max 167.221 - [v e] 167.222 - (let [min-v (:min v) 167.223 - max-v (:max v) 167.224 - new-min (if (nil? min-v) e (min min-v e)) 167.225 - new-max (if (nil? max-v) e (max max-v e))] 167.226 - (min-max new-min new-max))) 167.227 - 167.228 -; 167.229 -; Mean and variance accumulator 167.230 -; 167.231 -(deftype ::mean-variance mean-variance) 167.232 - 167.233 -(derive ::mean-variance ::accumulator) 167.234 - 167.235 -(defvar empty-mean-variance (mean-variance {:n 0 :mean 0 :variance 0}) 167.236 - "An empty mean-variance accumulator, combining sample mean and 167.237 - sample variance. Only numbers can be added.") 167.238 - 167.239 -(defmethod combine ::mean-variance 167.240 - ([mv] 167.241 - mv) 167.242 - 167.243 - ([mv1 mv2] 167.244 - (let [{n1 :n mean1 :mean var1 :variance} mv1 167.245 - {n2 :n mean2 :mean var2 :variance} mv2 167.246 - n (+ n1 n2) 167.247 - mean (/ (+ (* n1 mean1) (* n2 mean2)) n) 167.248 - sq #(* % %) 167.249 - c (+ (* n1 (sq (- mean mean1))) (* n2 (sq (- mean mean2)))) 167.250 - var (if (< n 2) 167.251 - 0 167.252 - (/ (+ c (* (dec n1) var1) (* (dec n2) var2)) (dec n)))] 167.253 - (mean-variance {:n n :mean mean :variance var}))) 167.254 - 167.255 - ([mv1 mv2 & mvs] 167.256 - (reduce combine (combine mv1 mv2) mvs))) 167.257 - 167.258 -(defmethod add ::mean-variance 167.259 - [mv x] 167.260 - (let [{n :n mean :mean var :variance} mv 167.261 - n1 (inc n) 167.262 - d (- x mean) 167.263 - new-mean (+ mean (/ d n1)) 167.264 - new-var (if (zero? n) 0 (/ (+ (* (dec n) var) (* d (- x new-mean))) n))] 167.265 - (mean-variance {:n n1 :mean new-mean :variance new-var}))) 167.266 - 167.267 -; 167.268 -; Counter accumulator 167.269 -; 167.270 -(deftype ::counter counter) 167.271 - 167.272 -(derive ::counter ::accumulator) 167.273 - 167.274 -(defvar empty-counter (counter {}) 167.275 - "An empty counter accumulator. Its value is a map that stores for 167.276 - every item the number of times it was added.") 167.277 - 167.278 -(defmethod combine ::counter 167.279 - [v & vs] 167.280 - (letfn [(add-item [cntr [item n]] 167.281 - (assoc cntr item (+ n (get cntr item 0)))) 167.282 - (add-two [c1 c2] (reduce add-item c1 c2))] 167.283 - (reduce add-two v vs))) 167.284 - 167.285 -(defmethod add ::counter 167.286 - [v e] 167.287 - (assoc v e (inc (get v e 0)))) 167.288 - 167.289 -; 167.290 -; Counter accumulator with total count 167.291 -; 167.292 -(deftype ::counter-with-total counter-with-total) 167.293 -(derive ::counter-with-total ::counter) 167.294 - 167.295 -(defvar empty-counter-with-total 167.296 - (counter-with-total {:total 0}) 167.297 - "An empty counter-with-total accumulator. It works like the counter 167.298 - accumulator, except that the total number of items added is stored as the 167.299 - value of the key :total.") 167.300 - 167.301 -(defmethod add ::counter-with-total 167.302 - [v e] 167.303 - (assoc v e (inc (get v e 0)) 167.304 - :total (inc (:total v)))) 167.305 - 167.306 -; 167.307 -; Accumulator n-tuple 167.308 -; 167.309 -(deftype ::tuple acc-tuple) 167.310 - 167.311 -(derive ::tuple ::accumulator) 167.312 - 167.313 -(defn empty-tuple 167.314 - "Returns an accumulator tuple with the supplied empty-accumulators 167.315 - as its value. Accumulator tuples consist of several accumulators that 167.316 - work in parallel. Added items must be sequences whose number of elements 167.317 - matches the number of sub-accumulators." 167.318 - [empty-accumulators] 167.319 - (acc-tuple (into [] empty-accumulators))) 167.320 - 167.321 -(defmethod combine ::tuple 167.322 - [& vs] 167.323 - (acc-tuple (vec (map combine vs)))) 167.324 - 167.325 -(defmethod add ::tuple 167.326 - [v e] 167.327 - (acc-tuple (vec (map add v e))))
168.1 --- a/src/clojure/contrib/agent_utils.clj Sat Aug 21 06:25:44 2010 -0400 168.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 168.3 @@ -1,35 +0,0 @@ 168.4 -; Copyright (c) Christophe Grand, November 2008. All rights reserved. 168.5 - 168.6 -; The use and distribution terms for this software are covered by the 168.7 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 168.8 -; which can be found in the file epl-v10.html at the root of this 168.9 -; distribution. 168.10 -; By using this software in any fashion, you are agreeing to be bound by 168.11 -; the terms of this license. 168.12 -; You must not remove this notice, or any other, from this software. 168.13 - 168.14 -;; misc agent utilities 168.15 - 168.16 -;; note to other contrib members: feel free to add to this lib 168.17 - 168.18 -(ns 168.19 - ^{:author "Christophe Grande", 168.20 - :doc "Miscellaneous agent utilities 168.21 - (note to other contrib members: feel free to add to this lib)", 168.22 -} 168.23 - clojure.contrib.agent-utils) 168.24 - 168.25 -(defmacro capture-and-send 168.26 - "Capture the current value of the specified vars and rebind 168.27 - them on the agent thread before executing the action. 168.28 - 168.29 - Example: 168.30 - (capture-and-send [*out*] a f b c)" 168.31 - 168.32 - [vars agent action & args] 168.33 - (let [locals (map #(gensym (name %)) vars)] 168.34 - `(let [~@(interleave locals vars) 168.35 - action# (fn [& args#] 168.36 - (binding [~@(interleave vars locals)] 168.37 - (apply ~action args#)))] 168.38 - (send ~agent action# ~@args))))
169.1 --- a/src/clojure/contrib/apply_macro.clj Sat Aug 21 06:25:44 2010 -0400 169.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 169.3 @@ -1,45 +0,0 @@ 169.4 -;;; apply_macro.clj: make macros behave like functions 169.5 - 169.6 -;; by Stuart Sierra, http://stuartsierra.com/ 169.7 -;; January 28, 2009 169.8 - 169.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 169.10 -;; and distribution terms for this software are covered by the Eclipse 169.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 169.12 -;; which can be found in the file epl-v10.html at the root of this 169.13 -;; distribution. By using this software in any fashion, you are 169.14 -;; agreeing to be bound by the terms of this license. You must not 169.15 -;; remove this notice, or any other, from this software. 169.16 - 169.17 - 169.18 -;; Don't use this. I mean it. It's evil. How evil? You can't 169.19 -;; handle it, that's how evil it is. That's right. I did it so you 169.20 -;; don't have to, ok? Look but don't touch. Use this lib and you'll 169.21 -;; go blind. 169.22 - 169.23 -;; DEPRECATED in 1.2 with no replacement. 169.24 - 169.25 -(ns ^{:deprecated "1.2"} 169.26 - clojure.contrib.apply-macro) 169.27 - 169.28 -;; Copied from clojure.core/spread, which is private. 169.29 -(defn- spread 169.30 - "Flatten final argument list as in apply." 169.31 - [arglist] 169.32 - (cond 169.33 - (nil? arglist) nil 169.34 - (nil? (rest arglist)) (seq (first arglist)) 169.35 - :else (cons (first arglist) (spread (rest arglist))))) 169.36 - 169.37 -(defmacro apply-macro 169.38 - "This is evil. Don't ever use it. It makes a macro behave like a 169.39 - function. Seriously, how messed up is that? 169.40 - 169.41 - Evaluates all args, then uses them as arguments to the macro as with 169.42 - apply. 169.43 - 169.44 - (def things [true true false]) 169.45 - (apply-macro and things) 169.46 - ;; Expands to: (and true true false)" 169.47 - [macro & args] 169.48 - (cons macro (spread (map eval args))))
170.1 --- a/src/clojure/contrib/base64.clj Sat Aug 21 06:25:44 2010 -0400 170.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 170.3 @@ -1,99 +0,0 @@ 170.4 -;;; base64.clj: Experimental Base-64 encoding and (later) decoding 170.5 - 170.6 -;; by Stuart Sierra, http://stuartsierra.com/ 170.7 -;; August 19, 2009 170.8 - 170.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 170.10 -;; and distribution terms for this software are covered by the Eclipse 170.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 170.12 -;; which can be found in the file epl-v10.html at the root of this 170.13 -;; distribution. By using this software in any fashion, you are 170.14 -;; agreeing to be bound by the terms of this license. You must not 170.15 -;; remove this notice, or any other, from this software. 170.16 - 170.17 - 170.18 -(ns ^{:doc "Base-64 encoding and (maybe later) decoding. 170.19 - 170.20 - This is mainly here as an example. It is much slower than the 170.21 - Apache Commons Codec implementation or sun.misc.BASE64Encoder." 170.22 - :author "Stuart Sierra"} 170.23 - clojure.contrib.base64 170.24 - (:import (java.io InputStream Writer ByteArrayInputStream 170.25 - StringWriter))) 170.26 - 170.27 -(def *base64-alphabet* 170.28 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=") 170.29 - 170.30 -(defn encode 170.31 - "Encodes bytes of input, writing Base 64 text on output. alphabet 170.32 - is a 65-character String containing the 64 characters to use in the 170.33 - encoding; the 65th character is the pad character. line-length is 170.34 - the maximum number of characters per line, nil for no line breaks." 170.35 - [^InputStream input ^Writer output ^String alphabet line-length] 170.36 - (let [buffer (make-array Byte/TYPE 3)] 170.37 - (loop [line 0] 170.38 - (let [len (.read input buffer)] 170.39 - (when (pos? len) 170.40 - ;; Pre-boxing the bytes as Integers is more efficient for 170.41 - ;; Clojure's bit operations. 170.42 - (let [b0 (Integer/valueOf (int (aget buffer 0))) 170.43 - b1 (Integer/valueOf (int (aget buffer 1))) 170.44 - b2 (Integer/valueOf (int (aget buffer 2)))] 170.45 - (cond (= len 3) 170.46 - (let [s0 (bit-and 0x3F (bit-shift-right b0 2)) 170.47 - s1 (bit-and 0x3F 170.48 - (bit-or (bit-shift-left b0 4) 170.49 - (bit-shift-right b1 4))) 170.50 - s2 (bit-and 0x3F 170.51 - (bit-or (bit-shift-left b1 2) 170.52 - (bit-shift-right b2 6))) 170.53 - s3 (bit-and 0x3F b2)] 170.54 - (.append output (.charAt alphabet s0)) 170.55 - (.append output (.charAt alphabet s1)) 170.56 - (.append output (.charAt alphabet s2)) 170.57 - (.append output (.charAt alphabet s3))) 170.58 - 170.59 - (= len 2) 170.60 - (let [s0 (bit-and 0x3F (bit-shift-right b0 2)) 170.61 - s1 (bit-and 0x3F 170.62 - (bit-or (bit-shift-left b0 4) 170.63 - (bit-shift-right b1 4))) 170.64 - s2 (bit-and 0x3F (bit-shift-left b1 2))] 170.65 - (.append output (.charAt alphabet s0)) 170.66 - (.append output (.charAt alphabet s1)) 170.67 - (.append output (.charAt alphabet s2)) 170.68 - (.append output (.charAt alphabet 64))) 170.69 - 170.70 - (= len 1) 170.71 - (let [s0 (bit-and 0x3F (bit-shift-right b0 2)) 170.72 - s1 (bit-and 0x3F (bit-shift-left b0 4))] 170.73 - (.append output (.charAt alphabet s0)) 170.74 - (.append output (.charAt alphabet s1)) 170.75 - (.append output (.charAt alphabet 64)) 170.76 - (.append output (.charAt alphabet 64))))) 170.77 - (if (and line-length (> (+ line 4) line-length)) 170.78 - (do (.append output \newline) 170.79 - (recur 0)) 170.80 - (recur (+ line 4)))))))) 170.81 - 170.82 -(defn encode-str 170.83 - "Encodes String in base 64; returns a String. If not specified, 170.84 - encoding is UTF-8 and line-length is nil." 170.85 - ([s] (encode-str s "UTF-8" nil)) 170.86 - ([^String s ^String encoding line-length] 170.87 - (let [output (StringWriter.)] 170.88 - (encode (ByteArrayInputStream. (.getBytes s encoding)) 170.89 - output *base64-alphabet* line-length) 170.90 - (.toString output)))) 170.91 - 170.92 - 170.93 -;;; tests 170.94 - 170.95 -;; (deftest t-encode-str 170.96 -;; (is (= (encode-str "") "")) 170.97 -;; (is (= (encode-str "f") "Zg==")) 170.98 -;; (is (= (encode-str "fo") "Zm8=")) 170.99 -;; (is (= (encode-str "foo") "Zm9v")) 170.100 -;; (is (= (encode-str "foob") "Zm9vYg==")) 170.101 -;; (is (= (encode-str "fooba") "Zm9vYmE=")) 170.102 -;; (is (= (encode-str "foobar") "Zm9vYmFy")))
171.1 --- a/src/clojure/contrib/classpath.clj Sat Aug 21 06:25:44 2010 -0400 171.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 171.3 @@ -1,39 +0,0 @@ 171.4 -;;; classpath.clj: utilities for working with the Java class path 171.5 - 171.6 -;; by Stuart Sierra, http://stuartsierra.com/ 171.7 -;; April 19, 2009 171.8 - 171.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 171.10 -;; and distribution terms for this software are covered by the Eclipse 171.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 171.12 -;; which can be found in the file epl-v10.html at the root of this 171.13 -;; distribution. By using this software in any fashion, you are 171.14 -;; agreeing to be bound by the terms of this license. You must not 171.15 -;; remove this notice, or any other, from this software. 171.16 - 171.17 - 171.18 -(ns 171.19 - ^{:author "Stuart Sierra", 171.20 - :doc "Utilities for dealing with the JVM's classpath"} 171.21 - clojure.contrib.classpath 171.22 - (:require [clojure.contrib.jar :as jar]) 171.23 - (:import (java.io File) 171.24 - (java.util.jar JarFile))) 171.25 - 171.26 -(defn classpath 171.27 - "Returns a sequence of File objects of the elements on CLASSPATH." 171.28 - [] 171.29 - (map #(File. %) 171.30 - (.split (System/getProperty "java.class.path") 171.31 - (System/getProperty "path.separator")))) 171.32 - 171.33 -(defn classpath-directories 171.34 - "Returns a sequence of File objects for the directories on classpath." 171.35 - [] 171.36 - (filter #(.isDirectory %) (classpath))) 171.37 - 171.38 -(defn classpath-jarfiles 171.39 - "Returns a sequence of JarFile objects for the JAR files on classpath." 171.40 - [] 171.41 - (map #(JarFile. %) (filter jar/jar-file? (classpath)))) 171.42 -
172.1 --- a/src/clojure/contrib/combinatorics.clj Sat Aug 21 06:25:44 2010 -0400 172.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 172.3 @@ -1,164 +0,0 @@ 172.4 -;;; combinatorics.clj: efficient, functional algorithms for generating lazy 172.5 -;;; sequences for common combinatorial functions. 172.6 - 172.7 -;; by Mark Engelberg (mark.engelberg@gmail.com) 172.8 -;; January 27, 2009 172.9 - 172.10 -(comment 172.11 -" 172.12 -(combinations items n) - A lazy sequence of all the unique 172.13 -ways of taking n different elements from items. 172.14 -Example: (combinations [1 2 3] 2) -> ((1 2) (1 3) (2 3)) 172.15 - 172.16 -(subsets items) - A lazy sequence of all the subsets of 172.17 -items (but generalized to all sequences, not just sets). 172.18 -Example: (subsets [1 2 3]) -> (() (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) 172.19 - 172.20 -(cartesian-product & seqs) - Takes any number of sequences 172.21 -as arguments, and returns a lazy sequence of all the ways 172.22 -to take one item from each seq. 172.23 -Example: (cartesian-product [1 2] [3 4]) -> ((1 3) (1 4) (2 3) (2 4)) 172.24 -(cartesian-product seq1 seq2 seq3 ...) behaves like but is 172.25 -faster than a nested for loop, such as: 172.26 -(for [i1 seq1 i2 seq2 i3 seq3 ...] (list i1 i2 i3 ...)) 172.27 - 172.28 -(selections items n) - A lazy sequence of all the ways to 172.29 -take n (possibly the same) items from the sequence of items. 172.30 -Example: (selections [1 2] 3) -> ((1 1 1) (1 1 2) (1 2 1) (1 2 2) (2 1 1) (2 1 2) (2 2 1) (2 2 2)) 172.31 - 172.32 -(permutations items) - A lazy sequence of all the permutations 172.33 -of items. 172.34 -Example: (permutations [1 2 3]) -> ((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 2 1)) 172.35 - 172.36 -(lex-permutations items) - A lazy sequence of all distinct 172.37 -permutations in lexicographic order 172.38 -(this function returns the permutations as 172.39 -vectors). Only works on sequences of comparable 172.40 -items. (Note that the result will be quite different from 172.41 -permutations when the sequence contains duplicate items.) 172.42 -Example: (lex-permutations [1 1 2]) -> ([1 1 2] [1 2 1] [2 1 1]) 172.43 - 172.44 -About permutations vs. lex-permutations: 172.45 -lex-permutations is faster than permutations, but only works 172.46 -on sequences of numbers. They operate differently 172.47 -on sequences with duplicate items (lex-permutations will only 172.48 -give you back distinct permutations). lex-permutations always 172.49 -returns the permutations sorted lexicographically whereas 172.50 -permutations will be in an order where the input sequence 172.51 -comes first. In general, I recommend using the regular 172.52 -permutations function unless you have a specific 172.53 -need for lex-permutations. 172.54 - 172.55 -About this code: 172.56 -These combinatorial functions can be written in an elegant way using recursion. However, when dealing with combinations and permutations, you're usually generating large numbers of things, and speed counts. My objective was to write the fastest possible code I could, restricting myself to Clojure's functional, persistent data structures (rather than using Java's arrays) so that this code could be safely leveraged within Clojure's transactional concurrency system. 172.57 - 172.58 -I also restricted myself to algorithms that return results in a standard order. For example, there are faster ways to generate cartesian-product, but I don't know of a faster way to generate the results in the standard nested-for-loop order. 172.59 - 172.60 -Most of these algorithms are derived from algorithms found in Knuth's wonderful Art of Computer Programming books (specifically, the volume 4 fascicles), which present fast, iterative solutions to these common combinatorial problems. Unfortunately, these iterative versions are somewhat inscrutable. If you want to better understand these algorithms, the Knuth books are the place to start. 172.61 - 172.62 -On my own computer, I use versions of all these algorithms that return sequences built with an uncached variation of lazy-seq. Not only does this boost performance, but it's easier to use these rather large sequences more safely (from a memory consumption standpoint). If some form of uncached sequences makes it into Clojure, I will update this accordingly. 172.63 -" 172.64 -) 172.65 - 172.66 - 172.67 -(ns 172.68 - ^{:author "Mark Engelberg", 172.69 - :doc "Efficient, functional algorithms for generating lazy 172.70 -sequences for common combinatorial functions. (See the source code 172.71 -for a longer description.)"} 172.72 - clojure.contrib.combinatorics) 172.73 - 172.74 -(defn- index-combinations 172.75 - [n cnt] 172.76 - (lazy-seq 172.77 - (let [c (vec (cons nil (for [j (range 1 (inc n))] (+ j cnt (- (inc n)))))), 172.78 - iter-comb 172.79 - (fn iter-comb [c j] 172.80 - (if (> j n) nil 172.81 - (let [c (assoc c j (dec (c j)))] 172.82 - (if (< (c j) j) [c (inc j)] 172.83 - (loop [c c, j j] 172.84 - (if (= j 1) [c j] 172.85 - (recur (assoc c (dec j) (dec (c j))) (dec j)))))))), 172.86 - step 172.87 - (fn step [c j] 172.88 - (cons (rseq (subvec c 1 (inc n))) 172.89 - (lazy-seq (let [next-step (iter-comb c j)] 172.90 - (when next-step (step (next-step 0) (next-step 1)))))))] 172.91 - (step c 1)))) 172.92 - 172.93 -(defn combinations 172.94 - "All the unique ways of taking n different elements from items" 172.95 - [items n] 172.96 - (let [v-items (vec (reverse items))] 172.97 - (if (zero? n) (list ()) 172.98 - (let [cnt (count items)] 172.99 - (cond (> n cnt) nil 172.100 - (= n cnt) (list (seq items)) 172.101 - :else 172.102 - (map #(map v-items %) (index-combinations n cnt))))))) 172.103 - 172.104 -(defn subsets 172.105 - "All the subsets of items" 172.106 - [items] 172.107 - (mapcat (fn [n] (combinations items n)) 172.108 - (range (inc (count items))))) 172.109 - 172.110 -(defn cartesian-product 172.111 - "All the ways to take one item from each sequence" 172.112 - [& seqs] 172.113 - (let [v-original-seqs (vec seqs) 172.114 - step 172.115 - (fn step [v-seqs] 172.116 - (let [increment 172.117 - (fn [v-seqs] 172.118 - (loop [i (dec (count v-seqs)), v-seqs v-seqs] 172.119 - (if (= i -1) nil 172.120 - (if-let [rst (next (v-seqs i))] 172.121 - (assoc v-seqs i rst) 172.122 - (recur (dec i) (assoc v-seqs i (v-original-seqs i)))))))] 172.123 - (when v-seqs 172.124 - (cons (map first v-seqs) 172.125 - (lazy-seq (step (increment v-seqs)))))))] 172.126 - (when (every? first seqs) 172.127 - (lazy-seq (step v-original-seqs))))) 172.128 - 172.129 - 172.130 -(defn selections 172.131 - "All the ways of taking n (possibly the same) elements from the sequence of items" 172.132 - [items n] 172.133 - (apply cartesian-product (take n (repeat items)))) 172.134 - 172.135 - 172.136 -(defn- iter-perm [v] 172.137 - (let [len (count v), 172.138 - j (loop [i (- len 2)] 172.139 - (cond (= i -1) nil 172.140 - (< (v i) (v (inc i))) i 172.141 - :else (recur (dec i))))] 172.142 - (when j 172.143 - (let [vj (v j), 172.144 - l (loop [i (dec len)] 172.145 - (if (< vj (v i)) i (recur (dec i))))] 172.146 - (loop [v (assoc v j (v l) l vj), k (inc j), l (dec len)] 172.147 - (if (< k l) 172.148 - (recur (assoc v k (v l) l (v k)) (inc k) (dec l)) 172.149 - v)))))) 172.150 - 172.151 -(defn- vec-lex-permutations [v] 172.152 - (when v (cons v (lazy-seq (vec-lex-permutations (iter-perm v)))))) 172.153 - 172.154 -(defn lex-permutations 172.155 - "Fast lexicographic permutation generator for a sequence of numbers" 172.156 - [c] 172.157 - (lazy-seq 172.158 - (let [vec-sorted (vec (sort c))] 172.159 - (if (zero? (count vec-sorted)) 172.160 - (list []) 172.161 - (vec-lex-permutations vec-sorted))))) 172.162 - 172.163 -(defn permutations 172.164 - "All the permutations of items, lexicographic by index" 172.165 - [items] 172.166 - (let [v (vec items)] 172.167 - (map #(map v %) (lex-permutations (range (count v))))))
173.1 --- a/src/clojure/contrib/command_line.clj Sat Aug 21 06:25:44 2010 -0400 173.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 173.3 @@ -1,121 +0,0 @@ 173.4 -; Copyright (c) Chris Houser, Nov-Dec 2008. All rights reserved. 173.5 -; The use and distribution terms for this software are covered by the 173.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 173.7 -; which can be found in the file epl-v10.html at the root of this distribution. 173.8 -; By using this software in any fashion, you are agreeing to be bound by 173.9 -; the terms of this license. 173.10 -; You must not remove this notice, or any other, from this software. 173.11 - 173.12 -; Process command-line arguments according to a given cmdspec 173.13 - 173.14 -(ns 173.15 - ^{:author "Chris Houser", 173.16 - :doc "Process command-line arguments according to a given cmdspec"} 173.17 - clojure.contrib.command-line 173.18 - (:use (clojure.contrib [string :only (join)]))) 173.19 - 173.20 -(defn make-map [args cmdspec] 173.21 - (let [{spec true [rest-sym] false} (group-by vector? cmdspec) 173.22 - rest-str (str rest-sym) 173.23 - key-data (into {} (for [[syms [_ default]] (map #(split-with symbol? %) 173.24 - (conj spec '[help? h?])) 173.25 - sym syms] 173.26 - [(re-find #"^.*[^?]" (str sym)) 173.27 - {:sym (str (first syms)) :default default}])) 173.28 - defaults (into {} (for [[_ {:keys [default sym]}] key-data 173.29 - :when default] 173.30 - [sym default]))] 173.31 - (loop [[argkey & [argval :as r]] args 173.32 - cmdmap (assoc defaults :cmdspec cmdspec rest-str [])] 173.33 - (if argkey 173.34 - (let [[_ & [keybase]] (re-find #"^--?(.*)" argkey)] 173.35 - (cond 173.36 - (= keybase nil) (recur r (update-in cmdmap [rest-str] conj argkey)) 173.37 - (= keybase "") (update-in cmdmap [rest-str] #(apply conj % r)) 173.38 - :else (if-let [found (key-data keybase)] 173.39 - (if (= \? (last (:sym found))) 173.40 - (recur r (assoc cmdmap (:sym found) true)) 173.41 - (recur (next r) (assoc cmdmap (:sym found) 173.42 - (if (or (nil? r) (= \- (ffirst r))) 173.43 - (:default found) 173.44 - (first r))))) 173.45 - (throw (Exception. (str "Unknown option " argkey)))))) 173.46 - cmdmap)))) 173.47 - 173.48 -(defn- align 173.49 - "Align strings given as vectors of columns, with first vector 173.50 - specifying right or left alignment (:r or :l) for each column." 173.51 - [spec & rows] 173.52 - (let [maxes (vec (for [n (range (count (first rows)))] 173.53 - (apply max (map (comp count #(nth % n)) rows)))) 173.54 - fmt (join " " 173.55 - (for [n (range (count maxes))] 173.56 - (str "%" 173.57 - (when-not (zero? (maxes n)) 173.58 - (str (when (= (spec n) :l) "-") (maxes n))) 173.59 - "s")))] 173.60 - (join "\n" 173.61 - (for [row rows] 173.62 - (apply format fmt row))))) 173.63 - 173.64 -(defn- rmv-q 173.65 - "Remove ?" 173.66 - [^String s] 173.67 - (if (.endsWith s "?") 173.68 - (.substring s 0 (dec (count s))) 173.69 - s)) 173.70 - 173.71 -(defn print-help [desc cmdmap] 173.72 - (println desc) 173.73 - (println "Options") 173.74 - (println 173.75 - (apply align [:l :l :l] 173.76 - (for [spec (:cmdspec cmdmap) :when (vector? spec)] 173.77 - (let [[argnames [text default]] (split-with symbol? spec) 173.78 - [_ opt q] (re-find #"^(.*[^?])(\??)$" 173.79 - (str (first argnames))) 173.80 - argnames (map (comp rmv-q str) argnames) 173.81 - argnames 173.82 - (join ", " 173.83 - (for [arg argnames] 173.84 - (if (= 1 (count arg)) 173.85 - (str "-" arg) 173.86 - (str "--" arg))))] 173.87 - [(str " " argnames (when (= "" q) " <arg>") " ") 173.88 - text 173.89 - (if-not default 173.90 - "" 173.91 - (str " [default " default "]"))]))))) 173.92 - 173.93 -(defmacro with-command-line 173.94 - "Bind locals to command-line args." 173.95 - [args desc cmdspec & body] 173.96 - (let [locals (vec (for [spec cmdspec] 173.97 - (if (vector? spec) 173.98 - (first spec) 173.99 - spec)))] 173.100 - `(let [{:strs ~locals :as cmdmap#} (make-map ~args '~cmdspec)] 173.101 - (if (cmdmap# "help?") 173.102 - (print-help ~desc cmdmap#) 173.103 - (do ~@body))))) 173.104 - 173.105 -(comment 173.106 - 173.107 -; example of usage: 173.108 - 173.109 -(with-command-line *command-line-args* 173.110 - "tojs -- Compile ClojureScript to JavaScript" 173.111 - [[simple? s? "Runs some simple built-in tests"] 173.112 - [serve "Starts a repl server on the given port" 8081] 173.113 - [mkboot? "Generates a boot.js file"] 173.114 - [verbose? v? "Includes extra fn names and comments in js"] 173.115 - filenames] 173.116 - (binding [*debug-fn-names* verbose? *debug-comments* verbose?] 173.117 - (cond 173.118 - simple? (simple-tests) 173.119 - serve (start-server (Integer/parseInt serve)) 173.120 - mkboot? (mkboot) 173.121 - :else (doseq [filename filenames] 173.122 - (filetojs filename))))) 173.123 - 173.124 -)
174.1 --- a/src/clojure/contrib/complex_numbers.clj Sat Aug 21 06:25:44 2010 -0400 174.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 174.3 @@ -1,293 +0,0 @@ 174.4 -;; Complex numbers 174.5 - 174.6 -;; by Konrad Hinsen 174.7 -;; last updated May 4, 2009 174.8 - 174.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 174.10 -;; and distribution terms for this software are covered by the Eclipse 174.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 174.12 -;; which can be found in the file epl-v10.html at the root of this 174.13 -;; distribution. By using this software in any fashion, you are 174.14 -;; agreeing to be bound by the terms of this license. You must not 174.15 -;; remove this notice, or any other, from this software. 174.16 - 174.17 -(ns 174.18 - ^{:author "Konrad Hinsen" 174.19 - :doc "Complex numbers 174.20 - NOTE: This library is in evolution. Most math functions are 174.21 - not implemented yet."} 174.22 - clojure.contrib.complex-numbers 174.23 - (:refer-clojure :exclude (deftype)) 174.24 - (:use [clojure.contrib.types :only (deftype)] 174.25 - [clojure.contrib.generic :only (root-type)]) 174.26 - (:require [clojure.contrib.generic.arithmetic :as ga] 174.27 - [clojure.contrib.generic.comparison :as gc] 174.28 - [clojure.contrib.generic.math-functions :as gm])) 174.29 - 174.30 -; 174.31 -; Complex numbers are represented as struct maps. The real and imaginary 174.32 -; parts can be of any type for which arithmetic and maths functions 174.33 -; are defined. 174.34 -; 174.35 -(defstruct complex-struct :real :imag) 174.36 - 174.37 -; 174.38 -; The general complex number type 174.39 -; 174.40 -(deftype ::complex complex 174.41 - (fn [real imag] (struct complex-struct real imag)) 174.42 - (fn [c] (vals c))) 174.43 - 174.44 -(derive ::complex root-type) 174.45 - 174.46 -; 174.47 -; A specialized subtype for pure imaginary numbers. Introducing this type 174.48 -; reduces the number of operations by eliminating additions with and 174.49 -; multiplications by zero. 174.50 -; 174.51 -(deftype ::pure-imaginary imaginary 174.52 - (fn [imag] (struct complex-struct 0 imag)) 174.53 - (fn [c] (list (:imag c)))) 174.54 - 174.55 -(derive ::pure-imaginary ::complex) 174.56 - 174.57 -; 174.58 -; Extraction of real and imaginary parts 174.59 -; 174.60 -(def real (accessor complex-struct :real)) 174.61 -(def imag (accessor complex-struct :imag)) 174.62 - 174.63 -; 174.64 -; Equality and zero test 174.65 -; 174.66 -(defmethod gc/zero? ::complex 174.67 - [x] 174.68 - (let [[rx ix] (vals x)] 174.69 - (and (zero? rx) (zero? ix)))) 174.70 - 174.71 -(defmethod gc/= [::complex ::complex] 174.72 - [x y] 174.73 - (let [[rx ix] (vals x) 174.74 - [ry iy] (vals y)] 174.75 - (and (gc/= rx ry) (gc/= ix iy)))) 174.76 - 174.77 -(defmethod gc/= [::pure-imaginary ::pure-imaginary] 174.78 - [x y] 174.79 - (gc/= (imag x) (imag y))) 174.80 - 174.81 -(defmethod gc/= [::complex ::pure-imaginary] 174.82 - [x y] 174.83 - (let [[rx ix] (vals x)] 174.84 - (and (gc/zero? rx) (gc/= ix (imag y))))) 174.85 - 174.86 -(defmethod gc/= [::pure-imaginary ::complex] 174.87 - [x y] 174.88 - (let [[ry iy] (vals y)] 174.89 - (and (gc/zero? ry) (gc/= (imag x) iy)))) 174.90 - 174.91 -(defmethod gc/= [::complex root-type] 174.92 - [x y] 174.93 - (let [[rx ix] (vals x)] 174.94 - (and (gc/zero? ix) (gc/= rx y)))) 174.95 - 174.96 -(defmethod gc/= [root-type ::complex] 174.97 - [x y] 174.98 - (let [[ry iy] (vals y)] 174.99 - (and (gc/zero? iy) (gc/= x ry)))) 174.100 - 174.101 -(defmethod gc/= [::pure-imaginary root-type] 174.102 - [x y] 174.103 - (and (gc/zero? (imag x)) (gc/zero? y))) 174.104 - 174.105 -(defmethod gc/= [root-type ::pure-imaginary] 174.106 - [x y] 174.107 - (and (gc/zero? x) (gc/zero? (imag y)))) 174.108 - 174.109 -; 174.110 -; Addition 174.111 -; 174.112 -(defmethod ga/+ [::complex ::complex] 174.113 - [x y] 174.114 - (let [[rx ix] (vals x) 174.115 - [ry iy] (vals y)] 174.116 - (complex (ga/+ rx ry) (ga/+ ix iy)))) 174.117 - 174.118 -(defmethod ga/+ [::pure-imaginary ::pure-imaginary] 174.119 - [x y] 174.120 - (imaginary (ga/+ (imag x) (imag y)))) 174.121 - 174.122 -(defmethod ga/+ [::complex ::pure-imaginary] 174.123 - [x y] 174.124 - (let [[rx ix] (vals x)] 174.125 - (complex rx (ga/+ ix (imag y))))) 174.126 - 174.127 -(defmethod ga/+ [::pure-imaginary ::complex] 174.128 - [x y] 174.129 - (let [[ry iy] (vals y)] 174.130 - (complex ry (ga/+ (imag x) iy)))) 174.131 - 174.132 -(defmethod ga/+ [::complex root-type] 174.133 - [x y] 174.134 - (let [[rx ix] (vals x)] 174.135 - (complex (ga/+ rx y) ix))) 174.136 - 174.137 -(defmethod ga/+ [root-type ::complex] 174.138 - [x y] 174.139 - (let [[ry iy] (vals y)] 174.140 - (complex (ga/+ x ry) iy))) 174.141 - 174.142 -(defmethod ga/+ [::pure-imaginary root-type] 174.143 - [x y] 174.144 - (complex y (imag x))) 174.145 - 174.146 -(defmethod ga/+ [root-type ::pure-imaginary] 174.147 - [x y] 174.148 - (complex x (imag y))) 174.149 - 174.150 -; 174.151 -; Negation 174.152 -; 174.153 -(defmethod ga/- ::complex 174.154 - [x] 174.155 - (let [[rx ix] (vals x)] 174.156 - (complex (ga/- rx) (ga/- ix)))) 174.157 - 174.158 -(defmethod ga/- ::pure-imaginary 174.159 - [x] 174.160 - (imaginary (ga/- (imag x)))) 174.161 - 174.162 -; 174.163 -; Subtraction is automatically supplied by ga/-, optimized implementations 174.164 -; can be added later... 174.165 -; 174.166 - 174.167 -; 174.168 -; Multiplication 174.169 -; 174.170 -(defmethod ga/* [::complex ::complex] 174.171 - [x y] 174.172 - (let [[rx ix] (vals x) 174.173 - [ry iy] (vals y)] 174.174 - (complex (ga/- (ga/* rx ry) (ga/* ix iy)) 174.175 - (ga/+ (ga/* rx iy) (ga/* ix ry))))) 174.176 - 174.177 -(defmethod ga/* [::pure-imaginary ::pure-imaginary] 174.178 - [x y] 174.179 - (ga/- (ga/* (imag x) (imag y)))) 174.180 - 174.181 -(defmethod ga/* [::complex ::pure-imaginary] 174.182 - [x y] 174.183 - (let [[rx ix] (vals x) 174.184 - iy (imag y)] 174.185 - (complex (ga/- (ga/* ix iy)) 174.186 - (ga/* rx iy)))) 174.187 - 174.188 -(defmethod ga/* [::pure-imaginary ::complex] 174.189 - [x y] 174.190 - (let [ix (imag x) 174.191 - [ry iy] (vals y)] 174.192 - (complex (ga/- (ga/* ix iy)) 174.193 - (ga/* ix ry)))) 174.194 - 174.195 -(defmethod ga/* [::complex root-type] 174.196 - [x y] 174.197 - (let [[rx ix] (vals x)] 174.198 - (complex (ga/* rx y) (ga/* ix y)))) 174.199 - 174.200 -(defmethod ga/* [root-type ::complex] 174.201 - [x y] 174.202 - (let [[ry iy] (vals y)] 174.203 - (complex (ga/* x ry) (ga/* x iy)))) 174.204 - 174.205 -(defmethod ga/* [::pure-imaginary root-type] 174.206 - [x y] 174.207 - (imaginary (ga/* (imag x) y))) 174.208 - 174.209 -(defmethod ga/* [root-type ::pure-imaginary] 174.210 - [x y] 174.211 - (imaginary (ga/* x (imag y)))) 174.212 - 174.213 -; 174.214 -; Inversion 174.215 -; 174.216 -(ga/defmethod* ga / ::complex 174.217 - [x] 174.218 - (let [[rx ix] (vals x) 174.219 - den ((ga/qsym ga /) (ga/+ (ga/* rx rx) (ga/* ix ix)))] 174.220 - (complex (ga/* rx den) (ga/- (ga/* ix den))))) 174.221 - 174.222 -(ga/defmethod* ga / ::pure-imaginary 174.223 - [x] 174.224 - (imaginary (ga/- ((ga/qsym ga /) (imag x))))) 174.225 - 174.226 -; 174.227 -; Division is automatically supplied by ga//, optimized implementations 174.228 -; can be added later... 174.229 -; 174.230 - 174.231 -; 174.232 -; Conjugation 174.233 -; 174.234 -(defmethod gm/conjugate ::complex 174.235 - [x] 174.236 - (let [[r i] (vals x)] 174.237 - (complex r (ga/- i)))) 174.238 - 174.239 -(defmethod gm/conjugate ::pure-imaginary 174.240 - [x] 174.241 - (imaginary (ga/- (imag x)))) 174.242 - 174.243 -; 174.244 -; Absolute value 174.245 -; 174.246 -(defmethod gm/abs ::complex 174.247 - [x] 174.248 - (let [[r i] (vals x)] 174.249 - (gm/sqrt (ga/+ (ga/* r r) (ga/* i i))))) 174.250 - 174.251 -(defmethod gm/abs ::pure-imaginary 174.252 - [x] 174.253 - (gm/abs (imag x))) 174.254 - 174.255 -; 174.256 -; Square root 174.257 -; 174.258 -(let [one-half (/ 1 2) 174.259 - one-eighth (/ 1 8)] 174.260 - (defmethod gm/sqrt ::complex 174.261 - [x] 174.262 - (let [[r i] (vals x)] 174.263 - (if (and (gc/zero? r) (gc/zero? i)) 174.264 - 0 174.265 - (let [; The basic formula would say 174.266 - ; abs (gm/sqrt (ga/+ (ga/* r r) (ga/* i i))) 174.267 - ; p (gm/sqrt (ga/* one-half (ga/+ abs r))) 174.268 - ; but the slightly more complicated one below 174.269 - ; avoids overflow for large r or i. 174.270 - ar (gm/abs r) 174.271 - ai (gm/abs i) 174.272 - r8 (ga/* one-eighth ar) 174.273 - i8 (ga/* one-eighth ai) 174.274 - abs (gm/sqrt (ga/+ (ga/* r8 r8) (ga/* i8 i8))) 174.275 - p (ga/* 2 (gm/sqrt (ga/+ abs r8))) 174.276 - q ((ga/qsym ga /) ai (ga/* 2 p)) 174.277 - s (gm/sgn i)] 174.278 - (if (gc/< r 0) 174.279 - (complex q (ga/* s p)) 174.280 - (complex p (ga/* s q)))))))) 174.281 - 174.282 -; 174.283 -; Exponential function 174.284 -; 174.285 -(defmethod gm/exp ::complex 174.286 - [x] 174.287 - (let [[r i] (vals x) 174.288 - exp-r (gm/exp r) 174.289 - cos-i (gm/cos i) 174.290 - sin-i (gm/sin i)] 174.291 - (complex (ga/* exp-r cos-i) (ga/* exp-r sin-i)))) 174.292 - 174.293 -(defmethod gm/exp ::pure-imaginary 174.294 - [x] 174.295 - (let [i (imag x)] 174.296 - (complex (gm/cos i) (gm/sin i))))
175.1 --- a/src/clojure/contrib/cond.clj Sat Aug 21 06:25:44 2010 -0400 175.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 175.3 @@ -1,34 +0,0 @@ 175.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 175.5 -;; distribution terms for this software are covered by the Eclipse Public 175.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 175.7 -;; be found in the file epl-v10.html at the root of this distribution. By 175.8 -;; using this software in any fashion, you are agreeing to be bound by the 175.9 -;; terms of this license. You must not remove this notice, or any other, 175.10 -;; from this software. 175.11 -;; 175.12 -;; File: cond.clj 175.13 -;; 175.14 -;; scgilardi (gmail) 175.15 -;; 2 October 2008 175.16 - 175.17 -(ns ^{:author "Stephen C. Gilardi" 175.18 - :doc "Extensions to the basic cond function."} 175.19 - clojure.contrib.cond) 175.20 - 175.21 -(defmacro cond-let 175.22 - "Takes a binding-form and a set of test/expr pairs. Evaluates each test 175.23 - one at a time. If a test returns logical true, cond-let evaluates and 175.24 - returns expr with binding-form bound to the value of test and doesn't 175.25 - evaluate any of the other tests or exprs. To provide a default value 175.26 - either provide a literal that evaluates to logical true and is 175.27 - binding-compatible with binding-form, or use :else as the test and don't 175.28 - refer to any parts of binding-form in the expr. (cond-let binding-form) 175.29 - returns nil." 175.30 - [bindings & clauses] 175.31 - (let [binding (first bindings)] 175.32 - (when-let [[test expr & more] clauses] 175.33 - (if (= test :else) 175.34 - expr 175.35 - `(if-let [~binding ~test] 175.36 - ~expr 175.37 - (cond-let ~bindings ~@more))))))
176.1 --- a/src/clojure/contrib/condition.clj Sat Aug 21 06:25:44 2010 -0400 176.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 176.3 @@ -1,147 +0,0 @@ 176.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 176.5 -;; distribution terms for this software are covered by the Eclipse Public 176.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 176.7 -;; be found in the file epl-v10.html at the root of this distribution. By 176.8 -;; using this software in any fashion, you are agreeing to be bound by the 176.9 -;; terms of this license. You must not remove this notice, or any other, 176.10 -;; from this software. 176.11 -;; 176.12 -;; condition.clj 176.13 -;; 176.14 -;; scgilardi (gmail) 176.15 -;; Created 09 June 2009 176.16 - 176.17 -(ns ^{:author "Stephen C. Gilardi" 176.18 - :doc "Flexible raising and handling of conditions: 176.19 - 176.20 -Functions: 176.21 - 176.22 - raise: raises a condition 176.23 - handler-case: dispatches raised conditions to appropriate handlers 176.24 - print-stack-trace: prints abbreviated or full condition stack traces 176.25 - 176.26 -Data: 176.27 - 176.28 - A condition is a map containing values for these keys: 176.29 - 176.30 - - :type, a condition type specifier, typically a keyword 176.31 - - :stack-trace, a stack trace to the site of the raise 176.32 - - :message, a human-readable message (optional) 176.33 - - :cause, a wrapped exception or condition (optional) 176.34 - - other keys given as arguments to raise (optional) 176.35 - 176.36 -Note: requires AOT compilation. 176.37 - 176.38 -Based on an idea from Chouser: 176.39 -http://groups.google.com/group/clojure/browse_frm/thread/da1285c538f22bb5"} 176.40 - clojure.contrib.condition 176.41 - (:require clojure.contrib.condition.Condition) 176.42 - (:import clojure.contrib.condition.Condition 176.43 - clojure.lang.IPersistentMap) 176.44 - (:use (clojure.contrib 176.45 - [def :only (defvar)] 176.46 - [seq :only (separate)]))) 176.47 - 176.48 -(defvar *condition* 176.49 - "While a handler is running, bound to the condition being handled") 176.50 - 176.51 -(defvar *selector* 176.52 - "While a handler is running, bound to the selector returned by the 176.53 - handler-case dispatch-fn for *condition*") 176.54 - 176.55 -(defvar *condition-object* 176.56 - "While a handler is running, bound to the Condition object whose metadata 176.57 - is the condition") 176.58 - 176.59 -(defvar *full-stack-traces* false 176.60 - "Bind to true to include clojure.{core,lang,main} frames in stack 176.61 - traces") 176.62 - 176.63 -(defmacro raise 176.64 - "Raises a condition. With no arguments, re-raises the current condition. 176.65 - With one argument (a map), raises the argument. With two or more 176.66 - arguments, raises a map with keys and values from the arguments." 176.67 - ([] 176.68 - `(throw *condition-object*)) 176.69 - ([m] 176.70 - `(throw (Condition. ~m))) 176.71 - ([key val & keyvals] 176.72 - `(raise (hash-map ~key ~val ~@keyvals)))) 176.73 - 176.74 -(defmacro handler-case 176.75 - "Executes body in a context where raised conditions can be handled. 176.76 - 176.77 - dispatch-fn accepts a raised condition (a map) and returns a selector 176.78 - used to choose a handler. Commonly, dispatch-fn will be :type to dispatch 176.79 - on the condition's :type value. 176.80 - 176.81 - Handlers are forms within body: 176.82 - 176.83 - (handle key 176.84 - ...) 176.85 - 176.86 - If a condition is raised, executes the body of the first handler whose 176.87 - key satisfies (isa? selector key). If no handlers match, re-raises the 176.88 - condition. 176.89 - 176.90 - While a handler is running, *condition* is bound to the condition being 176.91 - handled and *selector* is bound to to the value returned by dispatch-fn 176.92 - that matched the handler's key." 176.93 - [dispatch-fn & body] 176.94 - (let [[handlers code] 176.95 - (separate #(and (list? %) (= 'handle (first %))) body)] 176.96 - `(try 176.97 - ~@code 176.98 - (catch Condition c# 176.99 - (binding [*condition-object* c# 176.100 - *condition* (meta c#) 176.101 - *selector* (~dispatch-fn (meta c#))] 176.102 - (cond 176.103 - ~@(mapcat 176.104 - (fn [[_ key & body]] 176.105 - `[(isa? *selector* ~key) (do ~@body)]) 176.106 - handlers) 176.107 - :else (raise))))))) 176.108 - 176.109 -(defmulti stack-trace-info 176.110 - "Returns header, stack-trace, and cause info from conditions and 176.111 - Throwables" 176.112 - class) 176.113 - 176.114 -(defmethod stack-trace-info IPersistentMap 176.115 - [condition] 176.116 - [(format "condition: %s, %s" (:type condition) 176.117 - (dissoc condition :type :stack-trace :cause)) 176.118 - (:stack-trace condition) 176.119 - (:cause condition)]) 176.120 - 176.121 -(defmethod stack-trace-info Condition 176.122 - [condition] 176.123 - (stack-trace-info (meta condition))) 176.124 - 176.125 -(defmethod stack-trace-info Throwable 176.126 - [throwable] 176.127 - [(str throwable) 176.128 - (.getStackTrace throwable) 176.129 - (.getCause throwable)]) 176.130 - 176.131 -(defn print-stack-trace 176.132 - "Prints a stack trace for a condition or Throwable. Skips frames for 176.133 - classes in clojure.{core,lang,main} unless the *full-stack-traces* is 176.134 - bound to logical true" 176.135 - [x] 176.136 - (let [[header frames cause] (stack-trace-info x)] 176.137 - (printf "%s\n" header) 176.138 - (doseq [frame frames] 176.139 - (let [classname (.getClassName frame)] 176.140 - (if (or *full-stack-traces* 176.141 - (not (re-matches 176.142 - #"clojure.(?:core|lang|main).*" classname))) 176.143 - (printf " at %s/%s(%s:%s)\n" 176.144 - classname 176.145 - (.getMethodName frame) 176.146 - (.getFileName frame) 176.147 - (.getLineNumber frame))))) 176.148 - (when cause 176.149 - (printf "caused by: ") 176.150 - (recur cause))))
177.1 --- a/src/clojure/contrib/condition/Condition.clj Sat Aug 21 06:25:44 2010 -0400 177.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 177.3 @@ -1,43 +0,0 @@ 177.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 177.5 -;; distribution terms for this software are covered by the Eclipse Public 177.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 177.7 -;; be found in the file epl-v10.html at the root of this distribution. By 177.8 -;; using this software in any fashion, you are agreeing to be bound by the 177.9 -;; terms of this license. You must not remove this notice, or any other, 177.10 -;; from this software. 177.11 -;; 177.12 -;; Condition.clj 177.13 -;; 177.14 -;; Used by clojure.contrib.condition to implement a "Throwable map" 177.15 -;; 177.16 -;; scgilardi (gmail) 177.17 -;; Created 09 June 2009 177.18 - 177.19 -(ns clojure.contrib.condition.Condition 177.20 - (:gen-class :extends Throwable 177.21 - :implements [clojure.lang.IMeta] 177.22 - :state state 177.23 - :init init 177.24 - :post-init post-init 177.25 - :constructors {[clojure.lang.IPersistentMap] 177.26 - [String Throwable]})) 177.27 - 177.28 -(defn -init 177.29 - "Constructs a Condition object with condition (a map) as its 177.30 - metadata. Also initializes the superclass with the values at :message 177.31 - and :cause, if any, so they are also available via .getMessage and 177.32 - .getCause." 177.33 - [condition] 177.34 - [[(:message condition) (:cause condition)] (atom condition)]) 177.35 - 177.36 -(defn -post-init 177.37 - "Adds :stack-trace to the condition. Drops the bottom 3 frames because 177.38 - they are always the same: implementation details of Condition and raise." 177.39 - [this condition] 177.40 - (swap! (.state this) assoc 177.41 - :stack-trace (into-array (drop 3 (.getStackTrace this))))) 177.42 - 177.43 -(defn -meta 177.44 - "Returns this object's metadata, the condition" 177.45 - [this] 177.46 - @(.state this))
178.1 --- a/src/clojure/contrib/core.clj Sat Aug 21 06:25:44 2010 -0400 178.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 178.3 @@ -1,89 +0,0 @@ 178.4 -; Copyright (c) Laurent Petit and others, March 2009. All rights reserved. 178.5 - 178.6 -; The use and distribution terms for this software are covered by the 178.7 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 178.8 -; which can be found in the file epl-v10.html at the root of this 178.9 -; distribution. 178.10 -; By using this software in any fashion, you are agreeing to be bound by 178.11 -; the terms of this license. 178.12 -; You must not remove this notice, or any other, from this software. 178.13 - 178.14 -;; functions/macros variants of the ones that can be found in clojure.core 178.15 - 178.16 -;; note to other contrib members: feel free to add to this lib 178.17 - 178.18 -(ns 178.19 - ^{:author "Laurent Petit (and others)" 178.20 - :doc "Functions/macros variants of the ones that can be found in clojure.core 178.21 - (note to other contrib members: feel free to add to this lib)"} 178.22 - clojure.contrib.core 178.23 - (:use clojure.contrib.def)) 178.24 - 178.25 -(defmacro- defnilsafe [docstring non-safe-name nil-safe-name] 178.26 - `(defmacro ~nil-safe-name ~docstring 178.27 - {:arglists '([~'x ~'form] [~'x ~'form ~'& ~'forms])} 178.28 - ([x# form#] 178.29 - `(let [~'i# ~x#] (when-not (nil? ~'i#) (~'~non-safe-name ~'i# ~form#)))) 178.30 - ([x# form# & more#] 178.31 - `(~'~nil-safe-name (~'~nil-safe-name ~x# ~form#) ~@more#)))) 178.32 - 178.33 -(defnilsafe 178.34 - "Same as clojure.core/-> but returns nil as soon as the threaded value is nil itself (thus short-circuiting any pending computation). 178.35 - Examples : 178.36 - (-?> \"foo\" .toUpperCase (.substring 1)) returns \"OO\" 178.37 - (-?> nil .toUpperCase (.substring 1)) returns nil 178.38 - " 178.39 - -> -?>) 178.40 - 178.41 -(defnilsafe 178.42 - "Same as clojure.core/.. but returns nil as soon as the threaded value is nil itself (thus short-circuiting any pending computation). 178.43 - Examples : 178.44 - (.?. \"foo\" .toUpperCase (.substring 1)) returns \"OO\" 178.45 - (.?. nil .toUpperCase (.substring 1)) returns nil 178.46 - " 178.47 - .. .?.) 178.48 - 178.49 -(defnilsafe 178.50 - "Same as clojure.core/->> but returns nil as soon as the threaded value is nil itself (thus short-circuiting any pending computation). 178.51 - Examples : 178.52 - (-?>> (range 5) (map inc)) returns (1 2 3 4 5) 178.53 - (-?>> [] seq (map inc)) returns nil 178.54 - " 178.55 - ->> -?>>) 178.56 - 178.57 -;; ---------------------------------------------------------------------- 178.58 -;; scgilardi at gmail 178.59 - 178.60 -(defn dissoc-in 178.61 - "Dissociates an entry from a nested associative structure returning a new 178.62 - nested structure. keys is a sequence of keys. Any empty maps that result 178.63 - will not be present in the new structure." 178.64 - [m [k & ks :as keys]] 178.65 - (if ks 178.66 - (if-let [nextmap (get m k)] 178.67 - (let [newmap (dissoc-in nextmap ks)] 178.68 - (if (seq newmap) 178.69 - (assoc m k newmap) 178.70 - (dissoc m k))) 178.71 - m) 178.72 - (dissoc m k))) 178.73 - 178.74 -(defn new-by-name 178.75 - "Constructs a Java object whose class is specified by a String." 178.76 - [class-name & args] 178.77 - (clojure.lang.Reflector/invokeConstructor 178.78 - (clojure.lang.RT/classForName class-name) 178.79 - (into-array Object args))) 178.80 - 178.81 -(defn seqable? 178.82 - "Returns true if (seq x) will succeed, false otherwise." 178.83 - [x] 178.84 - (or (seq? x) 178.85 - (instance? clojure.lang.Seqable x) 178.86 - (nil? x) 178.87 - (instance? Iterable x) 178.88 - (-> x .getClass .isArray) 178.89 - (string? x) 178.90 - (instance? java.util.Map x))) 178.91 - 178.92 -;; ----------------------------------------------------------------------
179.1 --- a/src/clojure/contrib/dataflow.clj Sat Aug 21 06:25:44 2010 -0400 179.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 179.3 @@ -1,509 +0,0 @@ 179.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 179.5 -;; distribution terms for this software are covered by the Eclipse Public 179.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 179.7 -;; be found in the file epl-v10.html at the root of this distribution. By 179.8 -;; using this software in any fashion, you are agreeing to be bound by the 179.9 -;; terms of this license. You must not remove this notice, or any other, 179.10 -;; from this software. 179.11 -;; 179.12 -;; dataflow.clj 179.13 -;; 179.14 -;; A Library to Support a Dataflow Model of State 179.15 -;; 179.16 -;; straszheimjeffrey (gmail) 179.17 -;; Created 10 March 2009 179.18 - 179.19 - 179.20 -(ns 179.21 - ^{:author "Jeffrey Straszheim", 179.22 - :doc "A library to support a dataflow model of state"} 179.23 - clojure.contrib.dataflow 179.24 - (:use [clojure.set :only (union intersection difference)]) 179.25 - (:use [clojure.contrib.graph :only (directed-graph 179.26 - reverse-graph 179.27 - dependency-list 179.28 - get-neighbors)]) 179.29 - (:use [clojure.walk :only (postwalk)]) 179.30 - (:use [clojure.contrib.except :only (throwf)]) 179.31 - (:import java.io.Writer)) 179.32 - 179.33 - 179.34 -;;; Chief Data Structures 179.35 - 179.36 - 179.37 -;; Source Cell 179.38 - 179.39 -; The data of a source cell is directly set by a calling function. It 179.40 -; never depends on other cells. 179.41 - 179.42 -(defstruct source-cell 179.43 - :name ; The name, a symbol 179.44 - :value ; Its value, a Ref 179.45 - :cell-type) ; Should be ::source-cell 179.46 - 179.47 -;; Cell 179.48 - 179.49 -; A standard cell that computes its value from other cells. 179.50 - 179.51 -(defstruct standard-cell 179.52 - :name ; The name, a symbol 179.53 - :value ; Its value, a Ref 179.54 - :dependents ; The names of cells on which this depends, a collection 179.55 - :fun ; A closure that computes the value, given an environment 179.56 - :display ; The original expression for display 179.57 - :cell-type) ; Should be ::cell 179.58 - 179.59 -(derive ::cell ::dependent-cell) ; A cell that has a dependents field 179.60 - 179.61 -;; Validator 179.62 - 179.63 -; A cell that has no value, but can throw an exception when run 179.64 - 179.65 -(defstruct validator-cell 179.66 - :name ; Always ::validator 179.67 - :dependents ; The names of cells on which this depends, a collection 179.68 - :fun ; A clojure that can throw an exception 179.69 - :display ; The original exprssion for display 179.70 - :cell-type) ; Should be ::validator-cell 179.71 - 179.72 -(derive ::validator-cell ::dependent-cell) 179.73 - 179.74 - 179.75 -;; A sentinal value 179.76 - 179.77 -(def *empty-value* (java.lang.Object.)) 179.78 - 179.79 - 179.80 -;; Dataflow 179.81 - 179.82 -; A collection of cells and dependency information 179.83 - 179.84 -(defstruct dataflow 179.85 - :cells ; A set of all cells 179.86 - :cells-map ; A map of cell names (symbols) to collections of cells 179.87 - :fore-graph ; The inverse of the dependency graph, nodes are cells 179.88 - :topological) ; A vector of sets of independent nodes -- orders the computation 179.89 - 179.90 - 179.91 -;;; Environment Access 179.92 - 179.93 -(defn get-cells 179.94 - "Get all the cells named by name" 179.95 - [df name] 179.96 - ((:cells-map @df) name)) 179.97 - 179.98 -(defn get-cell 179.99 - "Get the single cell named by name" 179.100 - [df name] 179.101 - (let [cells (get-cells df name)] 179.102 - (cond 179.103 - (= (count cells) 1) (first cells) 179.104 - (> (count cells) 1) (throwf Exception "Cell %s has multiple instances" name) 179.105 - :otherwise (throwf Exception "Cell %s is undefined" name)))) 179.106 - 179.107 -(defn source-cell? 179.108 - "Is this cell a source cell?" 179.109 - [cell] 179.110 - (isa? (:cell-type cell) ::source-cell)) 179.111 - 179.112 -(defn get-source-cells 179.113 - "Returns a collection of source cells from the dataflow" 179.114 - [df] 179.115 - (for [cell (:cells @df) 179.116 - :when (source-cell? cell)] 179.117 - cell)) 179.118 - 179.119 -(defn get-value 179.120 - "Gets a value from the df matching the passed symbol. 179.121 - Signals an error if the name is not present, or if it not a single 179.122 - value." 179.123 - [df name] 179.124 - (let [cell (get-cell df name) 179.125 - result @(:value cell)] 179.126 - (do (when (= *empty-value* result) 179.127 - (throwf Exception "Cell named %s empty" name)) 179.128 - result))) 179.129 - 179.130 -(defn get-values 179.131 - "Gets a collection of values from the df by name" 179.132 - [df name] 179.133 - (let [cells (get-cells df name) 179.134 - results (map #(-> % :value deref) cells)] 179.135 - (do 179.136 - (when (some #(= % *empty-value*) results) 179.137 - (throwf Exception "At least one empty cell named %s found" name)) 179.138 - results))) 179.139 - 179.140 -(defn get-old-value 179.141 - "Looks up an old value" 179.142 - [df env name] 179.143 - (if (contains? env name) 179.144 - (env name) 179.145 - (get-value df name))) 179.146 - 179.147 -(defn get-value-from-cell 179.148 - "Given a cell, get its value" 179.149 - [cell] 179.150 - (-> cell :value deref)) 179.151 - 179.152 -;;; Build Dataflow Structure 179.153 - 179.154 -(defn- build-cells-map 179.155 - "Given a collection of cells, build a name->cells-collection map 179.156 - from it." 179.157 - [cs] 179.158 - (let [step (fn [m c] 179.159 - (let [n (:name c) 179.160 - o (get m n #{}) 179.161 - s (conj o c)] 179.162 - (assoc m n s)))] 179.163 - (reduce step {} cs))) 179.164 - 179.165 -(defn- build-back-graph 179.166 - "Builds the backward dependency graph from the cells map. Each 179.167 - node of the graph is a cell." 179.168 - [cells cells-map] 179.169 - (let [step (fn [n] 179.170 - (apply union (for [dep-name (:dependents n)] 179.171 - (cells-map dep-name)))) 179.172 - neighbors (zipmap cells (map step cells))] 179.173 - (struct-map directed-graph 179.174 - :nodes cells 179.175 - :neighbors neighbors))) 179.176 - 179.177 -(defn- build-dataflow* 179.178 - "Builds the dataflow structure" 179.179 - [cs] 179.180 - (let [cells (set cs) 179.181 - cells-map (build-cells-map cs) 179.182 - back-graph (build-back-graph cells cells-map) 179.183 - fore-graph (reverse-graph back-graph)] 179.184 - (struct-map dataflow 179.185 - :cells cells 179.186 - :cells-map cells-map 179.187 - :fore-graph fore-graph 179.188 - :topological (dependency-list back-graph)))) 179.189 - 179.190 -(def initialize) 179.191 - 179.192 -(defn build-dataflow 179.193 - "Given a collection of cells, build and return a dataflow object" 179.194 - [cs] 179.195 - (dosync 179.196 - (let [df (ref (build-dataflow* cs))] 179.197 - (initialize df) 179.198 - df))) 179.199 - 179.200 - 179.201 -;;; Displaying a dataflow 179.202 - 179.203 -(defn print-dataflow 179.204 - "Prints a dataflow, one cell per line" 179.205 - [df] 179.206 - (println) 179.207 - (let [f (fn [cell] (-> cell :name str))] 179.208 - (doseq [cell (sort-by f (:cells @df))] 179.209 - (prn cell)))) 179.210 - 179.211 - 179.212 -;;; Modifying a Dataflow 179.213 - 179.214 -(defn add-cells 179.215 - "Given a collection of cells, add them to the dataflow." 179.216 - [df cells] 179.217 - (dosync 179.218 - (let [new-cells (union (set cells) (:cells @df))] 179.219 - (ref-set df (build-dataflow* new-cells)) 179.220 - (initialize df)))) 179.221 - 179.222 -(defn remove-cells 179.223 - "Given a collection of cells, remove them from the dataflow." 179.224 - [df cells] 179.225 - (dosync 179.226 - (let [new-cells (difference (:cells @df) (set cells))] 179.227 - (ref-set df (build-dataflow* new-cells)) 179.228 - (initialize df)))) 179.229 - 179.230 - 179.231 -;;; Cell building 179.232 - 179.233 -(def *meta* {:type ::dataflow-cell}) 179.234 - 179.235 -(defn build-source-cell 179.236 - "Builds a source cell" 179.237 - [name init] 179.238 - (with-meta (struct source-cell name (ref init) ::source-cell) 179.239 - *meta*)) 179.240 - 179.241 -(defn- is-col-var? 179.242 - [symb] 179.243 - (let [name (name symb)] 179.244 - (and (= \? (first name)) 179.245 - (= \* (second name))))) 179.246 - 179.247 -(defn- is-old-var? 179.248 - [symb] 179.249 - (let [name (name symb)] 179.250 - (and (= \? (first name)) 179.251 - (= \- (second name))))) 179.252 - 179.253 -(defn- is-var? 179.254 - [symb] 179.255 - (let [name (name symb)] 179.256 - (and (= \? (first name)) 179.257 - (-> symb is-col-var? not) 179.258 - (-> symb is-old-var? not)))) 179.259 - 179.260 -(defn- cell-name 179.261 - [symb] 179.262 - `(quote ~(cond (is-var? symb) (-> symb name (.substring 1) symbol) 179.263 - (or (is-col-var? symb) 179.264 - (is-old-var? symb)) (-> symb name (.substring 2) symbol)))) 179.265 - 179.266 -(defn- replace-symbol 179.267 - "Walk the from replacing the ?X forms with the needed calls" 179.268 - [dfs ov form] 179.269 - (cond 179.270 - (-> form symbol? not) form 179.271 - (is-var? form) `(get-value ~dfs ~(cell-name form)) 179.272 - (is-col-var? form) `(get-values ~dfs ~(cell-name form)) 179.273 - (is-old-var? form) `(get-old-value ~dfs ~ov ~(cell-name form)) 179.274 - :otherwise form)) 179.275 - 179.276 -(defn- build-fun 179.277 - "Build the closure needed to compute a cell" 179.278 - [form] 179.279 - (let [dfs (gensym "df_") 179.280 - ov (gensym "old_")] 179.281 - `(fn [~dfs ~ov] ~(postwalk (partial replace-symbol dfs ov) form)))) 179.282 - 179.283 -(defn- get-deps 179.284 - "Get the names of the dependent cells" 179.285 - [form] 179.286 - (let [step (fn [f] 179.287 - (cond 179.288 - (coll? f) (apply union f) 179.289 - (-> f symbol? not) nil 179.290 - (is-var? f) #{(cell-name f)} 179.291 - (is-col-var? f) #{(cell-name f)} 179.292 - (is-old-var? f) #{(cell-name f)} 179.293 - :otherwise nil))] 179.294 - (postwalk step form))) 179.295 - 179.296 -(defn build-standard-cell 179.297 - "Builds a standard cell" 179.298 - [name deps fun expr] 179.299 - (with-meta (struct standard-cell name (ref *empty-value*) deps fun expr ::cell) 179.300 - *meta*)) 179.301 - 179.302 -(defn build-validator-cell 179.303 - "Builds a validator cell" 179.304 - [deps fun expr] 179.305 - (with-meta (struct validator-cell ::validator deps fun expr ::validator-cell) 179.306 - *meta*)) 179.307 - 179.308 -(defmacro cell 179.309 - "Build a standard cell, like this: 179.310 - 179.311 - (cell fred 179.312 - (* ?mary ?joe)) 179.313 - 179.314 - Which creates a cell named fred that is the product of a cell mary and cell joe 179.315 - 179.316 - Or: 179.317 - 179.318 - (cell joe 179.319 - (apply * ?*sally)) 179.320 - 179.321 - Which creates a cell that applies * to the collection of all cells named sally 179.322 - 179.323 - Or: 179.324 - 179.325 - (cell :source fred 0) 179.326 - 179.327 - Which builds a source cell fred with initial value 0 179.328 - 179.329 - Or: 179.330 - 179.331 - (cell :validator (when (< ?fred ?sally) 179.332 - (throwf \"%s must be greater than %s\" ?fred ?sally)) 179.333 - 179.334 - Which will perform the validation" 179.335 - [type & data] 179.336 - (cond 179.337 - (symbol? type) (let [name type ; No type for standard cell 179.338 - expr (first data) ; we ignore extra data! 179.339 - deps (get-deps expr) 179.340 - fun (build-fun expr)] 179.341 - `(build-standard-cell '~name ~deps ~fun '~expr)) 179.342 - (= type :source) (let [[name init] data] 179.343 - `(build-source-cell '~name ~init)) 179.344 - (= type :validator) (let [[expr] data 179.345 - deps (get-deps expr) 179.346 - fun (build-fun expr)] 179.347 - `(build-validator-cell ~deps ~fun '~expr)))) 179.348 - 179.349 - 179.350 -;;; Cell Display 179.351 - 179.352 -(defmulti display-cell 179.353 - "A 'readable' form of the cell" 179.354 - :cell-type) 179.355 - 179.356 -(defmethod display-cell ::source-cell 179.357 - [cell] 179.358 - (list 'cell :source (:name cell) (-> cell :value deref))) 179.359 - 179.360 -(defmethod display-cell ::cell 179.361 - [cell] 179.362 - (list 'cell (:name cell) (:display cell) (-> cell :value deref))) 179.363 - 179.364 -(defmethod display-cell ::validator-cell 179.365 - [cell] 179.366 - (list 'cell :validator (:display cell))) 179.367 - 179.368 -(defmethod print-method ::dataflow-cell 179.369 - [f ^Writer w] 179.370 - (binding [*out* w] 179.371 - (pr (display-cell f)))) 179.372 - 179.373 - 179.374 -;;; Evaluation 179.375 - 179.376 -(defmulti eval-cell 179.377 - "Evaluate a dataflow cell. Return [changed, old val]" 179.378 - (fn [df data old cell] (:cell-type cell))) 179.379 - 179.380 -(defmethod eval-cell ::source-cell 179.381 - [df data old cell] 179.382 - (let [name (:name cell) 179.383 - val (:value cell) 179.384 - ov @val] 179.385 - (if (contains? data name) 179.386 - (let [new-val (data name)] 179.387 - (if (not= ov new-val) 179.388 - (do (ref-set val new-val) 179.389 - [true ov]) 179.390 - [false ov])) 179.391 - [false ov]))) 179.392 - 179.393 -(defmethod eval-cell ::cell 179.394 - [df data old cell] 179.395 - (let [val (:value cell) 179.396 - old-val @val 179.397 - new-val ((:fun cell) df old)] 179.398 - (if (not= old-val new-val) 179.399 - (do (ref-set val new-val) 179.400 - [true old-val]) 179.401 - [false old-val]))) 179.402 - 179.403 -(defmethod eval-cell ::validator-cell 179.404 - [df data old cell] 179.405 - (do ((:fun cell) df old) 179.406 - [false nil])) 179.407 - 179.408 -(defn- perform-flow 179.409 - "Evaluate the needed cells (a set) from the given dataflow. Data is 179.410 - a name-value mapping of new values for the source cells" 179.411 - [df data needed] 179.412 - (loop [needed needed 179.413 - tops (:topological @df) 179.414 - old {}] 179.415 - (let [now (first tops) ; Now is a set of nodes 179.416 - new-tops (next tops)] 179.417 - (when (and (-> needed empty? not) 179.418 - (-> now empty? not)) 179.419 - (let [step (fn [[needed old] cell] 179.420 - (let [[changed ov] (try 179.421 - (eval-cell df data old cell) 179.422 - (catch Exception e 179.423 - (throw (Exception. (str cell) e)))) 179.424 - nn (disj needed cell)] 179.425 - (if changed 179.426 - [(union nn (get-neighbors (:fore-graph @df) cell)) 179.427 - (assoc old (:name cell) ov)] 179.428 - [nn old]))) 179.429 - [new-needed new-old] (reduce step 179.430 - [needed old] 179.431 - (intersection now needed))] 179.432 - (recur new-needed new-tops new-old)))))) 179.433 - 179.434 -(defn- validate-update 179.435 - "Ensure that all the updated cells are source cells" 179.436 - [df names] 179.437 - (let [scns (set (map :name (get-source-cells df)))] 179.438 - (doseq [name names] 179.439 - (when (-> name scns not) 179.440 - (throwf Exception "Cell %n is not a source cell" name))))) 179.441 - 179.442 -(defn update-values 179.443 - "Given a dataflow, and a map of name-value pairs, update the 179.444 - dataflow by binding the new values. Each name must be of a source 179.445 - cell" 179.446 - [df data] 179.447 - (dosync 179.448 - (validate-update df (keys data)) 179.449 - (let [needed (apply union (for [name (keys data)] 179.450 - (set ((:cells-map @df) name))))] 179.451 - (perform-flow df data needed)))) 179.452 - 179.453 -(defn- initialize 179.454 - "Apply all the current source cell values. Useful for a new 179.455 - dataflow, or one that has been updated with new cells" 179.456 - [df] 179.457 - (let [needed (:cells @df) 179.458 - fg (:fore-graph @df)] 179.459 - (perform-flow df {} needed))) 179.460 - 179.461 - 179.462 -;;; Watchers 179.463 - 179.464 -(defn add-cell-watcher 179.465 - "Adds a watcher to a cell to respond to changes of value. The is a 179.466 - function of 4 values: a key, the cell, its old value, its new 179.467 - value. This is implemented using Clojure's add-watch to the 179.468 - underlying ref, and shared its sematics" 179.469 - [cell key fun] 179.470 - (let [val (:value cell)] 179.471 - (add-watch val key (fn [key _ old-v new-v] 179.472 - (fun key cell old-v new-v))))) 179.473 - 179.474 - 179.475 -(comment 179.476 - 179.477 - (def df 179.478 - (build-dataflow 179.479 - [(cell :source fred 1) 179.480 - (cell :source mary 0) 179.481 - (cell greg (+ ?fred ?mary)) 179.482 - (cell joan (+ ?fred ?mary)) 179.483 - (cell joan (* ?fred ?mary)) 179.484 - (cell sally (apply + ?*joan)) 179.485 - (cell :validator (when (number? ?-greg) 179.486 - (when (<= ?greg ?-greg) 179.487 - (throwf Exception "Non monotonic"))))])) 179.488 - 179.489 - (do (println) 179.490 - (print-dataflow df)) 179.491 - 179.492 - (add-cell-watcher (get-cell df 'sally) 179.493 - nil 179.494 - (fn [key cell o n] 179.495 - (printf "sally changed from %s to %s\n" o n))) 179.496 - 179.497 - (update-values df {'fred 1 'mary 1}) 179.498 - (update-values df {'fred 5 'mary 1}) 179.499 - (update-values df {'fred 0 'mary 0}) 179.500 - 179.501 - (get-value df 'fred) 179.502 - (get-values df 'joan) 179.503 - (get-value df 'sally) 179.504 - (get-value df 'greg) 179.505 - 179.506 - (use :reload 'clojure.contrib.dataflow) 179.507 - (use 'clojure.stacktrace) (e) 179.508 - (use 'clojure.contrib.trace) 179.509 -) 179.510 - 179.511 - 179.512 -;; End of file
180.1 --- a/src/clojure/contrib/datalog.clj Sat Aug 21 06:25:44 2010 -0400 180.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 180.3 @@ -1,64 +0,0 @@ 180.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 180.5 -;; distribution terms for this software are covered by the Eclipse Public 180.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 180.7 -;; be found in the file epl-v10.html at the root of this distribution. By 180.8 -;; using this software in any fashion, you are agreeing to be bound by the 180.9 -;; terms of this license. You must not remove this notice, or any other, 180.10 -;; from this software. 180.11 -;; 180.12 -;; datalog.clj 180.13 -;; 180.14 -;; A Clojure implementation of Datalog 180.15 -;; 180.16 -;; straszheimjeffrey (gmail) 180.17 -;; Created 2 March 2009 180.18 - 180.19 - 180.20 -;;; Please see the example.clj file in the datalog folder 180.21 - 180.22 - 180.23 -(ns 180.24 - ^{:author "Jeffrey Straszheim", 180.25 - :doc "A Clojure implementation of Datalog"} 180.26 - clojure.contrib.datalog 180.27 - (:use clojure.contrib.datalog.rules 180.28 - clojure.contrib.datalog.softstrat 180.29 - clojure.contrib.datalog.database) 180.30 - (:use [clojure.set :only (intersection)] 180.31 - [clojure.contrib.except :only (throwf)])) 180.32 - 180.33 -(defstruct work-plan 180.34 - :work-plan ; The underlying structure 180.35 - :rules ; The original rules 180.36 - :query ; The original query 180.37 - :work-plan-type) ; The type of plan 180.38 - 180.39 -(defn- validate-work-plan 180.40 - "Ensure any top level semantics are not violated" 180.41 - [work-plan database] 180.42 - (let [common-relations (-> work-plan :rules (intersection (-> database keys set)))] 180.43 - (when (-> common-relations 180.44 - empty? 180.45 - not) 180.46 - (throwf "The rules and database define the same relation(s): %s" common-relations)))) 180.47 - ; More will follow 180.48 - 180.49 -(defn build-work-plan 180.50 - "Given a list of rules and a query, build a work plan that can be 180.51 - used to execute the query." 180.52 - [rules query] 180.53 - (struct-map work-plan 180.54 - :work-plan (build-soft-strat-work-plan rules query) 180.55 - :rules rules 180.56 - :query query 180.57 - :work-plan-type ::soft-stratified)) 180.58 - 180.59 -(defn run-work-plan 180.60 - "Given a work plan, a database, and some query bindings, run the 180.61 - work plan and return the results." 180.62 - [work-plan database query-bindings] 180.63 - (validate-work-plan work-plan database) 180.64 - (evaluate-soft-work-set (:work-plan work-plan) database query-bindings)) 180.65 - 180.66 - 180.67 -;; End of file
181.1 --- a/src/clojure/contrib/datalog/database.clj Sat Aug 21 06:25:44 2010 -0400 181.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 181.3 @@ -1,288 +0,0 @@ 181.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 181.5 -;; distribution terms for this software are covered by the Eclipse Public 181.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 181.7 -;; be found in the file epl-v10.html at the root of this distribution. By 181.8 -;; using this software in any fashion, you are agreeing to be bound by the 181.9 -;; terms of this license. You must not remove this notice, or any other, 181.10 -;; from this software. 181.11 -;; 181.12 -;; database.clj 181.13 -;; 181.14 -;; A Clojure implementation of Datalog -- Support for in-memory database 181.15 -;; 181.16 -;; straszheimjeffrey (gmail) 181.17 -;; Created 21 Feburary 2009 181.18 - 181.19 - 181.20 -(ns clojure.contrib.datalog.database 181.21 - (:use clojure.contrib.datalog.util) 181.22 - (:use clojure.contrib.def) 181.23 - (:use [clojure.set :only (union intersection difference)]) 181.24 - (:use [clojure.contrib.except :only (throwf)]) 181.25 - (:import java.io.Writer)) 181.26 - 181.27 - 181.28 -(defstruct relation 181.29 - :schema ; A set of key names 181.30 - :data ; A set of tuples 181.31 - :indexes) ; A map key names to indexes (in turn a map of value to tuples) 181.32 - 181.33 - 181.34 -;;; DDL 181.35 - 181.36 -(defmethod print-method ::datalog-database 181.37 - [db ^Writer writer] 181.38 - (binding [*out* writer] 181.39 - (do 181.40 - (println "(datalog-database") 181.41 - (println "{") 181.42 - (doseq [key (keys db)] 181.43 - (println) 181.44 - (println key) 181.45 - (print-method (db key) writer)) 181.46 - (println "})")))) 181.47 - 181.48 -(defn datalog-database 181.49 - [rels] 181.50 - (with-meta rels {:type ::datalog-database})) 181.51 - 181.52 -(def empty-database (datalog-database {})) 181.53 - 181.54 -(defmethod print-method ::datalog-relation 181.55 - [rel ^Writer writer] 181.56 - (binding [*out* writer] 181.57 - (do 181.58 - (println "(datalog-relation") 181.59 - (println " ;; Schema") 181.60 - (println " " (:schema rel)) 181.61 - (println) 181.62 - (println " ;; Data") 181.63 - (println " #{") 181.64 - (doseq [tuple (:data rel)] 181.65 - (println " " tuple)) 181.66 - (println " }") 181.67 - (println) 181.68 - (println " ;; Indexes") 181.69 - (println " {") 181.70 - (doseq [key (-> rel :indexes keys)] 181.71 - (println " " key) 181.72 - (println " {") 181.73 - (doseq [val (keys ((:indexes rel) key))] 181.74 - (println " " val) 181.75 - (println " " (get-in rel [:indexes key val]))) 181.76 - (println " }")) 181.77 - (println " })")))) 181.78 - 181.79 -(defn datalog-relation 181.80 - "Creates a relation" 181.81 - [schema data indexes] 181.82 - (with-meta (struct relation schema data indexes) {:type ::datalog-relation})) 181.83 - 181.84 -(defn add-relation 181.85 - "Adds a relation to the database" 181.86 - [db name keys] 181.87 - (assoc db name (datalog-relation (set keys) #{} {}))) 181.88 - 181.89 -(defn add-index 181.90 - "Adds an index to an empty relation named name" 181.91 - [db name key] 181.92 - (assert (empty? (:data (db name)))) 181.93 - (let [rel (db name) 181.94 - inx (assoc (:indexes rel) key {})] 181.95 - (assoc db name (datalog-relation (:schema rel) 181.96 - (:data rel) 181.97 - inx)))) 181.98 - 181.99 -(defn ensure-relation 181.100 - "If the database lacks the named relation, add it" 181.101 - [db name keys indexes] 181.102 - (if-let [rel (db name)] 181.103 - (do 181.104 - (assert (= (:schema rel) (set keys))) 181.105 - db) 181.106 - (let [db1 (add-relation db name keys)] 181.107 - (reduce (fn [db key] (add-index db name key)) 181.108 - db1 181.109 - indexes)))) 181.110 - 181.111 - 181.112 -(defmacro make-database 181.113 - "Makes a database, like this 181.114 - (make-database 181.115 - (relation :fred [:mary :sue]) 181.116 - (index :fred :mary) 181.117 - (relation :sally [:jen :becky]) 181.118 - (index :sally :jen) 181.119 - (index :sally :becky))" 181.120 - [& commands] 181.121 - (let [wrapper (fn [cur new] 181.122 - (let [cmd (first new) 181.123 - body (next new)] 181.124 - (assert (= 2 (count body))) 181.125 - (cond 181.126 - (= cmd 'relation) 181.127 - `(add-relation ~cur ~(first body) ~(fnext body)) 181.128 - (= cmd 'index) 181.129 - `(add-index ~cur ~(first body) ~(fnext body)) 181.130 - :otherwise (throwf "%s not recognized" new))))] 181.131 - (reduce wrapper `empty-database commands))) 181.132 - 181.133 -(defn get-relation 181.134 - "Get a relation object by name" 181.135 - [db rel-name] 181.136 - (db rel-name)) 181.137 - 181.138 -(defn replace-relation 181.139 - "Add or replace a fully constructed relation object to the database." 181.140 - [db rel-name rel] 181.141 - (assoc db rel-name rel)) 181.142 - 181.143 - 181.144 -;;; DML 181.145 - 181.146 - 181.147 -(defn database-counts 181.148 - "Returns a map with the count of elements in each relation." 181.149 - [db] 181.150 - (map-values #(-> % :data count) db)) 181.151 - 181.152 -(defn- modify-indexes 181.153 - "Perform f on the indexed tuple-set. f should take a set and tuple, 181.154 - and return the new set." 181.155 - [idxs tuple f] 181.156 - (into {} (for [ik (keys idxs)] 181.157 - (let [im (idxs ik) 181.158 - iv (tuple ik) 181.159 - os (get im iv #{}) 181.160 - ns (f os tuple)] 181.161 - [ik (if (empty? ns) 181.162 - (dissoc im iv) 181.163 - (assoc im iv (f os tuple)))])))) 181.164 - 181.165 -(defn- add-to-indexes 181.166 - "Adds the tuple to the appropriate keys in the index map" 181.167 - [idxs tuple] 181.168 - (modify-indexes idxs tuple conj)) 181.169 - 181.170 -(defn- remove-from-indexes 181.171 - "Removes the tuple from the appropriate keys in the index map" 181.172 - [idxs tuple] 181.173 - (modify-indexes idxs tuple disj)) 181.174 - 181.175 -(defn add-tuple 181.176 - "Two forms: 181.177 - 181.178 - [db relation-name tuple] adds tuple to the named relation. Returns 181.179 - the new database. 181.180 - 181.181 - [rel tuple] adds to the relation object. Returns the new relation." 181.182 - ([db rel-name tuple] 181.183 - (assert (= (-> tuple keys set) (-> rel-name db :schema))) 181.184 - (assoc db rel-name (add-tuple (db rel-name) tuple))) 181.185 - ([rel tuple] 181.186 - (let [data (:data rel) 181.187 - new-data (conj data tuple)] 181.188 - (if (identical? data new-data) ; optimization hack! 181.189 - rel 181.190 - (let [idxs (add-to-indexes (:indexes rel) tuple)] 181.191 - (assoc rel :data new-data :indexes idxs)))))) 181.192 - 181.193 -(defn remove-tuple 181.194 - "Two forms: 181.195 - 181.196 - [db relation-name tuple] removes the tuple from the named relation, 181.197 - returns a new database. 181.198 - 181.199 - [rel tuple] removes the tuple from the relation. Returns the new 181.200 - relation." 181.201 - ([db rel-name tuple] (assoc db rel-name (remove-tuple (db rel-name) tuple))) 181.202 - ([rel tuple] 181.203 - (let [data (:data rel) 181.204 - new-data (disj data tuple)] 181.205 - (if (identical? data new-data) 181.206 - rel 181.207 - (let [idxs (remove-from-indexes (:indexes rel) tuple)] 181.208 - (assoc rel :data new-data :indexes idxs)))))) 181.209 - 181.210 -(defn add-tuples 181.211 - "Adds a collection of tuples to the db, as 181.212 - (add-tuples db 181.213 - [:rel-name :key-1 1 :key-2 2] 181.214 - [:rel-name :key-1 2 :key-2 3])" 181.215 - [db & tupls] 181.216 - (reduce #(add-tuple %1 (first %2) (apply hash-map (next %2))) db tupls)) 181.217 - 181.218 -(defn- find-indexes 181.219 - "Given a map of indexes and a partial tuple, return the sets of full tuples" 181.220 - [idxs pt] 181.221 - (if (empty? idxs) 181.222 - nil 181.223 - (filter identity (for [key (keys pt)] 181.224 - (if-let [idx-map (idxs key)] 181.225 - (get idx-map (pt key) #{}) 181.226 - nil))))) 181.227 - 181.228 -(defn- match? 181.229 - "Is m2 contained in m1?" 181.230 - [m1 m2] 181.231 - (let [compare (fn [key] 181.232 - (and (contains? m1 key) 181.233 - (= (m1 key) (m2 key))))] 181.234 - (every? compare (keys m2)))) 181.235 - 181.236 -(defn- scan-space 181.237 - "Computes a stream of tuples from relation rn matching partial tuple (pt) 181.238 - and applies fun to each" 181.239 - [fun db rn pt] 181.240 - (let [rel (db rn) 181.241 - idxs (find-indexes (:indexes rel) pt) 181.242 - space (if (empty? idxs) 181.243 - (:data rel) ; table scan :( 181.244 - (reduce intersection idxs))] 181.245 - (trace-datalog (when (empty? idxs) 181.246 - (println (format "Table scan of %s: %s rows!!!!!" 181.247 - rn 181.248 - (count space))))) 181.249 - (fun #(match? % pt) space))) 181.250 - 181.251 -(defn select 181.252 - "finds all matching tuples to the partial tuple (pt) in the relation named (rn)" 181.253 - [db rn pt] 181.254 - (scan-space filter db rn pt)) 181.255 - 181.256 -(defn any-match? 181.257 - "Finds if there are any matching records for the partial tuple" 181.258 - [db rn pt] 181.259 - (if (= (-> pt keys set) (:schema (db rn))) 181.260 - (contains? (:data (db rn)) pt) 181.261 - (scan-space some db rn pt))) 181.262 - 181.263 - 181.264 -;;; Merge 181.265 - 181.266 -(defn merge-indexes 181.267 - [idx1 idx2] 181.268 - (merge-with (fn [h1 h2] (merge-with union h1 h2)) idx1 idx2)) 181.269 - 181.270 -(defn merge-relations 181.271 - "Merges two relations" 181.272 - [r1 r2] 181.273 - (assert (= (:schema r1) (:schema r2))) 181.274 - (let [merged-indexes (merge-indexes (:indexes r1) 181.275 - (:indexes r2)) 181.276 - merged-data (union (:data r1) 181.277 - (:data r2))] 181.278 - (assoc r1 :data merged-data :indexes merged-indexes))) 181.279 - 181.280 -(defn database-merge 181.281 - "Merges databases together" 181.282 - [dbs] 181.283 - (apply merge-with merge-relations dbs)) 181.284 - 181.285 -(defn database-merge-parallel 181.286 - "Merges databases together in parallel" 181.287 - [dbs] 181.288 - (preduce merge-relations dbs)) 181.289 - 181.290 - 181.291 -;; End of file
182.1 --- a/src/clojure/contrib/datalog/literals.clj Sat Aug 21 06:25:44 2010 -0400 182.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 182.3 @@ -1,413 +0,0 @@ 182.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 182.5 -;; distribution terms for this software are covered by the Eclipse Public 182.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 182.7 -;; be found in the file epl-v10.html at the root of this distribution. By 182.8 -;; using this software in any fashion, you are agreeing to be bound by the 182.9 -;; terms of this license. You must not remove this notice, or any other, 182.10 -;; from this software. 182.11 -;; 182.12 -;; literals.clj 182.13 -;; 182.14 -;; A Clojure implementation of Datalog -- Literals 182.15 -;; 182.16 -;; straszheimjeffrey (gmail) 182.17 -;; Created 25 Feburary 2009 182.18 - 182.19 - 182.20 -(ns clojure.contrib.datalog.literals 182.21 - (:use clojure.contrib.datalog.util) 182.22 - (:use clojure.contrib.datalog.database) 182.23 - (:use [clojure.set :only (intersection)]) 182.24 - (:use [clojure.contrib.set :only (subset?)])) 182.25 - 182.26 - 182.27 -;;; Type Definitions 182.28 - 182.29 -(defstruct atomic-literal 182.30 - :predicate ; The predicate name 182.31 - :term-bindings ; A map of column names to bindings 182.32 - :literal-type) ; ::literal or ::negated 182.33 - 182.34 -(derive ::negated ::literal) 182.35 - 182.36 -(defstruct conditional-literal 182.37 - :fun ; The fun to call 182.38 - :symbol ; The fun symbol (for display) 182.39 - :terms ; The formal arguments 182.40 - :literal-type) ; ::conditional 182.41 - 182.42 - 182.43 -;;; Basics 182.44 - 182.45 - 182.46 -(defmulti literal-predicate 182.47 - "Return the predicate/relation this conditional operates over" 182.48 - :literal-type) 182.49 - 182.50 -(defmulti literal-columns 182.51 - "Return the column names this applies to" 182.52 - :literal-type) 182.53 - 182.54 -(defmulti literal-vars 182.55 - "Returns the logic vars used by this literal" 182.56 - :literal-type) 182.57 - 182.58 -(defmulti positive-vars 182.59 - "Returns the logic vars used in a positive position" 182.60 - :literal-type) 182.61 - 182.62 -(defmulti negative-vars 182.63 - "Returns the logic vars used in a negative position" 182.64 - :literal-type) 182.65 - 182.66 -(defmethod literal-predicate ::literal 182.67 - [l] 182.68 - (:predicate l)) 182.69 - 182.70 -(defmethod literal-predicate ::conditional 182.71 - [l] 182.72 - nil) 182.73 - 182.74 -(defmethod literal-columns ::literal 182.75 - [l] 182.76 - (-> l :term-bindings keys set)) 182.77 - 182.78 -(defmethod literal-columns ::conditional 182.79 - [l] 182.80 - nil) 182.81 - 182.82 -(defmethod literal-vars ::literal 182.83 - [l] 182.84 - (set (filter is-var? (-> l :term-bindings vals)))) 182.85 - 182.86 -(defmethod literal-vars ::conditional 182.87 - [l] 182.88 - (set (filter is-var? (:terms l)))) 182.89 - 182.90 -(defmethod positive-vars ::literal 182.91 - [l] 182.92 - (literal-vars l)) 182.93 - 182.94 -(defmethod positive-vars ::negated 182.95 - [l] 182.96 - nil) 182.97 - 182.98 -(defmethod positive-vars ::conditional 182.99 - [l] 182.100 - nil) 182.101 - 182.102 -(defmethod negative-vars ::literal 182.103 - [l] 182.104 - nil) 182.105 - 182.106 -(defmethod negative-vars ::negated 182.107 - [l] 182.108 - (literal-vars l)) 182.109 - 182.110 -(defmethod negative-vars ::conditional 182.111 - [l] 182.112 - (literal-vars l)) 182.113 - 182.114 -(defn negated? 182.115 - "Is this literal a negated literal?" 182.116 - [l] 182.117 - (= (:literal-type l) ::negated)) 182.118 - 182.119 -(defn positive? 182.120 - "Is this a positive literal?" 182.121 - [l] 182.122 - (= (:literal-type l) ::literal)) 182.123 - 182.124 - 182.125 -;;; Building Literals 182.126 - 182.127 -(def negation-symbol 'not!) 182.128 -(def conditional-symbol 'if) 182.129 - 182.130 -(defmulti build-literal 182.131 - "(Returns an unevaluated expression (to be used in macros) of a 182.132 - literal." 182.133 - first) 182.134 - 182.135 -(defn build-atom 182.136 - "Returns an unevaluated expression (to be used in a macro) of an 182.137 - atom." 182.138 - [f type] 182.139 - (let [p (first f) 182.140 - ts (map #(if (is-var? %) `(quote ~%) %) (next f)) 182.141 - b (if (seq ts) (apply assoc {} ts) nil)] 182.142 - `(struct atomic-literal ~p ~b ~type))) 182.143 - 182.144 -(defmethod build-literal :default 182.145 - [f] 182.146 - (build-atom f ::literal)) 182.147 - 182.148 -(defmethod build-literal negation-symbol 182.149 - [f] 182.150 - (build-atom (rest f) ::negated)) 182.151 - 182.152 -(defmethod build-literal conditional-symbol 182.153 - [f] 182.154 - (let [symbol (fnext f) 182.155 - terms (nnext f) 182.156 - fun `(fn [binds#] (apply ~symbol binds#))] 182.157 - `(struct conditional-literal 182.158 - ~fun 182.159 - '~symbol 182.160 - '~terms 182.161 - ::conditional))) 182.162 - 182.163 - 182.164 -;;; Display 182.165 - 182.166 -(defmulti display-literal 182.167 - "Converts a struct representing a literal to a normal list" 182.168 - :literal-type) 182.169 - 182.170 -(defn- display 182.171 - [l] 182.172 - (conj (-> l :term-bindings list* flatten) (literal-predicate l))) 182.173 - 182.174 -(defmethod display-literal ::literal 182.175 - [l] 182.176 - (display l)) 182.177 - 182.178 -(defmethod display-literal ::negated 182.179 - [l] 182.180 - (conj (display l) negation-symbol)) 182.181 - 182.182 -(defmethod display-literal ::conditional 182.183 - [l] 182.184 - (list* conditional-symbol (:symbol l) (:terms l))) 182.185 - 182.186 - 182.187 -;;; Sip computation 182.188 - 182.189 -(defmulti get-vs-from-cs 182.190 - "From a set of columns, return the vars" 182.191 - :literal-type) 182.192 - 182.193 -(defmethod get-vs-from-cs ::literal 182.194 - [l bound] 182.195 - (set (filter is-var? 182.196 - (vals (select-keys (:term-bindings l) 182.197 - bound))))) 182.198 - 182.199 -(defmethod get-vs-from-cs ::conditional 182.200 - [l bound] 182.201 - nil) 182.202 - 182.203 - 182.204 -(defmulti get-cs-from-vs 182.205 - "From a set of vars, get the columns" 182.206 - :literal-type) 182.207 - 182.208 -(defmethod get-cs-from-vs ::literal 182.209 - [l bound] 182.210 - (reduce conj 182.211 - #{} 182.212 - (remove nil? 182.213 - (map (fn [[k v]] (if (bound v) k nil)) 182.214 - (:term-bindings l))))) 182.215 - 182.216 -(defmethod get-cs-from-vs ::conditional 182.217 - [l bound] 182.218 - nil) 182.219 - 182.220 - 182.221 -(defmulti get-self-bound-cs 182.222 - "Get the columns that are bound withing the literal." 182.223 - :literal-type) 182.224 - 182.225 -(defmethod get-self-bound-cs ::literal 182.226 - [l] 182.227 - (reduce conj 182.228 - #{} 182.229 - (remove nil? 182.230 - (map (fn [[k v]] (if (not (is-var? v)) k nil)) 182.231 - (:term-bindings l))))) 182.232 - 182.233 -(defmethod get-self-bound-cs ::conditional 182.234 - [l] 182.235 - nil) 182.236 - 182.237 - 182.238 -(defmulti literal-appropriate? 182.239 - "When passed a set of bound vars, determines if this literal can be 182.240 - used during this point of a SIP computation." 182.241 - (fn [b l] (:literal-type l))) 182.242 - 182.243 -(defmethod literal-appropriate? ::literal 182.244 - [bound l] 182.245 - (not (empty? (intersection (literal-vars l) bound)))) 182.246 - 182.247 -(defmethod literal-appropriate? ::negated 182.248 - [bound l] 182.249 - (subset? (literal-vars l) bound)) 182.250 - 182.251 -(defmethod literal-appropriate? ::conditional 182.252 - [bound l] 182.253 - (subset? (literal-vars l) bound)) 182.254 - 182.255 - 182.256 -(defmulti adorned-literal 182.257 - "When passed a set of bound columns, returns the adorned literal" 182.258 - (fn [l b] (:literal-type l))) 182.259 - 182.260 -(defmethod adorned-literal ::literal 182.261 - [l bound] 182.262 - (let [pred (literal-predicate l) 182.263 - bnds (intersection (literal-columns l) bound)] 182.264 - (if (empty? bound) 182.265 - l 182.266 - (assoc l :predicate {:pred pred :bound bnds})))) 182.267 - 182.268 -(defmethod adorned-literal ::conditional 182.269 - [l bound] 182.270 - l) 182.271 - 182.272 - 182.273 -(defn get-adorned-bindings 182.274 - "Get the bindings from this adorned literal." 182.275 - [pred] 182.276 - (:bound pred)) 182.277 - 182.278 -(defn get-base-predicate 182.279 - "Get the base predicate from this predicate." 182.280 - [pred] 182.281 - (if (map? pred) 182.282 - (:pred pred) 182.283 - pred)) 182.284 - 182.285 - 182.286 -;;; Magic Stuff 182.287 - 182.288 -(defn magic-literal 182.289 - "Create a magic version of this adorned predicate." 182.290 - [l] 182.291 - (assert (-> l :literal-type (isa? ::literal))) 182.292 - (let [pred (literal-predicate l) 182.293 - pred-map (if (map? pred) pred {:pred pred}) 182.294 - bound (get-adorned-bindings pred) 182.295 - ntb (select-keys (:term-bindings l) bound)] 182.296 - (assoc l :predicate (assoc pred-map :magic true) :term-bindings ntb :literal-type ::literal))) 182.297 - 182.298 -(defn literal-magic? 182.299 - "Is this literal magic?" 182.300 - [lit] 182.301 - (let [pred (literal-predicate lit)] 182.302 - (when (map? pred) 182.303 - (:magic pred)))) 182.304 - 182.305 -(defn build-seed-bindings 182.306 - "Given a seed literal, already adorned and in magic form, convert 182.307 - its bound constants to new variables." 182.308 - [s] 182.309 - (assert (-> s :literal-type (isa? ::literal))) 182.310 - (let [ntbs (map-values (fn [_] (gensym '?_gen_)) (:term-bindings s))] 182.311 - (assoc s :term-bindings ntbs))) 182.312 - 182.313 - 182.314 -;;; Semi-naive support 182.315 - 182.316 -(defn negated-literal 182.317 - "Given a literal l, return a negated version" 182.318 - [l] 182.319 - (assert (-> l :literal-type (= ::literal))) 182.320 - (assoc l :literal-type ::negated)) 182.321 - 182.322 -(defn delta-literal 182.323 - "Given a literal l, return a delta version" 182.324 - [l] 182.325 - (let [pred* (:predicate l) 182.326 - pred (if (map? pred*) pred* {:pred pred*})] 182.327 - (assoc l :predicate (assoc pred :delta true)))) 182.328 - 182.329 - 182.330 -;;; Database operations 182.331 - 182.332 -(defn- build-partial-tuple 182.333 - [lit binds] 182.334 - (let [tbs (:term-bindings lit) 182.335 - each (fn [[key val :as pair]] 182.336 - (if (is-var? val) 182.337 - (if-let [n (binds val)] 182.338 - [key n] 182.339 - nil) 182.340 - pair))] 182.341 - (into {} (remove nil? (map each tbs))))) 182.342 - 182.343 -(defn- project-onto-literal 182.344 - "Given a literal, and a materialized tuple, return a set of variable 182.345 - bindings." 182.346 - [lit tuple] 182.347 - (let [step (fn [binds [key val]] 182.348 - (if (and (is-var? val) 182.349 - (contains? tuple key)) 182.350 - (assoc binds val (tuple key)) 182.351 - binds))] 182.352 - (reduce step {} (:term-bindings lit)))) 182.353 - 182.354 - 182.355 -(defn- join-literal* 182.356 - [db lit bs fun] 182.357 - (let [each (fn [binds] 182.358 - (let [pt (build-partial-tuple lit binds)] 182.359 - (fun binds pt)))] 182.360 - (when (contains? db (literal-predicate lit)) 182.361 - (apply concat (map each bs))))) 182.362 - 182.363 -(defmulti join-literal 182.364 - "Given a database (db), a literal (lit) and a seq of bindings (bs), 182.365 - return a new seq of bindings by joining this literal." 182.366 - (fn [db lit bs] (:literal-type lit))) 182.367 - 182.368 -(defmethod join-literal ::literal 182.369 - [db lit bs] 182.370 - (join-literal* db lit bs (fn [binds pt] 182.371 - (map #(merge binds %) 182.372 - (map (partial project-onto-literal lit) 182.373 - (select db (literal-predicate lit) pt)))))) 182.374 - 182.375 -(defmethod join-literal ::negated 182.376 - [db lit bs] 182.377 - (join-literal* db lit bs (fn [binds pt] 182.378 - (if (any-match? db (literal-predicate lit) pt) 182.379 - nil 182.380 - [binds])))) 182.381 - 182.382 -(defmethod join-literal ::conditional 182.383 - [db lit bs] 182.384 - (let [each (fn [binds] 182.385 - (let [resolve (fn [term] 182.386 - (if (is-var? term) 182.387 - (binds term) 182.388 - term)) 182.389 - args (map resolve (:terms lit))] 182.390 - (if ((:fun lit) args) 182.391 - binds 182.392 - nil)))] 182.393 - (remove nil? (map each bs)))) 182.394 - 182.395 -(defn project-literal 182.396 - "Project a stream of bindings onto a literal/relation. Returns a new 182.397 - db." 182.398 - ([db lit bs] (project-literal db lit bs is-var?)) 182.399 - ([db lit bs var?] 182.400 - (assert (= (:literal-type lit) ::literal)) 182.401 - (let [rel-name (literal-predicate lit) 182.402 - columns (-> lit :term-bindings keys) 182.403 - idxs (vec (get-adorned-bindings (literal-predicate lit))) 182.404 - db1 (ensure-relation db rel-name columns idxs) 182.405 - rel (get-relation db1 rel-name) 182.406 - step (fn [rel bindings] 182.407 - (let [step (fn [t [k v]] 182.408 - (if (var? v) 182.409 - (assoc t k (bindings v)) 182.410 - (assoc t k v))) 182.411 - tuple (reduce step {} (:term-bindings lit))] 182.412 - (add-tuple rel tuple)))] 182.413 - (replace-relation db rel-name (reduce step rel bs))))) 182.414 - 182.415 - 182.416 -;; End of file
183.1 --- a/src/clojure/contrib/datalog/magic.clj Sat Aug 21 06:25:44 2010 -0400 183.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 183.3 @@ -1,128 +0,0 @@ 183.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 183.5 -;; distribution terms for this software are covered by the Eclipse Public 183.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 183.7 -;; be found in the file epl-v10.html at the root of this distribution. By 183.8 -;; using this software in any fashion, you are agreeing to be bound by the 183.9 -;; terms of this license. You must not remove this notice, or any other, 183.10 -;; from this software. 183.11 -;; 183.12 -;; magic.clj 183.13 -;; 183.14 -;; A Clojure implementation of Datalog -- Magic Sets 183.15 -;; 183.16 -;; straszheimjeffrey (gmail) 183.17 -;; Created 18 Feburary 2009 183.18 - 183.19 - 183.20 -(ns clojure.contrib.datalog.magic 183.21 - (:use clojure.contrib.datalog.util 183.22 - clojure.contrib.datalog.literals 183.23 - clojure.contrib.datalog.rules) 183.24 - (:use [clojure.set :only (union intersection difference)])) 183.25 - 183.26 - 183.27 -;;; Adornment 183.28 - 183.29 -(defn adorn-query 183.30 - "Adorn a query" 183.31 - [q] 183.32 - (adorned-literal q (get-self-bound-cs q))) 183.33 - 183.34 -(defn adorn-rules-set 183.35 - "Adorns the given rules-set for the given query. (rs) is a 183.36 - rules-set, (q) is an adorned query." 183.37 - [rs q] 183.38 - (let [i-preds (all-predicates rs) 183.39 - p-map (predicate-map rs)] 183.40 - (loop [nrs empty-rules-set ; The rules set being built 183.41 - needed #{(literal-predicate q)}] 183.42 - (if (empty? needed) 183.43 - nrs 183.44 - (let [pred (first needed) 183.45 - remaining (disj needed pred) 183.46 - base-pred (get-base-predicate pred) 183.47 - bindings (get-adorned-bindings pred) 183.48 - new-rules (p-map base-pred) 183.49 - new-adorned-rules (map (partial compute-sip bindings i-preds) 183.50 - new-rules) 183.51 - new-nrs (reduce conj nrs new-adorned-rules) 183.52 - current-preds (all-predicates new-nrs) 183.53 - not-needed? (fn [pred] 183.54 - (or (current-preds pred) 183.55 - (-> pred get-base-predicate i-preds not))) 183.56 - add-pred (fn [np pred] 183.57 - (if (not-needed? pred) np (conj np pred))) 183.58 - add-preds (fn [np rule] 183.59 - (reduce add-pred np (map literal-predicate (:body rule)))) 183.60 - new-needed (reduce add-preds remaining new-adorned-rules)] 183.61 - (recur new-nrs new-needed)))))) 183.62 - 183.63 - 183.64 -;;; Magic ! 183.65 - 183.66 -(defn seed-relation 183.67 - "Given a magic form of a query, give back the literal form of its seed 183.68 - relation" 183.69 - [q] 183.70 - (let [pred (-> q literal-predicate get-base-predicate) 183.71 - bnds (-> q literal-predicate get-adorned-bindings)] 183.72 - (with-meta (assoc q :predicate [pred :magic-seed bnds]) {}))) 183.73 - 183.74 -(defn seed-rule 183.75 - "Given an adorned query, give back its seed rule" 183.76 - [q] 183.77 - (let [mq (build-seed-bindings (magic-literal q)) 183.78 - sr (seed-relation mq)] 183.79 - (build-rule mq [sr]))) 183.80 - 183.81 -(defn build-partial-tuple 183.82 - "Given a query and a set of bindings, build a partial tuple needed 183.83 - to extract the relation from the database." 183.84 - [q bindings] 183.85 - (into {} (remove nil? (map (fn [[k v :as pair]] 183.86 - (if (is-var? v) 183.87 - nil 183.88 - (if (is-query-var? v) 183.89 - [k (bindings v)] 183.90 - pair))) 183.91 - (:term-bindings q))))) 183.92 - 183.93 -(defn seed-predicate-for-insertion 183.94 - "Given a query, return the predicate to use for database insertion." 183.95 - [q] 183.96 - (let [seed (-> q seed-rule :body first) 183.97 - columns (-> seed :term-bindings keys) 183.98 - new-term-bindings (-> q :term-bindings (select-keys columns))] 183.99 - (assoc seed :term-bindings new-term-bindings))) 183.100 - 183.101 -(defn magic-transform 183.102 - "Return a magic transformation of an adorned rules-set (rs). The 183.103 - (i-preds) are the predicates of the intension database. These 183.104 - default to the predicates within the rules-set." 183.105 - ([rs] 183.106 - (magic-transform rs (all-predicates rs))) 183.107 - ([rs i-preds] 183.108 - (let [not-duplicate? (fn [l mh bd] 183.109 - (or (not (empty? bd)) 183.110 - (not (= (magic-literal l) 183.111 - mh)))) 183.112 - xr (fn [rs rule] 183.113 - (let [head (:head rule) 183.114 - body (:body rule) 183.115 - mh (magic-literal head) 183.116 - answer-rule (build-rule head 183.117 - (concat [mh] body)) 183.118 - step (fn [[rs bd] l] 183.119 - (if (and (i-preds (literal-predicate l)) 183.120 - (not-duplicate? l mh bd)) 183.121 - (let [nr (build-rule (magic-literal l) 183.122 - (concat [mh] bd))] 183.123 - [(conj rs nr) (conj bd l)]) 183.124 - [rs (conj bd l)])) 183.125 - [nrs _] (reduce step [rs []] body)] 183.126 - (conj nrs answer-rule)))] 183.127 - (reduce xr empty-rules-set rs)))) 183.128 - 183.129 - 183.130 - 183.131 -;; End of file
184.1 --- a/src/clojure/contrib/datalog/rules.clj Sat Aug 21 06:25:44 2010 -0400 184.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 184.3 @@ -1,208 +0,0 @@ 184.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 184.5 -;; distribution terms for this software are covered by the Eclipse Public 184.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 184.7 -;; be found in the file epl-v10.html at the root of this distribution. By 184.8 -;; using this software in any fashion, you are agreeing to be bound by the 184.9 -;; terms of this license. You must not remove this notice, or any other, 184.10 -;; from this software. 184.11 -;; 184.12 -;; rules.clj 184.13 -;; 184.14 -;; A Clojure implementation of Datalog -- Rules Engine 184.15 -;; 184.16 -;; straszheimjeffrey (gmail) 184.17 -;; Created 2 Feburary 2009 184.18 - 184.19 - 184.20 -(ns clojure.contrib.datalog.rules 184.21 - (:use clojure.contrib.datalog.util) 184.22 - (:use clojure.contrib.datalog.literals 184.23 - clojure.contrib.datalog.database) 184.24 - (:use [clojure.set :only (union intersection difference)]) 184.25 - (:use [clojure.contrib.set :only (subset?)]) 184.26 - (:use [clojure.contrib.except :only (throwf)]) 184.27 - (:import java.io.Writer)) 184.28 - 184.29 - 184.30 -(defstruct datalog-rule 184.31 - :head 184.32 - :body) 184.33 - 184.34 -(defn display-rule 184.35 - "Return the rule in a readable format." 184.36 - [rule] 184.37 - (list* '<- 184.38 - (-> rule :head display-literal) 184.39 - (map display-literal (:body rule)))) 184.40 - 184.41 -(defn display-query 184.42 - "Return a query in a readable format." 184.43 - [query] 184.44 - (list* '?- (display-literal query))) 184.45 - 184.46 - 184.47 -;;; Check rule safety 184.48 - 184.49 -(defn is-safe? 184.50 - "Is the rule safe according to the datalog protocol?" 184.51 - [rule] 184.52 - (let [hv (literal-vars (:head rule)) 184.53 - bpv (apply union (map positive-vars (:body rule))) 184.54 - bnv (apply union (map negative-vars (:body rule))) 184.55 - ehv (difference hv bpv) 184.56 - env (difference bnv bpv)] 184.57 - (when-not (empty? ehv) 184.58 - (throwf "Head vars %s not bound in body in rule %s" ehv rule)) 184.59 - (when-not (empty? env) 184.60 - (throwf "Body vars %s not bound in negative positions in rule %s" env rule)) 184.61 - rule)) 184.62 - 184.63 - 184.64 -;;; Rule creation and printing 184.65 - 184.66 -(defn build-rule 184.67 - [hd bd] 184.68 - (with-meta (struct datalog-rule hd bd) {:type ::datalog-rule})) 184.69 - 184.70 -(defmacro <- 184.71 - "Build a datalog rule. Like this: 184.72 - 184.73 - (<- (:head :x ?x :y ?y) (:body-1 :x ?x :y ?y) (:body-2 :z ?z) (not! :body-3 :x ?x) (if > ?y ?z))" 184.74 - [hd & body] 184.75 - (let [head (build-atom hd :clojure.contrib.datalog.literals/literal) 184.76 - body (map build-literal body)] 184.77 - `(is-safe? (build-rule ~head [~@body])))) 184.78 - 184.79 -(defmethod print-method ::datalog-rule 184.80 - [rule ^Writer writer] 184.81 - (print-method (display-rule rule) writer)) 184.82 - 184.83 -(defn return-rule-data 184.84 - "Returns an untypted rule that will be fully printed" 184.85 - [rule] 184.86 - (with-meta rule {})) 184.87 - 184.88 -(defmacro ?- 184.89 - "Define a datalog query" 184.90 - [& q] 184.91 - (let [qq (build-atom q :clojure.contrib.datalog.literals/literal)] 184.92 - `(with-meta ~qq {:type ::datalog-query}))) 184.93 - 184.94 -(defmethod print-method ::datalog-query 184.95 - [query ^Writer writer] 184.96 - (print-method (display-query query) writer)) 184.97 - 184.98 - 184.99 - 184.100 -;;; SIP 184.101 - 184.102 -(defn compute-sip 184.103 - "Given a set of bound column names, return an adorned sip for this 184.104 - rule. A set of intensional predicates should be provided to 184.105 - determine what should be adorned." 184.106 - [bindings i-preds rule] 184.107 - (let [next-lit (fn [bv body] 184.108 - (or (first (drop-while 184.109 - #(not (literal-appropriate? bv %)) 184.110 - body)) 184.111 - (first (drop-while (complement positive?) body)))) 184.112 - adorn (fn [lit bvs] 184.113 - (if (i-preds (literal-predicate lit)) 184.114 - (let [bnds (union (get-cs-from-vs lit bvs) 184.115 - (get-self-bound-cs lit))] 184.116 - (adorned-literal lit bnds)) 184.117 - lit)) 184.118 - new-h (adorned-literal (:head rule) bindings)] 184.119 - (loop [bound-vars (get-vs-from-cs (:head rule) bindings) 184.120 - body (:body rule) 184.121 - sip []] 184.122 - (if-let [next (next-lit bound-vars body)] 184.123 - (recur (union bound-vars (literal-vars next)) 184.124 - (remove #(= % next) body) 184.125 - (conj sip (adorn next bound-vars))) 184.126 - (build-rule new-h (concat sip body)))))) 184.127 - 184.128 - 184.129 -;;; Rule sets 184.130 - 184.131 -(defn make-rules-set 184.132 - "Given an existing set of rules, make it a 'rules-set' for 184.133 - printing." 184.134 - [rs] 184.135 - (with-meta rs {:type ::datalog-rules-set})) 184.136 - 184.137 -(def empty-rules-set (make-rules-set #{})) 184.138 - 184.139 -(defn rules-set 184.140 - "Given a collection of rules return a rules set" 184.141 - [& rules] 184.142 - (reduce conj empty-rules-set rules)) 184.143 - 184.144 -(defmethod print-method ::datalog-rules-set 184.145 - [rules ^Writer writer] 184.146 - (binding [*out* writer] 184.147 - (do 184.148 - (print "(rules-set") 184.149 - (doseq [rule rules] 184.150 - (println) 184.151 - (print " ") 184.152 - (print rule)) 184.153 - (println ")")))) 184.154 - 184.155 -(defn predicate-map 184.156 - "Given a rules-set, return a map of rules keyed by their predicates. 184.157 - Each value will be a set of rules." 184.158 - [rs] 184.159 - (let [add-rule (fn [m r] 184.160 - (let [pred (-> r :head literal-predicate) 184.161 - os (get m pred #{})] 184.162 - (assoc m pred (conj os r))))] 184.163 - (reduce add-rule {} rs))) 184.164 - 184.165 -(defn all-predicates 184.166 - "Given a rules-set, return all defined predicates" 184.167 - [rs] 184.168 - (set (map literal-predicate (map :head rs)))) 184.169 - 184.170 -(defn non-base-rules 184.171 - "Return a collection of rules that depend, somehow, on other rules" 184.172 - [rs] 184.173 - (let [pred (all-predicates rs) 184.174 - non-base (fn [r] 184.175 - (if (some #(pred %) 184.176 - (map literal-predicate (:body r))) 184.177 - r 184.178 - nil))] 184.179 - (remove nil? (map non-base rs)))) 184.180 - 184.181 - 184.182 -;;; Database operations 184.183 - 184.184 -(def empty-bindings [{}]) 184.185 - 184.186 -(defn apply-rule 184.187 - "Apply the rule against db-1, adding the results to the appropriate 184.188 - relation in db-2. The relation will be created if needed." 184.189 - ([db rule] (apply-rule db db rule)) 184.190 - ([db-1 db-2 rule] 184.191 - (trace-datalog (println) 184.192 - (println) 184.193 - (println "--------------- Begin Rule ---------------") 184.194 - (println rule)) 184.195 - (let [head (:head rule) 184.196 - body (:body rule) 184.197 - step (fn [bs lit] 184.198 - (trace-datalog (println bs) 184.199 - (println lit)) 184.200 - (join-literal db-1 lit bs)) 184.201 - bs (reduce step empty-bindings body)] 184.202 - (do (trace-datalog (println bs)) 184.203 - (project-literal db-2 head bs))))) 184.204 - 184.205 -(defn apply-rules-set 184.206 - [db rs] 184.207 - (reduce (fn [rdb rule] 184.208 - (apply-rule db rdb rule)) db rs)) 184.209 - 184.210 - 184.211 -;; End of file 184.212 \ No newline at end of file
185.1 --- a/src/clojure/contrib/datalog/softstrat.clj Sat Aug 21 06:25:44 2010 -0400 185.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 185.3 @@ -1,161 +0,0 @@ 185.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 185.5 -;; distribution terms for this software are covered by the Eclipse Public 185.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 185.7 -;; be found in the file epl-v10.html at the root of this distribution. By 185.8 -;; using this software in any fashion, you are agreeing to be bound by the 185.9 -;; terms of this license. You must not remove this notice, or any other, 185.10 -;; from this software. 185.11 -;; 185.12 -;; softstrat.clj 185.13 -;; 185.14 -;; A Clojure implementation of Datalog -- Soft Stratification 185.15 -;; 185.16 -;; straszheimjeffrey (gmail) 185.17 -;; Created 28 Feburary 2009 185.18 - 185.19 - 185.20 -(ns clojure.contrib.datalog.softstrat 185.21 - (:use clojure.contrib.datalog.util 185.22 - clojure.contrib.datalog.database 185.23 - clojure.contrib.datalog.literals 185.24 - clojure.contrib.datalog.rules 185.25 - clojure.contrib.datalog.magic) 185.26 - (:use [clojure.set :only (union intersection difference)]) 185.27 - (:use [clojure.contrib.seq :only (indexed)]) 185.28 - (:require [clojure.contrib.graph :as graph])) 185.29 - 185.30 - 185.31 -;;; Dependency graph 185.32 - 185.33 -(defn- build-rules-graph 185.34 - "Given a rules-set (rs), build a graph where each predicate symbol in rs, 185.35 - there is a node n, and for each rule (<- h b-1 b-2 ...), there are edges 185.36 - from the (literal-predicate h) -> (literal-predicate b-*), one for each 185.37 - b-*." 185.38 - [rs] 185.39 - (let [preds (all-predicates rs) 185.40 - pred-map (predicate-map rs) 185.41 - step (fn [nbs pred] 185.42 - (let [rules (pred-map pred) 185.43 - preds (reduce (fn [pds lits] 185.44 - (reduce (fn [pds lit] 185.45 - (if-let [pred (literal-predicate lit)] 185.46 - (conj pds pred) 185.47 - pds)) 185.48 - pds 185.49 - lits)) 185.50 - #{} 185.51 - (map :body rules))] 185.52 - (assoc nbs pred preds))) 185.53 - neighbors (reduce step {} preds)] 185.54 - (struct graph/directed-graph preds neighbors))) 185.55 - 185.56 -(defn- build-def 185.57 - "Given a rules-set, build its def function" 185.58 - [rs] 185.59 - (let [pred-map (predicate-map rs) 185.60 - graph (-> rs 185.61 - build-rules-graph 185.62 - graph/transitive-closure 185.63 - graph/add-loops)] 185.64 - (fn [pred] 185.65 - (apply union (map set (map pred-map (graph/get-neighbors graph pred))))))) 185.66 - 185.67 - 185.68 -;;; Soft Stratificattion REQ Graph 185.69 - 185.70 -(defn- req 185.71 - "Returns a rules-set that is a superset of req(lit) for the lit at 185.72 - index lit-index" 185.73 - [rs soft-def rule lit-index] 185.74 - (let [head (:head rule) 185.75 - body (:body rule) 185.76 - lit (nth body lit-index) 185.77 - pre (subvec (vec body) 0 lit-index)] 185.78 - (conj (-> lit literal-predicate soft-def (magic-transform (all-predicates rs))) 185.79 - (build-rule (magic-literal lit) pre)))) 185.80 - 185.81 -(defn- rule-dep 185.82 - "Given a rule, return the set of rules it depends on." 185.83 - [rs mrs soft-def rule] 185.84 - (let [step (fn [nrs [idx lit]] 185.85 - (if (negated? lit) 185.86 - (union nrs (req rs soft-def rule idx)) 185.87 - nrs))] 185.88 - (intersection mrs 185.89 - (reduce step empty-rules-set (-> rule :body indexed))))) 185.90 - 185.91 -(defn- soft-strat-graph 185.92 - "The dependency graph for soft stratification." 185.93 - [rs mrs] 185.94 - (let [soft-def (build-def rs) 185.95 - step (fn [nbrs rule] 185.96 - (assoc nbrs rule (rule-dep rs mrs soft-def rule))) 185.97 - nbrs (reduce step {} mrs)] 185.98 - (struct graph/directed-graph mrs nbrs))) 185.99 - 185.100 -(defn- build-soft-strat 185.101 - "Given a rules-set (unadorned) and an adorned query, return the soft 185.102 - stratified list. The rules will be magic transformed, and the 185.103 - magic seed will be appended." 185.104 - [rs q] 185.105 - (let [ars (adorn-rules-set rs q) 185.106 - mrs (conj (magic-transform ars) 185.107 - (seed-rule q)) 185.108 - gr (soft-strat-graph ars mrs)] 185.109 - (map make-rules-set (graph/dependency-list gr)))) 185.110 - 185.111 - 185.112 -;;; Work plan 185.113 - 185.114 -(defstruct soft-strat-work-plan 185.115 - :query 185.116 - :stratification) 185.117 - 185.118 -(defn build-soft-strat-work-plan 185.119 - "Return a work plan for the given rules-set and query" 185.120 - [rs q] 185.121 - (let [aq (adorn-query q)] 185.122 - (struct soft-strat-work-plan aq (build-soft-strat rs aq)))) 185.123 - 185.124 -(defn get-all-relations 185.125 - "Return a set of all relation names defined in this workplan" 185.126 - [ws] 185.127 - (apply union (map all-predicates (:stratification ws)))) 185.128 - 185.129 - 185.130 -;;; Evaluate 185.131 - 185.132 -(defn- weak-consq-operator 185.133 - [db strat] 185.134 - (trace-datalog (println) 185.135 - (println) 185.136 - (println "=============== Begin iteration ===============")) 185.137 - (let [counts (database-counts db)] 185.138 - (loop [strat strat] 185.139 - (let [rs (first strat)] 185.140 - (if rs 185.141 - (let [new-db (apply-rules-set db rs)] 185.142 - (if (= counts (database-counts new-db)) 185.143 - (recur (next strat)) 185.144 - new-db)) 185.145 - db))))) 185.146 - 185.147 -(defn evaluate-soft-work-set 185.148 - ([ws db] (evaluate-soft-work-set ws db {})) 185.149 - ([ws db bindings] 185.150 - (let [query (:query ws) 185.151 - strat (:stratification ws) 185.152 - seed (seed-predicate-for-insertion query) 185.153 - seeded-db (project-literal db seed [bindings] is-query-var?) 185.154 - fun (fn [data] 185.155 - (weak-consq-operator data strat)) 185.156 - equal (fn [db1 db2] 185.157 - (= (database-counts db1) (database-counts db2))) 185.158 - new-db (graph/fixed-point seeded-db fun nil equal) 185.159 - pt (build-partial-tuple query bindings)] 185.160 - (select new-db (literal-predicate query) pt)))) 185.161 - 185.162 - 185.163 - 185.164 -;; End of file
186.1 --- a/src/clojure/contrib/datalog/util.clj Sat Aug 21 06:25:44 2010 -0400 186.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 186.3 @@ -1,89 +0,0 @@ 186.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 186.5 -;; distribution terms for this software are covered by the Eclipse Public 186.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 186.7 -;; be found in the file epl-v10.html at the root of this distribution. By 186.8 -;; using this software in any fashion, you are agreeing to be bound by the 186.9 -;; terms of this license. You must not remove this notice, or any other, 186.10 -;; from this software. 186.11 -;; 186.12 -;; util.clj 186.13 -;; 186.14 -;; A Clojure implementation of Datalog -- Utilities 186.15 -;; 186.16 -;; straszheimjeffrey (gmail) 186.17 -;; Created 3 Feburary 2009 186.18 - 186.19 - 186.20 -(ns clojure.contrib.datalog.util 186.21 - (:use [clojure.contrib.seq :only (separate)])) 186.22 - 186.23 - 186.24 - 186.25 -;;; Bindings and logic vars. A binding in a hash of logic vars to 186.26 -;;; bound values. Logic vars are any symbol prefixed with a \?. 186.27 - 186.28 -(defn is-var? 186.29 - "Is this a logic variable: e.g. a symbol prefixed with a ?" 186.30 - [sym] 186.31 - (when (symbol? sym) 186.32 - (let [name (name sym)] 186.33 - (and (= \? (first name)) 186.34 - (not= \? (fnext name)))))) 186.35 - 186.36 -(defn is-query-var? 186.37 - "Is this a query variable: e.g. a symbol prefixed with ??" 186.38 - [sym] 186.39 - (when (symbol? sym) 186.40 - (let [name (name sym)] 186.41 - (and (= \? (first name)) 186.42 - (= \? (fnext name)))))) 186.43 - 186.44 -(defn map-values 186.45 - "Like map, but works over the values of a hash map" 186.46 - [f hash] 186.47 - (let [key-vals (map (fn [[key val]] [key (f val)]) hash)] 186.48 - (if (seq key-vals) 186.49 - (apply conj (empty hash) key-vals) 186.50 - hash))) 186.51 - 186.52 -(defn keys-to-vals 186.53 - "Given a map and a collection of keys, return the collection of vals" 186.54 - [m ks] 186.55 - (vals (select-keys m ks))) 186.56 - 186.57 -(defn reverse-map 186.58 - "Reverse the keys/values of a map" 186.59 - [m] 186.60 - (into {} (map (fn [[k v]] [v k]) m))) 186.61 - 186.62 - 186.63 -;;; Preduce -- A parallel reduce over hashes 186.64 - 186.65 -(defn preduce 186.66 - "Similar to merge-with, but the contents of each key are merged in 186.67 - parallel using f. 186.68 - 186.69 - f - a function of 2 arguments. 186.70 - data - a collection of hashes." 186.71 - [f data] 186.72 - (let [data-1 (map (fn [h] (map-values #(list %) h)) data) 186.73 - merged (doall (apply merge-with concat data-1)) 186.74 - ; Groups w/ multiple elements are identified for parallel processing 186.75 - [complex simple] (separate (fn [[key vals]] (> (count vals) 1)) merged) 186.76 - fold-group (fn [[key vals]] {key (reduce f vals)}) 186.77 - fix-single (fn [[key [val]]] [key val])] 186.78 - (apply merge (concat (pmap fold-group merged) (map fix-single simple))))) 186.79 - 186.80 - 186.81 -;;; Debuging and Tracing 186.82 - 186.83 -(def *trace-datalog* nil) 186.84 - 186.85 -(defmacro trace-datalog 186.86 - "If *test-datalog* is set to true, run the enclosed commands" 186.87 - [& body] 186.88 - `(when *trace-datalog* 186.89 - ~@body)) 186.90 - 186.91 - 186.92 -;; End of file
187.1 --- a/src/clojure/contrib/def.clj Sat Aug 21 06:25:44 2010 -0400 187.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 187.3 @@ -1,149 +0,0 @@ 187.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 187.5 -;; distribution terms for this software are covered by the Eclipse Public 187.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 187.7 -;; be found in the file epl-v10.html at the root of this distribution. By 187.8 -;; using this software in any fashion, you are agreeing to be bound by the 187.9 -;; terms of this license. You must not remove this notice, or any other, 187.10 -;; from this software. 187.11 -;; 187.12 -;; File: def.clj 187.13 -;; 187.14 -;; def.clj provides variants of def that make including doc strings and 187.15 -;; making private definitions more succinct. 187.16 -;; 187.17 -;; scgilardi (gmail) 187.18 -;; 17 May 2008 187.19 - 187.20 -(ns 187.21 - ^{:author "Stephen C. Gilardi", 187.22 - :doc "def.clj provides variants of def that make including doc strings and 187.23 -making private definitions more succinct."} 187.24 - clojure.contrib.def) 187.25 - 187.26 -(defmacro defvar 187.27 - "Defines a var with an optional intializer and doc string" 187.28 - ([name] 187.29 - (list `def name)) 187.30 - ([name init] 187.31 - (list `def name init)) 187.32 - ([name init doc] 187.33 - (list `def (with-meta name (assoc (meta name) :doc doc)) init))) 187.34 - 187.35 -(defmacro defunbound 187.36 - "Defines an unbound var with optional doc string" 187.37 - ([name] 187.38 - (list `def name)) 187.39 - ([name doc] 187.40 - (list `def (with-meta name (assoc (meta name) :doc doc))))) 187.41 - 187.42 -(defmacro defmacro- 187.43 - "Same as defmacro but yields a private definition" 187.44 - [name & decls] 187.45 - (list* `defmacro (with-meta name (assoc (meta name) :private true)) decls)) 187.46 - 187.47 -(defmacro defvar- 187.48 - "Same as defvar but yields a private definition" 187.49 - [name & decls] 187.50 - (list* `defvar (with-meta name (assoc (meta name) :private true)) decls)) 187.51 - 187.52 -(defmacro defunbound- 187.53 - "Same as defunbound but yields a private definition" 187.54 - [name & decls] 187.55 - (list* `defunbound (with-meta name (assoc (meta name) :private true)) decls)) 187.56 - 187.57 -(defmacro defstruct- 187.58 - "Same as defstruct but yields a private definition" 187.59 - [name & decls] 187.60 - (list* `defstruct (with-meta name (assoc (meta name) :private true)) decls)) 187.61 - 187.62 -(defmacro defonce- 187.63 - "Same as defonce but yields a private definition" 187.64 - ([name expr] 187.65 - (list `defonce (with-meta name (assoc (meta name) :private true)) expr)) 187.66 - ([name expr doc] 187.67 - (list `defonce (with-meta name (assoc (meta name) :private true :doc doc)) expr))) 187.68 - 187.69 -(defmacro defalias 187.70 - "Defines an alias for a var: a new var with the same root binding (if 187.71 - any) and similar metadata. The metadata of the alias is its initial 187.72 - metadata (as provided by def) merged into the metadata of the original." 187.73 - ([name orig] 187.74 - `(do 187.75 - (alter-meta! 187.76 - (if (.hasRoot (var ~orig)) 187.77 - (def ~name (.getRoot (var ~orig))) 187.78 - (def ~name)) 187.79 - ;; When copying metadata, disregard {:macro false}. 187.80 - ;; Workaround for http://www.assembla.com/spaces/clojure/tickets/273 187.81 - #(conj (dissoc % :macro) 187.82 - (apply dissoc (meta (var ~orig)) (remove #{:macro} (keys %))))) 187.83 - (var ~name))) 187.84 - ([name orig doc] 187.85 - (list `defalias (with-meta name (assoc (meta name) :doc doc)) orig))) 187.86 - 187.87 -; defhinted by Chouser: 187.88 -(defmacro defhinted 187.89 - "Defines a var with a type hint matching the class of the given 187.90 - init. Be careful about using any form of 'def' or 'binding' to a 187.91 - value of a different type. See http://paste.lisp.org/display/73344" 187.92 - [sym init] 187.93 - `(do 187.94 - (def ~sym ~init) 187.95 - (alter-meta! (var ~sym) assoc :tag (class ~sym)) 187.96 - (var ~sym))) 187.97 - 187.98 -; name-with-attributes by Konrad Hinsen: 187.99 -(defn name-with-attributes 187.100 - "To be used in macro definitions. 187.101 - Handles optional docstrings and attribute maps for a name to be defined 187.102 - in a list of macro arguments. If the first macro argument is a string, 187.103 - it is added as a docstring to name and removed from the macro argument 187.104 - list. If afterwards the first macro argument is a map, its entries are 187.105 - added to the name's metadata map and the map is removed from the 187.106 - macro argument list. The return value is a vector containing the name 187.107 - with its extended metadata map and the list of unprocessed macro 187.108 - arguments." 187.109 - [name macro-args] 187.110 - (let [[docstring macro-args] (if (string? (first macro-args)) 187.111 - [(first macro-args) (next macro-args)] 187.112 - [nil macro-args]) 187.113 - [attr macro-args] (if (map? (first macro-args)) 187.114 - [(first macro-args) (next macro-args)] 187.115 - [{} macro-args]) 187.116 - attr (if docstring 187.117 - (assoc attr :doc docstring) 187.118 - attr) 187.119 - attr (if (meta name) 187.120 - (conj (meta name) attr) 187.121 - attr)] 187.122 - [(with-meta name attr) macro-args])) 187.123 - 187.124 -; defnk by Meikel Brandmeyer: 187.125 -(defmacro defnk 187.126 - "Define a function accepting keyword arguments. Symbols up to the first 187.127 - keyword in the parameter list are taken as positional arguments. Then 187.128 - an alternating sequence of keywords and defaults values is expected. The 187.129 - values of the keyword arguments are available in the function body by 187.130 - virtue of the symbol corresponding to the keyword (cf. :keys destructuring). 187.131 - defnk accepts an optional docstring as well as an optional metadata map." 187.132 - [fn-name & fn-tail] 187.133 - (let [[fn-name [args & body]] (name-with-attributes fn-name fn-tail) 187.134 - [pos kw-vals] (split-with symbol? args) 187.135 - syms (map #(-> % name symbol) (take-nth 2 kw-vals)) 187.136 - values (take-nth 2 (rest kw-vals)) 187.137 - sym-vals (apply hash-map (interleave syms values)) 187.138 - de-map {:keys (vec syms) 187.139 - :or sym-vals}] 187.140 - `(defn ~fn-name 187.141 - [~@pos & options#] 187.142 - (let [~de-map (apply hash-map options#)] 187.143 - ~@body)))) 187.144 - 187.145 -; defn-memo by Chouser: 187.146 -(defmacro defn-memo 187.147 - "Just like defn, but memoizes the function using clojure.core/memoize" 187.148 - [fn-name & defn-stuff] 187.149 - `(do 187.150 - (defn ~fn-name ~@defn-stuff) 187.151 - (alter-var-root (var ~fn-name) memoize) 187.152 - (var ~fn-name)))
188.1 --- a/src/clojure/contrib/duck_streams.clj Sat Aug 21 06:25:44 2010 -0400 188.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 188.3 @@ -1,418 +0,0 @@ 188.4 -;;; duck_streams.clj -- duck-typed I/O streams for Clojure 188.5 - 188.6 -;; by Stuart Sierra, http://stuartsierra.com/ 188.7 -;; May 13, 2009 188.8 - 188.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 188.10 -;; and distribution terms for this software are covered by the Eclipse 188.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 188.12 -;; which can be found in the file epl-v10.html at the root of this 188.13 -;; distribution. By using this software in any fashion, you are 188.14 -;; agreeing to be bound by the terms of this license. You must not 188.15 -;; remove this notice, or any other, from this software. 188.16 - 188.17 - 188.18 -;; This file defines "duck-typed" I/O utility functions for Clojure. 188.19 -;; The 'reader' and 'writer' functions will open and return an 188.20 -;; instance of java.io.BufferedReader and java.io.PrintWriter, 188.21 -;; respectively, for a variety of argument types -- filenames as 188.22 -;; strings, URLs, java.io.File's, etc. 'reader' even works on http 188.23 -;; URLs. 188.24 -;; 188.25 -;; Note: this is not really "duck typing" as implemented in languages 188.26 -;; like Ruby. A better name would have been "do-what-I-mean-streams" 188.27 -;; or "just-give-me-a-stream", but ducks are funnier. 188.28 - 188.29 - 188.30 -;; CHANGE LOG 188.31 -;; 188.32 -;; July 23, 2010: DEPRECATED in 1.2. Use clojure.java.io instead. 188.33 -;; 188.34 -;; May 13, 2009: added functions to open writers for appending 188.35 -;; 188.36 -;; May 3, 2009: renamed file to file-str, for compatibility with 188.37 -;; clojure.contrib.java-utils. reader/writer no longer use this 188.38 -;; function. 188.39 -;; 188.40 -;; February 16, 2009: (lazy branch) fixed read-lines to work with lazy 188.41 -;; Clojure. 188.42 -;; 188.43 -;; January 10, 2009: added *default-encoding*, so streams are always 188.44 -;; opened as UTF-8. 188.45 -;; 188.46 -;; December 19, 2008: rewrote reader and writer as multimethods; added 188.47 -;; slurp*, file, and read-lines 188.48 -;; 188.49 -;; April 8, 2008: first version 188.50 - 188.51 -(ns 188.52 - ^{:author "Stuart Sierra", 188.53 - :deprecated "1.2" 188.54 - :doc "This file defines \"duck-typed\" I/O utility functions for Clojure. 188.55 - The 'reader' and 'writer' functions will open and return an 188.56 - instance of java.io.BufferedReader and java.io.PrintWriter, 188.57 - respectively, for a variety of argument types -- filenames as 188.58 - strings, URLs, java.io.File's, etc. 'reader' even works on http 188.59 - URLs. 188.60 - 188.61 - Note: this is not really \"duck typing\" as implemented in languages 188.62 - like Ruby. A better name would have been \"do-what-I-mean-streams\" 188.63 - or \"just-give-me-a-stream\", but ducks are funnier."} 188.64 - clojure.contrib.duck-streams 188.65 - (:refer-clojure :exclude (spit)) 188.66 - (:import 188.67 - (java.io Reader InputStream InputStreamReader PushbackReader 188.68 - BufferedReader File PrintWriter OutputStream 188.69 - OutputStreamWriter BufferedWriter Writer 188.70 - FileInputStream FileOutputStream ByteArrayOutputStream 188.71 - StringReader ByteArrayInputStream) 188.72 - (java.net URI URL MalformedURLException Socket))) 188.73 - 188.74 - 188.75 -(def 188.76 - ^{:doc "Name of the default encoding to use when reading & writing. 188.77 - Default is UTF-8." 188.78 - :tag "java.lang.String"} 188.79 - *default-encoding* "UTF-8") 188.80 - 188.81 -(def 188.82 - ^{:doc "Size, in bytes or characters, of the buffer used when 188.83 - copying streams."} 188.84 - *buffer-size* 1024) 188.85 - 188.86 -(def 188.87 - ^{:doc "Type object for a Java primitive byte array."} 188.88 - *byte-array-type* (class (make-array Byte/TYPE 0))) 188.89 - 188.90 - 188.91 -(defn ^File file-str 188.92 - "Concatenates args as strings and returns a java.io.File. Replaces 188.93 - all / and \\ with File/separatorChar. Replaces ~ at the start of 188.94 - the path with the user.home system property." 188.95 - [& args] 188.96 - (let [^String s (apply str args) 188.97 - s (.replaceAll (re-matcher #"[/\\]" s) File/separator) 188.98 - s (if (.startsWith s "~") 188.99 - (str (System/getProperty "user.home") 188.100 - File/separator (subs s 1)) 188.101 - s)] 188.102 - (File. s))) 188.103 - 188.104 - 188.105 -(defmulti ^{:tag BufferedReader 188.106 - :doc "Attempts to coerce its argument into an open 188.107 - java.io.BufferedReader. Argument may be an instance of Reader, 188.108 - BufferedReader, InputStream, File, URI, URL, Socket, or String. 188.109 - 188.110 - If argument is a String, it tries to resolve it first as a URI, then 188.111 - as a local file name. URIs with a 'file' protocol are converted to 188.112 - local file names. Uses *default-encoding* as the text encoding. 188.113 - 188.114 - Should be used inside with-open to ensure the Reader is properly 188.115 - closed." 188.116 - :arglists '([x])} 188.117 - reader class) 188.118 - 188.119 -(defmethod reader Reader [x] 188.120 - (BufferedReader. x)) 188.121 - 188.122 -(defmethod reader InputStream [^InputStream x] 188.123 - (BufferedReader. (InputStreamReader. x *default-encoding*))) 188.124 - 188.125 -(defmethod reader File [^File x] 188.126 - (reader (FileInputStream. x))) 188.127 - 188.128 -(defmethod reader URL [^URL x] 188.129 - (reader (if (= "file" (.getProtocol x)) 188.130 - (FileInputStream. (.getPath x)) 188.131 - (.openStream x)))) 188.132 - 188.133 -(defmethod reader URI [^URI x] 188.134 - (reader (.toURL x))) 188.135 - 188.136 -(defmethod reader String [^String x] 188.137 - (try (let [url (URL. x)] 188.138 - (reader url)) 188.139 - (catch MalformedURLException e 188.140 - (reader (File. x))))) 188.141 - 188.142 -(defmethod reader Socket [^Socket x] 188.143 - (reader (.getInputStream x))) 188.144 - 188.145 -(defmethod reader :default [x] 188.146 - (throw (Exception. (str "Cannot open " (pr-str x) " as a reader.")))) 188.147 - 188.148 - 188.149 -(def 188.150 - ^{:doc "If true, writer and spit will open files in append mode. 188.151 - Defaults to false. Use append-writer or append-spit." 188.152 - :tag "java.lang.Boolean"} 188.153 - *append-to-writer* false) 188.154 - 188.155 - 188.156 -(defmulti ^{:tag PrintWriter 188.157 - :doc "Attempts to coerce its argument into an open java.io.PrintWriter 188.158 - wrapped around a java.io.BufferedWriter. Argument may be an 188.159 - instance of Writer, PrintWriter, BufferedWriter, OutputStream, File, 188.160 - URI, URL, Socket, or String. 188.161 - 188.162 - If argument is a String, it tries to resolve it first as a URI, then 188.163 - as a local file name. URIs with a 'file' protocol are converted to 188.164 - local file names. 188.165 - 188.166 - Should be used inside with-open to ensure the Writer is properly 188.167 - closed." 188.168 - :arglists '([x])} 188.169 - writer class) 188.170 - 188.171 -(defn- assert-not-appending [] 188.172 - (when *append-to-writer* 188.173 - (throw (Exception. "Cannot change an open stream to append mode.")))) 188.174 - 188.175 -(defmethod writer PrintWriter [x] 188.176 - (assert-not-appending) 188.177 - x) 188.178 - 188.179 -(defmethod writer BufferedWriter [^BufferedWriter x] 188.180 - (assert-not-appending) 188.181 - (PrintWriter. x)) 188.182 - 188.183 -(defmethod writer Writer [x] 188.184 - (assert-not-appending) 188.185 - ;; Writer includes sub-classes such as FileWriter 188.186 - (PrintWriter. (BufferedWriter. x))) 188.187 - 188.188 -(defmethod writer OutputStream [^OutputStream x] 188.189 - (assert-not-appending) 188.190 - (PrintWriter. 188.191 - (BufferedWriter. 188.192 - (OutputStreamWriter. x *default-encoding*)))) 188.193 - 188.194 -(defmethod writer File [^File x] 188.195 - (let [stream (FileOutputStream. x *append-to-writer*)] 188.196 - (binding [*append-to-writer* false] 188.197 - (writer stream)))) 188.198 - 188.199 -(defmethod writer URL [^URL x] 188.200 - (if (= "file" (.getProtocol x)) 188.201 - (writer (File. (.getPath x))) 188.202 - (throw (Exception. (str "Cannot write to non-file URL <" x ">"))))) 188.203 - 188.204 -(defmethod writer URI [^URI x] 188.205 - (writer (.toURL x))) 188.206 - 188.207 -(defmethod writer String [^String x] 188.208 - (try (let [url (URL. x)] 188.209 - (writer url)) 188.210 - (catch MalformedURLException err 188.211 - (writer (File. x))))) 188.212 - 188.213 -(defmethod writer Socket [^Socket x] 188.214 - (writer (.getOutputStream x))) 188.215 - 188.216 -(defmethod writer :default [x] 188.217 - (throw (Exception. (str "Cannot open <" (pr-str x) "> as a writer.")))) 188.218 - 188.219 - 188.220 -(defn append-writer 188.221 - "Like writer but opens file for appending. Does not work on streams 188.222 - that are already open." 188.223 - [x] 188.224 - (binding [*append-to-writer* true] 188.225 - (writer x))) 188.226 - 188.227 - 188.228 -(defn write-lines 188.229 - "Writes lines (a seq) to f, separated by newlines. f is opened with 188.230 - writer, and automatically closed at the end of the sequence." 188.231 - [f lines] 188.232 - (with-open [^PrintWriter writer (writer f)] 188.233 - (loop [lines lines] 188.234 - (when-let [line (first lines)] 188.235 - (.write writer (str line)) 188.236 - (.println writer) 188.237 - (recur (rest lines)))))) 188.238 - 188.239 -(defn read-lines 188.240 - "Like clojure.core/line-seq but opens f with reader. Automatically 188.241 - closes the reader AFTER YOU CONSUME THE ENTIRE SEQUENCE." 188.242 - [f] 188.243 - (let [read-line (fn this [^BufferedReader rdr] 188.244 - (lazy-seq 188.245 - (if-let [line (.readLine rdr)] 188.246 - (cons line (this rdr)) 188.247 - (.close rdr))))] 188.248 - (read-line (reader f)))) 188.249 - 188.250 -(defn ^String slurp* 188.251 - "Like clojure.core/slurp but opens f with reader." 188.252 - [f] 188.253 - (with-open [^BufferedReader r (reader f)] 188.254 - (let [sb (StringBuilder.)] 188.255 - (loop [c (.read r)] 188.256 - (if (neg? c) 188.257 - (str sb) 188.258 - (do (.append sb (char c)) 188.259 - (recur (.read r)))))))) 188.260 - 188.261 -(defn spit 188.262 - "Opposite of slurp. Opens f with writer, writes content, then 188.263 - closes f." 188.264 - [f content] 188.265 - (with-open [^PrintWriter w (writer f)] 188.266 - (.print w content))) 188.267 - 188.268 -(defn append-spit 188.269 - "Like spit but appends to file." 188.270 - [f content] 188.271 - (with-open [^PrintWriter w (append-writer f)] 188.272 - (.print w content))) 188.273 - 188.274 -(defn pwd 188.275 - "Returns current working directory as a String. (Like UNIX 'pwd'.) 188.276 - Note: In Java, you cannot change the current working directory." 188.277 - [] 188.278 - (System/getProperty "user.dir")) 188.279 - 188.280 - 188.281 - 188.282 -(defmacro with-out-writer 188.283 - "Opens a writer on f, binds it to *out*, and evalutes body. 188.284 - Anything printed within body will be written to f." 188.285 - [f & body] 188.286 - `(with-open [stream# (writer ~f)] 188.287 - (binding [*out* stream#] 188.288 - ~@body))) 188.289 - 188.290 -(defmacro with-out-append-writer 188.291 - "Like with-out-writer but appends to file." 188.292 - [f & body] 188.293 - `(with-open [stream# (append-writer ~f)] 188.294 - (binding [*out* stream#] 188.295 - ~@body))) 188.296 - 188.297 -(defmacro with-in-reader 188.298 - "Opens a PushbackReader on f, binds it to *in*, and evaluates body." 188.299 - [f & body] 188.300 - `(with-open [stream# (PushbackReader. (reader ~f))] 188.301 - (binding [*in* stream#] 188.302 - ~@body))) 188.303 - 188.304 -(defmulti 188.305 - ^{:doc "Copies input to output. Returns nil. 188.306 - Input may be an InputStream, Reader, File, byte[], or String. 188.307 - Output may be an OutputStream, Writer, or File. 188.308 - 188.309 - Does not close any streams except those it opens itself 188.310 - (on a File). 188.311 - 188.312 - Writing a File fails if the parent directory does not exist." 188.313 - :arglists '([input output])} 188.314 - copy 188.315 - (fn [input output] [(type input) (type output)])) 188.316 - 188.317 -(defmethod copy [InputStream OutputStream] [^InputStream input ^OutputStream output] 188.318 - (let [buffer (make-array Byte/TYPE *buffer-size*)] 188.319 - (loop [] 188.320 - (let [size (.read input buffer)] 188.321 - (when (pos? size) 188.322 - (do (.write output buffer 0 size) 188.323 - (recur))))))) 188.324 - 188.325 -(defmethod copy [InputStream Writer] [^InputStream input ^Writer output] 188.326 - (let [^"[B" buffer (make-array Byte/TYPE *buffer-size*)] 188.327 - (loop [] 188.328 - (let [size (.read input buffer)] 188.329 - (when (pos? size) 188.330 - (let [chars (.toCharArray (String. buffer 0 size *default-encoding*))] 188.331 - (do (.write output chars) 188.332 - (recur)))))))) 188.333 - 188.334 -(defmethod copy [InputStream File] [^InputStream input ^File output] 188.335 - (with-open [out (FileOutputStream. output)] 188.336 - (copy input out))) 188.337 - 188.338 -(defmethod copy [Reader OutputStream] [^Reader input ^OutputStream output] 188.339 - (let [^"[C" buffer (make-array Character/TYPE *buffer-size*)] 188.340 - (loop [] 188.341 - (let [size (.read input buffer)] 188.342 - (when (pos? size) 188.343 - (let [bytes (.getBytes (String. buffer 0 size) *default-encoding*)] 188.344 - (do (.write output bytes) 188.345 - (recur)))))))) 188.346 - 188.347 -(defmethod copy [Reader Writer] [^Reader input ^Writer output] 188.348 - (let [^"[C" buffer (make-array Character/TYPE *buffer-size*)] 188.349 - (loop [] 188.350 - (let [size (.read input buffer)] 188.351 - (when (pos? size) 188.352 - (do (.write output buffer 0 size) 188.353 - (recur))))))) 188.354 - 188.355 -(defmethod copy [Reader File] [^Reader input ^File output] 188.356 - (with-open [out (FileOutputStream. output)] 188.357 - (copy input out))) 188.358 - 188.359 -(defmethod copy [File OutputStream] [^File input ^OutputStream output] 188.360 - (with-open [in (FileInputStream. input)] 188.361 - (copy in output))) 188.362 - 188.363 -(defmethod copy [File Writer] [^File input ^Writer output] 188.364 - (with-open [in (FileInputStream. input)] 188.365 - (copy in output))) 188.366 - 188.367 -(defmethod copy [File File] [^File input ^File output] 188.368 - (with-open [in (FileInputStream. input) 188.369 - out (FileOutputStream. output)] 188.370 - (copy in out))) 188.371 - 188.372 -(defmethod copy [String OutputStream] [^String input ^OutputStream output] 188.373 - (copy (StringReader. input) output)) 188.374 - 188.375 -(defmethod copy [String Writer] [^String input ^Writer output] 188.376 - (copy (StringReader. input) output)) 188.377 - 188.378 -(defmethod copy [String File] [^String input ^File output] 188.379 - (copy (StringReader. input) output)) 188.380 - 188.381 -(defmethod copy [*byte-array-type* OutputStream] [^"[B" input ^OutputStream output] 188.382 - (copy (ByteArrayInputStream. input) output)) 188.383 - 188.384 -(defmethod copy [*byte-array-type* Writer] [^"[B" input ^Writer output] 188.385 - (copy (ByteArrayInputStream. input) output)) 188.386 - 188.387 -(defmethod copy [*byte-array-type* File] [^"[B" input ^Writer output] 188.388 - (copy (ByteArrayInputStream. input) output)) 188.389 - 188.390 - 188.391 -(defn make-parents 188.392 - "Creates all parent directories of file." 188.393 - [^File file] 188.394 - (.mkdirs (.getParentFile file))) 188.395 - 188.396 -(defmulti 188.397 - ^{:doc "Converts argument into a Java byte array. Argument may be 188.398 - a String, File, InputStream, or Reader. If the argument is already 188.399 - a byte array, returns it." 188.400 - :arglists '([arg])} 188.401 - to-byte-array type) 188.402 - 188.403 -(defmethod to-byte-array *byte-array-type* [x] x) 188.404 - 188.405 -(defmethod to-byte-array String [^String x] 188.406 - (.getBytes x *default-encoding*)) 188.407 - 188.408 -(defmethod to-byte-array File [^File x] 188.409 - (with-open [input (FileInputStream. x) 188.410 - buffer (ByteArrayOutputStream.)] 188.411 - (copy input buffer) 188.412 - (.toByteArray buffer))) 188.413 - 188.414 -(defmethod to-byte-array InputStream [^InputStream x] 188.415 - (let [buffer (ByteArrayOutputStream.)] 188.416 - (copy x buffer) 188.417 - (.toByteArray buffer))) 188.418 - 188.419 -(defmethod to-byte-array Reader [^Reader x] 188.420 - (.getBytes (slurp* x) *default-encoding*)) 188.421 -
189.1 --- a/src/clojure/contrib/error_kit.clj Sat Aug 21 06:25:44 2010 -0400 189.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 189.3 @@ -1,289 +0,0 @@ 189.4 -; Copyright (c) Chris Houser, Jan 2009. All rights reserved. 189.5 -; The use and distribution terms for this software are covered by the 189.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 189.7 -; which can be found in the file epl-v10.html at the root of this distribution. 189.8 -; By using this software in any fashion, you are agreeing to be bound by 189.9 -; the terms of this license. 189.10 -; You must not remove this notice, or any other, from this software. 189.11 - 189.12 -; == EXPERIMENTAL == 189.13 -; System for defining and using custom errors 189.14 -; Please contact Chouser if you have any suggestions for better names 189.15 -; or API adjustments. 189.16 - 189.17 -(ns 189.18 - ^{:author "Chris Houser", 189.19 - :doc "EXPERIMENTAL 189.20 -System for defining and using custom errors 189.21 -Please contact Chouser if you have any suggestions for better names 189.22 -or API adjustments."} 189.23 - clojure.contrib.error-kit 189.24 - (:use [clojure.contrib.def :only (defvar defvar-)] 189.25 - [clojure.stacktrace :only (root-cause)])) 189.26 - 189.27 -(defn- make-ctrl-exception [msg data] 189.28 - "Create an exception object with associated data, used for passing 189.29 - control and data to a dynamically containing handler." 189.30 - (proxy [Error clojure.lang.IDeref] [msg] 189.31 - (toString [] (str "Error Kit Control Exception: " msg ", " (pr-str data))) 189.32 - (deref [] data))) 189.33 - 189.34 -(defvar- ctrl-exception-class 189.35 - (class (make-ctrl-exception nil nil))) 189.36 - 189.37 -(defvar- *handler-stack* () "Stack of bound handler symbols") 189.38 - 189.39 -(defvar- *continues* {} "Map of currently available continue forms") 189.40 - 189.41 - 189.42 -(defmacro throw-msg 189.43 - "Returns a function that throws a Java Exception with the given 189.44 - name. Useful to associate a new error-kit error type with a 189.45 - particular Java Exception class, via the :unhandled error key." 189.46 - [class-name] 189.47 - `(fn [x#] (throw (new ~class-name (:msg x#))))) 189.48 - 189.49 -(defn error 189.50 - "Base type for all error-kit errors" 189.51 - {::args [:msg :unhandled :tag]} 189.52 - [details] 189.53 - (merge {:tag `error :msg "exception via error-kit" 189.54 - :unhandled (throw-msg Exception)} 189.55 - details)) 189.56 - 189.57 -(defn- qualify-sym [sym] 189.58 - (let [v (resolve sym)] 189.59 - (assert v) 189.60 - (apply symbol (map #(str (% (meta v))) [:ns :name])))) 189.61 - 189.62 -(defmacro deferror 189.63 - "Define a new error type" 189.64 - {:arglists '([name [parent-error?] doc-string? [args*] & body] 189.65 - [name [parent-error?] doc-string? args-destruct-map & body])} 189.66 - [err-name pvec & decl] 189.67 - (let [pvec (if (empty? pvec) [`error] pvec) 189.68 - [docstr args & body] (if (string? (first decl)) decl (cons nil decl)) 189.69 - args (or args []) 189.70 - argmap (if (vector? args) `{:keys ~args} args) 189.71 - body (or body {}) 189.72 - qual-err-name (symbol (str *ns*) (name err-name))] 189.73 - (assert (== (count pvec) 1)) ; only support single-inheritance for now 189.74 - (assert (vector? args)) ; only vector (keyword destruct) args for now 189.75 - `(do 189.76 - (defn ~err-name [details#] 189.77 - (let [basedata# ((resolve (first (parents '~qual-err-name))) details#) 189.78 - ~argmap basedata#] 189.79 - (merge basedata# {:tag '~qual-err-name} (do ~@body) details#))) 189.80 - (alter-meta! (var ~err-name) assoc 189.81 - :doc ~docstr ::args ~(vec (map #(keyword (str %)) args))) 189.82 - ~@(for [parent pvec] 189.83 - `(derive '~qual-err-name '~(qualify-sym parent))) 189.84 - (var ~err-name)))) 189.85 - 189.86 -(defn- throw-to [msg target-map args] 189.87 - (throw (make-ctrl-exception msg (assoc target-map :args args)))) 189.88 - 189.89 -(defn raise* 189.90 - "Raise the given error object, best if created by an error 189.91 - constructor defined with deferror. See also 'raise' macro." 189.92 - [err] 189.93 - (let [err-tag (:tag err)] 189.94 - (loop [hs *handler-stack*] 189.95 - (if (empty? hs) 189.96 - ((:unhandled err) err) 189.97 - (let [[{:keys [htag] :as handler}] hs] 189.98 - (if (and htag (not (isa? err-tag htag))) 189.99 - (recur (next hs)) 189.100 - (let [rtn ((:hfunc handler) err)] 189.101 - (if-not (vector? rtn) 189.102 - (throw-to "default" handler (list rtn)) 189.103 - (condp = (rtn 0) 189.104 - ::continue-with (rtn 1) 189.105 - ::continue (if-let [continue (*continues* (rtn 1))] 189.106 - (throw-to "continue" continue (rtn 2)) 189.107 - (do (prn *continues*) (throw 189.108 - (Exception. 189.109 - (str "Unbound continue name " (rtn 1)))))) 189.110 - ::do-not-handle (recur (next hs)) 189.111 - (throw-to "do-not-handle" handler (list rtn))))))))))) 189.112 - 189.113 -(defmacro raise 189.114 - "Raise an error of the type err-name, constructed with the given args" 189.115 - [err-name & args] 189.116 - `(raise* (~err-name ~(zipmap (::args (meta (resolve err-name))) 189.117 - args)))) 189.118 - 189.119 -; It'd be nice to assert that these are used in a tail position of a handler 189.120 -(defmacro do-not-handle 189.121 - "Use in a tail position of a 'handle' form to indicate 'raise' should 189.122 - not consider the error handled, but should continue searching for an 189.123 - appropriate 'handle' form. Allows finer-grain control over catching 189.124 - than just the error type." 189.125 - [] 189.126 - `[::do-not-handle]) 189.127 - 189.128 -(defmacro continue-with [value] 189.129 - "Use in a tail position of a 'handle' form to cause the currently 189.130 - running 'raise' to return the given 'value'." 189.131 - `[::continue-with ~value]) 189.132 - 189.133 -(defmacro continue [continue-name & args] 189.134 - "Use in a tail position of a 'handle' form to pass control to the 189.135 - named 'continue' form, passing in the given args. The 'continue' 189.136 - form with the given name and the smallest dynamic scope surrounding 189.137 - the currently running 'raise' will be used." 189.138 - `[::continue '~continue-name [~@args]]) 189.139 - 189.140 - 189.141 -(def ^{:doc "Special form to be used inside a 'with-handler'. When 189.142 - any error is 'raised' from withing the dynamic scope of 'body' that 189.143 - is of error-name's type or a derived type, the args will be bound 189.144 - and the body executed. If no 'error-name' is given, the body will 189.145 - be executed for regardless of the type of error raised. The body 189.146 - may return a value, in which case that will be the return value of 189.147 - the entire 'with-handler' form, or it may use any of the special 189.148 - return forms, 'do-not-handle', 'continue-with', or 'continue'." 189.149 - :arglists '([error-name? [args*] & body] 189.150 - [error-name? args-destruct-map-args & body])} 189.151 - handle) 189.152 - 189.153 -(def ^{:doc "Special form to be used inside a 'with-handler'. 189.154 - Control can be passed to this 'continue' form from a 'raise' enclosed 189.155 - in this with-handler's dynamic scope, when this 'continue-name' is 189.156 - given to a 'continue' form." 189.157 - :arglists '([continue-name [args*] & body])} 189.158 - bind-continue) 189.159 - 189.160 -(defn- special-form [form] 189.161 - (and (list form) 189.162 - (symbol? (first form)) 189.163 - (#{#'handle #'bind-continue} (resolve (first form))))) 189.164 - 189.165 - 189.166 -(defmacro with-handler 189.167 - "This is error-kit's dynamic scope form. The body will be executed 189.168 - in a dynamic context that includes all of the following 'handle' and 189.169 - 'bind-continue' forms." 189.170 - [& forms] 189.171 - (let [[body special-forms] (split-with (complement special-form) forms)] 189.172 - (assert (every? special-form special-forms)) 189.173 - (let [blockid (gensym) 189.174 - handlers (for [[type & more] special-forms 189.175 - :when (= (resolve type) #'handle)] 189.176 - (let [[htag args & hbody] (if (symbol? (first more)) 189.177 - more 189.178 - (cons nil more)) 189.179 - argmap (if (vector? args) `{:keys ~args} args)] 189.180 - `{:blockid '~blockid 189.181 - :htag ~(when htag (list `quote (qualify-sym htag))) 189.182 - :hfunc (fn [~argmap] ~@hbody) 189.183 - :rfunc identity})) 189.184 - continues (into {} 189.185 - (for [[type & more] special-forms 189.186 - :when (= (resolve type) #'bind-continue)] 189.187 - [(list `quote (first more)) 189.188 - `{:blockid '~blockid 189.189 - :rfunc (fn ~@(next more))}]))] 189.190 - `(try 189.191 - (binding [*handler-stack* (list* ~@handlers @#'*handler-stack*) 189.192 - *continues* (merge @#'*continues* ~@continues)] 189.193 - ~@body) 189.194 - (catch Throwable e# 189.195 - (let [root-cause# (root-cause e#)] 189.196 - (if-not (instance? @#'ctrl-exception-class root-cause#) 189.197 - (throw e#) 189.198 - (let [data# @root-cause#] 189.199 - (if (= '~blockid (:blockid data#)) 189.200 - (apply (:rfunc data#) (:args data#)) 189.201 - (throw e#)))))))))) 189.202 - 189.203 -(defn rebind-fn [func] 189.204 - (let [a *handler-stack*, b *continues*] 189.205 - (fn [& args] 189.206 - (binding [*handler-stack* a 189.207 - *continues* b] 189.208 - (apply func args))))) 189.209 - 189.210 -(comment 189.211 - 189.212 -(alias 'kit 'clojure.contrib.error-kit) 189.213 - 189.214 -; This defines an error and its action if unhandled. A good choice of 189.215 -; unhandled. action is to throw a Java exception so users of your code 189.216 -; who do not want to use error-kit can still use normal Java try/catch 189.217 -; forms to handle the error. 189.218 -(kit/deferror number-error [] [n] 189.219 - {:msg (str "Number error: " n) 189.220 - :unhandled (kit/throw-msg NumberFormatException)}) 189.221 - 189.222 -(kit/deferror odd-number-error [number-error] 189.223 - "Indicates an odd number was given to an operation that is only 189.224 - defined for even numbers." 189.225 - [n] 189.226 - {:msg (str "Can't handle odd number: " n)}) 189.227 - 189.228 -; Raise an error by name with any extra args defined by the deferror 189.229 -(defn int-half [i] 189.230 - (if (even? i) 189.231 - (quot i 2) 189.232 - (kit/raise odd-number-error i))) 189.233 - 189.234 -; Throws Java NumberFormatException because there's no 'handle' form 189.235 -(vec (map int-half [2 4 5 8])) 189.236 - 189.237 -; Throws Java Exception with details provided by 'raise' 189.238 -(kit/with-handler 189.239 - (vec (map int-half [2 4 5 8])) 189.240 - (kit/handle odd-number-error [n] 189.241 - (throw (Exception. (format "Odd number %d in vector." n))))) 189.242 - 189.243 -; The above is equivalent to the more complicated version below: 189.244 -(kit/with-handler 189.245 - (vec (map int-half [2 4 5 8])) 189.246 - (kit/handle {:keys [n tag]} 189.247 - (if (isa? tag `odd-number-error) 189.248 - (throw (Exception. (format "Odd number %d in vector." n))) 189.249 - (kit/do-not-handle)))) 189.250 - 189.251 -; Returns "invalid" string instead of a vector when an error is encountered 189.252 -(kit/with-handler 189.253 - (vec (map int-half [2 4 5 8])) 189.254 - (kit/handle kit/error [n] 189.255 - "invalid")) 189.256 - 189.257 -; Inserts a zero into the returned vector where there was an error, in 189.258 -; this case [1 2 0 4] 189.259 -(kit/with-handler 189.260 - (vec (map int-half [2 4 5 8])) 189.261 - (kit/handle number-error [n] 189.262 - (kit/continue-with 0))) 189.263 - 189.264 -; Intermediate continue: [1 2 :oops 5 4] 189.265 -(defn int-half-vec [s] 189.266 - (reduce (fn [v i] 189.267 - (kit/with-handler 189.268 - (conj v (int-half i)) 189.269 - (kit/bind-continue instead-of-half [& instead-seq] 189.270 - (apply conj v instead-seq)))) 189.271 - [] s)) 189.272 - 189.273 -(kit/with-handler 189.274 - (int-half-vec [2 4 5 8]) 189.275 - (kit/handle number-error [n] 189.276 - (kit/continue instead-of-half :oops n))) 189.277 - 189.278 -; Notes: 189.279 - 189.280 -; It seems likely you'd want to convert a handle clause to 189.281 -; bind-continue, since it would allow higher forms to request what you 189.282 -; used to do by default. Thus both should appear in the same 189.283 -; with-handler form 189.284 - 189.285 -; Should continue-names be namespace qualified, and therefore require 189.286 -; pre-definition in some namespace? 189.287 -; (kit/defcontinue skip-thing "docstring") 189.288 - 189.289 -; Could add 'catch' for Java Exceptions and 'finally' support to 189.290 -; with-handler forms. 189.291 - 189.292 -)
190.1 --- a/src/clojure/contrib/except.clj Sat Aug 21 06:25:44 2010 -0400 190.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 190.3 @@ -1,95 +0,0 @@ 190.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 190.5 -;; distribution terms for this software are covered by the Eclipse Public 190.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 190.7 -;; be found in the file epl-v10.html at the root of this distribution. By 190.8 -;; using this software in any fashion, you are agreeing to be bound by the 190.9 -;; terms of this license. You must not remove this notice, or any other, 190.10 -;; from this software. 190.11 -;; 190.12 -;; except.clj 190.13 -;; 190.14 -;; Provides functions that make it easy to specify the class, cause, and 190.15 -;; message when throwing an Exception or Error. The optional message is 190.16 -;; formatted using clojure.core/format. 190.17 -;; 190.18 -;; scgilardi (gmail) 190.19 -;; Created 07 July 2008 190.20 - 190.21 -(ns 190.22 - ^{:author "Stephen C. Gilardi", 190.23 - :doc "Provides functions that make it easy to specify the class, cause, and 190.24 -message when throwing an Exception or Error. The optional message is 190.25 -formatted using clojure.core/format."} 190.26 - clojure.contrib.except 190.27 - (:import (clojure.lang Reflector))) 190.28 - 190.29 -(declare throwable) 190.30 - 190.31 -(defn throwf 190.32 - "Throws an Exception or Error with an optional message formatted using 190.33 - clojure.core/format. All arguments are optional: 190.34 - 190.35 - class? cause? format? format-args* 190.36 - 190.37 - - class defaults to Exception, if present it must name a kind of 190.38 - Throwable 190.39 - - cause defaults to nil, if present it must be a Throwable 190.40 - - format is a format string for clojure.core/format 190.41 - - format-args are objects that correspond to format specifiers in 190.42 - format." 190.43 - [& args] 190.44 - (throw (throwable args))) 190.45 - 190.46 -(defn throw-if 190.47 - "Throws an Exception or Error if test is true. args are those documented 190.48 - for throwf." 190.49 - [test & args] 190.50 - (when test 190.51 - (throw (throwable args)))) 190.52 - 190.53 -(defn throw-if-not 190.54 - "Throws an Exception or Error if test is false. args are those documented 190.55 - for throwf." 190.56 - [test & args] 190.57 - (when-not test 190.58 - (throw (throwable args)))) 190.59 - 190.60 -(defn throw-arg 190.61 - "Throws an IllegalArgumentException. All arguments are optional: 190.62 - 190.63 - cause? format? format-args* 190.64 - 190.65 - - cause defaults to nil, if present it must be a Throwable 190.66 - - format is a format string for clojure.core/format 190.67 - - format-args are objects that correspond to format specifiers in 190.68 - format." 190.69 - [& args] 190.70 - (throw (throwable (cons IllegalArgumentException args)))) 190.71 - 190.72 -(defn- throwable? 190.73 - "Returns true if x is a Throwable" 190.74 - [x] 190.75 - (instance? Throwable x)) 190.76 - 190.77 -(defn- throwable 190.78 - "Constructs a Throwable with optional cause and formatted message. Its 190.79 - stack trace will begin with our caller's caller. Args are as described 190.80 - for throwf except throwable accepts them as list rather than inline." 190.81 - [args] 190.82 - (let [[arg] args 190.83 - [class & args] (if (class? arg) args (cons Exception args)) 190.84 - [arg] args 190.85 - [cause & args] (if (throwable? arg) args (cons nil args)) 190.86 - message (when args (apply format args)) 190.87 - ctor-args (into-array Object 190.88 - (cond (and message cause) [message cause] 190.89 - message [message] 190.90 - cause [cause])) 190.91 - throwable (Reflector/invokeConstructor class ctor-args) 190.92 - our-prefix "clojure.contrib.except$throwable" 190.93 - not-us? #(not (.startsWith (.getClassName %) our-prefix)) 190.94 - raw-trace (.getStackTrace throwable) 190.95 - edited-trace (into-array StackTraceElement 190.96 - (drop 3 (drop-while not-us? raw-trace)))] 190.97 - (.setStackTrace throwable edited-trace) 190.98 - throwable))
191.1 --- a/src/clojure/contrib/fcase.clj Sat Aug 21 06:25:44 2010 -0400 191.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 191.3 @@ -1,108 +0,0 @@ 191.4 -;;; fcase.clj -- simple variants of "case" for Clojure 191.5 - 191.6 -;; by Stuart Sierra, http://stuartsierra.com/ 191.7 -;; April 7, 2008 191.8 - 191.9 -;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use 191.10 -;; and distribution terms for this software are covered by the Eclipse 191.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 191.12 -;; which can be found in the file epl-v10.html at the root of this 191.13 -;; distribution. By using this software in any fashion, you are 191.14 -;; agreeing to be bound by the terms of this license. You must not 191.15 -;; remove this notice, or any other, from this software. 191.16 - 191.17 - 191.18 -;; This file defines a generic "case" macro called "fcase" which takes 191.19 -;; the equality-testing function as an argument. It also defines a 191.20 -;; traditional "case" macro that tests using "=" and variants that 191.21 -;; test for regular expressions and class membership. 191.22 - 191.23 - 191.24 -;; Note (December 23, 2008): This library has been supplanted by the 191.25 -;; inclusion of "condp" in clojure.core as of Clojure SVN rev. 1180. 191.26 - 191.27 - 191.28 -(ns 191.29 - ^{:author "Stuart Sierra", 191.30 - :doc "This file defines a generic \"case\" macro called \"fcase\" which takes 191.31 -the equality-testing function as an argument. It also defines a 191.32 -traditional \"case\" macro that tests using \"=\" and variants that 191.33 -test for regular expressions and class membership. 191.34 - 191.35 - 191.36 -Note (December 23, 2008): This library has been supplanted by the 191.37 -inclusion of \"condp\" in clojure.core as of Clojure SVN rev. 1180."} 191.38 - 191.39 - clojure.contrib.fcase 191.40 - (:refer-clojure :exclude (case))) 191.41 - 191.42 - 191.43 -(defmacro fcase 191.44 - "Generic switch/case macro. 'fcase' is short for 'function case'. 191.45 - 191.46 - The 'compare-fn' is a fn of two arguments. 191.47 - 191.48 - The 'test-expr-clauses' are value-expression pairs without 191.49 - surrounding parentheses, like in Clojure's 'cond'. 191.50 - 191.51 - The 'case-value' is evaluated once and cached. Then, 'compare-fn' 191.52 - is called once for each clause, with the clause's test value as its 191.53 - first argument and 'case-value' as its second argument. If 191.54 - 'compare-fn' returns logical true, the clause's expression is 191.55 - evaluated and returned. If 'compare-fn' returns false/nil, we go to 191.56 - the next test value. 191.57 - 191.58 - If 'test-expr-clauses' contains an odd number of items, the last 191.59 - item is the default expression evaluated if no case-value matches. 191.60 - If there is no default expression and no case-value matches, fcase 191.61 - returns nil. 191.62 - 191.63 - See specific forms of this macro in 'case' and 're-case'. 191.64 - 191.65 - The test expressions in 'fcase' are always evaluated linearly, in 191.66 - order. For a large number of case expressions it may be more 191.67 - efficient to use a hash lookup." 191.68 - [compare-fn case-value & 191.69 - test-expr-clauses] 191.70 - (let [test-val-sym (gensym "test_val") 191.71 - test-fn-sym (gensym "test_fn") 191.72 - cond-loop (fn this [clauses] 191.73 - (cond 191.74 - (>= (count clauses) 2) 191.75 - (list 'if (list test-fn-sym (first clauses) test-val-sym) 191.76 - (second clauses) 191.77 - (this (rest (rest clauses)))) 191.78 - (= (count clauses) 1) (first clauses)))] 191.79 - (list 'let [test-val-sym case-value, test-fn-sym compare-fn] 191.80 - (cond-loop test-expr-clauses)))) 191.81 - 191.82 -(defmacro case 191.83 - "Like cond, but test-value is compared against the value of each 191.84 - test expression with =. If they are equal, executes the \"body\" 191.85 - expression. Optional last expression is executed if none of the 191.86 - test expressions match." 191.87 - [test-value & clauses] 191.88 - `(fcase = ~test-value ~@clauses)) 191.89 - 191.90 -(defmacro re-case 191.91 - "Like case, but the test expressions are regular expressions, tested 191.92 - with re-find." 191.93 - [test-value & clauses] 191.94 - `(fcase re-find ~test-value ~@clauses)) 191.95 - 191.96 -(defmacro instance-case 191.97 - "Like case, but the test expressions are Java class names, tested with 191.98 - 'instance?'." 191.99 - [test-value & clauses] 191.100 - `(fcase instance? ~test-value ~@clauses)) 191.101 - 191.102 -(defn in-case-test [test-seq case-value] 191.103 - (some (fn [item] (= item case-value)) 191.104 - test-seq)) 191.105 - 191.106 -(defmacro in-case 191.107 - "Like case, but test expressions are sequences. The test expression 191.108 - is true if any item in the sequence is equal (tested with '=') to 191.109 - the test value." 191.110 - [test-value & clauses] 191.111 - `(fcase in-case-test ~test-value ~@clauses))
192.1 --- a/src/clojure/contrib/find_namespaces.clj Sat Aug 21 06:25:44 2010 -0400 192.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 192.3 @@ -1,136 +0,0 @@ 192.4 -;;; find_namespaces.clj: search for ns declarations in dirs, JARs, or CLASSPATH 192.5 - 192.6 -;; by Stuart Sierra, http://stuartsierra.com/ 192.7 -;; April 19, 2009 192.8 - 192.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 192.10 -;; and distribution terms for this software are covered by the Eclipse 192.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 192.12 -;; which can be found in the file epl-v10.html at the root of this 192.13 -;; distribution. By using this software in any fashion, you are 192.14 -;; agreeing to be bound by the terms of this license. You must not 192.15 -;; remove this notice, or any other, from this software. 192.16 - 192.17 - 192.18 -(ns 192.19 - ^{:author "Stuart Sierra", 192.20 - :doc "Search for ns declarations in dirs, JARs, or CLASSPATH"} 192.21 - clojure.contrib.find-namespaces 192.22 - (:require [clojure.contrib.classpath :as cp] 192.23 - [clojure.contrib.jar :as jar]) 192.24 - (import (java.io File FileReader BufferedReader PushbackReader 192.25 - InputStreamReader) 192.26 - (java.util.jar JarFile))) 192.27 - 192.28 - 192.29 -;;; Finding namespaces in a directory tree 192.30 - 192.31 -(defn clojure-source-file? 192.32 - "Returns true if file is a normal file with a .clj extension." 192.33 - [^File file] 192.34 - (and (.isFile file) 192.35 - (.endsWith (.getName file) ".clj"))) 192.36 - 192.37 -(defn find-clojure-sources-in-dir 192.38 - "Searches recursively under dir for Clojure source files (.clj). 192.39 - Returns a sequence of File objects, in breadth-first sort order." 192.40 - [^File dir] 192.41 - ;; Use sort by absolute path to get breadth-first search. 192.42 - (sort-by #(.getAbsolutePath %) 192.43 - (filter clojure-source-file? (file-seq dir)))) 192.44 - 192.45 -(defn comment? 192.46 - "Returns true if form is a (comment ...)" 192.47 - [form] 192.48 - (and (list? form) (= 'comment (first form)))) 192.49 - 192.50 -(defn ns-decl? 192.51 - "Returns true if form is a (ns ...) declaration." 192.52 - [form] 192.53 - (and (list? form) (= 'ns (first form)))) 192.54 - 192.55 -(defn read-ns-decl 192.56 - "Attempts to read a (ns ...) declaration from rdr, and returns the 192.57 - unevaluated form. Returns nil if read fails or if a ns declaration 192.58 - cannot be found. The ns declaration must be the first Clojure form 192.59 - in the file, except for (comment ...) forms." 192.60 - [^PushbackReader rdr] 192.61 - (try (let [form (read rdr)] 192.62 - (cond 192.63 - (ns-decl? form) form 192.64 - (comment? form) (recur rdr) 192.65 - :else nil)) 192.66 - (catch Exception e nil))) 192.67 - 192.68 -(defn read-file-ns-decl 192.69 - "Attempts to read a (ns ...) declaration from file, and returns the 192.70 - unevaluated form. Returns nil if read fails, or if the first form 192.71 - is not a ns declaration." 192.72 - [^File file] 192.73 - (with-open [rdr (PushbackReader. (BufferedReader. (FileReader. file)))] 192.74 - (read-ns-decl rdr))) 192.75 - 192.76 -(defn find-ns-decls-in-dir 192.77 - "Searches dir recursively for (ns ...) declarations in Clojure 192.78 - source files; returns the unevaluated ns declarations." 192.79 - [^File dir] 192.80 - (filter identity (map read-file-ns-decl (find-clojure-sources-in-dir dir)))) 192.81 - 192.82 -(defn find-namespaces-in-dir 192.83 - "Searches dir recursively for (ns ...) declarations in Clojure 192.84 - source files; returns the symbol names of the declared namespaces." 192.85 - [^File dir] 192.86 - (map second (find-ns-decls-in-dir dir))) 192.87 - 192.88 - 192.89 -;;; Finding namespaces in JAR files 192.90 - 192.91 -(defn clojure-sources-in-jar 192.92 - "Returns a sequence of filenames ending in .clj found in the JAR file." 192.93 - [^JarFile jar-file] 192.94 - (filter #(.endsWith % ".clj") (jar/filenames-in-jar jar-file))) 192.95 - 192.96 -(defn read-ns-decl-from-jarfile-entry 192.97 - "Attempts to read a (ns ...) declaration from the named entry in the 192.98 - JAR file, and returns the unevaluated form. Returns nil if the read 192.99 - fails, or if the first form is not a ns declaration." 192.100 - [^JarFile jarfile ^String entry-name] 192.101 - (with-open [rdr (PushbackReader. 192.102 - (BufferedReader. 192.103 - (InputStreamReader. 192.104 - (.getInputStream jarfile (.getEntry jarfile entry-name)))))] 192.105 - (read-ns-decl rdr))) 192.106 - 192.107 -(defn find-ns-decls-in-jarfile 192.108 - "Searches the JAR file for Clojure source files containing (ns ...) 192.109 - declarations; returns the unevaluated ns declarations." 192.110 - [^JarFile jarfile] 192.111 - (filter identity 192.112 - (map #(read-ns-decl-from-jarfile-entry jarfile %) 192.113 - (clojure-sources-in-jar jarfile)))) 192.114 - 192.115 -(defn find-namespaces-in-jarfile 192.116 - "Searches the JAR file for Clojure source files containing (ns ...) 192.117 - declarations. Returns a sequence of the symbol names of the 192.118 - declared namespaces." 192.119 - [^JarFile jarfile] 192.120 - (map second (find-ns-decls-in-jarfile jarfile))) 192.121 - 192.122 - 192.123 -;;; Finding namespaces anywhere on CLASSPATH 192.124 - 192.125 -(defn find-ns-decls-on-classpath 192.126 - "Searches CLASSPATH (both directories and JAR files) for Clojure 192.127 - source files containing (ns ...) declarations. Returns a sequence 192.128 - of the unevaluated ns declaration forms." 192.129 - [] 192.130 - (concat 192.131 - (mapcat find-ns-decls-in-dir (cp/classpath-directories)) 192.132 - (mapcat find-ns-decls-in-jarfile (cp/classpath-jarfiles)))) 192.133 - 192.134 -(defn find-namespaces-on-classpath 192.135 - "Searches CLASSPATH (both directories and JAR files) for Clojure 192.136 - source files containing (ns ...) declarations. Returns a sequence 192.137 - of the symbol names of the declared namespaces." 192.138 - [] 192.139 - (map second (find-ns-decls-on-classpath)))
193.1 --- a/src/clojure/contrib/fnmap.clj Sat Aug 21 06:25:44 2010 -0400 193.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 193.3 @@ -1,36 +0,0 @@ 193.4 -;;; fnmap.clj: maps that dispatch get/assoc to functions 193.5 - 193.6 -;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use 193.7 -;; and distribution terms for this software are covered by the Eclipse 193.8 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 193.9 -;; which can be found in the file epl-v10.html at the root of this 193.10 -;; distribution. By using this software in any fashion, you are 193.11 -;; agreeing to be bound by the terms of this license. You must not 193.12 -;; remove this notice, or any other, from this software. 193.13 - 193.14 - 193.15 -(ns ^{:author "Stuart Sierra" 193.16 - :doc "Maps that dispatch get/assoc to user-defined functions. 193.17 - 193.18 - Note: requires AOT-compilation"} 193.19 - clojure.contrib.fnmap 193.20 - (:require clojure.contrib.fnmap.PersistentFnMap)) 193.21 - 193.22 -(defn fnmap 193.23 - "Creates a fnmap, or functional map. A fnmap behaves like an 193.24 - ordinary Clojure map, except that calls to get and assoc are 193.25 - filtered through user-defined getter and setter functions, which 193.26 - operate on an internal map. 193.27 - 193.28 - (getter m key) should return a value for key. 193.29 - 193.30 - (setter m key value) should assoc key with value and return a new 193.31 - map for m. 193.32 - 193.33 - All other map operations are passed through to the internal map." 193.34 - ([getter setter] (clojure.contrib.fnmap.PersistentFnMap/create getter setter)) 193.35 - ([getter setter & keyvals] 193.36 - (apply assoc 193.37 - (clojure.contrib.fnmap.PersistentFnMap/create getter setter) 193.38 - keyvals))) 193.39 -
194.1 --- a/src/clojure/contrib/fnmap/PersistentFnMap.clj Sat Aug 21 06:25:44 2010 -0400 194.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 194.3 @@ -1,70 +0,0 @@ 194.4 -;; PersistentFnMap.clj: implementation for clojure.contrib.fnmap 194.5 - 194.6 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 194.7 -;; and distribution terms for this software are covered by the Eclipse 194.8 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 194.9 -;; which can be found in the file epl-v10.html at the root of this 194.10 -;; distribution. By using this software in any fashion, you are 194.11 -;; agreeing to be bound by the terms of this license. You must not 194.12 -;; remove this notice, or any other, from this software. 194.13 - 194.14 - 194.15 -;; Thanks to Meikel Brandmeyer for his work on lazymap, which made 194.16 -;; this implementation easier. 194.17 - 194.18 - 194.19 -(ns clojure.contrib.fnmap.PersistentFnMap 194.20 - (:gen-class :extends clojure.lang.APersistentMap 194.21 - :state state 194.22 - :init init 194.23 - :constructors {[clojure.lang.IPersistentMap] [], 194.24 - [clojure.lang.IPersistentMap clojure.lang.IPersistentMap] [clojure.lang.IPersistentMap]})) 194.25 - 194.26 -(defn -init 194.27 - ([theMap] [[] theMap]) 194.28 - ([theMap metadata] [[metadata] theMap])) 194.29 - 194.30 -(defn create [getter setter] 194.31 - (clojure.contrib.fnmap.PersistentFnMap. 194.32 - {::getter getter ::setter setter})) 194.33 - 194.34 -;; IPersistentMap 194.35 - 194.36 -(defn -assoc [this key value] 194.37 - (clojure.contrib.fnmap.PersistentFnMap. 194.38 - ((::setter (. this state)) (. this state) key value))) 194.39 - 194.40 -;; Associative 194.41 - 194.42 -(defn- -containsKey [this key] 194.43 - (not (nil? ((::getter (. this state)) this key)))) 194.44 - 194.45 -(defn- -entryAt [this key] 194.46 - (clojure.lang.MapEntry. key ((::getter (. this state)) (. this state) key))) 194.47 - 194.48 -(defn -valAt 194.49 - ([this key] 194.50 - ((::getter (. this state)) (. this state) key)) 194.51 - ([this key default] 194.52 - (or ((::getter (. this state)) (. this state) key) 194.53 - default))) 194.54 - 194.55 -;; Iterable 194.56 - 194.57 -(defn -iterator [this] 194.58 - (.. this state iterator)) 194.59 - 194.60 -;; IPersistentCollection 194.61 - 194.62 -(defn -count [this] 194.63 - (count (. this state))) 194.64 - 194.65 -(defn -seq [this] 194.66 - (seq (. this state))) 194.67 - 194.68 -(defn -cons [this that] 194.69 - (.. this state (cons this that))) 194.70 - 194.71 -(defn -empty [this] 194.72 - (.. this state empty)) 194.73 -
195.1 --- a/src/clojure/contrib/gen_html_docs.clj Sat Aug 21 06:25:44 2010 -0400 195.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 195.3 @@ -1,540 +0,0 @@ 195.4 -;;; gen-html-docs.clj: Generate HTML documentation for Clojure libs 195.5 - 195.6 -;; by Craig Andera, http://pluralsight.com/craig, candera@wangdera.com 195.7 -;; February 13th, 2009 195.8 - 195.9 -;; Copyright (c) Craig Andera, 2009. All rights reserved. The use 195.10 -;; and distribution terms for this software are covered by the Eclipse 195.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 195.12 -;; which can be found in the file epl-v10.html at the root of this 195.13 -;; distribution. By using this software in any fashion, you are 195.14 -;; agreeing to be bound by the terms of this license. You must not 195.15 -;; remove this notice, or any other, from this software. 195.16 - 195.17 -;; Generates a single HTML page that contains the documentation for 195.18 -;; one or more Clojure libraries. See the comments section at the end 195.19 -;; of this file for usage. 195.20 - 195.21 -;; TODO 195.22 -;; 195.23 -;; * Make symbols in the source hyperlinks to the appropriate section 195.24 -;; of the documentation. 195.25 -;; * Investigate issue with miglayout mentioned here: 195.26 -;; http://groups.google.com/group/clojure/browse_thread/thread/5a0c4395e44f5a79/3ae483100366bd3d?lnk=gst&q=documentation+browser#3ae483100366bd3d 195.27 -;; 195.28 -;; DONE 195.29 -;; 195.30 -;; * Move to clojure.contrib 195.31 -;; * Change namespace 195.32 -;; * Change license as appropriate 195.33 -;; * Double-check doc strings 195.34 -;; * Remove doc strings from source code 195.35 -;; * Add collapse/expand functionality for all namespaces 195.36 -;; * Add collapse/expand functionality for each namespace 195.37 -;; * See if converting to use clojure.contrib.prxml is possible 195.38 -;; * Figure out why the source doesn't show up for most things 195.39 -;; * Add collapsible source 195.40 -;; * Add links at the top to jump to each namespace 195.41 -;; * Add object type (var, function, whatever) 195.42 -;; * Add argument lists for functions 195.43 -;; * Add links at the top of each namespace to jump to members 195.44 -;; * Add license statement 195.45 -;; * Remove the whojure dependency 195.46 - 195.47 -(ns 195.48 - ^{:author "Craig Andera", 195.49 - :doc "Generates a single HTML page that contains the documentation for 195.50 -one or more Clojure libraries."} 195.51 - clojure.contrib.gen-html-docs 195.52 - (:require [clojure.contrib.io :as io] 195.53 - [clojure.contrib.string :as s]) 195.54 - (:use [clojure.contrib repl-utils def prxml]) 195.55 - (:import [java.lang Exception] 195.56 - [java.util.regex Pattern])) 195.57 - 195.58 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 195.59 -;; Doc generation constants 195.60 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 195.61 - 195.62 -(def *script* " // <![CDATA[ 195.63 - 195.64 -function getElem(id) 195.65 -{ 195.66 - if( document.getElementById ) 195.67 - { 195.68 - return document.getElementById( id ) 195.69 - } 195.70 - else if ( document.all ) 195.71 - { 195.72 - return eval( 'document.all.' + id ) 195.73 - } 195.74 - else 195.75 - return false; 195.76 -} 195.77 - 195.78 -function setDisplayStyle(id,displayStyle) 195.79 -{ 195.80 - var elem = getElem (id) 195.81 - if (elem) 195.82 - { 195.83 - elem.style.display = displayStyle 195.84 - } 195.85 - 195.86 -} 195.87 - 195.88 -function setLinkToggleText (id, text) 195.89 -{ 195.90 - var elem = getElem (id) 195.91 - if (elem) 195.92 - { 195.93 - elem.innerHTML = text 195.94 - } 195.95 -} 195.96 - 195.97 -function collapse(id) 195.98 -{ 195.99 - setDisplayStyle (id, 'none') 195.100 -} 195.101 - 195.102 -function expand (id) 195.103 -{ 195.104 - setDisplayStyle (id, 'block') 195.105 -} 195.106 - 195.107 -function toggleSource( id ) 195.108 -{ 195.109 - toggle(id, 'linkto-' + id, 'Hide Source', 'Show Source') 195.110 -} 195.111 - 195.112 -function toggle(targetid, linkid, textWhenOpen, textWhenClosed) 195.113 -{ 195.114 - var elem = getElem (targetid) 195.115 - var link = getElem (linkid) 195.116 - 195.117 - if (elem && link) 195.118 - { 195.119 - var isOpen = false 195.120 - if (elem.style.display == '') 195.121 - { 195.122 - isOpen = link.innerHTML == textWhenOpen 195.123 - } 195.124 - else if( elem.style.display == 'block' ) 195.125 - { 195.126 - isOpen = true 195.127 - } 195.128 - 195.129 - if (isOpen) 195.130 - { 195.131 - elem.style.display = 'none' 195.132 - link.innerHTML = textWhenClosed 195.133 - } 195.134 - else 195.135 - { 195.136 - elem.style.display = 'block' 195.137 - link.innerHTML = textWhenOpen 195.138 - } 195.139 - } 195.140 -} 195.141 - 195.142 - //]]> 195.143 -") 195.144 - 195.145 -(def *style* " 195.146 -.library 195.147 -{ 195.148 - padding: 0.5em 0 0 0 195.149 -} 195.150 -.all-libs-toggle,.library-contents-toggle 195.151 -{ 195.152 - font-size: small; 195.153 -} 195.154 -.all-libs-toggle a,.library-contents-toggle a 195.155 -{ 195.156 - color: white 195.157 -} 195.158 -.library-member-doc-whitespace 195.159 -{ 195.160 - white-space: pre 195.161 -} 195.162 -.library-member-source-toggle 195.163 -{ 195.164 - font-size: small; 195.165 - margin-top: 0.5em 195.166 -} 195.167 -.library-member-source 195.168 -{ 195.169 - display: none; 195.170 - border-left: solid lightblue 195.171 -} 195.172 -.library-member-docs 195.173 -{ 195.174 - font-family:monospace 195.175 -} 195.176 -.library-member-arglists 195.177 -{ 195.178 - font-family: monospace 195.179 -} 195.180 -.library-member-type 195.181 -{ 195.182 - font-weight: bold; 195.183 - font-size: small; 195.184 - font-style: italic; 195.185 - color: darkred 195.186 -} 195.187 -.lib-links 195.188 -{ 195.189 - margin: 0 0 1em 0 195.190 -} 195.191 - 195.192 -.lib-link-header 195.193 -{ 195.194 - color: white; 195.195 - background: darkgreen; 195.196 - width: 100% 195.197 -} 195.198 - 195.199 -.library-name 195.200 -{ 195.201 - color: white; 195.202 - background: darkblue; 195.203 - width: 100% 195.204 -} 195.205 - 195.206 -.missing-library 195.207 -{ 195.208 - color: darkred; 195.209 - margin: 0 0 1em 0 195.210 -} 195.211 - 195.212 -.library-members 195.213 -{ 195.214 - list-style: none 195.215 -} 195.216 - 195.217 -.library-member-name 195.218 -{ 195.219 - font-weight: bold; 195.220 - font-size: 105% 195.221 -}") 195.222 - 195.223 -(defn- extract-documentation 195.224 - "Pulls the documentation for a var v out and turns it into HTML" 195.225 - [v] 195.226 - (if-let [docs (:doc (meta v))] 195.227 - (map 195.228 - (fn [l] 195.229 - [:div {:class "library-member-doc-line"} 195.230 - (if (= 0 (count l)) 195.231 - [:span {:class "library-member-doc-whitespace"} " "] ; We need something here to make the blank line show up 195.232 - l)]) 195.233 - (s/split #"\n" docs)) 195.234 - "")) 195.235 - 195.236 -(defn- member-type 195.237 - "Figures out for a var x whether it's a macro, function, var or multifunction" 195.238 - [x] 195.239 - (try 195.240 - (let [dx (deref x)] 195.241 - (cond 195.242 - (:macro (meta x)) :macro 195.243 - (fn? dx) :fn 195.244 - (= clojure.lang.MultiFn (:tag (meta x))) :multi 195.245 - true :var)) 195.246 - (catch Exception e 195.247 - :unknown))) 195.248 - 195.249 -(defn- anchor-for-member 195.250 - "Returns a suitable HTML anchor name given a library id and a member 195.251 - id" 195.252 - [libid memberid] 195.253 - (str "member-" libid "-" memberid)) 195.254 - 195.255 -(defn- id-for-member-source 195.256 - "Returns a suitable HTML id for a source listing given a library and 195.257 - a member" 195.258 - [libid memberid] 195.259 - (str "membersource-" libid "-" memberid)) 195.260 - 195.261 -(defn- id-for-member-source-link 195.262 - "Returns a suitable HTML id for a link to a source listing given a 195.263 - library and a member" 195.264 - [libid memberid] 195.265 - (str "linkto-membersource-" libid "-" memberid)) 195.266 - 195.267 -(defn- symbol-for 195.268 - "Given a namespace object ns and a namespaceless symbol memberid 195.269 - naming a member of that namespace, returns a namespaced symbol that 195.270 - identifies that member." 195.271 - [ns memberid] 195.272 - (symbol (name (ns-name ns)) (name memberid))) 195.273 - 195.274 -(defn- elide-to-one-line 195.275 - "Elides a string down to one line." 195.276 - [s] 195.277 - (s/replace-re #"(\n.*)+" "..." s)) 195.278 - 195.279 -(defn- elide-string 195.280 - "Returns a string that is at most the first limit characters of s" 195.281 - [s limit] 195.282 - (if (< (- limit 3) (count s)) 195.283 - (str (subs s 0 (- limit 3)) "...") 195.284 - s)) 195.285 - 195.286 -(defn- doc-elided-src 195.287 - "Returns the src with the docs elided." 195.288 - [docs src] 195.289 - (s/replace-re (re-pattern (str "\"" (Pattern/quote docs) "\"")) 195.290 - (str "\"" 195.291 - (elide-to-one-line docs) 195.292 -;; (elide-string docs 10) 195.293 -;; "..." 195.294 - "\"") 195.295 - src)) 195.296 - 195.297 -(defn- format-source [libid memberid v] 195.298 - (try 195.299 - (let [docs (:doc (meta v)) 195.300 - src (if-let [ns (find-ns libid)] 195.301 - (get-source (symbol-for ns memberid)))] 195.302 - (if (and src docs) 195.303 - (doc-elided-src docs src) 195.304 - src)) 195.305 - (catch Exception ex 195.306 - nil))) 195.307 - 195.308 -(defn- generate-lib-member [libid [n v]] 195.309 - [:li {:class "library-member"} 195.310 - [:a {:name (anchor-for-member libid n)}] 195.311 - [:dl {:class "library-member-table"} 195.312 - [:dt {:class "library-member-name"} 195.313 - (str n)] 195.314 - [:dd 195.315 - [:div {:class "library-member-info"} 195.316 - [:span {:class "library-member-type"} (name (member-type v))] 195.317 - " " 195.318 - [:span {:class "library-member-arglists"} (str (:arglists (meta v)))]] 195.319 - (into [:div {:class "library-member-docs"}] (extract-documentation v)) 195.320 - (let [member-source-id (id-for-member-source libid n) 195.321 - member-source-link-id (id-for-member-source-link libid n)] 195.322 - (if-let [member-source (format-source libid n v)] 195.323 - [:div {:class "library-member-source-section"} 195.324 - [:div {:class "library-member-source-toggle"} 195.325 - "[ " 195.326 - [:a {:href (format "javascript:toggleSource('%s')" member-source-id) 195.327 - :id member-source-link-id} "Show Source"] 195.328 - " ]"] 195.329 - [:div {:class "library-member-source" :id member-source-id} 195.330 - [:pre member-source]]]))]]]) 195.331 - 195.332 -(defn- anchor-for-library 195.333 - "Given a symbol id identifying a namespace, returns an identifier 195.334 -suitable for use as the name attribute of an HTML anchor tag." 195.335 - [id] 195.336 - (str "library-" id)) 195.337 - 195.338 -(defn- generate-lib-member-link 195.339 - "Emits a hyperlink to a member of a namespace given libid (a symbol 195.340 -identifying the namespace) and the vector [n v], where n is the symbol 195.341 -naming the member in question and v is the var pointing to the 195.342 -member." 195.343 - [libid [n v]] 195.344 - [:a {:class "lib-member-link" 195.345 - :href (str "#" (anchor-for-member libid n))} (name n)]) 195.346 - 195.347 -(defn- anchor-for-library-contents 195.348 - "Returns an HTML ID that identifies the element that holds the 195.349 -documentation contents for the specified library." 195.350 - [lib] 195.351 - (str "library-contents-" lib)) 195.352 - 195.353 -(defn- anchor-for-library-contents-toggle 195.354 - "Returns an HTML ID that identifies the element that toggles the 195.355 -visibility of the library contents." 195.356 - [lib] 195.357 - (str "library-contents-toggle-" lib)) 195.358 - 195.359 -(defn- generate-lib-doc 195.360 - "Emits the HTML that documents the namespace identified by the 195.361 -symbol lib." 195.362 - [lib] 195.363 - [:div {:class "library"} 195.364 - [:a {:name (anchor-for-library lib)}] 195.365 - [:div {:class "library-name"} 195.366 - [:span {:class "library-contents-toggle"} 195.367 - "[ " 195.368 - [:a {:id (anchor-for-library-contents-toggle lib) 195.369 - :href (format "javascript:toggle('%s', '%s', '-', '+')" 195.370 - (anchor-for-library-contents lib) 195.371 - (anchor-for-library-contents-toggle lib))} 195.372 - "-"] 195.373 - " ] "] 195.374 - (name lib)] 195.375 - (let [ns (find-ns lib)] 195.376 - (if ns 195.377 - (let [lib-members (sort (ns-publics ns))] 195.378 - [:a {:name (anchor-for-library lib)}] 195.379 - [:div {:class "library-contents" :id (anchor-for-library-contents lib)} 195.380 - (into [:div {:class "library-member-links"}] 195.381 - (interpose " " (map #(generate-lib-member-link lib %) lib-members))) 195.382 - (into [:ol {:class "library-members"}] 195.383 - (map #(generate-lib-member lib %) lib-members))]) 195.384 - [:div {:class "missing-library library-contents" :id (anchor-for-library-contents lib)} "Could not load library"]))]) 195.385 - 195.386 -(defn- load-lib 195.387 - "Calls require on the library identified by lib, eating any 195.388 -exceptions." 195.389 - [lib] 195.390 - (try 195.391 - (require lib) 195.392 - (catch java.lang.Exception x 195.393 - nil))) 195.394 - 195.395 -(defn- generate-lib-link 195.396 - "Generates a hyperlink to the documentation for a namespace given 195.397 -lib, a symbol identifying that namespace." 195.398 - [lib] 195.399 - (let [ns (find-ns lib)] 195.400 - (if ns 195.401 - [:a {:class "lib-link" :href (str "#" (anchor-for-library lib))} (str (ns-name ns))]))) 195.402 - 195.403 -(defn- generate-lib-links 195.404 - "Generates the list of hyperlinks to each namespace, given libs, a 195.405 -vector of symbols naming namespaces." 195.406 - [libs] 195.407 - (into [:div {:class "lib-links"} 195.408 - [:div {:class "lib-link-header"} "Namespaces" 195.409 - [:span {:class "all-libs-toggle"} 195.410 - " [ " 195.411 - [:a {:href "javascript:expandAllNamespaces()"} 195.412 - "Expand All"] 195.413 - " ] [ " 195.414 - [:a {:href "javascript:collapseAllNamespaces()"} 195.415 - "Collapse All"] 195.416 - " ]"]]] 195.417 - (interpose " " (map generate-lib-link libs)))) 195.418 - 195.419 -(defn generate-toggle-namespace-script 195.420 - [action toggle-text lib] 195.421 - (str (format "%s('%s');\n" action (anchor-for-library-contents lib)) 195.422 - (format "setLinkToggleText('%s', '%s');\n" (anchor-for-library-contents-toggle lib) toggle-text))) 195.423 - 195.424 -(defn generate-all-namespaces-action-script 195.425 - [action toggle-text libs] 195.426 - (str (format "function %sAllNamespaces()" action) 195.427 - \newline 195.428 - "{" 195.429 - \newline 195.430 - (reduce str (map #(generate-toggle-namespace-script action toggle-text %) libs)) 195.431 - \newline 195.432 - "}")) 195.433 - 195.434 -(defn generate-documentation 195.435 - "Returns a string which is the HTML documentation for the libraries 195.436 -named by libs. Libs is a vector of symbols identifying Clojure 195.437 -libraries." 195.438 - [libs] 195.439 - (dorun (map load-lib libs)) 195.440 - (let [writer (new java.io.StringWriter)] 195.441 - (binding [*out* writer] 195.442 - (prxml 195.443 - [:html {:xmlns "http://www.w3.org/1999/xhtml"} 195.444 - [:head 195.445 - [:title "Clojure documentation browser"] 195.446 - [:style *style*] 195.447 - [:script {:language "JavaScript" :type "text/javascript"} [:raw! *script*]] 195.448 - 195.449 - [:script {:language "JavaScript" :type "text/javascript"} 195.450 - [:raw! "// <![CDATA[!" \newline] 195.451 - (generate-all-namespaces-action-script "expand" "-" libs) 195.452 - (generate-all-namespaces-action-script "collapse" "+" libs) 195.453 - [:raw! \newline "// ]]>"]]] 195.454 - (let [lib-vec (sort libs)] 195.455 - (into [:body (generate-lib-links lib-vec)] 195.456 - (map generate-lib-doc lib-vec)))])) 195.457 - (.toString writer))) 195.458 - 195.459 - 195.460 -(defn generate-documentation-to-file 195.461 - "Calls generate-documentation on the libraries named by libs and 195.462 -emits the generated HTML to the path named by path." 195.463 - [path libs] 195.464 - (io/spit path (generate-documentation libs))) 195.465 - 195.466 -(comment 195.467 - (generate-documentation-to-file 195.468 - "C:/TEMP/CLJ-DOCS.HTML" 195.469 - ['clojure.contrib.accumulators]) 195.470 - 195.471 - (defn gen-all-docs [] 195.472 - (generate-documentation-to-file 195.473 - "C:/temp/clj-libs.html" 195.474 - [ 195.475 - 'clojure.set 195.476 - 'clojure.main 195.477 - 'clojure.core 195.478 - 'clojure.zip 195.479 - 'clojure.xml 195.480 - 'clojure.contrib.accumulators 195.481 - 'clojure.contrib.apply-macro 195.482 - 'clojure.contrib.auto-agent 195.483 - 'clojure.contrib.combinatorics 195.484 - 'clojure.contrib.command-line 195.485 - 'clojure.contrib.complex-numbers 195.486 - 'clojure.contrib.cond 195.487 - 'clojure.contrib.def 195.488 - 'clojure.contrib.io 195.489 - 'clojure.contrib.enum 195.490 - 'clojure.contrib.error-kit 195.491 - 'clojure.contrib.except 195.492 - 'clojure.contrib.fcase 195.493 - 'clojure.contrib.generic 195.494 - 'clojure.contrib.generic.arithmetic 195.495 - 'clojure.contrib.generic.collection 195.496 - 'clojure.contrib.generic.comparison 195.497 - 'clojure.contrib.generic.functor 195.498 - 'clojure.contrib.generic.math-functions 195.499 - 'clojure.contrib.import-static 195.500 - 'clojure.contrib.javadoc 195.501 - 'clojure.contrib.javalog 195.502 - 'clojure.contrib.lazy-seqs 195.503 - 'clojure.contrib.lazy-xml 195.504 - 'clojure.contrib.macro-utils 195.505 - 'clojure.contrib.macros 195.506 - 'clojure.contrib.math 195.507 - 'clojure.contrib.miglayout 195.508 - 'clojure.contrib.mmap 195.509 - 'clojure.contrib.monads 195.510 - 'clojure.contrib.ns-utils 195.511 - 'clojure.contrib.prxml 195.512 - 'clojure.contrib.repl-ln 195.513 - 'clojure.contrib.repl-utils 195.514 - 'clojure.contrib.seq 195.515 - 'clojure.contrib.server-socket 195.516 - 'clojure.contrib.shell 195.517 - 'clojure.contrib.sql 195.518 - 'clojure.contrib.stream-utils 195.519 - 'clojure.contrib.string 195.520 - 'clojure.contrib.test-contrib 195.521 - 'clojure.contrib.trace 195.522 - 'clojure.contrib.types 195.523 - 'clojure.contrib.zip-filter 195.524 - 'clojure.contrib.javadoc.browse 195.525 - 'clojure.contrib.json.read 195.526 - 'clojure.contrib.json.write 195.527 - 'clojure.contrib.lazy-xml.with-pull 195.528 - 'clojure.contrib.miglayout.internal 195.529 - 'clojure.contrib.probabilities.finite-distributions 195.530 - 'clojure.contrib.probabilities.monte-carlo 195.531 - 'clojure.contrib.probabilities.random-numbers 195.532 - 'clojure.contrib.sql.internal 195.533 - 'clojure.contrib.test-clojure.evaluation 195.534 - 'clojure.contrib.test-clojure.for 195.535 - 'clojure.contrib.test-clojure.numbers 195.536 - 'clojure.contrib.test-clojure.printer 195.537 - 'clojure.contrib.test-clojure.reader 195.538 - 'clojure.contrib.test-clojure.sequences 195.539 - 'clojure.contrib.test-contrib.shell 195.540 - 'clojure.contrib.test-contrib.string 195.541 - 'clojure.contrib.zip-filter.xml 195.542 - ])) 195.543 - )
196.1 --- a/src/clojure/contrib/generic.clj Sat Aug 21 06:25:44 2010 -0400 196.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 196.3 @@ -1,54 +0,0 @@ 196.4 -;; Support code for generic interfaces 196.5 - 196.6 -;; by Konrad Hinsen 196.7 -;; last updated May 4, 2009 196.8 - 196.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 196.10 -;; and distribution terms for this software are covered by the Eclipse 196.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 196.12 -;; which can be found in the file epl-v10.html at the root of this 196.13 -;; distribution. By using this software in any fashion, you are 196.14 -;; agreeing to be bound by the terms of this license. You must not 196.15 -;; remove this notice, or any other, from this software. 196.16 - 196.17 -(ns 196.18 - ^{:author "Konrad Hinsen" 196.19 - :skip-wiki true 196.20 - :doc "Generic interfaces 196.21 - This library provides generic interfaces in the form of 196.22 - multimethods that can be implemented for any type. 196.23 - The interfaces partly duplicate existing non-generic 196.24 - functions in clojure.core (arithmetic, comparison, 196.25 - collections) and partly provide additional functions that 196.26 - can be defined for a wide variety of types (functors, math 196.27 - functions). More functions will be added in the future."} 196.28 - clojure.contrib.generic 196.29 - (:use [clojure.contrib.types :only (defadt)])) 196.30 - 196.31 -; 196.32 -; A dispatch function that separates nulary, unary, binary, and 196.33 -; higher arity calls and also selects on type for unary and binary 196.34 -; calls. 196.35 -; 196.36 -(defn nary-dispatch 196.37 - ([] ::nulary) 196.38 - ([x] (type x)) 196.39 - ([x y] 196.40 - [(type x) (type y)]) 196.41 - ([x y & more] ::nary)) 196.42 - 196.43 -; 196.44 -; We can't use [::binary :default], so we need to define a root type 196.45 -; of the type hierarcy. The derivation for Object covers all classes, 196.46 -; but all non-class types will need an explicit derive clause. 196.47 -; Ultimately, a macro might take care of this. 196.48 -; 196.49 -(def root-type ::any) 196.50 -(derive Object root-type) 196.51 - 196.52 -; 196.53 -; Symbols referring to ::nulary and ::n-ary 196.54 -; 196.55 -(def nulary-type ::nulary) 196.56 -(def nary-type ::nary) 196.57 -
197.1 --- a/src/clojure/contrib/generic/arithmetic.clj Sat Aug 21 06:25:44 2010 -0400 197.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 197.3 @@ -1,201 +0,0 @@ 197.4 -;; Generic interfaces for arithmetic operations 197.5 - 197.6 -;; by Konrad Hinsen 197.7 -;; last updated May 5, 2009 197.8 - 197.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 197.10 -;; and distribution terms for this software are covered by the Eclipse 197.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 197.12 -;; which can be found in the file epl-v10.html at the root of this 197.13 -;; distribution. By using this software in any fashion, you are 197.14 -;; agreeing to be bound by the terms of this license. You must not 197.15 -;; remove this notice, or any other, from this software. 197.16 - 197.17 -(ns 197.18 - ^{:author "Konrad Hinsen" 197.19 - :doc "Generic arithmetic interface 197.20 - This library defines generic versions of + - * / as multimethods 197.21 - that can be defined for any type. The minimal required 197.22 - implementations for a type are binary + and * plus unary - and /. 197.23 - Everything else is derived from these automatically. Explicit 197.24 - binary definitions for - and / can be provided for 197.25 - efficiency reasons."} 197.26 - clojure.contrib.generic.arithmetic 197.27 - (:use [clojure.contrib.generic 197.28 - :only (root-type nulary-type nary-type nary-dispatch)] 197.29 - [clojure.contrib.types :only (defadt)]) 197.30 - (:refer-clojure :exclude [+ - * /])) 197.31 - 197.32 -; 197.33 -; Universal zero and one values 197.34 -; 197.35 -(defadt ::zero zero) 197.36 -(defadt ::one one) 197.37 - 197.38 -(derive ::zero root-type) 197.39 -(derive ::one root-type) 197.40 - 197.41 -; 197.42 -; Addition 197.43 -; 197.44 -; The minimal implementation is for binary my-type. It is possible 197.45 -; in principle to implement [::unary my-type] as well, though this 197.46 -; doesn't make any sense. 197.47 -; 197.48 -(defmulti + 197.49 - "Return the sum of all arguments. The minimal implementation for type 197.50 - ::my-type is the binary form with dispatch value [::my-type ::my-type]." 197.51 - {:arglists '([x] [x y] [x y & more])} 197.52 - nary-dispatch) 197.53 - 197.54 -(defmethod + nulary-type 197.55 - [] 197.56 - zero) 197.57 - 197.58 -(defmethod + root-type 197.59 - [x] x) 197.60 - 197.61 -(defmethod + [root-type ::zero] 197.62 - [x y] x) 197.63 - 197.64 -(defmethod + [::zero root-type] 197.65 - [x y] y) 197.66 - 197.67 -(defmethod + nary-type 197.68 - [x y & more] 197.69 - (if more 197.70 - (recur (+ x y) (first more) (next more)) 197.71 - (+ x y))) 197.72 - 197.73 -; 197.74 -; Subtraction 197.75 -; 197.76 -; The minimal implementation is for unary my-type. A default binary 197.77 -; implementation is provided as (+ x (- y)), but it is possible to 197.78 -; implement unary my-type explicitly for efficiency reasons. 197.79 -; 197.80 -(defmulti - 197.81 - "Return the difference of the first argument and the sum of all other 197.82 - arguments. The minimal implementation for type ::my-type is the binary 197.83 - form with dispatch value [::my-type ::my-type]." 197.84 - {:arglists '([x] [x y] [x y & more])} 197.85 - nary-dispatch) 197.86 - 197.87 -(defmethod - nulary-type 197.88 - [] 197.89 - (throw (java.lang.IllegalArgumentException. 197.90 - "Wrong number of arguments passed"))) 197.91 - 197.92 -(defmethod - [root-type ::zero] 197.93 - [x y] x) 197.94 - 197.95 -(defmethod - [::zero root-type] 197.96 - [x y] (- y)) 197.97 - 197.98 -(defmethod - [root-type root-type] 197.99 - [x y] (+ x (- y))) 197.100 - 197.101 -(defmethod - nary-type 197.102 - [x y & more] 197.103 - (if more 197.104 - (recur (- x y) (first more) (next more)) 197.105 - (- x y))) 197.106 - 197.107 -; 197.108 -; Multiplication 197.109 -; 197.110 -; The minimal implementation is for binary [my-type my-type]. It is possible 197.111 -; in principle to implement unary my-type as well, though this 197.112 -; doesn't make any sense. 197.113 -; 197.114 -(defmulti * 197.115 - "Return the product of all arguments. The minimal implementation for type 197.116 - ::my-type is the binary form with dispatch value [::my-type ::my-type]." 197.117 - {:arglists '([x] [x y] [x y & more])} 197.118 - nary-dispatch) 197.119 - 197.120 -(defmethod * nulary-type 197.121 - [] 197.122 - one) 197.123 - 197.124 -(defmethod * root-type 197.125 - [x] x) 197.126 - 197.127 -(defmethod * [root-type ::one] 197.128 - [x y] x) 197.129 - 197.130 -(defmethod * [::one root-type] 197.131 - [x y] y) 197.132 - 197.133 -(defmethod * nary-type 197.134 - [x y & more] 197.135 - (if more 197.136 - (recur (* x y) (first more) (next more)) 197.137 - (* x y))) 197.138 - 197.139 -; 197.140 -; Division 197.141 -; 197.142 -; The minimal implementation is for unary my-type. A default binary 197.143 -; implementation is provided as (* x (/ y)), but it is possible to 197.144 -; implement binary [my-type my-type] explicitly for efficiency reasons. 197.145 -; 197.146 -(defmulti / 197.147 - "Return the quotient of the first argument and the product of all other 197.148 - arguments. The minimal implementation for type ::my-type is the binary 197.149 - form with dispatch value [::my-type ::my-type]." 197.150 - {:arglists '([x] [x y] [x y & more])} 197.151 - nary-dispatch) 197.152 - 197.153 -(defmethod / nulary-type 197.154 - [] 197.155 - (throw (java.lang.IllegalArgumentException. 197.156 - "Wrong number of arguments passed"))) 197.157 - 197.158 -(defmethod / [root-type ::one] 197.159 - [x y] x) 197.160 - 197.161 -(defmethod / [::one root-type] 197.162 - [x y] (/ y)) 197.163 - 197.164 -(defmethod / [root-type root-type] 197.165 - [x y] (* x (/ y))) 197.166 - 197.167 -(defmethod / nary-type 197.168 - [x y & more] 197.169 - (if more 197.170 - (recur (/ x y) (first more) (next more)) 197.171 - (/ x y))) 197.172 - 197.173 -; 197.174 -; Macros to permit access to the / multimethod via namespace qualification 197.175 -; 197.176 -(defmacro defmethod* 197.177 - "Define a method implementation for the multimethod name in namespace ns. 197.178 - Required for implementing the division function from another namespace." 197.179 - [ns name & args] 197.180 - (let [qsym (symbol (str ns) (str name))] 197.181 - `(defmethod ~qsym ~@args))) 197.182 - 197.183 -(defmacro qsym 197.184 - "Create the qualified symbol corresponding to sym in namespace ns. 197.185 - Required to access the division function from another namespace, 197.186 - e.g. as (qsym clojure.contrib.generic.arithmetic /)." 197.187 - [ns sym] 197.188 - (symbol (str ns) (str sym))) 197.189 - 197.190 -; 197.191 -; Minimal implementations for java.lang.Number 197.192 -; 197.193 -(defmethod + [java.lang.Number java.lang.Number] 197.194 - [x y] (clojure.core/+ x y)) 197.195 - 197.196 -(defmethod - java.lang.Number 197.197 - [x] (clojure.core/- x)) 197.198 - 197.199 -(defmethod * [java.lang.Number java.lang.Number] 197.200 - [x y] (clojure.core/* x y)) 197.201 - 197.202 -(defmethod / java.lang.Number 197.203 - [x] (clojure.core// x)) 197.204 -
198.1 --- a/src/clojure/contrib/generic/collection.clj Sat Aug 21 06:25:44 2010 -0400 198.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 198.3 @@ -1,116 +0,0 @@ 198.4 -;; Generic interfaces for collection-related functions 198.5 - 198.6 -;; by Konrad Hinsen 198.7 -;; last updated May 5, 2009 198.8 - 198.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 198.10 -;; and distribution terms for this software are covered by the Eclipse 198.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 198.12 -;; which can be found in the file epl-v10.html at the root of this 198.13 -;; distribution. By using this software in any fashion, you are 198.14 -;; agreeing to be bound by the terms of this license. You must not 198.15 -;; remove this notice, or any other, from this software. 198.16 - 198.17 -(ns 198.18 - ^{:author "Konrad Hinsen" 198.19 - :doc "Generic arithmetic interface 198.20 - This library defines generic versions of common 198.21 - collection-related functions as multimethods that can be 198.22 - defined for any type."} 198.23 - clojure.contrib.generic.collection 198.24 - (:refer-clojure :exclude [assoc conj dissoc empty get into seq])) 198.25 - 198.26 -; 198.27 -; assoc 198.28 -; 198.29 -(defmulti assoc 198.30 - "Returns a new collection in which the values corresponding to the 198.31 - given keys are updated by the given values. Each type of collection 198.32 - can have specific restrictions on the possible keys." 198.33 - {:arglists '([coll & key-val-pairs])} 198.34 - (fn [coll & items] (type coll))) 198.35 - 198.36 -(defmethod assoc :default 198.37 - [map & key-val-pairs] 198.38 - (apply clojure.core/assoc map key-val-pairs)) 198.39 - 198.40 -; assoc-in 198.41 - 198.42 -; 198.43 -; conj 198.44 -; 198.45 -(defmulti conj 198.46 - "Returns a new collection resulting from adding all xs to coll." 198.47 - {:arglists '([coll & xs])} 198.48 - (fn [coll & xs] (type coll))) 198.49 - 198.50 -(defmethod conj :default 198.51 - [coll & xs] 198.52 - (apply clojure.core/conj coll xs)) 198.53 - 198.54 -; 198.55 -; diassoc 198.56 -; 198.57 -(defmulti dissoc 198.58 - "Returns a new collection in which the entries corresponding to the 198.59 - given keys are removed. Each type of collection can have specific 198.60 - restrictions on the possible keys." 198.61 - {:arglists '([coll & keys])} 198.62 - (fn [coll & keys] (type coll))) 198.63 - 198.64 -(defmethod dissoc :default 198.65 - [map & keys] 198.66 - (apply clojure.core/dissoc map keys)) 198.67 - 198.68 -; 198.69 -; empty 198.70 -; 198.71 -(defmulti empty 198.72 - "Returns an empty collection of the same kind as the argument" 198.73 - {:arglists '([coll])} 198.74 - type) 198.75 - 198.76 -(defmethod empty :default 198.77 - [coll] 198.78 - (clojure.core/empty coll)) 198.79 - 198.80 -; 198.81 -; get 198.82 -; 198.83 -(defmulti get 198.84 - "Returns the element of coll referred to by key. Each type of collection 198.85 - can have specific restrictions on the possible keys." 198.86 - {:arglists '([coll key] [coll key not-found])} 198.87 - (fn [coll & args] (type coll))) 198.88 - 198.89 -(defmethod get :default 198.90 - ([coll key] 198.91 - (clojure.core/get coll key)) 198.92 - ([coll key not-found] 198.93 - (clojure.core/get coll key not-found))) 198.94 - 198.95 -; 198.96 -; into 198.97 -; 198.98 -(defmulti into 198.99 - "Returns a new coll consisting of to-coll with all of the items of 198.100 - from-coll conjoined." 198.101 - {:arglists '([to from])} 198.102 - (fn [to from] (type to))) 198.103 - 198.104 -(declare seq) 198.105 -(defmethod into :default 198.106 - [to from] 198.107 - (reduce conj to (seq from))) 198.108 - 198.109 -; 198.110 -; seq 198.111 -; 198.112 -(defmulti seq 198.113 - "Returns a seq on the object s." 198.114 - {:arglists '([s])} 198.115 - type) 198.116 - 198.117 -(defmethod seq :default 198.118 - [s] 198.119 - (clojure.core/seq s))
199.1 --- a/src/clojure/contrib/generic/comparison.clj Sat Aug 21 06:25:44 2010 -0400 199.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 199.3 @@ -1,214 +0,0 @@ 199.4 -;; Generic interfaces for comparison operations 199.5 - 199.6 -;; by Konrad Hinsen 199.7 -;; last updated May 25, 2010 199.8 - 199.9 -;; Copyright (c) Konrad Hinsen, 2009-2010. All rights reserved. The use 199.10 -;; and distribution terms for this software are covered by the Eclipse 199.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 199.12 -;; which can be found in the file epl-v10.html at the root of this 199.13 -;; distribution. By using this software in any fashion, you are 199.14 -;; agreeing to be bound by the terms of this license. You must not 199.15 -;; remove this notice, or any other, from this software. 199.16 - 199.17 -(ns 199.18 - ^{:author "Konrad Hinsen" 199.19 - :doc "Generic comparison interface 199.20 - This library defines generic versions of = < > <= >= zero? 199.21 - as multimethods that can be defined for any type. Of the 199.22 - greater/less-than relations, types must minimally implement >."} 199.23 - clojure.contrib.generic.comparison 199.24 - (:refer-clojure :exclude [= < > <= >= zero? pos? neg? min max]) 199.25 - (:use [clojure.contrib.generic 199.26 - :only (root-type nulary-type nary-type nary-dispatch)])) 199.27 - 199.28 -; 199.29 -; zero? pos? neg? 199.30 -; 199.31 -(defmulti zero? 199.32 - "Return true of x is zero." 199.33 - {:arglists '([x])} 199.34 - type) 199.35 - 199.36 -(defmulti pos? 199.37 - "Return true of x is positive." 199.38 - {:arglists '([x])} 199.39 - type) 199.40 - 199.41 -(defmulti neg? 199.42 - "Return true of x is negative." 199.43 - {:arglists '([x])} 199.44 - type) 199.45 - 199.46 -; 199.47 -; Equality 199.48 -; 199.49 -(defmulti = 199.50 - "Return true if all arguments are equal. The minimal implementation for type 199.51 - ::my-type is the binary form with dispatch value [::my-type ::my-type]." 199.52 - {:arglists '([x] [x y] [x y & more])} 199.53 - nary-dispatch) 199.54 - 199.55 -(defmethod = root-type 199.56 - [x] true) 199.57 - 199.58 -(defmethod = nary-type 199.59 - [x y & more] 199.60 - (if (= x y) 199.61 - (if (next more) 199.62 - (recur y (first more) (next more)) 199.63 - (= y (first more))) 199.64 - false)) 199.65 - 199.66 -; 199.67 -; Greater-than 199.68 -; 199.69 -(defmulti > 199.70 - "Return true if each argument is larger than the following ones. 199.71 - The minimal implementation for type ::my-type is the binary form 199.72 - with dispatch value [::my-type ::my-type]." 199.73 - {:arglists '([x] [x y] [x y & more])} 199.74 - nary-dispatch) 199.75 - 199.76 -(defmethod > root-type 199.77 - [x] true) 199.78 - 199.79 -(defmethod > nary-type 199.80 - [x y & more] 199.81 - (if (> x y) 199.82 - (if (next more) 199.83 - (recur y (first more) (next more)) 199.84 - (> y (first more))) 199.85 - false)) 199.86 - 199.87 -; 199.88 -; Less-than defaults to greater-than with arguments inversed 199.89 -; 199.90 -(defmulti < 199.91 - "Return true if each argument is smaller than the following ones. 199.92 - The minimal implementation for type ::my-type is the binary form 199.93 - with dispatch value [::my-type ::my-type]. A default implementation 199.94 - is provided in terms of >." 199.95 - {:arglists '([x] [x y] [x y & more])} 199.96 - nary-dispatch) 199.97 - 199.98 -(defmethod < root-type 199.99 - [x] true) 199.100 - 199.101 -(defmethod < [root-type root-type] 199.102 - [x y] 199.103 - (> y x)) 199.104 - 199.105 -(defmethod < nary-type 199.106 - [x y & more] 199.107 - (if (< x y) 199.108 - (if (next more) 199.109 - (recur y (first more) (next more)) 199.110 - (< y (first more))) 199.111 - false)) 199.112 - 199.113 -; 199.114 -; Greater-or-equal defaults to (complement <) 199.115 -; 199.116 -(defmulti >= 199.117 - "Return true if each argument is larger than or equal to the following 199.118 - ones. The minimal implementation for type ::my-type is the binary form 199.119 - with dispatch value [::my-type ::my-type]. A default implementation 199.120 - is provided in terms of <." 199.121 - {:arglists '([x] [x y] [x y & more])} 199.122 - nary-dispatch) 199.123 - 199.124 -(defmethod >= root-type 199.125 - [x] true) 199.126 - 199.127 -(defmethod >= [root-type root-type] 199.128 - [x y] 199.129 - (not (< x y))) 199.130 - 199.131 -(defmethod >= nary-type 199.132 - [x y & more] 199.133 - (if (>= x y) 199.134 - (if (next more) 199.135 - (recur y (first more) (next more)) 199.136 - (>= y (first more))) 199.137 - false)) 199.138 - 199.139 -; 199.140 -; Less-than defaults to (complement >) 199.141 -; 199.142 -(defmulti <= 199.143 - "Return true if each arguments is smaller than or equal to the following 199.144 - ones. The minimal implementation for type ::my-type is the binary form 199.145 - with dispatch value [::my-type ::my-type]. A default implementation 199.146 - is provided in terms of >." 199.147 - {:arglists '([x] [x y] [x y & more])} 199.148 - nary-dispatch) 199.149 - 199.150 -(defmethod <= root-type 199.151 - [x] true) 199.152 - 199.153 -(defmethod <= [root-type root-type] 199.154 - [x y] 199.155 - (not (> x y))) 199.156 - 199.157 -(defmethod <= nary-type 199.158 - [x y & more] 199.159 - (if (<= x y) 199.160 - (if (next more) 199.161 - (recur y (first more) (next more)) 199.162 - (<= y (first more))) 199.163 - false)) 199.164 - 199.165 -; 199.166 -; Implementations for Clojure's built-in types 199.167 -; 199.168 -(defmethod zero? java.lang.Number 199.169 - [x] 199.170 - (clojure.core/zero? x)) 199.171 - 199.172 -(defmethod pos? java.lang.Number 199.173 - [x] 199.174 - (clojure.core/pos? x)) 199.175 - 199.176 -(defmethod neg? java.lang.Number 199.177 - [x] 199.178 - (clojure.core/neg? x)) 199.179 - 199.180 -(defmethod = [Object Object] 199.181 - [x y] 199.182 - (clojure.core/= x y)) 199.183 - 199.184 -(defmethod > [java.lang.Number java.lang.Number] 199.185 - [x y] 199.186 - (clojure.core/> x y)) 199.187 - 199.188 -(defmethod < [java.lang.Number java.lang.Number] 199.189 - [x y] 199.190 - (clojure.core/< x y)) 199.191 - 199.192 -(defmethod >= [java.lang.Number java.lang.Number] 199.193 - [x y] 199.194 - (clojure.core/>= x y)) 199.195 - 199.196 -(defmethod <= [java.lang.Number java.lang.Number] 199.197 - [x y] 199.198 - (clojure.core/<= x y)) 199.199 - 199.200 -; 199.201 -; Functions defined in terms of the comparison operators 199.202 -; 199.203 -(defn max 199.204 - "Returns the greatest of its arguments. Like clojure.core/max except that 199.205 - is uses generic comparison functions implementable for any data type." 199.206 - ([x] x) 199.207 - ([x y] (if (> x y) x y)) 199.208 - ([x y & more] 199.209 - (reduce max (max x y) more))) 199.210 - 199.211 -(defn min 199.212 - "Returns the least of its arguments. Like clojure.core/min except that 199.213 - is uses generic comparison functions implementable for any data type." 199.214 - ([x] x) 199.215 - ([x y] (if (< x y) x y)) 199.216 - ([x y & more] 199.217 - (reduce min (min x y) more)))
200.1 --- a/src/clojure/contrib/generic/functor.clj Sat Aug 21 06:25:44 2010 -0400 200.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 200.3 @@ -1,40 +0,0 @@ 200.4 -;; Generic interface for functors 200.5 - 200.6 -;; by Konrad Hinsen 200.7 -;; last updated May 3, 2009 200.8 - 200.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 200.10 -;; and distribution terms for this software are covered by the Eclipse 200.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 200.12 -;; which can be found in the file epl-v10.html at the root of this 200.13 -;; distribution. By using this software in any fashion, you are 200.14 -;; agreeing to be bound by the terms of this license. You must not 200.15 -;; remove this notice, or any other, from this software. 200.16 - 200.17 -(ns 200.18 - ^{:author "Konrad Hinsen" 200.19 - :doc "Generic functor interface (fmap)"} 200.20 - clojure.contrib.generic.functor) 200.21 - 200.22 - 200.23 -(defmulti fmap 200.24 - "Applies function f to each item in the data structure s and returns 200.25 - a structure of the same kind." 200.26 - {:arglists '([f s])} 200.27 - (fn [f s] (type s))) 200.28 - 200.29 -(defmethod fmap clojure.lang.IPersistentList 200.30 - [f v] 200.31 - (into (empty v) (map f v))) 200.32 - 200.33 -(defmethod fmap clojure.lang.IPersistentVector 200.34 - [f v] 200.35 - (into (empty v) (map f v))) 200.36 - 200.37 -(defmethod fmap clojure.lang.IPersistentMap 200.38 - [f m] 200.39 - (into (empty m) (for [[k v] m] [k (f v)]))) 200.40 - 200.41 -(defmethod fmap clojure.lang.IPersistentSet 200.42 - [f s] 200.43 - (into (empty s) (map f s)))
201.1 --- a/src/clojure/contrib/generic/math_functions.clj Sat Aug 21 06:25:44 2010 -0400 201.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 201.3 @@ -1,114 +0,0 @@ 201.4 -;; Generic interfaces for mathematical functions 201.5 - 201.6 -;; by Konrad Hinsen 201.7 -;; last updated May 5, 2009 201.8 - 201.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 201.10 -;; and distribution terms for this software are covered by the Eclipse 201.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 201.12 -;; which can be found in the file epl-v10.html at the root of this 201.13 -;; distribution. By using this software in any fashion, you are 201.14 -;; agreeing to be bound by the terms of this license. You must not 201.15 -;; remove this notice, or any other, from this software. 201.16 - 201.17 -(ns 201.18 - ^{:author "Konrad Hinsen" 201.19 - :doc "Generic math function interface 201.20 - This library defines generic versions of common mathematical 201.21 - functions such as sqrt or sin as multimethods that can be 201.22 - defined for any type."} 201.23 - clojure.contrib.generic.math-functions 201.24 - (:use [clojure.contrib.def :only (defmacro-)]) 201.25 - (:require [clojure.contrib.generic.arithmetic :as ga] 201.26 - [clojure.contrib.generic.comparison :as gc])) 201.27 - 201.28 -(defmacro- defmathfn-1 201.29 - [name] 201.30 - (let [java-symbol (symbol "java.lang.Math" (str name))] 201.31 - `(do 201.32 - (defmulti ~name 201.33 - ~(str "Return the " name " of x.") 201.34 - {:arglists '([~'x])} 201.35 - type) 201.36 - (defmethod ~name java.lang.Number 201.37 - [~'x] 201.38 - (~java-symbol ~'x))))) 201.39 - 201.40 -(defn- two-types [x y] [(type x) (type y)]) 201.41 - 201.42 -(defmacro- defmathfn-2 201.43 - [name] 201.44 - (let [java-symbol (symbol "java.lang.Math" (str name))] 201.45 - `(do 201.46 - (defmulti ~name 201.47 - ~(str "Return the " name " of x and y.") 201.48 - {:arglists '([~'x ~'y])} 201.49 - two-types) 201.50 - (defmethod ~name [java.lang.Number java.lang.Number] 201.51 - [~'x ~'y] 201.52 - (~java-symbol ~'x ~'y))))) 201.53 - 201.54 -; List of math functions taken from 201.55 -; http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html 201.56 -(defmathfn-1 abs) 201.57 -(defmathfn-1 acos) 201.58 -(defmathfn-1 asin) 201.59 -(defmathfn-1 atan) 201.60 -(defmathfn-2 atan2) 201.61 -(defmathfn-1 ceil) 201.62 -(defmathfn-1 cos) 201.63 -(defmathfn-1 exp) 201.64 -(defmathfn-1 floor) 201.65 -(defmathfn-1 log) 201.66 -(defmathfn-2 pow) 201.67 -(defmathfn-1 rint) 201.68 -(defmathfn-1 round) 201.69 -(defmathfn-1 sin) 201.70 -(defmathfn-1 sqrt) 201.71 -(defmathfn-1 tan) 201.72 - 201.73 -; 201.74 -; Sign 201.75 -; 201.76 -(defmulti sgn 201.77 - "Return the sign of x (-1, 0, or 1)." 201.78 - {:arglists '([x])} 201.79 - type) 201.80 - 201.81 -(defmethod sgn :default 201.82 - [x] 201.83 - (cond (gc/zero? x) 0 201.84 - (gc/> x 0) 1 201.85 - :else -1)) 201.86 - 201.87 -; 201.88 -; Conjugation 201.89 -; 201.90 -(defmulti conjugate 201.91 - "Return the conjugate of x." 201.92 - {:arglists '([x])} 201.93 - type) 201.94 - 201.95 -(defmethod conjugate :default 201.96 - [x] x) 201.97 - 201.98 -; 201.99 -; Square 201.100 -; 201.101 -(defmulti sqr 201.102 - "Return the square of x." 201.103 - {:arglists '([x])} 201.104 - type) 201.105 - 201.106 -(defmethod sqr :default 201.107 - [x] 201.108 - (ga/* x x)) 201.109 - 201.110 -; 201.111 -; Approximate equality for use with floating point types 201.112 -; 201.113 -(defn approx= 201.114 - "Return true if the absolute value of the difference between x and y 201.115 - is less than eps." 201.116 - [x y eps] 201.117 - (gc/< (abs (ga/- x y)) eps))
202.1 --- a/src/clojure/contrib/graph.clj Sat Aug 21 06:25:44 2010 -0400 202.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 202.3 @@ -1,228 +0,0 @@ 202.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 202.5 -;; distribution terms for this software are covered by the Eclipse Public 202.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 202.7 -;; be found in the file epl-v10.html at the root of this distribution. By 202.8 -;; using this software in any fashion, you are agreeing to be bound by the 202.9 -;; terms of this license. You must not remove this notice, or any other, 202.10 -;; from this software. 202.11 -;; 202.12 -;; graph 202.13 -;; 202.14 -;; Basic Graph Theory Algorithms 202.15 -;; 202.16 -;; straszheimjeffrey (gmail) 202.17 -;; Created 23 June 2009 202.18 - 202.19 - 202.20 -(ns 202.21 - ^{:author "Jeffrey Straszheim", 202.22 - :doc "Basic graph theory algorithms"} 202.23 - clojure.contrib.graph 202.24 - (use [clojure.set :only (union)])) 202.25 - 202.26 - 202.27 -(defstruct directed-graph 202.28 - :nodes ; The nodes of the graph, a collection 202.29 - :neighbors) ; A function that, given a node returns a collection 202.30 - ; neighbor nodes. 202.31 - 202.32 -(defn get-neighbors 202.33 - "Get the neighbors of a node." 202.34 - [g n] 202.35 - ((:neighbors g) n)) 202.36 - 202.37 - 202.38 -;; Graph Modification 202.39 - 202.40 -(defn reverse-graph 202.41 - "Given a directed graph, return another directed graph with the 202.42 - order of the edges reversed." 202.43 - [g] 202.44 - (let [op (fn [rna idx] 202.45 - (let [ns (get-neighbors g idx) 202.46 - am (fn [m val] 202.47 - (assoc m val (conj (get m val #{}) idx)))] 202.48 - (reduce am rna ns))) 202.49 - rn (reduce op {} (:nodes g))] 202.50 - (struct directed-graph (:nodes g) rn))) 202.51 - 202.52 -(defn add-loops 202.53 - "For each node n, add the edge n->n if not already present." 202.54 - [g] 202.55 - (struct directed-graph 202.56 - (:nodes g) 202.57 - (into {} (map (fn [n] 202.58 - [n (conj (set (get-neighbors g n)) n)]) (:nodes g))))) 202.59 - 202.60 -(defn remove-loops 202.61 - "For each node n, remove any edges n->n." 202.62 - [g] 202.63 - (struct directed-graph 202.64 - (:nodes g) 202.65 - (into {} (map (fn [n] 202.66 - [n (disj (set (get-neighbors g n)) n)]) (:nodes g))))) 202.67 - 202.68 - 202.69 -;; Graph Walk 202.70 - 202.71 -(defn lazy-walk 202.72 - "Return a lazy sequence of the nodes of a graph starting a node n. Optionally, 202.73 - provide a set of visited notes (v) and a collection of nodes to 202.74 - visit (ns)." 202.75 - ([g n] 202.76 - (lazy-walk g [n] #{})) 202.77 - ([g ns v] 202.78 - (lazy-seq (let [s (seq (drop-while v ns)) 202.79 - n (first s) 202.80 - ns (rest s)] 202.81 - (when s 202.82 - (cons n (lazy-walk g (concat (get-neighbors g n) ns) (conj v n)))))))) 202.83 - 202.84 -(defn transitive-closure 202.85 - "Returns the transitive closure of a graph. The neighbors are lazily computed. 202.86 - 202.87 - Note: some version of this algorithm return all edges a->a 202.88 - regardless of whether such loops exist in the original graph. This 202.89 - version does not. Loops will be included only if produced by 202.90 - cycles in the graph. If you have code that depends on such 202.91 - behavior, call (-> g transitive-closure add-loops)" 202.92 - [g] 202.93 - (let [nns (fn [n] 202.94 - [n (delay (lazy-walk g (get-neighbors g n) #{}))]) 202.95 - nbs (into {} (map nns (:nodes g)))] 202.96 - (struct directed-graph 202.97 - (:nodes g) 202.98 - (fn [n] (force (nbs n)))))) 202.99 - 202.100 - 202.101 -;; Strongly Connected Components 202.102 - 202.103 -(defn- post-ordered-visit 202.104 - "Starting at node n, perform a post-ordered walk." 202.105 - [g n [visited acc :as state]] 202.106 - (if (visited n) 202.107 - state 202.108 - (let [[v2 acc2] (reduce (fn [st nd] (post-ordered-visit g nd st)) 202.109 - [(conj visited n) acc] 202.110 - (get-neighbors g n))] 202.111 - [v2 (conj acc2 n)]))) 202.112 - 202.113 -(defn post-ordered-nodes 202.114 - "Return a sequence of indexes of a post-ordered walk of the graph." 202.115 - [g] 202.116 - (fnext (reduce #(post-ordered-visit g %2 %1) 202.117 - [#{} []] 202.118 - (:nodes g)))) 202.119 - 202.120 -(defn scc 202.121 - "Returns, as a sequence of sets, the strongly connected components 202.122 - of g." 202.123 - [g] 202.124 - (let [po (reverse (post-ordered-nodes g)) 202.125 - rev (reverse-graph g) 202.126 - step (fn [stack visited acc] 202.127 - (if (empty? stack) 202.128 - acc 202.129 - (let [[nv comp] (post-ordered-visit rev 202.130 - (first stack) 202.131 - [visited #{}]) 202.132 - ns (remove nv stack)] 202.133 - (recur ns nv (conj acc comp)))))] 202.134 - (step po #{} []))) 202.135 - 202.136 -(defn component-graph 202.137 - "Given a graph, perhaps with cycles, return a reduced graph that is acyclic. 202.138 - Each node in the new graph will be a set of nodes from the old. 202.139 - These sets are the strongly connected components. Each edge will 202.140 - be the union of the corresponding edges of the prior graph." 202.141 - ([g] 202.142 - (component-graph g (scc g))) 202.143 - ([g sccs] 202.144 - (let [find-node-set (fn [n] 202.145 - (some #(if (% n) % nil) sccs)) 202.146 - find-neighbors (fn [ns] 202.147 - (let [nbs1 (map (partial get-neighbors g) ns) 202.148 - nbs2 (map set nbs1) 202.149 - nbs3 (apply union nbs2)] 202.150 - (set (map find-node-set nbs3)))) 202.151 - nm (into {} (map (fn [ns] [ns (find-neighbors ns)]) sccs))] 202.152 - (struct directed-graph (set sccs) nm)))) 202.153 - 202.154 -(defn recursive-component? 202.155 - "Is the component (recieved from scc) self recursive?" 202.156 - [g ns] 202.157 - (or (> (count ns) 1) 202.158 - (let [n (first ns)] 202.159 - (some #(= % n) (get-neighbors g n))))) 202.160 - 202.161 -(defn self-recursive-sets 202.162 - "Returns, as a sequence of sets, the components of a graph that are 202.163 - self-recursive." 202.164 - [g] 202.165 - (filter (partial recursive-component? g) (scc g))) 202.166 - 202.167 - 202.168 -;; Dependency Lists 202.169 - 202.170 -(defn fixed-point 202.171 - "Repeatedly apply fun to data until (equal old-data new-data) 202.172 - returns true. If max iterations occur, it will throw an 202.173 - exception. Set max to nil for unlimited iterations." 202.174 - [data fun max equal] 202.175 - (let [step (fn step [data idx] 202.176 - (when (and idx (= 0 idx)) 202.177 - (throw (Exception. "Fixed point overflow"))) 202.178 - (let [new-data (fun data)] 202.179 - (if (equal data new-data) 202.180 - new-data 202.181 - (recur new-data (and idx (dec idx))))))] 202.182 - (step data max))) 202.183 - 202.184 -(defn- fold-into-sets 202.185 - [priorities] 202.186 - (let [max (inc (apply max 0 (vals priorities))) 202.187 - step (fn [acc [n dep]] 202.188 - (assoc acc dep (conj (acc dep) n)))] 202.189 - (reduce step 202.190 - (vec (replicate max #{})) 202.191 - priorities))) 202.192 - 202.193 -(defn dependency-list 202.194 - "Similar to a topological sort, this returns a vector of sets. The 202.195 - set of nodes at index 0 are independent. The set at index 1 depend 202.196 - on index 0; those at 2 depend on 0 and 1, and so on. Those withing 202.197 - a set have no mutual dependencies. Assume the input graph (which 202.198 - much be acyclic) has an edge a->b when a depends on b." 202.199 - [g] 202.200 - (let [step (fn [d] 202.201 - (let [update (fn [n] 202.202 - (inc (apply max -1 (map d (get-neighbors g n)))))] 202.203 - (into {} (map (fn [[k v]] [k (update k)]) d)))) 202.204 - counts (fixed-point (zipmap (:nodes g) (repeat 0)) 202.205 - step 202.206 - (inc (count (:nodes g))) 202.207 - =)] 202.208 - (fold-into-sets counts))) 202.209 - 202.210 -(defn stratification-list 202.211 - "Similar to dependency-list (see doc), except two graphs are 202.212 - provided. The first is as dependency-list. The second (which may 202.213 - have cycles) provides a partial-dependency relation. If node a 202.214 - depends on node b (meaning an edge a->b exists) in the second 202.215 - graph, node a must be equal or later in the sequence." 202.216 - [g1 g2] 202.217 - (assert (= (-> g1 :nodes set) (-> g2 :nodes set))) 202.218 - (let [step (fn [d] 202.219 - (let [update (fn [n] 202.220 - (max (inc (apply max -1 202.221 - (map d (get-neighbors g1 n)))) 202.222 - (apply max -1 (map d (get-neighbors g2 n)))))] 202.223 - (into {} (map (fn [[k v]] [k (update k)]) d)))) 202.224 - counts (fixed-point (zipmap (:nodes g1) (repeat 0)) 202.225 - step 202.226 - (inc (count (:nodes g1))) 202.227 - =)] 202.228 - (fold-into-sets counts))) 202.229 - 202.230 - 202.231 -;; End of file
203.1 --- a/src/clojure/contrib/greatest_least.clj Sat Aug 21 06:25:44 2010 -0400 203.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 203.3 @@ -1,65 +0,0 @@ 203.4 -(ns 203.5 - ^{:author "Vincent Foley", 203.6 - :doc "Various functions for finding greatest and least values in a collection"} 203.7 - clojure.contrib.greatest-least) 203.8 - 203.9 -(defn- boundary 203.10 - [cmp-fn f & args] 203.11 - (when args 203.12 - (reduce (fn [a b] (if (cmp-fn (compare (f b) (f a))) 203.13 - b 203.14 - a)) args))) 203.15 - 203.16 -(defn greatest-by 203.17 - "Return the argument for which f yields the greatest value." 203.18 - [f & args] 203.19 - (apply boundary pos? f args)) 203.20 - 203.21 -(defn greatest 203.22 - "Return the greatest argument." 203.23 - [& args] 203.24 - (apply greatest-by identity args)) 203.25 - 203.26 -(defn least-by 203.27 - "Return the argument for which f yields the smallest value." 203.28 - [f & args] 203.29 - (apply boundary neg? f args)) 203.30 - 203.31 -(defn least 203.32 - "Return the smallest element." 203.33 - [& args] 203.34 - (apply least-by identity args)) 203.35 - 203.36 - 203.37 -(defn- boundary-all 203.38 - [cmp-fn f & args] 203.39 - (when args 203.40 - (reduce (fn [a b] 203.41 - (if (nil? a) 203.42 - (cons b nil) 203.43 - (let [x (compare (f b) (f (first a)))] 203.44 - (cond (zero? x) (cons b a) 203.45 - (cmp-fn x) (cons b nil) 203.46 - :else a)))) 203.47 - nil 203.48 - args))) 203.49 - 203.50 -(defn all-greatest-by 203.51 - "Return all the elements for which f yields the greatest value." 203.52 - [f & args] 203.53 - (apply boundary-all pos? f args)) 203.54 - 203.55 -(defn all-greatest 203.56 - "Returns all the greatest elements." 203.57 - [& args] 203.58 - (apply all-greatest-by identity args)) 203.59 - 203.60 -(defn all-least-by 203.61 - "Return all the elements for which f yields the least value." 203.62 - [f & args] 203.63 - (apply boundary-all neg? f args)) 203.64 - 203.65 -(defn all-least 203.66 - "Returns all the least elements." 203.67 - [& args] 203.68 - (apply all-least-by identity args))
204.1 --- a/src/clojure/contrib/http/agent.clj Sat Aug 21 06:25:44 2010 -0400 204.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 204.3 @@ -1,386 +0,0 @@ 204.4 -;;; http/agent.clj: agent-based asynchronous HTTP client 204.5 - 204.6 -;; by Stuart Sierra, http://stuartsierra.com/ 204.7 -;; August 17, 2009 204.8 - 204.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 204.10 -;; and distribution terms for this software are covered by the Eclipse 204.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 204.12 -;; which can be found in the file epl-v10.html at the root of this 204.13 -;; distribution. By using this software in any fashion, you are 204.14 -;; agreeing to be bound by the terms of this license. You must not 204.15 -;; remove this notice, or any other, from this software. 204.16 - 204.17 -;; DEPRECATED IN 1.2. Use direct Java bits, or take a look at 204.18 -;; http://github.com/technomancy/clojure-http-client 204.19 - 204.20 -(ns ^{:deprecated "1.2" 204.21 - :doc "Agent-based asynchronous HTTP client. 204.22 - 204.23 - This is a HTTP client library based on Java's HttpURLConnection 204.24 - class and Clojure's Agent system. It allows you to make multiple 204.25 - HTTP requests in parallel. 204.26 - 204.27 - Start an HTTP request with the 'http-agent' function, which 204.28 - immediately returns a Clojure Agent. You will never deref this 204.29 - agent; that is handled by the accessor functions. The agent will 204.30 - execute the HTTP request on a separate thread. 204.31 - 204.32 - If you pass a :handler function to http-agent, that function will be 204.33 - called as soon as the HTTP response body is ready. The handler 204.34 - function is called with one argument, the HTTP agent itself. The 204.35 - handler can read the response body by calling the 'stream' function 204.36 - on the agent. 204.37 - 204.38 - The value returned by the handler function becomes part of the state 204.39 - of the agent, and you can retrieve it with the 'result' function. 204.40 - If you call 'result' before the HTTP request has finished, it will 204.41 - block until the handler function returns. 204.42 - 204.43 - If you don't provide a handler function, the default handler will 204.44 - buffer the entire response body in memory, which you can retrieve 204.45 - with the 'bytes', 'string', or 'stream' functions. Like 'result', 204.46 - these functions will block until the HTTP request is completed. 204.47 - 204.48 - If you want to check if an HTTP request is finished without 204.49 - blocking, use the 'done?' function. 204.50 - 204.51 - A single GET request could be as simple as: 204.52 - 204.53 - (string (http-agent \"http://www.stuartsierra.com/\")) 204.54 - 204.55 - A simple POST might look like: 204.56 - 204.57 - (http-agent \"http...\" :method \"POST\" :body \"foo=1\") 204.58 - 204.59 - And you could write the response directly to a file like this: 204.60 - 204.61 - (require '[clojure.contrib.io :as d]) 204.62 - 204.63 - (http-agent \"http...\" 204.64 - :handler (fn [agnt] 204.65 - (with-open [w (d/writer \"/tmp/out\")] 204.66 - (d/copy (stream agnt) w)))) 204.67 -" 204.68 - :author "Stuart Sierra" 204.69 - } 204.70 - 204.71 - clojure.contrib.http.agent 204.72 - (:refer-clojure :exclude [bytes]) 204.73 - (:require [clojure.contrib.http.connection :as c] 204.74 - [clojure.contrib.io :as duck]) 204.75 - (:import (java.io InputStream ByteArrayOutputStream 204.76 - ByteArrayInputStream) 204.77 - (java.net HttpURLConnection))) 204.78 - 204.79 - 204.80 -;;; PRIVATE 204.81 - 204.82 -(declare result stream) 204.83 - 204.84 -(defn- setup-http-connection 204.85 - "Sets the instance method, redirect behavior, and request headers of 204.86 - the HttpURLConnection." 204.87 - [^HttpURLConnection conn options] 204.88 - (when-let [t (:connect-timeout options)] 204.89 - (.setConnectTimeout conn t)) 204.90 - (when-let [t (:read-timeout options)] 204.91 - (.setReadTimeout conn t)) 204.92 - (.setRequestMethod conn (:method options)) 204.93 - (.setInstanceFollowRedirects conn (:follow-redirects options)) 204.94 - (doseq [[name value] (:headers options)] 204.95 - (.setRequestProperty conn name value))) 204.96 - 204.97 -(defn- start-request 204.98 - "Agent action that starts sending the HTTP request." 204.99 - [state options] 204.100 - (let [conn (::connection state)] 204.101 - (setup-http-connection conn options) 204.102 - (c/start-http-connection conn (:body options)) 204.103 - (assoc state ::state ::started))) 204.104 - 204.105 -(defn- connection-success? [^HttpURLConnection conn] 204.106 - "Returns true if the HttpURLConnection response code is in the 2xx 204.107 - range." 204.108 - (= 2 (quot (.getResponseCode conn) 100))) 204.109 - 204.110 -(defn- open-response 204.111 - "Agent action that opens the response body stream on the HTTP 204.112 - request; this will block until the response stream is available." ; 204.113 - [state options] 204.114 - (let [^HttpURLConnection conn (::connection state)] 204.115 - (assoc state 204.116 - ::response-stream (if (connection-success? conn) 204.117 - (.getInputStream conn) 204.118 - (.getErrorStream conn)) 204.119 - ::state ::receiving))) 204.120 - 204.121 -(defn- handle-response 204.122 - "Agent action that calls the provided handler function, with no 204.123 - arguments, and sets the ::result key of the agent to the handler's 204.124 - return value." 204.125 - [state handler options] 204.126 - (let [conn (::connection state)] 204.127 - (assoc state 204.128 - ::result (handler) 204.129 - ::state ::finished))) 204.130 - 204.131 -(defn- disconnect 204.132 - "Agent action that closes the response body stream and disconnects 204.133 - the HttpURLConnection." 204.134 - [state options] 204.135 - (when (::response-stream state) 204.136 - (.close ^InputStream (::response-stream state))) 204.137 - (.disconnect ^HttpURLConnection (::connection state)) 204.138 - (assoc state 204.139 - ::response-stream nil 204.140 - ::state ::disconnected)) 204.141 - 204.142 -(defn- status-in-range? 204.143 - "Returns true if the response status of the HTTP agent begins with 204.144 - digit, an Integer." 204.145 - [digit http-agnt] 204.146 - (= digit (quot (.getResponseCode 204.147 - ^HttpURLConnection (::connection @http-agnt)) 204.148 - 100))) 204.149 - 204.150 -(defn- ^ByteArrayOutputStream get-byte-buffer [http-agnt] 204.151 - (let [buffer (result http-agnt)] 204.152 - (if (instance? ByteArrayOutputStream buffer) 204.153 - buffer 204.154 - (throw (Exception. "Handler result was not a ByteArrayOutputStream"))))) 204.155 - 204.156 - 204.157 -(defn buffer-bytes 204.158 - "The default HTTP agent result handler; it collects the response 204.159 - body in a java.io.ByteArrayOutputStream, which can later be 204.160 - retrieved with the 'stream', 'string', and 'bytes' functions." 204.161 - [http-agnt] 204.162 - (let [output (ByteArrayOutputStream.)] 204.163 - (duck/copy (or (stream http-agnt) "") output) 204.164 - output)) 204.165 - 204.166 - 204.167 -;;; CONSTRUCTOR 204.168 - 204.169 -(def *http-agent-defaults* 204.170 - {:method "GET" 204.171 - :headers {} 204.172 - :body nil 204.173 - :connect-timeout 0 204.174 - :read-timeout 0 204.175 - :follow-redirects true 204.176 - :handler buffer-bytes}) 204.177 - 204.178 -(defn http-agent 204.179 - "Creates (and immediately returns) an Agent representing an HTTP 204.180 - request running in a new thread. 204.181 - 204.182 - options are key/value pairs: 204.183 - 204.184 - :method string 204.185 - 204.186 - The HTTP method name. Default is \"GET\". 204.187 - 204.188 - :headers h 204.189 - 204.190 - HTTP headers, as a Map or a sequence of pairs like 204.191 - ([key1,value1], [key2,value2]) Default is nil. 204.192 - 204.193 - :body b 204.194 - 204.195 - HTTP request entity body, one of nil, String, byte[], InputStream, 204.196 - Reader, or File. Default is nil. 204.197 - 204.198 - :connect-timeout int 204.199 - 204.200 - Timeout value, in milliseconds, when opening a connection to the 204.201 - URL. Default is zero, meaning no timeout. 204.202 - 204.203 - :read-timeout int 204.204 - 204.205 - Timeout value, in milliseconds, when reading data from the 204.206 - connection. Default is zero, meaning no timeout. 204.207 - 204.208 - :follow-redirects boolean 204.209 - 204.210 - If true, HTTP 3xx redirects will be followed automatically. Default 204.211 - is true. 204.212 - 204.213 - :handler f 204.214 - 204.215 - Function to be called when the HTTP response body is ready. If you 204.216 - do not provide a handler function, the default is to buffer the 204.217 - entire response body in memory. 204.218 - 204.219 - The handler function will be called with the HTTP agent as its 204.220 - argument, and can use the 'stream' function to read the response 204.221 - body. The return value of this function will be stored in the state 204.222 - of the agent and can be retrieved with the 'result' function. Any 204.223 - exceptions thrown by this function will be added to the agent's 204.224 - error queue (see agent-errors). The default function collects the 204.225 - response stream in a memory buffer. 204.226 - " 204.227 - ([uri & options] 204.228 - (let [opts (merge *http-agent-defaults* (apply array-map options))] 204.229 - (let [a (agent {::connection (c/http-connection uri) 204.230 - ::state ::created 204.231 - ::uri uri 204.232 - ::options opts})] 204.233 - (send-off a start-request opts) 204.234 - (send-off a open-response opts) 204.235 - (send-off a handle-response (partial (:handler opts) a) opts) 204.236 - (send-off a disconnect opts))))) 204.237 - 204.238 - 204.239 -;;; RESPONSE BODY ACCESSORS 204.240 - 204.241 -(defn result 204.242 - "Returns the value returned by the :handler function of the HTTP 204.243 - agent; blocks until the HTTP request is completed. The default 204.244 - handler function returns a ByteArrayOutputStream." 204.245 - [http-agnt] 204.246 - (await http-agnt) 204.247 - (::result @http-agnt)) 204.248 - 204.249 -(defn stream 204.250 - "Returns an InputStream of the HTTP response body. When called by 204.251 - the handler function passed to http-agent, this is the raw 204.252 - HttpURLConnection stream. 204.253 - 204.254 - If the default handler function was used, this function returns a 204.255 - ByteArrayInputStream on the buffered response body." 204.256 - [http-agnt] 204.257 - (let [a @http-agnt] 204.258 - (if (= (::state a) ::receiving) 204.259 - (::response-stream a) 204.260 - (ByteArrayInputStream. 204.261 - (.toByteArray (get-byte-buffer http-agnt)))))) 204.262 - 204.263 -(defn bytes 204.264 - "Returns a Java byte array of the content returned by the server; 204.265 - nil if the content is not yet available." 204.266 - [http-agnt] 204.267 - (.toByteArray (get-byte-buffer http-agnt))) 204.268 - 204.269 -(defn string 204.270 - "Returns the HTTP response body as a string, using the given 204.271 - encoding. 204.272 - 204.273 - If no encoding is given, uses the encoding specified in the server 204.274 - headers, or clojure.contrib.io/*default-encoding* if it is 204.275 - not specified." 204.276 - ([http-agnt] 204.277 - (await http-agnt) ;; have to wait for Content-Encoding 204.278 - (string http-agnt (or (.getContentEncoding 204.279 - ^HttpURLConnection (::connection @http-agnt)) 204.280 - duck/*default-encoding*))) 204.281 - ([http-agnt ^String encoding] 204.282 - (.toString (get-byte-buffer http-agnt) encoding))) 204.283 - 204.284 - 204.285 -;;; REQUEST ACCESSORS 204.286 - 204.287 -(defn request-uri 204.288 - "Returns the URI/URL requested by this HTTP agent, as a String." 204.289 - [http-agnt] 204.290 - (::uri @http-agnt)) 204.291 - 204.292 -(defn request-headers 204.293 - "Returns the request headers specified for this HTTP agent." 204.294 - [http-agnt] 204.295 - (:headers (::options @http-agnt))) 204.296 - 204.297 -(defn method 204.298 - "Returns the HTTP method name used by this HTTP agent, as a String." 204.299 - [http-agnt] 204.300 - (:method (::options @http-agnt))) 204.301 - 204.302 -(defn request-body 204.303 - "Returns the HTTP request body given to this HTTP agent. 204.304 - 204.305 - Note: if the request body was an InputStream or a Reader, it will no 204.306 - longer be usable." 204.307 - [http-agnt] 204.308 - (:body (::options @http-agnt))) 204.309 - 204.310 - 204.311 -;;; RESPONSE ACCESSORS 204.312 - 204.313 -(defn done? 204.314 - "Returns true if the HTTP request/response has completed." 204.315 - [http-agnt] 204.316 - (if (#{::finished ::disconnected} (::state @http-agnt)) 204.317 - true false)) 204.318 - 204.319 -(defn status 204.320 - "Returns the HTTP response status code (e.g. 200, 404) for this 204.321 - request, as an Integer, or nil if the status has not yet been 204.322 - received." 204.323 - [http-agnt] 204.324 - (when (done? http-agnt) 204.325 - (.getResponseCode ^HttpURLConnection (::connection @http-agnt)))) 204.326 - 204.327 -(defn message 204.328 - "Returns the HTTP response message (e.g. 'Not Found'), for this 204.329 - request, or nil if the response has not yet been received." 204.330 - [http-agnt] 204.331 - (when (done? http-agnt) 204.332 - (.getResponseMessage ^HttpURLConnection (::connection @http-agnt)))) 204.333 - 204.334 -(defn headers 204.335 - "Returns a map of HTTP response headers. Header names are converted 204.336 - to keywords in all lower-case Header values are strings. If a 204.337 - header appears more than once, only the last value is returned." 204.338 - [http-agnt] 204.339 - (reduce (fn [m [^String k v]] 204.340 - (assoc m (when k (keyword (.toLowerCase k))) (last v))) 204.341 - {} (.getHeaderFields 204.342 - ^HttpURLConnection (::connection @http-agnt)))) 204.343 - 204.344 -(defn headers-seq 204.345 - "Returns the HTTP response headers in order as a sequence of 204.346 - [String,String] pairs. The first 'header' name may be null for the 204.347 - HTTP status line." 204.348 - [http-agnt] 204.349 - (let [^HttpURLConnection conn (::connection @http-agnt) 204.350 - f (fn thisfn [^Integer i] 204.351 - ;; Get value first because first key may be nil. 204.352 - (when-let [value (.getHeaderField conn i)] 204.353 - (cons [(.getHeaderFieldKey conn i) value] 204.354 - (thisfn (inc i)))))] 204.355 - (lazy-seq (f 0)))) 204.356 - 204.357 - 204.358 -;;; RESPONSE STATUS CODE ACCESSORS 204.359 - 204.360 -(defn success? 204.361 - "Returns true if the HTTP response code was in the 200-299 range." 204.362 - [http-agnt] 204.363 - (status-in-range? 2 http-agnt)) 204.364 - 204.365 -(defn redirect? 204.366 - "Returns true if the HTTP response code was in the 300-399 range. 204.367 - 204.368 - Note: if the :follow-redirects option was true (the default), 204.369 - redirects will be followed automatically and a the agent will never 204.370 - return a 3xx response code." 204.371 - [http-agnt] 204.372 - (status-in-range? 3 http-agnt)) 204.373 - 204.374 -(defn client-error? 204.375 - "Returns true if the HTTP response code was in the 400-499 range." 204.376 - [http-agnt] 204.377 - (status-in-range? 4 http-agnt)) 204.378 - 204.379 -(defn server-error? 204.380 - "Returns true if the HTTP response code was in the 500-599 range." 204.381 - [http-agnt] 204.382 - (status-in-range? 5 http-agnt)) 204.383 - 204.384 -(defn error? 204.385 - "Returns true if the HTTP response code was in the 400-499 range OR 204.386 - the 500-599 range." 204.387 - [http-agnt] 204.388 - (or (client-error? http-agnt) 204.389 - (server-error? http-agnt)))
205.1 --- a/src/clojure/contrib/http/connection.clj Sat Aug 21 06:25:44 2010 -0400 205.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 205.3 @@ -1,62 +0,0 @@ 205.4 -;;; http/connection.clj: low-level HTTP client API around HttpURLConnection 205.5 - 205.6 -;; by Stuart Sierra, http://stuartsierra.com/ 205.7 -;; June 8, 2009 205.8 - 205.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 205.10 -;; and distribution terms for this software are covered by the Eclipse 205.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 205.12 -;; which can be found in the file epl-v10.html at the root of this 205.13 -;; distribution. By using this software in any fashion, you are 205.14 -;; agreeing to be bound by the terms of this license. You must not 205.15 -;; remove this notice, or any other, from this software. 205.16 - 205.17 -;; DEPRECATED IN 1.2. Use direct Java bits, or take a look at 205.18 -;; http://github.com/technomancy/clojure-http-client 205.19 - 205.20 -(ns ^{:deprecated "1.2" 205.21 - :doc "Low-level HTTP client API around HttpURLConnection"} 205.22 - clojure.contrib.http.connection 205.23 - (:require [clojure.contrib.io :as duck]) 205.24 - (:import (java.net URI URL HttpURLConnection) 205.25 - (java.io File InputStream Reader))) 205.26 - 205.27 -(defn http-connection 205.28 - "Opens an HttpURLConnection at the URL, handled by as-url." 205.29 - [url] 205.30 - (.openConnection (duck/as-url url))) 205.31 - 205.32 -(defmulti 205.33 - ^{:doc "Transmits a request entity body."} 205.34 - send-request-entity (fn [conn entity] (type entity))) 205.35 - 205.36 -(defmethod send-request-entity duck/*byte-array-type* [^HttpURLConnection conn entity] 205.37 - (.setFixedLengthStreamingMode conn (count entity)) 205.38 - (.connect conn) 205.39 - (duck/copy entity (.getOutputStream conn))) 205.40 - 205.41 -(defmethod send-request-entity String [conn ^String entity] 205.42 - (send-request-entity conn (.getBytes entity duck/*default-encoding*))) 205.43 - 205.44 -(defmethod send-request-entity File [^HttpURLConnection conn ^File entity] 205.45 - (.setFixedLengthStreamingMode conn (.length entity)) 205.46 - (.connect conn) 205.47 - (duck/copy entity (.getOutputStream conn))) 205.48 - 205.49 -(defmethod send-request-entity InputStream [^HttpURLConnection conn entity] 205.50 - (.setChunkedStreamingMode conn -1) 205.51 - (.connect conn) 205.52 - (duck/copy entity (.getOutputStream conn))) 205.53 - 205.54 -(defmethod send-request-entity Reader [^HttpURLConnection conn entity] 205.55 - (.setChunkedStreamingMode conn -1) 205.56 - (.connect conn) 205.57 - (duck/copy entity (.getOutputStream conn))) 205.58 - 205.59 -(defn start-http-connection 205.60 - ([^HttpURLConnection conn] (.connect conn)) 205.61 - ([^HttpURLConnection conn request-entity-body] 205.62 - (if request-entity-body 205.63 - (do (.setDoOutput conn true) 205.64 - (send-request-entity conn request-entity-body)) 205.65 - (.connect conn))))
206.1 --- a/src/clojure/contrib/import_static.clj Sat Aug 21 06:25:44 2010 -0400 206.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 206.3 @@ -1,63 +0,0 @@ 206.4 -;;; import_static.clj -- import static Java methods/fields into Clojure 206.5 - 206.6 -;; by Stuart Sierra, http://stuartsierra.com/ 206.7 -;; June 1, 2008 206.8 - 206.9 -;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use 206.10 -;; and distribution terms for this software are covered by the Eclipse 206.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 206.12 -;; which can be found in the file epl-v10.html at the root of this 206.13 -;; distribution. By using this software in any fashion, you are 206.14 -;; agreeing to be bound by the terms of this license. You must not 206.15 -;; remove this notice, or any other, from this software. 206.16 - 206.17 - 206.18 - 206.19 -(ns 206.20 - ^{:author "Stuart Sierra", 206.21 - :doc "Import static Java methods/fields into Clojure"} 206.22 - clojure.contrib.import-static 206.23 - (:use clojure.set)) 206.24 - 206.25 -(defmacro import-static 206.26 - "Imports the named static fields and/or static methods of the class 206.27 - as (private) symbols in the current namespace. 206.28 - 206.29 - Example: 206.30 - user=> (import-static java.lang.Math PI sqrt) 206.31 - nil 206.32 - user=> PI 206.33 - 3.141592653589793 206.34 - user=> (sqrt 16) 206.35 - 4.0 206.36 - 206.37 - Note: The class name must be fully qualified, even if it has already 206.38 - been imported. Static methods are defined as MACROS, not 206.39 - first-class fns." 206.40 - [class & fields-and-methods] 206.41 - (let [only (set (map str fields-and-methods)) 206.42 - the-class (. Class forName (str class)) 206.43 - static? (fn [x] 206.44 - (. java.lang.reflect.Modifier 206.45 - (isStatic (. x (getModifiers))))) 206.46 - statics (fn [array] 206.47 - (set (map (memfn getName) 206.48 - (filter static? array)))) 206.49 - all-fields (statics (. the-class (getFields))) 206.50 - all-methods (statics (. the-class (getMethods))) 206.51 - fields-to-do (intersection all-fields only) 206.52 - methods-to-do (intersection all-methods only) 206.53 - make-sym (fn [string] 206.54 - (with-meta (symbol string) {:private true})) 206.55 - import-field (fn [name] 206.56 - (list 'def (make-sym name) 206.57 - (list '. class (symbol name)))) 206.58 - import-method (fn [name] 206.59 - (list 'defmacro (make-sym name) 206.60 - '[& args] 206.61 - (list 'list ''. (list 'quote class) 206.62 - (list 'apply 'list 206.63 - (list 'quote (symbol name)) 206.64 - 'args))))] 206.65 - `(do ~@(map import-field fields-to-do) 206.66 - ~@(map import-method methods-to-do))))
207.1 --- a/src/clojure/contrib/io.clj Sat Aug 21 06:25:44 2010 -0400 207.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 207.3 @@ -1,564 +0,0 @@ 207.4 -;;; io.clj -- duck-typed I/O streams for Clojure 207.5 - 207.6 -;; by Stuart Sierra, http://stuartsierra.com/ 207.7 -;; May 13, 2009 207.8 - 207.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 207.10 -;; and distribution terms for this software are covered by the Eclipse 207.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 207.12 -;; which can be found in the file epl-v10.html at the root of this 207.13 -;; distribution. By using this software in any fashion, you are 207.14 -;; agreeing to be bound by the terms of this license. You must not 207.15 -;; remove this notice, or any other, from this software. 207.16 - 207.17 - 207.18 -;; This file defines "duck-typed" I/O utility functions for Clojure. 207.19 -;; The 'reader' and 'writer' functions will open and return an 207.20 -;; instance of java.io.BufferedReader and java.io.BufferedWriter, 207.21 -;; respectively, for a variety of argument types -- filenames as 207.22 -;; strings, URLs, java.io.File's, etc. 'reader' even works on http 207.23 -;; URLs. 207.24 -;; 207.25 -;; Note: this is not really "duck typing" as implemented in languages 207.26 -;; like Ruby. A better name would have been "do-what-I-mean-streams" 207.27 -;; or "just-give-me-a-stream", but ducks are funnier. 207.28 - 207.29 - 207.30 -;; CHANGE LOG 207.31 -;; 207.32 -;; July 23, 2010: Most functions here are deprecated. Use 207.33 -;; clojure.java.io 207.34 -;; 207.35 -;; May 13, 2009: added functions to open writers for appending 207.36 -;; 207.37 -;; May 3, 2009: renamed file to file-str, for compatibility with 207.38 -;; clojure.contrib.java. reader/writer no longer use this 207.39 -;; function. 207.40 -;; 207.41 -;; February 16, 2009: (lazy branch) fixed read-lines to work with lazy 207.42 -;; Clojure. 207.43 -;; 207.44 -;; January 10, 2009: added *default-encoding*, so streams are always 207.45 -;; opened as UTF-8. 207.46 -;; 207.47 -;; December 19, 2008: rewrote reader and writer as multimethods; added 207.48 -;; slurp*, file, and read-lines 207.49 -;; 207.50 -;; April 8, 2008: first version 207.51 - 207.52 - 207.53 - 207.54 -(ns 207.55 - ^{:author "Stuart Sierra", 207.56 - :doc "This file defines polymorphic I/O utility functions for Clojure. 207.57 - 207.58 - The Streams protocol defines reader, writer, input-stream and 207.59 - output-stream methods that return BufferedReader, BufferedWriter, 207.60 - BufferedInputStream and BufferedOutputStream instances (respectively), 207.61 - with default implementations extended to a variety of argument 207.62 - types: URLs or filenames as strings, java.io.File's, Sockets, etc."} 207.63 - clojure.contrib.io 207.64 - (:refer-clojure :exclude (spit)) 207.65 - (:import 207.66 - (java.io Reader InputStream InputStreamReader PushbackReader 207.67 - BufferedReader File OutputStream 207.68 - OutputStreamWriter BufferedWriter Writer 207.69 - FileInputStream FileOutputStream ByteArrayOutputStream 207.70 - StringReader ByteArrayInputStream 207.71 - BufferedInputStream BufferedOutputStream 207.72 - CharArrayReader) 207.73 - (java.net URI URL MalformedURLException Socket))) 207.74 - 207.75 - 207.76 -(def 207.77 - ^{:doc "Name of the default encoding to use when reading & writing. 207.78 - Default is UTF-8." 207.79 - :tag "java.lang.String"} 207.80 - *default-encoding* "UTF-8") 207.81 - 207.82 -(def 207.83 - ^{:doc "Size, in bytes or characters, of the buffer used when 207.84 - copying streams."} 207.85 - *buffer-size* 1024) 207.86 - 207.87 -(def 207.88 - ^{:doc "Type object for a Java primitive byte array."} 207.89 - *byte-array-type* (class (make-array Byte/TYPE 0))) 207.90 - 207.91 -(def 207.92 - ^{:doc "Type object for a Java primitive char array."} 207.93 - *char-array-type* (class (make-array Character/TYPE 0))) 207.94 - 207.95 - 207.96 -(defn ^File file-str 207.97 - "Concatenates args as strings and returns a java.io.File. Replaces 207.98 - all / and \\ with File/separatorChar. Replaces ~ at the start of 207.99 - the path with the user.home system property." 207.100 - [& args] 207.101 - (let [^String s (apply str args) 207.102 - s (.replace s \\ File/separatorChar) 207.103 - s (.replace s \/ File/separatorChar) 207.104 - s (if (.startsWith s "~") 207.105 - (str (System/getProperty "user.home") 207.106 - File/separator (subs s 1)) 207.107 - s)] 207.108 - (File. s))) 207.109 - 207.110 -(def 207.111 - ^{:doc "If true, writer, output-stream and spit will open files in append mode. 207.112 - Defaults to false. Instead of binding this var directly, use append-writer, 207.113 - append-output-stream or append-spit." 207.114 - :tag "java.lang.Boolean"} 207.115 - *append* false) 207.116 - 207.117 -(defn- assert-not-appending [] 207.118 - (when *append* 207.119 - (throw (Exception. "Cannot change an open stream to append mode.")))) 207.120 - 207.121 -;; @todo -- Both simple and elaborate methods for controlling buffering of 207.122 -;; in the Streams protocol were implemented, considered, and postponed 207.123 -;; see http://groups.google.com/group/clojure-dev/browse_frm/thread/3e39e9b3982f542b 207.124 -(defprotocol Streams 207.125 - (reader [x] 207.126 - "Attempts to coerce its argument into an open java.io.Reader. 207.127 - The default implementations of this protocol always return a 207.128 - java.io.BufferedReader. 207.129 - 207.130 - Default implementations are provided for Reader, BufferedReader, 207.131 - InputStream, File, URI, URL, Socket, byte arrays, character arrays, 207.132 - and String. 207.133 - 207.134 - If argument is a String, it tries to resolve it first as a URI, then 207.135 - as a local file name. URIs with a 'file' protocol are converted to 207.136 - local file names. If this fails, a final attempt is made to resolve 207.137 - the string as a resource on the CLASSPATH. 207.138 - 207.139 - Uses *default-encoding* as the text encoding. 207.140 - 207.141 - Should be used inside with-open to ensure the Reader is properly 207.142 - closed.") 207.143 - (writer [x] 207.144 - "Attempts to coerce its argument into an open java.io.Writer. 207.145 - The default implementations of this protocol always return a 207.146 - java.io.BufferedWriter. 207.147 - 207.148 - Default implementations are provided for Writer, BufferedWriter, 207.149 - OutputStream, File, URI, URL, Socket, and String. 207.150 - 207.151 - If the argument is a String, it tries to resolve it first as a URI, then 207.152 - as a local file name. URIs with a 'file' protocol are converted to 207.153 - local file names. 207.154 - 207.155 - Should be used inside with-open to ensure the Writer is properly 207.156 - closed.") 207.157 - (input-stream [x] 207.158 - "Attempts to coerce its argument into an open java.io.InputStream. 207.159 - The default implementations of this protocol always return a 207.160 - java.io.BufferedInputStream. 207.161 - 207.162 - Default implementations are defined for OutputStream, File, URI, URL, 207.163 - Socket, byte array, and String arguments. 207.164 - 207.165 - If the argument is a String, it tries to resolve it first as a URI, then 207.166 - as a local file name. URIs with a 'file' protocol are converted to 207.167 - local file names. 207.168 - 207.169 - Should be used inside with-open to ensure the InputStream is properly 207.170 - closed.") 207.171 - (output-stream [x] 207.172 - "Attempts to coerce its argument into an open java.io.OutputStream. 207.173 - The default implementations of this protocol always return a 207.174 - java.io.BufferedOutputStream. 207.175 - 207.176 - Default implementations are defined for OutputStream, File, URI, URL, 207.177 - Socket, and String arguments. 207.178 - 207.179 - If the argument is a String, it tries to resolve it first as a URI, then 207.180 - as a local file name. URIs with a 'file' protocol are converted to 207.181 - local file names. 207.182 - 207.183 - Should be used inside with-open to ensure the OutputStream is 207.184 - properly closed.")) 207.185 - 207.186 -(def default-streams-impl 207.187 - {:reader #(reader (input-stream %)) 207.188 - :writer #(writer (output-stream %)) 207.189 - :input-stream #(throw (Exception. (str "Cannot open <" (pr-str %) "> as an InputStream."))) 207.190 - :output-stream #(throw (Exception. (str "Cannot open <" (pr-str %) "> as an OutputStream.")))}) 207.191 - 207.192 -(extend File 207.193 - Streams 207.194 - (assoc default-streams-impl 207.195 - :input-stream #(input-stream (FileInputStream. ^File %)) 207.196 - :output-stream #(let [stream (FileOutputStream. ^File % *append*)] 207.197 - (binding [*append* false] 207.198 - (output-stream stream))))) 207.199 -(extend URL 207.200 - Streams 207.201 - (assoc default-streams-impl 207.202 - :input-stream (fn [^URL x] 207.203 - (input-stream (if (= "file" (.getProtocol x)) 207.204 - (FileInputStream. (.getPath x)) 207.205 - (.openStream x)))) 207.206 - :output-stream (fn [^URL x] 207.207 - (if (= "file" (.getProtocol x)) 207.208 - (output-stream (File. (.getPath x))) 207.209 - (throw (Exception. (str "Can not write to non-file URL <" x ">"))))))) 207.210 -(extend URI 207.211 - Streams 207.212 - (assoc default-streams-impl 207.213 - :input-stream #(input-stream (.toURL ^URI %)) 207.214 - :output-stream #(output-stream (.toURL ^URI %)))) 207.215 -(extend String 207.216 - Streams 207.217 - (assoc default-streams-impl 207.218 - :input-stream #(try 207.219 - (input-stream (URL. %)) 207.220 - (catch MalformedURLException e 207.221 - (input-stream (File. ^String %)))) 207.222 - :output-stream #(try 207.223 - (output-stream (URL. %)) 207.224 - (catch MalformedURLException err 207.225 - (output-stream (File. ^String %)))))) 207.226 -(extend Socket 207.227 - Streams 207.228 - (assoc default-streams-impl 207.229 - :input-stream #(.getInputStream ^Socket %) 207.230 - :output-stream #(output-stream (.getOutputStream ^Socket %)))) 207.231 -(extend *byte-array-type* 207.232 - Streams 207.233 - (assoc default-streams-impl :input-stream #(input-stream (ByteArrayInputStream. %)))) 207.234 -(extend *char-array-type* 207.235 - Streams 207.236 - (assoc default-streams-impl :reader #(reader (CharArrayReader. %)))) 207.237 -(extend Object 207.238 - Streams 207.239 - default-streams-impl) 207.240 - 207.241 -(extend Reader 207.242 - Streams 207.243 - (assoc default-streams-impl :reader #(BufferedReader. %))) 207.244 -(extend BufferedReader 207.245 - Streams 207.246 - (assoc default-streams-impl :reader identity)) 207.247 -(defn- inputstream->reader 207.248 - [^InputStream is] 207.249 - (reader (InputStreamReader. is *default-encoding*))) 207.250 -(extend InputStream 207.251 - Streams 207.252 - (assoc default-streams-impl :input-stream #(BufferedInputStream. %) 207.253 - :reader inputstream->reader)) 207.254 -(extend BufferedInputStream 207.255 - Streams 207.256 - (assoc default-streams-impl 207.257 - :input-stream identity 207.258 - :reader inputstream->reader)) 207.259 - 207.260 -(extend Writer 207.261 - Streams 207.262 - (assoc default-streams-impl :writer #(do (assert-not-appending) 207.263 - (BufferedWriter. %)))) 207.264 -(extend BufferedWriter 207.265 - Streams 207.266 - (assoc default-streams-impl :writer #(do (assert-not-appending) %))) 207.267 -(defn- outputstream->writer 207.268 - [^OutputStream os] 207.269 - (assert-not-appending) 207.270 - (writer (OutputStreamWriter. os *default-encoding*))) 207.271 -(extend OutputStream 207.272 - Streams 207.273 - (assoc default-streams-impl 207.274 - :output-stream #(do (assert-not-appending) 207.275 - (BufferedOutputStream. %)) 207.276 - :writer outputstream->writer)) 207.277 -(extend BufferedOutputStream 207.278 - Streams 207.279 - (assoc default-streams-impl 207.280 - :output-stream #(do (assert-not-appending) %) 207.281 - :writer outputstream->writer)) 207.282 - 207.283 -(defn append-output-stream 207.284 - "Like output-stream but opens file for appending. Does not work on streams 207.285 - that are already open." 207.286 - {:deprecated "1.2"} 207.287 - [x] 207.288 - (binding [*append* true] 207.289 - (output-stream x))) 207.290 - 207.291 -(defn append-writer 207.292 - "Like writer but opens file for appending. Does not work on streams 207.293 - that are already open." 207.294 - {:deprecated "1.2"} 207.295 - [x] 207.296 - (binding [*append* true] 207.297 - (writer x))) 207.298 - 207.299 -(defn write-lines 207.300 - "Writes lines (a seq) to f, separated by newlines. f is opened with 207.301 - writer, and automatically closed at the end of the sequence." 207.302 - [f lines] 207.303 - (with-open [^BufferedWriter writer (writer f)] 207.304 - (loop [lines lines] 207.305 - (when-let [line (first lines)] 207.306 - (.write writer (str line)) 207.307 - (.newLine writer) 207.308 - (recur (rest lines)))))) 207.309 - 207.310 -(defn read-lines 207.311 - "Like clojure.core/line-seq but opens f with reader. Automatically 207.312 - closes the reader AFTER YOU CONSUME THE ENTIRE SEQUENCE." 207.313 - [f] 207.314 - (let [read-line (fn this [^BufferedReader rdr] 207.315 - (lazy-seq 207.316 - (if-let [line (.readLine rdr)] 207.317 - (cons line (this rdr)) 207.318 - (.close rdr))))] 207.319 - (read-line (reader f)))) 207.320 - 207.321 -(defn ^String slurp* 207.322 - "Like clojure.core/slurp but opens f with reader." 207.323 - {:deprecated "1.2"} 207.324 - [f] 207.325 - (with-open [^BufferedReader r (reader f)] 207.326 - (let [sb (StringBuilder.)] 207.327 - (loop [c (.read r)] 207.328 - (if (neg? c) 207.329 - (str sb) 207.330 - (do (.append sb (char c)) 207.331 - (recur (.read r)))))))) 207.332 - 207.333 -(defn spit 207.334 - "Opposite of slurp. Opens f with writer, writes content, then 207.335 - closes f." 207.336 - {:deprecated "1.2"} 207.337 - [f content] 207.338 - (with-open [^Writer w (writer f)] 207.339 - (.write w content))) 207.340 - 207.341 -(defn append-spit 207.342 - "Like spit but appends to file." 207.343 - {:deprecated "1.2"} 207.344 - [f content] 207.345 - (with-open [^Writer w (append-writer f)] 207.346 - (.write w content))) 207.347 - 207.348 -(defn pwd 207.349 - "Returns current working directory as a String. (Like UNIX 'pwd'.) 207.350 - Note: In Java, you cannot change the current working directory." 207.351 - {:deprecated "1.2"} 207.352 - [] 207.353 - (System/getProperty "user.dir")) 207.354 - 207.355 -(defmacro with-out-writer 207.356 - "Opens a writer on f, binds it to *out*, and evalutes body. 207.357 - Anything printed within body will be written to f." 207.358 - [f & body] 207.359 - `(with-open [stream# (writer ~f)] 207.360 - (binding [*out* stream#] 207.361 - ~@body))) 207.362 - 207.363 -(defmacro with-out-append-writer 207.364 - "Like with-out-writer but appends to file." 207.365 - {:deprecated "1.2"} 207.366 - [f & body] 207.367 - `(with-open [stream# (append-writer ~f)] 207.368 - (binding [*out* stream#] 207.369 - ~@body))) 207.370 - 207.371 -(defmacro with-in-reader 207.372 - "Opens a PushbackReader on f, binds it to *in*, and evaluates body." 207.373 - [f & body] 207.374 - `(with-open [stream# (PushbackReader. (reader ~f))] 207.375 - (binding [*in* stream#] 207.376 - ~@body))) 207.377 - 207.378 -(defmulti 207.379 - ^{:deprecated "1.2" 207.380 - :doc "Copies input to output. Returns nil. 207.381 - Input may be an InputStream, Reader, File, byte[], or String. 207.382 - Output may be an OutputStream, Writer, or File. 207.383 - 207.384 - Does not close any streams except those it opens itself 207.385 - (on a File). 207.386 - 207.387 - Writing a File fails if the parent directory does not exist." 207.388 - :arglists '([input output])} 207.389 - copy 207.390 - (fn [input output] [(type input) (type output)])) 207.391 - 207.392 -(defmethod copy [InputStream OutputStream] [^InputStream input ^OutputStream output] 207.393 - (let [buffer (make-array Byte/TYPE *buffer-size*)] 207.394 - (loop [] 207.395 - (let [size (.read input buffer)] 207.396 - (when (pos? size) 207.397 - (do (.write output buffer 0 size) 207.398 - (recur))))))) 207.399 - 207.400 -(defmethod copy [InputStream Writer] [^InputStream input ^Writer output] 207.401 - (let [^"[B" buffer (make-array Byte/TYPE *buffer-size*)] 207.402 - (loop [] 207.403 - (let [size (.read input buffer)] 207.404 - (when (pos? size) 207.405 - (let [chars (.toCharArray (String. buffer 0 size *default-encoding*))] 207.406 - (do (.write output chars) 207.407 - (recur)))))))) 207.408 - 207.409 -(defmethod copy [InputStream File] [^InputStream input ^File output] 207.410 - (with-open [out (FileOutputStream. output)] 207.411 - (copy input out))) 207.412 - 207.413 -(defmethod copy [Reader OutputStream] [^Reader input ^OutputStream output] 207.414 - (let [^"[C" buffer (make-array Character/TYPE *buffer-size*)] 207.415 - (loop [] 207.416 - (let [size (.read input buffer)] 207.417 - (when (pos? size) 207.418 - (let [bytes (.getBytes (String. buffer 0 size) *default-encoding*)] 207.419 - (do (.write output bytes) 207.420 - (recur)))))))) 207.421 - 207.422 -(defmethod copy [Reader Writer] [^Reader input ^Writer output] 207.423 - (let [^"[C" buffer (make-array Character/TYPE *buffer-size*)] 207.424 - (loop [] 207.425 - (let [size (.read input buffer)] 207.426 - (when (pos? size) 207.427 - (do (.write output buffer 0 size) 207.428 - (recur))))))) 207.429 - 207.430 -(defmethod copy [Reader File] [^Reader input ^File output] 207.431 - (with-open [out (FileOutputStream. output)] 207.432 - (copy input out))) 207.433 - 207.434 -(defmethod copy [File OutputStream] [^File input ^OutputStream output] 207.435 - (with-open [in (FileInputStream. input)] 207.436 - (copy in output))) 207.437 - 207.438 -(defmethod copy [File Writer] [^File input ^Writer output] 207.439 - (with-open [in (FileInputStream. input)] 207.440 - (copy in output))) 207.441 - 207.442 -(defmethod copy [File File] [^File input ^File output] 207.443 - (with-open [in (FileInputStream. input) 207.444 - out (FileOutputStream. output)] 207.445 - (copy in out))) 207.446 - 207.447 -(defmethod copy [String OutputStream] [^String input ^OutputStream output] 207.448 - (copy (StringReader. input) output)) 207.449 - 207.450 -(defmethod copy [String Writer] [^String input ^Writer output] 207.451 - (copy (StringReader. input) output)) 207.452 - 207.453 -(defmethod copy [String File] [^String input ^File output] 207.454 - (copy (StringReader. input) output)) 207.455 - 207.456 -(defmethod copy [*char-array-type* OutputStream] [input ^OutputStream output] 207.457 - (copy (CharArrayReader. input) output)) 207.458 - 207.459 -(defmethod copy [*char-array-type* Writer] [input ^Writer output] 207.460 - (copy (CharArrayReader. input) output)) 207.461 - 207.462 -(defmethod copy [*char-array-type* File] [input ^File output] 207.463 - (copy (CharArrayReader. input) output)) 207.464 - 207.465 -(defmethod copy [*byte-array-type* OutputStream] [^"[B" input ^OutputStream output] 207.466 - (copy (ByteArrayInputStream. input) output)) 207.467 - 207.468 -(defmethod copy [*byte-array-type* Writer] [^"[B" input ^Writer output] 207.469 - (copy (ByteArrayInputStream. input) output)) 207.470 - 207.471 -(defmethod copy [*byte-array-type* File] [^"[B" input ^Writer output] 207.472 - (copy (ByteArrayInputStream. input) output)) 207.473 - 207.474 -(defn make-parents 207.475 - "Creates all parent directories of file." 207.476 - [^File file] 207.477 - (.mkdirs (.getParentFile file))) 207.478 - 207.479 -(defmulti 207.480 - ^{:doc "Converts argument into a Java byte array. Argument may be 207.481 - a String, File, InputStream, or Reader. If the argument is already 207.482 - a byte array, returns it." 207.483 - :arglists '([arg])} 207.484 - to-byte-array type) 207.485 - 207.486 -(defmethod to-byte-array *byte-array-type* [x] x) 207.487 - 207.488 -(defmethod to-byte-array String [^String x] 207.489 - (.getBytes x *default-encoding*)) 207.490 - 207.491 -(defmethod to-byte-array File [^File x] 207.492 - (with-open [input (FileInputStream. x) 207.493 - buffer (ByteArrayOutputStream.)] 207.494 - (copy input buffer) 207.495 - (.toByteArray buffer))) 207.496 - 207.497 -(defmethod to-byte-array InputStream [^InputStream x] 207.498 - (let [buffer (ByteArrayOutputStream.)] 207.499 - (copy x buffer) 207.500 - (.toByteArray buffer))) 207.501 - 207.502 -(defmethod to-byte-array Reader [^Reader x] 207.503 - (.getBytes (slurp* x) *default-encoding*)) 207.504 - 207.505 -(defmulti relative-path-string 207.506 - "Interpret a String or java.io.File as a relative path string. 207.507 - Building block for clojure.contrib.java/file." 207.508 - {:deprecated "1.2"} 207.509 - class) 207.510 - 207.511 -(defmethod relative-path-string String [^String s] 207.512 - (relative-path-string (File. s))) 207.513 - 207.514 -(defmethod relative-path-string File [^File f] 207.515 - (if (.isAbsolute f) 207.516 - (throw (IllegalArgumentException. (str f " is not a relative path"))) 207.517 - (.getPath f))) 207.518 - 207.519 -(defmulti ^File as-file 207.520 - "Interpret a String or a java.io.File as a File. Building block 207.521 - for clojure.contrib.java/file, which you should prefer 207.522 - in most cases." 207.523 - {:deprecated "1.2"} 207.524 - class) 207.525 -(defmethod as-file String [^String s] (File. s)) 207.526 -(defmethod as-file File [f] f) 207.527 - 207.528 -(defn ^File file 207.529 - "Returns a java.io.File from string or file args." 207.530 - {:deprecated "1.2"} 207.531 - ([arg] 207.532 - (as-file arg)) 207.533 - ([parent child] 207.534 - (File. ^File (as-file parent) ^String (relative-path-string child))) 207.535 - ([parent child & more] 207.536 - (reduce file (file parent child) more))) 207.537 - 207.538 -(defn delete-file 207.539 - "Delete file f. Raise an exception if it fails unless silently is true." 207.540 - [f & [silently]] 207.541 - (or (.delete (file f)) 207.542 - silently 207.543 - (throw (java.io.IOException. (str "Couldn't delete " f))))) 207.544 - 207.545 -(defn delete-file-recursively 207.546 - "Delete file f. If it's a directory, recursively delete all its contents. 207.547 -Raise an exception if any deletion fails unless silently is true." 207.548 - [f & [silently]] 207.549 - (let [f (file f)] 207.550 - (if (.isDirectory f) 207.551 - (doseq [child (.listFiles f)] 207.552 - (delete-file-recursively child silently))) 207.553 - (delete-file f silently))) 207.554 - 207.555 -(defmulti 207.556 - ^{:deprecated "1.2" 207.557 - :doc "Coerces argument (URL, URI, or String) to a java.net.URL." 207.558 - :arglists '([arg])} 207.559 - as-url type) 207.560 - 207.561 -(defmethod as-url URL [x] x) 207.562 - 207.563 -(defmethod as-url URI [^URI x] (.toURL x)) 207.564 - 207.565 -(defmethod as-url String [^String x] (URL. x)) 207.566 - 207.567 -(defmethod as-url File [^File x] (.toURL x))
208.1 --- a/src/clojure/contrib/jar.clj Sat Aug 21 06:25:44 2010 -0400 208.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 208.3 @@ -1,35 +0,0 @@ 208.4 -;;; jar.clj: utilities for working with Java JAR files 208.5 - 208.6 -;; by Stuart Sierra, http://stuartsierra.com/ 208.7 -;; April 19, 2009 208.8 - 208.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 208.10 -;; and distribution terms for this software are covered by the Eclipse 208.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 208.12 -;; which can be found in the file epl-v10.html at the root of this 208.13 -;; distribution. By using this software in any fashion, you are 208.14 -;; agreeing to be bound by the terms of this license. You must not 208.15 -;; remove this notice, or any other, from this software. 208.16 - 208.17 - 208.18 -(ns 208.19 - ^{:author "Stuart Sierra", 208.20 - :doc "Utilities for working with Java JAR files"} 208.21 - clojure.contrib.jar 208.22 - (:import (java.io File) 208.23 - (java.util.jar JarFile))) 208.24 - 208.25 -(defn jar-file? 208.26 - "Returns true if file is a normal file with a .jar or .JAR extension." 208.27 - [^File file] 208.28 - (and (.isFile file) 208.29 - (or (.endsWith (.getName file) ".jar") 208.30 - (.endsWith (.getName file) ".JAR")))) 208.31 - 208.32 -(defn filenames-in-jar 208.33 - "Returns a sequence of Strings naming the non-directory entries in 208.34 - the JAR file." 208.35 - [^JarFile jar-file] 208.36 - (map #(.getName %) 208.37 - (filter #(not (.isDirectory %)) 208.38 - (enumeration-seq (.entries jar-file)))))
209.1 --- a/src/clojure/contrib/java_utils.clj Sat Aug 21 06:25:44 2010 -0400 209.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 209.3 @@ -1,219 +0,0 @@ 209.4 -; Copyright (c) Stuart Halloway & Contributors, April 2009. All rights reserved. 209.5 -; The use and distribution terms for this software are covered by the 209.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 209.7 -; which can be found in the file epl-v10.html at the root of this distribution. 209.8 -; By using this software in any fashion, you are agreeing to be bound by 209.9 -; the terms of this license. 209.10 -; You must not remove this notice, or any other, from this software. 209.11 - 209.12 -;; 209.13 -;; CHANGELOG 209.14 -;; 209.15 -;; Most functions deprecated in 1.2. Some already exist in c.c.io, and 209.16 -;; some replaced by c.c.reflections 209.17 - 209.18 -(ns 209.19 - ^{:author "Stuart Halloway, Stephen C. Gilardi, Shawn Hoover, Perry Trolard, Stuart Sierra", 209.20 - :doc "A set of utilties for dealing with Java stuff like files and properties. 209.21 - 209.22 - Design goals: 209.23 - 209.24 - (1) Ease-of-use. These APIs should be convenient. Performance is secondary. 209.25 - 209.26 - (2) Duck typing. I hate having to think about the difference between 209.27 - a string that names a file, and a File. Ditto for a ton of other 209.28 - wrapper classes in the Java world (URL, InternetAddress). With these 209.29 - APIs you should be able to think about domain equivalence, not type 209.30 - equivalence. 209.31 - 209.32 - (3) No bossiness. I am not marking any of these functions as private 209.33 - the docstrings will tell you the intended usage but do what works for you. 209.34 - 209.35 - Feedback welcome! 209.36 - 209.37 - If something in this module violates the principle of least surprise, please 209.38 - let me (Stu) and the Clojure community know via the mailing list. 209.39 - Contributors: 209.40 - 209.41 - Stuart Halloway 209.42 - Stephen C. Gilardi 209.43 - Shawn Hoover 209.44 - Perry Trolard 209.45 - Stuart Sierra 209.46 -"} 209.47 - clojure.contrib.java-utils 209.48 - (:import [java.io File FileOutputStream] 209.49 - [java.util Properties] 209.50 - [java.net URI URL])) 209.51 - 209.52 -(defmulti relative-path-string 209.53 - "Interpret a String or java.io.File as a relative path string. 209.54 - Building block for clojure.contrib.java-utils/file." 209.55 - {:deprecated "1.2"} 209.56 - class) 209.57 - 209.58 -(defmethod relative-path-string String [^String s] 209.59 - (relative-path-string (File. s))) 209.60 - 209.61 -(defmethod relative-path-string File [^File f] 209.62 - (if (.isAbsolute f) 209.63 - (throw (IllegalArgumentException. (str f " is not a relative path"))) 209.64 - (.getPath f))) 209.65 - 209.66 -(defmulti ^File as-file 209.67 - "Interpret a String or a java.io.File as a File. Building block 209.68 - for clojure.contrib.java-utils/file, which you should prefer 209.69 - in most cases." 209.70 - {:deprecated "1.2"} 209.71 - class) 209.72 -(defmethod as-file String [^String s] (File. s)) 209.73 -(defmethod as-file File [f] f) 209.74 - 209.75 -(defn ^File file 209.76 - "Returns a java.io.File from string or file args." 209.77 - {:deprecated "1.2"} 209.78 - ([arg] 209.79 - (as-file arg)) 209.80 - ([parent child] 209.81 - (File. ^File (as-file parent) ^String (relative-path-string child))) 209.82 - ([parent child & more] 209.83 - (reduce file (file parent child) more))) 209.84 - 209.85 -(defn as-str 209.86 - "Like clojure.core/str, but if an argument is a keyword or symbol, 209.87 - its name will be used instead of its literal representation. 209.88 - 209.89 - Example: 209.90 - (str :foo :bar) ;;=> \":foo:bar\" 209.91 - (as-str :foo :bar) ;;=> \"foobar\" 209.92 - 209.93 - Note that this does not apply to keywords or symbols nested within 209.94 - data structures; they will be rendered as with str. 209.95 - 209.96 - Example: 209.97 - (str {:foo :bar}) ;;=> \"{:foo :bar}\" 209.98 - (as-str {:foo :bar}) ;;=> \"{:foo :bar}\" " 209.99 - {:deprecated "1.2"} 209.100 - ([] "") 209.101 - ([x] (if (instance? clojure.lang.Named x) 209.102 - (name x) 209.103 - (str x))) 209.104 - ([x & ys] 209.105 - ((fn [^StringBuilder sb more] 209.106 - (if more 209.107 - (recur (. sb (append (as-str (first more)))) (next more)) 209.108 - (str sb))) 209.109 - (new StringBuilder ^String (as-str x)) ys))) 209.110 - 209.111 -(defn get-system-property 209.112 - "Get a system property." 209.113 - ([stringable] 209.114 - (System/getProperty (as-str stringable))) 209.115 - ([stringable default] 209.116 - (System/getProperty (as-str stringable) default))) 209.117 - 209.118 -(defn set-system-properties 209.119 - "Set some system properties. Nil clears a property." 209.120 - [settings] 209.121 - (doseq [[name val] settings] 209.122 - (if val 209.123 - (System/setProperty (as-str name) (as-str val)) 209.124 - (System/clearProperty (as-str name))))) 209.125 - 209.126 -(defmacro with-system-properties 209.127 - "setting => property-name value 209.128 - 209.129 - Sets the system properties to the supplied values, executes the body, and 209.130 - sets the properties back to their original values. Values of nil are 209.131 - translated to a clearing of the property." 209.132 - [settings & body] 209.133 - `(let [settings# ~settings 209.134 - current# (reduce (fn [coll# k#] 209.135 - (assoc coll# k# (get-system-property k#))) 209.136 - {} 209.137 - (keys settings#))] 209.138 - (set-system-properties settings#) 209.139 - (try 209.140 - ~@body 209.141 - (finally 209.142 - (set-system-properties current#))))) 209.143 - 209.144 - 209.145 -; Not there is no corresponding props->map. Just destructure! 209.146 -(defn ^Properties as-properties 209.147 - "Convert any seq of pairs to a java.utils.Properties instance. 209.148 - Uses as-str to convert both keys and values into strings." 209.149 - {:tag Properties} 209.150 - [m] 209.151 - (let [p (Properties.)] 209.152 - (doseq [[k v] m] 209.153 - (.setProperty p (as-str k) (as-str v))) 209.154 - p)) 209.155 - 209.156 -(defn read-properties 209.157 - "Read properties from file-able." 209.158 - [file-able] 209.159 - (with-open [f (java.io.FileInputStream. (file file-able))] 209.160 - (doto (Properties.) 209.161 - (.load f)))) 209.162 - 209.163 -(defn write-properties 209.164 - "Write properties to file-able." 209.165 - {:tag Properties} 209.166 - ([m file-able] (write-properties m file-able nil)) 209.167 - ([m file-able comments] 209.168 - (with-open [^FileOutputStream f (FileOutputStream. (file file-able))] 209.169 - (doto (as-properties m) 209.170 - (.store f ^String comments))))) 209.171 - 209.172 -(defn delete-file 209.173 - "Delete file f. Raise an exception if it fails unless silently is true." 209.174 - {:deprecated "1.2"} 209.175 - [f & [silently]] 209.176 - (or (.delete (file f)) 209.177 - silently 209.178 - (throw (java.io.IOException. (str "Couldn't delete " f))))) 209.179 - 209.180 -(defn delete-file-recursively 209.181 - "Delete file f. If it's a directory, recursively delete all its contents. 209.182 -Raise an exception if any deletion fails unless silently is true." 209.183 - {:deprecated "1.2"} 209.184 - [f & [silently]] 209.185 - (let [f (file f)] 209.186 - (if (.isDirectory f) 209.187 - (doseq [child (.listFiles f)] 209.188 - (delete-file-recursively child silently))) 209.189 - (delete-file f silently))) 209.190 - 209.191 -(defmulti 209.192 - ^{:deprecated "1.2" 209.193 - :doc "Coerces argument (URL, URI, or String) to a java.net.URL." 209.194 - :arglists '([arg])} 209.195 - as-url type) 209.196 - 209.197 -(defmethod as-url URL [x] x) 209.198 - 209.199 -(defmethod as-url URI [^URI x] (.toURL x)) 209.200 - 209.201 -(defmethod as-url String [^String x] (URL. x)) 209.202 - 209.203 -(defmethod as-url File [^File x] (.toURL x)) 209.204 - 209.205 -(defn wall-hack-method 209.206 - "Calls a private or protected method. 209.207 - params is a vector of class which correspond to the arguments to the method 209.208 - obj is nil for static methods, the instance object otherwise 209.209 - the method name is given as a symbol or a keyword (something Named)" 209.210 - {:deprecated "1.2"} 209.211 - [class-name method-name params obj & args] 209.212 - (-> class-name (.getDeclaredMethod (name method-name) (into-array Class params)) 209.213 - (doto (.setAccessible true)) 209.214 - (.invoke obj (into-array Object args)))) 209.215 - 209.216 -(defn wall-hack-field 209.217 - "Access to private or protected field." 209.218 - {:deprecated "1.2"} 209.219 - [class-name field-name obj] 209.220 - (-> class-name (.getDeclaredField (name field-name)) 209.221 - (doto (.setAccessible true)) 209.222 - (.get obj)))
210.1 --- a/src/clojure/contrib/javadoc.clj Sat Aug 21 06:25:44 2010 -0400 210.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 210.3 @@ -1,4 +0,0 @@ 210.4 -(ns ^{:deprecated "1.2"} 210.5 - clojure.contrib.javadoc) 210.6 - 210.7 -(throw (Exception. "clojure.contrib.javadoc/javadoc can now be found in clojure.java.javadoc"))
211.1 --- a/src/clojure/contrib/javadoc/browse.clj Sat Aug 21 06:25:44 2010 -0400 211.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 211.3 @@ -1,51 +0,0 @@ 211.4 -;;; browse.clj -- start a web browser from Clojure 211.5 - 211.6 -; Copyright (c) Christophe Grand, December 2008. All rights reserved. 211.7 -; The use and distribution terms for this software are covered by the 211.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 211.9 -; which can be found in the file epl-v10.html at the root of this 211.10 -; distribution. 211.11 -; By using this software in any fashion, you are agreeing to be bound by 211.12 -; the terms of this license. 211.13 -; You must not remove this notice, or any other, from this software. 211.14 - 211.15 -(ns 211.16 - ^{:author "Christophe Grand", 211.17 - :deprecated "1.2" 211.18 - :doc "Start a web browser from Clojure"} 211.19 - clojure.contrib.javadoc.browse 211.20 - (:require [clojure.contrib.shell :as sh]) 211.21 - (:import (java.net URI))) 211.22 - 211.23 -(defn- macosx? [] 211.24 - (-> "os.name" System/getProperty .toLowerCase 211.25 - (.startsWith "mac os x"))) 211.26 - 211.27 -(def *open-url-script* (when (macosx?) "/usr/bin/open")) 211.28 - 211.29 -(defn open-url-in-browser 211.30 - "Opens url (a string) in the default system web browser. May not 211.31 - work on all platforms. Returns url on success, nil if not 211.32 - supported." 211.33 - [url] 211.34 - (try 211.35 - (when (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" 211.36 - "isDesktopSupported" (to-array nil)) 211.37 - (-> (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" 211.38 - "getDesktop" (to-array nil)) 211.39 - (.browse (URI. url))) 211.40 - url) 211.41 - (catch ClassNotFoundException e 211.42 - nil))) 211.43 - 211.44 -(defn open-url-in-swing 211.45 - "Opens url (a string) in a Swing window." 211.46 - [url] 211.47 - ; the implementation of this function resides in another namespace to be loaded "on demand" 211.48 - ; this fixes a bug on mac os x where requiring repl-utils turns the process into a GUI app 211.49 - ; see http://code.google.com/p/clojure-contrib/issues/detail?id=32 211.50 - (require 'clojure.contrib.javadoc.browse-ui) 211.51 - ((find-var 'clojure.contrib.javadoc.browse-ui/open-url-in-swing) url)) 211.52 - 211.53 -(defn browse-url [url] 211.54 - (or (open-url-in-browser url) (when *open-url-script* (sh/sh *open-url-script* (str url)) true) (open-url-in-swing url)))
212.1 --- a/src/clojure/contrib/javadoc/browse_ui.clj Sat Aug 21 06:25:44 2010 -0400 212.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 212.3 @@ -1,31 +0,0 @@ 212.4 -;;; browse_ui.clj -- starts a swing web browser :-( 212.5 - 212.6 -; Copyright (c) Christophe Grand, December 2008. All rights reserved. 212.7 -; The use and distribution terms for this software are covered by the 212.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 212.9 -; which can be found in the file epl-v10.html at the root of this 212.10 -; distribution. 212.11 -; By using this software in any fashion, you are agreeing to be bound by 212.12 -; the terms of this license. 212.13 -; You must not remove this notice, or any other, from this software. 212.14 - 212.15 -(ns ^{:deprecated "1.2"} 212.16 - clojure.contrib.javadoc.browse-ui) 212.17 - 212.18 -(defn open-url-in-swing 212.19 - "Opens url (a string) in a Swing window." 212.20 - [url] 212.21 - (let [htmlpane (javax.swing.JEditorPane. url)] 212.22 - (.setEditable htmlpane false) 212.23 - (.addHyperlinkListener htmlpane 212.24 - (proxy [javax.swing.event.HyperlinkListener] [] 212.25 - (hyperlinkUpdate [^javax.swing.event.HyperlinkEvent e] 212.26 - (when (= (.getEventType e) (. javax.swing.event.HyperlinkEvent$EventType ACTIVATED)) 212.27 - (if (instance? javax.swing.text.html.HTMLFrameHyperlinkEvent e) 212.28 - (-> htmlpane .getDocument (.processHTMLFrameHyperlinkEvent e)) 212.29 - (.setPage htmlpane (.getURL e))))))) 212.30 - (doto (javax.swing.JFrame.) 212.31 - (.setContentPane (javax.swing.JScrollPane. htmlpane)) 212.32 - (.setBounds 32 32 700 900) 212.33 - (.show)))) 212.34 -
213.1 --- a/src/clojure/contrib/jmx.clj Sat Aug 21 06:25:44 2010 -0400 213.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 213.3 @@ -1,121 +0,0 @@ 213.4 -;; Copyright (c) Stuart Halloway, 2009. All rights reserved. The use 213.5 -;; and distribution terms for this software are covered by the Eclipse 213.6 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 213.7 -;; which can be found in the file epl-v10.html at the root of this 213.8 -;; distribution. By using this software in any fashion, you are 213.9 -;; agreeing to be bound by the terms of this license. You must not 213.10 -;; remove this notice, or any other, from this software. 213.11 - 213.12 - 213.13 -(ns ^{:author "Stuart Halloway" 213.14 - :doc "JMX support for Clojure 213.15 - 213.16 - Requires post-Clojure 1.0 git edge for clojure.test, clojure.backtrace. 213.17 - This is prerelease. 213.18 - This API will change. 213.19 - Send reports to stu@thinkrelevance.com. 213.20 - 213.21 - Usage 213.22 - (require '[clojure.contrib.jmx :as jmx]) 213.23 - 213.24 - What beans do I have? 213.25 - 213.26 - (jmx/mbean-names \"*:*\") 213.27 - -> #<HashSet [java.lang:type=MemoryPool,name=CMS Old Gen, 213.28 - java.lang:type=Memory, ...] 213.29 - 213.30 - What attributes does a bean have? 213.31 - 213.32 - (jmx/attribute-names \"java.lang:type=Memory\") 213.33 - -> (:Verbose :ObjectPendingFinalizationCount 213.34 - :HeapMemoryUsage :NonHeapMemoryUsage) 213.35 - 213.36 - What is the value of an attribute? 213.37 - 213.38 - (jmx/read \"java.lang:type=Memory\" :ObjectPendingFinalizationCount) 213.39 - -> 0 213.40 - 213.41 - Can't I just have *all* the attributes in a Clojure map? 213.42 - 213.43 - (jmx/mbean \"java.lang:type=Memory\") 213.44 - -> {:NonHeapMemoryUsage 213.45 - {:used 16674024, :max 138412032, :init 24317952, :committed 24317952}, 213.46 - :HeapMemoryUsage 213.47 - {:used 18619064, :max 85393408, :init 0, :committed 83230720}, 213.48 - :ObjectPendingFinalizationCount 0, 213.49 - :Verbose false} 213.50 - 213.51 - Can I find and invoke an operation? 213.52 - 213.53 - (jmx/operation-names \"java.lang:type=Memory\") 213.54 - -> (:gc) 213.55 - (jmx/invoke \"java.lang:type=Memory\" :gc) 213.56 - -> nil 213.57 - 213.58 - What about some other process? Just run *any* of the above code 213.59 - inside a with-connection: 213.60 - 213.61 - (jmx/with-connection {:host \"localhost\", :port 3000} 213.62 - (jmx/mbean \"java.lang:type=Memory\")) 213.63 - -> {:ObjectPendingFinalizationCount 0, 213.64 - :HeapMemoryUsage ... etc.} 213.65 - 213.66 - Can I serve my own beans? Sure, just drop a Clojure ref 213.67 - into an instance of clojure.contrib.jmx.Bean, and the bean 213.68 - will expose read-only attributes for every key/value pair 213.69 - in the ref: 213.70 - 213.71 - (jmx/register-mbean 213.72 - (Bean. 213.73 - (ref {:string-attribute \"a-string\"})) 213.74 - \"my.namespace:name=Value\")"} 213.75 - clojure.contrib.jmx 213.76 - (:refer-clojure :exclude [read]) 213.77 - (:use clojure.contrib.def 213.78 - [clojure.contrib.string :only [as-str]] 213.79 - [clojure.stacktrace :only (root-cause)] 213.80 - [clojure.walk :only [postwalk]]) 213.81 - (:import [clojure.lang Associative] 213.82 - java.lang.management.ManagementFactory 213.83 - [javax.management Attribute DynamicMBean MBeanInfo ObjectName RuntimeMBeanException MBeanAttributeInfo] 213.84 - [javax.management.remote JMXConnectorFactory JMXServiceURL])) 213.85 - 213.86 -(defvar *connection* (ManagementFactory/getPlatformMBeanServer) 213.87 - "The connection to be used for JMX ops. Defaults to the local process.") 213.88 - 213.89 -(load "jmx/data") 213.90 -(load "jmx/client") 213.91 -(load "jmx/server") 213.92 - 213.93 -(defn mbean-names 213.94 - "Finds all MBeans matching a name on the current *connection*." 213.95 - [n] 213.96 - (.queryNames *connection* (as-object-name n) nil)) 213.97 - 213.98 -(defn attribute-names 213.99 - "All attribute names available on an MBean." 213.100 - [n] 213.101 - (doall (map #(-> % .getName keyword) 213.102 - (.getAttributes (mbean-info n))))) 213.103 - 213.104 -(defn operation-names 213.105 - "All operation names available on an MBean." 213.106 - [n] 213.107 - (doall (map #(-> % .getName keyword) (operations n)))) 213.108 - 213.109 -(defn invoke [n op & args] 213.110 - (if ( seq args) 213.111 - (.invoke *connection* (as-object-name n) (as-str op) 213.112 - (into-array args) 213.113 - (into-array String (op-param-types n op))) 213.114 - (.invoke *connection* (as-object-name n) (as-str op) 213.115 - nil nil))) 213.116 - 213.117 -(defn mbean 213.118 - "Like clojure.core/bean, but for JMX beans. Returns a read-only map of 213.119 - a JMX bean's attributes. If an attribute it not supported, value is 213.120 - set to the exception thrown." 213.121 - [n] 213.122 - (into {} (map (fn [attr-name] [(keyword attr-name) (read-supported n attr-name)]) 213.123 - (attribute-names n)))) 213.124 -
214.1 --- a/src/clojure/contrib/jmx/Bean.clj Sat Aug 21 06:25:44 2010 -0400 214.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 214.3 @@ -1,35 +0,0 @@ 214.4 -(ns clojure.contrib.jmx.Bean 214.5 - (:gen-class 214.6 - :implements [javax.management.DynamicMBean] 214.7 - :init init 214.8 - :state state 214.9 - :constructors {[Object] []}) 214.10 - (:require [clojure.contrib.jmx :as jmx]) 214.11 - (:import [javax.management DynamicMBean MBeanInfo AttributeList])) 214.12 - 214.13 -(defn -init [derefable] 214.14 - [[] derefable]) 214.15 - 214.16 -; TODO: rest of the arguments, as needed 214.17 -(defn generate-mbean-info [clj-bean] 214.18 - (MBeanInfo. (.. clj-bean getClass getName) ; class name 214.19 - "Clojure Dynamic MBean" ; description 214.20 - (jmx/map->attribute-infos @(.state clj-bean)) ; attributes 214.21 - nil ; constructors 214.22 - nil ; operations 214.23 - nil)) ; notifications 214.24 - 214.25 -(defn -getMBeanInfo 214.26 - [this] 214.27 - (generate-mbean-info this)) 214.28 - 214.29 -(defn -getAttribute 214.30 - [this attr] 214.31 - (@(.state this) (keyword attr))) 214.32 - 214.33 -(defn -getAttributes 214.34 - [this attrs] 214.35 - (let [result (AttributeList.)] 214.36 - (doseq [attr attrs] 214.37 - (.add result (.getAttribute this attr))) 214.38 - result)) 214.39 \ No newline at end of file
215.1 --- a/src/clojure/contrib/jmx/client.clj Sat Aug 21 06:25:44 2010 -0400 215.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 215.3 @@ -1,87 +0,0 @@ 215.4 -;; JMX client APIs for Clojure 215.5 -;; docs in clojure/contrib/jmx.clj!! 215.6 - 215.7 -;; by Stuart Halloway 215.8 - 215.9 -;; Copyright (c) Stuart Halloway, 2009. All rights reserved. The use 215.10 -;; and distribution terms for this software are covered by the Eclipse 215.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 215.12 -;; which can be found in the file epl-v10.html at the root of this 215.13 -;; distribution. By using this software in any fashion, you are 215.14 -;; agreeing to be bound by the terms of this license. You must not 215.15 -;; remove this notice, or any other, from this software. 215.16 - 215.17 - 215.18 -(in-ns 'clojure.contrib.jmx) 215.19 - 215.20 -(defmacro with-connection 215.21 - "Execute body with JMX connection specified by opts. opts can also 215.22 - include an optional :environment key which is passed as the 215.23 - environment arg to JMXConnectorFactory/connect." 215.24 - [opts & body] 215.25 - `(let [opts# ~opts 215.26 - env# (get opts# :environment {}) 215.27 - opts# (dissoc opts# :environment)] 215.28 - (with-open [connector# (javax.management.remote.JMXConnectorFactory/connect 215.29 - (JMXServiceURL. (jmx-url opts#)) env#)] 215.30 - (binding [*connection* (.getMBeanServerConnection connector#)] 215.31 - ~@body)))) 215.32 - 215.33 -(defn mbean-info [n] 215.34 - (.getMBeanInfo *connection* (as-object-name n))) 215.35 - 215.36 -(defn raw-read 215.37 - "Read an mbean property. Returns low-level Java object model for 215.38 - composites, tabulars, etc. Most callers should use read." 215.39 - [n attr] 215.40 - (.getAttribute *connection* (as-object-name n) (as-str attr))) 215.41 - 215.42 -(defvar read 215.43 - (comp jmx->clj raw-read) 215.44 - "Read an mbean property.") 215.45 - 215.46 -(defn read-supported 215.47 - "Calls read to read an mbean property, *returning* unsupported 215.48 - operation exceptions instead of throwing them. Used to keep mbean 215.49 - from blowing up. Note: There is no good exception that aggregates 215.50 - unsupported operations, hence the overly-general catch block." 215.51 - [n attr] 215.52 - (try 215.53 - (read n attr) 215.54 - (catch Exception e 215.55 - e))) 215.56 - 215.57 -(defn write! [n attr value] 215.58 - (.setAttribute 215.59 - *connection* 215.60 - (as-object-name n) 215.61 - (Attribute. (as-str attr) value))) 215.62 - 215.63 -(defn attribute-info 215.64 - "Get the MBeanAttributeInfo for an attribute." 215.65 - [object-name attr-name] 215.66 - (filter #(= (as-str attr-name) (.getName %)) 215.67 - (.getAttributes (mbean-info object-name)))) 215.68 - 215.69 -(defn readable? 215.70 - "Is attribute readable?" 215.71 - [n attr] 215.72 - (.isReadable () (mbean-info n))) 215.73 - 215.74 -(defn operations 215.75 - "All oeprations available on an MBean." 215.76 - [n] 215.77 - (.getOperations (mbean-info n))) 215.78 - 215.79 -(defn operation 215.80 - "The MBeanOperationInfo for operation op on mbean n. Used by invoke." 215.81 - [n op] 215.82 - (first (filter #(= (-> % .getName keyword) op) (operations n)))) 215.83 - 215.84 -(defn op-param-types 215.85 - "The parameter types (as class name strings) for operation op on n. 215.86 - Used for invoke." 215.87 - [n op] 215.88 - (map #(-> % .getType) (.getSignature (operation n op)))) 215.89 - 215.90 -
216.1 --- a/src/clojure/contrib/jmx/data.clj Sat Aug 21 06:25:44 2010 -0400 216.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 216.3 @@ -1,104 +0,0 @@ 216.4 -;; Conversions between JMX data structures and idiomatic Clojure 216.5 -;; docs in clojure/contrib/jmx.clj!! 216.6 - 216.7 -;; by Stuart Halloway 216.8 - 216.9 -;; Copyright (c) Stuart Halloway, 2009. All rights reserved. The use 216.10 -;; and distribution terms for this software are covered by the Eclipse 216.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 216.12 -;; which can be found in the file epl-v10.html at the root of this 216.13 -;; distribution. By using this software in any fashion, you are 216.14 -;; agreeing to be bound by the terms of this license. You must not 216.15 -;; remove this notice, or any other, from this software. 216.16 - 216.17 - 216.18 -(in-ns 'clojure.contrib.jmx) 216.19 - 216.20 -(declare jmx->clj) 216.21 - 216.22 -(defn jmx-url 216.23 - "Build a JMX URL from options." 216.24 - ([] (jmx-url {})) 216.25 - ([overrides] 216.26 - (let [opts (merge {:host "localhost", :port "3000", :jndi-path "jmxrmi"} overrides)] 216.27 - (format "service:jmx:rmi:///jndi/rmi://%s:%s/%s" (opts :host) (opts :port) (opts :jndi-path))))) 216.28 - 216.29 -(defmulti as-object-name 216.30 - "Interpret an object as a JMX ObjectName." 216.31 - { :arglists '([string-or-name]) } 216.32 - class) 216.33 -(defmethod as-object-name String [n] (ObjectName. n)) 216.34 -(defmethod as-object-name ObjectName [n] n) 216.35 - 216.36 -(defn composite-data->map [cd] 216.37 - (into {} 216.38 - (map (fn [attr] [(keyword attr) (jmx->clj (.get cd attr))]) 216.39 - (.. cd getCompositeType keySet)))) 216.40 - 216.41 -(defn maybe-keywordize 216.42 - "Convert a string key to a keyword, leaving other types alone. Used to 216.43 - simplify keys in the tabular data API." 216.44 - [s] 216.45 - (if (string? s) (keyword s) s)) 216.46 - 216.47 -(defn maybe-atomize 216.48 - "Convert a list of length 1 into its contents, leaving other things alone. 216.49 - Used to simplify keys in the tabular data API." 216.50 - [k] 216.51 - (if (and (instance? java.util.List k) 216.52 - (= 1 (count k))) 216.53 - (first k) 216.54 - k)) 216.55 - 216.56 -(defvar simplify-tabular-data-key 216.57 - (comp maybe-keywordize maybe-atomize)) 216.58 - 216.59 -(defn tabular-data->map [td] 216.60 - (into {} 216.61 - ; the need for into-array here was a surprise, and may not 216.62 - ; work for all examples. Are keys always arrays? 216.63 - (map (fn [k] 216.64 - [(simplify-tabular-data-key k) (jmx->clj (.get td (into-array k)))]) 216.65 - (.keySet td)))) 216.66 - 216.67 -(defmulti jmx->clj 216.68 - "Coerce JMX data structures into Clojure data. 216.69 - Handles CompositeData, TabularData, maps, and atoms." 216.70 - { :argslists '([jmx-data-structure]) } 216.71 - (fn [x] 216.72 - (cond 216.73 - (instance? javax.management.openmbean.CompositeData x) :composite 216.74 - (instance? javax.management.openmbean.TabularData x) :tabular 216.75 - (instance? clojure.lang.Associative x) :map 216.76 - :default :default))) 216.77 -(defmethod jmx->clj :composite [c] (composite-data->map c)) 216.78 -(defmethod jmx->clj :tabular [t] (tabular-data->map t)) 216.79 -(defmethod jmx->clj :map [m] (into {} (zipmap (keys m) (map jmx->clj (vals m))))) 216.80 -(defmethod jmx->clj :default [obj] obj) 216.81 - 216.82 -(def guess-attribute-map 216.83 - {"java.lang.Integer" "int" 216.84 - "java.lang.Boolean" "boolean" 216.85 - "java.lang.Long" "long" 216.86 - }) 216.87 - 216.88 -(defn guess-attribute-typename 216.89 - "Guess the attribute typename for MBeanAttributeInfo based on the attribute value." 216.90 - [value] 216.91 - (let [classname (.getName (class value))] 216.92 - (get guess-attribute-map classname classname))) 216.93 - 216.94 -(defn build-attribute-info 216.95 - "Construct an MBeanAttributeInfo. Normally called with a key/value pair from a Clojure map." 216.96 - ([attr-name attr-value] 216.97 - (build-attribute-info 216.98 - (as-str attr-name) 216.99 - (guess-attribute-typename attr-value) 216.100 - (as-str attr-name) true false false)) 216.101 - ([name type desc readable? writable? is?] (MBeanAttributeInfo. name type desc readable? writable? is? ))) 216.102 - 216.103 -(defn map->attribute-infos 216.104 - "Construct an MBeanAttributeInfo[] from a Clojure associative." 216.105 - [attr-map] 216.106 - (into-array (map (fn [[attr-name value]] (build-attribute-info attr-name value)) 216.107 - attr-map)))
217.1 --- a/src/clojure/contrib/jmx/server.clj Sat Aug 21 06:25:44 2010 -0400 217.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 217.3 @@ -1,18 +0,0 @@ 217.4 -;; JMX server APIs for Clojure 217.5 -;; docs in clojure/contrib/jmx.clj!! 217.6 - 217.7 -;; by Stuart Halloway 217.8 - 217.9 -;; Copyright (c) Stuart Halloway, 2009. All rights reserved. The use 217.10 -;; and distribution terms for this software are covered by the Eclipse 217.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 217.12 -;; which can be found in the file epl-v10.html at the root of this 217.13 -;; distribution. By using this software in any fashion, you are 217.14 -;; agreeing to be bound by the terms of this license. You must not 217.15 -;; remove this notice, or any other, from this software. 217.16 - 217.17 -(in-ns 'clojure.contrib.jmx) 217.18 - 217.19 -(defn register-mbean [mbean mbean-name] 217.20 - (.registerMBean *connection* mbean (as-object-name mbean-name))) 217.21 -
218.1 --- a/src/clojure/contrib/json.clj Sat Aug 21 06:25:44 2010 -0400 218.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 218.3 @@ -1,341 +0,0 @@ 218.4 -;;; json.clj: JavaScript Object Notation (JSON) parser/writer 218.5 - 218.6 -;; by Stuart Sierra, http://stuartsierra.com/ 218.7 -;; January 30, 2010 218.8 - 218.9 -;; Copyright (c) Stuart Sierra, 2010. All rights reserved. The use 218.10 -;; and distribution terms for this software are covered by the Eclipse 218.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 218.12 -;; which can be found in the file epl-v10.html at the root of this 218.13 -;; distribution. By using this software in any fashion, you are 218.14 -;; agreeing to be bound by the terms of this license. You must not 218.15 -;; remove this notice, or any other, from this software. 218.16 - 218.17 -(ns ^{:author "Stuart Sierra" 218.18 - :doc "JavaScript Object Notation (JSON) parser/writer. 218.19 - See http://www.json.org/ 218.20 - To write JSON, use json-str, write-json, or write-json. 218.21 - To read JSON, use read-json."} 218.22 - clojure.contrib.json 218.23 - (:use [clojure.contrib.pprint :only (write formatter-out)] 218.24 - [clojure.contrib.string :only (as-str)]) 218.25 - (:import (java.io PrintWriter PushbackReader StringWriter 218.26 - StringReader Reader EOFException))) 218.27 - 218.28 -;;; JSON READER 218.29 - 218.30 -(declare read-json-reader) 218.31 - 218.32 -(defn- read-json-array [^PushbackReader stream keywordize?] 218.33 - ;; Expects to be called with the head of the stream AFTER the 218.34 - ;; opening bracket. 218.35 - (loop [i (.read stream), result (transient [])] 218.36 - (let [c (char i)] 218.37 - (cond 218.38 - (= i -1) (throw (EOFException. "JSON error (end-of-file inside array)")) 218.39 - (Character/isWhitespace c) (recur (.read stream) result) 218.40 - (= c \,) (recur (.read stream) result) 218.41 - (= c \]) (persistent! result) 218.42 - :else (do (.unread stream (int c)) 218.43 - (let [element (read-json-reader stream keywordize? true nil)] 218.44 - (recur (.read stream) (conj! result element)))))))) 218.45 - 218.46 -(defn- read-json-object [^PushbackReader stream keywordize?] 218.47 - ;; Expects to be called with the head of the stream AFTER the 218.48 - ;; opening bracket. 218.49 - (loop [i (.read stream), key nil, result (transient {})] 218.50 - (let [c (char i)] 218.51 - (cond 218.52 - (= i -1) (throw (EOFException. "JSON error (end-of-file inside object)")) 218.53 - 218.54 - (Character/isWhitespace c) (recur (.read stream) key result) 218.55 - 218.56 - (= c \,) (recur (.read stream) nil result) 218.57 - 218.58 - (= c \:) (recur (.read stream) key result) 218.59 - 218.60 - (= c \}) (if (nil? key) 218.61 - (persistent! result) 218.62 - (throw (Exception. "JSON error (key missing value in object)"))) 218.63 - 218.64 - :else (do (.unread stream i) 218.65 - (let [element (read-json-reader stream keywordize? true nil)] 218.66 - (if (nil? key) 218.67 - (if (string? element) 218.68 - (recur (.read stream) element result) 218.69 - (throw (Exception. "JSON error (non-string key in object)"))) 218.70 - (recur (.read stream) nil 218.71 - (assoc! result (if keywordize? (keyword key) key) 218.72 - element))))))))) 218.73 - 218.74 -(defn- read-json-hex-character [^PushbackReader stream] 218.75 - ;; Expects to be called with the head of the stream AFTER the 218.76 - ;; initial "\u". Reads the next four characters from the stream. 218.77 - (let [digits [(.read stream) 218.78 - (.read stream) 218.79 - (.read stream) 218.80 - (.read stream)]] 218.81 - (when (some neg? digits) 218.82 - (throw (EOFException. "JSON error (end-of-file inside Unicode character escape)"))) 218.83 - (let [chars (map char digits)] 218.84 - (when-not (every? #{\0 \1 \2 \3 \4 \5 \6 \7 \8 \9 \a \b \c \d \e \f \A \B \C \D \E \F} 218.85 - chars) 218.86 - (throw (Exception. "JSON error (invalid hex character in Unicode character escape)"))) 218.87 - (char (Integer/parseInt (apply str chars) 16))))) 218.88 - 218.89 -(defn- read-json-escaped-character [^PushbackReader stream] 218.90 - ;; Expects to be called with the head of the stream AFTER the 218.91 - ;; initial backslash. 218.92 - (let [c (char (.read stream))] 218.93 - (cond 218.94 - (#{\" \\ \/} c) c 218.95 - (= c \b) \backspace 218.96 - (= c \f) \formfeed 218.97 - (= c \n) \newline 218.98 - (= c \r) \return 218.99 - (= c \t) \tab 218.100 - (= c \u) (read-json-hex-character stream)))) 218.101 - 218.102 -(defn- read-json-quoted-string [^PushbackReader stream] 218.103 - ;; Expects to be called with the head of the stream AFTER the 218.104 - ;; opening quotation mark. 218.105 - (let [buffer (StringBuilder.)] 218.106 - (loop [i (.read stream)] 218.107 - (let [c (char i)] 218.108 - (cond 218.109 - (= i -1) (throw (EOFException. "JSON error (end-of-file inside string)")) 218.110 - (= c \") (str buffer) 218.111 - (= c \\) (do (.append buffer (read-json-escaped-character stream)) 218.112 - (recur (.read stream))) 218.113 - :else (do (.append buffer c) 218.114 - (recur (.read stream)))))))) 218.115 - 218.116 -(defn- read-json-reader 218.117 - ([^PushbackReader stream keywordize? eof-error? eof-value] 218.118 - (loop [i (.read stream)] 218.119 - (let [c (char i)] 218.120 - (cond 218.121 - ;; Handle end-of-stream 218.122 - (= i -1) (if eof-error? 218.123 - (throw (EOFException. "JSON error (end-of-file)")) 218.124 - eof-value) 218.125 - 218.126 - ;; Ignore whitespace 218.127 - (Character/isWhitespace c) (recur (.read stream)) 218.128 - 218.129 - ;; Read numbers, true, and false with Clojure reader 218.130 - (#{\- \0 \1 \2 \3 \4 \5 \6 \7 \8 \9} c) 218.131 - (do (.unread stream i) 218.132 - (read stream true nil)) 218.133 - 218.134 - ;; Read strings 218.135 - (= c \") (read-json-quoted-string stream) 218.136 - 218.137 - ;; Read null as nil 218.138 - (= c \n) (let [ull [(char (.read stream)) 218.139 - (char (.read stream)) 218.140 - (char (.read stream))]] 218.141 - (if (= ull [\u \l \l]) 218.142 - nil 218.143 - (throw (Exception. (str "JSON error (expected null): " c ull))))) 218.144 - 218.145 - ;; Read true 218.146 - (= c \t) (let [rue [(char (.read stream)) 218.147 - (char (.read stream)) 218.148 - (char (.read stream))]] 218.149 - (if (= rue [\r \u \e]) 218.150 - true 218.151 - (throw (Exception. (str "JSON error (expected true): " c rue))))) 218.152 - 218.153 - ;; Read false 218.154 - (= c \f) (let [alse [(char (.read stream)) 218.155 - (char (.read stream)) 218.156 - (char (.read stream)) 218.157 - (char (.read stream))]] 218.158 - (if (= alse [\a \l \s \e]) 218.159 - false 218.160 - (throw (Exception. (str "JSON error (expected false): " c alse))))) 218.161 - 218.162 - ;; Read JSON objects 218.163 - (= c \{) (read-json-object stream keywordize?) 218.164 - 218.165 - ;; Read JSON arrays 218.166 - (= c \[) (read-json-array stream keywordize?) 218.167 - 218.168 - :else (throw (Exception. (str "JSON error (unexpected character): " c)))))))) 218.169 - 218.170 -(defprotocol Read-JSON-From 218.171 - (read-json-from [input keywordize? eof-error? eof-value] 218.172 - "Reads one JSON value from input String or Reader. 218.173 - If keywordize? is true, object keys will be converted to keywords. 218.174 - If eof-error? is true, empty input will throw an EOFException; if 218.175 - false EOF will return eof-value. ")) 218.176 - 218.177 -(extend-protocol 218.178 - Read-JSON-From 218.179 - String 218.180 - (read-json-from [input keywordize? eof-error? eof-value] 218.181 - (read-json-reader (PushbackReader. (StringReader. input)) 218.182 - keywordize? eof-error? eof-value)) 218.183 - PushbackReader 218.184 - (read-json-from [input keywordize? eof-error? eof-value] 218.185 - (read-json-reader input 218.186 - keywordize? eof-error? eof-value)) 218.187 - Reader 218.188 - (read-json-from [input keywordize? eof-error? eof-value] 218.189 - (read-json-reader (PushbackReader. input) 218.190 - keywordize? eof-error? eof-value))) 218.191 - 218.192 -(defn read-json 218.193 - "Reads one JSON value from input String or Reader. 218.194 - If keywordize? is true (default), object keys will be converted to 218.195 - keywords. If eof-error? is true (default), empty input will throw 218.196 - an EOFException; if false EOF will return eof-value. " 218.197 - ([input] 218.198 - (read-json-from input true true nil)) 218.199 - ([input keywordize?] 218.200 - (read-json-from input keywordize? true nil)) 218.201 - ([input keywordize? eof-error? eof-value] 218.202 - (read-json-from input keywordize? eof-error? eof-value))) 218.203 - 218.204 - 218.205 -;;; JSON PRINTER 218.206 - 218.207 -(defprotocol Write-JSON 218.208 - (write-json [object out] 218.209 - "Print object to PrintWriter out as JSON")) 218.210 - 218.211 -(defn- write-json-string [^CharSequence s ^PrintWriter out] 218.212 - (let [sb (StringBuilder. ^Integer (count s))] 218.213 - (.append sb \") 218.214 - (dotimes [i (count s)] 218.215 - (let [cp (Character/codePointAt s i)] 218.216 - (cond 218.217 - ;; Handle printable JSON escapes before ASCII 218.218 - (= cp 34) (.append sb "\\\"") 218.219 - (= cp 92) (.append sb "\\\\") 218.220 - (= cp 47) (.append sb "\\/") 218.221 - ;; Print simple ASCII characters 218.222 - (< 31 cp 127) (.append sb (.charAt s i)) 218.223 - ;; Handle non-printable JSON escapes 218.224 - (= cp 8) (.append sb "\\b") 218.225 - (= cp 12) (.append sb "\\f") 218.226 - (= cp 10) (.append sb "\\n") 218.227 - (= cp 13) (.append sb "\\r") 218.228 - (= cp 9) (.append sb "\\t") 218.229 - ;; Any other character is Hexadecimal-escaped 218.230 - :else (.append sb (format "\\u%04x" cp))))) 218.231 - (.append sb \") 218.232 - (.print out (str sb)))) 218.233 - 218.234 -(defn- write-json-object [m ^PrintWriter out] 218.235 - (.print out \{) 218.236 - (loop [x m] 218.237 - (when (seq m) 218.238 - (let [[k v] (first x)] 218.239 - (when (nil? k) 218.240 - (throw (Exception. "JSON object keys cannot be nil/null"))) 218.241 - (.print out \") 218.242 - (.print out (as-str k)) 218.243 - (.print out \") 218.244 - (.print out \:) 218.245 - (write-json v out)) 218.246 - (let [nxt (next x)] 218.247 - (when (seq nxt) 218.248 - (.print out \,) 218.249 - (recur nxt))))) 218.250 - (.print out \})) 218.251 - 218.252 -(defn- write-json-array [s ^PrintWriter out] 218.253 - (.print out \[) 218.254 - (loop [x s] 218.255 - (when (seq x) 218.256 - (let [fst (first x) 218.257 - nxt (next x)] 218.258 - (write-json fst out) 218.259 - (when (seq nxt) 218.260 - (.print out \,) 218.261 - (recur nxt))))) 218.262 - (.print out \])) 218.263 - 218.264 -(defn- write-json-bignum [x ^PrintWriter out] 218.265 - (.print out (str x))) 218.266 - 218.267 -(defn- write-json-plain [x ^PrintWriter out] 218.268 - (.print out x)) 218.269 - 218.270 -(defn- write-json-null [x ^PrintWriter out] 218.271 - (.print out "null")) 218.272 - 218.273 -(defn- write-json-named [x ^PrintWriter out] 218.274 - (write-json-string (name x) out)) 218.275 - 218.276 -(defn- write-json-generic [x out] 218.277 - (if (.isArray (class x)) 218.278 - (write-json (seq x) out) 218.279 - (throw (Exception. (str "Don't know how to write JSON of " (class x)))))) 218.280 - 218.281 -(extend nil Write-JSON 218.282 - {:write-json write-json-null}) 218.283 -(extend clojure.lang.Named Write-JSON 218.284 - {:write-json write-json-named}) 218.285 -(extend java.lang.Boolean Write-JSON 218.286 - {:write-json write-json-plain}) 218.287 -(extend java.lang.Number Write-JSON 218.288 - {:write-json write-json-plain}) 218.289 -(extend java.math.BigInteger Write-JSON 218.290 - {:write-json write-json-bignum}) 218.291 -(extend java.math.BigDecimal Write-JSON 218.292 - {:write-json write-json-bignum}) 218.293 -(extend java.lang.CharSequence Write-JSON 218.294 - {:write-json write-json-string}) 218.295 -(extend java.util.Map Write-JSON 218.296 - {:write-json write-json-object}) 218.297 -(extend java.util.Collection Write-JSON 218.298 - {:write-json write-json-array}) 218.299 -(extend clojure.lang.ISeq Write-JSON 218.300 - {:write-json write-json-array}) 218.301 -(extend java.lang.Object Write-JSON 218.302 - {:write-json write-json-generic}) 218.303 - 218.304 -(defn json-str 218.305 - "Converts x to a JSON-formatted string." 218.306 - [x] 218.307 - (let [sw (StringWriter.) 218.308 - out (PrintWriter. sw)] 218.309 - (write-json x out) 218.310 - (.toString sw))) 218.311 - 218.312 -(defn print-json 218.313 - "Write JSON-formatted output to *out*" 218.314 - [x] 218.315 - (write-json x *out*)) 218.316 - 218.317 - 218.318 -;;; JSON PRETTY-PRINTER 218.319 - 218.320 -;; Based on code by Tom Faulhaber 218.321 - 218.322 -(defn- pprint-json-array [s] 218.323 - ((formatter-out "~<[~;~@{~w~^, ~:_~}~;]~:>") s)) 218.324 - 218.325 -(defn- pprint-json-object [m] 218.326 - ((formatter-out "~<{~;~@{~<~w:~_~w~:>~^, ~_~}~;}~:>") 218.327 - (for [[k v] m] [(as-str k) v]))) 218.328 - 218.329 -(defn- pprint-json-generic [x] 218.330 - (if (.isArray (class x)) 218.331 - (pprint-json-array (seq x)) 218.332 - (print (json-str x)))) 218.333 - 218.334 -(defn- pprint-json-dispatch [x] 218.335 - (cond (nil? x) (print "null") 218.336 - (instance? java.util.Map x) (pprint-json-object x) 218.337 - (instance? java.util.Collection x) (pprint-json-array x) 218.338 - (instance? clojure.lang.ISeq x) (pprint-json-array x) 218.339 - :else (pprint-json-generic x))) 218.340 - 218.341 -(defn pprint-json 218.342 - "Pretty-prints JSON representation of x to *out*" 218.343 - [x] 218.344 - (write x :dispatch pprint-json-dispatch))
219.1 --- a/src/clojure/contrib/lazy_seqs.clj Sat Aug 21 06:25:44 2010 -0400 219.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 219.3 @@ -1,90 +0,0 @@ 219.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 219.5 -;; distribution terms for this software are covered by the Eclipse Public 219.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 219.7 -;; be found in the file epl-v10.html at the root of this distribution. By 219.8 -;; using this software in any fashion, you are agreeing to be bound by the 219.9 -;; terms of this license. You must not remove this notice, or any other, 219.10 -;; from this software. 219.11 -;; 219.12 -;; lazy-seqs 219.13 -;; 219.14 -;; == Lazy sequences == 219.15 -;; 219.16 -;; primes - based on the "naive" implemention described in [1] plus a 219.17 -;; small "wheel" which eliminates multiples of 2, 3, 5, and 219.18 -;; 7 from consideration by incrementing past them. Also inspired 219.19 -;; by code from Christophe Grand in [2]. 219.20 -;; 219.21 -;; fibs - all the Fibonacci numbers 219.22 -;; 219.23 -;; powers-of-2 - all the powers of 2 219.24 -;; 219.25 -;; == Lazy sequence functions == 219.26 -;; 219.27 -;; (partition-all, shuffle moved to clojure.core) 219.28 -;; (rand-elt moved to clojure.core/rand-nth) 219.29 -;; (rotations, moved to seq_utils.clj) 219.30 -;; (permutations and combinations moved to combinatorics.clj) 219.31 -;; 219.32 -;; [1] http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf 219.33 -;; [2] http://clj-me.blogspot.com/2008/06/primes.html 219.34 -;; 219.35 -;; scgilardi (gmail) 219.36 -;; Created 07 June 2008 219.37 - 219.38 -(ns 219.39 - ^{:author "Stephen C. Gilardi", 219.40 - :doc " 219.41 -==== Lazy sequences ==== 219.42 - 219.43 - primes - based on the \"naive\" implemention described in [1] plus a 219.44 - small \"wheel\" which eliminates multiples of 2, 3, 5, and 219.45 - 7 from consideration by incrementing past them. Also inspired 219.46 - by code from Christophe Grand in [2]. 219.47 - 219.48 - fibs - all the Fibonacci numbers 219.49 - 219.50 - powers-of-2 - all the powers of 2 219.51 - 219.52 - ==== Lazy sequence functions ==== 219.53 - 219.54 - (partition-all, shuffle moved to clojure.core) 219.55 - (rand-elt moved to clojure.core/rand-nth) 219.56 - (rotations, rand-elt moved to seq_utils.clj) 219.57 - (permutations and combinations moved to combinatorics.clj) 219.58 - 219.59 - [1] http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf 219.60 - [2] http://clj-me.blogspot.com/2008/06/primes.html 219.61 -"} 219.62 - clojure.contrib.lazy-seqs 219.63 - (:use clojure.contrib.def)) 219.64 - 219.65 -; primes cannot be written efficiently as a function, because 219.66 -; it needs to look back on the whole sequence. contrast with 219.67 -; fibs and powers-of-2 which only need a fixed buffer of 1 or 2 219.68 -; previous values. 219.69 -(defvar primes 219.70 - (concat 219.71 - [2 3 5 7] 219.72 - (lazy-seq 219.73 - (let [primes-from 219.74 - (fn primes-from [n [f & r]] 219.75 - (if (some #(zero? (rem n %)) 219.76 - (take-while #(<= (* % %) n) primes)) 219.77 - (recur (+ n f) r) 219.78 - (lazy-seq (cons n (primes-from (+ n f) r))))) 219.79 - wheel (cycle [2 4 2 4 6 2 6 4 2 4 6 6 2 6 4 2 219.80 - 6 4 6 8 4 2 4 2 4 8 6 4 6 2 4 6 219.81 - 2 6 6 4 2 4 6 2 6 4 2 4 2 10 2 10])] 219.82 - (primes-from 11 wheel)))) 219.83 - "Lazy sequence of all the prime numbers.") 219.84 - 219.85 -(defn fibs 219.86 - "Returns a lazy sequence of all the Fibonacci numbers." 219.87 - [] 219.88 - (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1]))) 219.89 - 219.90 -(defn powers-of-2 219.91 - "Returns a lazy sequence of all the powers of 2" 219.92 - [] 219.93 - (iterate #(bit-shift-left % 1) 1))
220.1 --- a/src/clojure/contrib/lazy_xml.clj Sat Aug 21 06:25:44 2010 -0400 220.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 220.3 @@ -1,215 +0,0 @@ 220.4 -; Copyright (c) Chris Houser, Dec 2008. All rights reserved. 220.5 -; The use and distribution terms for this software are covered by the 220.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 220.7 -; which can be found in the file epl-v10.html at the root of this distribution. 220.8 -; By using this software in any fashion, you are agreeing to be bound by 220.9 -; the terms of this license. 220.10 -; You must not remove this notice, or any other, from this software. 220.11 - 220.12 -; Functions to parse xml lazily and emit back to text. 220.13 - 220.14 -(ns 220.15 - ^{:author "Chris Houser", 220.16 - :doc "Functions to parse xml lazily and emit back to text."} 220.17 - clojure.contrib.lazy-xml 220.18 - (:use [clojure.xml :as xml :only []] 220.19 - [clojure.contrib.seq :only [fill-queue]]) 220.20 - (:import (org.xml.sax Attributes InputSource) 220.21 - (org.xml.sax.helpers DefaultHandler) 220.22 - (javax.xml.parsers SAXParserFactory) 220.23 - (java.util.concurrent LinkedBlockingQueue TimeUnit) 220.24 - (java.lang.ref WeakReference) 220.25 - (java.io Reader))) 220.26 - 220.27 -(defstruct node :type :name :attrs :str) 220.28 - 220.29 -; http://www.extreme.indiana.edu/xgws/xsoap/xpp/ 220.30 -(def has-pull false) 220.31 -(defn- parse-seq-pull [& _]) 220.32 -(try 220.33 - (load "lazy_xml/with_pull") 220.34 - (catch Exception e 220.35 - (when-not (re-find #"XmlPullParser" (str e)) 220.36 - (throw e)))) 220.37 - 220.38 -(defn startparse-sax [s ch] 220.39 - (.. SAXParserFactory newInstance newSAXParser (parse s ch))) 220.40 - 220.41 -(defn parse-seq 220.42 - "Parses the source s, which can be a File, InputStream or String 220.43 - naming a URI. Returns a lazy sequence of maps with two or more of 220.44 - the keys :type, :name, :attrs, and :str. Other SAX-compatible 220.45 - parsers can be supplied by passing startparse, a fn taking a source 220.46 - and a ContentHandler and returning a parser. If a parser is 220.47 - specified, it will be run in a separate thread and be allowed to get 220.48 - ahead by queue-size items, which defaults to maxint. If no parser 220.49 - is specified and org.xmlpull.v1.XmlPullParser is in the classpath, 220.50 - this superior pull parser will be used." 220.51 - ([s] (if has-pull 220.52 - (parse-seq-pull s) 220.53 - (parse-seq s startparse-sax))) 220.54 - ([s startparse] (parse-seq s startparse Integer/MAX_VALUE)) 220.55 - ([s startparse queue-size] 220.56 - (let [s (if (instance? Reader s) (InputSource. s) s) 220.57 - f (fn filler-func [fill] 220.58 - (startparse s (proxy [DefaultHandler] [] 220.59 - (startElement [uri local-name q-name ^Attributes atts] 220.60 - ;(prn :start-element q-name)(flush) 220.61 - (let [attrs (into {} (for [i (range (.getLength atts))] 220.62 - [(keyword (.getQName atts i)) 220.63 - (.getValue atts i)]))] 220.64 - (fill (struct node :start-element (keyword q-name) attrs)))) 220.65 - (endElement [uri local-name q-name] 220.66 - ;(prn :end-element q-name)(flush) 220.67 - (fill (struct node :end-element (keyword q-name)))) 220.68 - (characters [ch start length] 220.69 - ;(prn :characters)(flush) 220.70 - (let [st (String. ch start length)] 220.71 - (when (seq (.trim st)) 220.72 - (fill (struct node :characters nil nil st))))))))] 220.73 - (fill-queue f :queue-size queue-size)))) 220.74 - 220.75 - 220.76 -(defstruct element :tag :attrs :content) 220.77 -(declare mktree) 220.78 - 220.79 -(defn- siblings [coll] 220.80 - (lazy-seq 220.81 - (when-let [s (seq coll)] 220.82 - (let [event (first s)] 220.83 - (condp = (:type event) 220.84 - :characters (cons (:str event) (siblings (rest s))) 220.85 - :start-element (let [t (mktree s)] 220.86 - (cons (first t) (siblings (rest t)))) 220.87 - :end-element [(rest s)]))))) 220.88 - 220.89 -(defn- mktree 220.90 - [[elem & events]] 220.91 - (lazy-seq 220.92 - (let [sibs (siblings events)] 220.93 - ;(prn :elem elem) 220.94 - (cons 220.95 - (struct element (:name elem) (:attrs elem) (drop-last sibs)) 220.96 - (lazy-seq (last sibs)))))) 220.97 - 220.98 -(defn parse-trim 220.99 - "Parses the source s, which can be a File, InputStream or String 220.100 - naming a URI. Returns a lazy tree of the clojure.xml/element 220.101 - struct-map, which has the keys :tag, :attrs, and :content and 220.102 - accessor fns tag, attrs, and content, with the whitespace trimmed 220.103 - from around each content string. This format is compatible with what 220.104 - clojure.xml/parse produces, except :content is a lazy seq instead of 220.105 - a vector. Other SAX-compatible parsers can be supplied by passing 220.106 - startparse, a fn taking a source and a ContentHandler and returning 220.107 - a parser. If a parser is specified, it will be run in a separate 220.108 - thread and be allowed to get ahead by queue-size items, which 220.109 - defaults to maxing. If no parser is specified and 220.110 - org.xmlpull.v1.XmlPullParser is in the classpath, this superior pull 220.111 - parser will be used." 220.112 - ([s] (first (mktree (parse-seq s)))) 220.113 - ([s startparse queue-size] 220.114 - (first (mktree (parse-seq s startparse queue-size))))) 220.115 - 220.116 -(defn attributes [e] 220.117 - (let [v (vec (:attrs e))] 220.118 - (reify org.xml.sax.Attributes 220.119 - (getLength [_] (count v)) 220.120 - (getURI [_ i] (namespace (key (v i)))) 220.121 - (getLocalName [_ i] (name (key (v i)))) 220.122 - (getQName [_ i] (name (key (v i)))) 220.123 - (getValue [_ uri name] (get (:attrs e) name)) 220.124 - (^String getValue [_ ^int i] (val (v i))) 220.125 - (^String getType [_ ^int i] "CDATA")))) 220.126 - 220.127 -(defn- emit-element 220.128 - "Recursively prints as XML text the element struct e. To have it 220.129 - print extra whitespace like clojure.xml/emit, use the :pad true 220.130 - option." 220.131 - [e ^org.xml.sax.ContentHandler ch] 220.132 - (if (instance? String e) 220.133 - (.characters ch (.toCharArray ^String e) 0 (count e)) 220.134 - (let [nspace (namespace (:tag e)) 220.135 - qname (name (:tag e))] 220.136 - (.startElement ch (or nspace "") qname qname (attributes e)) 220.137 - (doseq [c (:content e)] 220.138 - (emit-element c ch)) 220.139 - (.endElement ch (or nspace "") qname qname)))) 220.140 - 220.141 - 220.142 -(defn emit 220.143 - [e & {:as opts}] 220.144 - (let [content-handler (atom nil) 220.145 - trans (-> (javax.xml.transform.TransformerFactory/newInstance) 220.146 - .newTransformer)] 220.147 - 220.148 - (when (:indent opts) 220.149 - (.setOutputProperty trans "indent" "yes") 220.150 - (.setOutputProperty trans "{http://xml.apache.org/xslt}indent-amount" 220.151 - (str (:indent opts)))) 220.152 - 220.153 - (when (contains? opts :xml-declaration) 220.154 - (.setOutputProperty trans "omit-xml-declaration" 220.155 - (if (:xml-declaration opts) "no" "yes"))) 220.156 - 220.157 - (when (:encoding opts) 220.158 - (.setOutputProperty trans "encoding" (:encoding opts))) 220.159 - 220.160 - (.transform 220.161 - trans 220.162 - (javax.xml.transform.sax.SAXSource. 220.163 - (reify org.xml.sax.XMLReader 220.164 - (getContentHandler [_] @content-handler) 220.165 - (setDTDHandler [_ handler]) 220.166 - (setFeature [_ name value]) 220.167 - (setProperty [_ name value]) 220.168 - (setContentHandler [_ ch] (reset! content-handler ch)) 220.169 - (^void parse [_ ^org.xml.sax.InputSource _] 220.170 - (when @content-handler 220.171 - (.startDocument @content-handler) 220.172 - (emit-element e @content-handler) 220.173 - (.endDocument @content-handler)))) 220.174 - (org.xml.sax.InputSource.)) 220.175 - (javax.xml.transform.stream.StreamResult. *out*)))) 220.176 - 220.177 -(comment 220.178 - 220.179 -(def atomstr "<?xml version='1.0' encoding='UTF-8'?> 220.180 -<feed xmlns='http://www.w3.org/2005/Atom'> 220.181 - <id>tag:blogger.com,1999:blog-28403206</id> 220.182 - <updated>2008-02-14T08:00:58.567-08:00</updated> 220.183 - <title type='text'>n01senet</title> 220.184 - <link rel='alternate' type='text/html' href='http://n01senet.blogspot.com/'/> 220.185 - <entry xmlns:foo='http://foo' xmlns:bar='http://bar'> 220.186 - <id>1</id> 220.187 - <published>2008-02-13</published> 220.188 - <title type='text'>clojure is the best lisp yet</title> 220.189 - <author><name>Chouser</name></author> 220.190 - </entry> 220.191 - <entry> 220.192 - <id>2</id> 220.193 - <published>2008-02-07</published> 220.194 - <title type='text'>experimenting with vnc</title> 220.195 - <author><name>agriffis</name></author> 220.196 - </entry> 220.197 -</feed> 220.198 -") 220.199 - 220.200 -(def tree (parse-trim (java.io.StringReader. atomstr) 220.201 - startparse-sax 220.202 - 1)) 220.203 -(println "\nsax") 220.204 -(emit tree) 220.205 - 220.206 -(def tree (parse-trim (java.io.StringReader. atomstr))) 220.207 -(println "\ndefault") 220.208 -(emit tree) 220.209 - 220.210 -(def tree (xml/parse (org.xml.sax.InputSource. (java.io.StringReader. atomstr)))) 220.211 -(println "\norig") 220.212 -(emit tree) 220.213 - 220.214 -; When used with zip and zip-filter, you can get do queries like this 220.215 -; without parsing more than the first few tags: 220.216 -; (zip/node (first (xml-> (zip/xml-zip tree) :id))) 220.217 - 220.218 -)
221.1 --- a/src/clojure/contrib/lazy_xml/with_pull.clj Sat Aug 21 06:25:44 2010 -0400 221.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 221.3 @@ -1,58 +0,0 @@ 221.4 -; Copyright (c) Chris Houser, Dec 2008. All rights reserved. 221.5 -; The use and distribution terms for this software are covered by the 221.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 221.7 -; which can be found in the file epl-v10.html at the root of this distribution. 221.8 -; By using this software in any fashion, you are agreeing to be bound by 221.9 -; the terms of this license. 221.10 -; You must not remove this notice, or any other, from this software. 221.11 - 221.12 -; optional module to allow lazy-xml to use pull parser instead of sax 221.13 - 221.14 -(in-ns 'clojure.contrib.lazy-xml) 221.15 -(import '(org.xmlpull.v1 XmlPullParser XmlPullParserFactory)) 221.16 - 221.17 -(defn- attrs [xpp] 221.18 - (for [i (range (.getAttributeCount xpp))] 221.19 - [(keyword (.getAttributeName xpp i)) 221.20 - (.getAttributeValue xpp i)])) 221.21 - 221.22 -(defn- ns-decs [xpp] 221.23 - (let [d (.getDepth xpp)] 221.24 - (for [i (range (.getNamespaceCount xpp (dec d)) (.getNamespaceCount xpp d))] 221.25 - (let [prefix (.getNamespacePrefix xpp i)] 221.26 - [(keyword (str "xmlns" (when prefix (str ":" prefix)))) 221.27 - (.getNamespaceUri xpp i)])))) 221.28 - 221.29 -(defn- attr-hash [xpp] 221.30 - (into {} (concat (ns-decs xpp) (attrs xpp)))) 221.31 - 221.32 -(defn- pull-step [xpp] 221.33 - (let [step (fn [xpp] 221.34 - (condp = (.next xpp) 221.35 - XmlPullParser/START_TAG 221.36 - (cons (struct node :start-element 221.37 - (keyword (.getName xpp)) 221.38 - (attr-hash xpp)) 221.39 - (pull-step xpp)) 221.40 - XmlPullParser/END_TAG 221.41 - (cons (struct node :end-element 221.42 - (keyword (.getName xpp))) 221.43 - (pull-step xpp)) 221.44 - XmlPullParser/TEXT 221.45 - (let [text (.trim (.getText xpp))] 221.46 - (if (empty? text) 221.47 - (recur xpp) 221.48 - (cons (struct node :characters nil nil text) 221.49 - (pull-step xpp))))))] 221.50 - (lazy-seq (step xpp)))) 221.51 - 221.52 -(def ^{:private true} factory 221.53 - (doto (XmlPullParserFactory/newInstance) 221.54 - (.setNamespaceAware true))) 221.55 - 221.56 -(defn- parse-seq-pull [s] 221.57 - (let [xpp (.newPullParser factory)] 221.58 - (.setInput xpp s) 221.59 - (pull-step xpp))) 221.60 - 221.61 -(def has-pull true)
222.1 --- a/src/clojure/contrib/logging.clj Sat Aug 21 06:25:44 2010 -0400 222.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 222.3 @@ -1,343 +0,0 @@ 222.4 -;;; logging.clj -- delegated logging for Clojure 222.5 - 222.6 -;; by Alex Taggart 222.7 -;; July 27, 2009 222.8 - 222.9 -;; Copyright (c) Alex Taggart, July 2009. All rights reserved. The use 222.10 -;; and distribution terms for this software are covered by the Eclipse 222.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 222.12 -;; which can be found in the file epl-v10.html at the root of this 222.13 -;; distribution. By using this software in any fashion, you are 222.14 -;; agreeing to be bound by the terms of this license. You must not 222.15 -;; remove this notice, or any other, from this software. 222.16 -(ns 222.17 - ^{:author "Alex Taggart, Timothy Pratley", 222.18 - :doc 222.19 - "Logging macros which delegate to a specific logging implementation. At 222.20 - runtime a specific implementation is selected from, in order, Apache 222.21 - commons-logging, log4j, and finally java.util.logging. 222.22 - 222.23 - Logging levels are specified by clojure keywords corresponding to the 222.24 - values used in log4j and commons-logging: 222.25 - :trace, :debug, :info, :warn, :error, :fatal 222.26 - 222.27 - Logging occurs with the log macro, or the level-specific convenience macros, 222.28 - which write either directly or via an agent. For performance reasons, direct 222.29 - logging is enabled by default, but setting the *allow-direct-logging* boolean 222.30 - atom to false will disable it. If logging is invoked within a transaction it 222.31 - will always use an agent. 222.32 - 222.33 - The log macros will not evaluate their 'message' unless the specific logging 222.34 - level is in effect. Alternately, you can use the spy macro when you have code 222.35 - that needs to be evaluated, and also want to output the code and its result to 222.36 - the debug log. 222.37 - 222.38 - Unless otherwise specified, the current namespace (as identified by *ns*) will 222.39 - be used as the log-ns (similar to how the java class name is usually used). 222.40 - Note: your log configuration should display the name that was passed to the 222.41 - logging implementation, and not perform stack-inspection, otherwise you'll see 222.42 - something like \"fn__72$impl_write_BANG__39__auto____81\" in your logs. 222.43 - 222.44 - Use the enabled? macro to write conditional code against the logging level 222.45 - (beyond simply whether or not to call log, which is handled automatically). 222.46 - 222.47 - You can redirect all java writes of System.out and System.err to the log 222.48 - system by calling log-capture!. To rebind *out* and *err* to the log system 222.49 - invoke with-logs. In both cases a log-ns (e.g., \"com.example.captured\") 222.50 - needs to be specified to namespace the output."} 222.51 - clojure.contrib.logging) 222.52 - 222.53 -(declare *impl-name* impl-get-log impl-enabled? impl-write!) 222.54 - 222.55 -;; Macros used so that implementation-specific functions all have the same meta. 222.56 - 222.57 -(defmacro def-impl-name 222.58 - {:private true} [& body] 222.59 - `(def 222.60 - ^{:doc "The name of the logging implementation used."} 222.61 - *impl-name* 222.62 - ~@body)) 222.63 - 222.64 -(defmacro def-impl-get-log 222.65 - {:private true} [& body] 222.66 - `(def 222.67 - ^{:doc 222.68 - "Returns an implementation-specific log by string namespace. End-users should 222.69 - not need to call this." 222.70 - :arglist '([~'log-ns])} 222.71 - impl-get-log 222.72 - (memoize ~@body))) 222.73 - 222.74 -(defmacro def-impl-enabled? 222.75 - {:private true} [& body] 222.76 - `(def 222.77 - ^{:doc 222.78 - "Implementation-specific check if a particular level is enabled. End-users 222.79 - should not need to call this." 222.80 - :arglist '([~'log ~'level])} 222.81 - impl-enabled? 222.82 - ~@body)) 222.83 - 222.84 -(defmacro def-impl-write! 222.85 - {:private true} [& body] 222.86 - `(def 222.87 - ^{:doc 222.88 - "Implementation-specific write of a log message. End-users should not need to 222.89 - call this." 222.90 - :arglist '([~'log ~'level ~'message ~'throwable])} 222.91 - impl-write! 222.92 - ~@body)) 222.93 - 222.94 -(defn- commons-logging 222.95 - "Defines the commons-logging-based implementations of the core logging 222.96 - functions. End-users should never need to call this." 222.97 - [] 222.98 - (try 222.99 - (import (org.apache.commons.logging LogFactory Log)) 222.100 - (eval 222.101 - `(do 222.102 - (def-impl-name "org.apache.commons.logging") 222.103 - (def-impl-get-log 222.104 - (fn [log-ns#] 222.105 - (org.apache.commons.logging.LogFactory/getLog ^String log-ns#))) 222.106 - (def-impl-enabled? 222.107 - (fn [^org.apache.commons.logging.Log log# level#] 222.108 - (condp = level# 222.109 - :trace (.isTraceEnabled log#) 222.110 - :debug (.isDebugEnabled log#) 222.111 - :info (.isInfoEnabled log#) 222.112 - :warn (.isWarnEnabled log#) 222.113 - :error (.isErrorEnabled log#) 222.114 - :fatal (.isFatalEnabled log#)))) 222.115 - (def-impl-write! 222.116 - (fn [^org.apache.commons.logging.Log log# level# msg# e#] 222.117 - (condp = level# 222.118 - :trace (.trace log# msg# e#) 222.119 - :debug (.debug log# msg# e#) 222.120 - :info (.info log# msg# e#) 222.121 - :warn (.warn log# msg# e#) 222.122 - :error (.error log# msg# e#) 222.123 - :fatal (.fatal log# msg# e#)))) 222.124 - true)) 222.125 - (catch Exception e nil))) 222.126 - 222.127 - 222.128 -(defn- log4j-logging 222.129 - "Defines the log4j-based implementations of the core logging functions. 222.130 - End-users should never need to call this." 222.131 - [] 222.132 - (try 222.133 - (import (org.apache.log4j Logger Level)) 222.134 - (eval 222.135 - '(do 222.136 - (def-impl-name "org.apache.log4j") 222.137 - (def-impl-get-log 222.138 - (fn [log-ns#] 222.139 - (org.apache.log4j.Logger/getLogger ^String log-ns#))) 222.140 - (let [levels# {:trace org.apache.log4j.Level/TRACE 222.141 - :debug org.apache.log4j.Level/DEBUG 222.142 - :info org.apache.log4j.Level/INFO 222.143 - :warn org.apache.log4j.Level/WARN 222.144 - :error org.apache.log4j.Level/ERROR 222.145 - :fatal org.apache.log4j.Level/FATAL}] 222.146 - (def-impl-enabled? 222.147 - (fn [^org.apache.log4j.Logger log# level#] 222.148 - (.isEnabledFor log# (levels# level#)))) 222.149 - (def-impl-write! 222.150 - (fn [^org.apache.log4j.Logger log# level# msg# e#] 222.151 - (if-not e# 222.152 - (.log log# (levels# level#) msg#) 222.153 - (.log log# (levels# level#) msg# e#))))) 222.154 - true)) 222.155 - (catch Exception e nil))) 222.156 - 222.157 - 222.158 -(defn- java-logging 222.159 - "Defines the java-logging-based implementations of the core logging 222.160 - functions. End-users should never need to call this." 222.161 - [] 222.162 - (try 222.163 - (import (java.util.logging Logger Level)) 222.164 - (eval 222.165 - `(do 222.166 - (def-impl-name "java.util.logging") 222.167 - (def-impl-get-log 222.168 - (fn [log-ns#] 222.169 - (java.util.logging.Logger/getLogger log-ns#))) 222.170 - (let [levels# {:trace java.util.logging.Level/FINEST 222.171 - :debug java.util.logging.Level/FINE 222.172 - :info java.util.logging.Level/INFO 222.173 - :warn java.util.logging.Level/WARNING 222.174 - :error java.util.logging.Level/SEVERE 222.175 - :fatal java.util.logging.Level/SEVERE}] 222.176 - (def-impl-enabled? 222.177 - (fn [^java.util.logging.Logger log# level#] 222.178 - (.isLoggable log# (levels# level#)))) 222.179 - (def-impl-write! 222.180 - (fn [^java.util.logging.Logger log# level# msg# e#] 222.181 - (if-not e# 222.182 - (.log log# ^java.util.logging.Level (levels# level#) 222.183 - ^String (str msg#)) 222.184 - (.log log# ^java.util.logging.Level (levels# level#) 222.185 - ^String (str msg#) ^Throwable e#))))) 222.186 - true)) 222.187 - (catch Exception e nil))) 222.188 - 222.189 - 222.190 -;; Initialize implementation-specific functions 222.191 -(or (commons-logging) 222.192 - (log4j-logging) 222.193 - (java-logging) 222.194 - (throw ; this should never happen in 1.5+ 222.195 - (RuntimeException. 222.196 - "Valid logging implementation could not be found."))) 222.197 - 222.198 - 222.199 -(def ^{:doc 222.200 - "The default agent used for performing logging durng a transaction or when 222.201 - direct logging is disabled."} 222.202 - *logging-agent* (agent nil)) 222.203 - 222.204 - 222.205 -(def ^{:doc 222.206 - "A boolean indicating whether direct logging (as opposed to via an agent) is 222.207 - allowed when not operating from within a transaction. Defaults to true."} 222.208 - *allow-direct-logging* (atom true)) 222.209 - 222.210 - 222.211 -(defmacro log 222.212 - "Logs a message, either directly or via an agent. Also see the level-specific 222.213 - convenience macros." 222.214 - ([level message] 222.215 - `(log ~level ~message nil)) 222.216 - ([level message throwable] 222.217 - `(log ~level ~message ~throwable ~(str *ns*))) 222.218 - ([level message throwable log-ns] 222.219 - `(let [log# (impl-get-log ~log-ns)] 222.220 - (if (impl-enabled? log# ~level) 222.221 - (if (and @*allow-direct-logging* 222.222 - (not (clojure.lang.LockingTransaction/isRunning))) 222.223 - (impl-write! log# ~level ~message ~throwable) 222.224 - (send-off *logging-agent* 222.225 - (fn [_# l# v# m# t#] (impl-write! l# v# m# t#)) 222.226 - log# ~level ~message ~throwable)))))) 222.227 - 222.228 - 222.229 -(defmacro enabled? 222.230 - "Returns true if the specific logging level is enabled. Use of this function 222.231 - should only be necessary if one needs to execute alternate code paths beyond 222.232 - whether the log should be written to." 222.233 - ([level] 222.234 - `(enabled? ~level ~(str *ns*))) 222.235 - ([level log-ns] 222.236 - `(impl-enabled? (impl-get-log ~log-ns) ~level))) 222.237 - 222.238 - 222.239 -(defmacro spy 222.240 - "Evaluates expr and outputs the form and its result to the debug log; returns 222.241 - the result of expr." 222.242 - [expr] 222.243 - `(let [a# ~expr] (log :debug (str '~expr " => " a#)) a#)) 222.244 - 222.245 - 222.246 -(defn log-stream 222.247 - "Creates a PrintStream that will output to the log. End-users should not need 222.248 - to invoke this." 222.249 - [level log-ns] 222.250 - (java.io.PrintStream. 222.251 - (proxy [java.io.ByteArrayOutputStream] [] 222.252 - (flush [] 222.253 - (proxy-super flush) 222.254 - (let [s (.trim (.toString ^java.io.ByteArrayOutputStream this))] 222.255 - (proxy-super reset) 222.256 - (if (> (.length s) 0) 222.257 - (log level s nil log-ns))))) 222.258 - true)) 222.259 - 222.260 - 222.261 -(def ^{:doc 222.262 - "A ref used by log-capture! to maintain a reference to the original System.out 222.263 - and System.err streams." 222.264 - :private true} 222.265 - *old-std-streams* (ref nil)) 222.266 - 222.267 - 222.268 -(defn log-capture! 222.269 - "Captures System.out and System.err, redirecting all writes of those streams 222.270 - to :info and :error logging, respectively. The specified log-ns value will 222.271 - be used to namespace all redirected logging. NOTE: this will not redirect 222.272 - output of *out* or *err*; for that, use with-logs." 222.273 - [log-ns] 222.274 - (dosync 222.275 - (let [new-out (log-stream :info log-ns) 222.276 - new-err (log-stream :error log-ns)] 222.277 - ; don't overwrite the original values 222.278 - (if (nil? @*old-std-streams*) 222.279 - (ref-set *old-std-streams* {:out System/out :err System/err})) 222.280 - (System/setOut new-out) 222.281 - (System/setErr new-err)))) 222.282 - 222.283 - 222.284 -(defn log-uncapture! 222.285 - "Restores System.out and System.err to their original values." 222.286 - [] 222.287 - (dosync 222.288 - (when-let [{old-out :out old-err :err} @*old-std-streams*] 222.289 - (ref-set *old-std-streams* nil) 222.290 - (System/setOut old-out) 222.291 - (System/setErr old-err)))) 222.292 - 222.293 - 222.294 -(defmacro with-logs 222.295 - "Evaluates exprs in a context in which *out* and *err* are bound to :info and 222.296 - :error logging, respectively. The specified log-ns value will be used to 222.297 - namespace all redirected logging." 222.298 - [log-ns & body] 222.299 - (if (and log-ns (seq body)) 222.300 - `(binding [*out* (java.io.OutputStreamWriter. 222.301 - (log-stream :info ~log-ns)) 222.302 - *err* (java.io.OutputStreamWriter. 222.303 - (log-stream :error ~log-ns))] 222.304 - ~@body))) 222.305 - 222.306 -(defmacro trace 222.307 - "Logs a message at the trace level." 222.308 - ([message] 222.309 - `(log :trace ~message)) 222.310 - ([message throwable] 222.311 - `(log :trace ~message ~throwable))) 222.312 - 222.313 -(defmacro debug 222.314 - "Logs a message at the debug level." 222.315 - ([message] 222.316 - `(log :debug ~message)) 222.317 - ([message throwable] 222.318 - `(log :debug ~message ~throwable))) 222.319 - 222.320 -(defmacro info 222.321 - "Logs a message at the info level." 222.322 - ([message] 222.323 - `(log :info ~message)) 222.324 - ([message throwable] 222.325 - `(log :info ~message ~throwable))) 222.326 - 222.327 -(defmacro warn 222.328 - "Logs a message at the warn level." 222.329 - ([message] 222.330 - `(log :warn ~message)) 222.331 - ([message throwable] 222.332 - `(log :warn ~message ~throwable))) 222.333 - 222.334 -(defmacro error 222.335 - "Logs a message at the error level." 222.336 - ([message] 222.337 - `(log :error ~message)) 222.338 - ([message throwable] 222.339 - `(log :error ~message ~throwable))) 222.340 - 222.341 -(defmacro fatal 222.342 - "Logs a message at the fatal level." 222.343 - ([message] 222.344 - `(log :fatal ~message)) 222.345 - ([message throwable] 222.346 - `(log :fatal ~message ~throwable)))
223.1 --- a/src/clojure/contrib/macro_utils.clj Sat Aug 21 06:25:44 2010 -0400 223.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 223.3 @@ -1,270 +0,0 @@ 223.4 -;; Macrolet and symbol-macrolet 223.5 - 223.6 -;; by Konrad Hinsen 223.7 -;; last updated January 14, 2010 223.8 - 223.9 -;; Copyright (c) Konrad Hinsen, 2009-2010. All rights reserved. The use 223.10 -;; and distribution terms for this software are covered by the Eclipse 223.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 223.12 -;; which can be found in the file epl-v10.html at the root of this 223.13 -;; distribution. By using this software in any fashion, you are 223.14 -;; agreeing to be bound by the terms of this license. You must not 223.15 -;; remove this notice, or any other, from this software. 223.16 - 223.17 -(ns 223.18 - ^{:author "Konrad Hinsen" 223.19 - :doc "Local macros and symbol macros 223.20 - 223.21 - Local macros are defined by a macrolet form. They are usable only 223.22 - inside its body. Symbol macros can be defined globally 223.23 - (defsymbolmacro) or locally (symbol-macrolet). A symbol 223.24 - macro defines a form that replaces a symbol during macro 223.25 - expansion. Function arguments and symbols bound in let 223.26 - forms are not subject to symbol macro expansion. 223.27 - 223.28 - Local macros are most useful in the definition of the expansion 223.29 - of another macro, they may be used anywhere. Global symbol 223.30 - macros can be used only inside a with-symbol-macros form."} 223.31 - clojure.contrib.macro-utils 223.32 - (:use [clojure.contrib.def :only (defvar-)])) 223.33 - 223.34 -; A set of all special forms. Special forms are not macro-expanded, making 223.35 -; it impossible to shadow them by macro definitions. For most special 223.36 -; forms, all the arguments are simply macro-expanded, but some forms 223.37 -; get special treatment. 223.38 -(defvar- special-forms 223.39 - (into #{} (keys clojure.lang.Compiler/specials))) 223.40 -; Value in the Clojure 1.2 branch: 223.41 -; #{deftype* new quote & var set! monitor-enter recur . case* clojure.core/import* reify* do fn* throw monitor-exit letfn* finally let* loop* try catch if def} 223.42 - 223.43 -; The following three vars are constantly redefined using the binding 223.44 -; form, imitating dynamic scoping. 223.45 -; 223.46 -; Local macros. 223.47 -(defvar- macro-fns {}) 223.48 -; Local symbol macros. 223.49 -(defvar- macro-symbols {}) 223.50 -; Symbols defined inside let forms or function arguments. 223.51 -(defvar- protected-symbols #{}) 223.52 - 223.53 -(defn- reserved? 223.54 - [symbol] 223.55 - "Return true if symbol is a reserved symbol (starting or ending with a dot)." 223.56 - (let [s (str symbol)] 223.57 - (or (= "." (subs s 0 1)) 223.58 - (= "." (subs s (dec (count s))))))) 223.59 - 223.60 -(defn- expand-symbol 223.61 - "Expand symbol macros" 223.62 - [symbol] 223.63 - (cond (contains? protected-symbols symbol) symbol 223.64 - (reserved? symbol) symbol 223.65 - (contains? macro-symbols symbol) (get macro-symbols symbol) 223.66 - :else (let [v (resolve symbol) 223.67 - m (meta v)] 223.68 - (if (:symbol-macro m) 223.69 - (var-get v) 223.70 - symbol)))) 223.71 - 223.72 -(defn- expand-1 223.73 - "Perform a single non-recursive macro expansion of form." 223.74 - [form] 223.75 - (cond 223.76 - (seq? form) 223.77 - (let [f (first form)] 223.78 - (cond (contains? special-forms f) form 223.79 - (contains? macro-fns f) (apply (get macro-fns f) (rest form)) 223.80 - (symbol? f) (let [exp (expand-symbol f)] 223.81 - (if (= exp f) 223.82 - (clojure.core/macroexpand-1 form) 223.83 - (cons exp (rest form)))) 223.84 - ; handle defmacro macros and Java method special forms 223.85 - :else (clojure.core/macroexpand-1 form))) 223.86 - (symbol? form) 223.87 - (expand-symbol form) 223.88 - :else 223.89 - form)) 223.90 - 223.91 -(defn- expand 223.92 - "Perform repeated non-recursive macro expansion of form, until it no 223.93 - longer changes." 223.94 - [form] 223.95 - (let [ex (expand-1 form)] 223.96 - (if (identical? ex form) 223.97 - form 223.98 - (recur ex)))) 223.99 - 223.100 -(declare expand-all) 223.101 - 223.102 -(defn- expand-args 223.103 - "Recursively expand the arguments of form, leaving its first 223.104 - n elements unchanged." 223.105 - ([form] 223.106 - (expand-args form 1)) 223.107 - ([form n] 223.108 - (doall (concat (take n form) (map expand-all (drop n form)))))) 223.109 - 223.110 -(defn- expand-bindings 223.111 - [bindings exprs] 223.112 - (if (empty? bindings) 223.113 - (list (doall (map expand-all exprs))) 223.114 - (let [[[s b] & bindings] bindings] 223.115 - (let [b (expand-all b)] 223.116 - (binding [protected-symbols (conj protected-symbols s)] 223.117 - (doall (cons [s b] (expand-bindings bindings exprs)))))))) 223.118 - 223.119 -(defn- expand-with-bindings 223.120 - "Handle let* and loop* forms. The symbols defined in them are protected 223.121 - from symbol macro expansion, the definitions and the body expressions 223.122 - are expanded recursively." 223.123 - [form] 223.124 - (let [f (first form) 223.125 - bindings (partition 2 (second form)) 223.126 - exprs (rest (rest form)) 223.127 - expanded (expand-bindings bindings exprs) 223.128 - bindings (vec (apply concat (butlast expanded))) 223.129 - exprs (last expanded)] 223.130 - (cons f (cons bindings exprs)))) 223.131 - 223.132 -(defn- expand-fn-body 223.133 - [[args & exprs]] 223.134 - (binding [protected-symbols (reduce conj protected-symbols 223.135 - (filter #(not (= % '&)) args))] 223.136 - (cons args (doall (map expand-all exprs))))) 223.137 - 223.138 -(defn- expand-fn 223.139 - "Handle fn* forms. The arguments are protected from symbol macro 223.140 - expansion, the bodies are expanded recursively." 223.141 - [form] 223.142 - (let [[f & bodies] form 223.143 - name (when (symbol? (first bodies)) (first bodies)) 223.144 - bodies (if (symbol? (first bodies)) (rest bodies) bodies) 223.145 - bodies (if (vector? (first bodies)) (list bodies) bodies) 223.146 - bodies (doall (map expand-fn-body bodies))] 223.147 - (if (nil? name) 223.148 - (cons f bodies) 223.149 - (cons f (cons name bodies))))) 223.150 - 223.151 -(defn- expand-method 223.152 - "Handle a method in a deftype* or reify* form." 223.153 - [m] 223.154 - (rest (expand-fn (cons 'fn* m)))) 223.155 - 223.156 -(defn- expand-deftype 223.157 - "Handle deftype* forms." 223.158 - [[symbol typename classname fields implements interfaces & methods]] 223.159 - (assert (= implements :implements)) 223.160 - (let [expanded-methods (map expand-method methods)] 223.161 - (concat 223.162 - (list symbol typename classname fields implements interfaces) 223.163 - expanded-methods))) 223.164 - 223.165 -(defn- expand-reify 223.166 - "Handle reify* forms." 223.167 - [[symbol interfaces & methods]] 223.168 - (let [expanded-methods (map expand-method methods)] 223.169 - (cons symbol (cons interfaces expanded-methods)))) 223.170 - 223.171 -; Handlers for special forms that require special treatment. The default 223.172 -; is expand-args. 223.173 -(defvar- special-form-handlers 223.174 - {'quote identity 223.175 - 'var identity 223.176 - 'def #(expand-args % 2) 223.177 - 'new #(expand-args % 2) 223.178 - 'let* expand-with-bindings 223.179 - 'loop* expand-with-bindings 223.180 - 'fn* expand-fn 223.181 - 'deftype* expand-deftype 223.182 - 'reify* expand-reify}) 223.183 - 223.184 -(defn- expand-list 223.185 - "Recursively expand a form that is a list or a cons." 223.186 - [form] 223.187 - (let [f (first form)] 223.188 - (if (symbol? f) 223.189 - (if (contains? special-forms f) 223.190 - ((get special-form-handlers f expand-args) form) 223.191 - (expand-args form)) 223.192 - (doall (map expand-all form))))) 223.193 - 223.194 -(defn- expand-all 223.195 - "Expand a form recursively." 223.196 - [form] 223.197 - (let [exp (expand form)] 223.198 - (cond (symbol? exp) exp 223.199 - (seq? exp) (expand-list exp) 223.200 - (vector? exp) (into [] (map expand-all exp)) 223.201 - (map? exp) (into {} (map expand-all (seq exp))) 223.202 - :else exp))) 223.203 - 223.204 -(defmacro macrolet 223.205 - "Define local macros that are used in the expansion of exprs. The 223.206 - syntax is the same as for letfn forms." 223.207 - [fn-bindings & exprs] 223.208 - (let [names (map first fn-bindings) 223.209 - name-map (into {} (map (fn [n] [(list 'quote n) n]) names)) 223.210 - macro-map (eval `(letfn ~fn-bindings ~name-map))] 223.211 - (binding [macro-fns (merge macro-fns macro-map) 223.212 - macro-symbols (apply dissoc macro-symbols names)] 223.213 - `(do ~@(doall (map expand-all exprs)))))) 223.214 - 223.215 -(defmacro symbol-macrolet 223.216 - "Define local symbol macros that are used in the expansion of exprs. 223.217 - The syntax is the same as for let forms." 223.218 - [symbol-bindings & exprs] 223.219 - (let [symbol-map (into {} (map vec (partition 2 symbol-bindings))) 223.220 - names (keys symbol-map)] 223.221 - (binding [macro-fns (apply dissoc macro-fns names) 223.222 - macro-symbols (merge macro-symbols symbol-map)] 223.223 - `(do ~@(doall (map expand-all exprs)))))) 223.224 - 223.225 -(defmacro defsymbolmacro 223.226 - "Define a symbol macro. Because symbol macros are not part of 223.227 - Clojure's built-in macro expansion system, they can be used only 223.228 - inside a with-symbol-macros form." 223.229 - [symbol expansion] 223.230 - (let [meta-map (if (meta symbol) (meta symbol) {}) 223.231 - meta-map (assoc meta-map :symbol-macro true)] 223.232 - `(def ~(with-meta symbol meta-map) (quote ~expansion)))) 223.233 - 223.234 -(defmacro with-symbol-macros 223.235 - "Fully expand exprs, including symbol macros." 223.236 - [& exprs] 223.237 - `(do ~@(doall (map expand-all exprs)))) 223.238 - 223.239 -(defmacro deftemplate 223.240 - "Define a macro that expands into forms after replacing the 223.241 - symbols in params (a vector) by the corresponding parameters 223.242 - given in the macro call." 223.243 - [name params & forms] 223.244 - (let [param-map (for [p params] (list (list 'quote p) (gensym))) 223.245 - template-params (vec (map second param-map)) 223.246 - param-map (vec (apply concat param-map)) 223.247 - expansion (list 'list (list 'quote `symbol-macrolet) param-map 223.248 - (list 'quote (cons 'do forms)))] 223.249 - `(defmacro ~name ~template-params ~expansion))) 223.250 - 223.251 -(defn mexpand-1 223.252 - "Like clojure.core/macroexpand-1, but takes into account symbol macros." 223.253 - [form] 223.254 - (binding [macro-fns {} 223.255 - macro-symbols {} 223.256 - protected-symbols #{}] 223.257 - (expand-1 form))) 223.258 - 223.259 -(defn mexpand 223.260 - "Like clojure.core/macroexpand, but takes into account symbol macros." 223.261 - [form] 223.262 - (binding [macro-fns {} 223.263 - macro-symbols {} 223.264 - protected-symbols #{}] 223.265 - (expand form))) 223.266 - 223.267 -(defn mexpand-all 223.268 - "Perform a full recursive macro expansion of a form." 223.269 - [form] 223.270 - (binding [macro-fns {} 223.271 - macro-symbols {} 223.272 - protected-symbols #{}] 223.273 - (expand-all form)))
224.1 --- a/src/clojure/contrib/macros.clj Sat Aug 21 06:25:44 2010 -0400 224.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 224.3 @@ -1,84 +0,0 @@ 224.4 -;; Various useful macros 224.5 -;; 224.6 -;; Everybody is invited to add their own little macros here! 224.7 -;; 224.8 -;; The use and distribution terms for this software are covered by the 224.9 -;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 224.10 -;; which can be found in the file epl-v10.html at the root of this 224.11 -;; distribution. By using this software in any fashion, you are 224.12 -;; agreeing to be bound by the terms of this license. You must not 224.13 -;; remove this notice, or any other, from this software. 224.14 - 224.15 -(ns 224.16 - ^{:author "Konrad Hinsen" 224.17 - :doc "Various small macros"} 224.18 - clojure.contrib.macros) 224.19 - 224.20 -;; By Konrad Hinsen 224.21 -(defmacro const 224.22 - "Evaluate the constant expression expr at compile time." 224.23 - [expr] 224.24 - (eval expr)) 224.25 - 224.26 -;; By Konrad Hinsen 224.27 -; This macro is made obsolete by Clojure's built-in letfn. I renamed it to 224.28 -; letfn- (to avoid a name clash) but leave it in for a while, since its 224.29 -; syntax is not quite the same as Clojure's. Expect this to disappear 224.30 -; in the long run! 224.31 -(defmacro letfn- 224.32 - "OBSOLETE: use clojure.core/letfn 224.33 - A variant of let for local function definitions. fn-bindings consists 224.34 - of name/args/body triples, with (letfn [name args body] ...) 224.35 - being equivalent to (let [name (fn name args body)] ...)." 224.36 - [fn-bindings & exprs] 224.37 - (let [makefn (fn [[name args body]] (list name (list 'fn name args body))) 224.38 - fns (vec (apply concat (map makefn (partition 3 fn-bindings))))] 224.39 - `(let ~fns ~@exprs))) 224.40 - 224.41 - ;; By Konrad Hinsen 224.42 - 224.43 - (defn- unqualified-symbol 224.44 - [s] 224.45 - (let [s-str (str s)] 224.46 - (symbol (subs s-str (inc (.indexOf s-str (int \/))))))) 224.47 - 224.48 -(defn- bound-var? 224.49 - [var] 224.50 - (try 224.51 - (do (deref var) true) 224.52 - (catch java.lang.IllegalStateException e false))) 224.53 - 224.54 -(defn- fns-from-ns 224.55 - [ns ns-symbol] 224.56 - (apply concat 224.57 - (for [[k v] (ns-publics ns) 224.58 - :when (and (bound-var? v) 224.59 - (fn? @v) 224.60 - (not (:macro (meta v))))] 224.61 - [k (symbol (str ns-symbol) (str k))]))) 224.62 - 224.63 -(defn- expand-symbol 224.64 - [ns-or-var-sym] 224.65 - (if (= ns-or-var-sym '*ns*) 224.66 - (fns-from-ns *ns* (ns-name *ns*)) 224.67 - (if-let [ns (find-ns ns-or-var-sym)] 224.68 - (fns-from-ns ns ns-or-var-sym) 224.69 - (list (unqualified-symbol ns-or-var-sym) ns-or-var-sym)))) 224.70 - 224.71 -(defmacro with-direct-linking 224.72 - "EXPERIMENTAL! 224.73 - Compiles the functions in body with direct links to the functions 224.74 - named in symbols, i.e. without a var lookup for each invocation. 224.75 - Symbols is a vector of symbols that name either vars or namespaces. 224.76 - A namespace reference is replaced by the list of all symbols in the 224.77 - namespace that are bound to functions. If symbols is not provided, 224.78 - the default value ['clojure.core] is used. The symbol *ns* can be 224.79 - used to refer to the current namespace." 224.80 - {:arglists '([symbols? & body])} 224.81 - [& body] 224.82 - (let [[symbols body] (if (vector? (first body)) 224.83 - [(first body) (rest body)] 224.84 - [['clojure.core] body]) 224.85 - bindings (vec (mapcat expand-symbol symbols))] 224.86 - `(let ~bindings ~@body))) 224.87 - 224.88 \ No newline at end of file
225.1 --- a/src/clojure/contrib/map_utils.clj Sat Aug 21 06:25:44 2010 -0400 225.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 225.3 @@ -1,55 +0,0 @@ 225.4 -;; Copyright (c) Jason Wolfe. All rights reserved. The use and 225.5 -;; distribution terms for this software are covered by the Eclipse Public 225.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 225.7 -;; be found in the file epl-v10.html at the root of this distribution. By 225.8 -;; using this software in any fashion, you are agreeing to be bound by the 225.9 -;; terms of this license. You must not remove this notice, or any other, 225.10 -;; from this software. 225.11 -;; 225.12 -;; map_utils.clj 225.13 -;; 225.14 -;; Utilities for operating on Clojure maps. 225.15 -;; 225.16 -;; jason at w01fe dot com 225.17 -;; Created 25 Feb 2009 225.18 - 225.19 -(ns 225.20 - ^{:author "Jason Wolfe, Chris Houser", 225.21 - :doc "Utilities for operating on Clojure maps."} 225.22 - clojure.contrib.map-utils) 225.23 - 225.24 - 225.25 -(defmacro lazy-get 225.26 - "Like get, but doesn't evaluate not-found unless it is needed." 225.27 - [map key not-found] 225.28 - `(if-let [pair# (find ~map ~key)] 225.29 - (val pair#) 225.30 - ~not-found)) 225.31 - 225.32 -(defn safe-get 225.33 - "Like get, but throws an exception if the key is not found." 225.34 - [map key] 225.35 - (lazy-get map key 225.36 - (throw (IllegalArgumentException. (format "Key %s not found in %s" key map))))) 225.37 - 225.38 -(defn safe-get-in 225.39 - "Like get-in, but throws an exception if any key is not found." 225.40 - [map ks] 225.41 - (reduce safe-get map ks)) 225.42 - 225.43 -; by Chouser: 225.44 -(defn deep-merge-with 225.45 - "Like merge-with, but merges maps recursively, applying the given fn 225.46 - only when there's a non-map at a particular level. 225.47 - 225.48 - (deepmerge + {:a {:b {:c 1 :d {:x 1 :y 2}} :e 3} :f 4} 225.49 - {:a {:b {:c 2 :d {:z 9} :z 3} :e 100}}) 225.50 - -> {:a {:b {:z 3, :c 3, :d {:z 9, :x 1, :y 2}}, :e 103}, :f 4}" 225.51 - [f & maps] 225.52 - (apply 225.53 - (fn m [& maps] 225.54 - (if (every? map? maps) 225.55 - (apply merge-with m maps) 225.56 - (apply f maps))) 225.57 - maps)) 225.58 -
226.1 --- a/src/clojure/contrib/math.clj Sat Aug 21 06:25:44 2010 -0400 226.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 226.3 @@ -1,247 +0,0 @@ 226.4 -;;; math.clj: math functions that deal intelligently with the various 226.5 -;;; types in Clojure's numeric tower, as well as math functions 226.6 -;;; commonly found in Scheme implementations. 226.7 - 226.8 -;; by Mark Engelberg (mark.engelberg@gmail.com) 226.9 -;; January 17, 2009 226.10 - 226.11 -;; expt - (expt x y) is x to the yth power, returns an exact number 226.12 -;; if the base is an exact number, and the power is an integer, 226.13 -;; otherwise returns a double. 226.14 -;; abs - (abs n) is the absolute value of n 226.15 -;; gcd - (gcd m n) returns the greatest common divisor of m and n 226.16 -;; lcm - (lcm m n) returns the least common multiple of m and n 226.17 - 226.18 -;; The behavior of the next three functions on doubles is consistent 226.19 -;; with the behavior of the corresponding functions 226.20 -;; in Java's Math library, but on exact numbers, returns an integer. 226.21 - 226.22 -;; floor - (floor n) returns the greatest integer less than or equal to n. 226.23 -;; If n is an exact number, floor returns an integer, 226.24 -;; otherwise a double. 226.25 -;; ceil - (ceil n) returns the least integer greater than or equal to n. 226.26 -;; If n is an exact number, ceil returns an integer, 226.27 -;; otherwise a double. 226.28 -;; round - (round n) rounds to the nearest integer. 226.29 -;; round always returns an integer. round rounds up for values 226.30 -;; exactly in between two integers. 226.31 - 226.32 - 226.33 -;; sqrt - Implements the sqrt behavior I'm accustomed to from PLT Scheme, 226.34 -;; specifically, if the input is an exact number, and is a square 226.35 -;; of an exact number, the output will be exact. The downside 226.36 -;; is that for the common case (inexact square root), some extra 226.37 -;; computation is done to look for an exact square root first. 226.38 -;; So if you need blazingly fast square root performance, and you 226.39 -;; know you're just going to need a double result, you're better 226.40 -;; off calling java's Math/sqrt, or alternatively, you could just 226.41 -;; convert your input to a double before calling this sqrt function. 226.42 -;; If Clojure ever gets complex numbers, then this function will 226.43 -;; need to be updated (so negative inputs yield complex outputs). 226.44 -;; exact-integer-sqrt - Implements a math function from the R6RS Scheme 226.45 -;; standard. (exact-integer-sqrt k) where k is a non-negative integer, 226.46 -;; returns [s r] where k = s^2+r and k < (s+1)^2. In other words, it 226.47 -;; returns the floor of the square root and the "remainder". 226.48 - 226.49 -(ns 226.50 - ^{:author "Mark Engelberg", 226.51 - :doc "Math functions that deal intelligently with the various 226.52 -types in Clojure's numeric tower, as well as math functions 226.53 -commonly found in Scheme implementations. 226.54 - 226.55 -expt - (expt x y) is x to the yth power, returns an exact number 226.56 - if the base is an exact number, and the power is an integer, 226.57 - otherwise returns a double. 226.58 -abs - (abs n) is the absolute value of n 226.59 -gcd - (gcd m n) returns the greatest common divisor of m and n 226.60 -lcm - (lcm m n) returns the least common multiple of m and n 226.61 - 226.62 -The behavior of the next three functions on doubles is consistent 226.63 -with the behavior of the corresponding functions 226.64 -in Java's Math library, but on exact numbers, returns an integer. 226.65 - 226.66 -floor - (floor n) returns the greatest integer less than or equal to n. 226.67 - If n is an exact number, floor returns an integer, 226.68 - otherwise a double. 226.69 -ceil - (ceil n) returns the least integer greater than or equal to n. 226.70 - If n is an exact number, ceil returns an integer, 226.71 - otherwise a double. 226.72 -round - (round n) rounds to the nearest integer. 226.73 - round always returns an integer. round rounds up for values 226.74 - exactly in between two integers. 226.75 - 226.76 - 226.77 -sqrt - Implements the sqrt behavior I'm accustomed to from PLT Scheme, 226.78 - specifically, if the input is an exact number, and is a square 226.79 - of an exact number, the output will be exact. The downside 226.80 - is that for the common case (inexact square root), some extra 226.81 - computation is done to look for an exact square root first. 226.82 - So if you need blazingly fast square root performance, and you 226.83 - know you're just going to need a double result, you're better 226.84 - off calling java's Math/sqrt, or alternatively, you could just 226.85 - convert your input to a double before calling this sqrt function. 226.86 - If Clojure ever gets complex numbers, then this function will 226.87 - need to be updated (so negative inputs yield complex outputs). 226.88 -exact-integer-sqrt - Implements a math function from the R6RS Scheme 226.89 - standard. (exact-integer-sqrt k) where k is a non-negative integer, 226.90 - returns [s r] where k = s^2+r and k < (s+1)^2. In other words, it 226.91 - returns the floor of the square root and the "remainder". 226.92 -"} 226.93 - clojure.contrib.math) 226.94 - 226.95 -(derive ::integer ::exact) 226.96 -(derive java.lang.Integer ::integer) 226.97 -(derive java.math.BigInteger ::integer) 226.98 -(derive java.lang.Long ::integer) 226.99 -(derive java.math.BigDecimal ::exact) 226.100 -(derive clojure.lang.Ratio ::exact) 226.101 -(derive java.lang.Double ::inexact) 226.102 -(derive java.lang.Float ::inexact) 226.103 - 226.104 -(defmulti ^{:arglists '([base pow]) 226.105 - :doc "(expt base pow) is base to the pow power. 226.106 -Returns an exact number if the base is an exact number and the power is an integer, otherwise returns a double."} 226.107 - expt (fn [x y] [(class x) (class y)])) 226.108 - 226.109 -(defn- expt-int [base pow] 226.110 - (loop [n pow, y (num 1), z base] 226.111 - (let [t (bit-and n 1), n (bit-shift-right n 1)] 226.112 - (cond 226.113 - (zero? t) (recur n y (* z z)) 226.114 - (zero? n) (* z y) 226.115 - :else (recur n (* z y) (* z z)))))) 226.116 - 226.117 -(defmethod expt [::exact ::integer] [base pow] 226.118 - (cond 226.119 - (pos? pow) (expt-int base pow) 226.120 - (zero? pow) 1 226.121 - :else (/ 1 (expt-int base (- pow))))) 226.122 - 226.123 -(defmethod expt :default [base pow] (Math/pow base pow)) 226.124 - 226.125 -(defn abs "(abs n) is the absolute value of n" [n] 226.126 - (cond 226.127 - (not (number? n)) (throw (IllegalArgumentException. 226.128 - "abs requires a number")) 226.129 - (neg? n) (- n) 226.130 - :else n)) 226.131 - 226.132 -(defmulti ^{:arglists '([n]) 226.133 - :doc "(floor n) returns the greatest integer less than or equal to n. 226.134 -If n is an exact number, floor returns an integer, otherwise a double."} 226.135 - floor class) 226.136 -(defmethod floor ::integer [n] n) 226.137 -(defmethod floor java.math.BigDecimal [n] (.. n (setScale 0 BigDecimal/ROUND_FLOOR) (toBigInteger))) 226.138 -(defmethod floor clojure.lang.Ratio [n] 226.139 - (if (pos? n) (quot (. n numerator) (. n denominator)) 226.140 - (dec (quot (. n numerator) (. n denominator))))) 226.141 -(defmethod floor :default [n] 226.142 - (Math/floor n)) 226.143 - 226.144 -(defmulti ^{:arglists '([n]) 226.145 - :doc "(ceil n) returns the least integer greater than or equal to n. 226.146 -If n is an exact number, ceil returns an integer, otherwise a double."} 226.147 - ceil class) 226.148 -(defmethod ceil ::integer [n] n) 226.149 -(defmethod ceil java.math.BigDecimal [n] (.. n (setScale 0 BigDecimal/ROUND_CEILING) (toBigInteger))) 226.150 -(defmethod ceil clojure.lang.Ratio [n] 226.151 - (if (pos? n) (inc (quot (. n numerator) (. n denominator))) 226.152 - (quot (. n numerator) (. n denominator)))) 226.153 -(defmethod ceil :default [n] 226.154 - (Math/ceil n)) 226.155 - 226.156 -(defmulti ^{:arglists '([n]) 226.157 - :doc "(round n) rounds to the nearest integer. 226.158 -round always returns an integer. Rounds up for values exactly in between two integers."} 226.159 - round class) 226.160 -(defmethod round ::integer [n] n) 226.161 -(defmethod round java.math.BigDecimal [n] (floor (+ n 0.5M))) 226.162 -(defmethod round clojure.lang.Ratio [n] (floor (+ n 1/2))) 226.163 -(defmethod round :default [n] (Math/round n)) 226.164 - 226.165 -(defn gcd "(gcd a b) returns the greatest common divisor of a and b" [a b] 226.166 - (if (or (not (integer? a)) (not (integer? b))) 226.167 - (throw (IllegalArgumentException. "gcd requires two integers")) 226.168 - (loop [a (abs a) b (abs b)] 226.169 - (if (zero? b) a, 226.170 - (recur b (mod a b)))))) 226.171 - 226.172 -(defn lcm 226.173 - "(lcm a b) returns the least common multiple of a and b" 226.174 - [a b] 226.175 - (when (or (not (integer? a)) (not (integer? b))) 226.176 - (throw (IllegalArgumentException. "lcm requires two integers"))) 226.177 - (cond (zero? a) 0 226.178 - (zero? b) 0 226.179 - :else (abs (* b (quot a (gcd a b)))))) 226.180 - 226.181 -; Length of integer in binary, used as helper function for sqrt. 226.182 -(defmulti ^{:private true} integer-length class) 226.183 -(defmethod integer-length java.lang.Integer [n] 226.184 - (count (Integer/toBinaryString n))) 226.185 -(defmethod integer-length java.lang.Long [n] 226.186 - (count (Long/toBinaryString n))) 226.187 -(defmethod integer-length java.math.BigInteger [n] 226.188 - (count (. n toString 2))) 226.189 - 226.190 -;; Produces the largest integer less than or equal to the square root of n 226.191 -;; Input n must be a non-negative integer 226.192 -(defn- integer-sqrt [n] 226.193 - (cond 226.194 - (> n 24) 226.195 - (let [n-len (integer-length n)] 226.196 - (loop [init-value (if (even? n-len) 226.197 - (bit-shift-left 1 (bit-shift-right n-len 1)) 226.198 - (bit-shift-left 2 (bit-shift-right n-len 1)))] 226.199 - (let [iterated-value (bit-shift-right (+ init-value (quot n init-value)) 1)] 226.200 - (if (>= iterated-value init-value) 226.201 - init-value 226.202 - (recur iterated-value))))) 226.203 - (> n 15) 4 226.204 - (> n 8) 3 226.205 - (> n 3) 2 226.206 - (> n 0) 1 226.207 - (> n -1) 0)) 226.208 - 226.209 -(defn exact-integer-sqrt "(exact-integer-sqrt n) expects a non-negative integer n, and returns [s r] where n = s^2+r and n < (s+1)^2. In other words, it returns the floor of the square root and the 'remainder'. 226.210 -For example, (exact-integer-sqrt 15) is [3 6] because 15 = 3^2+6." 226.211 - [n] 226.212 - (if (or (not (integer? n)) (neg? n)) 226.213 - (throw (IllegalArgumentException. "exact-integer-sqrt requires a non-negative integer")) 226.214 - (let [isqrt (integer-sqrt n), 226.215 - error (- n (* isqrt isqrt))] 226.216 - [isqrt error]))) 226.217 - 226.218 -(defmulti ^{:arglists '([n]) 226.219 - :doc "Square root, but returns exact number if possible."} 226.220 - sqrt class) 226.221 -(defmethod sqrt ::integer [n] 226.222 - (if (neg? n) Double/NaN 226.223 - (let [isqrt (integer-sqrt n), 226.224 - error (- n (* isqrt isqrt))] 226.225 - (if (zero? error) isqrt 226.226 - (Math/sqrt n))))) 226.227 - 226.228 -(defmethod sqrt clojure.lang.Ratio [n] 226.229 - (if (neg? n) Double/NaN 226.230 - (let [numerator (.numerator n), 226.231 - denominator (.denominator n), 226.232 - sqrtnum (sqrt numerator)] 226.233 - (if (float? sqrtnum) 226.234 - (Math/sqrt n) 226.235 - (let [sqrtden (sqrt denominator)] 226.236 - (if (float? sqrtnum) 226.237 - (Math/sqrt n) 226.238 - (/ sqrtnum sqrtden))))))) 226.239 - 226.240 -(defmethod sqrt java.math.BigDecimal [n] 226.241 - (if (neg? n) Double/NaN 226.242 - (let [frac (rationalize n), 226.243 - sqrtfrac (sqrt frac)] 226.244 - (if (ratio? sqrtfrac) 226.245 - (/ (BigDecimal. (.numerator sqrtfrac)) 226.246 - (BigDecimal. (.denominator sqrtfrac))) 226.247 - sqrtfrac)))) 226.248 - 226.249 -(defmethod sqrt :default [n] 226.250 - (Math/sqrt n))
227.1 --- a/src/clojure/contrib/miglayout.clj Sat Aug 21 06:25:44 2010 -0400 227.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 227.3 @@ -1,79 +0,0 @@ 227.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 227.5 -;; distribution terms for this software are covered by the Eclipse Public 227.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 227.7 -;; be found in the file epl-v10.html at the root of this distribution. By 227.8 -;; using this software in any fashion, you are agreeing to be bound by the 227.9 -;; terms of this license. You must not remove this notice, or any other, 227.10 -;; from this software. 227.11 -;; 227.12 -;; clojure.contrib.miglayout 227.13 -;; 227.14 -;; Clojure support for the MiGLayout layout manager 227.15 -;; http://www.miglayout.com/ 227.16 -;; 227.17 -;; Example: 227.18 -;; 227.19 -;; (use '[clojure.contrib.miglayout.test :as mlt :only ()]) 227.20 -;; (dotimes [i 5] (mlt/run-test i)) 227.21 -;; 227.22 -;; scgilardi (gmail) 227.23 -;; Created 5 October 2008 227.24 - 227.25 -(ns 227.26 - ^{:author "Stephen C. Gilardi", 227.27 - :doc "Clojure support for the MiGLayout layout manager 227.28 -http://www.miglayout.com/ 227.29 - 227.30 -Example: 227.31 - 227.32 - (use '[clojure.contrib.miglayout.test :as mlt :only ()]) 227.33 - (dotimes [i 5] (mlt/run-test i)) 227.34 - 227.35 -"} 227.36 - clojure.contrib.miglayout 227.37 - (:import javax.swing.JComponent) 227.38 - (:use clojure.contrib.miglayout.internal)) 227.39 - 227.40 -(defn miglayout 227.41 - "Adds java.awt.Components to a javax.swing.JComponent with constraints 227.42 - formatted for the MiGLayout layout manager. 227.43 - 227.44 - Arguments: container [item constraint*]* 227.45 - 227.46 - - container: the container for the specified components, its layout 227.47 - manager will be set to a new instance of MigLayout 227.48 - 227.49 - - an inline series of items and constraints--each item may be followed 227.50 - by zero or more constraints. 227.51 - 227.52 - Item: 227.53 - 227.54 - - An item is either a Component or one of the keywords :layout 227.55 - :column or :row. Constraints for a keyword item affect the entire 227.56 - layout. 227.57 - 227.58 - Constraint: string, keyword, vector, map, or set 227.59 - 227.60 - - A string specifies one or more constraints each with zero or more 227.61 - arguments. 227.62 - - A keyword specifies a single constraint without arguments 227.63 - - A vector specifies a single constraint with one or more arguments 227.64 - - A map specifies one or more constraints as keys, each mapped to a 227.65 - single argument 227.66 - - A set groups two or more constraints, each a string, keyword, 227.67 - vector, map, or set 227.68 - 227.69 - Any items marked with an \"id\" constraint will be included in a map from 227.70 - id to component attached to the container. The map can be retrieved using 227.71 - clojure.contrib.miglayout/components." 227.72 - [^JComponent container & args] 227.73 - (let [item-constraints (apply parse-item-constraints args) 227.74 - {:keys [keywords components]} item-constraints 227.75 - {:keys [layout column row]} keywords] 227.76 - (do-layout container layout column row components))) 227.77 - 227.78 -(defn components 227.79 - "Returns a map from id (a keyword) to component for all components with 227.80 - an id constraint set" 227.81 - [^JComponent container] 227.82 - (get-components container))
228.1 --- a/src/clojure/contrib/miglayout/internal.clj Sat Aug 21 06:25:44 2010 -0400 228.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 228.3 @@ -1,120 +0,0 @@ 228.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 228.5 -;; distribution terms for this software are covered by the Eclipse Public 228.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 228.7 -;; be found in the file epl-v10.html at the root of this distribution. By 228.8 -;; using this software in any fashion, you are agreeing to be bound by the 228.9 -;; terms of this license. You must not remove this notice, or any other, 228.10 -;; from this software. 228.11 -;; 228.12 -;; clojure.contrib.miglayout.internal 228.13 -;; 228.14 -;; Internal functions for 'clojure.contrib.miglayout 228.15 -;; 228.16 -;; scgilardi (gmail) 228.17 -;; Created 13 October 2008 228.18 - 228.19 -(ns clojure.contrib.miglayout.internal 228.20 - (:import (clojure.lang RT Reflector) 228.21 - java.awt.Component 228.22 - javax.swing.JComponent) 228.23 - (:use (clojure.contrib 228.24 - [core :only (new-by-name)] 228.25 - [except :only (throwf)] 228.26 - [fcase :only (fcase)] 228.27 - [string :only (as-str)]))) 228.28 - 228.29 -(def MigLayout "net.miginfocom.swing.MigLayout") 228.30 -(def LayoutCallback "net.miginfocom.layout.LayoutCallback") 228.31 -(def ConstraintParser "net.miginfocom.layout.ConstraintParser") 228.32 - 228.33 -(declare format-constraints) 228.34 - 228.35 -(defn format-constraint 228.36 - "Returns a vector of vectors representing one or more constraints 228.37 - separated by commas. Constraints may be specified in Clojure using 228.38 - strings, keywords, vectors, maps, and/or sets." 228.39 - [c] 228.40 - [[", "] 228.41 - (fcase #(%1 %2) c 228.42 - string? [c] 228.43 - keyword? [c] 228.44 - vector? (interpose " " c) 228.45 - map? (apply concat (interpose [", "] (map #(interpose " " %) c))) 228.46 - set? (apply concat (interpose [", "] (map format-constraints c))) 228.47 - (throwf IllegalArgumentException 228.48 - "unrecognized constraint: %s (%s)" c (class c)))]) 228.49 - 228.50 -(defn format-constraints 228.51 - "Returns a string representing all the constraints for one keyword-item 228.52 - or component formatted for miglayout." 228.53 - [& constraints] 228.54 - (let [formatted 228.55 - (apply str 228.56 - (map as-str 228.57 - (rest (reduce concat [] 228.58 - (mapcat format-constraint constraints)))))] 228.59 -;; (prn formatted) 228.60 - formatted)) 228.61 - 228.62 -(defn component? 228.63 - "Returns true if x is a java.awt.Component" 228.64 - [x] 228.65 - (instance? Component x)) 228.66 - 228.67 -(defn constraint? 228.68 - "Returns true if x is not a keyword-item or component" 228.69 - [x] 228.70 - (not 228.71 - (or (component? x) 228.72 - (#{:layout :column :row} x)))) 228.73 - 228.74 -(defn parse-item-constraints 228.75 - "Iterates over args and builds a map containing values associated with 228.76 - :keywords and :components. The value for :keywords is a map from keyword 228.77 - items to constraints strings. The value for :components is a vector of 228.78 - vectors each associating a component with its constraints string." 228.79 - [& args] 228.80 - (loop [[item & args] args 228.81 - item-constraints {:keywords {} :components []}] 228.82 - (if item 228.83 - (let [[constraints args] (split-with constraint? args)] 228.84 - (recur args 228.85 - (update-in 228.86 - item-constraints 228.87 - [(if (component? item) :components :keywords)] 228.88 - conj [item (apply format-constraints constraints)]))) 228.89 - item-constraints))) 228.90 - 228.91 -(defn parse-component-constraint 228.92 - "Parses a component constraint string returning a CC object" 228.93 - [constraint] 228.94 - (Reflector/invokeStaticMethod 228.95 - ConstraintParser "parseComponentConstraint" (into-array [constraint]))) 228.96 - 228.97 -(defn add-components 228.98 - "Adds components with constraints to a container" 228.99 - [^JComponent container components] 228.100 - (loop [[[^Component component constraint] & components] components 228.101 - id-map nil] 228.102 - (if component 228.103 - (let [cc (parse-component-constraint constraint)] 228.104 - (.add container component cc) 228.105 - (recur 228.106 - components 228.107 - (if-let [id (.getId cc)] 228.108 - (assoc id-map (keyword id) component) 228.109 - id-map))) 228.110 - (doto container (.putClientProperty ::components id-map))))) 228.111 - 228.112 -(defn get-components 228.113 - "Returns a map from id to component for all components with an id" 228.114 - [^JComponent container] 228.115 - (.getClientProperty container ::components)) 228.116 - 228.117 -(defn do-layout 228.118 - "Attaches a MigLayout layout manager to container and adds components 228.119 - with constraints" 228.120 - [^JComponent container layout column row components] 228.121 - (doto container 228.122 - (.setLayout (new-by-name MigLayout layout column row)) 228.123 - (add-components components)))
229.1 --- a/src/clojure/contrib/mmap.clj Sat Aug 21 06:25:44 2010 -0400 229.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 229.3 @@ -1,90 +0,0 @@ 229.4 -; Copyright (c) Chris Houser, April 2008. All rights reserved. 229.5 -; The use and distribution terms for this software are covered by the 229.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 229.7 -; which can be found in the file epl-v10.html at the root of this distribution. 229.8 -; By using this software in any fashion, you are agreeing to be bound by 229.9 -; the terms of this license. 229.10 -; You must not remove this notice, or any other, from this software. 229.11 - 229.12 -; Functions for memory-mapping files, plus some functions that use a 229.13 -; mmaped file for "normal" activies -- slurp, load-file, etc. 229.14 - 229.15 -(ns 229.16 - ^{:author "Chris Houser", 229.17 - :doc "Functions for memory-mapping files, plus some functions that use a 229.18 -mmaped file for \"normal\" activies -- slurp, load-file, etc."} 229.19 - clojure.contrib.mmap 229.20 - (:refer-clojure :exclude (slurp load-file)) 229.21 - (:import (java.nio ByteBuffer CharBuffer) 229.22 - (java.io PushbackReader InputStream InputStreamReader 229.23 - FileInputStream))) 229.24 - 229.25 -;(set! *warn-on-reflection* true) 229.26 - 229.27 -(def READ_ONLY ^{:private true} 229.28 - (java.nio.channels.FileChannel$MapMode/READ_ONLY)) 229.29 - 229.30 -(defn mmap 229.31 - "Memory-map the file named f. Returns a ByteBuffer." 229.32 - [f] 229.33 - (let [channel (.getChannel (FileInputStream. f))] 229.34 - (.map channel READ_ONLY 0 (.size channel)))) 229.35 - 229.36 -(defn slurp 229.37 - "Reads the file named by f and returns it as a string." 229.38 - [^String f] 229.39 - (.. java.nio.charset.Charset (forName "UTF-8") 229.40 - (newDecoder) (decode (mmap f)))) 229.41 - 229.42 -(defn buffer-stream 229.43 - "Returns an InputStream for a ByteBuffer, such as returned by mmap." 229.44 - [^ByteBuffer buf] 229.45 - (proxy [InputStream] [] 229.46 - (available [] (.remaining buf)) 229.47 - (read 229.48 - ([] (if (.hasRemaining buf) (.get buf) -1)) 229.49 - ([dst offset len] (let [actlen (min (.remaining buf) len)] 229.50 - (.get buf dst offset actlen) 229.51 - (if (< actlen 1) -1 actlen)))))) 229.52 - 229.53 -(defn load-file [f] 229.54 - "Like clojure.lang/load-file, but uses mmap internally." 229.55 - (with-open [rdr (-> f mmap buffer-stream InputStreamReader. PushbackReader.)] 229.56 - (load-reader rdr))) 229.57 - 229.58 - 229.59 -(comment 229.60 - 229.61 -(alias 'mmap 'clojure.contrib.mmap) 229.62 -(alias 'core 'clojure.core) 229.63 - 229.64 -;--- 229.65 -; zip_filter.clj is 95KB 229.66 -(def tf "/home/chouser/build/clojure/src/clj/clojure/core.clj") 229.67 -(println "\nload-file" tf) 229.68 -(time (dotimes [_ 5] (core/load-file tf))) ; 5420.177813 msecs 229.69 -(time (dotimes [_ 5] (mmap/load-file tf))) ; 7946.854434 msecs -- not so good 229.70 - 229.71 -;--- 229.72 -; kern.log.0 is 961KB 229.73 -(def tf "/var/log/kern.log.0") 229.74 -(println "\nslurp" tf) 229.75 -(time (dotimes [_ 10] (.length (core/slurp tf)))) ; 435.767226 msecs 229.76 -(time (dotimes [_ 10] (.length (mmap/slurp tf)))) ; 93.176858 msecs 229.77 - 229.78 -;--- 229.79 -; kern.log.0 is 961KB 229.80 -(def tf "/var/log/kern.log.0") 229.81 -(println "\nregex slurp large" tf) 229.82 -(time (dotimes [_ 10] (count (re-seq #"EXT3.*" (core/slurp tf))))) ; 416 229.83 -(time (dotimes [_ 10] (count (re-seq #"EXT3.*" (mmap/slurp tf))))) ; 101 229.84 - 229.85 -;--- 229.86 -; mmap.clj is about 3.1KB 229.87 -(def tf "/home/chouser/proj/clojure-contrib/src/clojure/contrib/mmap.clj") 229.88 -(println "\nregex slurp small" tf) 229.89 - 229.90 -(time (dotimes [_ 1000] (count (re-seq #"defn \S*" (core/slurp tf))))) ; 308 229.91 -(time (dotimes [_ 1000] (count (re-seq #"defn \S*" (mmap/slurp tf))))) ; 198 229.92 - 229.93 -)
230.1 --- a/src/clojure/contrib/mock.clj Sat Aug 21 06:25:44 2010 -0400 230.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 230.3 @@ -1,285 +0,0 @@ 230.4 -;;; clojure.contrib.mock.clj: mocking/expectation framework for Clojure 230.5 - 230.6 -;; by Matt Clark 230.7 - 230.8 -;; Copyright (c) Matt Clark, 2009. All rights reserved. The use 230.9 -;; and distribution terms for this software are covered by the Eclipse 230.10 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php). 230.11 -;; By using this software in any fashion, you are 230.12 -;; agreeing to be bound by the terms of this license. You must not 230.13 -;; remove this notice, or any other, from this software. 230.14 -;;------------------------------------------------------------------------------ 230.15 - 230.16 -(comment 230.17 - ;; This is a simple function mocking library I accidentally wrote as a side 230.18 - ;; effect of trying to write an opengl library in clojure. This is loosely 230.19 - ;; based on various ruby and java mocking frameworks I have used in the past 230.20 - ;; such as mockito, easymock, and whatever rspec uses. 230.21 - ;; 230.22 - ;; expect uses bindings to wrap the functions that are being tested and 230.23 - ;; then validates the invocation count at the end. The expect macro is the 230.24 - ;; main entry point and it is given a vector of binding pairs. 230.25 - ;; The first of each pair names the dependent function you want to override, 230.26 - ;; while the second is a hashmap containing the mock description, usually 230.27 - ;; created via the simple helper methods described below. 230.28 - ;; 230.29 - ;; Usage: 230.30 - ;; 230.31 - ;; there are one or more dependent functions: 230.32 - 230.33 - (defn dep-fn1 [] "time consuming calculation in 3rd party library") 230.34 - (defn dep-fn2 [x] "function with undesirable side effects while testing") 230.35 - 230.36 - ;; then we have the code under test that calls these other functions: 230.37 - 230.38 - (defn my-code-under-test [] (dep-fn1) (dep-fn2 "a") (+ 2 2)) 230.39 - 230.40 - ;; to test this code, we simply surround it with an expect macro within 230.41 - ;; the test: 230.42 - 230.43 - (expect [dep-fn1 (times 1) 230.44 - dep-fn2 (times 1 (has-args [#(= "a" %)]))] 230.45 - (my-code-under-test)) 230.46 - 230.47 - ;; When an expectation fails during execution of the function under test, 230.48 - ;; an error condition function is called with the name of the function 230.49 - ;; being mocked, the expected form and the actual value. These 230.50 - ;; error functions can be overridden to allow easy integration into 230.51 - ;; test frameworks such as test-is by reporting errors in the function 230.52 - ;; overrides. 230.53 - 230.54 - ) ;; end comment 230.55 - 230.56 -(ns clojure.contrib.mock 230.57 - ^{:author "Matt Clark", 230.58 - :doc "function mocking/expectations for Clojure" } 230.59 - (:use [clojure.contrib.seq :only (positions)] 230.60 - [clojure.contrib.def :only (defmacro-)])) 230.61 - 230.62 - 230.63 -;;------------------------------------------------------------------------------ 230.64 -;; These are the error condition functions. Override them to integrate into 230.65 -;; the test framework of your choice, or to simply customize error handling. 230.66 - 230.67 -(defn report-problem 230.68 - {:dynamic true} 230.69 - ([function expected actual] 230.70 - (report-problem function expected actual "Expectation not met.")) 230.71 - ([function expected actual message] 230.72 - (prn (str message " Function name: " function 230.73 - " expected: " expected " actual: " actual)))) 230.74 - 230.75 -(defn no-matching-function-signature 230.76 - {:dynamic true} 230.77 - [function expected actual] 230.78 - (report-problem function expected actual 230.79 - "No matching real function signature for given argument count.")) 230.80 - 230.81 -(defn unexpected-args 230.82 - {:dynamic true} 230.83 - [function expected actual i] 230.84 - (report-problem function expected actual 230.85 - (str "Argument " i " has an unexpected value for function."))) 230.86 - 230.87 -(defn incorrect-invocation-count 230.88 - {:dynamic true} 230.89 - [function expected actual] 230.90 - (report-problem function expected actual "Unexpected invocation count.")) 230.91 - 230.92 - 230.93 -;;------------------------------------------------------------------------------ 230.94 -;; Internal Functions - ignore these 230.95 - 230.96 - 230.97 -(defn- has-arg-count-match? 230.98 - "Given the sequence of accepted argument vectors for a function, 230.99 -returns true if at least one matches the given-count value." 230.100 - [arg-lists given-count] 230.101 - (some #(let [[ind] (positions #{'&} %)] 230.102 - (if ind 230.103 - (>= given-count ind) 230.104 - (= (count %) given-count))) 230.105 - arg-lists)) 230.106 - 230.107 - 230.108 -(defn has-matching-signature? 230.109 - "Calls no-matching-function-signature if no match is found for the given 230.110 -function. If no argslist meta data is available for the function, it is 230.111 -not called." 230.112 - [fn-name args] 230.113 - (let [arg-count (count args) 230.114 - arg-lists (:arglists (meta (resolve fn-name)))] 230.115 - (if (and arg-lists (not (has-arg-count-match? arg-lists arg-count))) 230.116 - (no-matching-function-signature fn-name arg-lists args)))) 230.117 - 230.118 - 230.119 -(defn make-arg-checker 230.120 - "Creates the argument verifying function for a replaced dependency within 230.121 -the expectation bound scope. These functions take the additional argument 230.122 -of the name of the replaced function, then the rest of their args. It is 230.123 -designed to be called from the mock function generated in the first argument 230.124 -of the mock info object created by make-mock." 230.125 - [arg-preds arg-pred-forms] 230.126 - (let [sanitized-preds (map (fn [v] (if (fn? v) v #(= v %))) arg-preds)] 230.127 - (fn [fn-name & args] 230.128 - (every? true? 230.129 - (map (fn [pred arg pred-form i] (if (pred arg) true 230.130 - (unexpected-args fn-name pred-form arg i))) 230.131 - sanitized-preds args arg-pred-forms (iterate inc 0)))))) 230.132 - 230.133 - 230.134 -(defn make-count-checker 230.135 - "creates the count checker that is invoked at the end of an expectation, after 230.136 -the code under test has all been executed. The function returned takes the 230.137 -name of the associated dependency and the invocation count as arguments." 230.138 - [pred pred-form] 230.139 - (let [pred-fn (if (integer? pred) #(= pred %) pred)] 230.140 - (fn [fn-name v] (if (pred-fn v) true 230.141 - (incorrect-invocation-count fn-name pred-form v))))) 230.142 - 230.143 -; Borrowed from clojure core. Remove if this ever becomes public there. 230.144 -(defmacro- assert-args 230.145 - [fnname & pairs] 230.146 - `(do (when-not ~(first pairs) 230.147 - (throw (IllegalArgumentException. 230.148 - ~(str fnname " requires " (second pairs))))) 230.149 - ~(let [more (nnext pairs)] 230.150 - (when more 230.151 - (list* `assert-args fnname more))))) 230.152 - 230.153 -(defn make-mock 230.154 - "creates a vector containing the following information for the named function: 230.155 -1. dependent function replacement - verifies signature, calls arg checker, 230.156 -increases count, returns return value. 230.157 -2. an atom containing the invocation count 230.158 -3. the invocation count checker function 230.159 -4. a symbol of the name of the function being replaced." 230.160 - [fn-name expectation-hash] 230.161 - (assert-args make-mock 230.162 - (map? expectation-hash) "a map of expectations") 230.163 - (let [arg-checker (or (expectation-hash :has-args) (fn [& args] true)) 230.164 - count-atom (atom 0) 230.165 - ret-fn (or 230.166 - (expectation-hash :calls) 230.167 - (fn [& args] (expectation-hash :returns)))] 230.168 - [(fn [& args] 230.169 - (has-matching-signature? fn-name args) 230.170 - (apply arg-checker fn-name args) 230.171 - (swap! count-atom inc) 230.172 - (apply ret-fn args)) 230.173 - count-atom 230.174 - (or (expectation-hash :times) (fn [fn-name v] true)) 230.175 - fn-name])) 230.176 - 230.177 - 230.178 -(defn validate-counts 230.179 - "given the sequence of all mock data for the expectation, simply calls the 230.180 -count checker for each dependency." 230.181 - [mock-data] (doseq [[mfn i checker fn-name] mock-data] (checker fn-name @i))) 230.182 - 230.183 -(defn ^{:private true} make-bindings [expect-bindings mock-data-sym] 230.184 - `[~@(interleave (map #(first %) (partition 2 expect-bindings)) 230.185 - (map (fn [i] `(nth (nth ~mock-data-sym ~i) 0)) 230.186 - (range (quot (count expect-bindings) 2))))]) 230.187 - 230.188 - 230.189 -;;------------------------------------------------------------------------------ 230.190 -;; These are convenience functions to improve the readability and use of this 230.191 -;; library. Useful in expressions such as: 230.192 -;; (expect [dep-fn1 (times (more-than 1) (returns 15)) etc) 230.193 - 230.194 -(defn once [x] (= 1 x)) 230.195 - 230.196 -(defn never [x] (zero? x)) 230.197 - 230.198 -(defn more-than [x] #(< x %)) 230.199 - 230.200 -(defn less-than [x] #(> x %)) 230.201 - 230.202 -(defn between [x y] #(and (< x %) (> y %))) 230.203 - 230.204 - 230.205 -;;------------------------------------------------------------------------------ 230.206 -;; The following functions can be used to build up the expectation hash. 230.207 - 230.208 -(defn returns 230.209 - "Creates or associates to an existing expectation hash the :returns key with 230.210 -a value to be returned by the expectation after a successful invocation 230.211 -matching its expected arguments (if applicable). 230.212 -Usage: 230.213 -(returns ret-value expectation-hash?)" 230.214 - 230.215 - ([val] (returns val {})) 230.216 - ([val expectation-hash] (assoc expectation-hash :returns val))) 230.217 - 230.218 - 230.219 -(defn calls 230.220 - "Creates or associates to an existing expectation hash the :calls key with a 230.221 -function that will be called with the given arguments. The return value from 230.222 -this function will be returned returned by the expected function. If both this 230.223 -and returns are specified, the return value of \"calls\" will have precedence. 230.224 -Usage: 230.225 -(calls some-fn expectation-hash?)" 230.226 - 230.227 - ([val] (calls val {})) 230.228 - ([val expectation-hash] (assoc expectation-hash :calls val))) 230.229 - 230.230 - 230.231 -(defmacro has-args 230.232 - "Creates or associates to an existing expectation hash the :has-args key with 230.233 -a value corresponding to a function that will either return true if its 230.234 -argument expectations are met or throw an exception with the details of the 230.235 -first failed argument it encounters. 230.236 -Only specify as many predicates as you are interested in verifying. The rest 230.237 -of the values are safely ignored. 230.238 -Usage: 230.239 -(has-args [arg-pred-1 arg-pred-2 ... arg-pred-n] expectation-hash?)" 230.240 - 230.241 - ([arg-pred-forms] `(has-args ~arg-pred-forms {})) 230.242 - ([arg-pred-forms expect-hash-form] 230.243 - (assert-args has-args 230.244 - (vector? arg-pred-forms) "a vector of argument predicates") 230.245 - `(assoc ~expect-hash-form :has-args 230.246 - (make-arg-checker ~arg-pred-forms '~arg-pred-forms)))) 230.247 - 230.248 - 230.249 -(defmacro times 230.250 - "Creates or associates to an existing expectation hash the :times key with a 230.251 -value corresponding to a predicate function which expects an integer value. 230.252 -This function can either be specified as the first argument to times or can be 230.253 -the result of calling times with an integer argument, in which case the 230.254 -predicate will default to being an exact match. This predicate is called at 230.255 -the end of an expect expression to validate that an expected dependency 230.256 -function was called the expected number of times. 230.257 -Usage: 230.258 -(times n) 230.259 -(times #(> n %)) 230.260 -(times n expectation-hash)" 230.261 - ([times-fn] `(times ~times-fn {})) 230.262 - ([times-fn expectation-hash] 230.263 - `(assoc ~expectation-hash :times (make-count-checker ~times-fn '~times-fn)))) 230.264 - 230.265 - 230.266 -;------------------------------------------------------------------------------- 230.267 -; The main expect macro. 230.268 -(defmacro expect 230.269 - "Use expect to redirect calls to dependent functions that are made within the 230.270 -code under test. Instead of calling the functions that would normally be used, 230.271 -temporary stubs are used, which can verify function parameters and call counts. 230.272 -Return values can also be specified as needed. 230.273 -Usage: 230.274 -(expect [dep-fn (has-args [arg-pred1] (times n (returns x)))] 230.275 - (function-under-test a b c))" 230.276 - 230.277 - [expect-bindings & body] 230.278 - (assert-args expect 230.279 - (vector? expect-bindings) "a vector of expectation bindings" 230.280 - (even? (count expect-bindings)) 230.281 - "an even number of forms in expectation bindings") 230.282 - (let [mock-data (gensym "mock-data_")] 230.283 - `(let [~mock-data (map (fn [args#] 230.284 - (apply clojure.contrib.mock/make-mock args#)) 230.285 - ~(cons 'list (map (fn [[n m]] (vector (list 'quote n) m)) 230.286 - (partition 2 expect-bindings))))] 230.287 - (binding ~(make-bindings expect-bindings mock-data) ~@body) 230.288 - (clojure.contrib.mock/validate-counts ~mock-data) true)))
231.1 --- a/src/clojure/contrib/mock.clj.rej Sat Aug 21 06:25:44 2010 -0400 231.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 231.3 @@ -1,569 +0,0 @@ 231.4 -diff a/src/main/clojure/clojure/contrib/mock.clj b/src/main/clojure/clojure/contrib/mock.clj (rejected hunks) 231.5 -@@ -1,285 +1,282 @@ 231.6 --;;; clojure.contrib.mock.clj: mocking/expectation framework for Clojure 231.7 -- 231.8 --;; by Matt Clark 231.9 -- 231.10 --;; Copyright (c) Matt Clark, 2009. All rights reserved. The use 231.11 --;; and distribution terms for this software are covered by the Eclipse 231.12 --;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php). 231.13 --;; By using this software in any fashion, you are 231.14 --;; agreeing to be bound by the terms of this license. You must not 231.15 --;; remove this notice, or any other, from this software. 231.16 --;;------------------------------------------------------------------------------ 231.17 -- 231.18 --(comment 231.19 -- ;; This is a simple function mocking library I accidentally wrote as a side 231.20 -- ;; effect of trying to write an opengl library in clojure. This is loosely 231.21 -- ;; based on various ruby and java mocking frameworks I have used in the past 231.22 -- ;; such as mockito, easymock, and whatever rspec uses. 231.23 -- ;; 231.24 -- ;; expect uses bindings to wrap the functions that are being tested and 231.25 -- ;; then validates the invocation count at the end. The expect macro is the 231.26 -- ;; main entry point and it is given a vector of binding pairs. 231.27 -- ;; The first of each pair names the dependent function you want to override, 231.28 -- ;; while the second is a hashmap containing the mock description, usually 231.29 -- ;; created via the simple helper methods described below. 231.30 -- ;; 231.31 -- ;; Usage: 231.32 -- ;; 231.33 -- ;; there are one or more dependent functions: 231.34 -- 231.35 -- (defn dep-fn1 [] "time consuming calculation in 3rd party library") 231.36 -- (defn dep-fn2 [x] "function with undesirable side effects while testing") 231.37 -- 231.38 -- ;; then we have the code under test that calls these other functions: 231.39 -- 231.40 -- (defn my-code-under-test [] (dep-fn1) (dep-fn2 "a") (+ 2 2)) 231.41 -- 231.42 -- ;; to test this code, we simply surround it with an expect macro within 231.43 -- ;; the test: 231.44 -- 231.45 -- (expect [dep-fn1 (times 1) 231.46 -- dep-fn2 (times 1 (has-args [#(= "a" %)]))] 231.47 -- (my-code-under-test)) 231.48 -- 231.49 -- ;; When an expectation fails during execution of the function under test, 231.50 -- ;; an error condition function is called with the name of the function 231.51 -- ;; being mocked, the expected form and the actual value. These 231.52 -- ;; error functions can be overridden to allow easy integration into 231.53 -- ;; test frameworks such as test-is by reporting errors in the function 231.54 -- ;; overrides. 231.55 -- 231.56 -- ) ;; end comment 231.57 -- 231.58 --(ns clojure.contrib.mock 231.59 -- ^{:author "Matt Clark", 231.60 -- :doc "function mocking/expectations for Clojure" } 231.61 -- (:use [clojure.contrib.seq :only (positions)] 231.62 -- [clojure.contrib.def :only (defmacro-)])) 231.63 -- 231.64 -- 231.65 --;;------------------------------------------------------------------------------ 231.66 --;; These are the error condition functions. Override them to integrate into 231.67 --;; the test framework of your choice, or to simply customize error handling. 231.68 -- 231.69 --(defn report-problem 231.70 -- {:dynamic true} 231.71 -- ([function expected actual] 231.72 -- (report-problem function expected actual "Expectation not met.")) 231.73 -- ([function expected actual message] 231.74 -- (prn (str message " Function name: " function 231.75 -- " expected: " expected " actual: " actual)))) 231.76 -- 231.77 --(defn no-matching-function-signature 231.78 -- {:dynamic true} 231.79 -- [function expected actual] 231.80 -- (report-problem function expected actual 231.81 -- "No matching real function signature for given argument count.")) 231.82 -- 231.83 --(defn unexpected-args 231.84 -- {:dynamic true} 231.85 -- [function expected actual i] 231.86 -- (report-problem function expected actual 231.87 -- (str "Argument " i " has an unexpected value for function."))) 231.88 -- 231.89 --(defn incorrect-invocation-count 231.90 -- {:dynamic true} 231.91 -- [function expected actual] 231.92 -- (report-problem function expected actual "Unexpected invocation count.")) 231.93 -- 231.94 -- 231.95 --;;------------------------------------------------------------------------------ 231.96 --;; Internal Functions - ignore these 231.97 -- 231.98 -- 231.99 --(defn- has-arg-count-match? 231.100 -- "Given the sequence of accepted argument vectors for a function, 231.101 --returns true if at least one matches the given-count value." 231.102 -- [arg-lists given-count] 231.103 -- (some #(let [[ind] (positions #{'&} %)] 231.104 -- (if ind 231.105 -- (>= given-count ind) 231.106 -- (= (count %) given-count))) 231.107 -- arg-lists)) 231.108 -- 231.109 -- 231.110 --(defn has-matching-signature? 231.111 -- "Calls no-matching-function-signature if no match is found for the given 231.112 --function. If no argslist meta data is available for the function, it is 231.113 --not called." 231.114 -- [fn-name args] 231.115 -- (let [arg-count (count args) 231.116 -- arg-lists (:arglists (meta (resolve fn-name)))] 231.117 -- (if (and arg-lists (not (has-arg-count-match? arg-lists arg-count))) 231.118 -- (no-matching-function-signature fn-name arg-lists args)))) 231.119 -- 231.120 -- 231.121 --(defn make-arg-checker 231.122 -- "Creates the argument verifying function for a replaced dependency within 231.123 --the expectation bound scope. These functions take the additional argument 231.124 --of the name of the replaced function, then the rest of their args. It is 231.125 --designed to be called from the mock function generated in the first argument 231.126 --of the mock info object created by make-mock." 231.127 -- [arg-preds arg-pred-forms] 231.128 -- (let [sanitized-preds (map (fn [v] (if (fn? v) v #(= v %))) arg-preds)] 231.129 -- (fn [fn-name & args] 231.130 -- (every? true? 231.131 -- (map (fn [pred arg pred-form i] (if (pred arg) true 231.132 -- (unexpected-args fn-name pred-form arg i))) 231.133 -- sanitized-preds args arg-pred-forms (iterate inc 0)))))) 231.134 -- 231.135 -- 231.136 --(defn make-count-checker 231.137 -- "creates the count checker that is invoked at the end of an expectation, after 231.138 --the code under test has all been executed. The function returned takes the 231.139 --name of the associated dependency and the invocation count as arguments." 231.140 -- [pred pred-form] 231.141 -- (let [pred-fn (if (integer? pred) #(= pred %) pred)] 231.142 -- (fn [fn-name v] (if (pred-fn v) true 231.143 -- (incorrect-invocation-count fn-name pred-form v))))) 231.144 -- 231.145 --; Borrowed from clojure core. Remove if this ever becomes public there. 231.146 --(defmacro- assert-args 231.147 -- [fnname & pairs] 231.148 -- `(do (when-not ~(first pairs) 231.149 -- (throw (IllegalArgumentException. 231.150 -- ~(str fnname " requires " (second pairs))))) 231.151 -- ~(let [more (nnext pairs)] 231.152 -- (when more 231.153 -- (list* `assert-args fnname more))))) 231.154 -- 231.155 --(defn make-mock 231.156 -- "creates a vector containing the following information for the named function: 231.157 --1. dependent function replacement - verifies signature, calls arg checker, 231.158 --increases count, returns return value. 231.159 --2. an atom containing the invocation count 231.160 --3. the invocation count checker function 231.161 --4. a symbol of the name of the function being replaced." 231.162 -- [fn-name expectation-hash] 231.163 -- (assert-args make-mock 231.164 -- (map? expectation-hash) "a map of expectations") 231.165 -- (let [arg-checker (or (expectation-hash :has-args) (fn [& args] true)) 231.166 -- count-atom (atom 0) 231.167 -- ret-fn (or 231.168 -- (expectation-hash :calls) 231.169 -- (fn [& args] (expectation-hash :returns)))] 231.170 -- [(fn [& args] 231.171 -- (has-matching-signature? fn-name args) 231.172 -- (apply arg-checker fn-name args) 231.173 -- (swap! count-atom inc) 231.174 -- (apply ret-fn args)) 231.175 -- count-atom 231.176 -- (or (expectation-hash :times) (fn [fn-name v] true)) 231.177 -- fn-name])) 231.178 -- 231.179 -- 231.180 --(defn validate-counts 231.181 -- "given the sequence of all mock data for the expectation, simply calls the 231.182 --count checker for each dependency." 231.183 -- [mock-data] (doseq [[mfn i checker fn-name] mock-data] (checker fn-name @i))) 231.184 -- 231.185 --(defn ^{:private true} make-bindings [expect-bindings mock-data-sym] 231.186 -- `[~@(interleave (map #(first %) (partition 2 expect-bindings)) 231.187 -- (map (fn [i] `(nth (nth ~mock-data-sym ~i) 0)) 231.188 -- (range (quot (count expect-bindings) 2))))]) 231.189 -- 231.190 -- 231.191 --;;------------------------------------------------------------------------------ 231.192 --;; These are convenience functions to improve the readability and use of this 231.193 --;; library. Useful in expressions such as: 231.194 --;; (expect [dep-fn1 (times (more-than 1) (returns 15)) etc) 231.195 -- 231.196 --(defn once [x] (= 1 x)) 231.197 -- 231.198 --(defn never [x] (zero? x)) 231.199 -- 231.200 --(defn more-than [x] #(< x %)) 231.201 -- 231.202 --(defn less-than [x] #(> x %)) 231.203 -- 231.204 --(defn between [x y] #(and (< x %) (> y %))) 231.205 -- 231.206 -- 231.207 --;;------------------------------------------------------------------------------ 231.208 --;; The following functions can be used to build up the expectation hash. 231.209 -- 231.210 --(defn returns 231.211 -- "Creates or associates to an existing expectation hash the :returns key with 231.212 --a value to be returned by the expectation after a successful invocation 231.213 --matching its expected arguments (if applicable). 231.214 --Usage: 231.215 --(returns ret-value expectation-hash?)" 231.216 -- 231.217 -- ([val] (returns val {})) 231.218 -- ([val expectation-hash] (assoc expectation-hash :returns val))) 231.219 -- 231.220 -- 231.221 --(defn calls 231.222 -- "Creates or associates to an existing expectation hash the :calls key with a 231.223 --function that will be called with the given arguments. The return value from 231.224 --this function will be returned returned by the expected function. If both this 231.225 --and returns are specified, the return value of \"calls\" will have precedence. 231.226 --Usage: 231.227 --(calls some-fn expectation-hash?)" 231.228 -- 231.229 -- ([val] (calls val {})) 231.230 -- ([val expectation-hash] (assoc expectation-hash :calls val))) 231.231 -- 231.232 -- 231.233 --(defmacro has-args 231.234 -- "Creates or associates to an existing expectation hash the :has-args key with 231.235 --a value corresponding to a function that will either return true if its 231.236 --argument expectations are met or throw an exception with the details of the 231.237 --first failed argument it encounters. 231.238 --Only specify as many predicates as you are interested in verifying. The rest 231.239 --of the values are safely ignored. 231.240 --Usage: 231.241 --(has-args [arg-pred-1 arg-pred-2 ... arg-pred-n] expectation-hash?)" 231.242 -- 231.243 -- ([arg-pred-forms] `(has-args ~arg-pred-forms {})) 231.244 -- ([arg-pred-forms expect-hash-form] 231.245 -- (assert-args has-args 231.246 -- (vector? arg-pred-forms) "a vector of argument predicates") 231.247 -- `(assoc ~expect-hash-form :has-args 231.248 -- (make-arg-checker ~arg-pred-forms '~arg-pred-forms)))) 231.249 -- 231.250 -- 231.251 --(defmacro times 231.252 -- "Creates or associates to an existing expectation hash the :times key with a 231.253 --value corresponding to a predicate function which expects an integer value. 231.254 --This function can either be specified as the first argument to times or can be 231.255 --the result of calling times with an integer argument, in which case the 231.256 --predicate will default to being an exact match. This predicate is called at 231.257 --the end of an expect expression to validate that an expected dependency 231.258 --function was called the expected number of times. 231.259 --Usage: 231.260 --(times n) 231.261 --(times #(> n %)) 231.262 --(times n expectation-hash)" 231.263 -- ([times-fn] `(times ~times-fn {})) 231.264 -- ([times-fn expectation-hash] 231.265 -- `(assoc ~expectation-hash :times (make-count-checker ~times-fn '~times-fn)))) 231.266 -- 231.267 -- 231.268 --;------------------------------------------------------------------------------- 231.269 --; The main expect macro. 231.270 --(defmacro expect 231.271 -- "Use expect to redirect calls to dependent functions that are made within the 231.272 --code under test. Instead of calling the functions that would normally be used, 231.273 --temporary stubs are used, which can verify function parameters and call counts. 231.274 --Return values can also be specified as needed. 231.275 --Usage: 231.276 --(expect [dep-fn (has-args [arg-pred1] (times n (returns x)))] 231.277 -- (function-under-test a b c))" 231.278 -- 231.279 -- [expect-bindings & body] 231.280 -- (assert-args expect 231.281 -- (vector? expect-bindings) "a vector of expectation bindings" 231.282 -- (even? (count expect-bindings)) 231.283 -- "an even number of forms in expectation bindings") 231.284 -- (let [mock-data (gensym "mock-data_")] 231.285 -- `(let [~mock-data (map (fn [args#] 231.286 -- (apply clojure.contrib.mock/make-mock args#)) 231.287 -- ~(cons 'list (map (fn [[n m]] (vector (list 'quote n) m)) 231.288 -- (partition 2 expect-bindings))))] 231.289 -- (binding ~(make-bindings expect-bindings mock-data) ~@body) 231.290 -- (clojure.contrib.mock/validate-counts ~mock-data) true))) 231.291 -+;;; clojure.contrib.mock.clj: mocking/expectation framework for Clojure 231.292 -+ 231.293 -+;; by Matt Clark 231.294 -+ 231.295 -+;; Copyright (c) Matt Clark, 2009. All rights reserved. The use and 231.296 -+;; distribution terms for this software are covered by the Eclipse Public 231.297 -+;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 231.298 -+;; be found in the file epl-v10.html at the root of this distribution. By 231.299 -+;; using this software in any fashion, you are agreeing to be bound by the 231.300 -+;; terms of this license. You must not remove this notice, or any other 231.301 -+;; from this software. 231.302 -+;;------------------------------------------------------------------------------ 231.303 -+ 231.304 -+(comment 231.305 -+ ;; Mock is a function mocking utility loosely based on various ruby and java 231.306 -+ ;; mocking frameworks such as mockito, easymock, and rspec yet adapted to 231.307 -+ ;; fit the functional style of clojure. 231.308 -+ ;; 231.309 -+ ;; Mock uses bindings to wrap the functions that are being tested and 231.310 -+ ;; then validates the invocation count at the end. The expect macro is the 231.311 -+ ;; main entry point and it is given a vector of binding pairs. 231.312 -+ ;; The first of each pair names the dependent function you want to override 231.313 -+ ;; while the second is a hashmap containing the mock description, usually 231.314 -+ ;; created via the simple helper methods described below. 231.315 -+ ;; 231.316 -+ ;; Usage: 231.317 -+ ;; 231.318 -+ ;; there are one or more dependent functions: 231.319 -+ 231.320 -+ (defn dep-fn1 [] "time consuming calculation in 3rd party library") 231.321 -+ (defn dep-fn2 [x] "function with undesirable side effects while testing") 231.322 -+ 231.323 -+ ;; then we have the code under test that calls these other functions: 231.324 -+ 231.325 -+ (defn my-code-under-test [] (dep-fn1) (dep-fn2 "a") (+ 2 2)) 231.326 -+ 231.327 -+ ;; to test this code, we simply surround it with an expect macro within 231.328 -+ ;; the test: 231.329 -+ 231.330 -+ (expect [dep-fn1 (times 1) 231.331 -+ dep-fn2 (times 1 (has-args [#(= "a" %)]))] 231.332 -+ (my-code-under-test)) 231.333 -+ 231.334 -+ ;; When an expectation fails during execution of the function under test 231.335 -+ ;; an error condition function is called with the name of the function 231.336 -+ ;; being mocked, the expected form and the actual value. These 231.337 -+ ;; error functions can be overridden to allow easy integration into 231.338 -+ ;; test frameworks such as test-is by reporting errors in the function 231.339 -+ ;; overrides. 231.340 -+ 231.341 -+ ) ;; end comment 231.342 -+ 231.343 -+(ns clojure.contrib.mock 231.344 -+ ^{:author "Matt Clark" 231.345 -+ :doc "function mocking/expectations for Clojure" } 231.346 -+ (:use [clojure.contrib.seq :only (positions)] 231.347 -+ [clojure.contrib.def :only (defmacro-)])) 231.348 -+ 231.349 -+ 231.350 -+;;------------------------------------------------------------------------------ 231.351 -+;; These are the error condition functions. Override them to integrate into 231.352 -+;; the test framework of your choice, or to simply customize error handling. 231.353 -+ 231.354 -+(defn report-problem 231.355 -+ {:dynamic true} 231.356 -+ ([function expected actual] 231.357 -+ (report-problem function expected actual "Expectation not met.")) 231.358 -+ ([function expected actual message] 231.359 -+ (prn (str message " Function name: " function 231.360 -+ " expected: " expected " actual: " actual)))) 231.361 -+ 231.362 -+(defn no-matching-function-signature 231.363 -+ {:dynamic true} 231.364 -+ [function expected actual] 231.365 -+ (report-problem function expected actual 231.366 -+ "No matching real function signature for given argument count.")) 231.367 -+ 231.368 -+(defn unexpected-args 231.369 -+ {:dynamic true} 231.370 -+ [function expected actual i] 231.371 -+ (report-problem function expected actual 231.372 -+ (str "Argument " i " has an unexpected value for function."))) 231.373 -+ 231.374 -+(defn incorrect-invocation-count 231.375 -+ {:dynamic true} 231.376 -+ [function expected actual] 231.377 -+ (report-problem function expected actual "Unexpected invocation count.")) 231.378 -+ 231.379 -+ 231.380 -+;;------------------------------------------------------------------------------ 231.381 -+;; Internal Functions - ignore these 231.382 -+ 231.383 -+ 231.384 -+(defn- has-arg-count-match? 231.385 -+ "Given the sequence of accepted argument vectors for a function 231.386 -+returns true if at least one matches the given-count value." 231.387 -+ [arg-lists given-count] 231.388 -+ (some #(let [[ind] (positions #{'&} %)] 231.389 -+ (if ind 231.390 -+ (>= given-count ind) 231.391 -+ (= (count %) given-count))) 231.392 -+ arg-lists)) 231.393 -+ 231.394 -+ 231.395 -+(defn has-matching-signature? 231.396 -+ "Calls no-matching-function-signature if no match is found for the given 231.397 -+function. If no argslist meta data is available for the function, it is 231.398 -+not called." 231.399 -+ [fn-name args] 231.400 -+ (let [arg-count (count args) 231.401 -+ arg-lists (:arglists (meta (resolve fn-name)))] 231.402 -+ (if (and arg-lists (not (has-arg-count-match? arg-lists arg-count))) 231.403 -+ (no-matching-function-signature fn-name arg-lists args)))) 231.404 -+ 231.405 -+ 231.406 -+(defn make-arg-checker 231.407 -+ "Creates the argument verifying function for a replaced dependency within 231.408 -+the expectation bound scope. These functions take the additional argument 231.409 -+of the name of the replaced function, then the rest of their args. It is 231.410 -+designed to be called from the mock function generated in the first argument 231.411 -+of the mock info object created by make-mock." 231.412 -+ [arg-preds arg-pred-forms] 231.413 -+ (let [sanitized-preds (map (fn [v] (if (fn? v) v #(= v %))) arg-preds)] 231.414 -+ (fn [fn-name & args] 231.415 -+ (every? true? 231.416 -+ (map (fn [pred arg pred-form i] (if (pred arg) true 231.417 -+ (unexpected-args fn-name 231.418 -+ pred-form arg i))) 231.419 -+ sanitized-preds args arg-pred-forms (iterate inc 0)))))) 231.420 -+ 231.421 -+ 231.422 -+(defn make-count-checker 231.423 -+ "creates the count checker that is invoked at the end of an expectation, after 231.424 -+the code under test has all been executed. The function returned takes the 231.425 -+name of the associated dependency and the invocation count as arguments." 231.426 -+ [pred pred-form] 231.427 -+ (let [pred-fn (if (integer? pred) #(= pred %) pred)] 231.428 -+ (fn [fn-name v] (if (pred-fn v) true 231.429 -+ (incorrect-invocation-count fn-name pred-form v))))) 231.430 -+ 231.431 -+(defn make-mock 231.432 -+ "creates a vector containing the following information for the named function: 231.433 -+1. dependent function replacement - verifies signature, calls arg checker 231.434 -+increases count, returns return value. 231.435 -+2. an atom containing the invocation count 231.436 -+3. the invocation count checker function 231.437 -+4. a symbol of the name of the function being replaced." 231.438 -+ [fn-name expectation-hash] 231.439 -+ {:pre [(map? expectation-hash) 231.440 -+ (symbol? fn-name)]} 231.441 -+ (let [arg-checker (or (expectation-hash :has-args) (fn [& args] true)) 231.442 -+ count-atom (atom 0) 231.443 -+ ret-fn (or 231.444 -+ (expectation-hash :calls) 231.445 -+ (fn [& args] (expectation-hash :returns)))] 231.446 -+ [(fn [& args] 231.447 -+ (has-matching-signature? fn-name args) 231.448 -+ (apply arg-checker fn-name args) 231.449 -+ (swap! count-atom inc) 231.450 -+ (apply ret-fn args)) 231.451 -+ count-atom 231.452 -+ (or (expectation-hash :times) (fn [fn-name v] true)) 231.453 -+ fn-name])) 231.454 -+ 231.455 -+ 231.456 -+(defn validate-counts 231.457 -+ "given the sequence of all mock data for the expectation, simply calls the 231.458 -+count checker for each dependency." 231.459 -+ [mock-data] (doseq [[mfn i checker fn-name] mock-data] (checker fn-name @i))) 231.460 -+ 231.461 -+(defn- make-bindings [expect-bindings mock-data-sym] 231.462 -+ `[~@(interleave (map #(first %) (partition 2 expect-bindings)) 231.463 -+ (map (fn [i] `(nth (nth ~mock-data-sym ~i) 0)) 231.464 -+ (range (quot (count expect-bindings) 2))))]) 231.465 -+ 231.466 -+ 231.467 -+;;------------------------------------------------------------------------------ 231.468 -+;; These are convenience functions to improve the readability and use of this 231.469 -+;; library. Useful in expressions such as: 231.470 -+;; (expect [dep-fn1 (times (more-than 1) (returns 15)) etc) 231.471 -+ 231.472 -+;; best used in the times function 231.473 -+(defn once [x] (= 1 x)) 231.474 -+ 231.475 -+(defn never [x] (zero? x)) 231.476 -+ 231.477 -+(defn more-than [x] #(< x %)) 231.478 -+ 231.479 -+(defn less-than [x] #(> x %)) 231.480 -+ 231.481 -+(defn between [x y] #(and (< x %) (> y %))) 231.482 -+ 231.483 -+;;best used in the has-args function 231.484 -+(defn anything [x] true) 231.485 -+ 231.486 -+ 231.487 -+;;------------------------------------------------------------------------------ 231.488 -+;; The following functions can be used to build up the expectation hash. 231.489 -+ 231.490 -+(defn returns 231.491 -+ "Creates or associates to an existing expectation hash the :returns key with 231.492 -+a value to be returned by the expectation after a successful invocation 231.493 -+matching its expected arguments (if applicable). 231.494 -+Usage: 231.495 -+(returns ret-value expectation-hash?)" 231.496 -+ 231.497 -+ ([val] (returns val {})) 231.498 -+ ([val expectation-hash] 231.499 -+ {:pre [(map? expectation-hash)]} 231.500 -+ (assoc expectation-hash :returns val))) 231.501 -+ 231.502 -+ 231.503 -+(defn calls 231.504 -+ "Creates or associates to an existing expectation hash the :calls key with a 231.505 -+function that will be called with the given arguments. The return value from 231.506 -+this function will be returned by the expected function. If both this 231.507 -+and returns are specified, the return value of \"calls\" will have precedence. 231.508 -+Usage: 231.509 -+(calls some-fn expectation-hash?)" 231.510 -+ 231.511 -+ ([val] (calls val {})) 231.512 -+ ([val expectation-hash] 231.513 -+ {:pre [(map? expectation-hash)]} 231.514 -+ (assoc expectation-hash :calls val))) 231.515 -+ 231.516 -+ 231.517 -+(defmacro has-args 231.518 -+ "Creates or associates to an existing expectation hash the :has-args key with 231.519 -+a value corresponding to a function that will either return true if its 231.520 -+argument expectations are met or throw an exception with the details of the 231.521 -+first failed argument it encounters. 231.522 -+Only specify as many predicates as you are interested in verifying. The rest 231.523 -+of the values are safely ignored. 231.524 -+Usage: 231.525 -+(has-args [arg-pred-1 arg-pred-2 ... arg-pred-n] expectation-hash?)" 231.526 -+ 231.527 -+ ([arg-pred-forms] `(has-args ~arg-pred-forms {})) 231.528 -+ ([arg-pred-forms expectation-hash] 231.529 -+ {:pre [(vector? arg-pred-forms) 231.530 -+ (map? expectation-hash)]} 231.531 -+ `(assoc ~expectation-hash :has-args 231.532 -+ (make-arg-checker ~arg-pred-forms '~arg-pred-forms)))) 231.533 -+ 231.534 -+ 231.535 -+(defmacro times 231.536 -+ "Creates or associates to an existing expectation hash the :times key with a 231.537 -+value corresponding to a predicate function which expects an integer value. 231.538 -+Also, an integer can be specified, in which case the times will only be an 231.539 -+exact match. The times check is called at the end of an expect expression to 231.540 -+validate that an expected dependency function was called the expected 231.541 -+number of times. 231.542 -+Usage: 231.543 -+(times n) 231.544 -+(times #(> n %)) 231.545 -+(times n expectation-hash)" 231.546 -+ ([times-fn] `(times ~times-fn {})) 231.547 -+ ([times-fn expectation-hash] 231.548 -+ {:pre [(map? expectation-hash)]} 231.549 -+ `(assoc ~expectation-hash :times (make-count-checker ~times-fn '~times-fn)))) 231.550 -+ 231.551 -+ 231.552 -+;------------------------------------------------------------------------------- 231.553 -+; The main expect macro. 231.554 -+(defmacro expect 231.555 -+ "Use expect to redirect calls to dependent functions that are made within the 231.556 -+code under test. Instead of calling the functions that would normally be used 231.557 -+temporary stubs are used, which can verify function parameters and call counts. 231.558 -+Return values of overridden functions can also be specified as needed. 231.559 -+Usage: 231.560 -+(expect [dep-fn (has-args [arg-pred1] (times n (returns x)))] 231.561 -+ (function-under-test a b c))" 231.562 -+ 231.563 -+ [expect-bindings & body] 231.564 -+ {:pre [(vector? expect-bindings) 231.565 -+ (even? (count expect-bindings))]} 231.566 -+ (let [mock-data (gensym "mock-data_")] 231.567 -+ `(let [~mock-data (map (fn [args#] 231.568 -+ (apply clojure.contrib.mock/make-mock args#)) 231.569 -+ ~(cons 'list (map (fn [[n m]] (vector (list 'quote n) m)) 231.570 -+ (partition 2 expect-bindings))))] 231.571 -+ (binding ~(make-bindings expect-bindings mock-data) ~@body) 231.572 -+ (clojure.contrib.mock/validate-counts ~mock-data) true)))
232.1 --- a/src/clojure/contrib/mock/test_adapter.clj Sat Aug 21 06:25:44 2010 -0400 232.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 232.3 @@ -1,38 +0,0 @@ 232.4 -;;; test_adapter.clj: clojure.test adapter for mocking/expectation framework for Clojure 232.5 - 232.6 -;; by Matt Clark 232.7 - 232.8 -;; Copyright (c) Matt Clark, 2009. All rights reserved. The use 232.9 -;; and distribution terms for this software are covered by the Eclipse 232.10 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php). 232.11 -;; By using this software in any fashion, you are 232.12 -;; agreeing to be bound by the terms of this license. You must not 232.13 -;; remove this notice, or any other, from this software. 232.14 - 232.15 -(ns clojure.contrib.mock.test-adapter 232.16 - (:require [clojure.contrib.mock :as mock]) 232.17 - (:use clojure.test 232.18 - clojure.contrib.ns-utils)) 232.19 - 232.20 -(immigrate 'clojure.contrib.mock) 232.21 - 232.22 -(defn report-problem 232.23 - "This function is designed to be used in a binding macro to override 232.24 -the report-problem function in clojure.contrib.mock. Instead of printing 232.25 -the error to the console, the error is logged via clojure.test." 232.26 - {:dynamic true} 232.27 - [fn-name expected actual msg] 232.28 - (report {:type :fail, 232.29 - :message (str msg " Function name: " fn-name), 232.30 - :expected expected, 232.31 - :actual actual})) 232.32 - 232.33 - 232.34 -(defmacro expect [& body] 232.35 - "Use this macro instead of the standard c.c.mock expect macro to have 232.36 -failures reported through clojure.test." 232.37 - `(binding [mock/report-problem report-problem] 232.38 - (mock/expect ~@body))) 232.39 - 232.40 - 232.41 -
233.1 --- a/src/clojure/contrib/monadic_io_streams.clj Sat Aug 21 06:25:44 2010 -0400 233.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 233.3 @@ -1,145 +0,0 @@ 233.4 -;; Monadic I/O 233.5 - 233.6 -;; by Konrad Hinsen 233.7 -;; last updated June 24, 2009 233.8 - 233.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 233.10 -;; and distribution terms for this software are covered by the Eclipse 233.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 233.12 -;; which can be found in the file epl-v10.html at the root of this 233.13 -;; distribution. By using this software in any fashion, you are 233.14 -;; agreeing to be bound by the terms of this license. You must not 233.15 -;; remove this notice, or any other, from this software. 233.16 - 233.17 -(ns 233.18 - ^{:author "Konrad Hinsen" 233.19 - :doc "Monadic I/O with Java input/output streams 233.20 - Defines monadic I/O statements to be used in a state monad 233.21 - with an input or output stream as the state. The macro 233.22 - monadic-io creates a stream, runs a monadic I/O statement 233.23 - on it, and closes the stream. This structure permits the 233.24 - definition of purely functional compound I/O statements 233.25 - which are applied to streams that can never escape from the 233.26 - monadic statement sequence."} 233.27 - clojure.contrib.monadic-io-streams 233.28 - (:refer-clojure :exclude (read-line print println flush)) 233.29 - (:use [clojure.contrib.monads 233.30 - :only (with-monad domonad state-m state-m-until)]) 233.31 - (:use [clojure.contrib.generic.functor :only (fmap)]) 233.32 - (:use [clojure.java.io :only (reader writer)])) 233.33 - 233.34 -; 233.35 -; Wrap the state into a closure to make sure that "evil" code 233.36 -; can't obtain the stream using fetch-state and manipulate it. 233.37 -; 233.38 -(let [key (Object.) 233.39 - lock (fn [state] (fn [x] (if (identical? x key) state nil))) 233.40 - unlock (fn [state] (state key))] 233.41 - 233.42 - ; 233.43 - ; Basic stream I/O statements as provided by Java 233.44 - ; 233.45 - (defn read-char 233.46 - "Read a single character" 233.47 - [] 233.48 - (fn [s] [(.read (unlock s)) s])) 233.49 - 233.50 - (defn read-line 233.51 - "Read a single line" 233.52 - [] 233.53 - (fn [s] [(.readLine (unlock s)) s])) 233.54 - 233.55 - (defn skip-chars 233.56 - "Skip n characters" 233.57 - [n] 233.58 - (fn [s] [(.skip (unlock s) n) s])) 233.59 - 233.60 - (defn write 233.61 - "Write text (a string)" 233.62 - [^String text] 233.63 - (fn [s] [(.write (unlock s) text) s])) 233.64 - 233.65 - (defn flush 233.66 - "Flush" 233.67 - [] 233.68 - (fn [s] [(.flush (unlock s)) s])) 233.69 - 233.70 - (defn print 233.71 - "Print obj" 233.72 - [obj] 233.73 - (fn [s] [(.print (unlock s) obj) s])) 233.74 - 233.75 - (defn println 233.76 - "Print obj followed by a newline" 233.77 - ([] 233.78 - (fn [s] [(.println (unlock s)) s])) 233.79 - ([obj] 233.80 - (fn [s] [(.println (unlock s) obj) s]))) 233.81 - 233.82 - ; 233.83 - ; Inject I/O streams into monadic I/O statements 233.84 - ; 233.85 - (defn with-reader 233.86 - "Create a reader from reader-spec, run the monadic I/O statement 233.87 - on it, and close the reader. reader-spec can be any object accepted 233.88 - by clojure.contrib.io/reader." 233.89 - [reader-spec statement] 233.90 - (with-open [r (reader reader-spec)] 233.91 - (first (statement (lock r))))) 233.92 - 233.93 - (defn with-writer 233.94 - "Create a writer from writer-spec, run the monadic I/O statement 233.95 - on it, and close the writer. writer-spec can be any object accepted 233.96 - by clojure.contrib.io/writer." 233.97 - [writer-spec statement] 233.98 - (with-open [w (writer writer-spec)] 233.99 - (first (statement (lock w))))) 233.100 - 233.101 - (defn with-io-streams 233.102 - "Open one or more streams as specified by io-spec, run a monadic 233.103 - I/O statement on them, and close the streams. io-spec is 233.104 - a binding-like vector in which each stream is specified by 233.105 - three element: a keyword by which the stream can be referred to, 233.106 - the stream mode (:read or :write), and a stream specification as 233.107 - accepted by clojure.contrib.io/reader (mode :read) or 233.108 - clojure.contrib.io/writer (mode :write). The statement 233.109 - is run on a state which is a map from keywords to corresponding 233.110 - streams. Single-stream monadic I/O statements must be wrapped 233.111 - with clojure.contrib.monads/with-state-field." 233.112 - [io-specs statement] 233.113 - (letfn [(run-io [io-specs state statement] 233.114 - (if (zero? (count io-specs)) 233.115 - (first (statement state)) 233.116 - (let [[[key mode stream-spec] & r] io-specs 233.117 - opener (cond (= mode :read) reader 233.118 - (= mode :write) writer 233.119 - :else (throw 233.120 - (Exception. 233.121 - "Mode must be :read or :write")))] 233.122 - (with-open [stream (opener stream-spec)] 233.123 - (run-io r (assoc state key (lock stream)) statement)))))] 233.124 - (run-io (partition 3 io-specs) {} statement)))) 233.125 - 233.126 -; 233.127 -; Compound I/O statements 233.128 -; 233.129 -(with-monad state-m 233.130 - 233.131 - (defn- add-line 233.132 - "Read one line and add it to the end of the vector lines. Return 233.133 - [lines eof], where eof is an end-of-file flag. The input eof argument 233.134 - is not used." 233.135 - [[lines eof]] 233.136 - (domonad 233.137 - [line (read-line)] 233.138 - (if (nil? line) 233.139 - [lines true] 233.140 - [(conj lines line) false]))) 233.141 - 233.142 - (defn read-lines 233.143 - "Read all lines and return them in a vector" 233.144 - [] 233.145 - (domonad 233.146 - [[lines eof] (state-m-until second add-line [[] false])] 233.147 - lines))) 233.148 -
234.1 --- a/src/clojure/contrib/monads.clj Sat Aug 21 06:25:44 2010 -0400 234.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 234.3 @@ -1,580 +0,0 @@ 234.4 -;; Monads in Clojure 234.5 - 234.6 -;; by Konrad Hinsen 234.7 -;; last updated June 30, 2009 234.8 - 234.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 234.10 -;; and distribution terms for this software are covered by the Eclipse 234.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 234.12 -;; which can be found in the file epl-v10.html at the root of this 234.13 -;; distribution. By using this software in any fashion, you are 234.14 -;; agreeing to be bound by the terms of this license. You must not 234.15 -;; remove this notice, or any other, from this software. 234.16 - 234.17 -(ns 234.18 - ^{:author "Konrad Hinsen" 234.19 - :see-also [["http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/" "Monad tutorial part 1"] 234.20 - ["http://onclojure.com/2009/03/06/a-monad-tutorial-for-clojure-programmers-part-2/" "Monad tutorial part 2"] 234.21 - ["http://onclojure.com/2009/03/23/a-monad-tutorial-for-clojure-programmers-part-3/" "Monad tutorial part 3"] 234.22 - ["http://onclojure.com/2009/04/24/a-monad-tutorial-for-clojure-programmers-part-4/" "Monad tutorial part 4"] 234.23 - ["http://intensivesystems.net/tutorials/monads_101.html" "Monads in Clojure part 1"] 234.24 - ["http://intensivesystems.net/tutorials/monads_201.html" "Monads in Clojure part 2"]] 234.25 - :doc "This library contains the most commonly used monads as well 234.26 - as macros for defining and using monads and useful monadic 234.27 - functions."} 234.28 - clojure.contrib.monads 234.29 - (:require [clojure.contrib.accumulators]) 234.30 - (:use [clojure.contrib.macro-utils :only (with-symbol-macros defsymbolmacro)]) 234.31 - (:use [clojure.contrib.def :only (name-with-attributes)])) 234.32 - 234.33 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.34 -;; 234.35 -;; Defining monads 234.36 -;; 234.37 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.38 - 234.39 -(defmacro monad 234.40 - "Define a monad by defining the monad operations. The definitions 234.41 - are written like bindings to the monad operations m-bind and 234.42 - m-result (required) and m-zero and m-plus (optional)." 234.43 - [operations] 234.44 - `(let [~'m-bind ::undefined 234.45 - ~'m-result ::undefined 234.46 - ~'m-zero ::undefined 234.47 - ~'m-plus ::undefined 234.48 - ~@operations] 234.49 - {:m-result ~'m-result 234.50 - :m-bind ~'m-bind 234.51 - :m-zero ~'m-zero 234.52 - :m-plus ~'m-plus})) 234.53 - 234.54 -(defmacro defmonad 234.55 - "Define a named monad by defining the monad operations. The definitions 234.56 - are written like bindings to the monad operations m-bind and 234.57 - m-result (required) and m-zero and m-plus (optional)." 234.58 - 234.59 - ([name doc-string operations] 234.60 - (let [doc-name (with-meta name {:doc doc-string})] 234.61 - `(defmonad ~doc-name ~operations))) 234.62 - 234.63 - ([name operations] 234.64 - `(def ~name (monad ~operations)))) 234.65 - 234.66 - 234.67 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.68 -;; 234.69 -;; Using monads 234.70 -;; 234.71 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.72 - 234.73 -(defn- add-monad-step 234.74 - "Add a monad comprehension step before the already transformed 234.75 - monad comprehension expression mexpr." 234.76 - [mexpr step] 234.77 - (let [[bform expr] step] 234.78 - (cond (identical? bform :when) `(if ~expr ~mexpr ~'m-zero) 234.79 - (identical? bform :let) `(let ~expr ~mexpr) 234.80 - :else (list 'm-bind expr (list 'fn [bform] mexpr))))) 234.81 - 234.82 -(defn- monad-expr 234.83 - "Transforms a monad comprehension, consisting of a list of steps 234.84 - and an expression defining the final value, into an expression 234.85 - chaining together the steps using :bind and returning the final value 234.86 - using :result. The steps are given as a vector of 234.87 - binding-variable/monadic-expression pairs." 234.88 - [steps expr] 234.89 - (when (odd? (count steps)) 234.90 - (throw (Exception. "Odd number of elements in monad comprehension steps"))) 234.91 - (let [rsteps (reverse (partition 2 steps)) 234.92 - [lr ls] (first rsteps)] 234.93 - (if (= lr expr) 234.94 - ; Optimization: if the result expression is equal to the result 234.95 - ; of the last computation step, we can eliminate an m-bind to 234.96 - ; m-result. 234.97 - (reduce add-monad-step 234.98 - ls 234.99 - (rest rsteps)) 234.100 - ; The general case. 234.101 - (reduce add-monad-step 234.102 - (list 'm-result expr) 234.103 - rsteps)))) 234.104 - 234.105 -(defmacro with-monad 234.106 - "Evaluates an expression after replacing the keywords defining the 234.107 - monad operations by the functions associated with these keywords 234.108 - in the monad definition given by name." 234.109 - [monad & exprs] 234.110 - `(let [name# ~monad 234.111 - ~'m-bind (:m-bind name#) 234.112 - ~'m-result (:m-result name#) 234.113 - ~'m-zero (:m-zero name#) 234.114 - ~'m-plus (:m-plus name#)] 234.115 - (with-symbol-macros ~@exprs))) 234.116 - 234.117 -(defmacro domonad 234.118 - "Monad comprehension. Takes the name of a monad, a vector of steps 234.119 - given as binding-form/monadic-expression pairs, and a result value 234.120 - specified by expr. The monadic-expression terms can use the binding 234.121 - variables of the previous steps. 234.122 - If the monad contains a definition of m-zero, the step list can also 234.123 - contain conditions of the form :when p, where the predicate p can 234.124 - contain the binding variables from all previous steps. 234.125 - A clause of the form :let [binding-form expr ...], where the bindings 234.126 - are given as a vector as for the use in let, establishes additional 234.127 - bindings that can be used in the following steps." 234.128 - ([steps expr] 234.129 - (monad-expr steps expr)) 234.130 - ([name steps expr] 234.131 - (let [mexpr (monad-expr steps expr)] 234.132 - `(with-monad ~name ~mexpr)))) 234.133 - 234.134 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.135 -;; 234.136 -;; Defining functions used with monads 234.137 -;; 234.138 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.139 - 234.140 -(defmacro defmonadfn 234.141 - "Like defn, but for functions that use monad operations and are used inside 234.142 - a with-monad block." 234.143 - {:arglists '([name docstring? attr-map? args expr] 234.144 - [name docstring? attr-map? (args expr) ...])} 234.145 - [name & options] 234.146 - (let [[name options] (name-with-attributes name options) 234.147 - fn-name (symbol (str *ns*) (format "m+%s+m" (str name))) 234.148 - make-fn-body (fn [args expr] 234.149 - (list (vec (concat ['m-bind 'm-result 234.150 - 'm-zero 'm-plus] args)) 234.151 - (list `with-symbol-macros expr)))] 234.152 - (if (list? (first options)) 234.153 - ; multiple arities 234.154 - (let [arglists (map first options) 234.155 - exprs (map second options) 234.156 - ] 234.157 - `(do 234.158 - (defsymbolmacro ~name (partial ~fn-name ~'m-bind ~'m-result 234.159 - ~'m-zero ~'m-plus)) 234.160 - (defn ~fn-name ~@(map make-fn-body arglists exprs)))) 234.161 - ; single arity 234.162 - (let [[args expr] options] 234.163 - `(do 234.164 - (defsymbolmacro ~name (partial ~fn-name ~'m-bind ~'m-result 234.165 - ~'m-zero ~'m-plus)) 234.166 - (defn ~fn-name ~@(make-fn-body args expr))))))) 234.167 - 234.168 - 234.169 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.170 -;; 234.171 -;; Commonly used monad functions 234.172 -;; 234.173 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.174 - 234.175 -; Define the four basic monad operations as symbol macros that 234.176 -; expand to their unqualified symbol equivalents. This makes it possible 234.177 -; to use them inside macro templates without having to quote them. 234.178 -(defsymbolmacro m-result m-result) 234.179 -(defsymbolmacro m-bind m-bind) 234.180 -(defsymbolmacro m-zero m-zero) 234.181 -(defsymbolmacro m-plus m-plus) 234.182 - 234.183 -(defmacro m-lift 234.184 - "Converts a function f of n arguments into a function of n 234.185 - monadic arguments returning a monadic value." 234.186 - [n f] 234.187 - (let [expr (take n (repeatedly #(gensym "x_"))) 234.188 - vars (vec (take n (repeatedly #(gensym "mv_")))) 234.189 - steps (vec (interleave expr vars))] 234.190 - (list `fn vars (monad-expr steps (cons f expr))))) 234.191 - 234.192 -(defmonadfn m-join 234.193 - "Converts a monadic value containing a monadic value into a 'simple' 234.194 - monadic value." 234.195 - [m] 234.196 - (m-bind m identity)) 234.197 - 234.198 -(defmonadfn m-fmap 234.199 - "Bind the monadic value m to the function returning (f x) for argument x" 234.200 - [f m] 234.201 - (m-bind m (fn [x] (m-result (f x))))) 234.202 - 234.203 -(defmonadfn m-seq 234.204 - "'Executes' the monadic values in ms and returns a sequence of the 234.205 - basic values contained in them." 234.206 - [ms] 234.207 - (reduce (fn [q p] 234.208 - (m-bind p (fn [x] 234.209 - (m-bind q (fn [y] 234.210 - (m-result (cons x y)))) ))) 234.211 - (m-result '()) 234.212 - (reverse ms))) 234.213 - 234.214 -(defmonadfn m-map 234.215 - "'Executes' the sequence of monadic values resulting from mapping 234.216 - f onto the values xs. f must return a monadic value." 234.217 - [f xs] 234.218 - (m-seq (map f xs))) 234.219 - 234.220 -(defmonadfn m-chain 234.221 - "Chains together monadic computation steps that are each functions 234.222 - of one parameter. Each step is called with the result of the previous 234.223 - step as its argument. (m-chain (step1 step2)) is equivalent to 234.224 - (fn [x] (domonad [r1 (step1 x) r2 (step2 r1)] r2))." 234.225 - [steps] 234.226 - (reduce (fn m-chain-link [chain-expr step] 234.227 - (fn [v] (m-bind (chain-expr v) step))) 234.228 - m-result 234.229 - steps)) 234.230 - 234.231 -(defmonadfn m-reduce 234.232 - "Return the reduction of (m-lift 2 f) over the list of monadic values mvs 234.233 - with initial value (m-result val)." 234.234 - ([f mvs] 234.235 - (if (empty? mvs) 234.236 - (m-result (f)) 234.237 - (let [m-f (m-lift 2 f)] 234.238 - (reduce m-f mvs)))) 234.239 - ([f val mvs] 234.240 - (let [m-f (m-lift 2 f) 234.241 - m-val (m-result val)] 234.242 - (reduce m-f m-val mvs)))) 234.243 - 234.244 -(defmonadfn m-until 234.245 - "While (p x) is false, replace x by the value returned by the 234.246 - monadic computation (f x). Return (m-result x) for the first 234.247 - x for which (p x) is true." 234.248 - [p f x] 234.249 - (if (p x) 234.250 - (m-result x) 234.251 - (domonad 234.252 - [y (f x) 234.253 - z (m-until p f y)] 234.254 - z))) 234.255 - 234.256 -(defmacro m-when 234.257 - "If test is logical true, return monadic value m-expr, else return 234.258 - (m-result nil)." 234.259 - [test m-expr] 234.260 - `(if ~test ~m-expr (~'m-result nil))) 234.261 - 234.262 -(defmacro m-when-not 234.263 - "If test if logical false, return monadic value m-expr, else return 234.264 - (m-result nil)." 234.265 - [test m-expr] 234.266 - `(if ~test (~'m-result nil) ~m-expr)) 234.267 - 234.268 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.269 -;; 234.270 -;; Utility functions used in monad definitions 234.271 -;; 234.272 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.273 - 234.274 -(defn- flatten* 234.275 - "Like #(apply concat %), but fully lazy: it evaluates each sublist 234.276 - only when it is needed." 234.277 - [ss] 234.278 - (lazy-seq 234.279 - (when-let [s (seq ss)] 234.280 - (concat (first s) (flatten* (rest s)))))) 234.281 - 234.282 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.283 -;; 234.284 -;; Commonly used monads 234.285 -;; 234.286 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.287 - 234.288 -; Identity monad 234.289 -(defmonad identity-m 234.290 - "Monad describing plain computations. This monad does in fact nothing 234.291 - at all. It is useful for testing, for combination with monad 234.292 - transformers, and for code that is parameterized with a monad." 234.293 - [m-result identity 234.294 - m-bind (fn m-result-id [mv f] 234.295 - (f mv)) 234.296 - ]) 234.297 - 234.298 -; Maybe monad 234.299 -(defmonad maybe-m 234.300 - "Monad describing computations with possible failures. Failure is 234.301 - represented by nil, any other value is considered valid. As soon as 234.302 - a step returns nil, the whole computation will yield nil as well." 234.303 - [m-zero nil 234.304 - m-result (fn m-result-maybe [v] v) 234.305 - m-bind (fn m-bind-maybe [mv f] 234.306 - (if (nil? mv) nil (f mv))) 234.307 - m-plus (fn m-plus-maybe [& mvs] 234.308 - (first (drop-while nil? mvs))) 234.309 - ]) 234.310 - 234.311 -; Sequence monad (called "list monad" in Haskell) 234.312 -(defmonad sequence-m 234.313 - "Monad describing multi-valued computations, i.e. computations 234.314 - that can yield multiple values. Any object implementing the seq 234.315 - protocol can be used as a monadic value." 234.316 - [m-result (fn m-result-sequence [v] 234.317 - (list v)) 234.318 - m-bind (fn m-bind-sequence [mv f] 234.319 - (flatten* (map f mv))) 234.320 - m-zero (list) 234.321 - m-plus (fn m-plus-sequence [& mvs] 234.322 - (flatten* mvs)) 234.323 - ]) 234.324 - 234.325 -; Set monad 234.326 -(defmonad set-m 234.327 - "Monad describing multi-valued computations, like sequence-m, 234.328 - but returning sets of results instead of sequences of results." 234.329 - [m-result (fn m-result-set [v] 234.330 - #{v}) 234.331 - m-bind (fn m-bind-set [mv f] 234.332 - (apply clojure.set/union (map f mv))) 234.333 - m-zero #{} 234.334 - m-plus (fn m-plus-set [& mvs] 234.335 - (apply clojure.set/union mvs)) 234.336 - ]) 234.337 - 234.338 -; State monad 234.339 -(defmonad state-m 234.340 - "Monad describing stateful computations. The monadic values have the 234.341 - structure (fn [old-state] [result new-state])." 234.342 - [m-result (fn m-result-state [v] 234.343 - (fn [s] [v s])) 234.344 - m-bind (fn m-bind-state [mv f] 234.345 - (fn [s] 234.346 - (let [[v ss] (mv s)] 234.347 - ((f v) ss)))) 234.348 - ]) 234.349 - 234.350 -(defn update-state 234.351 - "Return a state-monad function that replaces the current state by the 234.352 - result of f applied to the current state and that returns the old state." 234.353 - [f] 234.354 - (fn [s] [s (f s)])) 234.355 - 234.356 -(defn set-state 234.357 - "Return a state-monad function that replaces the current state by s and 234.358 - returns the previous state." 234.359 - [s] 234.360 - (update-state (fn [_] s))) 234.361 - 234.362 -(defn fetch-state 234.363 - "Return a state-monad function that returns the current state and does not 234.364 - modify it." 234.365 - [] 234.366 - (update-state identity)) 234.367 - 234.368 -(defn fetch-val 234.369 - "Return a state-monad function that assumes the state to be a map and 234.370 - returns the value corresponding to the given key. The state is not modified." 234.371 - [key] 234.372 - (domonad state-m 234.373 - [s (fetch-state)] 234.374 - (key s))) 234.375 - 234.376 -(defn update-val 234.377 - "Return a state-monad function that assumes the state to be a map and 234.378 - replaces the value associated with the given key by the return value 234.379 - of f applied to the old value. The old value is returned." 234.380 - [key f] 234.381 - (fn [s] 234.382 - (let [old-val (get s key) 234.383 - new-s (assoc s key (f old-val))] 234.384 - [old-val new-s]))) 234.385 - 234.386 -(defn set-val 234.387 - "Return a state-monad function that assumes the state to be a map and 234.388 - replaces the value associated with key by val. The old value is returned." 234.389 - [key val] 234.390 - (update-val key (fn [_] val))) 234.391 - 234.392 -(defn with-state-field 234.393 - "Returns a state-monad function that expects a map as its state and 234.394 - runs statement (another state-monad function) on the state defined by 234.395 - the map entry corresponding to key. The map entry is updated with the 234.396 - new state returned by statement." 234.397 - [key statement] 234.398 - (fn [s] 234.399 - (let [substate (get s key nil) 234.400 - [result new-substate] (statement substate) 234.401 - new-state (assoc s key new-substate)] 234.402 - [result new-state]))) 234.403 - 234.404 -(defn state-m-until 234.405 - "An optimized implementation of m-until for the state monad that 234.406 - replaces recursion by a loop." 234.407 - [p f x] 234.408 - (letfn [(until [p f x s] 234.409 - (if (p x) 234.410 - [x s] 234.411 - (let [[x s] ((f x) s)] 234.412 - (recur p f x s))))] 234.413 - (fn [s] (until p f x s)))) 234.414 - 234.415 -; Writer monad 234.416 -(defn writer-m 234.417 - "Monad describing computations that accumulate data on the side, e.g. for 234.418 - logging. The monadic values have the structure [value log]. Any of the 234.419 - accumulators from clojure.contrib.accumulators can be used for storing the 234.420 - log data. Its empty value is passed as a parameter." 234.421 - [empty-accumulator] 234.422 - (monad 234.423 - [m-result (fn m-result-writer [v] 234.424 - [v empty-accumulator]) 234.425 - m-bind (fn m-bind-writer [mv f] 234.426 - (let [[v1 a1] mv 234.427 - [v2 a2] (f v1)] 234.428 - [v2 (clojure.contrib.accumulators/combine a1 a2)])) 234.429 - ])) 234.430 - 234.431 -(defmonadfn write [v] 234.432 - (let [[_ a] (m-result nil)] 234.433 - [nil (clojure.contrib.accumulators/add a v)])) 234.434 - 234.435 -(defn listen [mv] 234.436 - (let [[v a] mv] [[v a] a])) 234.437 - 234.438 -(defn censor [f mv] 234.439 - (let [[v a] mv] [v (f a)])) 234.440 - 234.441 -; Continuation monad 234.442 - 234.443 -(defmonad cont-m 234.444 - "Monad describing computations in continuation-passing style. The monadic 234.445 - values are functions that are called with a single argument representing 234.446 - the continuation of the computation, to which they pass their result." 234.447 - [m-result (fn m-result-cont [v] 234.448 - (fn [c] (c v))) 234.449 - m-bind (fn m-bind-cont [mv f] 234.450 - (fn [c] 234.451 - (mv (fn [v] ((f v) c))))) 234.452 - ]) 234.453 - 234.454 -(defn run-cont 234.455 - "Execute the computation c in the cont monad and return its result." 234.456 - [c] 234.457 - (c identity)) 234.458 - 234.459 -(defn call-cc 234.460 - "A computation in the cont monad that calls function f with a single 234.461 - argument representing the current continuation. The function f should 234.462 - return a continuation (which becomes the return value of call-cc), 234.463 - or call the passed-in current continuation to terminate." 234.464 - [f] 234.465 - (fn [c] 234.466 - (let [cc (fn cc [a] (fn [_] (c a))) 234.467 - rc (f cc)] 234.468 - (rc c)))) 234.469 - 234.470 - 234.471 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.472 -;; 234.473 -;; Monad transformers 234.474 -;; 234.475 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 234.476 - 234.477 -(defmacro monad-transformer 234.478 - "Define a monad transforer in terms of the monad operations and the base 234.479 - monad. The argument which-m-plus chooses if m-zero and m-plus are taken 234.480 - from the base monad or from the transformer." 234.481 - [base which-m-plus operations] 234.482 - `(let [which-m-plus# (cond (= ~which-m-plus :m-plus-default) 234.483 - (if (= ::undefined (with-monad ~base ~'m-plus)) 234.484 - :m-plus-from-transformer 234.485 - :m-plus-from-base) 234.486 - (or (= ~which-m-plus :m-plus-from-base) 234.487 - (= ~which-m-plus :m-plus-from-transformer)) 234.488 - ~which-m-plus 234.489 - :else 234.490 - (throw (java.lang.IllegalArgumentException. 234.491 - "undefined m-plus choice"))) 234.492 - combined-monad# (monad ~operations)] 234.493 - (if (= which-m-plus# :m-plus-from-base) 234.494 - (assoc combined-monad# 234.495 - :m-zero (with-monad ~base ~'m-zero) 234.496 - :m-plus (with-monad ~base ~'m-plus)) 234.497 - combined-monad#))) 234.498 - 234.499 -(defn maybe-t 234.500 - "Monad transformer that transforms a monad m into a monad in which 234.501 - the base values can be invalid (represented by nothing, which defaults 234.502 - to nil). The third argument chooses if m-zero and m-plus are inherited 234.503 - from the base monad (use :m-plus-from-base) or adopt maybe-like 234.504 - behaviour (use :m-plus-from-transformer). The default is :m-plus-from-base 234.505 - if the base monad m has a definition for m-plus, and 234.506 - :m-plus-from-transformer otherwise." 234.507 - ([m] (maybe-t m nil :m-plus-default)) 234.508 - ([m nothing] (maybe-t m nothing :m-plus-default)) 234.509 - ([m nothing which-m-plus] 234.510 - (monad-transformer m which-m-plus 234.511 - [m-result (with-monad m m-result) 234.512 - m-bind (with-monad m 234.513 - (fn m-bind-maybe-t [mv f] 234.514 - (m-bind mv 234.515 - (fn [x] 234.516 - (if (identical? x nothing) 234.517 - (m-result nothing) 234.518 - (f x)))))) 234.519 - m-zero (with-monad m (m-result nothing)) 234.520 - m-plus (with-monad m 234.521 - (fn m-plus-maybe-t [& mvs] 234.522 - (if (empty? mvs) 234.523 - (m-result nothing) 234.524 - (m-bind (first mvs) 234.525 - (fn [v] 234.526 - (if (= v nothing) 234.527 - (apply m-plus-maybe-t (rest mvs)) 234.528 - (m-result v))))))) 234.529 - ]))) 234.530 - 234.531 -(defn sequence-t 234.532 - "Monad transformer that transforms a monad m into a monad in which 234.533 - the base values are sequences. The argument which-m-plus chooses 234.534 - if m-zero and m-plus are inherited from the base monad 234.535 - (use :m-plus-from-base) or adopt sequence-like 234.536 - behaviour (use :m-plus-from-transformer). The default is :m-plus-from-base 234.537 - if the base monad m has a definition for m-plus, and 234.538 - :m-plus-from-transformer otherwise." 234.539 - ([m] (sequence-t m :m-plus-default)) 234.540 - ([m which-m-plus] 234.541 - (monad-transformer m which-m-plus 234.542 - [m-result (with-monad m 234.543 - (fn m-result-sequence-t [v] 234.544 - (m-result (list v)))) 234.545 - m-bind (with-monad m 234.546 - (fn m-bind-sequence-t [mv f] 234.547 - (m-bind mv 234.548 - (fn [xs] 234.549 - (m-fmap flatten* 234.550 - (m-map f xs)))))) 234.551 - m-zero (with-monad m (m-result (list))) 234.552 - m-plus (with-monad m 234.553 - (fn m-plus-sequence-t [& mvs] 234.554 - (m-reduce concat (list) mvs))) 234.555 - ]))) 234.556 - 234.557 -;; Contributed by Jim Duey 234.558 -(defn state-t 234.559 - "Monad transformer that transforms a monad m into a monad of stateful 234.560 - computations that have the base monad type as their result." 234.561 - [m] 234.562 - (monad [m-result (with-monad m 234.563 - (fn m-result-state-t [v] 234.564 - (fn [s] 234.565 - (m-result [v s])))) 234.566 - m-bind (with-monad m 234.567 - (fn m-bind-state-t [stm f] 234.568 - (fn [s] 234.569 - (m-bind (stm s) 234.570 - (fn [[v ss]] 234.571 - ((f v) ss)))))) 234.572 - m-zero (with-monad m 234.573 - (if (= ::undefined m-zero) 234.574 - ::undefined 234.575 - (fn [s] 234.576 - m-zero))) 234.577 - m-plus (with-monad m 234.578 - (if (= ::undefined m-plus) 234.579 - ::undefined 234.580 - (fn [& stms] 234.581 - (fn [s] 234.582 - (apply m-plus (map #(% s) stms)))))) 234.583 - ]))
235.1 --- a/src/clojure/contrib/ns_utils.clj Sat Aug 21 06:25:44 2010 -0400 235.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 235.3 @@ -1,100 +0,0 @@ 235.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 235.5 -;; distribution terms for this software are covered by the Eclipse Public 235.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 235.7 -;; be found in the file epl-v10.html at the root of this distribution. By 235.8 -;; using this software in any fashion, you are agreeing to be bound by the 235.9 -;; terms of this license. You must not remove this notice, or any other, 235.10 -;; from this software. 235.11 - 235.12 -;; scgilardi (gmail) 235.13 -;; 23 April 2008 235.14 - 235.15 -;; DEPRECATED in 1.2: dir and print-dir. Use dir and dir-fn in 235.16 -;; clojure.repl. 235.17 - 235.18 -(ns 235.19 - ^{:author "Stephen C. Gilardi", 235.20 - :doc "Namespace utilities 235.21 - 235.22 - get-ns returns the namespace named by a symbol or throws 235.23 - if the namespace does not exist 235.24 - 235.25 - ns-vars returns a sorted seq of symbols naming public vars 235.26 - in a namespace 235.27 - 235.28 - print-docs prints documentation for the public vars in a 235.29 - namespace 235.30 - 235.31 - immigrate Create a public var in this namespace for each 235.32 - public var in the namespaces named by ns-names. 235.33 - From James Reeves 235.34 - 235.35 - vars returns a sorted seq of symbols naming public vars 235.36 - in a namespace (macro) 235.37 - 235.38 - docs prints documentation for the public vars in a 235.39 - namespace (macro)"} 235.40 - clojure.contrib.ns-utils 235.41 - (:use clojure.contrib.except)) 235.42 - 235.43 -;; Namespace Utilities 235.44 - 235.45 -(defn get-ns 235.46 - "Returns the namespace named by ns-sym or throws if the 235.47 - namespace does not exist" 235.48 - [ns-sym] 235.49 - (let [ns (find-ns ns-sym)] 235.50 - (throw-if (not ns) "Unable to find namespace: %s" ns-sym) 235.51 - ns)) 235.52 - 235.53 -(defn ns-vars 235.54 - "Returns a sorted seq of symbols naming public vars in 235.55 - a namespace" 235.56 - [ns] 235.57 - (sort (map first (ns-publics ns)))) 235.58 - 235.59 -(defn print-dir 235.60 - "Prints a sorted directory of public vars in a namespace" 235.61 - {:deprecated "1.2"} 235.62 - [ns] 235.63 - (doseq [item (ns-vars ns)] 235.64 - (println item))) 235.65 - 235.66 -(defn print-docs 235.67 - "Prints documentation for the public vars in a namespace" 235.68 - [ns] 235.69 - (doseq [item (ns-vars ns)] 235.70 - (print-doc (ns-resolve ns item)))) 235.71 - 235.72 -;; Convenience 235.73 - 235.74 -(defmacro vars 235.75 - "Returns a sorted seq of symbols naming public vars in 235.76 - a namespace" 235.77 - [nsname] 235.78 - `(ns-vars (get-ns '~nsname))) 235.79 - 235.80 -(defmacro dir 235.81 - "Prints a sorted directory of public vars in a namespace" 235.82 - {:deprecated "1.2"} 235.83 - [nsname] 235.84 - `(print-dir (get-ns '~nsname))) 235.85 - 235.86 -(defmacro docs 235.87 - "Prints documentation for the public vars in a namespace" 235.88 - [nsname] 235.89 - `(print-docs (get-ns '~nsname))) 235.90 - 235.91 -(defn immigrate 235.92 - "Create a public var in this namespace for each public var in the 235.93 - namespaces named by ns-names. The created vars have the same name, root 235.94 - binding, and metadata as the original except that their :ns metadata 235.95 - value is this namespace." 235.96 - [& ns-names] 235.97 - (doseq [ns ns-names] 235.98 - (require ns) 235.99 - (doseq [[sym var] (ns-publics ns)] 235.100 - (let [sym (with-meta sym (assoc (meta var) :ns *ns*))] 235.101 - (if (.hasRoot var) 235.102 - (intern *ns* sym (.getRoot var)) 235.103 - (intern *ns* sym))))))
236.1 --- a/src/clojure/contrib/pprint.clj Sat Aug 21 06:25:44 2010 -0400 236.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 236.3 @@ -1,40 +0,0 @@ 236.4 -;;; pprint.clj -- Pretty printer and Common Lisp compatible format function (cl-format) for Clojure 236.5 - 236.6 -;; by Tom Faulhaber 236.7 -;; April 3, 2009 236.8 - 236.9 -;; Copyright (c) Tom Faulhaber, April 2009. All rights reserved. 236.10 -;; The use and distribution terms for this software are covered by the 236.11 -;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 236.12 -;; which can be found in the file epl-v10.html at the root of this distribution. 236.13 -;; By using this software in any fashion, you are agreeing to be bound by 236.14 -;; the terms of this license. 236.15 -;; You must not remove this notice, or any other, from this 236.16 -;; software. 236.17 - 236.18 -;; DEPRECATED in 1.2. Promoted to clojure.pprint 236.19 - 236.20 -(ns 236.21 - ^{:author "Tom Faulhaber", 236.22 - :deprecated "1.2" 236.23 - :doc "This module comprises two elements: 236.24 -1) A pretty printer for Clojure data structures, implemented in the 236.25 - function \"pprint\" 236.26 -2) A Common Lisp compatible format function, implemented as 236.27 - \"cl-format\" because Clojure is using the name \"format\" 236.28 - for its Java-based format function. 236.29 - 236.30 -See documentation for those functions for more information or complete 236.31 -documentation on the the clojure-contrib web site on github.", 236.32 - } 236.33 - clojure.contrib.pprint 236.34 - (:use clojure.contrib.pprint.utilities) 236.35 - (:use clojure.contrib.pprint.pretty-writer 236.36 - clojure.contrib.pprint.column-writer)) 236.37 - 236.38 - 236.39 -(load "pprint/pprint_base") 236.40 -(load "pprint/cl_format") 236.41 -(load "pprint/dispatch") 236.42 - 236.43 -nil
237.1 --- a/src/clojure/contrib/pprint/cl_format.clj Sat Aug 21 06:25:44 2010 -0400 237.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 237.3 @@ -1,1844 +0,0 @@ 237.4 -;;; cl_format.clj -- part of the pretty printer for Clojure 237.5 - 237.6 -;; by Tom Faulhaber 237.7 -;; April 3, 2009 237.8 - 237.9 -; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. 237.10 -; The use and distribution terms for this software are covered by the 237.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 237.12 -; which can be found in the file epl-v10.html at the root of this distribution. 237.13 -; By using this software in any fashion, you are agreeing to be bound by 237.14 -; the terms of this license. 237.15 -; You must not remove this notice, or any other, from this software. 237.16 - 237.17 -;; This module implements the Common Lisp compatible format function as documented 237.18 -;; in "Common Lisp the Language, 2nd edition", Chapter 22 (available online at: 237.19 -;; http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node200.html#SECTION002633000000000000000) 237.20 - 237.21 -(in-ns 'clojure.contrib.pprint) 237.22 - 237.23 -;;; Forward references 237.24 -(declare compile-format) 237.25 -(declare execute-format) 237.26 -(declare init-navigator) 237.27 -;;; End forward references 237.28 - 237.29 -(defn cl-format 237.30 - "An implementation of a Common Lisp compatible format function. cl-format formats its 237.31 -arguments to an output stream or string based on the format control string given. It 237.32 -supports sophisticated formatting of structured data. 237.33 - 237.34 -Writer is an instance of java.io.Writer, true to output to *out* or nil to output 237.35 -to a string, format-in is the format control string and the remaining arguments 237.36 -are the data to be formatted. 237.37 - 237.38 -The format control string is a string to be output with embedded 'format directives' 237.39 -describing how to format the various arguments passed in. 237.40 - 237.41 -If writer is nil, cl-format returns the formatted result string. Otherwise, cl-format 237.42 -returns nil. 237.43 - 237.44 -For example: 237.45 - (let [results [46 38 22]] 237.46 - (cl-format true \"There ~[are~;is~:;are~]~:* ~d result~:p: ~{~d~^, ~}~%\" 237.47 - (count results) results)) 237.48 - 237.49 -Prints to *out*: 237.50 - There are 3 results: 46, 38, 22 237.51 - 237.52 -Detailed documentation on format control strings is available in the \"Common Lisp the 237.53 -Language, 2nd edition\", Chapter 22 (available online at: 237.54 -http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node200.html#SECTION002633000000000000000) 237.55 -and in the Common Lisp HyperSpec at 237.56 -http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm 237.57 -" 237.58 - {:see-also [["http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node200.html#SECTION002633000000000000000" 237.59 - "Common Lisp the Language"] 237.60 - ["http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm" 237.61 - "Common Lisp HyperSpec"]]} 237.62 - [writer format-in & args] 237.63 - (let [compiled-format (if (string? format-in) (compile-format format-in) format-in) 237.64 - navigator (init-navigator args)] 237.65 - (execute-format writer compiled-format navigator))) 237.66 - 237.67 -(def ^{:private true} *format-str* nil) 237.68 - 237.69 -(defn- format-error [message offset] 237.70 - (let [full-message (str message \newline *format-str* \newline 237.71 - (apply str (repeat offset \space)) "^" \newline)] 237.72 - (throw (RuntimeException. full-message)))) 237.73 - 237.74 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.75 -;;; Argument navigators manage the argument list 237.76 -;;; as the format statement moves through the list 237.77 -;;; (possibly going forwards and backwards as it does so) 237.78 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.79 - 237.80 -(defstruct ^{:private true} 237.81 - arg-navigator :seq :rest :pos ) 237.82 - 237.83 -(defn init-navigator 237.84 - "Create a new arg-navigator from the sequence with the position set to 0" 237.85 - {:skip-wiki true} 237.86 - [s] 237.87 - (let [s (seq s)] 237.88 - (struct arg-navigator s s 0))) 237.89 - 237.90 -;; TODO call format-error with offset 237.91 -(defn- next-arg [ navigator ] 237.92 - (let [ rst (:rest navigator) ] 237.93 - (if rst 237.94 - [(first rst) (struct arg-navigator (:seq navigator ) (next rst) (inc (:pos navigator)))] 237.95 - (throw (new Exception "Not enough arguments for format definition"))))) 237.96 - 237.97 -(defn- next-arg-or-nil [navigator] 237.98 - (let [rst (:rest navigator)] 237.99 - (if rst 237.100 - [(first rst) (struct arg-navigator (:seq navigator ) (next rst) (inc (:pos navigator)))] 237.101 - [nil navigator]))) 237.102 - 237.103 -;; Get an argument off the arg list and compile it if it's not already compiled 237.104 -(defn- get-format-arg [navigator] 237.105 - (let [[raw-format navigator] (next-arg navigator) 237.106 - compiled-format (if (instance? String raw-format) 237.107 - (compile-format raw-format) 237.108 - raw-format)] 237.109 - [compiled-format navigator])) 237.110 - 237.111 -(declare relative-reposition) 237.112 - 237.113 -(defn- absolute-reposition [navigator position] 237.114 - (if (>= position (:pos navigator)) 237.115 - (relative-reposition navigator (- (:pos navigator) position)) 237.116 - (struct arg-navigator (:seq navigator) (drop position (:seq navigator)) position))) 237.117 - 237.118 -(defn- relative-reposition [navigator position] 237.119 - (let [newpos (+ (:pos navigator) position)] 237.120 - (if (neg? position) 237.121 - (absolute-reposition navigator newpos) 237.122 - (struct arg-navigator (:seq navigator) (drop position (:rest navigator)) newpos)))) 237.123 - 237.124 -(defstruct ^{:private true} 237.125 - compiled-directive :func :def :params :offset) 237.126 - 237.127 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.128 -;;; When looking at the parameter list, we may need to manipulate 237.129 -;;; the argument list as well (for 'V' and '#' parameter types). 237.130 -;;; We hide all of this behind a function, but clients need to 237.131 -;;; manage changing arg navigator 237.132 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.133 - 237.134 -;; TODO: validate parameters when they come from arg list 237.135 -(defn- realize-parameter [[param [raw-val offset]] navigator] 237.136 - (let [[real-param new-navigator] 237.137 - (cond 237.138 - (contains? #{ :at :colon } param) ;pass flags through unchanged - this really isn't necessary 237.139 - [raw-val navigator] 237.140 - 237.141 - (= raw-val :parameter-from-args) 237.142 - (next-arg navigator) 237.143 - 237.144 - (= raw-val :remaining-arg-count) 237.145 - [(count (:rest navigator)) navigator] 237.146 - 237.147 - true 237.148 - [raw-val navigator])] 237.149 - [[param [real-param offset]] new-navigator])) 237.150 - 237.151 -(defn- realize-parameter-list [parameter-map navigator] 237.152 - (let [[pairs new-navigator] 237.153 - (map-passing-context realize-parameter navigator parameter-map)] 237.154 - [(into {} pairs) new-navigator])) 237.155 - 237.156 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.157 -;;; Functions that support individual directives 237.158 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.159 - 237.160 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.161 -;;; Common handling code for ~A and ~S 237.162 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.163 - 237.164 -(declare opt-base-str) 237.165 - 237.166 -(def ^{:private true} 237.167 - special-radix-markers {2 "#b" 8 "#o", 16 "#x"}) 237.168 - 237.169 -(defn- format-simple-number [n] 237.170 - (cond 237.171 - (integer? n) (if (= *print-base* 10) 237.172 - (str n (if *print-radix* ".")) 237.173 - (str 237.174 - (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r"))) 237.175 - (opt-base-str *print-base* n))) 237.176 - (ratio? n) (str 237.177 - (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r"))) 237.178 - (opt-base-str *print-base* (.numerator n)) 237.179 - "/" 237.180 - (opt-base-str *print-base* (.denominator n))) 237.181 - :else nil)) 237.182 - 237.183 -(defn- format-ascii [print-func params arg-navigator offsets] 237.184 - (let [ [arg arg-navigator] (next-arg arg-navigator) 237.185 - ^String base-output (or (format-simple-number arg) (print-func arg)) 237.186 - base-width (.length base-output) 237.187 - min-width (+ base-width (:minpad params)) 237.188 - width (if (>= min-width (:mincol params)) 237.189 - min-width 237.190 - (+ min-width 237.191 - (* (+ (quot (- (:mincol params) min-width 1) 237.192 - (:colinc params) ) 237.193 - 1) 237.194 - (:colinc params)))) 237.195 - chars (apply str (repeat (- width base-width) (:padchar params)))] 237.196 - (if (:at params) 237.197 - (print (str chars base-output)) 237.198 - (print (str base-output chars))) 237.199 - arg-navigator)) 237.200 - 237.201 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.202 -;;; Support for the integer directives ~D, ~X, ~O, ~B and some 237.203 -;;; of ~R 237.204 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.205 - 237.206 -(defn- integral? 237.207 - "returns true if a number is actually an integer (that is, has no fractional part)" 237.208 - [x] 237.209 - (cond 237.210 - (integer? x) true 237.211 - (decimal? x) (>= (.ulp (.stripTrailingZeros (bigdec 0))) 1) ; true iff no fractional part 237.212 - (float? x) (= x (Math/floor x)) 237.213 - (ratio? x) (let [^clojure.lang.Ratio r x] 237.214 - (= 0 (rem (.numerator r) (.denominator r)))) 237.215 - :else false)) 237.216 - 237.217 -(defn- remainders 237.218 - "Return the list of remainders (essentially the 'digits') of val in the given base" 237.219 - [base val] 237.220 - (reverse 237.221 - (first 237.222 - (consume #(if (pos? %) 237.223 - [(rem % base) (quot % base)] 237.224 - [nil nil]) 237.225 - val)))) 237.226 - 237.227 -;;; TODO: xlated-val does not seem to be used here. 237.228 -(defn- base-str 237.229 - "Return val as a string in the given base" 237.230 - [base val] 237.231 - (if (zero? val) 237.232 - "0" 237.233 - (let [xlated-val (cond 237.234 - (float? val) (bigdec val) 237.235 - (ratio? val) (let [^clojure.lang.Ratio r val] 237.236 - (/ (.numerator r) (.denominator r))) 237.237 - :else val)] 237.238 - (apply str 237.239 - (map 237.240 - #(if (< % 10) (char (+ (int \0) %)) (char (+ (int \a) (- % 10)))) 237.241 - (remainders base val)))))) 237.242 - 237.243 -(def ^{:private true} 237.244 - java-base-formats {8 "%o", 10 "%d", 16 "%x"}) 237.245 - 237.246 -(defn- opt-base-str 237.247 - "Return val as a string in the given base, using clojure.core/format if supported 237.248 -for improved performance" 237.249 - [base val] 237.250 - (let [format-str (get java-base-formats base)] 237.251 - (if (and format-str (integer? val) (-> val class .getName (.startsWith "java."))) 237.252 - (clojure.core/format format-str val) 237.253 - (base-str base val)))) 237.254 - 237.255 -(defn- group-by* [unit lis] 237.256 - (reverse 237.257 - (first 237.258 - (consume (fn [x] [(seq (reverse (take unit x))) (seq (drop unit x))]) (reverse lis))))) 237.259 - 237.260 -(defn- format-integer [base params arg-navigator offsets] 237.261 - (let [[arg arg-navigator] (next-arg arg-navigator)] 237.262 - (if (integral? arg) 237.263 - (let [neg (neg? arg) 237.264 - pos-arg (if neg (- arg) arg) 237.265 - raw-str (opt-base-str base pos-arg) 237.266 - group-str (if (:colon params) 237.267 - (let [groups (map #(apply str %) (group-by* (:commainterval params) raw-str)) 237.268 - commas (repeat (count groups) (:commachar params))] 237.269 - (apply str (next (interleave commas groups)))) 237.270 - raw-str) 237.271 - ^String signed-str (cond 237.272 - neg (str "-" group-str) 237.273 - (:at params) (str "+" group-str) 237.274 - true group-str) 237.275 - padded-str (if (< (.length signed-str) (:mincol params)) 237.276 - (str (apply str (repeat (- (:mincol params) (.length signed-str)) 237.277 - (:padchar params))) 237.278 - signed-str) 237.279 - signed-str)] 237.280 - (print padded-str)) 237.281 - (format-ascii print-str {:mincol (:mincol params) :colinc 1 :minpad 0 237.282 - :padchar (:padchar params) :at true} 237.283 - (init-navigator [arg]) nil)) 237.284 - arg-navigator)) 237.285 - 237.286 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.287 -;;; Support for english formats (~R and ~:R) 237.288 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.289 - 237.290 -(def ^{:private true} 237.291 - english-cardinal-units 237.292 - ["zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" 237.293 - "ten" "eleven" "twelve" "thirteen" "fourteen" 237.294 - "fifteen" "sixteen" "seventeen" "eighteen" "nineteen"]) 237.295 - 237.296 -(def ^{:private true} 237.297 - english-ordinal-units 237.298 - ["zeroth" "first" "second" "third" "fourth" "fifth" "sixth" "seventh" "eighth" "ninth" 237.299 - "tenth" "eleventh" "twelfth" "thirteenth" "fourteenth" 237.300 - "fifteenth" "sixteenth" "seventeenth" "eighteenth" "nineteenth"]) 237.301 - 237.302 -(def ^{:private true} 237.303 - english-cardinal-tens 237.304 - ["" "" "twenty" "thirty" "forty" "fifty" "sixty" "seventy" "eighty" "ninety"]) 237.305 - 237.306 -(def ^{:private true} 237.307 - english-ordinal-tens 237.308 - ["" "" "twentieth" "thirtieth" "fortieth" "fiftieth" 237.309 - "sixtieth" "seventieth" "eightieth" "ninetieth"]) 237.310 - 237.311 -;; We use "short scale" for our units (see http://en.wikipedia.org/wiki/Long_and_short_scales) 237.312 -;; Number names from http://www.jimloy.com/math/billion.htm 237.313 -;; We follow the rules for writing numbers from the Blue Book 237.314 -;; (http://www.grammarbook.com/numbers/numbers.asp) 237.315 -(def ^{:private true} 237.316 - english-scale-numbers 237.317 - ["" "thousand" "million" "billion" "trillion" "quadrillion" "quintillion" 237.318 - "sextillion" "septillion" "octillion" "nonillion" "decillion" 237.319 - "undecillion" "duodecillion" "tredecillion" "quattuordecillion" 237.320 - "quindecillion" "sexdecillion" "septendecillion" 237.321 - "octodecillion" "novemdecillion" "vigintillion"]) 237.322 - 237.323 -(defn- format-simple-cardinal 237.324 - "Convert a number less than 1000 to a cardinal english string" 237.325 - [num] 237.326 - (let [hundreds (quot num 100) 237.327 - tens (rem num 100)] 237.328 - (str 237.329 - (if (pos? hundreds) (str (nth english-cardinal-units hundreds) " hundred")) 237.330 - (if (and (pos? hundreds) (pos? tens)) " ") 237.331 - (if (pos? tens) 237.332 - (if (< tens 20) 237.333 - (nth english-cardinal-units tens) 237.334 - (let [ten-digit (quot tens 10) 237.335 - unit-digit (rem tens 10)] 237.336 - (str 237.337 - (if (pos? ten-digit) (nth english-cardinal-tens ten-digit)) 237.338 - (if (and (pos? ten-digit) (pos? unit-digit)) "-") 237.339 - (if (pos? unit-digit) (nth english-cardinal-units unit-digit))))))))) 237.340 - 237.341 -(defn- add-english-scales 237.342 - "Take a sequence of parts, add scale numbers (e.g., million) and combine into a string 237.343 -offset is a factor of 10^3 to multiply by" 237.344 - [parts offset] 237.345 - (let [cnt (count parts)] 237.346 - (loop [acc [] 237.347 - pos (dec cnt) 237.348 - this (first parts) 237.349 - remainder (next parts)] 237.350 - (if (nil? remainder) 237.351 - (str (apply str (interpose ", " acc)) 237.352 - (if (and (not (empty? this)) (not (empty? acc))) ", ") 237.353 - this 237.354 - (if (and (not (empty? this)) (pos? (+ pos offset))) 237.355 - (str " " (nth english-scale-numbers (+ pos offset))))) 237.356 - (recur 237.357 - (if (empty? this) 237.358 - acc 237.359 - (conj acc (str this " " (nth english-scale-numbers (+ pos offset))))) 237.360 - (dec pos) 237.361 - (first remainder) 237.362 - (next remainder)))))) 237.363 - 237.364 -(defn- format-cardinal-english [params navigator offsets] 237.365 - (let [[arg navigator] (next-arg navigator)] 237.366 - (if (= 0 arg) 237.367 - (print "zero") 237.368 - (let [abs-arg (if (neg? arg) (- arg) arg) ; some numbers are too big for Math/abs 237.369 - parts (remainders 1000 abs-arg)] 237.370 - (if (<= (count parts) (count english-scale-numbers)) 237.371 - (let [parts-strs (map format-simple-cardinal parts) 237.372 - full-str (add-english-scales parts-strs 0)] 237.373 - (print (str (if (neg? arg) "minus ") full-str))) 237.374 - (format-integer ;; for numbers > 10^63, we fall back on ~D 237.375 - 10 237.376 - { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true} 237.377 - (init-navigator [arg]) 237.378 - { :mincol 0, :padchar 0, :commachar 0 :commainterval 0})))) 237.379 - navigator)) 237.380 - 237.381 -(defn- format-simple-ordinal 237.382 - "Convert a number less than 1000 to a ordinal english string 237.383 -Note this should only be used for the last one in the sequence" 237.384 - [num] 237.385 - (let [hundreds (quot num 100) 237.386 - tens (rem num 100)] 237.387 - (str 237.388 - (if (pos? hundreds) (str (nth english-cardinal-units hundreds) " hundred")) 237.389 - (if (and (pos? hundreds) (pos? tens)) " ") 237.390 - (if (pos? tens) 237.391 - (if (< tens 20) 237.392 - (nth english-ordinal-units tens) 237.393 - (let [ten-digit (quot tens 10) 237.394 - unit-digit (rem tens 10)] 237.395 - (if (and (pos? ten-digit) (not (pos? unit-digit))) 237.396 - (nth english-ordinal-tens ten-digit) 237.397 - (str 237.398 - (if (pos? ten-digit) (nth english-cardinal-tens ten-digit)) 237.399 - (if (and (pos? ten-digit) (pos? unit-digit)) "-") 237.400 - (if (pos? unit-digit) (nth english-ordinal-units unit-digit)))))) 237.401 - (if (pos? hundreds) "th"))))) 237.402 - 237.403 -(defn- format-ordinal-english [params navigator offsets] 237.404 - (let [[arg navigator] (next-arg navigator)] 237.405 - (if (= 0 arg) 237.406 - (print "zeroth") 237.407 - (let [abs-arg (if (neg? arg) (- arg) arg) ; some numbers are too big for Math/abs 237.408 - parts (remainders 1000 abs-arg)] 237.409 - (if (<= (count parts) (count english-scale-numbers)) 237.410 - (let [parts-strs (map format-simple-cardinal (drop-last parts)) 237.411 - head-str (add-english-scales parts-strs 1) 237.412 - tail-str (format-simple-ordinal (last parts))] 237.413 - (print (str (if (neg? arg) "minus ") 237.414 - (cond 237.415 - (and (not (empty? head-str)) (not (empty? tail-str))) 237.416 - (str head-str ", " tail-str) 237.417 - 237.418 - (not (empty? head-str)) (str head-str "th") 237.419 - :else tail-str)))) 237.420 - (do (format-integer ;; for numbers > 10^63, we fall back on ~D 237.421 - 10 237.422 - { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true} 237.423 - (init-navigator [arg]) 237.424 - { :mincol 0, :padchar 0, :commachar 0 :commainterval 0}) 237.425 - (let [low-two-digits (rem arg 100) 237.426 - not-teens (or (< 11 low-two-digits) (> 19 low-two-digits)) 237.427 - low-digit (rem low-two-digits 10)] 237.428 - (print (cond 237.429 - (and (== low-digit 1) not-teens) "st" 237.430 - (and (== low-digit 2) not-teens) "nd" 237.431 - (and (== low-digit 3) not-teens) "rd" 237.432 - :else "th"))))))) 237.433 - navigator)) 237.434 - 237.435 - 237.436 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.437 -;;; Support for roman numeral formats (~@R and ~@:R) 237.438 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.439 - 237.440 -(def ^{:private true} 237.441 - old-roman-table 237.442 - [[ "I" "II" "III" "IIII" "V" "VI" "VII" "VIII" "VIIII"] 237.443 - [ "X" "XX" "XXX" "XXXX" "L" "LX" "LXX" "LXXX" "LXXXX"] 237.444 - [ "C" "CC" "CCC" "CCCC" "D" "DC" "DCC" "DCCC" "DCCCC"] 237.445 - [ "M" "MM" "MMM"]]) 237.446 - 237.447 -(def ^{:private true} 237.448 - new-roman-table 237.449 - [[ "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX"] 237.450 - [ "X" "XX" "XXX" "XL" "L" "LX" "LXX" "LXXX" "XC"] 237.451 - [ "C" "CC" "CCC" "CD" "D" "DC" "DCC" "DCCC" "CM"] 237.452 - [ "M" "MM" "MMM"]]) 237.453 - 237.454 -(defn- format-roman 237.455 - "Format a roman numeral using the specified look-up table" 237.456 - [table params navigator offsets] 237.457 - (let [[arg navigator] (next-arg navigator)] 237.458 - (if (and (number? arg) (> arg 0) (< arg 4000)) 237.459 - (let [digits (remainders 10 arg)] 237.460 - (loop [acc [] 237.461 - pos (dec (count digits)) 237.462 - digits digits] 237.463 - (if (empty? digits) 237.464 - (print (apply str acc)) 237.465 - (let [digit (first digits)] 237.466 - (recur (if (= 0 digit) 237.467 - acc 237.468 - (conj acc (nth (nth table pos) (dec digit)))) 237.469 - (dec pos) 237.470 - (next digits)))))) 237.471 - (format-integer ;; for anything <= 0 or > 3999, we fall back on ~D 237.472 - 10 237.473 - { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true} 237.474 - (init-navigator [arg]) 237.475 - { :mincol 0, :padchar 0, :commachar 0 :commainterval 0})) 237.476 - navigator)) 237.477 - 237.478 -(defn- format-old-roman [params navigator offsets] 237.479 - (format-roman old-roman-table params navigator offsets)) 237.480 - 237.481 -(defn- format-new-roman [params navigator offsets] 237.482 - (format-roman new-roman-table params navigator offsets)) 237.483 - 237.484 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.485 -;;; Support for character formats (~C) 237.486 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.487 - 237.488 -(def ^{:private true} 237.489 - special-chars { 8 "Backspace", 9 "Tab", 10 "Newline", 13 "Return", 32 "Space"}) 237.490 - 237.491 -(defn- pretty-character [params navigator offsets] 237.492 - (let [[c navigator] (next-arg navigator) 237.493 - as-int (int c) 237.494 - base-char (bit-and as-int 127) 237.495 - meta (bit-and as-int 128) 237.496 - special (get special-chars base-char)] 237.497 - (if (> meta 0) (print "Meta-")) 237.498 - (print (cond 237.499 - special special 237.500 - (< base-char 32) (str "Control-" (char (+ base-char 64))) 237.501 - (= base-char 127) "Control-?" 237.502 - :else (char base-char))) 237.503 - navigator)) 237.504 - 237.505 -(defn- readable-character [params navigator offsets] 237.506 - (let [[c navigator] (next-arg navigator)] 237.507 - (condp = (:char-format params) 237.508 - \o (cl-format true "\\o~3,'0o" (int c)) 237.509 - \u (cl-format true "\\u~4,'0x" (int c)) 237.510 - nil (pr c)) 237.511 - navigator)) 237.512 - 237.513 -(defn- plain-character [params navigator offsets] 237.514 - (let [[char navigator] (next-arg navigator)] 237.515 - (print char) 237.516 - navigator)) 237.517 - 237.518 -;; Check to see if a result is an abort (~^) construct 237.519 -;; TODO: move these funcs somewhere more appropriate 237.520 -(defn- abort? [context] 237.521 - (let [token (first context)] 237.522 - (or (= :up-arrow token) (= :colon-up-arrow token)))) 237.523 - 237.524 -;; Handle the execution of "sub-clauses" in bracket constructions 237.525 -(defn- execute-sub-format [format args base-args] 237.526 - (second 237.527 - (map-passing-context 237.528 - (fn [element context] 237.529 - (if (abort? context) 237.530 - [nil context] ; just keep passing it along 237.531 - (let [[params args] (realize-parameter-list (:params element) context) 237.532 - [params offsets] (unzip-map params) 237.533 - params (assoc params :base-args base-args)] 237.534 - [nil (apply (:func element) [params args offsets])]))) 237.535 - args 237.536 - format))) 237.537 - 237.538 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.539 -;;; Support for real number formats 237.540 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.541 - 237.542 -;; TODO - return exponent as int to eliminate double conversion 237.543 -(defn- float-parts-base 237.544 - "Produce string parts for the mantissa (normalized 1-9) and exponent" 237.545 - [^Object f] 237.546 - (let [^String s (.toLowerCase (.toString f)) 237.547 - exploc (.indexOf s (int \e))] 237.548 - (if (neg? exploc) 237.549 - (let [dotloc (.indexOf s (int \.))] 237.550 - (if (neg? dotloc) 237.551 - [s (str (dec (count s)))] 237.552 - [(str (subs s 0 dotloc) (subs s (inc dotloc))) (str (dec dotloc))])) 237.553 - [(str (subs s 0 1) (subs s 2 exploc)) (subs s (inc exploc))]))) 237.554 - 237.555 - 237.556 -(defn- float-parts 237.557 - "Take care of leading and trailing zeros in decomposed floats" 237.558 - [f] 237.559 - (let [[m ^String e] (float-parts-base f) 237.560 - m1 (rtrim m \0) 237.561 - m2 (ltrim m1 \0) 237.562 - delta (- (count m1) (count m2)) 237.563 - ^String e (if (and (pos? (count e)) (= (nth e 0) \+)) (subs e 1) e)] 237.564 - (if (empty? m2) 237.565 - ["0" 0] 237.566 - [m2 (- (Integer/valueOf e) delta)]))) 237.567 - 237.568 -(defn- round-str [m e d w] 237.569 - (if (or d w) 237.570 - (let [len (count m) 237.571 - round-pos (if d (+ e d 1)) 237.572 - round-pos (if (and w (< (inc e) (dec w)) 237.573 - (or (nil? round-pos) (< (dec w) round-pos))) 237.574 - (dec w) 237.575 - round-pos) 237.576 - [m1 e1 round-pos len] (if (= round-pos 0) 237.577 - [(str "0" m) (inc e) 1 (inc len)] 237.578 - [m e round-pos len])] 237.579 - (if round-pos 237.580 - (if (neg? round-pos) 237.581 - ["0" 0 false] 237.582 - (if (> len round-pos) 237.583 - (let [round-char (nth m1 round-pos) 237.584 - ^String result (subs m1 0 round-pos)] 237.585 - (if (>= (int round-char) (int \5)) 237.586 - (let [result-val (Integer/valueOf result) 237.587 - leading-zeros (subs result 0 (min (prefix-count result \0) (- round-pos 1))) 237.588 - round-up-result (str leading-zeros 237.589 - (String/valueOf (+ result-val 237.590 - (if (neg? result-val) -1 1)))) 237.591 - expanded (> (count round-up-result) (count result))] 237.592 - [round-up-result e1 expanded]) 237.593 - [result e1 false])) 237.594 - [m e false])) 237.595 - [m e false])) 237.596 - [m e false])) 237.597 - 237.598 -(defn- expand-fixed [m e d] 237.599 - (let [m1 (if (neg? e) (str (apply str (repeat (dec (- e)) \0)) m) m) 237.600 - len (count m1) 237.601 - target-len (if d (+ e d 1) (inc e))] 237.602 - (if (< len target-len) 237.603 - (str m1 (apply str (repeat (- target-len len) \0))) 237.604 - m1))) 237.605 - 237.606 -(defn- insert-decimal 237.607 - "Insert the decimal point at the right spot in the number to match an exponent" 237.608 - [m e] 237.609 - (if (neg? e) 237.610 - (str "." m) 237.611 - (let [loc (inc e)] 237.612 - (str (subs m 0 loc) "." (subs m loc))))) 237.613 - 237.614 -(defn- get-fixed [m e d] 237.615 - (insert-decimal (expand-fixed m e d) e)) 237.616 - 237.617 -(defn- insert-scaled-decimal 237.618 - "Insert the decimal point at the right spot in the number to match an exponent" 237.619 - [m k] 237.620 - (if (neg? k) 237.621 - (str "." m) 237.622 - (str (subs m 0 k) "." (subs m k)))) 237.623 - 237.624 -;; the function to render ~F directives 237.625 -;; TODO: support rationals. Back off to ~D/~A is the appropriate cases 237.626 -(defn- fixed-float [params navigator offsets] 237.627 - (let [w (:w params) 237.628 - d (:d params) 237.629 - [arg navigator] (next-arg navigator) 237.630 - [sign abs] (if (neg? arg) ["-" (- arg)] ["+" arg]) 237.631 - [mantissa exp] (float-parts abs) 237.632 - scaled-exp (+ exp (:k params)) 237.633 - add-sign (or (:at params) (neg? arg)) 237.634 - append-zero (and (not d) (<= (dec (count mantissa)) scaled-exp)) 237.635 - [rounded-mantissa scaled-exp expanded] (round-str mantissa scaled-exp 237.636 - d (if w (- w (if add-sign 1 0)))) 237.637 - fixed-repr (get-fixed rounded-mantissa (if expanded (inc scaled-exp) scaled-exp) d) 237.638 - prepend-zero (= (first fixed-repr) \.)] 237.639 - (if w 237.640 - (let [len (count fixed-repr) 237.641 - signed-len (if add-sign (inc len) len) 237.642 - prepend-zero (and prepend-zero (not (>= signed-len w))) 237.643 - append-zero (and append-zero (not (>= signed-len w))) 237.644 - full-len (if (or prepend-zero append-zero) 237.645 - (inc signed-len) 237.646 - signed-len)] 237.647 - (if (and (> full-len w) (:overflowchar params)) 237.648 - (print (apply str (repeat w (:overflowchar params)))) 237.649 - (print (str 237.650 - (apply str (repeat (- w full-len) (:padchar params))) 237.651 - (if add-sign sign) 237.652 - (if prepend-zero "0") 237.653 - fixed-repr 237.654 - (if append-zero "0"))))) 237.655 - (print (str 237.656 - (if add-sign sign) 237.657 - (if prepend-zero "0") 237.658 - fixed-repr 237.659 - (if append-zero "0")))) 237.660 - navigator)) 237.661 - 237.662 - 237.663 -;; the function to render ~E directives 237.664 -;; TODO: support rationals. Back off to ~D/~A is the appropriate cases 237.665 -;; TODO: define ~E representation for Infinity 237.666 -(defn- exponential-float [params navigator offsets] 237.667 - (let [[arg navigator] (next-arg navigator)] 237.668 - (loop [[mantissa exp] (float-parts (if (neg? arg) (- arg) arg))] 237.669 - (let [w (:w params) 237.670 - d (:d params) 237.671 - e (:e params) 237.672 - k (:k params) 237.673 - expchar (or (:exponentchar params) \E) 237.674 - add-sign (or (:at params) (neg? arg)) 237.675 - prepend-zero (<= k 0) 237.676 - ^Integer scaled-exp (- exp (dec k)) 237.677 - scaled-exp-str (str (Math/abs scaled-exp)) 237.678 - scaled-exp-str (str expchar (if (neg? scaled-exp) \- \+) 237.679 - (if e (apply str 237.680 - (repeat 237.681 - (- e 237.682 - (count scaled-exp-str)) 237.683 - \0))) 237.684 - scaled-exp-str) 237.685 - exp-width (count scaled-exp-str) 237.686 - base-mantissa-width (count mantissa) 237.687 - scaled-mantissa (str (apply str (repeat (- k) \0)) 237.688 - mantissa 237.689 - (if d 237.690 - (apply str 237.691 - (repeat 237.692 - (- d (dec base-mantissa-width) 237.693 - (if (neg? k) (- k) 0)) \0)))) 237.694 - w-mantissa (if w (- w exp-width)) 237.695 - [rounded-mantissa _ incr-exp] (round-str 237.696 - scaled-mantissa 0 237.697 - (cond 237.698 - (= k 0) (dec d) 237.699 - (pos? k) d 237.700 - (neg? k) (dec d)) 237.701 - (if w-mantissa 237.702 - (- w-mantissa (if add-sign 1 0)))) 237.703 - full-mantissa (insert-scaled-decimal rounded-mantissa k) 237.704 - append-zero (and (= k (count rounded-mantissa)) (nil? d))] 237.705 - (if (not incr-exp) 237.706 - (if w 237.707 - (let [len (+ (count full-mantissa) exp-width) 237.708 - signed-len (if add-sign (inc len) len) 237.709 - prepend-zero (and prepend-zero (not (= signed-len w))) 237.710 - full-len (if prepend-zero (inc signed-len) signed-len) 237.711 - append-zero (and append-zero (< full-len w))] 237.712 - (if (and (or (> full-len w) (and e (> (- exp-width 2) e))) 237.713 - (:overflowchar params)) 237.714 - (print (apply str (repeat w (:overflowchar params)))) 237.715 - (print (str 237.716 - (apply str 237.717 - (repeat 237.718 - (- w full-len (if append-zero 1 0) ) 237.719 - (:padchar params))) 237.720 - (if add-sign (if (neg? arg) \- \+)) 237.721 - (if prepend-zero "0") 237.722 - full-mantissa 237.723 - (if append-zero "0") 237.724 - scaled-exp-str)))) 237.725 - (print (str 237.726 - (if add-sign (if (neg? arg) \- \+)) 237.727 - (if prepend-zero "0") 237.728 - full-mantissa 237.729 - (if append-zero "0") 237.730 - scaled-exp-str))) 237.731 - (recur [rounded-mantissa (inc exp)])))) 237.732 - navigator)) 237.733 - 237.734 -;; the function to render ~G directives 237.735 -;; This just figures out whether to pass the request off to ~F or ~E based 237.736 -;; on the algorithm in CLtL. 237.737 -;; TODO: support rationals. Back off to ~D/~A is the appropriate cases 237.738 -;; TODO: refactor so that float-parts isn't called twice 237.739 -(defn- general-float [params navigator offsets] 237.740 - (let [[arg _] (next-arg navigator) 237.741 - [mantissa exp] (float-parts (if (neg? arg) (- arg) arg)) 237.742 - w (:w params) 237.743 - d (:d params) 237.744 - e (:e params) 237.745 - n (if (= arg 0.0) 0 (inc exp)) 237.746 - ee (if e (+ e 2) 4) 237.747 - ww (if w (- w ee)) 237.748 - d (if d d (max (count mantissa) (min n 7))) 237.749 - dd (- d n)] 237.750 - (if (<= 0 dd d) 237.751 - (let [navigator (fixed-float {:w ww, :d dd, :k 0, 237.752 - :overflowchar (:overflowchar params), 237.753 - :padchar (:padchar params), :at (:at params)} 237.754 - navigator offsets)] 237.755 - (print (apply str (repeat ee \space))) 237.756 - navigator) 237.757 - (exponential-float params navigator offsets)))) 237.758 - 237.759 -;; the function to render ~$ directives 237.760 -;; TODO: support rationals. Back off to ~D/~A is the appropriate cases 237.761 -(defn- dollar-float [params navigator offsets] 237.762 - (let [[^Double arg navigator] (next-arg navigator) 237.763 - [mantissa exp] (float-parts (Math/abs arg)) 237.764 - d (:d params) ; digits after the decimal 237.765 - n (:n params) ; minimum digits before the decimal 237.766 - w (:w params) ; minimum field width 237.767 - add-sign (or (:at params) (neg? arg)) 237.768 - [rounded-mantissa scaled-exp expanded] (round-str mantissa exp d nil) 237.769 - ^String fixed-repr (get-fixed rounded-mantissa (if expanded (inc scaled-exp) scaled-exp) d) 237.770 - full-repr (str (apply str (repeat (- n (.indexOf fixed-repr (int \.))) \0)) fixed-repr) 237.771 - full-len (+ (count full-repr) (if add-sign 1 0))] 237.772 - (print (str 237.773 - (if (and (:colon params) add-sign) (if (neg? arg) \- \+)) 237.774 - (apply str (repeat (- w full-len) (:padchar params))) 237.775 - (if (and (not (:colon params)) add-sign) (if (neg? arg) \- \+)) 237.776 - full-repr)) 237.777 - navigator)) 237.778 - 237.779 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.780 -;;; Support for the '~[...~]' conditional construct in its 237.781 -;;; different flavors 237.782 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.783 - 237.784 -;; ~[...~] without any modifiers chooses one of the clauses based on the param or 237.785 -;; next argument 237.786 -;; TODO check arg is positive int 237.787 -(defn- choice-conditional [params arg-navigator offsets] 237.788 - (let [arg (:selector params) 237.789 - [arg navigator] (if arg [arg arg-navigator] (next-arg arg-navigator)) 237.790 - clauses (:clauses params) 237.791 - clause (if (or (neg? arg) (>= arg (count clauses))) 237.792 - (first (:else params)) 237.793 - (nth clauses arg))] 237.794 - (if clause 237.795 - (execute-sub-format clause navigator (:base-args params)) 237.796 - navigator))) 237.797 - 237.798 -;; ~:[...~] with the colon reads the next argument treating it as a truth value 237.799 -(defn- boolean-conditional [params arg-navigator offsets] 237.800 - (let [[arg navigator] (next-arg arg-navigator) 237.801 - clauses (:clauses params) 237.802 - clause (if arg 237.803 - (second clauses) 237.804 - (first clauses))] 237.805 - (if clause 237.806 - (execute-sub-format clause navigator (:base-args params)) 237.807 - navigator))) 237.808 - 237.809 -;; ~@[...~] with the at sign executes the conditional if the next arg is not 237.810 -;; nil/false without consuming the arg 237.811 -(defn- check-arg-conditional [params arg-navigator offsets] 237.812 - (let [[arg navigator] (next-arg arg-navigator) 237.813 - clauses (:clauses params) 237.814 - clause (if arg (first clauses))] 237.815 - (if arg 237.816 - (if clause 237.817 - (execute-sub-format clause arg-navigator (:base-args params)) 237.818 - arg-navigator) 237.819 - navigator))) 237.820 - 237.821 - 237.822 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.823 -;;; Support for the '~{...~}' iteration construct in its 237.824 -;;; different flavors 237.825 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.826 - 237.827 - 237.828 -;; ~{...~} without any modifiers uses the next argument as an argument list that 237.829 -;; is consumed by all the iterations 237.830 -(defn- iterate-sublist [params navigator offsets] 237.831 - (let [max-count (:max-iterations params) 237.832 - param-clause (first (:clauses params)) 237.833 - [clause navigator] (if (empty? param-clause) 237.834 - (get-format-arg navigator) 237.835 - [param-clause navigator]) 237.836 - [arg-list navigator] (next-arg navigator) 237.837 - args (init-navigator arg-list)] 237.838 - (loop [count 0 237.839 - args args 237.840 - last-pos (num -1)] 237.841 - (if (and (not max-count) (= (:pos args) last-pos) (> count 1)) 237.842 - ;; TODO get the offset in here and call format exception 237.843 - (throw (RuntimeException. "%{ construct not consuming any arguments: Infinite loop!"))) 237.844 - (if (or (and (empty? (:rest args)) 237.845 - (or (not (:colon (:right-params params))) (> count 0))) 237.846 - (and max-count (>= count max-count))) 237.847 - navigator 237.848 - (let [iter-result (execute-sub-format clause args (:base-args params))] 237.849 - (if (= :up-arrow (first iter-result)) 237.850 - navigator 237.851 - (recur (inc count) iter-result (:pos args)))))))) 237.852 - 237.853 -;; ~:{...~} with the colon treats the next argument as a list of sublists. Each of the 237.854 -;; sublists is used as the arglist for a single iteration. 237.855 -(defn- iterate-list-of-sublists [params navigator offsets] 237.856 - (let [max-count (:max-iterations params) 237.857 - param-clause (first (:clauses params)) 237.858 - [clause navigator] (if (empty? param-clause) 237.859 - (get-format-arg navigator) 237.860 - [param-clause navigator]) 237.861 - [arg-list navigator] (next-arg navigator)] 237.862 - (loop [count 0 237.863 - arg-list arg-list] 237.864 - (if (or (and (empty? arg-list) 237.865 - (or (not (:colon (:right-params params))) (> count 0))) 237.866 - (and max-count (>= count max-count))) 237.867 - navigator 237.868 - (let [iter-result (execute-sub-format 237.869 - clause 237.870 - (init-navigator (first arg-list)) 237.871 - (init-navigator (next arg-list)))] 237.872 - (if (= :colon-up-arrow (first iter-result)) 237.873 - navigator 237.874 - (recur (inc count) (next arg-list)))))))) 237.875 - 237.876 -;; ~@{...~} with the at sign uses the main argument list as the arguments to the iterations 237.877 -;; is consumed by all the iterations 237.878 -(defn- iterate-main-list [params navigator offsets] 237.879 - (let [max-count (:max-iterations params) 237.880 - param-clause (first (:clauses params)) 237.881 - [clause navigator] (if (empty? param-clause) 237.882 - (get-format-arg navigator) 237.883 - [param-clause navigator])] 237.884 - (loop [count 0 237.885 - navigator navigator 237.886 - last-pos (num -1)] 237.887 - (if (and (not max-count) (= (:pos navigator) last-pos) (> count 1)) 237.888 - ;; TODO get the offset in here and call format exception 237.889 - (throw (RuntimeException. "%@{ construct not consuming any arguments: Infinite loop!"))) 237.890 - (if (or (and (empty? (:rest navigator)) 237.891 - (or (not (:colon (:right-params params))) (> count 0))) 237.892 - (and max-count (>= count max-count))) 237.893 - navigator 237.894 - (let [iter-result (execute-sub-format clause navigator (:base-args params))] 237.895 - (if (= :up-arrow (first iter-result)) 237.896 - (second iter-result) 237.897 - (recur 237.898 - (inc count) iter-result (:pos navigator)))))))) 237.899 - 237.900 -;; ~@:{...~} with both colon and at sign uses the main argument list as a set of sublists, one 237.901 -;; of which is consumed with each iteration 237.902 -(defn- iterate-main-sublists [params navigator offsets] 237.903 - (let [max-count (:max-iterations params) 237.904 - param-clause (first (:clauses params)) 237.905 - [clause navigator] (if (empty? param-clause) 237.906 - (get-format-arg navigator) 237.907 - [param-clause navigator]) 237.908 - ] 237.909 - (loop [count 0 237.910 - navigator navigator] 237.911 - (if (or (and (empty? (:rest navigator)) 237.912 - (or (not (:colon (:right-params params))) (> count 0))) 237.913 - (and max-count (>= count max-count))) 237.914 - navigator 237.915 - (let [[sublist navigator] (next-arg-or-nil navigator) 237.916 - iter-result (execute-sub-format clause (init-navigator sublist) navigator)] 237.917 - (if (= :colon-up-arrow (first iter-result)) 237.918 - navigator 237.919 - (recur (inc count) navigator))))))) 237.920 - 237.921 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.922 -;;; The '~< directive has two completely different meanings 237.923 -;;; in the '~<...~>' form it does justification, but with 237.924 -;;; ~<...~:>' it represents the logical block operation of the 237.925 -;;; pretty printer. 237.926 -;;; 237.927 -;;; Unfortunately, the current architecture decides what function 237.928 -;;; to call at form parsing time before the sub-clauses have been 237.929 -;;; folded, so it is left to run-time to make the decision. 237.930 -;;; 237.931 -;;; TODO: make it possible to make these decisions at compile-time. 237.932 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.933 - 237.934 -(declare format-logical-block) 237.935 -(declare justify-clauses) 237.936 - 237.937 -(defn- logical-block-or-justify [params navigator offsets] 237.938 - (if (:colon (:right-params params)) 237.939 - (format-logical-block params navigator offsets) 237.940 - (justify-clauses params navigator offsets))) 237.941 - 237.942 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.943 -;;; Support for the '~<...~>' justification directive 237.944 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.945 - 237.946 -(defn- render-clauses [clauses navigator base-navigator] 237.947 - (loop [clauses clauses 237.948 - acc [] 237.949 - navigator navigator] 237.950 - (if (empty? clauses) 237.951 - [acc navigator] 237.952 - (let [clause (first clauses) 237.953 - [iter-result result-str] (binding [*out* (java.io.StringWriter.)] 237.954 - [(execute-sub-format clause navigator base-navigator) 237.955 - (.toString *out*)])] 237.956 - (if (= :up-arrow (first iter-result)) 237.957 - [acc (second iter-result)] 237.958 - (recur (next clauses) (conj acc result-str) iter-result)))))) 237.959 - 237.960 -;; TODO support for ~:; constructions 237.961 -(defn- justify-clauses [params navigator offsets] 237.962 - (let [[[eol-str] new-navigator] (when-let [else (:else params)] 237.963 - (render-clauses else navigator (:base-args params))) 237.964 - navigator (or new-navigator navigator) 237.965 - [else-params new-navigator] (when-let [p (:else-params params)] 237.966 - (realize-parameter-list p navigator)) 237.967 - navigator (or new-navigator navigator) 237.968 - min-remaining (or (first (:min-remaining else-params)) 0) 237.969 - max-columns (or (first (:max-columns else-params)) 237.970 - (get-max-column *out*)) 237.971 - clauses (:clauses params) 237.972 - [strs navigator] (render-clauses clauses navigator (:base-args params)) 237.973 - slots (max 1 237.974 - (+ (dec (count strs)) (if (:colon params) 1 0) (if (:at params) 1 0))) 237.975 - chars (reduce + (map count strs)) 237.976 - mincol (:mincol params) 237.977 - minpad (:minpad params) 237.978 - colinc (:colinc params) 237.979 - minout (+ chars (* slots minpad)) 237.980 - result-columns (if (<= minout mincol) 237.981 - mincol 237.982 - (+ mincol (* colinc 237.983 - (+ 1 (quot (- minout mincol 1) colinc))))) 237.984 - total-pad (- result-columns chars) 237.985 - pad (max minpad (quot total-pad slots)) 237.986 - extra-pad (- total-pad (* pad slots)) 237.987 - pad-str (apply str (repeat pad (:padchar params)))] 237.988 - (if (and eol-str (> (+ (get-column (:base @@*out*)) min-remaining result-columns) 237.989 - max-columns)) 237.990 - (print eol-str)) 237.991 - (loop [slots slots 237.992 - extra-pad extra-pad 237.993 - strs strs 237.994 - pad-only (or (:colon params) 237.995 - (and (= (count strs) 1) (not (:at params))))] 237.996 - (if (seq strs) 237.997 - (do 237.998 - (print (str (if (not pad-only) (first strs)) 237.999 - (if (or pad-only (next strs) (:at params)) pad-str) 237.1000 - (if (pos? extra-pad) (:padchar params)))) 237.1001 - (recur 237.1002 - (dec slots) 237.1003 - (dec extra-pad) 237.1004 - (if pad-only strs (next strs)) 237.1005 - false)))) 237.1006 - navigator)) 237.1007 - 237.1008 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1009 -;;; Support for case modification with ~(...~). 237.1010 -;;; We do this by wrapping the underlying writer with 237.1011 -;;; a special writer to do the appropriate modification. This 237.1012 -;;; allows us to support arbitrary-sized output and sources 237.1013 -;;; that may block. 237.1014 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1015 - 237.1016 -(defn- downcase-writer 237.1017 - "Returns a proxy that wraps writer, converting all characters to lower case" 237.1018 - [^java.io.Writer writer] 237.1019 - (proxy [java.io.Writer] [] 237.1020 - (close [] (.close writer)) 237.1021 - (flush [] (.flush writer)) 237.1022 - (write ([^chars cbuf ^Integer off ^Integer len] 237.1023 - (.write writer cbuf off len)) 237.1024 - ([x] 237.1025 - (condp = (class x) 237.1026 - String 237.1027 - (let [s ^String x] 237.1028 - (.write writer (.toLowerCase s))) 237.1029 - 237.1030 - Integer 237.1031 - (let [c ^Character x] 237.1032 - (.write writer (int (Character/toLowerCase (char c)))))))))) 237.1033 - 237.1034 -(defn- upcase-writer 237.1035 - "Returns a proxy that wraps writer, converting all characters to upper case" 237.1036 - [^java.io.Writer writer] 237.1037 - (proxy [java.io.Writer] [] 237.1038 - (close [] (.close writer)) 237.1039 - (flush [] (.flush writer)) 237.1040 - (write ([^chars cbuf ^Integer off ^Integer len] 237.1041 - (.write writer cbuf off len)) 237.1042 - ([x] 237.1043 - (condp = (class x) 237.1044 - String 237.1045 - (let [s ^String x] 237.1046 - (.write writer (.toUpperCase s))) 237.1047 - 237.1048 - Integer 237.1049 - (let [c ^Character x] 237.1050 - (.write writer (int (Character/toUpperCase (char c)))))))))) 237.1051 - 237.1052 -(defn- capitalize-string 237.1053 - "Capitalizes the words in a string. If first? is false, don't capitalize the 237.1054 - first character of the string even if it's a letter." 237.1055 - [s first?] 237.1056 - (let [^Character f (first s) 237.1057 - s (if (and first? f (Character/isLetter f)) 237.1058 - (str (Character/toUpperCase f) (subs s 1)) 237.1059 - s)] 237.1060 - (apply str 237.1061 - (first 237.1062 - (consume 237.1063 - (fn [s] 237.1064 - (if (empty? s) 237.1065 - [nil nil] 237.1066 - (let [m (re-matcher #"\W\w" s) 237.1067 - match (re-find m) 237.1068 - offset (and match (inc (.start m)))] 237.1069 - (if offset 237.1070 - [(str (subs s 0 offset) 237.1071 - (Character/toUpperCase ^Character (nth s offset))) 237.1072 - (subs s (inc offset))] 237.1073 - [s nil])))) 237.1074 - s))))) 237.1075 - 237.1076 -(defn- capitalize-word-writer 237.1077 - "Returns a proxy that wraps writer, captializing all words" 237.1078 - [^java.io.Writer writer] 237.1079 - (let [last-was-whitespace? (ref true)] 237.1080 - (proxy [java.io.Writer] [] 237.1081 - (close [] (.close writer)) 237.1082 - (flush [] (.flush writer)) 237.1083 - (write 237.1084 - ([^chars cbuf ^Integer off ^Integer len] 237.1085 - (.write writer cbuf off len)) 237.1086 - ([x] 237.1087 - (condp = (class x) 237.1088 - String 237.1089 - (let [s ^String x] 237.1090 - (.write writer 237.1091 - ^String (capitalize-string (.toLowerCase s) @last-was-whitespace?)) 237.1092 - (dosync 237.1093 - (ref-set last-was-whitespace? 237.1094 - (Character/isWhitespace 237.1095 - ^Character (nth s (dec (count s))))))) 237.1096 - 237.1097 - Integer 237.1098 - (let [c (char x)] 237.1099 - (let [mod-c (if @last-was-whitespace? (Character/toUpperCase ^Character (char x)) c)] 237.1100 - (.write writer (int mod-c)) 237.1101 - (dosync (ref-set last-was-whitespace? (Character/isWhitespace ^Character (char x)))))))))))) 237.1102 - 237.1103 -(defn- init-cap-writer 237.1104 - "Returns a proxy that wraps writer, capitalizing the first word" 237.1105 - [^java.io.Writer writer] 237.1106 - (let [capped (ref false)] 237.1107 - (proxy [java.io.Writer] [] 237.1108 - (close [] (.close writer)) 237.1109 - (flush [] (.flush writer)) 237.1110 - (write ([^chars cbuf ^Integer off ^Integer len] 237.1111 - (.write writer cbuf off len)) 237.1112 - ([x] 237.1113 - (condp = (class x) 237.1114 - String 237.1115 - (let [s (.toLowerCase ^String x)] 237.1116 - (if (not @capped) 237.1117 - (let [m (re-matcher #"\S" s) 237.1118 - match (re-find m) 237.1119 - offset (and match (.start m))] 237.1120 - (if offset 237.1121 - (do (.write writer 237.1122 - (str (subs s 0 offset) 237.1123 - (Character/toUpperCase ^Character (nth s offset)) 237.1124 - (.toLowerCase ^String (subs s (inc offset))))) 237.1125 - (dosync (ref-set capped true))) 237.1126 - (.write writer s))) 237.1127 - (.write writer (.toLowerCase s)))) 237.1128 - 237.1129 - Integer 237.1130 - (let [c ^Character (char x)] 237.1131 - (if (and (not @capped) (Character/isLetter c)) 237.1132 - (do 237.1133 - (dosync (ref-set capped true)) 237.1134 - (.write writer (int (Character/toUpperCase c)))) 237.1135 - (.write writer (int (Character/toLowerCase c))))))))))) 237.1136 - 237.1137 -(defn- modify-case [make-writer params navigator offsets] 237.1138 - (let [clause (first (:clauses params))] 237.1139 - (binding [*out* (make-writer *out*)] 237.1140 - (execute-sub-format clause navigator (:base-args params))))) 237.1141 - 237.1142 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1143 -;;; If necessary, wrap the writer in a PrettyWriter object 237.1144 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1145 - 237.1146 -(defn get-pretty-writer [writer] 237.1147 - (if (pretty-writer? writer) 237.1148 - writer 237.1149 - (pretty-writer writer *print-right-margin* *print-miser-width*))) 237.1150 - 237.1151 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1152 -;;; Support for column-aware operations ~&, ~T 237.1153 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1154 - 237.1155 -;; TODO: make an automatic newline for non-ColumnWriters 237.1156 -(defn fresh-line 237.1157 - "Make a newline if the Writer is not already at the beginning of the line. 237.1158 -N.B. Only works on ColumnWriters right now." 237.1159 - [] 237.1160 - (if (not (= 0 (get-column (:base @@*out*)))) 237.1161 - (prn))) 237.1162 - 237.1163 -(defn- absolute-tabulation [params navigator offsets] 237.1164 - (let [colnum (:colnum params) 237.1165 - colinc (:colinc params) 237.1166 - current (get-column (:base @@*out*)) 237.1167 - space-count (cond 237.1168 - (< current colnum) (- colnum current) 237.1169 - (= colinc 0) 0 237.1170 - :else (- colinc (rem (- current colnum) colinc)))] 237.1171 - (print (apply str (repeat space-count \space)))) 237.1172 - navigator) 237.1173 - 237.1174 -(defn- relative-tabulation [params navigator offsets] 237.1175 - (let [colrel (:colnum params) 237.1176 - colinc (:colinc params) 237.1177 - start-col (+ colrel (get-column (:base @@*out*))) 237.1178 - offset (if (pos? colinc) (rem start-col colinc) 0) 237.1179 - space-count (+ colrel (if (= 0 offset) 0 (- colinc offset)))] 237.1180 - (print (apply str (repeat space-count \space)))) 237.1181 - navigator) 237.1182 - 237.1183 - 237.1184 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1185 -;;; Support for accessing the pretty printer from a format 237.1186 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1187 - 237.1188 -;; TODO: support ~@; per-line-prefix separator 237.1189 -;; TODO: get the whole format wrapped so we can start the lb at any column 237.1190 -(defn- format-logical-block [params navigator offsets] 237.1191 - (let [clauses (:clauses params) 237.1192 - clause-count (count clauses) 237.1193 - prefix (cond 237.1194 - (> clause-count 1) (:string (:params (first (first clauses)))) 237.1195 - (:colon params) "(") 237.1196 - body (nth clauses (if (> clause-count 1) 1 0)) 237.1197 - suffix (cond 237.1198 - (> clause-count 2) (:string (:params (first (nth clauses 2)))) 237.1199 - (:colon params) ")") 237.1200 - [arg navigator] (next-arg navigator)] 237.1201 - (pprint-logical-block :prefix prefix :suffix suffix 237.1202 - (execute-sub-format 237.1203 - body 237.1204 - (init-navigator arg) 237.1205 - (:base-args params))) 237.1206 - navigator)) 237.1207 - 237.1208 -(defn- set-indent [params navigator offsets] 237.1209 - (let [relative-to (if (:colon params) :current :block)] 237.1210 - (pprint-indent relative-to (:n params)) 237.1211 - navigator)) 237.1212 - 237.1213 -;;; TODO: support ~:T section options for ~T 237.1214 - 237.1215 -(defn- conditional-newline [params navigator offsets] 237.1216 - (let [kind (if (:colon params) 237.1217 - (if (:at params) :mandatory :fill) 237.1218 - (if (:at params) :miser :linear))] 237.1219 - (pprint-newline kind) 237.1220 - navigator)) 237.1221 - 237.1222 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1223 -;;; The table of directives we support, each with its params, 237.1224 -;;; properties, and the compilation function 237.1225 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1226 - 237.1227 -;; We start with a couple of helpers 237.1228 -(defn- process-directive-table-element [ [ char params flags bracket-info & generator-fn ] ] 237.1229 - [char, 237.1230 - {:directive char, 237.1231 - :params `(array-map ~@params), 237.1232 - :flags flags, 237.1233 - :bracket-info bracket-info, 237.1234 - :generator-fn (concat '(fn [ params offset]) generator-fn) }]) 237.1235 - 237.1236 -(defmacro ^{:private true} 237.1237 - defdirectives 237.1238 - [ & directives ] 237.1239 - `(def ^{:private true} 237.1240 - directive-table (hash-map ~@(mapcat process-directive-table-element directives)))) 237.1241 - 237.1242 -(defdirectives 237.1243 - (\A 237.1244 - [ :mincol [0 Integer] :colinc [1 Integer] :minpad [0 Integer] :padchar [\space Character] ] 237.1245 - #{ :at :colon :both} {} 237.1246 - #(format-ascii print-str %1 %2 %3)) 237.1247 - 237.1248 - (\S 237.1249 - [ :mincol [0 Integer] :colinc [1 Integer] :minpad [0 Integer] :padchar [\space Character] ] 237.1250 - #{ :at :colon :both} {} 237.1251 - #(format-ascii pr-str %1 %2 %3)) 237.1252 - 237.1253 - (\D 237.1254 - [ :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 237.1255 - :commainterval [ 3 Integer]] 237.1256 - #{ :at :colon :both } {} 237.1257 - #(format-integer 10 %1 %2 %3)) 237.1258 - 237.1259 - (\B 237.1260 - [ :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 237.1261 - :commainterval [ 3 Integer]] 237.1262 - #{ :at :colon :both } {} 237.1263 - #(format-integer 2 %1 %2 %3)) 237.1264 - 237.1265 - (\O 237.1266 - [ :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 237.1267 - :commainterval [ 3 Integer]] 237.1268 - #{ :at :colon :both } {} 237.1269 - #(format-integer 8 %1 %2 %3)) 237.1270 - 237.1271 - (\X 237.1272 - [ :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 237.1273 - :commainterval [ 3 Integer]] 237.1274 - #{ :at :colon :both } {} 237.1275 - #(format-integer 16 %1 %2 %3)) 237.1276 - 237.1277 - (\R 237.1278 - [:base [nil Integer] :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 237.1279 - :commainterval [ 3 Integer]] 237.1280 - #{ :at :colon :both } {} 237.1281 - (do 237.1282 - (cond ; ~R is overloaded with bizareness 237.1283 - (first (:base params)) #(format-integer (:base %1) %1 %2 %3) 237.1284 - (and (:at params) (:colon params)) #(format-old-roman %1 %2 %3) 237.1285 - (:at params) #(format-new-roman %1 %2 %3) 237.1286 - (:colon params) #(format-ordinal-english %1 %2 %3) 237.1287 - true #(format-cardinal-english %1 %2 %3)))) 237.1288 - 237.1289 - (\P 237.1290 - [ ] 237.1291 - #{ :at :colon :both } {} 237.1292 - (fn [params navigator offsets] 237.1293 - (let [navigator (if (:colon params) (relative-reposition navigator -1) navigator) 237.1294 - strs (if (:at params) ["y" "ies"] ["" "s"]) 237.1295 - [arg navigator] (next-arg navigator)] 237.1296 - (print (if (= arg 1) (first strs) (second strs))) 237.1297 - navigator))) 237.1298 - 237.1299 - (\C 237.1300 - [:char-format [nil Character]] 237.1301 - #{ :at :colon :both } {} 237.1302 - (cond 237.1303 - (:colon params) pretty-character 237.1304 - (:at params) readable-character 237.1305 - :else plain-character)) 237.1306 - 237.1307 - (\F 237.1308 - [ :w [nil Integer] :d [nil Integer] :k [0 Integer] :overflowchar [nil Character] 237.1309 - :padchar [\space Character] ] 237.1310 - #{ :at } {} 237.1311 - fixed-float) 237.1312 - 237.1313 - (\E 237.1314 - [ :w [nil Integer] :d [nil Integer] :e [nil Integer] :k [1 Integer] 237.1315 - :overflowchar [nil Character] :padchar [\space Character] 237.1316 - :exponentchar [nil Character] ] 237.1317 - #{ :at } {} 237.1318 - exponential-float) 237.1319 - 237.1320 - (\G 237.1321 - [ :w [nil Integer] :d [nil Integer] :e [nil Integer] :k [1 Integer] 237.1322 - :overflowchar [nil Character] :padchar [\space Character] 237.1323 - :exponentchar [nil Character] ] 237.1324 - #{ :at } {} 237.1325 - general-float) 237.1326 - 237.1327 - (\$ 237.1328 - [ :d [2 Integer] :n [1 Integer] :w [0 Integer] :padchar [\space Character]] 237.1329 - #{ :at :colon :both} {} 237.1330 - dollar-float) 237.1331 - 237.1332 - (\% 237.1333 - [ :count [1 Integer] ] 237.1334 - #{ } {} 237.1335 - (fn [params arg-navigator offsets] 237.1336 - (dotimes [i (:count params)] 237.1337 - (prn)) 237.1338 - arg-navigator)) 237.1339 - 237.1340 - (\& 237.1341 - [ :count [1 Integer] ] 237.1342 - #{ :pretty } {} 237.1343 - (fn [params arg-navigator offsets] 237.1344 - (let [cnt (:count params)] 237.1345 - (if (pos? cnt) (fresh-line)) 237.1346 - (dotimes [i (dec cnt)] 237.1347 - (prn))) 237.1348 - arg-navigator)) 237.1349 - 237.1350 - (\| 237.1351 - [ :count [1 Integer] ] 237.1352 - #{ } {} 237.1353 - (fn [params arg-navigator offsets] 237.1354 - (dotimes [i (:count params)] 237.1355 - (print \formfeed)) 237.1356 - arg-navigator)) 237.1357 - 237.1358 - (\~ 237.1359 - [ :n [1 Integer] ] 237.1360 - #{ } {} 237.1361 - (fn [params arg-navigator offsets] 237.1362 - (let [n (:n params)] 237.1363 - (print (apply str (repeat n \~))) 237.1364 - arg-navigator))) 237.1365 - 237.1366 - (\newline ;; Whitespace supression is handled in the compilation loop 237.1367 - [ ] 237.1368 - #{:colon :at} {} 237.1369 - (fn [params arg-navigator offsets] 237.1370 - (if (:at params) 237.1371 - (prn)) 237.1372 - arg-navigator)) 237.1373 - 237.1374 - (\T 237.1375 - [ :colnum [1 Integer] :colinc [1 Integer] ] 237.1376 - #{ :at :pretty } {} 237.1377 - (if (:at params) 237.1378 - #(relative-tabulation %1 %2 %3) 237.1379 - #(absolute-tabulation %1 %2 %3))) 237.1380 - 237.1381 - (\* 237.1382 - [ :n [1 Integer] ] 237.1383 - #{ :colon :at } {} 237.1384 - (fn [params navigator offsets] 237.1385 - (let [n (:n params)] 237.1386 - (if (:at params) 237.1387 - (absolute-reposition navigator n) 237.1388 - (relative-reposition navigator (if (:colon params) (- n) n))) 237.1389 - ))) 237.1390 - 237.1391 - (\? 237.1392 - [ ] 237.1393 - #{ :at } {} 237.1394 - (if (:at params) 237.1395 - (fn [params navigator offsets] ; args from main arg list 237.1396 - (let [[subformat navigator] (get-format-arg navigator)] 237.1397 - (execute-sub-format subformat navigator (:base-args params)))) 237.1398 - (fn [params navigator offsets] ; args from sub-list 237.1399 - (let [[subformat navigator] (get-format-arg navigator) 237.1400 - [subargs navigator] (next-arg navigator) 237.1401 - sub-navigator (init-navigator subargs)] 237.1402 - (execute-sub-format subformat sub-navigator (:base-args params)) 237.1403 - navigator)))) 237.1404 - 237.1405 - 237.1406 - (\( 237.1407 - [ ] 237.1408 - #{ :colon :at :both} { :right \), :allows-separator nil, :else nil } 237.1409 - (let [mod-case-writer (cond 237.1410 - (and (:at params) (:colon params)) 237.1411 - upcase-writer 237.1412 - 237.1413 - (:colon params) 237.1414 - capitalize-word-writer 237.1415 - 237.1416 - (:at params) 237.1417 - init-cap-writer 237.1418 - 237.1419 - :else 237.1420 - downcase-writer)] 237.1421 - #(modify-case mod-case-writer %1 %2 %3))) 237.1422 - 237.1423 - (\) [] #{} {} nil) 237.1424 - 237.1425 - (\[ 237.1426 - [ :selector [nil Integer] ] 237.1427 - #{ :colon :at } { :right \], :allows-separator true, :else :last } 237.1428 - (cond 237.1429 - (:colon params) 237.1430 - boolean-conditional 237.1431 - 237.1432 - (:at params) 237.1433 - check-arg-conditional 237.1434 - 237.1435 - true 237.1436 - choice-conditional)) 237.1437 - 237.1438 - (\; [:min-remaining [nil Integer] :max-columns [nil Integer]] 237.1439 - #{ :colon } { :separator true } nil) 237.1440 - 237.1441 - (\] [] #{} {} nil) 237.1442 - 237.1443 - (\{ 237.1444 - [ :max-iterations [nil Integer] ] 237.1445 - #{ :colon :at :both} { :right \}, :allows-separator false } 237.1446 - (cond 237.1447 - (and (:at params) (:colon params)) 237.1448 - iterate-main-sublists 237.1449 - 237.1450 - (:colon params) 237.1451 - iterate-list-of-sublists 237.1452 - 237.1453 - (:at params) 237.1454 - iterate-main-list 237.1455 - 237.1456 - true 237.1457 - iterate-sublist)) 237.1458 - 237.1459 - 237.1460 - (\} [] #{:colon} {} nil) 237.1461 - 237.1462 - (\< 237.1463 - [:mincol [0 Integer] :colinc [1 Integer] :minpad [0 Integer] :padchar [\space Character]] 237.1464 - #{:colon :at :both :pretty} { :right \>, :allows-separator true, :else :first } 237.1465 - logical-block-or-justify) 237.1466 - 237.1467 - (\> [] #{:colon} {} nil) 237.1468 - 237.1469 - ;; TODO: detect errors in cases where colon not allowed 237.1470 - (\^ [:arg1 [nil Integer] :arg2 [nil Integer] :arg3 [nil Integer]] 237.1471 - #{:colon} {} 237.1472 - (fn [params navigator offsets] 237.1473 - (let [arg1 (:arg1 params) 237.1474 - arg2 (:arg2 params) 237.1475 - arg3 (:arg3 params) 237.1476 - exit (if (:colon params) :colon-up-arrow :up-arrow)] 237.1477 - (cond 237.1478 - (and arg1 arg2 arg3) 237.1479 - (if (<= arg1 arg2 arg3) [exit navigator] navigator) 237.1480 - 237.1481 - (and arg1 arg2) 237.1482 - (if (= arg1 arg2) [exit navigator] navigator) 237.1483 - 237.1484 - arg1 237.1485 - (if (= arg1 0) [exit navigator] navigator) 237.1486 - 237.1487 - true ; TODO: handle looking up the arglist stack for info 237.1488 - (if (if (:colon params) 237.1489 - (empty? (:rest (:base-args params))) 237.1490 - (empty? (:rest navigator))) 237.1491 - [exit navigator] navigator))))) 237.1492 - 237.1493 - (\W 237.1494 - [] 237.1495 - #{:at :colon :both} {} 237.1496 - (if (or (:at params) (:colon params)) 237.1497 - (let [bindings (concat 237.1498 - (if (:at params) [:level nil :length nil] []) 237.1499 - (if (:colon params) [:pretty true] []))] 237.1500 - (fn [params navigator offsets] 237.1501 - (let [[arg navigator] (next-arg navigator)] 237.1502 - (if (apply write arg bindings) 237.1503 - [:up-arrow navigator] 237.1504 - navigator)))) 237.1505 - (fn [params navigator offsets] 237.1506 - (let [[arg navigator] (next-arg navigator)] 237.1507 - (if (write-out arg) 237.1508 - [:up-arrow navigator] 237.1509 - navigator))))) 237.1510 - 237.1511 - (\_ 237.1512 - [] 237.1513 - #{:at :colon :both} {} 237.1514 - conditional-newline) 237.1515 - 237.1516 - (\I 237.1517 - [:n [0 Integer]] 237.1518 - #{:colon} {} 237.1519 - set-indent) 237.1520 - ) 237.1521 - 237.1522 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1523 -;;; Code to manage the parameters and flags associated with each 237.1524 -;;; directive in the format string. 237.1525 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 237.1526 - 237.1527 -(def ^{:private true} 237.1528 - param-pattern #"^([vV]|#|('.)|([+-]?\d+)|(?=,))") 237.1529 -(def ^{:private true} 237.1530 - special-params #{ :parameter-from-args :remaining-arg-count }) 237.1531 - 237.1532 -(defn- extract-param [[s offset saw-comma]] 237.1533 - (let [m (re-matcher param-pattern s) 237.1534 - param (re-find m)] 237.1535 - (if param 237.1536 - (let [token-str (first (re-groups m)) 237.1537 - remainder (subs s (.end m)) 237.1538 - new-offset (+ offset (.end m))] 237.1539 - (if (not (= \, (nth remainder 0))) 237.1540 - [ [token-str offset] [remainder new-offset false]] 237.1541 - [ [token-str offset] [(subs remainder 1) (inc new-offset) true]])) 237.1542 - (if saw-comma 237.1543 - (format-error "Badly formed parameters in format directive" offset) 237.1544 - [ nil [s offset]])))) 237.1545 - 237.1546 - 237.1547 -(defn- extract-params [s offset] 237.1548 - (consume extract-param [s offset false])) 237.1549 - 237.1550 -(defn- translate-param 237.1551 - "Translate the string representation of a param to the internalized 237.1552 - representation" 237.1553 - [[^String p offset]] 237.1554 - [(cond 237.1555 - (= (.length p) 0) nil 237.1556 - (and (= (.length p) 1) (contains? #{\v \V} (nth p 0))) :parameter-from-args 237.1557 - (and (= (.length p) 1) (= \# (nth p 0))) :remaining-arg-count 237.1558 - (and (= (.length p) 2) (= \' (nth p 0))) (nth p 1) 237.1559 - true (new Integer p)) 237.1560 - offset]) 237.1561 - 237.1562 -(def ^{:private true} 237.1563 - flag-defs { \: :colon, \@ :at }) 237.1564 - 237.1565 -(defn- extract-flags [s offset] 237.1566 - (consume 237.1567 - (fn [[s offset flags]] 237.1568 - (if (empty? s) 237.1569 - [nil [s offset flags]] 237.1570 - (let [flag (get flag-defs (first s))] 237.1571 - (if flag 237.1572 - (if (contains? flags flag) 237.1573 - (format-error 237.1574 - (str "Flag \"" (first s) "\" appears more than once in a directive") 237.1575 - offset) 237.1576 - [true [(subs s 1) (inc offset) (assoc flags flag [true offset])]]) 237.1577 - [nil [s offset flags]])))) 237.1578 - [s offset {}])) 237.1579 - 237.1580 -(defn- check-flags [def flags] 237.1581 - (let [allowed (:flags def)] 237.1582 - (if (and (not (:at allowed)) (:at flags)) 237.1583 - (format-error (str "\"@\" is an illegal flag for format directive \"" (:directive def) "\"") 237.1584 - (nth (:at flags) 1))) 237.1585 - (if (and (not (:colon allowed)) (:colon flags)) 237.1586 - (format-error (str "\":\" is an illegal flag for format directive \"" (:directive def) "\"") 237.1587 - (nth (:colon flags) 1))) 237.1588 - (if (and (not (:both allowed)) (:at flags) (:colon flags)) 237.1589 - (format-error (str "Cannot combine \"@\" and \":\" flags for format directive \"" 237.1590 - (:directive def) "\"") 237.1591 - (min (nth (:colon flags) 1) (nth (:at flags) 1)))))) 237.1592 - 237.1593 -(defn- map-params 237.1594 - "Takes a directive definition and the list of actual parameters and 237.1595 -a map of flags and returns a map of the parameters and flags with defaults 237.1596 -filled in. We check to make sure that there are the right types and number 237.1597 -of parameters as well." 237.1598 - [def params flags offset] 237.1599 - (check-flags def flags) 237.1600 - (if (> (count params) (count (:params def))) 237.1601 - (format-error 237.1602 - (cl-format 237.1603 - nil 237.1604 - "Too many parameters for directive \"~C\": ~D~:* ~[were~;was~:;were~] specified but only ~D~:* ~[are~;is~:;are~] allowed" 237.1605 - (:directive def) (count params) (count (:params def))) 237.1606 - (second (first params)))) 237.1607 - (doall 237.1608 - (map #(let [val (first %1)] 237.1609 - (if (not (or (nil? val) (contains? special-params val) 237.1610 - (instance? (second (second %2)) val))) 237.1611 - (format-error (str "Parameter " (name (first %2)) 237.1612 - " has bad type in directive \"" (:directive def) "\": " 237.1613 - (class val)) 237.1614 - (second %1))) ) 237.1615 - params (:params def))) 237.1616 - 237.1617 - (merge ; create the result map 237.1618 - (into (array-map) ; start with the default values, make sure the order is right 237.1619 - (reverse (for [[name [default]] (:params def)] [name [default offset]]))) 237.1620 - (reduce #(apply assoc %1 %2) {} (filter #(first (nth % 1)) (zipmap (keys (:params def)) params))) ; add the specified parameters, filtering out nils 237.1621 - flags)) ; and finally add the flags 237.1622 - 237.1623 -(defn- compile-directive [s offset] 237.1624 - (let [[raw-params [rest offset]] (extract-params s offset) 237.1625 - [_ [rest offset flags]] (extract-flags rest offset) 237.1626 - directive (first rest) 237.1627 - def (get directive-table (Character/toUpperCase ^Character directive)) 237.1628 - params (if def (map-params def (map translate-param raw-params) flags offset))] 237.1629 - (if (not directive) 237.1630 - (format-error "Format string ended in the middle of a directive" offset)) 237.1631 - (if (not def) 237.1632 - (format-error (str "Directive \"" directive "\" is undefined") offset)) 237.1633 - [(struct compiled-directive ((:generator-fn def) params offset) def params offset) 237.1634 - (let [remainder (subs rest 1) 237.1635 - offset (inc offset) 237.1636 - trim? (and (= \newline (:directive def)) 237.1637 - (not (:colon params))) 237.1638 - trim-count (if trim? (prefix-count remainder [\space \tab]) 0) 237.1639 - remainder (subs remainder trim-count) 237.1640 - offset (+ offset trim-count)] 237.1641 - [remainder offset])])) 237.1642 - 237.1643 -(defn- compile-raw-string [s offset] 237.1644 - (struct compiled-directive (fn [_ a _] (print s) a) nil { :string s } offset)) 237.1645 - 237.1646 -(defn- right-bracket [this] (:right (:bracket-info (:def this)))) 237.1647 -(defn- separator? [this] (:separator (:bracket-info (:def this)))) 237.1648 -(defn- else-separator? [this] 237.1649 - (and (:separator (:bracket-info (:def this))) 237.1650 - (:colon (:params this)))) 237.1651 - 237.1652 - 237.1653 -(declare collect-clauses) 237.1654 - 237.1655 -(defn- process-bracket [this remainder] 237.1656 - (let [[subex remainder] (collect-clauses (:bracket-info (:def this)) 237.1657 - (:offset this) remainder)] 237.1658 - [(struct compiled-directive 237.1659 - (:func this) (:def this) 237.1660 - (merge (:params this) (tuple-map subex (:offset this))) 237.1661 - (:offset this)) 237.1662 - remainder])) 237.1663 - 237.1664 -(defn- process-clause [bracket-info offset remainder] 237.1665 - (consume 237.1666 - (fn [remainder] 237.1667 - (if (empty? remainder) 237.1668 - (format-error "No closing bracket found." offset) 237.1669 - (let [this (first remainder) 237.1670 - remainder (next remainder)] 237.1671 - (cond 237.1672 - (right-bracket this) 237.1673 - (process-bracket this remainder) 237.1674 - 237.1675 - (= (:right bracket-info) (:directive (:def this))) 237.1676 - [ nil [:right-bracket (:params this) nil remainder]] 237.1677 - 237.1678 - (else-separator? this) 237.1679 - [nil [:else nil (:params this) remainder]] 237.1680 - 237.1681 - (separator? this) 237.1682 - [nil [:separator nil nil remainder]] ;; TODO: check to make sure that there are no params on ~; 237.1683 - 237.1684 - true 237.1685 - [this remainder])))) 237.1686 - remainder)) 237.1687 - 237.1688 -(defn- collect-clauses [bracket-info offset remainder] 237.1689 - (second 237.1690 - (consume 237.1691 - (fn [[clause-map saw-else remainder]] 237.1692 - (let [[clause [type right-params else-params remainder]] 237.1693 - (process-clause bracket-info offset remainder)] 237.1694 - (cond 237.1695 - (= type :right-bracket) 237.1696 - [nil [(merge-with concat clause-map 237.1697 - {(if saw-else :else :clauses) [clause] 237.1698 - :right-params right-params}) 237.1699 - remainder]] 237.1700 - 237.1701 - (= type :else) 237.1702 - (cond 237.1703 - (:else clause-map) 237.1704 - (format-error "Two else clauses (\"~:;\") inside bracket construction." offset) 237.1705 - 237.1706 - (not (:else bracket-info)) 237.1707 - (format-error "An else clause (\"~:;\") is in a bracket type that doesn't support it." 237.1708 - offset) 237.1709 - 237.1710 - (and (= :first (:else bracket-info)) (seq (:clauses clause-map))) 237.1711 - (format-error 237.1712 - "The else clause (\"~:;\") is only allowed in the first position for this directive." 237.1713 - offset) 237.1714 - 237.1715 - true ; if the ~:; is in the last position, the else clause 237.1716 - ; is next, this was a regular clause 237.1717 - (if (= :first (:else bracket-info)) 237.1718 - [true [(merge-with concat clause-map { :else [clause] :else-params else-params}) 237.1719 - false remainder]] 237.1720 - [true [(merge-with concat clause-map { :clauses [clause] }) 237.1721 - true remainder]])) 237.1722 - 237.1723 - (= type :separator) 237.1724 - (cond 237.1725 - saw-else 237.1726 - (format-error "A plain clause (with \"~;\") follows an else clause (\"~:;\") inside bracket construction." offset) 237.1727 - 237.1728 - (not (:allows-separator bracket-info)) 237.1729 - (format-error "A separator (\"~;\") is in a bracket type that doesn't support it." 237.1730 - offset) 237.1731 - 237.1732 - true 237.1733 - [true [(merge-with concat clause-map { :clauses [clause] }) 237.1734 - false remainder]])))) 237.1735 - [{ :clauses [] } false remainder]))) 237.1736 - 237.1737 -(defn- process-nesting 237.1738 - "Take a linearly compiled format and process the bracket directives to give it 237.1739 - the appropriate tree structure" 237.1740 - [format] 237.1741 - (first 237.1742 - (consume 237.1743 - (fn [remainder] 237.1744 - (let [this (first remainder) 237.1745 - remainder (next remainder) 237.1746 - bracket (:bracket-info (:def this))] 237.1747 - (if (:right bracket) 237.1748 - (process-bracket this remainder) 237.1749 - [this remainder]))) 237.1750 - format))) 237.1751 - 237.1752 -(defn compile-format 237.1753 - "Compiles format-str into a compiled format which can be used as an argument 237.1754 -to cl-format just like a plain format string. Use this function for improved 237.1755 -performance when you're using the same format string repeatedly" 237.1756 - [ format-str ] 237.1757 -; (prlabel compiling format-str) 237.1758 - (binding [*format-str* format-str] 237.1759 - (process-nesting 237.1760 - (first 237.1761 - (consume 237.1762 - (fn [[^String s offset]] 237.1763 - (if (empty? s) 237.1764 - [nil s] 237.1765 - (let [tilde (.indexOf s (int \~))] 237.1766 - (cond 237.1767 - (neg? tilde) [(compile-raw-string s offset) ["" (+ offset (.length s))]] 237.1768 - (zero? tilde) (compile-directive (subs s 1) (inc offset)) 237.1769 - true 237.1770 - [(compile-raw-string (subs s 0 tilde) offset) [(subs s tilde) (+ tilde offset)]])))) 237.1771 - [format-str 0]))))) 237.1772 - 237.1773 -(defn- needs-pretty 237.1774 - "determine whether a given compiled format has any directives that depend on the 237.1775 -column number or pretty printing" 237.1776 - [format] 237.1777 - (loop [format format] 237.1778 - (if (empty? format) 237.1779 - false 237.1780 - (if (or (:pretty (:flags (:def (first format)))) 237.1781 - (some needs-pretty (first (:clauses (:params (first format))))) 237.1782 - (some needs-pretty (first (:else (:params (first format)))))) 237.1783 - true 237.1784 - (recur (next format)))))) 237.1785 - 237.1786 -(defn execute-format 237.1787 - "Executes the format with the arguments. This should never be used directly, but is public 237.1788 -because the formatter macro uses it." 237.1789 - {:skip-wiki true} 237.1790 - ([stream format args] 237.1791 - (let [^java.io.Writer real-stream (cond 237.1792 - (not stream) (java.io.StringWriter.) 237.1793 - (true? stream) *out* 237.1794 - :else stream) 237.1795 - ^java.io.Writer wrapped-stream (if (and (needs-pretty format) 237.1796 - (not (pretty-writer? real-stream))) 237.1797 - (get-pretty-writer real-stream) 237.1798 - real-stream)] 237.1799 - (binding [*out* wrapped-stream] 237.1800 - (try 237.1801 - (execute-format format args) 237.1802 - (finally 237.1803 - (if-not (identical? real-stream wrapped-stream) 237.1804 - (.flush wrapped-stream)))) 237.1805 - (if (not stream) (.toString real-stream))))) 237.1806 - ([format args] 237.1807 - (map-passing-context 237.1808 - (fn [element context] 237.1809 - (if (abort? context) 237.1810 - [nil context] 237.1811 - (let [[params args] (realize-parameter-list 237.1812 - (:params element) context) 237.1813 - [params offsets] (unzip-map params) 237.1814 - params (assoc params :base-args args)] 237.1815 - [nil (apply (:func element) [params args offsets])]))) 237.1816 - args 237.1817 - format))) 237.1818 - 237.1819 - 237.1820 -(defmacro formatter 237.1821 - "Makes a function which can directly run format-in. The function is 237.1822 -fn [stream & args] ... and returns nil unless the stream is nil (meaning 237.1823 -output to a string) in which case it returns the resulting string. 237.1824 - 237.1825 -format-in can be either a control string or a previously compiled format." 237.1826 - [format-in] 237.1827 - (let [cf (gensym "compiled-format")] 237.1828 - `(let [format-in# ~format-in] 237.1829 - (do (defonce ~cf (if (string? format-in#) (compile-format format-in#) format-in#)) 237.1830 - (fn [stream# & args#] 237.1831 - (let [navigator# (init-navigator args#)] 237.1832 - (execute-format stream# ~cf navigator#))))))) 237.1833 - 237.1834 -(defmacro formatter-out 237.1835 - "Makes a function which can directly run format-in. The function is 237.1836 -fn [& args] ... and returns nil. This version of the formatter macro is 237.1837 -designed to be used with *out* set to an appropriate Writer. In particular, 237.1838 -this is meant to be used as part of a pretty printer dispatch method. 237.1839 - 237.1840 -format-in can be either a control string or a previously compiled format." 237.1841 - [format-in] 237.1842 - (let [cf (gensym "compiled-format")] 237.1843 - `(let [format-in# ~format-in] 237.1844 - (do (defonce ~cf (if (string? format-in#) (compile-format format-in#) format-in#)) 237.1845 - (fn [& args#] 237.1846 - (let [navigator# (init-navigator args#)] 237.1847 - (execute-format ~cf navigator#)))))))
238.1 --- a/src/clojure/contrib/pprint/column_writer.clj Sat Aug 21 06:25:44 2010 -0400 238.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 238.3 @@ -1,80 +0,0 @@ 238.4 -;;; column_writer.clj -- part of the pretty printer for Clojure 238.5 - 238.6 -;; by Tom Faulhaber 238.7 -;; April 3, 2009 238.8 -;; Revised to use proxy instead of gen-class April 2010 238.9 - 238.10 -; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. 238.11 -; The use and distribution terms for this software are covered by the 238.12 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 238.13 -; which can be found in the file epl-v10.html at the root of this distribution. 238.14 -; By using this software in any fashion, you are agreeing to be bound by 238.15 -; the terms of this license. 238.16 -; You must not remove this notice, or any other, from this software. 238.17 - 238.18 -;; This module implements a column-aware wrapper around an instance of java.io.Writer 238.19 - 238.20 -(ns clojure.contrib.pprint.column-writer 238.21 - (:import 238.22 - [clojure.lang IDeref] 238.23 - [java.io Writer])) 238.24 - 238.25 -(def *default-page-width* 72) 238.26 - 238.27 -(defn- get-field [^Writer this sym] 238.28 - (sym @@this)) 238.29 - 238.30 -(defn- set-field [^Writer this sym new-val] 238.31 - (alter @this assoc sym new-val)) 238.32 - 238.33 -(defn get-column [this] 238.34 - (get-field this :cur)) 238.35 - 238.36 -(defn get-line [this] 238.37 - (get-field this :line)) 238.38 - 238.39 -(defn get-max-column [this] 238.40 - (get-field this :max)) 238.41 - 238.42 -(defn set-max-column [this new-max] 238.43 - (dosync (set-field this :max new-max)) 238.44 - nil) 238.45 - 238.46 -(defn get-writer [this] 238.47 - (get-field this :base)) 238.48 - 238.49 -(defn- write-char [^Writer this ^Integer c] 238.50 - (dosync (if (= c (int \newline)) 238.51 - (do 238.52 - (set-field this :cur 0) 238.53 - (set-field this :line (inc (get-field this :line)))) 238.54 - (set-field this :cur (inc (get-field this :cur))))) 238.55 - (.write ^Writer (get-field this :base) c)) 238.56 - 238.57 -(defn column-writer 238.58 - ([writer] (column-writer writer *default-page-width*)) 238.59 - ([writer max-columns] 238.60 - (let [fields (ref {:max max-columns, :cur 0, :line 0 :base writer})] 238.61 - (proxy [Writer IDeref] [] 238.62 - (deref [] fields) 238.63 - (write 238.64 - ([^chars cbuf ^Integer off ^Integer len] 238.65 - (let [^Writer writer (get-field this :base)] 238.66 - (.write writer cbuf off len))) 238.67 - ([x] 238.68 - (condp = (class x) 238.69 - String 238.70 - (let [^String s x 238.71 - nl (.lastIndexOf s (int \newline))] 238.72 - (dosync (if (neg? nl) 238.73 - (set-field this :cur (+ (get-field this :cur) (count s))) 238.74 - (do 238.75 - (set-field this :cur (- (count s) nl 1)) 238.76 - (set-field this :line (+ (get-field this :line) 238.77 - (count (filter #(= % \newline) s))))))) 238.78 - (.write ^Writer (get-field this :base) s)) 238.79 - 238.80 - Integer 238.81 - (write-char this x) 238.82 - Long 238.83 - (write-char this x))))))))
239.1 --- a/src/clojure/contrib/pprint/dispatch.clj Sat Aug 21 06:25:44 2010 -0400 239.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 239.3 @@ -1,447 +0,0 @@ 239.4 -;; dispatch.clj -- part of the pretty printer for Clojure 239.5 - 239.6 -;; by Tom Faulhaber 239.7 -;; April 3, 2009 239.8 - 239.9 -; Copyright (c) Tom Faulhaber, Feb 2009. All rights reserved. 239.10 -; The use and distribution terms for this software are covered by the 239.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 239.12 -; which can be found in the file epl-v10.html at the root of this distribution. 239.13 -; By using this software in any fashion, you are agreeing to be bound by 239.14 -; the terms of this license. 239.15 -; You must not remove this notice, or any other, from this software. 239.16 - 239.17 -;; This module implements the default dispatch tables for pretty printing code and 239.18 -;; data. 239.19 - 239.20 -(in-ns 'clojure.contrib.pprint) 239.21 - 239.22 -(defn use-method 239.23 - "Installs a function as a new method of multimethod associated with dispatch-value. " 239.24 - [multifn dispatch-val func] 239.25 - (. multifn addMethod dispatch-val func)) 239.26 - 239.27 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.28 -;; Implementations of specific dispatch table entries 239.29 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.30 - 239.31 -;;; Handle forms that can be "back-translated" to reader macros 239.32 -;;; Not all reader macros can be dealt with this way or at all. 239.33 -;;; Macros that we can't deal with at all are: 239.34 -;;; ; - The comment character is aborbed by the reader and never is part of the form 239.35 -;;; ` - Is fully processed at read time into a lisp expression (which will contain concats 239.36 -;;; and regular quotes). 239.37 -;;; ~@ - Also fully eaten by the processing of ` and can't be used outside. 239.38 -;;; , - is whitespace and is lost (like all other whitespace). Formats can generate commas 239.39 -;;; where they deem them useful to help readability. 239.40 -;;; ^ - Adding metadata completely disappears at read time and the data appears to be 239.41 -;;; completely lost. 239.42 -;;; 239.43 -;;; Most other syntax stuff is dealt with directly by the formats (like (), [], {}, and #{}) 239.44 -;;; or directly by printing the objects using Clojure's built-in print functions (like 239.45 -;;; :keyword, \char, or ""). The notable exception is #() which is special-cased. 239.46 - 239.47 -(def reader-macros 239.48 - {'quote "'", 'clojure.core/deref "@", 239.49 - 'var "#'", 'clojure.core/unquote "~"}) 239.50 - 239.51 -(defn pprint-reader-macro [alis] 239.52 - (let [^String macro-char (reader-macros (first alis))] 239.53 - (when (and macro-char (= 2 (count alis))) 239.54 - (.write ^java.io.Writer *out* macro-char) 239.55 - (write-out (second alis)) 239.56 - true))) 239.57 - 239.58 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.59 -;; Dispatch for the basic data types when interpreted 239.60 -;; as data (as opposed to code). 239.61 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.62 - 239.63 -;;; TODO: inline these formatter statements into funcs so that we 239.64 -;;; are a little easier on the stack. (Or, do "real" compilation, a 239.65 -;;; la Common Lisp) 239.66 - 239.67 -;;; (def pprint-simple-list (formatter-out "~:<~@{~w~^ ~_~}~:>")) 239.68 -(defn pprint-simple-list [alis] 239.69 - (pprint-logical-block :prefix "(" :suffix ")" 239.70 - (loop [alis (seq alis)] 239.71 - (when alis 239.72 - (write-out (first alis)) 239.73 - (when (next alis) 239.74 - (.write ^java.io.Writer *out* " ") 239.75 - (pprint-newline :linear) 239.76 - (recur (next alis))))))) 239.77 - 239.78 -(defn pprint-list [alis] 239.79 - (if-not (pprint-reader-macro alis) 239.80 - (pprint-simple-list alis))) 239.81 - 239.82 -;;; (def pprint-vector (formatter-out "~<[~;~@{~w~^ ~_~}~;]~:>")) 239.83 -(defn pprint-vector [avec] 239.84 - (pprint-logical-block :prefix "[" :suffix "]" 239.85 - (loop [aseq (seq avec)] 239.86 - (when aseq 239.87 - (write-out (first aseq)) 239.88 - (when (next aseq) 239.89 - (.write ^java.io.Writer *out* " ") 239.90 - (pprint-newline :linear) 239.91 - (recur (next aseq))))))) 239.92 - 239.93 -(def pprint-array (formatter-out "~<[~;~@{~w~^, ~:_~}~;]~:>")) 239.94 - 239.95 -;;; (def pprint-map (formatter-out "~<{~;~@{~<~w~^ ~_~w~:>~^, ~_~}~;}~:>")) 239.96 -(defn pprint-map [amap] 239.97 - (pprint-logical-block :prefix "{" :suffix "}" 239.98 - (loop [aseq (seq amap)] 239.99 - (when aseq 239.100 - (pprint-logical-block 239.101 - (write-out (ffirst aseq)) 239.102 - (.write ^java.io.Writer *out* " ") 239.103 - (pprint-newline :linear) 239.104 - (write-out (fnext (first aseq)))) 239.105 - (when (next aseq) 239.106 - (.write ^java.io.Writer *out* ", ") 239.107 - (pprint-newline :linear) 239.108 - (recur (next aseq))))))) 239.109 - 239.110 -(def pprint-set (formatter-out "~<#{~;~@{~w~^ ~:_~}~;}~:>")) 239.111 -(defn pprint-ref [ref] 239.112 - (pprint-logical-block :prefix "#<Ref " :suffix ">" 239.113 - (write-out @ref))) 239.114 -(defn pprint-atom [ref] 239.115 - (pprint-logical-block :prefix "#<Atom " :suffix ">" 239.116 - (write-out @ref))) 239.117 -(defn pprint-agent [ref] 239.118 - (pprint-logical-block :prefix "#<Agent " :suffix ">" 239.119 - (write-out @ref))) 239.120 - 239.121 -(defn pprint-simple-default [obj] 239.122 - (cond 239.123 - (.isArray (class obj)) (pprint-array obj) 239.124 - (and *print-suppress-namespaces* (symbol? obj)) (print (name obj)) 239.125 - :else (pr obj))) 239.126 - 239.127 - 239.128 -(defmulti 239.129 - *simple-dispatch* 239.130 - "The pretty print dispatch function for simple data structure format." 239.131 - {:arglists '[[object]]} 239.132 - class) 239.133 - 239.134 -(use-method *simple-dispatch* clojure.lang.ISeq pprint-list) 239.135 -(use-method *simple-dispatch* clojure.lang.IPersistentVector pprint-vector) 239.136 -(use-method *simple-dispatch* clojure.lang.IPersistentMap pprint-map) 239.137 -(use-method *simple-dispatch* clojure.lang.IPersistentSet pprint-set) 239.138 -(use-method *simple-dispatch* clojure.lang.Ref pprint-ref) 239.139 -(use-method *simple-dispatch* clojure.lang.Atom pprint-atom) 239.140 -(use-method *simple-dispatch* clojure.lang.Agent pprint-agent) 239.141 -(use-method *simple-dispatch* nil pr) 239.142 -(use-method *simple-dispatch* :default pprint-simple-default) 239.143 - 239.144 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.145 -;;; Dispatch for the code table 239.146 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.147 - 239.148 -(declare pprint-simple-code-list) 239.149 - 239.150 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.151 -;;; Format something that looks like a simple def (sans metadata, since the reader 239.152 -;;; won't give it to us now). 239.153 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.154 - 239.155 -(def pprint-hold-first (formatter-out "~:<~w~^ ~@_~w~^ ~_~@{~w~^ ~_~}~:>")) 239.156 - 239.157 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.158 -;;; Format something that looks like a defn or defmacro 239.159 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.160 - 239.161 -;;; Format the params and body of a defn with a single arity 239.162 -(defn- single-defn [alis has-doc-str?] 239.163 - (if (seq alis) 239.164 - (do 239.165 - (if has-doc-str? 239.166 - ((formatter-out " ~_")) 239.167 - ((formatter-out " ~@_"))) 239.168 - ((formatter-out "~{~w~^ ~_~}") alis)))) 239.169 - 239.170 -;;; Format the param and body sublists of a defn with multiple arities 239.171 -(defn- multi-defn [alis has-doc-str?] 239.172 - (if (seq alis) 239.173 - ((formatter-out " ~_~{~w~^ ~_~}") alis))) 239.174 - 239.175 -;;; TODO: figure out how to support capturing metadata in defns (we might need a 239.176 -;;; special reader) 239.177 -(defn pprint-defn [alis] 239.178 - (if (next alis) 239.179 - (let [[defn-sym defn-name & stuff] alis 239.180 - [doc-str stuff] (if (string? (first stuff)) 239.181 - [(first stuff) (next stuff)] 239.182 - [nil stuff]) 239.183 - [attr-map stuff] (if (map? (first stuff)) 239.184 - [(first stuff) (next stuff)] 239.185 - [nil stuff])] 239.186 - (pprint-logical-block :prefix "(" :suffix ")" 239.187 - ((formatter-out "~w ~1I~@_~w") defn-sym defn-name) 239.188 - (if doc-str 239.189 - ((formatter-out " ~_~w") doc-str)) 239.190 - (if attr-map 239.191 - ((formatter-out " ~_~w") attr-map)) 239.192 - ;; Note: the multi-defn case will work OK for malformed defns too 239.193 - (cond 239.194 - (vector? (first stuff)) (single-defn stuff (or doc-str attr-map)) 239.195 - :else (multi-defn stuff (or doc-str attr-map))))) 239.196 - (pprint-simple-code-list alis))) 239.197 - 239.198 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.199 -;;; Format something with a binding form 239.200 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.201 - 239.202 -(defn pprint-binding-form [binding-vec] 239.203 - (pprint-logical-block :prefix "[" :suffix "]" 239.204 - (loop [binding binding-vec] 239.205 - (when (seq binding) 239.206 - (pprint-logical-block binding 239.207 - (write-out (first binding)) 239.208 - (when (next binding) 239.209 - (.write ^java.io.Writer *out* " ") 239.210 - (pprint-newline :miser) 239.211 - (write-out (second binding)))) 239.212 - (when (next (rest binding)) 239.213 - (.write ^java.io.Writer *out* " ") 239.214 - (pprint-newline :linear) 239.215 - (recur (next (rest binding)))))))) 239.216 - 239.217 -(defn pprint-let [alis] 239.218 - (let [base-sym (first alis)] 239.219 - (pprint-logical-block :prefix "(" :suffix ")" 239.220 - (if (and (next alis) (vector? (second alis))) 239.221 - (do 239.222 - ((formatter-out "~w ~1I~@_") base-sym) 239.223 - (pprint-binding-form (second alis)) 239.224 - ((formatter-out " ~_~{~w~^ ~_~}") (next (rest alis)))) 239.225 - (pprint-simple-code-list alis))))) 239.226 - 239.227 - 239.228 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.229 -;;; Format something that looks like "if" 239.230 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.231 - 239.232 -(def pprint-if (formatter-out "~:<~1I~w~^ ~@_~w~@{ ~_~w~}~:>")) 239.233 - 239.234 -(defn pprint-cond [alis] 239.235 - (pprint-logical-block :prefix "(" :suffix ")" 239.236 - (pprint-indent :block 1) 239.237 - (write-out (first alis)) 239.238 - (when (next alis) 239.239 - (.write ^java.io.Writer *out* " ") 239.240 - (pprint-newline :linear) 239.241 - (loop [alis (next alis)] 239.242 - (when alis 239.243 - (pprint-logical-block alis 239.244 - (write-out (first alis)) 239.245 - (when (next alis) 239.246 - (.write ^java.io.Writer *out* " ") 239.247 - (pprint-newline :miser) 239.248 - (write-out (second alis)))) 239.249 - (when (next (rest alis)) 239.250 - (.write ^java.io.Writer *out* " ") 239.251 - (pprint-newline :linear) 239.252 - (recur (next (rest alis))))))))) 239.253 - 239.254 -(defn pprint-condp [alis] 239.255 - (if (> (count alis) 3) 239.256 - (pprint-logical-block :prefix "(" :suffix ")" 239.257 - (pprint-indent :block 1) 239.258 - (apply (formatter-out "~w ~@_~w ~@_~w ~_") alis) 239.259 - (loop [alis (seq (drop 3 alis))] 239.260 - (when alis 239.261 - (pprint-logical-block alis 239.262 - (write-out (first alis)) 239.263 - (when (next alis) 239.264 - (.write ^java.io.Writer *out* " ") 239.265 - (pprint-newline :miser) 239.266 - (write-out (second alis)))) 239.267 - (when (next (rest alis)) 239.268 - (.write ^java.io.Writer *out* " ") 239.269 - (pprint-newline :linear) 239.270 - (recur (next (rest alis))))))) 239.271 - (pprint-simple-code-list alis))) 239.272 - 239.273 -;;; The map of symbols that are defined in an enclosing #() anonymous function 239.274 -(def *symbol-map* {}) 239.275 - 239.276 -(defn pprint-anon-func [alis] 239.277 - (let [args (second alis) 239.278 - nlis (first (rest (rest alis)))] 239.279 - (if (vector? args) 239.280 - (binding [*symbol-map* (if (= 1 (count args)) 239.281 - {(first args) "%"} 239.282 - (into {} 239.283 - (map 239.284 - #(vector %1 (str \% %2)) 239.285 - args 239.286 - (range 1 (inc (count args))))))] 239.287 - ((formatter-out "~<#(~;~@{~w~^ ~_~}~;)~:>") nlis)) 239.288 - (pprint-simple-code-list alis)))) 239.289 - 239.290 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.291 -;;; The master definitions for formatting lists in code (that is, (fn args...) or 239.292 -;;; special forms). 239.293 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 239.294 - 239.295 -;;; This is the equivalent of (formatter-out "~:<~1I~@{~w~^ ~_~}~:>"), but is 239.296 -;;; easier on the stack. 239.297 - 239.298 -(defn pprint-simple-code-list [alis] 239.299 - (pprint-logical-block :prefix "(" :suffix ")" 239.300 - (pprint-indent :block 1) 239.301 - (loop [alis (seq alis)] 239.302 - (when alis 239.303 - (write-out (first alis)) 239.304 - (when (next alis) 239.305 - (.write ^java.io.Writer *out* " ") 239.306 - (pprint-newline :linear) 239.307 - (recur (next alis))))))) 239.308 - 239.309 -;;; Take a map with symbols as keys and add versions with no namespace. 239.310 -;;; That is, if ns/sym->val is in the map, add sym->val to the result. 239.311 -(defn two-forms [amap] 239.312 - (into {} 239.313 - (mapcat 239.314 - identity 239.315 - (for [x amap] 239.316 - [x [(symbol (name (first x))) (second x)]])))) 239.317 - 239.318 -(defn add-core-ns [amap] 239.319 - (let [core "clojure.core"] 239.320 - (into {} 239.321 - (map #(let [[s f] %] 239.322 - (if (not (or (namespace s) (special-symbol? s))) 239.323 - [(symbol core (name s)) f] 239.324 - %)) 239.325 - amap)))) 239.326 - 239.327 -(def *code-table* 239.328 - (two-forms 239.329 - (add-core-ns 239.330 - {'def pprint-hold-first, 'defonce pprint-hold-first, 239.331 - 'defn pprint-defn, 'defn- pprint-defn, 'defmacro pprint-defn, 'fn pprint-defn, 239.332 - 'let pprint-let, 'loop pprint-let, 'binding pprint-let, 239.333 - 'with-local-vars pprint-let, 'with-open pprint-let, 'when-let pprint-let, 239.334 - 'if-let pprint-let, 'doseq pprint-let, 'dotimes pprint-let, 239.335 - 'when-first pprint-let, 239.336 - 'if pprint-if, 'if-not pprint-if, 'when pprint-if, 'when-not pprint-if, 239.337 - 'cond pprint-cond, 'condp pprint-condp, 239.338 - 'fn* pprint-anon-func, 239.339 - '. pprint-hold-first, '.. pprint-hold-first, '-> pprint-hold-first, 239.340 - 'locking pprint-hold-first, 'struct pprint-hold-first, 239.341 - 'struct-map pprint-hold-first, 239.342 - }))) 239.343 - 239.344 -(defn pprint-code-list [alis] 239.345 - (if-not (pprint-reader-macro alis) 239.346 - (if-let [special-form (*code-table* (first alis))] 239.347 - (special-form alis) 239.348 - (pprint-simple-code-list alis)))) 239.349 - 239.350 -(defn pprint-code-symbol [sym] 239.351 - (if-let [arg-num (sym *symbol-map*)] 239.352 - (print arg-num) 239.353 - (if *print-suppress-namespaces* 239.354 - (print (name sym)) 239.355 - (pr sym)))) 239.356 - 239.357 -(defmulti 239.358 - *code-dispatch* 239.359 - "The pretty print dispatch function for pretty printing Clojure code." 239.360 - {:arglists '[[object]]} 239.361 - class) 239.362 - 239.363 -(use-method *code-dispatch* clojure.lang.ISeq pprint-code-list) 239.364 -(use-method *code-dispatch* clojure.lang.Symbol pprint-code-symbol) 239.365 - 239.366 -;; The following are all exact copies of *simple-dispatch* 239.367 -(use-method *code-dispatch* clojure.lang.IPersistentVector pprint-vector) 239.368 -(use-method *code-dispatch* clojure.lang.IPersistentMap pprint-map) 239.369 -(use-method *code-dispatch* clojure.lang.IPersistentSet pprint-set) 239.370 -(use-method *code-dispatch* clojure.lang.Ref pprint-ref) 239.371 -(use-method *code-dispatch* clojure.lang.Atom pprint-atom) 239.372 -(use-method *code-dispatch* clojure.lang.Agent pprint-agent) 239.373 -(use-method *code-dispatch* nil pr) 239.374 -(use-method *code-dispatch* :default pprint-simple-default) 239.375 - 239.376 -(set-pprint-dispatch *simple-dispatch*) 239.377 - 239.378 - 239.379 -;;; For testing 239.380 -(comment 239.381 - 239.382 -(with-pprint-dispatch *code-dispatch* 239.383 - (pprint 239.384 - '(defn cl-format 239.385 - "An implementation of a Common Lisp compatible format function" 239.386 - [stream format-in & args] 239.387 - (let [compiled-format (if (string? format-in) (compile-format format-in) format-in) 239.388 - navigator (init-navigator args)] 239.389 - (execute-format stream compiled-format navigator))))) 239.390 - 239.391 -(with-pprint-dispatch *code-dispatch* 239.392 - (pprint 239.393 - '(defn cl-format 239.394 - [stream format-in & args] 239.395 - (let [compiled-format (if (string? format-in) (compile-format format-in) format-in) 239.396 - navigator (init-navigator args)] 239.397 - (execute-format stream compiled-format navigator))))) 239.398 - 239.399 -(with-pprint-dispatch *code-dispatch* 239.400 - (pprint 239.401 - '(defn- -write 239.402 - ([this x] 239.403 - (condp = (class x) 239.404 - String 239.405 - (let [s0 (write-initial-lines this x) 239.406 - s (.replaceFirst s0 "\\s+$" "") 239.407 - white-space (.substring s0 (count s)) 239.408 - mode (getf :mode)] 239.409 - (if (= mode :writing) 239.410 - (dosync 239.411 - (write-white-space this) 239.412 - (.col_write this s) 239.413 - (setf :trailing-white-space white-space)) 239.414 - (add-to-buffer this (make-buffer-blob s white-space)))) 239.415 - 239.416 - Integer 239.417 - (let [c ^Character x] 239.418 - (if (= (getf :mode) :writing) 239.419 - (do 239.420 - (write-white-space this) 239.421 - (.col_write this x)) 239.422 - (if (= c (int \newline)) 239.423 - (write-initial-lines this "\n") 239.424 - (add-to-buffer this (make-buffer-blob (str (char c)) nil)))))))))) 239.425 - 239.426 -(with-pprint-dispatch *code-dispatch* 239.427 - (pprint 239.428 - '(defn pprint-defn [writer alis] 239.429 - (if (next alis) 239.430 - (let [[defn-sym defn-name & stuff] alis 239.431 - [doc-str stuff] (if (string? (first stuff)) 239.432 - [(first stuff) (next stuff)] 239.433 - [nil stuff]) 239.434 - [attr-map stuff] (if (map? (first stuff)) 239.435 - [(first stuff) (next stuff)] 239.436 - [nil stuff])] 239.437 - (pprint-logical-block writer :prefix "(" :suffix ")" 239.438 - (cl-format true "~w ~1I~@_~w" defn-sym defn-name) 239.439 - (if doc-str 239.440 - (cl-format true " ~_~w" doc-str)) 239.441 - (if attr-map 239.442 - (cl-format true " ~_~w" attr-map)) 239.443 - ;; Note: the multi-defn case will work OK for malformed defns too 239.444 - (cond 239.445 - (vector? (first stuff)) (single-defn stuff (or doc-str attr-map)) 239.446 - :else (multi-defn stuff (or doc-str attr-map))))) 239.447 - (pprint-simple-code-list writer alis))))) 239.448 -) 239.449 -nil 239.450 -
240.1 --- a/src/clojure/contrib/pprint/pprint_base.clj Sat Aug 21 06:25:44 2010 -0400 240.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 240.3 @@ -1,342 +0,0 @@ 240.4 -;;; pprint_base.clj -- part of the pretty printer for Clojure 240.5 - 240.6 -;; by Tom Faulhaber 240.7 -;; April 3, 2009 240.8 - 240.9 -; Copyright (c) Tom Faulhaber, Jan 2009. All rights reserved. 240.10 -; The use and distribution terms for this software are covered by the 240.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 240.12 -; which can be found in the file epl-v10.html at the root of this distribution. 240.13 -; By using this software in any fashion, you are agreeing to be bound by 240.14 -; the terms of this license. 240.15 -; You must not remove this notice, or any other, from this software. 240.16 - 240.17 -;; This module implements the generic pretty print functions and special variables 240.18 - 240.19 -(in-ns 'clojure.contrib.pprint) 240.20 - 240.21 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 240.22 -;; Variables that control the pretty printer 240.23 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 240.24 - 240.25 -;;; 240.26 -;;; *print-length*, *print-level* and *print-dup* are defined in clojure.core 240.27 -;;; TODO: use *print-dup* here (or is it supplanted by other variables?) 240.28 -;;; TODO: make dispatch items like "(let..." get counted in *print-length* 240.29 -;;; constructs 240.30 - 240.31 - 240.32 -(def 240.33 - ^{ :doc "Bind to true if you want write to use pretty printing"} 240.34 - *print-pretty* true) 240.35 - 240.36 -(defonce ; If folks have added stuff here, don't overwrite 240.37 - ^{ :doc "The pretty print dispatch function. Use with-pprint-dispatch or set-pprint-dispatch 240.38 -to modify."} 240.39 - *print-pprint-dispatch* nil) 240.40 - 240.41 -(def 240.42 - ^{ :doc "Pretty printing will try to avoid anything going beyond this column. 240.43 -Set it to nil to have pprint let the line be arbitrarily long. This will ignore all 240.44 -non-mandatory newlines."} 240.45 - *print-right-margin* 72) 240.46 - 240.47 -(def 240.48 - ^{ :doc "The column at which to enter miser style. Depending on the dispatch table, 240.49 -miser style add newlines in more places to try to keep lines short allowing for further 240.50 -levels of nesting."} 240.51 - *print-miser-width* 40) 240.52 - 240.53 -;;; TODO implement output limiting 240.54 -(def 240.55 - ^{ :doc "Maximum number of lines to print in a pretty print instance (N.B. This is not yet used)"} 240.56 - *print-lines* nil) 240.57 - 240.58 -;;; TODO: implement circle and shared 240.59 -(def 240.60 - ^{ :doc "Mark circular structures (N.B. This is not yet used)"} 240.61 - *print-circle* nil) 240.62 - 240.63 -;;; TODO: should we just use *print-dup* here? 240.64 -(def 240.65 - ^{ :doc "Mark repeated structures rather than repeat them (N.B. This is not yet used)"} 240.66 - *print-shared* nil) 240.67 - 240.68 -(def 240.69 - ^{ :doc "Don't print namespaces with symbols. This is particularly useful when 240.70 -pretty printing the results of macro expansions"} 240.71 - *print-suppress-namespaces* nil) 240.72 - 240.73 -;;; TODO: support print-base and print-radix in cl-format 240.74 -;;; TODO: support print-base and print-radix in rationals 240.75 -(def 240.76 - ^{ :doc "Print a radix specifier in front of integers and rationals. If *print-base* is 2, 8, 240.77 -or 16, then the radix specifier used is #b, #o, or #x, respectively. Otherwise the 240.78 -radix specifier is in the form #XXr where XX is the decimal value of *print-base* "} 240.79 - *print-radix* nil) 240.80 - 240.81 -(def 240.82 - ^{ :doc "The base to use for printing integers and rationals."} 240.83 - *print-base* 10) 240.84 - 240.85 - 240.86 - 240.87 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 240.88 -;; Internal variables that keep track of where we are in the 240.89 -;; structure 240.90 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 240.91 - 240.92 -(def ^{ :private true } *current-level* 0) 240.93 - 240.94 -(def ^{ :private true } *current-length* nil) 240.95 - 240.96 -;; TODO: add variables for length, lines. 240.97 - 240.98 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 240.99 -;; Support for the write function 240.100 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 240.101 - 240.102 -(declare format-simple-number) 240.103 - 240.104 -(def ^{:private true} orig-pr pr) 240.105 - 240.106 -(defn- pr-with-base [x] 240.107 - (if-let [s (format-simple-number x)] 240.108 - (print s) 240.109 - (orig-pr x))) 240.110 - 240.111 -(def ^{:private true} write-option-table 240.112 - {;:array *print-array* 240.113 - :base 'clojure.contrib.pprint/*print-base*, 240.114 - ;;:case *print-case*, 240.115 - :circle 'clojure.contrib.pprint/*print-circle*, 240.116 - ;;:escape *print-escape*, 240.117 - ;;:gensym *print-gensym*, 240.118 - :length 'clojure.core/*print-length*, 240.119 - :level 'clojure.core/*print-level*, 240.120 - :lines 'clojure.contrib.pprint/*print-lines*, 240.121 - :miser-width 'clojure.contrib.pprint/*print-miser-width*, 240.122 - :dispatch 'clojure.contrib.pprint/*print-pprint-dispatch*, 240.123 - :pretty 'clojure.contrib.pprint/*print-pretty*, 240.124 - :radix 'clojure.contrib.pprint/*print-radix*, 240.125 - :readably 'clojure.core/*print-readably*, 240.126 - :right-margin 'clojure.contrib.pprint/*print-right-margin*, 240.127 - :suppress-namespaces 'clojure.contrib.pprint/*print-suppress-namespaces*}) 240.128 - 240.129 - 240.130 -(defmacro ^{:private true} binding-map [amap & body] 240.131 - (let [] 240.132 - `(do 240.133 - (. clojure.lang.Var (pushThreadBindings ~amap)) 240.134 - (try 240.135 - ~@body 240.136 - (finally 240.137 - (. clojure.lang.Var (popThreadBindings))))))) 240.138 - 240.139 -(defn- table-ize [t m] 240.140 - (apply hash-map (mapcat 240.141 - #(when-let [v (get t (key %))] [(find-var v) (val %)]) 240.142 - m))) 240.143 - 240.144 -(defn- pretty-writer? 240.145 - "Return true iff x is a PrettyWriter" 240.146 - [x] (and (instance? clojure.lang.IDeref x) (:pretty-writer @@x))) 240.147 - 240.148 -(defn- make-pretty-writer 240.149 - "Wrap base-writer in a PrettyWriter with the specified right-margin and miser-width" 240.150 - [base-writer right-margin miser-width] 240.151 - (pretty-writer base-writer right-margin miser-width)) 240.152 - 240.153 -(defmacro ^{:private true} with-pretty-writer [base-writer & body] 240.154 - `(let [base-writer# ~base-writer 240.155 - new-writer# (not (pretty-writer? base-writer#))] 240.156 - (binding [*out* (if new-writer# 240.157 - (make-pretty-writer base-writer# *print-right-margin* *print-miser-width*) 240.158 - base-writer#)] 240.159 - ~@body 240.160 - (.flush *out*)))) 240.161 - 240.162 - 240.163 -;;;TODO: if pretty print is not set, don't use pr but rather something that respects *print-base*, etc. 240.164 -(defn write-out 240.165 - "Write an object to *out* subject to the current bindings of the printer control 240.166 -variables. Use the kw-args argument to override individual variables for this call (and 240.167 -any recursive calls). 240.168 - 240.169 -*out* must be a PrettyWriter if pretty printing is enabled. This is the responsibility 240.170 -of the caller. 240.171 - 240.172 -This method is primarily intended for use by pretty print dispatch functions that 240.173 -already know that the pretty printer will have set up their environment appropriately. 240.174 -Normal library clients should use the standard \"write\" interface. " 240.175 - [object] 240.176 - (let [length-reached (and 240.177 - *current-length* 240.178 - *print-length* 240.179 - (>= *current-length* *print-length*))] 240.180 - (if-not *print-pretty* 240.181 - (pr object) 240.182 - (if length-reached 240.183 - (print "...") 240.184 - (do 240.185 - (if *current-length* (set! *current-length* (inc *current-length*))) 240.186 - (*print-pprint-dispatch* object)))) 240.187 - length-reached)) 240.188 - 240.189 -(defn write 240.190 - "Write an object subject to the current bindings of the printer control variables. 240.191 -Use the kw-args argument to override individual variables for this call (and any 240.192 -recursive calls). Returns the string result if :stream is nil or nil otherwise. 240.193 - 240.194 -The following keyword arguments can be passed with values: 240.195 - Keyword Meaning Default value 240.196 - :stream Writer for output or nil true (indicates *out*) 240.197 - :base Base to use for writing rationals Current value of *print-base* 240.198 - :circle* If true, mark circular structures Current value of *print-circle* 240.199 - :length Maximum elements to show in sublists Current value of *print-length* 240.200 - :level Maximum depth Current value of *print-level* 240.201 - :lines* Maximum lines of output Current value of *print-lines* 240.202 - :miser-width Width to enter miser mode Current value of *print-miser-width* 240.203 - :dispatch The pretty print dispatch function Current value of *print-pprint-dispatch* 240.204 - :pretty If true, do pretty printing Current value of *print-pretty* 240.205 - :radix If true, prepend a radix specifier Current value of *print-radix* 240.206 - :readably* If true, print readably Current value of *print-readably* 240.207 - :right-margin The column for the right margin Current value of *print-right-margin* 240.208 - :suppress-namespaces If true, no namespaces in symbols Current value of *print-suppress-namespaces* 240.209 - 240.210 - * = not yet supported 240.211 -" 240.212 - [object & kw-args] 240.213 - (let [options (merge {:stream true} (apply hash-map kw-args))] 240.214 - (binding-map (table-ize write-option-table options) 240.215 - (binding-map (if (or (not (= *print-base* 10)) *print-radix*) {#'pr pr-with-base} {}) 240.216 - (let [optval (if (contains? options :stream) 240.217 - (:stream options) 240.218 - true) 240.219 - base-writer (condp = optval 240.220 - nil (java.io.StringWriter.) 240.221 - true *out* 240.222 - optval)] 240.223 - (if *print-pretty* 240.224 - (with-pretty-writer base-writer 240.225 - (write-out object)) 240.226 - (binding [*out* base-writer] 240.227 - (pr object))) 240.228 - (if (nil? optval) 240.229 - (.toString ^java.io.StringWriter base-writer))))))) 240.230 - 240.231 - 240.232 -(defn pprint 240.233 - "Pretty print object to the optional output writer. If the writer is not provided, 240.234 -print the object to the currently bound value of *out*." 240.235 - ([object] (pprint object *out*)) 240.236 - ([object writer] 240.237 - (with-pretty-writer writer 240.238 - (binding [*print-pretty* true] 240.239 - (binding-map (if (or (not (= *print-base* 10)) *print-radix*) {#'pr pr-with-base} {}) 240.240 - (write-out object))) 240.241 - (if (not (= 0 (get-column *out*))) 240.242 - (.write *out* (int \newline)))))) 240.243 - 240.244 -(defmacro pp 240.245 - "A convenience macro that pretty prints the last thing output. This is 240.246 -exactly equivalent to (pprint *1)." 240.247 - [] `(pprint *1)) 240.248 - 240.249 -(defn set-pprint-dispatch 240.250 - "Set the pretty print dispatch function to a function matching (fn [obj] ...) 240.251 -where obj is the object to pretty print. That function will be called with *out* set 240.252 -to a pretty printing writer to which it should do its printing. 240.253 - 240.254 -For example functions, see *simple-dispatch* and *code-dispatch* in 240.255 -clojure.contrib.pprint.dispatch.clj." 240.256 - [function] 240.257 - (let [old-meta (meta #'*print-pprint-dispatch*)] 240.258 - (alter-var-root #'*print-pprint-dispatch* (constantly function)) 240.259 - (alter-meta! #'*print-pprint-dispatch* (constantly old-meta))) 240.260 - nil) 240.261 - 240.262 -(defmacro with-pprint-dispatch 240.263 - "Execute body with the pretty print dispatch function bound to function." 240.264 - [function & body] 240.265 - `(binding [*print-pprint-dispatch* ~function] 240.266 - ~@body)) 240.267 - 240.268 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 240.269 -;; Support for the functional interface to the pretty printer 240.270 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 240.271 - 240.272 -(defn- parse-lb-options [opts body] 240.273 - (loop [body body 240.274 - acc []] 240.275 - (if (opts (first body)) 240.276 - (recur (drop 2 body) (concat acc (take 2 body))) 240.277 - [(apply hash-map acc) body]))) 240.278 - 240.279 -(defn- check-enumerated-arg [arg choices] 240.280 - (if-not (choices arg) 240.281 - (throw 240.282 - (IllegalArgumentException. 240.283 - ;; TODO clean up choices string 240.284 - (str "Bad argument: " arg ". It must be one of " choices))))) 240.285 - 240.286 -(defn level-exceeded [] 240.287 - (and *print-level* (>= *current-level* *print-level*))) 240.288 - 240.289 -(defmacro pprint-logical-block 240.290 - "Execute the body as a pretty printing logical block with output to *out* which 240.291 -must be a pretty printing writer. When used from pprint or cl-format, this can be 240.292 -assumed. 240.293 - 240.294 -Before the body, the caller can optionally specify options: :prefix, :per-line-prefix, 240.295 -and :suffix." 240.296 - {:arglists '[[options* body]]} 240.297 - [& args] 240.298 - (let [[options body] (parse-lb-options #{:prefix :per-line-prefix :suffix} args)] 240.299 - `(do (if (level-exceeded) 240.300 - (.write ^java.io.Writer *out* "#") 240.301 - (binding [*current-level* (inc *current-level*) 240.302 - *current-length* 0] 240.303 - (start-block *out* 240.304 - ~(:prefix options) ~(:per-line-prefix options) ~(:suffix options)) 240.305 - ~@body 240.306 - (end-block *out*))) 240.307 - nil))) 240.308 - 240.309 -(defn pprint-newline 240.310 - "Print a conditional newline to a pretty printing stream. kind specifies if the 240.311 -newline is :linear, :miser, :fill, or :mandatory. 240.312 - 240.313 -Output is sent to *out* which must be a pretty printing writer." 240.314 - [kind] 240.315 - (check-enumerated-arg kind #{:linear :miser :fill :mandatory}) 240.316 - (nl *out* kind)) 240.317 - 240.318 -(defn pprint-indent 240.319 - "Create an indent at this point in the pretty printing stream. This defines how 240.320 -following lines are indented. relative-to can be either :block or :current depending 240.321 -whether the indent should be computed relative to the start of the logical block or 240.322 -the current column position. n is an offset. 240.323 - 240.324 -Output is sent to *out* which must be a pretty printing writer." 240.325 - [relative-to n] 240.326 - (check-enumerated-arg relative-to #{:block :current}) 240.327 - (indent *out* relative-to n)) 240.328 - 240.329 -;; TODO a real implementation for pprint-tab 240.330 -(defn pprint-tab 240.331 - "Tab at this point in the pretty printing stream. kind specifies whether the tab 240.332 -is :line, :section, :line-relative, or :section-relative. 240.333 - 240.334 -Colnum and colinc specify the target column and the increment to move the target 240.335 -forward if the output is already past the original target. 240.336 - 240.337 -Output is sent to *out* which must be a pretty printing writer. 240.338 - 240.339 -THIS FUNCTION IS NOT YET IMPLEMENTED." 240.340 - [kind colnum colinc] 240.341 - (check-enumerated-arg kind #{:line :section :line-relative :section-relative}) 240.342 - (throw (UnsupportedOperationException. "pprint-tab is not yet implemented"))) 240.343 - 240.344 - 240.345 -nil
241.1 --- a/src/clojure/contrib/pprint/pretty_writer.clj Sat Aug 21 06:25:44 2010 -0400 241.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 241.3 @@ -1,488 +0,0 @@ 241.4 -;;; pretty_writer.clj -- part of the pretty printer for Clojure 241.5 - 241.6 -;; by Tom Faulhaber 241.7 -;; April 3, 2009 241.8 -;; Revised to use proxy instead of gen-class April 2010 241.9 - 241.10 -; Copyright (c) Tom Faulhaber, Jan 2009. All rights reserved. 241.11 -; The use and distribution terms for this software are covered by the 241.12 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 241.13 -; which can be found in the file epl-v10.html at the root of this distribution. 241.14 -; By using this software in any fashion, you are agreeing to be bound by 241.15 -; the terms of this license. 241.16 -; You must not remove this notice, or any other, from this software. 241.17 - 241.18 -;; This module implements a wrapper around a java.io.Writer which implements the 241.19 -;; core of the XP algorithm. 241.20 - 241.21 -(ns clojure.contrib.pprint.pretty-writer 241.22 - (:refer-clojure :exclude (deftype)) 241.23 - (:use clojure.contrib.pprint.utilities) 241.24 - (:use [clojure.contrib.pprint.column-writer 241.25 - :only (column-writer get-column get-max-column)]) 241.26 - (:import 241.27 - [clojure.lang IDeref] 241.28 - [java.io Writer])) 241.29 - 241.30 -;; TODO: Support for tab directives 241.31 - 241.32 - 241.33 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.34 -;;; Forward declarations 241.35 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.36 - 241.37 -(declare get-miser-width) 241.38 - 241.39 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.40 -;;; Macros to simplify dealing with types and classes. These are 241.41 -;;; really utilities, but I'm experimenting with them here. 241.42 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.43 - 241.44 -(defmacro ^{:private true} 241.45 - getf 241.46 - "Get the value of the field a named by the argument (which should be a keyword)." 241.47 - [sym] 241.48 - `(~sym @@~'this)) 241.49 - 241.50 -(defmacro ^{:private true} 241.51 - setf [sym new-val] 241.52 - "Set the value of the field SYM to NEW-VAL" 241.53 - `(alter @~'this assoc ~sym ~new-val)) 241.54 - 241.55 -(defmacro ^{:private true} 241.56 - deftype [type-name & fields] 241.57 - (let [name-str (name type-name)] 241.58 - `(do 241.59 - (defstruct ~type-name :type-tag ~@fields) 241.60 - (defn- ~(symbol (str "make-" name-str)) 241.61 - [& vals#] (apply struct ~type-name ~(keyword name-str) vals#)) 241.62 - (defn- ~(symbol (str name-str "?")) [x#] (= (:type-tag x#) ~(keyword name-str)))))) 241.63 - 241.64 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.65 -;;; The data structures used by pretty-writer 241.66 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.67 - 241.68 -(defstruct ^{:private true} logical-block 241.69 - :parent :section :start-col :indent 241.70 - :done-nl :intra-block-nl 241.71 - :prefix :per-line-prefix :suffix 241.72 - :logical-block-callback) 241.73 - 241.74 -(defn ancestor? [parent child] 241.75 - (loop [child (:parent child)] 241.76 - (cond 241.77 - (nil? child) false 241.78 - (identical? parent child) true 241.79 - :else (recur (:parent child))))) 241.80 - 241.81 -(defstruct ^{:private true} section :parent) 241.82 - 241.83 -(defn buffer-length [l] 241.84 - (let [l (seq l)] 241.85 - (if l 241.86 - (- (:end-pos (last l)) (:start-pos (first l))) 241.87 - 0))) 241.88 - 241.89 -; A blob of characters (aka a string) 241.90 -(deftype buffer-blob :data :trailing-white-space :start-pos :end-pos) 241.91 - 241.92 -; A newline 241.93 -(deftype nl-t :type :logical-block :start-pos :end-pos) 241.94 - 241.95 -(deftype start-block-t :logical-block :start-pos :end-pos) 241.96 - 241.97 -(deftype end-block-t :logical-block :start-pos :end-pos) 241.98 - 241.99 -(deftype indent-t :logical-block :relative-to :offset :start-pos :end-pos) 241.100 - 241.101 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.102 -;;; Functions to write tokens in the output buffer 241.103 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.104 - 241.105 -(declare emit-nl) 241.106 - 241.107 -(defmulti write-token #(:type-tag %2)) 241.108 -(defmethod write-token :start-block-t [^Writer this token] 241.109 - (when-let [cb (getf :logical-block-callback)] (cb :start)) 241.110 - (let [lb (:logical-block token)] 241.111 - (dosync 241.112 - (when-let [^String prefix (:prefix lb)] 241.113 - (.write (getf :base) prefix)) 241.114 - (let [col (get-column (getf :base))] 241.115 - (ref-set (:start-col lb) col) 241.116 - (ref-set (:indent lb) col))))) 241.117 - 241.118 -(defmethod write-token :end-block-t [^Writer this token] 241.119 - (when-let [cb (getf :logical-block-callback)] (cb :end)) 241.120 - (when-let [^String suffix (:suffix (:logical-block token))] 241.121 - (.write (getf :base) suffix))) 241.122 - 241.123 -(defmethod write-token :indent-t [^Writer this token] 241.124 - (let [lb (:logical-block token)] 241.125 - (ref-set (:indent lb) 241.126 - (+ (:offset token) 241.127 - (condp = (:relative-to token) 241.128 - :block @(:start-col lb) 241.129 - :current (get-column (getf :base))))))) 241.130 - 241.131 -(defmethod write-token :buffer-blob [^Writer this token] 241.132 - (.write (getf :base) ^String (:data token))) 241.133 - 241.134 -(defmethod write-token :nl-t [^Writer this token] 241.135 -; (prlabel wt @(:done-nl (:logical-block token))) 241.136 -; (prlabel wt (:type token) (= (:type token) :mandatory)) 241.137 - (if (or (= (:type token) :mandatory) 241.138 - (and (not (= (:type token) :fill)) 241.139 - @(:done-nl (:logical-block token)))) 241.140 - (emit-nl this token) 241.141 - (if-let [^String tws (getf :trailing-white-space)] 241.142 - (.write (getf :base) tws))) 241.143 - (dosync (setf :trailing-white-space nil))) 241.144 - 241.145 -(defn- write-tokens [^Writer this tokens force-trailing-whitespace] 241.146 - (doseq [token tokens] 241.147 - (if-not (= (:type-tag token) :nl-t) 241.148 - (if-let [^String tws (getf :trailing-white-space)] 241.149 - (.write (getf :base) tws))) 241.150 - (write-token this token) 241.151 - (setf :trailing-white-space (:trailing-white-space token))) 241.152 - (let [^String tws (getf :trailing-white-space)] 241.153 - (when (and force-trailing-whitespace tws) 241.154 - (.write (getf :base) tws) 241.155 - (setf :trailing-white-space nil)))) 241.156 - 241.157 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.158 -;;; emit-nl? method defs for each type of new line. This makes 241.159 -;;; the decision about whether to print this type of new line. 241.160 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.161 - 241.162 - 241.163 -(defn- tokens-fit? [^Writer this tokens] 241.164 -;;; (prlabel tf? (get-column (getf :base) (buffer-length tokens)) 241.165 - (let [maxcol (get-max-column (getf :base))] 241.166 - (or 241.167 - (nil? maxcol) 241.168 - (< (+ (get-column (getf :base)) (buffer-length tokens)) maxcol)))) 241.169 - 241.170 -(defn- linear-nl? [this lb section] 241.171 -; (prlabel lnl? @(:done-nl lb) (tokens-fit? this section)) 241.172 - (or @(:done-nl lb) 241.173 - (not (tokens-fit? this section)))) 241.174 - 241.175 -(defn- miser-nl? [^Writer this lb section] 241.176 - (let [miser-width (get-miser-width this) 241.177 - maxcol (get-max-column (getf :base))] 241.178 - (and miser-width maxcol 241.179 - (>= @(:start-col lb) (- maxcol miser-width)) 241.180 - (linear-nl? this lb section)))) 241.181 - 241.182 -(defmulti emit-nl? (fn [t _ _ _] (:type t))) 241.183 - 241.184 -(defmethod emit-nl? :linear [newl this section _] 241.185 - (let [lb (:logical-block newl)] 241.186 - (linear-nl? this lb section))) 241.187 - 241.188 -(defmethod emit-nl? :miser [newl this section _] 241.189 - (let [lb (:logical-block newl)] 241.190 - (miser-nl? this lb section))) 241.191 - 241.192 -(defmethod emit-nl? :fill [newl this section subsection] 241.193 - (let [lb (:logical-block newl)] 241.194 - (or @(:intra-block-nl lb) 241.195 - (not (tokens-fit? this subsection)) 241.196 - (miser-nl? this lb section)))) 241.197 - 241.198 -(defmethod emit-nl? :mandatory [_ _ _ _] 241.199 - true) 241.200 - 241.201 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.202 -;;; Various support functions 241.203 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.204 - 241.205 - 241.206 -(defn- get-section [buffer] 241.207 - (let [nl (first buffer) 241.208 - lb (:logical-block nl) 241.209 - section (seq (take-while #(not (and (nl-t? %) (ancestor? (:logical-block %) lb))) 241.210 - (next buffer)))] 241.211 - [section (seq (drop (inc (count section)) buffer))])) 241.212 - 241.213 -(defn- get-sub-section [buffer] 241.214 - (let [nl (first buffer) 241.215 - lb (:logical-block nl) 241.216 - section (seq (take-while #(let [nl-lb (:logical-block %)] 241.217 - (not (and (nl-t? %) (or (= nl-lb lb) (ancestor? nl-lb lb))))) 241.218 - (next buffer)))] 241.219 - section)) 241.220 - 241.221 -(defn- update-nl-state [lb] 241.222 - (dosync 241.223 - (ref-set (:intra-block-nl lb) false) 241.224 - (ref-set (:done-nl lb) true) 241.225 - (loop [lb (:parent lb)] 241.226 - (if lb 241.227 - (do (ref-set (:done-nl lb) true) 241.228 - (ref-set (:intra-block-nl lb) true) 241.229 - (recur (:parent lb))))))) 241.230 - 241.231 -(defn emit-nl [^Writer this nl] 241.232 - (.write (getf :base) (int \newline)) 241.233 - (dosync (setf :trailing-white-space nil)) 241.234 - (let [lb (:logical-block nl) 241.235 - ^String prefix (:per-line-prefix lb)] 241.236 - (if prefix 241.237 - (.write (getf :base) prefix)) 241.238 - (let [^String istr (apply str (repeat (- @(:indent lb) (count prefix)) 241.239 - \space))] 241.240 - (.write (getf :base) istr)) 241.241 - (update-nl-state lb))) 241.242 - 241.243 -(defn- split-at-newline [tokens] 241.244 - (let [pre (seq (take-while #(not (nl-t? %)) tokens))] 241.245 - [pre (seq (drop (count pre) tokens))])) 241.246 - 241.247 -;;; Methods for showing token strings for debugging 241.248 - 241.249 -(defmulti tok :type-tag) 241.250 -(defmethod tok :nl-t [token] 241.251 - (:type token)) 241.252 -(defmethod tok :buffer-blob [token] 241.253 - (str \" (:data token) (:trailing-white-space token) \")) 241.254 -(defmethod tok :default [token] 241.255 - (:type-tag token)) 241.256 -(defn toks [toks] (map tok toks)) 241.257 - 241.258 -;;; write-token-string is called when the set of tokens in the buffer 241.259 -;;; is longer than the available space on the line 241.260 - 241.261 -(defn- write-token-string [this tokens] 241.262 - (let [[a b] (split-at-newline tokens)] 241.263 -;; (prlabel wts (toks a) (toks b)) 241.264 - (if a (write-tokens this a false)) 241.265 - (if b 241.266 - (let [[section remainder] (get-section b) 241.267 - newl (first b)] 241.268 -;; (prlabel wts (toks section)) (prlabel wts (:type newl)) (prlabel wts (toks remainder)) 241.269 - (let [do-nl (emit-nl? newl this section (get-sub-section b)) 241.270 - result (if do-nl 241.271 - (do 241.272 -;; (prlabel emit-nl (:type newl)) 241.273 - (emit-nl this newl) 241.274 - (next b)) 241.275 - b) 241.276 - long-section (not (tokens-fit? this result)) 241.277 - result (if long-section 241.278 - (let [rem2 (write-token-string this section)] 241.279 -;;; (prlabel recurse (toks rem2)) 241.280 - (if (= rem2 section) 241.281 - (do ; If that didn't produce any output, it has no nls 241.282 - ; so we'll force it 241.283 - (write-tokens this section false) 241.284 - remainder) 241.285 - (into [] (concat rem2 remainder)))) 241.286 - result) 241.287 -;; ff (prlabel wts (toks result)) 241.288 - ] 241.289 - result))))) 241.290 - 241.291 -(defn- write-line [^Writer this] 241.292 - (dosync 241.293 - (loop [buffer (getf :buffer)] 241.294 -;; (prlabel wl1 (toks buffer)) 241.295 - (setf :buffer (into [] buffer)) 241.296 - (if (not (tokens-fit? this buffer)) 241.297 - (let [new-buffer (write-token-string this buffer)] 241.298 -;; (prlabel wl new-buffer) 241.299 - (if-not (identical? buffer new-buffer) 241.300 - (recur new-buffer))))))) 241.301 - 241.302 -;;; Add a buffer token to the buffer and see if it's time to start 241.303 -;;; writing 241.304 -(defn- add-to-buffer [^Writer this token] 241.305 -; (prlabel a2b token) 241.306 - (dosync 241.307 - (setf :buffer (conj (getf :buffer) token)) 241.308 - (if (not (tokens-fit? this (getf :buffer))) 241.309 - (write-line this)))) 241.310 - 241.311 -;;; Write all the tokens that have been buffered 241.312 -(defn- write-buffered-output [^Writer this] 241.313 - (write-line this) 241.314 - (if-let [buf (getf :buffer)] 241.315 - (do 241.316 - (write-tokens this buf true) 241.317 - (setf :buffer [])))) 241.318 - 241.319 -;;; If there are newlines in the string, print the lines up until the last newline, 241.320 -;;; making the appropriate adjustments. Return the remainder of the string 241.321 -(defn- write-initial-lines 241.322 - [^Writer this ^String s] 241.323 - (let [lines (.split s "\n" -1)] 241.324 - (if (= (count lines) 1) 241.325 - s 241.326 - (dosync 241.327 - (let [^String prefix (:per-line-prefix (first (getf :logical-blocks))) 241.328 - ^String l (first lines)] 241.329 - (if (= :buffering (getf :mode)) 241.330 - (let [oldpos (getf :pos) 241.331 - newpos (+ oldpos (count l))] 241.332 - (setf :pos newpos) 241.333 - (add-to-buffer this (make-buffer-blob l nil oldpos newpos)) 241.334 - (write-buffered-output this)) 241.335 - (.write (getf :base) l)) 241.336 - (.write (getf :base) (int \newline)) 241.337 - (doseq [^String l (next (butlast lines))] 241.338 - (.write (getf :base) l) 241.339 - (.write (getf :base) (int \newline)) 241.340 - (if prefix 241.341 - (.write (getf :base) prefix))) 241.342 - (setf :buffering :writing) 241.343 - (last lines)))))) 241.344 - 241.345 - 241.346 -(defn write-white-space [^Writer this] 241.347 - (if-let [^String tws (getf :trailing-white-space)] 241.348 - (dosync 241.349 - (.write (getf :base) tws) 241.350 - (setf :trailing-white-space nil)))) 241.351 - 241.352 -(defn- write-char [^Writer this ^Integer c] 241.353 - (if (= (getf :mode) :writing) 241.354 - (do 241.355 - (write-white-space this) 241.356 - (.write (getf :base) c)) 241.357 - (if (= c \newline) 241.358 - (write-initial-lines this "\n") 241.359 - (let [oldpos (getf :pos) 241.360 - newpos (inc oldpos)] 241.361 - (dosync 241.362 - (setf :pos newpos) 241.363 - (add-to-buffer this (make-buffer-blob (str (char c)) nil oldpos newpos))))))) 241.364 - 241.365 - 241.366 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.367 -;;; Initialize the pretty-writer instance 241.368 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.369 - 241.370 - 241.371 -(defn pretty-writer [writer max-columns miser-width] 241.372 - (let [lb (struct logical-block nil nil (ref 0) (ref 0) (ref false) (ref false)) 241.373 - fields (ref {:pretty-writer true 241.374 - :base (column-writer writer max-columns) 241.375 - :logical-blocks lb 241.376 - :sections nil 241.377 - :mode :writing 241.378 - :buffer [] 241.379 - :buffer-block lb 241.380 - :buffer-level 1 241.381 - :miser-width miser-width 241.382 - :trailing-white-space nil 241.383 - :pos 0})] 241.384 - (proxy [Writer IDeref] [] 241.385 - (deref [] fields) 241.386 - 241.387 - (write 241.388 - ([x] 241.389 - ;; (prlabel write x (getf :mode)) 241.390 - (condp = (class x) 241.391 - String 241.392 - (let [^String s0 (write-initial-lines this x) 241.393 - ^String s (.replaceFirst s0 "\\s+$" "") 241.394 - white-space (.substring s0 (count s)) 241.395 - mode (getf :mode)] 241.396 - (dosync 241.397 - (if (= mode :writing) 241.398 - (do 241.399 - (write-white-space this) 241.400 - (.write (getf :base) s) 241.401 - (setf :trailing-white-space white-space)) 241.402 - (let [oldpos (getf :pos) 241.403 - newpos (+ oldpos (count s0))] 241.404 - (setf :pos newpos) 241.405 - (add-to-buffer this (make-buffer-blob s white-space oldpos newpos)))))) 241.406 - 241.407 - Integer 241.408 - (write-char this x) 241.409 - Long 241.410 - (write-char this x)))) 241.411 - 241.412 - (flush [] 241.413 - (if (= (getf :mode) :buffering) 241.414 - (dosync 241.415 - (write-tokens this (getf :buffer) true) 241.416 - (setf :buffer [])) 241.417 - (write-white-space this))) 241.418 - 241.419 - (close [] 241.420 - (.flush this))))) 241.421 - 241.422 - 241.423 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.424 -;;; Methods for pretty-writer 241.425 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 241.426 - 241.427 -(defn start-block 241.428 - [^Writer this 241.429 - ^String prefix ^String per-line-prefix ^String suffix] 241.430 - (dosync 241.431 - (let [lb (struct logical-block (getf :logical-blocks) nil (ref 0) (ref 0) 241.432 - (ref false) (ref false) 241.433 - prefix per-line-prefix suffix)] 241.434 - (setf :logical-blocks lb) 241.435 - (if (= (getf :mode) :writing) 241.436 - (do 241.437 - (write-white-space this) 241.438 - (when-let [cb (getf :logical-block-callback)] (cb :start)) 241.439 - (if prefix 241.440 - (.write (getf :base) prefix)) 241.441 - (let [col (get-column (getf :base))] 241.442 - (ref-set (:start-col lb) col) 241.443 - (ref-set (:indent lb) col))) 241.444 - (let [oldpos (getf :pos) 241.445 - newpos (+ oldpos (if prefix (count prefix) 0))] 241.446 - (setf :pos newpos) 241.447 - (add-to-buffer this (make-start-block-t lb oldpos newpos))))))) 241.448 - 241.449 -(defn end-block [^Writer this] 241.450 - (dosync 241.451 - (let [lb (getf :logical-blocks) 241.452 - ^String suffix (:suffix lb)] 241.453 - (if (= (getf :mode) :writing) 241.454 - (do 241.455 - (write-white-space this) 241.456 - (if suffix 241.457 - (.write (getf :base) suffix)) 241.458 - (when-let [cb (getf :logical-block-callback)] (cb :end))) 241.459 - (let [oldpos (getf :pos) 241.460 - newpos (+ oldpos (if suffix (count suffix) 0))] 241.461 - (setf :pos newpos) 241.462 - (add-to-buffer this (make-end-block-t lb oldpos newpos)))) 241.463 - (setf :logical-blocks (:parent lb))))) 241.464 - 241.465 -(defn nl [^Writer this type] 241.466 - (dosync 241.467 - (setf :mode :buffering) 241.468 - (let [pos (getf :pos)] 241.469 - (add-to-buffer this (make-nl-t type (getf :logical-blocks) pos pos))))) 241.470 - 241.471 -(defn indent [^Writer this relative-to offset] 241.472 - (dosync 241.473 - (let [lb (getf :logical-blocks)] 241.474 - (if (= (getf :mode) :writing) 241.475 - (do 241.476 - (write-white-space this) 241.477 - (ref-set (:indent lb) 241.478 - (+ offset (condp = relative-to 241.479 - :block @(:start-col lb) 241.480 - :current (get-column (getf :base)))))) 241.481 - (let [pos (getf :pos)] 241.482 - (add-to-buffer this (make-indent-t lb relative-to offset pos pos))))))) 241.483 - 241.484 -(defn get-miser-width [^Writer this] 241.485 - (getf :miser-width)) 241.486 - 241.487 -(defn set-miser-width [^Writer this new-miser-width] 241.488 - (dosync (setf :miser-width new-miser-width))) 241.489 - 241.490 -(defn set-logical-block-callback [^Writer this f] 241.491 - (dosync (setf :logical-block-callback f)))
242.1 --- a/src/clojure/contrib/pprint/utilities.clj Sat Aug 21 06:25:44 2010 -0400 242.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 242.3 @@ -1,104 +0,0 @@ 242.4 -;;; utilities.clj -- part of the pretty printer for Clojure 242.5 - 242.6 -;; by Tom Faulhaber 242.7 -;; April 3, 2009 242.8 - 242.9 -; Copyright (c) Tom Faulhaber, Jan 2009. All rights reserved. 242.10 -; The use and distribution terms for this software are covered by the 242.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 242.12 -; which can be found in the file epl-v10.html at the root of this distribution. 242.13 -; By using this software in any fashion, you are agreeing to be bound by 242.14 -; the terms of this license. 242.15 -; You must not remove this notice, or any other, from this software. 242.16 - 242.17 -;; This module implements some utility function used in formatting and pretty 242.18 -;; printing. The functions here could go in a more general purpose library, 242.19 -;; perhaps. 242.20 - 242.21 -(ns clojure.contrib.pprint.utilities) 242.22 - 242.23 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 242.24 -;;; Helper functions for digesting formats in the various 242.25 -;;; phases of their lives. 242.26 -;;; These functions are actually pretty general. 242.27 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 242.28 - 242.29 -(defn map-passing-context [func initial-context lis] 242.30 - (loop [context initial-context 242.31 - lis lis 242.32 - acc []] 242.33 - (if (empty? lis) 242.34 - [acc context] 242.35 - (let [this (first lis) 242.36 - remainder (next lis) 242.37 - [result new-context] (apply func [this context])] 242.38 - (recur new-context remainder (conj acc result)))))) 242.39 - 242.40 -(defn consume [func initial-context] 242.41 - (loop [context initial-context 242.42 - acc []] 242.43 - (let [[result new-context] (apply func [context])] 242.44 - (if (not result) 242.45 - [acc new-context] 242.46 - (recur new-context (conj acc result)))))) 242.47 - 242.48 -(defn consume-while [func initial-context] 242.49 - (loop [context initial-context 242.50 - acc []] 242.51 - (let [[result continue new-context] (apply func [context])] 242.52 - (if (not continue) 242.53 - [acc context] 242.54 - (recur new-context (conj acc result)))))) 242.55 - 242.56 -(defn unzip-map [m] 242.57 - "Take a map that has pairs in the value slots and produce a pair of maps, 242.58 - the first having all the first elements of the pairs and the second all 242.59 - the second elements of the pairs" 242.60 - [(into {} (for [[k [v1 v2]] m] [k v1])) 242.61 - (into {} (for [[k [v1 v2]] m] [k v2]))]) 242.62 - 242.63 -(defn tuple-map [m v1] 242.64 - "For all the values, v, in the map, replace them with [v v1]" 242.65 - (into {} (for [[k v] m] [k [v v1]]))) 242.66 - 242.67 -(defn rtrim [s c] 242.68 - "Trim all instances of c from the end of sequence s" 242.69 - (let [len (count s)] 242.70 - (if (and (pos? len) (= (nth s (dec (count s))) c)) 242.71 - (loop [n (dec len)] 242.72 - (cond 242.73 - (neg? n) "" 242.74 - (not (= (nth s n) c)) (subs s 0 (inc n)) 242.75 - true (recur (dec n)))) 242.76 - s))) 242.77 - 242.78 -(defn ltrim [s c] 242.79 - "Trim all instances of c from the beginning of sequence s" 242.80 - (let [len (count s)] 242.81 - (if (and (pos? len) (= (nth s 0) c)) 242.82 - (loop [n 0] 242.83 - (if (or (= n len) (not (= (nth s n) c))) 242.84 - (subs s n) 242.85 - (recur (inc n)))) 242.86 - s))) 242.87 - 242.88 -(defn prefix-count [aseq val] 242.89 - "Return the number of times that val occurs at the start of sequence aseq, 242.90 -if val is a seq itself, count the number of times any element of val occurs at the 242.91 -beginning of aseq" 242.92 - (let [test (if (coll? val) (set val) #{val})] 242.93 - (loop [pos 0] 242.94 - (if (or (= pos (count aseq)) (not (test (nth aseq pos)))) 242.95 - pos 242.96 - (recur (inc pos)))))) 242.97 - 242.98 -(defn prerr [& args] 242.99 - "Println to *err*" 242.100 - (binding [*out* *err*] 242.101 - (apply println args))) 242.102 - 242.103 -(defmacro prlabel [prefix arg & more-args] 242.104 - "Print args to *err* in name = value format" 242.105 - `(prerr ~@(cons (list 'quote prefix) (mapcat #(list (list 'quote %) "=" %) 242.106 - (cons arg (seq more-args)))))) 242.107 -
243.1 --- a/src/clojure/contrib/probabilities/finite_distributions.clj Sat Aug 21 06:25:44 2010 -0400 243.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 243.3 @@ -1,203 +0,0 @@ 243.4 -;; Finite probability distributions 243.5 - 243.6 -;; by Konrad Hinsen 243.7 -;; last updated January 8, 2010 243.8 - 243.9 -;; Copyright (c) Konrad Hinsen, 2009-2010. All rights reserved. The use 243.10 -;; and distribution terms for this software are covered by the Eclipse 243.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 243.12 -;; which can be found in the file epl-v10.html at the root of this 243.13 -;; distribution. By using this software in any fashion, you are 243.14 -;; agreeing to be bound by the terms of this license. You must not 243.15 -;; remove this notice, or any other, from this software. 243.16 - 243.17 -(ns 243.18 - ^{:author "Konrad Hinsen" 243.19 - :doc "Finite probability distributions 243.20 - This library defines a monad for combining finite probability 243.21 - distributions."} 243.22 - clojure.contrib.probabilities.finite-distributions 243.23 - (:use [clojure.contrib.monads 243.24 - :only (defmonad domonad with-monad maybe-t m-lift m-chain)] 243.25 - [clojure.contrib.def :only (defvar)])) 243.26 - 243.27 -; The probability distribution monad. It is limited to finite probability 243.28 -; distributions (e.g. there is a finite number of possible value), which 243.29 -; are represented as maps from values to probabilities. 243.30 - 243.31 -(defmonad dist-m 243.32 - "Monad describing computations on fuzzy quantities, represented by a finite 243.33 - probability distribution for the possible values. A distribution is 243.34 - represented by a map from values to probabilities." 243.35 - [m-result (fn m-result-dist [v] 243.36 - {v 1}) 243.37 - m-bind (fn m-bind-dist [mv f] 243.38 - (reduce (partial merge-with +) 243.39 - (for [[x p] mv [y q] (f x)] 243.40 - {y (* q p)}))) 243.41 - ]) 243.42 - 243.43 -; Applying the monad transformer maybe-t to the basic dist monad results 243.44 -; in the cond-dist monad that can handle invalid values. The total probability 243.45 -; for invalid values ends up as the probability of m-zero (which is nil). 243.46 -; The function normalize takes this probability out of the distribution and 243.47 -; re-distributes its weight over the valid values. 243.48 - 243.49 -(defvar cond-dist-m 243.50 - (maybe-t dist-m) 243.51 - "Variant of the dist monad that can handle undefined values.") 243.52 - 243.53 -; Normalization 243.54 - 243.55 -(defn- scale-by 243.56 - "Multiply each entry in dist by the scale factor s and remove zero entries." 243.57 - [dist s] 243.58 - (into {} 243.59 - (for [[val p] dist :when (> p 0)] 243.60 - [val (* p s)]))) 243.61 - 243.62 -(defn normalize-cond [cdist] 243.63 - "Normalize a probability distribution resulting from a computation in 243.64 - the cond-dist monad by re-distributing the weight of the invalid values 243.65 - over the valid ones." 243.66 - (let [missing (get cdist nil 0) 243.67 - dist (dissoc cdist nil)] 243.68 - (cond (zero? missing) dist 243.69 - (= 1 missing) {} 243.70 - :else (let [scale (/ 1 (- 1 missing))] 243.71 - (scale-by dist scale))))) 243.72 - 243.73 -(defn normalize 243.74 - "Convert a weight map (e.g. a map of counter values) to a distribution 243.75 - by multiplying with a normalization factor. If the map has a key 243.76 - :total, its value is assumed to be the sum over all the other values and 243.77 - it is used for normalization. Otherwise, the sum is calculated 243.78 - explicitly. The :total key is removed from the resulting distribution." 243.79 - [weights] 243.80 - (let [total (:total weights) 243.81 - w (dissoc weights :total) 243.82 - s (/ 1 (if (nil? total) (reduce + (vals w)) total))] 243.83 - (scale-by w s))) 243.84 - 243.85 -; Functions that construct distributions 243.86 - 243.87 -(defn uniform 243.88 - "Return a distribution in which each of the elements of coll 243.89 - has the same probability." 243.90 - [coll] 243.91 - (let [n (count coll) 243.92 - p (/ 1 n)] 243.93 - (into {} (for [x (seq coll)] [x p])))) 243.94 - 243.95 -(defn choose 243.96 - "Construct a distribution from an explicit list of probabilities 243.97 - and values. They are given in the form of a vector of probability-value 243.98 - pairs. In the last pair, the probability can be given by the keyword 243.99 - :else, which stands for 1 minus the total of the other probabilities." 243.100 - [& choices] 243.101 - (letfn [(add-choice [dist [p v]] 243.102 - (cond (nil? p) dist 243.103 - (= p :else) 243.104 - (let [total-p (reduce + (vals dist))] 243.105 - (assoc dist v (- 1 total-p))) 243.106 - :else (assoc dist v p)))] 243.107 - (reduce add-choice {} (partition 2 choices)))) 243.108 - 243.109 -(defn bernoulli 243.110 - [p] 243.111 - "Returns the Bernoulli distribution for probability p." 243.112 - (choose p 1 :else 0)) 243.113 - 243.114 -(defn- bc 243.115 - [n] 243.116 - "Returns the binomial coefficients for a given n." 243.117 - (let [r (inc n)] 243.118 - (loop [c 1 243.119 - f (list 1)] 243.120 - (if (> c n) 243.121 - f 243.122 - (recur (inc c) (cons (* (/ (- r c) c) (first f)) f)))))) 243.123 - 243.124 -(defn binomial 243.125 - [n p] 243.126 - "Returns the binomial distribution, which is the distribution of the 243.127 - number of successes in a series of n experiments whose individual 243.128 - success probability is p." 243.129 - (let [q (- 1 p) 243.130 - n1 (inc n) 243.131 - k (range n1) 243.132 - pk (take n1 (iterate #(* p %) 1)) 243.133 - ql (reverse (take n1 (iterate #(* q %) 1))) 243.134 - f (bc n)] 243.135 - (into {} (map vector k (map * f pk ql))))) 243.136 - 243.137 -(defn make-distribution 243.138 - "Returns the distribution in which each element x of the collection 243.139 - has a probability proportional to (f x)" 243.140 - [coll f] 243.141 - (normalize (into {} (for [k coll] [k (f k)])))) 243.142 - 243.143 -(defn zipf 243.144 - "Returns the Zipf distribution in which the numbers k=1..n have 243.145 - probabilities proportional to 1/k^s." 243.146 - [s n] 243.147 - (make-distribution (range 1 (inc n)) #(/ (java.lang.Math/pow % s)))) 243.148 - 243.149 -(defn certainly 243.150 - "Returns a distribution in which the single value v has probability 1." 243.151 - [v] 243.152 - {v 1}) 243.153 - 243.154 -(with-monad dist-m 243.155 - 243.156 - (defn join-with 243.157 - "Returns the distribution of (f x y) with x from dist1 and y from dist2." 243.158 - [f dist1 dist2] 243.159 - ((m-lift 2 f) dist1 dist2)) 243.160 - 243.161 -) 243.162 - 243.163 -(with-monad cond-dist-m 243.164 - (defn cond-prob 243.165 - "Returns the conditional probability for the values in dist that satisfy 243.166 - the predicate pred." 243.167 - [pred dist] 243.168 - (normalize-cond 243.169 - (domonad 243.170 - [v dist 243.171 - :when (pred v)] 243.172 - v)))) 243.173 - 243.174 -; Select (with equal probability) N items from a sequence 243.175 - 243.176 -(defn- nth-and-rest [n xs] 243.177 - "Return a list containing the n-th value of xs and the sequence 243.178 - obtained by removing the n-th value from xs." 243.179 - (let [[h t] (split-at n xs)] 243.180 - (list (first t) (concat h (rest t))))) 243.181 - 243.182 -(with-monad dist-m 243.183 - 243.184 - (defn- select-n [n xs] 243.185 - (letfn [(select-1 [[s xs]] 243.186 - (uniform (for [i (range (count xs))] 243.187 - (let [[nth rest] (nth-and-rest i xs)] 243.188 - (list (cons nth s) rest)))))] 243.189 - ((m-chain (replicate n select-1)) (list '() xs)))) 243.190 - 243.191 - (defn select [n xs] 243.192 - "Return the distribution for all possible ordered selections of n elements 243.193 - out of xs." 243.194 - ((m-lift 1 first) (select-n n xs))) 243.195 - 243.196 -) 243.197 - 243.198 -; Find the probability that a given predicate is satisfied 243.199 - 243.200 -(defn prob 243.201 - "Return the probability that the predicate pred is satisfied in the 243.202 - distribution dist, i.e. the sum of the probabilities of the values 243.203 - that satisfy pred." 243.204 - [pred dist] 243.205 - (apply + (for [[x p] dist :when (pred x)] p))) 243.206 -
244.1 --- a/src/clojure/contrib/probabilities/monte_carlo.clj Sat Aug 21 06:25:44 2010 -0400 244.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 244.3 @@ -1,240 +0,0 @@ 244.4 -;; Monte-Carlo algorithms 244.5 - 244.6 -;; by Konrad Hinsen 244.7 -;; last updated May 3, 2009 244.8 - 244.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 244.10 -;; and distribution terms for this software are covered by the Eclipse 244.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 244.12 -;; which can be found in the file epl-v10.html at the root of this 244.13 -;; distribution. By using this software in any fashion, you are 244.14 -;; agreeing to be bound by the terms of this license. You must not 244.15 -;; remove this notice, or any other, from this software. 244.16 - 244.17 -(ns 244.18 - ^{:author "Konrad Hinsen" 244.19 - :doc "Monte-Carlo method support 244.20 - 244.21 - Monte-Carlo methods transform an input random number stream 244.22 - (usually having a continuous uniform distribution in the 244.23 - interval [0, 1)) into a random number stream whose distribution 244.24 - satisfies certain conditions (usually the expectation value 244.25 - is equal to some desired quantity). They are thus 244.26 - transformations from one probability distribution to another one. 244.27 - 244.28 - This library represents a Monte-Carlo method by a function that 244.29 - takes as input the state of a random number stream with 244.30 - uniform distribution (see 244.31 - clojure.contrib.probabilities.random-numbers) and returns a 244.32 - vector containing one sample value of the desired output 244.33 - distribution and the final state of the input random number 244.34 - stream. Such functions are state monad values and can be 244.35 - composed using operations defined in clojure.contrib.monads."} 244.36 - clojure.contrib.probabilities.monte-carlo 244.37 - (:refer-clojure :exclude (deftype)) 244.38 - (:use [clojure.contrib.macros :only (const)]) 244.39 - (:use [clojure.contrib.types :only (deftype)]) 244.40 - (:use [clojure.contrib.stream-utils :only (defstream stream-next)]) 244.41 - (:use [clojure.contrib.monads 244.42 - :only (with-monad state-m m-lift m-seq m-fmap)]) 244.43 - (:require [clojure.contrib.generic.arithmetic :as ga]) 244.44 - (:require [clojure.contrib.accumulators :as acc])) 244.45 - 244.46 -;; Random number transformers and random streams 244.47 -;; 244.48 -;; A random number transformer is a function that takes a random stream 244.49 -;; state as input and returns the next value from the transformed stream 244.50 -;; plus the new state of the input stream. Random number transformers 244.51 -;; are thus state monad values. 244.52 -;; 244.53 -;; Distributions are implemented as random number transformers that 244.54 -;; transform a uniform distribution in the interval [0, 1) to the 244.55 -;; desired distribution. Composition of such distributions allows 244.56 -;; the realization of any kind of Monte-Carlo algorithm. The result 244.57 -;; of such a composition is always again a distribution. 244.58 -;; 244.59 -;; Random streams are defined by a random number transformer and an 244.60 -;; input random number stream. If the randon number transformer represents 244.61 -;; a distribution, the input stream must have a uniform distribution 244.62 -;; in the interval [0, 1). 244.63 - 244.64 -; Random stream definition 244.65 -(deftype ::random-stream random-stream 244.66 - "Define a random stream by a distribution and the state of a 244.67 - random number stream with uniform distribution in [0, 1)." 244.68 - {:arglists '([distribution random-stream-state])} 244.69 - (fn [d rs] (list d rs))) 244.70 - 244.71 -(defstream ::random-stream 244.72 - [[d rs]] 244.73 - (let [[r nrs] (d rs)] 244.74 - [r (random-stream d nrs)])) 244.75 - 244.76 -; Rejection of values is used in the construction of distributions 244.77 -(defn reject 244.78 - "Return the distribution that results from rejecting the values from 244.79 - dist that do not satisfy predicate p." 244.80 - [p dist] 244.81 - (fn [rs] 244.82 - (let [[r nrs] (dist rs)] 244.83 - (if (p r) 244.84 - (recur nrs) 244.85 - [r nrs])))) 244.86 - 244.87 -; Draw a value from a discrete distribution given as a map from 244.88 -; values to probabilities. 244.89 -; (see clojure.contrib.probabilities.finite-distributions) 244.90 -(with-monad state-m 244.91 - (defn discrete 244.92 - "A discrete distribution, defined by a map dist mapping values 244.93 - to probabilities. The sum of probabilities must be one." 244.94 - [dist] 244.95 - (letfn [(pick-at-level [l dist-items] 244.96 - (let [[[x p] & rest-dist] dist-items] 244.97 - (if (> p l) 244.98 - x 244.99 - (recur (- l p) rest-dist))))] 244.100 - (m-fmap #(pick-at-level % (seq dist)) stream-next)))) 244.101 - 244.102 -; Uniform distribution in an finite half-open interval 244.103 -(with-monad state-m 244.104 - (defn interval 244.105 - [a b] 244.106 - "Transform a sequence of uniform random numbers in the interval [0, 1) 244.107 - into a sequence of uniform random numbers in the interval [a, b)." 244.108 - (let [d (- b a) 244.109 - f (if (zero? a) 244.110 - (if (= d 1) 244.111 - identity 244.112 - (fn [r] (* d r))) 244.113 - (if (= d 1) 244.114 - (fn [r] (+ a r)) 244.115 - (fn [r] (+ a (* d r)))))] 244.116 - (m-fmap f stream-next)))) 244.117 - 244.118 -; Normal (Gaussian) distribution 244.119 -(defn normal 244.120 - "Transform a sequence urs of uniform random number in the interval [0, 1) 244.121 - into a sequence of normal random numbers with mean mu and standard 244.122 - deviation sigma." 244.123 - [mu sigma] 244.124 - ; This function implements the Kinderman-Monahan ratio method: 244.125 - ; A.J. Kinderman & J.F. Monahan 244.126 - ; Computer Generation of Random Variables Using the Ratio of Uniform Deviates 244.127 - ; ACM Transactions on Mathematical Software 3(3) 257-260, 1977 244.128 - (fn [rs] 244.129 - (let [[u1 rs] (stream-next rs) 244.130 - [u2* rs] (stream-next rs) 244.131 - u2 (- 1. u2*) 244.132 - s (const (* 4 (/ (. Math exp (- 0.5)) (. Math sqrt 2.)))) 244.133 - z (* s (/ (- u1 0.5) u2)) 244.134 - zz (+ (* 0.25 z z) (. Math log u2))] 244.135 - (if (> zz 0) 244.136 - (recur rs) 244.137 - [(+ mu (* sigma z)) rs])))) 244.138 - 244.139 -; Lognormal distribution 244.140 -(with-monad state-m 244.141 - (defn lognormal 244.142 - "Transform a sequence of uniform random numbesr in the interval [0, 1) 244.143 - into a sequence of lognormal random numbers with mean mu and standard 244.144 - deviation sigma." 244.145 - [mu sigma] 244.146 - (m-fmap #(. Math exp %) (normal mu sigma)))) 244.147 - 244.148 -; Exponential distribution 244.149 -(with-monad state-m 244.150 - (defn exponential 244.151 - "Transform a sequence of uniform random numbers in the interval [0, 1) 244.152 - into a sequence of exponential random numbers with parameter lambda." 244.153 - [lambda] 244.154 - (when (<= lambda 0) 244.155 - (throw (IllegalArgumentException. 244.156 - "exponential distribution requires a positive argument"))) 244.157 - (let [neg-inv-lambda (- (/ lambda)) 244.158 - ; remove very small numbers to prevent log from returning -Infinity 244.159 - not-too-small (reject #(< % 1e-323) stream-next)] 244.160 - (m-fmap #(* (. Math log %) neg-inv-lambda) not-too-small)))) 244.161 - 244.162 -; Another implementation of the normal distribution. It uses the 244.163 -; Box-Muller transform, but discards one of the two result values 244.164 -; at each cycle because the random number transformer interface cannot 244.165 -; handle two outputs at the same time. 244.166 -(defn normal-box-muller 244.167 - "Transform a sequence of uniform random numbers in the interval [0, 1) 244.168 - into a sequence of normal random numbers with mean mu and standard 244.169 - deviation sigma." 244.170 - [mu sigma] 244.171 - (fn [rs] 244.172 - (let [[u1 rs] (stream-next rs) 244.173 - [u2 rs] (stream-next rs) 244.174 - v1 (- (* 2.0 u1) 1.0) 244.175 - v2 (- (* 2.0 u2) 1.0) 244.176 - s (+ (* v1 v1) (* v2 v2)) 244.177 - ls (. Math sqrt (/ (* -2.0 (. Math log s)) s)) 244.178 - x1 (* v1 ls) 244.179 - x2 (* v2 ls)] 244.180 - (if (or (>= s 1) (= s 0)) 244.181 - (recur rs) 244.182 - [x1 rs])))) 244.183 - 244.184 -; Finite samples from a distribution 244.185 -(with-monad state-m 244.186 - 244.187 - (defn sample 244.188 - "Return the distribution of samples of length n from the 244.189 - distribution dist" 244.190 - [n dist] 244.191 - (m-seq (replicate n dist))) 244.192 - 244.193 - (defn sample-reduce 244.194 - "Returns the distribution of the reduction of f over n samples from the 244.195 - distribution dist." 244.196 - ([f n dist] 244.197 - (if (zero? n) 244.198 - (m-result (f)) 244.199 - (let [m-f (m-lift 2 f) 244.200 - sample (replicate n dist)] 244.201 - (reduce m-f sample)))) 244.202 - ([f val n dist] 244.203 - (let [m-f (m-lift 2 f) 244.204 - m-val (m-result val) 244.205 - sample (replicate n dist)] 244.206 - (reduce m-f m-val sample)))) 244.207 - 244.208 - (defn sample-sum 244.209 - "Return the distribution of the sum over n samples from the 244.210 - distribution dist." 244.211 - [n dist] 244.212 - (sample-reduce ga/+ n dist)) 244.213 - 244.214 - (defn sample-mean 244.215 - "Return the distribution of the mean over n samples from the 244.216 - distribution dist" 244.217 - [n dist] 244.218 - (let [div-by-n (m-lift 1 #(ga/* % (/ n)))] 244.219 - (div-by-n (sample-sum n dist)))) 244.220 - 244.221 - (defn sample-mean-variance 244.222 - "Return the distribution of the mean-and-variance (a vector containing 244.223 - the mean and the variance) over n samples from the distribution dist" 244.224 - [n dist] 244.225 - (let [extract (m-lift 1 (fn [mv] [(:mean mv) (:variance mv)]))] 244.226 - (extract (sample-reduce acc/add acc/empty-mean-variance n dist)))) 244.227 - 244.228 -) 244.229 - 244.230 -; Uniform distribution inside an n-sphere 244.231 -(with-monad state-m 244.232 - (defn n-sphere 244.233 - "Return a uniform distribution of n-dimensional vectors inside an 244.234 - n-sphere of radius r." 244.235 - [n r] 244.236 - (let [box-dist (sample n (interval (- r) r)) 244.237 - sq #(* % %) 244.238 - r-sq (sq r) 244.239 - vec-sq #(apply + (map sq %)) 244.240 - sphere-dist (reject #(> (vec-sq %) r-sq) box-dist) 244.241 - as-vectors (m-lift 1 vec)] 244.242 - (as-vectors sphere-dist)))) 244.243 -
245.1 --- a/src/clojure/contrib/probabilities/random_numbers.clj Sat Aug 21 06:25:44 2010 -0400 245.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 245.3 @@ -1,63 +0,0 @@ 245.4 -;; Random number generators 245.5 - 245.6 -;; by Konrad Hinsen 245.7 -;; last updated May 3, 2009 245.8 - 245.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 245.10 -;; and distribution terms for this software are covered by the Eclipse 245.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 245.12 -;; which can be found in the file epl-v10.html at the root of this 245.13 -;; distribution. By using this software in any fashion, you are 245.14 -;; agreeing to be bound by the terms of this license. You must not 245.15 -;; remove this notice, or any other, from this software. 245.16 - 245.17 -(ns 245.18 - ^{:author "Konrad Hinsen" 245.19 - :doc "Random number streams 245.20 - 245.21 - This library provides random number generators with a common 245.22 - stream interface. They all produce pseudo-random numbers that are 245.23 - uniformly distributed in the interval [0, 1), i.e. 0 is a 245.24 - possible value but 1 isn't. For transformations to other 245.25 - distributions, see clojure.contrib.probabilities.monte-carlo. 245.26 - 245.27 - At the moment, the only generator provided is a rather simple 245.28 - linear congruential generator."} 245.29 - clojure.contrib.probabilities.random-numbers 245.30 - (:refer-clojure :exclude (deftype)) 245.31 - (:use [clojure.contrib.types :only (deftype)]) 245.32 - (:use [clojure.contrib.stream-utils :only (defstream)]) 245.33 - (:use [clojure.contrib.def :only (defvar)])) 245.34 - 245.35 -;; Linear congruential generator 245.36 -;; http://en.wikipedia.org/wiki/Linear_congruential_generator 245.37 - 245.38 -(deftype ::lcg lcg 245.39 - "Create a linear congruential generator" 245.40 - {:arglists '([modulus multiplier increment seed])} 245.41 - (fn [modulus multiplier increment seed] 245.42 - {:m modulus :a multiplier :c increment :seed seed}) 245.43 - (fn [s] (map s (list :m :a :c :seed)))) 245.44 - 245.45 -(defstream ::lcg 245.46 - [lcg-state] 245.47 - (let [{m :m a :a c :c seed :seed} lcg-state 245.48 - value (/ (float seed) (float m)) 245.49 - new-seed (rem (+ c (* a seed)) m)] 245.50 - [value (assoc lcg-state :seed new-seed)])) 245.51 - 245.52 -;; A generator based on Clojure's built-in rand function 245.53 -;; (and thus random from java.lang.Math) 245.54 -;; Note that this generator uses an internal mutable state. 245.55 -;; 245.56 -;; The state is *not* stored in the stream object and can thus 245.57 -;; *not* be restored! 245.58 - 245.59 -(defvar rand-stream (with-meta 'rand {:type ::rand-stream}) 245.60 - "A random number stream based on clojure.core/rand. Note that this 245.61 - generator uses an internal mutable state. The state is thus not stored 245.62 - in the stream object and cannot be restored.") 245.63 - 245.64 -(defstream ::rand-stream 245.65 - [dummy-state] 245.66 - [(rand) dummy-state])
246.1 --- a/src/clojure/contrib/profile.clj Sat Aug 21 06:25:44 2010 -0400 246.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 246.3 @@ -1,110 +0,0 @@ 246.4 -;;; profile.clj: simple code profiling & timing 246.5 - 246.6 -;; by Stuart Sierra, http://stuartsierra.com/ 246.7 -;; May 9, 2009 246.8 - 246.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 246.10 -;; and distribution terms for this software are covered by the Eclipse 246.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 246.12 -;; which can be found in the file epl-v10.html at the root of this 246.13 -;; distribution. By using this software in any fashion, you are 246.14 -;; agreeing to be bound by the terms of this license. You must not 246.15 -;; remove this notice, or any other, from this software. 246.16 - 246.17 - 246.18 -(ns ^{:author "Stuart Sierra" 246.19 - :doc "Simple code profiling & timing measurement. 246.20 - 246.21 -Wrap any section of code in the prof macro, giving it a name, like this: 246.22 - 246.23 - (defn my-function [x y] 246.24 - (let [sum (prof :addition (+ x y)) 246.25 - product (prof :multiplication (* x y))] 246.26 - [sum product])) 246.27 - 246.28 -The run your code in the profile macro, like this: 246.29 - 246.30 - (profile (dotimes [i 10000] (my-function 3 4))) 246.31 - 246.32 -Which prints a report for each named section of code: 246.33 - 246.34 - Name mean min max count sum 246.35 - addition 265 0 37000 10000 2655000 246.36 -multiplication 274 0 53000 10000 2747000 246.37 - 246.38 -Times are measured in nanoseconds, to the maximum precision available 246.39 -under the JVM. See the function documentation for more details. 246.40 -"} 246.41 - clojure.contrib.profile) 246.42 - 246.43 -(def *profile-data* nil) 246.44 - 246.45 -(def ^{:doc "Set this to false before loading/compiling to omit 246.46 -profiling code."} *enable-profiling* true) 246.47 - 246.48 -(defmacro prof 246.49 - "If *enable-profiling* is true, wraps body in profiling code. 246.50 - Returns the result of body. Profile timings will be stored in 246.51 - *profile-data* using name, which must be a keyword, as the key. 246.52 - Timings are measured with System/nanoTime." 246.53 - [name & body] 246.54 - (assert (keyword? name)) 246.55 - (if *enable-profiling* 246.56 - `(if *profile-data* 246.57 - (let [start-time# (System/nanoTime) 246.58 - value# (do ~@body) 246.59 - elapsed# (- (System/nanoTime) start-time#)] 246.60 - (swap! *profile-data* assoc ~name 246.61 - (conj (get @*profile-data* ~name) elapsed#)) 246.62 - value#) 246.63 - ~@body) 246.64 - `(do ~@body))) 246.65 - 246.66 -(defmacro with-profile-data 246.67 - "Executes body with *profile-data* bound to an atom of a new map. 246.68 - Returns the raw profile data as a map. Keys in the map are profile 246.69 - names (keywords), and values are lists of elapsed time, in 246.70 - nanoseconds." 246.71 - [& body] 246.72 - `(binding [*profile-data* (atom {})] 246.73 - ~@body 246.74 - @*profile-data*)) 246.75 - 246.76 -(defn summarize 246.77 - "Takes the raw data returned by with-profile-data and returns a map 246.78 - from names to summary statistics. Each value in the map will look 246.79 - like: 246.80 - 246.81 - {:mean ..., :min ..., :max ..., :count ..., :sum ...} 246.82 - 246.83 - :mean, :min, and :max are how long the profiled section took to run, 246.84 - in nanoseconds. :count is the total number of times the profiled 246.85 - section was executed. :sum is the total amount of time spent in the 246.86 - profiled section, in nanoseconds." 246.87 - [profile-data] 246.88 - (reduce (fn [m [k v]] 246.89 - (let [cnt (count v) 246.90 - sum (reduce + v)] 246.91 - (assoc m k {:mean (int (/ sum cnt)) 246.92 - :min (apply min v) 246.93 - :max (apply max v) 246.94 - :count cnt 246.95 - :sum sum}))) 246.96 - {} profile-data)) 246.97 - 246.98 -(defn print-summary 246.99 - "Prints a table of the results returned by summarize." 246.100 - [profile-summary] 246.101 - (let [name-width (apply max 1 (map (comp count name) (keys profile-summary))) 246.102 - fmt-string (str "%" name-width "s %8d %8d %8d %8d %8d%n")] 246.103 - (printf (.replace fmt-string \d \s) 246.104 - "Name" "mean" "min" "max" "count" "sum") 246.105 - (doseq [k (sort (keys profile-summary))] 246.106 - (let [v (get profile-summary k)] 246.107 - (printf fmt-string (name k) (:mean v) (:min v) (:max v) (:count v) (:sum v)))))) 246.108 - 246.109 -(defmacro profile 246.110 - "Runs body with profiling enabled, then prints a summary of 246.111 - results. Returns nil." 246.112 - [& body] 246.113 - `(print-summary (summarize (with-profile-data (do ~@body)))))
247.1 --- a/src/clojure/contrib/properties.clj Sat Aug 21 06:25:44 2010 -0400 247.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 247.3 @@ -1,77 +0,0 @@ 247.4 -; Copyright (c) Stuart Halloway & Contributors, April 2009. All rights reserved. 247.5 -; The use and distribution terms for this software are covered by the 247.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 247.7 -; which can be found in the file epl-v10.html at the root of this distribution. 247.8 -; By using this software in any fashion, you are agreeing to be bound by 247.9 -; the terms of this license. 247.10 -; You must not remove this notice, or any other, from this software. 247.11 - 247.12 -;; DEPRECATED in 1.2. Moved to c.c.java-utils 247.13 - 247.14 -(ns ^{:deprecated "1.2"} 247.15 - clojure.contrib.properties 247.16 - (:use [clojure.contrib.string :only (as-str)] 247.17 - [clojure.contrib.io :only (file)]) 247.18 - (:import (java.util Properties) 247.19 - (java.io FileInputStream FileOutputStream))) 247.20 - 247.21 -(defn get-system-property 247.22 - "Get a system property." 247.23 - ([stringable] 247.24 - (System/getProperty (as-str stringable))) 247.25 - ([stringable default] 247.26 - (System/getProperty (as-str stringable) default))) 247.27 - 247.28 -(defn set-system-properties 247.29 - "Set some system properties. Nil clears a property." 247.30 - [settings] 247.31 - (doseq [[name val] settings] 247.32 - (if val 247.33 - (System/setProperty (as-str name) (as-str val)) 247.34 - (System/clearProperty (as-str name))))) 247.35 - 247.36 -(defmacro with-system-properties 247.37 - "setting => property-name value 247.38 - 247.39 - Sets the system properties to the supplied values, executes the body, and 247.40 - sets the properties back to their original values. Values of nil are 247.41 - translated to a clearing of the property." 247.42 - [settings & body] 247.43 - `(let [settings# ~settings 247.44 - current# (reduce (fn [coll# k#] 247.45 - (assoc coll# k# (get-system-property k#))) 247.46 - {} 247.47 - (keys settings#))] 247.48 - (set-system-properties settings#) 247.49 - (try 247.50 - ~@body 247.51 - (finally 247.52 - (set-system-properties current#))))) 247.53 - 247.54 - 247.55 -; Not there is no corresponding props->map. Just destructure! 247.56 -(defn ^Properties as-properties 247.57 - "Convert any seq of pairs to a java.utils.Properties instance. 247.58 - Uses as-str to convert both keys and values into strings." 247.59 - {:tag Properties} 247.60 - [m] 247.61 - (let [p (Properties.)] 247.62 - (doseq [[k v] m] 247.63 - (.setProperty p (as-str k) (as-str v))) 247.64 - p)) 247.65 - 247.66 -(defn read-properties 247.67 - "Read properties from file-able." 247.68 - [file-able] 247.69 - (with-open [f (java.io.FileInputStream. (file file-able))] 247.70 - (doto (Properties.) 247.71 - (.load f)))) 247.72 - 247.73 -(defn write-properties 247.74 - "Write properties to file-able." 247.75 - {:tag Properties} 247.76 - ([m file-able] (write-properties m file-able nil)) 247.77 - ([m file-able comments] 247.78 - (with-open [^FileOutputStream f (FileOutputStream. (file file-able))] 247.79 - (doto (as-properties m) 247.80 - (.store f ^String comments)))))
248.1 --- a/src/clojure/contrib/prxml.clj Sat Aug 21 06:25:44 2010 -0400 248.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 248.3 @@ -1,170 +0,0 @@ 248.4 -;;; prxml.clj -- compact syntax for generating XML 248.5 - 248.6 -;; by Stuart Sierra, http://stuartsierra.com/ 248.7 -;; March 29, 2009 248.8 - 248.9 -;; Copyright (c) 2009 Stuart Sierra. All rights reserved. The use and 248.10 -;; distribution terms for this software are covered by the Eclipse 248.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 248.12 -;; which can be found in the file epl-v10.html at the root of this 248.13 -;; distribution. By using this software in any fashion, you are 248.14 -;; agreeing to be bound by the terms of this license. You must not 248.15 -;; remove this notice, or any other, from this software. 248.16 - 248.17 - 248.18 -;; Change Log 248.19 -;; 248.20 -;; March 29, 2009: added *prxml-indent* 248.21 -;; 248.22 -;; January 4, 2009: initial version 248.23 - 248.24 - 248.25 -;; See function "prxml" at the bottom of this file for documentation. 248.26 - 248.27 - 248.28 -(ns 248.29 - ^{:author "Stuart Sierra", 248.30 - :doc "Compact syntax for generating XML. See the documentation of \"prxml\" 248.31 -for details."} 248.32 - clojure.contrib.prxml 248.33 - (:use [clojure.contrib.string :only (escape as-str)])) 248.34 - 248.35 -(def 248.36 - ^{:doc "If true, empty tags will have a space before the closing />"} 248.37 - *html-compatible* false) 248.38 - 248.39 -(def 248.40 - ^{:doc "The number of spaces to indent sub-tags. nil for no indent 248.41 - and no extra line-breaks."} 248.42 - *prxml-indent* nil) 248.43 - 248.44 -(def ^{:private true} *prxml-tag-depth* 0) 248.45 - 248.46 -(def ^{:private true} print-xml) ; forward declaration 248.47 - 248.48 -(defn- escape-xml [s] 248.49 - (escape {\< "<" 248.50 - \> ">" 248.51 - \& "&" 248.52 - \' "'" 248.53 - \" """} s)) 248.54 - 248.55 -(defn- prxml-attribute [name value] 248.56 - (print " ") 248.57 - (print (as-str name)) 248.58 - (print "=\"") 248.59 - (print (escape-xml (str value))) 248.60 - (print "\"")) 248.61 - 248.62 -(defmulti ^{:private true} print-xml-tag (fn [tag attrs content] tag)) 248.63 - 248.64 -(defmethod print-xml-tag :raw! [tag attrs contents] 248.65 - (doseq [c contents] (print c))) 248.66 - 248.67 -(defmethod print-xml-tag :comment! [tag attrs contents] 248.68 - (print "<!-- ") 248.69 - (doseq [c contents] (print c)) 248.70 - (print " -->")) 248.71 - 248.72 -(defmethod print-xml-tag :decl! [tag attrs contents] 248.73 - (let [attrs (merge {:version "1.0" :encoding "UTF-8"} 248.74 - attrs)] 248.75 - ;; Must enforce ordering of pseudo-attributes: 248.76 - (print "<?xml version=\"") 248.77 - (print (:version attrs)) 248.78 - (print "\" encoding=\"") 248.79 - (print (:encoding attrs)) 248.80 - (print "\"") 248.81 - (when (:standalone attrs) 248.82 - (print " standalone=\"") 248.83 - (print (:standalone attrs)) 248.84 - (print "\"")) 248.85 - (print "?>"))) 248.86 - 248.87 -(defmethod print-xml-tag :cdata! [tag attrs contents] 248.88 - (print "<![CDATA[") 248.89 - (doseq [c contents] (print c)) 248.90 - (print "]]>")) 248.91 - 248.92 -(defmethod print-xml-tag :doctype! [tag attrs contents] 248.93 - (print "<!DOCTYPE ") 248.94 - (doseq [c contents] (print c)) 248.95 - (print ">")) 248.96 - 248.97 -(defmethod print-xml-tag :default [tag attrs contents] 248.98 - (let [tag-name (as-str tag)] 248.99 - (when *prxml-indent* 248.100 - (newline) 248.101 - (dotimes [n (* *prxml-tag-depth* *prxml-indent*)] (print " "))) 248.102 - (print "<") 248.103 - (print tag-name) 248.104 - (doseq [[name value] attrs] 248.105 - (prxml-attribute name value)) 248.106 - (if (seq contents) 248.107 - (do ;; not an empty tag 248.108 - (print ">") 248.109 - (if (every? string? contents) 248.110 - ;; tag only contains strings: 248.111 - (do (doseq [c contents] (print-xml c)) 248.112 - (print "</") (print tag-name) (print ">")) 248.113 - ;; tag contains sub-tags: 248.114 - (do (binding [*prxml-tag-depth* (inc *prxml-tag-depth*)] 248.115 - (doseq [c contents] (print-xml c))) 248.116 - (when *prxml-indent* 248.117 - (newline) 248.118 - (dotimes [n (* *prxml-tag-depth* *prxml-indent*)] (print " "))) 248.119 - (print "</") (print tag-name) (print ">")))) 248.120 - ;; empty tag: 248.121 - (print (if *html-compatible* " />" "/>"))))) 248.122 - 248.123 - 248.124 -(defmulti ^{:private true} print-xml class) 248.125 - 248.126 -(defmethod print-xml clojure.lang.IPersistentVector [x] 248.127 - (let [[tag & contents] x 248.128 - [attrs content] (if (map? (first contents)) 248.129 - [(first contents) (rest contents)] 248.130 - [{} contents])] 248.131 - (print-xml-tag tag attrs content))) 248.132 - 248.133 -(defmethod print-xml clojure.lang.ISeq [x] 248.134 - ;; Recurse into sequences, so we can use (map ...) inside prxml. 248.135 - (doseq [c x] (print-xml c))) 248.136 - 248.137 -(defmethod print-xml clojure.lang.Keyword [x] 248.138 - (print-xml-tag x {} nil)) 248.139 - 248.140 -(defmethod print-xml String [x] 248.141 - (print (escape-xml x))) 248.142 - 248.143 -(defmethod print-xml nil [x]) 248.144 - 248.145 -(defmethod print-xml :default [x] 248.146 - (print x)) 248.147 - 248.148 - 248.149 -(defn prxml 248.150 - "Print XML to *out*. Vectors become XML tags: the first item is the 248.151 - tag name; optional second item is a map of attributes. 248.152 - 248.153 - Sequences are processed recursively, so you can use map and other 248.154 - sequence functions inside prxml. 248.155 - 248.156 - (prxml [:p {:class \"greet\"} [:i \"Ladies & gentlemen\"]]) 248.157 - ; => <p class=\"greet\"><i>Ladies & gentlemen</i></p> 248.158 - 248.159 - PSEUDO-TAGS: some keywords have special meaning: 248.160 - 248.161 - :raw! do not XML-escape contents 248.162 - :comment! create an XML comment 248.163 - :decl! create an XML declaration, with attributes 248.164 - :cdata! create a CDATA section 248.165 - :doctype! create a DOCTYPE! 248.166 - 248.167 - (prxml [:p [:raw! \"<i>here & gone</i>\"]]) 248.168 - ; => <p><i>here & gone</i></p> 248.169 - 248.170 - (prxml [:decl! {:version \"1.1\"}]) 248.171 - ; => <?xml version=\"1.1\" encoding=\"UTF-8\"?>" 248.172 - [& args] 248.173 - (doseq [arg args] (print-xml arg)))
249.1 --- a/src/clojure/contrib/reflect.clj Sat Aug 21 06:25:44 2010 -0400 249.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 249.3 @@ -1,33 +0,0 @@ 249.4 -; Copyright (c) 2010 Stuart Halloway & Contributors. All rights 249.5 -; reserved. The use and distribution terms for this software are 249.6 -; covered by the Eclipse Public License 1.0 249.7 -; (http://opensource.org/licenses/eclipse-1.0.php) which can be 249.8 -; found in the file epl-v10.html at the root of this distribution. 249.9 -; By using this software in any fashion, you are agreeing to be 249.10 -; bound by the terms of this license. You must not remove this 249.11 -; notice, or any other, from this software. 249.12 - 249.13 -(ns clojure.contrib.reflect) 249.14 - 249.15 -(defn call-method 249.16 - "Calls a private or protected method. 249.17 - 249.18 - params is a vector of classes which correspond to the arguments to 249.19 - the method e 249.20 - 249.21 - obj is nil for static methods, the instance object otherwise. 249.22 - 249.23 - The method-name is given a symbol or a keyword (something Named)." 249.24 - [klass method-name params obj & args] 249.25 - (-> klass (.getDeclaredMethod (name method-name) 249.26 - (into-array Class params)) 249.27 - (doto (.setAccessible true)) 249.28 - (.invoke obj (into-array Object args)))) 249.29 - 249.30 -(defn get-field 249.31 - "Access to private or protected field. field-name is a symbol or 249.32 - keyword." 249.33 - [klass field-name obj] 249.34 - (-> klass (.getDeclaredField (name field-name)) 249.35 - (doto (.setAccessible true)) 249.36 - (.get obj)))
250.1 --- a/src/clojure/contrib/repl_ln.clj Sat Aug 21 06:25:44 2010 -0400 250.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 250.3 @@ -1,274 +0,0 @@ 250.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 250.5 -;; distribution terms for this software are covered by the Eclipse Public 250.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 250.7 -;; be found in the file epl-v10.html at the root of this distribution. By 250.8 -;; using this software in any fashion, you are agreeing to be bound by the 250.9 -;; terms of this license. You must not remove this notice, or any other, 250.10 -;; from this software. 250.11 -;; 250.12 -;; A repl with that provides support for lines and line numbers in the 250.13 -;; input stream. 250.14 -;; 250.15 -;; scgilardi (gmail) 250.16 -;; Created 28 November 2008 250.17 - 250.18 -(ns 250.19 - ^{:author "Stephen C. Gilardi", 250.20 - :doc "A repl with that provides support for lines and line numbers in the 250.21 - input stream."} 250.22 - clojure.contrib.repl-ln 250.23 - (:gen-class) 250.24 - (:import (clojure.lang Compiler LineNumberingPushbackReader RT Var) 250.25 - (java.io InputStreamReader OutputStreamWriter PrintWriter) 250.26 - java.util.Date) 250.27 - (:require clojure.main) 250.28 - (:use [clojure.contrib.def 250.29 - :only (defmacro- defonce- defstruct- defvar-)])) 250.30 - 250.31 -;; Private 250.32 - 250.33 -(declare repl) 250.34 - 250.35 -(defstruct- repl-info 250.36 - :name :started :name-fmt :prompt-fmt :serial :thread :depth) 250.37 - 250.38 -(defvar- +name-formats+ 250.39 - {"%S" "%1$d" "%T" "%2$d" "%D" "%3$d"} 250.40 - "For set-name, maps our dynamic value codes to arg positions in 250.41 - the call to format in repl-name") 250.42 - 250.43 -(defvar- +prompt-formats+ 250.44 - {"%S" "%1$d" "%T" "%2$d" "%D" "%3$d" "%L" "%4$d" "%N" "%5$s"} 250.45 - "For set-prompt, maps our dynamic value codes to arg positions in 250.46 - the call to format in repl-prompt") 250.47 - 250.48 -(defvar- +info-format+ 250.49 - ["Name: %s" 250.50 - "Started: %s" 250.51 - "Name-fmt: \"%s\"" 250.52 - "Prompt-fmt: \"%s\"" 250.53 - "Serial: %d" 250.54 - "Thread: %d" 250.55 - "Depth: %d" 250.56 - "Line: %d"]) 250.57 - 250.58 -(defvar- +info-defaults+ 250.59 - (struct-map repl-info 250.60 - :name-fmt "repl-%S" 250.61 - :prompt-fmt "%S:%L %N=> " 250.62 - :depth 0) 250.63 - "Default/root values for repl info") 250.64 - 250.65 -(defonce- *serial-number* (atom 0) 250.66 - "Serial number counter") 250.67 - 250.68 -(defonce- *info* +info-defaults+ 250.69 - "Public info for this repl") 250.70 - 250.71 -(defonce- *private* {} 250.72 - "Private info for this repl") 250.73 - 250.74 -(defmacro- update 250.75 - "Replaces the map thread-locally bound to map-var with a copy that 250.76 - includes updated and/or new values from keys and vals." 250.77 - [map-var & key-vals] 250.78 - `(set! ~map-var (assoc ~map-var ~@key-vals))) 250.79 - 250.80 -(defn- repl-name 250.81 - "Returns the repl name based on this repl's name-fmt" 250.82 - [] 250.83 - (let [{:keys [name-fmt]} *private* 250.84 - {:keys [serial thread depth]} *info*] 250.85 - (format name-fmt serial thread depth))) 250.86 - 250.87 -(defn- prompt-hook 250.88 - [] 250.89 - (let [prompt (*private* :prompt)] 250.90 - (var-set Compiler/LINE (.getLineNumber *in*)) 250.91 - (prompt))) 250.92 - 250.93 -(defn- process-inits 250.94 - "Processes initial pairs of args of the form: 250.95 - 250.96 - -i filepath, or 250.97 - --init filepath 250.98 - 250.99 - by loading the referenced files, then accepts an optional terminating arg 250.100 - of the form: 250.101 - 250.102 - -r, or 250.103 - --repl 250.104 - 250.105 - Returns a seq of any remaining args." 250.106 - [args] 250.107 - (loop [[init filename & more :as args] args] 250.108 - (if (#{"-i" "--init"} init) 250.109 - (do 250.110 - (clojure.main/load-script filename) 250.111 - (recur more)) 250.112 - (if (#{"-r" "--repl"} init) 250.113 - (rest args) 250.114 - args)))) 250.115 - 250.116 -(defn- process-command-line 250.117 - "Args are strings passed in from the command line. Loads any requested 250.118 - init files and binds *command-line-args* to a seq of the remaining args" 250.119 - [args] 250.120 - (set! *command-line-args* (process-inits args))) 250.121 - 250.122 -(defn stream-repl 250.123 - "Repl entry point that provides convenient overriding of input, output, 250.124 - and err streams via sequential keyword-value pairs. Default values 250.125 - for :in, :out, and :err are streams associated with System/in, 250.126 - System/out, and System/err using UTF-8 encoding. Also supports all the 250.127 - options provided by clojure.contrib.repl-ln/repl." 250.128 - [& options] 250.129 - (let [enc RT/UTF8 250.130 - {:keys [in out err] 250.131 - :or {in (LineNumberingPushbackReader. 250.132 - (InputStreamReader. System/in enc)) 250.133 - out (OutputStreamWriter. System/out enc) 250.134 - err (PrintWriter. (OutputStreamWriter. System/err enc))}} 250.135 - (apply hash-map options)] 250.136 - (binding [*in* in *out* out *err* err] 250.137 - (apply repl options)))) 250.138 - 250.139 -(defn- -main 250.140 - "Main entry point, starts a repl enters the user namespace and processes 250.141 - command line args." 250.142 - [& args] 250.143 - (repl :init 250.144 - (fn [] 250.145 - (println "Clojure" (clojure-version)) 250.146 - (in-ns 'user) 250.147 - (process-command-line args)))) 250.148 - 250.149 -;; Public 250.150 - 250.151 -(defn repl-prompt 250.152 - "Returns the current repl prompt based on this repl's prompt-fmt" 250.153 - [] 250.154 - (let [{:keys [prompt-fmt]} *private* 250.155 - {:keys [serial thread depth]} *info* 250.156 - line (.getLineNumber *in*) 250.157 - namespace (ns-name *ns*)] 250.158 - (format prompt-fmt serial thread depth line namespace))) 250.159 - 250.160 -(defn set-repl-name 250.161 - "Sets the repl name format to the string name-fmt. Include the following 250.162 - codes in the name to make the corresponding dynamic values part of it: 250.163 - 250.164 - %S - repl serial number 250.165 - %T - thread id 250.166 - %D - nesting depth in this thread 250.167 - 250.168 - With no arguments, resets the repl name to its default: \"repl-%S\"" 250.169 - ([] 250.170 - (set-repl-name (+info-defaults+ :name-fmt))) 250.171 - ([name-fmt] 250.172 - (update *info* :name-fmt name-fmt) 250.173 - (loop [[[code fmt] & more] (seq +name-formats+) 250.174 - name-fmt name-fmt] 250.175 - (if code 250.176 - (recur more (.replace name-fmt code fmt)) 250.177 - (update *private* :name-fmt name-fmt))) 250.178 - (let [name (repl-name)] 250.179 - (update *info* :name name) 250.180 - (var-set Compiler/SOURCE name)) 250.181 - nil)) 250.182 - 250.183 -(defn set-repl-prompt 250.184 - "Sets the repl prompt. Include the following codes in the prompt to make 250.185 - the corresponding dynamic values part of it: 250.186 - 250.187 - %S - repl serial number 250.188 - %T - thread id 250.189 - %D - nesting depth in this thread 250.190 - %L - input line number 250.191 - %N - namespace name 250.192 - 250.193 - With no arguments, resets the repl pompt to its default: \"%S:%L %N=> \"" 250.194 - ([] 250.195 - (set-repl-prompt (+info-defaults+ :prompt-fmt))) 250.196 - ([prompt-fmt] 250.197 - (update *info* :prompt-fmt prompt-fmt) 250.198 - (loop [[[code fmt] & more] (seq +prompt-formats+) 250.199 - prompt-fmt prompt-fmt] 250.200 - (if code 250.201 - (recur more (.replace prompt-fmt code fmt)) 250.202 - (update *private* :prompt-fmt prompt-fmt))) 250.203 - nil)) 250.204 - 250.205 -(defn repl-info 250.206 - "Returns a map of info about the current repl" 250.207 - [] 250.208 - (let [line (.getLineNumber *in*)] 250.209 - (assoc *info* :line line))) 250.210 - 250.211 -(defn print-repl-info 250.212 - "Prints info about the current repl" 250.213 - [] 250.214 - (let [{:keys [name started name-fmt prompt-fmt serial thread depth line]} 250.215 - (repl-info)] 250.216 - (printf 250.217 - (apply str (interleave +info-format+ (repeat "\n"))) 250.218 - name started name-fmt prompt-fmt serial thread depth line))) 250.219 - 250.220 -(defn repl 250.221 - "A repl that supports line numbers. For definitions and evaluations made 250.222 - at the repl, the repl-name and line number will be reported as the 250.223 - origin. Use set-repl-name and set-repl-prompt to customize the repl name 250.224 - and prompt. This repl supports all of the keyword arguments documented 250.225 - for clojure.main/repl with the following change and additions: 250.226 - 250.227 - - :prompt has a new default 250.228 - default: #(clojure.core/print (repl-prompt)) 250.229 - 250.230 - - :name-fmt, Name format string 250.231 - default: the name-fmt of the parent repl, or \"repl-%S\" 250.232 - 250.233 - - :prompt-fmt, Prompt format string 250.234 - default: the prompt-fmt of the parent repl, or \"%S:%L %N=> \"" 250.235 - [& options] 250.236 - (let [{:keys [init need-prompt prompt flush read eval print caught 250.237 - name-fmt prompt-fmt] 250.238 - :or {init #() 250.239 - need-prompt (if (instance? LineNumberingPushbackReader *in*) 250.240 - #(.atLineStart *in*) 250.241 - #(identity true)) 250.242 - prompt #(clojure.core/print (repl-prompt)) 250.243 - flush flush 250.244 - read clojure.main/repl-read 250.245 - eval eval 250.246 - print prn 250.247 - caught clojure.main/repl-caught 250.248 - name-fmt (*info* :name-fmt) 250.249 - prompt-fmt (*info* :prompt-fmt)}} 250.250 - (apply hash-map options)] 250.251 - (try 250.252 - (Var/pushThreadBindings 250.253 - {Compiler/SOURCE (var-get Compiler/SOURCE) 250.254 - Compiler/LINE (var-get Compiler/LINE) 250.255 - (var *info*) *info* 250.256 - (var *private*) {}}) 250.257 - (update *info* 250.258 - :started (Date.) 250.259 - :serial (swap! *serial-number* inc) 250.260 - :thread (.getId (Thread/currentThread)) 250.261 - :depth (inc (*info* :depth))) 250.262 - (update *private* 250.263 - :prompt prompt) 250.264 - (set-repl-name name-fmt) 250.265 - (set-repl-prompt prompt-fmt) 250.266 - (clojure.main/repl 250.267 - :init init 250.268 - :need-prompt need-prompt 250.269 - :prompt prompt-hook 250.270 - :flush flush 250.271 - :read read 250.272 - :eval eval 250.273 - :print print 250.274 - :caught caught) 250.275 - (finally 250.276 - (Var/popThreadBindings) 250.277 - (prn)))))
251.1 --- a/src/clojure/contrib/repl_utils.clj Sat Aug 21 06:25:44 2010 -0400 251.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 251.3 @@ -1,213 +0,0 @@ 251.4 -; Copyright (c) Chris Houser, Dec 2008. All rights reserved. 251.5 -; The use and distribution terms for this software are covered by the 251.6 -; Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 251.7 -; which can be found in the file CPL.TXT at the root of this distribution. 251.8 -; By using this software in any fashion, you are agreeing to be bound by 251.9 -; the terms of this license. 251.10 -; You must not remove this notice, or any other, from this software. 251.11 - 251.12 -; Utilities meant to be used interactively at the REPL 251.13 - 251.14 -;; Deprecated in 1.2: source, get-source, and apropos. These are 251.15 -;; available in clojure.repl as source, source-fn, and apropos, respectively. 251.16 - 251.17 -(ns 251.18 - ^{:author "Chris Houser, Christophe Grand, Stephen Gilardi, Michel Salim", 251.19 - :doc "Utilities meant to be used interactively at the REPL"} 251.20 - clojure.contrib.repl-utils 251.21 - (:import (java.io File LineNumberReader InputStreamReader PushbackReader) 251.22 - (java.lang.reflect Modifier Method Constructor) 251.23 - (clojure.lang RT Compiler Compiler$C)) 251.24 - (:require [clojure.contrib.string :as s]) 251.25 - (:use [clojure.contrib.seq :only (indexed)] 251.26 - [clojure.contrib.javadoc.browse :only (browse-url)])) 251.27 - 251.28 -;; ---------------------------------------------------------------------- 251.29 -;; Examine Java classes 251.30 - 251.31 -(defn- sortable [t] 251.32 - (apply str (map (fn [[a b]] (str a (format "%04d" (Integer. b)))) 251.33 - (partition 2 (concat (s/partition #"\d+" t) [0]))))) 251.34 - 251.35 -(defn- param-str [m] 251.36 - (str " (" (s/join 251.37 - "," (map (fn [[c i]] 251.38 - (if (> i 3) 251.39 - (str (.getSimpleName c) "*" i) 251.40 - (s/join "," (replicate i (.getSimpleName c))))) 251.41 - (reduce (fn [pairs y] (let [[x i] (peek pairs)] 251.42 - (if (= x y) 251.43 - (conj (pop pairs) [y (inc i)]) 251.44 - (conj pairs [y 1])))) 251.45 - [] (.getParameterTypes m)))) 251.46 - ")")) 251.47 - 251.48 -(defn- member-details [m] 251.49 - (let [static? (Modifier/isStatic (.getModifiers m)) 251.50 - method? (instance? Method m) 251.51 - ctor? (instance? Constructor m) 251.52 - text (if ctor? 251.53 - (str "<init>" (param-str m)) 251.54 - (str 251.55 - (when static? "static ") 251.56 - (.getName m) " : " 251.57 - (if method? 251.58 - (str (.getSimpleName (.getReturnType m)) (param-str m)) 251.59 - (str (.getSimpleName (.getType m))))))] 251.60 - (assoc (bean m) 251.61 - :sort-val [(not static?) method? (sortable text)] 251.62 - :text text 251.63 - :member m))) 251.64 - 251.65 -(defn show 251.66 - "With one arg prints all static and instance members of x or (class x). 251.67 - Each member is listed with a number which can be given as 'selector' 251.68 - to return the member object -- the REPL will print more details for 251.69 - that member. 251.70 - 251.71 - The selector also may be a string or regex, in which case only 251.72 - members whose names match 'selector' as a case-insensitive regex 251.73 - will be printed. 251.74 - 251.75 - Finally, the selector also may be a predicate, in which case only 251.76 - members for which the predicate returns true will be printed. The 251.77 - predicate will be passed a single argument, a map that includes the 251.78 - :text that will be printed and the :member object itself, as well as 251.79 - all the properies of the member object as translated by 'bean'. 251.80 - 251.81 - Examples: (show Integer) (show []) (show String 23) (show String \"case\")" 251.82 - ([x] (show x (constantly true))) 251.83 - ([x selector] 251.84 - (let [c (if (class? x) x (class x)) 251.85 - members (sort-by :sort-val 251.86 - (map member-details 251.87 - (concat (.getFields c) 251.88 - (.getMethods c) 251.89 - (.getConstructors c))))] 251.90 - (if (number? selector) 251.91 - (:member (nth members selector)) 251.92 - (let [pred (if (ifn? selector) 251.93 - selector 251.94 - #(re-find (re-pattern (str "(?i)" selector)) (:name %)))] 251.95 - (println "=== " (Modifier/toString (.getModifiers c)) c " ===") 251.96 - (doseq [[i m] (indexed members)] 251.97 - (when (pred m) 251.98 - (printf "[%2d] %s\n" i (:text m))))))))) 251.99 - 251.100 -;; ---------------------------------------------------------------------- 251.101 -;; Examine Clojure functions (Vars, really) 251.102 - 251.103 -(defn get-source 251.104 - "Returns a string of the source code for the given symbol, if it can 251.105 - find it. This requires that the symbol resolve to a Var defined in 251.106 - a namespace for which the .clj is in the classpath. Returns nil if 251.107 - it can't find the source. For most REPL usage, 'source' is more 251.108 - convenient. 251.109 - 251.110 - Example: (get-source 'filter)" 251.111 - {:deprecated "1.2"} 251.112 - [x] 251.113 - (when-let [v (resolve x)] 251.114 - (when-let [filepath (:file (meta v))] 251.115 - (when-let [strm (.getResourceAsStream (RT/baseLoader) filepath)] 251.116 - (with-open [rdr (LineNumberReader. (InputStreamReader. strm))] 251.117 - (dotimes [_ (dec (:line (meta v)))] (.readLine rdr)) 251.118 - (let [text (StringBuilder.) 251.119 - pbr (proxy [PushbackReader] [rdr] 251.120 - (read [] (let [i (proxy-super read)] 251.121 - (.append text (char i)) 251.122 - i)))] 251.123 - (read (PushbackReader. pbr)) 251.124 - (str text))))))) 251.125 - 251.126 -(defmacro source 251.127 - "Prints the source code for the given symbol, if it can find it. 251.128 - This requires that the symbol resolve to a Var defined in a 251.129 - namespace for which the .clj is in the classpath. 251.130 - 251.131 - Example: (source filter)" 251.132 - {:deprecated "1.2"} 251.133 - [n] 251.134 - `(println (or (get-source '~n) (str "Source not found")))) 251.135 - 251.136 -(defn apropos 251.137 - "Given a regular expression or stringable thing, return a seq of 251.138 -all definitions in all currently-loaded namespaces that match the 251.139 -str-or-pattern." 251.140 - {:deprecated "1.2"} 251.141 - [str-or-pattern] 251.142 - (let [matches? (if (instance? java.util.regex.Pattern str-or-pattern) 251.143 - #(re-find str-or-pattern (str %)) 251.144 - #(s/substring? (str str-or-pattern) (str %)))] 251.145 - (mapcat (fn [ns] 251.146 - (filter matches? (keys (ns-publics ns)))) 251.147 - (all-ns)))) 251.148 - 251.149 -;; ---------------------------------------------------------------------- 251.150 -;; Handle Ctrl-C keystrokes 251.151 - 251.152 -(def ^{:doc "Threads to stop when Ctrl-C is pressed. See 'add-break-thread!'"} 251.153 - break-threads (atom {})) 251.154 - 251.155 -(let [first-time (atom true)] 251.156 - (defn start-handling-break 251.157 - "Register INT signal handler. After calling this, Ctrl-C will cause 251.158 - all break-threads to be stopped. See 'add-break-thread!'" 251.159 - [] 251.160 - (when (= :need-init 251.161 - (swap! first-time 251.162 - {:need-init false, false false, true :need-init})) 251.163 - (sun.misc.Signal/handle 251.164 - (sun.misc.Signal. "INT") 251.165 - (proxy [sun.misc.SignalHandler] [] 251.166 - (handle [sig] 251.167 - (let [exc (Exception. (str sig))] 251.168 - (doseq [tref (vals @break-threads) :when (.get tref)] 251.169 - (.stop (.get tref) exc))))))))) 251.170 - 251.171 -(defn add-break-thread! 251.172 - "Add the given thread to break-threads so that it will be stopped 251.173 - any time the user presses Ctrl-C. Calls start-handling-break for 251.174 - you. Adds the current thread if none is given." 251.175 - ([] (add-break-thread! (Thread/currentThread))) 251.176 - ([t] 251.177 - (start-handling-break) 251.178 - (let [tref (java.lang.ref.WeakReference. t)] 251.179 - (swap! break-threads assoc (.getId t) tref)))) 251.180 - 251.181 -;; ---------------------------------------------------------------------- 251.182 -;; Compiler hooks 251.183 - 251.184 -(defn expression-info 251.185 - "Uses the Clojure compiler to analyze the given s-expr. Returns 251.186 - a map with keys :class and :primitive? indicating what the compiler 251.187 - concluded about the return value of the expression. Returns nil if 251.188 - not type info can be determined at compile-time. 251.189 - 251.190 - Example: (expression-info '(+ (int 5) (float 10))) 251.191 - Returns: {:class float, :primitive? true}" 251.192 - [expr] 251.193 - (let [fn-ast (Compiler/analyze Compiler$C/EXPRESSION `(fn [] ~expr)) 251.194 - expr-ast (.body (first (.methods fn-ast)))] 251.195 - (when (.hasJavaClass expr-ast) 251.196 - {:class (.getJavaClass expr-ast) 251.197 - :primitive? (.isPrimitive (.getJavaClass expr-ast))}))) 251.198 - 251.199 -;; ---------------------------------------------------------------------- 251.200 -;; scgilardi at gmail 251.201 - 251.202 -(defn run* 251.203 - "Loads the specified namespace and invokes its \"main\" function with 251.204 - optional args." 251.205 - [ns-sym & args] 251.206 - (require ns-sym :reload-all) 251.207 - (apply (ns-resolve ns-sym 'main) args)) 251.208 - 251.209 -(defmacro run 251.210 - "Loads the specified namespace and invokes its \"main\" function with 251.211 - optional args. ns-name is not evaluated." 251.212 - [ns-name & args] 251.213 - `(run* '~ns-name ~@args)) 251.214 - 251.215 - 251.216 -(load "repl_utils/javadoc")
252.1 --- a/src/clojure/contrib/repl_utils/javadoc.clj Sat Aug 21 06:25:44 2010 -0400 252.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 252.3 @@ -1,83 +0,0 @@ 252.4 -; Copyright (c) Christophe Grand, November 2008. All rights reserved. 252.5 - 252.6 -; The use and distribution terms for this software are covered by the 252.7 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 252.8 -; which can be found in the file epl-v10.html at the root of this 252.9 -; distribution. 252.10 -; By using this software in any fashion, you are agreeing to be bound by 252.11 -; the terms of this license. 252.12 -; You must not remove this notice, or any other, from this software. 252.13 - 252.14 -; thanks to Stuart Sierra 252.15 - 252.16 -; a repl helper to quickly open javadocs. 252.17 - 252.18 -(def *feeling-lucky-url* "http://www.google.com/search?btnI=I%27m%20Feeling%20Lucky&q=allinurl:") 252.19 -(def *feeling-lucky* true) 252.20 - 252.21 -(def 252.22 - ^{:doc "Ref to a list of local paths for Javadoc-generated HTML 252.23 - files."} 252.24 - *local-javadocs* (ref (list))) 252.25 - 252.26 -(def *core-java-api* 252.27 - (if (= "1.5" (System/getProperty "java.specification.version")) 252.28 - "http://java.sun.com/j2se/1.5.0/docs/api/" 252.29 - "http://java.sun.com/javase/6/docs/api/")) 252.30 - 252.31 -(def 252.32 - ^{:doc "Ref to a map from package name prefixes to URLs for remote 252.33 - Javadocs."} 252.34 - *remote-javadocs* 252.35 - (ref (sorted-map 252.36 - "java." *core-java-api* 252.37 - "javax." *core-java-api* 252.38 - "org.ietf.jgss." *core-java-api* 252.39 - "org.omg." *core-java-api* 252.40 - "org.w3c.dom." *core-java-api* 252.41 - "org.xml.sax." *core-java-api* 252.42 - "org.apache.commons.codec." "http://commons.apache.org/codec/api-release/" 252.43 - "org.apache.commons.io." "http://commons.apache.org/io/api-release/" 252.44 - "org.apache.commons.lang." "http://commons.apache.org/lang/api-release/"))) 252.45 - 252.46 -(defn add-local-javadoc 252.47 - "Adds to the list of local Javadoc paths." 252.48 - [path] 252.49 - (dosync (commute *local-javadocs* conj path))) 252.50 - 252.51 -(defn add-remote-javadoc 252.52 - "Adds to the list of remote Javadoc URLs. package-prefix is the 252.53 - beginning of the package name that has docs at this URL." 252.54 - [package-prefix url] 252.55 - (dosync (commute *remote-javadocs* assoc package-prefix url))) 252.56 - 252.57 -(defn find-javadoc-url 252.58 - "Searches for a URL for the given class name. Tries 252.59 - *local-javadocs* first, then *remote-javadocs*. Returns a string." 252.60 - {:tag String} 252.61 - [^String classname] 252.62 - (let [file-path (.replace classname \. File/separatorChar) 252.63 - url-path (.replace classname \. \/)] 252.64 - (if-let [file ^File (first 252.65 - (filter #(.exists ^File %) 252.66 - (map #(File. (str %) (str file-path ".html")) 252.67 - @*local-javadocs*)))] 252.68 - (-> file .toURI str) 252.69 - ;; If no local file, try remote URLs: 252.70 - (or (some (fn [[prefix url]] 252.71 - (when (.startsWith classname prefix) 252.72 - (str url url-path ".html"))) 252.73 - @*remote-javadocs*) 252.74 - ;; if *feeling-lucky* try a web search 252.75 - (when *feeling-lucky* (str *feeling-lucky-url* url-path ".html")))))) 252.76 - 252.77 -(defn javadoc 252.78 - "Opens a browser window displaying the javadoc for the argument. 252.79 - Tries *local-javadocs* first, then *remote-javadocs*." 252.80 - [class-or-object] 252.81 - (let [^Class c (if (instance? Class class-or-object) 252.82 - class-or-object 252.83 - (class class-or-object))] 252.84 - (if-let [url (find-javadoc-url (.getName c))] 252.85 - (browse-url url) 252.86 - (println "Could not find Javadoc for" c))))
253.1 --- a/src/clojure/contrib/seq.clj Sat Aug 21 06:25:44 2010 -0400 253.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 253.3 @@ -1,238 +0,0 @@ 253.4 -;;; seq_utils.clj -- Sequence utilities for Clojure 253.5 - 253.6 -;; by Stuart Sierra, http://stuartsierra.com/ 253.7 -;; last updated March 2, 2009 253.8 - 253.9 -;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use 253.10 -;; and distribution terms for this software are covered by the Eclipse 253.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 253.12 -;; which can be found in the file epl-v10.html at the root of this 253.13 -;; distribution. By using this software in any fashion, you are 253.14 -;; agreeing to be bound by the terms of this license. You must not 253.15 -;; remove this notice, or any other, from this software. 253.16 - 253.17 - 253.18 -;; Change Log 253.19 -;; 253.20 -;; January 10, 2009 (Stuart Sierra): 253.21 -;; 253.22 -;; * BREAKING CHANGE: "includes?" now takes collection as first 253.23 -;; argument. This is more consistent with Clojure collection 253.24 -;; functions; see discussion at http://groups.google.com/group/clojure/browse_thread/thread/8b2c8dc96b39ddd7/a8866d34b601ff43 253.25 - 253.26 - 253.27 -(ns 253.28 - ^{:author "Stuart Sierra (and others)", 253.29 - :doc "Sequence utilities for Clojure"} 253.30 - clojure.contrib.seq 253.31 - (:import (java.util.concurrent LinkedBlockingQueue TimeUnit) 253.32 - (java.lang.ref WeakReference)) 253.33 - (:refer-clojure :exclude [frequencies shuffle partition-by reductions partition-all group-by flatten])) 253.34 - 253.35 - 253.36 -;; 'flatten' written by Rich Hickey, 253.37 -;; see http://groups.google.com/group/clojure/msg/385098fabfcaad9b 253.38 -(defn flatten 253.39 - "DEPRECATED. Prefer clojure.core version. 253.40 - Takes any nested combination of sequential things (lists, vectors, 253.41 - etc.) and returns their contents as a single, flat sequence. 253.42 - (flatten nil) returns nil." 253.43 - {:deprecated "1.2"} 253.44 - [x] 253.45 - (filter (complement sequential?) 253.46 - (rest (tree-seq sequential? seq x)))) 253.47 - 253.48 -(defn separate 253.49 - "Returns a vector: 253.50 - [ (filter f s), (filter (complement f) s) ]" 253.51 - [f s] 253.52 - [(filter f s) (filter (complement f) s)]) 253.53 - 253.54 -(defn indexed 253.55 - "Returns a lazy sequence of [index, item] pairs, where items come 253.56 - from 's' and indexes count up from zero. 253.57 - 253.58 - (indexed '(a b c d)) => ([0 a] [1 b] [2 c] [3 d])" 253.59 - [s] 253.60 - (map vector (iterate inc 0) s)) 253.61 - 253.62 -;; group-by written by Rich Hickey; 253.63 -;; see http://paste.lisp.org/display/64190 253.64 -(defn group-by 253.65 - "DEPRECATED. Prefer clojure.core version. 253.66 - Returns a sorted map of the elements of coll keyed by the result of 253.67 - f on each element. The value at each key will be a vector of the 253.68 - corresponding elements, in the order they appeared in coll." 253.69 - {:deprecated "1.2"} 253.70 - [f coll] 253.71 - (reduce 253.72 - (fn [ret x] 253.73 - (let [k (f x)] 253.74 - (assoc ret k (conj (get ret k []) x)))) 253.75 - (sorted-map) coll)) 253.76 - 253.77 -;; partition-by originally written by Rich Hickey; 253.78 -;; modified by Stuart Sierra 253.79 -(defn partition-by 253.80 - "DEPRECATED. Prefer clojure.core version. 253.81 - Applies f to each value in coll, splitting it each time f returns 253.82 - a new value. Returns a lazy seq of lazy seqs." 253.83 - {:deprecated "1.2"} 253.84 - [f coll] 253.85 - (when-let [s (seq coll)] 253.86 - (let [fst (first s) 253.87 - fv (f fst) 253.88 - run (cons fst (take-while #(= fv (f %)) (rest s)))] 253.89 - (lazy-seq 253.90 - (cons run (partition-by f (drop (count run) s))))))) 253.91 - 253.92 -(defn frequencies 253.93 - "DEPRECATED. Prefer clojure.core version. 253.94 - Returns a map from distinct items in coll to the number of times 253.95 - they appear." 253.96 - {:deprecated "1.2"} 253.97 - [coll] 253.98 - (reduce (fn [counts x] 253.99 - (assoc counts x (inc (get counts x 0)))) 253.100 - {} coll)) 253.101 - 253.102 -;; recursive sequence helpers by Christophe Grand 253.103 -;; see http://clj-me.blogspot.com/2009/01/recursive-seqs.html 253.104 -(defmacro rec-seq 253.105 - "Similar to lazy-seq but binds the resulting seq to the supplied 253.106 - binding-name, allowing for recursive expressions." 253.107 - [binding-name & body] 253.108 - `(let [s# (atom nil)] 253.109 - (reset! s# (lazy-seq (let [~binding-name @s#] ~@body))))) 253.110 - 253.111 -(defmacro rec-cat 253.112 - "Similar to lazy-cat but binds the resulting sequence to the supplied 253.113 - binding-name, allowing for recursive expressions." 253.114 - [binding-name & exprs] 253.115 - `(rec-seq ~binding-name (lazy-cat ~@exprs))) 253.116 - 253.117 - 253.118 -;; reductions by Chris Houser 253.119 -;; see http://groups.google.com/group/clojure/browse_thread/thread/3edf6e82617e18e0/58d9e319ad92aa5f?#58d9e319ad92aa5f 253.120 -(defn reductions 253.121 - "DEPRECATED. Prefer clojure.core version. 253.122 - Returns a lazy seq of the intermediate values of the reduction (as 253.123 - per reduce) of coll by f, starting with init." 253.124 - {:deprecated "1.2"} 253.125 - ([f coll] 253.126 - (if (seq coll) 253.127 - (rec-seq self (cons (first coll) (map f self (rest coll)))) 253.128 - (cons (f) nil))) 253.129 - ([f init coll] 253.130 - (rec-seq self (cons init (map f self coll))))) 253.131 - 253.132 -(defn rotations 253.133 - "Returns a lazy seq of all rotations of a seq" 253.134 - [x] 253.135 - (if (seq x) 253.136 - (map 253.137 - (fn [n _] 253.138 - (lazy-cat (drop n x) (take n x))) 253.139 - (iterate inc 0) x) 253.140 - (list nil))) 253.141 - 253.142 -(defn partition-all 253.143 - "DEPRECATED. Prefer clojure.core version. 253.144 - Returns a lazy sequence of lists like clojure.core/partition, but may 253.145 - include lists with fewer than n items at the end." 253.146 - {:deprecated "1.2"} 253.147 - ([n coll] 253.148 - (partition-all n n coll)) 253.149 - ([n step coll] 253.150 - (lazy-seq 253.151 - (when-let [s (seq coll)] 253.152 - (cons (take n s) (partition-all n step (drop step s))))))) 253.153 - 253.154 -(defn shuffle 253.155 - "DEPRECATED. Prefer clojure.core version. 253.156 - Return a random permutation of coll" 253.157 - {:deprecated "1.2"} 253.158 - [coll] 253.159 - (let [l (java.util.ArrayList. coll)] 253.160 - (java.util.Collections/shuffle l) 253.161 - (seq l))) 253.162 - 253.163 -(defn rand-elt 253.164 - "DEPRECATED. Prefer clojure.core/rand-nth. 253.165 - Return a random element of this seq" 253.166 - {:deprecated "1.2"} 253.167 - [s] 253.168 - (nth s (rand-int (count s)))) 253.169 - 253.170 -;; seq-on written by Konrad Hinsen 253.171 -(defmulti seq-on 253.172 - "Returns a seq on the object s. Works like the built-in seq but as 253.173 - a multimethod that can have implementations for new classes and types." 253.174 - {:arglists '([s])} 253.175 - type) 253.176 - 253.177 -(defmethod seq-on :default 253.178 - [s] 253.179 - (seq s)) 253.180 - 253.181 - 253.182 -(defn find-first 253.183 - "Returns the first item of coll for which (pred item) returns logical true. 253.184 - Consumes sequences up to the first match, will consume the entire sequence 253.185 - and return nil if no match is found." 253.186 - [pred coll] 253.187 - (first (filter pred coll))) 253.188 - 253.189 -; based on work related to Rich Hickey's seque. 253.190 -; blame Chouser for anything broken or ugly. 253.191 -(defn fill-queue 253.192 - "filler-func will be called in another thread with a single arg 253.193 - 'fill'. filler-func may call fill repeatedly with one arg each 253.194 - time which will be pushed onto a queue, blocking if needed until 253.195 - this is possible. fill-queue will return a lazy seq of the values 253.196 - filler-func has pushed onto the queue, blocking if needed until each 253.197 - next element becomes available. filler-func's return value is ignored." 253.198 - ([filler-func & optseq] 253.199 - (let [opts (apply array-map optseq) 253.200 - apoll (:alive-poll opts 1) 253.201 - q (LinkedBlockingQueue. (:queue-size opts 1)) 253.202 - NIL (Object.) ;nil sentinel since LBQ doesn't support nils 253.203 - weak-target (Object.) 253.204 - alive? (WeakReference. weak-target) 253.205 - fill (fn fill [x] 253.206 - (if (.get alive?) 253.207 - (if (.offer q (if (nil? x) NIL x) apoll TimeUnit/SECONDS) 253.208 - x 253.209 - (recur x)) 253.210 - (throw (Exception. "abandoned")))) 253.211 - f (future 253.212 - (try 253.213 - (filler-func fill) 253.214 - (finally 253.215 - (.put q q))) ;q itself is eos sentinel 253.216 - nil)] ; set future's value to nil 253.217 - ((fn drain [] 253.218 - weak-target ; force closing over this object 253.219 - (lazy-seq 253.220 - (let [x (.take q)] 253.221 - (if (identical? x q) 253.222 - @f ;will be nil, touch just to propagate errors 253.223 - (cons (if (identical? x NIL) nil x) 253.224 - (drain)))))))))) 253.225 - 253.226 -(defn positions 253.227 - "Returns a lazy sequence containing the positions at which pred 253.228 - is true for items in coll." 253.229 - [pred coll] 253.230 - (for [[idx elt] (indexed coll) :when (pred elt)] idx)) 253.231 - 253.232 -(defn includes? 253.233 - "Returns true if coll contains something equal (with =) to x, 253.234 - in linear time. Deprecated. Prefer 'contains?' for key testing, 253.235 - or 'some' for ad hoc linear searches." 253.236 - {:deprecated "1.2"} 253.237 - [coll x] 253.238 - (boolean (some (fn [y] (= y x)) coll))) 253.239 - 253.240 - 253.241 -
254.1 --- a/src/clojure/contrib/seq_utils.clj Sat Aug 21 06:25:44 2010 -0400 254.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 254.3 @@ -1,244 +0,0 @@ 254.4 -;;; seq_utils.clj -- Sequence utilities for Clojure 254.5 - 254.6 -;; by Stuart Sierra, http://stuartsierra.com/ 254.7 -;; last updated March 2, 2009 254.8 - 254.9 -;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use 254.10 -;; and distribution terms for this software are covered by the Eclipse 254.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 254.12 -;; which can be found in the file epl-v10.html at the root of this 254.13 -;; distribution. By using this software in any fashion, you are 254.14 -;; agreeing to be bound by the terms of this license. You must not 254.15 -;; remove this notice, or any other, from this software. 254.16 - 254.17 - 254.18 -;; Change Log 254.19 -;; 254.20 -;; DEPRECATED in 1.2. Some functions promoted to clojure.core and some 254.21 -;; moved to c.c.seq 254.22 -;; 254.23 -;; January 10, 2009 (Stuart Sierra): 254.24 -;; 254.25 -;; * BREAKING CHANGE: "includes?" now takes collection as first 254.26 -;; argument. This is more consistent with Clojure collection 254.27 -;; functions; see discussion at http://groups.google.com/group/clojure/browse_thread/thread/8b2c8dc96b39ddd7/a8866d34b601ff43 254.28 -;; 254.29 - 254.30 -(ns 254.31 - ^{:author "Stuart Sierra (and others)", 254.32 - :deprecated "1.2" 254.33 - :doc "Sequence utilities for Clojure"} 254.34 - clojure.contrib.seq-utils 254.35 - (:import (java.util.concurrent LinkedBlockingQueue TimeUnit) 254.36 - (java.lang.ref WeakReference)) 254.37 - (:refer-clojure :exclude [frequencies shuffle partition-by reductions partition-all group-by flatten])) 254.38 - 254.39 - 254.40 -;; 'flatten' written by Rich Hickey, 254.41 -;; see http://groups.google.com/group/clojure/msg/385098fabfcaad9b 254.42 -(defn flatten 254.43 - "DEPRECATED. Prefer clojure.core version. 254.44 - Takes any nested combination of sequential things (lists, vectors, 254.45 - etc.) and returns their contents as a single, flat sequence. 254.46 - (flatten nil) returns nil." 254.47 - {:deprecated "1.2"} 254.48 - [x] 254.49 - (filter (complement sequential?) 254.50 - (rest (tree-seq sequential? seq x)))) 254.51 - 254.52 -(defn separate 254.53 - "Returns a vector: 254.54 - [ (filter f s), (filter (complement f) s) ]" 254.55 - [f s] 254.56 - [(filter f s) (filter (complement f) s)]) 254.57 - 254.58 -(defn indexed 254.59 - "Returns a lazy sequence of [index, item] pairs, where items come 254.60 - from 's' and indexes count up from zero. 254.61 - 254.62 - (indexed '(a b c d)) => ([0 a] [1 b] [2 c] [3 d])" 254.63 - [s] 254.64 - (map vector (iterate inc 0) s)) 254.65 - 254.66 -;; group-by written by Rich Hickey; 254.67 -;; see http://paste.lisp.org/display/64190 254.68 -(defn group-by 254.69 - "DEPRECATED. Prefer clojure.core version. 254.70 - Returns a sorted map of the elements of coll keyed by the result of 254.71 - f on each element. The value at each key will be a vector of the 254.72 - corresponding elements, in the order they appeared in coll." 254.73 - {:deprecated "1.2"} 254.74 - [f coll] 254.75 - (reduce 254.76 - (fn [ret x] 254.77 - (let [k (f x)] 254.78 - (assoc ret k (conj (get ret k []) x)))) 254.79 - (sorted-map) coll)) 254.80 - 254.81 -;; partition-by originally written by Rich Hickey; 254.82 -;; modified by Stuart Sierra 254.83 -(defn partition-by 254.84 - "DEPRECATED. Prefer clojure.core version. 254.85 - Applies f to each value in coll, splitting it each time f returns 254.86 - a new value. Returns a lazy seq of lazy seqs." 254.87 - {:deprecated "1.2"} 254.88 - [f coll] 254.89 - (when-let [s (seq coll)] 254.90 - (let [fst (first s) 254.91 - fv (f fst) 254.92 - run (cons fst (take-while #(= fv (f %)) (rest s)))] 254.93 - (lazy-seq 254.94 - (cons run (partition-by f (drop (count run) s))))))) 254.95 - 254.96 -(defn frequencies 254.97 - "DEPRECATED. Prefer clojure.core version. 254.98 - Returns a map from distinct items in coll to the number of times 254.99 - they appear." 254.100 - {:deprecated "1.2"} 254.101 - [coll] 254.102 - (reduce (fn [counts x] 254.103 - (assoc counts x (inc (get counts x 0)))) 254.104 - {} coll)) 254.105 - 254.106 -;; recursive sequence helpers by Christophe Grand 254.107 -;; see http://clj-me.blogspot.com/2009/01/recursive-seqs.html 254.108 -(defmacro rec-seq 254.109 - "Similar to lazy-seq but binds the resulting seq to the supplied 254.110 - binding-name, allowing for recursive expressions." 254.111 - [binding-name & body] 254.112 - `(let [s# (atom nil)] 254.113 - (reset! s# (lazy-seq (let [~binding-name @s#] ~@body))))) 254.114 - 254.115 -(defmacro rec-cat 254.116 - "Similar to lazy-cat but binds the resulting sequence to the supplied 254.117 - binding-name, allowing for recursive expressions." 254.118 - [binding-name & exprs] 254.119 - `(rec-seq ~binding-name (lazy-cat ~@exprs))) 254.120 - 254.121 - 254.122 -;; reductions by Chris Houser 254.123 -;; see http://groups.google.com/group/clojure/browse_thread/thread/3edf6e82617e18e0/58d9e319ad92aa5f?#58d9e319ad92aa5f 254.124 -(defn reductions 254.125 - "DEPRECATED. Prefer clojure.core version. 254.126 - Returns a lazy seq of the intermediate values of the reduction (as 254.127 - per reduce) of coll by f, starting with init." 254.128 - {:deprecated "1.2"} 254.129 - ([f coll] 254.130 - (if (seq coll) 254.131 - (rec-seq self (cons (first coll) (map f self (rest coll)))) 254.132 - (cons (f) nil))) 254.133 - ([f init coll] 254.134 - (rec-seq self (cons init (map f self coll))))) 254.135 - 254.136 -(defn rotations 254.137 - "Returns a lazy seq of all rotations of a seq" 254.138 - [x] 254.139 - (if (seq x) 254.140 - (map 254.141 - (fn [n _] 254.142 - (lazy-cat (drop n x) (take n x))) 254.143 - (iterate inc 0) x) 254.144 - (list nil))) 254.145 - 254.146 -(defn partition-all 254.147 - "DEPRECATED. Prefer clojure.core version. 254.148 - Returns a lazy sequence of lists like clojure.core/partition, but may 254.149 - include lists with fewer than n items at the end." 254.150 - {:deprecated "1.2"} 254.151 - ([n coll] 254.152 - (partition-all n n coll)) 254.153 - ([n step coll] 254.154 - (lazy-seq 254.155 - (when-let [s (seq coll)] 254.156 - (cons (take n s) (partition-all n step (drop step s))))))) 254.157 - 254.158 -(defn shuffle 254.159 - "DEPRECATED. Prefer clojure.core version. 254.160 - Return a random permutation of coll" 254.161 - {:deprecated "1.2"} 254.162 - [coll] 254.163 - (let [l (java.util.ArrayList. coll)] 254.164 - (java.util.Collections/shuffle l) 254.165 - (seq l))) 254.166 - 254.167 -(defn rand-elt 254.168 - "DEPRECATED. Prefer clojure.core/rand-nth. 254.169 - Return a random element of this seq" 254.170 - {:deprecated "1.2"} 254.171 - [s] 254.172 - (nth s (rand-int (count s)))) 254.173 - 254.174 - 254.175 -;; seq-on written by Konrad Hinsen 254.176 -(defmulti seq-on 254.177 - "Returns a seq on the object s. Works like the built-in seq but as 254.178 - a multimethod that can have implementations for new classes and types." 254.179 - {:arglists '([s])} 254.180 - type) 254.181 - 254.182 -(defmethod seq-on :default 254.183 - [s] 254.184 - (seq s)) 254.185 - 254.186 - 254.187 -(defn find-first 254.188 - "Returns the first item of coll for which (pred item) returns logical true. 254.189 - Consumes sequences up to the first match, will consume the entire sequence 254.190 - and return nil if no match is found." 254.191 - [pred coll] 254.192 - (first (filter pred coll))) 254.193 - 254.194 -; based on work related to Rich Hickey's seque. 254.195 -; blame Chouser for anything broken or ugly. 254.196 -(defn fill-queue 254.197 - "filler-func will be called in another thread with a single arg 254.198 - 'fill'. filler-func may call fill repeatedly with one arg each 254.199 - time which will be pushed onto a queue, blocking if needed until 254.200 - this is possible. fill-queue will return a lazy seq of the values 254.201 - filler-func has pushed onto the queue, blocking if needed until each 254.202 - next element becomes available. filler-func's return value is ignored." 254.203 - ([filler-func & optseq] 254.204 - (let [opts (apply array-map optseq) 254.205 - apoll (:alive-poll opts 1) 254.206 - q (LinkedBlockingQueue. (:queue-size opts 1)) 254.207 - NIL (Object.) ;nil sentinel since LBQ doesn't support nils 254.208 - weak-target (Object.) 254.209 - alive? (WeakReference. weak-target) 254.210 - fill (fn fill [x] 254.211 - (if (.get alive?) 254.212 - (if (.offer q (if (nil? x) NIL x) apoll TimeUnit/SECONDS) 254.213 - x 254.214 - (recur x)) 254.215 - (throw (Exception. "abandoned")))) 254.216 - f (future 254.217 - (try 254.218 - (filler-func fill) 254.219 - (finally 254.220 - (.put q q))) ;q itself is eos sentinel 254.221 - nil)] ; set future's value to nil 254.222 - ((fn drain [] 254.223 - weak-target ; force closing over this object 254.224 - (lazy-seq 254.225 - (let [x (.take q)] 254.226 - (if (identical? x q) 254.227 - @f ;will be nil, touch just to propagate errors 254.228 - (cons (if (identical? x NIL) nil x) 254.229 - (drain)))))))))) 254.230 - 254.231 -(defn positions 254.232 - "Returns a lazy sequence containing the positions at which pred 254.233 - is true for items in coll." 254.234 - [pred coll] 254.235 - (for [[idx elt] (indexed coll) :when (pred elt)] idx)) 254.236 - 254.237 -(defn includes? 254.238 - "Returns true if coll contains something equal (with =) to x, 254.239 - in linear time. Deprecated. Prefer 'contains?' for key testing, 254.240 - or 'some' for ad hoc linear searches." 254.241 - {:deprecated "1.2"} 254.242 - [coll x] 254.243 - (boolean (some (fn [y] (= y x)) coll))) 254.244 - 254.245 - 254.246 - 254.247 -
255.1 --- a/src/clojure/contrib/server_socket.clj Sat Aug 21 06:25:44 2010 -0400 255.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 255.3 @@ -1,94 +0,0 @@ 255.4 -;; Copyright (c) Craig McDaniel, Jan 2009. All rights reserved. 255.5 -;; The use and distribution terms for this software are covered by the 255.6 -;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 255.7 -;; which can be found in the file epl-v10.html at the root of this distribution. 255.8 -;; By using this software in any fashion, you are agreeing to be bound by 255.9 -;; the terms of this license. 255.10 -;; You must not remove this notice, or any other, from this software. 255.11 - 255.12 -;; Server socket library - includes REPL on socket 255.13 - 255.14 -(ns 255.15 - ^{:author "Craig McDaniel", 255.16 - :doc "Server socket library - includes REPL on socket"} 255.17 - clojure.contrib.server-socket 255.18 - (:import (java.net InetAddress ServerSocket Socket SocketException) 255.19 - (java.io InputStreamReader OutputStream OutputStreamWriter PrintWriter) 255.20 - (clojure.lang LineNumberingPushbackReader)) 255.21 - (:use [clojure.main :only (repl)])) 255.22 - 255.23 -(defn- on-thread [f] 255.24 - (doto (Thread. ^Runnable f) 255.25 - (.start))) 255.26 - 255.27 -(defn- close-socket [^Socket s] 255.28 - (when-not (.isClosed s) 255.29 - (doto s 255.30 - (.shutdownInput) 255.31 - (.shutdownOutput) 255.32 - (.close)))) 255.33 - 255.34 -(defn- accept-fn [^Socket s connections fun] 255.35 - (let [ins (.getInputStream s) 255.36 - outs (.getOutputStream s)] 255.37 - (on-thread #(do 255.38 - (dosync (commute connections conj s)) 255.39 - (try 255.40 - (fun ins outs) 255.41 - (catch SocketException e)) 255.42 - (close-socket s) 255.43 - (dosync (commute connections disj s)))))) 255.44 - 255.45 -(defstruct server-def :server-socket :connections) 255.46 - 255.47 -(defn- create-server-aux [fun ^ServerSocket ss] 255.48 - (let [connections (ref #{})] 255.49 - (on-thread #(when-not (.isClosed ss) 255.50 - (try 255.51 - (accept-fn (.accept ss) connections fun) 255.52 - (catch SocketException e)) 255.53 - (recur))) 255.54 - (struct-map server-def :server-socket ss :connections connections))) 255.55 - 255.56 -(defn create-server 255.57 - "Creates a server socket on port. Upon accept, a new thread is 255.58 - created which calls: 255.59 - 255.60 - (fun input-stream output-stream) 255.61 - 255.62 - Optional arguments support specifying a listen backlog and binding 255.63 - to a specific endpoint." 255.64 - ([port fun backlog ^InetAddress bind-addr] 255.65 - (create-server-aux fun (ServerSocket. port backlog bind-addr))) 255.66 - ([port fun backlog] 255.67 - (create-server-aux fun (ServerSocket. port backlog))) 255.68 - ([port fun] 255.69 - (create-server-aux fun (ServerSocket. port)))) 255.70 - 255.71 -(defn close-server [server] 255.72 - (doseq [s @(:connections server)] 255.73 - (close-socket s)) 255.74 - (dosync (ref-set (:connections server) #{})) 255.75 - (.close ^ServerSocket (:server-socket server))) 255.76 - 255.77 -(defn connection-count [server] 255.78 - (count @(:connections server))) 255.79 - 255.80 -;;;; 255.81 -;;;; REPL on a socket 255.82 -;;;; 255.83 - 255.84 -(defn- socket-repl [ins outs] 255.85 - (binding [*in* (LineNumberingPushbackReader. (InputStreamReader. ins)) 255.86 - *out* (OutputStreamWriter. outs) 255.87 - *err* (PrintWriter. ^OutputStream outs true)] 255.88 - (repl))) 255.89 - 255.90 -(defn create-repl-server 255.91 - "create a repl on a socket" 255.92 - ([port backlog ^InetAddress bind-addr] 255.93 - (create-server port socket-repl backlog bind-addr)) 255.94 - ([port backlog] 255.95 - (create-server port socket-repl backlog)) 255.96 - ([port] 255.97 - (create-server port socket-repl)))
256.1 --- a/src/clojure/contrib/set.clj Sat Aug 21 06:25:44 2010 -0400 256.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 256.3 @@ -1,52 +0,0 @@ 256.4 -;; Copyright (c) Jason Wolfe. All rights reserved. The use and 256.5 -;; distribution terms for this software are covered by the Eclipse Public 256.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 256.7 -;; be found in the file epl-v10.html at the root of this distribution. By 256.8 -;; using this software in any fashion, you are agreeing to be bound by the 256.9 -;; terms of this license. You must not remove this notice, or any other, 256.10 -;; from this software. 256.11 -;; 256.12 -;; set.clj 256.13 -;; 256.14 -;; Clojure functions for operating on sets (supplemental to clojure.set) 256.15 -;; 256.16 -;; jason at w01fe dot com 256.17 -;; Created 2 Feb 2009 256.18 - 256.19 -;; Deprecations in 1.2: subset and superset have been promoted to 256.20 -;; clojure.set 256.21 - 256.22 -(ns 256.23 - ^{:author "Jason Wolfe", 256.24 - :doc "Clojure functions for operating on sets (supplemental to clojure.set)"} 256.25 - clojure.contrib.set) 256.26 - 256.27 -(defn subset? 256.28 - "Is set1 a subset of set2?" 256.29 - {:deprecated "1.2"} 256.30 - [set1 set2] 256.31 - {:tag Boolean} 256.32 - (and (<= (count set1) (count set2)) 256.33 - (every? set2 set1))) 256.34 - 256.35 -(defn superset? 256.36 - "Is set1 a superset of set2?" 256.37 - {:deprecated "1.2"} 256.38 - [set1 set2] 256.39 - {:tag Boolean} 256.40 - (and (>= (count set1) (count set2)) 256.41 - (every? set1 set2))) 256.42 - 256.43 -(defn proper-subset? 256.44 - "Is s1 a proper subset of s2?" 256.45 - [set1 set2] 256.46 - {:tag Boolean} 256.47 - (and (< (count set1) (count set2)) 256.48 - (every? set2 set1))) 256.49 - 256.50 -(defn proper-superset? 256.51 - "Is s1 a proper superset of s2?" 256.52 - [set1 set2] 256.53 - {:tag Boolean} 256.54 - (and (> (count set1) (count set2)) 256.55 - (every? set1 set2)))
257.1 --- a/src/clojure/contrib/shell.clj Sat Aug 21 06:25:44 2010 -0400 257.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 257.3 @@ -1,149 +0,0 @@ 257.4 -; Copyright (c) Chris Houser, Jan 2009. All rights reserved. 257.5 -; The use and distribution terms for this software are covered by the 257.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 257.7 -; which can be found in the file epl-v10.html at the root of this distribution. 257.8 -; By using this software in any fashion, you are agreeing to be bound by 257.9 -; the terms of this license. 257.10 -; You must not remove this notice, or any other, from this software. 257.11 - 257.12 -; :dir and :env options added by Stuart Halloway 257.13 - 257.14 -; Conveniently launch a sub-process providing to its stdin and 257.15 -; collecting its stdout 257.16 - 257.17 -;; DEPRECATED in 1.2: Promoted to clojure.java.shell 257.18 - 257.19 -(ns 257.20 - ^{:author "Chris Houser", 257.21 - :deprecated "1.2" 257.22 - :doc "Conveniently launch a sub-process providing to its stdin and 257.23 -collecting its stdout"} 257.24 - clojure.contrib.shell 257.25 - (:import (java.io InputStreamReader OutputStreamWriter))) 257.26 - 257.27 -(def *sh-dir* nil) 257.28 -(def *sh-env* nil) 257.29 - 257.30 -(defmacro with-sh-dir [dir & forms] 257.31 - "Sets the directory for use with sh, see sh for details." 257.32 - `(binding [*sh-dir* ~dir] 257.33 - ~@forms)) 257.34 - 257.35 -(defmacro with-sh-env [env & forms] 257.36 - "Sets the environment for use with sh, see sh for details." 257.37 - `(binding [*sh-env* ~env] 257.38 - ~@forms)) 257.39 - 257.40 -(defn- stream-seq 257.41 - "Takes an InputStream and returns a lazy seq of integers from the stream." 257.42 - [stream] 257.43 - (take-while #(>= % 0) (repeatedly #(.read stream)))) 257.44 - 257.45 -(defn- aconcat 257.46 - "Concatenates arrays of given type." 257.47 - [type & xs] 257.48 - (let [target (make-array type (apply + (map count xs)))] 257.49 - (loop [i 0 idx 0] 257.50 - (when-let [a (nth xs i nil)] 257.51 - (System/arraycopy a 0 target idx (count a)) 257.52 - (recur (inc i) (+ idx (count a))))) 257.53 - target)) 257.54 - 257.55 -(defn- parse-args 257.56 - "Takes a seq of 'sh' arguments and returns a map of option keywords 257.57 - to option values." 257.58 - [args] 257.59 - (loop [[arg :as args] args opts {:cmd [] :out "UTF-8" :dir *sh-dir* :env *sh-env*}] 257.60 - (if-not args 257.61 - opts 257.62 - (if (keyword? arg) 257.63 - (recur (nnext args) (assoc opts arg (second args))) 257.64 - (recur (next args) (update-in opts [:cmd] conj arg)))))) 257.65 - 257.66 -(defn- as-env-key [arg] 257.67 - "Helper so that callers can use symbols, keywords, or strings 257.68 - when building an environment map." 257.69 - (cond 257.70 - (symbol? arg) (name arg) 257.71 - (keyword? arg) (name arg) 257.72 - (string? arg) arg)) 257.73 - 257.74 -(defn- as-file [arg] 257.75 - "Helper so that callers can pass a String for the :dir to sh." 257.76 - (cond 257.77 - (string? arg) (java.io.File. arg) 257.78 - (nil? arg) nil 257.79 - (instance? java.io.File arg) arg)) 257.80 - 257.81 -(defn- as-env-string [arg] 257.82 - "Helper so that callers can pass a Clojure map for the :env to sh." 257.83 - (cond 257.84 - (nil? arg) nil 257.85 - (map? arg) (into-array String (map (fn [[k v]] (str (as-env-key k) "=" v)) arg)) 257.86 - true arg)) 257.87 - 257.88 - 257.89 -(defn sh 257.90 - "Passes the given strings to Runtime.exec() to launch a sub-process. 257.91 - 257.92 - Options are 257.93 - 257.94 - :in may be given followed by a String specifying text to be fed to the 257.95 - sub-process's stdin. 257.96 - :out option may be given followed by :bytes or a String. If a String 257.97 - is given, it will be used as a character encoding name (for 257.98 - example \"UTF-8\" or \"ISO-8859-1\") to convert the 257.99 - sub-process's stdout to a String which is returned. 257.100 - If :bytes is given, the sub-process's stdout will be stored in 257.101 - a byte array and returned. Defaults to UTF-8. 257.102 - :return-map 257.103 - when followed by boolean true, sh returns a map of 257.104 - :exit => sub-process's exit code 257.105 - :out => sub-process's stdout (as byte[] or String) 257.106 - :err => sub-process's stderr (as byte[] or String) 257.107 - when not given or followed by false, sh returns a single 257.108 - array or String of the sub-process's stdout followed by its 257.109 - stderr 257.110 - :env override the process env with a map (or the underlying Java 257.111 - String[] if you are a masochist). 257.112 - :dir override the process dir with a String or java.io.File. 257.113 - 257.114 - You can bind :env or :dir for multiple operations using with-sh-env 257.115 - and with-sh-dir." 257.116 - [& args] 257.117 - (let [opts (parse-args args) 257.118 - proc (.exec (Runtime/getRuntime) 257.119 - (into-array (:cmd opts)) 257.120 - (as-env-string (:env opts)) 257.121 - (as-file (:dir opts)))] 257.122 - (if (:in opts) 257.123 - (with-open [osw (OutputStreamWriter. (.getOutputStream proc))] 257.124 - (.write osw (:in opts))) 257.125 - (.close (.getOutputStream proc))) 257.126 - (with-open [stdout (.getInputStream proc) 257.127 - stderr (.getErrorStream proc)] 257.128 - (let [[[out err] combine-fn] 257.129 - (if (= (:out opts) :bytes) 257.130 - [(for [strm [stdout stderr]] 257.131 - (into-array Byte/TYPE (map byte (stream-seq strm)))) 257.132 - #(aconcat Byte/TYPE %1 %2)] 257.133 - [(for [strm [stdout stderr]] 257.134 - (apply str (map char (stream-seq 257.135 - (InputStreamReader. strm (:out opts)))))) 257.136 - str]) 257.137 - exit-code (.waitFor proc)] 257.138 - (if (:return-map opts) 257.139 - {:exit exit-code :out out :err err} 257.140 - (combine-fn out err)))))) 257.141 - 257.142 -(comment 257.143 - 257.144 -(println (sh "ls" "-l")) 257.145 -(println (sh "ls" "-l" "/no-such-thing")) 257.146 -(println (sh "sed" "s/[aeiou]/oo/g" :in "hello there\n")) 257.147 -(println (sh "cat" :in "x\u25bax\n")) 257.148 -(println (sh "echo" "x\u25bax")) 257.149 -(println (sh "echo" "x\u25bax" :out "ISO-8859-1")) ; reads 4 single-byte chars 257.150 -(println (sh "cat" "myimage.png" :out :bytes)) ; reads binary file into bytes[] 257.151 - 257.152 -)
258.1 --- a/src/clojure/contrib/shell_out.clj Sat Aug 21 06:25:44 2010 -0400 258.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 258.3 @@ -1,149 +0,0 @@ 258.4 -; Copyright (c) Chris Houser, Jan 2009. All rights reserved. 258.5 -; The use and distribution terms for this software are covered by the 258.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 258.7 -; which can be found in the file epl-v10.html at the root of this distribution. 258.8 -; By using this software in any fashion, you are agreeing to be bound by 258.9 -; the terms of this license. 258.10 -; You must not remove this notice, or any other, from this software. 258.11 - 258.12 -; :dir and :env options added by Stuart Halloway 258.13 - 258.14 -; Conveniently launch a sub-process providing to its stdin and 258.15 -; collecting its stdout 258.16 - 258.17 -;; DEPRECATED in 1.2: Promoted to clojure.java.shell 258.18 - 258.19 -(ns 258.20 - ^{:author "Chris Houser", 258.21 - :deprecated "1.2" 258.22 - :doc "Conveniently launch a sub-process providing to its stdin and 258.23 -collecting its stdout"} 258.24 - clojure.contrib.shell-out 258.25 - (:import (java.io InputStreamReader OutputStreamWriter))) 258.26 - 258.27 -(def *sh-dir* nil) 258.28 -(def *sh-env* nil) 258.29 - 258.30 -(defmacro with-sh-dir [dir & forms] 258.31 - "Sets the directory for use with sh, see sh for details." 258.32 - `(binding [*sh-dir* ~dir] 258.33 - ~@forms)) 258.34 - 258.35 -(defmacro with-sh-env [env & forms] 258.36 - "Sets the environment for use with sh, see sh for details." 258.37 - `(binding [*sh-env* ~env] 258.38 - ~@forms)) 258.39 - 258.40 -(defn- stream-seq 258.41 - "Takes an InputStream and returns a lazy seq of integers from the stream." 258.42 - [stream] 258.43 - (take-while #(>= % 0) (repeatedly #(.read stream)))) 258.44 - 258.45 -(defn- aconcat 258.46 - "Concatenates arrays of given type." 258.47 - [type & xs] 258.48 - (let [target (make-array type (apply + (map count xs)))] 258.49 - (loop [i 0 idx 0] 258.50 - (when-let [a (nth xs i nil)] 258.51 - (System/arraycopy a 0 target idx (count a)) 258.52 - (recur (inc i) (+ idx (count a))))) 258.53 - target)) 258.54 - 258.55 -(defn- parse-args 258.56 - "Takes a seq of 'sh' arguments and returns a map of option keywords 258.57 - to option values." 258.58 - [args] 258.59 - (loop [[arg :as args] args opts {:cmd [] :out "UTF-8" :dir *sh-dir* :env *sh-env*}] 258.60 - (if-not args 258.61 - opts 258.62 - (if (keyword? arg) 258.63 - (recur (nnext args) (assoc opts arg (second args))) 258.64 - (recur (next args) (update-in opts [:cmd] conj arg)))))) 258.65 - 258.66 -(defn- as-env-key [arg] 258.67 - "Helper so that callers can use symbols, keywords, or strings 258.68 - when building an environment map." 258.69 - (cond 258.70 - (symbol? arg) (name arg) 258.71 - (keyword? arg) (name arg) 258.72 - (string? arg) arg)) 258.73 - 258.74 -(defn- as-file [arg] 258.75 - "Helper so that callers can pass a String for the :dir to sh." 258.76 - (cond 258.77 - (string? arg) (java.io.File. arg) 258.78 - (nil? arg) nil 258.79 - (instance? java.io.File arg) arg)) 258.80 - 258.81 -(defn- as-env-string [arg] 258.82 - "Helper so that callers can pass a Clojure map for the :env to sh." 258.83 - (cond 258.84 - (nil? arg) nil 258.85 - (map? arg) (into-array String (map (fn [[k v]] (str (as-env-key k) "=" v)) arg)) 258.86 - true arg)) 258.87 - 258.88 - 258.89 -(defn sh 258.90 - "Passes the given strings to Runtime.exec() to launch a sub-process. 258.91 - 258.92 - Options are 258.93 - 258.94 - :in may be given followed by a String specifying text to be fed to the 258.95 - sub-process's stdin. 258.96 - :out option may be given followed by :bytes or a String. If a String 258.97 - is given, it will be used as a character encoding name (for 258.98 - example \"UTF-8\" or \"ISO-8859-1\") to convert the 258.99 - sub-process's stdout to a String which is returned. 258.100 - If :bytes is given, the sub-process's stdout will be stored in 258.101 - a byte array and returned. Defaults to UTF-8. 258.102 - :return-map 258.103 - when followed by boolean true, sh returns a map of 258.104 - :exit => sub-process's exit code 258.105 - :out => sub-process's stdout (as byte[] or String) 258.106 - :err => sub-process's stderr (as byte[] or String) 258.107 - when not given or followed by false, sh returns a single 258.108 - array or String of the sub-process's stdout followed by its 258.109 - stderr 258.110 - :env override the process env with a map (or the underlying Java 258.111 - String[] if you are a masochist). 258.112 - :dir override the process dir with a String or java.io.File. 258.113 - 258.114 - You can bind :env or :dir for multiple operations using with-sh-env 258.115 - and with-sh-dir." 258.116 - [& args] 258.117 - (let [opts (parse-args args) 258.118 - proc (.exec (Runtime/getRuntime) 258.119 - (into-array (:cmd opts)) 258.120 - (as-env-string (:env opts)) 258.121 - (as-file (:dir opts)))] 258.122 - (if (:in opts) 258.123 - (with-open [osw (OutputStreamWriter. (.getOutputStream proc))] 258.124 - (.write osw (:in opts))) 258.125 - (.close (.getOutputStream proc))) 258.126 - (with-open [stdout (.getInputStream proc) 258.127 - stderr (.getErrorStream proc)] 258.128 - (let [[[out err] combine-fn] 258.129 - (if (= (:out opts) :bytes) 258.130 - [(for [strm [stdout stderr]] 258.131 - (into-array Byte/TYPE (map byte (stream-seq strm)))) 258.132 - #(aconcat Byte/TYPE %1 %2)] 258.133 - [(for [strm [stdout stderr]] 258.134 - (apply str (map char (stream-seq 258.135 - (InputStreamReader. strm (:out opts)))))) 258.136 - str]) 258.137 - exit-code (.waitFor proc)] 258.138 - (if (:return-map opts) 258.139 - {:exit exit-code :out out :err err} 258.140 - (combine-fn out err)))))) 258.141 - 258.142 -(comment 258.143 - 258.144 -(println (sh "ls" "-l")) 258.145 -(println (sh "ls" "-l" "/no-such-thing")) 258.146 -(println (sh "sed" "s/[aeiou]/oo/g" :in "hello there\n")) 258.147 -(println (sh "cat" :in "x\u25bax\n")) 258.148 -(println (sh "echo" "x\u25bax")) 258.149 -(println (sh "echo" "x\u25bax" :out "ISO-8859-1")) ; reads 4 single-byte chars 258.150 -(println (sh "cat" "myimage.png" :out :bytes)) ; reads binary file into bytes[] 258.151 - 258.152 -)
259.1 --- a/src/clojure/contrib/singleton.clj Sat Aug 21 06:25:44 2010 -0400 259.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 259.3 @@ -1,54 +0,0 @@ 259.4 -;;; singleton.clj: singleton functions 259.5 - 259.6 -;; by Stuart Sierra, http://stuartsierra.com/ 259.7 -;; April 14, 2009 259.8 - 259.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 259.10 -;; and distribution terms for this software are covered by the Eclipse 259.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 259.12 -;; which can be found in the file epl-v10.html at the root of this 259.13 -;; distribution. By using this software in any fashion, you are 259.14 -;; agreeing to be bound by the terms of this license. You must not 259.15 -;; remove this notice, or any other, from this software. 259.16 - 259.17 - 259.18 -;; Change Log: 259.19 -;; 259.20 -;; April 14, 2009: added per-thread-singleton, renamed singleton to 259.21 -;; global-singleton 259.22 -;; 259.23 -;; April 9, 2009: initial version 259.24 - 259.25 - 259.26 -(ns 259.27 - ^{:author "Stuart Sierra", 259.28 - :doc "Singleton functions"} 259.29 - clojure.contrib.singleton) 259.30 - 259.31 -(defn global-singleton 259.32 - "Returns a global singleton function. f is a function of no 259.33 - arguments that creates and returns some object. The singleton 259.34 - function will call f just once, the first time it is needed, and 259.35 - cache the value for all subsequent calls. 259.36 - 259.37 - Warning: global singletons are often unsafe in multi-threaded code. 259.38 - Consider per-thread-singleton instead." 259.39 - [f] 259.40 - (let [instance (atom nil) 259.41 - make-instance (fn [_] (f))] 259.42 - (fn [] (or @instance (swap! instance make-instance))))) 259.43 - 259.44 -(defn per-thread-singleton 259.45 - "Returns a per-thread singleton function. f is a function of no 259.46 - arguments that creates and returns some object. The singleton 259.47 - function will call f only once for each thread, and cache its value 259.48 - for subsequent calls from the same thread. This allows you to 259.49 - safely and lazily initialize shared objects on a per-thread basis. 259.50 - 259.51 - Warning: due to a bug in JDK 5, it may not be safe to use a 259.52 - per-thread-singleton in the initialization function for another 259.53 - per-thread-singleton. See 259.54 - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5025230" 259.55 - [f] 259.56 - (let [thread-local (proxy [ThreadLocal] [] (initialValue [] (f)))] 259.57 - (fn [] (.get thread-local))))
260.1 --- a/src/clojure/contrib/sql.clj Sat Aug 21 06:25:44 2010 -0400 260.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 260.3 @@ -1,201 +0,0 @@ 260.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 260.5 -;; distribution terms for this software are covered by the Eclipse Public 260.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 260.7 -;; be found in the file epl-v10.html at the root of this distribution. By 260.8 -;; using this software in any fashion, you are agreeing to be bound by the 260.9 -;; terms of this license. You must not remove this notice, or any other, 260.10 -;; from this software. 260.11 -;; 260.12 -;; sql.clj 260.13 -;; 260.14 -;; A Clojure interface to sql databases via jdbc 260.15 -;; 260.16 -;; See clojure.contrib.sql.test for an example 260.17 -;; 260.18 -;; scgilardi (gmail) 260.19 -;; Created 2 April 2008 260.20 - 260.21 -(ns 260.22 - ^{:author "Stephen C. Gilardi", 260.23 - :doc "A Clojure interface to sql databases via jdbc." 260.24 - :see-also [["http://github.com/richhickey/clojure-contrib/blob/master/src/test/clojure/clojure/contrib/test_sql.clj" 260.25 - "Example code"]]} 260.26 - clojure.contrib.sql 260.27 - (:use (clojure.contrib 260.28 - [def :only (defalias)] 260.29 - [string :only (as-str)]) 260.30 - clojure.contrib.sql.internal)) 260.31 - 260.32 -(defalias find-connection find-connection*) 260.33 -(defalias connection connection*) 260.34 - 260.35 -(defmacro with-connection 260.36 - "Evaluates body in the context of a new connection to a database then 260.37 - closes the connection. db-spec is a map containing values for one of the 260.38 - following parameter sets: 260.39 - 260.40 - Factory: 260.41 - :factory (required) a function of one argument, a map of params 260.42 - (others) (optional) passed to the factory function in a map 260.43 - 260.44 - DriverManager: 260.45 - :classname (required) a String, the jdbc driver class name 260.46 - :subprotocol (required) a String, the jdbc subprotocol 260.47 - :subname (required) a String, the jdbc subname 260.48 - (others) (optional) passed to the driver as properties. 260.49 - 260.50 - DataSource: 260.51 - :datasource (required) a javax.sql.DataSource 260.52 - :username (optional) a String 260.53 - :password (optional) a String, required if :username is supplied 260.54 - 260.55 - JNDI: 260.56 - :name (required) a String or javax.naming.Name 260.57 - :environment (optional) a java.util.Map" 260.58 - [db-spec & body] 260.59 - `(with-connection* ~db-spec (fn [] ~@body))) 260.60 - 260.61 -(defmacro transaction 260.62 - "Evaluates body as a transaction on the open database connection. Any 260.63 - nested transactions are absorbed into the outermost transaction. By 260.64 - default, all database updates are committed together as a group after 260.65 - evaluating the outermost body, or rolled back on any uncaught 260.66 - exception. If set-rollback-only is called within scope of the outermost 260.67 - transaction, the entire transaction will be rolled back rather than 260.68 - committed when complete." 260.69 - [& body] 260.70 - `(transaction* (fn [] ~@body))) 260.71 - 260.72 -(defn set-rollback-only 260.73 - "Marks the outermost transaction such that it will rollback rather than 260.74 - commit when complete" 260.75 - [] 260.76 - (rollback true)) 260.77 - 260.78 -(defn is-rollback-only 260.79 - "Returns true if the outermost transaction will rollback rather than 260.80 - commit when complete" 260.81 - [] 260.82 - (rollback)) 260.83 - 260.84 -(defn do-commands 260.85 - "Executes SQL commands on the open database connection." 260.86 - [& commands] 260.87 - (with-open [stmt (.createStatement (connection))] 260.88 - (doseq [cmd commands] 260.89 - (.addBatch stmt cmd)) 260.90 - (transaction 260.91 - (seq (.executeBatch stmt))))) 260.92 - 260.93 -(defn do-prepared 260.94 - "Executes an (optionally parameterized) SQL prepared statement on the 260.95 - open database connection. Each param-group is a seq of values for all of 260.96 - the parameters." 260.97 - [sql & param-groups] 260.98 - (with-open [stmt (.prepareStatement (connection) sql)] 260.99 - (doseq [param-group param-groups] 260.100 - (doseq [[index value] (map vector (iterate inc 1) param-group)] 260.101 - (.setObject stmt index value)) 260.102 - (.addBatch stmt)) 260.103 - (transaction 260.104 - (seq (.executeBatch stmt))))) 260.105 - 260.106 -(defn create-table 260.107 - "Creates a table on the open database connection given a table name and 260.108 - specs. Each spec is either a column spec: a vector containing a column 260.109 - name and optionally a type and other constraints, or a table-level 260.110 - constraint: a vector containing words that express the constraint. All 260.111 - words used to describe the table may be supplied as strings or keywords." 260.112 - [name & specs] 260.113 - (do-commands 260.114 - (format "CREATE TABLE %s (%s)" 260.115 - (as-str name) 260.116 - (apply str 260.117 - (map as-str 260.118 - (apply concat 260.119 - (interpose [", "] 260.120 - (map (partial interpose " ") specs)))))))) 260.121 - 260.122 -(defn drop-table 260.123 - "Drops a table on the open database connection given its name, a string 260.124 - or keyword" 260.125 - [name] 260.126 - (do-commands 260.127 - (format "DROP TABLE %s" (as-str name)))) 260.128 - 260.129 -(defn insert-values 260.130 - "Inserts rows into a table with values for specified columns only. 260.131 - column-names is a vector of strings or keywords identifying columns. Each 260.132 - value-group is a vector containing a values for each column in 260.133 - order. When inserting complete rows (all columns), consider using 260.134 - insert-rows instead." 260.135 - [table column-names & value-groups] 260.136 - (let [column-strs (map as-str column-names) 260.137 - n (count (first value-groups)) 260.138 - template (apply str (interpose "," (replicate n "?"))) 260.139 - columns (if (seq column-names) 260.140 - (format "(%s)" (apply str (interpose "," column-strs))) 260.141 - "")] 260.142 - (apply do-prepared 260.143 - (format "INSERT INTO %s %s VALUES (%s)" 260.144 - (as-str table) columns template) 260.145 - value-groups))) 260.146 - 260.147 -(defn insert-rows 260.148 - "Inserts complete rows into a table. Each row is a vector of values for 260.149 - each of the table's columns in order." 260.150 - [table & rows] 260.151 - (apply insert-values table nil rows)) 260.152 - 260.153 -(defn insert-records 260.154 - "Inserts records into a table. records are maps from strings or 260.155 - keywords (identifying columns) to values." 260.156 - [table & records] 260.157 - (doseq [record records] 260.158 - (insert-values table (keys record) (vals record)))) 260.159 - 260.160 -(defn delete-rows 260.161 - "Deletes rows from a table. where-params is a vector containing a string 260.162 - providing the (optionally parameterized) selection criteria followed by 260.163 - values for any parameters." 260.164 - [table where-params] 260.165 - (let [[where & params] where-params] 260.166 - (do-prepared 260.167 - (format "DELETE FROM %s WHERE %s" 260.168 - (as-str table) where) 260.169 - params))) 260.170 - 260.171 -(defn update-values 260.172 - "Updates values on selected rows in a table. where-params is a vector 260.173 - containing a string providing the (optionally parameterized) selection 260.174 - criteria followed by values for any parameters. record is a map from 260.175 - strings or keywords (identifying columns) to updated values." 260.176 - [table where-params record] 260.177 - (let [[where & params] where-params 260.178 - column-strs (map as-str (keys record)) 260.179 - columns (apply str (concat (interpose "=?, " column-strs) "=?"))] 260.180 - (do-prepared 260.181 - (format "UPDATE %s SET %s WHERE %s" 260.182 - (as-str table) columns where) 260.183 - (concat (vals record) params)))) 260.184 - 260.185 -(defn update-or-insert-values 260.186 - "Updates values on selected rows in a table, or inserts a new row when no 260.187 - existing row matches the selection criteria. where-params is a vector 260.188 - containing a string providing the (optionally parameterized) selection 260.189 - criteria followed by values for any parameters. record is a map from 260.190 - strings or keywords (identifying columns) to updated values." 260.191 - [table where-params record] 260.192 - (transaction 260.193 - (let [result (update-values table where-params record)] 260.194 - (if (zero? (first result)) 260.195 - (insert-values table (keys record) (vals record)) 260.196 - result)))) 260.197 - 260.198 -(defmacro with-query-results 260.199 - "Executes a query, then evaluates body with results bound to a seq of the 260.200 - results. sql-params is a vector containing a string providing 260.201 - the (optionally parameterized) SQL query followed by values for any 260.202 - parameters." 260.203 - [results sql-params & body] 260.204 - `(with-query-results* ~sql-params (fn [~results] ~@body)))
261.1 --- a/src/clojure/contrib/sql/internal.clj Sat Aug 21 06:25:44 2010 -0400 261.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 261.3 @@ -1,194 +0,0 @@ 261.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 261.5 -;; distribution terms for this software are covered by the Eclipse Public 261.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 261.7 -;; be found in the file epl-v10.html at the root of this distribution. By 261.8 -;; using this software in any fashion, you are agreeing to be bound by the 261.9 -;; terms of this license. You must not remove this notice, or any other, 261.10 -;; from this software. 261.11 -;; 261.12 -;; internal definitions for clojure.contrib.sql 261.13 -;; 261.14 -;; scgilardi (gmail) 261.15 -;; Created 3 October 2008 261.16 - 261.17 -(ns clojure.contrib.sql.internal 261.18 - (:use 261.19 - (clojure.contrib 261.20 - [except :only (throwf throw-arg)] 261.21 - [properties :only (as-properties)] 261.22 - [seq :only (indexed)])) 261.23 - (:import 261.24 - (clojure.lang RT) 261.25 - (java.sql BatchUpdateException DriverManager SQLException Statement) 261.26 - (java.util Hashtable Map) 261.27 - (javax.naming InitialContext Name) 261.28 - (javax.sql DataSource))) 261.29 - 261.30 -(def *db* {:connection nil :level 0}) 261.31 - 261.32 -(def special-counts 261.33 - {Statement/EXECUTE_FAILED "EXECUTE_FAILED" 261.34 - Statement/SUCCESS_NO_INFO "SUCCESS_NO_INFO"}) 261.35 - 261.36 -(defn find-connection* 261.37 - "Returns the current database connection (or nil if there is none)" 261.38 - [] 261.39 - (:connection *db*)) 261.40 - 261.41 -(defn connection* 261.42 - "Returns the current database connection (or throws if there is none)" 261.43 - [] 261.44 - (or (find-connection*) 261.45 - (throwf "no current database connection"))) 261.46 - 261.47 -(defn rollback 261.48 - "Accessor for the rollback flag on the current connection" 261.49 - ([] 261.50 - (deref (:rollback *db*))) 261.51 - ([val] 261.52 - (swap! (:rollback *db*) (fn [_] val)))) 261.53 - 261.54 -(defn get-connection 261.55 - "Creates a connection to a database. db-spec is a map containing values 261.56 - for one of the following parameter sets: 261.57 - 261.58 - Factory: 261.59 - :factory (required) a function of one argument, a map of params 261.60 - (others) (optional) passed to the factory function in a map 261.61 - 261.62 - DriverManager: 261.63 - :classname (required) a String, the jdbc driver class name 261.64 - :subprotocol (required) a String, the jdbc subprotocol 261.65 - :subname (required) a String, the jdbc subname 261.66 - (others) (optional) passed to the driver as properties. 261.67 - 261.68 - DataSource: 261.69 - :datasource (required) a javax.sql.DataSource 261.70 - :username (optional) a String 261.71 - :password (optional) a String, required if :username is supplied 261.72 - 261.73 - JNDI: 261.74 - :name (required) a String or javax.naming.Name 261.75 - :environment (optional) a java.util.Map" 261.76 - [{:keys [factory 261.77 - classname subprotocol subname 261.78 - datasource username password 261.79 - name environment] 261.80 - :as db-spec}] 261.81 - (cond 261.82 - factory 261.83 - (factory (dissoc db-spec :factory)) 261.84 - (and classname subprotocol subname) 261.85 - (let [url (format "jdbc:%s:%s" subprotocol subname) 261.86 - etc (dissoc db-spec :classname :subprotocol :subname)] 261.87 - (RT/loadClassForName classname) 261.88 - (DriverManager/getConnection url (as-properties etc))) 261.89 - (and datasource username password) 261.90 - (.getConnection datasource username password) 261.91 - datasource 261.92 - (.getConnection datasource) 261.93 - name 261.94 - (let [env (and environment (Hashtable. environment)) 261.95 - context (InitialContext. env) 261.96 - datasource (.lookup context name)] 261.97 - (.getConnection datasource)) 261.98 - :else 261.99 - (throw-arg "db-spec %s is missing a required parameter" db-spec))) 261.100 - 261.101 -(defn with-connection* 261.102 - "Evaluates func in the context of a new connection to a database then 261.103 - closes the connection." 261.104 - [db-spec func] 261.105 - (with-open [con (get-connection db-spec)] 261.106 - (binding [*db* (assoc *db* 261.107 - :connection con :level 0 :rollback (atom false))] 261.108 - (func)))) 261.109 - 261.110 -(defn print-sql-exception 261.111 - "Prints the contents of an SQLException to stream" 261.112 - [stream exception] 261.113 - (.println 261.114 - stream 261.115 - (format (str "%s:" \newline 261.116 - " Message: %s" \newline 261.117 - " SQLState: %s" \newline 261.118 - " Error Code: %d") 261.119 - (.getSimpleName (class exception)) 261.120 - (.getMessage exception) 261.121 - (.getSQLState exception) 261.122 - (.getErrorCode exception)))) 261.123 - 261.124 -(defn print-sql-exception-chain 261.125 - "Prints a chain of SQLExceptions to stream" 261.126 - [stream exception] 261.127 - (loop [e exception] 261.128 - (when e 261.129 - (print-sql-exception stream e) 261.130 - (recur (.getNextException e))))) 261.131 - 261.132 -(defn print-update-counts 261.133 - "Prints the update counts from a BatchUpdateException to stream" 261.134 - [stream exception] 261.135 - (.println stream "Update counts:") 261.136 - (doseq [[index count] (indexed (.getUpdateCounts exception))] 261.137 - (.println stream (format " Statement %d: %s" 261.138 - index 261.139 - (get special-counts count count))))) 261.140 - 261.141 -(defn throw-rollback 261.142 - "Sets rollback and throws a wrapped exception" 261.143 - [e] 261.144 - (rollback true) 261.145 - (throwf e "transaction rolled back: %s" (.getMessage e))) 261.146 - 261.147 -(defn transaction* 261.148 - "Evaluates func as a transaction on the open database connection. Any 261.149 - nested transactions are absorbed into the outermost transaction. By 261.150 - default, all database updates are committed together as a group after 261.151 - evaluating the outermost body, or rolled back on any uncaught 261.152 - exception. If rollback is set within scope of the outermost transaction, 261.153 - the entire transaction will be rolled back rather than committed when 261.154 - complete." 261.155 - [func] 261.156 - (binding [*db* (update-in *db* [:level] inc)] 261.157 - (if (= (:level *db*) 1) 261.158 - (let [con (connection*) 261.159 - auto-commit (.getAutoCommit con)] 261.160 - (io! 261.161 - (.setAutoCommit con false) 261.162 - (try 261.163 - (func) 261.164 - (catch BatchUpdateException e 261.165 - (print-update-counts *err* e) 261.166 - (print-sql-exception-chain *err* e) 261.167 - (throw-rollback e)) 261.168 - (catch SQLException e 261.169 - (print-sql-exception-chain *err* e) 261.170 - (throw-rollback e)) 261.171 - (catch Exception e 261.172 - (throw-rollback e)) 261.173 - (finally 261.174 - (if (rollback) 261.175 - (.rollback con) 261.176 - (.commit con)) 261.177 - (rollback false) 261.178 - (.setAutoCommit con auto-commit))))) 261.179 - (func)))) 261.180 - 261.181 -(defn with-query-results* 261.182 - "Executes a query, then evaluates func passing in a seq of the results as 261.183 - an argument. The first argument is a vector containing the (optionally 261.184 - parameterized) sql query string followed by values for any parameters." 261.185 - [[sql & params :as sql-params] func] 261.186 - (when-not (vector? sql-params) 261.187 - (throw-arg "\"%s\" expected %s %s, found %s %s" 261.188 - "sql-params" 261.189 - "vector" 261.190 - "[sql param*]" 261.191 - (.getName (class sql-params)) 261.192 - (pr-str sql-params))) 261.193 - (with-open [stmt (.prepareStatement (connection*) sql)] 261.194 - (doseq [[index value] (map vector (iterate inc 1) params)] 261.195 - (.setObject stmt index value)) 261.196 - (with-open [rset (.executeQuery stmt)] 261.197 - (func (resultset-seq rset)))))
262.1 --- a/src/clojure/contrib/str_utils.clj Sat Aug 21 06:25:44 2010 -0400 262.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 262.3 @@ -1,103 +0,0 @@ 262.4 -;;; str_utils.clj -- string utilities for Clojure 262.5 - 262.6 -;; by Stuart Sierra <mail@stuartsierra.com> 262.7 -;; April 8, 2008 262.8 - 262.9 -;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use 262.10 -;; and distribution terms for this software are covered by the Eclipse 262.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 262.12 -;; which can be found in the file epl-v10.html at the root of this 262.13 -;; distribution. By using this software in any fashion, you are 262.14 -;; agreeing to be bound by the terms of this license. You must not 262.15 -;; remove this notice, or any other, from this software. 262.16 - 262.17 -;; DEPRECATED in 1.2: Promoted to clojure.java.string. Note that 262.18 -;; many function names and semantics have changed 262.19 - 262.20 -(ns 262.21 - ^{:author "Stuart Sierra", 262.22 - :deprecated "1.2" 262.23 - :doc "String utilities for Clojure"} 262.24 - clojure.contrib.str-utils 262.25 - (:import (java.util.regex Pattern))) 262.26 - 262.27 -(defn re-split 262.28 - "Splits the string on instances of 'pattern'. Returns a sequence of 262.29 - strings. Optional 'limit' argument is the maximum number of 262.30 - splits. Like Perl's 'split'." 262.31 - ([^Pattern pattern string] (seq (. pattern (split string)))) 262.32 - ([^Pattern pattern string limit] (seq (. pattern (split string limit))))) 262.33 - 262.34 -(defn re-partition 262.35 - "Splits the string into a lazy sequence of substrings, alternating 262.36 - between substrings that match the patthern and the substrings 262.37 - between the matches. The sequence always starts with the substring 262.38 - before the first match, or an empty string if the beginning of the 262.39 - string matches. 262.40 - 262.41 - For example: (re-partition #\"[a-z]+\" \"abc123def\") 262.42 - 262.43 - Returns: (\"\" \"abc\" \"123\" \"def\")" 262.44 - [^Pattern re string] 262.45 - (let [m (re-matcher re string)] 262.46 - ((fn step [prevend] 262.47 - (lazy-seq 262.48 - (if (.find m) 262.49 - (cons (.subSequence string prevend (.start m)) 262.50 - (cons (re-groups m) 262.51 - (step (+ (.start m) (count (.group m)))))) 262.52 - (when (< prevend (.length string)) 262.53 - (list (.subSequence string prevend (.length string))))))) 262.54 - 0))) 262.55 - 262.56 -(defn re-gsub 262.57 - "Replaces all instances of 'pattern' in 'string' with 262.58 - 'replacement'. Like Ruby's 'String#gsub'. 262.59 - 262.60 - If (ifn? replacment) is true, the replacement is called with the 262.61 - match. 262.62 - " 262.63 - [^java.util.regex.Pattern regex replacement ^String string] 262.64 - (if (ifn? replacement) 262.65 - (let [parts (vec (re-partition regex string))] 262.66 - (apply str 262.67 - (reduce (fn [parts match-idx] 262.68 - (update-in parts [match-idx] replacement)) 262.69 - parts (range 1 (count parts) 2)))) 262.70 - (.. regex (matcher string) (replaceAll replacement)))) 262.71 - 262.72 -(defn re-sub 262.73 - "Replaces the first instance of 'pattern' in 'string' with 262.74 - 'replacement'. Like Ruby's 'String#sub'. 262.75 - 262.76 - If (ifn? replacement) is true, the replacement is called with 262.77 - the match. 262.78 - " 262.79 - [^Pattern regex replacement ^String string] 262.80 - (if (ifn? replacement) 262.81 - (let [m (re-matcher regex string)] 262.82 - (if (.find m) 262.83 - (str (.subSequence string 0 (.start m)) 262.84 - (replacement (re-groups m)) 262.85 - (.subSequence string (.end m) (.length string))) 262.86 - string)) 262.87 - (.. regex (matcher string) (replaceFirst replacement)))) 262.88 - 262.89 - 262.90 -(defn str-join 262.91 - "Returns a string of all elements in 'sequence', separated by 262.92 - 'separator'. Like Perl's 'join'." 262.93 - [separator sequence] 262.94 - (apply str (interpose separator sequence))) 262.95 - 262.96 - 262.97 -(defn chop 262.98 - "Removes the last character of string." 262.99 - [s] 262.100 - (subs s 0 (dec (count s)))) 262.101 - 262.102 -(defn chomp 262.103 - "Removes all trailing newline \\n or return \\r characters from 262.104 - string. Note: String.trim() is similar and faster." 262.105 - [s] 262.106 - (re-sub #"[\r\n]+$" "" s))
263.1 --- a/src/clojure/contrib/str_utils2.clj Sat Aug 21 06:25:44 2010 -0400 263.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 263.3 @@ -1,376 +0,0 @@ 263.4 -;;; str_utils2.clj -- functional string utilities for Clojure 263.5 - 263.6 -;; by Stuart Sierra, http://stuartsierra.com/ 263.7 -;; August 19, 2009 263.8 - 263.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 263.10 -;; and distribution terms for this software are covered by the Eclipse 263.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 263.12 -;; which can be found in the file epl-v10.html at the root of this 263.13 -;; distribution. By using this software in any fashion, you are 263.14 -;; agreeing to be bound by the terms of this license. You must not 263.15 -;; remove this notice, or any other, from this software. 263.16 - 263.17 -;; DEPRECATED in 1.2: Promoted to clojure.java.string. Note that 263.18 -;; many function names and semantics have changed 263.19 - 263.20 -(ns ^{:author "Stuart Sierra" 263.21 - :deprecated "1.2" 263.22 - :doc "This is a library of string manipulation functions. It 263.23 - is intented as a replacement for clojure.contrib.str-utils. 263.24 - 263.25 - You cannot (use 'clojure.contrib.str-utils2) because it defines 263.26 - functions with the same names as functions in clojure.core. 263.27 - Instead, do (require '[clojure.contrib.str-utils2 :as s]) 263.28 - or something similar. 263.29 - 263.30 - Goals: 263.31 - 1. Be functional 263.32 - 2. String argument first, to work with -> 263.33 - 3. Performance linear in string length 263.34 - 263.35 - Some ideas are borrowed from 263.36 - http://github.com/francoisdevlin/devlinsf-clojure-utils/"} 263.37 - clojure.contrib.str-utils2 263.38 - (:refer-clojure :exclude (take replace drop butlast partition 263.39 - contains? get repeat reverse partial)) 263.40 - (:import (java.util.regex Pattern))) 263.41 - 263.42 - 263.43 -(defmacro dochars 263.44 - "bindings => [name string] 263.45 - 263.46 - Repeatedly executes body, with name bound to each character in 263.47 - string. Does NOT handle Unicode supplementary characters (above 263.48 - U+FFFF)." 263.49 - [bindings & body] 263.50 - (assert (vector bindings)) 263.51 - (assert (= 2 (count bindings))) 263.52 - ;; This seems to be the fastest way to iterate over characters. 263.53 - `(let [^String s# ~(second bindings)] 263.54 - (dotimes [i# (.length s#)] 263.55 - (let [~(first bindings) (.charAt s# i#)] 263.56 - ~@body)))) 263.57 - 263.58 - 263.59 -(defmacro docodepoints 263.60 - "bindings => [name string] 263.61 - 263.62 - Repeatedly executes body, with name bound to the integer code point 263.63 - of each Unicode character in the string. Handles Unicode 263.64 - supplementary characters (above U+FFFF) correctly." 263.65 - [bindings & body] 263.66 - (assert (vector bindings)) 263.67 - (assert (= 2 (count bindings))) 263.68 - (let [character (first bindings) 263.69 - string (second bindings)] 263.70 - `(let [^String s# ~string 263.71 - len# (.length s#)] 263.72 - (loop [i# 0] 263.73 - (when (< i# len#) 263.74 - (let [~character (.charAt s# i#)] 263.75 - (if (Character/isHighSurrogate ~character) 263.76 - (let [~character (.codePointAt s# i#)] 263.77 - ~@body 263.78 - (recur (+ 2 i#))) 263.79 - (let [~character (int ~character)] 263.80 - ~@body 263.81 - (recur (inc i#)))))))))) 263.82 - 263.83 -(defn codepoints 263.84 - "Returns a sequence of integer Unicode code points in s. Handles 263.85 - Unicode supplementary characters (above U+FFFF) correctly." 263.86 - [^String s] 263.87 - (let [len (.length s) 263.88 - f (fn thisfn [^String s i] 263.89 - (when (< i len) 263.90 - (let [c (.charAt s i)] 263.91 - (if (Character/isHighSurrogate c) 263.92 - (cons (.codePointAt s i) (thisfn s (+ 2 i))) 263.93 - (cons (int c) (thisfn s (inc i)))))))] 263.94 - (lazy-seq (f s 0)))) 263.95 - 263.96 -(defn ^String escape 263.97 - "Returns a new String by applying cmap (a function or a map) to each 263.98 - character in s. If cmap returns nil, the original character is 263.99 - added to the output unchanged." 263.100 - [^String s cmap] 263.101 - (let [buffer (StringBuilder. (.length s))] 263.102 - (dochars [c s] 263.103 - (if-let [r (cmap c)] 263.104 - (.append buffer r) 263.105 - (.append buffer c))) 263.106 - (.toString buffer))) 263.107 - 263.108 -(defn blank? 263.109 - "True if s is nil, empty, or contains only whitespace." 263.110 - [^String s] 263.111 - (every? (fn [^Character c] (Character/isWhitespace c)) s)) 263.112 - 263.113 -(defn ^String take 263.114 - "Take first n characters from s, up to the length of s. 263.115 - 263.116 - Note the argument order is the opposite of clojure.core/take; this 263.117 - is to keep the string as the first argument for use with ->" 263.118 - [^String s n] 263.119 - (if (< (count s) n) 263.120 - s 263.121 - (.substring s 0 n))) 263.122 - 263.123 -(defn ^String drop 263.124 - "Drops first n characters from s. Returns an empty string if n is 263.125 - greater than the length of s. 263.126 - 263.127 - Note the argument order is the opposite of clojure.core/drop; this 263.128 - is to keep the string as the first argument for use with ->" 263.129 - [^String s n] 263.130 - (if (< (count s) n) 263.131 - "" 263.132 - (.substring s n))) 263.133 - 263.134 -(defn ^String butlast 263.135 - "Returns s without the last n characters. Returns an empty string 263.136 - if n is greater than the length of s. 263.137 - 263.138 - Note the argument order is the opposite of clojure.core/butlast; 263.139 - this is to keep the string as the first argument for use with ->" 263.140 - [^String s n] 263.141 - (if (< (count s) n) 263.142 - "" 263.143 - (.substring s 0 (- (count s) n)))) 263.144 - 263.145 -(defn ^String tail 263.146 - "Returns the last n characters of s." 263.147 - [^String s n] 263.148 - (if (< (count s) n) 263.149 - s 263.150 - (.substring s (- (count s) n)))) 263.151 - 263.152 -(defn ^String repeat 263.153 - "Returns a new String containing s repeated n times." 263.154 - [^String s n] 263.155 - (apply str (clojure.core/repeat n s))) 263.156 - 263.157 -(defn ^String reverse 263.158 - "Returns s with its characters reversed." 263.159 - [^String s] 263.160 - (.toString (.reverse (StringBuilder. s)))) 263.161 - 263.162 -(defmulti 263.163 - ^{:doc "Replaces all instances of pattern in string with replacement. 263.164 - 263.165 - Allowed argument types for pattern and replacement are: 263.166 - 1. String and String 263.167 - 2. Character and Character 263.168 - 3. regex Pattern and String 263.169 - (Uses java.util.regex.Matcher.replaceAll) 263.170 - 4. regex Pattern and function 263.171 - (Calls function with re-groups of each match, uses return 263.172 - value as replacement.)" 263.173 - :arglists '([string pattern replacement]) 263.174 - :tag String} 263.175 - replace 263.176 - (fn [^String string pattern replacement] 263.177 - [(class pattern) (class replacement)])) 263.178 - 263.179 -(defmethod replace [String String] [^String s ^String a ^String b] 263.180 - (.replace s a b)) 263.181 - 263.182 -(defmethod replace [Character Character] [^String s ^Character a ^Character b] 263.183 - (.replace s a b)) 263.184 - 263.185 -(defmethod replace [Pattern String] [^String s re replacement] 263.186 - (.replaceAll (re-matcher re s) replacement)) 263.187 - 263.188 -(defmethod replace [Pattern clojure.lang.IFn] [^String s re replacement] 263.189 - (let [m (re-matcher re s)] 263.190 - (let [buffer (StringBuffer. (.length s))] 263.191 - (loop [] 263.192 - (if (.find m) 263.193 - (do (.appendReplacement m buffer (replacement (re-groups m))) 263.194 - (recur)) 263.195 - (do (.appendTail m buffer) 263.196 - (.toString buffer))))))) 263.197 - 263.198 -(defmulti 263.199 - ^{:doc "Replaces the first instance of pattern in s with replacement. 263.200 - 263.201 - Allowed argument types for pattern and replacement are: 263.202 - 1. String and String 263.203 - 2. regex Pattern and String 263.204 - (Uses java.util.regex.Matcher.replaceAll) 263.205 - 3. regex Pattern and function 263.206 -" 263.207 - :arglists '([s pattern replacement]) 263.208 - :tag String} 263.209 - replace-first 263.210 - (fn [s pattern replacement] 263.211 - [(class pattern) (class replacement)])) 263.212 - 263.213 -(defmethod replace-first [String String] [^String s pattern replacement] 263.214 - (.replaceFirst (re-matcher (Pattern/quote pattern) s) replacement)) 263.215 - 263.216 -(defmethod replace-first [Pattern String] [^String s re replacement] 263.217 - (.replaceFirst (re-matcher re s) replacement)) 263.218 - 263.219 -(defmethod replace-first [Pattern clojure.lang.IFn] [^String s ^Pattern re f] 263.220 - (let [m (re-matcher re s)] 263.221 - (let [buffer (StringBuffer.)] 263.222 - (if (.find m) 263.223 - (let [rep (f (re-groups m))] 263.224 - (.appendReplacement m buffer rep) 263.225 - (.appendTail m buffer) 263.226 - (str buffer)))))) 263.227 - 263.228 -(defn partition 263.229 - "Splits the string into a lazy sequence of substrings, alternating 263.230 - between substrings that match the patthern and the substrings 263.231 - between the matches. The sequence always starts with the substring 263.232 - before the first match, or an empty string if the beginning of the 263.233 - string matches. 263.234 - 263.235 - For example: (partition \"abc123def\" #\"[a-z]+\") 263.236 - returns: (\"\" \"abc\" \"123\" \"def\")" 263.237 - [^String s ^Pattern re] 263.238 - (let [m (re-matcher re s)] 263.239 - ((fn step [prevend] 263.240 - (lazy-seq 263.241 - (if (.find m) 263.242 - (cons (.subSequence s prevend (.start m)) 263.243 - (cons (re-groups m) 263.244 - (step (+ (.start m) (count (.group m)))))) 263.245 - (when (< prevend (.length s)) 263.246 - (list (.subSequence s prevend (.length s))))))) 263.247 - 0))) 263.248 - 263.249 -(defn ^String join 263.250 - "Returns a string of all elements in coll, separated by 263.251 - separator. Like Perl's join." 263.252 - [^String separator coll] 263.253 - (apply str (interpose separator coll))) 263.254 - 263.255 -(defn ^String chop 263.256 - "Removes the last character of string, does nothing on a zero-length 263.257 - string." 263.258 - [^String s] 263.259 - (let [size (count s)] 263.260 - (if (zero? size) 263.261 - s 263.262 - (subs s 0 (dec (count s)))))) 263.263 - 263.264 -(defn ^String chomp 263.265 - "Removes all trailing newline \\n or return \\r characters from 263.266 - string. Note: String.trim() is similar and faster." 263.267 - [^String s] 263.268 - (replace s #"[\r\n]+$" "")) 263.269 - 263.270 -(defn title-case [^String s] 263.271 - (throw (Exception. "title-case not implemeted yet"))) 263.272 - 263.273 -(defn ^String swap-case 263.274 - "Changes upper case characters to lower case and vice-versa. 263.275 - Handles Unicode supplementary characters correctly. Uses the 263.276 - locale-sensitive String.toUpperCase() and String.toLowerCase() 263.277 - methods." 263.278 - [^String s] 263.279 - (let [buffer (StringBuilder. (.length s)) 263.280 - ;; array to make a String from one code point 263.281 - ^"[I" array (make-array Integer/TYPE 1)] 263.282 - (docodepoints [c s] 263.283 - (aset-int array 0 c) 263.284 - (if (Character/isLowerCase c) 263.285 - ;; Character.toUpperCase is not locale-sensitive, but 263.286 - ;; String.toUpperCase is; so we use a String. 263.287 - (.append buffer (.toUpperCase (String. array 0 1))) 263.288 - (.append buffer (.toLowerCase (String. array 0 1))))) 263.289 - (.toString buffer))) 263.290 - 263.291 -(defn ^String capitalize 263.292 - "Converts first character of the string to upper-case, all other 263.293 - characters to lower-case." 263.294 - [^String s] 263.295 - (if (< (count s) 2) 263.296 - (.toUpperCase s) 263.297 - (str (.toUpperCase ^String (subs s 0 1)) 263.298 - (.toLowerCase ^String (subs s 1))))) 263.299 - 263.300 -(defn ^String ltrim 263.301 - "Removes whitespace from the left side of string." 263.302 - [^String s] 263.303 - (replace s #"^\s+" "")) 263.304 - 263.305 -(defn ^String rtrim 263.306 - "Removes whitespace from the right side of string." 263.307 - [^String s] 263.308 - (replace s #"\s+$" "")) 263.309 - 263.310 -(defn split-lines 263.311 - "Splits s on \\n or \\r\\n." 263.312 - [^String s] 263.313 - (seq (.split #"\r?\n" s))) 263.314 - 263.315 -;; borrowed from compojure.str-utils, by James Reeves, EPL 1.0 263.316 -(defn ^String map-str 263.317 - "Apply f to each element of coll, concatenate all results into a 263.318 - String." 263.319 - [f coll] 263.320 - (apply str (map f coll))) 263.321 - 263.322 -;; borrowed from compojure.str-utils, by James Reeves, EPL 1.0 263.323 -(defn grep 263.324 - "Filters elements of coll by a regular expression. The String 263.325 - representation (with str) of each element is tested with re-find." 263.326 - [re coll] 263.327 - (filter (fn [x] (re-find re (str x))) coll)) 263.328 - 263.329 -(defn partial 263.330 - "Like clojure.core/partial for functions that take their primary 263.331 - argument first. 263.332 - 263.333 - Takes a function f and its arguments, NOT INCLUDING the first 263.334 - argument. Returns a new function whose first argument will be the 263.335 - first argument to f. 263.336 - 263.337 - Example: (str-utils2/partial str-utils2/take 2) 263.338 - ;;=> (fn [s] (str-utils2/take s 2))" 263.339 - [f & args] 263.340 - (fn [s & more] (apply f s (concat args more)))) 263.341 - 263.342 - 263.343 -;;; WRAPPERS 263.344 - 263.345 -;; The following functions are simple wrappers around java.lang.String 263.346 -;; functions. They are included here for completeness, and for use 263.347 -;; when mapping over a collection of strings. 263.348 - 263.349 -(defn ^String upper-case 263.350 - "Converts string to all upper-case." 263.351 - [^String s] 263.352 - (.toUpperCase s)) 263.353 - 263.354 -(defn ^String lower-case 263.355 - "Converts string to all lower-case." 263.356 - [^String s] 263.357 - (.toLowerCase s)) 263.358 - 263.359 -(defn split 263.360 - "Splits string on a regular expression. Optional argument limit is 263.361 - the maximum number of splits." 263.362 - ([^String s ^Pattern re] (seq (.split re s))) 263.363 - ([^String s ^Pattern re limit] (seq (.split re s limit)))) 263.364 - 263.365 -(defn ^String trim 263.366 - "Removes whitespace from both ends of string." 263.367 - [^String s] 263.368 - (.trim s)) 263.369 - 263.370 -(defn ^String contains? 263.371 - "True if s contains the substring." 263.372 - [^String s substring] 263.373 - (.contains s substring)) 263.374 - 263.375 -(defn ^String get 263.376 - "Gets the i'th character in string." 263.377 - [^String s i] 263.378 - (.charAt s i)) 263.379 -
264.1 --- a/src/clojure/contrib/stream_utils.clj Sat Aug 21 06:25:44 2010 -0400 264.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 264.3 @@ -1,276 +0,0 @@ 264.4 -;; Stream utilities 264.5 - 264.6 -;; by Konrad Hinsen 264.7 -;; last updated May 3, 2009 264.8 - 264.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 264.10 -;; and distribution terms for this software are covered by the Eclipse 264.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 264.12 -;; which can be found in the file epl-v10.html at the root of this 264.13 -;; distribution. By using this software in any fashion, you are 264.14 -;; agreeing to be bound by the terms of this license. You must not 264.15 -;; remove this notice, or any other, from this software. 264.16 - 264.17 -(ns 264.18 - ^{:author "Konrad Hinsen" 264.19 - :doc "Functions for setting up computational pipelines via data streams. 264.20 - 264.21 - NOTE: This library is experimental. It may change significantly 264.22 - with future release. 264.23 - 264.24 - This library defines: 264.25 - - an abstract stream type, whose interface consists of the 264.26 - multimethod stream-next 264.27 - - a macro for implementing streams 264.28 - - implementations of stream for 264.29 - 1) Clojure sequences, and vectors 264.30 - 2) nil, representing an empty stream 264.31 - - tools for writing stream transformers, including the 264.32 - monad stream-m 264.33 - - various utility functions for working with streams 264.34 - 264.35 - Streams are building blocks in the construction of computational 264.36 - pipelines. A stream is represented by its current state plus 264.37 - a function that takes a stream state and obtains the next item 264.38 - in the stream as well as the new stream state. The state is 264.39 - implemented as a Java class or a Clojure type (as defined by the 264.40 - function clojure.core/type), and the function is provided as an 264.41 - implementation of the multimethod stream-next for this class or type. 264.42 - 264.43 - While setting up pipelines using this mechanism is somewhat more 264.44 - cumbersome than using Clojure's lazy seq mechanisms, there are a 264.45 - few advantages: 264.46 - - The state of a stream can be stored in any Clojure data structure, 264.47 - and the stream can be re-generated from it any number of times. 264.48 - Any number of states can be stored this way. 264.49 - - The elements of the stream are never cached, so keeping a reference 264.50 - to a stream state does not incur an uncontrollable memory penalty. 264.51 - 264.52 - Note that the stream mechanism is thread-safe as long as the 264.53 - concrete stream implementations do not use any mutable state. 264.54 - 264.55 - Stream transformers take any number of input streams and produce one 264.56 - output stream. They are typically written using the stream-m 264.57 - monad. In the definition of a stream transformer, (pick s) returns 264.58 - the next value of stream argument s, whereas pick-all returns the 264.59 - next value of all stream arguments in the form of a vector."} 264.60 - clojure.contrib.stream-utils 264.61 - (:refer-clojure :exclude (deftype)) 264.62 - (:use [clojure.contrib.types :only (deftype deftype-)]) 264.63 - (:use [clojure.contrib.monads :only (defmonad with-monad)]) 264.64 - (:use [clojure.contrib.def :only (defvar defvar-)]) 264.65 - (:require [clojure.contrib.seq]) 264.66 - (:require [clojure.contrib.generic.collection])) 264.67 - 264.68 - 264.69 -; 264.70 -; Stream type and interface 264.71 -; 264.72 -(defvar stream-type ::stream 264.73 - "The root type for the stream hierarchy. For each stream type, 264.74 - add a derivation from this type.") 264.75 - 264.76 -(defmacro defstream 264.77 - "Define object of the given type as a stream whose implementation 264.78 - of stream-next is defined by args and body. This macro adds 264.79 - a type-specific method for stream-next and derives type 264.80 - from stream-type." 264.81 - [type-tag args & body] 264.82 - `(do 264.83 - (derive ~type-tag stream-type) 264.84 - (defmethod stream-next ~type-tag ~args ~@body))) 264.85 - 264.86 -(defvar- stream-skip ::skip 264.87 - "The skip-this-item value.") 264.88 - 264.89 -(defn- stream-skip? 264.90 - "Returns true if x is the stream-skip." 264.91 - [x] 264.92 - (identical? x stream-skip)) 264.93 - 264.94 -(defmulti stream-next 264.95 - "Returns a vector [next-value new-state] where next-value is the next 264.96 - item in the data stream defined by stream-state and new-state 264.97 - is the new state of the stream. At the end of the stream, 264.98 - next-value and new-state are nil." 264.99 - {:arglists '([stream-state])} 264.100 - type) 264.101 - 264.102 -(defmethod stream-next nil 264.103 - [s] 264.104 - [nil nil]) 264.105 - 264.106 -(defmethod stream-next clojure.lang.ISeq 264.107 - [s] 264.108 - (if (seq s) 264.109 - [(first s) (rest s)] 264.110 - [nil nil])) 264.111 - 264.112 -(defmethod stream-next clojure.lang.IPersistentVector 264.113 - [v] 264.114 - (stream-next (seq v))) 264.115 - 264.116 -(defn stream-seq 264.117 - "Return a lazy seq on the stream. Also accessible via 264.118 - clojure.contrib.seq/seq-on and 264.119 - clojure.contrib.generic.collection/seq for streams." 264.120 - [s] 264.121 - (lazy-seq 264.122 - (let [[v ns] (stream-next s)] 264.123 - (if (nil? ns) 264.124 - nil 264.125 - (cons v (stream-seq ns)))))) 264.126 - 264.127 -(defmethod clojure.contrib.seq/seq-on stream-type 264.128 - [s] 264.129 - (stream-seq s)) 264.130 - 264.131 -(defmethod clojure.contrib.generic.collection/seq stream-type 264.132 - [s] 264.133 - (stream-seq s)) 264.134 - 264.135 -; 264.136 -; Stream transformers 264.137 -; 264.138 -(defmonad stream-m 264.139 - "Monad describing stream computations. The monadic values can be 264.140 - of any type handled by stream-next." 264.141 - [m-result (fn m-result-stream [v] 264.142 - (fn [s] [v s])) 264.143 - m-bind (fn m-bind-stream [mv f] 264.144 - (fn [s] 264.145 - (let [[v ss :as r] (mv s)] 264.146 - (if (or (nil? ss) (stream-skip? v)) 264.147 - r 264.148 - ((f v) ss))))) 264.149 - m-zero (fn [s] [stream-skip s]) 264.150 - ]) 264.151 - 264.152 -(defn pick 264.153 - "Return the next value of stream argument n inside a stream 264.154 - transformer. When used inside of defst, the name of the stream 264.155 - argument can be used instead of its index n." 264.156 - [n] 264.157 - (fn [streams] 264.158 - (let [[v ns] (stream-next (streams n))] 264.159 - (if (nil? ns) 264.160 - [nil nil] 264.161 - [v (assoc streams n ns)])))) 264.162 - 264.163 -(defn pick-all 264.164 - "Return a vector containing the next value of each stream argument 264.165 - inside a stream transformer." 264.166 - [streams] 264.167 - (let [next (map stream-next streams) 264.168 - values (map first next) 264.169 - streams (vec (map second next))] 264.170 - (if (some nil? streams) 264.171 - [nil nil] 264.172 - [values streams]))) 264.173 - 264.174 -(deftype ::stream-transformer st-as-stream 264.175 - (fn [st streams] [st streams]) 264.176 - seq) 264.177 - 264.178 -(defstream ::stream-transformer 264.179 - [[st streams]] 264.180 - (loop [s streams] 264.181 - (let [[v ns] (st s)] 264.182 - (cond (nil? ns) [nil nil] 264.183 - (stream-skip? v) (recur ns) 264.184 - :else [v (st-as-stream st ns)])))) 264.185 - 264.186 -(defmacro defst 264.187 - "Define the stream transformer name by body. 264.188 - The non-stream arguments args and the stream arguments streams 264.189 - are given separately, with args being possibly empty." 264.190 - [name args streams & body] 264.191 - (if (= (first streams) '&) 264.192 - `(defn ~name ~(vec (concat args streams)) 264.193 - (let [~'st (with-monad stream-m ~@body)] 264.194 - (st-as-stream ~'st ~(second streams)))) 264.195 - `(defn ~name ~(vec (concat args streams)) 264.196 - (let [~'st (with-monad stream-m 264.197 - (let [~streams (range ~(count streams))] 264.198 - ~@body))] 264.199 - (st-as-stream ~'st ~streams))))) 264.200 - 264.201 -; 264.202 -; Stream utilities 264.203 -; 264.204 -(defn stream-drop 264.205 - "Return a stream containing all but the first n elements of stream." 264.206 - [n stream] 264.207 - (if (zero? n) 264.208 - stream 264.209 - (let [[_ s] (stream-next stream)] 264.210 - (recur (dec n) s)))) 264.211 - 264.212 -; Map a function on a stream 264.213 -(deftype- ::stream-map stream-map-state) 264.214 - 264.215 -(defstream ::stream-map 264.216 - [[f stream]] 264.217 - (let [[v ns] (stream-next stream)] 264.218 - (if (nil? ns) 264.219 - [nil nil] 264.220 - [(f v) (stream-map-state [f ns])]))) 264.221 - 264.222 -(defmulti stream-map 264.223 - "Return a new stream by mapping the function f on the given stream." 264.224 - {:arglists '([f stream])} 264.225 - (fn [f stream] (type stream))) 264.226 - 264.227 -(defmethod stream-map :default 264.228 - [f stream] 264.229 - (stream-map-state [f stream])) 264.230 - 264.231 -(defmethod stream-map ::stream-map 264.232 - [f [g stream]] 264.233 - (stream-map-state [(comp f g) stream])) 264.234 - 264.235 -; Filter stream elements 264.236 -(deftype- ::stream-filter stream-filter-state) 264.237 - 264.238 -(defstream ::stream-filter 264.239 - [[p stream]] 264.240 - (loop [stream stream] 264.241 - (let [[v ns] (stream-next stream)] 264.242 - (cond (nil? ns) [nil nil] 264.243 - (p v) [v (stream-filter-state [p ns])] 264.244 - :else (recur ns))))) 264.245 - 264.246 -(defmulti stream-filter 264.247 - "Return a new stream that contrains the elements of stream 264.248 - that satisfy the predicate p." 264.249 - {:arglists '([p stream])} 264.250 - (fn [p stream] (type stream))) 264.251 - 264.252 -(defmethod stream-filter :default 264.253 - [p stream] 264.254 - (stream-filter-state [p stream])) 264.255 - 264.256 -(defmethod stream-filter ::stream-filter 264.257 - [p [q stream]] 264.258 - (stream-filter-state [(fn [v] (and (q v) (p v))) stream])) 264.259 - 264.260 -; Flatten a stream of sequences 264.261 -(deftype- ::stream-flatten stream-flatten-state) 264.262 - 264.263 -(defstream ::stream-flatten 264.264 - [[buffer stream]] 264.265 - (loop [buffer buffer 264.266 - stream stream] 264.267 - (if (nil? buffer) 264.268 - (let [[v new-stream] (stream-next stream)] 264.269 - (cond (nil? new-stream) [nil nil] 264.270 - (empty? v) (recur nil new-stream) 264.271 - :else (recur v new-stream))) 264.272 - [(first buffer) (stream-flatten-state [(next buffer) stream])]))) 264.273 - 264.274 -(defn stream-flatten 264.275 - "Converts a stream of sequences into a stream of the elements of the 264.276 - sequences. Flattening is not recursive, only one level of nesting 264.277 - will be removed." 264.278 - [s] 264.279 - (stream-flatten-state [nil s]))
265.1 --- a/src/clojure/contrib/string.clj Sat Aug 21 06:25:44 2010 -0400 265.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 265.3 @@ -1,382 +0,0 @@ 265.4 -;;; string.clj -- functional string utilities for Clojure 265.5 - 265.6 -;; by Stuart Sierra, http://stuartsierra.com/ 265.7 -;; January 26, 2010 265.8 - 265.9 -;; Copyright (c) Stuart Sierra, 2010. All rights reserved. The use 265.10 -;; and distribution terms for this software are covered by the Eclipse 265.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 265.12 -;; which can be found in the file epl-v10.html at the root of this 265.13 -;; distribution. By using this software in any fashion, you are 265.14 -;; agreeing to be bound by the terms of this license. You must not 265.15 -;; remove this notice, or any other, from this software. 265.16 - 265.17 -;; DEPRECATED in 1.2: Many functions have moved to clojure.string. 265.18 - 265.19 -(ns ^{:author "Stuart Sierra" 265.20 - :doc "This is a library of string manipulation functions. It 265.21 - is intented as a replacement for clojure.contrib.string. 265.22 - 265.23 - You cannot (use 'clojure.contrib.string) because it defines 265.24 - functions with the same names as functions in clojure.core. 265.25 - Instead, do (require '[clojure.contrib.string :as s]) 265.26 - or something similar. 265.27 - 265.28 - Goals: 265.29 - 1. Be functional 265.30 - 2. Most significant argument LAST, to work with ->> 265.31 - 3. At least O(n) performance for Strings of length n 265.32 - 265.33 - Some ideas are borrowed from 265.34 - http://github.com/francoisdevlin/devlinsf-clojure-utils/"} 265.35 - clojure.contrib.string 265.36 - (:refer-clojure :exclude (take replace drop butlast partition 265.37 - contains? get repeat reverse partial)) 265.38 - (:import (java.util.regex Pattern))) 265.39 - 265.40 - 265.41 -(defmacro dochars 265.42 - "bindings => [name string] 265.43 - 265.44 - Repeatedly executes body, with name bound to each character in 265.45 - string. Does NOT handle Unicode supplementary characters (above 265.46 - U+FFFF)." 265.47 - [bindings & body] 265.48 - (assert (vector bindings)) 265.49 - (assert (= 2 (count bindings))) 265.50 - ;; This seems to be the fastest way to iterate over characters. 265.51 - `(let [^String s# ~(second bindings)] 265.52 - (dotimes [i# (.length s#)] 265.53 - (let [~(first bindings) (.charAt s# i#)] 265.54 - ~@body)))) 265.55 - 265.56 - 265.57 -(defmacro docodepoints 265.58 - "bindings => [name string] 265.59 - 265.60 - Repeatedly executes body, with name bound to the integer code point 265.61 - of each Unicode character in the string. Handles Unicode 265.62 - supplementary characters (above U+FFFF) correctly." 265.63 - [bindings & body] 265.64 - (assert (vector bindings)) 265.65 - (assert (= 2 (count bindings))) 265.66 - (let [character (first bindings) 265.67 - string (second bindings)] 265.68 - `(let [^String s# ~string 265.69 - len# (.length s#)] 265.70 - (loop [i# 0] 265.71 - (when (< i# len#) 265.72 - (let [~character (.charAt s# i#)] 265.73 - (if (Character/isHighSurrogate ~character) 265.74 - (let [~character (.codePointAt s# i#)] 265.75 - ~@body 265.76 - (recur (+ 2 i#))) 265.77 - (let [~character (int ~character)] 265.78 - ~@body 265.79 - (recur (inc i#)))))))))) 265.80 - 265.81 -(defn codepoints 265.82 - "Returns a sequence of integer Unicode code points in s. Handles 265.83 - Unicode supplementary characters (above U+FFFF) correctly." 265.84 - [^String s] 265.85 - (let [len (.length s) 265.86 - f (fn thisfn [^String s i] 265.87 - (when (< i len) 265.88 - (let [c (.charAt s i)] 265.89 - (if (Character/isHighSurrogate c) 265.90 - (cons (.codePointAt s i) (thisfn s (+ 2 i))) 265.91 - (cons (int c) (thisfn s (inc i)))))))] 265.92 - (lazy-seq (f s 0)))) 265.93 - 265.94 -(defn ^String escape 265.95 - "Returns a new String by applying cmap (a function or a map) to each 265.96 - character in s. If cmap returns nil, the original character is 265.97 - added to the output unchanged." 265.98 - {:deprecated "1.2"} 265.99 - [cmap ^String s] 265.100 - (let [buffer (StringBuilder. (.length s))] 265.101 - (dochars [c s] 265.102 - (if-let [r (cmap c)] 265.103 - (.append buffer r) 265.104 - (.append buffer c))) 265.105 - (.toString buffer))) 265.106 - 265.107 -(defn blank? 265.108 - "True if s is nil, empty, or contains only whitespace." 265.109 - {:deprecated "1.2"} 265.110 - [^String s] 265.111 - (every? (fn [^Character c] (Character/isWhitespace c)) s)) 265.112 - 265.113 -(defn ^String take 265.114 - "Take first n characters from s, up to the length of s." 265.115 - [n ^String s] 265.116 - (if (< (count s) n) 265.117 - s 265.118 - (.substring s 0 n))) 265.119 - 265.120 -(defn ^String drop 265.121 - "Drops first n characters from s. Returns an empty string if n is 265.122 - greater than the length of s." 265.123 - [n ^String s] 265.124 - (if (< (count s) n) 265.125 - "" 265.126 - (.substring s n))) 265.127 - 265.128 -(defn ^String butlast 265.129 - "Returns s without the last n characters. Returns an empty string 265.130 - if n is greater than the length of s." 265.131 - [n ^String s] 265.132 - (if (< (count s) n) 265.133 - "" 265.134 - (.substring s 0 (- (count s) n)))) 265.135 - 265.136 -(defn ^String tail 265.137 - "Returns the last n characters of s." 265.138 - [n ^String s] 265.139 - (if (< (count s) n) 265.140 - s 265.141 - (.substring s (- (count s) n)))) 265.142 - 265.143 -(defn ^String repeat 265.144 - "Returns a new String containing s repeated n times." 265.145 - [n ^String s] 265.146 - (apply str (clojure.core/repeat n s))) 265.147 - 265.148 -(defn ^String reverse 265.149 - "Returns s with its characters reversed." 265.150 - {:deprecated "1.2"} 265.151 - [^String s] 265.152 - (.toString (.reverse (StringBuilder. s)))) 265.153 - 265.154 -(defn replace-str 265.155 - "Replaces all instances of substring a with b in s." 265.156 - {:deprecated "1.2"} 265.157 - [^String a ^String b ^String s] 265.158 - (.replace s a b)) 265.159 - 265.160 -(defn replace-char 265.161 - "Replaces all instances of character a with character b in s." 265.162 - {:deprecated "1.2"} 265.163 - [^Character a ^Character b ^String s] 265.164 - (.replace s a b)) 265.165 - 265.166 -(defn replace-re 265.167 - "Replaces all matches of re with replacement in s." 265.168 - {:deprecated "1.2"} 265.169 - [re replacement ^String s] 265.170 - (.replaceAll (re-matcher re s) replacement)) 265.171 - 265.172 -(defn replace-by 265.173 - "Replaces all matches of re in s with the result of 265.174 - (f (re-groups the-match))." 265.175 - {:deprecated "1.2"} 265.176 - [re f ^String s] 265.177 - (let [m (re-matcher re s)] 265.178 - (let [buffer (StringBuffer. (.length s))] 265.179 - (loop [] 265.180 - (if (.find m) 265.181 - (do (.appendReplacement m buffer (f (re-groups m))) 265.182 - (recur)) 265.183 - (do (.appendTail m buffer) 265.184 - (.toString buffer))))))) 265.185 - 265.186 -(defn replace-first-str 265.187 - "Replace first occurance of substring a with b in s." 265.188 - {:deprecated "1.2"} 265.189 - [^String a ^String b ^String s] 265.190 - (.replaceFirst (re-matcher (Pattern/quote a) s) b)) 265.191 - 265.192 -(defn replace-first-re 265.193 - "Replace first match of re in s." 265.194 - {:deprecated "1.2"} 265.195 - [^Pattern re ^String replacement ^String s] 265.196 - (.replaceFirst (re-matcher re s) replacement)) 265.197 - 265.198 -(defn replace-first-by 265.199 - "Replace first match of re in s with the result of 265.200 - (f (re-groups the-match))." 265.201 - {:deprecated "1.2"} 265.202 - [^Pattern re f ^String s] 265.203 - (let [m (re-matcher re s)] 265.204 - (let [buffer (StringBuffer.)] 265.205 - (if (.find m) 265.206 - (let [rep (f (re-groups m))] 265.207 - (.appendReplacement m buffer rep) 265.208 - (.appendTail m buffer) 265.209 - (str buffer)))))) 265.210 - 265.211 -(defn partition 265.212 - "Splits the string into a lazy sequence of substrings, alternating 265.213 - between substrings that match the patthern and the substrings 265.214 - between the matches. The sequence always starts with the substring 265.215 - before the first match, or an empty string if the beginning of the 265.216 - string matches. 265.217 - 265.218 - For example: (partition #\"[a-z]+\" \"abc123def\") 265.219 - returns: (\"\" \"abc\" \"123\" \"def\")" 265.220 - [^Pattern re ^String s] 265.221 - (let [m (re-matcher re s)] 265.222 - ((fn step [prevend] 265.223 - (lazy-seq 265.224 - (if (.find m) 265.225 - (cons (.subSequence s prevend (.start m)) 265.226 - (cons (re-groups m) 265.227 - (step (+ (.start m) (count (.group m)))))) 265.228 - (when (< prevend (.length s)) 265.229 - (list (.subSequence s prevend (.length s))))))) 265.230 - 0))) 265.231 - 265.232 -(defn ^String join 265.233 - "Returns a string of all elements in coll, separated by 265.234 - separator. Like Perl's join." 265.235 - {:deprecated "1.2"} 265.236 - [^String separator coll] 265.237 - (apply str (interpose separator coll))) 265.238 - 265.239 -(defn ^String chop 265.240 - "Removes the last character of string, does nothing on a zero-length 265.241 - string." 265.242 - [^String s] 265.243 - (let [size (count s)] 265.244 - (if (zero? size) 265.245 - s 265.246 - (subs s 0 (dec (count s)))))) 265.247 - 265.248 -(defn ^String chomp 265.249 - "Removes all trailing newline \\n or return \\r characters from 265.250 - string. Note: String.trim() is similar and faster. 265.251 - Deprecated in 1.2. Use clojure.string/trim-newline" 265.252 - {:deprecated "1.2"} 265.253 - [^String s] 265.254 - (replace-re #"[\r\n]+$" "" s)) 265.255 - 265.256 -(defn ^String swap-case 265.257 - "Changes upper case characters to lower case and vice-versa. 265.258 - Handles Unicode supplementary characters correctly. Uses the 265.259 - locale-sensitive String.toUpperCase() and String.toLowerCase() 265.260 - methods." 265.261 - [^String s] 265.262 - (let [buffer (StringBuilder. (.length s)) 265.263 - ;; array to make a String from one code point 265.264 - ^"[I" array (make-array Integer/TYPE 1)] 265.265 - (docodepoints [c s] 265.266 - (aset-int array 0 c) 265.267 - (if (Character/isLowerCase c) 265.268 - ;; Character.toUpperCase is not locale-sensitive, but 265.269 - ;; String.toUpperCase is; so we use a String. 265.270 - (.append buffer (.toUpperCase (String. array 0 1))) 265.271 - (.append buffer (.toLowerCase (String. array 0 1))))) 265.272 - (.toString buffer))) 265.273 - 265.274 -(defn ^String capitalize 265.275 - "Converts first character of the string to upper-case, all other 265.276 - characters to lower-case." 265.277 - {:deprecated "1.2"} 265.278 - [^String s] 265.279 - (if (< (count s) 2) 265.280 - (.toUpperCase s) 265.281 - (str (.toUpperCase ^String (subs s 0 1)) 265.282 - (.toLowerCase ^String (subs s 1))))) 265.283 - 265.284 -(defn ^String ltrim 265.285 - "Removes whitespace from the left side of string. 265.286 - Deprecated in 1.2. Use clojure.string/triml." 265.287 - {:deprecated "1.2"} 265.288 - [^String s] 265.289 - (replace-re #"^\s+" "" s)) 265.290 - 265.291 -(defn ^String rtrim 265.292 - "Removes whitespace from the right side of string. 265.293 - Deprecated in 1.2. Use clojure.string/trimr." 265.294 - {:deprecated "1.2"} 265.295 - [^String s] 265.296 - (replace-re #"\s+$" "" s)) 265.297 - 265.298 -(defn split-lines 265.299 - "Splits s on \\n or \\r\\n." 265.300 - {:deprecated "1.2"} 265.301 - [^String s] 265.302 - (seq (.split #"\r?\n" s))) 265.303 - 265.304 -;; borrowed from compojure.string, by James Reeves, EPL 1.0 265.305 -(defn ^String map-str 265.306 - "Apply f to each element of coll, concatenate all results into a 265.307 - String." 265.308 - [f coll] 265.309 - (apply str (map f coll))) 265.310 - 265.311 -;; borrowed from compojure.string, by James Reeves, EPL 1.0 265.312 -(defn grep 265.313 - "Filters elements of coll by a regular expression. The String 265.314 - representation (with str) of each element is tested with re-find." 265.315 - [re coll] 265.316 - (filter (fn [x] (re-find re (str x))) coll)) 265.317 - 265.318 -(defn as-str 265.319 - "Like clojure.core/str, but if an argument is a keyword or symbol, 265.320 - its name will be used instead of its literal representation. 265.321 - 265.322 - Example: 265.323 - (str :foo :bar) ;;=> \":foo:bar\" 265.324 - (as-str :foo :bar) ;;=> \"foobar\" 265.325 - 265.326 - Note that this does not apply to keywords or symbols nested within 265.327 - data structures; they will be rendered as with str. 265.328 - 265.329 - Example: 265.330 - (str {:foo :bar}) ;;=> \"{:foo :bar}\" 265.331 - (as-str {:foo :bar}) ;;=> \"{:foo :bar}\" " 265.332 - ([] "") 265.333 - ([x] (if (instance? clojure.lang.Named x) 265.334 - (name x) 265.335 - (str x))) 265.336 - ([x & ys] 265.337 - ((fn [^StringBuilder sb more] 265.338 - (if more 265.339 - (recur (. sb (append (as-str (first more)))) (next more)) 265.340 - (str sb))) 265.341 - (new StringBuilder ^String (as-str x)) ys))) 265.342 - 265.343 - 265.344 -;;; WRAPPERS 265.345 - 265.346 -;; The following functions are simple wrappers around java.lang.String 265.347 -;; functions. They are included here for completeness, and for use 265.348 -;; when mapping over a collection of strings. 265.349 - 265.350 -(defn ^String upper-case 265.351 - "Converts string to all upper-case." 265.352 - {:deprecated "1.2"} 265.353 - [^String s] 265.354 - (.toUpperCase s)) 265.355 - 265.356 -(defn ^String lower-case 265.357 - "Converts string to all lower-case." 265.358 - {:deprecated "1.2"} 265.359 - [^String s] 265.360 - (.toLowerCase s)) 265.361 - 265.362 -(defn split 265.363 - "Splits string on a regular expression. Optional argument limit is 265.364 - the maximum number of splits." 265.365 - {:deprecated "1.2"} 265.366 - ([^Pattern re ^String s] (seq (.split re s))) 265.367 - ([^Pattern re limit ^String s] (seq (.split re s limit)))) 265.368 - 265.369 -(defn ^String trim 265.370 - "Removes whitespace from both ends of string." 265.371 - {:deprecated "1.2"} 265.372 - [^String s] 265.373 - (.trim s)) 265.374 - 265.375 -(defn ^String substring? 265.376 - "True if s contains the substring." 265.377 - [substring ^String s] 265.378 - (.contains s substring)) 265.379 - 265.380 -(defn ^String get 265.381 - "Gets the i'th character in string." 265.382 - {:deprecated "1.2"} 265.383 - [^String s i] 265.384 - (.charAt s i)) 265.385 -
266.1 --- a/src/clojure/contrib/strint.clj Sat Aug 21 06:25:44 2010 -0400 266.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 266.3 @@ -1,72 +0,0 @@ 266.4 -;;; strint.clj -- String interpolation for Clojure 266.5 -;; originally proposed/published at http://muckandbrass.com/web/x/AgBP 266.6 - 266.7 -;; by Chas Emerick <cemerick@snowtide.com> 266.8 -;; December 4, 2009 266.9 - 266.10 -;; Copyright (c) Chas Emerick, 2009. All rights reserved. The use 266.11 -;; and distribution terms for this software are covered by the Eclipse 266.12 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 266.13 -;; which can be found in the file epl-v10.html at the root of this 266.14 -;; distribution. By using this software in any fashion, you are 266.15 -;; agreeing to be bound by the terms of this license. You must not 266.16 -;; remove this notice, or any other, from this software. 266.17 - 266.18 -(ns 266.19 - ^{:author "Chas Emerick", 266.20 - :doc "String interpolation for Clojure."} 266.21 - clojure.contrib.strint) 266.22 - 266.23 -(defn- silent-read 266.24 - "Attempts to clojure.core/read a single form from the provided String, returning 266.25 - a vector containing the read form and a String containing the unread remainder 266.26 - of the provided String. Returns nil if no valid form can be read from the 266.27 - head of the String." 266.28 - [s] 266.29 - (try 266.30 - (let [r (-> s java.io.StringReader. java.io.PushbackReader.)] 266.31 - [(read r) (slurp r)]) 266.32 - (catch Exception e))) ; this indicates an invalid form -- the head of s is just string data 266.33 - 266.34 -(defn- interpolate 266.35 - "Yields a seq of Strings and read forms." 266.36 - ([s atom?] 266.37 - (lazy-seq 266.38 - (if-let [[form rest] (silent-read (subs s (if atom? 2 1)))] 266.39 - (cons form (interpolate (if atom? (subs rest 1) rest))) 266.40 - (cons (subs s 0 2) (interpolate (subs s 2)))))) 266.41 - ([^String s] 266.42 - (if-let [start (->> ["~{" "~("] 266.43 - (map #(.indexOf s %)) 266.44 - (remove #(== -1 %)) 266.45 - sort 266.46 - first)] 266.47 - (lazy-seq (cons 266.48 - (subs s 0 start) 266.49 - (interpolate (subs s start) (= \{ (.charAt s (inc start)))))) 266.50 - [s]))) 266.51 - 266.52 -(defmacro << 266.53 - "Takes a single string argument and emits a str invocation that concatenates 266.54 - the string data and evaluated expressions contained within that argument. 266.55 - Evaluation is controlled using ~{} and ~() forms. The former is used for 266.56 - simple value replacement using clojure.core/str; the latter can be used to 266.57 - embed the results of arbitrary function invocation into the produced string. 266.58 - 266.59 - Examples: 266.60 - user=> (def v 30.5) 266.61 - #'user/v 266.62 - user=> (<< \"This trial required ~{v}ml of solution.\") 266.63 - \"This trial required 30.5ml of solution.\" 266.64 - user=> (<< \"There are ~(int v) days in November.\") 266.65 - \"There are 30 days in November.\" 266.66 - user=> (def m {:a [1 2 3]}) 266.67 - #'user/m 266.68 - user=> (<< \"The total for your order is $~(->> m :a (apply +)).\") 266.69 - \"The total for your order is $6.\" 266.70 - 266.71 - Note that quotes surrounding string literals within ~() forms must be 266.72 - escaped." 266.73 - [string] 266.74 - `(str ~@(interpolate string))) 266.75 -
267.1 --- a/src/clojure/contrib/swing_utils.clj Sat Aug 21 06:25:44 2010 -0400 267.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 267.3 @@ -1,152 +0,0 @@ 267.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 267.5 -;; distribution terms for this software are covered by the Eclipse Public 267.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 267.7 -;; be found in the file epl-v10.html at the root of this distribution. By 267.8 -;; using this software in any fashion, you are agreeing to be bound by the 267.9 -;; terms of this license. You must not remove this notice, or any other, 267.10 -;; from this software. 267.11 -;; 267.12 -;; clojure.contrib.swing-utils 267.13 -;; 267.14 -;; Useful functions for interfacing Clojure to Swing 267.15 -;; 267.16 -;; scgilardi (gmail) 267.17 -;; Created 31 May 2009 267.18 - 267.19 -(ns clojure.contrib.swing-utils 267.20 - (:import (java.awt.event ActionListener KeyAdapter) 267.21 - (javax.swing AbstractAction Action 267.22 - JMenu JMenuBar JMenuItem 267.23 - SwingUtilities)) 267.24 - (:use [clojure.contrib.def :only (defvar)])) 267.25 - 267.26 -(defn add-action-listener 267.27 - "Adds an ActionLister to component. When the action fires, f will be 267.28 - invoked with the event as its first argument followed by args. 267.29 - Returns the listener." 267.30 - [component f & args] 267.31 - (let [listener (proxy [ActionListener] [] 267.32 - (actionPerformed [event] (apply f event args)))] 267.33 - (.addActionListener component listener) 267.34 - listener)) 267.35 - 267.36 -(defn add-key-typed-listener 267.37 - "Adds a KeyListener to component that only responds to KeyTyped events. 267.38 - When a key is typed, f is invoked with the KeyEvent as its first argument 267.39 - followed by args. Returns the listener." 267.40 - [component f & args] 267.41 - (let [listener (proxy [KeyAdapter] [] 267.42 - (keyTyped [event] (apply f event args)))] 267.43 - (.addKeyListener component listener) 267.44 - listener)) 267.45 - 267.46 -;; ---------------------------------------------------------------------- 267.47 -;; Meikel Brandmeyer 267.48 - 267.49 -(defn do-swing* 267.50 - "Runs thunk in the Swing event thread according to schedule: 267.51 - - :later => schedule the execution and return immediately 267.52 - - :now => wait until the execution completes." 267.53 - [schedule thunk] 267.54 - (cond 267.55 - (= schedule :later) (SwingUtilities/invokeLater thunk) 267.56 - (= schedule :now) (if (SwingUtilities/isEventDispatchThread) 267.57 - (thunk) 267.58 - (SwingUtilities/invokeAndWait thunk))) 267.59 - nil) 267.60 - 267.61 -(defmacro do-swing 267.62 - "Executes body in the Swing event thread asynchronously. Returns 267.63 - immediately after scheduling the execution." 267.64 - [& body] 267.65 - `(do-swing* :later (fn [] ~@body))) 267.66 - 267.67 -(defmacro do-swing-and-wait 267.68 - "Executes body in the Swing event thread synchronously. Returns 267.69 - after the execution is complete." 267.70 - [& body] 267.71 - `(do-swing* :now (fn [] ~@body))) 267.72 - 267.73 -(defvar action-translation-table 267.74 - (atom {:name Action/NAME 267.75 - :accelerator Action/ACCELERATOR_KEY 267.76 - :command-key Action/ACTION_COMMAND_KEY 267.77 - :long-desc Action/LONG_DESCRIPTION 267.78 - :short-desc Action/SHORT_DESCRIPTION 267.79 - :mnemonic Action/MNEMONIC_KEY 267.80 - :icon Action/SMALL_ICON}) 267.81 - "Translation table for the make-action constructor.") 267.82 - 267.83 -(defn make-action 267.84 - "Create an Action proxy from the given action spec. The standard keys 267.85 - recognised are: :name, :accelerator, :command-key, :long-desc, 267.86 - :short-desc, :mnemonic and :icon - corresponding to the similar named 267.87 - Action properties. The :handler value is used in the actionPerformed 267.88 - method of the proxy to pass on the event." 267.89 - [spec] 267.90 - (let [t-table @action-translation-table 267.91 - handler (:handler spec) 267.92 - spec (dissoc spec :handler) 267.93 - spec (map (fn [[k v]] [(t-table k) v]) spec) 267.94 - action (proxy [AbstractAction] [] 267.95 - (actionPerformed [evt] (handler evt)))] 267.96 - (doseq [[k v] spec] 267.97 - (.putValue action k v)) 267.98 - action)) 267.99 - 267.100 -(defvar menu-constructor-dispatch 267.101 - (atom #{:action :handler :items}) 267.102 - "An atom containing the dispatch set for the add-menu-item method.") 267.103 - 267.104 -(defmulti add-menu-item 267.105 - "Adds a menu item to the parent according to the item description. 267.106 - The item description is a map of the following structure. 267.107 - 267.108 - Either: 267.109 - - one single :action specifying a javax.swing.Action to be associated 267.110 - with the item. 267.111 - - a specification suitable for make-action 267.112 - - a set of :name, :mnemonic and :items keys, specifying a submenu with 267.113 - the given sequence of item entries. 267.114 - - an empty map specifying a separator." 267.115 - {:arglists '([parent item])} 267.116 - (fn add-menu-item-dispatch [_ item] 267.117 - (some @menu-constructor-dispatch (keys item)))) 267.118 - 267.119 -(defmethod add-menu-item :action 267.120 - add-menu-item-action 267.121 - [parent {:keys [action]}] 267.122 - (let [item (JMenuItem. action)] 267.123 - (.add parent item))) 267.124 - 267.125 -(defmethod add-menu-item :handler 267.126 - add-menu-item-handler 267.127 - [parent spec] 267.128 - (add-menu-item parent {:action (make-action spec)})) 267.129 - 267.130 -(defmethod add-menu-item :items 267.131 - add-menu-item-submenu 267.132 - [parent {:keys [items mnemonic name]}] 267.133 - (let [menu (JMenu. name)] 267.134 - (when mnemonic 267.135 - (.setMnemonic menu mnemonic)) 267.136 - (doseq [item items] 267.137 - (add-menu-item menu item)) 267.138 - (.add parent menu))) 267.139 - 267.140 -(defmethod add-menu-item nil ; nil meaning separator 267.141 - add-menu-item-separator 267.142 - [parent _] 267.143 - (.addSeparator parent)) 267.144 - 267.145 -(defn make-menubar 267.146 - "Create a menubar containing the given sequence of menu items. The menu 267.147 - items are described by a map as is detailed in the docstring of the 267.148 - add-menu-item function." 267.149 - [menubar-items] 267.150 - (let [menubar (JMenuBar.)] 267.151 - (doseq [item menubar-items] 267.152 - (add-menu-item menubar item)) 267.153 - menubar)) 267.154 - 267.155 -;; ----------------------------------------------------------------------
268.1 --- a/src/clojure/contrib/test_contrib/accumulators/examples.clj Sat Aug 21 06:25:44 2010 -0400 268.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 268.3 @@ -1,93 +0,0 @@ 268.4 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 268.5 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 268.6 -;; 268.7 -;; Accumulator application examples 268.8 -;; 268.9 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 268.10 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 268.11 - 268.12 -(ns 268.13 - #^{:author "Konrad Hinsen" 268.14 - :skip-wiki true 268.15 - :doc "Examples for using accumulators"} 268.16 - clojure.contrib.accumulators.examples 268.17 - (:use [clojure.contrib.accumulators 268.18 - :only (combine add add-items 268.19 - empty-vector empty-list empty-queue empty-set empty-map 268.20 - empty-counter empty-counter-with-total 268.21 - empty-sum empty-product empty-maximum empty-minimum 268.22 - empty-min-max empty-mean-variance empty-string empty-tuple)])) 268.23 - 268.24 -; Vector accumulator: combine is concat, add is conj 268.25 -(combine [:a :b] [:c :d] [:x :y]) 268.26 -(add [:a :b] :c) 268.27 -(add-items empty-vector [:a :b :a]) 268.28 - 268.29 -; List accumulator: combine is concat, add is conj 268.30 -(combine '(:a :b) '(:c :d) '(:x :y)) 268.31 -(add '(:a :b) :c) 268.32 -(add-items empty-list [:a :b :a]) 268.33 - 268.34 -; Queue accumulator 268.35 -(let [q1 (add-items empty-queue [:a :b :a]) 268.36 - q2 (add-items empty-queue [:x :y])] 268.37 - (combine q1 q2)) 268.38 - 268.39 -; Set accumulator: combine is union, add is conj 268.40 -(combine #{:a :b} #{:c :d} #{:a :d}) 268.41 -(add #{:a :b} :c) 268.42 -(add-items empty-set [:a :b :a]) 268.43 - 268.44 -; Map accumulator: combine is merge, add is conj 268.45 -(combine {:a 1} {:b 2 :c 3} {}) 268.46 -(add {:a 1} [:b 2]) 268.47 -(add-items empty-map [[:a 1] [:b 2] [:a 0]]) 268.48 - 268.49 -; Counter accumulator 268.50 -(let [c1 (add-items empty-counter [:a :b :a]) 268.51 - c2 (add-items empty-counter [:x :y])] 268.52 - (combine c1 c2)) 268.53 - 268.54 -; Counter-with-total accumulator 268.55 -(let [c1 (add-items empty-counter-with-total [:a :b :a]) 268.56 - c2 (add-items empty-counter-with-total [:x :y])] 268.57 - (combine c1 c2)) 268.58 - 268.59 -; Sum accumulator: combine is addition 268.60 -(let [s1 (add-items empty-sum [1 2 3]) 268.61 - s2 (add-items empty-sum [-1 -2 -3])] 268.62 - (combine s1 s2)) 268.63 - 268.64 -; Product accumulator: combine is multiplication 268.65 -(let [p1 (add-items empty-product [2 3]) 268.66 - p2 (add-items empty-product [(/ 1 2)])] 268.67 - (combine p1 p2)) 268.68 - 268.69 -; Maximum accumulator: combine is max 268.70 -(let [m1 (add-items empty-maximum [2 3]) 268.71 - m2 (add-items empty-maximum [(/ 1 2)])] 268.72 - (combine m1 m2)) 268.73 - 268.74 -; Minimum accumulator: combine is min 268.75 -(let [m1 (add-items empty-minimum [2 3]) 268.76 - m2 (add-items empty-minimum [(/ 1 2)])] 268.77 - (combine m1 m2)) 268.78 - 268.79 -; Min-max accumulator: combination of minimum and maximum 268.80 -(let [m1 (add-items empty-min-max [2 3]) 268.81 - m2 (add-items empty-min-max [(/ 1 2)])] 268.82 - (combine m1 m2)) 268.83 - 268.84 -; Mean-variance accumulator: sample mean and sample variance 268.85 -(let [m1 (add-items empty-mean-variance [2 4]) 268.86 - m2 (add-items empty-mean-variance [6])] 268.87 - (combine m1 m2)) 268.88 - 268.89 -; String accumulator: combine is concatenation 268.90 -(combine "a" "b" "c" "def") 268.91 -(add "a" (char 44)) 268.92 -(add-items empty-string [(char 55) (char 56) (char 57)]) 268.93 - 268.94 -; Accumulator tuples permit to update several accumulators in parallel 268.95 -(let [pair (empty-tuple [empty-vector empty-string])] 268.96 - (add-items pair [[1 "a"] [2 "b"]]))
269.1 --- a/src/clojure/contrib/test_contrib/condition/example.clj Sat Aug 21 06:25:44 2010 -0400 269.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 269.3 @@ -1,66 +0,0 @@ 269.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 269.5 -;; distribution terms for this software are covered by the Eclipse Public 269.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 269.7 -;; be found in the file epl-v10.html at the root of this distribution. By 269.8 -;; using this software in any fashion, you are agreeing to be bound by the 269.9 -;; terms of this license. You must not remove this notice, or any other, 269.10 -;; from this software. 269.11 -;; 269.12 -;; clojure.contrib.condition.example.clj 269.13 -;; 269.14 -;; scgilardi (gmail) 269.15 -;; Created 09 June 2009 269.16 - 269.17 -(ns clojure.contrib.condition.example 269.18 - (:use (clojure.contrib 269.19 - [condition 269.20 - :only (handler-case print-stack-trace raise *condition*)]))) 269.21 - 269.22 -(defn func [x y] 269.23 - "Raises an exception if x is negative" 269.24 - (when (neg? x) 269.25 - (raise :type :illegal-argument :arg 'x :value x)) 269.26 - (+ x y)) 269.27 - 269.28 -(defn main 269.29 - [] 269.30 - 269.31 - ;; simple handler 269.32 - 269.33 - (handler-case :type 269.34 - (println (func 3 4)) 269.35 - (println (func -5 10)) 269.36 - (handle :illegal-argument 269.37 - (print-stack-trace *condition*)) 269.38 - (println 3)) 269.39 - 269.40 - ;; multiple handlers 269.41 - 269.42 - (handler-case :type 269.43 - (println (func 4 1)) 269.44 - (println (func -3 22)) 269.45 - (handle :overflow 269.46 - (print-stack-trace *condition*)) 269.47 - (handle :illegal-argument 269.48 - (print-stack-trace *condition*))) 269.49 - 269.50 - ;; nested handlers 269.51 - 269.52 - (handler-case :type 269.53 - (handler-case :type 269.54 - nil 269.55 - nil 269.56 - (println 1) 269.57 - (println 2) 269.58 - (println 3) 269.59 - (println (func 8 2)) 269.60 - (println (func -6 17)) 269.61 - ;; no handler for :illegal-argument 269.62 - (handle :overflow 269.63 - (println "nested") 269.64 - (print-stack-trace *condition*))) 269.65 - (println (func 3 4)) 269.66 - (println (func -5 10)) 269.67 - (handle :illegal-argument 269.68 - (println "outer") 269.69 - (print-stack-trace *condition*))))
270.1 --- a/src/clojure/contrib/test_contrib/datalog/example.clj Sat Aug 21 06:25:44 2010 -0400 270.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 270.3 @@ -1,116 +0,0 @@ 270.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 270.5 -;; distribution terms for this software are covered by the Eclipse Public 270.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 270.7 -;; be found in the file epl-v10.html at the root of this distribution. By 270.8 -;; using this software in any fashion, you are agreeing to be bound by the 270.9 -;; terms of this license. You must not remove this notice, or any other, 270.10 -;; from this software. 270.11 -;; 270.12 -;; example.clj 270.13 -;; 270.14 -;; A Clojure implementation of Datalog - Example 270.15 -;; 270.16 -;; straszheimjeffrey (gmail) 270.17 -;; Created 2 March 2009 270.18 - 270.19 - 270.20 -(ns clojure.contrib.datalog.example 270.21 - (:use [clojure.contrib.datalog :only (build-work-plan run-work-plan)] 270.22 - [clojure.contrib.datalog.rules :only (<- ?- rules-set)] 270.23 - [clojure.contrib.datalog.database :only (make-database add-tuples)] 270.24 - [clojure.contrib.datalog.util :only (*trace-datalog*)])) 270.25 - 270.26 - 270.27 - 270.28 - 270.29 -(def db-base 270.30 - (make-database 270.31 - (relation :employee [:id :name :position]) 270.32 - (index :employee :name) 270.33 - 270.34 - (relation :boss [:employee-id :boss-id]) 270.35 - (index :boss :employee-id) 270.36 - 270.37 - (relation :can-do-job [:position :job]) 270.38 - (index :can-do-job :position) 270.39 - 270.40 - (relation :job-replacement [:job :can-be-done-by]) 270.41 - ;(index :job-replacement :can-be-done-by) 270.42 - 270.43 - (relation :job-exceptions [:id :job]))) 270.44 - 270.45 -(def db 270.46 - (add-tuples db-base 270.47 - [:employee :id 1 :name "Bob" :position :boss] 270.48 - [:employee :id 2 :name "Mary" :position :chief-accountant] 270.49 - [:employee :id 3 :name "John" :position :accountant] 270.50 - [:employee :id 4 :name "Sameer" :position :chief-programmer] 270.51 - [:employee :id 5 :name "Lilian" :position :programmer] 270.52 - [:employee :id 6 :name "Li" :position :technician] 270.53 - [:employee :id 7 :name "Fred" :position :sales] 270.54 - [:employee :id 8 :name "Brenda" :position :sales] 270.55 - [:employee :id 9 :name "Miki" :position :project-management] 270.56 - [:employee :id 10 :name "Albert" :position :technician] 270.57 - 270.58 - [:boss :employee-id 2 :boss-id 1] 270.59 - [:boss :employee-id 3 :boss-id 2] 270.60 - [:boss :employee-id 4 :boss-id 1] 270.61 - [:boss :employee-id 5 :boss-id 4] 270.62 - [:boss :employee-id 6 :boss-id 4] 270.63 - [:boss :employee-id 7 :boss-id 1] 270.64 - [:boss :employee-id 8 :boss-id 7] 270.65 - [:boss :employee-id 9 :boss-id 1] 270.66 - [:boss :employee-id 10 :boss-id 6] 270.67 - 270.68 - [:can-do-job :position :boss :job :management] 270.69 - [:can-do-job :position :accountant :job :accounting] 270.70 - [:can-do-job :position :chief-accountant :job :accounting] 270.71 - [:can-do-job :position :programmer :job :programming] 270.72 - [:can-do-job :position :chief-programmer :job :programming] 270.73 - [:can-do-job :position :technician :job :server-support] 270.74 - [:can-do-job :position :sales :job :sales] 270.75 - [:can-do-job :position :project-management :job :project-management] 270.76 - 270.77 - [:job-replacement :job :pc-support :can-be-done-by :server-support] 270.78 - [:job-replacement :job :pc-support :can-be-done-by :programming] 270.79 - [:job-replacement :job :payroll :can-be-done-by :accounting] 270.80 - 270.81 - [:job-exceptions :id 4 :job :pc-support])) 270.82 - 270.83 -(def rules 270.84 - (rules-set 270.85 - (<- (:works-for :employee ?x :boss ?y) (:boss :employee-id ?e-id :boss-id ?b-id) 270.86 - (:employee :id ?e-id :name ?x) 270.87 - (:employee :id ?b-id :name ?y)) 270.88 - (<- (:works-for :employee ?x :boss ?y) (:works-for :employee ?x :boss ?z) 270.89 - (:works-for :employee ?z :boss ?y)) 270.90 - (<- (:employee-job* :employee ?x :job ?y) (:employee :name ?x :position ?pos) 270.91 - (:can-do-job :position ?pos :job ?y)) 270.92 - (<- (:employee-job* :employee ?x :job ?y) (:job-replacement :job ?y :can-be-done-by ?z) 270.93 - (:employee-job* :employee ?x :job ?z)) 270.94 - (<- (:employee-job* :employee ?x :job ?y) (:can-do-job :job ?y) 270.95 - (:employee :name ?x :position ?z) 270.96 - (if = ?z :boss)) 270.97 - (<- (:employee-job :employee ?x :job ?y) (:employee-job* :employee ?x :job ?y) 270.98 - (:employee :id ?id :name ?x) 270.99 - (not! :job-exceptions :id ?id :job ?y)) 270.100 - (<- (:bj :name ?x :boss ?y) (:works-for :employee ?x :boss ?y) 270.101 - (not! :employee-job :employee ?y :job :pc-support)))) 270.102 - 270.103 - 270.104 - 270.105 -(def wp-1 (build-work-plan rules (?- :works-for :employee '??name :boss ?x))) 270.106 -(run-work-plan wp-1 db {'??name "Albert"}) 270.107 - 270.108 -(def wp-2 (build-work-plan rules (?- :employee-job :employee '??name :job ?x))) 270.109 -(binding [*trace-datalog* true] 270.110 - (run-work-plan wp-2 db {'??name "Li"})) 270.111 - 270.112 -(def wp-3 (build-work-plan rules (?- :bj :name '??name :boss ?x))) 270.113 -(run-work-plan wp-3 db {'??name "Albert"}) 270.114 - 270.115 -(def wp-4 (build-work-plan rules (?- :works-for :employee ?x :boss ?y))) 270.116 -(run-work-plan wp-4 db {}) 270.117 - 270.118 - 270.119 -;; End of file
271.1 --- a/src/clojure/contrib/test_contrib/datalog/tests/test.clj Sat Aug 21 06:25:44 2010 -0400 271.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 271.3 @@ -1,45 +0,0 @@ 271.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 271.5 -;; distribution terms for this software are covered by the Eclipse Public 271.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 271.7 -;; be found in the file epl-v10.html at the root of this distribution. By 271.8 -;; using this software in any fashion, you are agreeing to be bound by the 271.9 -;; terms of this license. You must not remove this notice, or any other, 271.10 -;; from this software. 271.11 -;; 271.12 -;; test.clj 271.13 -;; 271.14 -;; A Clojure implementation of Datalog -- Tests 271.15 -;; 271.16 -;; straszheimjeffrey (gmail) 271.17 -;; Created 11 Feburary 2009 271.18 - 271.19 -(ns clojure.contrib.datalog.tests.test 271.20 - (:use [clojure.test :only (run-tests)]) 271.21 - (:gen-class)) 271.22 - 271.23 -(def test-names [:test-util 271.24 - :test-database 271.25 - :test-literals 271.26 - :test-rules 271.27 - :test-magic 271.28 - :test-softstrat]) 271.29 - 271.30 -(def test-namespaces 271.31 - (map #(symbol (str "clojure.contrib.datalog.tests." (name %))) 271.32 - test-names)) 271.33 - 271.34 -(defn run 271.35 - "Runs all defined tests" 271.36 - [] 271.37 - (println "Loading tests...") 271.38 - (apply require :reload-all test-namespaces) 271.39 - (apply run-tests test-namespaces)) 271.40 - 271.41 -(defn -main 271.42 - "Run all defined tests from the command line" 271.43 - [& args] 271.44 - (run) 271.45 - (System/exit 0)) 271.46 - 271.47 - 271.48 -;; End of file
272.1 --- a/src/clojure/contrib/test_contrib/datalog/tests/test_database.clj Sat Aug 21 06:25:44 2010 -0400 272.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 272.3 @@ -1,153 +0,0 @@ 272.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 272.5 -;; distribution terms for this software are covered by the Eclipse Public 272.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 272.7 -;; be found in the file epl-v10.html at the root of this distribution. By 272.8 -;; using this software in any fashion, you are agreeing to be bound by the 272.9 -;; terms of this license. You must not remove this notice, or any other, 272.10 -;; from this software. 272.11 -;; 272.12 -;; test-database.clj 272.13 -;; 272.14 -;; A Clojure implementation of Datalog -- Database 272.15 -;; 272.16 -;; straszheimjeffrey (gmail) 272.17 -;; Created 12 Feburary 2009 272.18 - 272.19 - 272.20 -(ns clojure.contrib.datalog.tests.test-database 272.21 - (:use clojure.test 272.22 - clojure.contrib.datalog.database)) 272.23 - 272.24 - 272.25 -(def test-db 272.26 - (make-database 272.27 - (relation :fred [:mary :sue]) 272.28 - (index :fred :mary) 272.29 - (relation :sally [:jen :becky :joan]) 272.30 - (index :sally :jen) 272.31 - (index :sally :becky))) 272.32 - 272.33 -(deftest test-make-database 272.34 - (is (= test-db 272.35 - (datalog-database 272.36 - {:sally (datalog-relation 272.37 - #{:jen :joan :becky} 272.38 - #{} 272.39 - {:becky {} 272.40 - :jen {}}) 272.41 - :fred (datalog-relation 272.42 - #{:sue :mary} 272.43 - #{} 272.44 - {:mary {}})})))) 272.45 - 272.46 - 272.47 -(deftest test-ensure-relation 272.48 - (is (contains? (ensure-relation test-db :bob [:sam :george] [:sam]) :bob)) 272.49 - (is (contains? (ensure-relation test-db :fred [:mary :sue] [:mary]) :fred)) 272.50 - (is (thrown? AssertionError (ensure-relation test-db :fred [:bob :joe] [])))) 272.51 - 272.52 -(deftest test-add-tuple 272.53 - (let [new-db (add-tuple test-db :fred {:mary 1 :sue 2})] 272.54 - (is (= (select new-db :fred {:mary 1}) [{:mary 1 :sue 2}]))) 272.55 - (is (thrown? AssertionError (add-tuple test-db :fred {:mary 1})))) 272.56 - 272.57 -(def test-db-1 272.58 - (add-tuples test-db 272.59 - [:fred :mary 1 :sue 2] 272.60 - [:fred :mary 2 :sue 3] 272.61 - [:sally :jen 1 :becky 2 :joan 0] 272.62 - [:sally :jen 1 :becky 4 :joan 3] 272.63 - [:sally :jen 1 :becky 3 :joan 0] 272.64 - [:sally :jen 1 :becky 2 :joan 3] 272.65 - [:fred :mary 1 :sue 1] 272.66 - [:fred :mary 3 :sue 1])) 272.67 - 272.68 -(deftest test-add-tuples 272.69 - (is (= test-db-1 272.70 - (datalog-database 272.71 - {:sally (datalog-relation 272.72 - #{:jen :joan :becky} 272.73 - #{{:jen 1, :joan 0, :becky 3} 272.74 - {:jen 1, :joan 0, :becky 2} 272.75 - {:jen 1, :joan 3, :becky 2} 272.76 - {:jen 1, :joan 3, :becky 4}} 272.77 - {:becky {3 272.78 - #{{:jen 1, :joan 0, :becky 3}} 272.79 - 4 272.80 - #{{:jen 1, :joan 3, :becky 4}} 272.81 - 2 272.82 - #{{:jen 1, :joan 0, :becky 2} 272.83 - {:jen 1, :joan 3, :becky 2}}} 272.84 - :jen {1 272.85 - #{{:jen 1, :joan 0, :becky 3} 272.86 - {:jen 1, :joan 0, :becky 2} 272.87 - {:jen 1, :joan 3, :becky 2} 272.88 - {:jen 1, :joan 3, :becky 4}}}}) 272.89 - :fred (datalog-relation 272.90 - #{:sue :mary} 272.91 - #{{:sue 2, :mary 1} 272.92 - {:sue 1, :mary 1} 272.93 - {:sue 3, :mary 2} 272.94 - {:sue 1, :mary 3}} 272.95 - {:mary {3 272.96 - #{{:sue 1, :mary 3}} 272.97 - 2 272.98 - #{{:sue 3, :mary 2}} 272.99 - 1 272.100 - #{{:sue 2, :mary 1} 272.101 - {:sue 1, :mary 1}}}})})))) 272.102 - 272.103 -(deftest test-remove-tuples 272.104 - (let [db (reduce #(apply remove-tuple %1 (first %2) (next %2)) 272.105 - test-db-1 272.106 - [[:fred {:mary 1 :sue 1}] 272.107 - [:fred {:mary 3 :sue 1}] 272.108 - [:sally {:jen 1 :becky 2 :joan 0}] 272.109 - [:sally {:jen 1 :becky 4 :joan 3}]])] 272.110 - (is (= db 272.111 - (datalog-database 272.112 - {:sally (datalog-relation 272.113 - #{:jen :joan :becky} 272.114 - #{{:jen 1, :joan 0, :becky 3} 272.115 - {:jen 1, :joan 3, :becky 2}} 272.116 - {:becky 272.117 - {3 272.118 - #{{:jen 1, :joan 0, :becky 3}} 272.119 - 2 272.120 - #{{:jen 1, :joan 3, :becky 2}}} 272.121 - :jen 272.122 - {1 272.123 - #{{:jen 1, :joan 0, :becky 3} 272.124 - {:jen 1, :joan 3, :becky 2}}}}) 272.125 - :fred (datalog-relation 272.126 - #{:sue :mary} 272.127 - #{{:sue 2, :mary 1} 272.128 - {:sue 3, :mary 2}} 272.129 - {:mary 272.130 - {2 272.131 - #{{:sue 3, :mary 2}} 272.132 - 1 272.133 - #{{:sue 2, :mary 1}}}})}))))) 272.134 - 272.135 - 272.136 - 272.137 -(deftest test-select 272.138 - (is (= (set (select test-db-1 :sally {:jen 1 :becky 2})) 272.139 - #{{:jen 1 :joan 0 :becky 2} {:jen 1 :joan 3 :becky 2}})) 272.140 - (is (= (set (select test-db-1 :fred {:sue 1}))) 272.141 - #{{:mary 3 :sue 1} {:mary 1 :sue 1}}) 272.142 - (is (empty? (select test-db-1 :sally {:joan 5 :jen 1})))) 272.143 - 272.144 -(deftest test-any-match? 272.145 - (is (any-match? test-db-1 :fred {:mary 3})) 272.146 - (is (any-match? test-db-1 :sally {:jen 1 :becky 2 :joan 3})) 272.147 - (is (not (any-match? test-db-1 :sally {:jen 5}))) 272.148 - (is (not (any-match? test-db-1 :fred {:mary 1 :sue 5})))) 272.149 - 272.150 - 272.151 -(comment 272.152 - (run-tests) 272.153 -) 272.154 - 272.155 -;; End of file 272.156 -
273.1 --- a/src/clojure/contrib/test_contrib/datalog/tests/test_literals.clj Sat Aug 21 06:25:44 2010 -0400 273.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 273.3 @@ -1,187 +0,0 @@ 273.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 273.5 -;; distribution terms for this software are covered by the Eclipse Public 273.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 273.7 -;; be found in the file epl-v10.html at the root of this distribution. By 273.8 -;; using this software in any fashion, you are agreeing to be bound by the 273.9 -;; terms of this license. You must not remove this notice, or any other, 273.10 -;; from this software. 273.11 -;; 273.12 -;; test-literals.clj 273.13 -;; 273.14 -;; A Clojure implementation of Datalog -- Literals tests 273.15 -;; 273.16 -;; straszheimjeffrey (gmail) 273.17 -;; Created 25 Feburary 2009 273.18 - 273.19 - 273.20 -(ns clojure.contrib.datalog.tests.test-literals 273.21 - (:use clojure.test) 273.22 - (:use clojure.contrib.datalog.literals 273.23 - clojure.contrib.datalog.database)) 273.24 - 273.25 - 273.26 -(def pl (eval (build-literal '(:fred :x ?x :y ?y :z 3)))) 273.27 -(def nl (eval (build-literal '(not! :fred :x ?x :y ?y :z 3)))) 273.28 -(def cl (eval (build-literal '(if > ?x 3)))) 273.29 - 273.30 -(def bl (eval (build-literal '(:fred)))) 273.31 - 273.32 -(def bns {:x '?x :y '?y :z 3}) 273.33 - 273.34 -(deftest test-build-literal 273.35 - (is (= (:predicate pl) :fred)) 273.36 - (is (= (:term-bindings pl) bns)) 273.37 - (is (= (:predicate nl) :fred)) 273.38 - (is (= (:term-bindings nl) bns)) 273.39 - (is (= (:symbol cl) '>)) 273.40 - (is (= (:terms cl) '(?x 3))) 273.41 - (is ((:fun cl) [4 3])) 273.42 - (is (not ((:fun cl) [2 4]))) 273.43 - (is (= (:predicate bl) :fred))) 273.44 - 273.45 -(deftest test-literal-predicate 273.46 - (is (= (literal-predicate pl) :fred)) 273.47 - (is (= (literal-predicate nl) :fred)) 273.48 - (is (nil? (literal-predicate cl))) 273.49 - (is (= (literal-predicate bl) :fred))) 273.50 - 273.51 -(deftest test-literal-columns 273.52 - (is (= (literal-columns pl) #{:x :y :z})) 273.53 - (is (= (literal-columns nl) #{:x :y :z})) 273.54 - (is (nil? (literal-columns cl))) 273.55 - (is (empty? (literal-columns bl)))) 273.56 - 273.57 -(deftest test-literal-vars 273.58 - (is (= (literal-vars pl) #{'?x '?y})) 273.59 - (is (= (literal-vars nl) #{'?x '?y})) 273.60 - (is (= (literal-vars cl) #{'?x})) 273.61 - (is (empty? (literal-vars bl)))) 273.62 - 273.63 -(deftest test-positive-vars 273.64 - (is (= (positive-vars pl) (literal-vars pl))) 273.65 - (is (nil? (positive-vars nl))) 273.66 - (is (nil? (positive-vars cl))) 273.67 - (is (empty? (positive-vars bl)))) 273.68 - 273.69 -(deftest test-negative-vars 273.70 - (is (nil? (negative-vars pl))) 273.71 - (is (= (negative-vars nl) (literal-vars nl))) 273.72 - (is (= (negative-vars cl) (literal-vars cl))) 273.73 - (is (empty? (negative-vars bl)))) 273.74 - 273.75 -(deftest test-negated? 273.76 - (is (not (negated? pl))) 273.77 - (is (negated? nl)) 273.78 - (is (not (negated? cl)))) 273.79 - 273.80 -(deftest test-vs-from-cs 273.81 - (is (= (get-vs-from-cs pl #{:x}) #{'?x})) 273.82 - (is (empty? (get-vs-from-cs pl #{:z}))) 273.83 - (is (= (get-vs-from-cs pl #{:x :r}) #{'?x})) 273.84 - (is (empty? (get-vs-from-cs pl #{})))) 273.85 - 273.86 -(deftest test-cs-from-vs 273.87 - (is (= (get-cs-from-vs pl #{'?x}) #{:x})) 273.88 - (is (= (get-cs-from-vs pl #{'?x '?r}) #{:x})) 273.89 - (is (empty? (get-cs-from-vs pl #{})))) 273.90 - 273.91 -(deftest test-literal-appropriate? 273.92 - (is (not (literal-appropriate? #{} pl))) 273.93 - (is (literal-appropriate? #{'?x} pl)) 273.94 - (is (not (literal-appropriate? #{'?x} nl))) 273.95 - (is (literal-appropriate? #{'?x '?y} nl)) 273.96 - (is (not (literal-appropriate? #{'?z} cl))) 273.97 - (is (literal-appropriate? #{'?x} cl))) 273.98 - 273.99 -(deftest test-adorned-literal 273.100 - (is (= (literal-predicate (adorned-literal pl #{:x})) 273.101 - {:pred :fred :bound #{:x}})) 273.102 - (is (= (literal-predicate (adorned-literal nl #{:x :y :q})) 273.103 - {:pred :fred :bound #{:x :y}})) 273.104 - (is (= (:term-bindings (adorned-literal nl #{:x})) 273.105 - {:x '?x :y '?y :z 3})) 273.106 - (is (= (adorned-literal cl #{}) 273.107 - cl))) 273.108 - 273.109 -(deftest test-get-adorned-bindings 273.110 - (is (= (get-adorned-bindings (literal-predicate (adorned-literal pl #{:x}))) 273.111 - #{:x})) 273.112 - (is (= (get-adorned-bindings (literal-predicate pl)) 273.113 - nil))) 273.114 - 273.115 -(deftest test-get-base-predicate 273.116 - (is (= (get-base-predicate (literal-predicate (adorned-literal pl #{:x}))) 273.117 - :fred)) 273.118 - (is (= (get-base-predicate (literal-predicate pl)) 273.119 - :fred))) 273.120 - 273.121 -(deftest test-magic-literal 273.122 - (is (= (magic-literal pl) 273.123 - {:predicate {:pred :fred :magic true}, :term-bindings {}, :literal-type :clojure.contrib.datalog.literals/literal})) 273.124 - (is (= (magic-literal (adorned-literal pl #{:x})) 273.125 - {:predicate {:pred :fred :magic true :bound #{:x}}, 273.126 - :term-bindings {:x '?x}, 273.127 - :literal-type :clojure.contrib.datalog.literals/literal}))) 273.128 - 273.129 -(comment 273.130 - (use 'clojure.contrib.stacktrace) (e) 273.131 - (use :reload 'clojure.contrib.datalog.literals) 273.132 -) 273.133 - 273.134 - 273.135 -(def db1 (make-database 273.136 - (relation :fred [:x :y]) 273.137 - (index :fred :x) 273.138 - (relation :sally [:x]))) 273.139 - 273.140 -(def db2 (add-tuples db1 273.141 - [:fred :x 1 :y :mary] 273.142 - [:fred :x 1 :y :becky] 273.143 - [:fred :x 3 :y :sally] 273.144 - [:fred :x 4 :y :joe] 273.145 - [:sally :x 1] 273.146 - [:sally :x 2])) 273.147 - 273.148 -(def lit1 (eval (build-literal '(:fred :x ?x :y ?y)))) 273.149 -(def lit2 (eval (build-literal '(not! :fred :x ?x)))) 273.150 -(def lit3 (eval (build-literal '(if > ?x ?y)))) 273.151 -(def lit4 (adorned-literal (eval (build-literal '(:joan :x ?x :y ?y))) #{:x})) 273.152 - 273.153 -(deftest test-join-literal 273.154 - (is (= (set (join-literal db2 lit1 [{'?x 1} {'?x 2} {'?x 3}])) 273.155 - #{{'?x 1, '?y :mary} {'?x 1, '?y :becky} {'?x 3, '?y :sally}})) 273.156 - (is (= (join-literal db2 lit2 [{'?x 1} {'?x 2} {'?x 3}]) 273.157 - [{'?x 2}])) 273.158 - (is (= (join-literal db2 lit3 [{'?x 1 '?y 2} {'?x 3 '?y 1}]) 273.159 - [{'?x 3 '?y 1}]))) 273.160 - 273.161 -(deftest test-project-literal 273.162 - (is (= ((project-literal db2 lit4 [{'?x 1 '?y 3}{'?x 4 '?y 2}]) {:pred :joan :bound #{:x}}) 273.163 - (datalog-relation 273.164 - ;; Schema 273.165 - #{:y :x} 273.166 - 273.167 - ;; Data 273.168 - #{ 273.169 - {:x 1, :y 3} 273.170 - {:x 4, :y 2} 273.171 - } 273.172 - 273.173 - ;; Indexes 273.174 - { 273.175 - :x 273.176 - { 273.177 - 4 273.178 - #{{:x 4, :y 2}} 273.179 - 1 273.180 - #{{:x 1, :y 3}} 273.181 - } 273.182 - })))) 273.183 - 273.184 - 273.185 - 273.186 -(comment 273.187 - (run-tests) 273.188 -) 273.189 - 273.190 -;; End of file
274.1 --- a/src/clojure/contrib/test_contrib/datalog/tests/test_magic.clj Sat Aug 21 06:25:44 2010 -0400 274.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 274.3 @@ -1,72 +0,0 @@ 274.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 274.5 -;; distribution terms for this software are covered by the Eclipse Public 274.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 274.7 -;; be found in the file epl-v10.html at the root of this distribution. By 274.8 -;; using this software in any fashion, you are agreeing to be bound by the 274.9 -;; terms of this license. You must not remove this notice, or any other, 274.10 -;; from this software. 274.11 -;; 274.12 -;; test-magic.clj 274.13 -;; 274.14 -;; A Clojure implementation of Datalog -- Magic Tests 274.15 -;; 274.16 -;; straszheimjeffrey (gmail) 274.17 -;; Created 18 Feburary 2009 274.18 - 274.19 -(ns clojure.contrib.datalog.tests.test-magic 274.20 - (:use clojure.test) 274.21 - (:use clojure.contrib.datalog.magic 274.22 - clojure.contrib.datalog.rules)) 274.23 - 274.24 - 274.25 - 274.26 -(def rs (rules-set 274.27 - (<- (:p :x ?x :y ?y) (:e :x ?x :y ?y)) 274.28 - (<- (:p :x ?x :y ?y) (:e :x ?x :y ?z) (:p :x ?z :y ?y)) 274.29 - (<- (:e :x ?x :y ?y) (:b :x ?x :y ?y)) 274.30 - (<- (:e :x ?y :y ?y) (:c :x ?x :y ?y)))) 274.31 - 274.32 -(def q (adorn-query (?- :p :x 1 :y ?y))) 274.33 - 274.34 -(def ars (adorn-rules-set rs q)) 274.35 - 274.36 -(deftest test-adorn-rules-set 274.37 - (is (= ars 274.38 - (rules-set 274.39 - (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?y :x ?x)) 274.40 - (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :e :bound #{:x}} :y ?z :x ?x) 274.41 - ({:pred :p :bound #{:x}} :y ?y :x ?z)) 274.42 - (<- ({:pred :e :bound #{:x}} :y ?y :x ?y) (:c :y ?y :x ?x)) 274.43 - (<- ({:pred :e :bound #{:x}} :y ?y :x ?x) (:b :y ?y :x ?x)))))) 274.44 - 274.45 - 274.46 -(def m (magic-transform ars)) 274.47 - 274.48 -(deftest test-magic-transform 274.49 - (is (= m 274.50 - (rules-set 274.51 - (<- ({:pred :e :bound #{:x}} :y ?y :x ?y) ({:pred :e :magic true :bound #{:x}} :x ?y) (:c :y ?y :x ?x)) 274.52 - 274.53 - (<- ({:pred :e :bound #{:x}} :y ?y :x ?x) ({:pred :e :magic true :bound #{:x}} :x ?x) (:b :y ?y :x ?x)) 274.54 - 274.55 - (<- ({:pred :p :magic true :bound #{:x}} :x ?z) ({:pred :p :magic true :bound #{:x}} :x ?x) 274.56 - ({:pred :e :bound #{:x}} :y ?z :x ?x)) 274.57 - 274.58 - (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x) 274.59 - ({:pred :e :bound #{:x}} :y ?z :x ?x) 274.60 - ({:pred :p :bound #{:x}} :y ?y :x ?z)) 274.61 - 274.62 - (<- ({:pred :e :magic true :bound #{:x}} :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x)) 274.63 - 274.64 - (<- ({:pred :p :bound #{:x}} :y ?y :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x) 274.65 - ({:pred :e :bound #{:x}} :y ?y :x ?x)))))) 274.66 - 274.67 - 274.68 - 274.69 - 274.70 -(comment 274.71 - (run-tests) 274.72 -) 274.73 - 274.74 -;; End of file 274.75 -
275.1 --- a/src/clojure/contrib/test_contrib/datalog/tests/test_rules.clj Sat Aug 21 06:25:44 2010 -0400 275.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 275.3 @@ -1,130 +0,0 @@ 275.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 275.5 -;; distribution terms for this software are covered by the Eclipse Public 275.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 275.7 -;; be found in the file epl-v10.html at the root of this distribution. By 275.8 -;; using this software in any fashion, you are agreeing to be bound by the 275.9 -;; terms of this license. You must not remove this notice, or any other, 275.10 -;; from this software. 275.11 -;; 275.12 -;; test-rules.clj 275.13 -;; 275.14 -;; A Clojure implementation of Datalog -- Rule Tests 275.15 -;; 275.16 -;; straszheimjeffrey (gmail) 275.17 -;; Created 12 Feburary 2009 275.18 - 275.19 - 275.20 -(ns clojure.contrib.datalog.tests.test-rules 275.21 - (:use clojure.test 275.22 - clojure.contrib.datalog.rules 275.23 - clojure.contrib.datalog.literals 275.24 - clojure.contrib.datalog.database)) 275.25 - 275.26 - 275.27 -(def tr-1 (<- (:fred :x ?x :y ?y) (:mary :x ?x :z ?z) (:sally :z ?z :y ?y))) 275.28 -(def tr-2 (<- (:fred) (not! :mary :x 3))) 275.29 -(def tr-3 (<- (:fred :x ?x :y ?y) (if > ?x ?y) (:mary :x ?x) (:sally :y ?y))) 275.30 - 275.31 - 275.32 - 275.33 -(deftest test-rule-safety 275.34 - (is (thrown-with-msg? Exception #".*Head vars.*not bound.*" 275.35 - (<- (:fred :x ?x) (:sally :y ?y)))) 275.36 - (is (thrown-with-msg? Exception #".*Body vars.*not bound.*negative position.*" 275.37 - (<- (:fred :x ?x) (:becky :x ?x) (not! :sally :y ?y)))) 275.38 - (is (thrown-with-msg? Exception #".*Body vars.*not bound.*negative position.*" 275.39 - (<- (:fred :x ?x) (:becky :x ?x) (if > ?x ?y))))) 275.40 - 275.41 - 275.42 -(deftest test-sip 275.43 - (is (= (compute-sip #{:x} #{:mary :sally} tr-1) 275.44 - (<- ({:pred :fred :bound #{:x}} :x ?x :y ?y) 275.45 - ({:pred :mary :bound #{:x}} :z ?z :x ?x) 275.46 - ({:pred :sally :bound #{:z}} :y ?y :z ?z)))) 275.47 - 275.48 - (is (= (compute-sip #{} #{:mary :sally} tr-1) 275.49 - (<- (:fred :y ?y :x ?x) (:mary :z ?z :x ?x) ({:pred :sally :bound #{:z}} :y ?y :z ?z)))) 275.50 - 275.51 - (is (= (compute-sip #{} #{:mary} tr-2) 275.52 - (<- (:fred) (not! {:pred :mary :bound #{:x}} :x 3)))) 275.53 - 275.54 - (is (= (compute-sip #{} #{} tr-2) 275.55 - tr-2)) 275.56 - 275.57 - (is (= (display-rule (compute-sip #{:x} #{:mary :sally} tr-3)) 275.58 - (display-rule (<- ({:pred :fred :bound #{:x}} :x ?x :y ?y) 275.59 - ({:pred :mary :bound #{:x}} :x ?x) 275.60 - (:sally :y ?y) 275.61 - (if > ?x ?y)))))) 275.62 - ; Display rule is used because = does not work on 275.63 - ; (if > ?x ?y) because it contains a closure 275.64 - 275.65 - 275.66 -(def rs 275.67 - (rules-set 275.68 - (<- (:path :a ?x :b ?y) (:edge :a ?x :b ?y)) 275.69 - (<- (:path :a ?x :b ?y) (:edge :a ?x :b ?z) (:path :a ?z :b ?y)) 275.70 - (<- (:edge :a ?x :b ?y) (:route :a ?x :b ?y) (if not= ?x ?y)))) 275.71 - 275.72 -(deftest test-rules-set 275.73 - (is (= (count rs) 3)) 275.74 - (is (contains? rs (<- (:path :a ?x :b ?y) (:edge :a ?x :b ?z) (:path :a ?z :b ?y))))) 275.75 - 275.76 -(deftest test-predicate-map 275.77 - (let [pm (predicate-map rs)] 275.78 - (is (= (pm :path) 275.79 - #{(<- (:path :a ?x :b ?y) (:edge :a ?x :b ?y)) 275.80 - (<- (:path :a ?x :b ?y) (:edge :a ?x :b ?z) (:path :a ?z :b ?y))})) 275.81 - (is (= (-> :edge pm count) 1)))) 275.82 - 275.83 - 275.84 -(def db1 (make-database 275.85 - (relation :fred [:x :y]) 275.86 - (index :fred :x) 275.87 - (relation :sally [:x]) 275.88 - (relation :ben [:y]))) 275.89 - 275.90 -(def db2 (add-tuples db1 275.91 - [:fred :x 1 :y :mary] 275.92 - [:fred :x 1 :y :becky] 275.93 - [:fred :x 3 :y :sally] 275.94 - [:fred :x 4 :y :joe] 275.95 - [:fred :x 4 :y :bob] 275.96 - [:sally :x 1] 275.97 - [:sally :x 2] 275.98 - [:sally :x 3] 275.99 - [:sally :x 4] 275.100 - [:ben :y :bob])) 275.101 - 275.102 - 275.103 -(deftest test-apply-rule 275.104 - (is (= (apply-rule db2 empty-database (<- (:becky :y ?y) (:sally :x ?x) 275.105 - (:fred :x ?x :y ?y) 275.106 - (not! :ben :y ?y) 275.107 - (if not= ?x 3))) 275.108 - (datalog-database 275.109 - { 275.110 - :becky 275.111 - (datalog-relation 275.112 - ;; Schema 275.113 - #{:y} 275.114 - ;; Data 275.115 - #{ 275.116 - {:y :joe} 275.117 - {:y :mary} 275.118 - {:y :becky} 275.119 - } 275.120 - ;; Indexes 275.121 - { 275.122 - }) 275.123 - })))) 275.124 - 275.125 - 275.126 - 275.127 - 275.128 -(comment 275.129 - (run-tests) 275.130 -) 275.131 - 275.132 -;; End of file 275.133 -
276.1 --- a/src/clojure/contrib/test_contrib/datalog/tests/test_softstrat.clj Sat Aug 21 06:25:44 2010 -0400 276.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 276.3 @@ -1,233 +0,0 @@ 276.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 276.5 -;; distribution terms for this software are covered by the Eclipse Public 276.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 276.7 -;; be found in the file epl-v10.html at the root of this distribution. By 276.8 -;; using this software in any fashion, you are agreeing to be bound by the 276.9 -;; terms of this license. You must not remove this notice, or any other, 276.10 -;; from this software. 276.11 -;; 276.12 -;; test-softstrat.clj 276.13 -;; 276.14 -;; A Clojure implementation of Datalog -- Soft Stratification Tests 276.15 -;; 276.16 -;; straszheimjeffrey (gmail) 276.17 -;; Created 28 Feburary 2009 276.18 - 276.19 -(ns clojure.contrib.datalog.tests.test-softstrat 276.20 - (:use clojure.test) 276.21 - (:use clojure.contrib.datalog.softstrat 276.22 - clojure.contrib.datalog.magic 276.23 - clojure.contrib.datalog.rules 276.24 - clojure.contrib.datalog.database) 276.25 - (:use [clojure.contrib.set :only (subset?)])) 276.26 - 276.27 - 276.28 - 276.29 -(def rs1 (rules-set 276.30 - (<- (:p :x ?x) (:b :x ?x :y ?y :z ?z) (not! :q :x ?x) (not! :q :x ?y) (not! :q :x ?z)) 276.31 - (<- (:q :x ?x) (:d :x ?x)))) 276.32 - 276.33 -(def q1 (?- :p :x 1)) 276.34 - 276.35 -(def ws (build-soft-strat-work-plan rs1 q1)) 276.36 - 276.37 -(deftest test-soft-stratification 276.38 - (let [soft (:stratification ws) 276.39 - q (:query ws)] 276.40 - (is (= q (?- {:pred :p :bound #{:x}} :x 1))) 276.41 - (is (= (count soft) 4)) 276.42 - (is (subset? (rules-set 276.43 - (<- ({:pred :q :bound #{:x}} :x ?x) ({:pred :q :magic true :bound #{:x}} :x ?x) 276.44 - (:d :x ?x)) 276.45 - 276.46 - (<- ({:pred :q :magic true :bound #{:x}} :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x) 276.47 - (:b :z ?z :y ?y :x ?x))) 276.48 - (nth soft 0))) 276.49 - (is (= (nth soft 1) 276.50 - (rules-set 276.51 - (<- ({:pred :q :magic true :bound #{:x}} :x ?y) ({:pred :p :magic true :bound #{:x}} :x ?x) 276.52 - (:b :z ?z :y ?y :x ?x) 276.53 - (not! {:pred :q :bound #{:x}} :x ?x))))) 276.54 - (is (= (nth soft 2) 276.55 - (rules-set 276.56 - (<- ({:pred :q :magic true :bound #{:x}} :x ?z) ({:pred :p :magic true :bound #{:x}} :x ?x) 276.57 - (:b :z ?z :y ?y :x ?x) 276.58 - (not! {:pred :q :bound #{:x}} :x ?x) 276.59 - (not! {:pred :q :bound #{:x}} :x ?y))))) 276.60 - (is (= (nth soft 3) 276.61 - (rules-set 276.62 - (<- ({:pred :p :bound #{:x}} :x ?x) ({:pred :p :magic true :bound #{:x}} :x ?x) 276.63 - (:b :z ?z :y ?y :x ?x) 276.64 - (not! {:pred :q :bound #{:x}} :x ?x) 276.65 - (not! {:pred :q :bound #{:x}} :x ?y) 276.66 - (not! {:pred :q :bound #{:x}} :x ?z))))))) 276.67 - 276.68 - 276.69 -(def tdb-1 276.70 - (make-database 276.71 - (relation :b [:x :y :z]) 276.72 - (relation :d [:x]))) 276.73 - 276.74 -(def tdb-2 276.75 - (add-tuples tdb-1 276.76 - [:b :x 1 :y 2 :z 3])) 276.77 - 276.78 -(deftest test-tdb-2 276.79 - (is (= (evaluate-soft-work-set ws tdb-2 {}) 276.80 - [{:x 1}]))) 276.81 - 276.82 - 276.83 - 276.84 -(def tdb-3 276.85 - (add-tuples tdb-2 276.86 - [:d :x 2] 276.87 - [:d :x 3])) 276.88 - 276.89 -(deftest test-tdb-3 276.90 - (is (empty? (evaluate-soft-work-set ws tdb-3 {})))) 276.91 - 276.92 - 276.93 - 276.94 -;;;;;;;;;;; 276.95 - 276.96 - 276.97 - 276.98 -(def db-base 276.99 - (make-database 276.100 - (relation :employee [:id :name :position]) 276.101 - (index :employee :name) 276.102 - 276.103 - (relation :boss [:employee-id :boss-id]) 276.104 - (index :boss :employee-id) 276.105 - 276.106 - (relation :can-do-job [:position :job]) 276.107 - (index :can-do-job :position) 276.108 - 276.109 - (relation :job-replacement [:job :can-be-done-by]) 276.110 - 276.111 - (relation :job-exceptions [:id :job]))) 276.112 - 276.113 -(def db 276.114 - (add-tuples db-base 276.115 - [:employee :id 1 :name "Bob" :position :boss] 276.116 - [:employee :id 2 :name "Mary" :position :chief-accountant] 276.117 - [:employee :id 3 :name "John" :position :accountant] 276.118 - [:employee :id 4 :name "Sameer" :position :chief-programmer] 276.119 - [:employee :id 5 :name "Lilian" :position :programmer] 276.120 - [:employee :id 6 :name "Li" :position :technician] 276.121 - [:employee :id 7 :name "Fred" :position :sales] 276.122 - [:employee :id 8 :name "Brenda" :position :sales] 276.123 - [:employee :id 9 :name "Miki" :position :project-management] 276.124 - [:employee :id 10 :name "Albert" :position :technician] 276.125 - 276.126 - [:boss :employee-id 2 :boss-id 1] 276.127 - [:boss :employee-id 3 :boss-id 2] 276.128 - [:boss :employee-id 4 :boss-id 1] 276.129 - [:boss :employee-id 5 :boss-id 4] 276.130 - [:boss :employee-id 6 :boss-id 4] 276.131 - [:boss :employee-id 7 :boss-id 1] 276.132 - [:boss :employee-id 8 :boss-id 7] 276.133 - [:boss :employee-id 9 :boss-id 1] 276.134 - [:boss :employee-id 10 :boss-id 6] 276.135 - 276.136 - [:can-do-job :position :boss :job :management] 276.137 - [:can-do-job :position :accountant :job :accounting] 276.138 - [:can-do-job :position :chief-accountant :job :accounting] 276.139 - [:can-do-job :position :programmer :job :programming] 276.140 - [:can-do-job :position :chief-programmer :job :programming] 276.141 - [:can-do-job :position :technician :job :server-support] 276.142 - [:can-do-job :position :sales :job :sales] 276.143 - [:can-do-job :position :project-management :job :project-management] 276.144 - 276.145 - [:job-replacement :job :pc-support :can-be-done-by :server-support] 276.146 - [:job-replacement :job :pc-support :can-be-done-by :programming] 276.147 - [:job-replacement :job :payroll :can-be-done-by :accounting] 276.148 - 276.149 - [:job-exceptions :id 4 :job :pc-support])) 276.150 - 276.151 -(def rules 276.152 - (rules-set 276.153 - (<- (:works-for :employee ?x :boss ?y) (:boss :employee-id ?e-id :boss-id ?b-id) 276.154 - (:employee :id ?e-id :name ?x) 276.155 - (:employee :id ?b-id :name ?y)) 276.156 - (<- (:works-for :employee ?x :boss ?y) (:works-for :employee ?x :boss ?z) 276.157 - (:works-for :employee ?z :boss ?y)) 276.158 - (<- (:employee-job* :employee ?x :job ?y) (:employee :name ?x :position ?pos) 276.159 - (:can-do-job :position ?pos :job ?y)) 276.160 - (<- (:employee-job* :employee ?x :job ?y) (:job-replacement :job ?y :can-be-done-by ?z) 276.161 - (:employee-job* :employee ?x :job ?z)) 276.162 - (<- (:employee-job* :employee ?x :job ?y) (:can-do-job :job ?y) 276.163 - (:employee :name ?x :position ?z) 276.164 - (if = ?z :boss)) 276.165 - (<- (:employee-job :employee ?x :job ?y) (:employee-job* :employee ?x :job ?y) 276.166 - (:employee :id ?id :name ?x) 276.167 - (not! :job-exceptions :id ?id :job ?y)) 276.168 - (<- (:bj :name ?x :boss ?y) (:works-for :employee ?x :boss ?y) 276.169 - (not! :employee-job :employee ?y :job :pc-support)))) 276.170 - 276.171 - 276.172 -(def ws-1 (build-soft-strat-work-plan rules (?- :works-for :employee '??name :boss ?x))) 276.173 -(defn evaluate-1 [name] (set (evaluate-soft-work-set ws-1 db {'??name name}))) 276.174 - 276.175 -(deftest test-ws-1 276.176 - (is (= (evaluate-1 "Albert") 276.177 - #{{:employee "Albert", :boss "Li"} 276.178 - {:employee "Albert", :boss "Sameer"} 276.179 - {:employee "Albert", :boss "Bob"}})) 276.180 - (is (empty? (evaluate-1 "Bob"))) 276.181 - (is (= (evaluate-1 "John") 276.182 - #{{:employee "John", :boss "Bob"} 276.183 - {:employee "John", :boss "Mary"}}))) 276.184 - 276.185 - 276.186 -(def ws-2 (build-soft-strat-work-plan rules (?- :employee-job :employee '??name :job ?x))) 276.187 -(defn evaluate-2 [name] (set (evaluate-soft-work-set ws-2 db {'??name name}))) 276.188 - 276.189 -(deftest test-ws-2 276.190 - (is (= (evaluate-2 "Albert") 276.191 - #{{:employee "Albert", :job :pc-support} 276.192 - {:employee "Albert", :job :server-support}})) 276.193 - (is (= (evaluate-2 "Sameer") 276.194 - #{{:employee "Sameer", :job :programming}})) 276.195 - (is (= (evaluate-2 "Bob") 276.196 - #{{:employee "Bob", :job :accounting} 276.197 - {:employee "Bob", :job :management} 276.198 - {:employee "Bob", :job :payroll} 276.199 - {:employee "Bob", :job :pc-support} 276.200 - {:employee "Bob", :job :project-management} 276.201 - {:employee "Bob", :job :programming} 276.202 - {:employee "Bob", :job :server-support} 276.203 - {:employee "Bob", :job :sales}}))) 276.204 - 276.205 -(def ws-3 (build-soft-strat-work-plan rules (?- :bj :name '??name :boss ?x))) 276.206 -(defn evaluate-3 [name] (set (evaluate-soft-work-set ws-3 db {'??name name}))) 276.207 - 276.208 -(deftest test-ws-3 276.209 - (is (= (evaluate-3 "Albert") 276.210 - #{{:name "Albert", :boss "Sameer"}}))) 276.211 - 276.212 -(def ws-4 (build-soft-strat-work-plan rules (?- :works-for :name ?x :boss ?x))) 276.213 - 276.214 -(deftest test-ws-4 276.215 - (is (= (set (evaluate-soft-work-set ws-4 db {})) 276.216 - #{{:employee "Miki", :boss "Bob"} 276.217 - {:employee "Albert", :boss "Li"} 276.218 - {:employee "Lilian", :boss "Sameer"} 276.219 - {:employee "Li", :boss "Bob"} 276.220 - {:employee "Lilian", :boss "Bob"} 276.221 - {:employee "Brenda", :boss "Fred"} 276.222 - {:employee "Fred", :boss "Bob"} 276.223 - {:employee "John", :boss "Bob"} 276.224 - {:employee "John", :boss "Mary"} 276.225 - {:employee "Albert", :boss "Sameer"} 276.226 - {:employee "Sameer", :boss "Bob"} 276.227 - {:employee "Albert", :boss "Bob"} 276.228 - {:employee "Brenda", :boss "Bob"} 276.229 - {:employee "Mary", :boss "Bob"} 276.230 - {:employee "Li", :boss "Sameer"}}))) 276.231 - 276.232 -(comment 276.233 - (run-tests) 276.234 -) 276.235 - 276.236 -;; End of file
277.1 --- a/src/clojure/contrib/test_contrib/datalog/tests/test_util.clj Sat Aug 21 06:25:44 2010 -0400 277.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 277.3 @@ -1,69 +0,0 @@ 277.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 277.5 -;; distribution terms for this software are covered by the Eclipse Public 277.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 277.7 -;; be found in the file epl-v10.html at the root of this distribution. By 277.8 -;; using this software in any fashion, you are agreeing to be bound by the 277.9 -;; terms of this license. You must not remove this notice, or any other, 277.10 -;; from this software. 277.11 -;; 277.12 -;; test-util.clj 277.13 -;; 277.14 -;; A Clojure implementation of Datalog -- Utilities Tests 277.15 -;; 277.16 -;; straszheimjeffrey (gmail) 277.17 -;; Created 11 Feburary 2009 277.18 - 277.19 -(ns clojure.contrib.datalog.tests.test-util 277.20 - (:use clojure.test 277.21 - clojure.contrib.datalog.util) 277.22 - (:use [clojure.contrib.except :only (throwf)])) 277.23 - 277.24 -(deftest test-is-var? 277.25 - (is (is-var? '?x)) 277.26 - (is (is-var? '?)) 277.27 - (is (not (is-var? '??x))) 277.28 - (is (not (is-var? '??))) 277.29 - (is (not (is-var? 'x))) 277.30 - (is (not (is-var? "fred"))) 277.31 - (is (not (is-var? :q)))) 277.32 - 277.33 -(deftest test-map-values 277.34 - (let [map {:fred 1 :sally 2}] 277.35 - (is (= (map-values #(* 2 %) map) {:fred 2 :sally 4})) 277.36 - (is (= (map-values identity {}) {})))) 277.37 - 277.38 -(deftest test-keys-to-vals 277.39 - (let [map {:fred 1 :sally 2 :joey 3}] 277.40 - (is (= (set (keys-to-vals map [:fred :sally])) #{1 2})) 277.41 - (is (= (set (keys-to-vals map [:fred :sally :becky])) #{1 2})) 277.42 - (is (empty? (keys-to-vals map []))) 277.43 - (is (empty? (keys-to-vals {} [:fred]))))) 277.44 - 277.45 -(deftest test-reverse-map 277.46 - (let [map {:fred 1 :sally 2 :joey 3} 277.47 - map-1 (assoc map :mary 3)] 277.48 - (is (= (reverse-map map) {1 :fred 2 :sally 3 :joey})) 277.49 - (is (or (= (reverse-map map-1) {1 :fred 2 :sally 3 :joey}) 277.50 - (= (reverse-map map-1) {1 :fred 2 :sally 3 :mary}))))) 277.51 - 277.52 -(def some-maps 277.53 - [ 277.54 - { :a 1 :b 2 } 277.55 - { :c 3 :b 3 } 277.56 - { :d 4 :a 1 } 277.57 - { :g 4 :b 4 } 277.58 - { :a 2 :b 1 } 277.59 - { :e 1 :f 1 } 277.60 - ]) 277.61 - 277.62 -(def reduced (preduce + some-maps)) 277.63 -(def merged (apply merge-with + some-maps)) 277.64 - 277.65 -(deftest test-preduce 277.66 - (is (= reduced merged))) 277.67 - 277.68 -(comment 277.69 - (run-tests) 277.70 -) 277.71 - 277.72 -; End of file
278.1 --- a/src/clojure/contrib/test_contrib/miglayout/example.clj Sat Aug 21 06:25:44 2010 -0400 278.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 278.3 @@ -1,60 +0,0 @@ 278.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 278.5 -;; distribution terms for this software are covered by the Eclipse Public 278.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 278.7 -;; be found in the file epl-v10.html at the root of this distribution. By 278.8 -;; using this software in any fashion, you are agreeing to be bound by the 278.9 -;; terms of this license. You must not remove this notice, or any other, 278.10 -;; from this software. 278.11 -;; 278.12 -;; clojure.contrib.miglayout.example 278.13 -;; 278.14 -;; A temperature converter using miglayout. Demonstrates accessing 278.15 -;; components by their id constraint. 278.16 -;; 278.17 -;; scgilardi (gmail) 278.18 -;; Created 31 May 2009 278.19 - 278.20 -(ns clojure.contrib.miglayout.example 278.21 - (:import (javax.swing JButton JFrame JLabel JPanel JTextField 278.22 - SwingUtilities)) 278.23 - (:use (clojure.contrib 278.24 - [miglayout :only (miglayout components)] 278.25 - [swing-utils :only (add-key-typed-listener)]))) 278.26 - 278.27 -(defn fahrenheit 278.28 - "Converts a Celsius temperature to Fahrenheit. Input and output are 278.29 - strings. Returns \"input?\" if the input can't be parsed as a Double." 278.30 - [celsius] 278.31 - (try 278.32 - (format "%.2f" (+ 32 (* 1.8 (Double/parseDouble celsius)))) 278.33 - (catch NumberFormatException _ "input?"))) 278.34 - 278.35 -(defn- handle-key 278.36 - "Clears output on most keys, shows conversion on \"Enter\"" 278.37 - [event out] 278.38 - (.setText out 278.39 - (if (= (.getKeyChar event) \newline) 278.40 - (fahrenheit (-> event .getComponent .getText)) 278.41 - ""))) 278.42 - 278.43 -(defn converter-ui 278.44 - "Lays out and shows a Temperature Converter UI" 278.45 - [] 278.46 - (let [panel 278.47 - (miglayout (JPanel.) 278.48 - (JTextField. 6) {:id :input} 278.49 - (JLabel. "\u00b0Celsius") :wrap 278.50 - (JLabel.) {:id :output} 278.51 - (JLabel. "\u00b0Fahrenheit")) 278.52 - {:keys [input output]} (components panel)] 278.53 - (add-key-typed-listener input handle-key output) 278.54 - (doto (JFrame. "Temperature Converter") 278.55 - (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE) 278.56 - (.add panel) 278.57 - (.pack) 278.58 - (.setVisible true)))) 278.59 - 278.60 -(defn main 278.61 - "Invokes converter-ui in the AWT Event thread" 278.62 - [] 278.63 - (SwingUtilities/invokeLater converter-ui))
279.1 --- a/src/clojure/contrib/test_contrib/mock/test_adapter.clj Sat Aug 21 06:25:44 2010 -0400 279.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 279.3 @@ -1,18 +0,0 @@ 279.4 -(ns clojure.contrib.test-contrib.mock-test.test-adapter-test 279.5 - (:use clojure.contrib.mock.test-adapter 279.6 - [clojure.contrib.test-contrib.mock-test :only (assert-called)] 279.7 - clojure.test)) 279.8 - 279.9 -(deftest test-report-problem-called 279.10 - (def #^{:private true :dynamic true} fn1 (fn [x] "dummy code")) 279.11 - (def #^{:private true :dynamic true} fn2 (fn [x y] "dummy code2")) 279.12 - (let [under-test (fn [x] (fn1 x))] 279.13 - (assert-called clojure.contrib.mock.test-adapter/report-problem 279.14 - true (expect [fn1 (times 5)] (under-test "hi"))))) 279.15 - 279.16 -(deftest test-is-report-called 279.17 - (assert-called clojure.test/report true 279.18 - (clojure.contrib.mock.test-adapter/report-problem 279.19 - 'fn-name 5 6 "fake problem"))) 279.20 - 279.21 -
280.1 --- a/src/clojure/contrib/test_contrib/monads/examples.clj Sat Aug 21 06:25:44 2010 -0400 280.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 280.3 @@ -1,425 +0,0 @@ 280.4 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.5 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.6 -;; 280.7 -;; Monad application examples 280.8 -;; 280.9 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.10 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.11 - 280.12 -(ns 280.13 - #^{:author "Konrad Hinsen" 280.14 - :skip-wiki true 280.15 - :doc "Examples for using monads"} 280.16 - clojure.contrib.monads.examples 280.17 - (:use [clojure.contrib.monads 280.18 - :only (domonad with-monad m-lift m-seq m-reduce m-when 280.19 - sequence-m 280.20 - maybe-m 280.21 - state-m fetch-state set-state 280.22 - writer-m write 280.23 - cont-m run-cont call-cc 280.24 - maybe-t)]) 280.25 - (:require (clojure.contrib [accumulators :as accu]))) 280.26 - 280.27 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.28 -;; 280.29 -;; Sequence manipulations with the sequence monad 280.30 -;; 280.31 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.32 - 280.33 -; Note: in the Haskell world, this monad is called the list monad. 280.34 -; The Clojure equivalent to Haskell's lists are (possibly lazy) 280.35 -; sequences. This is why I call this monad "sequence". All sequences 280.36 -; created by sequence monad operations are lazy. 280.37 - 280.38 -; Monad comprehensions in the sequence monad work exactly the same 280.39 -; as Clojure's 'for' construct, except that :while clauses are not 280.40 -; available. 280.41 -(domonad sequence-m 280.42 - [x (range 5) 280.43 - y (range 3)] 280.44 - (+ x y)) 280.45 - 280.46 -; Inside a with-monad block, domonad is used without the monad name. 280.47 -(with-monad sequence-m 280.48 - (domonad 280.49 - [x (range 5) 280.50 - y (range 3)] 280.51 - (+ x y))) 280.52 - 280.53 -; Conditions are written with :when, as in Clojure's for form: 280.54 -(domonad sequence-m 280.55 - [x (range 5) 280.56 - y (range (+ 1 x)) 280.57 - :when (= (+ x y) 2)] 280.58 - (list x y)) 280.59 - 280.60 -; :let is also supported like in for: 280.61 -(domonad sequence-m 280.62 - [x (range 5) 280.63 - y (range (+ 1 x)) 280.64 - :let [sum (+ x y) 280.65 - diff (- x y)] 280.66 - :when (= sum 2)] 280.67 - (list diff)) 280.68 - 280.69 -; An example of a sequence function defined in terms of a lift operation. 280.70 -(with-monad sequence-m 280.71 - (defn pairs [xs] 280.72 - ((m-lift 2 #(list %1 %2)) xs xs))) 280.73 - 280.74 -(pairs (range 5)) 280.75 - 280.76 -; Another way to define pairs is through the m-seq operation. It takes 280.77 -; a sequence of monadic values and returns a monadic value containing 280.78 -; the sequence of the underlying values, obtained from chaining together 280.79 -; from left to right the monadic values in the sequence. 280.80 -(with-monad sequence-m 280.81 - (defn pairs [xs] 280.82 - (m-seq (list xs xs)))) 280.83 - 280.84 -(pairs (range 5)) 280.85 - 280.86 -; This definition suggests a generalization: 280.87 -(with-monad sequence-m 280.88 - (defn ntuples [n xs] 280.89 - (m-seq (replicate n xs)))) 280.90 - 280.91 -(ntuples 2 (range 5)) 280.92 -(ntuples 3 (range 5)) 280.93 - 280.94 -; Lift operations can also be used inside a monad comprehension: 280.95 -(domonad sequence-m 280.96 - [x ((m-lift 1 (partial * 2)) (range 5)) 280.97 - y (range 2)] 280.98 - [x y]) 280.99 - 280.100 -; The m-plus operation does concatenation in the sequence monad. 280.101 -(domonad sequence-m 280.102 - [x ((m-lift 2 +) (range 5) (range 3)) 280.103 - y (m-plus (range 2) '(10 11))] 280.104 - [x y]) 280.105 - 280.106 - 280.107 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.108 -;; 280.109 -;; Handling failures with the maybe monad 280.110 -;; 280.111 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.112 - 280.113 -; Maybe monad versions of basic arithmetic 280.114 -(with-monad maybe-m 280.115 - (def m+ (m-lift 2 +)) 280.116 - (def m- (m-lift 2 -)) 280.117 - (def m* (m-lift 2 *))) 280.118 - 280.119 -; Division is special for two reasons: we can't call it m/ because that's 280.120 -; not a legal Clojure symbol, and we want it to fail if a division by zero 280.121 -; is attempted. It is best defined by a monad comprehension with a 280.122 -; :when clause: 280.123 -(defn safe-div [x y] 280.124 - (domonad maybe-m 280.125 - [a x 280.126 - b y 280.127 - :when (not (zero? b))] 280.128 - (/ a b))) 280.129 - 280.130 -; Now do some non-trivial computation with division 280.131 -; It fails for (1) x = 0, (2) y = 0 or (3) y = -x. 280.132 -(with-monad maybe-m 280.133 - (defn some-function [x y] 280.134 - (let [one (m-result 1)] 280.135 - (safe-div one (m+ (safe-div one (m-result x)) 280.136 - (safe-div one (m-result y))))))) 280.137 - 280.138 -; An example that doesn't fail: 280.139 -(some-function 2 3) 280.140 -; And two that do fail, at different places: 280.141 -(some-function 2 0) 280.142 -(some-function 2 -2) 280.143 - 280.144 -; In the maybe monad, m-plus selects the first monadic value that 280.145 -; holds a valid value. 280.146 -(with-monad maybe-m 280.147 - (m-plus (some-function 2 0) (some-function 2 -2) (some-function 2 3))) 280.148 - 280.149 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.150 -;; 280.151 -;; Random numbers with the state monad 280.152 -;; 280.153 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.154 - 280.155 -; A state monad item represents a computation that changes a state and 280.156 -; returns a value. Its structure is a function that takes a state argument 280.157 -; and returns a two-item list containing the value and the updated state. 280.158 -; It is important to realize that everything you put into a state monad 280.159 -; expression is a state monad item (thus a function), and everything you 280.160 -; get out as well. A state monad does not perform a calculation, it 280.161 -; constructs a function that does the computation when called. 280.162 - 280.163 -; First, we define a simple random number generator with explicit state. 280.164 -; rng is a function of its state (an integer) that returns the 280.165 -; pseudo-random value derived from this state and the updated state 280.166 -; for the next iteration. This is exactly the structure of a state 280.167 -; monad item. 280.168 -(defn rng [seed] 280.169 - (let [m 259200 280.170 - value (/ (float seed) (float m)) 280.171 - next (rem (+ 54773 (* 7141 seed)) m)] 280.172 - [value next])) 280.173 - 280.174 -; We define a convenience function that creates an infinite lazy seq 280.175 -; of values obtained from iteratively applying a state monad value. 280.176 -(defn value-seq [f seed] 280.177 - (lazy-seq 280.178 - (let [[value next] (f seed)] 280.179 - (cons value (value-seq f next))))) 280.180 - 280.181 -; Next, we define basic statistics functions to check our random numbers 280.182 -(defn sum [xs] (apply + xs)) 280.183 -(defn mean [xs] (/ (sum xs) (count xs))) 280.184 -(defn variance [xs] 280.185 - (let [m (mean xs) 280.186 - sq #(* % %)] 280.187 - (mean (for [x xs] (sq (- x m)))))) 280.188 - 280.189 -; rng implements a uniform distribution in the interval [0., 1.), so 280.190 -; ideally, the mean would be 1/2 (0.5) and the variance 1/12 (0.8333). 280.191 -(mean (take 1000 (value-seq rng 1))) 280.192 -(variance (take 1000 (value-seq rng 1))) 280.193 - 280.194 -; We make use of the state monad to implement a simple (but often sufficient) 280.195 -; approximation to a Gaussian distribution: the sum of 12 random numbers 280.196 -; from rng's distribution, shifted by -6, has a distribution that is 280.197 -; approximately Gaussian with 0 mean and variance 1, by virtue of the central 280.198 -; limit theorem. 280.199 -; In the first version, we call rng 12 times explicitly and calculate the 280.200 -; shifted sum in a monad comprehension: 280.201 -(def gaussian1 280.202 - (domonad state-m 280.203 - [x1 rng 280.204 - x2 rng 280.205 - x3 rng 280.206 - x4 rng 280.207 - x5 rng 280.208 - x6 rng 280.209 - x7 rng 280.210 - x8 rng 280.211 - x9 rng 280.212 - x10 rng 280.213 - x11 rng 280.214 - x12 rng] 280.215 - (- (+ x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12) 6.))) 280.216 - 280.217 -; Let's test it: 280.218 -(mean (take 1000 (value-seq gaussian1 1))) 280.219 -(variance (take 1000 (value-seq gaussian1 1))) 280.220 - 280.221 -; Of course, we'd rather have a loop construct for creating the 12 280.222 -; random numbers. This would be easy if we could define a summation 280.223 -; operation on random-number generators, which would then be used in 280.224 -; combination with reduce. The lift operation gives us exactly that. 280.225 -; More precisely, we need (m-lift 2 +), because we want both arguments 280.226 -; of + to be lifted to the state monad: 280.227 -(def gaussian2 280.228 - (domonad state-m 280.229 - [sum12 (reduce (m-lift 2 +) (replicate 12 rng))] 280.230 - (- sum12 6.))) 280.231 - 280.232 -; Such a reduction is often quite useful, so there's m-reduce predefined 280.233 -; to simplify it: 280.234 -(def gaussian2 280.235 - (domonad state-m 280.236 - [sum12 (m-reduce + (replicate 12 rng))] 280.237 - (- sum12 6.))) 280.238 - 280.239 -; The statistics should be strictly the same as above, as long as 280.240 -; we use the same seed: 280.241 -(mean (take 1000 (value-seq gaussian2 1))) 280.242 -(variance (take 1000 (value-seq gaussian2 1))) 280.243 - 280.244 -; We can also do the subtraction of 6 in a lifted function, and get rid 280.245 -; of the monad comprehension altogether: 280.246 -(with-monad state-m 280.247 - (def gaussian3 280.248 - ((m-lift 1 #(- % 6.)) 280.249 - (m-reduce + (replicate 12 rng))))) 280.250 - 280.251 -; Again, the statistics are the same: 280.252 -(mean (take 1000 (value-seq gaussian3 1))) 280.253 -(variance (take 1000 (value-seq gaussian3 1))) 280.254 - 280.255 -; For a random point in two dimensions, we'd like a random number generator 280.256 -; that yields a list of two random numbers. The m-seq operation can easily 280.257 -; provide it: 280.258 -(with-monad state-m 280.259 - (def rng2 (m-seq (list rng rng)))) 280.260 - 280.261 -; Let's test it: 280.262 -(rng2 1) 280.263 - 280.264 -; fetch-state and get-state can be used to save the seed of the random 280.265 -; number generator and go back to that saved seed later on: 280.266 -(def identical-random-seqs 280.267 - (domonad state-m 280.268 - [seed (fetch-state) 280.269 - x1 rng 280.270 - x2 rng 280.271 - _ (set-state seed) 280.272 - y1 rng 280.273 - y2 rng] 280.274 - (list [x1 x2] [y1 y2]))) 280.275 - 280.276 -(identical-random-seqs 1) 280.277 - 280.278 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.279 -;; 280.280 -;; Logging with the writer monad 280.281 -;; 280.282 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.283 - 280.284 -; A basic logging example 280.285 -(domonad (writer-m accu/empty-string) 280.286 - [x (m-result 1) 280.287 - _ (write "first step\n") 280.288 - y (m-result 2) 280.289 - _ (write "second step\n")] 280.290 - (+ x y)) 280.291 - 280.292 -; For a more elaborate application, let's trace the recursive calls of 280.293 -; a naive implementation of a Fibonacci function. The starting point is: 280.294 -(defn fib [n] 280.295 - (if (< n 2) 280.296 - n 280.297 - (let [n1 (dec n) 280.298 - n2 (dec n1)] 280.299 - (+ (fib n1) (fib n2))))) 280.300 - 280.301 -; First we rewrite it to make every computational step explicit 280.302 -; in a let expression: 280.303 -(defn fib [n] 280.304 - (if (< n 2) 280.305 - n 280.306 - (let [n1 (dec n) 280.307 - n2 (dec n1) 280.308 - f1 (fib n1) 280.309 - f2 (fib n2)] 280.310 - (+ f1 f2)))) 280.311 - 280.312 -; Next, we replace the let by a domonad in a writer monad that uses a 280.313 -; vector accumulator. We can then place calls to write in between the 280.314 -; steps, and obtain as a result both the return value of the function 280.315 -; and the accumulated trace values. 280.316 -(with-monad (writer-m accu/empty-vector) 280.317 - 280.318 - (defn fib-trace [n] 280.319 - (if (< n 2) 280.320 - (m-result n) 280.321 - (domonad 280.322 - [n1 (m-result (dec n)) 280.323 - n2 (m-result (dec n1)) 280.324 - f1 (fib-trace n1) 280.325 - _ (write [n1 f1]) 280.326 - f2 (fib-trace n2) 280.327 - _ (write [n2 f2]) 280.328 - ] 280.329 - (+ f1 f2)))) 280.330 - 280.331 -) 280.332 - 280.333 -(fib-trace 5) 280.334 - 280.335 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.336 -;; 280.337 -;; Sequences with undefined value: the maybe-t monad transformer 280.338 -;; 280.339 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.340 - 280.341 -; A monad transformer is a function that takes a monad argument and 280.342 -; returns a monad as its result. The resulting monad adds some 280.343 -; specific behaviour aspect to the input monad. 280.344 - 280.345 -; The simplest monad transformer is maybe-t. It adds the functionality 280.346 -; of the maybe monad (handling failures or undefined values) to any other 280.347 -; monad. We illustrate this by applying maybe-t to the sequence monad. 280.348 -; The result is an enhanced sequence monad in which undefined values 280.349 -; (represented by nil) are not subjected to any transformation, but 280.350 -; lead immediately to a nil result in the output. 280.351 - 280.352 -; First we define the combined monad: 280.353 -(def seq-maybe-m (maybe-t sequence-m)) 280.354 - 280.355 -; As a first illustration, we create a range of integers and replace 280.356 -; all even values by nil, using a simple when expression. We use this 280.357 -; sequence in a monad comprehension that yields (inc x). The result 280.358 -; is a sequence in which inc has been applied to all non-nil values, 280.359 -; whereas the nil values appear unmodified in the output: 280.360 -(domonad seq-maybe-m 280.361 - [x (for [n (range 10)] (when (odd? n) n))] 280.362 - (inc x)) 280.363 - 280.364 -; Next we repeat the definition of the function pairs (see above), but 280.365 -; using the seq-maybe monad: 280.366 -(with-monad seq-maybe-m 280.367 - (defn pairs-maybe [xs] 280.368 - (m-seq (list xs xs)))) 280.369 - 280.370 -; Applying this to a sequence containing nils yields the pairs of all 280.371 -; non-nil values interspersed with nils that result from any combination 280.372 -; in which one or both of the values is nil: 280.373 -(pairs-maybe (for [n (range 5)] (when (odd? n) n))) 280.374 - 280.375 -; It is important to realize that undefined values (nil) are not eliminated 280.376 -; from the iterations. They are simply not passed on to any operations. 280.377 -; The outcome of any function applied to arguments of which at least one 280.378 -; is nil is supposed to be nil as well, and the function is never called. 280.379 - 280.380 - 280.381 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.382 -;; 280.383 -;; Continuation-passing style in the cont monad 280.384 -;; 280.385 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 280.386 - 280.387 -; A simple computation performed in continuation-passing style. 280.388 -; (m-result 1) returns a function that, when called with a single 280.389 -; argument f, calls (f 1). The result of the domonad-computation is 280.390 -; a function that behaves in the same way, passing 3 to its function 280.391 -; argument. run-cont executes a continuation by calling it on identity. 280.392 -(run-cont 280.393 - (domonad cont-m 280.394 - [x (m-result 1) 280.395 - y (m-result 2)] 280.396 - (+ x y))) 280.397 - 280.398 -; Let's capture a continuation using call-cc. We store it in a global 280.399 -; variable so that we can do with it whatever we want. The computation 280.400 -; is the same one as in the first example, but it has the side effect 280.401 -; of storing the continuation at (m-result 2). 280.402 -(def continuation nil) 280.403 - 280.404 -(run-cont 280.405 - (domonad cont-m 280.406 - [x (m-result 1) 280.407 - y (call-cc (fn [c] (def continuation c) (c 2)))] 280.408 - (+ x y))) 280.409 - 280.410 -; Now we can call the continuation with whatever argument we want. The 280.411 -; supplied argument takes the place of 2 in the above computation: 280.412 -(run-cont (continuation 5)) 280.413 -(run-cont (continuation 42)) 280.414 -(run-cont (continuation -1)) 280.415 - 280.416 -; Next, a function that illustrates how a captured continuation can be 280.417 -; used as an "emergency exit" out of a computation: 280.418 -(defn sqrt-as-str [x] 280.419 - (call-cc 280.420 - (fn [k] 280.421 - (domonad cont-m 280.422 - [_ (m-when (< x 0) (k (str "negative argument " x)))] 280.423 - (str (. Math sqrt x)))))) 280.424 - 280.425 -(run-cont (sqrt-as-str 2)) 280.426 -(run-cont (sqrt-as-str -2)) 280.427 - 280.428 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
281.1 --- a/src/clojure/contrib/test_contrib/pprint/examples/hexdump.clj Sat Aug 21 06:25:44 2010 -0400 281.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 281.3 @@ -1,63 +0,0 @@ 281.4 -;;; hexdump.clj -- part of the pretty printer for Clojure 281.5 - 281.6 -;; by Tom Faulhaber 281.7 -;; April 3, 2009 281.8 - 281.9 -; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. 281.10 -; The use and distribution terms for this software are covered by the 281.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 281.12 -; which can be found in the file epl-v10.html at the root of this distribution. 281.13 -; By using this software in any fashion, you are agreeing to be bound by 281.14 -; the terms of this license. 281.15 -; You must not remove this notice, or any other, from this software. 281.16 - 281.17 -;; This example is a classic hexdump program written using cl-format. 281.18 - 281.19 -;; For some local color, it was written in Dulles Airport while waiting for a flight 281.20 -;; home to San Francisco. 281.21 - 281.22 -(ns clojure.contrib.pprint.examples.hexdump 281.23 - (:use clojure.contrib.pprint 281.24 - clojure.contrib.pprint.utilities) 281.25 - (:gen-class (:main true))) 281.26 - 281.27 -(def *buffer-length* 1024) 281.28 - 281.29 -(defn zip-array [base-offset arr] 281.30 - (let [grouped (partition 16 arr)] 281.31 - (first (map-passing-context 281.32 - (fn [line offset] 281.33 - [[offset 281.34 - (map #(if (neg? %) (+ % 256) %) line) 281.35 - (- 16 (count line)) 281.36 - (map #(if (<= 32 % 126) (char %) \.) line)] 281.37 - (+ 16 offset)]) 281.38 - base-offset grouped)))) 281.39 - 281.40 - 281.41 -(defn hexdump 281.42 - ([in-stream] (hexdump in-stream true 0)) 281.43 - ([in-stream out-stream] (hexdump [in-stream out-stream 0])) 281.44 - ([in-stream out-stream offset] 281.45 - (let [buf (make-array Byte/TYPE *buffer-length*)] 281.46 - (loop [offset offset 281.47 - count (.read in-stream buf)] 281.48 - (if (neg? count) 281.49 - nil 281.50 - (let [bytes (take count buf) 281.51 - zipped (zip-array offset bytes)] 281.52 - (cl-format out-stream 281.53 - "~:{~8,'0X: ~2{~8@{~#[ ~:;~2,'0X ~]~} ~}~v@{ ~}~2{~8@{~A~} ~}~%~}" 281.54 - zipped) 281.55 - (recur (+ offset *buffer-length*) (.read in-stream buf)))))))) 281.56 - 281.57 -(defn hexdump-file 281.58 - ([file-name] (hexdump-file file-name true)) 281.59 - ([file-name stream] 281.60 - (with-open [s (java.io.FileInputStream. file-name)] 281.61 - (hexdump s)))) 281.62 - 281.63 -;; I don't quite understand how to invoke main funcs w/o AOT yet 281.64 -(defn -main [& args] 281.65 - (hexdump-file (first args))) 281.66 -
282.1 --- a/src/clojure/contrib/test_contrib/pprint/examples/json.clj Sat Aug 21 06:25:44 2010 -0400 282.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 282.3 @@ -1,142 +0,0 @@ 282.4 -;;; json.clj: A pretty printing version of the JavaScript Object Notation (JSON) generator 282.5 - 282.6 -;; by Tom Faulhaber, based on the version by Stuart Sierra (clojure.contrib.json.write) 282.7 -;; May 9, 2009 282.8 - 282.9 -;; Copyright (c) Tom Faulhaber/Stuart Sierra, 2009. All rights reserved. The use 282.10 -;; and distribution terms for this software are covered by the Eclipse 282.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 282.12 -;; which can be found in the file epl-v10.html at the root of this 282.13 -;; distribution. By using this software in any fashion, you are 282.14 -;; agreeing to be bound by the terms of this license. You must not 282.15 -;; remove this notice, or any other, from this software. 282.16 - 282.17 - 282.18 -(ns 282.19 - #^{:author "Tom Faulhaber (based on the version by Stuart Sierra)", 282.20 - :doc "Pretty printing JavaScript Object Notation (JSON) generator. 282.21 - 282.22 -This is an example of using a pretty printer dispatch function to generate JSON output", 282.23 - :see-also [["http://json.org/", "JSON Home Page"]]} 282.24 - clojure.contrib.pprint.examples.json 282.25 - (:use [clojure.test :only (deftest- is)] 282.26 - [clojure.contrib.string :only (as-str)] 282.27 - [clojure.contrib.pprint :only (write formatter-out)])) 282.28 - 282.29 - 282.30 - 282.31 -(defmulti dispatch-json 282.32 - "The dispatch function for printing objects as JSON" 282.33 - {:arglists '[[x]]} 282.34 - (fn [x] (cond 282.35 - (nil? x) nil ;; prevent NullPointerException on next line 282.36 - (.isArray (class x)) ::array 282.37 - :else (type x)))) 282.38 - 282.39 -;; Primitive types can be printed with Clojure's pr function. 282.40 -(derive java.lang.Boolean ::pr) 282.41 -(derive java.lang.Byte ::pr) 282.42 -(derive java.lang.Short ::pr) 282.43 -(derive java.lang.Integer ::pr) 282.44 -(derive java.lang.Long ::pr) 282.45 -(derive java.lang.Float ::pr) 282.46 -(derive java.lang.Double ::pr) 282.47 - 282.48 -;; Collection types can be printed as JSON objects or arrays. 282.49 -(derive java.util.Map ::object) 282.50 -(derive java.util.Collection ::array) 282.51 - 282.52 -;; Symbols and keywords are converted to strings. 282.53 -(derive clojure.lang.Symbol ::symbol) 282.54 -(derive clojure.lang.Keyword ::symbol) 282.55 - 282.56 - 282.57 -(defmethod dispatch-json ::pr [x] (pr x)) 282.58 - 282.59 -(defmethod dispatch-json nil [x] (print "null")) 282.60 - 282.61 -(defmethod dispatch-json ::symbol [x] (pr (name x))) 282.62 - 282.63 -(defmethod dispatch-json ::array [s] 282.64 - ((formatter-out "~<[~;~@{~w~^, ~:_~}~;]~:>") s)) 282.65 - 282.66 -(defmethod dispatch-json ::object [m] 282.67 - ((formatter-out "~<{~;~@{~<~w:~_~w~:>~^, ~_~}~;}~:>") 282.68 - (for [[k v] m] [(as-str k) v]))) 282.69 - 282.70 -(defmethod dispatch-json java.lang.CharSequence [s] 282.71 - (print \") 282.72 - (dotimes [i (count s)] 282.73 - (let [cp (Character/codePointAt s i)] 282.74 - (cond 282.75 - ;; Handle printable JSON escapes before ASCII 282.76 - (= cp 34) (print "\\\"") 282.77 - (= cp 92) (print "\\\\") 282.78 - ;; Print simple ASCII characters 282.79 - (< 31 cp 127) (print (.charAt s i)) 282.80 - ;; Handle non-printable JSON escapes 282.81 - (= cp 8) (print "\\b") 282.82 - (= cp 12) (print "\\f") 282.83 - (= cp 10) (print "\\n") 282.84 - (= cp 13) (print "\\r") 282.85 - (= cp 9) (print "\\t") 282.86 - ;; Any other character is printed as Hexadecimal escape 282.87 - :else (printf "\\u%04x" cp)))) 282.88 - (print \")) 282.89 - 282.90 -(defn print-json 282.91 - "Prints x as JSON. Nil becomes JSON null. Keywords become 282.92 - strings, without the leading colon. Maps become JSON objects, all 282.93 - other collection types become JSON arrays. Java arrays become JSON 282.94 - arrays. Unicode characters in strings are escaped as \\uXXXX. 282.95 - Numbers print as with pr." 282.96 - [x] 282.97 - (write x :dispatch dispatch-json)) 282.98 - 282.99 -(defn json-str 282.100 - "Converts x to a JSON-formatted string." 282.101 - [x] 282.102 - (with-out-str (print-json x))) 282.103 - 282.104 - 282.105 - 282.106 -;;; TESTS 282.107 - 282.108 -;; Run these tests with 282.109 -;; (clojure.test/run-tests 'clojure.contrib.print-json) 282.110 - 282.111 -;; Bind clojure.test/*load-tests* to false to omit these 282.112 -;; tests from production code. 282.113 - 282.114 -(deftest- can-print-json-strings 282.115 - (is (= "\"Hello, World!\"" (json-str "Hello, World!"))) 282.116 - (is (= "\"\\\"Embedded\\\" Quotes\"" (json-str "\"Embedded\" Quotes")))) 282.117 - 282.118 -(deftest- can-print-unicode 282.119 - (is (= "\"\\u1234\\u4567\"" (json-str "\u1234\u4567")))) 282.120 - 282.121 -(deftest- can-print-json-null 282.122 - (is (= "null" (json-str nil)))) 282.123 - 282.124 -(deftest- can-print-json-arrays 282.125 - (is (= "[1, 2, 3]" (json-str [1 2 3]))) 282.126 - (is (= "[1, 2, 3]" (json-str (list 1 2 3)))) 282.127 - (is (= "[1, 2, 3]" (json-str (sorted-set 1 2 3)))) 282.128 - (is (= "[1, 2, 3]" (json-str (seq [1 2 3]))))) 282.129 - 282.130 -(deftest- can-print-java-arrays 282.131 - (is (= "[1, 2, 3]" (json-str (into-array [1 2 3]))))) 282.132 - 282.133 -(deftest- can-print-empty-arrays 282.134 - (is (= "[]" (json-str []))) 282.135 - (is (= "[]" (json-str (list)))) 282.136 - (is (= "[]" (json-str #{})))) 282.137 - 282.138 -(deftest- can-print-json-objects 282.139 - (is (= "{\"a\":1, \"b\":2}" (json-str (sorted-map :a 1 :b 2))))) 282.140 - 282.141 -(deftest- object-keys-must-be-strings 282.142 - (is (= "{\"1\":1, \"2\":2}" (json-str (sorted-map 1 1 2 2))))) 282.143 - 282.144 -(deftest- can-print-empty-objects 282.145 - (is (= "{}" (json-str {}))))
283.1 --- a/src/clojure/contrib/test_contrib/pprint/examples/multiply.clj Sat Aug 21 06:25:44 2010 -0400 283.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 283.3 @@ -1,23 +0,0 @@ 283.4 -;;; multiply.clj -- part of the pretty printer for Clojure 283.5 - 283.6 -;; by Tom Faulhaber 283.7 -;; April 3, 2009 283.8 - 283.9 -; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. 283.10 -; The use and distribution terms for this software are covered by the 283.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 283.12 -; which can be found in the file epl-v10.html at the root of this distribution. 283.13 -; By using this software in any fashion, you are agreeing to be bound by 283.14 -; the terms of this license. 283.15 -; You must not remove this notice, or any other, from this software. 283.16 - 283.17 -;; This example prints a multiplication table using cl-format. 283.18 - 283.19 -(ns clojure.contrib.pprint.examples.multiply 283.20 - (:use clojure.contrib.pprint)) 283.21 - 283.22 -(defn multiplication-table [limit] 283.23 - (let [nums (range 1 (inc limit))] 283.24 - (cl-format true "~{~{~4d~}~%~}" 283.25 - (map #(map % nums) 283.26 - (map #(partial * %) nums)))))
284.1 --- a/src/clojure/contrib/test_contrib/pprint/examples/props.clj Sat Aug 21 06:25:44 2010 -0400 284.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 284.3 @@ -1,25 +0,0 @@ 284.4 -;;; props.clj -- part of the pretty printer for Clojure 284.5 - 284.6 -;; by Tom Faulhaber 284.7 -;; April 3, 2009 284.8 - 284.9 -; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. 284.10 -; The use and distribution terms for this software are covered by the 284.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 284.12 -; which can be found in the file epl-v10.html at the root of this distribution. 284.13 -; By using this software in any fashion, you are agreeing to be bound by 284.14 -; the terms of this license. 284.15 -; You must not remove this notice, or any other, from this software. 284.16 - 284.17 -;; This example displays a nicely formatted table of the java properties using 284.18 -;; cl-format 284.19 - 284.20 -(ns clojure.contrib.pprint.examples.props 284.21 - (:use clojure.contrib.pprint)) 284.22 - 284.23 -(defn show-props [stream] 284.24 - (let [p (mapcat 284.25 - #(vector (key %) (val %)) 284.26 - (sort-by key (System/getProperties)))] 284.27 - (cl-format true "~30A~A~%~{~20,,,'-A~10A~}~%~{~30A~S~%~}" 284.28 - "Property" "Value" ["" "" "" ""] p)))
285.1 --- a/src/clojure/contrib/test_contrib/pprint/examples/show_doc.clj Sat Aug 21 06:25:44 2010 -0400 285.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 285.3 @@ -1,50 +0,0 @@ 285.4 -;;; show_doc.clj -- part of the pretty printer for Clojure 285.5 - 285.6 -;; by Tom Faulhaber 285.7 -;; April 3, 2009 285.8 - 285.9 -; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. 285.10 -; The use and distribution terms for this software are covered by the 285.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 285.12 -; which can be found in the file epl-v10.html at the root of this distribution. 285.13 -; By using this software in any fashion, you are agreeing to be bound by 285.14 -; the terms of this license. 285.15 -; You must not remove this notice, or any other, from this software. 285.16 - 285.17 -;; This example uses cl-format as part of a routine to display all the doc 285.18 -;; strings and function arguments from one or more namespaces. 285.19 - 285.20 -(ns clojure.contrib.pprint.examples.show-doc 285.21 - (:use clojure.contrib.pprint)) 285.22 - 285.23 -(defn ns-list 285.24 - ([] (ns-list nil)) 285.25 - ([pattern] 285.26 - (filter 285.27 - (if pattern 285.28 - (comp (partial re-find pattern) name ns-name) 285.29 - (constantly true)) 285.30 - (sort-by ns-name (all-ns))))) 285.31 - 285.32 -(defn show-doc 285.33 - ([] (show-doc nil)) 285.34 - ([pattern] 285.35 - (cl-format 285.36 - true 285.37 - "~:{~A: ===============================================~ 285.38 - ~%~{~{~a: ~{~a~^, ~}~%~a~%~}~^~%~}~2%~}" 285.39 - (map 285.40 - #(vector (ns-name %) 285.41 - (map 285.42 - (fn [f] 285.43 - (let [f-meta (meta (find-var (symbol (str (ns-name %)) (str f))))] 285.44 - [f (:arglists f-meta) (:doc f-meta)])) 285.45 - (filter 285.46 - (fn [a] (instance? clojure.lang.IFn a)) 285.47 - (sort (map key (ns-publics %)))))) 285.48 - (ns-list pattern))))) 285.49 - 285.50 -(defn create-api-file [pattern out-file] 285.51 - (with-open [f (java.io.FileWriter. out-file)] 285.52 - (binding [*out* f] 285.53 - (show-doc pattern))))
286.1 --- a/src/clojure/contrib/test_contrib/pprint/examples/xml.clj Sat Aug 21 06:25:44 2010 -0400 286.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 286.3 @@ -1,121 +0,0 @@ 286.4 -;;; xml.clj -- a pretty print dispatch version of prxml.clj -- a compact syntax for generating XML 286.5 - 286.6 -;; by Tom Faulhaber, based on the original by Stuart Sierra, http://stuartsierra.com/ 286.7 -;; May 13, 2009 286.8 - 286.9 -;; Copyright (c) 2009 Tom Faulhaber/Stuart Sierra. All rights reserved. The use and 286.10 -;; distribution terms for this software are covered by the Eclipse 286.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 286.12 -;; which can be found in the file epl-v10.html at the root of this 286.13 -;; distribution. By using this software in any fashion, you are 286.14 -;; agreeing to be bound by the terms of this license. You must not 286.15 -;; remove this notice, or any other, from this software. 286.16 - 286.17 - 286.18 -;; See function "prxml" at the bottom of this file for documentation. 286.19 - 286.20 - 286.21 -(ns 286.22 - #^{:author "Tom Faulhaber, based on the original by Stuart Sierra", 286.23 - :doc "A version of prxml that uses a pretty print dispatch function."} 286.24 - clojure.contrib.pprint.examples.xml 286.25 - (:use [clojure.contrib.string :only (as-str escape)] 286.26 - [clojure.contrib.pprint :only (formatter-out write)] 286.27 - [clojure.contrib.pprint.utilities :only (prlabel)])) 286.28 - 286.29 -(def 286.30 - #^{:doc "If true, empty tags will have a space before the closing />"} 286.31 - *html-compatible* false) 286.32 - 286.33 -(def 286.34 - #^{:doc "The number of spaces to indent sub-tags."} 286.35 - *prxml-indent* 2) 286.36 - 286.37 -(defmulti #^{:private true} print-xml-tag (fn [tag attrs content] tag)) 286.38 - 286.39 -(defmethod print-xml-tag :raw! [tag attrs contents] 286.40 - (doseq [c contents] (print c))) 286.41 - 286.42 -(defmethod print-xml-tag :comment! [tag attrs contents] 286.43 - (print "<!-- ") 286.44 - (doseq [c contents] (print c)) 286.45 - (print " -->")) 286.46 - 286.47 -(defmethod print-xml-tag :decl! [tag attrs contents] 286.48 - (let [attrs (merge {:version "1.0" :encoding "UTF-8"} 286.49 - attrs)] 286.50 - ;; Must enforce ordering of pseudo-attributes: 286.51 - ((formatter-out "<?xml version=\"~a\" encoding=\"~a\"~@[ standalone=\"~a\"~]?>") 286.52 - (:version attrs) (:encoding attrs) (:standalone attrs)))) 286.53 - 286.54 -(defmethod print-xml-tag :cdata! [tag attrs contents] 286.55 - ((formatter-out "<[!CDATA[~{~a~}]]>") contents)) 286.56 - 286.57 -(defmethod print-xml-tag :doctype! [tag attrs contents] 286.58 - ((formatter-out "<[!DOCTYPE [~{~a~}]]>") contents)) 286.59 - 286.60 -(defmethod print-xml-tag :default [tag attrs contents] 286.61 - (let [tag-name (as-str tag) 286.62 - xlated-attrs (map #(vector (as-str (key %)) (as-str (val %))) attrs)] 286.63 - (if (seq contents) 286.64 - ((formatter-out "~<~<<~a~1:i~{ ~:_~{~a=\"~a\"~}~}>~:>~vi~{~_~w~}~0i~_</~a>~:>") 286.65 - [[tag-name xlated-attrs] *prxml-indent* contents tag-name]) 286.66 - ((formatter-out "~<<~a~1:i~{~:_ ~{~a=\"~a\"~}~}/>~:>") [tag-name xlated-attrs])))) 286.67 - 286.68 - 286.69 -(defmulti xml-dispatch class) 286.70 - 286.71 -(defmethod xml-dispatch clojure.lang.IPersistentVector [x] 286.72 - (let [[tag & contents] x 286.73 - [attrs content] (if (map? (first contents)) 286.74 - [(first contents) (rest contents)] 286.75 - [{} contents])] 286.76 - (print-xml-tag tag attrs content))) 286.77 - 286.78 -(defmethod xml-dispatch clojure.lang.ISeq [x] 286.79 - ;; Recurse into sequences, so we can use (map ...) inside prxml. 286.80 - (doseq [c x] (xml-dispatch c))) 286.81 - 286.82 -(defmethod xml-dispatch clojure.lang.Keyword [x] 286.83 - (print-xml-tag x {} nil)) 286.84 - 286.85 - 286.86 -(defmethod xml-dispatch String [x] 286.87 - (print (escape {\< "<" 286.88 - \> ">" 286.89 - \& "&" 286.90 - \' "'" 286.91 - \" """} x))) 286.92 - 286.93 -(defmethod xml-dispatch nil [x]) 286.94 - 286.95 -(defmethod xml-dispatch :default [x] 286.96 - (print x)) 286.97 - 286.98 - 286.99 -(defn prxml 286.100 - "Print XML to *out*. Vectors become XML tags: the first item is the 286.101 - tag name; optional second item is a map of attributes. 286.102 - 286.103 - Sequences are processed recursively, so you can use map and other 286.104 - sequence functions inside prxml. 286.105 - 286.106 - (prxml [:p {:class \"greet\"} [:i \"Ladies & gentlemen\"]]) 286.107 - ; => <p class=\"greet\"><i>Ladies & gentlemen</i></p> 286.108 - 286.109 - PSEUDO-TAGS: some keywords have special meaning: 286.110 - 286.111 - :raw! do not XML-escape contents 286.112 - :comment! create an XML comment 286.113 - :decl! create an XML declaration, with attributes 286.114 - :cdata! create a CDATA section 286.115 - :doctype! create a DOCTYPE! 286.116 - 286.117 - (prxml [:p [:raw! \"<i>here & gone</i>\"]]) 286.118 - ; => <p><i>here & gone</i></p> 286.119 - 286.120 - (prxml [:decl! {:version \"1.1\"}]) 286.121 - ; => <?xml version=\"1.1\" encoding=\"UTF-8\"?>" 286.122 - [& args] 286.123 - (doseq [arg args] (write arg :dispatch xml-dispatch)) 286.124 - (when (pos? (count args)) (newline)))
287.1 --- a/src/clojure/contrib/test_contrib/pprint/test_cl_format.clj Sat Aug 21 06:25:44 2010 -0400 287.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 287.3 @@ -1,691 +0,0 @@ 287.4 -;;; cl_format.clj -- part of the pretty printer for Clojure 287.5 - 287.6 -;; by Tom Faulhaber 287.7 -;; April 3, 2009 287.8 - 287.9 -; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. 287.10 -; The use and distribution terms for this software are covered by the 287.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 287.12 -; which can be found in the file epl-v10.html at the root of this distribution. 287.13 -; By using this software in any fashion, you are agreeing to be bound by 287.14 -; the terms of this license. 287.15 -; You must not remove this notice, or any other, from this software. 287.16 - 287.17 -;; This test set tests the basic cl-format functionality 287.18 - 287.19 -(ns clojure.contrib.pprint.test-cl-format 287.20 - (:refer-clojure :exclude [format]) 287.21 - (:use [clojure.test :only (deftest are run-tests)] 287.22 - clojure.contrib.pprint.test-helper 287.23 - clojure.contrib.pprint)) 287.24 - 287.25 -(def format cl-format) 287.26 - 287.27 -;; TODO tests for ~A, ~D, etc. 287.28 -;; TODO add tests for ~F, etc.: 0.0, 9.9999 with rounding, 9.9999E99 with rounding 287.29 - 287.30 -(simple-tests d-tests 287.31 - (cl-format nil "~D" 0) "0" 287.32 - (cl-format nil "~D" 2e6) "2000000" 287.33 - (cl-format nil "~D" 2000000) "2000000" 287.34 - (cl-format nil "~:D" 2000000) "2,000,000" 287.35 - (cl-format nil "~D" 1/2) "1/2" 287.36 - (cl-format nil "~D" 'fred) "fred" 287.37 -) 287.38 - 287.39 -(simple-tests base-tests 287.40 - (cl-format nil "~{~2r~^ ~}~%" (range 10)) 287.41 - "0 1 10 11 100 101 110 111 1000 1001\n" 287.42 - (with-out-str 287.43 - (dotimes [i 35] 287.44 - (binding [*print-base* (+ i 2)] ;print the decimal number 40 287.45 - (write 40) ;in each base from 2 to 36 287.46 - (if (zero? (mod i 10)) (prn) (cl-format true " "))))) 287.47 - "101000 287.48 -1111 220 130 104 55 50 44 40 37 34 287.49 -31 2c 2a 28 26 24 22 20 1j 1i 287.50 -1h 1g 1f 1e 1d 1c 1b 1a 19 18 287.51 -17 16 15 14 " 287.52 - (with-out-str 287.53 - (doseq [pb [2 3 8 10 16]] 287.54 - (binding [*print-radix* true ;print the integer 10 and 287.55 - *print-base* pb] ;the ratio 1/10 in bases 2, 287.56 - (cl-format true "~&~S ~S~%" 10 1/10)))) ;3, 8, 10, 16 287.57 - "#b1010 #b1/1010 287.58 -#3r101 #3r1/101 287.59 -#o12 #o1/12 287.60 -10. #10r1/10 287.61 -#xa #x1/a 287.62 -") 287.63 - 287.64 - 287.65 - 287.66 -(simple-tests cardinal-tests 287.67 - (cl-format nil "~R" 0) "zero" 287.68 - (cl-format nil "~R" 4) "four" 287.69 - (cl-format nil "~R" 15) "fifteen" 287.70 - (cl-format nil "~R" -15) "minus fifteen" 287.71 - (cl-format nil "~R" 25) "twenty-five" 287.72 - (cl-format nil "~R" 20) "twenty" 287.73 - (cl-format nil "~R" 200) "two hundred" 287.74 - (cl-format nil "~R" 203) "two hundred three" 287.75 - 287.76 - (cl-format nil "~R" 44879032) 287.77 - "forty-four million, eight hundred seventy-nine thousand, thirty-two" 287.78 - 287.79 - (cl-format nil "~R" -44879032) 287.80 - "minus forty-four million, eight hundred seventy-nine thousand, thirty-two" 287.81 - 287.82 - (cl-format nil "~R = ~:*~:D" 44000032) 287.83 - "forty-four million, thirty-two = 44,000,032" 287.84 - 287.85 - (cl-format nil "~R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094) 287.86 - "four hundred forty-eight septendecillion, seven hundred ninety sexdecillion, three hundred twenty-nine quindecillion, four hundred eighty quattuordecillion, nine hundred forty-eight tredecillion, two hundred nine duodecillion, three hundred eighty-four undecillion, three hundred eighty-nine decillion, four hundred twenty-nine nonillion, three hundred eighty-four octillion, twenty-nine septillion, three hundred eighty-four sextillion, twenty-nine quintillion, eight hundred forty-two quadrillion, ninety-eight trillion, four hundred twenty billion, nine hundred eighty-nine million, eight hundred forty-two thousand, ninety-four = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094" 287.87 - 287.88 - (cl-format nil "~R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094490320942058747587584758375847593475) 287.89 - "448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475 = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475" 287.90 - 287.91 - (cl-format nil "~R = ~:*~:D" 2e6) 287.92 - "two million = 2,000,000" 287.93 - 287.94 - (cl-format nil "~R = ~:*~:D" 200000200000) 287.95 - "two hundred billion, two hundred thousand = 200,000,200,000") 287.96 - 287.97 -(simple-tests ordinal-tests 287.98 - (cl-format nil "~:R" 0) "zeroth" 287.99 - (cl-format nil "~:R" 4) "fourth" 287.100 - (cl-format nil "~:R" 15) "fifteenth" 287.101 - (cl-format nil "~:R" -15) "minus fifteenth" 287.102 - (cl-format nil "~:R" 25) "twenty-fifth" 287.103 - (cl-format nil "~:R" 20) "twentieth" 287.104 - (cl-format nil "~:R" 200) "two hundredth" 287.105 - (cl-format nil "~:R" 203) "two hundred third" 287.106 - 287.107 - (cl-format nil "~:R" 44879032) 287.108 - "forty-four million, eight hundred seventy-nine thousand, thirty-second" 287.109 - 287.110 - (cl-format nil "~:R" -44879032) 287.111 - "minus forty-four million, eight hundred seventy-nine thousand, thirty-second" 287.112 - 287.113 - (cl-format nil "~:R = ~:*~:D" 44000032) 287.114 - "forty-four million, thirty-second = 44,000,032" 287.115 - 287.116 - (cl-format nil "~:R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094) 287.117 - "four hundred forty-eight septendecillion, seven hundred ninety sexdecillion, three hundred twenty-nine quindecillion, four hundred eighty quattuordecillion, nine hundred forty-eight tredecillion, two hundred nine duodecillion, three hundred eighty-four undecillion, three hundred eighty-nine decillion, four hundred twenty-nine nonillion, three hundred eighty-four octillion, twenty-nine septillion, three hundred eighty-four sextillion, twenty-nine quintillion, eight hundred forty-two quadrillion, ninety-eight trillion, four hundred twenty billion, nine hundred eighty-nine million, eight hundred forty-two thousand, ninety-fourth = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094" 287.118 - (cl-format nil "~:R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094490320942058747587584758375847593475) 287.119 - "448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475th = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475" 287.120 - (cl-format nil "~:R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094490320942058747587584758375847593471) 287.121 - "448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,471st = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,471" 287.122 - (cl-format nil "~:R = ~:*~:D" 2e6) 287.123 - "two millionth = 2,000,000") 287.124 - 287.125 -(simple-tests ordinal1-tests 287.126 - (cl-format nil "~:R" 1) "first" 287.127 - (cl-format nil "~:R" 11) "eleventh" 287.128 - (cl-format nil "~:R" 21) "twenty-first" 287.129 - (cl-format nil "~:R" 20) "twentieth" 287.130 - (cl-format nil "~:R" 220) "two hundred twentieth" 287.131 - (cl-format nil "~:R" 200) "two hundredth" 287.132 - (cl-format nil "~:R" 999) "nine hundred ninety-ninth" 287.133 - ) 287.134 - 287.135 -(simple-tests roman-tests 287.136 - (cl-format nil "~@R" 3) "III" 287.137 - (cl-format nil "~@R" 4) "IV" 287.138 - (cl-format nil "~@R" 9) "IX" 287.139 - (cl-format nil "~@R" 29) "XXIX" 287.140 - (cl-format nil "~@R" 429) "CDXXIX" 287.141 - (cl-format nil "~@:R" 429) "CCCCXXVIIII" 287.142 - (cl-format nil "~@:R" 3429) "MMMCCCCXXVIIII" 287.143 - (cl-format nil "~@R" 3429) "MMMCDXXIX" 287.144 - (cl-format nil "~@R" 3479) "MMMCDLXXIX" 287.145 - (cl-format nil "~@R" 3409) "MMMCDIX" 287.146 - (cl-format nil "~@R" 300) "CCC" 287.147 - (cl-format nil "~@R ~D" 300 20) "CCC 20" 287.148 - (cl-format nil "~@R" 5000) "5,000" 287.149 - (cl-format nil "~@R ~D" 5000 20) "5,000 20" 287.150 - (cl-format nil "~@R" "the quick") "the quick") 287.151 - 287.152 -(simple-tests c-tests 287.153 - (cl-format nil "~{~c~^, ~}~%" "hello") "h, e, l, l, o\n" 287.154 - (cl-format nil "~{~:c~^, ~}~%" "hello") "h, e, l, l, o\n" 287.155 - (cl-format nil "~@C~%" \m) "\\m\n" 287.156 - (cl-format nil "~@C~%" (char 222)) "\\Þ\n" 287.157 - (cl-format nil "~@C~%" (char 8)) "\\backspace\n" 287.158 - (cl-format nil "~@C~%" (char 3)) "\\\n") 287.159 - 287.160 -(simple-tests e-tests 287.161 - (cl-format nil "*~E*" 0.0) "*0.0E+0*" 287.162 - (cl-format nil "*~6E*" 0.0) "*0.0E+0*" 287.163 - (cl-format nil "*~6,0E*" 0.0) "* 0.E+0*" 287.164 - (cl-format nil "*~7,2E*" 0.0) "*0.00E+0*" 287.165 - (cl-format nil "*~5E*" 0.0) "*0.E+0*" 287.166 - (cl-format nil "*~10,2,2,,'?E*" 2.8E120) "*??????????*" 287.167 - (cl-format nil "*~10,2E*" 9.99999) "* 1.00E+1*" 287.168 - (cl-format nil "*~10,2E*" 9.99999E99) "* 1.00E+100*" 287.169 - (cl-format nil "*~10,2,2E*" 9.99999E99) "* 1.00E+100*" 287.170 - (cl-format nil "*~10,2,2,,'?E*" 9.99999E99) "*??????????*" 287.171 - ) 287.172 - 287.173 -(simple-tests $-tests 287.174 - (cl-format nil "~$" 22.3) "22.30" 287.175 - (cl-format nil "~$" 22.375) "22.38" 287.176 - (cl-format nil "~3,5$" 22.375) "00022.375" 287.177 - (cl-format nil "~3,5,8$" 22.375) "00022.375" 287.178 - (cl-format nil "~3,5,10$" 22.375) " 00022.375" 287.179 - (cl-format nil "~3,5,14@$" 22.375) " +00022.375" 287.180 - (cl-format nil "~3,5,14@$" 22.375) " +00022.375" 287.181 - (cl-format nil "~3,5,14@:$" 22.375) "+ 00022.375" 287.182 - (cl-format nil "~3,,14@:$" 0.375) "+ 0.375" 287.183 - (cl-format nil "~1,1$" -12.0) "-12.0" 287.184 - (cl-format nil "~1,1$" 12.0) "12.0" 287.185 - (cl-format nil "~1,1$" 12.0) "12.0" 287.186 - (cl-format nil "~1,1@$" 12.0) "+12.0" 287.187 - (cl-format nil "~1,1,8,' @:$" 12.0) "+ 12.0" 287.188 - (cl-format nil "~1,1,8,' @$" 12.0) " +12.0" 287.189 - (cl-format nil "~1,1,8,' :$" 12.0) " 12.0" 287.190 - (cl-format nil "~1,1,8,' $" 12.0) " 12.0" 287.191 - (cl-format nil "~1,1,8,' @:$" -12.0) "- 12.0" 287.192 - (cl-format nil "~1,1,8,' @$" -12.0) " -12.0" 287.193 - (cl-format nil "~1,1,8,' :$" -12.0) "- 12.0" 287.194 - (cl-format nil "~1,1,8,' $" -12.0) " -12.0" 287.195 - (cl-format nil "~1,1$" 0.001) "0.0" 287.196 - (cl-format nil "~2,1$" 0.001) "0.00" 287.197 - (cl-format nil "~1,1,6$" 0.001) " 0.0" 287.198 - (cl-format nil "~1,1,6$" 0.0015) " 0.0" 287.199 - (cl-format nil "~2,1,6$" 0.005) " 0.01" 287.200 - (cl-format nil "~2,1,6$" 0.01) " 0.01" 287.201 - (cl-format nil "~$" 0.099) "0.10" 287.202 - (cl-format nil "~1$" 0.099) "0.1" 287.203 - (cl-format nil "~1$" 0.1) "0.1" 287.204 - (cl-format nil "~1$" 0.99) "1.0" 287.205 - (cl-format nil "~1$" -0.99) "-1.0") 287.206 - 287.207 -(simple-tests f-tests 287.208 - (cl-format nil "~,1f" -12.0) "-12.0" 287.209 - (cl-format nil "~,0f" 9.4) "9." 287.210 - (cl-format nil "~,0f" 9.5) "10." 287.211 - (cl-format nil "~,0f" -0.99) "-1." 287.212 - (cl-format nil "~,1f" -0.99) "-1.0" 287.213 - (cl-format nil "~,2f" -0.99) "-0.99" 287.214 - (cl-format nil "~,3f" -0.99) "-0.990" 287.215 - (cl-format nil "~,0f" 0.99) "1." 287.216 - (cl-format nil "~,1f" 0.99) "1.0" 287.217 - (cl-format nil "~,2f" 0.99) "0.99" 287.218 - (cl-format nil "~,3f" 0.99) "0.990" 287.219 - (cl-format nil "~f" -1) "-1.0" 287.220 - (cl-format nil "~2f" -1) "-1." 287.221 - (cl-format nil "~3f" -1) "-1." 287.222 - (cl-format nil "~4f" -1) "-1.0" 287.223 - (cl-format nil "~8f" -1) " -1.0" 287.224 - (cl-format nil "~1,1f" 0.1) ".1") 287.225 - 287.226 -(simple-tests ampersand-tests 287.227 - (cl-format nil "The quick brown ~a jumped over ~d lazy dogs" 'elephant 5) 287.228 - "The quick brown elephant jumped over 5 lazy dogs" 287.229 - (cl-format nil "The quick brown ~&~a jumped over ~d lazy dogs" 'elephant 5) 287.230 - "The quick brown \nelephant jumped over 5 lazy dogs" 287.231 - (cl-format nil "The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5) 287.232 - "The quick brown \nelephant jumped\n over 5 lazy dogs" 287.233 - (cl-format nil "~&The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5) 287.234 - "The quick brown \nelephant jumped\n over 5 lazy dogs" 287.235 - (cl-format nil "~3&The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5) 287.236 - "\n\nThe quick brown \nelephant jumped\n over 5 lazy dogs" 287.237 - (cl-format nil "~@{~&The quick brown ~a jumped over ~d lazy dogs~}" 'elephant 5 'fox 10) 287.238 - "The quick brown elephant jumped over 5 lazy dogs\nThe quick brown fox jumped over 10 lazy dogs" 287.239 - (cl-format nil "I ~[don't ~:;d~&o ~]have one~%" 0) "I don't have one\n" 287.240 - (cl-format nil "I ~[don't ~:;d~&o ~]have one~%" 1) "I d\no have one\n") 287.241 - 287.242 -(simple-tests t-tests 287.243 - (cl-format nil "~@{~&~A~8,4T~:*~A~}" 287.244 - 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa) 287.245 - "a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa" 287.246 - (cl-format nil "~@{~&~A~,4T~:*~A~}" 287.247 - 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa) 287.248 - "a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa" 287.249 - (cl-format nil "~@{~&~A~2,6@T~:*~A~}" 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa) 287.250 - "a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa" 287.251 -) 287.252 - 287.253 -(simple-tests paren-tests 287.254 - (cl-format nil "~(PLEASE SPEAK QUIETLY IN HERE~)") "please speak quietly in here" 287.255 - (cl-format nil "~@(PLEASE SPEAK QUIETLY IN HERE~)") "Please speak quietly in here" 287.256 - (cl-format nil "~@:(but this Is imporTant~)") "BUT THIS IS IMPORTANT" 287.257 - (cl-format nil "~:(the greAt gatsby~)!") "The Great Gatsby!" 287.258 - ;; Test cases from CLtL 18.3 - string-upcase, et al. 287.259 - (cl-format nil "~@:(~A~)" "Dr. Livingstone, I presume?") "DR. LIVINGSTONE, I PRESUME?" 287.260 - (cl-format nil "~(~A~)" "Dr. Livingstone, I presume?") "dr. livingstone, i presume?" 287.261 - (cl-format nil "~:(~A~)" " hello ") " Hello " 287.262 - (cl-format nil "~:(~A~)" "occlUDeD cASEmenTs FOreSTAll iNADVertent DEFenestraTION") 287.263 - "Occluded Casements Forestall Inadvertent Defenestration" 287.264 - (cl-format nil "~:(~A~)" 'kludgy-hash-search) "Kludgy-Hash-Search" 287.265 - (cl-format nil "~:(~A~)" "DON'T!") "Don'T!" ;not "Don't!" 287.266 - (cl-format nil "~:(~A~)" "pipe 13a, foo16c") "Pipe 13a, Foo16c" 287.267 -) 287.268 - 287.269 -(simple-tests square-bracket-tests 287.270 - ;; Tests for format without modifiers 287.271 - (cl-format nil "I ~[don't ~]have one~%" 0) "I don't have one\n" 287.272 - (cl-format nil "I ~[don't ~]have one~%" 1) "I have one\n" 287.273 - (cl-format nil "I ~[don't ~;do ~]have one~%" 0) "I don't have one\n" 287.274 - (cl-format nil "I ~[don't ~;do ~]have one~%" 1) "I do have one\n" 287.275 - (cl-format nil "I ~[don't ~;do ~]have one~%" 2) "I have one\n" 287.276 - (cl-format nil "I ~[don't ~:;do ~]have one~%" 0) "I don't have one\n" 287.277 - (cl-format nil "I ~[don't ~:;do ~]have one~%" 1) "I do have one\n" 287.278 - (cl-format nil "I ~[don't ~:;do ~]have one~%" 2) "I do have one\n" 287.279 - (cl-format nil "I ~[don't ~:;do ~]have one~%" 700) "I do have one\n" 287.280 - 287.281 - ;; Tests for format with a colon 287.282 - (cl-format nil "I ~:[don't ~;do ~]have one~%" true) "I do have one\n" 287.283 - (cl-format nil "I ~:[don't ~;do ~]have one~%" 700) "I do have one\n" 287.284 - (cl-format nil "I ~:[don't ~;do ~]have one~%" '(a b)) "I do have one\n" 287.285 - (cl-format nil "I ~:[don't ~;do ~]have one~%" nil) "I don't have one\n" 287.286 - (cl-format nil "I ~:[don't ~;do ~]have one~%" false) "I don't have one\n" 287.287 - 287.288 - ;; Tests for format with an at sign 287.289 - (cl-format nil "We had ~D wins~@[ (out of ~D tries)~].~%" 15 nil) "We had 15 wins.\n" 287.290 - (cl-format nil "We had ~D wins~@[ (out of ~D tries)~].~%" 15 17) 287.291 - "We had 15 wins (out of 17 tries).\n" 287.292 - 287.293 - ;; Format tests with directives 287.294 - (cl-format nil "Max ~D: ~[Blue team ~D~;Red team ~D~:;No team ~A~].~%" 15, 0, 7) 287.295 - "Max 15: Blue team 7.\n" 287.296 - (cl-format nil "Max ~D: ~[Blue team ~D~;Red team ~D~:;No team ~A~].~%" 15, 1, 12) 287.297 - "Max 15: Red team 12.\n" 287.298 - (cl-format nil "Max ~D: ~[Blue team ~D~;Red team ~D~:;No team ~A~].~%" 287.299 - 15, -1, "(system failure)") 287.300 - "Max 15: No team (system failure).\n" 287.301 - 287.302 - ;; Nested format tests 287.303 - (cl-format nil "Max ~D: ~[Blue team ~D~:[~; (complete success)~]~;Red team ~D~:;No team ~].~%" 287.304 - 15, 0, 7, true) 287.305 - "Max 15: Blue team 7 (complete success).\n" 287.306 - (cl-format nil "Max ~D: ~[Blue team ~D~:[~; (complete success)~]~;Red team ~D~:;No team ~].~%" 287.307 - 15, 0, 7, false) 287.308 - "Max 15: Blue team 7.\n" 287.309 - 287.310 - ;; Test the selector as part of the argument 287.311 - (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~].") 287.312 - "The answer is nothing." 287.313 - (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 4) 287.314 - "The answer is 4." 287.315 - (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 7 22) 287.316 - "The answer is 7 out of 22." 287.317 - (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 1 2 3 4) 287.318 - "The answer is something crazy." 287.319 -) 287.320 - 287.321 -(simple-tests curly-brace-plain-tests 287.322 - ;; Iteration from sublist 287.323 - (cl-format nil "Coordinates are~{ [~D,~D]~}~%" [ 0, 1, 1, 0, 3, 5, 2, 1 ]) 287.324 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 287.325 - 287.326 - (cl-format nil "Coordinates are~2{ [~D,~D]~}~%" [ 0, 1, 1, 0, 3, 5, 2, 1 ]) 287.327 - "Coordinates are [0,1] [1,0]\n" 287.328 - 287.329 - (cl-format nil "Coordinates are~{ ~#[none~;<~D>~:;[~D,~D]~]~}~%" [ ]) 287.330 - "Coordinates are\n" 287.331 - 287.332 - (cl-format nil "Coordinates are~{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [ ]) 287.333 - "Coordinates are none\n" 287.334 - 287.335 - (cl-format nil "Coordinates are~{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [2 3 1]) 287.336 - "Coordinates are [2,3] <1>\n" 287.337 - 287.338 - (cl-format nil "Coordinates are~{~:}~%" "" []) 287.339 - "Coordinates are\n" 287.340 - 287.341 - (cl-format nil "Coordinates are~{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [2 3 1]) 287.342 - "Coordinates are [2,3] <1>\n" 287.343 - 287.344 - (cl-format nil "Coordinates are~{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [ ]) 287.345 - "Coordinates are none\n" 287.346 -) 287.347 - 287.348 - 287.349 -(simple-tests curly-brace-colon-tests 287.350 - ;; Iteration from list of sublists 287.351 - (cl-format nil "Coordinates are~:{ [~D,~D]~}~%" [ [0, 1], [1, 0], [3, 5], [2, 1] ]) 287.352 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 287.353 - 287.354 - (cl-format nil "Coordinates are~:{ [~D,~D]~}~%" [ [0, 1, 0], [1, 0, 12], [3, 5], [2, 1] ]) 287.355 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 287.356 - 287.357 - (cl-format nil "Coordinates are~2:{ [~D,~D]~}~%" [ [0, 1], [1, 0], [3, 5], [2, 1] ]) 287.358 - "Coordinates are [0,1] [1,0]\n" 287.359 - 287.360 - (cl-format nil "Coordinates are~:{ ~#[none~;<~D>~:;[~D,~D]~]~}~%" [ ]) 287.361 - "Coordinates are\n" 287.362 - 287.363 - (cl-format nil "Coordinates are~:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [ ]) 287.364 - "Coordinates are none\n" 287.365 - 287.366 - (cl-format nil "Coordinates are~:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [[2 3] [1]]) 287.367 - "Coordinates are [2,3] <1>\n" 287.368 - 287.369 - (cl-format nil "Coordinates are~:{~:}~%" "" []) 287.370 - "Coordinates are\n" 287.371 - 287.372 - (cl-format nil "Coordinates are~:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [[2 3] [1]]) 287.373 - "Coordinates are [2,3] <1>\n" 287.374 - 287.375 - (cl-format nil "Coordinates are~:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [ ]) 287.376 - "Coordinates are none\n" 287.377 -) 287.378 - 287.379 -(simple-tests curly-brace-at-tests 287.380 - ;; Iteration from main list 287.381 - (cl-format nil "Coordinates are~@{ [~D,~D]~}~%" 0, 1, 1, 0, 3, 5, 2, 1) 287.382 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 287.383 - 287.384 - (cl-format nil "Coordinates are~2@{ [~D,~D]~}~%" 0, 1, 1, 0, 3, 5, 2, 1) 287.385 - "Coordinates are [0,1] [1,0]\n" 287.386 - 287.387 - (cl-format nil "Coordinates are~@{ ~#[none~;<~D>~:;[~D,~D]~]~}~%") 287.388 - "Coordinates are\n" 287.389 - 287.390 - (cl-format nil "Coordinates are~@{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%") 287.391 - "Coordinates are none\n" 287.392 - 287.393 - (cl-format nil "Coordinates are~@{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" 2 3 1) 287.394 - "Coordinates are [2,3] <1>\n" 287.395 - 287.396 - (cl-format nil "Coordinates are~@{~:}~%" "") 287.397 - "Coordinates are\n" 287.398 - 287.399 - (cl-format nil "Coordinates are~@{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" 2 3 1) 287.400 - "Coordinates are [2,3] <1>\n" 287.401 - 287.402 - (cl-format nil "Coordinates are~@{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]") 287.403 - "Coordinates are none\n" 287.404 -) 287.405 - 287.406 -(simple-tests curly-brace-colon-at-tests 287.407 - ;; Iteration from sublists on the main arg list 287.408 - (cl-format nil "Coordinates are~@:{ [~D,~D]~}~%" [0, 1], [1, 0], [3, 5], [2, 1] ) 287.409 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 287.410 - 287.411 - (cl-format nil "Coordinates are~@:{ [~D,~D]~}~%" [0, 1, 0], [1, 0, 12], [3, 5], [2, 1] ) 287.412 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 287.413 - 287.414 - (cl-format nil "Coordinates are~2@:{ [~D,~D]~}~%" [0, 1], [1, 0], [3, 5], [2, 1]) 287.415 - "Coordinates are [0,1] [1,0]\n" 287.416 - 287.417 - (cl-format nil "Coordinates are~@:{ ~#[none~;<~D>~:;[~D,~D]~]~}~%") 287.418 - "Coordinates are\n" 287.419 - 287.420 - (cl-format nil "Coordinates are~@:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%") 287.421 - "Coordinates are none\n" 287.422 - 287.423 - (cl-format nil "Coordinates are~@:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [2 3] [1]) 287.424 - "Coordinates are [2,3] <1>\n" 287.425 - 287.426 - (cl-format nil "Coordinates are~@:{~:}~%" "") 287.427 - "Coordinates are\n" 287.428 - 287.429 - (cl-format nil "Coordinates are~@:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [2 3] [1]) 287.430 - "Coordinates are [2,3] <1>\n" 287.431 - 287.432 - (cl-format nil "Coordinates are~@:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]") 287.433 - "Coordinates are none\n" 287.434 -) 287.435 - 287.436 -;; TODO tests for ~^ in ~[ constructs and other brackets 287.437 -;; TODO test ~:^ generates an error when used improperly 287.438 -;; TODO test ~:^ works in ~@:{...~} 287.439 -(let [aseq '(a quick brown fox jumped over the lazy dog) 287.440 - lseq (mapcat identity (for [x aseq] [x (.length (name x))]))] 287.441 - (simple-tests up-tests 287.442 - (cl-format nil "~{~a~^, ~}" aseq) "a, quick, brown, fox, jumped, over, the, lazy, dog" 287.443 - (cl-format nil "~{~a~0^, ~}" aseq) "a" 287.444 - (cl-format nil "~{~a~#,3^, ~}" aseq) "a, quick, brown, fox, jumped, over" 287.445 - (cl-format nil "~{~a~v,3^, ~}" lseq) "a, quick, brown, fox" 287.446 - (cl-format nil "~{~a~3,v,4^, ~}" lseq) "a, quick, brown, fox" 287.447 -)) 287.448 - 287.449 -(simple-tests angle-bracket-tests 287.450 - (cl-format nil "~<foo~;bar~;baz~>") "foobarbaz" 287.451 - (cl-format nil "~20<foo~;bar~;baz~>") "foo bar baz" 287.452 - (cl-format nil "~,,2<foo~;bar~;baz~>") "foo bar baz" 287.453 - (cl-format nil "~20<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz" 287.454 - (cl-format nil "~20:<~A~;~A~;~A~>" "foo" "bar" "baz") " foo bar baz" 287.455 - (cl-format nil "~20@<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz " 287.456 - (cl-format nil "~20@:<~A~;~A~;~A~>" "foo" "bar" "baz") " foo bar baz " 287.457 - (cl-format nil "~10,,2<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz" 287.458 - (cl-format nil "~10,10,2<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz" 287.459 - (cl-format nil "~10,10<~A~;~A~;~A~>" "foo" "bar" "baz") "foo barbaz" 287.460 - (cl-format nil "~20<~A~;~^~A~;~^~A~>" "foo" "bar" "baz") "foo bar baz" 287.461 - (cl-format nil "~20<~A~;~^~A~;~^~A~>" "foo" "bar") "foo bar" 287.462 - (cl-format nil "~20@<~A~;~^~A~;~^~A~>" "foo") "foo " 287.463 - (cl-format nil "~20:<~A~;~^~A~;~^~A~>" "foo") " foo" 287.464 -) 287.465 - 287.466 -(simple-tests angle-bracket-max-column-tests 287.467 - (cl-format nil "~%;; ~{~<~%;; ~1,50:; ~A~>~}.~%" (into [] (.split "This function computes the circular thermodynamic coefficient of the thrombulator angle for use in determining the reaction distance" "\\s"))) 287.468 - "\n;; This function computes the circular\n;; thermodynamic coefficient of the thrombulator\n;; angle for use in determining the reaction\n;; distance.\n" 287.469 -(cl-format true "~%;; ~{~<~%;; ~:; ~A~>~}.~%" (into [] (.split "This function computes the circular thermodynamic coefficient of the thrombulator angle for use in determining the reaction distance." "\\s")))) 287.470 - 287.471 -(defn list-to-table [aseq column-width] 287.472 - (let [stream (get-pretty-writer (java.io.StringWriter.))] 287.473 - (binding [*out* stream] 287.474 - (doseq [row aseq] 287.475 - (doseq [col row] 287.476 - (cl-format true "~4D~7,vT" col column-width)) 287.477 - (prn))) 287.478 - (.flush stream) 287.479 - (.toString (:base @@(:base @@stream))))) 287.480 - 287.481 -(simple-tests column-writer-test 287.482 - (list-to-table (map #(vector % (* % %) (* % % %)) (range 1 21)) 8) 287.483 - " 1 1 1 \n 2 4 8 \n 3 9 27 \n 4 16 64 \n 5 25 125 \n 6 36 216 \n 7 49 343 \n 8 64 512 \n 9 81 729 \n 10 100 1000 \n 11 121 1331 \n 12 144 1728 \n 13 169 2197 \n 14 196 2744 \n 15 225 3375 \n 16 256 4096 \n 17 289 4913 \n 18 324 5832 \n 19 361 6859 \n 20 400 8000 \n") 287.484 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 287.485 -;; The following tests are the various examples from the format 287.486 -;; documentation in Common Lisp, the Language, 2nd edition, Chapter 22.3 287.487 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 287.488 - 287.489 -(defn expt [base pow] (reduce * (repeat pow base))) 287.490 - 287.491 -(let [x 5, y "elephant", n 3] 287.492 - (simple-tests cltl-intro-tests 287.493 - (format nil "foo") "foo" 287.494 - (format nil "The answer is ~D." x) "The answer is 5." 287.495 - (format nil "The answer is ~3D." x) "The answer is 5." 287.496 - (format nil "The answer is ~3,'0D." x) "The answer is 005." 287.497 - (format nil "The answer is ~:D." (expt 47 x)) "The answer is 229,345,007." 287.498 - (format nil "Look at the ~A!" y) "Look at the elephant!" 287.499 - (format nil "Type ~:C to ~A." (char 4) "delete all your files") 287.500 - "Type Control-D to delete all your files." 287.501 - (format nil "~D item~:P found." n) "3 items found." 287.502 - (format nil "~R dog~:[s are~; is~] here." n (= n 1)) "three dogs are here." 287.503 - (format nil "~R dog~:*~[s are~; is~:;s are~] here." n) "three dogs are here." 287.504 - (format nil "Here ~[are~;is~:;are~] ~:*~R pupp~:@P." n) "Here are three puppies.")) 287.505 - 287.506 -(simple-tests cltl-B-tests 287.507 - ;; CLtL didn't have the colons here, but the spec requires them 287.508 - (format nil "~,,' ,4:B" 0xFACE) "1111 1010 1100 1110" 287.509 - (format nil "~,,' ,4:B" 0x1CE) "1 1100 1110" 287.510 - (format nil "~19,,' ,4:B" 0xFACE) "1111 1010 1100 1110" 287.511 - ;; This one was a nice idea, but nothing in the spec supports it working this way 287.512 - ;; (and SBCL doesn't work this way either) 287.513 - ;(format nil "~19,,' ,4:B" 0x1CE) "0000 0001 1100 1110") 287.514 - ) 287.515 - 287.516 -(simple-tests cltl-P-tests 287.517 - (format nil "~D tr~:@P/~D win~:P" 7 1) "7 tries/1 win" 287.518 - (format nil "~D tr~:@P/~D win~:P" 1 0) "1 try/0 wins" 287.519 - (format nil "~D tr~:@P/~D win~:P" 1 3) "1 try/3 wins") 287.520 - 287.521 -(defn foo [x] 287.522 - (format nil "~6,2F|~6,2,1,'*F|~6,2,,'?F|~6F|~,2F|~F" 287.523 - x x x x x x)) 287.524 - 287.525 -(simple-tests cltl-F-tests 287.526 - (foo 3.14159) " 3.14| 31.42| 3.14|3.1416|3.14|3.14159" 287.527 - (foo -3.14159) " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159" 287.528 - (foo 100.0) "100.00|******|100.00| 100.0|100.00|100.0" 287.529 - (foo 1234.0) "1234.00|******|??????|1234.0|1234.00|1234.0" 287.530 - (foo 0.006) " 0.01| 0.06| 0.01| 0.006|0.01|0.006") 287.531 - 287.532 -(defn foo-e [x] 287.533 - (format nil 287.534 - "~9,2,1,,'*E|~10,3,2,2,'?,,'$E|~9,3,2,-2,'%@E|~9,2E" 287.535 - x x x x)) 287.536 - 287.537 -;; Clojure doesn't support float/double differences in representation 287.538 -(simple-tests cltl-E-tests 287.539 - (foo-e 0.0314159) " 3.14E-2| 31.42$-03|+.003E+01| 3.14E-2" ; Added this one 287.540 - (foo-e 3.14159) " 3.14E+0| 31.42$-01|+.003E+03| 3.14E+0" 287.541 - (foo-e -3.14159) " -3.14E+0|-31.42$-01|-.003E+03| -3.14E+0" 287.542 - (foo-e 1100.0) " 1.10E+3| 11.00$+02|+.001E+06| 1.10E+3" 287.543 -; In Clojure, this is identical to the above 287.544 -; (foo-e 1100.0L0) " 1.10L+3| 11.00$+02|+.001L+06| 1.10L+3" 287.545 - (foo-e 1.1E13) "*********| 11.00$+12|+.001E+16| 1.10E+13" 287.546 - (foo-e 1.1E120) "*********|??????????|%%%%%%%%%|1.10E+120" 287.547 -; Clojure doesn't support real numbers this large 287.548 -; (foo-e 1.1L1200) "*********|??????????|%%%%%%%%%|1.10L+1200" 287.549 -) 287.550 - 287.551 -(simple-tests cltl-E-scale-tests 287.552 - (map 287.553 - (fn [k] (format nil "Scale factor ~2D~:*: |~13,6,2,VE|" 287.554 - (- k 5) 3.14159)) ;Prints 13 lines 287.555 - (range 13)) 287.556 - '("Scale factor -5: | 0.000003E+06|" 287.557 - "Scale factor -4: | 0.000031E+05|" 287.558 - "Scale factor -3: | 0.000314E+04|" 287.559 - "Scale factor -2: | 0.003142E+03|" 287.560 - "Scale factor -1: | 0.031416E+02|" 287.561 - "Scale factor 0: | 0.314159E+01|" 287.562 - "Scale factor 1: | 3.141590E+00|" 287.563 - "Scale factor 2: | 31.41590E-01|" 287.564 - "Scale factor 3: | 314.1590E-02|" 287.565 - "Scale factor 4: | 3141.590E-03|" 287.566 - "Scale factor 5: | 31415.90E-04|" 287.567 - "Scale factor 6: | 314159.0E-05|" 287.568 - "Scale factor 7: | 3141590.E-06|")) 287.569 - 287.570 -(defn foo-g [x] 287.571 - (format nil 287.572 - "~9,2,1,,'*G|~9,3,2,3,'?,,'$G|~9,3,2,0,'%G|~9,2G" 287.573 - x x x x)) 287.574 - 287.575 -;; Clojure doesn't support float/double differences in representation 287.576 -(simple-tests cltl-G-tests 287.577 - (foo-g 0.0314159) " 3.14E-2|314.2$-04|0.314E-01| 3.14E-2" 287.578 - (foo-g 0.314159) " 0.31 |0.314 |0.314 | 0.31 " 287.579 - (foo-g 3.14159) " 3.1 | 3.14 | 3.14 | 3.1 " 287.580 - (foo-g 31.4159) " 31. | 31.4 | 31.4 | 31. " 287.581 - (foo-g 314.159) " 3.14E+2| 314. | 314. | 3.14E+2" 287.582 - (foo-g 3141.59) " 3.14E+3|314.2$+01|0.314E+04| 3.14E+3" 287.583 -; In Clojure, this is identical to the above 287.584 -; (foo-g 3141.59L0) " 3.14L+3|314.2$+01|0.314L+04| 3.14L+3" 287.585 - (foo-g 3.14E12) "*********|314.0$+10|0.314E+13| 3.14E+12" 287.586 - (foo-g 3.14E120) "*********|?????????|%%%%%%%%%|3.14E+120" 287.587 -; Clojure doesn't support real numbers this large 287.588 -; (foo-g 3.14L1200) "*********|?????????|%%%%%%%%%|3.14L+1200" 287.589 -) 287.590 - 287.591 -(defn type-clash-error [fun nargs argnum right-type wrong-type] 287.592 - (format nil ;; CLtL has this format string slightly wrong 287.593 - "~&Function ~S requires its ~:[~:R ~;~*~]~ 287.594 - argument to be of type ~S,~%but it was called ~ 287.595 - with an argument of type ~S.~%" 287.596 - fun (= nargs 1) argnum right-type wrong-type)) 287.597 - 287.598 -(simple-tests cltl-Newline-tests 287.599 - (type-clash-error 'aref nil 2 'integer 'vector) 287.600 -"Function aref requires its second argument to be of type integer, 287.601 -but it was called with an argument of type vector.\n" 287.602 - (type-clash-error 'car 1 1 'list 'short-float) 287.603 -"Function car requires its argument to be of type list, 287.604 -but it was called with an argument of type short-float.\n") 287.605 - 287.606 -(simple-tests cltl-?-tests 287.607 - (format nil "~? ~D" "<~A ~D>" '("Foo" 5) 7) "<Foo 5> 7" 287.608 - (format nil "~? ~D" "<~A ~D>" '("Foo" 5 14) 7) "<Foo 5> 7" 287.609 - (format nil "~@? ~D" "<~A ~D>" "Foo" 5 7) "<Foo 5> 7" 287.610 - (format nil "~@? ~D" "<~A ~D>" "Foo" 5 14 7) "<Foo 5> 14") 287.611 - 287.612 -(defn f [n] (format nil "~@(~R~) error~:P detected." n)) 287.613 - 287.614 -(simple-tests cltl-paren-tests 287.615 - (format nil "~@R ~(~@R~)" 14 14) "XIV xiv" 287.616 - (f 0) "Zero errors detected." 287.617 - (f 1) "One error detected." 287.618 - (f 23) "Twenty-three errors detected.") 287.619 - 287.620 -(let [*print-level* nil *print-length* 5] 287.621 - (simple-tests cltl-bracket-tests 287.622 - (format nil "~@[ print level = ~D~]~@[ print length = ~D~]" 287.623 - *print-level* *print-length*) 287.624 - " print length = 5")) 287.625 - 287.626 -(let [foo "Items:~#[ none~; ~S~; ~S and ~S~ 287.627 - ~:;~@{~#[~; and~] ~ 287.628 - ~S~^,~}~]."] 287.629 - (simple-tests cltl-bracket1-tests 287.630 - (format nil foo) "Items: none." 287.631 - (format nil foo 'foo) "Items: foo." 287.632 - (format nil foo 'foo 'bar) "Items: foo and bar." 287.633 - (format nil foo 'foo 'bar 'baz) "Items: foo, bar, and baz." 287.634 - (format nil foo 'foo 'bar 'baz 'quux) "Items: foo, bar, baz, and quux.")) 287.635 - 287.636 -(simple-tests cltl-curly-bracket-tests 287.637 - (format nil 287.638 - "The winners are:~{ ~S~}." 287.639 - '(fred harry jill)) 287.640 - "The winners are: fred harry jill." 287.641 - 287.642 - (format nil "Pairs:~{ <~S,~S>~}." '(a 1 b 2 c 3)) 287.643 - "Pairs: <a,1> <b,2> <c,3>." 287.644 - 287.645 - (format nil "Pairs:~:{ <~S,~S>~}." '((a 1) (b 2) (c 3))) 287.646 - "Pairs: <a,1> <b,2> <c,3>." 287.647 - 287.648 - (format nil "Pairs:~@{ <~S,~S>~}." 'a 1 'b 2 'c 3) 287.649 - "Pairs: <a,1> <b,2> <c,3>." 287.650 - 287.651 - (format nil "Pairs:~:@{ <~S,~S>~}." '(a 1) '(b 2) '(c 3)) 287.652 - "Pairs: <a,1> <b,2> <c,3>.") 287.653 - 287.654 -(simple-tests cltl-angle-bracket-tests 287.655 - (format nil "~10<foo~;bar~>") "foo bar" 287.656 - (format nil "~10:<foo~;bar~>") " foo bar" 287.657 - (format nil "~10:@<foo~;bar~>") " foo bar " 287.658 - (format nil "~10<foobar~>") " foobar" 287.659 - (format nil "~10:<foobar~>") " foobar" 287.660 - (format nil "~10@<foobar~>") "foobar " 287.661 - (format nil "~10:@<foobar~>") " foobar ") 287.662 - 287.663 -(let [donestr "Done.~^ ~D warning~:P.~^ ~D error~:P." 287.664 - tellstr "~@{~@(~@[~R~^ ~]~A~)~}."] ;; The CLtL example is a little wrong here 287.665 - 287.666 - (simple-tests cltl-up-tests 287.667 - (format nil donestr) "Done." 287.668 - (format nil donestr 3) "Done. 3 warnings." 287.669 - (format nil donestr 1 5) "Done. 1 warning. 5 errors." 287.670 - (format nil tellstr 23) "Twenty-three." 287.671 - (format nil tellstr nil "losers") "Losers." 287.672 - (format nil tellstr 23 "losers") "Twenty-three losers." 287.673 - (format nil "~15<~S~;~^~S~;~^~S~>" 'foo) 287.674 - " foo" 287.675 - (format nil "~15<~S~;~^~S~;~^~S~>" 'foo 'bar) 287.676 - "foo bar" 287.677 - (format nil "~15<~S~;~^~S~;~^~S~>" 'foo 'bar 'baz) 287.678 - "foo bar baz")) 287.679 - 287.680 -(simple-tests cltl-up-x3j13-tests 287.681 - (format nil 287.682 - "~:{/~S~^ ...~}" 287.683 - '((hot dog) (hamburger) (ice cream) (french fries))) 287.684 - "/hot .../hamburger/ice .../french ..." 287.685 - (format nil 287.686 - "~:{/~S~:^ ...~}" 287.687 - '((hot dog) (hamburger) (ice cream) (french fries))) 287.688 - "/hot .../hamburger .../ice .../french" 287.689 - 287.690 - (format nil 287.691 - "~:{/~S~#:^ ...~}" ;; This is wrong in CLtL 287.692 - '((hot dog) (hamburger) (ice cream) (french fries))) 287.693 - "/hot .../hamburger") 287.694 -
288.1 --- a/src/clojure/contrib/test_contrib/pprint/test_helper.clj Sat Aug 21 06:25:44 2010 -0400 288.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 288.3 @@ -1,21 +0,0 @@ 288.4 -;;; helper.clj -- part of the pretty printer for Clojure 288.5 - 288.6 -;; by Tom Faulhaber 288.7 -;; April 3, 2009 288.8 - 288.9 -; Copyright (c) Tom Faulhaber, April 2009. All rights reserved. 288.10 -; The use and distribution terms for this software are covered by the 288.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 288.12 -; which can be found in the file epl-v10.html at the root of this distribution. 288.13 -; By using this software in any fashion, you are agreeing to be bound by 288.14 -; the terms of this license. 288.15 -; You must not remove this notice, or any other, from this software. 288.16 - 288.17 -;; This is just a macro to make my tests a little cleaner 288.18 - 288.19 -(ns clojure.contrib.pprint.test-helper 288.20 - (:use [clojure.test :only (deftest are run-tests)])) 288.21 - 288.22 -(defmacro simple-tests [name & test-pairs] 288.23 - `(deftest ~name (are [x y] (= x y) ~@test-pairs))) 288.24 -
289.1 --- a/src/clojure/contrib/test_contrib/pprint/test_pretty.clj Sat Aug 21 06:25:44 2010 -0400 289.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 289.3 @@ -1,127 +0,0 @@ 289.4 -;;; pretty.clj -- part of the pretty printer for Clojure 289.5 - 289.6 -;; by Tom Faulhaber 289.7 -;; April 3, 2009 289.8 - 289.9 -; Copyright (c) Tom Faulhaber, Feb 2009. All rights reserved. 289.10 -; The use and distribution terms for this software are covered by the 289.11 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 289.12 -; which can be found in the file epl-v10.html at the root of this distribution. 289.13 -; By using this software in any fashion, you are agreeing to be bound by 289.14 -; the terms of this license. 289.15 -; You must not remove this notice, or any other, from this software. 289.16 - 289.17 -(ns clojure.contrib.pprint.test-pretty 289.18 - (:use [clojure.test :only (deftest are run-tests)] 289.19 - clojure.contrib.pprint.test-helper 289.20 - clojure.contrib.pprint)) 289.21 - 289.22 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 289.23 -;;; 289.24 -;;; Unit tests for the pretty printer 289.25 -;;; 289.26 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 289.27 - 289.28 -(simple-tests xp-fill-test 289.29 - (binding [*print-pprint-dispatch* *simple-dispatch* 289.30 - *print-right-margin* 38 289.31 - *print-miser-width* nil] 289.32 - (cl-format nil "(let ~:<~@{~:<~w ~_~w~:>~^ ~:_~}~:>~_ ...)~%" 289.33 - '((x 4) (*print-length* nil) (z 2) (list nil)))) 289.34 - "(let ((x 4) (*print-length* nil)\n (z 2) (list nil))\n ...)\n" 289.35 - 289.36 - (binding [*print-pprint-dispatch* *simple-dispatch* 289.37 - *print-right-margin* 22] 289.38 - (cl-format nil "(let ~:<~@{~:<~w ~_~w~:>~^ ~:_~}~:>~_ ...)~%" 289.39 - '((x 4) (*print-length* nil) (z 2) (list nil)))) 289.40 - "(let ((x 4)\n (*print-length*\n nil)\n (z 2)\n (list nil))\n ...)\n") 289.41 - 289.42 -(simple-tests xp-miser-test 289.43 - (binding [*print-pprint-dispatch* *simple-dispatch* 289.44 - *print-right-margin* 10, *print-miser-width* 9] 289.45 - (cl-format nil "~:<LIST ~@_~W ~@_~W ~@_~W~:>" '(first second third))) 289.46 - "(LIST\n first\n second\n third)" 289.47 - 289.48 - (binding [*print-pprint-dispatch* *simple-dispatch* 289.49 - *print-right-margin* 10, *print-miser-width* 8] 289.50 - (cl-format nil "~:<LIST ~@_~W ~@_~W ~@_~W~:>" '(first second third))) 289.51 - "(LIST first second third)") 289.52 - 289.53 -(simple-tests mandatory-fill-test 289.54 - (cl-format nil 289.55 - "<pre>~%~<Usage: ~:I~@{*~a*~^~:@_~}~:>~%</pre>~%" 289.56 - [ "hello" "gooodbye" ]) 289.57 - "<pre> 289.58 -Usage: *hello* 289.59 - *gooodbye* 289.60 -</pre> 289.61 -") 289.62 - 289.63 -(simple-tests prefix-suffix-test 289.64 - (binding [*print-pprint-dispatch* *simple-dispatch* 289.65 - *print-right-margin* 10, *print-miser-width* 10] 289.66 - (cl-format nil "~<{~;LIST ~@_~W ~@_~W ~@_~W~;}~:>" '(first second third))) 289.67 - "{LIST\n first\n second\n third}") 289.68 - 289.69 -(simple-tests pprint-test 289.70 - (binding [*print-pprint-dispatch* *simple-dispatch*] 289.71 - (write '(defn foo [x y] 289.72 - (let [result (* x y)] 289.73 - (if (> result 400) 289.74 - (cl-format true "That number is too big") 289.75 - (cl-format true "The result of ~d x ~d is ~d" x y result)))) 289.76 - :stream nil)) 289.77 - "(defn 289.78 - foo 289.79 - [x y] 289.80 - (let 289.81 - [result (* x y)] 289.82 - (if 289.83 - (> result 400) 289.84 - (cl-format true \"That number is too big\") 289.85 - (cl-format true \"The result of ~d x ~d is ~d\" x y result))))" 289.86 - 289.87 - (with-pprint-dispatch *code-dispatch* 289.88 - (write '(defn foo [x y] 289.89 - (let [result (* x y)] 289.90 - (if (> result 400) 289.91 - (cl-format true "That number is too big") 289.92 - (cl-format true "The result of ~d x ~d is ~d" x y result)))) 289.93 - :stream nil)) 289.94 - "(defn foo [x y] 289.95 - (let [result (* x y)] 289.96 - (if (> result 400) 289.97 - (cl-format true \"That number is too big\") 289.98 - (cl-format true \"The result of ~d x ~d is ~d\" x y result))))" 289.99 - 289.100 - (binding [*print-pprint-dispatch* *simple-dispatch* 289.101 - *print-right-margin* 15] 289.102 - (write '(fn (cons (car x) (cdr y))) :stream nil)) 289.103 - "(fn\n (cons\n (car x)\n (cdr y)))" 289.104 - 289.105 - (with-pprint-dispatch *code-dispatch* 289.106 - (binding [*print-right-margin* 52] 289.107 - (write 289.108 - '(add-to-buffer this (make-buffer-blob (str (char c)) nil)) 289.109 - :stream nil))) 289.110 - "(add-to-buffer\n this\n (make-buffer-blob (str (char c)) nil))" 289.111 - ) 289.112 - 289.113 - 289.114 - 289.115 -(simple-tests pprint-reader-macro-test 289.116 - (with-pprint-dispatch *code-dispatch* 289.117 - (write (read-string "(map #(first %) [[1 2 3] [4 5 6] [7]])") 289.118 - :stream nil)) 289.119 - "(map #(first %) [[1 2 3] [4 5 6] [7]])" 289.120 - 289.121 - (with-pprint-dispatch *code-dispatch* 289.122 - (write (read-string "@@(ref (ref 1))") 289.123 - :stream nil)) 289.124 - "@@(ref (ref 1))" 289.125 - 289.126 - (with-pprint-dispatch *code-dispatch* 289.127 - (write (read-string "'foo") 289.128 - :stream nil)) 289.129 - "'foo" 289.130 -)
290.1 --- a/src/clojure/contrib/test_contrib/probabilities/examples_finite_distributions.clj Sat Aug 21 06:25:44 2010 -0400 290.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 290.3 @@ -1,209 +0,0 @@ 290.4 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 290.5 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 290.6 -;; 290.7 -;; Probability distribution application examples 290.8 -;; 290.9 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 290.10 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 290.11 - 290.12 -(ns 290.13 - #^{:author "Konrad Hinsen" 290.14 - :skip-wiki true 290.15 - :doc "Examples for finite probability distribution"} 290.16 - clojure.contrib.probabilities.examples-finite-distributions 290.17 - (:use [clojure.contrib.probabilities.finite-distributions 290.18 - :only (uniform prob cond-prob join-with dist-m choose 290.19 - normalize certainly cond-dist-m normalize-cond)]) 290.20 - (:use [clojure.contrib.monads 290.21 - :only (domonad with-monad m-seq m-chain m-lift)]) 290.22 - (:require clojure.contrib.accumulators)) 290.23 - 290.24 -;; Simple examples using dice 290.25 - 290.26 -; A single die is represented by a uniform distribution over the 290.27 -; six possible outcomes. 290.28 -(def die (uniform #{1 2 3 4 5 6})) 290.29 - 290.30 -; The probability that the result is odd... 290.31 -(prob odd? die) 290.32 -; ... or greater than four. 290.33 -(prob #(> % 4) die) 290.34 - 290.35 -; The sum of two dice 290.36 -(def two-dice (join-with + die die)) 290.37 -(prob #(> % 6) two-dice) 290.38 - 290.39 -; The sum of two dice using a monad comprehension 290.40 -(assert (= two-dice 290.41 - (domonad dist-m 290.42 - [d1 die 290.43 - d2 die] 290.44 - (+ d1 d2)))) 290.45 - 290.46 -; The two values separately, but as an ordered pair 290.47 -(domonad dist-m 290.48 - [d1 die 290.49 - d2 die] 290.50 - (if (< d1 d2) (list d1 d2) (list d2 d1))) 290.51 - 290.52 -; The conditional probability for two dice yielding X if X is odd: 290.53 -(cond-prob odd? two-dice) 290.54 - 290.55 -; A two-step experiment: throw a die, and then add 1 with probability 1/2 290.56 -(domonad dist-m 290.57 - [d die 290.58 - x (choose (/ 1 2) d 290.59 - :else (inc d))] 290.60 - x) 290.61 - 290.62 -; The sum of n dice 290.63 -(defn dice [n] 290.64 - (domonad dist-m 290.65 - [ds (m-seq (replicate n die))] 290.66 - (apply + ds))) 290.67 - 290.68 -(assert (= two-dice (dice 2))) 290.69 - 290.70 -(dice 3) 290.71 - 290.72 - 290.73 -;; Construct an empirical distribution from counters 290.74 - 290.75 -; Using an ordinary counter: 290.76 -(def dist1 290.77 - (normalize 290.78 - (clojure.contrib.accumulators/add-items 290.79 - clojure.contrib.accumulators/empty-counter 290.80 - (for [_ (range 1000)] (rand-int 5))))) 290.81 - 290.82 -; Or, more efficiently, using a counter that already keeps track of its total: 290.83 -(def dist2 290.84 - (normalize 290.85 - (clojure.contrib.accumulators/add-items 290.86 - clojure.contrib.accumulators/empty-counter-with-total 290.87 - (for [_ (range 1000)] (rand-int 5))))) 290.88 - 290.89 - 290.90 -;; The Monty Hall game 290.91 -;; (see http://en.wikipedia.org/wiki/Monty_Hall_problem for a description) 290.92 - 290.93 -; The set of doors. In the classical variant, there are three doors, 290.94 -; but the code can also work with more than three doors. 290.95 -(def doors #{:A :B :C}) 290.96 - 290.97 -; A simulation of the game, step by step: 290.98 -(domonad dist-m 290.99 - [; The prize is hidden behind one of the doors. 290.100 - prize (uniform doors) 290.101 - ; The player make his initial choice. 290.102 - choice (uniform doors) 290.103 - ; The host opens a door which is neither the prize door nor the 290.104 - ; one chosen by the player. 290.105 - opened (uniform (disj doors prize choice)) 290.106 - ; If the player stays with his initial choice, the game ends and the 290.107 - ; following line should be commented out. It describes the switch from 290.108 - ; the initial choice to a door that is neither the opened one nor 290.109 - ; his original choice. 290.110 - choice (uniform (disj doors opened choice)) 290.111 - ] 290.112 - ; If the chosen door has the prize behind it, the player wins. 290.113 - (if (= choice prize) :win :loose)) 290.114 - 290.115 - 290.116 -;; Tree growth simulation 290.117 -;; Adapted from the code in: 290.118 -;; Martin Erwig and Steve Kollmansberger, 290.119 -;; "Probabilistic Functional Programming in Haskell", 290.120 -;; Journal of Functional Programming, Vol. 16, No. 1, 21-34, 2006 290.121 -;; http://web.engr.oregonstate.edu/~erwig/papers/abstracts.html#JFP06a 290.122 - 290.123 -; A tree is represented by two attributes: its state (alive, hit, fallen), 290.124 -; and its height (an integer). A new tree starts out alive and with zero height. 290.125 -(def new-tree {:state :alive, :height 0}) 290.126 - 290.127 -; An evolution step in the simulation modifies alive trees only. They can 290.128 -; either grow by one (90% probability), be hit by lightning and then stop 290.129 -; growing (4% probability), or fall down (6% probability). 290.130 -(defn evolve-1 [tree] 290.131 - (let [{s :state h :height} tree] 290.132 - (if (= s :alive) 290.133 - (choose 0.9 (assoc tree :height (inc (:height tree))) 290.134 - 0.04 (assoc tree :state :hit) 290.135 - :else {:state :fallen, :height 0}) 290.136 - (certainly tree)))) 290.137 - 290.138 -; Multiple evolution steps can be chained together with m-chain, 290.139 -; since each step's input is the output of the previous step. 290.140 -(with-monad dist-m 290.141 - (defn evolve [n tree] 290.142 - ((m-chain (replicate n evolve-1)) tree))) 290.143 - 290.144 -; Try it for zero, one, or two steps. 290.145 -(evolve 0 new-tree) 290.146 -(evolve 1 new-tree) 290.147 -(evolve 2 new-tree) 290.148 - 290.149 -; We can also get a distribution of the height only: 290.150 -(with-monad dist-m 290.151 - ((m-lift 1 :height) (evolve 2 new-tree))) 290.152 - 290.153 - 290.154 - 290.155 -;; Bayesian inference 290.156 -;; 290.157 -;; Suppose someone has three dice, one with six faces, one with eight, and 290.158 -;; one with twelve. This person throws one die and gives us the number, 290.159 -;; but doesn't tell us which die it was. What are the Bayesian probabilities 290.160 -;; for each of the three dice, given the observation we have? 290.161 - 290.162 -; A function that returns the distribution of a dice with n faces. 290.163 -(defn die-n [n] (uniform (range 1 (inc n)))) 290.164 - 290.165 -; The three dice in the game with their distributions. With this map, we 290.166 -; can easily calculate the probability for an observation under the 290.167 -; condition that a particular die was used. 290.168 -(def dice {:six (die-n 6) 290.169 - :eight (die-n 8) 290.170 - :twelve (die-n 12)}) 290.171 - 290.172 -; The only prior knowledge is that one of the three dice is used, so we 290.173 -; have no better than a uniform distribution to start with. 290.174 -(def prior (uniform (keys dice))) 290.175 - 290.176 -; Add a single observation to the information contained in the 290.177 -; distribution. Adding an observation consists of 290.178 -; 1) Draw a die from the prior distribution. 290.179 -; 2) Draw an observation from the distribution of that die. 290.180 -; 3) Eliminate (replace by nil) the trials that do not match the observation. 290.181 -; 4) Normalize the distribution for the non-nil values. 290.182 -(defn add-observation [prior observation] 290.183 - (normalize-cond 290.184 - (domonad cond-dist-m 290.185 - [die prior 290.186 - number (get dice die) 290.187 - :when (= number observation) ] 290.188 - die))) 290.189 - 290.190 -; Add one observation. 290.191 -(add-observation prior 1) 290.192 - 290.193 -; Add three consecutive observations. 290.194 -(-> prior (add-observation 1) 290.195 - (add-observation 3) 290.196 - (add-observation 7)) 290.197 - 290.198 -; We can also add multiple observations in a single trial, but this 290.199 -; is slower because more combinations have to be taken into account. 290.200 -; With Bayesian inference, it is most efficient to eliminate choices 290.201 -; as early as possible. 290.202 -(defn add-observations [prior observations] 290.203 - (with-monad cond-dist-m 290.204 - (let [n-nums #(m-seq (replicate (count observations) (get dice %)))] 290.205 - (normalize-cond 290.206 - (domonad 290.207 - [die prior 290.208 - nums (n-nums die) 290.209 - :when (= nums observations)] 290.210 - die))))) 290.211 - 290.212 -(add-observations prior [1 3 7])
291.1 --- a/src/clojure/contrib/test_contrib/probabilities/examples_monte_carlo.clj Sat Aug 21 06:25:44 2010 -0400 291.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 291.3 @@ -1,73 +0,0 @@ 291.4 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 291.5 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 291.6 -;; 291.7 -;; Monte-Carlo application examples 291.8 -;; 291.9 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 291.10 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 291.11 - 291.12 -(ns 291.13 - #^{:author "Konrad Hinsen" 291.14 - :skip-wiki true 291.15 - :doc "Examples for monte carlo methods"} 291.16 - clojure.contrib.probabilities.random.examples-monte-carlo 291.17 - (:require [clojure.contrib.generic.collection :as gc]) 291.18 - (:use [clojure.contrib.probabilities.random-numbers 291.19 - :only (lcg rand-stream)]) 291.20 - (:use [clojure.contrib.probabilities.finite-distributions 291.21 - :only (uniform)]) 291.22 - (:use [clojure.contrib.probabilities.monte-carlo 291.23 - :only (random-stream discrete interval normal lognormal exponential 291.24 - n-sphere 291.25 - sample sample-sum sample-mean sample-mean-variance)] 291.26 - :reload) 291.27 - (:use [clojure.contrib.monads 291.28 - :only (domonad state-m)])) 291.29 - 291.30 -; Create a linear congruential generator 291.31 -(def urng (lcg 259200 7141 54773 1)) 291.32 - 291.33 -;; Use Clojure's built-in random number generator 291.34 -;(def urng rand-stream) 291.35 - 291.36 -; Sample transformed distributions 291.37 -(defn sample-distribution 291.38 - [n rt] 291.39 - (take n (gc/seq (random-stream rt urng)))) 291.40 - 291.41 -; Interval [-2, 2) 291.42 -(sample-distribution 10 (interval -2 2)) 291.43 -; Compare with a direct transformation 291.44 -(= (sample-distribution 10 (interval -2 2)) 291.45 - (map (fn [x] (- (* 4 x) 2)) (take 10 (gc/seq urng)))) 291.46 - 291.47 -; Normal distribution 291.48 -(sample-distribution 10 (normal 0 1)) 291.49 - 291.50 -; Log-Normal distribution 291.51 -(sample-distribution 10 (lognormal 0 1)) 291.52 - 291.53 -; Exponential distribution 291.54 -(sample-distribution 10 (exponential 1)) 291.55 - 291.56 -; n-sphere distribution 291.57 -(sample-distribution 10 (n-sphere 2 1)) 291.58 - 291.59 -; Discrete distribution 291.60 -(sample-distribution 10 (discrete (uniform (range 1 7)))) 291.61 - 291.62 -; Compose distributions in the state monad 291.63 -(def sum-two-dists 291.64 - (domonad state-m 291.65 - [r1 (interval -2 2) 291.66 - r2 (normal 0 1)] 291.67 - (+ r1 r2))) 291.68 - 291.69 -(sample-distribution 10 sum-two-dists) 291.70 - 291.71 -; Distribution transformations 291.72 -(sample-distribution 5 (sample 2 (interval -2 2))) 291.73 -(sample-distribution 10 (sample-sum 10 (interval -2 2))) 291.74 -(sample-distribution 10 (sample-mean 10 (interval -2 2))) 291.75 -(sample-distribution 10 (sample-mean-variance 10 (interval -2 2))) 291.76 -
292.1 --- a/src/clojure/contrib/test_contrib/stream_utils/examples.clj Sat Aug 21 06:25:44 2010 -0400 292.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 292.3 @@ -1,117 +0,0 @@ 292.4 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 292.5 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 292.6 -;; 292.7 -;; Stream application examples 292.8 -;; 292.9 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 292.10 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 292.11 - 292.12 -(ns 292.13 - #^{:author "Konrad Hinsen" 292.14 - :skip-wiki true 292.15 - :doc "Examples for data streams"} 292.16 - clojure.contrib.stream-utils.examples 292.17 - (:refer-clojure :exclude (deftype)) 292.18 - (:use [clojure.contrib.stream-utils 292.19 - :only (defst stream-next 292.20 - pick pick-all 292.21 - stream-type defstream 292.22 - stream-drop stream-map stream-filter stream-flatten)]) 292.23 - (:use [clojure.contrib.monads :only (domonad)]) 292.24 - (:use [clojure.contrib.types :only (deftype)]) 292.25 - (:require [clojure.contrib.generic.collection :as gc])) 292.26 - 292.27 -; 292.28 -; Define a stream of Fibonacci numbers 292.29 -; 292.30 -(deftype ::fib-stream last-two-fib) 292.31 - 292.32 -(defstream ::fib-stream 292.33 - [fs] 292.34 - (let [[n1 n2] fs] 292.35 - [n1 (last-two-fib [n2 (+ n1 n2)])])) 292.36 - 292.37 -(def fib-stream (last-two-fib [0 1])) 292.38 - 292.39 -(take 10 (gc/seq fib-stream)) 292.40 - 292.41 -; 292.42 -; A simple random number generator, implemented as a stream 292.43 -; 292.44 -(deftype ::random-seed rng-seed vector seq) 292.45 - 292.46 -(defstream ::random-seed 292.47 - [seed] 292.48 - (let [[seed] seed 292.49 - m 259200 292.50 - value (/ (float seed) (float m)) 292.51 - next (rem (+ 54773 (* 7141 seed)) m)] 292.52 - [value (rng-seed next)])) 292.53 - 292.54 -(take 10 (gc/seq (rng-seed 1))) 292.55 - 292.56 -; 292.57 -; Various stream utilities 292.58 -; 292.59 -(take 10 (gc/seq (stream-drop 10 (rng-seed 1)))) 292.60 -(gc/seq (stream-map inc (range 5))) 292.61 -(gc/seq (stream-filter odd? (range 10))) 292.62 -(gc/seq (stream-flatten (partition 3 (range 9)))) 292.63 - 292.64 -; 292.65 -; Stream transformers 292.66 -; 292.67 - 292.68 -; Transform a stream of numbers into a stream of sums of two 292.69 -; consecutive numbers. 292.70 -(defst sum-two [] [xs] 292.71 - (domonad 292.72 - [x1 (pick xs) 292.73 - x2 (pick xs)] 292.74 - (+ x1 x2))) 292.75 - 292.76 -(def s (sum-two '(1 2 3 4 5 6 7 8))) 292.77 - 292.78 -(let [[v1 s] (stream-next s)] 292.79 - (let [[v2 s] (stream-next s)] 292.80 - (let [[v3 s] (stream-next s)] 292.81 - (let [[v4 s] (stream-next s)] 292.82 - (let [[v5 s] (stream-next s)] 292.83 - [v1 v2 v3 v4 v5]))))) 292.84 - 292.85 -(gc/seq s) 292.86 - 292.87 -; Map (for a single stream) written as a stream transformer 292.88 -(defst my-map-1 [f] [xs] 292.89 - (domonad 292.90 - [x (pick xs)] 292.91 - (f x))) 292.92 - 292.93 -(gc/seq (my-map-1 inc [1 2 3])) 292.94 - 292.95 -; Map for two stream arguments 292.96 -(defst my-map-2 [f] [xs ys] 292.97 - (domonad 292.98 - [x (pick xs) 292.99 - y (pick ys)] 292.100 - (f x y))) 292.101 - 292.102 -(gc/seq (my-map-2 + '(1 2 3 4) '(10 20 30 40))) 292.103 - 292.104 -; Map for any number of stream arguments 292.105 -(defst my-map [f] [& streams] 292.106 - (domonad 292.107 - [vs pick-all] 292.108 - (apply f vs))) 292.109 - 292.110 -(gc/seq (my-map inc [1 2 3])) 292.111 -(gc/seq (my-map + '(1 2 3 4) '(10 20 30 40))) 292.112 - 292.113 -; Filter written as a stream transformer 292.114 -(defst my-filter [p] [xs] 292.115 - (domonad 292.116 - [x (pick xs) :when (p x)] 292.117 - x)) 292.118 - 292.119 -(gc/seq (my-filter odd? [1 2 3])) 292.120 -
293.1 --- a/src/clojure/contrib/test_contrib/test_complex_numbers.clj Sat Aug 21 06:25:44 2010 -0400 293.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 293.3 @@ -1,313 +0,0 @@ 293.4 -;; Test routines for complex-numbers.clj 293.5 - 293.6 -;; by Konrad Hinsen 293.7 -;; last updated April 2, 2009 293.8 - 293.9 -;; Copyright (c) Konrad Hinsen, 2008. All rights reserved. The use 293.10 -;; and distribution terms for this software are covered by the Eclipse 293.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 293.12 -;; which can be found in the file epl-v10.html at the root of this 293.13 -;; distribution. By using this software in any fashion, you are 293.14 -;; agreeing to be bound by the terms of this license. You must not 293.15 -;; remove this notice, or any other, from this software. 293.16 - 293.17 -(ns clojure.contrib.test-complex-numbers 293.18 - (:refer-clojure :exclude [+ - * / = < > <= >=]) 293.19 - (:use [clojure.test 293.20 - :only (deftest is are run-tests)] 293.21 - [clojure.contrib.generic.arithmetic 293.22 - :only (+ - * /)] 293.23 - [clojure.contrib.generic.comparison 293.24 - :only (= < > <= >=)] 293.25 - [clojure.contrib.generic.math-functions 293.26 - :only (abs approx= conjugate exp sqr sqrt)] 293.27 - [clojure.contrib.complex-numbers 293.28 - :only (complex imaginary real imag)])) 293.29 - 293.30 -(deftest complex-addition 293.31 - (is (= (+ (complex 1 2) (complex 1 2)) (complex 2 4))) 293.32 - (is (= (+ (complex 1 2) (complex -3 -7)) (complex -2 -5))) 293.33 - (is (= (+ (complex -3 -7) (complex 1 2)) (complex -2 -5))) 293.34 - (is (= (+ (complex 1 2) 3) (complex 4 2))) 293.35 - (is (= (+ 3 (complex 1 2)) (complex 4 2))) 293.36 - (is (= (+ (complex 1 2) -1) (imaginary 2))) 293.37 - (is (= (+ -1 (complex 1 2)) (imaginary 2))) 293.38 - (is (= (+ (complex 1 2) (imaginary -2)) 1)) 293.39 - (is (= (+ (imaginary -2) (complex 1 2)) 1)) 293.40 - (is (= (+ (complex 1 2) (imaginary 5)) (complex 1 7))) 293.41 - (is (= (+ (imaginary 5) (complex 1 2)) (complex 1 7))) 293.42 - (is (= (+ (complex -3 -7) (complex 1 2)) (complex -2 -5))) 293.43 - (is (= (+ (complex 1 2) (complex -3 -7)) (complex -2 -5))) 293.44 - (is (= (+ (complex -3 -7) (complex -3 -7)) (complex -6 -14))) 293.45 - (is (= (+ (complex -3 -7) 3) (imaginary -7))) 293.46 - (is (= (+ 3 (complex -3 -7)) (imaginary -7))) 293.47 - (is (= (+ (complex -3 -7) -1) (complex -4 -7))) 293.48 - (is (= (+ -1 (complex -3 -7)) (complex -4 -7))) 293.49 - (is (= (+ (complex -3 -7) (imaginary -2)) (complex -3 -9))) 293.50 - (is (= (+ (imaginary -2) (complex -3 -7)) (complex -3 -9))) 293.51 - (is (= (+ (complex -3 -7) (imaginary 5)) (complex -3 -2))) 293.52 - (is (= (+ (imaginary 5) (complex -3 -7)) (complex -3 -2))) 293.53 - (is (= (+ 3 (complex 1 2)) (complex 4 2))) 293.54 - (is (= (+ (complex 1 2) 3) (complex 4 2))) 293.55 - (is (= (+ 3 (complex -3 -7)) (imaginary -7))) 293.56 - (is (= (+ (complex -3 -7) 3) (imaginary -7))) 293.57 - (is (= (+ 3 (imaginary -2)) (complex 3 -2))) 293.58 - (is (= (+ (imaginary -2) 3) (complex 3 -2))) 293.59 - (is (= (+ 3 (imaginary 5)) (complex 3 5))) 293.60 - (is (= (+ (imaginary 5) 3) (complex 3 5))) 293.61 - (is (= (+ -1 (complex 1 2)) (imaginary 2))) 293.62 - (is (= (+ (complex 1 2) -1) (imaginary 2))) 293.63 - (is (= (+ -1 (complex -3 -7)) (complex -4 -7))) 293.64 - (is (= (+ (complex -3 -7) -1) (complex -4 -7))) 293.65 - (is (= (+ -1 (imaginary -2)) (complex -1 -2))) 293.66 - (is (= (+ (imaginary -2) -1) (complex -1 -2))) 293.67 - (is (= (+ -1 (imaginary 5)) (complex -1 5))) 293.68 - (is (= (+ (imaginary 5) -1) (complex -1 5))) 293.69 - (is (= (+ (imaginary -2) (complex 1 2)) 1)) 293.70 - (is (= (+ (complex 1 2) (imaginary -2)) 1)) 293.71 - (is (= (+ (imaginary -2) (complex -3 -7)) (complex -3 -9))) 293.72 - (is (= (+ (complex -3 -7) (imaginary -2)) (complex -3 -9))) 293.73 - (is (= (+ (imaginary -2) 3) (complex 3 -2))) 293.74 - (is (= (+ 3 (imaginary -2)) (complex 3 -2))) 293.75 - (is (= (+ (imaginary -2) -1) (complex -1 -2))) 293.76 - (is (= (+ -1 (imaginary -2)) (complex -1 -2))) 293.77 - (is (= (+ (imaginary -2) (imaginary -2)) (imaginary -4))) 293.78 - (is (= (+ (imaginary -2) (imaginary 5)) (imaginary 3))) 293.79 - (is (= (+ (imaginary 5) (imaginary -2)) (imaginary 3))) 293.80 - (is (= (+ (imaginary 5) (complex 1 2)) (complex 1 7))) 293.81 - (is (= (+ (complex 1 2) (imaginary 5)) (complex 1 7))) 293.82 - (is (= (+ (imaginary 5) (complex -3 -7)) (complex -3 -2))) 293.83 - (is (= (+ (complex -3 -7) (imaginary 5)) (complex -3 -2))) 293.84 - (is (= (+ (imaginary 5) 3) (complex 3 5))) 293.85 - (is (= (+ 3 (imaginary 5)) (complex 3 5))) 293.86 - (is (= (+ (imaginary 5) -1) (complex -1 5))) 293.87 - (is (= (+ -1 (imaginary 5)) (complex -1 5))) 293.88 - (is (= (+ (imaginary 5) (imaginary -2)) (imaginary 3))) 293.89 - (is (= (+ (imaginary -2) (imaginary 5)) (imaginary 3))) 293.90 - (is (= (+ (imaginary 5) (imaginary 5)) (imaginary 10)))) 293.91 - 293.92 -(deftest complex-subtraction 293.93 - (is (= (- (complex 1 2) (complex 1 2)) 0)) 293.94 - (is (= (- (complex 1 2) (complex -3 -7)) (complex 4 9))) 293.95 - (is (= (- (complex -3 -7) (complex 1 2)) (complex -4 -9))) 293.96 - (is (= (- (complex 1 2) 3) (complex -2 2))) 293.97 - (is (= (- 3 (complex 1 2)) (complex 2 -2))) 293.98 - (is (= (- (complex 1 2) -1) (complex 2 2))) 293.99 - (is (= (- -1 (complex 1 2)) (complex -2 -2))) 293.100 - (is (= (- (complex 1 2) (imaginary -2)) (complex 1 4))) 293.101 - (is (= (- (imaginary -2) (complex 1 2)) (complex -1 -4))) 293.102 - (is (= (- (complex 1 2) (imaginary 5)) (complex 1 -3))) 293.103 - (is (= (- (imaginary 5) (complex 1 2)) (complex -1 3))) 293.104 - (is (= (- (complex -3 -7) (complex 1 2)) (complex -4 -9))) 293.105 - (is (= (- (complex 1 2) (complex -3 -7)) (complex 4 9))) 293.106 - (is (= (- (complex -3 -7) (complex -3 -7)) 0)) 293.107 - (is (= (- (complex -3 -7) 3) (complex -6 -7))) 293.108 - (is (= (- 3 (complex -3 -7)) (complex 6 7))) 293.109 - (is (= (- (complex -3 -7) -1) (complex -2 -7))) 293.110 - (is (= (- -1 (complex -3 -7)) (complex 2 7))) 293.111 - (is (= (- (complex -3 -7) (imaginary -2)) (complex -3 -5))) 293.112 - (is (= (- (imaginary -2) (complex -3 -7)) (complex 3 5))) 293.113 - (is (= (- (complex -3 -7) (imaginary 5)) (complex -3 -12))) 293.114 - (is (= (- (imaginary 5) (complex -3 -7)) (complex 3 12))) 293.115 - (is (= (- 3 (complex 1 2)) (complex 2 -2))) 293.116 - (is (= (- (complex 1 2) 3) (complex -2 2))) 293.117 - (is (= (- 3 (complex -3 -7)) (complex 6 7))) 293.118 - (is (= (- (complex -3 -7) 3) (complex -6 -7))) 293.119 - (is (= (- 3 (imaginary -2)) (complex 3 2))) 293.120 - (is (= (- (imaginary -2) 3) (complex -3 -2))) 293.121 - (is (= (- 3 (imaginary 5)) (complex 3 -5))) 293.122 - (is (= (- (imaginary 5) 3) (complex -3 5))) 293.123 - (is (= (- -1 (complex 1 2)) (complex -2 -2))) 293.124 - (is (= (- (complex 1 2) -1) (complex 2 2))) 293.125 - (is (= (- -1 (complex -3 -7)) (complex 2 7))) 293.126 - (is (= (- (complex -3 -7) -1) (complex -2 -7))) 293.127 - (is (= (- -1 (imaginary -2)) (complex -1 2))) 293.128 - (is (= (- (imaginary -2) -1) (complex 1 -2))) 293.129 - (is (= (- -1 (imaginary 5)) (complex -1 -5))) 293.130 - (is (= (- (imaginary 5) -1) (complex 1 5))) 293.131 - (is (= (- (imaginary -2) (complex 1 2)) (complex -1 -4))) 293.132 - (is (= (- (complex 1 2) (imaginary -2)) (complex 1 4))) 293.133 - (is (= (- (imaginary -2) (complex -3 -7)) (complex 3 5))) 293.134 - (is (= (- (complex -3 -7) (imaginary -2)) (complex -3 -5))) 293.135 - (is (= (- (imaginary -2) 3) (complex -3 -2))) 293.136 - (is (= (- 3 (imaginary -2)) (complex 3 2))) 293.137 - (is (= (- (imaginary -2) -1) (complex 1 -2))) 293.138 - (is (= (- -1 (imaginary -2)) (complex -1 2))) 293.139 - (is (= (- (imaginary -2) (imaginary -2)) 0)) 293.140 - (is (= (- (imaginary -2) (imaginary 5)) (imaginary -7))) 293.141 - (is (= (- (imaginary 5) (imaginary -2)) (imaginary 7))) 293.142 - (is (= (- (imaginary 5) (complex 1 2)) (complex -1 3))) 293.143 - (is (= (- (complex 1 2) (imaginary 5)) (complex 1 -3))) 293.144 - (is (= (- (imaginary 5) (complex -3 -7)) (complex 3 12))) 293.145 - (is (= (- (complex -3 -7) (imaginary 5)) (complex -3 -12))) 293.146 - (is (= (- (imaginary 5) 3) (complex -3 5))) 293.147 - (is (= (- 3 (imaginary 5)) (complex 3 -5))) 293.148 - (is (= (- (imaginary 5) -1) (complex 1 5))) 293.149 - (is (= (- -1 (imaginary 5)) (complex -1 -5))) 293.150 - (is (= (- (imaginary 5) (imaginary -2)) (imaginary 7))) 293.151 - (is (= (- (imaginary -2) (imaginary 5)) (imaginary -7))) 293.152 - (is (= (- (imaginary 5) (imaginary 5)) 0))) 293.153 - 293.154 -(deftest complex-multiplication 293.155 - (is (= (* (complex 1 2) (complex 1 2)) (complex -3 4))) 293.156 - (is (= (* (complex 1 2) (complex -3 -7)) (complex 11 -13))) 293.157 - (is (= (* (complex -3 -7) (complex 1 2)) (complex 11 -13))) 293.158 - (is (= (* (complex 1 2) 3) (complex 3 6))) 293.159 - (is (= (* 3 (complex 1 2)) (complex 3 6))) 293.160 - (is (= (* (complex 1 2) -1) (complex -1 -2))) 293.161 - (is (= (* -1 (complex 1 2)) (complex -1 -2))) 293.162 - (is (= (* (complex 1 2) (imaginary -2)) (complex 4 -2))) 293.163 - (is (= (* (imaginary -2) (complex 1 2)) (complex 4 -2))) 293.164 - (is (= (* (complex 1 2) (imaginary 5)) (complex -10 5))) 293.165 - (is (= (* (imaginary 5) (complex 1 2)) (complex -10 5))) 293.166 - (is (= (* (complex -3 -7) (complex 1 2)) (complex 11 -13))) 293.167 - (is (= (* (complex 1 2) (complex -3 -7)) (complex 11 -13))) 293.168 - (is (= (* (complex -3 -7) (complex -3 -7)) (complex -40 42))) 293.169 - (is (= (* (complex -3 -7) 3) (complex -9 -21))) 293.170 - (is (= (* 3 (complex -3 -7)) (complex -9 -21))) 293.171 - (is (= (* (complex -3 -7) -1) (complex 3 7))) 293.172 - (is (= (* -1 (complex -3 -7)) (complex 3 7))) 293.173 - (is (= (* (complex -3 -7) (imaginary -2)) (complex -14 6))) 293.174 - (is (= (* (imaginary -2) (complex -3 -7)) (complex -14 6))) 293.175 - (is (= (* (complex -3 -7) (imaginary 5)) (complex 35 -15))) 293.176 - (is (= (* (imaginary 5) (complex -3 -7)) (complex 35 -15))) 293.177 - (is (= (* 3 (complex 1 2)) (complex 3 6))) 293.178 - (is (= (* (complex 1 2) 3) (complex 3 6))) 293.179 - (is (= (* 3 (complex -3 -7)) (complex -9 -21))) 293.180 - (is (= (* (complex -3 -7) 3) (complex -9 -21))) 293.181 - (is (= (* 3 (imaginary -2)) (imaginary -6))) 293.182 - (is (= (* (imaginary -2) 3) (imaginary -6))) 293.183 - (is (= (* 3 (imaginary 5)) (imaginary 15))) 293.184 - (is (= (* (imaginary 5) 3) (imaginary 15))) 293.185 - (is (= (* -1 (complex 1 2)) (complex -1 -2))) 293.186 - (is (= (* (complex 1 2) -1) (complex -1 -2))) 293.187 - (is (= (* -1 (complex -3 -7)) (complex 3 7))) 293.188 - (is (= (* (complex -3 -7) -1) (complex 3 7))) 293.189 - (is (= (* -1 (imaginary -2)) (imaginary 2))) 293.190 - (is (= (* (imaginary -2) -1) (imaginary 2))) 293.191 - (is (= (* -1 (imaginary 5)) (imaginary -5))) 293.192 - (is (= (* (imaginary 5) -1) (imaginary -5))) 293.193 - (is (= (* (imaginary -2) (complex 1 2)) (complex 4 -2))) 293.194 - (is (= (* (complex 1 2) (imaginary -2)) (complex 4 -2))) 293.195 - (is (= (* (imaginary -2) (complex -3 -7)) (complex -14 6))) 293.196 - (is (= (* (complex -3 -7) (imaginary -2)) (complex -14 6))) 293.197 - (is (= (* (imaginary -2) 3) (imaginary -6))) 293.198 - (is (= (* 3 (imaginary -2)) (imaginary -6))) 293.199 - (is (= (* (imaginary -2) -1) (imaginary 2))) 293.200 - (is (= (* -1 (imaginary -2)) (imaginary 2))) 293.201 - (is (= (* (imaginary -2) (imaginary -2)) -4)) 293.202 - (is (= (* (imaginary -2) (imaginary 5)) 10)) 293.203 - (is (= (* (imaginary 5) (imaginary -2)) 10)) 293.204 - (is (= (* (imaginary 5) (complex 1 2)) (complex -10 5))) 293.205 - (is (= (* (complex 1 2) (imaginary 5)) (complex -10 5))) 293.206 - (is (= (* (imaginary 5) (complex -3 -7)) (complex 35 -15))) 293.207 - (is (= (* (complex -3 -7) (imaginary 5)) (complex 35 -15))) 293.208 - (is (= (* (imaginary 5) 3) (imaginary 15))) 293.209 - (is (= (* 3 (imaginary 5)) (imaginary 15))) 293.210 - (is (= (* (imaginary 5) -1) (imaginary -5))) 293.211 - (is (= (* -1 (imaginary 5)) (imaginary -5))) 293.212 - (is (= (* (imaginary 5) (imaginary -2)) 10)) 293.213 - (is (= (* (imaginary -2) (imaginary 5)) 10)) 293.214 - (is (= (* (imaginary 5) (imaginary 5)) -25))) 293.215 - 293.216 -(deftest complex-division 293.217 - (is (= (/ (complex 1 2) (complex 1 2)) 1)) 293.218 - (is (= (/ (complex 1 2) (complex -3 -7)) (complex -17/58 1/58))) 293.219 - (is (= (/ (complex -3 -7) (complex 1 2)) (complex -17/5 -1/5))) 293.220 - (is (= (/ (complex 1 2) 3) (complex 1/3 2/3))) 293.221 - (is (= (/ 3 (complex 1 2)) (complex 3/5 -6/5))) 293.222 - (is (= (/ (complex 1 2) -1) (complex -1 -2))) 293.223 - (is (= (/ -1 (complex 1 2)) (complex -1/5 2/5))) 293.224 - (is (= (/ (complex 1 2) (imaginary -2)) (complex -1 1/2))) 293.225 - (is (= (/ (imaginary -2) (complex 1 2)) (complex -4/5 -2/5))) 293.226 - (is (= (/ (complex 1 2) (imaginary 5)) (complex 2/5 -1/5))) 293.227 - (is (= (/ (imaginary 5) (complex 1 2)) (complex 2 1))) 293.228 - (is (= (/ (complex -3 -7) (complex 1 2)) (complex -17/5 -1/5))) 293.229 - (is (= (/ (complex 1 2) (complex -3 -7)) (complex -17/58 1/58))) 293.230 - (is (= (/ (complex -3 -7) (complex -3 -7)) 1)) 293.231 - (is (= (/ (complex -3 -7) 3) (complex -1 -7/3))) 293.232 - (is (= (/ 3 (complex -3 -7)) (complex -9/58 21/58))) 293.233 - (is (= (/ (complex -3 -7) -1) (complex 3 7))) 293.234 - (is (= (/ -1 (complex -3 -7)) (complex 3/58 -7/58))) 293.235 - (is (= (/ (complex -3 -7) (imaginary -2)) (complex 7/2 -3/2))) 293.236 - (is (= (/ (imaginary -2) (complex -3 -7)) (complex 7/29 3/29))) 293.237 - (is (= (/ (complex -3 -7) (imaginary 5)) (complex -7/5 3/5))) 293.238 - (is (= (/ (imaginary 5) (complex -3 -7)) (complex -35/58 -15/58))) 293.239 - (is (= (/ 3 (complex 1 2)) (complex 3/5 -6/5))) 293.240 - (is (= (/ (complex 1 2) 3) (complex 1/3 2/3))) 293.241 - (is (= (/ 3 (complex -3 -7)) (complex -9/58 21/58))) 293.242 - (is (= (/ (complex -3 -7) 3) (complex -1 -7/3))) 293.243 - #_(is (= (/ 3 (imaginary -2)) (imaginary 1.5))) 293.244 - (is (= (/ (imaginary -2) 3) (imaginary -2/3))) 293.245 - (is (= (/ 3 (imaginary 5)) (imaginary -3/5))) 293.246 - (is (= (/ (imaginary 5) 3) (imaginary 5/3))) 293.247 - (is (= (/ -1 (complex 1 2)) (complex -1/5 2/5))) 293.248 - (is (= (/ (complex 1 2) -1) (complex -1 -2))) 293.249 - (is (= (/ -1 (complex -3 -7)) (complex 3/58 -7/58))) 293.250 - (is (= (/ (complex -3 -7) -1) (complex 3 7))) 293.251 - (is (= (/ -1 (imaginary -2)) (imaginary -1/2))) 293.252 - (is (= (/ (imaginary -2) -1) (imaginary 2))) 293.253 - (is (= (/ -1 (imaginary 5)) (imaginary 1/5))) 293.254 - (is (= (/ (imaginary 5) -1) (imaginary -5))) 293.255 - (is (= (/ (imaginary -2) (complex 1 2)) (complex -4/5 -2/5))) 293.256 - (is (= (/ (complex 1 2) (imaginary -2)) (complex -1 1/2))) 293.257 - (is (= (/ (imaginary -2) (complex -3 -7)) (complex 7/29 3/29))) 293.258 - (is (= (/ (complex -3 -7) (imaginary -2)) (complex 7/2 -3/2))) 293.259 - (is (= (/ (imaginary -2) 3) (imaginary -2/3))) 293.260 - (is (= (/ 3 (imaginary -2)) (imaginary 3/2))) 293.261 - (is (= (/ (imaginary -2) -1) (imaginary 2))) 293.262 - (is (= (/ -1 (imaginary -2)) (imaginary -1/2))) 293.263 - (is (= (/ (imaginary -2) (imaginary -2)) 1)) 293.264 - (is (= (/ (imaginary -2) (imaginary 5)) -2/5)) 293.265 - (is (= (/ (imaginary 5) (imaginary -2)) -5/2)) 293.266 - (is (= (/ (imaginary 5) (complex 1 2)) (complex 2 1))) 293.267 - (is (= (/ (complex 1 2) (imaginary 5)) (complex 2/5 -1/5))) 293.268 - (is (= (/ (imaginary 5) (complex -3 -7)) (complex -35/58 -15/58))) 293.269 - (is (= (/ (complex -3 -7) (imaginary 5)) (complex -7/5 3/5))) 293.270 - (is (= (/ (imaginary 5) 3) (imaginary 5/3))) 293.271 - (is (= (/ 3 (imaginary 5)) (imaginary -3/5))) 293.272 - (is (= (/ (imaginary 5) -1) (imaginary -5))) 293.273 - (is (= (/ -1 (imaginary 5)) (imaginary 1/5))) 293.274 - (is (= (/ (imaginary 5) (imaginary -2)) -5/2)) 293.275 - (is (= (/ (imaginary -2) (imaginary 5)) -2/5)) 293.276 - (is (= (/ (imaginary 5) (imaginary 5)) 1))) 293.277 - 293.278 -(deftest complex-conjugate 293.279 - (is (= (conjugate (complex 1 2)) (complex 1 -2))) 293.280 - (is (= (conjugate (complex -3 -7)) (complex -3 7))) 293.281 - (is (= (conjugate (imaginary -2)) (imaginary 2))) 293.282 - (is (= (conjugate (imaginary 5)) (imaginary -5)))) 293.283 - 293.284 -(deftest complex-abs 293.285 - (doseq [c [(complex 1 2) (complex -2 3) (complex 4 -2) 293.286 - (complex -3 -7) (imaginary -2) (imaginary 5)]] 293.287 - (is (approx= (* c (conjugate c)) 293.288 - (sqr (abs c)) 293.289 - 1e-14)))) 293.290 - 293.291 -(deftest complex-sqrt 293.292 - (doseq [c [(complex 1 2) (complex -2 3) (complex 4 -2) 293.293 - (complex -3 -7) (imaginary -2) (imaginary 5)]] 293.294 - (let [r (sqrt c)] 293.295 - (is (approx= c (sqr r) 1e-14)) 293.296 - (is (>= (real r) 0))))) 293.297 - 293.298 -(deftest complex-exp 293.299 - (is (approx= (exp (complex 1 2)) 293.300 - (complex -1.1312043837568135 2.4717266720048188) 293.301 - 1e-14)) 293.302 - (is (approx= (exp (complex 2 3)) 293.303 - (complex -7.3151100949011028 1.0427436562359045) 293.304 - 1e-14)) 293.305 - (is (approx= (exp (complex 4 -2)) 293.306 - (complex -22.720847417619233 -49.645957334580565) 293.307 - 1e-14)) 293.308 - (is (approx= (exp (complex 3 -7)) 293.309 - (complex 15.142531566086868 -13.195928586605717) 293.310 - 1e-14)) 293.311 - (is (approx= (exp (imaginary -2)) 293.312 - (complex -0.41614683654714241 -0.90929742682568171) 293.313 - 1e-14)) 293.314 - (is (approx= (exp (imaginary 5)) 293.315 - (complex 0.2836621854632263 -0.95892427466313845) 293.316 - 1e-14)))
294.1 --- a/src/clojure/contrib/test_contrib/test_core.clj Sat Aug 21 06:25:44 2010 -0400 294.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 294.3 @@ -1,42 +0,0 @@ 294.4 -; Copyright (c) Laurent Petit, March 2009. All rights reserved. 294.5 - 294.6 -; The use and distribution terms for this software are covered by the 294.7 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 294.8 -; which can be found in the file epl-v10.html at the root of this 294.9 -; distribution. 294.10 -; By using this software in any fashion, you are agreeing to be bound by 294.11 -; the terms of this license. 294.12 -; You must not remove this notice, or any other, from this software. 294.13 - 294.14 -;; test namespace for clojure.contrib.core 294.15 - 294.16 -;; note to other contrib members: feel free to add to this lib 294.17 - 294.18 -(ns clojure.contrib.test-core 294.19 - (:use clojure.test) 294.20 - (:use clojure.contrib.core)) 294.21 - 294.22 -(deftest test-classic-versions 294.23 - (testing "Classic -> throws NPE if passed nil" 294.24 - (is (thrown? NullPointerException (-> nil .toString))) 294.25 - (is (thrown? NullPointerException (-> "foo" seq next next next .toString)))) 294.26 - (testing "Classic .. throws NPE if one of the intermediate threaded values is nil" 294.27 - (is (thrown? NullPointerException (.. nil toString))) 294.28 - (is (thrown? NullPointerException (.. [nil] (get 0) toString))))) 294.29 - 294.30 -(deftest test-new-versions 294.31 - (testing "Version -?>> falls out on nil" 294.32 - (is (nil? (-?>> nil .toString))) 294.33 - (is (nil? (-?>> [] seq (map inc)))) 294.34 - (is (= [] (->> [] seq (map inc))))) 294.35 - (testing "Version -?>> completes for non-nil" 294.36 - (is (= [3 4] (-?>> [1 2] (map inc) (map inc))))) 294.37 - (testing "Version -?> falls out on nil" 294.38 - (is (nil? (-?> nil .toString))) 294.39 - (is (nil? (-?> "foo" seq next next next .toString)))) 294.40 - (testing "Version -?> completes for non-nil" 294.41 - (is (= [\O \O] (-?> "foo" .toUpperCase rest)))) 294.42 - (testing "Version .?. returns nil if one of the intermediate threaded values is nil" 294.43 - (is (nil? (.?. nil toString))) 294.44 - (is (nil? (.?. [nil] (get 0) toString))))) 294.45 -
295.1 --- a/src/clojure/contrib/test_contrib/test_dataflow.clj Sat Aug 21 06:25:44 2010 -0400 295.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 295.3 @@ -1,90 +0,0 @@ 295.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 295.5 -;; distribution terms for this software are covered by the Eclipse Public 295.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 295.7 -;; be found in the file epl-v10.html at the root of this distribution. By 295.8 -;; using this software in any fashion, you are agreeing to be bound by the 295.9 -;; terms of this license. You must not remove this notice, or any other, 295.10 -;; from this software. 295.11 -;; 295.12 -;; test-dataflow 295.13 -;; 295.14 -;; A Library to Support a Dataflow Model of State - Tests 295.15 -;; 295.16 -;; straszheimjeffrey (gmail) 295.17 -;; Created 11 March 2009 295.18 - 295.19 - 295.20 -(ns clojure.contrib.test-dataflow 295.21 - (:use clojure.test) 295.22 - (:use clojure.contrib.dataflow)) 295.23 - 295.24 -(def df-1 295.25 - (build-dataflow 295.26 - [(cell :source base 0) 295.27 - (cell :source items ()) 295.28 - (cell product (* ?base (apply + ?items))) 295.29 - (cell :validator (when (number? ?-product) 295.30 - (assert (>= ?product ?-product))))])) 295.31 - 295.32 -(deftest test-df-1 295.33 - (is (= (get-value df-1 'product) 0)) 295.34 - (is (do (update-values df-1 {'items [4 5]}) 295.35 - (= (get-value df-1 'product) 0))) 295.36 - (is (do (update-values df-1 {'base 2}) 295.37 - (= (get-value df-1 'product) 18))) 295.38 - (is (thrown? AssertionError (update-values df-1 {'base 0}))) 295.39 - (is (= (get-value df-1 'product) 18))) 295.40 - 295.41 -(def df-2 295.42 - (build-dataflow 295.43 - [(cell :source strength 10) 295.44 - (cell :source agility 10) 295.45 - (cell :source magic 10) 295.46 - 295.47 - (cell total-cost (apply + ?*cost)) 295.48 - 295.49 - (cell cost (- ?strength 10)) 295.50 - (cell cost (- ?agility 10)) 295.51 - (cell cost (- ?magic 10)) 295.52 - 295.53 - (cell combat (+ ?strength ?agility ?combat-mod)) 295.54 - (cell speed (+ ?agility (/ ?strength 10.0) ?speed-mod)) 295.55 - (cell casting (+ ?agility ?magic ?magic-mod)) 295.56 - 295.57 - (cell combat-mod (apply + ?*combat-mods)) 295.58 - (cell speed-mod (apply + ?*speed-mods)) 295.59 - (cell magic-mod (apply + ?*magic-mods))])) 295.60 - 295.61 -(def magic-skill 295.62 - [(cell cost 5) 295.63 - (cell speed-mods 1) 295.64 - (cell magic-mods 2)]) 295.65 - 295.66 -(defn gv [n] (get-value df-2 n)) 295.67 - 295.68 -(deftest test-df-2 295.69 - (is (and (= (gv 'total-cost) 0) 295.70 - (= (gv 'strength) 10) 295.71 - (= (gv 'casting) 20))) 295.72 - (is (do (update-values df-2 {'magic 12}) 295.73 - (and (= (gv 'total-cost) 2) 295.74 - (= (gv 'casting) 22)))) 295.75 - (is (do (add-cells df-2 magic-skill) 295.76 - (and (= (gv 'total-cost) 7) 295.77 - (= (gv 'casting) 24)))) 295.78 - (is (do (remove-cells df-2 magic-skill) 295.79 - (and (= (gv 'total-cost) 2) 295.80 - (= (gv 'casting) 22))))) 295.81 - 295.82 - 295.83 -(comment 295.84 - (run-tests) 295.85 - 295.86 - (use :reload 'clojure.contrib.dataflow) 295.87 - (use 'clojure.contrib.stacktrace) (e) 295.88 - (use 'clojure.contrib.trace) 295.89 - 295.90 -) 295.91 - 295.92 - 295.93 -;; End of file
296.1 --- a/src/clojure/contrib/test_contrib/test_def.clj Sat Aug 21 06:25:44 2010 -0400 296.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 296.3 @@ -1,27 +0,0 @@ 296.4 -;; Tests for def.clj 296.5 - 296.6 -;; by Stuart Halloway 296.7 - 296.8 -;; Copyright (c) Stuart Halloway, 2009. All rights reserved. The use 296.9 -;; and distribution terms for this software are covered by the Eclipse 296.10 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 296.11 -;; which can be found in the file epl-v10.html at the root of this 296.12 -;; distribution. By using this software in any fashion, you are 296.13 -;; agreeing to be bound by the terms of this license. You must not 296.14 -;; remove this notice, or any other, from this software. 296.15 - 296.16 -(ns clojure.contrib.test-def 296.17 - (:use clojure.test) 296.18 - (:require [clojure.contrib.def :as d])) 296.19 - 296.20 -(defn sample-fn "sample-fn docstring" []) 296.21 -(d/defalias aliased-fn sample-fn) 296.22 -(defmacro sample-macro "sample-macro-docstring" []) 296.23 -(d/defalias aliased-macro sample-macro) 296.24 - 296.25 -(deftest defalias-preserves-metadata 296.26 - (let [preserved-meta #(-> % (meta) (select-keys [:doc :arglists :ns :file :macro]))] 296.27 - (are [x y] (= (preserved-meta (var x)) (preserved-meta (var y))) 296.28 - aliased-fn sample-fn 296.29 - aliased-macro sample-macro))) 296.30 -
297.1 --- a/src/clojure/contrib/test_contrib/test_fnmap.clj Sat Aug 21 06:25:44 2010 -0400 297.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 297.3 @@ -1,39 +0,0 @@ 297.4 -(ns clojure.contrib.test-fnmap 297.5 - (:use clojure.contrib.fnmap 297.6 - clojure.test)) 297.7 - 297.8 -(deftest acts-like-map 297.9 - (let [m1 (fnmap get assoc :key1 1 :key2 2)] 297.10 - (are [k v] (= v (get m1 k)) 297.11 - :key1 1 297.12 - :key2 2 297.13 - :nonexistent-key nil) 297.14 - (are [k v] (= v (k m1)) 297.15 - :key1 1 297.16 - :key2 2 297.17 - :nonexistent-key nil) 297.18 - (let [m2 (assoc m1 :key3 3 :key4 4)] 297.19 - (are [k v] (= v (get m2 k)) 297.20 - :key1 1 297.21 - :key2 2 297.22 - :key3 3 297.23 - :key4 4 297.24 - :nonexistent-key nil)))) 297.25 - 297.26 -(defn assoc-validate [m key value] 297.27 - (if (integer? value) 297.28 - (assoc m key value) 297.29 - (throw (Exception. "Only integers allowed in this map!")))) 297.30 - 297.31 -(deftest validators 297.32 - (let [m (fnmap get assoc-validate)] 297.33 - (is (= 2 (:key2 (assoc m :key2 2)))) 297.34 - (is (thrown? Exception (assoc m :key3 3.14))))) 297.35 - 297.36 -(defn get-transform [m key] 297.37 - (when-let [value (m key)] 297.38 - (- value))) 297.39 - 297.40 -(deftest transforms 297.41 - (let [m (fnmap get-transform assoc)] 297.42 - (is (= -2 (:key2 (assoc m :key2 2))))))
298.1 --- a/src/clojure/contrib/test_contrib/test_graph.clj Sat Aug 21 06:25:44 2010 -0400 298.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 298.3 @@ -1,187 +0,0 @@ 298.4 -;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and 298.5 -;; distribution terms for this software are covered by the Eclipse Public 298.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 298.7 -;; be found in the file epl-v10.html at the root of this distribution. By 298.8 -;; using this software in any fashion, you are agreeing to be bound by the 298.9 -;; terms of this license. You must not remove this notice, or any other, 298.10 -;; from this software. 298.11 -;; 298.12 -;; test-graph 298.13 -;; 298.14 -;; Basic Graph Theory Algorithms Tests 298.15 -;; 298.16 -;; straszheimjeffrey (gmail) 298.17 -;; Created 23 June 2009 298.18 - 298.19 -(ns clojure.contrib.test-graph 298.20 - (use clojure.test 298.21 - clojure.contrib.graph)) 298.22 - 298.23 - 298.24 -(def empty-graph (struct directed-graph #{} {})) 298.25 - 298.26 -(def test-graph-1 298.27 - (struct directed-graph 298.28 - #{:a :b :c :d :e} 298.29 - {:a #{:b :c} 298.30 - :b #{:a :c} 298.31 - :c #{:d :e} 298.32 - :d #{:a :b} 298.33 - :e #{:d}})) 298.34 - 298.35 -(deftest test-reverse-graph 298.36 - (is (= (reverse-graph test-graph-1) 298.37 - (struct directed-graph 298.38 - #{:a :b :c :d :e} 298.39 - {:c #{:b :a} 298.40 - :e #{:c} 298.41 - :d #{:c :e} 298.42 - :b #{:d :a} 298.43 - :a #{:d :b}}))) 298.44 - (is (= (reverse-graph (reverse-graph test-graph-1)) 298.45 - test-graph-1)) 298.46 - (is (= (reverse-graph empty-graph) empty-graph))) 298.47 - 298.48 -(deftest test-add-loops 298.49 - (let [tg1 (add-loops test-graph-1)] 298.50 - (is (every? (fn [n] (contains? (get-neighbors tg1 n) n)) (:nodes tg1)))) 298.51 - (is (= (add-loops empty-graph) empty-graph))) 298.52 - 298.53 -(deftest test-remove-loops 298.54 - (let [tg1 (remove-loops (add-loops test-graph-1))] 298.55 - (is (not-any? (fn [n] (contains? (get-neighbors tg1 n) n)) (:nodes tg1)))) 298.56 - (is (= (remove-loops empty-graph) empty-graph))) 298.57 - 298.58 - 298.59 -(def test-graph-2 298.60 - (struct directed-graph 298.61 - #{:a :b :c :d :e :f :g :h :i :j} 298.62 - {:a #{:b :c} 298.63 - :b #{:a :c} 298.64 - :c #{:d :e} 298.65 - :d #{:a :b} 298.66 - :e #{:d} 298.67 - :f #{:f} 298.68 - :g #{:a :f} 298.69 - :h #{} 298.70 - :i #{:j} 298.71 - :j #{:i}})) 298.72 - 298.73 - 298.74 -(deftest test-lazy-walk 298.75 - (is (= (lazy-walk test-graph-2 :h) [:h])) 298.76 - (is (= (lazy-walk test-graph-2 :j) [:j :i]))) 298.77 - 298.78 -(deftest test-transitive-closure 298.79 - (let [tc-1 (transitive-closure test-graph-1) 298.80 - tc-2 (transitive-closure test-graph-2) 298.81 - get (fn [n] (set (get-neighbors tc-2 n)))] 298.82 - (is (every? #(= #{:a :b :c :d :e} (set %)) 298.83 - (map (partial get-neighbors tc-1) (:nodes tc-1)))) 298.84 - (is (= (get :a) #{:a :b :c :d :e})) 298.85 - (is (= (get :h) #{})) 298.86 - (is (= (get :j) #{:i :j})) 298.87 - (is (= (get :g) #{:a :b :c :d :e :f})))) 298.88 - 298.89 - 298.90 -(deftest test-post-ordered-nodes 298.91 - (is (= (set (post-ordered-nodes test-graph-2)) 298.92 - #{:a :b :c :d :e :f :g :h :i :j})) 298.93 - (is (empty? (post-ordered-nodes empty-graph)))) 298.94 - 298.95 - 298.96 -(deftest test-scc 298.97 - (is (= (set (scc test-graph-2)) 298.98 - #{#{:h} #{:g} #{:i :j} #{:b :c :a :d :e} #{:f}})) 298.99 - (is (empty? (scc empty-graph)))) 298.100 - 298.101 -(deftest test-component-graph 298.102 - (let [cg (component-graph test-graph-2) 298.103 - ecg (component-graph empty-graph)] 298.104 - (is (= (:nodes cg) (set (scc test-graph-2)))) 298.105 - (is (= (get-neighbors cg #{:a :b :c :d :e}) 298.106 - #{#{:a :b :c :d :e}})) 298.107 - (is (= (get-neighbors cg #{:g}) 298.108 - #{#{:a :b :c :d :e} #{:f}})) 298.109 - (is (= (get-neighbors cg #{:i :j}) 298.110 - #{#{:i :j}})) 298.111 - (is (= (get-neighbors cg #{:h}) 298.112 - #{})) 298.113 - (is (= (apply max (map count (self-recursive-sets cg))) 1)) 298.114 - (is (= ecg empty-graph)))) 298.115 - 298.116 - 298.117 -(deftest test-recursive-component? 298.118 - (let [sccs (scc test-graph-2)] 298.119 - (is (= (set (filter (partial recursive-component? test-graph-2) sccs)) 298.120 - #{#{:i :j} #{:b :c :a :d :e} #{:f}})))) 298.121 - 298.122 - 298.123 -(deftest test-self-recursive-sets 298.124 - (is (= (set (self-recursive-sets test-graph-2)) 298.125 - (set (filter 298.126 - (partial recursive-component? test-graph-2) 298.127 - (scc test-graph-2))))) 298.128 - (is (empty? (self-recursive-sets empty-graph)))) 298.129 - 298.130 - 298.131 -(def test-graph-3 298.132 - (struct directed-graph 298.133 - #{:a :b :c :d :e :f} 298.134 - {:a #{:b} 298.135 - :b #{:c} 298.136 - :c #{:d} 298.137 - :d #{:e} 298.138 - :e #{:f} 298.139 - :f #{}})) 298.140 - 298.141 -(def test-graph-4 298.142 - (struct directed-graph 298.143 - #{:a :b :c :d :e :f :g :h} 298.144 - {:a #{} 298.145 - :b #{:a} 298.146 - :c #{:a} 298.147 - :d #{:a :b} 298.148 - :e #{:d :c} 298.149 - :f #{:e} 298.150 - :g #{:d} 298.151 - :h #{:f}})) 298.152 - 298.153 -(def test-graph-5 298.154 - (struct directed-graph 298.155 - #{:a :b :c :d :e :f :g :h} 298.156 - {:a #{} 298.157 - :b #{} 298.158 - :c #{:b} 298.159 - :d #{} 298.160 - :e #{} 298.161 - :f #{} 298.162 - :g #{:f} 298.163 - :h #{}})) 298.164 - 298.165 -(deftest test-dependency-list 298.166 - (is (thrown-with-msg? Exception #".*Fixed point overflow.*" 298.167 - (dependency-list test-graph-2))) 298.168 - (is (= (dependency-list test-graph-3) 298.169 - [#{:f} #{:e} #{:d} #{:c} #{:b} #{:a}])) 298.170 - (is (= (dependency-list test-graph-4) 298.171 - [#{:a} #{:b :c} #{:d} #{:g :e} #{:f} #{:h}])) 298.172 - (is (= (dependency-list test-graph-5) 298.173 - [#{:f :b :a :d :h :e} #{:g :c}])) 298.174 - (is (= (dependency-list empty-graph) 298.175 - [#{}]))) 298.176 - 298.177 -(deftest test-stratification-list 298.178 - (is (thrown-with-msg? Exception #".*Fixed point overflow.*" 298.179 - (stratification-list test-graph-2 test-graph-2))) 298.180 - (is (= (stratification-list test-graph-4 test-graph-5) 298.181 - [#{:a} #{:b :c} #{:d} #{:e} #{:f :g} #{:h}])) 298.182 - (is (= (stratification-list empty-graph empty-graph) 298.183 - [#{}]))) 298.184 - 298.185 -(comment 298.186 - (run-tests) 298.187 -) 298.188 - 298.189 - 298.190 -;; End of file
299.1 --- a/src/clojure/contrib/test_contrib/test_greatest_least.clj Sat Aug 21 06:25:44 2010 -0400 299.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 299.3 @@ -1,65 +0,0 @@ 299.4 -(ns clojure.contrib.test-greatest-least 299.5 - (:use clojure.contrib.greatest-least 299.6 - [clojure.test :only (is deftest run-tests)])) 299.7 - 299.8 -(deftest test-greatest 299.9 - (is (nil? (greatest)) "greatest with no arguments is nil") 299.10 - (is (= 1 (greatest 1))) 299.11 - (is (= 2 (greatest 1 2))) 299.12 - (is (= 2 (greatest 2 1))) 299.13 - (is (= "b" (greatest "aa" "b")))) 299.14 - 299.15 -(deftest test-greatest-by 299.16 - (is (nil? (greatest-by identity)) "greatest-by with no arguments is nil") 299.17 - (is (= "" (greatest-by count ""))) 299.18 - (is (= "a" (greatest-by count "a" ""))) 299.19 - (is (= "a" (greatest-by count "" "a"))) 299.20 - (is (= "aa" (greatest-by count "aa" "b")))) 299.21 - 299.22 -(deftest test-least 299.23 - (is (nil? (least)) "least with no arguments is nil") 299.24 - (is (= 1 (least 1))) 299.25 - (is (= 1 (least 1 2))) 299.26 - (is (= 1 (least 2 1))) 299.27 - (is (= "aa" (least "aa" "b")))) 299.28 - 299.29 -(deftest test-least-by 299.30 - (is (nil? (least-by identity)) "least-by with no arguments is nil") 299.31 - (is (= "" (least-by count ""))) 299.32 - (is (= "" (least-by count "a" ""))) 299.33 - (is (= "" (least-by count "" "a"))) 299.34 - (is (= "b" (least-by count "aa" "b")))) 299.35 - 299.36 -(deftest test-all-greatest 299.37 - (is (nil? (all-greatest)) "all-greatest with no arguments is nil") 299.38 - (is (= (list 1) (all-greatest 1))) 299.39 - (is (= (list 1 1) (all-greatest 1 1))) 299.40 - (is (= (list 2) (all-greatest 2 1 1))) 299.41 - (is (= (list 2) (all-greatest 1 2 1))) 299.42 - (is (= (list 2) (all-greatest 1 1 2))) 299.43 - (is (= (list :c) (all-greatest :b :c :a)))) 299.44 - 299.45 -(deftest test-all-greatest-by 299.46 - (is (nil? (all-greatest-by identity)) "all-greatest-by with no arguments is nil") 299.47 - (is (= (list "a")) (all-greatest-by count "a")) 299.48 - (is (= (list "a" "a")) (all-greatest-by count "a" "a")) 299.49 - (is (= (list "aa")) (all-greatest-by count "aa" "b")) 299.50 - (is (= (list "aa")) (all-greatest-by count "b" "aa" "c")) 299.51 - (is (= (list "cc" "aa")) (all-greatest-by count "aa" "b" "cc"))) 299.52 - 299.53 -(deftest test-all-least 299.54 - (is (nil? (all-least)) "all-least with no arguments is nil") 299.55 - (is (= (list 1) (all-least 1))) 299.56 - (is (= (list 1 1) (all-least 1 1))) 299.57 - (is (= (list 1 1) (all-least 2 1 1))) 299.58 - (is (= (list 1 1) (all-least 1 2 1))) 299.59 - (is (= (list 1 1) (all-least 1 1 2))) 299.60 - (is (= (list :a) (all-least :b :c :a)))) 299.61 - 299.62 -(deftest test-all-least-by 299.63 - (is (nil? (all-least-by identity)) "all-least-by with no arguments is nil") 299.64 - (is (= (list "a")) (all-least-by count "a")) 299.65 - (is (= (list "a" "a")) (all-least-by count "a" "a")) 299.66 - (is (= (list "b")) (all-least-by count "aa" "b")) 299.67 - (is (= (list "c" "b")) (all-least-by count "b" "aa" "c")) 299.68 - (is (= (list "b")) (all-least-by count "aa" "b" "cc")))
300.1 --- a/src/clojure/contrib/test_contrib/test_io.clj Sat Aug 21 06:25:44 2010 -0400 300.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 300.3 @@ -1,96 +0,0 @@ 300.4 -(ns clojure.contrib.test-io 300.5 - (:refer-clojure :exclude (spit)) 300.6 - (:use clojure.test clojure.contrib.io) 300.7 - (:import (java.io File FileInputStream BufferedInputStream) 300.8 - (java.net URL URI))) 300.9 - 300.10 -(deftest file-str-backslash 300.11 - (is (= (java.io.File. 300.12 - (str "C:" java.io.File/separator 300.13 - "Documents" java.io.File/separator 300.14 - "file.txt")) 300.15 - (file-str "C:\\Documents\\file.txt")))) 300.16 - 300.17 -(deftest test-as-file 300.18 - (testing "strings" 300.19 - (is (= (File. "foo") (as-file "foo")))) 300.20 - (testing "Files" 300.21 - (is (= (File. "bar") (as-file (File. "bar")))))) 300.22 - 300.23 -(deftest test-as-url 300.24 - (are [result expr] (= result expr) 300.25 - (URL. "http://foo") (as-url (URL. "http://foo")) 300.26 - (URL. "http://foo") (as-url "http://foo") 300.27 - (URL. "http://foo") (as-url (URI. "http://foo")) 300.28 - (URL. "file:/foo") (as-url (File. "/foo")))) 300.29 - 300.30 -(deftest test-delete-file 300.31 - (let [file (File/createTempFile "test" "deletion") 300.32 - not-file (File. (str (java.util.UUID/randomUUID)))] 300.33 - (delete-file (.getAbsolutePath file)) 300.34 - (is (not (.exists file))) 300.35 - (is (thrown? ArithmeticException (/ 1 0))) 300.36 - (is (thrown? java.io.IOException (delete-file not-file))) 300.37 - (is (delete-file not-file :silently)))) 300.38 - 300.39 -(deftest test-relative-path-string 300.40 - (testing "strings" 300.41 - (is (= "foo" (relative-path-string "foo")))) 300.42 - (testing "absolute path strings are forbidden" 300.43 - (is (thrown? IllegalArgumentException (relative-path-string (str File/separator "baz"))))) 300.44 - (testing "relative File paths" 300.45 - (is (= "bar" (relative-path-string (File. "bar"))))) 300.46 - (testing "absolute File paths are forbidden" 300.47 - (is (thrown? IllegalArgumentException (relative-path-string (File. (str File/separator "quux"))))))) 300.48 - 300.49 -(defn stream-should-have [stream expected-bytes msg] 300.50 - (let [actual-bytes (byte-array (alength expected-bytes))] 300.51 - (.read stream actual-bytes) 300.52 - (is (= -1 (.read stream)) (str msg " : should be end of stream")) 300.53 - (is (= (seq expected-bytes) (seq actual-bytes)) (str msg " : byte arrays should match")))) 300.54 - 300.55 -(deftest test-input-stream 300.56 - (let [file (File/createTempFile "test-input-stream" "txt") 300.57 - bytes (.getBytes "foobar")] 300.58 - (spit file "foobar") 300.59 - (doseq [[expr msg] 300.60 - [[file File] 300.61 - [(FileInputStream. file) FileInputStream] 300.62 - [(BufferedInputStream. (FileInputStream. file)) BufferedInputStream] 300.63 - [(.. file toURI) URI] 300.64 - [(.. file toURI toURL) URL] 300.65 - [(.. file toURI toURL toString) "URL as String"] 300.66 - [(.. file toString) "File as String"]]] 300.67 - (with-open [s (input-stream expr)] 300.68 - (stream-should-have s bytes msg))))) 300.69 - 300.70 -(deftest test-streams-buffering 300.71 - (let [data (.getBytes "")] 300.72 - (is (instance? java.io.BufferedReader (reader data))) 300.73 - (is (instance? java.io.BufferedWriter (writer (java.io.ByteArrayOutputStream.)))) 300.74 - (is (instance? java.io.BufferedInputStream (input-stream data))) 300.75 - (is (instance? java.io.BufferedOutputStream (output-stream (java.io.ByteArrayOutputStream.)))))) 300.76 - 300.77 -(deftest test-streams-defaults 300.78 - (let [f (File/createTempFile "clojure.contrib" "test-reader-writer") 300.79 - content "test\u2099ing"] 300.80 - (try 300.81 - (is (thrown? Exception (reader (Object.)))) 300.82 - (is (thrown? Exception (writer (Object.)))) 300.83 - 300.84 - (are [write-to read-from] (= content (do 300.85 - (spit write-to content) 300.86 - (slurp* (or read-from write-to)))) 300.87 - f nil 300.88 - (.getAbsolutePath f) nil 300.89 - (.toURL f) nil 300.90 - (.toURI f) nil 300.91 - (java.io.FileOutputStream. f) f 300.92 - (java.io.OutputStreamWriter. (java.io.FileOutputStream. f) "UTF-8") f 300.93 - f (java.io.FileInputStream. f) 300.94 - f (java.io.InputStreamReader. (java.io.FileInputStream. f) "UTF-8")) 300.95 - 300.96 - (is (= content (slurp* (.getBytes content "UTF-8")))) 300.97 - (is (= content (slurp* (.toCharArray content)))) 300.98 - (finally 300.99 - (.delete f)))))
301.1 --- a/src/clojure/contrib/test_contrib/test_jmx.clj Sat Aug 21 06:25:44 2010 -0400 301.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 301.3 @@ -1,178 +0,0 @@ 301.4 -;; Tests for JMX support for Clojure (see also clojure/contrib/jmx.clj) 301.5 - 301.6 -;; by Stuart Halloway 301.7 - 301.8 -;; Copyright (c) Stuart Halloway, 2009. All rights reserved. The use 301.9 -;; and distribution terms for this software are covered by the Eclipse 301.10 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 301.11 -;; which can be found in the file epl-v10.html at the root of this 301.12 -;; distribution. By using this software in any fashion, you are 301.13 -;; agreeing to be bound by the terms of this license. You must not 301.14 -;; remove this notice, or any other, from this software. 301.15 - 301.16 -(ns clojure.contrib.test-jmx 301.17 - (:import javax.management.openmbean.CompositeDataSupport 301.18 - [javax.management MBeanAttributeInfo AttributeList] 301.19 - [java.util.logging LogManager Logger] 301.20 - clojure.contrib.jmx.Bean) 301.21 - (:use clojure.test) 301.22 - (:require [clojure.contrib [jmx :as jmx]])) 301.23 - 301.24 - 301.25 -(defn =set [a b] 301.26 - (= (set a) (set b))) 301.27 - 301.28 -(defn seq-contains-all? 301.29 - "Does container contain every item in containee? 301.30 - Not fast. Testing use only" 301.31 - [container containee] 301.32 - (let [container (set container)] 301.33 - (every? #(contains? container %) containee))) 301.34 - 301.35 -(deftest finding-mbeans 301.36 - (testing "as-object-name" 301.37 - (are [cname object-name] 301.38 - (= cname (.getCanonicalName object-name)) 301.39 - "java.lang:type=Memory" (jmx/as-object-name "java.lang:type=Memory"))) 301.40 - (testing "mbean-names" 301.41 - (are [cnames object-name] 301.42 - (= cnames (map #(.getCanonicalName %) object-name)) 301.43 - ["java.lang:type=Memory"] (jmx/mbean-names "java.lang:type=Memory")))) 301.44 - 301.45 -; These actual beans may differ on different JVM platforms. 301.46 -; Tested April 2010 to work on Sun and IBM JDKs. 301.47 -(deftest testing-actual-beans 301.48 - (testing "reflecting on capabilities" 301.49 - (are [attr-list mbean-name] 301.50 - (seq-contains-all? (jmx/attribute-names mbean-name) attr-list) 301.51 - [:Verbose :ObjectPendingFinalizationCount :HeapMemoryUsage :NonHeapMemoryUsage] "java.lang:type=Memory") 301.52 - (are [op-list mbean-name] 301.53 - (seq-contains-all? (jmx/operation-names mbean-name) op-list) 301.54 - [:gc] "java.lang:type=Memory")) 301.55 - (testing "mbean-from-oname" 301.56 - (are [key-names oname] 301.57 - (seq-contains-all? (keys (jmx/mbean oname)) key-names) 301.58 - [:Verbose :ObjectPendingFinalizationCount :HeapMemoryUsage :NonHeapMemoryUsage] "java.lang:type=Memory"))) 301.59 - 301.60 -(deftest raw-reading-attributes 301.61 - (let [mem "java.lang:type=Memory" 301.62 - log "java.util.logging:type=Logging"] 301.63 - (testing "simple scalar attributes" 301.64 - (are [a b] (= a b) 301.65 - false (jmx/raw-read mem :Verbose)) 301.66 - (are [type attr] (instance? type attr) 301.67 - Number (jmx/raw-read mem :ObjectPendingFinalizationCount))))) 301.68 - 301.69 -(deftest reading-attributes 301.70 - (testing "simple scalar attributes" 301.71 - (are [type attr] (instance? type attr) 301.72 - Number (jmx/read "java.lang:type=Memory" :ObjectPendingFinalizationCount))) 301.73 - (testing "composite attributes" 301.74 - (are [ks attr] (=set ks (keys attr)) 301.75 - [:used :max :init :committed] (jmx/read "java.lang:type=Memory" :HeapMemoryUsage))) 301.76 - (testing "tabular attributes" 301.77 - (is (map? (jmx/read "java.lang:type=Runtime" :SystemProperties))))) 301.78 - 301.79 -(deftest writing-attributes 301.80 - (let [mem "java.lang:type=Memory"] 301.81 - (jmx/write! mem :Verbose true) 301.82 - (is (true? (jmx/raw-read mem :Verbose))) 301.83 - (jmx/write! mem :Verbose false))) 301.84 - 301.85 -(deftest test-invoke-operations 301.86 - (testing "without arguments" 301.87 - (jmx/invoke "java.lang:type=Memory" :gc)) 301.88 - (testing "with arguments" 301.89 - (.addLogger (LogManager/getLogManager) (Logger/getLogger "clojure.contrib.test_contrib.test_jmx")) 301.90 - (jmx/invoke "java.util.logging:type=Logging" :setLoggerLevel "clojure.contrib.test_contrib.test_jmx" "WARNING"))) 301.91 - 301.92 -(deftest test-jmx->clj 301.93 - (testing "it works recursively on maps" 301.94 - (let [some-map {:foo (jmx/raw-read "java.lang:type=Memory" :HeapMemoryUsage)}] 301.95 - (is (map? (:foo (jmx/jmx->clj some-map)))))) 301.96 - (testing "it leaves everything else untouched" 301.97 - (is (= "foo" (jmx/jmx->clj "foo"))))) 301.98 - 301.99 - 301.100 -(deftest test-composite-data->map 301.101 - (let [data (jmx/raw-read "java.lang:type=Memory" :HeapMemoryUsage) 301.102 - prox (jmx/composite-data->map data)] 301.103 - (testing "returns a map with keyword keys" 301.104 - (is (= (set [:committed :init :max :used]) (set (keys prox))))))) 301.105 - 301.106 -(deftest test-tabular-data->map 301.107 - (let [raw-props (jmx/raw-read "java.lang:type=Runtime" :SystemProperties) 301.108 - props (jmx/tabular-data->map raw-props)] 301.109 - (are [k] (contains? props k) 301.110 - :java.class.path 301.111 - :path.separator))) 301.112 - 301.113 -(deftest test-creating-attribute-infos 301.114 - (let [infos (jmx/map->attribute-infos [[:a 1] [:b 2]]) 301.115 - info (first infos)] 301.116 - (testing "generates the right class" 301.117 - (is (= (class (into-array MBeanAttributeInfo [])) (class infos)))) 301.118 - (testing "generates the right instance data" 301.119 - (are [result expr] (= result expr) 301.120 - "a" (.getName info) 301.121 - "a" (.getDescription info))))) 301.122 - 301.123 -(deftest various-beans-are-readable 301.124 - (testing "that all java.lang beans can be read without error" 301.125 - (doseq [mb (jmx/mbean-names "*:*")] 301.126 - (is (map? (jmx/mbean mb)) mb)))) 301.127 - 301.128 -(deftest test-jmx-url 301.129 - (testing "creates default url" 301.130 - (is (= "service:jmx:rmi:///jndi/rmi://localhost:3000/jmxrmi" 301.131 - (jmx/jmx-url)))) 301.132 - (testing "creates custom url" 301.133 - (is (= "service:jmx:rmi:///jndi/rmi://example.com:4000/jmxrmi" 301.134 - (jmx/jmx-url {:host "example.com" :port 4000})))) 301.135 - (testing "creates custom jndi path" 301.136 - (is (= "service:jmx:rmi:///jndi/rmi://example.com:4000/jmxconnector" 301.137 - (jmx/jmx-url {:host "example.com" :port 4000 :jndi-path "jmxconnector"}))))) 301.138 - 301.139 -;; ---------------------------------------------------------------------- 301.140 -;; tests for clojure.contrib.jmx.Bean. 301.141 - 301.142 -(deftest dynamic-mbean-from-compiled-class 301.143 - (let [mbean-name "clojure.contrib.test_contrib.test_jmx:name=Foo"] 301.144 - (jmx/register-mbean 301.145 - (Bean. 301.146 - (ref {:string-attribute "a-string"})) 301.147 - mbean-name) 301.148 - (are [result expr] (= result expr) 301.149 - "a-string" (jmx/read mbean-name :string-attribute) 301.150 - {:string-attribute "a-string"} (jmx/mbean mbean-name) 301.151 - ))) 301.152 - 301.153 -(deftest test-getAttribute 301.154 - (doseq [reftype [ref atom agent]] 301.155 - (let [state (reftype {:a 1 :b 2}) 301.156 - bean (Bean. state)] 301.157 - (testing (str "accessing values from a " (class state)) 301.158 - (are [result expr] (= result expr) 301.159 - 1 (.getAttribute bean "a")))))) 301.160 - 301.161 -(deftest test-bean-info 301.162 - (let [state (ref {:a 1 :b 2}) 301.163 - bean (Bean. state) 301.164 - info (.getMBeanInfo bean)] 301.165 - (testing "accessing info" 301.166 - (are [result expr] (= result expr) 301.167 - "clojure.contrib.jmx.Bean" (.getClassName info))))) 301.168 - 301.169 -(deftest test-getAttributes 301.170 - (let [bean (Bean. (ref {:r 5 :d 4})) 301.171 - atts (.getAttributes bean (into-array ["r" "d"]))] 301.172 - (are [x y] (= x y) 301.173 - AttributeList (class atts) 301.174 - [5 4] (seq atts)))) 301.175 - 301.176 -(deftest test-guess-attribute-typename 301.177 - (are [x y] (= x (jmx/guess-attribute-typename y)) 301.178 -; "long" 10 301.179 - "boolean" false 301.180 - "java.lang.String" "foo" 301.181 - "long" (Long/valueOf (long 10))))
302.1 --- a/src/clojure/contrib/test_contrib/test_json.clj Sat Aug 21 06:25:44 2010 -0400 302.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 302.3 @@ -1,186 +0,0 @@ 302.4 -(ns clojure.contrib.test-json 302.5 - (:use clojure.test clojure.contrib.json)) 302.6 - 302.7 -(deftest can-read-from-pushback-reader 302.8 - (let [s (java.io.PushbackReader. (java.io.StringReader. "42"))] 302.9 - (is (= 42 (read-json s))))) 302.10 - 302.11 -(deftest can-read-from-reader 302.12 - (let [s (java.io.StringReader. "42")] 302.13 - (is (= 42 (read-json s))))) 302.14 - 302.15 -(deftest can-read-numbers 302.16 - (is (= 42 (read-json "42"))) 302.17 - (is (= -3 (read-json "-3"))) 302.18 - (is (= 3.14159 (read-json "3.14159"))) 302.19 - (is (= 6.022e23 (read-json "6.022e23")))) 302.20 - 302.21 -(deftest can-read-null 302.22 - (is (= nil (read-json "null")))) 302.23 - 302.24 -(deftest can-read-strings 302.25 - (is (= "Hello, World!" (read-json "\"Hello, World!\"")))) 302.26 - 302.27 -(deftest handles-escaped-slashes-in-strings 302.28 - (is (= "/foo/bar" (read-json "\"\\/foo\\/bar\"")))) 302.29 - 302.30 -(deftest handles-unicode-escapes 302.31 - (is (= " \u0beb " (read-json "\" \\u0bEb \"")))) 302.32 - 302.33 -(deftest handles-escaped-whitespace 302.34 - (is (= "foo\nbar" (read-json "\"foo\\nbar\""))) 302.35 - (is (= "foo\rbar" (read-json "\"foo\\rbar\""))) 302.36 - (is (= "foo\tbar" (read-json "\"foo\\tbar\"")))) 302.37 - 302.38 -(deftest can-read-booleans 302.39 - (is (= true (read-json "true"))) 302.40 - (is (= false (read-json "false")))) 302.41 - 302.42 -(deftest can-ignore-whitespace 302.43 - (is (= nil (read-json "\r\n null")))) 302.44 - 302.45 -(deftest can-read-arrays 302.46 - (is (= [1 2 3] (read-json "[1,2,3]"))) 302.47 - (is (= ["Ole" "Lena"] (read-json "[\"Ole\", \r\n \"Lena\"]")))) 302.48 - 302.49 -(deftest can-read-objects 302.50 - (is (= {:a 1, :b 2} (read-json "{\"a\": 1, \"b\": 2}")))) 302.51 - 302.52 -(deftest can-read-nested-structures 302.53 - (is (= {:a [1 2 {:b [3 "four"]} 5.5]} 302.54 - (read-json "{\"a\":[1,2,{\"b\":[3,\"four\"]},5.5]}")))) 302.55 - 302.56 -(deftest disallows-non-string-keys 302.57 - (is (thrown? Exception (read-json "{26:\"z\"")))) 302.58 - 302.59 -(deftest disallows-barewords 302.60 - (is (thrown? Exception (read-json " foo ")))) 302.61 - 302.62 -(deftest disallows-unclosed-arrays 302.63 - (is (thrown? Exception (read-json "[1, 2, ")))) 302.64 - 302.65 -(deftest disallows-unclosed-objects 302.66 - (is (thrown? Exception (read-json "{\"a\":1, ")))) 302.67 - 302.68 -(deftest can-get-string-keys 302.69 - (is (= {"a" [1 2 {"b" [3 "four"]} 5.5]} 302.70 - (read-json "{\"a\":[1,2,{\"b\":[3,\"four\"]},5.5]}" false true nil)))) 302.71 - 302.72 -(declare *pass1-string*) 302.73 - 302.74 -(deftest pass1-test 302.75 - (let [input (read-json *pass1-string* false true nil)] 302.76 - (is (= "JSON Test Pattern pass1" (first input))) 302.77 - (is (= "array with 1 element" (get-in input [1 "object with 1 member" 0]))) 302.78 - (is (= 1234567890 (get-in input [8 "integer"]))) 302.79 - (is (= "rosebud" (last input))))) 302.80 - 302.81 -; from http://www.json.org/JSON_checker/test/pass1.json 302.82 -(def *pass1-string* 302.83 - "[ 302.84 - \"JSON Test Pattern pass1\", 302.85 - {\"object with 1 member\":[\"array with 1 element\"]}, 302.86 - {}, 302.87 - [], 302.88 - -42, 302.89 - true, 302.90 - false, 302.91 - null, 302.92 - { 302.93 - \"integer\": 1234567890, 302.94 - \"real\": -9876.543210, 302.95 - \"e\": 0.123456789e-12, 302.96 - \"E\": 1.234567890E+34, 302.97 - \"\": 23456789012E66, 302.98 - \"zero\": 0, 302.99 - \"one\": 1, 302.100 - \"space\": \" \", 302.101 - \"quote\": \"\\\"\", 302.102 - \"backslash\": \"\\\\\", 302.103 - \"controls\": \"\\b\\f\\n\\r\\t\", 302.104 - \"slash\": \"/ & \\/\", 302.105 - \"alpha\": \"abcdefghijklmnopqrstuvwyz\", 302.106 - \"ALPHA\": \"ABCDEFGHIJKLMNOPQRSTUVWYZ\", 302.107 - \"digit\": \"0123456789\", 302.108 - \"0123456789\": \"digit\", 302.109 - \"special\": \"`1~!@#$%^&*()_+-={':[,]}|;.</>?\", 302.110 - \"hex\": \"\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A\", 302.111 - \"true\": true, 302.112 - \"false\": false, 302.113 - \"null\": null, 302.114 - \"array\":[ ], 302.115 - \"object\":{ }, 302.116 - \"address\": \"50 St. James Street\", 302.117 - \"url\": \"http://www.JSON.org/\", 302.118 - \"comment\": \"// /* <!-- --\", 302.119 - \"# -- --> */\": \" \", 302.120 - \" s p a c e d \" :[1,2 , 3 302.121 - 302.122 -, 302.123 - 302.124 -4 , 5 , 6 ,7 ],\"compact\":[1,2,3,4,5,6,7], 302.125 - \"jsontext\": \"{\\\"object with 1 member\\\":[\\\"array with 1 element\\\"]}\", 302.126 - \"quotes\": \"" \\u0022 %22 0x22 034 "\", 302.127 - \"\\/\\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?\" 302.128 -: \"A key can be any string\" 302.129 - }, 302.130 - 0.5 ,98.6 302.131 -, 302.132 -99.44 302.133 -, 302.134 - 302.135 -1066, 302.136 -1e1, 302.137 -0.1e1, 302.138 -1e-1, 302.139 -1e00,2e+00,2e-00 302.140 -,\"rosebud\"]") 302.141 - 302.142 - 302.143 -(deftest can-print-json-strings 302.144 - (is (= "\"Hello, World!\"" (json-str "Hello, World!"))) 302.145 - (is (= "\"\\\"Embedded\\\" Quotes\"" (json-str "\"Embedded\" Quotes")))) 302.146 - 302.147 -(deftest can-print-unicode 302.148 - (is (= "\"\\u1234\\u4567\"" (json-str "\u1234\u4567")))) 302.149 - 302.150 -(deftest can-print-json-null 302.151 - (is (= "null" (json-str nil)))) 302.152 - 302.153 -(deftest can-print-json-arrays 302.154 - (is (= "[1,2,3]" (json-str [1 2 3]))) 302.155 - (is (= "[1,2,3]" (json-str (list 1 2 3)))) 302.156 - (is (= "[1,2,3]" (json-str (sorted-set 1 2 3)))) 302.157 - (is (= "[1,2,3]" (json-str (seq [1 2 3]))))) 302.158 - 302.159 -(deftest can-print-java-arrays 302.160 - (is (= "[1,2,3]" (json-str (into-array [1 2 3]))))) 302.161 - 302.162 -(deftest can-print-empty-arrays 302.163 - (is (= "[]" (json-str []))) 302.164 - (is (= "[]" (json-str (list)))) 302.165 - (is (= "[]" (json-str #{})))) 302.166 - 302.167 -(deftest can-print-json-objects 302.168 - (is (= "{\"a\":1,\"b\":2}" (json-str (sorted-map :a 1 :b 2))))) 302.169 - 302.170 -(deftest object-keys-must-be-strings 302.171 - (is (= "{\"1\":1,\"2\":2") (json-str (sorted-map 1 1 2 2)))) 302.172 - 302.173 -(deftest can-print-empty-objects 302.174 - (is (= "{}" (json-str {})))) 302.175 - 302.176 -(deftest accept-sequence-of-nils 302.177 - (is (= "[null,null,null]" (json-str [nil nil nil])))) 302.178 - 302.179 -(deftest error-on-nil-keys 302.180 - (is (thrown? Exception (json-str {nil 1})))) 302.181 - 302.182 -(deftest characters-in-symbols-are-escaped 302.183 - (is (= "\"foo\\u1b1b\"" (json-str (symbol "foo\u1b1b"))))) 302.184 - 302.185 -;;; Pretty-printer 302.186 - 302.187 -(deftest pretty-printing 302.188 - (let [x (read-json *pass1-string* false)] 302.189 - (is (= x (read-json (with-out-str (pprint-json x)) false)))))
303.1 --- a/src/clojure/contrib/test_contrib/test_lazy_seqs.clj Sat Aug 21 06:25:44 2010 -0400 303.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 303.3 @@ -1,21 +0,0 @@ 303.4 -(ns clojure.contrib.test-lazy-seqs 303.5 - (:use clojure.test 303.6 - clojure.contrib.lazy-seqs)) 303.7 - 303.8 -(deftest test-fibs 303.9 - (is (= [0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 303.10 - 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 303.11 - 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 303.12 - 165580141 267914296 433494437 701408733 1134903170 1836311903 2971215073 303.13 - 4807526976 7778742049] 303.14 - (take 50 (fibs))))) 303.15 - 303.16 -(deftest test-powers-of-2 303.17 - (is (= [1 2 4 8 16 32 64 128 256 512] 303.18 - (take 10 (powers-of-2))))) 303.19 - 303.20 -(deftest test-primes 303.21 - (is (= [2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 303.22 - 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 303.23 - 199 211 223 227 229] 303.24 - (take 50 primes))))
304.1 --- a/src/clojure/contrib/test_contrib/test_load_all.clj Sat Aug 21 06:25:44 2010 -0400 304.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 304.3 @@ -1,53 +0,0 @@ 304.4 -;;; test_load_all.clj - loads all contrib libraries for testing purposes 304.5 - 304.6 -;; by Stuart Halloway, http://blog.thinkrelevance.com 304.7 - 304.8 -;; Copyright (c) Stuart Halloway, 2009. All rights reserved. The use 304.9 -;; and distribution terms for this software are covered by the Eclipse 304.10 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 304.11 -;; which can be found in the file epl-v10.html at the root of this 304.12 -;; distribution. By using this software in any fashion, you are 304.13 -;; agreeing to be bound by the terms of this license. You must not 304.14 -;; remove this notice, or any other, from this software. 304.15 - 304.16 -;; This is only intended to check that the libraries will load without 304.17 -;; errors, not that they work correctly. 304.18 - 304.19 -;; The code includes several design choices I don't love, but find 304.20 -;; tolerable in a test-only lib: 304.21 -;; 304.22 -;; * namespaces that blow up to document deprecation 304.23 -;; * using directory paths to find contrib 304.24 -;; * using a macro to reflectively write tests 304.25 -;; 304.26 -;; I *am* happy that code that won't even load now breaks the build. 304.27 - 304.28 -(ns clojure.contrib.test-load-all 304.29 - (:use clojure.test clojure.contrib.find-namespaces)) 304.30 - 304.31 -(def deprecated-contrib-namespaces 304.32 - '[clojure.contrib.javadoc]) 304.33 - 304.34 -(defn loadable-contrib-namespaces 304.35 - "Contrib namespaces that can be loaded (everything except 304.36 - deprecated nses that throw on load.)" 304.37 - [] 304.38 - (apply disj 304.39 - (into #{} (find-namespaces-in-dir (java.io.File. "src/main"))) 304.40 - deprecated-contrib-namespaces)) 304.41 - 304.42 -(defn emit-test-load 304.43 - [] 304.44 - `(do 304.45 - ~@(map 304.46 - (fn [ns] 304.47 - `(deftest ~(symbol (str "test-loading-" (.replace (str ns) "." "-"))) 304.48 - (require :reload '~ns))) 304.49 - (loadable-contrib-namespaces)))) 304.50 - 304.51 -(defmacro test-load 304.52 - [] 304.53 - (emit-test-load)) 304.54 - 304.55 -(test-load) 304.56 -
305.1 --- a/src/clojure/contrib/test_contrib/test_macro_utils.clj Sat Aug 21 06:25:44 2010 -0400 305.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 305.3 @@ -1,67 +0,0 @@ 305.4 -;; Test routines for macro_utils.clj 305.5 - 305.6 -;; by Konrad Hinsen 305.7 -;; last updated May 6, 2009 305.8 - 305.9 -;; Copyright (c) Konrad Hinsen, 2008. All rights reserved. The use 305.10 -;; and distribution terms for this software are covered by the Eclipse 305.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 305.12 -;; which can be found in the file epl-v10.html at the root of this 305.13 -;; distribution. By using this software in any fashion, you are 305.14 -;; agreeing to be bound by the terms of this license. You must not 305.15 -;; remove this notice, or any other, from this software. 305.16 - 305.17 -(ns clojure.contrib.test-macro-utils 305.18 - (:use [clojure.test :only (deftest is are run-tests use-fixtures)] 305.19 - [clojure.contrib.macro-utils 305.20 - :only (macrolet symbol-macrolet defsymbolmacro with-symbol-macros 305.21 - mexpand-1 mexpand mexpand-all)] 305.22 - [clojure.contrib.monads 305.23 - :only (with-monad domonad)])) 305.24 - 305.25 -(use-fixtures :each 305.26 - (fn [f] (binding [*ns* (the-ns 'clojure.contrib.test-macro-utils)] 305.27 - (f)))) 305.28 - 305.29 -(deftest macrolet-test 305.30 - (is (= (macroexpand-1 305.31 - '(macrolet [(foo [form] `(~form ~form))] (foo x))) 305.32 - '(do (x x))))) 305.33 - 305.34 -(deftest symbol-macrolet-test 305.35 - (is (= (macroexpand-1 305.36 - '(symbol-macrolet [x xx y yy] 305.37 - (exp [a y] (x y)))) 305.38 - '(do (exp [a yy] (xx yy))))) 305.39 - (is (= (macroexpand-1 305.40 - '(symbol-macrolet [def foo] 305.41 - (def def def))) 305.42 - '(do (def def foo)))) 305.43 - (is (= (macroexpand-1 305.44 - '(symbol-macrolet [x foo z bar] 305.45 - (let [a x b y x b] [a b x z]))) 305.46 - '(do (let* [a foo b y x b] [a b x bar])))) 305.47 - (is (= (macroexpand-1 305.48 - '(symbol-macrolet [x foo z bar] 305.49 - (fn ([x y] [x y z]) ([x y z] [x y z])))) 305.50 - '(do (fn* ([x y] [x y bar]) ([x y z] [x y z]))))) 305.51 - (is (= (macroexpand-1 305.52 - '(symbol-macrolet [x foo z bar] 305.53 - (fn f ([x y] [x y z]) ([x y z] [x y z])))) 305.54 - '(do (fn* f ([x y] [x y bar]) ([x y z] [x y z]))))) 305.55 - (is (= (nth (second (macroexpand-1 305.56 - '(symbol-macrolet [x xx y yy z zz] 305.57 - (domonad m [a x b y x z] [a b x z])))) 2) 305.58 - '(do (m-bind xx (fn* ([a] 305.59 - (m-bind yy (fn* ([b] 305.60 - (m-bind zz (fn* ([x] 305.61 - (m-result [a b x zz])))))))))))))) 305.62 - 305.63 -(deftest symbol-test 305.64 - (defsymbolmacro sum-2-3 (plus 2 3)) 305.65 - (is (= (macroexpand '(with-symbol-macros (+ 1 sum-2-3))) 305.66 - '(do (+ 1 (plus 2 3))))) 305.67 - (is (= (macroexpand '(macrolet [(plus [a b] `(+ ~a ~b))] (+ 1 sum-2-3))) 305.68 - '(do (+ 1 (clojure.core/+ 2 3))))) 305.69 - (ns-unmap *ns* 'sum-2-3)) 305.70 -
306.1 --- a/src/clojure/contrib/test_contrib/test_math.clj Sat Aug 21 06:25:44 2010 -0400 306.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 306.3 @@ -1,118 +0,0 @@ 306.4 -(ns clojure.contrib.test-math 306.5 - (:use clojure.test 306.6 - clojure.contrib.math)) 306.7 - 306.8 -(deftest test-expt 306.9 - (are [x y] (= x y) 306.10 - (expt 2 3) 8 306.11 - (expt (expt 2 16) 2) (expt 2 32) 306.12 - (expt 4/3 2) 16/9 306.13 - (expt 2 -10) 1/1024 306.14 - (expt 0.5M 2) 0.25M 306.15 - (expt 5 4.2) (Math/pow 5 4.2) 306.16 - (expt 5.3 4) (Math/pow 5.3 4))) 306.17 - 306.18 -(deftest test-abs 306.19 - (are [x y] (= x y) 306.20 - (abs -2) 2 306.21 - (abs 0) 0 306.22 - (abs 5) 5 306.23 - (abs 123456789123456789) 123456789123456789 306.24 - (abs -123456789123456789) 123456789123456789 306.25 - (abs 5/3) 5/3 306.26 - (abs -4/3) 4/3 306.27 - (abs 4.3M) 4.3M 306.28 - (abs -4.3M) 4.3M 306.29 - (abs 2.8) 2.8 306.30 - (abs -2.8) 2.8)) 306.31 - 306.32 -(deftest test-gcd 306.33 - (are [x y] (= x y) 306.34 - (gcd 4 3) 1 306.35 - (gcd 24 12) 12 306.36 - (gcd 24 27) 3 306.37 - (gcd 1 0) 1 306.38 - (gcd 0 1) 1 306.39 - (gcd 0 0) 0) 306.40 - (is (thrown? IllegalArgumentException (gcd nil 0))) 306.41 - (is (thrown? IllegalArgumentException (gcd 0 nil))) 306.42 - (is (thrown? IllegalArgumentException (gcd 7.0 0)))) 306.43 - 306.44 -(deftest test-lcm 306.45 - (are [x y] (= x y) 306.46 - (lcm 2 3) 6 306.47 - (lcm 3 2) 6 306.48 - (lcm -2 3) 6 306.49 - (lcm 2 -3) 6 306.50 - (lcm -2 -3) 6 306.51 - (lcm 4 10) 20 306.52 - (lcm 1 0) 0 306.53 - (lcm 0 1) 0 306.54 - (lcm 0 0)) 306.55 - (is (thrown? IllegalArgumentException (lcm nil 0))) 306.56 - (is (thrown? IllegalArgumentException (lcm 0 nil))) 306.57 - (is (thrown? IllegalArgumentException (lcm 7.0 0)))) 306.58 - 306.59 -(deftest test-floor 306.60 - (are [x y] (== x y) 306.61 - (floor 6) 6 306.62 - (floor -6) -6 306.63 - (floor 123456789123456789) 123456789123456789 306.64 - (floor -123456789123456789) -123456789123456789 306.65 - (floor 4/3) 1 306.66 - (floor -4/3) -2 306.67 - (floor 4.3M) 4 306.68 - (floor -4.3M) -5 306.69 - (floor 4.3) 4.0 306.70 - (floor -4.3) -5.0)) 306.71 - 306.72 -(deftest test-ceil 306.73 - (are [x y] (== x y) 306.74 - (ceil 6) 6 306.75 - (ceil -6) -6 306.76 - (ceil 123456789123456789) 123456789123456789 306.77 - (ceil -123456789123456789) -123456789123456789 306.78 - (ceil 4/3) 2 306.79 - (ceil -4/3) -1 306.80 - (ceil 4.3M) 5 306.81 - (ceil -4.3M) -4 306.82 - (ceil 4.3) 5.0 306.83 - (ceil -4.3) -4.0)) 306.84 - 306.85 -(deftest test-round 306.86 - (are [x y] (== x y) 306.87 - (round 6) 6 306.88 - (round -6) -6 306.89 - (round 123456789123456789) 123456789123456789 306.90 - (round -123456789123456789) -123456789123456789 306.91 - (round 4/3) 1 306.92 - (round 5/3) 2 306.93 - (round 5/2) 3 306.94 - (round -4/3) -1 306.95 - (round -5/3) -2 306.96 - (round -5/2) -2 306.97 - (round 4.3M) 4 306.98 - (round 4.7M) 5 306.99 - (round -4.3M) -4 306.100 - (round -4.7M) -5 306.101 - (round 4.5M) 5 306.102 - (round -4.5M) -4 306.103 - (round 4.3) 4 306.104 - (round 4.7) 5 306.105 - (round -4.3) -4 306.106 - (round -4.7) -5 306.107 - (round 4.5) 5 306.108 - (round -4.5) -4)) 306.109 - 306.110 -(deftest test-sqrt 306.111 - (are [x y] (= x y) 306.112 - (sqrt 9) 3 306.113 - (sqrt 16/9) 4/3 306.114 - (sqrt 0.25M) 0.5M 306.115 - (sqrt 2) (Math/sqrt 2))) 306.116 - 306.117 -(deftest test-exact-integer-sqrt 306.118 - (are [x y] (= x y) 306.119 - (exact-integer-sqrt 15) [3 6] 306.120 - (exact-integer-sqrt (inc (expt 2 32))) [(expt 2 16) 1] 306.121 - (exact-integer-sqrt 1000000000000) [1000000 0]))
307.1 --- a/src/clojure/contrib/test_contrib/test_miglayout.clj Sat Aug 21 06:25:44 2010 -0400 307.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 307.3 @@ -1,145 +0,0 @@ 307.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 307.5 -;; distribution terms for this software are covered by the Eclipse Public 307.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 307.7 -;; be found in the file epl-v10.html at the root of this distribution. By 307.8 -;; using this software in any fashion, you are agreeing to be bound by the 307.9 -;; terms of this license. You must not remove this notice, or any other, 307.10 -;; from this software. 307.11 -;; 307.12 -;; clojure.contrib.miglayout.test 307.13 -;; 307.14 -;; Test/example for clojure.contrib.miglayout 307.15 -;; 307.16 -;; scgilardi (gmail) 307.17 -;; Created 5 October 2008 307.18 - 307.19 -(ns clojure.contrib.test-miglayout 307.20 - (:import (javax.swing JButton JFrame JLabel JList JPanel 307.21 - JScrollPane JTabbedPane JTextField JSeparator)) 307.22 - (:use clojure.contrib.miglayout)) 307.23 - 307.24 -(def tests) 307.25 - 307.26 -(defn run-test 307.27 - [index] 307.28 - (let [panel ((tests index) (JPanel.))] 307.29 - (println index (components panel)) 307.30 - (doto (JFrame. (format "MigLayout Test %d" index)) 307.31 - (.add panel) 307.32 - (.pack) 307.33 - (.setVisible true)))) 307.34 - 307.35 -(defn label 307.36 - "Returns a swing label" 307.37 - [text] 307.38 - (JLabel. text)) 307.39 - 307.40 -(defn text-field 307.41 - "Returns a swing text field" 307.42 - ([] (text-field 10)) 307.43 - ([width] 307.44 - (JTextField. width))) 307.45 - 307.46 -(defn sep 307.47 - "Returns a swing separator" 307.48 - [] 307.49 - (JSeparator.)) 307.50 - 307.51 -(def tests [ 307.52 - 307.53 - (fn test0 307.54 - [panel] 307.55 - (miglayout panel 307.56 - (label "Hello") 307.57 - (label "World") {:gap :unrelated} 307.58 - (text-field) :wrap 307.59 - (label "Bonus!") 307.60 - (JButton. "Bang it") {:wmin :button :grow :x :span 2} :center)) 307.61 - 307.62 - ;; test1 and test2 are based on code from 307.63 - ;; http://www.devx.com/java/Article/38017/1954 307.64 - 307.65 - ;; constraints as strings exclusively 307.66 - (fn test1 307.67 - [panel] 307.68 - (miglayout panel 307.69 - :column "[right]" 307.70 - (label "General") "split, span" 307.71 - (sep) "growx, wrap" 307.72 - (label "Company") "gap 10" 307.73 - (text-field "") "span, growx" 307.74 - (label "Contact") "gap 10" 307.75 - (text-field "") "span, growx, wrap" 307.76 - (label "Propeller") "split, span, gaptop 10" 307.77 - (sep) "growx, wrap, gaptop 10" 307.78 - (label "PTI/kW") "gapx 10, gapy 15" 307.79 - (text-field) 307.80 - (label "Power/kW") "gap 10" 307.81 - (text-field) "wrap" 307.82 - (label "R/mm") "gap 10" 307.83 - (text-field) 307.84 - (label "D/mm") "gap 10" 307.85 - (text-field))) 307.86 - 307.87 - ;; the same constraints as strings, keywords, vectors, and maps 307.88 - (fn test2 307.89 - [panel] 307.90 - (miglayout panel 307.91 - :column "[right]" 307.92 - (label "General") "split, span" 307.93 - (sep) :growx :wrap 307.94 - (label "Company") [:gap 10] 307.95 - (text-field "") :span :growx 307.96 - (label "Contact") [:gap 10] 307.97 - (text-field "") :span :growx :wrap 307.98 - (label "Propeller") :split :span [:gaptop 10] 307.99 - (sep) :growx :wrap [:gaptop 10] 307.100 - (label "PTI/kW") {:gapx 10 :gapy 15} 307.101 - (text-field) 307.102 - (label "Power/kW") [:gap 10] 307.103 - (text-field) :wrap 307.104 - (label "R/mm") [:gap 10] 307.105 - (text-field) 307.106 - (label "D/mm") [:gap 10] 307.107 - (text-field))) 307.108 - 307.109 - ;; the same constraints using symbols to name groups of constraints 307.110 - (fn test3 307.111 - [panel] 307.112 - (let [g [:gap 10] 307.113 - gt [:gaptop 10] 307.114 - gxs #{:growx :span} 307.115 - gxw #{:growx :wrap} 307.116 - gxy {:gapx 10 :gapy 15} 307.117 - right "[right]" 307.118 - ss #{:split :span} 307.119 - w :wrap] 307.120 - (miglayout panel 307.121 - :column right 307.122 - (label "General") ss 307.123 - (sep) gxw 307.124 - (label "Company") g 307.125 - (text-field "") gxs 307.126 - (label "Contact") g 307.127 - (text-field "") gxs 307.128 - (label "Propeller") ss gt 307.129 - (sep) gxw g 307.130 - (label "PTI/kW") gxy 307.131 - (text-field) 307.132 - (label "Power/kW") g 307.133 - (text-field) w 307.134 - (label "R/mm") g 307.135 - (text-field) 307.136 - (label "D/mm") g 307.137 - (text-field)))) 307.138 - 307.139 - (fn test4 307.140 - [panel] 307.141 - (miglayout panel 307.142 - (label "First Name") 307.143 - (text-field) {:id :firstname} 307.144 - (label "Surname") [:gap :unrelated] 307.145 - (text-field) {:id :surname} :wrap 307.146 - (label "Address") 307.147 - (text-field) {:id :address} :span :grow)) 307.148 -])
308.1 --- a/src/clojure/contrib/test_contrib/test_mock.clj Sat Aug 21 06:25:44 2010 -0400 308.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 308.3 @@ -1,131 +0,0 @@ 308.4 -(ns clojure.contrib.test-mock 308.5 - (:use clojure.test) 308.6 - (:require [clojure.contrib.mock :as mock])) 308.7 - 308.8 -; Used as dummy dependency functions 308.9 -(defn fn1 {:dynamic true} [x] :ignore) 308.10 -(defn fn2 {:dynamic true} [x y] :ignore) 308.11 -(defn fn3 {:dynamic true} ([x] :ignore) 308.12 - ([x y z] :ignore)) 308.13 -(defn fn4 {:dynamic true} [x y & r] :ignore) 308.14 - 308.15 -;functions created using fn directly lack the argslist meta data 308.16 -(def #^{:dynamic true} deffed-differently (fn [x] :ignore)) 308.17 - 308.18 -(defmacro assert-called [fn-name called? & body] 308.19 - `(let [called-status?# (atom false)] 308.20 - (binding [~fn-name (fn [& args#] (reset! called-status?# true))] ~@body) 308.21 - (is (= ~called? @called-status?#)))) 308.22 - 308.23 -(deftest test-convenience 308.24 - (testing "once" 308.25 - (is (false? (mock/once 0))) 308.26 - (is (false? (mock/once 123))) 308.27 - (is (true? (mock/once 1)))) 308.28 - 308.29 - (testing "never" 308.30 - (is (false? (mock/never 4))) 308.31 - (is (true? (mock/never 0)))) 308.32 - 308.33 - (testing "more-than" 308.34 - (is (false? ((mock/more-than 5) 3))) 308.35 - (is (true? ((mock/more-than 5) 9)))) 308.36 - 308.37 - (testing "less-than" 308.38 - (is (true? ((mock/less-than 5) 3))) 308.39 - (is (false? ((mock/less-than 5) 9)))) 308.40 - 308.41 - (testing "between" 308.42 - (is (true? ((mock/between 5 8) 6))) 308.43 - (is (false? ((mock/between 5 8) 5))))) 308.44 - 308.45 - 308.46 -(deftest test-returns 308.47 - (is (= {:returns 5} (mock/returns 5))) 308.48 - (is (= {:other-key "test" :returns nil} (mock/returns nil {:other-key "test"})))) 308.49 - 308.50 - 308.51 -(deftest test-has-args 308.52 - (let [ex (:has-args (mock/has-args [1]))] 308.53 - (is (fn? ex)) 308.54 - (is (ex 'fn1 1)) 308.55 - (is (ex 'fn1 1 5 6)) 308.56 - (assert-called mock/unexpected-args true (ex 'fn1 5))) 308.57 - (is (contains? (mock/has-args [] {:pre-existing-key "test"}) :pre-existing-key)) 308.58 - (is (true? (((mock/has-args [5]) :has-args)'fn1 5)))) 308.59 - 308.60 - 308.61 -(deftest test-has-matching-signature 308.62 - (assert-called mock/no-matching-function-signature true 308.63 - (mock/has-matching-signature? 'clojure.contrib.test-mock/fn2 [1])) 308.64 - (assert-called mock/no-matching-function-signature true 308.65 - (mock/has-matching-signature? 'clojure.contrib.test-mock/fn3 [1 3])) 308.66 - (assert-called mock/no-matching-function-signature false 308.67 - (mock/has-matching-signature? 'clojure.contrib.test-mock/fn3 [1 3 5])) 308.68 - (assert-called mock/no-matching-function-signature false 308.69 - (mock/has-matching-signature? 'clojure.contrib.test-mock/fn4 [1 3 5 7 9])) 308.70 - (assert-called mock/no-matching-function-signature false 308.71 - (mock/has-matching-signature? 'clojure.contrib.test-mock/fn4 [1 3])) 308.72 - (assert-called mock/no-matching-function-signature true 308.73 - (mock/has-matching-signature? 'clojure.contrib.test-mock/fn4 [1])) 308.74 - (assert-called mock/no-matching-function-signature false 308.75 - (mock/has-matching-signature? 'clojure.contrib.test-mock/deffed-differently [1]))) 308.76 - 308.77 - 308.78 -(deftest test-times 308.79 - (is (fn? ((mock/times #(= 1 %)) :times))) 308.80 - (is (contains? (mock/times #(= 1 %) {:existing-key "test"}) :existing-key))) 308.81 - 308.82 -(deftest test-make-mock 308.83 - (testing "invalid arguments" 308.84 - (is (thrown? IllegalArgumentException (mock/make-mock [5])))) 308.85 - 308.86 - (testing "valid counter and unevaluated returns" 308.87 - (let [[mock counter count-checker] (mock/make-mock 'fn1 (mock/returns 5 (mock/times 1)))] 308.88 - (is (fn? mock)) 308.89 - (is (= 0 @counter)) 308.90 - (is (= 5 (mock :ignore-me))) 308.91 - (is (= 1 @counter)))) 308.92 - 308.93 - (testing "returns as expected" 308.94 - (let [[mock] (mock/make-mock 'fn1 (mock/returns 5))] 308.95 - (is (= 5 (mock :ignore)))) 308.96 - (let [[mock] (mock/make-mock 'fn1 (mock/returns #(* 2 %)))] 308.97 - (is (= 10 ((mock :ignore) 5)) ":returns a function should not automatically 308.98 - evaluate it."))) 308.99 - 308.100 - (testing "calls replacement-fn and returns the result" 308.101 - (let [[mock] (mock/make-mock 'fn1 (mock/calls #(* 3 %)))] 308.102 - (is (= 15 (mock 5)))) 308.103 - (let [[mock] (mock/make-mock 'fn1 (mock/calls #(* 2 %) (mock/returns 3)))] 308.104 - (is (= 10 (mock 5))))) 308.105 - 308.106 - (testing "argument validation" 308.107 - (let [[mock] (mock/make-mock 'fn1 (mock/has-args [#(= 5 %)]))] 308.108 - (assert-called mock/unexpected-args true (mock "test")) 308.109 - (is (nil? (mock 5)))))) 308.110 - 308.111 - 308.112 -(deftest test-make-count-checker 308.113 - (let [checker (mock/make-count-checker 5 5)] 308.114 - (assert-called mock/incorrect-invocation-count false (checker 'fn1 5)) 308.115 - (assert-called mock/incorrect-invocation-count true (checker 'fn1 3)))) 308.116 - 308.117 - 308.118 -(deftest test-validate-counts 308.119 - (assert-called mock/incorrect-invocation-count false 308.120 - (mock/validate-counts (list [(fn []) (atom 0) (mock/make-count-checker #(< % 6) '#(< % 6)) 'fn1]))) 308.121 - (assert-called mock/incorrect-invocation-count true 308.122 - (mock/validate-counts (list [(fn []) (atom 0) (mock/make-count-checker 4 4) 'fn1])))) 308.123 - 308.124 - 308.125 -(deftest test-expect-macro 308.126 - (let [under-test (fn [x] (fn1 x))] 308.127 - (is (true? (mock/expect [fn1 (mock/times 1 (mock/has-args [#(= 3 %)]))] 308.128 - (under-test 3)))) 308.129 - (assert-called mock/unexpected-args true (mock/expect [fn1 (mock/times 1 (mock/has-args [#(= 4 %)]))] 308.130 - (under-test 3)))) 308.131 - (let [under-test (fn [] (fn2 (fn1 1) 3))] 308.132 - (is (true? (mock/expect [fn1 (mock/times 1 (mock/has-args [#(= 1 %)] (mock/returns 2))) 308.133 - fn2 (mock/times 1 (mock/has-args [#(= 2 %) #(= 3 %)] (mock/returns 5)))] 308.134 - (under-test)))))) 308.135 \ No newline at end of file
309.1 --- a/src/clojure/contrib/test_contrib/test_monads.clj Sat Aug 21 06:25:44 2010 -0400 309.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 309.3 @@ -1,78 +0,0 @@ 309.4 -;; Test routines for monads.clj 309.5 - 309.6 -;; by Konrad Hinsen 309.7 -;; last updated March 28, 2009 309.8 - 309.9 -;; Copyright (c) Konrad Hinsen, 2008. All rights reserved. The use 309.10 -;; and distribution terms for this software are covered by the Eclipse 309.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 309.12 -;; which can be found in the file epl-v10.html at the root of this 309.13 -;; distribution. By using this software in any fashion, you are 309.14 -;; agreeing to be bound by the terms of this license. You must not 309.15 -;; remove this notice, or any other, from this software. 309.16 - 309.17 -(ns clojure.contrib.test-monads 309.18 - (:use [clojure.test :only (deftest is are run-tests)] 309.19 - [clojure.contrib.monads 309.20 - :only (with-monad domonad m-lift m-seq m-chain 309.21 - sequence-m maybe-m state-m maybe-t sequence-t)])) 309.22 - 309.23 -(deftest sequence-monad 309.24 - (with-monad sequence-m 309.25 - (are [a b] (= a b) 309.26 - (domonad [x (range 3) y (range 2)] (+ x y)) 309.27 - '(0 1 1 2 2 3) 309.28 - (domonad [x (range 5) y (range (+ 1 x)) :when (= (+ x y) 2)] (list x y)) 309.29 - '((1 1) (2 0)) 309.30 - ((m-lift 2 #(list %1 %2)) (range 3) (range 2)) 309.31 - '((0 0) (0 1) (1 0) (1 1) (2 0) (2 1)) 309.32 - (m-seq (replicate 3 (range 2))) 309.33 - '((0 0 0) (0 0 1) (0 1 0) (0 1 1) (1 0 0) (1 0 1) (1 1 0) (1 1 1)) 309.34 - ((m-chain (replicate 3 range)) 5) 309.35 - '(0 0 0 1 0 0 1 0 1 2) 309.36 - (m-plus (range 3) (range 2)) 309.37 - '(0 1 2 0 1)))) 309.38 - 309.39 -(deftest maybe-monad 309.40 - (with-monad maybe-m 309.41 - (let [m+ (m-lift 2 +) 309.42 - mdiv (fn [x y] (domonad [a x b y :when (not (zero? b))] (/ a b)))] 309.43 - (are [a b] (= a b) 309.44 - (m+ (m-result 1) (m-result 3)) 309.45 - (m-result 4) 309.46 - (mdiv (m-result 1) (m-result 3)) 309.47 - (m-result (/ 1 3)) 309.48 - (m+ 1 (mdiv (m-result 1) (m-result 0))) 309.49 - m-zero 309.50 - (m-plus m-zero (m-result 1) m-zero (m-result 2)) 309.51 - (m-result 1))))) 309.52 - 309.53 -(deftest seq-maybe-monad 309.54 - (with-monad (maybe-t sequence-m) 309.55 - (letfn [(pairs [xs] ((m-lift 2 #(list %1 %2)) xs xs))] 309.56 - (are [a b] (= a b) 309.57 - ((m-lift 1 inc) (for [n (range 10)] (when (odd? n) n))) 309.58 - '(nil 2 nil 4 nil 6 nil 8 nil 10) 309.59 - (pairs (for [n (range 5)] (when (odd? n) n))) 309.60 - '(nil nil (1 1) nil (1 3) nil nil nil (3 1) nil (3 3) nil nil))))) 309.61 - 309.62 -(deftest state-maybe-monad 309.63 - (with-monad (maybe-t state-m) 309.64 - (is (= (for [[a b c d] (list [1 2 3 4] [nil 2 3 4] [ 1 nil 3 4] 309.65 - [nil nil 3 4] [1 2 nil nil])] 309.66 - (let [f (domonad 309.67 - [x (m-plus (m-result a) (m-result b)) 309.68 - y (m-plus (m-result c) (m-result d))] 309.69 - (+ x y))] 309.70 - (f :state))) 309.71 - (list [4 :state] [5 :state] [4 :state] [nil :state] [nil :state]))))) 309.72 - 309.73 -(deftest state-seq-monad 309.74 - (with-monad (sequence-t state-m) 309.75 - (is (= (let [[a b c d] [1 2 10 20] 309.76 - f (domonad 309.77 - [x (m-plus (m-result a) (m-result b)) 309.78 - y (m-plus (m-result c) (m-result d))] 309.79 - (+ x y))] 309.80 - (f :state))) 309.81 - (list [(list 11 21 12 22) :state]))))
310.1 --- a/src/clojure/contrib/test_contrib/test_profile.clj Sat Aug 21 06:25:44 2010 -0400 310.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 310.3 @@ -1,8 +0,0 @@ 310.4 -(ns clojure.contrib.test-profile 310.5 - (:use clojure.test 310.6 - clojure.contrib.profile)) 310.7 - 310.8 -(deftest test-print-summary 310.9 - (testing "doesn't blow up with no data (assembla #31)" 310.10 - (is (= "Name mean min max count sum\n" 310.11 - (with-out-str (print-summary {}))))))
311.1 --- a/src/clojure/contrib/test_contrib/test_properties.clj Sat Aug 21 06:25:44 2010 -0400 311.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 311.3 @@ -1,63 +0,0 @@ 311.4 -(ns clojure.contrib.test-properties 311.5 - (:refer-clojure :exclude (spit)) 311.6 - (:use clojure.test clojure.contrib.properties 311.7 - [clojure.contrib.io :only (spit)]) 311.8 - (:import (java.util Properties) 311.9 - (java.io File))) 311.10 - 311.11 -(deftest test-get-system-property 311.12 - (testing "works the same with keywords, symbols, and strings" 311.13 - (is (= (get-system-property "java.home") (get-system-property 'java.home))) 311.14 - (is (= (get-system-property "java.home") (get-system-property :java.home)))) 311.15 - (testing "treats second arg as default" 311.16 - (is (= "default" (get-system-property "testing.test-system-property" "default")))) 311.17 - (testing "returns nil for missing properties" 311.18 - (is (nil? (get-system-property "testing.test-system-property"))))) 311.19 - 311.20 -(deftest test-set-system-properties 311.21 - (testing "set and then unset a property using keywords" 311.22 - (let [propname :clojure.contrib.java.test-set-system-properties] 311.23 - (is (nil? (get-system-property propname))) 311.24 - (set-system-properties {propname :foo}) 311.25 - (is (= "foo") (get-system-property propname)) 311.26 - (set-system-properties {propname nil}) 311.27 - (is (nil? (get-system-property propname)))))) 311.28 - 311.29 -(deftest test-with-system-properties 311.30 - (let [propname :clojure.contrib.java.test-with-system-properties] 311.31 - (testing "sets a property only for the duration of a block" 311.32 - (is (= "foo" 311.33 - (with-system-properties {propname "foo"} 311.34 - (get-system-property propname)))) 311.35 - (is (nil? (get-system-property propname))))) 311.36 - (testing "leaves other properties alone" 311.37 - ; TODO: write this test better, using a properties -> map function 311.38 - (let [propname :clojure.contrib.java.test-with-system-properties 311.39 - propcount (count (System/getProperties))] 311.40 - (with-system-properties {propname "foo"} 311.41 - (is (= (inc propcount) (count (System/getProperties))))) 311.42 - (is (= propcount (count (System/getProperties))))))) 311.43 - 311.44 -(deftest test-as-properties 311.45 - (let [expected (doto (Properties.) 311.46 - (.setProperty "a" "b") 311.47 - (.setProperty "c" "d"))] 311.48 - (testing "with a map" 311.49 - (is (= expected 311.50 - (as-properties {:a "b" :c "d"})))) 311.51 - (testing "with a sequence of pairs" 311.52 - (is (= expected 311.53 - (as-properties [[:a :b] [:c :d]])))))) 311.54 - 311.55 -(deftest test-read-properties 311.56 - (let [f (File/createTempFile "test" "properties")] 311.57 - (spit f "a=b\nc=d") 311.58 - (is (= {"a" "b" "c" "d"} 311.59 - (read-properties f))))) 311.60 - 311.61 -(deftest test-write-properties 311.62 - (let [f (File/createTempFile "test" "properties")] 311.63 - (write-properties [['a 'b] ['c 'd]] f) 311.64 - (is (= {"a" "b" "c" "d"} 311.65 - (read-properties f))))) 311.66 -
312.1 --- a/src/clojure/contrib/test_contrib/test_prxml.clj Sat Aug 21 06:25:44 2010 -0400 312.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 312.3 @@ -1,10 +0,0 @@ 312.4 -(ns clojure.contrib.test-prxml 312.5 - (:use clojure.test clojure.contrib.prxml)) 312.6 - 312.7 -(deftest prxml-basic 312.8 - (is (= "<p>Hello, World!</p>" 312.9 - (with-out-str (prxml [:p "Hello, World!"]))))) 312.10 - 312.11 -(deftest prxml-escaping 312.12 - (is (= "<a href=\"foo&bar\">foo<bar</a>" 312.13 - (with-out-str (prxml [:a {:href "foo&bar"} "foo<bar"])))))
313.1 --- a/src/clojure/contrib/test_contrib/test_repl_utils.clj Sat Aug 21 06:25:44 2010 -0400 313.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 313.3 @@ -1,20 +0,0 @@ 313.4 -(ns clojure.contrib.test-repl-utils 313.5 - (:use clojure.test 313.6 - clojure.contrib.repl-utils)) 313.7 - 313.8 -(deftest test-apropos 313.9 - (testing "with a regular expression" 313.10 - (is (= '[defmacro] (apropos #"^defmacro$"))) 313.11 - (is (some '#{defmacro} (apropos #"def.acr."))) 313.12 - (is (= [] (apropos #"nothing-has-this-name")))) 313.13 - 313.14 - 313.15 - (testing "with a string" 313.16 - (is (some '#{defmacro} (apropos "defmacro"))) 313.17 - (is (some '#{defmacro} (apropos "efmac"))) 313.18 - (is (= [] (apropos "nothing-has-this-name")))) 313.19 - 313.20 - (testing "with a symbol" 313.21 - (is (some '#{defmacro} (apropos 'defmacro))) 313.22 - (is (some '#{defmacro} (apropos 'efmac))) 313.23 - (is (= [] (apropos 'nothing-has-this-name)))))
314.1 --- a/src/clojure/contrib/test_contrib/test_seq.clj Sat Aug 21 06:25:44 2010 -0400 314.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 314.3 @@ -1,128 +0,0 @@ 314.4 -(ns clojure.contrib.test-seq 314.5 - (:use clojure.test) 314.6 - (:require [clojure.contrib.seq :as seq])) 314.7 - 314.8 - 314.9 -(deftest test-positions 314.10 - (are [expected pred coll] (= expected (seq/positions pred coll)) 314.11 - [2] string? [:a :b "c"] 314.12 - () :d [:a :b :c] 314.13 - [0 2] #{:d} [:d :a :d :a])) 314.14 - 314.15 -;Upon further inspection, flatten behaves... wierd. 314.16 -;These tests are what passes on August 7, 2009 314.17 -(deftest test-flatten-present 314.18 - (are [expected nested-val] (= (seq/flatten nested-val) expected) 314.19 - ;simple literals 314.20 - [] nil 314.21 - [] 1 314.22 - [] 'test 314.23 - [] :keyword 314.24 - [] 1/2 314.25 - [] #"[\r\n]" 314.26 - [] true 314.27 - [] false 314.28 - ;vectors 314.29 - [1 2 3 4 5] [[1 2] [3 4 [5]]] 314.30 - [1 2 3 4 5] [1 2 3 4 5] 314.31 - [#{1 2} 3 4 5] [#{1 2} 3 4 5] 314.32 - ;sets 314.33 - [] #{} 314.34 - [] #{#{1 2} 3 4 5} 314.35 - [] #{1 2 3 4 5} 314.36 - [] #{#{1 2} 3 4 5} 314.37 - ;lists 314.38 - [] '() 314.39 - [1 2 3 4 5] `(1 2 3 4 5) 314.40 - ;maps 314.41 - [] {:a 1 :b 2} 314.42 - [:a 1 :b 2] (seq {:a 1 :b 2}) 314.43 - [] {[:a :b] 1 :c 2} 314.44 - [:a :b 1 :c 2] (seq {[:a :b] 1 :c 2}) 314.45 - [:a 1 2 :b 3] (seq {:a [1 2] :b 3}) 314.46 - ;Strings 314.47 - [] "12345" 314.48 - [\1 \2 \3 \4 \5] (seq "12345") 314.49 - ;fns 314.50 - [] count 314.51 - [count even? odd?] [count even? odd?])) 314.52 - 314.53 -(deftest test-separate 314.54 - (are [test-seq] (= (seq/separate even? test-seq) [[2 4] [1 3 5]]) 314.55 - [1 2 3 4 5] 314.56 - #{1 2 3 4 5} 314.57 - '(1 2 3 4 5))) 314.58 - 314.59 -;Note - this does not make sense for maps and sets, because order is expected 314.60 -(deftest test-indexed 314.61 - (are [expected test-seq] (= (seq/indexed test-seq) expected) 314.62 - [[0 :a] [1 :b] [2 :c] [3 :d]] [:a :b :c :d] 314.63 - [[0 :a] [1 :b] [2 :c] [3 :d]] '(:a :b :c :d) 314.64 - [[0 \1] [1 \2] [2 \3] [3 \4]] "1234")) 314.65 - 314.66 -(deftest test-group-by 314.67 - (is (= (seq/group-by even? [1 2 3 4 5]) 314.68 - {false [1 3 5], true [2 4]}))) 314.69 - 314.70 -;Note - this does not make sense for maps and sets, because order is expected 314.71 -(deftest test-partition-by 314.72 - (are [test-seq] (= (seq/partition-by (comp even? count) test-seq) 314.73 - [["a"] ["bb" "cccc" "dd"] ["eee" "f"] ["" "hh"]]) 314.74 - ["a" "bb" "cccc" "dd" "eee" "f" "" "hh"] 314.75 - '("a" "bb" "cccc" "dd" "eee" "f" "" "hh")) 314.76 - (is (=(partition-by #{\a \e \i \o \u} "abcdefghijklm") 314.77 - [[\a] [\b \c \d] [\e] [\f \g \h] [\i] [\j \k \l \m]]))) 314.78 - 314.79 -(deftest test-frequencies 314.80 - (are [expected test-seq] (= (seq/frequencies test-seq) expected) 314.81 - {\p 2, \s 4, \i 4, \m 1} "mississippi" 314.82 - {1 4 2 2 3 1} [1 1 1 1 2 2 3] 314.83 - {1 4 2 2 3 1} '(1 1 1 1 2 2 3))) 314.84 - 314.85 -;Note - this does not make sense for maps and sets, because order is expected 314.86 -;This is a key differnce between reductions and reduce. 314.87 -(deftest test-reductions 314.88 - (is (= (seq/reductions + [1 2 3 4 5]) 314.89 - [1 3 6 10 15])) 314.90 - (is (= (reductions + 10 [1 2 3 4 5]) 314.91 - [10 11 13 16 20 25]))) 314.92 - 314.93 -;Note - this does not make sense for maps and sets, because order is expected 314.94 -(deftest test-rotations 314.95 - (is (= (seq/rotations [1 2 3 4]) 314.96 - [[1 2 3 4] 314.97 - [2 3 4 1] 314.98 - [3 4 1 2] 314.99 - [4 1 2 3]]))) 314.100 - 314.101 -;Note - this does not make sense for maps and sets, because order is expected 314.102 -(deftest test-partition-all 314.103 - (is (= (seq/partition-all 4 [1 2 3 4 5 6 7 8 9]) 314.104 - [[1 2 3 4] [5 6 7 8] [9]])) 314.105 - (is (= (seq/partition-all 4 2 [1 2 3 4 5 6 7 8 9]) 314.106 - [[1 2 3 4] [3 4 5 6] [5 6 7 8] [7 8 9] [9]]))) 314.107 - 314.108 -;Thanks to Andy Fingerhut for the idea of testing invariants 314.109 -(deftest test-shuffle-invariants 314.110 - (is (= (count (seq/shuffle [1 2 3 4])) 4)) 314.111 - (let [shuffled-seq (seq/shuffle [1 2 3 4])] 314.112 - (is (every? #{1 2 3 4} shuffled-seq)))) 314.113 - 314.114 -;Thanks to Andy Fingerhut for the idea of testing invariants 314.115 -(deftest test-rand-elt-invariants 314.116 - (let [elt (seq/rand-elt [:a :b :c :d])] 314.117 - (is (#{:a :b :c :d} elt)))) 314.118 - 314.119 -;Note - this does not make sense for maps and sets, because order is expected 314.120 -(deftest test-find-first 314.121 - (is (= (seq/find-first even? [1 2 3 4 5]) 2)) 314.122 - (is (= (seq/find-first even? '(1 2 3 4 5)) 2))) 314.123 - 314.124 -(deftest test-includes 314.125 - (are [coll k] (false? (seq/includes? coll k)) 314.126 - [1 2 3] 0 314.127 - [] nil 314.128 - [:a :b] :c) 314.129 - (are [coll k] (true? (seq/includes? coll k)) 314.130 - [1 2 3] 1 314.131 - [:a :b] :b))
315.1 --- a/src/clojure/contrib/test_contrib/test_shell.clj Sat Aug 21 06:25:44 2010 -0400 315.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 315.3 @@ -1,41 +0,0 @@ 315.4 -(ns clojure.contrib.test-shell 315.5 - (:use clojure.test 315.6 - clojure.contrib.shell) 315.7 - (:import (java.io File))) 315.8 - 315.9 -; workaroung to access private parse-args. Better way? 315.10 -(def parse-args ((ns-interns 'clojure.contrib.shell) 'parse-args)) 315.11 -(def as-file ((ns-interns 'clojure.contrib.shell) 'as-file)) 315.12 -(def as-env-string ((ns-interns 'clojure.contrib.shell) 'as-env-string)) 315.13 - 315.14 -(deftest test-parse-args 315.15 - (are [x y] (= x y) 315.16 - {:cmd [nil] :out "UTF-8" :dir nil :env nil} (parse-args []) 315.17 - {:cmd ["ls"] :out "UTF-8" :dir nil :env nil} (parse-args ["ls"]) 315.18 - {:cmd ["ls" "-l"] :out "UTF-8" :dir nil :env nil} (parse-args ["ls" "-l"]) 315.19 - {:cmd ["ls"] :out "ISO-8859-1" :dir nil :env nil} (parse-args ["ls" :out "ISO-8859-1"]) 315.20 -)) 315.21 - 315.22 -(deftest test-with-sh-dir 315.23 - (are [x y] (= x y) 315.24 - nil *sh-dir* 315.25 - "foo" (with-sh-dir "foo" *sh-dir*))) 315.26 - 315.27 -(deftest test-with-sh-env 315.28 - (are [x y] (= x y) 315.29 - nil *sh-env* 315.30 - {:KEY "VAL"} (with-sh-env {:KEY "VAL"} *sh-env*))) 315.31 - 315.32 -(deftest test-as-env-string 315.33 - (are [x y] (= x y) 315.34 - nil (as-env-string nil) 315.35 - ["FOO=BAR"] (seq (as-env-string {"FOO" "BAR"})) 315.36 - ["FOO_SYMBOL=BAR"] (seq (as-env-string {'FOO_SYMBOL "BAR"})) 315.37 - ["FOO_KEYWORD=BAR"] (seq (as-env-string {:FOO_KEYWORD "BAR"})))) 315.38 - 315.39 - 315.40 -(deftest test-as-file 315.41 - (are [x y] (= x y) 315.42 - (File. "foo") (as-file "foo") 315.43 - nil (as-file nil) 315.44 - (File. "bar") (as-file (File. "bar")))) 315.45 \ No newline at end of file
316.1 --- a/src/clojure/contrib/test_contrib/test_sql.clj Sat Aug 21 06:25:44 2010 -0400 316.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 316.3 @@ -1,207 +0,0 @@ 316.4 -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 316.5 -;; distribution terms for this software are covered by the Eclipse Public 316.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 316.7 -;; be found in the file epl-v10.html at the root of this distribution. By 316.8 -;; using this software in any fashion, you are agreeing to be bound by the 316.9 -;; terms of this license. You must not remove this notice, or any other, 316.10 -;; from this software. 316.11 -;; 316.12 -;; test.clj 316.13 -;; 316.14 -;; test/example for clojure.contrib.sql 316.15 -;; 316.16 -;; scgilardi (gmail) 316.17 -;; Created 13 September 2008 316.18 - 316.19 -(ns clojure.contrib.test-sql 316.20 - (:use [clojure.contrib.sql :as sql :only ()])) 316.21 - 316.22 -(def db {:classname "org.apache.derby.jdbc.EmbeddedDriver" 316.23 - :subprotocol "derby" 316.24 - :subname "/tmp/clojure.contrib.sql.test.db" 316.25 - :create true}) 316.26 - 316.27 -(defn create-fruit 316.28 - "Create a table" 316.29 - [] 316.30 - (sql/create-table 316.31 - :fruit 316.32 - [:name "varchar(32)" "PRIMARY KEY"] 316.33 - [:appearance "varchar(32)"] 316.34 - [:cost :int] 316.35 - [:grade :real])) 316.36 - 316.37 -(defn drop-fruit 316.38 - "Drop a table" 316.39 - [] 316.40 - (try 316.41 - (sql/drop-table :fruit) 316.42 - (catch Exception _))) 316.43 - 316.44 -(defn insert-rows-fruit 316.45 - "Insert complete rows" 316.46 - [] 316.47 - (sql/insert-rows 316.48 - :fruit 316.49 - ["Apple" "red" 59 87] 316.50 - ["Banana" "yellow" 29 92.2] 316.51 - ["Peach" "fuzzy" 139 90.0] 316.52 - ["Orange" "juicy" 89 88.6])) 316.53 - 316.54 -(defn insert-values-fruit 316.55 - "Insert rows with values for only specific columns" 316.56 - [] 316.57 - (sql/insert-values 316.58 - :fruit 316.59 - [:name :cost] 316.60 - ["Mango" 722] 316.61 - ["Feijoa" 441])) 316.62 - 316.63 -(defn insert-records-fruit 316.64 - "Insert records, maps from keys specifying columns to values" 316.65 - [] 316.66 - (sql/insert-records 316.67 - :fruit 316.68 - {:name "Pomegranate" :appearance "fresh" :cost 585} 316.69 - {:name "Kiwifruit" :grade 93})) 316.70 - 316.71 -(defn db-write 316.72 - "Write initial values to the database as a transaction" 316.73 - [] 316.74 - (sql/with-connection db 316.75 - (sql/transaction 316.76 - (drop-fruit) 316.77 - (create-fruit) 316.78 - (insert-rows-fruit) 316.79 - (insert-values-fruit) 316.80 - (insert-records-fruit))) 316.81 - nil) 316.82 - 316.83 -(defn db-read 316.84 - "Read the entire fruit table" 316.85 - [] 316.86 - (sql/with-connection db 316.87 - (sql/with-query-results res 316.88 - ["SELECT * FROM fruit"] 316.89 - (doseq [rec res] 316.90 - (println rec))))) 316.91 - 316.92 -(defn db-update-appearance-cost 316.93 - "Update the appearance and cost of the named fruit" 316.94 - [name appearance cost] 316.95 - (sql/update-values 316.96 - :fruit 316.97 - ["name=?" name] 316.98 - {:appearance appearance :cost cost})) 316.99 - 316.100 -(defn db-update 316.101 - "Update two fruits as a transaction" 316.102 - [] 316.103 - (sql/with-connection db 316.104 - (sql/transaction 316.105 - (db-update-appearance-cost "Banana" "bruised" 14) 316.106 - (db-update-appearance-cost "Feijoa" "green" 400))) 316.107 - nil) 316.108 - 316.109 -(defn db-update-or-insert 316.110 - "Updates or inserts a fruit" 316.111 - [record] 316.112 - (sql/with-connection db 316.113 - (sql/update-or-insert-values 316.114 - :fruit 316.115 - ["name=?" (:name record)] 316.116 - record))) 316.117 - 316.118 -(defn db-read-all 316.119 - "Return all the rows of the fruit table as a vector" 316.120 - [] 316.121 - (sql/with-connection db 316.122 - (sql/with-query-results res 316.123 - ["SELECT * FROM fruit"] 316.124 - (into [] res)))) 316.125 - 316.126 -(defn db-grade-range 316.127 - "Print rows describing fruit that are within a grade range" 316.128 - [min max] 316.129 - (sql/with-connection db 316.130 - (sql/with-query-results res 316.131 - [(str "SELECT name, cost, grade " 316.132 - "FROM fruit " 316.133 - "WHERE grade >= ? AND grade <= ?") 316.134 - min max] 316.135 - (doseq [rec res] 316.136 - (println rec))))) 316.137 - 316.138 -(defn db-grade-a 316.139 - "Print rows describing all grade a fruit (grade between 90 and 100)" 316.140 - [] 316.141 - (db-grade-range 90 100)) 316.142 - 316.143 -(defn db-get-tables 316.144 - "Demonstrate getting table info" 316.145 - [] 316.146 - (sql/with-connection db 316.147 - (into [] 316.148 - (resultset-seq 316.149 - (-> (sql/connection) 316.150 - (.getMetaData) 316.151 - (.getTables nil nil nil (into-array ["TABLE" "VIEW"]))))))) 316.152 - 316.153 -(defn db-exception 316.154 - "Demonstrate rolling back a partially completed transaction on exception" 316.155 - [] 316.156 - (sql/with-connection db 316.157 - (sql/transaction 316.158 - (sql/insert-values 316.159 - :fruit 316.160 - [:name :appearance] 316.161 - ["Grape" "yummy"] 316.162 - ["Pear" "bruised"]) 316.163 - ;; at this point the insert-values call is complete, but the transaction 316.164 - ;; is not. the exception will cause it to roll back leaving the database 316.165 - ;; untouched. 316.166 - (throw (Exception. "sql/test exception"))))) 316.167 - 316.168 -(defn db-sql-exception 316.169 - "Demonstrate an sql exception" 316.170 - [] 316.171 - (sql/with-connection db 316.172 - (sql/transaction 316.173 - (sql/insert-values 316.174 - :fruit 316.175 - [:name :appearance] 316.176 - ["Grape" "yummy"] 316.177 - ["Pear" "bruised"] 316.178 - ["Apple" "strange" "whoops"])))) 316.179 - 316.180 -(defn db-batchupdate-exception 316.181 - "Demonstrate a batch update exception" 316.182 - [] 316.183 - (sql/with-connection db 316.184 - (sql/transaction 316.185 - (sql/do-commands 316.186 - "DROP TABLE fruit" 316.187 - "DROP TABLE fruit")))) 316.188 - 316.189 -(defn db-rollback 316.190 - "Demonstrate a rollback-only trasaction" 316.191 - [] 316.192 - (sql/with-connection db 316.193 - (sql/transaction 316.194 - (prn "is-rollback-only" (sql/is-rollback-only)) 316.195 - (sql/set-rollback-only) 316.196 - (sql/insert-values 316.197 - :fruit 316.198 - [:name :appearance] 316.199 - ["Grape" "yummy"] 316.200 - ["Pear" "bruised"]) 316.201 - (prn "is-rollback-only" (sql/is-rollback-only)) 316.202 - (sql/with-query-results res 316.203 - ["SELECT * FROM fruit"] 316.204 - (doseq [rec res] 316.205 - (println rec)))) 316.206 - (prn) 316.207 - (sql/with-query-results res 316.208 - ["SELECT * FROM fruit"] 316.209 - (doseq [rec res] 316.210 - (println rec)))))
317.1 --- a/src/clojure/contrib/test_contrib/test_string.clj Sat Aug 21 06:25:44 2010 -0400 317.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 317.3 @@ -1,124 +0,0 @@ 317.4 -(ns clojure.contrib.test-string 317.5 - (:require [clojure.contrib.string :as s]) 317.6 - (:use clojure.test)) 317.7 - 317.8 -(deftest t-codepoints 317.9 - (is (= (list 102 111 111 65536 98 97 114) 317.10 - (s/codepoints "foo\uD800\uDC00bar")) 317.11 - "Handles Unicode supplementary characters")) 317.12 - 317.13 -(deftest t-escape 317.14 - (is (= "<foo&bar>" 317.15 - (s/escape {\& "&" \< "<" \> ">"} "<foo&bar>"))) 317.16 - (is (= " \\\"foo\\\" " 317.17 - (s/escape {\" "\\\""} " \"foo\" " ))) 317.18 - (is (= "faabor" (s/escape {\a \o, \o \a} "foobar")))) 317.19 - 317.20 -(deftest t-blank 317.21 - (is (s/blank? nil)) 317.22 - (is (s/blank? "")) 317.23 - (is (s/blank? " ")) 317.24 - (is (s/blank? " \t \n \r ")) 317.25 - (is (not (s/blank? " foo ")))) 317.26 - 317.27 -(deftest t-take 317.28 - (is (= "foo" (s/take 3 "foobar"))) 317.29 - (is (= "foobar" (s/take 7 "foobar"))) 317.30 - (is (= "" (s/take 0 "foo")))) 317.31 - 317.32 -(deftest t-drop 317.33 - (is (= "bar" (s/drop 3 "foobar"))) 317.34 - (is (= "" (s/drop 9 "foobar"))) 317.35 - (is (= "foobar" (s/drop 0 "foobar")))) 317.36 - 317.37 -(deftest t-butlast 317.38 - (is (= "foob" (s/butlast 2 "foobar"))) 317.39 - (is (= "" (s/butlast 9 "foobar"))) 317.40 - (is (= "foobar" (s/butlast 0 "foobar")))) 317.41 - 317.42 -(deftest t-tail 317.43 - (is (= "ar" (s/tail 2 "foobar"))) 317.44 - (is (= "foobar" (s/tail 9 "foobar"))) 317.45 - (is (= "" (s/tail 0 "foobar")))) 317.46 - 317.47 -(deftest t-repeat 317.48 - (is (= "foofoofoo" (s/repeat 3 "foo")))) 317.49 - 317.50 -(deftest t-reverse 317.51 - (is (= "tab" (s/reverse "bat")))) 317.52 - 317.53 -(deftest t-replace 317.54 - (is (= "faabar" (s/replace-char \o \a "foobar"))) 317.55 - (is (= "barbarbar" (s/replace-str "foo" "bar" "foobarfoo"))) 317.56 - (is (= "FOObarFOO" (s/replace-by #"foo" s/upper-case "foobarfoo")))) 317.57 - 317.58 -(deftest t-replace-first 317.59 - (is (= "barbarfoo" (s/replace-first-re #"foo" "bar" "foobarfoo"))) 317.60 - (is (= "FOObarfoo" (s/replace-first-by #"foo" s/upper-case "foobarfoo")))) 317.61 - 317.62 -(deftest t-partition 317.63 - (is (= (list "" "abc" "123" "def") 317.64 - (s/partition #"[a-z]+" "abc123def")))) 317.65 - 317.66 -(deftest t-join 317.67 - (is (= "1,2,3" (s/join \, [1 2 3]))) 317.68 - (is (= "" (s/join \, []))) 317.69 - (is (= "1 and-a 2 and-a 3" (s/join " and-a " [1 2 3])))) 317.70 - 317.71 -(deftest t-chop 317.72 - (is (= "fo" (s/chop "foo"))) 317.73 - (is (= "") (s/chop "f")) 317.74 - (is (= "") (s/chop ""))) 317.75 - 317.76 -(deftest t-chomp 317.77 - (is (= "foo" (s/chomp "foo\n"))) 317.78 - (is (= "foo" (s/chomp "foo\r\n"))) 317.79 - (is (= "foo" (s/chomp "foo"))) 317.80 - (is (= "" (s/chomp "")))) 317.81 - 317.82 -(deftest t-swap-case 317.83 - (is (= "fOO!bAR" (s/swap-case "Foo!Bar"))) 317.84 - (is (= "" (s/swap-case "")))) 317.85 - 317.86 -(deftest t-capitalize 317.87 - (is (= "Foobar" (s/capitalize "foobar"))) 317.88 - (is (= "Foobar" (s/capitalize "FOOBAR")))) 317.89 - 317.90 -(deftest t-ltrim 317.91 - (is (= "foo " (s/ltrim " foo "))) 317.92 - (is (= "" (s/ltrim " ")))) 317.93 - 317.94 -(deftest t-rtrim 317.95 - (is (= " foo" (s/rtrim " foo "))) 317.96 - (is (= "" (s/rtrim " ")))) 317.97 - 317.98 -(deftest t-split-lines 317.99 - (is (= (list "one" "two" "three") 317.100 - (s/split-lines "one\ntwo\r\nthree"))) 317.101 - (is (= (list "foo") (s/split-lines "foo")))) 317.102 - 317.103 -(deftest t-upper-case 317.104 - (is (= "FOOBAR" (s/upper-case "Foobar")))) 317.105 - 317.106 -(deftest t-lower-case 317.107 - (is (= "foobar" (s/lower-case "FooBar")))) 317.108 - 317.109 -(deftest t-trim 317.110 - (is (= "foo" (s/trim " foo \r\n")))) 317.111 - 317.112 -(deftest t-substring 317.113 - (is (s/substring? "foo" "foobar")) 317.114 - (is (not (s/substring? "baz" "foobar")))) 317.115 - 317.116 -(deftest t-get 317.117 - (is (= \o (s/get "foo" 1)))) 317.118 - 317.119 -(deftest t-as-str 317.120 - (testing "keyword to string" 317.121 - (is (= "foo") (s/as-str :foo))) 317.122 - (testing "symbol to string" 317.123 - (is (= "foo") (s/as-str 'foo))) 317.124 - (testing "string to string" 317.125 - (is (= "foo") (s/as-str "foo"))) 317.126 - (testing "stringifying non-namish things" 317.127 - (is (= "42") (s/as-str 42))))
318.1 --- a/src/clojure/contrib/test_contrib/test_strint.clj Sat Aug 21 06:25:44 2010 -0400 318.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 318.3 @@ -1,41 +0,0 @@ 318.4 -; Copyright (c) Stuart Halloway, 2010-. All rights reserved. 318.5 - 318.6 -; The use and distribution terms for this software are covered by the 318.7 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 318.8 -; which can be found in the file epl-v10.html at the root of this 318.9 -; distribution. 318.10 -; By using this software in any fashion, you are agreeing to be bound by 318.11 -; the terms of this license. 318.12 -; You must not remove this notice, or any other, from this software. 318.13 - 318.14 -(ns clojure.contrib.test-strint 318.15 - (:use clojure.test) 318.16 - (:use [clojure.contrib strint with-ns])) 318.17 - 318.18 -(def silent-read (with-ns 'clojure.contrib.strint silent-read)) 318.19 -(def interpolate (with-ns 'clojure.contrib.strint interpolate)) 318.20 - 318.21 -(deftest test-silent-read 318.22 - (testing "reading a valid form returns [read form, rest of string]" 318.23 - (is (= [[1] "[2]"] (silent-read "[1][2]")))) 318.24 - (testing "reading an invalid form returns nil" 318.25 - (is (= nil (silent-read "["))))) 318.26 - 318.27 -(deftest test-interpolate 318.28 - (testing "a plain old string" 318.29 - (is (= ["a plain old string"] (interpolate "a plain old string")))) 318.30 - (testing "some value replacement forms" 318.31 - (is (= '["" foo " and " bar ""] (interpolate "~{foo} and ~{bar}")))) 318.32 - (testing "some fn-calling forms" 318.33 - (is (= '["" (+ 1 2) " and " (vector 3) ""] (interpolate "~(+ 1 2) and ~(vector 3)"))))) 318.34 - 318.35 -(deftest test-<< 318.36 - (testing "docstring examples" 318.37 - (let [v 30.5 318.38 - m {:a [1 2 3]}] 318.39 - (is (= "This trial required 30.5ml of solution." 318.40 - (<< "This trial required ~{v}ml of solution."))) 318.41 - (is (= "There are 30 days in November." 318.42 - (<< "There are ~(int v) days in November."))) 318.43 - (is (= "The total for your order is $6." 318.44 - (<< "The total for your order is $~(->> m :a (apply +))."))))))
319.1 --- a/src/clojure/contrib/test_contrib/test_trace.clj Sat Aug 21 06:25:44 2010 -0400 319.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 319.3 @@ -1,16 +0,0 @@ 319.4 -(ns clojure.contrib.test-trace 319.5 - (:use clojure.test 319.6 - clojure.contrib.trace)) 319.7 - 319.8 -(deftrace call-myself [n] 319.9 - (when-not (< n 1) 319.10 - (call-myself (dec n)))) 319.11 - 319.12 -(deftest test-tracing-a-function-that-calls-itself 319.13 - (let [output (with-out-str (call-myself 1))] 319.14 - (is (re-find #"^TRACE t\d+: (call-myself 1)\nTRACE t\d+: | (call-myself 0)\nTRACE t\d+: | => nil\nTRACE t\d+: => nil$" 319.15 - output)))) 319.16 - 319.17 -;(deftest dotrace-on-core 319.18 -; (let [output (with-out-str (dotrace [mod] (mod 11 5)))] 319.19 -; (is (re-find #"\(mod 11 5\)" output))))
320.1 --- a/src/clojure/contrib/test_contrib/test_with_ns.clj Sat Aug 21 06:25:44 2010 -0400 320.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 320.3 @@ -1,18 +0,0 @@ 320.4 -(ns clojure.contrib.test-with-ns 320.5 - (:use clojure.test 320.6 - clojure.contrib.with-ns)) 320.7 - 320.8 -(deftest test-namespace-gets-removed 320.9 - (let [all-ns-names (fn [] (map #(.name %) (all-ns)))] 320.10 - (testing "unexceptional return" 320.11 - (let [ns-name (with-temp-ns (ns-name *ns*))] 320.12 - (is (not (some #{ns-name} (all-ns-names)))))) 320.13 - (testing "when an exception is thrown" 320.14 - (let [ns-name-str 320.15 - (try 320.16 - (with-temp-ns 320.17 - (throw (RuntimeException. (str (ns-name *ns*))))) 320.18 - (catch clojure.lang.Compiler$CompilerException e 320.19 - (-> e .getCause .getMessage)))] 320.20 - (is (re-find #"^sym.*$" ns-name-str)) 320.21 - (is (not (some #{(symbol ns-name-str)} (all-ns-names))))))))
321.1 --- a/src/clojure/contrib/test_contrib/types/examples.clj Sat Aug 21 06:25:44 2010 -0400 321.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 321.3 @@ -1,152 +0,0 @@ 321.4 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 321.5 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 321.6 -;; 321.7 -;; Application examples for data types 321.8 -;; 321.9 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 321.10 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 321.11 - 321.12 -(ns 321.13 - #^{:author "Konrad Hinsen" 321.14 - :skip-wiki true 321.15 - :doc "Examples for data type definitions"} 321.16 - clojure.contrib.types.examples 321.17 - (:refer-clojure :exclude (deftype)) 321.18 - (:use [clojure.contrib.types 321.19 - :only (deftype defadt match)]) 321.20 - (:require [clojure.contrib.generic.collection :as gc]) 321.21 - (:require [clojure.contrib.generic.functor :as gf])) 321.22 - 321.23 -; 321.24 -; Multisets implemented as maps to integers 321.25 -; 321.26 - 321.27 -; The most basic type definition. A more elaborate version could add 321.28 -; a constructor that verifies that its argument is a map with integer values. 321.29 -(deftype ::multiset multiset 321.30 - "Multiset (demo implementation)") 321.31 - 321.32 -; Some set operations generalized to multisets 321.33 -; Note that the multiset constructor is nowhere called explicitly, as the 321.34 -; map operations all preserve the metadata. 321.35 -(defmethod gc/conj ::multiset 321.36 - ([ms x] 321.37 - (assoc ms x (inc (get ms x 0)))) 321.38 - ([ms x & xs] 321.39 - (reduce gc/conj (gc/conj ms x) xs))) 321.40 - 321.41 -(defmulti union (fn [& sets] (type (first sets)))) 321.42 - 321.43 -(defmethod union clojure.lang.IPersistentSet 321.44 - [& sets] 321.45 - (apply clojure.set/union sets)) 321.46 - 321.47 -; Note: a production-quality implementation should accept standard sets 321.48 -; and perhaps other collections for its second argument. 321.49 -(defmethod union ::multiset 321.50 - ([ms] ms) 321.51 - ([ms1 ms2] 321.52 - (letfn [(add-item [ms [item n]] 321.53 - (assoc ms item (+ n (get ms item 0))))] 321.54 - (reduce add-item ms1 ms2))) 321.55 - ([ms1 ms2 & mss] 321.56 - (reduce union (union ms1 ms2) mss))) 321.57 - 321.58 -; Let's use it: 321.59 -(gc/conj #{} :a :a :b :c) 321.60 -(gc/conj (multiset {}) :a :a :b :c) 321.61 - 321.62 -(union #{:a :b} #{:b :c}) 321.63 -(union (multiset {:a 1 :b 1}) (multiset {:b 1 :c 2})) 321.64 - 321.65 -; 321.66 -; A simple tree structure defined as an algebraic data type 321.67 -; 321.68 -(defadt ::tree 321.69 - empty-tree 321.70 - (leaf value) 321.71 - (node left-tree right-tree)) 321.72 - 321.73 -(def a-tree (node (leaf :a) 321.74 - (node (leaf :b) 321.75 - (leaf :c)))) 321.76 - 321.77 -(defn depth 321.78 - [t] 321.79 - (match t 321.80 - empty-tree 0 321.81 - (leaf _) 1 321.82 - (node l r) (inc (max (depth l) (depth r))))) 321.83 - 321.84 -(depth empty-tree) 321.85 -(depth (leaf 42)) 321.86 -(depth a-tree) 321.87 - 321.88 -; Algebraic data types with multimethods: fmap on a tree 321.89 -(defmethod gf/fmap ::tree 321.90 - [f t] 321.91 - (match t 321.92 - empty-tree empty-tree 321.93 - (leaf v) (leaf (f v)) 321.94 - (node l r) (node (gf/fmap f l) (gf/fmap f r)))) 321.95 - 321.96 -(gf/fmap str a-tree) 321.97 - 321.98 -; 321.99 -; Nonsense examples to illustrate all the features of match 321.100 -; for type constructors. 321.101 -; 321.102 -(defadt ::foo 321.103 - (bar a b c)) 321.104 - 321.105 -(defn foo-to-int 321.106 - [a-foo] 321.107 - (match a-foo 321.108 - (bar x x x) x 321.109 - (bar 0 x y) (+ x y) 321.110 - (bar 1 2 3) -1 321.111 - (bar a b 1) (* a b) 321.112 - :else 42)) 321.113 - 321.114 -(foo-to-int (bar 0 0 0)) ; 0 321.115 -(foo-to-int (bar 0 5 6)) ; 11 321.116 -(foo-to-int (bar 1 2 3)) ; -1 321.117 -(foo-to-int (bar 3 3 1)) ; 9 321.118 -(foo-to-int (bar 0 3 1)) ; 4 321.119 -(foo-to-int (bar 10 20 30)) ; 42 321.120 - 321.121 -; 321.122 -; Match can also be used for lists, vectors, and maps. Note that since 321.123 -; algebraic data types are represented as maps, they can be matched 321.124 -; either with their type constructor and positional arguments, or 321.125 -; with a map template. 321.126 -; 321.127 - 321.128 -; Tree depth once again with map templates 321.129 -(defn depth 321.130 - [t] 321.131 - (match t 321.132 - empty-tree 0 321.133 - {:value _} 1 321.134 - {:left-tree l :right-tree r} (inc (max (depth l) (depth r))))) 321.135 - 321.136 -(depth empty-tree) 321.137 -(depth (leaf 42)) 321.138 -(depth a-tree) 321.139 - 321.140 -; Match for lists, vectors, and maps: 321.141 - 321.142 -(for [x ['(1 2 3) 321.143 - [1 2 3] 321.144 - {:x 1 :y 2 :z 3} 321.145 - '(1 1 1) 321.146 - [2 1 2] 321.147 - {:x 1 :y 1 :z 2}]] 321.148 - (match x 321.149 - '(a a a) 'list-of-three-equal-values 321.150 - '(a b c) 'list 321.151 - [a a a] 'vector-of-three-equal-values 321.152 - [a b a] 'vector-of-three-with-first-and-last-equal 321.153 - [a b c] 'vector 321.154 - {:x a :y z} 'map-with-x-equal-y 321.155 - {} 'any-map))
322.1 --- a/src/clojure/contrib/test_is.clj Sat Aug 21 06:25:44 2010 -0400 322.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 322.3 @@ -1,119 +0,0 @@ 322.4 -;;; test_is.clj: Compatibility layer for old clojure.contrib.test-is 322.5 - 322.6 -;; by Stuart Sierra, http://stuartsierra.com/ 322.7 -;; August 28, 2009 322.8 - 322.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 322.10 -;; and distribution terms for this software are covered by the Eclipse 322.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 322.12 -;; which can be found in the file epl-v10.html at the root of this 322.13 -;; distribution. By using this software in any fashion, you are 322.14 -;; agreeing to be bound by the terms of this license. You must not 322.15 -;; remove this notice, or any other, from this software. 322.16 - 322.17 -;; DEPRECATED in 1.2: Moved to clojure.test 322.18 - 322.19 -(ns ^{:deprecated "1.2" 322.20 - :doc "Backwards-compatibility for clojure.contrib.test-is 322.21 - 322.22 - The clojure.contrib.test-is library moved from Contrib into the 322.23 - Clojure distribution as clojure.test. 322.24 - 322.25 - This happened on or around clojure-contrib Git commit 322.26 - 82cf0409d0fcb71be477ebfc4da18ee2128a2ad1 on June 25, 2009. 322.27 - 322.28 - This file makes the clojure.test interface available under the old 322.29 - namespace clojure.contrib.test-is. 322.30 - 322.31 - This includes support for the old syntax of the 'are' macro. 322.32 - 322.33 - This was suggested by Howard Lewis Ship in ticket #26, 322.34 - http://www.assembla.com/spaces/clojure-contrib/tickets/26" 322.35 - :author "Stuart Sierra"} 322.36 - clojure.contrib.test-is 322.37 - (:require clojure.test 322.38 - [clojure.walk :as walk])) 322.39 - 322.40 - 322.41 -;;; COPY INTERNED VARS (EXCEPT are) FROM clojure.test 322.42 - 322.43 -(doseq [v (disj (set (vals (ns-interns 'clojure.test))) 322.44 - #'clojure.test/are)] 322.45 - (intern *ns* (with-meta (:name (meta v)) (meta v)) (var-get v))) 322.46 - 322.47 - 322.48 -;;; REDEFINE OLD clojure.contrib.template 322.49 - 322.50 -(defn find-symbols 322.51 - "Recursively finds all symbols in form." 322.52 - [form] 322.53 - (distinct (filter symbol? (tree-seq coll? seq form)))) 322.54 - 322.55 -(defn find-holes 322.56 - "Recursively finds all symbols starting with _ in form." 322.57 - [form] 322.58 - (sort (distinct (filter #(.startsWith (name %) "_") 322.59 - (find-symbols form))))) 322.60 - 322.61 -(defn find-pure-exprs 322.62 - "Recursively finds all sub-expressions in form that do not contain 322.63 - any symbols starting with _" 322.64 - [form] 322.65 - (filter #(and (list? %) 322.66 - (empty? (find-holes %))) 322.67 - (tree-seq seq? seq form))) 322.68 - 322.69 -(defn flatten-map 322.70 - "Transforms a map into a vector like [key value key value]." 322.71 - [m] 322.72 - (reduce (fn [coll [k v]] (conj coll k v)) 322.73 - [] m)) 322.74 - 322.75 -(defn template? 322.76 - "Returns true if form is a valid template expression." 322.77 - [form] 322.78 - (if (seq (find-holes form)) true false)) 322.79 - 322.80 -(defn apply-template 322.81 - "Replaces _1, _2, _3, etc. in expr with corresponding elements of 322.82 - values. Returns the modified expression. For use in macros." 322.83 - [expr values] 322.84 - (when-not (template? expr) 322.85 - (throw (IllegalArgumentException. (str (pr-str expr) " is not a valid template.")))) 322.86 - (let [expr (walk/postwalk-replace {'_ '_1} expr) 322.87 - holes (find-holes expr) 322.88 - smap (zipmap holes values)] 322.89 - (walk/prewalk-replace smap expr))) 322.90 - 322.91 -(defmacro do-template 322.92 - "Repeatedly evaluates template expr (in a do block) using values in 322.93 - args. args are grouped by the number of holes in the template. 322.94 - Example: (do-template (check _1 _2) :a :b :c :d) 322.95 - expands to (do (check :a :b) (check :c :d))" 322.96 - [expr & args] 322.97 - (when-not (template? expr) 322.98 - (throw (IllegalArgumentException. (str (pr-str expr) " is not a valid template.")))) 322.99 - (let [expr (walk/postwalk-replace {'_ '_1} expr) 322.100 - argcount (count (find-holes expr))] 322.101 - `(do ~@(map (fn [a] (apply-template expr a)) 322.102 - (partition argcount args))))) 322.103 - 322.104 - 322.105 - 322.106 -;;; REDEFINE are MACRO TO MATCH OLD TEMPLATE BEHAVIOR 322.107 - 322.108 -(defmacro are 322.109 - "Checks multiple assertions with a template expression. 322.110 - See clojure.contrib.template/do-template for an explanation of 322.111 - templates. 322.112 - 322.113 - Example: (are (= _1 _2) 322.114 - 2 (+ 1 1) 322.115 - 4 (* 2 2)) 322.116 - Expands to: 322.117 - (do (is (= 2 (+ 1 1))) 322.118 - (is (= 4 (* 2 2)))) 322.119 - 322.120 - Note: This breaks some reporting features, such as line numbers." 322.121 - [expr & args] 322.122 - `(do-template (is ~expr) ~@args))
323.1 --- a/src/clojure/contrib/trace.clj Sat Aug 21 06:25:44 2010 -0400 323.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 323.3 @@ -1,97 +0,0 @@ 323.4 -;;; trace.clj -- simple call-tracing macros for Clojure 323.5 - 323.6 -;; by Stuart Sierra, http://stuartsierra.com/ 323.7 -;; December 3, 2008 323.8 - 323.9 -;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use 323.10 -;; and distribution terms for this software are covered by the Eclipse 323.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 323.12 -;; which can be found in the file epl-v10.html at the root of this 323.13 -;; distribution. By using this software in any fashion, you are 323.14 -;; agreeing to be bound by the terms of this license. You must not 323.15 -;; remove this notice, or any other, from this software. 323.16 - 323.17 - 323.18 -;; This file defines simple "tracing" macros to help you see what your 323.19 -;; code is doing. 323.20 - 323.21 - 323.22 -;; CHANGE LOG 323.23 -;; 323.24 -;; December 3, 2008: 323.25 -;; 323.26 -;; * replaced *trace-out* with tracer 323.27 -;; 323.28 -;; * made trace a function instead of a macro 323.29 -;; (suggestion from Stuart Halloway) 323.30 -;; 323.31 -;; * added trace-fn-call 323.32 -;; 323.33 -;; June 9, 2008: first version 323.34 - 323.35 - 323.36 - 323.37 -(ns 323.38 - ^{:author "Stuart Sierra, Michel Salim", 323.39 - :doc "This file defines simple \"tracing\" macros to help you see what your 323.40 -code is doing."} 323.41 - clojure.contrib.trace) 323.42 - 323.43 -(def 323.44 - ^{:doc "Current stack depth of traced function calls."} 323.45 - *trace-depth* 0) 323.46 - 323.47 -(defn tracer 323.48 - "This function is called by trace. Prints to standard output, but 323.49 - may be rebound to do anything you like. 'name' is optional." 323.50 - [name value] 323.51 - (println (str "TRACE" (when name (str " " name)) ": " value))) 323.52 - 323.53 -(defn trace 323.54 - "Sends name (optional) and value to the tracer function, then 323.55 - returns value. May be wrapped around any expression without 323.56 - affecting the result." 323.57 - ([value] (trace nil value)) 323.58 - ([name value] 323.59 - (tracer name (pr-str value)) 323.60 - value)) 323.61 - 323.62 -(defn trace-indent 323.63 - "Returns an indentation string based on *trace-depth*" 323.64 - [] 323.65 - (apply str (take *trace-depth* (repeat "| ")))) 323.66 - 323.67 -(defn trace-fn-call 323.68 - "Traces a single call to a function f with args. 'name' is the 323.69 - symbol name of the function." 323.70 - [name f args] 323.71 - (let [id (gensym "t")] 323.72 - (tracer id (str (trace-indent) (pr-str (cons name args)))) 323.73 - (let [value (binding [*trace-depth* (inc *trace-depth*)] 323.74 - (apply f args))] 323.75 - (tracer id (str (trace-indent) "=> " (pr-str value))) 323.76 - value))) 323.77 - 323.78 -(defmacro deftrace 323.79 - "Use in place of defn; traces each call/return of this fn, including 323.80 - arguments. Nested calls to deftrace'd functions will print a 323.81 - tree-like structure." 323.82 - [name & definition] 323.83 - `(do 323.84 - (def ~name) 323.85 - (let [f# (fn ~@definition)] 323.86 - (defn ~name [& args#] 323.87 - (trace-fn-call '~name f# args#))))) 323.88 - 323.89 -(defmacro dotrace 323.90 - "Given a sequence of function identifiers, evaluate the body 323.91 - expressions in an environment in which the identifiers are bound to 323.92 - the traced functions. Does not work on inlined functions, 323.93 - such as clojure.core/+" 323.94 - [fnames & exprs] 323.95 - `(binding [~@(interleave fnames 323.96 - (for [fname fnames] 323.97 - `(let [f# @(var ~fname)] 323.98 - (fn [& args#] 323.99 - (trace-fn-call '~fname f# args#)))))] 323.100 - ~@exprs))
324.1 --- a/src/clojure/contrib/types.clj Sat Aug 21 06:25:44 2010 -0400 324.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 324.3 @@ -1,275 +0,0 @@ 324.4 -;; Data types 324.5 - 324.6 -;; by Konrad Hinsen 324.7 -;; last updated May 3, 2009 324.8 - 324.9 -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use 324.10 -;; and distribution terms for this software are covered by the Eclipse 324.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 324.12 -;; which can be found in the file epl-v10.html at the root of this 324.13 -;; distribution. By using this software in any fashion, you are 324.14 -;; agreeing to be bound by the terms of this license. You must not 324.15 -;; remove this notice, or any other, from this software. 324.16 - 324.17 -(ns 324.18 - ^{:author "Konrad Hinsen" 324.19 - :doc "General and algebraic data types"} 324.20 - clojure.contrib.types 324.21 - (:refer-clojure :exclude (deftype)) 324.22 - (:use [clojure.contrib.def :only (name-with-attributes)])) 324.23 - 324.24 -; 324.25 -; Utility functions 324.26 -; 324.27 -(defn- qualified-symbol 324.28 - [s] 324.29 - (symbol (str *ns*) (str s))) 324.30 - 324.31 -(defn- qualified-keyword 324.32 - [s] 324.33 - (keyword (str *ns*) (str s))) 324.34 - 324.35 -(defn- unqualified-symbol 324.36 - [s] 324.37 - (let [s-str (str s)] 324.38 - (symbol (subs s-str (inc (.indexOf s-str (int \/))))))) 324.39 - 324.40 -(defn- resolve-symbol 324.41 - [s] 324.42 - (if-let [var (resolve s)] 324.43 - (symbol (str (.ns var)) (str (.sym var))) 324.44 - s)) 324.45 - 324.46 -; 324.47 -; Data type definition 324.48 -; 324.49 -(defmulti deconstruct type) 324.50 - 324.51 -(defmulti constructor-form type) 324.52 -(defmethod constructor-form :default 324.53 - [o] nil) 324.54 -(defmethod constructor-form ::type 324.55 - [o] (cons (::constructor (meta o)) (deconstruct o))) 324.56 - 324.57 -(defmacro deftype 324.58 - "Define a data type by a type tag (a namespace-qualified keyword) 324.59 - and a symbol naming the constructor function. Optionally, a 324.60 - constructor and a deconstructor function can be given as well, 324.61 - the defaults being clojure.core/identity and clojure.core/list. 324.62 - The full constructor associated with constructor-name calls the 324.63 - constructor function and attaches the type tag to its result 324.64 - as metadata. The deconstructor function must return the arguments 324.65 - to be passed to the constructor in order to create an equivalent 324.66 - object. It is used for printing and matching." 324.67 - {:arglists 324.68 - '([type-tag constructor-name docstring? attr-map?] 324.69 - [type-tag constructor-name docstring? attr-map? constructor] 324.70 - [type-tag constructor-name docstring? attr-map? constructor deconstructor])} 324.71 - [type-tag constructor-name & options] 324.72 - (let [[constructor-name options] (name-with-attributes 324.73 - constructor-name options) 324.74 - [constructor deconstructor] options 324.75 - constructor (if (nil? constructor) 324.76 - 'clojure.core/identity 324.77 - constructor) 324.78 - deconstructor (if (nil? deconstructor) 324.79 - 'clojure.core/list 324.80 - deconstructor)] 324.81 - `(do 324.82 - (derive ~type-tag ::type) 324.83 - (let [meta-map# {:type ~type-tag 324.84 - ::constructor 324.85 - (quote ~(qualified-symbol constructor-name))}] 324.86 - (def ~constructor-name 324.87 - (comp (fn [~'x] (with-meta ~'x meta-map#)) ~constructor)) 324.88 - (defmethod deconstruct ~type-tag [~'x] 324.89 - (~deconstructor (with-meta ~'x {}))))))) 324.90 - 324.91 -(defmacro deftype- 324.92 - "Same as deftype but the constructor is private." 324.93 - [type-tag constructor-name & optional] 324.94 - `(deftype ~type-tag 324.95 - ~(vary-meta constructor-name assoc :private true) 324.96 - ~@optional)) 324.97 - 324.98 -(defmethod print-method ::type [o w] 324.99 - (let [cf (constructor-form o)] 324.100 - (if (symbol? cf) 324.101 - (print-method (unqualified-symbol cf) w) 324.102 - (print-method (cons (unqualified-symbol (first cf)) (rest cf)) w)))) 324.103 - 324.104 -; 324.105 -; Algebraic types 324.106 -; 324.107 -(derive ::adt ::type) 324.108 - 324.109 -(defmethod constructor-form ::adt 324.110 - [o] 324.111 - (let [v (vals o)] 324.112 - (if (= 1 (count v)) 324.113 - (first v) 324.114 - v))) 324.115 - 324.116 -(defn- constructor-code 324.117 - [meta-map-symbol constructor] 324.118 - (if (symbol? constructor) 324.119 - `(def ~constructor 324.120 - (with-meta {::tag (quote ~(qualified-symbol constructor))} 324.121 - ~meta-map-symbol)) 324.122 - (let [[name & args] constructor 324.123 - keys (cons ::tag (map (comp keyword str) args))] 324.124 - (if (empty? args) 324.125 - (throw (IllegalArgumentException. "zero argument constructor")) 324.126 - `(let [~'basis (create-struct ~@keys)] 324.127 - (defn ~name ~(vec args) 324.128 - (with-meta (struct ~'basis (quote ~(qualified-symbol name)) ~@args) 324.129 - ~meta-map-symbol))))))) 324.130 - 324.131 -(defmacro defadt 324.132 - "Define an algebraic data type name by an exhaustive list of constructors. 324.133 - Each constructor can be a symbol (argument-free constructor) or a 324.134 - list consisting of a tag symbol followed by the argument symbols. 324.135 - The data type tag must be a keyword." 324.136 - [type-tag & constructors] 324.137 - (let [meta-map-symbol (gensym "mm")] 324.138 - `(let [~meta-map-symbol {:type ~type-tag}] 324.139 - (derive ~type-tag ::adt) 324.140 - ~@(map (partial constructor-code meta-map-symbol) constructors) 324.141 - ))) 324.142 - 324.143 -; 324.144 -; Matching templates 324.145 -; 324.146 -(defn- symbol-tests-and-bindings 324.147 - [template vsymbol] 324.148 - [`(= (quote ~(resolve-symbol template)) ~vsymbol) 324.149 - []]) 324.150 - 324.151 -(defn- sequential-tests-and-bindings 324.152 - [template vsymbol] 324.153 - (let [enum-values (map list template (range (count template))) 324.154 - ; Non-symbols in the template create an equality test with the 324.155 - ; corresponding value in the object's value list 324.156 - tests (map (fn [[v i]] `(= ~v (nth ~vsymbol ~i))) 324.157 - (filter (complement #(symbol? (first %))) enum-values)) 324.158 - ; Symbols in the template become bindings to the corresponding 324.159 - ; value in the object. However, if a symbol occurs more than once, 324.160 - ; only one binding is generated, and equality tests are added 324.161 - ; for the other values. 324.162 - bindings (reduce (fn [map [symbol index]] 324.163 - (assoc map symbol 324.164 - (conj (get map symbol []) index))) 324.165 - {} 324.166 - (filter #(symbol? (first %)) enum-values)) 324.167 - tests (concat tests 324.168 - (map (fn [[symbol indices]] 324.169 - (cons `= (map #(list `nth vsymbol %) indices))) 324.170 - (filter #(> (count (second %)) 1) bindings))) 324.171 - bindings (mapcat (fn [[symbol indices]] 324.172 - [symbol (list `nth vsymbol (first indices))]) 324.173 - bindings)] 324.174 - [tests (vec bindings)])) 324.175 - 324.176 -(defn- constr-tests-and-bindings 324.177 - [template cfsymbol] 324.178 - (let [[tag & values] template 324.179 - cfasymbol (gensym) 324.180 - [tests bindings] (sequential-tests-and-bindings values cfasymbol) 324.181 - argtests (if (empty? tests) 324.182 - tests 324.183 - `((let [~cfasymbol (rest ~cfsymbol)] ~@tests)))] 324.184 - [`(and (seq? ~cfsymbol) 324.185 - (= (quote ~(resolve-symbol tag)) (first ~cfsymbol)) 324.186 - ~@argtests) 324.187 - `[~cfasymbol (rest ~cfsymbol) ~@bindings]])) 324.188 - 324.189 -(defn- list-tests-and-bindings 324.190 - [template vsymbol] 324.191 - (let [[tests bindings] (sequential-tests-and-bindings template vsymbol)] 324.192 - [`(and (list? ~vsymbol) ~@tests) 324.193 - bindings])) 324.194 - 324.195 -(defn- vector-tests-and-bindings 324.196 - [template vsymbol] 324.197 - (let [[tests bindings] (sequential-tests-and-bindings template vsymbol)] 324.198 - [`(and (vector? ~vsymbol) ~@tests) 324.199 - bindings])) 324.200 - 324.201 -(defn- map-tests-and-bindings 324.202 - [template vsymbol] 324.203 - (let [; First test if the given keys are all present. 324.204 - tests (map (fn [[k v]] `(contains? ~vsymbol ~k)) template) 324.205 - ; Non-symbols in the template create an equality test with the 324.206 - ; corresponding value in the object's value list. 324.207 - tests (concat tests 324.208 - (map (fn [[k v]] `(= ~v (~k ~vsymbol))) 324.209 - (filter (complement #(symbol? (second %))) template))) 324.210 - ; Symbols in the template become bindings to the corresponding 324.211 - ; value in the object. However, if a symbol occurs more than once, 324.212 - ; only one binding is generated, and equality tests are added 324.213 - ; for the other values. 324.214 - bindings (reduce (fn [map [key symbol]] 324.215 - (assoc map symbol 324.216 - (conj (get map symbol []) key))) 324.217 - {} 324.218 - (filter #(symbol? (second %)) template)) 324.219 - tests (concat tests 324.220 - (map (fn [[symbol keys]] 324.221 - (cons `= (map #(list % vsymbol) keys))) 324.222 - (filter #(> (count (second %)) 1) bindings))) 324.223 - bindings (mapcat (fn [[symbol keys]] 324.224 - [symbol (list (first keys) vsymbol)]) 324.225 - bindings)] 324.226 - [`(and (map? ~vsymbol) ~@tests) 324.227 - (vec bindings)])) 324.228 - 324.229 -(defn- tests-and-bindings 324.230 - [template vsymbol cfsymbol] 324.231 - (cond (symbol? template) 324.232 - (symbol-tests-and-bindings template cfsymbol) 324.233 - (seq? template) 324.234 - (if (= (first template) 'quote) 324.235 - (list-tests-and-bindings (second template) vsymbol) 324.236 - (constr-tests-and-bindings template cfsymbol)) 324.237 - (vector? template) 324.238 - (vector-tests-and-bindings template vsymbol) 324.239 - (map? template) 324.240 - (map-tests-and-bindings template vsymbol) 324.241 - :else 324.242 - (throw (IllegalArgumentException. "illegal template for match")))) 324.243 - 324.244 -(defmacro match 324.245 - "Given a value and a list of template-expr clauses, evaluate the first 324.246 - expr whose template matches the value. There are four kinds of templates: 324.247 - 1) Lists of the form (tag x1 x2 ...) match instances of types 324.248 - whose constructor has the same form as the list. 324.249 - 2) Quoted lists of the form '(x1 x2 ...) match lists of the same 324.250 - length. 324.251 - 3) Vectors of the form [x1 x2 ...] match vectors of the same length. 324.252 - 4) Maps of the form {:key1 x1 :key2 x2 ...} match maps that have 324.253 - the same keys as the template, but which can have additional keys 324.254 - that are not part of the template. 324.255 - The values x1, x2, ... can be symbols or non-symbol values. Non-symbols 324.256 - must be equal to the corresponding values in the object to be matched. 324.257 - Symbols will be bound to the corresponding value in the object in the 324.258 - evaluation of expr. If the same symbol occurs more than once in a, 324.259 - template the corresponding elements of the object must be equal 324.260 - for the template to match." 324.261 - [value & clauses] 324.262 - (when (odd? (count clauses)) 324.263 - (throw (Exception. "Odd number of elements in match expression"))) 324.264 - (let [vsymbol (gensym) 324.265 - cfsymbol (gensym) 324.266 - terms (mapcat (fn [[template expr]] 324.267 - (if (= template :else) 324.268 - [template expr] 324.269 - (let [[tests bindings] 324.270 - (tests-and-bindings template vsymbol cfsymbol)] 324.271 - [tests 324.272 - (if (empty? bindings) 324.273 - expr 324.274 - `(let ~bindings ~expr))]))) 324.275 - (partition 2 clauses))] 324.276 - `(let [~vsymbol ~value 324.277 - ~cfsymbol (constructor-form ~vsymbol)] 324.278 - (cond ~@terms))))
325.1 --- a/src/clojure/contrib/with_ns.clj Sat Aug 21 06:25:44 2010 -0400 325.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 325.3 @@ -1,38 +0,0 @@ 325.4 -;;; with_ns.clj -- temporary namespace macro 325.5 - 325.6 -;; by Stuart Sierra, http://stuartsierra.com/ 325.7 -;; March 28, 2009 325.8 - 325.9 -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 325.10 -;; and distribution terms for this software are covered by the Eclipse 325.11 -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 325.12 -;; which can be found in the file epl-v10.html at the root of this 325.13 -;; distribution. By using this software in any fashion, you are 325.14 -;; agreeing to be bound by the terms of this license. You must not 325.15 -;; remove this notice, or any other, from this software. 325.16 - 325.17 - 325.18 -(ns 325.19 - ^{:author "Stuart Sierra", 325.20 - :doc "Temporary namespace macro"} 325.21 - clojure.contrib.with-ns) 325.22 - 325.23 -(defmacro with-ns 325.24 - "Evaluates body in another namespace. ns is either a namespace 325.25 - object or a symbol. This makes it possible to define functions in 325.26 - namespaces other than the current one." 325.27 - [ns & body] 325.28 - `(binding [*ns* (the-ns ~ns)] 325.29 - ~@(map (fn [form] `(eval '~form)) body))) 325.30 - 325.31 -(defmacro with-temp-ns 325.32 - "Evaluates body in an anonymous namespace, which is then immediately 325.33 - removed. The temporary namespace will 'refer' clojure.core." 325.34 - [& body] 325.35 - `(try 325.36 - (create-ns 'sym#) 325.37 - (let [result# (with-ns 'sym# 325.38 - (clojure.core/refer-clojure) 325.39 - ~@body)] 325.40 - result#) 325.41 - (finally (remove-ns 'sym#))))
326.1 --- a/src/clojure/contrib/zip_filter.clj Sat Aug 21 06:25:44 2010 -0400 326.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 326.3 @@ -1,92 +0,0 @@ 326.4 -; Copyright (c) Chris Houser, April 2008. All rights reserved. 326.5 -; The use and distribution terms for this software are covered by the 326.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 326.7 -; which can be found in the file epl-v10.html at the root of this distribution. 326.8 -; By using this software in any fashion, you are agreeing to be bound by 326.9 -; the terms of this license. 326.10 -; You must not remove this notice, or any other, from this software. 326.11 - 326.12 -; System for filtering trees and nodes generated by zip.clj in 326.13 -; general, and xml trees in particular. 326.14 - 326.15 -(ns 326.16 - ^{:author "Chris Houser", 326.17 - :doc "System for filtering trees and nodes generated by zip.clj in 326.18 -general, and xml trees in particular. 326.19 -"} 326.20 - clojure.contrib.zip-filter 326.21 - (:refer-clojure :exclude (descendants ancestors)) 326.22 - (:require [clojure.zip :as zip])) 326.23 - 326.24 -; This uses the negative form (no-auto) so that the result from any 326.25 -; naive function, including user functions, defaults to "auto". 326.26 -(defn auto 326.27 - [v x] (with-meta x ((if v dissoc assoc) (meta x) :zip-filter/no-auto? true))) 326.28 - 326.29 -(defn auto? 326.30 - [x] (not (:zip-filter/no-auto? (meta x)))) 326.31 - 326.32 -(defn right-locs 326.33 - "Returns a lazy sequence of locations to the right of loc, starting with loc." 326.34 - [loc] (lazy-seq (when loc (cons (auto false loc) (right-locs (zip/right loc)))))) 326.35 - 326.36 -(defn left-locs 326.37 - "Returns a lazy sequence of locations to the left of loc, starting with loc." 326.38 - [loc] (lazy-seq (when loc (cons (auto false loc) (left-locs (zip/left loc)))))) 326.39 - 326.40 -(defn leftmost? 326.41 - "Returns true if there are no more nodes to the left of location loc." 326.42 - [loc] (nil? (zip/left loc))) 326.43 - 326.44 -(defn rightmost? 326.45 - "Returns true if there are no more nodes to the right of location loc." 326.46 - [loc] (nil? (zip/right loc))) 326.47 - 326.48 -(defn children 326.49 - "Returns a lazy sequence of all immediate children of location loc, 326.50 - left-to-right." 326.51 - [loc] 326.52 - (when (zip/branch? loc) 326.53 - (map #(auto false %) (right-locs (zip/down loc))))) 326.54 - 326.55 -(defn children-auto 326.56 - "Returns a lazy sequence of all immediate children of location loc, 326.57 - left-to-right, marked so that a following tag= predicate will auto-descend." 326.58 - ^{:private true} 326.59 - [loc] 326.60 - (when (zip/branch? loc) 326.61 - (map #(auto true %) (right-locs (zip/down loc))))) 326.62 - 326.63 -(defn descendants 326.64 - "Returns a lazy sequence of all descendants of location loc, in 326.65 - depth-first order, left-to-right, starting with loc." 326.66 - [loc] (lazy-seq (cons (auto false loc) (mapcat descendants (children loc))))) 326.67 - 326.68 -(defn ancestors 326.69 - "Returns a lazy sequence of all ancestors of location loc, starting 326.70 - with loc and proceeding to loc's parent node and on through to the 326.71 - root of the tree." 326.72 - [loc] (lazy-seq (when loc (cons (auto false loc) (ancestors (zip/up loc)))))) 326.73 - 326.74 -(defn- fixup-apply 326.75 - "Calls (pred loc), and then converts the result to the 'appropriate' 326.76 - sequence." 326.77 - ^{:private true} 326.78 - [pred loc] 326.79 - (let [rtn (pred loc)] 326.80 - (cond (and (map? (meta rtn)) (:zip-filter/is-node? (meta rtn))) (list rtn) 326.81 - (= rtn true) (list loc) 326.82 - (= rtn false) nil 326.83 - (nil? rtn) nil 326.84 - (sequential? rtn) rtn 326.85 - :else (list rtn)))) 326.86 - 326.87 -(defn mapcat-chain 326.88 - ^{:private true} 326.89 - [loc preds mkpred] 326.90 - (reduce (fn [prevseq expr] 326.91 - (mapcat #(fixup-apply (or (mkpred expr) expr) %) prevseq)) 326.92 - (list (with-meta loc (assoc (meta loc) :zip-filter/is-node? true))) 326.93 - preds)) 326.94 - 326.95 -; see clojure.contrib.zip-filter.xml for examples
327.1 --- a/src/clojure/contrib/zip_filter/xml.clj Sat Aug 21 06:25:44 2010 -0400 327.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 327.3 @@ -1,170 +0,0 @@ 327.4 -; Copyright (c) Chris Houser, April 2008. All rights reserved. 327.5 -; The use and distribution terms for this software are covered by the 327.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 327.7 -; which can be found in the file epl-v10.html at the root of this distribution. 327.8 -; By using this software in any fashion, you are agreeing to be bound by 327.9 -; the terms of this license. 327.10 -; You must not remove this notice, or any other, from this software. 327.11 - 327.12 -; Specialization of zip-filter for xml trees. 327.13 - 327.14 -(ns clojure.contrib.zip-filter.xml 327.15 - (:require [clojure.contrib.zip-filter :as zf] 327.16 - [clojure.zip :as zip] 327.17 - [clojure.xml :as xml])) 327.18 - 327.19 -(declare xml->) 327.20 - 327.21 -(defn attr 327.22 - "Returns the xml attribute named attrname, of the xml node at location loc." 327.23 - ([attrname] (fn [loc] (attr loc attrname))) 327.24 - ([loc attrname] (when (zip/branch? loc) (-> loc zip/node :attrs attrname)))) 327.25 - 327.26 -(defn attr= 327.27 - "Returns a query predicate that matches a node when it has an 327.28 - attribute named attrname whose value is attrval." 327.29 - [attrname attrval] (fn [loc] (= attrval (attr loc attrname)))) 327.30 - 327.31 -(defn tag= 327.32 - "Returns a query predicate that matches a node when its is a tag 327.33 - named tagname." 327.34 - [tagname] 327.35 - (fn [loc] 327.36 - (filter #(and (zip/branch? %) (= tagname ((zip/node %) :tag))) 327.37 - (if (zf/auto? loc) 327.38 - (zf/children-auto loc) 327.39 - (list (zf/auto true loc)))))) 327.40 - 327.41 -(defn text 327.42 - "Returns the textual contents of the given location, similar to 327.43 - xpaths's value-of" 327.44 - [loc] 327.45 - (.replaceAll 327.46 - ^String (apply str (xml-> loc zf/descendants zip/node string?)) 327.47 - (str "[\\s" (char 160) "]+") " ")) 327.48 - 327.49 -(defn text= 327.50 - "Returns a query predicate that matches a node when its textual 327.51 - content equals s." 327.52 - [s] (fn [loc] (= (text loc) s))) 327.53 - 327.54 -(defn seq-test 327.55 - "Returns a query predicate that matches a node when its xml content 327.56 - matches the query expresions given." 327.57 - ^{:private true} 327.58 - [preds] (fn [loc] (and (seq (apply xml-> loc preds)) (list loc)))) 327.59 - 327.60 -(defn xml-> 327.61 - "The loc is passed to the first predicate. If the predicate returns 327.62 - a collection, each value of the collection is passed to the next 327.63 - predicate. If it returns a location, the location is passed to the 327.64 - next predicate. If it returns true, the input location is passed to 327.65 - the next predicate. If it returns false or nil, the next predicate 327.66 - is not called. 327.67 - 327.68 - This process is repeated, passing the processed results of each 327.69 - predicate to the next predicate. xml-> returns the final sequence. 327.70 - The entire chain is evaluated lazily. 327.71 - 327.72 - There are also special predicates: keywords are converted to tag=, 327.73 - strings to text=, and vectors to sub-queries that return true if 327.74 - they match. 327.75 - 327.76 - See the footer of zip-query.clj for examples." 327.77 - [loc & preds] 327.78 - (zf/mapcat-chain loc preds 327.79 - #(cond (keyword? %) (tag= %) 327.80 - (string? %) (text= %) 327.81 - (vector? %) (seq-test %)))) 327.82 - 327.83 -(defn xml1-> 327.84 - "Returns the first item from loc based on the query predicates 327.85 - given. See xml->" 327.86 - [loc & preds] (first (apply xml-> loc preds))) 327.87 - 327.88 - 327.89 -; === examples === 327.90 - 327.91 -(comment 327.92 - 327.93 -(defn parse-str [s] 327.94 - (zip/xml-zip (xml/parse (new org.xml.sax.InputSource 327.95 - (new java.io.StringReader s))))) 327.96 - 327.97 -(def atom1 (parse-str "<?xml version='1.0' encoding='UTF-8'?> 327.98 -<feed xmlns='http://www.w3.org/2005/Atom'> 327.99 - <id>tag:blogger.com,1999:blog-28403206</id> 327.100 - <updated>2008-02-14T08:00:58.567-08:00</updated> 327.101 - <title type='text'>n01senet</title> 327.102 - <link rel='alternate' type='text/html' href='http://n01senet.blogspot.com/'/> 327.103 - <entry> 327.104 - <id>1</id> 327.105 - <published>2008-02-13</published> 327.106 - <title type='text'>clojure is the best lisp yet</title> 327.107 - <author><name>Chouser</name></author> 327.108 - </entry> 327.109 - <entry> 327.110 - <id>2</id> 327.111 - <published>2008-02-07</published> 327.112 - <title type='text'>experimenting with vnc</title> 327.113 - <author><name>agriffis</name></author> 327.114 - </entry> 327.115 -</feed> 327.116 -")) 327.117 - 327.118 -; simple single-function filter 327.119 -(assert (= (xml-> atom1 #((zip/node %) :tag)) 327.120 - '(:feed))) 327.121 - 327.122 -; two-stage filter using helpful query prediates 327.123 -(assert (= (xml-> atom1 (tag= :title) text) 327.124 - '("n01senet"))) 327.125 - 327.126 -; same filter as above, this time using keyword shortcut 327.127 -(assert (= (xml-> atom1 :title text) 327.128 - '("n01senet"))) 327.129 - 327.130 -; multi-stage filter 327.131 -(assert (= (xml-> atom1 :entry :author :name text) 327.132 - '("Chouser" "agriffis"))) 327.133 - 327.134 -; test xml1-> 327.135 -(assert (= (xml1-> atom1 :entry :author :name text) 327.136 - "Chouser")) 327.137 - 327.138 -; multi-stage filter with subquery specified using a vector 327.139 -(assert (= (xml-> atom1 :entry [:author :name (text= "agriffis")] 327.140 - :id text) 327.141 - '("2"))) 327.142 - 327.143 -; same filter as above, this time using a string shortcut 327.144 -(assert (= (xml-> atom1 :entry [:author :name "agriffis"] :id text) 327.145 - '("2"))) 327.146 - 327.147 -; attribute access 327.148 -(assert (= (xml-> atom1 :title (attr :type)) 327.149 - '("text"))) 327.150 - 327.151 -; attribute filtering 327.152 -(assert (= (xml-> atom1 :link [(attr= :rel "alternate")] (attr :type)) 327.153 - '("text/html"))) 327.154 - 327.155 -; ancestors 327.156 -(assert (= (xml-> atom1 zf/descendants :id "2" zf/ancestors zip/node #(:tag %)) 327.157 - '(:id :entry :feed))) 327.158 - 327.159 -; ancestors with non-auto tag= (:entry), followed by auto tag= (:id) 327.160 -(assert (= (xml-> atom1 zf/descendants :name "Chouser" zf/ancestors 327.161 - :entry :id text) 327.162 - '("1"))) 327.163 - 327.164 -; left-locs and detection of returning a single loc (zip/up) 327.165 -(assert (= (xml-> atom1 zf/descendants :name "Chouser" zip/up 327.166 - zf/left-locs :id text) 327.167 - '("1"))) 327.168 - 327.169 -; right-locs 327.170 -(assert (= (xml-> atom1 zf/descendants :id zf/right-locs :author text) 327.171 - '("Chouser" "agriffis"))) 327.172 - 327.173 -)
328.1 --- a/src/clojure/core.clj Sat Aug 21 06:25:44 2010 -0400 328.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 328.3 @@ -1,5710 +0,0 @@ 328.4 -; Copyright (c) Rich Hickey. All rights reserved. 328.5 -; The use and distribution terms for this software are covered by the 328.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 328.7 -; which can be found in the file epl-v10.html at the root of this distribution. 328.8 -; By using this software in any fashion, you are agreeing to be bound by 328.9 -; the terms of this license. 328.10 -; You must not remove this notice, or any other, from this software. 328.11 - 328.12 -(ns clojure.core) 328.13 - 328.14 -(def unquote) 328.15 -(def unquote-splicing) 328.16 - 328.17 -(def 328.18 - ^{:arglists '([& items]) 328.19 - :doc "Creates a new list containing the items." 328.20 - :added "1.0"} 328.21 - list (. clojure.lang.PersistentList creator)) 328.22 - 328.23 -(def 328.24 - ^{:arglists '([x seq]) 328.25 - :doc "Returns a new seq where x is the first element and seq is 328.26 - the rest." 328.27 - :added "1.0"} 328.28 - 328.29 - cons (fn* cons [x seq] (. clojure.lang.RT (cons x seq)))) 328.30 - 328.31 -;during bootstrap we don't have destructuring let, loop or fn, will redefine later 328.32 -(def 328.33 - ^{:macro true 328.34 - :added "1.0"} 328.35 - let (fn* let [&form &env & decl] (cons 'let* decl))) 328.36 - 328.37 -(def 328.38 - ^{:macro true 328.39 - :added "1.0"} 328.40 - loop (fn* loop [&form &env & decl] (cons 'loop* decl))) 328.41 - 328.42 -(def 328.43 - ^{:macro true 328.44 - :added "1.0"} 328.45 - fn (fn* fn [&form &env & decl] 328.46 - (.withMeta ^clojure.lang.IObj (cons 'fn* decl) 328.47 - (.meta ^clojure.lang.IMeta &form)))) 328.48 - 328.49 -(def 328.50 - ^{:arglists '([coll]) 328.51 - :doc "Returns the first item in the collection. Calls seq on its 328.52 - argument. If coll is nil, returns nil." 328.53 - :added "1.0"} 328.54 - first (fn first [coll] (. clojure.lang.RT (first coll)))) 328.55 - 328.56 -(def 328.57 - ^{:arglists '([coll]) 328.58 - :tag clojure.lang.ISeq 328.59 - :doc "Returns a seq of the items after the first. Calls seq on its 328.60 - argument. If there are no more items, returns nil." 328.61 - :added "1.0"} 328.62 - next (fn next [x] (. clojure.lang.RT (next x)))) 328.63 - 328.64 -(def 328.65 - ^{:arglists '([coll]) 328.66 - :tag clojure.lang.ISeq 328.67 - :doc "Returns a possibly empty seq of the items after the first. Calls seq on its 328.68 - argument." 328.69 - :added "1.0"} 328.70 - rest (fn rest [x] (. clojure.lang.RT (more x)))) 328.71 - 328.72 -(def 328.73 - ^{:arglists '([coll x] [coll x & xs]) 328.74 - :doc "conj[oin]. Returns a new collection with the xs 328.75 - 'added'. (conj nil item) returns (item). The 'addition' may 328.76 - happen at different 'places' depending on the concrete type." 328.77 - :added "1.0"} 328.78 - conj (fn conj 328.79 - ([coll x] (. clojure.lang.RT (conj coll x))) 328.80 - ([coll x & xs] 328.81 - (if xs 328.82 - (recur (conj coll x) (first xs) (next xs)) 328.83 - (conj coll x))))) 328.84 - 328.85 -(def 328.86 - ^{:doc "Same as (first (next x))" 328.87 - :arglists '([x]) 328.88 - :added "1.0"} 328.89 - second (fn second [x] (first (next x)))) 328.90 - 328.91 -(def 328.92 - ^{:doc "Same as (first (first x))" 328.93 - :arglists '([x]) 328.94 - :added "1.0"} 328.95 - ffirst (fn ffirst [x] (first (first x)))) 328.96 - 328.97 -(def 328.98 - ^{:doc "Same as (next (first x))" 328.99 - :arglists '([x]) 328.100 - :added "1.0"} 328.101 - nfirst (fn nfirst [x] (next (first x)))) 328.102 - 328.103 -(def 328.104 - ^{:doc "Same as (first (next x))" 328.105 - :arglists '([x]) 328.106 - :added "1.0"} 328.107 - fnext (fn fnext [x] (first (next x)))) 328.108 - 328.109 -(def 328.110 - ^{:doc "Same as (next (next x))" 328.111 - :arglists '([x]) 328.112 - :added "1.0"} 328.113 - nnext (fn nnext [x] (next (next x)))) 328.114 - 328.115 -(def 328.116 - ^{:arglists '([coll]) 328.117 - :doc "Returns a seq on the collection. If the collection is 328.118 - empty, returns nil. (seq nil) returns nil. seq also works on 328.119 - Strings, native Java arrays (of reference types) and any objects 328.120 - that implement Iterable." 328.121 - :tag clojure.lang.ISeq 328.122 - :added "1.0"} 328.123 - seq (fn seq [coll] (. clojure.lang.RT (seq coll)))) 328.124 - 328.125 -(def 328.126 - ^{:arglists '([^Class c x]) 328.127 - :doc "Evaluates x and tests if it is an instance of the class 328.128 - c. Returns true or false" 328.129 - :added "1.0"} 328.130 - instance? (fn instance? [^Class c x] (. c (isInstance x)))) 328.131 - 328.132 -(def 328.133 - ^{:arglists '([x]) 328.134 - :doc "Return true if x implements ISeq" 328.135 - :added "1.0"} 328.136 - seq? (fn seq? [x] (instance? clojure.lang.ISeq x))) 328.137 - 328.138 -(def 328.139 - ^{:arglists '([x]) 328.140 - :doc "Return true if x is a Character" 328.141 - :added "1.0"} 328.142 - char? (fn char? [x] (instance? Character x))) 328.143 - 328.144 -(def 328.145 - ^{:arglists '([x]) 328.146 - :doc "Return true if x is a String" 328.147 - :added "1.0"} 328.148 - string? (fn string? [x] (instance? String x))) 328.149 - 328.150 -(def 328.151 - ^{:arglists '([x]) 328.152 - :doc "Return true if x implements IPersistentMap" 328.153 - :added "1.0"} 328.154 - map? (fn map? [x] (instance? clojure.lang.IPersistentMap x))) 328.155 - 328.156 -(def 328.157 - ^{:arglists '([x]) 328.158 - :doc "Return true if x implements IPersistentVector" 328.159 - :added "1.0"} 328.160 - vector? (fn vector? [x] (instance? clojure.lang.IPersistentVector x))) 328.161 - 328.162 -(def 328.163 - ^{:arglists '([map key val] [map key val & kvs]) 328.164 - :doc "assoc[iate]. When applied to a map, returns a new map of the 328.165 - same (hashed/sorted) type, that contains the mapping of key(s) to 328.166 - val(s). When applied to a vector, returns a new vector that 328.167 - contains val at index. Note - index must be <= (count vector)." 328.168 - :added "1.0"} 328.169 - assoc 328.170 - (fn assoc 328.171 - ([map key val] (. clojure.lang.RT (assoc map key val))) 328.172 - ([map key val & kvs] 328.173 - (let [ret (assoc map key val)] 328.174 - (if kvs 328.175 - (recur ret (first kvs) (second kvs) (nnext kvs)) 328.176 - ret))))) 328.177 - 328.178 -;;;;;;;;;;;;;;;;; metadata ;;;;;;;;;;;;;;;;;;;;;;;;;;; 328.179 -(def 328.180 - ^{:arglists '([obj]) 328.181 - :doc "Returns the metadata of obj, returns nil if there is no metadata." 328.182 - :added "1.0"} 328.183 - meta (fn meta [x] 328.184 - (if (instance? clojure.lang.IMeta x) 328.185 - (. ^clojure.lang.IMeta x (meta))))) 328.186 - 328.187 -(def 328.188 - ^{:arglists '([^clojure.lang.IObj obj m]) 328.189 - :doc "Returns an object of the same type and value as obj, with 328.190 - map m as its metadata." 328.191 - :added "1.0"} 328.192 - with-meta (fn with-meta [^clojure.lang.IObj x m] 328.193 - (. x (withMeta m)))) 328.194 - 328.195 -(def ^{:private true :dynamic true} 328.196 - assert-valid-fdecl (fn [fdecl])) 328.197 - 328.198 -(def 328.199 - ^{:private true} 328.200 - sigs 328.201 - (fn [fdecl] 328.202 - (assert-valid-fdecl fdecl) 328.203 - (let [asig 328.204 - (fn [fdecl] 328.205 - (let [arglist (first fdecl) 328.206 - ;elide implicit macro args 328.207 - arglist (if (clojure.lang.Util/equals '&form (first arglist)) 328.208 - (clojure.lang.RT/subvec arglist 2 (clojure.lang.RT/count arglist)) 328.209 - arglist) 328.210 - body (next fdecl)] 328.211 - (if (map? (first body)) 328.212 - (if (next body) 328.213 - (with-meta arglist (conj (if (meta arglist) (meta arglist) {}) (first body))) 328.214 - arglist) 328.215 - arglist)))] 328.216 - (if (seq? (first fdecl)) 328.217 - (loop [ret [] fdecls fdecl] 328.218 - (if fdecls 328.219 - (recur (conj ret (asig (first fdecls))) (next fdecls)) 328.220 - (seq ret))) 328.221 - (list (asig fdecl)))))) 328.222 - 328.223 - 328.224 -(def 328.225 - ^{:arglists '([coll]) 328.226 - :doc "Return the last item in coll, in linear time" 328.227 - :added "1.0"} 328.228 - last (fn last [s] 328.229 - (if (next s) 328.230 - (recur (next s)) 328.231 - (first s)))) 328.232 - 328.233 -(def 328.234 - ^{:arglists '([coll]) 328.235 - :doc "Return a seq of all but the last item in coll, in linear time" 328.236 - :added "1.0"} 328.237 - butlast (fn butlast [s] 328.238 - (loop [ret [] s s] 328.239 - (if (next s) 328.240 - (recur (conj ret (first s)) (next s)) 328.241 - (seq ret))))) 328.242 - 328.243 -(def 328.244 - 328.245 - ^{:doc "Same as (def name (fn [params* ] exprs*)) or (def 328.246 - name (fn ([params* ] exprs*)+)) with any doc-string or attrs added 328.247 - to the var metadata" 328.248 - :arglists '([name doc-string? attr-map? [params*] body] 328.249 - [name doc-string? attr-map? ([params*] body)+ attr-map?]) 328.250 - :added "1.0"} 328.251 - defn (fn defn [&form &env name & fdecl] 328.252 - (let [m (if (string? (first fdecl)) 328.253 - {:doc (first fdecl)} 328.254 - {}) 328.255 - fdecl (if (string? (first fdecl)) 328.256 - (next fdecl) 328.257 - fdecl) 328.258 - m (if (map? (first fdecl)) 328.259 - (conj m (first fdecl)) 328.260 - m) 328.261 - fdecl (if (map? (first fdecl)) 328.262 - (next fdecl) 328.263 - fdecl) 328.264 - fdecl (if (vector? (first fdecl)) 328.265 - (list fdecl) 328.266 - fdecl) 328.267 - m (if (map? (last fdecl)) 328.268 - (conj m (last fdecl)) 328.269 - m) 328.270 - fdecl (if (map? (last fdecl)) 328.271 - (butlast fdecl) 328.272 - fdecl) 328.273 - m (conj {:arglists (list 'quote (sigs fdecl))} m) 328.274 - m (let [inline (:inline m) 328.275 - ifn (first inline) 328.276 - iname (second inline)] 328.277 - ;; same as: (if (and (= 'fn ifn) (not (symbol? iname))) ...) 328.278 - (if (if (clojure.lang.Util/equiv 'fn ifn) 328.279 - (if (instance? clojure.lang.Symbol iname) false true)) 328.280 - ;; inserts the same fn name to the inline fn if it does not have one 328.281 - (assoc m :inline (cons ifn (cons (clojure.lang.Symbol/intern (.concat (.getName name) "__inliner")) 328.282 - (next inline)))) 328.283 - m)) 328.284 - m (conj (if (meta name) (meta name) {}) m)] 328.285 - (list 'def (with-meta name m) 328.286 - (list '.withMeta (cons `fn (cons name fdecl)) (list '.meta (list 'var name))))))) 328.287 - 328.288 -(. (var defn) (setMacro)) 328.289 - 328.290 -(defn cast 328.291 - "Throws a ClassCastException if x is not a c, else returns x." 328.292 - {:added "1.0"} 328.293 - [^Class c x] 328.294 - (. c (cast x))) 328.295 - 328.296 -(defn to-array 328.297 - "Returns an array of Objects containing the contents of coll, which 328.298 - can be any Collection. Maps to java.util.Collection.toArray()." 328.299 - {:tag "[Ljava.lang.Object;" 328.300 - :added "1.0"} 328.301 - [coll] (. clojure.lang.RT (toArray coll))) 328.302 - 328.303 -(defn vector 328.304 - "Creates a new vector containing the args." 328.305 - {:added "1.0"} 328.306 - ([] []) 328.307 - ([a] [a]) 328.308 - ([a b] [a b]) 328.309 - ([a b c] [a b c]) 328.310 - ([a b c d] [a b c d]) 328.311 - ([a b c d & args] 328.312 - (. clojure.lang.LazilyPersistentVector (create (cons a (cons b (cons c (cons d args)))))))) 328.313 - 328.314 -(defn vec 328.315 - "Creates a new vector containing the contents of coll." 328.316 - {:added "1.0"} 328.317 - ([coll] 328.318 - (if (instance? java.util.Collection coll) 328.319 - (clojure.lang.LazilyPersistentVector/create coll) 328.320 - (. clojure.lang.LazilyPersistentVector (createOwning (to-array coll)))))) 328.321 - 328.322 -(defn hash-map 328.323 - "keyval => key val 328.324 - Returns a new hash map with supplied mappings." 328.325 - {:added "1.0"} 328.326 - ([] {}) 328.327 - ([& keyvals] 328.328 - (. clojure.lang.PersistentHashMap (createWithCheck keyvals)))) 328.329 - 328.330 -(defn hash-set 328.331 - "Returns a new hash set with supplied keys." 328.332 - {:added "1.0"} 328.333 - ([] #{}) 328.334 - ([& keys] 328.335 - (clojure.lang.PersistentHashSet/createWithCheck keys))) 328.336 - 328.337 -(defn sorted-map 328.338 - "keyval => key val 328.339 - Returns a new sorted map with supplied mappings." 328.340 - {:added "1.0"} 328.341 - ([& keyvals] 328.342 - (clojure.lang.PersistentTreeMap/create keyvals))) 328.343 - 328.344 -(defn sorted-map-by 328.345 - "keyval => key val 328.346 - Returns a new sorted map with supplied mappings, using the supplied comparator." 328.347 - {:added "1.0"} 328.348 - ([comparator & keyvals] 328.349 - (clojure.lang.PersistentTreeMap/create comparator keyvals))) 328.350 - 328.351 -(defn sorted-set 328.352 - "Returns a new sorted set with supplied keys." 328.353 - {:added "1.0"} 328.354 - ([& keys] 328.355 - (clojure.lang.PersistentTreeSet/create keys))) 328.356 - 328.357 -(defn sorted-set-by 328.358 - "Returns a new sorted set with supplied keys, using the supplied comparator." 328.359 - {:added "1.1"} 328.360 - ([comparator & keys] 328.361 - (clojure.lang.PersistentTreeSet/create comparator keys))) 328.362 - 328.363 - 328.364 -;;;;;;;;;;;;;;;;;;;; 328.365 -(defn nil? 328.366 - "Returns true if x is nil, false otherwise." 328.367 - {:tag Boolean 328.368 - :added "1.0"} 328.369 - [x] (clojure.lang.Util/identical x nil)) 328.370 - 328.371 -(def 328.372 - 328.373 - ^{:doc "Like defn, but the resulting function name is declared as a 328.374 - macro and will be used as a macro by the compiler when it is 328.375 - called." 328.376 - :arglists '([name doc-string? attr-map? [params*] body] 328.377 - [name doc-string? attr-map? ([params*] body)+ attr-map?]) 328.378 - :added "1.0"} 328.379 - defmacro (fn [&form &env 328.380 - name & args] 328.381 - (let [prefix (loop [p (list name) args args] 328.382 - (let [f (first args)] 328.383 - (if (string? f) 328.384 - (recur (cons f p) (next args)) 328.385 - (if (map? f) 328.386 - (recur (cons f p) (next args)) 328.387 - p)))) 328.388 - fdecl (loop [fd args] 328.389 - (if (string? (first fd)) 328.390 - (recur (next fd)) 328.391 - (if (map? (first fd)) 328.392 - (recur (next fd)) 328.393 - fd))) 328.394 - fdecl (if (vector? (first fdecl)) 328.395 - (list fdecl) 328.396 - fdecl) 328.397 - add-implicit-args (fn [fd] 328.398 - (let [args (first fd)] 328.399 - (cons (vec (cons '&form (cons '&env args))) (next fd)))) 328.400 - add-args (fn [acc ds] 328.401 - (if (nil? ds) 328.402 - acc 328.403 - (let [d (first ds)] 328.404 - (if (map? d) 328.405 - (conj acc d) 328.406 - (recur (conj acc (add-implicit-args d)) (next ds)))))) 328.407 - fdecl (seq (add-args [] fdecl)) 328.408 - decl (loop [p prefix d fdecl] 328.409 - (if p 328.410 - (recur (next p) (cons (first p) d)) 328.411 - d))] 328.412 - (list 'do 328.413 - (cons `defn decl) 328.414 - (list '. (list 'var name) '(setMacro)) 328.415 - (list 'var name))))) 328.416 - 328.417 - 328.418 -(. (var defmacro) (setMacro)) 328.419 - 328.420 -(defmacro when 328.421 - "Evaluates test. If logical true, evaluates body in an implicit do." 328.422 - {:added "1.0"} 328.423 - [test & body] 328.424 - (list 'if test (cons 'do body))) 328.425 - 328.426 -(defmacro when-not 328.427 - "Evaluates test. If logical false, evaluates body in an implicit do." 328.428 - {:added "1.0"} 328.429 - [test & body] 328.430 - (list 'if test nil (cons 'do body))) 328.431 - 328.432 -(defn false? 328.433 - "Returns true if x is the value false, false otherwise." 328.434 - {:tag Boolean, 328.435 - :added "1.0"} 328.436 - [x] (clojure.lang.Util/identical x false)) 328.437 - 328.438 -(defn true? 328.439 - "Returns true if x is the value true, false otherwise." 328.440 - {:tag Boolean, 328.441 - :added "1.0"} 328.442 - [x] (clojure.lang.Util/identical x true)) 328.443 - 328.444 -(defn not 328.445 - "Returns true if x is logical false, false otherwise." 328.446 - {:tag Boolean 328.447 - :added "1.0"} 328.448 - [x] (if x false true)) 328.449 - 328.450 -(defn str 328.451 - "With no args, returns the empty string. With one arg x, returns 328.452 - x.toString(). (str nil) returns the empty string. With more than 328.453 - one arg, returns the concatenation of the str values of the args." 328.454 - {:tag String 328.455 - :added "1.0"} 328.456 - ([] "") 328.457 - ([^Object x] 328.458 - (if (nil? x) "" (. x (toString)))) 328.459 - ([x & ys] 328.460 - ((fn [^StringBuilder sb more] 328.461 - (if more 328.462 - (recur (. sb (append (str (first more)))) (next more)) 328.463 - (str sb))) 328.464 - (new StringBuilder ^String (str x)) ys))) 328.465 - 328.466 - 328.467 -(defn symbol? 328.468 - "Return true if x is a Symbol" 328.469 - {:added "1.0"} 328.470 - [x] (instance? clojure.lang.Symbol x)) 328.471 - 328.472 -(defn keyword? 328.473 - "Return true if x is a Keyword" 328.474 - {:added "1.0"} 328.475 - [x] (instance? clojure.lang.Keyword x)) 328.476 - 328.477 -(defn symbol 328.478 - "Returns a Symbol with the given namespace and name." 328.479 - {:tag clojure.lang.Symbol 328.480 - :added "1.0"} 328.481 - ([name] (if (symbol? name) name (clojure.lang.Symbol/intern name))) 328.482 - ([ns name] (clojure.lang.Symbol/intern ns name))) 328.483 - 328.484 -(defn gensym 328.485 - "Returns a new symbol with a unique name. If a prefix string is 328.486 - supplied, the name is prefix# where # is some unique number. If 328.487 - prefix is not supplied, the prefix is 'G__'." 328.488 - {:added "1.0"} 328.489 - ([] (gensym "G__")) 328.490 - ([prefix-string] (. clojure.lang.Symbol (intern (str prefix-string (str (. clojure.lang.RT (nextID)))))))) 328.491 - 328.492 -(defmacro cond 328.493 - "Takes a set of test/expr pairs. It evaluates each test one at a 328.494 - time. If a test returns logical true, cond evaluates and returns 328.495 - the value of the corresponding expr and doesn't evaluate any of the 328.496 - other tests or exprs. (cond) returns nil." 328.497 - {:added "1.0"} 328.498 - [& clauses] 328.499 - (when clauses 328.500 - (list 'if (first clauses) 328.501 - (if (next clauses) 328.502 - (second clauses) 328.503 - (throw (IllegalArgumentException. 328.504 - "cond requires an even number of forms"))) 328.505 - (cons 'clojure.core/cond (next (next clauses)))))) 328.506 - 328.507 -(defn keyword 328.508 - "Returns a Keyword with the given namespace and name. Do not use : 328.509 - in the keyword strings, it will be added automatically." 328.510 - {:tag clojure.lang.Keyword 328.511 - :added "1.0"} 328.512 - ([name] (cond (keyword? name) name 328.513 - (symbol? name) (clojure.lang.Keyword/intern ^clojure.lang.Symbol name) 328.514 - (string? name) (clojure.lang.Keyword/intern ^String name))) 328.515 - ([ns name] (clojure.lang.Keyword/intern ns name))) 328.516 - 328.517 -(defn spread 328.518 - {:private true} 328.519 - [arglist] 328.520 - (cond 328.521 - (nil? arglist) nil 328.522 - (nil? (next arglist)) (seq (first arglist)) 328.523 - :else (cons (first arglist) (spread (next arglist))))) 328.524 - 328.525 -(defn list* 328.526 - "Creates a new list containing the items prepended to the rest, the 328.527 - last of which will be treated as a sequence." 328.528 - {:added "1.0"} 328.529 - ([args] (seq args)) 328.530 - ([a args] (cons a args)) 328.531 - ([a b args] (cons a (cons b args))) 328.532 - ([a b c args] (cons a (cons b (cons c args)))) 328.533 - ([a b c d & more] 328.534 - (cons a (cons b (cons c (cons d (spread more))))))) 328.535 - 328.536 -(defn apply 328.537 - "Applies fn f to the argument list formed by prepending args to argseq." 328.538 - {:arglists '([f args* argseq]) 328.539 - :added "1.0"} 328.540 - ([^clojure.lang.IFn f args] 328.541 - (. f (applyTo (seq args)))) 328.542 - ([^clojure.lang.IFn f x args] 328.543 - (. f (applyTo (list* x args)))) 328.544 - ([^clojure.lang.IFn f x y args] 328.545 - (. f (applyTo (list* x y args)))) 328.546 - ([^clojure.lang.IFn f x y z args] 328.547 - (. f (applyTo (list* x y z args)))) 328.548 - ([^clojure.lang.IFn f a b c d & args] 328.549 - (. f (applyTo (cons a (cons b (cons c (cons d (spread args))))))))) 328.550 - 328.551 -(defn vary-meta 328.552 - "Returns an object of the same type and value as obj, with 328.553 - (apply f (meta obj) args) as its metadata." 328.554 - {:added "1.0"} 328.555 - [obj f & args] 328.556 - (with-meta obj (apply f (meta obj) args))) 328.557 - 328.558 -(defmacro lazy-seq 328.559 - "Takes a body of expressions that returns an ISeq or nil, and yields 328.560 - a Seqable object that will invoke the body only the first time seq 328.561 - is called, and will cache the result and return it on all subsequent 328.562 - seq calls." 328.563 - {:added "1.0"} 328.564 - [& body] 328.565 - (list 'new 'clojure.lang.LazySeq (list* '^{:once true} fn* [] body))) 328.566 - 328.567 -(defn ^clojure.lang.ChunkBuffer chunk-buffer [capacity] 328.568 - (clojure.lang.ChunkBuffer. capacity)) 328.569 - 328.570 -(defn chunk-append [^clojure.lang.ChunkBuffer b x] 328.571 - (.add b x)) 328.572 - 328.573 -(defn chunk [^clojure.lang.ChunkBuffer b] 328.574 - (.chunk b)) 328.575 - 328.576 -(defn ^clojure.lang.IChunk chunk-first [^clojure.lang.IChunkedSeq s] 328.577 - (.chunkedFirst s)) 328.578 - 328.579 -(defn ^clojure.lang.ISeq chunk-rest [^clojure.lang.IChunkedSeq s] 328.580 - (.chunkedMore s)) 328.581 - 328.582 -(defn ^clojure.lang.ISeq chunk-next [^clojure.lang.IChunkedSeq s] 328.583 - (.chunkedNext s)) 328.584 - 328.585 -(defn chunk-cons [chunk rest] 328.586 - (if (clojure.lang.Numbers/isZero (clojure.lang.RT/count chunk)) 328.587 - rest 328.588 - (clojure.lang.ChunkedCons. chunk rest))) 328.589 - 328.590 -(defn chunked-seq? [s] 328.591 - (instance? clojure.lang.IChunkedSeq s)) 328.592 - 328.593 -(defn concat 328.594 - "Returns a lazy seq representing the concatenation of the elements in the supplied colls." 328.595 - {:added "1.0"} 328.596 - ([] (lazy-seq nil)) 328.597 - ([x] (lazy-seq x)) 328.598 - ([x y] 328.599 - (lazy-seq 328.600 - (let [s (seq x)] 328.601 - (if s 328.602 - (if (chunked-seq? s) 328.603 - (chunk-cons (chunk-first s) (concat (chunk-rest s) y)) 328.604 - (cons (first s) (concat (rest s) y))) 328.605 - y)))) 328.606 - ([x y & zs] 328.607 - (let [cat (fn cat [xys zs] 328.608 - (lazy-seq 328.609 - (let [xys (seq xys)] 328.610 - (if xys 328.611 - (if (chunked-seq? xys) 328.612 - (chunk-cons (chunk-first xys) 328.613 - (cat (chunk-rest xys) zs)) 328.614 - (cons (first xys) (cat (rest xys) zs))) 328.615 - (when zs 328.616 - (cat (first zs) (next zs)))))))] 328.617 - (cat (concat x y) zs)))) 328.618 - 328.619 -;;;;;;;;;;;;;;;;at this point all the support for syntax-quote exists;;;;;;;;;;;;;;;;;;;;;; 328.620 -(defmacro delay 328.621 - "Takes a body of expressions and yields a Delay object that will 328.622 - invoke the body only the first time it is forced (with force or deref/@), and 328.623 - will cache the result and return it on all subsequent force 328.624 - calls." 328.625 - {:added "1.0"} 328.626 - [& body] 328.627 - (list 'new 'clojure.lang.Delay (list* `^{:once true} fn* [] body))) 328.628 - 328.629 -(defn delay? 328.630 - "returns true if x is a Delay created with delay" 328.631 - {:added "1.0"} 328.632 - [x] (instance? clojure.lang.Delay x)) 328.633 - 328.634 -(defn force 328.635 - "If x is a Delay, returns the (possibly cached) value of its expression, else returns x" 328.636 - {:added "1.0"} 328.637 - [x] (. clojure.lang.Delay (force x))) 328.638 - 328.639 -(defmacro if-not 328.640 - "Evaluates test. If logical false, evaluates and returns then expr, 328.641 - otherwise else expr, if supplied, else nil." 328.642 - {:added "1.0"} 328.643 - ([test then] `(if-not ~test ~then nil)) 328.644 - ([test then else] 328.645 - `(if (not ~test) ~then ~else))) 328.646 - 328.647 -(defn identical? 328.648 - "Tests if 2 arguments are the same object" 328.649 - {:inline (fn [x y] `(. clojure.lang.Util identical ~x ~y)) 328.650 - :inline-arities #{2} 328.651 - :added "1.0"} 328.652 - ([x y] (clojure.lang.Util/identical x y))) 328.653 - 328.654 -(defn = 328.655 - "Equality. Returns true if x equals y, false if not. Same as 328.656 - Java x.equals(y) except it also works for nil, and compares 328.657 - numbers and collections in a type-independent manner. Clojure's immutable data 328.658 - structures define equals() (and thus =) as a value, not an identity, 328.659 - comparison." 328.660 - {:inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y)) 328.661 - :inline-arities #{2} 328.662 - :added "1.0"} 328.663 - ([x] true) 328.664 - ([x y] (clojure.lang.Util/equiv x y)) 328.665 - ([x y & more] 328.666 - (if (= x y) 328.667 - (if (next more) 328.668 - (recur y (first more) (next more)) 328.669 - (= y (first more))) 328.670 - false))) 328.671 - 328.672 -(defn not= 328.673 - "Same as (not (= obj1 obj2))" 328.674 - {:tag Boolean 328.675 - :added "1.0"} 328.676 - ([x] false) 328.677 - ([x y] (not (= x y))) 328.678 - ([x y & more] 328.679 - (not (apply = x y more)))) 328.680 - 328.681 - 328.682 - 328.683 -(defn compare 328.684 - "Comparator. Returns a negative number, zero, or a positive number 328.685 - when x is logically 'less than', 'equal to', or 'greater than' 328.686 - y. Same as Java x.compareTo(y) except it also works for nil, and 328.687 - compares numbers and collections in a type-independent manner. x 328.688 - must implement Comparable" 328.689 - { 328.690 - :inline (fn [x y] `(. clojure.lang.Util compare ~x ~y)) 328.691 - :added "1.0"} 328.692 - [x y] (. clojure.lang.Util (compare x y))) 328.693 - 328.694 -(defmacro and 328.695 - "Evaluates exprs one at a time, from left to right. If a form 328.696 - returns logical false (nil or false), and returns that value and 328.697 - doesn't evaluate any of the other expressions, otherwise it returns 328.698 - the value of the last expr. (and) returns true." 328.699 - {:added "1.0"} 328.700 - ([] true) 328.701 - ([x] x) 328.702 - ([x & next] 328.703 - `(let [and# ~x] 328.704 - (if and# (and ~@next) and#)))) 328.705 - 328.706 -(defmacro or 328.707 - "Evaluates exprs one at a time, from left to right. If a form 328.708 - returns a logical true value, or returns that value and doesn't 328.709 - evaluate any of the other expressions, otherwise it returns the 328.710 - value of the last expression. (or) returns nil." 328.711 - {:added "1.0"} 328.712 - ([] nil) 328.713 - ([x] x) 328.714 - ([x & next] 328.715 - `(let [or# ~x] 328.716 - (if or# or# (or ~@next))))) 328.717 - 328.718 -;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;; 328.719 -(defn zero? 328.720 - "Returns true if num is zero, else false" 328.721 - { 328.722 - :inline (fn [x] `(. clojure.lang.Numbers (isZero ~x))) 328.723 - :added "1.0"} 328.724 - [x] (. clojure.lang.Numbers (isZero x))) 328.725 - 328.726 -(defn count 328.727 - "Returns the number of items in the collection. (count nil) returns 328.728 - 0. Also works on strings, arrays, and Java Collections and Maps" 328.729 - { 328.730 - :inline (fn [x] `(. clojure.lang.RT (count ~x))) 328.731 - :added "1.0"} 328.732 - [coll] (clojure.lang.RT/count coll)) 328.733 - 328.734 -(defn int 328.735 - "Coerce to int" 328.736 - { 328.737 - :inline (fn [x] `(. clojure.lang.RT (intCast ~x))) 328.738 - :added "1.0"} 328.739 - [x] (. clojure.lang.RT (intCast x))) 328.740 - 328.741 -(defn nth 328.742 - "Returns the value at the index. get returns nil if index out of 328.743 - bounds, nth throws an exception unless not-found is supplied. nth 328.744 - also works for strings, Java arrays, regex Matchers and Lists, and, 328.745 - in O(n) time, for sequences." 328.746 - {:inline (fn [c i & nf] `(. clojure.lang.RT (nth ~c ~i ~@nf))) 328.747 - :inline-arities #{2 3} 328.748 - :added "1.0"} 328.749 - ([coll index] (. clojure.lang.RT (nth coll index))) 328.750 - ([coll index not-found] (. clojure.lang.RT (nth coll index not-found)))) 328.751 - 328.752 -(defn < 328.753 - "Returns non-nil if nums are in monotonically increasing order, 328.754 - otherwise false." 328.755 - {:inline (fn [x y] `(. clojure.lang.Numbers (lt ~x ~y))) 328.756 - :inline-arities #{2} 328.757 - :added "1.0"} 328.758 - ([x] true) 328.759 - ([x y] (. clojure.lang.Numbers (lt x y))) 328.760 - ([x y & more] 328.761 - (if (< x y) 328.762 - (if (next more) 328.763 - (recur y (first more) (next more)) 328.764 - (< y (first more))) 328.765 - false))) 328.766 - 328.767 -(defn inc 328.768 - "Returns a number one greater than num." 328.769 - {:inline (fn [x] `(. clojure.lang.Numbers (inc ~x))) 328.770 - :added "1.0"} 328.771 - [x] (. clojure.lang.Numbers (inc x))) 328.772 - 328.773 -;; reduce is defined again later after InternalReduce loads 328.774 -(def 328.775 - ^{:arglists '([f coll] [f val coll]) 328.776 - :doc "f should be a function of 2 arguments. If val is not supplied, 328.777 - returns the result of applying f to the first 2 items in coll, then 328.778 - applying f to that result and the 3rd item, etc. If coll contains no 328.779 - items, f must accept no arguments as well, and reduce returns the 328.780 - result of calling f with no arguments. If coll has only 1 item, it 328.781 - is returned and f is not called. If val is supplied, returns the 328.782 - result of applying f to val and the first item in coll, then 328.783 - applying f to that result and the 2nd item, etc. If coll contains no 328.784 - items, returns val and f is not called." 328.785 - :added "1.0"} 328.786 - reduce 328.787 - (fn r 328.788 - ([f coll] 328.789 - (let [s (seq coll)] 328.790 - (if s 328.791 - (r f (first s) (next s)) 328.792 - (f)))) 328.793 - ([f val coll] 328.794 - (let [s (seq coll)] 328.795 - (if s 328.796 - (if (chunked-seq? s) 328.797 - (recur f 328.798 - (.reduce (chunk-first s) f val) 328.799 - (chunk-next s)) 328.800 - (recur f (f val (first s)) (next s))) 328.801 - val))))) 328.802 - 328.803 -(defn reverse 328.804 - "Returns a seq of the items in coll in reverse order. Not lazy." 328.805 - {:added "1.0"} 328.806 - [coll] 328.807 - (reduce conj () coll)) 328.808 - 328.809 -;;math stuff 328.810 -(defn + 328.811 - "Returns the sum of nums. (+) returns 0." 328.812 - {:inline (fn [x y] `(. clojure.lang.Numbers (add ~x ~y))) 328.813 - :inline-arities #{2} 328.814 - :added "1.0"} 328.815 - ([] 0) 328.816 - ([x] (cast Number x)) 328.817 - ([x y] (. clojure.lang.Numbers (add x y))) 328.818 - ([x y & more] 328.819 - (reduce + (+ x y) more))) 328.820 - 328.821 -(defn * 328.822 - "Returns the product of nums. (*) returns 1." 328.823 - {:inline (fn [x y] `(. clojure.lang.Numbers (multiply ~x ~y))) 328.824 - :inline-arities #{2} 328.825 - :added "1.0"} 328.826 - ([] 1) 328.827 - ([x] (cast Number x)) 328.828 - ([x y] (. clojure.lang.Numbers (multiply x y))) 328.829 - ([x y & more] 328.830 - (reduce * (* x y) more))) 328.831 - 328.832 -(defn / 328.833 - "If no denominators are supplied, returns 1/numerator, 328.834 - else returns numerator divided by all of the denominators." 328.835 - {:inline (fn [x y] `(. clojure.lang.Numbers (divide ~x ~y))) 328.836 - :inline-arities #{2} 328.837 - :added "1.0"} 328.838 - ([x] (/ 1 x)) 328.839 - ([x y] (. clojure.lang.Numbers (divide x y))) 328.840 - ([x y & more] 328.841 - (reduce / (/ x y) more))) 328.842 - 328.843 -(defn - 328.844 - "If no ys are supplied, returns the negation of x, else subtracts 328.845 - the ys from x and returns the result." 328.846 - {:inline (fn [& args] `(. clojure.lang.Numbers (minus ~@args))) 328.847 - :inline-arities #{1 2} 328.848 - :added "1.0"} 328.849 - ([x] (. clojure.lang.Numbers (minus x))) 328.850 - ([x y] (. clojure.lang.Numbers (minus x y))) 328.851 - ([x y & more] 328.852 - (reduce - (- x y) more))) 328.853 - 328.854 -(defn <= 328.855 - "Returns non-nil if nums are in monotonically non-decreasing order, 328.856 - otherwise false." 328.857 - {:inline (fn [x y] `(. clojure.lang.Numbers (lte ~x ~y))) 328.858 - :inline-arities #{2} 328.859 - :added "1.0"} 328.860 - ([x] true) 328.861 - ([x y] (. clojure.lang.Numbers (lte x y))) 328.862 - ([x y & more] 328.863 - (if (<= x y) 328.864 - (if (next more) 328.865 - (recur y (first more) (next more)) 328.866 - (<= y (first more))) 328.867 - false))) 328.868 - 328.869 -(defn > 328.870 - "Returns non-nil if nums are in monotonically decreasing order, 328.871 - otherwise false." 328.872 - {:inline (fn [x y] `(. clojure.lang.Numbers (gt ~x ~y))) 328.873 - :inline-arities #{2} 328.874 - :added "1.0"} 328.875 - ([x] true) 328.876 - ([x y] (. clojure.lang.Numbers (gt x y))) 328.877 - ([x y & more] 328.878 - (if (> x y) 328.879 - (if (next more) 328.880 - (recur y (first more) (next more)) 328.881 - (> y (first more))) 328.882 - false))) 328.883 - 328.884 -(defn >= 328.885 - "Returns non-nil if nums are in monotonically non-increasing order, 328.886 - otherwise false." 328.887 - {:inline (fn [x y] `(. clojure.lang.Numbers (gte ~x ~y))) 328.888 - :inline-arities #{2} 328.889 - :added "1.0"} 328.890 - ([x] true) 328.891 - ([x y] (. clojure.lang.Numbers (gte x y))) 328.892 - ([x y & more] 328.893 - (if (>= x y) 328.894 - (if (next more) 328.895 - (recur y (first more) (next more)) 328.896 - (>= y (first more))) 328.897 - false))) 328.898 - 328.899 -(defn == 328.900 - "Returns non-nil if nums all have the same value, otherwise false" 328.901 - {:inline (fn [x y] `(. clojure.lang.Numbers (equiv ~x ~y))) 328.902 - :inline-arities #{2} 328.903 - :added "1.0"} 328.904 - ([x] true) 328.905 - ([x y] (. clojure.lang.Numbers (equiv x y))) 328.906 - ([x y & more] 328.907 - (if (== x y) 328.908 - (if (next more) 328.909 - (recur y (first more) (next more)) 328.910 - (== y (first more))) 328.911 - false))) 328.912 - 328.913 -(defn max 328.914 - "Returns the greatest of the nums." 328.915 - {:added "1.0"} 328.916 - ([x] x) 328.917 - ([x y] (if (> x y) x y)) 328.918 - ([x y & more] 328.919 - (reduce max (max x y) more))) 328.920 - 328.921 -(defn min 328.922 - "Returns the least of the nums." 328.923 - {:added "1.0"} 328.924 - ([x] x) 328.925 - ([x y] (if (< x y) x y)) 328.926 - ([x y & more] 328.927 - (reduce min (min x y) more))) 328.928 - 328.929 -(defn dec 328.930 - "Returns a number one less than num." 328.931 - {:inline (fn [x] `(. clojure.lang.Numbers (dec ~x))) 328.932 - :added "1.0"} 328.933 - [x] (. clojure.lang.Numbers (dec x))) 328.934 - 328.935 -(defn unchecked-inc 328.936 - "Returns a number one greater than x, an int or long. 328.937 - Note - uses a primitive operator subject to overflow." 328.938 - {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_inc ~x))) 328.939 - :added "1.0"} 328.940 - [x] (. clojure.lang.Numbers (unchecked_inc x))) 328.941 - 328.942 -(defn unchecked-dec 328.943 - "Returns a number one less than x, an int or long. 328.944 - Note - uses a primitive operator subject to overflow." 328.945 - {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_dec ~x))) 328.946 - :added "1.0"} 328.947 - [x] (. clojure.lang.Numbers (unchecked_dec x))) 328.948 - 328.949 -(defn unchecked-negate 328.950 - "Returns the negation of x, an int or long. 328.951 - Note - uses a primitive operator subject to overflow." 328.952 - {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_negate ~x))) 328.953 - :added "1.0"} 328.954 - [x] (. clojure.lang.Numbers (unchecked_negate x))) 328.955 - 328.956 -(defn unchecked-add 328.957 - "Returns the sum of x and y, both int or long. 328.958 - Note - uses a primitive operator subject to overflow." 328.959 - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_add ~x ~y))) 328.960 - :added "1.0"} 328.961 - [x y] (. clojure.lang.Numbers (unchecked_add x y))) 328.962 - 328.963 -(defn unchecked-subtract 328.964 - "Returns the difference of x and y, both int or long. 328.965 - Note - uses a primitive operator subject to overflow." 328.966 - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_subtract ~x ~y))) 328.967 - :added "1.0"} 328.968 - [x y] (. clojure.lang.Numbers (unchecked_subtract x y))) 328.969 - 328.970 -(defn unchecked-multiply 328.971 - "Returns the product of x and y, both int or long. 328.972 - Note - uses a primitive operator subject to overflow." 328.973 - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_multiply ~x ~y))) 328.974 - :added "1.0"} 328.975 - [x y] (. clojure.lang.Numbers (unchecked_multiply x y))) 328.976 - 328.977 -(defn unchecked-divide 328.978 - "Returns the division of x by y, both int or long. 328.979 - Note - uses a primitive operator subject to truncation." 328.980 - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_divide ~x ~y))) 328.981 - :added "1.0"} 328.982 - [x y] (. clojure.lang.Numbers (unchecked_divide x y))) 328.983 - 328.984 -(defn unchecked-remainder 328.985 - "Returns the remainder of division of x by y, both int or long. 328.986 - Note - uses a primitive operator subject to truncation." 328.987 - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_remainder ~x ~y))) 328.988 - :added "1.0"} 328.989 - [x y] (. clojure.lang.Numbers (unchecked_remainder x y))) 328.990 - 328.991 -(defn pos? 328.992 - "Returns true if num is greater than zero, else false" 328.993 - { 328.994 - :inline (fn [x] `(. clojure.lang.Numbers (isPos ~x))) 328.995 - :added "1.0"} 328.996 - [x] (. clojure.lang.Numbers (isPos x))) 328.997 - 328.998 -(defn neg? 328.999 - "Returns true if num is less than zero, else false" 328.1000 - { 328.1001 - :inline (fn [x] `(. clojure.lang.Numbers (isNeg ~x))) 328.1002 - :added "1.0"} 328.1003 - [x] (. clojure.lang.Numbers (isNeg x))) 328.1004 - 328.1005 -(defn quot 328.1006 - "quot[ient] of dividing numerator by denominator." 328.1007 - {:added "1.0"} 328.1008 - [num div] 328.1009 - (. clojure.lang.Numbers (quotient num div))) 328.1010 - 328.1011 -(defn rem 328.1012 - "remainder of dividing numerator by denominator." 328.1013 - {:added "1.0"} 328.1014 - [num div] 328.1015 - (. clojure.lang.Numbers (remainder num div))) 328.1016 - 328.1017 -(defn rationalize 328.1018 - "returns the rational value of num" 328.1019 - {:added "1.0"} 328.1020 - [num] 328.1021 - (. clojure.lang.Numbers (rationalize num))) 328.1022 - 328.1023 -;;Bit ops 328.1024 - 328.1025 -(defn bit-not 328.1026 - "Bitwise complement" 328.1027 - {:inline (fn [x] `(. clojure.lang.Numbers (not ~x))) 328.1028 - :added "1.0"} 328.1029 - [x] (. clojure.lang.Numbers not x)) 328.1030 - 328.1031 - 328.1032 -(defn bit-and 328.1033 - "Bitwise and" 328.1034 - {:inline (fn [x y] `(. clojure.lang.Numbers (and ~x ~y))) 328.1035 - :added "1.0"} 328.1036 - [x y] (. clojure.lang.Numbers and x y)) 328.1037 - 328.1038 -(defn bit-or 328.1039 - "Bitwise or" 328.1040 - {:inline (fn [x y] `(. clojure.lang.Numbers (or ~x ~y))) 328.1041 - :added "1.0"} 328.1042 - [x y] (. clojure.lang.Numbers or x y)) 328.1043 - 328.1044 -(defn bit-xor 328.1045 - "Bitwise exclusive or" 328.1046 - {:inline (fn [x y] `(. clojure.lang.Numbers (xor ~x ~y))) 328.1047 - :added "1.0"} 328.1048 - [x y] (. clojure.lang.Numbers xor x y)) 328.1049 - 328.1050 -(defn bit-and-not 328.1051 - "Bitwise and with complement" 328.1052 - {:added "1.0"} 328.1053 - [x y] (. clojure.lang.Numbers andNot x y)) 328.1054 - 328.1055 - 328.1056 -(defn bit-clear 328.1057 - "Clear bit at index n" 328.1058 - {:added "1.0"} 328.1059 - [x n] (. clojure.lang.Numbers clearBit x n)) 328.1060 - 328.1061 -(defn bit-set 328.1062 - "Set bit at index n" 328.1063 - {:added "1.0"} 328.1064 - [x n] (. clojure.lang.Numbers setBit x n)) 328.1065 - 328.1066 -(defn bit-flip 328.1067 - "Flip bit at index n" 328.1068 - {:added "1.0"} 328.1069 - [x n] (. clojure.lang.Numbers flipBit x n)) 328.1070 - 328.1071 -(defn bit-test 328.1072 - "Test bit at index n" 328.1073 - {:added "1.0"} 328.1074 - [x n] (. clojure.lang.Numbers testBit x n)) 328.1075 - 328.1076 - 328.1077 -(defn bit-shift-left 328.1078 - "Bitwise shift left" 328.1079 - {:inline (fn [x n] `(. clojure.lang.Numbers (shiftLeft ~x ~n))) 328.1080 - :added "1.0"} 328.1081 - [x n] (. clojure.lang.Numbers shiftLeft x n)) 328.1082 - 328.1083 -(defn bit-shift-right 328.1084 - "Bitwise shift right" 328.1085 - {:inline (fn [x n] `(. clojure.lang.Numbers (shiftRight ~x ~n))) 328.1086 - :added "1.0"} 328.1087 - [x n] (. clojure.lang.Numbers shiftRight x n)) 328.1088 - 328.1089 -(defn even? 328.1090 - "Returns true if n is even, throws an exception if n is not an integer" 328.1091 - {:added "1.0"} 328.1092 - [n] (zero? (bit-and n 1))) 328.1093 - 328.1094 -(defn odd? 328.1095 - "Returns true if n is odd, throws an exception if n is not an integer" 328.1096 - {:added "1.0"} 328.1097 - [n] (not (even? n))) 328.1098 - 328.1099 - 328.1100 -;; 328.1101 - 328.1102 -(defn complement 328.1103 - "Takes a fn f and returns a fn that takes the same arguments as f, 328.1104 - has the same effects, if any, and returns the opposite truth value." 328.1105 - {:added "1.0"} 328.1106 - [f] 328.1107 - (fn 328.1108 - ([] (not (f))) 328.1109 - ([x] (not (f x))) 328.1110 - ([x y] (not (f x y))) 328.1111 - ([x y & zs] (not (apply f x y zs))))) 328.1112 - 328.1113 -(defn constantly 328.1114 - "Returns a function that takes any number of arguments and returns x." 328.1115 - {:added "1.0"} 328.1116 - [x] (fn [& args] x)) 328.1117 - 328.1118 -(defn identity 328.1119 - "Returns its argument." 328.1120 - {:added "1.0"} 328.1121 - [x] x) 328.1122 - 328.1123 -;;Collection stuff 328.1124 - 328.1125 - 328.1126 - 328.1127 - 328.1128 - 328.1129 -;;list stuff 328.1130 -(defn peek 328.1131 - "For a list or queue, same as first, for a vector, same as, but much 328.1132 - more efficient than, last. If the collection is empty, returns nil." 328.1133 - {:added "1.0"} 328.1134 - [coll] (. clojure.lang.RT (peek coll))) 328.1135 - 328.1136 -(defn pop 328.1137 - "For a list or queue, returns a new list/queue without the first 328.1138 - item, for a vector, returns a new vector without the last item. If 328.1139 - the collection is empty, throws an exception. Note - not the same 328.1140 - as next/butlast." 328.1141 - {:added "1.0"} 328.1142 - [coll] (. clojure.lang.RT (pop coll))) 328.1143 - 328.1144 -;;map stuff 328.1145 - 328.1146 -(defn contains? 328.1147 - "Returns true if key is present in the given collection, otherwise 328.1148 - returns false. Note that for numerically indexed collections like 328.1149 - vectors and Java arrays, this tests if the numeric key is within the 328.1150 - range of indexes. 'contains?' operates constant or logarithmic time; 328.1151 - it will not perform a linear search for a value. See also 'some'." 328.1152 - {:added "1.0"} 328.1153 - [coll key] (. clojure.lang.RT (contains coll key))) 328.1154 - 328.1155 -(defn get 328.1156 - "Returns the value mapped to key, not-found or nil if key not present." 328.1157 - {:inline (fn [m k & nf] `(. clojure.lang.RT (get ~m ~k ~@nf))) 328.1158 - :inline-arities #{2 3} 328.1159 - :added "1.0"} 328.1160 - ([map key] 328.1161 - (. clojure.lang.RT (get map key))) 328.1162 - ([map key not-found] 328.1163 - (. clojure.lang.RT (get map key not-found)))) 328.1164 - 328.1165 -(defn dissoc 328.1166 - "dissoc[iate]. Returns a new map of the same (hashed/sorted) type, 328.1167 - that does not contain a mapping for key(s)." 328.1168 - {:added "1.0"} 328.1169 - ([map] map) 328.1170 - ([map key] 328.1171 - (. clojure.lang.RT (dissoc map key))) 328.1172 - ([map key & ks] 328.1173 - (let [ret (dissoc map key)] 328.1174 - (if ks 328.1175 - (recur ret (first ks) (next ks)) 328.1176 - ret)))) 328.1177 - 328.1178 -(defn disj 328.1179 - "disj[oin]. Returns a new set of the same (hashed/sorted) type, that 328.1180 - does not contain key(s)." 328.1181 - {:added "1.0"} 328.1182 - ([set] set) 328.1183 - ([^clojure.lang.IPersistentSet set key] 328.1184 - (when set 328.1185 - (. set (disjoin key)))) 328.1186 - ([set key & ks] 328.1187 - (when set 328.1188 - (let [ret (disj set key)] 328.1189 - (if ks 328.1190 - (recur ret (first ks) (next ks)) 328.1191 - ret))))) 328.1192 - 328.1193 -(defn find 328.1194 - "Returns the map entry for key, or nil if key not present." 328.1195 - {:added "1.0"} 328.1196 - [map key] (. clojure.lang.RT (find map key))) 328.1197 - 328.1198 -(defn select-keys 328.1199 - "Returns a map containing only those entries in map whose key is in keys" 328.1200 - {:added "1.0"} 328.1201 - [map keyseq] 328.1202 - (loop [ret {} keys (seq keyseq)] 328.1203 - (if keys 328.1204 - (let [entry (. clojure.lang.RT (find map (first keys)))] 328.1205 - (recur 328.1206 - (if entry 328.1207 - (conj ret entry) 328.1208 - ret) 328.1209 - (next keys))) 328.1210 - ret))) 328.1211 - 328.1212 -(defn keys 328.1213 - "Returns a sequence of the map's keys." 328.1214 - {:added "1.0"} 328.1215 - [map] (. clojure.lang.RT (keys map))) 328.1216 - 328.1217 -(defn vals 328.1218 - "Returns a sequence of the map's values." 328.1219 - {:added "1.0"} 328.1220 - [map] (. clojure.lang.RT (vals map))) 328.1221 - 328.1222 -(defn key 328.1223 - "Returns the key of the map entry." 328.1224 - {:added "1.0"} 328.1225 - [^java.util.Map$Entry e] 328.1226 - (. e (getKey))) 328.1227 - 328.1228 -(defn val 328.1229 - "Returns the value in the map entry." 328.1230 - {:added "1.0"} 328.1231 - [^java.util.Map$Entry e] 328.1232 - (. e (getValue))) 328.1233 - 328.1234 -(defn rseq 328.1235 - "Returns, in constant time, a seq of the items in rev (which 328.1236 - can be a vector or sorted-map), in reverse order. If rev is empty returns nil" 328.1237 - {:added "1.0"} 328.1238 - [^clojure.lang.Reversible rev] 328.1239 - (. rev (rseq))) 328.1240 - 328.1241 -(defn name 328.1242 - "Returns the name String of a string, symbol or keyword." 328.1243 - {:tag String 328.1244 - :added "1.0"} 328.1245 - [^clojure.lang.Named x] 328.1246 - (if (string? x) x (. x (getName)))) 328.1247 - 328.1248 -(defn namespace 328.1249 - "Returns the namespace String of a symbol or keyword, or nil if not present." 328.1250 - {:tag String 328.1251 - :added "1.0"} 328.1252 - [^clojure.lang.Named x] 328.1253 - (. x (getNamespace))) 328.1254 - 328.1255 -(defmacro locking 328.1256 - "Executes exprs in an implicit do, while holding the monitor of x. 328.1257 - Will release the monitor of x in all circumstances." 328.1258 - {:added "1.0"} 328.1259 - [x & body] 328.1260 - `(let [lockee# ~x] 328.1261 - (try 328.1262 - (monitor-enter lockee#) 328.1263 - ~@body 328.1264 - (finally 328.1265 - (monitor-exit lockee#))))) 328.1266 - 328.1267 -(defmacro .. 328.1268 - "form => fieldName-symbol or (instanceMethodName-symbol args*) 328.1269 - 328.1270 - Expands into a member access (.) of the first member on the first 328.1271 - argument, followed by the next member on the result, etc. For 328.1272 - instance: 328.1273 - 328.1274 - (.. System (getProperties) (get \"os.name\")) 328.1275 - 328.1276 - expands to: 328.1277 - 328.1278 - (. (. System (getProperties)) (get \"os.name\")) 328.1279 - 328.1280 - but is easier to write, read, and understand." 328.1281 - {:added "1.0"} 328.1282 - ([x form] `(. ~x ~form)) 328.1283 - ([x form & more] `(.. (. ~x ~form) ~@more))) 328.1284 - 328.1285 -(defmacro -> 328.1286 - "Threads the expr through the forms. Inserts x as the 328.1287 - second item in the first form, making a list of it if it is not a 328.1288 - list already. If there are more forms, inserts the first form as the 328.1289 - second item in second form, etc." 328.1290 - {:added "1.0"} 328.1291 - ([x] x) 328.1292 - ([x form] (if (seq? form) 328.1293 - (with-meta `(~(first form) ~x ~@(next form)) (meta form)) 328.1294 - (list form x))) 328.1295 - ([x form & more] `(-> (-> ~x ~form) ~@more))) 328.1296 - 328.1297 -(defmacro ->> 328.1298 - "Threads the expr through the forms. Inserts x as the 328.1299 - last item in the first form, making a list of it if it is not a 328.1300 - list already. If there are more forms, inserts the first form as the 328.1301 - last item in second form, etc." 328.1302 - {:added "1.1"} 328.1303 - ([x form] (if (seq? form) 328.1304 - (with-meta `(~(first form) ~@(next form) ~x) (meta form)) 328.1305 - (list form x))) 328.1306 - ([x form & more] `(->> (->> ~x ~form) ~@more))) 328.1307 - 328.1308 -;;multimethods 328.1309 -(def global-hierarchy) 328.1310 - 328.1311 -(defmacro defmulti 328.1312 - "Creates a new multimethod with the associated dispatch function. 328.1313 - The docstring and attribute-map are optional. 328.1314 - 328.1315 - Options are key-value pairs and may be one of: 328.1316 - :default the default dispatch value, defaults to :default 328.1317 - :hierarchy the isa? hierarchy to use for dispatching 328.1318 - defaults to the global hierarchy" 328.1319 - {:arglists '([name docstring? attr-map? dispatch-fn & options]) 328.1320 - :added "1.0"} 328.1321 - [mm-name & options] 328.1322 - (let [docstring (if (string? (first options)) 328.1323 - (first options) 328.1324 - nil) 328.1325 - options (if (string? (first options)) 328.1326 - (next options) 328.1327 - options) 328.1328 - m (if (map? (first options)) 328.1329 - (first options) 328.1330 - {}) 328.1331 - options (if (map? (first options)) 328.1332 - (next options) 328.1333 - options) 328.1334 - dispatch-fn (first options) 328.1335 - options (next options) 328.1336 - m (assoc m :tag 'clojure.lang.MultiFn) 328.1337 - m (if docstring 328.1338 - (assoc m :doc docstring) 328.1339 - m) 328.1340 - m (if (meta mm-name) 328.1341 - (conj (meta mm-name) m) 328.1342 - m)] 328.1343 - (when (= (count options) 1) 328.1344 - (throw (Exception. "The syntax for defmulti has changed. Example: (defmulti name dispatch-fn :default dispatch-value)"))) 328.1345 - (let [options (apply hash-map options) 328.1346 - default (get options :default :default) 328.1347 - hierarchy (get options :hierarchy #'global-hierarchy)] 328.1348 - `(let [v# (def ~mm-name)] 328.1349 - (when-not (and (.hasRoot v#) (instance? clojure.lang.MultiFn (deref v#))) 328.1350 - (def ~(with-meta mm-name m) 328.1351 - (new clojure.lang.MultiFn ~(name mm-name) ~dispatch-fn ~default ~hierarchy))))))) 328.1352 - 328.1353 -(defmacro defmethod 328.1354 - "Creates and installs a new method of multimethod associated with dispatch-value. " 328.1355 - {:added "1.0"} 328.1356 - [multifn dispatch-val & fn-tail] 328.1357 - `(. ~(with-meta multifn {:tag 'clojure.lang.MultiFn}) addMethod ~dispatch-val (fn ~@fn-tail))) 328.1358 - 328.1359 -(defn remove-all-methods 328.1360 - "Removes all of the methods of multimethod." 328.1361 - {:added "1.2"} 328.1362 - [^clojure.lang.MultiFn multifn] 328.1363 - (.reset multifn)) 328.1364 - 328.1365 -(defn remove-method 328.1366 - "Removes the method of multimethod associated with dispatch-value." 328.1367 - {:added "1.0"} 328.1368 - [^clojure.lang.MultiFn multifn dispatch-val] 328.1369 - (. multifn removeMethod dispatch-val)) 328.1370 - 328.1371 -(defn prefer-method 328.1372 - "Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y 328.1373 - when there is a conflict" 328.1374 - {:added "1.0"} 328.1375 - [^clojure.lang.MultiFn multifn dispatch-val-x dispatch-val-y] 328.1376 - (. multifn preferMethod dispatch-val-x dispatch-val-y)) 328.1377 - 328.1378 -(defn methods 328.1379 - "Given a multimethod, returns a map of dispatch values -> dispatch fns" 328.1380 - {:added "1.0"} 328.1381 - [^clojure.lang.MultiFn multifn] (.getMethodTable multifn)) 328.1382 - 328.1383 -(defn get-method 328.1384 - "Given a multimethod and a dispatch value, returns the dispatch fn 328.1385 - that would apply to that value, or nil if none apply and no default" 328.1386 - {:added "1.0"} 328.1387 - [^clojure.lang.MultiFn multifn dispatch-val] (.getMethod multifn dispatch-val)) 328.1388 - 328.1389 -(defn prefers 328.1390 - "Given a multimethod, returns a map of preferred value -> set of other values" 328.1391 - {:added "1.0"} 328.1392 - [^clojure.lang.MultiFn multifn] (.getPreferTable multifn)) 328.1393 - 328.1394 -;;;;;;;;; var stuff 328.1395 - 328.1396 -(defmacro ^{:private true} assert-args [fnname & pairs] 328.1397 - `(do (when-not ~(first pairs) 328.1398 - (throw (IllegalArgumentException. 328.1399 - ~(str fnname " requires " (second pairs))))) 328.1400 - ~(let [more (nnext pairs)] 328.1401 - (when more 328.1402 - (list* `assert-args fnname more))))) 328.1403 - 328.1404 -(defmacro if-let 328.1405 - "bindings => binding-form test 328.1406 - 328.1407 - If test is true, evaluates then with binding-form bound to the value of 328.1408 - test, if not, yields else" 328.1409 - {:added "1.0"} 328.1410 - ([bindings then] 328.1411 - `(if-let ~bindings ~then nil)) 328.1412 - ([bindings then else & oldform] 328.1413 - (assert-args if-let 328.1414 - (and (vector? bindings) (nil? oldform)) "a vector for its binding" 328.1415 - (= 2 (count bindings)) "exactly 2 forms in binding vector") 328.1416 - (let [form (bindings 0) tst (bindings 1)] 328.1417 - `(let [temp# ~tst] 328.1418 - (if temp# 328.1419 - (let [~form temp#] 328.1420 - ~then) 328.1421 - ~else))))) 328.1422 - 328.1423 -(defmacro when-let 328.1424 - "bindings => binding-form test 328.1425 - 328.1426 - When test is true, evaluates body with binding-form bound to the value of test" 328.1427 - {:added "1.0"} 328.1428 - [bindings & body] 328.1429 - (assert-args when-let 328.1430 - (vector? bindings) "a vector for its binding" 328.1431 - (= 2 (count bindings)) "exactly 2 forms in binding vector") 328.1432 - (let [form (bindings 0) tst (bindings 1)] 328.1433 - `(let [temp# ~tst] 328.1434 - (when temp# 328.1435 - (let [~form temp#] 328.1436 - ~@body))))) 328.1437 - 328.1438 -(defn push-thread-bindings 328.1439 - "WARNING: This is a low-level function. Prefer high-level macros like 328.1440 - binding where ever possible. 328.1441 - 328.1442 - Takes a map of Var/value pairs. Binds each Var to the associated value for 328.1443 - the current thread. Each call *MUST* be accompanied by a matching call to 328.1444 - pop-thread-bindings wrapped in a try-finally! 328.1445 - 328.1446 - (push-thread-bindings bindings) 328.1447 - (try 328.1448 - ... 328.1449 - (finally 328.1450 - (pop-thread-bindings)))" 328.1451 - {:added "1.1"} 328.1452 - [bindings] 328.1453 - (clojure.lang.Var/pushThreadBindings bindings)) 328.1454 - 328.1455 -(defn pop-thread-bindings 328.1456 - "Pop one set of bindings pushed with push-binding before. It is an error to 328.1457 - pop bindings without pushing before." 328.1458 - {:added "1.1"} 328.1459 - [] 328.1460 - (clojure.lang.Var/popThreadBindings)) 328.1461 - 328.1462 -(defn get-thread-bindings 328.1463 - "Get a map with the Var/value pairs which is currently in effect for the 328.1464 - current thread." 328.1465 - {:added "1.1"} 328.1466 - [] 328.1467 - (clojure.lang.Var/getThreadBindings)) 328.1468 - 328.1469 -(defmacro binding 328.1470 - "binding => var-symbol init-expr 328.1471 - 328.1472 - Creates new bindings for the (already-existing) vars, with the 328.1473 - supplied initial values, executes the exprs in an implicit do, then 328.1474 - re-establishes the bindings that existed before. The new bindings 328.1475 - are made in parallel (unlike let); all init-exprs are evaluated 328.1476 - before the vars are bound to their new values." 328.1477 - {:added "1.0"} 328.1478 - [bindings & body] 328.1479 - (assert-args binding 328.1480 - (vector? bindings) "a vector for its binding" 328.1481 - (even? (count bindings)) "an even number of forms in binding vector") 328.1482 - (let [var-ize (fn [var-vals] 328.1483 - (loop [ret [] vvs (seq var-vals)] 328.1484 - (if vvs 328.1485 - (recur (conj (conj ret `(var ~(first vvs))) (second vvs)) 328.1486 - (next (next vvs))) 328.1487 - (seq ret))))] 328.1488 - `(let [] 328.1489 - (push-thread-bindings (hash-map ~@(var-ize bindings))) 328.1490 - (try 328.1491 - ~@body 328.1492 - (finally 328.1493 - (pop-thread-bindings)))))) 328.1494 - 328.1495 -(defn with-bindings* 328.1496 - "Takes a map of Var/value pairs. Installs for the given Vars the associated 328.1497 - values as thread-local bindings. Then calls f with the supplied arguments. 328.1498 - Pops the installed bindings after f returned. Returns whatever f returns." 328.1499 - {:added "1.1"} 328.1500 - [binding-map f & args] 328.1501 - (push-thread-bindings binding-map) 328.1502 - (try 328.1503 - (apply f args) 328.1504 - (finally 328.1505 - (pop-thread-bindings)))) 328.1506 - 328.1507 -(defmacro with-bindings 328.1508 - "Takes a map of Var/value pairs. Installs for the given Vars the associated 328.1509 - values as thread-local bindings. The executes body. Pops the installed 328.1510 - bindings after body was evaluated. Returns the value of body." 328.1511 - {:added "1.1"} 328.1512 - [binding-map & body] 328.1513 - `(with-bindings* ~binding-map (fn [] ~@body))) 328.1514 - 328.1515 -(defn bound-fn* 328.1516 - "Returns a function, which will install the same bindings in effect as in 328.1517 - the thread at the time bound-fn* was called and then call f with any given 328.1518 - arguments. This may be used to define a helper function which runs on a 328.1519 - different thread, but needs the same bindings in place." 328.1520 - {:added "1.1"} 328.1521 - [f] 328.1522 - (let [bindings (get-thread-bindings)] 328.1523 - (fn [& args] 328.1524 - (apply with-bindings* bindings f args)))) 328.1525 - 328.1526 -(defmacro bound-fn 328.1527 - "Returns a function defined by the given fntail, which will install the 328.1528 - same bindings in effect as in the thread at the time bound-fn was called. 328.1529 - This may be used to define a helper function which runs on a different 328.1530 - thread, but needs the same bindings in place." 328.1531 - {:added "1.1"} 328.1532 - [& fntail] 328.1533 - `(bound-fn* (fn ~@fntail))) 328.1534 - 328.1535 -(defn find-var 328.1536 - "Returns the global var named by the namespace-qualified symbol, or 328.1537 - nil if no var with that name." 328.1538 - {:added "1.0"} 328.1539 - [sym] (. clojure.lang.Var (find sym))) 328.1540 - 328.1541 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Refs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 328.1542 -(defn ^{:private true} 328.1543 - setup-reference [^clojure.lang.ARef r options] 328.1544 - (let [opts (apply hash-map options)] 328.1545 - (when (:meta opts) 328.1546 - (.resetMeta r (:meta opts))) 328.1547 - (when (:validator opts) 328.1548 - (.setValidator r (:validator opts))) 328.1549 - r)) 328.1550 - 328.1551 -(defn agent 328.1552 - "Creates and returns an agent with an initial value of state and 328.1553 - zero or more options (in any order): 328.1554 - 328.1555 - :meta metadata-map 328.1556 - 328.1557 - :validator validate-fn 328.1558 - 328.1559 - :error-handler handler-fn 328.1560 - 328.1561 - :error-mode mode-keyword 328.1562 - 328.1563 - If metadata-map is supplied, it will be come the metadata on the 328.1564 - agent. validate-fn must be nil or a side-effect-free fn of one 328.1565 - argument, which will be passed the intended new state on any state 328.1566 - change. If the new state is unacceptable, the validate-fn should 328.1567 - return false or throw an exception. handler-fn is called if an 328.1568 - action throws an exception or if validate-fn rejects a new state -- 328.1569 - see set-error-handler! for details. The mode-keyword may be either 328.1570 - :continue (the default if an error-handler is given) or :fail (the 328.1571 - default if no error-handler is given) -- see set-error-mode! for 328.1572 - details." 328.1573 - {:added "1.0"} 328.1574 - ([state & options] 328.1575 - (let [a (new clojure.lang.Agent state) 328.1576 - opts (apply hash-map options)] 328.1577 - (setup-reference a options) 328.1578 - (when (:error-handler opts) 328.1579 - (.setErrorHandler a (:error-handler opts))) 328.1580 - (.setErrorMode a (or (:error-mode opts) 328.1581 - (if (:error-handler opts) :continue :fail))) 328.1582 - a))) 328.1583 - 328.1584 -(defn send 328.1585 - "Dispatch an action to an agent. Returns the agent immediately. 328.1586 - Subsequently, in a thread from a thread pool, the state of the agent 328.1587 - will be set to the value of: 328.1588 - 328.1589 - (apply action-fn state-of-agent args)" 328.1590 - {:added "1.0"} 328.1591 - [^clojure.lang.Agent a f & args] 328.1592 - (. a (dispatch f args false))) 328.1593 - 328.1594 -(defn send-off 328.1595 - "Dispatch a potentially blocking action to an agent. Returns the 328.1596 - agent immediately. Subsequently, in a separate thread, the state of 328.1597 - the agent will be set to the value of: 328.1598 - 328.1599 - (apply action-fn state-of-agent args)" 328.1600 - {:added "1.0"} 328.1601 - [^clojure.lang.Agent a f & args] 328.1602 - (. a (dispatch f args true))) 328.1603 - 328.1604 -(defn release-pending-sends 328.1605 - "Normally, actions sent directly or indirectly during another action 328.1606 - are held until the action completes (changes the agent's 328.1607 - state). This function can be used to dispatch any pending sent 328.1608 - actions immediately. This has no impact on actions sent during a 328.1609 - transaction, which are still held until commit. If no action is 328.1610 - occurring, does nothing. Returns the number of actions dispatched." 328.1611 - {:added "1.0"} 328.1612 - [] (clojure.lang.Agent/releasePendingSends)) 328.1613 - 328.1614 -(defn add-watch 328.1615 - "Alpha - subject to change. 328.1616 - Adds a watch function to an agent/atom/var/ref reference. The watch 328.1617 - fn must be a fn of 4 args: a key, the reference, its old-state, its 328.1618 - new-state. Whenever the reference's state might have been changed, 328.1619 - any registered watches will have their functions called. The watch fn 328.1620 - will be called synchronously, on the agent's thread if an agent, 328.1621 - before any pending sends if agent or ref. Note that an atom's or 328.1622 - ref's state may have changed again prior to the fn call, so use 328.1623 - old/new-state rather than derefing the reference. Note also that watch 328.1624 - fns may be called from multiple threads simultaneously. Var watchers 328.1625 - are triggered only by root binding changes, not thread-local 328.1626 - set!s. Keys must be unique per reference, and can be used to remove 328.1627 - the watch with remove-watch, but are otherwise considered opaque by 328.1628 - the watch mechanism." 328.1629 - {:added "1.0"} 328.1630 - [^clojure.lang.IRef reference key fn] (.addWatch reference key fn)) 328.1631 - 328.1632 -(defn remove-watch 328.1633 - "Alpha - subject to change. 328.1634 - Removes a watch (set by add-watch) from a reference" 328.1635 - {:added "1.0"} 328.1636 - [^clojure.lang.IRef reference key] 328.1637 - (.removeWatch reference key)) 328.1638 - 328.1639 -(defn agent-error 328.1640 - "Returns the exception thrown during an asynchronous action of the 328.1641 - agent if the agent is failed. Returns nil if the agent is not 328.1642 - failed." 328.1643 - {:added "1.2"} 328.1644 - [^clojure.lang.Agent a] (.getError a)) 328.1645 - 328.1646 -(defn restart-agent 328.1647 - "When an agent is failed, changes the agent state to new-state and 328.1648 - then un-fails the agent so that sends are allowed again. If 328.1649 - a :clear-actions true option is given, any actions queued on the 328.1650 - agent that were being held while it was failed will be discarded, 328.1651 - otherwise those held actions will proceed. The new-state must pass 328.1652 - the validator if any, or restart will throw an exception and the 328.1653 - agent will remain failed with its old state and error. Watchers, if 328.1654 - any, will NOT be notified of the new state. Throws an exception if 328.1655 - the agent is not failed." 328.1656 - {:added "1.2"} 328.1657 - [^clojure.lang.Agent a, new-state & options] 328.1658 - (let [opts (apply hash-map options)] 328.1659 - (.restart a new-state (if (:clear-actions opts) true false)))) 328.1660 - 328.1661 -(defn set-error-handler! 328.1662 - "Sets the error-handler of agent a to handler-fn. If an action 328.1663 - being run by the agent throws an exception or doesn't pass the 328.1664 - validator fn, handler-fn will be called with two arguments: the 328.1665 - agent and the exception." 328.1666 - {:added "1.2"} 328.1667 - [^clojure.lang.Agent a, handler-fn] 328.1668 - (.setErrorHandler a handler-fn)) 328.1669 - 328.1670 -(defn error-handler 328.1671 - "Returns the error-handler of agent a, or nil if there is none. 328.1672 - See set-error-handler!" 328.1673 - {:added "1.2"} 328.1674 - [^clojure.lang.Agent a] 328.1675 - (.getErrorHandler a)) 328.1676 - 328.1677 -(defn set-error-mode! 328.1678 - "Sets the error-mode of agent a to mode-keyword, which must be 328.1679 - either :fail or :continue. If an action being run by the agent 328.1680 - throws an exception or doesn't pass the validator fn, an 328.1681 - error-handler may be called (see set-error-handler!), after which, 328.1682 - if the mode is :continue, the agent will continue as if neither the 328.1683 - action that caused the error nor the error itself ever happened. 328.1684 - 328.1685 - If the mode is :fail, the agent will become failed and will stop 328.1686 - accepting new 'send' and 'send-off' actions, and any previously 328.1687 - queued actions will be held until a 'restart-agent'. Deref will 328.1688 - still work, returning the state of the agent before the error." 328.1689 - {:added "1.2"} 328.1690 - [^clojure.lang.Agent a, mode-keyword] 328.1691 - (.setErrorMode a mode-keyword)) 328.1692 - 328.1693 -(defn error-mode 328.1694 - "Returns the error-mode of agent a. See set-error-mode!" 328.1695 - {:added "1.2"} 328.1696 - [^clojure.lang.Agent a] 328.1697 - (.getErrorMode a)) 328.1698 - 328.1699 -(defn agent-errors 328.1700 - "DEPRECATED: Use 'agent-error' instead. 328.1701 - Returns a sequence of the exceptions thrown during asynchronous 328.1702 - actions of the agent." 328.1703 - {:added "1.0" 328.1704 - :deprecated "1.2"} 328.1705 - [a] 328.1706 - (when-let [e (agent-error a)] 328.1707 - (list e))) 328.1708 - 328.1709 -(defn clear-agent-errors 328.1710 - "DEPRECATED: Use 'restart-agent' instead. 328.1711 - Clears any exceptions thrown during asynchronous actions of the 328.1712 - agent, allowing subsequent actions to occur." 328.1713 - {:added "1.0" 328.1714 - :deprecated "1.2"} 328.1715 - [^clojure.lang.Agent a] (restart-agent a (.deref a))) 328.1716 - 328.1717 -(defn shutdown-agents 328.1718 - "Initiates a shutdown of the thread pools that back the agent 328.1719 - system. Running actions will complete, but no new actions will be 328.1720 - accepted" 328.1721 - {:added "1.0"} 328.1722 - [] (. clojure.lang.Agent shutdown)) 328.1723 - 328.1724 -(defn ref 328.1725 - "Creates and returns a Ref with an initial value of x and zero or 328.1726 - more options (in any order): 328.1727 - 328.1728 - :meta metadata-map 328.1729 - 328.1730 - :validator validate-fn 328.1731 - 328.1732 - :min-history (default 0) 328.1733 - :max-history (default 10) 328.1734 - 328.1735 - If metadata-map is supplied, it will be come the metadata on the 328.1736 - ref. validate-fn must be nil or a side-effect-free fn of one 328.1737 - argument, which will be passed the intended new state on any state 328.1738 - change. If the new state is unacceptable, the validate-fn should 328.1739 - return false or throw an exception. validate-fn will be called on 328.1740 - transaction commit, when all refs have their final values. 328.1741 - 328.1742 - Normally refs accumulate history dynamically as needed to deal with 328.1743 - read demands. If you know in advance you will need history you can 328.1744 - set :min-history to ensure it will be available when first needed (instead 328.1745 - of after a read fault). History is limited, and the limit can be set 328.1746 - with :max-history." 328.1747 - {:added "1.0"} 328.1748 - ([x] (new clojure.lang.Ref x)) 328.1749 - ([x & options] 328.1750 - (let [r ^clojure.lang.Ref (setup-reference (ref x) options) 328.1751 - opts (apply hash-map options)] 328.1752 - (when (:max-history opts) 328.1753 - (.setMaxHistory r (:max-history opts))) 328.1754 - (when (:min-history opts) 328.1755 - (.setMinHistory r (:min-history opts))) 328.1756 - r))) 328.1757 - 328.1758 -(defn deref 328.1759 - "Also reader macro: @ref/@agent/@var/@atom/@delay/@future. Within a transaction, 328.1760 - returns the in-transaction-value of ref, else returns the 328.1761 - most-recently-committed value of ref. When applied to a var, agent 328.1762 - or atom, returns its current state. When applied to a delay, forces 328.1763 - it if not already forced. When applied to a future, will block if 328.1764 - computation not complete" 328.1765 - {:added "1.0"} 328.1766 - [^clojure.lang.IDeref ref] (.deref ref)) 328.1767 - 328.1768 -(defn atom 328.1769 - "Creates and returns an Atom with an initial value of x and zero or 328.1770 - more options (in any order): 328.1771 - 328.1772 - :meta metadata-map 328.1773 - 328.1774 - :validator validate-fn 328.1775 - 328.1776 - If metadata-map is supplied, it will be come the metadata on the 328.1777 - atom. validate-fn must be nil or a side-effect-free fn of one 328.1778 - argument, which will be passed the intended new state on any state 328.1779 - change. If the new state is unacceptable, the validate-fn should 328.1780 - return false or throw an exception." 328.1781 - {:added "1.0"} 328.1782 - ([x] (new clojure.lang.Atom x)) 328.1783 - ([x & options] (setup-reference (atom x) options))) 328.1784 - 328.1785 -(defn swap! 328.1786 - "Atomically swaps the value of atom to be: 328.1787 - (apply f current-value-of-atom args). Note that f may be called 328.1788 - multiple times, and thus should be free of side effects. Returns 328.1789 - the value that was swapped in." 328.1790 - {:added "1.0"} 328.1791 - ([^clojure.lang.Atom atom f] (.swap atom f)) 328.1792 - ([^clojure.lang.Atom atom f x] (.swap atom f x)) 328.1793 - ([^clojure.lang.Atom atom f x y] (.swap atom f x y)) 328.1794 - ([^clojure.lang.Atom atom f x y & args] (.swap atom f x y args))) 328.1795 - 328.1796 -(defn compare-and-set! 328.1797 - "Atomically sets the value of atom to newval if and only if the 328.1798 - current value of the atom is identical to oldval. Returns true if 328.1799 - set happened, else false" 328.1800 - {:added "1.0"} 328.1801 - [^clojure.lang.Atom atom oldval newval] (.compareAndSet atom oldval newval)) 328.1802 - 328.1803 -(defn reset! 328.1804 - "Sets the value of atom to newval without regard for the 328.1805 - current value. Returns newval." 328.1806 - {:added "1.0"} 328.1807 - [^clojure.lang.Atom atom newval] (.reset atom newval)) 328.1808 - 328.1809 -(defn set-validator! 328.1810 - "Sets the validator-fn for a var/ref/agent/atom. validator-fn must be nil or a 328.1811 - side-effect-free fn of one argument, which will be passed the intended 328.1812 - new state on any state change. If the new state is unacceptable, the 328.1813 - validator-fn should return false or throw an exception. If the current state (root 328.1814 - value if var) is not acceptable to the new validator, an exception 328.1815 - will be thrown and the validator will not be changed." 328.1816 - {:added "1.0"} 328.1817 - [^clojure.lang.IRef iref validator-fn] (. iref (setValidator validator-fn))) 328.1818 - 328.1819 -(defn get-validator 328.1820 - "Gets the validator-fn for a var/ref/agent/atom." 328.1821 - {:added "1.0"} 328.1822 - [^clojure.lang.IRef iref] (. iref (getValidator))) 328.1823 - 328.1824 -(defn alter-meta! 328.1825 - "Atomically sets the metadata for a namespace/var/ref/agent/atom to be: 328.1826 - 328.1827 - (apply f its-current-meta args) 328.1828 - 328.1829 - f must be free of side-effects" 328.1830 - {:added "1.0"} 328.1831 - [^clojure.lang.IReference iref f & args] (.alterMeta iref f args)) 328.1832 - 328.1833 -(defn reset-meta! 328.1834 - "Atomically resets the metadata for a namespace/var/ref/agent/atom" 328.1835 - {:added "1.0"} 328.1836 - [^clojure.lang.IReference iref metadata-map] (.resetMeta iref metadata-map)) 328.1837 - 328.1838 -(defn commute 328.1839 - "Must be called in a transaction. Sets the in-transaction-value of 328.1840 - ref to: 328.1841 - 328.1842 - (apply fun in-transaction-value-of-ref args) 328.1843 - 328.1844 - and returns the in-transaction-value of ref. 328.1845 - 328.1846 - At the commit point of the transaction, sets the value of ref to be: 328.1847 - 328.1848 - (apply fun most-recently-committed-value-of-ref args) 328.1849 - 328.1850 - Thus fun should be commutative, or, failing that, you must accept 328.1851 - last-one-in-wins behavior. commute allows for more concurrency than 328.1852 - ref-set." 328.1853 - {:added "1.0"} 328.1854 - 328.1855 - [^clojure.lang.Ref ref fun & args] 328.1856 - (. ref (commute fun args))) 328.1857 - 328.1858 -(defn alter 328.1859 - "Must be called in a transaction. Sets the in-transaction-value of 328.1860 - ref to: 328.1861 - 328.1862 - (apply fun in-transaction-value-of-ref args) 328.1863 - 328.1864 - and returns the in-transaction-value of ref." 328.1865 - {:added "1.0"} 328.1866 - [^clojure.lang.Ref ref fun & args] 328.1867 - (. ref (alter fun args))) 328.1868 - 328.1869 -(defn ref-set 328.1870 - "Must be called in a transaction. Sets the value of ref. 328.1871 - Returns val." 328.1872 - {:added "1.0"} 328.1873 - [^clojure.lang.Ref ref val] 328.1874 - (. ref (set val))) 328.1875 - 328.1876 -(defn ref-history-count 328.1877 - "Returns the history count of a ref" 328.1878 - {:added "1.1"} 328.1879 - [^clojure.lang.Ref ref] 328.1880 - (.getHistoryCount ref)) 328.1881 - 328.1882 -(defn ref-min-history 328.1883 - "Gets the min-history of a ref, or sets it and returns the ref" 328.1884 - {:added "1.1"} 328.1885 - ([^clojure.lang.Ref ref] 328.1886 - (.getMinHistory ref)) 328.1887 - ([^clojure.lang.Ref ref n] 328.1888 - (.setMinHistory ref n))) 328.1889 - 328.1890 -(defn ref-max-history 328.1891 - "Gets the max-history of a ref, or sets it and returns the ref" 328.1892 - {:added "1.1"} 328.1893 - ([^clojure.lang.Ref ref] 328.1894 - (.getMaxHistory ref)) 328.1895 - ([^clojure.lang.Ref ref n] 328.1896 - (.setMaxHistory ref n))) 328.1897 - 328.1898 -(defn ensure 328.1899 - "Must be called in a transaction. Protects the ref from modification 328.1900 - by other transactions. Returns the in-transaction-value of 328.1901 - ref. Allows for more concurrency than (ref-set ref @ref)" 328.1902 - {:added "1.0"} 328.1903 - [^clojure.lang.Ref ref] 328.1904 - (. ref (touch)) 328.1905 - (. ref (deref))) 328.1906 - 328.1907 -(defmacro sync 328.1908 - "transaction-flags => TBD, pass nil for now 328.1909 - 328.1910 - Runs the exprs (in an implicit do) in a transaction that encompasses 328.1911 - exprs and any nested calls. Starts a transaction if none is already 328.1912 - running on this thread. Any uncaught exception will abort the 328.1913 - transaction and flow out of sync. The exprs may be run more than 328.1914 - once, but any effects on Refs will be atomic." 328.1915 - {:added "1.0"} 328.1916 - [flags-ignored-for-now & body] 328.1917 - `(. clojure.lang.LockingTransaction 328.1918 - (runInTransaction (fn [] ~@body)))) 328.1919 - 328.1920 - 328.1921 -(defmacro io! 328.1922 - "If an io! block occurs in a transaction, throws an 328.1923 - IllegalStateException, else runs body in an implicit do. If the 328.1924 - first expression in body is a literal string, will use that as the 328.1925 - exception message." 328.1926 - {:added "1.0"} 328.1927 - [& body] 328.1928 - (let [message (when (string? (first body)) (first body)) 328.1929 - body (if message (next body) body)] 328.1930 - `(if (clojure.lang.LockingTransaction/isRunning) 328.1931 - (throw (new IllegalStateException ~(or message "I/O in transaction"))) 328.1932 - (do ~@body)))) 328.1933 - 328.1934 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fn stuff ;;;;;;;;;;;;;;;; 328.1935 - 328.1936 - 328.1937 -(defn comp 328.1938 - "Takes a set of functions and returns a fn that is the composition 328.1939 - of those fns. The returned fn takes a variable number of args, 328.1940 - applies the rightmost of fns to the args, the next 328.1941 - fn (right-to-left) to the result, etc." 328.1942 - {:added "1.0"} 328.1943 - ([f] f) 328.1944 - ([f g] 328.1945 - (fn 328.1946 - ([] (f (g))) 328.1947 - ([x] (f (g x))) 328.1948 - ([x y] (f (g x y))) 328.1949 - ([x y z] (f (g x y z))) 328.1950 - ([x y z & args] (f (apply g x y z args))))) 328.1951 - ([f g h] 328.1952 - (fn 328.1953 - ([] (f (g (h)))) 328.1954 - ([x] (f (g (h x)))) 328.1955 - ([x y] (f (g (h x y)))) 328.1956 - ([x y z] (f (g (h x y z)))) 328.1957 - ([x y z & args] (f (g (apply h x y z args)))))) 328.1958 - ([f1 f2 f3 & fs] 328.1959 - (let [fs (reverse (list* f1 f2 f3 fs))] 328.1960 - (fn [& args] 328.1961 - (loop [ret (apply (first fs) args) fs (next fs)] 328.1962 - (if fs 328.1963 - (recur ((first fs) ret) (next fs)) 328.1964 - ret)))))) 328.1965 - 328.1966 -(defn juxt 328.1967 - "Alpha - name subject to change. 328.1968 - Takes a set of functions and returns a fn that is the juxtaposition 328.1969 - of those fns. The returned fn takes a variable number of args, and 328.1970 - returns a vector containing the result of applying each fn to the 328.1971 - args (left-to-right). 328.1972 - ((juxt a b c) x) => [(a x) (b x) (c x)]" 328.1973 - {:added "1.1"} 328.1974 - ([f] 328.1975 - (fn 328.1976 - ([] [(f)]) 328.1977 - ([x] [(f x)]) 328.1978 - ([x y] [(f x y)]) 328.1979 - ([x y z] [(f x y z)]) 328.1980 - ([x y z & args] [(apply f x y z args)]))) 328.1981 - ([f g] 328.1982 - (fn 328.1983 - ([] [(f) (g)]) 328.1984 - ([x] [(f x) (g x)]) 328.1985 - ([x y] [(f x y) (g x y)]) 328.1986 - ([x y z] [(f x y z) (g x y z)]) 328.1987 - ([x y z & args] [(apply f x y z args) (apply g x y z args)]))) 328.1988 - ([f g h] 328.1989 - (fn 328.1990 - ([] [(f) (g) (h)]) 328.1991 - ([x] [(f x) (g x) (h x)]) 328.1992 - ([x y] [(f x y) (g x y) (h x y)]) 328.1993 - ([x y z] [(f x y z) (g x y z) (h x y z)]) 328.1994 - ([x y z & args] [(apply f x y z args) (apply g x y z args) (apply h x y z args)]))) 328.1995 - ([f g h & fs] 328.1996 - (let [fs (list* f g h fs)] 328.1997 - (fn 328.1998 - ([] (reduce #(conj %1 (%2)) [] fs)) 328.1999 - ([x] (reduce #(conj %1 (%2 x)) [] fs)) 328.2000 - ([x y] (reduce #(conj %1 (%2 x y)) [] fs)) 328.2001 - ([x y z] (reduce #(conj %1 (%2 x y z)) [] fs)) 328.2002 - ([x y z & args] (reduce #(conj %1 (apply %2 x y z args)) [] fs)))))) 328.2003 - 328.2004 -(defn partial 328.2005 - "Takes a function f and fewer than the normal arguments to f, and 328.2006 - returns a fn that takes a variable number of additional args. When 328.2007 - called, the returned function calls f with args + additional args." 328.2008 - {:added "1.0"} 328.2009 - ([f arg1] 328.2010 - (fn [& args] (apply f arg1 args))) 328.2011 - ([f arg1 arg2] 328.2012 - (fn [& args] (apply f arg1 arg2 args))) 328.2013 - ([f arg1 arg2 arg3] 328.2014 - (fn [& args] (apply f arg1 arg2 arg3 args))) 328.2015 - ([f arg1 arg2 arg3 & more] 328.2016 - (fn [& args] (apply f arg1 arg2 arg3 (concat more args))))) 328.2017 - 328.2018 -;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;; 328.2019 -(defn sequence 328.2020 - "Coerces coll to a (possibly empty) sequence, if it is not already 328.2021 - one. Will not force a lazy seq. (sequence nil) yields ()" 328.2022 - {:added "1.0"} 328.2023 - [coll] 328.2024 - (if (seq? coll) coll 328.2025 - (or (seq coll) ()))) 328.2026 - 328.2027 -(defn every? 328.2028 - "Returns true if (pred x) is logical true for every x in coll, else 328.2029 - false." 328.2030 - {:tag Boolean 328.2031 - :added "1.0"} 328.2032 - [pred coll] 328.2033 - (cond 328.2034 - (nil? (seq coll)) true 328.2035 - (pred (first coll)) (recur pred (next coll)) 328.2036 - :else false)) 328.2037 - 328.2038 -(def 328.2039 - ^{:tag Boolean 328.2040 - :doc "Returns false if (pred x) is logical true for every x in 328.2041 - coll, else true." 328.2042 - :arglists '([pred coll]) 328.2043 - :added "1.0"} 328.2044 - not-every? (comp not every?)) 328.2045 - 328.2046 -(defn some 328.2047 - "Returns the first logical true value of (pred x) for any x in coll, 328.2048 - else nil. One common idiom is to use a set as pred, for example 328.2049 - this will return :fred if :fred is in the sequence, otherwise nil: 328.2050 - (some #{:fred} coll)" 328.2051 - {:added "1.0"} 328.2052 - [pred coll] 328.2053 - (when (seq coll) 328.2054 - (or (pred (first coll)) (recur pred (next coll))))) 328.2055 - 328.2056 -(def 328.2057 - ^{:tag Boolean 328.2058 - :doc "Returns false if (pred x) is logical true for any x in coll, 328.2059 - else true." 328.2060 - :arglists '([pred coll]) 328.2061 - :added "1.0"} 328.2062 - not-any? (comp not some)) 328.2063 - 328.2064 -;will be redefed later with arg checks 328.2065 -(defmacro dotimes 328.2066 - "bindings => name n 328.2067 - 328.2068 - Repeatedly executes body (presumably for side-effects) with name 328.2069 - bound to integers from 0 through n-1." 328.2070 - {:added "1.0"} 328.2071 - [bindings & body] 328.2072 - (let [i (first bindings) 328.2073 - n (second bindings)] 328.2074 - `(let [n# (int ~n)] 328.2075 - (loop [~i (int 0)] 328.2076 - (when (< ~i n#) 328.2077 - ~@body 328.2078 - (recur (inc ~i))))))) 328.2079 - 328.2080 -(defn map 328.2081 - "Returns a lazy sequence consisting of the result of applying f to the 328.2082 - set of first items of each coll, followed by applying f to the set 328.2083 - of second items in each coll, until any one of the colls is 328.2084 - exhausted. Any remaining items in other colls are ignored. Function 328.2085 - f should accept number-of-colls arguments." 328.2086 - {:added "1.0"} 328.2087 - ([f coll] 328.2088 - (lazy-seq 328.2089 - (when-let [s (seq coll)] 328.2090 - (if (chunked-seq? s) 328.2091 - (let [c (chunk-first s) 328.2092 - size (int (count c)) 328.2093 - b (chunk-buffer size)] 328.2094 - (dotimes [i size] 328.2095 - (chunk-append b (f (.nth c i)))) 328.2096 - (chunk-cons (chunk b) (map f (chunk-rest s)))) 328.2097 - (cons (f (first s)) (map f (rest s))))))) 328.2098 - ([f c1 c2] 328.2099 - (lazy-seq 328.2100 - (let [s1 (seq c1) s2 (seq c2)] 328.2101 - (when (and s1 s2) 328.2102 - (cons (f (first s1) (first s2)) 328.2103 - (map f (rest s1) (rest s2))))))) 328.2104 - ([f c1 c2 c3] 328.2105 - (lazy-seq 328.2106 - (let [s1 (seq c1) s2 (seq c2) s3 (seq c3)] 328.2107 - (when (and s1 s2 s3) 328.2108 - (cons (f (first s1) (first s2) (first s3)) 328.2109 - (map f (rest s1) (rest s2) (rest s3))))))) 328.2110 - ([f c1 c2 c3 & colls] 328.2111 - (let [step (fn step [cs] 328.2112 - (lazy-seq 328.2113 - (let [ss (map seq cs)] 328.2114 - (when (every? identity ss) 328.2115 - (cons (map first ss) (step (map rest ss)))))))] 328.2116 - (map #(apply f %) (step (conj colls c3 c2 c1)))))) 328.2117 - 328.2118 -(defn mapcat 328.2119 - "Returns the result of applying concat to the result of applying map 328.2120 - to f and colls. Thus function f should return a collection." 328.2121 - {:added "1.0"} 328.2122 - [f & colls] 328.2123 - (apply concat (apply map f colls))) 328.2124 - 328.2125 -(defn filter 328.2126 - "Returns a lazy sequence of the items in coll for which 328.2127 - (pred item) returns true. pred must be free of side-effects." 328.2128 - {:added "1.0"} 328.2129 - ([pred coll] 328.2130 - (lazy-seq 328.2131 - (when-let [s (seq coll)] 328.2132 - (if (chunked-seq? s) 328.2133 - (let [c (chunk-first s) 328.2134 - size (count c) 328.2135 - b (chunk-buffer size)] 328.2136 - (dotimes [i size] 328.2137 - (when (pred (.nth c i)) 328.2138 - (chunk-append b (.nth c i)))) 328.2139 - (chunk-cons (chunk b) (filter pred (chunk-rest s)))) 328.2140 - (let [f (first s) r (rest s)] 328.2141 - (if (pred f) 328.2142 - (cons f (filter pred r)) 328.2143 - (filter pred r)))))))) 328.2144 - 328.2145 - 328.2146 -(defn remove 328.2147 - "Returns a lazy sequence of the items in coll for which 328.2148 - (pred item) returns false. pred must be free of side-effects." 328.2149 - {:added "1.0"} 328.2150 - [pred coll] 328.2151 - (filter (complement pred) coll)) 328.2152 - 328.2153 -(defn take 328.2154 - "Returns a lazy sequence of the first n items in coll, or all items if 328.2155 - there are fewer than n." 328.2156 - {:added "1.0"} 328.2157 - [n coll] 328.2158 - (lazy-seq 328.2159 - (when (pos? n) 328.2160 - (when-let [s (seq coll)] 328.2161 - (cons (first s) (take (dec n) (rest s))))))) 328.2162 - 328.2163 -(defn take-while 328.2164 - "Returns a lazy sequence of successive items from coll while 328.2165 - (pred item) returns true. pred must be free of side-effects." 328.2166 - {:added "1.0"} 328.2167 - [pred coll] 328.2168 - (lazy-seq 328.2169 - (when-let [s (seq coll)] 328.2170 - (when (pred (first s)) 328.2171 - (cons (first s) (take-while pred (rest s))))))) 328.2172 - 328.2173 -(defn drop 328.2174 - "Returns a lazy sequence of all but the first n items in coll." 328.2175 - {:added "1.0"} 328.2176 - [n coll] 328.2177 - (let [step (fn [n coll] 328.2178 - (let [s (seq coll)] 328.2179 - (if (and (pos? n) s) 328.2180 - (recur (dec n) (rest s)) 328.2181 - s)))] 328.2182 - (lazy-seq (step n coll)))) 328.2183 - 328.2184 -(defn drop-last 328.2185 - "Return a lazy sequence of all but the last n (default 1) items in coll" 328.2186 - {:added "1.0"} 328.2187 - ([s] (drop-last 1 s)) 328.2188 - ([n s] (map (fn [x _] x) s (drop n s)))) 328.2189 - 328.2190 -(defn take-last 328.2191 - "Returns a seq of the last n items in coll. Depending on the type 328.2192 - of coll may be no better than linear time. For vectors, see also subvec." 328.2193 - {:added "1.1"} 328.2194 - [n coll] 328.2195 - (loop [s (seq coll), lead (seq (drop n coll))] 328.2196 - (if lead 328.2197 - (recur (next s) (next lead)) 328.2198 - s))) 328.2199 - 328.2200 -(defn drop-while 328.2201 - "Returns a lazy sequence of the items in coll starting from the first 328.2202 - item for which (pred item) returns nil." 328.2203 - {:added "1.0"} 328.2204 - [pred coll] 328.2205 - (let [step (fn [pred coll] 328.2206 - (let [s (seq coll)] 328.2207 - (if (and s (pred (first s))) 328.2208 - (recur pred (rest s)) 328.2209 - s)))] 328.2210 - (lazy-seq (step pred coll)))) 328.2211 - 328.2212 -(defn cycle 328.2213 - "Returns a lazy (infinite!) sequence of repetitions of the items in coll." 328.2214 - {:added "1.0"} 328.2215 - [coll] (lazy-seq 328.2216 - (when-let [s (seq coll)] 328.2217 - (concat s (cycle s))))) 328.2218 - 328.2219 -(defn split-at 328.2220 - "Returns a vector of [(take n coll) (drop n coll)]" 328.2221 - {:added "1.0"} 328.2222 - [n coll] 328.2223 - [(take n coll) (drop n coll)]) 328.2224 - 328.2225 -(defn split-with 328.2226 - "Returns a vector of [(take-while pred coll) (drop-while pred coll)]" 328.2227 - {:added "1.0"} 328.2228 - [pred coll] 328.2229 - [(take-while pred coll) (drop-while pred coll)]) 328.2230 - 328.2231 -(defn repeat 328.2232 - "Returns a lazy (infinite!, or length n if supplied) sequence of xs." 328.2233 - {:added "1.0"} 328.2234 - ([x] (lazy-seq (cons x (repeat x)))) 328.2235 - ([n x] (take n (repeat x)))) 328.2236 - 328.2237 -(defn replicate 328.2238 - "Returns a lazy seq of n xs." 328.2239 - {:added "1.0"} 328.2240 - [n x] (take n (repeat x))) 328.2241 - 328.2242 -(defn iterate 328.2243 - "Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects" 328.2244 - {:added "1.0"} 328.2245 - [f x] (cons x (lazy-seq (iterate f (f x))))) 328.2246 - 328.2247 -(defn range 328.2248 - "Returns a lazy seq of nums from start (inclusive) to end 328.2249 - (exclusive), by step, where start defaults to 0, step to 1, and end 328.2250 - to infinity." 328.2251 - {:added "1.0"} 328.2252 - ([] (range 0 Double/POSITIVE_INFINITY 1)) 328.2253 - ([end] (range 0 end 1)) 328.2254 - ([start end] (range start end 1)) 328.2255 - ([start end step] 328.2256 - (lazy-seq 328.2257 - (let [b (chunk-buffer 32) 328.2258 - comp (if (pos? step) < >)] 328.2259 - (loop [i start] 328.2260 - (if (and (< (count b) 32) 328.2261 - (comp i end)) 328.2262 - (do 328.2263 - (chunk-append b i) 328.2264 - (recur (+ i step))) 328.2265 - (chunk-cons (chunk b) 328.2266 - (when (comp i end) 328.2267 - (range i end step))))))))) 328.2268 - 328.2269 -(defn merge 328.2270 - "Returns a map that consists of the rest of the maps conj-ed onto 328.2271 - the first. If a key occurs in more than one map, the mapping from 328.2272 - the latter (left-to-right) will be the mapping in the result." 328.2273 - {:added "1.0"} 328.2274 - [& maps] 328.2275 - (when (some identity maps) 328.2276 - (reduce #(conj (or %1 {}) %2) maps))) 328.2277 - 328.2278 -(defn merge-with 328.2279 - "Returns a map that consists of the rest of the maps conj-ed onto 328.2280 - the first. If a key occurs in more than one map, the mapping(s) 328.2281 - from the latter (left-to-right) will be combined with the mapping in 328.2282 - the result by calling (f val-in-result val-in-latter)." 328.2283 - {:added "1.0"} 328.2284 - [f & maps] 328.2285 - (when (some identity maps) 328.2286 - (let [merge-entry (fn [m e] 328.2287 - (let [k (key e) v (val e)] 328.2288 - (if (contains? m k) 328.2289 - (assoc m k (f (get m k) v)) 328.2290 - (assoc m k v)))) 328.2291 - merge2 (fn [m1 m2] 328.2292 - (reduce merge-entry (or m1 {}) (seq m2)))] 328.2293 - (reduce merge2 maps)))) 328.2294 - 328.2295 - 328.2296 - 328.2297 -(defn zipmap 328.2298 - "Returns a map with the keys mapped to the corresponding vals." 328.2299 - {:added "1.0"} 328.2300 - [keys vals] 328.2301 - (loop [map {} 328.2302 - ks (seq keys) 328.2303 - vs (seq vals)] 328.2304 - (if (and ks vs) 328.2305 - (recur (assoc map (first ks) (first vs)) 328.2306 - (next ks) 328.2307 - (next vs)) 328.2308 - map))) 328.2309 - 328.2310 -(defmacro declare 328.2311 - "defs the supplied var names with no bindings, useful for making forward declarations." 328.2312 - {:added "1.0"} 328.2313 - [& names] `(do ~@(map #(list 'def (vary-meta % assoc :declared true)) names))) 328.2314 - 328.2315 -(defn line-seq 328.2316 - "Returns the lines of text from rdr as a lazy sequence of strings. 328.2317 - rdr must implement java.io.BufferedReader." 328.2318 - {:added "1.0"} 328.2319 - [^java.io.BufferedReader rdr] 328.2320 - (when-let [line (.readLine rdr)] 328.2321 - (cons line (lazy-seq (line-seq rdr))))) 328.2322 - 328.2323 -(defn comparator 328.2324 - "Returns an implementation of java.util.Comparator based upon pred." 328.2325 - {:added "1.0"} 328.2326 - [pred] 328.2327 - (fn [x y] 328.2328 - (cond (pred x y) -1 (pred y x) 1 :else 0))) 328.2329 - 328.2330 -(defn sort 328.2331 - "Returns a sorted sequence of the items in coll. If no comparator is 328.2332 - supplied, uses compare. comparator must 328.2333 - implement java.util.Comparator." 328.2334 - {:added "1.0"} 328.2335 - ([coll] 328.2336 - (sort compare coll)) 328.2337 - ([^java.util.Comparator comp coll] 328.2338 - (if (seq coll) 328.2339 - (let [a (to-array coll)] 328.2340 - (. java.util.Arrays (sort a comp)) 328.2341 - (seq a)) 328.2342 - ()))) 328.2343 - 328.2344 -(defn sort-by 328.2345 - "Returns a sorted sequence of the items in coll, where the sort 328.2346 - order is determined by comparing (keyfn item). If no comparator is 328.2347 - supplied, uses compare. comparator must 328.2348 - implement java.util.Comparator." 328.2349 - {:added "1.0"} 328.2350 - ([keyfn coll] 328.2351 - (sort-by keyfn compare coll)) 328.2352 - ([keyfn ^java.util.Comparator comp coll] 328.2353 - (sort (fn [x y] (. comp (compare (keyfn x) (keyfn y)))) coll))) 328.2354 - 328.2355 -(defn partition 328.2356 - "Returns a lazy sequence of lists of n items each, at offsets step 328.2357 - apart. If step is not supplied, defaults to n, i.e. the partitions 328.2358 - do not overlap. If a pad collection is supplied, use its elements as 328.2359 - necessary to complete last partition upto n items. In case there are 328.2360 - not enough padding elements, return a partition with less than n items." 328.2361 - {:added "1.0"} 328.2362 - ([n coll] 328.2363 - (partition n n coll)) 328.2364 - ([n step coll] 328.2365 - (lazy-seq 328.2366 - (when-let [s (seq coll)] 328.2367 - (let [p (take n s)] 328.2368 - (when (= n (count p)) 328.2369 - (cons p (partition n step (drop step s)))))))) 328.2370 - ([n step pad coll] 328.2371 - (lazy-seq 328.2372 - (when-let [s (seq coll)] 328.2373 - (let [p (take n s)] 328.2374 - (if (= n (count p)) 328.2375 - (cons p (partition n step pad (drop step s))) 328.2376 - (list (take n (concat p pad))))))))) 328.2377 - 328.2378 -;; evaluation 328.2379 - 328.2380 -(defn eval 328.2381 - "Evaluates the form data structure (not text!) and returns the result." 328.2382 - {:added "1.0"} 328.2383 - [form] (. clojure.lang.Compiler (eval form))) 328.2384 - 328.2385 -(defmacro doseq 328.2386 - "Repeatedly executes body (presumably for side-effects) with 328.2387 - bindings and filtering as provided by \"for\". Does not retain 328.2388 - the head of the sequence. Returns nil." 328.2389 - {:added "1.0"} 328.2390 - [seq-exprs & body] 328.2391 - (assert-args doseq 328.2392 - (vector? seq-exprs) "a vector for its binding" 328.2393 - (even? (count seq-exprs)) "an even number of forms in binding vector") 328.2394 - (let [step (fn step [recform exprs] 328.2395 - (if-not exprs 328.2396 - [true `(do ~@body)] 328.2397 - (let [k (first exprs) 328.2398 - v (second exprs)] 328.2399 - (if (keyword? k) 328.2400 - (let [steppair (step recform (nnext exprs)) 328.2401 - needrec (steppair 0) 328.2402 - subform (steppair 1)] 328.2403 - (cond 328.2404 - (= k :let) [needrec `(let ~v ~subform)] 328.2405 - (= k :while) [false `(when ~v 328.2406 - ~subform 328.2407 - ~@(when needrec [recform]))] 328.2408 - (= k :when) [false `(if ~v 328.2409 - (do 328.2410 - ~subform 328.2411 - ~@(when needrec [recform])) 328.2412 - ~recform)])) 328.2413 - (let [seq- (gensym "seq_") 328.2414 - chunk- (with-meta (gensym "chunk_") 328.2415 - {:tag 'clojure.lang.IChunk}) 328.2416 - count- (gensym "count_") 328.2417 - i- (gensym "i_") 328.2418 - recform `(recur (next ~seq-) nil (int 0) (int 0)) 328.2419 - steppair (step recform (nnext exprs)) 328.2420 - needrec (steppair 0) 328.2421 - subform (steppair 1) 328.2422 - recform-chunk 328.2423 - `(recur ~seq- ~chunk- ~count- (unchecked-inc ~i-)) 328.2424 - steppair-chunk (step recform-chunk (nnext exprs)) 328.2425 - subform-chunk (steppair-chunk 1)] 328.2426 - [true 328.2427 - `(loop [~seq- (seq ~v), ~chunk- nil, 328.2428 - ~count- (int 0), ~i- (int 0)] 328.2429 - (if (< ~i- ~count-) 328.2430 - (let [~k (.nth ~chunk- ~i-)] 328.2431 - ~subform-chunk 328.2432 - ~@(when needrec [recform-chunk])) 328.2433 - (when-let [~seq- (seq ~seq-)] 328.2434 - (if (chunked-seq? ~seq-) 328.2435 - (let [c# (chunk-first ~seq-)] 328.2436 - (recur (chunk-rest ~seq-) c# 328.2437 - (int (count c#)) (int 0))) 328.2438 - (let [~k (first ~seq-)] 328.2439 - ~subform 328.2440 - ~@(when needrec [recform]))))))])))))] 328.2441 - (nth (step nil (seq seq-exprs)) 1))) 328.2442 - 328.2443 -(defn dorun 328.2444 - "When lazy sequences are produced via functions that have side 328.2445 - effects, any effects other than those needed to produce the first 328.2446 - element in the seq do not occur until the seq is consumed. dorun can 328.2447 - be used to force any effects. Walks through the successive nexts of 328.2448 - the seq, does not retain the head and returns nil." 328.2449 - {:added "1.0"} 328.2450 - ([coll] 328.2451 - (when (seq coll) 328.2452 - (recur (next coll)))) 328.2453 - ([n coll] 328.2454 - (when (and (seq coll) (pos? n)) 328.2455 - (recur (dec n) (next coll))))) 328.2456 - 328.2457 -(defn doall 328.2458 - "When lazy sequences are produced via functions that have side 328.2459 - effects, any effects other than those needed to produce the first 328.2460 - element in the seq do not occur until the seq is consumed. doall can 328.2461 - be used to force any effects. Walks through the successive nexts of 328.2462 - the seq, retains the head and returns it, thus causing the entire 328.2463 - seq to reside in memory at one time." 328.2464 - {:added "1.0"} 328.2465 - ([coll] 328.2466 - (dorun coll) 328.2467 - coll) 328.2468 - ([n coll] 328.2469 - (dorun n coll) 328.2470 - coll)) 328.2471 - 328.2472 -(defn await 328.2473 - "Blocks the current thread (indefinitely!) until all actions 328.2474 - dispatched thus far, from this thread or agent, to the agent(s) have 328.2475 - occurred. Will block on failed agents. Will never return if 328.2476 - a failed agent is restarted with :clear-actions true." 328.2477 - {:added "1.0"} 328.2478 - [& agents] 328.2479 - (io! "await in transaction" 328.2480 - (when *agent* 328.2481 - (throw (new Exception "Can't await in agent action"))) 328.2482 - (let [latch (new java.util.concurrent.CountDownLatch (count agents)) 328.2483 - count-down (fn [agent] (. latch (countDown)) agent)] 328.2484 - (doseq [agent agents] 328.2485 - (send agent count-down)) 328.2486 - (. latch (await))))) 328.2487 - 328.2488 -(defn await1 [^clojure.lang.Agent a] 328.2489 - (when (pos? (.getQueueCount a)) 328.2490 - (await a)) 328.2491 - a) 328.2492 - 328.2493 -(defn await-for 328.2494 - "Blocks the current thread until all actions dispatched thus 328.2495 - far (from this thread or agent) to the agents have occurred, or the 328.2496 - timeout (in milliseconds) has elapsed. Returns nil if returning due 328.2497 - to timeout, non-nil otherwise." 328.2498 - {:added "1.0"} 328.2499 - [timeout-ms & agents] 328.2500 - (io! "await-for in transaction" 328.2501 - (when *agent* 328.2502 - (throw (new Exception "Can't await in agent action"))) 328.2503 - (let [latch (new java.util.concurrent.CountDownLatch (count agents)) 328.2504 - count-down (fn [agent] (. latch (countDown)) agent)] 328.2505 - (doseq [agent agents] 328.2506 - (send agent count-down)) 328.2507 - (. latch (await timeout-ms (. java.util.concurrent.TimeUnit MILLISECONDS)))))) 328.2508 - 328.2509 -(defmacro dotimes 328.2510 - "bindings => name n 328.2511 - 328.2512 - Repeatedly executes body (presumably for side-effects) with name 328.2513 - bound to integers from 0 through n-1." 328.2514 - {:added "1.0"} 328.2515 - [bindings & body] 328.2516 - (assert-args dotimes 328.2517 - (vector? bindings) "a vector for its binding" 328.2518 - (= 2 (count bindings)) "exactly 2 forms in binding vector") 328.2519 - (let [i (first bindings) 328.2520 - n (second bindings)] 328.2521 - `(let [n# (int ~n)] 328.2522 - (loop [~i (int 0)] 328.2523 - (when (< ~i n#) 328.2524 - ~@body 328.2525 - (recur (unchecked-inc ~i))))))) 328.2526 - 328.2527 -#_(defn into 328.2528 - "Returns a new coll consisting of to-coll with all of the items of 328.2529 - from-coll conjoined." 328.2530 - {:added "1.0"} 328.2531 - [to from] 328.2532 - (let [ret to items (seq from)] 328.2533 - (if items 328.2534 - (recur (conj ret (first items)) (next items)) 328.2535 - ret))) 328.2536 - 328.2537 -;;;;;;;;;;;;;;;;;;;;; editable collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 328.2538 -(defn transient 328.2539 - "Alpha - subject to change. 328.2540 - Returns a new, transient version of the collection, in constant time." 328.2541 - {:added "1.1"} 328.2542 - [^clojure.lang.IEditableCollection coll] 328.2543 - (.asTransient coll)) 328.2544 - 328.2545 -(defn persistent! 328.2546 - "Alpha - subject to change. 328.2547 - Returns a new, persistent version of the transient collection, in 328.2548 - constant time. The transient collection cannot be used after this 328.2549 - call, any such use will throw an exception." 328.2550 - {:added "1.1"} 328.2551 - [^clojure.lang.ITransientCollection coll] 328.2552 - (.persistent coll)) 328.2553 - 328.2554 -(defn conj! 328.2555 - "Alpha - subject to change. 328.2556 - Adds x to the transient collection, and return coll. The 'addition' 328.2557 - may happen at different 'places' depending on the concrete type." 328.2558 - {:added "1.1"} 328.2559 - [^clojure.lang.ITransientCollection coll x] 328.2560 - (.conj coll x)) 328.2561 - 328.2562 -(defn assoc! 328.2563 - "Alpha - subject to change. 328.2564 - When applied to a transient map, adds mapping of key(s) to 328.2565 - val(s). When applied to a transient vector, sets the val at index. 328.2566 - Note - index must be <= (count vector). Returns coll." 328.2567 - {:added "1.1"} 328.2568 - ([^clojure.lang.ITransientAssociative coll key val] (.assoc coll key val)) 328.2569 - ([^clojure.lang.ITransientAssociative coll key val & kvs] 328.2570 - (let [ret (.assoc coll key val)] 328.2571 - (if kvs 328.2572 - (recur ret (first kvs) (second kvs) (nnext kvs)) 328.2573 - ret)))) 328.2574 - 328.2575 -(defn dissoc! 328.2576 - "Alpha - subject to change. 328.2577 - Returns a transient map that doesn't contain a mapping for key(s)." 328.2578 - {:added "1.1"} 328.2579 - ([^clojure.lang.ITransientMap map key] (.without map key)) 328.2580 - ([^clojure.lang.ITransientMap map key & ks] 328.2581 - (let [ret (.without map key)] 328.2582 - (if ks 328.2583 - (recur ret (first ks) (next ks)) 328.2584 - ret)))) 328.2585 - 328.2586 -(defn pop! 328.2587 - "Alpha - subject to change. 328.2588 - Removes the last item from a transient vector. If 328.2589 - the collection is empty, throws an exception. Returns coll" 328.2590 - {:added "1.1"} 328.2591 - [^clojure.lang.ITransientVector coll] 328.2592 - (.pop coll)) 328.2593 - 328.2594 -(defn disj! 328.2595 - "Alpha - subject to change. 328.2596 - disj[oin]. Returns a transient set of the same (hashed/sorted) type, that 328.2597 - does not contain key(s)." 328.2598 - {:added "1.1"} 328.2599 - ([set] set) 328.2600 - ([^clojure.lang.ITransientSet set key] 328.2601 - (. set (disjoin key))) 328.2602 - ([set key & ks] 328.2603 - (let [ret (disj set key)] 328.2604 - (if ks 328.2605 - (recur ret (first ks) (next ks)) 328.2606 - ret)))) 328.2607 - 328.2608 -;redef into with batch support 328.2609 -(defn into 328.2610 - "Returns a new coll consisting of to-coll with all of the items of 328.2611 - from-coll conjoined." 328.2612 - {:added "1.0"} 328.2613 - [to from] 328.2614 - (if (instance? clojure.lang.IEditableCollection to) 328.2615 - (persistent! (reduce conj! (transient to) from)) 328.2616 - (reduce conj to from))) 328.2617 - 328.2618 -(defmacro import 328.2619 - "import-list => (package-symbol class-name-symbols*) 328.2620 - 328.2621 - For each name in class-name-symbols, adds a mapping from name to the 328.2622 - class named by package.name to the current namespace. Use :import in the ns 328.2623 - macro in preference to calling this directly." 328.2624 - {:added "1.0"} 328.2625 - [& import-symbols-or-lists] 328.2626 - (let [specs (map #(if (and (seq? %) (= 'quote (first %))) (second %) %) 328.2627 - import-symbols-or-lists)] 328.2628 - `(do ~@(map #(list 'clojure.core/import* %) 328.2629 - (reduce (fn [v spec] 328.2630 - (if (symbol? spec) 328.2631 - (conj v (name spec)) 328.2632 - (let [p (first spec) cs (rest spec)] 328.2633 - (into v (map #(str p "." %) cs))))) 328.2634 - [] specs))))) 328.2635 - 328.2636 -(defn into-array 328.2637 - "Returns an array with components set to the values in aseq. The array's 328.2638 - component type is type if provided, or the type of the first value in 328.2639 - aseq if present, or Object. All values in aseq must be compatible with 328.2640 - the component type. Class objects for the primitive types can be obtained 328.2641 - using, e.g., Integer/TYPE." 328.2642 - {:added "1.0"} 328.2643 - ([aseq] 328.2644 - (clojure.lang.RT/seqToTypedArray (seq aseq))) 328.2645 - ([type aseq] 328.2646 - (clojure.lang.RT/seqToTypedArray type (seq aseq)))) 328.2647 - 328.2648 -(defn ^{:private true} 328.2649 - array [& items] 328.2650 - (into-array items)) 328.2651 - 328.2652 -(defn ^Class class 328.2653 - "Returns the Class of x" 328.2654 - {:added "1.0"} 328.2655 - [^Object x] (if (nil? x) x (. x (getClass)))) 328.2656 - 328.2657 -(defn type 328.2658 - "Returns the :type metadata of x, or its Class if none" 328.2659 - {:added "1.0"} 328.2660 - [x] 328.2661 - (or (:type (meta x)) (class x))) 328.2662 - 328.2663 -(defn num 328.2664 - "Coerce to Number" 328.2665 - {:tag Number 328.2666 - :inline (fn [x] `(. clojure.lang.Numbers (num ~x))) 328.2667 - :added "1.0"} 328.2668 - [x] (. clojure.lang.Numbers (num x))) 328.2669 - 328.2670 -(defn long 328.2671 - "Coerce to long" 328.2672 - {:tag Long 328.2673 - :inline (fn [x] `(. clojure.lang.RT (longCast ~x))) 328.2674 - :added "1.0"} 328.2675 - [^Number x] (clojure.lang.RT/longCast x)) 328.2676 - 328.2677 -(defn float 328.2678 - "Coerce to float" 328.2679 - {:tag Float 328.2680 - :inline (fn [x] `(. clojure.lang.RT (floatCast ~x))) 328.2681 - :added "1.0"} 328.2682 - [^Number x] (clojure.lang.RT/floatCast x)) 328.2683 - 328.2684 -(defn double 328.2685 - "Coerce to double" 328.2686 - {:tag Double 328.2687 - :inline (fn [x] `(. clojure.lang.RT (doubleCast ~x))) 328.2688 - :added "1.0"} 328.2689 - [^Number x] (clojure.lang.RT/doubleCast x)) 328.2690 - 328.2691 -(defn short 328.2692 - "Coerce to short" 328.2693 - {:tag Short 328.2694 - :inline (fn [x] `(. clojure.lang.RT (shortCast ~x))) 328.2695 - :added "1.0"} 328.2696 - [^Number x] (clojure.lang.RT/shortCast x)) 328.2697 - 328.2698 -(defn byte 328.2699 - "Coerce to byte" 328.2700 - {:tag Byte 328.2701 - :inline (fn [x] `(. clojure.lang.RT (byteCast ~x))) 328.2702 - :added "1.0"} 328.2703 - [^Number x] (clojure.lang.RT/byteCast x)) 328.2704 - 328.2705 -(defn char 328.2706 - "Coerce to char" 328.2707 - {:tag Character 328.2708 - :inline (fn [x] `(. clojure.lang.RT (charCast ~x))) 328.2709 - :added "1.1"} 328.2710 - [x] (. clojure.lang.RT (charCast x))) 328.2711 - 328.2712 -(defn boolean 328.2713 - "Coerce to boolean" 328.2714 - { 328.2715 - :inline (fn [x] `(. clojure.lang.RT (booleanCast ~x))) 328.2716 - :added "1.0"} 328.2717 - [x] (clojure.lang.RT/booleanCast x)) 328.2718 - 328.2719 -(defn number? 328.2720 - "Returns true if x is a Number" 328.2721 - {:added "1.0"} 328.2722 - [x] 328.2723 - (instance? Number x)) 328.2724 - 328.2725 -(defn integer? 328.2726 - "Returns true if n is an integer" 328.2727 - {:added "1.0"} 328.2728 - [n] 328.2729 - (or (instance? Integer n) 328.2730 - (instance? Long n) 328.2731 - (instance? BigInteger n) 328.2732 - (instance? Short n) 328.2733 - (instance? Byte n))) 328.2734 - 328.2735 -(defn mod 328.2736 - "Modulus of num and div. Truncates toward negative infinity." 328.2737 - {:added "1.0"} 328.2738 - [num div] 328.2739 - (let [m (rem num div)] 328.2740 - (if (or (zero? m) (pos? (* num div))) 328.2741 - m 328.2742 - (+ m div)))) 328.2743 - 328.2744 -(defn ratio? 328.2745 - "Returns true if n is a Ratio" 328.2746 - {:added "1.0"} 328.2747 - [n] (instance? clojure.lang.Ratio n)) 328.2748 - 328.2749 -(defn numerator 328.2750 - "Returns the numerator part of a Ratio." 328.2751 - {:tag BigInteger 328.2752 - :added "1.2"} 328.2753 - [r] 328.2754 - (.numerator ^clojure.lang.Ratio r)) 328.2755 - 328.2756 -(defn denominator 328.2757 - "Returns the denominator part of a Ratio." 328.2758 - {:tag BigInteger 328.2759 - :added "1.2"} 328.2760 - [r] 328.2761 - (.denominator ^clojure.lang.Ratio r)) 328.2762 - 328.2763 -(defn decimal? 328.2764 - "Returns true if n is a BigDecimal" 328.2765 - {:added "1.0"} 328.2766 - [n] (instance? BigDecimal n)) 328.2767 - 328.2768 -(defn float? 328.2769 - "Returns true if n is a floating point number" 328.2770 - {:added "1.0"} 328.2771 - [n] 328.2772 - (or (instance? Double n) 328.2773 - (instance? Float n))) 328.2774 - 328.2775 -(defn rational? [n] 328.2776 - "Returns true if n is a rational number" 328.2777 - {:added "1.0"} 328.2778 - (or (integer? n) (ratio? n) (decimal? n))) 328.2779 - 328.2780 -(defn bigint 328.2781 - "Coerce to BigInteger" 328.2782 - {:tag BigInteger 328.2783 - :added "1.0"} 328.2784 - [x] (cond 328.2785 - (instance? BigInteger x) x 328.2786 - (decimal? x) (.toBigInteger ^BigDecimal x) 328.2787 - (ratio? x) (.bigIntegerValue ^clojure.lang.Ratio x) 328.2788 - (number? x) (BigInteger/valueOf (long x)) 328.2789 - :else (BigInteger. x))) 328.2790 - 328.2791 -(defn bigdec 328.2792 - "Coerce to BigDecimal" 328.2793 - {:tag BigDecimal 328.2794 - :added "1.0"} 328.2795 - [x] (cond 328.2796 - (decimal? x) x 328.2797 - (float? x) (. BigDecimal valueOf (double x)) 328.2798 - (ratio? x) (/ (BigDecimal. (.numerator x)) (.denominator x)) 328.2799 - (instance? BigInteger x) (BigDecimal. ^BigInteger x) 328.2800 - (number? x) (BigDecimal/valueOf (long x)) 328.2801 - :else (BigDecimal. x))) 328.2802 - 328.2803 -(def ^{:private true} print-initialized false) 328.2804 - 328.2805 -(defmulti print-method (fn [x writer] (type x))) 328.2806 -(defmulti print-dup (fn [x writer] (class x))) 328.2807 - 328.2808 -(defn pr-on 328.2809 - {:private true} 328.2810 - [x w] 328.2811 - (if *print-dup* 328.2812 - (print-dup x w) 328.2813 - (print-method x w)) 328.2814 - nil) 328.2815 - 328.2816 -(defn pr 328.2817 - "Prints the object(s) to the output stream that is the current value 328.2818 - of *out*. Prints the object(s), separated by spaces if there is 328.2819 - more than one. By default, pr and prn print in a way that objects 328.2820 - can be read by the reader" 328.2821 - {:dynamic true 328.2822 - :added "1.0"} 328.2823 - ([] nil) 328.2824 - ([x] 328.2825 - (pr-on x *out*)) 328.2826 - ([x & more] 328.2827 - (pr x) 328.2828 - (. *out* (append \space)) 328.2829 - (if-let [nmore (next more)] 328.2830 - (recur (first more) nmore) 328.2831 - (apply pr more)))) 328.2832 - 328.2833 -(defn newline 328.2834 - "Writes a newline to the output stream that is the current value of 328.2835 - *out*" 328.2836 - {:added "1.0"} 328.2837 - [] 328.2838 - (. *out* (append \newline)) 328.2839 - nil) 328.2840 - 328.2841 -(defn flush 328.2842 - "Flushes the output stream that is the current value of 328.2843 - *out*" 328.2844 - {:added "1.0"} 328.2845 - [] 328.2846 - (. *out* (flush)) 328.2847 - nil) 328.2848 - 328.2849 -(defn prn 328.2850 - "Same as pr followed by (newline). Observes *flush-on-newline*" 328.2851 - {:added "1.0"} 328.2852 - [& more] 328.2853 - (apply pr more) 328.2854 - (newline) 328.2855 - (when *flush-on-newline* 328.2856 - (flush))) 328.2857 - 328.2858 -(defn print 328.2859 - "Prints the object(s) to the output stream that is the current value 328.2860 - of *out*. print and println produce output for human consumption." 328.2861 - {:added "1.0"} 328.2862 - [& more] 328.2863 - (binding [*print-readably* nil] 328.2864 - (apply pr more))) 328.2865 - 328.2866 -(defn println 328.2867 - "Same as print followed by (newline)" 328.2868 - {:added "1.0"} 328.2869 - [& more] 328.2870 - (binding [*print-readably* nil] 328.2871 - (apply prn more))) 328.2872 - 328.2873 -(defn read 328.2874 - "Reads the next object from stream, which must be an instance of 328.2875 - java.io.PushbackReader or some derivee. stream defaults to the 328.2876 - current value of *in* ." 328.2877 - {:added "1.0"} 328.2878 - ([] 328.2879 - (read *in*)) 328.2880 - ([stream] 328.2881 - (read stream true nil)) 328.2882 - ([stream eof-error? eof-value] 328.2883 - (read stream eof-error? eof-value false)) 328.2884 - ([stream eof-error? eof-value recursive?] 328.2885 - (. clojure.lang.LispReader (read stream (boolean eof-error?) eof-value recursive?)))) 328.2886 - 328.2887 -(defn read-line 328.2888 - "Reads the next line from stream that is the current value of *in* ." 328.2889 - {:added "1.0"} 328.2890 - [] 328.2891 - (if (instance? clojure.lang.LineNumberingPushbackReader *in*) 328.2892 - (.readLine ^clojure.lang.LineNumberingPushbackReader *in*) 328.2893 - (.readLine ^java.io.BufferedReader *in*))) 328.2894 - 328.2895 -(defn read-string 328.2896 - "Reads one object from the string s" 328.2897 - {:added "1.0"} 328.2898 - [s] (clojure.lang.RT/readString s)) 328.2899 - 328.2900 -(defn subvec 328.2901 - "Returns a persistent vector of the items in vector from 328.2902 - start (inclusive) to end (exclusive). If end is not supplied, 328.2903 - defaults to (count vector). This operation is O(1) and very fast, as 328.2904 - the resulting vector shares structure with the original and no 328.2905 - trimming is done." 328.2906 - {:added "1.0"} 328.2907 - ([v start] 328.2908 - (subvec v start (count v))) 328.2909 - ([v start end] 328.2910 - (. clojure.lang.RT (subvec v start end)))) 328.2911 - 328.2912 -(defmacro with-open 328.2913 - "bindings => [name init ...] 328.2914 - 328.2915 - Evaluates body in a try expression with names bound to the values 328.2916 - of the inits, and a finally clause that calls (.close name) on each 328.2917 - name in reverse order." 328.2918 - {:added "1.0"} 328.2919 - [bindings & body] 328.2920 - (assert-args with-open 328.2921 - (vector? bindings) "a vector for its binding" 328.2922 - (even? (count bindings)) "an even number of forms in binding vector") 328.2923 - (cond 328.2924 - (= (count bindings) 0) `(do ~@body) 328.2925 - (symbol? (bindings 0)) `(let ~(subvec bindings 0 2) 328.2926 - (try 328.2927 - (with-open ~(subvec bindings 2) ~@body) 328.2928 - (finally 328.2929 - (. ~(bindings 0) close)))) 328.2930 - :else (throw (IllegalArgumentException. 328.2931 - "with-open only allows Symbols in bindings")))) 328.2932 - 328.2933 -(defmacro doto 328.2934 - "Evaluates x then calls all of the methods and functions with the 328.2935 - value of x supplied at the front of the given arguments. The forms 328.2936 - are evaluated in order. Returns x. 328.2937 - 328.2938 - (doto (new java.util.HashMap) (.put \"a\" 1) (.put \"b\" 2))" 328.2939 - {:added "1.0"} 328.2940 - [x & forms] 328.2941 - (let [gx (gensym)] 328.2942 - `(let [~gx ~x] 328.2943 - ~@(map (fn [f] 328.2944 - (if (seq? f) 328.2945 - `(~(first f) ~gx ~@(next f)) 328.2946 - `(~f ~gx))) 328.2947 - forms) 328.2948 - ~gx))) 328.2949 - 328.2950 -(defmacro memfn 328.2951 - "Expands into code that creates a fn that expects to be passed an 328.2952 - object and any args and calls the named instance method on the 328.2953 - object passing the args. Use when you want to treat a Java method as 328.2954 - a first-class fn." 328.2955 - {:added "1.0"} 328.2956 - [name & args] 328.2957 - `(fn [target# ~@args] 328.2958 - (. target# (~name ~@args)))) 328.2959 - 328.2960 -(defmacro time 328.2961 - "Evaluates expr and prints the time it took. Returns the value of 328.2962 - expr." 328.2963 - {:added "1.0"} 328.2964 - [expr] 328.2965 - `(let [start# (. System (nanoTime)) 328.2966 - ret# ~expr] 328.2967 - (prn (str "Elapsed time: " (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs")) 328.2968 - ret#)) 328.2969 - 328.2970 - 328.2971 - 328.2972 -(import '(java.lang.reflect Array)) 328.2973 - 328.2974 -(defn alength 328.2975 - "Returns the length of the Java array. Works on arrays of all 328.2976 - types." 328.2977 - {:inline (fn [a] `(. clojure.lang.RT (alength ~a))) 328.2978 - :added "1.0"} 328.2979 - [array] (. clojure.lang.RT (alength array))) 328.2980 - 328.2981 -(defn aclone 328.2982 - "Returns a clone of the Java array. Works on arrays of known 328.2983 - types." 328.2984 - {:inline (fn [a] `(. clojure.lang.RT (aclone ~a))) 328.2985 - :added "1.0"} 328.2986 - [array] (. clojure.lang.RT (aclone array))) 328.2987 - 328.2988 -(defn aget 328.2989 - "Returns the value at the index/indices. Works on Java arrays of all 328.2990 - types." 328.2991 - {:inline (fn [a i] `(. clojure.lang.RT (aget ~a (int ~i)))) 328.2992 - :inline-arities #{2} 328.2993 - :added "1.0"} 328.2994 - ([array idx] 328.2995 - (clojure.lang.Reflector/prepRet (. Array (get array idx)))) 328.2996 - ([array idx & idxs] 328.2997 - (apply aget (aget array idx) idxs))) 328.2998 - 328.2999 -(defn aset 328.3000 - "Sets the value at the index/indices. Works on Java arrays of 328.3001 - reference types. Returns val." 328.3002 - {:inline (fn [a i v] `(. clojure.lang.RT (aset ~a (int ~i) ~v))) 328.3003 - :inline-arities #{3} 328.3004 - :added "1.0"} 328.3005 - ([array idx val] 328.3006 - (. Array (set array idx val)) 328.3007 - val) 328.3008 - ([array idx idx2 & idxv] 328.3009 - (apply aset (aget array idx) idx2 idxv))) 328.3010 - 328.3011 -(defmacro 328.3012 - ^{:private true} 328.3013 - def-aset [name method coerce] 328.3014 - `(defn ~name 328.3015 - {:arglists '([~'array ~'idx ~'val] [~'array ~'idx ~'idx2 & ~'idxv])} 328.3016 - ([array# idx# val#] 328.3017 - (. Array (~method array# idx# (~coerce val#))) 328.3018 - val#) 328.3019 - ([array# idx# idx2# & idxv#] 328.3020 - (apply ~name (aget array# idx#) idx2# idxv#)))) 328.3021 - 328.3022 -(def-aset 328.3023 - ^{:doc "Sets the value at the index/indices. Works on arrays of int. Returns val." 328.3024 - :added "1.0"} 328.3025 - aset-int setInt int) 328.3026 - 328.3027 -(def-aset 328.3028 - ^{:doc "Sets the value at the index/indices. Works on arrays of long. Returns val." 328.3029 - :added "1.0"} 328.3030 - aset-long setLong long) 328.3031 - 328.3032 -(def-aset 328.3033 - ^{:doc "Sets the value at the index/indices. Works on arrays of boolean. Returns val." 328.3034 - :added "1.0"} 328.3035 - aset-boolean setBoolean boolean) 328.3036 - 328.3037 -(def-aset 328.3038 - ^{:doc "Sets the value at the index/indices. Works on arrays of float. Returns val." 328.3039 - :added "1.0"} 328.3040 - aset-float setFloat float) 328.3041 - 328.3042 -(def-aset 328.3043 - ^{:doc "Sets the value at the index/indices. Works on arrays of double. Returns val." 328.3044 - :added "1.0"} 328.3045 - aset-double setDouble double) 328.3046 - 328.3047 -(def-aset 328.3048 - ^{:doc "Sets the value at the index/indices. Works on arrays of short. Returns val." 328.3049 - :added "1.0"} 328.3050 - aset-short setShort short) 328.3051 - 328.3052 -(def-aset 328.3053 - ^{:doc "Sets the value at the index/indices. Works on arrays of byte. Returns val." 328.3054 - :added "1.0"} 328.3055 - aset-byte setByte byte) 328.3056 - 328.3057 -(def-aset 328.3058 - ^{:doc "Sets the value at the index/indices. Works on arrays of char. Returns val." 328.3059 - :added "1.0"} 328.3060 - aset-char setChar char) 328.3061 - 328.3062 -(defn make-array 328.3063 - "Creates and returns an array of instances of the specified class of 328.3064 - the specified dimension(s). Note that a class object is required. 328.3065 - Class objects can be obtained by using their imported or 328.3066 - fully-qualified name. Class objects for the primitive types can be 328.3067 - obtained using, e.g., Integer/TYPE." 328.3068 - {:added "1.0"} 328.3069 - ([^Class type len] 328.3070 - (. Array (newInstance type (int len)))) 328.3071 - ([^Class type dim & more-dims] 328.3072 - (let [dims (cons dim more-dims) 328.3073 - ^"[I" dimarray (make-array (. Integer TYPE) (count dims))] 328.3074 - (dotimes [i (alength dimarray)] 328.3075 - (aset-int dimarray i (nth dims i))) 328.3076 - (. Array (newInstance type dimarray))))) 328.3077 - 328.3078 -(defn to-array-2d 328.3079 - "Returns a (potentially-ragged) 2-dimensional array of Objects 328.3080 - containing the contents of coll, which can be any Collection of any 328.3081 - Collection." 328.3082 - {:tag "[[Ljava.lang.Object;" 328.3083 - :added "1.0"} 328.3084 - [^java.util.Collection coll] 328.3085 - (let [ret (make-array (. Class (forName "[Ljava.lang.Object;")) (. coll (size)))] 328.3086 - (loop [i 0 xs (seq coll)] 328.3087 - (when xs 328.3088 - (aset ret i (to-array (first xs))) 328.3089 - (recur (inc i) (next xs)))) 328.3090 - ret)) 328.3091 - 328.3092 -(defn macroexpand-1 328.3093 - "If form represents a macro form, returns its expansion, 328.3094 - else returns form." 328.3095 - {:added "1.0"} 328.3096 - [form] 328.3097 - (. clojure.lang.Compiler (macroexpand1 form))) 328.3098 - 328.3099 -(defn macroexpand 328.3100 - "Repeatedly calls macroexpand-1 on form until it no longer 328.3101 - represents a macro form, then returns it. Note neither 328.3102 - macroexpand-1 nor macroexpand expand macros in subforms." 328.3103 - {:added "1.0"} 328.3104 - [form] 328.3105 - (let [ex (macroexpand-1 form)] 328.3106 - (if (identical? ex form) 328.3107 - form 328.3108 - (macroexpand ex)))) 328.3109 - 328.3110 -(defn create-struct 328.3111 - "Returns a structure basis object." 328.3112 - {:added "1.0"} 328.3113 - [& keys] 328.3114 - (. clojure.lang.PersistentStructMap (createSlotMap keys))) 328.3115 - 328.3116 -(defmacro defstruct 328.3117 - "Same as (def name (create-struct keys...))" 328.3118 - {:added "1.0"} 328.3119 - [name & keys] 328.3120 - `(def ~name (create-struct ~@keys))) 328.3121 - 328.3122 -(defn struct-map 328.3123 - "Returns a new structmap instance with the keys of the 328.3124 - structure-basis. keyvals may contain all, some or none of the basis 328.3125 - keys - where values are not supplied they will default to nil. 328.3126 - keyvals can also contain keys not in the basis." 328.3127 - {:added "1.0"} 328.3128 - [s & inits] 328.3129 - (. clojure.lang.PersistentStructMap (create s inits))) 328.3130 - 328.3131 -(defn struct 328.3132 - "Returns a new structmap instance with the keys of the 328.3133 - structure-basis. vals must be supplied for basis keys in order - 328.3134 - where values are not supplied they will default to nil." 328.3135 - {:added "1.0"} 328.3136 - [s & vals] 328.3137 - (. clojure.lang.PersistentStructMap (construct s vals))) 328.3138 - 328.3139 -(defn accessor 328.3140 - "Returns a fn that, given an instance of a structmap with the basis, 328.3141 - returns the value at the key. The key must be in the basis. The 328.3142 - returned function should be (slightly) more efficient than using 328.3143 - get, but such use of accessors should be limited to known 328.3144 - performance-critical areas." 328.3145 - {:added "1.0"} 328.3146 - [s key] 328.3147 - (. clojure.lang.PersistentStructMap (getAccessor s key))) 328.3148 - 328.3149 -(defn load-reader 328.3150 - "Sequentially read and evaluate the set of forms contained in the 328.3151 - stream/file" 328.3152 - {:added "1.0"} 328.3153 - [rdr] (. clojure.lang.Compiler (load rdr))) 328.3154 - 328.3155 -(defn load-string 328.3156 - "Sequentially read and evaluate the set of forms contained in the 328.3157 - string" 328.3158 - {:added "1.0"} 328.3159 - [s] 328.3160 - (let [rdr (-> (java.io.StringReader. s) 328.3161 - (clojure.lang.LineNumberingPushbackReader.))] 328.3162 - (load-reader rdr))) 328.3163 - 328.3164 -(defn set 328.3165 - "Returns a set of the distinct elements of coll." 328.3166 - {:added "1.0"} 328.3167 - [coll] (clojure.lang.PersistentHashSet/create ^clojure.lang.ISeq (seq coll))) 328.3168 - 328.3169 -(defn ^{:private true} 328.3170 - filter-key [keyfn pred amap] 328.3171 - (loop [ret {} es (seq amap)] 328.3172 - (if es 328.3173 - (if (pred (keyfn (first es))) 328.3174 - (recur (assoc ret (key (first es)) (val (first es))) (next es)) 328.3175 - (recur ret (next es))) 328.3176 - ret))) 328.3177 - 328.3178 -(defn find-ns 328.3179 - "Returns the namespace named by the symbol or nil if it doesn't exist." 328.3180 - {:added "1.0"} 328.3181 - [sym] (clojure.lang.Namespace/find sym)) 328.3182 - 328.3183 -(defn create-ns 328.3184 - "Create a new namespace named by the symbol if one doesn't already 328.3185 - exist, returns it or the already-existing namespace of the same 328.3186 - name." 328.3187 - {:added "1.0"} 328.3188 - [sym] (clojure.lang.Namespace/findOrCreate sym)) 328.3189 - 328.3190 -(defn remove-ns 328.3191 - "Removes the namespace named by the symbol. Use with caution. 328.3192 - Cannot be used to remove the clojure namespace." 328.3193 - {:added "1.0"} 328.3194 - [sym] (clojure.lang.Namespace/remove sym)) 328.3195 - 328.3196 -(defn all-ns 328.3197 - "Returns a sequence of all namespaces." 328.3198 - {:added "1.0"} 328.3199 - [] (clojure.lang.Namespace/all)) 328.3200 - 328.3201 -(defn ^clojure.lang.Namespace the-ns 328.3202 - "If passed a namespace, returns it. Else, when passed a symbol, 328.3203 - returns the namespace named by it, throwing an exception if not 328.3204 - found." 328.3205 - {:added "1.0"} 328.3206 - [x] 328.3207 - (if (instance? clojure.lang.Namespace x) 328.3208 - x 328.3209 - (or (find-ns x) (throw (Exception. (str "No namespace: " x " found")))))) 328.3210 - 328.3211 -(defn ns-name 328.3212 - "Returns the name of the namespace, a symbol." 328.3213 - {:added "1.0"} 328.3214 - [ns] 328.3215 - (.getName (the-ns ns))) 328.3216 - 328.3217 -(defn ns-map 328.3218 - "Returns a map of all the mappings for the namespace." 328.3219 - {:added "1.0"} 328.3220 - [ns] 328.3221 - (.getMappings (the-ns ns))) 328.3222 - 328.3223 -(defn ns-unmap 328.3224 - "Removes the mappings for the symbol from the namespace." 328.3225 - {:added "1.0"} 328.3226 - [ns sym] 328.3227 - (.unmap (the-ns ns) sym)) 328.3228 - 328.3229 -;(defn export [syms] 328.3230 -; (doseq [sym syms] 328.3231 -; (.. *ns* (intern sym) (setExported true)))) 328.3232 - 328.3233 -(defn ns-publics 328.3234 - "Returns a map of the public intern mappings for the namespace." 328.3235 - {:added "1.0"} 328.3236 - [ns] 328.3237 - (let [ns (the-ns ns)] 328.3238 - (filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v) 328.3239 - (= ns (.ns v)) 328.3240 - (.isPublic v))) 328.3241 - (ns-map ns)))) 328.3242 - 328.3243 -(defn ns-imports 328.3244 - "Returns a map of the import mappings for the namespace." 328.3245 - {:added "1.0"} 328.3246 - [ns] 328.3247 - (filter-key val (partial instance? Class) (ns-map ns))) 328.3248 - 328.3249 -(defn ns-interns 328.3250 - "Returns a map of the intern mappings for the namespace." 328.3251 - {:added "1.0"} 328.3252 - [ns] 328.3253 - (let [ns (the-ns ns)] 328.3254 - (filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v) 328.3255 - (= ns (.ns v)))) 328.3256 - (ns-map ns)))) 328.3257 - 328.3258 -(defn refer 328.3259 - "refers to all public vars of ns, subject to filters. 328.3260 - filters can include at most one each of: 328.3261 - 328.3262 - :exclude list-of-symbols 328.3263 - :only list-of-symbols 328.3264 - :rename map-of-fromsymbol-tosymbol 328.3265 - 328.3266 - For each public interned var in the namespace named by the symbol, 328.3267 - adds a mapping from the name of the var to the var to the current 328.3268 - namespace. Throws an exception if name is already mapped to 328.3269 - something else in the current namespace. Filters can be used to 328.3270 - select a subset, via inclusion or exclusion, or to provide a mapping 328.3271 - to a symbol different from the var's name, in order to prevent 328.3272 - clashes. Use :use in the ns macro in preference to calling this directly." 328.3273 - {:added "1.0"} 328.3274 - [ns-sym & filters] 328.3275 - (let [ns (or (find-ns ns-sym) (throw (new Exception (str "No namespace: " ns-sym)))) 328.3276 - fs (apply hash-map filters) 328.3277 - nspublics (ns-publics ns) 328.3278 - rename (or (:rename fs) {}) 328.3279 - exclude (set (:exclude fs)) 328.3280 - to-do (or (:only fs) (keys nspublics))] 328.3281 - (doseq [sym to-do] 328.3282 - (when-not (exclude sym) 328.3283 - (let [v (nspublics sym)] 328.3284 - (when-not v 328.3285 - (throw (new java.lang.IllegalAccessError 328.3286 - (if (get (ns-interns ns) sym) 328.3287 - (str sym " is not public") 328.3288 - (str sym " does not exist"))))) 328.3289 - (. *ns* (refer (or (rename sym) sym) v))))))) 328.3290 - 328.3291 -(defn ns-refers 328.3292 - "Returns a map of the refer mappings for the namespace." 328.3293 - {:added "1.0"} 328.3294 - [ns] 328.3295 - (let [ns (the-ns ns)] 328.3296 - (filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v) 328.3297 - (not= ns (.ns v)))) 328.3298 - (ns-map ns)))) 328.3299 - 328.3300 -(defn alias 328.3301 - "Add an alias in the current namespace to another 328.3302 - namespace. Arguments are two symbols: the alias to be used, and 328.3303 - the symbolic name of the target namespace. Use :as in the ns macro in preference 328.3304 - to calling this directly." 328.3305 - {:added "1.0"} 328.3306 - [alias namespace-sym] 328.3307 - (.addAlias *ns* alias (find-ns namespace-sym))) 328.3308 - 328.3309 -(defn ns-aliases 328.3310 - "Returns a map of the aliases for the namespace." 328.3311 - {:added "1.0"} 328.3312 - [ns] 328.3313 - (.getAliases (the-ns ns))) 328.3314 - 328.3315 -(defn ns-unalias 328.3316 - "Removes the alias for the symbol from the namespace." 328.3317 - {:added "1.0"} 328.3318 - [ns sym] 328.3319 - (.removeAlias (the-ns ns) sym)) 328.3320 - 328.3321 -(defn take-nth 328.3322 - "Returns a lazy seq of every nth item in coll." 328.3323 - {:added "1.0"} 328.3324 - [n coll] 328.3325 - (lazy-seq 328.3326 - (when-let [s (seq coll)] 328.3327 - (cons (first s) (take-nth n (drop n s)))))) 328.3328 - 328.3329 -(defn interleave 328.3330 - "Returns a lazy seq of the first item in each coll, then the second etc." 328.3331 - {:added "1.0"} 328.3332 - ([c1 c2] 328.3333 - (lazy-seq 328.3334 - (let [s1 (seq c1) s2 (seq c2)] 328.3335 - (when (and s1 s2) 328.3336 - (cons (first s1) (cons (first s2) 328.3337 - (interleave (rest s1) (rest s2)))))))) 328.3338 - ([c1 c2 & colls] 328.3339 - (lazy-seq 328.3340 - (let [ss (map seq (conj colls c2 c1))] 328.3341 - (when (every? identity ss) 328.3342 - (concat (map first ss) (apply interleave (map rest ss)))))))) 328.3343 - 328.3344 -(defn var-get 328.3345 - "Gets the value in the var object" 328.3346 - {:added "1.0"} 328.3347 - [^clojure.lang.Var x] (. x (get))) 328.3348 - 328.3349 -(defn var-set 328.3350 - "Sets the value in the var object to val. The var must be 328.3351 - thread-locally bound." 328.3352 - {:added "1.0"} 328.3353 - [^clojure.lang.Var x val] (. x (set val))) 328.3354 - 328.3355 -(defmacro with-local-vars 328.3356 - "varbinding=> symbol init-expr 328.3357 - 328.3358 - Executes the exprs in a context in which the symbols are bound to 328.3359 - vars with per-thread bindings to the init-exprs. The symbols refer 328.3360 - to the var objects themselves, and must be accessed with var-get and 328.3361 - var-set" 328.3362 - {:added "1.0"} 328.3363 - [name-vals-vec & body] 328.3364 - (assert-args with-local-vars 328.3365 - (vector? name-vals-vec) "a vector for its binding" 328.3366 - (even? (count name-vals-vec)) "an even number of forms in binding vector") 328.3367 - `(let [~@(interleave (take-nth 2 name-vals-vec) 328.3368 - (repeat '(. clojure.lang.Var (create))))] 328.3369 - (. clojure.lang.Var (pushThreadBindings (hash-map ~@name-vals-vec))) 328.3370 - (try 328.3371 - ~@body 328.3372 - (finally (. clojure.lang.Var (popThreadBindings)))))) 328.3373 - 328.3374 -(defn ns-resolve 328.3375 - "Returns the var or Class to which a symbol will be resolved in the 328.3376 - namespace, else nil. Note that if the symbol is fully qualified, 328.3377 - the var/Class to which it resolves need not be present in the 328.3378 - namespace." 328.3379 - {:added "1.0"} 328.3380 - [ns sym] 328.3381 - (clojure.lang.Compiler/maybeResolveIn (the-ns ns) sym)) 328.3382 - 328.3383 -(defn resolve 328.3384 - "same as (ns-resolve *ns* symbol)" 328.3385 - {:added "1.0"} 328.3386 - [sym] (ns-resolve *ns* sym)) 328.3387 - 328.3388 -(defn array-map 328.3389 - "Constructs an array-map." 328.3390 - {:added "1.0"} 328.3391 - ([] (. clojure.lang.PersistentArrayMap EMPTY)) 328.3392 - ([& keyvals] (clojure.lang.PersistentArrayMap/createWithCheck (to-array keyvals)))) 328.3393 - 328.3394 -(defn nthnext 328.3395 - "Returns the nth next of coll, (seq coll) when n is 0." 328.3396 - {:added "1.0"} 328.3397 - [coll n] 328.3398 - (loop [n n xs (seq coll)] 328.3399 - (if (and xs (pos? n)) 328.3400 - (recur (dec n) (next xs)) 328.3401 - xs))) 328.3402 - 328.3403 - 328.3404 -;redefine let and loop with destructuring 328.3405 -(defn destructure [bindings] 328.3406 - (let [bents (partition 2 bindings) 328.3407 - pb (fn pb [bvec b v] 328.3408 - (let [pvec 328.3409 - (fn [bvec b val] 328.3410 - (let [gvec (gensym "vec__")] 328.3411 - (loop [ret (-> bvec (conj gvec) (conj val)) 328.3412 - n 0 328.3413 - bs b 328.3414 - seen-rest? false] 328.3415 - (if (seq bs) 328.3416 - (let [firstb (first bs)] 328.3417 - (cond 328.3418 - (= firstb '&) (recur (pb ret (second bs) (list `nthnext gvec n)) 328.3419 - n 328.3420 - (nnext bs) 328.3421 - true) 328.3422 - (= firstb :as) (pb ret (second bs) gvec) 328.3423 - :else (if seen-rest? 328.3424 - (throw (new Exception "Unsupported binding form, only :as can follow & parameter")) 328.3425 - (recur (pb ret firstb (list `nth gvec n nil)) 328.3426 - (inc n) 328.3427 - (next bs) 328.3428 - seen-rest?)))) 328.3429 - ret)))) 328.3430 - pmap 328.3431 - (fn [bvec b v] 328.3432 - (let [gmap (or (:as b) (gensym "map__")) 328.3433 - defaults (:or b)] 328.3434 - (loop [ret (-> bvec (conj gmap) (conj v) 328.3435 - (conj gmap) (conj `(if (seq? ~gmap) (apply hash-map ~gmap) ~gmap))) 328.3436 - bes (reduce 328.3437 - (fn [bes entry] 328.3438 - (reduce #(assoc %1 %2 ((val entry) %2)) 328.3439 - (dissoc bes (key entry)) 328.3440 - ((key entry) bes))) 328.3441 - (dissoc b :as :or) 328.3442 - {:keys #(keyword (str %)), :strs str, :syms #(list `quote %)})] 328.3443 - (if (seq bes) 328.3444 - (let [bb (key (first bes)) 328.3445 - bk (val (first bes)) 328.3446 - has-default (contains? defaults bb)] 328.3447 - (recur (pb ret bb (if has-default 328.3448 - (list `get gmap bk (defaults bb)) 328.3449 - (list `get gmap bk))) 328.3450 - (next bes))) 328.3451 - ret))))] 328.3452 - (cond 328.3453 - (symbol? b) (-> bvec (conj b) (conj v)) 328.3454 - (vector? b) (pvec bvec b v) 328.3455 - (map? b) (pmap bvec b v) 328.3456 - :else (throw (new Exception (str "Unsupported binding form: " b)))))) 328.3457 - process-entry (fn [bvec b] (pb bvec (first b) (second b)))] 328.3458 - (if (every? symbol? (map first bents)) 328.3459 - bindings 328.3460 - (reduce process-entry [] bents)))) 328.3461 - 328.3462 -(defmacro let 328.3463 - "Evaluates the exprs in a lexical context in which the symbols in 328.3464 - the binding-forms are bound to their respective init-exprs or parts 328.3465 - therein." 328.3466 - {:added "1.0"} 328.3467 - [bindings & body] 328.3468 - (assert-args let 328.3469 - (vector? bindings) "a vector for its binding" 328.3470 - (even? (count bindings)) "an even number of forms in binding vector") 328.3471 - `(let* ~(destructure bindings) ~@body)) 328.3472 - 328.3473 -(defn ^{:private true} 328.3474 - maybe-destructured 328.3475 - [params body] 328.3476 - (if (every? symbol? params) 328.3477 - (cons params body) 328.3478 - (loop [params params 328.3479 - new-params [] 328.3480 - lets []] 328.3481 - (if params 328.3482 - (if (symbol? (first params)) 328.3483 - (recur (next params) (conj new-params (first params)) lets) 328.3484 - (let [gparam (gensym "p__")] 328.3485 - (recur (next params) (conj new-params gparam) 328.3486 - (-> lets (conj (first params)) (conj gparam))))) 328.3487 - `(~new-params 328.3488 - (let ~lets 328.3489 - ~@body)))))) 328.3490 - 328.3491 -;redefine fn with destructuring and pre/post conditions 328.3492 -(defmacro fn 328.3493 - "(fn name? [params* ] exprs*) 328.3494 - (fn name? ([params* ] exprs*)+) 328.3495 - 328.3496 - params => positional-params* , or positional-params* & next-param 328.3497 - positional-param => binding-form 328.3498 - next-param => binding-form 328.3499 - name => symbol 328.3500 - 328.3501 - Defines a function" 328.3502 - {:added "1.0"} 328.3503 - [& sigs] 328.3504 - (let [name (if (symbol? (first sigs)) (first sigs) nil) 328.3505 - sigs (if name (next sigs) sigs) 328.3506 - sigs (if (vector? (first sigs)) (list sigs) sigs) 328.3507 - psig (fn* [sig] 328.3508 - (let [[params & body] sig 328.3509 - conds (when (and (next body) (map? (first body))) 328.3510 - (first body)) 328.3511 - body (if conds (next body) body) 328.3512 - conds (or conds (meta params)) 328.3513 - pre (:pre conds) 328.3514 - post (:post conds) 328.3515 - body (if post 328.3516 - `((let [~'% ~(if (< 1 (count body)) 328.3517 - `(do ~@body) 328.3518 - (first body))] 328.3519 - ~@(map (fn* [c] `(assert ~c)) post) 328.3520 - ~'%)) 328.3521 - body) 328.3522 - body (if pre 328.3523 - (concat (map (fn* [c] `(assert ~c)) pre) 328.3524 - body) 328.3525 - body)] 328.3526 - (maybe-destructured params body))) 328.3527 - new-sigs (map psig sigs)] 328.3528 - (with-meta 328.3529 - (if name 328.3530 - (list* 'fn* name new-sigs) 328.3531 - (cons 'fn* new-sigs)) 328.3532 - (meta &form)))) 328.3533 - 328.3534 -(defmacro loop 328.3535 - "Evaluates the exprs in a lexical context in which the symbols in 328.3536 - the binding-forms are bound to their respective init-exprs or parts 328.3537 - therein. Acts as a recur target." 328.3538 - {:added "1.0"} 328.3539 - [bindings & body] 328.3540 - (assert-args loop 328.3541 - (vector? bindings) "a vector for its binding" 328.3542 - (even? (count bindings)) "an even number of forms in binding vector") 328.3543 - (let [db (destructure bindings)] 328.3544 - (if (= db bindings) 328.3545 - `(loop* ~bindings ~@body) 328.3546 - (let [vs (take-nth 2 (drop 1 bindings)) 328.3547 - bs (take-nth 2 bindings) 328.3548 - gs (map (fn [b] (if (symbol? b) b (gensym))) bs) 328.3549 - bfs (reduce (fn [ret [b v g]] 328.3550 - (if (symbol? b) 328.3551 - (conj ret g v) 328.3552 - (conj ret g v b g))) 328.3553 - [] (map vector bs vs gs))] 328.3554 - `(let ~bfs 328.3555 - (loop* ~(vec (interleave gs gs)) 328.3556 - (let ~(vec (interleave bs gs)) 328.3557 - ~@body))))))) 328.3558 - 328.3559 -(defmacro when-first 328.3560 - "bindings => x xs 328.3561 - 328.3562 - Same as (when (seq xs) (let [x (first xs)] body))" 328.3563 - {:added "1.0"} 328.3564 - [bindings & body] 328.3565 - (assert-args when-first 328.3566 - (vector? bindings) "a vector for its binding" 328.3567 - (= 2 (count bindings)) "exactly 2 forms in binding vector") 328.3568 - (let [[x xs] bindings] 328.3569 - `(when (seq ~xs) 328.3570 - (let [~x (first ~xs)] 328.3571 - ~@body)))) 328.3572 - 328.3573 -(defmacro lazy-cat 328.3574 - "Expands to code which yields a lazy sequence of the concatenation 328.3575 - of the supplied colls. Each coll expr is not evaluated until it is 328.3576 - needed. 328.3577 - 328.3578 - (lazy-cat xs ys zs) === (concat (lazy-seq xs) (lazy-seq ys) (lazy-seq zs))" 328.3579 - {:added "1.0"} 328.3580 - [& colls] 328.3581 - `(concat ~@(map #(list `lazy-seq %) colls))) 328.3582 - 328.3583 -(defmacro for 328.3584 - "List comprehension. Takes a vector of one or more 328.3585 - binding-form/collection-expr pairs, each followed by zero or more 328.3586 - modifiers, and yields a lazy sequence of evaluations of expr. 328.3587 - Collections are iterated in a nested fashion, rightmost fastest, 328.3588 - and nested coll-exprs can refer to bindings created in prior 328.3589 - binding-forms. Supported modifiers are: :let [binding-form expr ...], 328.3590 - :while test, :when test. 328.3591 - 328.3592 - (take 100 (for [x (range 100000000) y (range 1000000) :while (< y x)] [x y]))" 328.3593 - {:added "1.0"} 328.3594 - [seq-exprs body-expr] 328.3595 - (assert-args for 328.3596 - (vector? seq-exprs) "a vector for its binding" 328.3597 - (even? (count seq-exprs)) "an even number of forms in binding vector") 328.3598 - (let [to-groups (fn [seq-exprs] 328.3599 - (reduce (fn [groups [k v]] 328.3600 - (if (keyword? k) 328.3601 - (conj (pop groups) (conj (peek groups) [k v])) 328.3602 - (conj groups [k v]))) 328.3603 - [] (partition 2 seq-exprs))) 328.3604 - err (fn [& msg] (throw (IllegalArgumentException. ^String (apply str msg)))) 328.3605 - emit-bind (fn emit-bind [[[bind expr & mod-pairs] 328.3606 - & [[_ next-expr] :as next-groups]]] 328.3607 - (let [giter (gensym "iter__") 328.3608 - gxs (gensym "s__") 328.3609 - do-mod (fn do-mod [[[k v :as pair] & etc]] 328.3610 - (cond 328.3611 - (= k :let) `(let ~v ~(do-mod etc)) 328.3612 - (= k :while) `(when ~v ~(do-mod etc)) 328.3613 - (= k :when) `(if ~v 328.3614 - ~(do-mod etc) 328.3615 - (recur (rest ~gxs))) 328.3616 - (keyword? k) (err "Invalid 'for' keyword " k) 328.3617 - next-groups 328.3618 - `(let [iterys# ~(emit-bind next-groups) 328.3619 - fs# (seq (iterys# ~next-expr))] 328.3620 - (if fs# 328.3621 - (concat fs# (~giter (rest ~gxs))) 328.3622 - (recur (rest ~gxs)))) 328.3623 - :else `(cons ~body-expr 328.3624 - (~giter (rest ~gxs)))))] 328.3625 - (if next-groups 328.3626 - #_"not the inner-most loop" 328.3627 - `(fn ~giter [~gxs] 328.3628 - (lazy-seq 328.3629 - (loop [~gxs ~gxs] 328.3630 - (when-first [~bind ~gxs] 328.3631 - ~(do-mod mod-pairs))))) 328.3632 - #_"inner-most loop" 328.3633 - (let [gi (gensym "i__") 328.3634 - gb (gensym "b__") 328.3635 - do-cmod (fn do-cmod [[[k v :as pair] & etc]] 328.3636 - (cond 328.3637 - (= k :let) `(let ~v ~(do-cmod etc)) 328.3638 - (= k :while) `(when ~v ~(do-cmod etc)) 328.3639 - (= k :when) `(if ~v 328.3640 - ~(do-cmod etc) 328.3641 - (recur 328.3642 - (unchecked-inc ~gi))) 328.3643 - (keyword? k) 328.3644 - (err "Invalid 'for' keyword " k) 328.3645 - :else 328.3646 - `(do (chunk-append ~gb ~body-expr) 328.3647 - (recur (unchecked-inc ~gi)))))] 328.3648 - `(fn ~giter [~gxs] 328.3649 - (lazy-seq 328.3650 - (loop [~gxs ~gxs] 328.3651 - (when-let [~gxs (seq ~gxs)] 328.3652 - (if (chunked-seq? ~gxs) 328.3653 - (let [c# (chunk-first ~gxs) 328.3654 - size# (int (count c#)) 328.3655 - ~gb (chunk-buffer size#)] 328.3656 - (if (loop [~gi (int 0)] 328.3657 - (if (< ~gi size#) 328.3658 - (let [~bind (.nth c# ~gi)] 328.3659 - ~(do-cmod mod-pairs)) 328.3660 - true)) 328.3661 - (chunk-cons 328.3662 - (chunk ~gb) 328.3663 - (~giter (chunk-rest ~gxs))) 328.3664 - (chunk-cons (chunk ~gb) nil))) 328.3665 - (let [~bind (first ~gxs)] 328.3666 - ~(do-mod mod-pairs)))))))))))] 328.3667 - `(let [iter# ~(emit-bind (to-groups seq-exprs))] 328.3668 - (iter# ~(second seq-exprs))))) 328.3669 - 328.3670 -(defmacro comment 328.3671 - "Ignores body, yields nil" 328.3672 - {:added "1.0"} 328.3673 - [& body]) 328.3674 - 328.3675 -(defmacro with-out-str 328.3676 - "Evaluates exprs in a context in which *out* is bound to a fresh 328.3677 - StringWriter. Returns the string created by any nested printing 328.3678 - calls." 328.3679 - {:added "1.0"} 328.3680 - [& body] 328.3681 - `(let [s# (new java.io.StringWriter)] 328.3682 - (binding [*out* s#] 328.3683 - ~@body 328.3684 - (str s#)))) 328.3685 - 328.3686 -(defmacro with-in-str 328.3687 - "Evaluates body in a context in which *in* is bound to a fresh 328.3688 - StringReader initialized with the string s." 328.3689 - {:added "1.0"} 328.3690 - [s & body] 328.3691 - `(with-open [s# (-> (java.io.StringReader. ~s) clojure.lang.LineNumberingPushbackReader.)] 328.3692 - (binding [*in* s#] 328.3693 - ~@body))) 328.3694 - 328.3695 -(defn pr-str 328.3696 - "pr to a string, returning it" 328.3697 - {:tag String 328.3698 - :added "1.0"} 328.3699 - [& xs] 328.3700 - (with-out-str 328.3701 - (apply pr xs))) 328.3702 - 328.3703 -(defn prn-str 328.3704 - "prn to a string, returning it" 328.3705 - {:tag String 328.3706 - :added "1.0"} 328.3707 - [& xs] 328.3708 - (with-out-str 328.3709 - (apply prn xs))) 328.3710 - 328.3711 -(defn print-str 328.3712 - "print to a string, returning it" 328.3713 - {:tag String 328.3714 - :added "1.0"} 328.3715 - [& xs] 328.3716 - (with-out-str 328.3717 - (apply print xs))) 328.3718 - 328.3719 -(defn println-str 328.3720 - "println to a string, returning it" 328.3721 - {:tag String 328.3722 - :added "1.0"} 328.3723 - [& xs] 328.3724 - (with-out-str 328.3725 - (apply println xs))) 328.3726 - 328.3727 -(defmacro assert 328.3728 - "Evaluates expr and throws an exception if it does not evaluate to 328.3729 - logical true." 328.3730 - {:added "1.0"} 328.3731 - [x] 328.3732 - (when *assert* 328.3733 - `(when-not ~x 328.3734 - (throw (new AssertionError (str "Assert failed: " (pr-str '~x))))))) 328.3735 - 328.3736 -(defn test 328.3737 - "test [v] finds fn at key :test in var metadata and calls it, 328.3738 - presuming failure will throw exception" 328.3739 - {:added "1.0"} 328.3740 - [v] 328.3741 - (let [f (:test (meta v))] 328.3742 - (if f 328.3743 - (do (f) :ok) 328.3744 - :no-test))) 328.3745 - 328.3746 -(defn re-pattern 328.3747 - "Returns an instance of java.util.regex.Pattern, for use, e.g. in 328.3748 - re-matcher." 328.3749 - {:tag java.util.regex.Pattern 328.3750 - :added "1.0"} 328.3751 - [s] (if (instance? java.util.regex.Pattern s) 328.3752 - s 328.3753 - (. java.util.regex.Pattern (compile s)))) 328.3754 - 328.3755 -(defn re-matcher 328.3756 - "Returns an instance of java.util.regex.Matcher, for use, e.g. in 328.3757 - re-find." 328.3758 - {:tag java.util.regex.Matcher 328.3759 - :added "1.0"} 328.3760 - [^java.util.regex.Pattern re s] 328.3761 - (. re (matcher s))) 328.3762 - 328.3763 -(defn re-groups 328.3764 - "Returns the groups from the most recent match/find. If there are no 328.3765 - nested groups, returns a string of the entire match. If there are 328.3766 - nested groups, returns a vector of the groups, the first element 328.3767 - being the entire match." 328.3768 - {:added "1.0"} 328.3769 - [^java.util.regex.Matcher m] 328.3770 - (let [gc (. m (groupCount))] 328.3771 - (if (zero? gc) 328.3772 - (. m (group)) 328.3773 - (loop [ret [] c 0] 328.3774 - (if (<= c gc) 328.3775 - (recur (conj ret (. m (group c))) (inc c)) 328.3776 - ret))))) 328.3777 - 328.3778 -(defn re-seq 328.3779 - "Returns a lazy sequence of successive matches of pattern in string, 328.3780 - using java.util.regex.Matcher.find(), each such match processed with 328.3781 - re-groups." 328.3782 - {:added "1.0"} 328.3783 - [^java.util.regex.Pattern re s] 328.3784 - (let [m (re-matcher re s)] 328.3785 - ((fn step [] 328.3786 - (when (. m (find)) 328.3787 - (cons (re-groups m) (lazy-seq (step)))))))) 328.3788 - 328.3789 -(defn re-matches 328.3790 - "Returns the match, if any, of string to pattern, using 328.3791 - java.util.regex.Matcher.matches(). Uses re-groups to return the 328.3792 - groups." 328.3793 - {:added "1.0"} 328.3794 - [^java.util.regex.Pattern re s] 328.3795 - (let [m (re-matcher re s)] 328.3796 - (when (. m (matches)) 328.3797 - (re-groups m)))) 328.3798 - 328.3799 - 328.3800 -(defn re-find 328.3801 - "Returns the next regex match, if any, of string to pattern, using 328.3802 - java.util.regex.Matcher.find(). Uses re-groups to return the 328.3803 - groups." 328.3804 - {:added "1.0"} 328.3805 - ([^java.util.regex.Matcher m] 328.3806 - (when (. m (find)) 328.3807 - (re-groups m))) 328.3808 - ([^java.util.regex.Pattern re s] 328.3809 - (let [m (re-matcher re s)] 328.3810 - (re-find m)))) 328.3811 - 328.3812 -(defn rand 328.3813 - "Returns a random floating point number between 0 (inclusive) and 328.3814 - n (default 1) (exclusive)." 328.3815 - {:added "1.0"} 328.3816 - ([] (. Math (random))) 328.3817 - ([n] (* n (rand)))) 328.3818 - 328.3819 -(defn rand-int 328.3820 - "Returns a random integer between 0 (inclusive) and n (exclusive)." 328.3821 - {:added "1.0"} 328.3822 - [n] (int (rand n))) 328.3823 - 328.3824 -(defmacro defn- 328.3825 - "same as defn, yielding non-public def" 328.3826 - {:added "1.0"} 328.3827 - [name & decls] 328.3828 - (list* `defn (with-meta name (assoc (meta name) :private true)) decls)) 328.3829 - 328.3830 -(defn print-doc [v] 328.3831 - (println "-------------------------") 328.3832 - (println (str (ns-name (:ns (meta v))) "/" (:name (meta v)))) 328.3833 - (prn (:arglists (meta v))) 328.3834 - (when (:macro (meta v)) 328.3835 - (println "Macro")) 328.3836 - (println " " (:doc (meta v)))) 328.3837 - 328.3838 -(defn find-doc 328.3839 - "Prints documentation for any var whose documentation or name 328.3840 - contains a match for re-string-or-pattern" 328.3841 - {:added "1.0"} 328.3842 - [re-string-or-pattern] 328.3843 - (let [re (re-pattern re-string-or-pattern)] 328.3844 - (doseq [ns (all-ns) 328.3845 - v (sort-by (comp :name meta) (vals (ns-interns ns))) 328.3846 - :when (and (:doc (meta v)) 328.3847 - (or (re-find (re-matcher re (:doc (meta v)))) 328.3848 - (re-find (re-matcher re (str (:name (meta v)))))))] 328.3849 - (print-doc v)))) 328.3850 - 328.3851 -(defn special-form-anchor 328.3852 - "Returns the anchor tag on http://clojure.org/special_forms for the 328.3853 - special form x, or nil" 328.3854 - {:added "1.0"} 328.3855 - [x] 328.3856 - (#{'. 'def 'do 'fn 'if 'let 'loop 'monitor-enter 'monitor-exit 'new 328.3857 - 'quote 'recur 'set! 'throw 'try 'var} x)) 328.3858 - 328.3859 -(defn syntax-symbol-anchor 328.3860 - "Returns the anchor tag on http://clojure.org/special_forms for the 328.3861 - special form that uses syntax symbol x, or nil" 328.3862 - {:added "1.0"} 328.3863 - [x] 328.3864 - ({'& 'fn 'catch 'try 'finally 'try} x)) 328.3865 - 328.3866 -(defn print-special-doc 328.3867 - [name type anchor] 328.3868 - (println "-------------------------") 328.3869 - (println name) 328.3870 - (println type) 328.3871 - (println (str " Please see http://clojure.org/special_forms#" anchor))) 328.3872 - 328.3873 -(defn print-namespace-doc 328.3874 - "Print the documentation string of a Namespace." 328.3875 - {:added "1.0"} 328.3876 - [nspace] 328.3877 - (println "-------------------------") 328.3878 - (println (str (ns-name nspace))) 328.3879 - (println " " (:doc (meta nspace)))) 328.3880 - 328.3881 -(defmacro doc 328.3882 - "Prints documentation for a var or special form given its name" 328.3883 - {:added "1.0"} 328.3884 - [name] 328.3885 - (cond 328.3886 - (special-form-anchor `~name) 328.3887 - `(print-special-doc '~name "Special Form" (special-form-anchor '~name)) 328.3888 - (syntax-symbol-anchor `~name) 328.3889 - `(print-special-doc '~name "Syntax Symbol" (syntax-symbol-anchor '~name)) 328.3890 - :else 328.3891 - (let [nspace (find-ns name)] 328.3892 - (if nspace 328.3893 - `(print-namespace-doc ~nspace) 328.3894 - `(print-doc (var ~name)))))) 328.3895 - 328.3896 - (defn tree-seq 328.3897 - "Returns a lazy sequence of the nodes in a tree, via a depth-first walk. 328.3898 - branch? must be a fn of one arg that returns true if passed a node 328.3899 - that can have children (but may not). children must be a fn of one 328.3900 - arg that returns a sequence of the children. Will only be called on 328.3901 - nodes for which branch? returns true. Root is the root node of the 328.3902 - tree." 328.3903 - {:added "1.0"} 328.3904 - [branch? children root] 328.3905 - (let [walk (fn walk [node] 328.3906 - (lazy-seq 328.3907 - (cons node 328.3908 - (when (branch? node) 328.3909 - (mapcat walk (children node))))))] 328.3910 - (walk root))) 328.3911 - 328.3912 -(defn file-seq 328.3913 - "A tree seq on java.io.Files" 328.3914 - {:added "1.0"} 328.3915 - [dir] 328.3916 - (tree-seq 328.3917 - (fn [^java.io.File f] (. f (isDirectory))) 328.3918 - (fn [^java.io.File d] (seq (. d (listFiles)))) 328.3919 - dir)) 328.3920 - 328.3921 -(defn xml-seq 328.3922 - "A tree seq on the xml elements as per xml/parse" 328.3923 - {:added "1.0"} 328.3924 - [root] 328.3925 - (tree-seq 328.3926 - (complement string?) 328.3927 - (comp seq :content) 328.3928 - root)) 328.3929 - 328.3930 -(defn special-symbol? 328.3931 - "Returns true if s names a special form" 328.3932 - {:added "1.0"} 328.3933 - [s] 328.3934 - (contains? (. clojure.lang.Compiler specials) s)) 328.3935 - 328.3936 -(defn var? 328.3937 - "Returns true if v is of type clojure.lang.Var" 328.3938 - {:added "1.0"} 328.3939 - [v] (instance? clojure.lang.Var v)) 328.3940 - 328.3941 -(defn ^String subs 328.3942 - "Returns the substring of s beginning at start inclusive, and ending 328.3943 - at end (defaults to length of string), exclusive." 328.3944 - {:added "1.0"} 328.3945 - ([^String s start] (. s (substring start))) 328.3946 - ([^String s start end] (. s (substring start end)))) 328.3947 - 328.3948 -(defn max-key 328.3949 - "Returns the x for which (k x), a number, is greatest." 328.3950 - {:added "1.0"} 328.3951 - ([k x] x) 328.3952 - ([k x y] (if (> (k x) (k y)) x y)) 328.3953 - ([k x y & more] 328.3954 - (reduce #(max-key k %1 %2) (max-key k x y) more))) 328.3955 - 328.3956 -(defn min-key 328.3957 - "Returns the x for which (k x), a number, is least." 328.3958 - {:added "1.0"} 328.3959 - ([k x] x) 328.3960 - ([k x y] (if (< (k x) (k y)) x y)) 328.3961 - ([k x y & more] 328.3962 - (reduce #(min-key k %1 %2) (min-key k x y) more))) 328.3963 - 328.3964 -(defn distinct 328.3965 - "Returns a lazy sequence of the elements of coll with duplicates removed" 328.3966 - {:added "1.0"} 328.3967 - [coll] 328.3968 - (let [step (fn step [xs seen] 328.3969 - (lazy-seq 328.3970 - ((fn [[f :as xs] seen] 328.3971 - (when-let [s (seq xs)] 328.3972 - (if (contains? seen f) 328.3973 - (recur (rest s) seen) 328.3974 - (cons f (step (rest s) (conj seen f)))))) 328.3975 - xs seen)))] 328.3976 - (step coll #{}))) 328.3977 - 328.3978 - 328.3979 - 328.3980 -(defn replace 328.3981 - "Given a map of replacement pairs and a vector/collection, returns a 328.3982 - vector/seq with any elements = a key in smap replaced with the 328.3983 - corresponding val in smap" 328.3984 - {:added "1.0"} 328.3985 - [smap coll] 328.3986 - (if (vector? coll) 328.3987 - (reduce (fn [v i] 328.3988 - (if-let [e (find smap (nth v i))] 328.3989 - (assoc v i (val e)) 328.3990 - v)) 328.3991 - coll (range (count coll))) 328.3992 - (map #(if-let [e (find smap %)] (val e) %) coll))) 328.3993 - 328.3994 -(defmacro dosync 328.3995 - "Runs the exprs (in an implicit do) in a transaction that encompasses 328.3996 - exprs and any nested calls. Starts a transaction if none is already 328.3997 - running on this thread. Any uncaught exception will abort the 328.3998 - transaction and flow out of dosync. The exprs may be run more than 328.3999 - once, but any effects on Refs will be atomic." 328.4000 - {:added "1.0"} 328.4001 - [& exprs] 328.4002 - `(sync nil ~@exprs)) 328.4003 - 328.4004 -(defmacro with-precision 328.4005 - "Sets the precision and rounding mode to be used for BigDecimal operations. 328.4006 - 328.4007 - Usage: (with-precision 10 (/ 1M 3)) 328.4008 - or: (with-precision 10 :rounding HALF_DOWN (/ 1M 3)) 328.4009 - 328.4010 - The rounding mode is one of CEILING, FLOOR, HALF_UP, HALF_DOWN, 328.4011 - HALF_EVEN, UP, DOWN and UNNECESSARY; it defaults to HALF_UP." 328.4012 - {:added "1.0"} 328.4013 - [precision & exprs] 328.4014 - (let [[body rm] (if (= (first exprs) :rounding) 328.4015 - [(next (next exprs)) 328.4016 - `((. java.math.RoundingMode ~(second exprs)))] 328.4017 - [exprs nil])] 328.4018 - `(binding [*math-context* (java.math.MathContext. ~precision ~@rm)] 328.4019 - ~@body))) 328.4020 - 328.4021 -(defn mk-bound-fn 328.4022 - {:private true} 328.4023 - [^clojure.lang.Sorted sc test key] 328.4024 - (fn [e] 328.4025 - (test (.. sc comparator (compare (. sc entryKey e) key)) 0))) 328.4026 - 328.4027 -(defn subseq 328.4028 - "sc must be a sorted collection, test(s) one of <, <=, > or 328.4029 - >=. Returns a seq of those entries with keys ek for 328.4030 - which (test (.. sc comparator (compare ek key)) 0) is true" 328.4031 - {:added "1.0"} 328.4032 - ([^clojure.lang.Sorted sc test key] 328.4033 - (let [include (mk-bound-fn sc test key)] 328.4034 - (if (#{> >=} test) 328.4035 - (when-let [[e :as s] (. sc seqFrom key true)] 328.4036 - (if (include e) s (next s))) 328.4037 - (take-while include (. sc seq true))))) 328.4038 - ([^clojure.lang.Sorted sc start-test start-key end-test end-key] 328.4039 - (when-let [[e :as s] (. sc seqFrom start-key true)] 328.4040 - (take-while (mk-bound-fn sc end-test end-key) 328.4041 - (if ((mk-bound-fn sc start-test start-key) e) s (next s)))))) 328.4042 - 328.4043 -(defn rsubseq 328.4044 - "sc must be a sorted collection, test(s) one of <, <=, > or 328.4045 - >=. Returns a reverse seq of those entries with keys ek for 328.4046 - which (test (.. sc comparator (compare ek key)) 0) is true" 328.4047 - {:added "1.0"} 328.4048 - ([^clojure.lang.Sorted sc test key] 328.4049 - (let [include (mk-bound-fn sc test key)] 328.4050 - (if (#{< <=} test) 328.4051 - (when-let [[e :as s] (. sc seqFrom key false)] 328.4052 - (if (include e) s (next s))) 328.4053 - (take-while include (. sc seq false))))) 328.4054 - ([^clojure.lang.Sorted sc start-test start-key end-test end-key] 328.4055 - (when-let [[e :as s] (. sc seqFrom end-key false)] 328.4056 - (take-while (mk-bound-fn sc start-test start-key) 328.4057 - (if ((mk-bound-fn sc end-test end-key) e) s (next s)))))) 328.4058 - 328.4059 -(defn repeatedly 328.4060 - "Takes a function of no args, presumably with side effects, and 328.4061 - returns an infinite (or length n if supplied) lazy sequence of calls 328.4062 - to it" 328.4063 - {:added "1.0"} 328.4064 - ([f] (lazy-seq (cons (f) (repeatedly f)))) 328.4065 - ([n f] (take n (repeatedly f)))) 328.4066 - 328.4067 -(defn add-classpath 328.4068 - "DEPRECATED 328.4069 - 328.4070 - Adds the url (String or URL object) to the classpath per 328.4071 - URLClassLoader.addURL" 328.4072 - {:added "1.0" 328.4073 - :deprecated "1.1"} 328.4074 - [url] 328.4075 - (println "WARNING: add-classpath is deprecated") 328.4076 - (clojure.lang.RT/addURL url)) 328.4077 - 328.4078 - 328.4079 - 328.4080 -(defn hash 328.4081 - "Returns the hash code of its argument" 328.4082 - {:added "1.0"} 328.4083 - [x] (. clojure.lang.Util (hash x))) 328.4084 - 328.4085 -(defn interpose 328.4086 - "Returns a lazy seq of the elements of coll separated by sep" 328.4087 - {:added "1.0"} 328.4088 - [sep coll] (drop 1 (interleave (repeat sep) coll))) 328.4089 - 328.4090 -(defmacro definline 328.4091 - "Experimental - like defmacro, except defines a named function whose 328.4092 - body is the expansion, calls to which may be expanded inline as if 328.4093 - it were a macro. Cannot be used with variadic (&) args." 328.4094 - {:added "1.0"} 328.4095 - [name & decl] 328.4096 - (let [[pre-args [args expr]] (split-with (comp not vector?) decl)] 328.4097 - `(do 328.4098 - (defn ~name ~@pre-args ~args ~(apply (eval (list `fn args expr)) args)) 328.4099 - (alter-meta! (var ~name) assoc :inline (fn ~name ~args ~expr)) 328.4100 - (var ~name)))) 328.4101 - 328.4102 -(defn empty 328.4103 - "Returns an empty collection of the same category as coll, or nil" 328.4104 - {:added "1.0"} 328.4105 - [coll] 328.4106 - (when (instance? clojure.lang.IPersistentCollection coll) 328.4107 - (.empty ^clojure.lang.IPersistentCollection coll))) 328.4108 - 328.4109 -(defmacro amap 328.4110 - "Maps an expression across an array a, using an index named idx, and 328.4111 - return value named ret, initialized to a clone of a, then setting 328.4112 - each element of ret to the evaluation of expr, returning the new 328.4113 - array ret." 328.4114 - {:added "1.0"} 328.4115 - [a idx ret expr] 328.4116 - `(let [a# ~a 328.4117 - ~ret (aclone a#)] 328.4118 - (loop [~idx (int 0)] 328.4119 - (if (< ~idx (alength a#)) 328.4120 - (do 328.4121 - (aset ~ret ~idx ~expr) 328.4122 - (recur (unchecked-inc ~idx))) 328.4123 - ~ret)))) 328.4124 - 328.4125 -(defmacro areduce 328.4126 - "Reduces an expression across an array a, using an index named idx, 328.4127 - and return value named ret, initialized to init, setting ret to the 328.4128 - evaluation of expr at each step, returning ret." 328.4129 - {:added "1.0"} 328.4130 - [a idx ret init expr] 328.4131 - `(let [a# ~a] 328.4132 - (loop [~idx (int 0) ~ret ~init] 328.4133 - (if (< ~idx (alength a#)) 328.4134 - (recur (unchecked-inc ~idx) ~expr) 328.4135 - ~ret)))) 328.4136 - 328.4137 -(defn float-array 328.4138 - "Creates an array of floats" 328.4139 - {:inline (fn [& args] `(. clojure.lang.Numbers float_array ~@args)) 328.4140 - :inline-arities #{1 2} 328.4141 - :added "1.0"} 328.4142 - ([size-or-seq] (. clojure.lang.Numbers float_array size-or-seq)) 328.4143 - ([size init-val-or-seq] (. clojure.lang.Numbers float_array size init-val-or-seq))) 328.4144 - 328.4145 -(defn boolean-array 328.4146 - "Creates an array of booleans" 328.4147 - {:inline (fn [& args] `(. clojure.lang.Numbers boolean_array ~@args)) 328.4148 - :inline-arities #{1 2} 328.4149 - :added "1.1"} 328.4150 - ([size-or-seq] (. clojure.lang.Numbers boolean_array size-or-seq)) 328.4151 - ([size init-val-or-seq] (. clojure.lang.Numbers boolean_array size init-val-or-seq))) 328.4152 - 328.4153 -(defn byte-array 328.4154 - "Creates an array of bytes" 328.4155 - {:inline (fn [& args] `(. clojure.lang.Numbers byte_array ~@args)) 328.4156 - :inline-arities #{1 2} 328.4157 - :added "1.1"} 328.4158 - ([size-or-seq] (. clojure.lang.Numbers byte_array size-or-seq)) 328.4159 - ([size init-val-or-seq] (. clojure.lang.Numbers byte_array size init-val-or-seq))) 328.4160 - 328.4161 -(defn char-array 328.4162 - "Creates an array of chars" 328.4163 - {:inline (fn [& args] `(. clojure.lang.Numbers char_array ~@args)) 328.4164 - :inline-arities #{1 2} 328.4165 - :added "1.1"} 328.4166 - ([size-or-seq] (. clojure.lang.Numbers char_array size-or-seq)) 328.4167 - ([size init-val-or-seq] (. clojure.lang.Numbers char_array size init-val-or-seq))) 328.4168 - 328.4169 -(defn short-array 328.4170 - "Creates an array of shorts" 328.4171 - {:inline (fn [& args] `(. clojure.lang.Numbers short_array ~@args)) 328.4172 - :inline-arities #{1 2} 328.4173 - :added "1.1"} 328.4174 - ([size-or-seq] (. clojure.lang.Numbers short_array size-or-seq)) 328.4175 - ([size init-val-or-seq] (. clojure.lang.Numbers short_array size init-val-or-seq))) 328.4176 - 328.4177 -(defn double-array 328.4178 - "Creates an array of doubles" 328.4179 - {:inline (fn [& args] `(. clojure.lang.Numbers double_array ~@args)) 328.4180 - :inline-arities #{1 2} 328.4181 - :added "1.0"} 328.4182 - ([size-or-seq] (. clojure.lang.Numbers double_array size-or-seq)) 328.4183 - ([size init-val-or-seq] (. clojure.lang.Numbers double_array size init-val-or-seq))) 328.4184 - 328.4185 -(defn object-array 328.4186 - "Creates an array of objects" 328.4187 - {:inline (fn [arg] `(. clojure.lang.RT object_array ~arg)) 328.4188 - :inline-arities #{1} 328.4189 - :added "1.2"} 328.4190 - ([size-or-seq] (. clojure.lang.RT object_array size-or-seq))) 328.4191 - 328.4192 -(defn int-array 328.4193 - "Creates an array of ints" 328.4194 - {:inline (fn [& args] `(. clojure.lang.Numbers int_array ~@args)) 328.4195 - :inline-arities #{1 2} 328.4196 - :added "1.0"} 328.4197 - ([size-or-seq] (. clojure.lang.Numbers int_array size-or-seq)) 328.4198 - ([size init-val-or-seq] (. clojure.lang.Numbers int_array size init-val-or-seq))) 328.4199 - 328.4200 -(defn long-array 328.4201 - "Creates an array of longs" 328.4202 - {:inline (fn [& args] `(. clojure.lang.Numbers long_array ~@args)) 328.4203 - :inline-arities #{1 2} 328.4204 - :added "1.0"} 328.4205 - ([size-or-seq] (. clojure.lang.Numbers long_array size-or-seq)) 328.4206 - ([size init-val-or-seq] (. clojure.lang.Numbers long_array size init-val-or-seq))) 328.4207 - 328.4208 -(definline booleans 328.4209 - "Casts to boolean[]" 328.4210 - {:added "1.1"} 328.4211 - [xs] `(. clojure.lang.Numbers booleans ~xs)) 328.4212 - 328.4213 -(definline bytes 328.4214 - "Casts to bytes[]" 328.4215 - {:added "1.1"} 328.4216 - [xs] `(. clojure.lang.Numbers bytes ~xs)) 328.4217 - 328.4218 -(definline chars 328.4219 - "Casts to chars[]" 328.4220 - {:added "1.1"} 328.4221 - [xs] `(. clojure.lang.Numbers chars ~xs)) 328.4222 - 328.4223 -(definline shorts 328.4224 - "Casts to shorts[]" 328.4225 - {:added "1.1"} 328.4226 - [xs] `(. clojure.lang.Numbers shorts ~xs)) 328.4227 - 328.4228 -(definline floats 328.4229 - "Casts to float[]" 328.4230 - {:added "1.0"} 328.4231 - [xs] `(. clojure.lang.Numbers floats ~xs)) 328.4232 - 328.4233 -(definline ints 328.4234 - "Casts to int[]" 328.4235 - {:added "1.0"} 328.4236 - [xs] `(. clojure.lang.Numbers ints ~xs)) 328.4237 - 328.4238 -(definline doubles 328.4239 - "Casts to double[]" 328.4240 - {:added "1.0"} 328.4241 - [xs] `(. clojure.lang.Numbers doubles ~xs)) 328.4242 - 328.4243 -(definline longs 328.4244 - "Casts to long[]" 328.4245 - {:added "1.0"} 328.4246 - [xs] `(. clojure.lang.Numbers longs ~xs)) 328.4247 - 328.4248 -(import '(java.util.concurrent BlockingQueue LinkedBlockingQueue)) 328.4249 - 328.4250 -(defn seque 328.4251 - "Creates a queued seq on another (presumably lazy) seq s. The queued 328.4252 - seq will produce a concrete seq in the background, and can get up to 328.4253 - n items ahead of the consumer. n-or-q can be an integer n buffer 328.4254 - size, or an instance of java.util.concurrent BlockingQueue. Note 328.4255 - that reading from a seque can block if the reader gets ahead of the 328.4256 - producer." 328.4257 - {:added "1.0"} 328.4258 - ([s] (seque 100 s)) 328.4259 - ([n-or-q s] 328.4260 - (let [^BlockingQueue q (if (instance? BlockingQueue n-or-q) 328.4261 - n-or-q 328.4262 - (LinkedBlockingQueue. (int n-or-q))) 328.4263 - NIL (Object.) ;nil sentinel since LBQ doesn't support nils 328.4264 - agt (agent (seq s)) 328.4265 - fill (fn [s] 328.4266 - (try 328.4267 - (loop [[x & xs :as s] s] 328.4268 - (if s 328.4269 - (if (.offer q (if (nil? x) NIL x)) 328.4270 - (recur xs) 328.4271 - s) 328.4272 - (.put q q))) ; q itself is eos sentinel 328.4273 - (catch Exception e 328.4274 - (.put q q) 328.4275 - (throw e)))) 328.4276 - drain (fn drain [] 328.4277 - (lazy-seq 328.4278 - (let [x (.take q)] 328.4279 - (if (identical? x q) ;q itself is eos sentinel 328.4280 - (do @agt nil) ;touch agent just to propagate errors 328.4281 - (do 328.4282 - (send-off agt fill) 328.4283 - (cons (if (identical? x NIL) nil x) (drain)))))))] 328.4284 - (send-off agt fill) 328.4285 - (drain)))) 328.4286 - 328.4287 -(defn class? 328.4288 - "Returns true if x is an instance of Class" 328.4289 - {:added "1.0"} 328.4290 - [x] (instance? Class x)) 328.4291 - 328.4292 -(defn- is-annotation? [c] 328.4293 - (and (class? c) 328.4294 - (.isAssignableFrom java.lang.annotation.Annotation c))) 328.4295 - 328.4296 -(defn- is-runtime-annotation? [^Class c] 328.4297 - (boolean 328.4298 - (and (is-annotation? c) 328.4299 - (when-let [^java.lang.annotation.Retention r 328.4300 - (.getAnnotation c java.lang.annotation.Retention)] 328.4301 - (= (.value r) java.lang.annotation.RetentionPolicy/RUNTIME))))) 328.4302 - 328.4303 -(defn- descriptor [^Class c] (clojure.asm.Type/getDescriptor c)) 328.4304 - 328.4305 -(declare process-annotation) 328.4306 -(defn- add-annotation [^clojure.asm.AnnotationVisitor av name v] 328.4307 - (cond 328.4308 - (vector? v) (let [avec (.visitArray av name)] 328.4309 - (doseq [vval v] 328.4310 - (add-annotation avec "value" vval)) 328.4311 - (.visitEnd avec)) 328.4312 - (symbol? v) (let [ev (eval v)] 328.4313 - (cond 328.4314 - (instance? java.lang.Enum ev) 328.4315 - (.visitEnum av name (descriptor (class ev)) (str ev)) 328.4316 - (class? ev) (.visit av name (clojure.asm.Type/getType ev)) 328.4317 - :else (throw (IllegalArgumentException. 328.4318 - (str "Unsupported annotation value: " v " of class " (class ev)))))) 328.4319 - (seq? v) (let [[nested nv] v 328.4320 - c (resolve nested) 328.4321 - nav (.visitAnnotation av name (descriptor c))] 328.4322 - (process-annotation nav nv) 328.4323 - (.visitEnd nav)) 328.4324 - :else (.visit av name v))) 328.4325 - 328.4326 -(defn- process-annotation [av v] 328.4327 - (if (map? v) 328.4328 - (doseq [[k v] v] 328.4329 - (add-annotation av (name k) v)) 328.4330 - (add-annotation av "value" v))) 328.4331 - 328.4332 -(defn- add-annotations 328.4333 - ([visitor m] (add-annotations visitor m nil)) 328.4334 - ([visitor m i] 328.4335 - (doseq [[k v] m] 328.4336 - (when (symbol? k) 328.4337 - (when-let [c (resolve k)] 328.4338 - (when (is-annotation? c) 328.4339 - ;this is known duck/reflective as no common base of ASM Visitors 328.4340 - (let [av (if i 328.4341 - (.visitParameterAnnotation visitor i (descriptor c) 328.4342 - (is-runtime-annotation? c)) 328.4343 - (.visitAnnotation visitor (descriptor c) 328.4344 - (is-runtime-annotation? c)))] 328.4345 - (process-annotation av v) 328.4346 - (.visitEnd av)))))))) 328.4347 - 328.4348 -(defn alter-var-root 328.4349 - "Atomically alters the root binding of var v by applying f to its 328.4350 - current value plus any args" 328.4351 - {:added "1.0"} 328.4352 - [^clojure.lang.Var v f & args] (.alterRoot v f args)) 328.4353 - 328.4354 -(defn bound? 328.4355 - "Returns true if all of the vars provided as arguments have any bound value, root or thread-local. 328.4356 - Implies that deref'ing the provided vars will succeed. Returns true if no vars are provided." 328.4357 - {:added "1.2"} 328.4358 - [& vars] 328.4359 - (every? #(.isBound ^clojure.lang.Var %) vars)) 328.4360 - 328.4361 -(defn thread-bound? 328.4362 - "Returns true if all of the vars provided as arguments have thread-local bindings. 328.4363 - Implies that set!'ing the provided vars will succeed. Returns true if no vars are provided." 328.4364 - {:added "1.2"} 328.4365 - [& vars] 328.4366 - (every? #(.getThreadBinding ^clojure.lang.Var %) vars)) 328.4367 - 328.4368 -(defn make-hierarchy 328.4369 - "Creates a hierarchy object for use with derive, isa? etc." 328.4370 - {:added "1.0"} 328.4371 - [] {:parents {} :descendants {} :ancestors {}}) 328.4372 - 328.4373 -(def ^{:private true} 328.4374 - global-hierarchy (make-hierarchy)) 328.4375 - 328.4376 -(defn not-empty 328.4377 - "If coll is empty, returns nil, else coll" 328.4378 - {:added "1.0"} 328.4379 - [coll] (when (seq coll) coll)) 328.4380 - 328.4381 -(defn bases 328.4382 - "Returns the immediate superclass and direct interfaces of c, if any" 328.4383 - {:added "1.0"} 328.4384 - [^Class c] 328.4385 - (when c 328.4386 - (let [i (.getInterfaces c) 328.4387 - s (.getSuperclass c)] 328.4388 - (not-empty 328.4389 - (if s (cons s i) i))))) 328.4390 - 328.4391 -(defn supers 328.4392 - "Returns the immediate and indirect superclasses and interfaces of c, if any" 328.4393 - {:added "1.0"} 328.4394 - [^Class class] 328.4395 - (loop [ret (set (bases class)) cs ret] 328.4396 - (if (seq cs) 328.4397 - (let [c (first cs) bs (bases c)] 328.4398 - (recur (into ret bs) (into (disj cs c) bs))) 328.4399 - (not-empty ret)))) 328.4400 - 328.4401 -(defn isa? 328.4402 - "Returns true if (= child parent), or child is directly or indirectly derived from 328.4403 - parent, either via a Java type inheritance relationship or a 328.4404 - relationship established via derive. h must be a hierarchy obtained 328.4405 - from make-hierarchy, if not supplied defaults to the global 328.4406 - hierarchy" 328.4407 - {:added "1.0"} 328.4408 - ([child parent] (isa? global-hierarchy child parent)) 328.4409 - ([h child parent] 328.4410 - (or (= child parent) 328.4411 - (and (class? parent) (class? child) 328.4412 - (. ^Class parent isAssignableFrom child)) 328.4413 - (contains? ((:ancestors h) child) parent) 328.4414 - (and (class? child) (some #(contains? ((:ancestors h) %) parent) (supers child))) 328.4415 - (and (vector? parent) (vector? child) 328.4416 - (= (count parent) (count child)) 328.4417 - (loop [ret true i 0] 328.4418 - (if (or (not ret) (= i (count parent))) 328.4419 - ret 328.4420 - (recur (isa? h (child i) (parent i)) (inc i)))))))) 328.4421 - 328.4422 -(defn parents 328.4423 - "Returns the immediate parents of tag, either via a Java type 328.4424 - inheritance relationship or a relationship established via derive. h 328.4425 - must be a hierarchy obtained from make-hierarchy, if not supplied 328.4426 - defaults to the global hierarchy" 328.4427 - {:added "1.0"} 328.4428 - ([tag] (parents global-hierarchy tag)) 328.4429 - ([h tag] (not-empty 328.4430 - (let [tp (get (:parents h) tag)] 328.4431 - (if (class? tag) 328.4432 - (into (set (bases tag)) tp) 328.4433 - tp))))) 328.4434 - 328.4435 -(defn ancestors 328.4436 - "Returns the immediate and indirect parents of tag, either via a Java type 328.4437 - inheritance relationship or a relationship established via derive. h 328.4438 - must be a hierarchy obtained from make-hierarchy, if not supplied 328.4439 - defaults to the global hierarchy" 328.4440 - {:added "1.0"} 328.4441 - ([tag] (ancestors global-hierarchy tag)) 328.4442 - ([h tag] (not-empty 328.4443 - (let [ta (get (:ancestors h) tag)] 328.4444 - (if (class? tag) 328.4445 - (let [superclasses (set (supers tag))] 328.4446 - (reduce into superclasses 328.4447 - (cons ta 328.4448 - (map #(get (:ancestors h) %) superclasses)))) 328.4449 - ta))))) 328.4450 - 328.4451 -(defn descendants 328.4452 - "Returns the immediate and indirect children of tag, through a 328.4453 - relationship established via derive. h must be a hierarchy obtained 328.4454 - from make-hierarchy, if not supplied defaults to the global 328.4455 - hierarchy. Note: does not work on Java type inheritance 328.4456 - relationships." 328.4457 - {:added "1.0"} 328.4458 - ([tag] (descendants global-hierarchy tag)) 328.4459 - ([h tag] (if (class? tag) 328.4460 - (throw (java.lang.UnsupportedOperationException. "Can't get descendants of classes")) 328.4461 - (not-empty (get (:descendants h) tag))))) 328.4462 - 328.4463 -(defn derive 328.4464 - "Establishes a parent/child relationship between parent and 328.4465 - tag. Parent must be a namespace-qualified symbol or keyword and 328.4466 - child can be either a namespace-qualified symbol or keyword or a 328.4467 - class. h must be a hierarchy obtained from make-hierarchy, if not 328.4468 - supplied defaults to, and modifies, the global hierarchy." 328.4469 - {:added "1.0"} 328.4470 - ([tag parent] 328.4471 - (assert (namespace parent)) 328.4472 - (assert (or (class? tag) (and (instance? clojure.lang.Named tag) (namespace tag)))) 328.4473 - 328.4474 - (alter-var-root #'global-hierarchy derive tag parent) nil) 328.4475 - ([h tag parent] 328.4476 - (assert (not= tag parent)) 328.4477 - (assert (or (class? tag) (instance? clojure.lang.Named tag))) 328.4478 - (assert (instance? clojure.lang.Named parent)) 328.4479 - 328.4480 - (let [tp (:parents h) 328.4481 - td (:descendants h) 328.4482 - ta (:ancestors h) 328.4483 - tf (fn [m source sources target targets] 328.4484 - (reduce (fn [ret k] 328.4485 - (assoc ret k 328.4486 - (reduce conj (get targets k #{}) (cons target (targets target))))) 328.4487 - m (cons source (sources source))))] 328.4488 - (or 328.4489 - (when-not (contains? (tp tag) parent) 328.4490 - (when (contains? (ta tag) parent) 328.4491 - (throw (Exception. (print-str tag "already has" parent "as ancestor")))) 328.4492 - (when (contains? (ta parent) tag) 328.4493 - (throw (Exception. (print-str "Cyclic derivation:" parent "has" tag "as ancestor")))) 328.4494 - {:parents (assoc (:parents h) tag (conj (get tp tag #{}) parent)) 328.4495 - :ancestors (tf (:ancestors h) tag td parent ta) 328.4496 - :descendants (tf (:descendants h) parent ta tag td)}) 328.4497 - h)))) 328.4498 - 328.4499 -(declare flatten) 328.4500 - 328.4501 -(defn underive 328.4502 - "Removes a parent/child relationship between parent and 328.4503 - tag. h must be a hierarchy obtained from make-hierarchy, if not 328.4504 - supplied defaults to, and modifies, the global hierarchy." 328.4505 - {:added "1.0"} 328.4506 - ([tag parent] (alter-var-root #'global-hierarchy underive tag parent) nil) 328.4507 - ([h tag parent] 328.4508 - (let [parentMap (:parents h) 328.4509 - childsParents (if (parentMap tag) 328.4510 - (disj (parentMap tag) parent) #{}) 328.4511 - newParents (if (not-empty childsParents) 328.4512 - (assoc parentMap tag childsParents) 328.4513 - (dissoc parentMap tag)) 328.4514 - deriv-seq (flatten (map #(cons (key %) (interpose (key %) (val %))) 328.4515 - (seq newParents)))] 328.4516 - (if (contains? (parentMap tag) parent) 328.4517 - (reduce #(apply derive %1 %2) (make-hierarchy) 328.4518 - (partition 2 deriv-seq)) 328.4519 - h)))) 328.4520 - 328.4521 - 328.4522 -(defn distinct? 328.4523 - "Returns true if no two of the arguments are =" 328.4524 - {:tag Boolean 328.4525 - :added "1.0"} 328.4526 - ([x] true) 328.4527 - ([x y] (not (= x y))) 328.4528 - ([x y & more] 328.4529 - (if (not= x y) 328.4530 - (loop [s #{x y} [x & etc :as xs] more] 328.4531 - (if xs 328.4532 - (if (contains? s x) 328.4533 - false 328.4534 - (recur (conj s x) etc)) 328.4535 - true)) 328.4536 - false))) 328.4537 - 328.4538 -(defn resultset-seq 328.4539 - "Creates and returns a lazy sequence of structmaps corresponding to 328.4540 - the rows in the java.sql.ResultSet rs" 328.4541 - {:added "1.0"} 328.4542 - [^java.sql.ResultSet rs] 328.4543 - (let [rsmeta (. rs (getMetaData)) 328.4544 - idxs (range 1 (inc (. rsmeta (getColumnCount)))) 328.4545 - keys (map (comp keyword #(.toLowerCase ^String %)) 328.4546 - (map (fn [i] (. rsmeta (getColumnLabel i))) idxs)) 328.4547 - check-keys 328.4548 - (or (apply distinct? keys) 328.4549 - (throw (Exception. "ResultSet must have unique column labels"))) 328.4550 - row-struct (apply create-struct keys) 328.4551 - row-values (fn [] (map (fn [^Integer i] (. rs (getObject i))) idxs)) 328.4552 - rows (fn thisfn [] 328.4553 - (when (. rs (next)) 328.4554 - (cons (apply struct row-struct (row-values)) (lazy-seq (thisfn)))))] 328.4555 - (rows))) 328.4556 - 328.4557 -(defn iterator-seq 328.4558 - "Returns a seq on a java.util.Iterator. Note that most collections 328.4559 - providing iterators implement Iterable and thus support seq directly." 328.4560 - {:added "1.0"} 328.4561 - [iter] 328.4562 - (clojure.lang.IteratorSeq/create iter)) 328.4563 - 328.4564 -(defn enumeration-seq 328.4565 - "Returns a seq on a java.util.Enumeration" 328.4566 - {:added "1.0"} 328.4567 - [e] 328.4568 - (clojure.lang.EnumerationSeq/create e)) 328.4569 - 328.4570 -(defn format 328.4571 - "Formats a string using java.lang.String.format, see java.util.Formatter for format 328.4572 - string syntax" 328.4573 - {:tag String 328.4574 - :added "1.0"} 328.4575 - [fmt & args] 328.4576 - (String/format fmt (to-array args))) 328.4577 - 328.4578 -(defn printf 328.4579 - "Prints formatted output, as per format" 328.4580 - {:added "1.0"} 328.4581 - [fmt & args] 328.4582 - (print (apply format fmt args))) 328.4583 - 328.4584 -(declare gen-class) 328.4585 - 328.4586 -(defmacro with-loading-context [& body] 328.4587 - `((fn loading# [] 328.4588 - (. clojure.lang.Var (pushThreadBindings {clojure.lang.Compiler/LOADER 328.4589 - (.getClassLoader (.getClass ^Object loading#))})) 328.4590 - (try 328.4591 - ~@body 328.4592 - (finally 328.4593 - (. clojure.lang.Var (popThreadBindings))))))) 328.4594 - 328.4595 -(defmacro ns 328.4596 - "Sets *ns* to the namespace named by name (unevaluated), creating it 328.4597 - if needed. references can be zero or more of: (:refer-clojure ...) 328.4598 - (:require ...) (:use ...) (:import ...) (:load ...) (:gen-class) 328.4599 - with the syntax of refer-clojure/require/use/import/load/gen-class 328.4600 - respectively, except the arguments are unevaluated and need not be 328.4601 - quoted. (:gen-class ...), when supplied, defaults to :name 328.4602 - corresponding to the ns name, :main true, :impl-ns same as ns, and 328.4603 - :init-impl-ns true. All options of gen-class are 328.4604 - supported. The :gen-class directive is ignored when not 328.4605 - compiling. If :gen-class is not supplied, when compiled only an 328.4606 - nsname__init.class will be generated. If :refer-clojure is not used, a 328.4607 - default (refer 'clojure) is used. Use of ns is preferred to 328.4608 - individual calls to in-ns/require/use/import: 328.4609 - 328.4610 - (ns foo.bar 328.4611 - (:refer-clojure :exclude [ancestors printf]) 328.4612 - (:require (clojure.contrib sql sql.tests)) 328.4613 - (:use (my.lib this that)) 328.4614 - (:import (java.util Date Timer Random) 328.4615 - (java.sql Connection Statement)))" 328.4616 - {:arglists '([name docstring? attr-map? references*]) 328.4617 - :added "1.0"} 328.4618 - [name & references] 328.4619 - (let [process-reference 328.4620 - (fn [[kname & args]] 328.4621 - `(~(symbol "clojure.core" (clojure.core/name kname)) 328.4622 - ~@(map #(list 'quote %) args))) 328.4623 - docstring (when (string? (first references)) (first references)) 328.4624 - references (if docstring (next references) references) 328.4625 - name (if docstring 328.4626 - (vary-meta name assoc :doc docstring) 328.4627 - name) 328.4628 - metadata (when (map? (first references)) (first references)) 328.4629 - references (if metadata (next references) references) 328.4630 - name (if metadata 328.4631 - (vary-meta name merge metadata) 328.4632 - name) 328.4633 - gen-class-clause (first (filter #(= :gen-class (first %)) references)) 328.4634 - gen-class-call 328.4635 - (when gen-class-clause 328.4636 - (list* `gen-class :name (.replace (str name) \- \_) :impl-ns name :main true (next gen-class-clause))) 328.4637 - references (remove #(= :gen-class (first %)) references) 328.4638 - ;ns-effect (clojure.core/in-ns name) 328.4639 - ] 328.4640 - `(do 328.4641 - (clojure.core/in-ns '~name) 328.4642 - (with-loading-context 328.4643 - ~@(when gen-class-call (list gen-class-call)) 328.4644 - ~@(when (and (not= name 'clojure.core) (not-any? #(= :refer-clojure (first %)) references)) 328.4645 - `((clojure.core/refer '~'clojure.core))) 328.4646 - ~@(map process-reference references))))) 328.4647 - 328.4648 -(defmacro refer-clojure 328.4649 - "Same as (refer 'clojure.core <filters>)" 328.4650 - {:added "1.0"} 328.4651 - [& filters] 328.4652 - `(clojure.core/refer '~'clojure.core ~@filters)) 328.4653 - 328.4654 -(defmacro defonce 328.4655 - "defs name to have the root value of the expr iff the named var has no root value, 328.4656 - else expr is unevaluated" 328.4657 - {:added "1.0"} 328.4658 - [name expr] 328.4659 - `(let [v# (def ~name)] 328.4660 - (when-not (.hasRoot v#) 328.4661 - (def ~name ~expr)))) 328.4662 - 328.4663 -;;;;;;;;;;; require/use/load, contributed by Stephen C. Gilardi ;;;;;;;;;;;;;;;;;; 328.4664 - 328.4665 -(defonce 328.4666 - ^{:private true 328.4667 - :doc "A ref to a sorted set of symbols representing loaded libs"} 328.4668 - *loaded-libs* (ref (sorted-set))) 328.4669 - 328.4670 -(defonce 328.4671 - ^{:private true 328.4672 - :doc "the set of paths currently being loaded by this thread"} 328.4673 - *pending-paths* #{}) 328.4674 - 328.4675 -(defonce 328.4676 - ^{:private true :doc 328.4677 - "True while a verbose load is pending"} 328.4678 - *loading-verbosely* false) 328.4679 - 328.4680 -(defn- throw-if 328.4681 - "Throws an exception with a message if pred is true" 328.4682 - [pred fmt & args] 328.4683 - (when pred 328.4684 - (let [^String message (apply format fmt args) 328.4685 - exception (Exception. message) 328.4686 - raw-trace (.getStackTrace exception) 328.4687 - boring? #(not= (.getMethodName ^StackTraceElement %) "doInvoke") 328.4688 - trace (into-array (drop 2 (drop-while boring? raw-trace)))] 328.4689 - (.setStackTrace exception trace) 328.4690 - (throw exception)))) 328.4691 - 328.4692 -(defn- libspec? 328.4693 - "Returns true if x is a libspec" 328.4694 - [x] 328.4695 - (or (symbol? x) 328.4696 - (and (vector? x) 328.4697 - (or 328.4698 - (nil? (second x)) 328.4699 - (keyword? (second x)))))) 328.4700 - 328.4701 -(defn- prependss 328.4702 - "Prepends a symbol or a seq to coll" 328.4703 - [x coll] 328.4704 - (if (symbol? x) 328.4705 - (cons x coll) 328.4706 - (concat x coll))) 328.4707 - 328.4708 -(defn- root-resource 328.4709 - "Returns the root directory path for a lib" 328.4710 - {:tag String} 328.4711 - [lib] 328.4712 - (str \/ 328.4713 - (.. (name lib) 328.4714 - (replace \- \_) 328.4715 - (replace \. \/)))) 328.4716 - 328.4717 -(defn- root-directory 328.4718 - "Returns the root resource path for a lib" 328.4719 - [lib] 328.4720 - (let [d (root-resource lib)] 328.4721 - (subs d 0 (.lastIndexOf d "/")))) 328.4722 - 328.4723 -(declare load) 328.4724 - 328.4725 -(defn- load-one 328.4726 - "Loads a lib given its name. If need-ns, ensures that the associated 328.4727 - namespace exists after loading. If require, records the load so any 328.4728 - duplicate loads can be skipped." 328.4729 - [lib need-ns require] 328.4730 - (load (root-resource lib)) 328.4731 - (throw-if (and need-ns (not (find-ns lib))) 328.4732 - "namespace '%s' not found after loading '%s'" 328.4733 - lib (root-resource lib)) 328.4734 - (when require 328.4735 - (dosync 328.4736 - (commute *loaded-libs* conj lib)))) 328.4737 - 328.4738 -(defn- load-all 328.4739 - "Loads a lib given its name and forces a load of any libs it directly or 328.4740 - indirectly loads. If need-ns, ensures that the associated namespace 328.4741 - exists after loading. If require, records the load so any duplicate loads 328.4742 - can be skipped." 328.4743 - [lib need-ns require] 328.4744 - (dosync 328.4745 - (commute *loaded-libs* #(reduce conj %1 %2) 328.4746 - (binding [*loaded-libs* (ref (sorted-set))] 328.4747 - (load-one lib need-ns require) 328.4748 - @*loaded-libs*)))) 328.4749 - 328.4750 -(defn- load-lib 328.4751 - "Loads a lib with options" 328.4752 - [prefix lib & options] 328.4753 - (throw-if (and prefix (pos? (.indexOf (name lib) (int \.)))) 328.4754 - "lib names inside prefix lists must not contain periods") 328.4755 - (let [lib (if prefix (symbol (str prefix \. lib)) lib) 328.4756 - opts (apply hash-map options) 328.4757 - {:keys [as reload reload-all require use verbose]} opts 328.4758 - loaded (contains? @*loaded-libs* lib) 328.4759 - load (cond reload-all 328.4760 - load-all 328.4761 - (or reload (not require) (not loaded)) 328.4762 - load-one) 328.4763 - need-ns (or as use) 328.4764 - filter-opts (select-keys opts '(:exclude :only :rename))] 328.4765 - (binding [*loading-verbosely* (or *loading-verbosely* verbose)] 328.4766 - (if load 328.4767 - (load lib need-ns require) 328.4768 - (throw-if (and need-ns (not (find-ns lib))) 328.4769 - "namespace '%s' not found" lib)) 328.4770 - (when (and need-ns *loading-verbosely*) 328.4771 - (printf "(clojure.core/in-ns '%s)\n" (ns-name *ns*))) 328.4772 - (when as 328.4773 - (when *loading-verbosely* 328.4774 - (printf "(clojure.core/alias '%s '%s)\n" as lib)) 328.4775 - (alias as lib)) 328.4776 - (when use 328.4777 - (when *loading-verbosely* 328.4778 - (printf "(clojure.core/refer '%s" lib) 328.4779 - (doseq [opt filter-opts] 328.4780 - (printf " %s '%s" (key opt) (print-str (val opt)))) 328.4781 - (printf ")\n")) 328.4782 - (apply refer lib (mapcat seq filter-opts)))))) 328.4783 - 328.4784 -(defn- load-libs 328.4785 - "Loads libs, interpreting libspecs, prefix lists, and flags for 328.4786 - forwarding to load-lib" 328.4787 - [& args] 328.4788 - (let [flags (filter keyword? args) 328.4789 - opts (interleave flags (repeat true)) 328.4790 - args (filter (complement keyword?) args)] 328.4791 - ; check for unsupported options 328.4792 - (let [supported #{:as :reload :reload-all :require :use :verbose} 328.4793 - unsupported (seq (remove supported flags))] 328.4794 - (throw-if unsupported 328.4795 - (apply str "Unsupported option(s) supplied: " 328.4796 - (interpose \, unsupported)))) 328.4797 - ; check a load target was specified 328.4798 - (throw-if (not (seq args)) "Nothing specified to load") 328.4799 - (doseq [arg args] 328.4800 - (if (libspec? arg) 328.4801 - (apply load-lib nil (prependss arg opts)) 328.4802 - (let [[prefix & args] arg] 328.4803 - (throw-if (nil? prefix) "prefix cannot be nil") 328.4804 - (doseq [arg args] 328.4805 - (apply load-lib prefix (prependss arg opts)))))))) 328.4806 - 328.4807 -;; Public 328.4808 - 328.4809 - 328.4810 -(defn require 328.4811 - "Loads libs, skipping any that are already loaded. Each argument is 328.4812 - either a libspec that identifies a lib, a prefix list that identifies 328.4813 - multiple libs whose names share a common prefix, or a flag that modifies 328.4814 - how all the identified libs are loaded. Use :require in the ns macro 328.4815 - in preference to calling this directly. 328.4816 - 328.4817 - Libs 328.4818 - 328.4819 - A 'lib' is a named set of resources in classpath whose contents define a 328.4820 - library of Clojure code. Lib names are symbols and each lib is associated 328.4821 - with a Clojure namespace and a Java package that share its name. A lib's 328.4822 - name also locates its root directory within classpath using Java's 328.4823 - package name to classpath-relative path mapping. All resources in a lib 328.4824 - should be contained in the directory structure under its root directory. 328.4825 - All definitions a lib makes should be in its associated namespace. 328.4826 - 328.4827 - 'require loads a lib by loading its root resource. The root resource path 328.4828 - is derived from the lib name in the following manner: 328.4829 - Consider a lib named by the symbol 'x.y.z; it has the root directory 328.4830 - <classpath>/x/y/, and its root resource is <classpath>/x/y/z.clj. The root 328.4831 - resource should contain code to create the lib's namespace (usually by using 328.4832 - the ns macro) and load any additional lib resources. 328.4833 - 328.4834 - Libspecs 328.4835 - 328.4836 - A libspec is a lib name or a vector containing a lib name followed by 328.4837 - options expressed as sequential keywords and arguments. 328.4838 - 328.4839 - Recognized options: :as 328.4840 - :as takes a symbol as its argument and makes that symbol an alias to the 328.4841 - lib's namespace in the current namespace. 328.4842 - 328.4843 - Prefix Lists 328.4844 - 328.4845 - It's common for Clojure code to depend on several libs whose names have 328.4846 - the same prefix. When specifying libs, prefix lists can be used to reduce 328.4847 - repetition. A prefix list contains the shared prefix followed by libspecs 328.4848 - with the shared prefix removed from the lib names. After removing the 328.4849 - prefix, the names that remain must not contain any periods. 328.4850 - 328.4851 - Flags 328.4852 - 328.4853 - A flag is a keyword. 328.4854 - Recognized flags: :reload, :reload-all, :verbose 328.4855 - :reload forces loading of all the identified libs even if they are 328.4856 - already loaded 328.4857 - :reload-all implies :reload and also forces loading of all libs that the 328.4858 - identified libs directly or indirectly load via require or use 328.4859 - :verbose triggers printing information about each load, alias, and refer 328.4860 - 328.4861 - Example: 328.4862 - 328.4863 - The following would load the libraries clojure.zip and clojure.set 328.4864 - abbreviated as 's'. 328.4865 - 328.4866 - (require '(clojure zip [set :as s]))" 328.4867 - {:added "1.0"} 328.4868 - 328.4869 - [& args] 328.4870 - (apply load-libs :require args)) 328.4871 - 328.4872 -(defn use 328.4873 - "Like 'require, but also refers to each lib's namespace using 328.4874 - clojure.core/refer. Use :use in the ns macro in preference to calling 328.4875 - this directly. 328.4876 - 328.4877 - 'use accepts additional options in libspecs: :exclude, :only, :rename. 328.4878 - The arguments and semantics for :exclude, :only, and :rename are the same 328.4879 - as those documented for clojure.core/refer." 328.4880 - {:added "1.0"} 328.4881 - [& args] (apply load-libs :require :use args)) 328.4882 - 328.4883 -(defn loaded-libs 328.4884 - "Returns a sorted set of symbols naming the currently loaded libs" 328.4885 - {:added "1.0"} 328.4886 - [] @*loaded-libs*) 328.4887 - 328.4888 -(defn load 328.4889 - "Loads Clojure code from resources in classpath. A path is interpreted as 328.4890 - classpath-relative if it begins with a slash or relative to the root 328.4891 - directory for the current namespace otherwise." 328.4892 - {:added "1.0"} 328.4893 - [& paths] 328.4894 - (doseq [^String path paths] 328.4895 - (let [^String path (if (.startsWith path "/") 328.4896 - path 328.4897 - (str (root-directory (ns-name *ns*)) \/ path))] 328.4898 - (when *loading-verbosely* 328.4899 - (printf "(clojure.core/load \"%s\")\n" path) 328.4900 - (flush)) 328.4901 -; (throw-if (*pending-paths* path) 328.4902 -; "cannot load '%s' again while it is loading" 328.4903 -; path) 328.4904 - (when-not (*pending-paths* path) 328.4905 - (binding [*pending-paths* (conj *pending-paths* path)] 328.4906 - (clojure.lang.RT/load (.substring path 1))))))) 328.4907 - 328.4908 -(defn compile 328.4909 - "Compiles the namespace named by the symbol lib into a set of 328.4910 - classfiles. The source for the lib must be in a proper 328.4911 - classpath-relative directory. The output files will go into the 328.4912 - directory specified by *compile-path*, and that directory too must 328.4913 - be in the classpath." 328.4914 - {:added "1.0"} 328.4915 - [lib] 328.4916 - (binding [*compile-files* true] 328.4917 - (load-one lib true true)) 328.4918 - lib) 328.4919 - 328.4920 -;;;;;;;;;;;;; nested associative ops ;;;;;;;;;;; 328.4921 - 328.4922 -(defn get-in 328.4923 - "Returns the value in a nested associative structure, 328.4924 - where ks is a sequence of ke(ys. Returns nil if the key is not present, 328.4925 - or the not-found value if supplied." 328.4926 - {:added "1.2"} 328.4927 - ([m ks] 328.4928 - (reduce get m ks)) 328.4929 - ([m ks not-found] 328.4930 - (loop [sentinel (Object.) 328.4931 - m m 328.4932 - ks (seq ks)] 328.4933 - (if ks 328.4934 - (let [m (get m (first ks) sentinel)] 328.4935 - (if (identical? sentinel m) 328.4936 - not-found 328.4937 - (recur sentinel m (next ks)))) 328.4938 - m)))) 328.4939 - 328.4940 -(defn assoc-in 328.4941 - "Associates a value in a nested associative structure, where ks is a 328.4942 - sequence of keys and v is the new value and returns a new nested structure. 328.4943 - If any levels do not exist, hash-maps will be created." 328.4944 - {:added "1.0"} 328.4945 - [m [k & ks] v] 328.4946 - (if ks 328.4947 - (assoc m k (assoc-in (get m k) ks v)) 328.4948 - (assoc m k v))) 328.4949 - 328.4950 -(defn update-in 328.4951 - "'Updates' a value in a nested associative structure, where ks is a 328.4952 - sequence of keys and f is a function that will take the old value 328.4953 - and any supplied args and return the new value, and returns a new 328.4954 - nested structure. If any levels do not exist, hash-maps will be 328.4955 - created." 328.4956 - {:added "1.0"} 328.4957 - ([m [k & ks] f & args] 328.4958 - (if ks 328.4959 - (assoc m k (apply update-in (get m k) ks f args)) 328.4960 - (assoc m k (apply f (get m k) args))))) 328.4961 - 328.4962 - 328.4963 -(defn empty? 328.4964 - "Returns true if coll has no items - same as (not (seq coll)). 328.4965 - Please use the idiom (seq x) rather than (not (empty? x))" 328.4966 - {:added "1.0"} 328.4967 - [coll] (not (seq coll))) 328.4968 - 328.4969 -(defn coll? 328.4970 - "Returns true if x implements IPersistentCollection" 328.4971 - {:added "1.0"} 328.4972 - [x] (instance? clojure.lang.IPersistentCollection x)) 328.4973 - 328.4974 -(defn list? 328.4975 - "Returns true if x implements IPersistentList" 328.4976 - {:added "1.0"} 328.4977 - [x] (instance? clojure.lang.IPersistentList x)) 328.4978 - 328.4979 -(defn set? 328.4980 - "Returns true if x implements IPersistentSet" 328.4981 - {:added "1.0"} 328.4982 - [x] (instance? clojure.lang.IPersistentSet x)) 328.4983 - 328.4984 -(defn ifn? 328.4985 - "Returns true if x implements IFn. Note that many data structures 328.4986 - (e.g. sets and maps) implement IFn" 328.4987 - {:added "1.0"} 328.4988 - [x] (instance? clojure.lang.IFn x)) 328.4989 - 328.4990 -(defn fn? 328.4991 - "Returns true if x implements Fn, i.e. is an object created via fn." 328.4992 - {:added "1.0"} 328.4993 - [x] (instance? clojure.lang.Fn x)) 328.4994 - 328.4995 - 328.4996 -(defn associative? 328.4997 - "Returns true if coll implements Associative" 328.4998 - {:added "1.0"} 328.4999 - [coll] (instance? clojure.lang.Associative coll)) 328.5000 - 328.5001 -(defn sequential? 328.5002 - "Returns true if coll implements Sequential" 328.5003 - {:added "1.0"} 328.5004 - [coll] (instance? clojure.lang.Sequential coll)) 328.5005 - 328.5006 -(defn sorted? 328.5007 - "Returns true if coll implements Sorted" 328.5008 - {:added "1.0"} 328.5009 - [coll] (instance? clojure.lang.Sorted coll)) 328.5010 - 328.5011 -(defn counted? 328.5012 - "Returns true if coll implements count in constant time" 328.5013 - {:added "1.0"} 328.5014 - [coll] (instance? clojure.lang.Counted coll)) 328.5015 - 328.5016 -(defn reversible? 328.5017 - "Returns true if coll implements Reversible" 328.5018 - {:added "1.0"} 328.5019 - [coll] (instance? clojure.lang.Reversible coll)) 328.5020 - 328.5021 -(def 328.5022 - ^{:doc "bound in a repl thread to the most recent value printed" 328.5023 - :added "1.0"} 328.5024 - *1) 328.5025 - 328.5026 -(def 328.5027 - ^{:doc "bound in a repl thread to the second most recent value printed" 328.5028 - :added "1.0"} 328.5029 - *2) 328.5030 - 328.5031 -(def 328.5032 - ^{:doc "bound in a repl thread to the third most recent value printed" 328.5033 - :added "1.0"} 328.5034 - *3) 328.5035 - 328.5036 -(def 328.5037 - ^{:doc "bound in a repl thread to the most recent exception caught by the repl" 328.5038 - :added "1.0"} 328.5039 - *e) 328.5040 - 328.5041 -(defn trampoline 328.5042 - "trampoline can be used to convert algorithms requiring mutual 328.5043 - recursion without stack consumption. Calls f with supplied args, if 328.5044 - any. If f returns a fn, calls that fn with no arguments, and 328.5045 - continues to repeat, until the return value is not a fn, then 328.5046 - returns that non-fn value. Note that if you want to return a fn as a 328.5047 - final value, you must wrap it in some data structure and unpack it 328.5048 - after trampoline returns." 328.5049 - {:added "1.0"} 328.5050 - ([f] 328.5051 - (let [ret (f)] 328.5052 - (if (fn? ret) 328.5053 - (recur ret) 328.5054 - ret))) 328.5055 - ([f & args] 328.5056 - (trampoline #(apply f args)))) 328.5057 - 328.5058 -(defn intern 328.5059 - "Finds or creates a var named by the symbol name in the namespace 328.5060 - ns (which can be a symbol or a namespace), setting its root binding 328.5061 - to val if supplied. The namespace must exist. The var will adopt any 328.5062 - metadata from the name symbol. Returns the var." 328.5063 - {:added "1.0"} 328.5064 - ([ns ^clojure.lang.Symbol name] 328.5065 - (let [v (clojure.lang.Var/intern (the-ns ns) name)] 328.5066 - (when (meta name) (.setMeta v (meta name))) 328.5067 - v)) 328.5068 - ([ns name val] 328.5069 - (let [v (clojure.lang.Var/intern (the-ns ns) name val)] 328.5070 - (when (meta name) (.setMeta v (meta name))) 328.5071 - v))) 328.5072 - 328.5073 -(defmacro while 328.5074 - "Repeatedly executes body while test expression is true. Presumes 328.5075 - some side-effect will cause test to become false/nil. Returns nil" 328.5076 - {:added "1.0"} 328.5077 - [test & body] 328.5078 - `(loop [] 328.5079 - (when ~test 328.5080 - ~@body 328.5081 - (recur)))) 328.5082 - 328.5083 -(defn memoize 328.5084 - "Returns a memoized version of a referentially transparent function. The 328.5085 - memoized version of the function keeps a cache of the mapping from arguments 328.5086 - to results and, when calls with the same arguments are repeated often, has 328.5087 - higher performance at the expense of higher memory use." 328.5088 - {:added "1.0"} 328.5089 - [f] 328.5090 - (let [mem (atom {})] 328.5091 - (fn [& args] 328.5092 - (if-let [e (find @mem args)] 328.5093 - (val e) 328.5094 - (let [ret (apply f args)] 328.5095 - (swap! mem assoc args ret) 328.5096 - ret))))) 328.5097 - 328.5098 -(defmacro condp 328.5099 - "Takes a binary predicate, an expression, and a set of clauses. 328.5100 - Each clause can take the form of either: 328.5101 - 328.5102 - test-expr result-expr 328.5103 - 328.5104 - test-expr :>> result-fn 328.5105 - 328.5106 - Note :>> is an ordinary keyword. 328.5107 - 328.5108 - For each clause, (pred test-expr expr) is evaluated. If it returns 328.5109 - logical true, the clause is a match. If a binary clause matches, the 328.5110 - result-expr is returned, if a ternary clause matches, its result-fn, 328.5111 - which must be a unary function, is called with the result of the 328.5112 - predicate as its argument, the result of that call being the return 328.5113 - value of condp. A single default expression can follow the clauses, 328.5114 - and its value will be returned if no clause matches. If no default 328.5115 - expression is provided and no clause matches, an 328.5116 - IllegalArgumentException is thrown." 328.5117 - {:added "1.0"} 328.5118 - 328.5119 - [pred expr & clauses] 328.5120 - (let [gpred (gensym "pred__") 328.5121 - gexpr (gensym "expr__") 328.5122 - emit (fn emit [pred expr args] 328.5123 - (let [[[a b c :as clause] more] 328.5124 - (split-at (if (= :>> (second args)) 3 2) args) 328.5125 - n (count clause)] 328.5126 - (cond 328.5127 - (= 0 n) `(throw (IllegalArgumentException. (str "No matching clause: " ~expr))) 328.5128 - (= 1 n) a 328.5129 - (= 2 n) `(if (~pred ~a ~expr) 328.5130 - ~b 328.5131 - ~(emit pred expr more)) 328.5132 - :else `(if-let [p# (~pred ~a ~expr)] 328.5133 - (~c p#) 328.5134 - ~(emit pred expr more))))) 328.5135 - gres (gensym "res__")] 328.5136 - `(let [~gpred ~pred 328.5137 - ~gexpr ~expr] 328.5138 - ~(emit gpred gexpr clauses)))) 328.5139 - 328.5140 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; var documentation ;;;;;;;;;;;;;;;;;;;;;;;;;; 328.5141 - 328.5142 -(alter-meta! #'*agent* assoc :added "1.0") 328.5143 -(alter-meta! #'in-ns assoc :added "1.0") 328.5144 -(alter-meta! #'load-file assoc :added "1.0") 328.5145 - 328.5146 -(defmacro add-doc-and-meta {:private true} [name docstring meta] 328.5147 - `(alter-meta! (var ~name) merge (assoc ~meta :doc ~docstring))) 328.5148 - 328.5149 -(add-doc-and-meta *file* 328.5150 - "The path of the file being evaluated, as a String. 328.5151 - 328.5152 - Evaluates to nil when there is no file, eg. in the REPL." 328.5153 - {:added "1.0"}) 328.5154 - 328.5155 -(add-doc-and-meta *command-line-args* 328.5156 - "A sequence of the supplied command line arguments, or nil if 328.5157 - none were supplied" 328.5158 - {:added "1.0"}) 328.5159 - 328.5160 -(add-doc-and-meta *warn-on-reflection* 328.5161 - "When set to true, the compiler will emit warnings when reflection is 328.5162 - needed to resolve Java method calls or field accesses. 328.5163 - 328.5164 - Defaults to false." 328.5165 - {:added "1.0"}) 328.5166 - 328.5167 -(add-doc-and-meta *compile-path* 328.5168 - "Specifies the directory where 'compile' will write out .class 328.5169 - files. This directory must be in the classpath for 'compile' to 328.5170 - work. 328.5171 - 328.5172 - Defaults to \"classes\"" 328.5173 - {:added "1.0"}) 328.5174 - 328.5175 -(add-doc-and-meta *compile-files* 328.5176 - "Set to true when compiling files, false otherwise." 328.5177 - {:added "1.0"}) 328.5178 - 328.5179 -(add-doc-and-meta *ns* 328.5180 - "A clojure.lang.Namespace object representing the current namespace." 328.5181 - {:added "1.0"}) 328.5182 - 328.5183 -(add-doc-and-meta *in* 328.5184 - "A java.io.Reader object representing standard input for read operations. 328.5185 - 328.5186 - Defaults to System/in, wrapped in a LineNumberingPushbackReader" 328.5187 - {:added "1.0"}) 328.5188 - 328.5189 -(add-doc-and-meta *out* 328.5190 - "A java.io.Writer object representing standard output for print operations. 328.5191 - 328.5192 - Defaults to System/out" 328.5193 - {:added "1.0"}) 328.5194 - 328.5195 -(add-doc-and-meta *err* 328.5196 - "A java.io.Writer object representing standard error for print operations. 328.5197 - 328.5198 - Defaults to System/err, wrapped in a PrintWriter" 328.5199 - {:added "1.0"}) 328.5200 - 328.5201 -(add-doc-and-meta *flush-on-newline* 328.5202 - "When set to true, output will be flushed whenever a newline is printed. 328.5203 - 328.5204 - Defaults to true." 328.5205 - {:added "1.0"}) 328.5206 - 328.5207 -(add-doc-and-meta *print-meta* 328.5208 - "If set to logical true, when printing an object, its metadata will also 328.5209 - be printed in a form that can be read back by the reader. 328.5210 - 328.5211 - Defaults to false." 328.5212 - {:added "1.0"}) 328.5213 - 328.5214 -(add-doc-and-meta *print-dup* 328.5215 - "When set to logical true, objects will be printed in a way that preserves 328.5216 - their type when read in later. 328.5217 - 328.5218 - Defaults to false." 328.5219 - {:added "1.0"}) 328.5220 - 328.5221 -(add-doc-and-meta *print-readably* 328.5222 - "When set to logical false, strings and characters will be printed with 328.5223 - non-alphanumeric characters converted to the appropriate escape sequences. 328.5224 - 328.5225 - Defaults to true" 328.5226 - {:added "1.0"}) 328.5227 - 328.5228 -(add-doc-and-meta *read-eval* 328.5229 - "When set to logical false, the EvalReader (#=(...)) is disabled in the 328.5230 - read/load in the thread-local binding. 328.5231 - Example: (binding [*read-eval* false] (read-string \"#=(eval (def x 3))\")) 328.5232 - 328.5233 - Defaults to true" 328.5234 - {:added "1.0"}) 328.5235 - 328.5236 -(defn future? 328.5237 - "Returns true if x is a future" 328.5238 - {:added "1.1"} 328.5239 - [x] (instance? java.util.concurrent.Future x)) 328.5240 - 328.5241 -(defn future-done? 328.5242 - "Returns true if future f is done" 328.5243 - {:added "1.1"} 328.5244 - [^java.util.concurrent.Future f] (.isDone f)) 328.5245 - 328.5246 - 328.5247 -(defmacro letfn 328.5248 - "Takes a vector of function specs and a body, and generates a set of 328.5249 - bindings of functions to their names. All of the names are available 328.5250 - in all of the definitions of the functions, as well as the body. 328.5251 - 328.5252 - fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)" 328.5253 - {:added "1.0"} 328.5254 - [fnspecs & body] 328.5255 - `(letfn* ~(vec (interleave (map first fnspecs) 328.5256 - (map #(cons `fn %) fnspecs))) 328.5257 - ~@body)) 328.5258 - 328.5259 - 328.5260 -;;;;;;; case ;;;;;;;;;;;;; 328.5261 -(defn- shift-mask [shift mask x] 328.5262 - (-> x (bit-shift-right shift) (bit-and mask))) 328.5263 - 328.5264 -(defn- min-hash 328.5265 - "takes a collection of keys and returns [shift mask]" 328.5266 - [keys] 328.5267 - (let [hashes (map hash keys) 328.5268 - cnt (count keys)] 328.5269 - (when-not (apply distinct? hashes) 328.5270 - (throw (IllegalArgumentException. "Hashes must be distinct"))) 328.5271 - (or (first 328.5272 - (filter (fn [[s m]] 328.5273 - (apply distinct? (map #(shift-mask s m %) hashes))) 328.5274 - (for [mask (map #(dec (bit-shift-left 1 %)) (range 1 14)) 328.5275 - shift (range 0 31)] 328.5276 - [shift mask]))) 328.5277 - (throw (IllegalArgumentException. "No distinct mapping found"))))) 328.5278 - 328.5279 -(defmacro case 328.5280 - "Takes an expression, and a set of clauses. 328.5281 - 328.5282 - Each clause can take the form of either: 328.5283 - 328.5284 - test-constant result-expr 328.5285 - 328.5286 - (test-constant1 ... test-constantN) result-expr 328.5287 - 328.5288 - The test-constants are not evaluated. They must be compile-time 328.5289 - literals, and need not be quoted. If the expression is equal to a 328.5290 - test-constant, the corresponding result-expr is returned. A single 328.5291 - default expression can follow the clauses, and its value will be 328.5292 - returned if no clause matches. If no default expression is provided 328.5293 - and no clause matches, an IllegalArgumentException is thrown. 328.5294 - 328.5295 - Unlike cond and condp, case does a constant-time dispatch, the 328.5296 - clauses are not considered sequentially. All manner of constant 328.5297 - expressions are acceptable in case, including numbers, strings, 328.5298 - symbols, keywords, and (Clojure) composites thereof. Note that since 328.5299 - lists are used to group multiple constants that map to the same 328.5300 - expression, a vector can be used to match a list if needed. The 328.5301 - test-constants need not be all of the same type." 328.5302 - {:added "1.2"} 328.5303 - 328.5304 - [e & clauses] 328.5305 - (let [ge (with-meta (gensym) {:tag Object}) 328.5306 - default (if (odd? (count clauses)) 328.5307 - (last clauses) 328.5308 - `(throw (IllegalArgumentException. (str "No matching clause: " ~ge)))) 328.5309 - cases (partition 2 clauses) 328.5310 - case-map (reduce (fn [m [test expr]] 328.5311 - (if (seq? test) 328.5312 - (into m (zipmap test (repeat expr))) 328.5313 - (assoc m test expr))) 328.5314 - {} cases) 328.5315 - [shift mask] (if (seq case-map) (min-hash (keys case-map)) [0 0]) 328.5316 - 328.5317 - hmap (reduce (fn [m [test expr :as te]] 328.5318 - (assoc m (shift-mask shift mask (hash test)) te)) 328.5319 - (sorted-map) case-map)] 328.5320 - `(let [~ge ~e] 328.5321 - ~(condp = (count clauses) 328.5322 - 0 default 328.5323 - 1 default 328.5324 - `(case* ~ge ~shift ~mask ~(key (first hmap)) ~(key (last hmap)) ~default ~hmap 328.5325 - ~(every? keyword? (keys case-map))))))) 328.5326 - 328.5327 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; helper files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 328.5328 -(alter-meta! (find-ns 'clojure.core) assoc :doc "Fundamental library of the Clojure language") 328.5329 -(load "core_proxy") 328.5330 -(load "core_print") 328.5331 -(load "genclass") 328.5332 -(load "core_deftype") 328.5333 -(load "core/protocols") 328.5334 -(load "gvec") 328.5335 - 328.5336 -;; redefine reduce with internal-reduce 328.5337 -#_(defn reduce 328.5338 - "f should be a function of 2 arguments. If val is not supplied, 328.5339 - returns the result of applying f to the first 2 items in coll, then 328.5340 - applying f to that result and the 3rd item, etc. If coll contains no 328.5341 - items, f must accept no arguments as well, and reduce returns the 328.5342 - result of calling f with no arguments. If coll has only 1 item, it 328.5343 - is returned and f is not called. If val is supplied, returns the 328.5344 - result of applying f to val and the first item in coll, then 328.5345 - applying f to that result and the 2nd item, etc. If coll contains no 328.5346 - items, returns val and f is not called." 328.5347 - {:added "1.0"} 328.5348 - ([f coll] 328.5349 - (if-let [s (seq coll)] 328.5350 - (reduce f (first s) (next s)) 328.5351 - (f))) 328.5352 - ([f val coll] 328.5353 - (let [s (seq coll)] 328.5354 - (clojure.core.protocols/internal-reduce s f val)))) 328.5355 - 328.5356 -(require '[clojure.java.io :as jio]) 328.5357 - 328.5358 -(defn- normalize-slurp-opts 328.5359 - [opts] 328.5360 - (if (string? (first opts)) 328.5361 - (do 328.5362 - (println "WARNING: (slurp f enc) is deprecated, use (slurp f :encoding enc).") 328.5363 - [:encoding (first opts)]) 328.5364 - opts)) 328.5365 - 328.5366 -(defn slurp 328.5367 - "Reads the file named by f using the encoding enc into a string 328.5368 - and returns it." 328.5369 - {:added "1.0"} 328.5370 - ([f & opts] 328.5371 - (let [opts (normalize-slurp-opts opts) 328.5372 - sb (StringBuilder.)] 328.5373 - (with-open [#^java.io.Reader r (apply jio/reader f opts)] 328.5374 - (loop [c (.read r)] 328.5375 - (if (neg? c) 328.5376 - (str sb) 328.5377 - (do 328.5378 - (.append sb (char c)) 328.5379 - (recur (.read r))))))))) 328.5380 - 328.5381 -(defn spit 328.5382 - "Opposite of slurp. Opens f with writer, writes content, then 328.5383 - closes f. Options passed to clojure.java.io/writer." 328.5384 - {:added "1.2"} 328.5385 - [f content & options] 328.5386 - (with-open [#^java.io.Writer w (apply jio/writer f options)] 328.5387 - (.write w (str content)))) 328.5388 - 328.5389 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; futures (needs proxy);;;;;;;;;;;;;;;;;; 328.5390 -(defn future-call 328.5391 - "Takes a function of no args and yields a future object that will 328.5392 - invoke the function in another thread, and will cache the result and 328.5393 - return it on all subsequent calls to deref/@. If the computation has 328.5394 - not yet finished, calls to deref/@ will block." 328.5395 - {:added "1.1"} 328.5396 - [^Callable f] 328.5397 - (let [fut (.submit clojure.lang.Agent/soloExecutor f)] 328.5398 - (reify 328.5399 - clojure.lang.IDeref 328.5400 - (deref [_] (.get fut)) 328.5401 - java.util.concurrent.Future 328.5402 - (get [_] (.get fut)) 328.5403 - (get [_ timeout unit] (.get fut timeout unit)) 328.5404 - (isCancelled [_] (.isCancelled fut)) 328.5405 - (isDone [_] (.isDone fut)) 328.5406 - (cancel [_ interrupt?] (.cancel fut interrupt?))))) 328.5407 - 328.5408 -(defmacro future 328.5409 - "Takes a body of expressions and yields a future object that will 328.5410 - invoke the body in another thread, and will cache the result and 328.5411 - return it on all subsequent calls to deref/@. If the computation has 328.5412 - not yet finished, calls to deref/@ will block." 328.5413 - {:added "1.1"} 328.5414 - [& body] `(future-call (^{:once true} fn* [] ~@body))) 328.5415 - 328.5416 - 328.5417 -(defn future-cancel 328.5418 - "Cancels the future, if possible." 328.5419 - {:added "1.1"} 328.5420 - [^java.util.concurrent.Future f] (.cancel f true)) 328.5421 - 328.5422 -(defn future-cancelled? 328.5423 - "Returns true if future f is cancelled" 328.5424 - {:added "1.1"} 328.5425 - [^java.util.concurrent.Future f] (.isCancelled f)) 328.5426 - 328.5427 -(defn pmap 328.5428 - "Like map, except f is applied in parallel. Semi-lazy in that the 328.5429 - parallel computation stays ahead of the consumption, but doesn't 328.5430 - realize the entire result unless required. Only useful for 328.5431 - computationally intensive functions where the time of f dominates 328.5432 - the coordination overhead." 328.5433 - {:added "1.0"} 328.5434 - ([f coll] 328.5435 - (let [n (+ 2 (.. Runtime getRuntime availableProcessors)) 328.5436 - rets (map #(future (f %)) coll) 328.5437 - step (fn step [[x & xs :as vs] fs] 328.5438 - (lazy-seq 328.5439 - (if-let [s (seq fs)] 328.5440 - (cons (deref x) (step xs (rest s))) 328.5441 - (map deref vs))))] 328.5442 - (step rets (drop n rets)))) 328.5443 - ([f coll & colls] 328.5444 - (let [step (fn step [cs] 328.5445 - (lazy-seq 328.5446 - (let [ss (map seq cs)] 328.5447 - (when (every? identity ss) 328.5448 - (cons (map first ss) (step (map rest ss)))))))] 328.5449 - (pmap #(apply f %) (step (cons coll colls)))))) 328.5450 - 328.5451 -(defn pcalls 328.5452 - "Executes the no-arg fns in parallel, returning a lazy sequence of 328.5453 - their values" 328.5454 - {:added "1.0"} 328.5455 - [& fns] (pmap #(%) fns)) 328.5456 - 328.5457 -(defmacro pvalues 328.5458 - "Returns a lazy sequence of the values of the exprs, which are 328.5459 - evaluated in parallel" 328.5460 - {:added "1.0"} 328.5461 - [& exprs] 328.5462 - `(pcalls ~@(map #(list `fn [] %) exprs))) 328.5463 - 328.5464 - 328.5465 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; clojure version number ;;;;;;;;;;;;;;;;;;;;;; 328.5466 - 328.5467 -(let [version-stream (.getResourceAsStream (clojure.lang.RT/baseLoader) 328.5468 - "clojure/version.properties") 328.5469 - properties (doto (new java.util.Properties) (.load version-stream)) 328.5470 - prop (fn [k] (.getProperty properties (str "clojure.version." k))) 328.5471 - clojure-version {:major (Integer/valueOf ^String (prop "major")) 328.5472 - :minor (Integer/valueOf ^String (prop "minor")) 328.5473 - :incremental (Integer/valueOf ^String (prop "incremental")) 328.5474 - :qualifier (prop "qualifier")}] 328.5475 - (def *clojure-version* 328.5476 - (if (not (= (prop "interim") "false")) 328.5477 - (clojure.lang.RT/assoc clojure-version :interim true) 328.5478 - clojure-version))) 328.5479 - 328.5480 -(add-doc-and-meta *clojure-version* 328.5481 - "The version info for Clojure core, as a map containing :major :minor 328.5482 - :incremental and :qualifier keys. Feature releases may increment 328.5483 - :minor and/or :major, bugfix releases will increment :incremental. 328.5484 - Possible values of :qualifier include \"GA\", \"SNAPSHOT\", \"RC-x\" \"BETA-x\"" 328.5485 - {:added "1.0"}) 328.5486 - 328.5487 -(defn 328.5488 - clojure-version 328.5489 - "Returns clojure version as a printable string." 328.5490 - {:added "1.0"} 328.5491 - [] 328.5492 - (str (:major *clojure-version*) 328.5493 - "." 328.5494 - (:minor *clojure-version*) 328.5495 - (when-let [i (:incremental *clojure-version*)] 328.5496 - (str "." i)) 328.5497 - (when-let [q (:qualifier *clojure-version*)] 328.5498 - (when (pos? (count q)) (str "-" q))) 328.5499 - (when (:interim *clojure-version*) 328.5500 - "-SNAPSHOT"))) 328.5501 - 328.5502 -(defn promise 328.5503 - "Alpha - subject to change. 328.5504 - Returns a promise object that can be read with deref/@, and set, 328.5505 - once only, with deliver. Calls to deref/@ prior to delivery will 328.5506 - block. All subsequent derefs will return the same delivered value 328.5507 - without blocking." 328.5508 - {:added "1.1"} 328.5509 - [] 328.5510 - (let [d (java.util.concurrent.CountDownLatch. 1) 328.5511 - v (atom nil)] 328.5512 - (reify 328.5513 - clojure.lang.IDeref 328.5514 - (deref [_] (.await d) @v) 328.5515 - clojure.lang.IFn 328.5516 - (invoke [this x] 328.5517 - (locking d 328.5518 - (if (pos? (.getCount d)) 328.5519 - (do (reset! v x) 328.5520 - (.countDown d) 328.5521 - this) 328.5522 - (throw (IllegalStateException. "Multiple deliver calls to a promise")))))))) 328.5523 - 328.5524 -(defn deliver 328.5525 - "Alpha - subject to change. 328.5526 - Delivers the supplied value to the promise, releasing any pending 328.5527 - derefs. A subsequent call to deliver on a promise will throw an exception." 328.5528 - {:added "1.1"} 328.5529 - [promise val] (promise val)) 328.5530 - 328.5531 - 328.5532 - 328.5533 -(defn flatten 328.5534 - "Takes any nested combination of sequential things (lists, vectors, 328.5535 - etc.) and returns their contents as a single, flat sequence. 328.5536 - (flatten nil) returns nil." 328.5537 - {:added "1.2"} 328.5538 - [x] 328.5539 - (filter (complement sequential?) 328.5540 - (rest (tree-seq sequential? seq x)))) 328.5541 - 328.5542 -(defn group-by 328.5543 - "Returns a map of the elements of coll keyed by the result of 328.5544 - f on each element. The value at each key will be a vector of the 328.5545 - corresponding elements, in the order they appeared in coll." 328.5546 - {:added "1.2"} 328.5547 - [f coll] 328.5548 - (persistent! 328.5549 - (reduce 328.5550 - (fn [ret x] 328.5551 - (let [k (f x)] 328.5552 - (assoc! ret k (conj (get ret k []) x)))) 328.5553 - (transient {}) coll))) 328.5554 - 328.5555 -(defn partition-by 328.5556 - "Applies f to each value in coll, splitting it each time f returns 328.5557 - a new value. Returns a lazy seq of partitions." 328.5558 - {:added "1.2"} 328.5559 - [f coll] 328.5560 - (lazy-seq 328.5561 - (when-let [s (seq coll)] 328.5562 - (let [fst (first s) 328.5563 - fv (f fst) 328.5564 - run (cons fst (take-while #(= fv (f %)) (rest s)))] 328.5565 - (cons run (partition-by f (drop (count run) s))))))) 328.5566 - 328.5567 -(defn frequencies 328.5568 - "Returns a map from distinct items in coll to the number of times 328.5569 - they appear." 328.5570 - {:added "1.2"} 328.5571 - [coll] 328.5572 - (persistent! 328.5573 - (reduce (fn [counts x] 328.5574 - (assoc! counts x (inc (get counts x 0)))) 328.5575 - (transient {}) coll))) 328.5576 - 328.5577 -(defn reductions 328.5578 - "Returns a lazy seq of the intermediate values of the reduction (as 328.5579 - per reduce) of coll by f, starting with init." 328.5580 - {:added "1.2"} 328.5581 - ([f coll] 328.5582 - (lazy-seq 328.5583 - (if-let [s (seq coll)] 328.5584 - (reductions f (first s) (rest s)) 328.5585 - (list (f))))) 328.5586 - ([f init coll] 328.5587 - (cons init 328.5588 - (lazy-seq 328.5589 - (when-let [s (seq coll)] 328.5590 - (reductions f (f init (first s)) (rest s))))))) 328.5591 - 328.5592 -(defn rand-nth 328.5593 - "Return a random element of the (sequential) collection. Will have 328.5594 - the same performance characteristics as nth for the given 328.5595 - collection." 328.5596 - {:added "1.2"} 328.5597 - [coll] 328.5598 - (nth coll (rand-int (count coll)))) 328.5599 - 328.5600 -(defn partition-all 328.5601 - "Returns a lazy sequence of lists like partition, but may include 328.5602 - partitions with fewer than n items at the end." 328.5603 - {:added "1.2"} 328.5604 - ([n coll] 328.5605 - (partition-all n n coll)) 328.5606 - ([n step coll] 328.5607 - (lazy-seq 328.5608 - (when-let [s (seq coll)] 328.5609 - (cons (take n s) (partition-all n step (drop step s))))))) 328.5610 - 328.5611 -(defn shuffle 328.5612 - "Return a random permutation of coll" 328.5613 - {:added "1.2"} 328.5614 - [coll] 328.5615 - (let [al (java.util.ArrayList. coll)] 328.5616 - (java.util.Collections/shuffle al) 328.5617 - (clojure.lang.RT/vector (.toArray al)))) 328.5618 - 328.5619 -(defn map-indexed 328.5620 - "Returns a lazy sequence consisting of the result of applying f to 0 328.5621 - and the first item of coll, followed by applying f to 1 and the second 328.5622 - item in coll, etc, until coll is exhausted. Thus function f should 328.5623 - accept 2 arguments, index and item." 328.5624 - {:added "1.2"} 328.5625 - [f coll] 328.5626 - (letfn [(mapi [idx coll] 328.5627 - (lazy-seq 328.5628 - (when-let [s (seq coll)] 328.5629 - (if (chunked-seq? s) 328.5630 - (let [c (chunk-first s) 328.5631 - size (int (count c)) 328.5632 - b (chunk-buffer size)] 328.5633 - (dotimes [i size] 328.5634 - (chunk-append b (f (+ idx i) (.nth c i)))) 328.5635 - (chunk-cons (chunk b) (mapi (+ idx size) (chunk-rest s)))) 328.5636 - (cons (f idx (first s)) (mapi (inc idx) (rest s)))))))] 328.5637 - (mapi 0 coll))) 328.5638 - 328.5639 -(defn keep 328.5640 - "Returns a lazy sequence of the non-nil results of (f item). Note, 328.5641 - this means false return values will be included. f must be free of 328.5642 - side-effects." 328.5643 - {:added "1.2"} 328.5644 - ([f coll] 328.5645 - (lazy-seq 328.5646 - (when-let [s (seq coll)] 328.5647 - (if (chunked-seq? s) 328.5648 - (let [c (chunk-first s) 328.5649 - size (count c) 328.5650 - b (chunk-buffer size)] 328.5651 - (dotimes [i size] 328.5652 - (let [x (f (.nth c i))] 328.5653 - (when-not (nil? x) 328.5654 - (chunk-append b x)))) 328.5655 - (chunk-cons (chunk b) (keep f (chunk-rest s)))) 328.5656 - (let [x (f (first s))] 328.5657 - (if (nil? x) 328.5658 - (keep f (rest s)) 328.5659 - (cons x (keep f (rest s)))))))))) 328.5660 - 328.5661 -(defn keep-indexed 328.5662 - "Returns a lazy sequence of the non-nil results of (f index item). Note, 328.5663 - this means false return values will be included. f must be free of 328.5664 - side-effects." 328.5665 - {:added "1.2"} 328.5666 - ([f coll] 328.5667 - (letfn [(keepi [idx coll] 328.5668 - (lazy-seq 328.5669 - (when-let [s (seq coll)] 328.5670 - (if (chunked-seq? s) 328.5671 - (let [c (chunk-first s) 328.5672 - size (count c) 328.5673 - b (chunk-buffer size)] 328.5674 - (dotimes [i size] 328.5675 - (let [x (f (+ idx i) (.nth c i))] 328.5676 - (when-not (nil? x) 328.5677 - (chunk-append b x)))) 328.5678 - (chunk-cons (chunk b) (keepi (+ idx size) (chunk-rest s)))) 328.5679 - (let [x (f idx (first s))] 328.5680 - (if (nil? x) 328.5681 - (keepi (inc idx) (rest s)) 328.5682 - (cons x (keepi (inc idx) (rest s)))))))))] 328.5683 - (keepi 0 coll)))) 328.5684 - 328.5685 -(defn fnil 328.5686 - "Takes a function f, and returns a function that calls f, replacing 328.5687 - a nil first argument to f with the supplied value x. Higher arity 328.5688 - versions can replace arguments in the second and third 328.5689 - positions (y, z). Note that the function f can take any number of 328.5690 - arguments, not just the one(s) being nil-patched." 328.5691 - {:added "1.2"} 328.5692 - ([f x] 328.5693 - (fn 328.5694 - ([a] (f (if (nil? a) x a))) 328.5695 - ([a b] (f (if (nil? a) x a) b)) 328.5696 - ([a b c] (f (if (nil? a) x a) b c)) 328.5697 - ([a b c & ds] (apply f (if (nil? a) x a) b c ds)))) 328.5698 - ([f x y] 328.5699 - (fn 328.5700 - ([a b] (f (if (nil? a) x a) (if (nil? b) y b))) 328.5701 - ([a b c] (f (if (nil? a) x a) (if (nil? b) y b) c)) 328.5702 - ([a b c & ds] (apply f (if (nil? a) x a) (if (nil? b) y b) c ds)))) 328.5703 - ([f x y z] 328.5704 - (fn 328.5705 - ([a b] (f (if (nil? a) x a) (if (nil? b) y b))) 328.5706 - ([a b c] (f (if (nil? a) x a) (if (nil? b) y b) (if (nil? c) z c))) 328.5707 - ([a b c & ds] (apply f (if (nil? a) x a) (if (nil? b) y b) (if (nil? c) z c) ds))))) 328.5708 - 328.5709 -(defn- ^{:dynamic true} assert-valid-fdecl 328.5710 - "A good fdecl looks like (([a] ...) ([a b] ...)) near the end of defn." 328.5711 - [fdecl] 328.5712 - (if-let [bad-args (seq (remove #(vector? %) (map first fdecl)))] 328.5713 - (throw (IllegalArgumentException. (str "Parameter declaration " (first bad-args) " should be a vector")))))
329.1 --- a/src/clojure/core/protocols.clj Sat Aug 21 06:25:44 2010 -0400 329.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 329.3 @@ -1,94 +0,0 @@ 329.4 -; Copyright (c) Rich Hickey. All rights reserved. 329.5 -; The use and distribution terms for this software are covered by the 329.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 329.7 -; which can be found in the file epl-v10.html at the root of this distribution. 329.8 -; By using this software in any fashion, you are agreeing to be bound by 329.9 -; the terms of this license. 329.10 -; You must not remove this notice, or any other, from this software. 329.11 - 329.12 -(ns clojure.core.protocols) 329.13 - 329.14 -(defprotocol InternalReduce 329.15 - "Protocol for concrete seq types that can reduce themselves 329.16 - faster than first/next recursion. Called by clojure.core/reduce." 329.17 - (internal-reduce [seq f start])) 329.18 - 329.19 -(extend-protocol InternalReduce 329.20 - nil 329.21 - (internal-reduce 329.22 - [s f val] 329.23 - val) 329.24 - 329.25 - ;; handles vectors and ranges 329.26 - clojure.lang.IChunkedSeq 329.27 - (internal-reduce 329.28 - [s f val] 329.29 - (if-let [s (seq s)] 329.30 - (if (chunked-seq? s) 329.31 - (recur (chunk-next s) 329.32 - f 329.33 - (.reduce (chunk-first s) f val)) 329.34 - (internal-reduce s f val)) 329.35 - val)) 329.36 - 329.37 - clojure.lang.StringSeq 329.38 - (internal-reduce 329.39 - [str-seq f val] 329.40 - (let [s (.s str-seq)] 329.41 - (loop [i (.i str-seq) 329.42 - val val] 329.43 - (if (< i (.length s)) 329.44 - (recur (inc i) (f val (.charAt s i))) 329.45 - val)))) 329.46 - 329.47 - clojure.lang.ArraySeq 329.48 - (internal-reduce 329.49 - [a-seq f val] 329.50 - (let [^objects arr (.array a-seq)] 329.51 - (loop [i (.index a-seq) 329.52 - val val] 329.53 - (if (< i (alength arr)) 329.54 - (recur (inc i) (f val (aget arr i))) 329.55 - val)))) 329.56 - 329.57 - java.lang.Object 329.58 - (internal-reduce 329.59 - [s f val] 329.60 - (loop [cls (class s) 329.61 - s s 329.62 - f f 329.63 - val val] 329.64 - (if-let [s (seq s)] 329.65 - ;; roll over to faster implementation if underlying seq changes type 329.66 - (if (identical? (class s) cls) 329.67 - (recur cls (next s) f (f val (first s))) 329.68 - (internal-reduce s f val)) 329.69 - val)))) 329.70 - 329.71 -(def arr-impl 329.72 - '(internal-reduce 329.73 - [a-seq f val] 329.74 - (let [arr (.array a-seq)] 329.75 - (loop [i (.index a-seq) 329.76 - val val] 329.77 - (if (< i (alength arr)) 329.78 - (recur (inc i) (f val (aget arr i))) 329.79 - val))))) 329.80 - 329.81 -(defn- emit-array-impls* 329.82 - [syms] 329.83 - (apply 329.84 - concat 329.85 - (map 329.86 - (fn [s] 329.87 - [(symbol (str "clojure.lang.ArraySeq$ArraySeq_" s)) 329.88 - arr-impl]) 329.89 - syms))) 329.90 - 329.91 -(defmacro emit-array-impls 329.92 - [& syms] 329.93 - `(extend-protocol InternalReduce 329.94 - ~@(emit-array-impls* syms))) 329.95 - 329.96 -(emit-array-impls int long float double byte char boolean) 329.97 -
330.1 --- a/src/clojure/core_deftype.clj Sat Aug 21 06:25:44 2010 -0400 330.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 330.3 @@ -1,769 +0,0 @@ 330.4 -; Copyright (c) Rich Hickey. All rights reserved. 330.5 -; The use and distribution terms for this software are covered by the 330.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 330.7 -; which can be found in the file epl-v10.html at the root of this distribution. 330.8 -; By using this software in any fashion, you are agreeing to be bound by 330.9 -; the terms of this license. 330.10 -; You must not remove this notice, or any other, from this software. 330.11 - 330.12 -(in-ns 'clojure.core) 330.13 - 330.14 -;;;;;;;;;;;;;;;;;;;;;;;;;;;; definterface ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 330.15 - 330.16 -(defn namespace-munge 330.17 - "Convert a Clojure namespace name to a legal Java package name." 330.18 - {:added "1.2"} 330.19 - [ns] 330.20 - (.replace (str ns) \- \_)) 330.21 - 330.22 -;for now, built on gen-interface 330.23 -(defmacro definterface 330.24 - [name & sigs] 330.25 - (let [tag (fn [x] (or (:tag (meta x)) Object)) 330.26 - psig (fn [[name [& args]]] 330.27 - (vector name (vec (map tag args)) (tag name) (map meta args))) 330.28 - cname (with-meta (symbol (str (namespace-munge *ns*) "." name)) (meta name))] 330.29 - `(let [] 330.30 - (gen-interface :name ~cname :methods ~(vec (map psig sigs))) 330.31 - (import ~cname)))) 330.32 - 330.33 -;;;;;;;;;;;;;;;;;;;;;;;;;;;; reify/deftype ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 330.34 - 330.35 -(defn- parse-opts [s] 330.36 - (loop [opts {} [k v & rs :as s] s] 330.37 - (if (keyword? k) 330.38 - (recur (assoc opts k v) rs) 330.39 - [opts s]))) 330.40 - 330.41 -(defn- parse-impls [specs] 330.42 - (loop [ret {} s specs] 330.43 - (if (seq s) 330.44 - (recur (assoc ret (first s) (take-while seq? (next s))) 330.45 - (drop-while seq? (next s))) 330.46 - ret))) 330.47 - 330.48 -(defn- parse-opts+specs [opts+specs] 330.49 - (let [[opts specs] (parse-opts opts+specs) 330.50 - impls (parse-impls specs) 330.51 - interfaces (-> (map #(if (var? (resolve %)) 330.52 - (:on (deref (resolve %))) 330.53 - %) 330.54 - (keys impls)) 330.55 - set 330.56 - (disj 'Object 'java.lang.Object) 330.57 - vec) 330.58 - methods (map (fn [[name params & body]] 330.59 - (cons name (maybe-destructured params body))) 330.60 - (apply concat (vals impls)))] 330.61 - (when-let [bad-opts (seq (remove #{:no-print} (keys opts)))] 330.62 - (throw (IllegalArgumentException. (apply print-str "Unsupported option(s) -" bad-opts)))) 330.63 - [interfaces methods opts])) 330.64 - 330.65 -(defmacro reify 330.66 - "reify is a macro with the following structure: 330.67 - 330.68 - (reify options* specs*) 330.69 - 330.70 - Currently there are no options. 330.71 - 330.72 - Each spec consists of the protocol or interface name followed by zero 330.73 - or more method bodies: 330.74 - 330.75 - protocol-or-interface-or-Object 330.76 - (methodName [args+] body)* 330.77 - 330.78 - Methods should be supplied for all methods of the desired 330.79 - protocol(s) and interface(s). You can also define overrides for 330.80 - methods of Object. Note that the first parameter must be supplied to 330.81 - correspond to the target object ('this' in Java parlance). Thus 330.82 - methods for interfaces will take one more argument than do the 330.83 - interface declarations. Note also that recur calls to the method 330.84 - head should *not* pass the target object, it will be supplied 330.85 - automatically and can not be substituted. 330.86 - 330.87 - The return type can be indicated by a type hint on the method name, 330.88 - and arg types can be indicated by a type hint on arg names. If you 330.89 - leave out all hints, reify will try to match on same name/arity 330.90 - method in the protocol(s)/interface(s) - this is preferred. If you 330.91 - supply any hints at all, no inference is done, so all hints (or 330.92 - default of Object) must be correct, for both arguments and return 330.93 - type. If a method is overloaded in a protocol/interface, multiple 330.94 - independent method definitions must be supplied. If overloaded with 330.95 - same arity in an interface you must specify complete hints to 330.96 - disambiguate - a missing hint implies Object. 330.97 - 330.98 - recur works to method heads The method bodies of reify are lexical 330.99 - closures, and can refer to the surrounding local scope: 330.100 - 330.101 - (str (let [f \"foo\"] 330.102 - (reify Object 330.103 - (toString [this] f)))) 330.104 - == \"foo\" 330.105 - 330.106 - (seq (let [f \"foo\"] 330.107 - (reify clojure.lang.Seqable 330.108 - (seq [this] (seq f))))) 330.109 - == (\\f \\o \\o))" 330.110 - {:added "1.2"} 330.111 - [& opts+specs] 330.112 - (let [[interfaces methods] (parse-opts+specs opts+specs)] 330.113 - (with-meta `(reify* ~interfaces ~@methods) (meta &form)))) 330.114 - 330.115 -(defn hash-combine [x y] 330.116 - (clojure.lang.Util/hashCombine x (clojure.lang.Util/hash y))) 330.117 - 330.118 -(defn munge [s] 330.119 - ((if (symbol? s) symbol str) (clojure.lang.Compiler/munge (str s)))) 330.120 - 330.121 -(defn- imap-cons 330.122 - [^IPersistentMap this o] 330.123 - (cond 330.124 - (instance? java.util.Map$Entry o) 330.125 - (let [^java.util.Map$Entry pair o] 330.126 - (.assoc this (.getKey pair) (.getValue pair))) 330.127 - (instance? clojure.lang.IPersistentVector o) 330.128 - (let [^clojure.lang.IPersistentVector vec o] 330.129 - (.assoc this (.nth vec 0) (.nth vec 1))) 330.130 - :else (loop [this this 330.131 - o o] 330.132 - (if (seq o) 330.133 - (let [^java.util.Map$Entry pair (first o)] 330.134 - (recur (.assoc this (.getKey pair) (.getValue pair)) (rest o))) 330.135 - this)))) 330.136 - 330.137 -(defn- emit-defrecord 330.138 - "Do not use this directly - use defrecord" 330.139 - {:added "1.2"} 330.140 - [tagname name fields interfaces methods] 330.141 - (let [tag (keyword (str *ns*) (str tagname)) 330.142 - classname (with-meta (symbol (str *ns* "." name)) (meta name)) 330.143 - interfaces (vec interfaces) 330.144 - interface-set (set (map resolve interfaces)) 330.145 - methodname-set (set (map first methods)) 330.146 - hinted-fields fields 330.147 - fields (vec (map #(with-meta % nil) fields)) 330.148 - base-fields fields 330.149 - fields (conj fields '__meta '__extmap)] 330.150 - (when (some #{:volatile-mutable :unsynchronized-mutable} (mapcat (comp keys meta) hinted-fields)) 330.151 - (throw (IllegalArgumentException. ":volatile-mutable or :unsynchronized-mutable not supported for record fields"))) 330.152 - (let [gs (gensym)] 330.153 - (letfn 330.154 - [(eqhash [[i m]] 330.155 - [i 330.156 - (conj m 330.157 - `(hashCode [this#] (clojure.lang.APersistentMap/mapHash this#)) 330.158 - `(equals [this# ~gs] (clojure.lang.APersistentMap/mapEquals this# ~gs)))]) 330.159 - (iobj [[i m]] 330.160 - [(conj i 'clojure.lang.IObj) 330.161 - (conj m `(meta [this#] ~'__meta) 330.162 - `(withMeta [this# ~gs] (new ~tagname ~@(replace {'__meta gs} fields))))]) 330.163 - (ilookup [[i m]] 330.164 - [(conj i 'clojure.lang.ILookup 'clojure.lang.IKeywordLookup) 330.165 - (conj m `(valAt [this# k#] (.valAt this# k# nil)) 330.166 - `(valAt [this# k# else#] 330.167 - (case k# ~@(mapcat (fn [fld] [(keyword fld) fld]) 330.168 - base-fields) 330.169 - (get ~'__extmap k# else#))) 330.170 - `(getLookupThunk [this# k#] 330.171 - (let [~'gclass (class this#)] 330.172 - (case k# 330.173 - ~@(let [hinted-target (with-meta 'gtarget {:tag tagname})] 330.174 - (mapcat 330.175 - (fn [fld] 330.176 - [(keyword fld) 330.177 - `(reify clojure.lang.ILookupThunk 330.178 - (get [~'thunk ~'gtarget] 330.179 - (if (identical? (class ~'gtarget) ~'gclass) 330.180 - (. ~hinted-target ~(keyword fld)) 330.181 - ~'thunk)))]) 330.182 - base-fields)) 330.183 - nil))))]) 330.184 - (imap [[i m]] 330.185 - [(conj i 'clojure.lang.IPersistentMap) 330.186 - (conj m 330.187 - `(count [this#] (+ ~(count base-fields) (count ~'__extmap))) 330.188 - `(empty [this#] (throw (UnsupportedOperationException. (str "Can't create empty: " ~(str classname))))) 330.189 - `(cons [this# e#] ((var imap-cons) this# e#)) 330.190 - `(equiv [this# ~gs] 330.191 - (boolean 330.192 - (or (identical? this# ~gs) 330.193 - (when (identical? (class this#) (class ~gs)) 330.194 - (let [~gs ~(with-meta gs {:tag tagname})] 330.195 - (and ~@(map (fn [fld] `(= ~fld (. ~gs ~fld))) base-fields) 330.196 - (= ~'__extmap (. ~gs ~'__extmap)))))))) 330.197 - `(containsKey [this# k#] (not (identical? this# (.valAt this# k# this#)))) 330.198 - `(entryAt [this# k#] (let [v# (.valAt this# k# this#)] 330.199 - (when-not (identical? this# v#) 330.200 - (clojure.lang.MapEntry. k# v#)))) 330.201 - `(seq [this#] (seq (concat [~@(map #(list `new `clojure.lang.MapEntry (keyword %) %) base-fields)] 330.202 - ~'__extmap))) 330.203 - `(assoc [this# k# ~gs] 330.204 - (condp identical? k# 330.205 - ~@(mapcat (fn [fld] 330.206 - [(keyword fld) (list* `new tagname (replace {fld gs} fields))]) 330.207 - base-fields) 330.208 - (new ~tagname ~@(remove #{'__extmap} fields) (assoc ~'__extmap k# ~gs)))) 330.209 - `(without [this# k#] (if (contains? #{~@(map keyword base-fields)} k#) 330.210 - (dissoc (with-meta (into {} this#) ~'__meta) k#) 330.211 - (new ~tagname ~@(remove #{'__extmap} fields) 330.212 - (not-empty (dissoc ~'__extmap k#))))))]) 330.213 - (ijavamap [[i m]] 330.214 - [(conj i 'java.util.Map 'java.io.Serializable) 330.215 - (conj m 330.216 - `(size [this#] (.count this#)) 330.217 - `(isEmpty [this#] (= 0 (.count this#))) 330.218 - `(containsValue [this# v#] (boolean (some #{v#} (vals this#)))) 330.219 - `(get [this# k#] (.valAt this# k#)) 330.220 - `(put [this# k# v#] (throw (UnsupportedOperationException.))) 330.221 - `(remove [this# k#] (throw (UnsupportedOperationException.))) 330.222 - `(putAll [this# m#] (throw (UnsupportedOperationException.))) 330.223 - `(clear [this#] (throw (UnsupportedOperationException.))) 330.224 - `(keySet [this#] (set (keys this#))) 330.225 - `(values [this#] (vals this#)) 330.226 - `(entrySet [this#] (set this#)))]) 330.227 - ] 330.228 - (let [[i m] (-> [interfaces methods] eqhash iobj ilookup imap ijavamap)] 330.229 - `(deftype* ~tagname ~classname ~(conj hinted-fields '__meta '__extmap) 330.230 - :implements ~(vec i) 330.231 - ~@m)))))) 330.232 - 330.233 -(defmacro defrecord 330.234 - "Alpha - subject to change 330.235 - 330.236 - (defrecord name [fields*] options* specs*) 330.237 - 330.238 - Currently there are no options. 330.239 - 330.240 - Each spec consists of a protocol or interface name followed by zero 330.241 - or more method bodies: 330.242 - 330.243 - protocol-or-interface-or-Object 330.244 - (methodName [args*] body)* 330.245 - 330.246 - Dynamically generates compiled bytecode for class with the given 330.247 - name, in a package with the same name as the current namespace, the 330.248 - given fields, and, optionally, methods for protocols and/or 330.249 - interfaces. 330.250 - 330.251 - The class will have the (immutable) fields named by 330.252 - fields, which can have type hints. Protocols/interfaces and methods 330.253 - are optional. The only methods that can be supplied are those 330.254 - declared in the protocols/interfaces. Note that method bodies are 330.255 - not closures, the local environment includes only the named fields, 330.256 - and those fields can be accessed directy. 330.257 - 330.258 - Method definitions take the form: 330.259 - 330.260 - (methodname [args*] body) 330.261 - 330.262 - The argument and return types can be hinted on the arg and 330.263 - methodname symbols. If not supplied, they will be inferred, so type 330.264 - hints should be reserved for disambiguation. 330.265 - 330.266 - Methods should be supplied for all methods of the desired 330.267 - protocol(s) and interface(s). You can also define overrides for 330.268 - methods of Object. Note that a parameter must be supplied to 330.269 - correspond to the target object ('this' in Java parlance). Thus 330.270 - methods for interfaces will take one more argument than do the 330.271 - interface declarations. Note also that recur calls to the method 330.272 - head should *not* pass the target object, it will be supplied 330.273 - automatically and can not be substituted. 330.274 - 330.275 - In the method bodies, the (unqualified) name can be used to name the 330.276 - class (for calls to new, instance? etc). 330.277 - 330.278 - The class will have implementations of several (clojure.lang) 330.279 - interfaces generated automatically: IObj (metadata support) and 330.280 - IPersistentMap, and all of their superinterfaces. 330.281 - 330.282 - In addition, defrecord will define type-and-value-based equality and 330.283 - hashCode. 330.284 - 330.285 - When AOT compiling, generates compiled bytecode for a class with the 330.286 - given name (a symbol), prepends the current ns as the package, and 330.287 - writes the .class file to the *compile-path* directory. 330.288 - 330.289 - Two constructors will be defined, one taking the designated fields 330.290 - followed by a metadata map (nil for none) and an extension field 330.291 - map (nil for none), and one taking only the fields (using nil for 330.292 - meta and extension fields)." 330.293 - {:added "1.2"} 330.294 - 330.295 - [name [& fields] & opts+specs] 330.296 - (let [gname name 330.297 - [interfaces methods opts] (parse-opts+specs opts+specs) 330.298 - classname (symbol (str *ns* "." gname)) 330.299 - tag (keyword (str *ns*) (str name)) 330.300 - hinted-fields fields 330.301 - fields (vec (map #(with-meta % nil) fields))] 330.302 - `(let [] 330.303 - ~(emit-defrecord name gname (vec hinted-fields) (vec interfaces) methods) 330.304 - (defmethod print-method ~classname [o# w#] 330.305 - ((var print-defrecord) o# w#)) 330.306 - (import ~classname) 330.307 - #_(defn ~name 330.308 - ([~@fields] (new ~classname ~@fields nil nil)) 330.309 - ([~@fields meta# extmap#] (new ~classname ~@fields meta# extmap#)))))) 330.310 - 330.311 -(defn- print-defrecord [o ^Writer w] 330.312 - (print-meta o w) 330.313 - (.write w "#:") 330.314 - (.write w (.getName (class o))) 330.315 - (print-map 330.316 - o 330.317 - pr-on w)) 330.318 - 330.319 -(defn- emit-deftype* 330.320 - "Do not use this directly - use deftype" 330.321 - [tagname name fields interfaces methods] 330.322 - (let [classname (with-meta (symbol (str *ns* "." name)) (meta name))] 330.323 - `(deftype* ~tagname ~classname ~fields 330.324 - :implements ~interfaces 330.325 - ~@methods))) 330.326 - 330.327 -(defmacro deftype 330.328 - "Alpha - subject to change 330.329 - 330.330 - (deftype name [fields*] options* specs*) 330.331 - 330.332 - Currently there are no options. 330.333 - 330.334 - Each spec consists of a protocol or interface name followed by zero 330.335 - or more method bodies: 330.336 - 330.337 - protocol-or-interface-or-Object 330.338 - (methodName [args*] body)* 330.339 - 330.340 - Dynamically generates compiled bytecode for class with the given 330.341 - name, in a package with the same name as the current namespace, the 330.342 - given fields, and, optionally, methods for protocols and/or 330.343 - interfaces. 330.344 - 330.345 - The class will have the (by default, immutable) fields named by 330.346 - fields, which can have type hints. Protocols/interfaces and methods 330.347 - are optional. The only methods that can be supplied are those 330.348 - declared in the protocols/interfaces. Note that method bodies are 330.349 - not closures, the local environment includes only the named fields, 330.350 - and those fields can be accessed directy. Fields can be qualified 330.351 - with the metadata :volatile-mutable true or :unsynchronized-mutable 330.352 - true, at which point (set! afield aval) will be supported in method 330.353 - bodies. Note well that mutable fields are extremely difficult to use 330.354 - correctly, and are present only to facilitate the building of higher 330.355 - level constructs, such as Clojure's reference types, in Clojure 330.356 - itself. They are for experts only - if the semantics and 330.357 - implications of :volatile-mutable or :unsynchronized-mutable are not 330.358 - immediately apparent to you, you should not be using them. 330.359 - 330.360 - Method definitions take the form: 330.361 - 330.362 - (methodname [args*] body) 330.363 - 330.364 - The argument and return types can be hinted on the arg and 330.365 - methodname symbols. If not supplied, they will be inferred, so type 330.366 - hints should be reserved for disambiguation. 330.367 - 330.368 - Methods should be supplied for all methods of the desired 330.369 - protocol(s) and interface(s). You can also define overrides for 330.370 - methods of Object. Note that a parameter must be supplied to 330.371 - correspond to the target object ('this' in Java parlance). Thus 330.372 - methods for interfaces will take one more argument than do the 330.373 - interface declarations. Note also that recur calls to the method 330.374 - head should *not* pass the target object, it will be supplied 330.375 - automatically and can not be substituted. 330.376 - 330.377 - In the method bodies, the (unqualified) name can be used to name the 330.378 - class (for calls to new, instance? etc). 330.379 - 330.380 - When AOT compiling, generates compiled bytecode for a class with the 330.381 - given name (a symbol), prepends the current ns as the package, and 330.382 - writes the .class file to the *compile-path* directory. 330.383 - 330.384 - One constructors will be defined, taking the designated fields." 330.385 - {:added "1.2"} 330.386 - 330.387 - [name [& fields] & opts+specs] 330.388 - (let [gname name 330.389 - [interfaces methods opts] (parse-opts+specs opts+specs) 330.390 - classname (symbol (str *ns* "." gname)) 330.391 - tag (keyword (str *ns*) (str name)) 330.392 - hinted-fields fields 330.393 - fields (vec (map #(with-meta % nil) fields))] 330.394 - `(let [] 330.395 - ~(emit-deftype* name gname (vec hinted-fields) (vec interfaces) methods) 330.396 - (import ~classname)))) 330.397 - 330.398 - 330.399 - 330.400 - 330.401 -;;;;;;;;;;;;;;;;;;;;;;; protocols ;;;;;;;;;;;;;;;;;;;;;;;; 330.402 - 330.403 -(defn- expand-method-impl-cache [^clojure.lang.MethodImplCache cache c f] 330.404 - (let [cs (into {} (remove (fn [[c e]] (nil? e)) (map vec (partition 2 (.table cache))))) 330.405 - cs (assoc cs c (clojure.lang.MethodImplCache$Entry. c f)) 330.406 - [shift mask] (min-hash (keys cs)) 330.407 - table (make-array Object (* 2 (inc mask))) 330.408 - table (reduce (fn [^objects t [c e]] 330.409 - (let [i (* 2 (int (shift-mask shift mask (hash c))))] 330.410 - (aset t i c) 330.411 - (aset t (inc i) e) 330.412 - t)) 330.413 - table cs)] 330.414 - (clojure.lang.MethodImplCache. (.protocol cache) (.methodk cache) shift mask table))) 330.415 - 330.416 -(defn- super-chain [^Class c] 330.417 - (when c 330.418 - (cons c (super-chain (.getSuperclass c))))) 330.419 - 330.420 -(defn- pref 330.421 - ([] nil) 330.422 - ([a] a) 330.423 - ([^Class a ^Class b] 330.424 - (if (.isAssignableFrom a b) b a))) 330.425 - 330.426 -(defn find-protocol-impl [protocol x] 330.427 - (if (instance? (:on-interface protocol) x) 330.428 - x 330.429 - (let [c (class x) 330.430 - impl #(get (:impls protocol) %)] 330.431 - (or (impl c) 330.432 - (and c (or (first (remove nil? (map impl (butlast (super-chain c))))) 330.433 - (when-let [t (reduce pref (filter impl (disj (supers c) Object)))] 330.434 - (impl t)) 330.435 - (impl Object))))))) 330.436 - 330.437 -(defn find-protocol-method [protocol methodk x] 330.438 - (get (find-protocol-impl protocol x) methodk)) 330.439 - 330.440 -(defn- protocol? 330.441 - [maybe-p] 330.442 - (boolean (:on-interface maybe-p))) 330.443 - 330.444 -(defn- implements? [protocol atype] 330.445 - (and atype (.isAssignableFrom ^Class (:on-interface protocol) atype))) 330.446 - 330.447 -(defn extends? 330.448 - "Returns true if atype extends protocol" 330.449 - {:added "1.2"} 330.450 - [protocol atype] 330.451 - (boolean (or (implements? protocol atype) 330.452 - (get (:impls protocol) atype)))) 330.453 - 330.454 -(defn extenders 330.455 - "Returns a collection of the types explicitly extending protocol" 330.456 - {:added "1.2"} 330.457 - [protocol] 330.458 - (keys (:impls protocol))) 330.459 - 330.460 -(defn satisfies? 330.461 - "Returns true if x satisfies the protocol" 330.462 - {:added "1.2"} 330.463 - [protocol x] 330.464 - (boolean (find-protocol-impl protocol x))) 330.465 - 330.466 -(defn -cache-protocol-fn [^clojure.lang.AFunction pf x ^Class c ^clojure.lang.IFn interf] 330.467 - (let [cache (.__methodImplCache pf) 330.468 - f (if (.isInstance c x) 330.469 - interf 330.470 - (find-protocol-method (.protocol cache) (.methodk cache) x))] 330.471 - (when-not f 330.472 - (throw (IllegalArgumentException. (str "No implementation of method: " (.methodk cache) 330.473 - " of protocol: " (:var (.protocol cache)) 330.474 - " found for class: " (if (nil? x) "nil" (.getName (class x))))))) 330.475 - (set! (.__methodImplCache pf) (expand-method-impl-cache cache (class x) f)) 330.476 - f)) 330.477 - 330.478 -(defn- emit-method-builder [on-interface method on-method arglists] 330.479 - (let [methodk (keyword method) 330.480 - gthis (with-meta (gensym) {:tag 'clojure.lang.AFunction}) 330.481 - ginterf (gensym)] 330.482 - `(fn [cache#] 330.483 - (let [~ginterf 330.484 - (fn 330.485 - ~@(map 330.486 - (fn [args] 330.487 - (let [gargs (map #(gensym (str "gf__" % "__")) args) 330.488 - target (first gargs)] 330.489 - `([~@gargs] 330.490 - (. ~(with-meta target {:tag on-interface}) ~(or on-method method) ~@(rest gargs))))) 330.491 - arglists)) 330.492 - ^clojure.lang.AFunction f# 330.493 - (fn ~gthis 330.494 - ~@(map 330.495 - (fn [args] 330.496 - (let [gargs (map #(gensym (str "gf__" % "__")) args) 330.497 - target (first gargs)] 330.498 - `([~@gargs] 330.499 - (let [cache# (.__methodImplCache ~gthis) 330.500 - f# (.fnFor cache# (clojure.lang.Util/classOf ~target))] 330.501 - (if f# 330.502 - (f# ~@gargs) 330.503 - ((-cache-protocol-fn ~gthis ~target ~on-interface ~ginterf) ~@gargs)))))) 330.504 - arglists))] 330.505 - (set! (.__methodImplCache f#) cache#) 330.506 - f#)))) 330.507 - 330.508 -(defn -reset-methods [protocol] 330.509 - (doseq [[^clojure.lang.Var v build] (:method-builders protocol)] 330.510 - (let [cache (clojure.lang.MethodImplCache. protocol (keyword (.sym v)))] 330.511 - (.bindRoot v (build cache))))) 330.512 - 330.513 -(defn- assert-same-protocol [protocol-var method-syms] 330.514 - (doseq [m method-syms] 330.515 - (let [v (resolve m) 330.516 - p (:protocol (meta v))] 330.517 - (when (and v (bound? v) (not= protocol-var p)) 330.518 - (binding [*out* *err*] 330.519 - (println "Warning: protocol" protocol-var "is overwriting" 330.520 - (if p 330.521 - (str "method " (.sym v) " of protocol " (.sym p)) 330.522 - (str "function " (.sym v))))))))) 330.523 - 330.524 -(defn- emit-protocol [name opts+sigs] 330.525 - (let [iname (symbol (str (munge *ns*) "." (munge name))) 330.526 - [opts sigs] 330.527 - (loop [opts {:on (list 'quote iname) :on-interface iname} sigs opts+sigs] 330.528 - (condp #(%1 %2) (first sigs) 330.529 - string? (recur (assoc opts :doc (first sigs)) (next sigs)) 330.530 - keyword? (recur (assoc opts (first sigs) (second sigs)) (nnext sigs)) 330.531 - [opts sigs])) 330.532 - sigs (reduce (fn [m s] 330.533 - (let [name-meta (meta (first s)) 330.534 - mname (with-meta (first s) nil) 330.535 - [arglists doc] 330.536 - (loop [as [] rs (rest s)] 330.537 - (if (vector? (first rs)) 330.538 - (recur (conj as (first rs)) (next rs)) 330.539 - [(seq as) (first rs)]))] 330.540 - (when (some #{0} (map count arglists)) 330.541 - (throw (IllegalArgumentException. (str "Protocol fn: " mname " must take at least one arg")))) 330.542 - (assoc m (keyword mname) 330.543 - (merge name-meta 330.544 - {:name (vary-meta mname assoc :doc doc :arglists arglists) 330.545 - :arglists arglists 330.546 - :doc doc})))) 330.547 - {} sigs) 330.548 - meths (mapcat (fn [sig] 330.549 - (let [m (munge (:name sig))] 330.550 - (map #(vector m (vec (repeat (dec (count %))'Object)) 'Object) 330.551 - (:arglists sig)))) 330.552 - (vals sigs))] 330.553 - `(do 330.554 - (defonce ~name {}) 330.555 - (gen-interface :name ~iname :methods ~meths) 330.556 - (alter-meta! (var ~name) assoc :doc ~(:doc opts)) 330.557 - (#'assert-same-protocol (var ~name) '~(map :name (vals sigs))) 330.558 - (alter-var-root (var ~name) merge 330.559 - (assoc ~opts 330.560 - :sigs '~sigs 330.561 - :var (var ~name) 330.562 - :method-map 330.563 - ~(and (:on opts) 330.564 - (apply hash-map 330.565 - (mapcat 330.566 - (fn [s] 330.567 - [(keyword (:name s)) (keyword (or (:on s) (:name s)))]) 330.568 - (vals sigs)))) 330.569 - :method-builders 330.570 - ~(apply hash-map 330.571 - (mapcat 330.572 - (fn [s] 330.573 - [`(intern *ns* (with-meta '~(:name s) (merge '~s {:protocol (var ~name)}))) 330.574 - (emit-method-builder (:on-interface opts) (:name s) (:on s) (:arglists s))]) 330.575 - (vals sigs))))) 330.576 - (-reset-methods ~name) 330.577 - '~name))) 330.578 - 330.579 -(defmacro defprotocol 330.580 - "A protocol is a named set of named methods and their signatures: 330.581 - (defprotocol AProtocolName 330.582 - 330.583 - ;optional doc string 330.584 - \"A doc string for AProtocol abstraction\" 330.585 - 330.586 - ;method signatures 330.587 - (bar [this a b] \"bar docs\") 330.588 - (baz [this a] [this a b] [this a b c] \"baz docs\")) 330.589 - 330.590 - No implementations are provided. Docs can be specified for the 330.591 - protocol overall and for each method. The above yields a set of 330.592 - polymorphic functions and a protocol object. All are 330.593 - namespace-qualified by the ns enclosing the definition The resulting 330.594 - functions dispatch on the type of their first argument, which is 330.595 - required and corresponds to the implicit target object ('this' in 330.596 - Java parlance). defprotocol is dynamic, has no special compile-time 330.597 - effect, and defines no new types or classes. Implementations of 330.598 - the protocol methods can be provided using extend. 330.599 - 330.600 - defprotocol will automatically generate a corresponding interface, 330.601 - with the same name as the protocol, i.e. given a protocol: 330.602 - my.ns/Protocol, an interface: my.ns.Protocol. The interface will 330.603 - have methods corresponding to the protocol functions, and the 330.604 - protocol will automatically work with instances of the interface. 330.605 - 330.606 - Note that you should not use this interface with deftype or 330.607 - reify, as they support the protocol directly: 330.608 - 330.609 - (defprotocol P 330.610 - (foo [this]) 330.611 - (bar-me [this] [this y])) 330.612 - 330.613 - (deftype Foo [a b c] 330.614 - P 330.615 - (foo [this] a) 330.616 - (bar-me [this] b) 330.617 - (bar-me [this y] (+ c y))) 330.618 - 330.619 - (bar-me (Foo. 1 2 3) 42) 330.620 - => 45 330.621 - 330.622 - (foo 330.623 - (let [x 42] 330.624 - (reify P 330.625 - (foo [this] 17) 330.626 - (bar-me [this] x) 330.627 - (bar-me [this y] x)))) 330.628 - => 17" 330.629 - {:added "1.2"} 330.630 - [name & opts+sigs] 330.631 - (emit-protocol name opts+sigs)) 330.632 - 330.633 -(defn extend 330.634 - "Implementations of protocol methods can be provided using the extend construct: 330.635 - 330.636 - (extend AType 330.637 - AProtocol 330.638 - {:foo an-existing-fn 330.639 - :bar (fn [a b] ...) 330.640 - :baz (fn ([a]...) ([a b] ...)...)} 330.641 - BProtocol 330.642 - {...} 330.643 - ...) 330.644 - 330.645 - extend takes a type/class (or interface, see below), and one or more 330.646 - protocol + method map pairs. It will extend the polymorphism of the 330.647 - protocol's methods to call the supplied methods when an AType is 330.648 - provided as the first argument. 330.649 - 330.650 - Method maps are maps of the keyword-ized method names to ordinary 330.651 - fns. This facilitates easy reuse of existing fns and fn maps, for 330.652 - code reuse/mixins without derivation or composition. You can extend 330.653 - an interface to a protocol. This is primarily to facilitate interop 330.654 - with the host (e.g. Java) but opens the door to incidental multiple 330.655 - inheritance of implementation since a class can inherit from more 330.656 - than one interface, both of which extend the protocol. It is TBD how 330.657 - to specify which impl to use. You can extend a protocol on nil. 330.658 - 330.659 - If you are supplying the definitions explicitly (i.e. not reusing 330.660 - exsting functions or mixin maps), you may find it more convenient to 330.661 - use the extend-type or extend-protocol macros. 330.662 - 330.663 - Note that multiple independent extend clauses can exist for the same 330.664 - type, not all protocols need be defined in a single extend call. 330.665 - 330.666 - See also: 330.667 - extends?, satisfies?, extenders" 330.668 - {:added "1.2"} 330.669 - [atype & proto+mmaps] 330.670 - (doseq [[proto mmap] (partition 2 proto+mmaps)] 330.671 - (when-not (protocol? proto) 330.672 - (throw (IllegalArgumentException. 330.673 - (str proto " is not a protocol")))) 330.674 - (when (implements? proto atype) 330.675 - (throw (IllegalArgumentException. 330.676 - (str atype " already directly implements " (:on-interface proto) " for protocol:" 330.677 - (:var proto))))) 330.678 - (-reset-methods (alter-var-root (:var proto) assoc-in [:impls atype] mmap)))) 330.679 - 330.680 -(defn- emit-impl [[p fs]] 330.681 - [p (zipmap (map #(-> % first keyword) fs) 330.682 - (map #(cons 'fn (drop 1 %)) fs))]) 330.683 - 330.684 -(defn- emit-hinted-impl [c [p fs]] 330.685 - (let [hint (fn [specs] 330.686 - (let [specs (if (vector? (first specs)) 330.687 - (list specs) 330.688 - specs)] 330.689 - (map (fn [[[target & args] & body]] 330.690 - (cons (apply vector (vary-meta target assoc :tag c) args) 330.691 - body)) 330.692 - specs)))] 330.693 - [p (zipmap (map #(-> % first keyword) fs) 330.694 - (map #(cons 'fn (hint (drop 1 %))) fs))])) 330.695 - 330.696 -(defn- emit-extend-type [c specs] 330.697 - (let [impls (parse-impls specs)] 330.698 - `(extend ~c 330.699 - ~@(mapcat (partial emit-hinted-impl c) impls)))) 330.700 - 330.701 -(defmacro extend-type 330.702 - "A macro that expands into an extend call. Useful when you are 330.703 - supplying the definitions explicitly inline, extend-type 330.704 - automatically creates the maps required by extend. Propagates the 330.705 - class as a type hint on the first argument of all fns. 330.706 - 330.707 - (extend-type MyType 330.708 - Countable 330.709 - (cnt [c] ...) 330.710 - Foo 330.711 - (bar [x y] ...) 330.712 - (baz ([x] ...) ([x y & zs] ...))) 330.713 - 330.714 - expands into: 330.715 - 330.716 - (extend MyType 330.717 - Countable 330.718 - {:cnt (fn [c] ...)} 330.719 - Foo 330.720 - {:baz (fn ([x] ...) ([x y & zs] ...)) 330.721 - :bar (fn [x y] ...)})" 330.722 - {:added "1.2"} 330.723 - [t & specs] 330.724 - (emit-extend-type t specs)) 330.725 - 330.726 -(defn- emit-extend-protocol [p specs] 330.727 - (let [impls (parse-impls specs)] 330.728 - `(do 330.729 - ~@(map (fn [[t fs]] 330.730 - `(extend-type ~t ~p ~@fs)) 330.731 - impls)))) 330.732 - 330.733 -(defmacro extend-protocol 330.734 - "Useful when you want to provide several implementations of the same 330.735 - protocol all at once. Takes a single protocol and the implementation 330.736 - of that protocol for one or more types. Expands into calls to 330.737 - extend-type: 330.738 - 330.739 - (extend-protocol Protocol 330.740 - AType 330.741 - (foo [x] ...) 330.742 - (bar [x y] ...) 330.743 - BType 330.744 - (foo [x] ...) 330.745 - (bar [x y] ...) 330.746 - AClass 330.747 - (foo [x] ...) 330.748 - (bar [x y] ...) 330.749 - nil 330.750 - (foo [x] ...) 330.751 - (bar [x y] ...)) 330.752 - 330.753 - expands into: 330.754 - 330.755 - (do 330.756 - (clojure.core/extend-type AType Protocol 330.757 - (foo [x] ...) 330.758 - (bar [x y] ...)) 330.759 - (clojure.core/extend-type BType Protocol 330.760 - (foo [x] ...) 330.761 - (bar [x y] ...)) 330.762 - (clojure.core/extend-type AClass Protocol 330.763 - (foo [x] ...) 330.764 - (bar [x y] ...)) 330.765 - (clojure.core/extend-type nil Protocol 330.766 - (foo [x] ...) 330.767 - (bar [x y] ...)))" 330.768 - {:added "1.2"} 330.769 - 330.770 - [p & specs] 330.771 - (emit-extend-protocol p specs)) 330.772 -
331.1 --- a/src/clojure/core_print.clj Sat Aug 21 06:25:44 2010 -0400 331.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 331.3 @@ -1,320 +0,0 @@ 331.4 -; Copyright (c) Rich Hickey. All rights reserved. 331.5 -; The use and distribution terms for this software are covered by the 331.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 331.7 -; which can be found in the file epl-v10.html at the root of this distribution. 331.8 -; By using this software in any fashion, you are agreeing to be bound by 331.9 -; the terms of this license. 331.10 -; You must not remove this notice, or any other, from this software. 331.11 - 331.12 -(in-ns 'clojure.core) 331.13 - 331.14 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; printing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 331.15 - 331.16 -(import '(java.io Writer)) 331.17 - 331.18 -(def 331.19 - ^{:doc "*print-length* controls how many items of each collection the 331.20 - printer will print. If it is bound to logical false, there is no 331.21 - limit. Otherwise, it must be bound to an integer indicating the maximum 331.22 - number of items of each collection to print. If a collection contains 331.23 - more items, the printer will print items up to the limit followed by 331.24 - '...' to represent the remaining items. The root binding is nil 331.25 - indicating no limit." 331.26 - :added "1.0"} 331.27 - *print-length* nil) 331.28 - 331.29 -(def 331.30 - ^{:doc "*print-level* controls how many levels deep the printer will 331.31 - print nested objects. If it is bound to logical false, there is no 331.32 - limit. Otherwise, it must be bound to an integer indicating the maximum 331.33 - level to print. Each argument to print is at level 0; if an argument is a 331.34 - collection, its items are at level 1; and so on. If an object is a 331.35 - collection and is at a level greater than or equal to the value bound to 331.36 - *print-level*, the printer prints '#' to represent it. The root binding 331.37 - is nil indicating no limit." 331.38 - :added "1.0"} 331.39 -*print-level* nil) 331.40 - 331.41 -(defn- print-sequential [^String begin, print-one, ^String sep, ^String end, sequence, ^Writer w] 331.42 - (binding [*print-level* (and (not *print-dup*) *print-level* (dec *print-level*))] 331.43 - (if (and *print-level* (neg? *print-level*)) 331.44 - (.write w "#") 331.45 - (do 331.46 - (.write w begin) 331.47 - (when-let [xs (seq sequence)] 331.48 - (if (and (not *print-dup*) *print-length*) 331.49 - (loop [[x & xs] xs 331.50 - print-length *print-length*] 331.51 - (if (zero? print-length) 331.52 - (.write w "...") 331.53 - (do 331.54 - (print-one x w) 331.55 - (when xs 331.56 - (.write w sep) 331.57 - (recur xs (dec print-length)))))) 331.58 - (loop [[x & xs] xs] 331.59 - (print-one x w) 331.60 - (when xs 331.61 - (.write w sep) 331.62 - (recur xs))))) 331.63 - (.write w end))))) 331.64 - 331.65 -(defn- print-meta [o, ^Writer w] 331.66 - (when-let [m (meta o)] 331.67 - (when (and (pos? (count m)) 331.68 - (or *print-dup* 331.69 - (and *print-meta* *print-readably*))) 331.70 - (.write w "^") 331.71 - (if (and (= (count m) 1) (:tag m)) 331.72 - (pr-on (:tag m) w) 331.73 - (pr-on m w)) 331.74 - (.write w " ")))) 331.75 - 331.76 -(defmethod print-method :default [o, ^Writer w] 331.77 - (print-method (vary-meta o #(dissoc % :type)) w)) 331.78 - 331.79 -(defmethod print-method nil [o, ^Writer w] 331.80 - (.write w "nil")) 331.81 - 331.82 -(defmethod print-dup nil [o w] (print-method o w)) 331.83 - 331.84 -(defn print-ctor [o print-args ^Writer w] 331.85 - (.write w "#=(") 331.86 - (.write w (.getName ^Class (class o))) 331.87 - (.write w ". ") 331.88 - (print-args o w) 331.89 - (.write w ")")) 331.90 - 331.91 -(defmethod print-method Object [o, ^Writer w] 331.92 - (.write w "#<") 331.93 - (.write w (.getSimpleName (class o))) 331.94 - (.write w " ") 331.95 - (.write w (str o)) 331.96 - (.write w ">")) 331.97 - 331.98 -(defmethod print-method clojure.lang.Keyword [o, ^Writer w] 331.99 - (.write w (str o))) 331.100 - 331.101 -(defmethod print-dup clojure.lang.Keyword [o w] (print-method o w)) 331.102 - 331.103 -(defmethod print-method Number [o, ^Writer w] 331.104 - (.write w (str o))) 331.105 - 331.106 -(defmethod print-dup Number [o, ^Writer w] 331.107 - (print-ctor o 331.108 - (fn [o w] 331.109 - (print-dup (str o) w)) 331.110 - w)) 331.111 - 331.112 -(defmethod print-dup clojure.lang.Fn [o, ^Writer w] 331.113 - (print-ctor o (fn [o w]) w)) 331.114 - 331.115 -(prefer-method print-dup clojure.lang.IPersistentCollection clojure.lang.Fn) 331.116 -(prefer-method print-dup java.util.Map clojure.lang.Fn) 331.117 -(prefer-method print-dup java.util.Collection clojure.lang.Fn) 331.118 - 331.119 -(defmethod print-method Boolean [o, ^Writer w] 331.120 - (.write w (str o))) 331.121 - 331.122 -(defmethod print-dup Boolean [o w] (print-method o w)) 331.123 - 331.124 -(defn print-simple [o, ^Writer w] 331.125 - (print-meta o w) 331.126 - (.write w (str o))) 331.127 - 331.128 -(defmethod print-method clojure.lang.Symbol [o, ^Writer w] 331.129 - (print-simple o w)) 331.130 - 331.131 -(defmethod print-dup clojure.lang.Symbol [o w] (print-method o w)) 331.132 - 331.133 -(defmethod print-method clojure.lang.Var [o, ^Writer w] 331.134 - (print-simple o w)) 331.135 - 331.136 -(defmethod print-dup clojure.lang.Var [^clojure.lang.Var o, ^Writer w] 331.137 - (.write w (str "#=(var " (.name (.ns o)) "/" (.sym o) ")"))) 331.138 - 331.139 -(defmethod print-method clojure.lang.ISeq [o, ^Writer w] 331.140 - (print-meta o w) 331.141 - (print-sequential "(" pr-on " " ")" o w)) 331.142 - 331.143 -(defmethod print-dup clojure.lang.ISeq [o w] (print-method o w)) 331.144 -(defmethod print-dup clojure.lang.IPersistentList [o w] (print-method o w)) 331.145 -(prefer-method print-method clojure.lang.ISeq clojure.lang.IPersistentCollection) 331.146 -(prefer-method print-dup clojure.lang.ISeq clojure.lang.IPersistentCollection) 331.147 -(prefer-method print-method clojure.lang.ISeq java.util.Collection) 331.148 -(prefer-method print-dup clojure.lang.ISeq java.util.Collection) 331.149 - 331.150 - 331.151 - 331.152 -(defmethod print-dup java.util.Collection [o, ^Writer w] 331.153 - (print-ctor o #(print-sequential "[" print-dup " " "]" %1 %2) w)) 331.154 - 331.155 -(defmethod print-dup clojure.lang.IPersistentCollection [o, ^Writer w] 331.156 - (print-meta o w) 331.157 - (.write w "#=(") 331.158 - (.write w (.getName ^Class (class o))) 331.159 - (.write w "/create ") 331.160 - (print-sequential "[" print-dup " " "]" o w) 331.161 - (.write w ")")) 331.162 - 331.163 -(prefer-method print-dup clojure.lang.IPersistentCollection java.util.Collection) 331.164 - 331.165 -(def ^{:tag String 331.166 - :doc "Returns escape string for char or nil if none" 331.167 - :added "1.0"} 331.168 - char-escape-string 331.169 - {\newline "\\n" 331.170 - \tab "\\t" 331.171 - \return "\\r" 331.172 - \" "\\\"" 331.173 - \\ "\\\\" 331.174 - \formfeed "\\f" 331.175 - \backspace "\\b"}) 331.176 - 331.177 -(defmethod print-method String [^String s, ^Writer w] 331.178 - (if (or *print-dup* *print-readably*) 331.179 - (do (.append w \") 331.180 - (dotimes [n (count s)] 331.181 - (let [c (.charAt s n) 331.182 - e (char-escape-string c)] 331.183 - (if e (.write w e) (.append w c)))) 331.184 - (.append w \")) 331.185 - (.write w s)) 331.186 - nil) 331.187 - 331.188 -(defmethod print-dup String [s w] (print-method s w)) 331.189 - 331.190 -(defmethod print-method clojure.lang.IPersistentVector [v, ^Writer w] 331.191 - (print-meta v w) 331.192 - (print-sequential "[" pr-on " " "]" v w)) 331.193 - 331.194 -(defn- print-map [m print-one w] 331.195 - (print-sequential 331.196 - "{" 331.197 - (fn [e ^Writer w] 331.198 - (do (print-one (key e) w) (.append w \space) (print-one (val e) w))) 331.199 - ", " 331.200 - "}" 331.201 - (seq m) w)) 331.202 - 331.203 -(defmethod print-method clojure.lang.IPersistentMap [m, ^Writer w] 331.204 - (print-meta m w) 331.205 - (print-map m pr-on w)) 331.206 - 331.207 -(defmethod print-dup java.util.Map [m, ^Writer w] 331.208 - (print-ctor m #(print-map (seq %1) print-dup %2) w)) 331.209 - 331.210 -(defmethod print-dup clojure.lang.IPersistentMap [m, ^Writer w] 331.211 - (print-meta m w) 331.212 - (.write w "#=(") 331.213 - (.write w (.getName (class m))) 331.214 - (.write w "/create ") 331.215 - (print-map m print-dup w) 331.216 - (.write w ")")) 331.217 - 331.218 -(prefer-method print-dup clojure.lang.IPersistentCollection java.util.Map) 331.219 - 331.220 -(defmethod print-method clojure.lang.IPersistentSet [s, ^Writer w] 331.221 - (print-meta s w) 331.222 - (print-sequential "#{" pr-on " " "}" (seq s) w)) 331.223 - 331.224 -(def ^{:tag String 331.225 - :doc "Returns name string for char or nil if none" 331.226 - :added "1.0"} 331.227 - char-name-string 331.228 - {\newline "newline" 331.229 - \tab "tab" 331.230 - \space "space" 331.231 - \backspace "backspace" 331.232 - \formfeed "formfeed" 331.233 - \return "return"}) 331.234 - 331.235 -(defmethod print-method java.lang.Character [^Character c, ^Writer w] 331.236 - (if (or *print-dup* *print-readably*) 331.237 - (do (.append w \\) 331.238 - (let [n (char-name-string c)] 331.239 - (if n (.write w n) (.append w c)))) 331.240 - (.append w c)) 331.241 - nil) 331.242 - 331.243 -(defmethod print-dup java.lang.Character [c w] (print-method c w)) 331.244 -(defmethod print-dup java.lang.Integer [o w] (print-method o w)) 331.245 -(defmethod print-dup java.lang.Double [o w] (print-method o w)) 331.246 -(defmethod print-dup clojure.lang.Ratio [o w] (print-method o w)) 331.247 -(defmethod print-dup java.math.BigDecimal [o w] (print-method o w)) 331.248 -(defmethod print-dup clojure.lang.PersistentHashMap [o w] (print-method o w)) 331.249 -(defmethod print-dup clojure.lang.PersistentHashSet [o w] (print-method o w)) 331.250 -(defmethod print-dup clojure.lang.PersistentVector [o w] (print-method o w)) 331.251 -(defmethod print-dup clojure.lang.LazilyPersistentVector [o w] (print-method o w)) 331.252 - 331.253 -(def primitives-classnames 331.254 - {Float/TYPE "Float/TYPE" 331.255 - Integer/TYPE "Integer/TYPE" 331.256 - Long/TYPE "Long/TYPE" 331.257 - Boolean/TYPE "Boolean/TYPE" 331.258 - Character/TYPE "Character/TYPE" 331.259 - Double/TYPE "Double/TYPE" 331.260 - Byte/TYPE "Byte/TYPE" 331.261 - Short/TYPE "Short/TYPE"}) 331.262 - 331.263 -(defmethod print-method Class [^Class c, ^Writer w] 331.264 - (.write w (.getName c))) 331.265 - 331.266 -(defmethod print-dup Class [^Class c, ^Writer w] 331.267 - (cond 331.268 - (.isPrimitive c) (do 331.269 - (.write w "#=(identity ") 331.270 - (.write w ^String (primitives-classnames c)) 331.271 - (.write w ")")) 331.272 - (.isArray c) (do 331.273 - (.write w "#=(java.lang.Class/forName \"") 331.274 - (.write w (.getName c)) 331.275 - (.write w "\")")) 331.276 - :else (do 331.277 - (.write w "#=") 331.278 - (.write w (.getName c))))) 331.279 - 331.280 -(defmethod print-method java.math.BigDecimal [b, ^Writer w] 331.281 - (.write w (str b)) 331.282 - (.write w "M")) 331.283 - 331.284 -(defmethod print-method java.util.regex.Pattern [p ^Writer w] 331.285 - (.write w "#\"") 331.286 - (loop [[^Character c & r :as s] (seq (.pattern ^java.util.regex.Pattern p)) 331.287 - qmode false] 331.288 - (when s 331.289 - (cond 331.290 - (= c \\) (let [[^Character c2 & r2] r] 331.291 - (.append w \\) 331.292 - (.append w c2) 331.293 - (if qmode 331.294 - (recur r2 (not= c2 \E)) 331.295 - (recur r2 (= c2 \Q)))) 331.296 - (= c \") (do 331.297 - (if qmode 331.298 - (.write w "\\E\\\"\\Q") 331.299 - (.write w "\\\"")) 331.300 - (recur r qmode)) 331.301 - :else (do 331.302 - (.append w c) 331.303 - (recur r qmode))))) 331.304 - (.append w \")) 331.305 - 331.306 -(defmethod print-dup java.util.regex.Pattern [p ^Writer w] (print-method p w)) 331.307 - 331.308 -(defmethod print-dup clojure.lang.Namespace [^clojure.lang.Namespace n ^Writer w] 331.309 - (.write w "#=(find-ns ") 331.310 - (print-dup (.name n) w) 331.311 - (.write w ")")) 331.312 - 331.313 -(defmethod print-method clojure.lang.IDeref [o ^Writer w] 331.314 - (print-sequential (format "#<%s@%x%s: " 331.315 - (.getSimpleName (class o)) 331.316 - (System/identityHashCode o) 331.317 - (if (and (instance? clojure.lang.Agent o) 331.318 - (agent-error o)) 331.319 - " FAILED" 331.320 - "")) 331.321 - pr-on, "", ">", (list (if (and (future? o) (not (future-done? o))) :pending @o)), w)) 331.322 - 331.323 -(def ^{:private true} print-initialized true)
332.1 --- a/src/clojure/core_proxy.clj Sat Aug 21 06:25:44 2010 -0400 332.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 332.3 @@ -1,407 +0,0 @@ 332.4 -; Copyright (c) Rich Hickey. All rights reserved. 332.5 -; The use and distribution terms for this software are covered by the 332.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 332.7 -; which can be found in the file epl-v10.html at the root of this distribution. 332.8 -; By using this software in any fashion, you are agreeing to be bound by 332.9 -; the terms of this license. 332.10 -; You must not remove this notice, or any other, from this software. 332.11 - 332.12 -(in-ns 'clojure.core) 332.13 - 332.14 -;;;;;;;;;;;;;;;;;;;;;;;;;;;; proxy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 332.15 - 332.16 -(import 332.17 - '(clojure.asm ClassWriter ClassVisitor Opcodes Type) 332.18 - '(java.lang.reflect Modifier Constructor) 332.19 - '(clojure.asm.commons Method GeneratorAdapter) 332.20 - '(clojure.lang IProxy Reflector DynamicClassLoader IPersistentMap PersistentHashMap RT)) 332.21 - 332.22 -(defn method-sig [^java.lang.reflect.Method meth] 332.23 - [(. meth (getName)) (seq (. meth (getParameterTypes))) (. meth getReturnType)]) 332.24 - 332.25 -(defn- most-specific [rtypes] 332.26 - (or (some (fn [t] (when (every? #(isa? t %) rtypes) t)) rtypes) 332.27 - (throw (Exception. "Incompatible return types")))) 332.28 - 332.29 -(defn- group-by-sig [coll] 332.30 - "takes a collection of [msig meth] and returns a seq of maps from return-types to meths." 332.31 - (vals (reduce (fn [m [msig meth]] 332.32 - (let [rtype (peek msig) 332.33 - argsig (pop msig)] 332.34 - (assoc m argsig (assoc (m argsig {}) rtype meth)))) 332.35 - {} coll))) 332.36 - 332.37 -(defn proxy-name 332.38 - {:tag String} 332.39 - [^Class super interfaces] 332.40 - (let [inames (into (sorted-set) (map #(.getName ^Class %) interfaces))] 332.41 - (apply str (.replace (str *ns*) \- \_) ".proxy" 332.42 - (interleave (repeat "$") 332.43 - (concat 332.44 - [(.getName super)] 332.45 - (map #(subs % (inc (.lastIndexOf ^String % "."))) inames) 332.46 - [(Integer/toHexString (hash inames))]))))) 332.47 - 332.48 -(defn- generate-proxy [^Class super interfaces] 332.49 - (let [cv (new ClassWriter (. ClassWriter COMPUTE_MAXS)) 332.50 - cname (.replace (proxy-name super interfaces) \. \/) ;(str "clojure/lang/" (gensym "Proxy__")) 332.51 - ctype (. Type (getObjectType cname)) 332.52 - iname (fn [^Class c] (.. Type (getType c) (getInternalName))) 332.53 - fmap "__clojureFnMap" 332.54 - totype (fn [^Class c] (. Type (getType c))) 332.55 - to-types (fn [cs] (if (pos? (count cs)) 332.56 - (into-array (map totype cs)) 332.57 - (make-array Type 0))) 332.58 - super-type ^Type (totype super) 332.59 - imap-type ^Type (totype IPersistentMap) 332.60 - ifn-type (totype clojure.lang.IFn) 332.61 - obj-type (totype Object) 332.62 - sym-type (totype clojure.lang.Symbol) 332.63 - rt-type (totype clojure.lang.RT) 332.64 - ex-type (totype java.lang.UnsupportedOperationException) 332.65 - gen-bridge 332.66 - (fn [^java.lang.reflect.Method meth ^java.lang.reflect.Method dest] 332.67 - (let [pclasses (. meth (getParameterTypes)) 332.68 - ptypes (to-types pclasses) 332.69 - rtype ^Type (totype (. meth (getReturnType))) 332.70 - m (new Method (. meth (getName)) rtype ptypes) 332.71 - dtype (totype (.getDeclaringClass dest)) 332.72 - dm (new Method (. dest (getName)) (totype (. dest (getReturnType))) (to-types (. dest (getParameterTypes)))) 332.73 - gen (new GeneratorAdapter (bit-or (. Opcodes ACC_PUBLIC) (. Opcodes ACC_BRIDGE)) m nil nil cv)] 332.74 - (. gen (visitCode)) 332.75 - (. gen (loadThis)) 332.76 - (dotimes [i (count ptypes)] 332.77 - (. gen (loadArg i))) 332.78 - (if (-> dest .getDeclaringClass .isInterface) 332.79 - (. gen (invokeInterface dtype dm)) 332.80 - (. gen (invokeVirtual dtype dm))) 332.81 - (. gen (returnValue)) 332.82 - (. gen (endMethod)))) 332.83 - gen-method 332.84 - (fn [^java.lang.reflect.Method meth else-gen] 332.85 - (let [pclasses (. meth (getParameterTypes)) 332.86 - ptypes (to-types pclasses) 332.87 - rtype ^Type (totype (. meth (getReturnType))) 332.88 - m (new Method (. meth (getName)) rtype ptypes) 332.89 - gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv) 332.90 - else-label (. gen (newLabel)) 332.91 - end-label (. gen (newLabel)) 332.92 - decl-type (. Type (getType (. meth (getDeclaringClass))))] 332.93 - (. gen (visitCode)) 332.94 - (if (> (count pclasses) 18) 332.95 - (else-gen gen m) 332.96 - (do 332.97 - (. gen (loadThis)) 332.98 - (. gen (getField ctype fmap imap-type)) 332.99 - 332.100 - (. gen (push (. meth (getName)))) 332.101 - ;lookup fn in map 332.102 - (. gen (invokeStatic rt-type (. Method (getMethod "Object get(Object, Object)")))) 332.103 - (. gen (dup)) 332.104 - (. gen (ifNull else-label)) 332.105 - ;if found 332.106 - (.checkCast gen ifn-type) 332.107 - (. gen (loadThis)) 332.108 - ;box args 332.109 - (dotimes [i (count ptypes)] 332.110 - (. gen (loadArg i)) 332.111 - (. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i)))) 332.112 - ;call fn 332.113 - (. gen (invokeInterface ifn-type (new Method "invoke" obj-type 332.114 - (into-array (cons obj-type 332.115 - (replicate (count ptypes) obj-type)))))) 332.116 - ;unbox return 332.117 - (. gen (unbox rtype)) 332.118 - (when (= (. rtype (getSort)) (. Type VOID)) 332.119 - (. gen (pop))) 332.120 - (. gen (goTo end-label)) 332.121 - 332.122 - ;else call supplied alternative generator 332.123 - (. gen (mark else-label)) 332.124 - (. gen (pop)) 332.125 - 332.126 - (else-gen gen m) 332.127 - 332.128 - (. gen (mark end-label)))) 332.129 - (. gen (returnValue)) 332.130 - (. gen (endMethod))))] 332.131 - 332.132 - ;start class definition 332.133 - (. cv (visit (. Opcodes V1_5) (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_SUPER)) 332.134 - cname nil (iname super) 332.135 - (into-array (map iname (cons IProxy interfaces))))) 332.136 - ;add field for fn mappings 332.137 - (. cv (visitField (+ (. Opcodes ACC_PRIVATE) (. Opcodes ACC_VOLATILE)) 332.138 - fmap (. imap-type (getDescriptor)) nil nil)) 332.139 - ;add ctors matching/calling super's 332.140 - (doseq [^Constructor ctor (. super (getDeclaredConstructors))] 332.141 - (when-not (. Modifier (isPrivate (. ctor (getModifiers)))) 332.142 - (let [ptypes (to-types (. ctor (getParameterTypes))) 332.143 - m (new Method "<init>" (. Type VOID_TYPE) ptypes) 332.144 - gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)] 332.145 - (. gen (visitCode)) 332.146 - ;call super ctor 332.147 - (. gen (loadThis)) 332.148 - (. gen (dup)) 332.149 - (. gen (loadArgs)) 332.150 - (. gen (invokeConstructor super-type m)) 332.151 - 332.152 - (. gen (returnValue)) 332.153 - (. gen (endMethod))))) 332.154 - ;add IProxy methods 332.155 - (let [m (. Method (getMethod "void __initClojureFnMappings(clojure.lang.IPersistentMap)")) 332.156 - gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)] 332.157 - (. gen (visitCode)) 332.158 - (. gen (loadThis)) 332.159 - (. gen (loadArgs)) 332.160 - (. gen (putField ctype fmap imap-type)) 332.161 - 332.162 - (. gen (returnValue)) 332.163 - (. gen (endMethod))) 332.164 - (let [m (. Method (getMethod "void __updateClojureFnMappings(clojure.lang.IPersistentMap)")) 332.165 - gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)] 332.166 - (. gen (visitCode)) 332.167 - (. gen (loadThis)) 332.168 - (. gen (dup)) 332.169 - (. gen (getField ctype fmap imap-type)) 332.170 - (.checkCast gen (totype clojure.lang.IPersistentCollection)) 332.171 - (. gen (loadArgs)) 332.172 - (. gen (invokeInterface (totype clojure.lang.IPersistentCollection) 332.173 - (. Method (getMethod "clojure.lang.IPersistentCollection cons(Object)")))) 332.174 - (. gen (checkCast imap-type)) 332.175 - (. gen (putField ctype fmap imap-type)) 332.176 - 332.177 - (. gen (returnValue)) 332.178 - (. gen (endMethod))) 332.179 - (let [m (. Method (getMethod "clojure.lang.IPersistentMap __getClojureFnMappings()")) 332.180 - gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)] 332.181 - (. gen (visitCode)) 332.182 - (. gen (loadThis)) 332.183 - (. gen (getField ctype fmap imap-type)) 332.184 - (. gen (returnValue)) 332.185 - (. gen (endMethod))) 332.186 - 332.187 - ;calc set of supers' non-private instance methods 332.188 - (let [[mm considered] 332.189 - (loop [mm {} considered #{} c super] 332.190 - (if c 332.191 - (let [[mm considered] 332.192 - (loop [mm mm 332.193 - considered considered 332.194 - meths (concat 332.195 - (seq (. c (getDeclaredMethods))) 332.196 - (seq (. c (getMethods))))] 332.197 - (if (seq meths) 332.198 - (let [^java.lang.reflect.Method meth (first meths) 332.199 - mods (. meth (getModifiers)) 332.200 - mk (method-sig meth)] 332.201 - (if (or (considered mk) 332.202 - (not (or (Modifier/isPublic mods) (Modifier/isProtected mods))) 332.203 - ;(. Modifier (isPrivate mods)) 332.204 - (. Modifier (isStatic mods)) 332.205 - (. Modifier (isFinal mods)) 332.206 - (= "finalize" (.getName meth))) 332.207 - (recur mm (conj considered mk) (next meths)) 332.208 - (recur (assoc mm mk meth) (conj considered mk) (next meths)))) 332.209 - [mm considered]))] 332.210 - (recur mm considered (. c (getSuperclass)))) 332.211 - [mm considered])) 332.212 - ifaces-meths (into {} 332.213 - (for [^Class iface interfaces meth (. iface (getMethods)) 332.214 - :let [msig (method-sig meth)] :when (not (considered msig))] 332.215 - {msig meth})) 332.216 - mgroups (group-by-sig (concat mm ifaces-meths)) 332.217 - rtypes (map #(most-specific (keys %)) mgroups) 332.218 - mb (map #(vector (%1 %2) (vals (dissoc %1 %2))) mgroups rtypes) 332.219 - bridge? (reduce into #{} (map second mb)) 332.220 - ifaces-meths (remove bridge? (vals ifaces-meths)) 332.221 - mm (remove bridge? (vals mm))] 332.222 - ;add methods matching supers', if no mapping -> call super 332.223 - (doseq [[^java.lang.reflect.Method dest bridges] mb 332.224 - ^java.lang.reflect.Method meth bridges] 332.225 - (gen-bridge meth dest)) 332.226 - (doseq [^java.lang.reflect.Method meth mm] 332.227 - (gen-method meth 332.228 - (fn [^GeneratorAdapter gen ^Method m] 332.229 - (. gen (loadThis)) 332.230 - ;push args 332.231 - (. gen (loadArgs)) 332.232 - ;call super 332.233 - (. gen (visitMethodInsn (. Opcodes INVOKESPECIAL) 332.234 - (. super-type (getInternalName)) 332.235 - (. m (getName)) 332.236 - (. m (getDescriptor))))))) 332.237 - 332.238 - ;add methods matching interfaces', if no mapping -> throw 332.239 - (doseq [^java.lang.reflect.Method meth ifaces-meths] 332.240 - (gen-method meth 332.241 - (fn [^GeneratorAdapter gen ^Method m] 332.242 - (. gen (throwException ex-type (. m (getName)))))))) 332.243 - 332.244 - ;finish class def 332.245 - (. cv (visitEnd)) 332.246 - [cname (. cv toByteArray)])) 332.247 - 332.248 -(defn- get-super-and-interfaces [bases] 332.249 - (if (. ^Class (first bases) (isInterface)) 332.250 - [Object bases] 332.251 - [(first bases) (next bases)])) 332.252 - 332.253 -(defn get-proxy-class 332.254 - "Takes an optional single class followed by zero or more 332.255 - interfaces. If not supplied class defaults to Object. Creates an 332.256 - returns an instance of a proxy class derived from the supplied 332.257 - classes. The resulting value is cached and used for any subsequent 332.258 - requests for the same class set. Returns a Class object." 332.259 - {:added "1.0"} 332.260 - [& bases] 332.261 - (let [[super interfaces] (get-super-and-interfaces bases) 332.262 - pname (proxy-name super interfaces)] 332.263 - (or (RT/loadClassForName pname) 332.264 - (let [[cname bytecode] (generate-proxy super interfaces)] 332.265 - (. ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER) (defineClass pname bytecode [super interfaces])))))) 332.266 - 332.267 -(defn construct-proxy 332.268 - "Takes a proxy class and any arguments for its superclass ctor and 332.269 - creates and returns an instance of the proxy." 332.270 - {:added "1.0"} 332.271 - [c & ctor-args] 332.272 - (. Reflector (invokeConstructor c (to-array ctor-args)))) 332.273 - 332.274 -(defn init-proxy 332.275 - "Takes a proxy instance and a map of strings (which must 332.276 - correspond to methods of the proxy superclass/superinterfaces) to 332.277 - fns (which must take arguments matching the corresponding method, 332.278 - plus an additional (explicit) first arg corresponding to this, and 332.279 - sets the proxy's fn map." 332.280 - {:added "1.0"} 332.281 - [^IProxy proxy mappings] 332.282 - (. proxy (__initClojureFnMappings mappings))) 332.283 - 332.284 -(defn update-proxy 332.285 - "Takes a proxy instance and a map of strings (which must 332.286 - correspond to methods of the proxy superclass/superinterfaces) to 332.287 - fns (which must take arguments matching the corresponding method, 332.288 - plus an additional (explicit) first arg corresponding to this, and 332.289 - updates (via assoc) the proxy's fn map. nil can be passed instead of 332.290 - a fn, in which case the corresponding method will revert to the 332.291 - default behavior. Note that this function can be used to update the 332.292 - behavior of an existing instance without changing its identity." 332.293 - {:added "1.0"} 332.294 - [^IProxy proxy mappings] 332.295 - (. proxy (__updateClojureFnMappings mappings))) 332.296 - 332.297 -(defn proxy-mappings 332.298 - "Takes a proxy instance and returns the proxy's fn map." 332.299 - {:added "1.0"} 332.300 - [^IProxy proxy] 332.301 - (. proxy (__getClojureFnMappings))) 332.302 - 332.303 -(defmacro proxy 332.304 - "class-and-interfaces - a vector of class names 332.305 - 332.306 - args - a (possibly empty) vector of arguments to the superclass 332.307 - constructor. 332.308 - 332.309 - f => (name [params*] body) or 332.310 - (name ([params*] body) ([params+] body) ...) 332.311 - 332.312 - Expands to code which creates a instance of a proxy class that 332.313 - implements the named class/interface(s) by calling the supplied 332.314 - fns. A single class, if provided, must be first. If not provided it 332.315 - defaults to Object. 332.316 - 332.317 - The interfaces names must be valid interface types. If a method fn 332.318 - is not provided for a class method, the superclass methd will be 332.319 - called. If a method fn is not provided for an interface method, an 332.320 - UnsupportedOperationException will be thrown should it be 332.321 - called. Method fns are closures and can capture the environment in 332.322 - which proxy is called. Each method fn takes an additional implicit 332.323 - first arg, which is bound to 'this. Note that while method fns can 332.324 - be provided to override protected methods, they have no other access 332.325 - to protected members, nor to super, as these capabilities cannot be 332.326 - proxied." 332.327 - {:added "1.0"} 332.328 - [class-and-interfaces args & fs] 332.329 - (let [bases (map #(or (resolve %) (throw (Exception. (str "Can't resolve: " %)))) 332.330 - class-and-interfaces) 332.331 - [super interfaces] (get-super-and-interfaces bases) 332.332 - compile-effect (when *compile-files* 332.333 - (let [[cname bytecode] (generate-proxy super interfaces)] 332.334 - (clojure.lang.Compiler/writeClassFile cname bytecode))) 332.335 - pc-effect (apply get-proxy-class bases) 332.336 - pname (proxy-name super interfaces)] 332.337 - ;remember the class to prevent it from disappearing before use 332.338 - (intern *ns* (symbol pname) pc-effect) 332.339 - `(let [;pc# (get-proxy-class ~@class-and-interfaces) 332.340 - p# (new ~(symbol pname) ~@args)] ;(construct-proxy pc# ~@args)] 332.341 - (init-proxy p# 332.342 - ~(loop [fmap {} fs fs] 332.343 - (if fs 332.344 - (let [[sym & meths] (first fs) 332.345 - meths (if (vector? (first meths)) 332.346 - (list meths) 332.347 - meths) 332.348 - meths (map (fn [[params & body]] 332.349 - (cons (apply vector 'this params) body)) 332.350 - meths)] 332.351 - (if-not (contains? fmap (name sym)) 332.352 - (recur (assoc fmap (name sym) (cons `fn meths)) (next fs)) 332.353 - (throw (IllegalArgumentException. 332.354 - (str "Method '" (name sym) "' redefined"))))) 332.355 - fmap))) 332.356 - p#))) 332.357 - 332.358 -(defn proxy-call-with-super [call this meth] 332.359 - (let [m (proxy-mappings this)] 332.360 - (update-proxy this (assoc m meth nil)) 332.361 - (let [ret (call)] 332.362 - (update-proxy this m) 332.363 - ret))) 332.364 - 332.365 -(defmacro proxy-super 332.366 - "Use to call a superclass method in the body of a proxy method. 332.367 - Note, expansion captures 'this" 332.368 - {:added "1.0"} 332.369 - [meth & args] 332.370 - `(proxy-call-with-super (fn [] (. ~'this ~meth ~@args)) ~'this ~(name meth))) 332.371 - 332.372 -(defn bean 332.373 - "Takes a Java object and returns a read-only implementation of the 332.374 - map abstraction based upon its JavaBean properties." 332.375 - {:added "1.0"} 332.376 - [^Object x] 332.377 - (let [c (. x (getClass)) 332.378 - pmap (reduce (fn [m ^java.beans.PropertyDescriptor pd] 332.379 - (let [name (. pd (getName)) 332.380 - method (. pd (getReadMethod))] 332.381 - (if (and method (zero? (alength (. method (getParameterTypes))))) 332.382 - (assoc m (keyword name) (fn [] (clojure.lang.Reflector/prepRet (. method (invoke x nil))))) 332.383 - m))) 332.384 - {} 332.385 - (seq (.. java.beans.Introspector 332.386 - (getBeanInfo c) 332.387 - (getPropertyDescriptors)))) 332.388 - v (fn [k] ((pmap k))) 332.389 - snapshot (fn [] 332.390 - (reduce (fn [m e] 332.391 - (assoc m (key e) ((val e)))) 332.392 - {} (seq pmap)))] 332.393 - (proxy [clojure.lang.APersistentMap] 332.394 - [] 332.395 - (containsKey [k] (contains? pmap k)) 332.396 - (entryAt [k] (when (contains? pmap k) (new clojure.lang.MapEntry k (v k)))) 332.397 - (valAt ([k] (v k)) 332.398 - ([k default] (if (contains? pmap k) (v k) default))) 332.399 - (cons [m] (conj (snapshot) m)) 332.400 - (count [] (count pmap)) 332.401 - (assoc [k v] (assoc (snapshot) k v)) 332.402 - (without [k] (dissoc (snapshot) k)) 332.403 - (seq [] ((fn thisfn [plseq] 332.404 - (lazy-seq 332.405 - (when-let [pseq (seq plseq)] 332.406 - (cons (new clojure.lang.MapEntry (first pseq) (v (first pseq))) 332.407 - (thisfn (rest pseq)))))) (keys pmap)))))) 332.408 - 332.409 - 332.410 -
333.1 --- a/src/clojure/genclass.clj Sat Aug 21 06:25:44 2010 -0400 333.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 333.3 @@ -1,714 +0,0 @@ 333.4 -; Copyright (c) Rich Hickey. All rights reserved. 333.5 -; The use and distribution terms for this software are covered by the 333.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 333.7 -; which can be found in the file epl-v10.html at the root of this distribution. 333.8 -; By using this software in any fashion, you are agreeing to be bound by 333.9 -; the terms of this license. 333.10 -; You must not remove this notice, or any other, from this software. 333.11 - 333.12 -(in-ns 'clojure.core) 333.13 - 333.14 -(import '(java.lang.reflect Modifier Constructor) 333.15 - '(clojure.asm ClassWriter ClassVisitor Opcodes Type) 333.16 - '(clojure.asm.commons Method GeneratorAdapter) 333.17 - '(clojure.lang IPersistentMap)) 333.18 - 333.19 -;(defn method-sig [^java.lang.reflect.Method meth] 333.20 -; [(. meth (getName)) (seq (. meth (getParameterTypes)))]) 333.21 - 333.22 -(defn- non-private-methods [^Class c] 333.23 - (loop [mm {} 333.24 - considered #{} 333.25 - c c] 333.26 - (if c 333.27 - (let [[mm considered] 333.28 - (loop [mm mm 333.29 - considered considered 333.30 - meths (seq (concat 333.31 - (seq (. c (getDeclaredMethods))) 333.32 - (seq (. c (getMethods)))))] 333.33 - (if meths 333.34 - (let [^java.lang.reflect.Method meth (first meths) 333.35 - mods (. meth (getModifiers)) 333.36 - mk (method-sig meth)] 333.37 - (if (or (considered mk) 333.38 - (not (or (Modifier/isPublic mods) (Modifier/isProtected mods))) 333.39 - ;(. Modifier (isPrivate mods)) 333.40 - (. Modifier (isStatic mods)) 333.41 - (. Modifier (isFinal mods)) 333.42 - (= "finalize" (.getName meth))) 333.43 - (recur mm (conj considered mk) (next meths)) 333.44 - (recur (assoc mm mk meth) (conj considered mk) (next meths)))) 333.45 - [mm considered]))] 333.46 - (recur mm considered (. c (getSuperclass)))) 333.47 - mm))) 333.48 - 333.49 -(defn- ctor-sigs [^Class super] 333.50 - (for [^Constructor ctor (. super (getDeclaredConstructors)) 333.51 - :when (not (. Modifier (isPrivate (. ctor (getModifiers)))))] 333.52 - (apply vector (. ctor (getParameterTypes))))) 333.53 - 333.54 -(defn- escape-class-name [^Class c] 333.55 - (.. (.getSimpleName c) 333.56 - (replace "[]" "<>"))) 333.57 - 333.58 -(defn- overload-name [mname pclasses] 333.59 - (if (seq pclasses) 333.60 - (apply str mname (interleave (repeat \-) 333.61 - (map escape-class-name pclasses))) 333.62 - (str mname "-void"))) 333.63 - 333.64 -(defn- ^java.lang.reflect.Field find-field [^Class c f] 333.65 - (let [start-class c] 333.66 - (loop [c c] 333.67 - (if (= c Object) 333.68 - (throw (new Exception (str "field, " f ", not defined in class, " start-class ", or its ancestors"))) 333.69 - (let [dflds (.getDeclaredFields c) 333.70 - rfld (first (filter #(= f (.getName ^java.lang.reflect.Field %)) dflds))] 333.71 - (or rfld (recur (.getSuperclass c)))))))) 333.72 - 333.73 -;(distinct (map first(keys (mapcat non-private-methods [Object IPersistentMap])))) 333.74 - 333.75 -(def ^{:private true} prim->class 333.76 - {'int Integer/TYPE 333.77 - 'long Long/TYPE 333.78 - 'float Float/TYPE 333.79 - 'double Double/TYPE 333.80 - 'void Void/TYPE 333.81 - 'short Short/TYPE 333.82 - 'boolean Boolean/TYPE 333.83 - 'byte Byte/TYPE 333.84 - 'char Character/TYPE}) 333.85 - 333.86 -(defn- ^Class the-class [x] 333.87 - (cond 333.88 - (class? x) x 333.89 - (contains? prim->class x) (prim->class x) 333.90 - :else (let [strx (str x)] 333.91 - (clojure.lang.RT/classForName 333.92 - (if (some #{\. \[} strx) 333.93 - strx 333.94 - (str "java.lang." strx)))))) 333.95 - 333.96 -;; someday this can be made codepoint aware 333.97 -(defn- valid-java-method-name 333.98 - [^String s] 333.99 - (= s (clojure.lang.Compiler/munge s))) 333.100 - 333.101 -(defn- validate-generate-class-options 333.102 - [{:keys [methods]}] 333.103 - (let [[mname] (remove valid-java-method-name (map (comp str first) methods))] 333.104 - (when mname (throw (IllegalArgumentException. (str "Not a valid method name: " mname)))))) 333.105 - 333.106 -(defn- generate-class [options-map] 333.107 - (validate-generate-class-options options-map) 333.108 - (let [default-options {:prefix "-" :load-impl-ns true :impl-ns (ns-name *ns*)} 333.109 - {:keys [name extends implements constructors methods main factory state init exposes 333.110 - exposes-methods prefix load-impl-ns impl-ns post-init]} 333.111 - (merge default-options options-map) 333.112 - name-meta (meta name) 333.113 - name (str name) 333.114 - super (if extends (the-class extends) Object) 333.115 - interfaces (map the-class implements) 333.116 - supers (cons super interfaces) 333.117 - ctor-sig-map (or constructors (zipmap (ctor-sigs super) (ctor-sigs super))) 333.118 - cv (new ClassWriter (. ClassWriter COMPUTE_MAXS)) 333.119 - cname (. name (replace "." "/")) 333.120 - pkg-name name 333.121 - impl-pkg-name (str impl-ns) 333.122 - impl-cname (.. impl-pkg-name (replace "." "/") (replace \- \_)) 333.123 - ctype (. Type (getObjectType cname)) 333.124 - iname (fn [^Class c] (.. Type (getType c) (getInternalName))) 333.125 - totype (fn [^Class c] (. Type (getType c))) 333.126 - to-types (fn [cs] (if (pos? (count cs)) 333.127 - (into-array (map totype cs)) 333.128 - (make-array Type 0))) 333.129 - obj-type ^Type (totype Object) 333.130 - arg-types (fn [n] (if (pos? n) 333.131 - (into-array (replicate n obj-type)) 333.132 - (make-array Type 0))) 333.133 - super-type ^Type (totype super) 333.134 - init-name (str init) 333.135 - post-init-name (str post-init) 333.136 - factory-name (str factory) 333.137 - state-name (str state) 333.138 - main-name "main" 333.139 - var-name (fn [s] (clojure.lang.Compiler/munge (str s "__var"))) 333.140 - class-type (totype Class) 333.141 - rt-type (totype clojure.lang.RT) 333.142 - var-type ^Type (totype clojure.lang.Var) 333.143 - ifn-type (totype clojure.lang.IFn) 333.144 - iseq-type (totype clojure.lang.ISeq) 333.145 - ex-type (totype java.lang.UnsupportedOperationException) 333.146 - all-sigs (distinct (concat (map #(let[[m p] (key %)] {m [p]}) (mapcat non-private-methods supers)) 333.147 - (map (fn [[m p]] {(str m) [p]}) methods))) 333.148 - sigs-by-name (apply merge-with concat {} all-sigs) 333.149 - overloads (into {} (filter (fn [[m s]] (next s)) sigs-by-name)) 333.150 - var-fields (concat (when init [init-name]) 333.151 - (when post-init [post-init-name]) 333.152 - (when main [main-name]) 333.153 - ;(when exposes-methods (map str (vals exposes-methods))) 333.154 - (distinct (concat (keys sigs-by-name) 333.155 - (mapcat (fn [[m s]] (map #(overload-name m (map the-class %)) s)) overloads) 333.156 - (mapcat (comp (partial map str) vals val) exposes)))) 333.157 - emit-get-var (fn [^GeneratorAdapter gen v] 333.158 - (let [false-label (. gen newLabel) 333.159 - end-label (. gen newLabel)] 333.160 - (. gen getStatic ctype (var-name v) var-type) 333.161 - (. gen dup) 333.162 - (. gen invokeVirtual var-type (. Method (getMethod "boolean isBound()"))) 333.163 - (. gen ifZCmp (. GeneratorAdapter EQ) false-label) 333.164 - (. gen invokeVirtual var-type (. Method (getMethod "Object get()"))) 333.165 - (. gen goTo end-label) 333.166 - (. gen mark false-label) 333.167 - (. gen pop) 333.168 - (. gen visitInsn (. Opcodes ACONST_NULL)) 333.169 - (. gen mark end-label))) 333.170 - emit-unsupported (fn [^GeneratorAdapter gen ^Method m] 333.171 - (. gen (throwException ex-type (str (. m (getName)) " (" 333.172 - impl-pkg-name "/" prefix (.getName m) 333.173 - " not defined?)")))) 333.174 - emit-forwarding-method 333.175 - (fn [name pclasses rclass as-static else-gen] 333.176 - (let [mname (str name) 333.177 - pmetas (map meta pclasses) 333.178 - pclasses (map the-class pclasses) 333.179 - rclass (the-class rclass) 333.180 - ptypes (to-types pclasses) 333.181 - rtype ^Type (totype rclass) 333.182 - m (new Method mname rtype ptypes) 333.183 - is-overload (seq (overloads mname)) 333.184 - gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (if as-static (. Opcodes ACC_STATIC) 0)) 333.185 - m nil nil cv) 333.186 - found-label (. gen (newLabel)) 333.187 - else-label (. gen (newLabel)) 333.188 - end-label (. gen (newLabel))] 333.189 - (add-annotations gen (meta name)) 333.190 - (dotimes [i (count pmetas)] 333.191 - (add-annotations gen (nth pmetas i) i)) 333.192 - (. gen (visitCode)) 333.193 - (if (> (count pclasses) 18) 333.194 - (else-gen gen m) 333.195 - (do 333.196 - (when is-overload 333.197 - (emit-get-var gen (overload-name mname pclasses)) 333.198 - (. gen (dup)) 333.199 - (. gen (ifNonNull found-label)) 333.200 - (. gen (pop))) 333.201 - (emit-get-var gen mname) 333.202 - (. gen (dup)) 333.203 - (. gen (ifNull else-label)) 333.204 - (when is-overload 333.205 - (. gen (mark found-label))) 333.206 - ;if found 333.207 - (.checkCast gen ifn-type) 333.208 - (when-not as-static 333.209 - (. gen (loadThis))) 333.210 - ;box args 333.211 - (dotimes [i (count ptypes)] 333.212 - (. gen (loadArg i)) 333.213 - (. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i)))) 333.214 - ;call fn 333.215 - (. gen (invokeInterface ifn-type (new Method "invoke" obj-type 333.216 - (to-types (replicate (+ (count ptypes) 333.217 - (if as-static 0 1)) 333.218 - Object))))) 333.219 - ;(into-array (cons obj-type 333.220 - ; (replicate (count ptypes) obj-type)))))) 333.221 - ;unbox return 333.222 - (. gen (unbox rtype)) 333.223 - (when (= (. rtype (getSort)) (. Type VOID)) 333.224 - (. gen (pop))) 333.225 - (. gen (goTo end-label)) 333.226 - 333.227 - ;else call supplied alternative generator 333.228 - (. gen (mark else-label)) 333.229 - (. gen (pop)) 333.230 - 333.231 - (else-gen gen m) 333.232 - 333.233 - (. gen (mark end-label)))) 333.234 - (. gen (returnValue)) 333.235 - (. gen (endMethod)))) 333.236 - ] 333.237 - ;start class definition 333.238 - (. cv (visit (. Opcodes V1_5) (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_SUPER)) 333.239 - cname nil (iname super) 333.240 - (when-let [ifc (seq interfaces)] 333.241 - (into-array (map iname ifc))))) 333.242 - 333.243 - ; class annotations 333.244 - (add-annotations cv name-meta) 333.245 - 333.246 - ;static fields for vars 333.247 - (doseq [v var-fields] 333.248 - (. cv (visitField (+ (. Opcodes ACC_PRIVATE) (. Opcodes ACC_FINAL) (. Opcodes ACC_STATIC)) 333.249 - (var-name v) 333.250 - (. var-type getDescriptor) 333.251 - nil nil))) 333.252 - 333.253 - ;instance field for state 333.254 - (when state 333.255 - (. cv (visitField (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_FINAL)) 333.256 - state-name 333.257 - (. obj-type getDescriptor) 333.258 - nil nil))) 333.259 - 333.260 - ;static init to set up var fields and load init 333.261 - (let [gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_STATIC)) 333.262 - (. Method getMethod "void <clinit> ()") 333.263 - nil nil cv)] 333.264 - (. gen (visitCode)) 333.265 - (doseq [v var-fields] 333.266 - (. gen push impl-pkg-name) 333.267 - (. gen push (str prefix v)) 333.268 - (. gen (invokeStatic var-type (. Method (getMethod "clojure.lang.Var internPrivate(String,String)")))) 333.269 - (. gen putStatic ctype (var-name v) var-type)) 333.270 - 333.271 - (when load-impl-ns 333.272 - (. gen push "clojure.core") 333.273 - (. gen push "load") 333.274 - (. gen (invokeStatic rt-type (. Method (getMethod "clojure.lang.Var var(String,String)")))) 333.275 - (. gen push (str "/" impl-cname)) 333.276 - (. gen (invokeInterface ifn-type (new Method "invoke" obj-type (to-types [Object])))) 333.277 -; (. gen push (str (.replace impl-pkg-name \- \_) "__init")) 333.278 -; (. gen (invokeStatic class-type (. Method (getMethod "Class forName(String)")))) 333.279 - (. gen pop)) 333.280 - 333.281 - (. gen (returnValue)) 333.282 - (. gen (endMethod))) 333.283 - 333.284 - ;ctors 333.285 - (doseq [[pclasses super-pclasses] ctor-sig-map] 333.286 - (let [pclasses (map the-class pclasses) 333.287 - super-pclasses (map the-class super-pclasses) 333.288 - ptypes (to-types pclasses) 333.289 - super-ptypes (to-types super-pclasses) 333.290 - m (new Method "<init>" (. Type VOID_TYPE) ptypes) 333.291 - super-m (new Method "<init>" (. Type VOID_TYPE) super-ptypes) 333.292 - gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv) 333.293 - no-init-label (. gen newLabel) 333.294 - end-label (. gen newLabel) 333.295 - no-post-init-label (. gen newLabel) 333.296 - end-post-init-label (. gen newLabel) 333.297 - nth-method (. Method (getMethod "Object nth(Object,int)")) 333.298 - local (. gen newLocal obj-type)] 333.299 - (. gen (visitCode)) 333.300 - 333.301 - (if init 333.302 - (do 333.303 - (emit-get-var gen init-name) 333.304 - (. gen dup) 333.305 - (. gen ifNull no-init-label) 333.306 - (.checkCast gen ifn-type) 333.307 - ;box init args 333.308 - (dotimes [i (count pclasses)] 333.309 - (. gen (loadArg i)) 333.310 - (. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i)))) 333.311 - ;call init fn 333.312 - (. gen (invokeInterface ifn-type (new Method "invoke" obj-type 333.313 - (arg-types (count ptypes))))) 333.314 - ;expecting [[super-ctor-args] state] returned 333.315 - (. gen dup) 333.316 - (. gen push 0) 333.317 - (. gen (invokeStatic rt-type nth-method)) 333.318 - (. gen storeLocal local) 333.319 - 333.320 - (. gen (loadThis)) 333.321 - (. gen dupX1) 333.322 - (dotimes [i (count super-pclasses)] 333.323 - (. gen loadLocal local) 333.324 - (. gen push i) 333.325 - (. gen (invokeStatic rt-type nth-method)) 333.326 - (. clojure.lang.Compiler$HostExpr (emitUnboxArg nil gen (nth super-pclasses i)))) 333.327 - (. gen (invokeConstructor super-type super-m)) 333.328 - 333.329 - (if state 333.330 - (do 333.331 - (. gen push 1) 333.332 - (. gen (invokeStatic rt-type nth-method)) 333.333 - (. gen (putField ctype state-name obj-type))) 333.334 - (. gen pop)) 333.335 - 333.336 - (. gen goTo end-label) 333.337 - ;no init found 333.338 - (. gen mark no-init-label) 333.339 - (. gen (throwException ex-type (str impl-pkg-name "/" prefix init-name " not defined"))) 333.340 - (. gen mark end-label)) 333.341 - (if (= pclasses super-pclasses) 333.342 - (do 333.343 - (. gen (loadThis)) 333.344 - (. gen (loadArgs)) 333.345 - (. gen (invokeConstructor super-type super-m))) 333.346 - (throw (new Exception ":init not specified, but ctor and super ctor args differ")))) 333.347 - 333.348 - (when post-init 333.349 - (emit-get-var gen post-init-name) 333.350 - (. gen dup) 333.351 - (. gen ifNull no-post-init-label) 333.352 - (.checkCast gen ifn-type) 333.353 - (. gen (loadThis)) 333.354 - ;box init args 333.355 - (dotimes [i (count pclasses)] 333.356 - (. gen (loadArg i)) 333.357 - (. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i)))) 333.358 - ;call init fn 333.359 - (. gen (invokeInterface ifn-type (new Method "invoke" obj-type 333.360 - (arg-types (inc (count ptypes)))))) 333.361 - (. gen pop) 333.362 - (. gen goTo end-post-init-label) 333.363 - ;no init found 333.364 - (. gen mark no-post-init-label) 333.365 - (. gen (throwException ex-type (str impl-pkg-name "/" prefix post-init-name " not defined"))) 333.366 - (. gen mark end-post-init-label)) 333.367 - 333.368 - (. gen (returnValue)) 333.369 - (. gen (endMethod)) 333.370 - ;factory 333.371 - (when factory 333.372 - (let [fm (new Method factory-name ctype ptypes) 333.373 - gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_STATIC)) 333.374 - fm nil nil cv)] 333.375 - (. gen (visitCode)) 333.376 - (. gen newInstance ctype) 333.377 - (. gen dup) 333.378 - (. gen (loadArgs)) 333.379 - (. gen (invokeConstructor ctype m)) 333.380 - (. gen (returnValue)) 333.381 - (. gen (endMethod)))))) 333.382 - 333.383 - ;add methods matching supers', if no fn -> call super 333.384 - (let [mm (non-private-methods super)] 333.385 - (doseq [^java.lang.reflect.Method meth (vals mm)] 333.386 - (emit-forwarding-method (.getName meth) (.getParameterTypes meth) (.getReturnType meth) false 333.387 - (fn [^GeneratorAdapter gen ^Method m] 333.388 - (. gen (loadThis)) 333.389 - ;push args 333.390 - (. gen (loadArgs)) 333.391 - ;call super 333.392 - (. gen (visitMethodInsn (. Opcodes INVOKESPECIAL) 333.393 - (. super-type (getInternalName)) 333.394 - (. m (getName)) 333.395 - (. m (getDescriptor))))))) 333.396 - ;add methods matching interfaces', if no fn -> throw 333.397 - (reduce (fn [mm ^java.lang.reflect.Method meth] 333.398 - (if (contains? mm (method-sig meth)) 333.399 - mm 333.400 - (do 333.401 - (emit-forwarding-method (.getName meth) (.getParameterTypes meth) (.getReturnType meth) false 333.402 - emit-unsupported) 333.403 - (assoc mm (method-sig meth) meth)))) 333.404 - mm (mapcat #(.getMethods ^Class %) interfaces)) 333.405 - ;extra methods 333.406 - (doseq [[mname pclasses rclass :as msig] methods] 333.407 - (emit-forwarding-method mname pclasses rclass (:static (meta msig)) 333.408 - emit-unsupported)) 333.409 - ;expose specified overridden superclass methods 333.410 - (doseq [[local-mname ^java.lang.reflect.Method m] (reduce (fn [ms [[name _ _] m]] 333.411 - (if (contains? exposes-methods (symbol name)) 333.412 - (conj ms [((symbol name) exposes-methods) m]) 333.413 - ms)) [] (seq mm))] 333.414 - (let [ptypes (to-types (.getParameterTypes m)) 333.415 - rtype (totype (.getReturnType m)) 333.416 - exposer-m (new Method (str local-mname) rtype ptypes) 333.417 - target-m (new Method (.getName m) rtype ptypes) 333.418 - gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) exposer-m nil nil cv)] 333.419 - (. gen (loadThis)) 333.420 - (. gen (loadArgs)) 333.421 - (. gen (visitMethodInsn (. Opcodes INVOKESPECIAL) 333.422 - (. super-type (getInternalName)) 333.423 - (. target-m (getName)) 333.424 - (. target-m (getDescriptor)))) 333.425 - (. gen (returnValue)) 333.426 - (. gen (endMethod))))) 333.427 - ;main 333.428 - (when main 333.429 - (let [m (. Method getMethod "void main (String[])") 333.430 - gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_STATIC)) 333.431 - m nil nil cv) 333.432 - no-main-label (. gen newLabel) 333.433 - end-label (. gen newLabel)] 333.434 - (. gen (visitCode)) 333.435 - 333.436 - (emit-get-var gen main-name) 333.437 - (. gen dup) 333.438 - (. gen ifNull no-main-label) 333.439 - (.checkCast gen ifn-type) 333.440 - (. gen loadArgs) 333.441 - (. gen (invokeStatic rt-type (. Method (getMethod "clojure.lang.ISeq seq(Object)")))) 333.442 - (. gen (invokeInterface ifn-type (new Method "applyTo" obj-type 333.443 - (into-array [iseq-type])))) 333.444 - (. gen pop) 333.445 - (. gen goTo end-label) 333.446 - ;no main found 333.447 - (. gen mark no-main-label) 333.448 - (. gen (throwException ex-type (str impl-pkg-name "/" prefix main-name " not defined"))) 333.449 - (. gen mark end-label) 333.450 - (. gen (returnValue)) 333.451 - (. gen (endMethod)))) 333.452 - ;field exposers 333.453 - (doseq [[f {getter :get setter :set}] exposes] 333.454 - (let [fld (find-field super (str f)) 333.455 - ftype (totype (.getType fld)) 333.456 - static? (Modifier/isStatic (.getModifiers fld)) 333.457 - acc (+ Opcodes/ACC_PUBLIC (if static? Opcodes/ACC_STATIC 0))] 333.458 - (when getter 333.459 - (let [m (new Method (str getter) ftype (to-types [])) 333.460 - gen (new GeneratorAdapter acc m nil nil cv)] 333.461 - (. gen (visitCode)) 333.462 - (if static? 333.463 - (. gen getStatic ctype (str f) ftype) 333.464 - (do 333.465 - (. gen loadThis) 333.466 - (. gen getField ctype (str f) ftype))) 333.467 - (. gen (returnValue)) 333.468 - (. gen (endMethod)))) 333.469 - (when setter 333.470 - (let [m (new Method (str setter) Type/VOID_TYPE (into-array [ftype])) 333.471 - gen (new GeneratorAdapter acc m nil nil cv)] 333.472 - (. gen (visitCode)) 333.473 - (if static? 333.474 - (do 333.475 - (. gen loadArgs) 333.476 - (. gen putStatic ctype (str f) ftype)) 333.477 - (do 333.478 - (. gen loadThis) 333.479 - (. gen loadArgs) 333.480 - (. gen putField ctype (str f) ftype))) 333.481 - (. gen (returnValue)) 333.482 - (. gen (endMethod)))))) 333.483 - ;finish class def 333.484 - (. cv (visitEnd)) 333.485 - [cname (. cv (toByteArray))])) 333.486 - 333.487 -(defmacro gen-class 333.488 - "When compiling, generates compiled bytecode for a class with the 333.489 - given package-qualified :name (which, as all names in these 333.490 - parameters, can be a string or symbol), and writes the .class file 333.491 - to the *compile-path* directory. When not compiling, does 333.492 - nothing. The gen-class construct contains no implementation, as the 333.493 - implementation will be dynamically sought by the generated class in 333.494 - functions in an implementing Clojure namespace. Given a generated 333.495 - class org.mydomain.MyClass with a method named mymethod, gen-class 333.496 - will generate an implementation that looks for a function named by 333.497 - (str prefix mymethod) (default prefix: \"-\") in a 333.498 - Clojure namespace specified by :impl-ns 333.499 - (defaults to the current namespace). All inherited methods, 333.500 - generated methods, and init and main functions (see :methods, :init, 333.501 - and :main below) will be found similarly prefixed. By default, the 333.502 - static initializer for the generated class will attempt to load the 333.503 - Clojure support code for the class as a resource from the classpath, 333.504 - e.g. in the example case, ``org/mydomain/MyClass__init.class``. This 333.505 - behavior can be controlled by :load-impl-ns 333.506 - 333.507 - Note that methods with a maximum of 18 parameters are supported. 333.508 - 333.509 - In all subsequent sections taking types, the primitive types can be 333.510 - referred to by their Java names (int, float etc), and classes in the 333.511 - java.lang package can be used without a package qualifier. All other 333.512 - classes must be fully qualified. 333.513 - 333.514 - Options should be a set of key/value pairs, all except for :name are optional: 333.515 - 333.516 - :name aname 333.517 - 333.518 - The package-qualified name of the class to be generated 333.519 - 333.520 - :extends aclass 333.521 - 333.522 - Specifies the superclass, the non-private methods of which will be 333.523 - overridden by the class. If not provided, defaults to Object. 333.524 - 333.525 - :implements [interface ...] 333.526 - 333.527 - One or more interfaces, the methods of which will be implemented by the class. 333.528 - 333.529 - :init name 333.530 - 333.531 - If supplied, names a function that will be called with the arguments 333.532 - to the constructor. Must return [ [superclass-constructor-args] state] 333.533 - If not supplied, the constructor args are passed directly to 333.534 - the superclass constructor and the state will be nil 333.535 - 333.536 - :constructors {[param-types] [super-param-types], ...} 333.537 - 333.538 - By default, constructors are created for the generated class which 333.539 - match the signature(s) of the constructors for the superclass. This 333.540 - parameter may be used to explicitly specify constructors, each entry 333.541 - providing a mapping from a constructor signature to a superclass 333.542 - constructor signature. When you supply this, you must supply an :init 333.543 - specifier. 333.544 - 333.545 - :post-init name 333.546 - 333.547 - If supplied, names a function that will be called with the object as 333.548 - the first argument, followed by the arguments to the constructor. 333.549 - It will be called every time an object of this class is created, 333.550 - immediately after all the inherited constructors have completed. 333.551 - It's return value is ignored. 333.552 - 333.553 - :methods [ [name [param-types] return-type], ...] 333.554 - 333.555 - The generated class automatically defines all of the non-private 333.556 - methods of its superclasses/interfaces. This parameter can be used 333.557 - to specify the signatures of additional methods of the generated 333.558 - class. Static methods can be specified with ^{:static true} in the 333.559 - signature's metadata. Do not repeat superclass/interface signatures 333.560 - here. 333.561 - 333.562 - :main boolean 333.563 - 333.564 - If supplied and true, a static public main function will be generated. It will 333.565 - pass each string of the String[] argument as a separate argument to 333.566 - a function called (str prefix main). 333.567 - 333.568 - :factory name 333.569 - 333.570 - If supplied, a (set of) public static factory function(s) will be 333.571 - created with the given name, and the same signature(s) as the 333.572 - constructor(s). 333.573 - 333.574 - :state name 333.575 - 333.576 - If supplied, a public final instance field with the given name will be 333.577 - created. You must supply an :init function in order to provide a 333.578 - value for the state. Note that, though final, the state can be a ref 333.579 - or agent, supporting the creation of Java objects with transactional 333.580 - or asynchronous mutation semantics. 333.581 - 333.582 - :exposes {protected-field-name {:get name :set name}, ...} 333.583 - 333.584 - Since the implementations of the methods of the generated class 333.585 - occur in Clojure functions, they have no access to the inherited 333.586 - protected fields of the superclass. This parameter can be used to 333.587 - generate public getter/setter methods exposing the protected field(s) 333.588 - for use in the implementation. 333.589 - 333.590 - :exposes-methods {super-method-name exposed-name, ...} 333.591 - 333.592 - It is sometimes necessary to call the superclass' implementation of an 333.593 - overridden method. Those methods may be exposed and referred in 333.594 - the new method implementation by a local name. 333.595 - 333.596 - :prefix string 333.597 - 333.598 - Default: \"-\" Methods called e.g. Foo will be looked up in vars called 333.599 - prefixFoo in the implementing ns. 333.600 - 333.601 - :impl-ns name 333.602 - 333.603 - Default: the name of the current ns. Implementations of methods will be 333.604 - looked up in this namespace. 333.605 - 333.606 - :load-impl-ns boolean 333.607 - 333.608 - Default: true. Causes the static initializer for the generated class 333.609 - to reference the load code for the implementing namespace. Should be 333.610 - true when implementing-ns is the default, false if you intend to 333.611 - load the code via some other method." 333.612 - {:added "1.0"} 333.613 - 333.614 - [& options] 333.615 - (when *compile-files* 333.616 - (let [options-map (into {} (map vec (partition 2 options))) 333.617 - [cname bytecode] (generate-class options-map)] 333.618 - (clojure.lang.Compiler/writeClassFile cname bytecode)))) 333.619 - 333.620 -;;;;;;;;;;;;;;;;;;;; gen-interface ;;;;;;;;;;;;;;;;;;;;;; 333.621 -;; based on original contribution by Chris Houser 333.622 - 333.623 -(defn- ^Type asm-type 333.624 - "Returns an asm Type object for c, which may be a primitive class 333.625 - (such as Integer/TYPE), any other class (such as Double), or a 333.626 - fully-qualified class name given as a string or symbol 333.627 - (such as 'java.lang.String)" 333.628 - [c] 333.629 - (if (or (instance? Class c) (prim->class c)) 333.630 - (Type/getType (the-class c)) 333.631 - (let [strx (str c)] 333.632 - (Type/getObjectType 333.633 - (.replace (if (some #{\.} strx) 333.634 - strx 333.635 - (str "java.lang." strx)) 333.636 - "." "/"))))) 333.637 - 333.638 -(defn- generate-interface 333.639 - [{:keys [name extends methods]}] 333.640 - (let [iname (.replace (str name) "." "/") 333.641 - cv (ClassWriter. ClassWriter/COMPUTE_MAXS)] 333.642 - (. cv visit Opcodes/V1_5 (+ Opcodes/ACC_PUBLIC 333.643 - Opcodes/ACC_ABSTRACT 333.644 - Opcodes/ACC_INTERFACE) 333.645 - iname nil "java/lang/Object" 333.646 - (when (seq extends) 333.647 - (into-array (map #(.getInternalName (asm-type %)) extends)))) 333.648 - (add-annotations cv (meta name)) 333.649 - (doseq [[mname pclasses rclass pmetas] methods] 333.650 - (let [mv (. cv visitMethod (+ Opcodes/ACC_PUBLIC Opcodes/ACC_ABSTRACT) 333.651 - (str mname) 333.652 - (Type/getMethodDescriptor (asm-type rclass) 333.653 - (if pclasses 333.654 - (into-array Type (map asm-type pclasses)) 333.655 - (make-array Type 0))) 333.656 - nil nil)] 333.657 - (add-annotations mv (meta mname)) 333.658 - (dotimes [i (count pmetas)] 333.659 - (add-annotations mv (nth pmetas i) i)) 333.660 - (. mv visitEnd))) 333.661 - (. cv visitEnd) 333.662 - [iname (. cv toByteArray)])) 333.663 - 333.664 -(defmacro gen-interface 333.665 - "When compiling, generates compiled bytecode for an interface with 333.666 - the given package-qualified :name (which, as all names in these 333.667 - parameters, can be a string or symbol), and writes the .class file 333.668 - to the *compile-path* directory. When not compiling, does nothing. 333.669 - 333.670 - In all subsequent sections taking types, the primitive types can be 333.671 - referred to by their Java names (int, float etc), and classes in the 333.672 - java.lang package can be used without a package qualifier. All other 333.673 - classes must be fully qualified. 333.674 - 333.675 - Options should be a set of key/value pairs, all except for :name are 333.676 - optional: 333.677 - 333.678 - :name aname 333.679 - 333.680 - The package-qualified name of the class to be generated 333.681 - 333.682 - :extends [interface ...] 333.683 - 333.684 - One or more interfaces, which will be extended by this interface. 333.685 - 333.686 - :methods [ [name [param-types] return-type], ...] 333.687 - 333.688 - This parameter is used to specify the signatures of the methods of 333.689 - the generated interface. Do not repeat superinterface signatures 333.690 - here." 333.691 - {:added "1.0"} 333.692 - 333.693 - [& options] 333.694 - (let [options-map (apply hash-map options) 333.695 - [cname bytecode] (generate-interface options-map)] 333.696 - (if *compile-files* 333.697 - (clojure.lang.Compiler/writeClassFile cname bytecode) 333.698 - (.defineClass ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER) 333.699 - (str (:name options-map)) bytecode options)))) 333.700 - 333.701 -(comment 333.702 - 333.703 -(defn gen-and-load-class 333.704 - "Generates and immediately loads the bytecode for the specified 333.705 - class. Note that a class generated this way can be loaded only once 333.706 - - the JVM supports only one class with a given name per 333.707 - classloader. Subsequent to generation you can import it into any 333.708 - desired namespaces just like any other class. See gen-class for a 333.709 - description of the options." 333.710 - {:added "1.0"} 333.711 - 333.712 - [& options] 333.713 - (let [options-map (apply hash-map options) 333.714 - [cname bytecode] (generate-class options-map)] 333.715 - (.. (clojure.lang.RT/getRootClassLoader) (defineClass cname bytecode options)))) 333.716 - 333.717 -)
334.1 --- a/src/clojure/gvec.clj Sat Aug 21 06:25:44 2010 -0400 334.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 334.3 @@ -1,460 +0,0 @@ 334.4 -; Copyright (c) Rich Hickey. All rights reserved. 334.5 -; The use and distribution terms for this software are covered by the 334.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 334.7 -; which can be found in the file epl-v10.html at the root of this distribution. 334.8 -; By using this software in any fashion, you are agreeing to be bound by 334.9 -; the terms of this license. 334.10 -; You must not remove this notice, or any other, from this software. 334.11 - 334.12 -;;; a generic vector implementation for vectors of primitives 334.13 - 334.14 -(in-ns 'clojure.core) 334.15 - 334.16 -;(set! *warn-on-reflection* true) 334.17 - 334.18 -(deftype VecNode [edit arr]) 334.19 - 334.20 -(def EMPTY-NODE (VecNode. nil (object-array 32))) 334.21 - 334.22 -(definterface IVecImpl 334.23 - (^int tailoff []) 334.24 - (arrayFor [^int i]) 334.25 - (pushTail [^int level ^clojure.core.VecNode parent ^clojure.core.VecNode tailnode]) 334.26 - (popTail [^int level node]) 334.27 - (newPath [edit ^int level node]) 334.28 - (doAssoc [^int level node ^int i val])) 334.29 - 334.30 -(definterface ArrayManager 334.31 - (array [^int size]) 334.32 - (^int alength [arr]) 334.33 - (aclone [arr]) 334.34 - (aget [arr ^int i]) 334.35 - (aset [arr ^int i val])) 334.36 - 334.37 -(deftype ArrayChunk [^clojure.core.ArrayManager am arr ^int off ^int end] 334.38 - 334.39 - clojure.lang.Indexed 334.40 - (nth [_ i] (.aget am arr (+ off i))) 334.41 - 334.42 - (count [_] (- end off)) 334.43 - 334.44 - clojure.lang.IChunk 334.45 - (dropFirst [_] 334.46 - (if (= off end) 334.47 - (throw (IllegalStateException. "dropFirst of empty chunk")) 334.48 - (new ArrayChunk am arr (inc off) end))) 334.49 - 334.50 - (reduce [_ f init] 334.51 - (loop [ret init i off] 334.52 - (if (< i end) 334.53 - (recur (f ret (.aget am arr i)) (inc i)) 334.54 - ret))) 334.55 - ) 334.56 - 334.57 -(deftype VecSeq [^clojure.core.ArrayManager am ^clojure.core.IVecImpl vec anode ^int i ^int offset] 334.58 - :no-print true 334.59 - 334.60 - clojure.core.protocols.InternalReduce 334.61 - (internal-reduce 334.62 - [_ f val] 334.63 - (loop [result val 334.64 - aidx offset] 334.65 - (if (< aidx (count vec)) 334.66 - (let [node (.arrayFor vec aidx) 334.67 - result (loop [result result 334.68 - node-idx (bit-and (int 0x1f) aidx)] 334.69 - (if (< node-idx (.alength am node)) 334.70 - (recur (f result (.aget am node node-idx)) (inc node-idx)) 334.71 - result))] 334.72 - (recur result (bit-and (int 0xffe0) (+ aidx (int 32))))) 334.73 - result))) 334.74 - 334.75 - clojure.lang.ISeq 334.76 - (first [_] (.aget am anode offset)) 334.77 - (next [this] 334.78 - (if (< (inc offset) (.alength am anode)) 334.79 - (new VecSeq am vec anode i (inc offset)) 334.80 - (.chunkedNext this))) 334.81 - (more [this] 334.82 - (let [s (.next this)] 334.83 - (or s (clojure.lang.PersistentList/EMPTY)))) 334.84 - (cons [this o] 334.85 - (clojure.lang.Cons. o this)) 334.86 - (count [this] 334.87 - (loop [i 1 334.88 - s (next this)] 334.89 - (if s 334.90 - (if (instance? clojure.lang.Counted s) 334.91 - (+ i (.count s)) 334.92 - (recur (inc i) (next s))) 334.93 - i))) 334.94 - (equiv [this o] 334.95 - (cond 334.96 - (identical? this o) true 334.97 - (or (instance? clojure.lang.Sequential o) (instance? java.util.List o)) 334.98 - (loop [me this 334.99 - you (seq o)] 334.100 - (if (nil? me) 334.101 - (nil? you) 334.102 - (and (clojure.lang.Util/equiv (first me) (first you)) 334.103 - (recur (next me) (next you))))) 334.104 - :else false)) 334.105 - (empty [_] 334.106 - clojure.lang.PersistentList/EMPTY) 334.107 - 334.108 - 334.109 - clojure.lang.Seqable 334.110 - (seq [this] this) 334.111 - 334.112 - clojure.lang.IChunkedSeq 334.113 - (chunkedFirst [_] (ArrayChunk. am anode offset (.alength am anode))) 334.114 - (chunkedNext [_] 334.115 - (let [nexti (+ i (.alength am anode))] 334.116 - (when (< nexti (count vec)) 334.117 - (new VecSeq am vec (.arrayFor vec nexti) nexti 0)))) 334.118 - (chunkedMore [this] 334.119 - (let [s (.chunkedNext this)] 334.120 - (or s (clojure.lang.PersistentList/EMPTY))))) 334.121 - 334.122 -(defmethod print-method ::VecSeq [v w] 334.123 - ((get (methods print-method) clojure.lang.ISeq) v w)) 334.124 - 334.125 -(deftype Vec [^clojure.core.ArrayManager am ^int cnt ^int shift ^clojure.core.VecNode root tail _meta] 334.126 - Object 334.127 - (equals [this o] 334.128 - (cond 334.129 - (identical? this o) true 334.130 - (or (instance? clojure.lang.IPersistentVector o) (instance? java.util.RandomAccess o)) 334.131 - (and (= cnt (count o)) 334.132 - (loop [i (int 0)] 334.133 - (cond 334.134 - (= i cnt) true 334.135 - (.equals (.nth this i) (nth o i)) (recur (inc i)) 334.136 - :else false))) 334.137 - (or (instance? clojure.lang.Sequential o) (instance? java.util.List o)) 334.138 - (.equals (seq this) (seq o)) 334.139 - :else false)) 334.140 - 334.141 - ;todo - cache 334.142 - (hashCode [this] 334.143 - (loop [hash (int 1) i (int 0)] 334.144 - (if (= i cnt) 334.145 - hash 334.146 - (let [val (.nth this i)] 334.147 - (recur (unchecked-add (unchecked-multiply (int 31) hash) 334.148 - (clojure.lang.Util/hash val)) 334.149 - (inc i)))))) 334.150 - 334.151 - clojure.lang.Counted 334.152 - (count [_] cnt) 334.153 - 334.154 - clojure.lang.IMeta 334.155 - (meta [_] _meta) 334.156 - 334.157 - clojure.lang.IObj 334.158 - (withMeta [_ m] (new Vec am cnt shift root tail m)) 334.159 - 334.160 - clojure.lang.Indexed 334.161 - (nth [this i] 334.162 - (let [a (.arrayFor this i)] 334.163 - (.aget am a (bit-and i (int 0x1f))))) 334.164 - (nth [this i not-found] 334.165 - (let [z (int 0)] 334.166 - (if (and (>= i z) (< i (.count this))) 334.167 - (.nth this i) 334.168 - not-found))) 334.169 - 334.170 - clojure.lang.IPersistentCollection 334.171 - (cons [this val] 334.172 - (if (< (- cnt (.tailoff this)) (int 32)) 334.173 - (let [new-tail (.array am (inc (.alength am tail)))] 334.174 - (System/arraycopy tail 0 new-tail 0 (.alength am tail)) 334.175 - (.aset am new-tail (.alength am tail) val) 334.176 - (new Vec am (inc cnt) shift root new-tail (meta this))) 334.177 - (let [tail-node (VecNode. (.edit root) tail)] 334.178 - (if (> (bit-shift-right cnt (int 5)) (bit-shift-left (int 1) shift)) ;overflow root? 334.179 - (let [new-root (VecNode. (.edit root) (object-array 32))] 334.180 - (doto ^objects (.arr new-root) 334.181 - (aset 0 root) 334.182 - (aset 1 (.newPath this (.edit root) shift tail-node))) 334.183 - (new Vec am (inc cnt) (+ shift (int 5)) new-root (let [tl (.array am 1)] (.aset am tl 0 val) tl) (meta this))) 334.184 - (new Vec am (inc cnt) shift (.pushTail this shift root tail-node) 334.185 - (let [tl (.array am 1)] (.aset am tl 0 val) tl) (meta this)))))) 334.186 - 334.187 - (empty [_] (new Vec am 0 5 EMPTY-NODE (.array am 0) nil)) 334.188 - (equiv [this o] 334.189 - (cond 334.190 - (or (instance? clojure.lang.IPersistentVector o) (instance? java.util.RandomAccess o)) 334.191 - (and (= cnt (count o)) 334.192 - (loop [i (int 0)] 334.193 - (cond 334.194 - (= i cnt) true 334.195 - (= (.nth this i) (nth o i)) (recur (inc i)) 334.196 - :else false))) 334.197 - (or (instance? clojure.lang.Sequential o) (instance? java.util.List o)) 334.198 - (= (seq this) (seq o)) 334.199 - :else false)) 334.200 - 334.201 - clojure.lang.IPersistentStack 334.202 - (peek [this] 334.203 - (when (> cnt (int 0)) 334.204 - (.nth this (dec cnt)))) 334.205 - 334.206 - (pop [this] 334.207 - (cond 334.208 - (zero? cnt) 334.209 - (throw (IllegalStateException. "Can't pop empty vector")) 334.210 - (= 1 cnt) 334.211 - (new Vec am 0 5 EMPTY-NODE (.array am 0) (meta this)) 334.212 - (> (- cnt (.tailoff this)) 1) 334.213 - (let [new-tail (.array am (dec (.alength am tail)))] 334.214 - (System/arraycopy tail 0 new-tail 0 (.alength am new-tail)) 334.215 - (new Vec am (dec cnt) shift root new-tail (meta this))) 334.216 - :else 334.217 - (let [new-tail (.arrayFor this (- cnt 2)) 334.218 - new-root ^clojure.core.VecNode (.popTail this shift root)] 334.219 - (cond 334.220 - (nil? new-root) 334.221 - (new Vec am (dec cnt) shift EMPTY-NODE new-tail (meta this)) 334.222 - (and (> shift 5) (nil? (aget ^objects (.arr new-root) 1))) 334.223 - (new Vec am (dec cnt) (- shift 5) (aget ^objects (.arr new-root) 0) new-tail (meta this)) 334.224 - :else 334.225 - (new Vec am (dec cnt) shift new-root new-tail (meta this)))))) 334.226 - 334.227 - clojure.lang.IPersistentVector 334.228 - (assocN [this i val] 334.229 - (cond 334.230 - (and (<= (int 0) i) (< i cnt)) 334.231 - (if (>= i (.tailoff this)) 334.232 - (let [new-tail (.array am (.alength am tail))] 334.233 - (System/arraycopy tail 0 new-tail 0 (.alength am tail)) 334.234 - (.aset am new-tail (bit-and i (int 0x1f)) val) 334.235 - (new Vec am cnt shift root new-tail (meta this))) 334.236 - (new Vec am cnt shift (.doAssoc this shift root i val) tail (meta this))) 334.237 - (= i cnt) (.cons this val) 334.238 - :else (throw (IndexOutOfBoundsException.)))) 334.239 - 334.240 - clojure.lang.Reversible 334.241 - (rseq [this] 334.242 - (if (> (.count this) 0) 334.243 - (clojure.lang.APersistentVector$RSeq. this (dec (.count this))) 334.244 - nil)) 334.245 - 334.246 - clojure.lang.Associative 334.247 - (assoc [this k v] 334.248 - (if (clojure.lang.Util/isInteger k) 334.249 - (.assocN this k v) 334.250 - (throw (IllegalArgumentException. "Key must be integer")))) 334.251 - (containsKey [this k] 334.252 - (and (clojure.lang.Util/isInteger k) 334.253 - (<= 0 (int k)) 334.254 - (< (int k) cnt))) 334.255 - (entryAt [this k] 334.256 - (if (.containsKey this k) 334.257 - (clojure.lang.MapEntry. k (.nth this (int k))) 334.258 - nil)) 334.259 - 334.260 - clojure.lang.ILookup 334.261 - (valAt [this k not-found] 334.262 - (if (clojure.lang.Util/isInteger k) 334.263 - (let [i (int k)] 334.264 - (if (and (>= i 0) (< i cnt)) 334.265 - (.nth this i) 334.266 - not-found)) 334.267 - not-found)) 334.268 - 334.269 - (valAt [this k] (.valAt this k nil)) 334.270 - 334.271 - clojure.lang.IFn 334.272 - (invoke [this k] 334.273 - (if (clojure.lang.Util/isInteger k) 334.274 - (let [i (int k)] 334.275 - (if (and (>= i 0) (< i cnt)) 334.276 - (.nth this i) 334.277 - (throw (IndexOutOfBoundsException.)))) 334.278 - (throw (IllegalArgumentException. "Key must be integer")))) 334.279 - 334.280 - 334.281 - clojure.lang.Seqable 334.282 - (seq [this] 334.283 - (if (zero? cnt) 334.284 - nil 334.285 - (VecSeq. am this (.arrayFor this 0) 0 0))) 334.286 - 334.287 - clojure.lang.Sequential ;marker, no methods 334.288 - 334.289 - clojure.core.IVecImpl 334.290 - (tailoff [_] 334.291 - (- cnt (.alength am tail))) 334.292 - 334.293 - (arrayFor [this i] 334.294 - (if (and (<= (int 0) i) (< i cnt)) 334.295 - (if (>= i (.tailoff this)) 334.296 - tail 334.297 - (loop [node root level shift] 334.298 - (if (zero? level) 334.299 - (.arr node) 334.300 - (recur (aget ^objects (.arr node) (bit-and (bit-shift-right i level) (int 0x1f))) 334.301 - (- level (int 5)))))) 334.302 - (throw (IndexOutOfBoundsException.)))) 334.303 - 334.304 - (pushTail [this level parent tailnode] 334.305 - (let [subidx (bit-and (bit-shift-right (dec cnt) level) (int 0x1f)) 334.306 - parent ^clojure.core.VecNode parent 334.307 - ret (VecNode. (.edit parent) (aclone ^objects (.arr parent))) 334.308 - node-to-insert (if (= level (int 5)) 334.309 - tailnode 334.310 - (let [child (aget ^objects (.arr parent) subidx)] 334.311 - (if child 334.312 - (.pushTail this (- level (int 5)) child tailnode) 334.313 - (.newPath this (.edit root) (- level (int 5)) tailnode))))] 334.314 - (aset ^objects (.arr ret) subidx node-to-insert) 334.315 - ret)) 334.316 - 334.317 - (popTail [this level node] 334.318 - (let [node ^clojure.core.VecNode node 334.319 - subidx (bit-and (bit-shift-right (- cnt (int 2)) level) (int 0x1f))] 334.320 - (cond 334.321 - (> level 5) 334.322 - (let [new-child (.popTail this (- level 5) (aget ^objects (.arr node) subidx))] 334.323 - (if (and (nil? new-child) (zero? subidx)) 334.324 - nil 334.325 - (let [arr (aclone ^objects (.arr node))] 334.326 - (aset arr subidx new-child) 334.327 - (VecNode. (.edit root) arr)))) 334.328 - (zero? subidx) nil 334.329 - :else (let [arr (aclone ^objects (.arr node))] 334.330 - (aset arr subidx nil) 334.331 - (VecNode. (.edit root) arr))))) 334.332 - 334.333 - (newPath [this edit ^int level node] 334.334 - (if (zero? level) 334.335 - node 334.336 - (let [ret (VecNode. edit (object-array 32))] 334.337 - (aset ^objects (.arr ret) 0 (.newPath this edit (- level (int 5)) node)) 334.338 - ret))) 334.339 - 334.340 - (doAssoc [this level node i val] 334.341 - (let [node ^clojure.core.VecNode node] 334.342 - (if (zero? level) 334.343 - ;on this branch, array will need val type 334.344 - (let [arr (.aclone am (.arr node))] 334.345 - (.aset am arr (bit-and i (int 0x1f)) val) 334.346 - (VecNode. (.edit node) arr)) 334.347 - (let [arr (aclone ^objects (.arr node)) 334.348 - subidx (bit-and (bit-shift-right i level) (int 0x1f))] 334.349 - (aset arr subidx (.doAssoc this (- level (int 5)) (aget arr subidx) i val)) 334.350 - (VecNode. (.edit node) arr))))) 334.351 - 334.352 - java.lang.Comparable 334.353 - (compareTo [this o] 334.354 - (if (identical? this o) 334.355 - 0 334.356 - (let [#^clojure.lang.IPersistentVector v (cast clojure.lang.IPersistentVector o) 334.357 - vcnt (.count v)] 334.358 - (cond 334.359 - (< cnt vcnt) -1 334.360 - (> cnt vcnt) 1 334.361 - :else 334.362 - (loop [i (int 0)] 334.363 - (if (= i cnt) 334.364 - 0 334.365 - (let [comp (clojure.lang.Util/compare (.nth this i) (.nth v i))] 334.366 - (if (= 0 comp) 334.367 - (recur (inc i)) 334.368 - comp)))))))) 334.369 - 334.370 - java.lang.Iterable 334.371 - (iterator [this] 334.372 - (let [i (java.util.concurrent.atomic.AtomicInteger. 0)] 334.373 - (reify java.util.Iterator 334.374 - (hasNext [_] (< (.get i) cnt)) 334.375 - (next [_] (.nth this (dec (.incrementAndGet i)))) 334.376 - (remove [_] (throw (UnsupportedOperationException.)))))) 334.377 - 334.378 - java.util.Collection 334.379 - (contains [this o] (boolean (some #(= % o) this))) 334.380 - (containsAll [this c] (every? #(.contains this %) c)) 334.381 - (isEmpty [_] (zero? cnt)) 334.382 - (toArray [this] (into-array Object this)) 334.383 - (toArray [this arr] 334.384 - (if (>= (count arr) cnt) 334.385 - (do 334.386 - (dotimes [i cnt] 334.387 - (aset arr i (.nth this i))) 334.388 - arr) 334.389 - (into-array Object this))) 334.390 - (size [_] cnt) 334.391 - (add [_ o] (throw (UnsupportedOperationException.))) 334.392 - (addAll [_ c] (throw (UnsupportedOperationException.))) 334.393 - (clear [_] (throw (UnsupportedOperationException.))) 334.394 - (^boolean remove [_ o] (throw (UnsupportedOperationException.))) 334.395 - (removeAll [_ c] (throw (UnsupportedOperationException.))) 334.396 - (retainAll [_ c] (throw (UnsupportedOperationException.))) 334.397 - 334.398 - java.util.List 334.399 - (get [this i] (.nth this i)) 334.400 - (indexOf [this o] 334.401 - (loop [i (int 0)] 334.402 - (cond 334.403 - (== i cnt) -1 334.404 - (= o (.nth this i)) i 334.405 - :else (recur (inc i))))) 334.406 - (lastIndexOf [this o] 334.407 - (loop [i (dec cnt)] 334.408 - (cond 334.409 - (< i 0) -1 334.410 - (= o (.nth this i)) i 334.411 - :else (recur (dec i))))) 334.412 - (listIterator [this] (.listIterator this 0)) 334.413 - (listIterator [this i] 334.414 - (let [i (java.util.concurrent.atomic.AtomicInteger. i)] 334.415 - (reify java.util.ListIterator 334.416 - (hasNext [_] (< (.get i) cnt)) 334.417 - (hasPrevious [_] (pos? i)) 334.418 - (next [_] (.nth this (dec (.incrementAndGet i)))) 334.419 - (nextIndex [_] (.get i)) 334.420 - (previous [_] (.nth this (.decrementAndGet i))) 334.421 - (previousIndex [_] (dec (.get i))) 334.422 - (add [_ e] (throw (UnsupportedOperationException.))) 334.423 - (remove [_] (throw (UnsupportedOperationException.))) 334.424 - (set [_ e] (throw (UnsupportedOperationException.)))))) 334.425 - (subList [this a z] (subvec this a z)) 334.426 - (add [_ i o] (throw (UnsupportedOperationException.))) 334.427 - (addAll [_ i c] (throw (UnsupportedOperationException.))) 334.428 - (^Object remove [_ ^int i] (throw (UnsupportedOperationException.))) 334.429 - (set [_ i e] (throw (UnsupportedOperationException.))) 334.430 -) 334.431 - 334.432 -(defmethod print-method ::Vec [v w] 334.433 - ((get (methods print-method) clojure.lang.IPersistentVector) v w)) 334.434 - 334.435 -(defmacro mk-am {:private true} [t] 334.436 - (let [garr (gensym) 334.437 - tgarr (with-meta garr {:tag (symbol (str t "s"))})] 334.438 - `(reify clojure.core.ArrayManager 334.439 - (array [_ size#] (~(symbol (str t "-array")) size#)) 334.440 - (alength [_ ~garr] (alength ~tgarr)) 334.441 - (aclone [_ ~garr] (aclone ~tgarr)) 334.442 - (aget [_ ~garr i#] (aget ~tgarr i#)) 334.443 - (aset [_ ~garr i# val#] (aset ~tgarr i# (~t val#)))))) 334.444 - 334.445 -(def ^{:private true} ams 334.446 - {:int (mk-am int) 334.447 - :long (mk-am long) 334.448 - :float (mk-am float) 334.449 - :double (mk-am double) 334.450 - :byte (mk-am byte) 334.451 - :short (mk-am short) 334.452 - :char (mk-am char) 334.453 - :boolean (mk-am boolean)}) 334.454 - 334.455 -(defn vector-of 334.456 - "Creates a new vector of a single primitive type t, where t is one 334.457 - of :int :long :float :double :byte :short :char or :boolean. The 334.458 - resulting vector complies with the interface of vectors in general, 334.459 - but stores the values unboxed internally." 334.460 - {:added "1.2"} 334.461 - [t] 334.462 - (let [am ^clojure.core.ArrayManager (ams t)] 334.463 - (Vec. am 0 5 EMPTY-NODE (.array am 0) nil)))
335.1 --- a/src/clojure/inspector.clj Sat Aug 21 06:25:44 2010 -0400 335.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 335.3 @@ -1,185 +0,0 @@ 335.4 -; Copyright (c) Rich Hickey. All rights reserved. 335.5 -; The use and distribution terms for this software are covered by the 335.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 335.7 -; which can be found in the file epl-v10.html at the root of this distribution. 335.8 -; By using this software in any fashion, you are agreeing to be bound by 335.9 -; the terms of this license. 335.10 -; You must not remove this notice, or any other, from this software. 335.11 - 335.12 -(ns ^{:doc "Graphical object inspector for Clojure data structures." 335.13 - :author "Rich Hickey"} 335.14 - clojure.inspector 335.15 - (:import 335.16 - (java.awt BorderLayout) 335.17 - (java.awt.event ActionEvent ActionListener) 335.18 - (javax.swing.tree TreeModel) 335.19 - (javax.swing.table TableModel AbstractTableModel) 335.20 - (javax.swing JPanel JTree JTable JScrollPane JFrame JToolBar JButton SwingUtilities))) 335.21 - 335.22 -(defn atom? [x] 335.23 - (not (coll? x))) 335.24 - 335.25 -(defn collection-tag [x] 335.26 - (cond 335.27 - (instance? java.util.Map$Entry x) :entry 335.28 - (instance? java.util.Map x) :map 335.29 - (sequential? x) :seq 335.30 - :else :atom)) 335.31 - 335.32 -(defmulti is-leaf collection-tag) 335.33 -(defmulti get-child (fn [parent index] (collection-tag parent))) 335.34 -(defmulti get-child-count collection-tag) 335.35 - 335.36 -(defmethod is-leaf :default [node] 335.37 - (atom? node)) 335.38 -(defmethod get-child :default [parent index] 335.39 - (nth parent index)) 335.40 -(defmethod get-child-count :default [parent] 335.41 - (count parent)) 335.42 - 335.43 -(defmethod is-leaf :entry [e] 335.44 - (is-leaf (val e))) 335.45 -(defmethod get-child :entry [e index] 335.46 - (get-child (val e) index)) 335.47 -(defmethod get-child-count :entry [e] 335.48 - (count (val e))) 335.49 - 335.50 -(defmethod is-leaf :map [m] 335.51 - false) 335.52 -(defmethod get-child :map [m index] 335.53 - (nth (seq m) index)) 335.54 - 335.55 -(defn tree-model [data] 335.56 - (proxy [TreeModel] [] 335.57 - (getRoot [] data) 335.58 - (addTreeModelListener [treeModelListener]) 335.59 - (getChild [parent index] 335.60 - (get-child parent index)) 335.61 - (getChildCount [parent] 335.62 - (get-child-count parent)) 335.63 - (isLeaf [node] 335.64 - (is-leaf node)) 335.65 - (valueForPathChanged [path newValue]) 335.66 - (getIndexOfChild [parent child] 335.67 - -1) 335.68 - (removeTreeModelListener [treeModelListener]))) 335.69 - 335.70 - 335.71 -(defn old-table-model [data] 335.72 - (let [row1 (first data) 335.73 - colcnt (count row1) 335.74 - cnt (count data) 335.75 - vals (if (map? row1) vals identity)] 335.76 - (proxy [TableModel] [] 335.77 - (addTableModelListener [tableModelListener]) 335.78 - (getColumnClass [columnIndex] Object) 335.79 - (getColumnCount [] colcnt) 335.80 - (getColumnName [columnIndex] 335.81 - (if (map? row1) 335.82 - (name (nth (keys row1) columnIndex)) 335.83 - (str columnIndex))) 335.84 - (getRowCount [] cnt) 335.85 - (getValueAt [rowIndex columnIndex] 335.86 - (nth (vals (nth data rowIndex)) columnIndex)) 335.87 - (isCellEditable [rowIndex columnIndex] false) 335.88 - (removeTableModelListener [tableModelListener])))) 335.89 - 335.90 -(defn inspect-tree 335.91 - "creates a graphical (Swing) inspector on the supplied hierarchical data" 335.92 - {:added "1.0"} 335.93 - [data] 335.94 - (doto (JFrame. "Clojure Inspector") 335.95 - (.add (JScrollPane. (JTree. (tree-model data)))) 335.96 - (.setSize 400 600) 335.97 - (.setVisible true))) 335.98 - 335.99 -(defn inspect-table 335.100 - "creates a graphical (Swing) inspector on the supplied regular 335.101 - data, which must be a sequential data structure of data structures 335.102 - of equal length" 335.103 - {:added "1.0"} 335.104 - [data] 335.105 - (doto (JFrame. "Clojure Inspector") 335.106 - (.add (JScrollPane. (JTable. (old-table-model data)))) 335.107 - (.setSize 400 600) 335.108 - (.setVisible true))) 335.109 - 335.110 - 335.111 -(defmulti list-provider class) 335.112 - 335.113 -(defmethod list-provider :default [x] 335.114 - {:nrows 1 :get-value (fn [i] x) :get-label (fn [i] (.getName (class x)))}) 335.115 - 335.116 -(defmethod list-provider java.util.List [c] 335.117 - (let [v (if (vector? c) c (vec c))] 335.118 - {:nrows (count v) 335.119 - :get-value (fn [i] (v i)) 335.120 - :get-label (fn [i] i)})) 335.121 - 335.122 -(defmethod list-provider java.util.Map [c] 335.123 - (let [v (vec (sort (map (fn [[k v]] (vector k v)) c)))] 335.124 - {:nrows (count v) 335.125 - :get-value (fn [i] ((v i) 1)) 335.126 - :get-label (fn [i] ((v i) 0))})) 335.127 - 335.128 -(defn list-model [provider] 335.129 - (let [{:keys [nrows get-value get-label]} provider] 335.130 - (proxy [AbstractTableModel] [] 335.131 - (getColumnCount [] 2) 335.132 - (getRowCount [] nrows) 335.133 - (getValueAt [rowIndex columnIndex] 335.134 - (cond 335.135 - (= 0 columnIndex) (get-label rowIndex) 335.136 - (= 1 columnIndex) (print-str (get-value rowIndex))))))) 335.137 - 335.138 -(defmulti table-model class) 335.139 - 335.140 -(defmethod table-model :default [x] 335.141 - (proxy [AbstractTableModel] [] 335.142 - (getColumnCount [] 2) 335.143 - (getRowCount [] 1) 335.144 - (getValueAt [rowIndex columnIndex] 335.145 - (if (zero? columnIndex) 335.146 - (class x) 335.147 - x)))) 335.148 - 335.149 -;(defn make-inspector [x] 335.150 -; (agent {:frame frame :data x :parent nil :index 0})) 335.151 - 335.152 - 335.153 -(defn inspect 335.154 - "creates a graphical (Swing) inspector on the supplied object" 335.155 - {:added "1.0"} 335.156 - [x] 335.157 - (doto (JFrame. "Clojure Inspector") 335.158 - (.add 335.159 - (doto (JPanel. (BorderLayout.)) 335.160 - (.add (doto (JToolBar.) 335.161 - (.add (JButton. "Back")) 335.162 - (.addSeparator) 335.163 - (.add (JButton. "List")) 335.164 - (.add (JButton. "Table")) 335.165 - (.add (JButton. "Bean")) 335.166 - (.add (JButton. "Line")) 335.167 - (.add (JButton. "Bar")) 335.168 - (.addSeparator) 335.169 - (.add (JButton. "Prev")) 335.170 - (.add (JButton. "Next"))) 335.171 - BorderLayout/NORTH) 335.172 - (.add 335.173 - (JScrollPane. 335.174 - (doto (JTable. (list-model (list-provider x))) 335.175 - (.setAutoResizeMode JTable/AUTO_RESIZE_LAST_COLUMN))) 335.176 - BorderLayout/CENTER))) 335.177 - (.setSize 400 400) 335.178 - (.setVisible true))) 335.179 - 335.180 - 335.181 -(comment 335.182 - 335.183 -(load-file "src/inspector.clj") 335.184 -(refer 'inspector) 335.185 -(inspect-tree {:a 1 :b 2 :c [1 2 3 {:d 4 :e 5 :f [6 7 8]}]}) 335.186 -(inspect-table [[1 2 3][4 5 6][7 8 9][10 11 12]]) 335.187 - 335.188 -)
336.1 --- a/src/clojure/java/browse.clj Sat Aug 21 06:25:44 2010 -0400 336.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 336.3 @@ -1,52 +0,0 @@ 336.4 -; Copyright (c) Rich Hickey. All rights reserved. 336.5 -; The use and distribution terms for this software are covered by the 336.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 336.7 -; which can be found in the file epl-v10.html at the root of this distribution. 336.8 -; By using this software in any fashion, you are agreeing to be bound by 336.9 -; the terms of this license. 336.10 -; You must not remove this notice, or any other, from this software. 336.11 - 336.12 -(ns 336.13 - ^{:author "Christophe Grand", 336.14 - :doc "Start a web browser from Clojure"} 336.15 - clojure.java.browse 336.16 - (:require [clojure.java.shell :as sh]) 336.17 - (:import (java.net URI))) 336.18 - 336.19 -(defn- macosx? [] 336.20 - (-> "os.name" System/getProperty .toLowerCase 336.21 - (.startsWith "mac os x"))) 336.22 - 336.23 -(def *open-url-script* (when (macosx?) "/usr/bin/open")) 336.24 - 336.25 -(defn- open-url-in-browser 336.26 - "Opens url (a string) in the default system web browser. May not 336.27 - work on all platforms. Returns url on success, nil if not 336.28 - supported." 336.29 - [url] 336.30 - (try 336.31 - (when (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" 336.32 - "isDesktopSupported" (to-array nil)) 336.33 - (-> (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" 336.34 - "getDesktop" (to-array nil)) 336.35 - (.browse (URI. url))) 336.36 - url) 336.37 - (catch ClassNotFoundException e 336.38 - nil))) 336.39 - 336.40 -(defn- open-url-in-swing 336.41 - "Opens url (a string) in a Swing window." 336.42 - [url] 336.43 - ; the implementation of this function resides in another namespace to be loaded "on demand" 336.44 - ; this fixes a bug on mac os x where the process turns into a GUI app 336.45 - ; see http://code.google.com/p/clojure-contrib/issues/detail?id=32 336.46 - (require 'clojure.java.browse-ui) 336.47 - ((find-var 'clojure.java.browse-ui/open-url-in-swing) url)) 336.48 - 336.49 -(defn browse-url 336.50 - "Open url in a browser" 336.51 - {:added "1.2"} 336.52 - [url] 336.53 - (or (open-url-in-browser url) 336.54 - (when *open-url-script* (sh/sh *open-url-script* (str url)) true) 336.55 - (open-url-in-swing url)))
337.1 --- a/src/clojure/java/browse_ui.clj Sat Aug 21 06:25:44 2010 -0400 337.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 337.3 @@ -1,30 +0,0 @@ 337.4 -; Copyright (c) Rich Hickey. All rights reserved. 337.5 -; The use and distribution terms for this software are covered by the 337.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 337.7 -; which can be found in the file epl-v10.html at the root of this distribution. 337.8 -; By using this software in any fashion, you are agreeing to be bound by 337.9 -; the terms of this license. 337.10 -; You must not remove this notice, or any other, from this software. 337.11 - 337.12 -(ns 337.13 - ^{:author "Christophe Grand", 337.14 - :doc "Helper namespace for clojure.java.browse. 337.15 - Prevents console apps from becoming GUI unnecessarily."} 337.16 - clojure.java.browse-ui) 337.17 - 337.18 -(defn- open-url-in-swing 337.19 - [url] 337.20 - (let [htmlpane (javax.swing.JEditorPane. url)] 337.21 - (.setEditable htmlpane false) 337.22 - (.addHyperlinkListener htmlpane 337.23 - (proxy [javax.swing.event.HyperlinkListener] [] 337.24 - (hyperlinkUpdate [#^javax.swing.event.HyperlinkEvent e] 337.25 - (when (= (.getEventType e) (. javax.swing.event.HyperlinkEvent$EventType ACTIVATED)) 337.26 - (if (instance? javax.swing.text.html.HTMLFrameHyperlinkEvent e) 337.27 - (-> htmlpane .getDocument (.processHTMLFrameHyperlinkEvent e)) 337.28 - (.setPage htmlpane (.getURL e))))))) 337.29 - (doto (javax.swing.JFrame.) 337.30 - (.setContentPane (javax.swing.JScrollPane. htmlpane)) 337.31 - (.setBounds 32 32 700 900) 337.32 - (.show)))) 337.33 -
338.1 --- a/src/clojure/java/io.clj Sat Aug 21 06:25:44 2010 -0400 338.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 338.3 @@ -1,427 +0,0 @@ 338.4 -; Copyright (c) Rich Hickey. All rights reserved. 338.5 -; The use and distribution terms for this software are covered by the 338.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 338.7 -; which can be found in the file epl-v10.html at the root of this distribution. 338.8 -; By using this software in any fashion, you are agreeing to be bound by 338.9 -; the terms of this license. 338.10 -; You must not remove this notice, or any other, from this software. 338.11 - 338.12 -(ns 338.13 - ^{:author "Stuart Sierra, Chas Emerick, Stuart Halloway", 338.14 - :doc "This file defines polymorphic I/O utility functions for Clojure."} 338.15 - clojure.java.io 338.16 - (:import 338.17 - (java.io Reader InputStream InputStreamReader PushbackReader 338.18 - BufferedReader File OutputStream 338.19 - OutputStreamWriter BufferedWriter Writer 338.20 - FileInputStream FileOutputStream ByteArrayOutputStream 338.21 - StringReader ByteArrayInputStream 338.22 - BufferedInputStream BufferedOutputStream 338.23 - CharArrayReader Closeable) 338.24 - (java.net URI URL MalformedURLException Socket))) 338.25 - 338.26 -(def 338.27 - ^{:doc "Type object for a Java primitive byte array." 338.28 - :private true 338.29 - } 338.30 - byte-array-type (class (make-array Byte/TYPE 0))) 338.31 - 338.32 -(def 338.33 - ^{:doc "Type object for a Java primitive char array." 338.34 - :private true} 338.35 - char-array-type (class (make-array Character/TYPE 0))) 338.36 - 338.37 -(defprotocol ^{:added "1.2"} Coercions 338.38 - "Coerce between various 'resource-namish' things." 338.39 - (^{:tag java.io.File, :added "1.2"} as-file [x] "Coerce argument to a file.") 338.40 - (^{:tag java.net.URL, :added "1.2"} as-url [x] "Coerce argument to a URL.")) 338.41 - 338.42 -(extend-protocol Coercions 338.43 - nil 338.44 - (as-file [_] nil) 338.45 - (as-url [_] nil) 338.46 - 338.47 - String 338.48 - (as-file [s] (File. s)) 338.49 - (as-url [s] (URL. s)) 338.50 - 338.51 - File 338.52 - (as-file [f] f) 338.53 - (as-url [f] (.toURL f)) 338.54 - 338.55 - URL 338.56 - (as-url [u] u) 338.57 - (as-file [u] 338.58 - (if (= "file" (.getProtocol u)) 338.59 - (as-file (.getPath u)) 338.60 - (throw (IllegalArgumentException. "Not a file: " u)))) 338.61 - 338.62 - URI 338.63 - (as-url [u] (.toURL u)) 338.64 - (as-file [u] (as-file (as-url u)))) 338.65 - 338.66 -(defprotocol ^{:added "1.2"} IOFactory 338.67 - "Factory functions that create ready-to-use, buffered versions of 338.68 - the various Java I/O stream types, on top of anything that can 338.69 - be unequivocally converted to the requested kind of stream. 338.70 - 338.71 - Common options include 338.72 - 338.73 - :append true to open stream in append mode 338.74 - :encoding string name of encoding to use, e.g. \"UTF-8\". 338.75 - 338.76 - Callers should generally prefer the higher level API provided by 338.77 - reader, writer, input-stream, and output-stream." 338.78 - (^{:added "1.2"} make-reader [x opts] "Creates a BufferedReader. See also IOFactory docs.") 338.79 - (^{:added "1.2"} make-writer [x opts] "Creates a BufferedWriter. See also IOFactory docs.") 338.80 - (^{:added "1.2"} make-input-stream [x opts] "Creates a BufferedInputStream. See also IOFactory docs.") 338.81 - (^{:added "1.2"} make-output-stream [x opts] "Creates a BufferedOutputStream. See also IOFactory docs.")) 338.82 - 338.83 -(defn ^Reader reader 338.84 - "Attempts to coerce its argument into an open java.io.Reader. 338.85 - Default implementations always return a java.io.BufferedReader. 338.86 - 338.87 - Default implementations are provided for Reader, BufferedReader, 338.88 - InputStream, File, URI, URL, Socket, byte arrays, character arrays, 338.89 - and String. 338.90 - 338.91 - If argument is a String, it tries to resolve it first as a URI, then 338.92 - as a local file name. URIs with a 'file' protocol are converted to 338.93 - local file names. 338.94 - 338.95 - Should be used inside with-open to ensure the Reader is properly 338.96 - closed." 338.97 - {:added "1.2"} 338.98 - [x & opts] 338.99 - (make-reader x (when opts (apply hash-map opts)))) 338.100 - 338.101 -(defn ^Writer writer 338.102 - "Attempts to coerce its argument into an open java.io.Writer. 338.103 - Default implementations always return a java.io.BufferedWriter. 338.104 - 338.105 - Default implementations are provided for Writer, BufferedWriter, 338.106 - OutputStream, File, URI, URL, Socket, and String. 338.107 - 338.108 - If the argument is a String, it tries to resolve it first as a URI, then 338.109 - as a local file name. URIs with a 'file' protocol are converted to 338.110 - local file names. 338.111 - 338.112 - Should be used inside with-open to ensure the Writer is properly 338.113 - closed." 338.114 - {:added "1.2"} 338.115 - [x & opts] 338.116 - (make-writer x (when opts (apply hash-map opts)))) 338.117 - 338.118 -(defn ^InputStream input-stream 338.119 - "Attempts to coerce its argument into an open java.io.InputStream. 338.120 - Default implementations always return a java.io.BufferedInputStream. 338.121 - 338.122 - Default implementations are defined for OutputStream, File, URI, URL, 338.123 - Socket, byte array, and String arguments. 338.124 - 338.125 - If the argument is a String, it tries to resolve it first as a URI, then 338.126 - as a local file name. URIs with a 'file' protocol are converted to 338.127 - local file names. 338.128 - 338.129 - Should be used inside with-open to ensure the InputStream is properly 338.130 - closed." 338.131 - {:added "1.2"} 338.132 - [x & opts] 338.133 - (make-input-stream x (when opts (apply hash-map opts)))) 338.134 - 338.135 -(defn ^OutputStream output-stream 338.136 - "Attempts to coerce its argument into an open java.io.OutputStream. 338.137 - Default implementations always return a java.io.BufferedOutputStream. 338.138 - 338.139 - Default implementations are defined for OutputStream, File, URI, URL, 338.140 - Socket, and String arguments. 338.141 - 338.142 - If the argument is a String, it tries to resolve it first as a URI, then 338.143 - as a local file name. URIs with a 'file' protocol are converted to 338.144 - local file names. 338.145 - 338.146 - Should be used inside with-open to ensure the OutputStream is 338.147 - properly closed." 338.148 - {:added "1.2"} 338.149 - [x & opts] 338.150 - (make-output-stream x (when opts (apply hash-map opts)))) 338.151 - 338.152 -(defn- ^Boolean append? [opts] 338.153 - (boolean (:append opts))) 338.154 - 338.155 -(defn- ^String encoding [opts] 338.156 - (or (:encoding opts) "UTF-8")) 338.157 - 338.158 -(defn- buffer-size [opts] 338.159 - (or (:buffer-size opts) 1024)) 338.160 - 338.161 -(def default-streams-impl 338.162 - {:make-reader (fn [x opts] (make-reader (make-input-stream x opts) opts)) 338.163 - :make-writer (fn [x opts] (make-writer (make-output-stream x opts) opts)) 338.164 - :make-input-stream (fn [x opts] 338.165 - (throw (IllegalArgumentException. 338.166 - (str "Cannot open <" (pr-str x) "> as an InputStream.")))) 338.167 - :make-output-stream (fn [x opts] 338.168 - (throw (IllegalArgumentException. 338.169 - (str "Cannot open <" (pr-str x) "> as an OutputStream."))))}) 338.170 - 338.171 -(defn- inputstream->reader 338.172 - [^InputStream is opts] 338.173 - (make-reader (InputStreamReader. is (encoding opts)) opts)) 338.174 - 338.175 -(defn- outputstream->writer 338.176 - [^OutputStream os opts] 338.177 - (make-writer (OutputStreamWriter. os (encoding opts)) opts)) 338.178 - 338.179 -(extend BufferedInputStream 338.180 - IOFactory 338.181 - (assoc default-streams-impl 338.182 - :make-input-stream (fn [x opts] x) 338.183 - :make-reader inputstream->reader)) 338.184 - 338.185 -(extend InputStream 338.186 - IOFactory 338.187 - (assoc default-streams-impl 338.188 - :make-input-stream (fn [x opts] (BufferedInputStream. x)) 338.189 - :make-reader inputstream->reader)) 338.190 - 338.191 -(extend Reader 338.192 - IOFactory 338.193 - (assoc default-streams-impl 338.194 - :make-reader (fn [x opts] (BufferedReader. x)))) 338.195 - 338.196 -(extend BufferedReader 338.197 - IOFactory 338.198 - (assoc default-streams-impl 338.199 - :make-reader (fn [x opts] x))) 338.200 - 338.201 -(extend Writer 338.202 - IOFactory 338.203 - (assoc default-streams-impl 338.204 - :make-writer (fn [x opts] (BufferedWriter. x)))) 338.205 - 338.206 -(extend BufferedWriter 338.207 - IOFactory 338.208 - (assoc default-streams-impl 338.209 - :make-writer (fn [x opts] x))) 338.210 - 338.211 -(extend OutputStream 338.212 - IOFactory 338.213 - (assoc default-streams-impl 338.214 - :make-output-stream (fn [x opts] (BufferedOutputStream. x)) 338.215 - :make-writer outputstream->writer)) 338.216 - 338.217 -(extend BufferedOutputStream 338.218 - IOFactory 338.219 - (assoc default-streams-impl 338.220 - :make-output-stream (fn [x opts] x) 338.221 - :make-writer outputstream->writer)) 338.222 - 338.223 -(extend File 338.224 - IOFactory 338.225 - (assoc default-streams-impl 338.226 - :make-input-stream (fn [^File x opts] (make-input-stream (FileInputStream. x) opts)) 338.227 - :make-output-stream (fn [^File x opts] (make-output-stream (FileOutputStream. x (append? opts)) opts)))) 338.228 - 338.229 -(extend URL 338.230 - IOFactory 338.231 - (assoc default-streams-impl 338.232 - :make-input-stream (fn [^URL x opts] 338.233 - (make-input-stream 338.234 - (if (= "file" (.getProtocol x)) 338.235 - (FileInputStream. (.getPath x)) 338.236 - (.openStream x)) opts)) 338.237 - :make-output-stream (fn [^URL x opts] 338.238 - (if (= "file" (.getProtocol x)) 338.239 - (make-output-stream (File. (.getPath x)) opts) 338.240 - (throw (IllegalArgumentException. (str "Can not write to non-file URL <" x ">"))))))) 338.241 - 338.242 -(extend URI 338.243 - IOFactory 338.244 - (assoc default-streams-impl 338.245 - :make-input-stream (fn [^URI x opts] (make-input-stream (.toURL x) opts)) 338.246 - :make-output-stream (fn [^URI x opts] (make-output-stream (.toURL x) opts)))) 338.247 - 338.248 -(extend String 338.249 - IOFactory 338.250 - (assoc default-streams-impl 338.251 - :make-input-stream (fn [^String x opts] 338.252 - (try 338.253 - (make-input-stream (URL. x) opts) 338.254 - (catch MalformedURLException e 338.255 - (make-input-stream (File. x) opts)))) 338.256 - :make-output-stream (fn [^String x opts] 338.257 - (try 338.258 - (make-output-stream (URL. x) opts) 338.259 - (catch MalformedURLException err 338.260 - (make-output-stream (File. x) opts)))))) 338.261 - 338.262 -(extend Socket 338.263 - IOFactory 338.264 - (assoc default-streams-impl 338.265 - :make-input-stream (fn [^Socket x opts] (make-input-stream (.getInputStream x) opts)) 338.266 - :make-output-stream (fn [^Socket x opts] (make-output-stream (.getOutputStream x) opts)))) 338.267 - 338.268 -(extend byte-array-type 338.269 - IOFactory 338.270 - (assoc default-streams-impl 338.271 - :make-input-stream (fn [x opts] (make-input-stream (ByteArrayInputStream. x) opts)))) 338.272 - 338.273 -(extend char-array-type 338.274 - IOFactory 338.275 - (assoc default-streams-impl 338.276 - :make-reader (fn [x opts] (make-reader (CharArrayReader. x) opts)))) 338.277 - 338.278 -(extend Object 338.279 - IOFactory 338.280 - default-streams-impl) 338.281 - 338.282 -(defmulti 338.283 - #^{:doc "Internal helper for copy" 338.284 - :private true 338.285 - :arglists '([input output opts])} 338.286 - do-copy 338.287 - (fn [input output opts] [(type input) (type output)])) 338.288 - 338.289 -(defmethod do-copy [InputStream OutputStream] [#^InputStream input #^OutputStream output opts] 338.290 - (let [buffer (make-array Byte/TYPE (buffer-size opts))] 338.291 - (loop [] 338.292 - (let [size (.read input buffer)] 338.293 - (when (pos? size) 338.294 - (do (.write output buffer 0 size) 338.295 - (recur))))))) 338.296 - 338.297 -(defmethod do-copy [InputStream Writer] [#^InputStream input #^Writer output opts] 338.298 - (let [#^"[B" buffer (make-array Byte/TYPE (buffer-size opts))] 338.299 - (loop [] 338.300 - (let [size (.read input buffer)] 338.301 - (when (pos? size) 338.302 - (let [chars (.toCharArray (String. buffer 0 size (encoding opts)))] 338.303 - (do (.write output chars) 338.304 - (recur)))))))) 338.305 - 338.306 -(defmethod do-copy [InputStream File] [#^InputStream input #^File output opts] 338.307 - (with-open [out (FileOutputStream. output)] 338.308 - (do-copy input out opts))) 338.309 - 338.310 -(defmethod do-copy [Reader OutputStream] [#^Reader input #^OutputStream output opts] 338.311 - (let [#^"[C" buffer (make-array Character/TYPE (buffer-size opts))] 338.312 - (loop [] 338.313 - (let [size (.read input buffer)] 338.314 - (when (pos? size) 338.315 - (let [bytes (.getBytes (String. buffer 0 size) (encoding opts))] 338.316 - (do (.write output bytes) 338.317 - (recur)))))))) 338.318 - 338.319 -(defmethod do-copy [Reader Writer] [#^Reader input #^Writer output opts] 338.320 - (let [#^"[C" buffer (make-array Character/TYPE (buffer-size opts))] 338.321 - (loop [] 338.322 - (let [size (.read input buffer)] 338.323 - (when (pos? size) 338.324 - (do (.write output buffer 0 size) 338.325 - (recur))))))) 338.326 - 338.327 -(defmethod do-copy [Reader File] [#^Reader input #^File output opts] 338.328 - (with-open [out (FileOutputStream. output)] 338.329 - (do-copy input out opts))) 338.330 - 338.331 -(defmethod do-copy [File OutputStream] [#^File input #^OutputStream output opts] 338.332 - (with-open [in (FileInputStream. input)] 338.333 - (do-copy in output opts))) 338.334 - 338.335 -(defmethod do-copy [File Writer] [#^File input #^Writer output opts] 338.336 - (with-open [in (FileInputStream. input)] 338.337 - (do-copy in output opts))) 338.338 - 338.339 -(defmethod do-copy [File File] [#^File input #^File output opts] 338.340 - (with-open [in (FileInputStream. input) 338.341 - out (FileOutputStream. output)] 338.342 - (do-copy in out opts))) 338.343 - 338.344 -(defmethod do-copy [String OutputStream] [#^String input #^OutputStream output opts] 338.345 - (do-copy (StringReader. input) output opts)) 338.346 - 338.347 -(defmethod do-copy [String Writer] [#^String input #^Writer output opts] 338.348 - (do-copy (StringReader. input) output opts)) 338.349 - 338.350 -(defmethod do-copy [String File] [#^String input #^File output opts] 338.351 - (do-copy (StringReader. input) output opts)) 338.352 - 338.353 -(defmethod do-copy [char-array-type OutputStream] [input #^OutputStream output opts] 338.354 - (do-copy (CharArrayReader. input) output opts)) 338.355 - 338.356 -(defmethod do-copy [char-array-type Writer] [input #^Writer output opts] 338.357 - (do-copy (CharArrayReader. input) output opts)) 338.358 - 338.359 -(defmethod do-copy [char-array-type File] [input #^File output opts] 338.360 - (do-copy (CharArrayReader. input) output opts)) 338.361 - 338.362 -(defmethod do-copy [byte-array-type OutputStream] [#^"[B" input #^OutputStream output opts] 338.363 - (do-copy (ByteArrayInputStream. input) output opts)) 338.364 - 338.365 -(defmethod do-copy [byte-array-type Writer] [#^"[B" input #^Writer output opts] 338.366 - (do-copy (ByteArrayInputStream. input) output opts)) 338.367 - 338.368 -(defmethod do-copy [byte-array-type File] [#^"[B" input #^Writer output opts] 338.369 - (do-copy (ByteArrayInputStream. input) output opts)) 338.370 - 338.371 -(defn copy 338.372 - "Copies input to output. Returns nil or throws IOException. 338.373 - Input may be an InputStream, Reader, File, byte[], or String. 338.374 - Output may be an OutputStream, Writer, or File. 338.375 - 338.376 - Options are key/value pairs and may be one of 338.377 - 338.378 - :buffer-size buffer size to use, default is 1024. 338.379 - :encoding encoding to use if converting between 338.380 - byte and char streams. 338.381 - 338.382 - Does not close any streams except those it opens itself 338.383 - (on a File)." 338.384 - {:added "1.2"} 338.385 - [input output & opts] 338.386 - (do-copy input output (when opts (apply hash-map opts)))) 338.387 - 338.388 -(defn ^String as-relative-path 338.389 - "Take an as-file-able thing and return a string if it is 338.390 - a relative path, else IllegalArgumentException." 338.391 - {:added "1.2"} 338.392 - [x] 338.393 - (let [^File f (as-file x)] 338.394 - (if (.isAbsolute f) 338.395 - (throw (IllegalArgumentException. (str f " is not a relative path"))) 338.396 - (.getPath f)))) 338.397 - 338.398 -(defn ^File file 338.399 - "Returns a java.io.File, passing each arg to as-file. Multiple-arg 338.400 - versions treat the first argument as parent and subsequent args as 338.401 - children relative to the parent." 338.402 - {:added "1.2"} 338.403 - ([arg] 338.404 - (as-file arg)) 338.405 - ([parent child] 338.406 - (File. ^File (as-file parent) ^String (as-relative-path child))) 338.407 - ([parent child & more] 338.408 - (reduce file (file parent child) more))) 338.409 - 338.410 -(defn delete-file 338.411 - "Delete file f. Raise an exception if it fails unless silently is true." 338.412 - {:added "1.2"} 338.413 - [f & [silently]] 338.414 - (or (.delete (file f)) 338.415 - silently 338.416 - (throw (java.io.IOException. (str "Couldn't delete " f))))) 338.417 - 338.418 -(defn make-parents 338.419 - "Given the same arg(s) as for file, creates all parent directories of 338.420 - the file they represent." 338.421 - {:added "1.2"} 338.422 - [f & more] 338.423 - (.mkdirs (.getParentFile ^File (apply file f more)))) 338.424 - 338.425 -(defn ^URL resource 338.426 - "Returns the URL for a named resource. Use the context class loader 338.427 - if no loader is specified." 338.428 - {:added "1.2"} 338.429 - ([n] (resource n (.getContextClassLoader (Thread/currentThread)))) 338.430 - ([n ^ClassLoader loader] (.getResource loader n)))
339.1 --- a/src/clojure/java/javadoc.clj Sat Aug 21 06:25:44 2010 -0400 339.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 339.3 @@ -1,82 +0,0 @@ 339.4 -; Copyright (c) Rich Hickey. All rights reserved. 339.5 -; The use and distribution terms for this software are covered by the 339.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 339.7 -; which can be found in the file epl-v10.html at the root of this distribution. 339.8 -; By using this software in any fashion, you are agreeing to be bound by 339.9 -; the terms of this license. 339.10 -; You must not remove this notice, or any other, from this software. 339.11 -(ns 339.12 - ^{:author "Christophe Grand, Stuart Sierra", 339.13 - :doc "A repl helper to quickly open javadocs."} 339.14 - clojure.java.javadoc 339.15 - (:use [clojure.java.browse :only (browse-url)] ) 339.16 - (:import 339.17 - (java.io File))) 339.18 - 339.19 -(def *feeling-lucky-url* "http://www.google.com/search?btnI=I%27m%20Feeling%20Lucky&q=allinurl:") 339.20 -(def *feeling-lucky* true) 339.21 - 339.22 -(def *local-javadocs* (ref (list))) 339.23 - 339.24 -(def *core-java-api* 339.25 - (if (= "1.5" (System/getProperty "java.specification.version")) 339.26 - "http://java.sun.com/j2se/1.5.0/docs/api/" 339.27 - "http://java.sun.com/javase/6/docs/api/")) 339.28 - 339.29 -(def *remote-javadocs* 339.30 - (ref (sorted-map 339.31 - "java." *core-java-api* 339.32 - "javax." *core-java-api* 339.33 - "org.ietf.jgss." *core-java-api* 339.34 - "org.omg." *core-java-api* 339.35 - "org.w3c.dom." *core-java-api* 339.36 - "org.xml.sax." *core-java-api* 339.37 - "org.apache.commons.codec." "http://commons.apache.org/codec/api-release/" 339.38 - "org.apache.commons.io." "http://commons.apache.org/io/api-release/" 339.39 - "org.apache.commons.lang." "http://commons.apache.org/lang/api-release/"))) 339.40 - 339.41 -(defn add-local-javadoc 339.42 - "Adds to the list of local Javadoc paths." 339.43 - {:added "1.2"} 339.44 - [path] 339.45 - (dosync (commute *local-javadocs* conj path))) 339.46 - 339.47 -(defn add-remote-javadoc 339.48 - "Adds to the list of remote Javadoc URLs. package-prefix is the 339.49 - beginning of the package name that has docs at this URL." 339.50 - {:added "1.2"} 339.51 - [package-prefix url] 339.52 - (dosync (commute *remote-javadocs* assoc package-prefix url))) 339.53 - 339.54 -(defn- javadoc-url 339.55 - "Searches for a URL for the given class name. Tries 339.56 - *local-javadocs* first, then *remote-javadocs*. Returns a string." 339.57 - {:tag String, 339.58 - :added "1.2"} 339.59 - [^String classname] 339.60 - (let [file-path (.replace classname \. File/separatorChar) 339.61 - url-path (.replace classname \. \/)] 339.62 - (if-let [file ^File (first 339.63 - (filter #(.exists ^File %) 339.64 - (map #(File. (str %) (str file-path ".html")) 339.65 - @*local-javadocs*)))] 339.66 - (-> file .toURI str) 339.67 - ;; If no local file, try remote URLs: 339.68 - (or (some (fn [[prefix url]] 339.69 - (when (.startsWith classname prefix) 339.70 - (str url url-path ".html"))) 339.71 - @*remote-javadocs*) 339.72 - ;; if *feeling-lucky* try a web search 339.73 - (when *feeling-lucky* (str *feeling-lucky-url* url-path ".html")))))) 339.74 - 339.75 -(defn javadoc 339.76 - "Opens a browser window displaying the javadoc for the argument. 339.77 - Tries *local-javadocs* first, then *remote-javadocs*." 339.78 - {:added "1.2"} 339.79 - [class-or-object] 339.80 - (let [^Class c (if (instance? Class class-or-object) 339.81 - class-or-object 339.82 - (class class-or-object))] 339.83 - (if-let [url (javadoc-url (.getName c))] 339.84 - (browse-url url) 339.85 - (println "Could not find Javadoc for" c))))
340.1 --- a/src/clojure/java/shell.clj Sat Aug 21 06:25:44 2010 -0400 340.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 340.3 @@ -1,143 +0,0 @@ 340.4 -; Copyright (c) Rich Hickey. All rights reserved. 340.5 -; The use and distribution terms for this software are covered by the 340.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 340.7 -; which can be found in the file epl-v10.html at the root of this distribution. 340.8 -; By using this software in any fashion, you are agreeing to be bound by 340.9 -; the terms of this license. 340.10 -; You must not remove this notice, or any other, from this software. 340.11 - 340.12 -(ns 340.13 - ^{:author "Chris Houser, Stuart Halloway", 340.14 - :doc "Conveniently launch a sub-process providing its stdin and 340.15 -collecting its stdout"} 340.16 - clojure.java.shell 340.17 - (:use [clojure.java.io :only (as-file copy)]) 340.18 - (:import (java.io OutputStreamWriter ByteArrayOutputStream StringWriter) 340.19 - (java.nio.charset Charset))) 340.20 - 340.21 -(def *sh-dir* nil) 340.22 -(def *sh-env* nil) 340.23 - 340.24 -(defmacro with-sh-dir 340.25 - "Sets the directory for use with sh, see sh for details." 340.26 - {:added "1.2"} 340.27 - [dir & forms] 340.28 - `(binding [*sh-dir* ~dir] 340.29 - ~@forms)) 340.30 - 340.31 -(defmacro with-sh-env 340.32 - "Sets the environment for use with sh, see sh for details." 340.33 - {:added "1.2"} 340.34 - [env & forms] 340.35 - `(binding [*sh-env* ~env] 340.36 - ~@forms)) 340.37 - 340.38 -(defn- aconcat 340.39 - "Concatenates arrays of given type." 340.40 - [type & xs] 340.41 - (let [target (make-array type (apply + (map count xs)))] 340.42 - (loop [i 0 idx 0] 340.43 - (when-let [a (nth xs i nil)] 340.44 - (System/arraycopy a 0 target idx (count a)) 340.45 - (recur (inc i) (+ idx (count a))))) 340.46 - target)) 340.47 - 340.48 -(defn- parse-args 340.49 - [args] 340.50 - (let [default-encoding "UTF-8" ;; see sh doc string 340.51 - default-opts {:out-enc default-encoding :in-enc default-encoding :dir *sh-dir* :env *sh-env*} 340.52 - [cmd opts] (split-with string? args)] 340.53 - [cmd (merge default-opts (apply hash-map opts))])) 340.54 - 340.55 -(defn- ^"[Ljava.lang.String;" as-env-strings 340.56 - "Helper so that callers can pass a Clojure map for the :env to sh." 340.57 - [arg] 340.58 - (cond 340.59 - (nil? arg) nil 340.60 - (map? arg) (into-array String (map (fn [[k v]] (str (name k) "=" v)) arg)) 340.61 - true arg)) 340.62 - 340.63 -(defn- stream-to-bytes 340.64 - [in] 340.65 - (with-open [bout (ByteArrayOutputStream.)] 340.66 - (copy in bout) 340.67 - (.toByteArray bout))) 340.68 - 340.69 -(defn- stream-to-string 340.70 - ([in] (stream-to-string in (.name (Charset/defaultCharset)))) 340.71 - ([in enc] 340.72 - (with-open [bout (StringWriter.)] 340.73 - (copy in bout :encoding enc) 340.74 - (.toString bout)))) 340.75 - 340.76 -(defn- stream-to-enc 340.77 - [stream enc] 340.78 - (if (= enc :bytes) 340.79 - (stream-to-bytes stream) 340.80 - (stream-to-string stream enc))) 340.81 - 340.82 -(defn sh 340.83 - "Passes the given strings to Runtime.exec() to launch a sub-process. 340.84 - 340.85 - Options are 340.86 - 340.87 - :in may be given followed by a String or byte array specifying input 340.88 - to be fed to the sub-process's stdin. 340.89 - :in-enc option may be given followed by a String, used as a character 340.90 - encoding name (for example \"UTF-8\" or \"ISO-8859-1\") to 340.91 - convert the input string specified by the :in option to the 340.92 - sub-process's stdin. Defaults to UTF-8. 340.93 - If the :in option provides a byte array, then the bytes are passed 340.94 - unencoded, and this option is ignored. 340.95 - :out-enc option may be given followed by :bytes or a String. If a 340.96 - String is given, it will be used as a character encoding 340.97 - name (for example \"UTF-8\" or \"ISO-8859-1\") to convert 340.98 - the sub-process's stdout to a String which is returned. 340.99 - If :bytes is given, the sub-process's stdout will be stored 340.100 - in a byte array and returned. Defaults to UTF-8. 340.101 - :env override the process env with a map (or the underlying Java 340.102 - String[] if you are a masochist). 340.103 - :dir override the process dir with a String or java.io.File. 340.104 - 340.105 - You can bind :env or :dir for multiple operations using with-sh-env 340.106 - and with-sh-dir. 340.107 - 340.108 - sh returns a map of 340.109 - :exit => sub-process's exit code 340.110 - :out => sub-process's stdout (as byte[] or String) 340.111 - :err => sub-process's stderr (String via platform default encoding)" 340.112 - {:added "1.2"} 340.113 - [& args] 340.114 - (let [[cmd opts] (parse-args args) 340.115 - proc (.exec (Runtime/getRuntime) 340.116 - ^"[Ljava.lang.String;" (into-array cmd) 340.117 - (as-env-strings (:env opts)) 340.118 - (as-file (:dir opts))) 340.119 - {:keys [in in-enc out-enc]} opts] 340.120 - (if in 340.121 - (future 340.122 - (if (instance? (class (byte-array 0)) in) 340.123 - (with-open [os (.getOutputStream proc)] 340.124 - (.write os ^"[B" in)) 340.125 - (with-open [osw (OutputStreamWriter. (.getOutputStream proc) ^String in-enc)] 340.126 - (.write osw ^String in)))) 340.127 - (.close (.getOutputStream proc))) 340.128 - (with-open [stdout (.getInputStream proc) 340.129 - stderr (.getErrorStream proc)] 340.130 - (let [out (future (stream-to-enc stdout out-enc)) 340.131 - err (future (stream-to-string stderr)) 340.132 - exit-code (.waitFor proc)] 340.133 - {:exit exit-code :out @out :err @err})))) 340.134 - 340.135 -(comment 340.136 - 340.137 -(println (sh "ls" "-l")) 340.138 -(println (sh "ls" "-l" "/no-such-thing")) 340.139 -(println (sh "sed" "s/[aeiou]/oo/g" :in "hello there\n")) 340.140 -(println (sh "cat" :in "x\u25bax\n")) 340.141 -(println (sh "echo" "x\u25bax")) 340.142 -(println (sh "echo" "x\u25bax" :out-enc "ISO-8859-1")) ; reads 4 single-byte chars 340.143 -(println (sh "cat" "myimage.png" :out-enc :bytes)) ; reads binary file into bytes[] 340.144 -(println (sh "cmd" "/c dir 1>&2")) 340.145 - 340.146 -)
341.1 --- a/src/clojure/lang/AFn.java Sat Aug 21 06:25:44 2010 -0400 341.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 341.3 @@ -1,442 +0,0 @@ 341.4 -/** 341.5 - * Copyright (c) Rich Hickey. All rights reserved. 341.6 - * The use and distribution terms for this software are covered by the 341.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 341.8 - * which can be found in the file epl-v10.html at the root of this distribution. 341.9 - * By using this software in any fashion, you are agreeing to be bound by 341.10 - * the terms of this license. 341.11 - * You must not remove this notice, or any other, from this software. 341.12 - **/ 341.13 - 341.14 -/* rich Mar 25, 2006 4:05:37 PM */ 341.15 - 341.16 -package clojure.lang; 341.17 - 341.18 -public abstract class AFn implements IFn { 341.19 - 341.20 -public Object call() throws Exception{ 341.21 - return invoke(); 341.22 -} 341.23 - 341.24 -public void run(){ 341.25 - try 341.26 - { 341.27 - invoke(); 341.28 - } 341.29 - catch(Exception e) 341.30 - { 341.31 - throw new RuntimeException(e); 341.32 - } 341.33 -} 341.34 - 341.35 - 341.36 - 341.37 -public Object invoke() throws Exception{ 341.38 - return throwArity(0); 341.39 -} 341.40 - 341.41 -public Object invoke(Object arg1) throws Exception{ 341.42 - return throwArity(1); 341.43 -} 341.44 - 341.45 -public Object invoke(Object arg1, Object arg2) throws Exception{ 341.46 - return throwArity(2); 341.47 -} 341.48 - 341.49 -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception{ 341.50 - return throwArity(3); 341.51 -} 341.52 - 341.53 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception{ 341.54 - return throwArity(4); 341.55 -} 341.56 - 341.57 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception{ 341.58 - return throwArity(5); 341.59 -} 341.60 - 341.61 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception{ 341.62 - return throwArity(6); 341.63 -} 341.64 - 341.65 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) 341.66 - throws Exception{ 341.67 - return throwArity(7); 341.68 -} 341.69 - 341.70 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.71 - Object arg8) throws Exception{ 341.72 - return throwArity(8); 341.73 -} 341.74 - 341.75 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.76 - Object arg8, Object arg9) throws Exception{ 341.77 - return throwArity(9); 341.78 -} 341.79 - 341.80 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.81 - Object arg8, Object arg9, Object arg10) throws Exception{ 341.82 - return throwArity(10); 341.83 -} 341.84 - 341.85 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.86 - Object arg8, Object arg9, Object arg10, Object arg11) throws Exception{ 341.87 - return throwArity(11); 341.88 -} 341.89 - 341.90 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.91 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception{ 341.92 - return throwArity(12); 341.93 -} 341.94 - 341.95 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.96 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) 341.97 - throws Exception{ 341.98 - return throwArity(13); 341.99 -} 341.100 - 341.101 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.102 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) 341.103 - throws Exception{ 341.104 - return throwArity(14); 341.105 -} 341.106 - 341.107 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.108 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 341.109 - Object arg15) throws Exception{ 341.110 - return throwArity(15); 341.111 -} 341.112 - 341.113 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.114 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 341.115 - Object arg15, Object arg16) throws Exception{ 341.116 - return throwArity(16); 341.117 -} 341.118 - 341.119 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.120 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 341.121 - Object arg15, Object arg16, Object arg17) throws Exception{ 341.122 - return throwArity(17); 341.123 -} 341.124 - 341.125 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.126 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 341.127 - Object arg15, Object arg16, Object arg17, Object arg18) throws Exception{ 341.128 - return throwArity(18); 341.129 -} 341.130 - 341.131 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.132 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 341.133 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception{ 341.134 - return throwArity(19); 341.135 -} 341.136 - 341.137 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.138 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 341.139 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20) 341.140 - throws Exception{ 341.141 - return throwArity(20); 341.142 -} 341.143 - 341.144 - 341.145 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 341.146 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 341.147 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20, 341.148 - Object... args) 341.149 - throws Exception{ 341.150 - return throwArity(21); 341.151 -} 341.152 - 341.153 -public Object applyTo(ISeq arglist) throws Exception{ 341.154 - return applyToHelper(this, Util.ret1(arglist,arglist = null)); 341.155 -} 341.156 - 341.157 -static public Object applyToHelper(IFn ifn, ISeq arglist) throws Exception{ 341.158 - switch(RT.boundedLength(arglist, 20)) 341.159 - { 341.160 - case 0: 341.161 - arglist = null; 341.162 - return ifn.invoke(); 341.163 - case 1: 341.164 - Object a1 = arglist.first(); 341.165 - arglist = null; 341.166 - return ifn.invoke(a1); 341.167 - case 2: 341.168 - return ifn.invoke(arglist.first() 341.169 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.170 - ); 341.171 - case 3: 341.172 - return ifn.invoke(arglist.first() 341.173 - , (arglist = arglist.next()).first() 341.174 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.175 - ); 341.176 - case 4: 341.177 - return ifn.invoke(arglist.first() 341.178 - , (arglist = arglist.next()).first() 341.179 - , (arglist = arglist.next()).first() 341.180 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.181 - ); 341.182 - case 5: 341.183 - return ifn.invoke(arglist.first() 341.184 - , (arglist = arglist.next()).first() 341.185 - , (arglist = arglist.next()).first() 341.186 - , (arglist = arglist.next()).first() 341.187 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.188 - ); 341.189 - case 6: 341.190 - return ifn.invoke(arglist.first() 341.191 - , (arglist = arglist.next()).first() 341.192 - , (arglist = arglist.next()).first() 341.193 - , (arglist = arglist.next()).first() 341.194 - , (arglist = arglist.next()).first() 341.195 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.196 - ); 341.197 - case 7: 341.198 - return ifn.invoke(arglist.first() 341.199 - , (arglist = arglist.next()).first() 341.200 - , (arglist = arglist.next()).first() 341.201 - , (arglist = arglist.next()).first() 341.202 - , (arglist = arglist.next()).first() 341.203 - , (arglist = arglist.next()).first() 341.204 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.205 - ); 341.206 - case 8: 341.207 - return ifn.invoke(arglist.first() 341.208 - , (arglist = arglist.next()).first() 341.209 - , (arglist = arglist.next()).first() 341.210 - , (arglist = arglist.next()).first() 341.211 - , (arglist = arglist.next()).first() 341.212 - , (arglist = arglist.next()).first() 341.213 - , (arglist = arglist.next()).first() 341.214 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.215 - ); 341.216 - case 9: 341.217 - return ifn.invoke(arglist.first() 341.218 - , (arglist = arglist.next()).first() 341.219 - , (arglist = arglist.next()).first() 341.220 - , (arglist = arglist.next()).first() 341.221 - , (arglist = arglist.next()).first() 341.222 - , (arglist = arglist.next()).first() 341.223 - , (arglist = arglist.next()).first() 341.224 - , (arglist = arglist.next()).first() 341.225 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.226 - ); 341.227 - case 10: 341.228 - return ifn.invoke(arglist.first() 341.229 - , (arglist = arglist.next()).first() 341.230 - , (arglist = arglist.next()).first() 341.231 - , (arglist = arglist.next()).first() 341.232 - , (arglist = arglist.next()).first() 341.233 - , (arglist = arglist.next()).first() 341.234 - , (arglist = arglist.next()).first() 341.235 - , (arglist = arglist.next()).first() 341.236 - , (arglist = arglist.next()).first() 341.237 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.238 - ); 341.239 - case 11: 341.240 - return ifn.invoke(arglist.first() 341.241 - , (arglist = arglist.next()).first() 341.242 - , (arglist = arglist.next()).first() 341.243 - , (arglist = arglist.next()).first() 341.244 - , (arglist = arglist.next()).first() 341.245 - , (arglist = arglist.next()).first() 341.246 - , (arglist = arglist.next()).first() 341.247 - , (arglist = arglist.next()).first() 341.248 - , (arglist = arglist.next()).first() 341.249 - , (arglist = arglist.next()).first() 341.250 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.251 - ); 341.252 - case 12: 341.253 - return ifn.invoke(arglist.first() 341.254 - , (arglist = arglist.next()).first() 341.255 - , (arglist = arglist.next()).first() 341.256 - , (arglist = arglist.next()).first() 341.257 - , (arglist = arglist.next()).first() 341.258 - , (arglist = arglist.next()).first() 341.259 - , (arglist = arglist.next()).first() 341.260 - , (arglist = arglist.next()).first() 341.261 - , (arglist = arglist.next()).first() 341.262 - , (arglist = arglist.next()).first() 341.263 - , (arglist = arglist.next()).first() 341.264 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.265 - ); 341.266 - case 13: 341.267 - return ifn.invoke(arglist.first() 341.268 - , (arglist = arglist.next()).first() 341.269 - , (arglist = arglist.next()).first() 341.270 - , (arglist = arglist.next()).first() 341.271 - , (arglist = arglist.next()).first() 341.272 - , (arglist = arglist.next()).first() 341.273 - , (arglist = arglist.next()).first() 341.274 - , (arglist = arglist.next()).first() 341.275 - , (arglist = arglist.next()).first() 341.276 - , (arglist = arglist.next()).first() 341.277 - , (arglist = arglist.next()).first() 341.278 - , (arglist = arglist.next()).first() 341.279 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.280 - ); 341.281 - case 14: 341.282 - return ifn.invoke(arglist.first() 341.283 - , (arglist = arglist.next()).first() 341.284 - , (arglist = arglist.next()).first() 341.285 - , (arglist = arglist.next()).first() 341.286 - , (arglist = arglist.next()).first() 341.287 - , (arglist = arglist.next()).first() 341.288 - , (arglist = arglist.next()).first() 341.289 - , (arglist = arglist.next()).first() 341.290 - , (arglist = arglist.next()).first() 341.291 - , (arglist = arglist.next()).first() 341.292 - , (arglist = arglist.next()).first() 341.293 - , (arglist = arglist.next()).first() 341.294 - , (arglist = arglist.next()).first() 341.295 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.296 - ); 341.297 - case 15: 341.298 - return ifn.invoke(arglist.first() 341.299 - , (arglist = arglist.next()).first() 341.300 - , (arglist = arglist.next()).first() 341.301 - , (arglist = arglist.next()).first() 341.302 - , (arglist = arglist.next()).first() 341.303 - , (arglist = arglist.next()).first() 341.304 - , (arglist = arglist.next()).first() 341.305 - , (arglist = arglist.next()).first() 341.306 - , (arglist = arglist.next()).first() 341.307 - , (arglist = arglist.next()).first() 341.308 - , (arglist = arglist.next()).first() 341.309 - , (arglist = arglist.next()).first() 341.310 - , (arglist = arglist.next()).first() 341.311 - , (arglist = arglist.next()).first() 341.312 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.313 - ); 341.314 - case 16: 341.315 - return ifn.invoke(arglist.first() 341.316 - , (arglist = arglist.next()).first() 341.317 - , (arglist = arglist.next()).first() 341.318 - , (arglist = arglist.next()).first() 341.319 - , (arglist = arglist.next()).first() 341.320 - , (arglist = arglist.next()).first() 341.321 - , (arglist = arglist.next()).first() 341.322 - , (arglist = arglist.next()).first() 341.323 - , (arglist = arglist.next()).first() 341.324 - , (arglist = arglist.next()).first() 341.325 - , (arglist = arglist.next()).first() 341.326 - , (arglist = arglist.next()).first() 341.327 - , (arglist = arglist.next()).first() 341.328 - , (arglist = arglist.next()).first() 341.329 - , (arglist = arglist.next()).first() 341.330 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.331 - ); 341.332 - case 17: 341.333 - return ifn.invoke(arglist.first() 341.334 - , (arglist = arglist.next()).first() 341.335 - , (arglist = arglist.next()).first() 341.336 - , (arglist = arglist.next()).first() 341.337 - , (arglist = arglist.next()).first() 341.338 - , (arglist = arglist.next()).first() 341.339 - , (arglist = arglist.next()).first() 341.340 - , (arglist = arglist.next()).first() 341.341 - , (arglist = arglist.next()).first() 341.342 - , (arglist = arglist.next()).first() 341.343 - , (arglist = arglist.next()).first() 341.344 - , (arglist = arglist.next()).first() 341.345 - , (arglist = arglist.next()).first() 341.346 - , (arglist = arglist.next()).first() 341.347 - , (arglist = arglist.next()).first() 341.348 - , (arglist = arglist.next()).first() 341.349 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.350 - ); 341.351 - case 18: 341.352 - return ifn.invoke(arglist.first() 341.353 - , (arglist = arglist.next()).first() 341.354 - , (arglist = arglist.next()).first() 341.355 - , (arglist = arglist.next()).first() 341.356 - , (arglist = arglist.next()).first() 341.357 - , (arglist = arglist.next()).first() 341.358 - , (arglist = arglist.next()).first() 341.359 - , (arglist = arglist.next()).first() 341.360 - , (arglist = arglist.next()).first() 341.361 - , (arglist = arglist.next()).first() 341.362 - , (arglist = arglist.next()).first() 341.363 - , (arglist = arglist.next()).first() 341.364 - , (arglist = arglist.next()).first() 341.365 - , (arglist = arglist.next()).first() 341.366 - , (arglist = arglist.next()).first() 341.367 - , (arglist = arglist.next()).first() 341.368 - , (arglist = arglist.next()).first() 341.369 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.370 - ); 341.371 - case 19: 341.372 - return ifn.invoke(arglist.first() 341.373 - , (arglist = arglist.next()).first() 341.374 - , (arglist = arglist.next()).first() 341.375 - , (arglist = arglist.next()).first() 341.376 - , (arglist = arglist.next()).first() 341.377 - , (arglist = arglist.next()).first() 341.378 - , (arglist = arglist.next()).first() 341.379 - , (arglist = arglist.next()).first() 341.380 - , (arglist = arglist.next()).first() 341.381 - , (arglist = arglist.next()).first() 341.382 - , (arglist = arglist.next()).first() 341.383 - , (arglist = arglist.next()).first() 341.384 - , (arglist = arglist.next()).first() 341.385 - , (arglist = arglist.next()).first() 341.386 - , (arglist = arglist.next()).first() 341.387 - , (arglist = arglist.next()).first() 341.388 - , (arglist = arglist.next()).first() 341.389 - , (arglist = arglist.next()).first() 341.390 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.391 - ); 341.392 - case 20: 341.393 - return ifn.invoke(arglist.first() 341.394 - , (arglist = arglist.next()).first() 341.395 - , (arglist = arglist.next()).first() 341.396 - , (arglist = arglist.next()).first() 341.397 - , (arglist = arglist.next()).first() 341.398 - , (arglist = arglist.next()).first() 341.399 - , (arglist = arglist.next()).first() 341.400 - , (arglist = arglist.next()).first() 341.401 - , (arglist = arglist.next()).first() 341.402 - , (arglist = arglist.next()).first() 341.403 - , (arglist = arglist.next()).first() 341.404 - , (arglist = arglist.next()).first() 341.405 - , (arglist = arglist.next()).first() 341.406 - , (arglist = arglist.next()).first() 341.407 - , (arglist = arglist.next()).first() 341.408 - , (arglist = arglist.next()).first() 341.409 - , (arglist = arglist.next()).first() 341.410 - , (arglist = arglist.next()).first() 341.411 - , (arglist = arglist.next()).first() 341.412 - , Util.ret1((arglist = arglist.next()).first(),arglist = null) 341.413 - ); 341.414 - default: 341.415 - return ifn.invoke(arglist.first() 341.416 - , (arglist = arglist.next()).first() 341.417 - , (arglist = arglist.next()).first() 341.418 - , (arglist = arglist.next()).first() 341.419 - , (arglist = arglist.next()).first() 341.420 - , (arglist = arglist.next()).first() 341.421 - , (arglist = arglist.next()).first() 341.422 - , (arglist = arglist.next()).first() 341.423 - , (arglist = arglist.next()).first() 341.424 - , (arglist = arglist.next()).first() 341.425 - , (arglist = arglist.next()).first() 341.426 - , (arglist = arglist.next()).first() 341.427 - , (arglist = arglist.next()).first() 341.428 - , (arglist = arglist.next()).first() 341.429 - , (arglist = arglist.next()).first() 341.430 - , (arglist = arglist.next()).first() 341.431 - , (arglist = arglist.next()).first() 341.432 - , (arglist = arglist.next()).first() 341.433 - , (arglist = arglist.next()).first() 341.434 - , (arglist = arglist.next()).first() 341.435 - , RT.seqToArray(Util.ret1(arglist.next(),arglist = null))); 341.436 - } 341.437 -} 341.438 - 341.439 -public Object throwArity(int n){ 341.440 - String name = getClass().getSimpleName(); 341.441 - int suffix = name.lastIndexOf("__"); 341.442 - throw new IllegalArgumentException("Wrong number of args (" + n + ") passed to: " 341.443 - + (suffix == -1 ? name : name.substring(0, suffix)).replace('_', '-')); 341.444 -} 341.445 -}
342.1 --- a/src/clojure/lang/AFunction.java Sat Aug 21 06:25:44 2010 -0400 342.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 342.3 @@ -1,42 +0,0 @@ 342.4 -/** 342.5 - * Copyright (c) Rich Hickey. All rights reserved. 342.6 - * The use and distribution terms for this software are covered by the 342.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 342.8 - * which can be found in the file epl-v10.html at the root of this distribution. 342.9 - * By using this software in any fashion, you are agreeing to be bound by 342.10 - * the terms of this license. 342.11 - * You must not remove this notice, or any other, from this software. 342.12 - **/ 342.13 - 342.14 -/* rich Dec 16, 2008 */ 342.15 - 342.16 -package clojure.lang; 342.17 - 342.18 -import java.io.Serializable; 342.19 -import java.util.Comparator; 342.20 - 342.21 -public abstract class AFunction extends AFn implements IObj, Comparator, Fn, Serializable { 342.22 - 342.23 -public volatile MethodImplCache __methodImplCache; 342.24 - 342.25 -public int compare(Object o1, Object o2){ 342.26 - try 342.27 - { 342.28 - Object o = invoke(o1, o2); 342.29 - 342.30 - if(o instanceof Boolean) 342.31 - { 342.32 - if(RT.booleanCast(o)) 342.33 - return -1; 342.34 - return RT.booleanCast(invoke(o2,o1))? 1 : 0; 342.35 - } 342.36 - 342.37 - Number n = (Number) o; 342.38 - return n.intValue(); 342.39 - } 342.40 - catch(Exception e) 342.41 - { 342.42 - throw new RuntimeException(e); 342.43 - } 342.44 -} 342.45 -}
343.1 --- a/src/clojure/lang/AMapEntry.java Sat Aug 21 06:25:44 2010 -0400 343.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 343.3 @@ -1,149 +0,0 @@ 343.4 -/** 343.5 - * Copyright (c) Rich Hickey. All rights reserved. 343.6 - * The use and distribution terms for this software are covered by the 343.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 343.8 - * which can be found in the file epl-v10.html at the root of this distribution. 343.9 - * By using this software in any fashion, you are agreeing to be bound by 343.10 - * the terms of this license. 343.11 - * You must not remove this notice, or any other, from this software. 343.12 - **/ 343.13 - 343.14 -/* rich Mar 1, 2008 */ 343.15 - 343.16 -package clojure.lang; 343.17 - 343.18 -import java.io.StringWriter; 343.19 - 343.20 -public abstract class AMapEntry extends APersistentVector implements IMapEntry{ 343.21 - 343.22 -public Object nth(int i){ 343.23 - if(i == 0) 343.24 - return key(); 343.25 - else if(i == 1) 343.26 - return val(); 343.27 - else 343.28 - throw new IndexOutOfBoundsException(); 343.29 -} 343.30 - 343.31 -private IPersistentVector asVector(){ 343.32 - return LazilyPersistentVector.createOwning(key(), val()); 343.33 -} 343.34 - 343.35 -public IPersistentVector assocN(int i, Object val){ 343.36 - return asVector().assocN(i, val); 343.37 -} 343.38 - 343.39 -public int count(){ 343.40 - return 2; 343.41 -} 343.42 - 343.43 -public ISeq seq(){ 343.44 - return asVector().seq(); 343.45 -} 343.46 - 343.47 -public IPersistentVector cons(Object o){ 343.48 - return asVector().cons(o); 343.49 -} 343.50 - 343.51 -public IPersistentCollection empty(){ 343.52 - return null; 343.53 -} 343.54 - 343.55 -public IPersistentStack pop(){ 343.56 - return LazilyPersistentVector.createOwning(key()); 343.57 -} 343.58 - 343.59 -public Object setValue(Object value){ 343.60 - throw new UnsupportedOperationException(); 343.61 -} 343.62 - 343.63 -/* 343.64 - 343.65 -public boolean equals(Object obj){ 343.66 - return APersistentVector.doEquals(this, obj); 343.67 -} 343.68 - 343.69 -public int hashCode(){ 343.70 - //must match logic in APersistentVector 343.71 - return 31 * (31 + Util.hash(key())) + Util.hash(val()); 343.72 -// return Util.hashCombine(Util.hashCombine(0, Util.hash(key())), Util.hash(val())); 343.73 -} 343.74 - 343.75 -public String toString(){ 343.76 - StringWriter sw = new StringWriter(); 343.77 - try 343.78 - { 343.79 - RT.print(this, sw); 343.80 - } 343.81 - catch(Exception e) 343.82 - { 343.83 - //checked exceptions stink! 343.84 - throw new RuntimeException(e); 343.85 - } 343.86 - return sw.toString(); 343.87 -} 343.88 - 343.89 -public int length(){ 343.90 - return 2; 343.91 -} 343.92 - 343.93 -public Object nth(int i){ 343.94 - if(i == 0) 343.95 - return key(); 343.96 - else if(i == 1) 343.97 - return val(); 343.98 - else 343.99 - throw new IndexOutOfBoundsException(); 343.100 -} 343.101 - 343.102 -private IPersistentVector asVector(){ 343.103 - return LazilyPersistentVector.createOwning(key(), val()); 343.104 -} 343.105 - 343.106 -public IPersistentVector assocN(int i, Object val){ 343.107 - return asVector().assocN(i, val); 343.108 -} 343.109 - 343.110 -public int count(){ 343.111 - return 2; 343.112 -} 343.113 - 343.114 -public ISeq seq(){ 343.115 - return asVector().seq(); 343.116 -} 343.117 - 343.118 -public IPersistentVector cons(Object o){ 343.119 - return asVector().cons(o); 343.120 -} 343.121 - 343.122 -public boolean containsKey(Object key){ 343.123 - return asVector().containsKey(key); 343.124 -} 343.125 - 343.126 -public IMapEntry entryAt(Object key){ 343.127 - return asVector().entryAt(key); 343.128 -} 343.129 - 343.130 -public Associative assoc(Object key, Object val){ 343.131 - return asVector().assoc(key, val); 343.132 -} 343.133 - 343.134 -public Object valAt(Object key){ 343.135 - return asVector().valAt(key); 343.136 -} 343.137 - 343.138 -public Object valAt(Object key, Object notFound){ 343.139 - return asVector().valAt(key, notFound); 343.140 -} 343.141 - 343.142 -public Object peek(){ 343.143 - return val(); 343.144 -} 343.145 - 343.146 - 343.147 -public ISeq rseq() throws Exception{ 343.148 - return asVector().rseq(); 343.149 -} 343.150 -*/ 343.151 - 343.152 -}
344.1 --- a/src/clojure/lang/APersistentMap.java Sat Aug 21 06:25:44 2010 -0400 344.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 344.3 @@ -1,384 +0,0 @@ 344.4 -/** 344.5 - * Copyright (c) Rich Hickey. All rights reserved. 344.6 - * The use and distribution terms for this software are covered by the 344.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 344.8 - * which can be found in the file epl-v10.html at the root of this distribution. 344.9 - * By using this software in any fashion, you are agreeing to be bound by 344.10 - * the terms of this license. 344.11 - * You must not remove this notice, or any other, from this software. 344.12 - **/ 344.13 - 344.14 -package clojure.lang; 344.15 - 344.16 -import java.io.Serializable; 344.17 -import java.util.*; 344.18 - 344.19 -public abstract class APersistentMap extends AFn implements IPersistentMap, Map, Iterable, Serializable, MapEquivalence { 344.20 -int _hash = -1; 344.21 - 344.22 -public String toString(){ 344.23 - return RT.printString(this); 344.24 -} 344.25 - 344.26 -public IPersistentCollection cons(Object o){ 344.27 - if(o instanceof Map.Entry) 344.28 - { 344.29 - Map.Entry e = (Map.Entry) o; 344.30 - 344.31 - return assoc(e.getKey(), e.getValue()); 344.32 - } 344.33 - else if(o instanceof IPersistentVector) 344.34 - { 344.35 - IPersistentVector v = (IPersistentVector) o; 344.36 - if(v.count() != 2) 344.37 - throw new IllegalArgumentException("Vector arg to map conj must be a pair"); 344.38 - return assoc(v.nth(0), v.nth(1)); 344.39 - } 344.40 - 344.41 - IPersistentMap ret = this; 344.42 - for(ISeq es = RT.seq(o); es != null; es = es.next()) 344.43 - { 344.44 - Map.Entry e = (Map.Entry) es.first(); 344.45 - ret = ret.assoc(e.getKey(), e.getValue()); 344.46 - } 344.47 - return ret; 344.48 -} 344.49 - 344.50 -public boolean equals(Object obj){ 344.51 - return mapEquals(this, obj); 344.52 -} 344.53 - 344.54 -static public boolean mapEquals(IPersistentMap m1, Object obj){ 344.55 - if(m1 == obj) return true; 344.56 - if(!(obj instanceof Map)) 344.57 - return false; 344.58 - Map m = (Map) obj; 344.59 - 344.60 - if(m.size() != m1.count() || m.hashCode() != m1.hashCode()) 344.61 - return false; 344.62 - 344.63 - for(ISeq s = m1.seq(); s != null; s = s.next()) 344.64 - { 344.65 - Map.Entry e = (Map.Entry) s.first(); 344.66 - boolean found = m.containsKey(e.getKey()); 344.67 - 344.68 - if(!found || !Util.equals(e.getValue(), m.get(e.getKey()))) 344.69 - return false; 344.70 - } 344.71 - 344.72 - return true; 344.73 -} 344.74 - 344.75 -public boolean equiv(Object obj){ 344.76 - if(!(obj instanceof Map)) 344.77 - return false; 344.78 - if(obj instanceof IPersistentMap && !(obj instanceof MapEquivalence)) 344.79 - return false; 344.80 - 344.81 - Map m = (Map) obj; 344.82 - 344.83 - if(m.size() != size()) 344.84 - return false; 344.85 - 344.86 - for(ISeq s = seq(); s != null; s = s.next()) 344.87 - { 344.88 - Map.Entry e = (Map.Entry) s.first(); 344.89 - boolean found = m.containsKey(e.getKey()); 344.90 - 344.91 - if(!found || !Util.equiv(e.getValue(), m.get(e.getKey()))) 344.92 - return false; 344.93 - } 344.94 - 344.95 - return true; 344.96 -} 344.97 -public int hashCode(){ 344.98 - if(_hash == -1) 344.99 - { 344.100 - this._hash = mapHash(this); 344.101 - } 344.102 - return _hash; 344.103 -} 344.104 - 344.105 -static public int mapHash(IPersistentMap m){ 344.106 - int hash = 0; 344.107 - for(ISeq s = m.seq(); s != null; s = s.next()) 344.108 - { 344.109 - Map.Entry e = (Map.Entry) s.first(); 344.110 - hash += (e.getKey() == null ? 0 : e.getKey().hashCode()) ^ 344.111 - (e.getValue() == null ? 0 : e.getValue().hashCode()); 344.112 - } 344.113 - return hash; 344.114 -} 344.115 - 344.116 -static public class KeySeq extends ASeq{ 344.117 - ISeq seq; 344.118 - 344.119 - static public KeySeq create(ISeq seq){ 344.120 - if(seq == null) 344.121 - return null; 344.122 - return new KeySeq(seq); 344.123 - } 344.124 - 344.125 - private KeySeq(ISeq seq){ 344.126 - this.seq = seq; 344.127 - } 344.128 - 344.129 - private KeySeq(IPersistentMap meta, ISeq seq){ 344.130 - super(meta); 344.131 - this.seq = seq; 344.132 - } 344.133 - 344.134 - public Object first(){ 344.135 - return ((Map.Entry) seq.first()).getKey(); 344.136 - } 344.137 - 344.138 - public ISeq next(){ 344.139 - return create(seq.next()); 344.140 - } 344.141 - 344.142 - public KeySeq withMeta(IPersistentMap meta){ 344.143 - return new KeySeq(meta, seq); 344.144 - } 344.145 -} 344.146 - 344.147 -static public class ValSeq extends ASeq{ 344.148 - ISeq seq; 344.149 - 344.150 - static public ValSeq create(ISeq seq){ 344.151 - if(seq == null) 344.152 - return null; 344.153 - return new ValSeq(seq); 344.154 - } 344.155 - 344.156 - private ValSeq(ISeq seq){ 344.157 - this.seq = seq; 344.158 - } 344.159 - 344.160 - private ValSeq(IPersistentMap meta, ISeq seq){ 344.161 - super(meta); 344.162 - this.seq = seq; 344.163 - } 344.164 - 344.165 - public Object first(){ 344.166 - return ((Map.Entry) seq.first()).getValue(); 344.167 - } 344.168 - 344.169 - public ISeq next(){ 344.170 - return create(seq.next()); 344.171 - } 344.172 - 344.173 - public ValSeq withMeta(IPersistentMap meta){ 344.174 - return new ValSeq(meta, seq); 344.175 - } 344.176 -} 344.177 - 344.178 - 344.179 -public Object invoke(Object arg1) throws Exception{ 344.180 - return valAt(arg1); 344.181 -} 344.182 - 344.183 -public Object invoke(Object arg1, Object notFound) throws Exception{ 344.184 - return valAt(arg1, notFound); 344.185 -} 344.186 - 344.187 -// java.util.Map implementation 344.188 - 344.189 -public void clear(){ 344.190 - throw new UnsupportedOperationException(); 344.191 -} 344.192 - 344.193 -public boolean containsValue(Object value){ 344.194 - return values().contains(value); 344.195 -} 344.196 - 344.197 -public Set entrySet(){ 344.198 - return new AbstractSet(){ 344.199 - 344.200 - public Iterator iterator(){ 344.201 - return APersistentMap.this.iterator(); 344.202 - } 344.203 - 344.204 - public int size(){ 344.205 - return count(); 344.206 - } 344.207 - 344.208 - public int hashCode(){ 344.209 - return APersistentMap.this.hashCode(); 344.210 - } 344.211 - 344.212 - public boolean contains(Object o){ 344.213 - if(o instanceof Entry) 344.214 - { 344.215 - Entry e = (Entry) o; 344.216 - Entry found = entryAt(e.getKey()); 344.217 - if(found != null && Util.equals(found.getValue(), e.getValue())) 344.218 - return true; 344.219 - } 344.220 - return false; 344.221 - } 344.222 - }; 344.223 -} 344.224 - 344.225 -public Object get(Object key){ 344.226 - return valAt(key); 344.227 -} 344.228 - 344.229 -public boolean isEmpty(){ 344.230 - return count() == 0; 344.231 -} 344.232 - 344.233 -public Set keySet(){ 344.234 - return new AbstractSet(){ 344.235 - 344.236 - public Iterator iterator(){ 344.237 - final Iterator mi = APersistentMap.this.iterator(); 344.238 - 344.239 - return new Iterator(){ 344.240 - 344.241 - 344.242 - public boolean hasNext(){ 344.243 - return mi.hasNext(); 344.244 - } 344.245 - 344.246 - public Object next(){ 344.247 - Entry e = (Entry) mi.next(); 344.248 - return e.getKey(); 344.249 - } 344.250 - 344.251 - public void remove(){ 344.252 - throw new UnsupportedOperationException(); 344.253 - } 344.254 - }; 344.255 - } 344.256 - 344.257 - public int size(){ 344.258 - return count(); 344.259 - } 344.260 - 344.261 - public boolean contains(Object o){ 344.262 - return APersistentMap.this.containsKey(o); 344.263 - } 344.264 - }; 344.265 -} 344.266 - 344.267 -public Object put(Object key, Object value){ 344.268 - throw new UnsupportedOperationException(); 344.269 -} 344.270 - 344.271 -public void putAll(Map t){ 344.272 - throw new UnsupportedOperationException(); 344.273 -} 344.274 - 344.275 -public Object remove(Object key){ 344.276 - throw new UnsupportedOperationException(); 344.277 -} 344.278 - 344.279 -public int size(){ 344.280 - return count(); 344.281 -} 344.282 - 344.283 -public Collection values(){ 344.284 - return new AbstractCollection(){ 344.285 - 344.286 - public Iterator iterator(){ 344.287 - final Iterator mi = APersistentMap.this.iterator(); 344.288 - 344.289 - return new Iterator(){ 344.290 - 344.291 - 344.292 - public boolean hasNext(){ 344.293 - return mi.hasNext(); 344.294 - } 344.295 - 344.296 - public Object next(){ 344.297 - Entry e = (Entry) mi.next(); 344.298 - return e.getValue(); 344.299 - } 344.300 - 344.301 - public void remove(){ 344.302 - throw new UnsupportedOperationException(); 344.303 - } 344.304 - }; 344.305 - } 344.306 - 344.307 - public int size(){ 344.308 - return count(); 344.309 - } 344.310 - }; 344.311 -} 344.312 - 344.313 -/* 344.314 -// java.util.Collection implementation 344.315 - 344.316 -public Object[] toArray(){ 344.317 - return RT.seqToArray(seq()); 344.318 -} 344.319 - 344.320 -public boolean add(Object o){ 344.321 - throw new UnsupportedOperationException(); 344.322 -} 344.323 - 344.324 -public boolean remove(Object o){ 344.325 - throw new UnsupportedOperationException(); 344.326 -} 344.327 - 344.328 -public boolean addAll(Collection c){ 344.329 - throw new UnsupportedOperationException(); 344.330 -} 344.331 - 344.332 -public void clear(){ 344.333 - throw new UnsupportedOperationException(); 344.334 -} 344.335 - 344.336 -public boolean retainAll(Collection c){ 344.337 - throw new UnsupportedOperationException(); 344.338 -} 344.339 - 344.340 -public boolean removeAll(Collection c){ 344.341 - throw new UnsupportedOperationException(); 344.342 -} 344.343 - 344.344 -public boolean containsAll(Collection c){ 344.345 - for(Object o : c) 344.346 - { 344.347 - if(!contains(o)) 344.348 - return false; 344.349 - } 344.350 - return true; 344.351 -} 344.352 - 344.353 -public Object[] toArray(Object[] a){ 344.354 - if(a.length >= count()) 344.355 - { 344.356 - ISeq s = seq(); 344.357 - for(int i = 0; s != null; ++i, s = s.rest()) 344.358 - { 344.359 - a[i] = s.first(); 344.360 - } 344.361 - if(a.length > count()) 344.362 - a[count()] = null; 344.363 - return a; 344.364 - } 344.365 - else 344.366 - return toArray(); 344.367 -} 344.368 - 344.369 -public int size(){ 344.370 - return count(); 344.371 -} 344.372 - 344.373 -public boolean isEmpty(){ 344.374 - return count() == 0; 344.375 -} 344.376 - 344.377 -public boolean contains(Object o){ 344.378 - if(o instanceof Map.Entry) 344.379 - { 344.380 - Map.Entry e = (Map.Entry) o; 344.381 - Map.Entry v = entryAt(e.getKey()); 344.382 - return (v != null && Util.equal(v.getValue(), e.getValue())); 344.383 - } 344.384 - return false; 344.385 -} 344.386 -*/ 344.387 -}
345.1 --- a/src/clojure/lang/APersistentSet.java Sat Aug 21 06:25:44 2010 -0400 345.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 345.3 @@ -1,160 +0,0 @@ 345.4 -/** 345.5 - * Copyright (c) Rich Hickey. All rights reserved. 345.6 - * The use and distribution terms for this software are covered by the 345.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 345.8 - * which can be found in the file epl-v10.html at the root of this distribution. 345.9 - * By using this software in any fashion, you are agreeing to be bound by 345.10 - * the terms of this license. 345.11 - * You must not remove this notice, or any other, from this software. 345.12 - **/ 345.13 - 345.14 -/* rich Mar 3, 2008 */ 345.15 - 345.16 -package clojure.lang; 345.17 - 345.18 -import java.io.Serializable; 345.19 -import java.util.Collection; 345.20 -import java.util.Iterator; 345.21 -import java.util.Set; 345.22 - 345.23 -public abstract class APersistentSet extends AFn implements IPersistentSet, Collection, Set, Serializable { 345.24 -int _hash = -1; 345.25 -final IPersistentMap impl; 345.26 - 345.27 -protected APersistentSet(IPersistentMap impl){ 345.28 - this.impl = impl; 345.29 -} 345.30 - 345.31 -public String toString(){ 345.32 - return RT.printString(this); 345.33 -} 345.34 - 345.35 -public boolean contains(Object key){ 345.36 - return impl.containsKey(key); 345.37 -} 345.38 - 345.39 -public Object get(Object key){ 345.40 - return impl.valAt(key); 345.41 -} 345.42 - 345.43 -public int count(){ 345.44 - return impl.count(); 345.45 -} 345.46 - 345.47 -public ISeq seq(){ 345.48 - return RT.keys(impl); 345.49 -} 345.50 - 345.51 -public Object invoke(Object arg1) throws Exception{ 345.52 - return get(arg1); 345.53 -} 345.54 - 345.55 -public boolean equals(Object obj){ 345.56 - if(this == obj) return true; 345.57 - if(!(obj instanceof Set)) 345.58 - return false; 345.59 - Set m = (Set) obj; 345.60 - 345.61 - if(m.size() != count() || m.hashCode() != hashCode()) 345.62 - return false; 345.63 - 345.64 - for(Object aM : m) 345.65 - { 345.66 - if(!contains(aM)) 345.67 - return false; 345.68 - } 345.69 -// for(ISeq s = seq(); s != null; s = s.rest()) 345.70 -// { 345.71 -// if(!m.contains(s.first())) 345.72 -// return false; 345.73 -// } 345.74 - 345.75 - return true; 345.76 -} 345.77 - 345.78 -public boolean equiv(Object o){ 345.79 - return equals(o); 345.80 -} 345.81 - 345.82 -public int hashCode(){ 345.83 - if(_hash == -1) 345.84 - { 345.85 - //int hash = count(); 345.86 - int hash = 0; 345.87 - for(ISeq s = seq(); s != null; s = s.next()) 345.88 - { 345.89 - Object e = s.first(); 345.90 -// hash = Util.hashCombine(hash, Util.hash(e)); 345.91 - hash += Util.hash(e); 345.92 - } 345.93 - this._hash = hash; 345.94 - } 345.95 - return _hash; 345.96 -} 345.97 - 345.98 -public Object[] toArray(){ 345.99 - return RT.seqToArray(seq()); 345.100 -} 345.101 - 345.102 -public boolean add(Object o){ 345.103 - throw new UnsupportedOperationException(); 345.104 -} 345.105 - 345.106 -public boolean remove(Object o){ 345.107 - throw new UnsupportedOperationException(); 345.108 -} 345.109 - 345.110 -public boolean addAll(Collection c){ 345.111 - throw new UnsupportedOperationException(); 345.112 -} 345.113 - 345.114 -public void clear(){ 345.115 - throw new UnsupportedOperationException(); 345.116 -} 345.117 - 345.118 -public boolean retainAll(Collection c){ 345.119 - throw new UnsupportedOperationException(); 345.120 -} 345.121 - 345.122 -public boolean removeAll(Collection c){ 345.123 - throw new UnsupportedOperationException(); 345.124 -} 345.125 - 345.126 -public boolean containsAll(Collection c){ 345.127 - for(Object o : c) 345.128 - { 345.129 - if(!contains(o)) 345.130 - return false; 345.131 - } 345.132 - return true; 345.133 -} 345.134 - 345.135 -public Object[] toArray(Object[] a){ 345.136 - if(a.length >= count()) 345.137 - { 345.138 - ISeq s = seq(); 345.139 - for(int i = 0; s != null; ++i, s = s.next()) 345.140 - { 345.141 - a[i] = s.first(); 345.142 - } 345.143 - if(a.length > count()) 345.144 - a[count()] = null; 345.145 - return a; 345.146 - } 345.147 - else 345.148 - return toArray(); 345.149 -} 345.150 - 345.151 -public int size(){ 345.152 - return count(); 345.153 -} 345.154 - 345.155 -public boolean isEmpty(){ 345.156 - return count() == 0; 345.157 -} 345.158 - 345.159 -public Iterator iterator(){ 345.160 - return new SeqIterator(seq()); 345.161 -} 345.162 - 345.163 -}
346.1 --- a/src/clojure/lang/APersistentVector.java Sat Aug 21 06:25:44 2010 -0400 346.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 346.3 @@ -1,568 +0,0 @@ 346.4 -/** 346.5 - * Copyright (c) Rich Hickey. All rights reserved. 346.6 - * The use and distribution terms for this software are covered by the 346.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 346.8 - * which can be found in the file epl-v10.html at the root of this distribution. 346.9 - * By using this software in any fashion, you are agreeing to be bound by 346.10 - * the terms of this license. 346.11 - * You must not remove this notice, or any other, from this software. 346.12 - **/ 346.13 - 346.14 -/* rich Dec 18, 2007 */ 346.15 - 346.16 -package clojure.lang; 346.17 - 346.18 -import java.io.Serializable; 346.19 -import java.util.*; 346.20 - 346.21 -public abstract class APersistentVector extends AFn implements IPersistentVector, Iterable, 346.22 - List, 346.23 - RandomAccess, Comparable, 346.24 - Serializable { 346.25 -int _hash = -1; 346.26 - 346.27 -public String toString(){ 346.28 - return RT.printString(this); 346.29 -} 346.30 - 346.31 -public ISeq seq(){ 346.32 - if(count() > 0) 346.33 - return new Seq(this, 0); 346.34 - return null; 346.35 -} 346.36 - 346.37 -public ISeq rseq(){ 346.38 - if(count() > 0) 346.39 - return new RSeq(this, count() - 1); 346.40 - return null; 346.41 -} 346.42 - 346.43 -static boolean doEquals(IPersistentVector v, Object obj){ 346.44 - if(v == obj) return true; 346.45 - if(obj instanceof List || obj instanceof IPersistentVector) 346.46 - { 346.47 - Collection ma = (Collection) obj; 346.48 - if(ma.size() != v.count() || ma.hashCode() != v.hashCode()) 346.49 - return false; 346.50 - for(Iterator i1 = ((List) v).iterator(), i2 = ma.iterator(); 346.51 - i1.hasNext();) 346.52 - { 346.53 - if(!Util.equals(i1.next(), i2.next())) 346.54 - return false; 346.55 - } 346.56 - return true; 346.57 - } 346.58 -// if(obj instanceof IPersistentVector) 346.59 -// { 346.60 -// IPersistentVector ma = (IPersistentVector) obj; 346.61 -// if(ma.count() != v.count() || ma.hashCode() != v.hashCode()) 346.62 -// return false; 346.63 -// for(int i = 0; i < v.count(); i++) 346.64 -// { 346.65 -// if(!Util.equal(v.nth(i), ma.nth(i))) 346.66 -// return false; 346.67 -// } 346.68 -// } 346.69 - else 346.70 - { 346.71 - if(!(obj instanceof Sequential)) 346.72 - return false; 346.73 - ISeq ms = RT.seq(obj); 346.74 - for(int i = 0; i < v.count(); i++, ms = ms.next()) 346.75 - { 346.76 - if(ms == null || !Util.equals(v.nth(i), ms.first())) 346.77 - return false; 346.78 - } 346.79 - if(ms != null) 346.80 - return false; 346.81 - } 346.82 - 346.83 - return true; 346.84 - 346.85 -} 346.86 - 346.87 -static boolean doEquiv(IPersistentVector v, Object obj){ 346.88 - if(obj instanceof List || obj instanceof IPersistentVector) 346.89 - { 346.90 - Collection ma = (Collection) obj; 346.91 - if(ma.size() != v.count()) 346.92 - return false; 346.93 - for(Iterator i1 = ((List) v).iterator(), i2 = ma.iterator(); 346.94 - i1.hasNext();) 346.95 - { 346.96 - if(!Util.equiv(i1.next(), i2.next())) 346.97 - return false; 346.98 - } 346.99 - return true; 346.100 - } 346.101 -// if(obj instanceof IPersistentVector) 346.102 -// { 346.103 -// IPersistentVector ma = (IPersistentVector) obj; 346.104 -// if(ma.count() != v.count() || ma.hashCode() != v.hashCode()) 346.105 -// return false; 346.106 -// for(int i = 0; i < v.count(); i++) 346.107 -// { 346.108 -// if(!Util.equal(v.nth(i), ma.nth(i))) 346.109 -// return false; 346.110 -// } 346.111 -// } 346.112 - else 346.113 - { 346.114 - if(!(obj instanceof Sequential)) 346.115 - return false; 346.116 - ISeq ms = RT.seq(obj); 346.117 - for(int i = 0; i < v.count(); i++, ms = ms.next()) 346.118 - { 346.119 - if(ms == null || !Util.equiv(v.nth(i), ms.first())) 346.120 - return false; 346.121 - } 346.122 - if(ms != null) 346.123 - return false; 346.124 - } 346.125 - 346.126 - return true; 346.127 - 346.128 -} 346.129 - 346.130 -public boolean equals(Object obj){ 346.131 - return doEquals(this, obj); 346.132 -} 346.133 - 346.134 -public boolean equiv(Object obj){ 346.135 - return doEquiv(this, obj); 346.136 -} 346.137 - 346.138 -public int hashCode(){ 346.139 - if(_hash == -1) 346.140 - { 346.141 - int hash = 1; 346.142 - Iterator i = iterator(); 346.143 - while(i.hasNext()) 346.144 - { 346.145 - Object obj = i.next(); 346.146 - hash = 31 * hash + (obj == null ? 0 : obj.hashCode()); 346.147 - } 346.148 -// int hash = 0; 346.149 -// for(int i = 0; i < count(); i++) 346.150 -// { 346.151 -// hash = Util.hashCombine(hash, Util.hash(nth(i))); 346.152 -// } 346.153 - this._hash = hash; 346.154 - } 346.155 - return _hash; 346.156 -} 346.157 - 346.158 -public Object get(int index){ 346.159 - return nth(index); 346.160 -} 346.161 - 346.162 -public Object nth(int i, Object notFound){ 346.163 - if(i >= 0 && i < count()) 346.164 - return nth(i); 346.165 - return notFound; 346.166 -} 346.167 - 346.168 -public Object remove(int i){ 346.169 - throw new UnsupportedOperationException(); 346.170 -} 346.171 - 346.172 -public int indexOf(Object o){ 346.173 - for(int i = 0; i < count(); i++) 346.174 - if(Util.equiv(nth(i), o)) 346.175 - return i; 346.176 - return -1; 346.177 -} 346.178 - 346.179 -public int lastIndexOf(Object o){ 346.180 - for(int i = count() - 1; i >= 0; i--) 346.181 - if(Util.equiv(nth(i), o)) 346.182 - return i; 346.183 - return -1; 346.184 -} 346.185 - 346.186 -public ListIterator listIterator(){ 346.187 - return listIterator(0); 346.188 -} 346.189 - 346.190 -public ListIterator listIterator(final int index){ 346.191 - return new ListIterator(){ 346.192 - int nexti = index; 346.193 - 346.194 - public boolean hasNext(){ 346.195 - return nexti < count(); 346.196 - } 346.197 - 346.198 - public Object next(){ 346.199 - return nth(nexti++); 346.200 - } 346.201 - 346.202 - public boolean hasPrevious(){ 346.203 - return nexti > 0; 346.204 - } 346.205 - 346.206 - public Object previous(){ 346.207 - return nth(--nexti); 346.208 - } 346.209 - 346.210 - public int nextIndex(){ 346.211 - return nexti; 346.212 - } 346.213 - 346.214 - public int previousIndex(){ 346.215 - return nexti - 1; 346.216 - } 346.217 - 346.218 - public void remove(){ 346.219 - throw new UnsupportedOperationException(); 346.220 - } 346.221 - 346.222 - public void set(Object o){ 346.223 - throw new UnsupportedOperationException(); 346.224 - } 346.225 - 346.226 - public void add(Object o){ 346.227 - throw new UnsupportedOperationException(); 346.228 - } 346.229 - }; 346.230 -} 346.231 - 346.232 -public List subList(int fromIndex, int toIndex){ 346.233 - return (List) RT.subvec(this, fromIndex, toIndex); 346.234 -} 346.235 - 346.236 - 346.237 -public Object set(int i, Object o){ 346.238 - throw new UnsupportedOperationException(); 346.239 -} 346.240 - 346.241 -public void add(int i, Object o){ 346.242 - throw new UnsupportedOperationException(); 346.243 -} 346.244 - 346.245 -public boolean addAll(int i, Collection c){ 346.246 - throw new UnsupportedOperationException(); 346.247 -} 346.248 - 346.249 - 346.250 -public Object invoke(Object arg1) throws Exception{ 346.251 - if(Util.isInteger(arg1)) 346.252 - return nth(((Number) arg1).intValue()); 346.253 - throw new IllegalArgumentException("Key must be integer"); 346.254 -} 346.255 - 346.256 -public Iterator iterator(){ 346.257 - //todo - something more efficient 346.258 - return new Iterator(){ 346.259 - int i = 0; 346.260 - 346.261 - public boolean hasNext(){ 346.262 - return i < count(); 346.263 - } 346.264 - 346.265 - public Object next(){ 346.266 - return nth(i++); 346.267 - } 346.268 - 346.269 - public void remove(){ 346.270 - throw new UnsupportedOperationException(); 346.271 - } 346.272 - }; 346.273 -} 346.274 - 346.275 -public Object peek(){ 346.276 - if(count() > 0) 346.277 - return nth(count() - 1); 346.278 - return null; 346.279 -} 346.280 - 346.281 -public boolean containsKey(Object key){ 346.282 - if(!(Util.isInteger(key))) 346.283 - return false; 346.284 - int i = ((Number) key).intValue(); 346.285 - return i >= 0 && i < count(); 346.286 -} 346.287 - 346.288 -public IMapEntry entryAt(Object key){ 346.289 - if(Util.isInteger(key)) 346.290 - { 346.291 - int i = ((Number) key).intValue(); 346.292 - if(i >= 0 && i < count()) 346.293 - return new MapEntry(key, nth(i)); 346.294 - } 346.295 - return null; 346.296 -} 346.297 - 346.298 -public IPersistentVector assoc(Object key, Object val){ 346.299 - if(Util.isInteger(key)) 346.300 - { 346.301 - int i = ((Number) key).intValue(); 346.302 - return assocN(i, val); 346.303 - } 346.304 - throw new IllegalArgumentException("Key must be integer"); 346.305 -} 346.306 - 346.307 -public Object valAt(Object key, Object notFound){ 346.308 - if(Util.isInteger(key)) 346.309 - { 346.310 - int i = ((Number) key).intValue(); 346.311 - if(i >= 0 && i < count()) 346.312 - return nth(i); 346.313 - } 346.314 - return notFound; 346.315 -} 346.316 - 346.317 -public Object valAt(Object key){ 346.318 - return valAt(key, null); 346.319 -} 346.320 - 346.321 -// java.util.Collection implementation 346.322 - 346.323 -public Object[] toArray(){ 346.324 - return RT.seqToArray(seq()); 346.325 -} 346.326 - 346.327 -public boolean add(Object o){ 346.328 - throw new UnsupportedOperationException(); 346.329 -} 346.330 - 346.331 -public boolean remove(Object o){ 346.332 - throw new UnsupportedOperationException(); 346.333 -} 346.334 - 346.335 -public boolean addAll(Collection c){ 346.336 - throw new UnsupportedOperationException(); 346.337 -} 346.338 - 346.339 -public void clear(){ 346.340 - throw new UnsupportedOperationException(); 346.341 -} 346.342 - 346.343 -public boolean retainAll(Collection c){ 346.344 - throw new UnsupportedOperationException(); 346.345 -} 346.346 - 346.347 -public boolean removeAll(Collection c){ 346.348 - throw new UnsupportedOperationException(); 346.349 -} 346.350 - 346.351 -public boolean containsAll(Collection c){ 346.352 - for(Object o : c) 346.353 - { 346.354 - if(!contains(o)) 346.355 - return false; 346.356 - } 346.357 - return true; 346.358 -} 346.359 - 346.360 -public Object[] toArray(Object[] a){ 346.361 - if(a.length >= count()) 346.362 - { 346.363 - ISeq s = seq(); 346.364 - for(int i = 0; s != null; ++i, s = s.next()) 346.365 - { 346.366 - a[i] = s.first(); 346.367 - } 346.368 - if(a.length > count()) 346.369 - a[count()] = null; 346.370 - return a; 346.371 - } 346.372 - else 346.373 - return toArray(); 346.374 -} 346.375 - 346.376 -public int size(){ 346.377 - return count(); 346.378 -} 346.379 - 346.380 -public boolean isEmpty(){ 346.381 - return count() == 0; 346.382 -} 346.383 - 346.384 -public boolean contains(Object o){ 346.385 - for(ISeq s = seq(); s != null; s = s.next()) 346.386 - { 346.387 - if(Util.equiv(s.first(), o)) 346.388 - return true; 346.389 - } 346.390 - return false; 346.391 -} 346.392 - 346.393 -public int length(){ 346.394 - return count(); 346.395 -} 346.396 - 346.397 -public int compareTo(Object o){ 346.398 - IPersistentVector v = (IPersistentVector) o; 346.399 - if(count() < v.count()) 346.400 - return -1; 346.401 - else if(count() > v.count()) 346.402 - return 1; 346.403 - for(int i = 0; i < count(); i++) 346.404 - { 346.405 - int c = Util.compare(nth(i),v.nth(i)); 346.406 - if(c != 0) 346.407 - return c; 346.408 - } 346.409 - return 0; 346.410 -} 346.411 - 346.412 - static class Seq extends ASeq implements IndexedSeq, IReduce{ 346.413 - //todo - something more efficient 346.414 - final IPersistentVector v; 346.415 - final int i; 346.416 - 346.417 - 346.418 - public Seq(IPersistentVector v, int i){ 346.419 - this.v = v; 346.420 - this.i = i; 346.421 - } 346.422 - 346.423 - Seq(IPersistentMap meta, IPersistentVector v, int i){ 346.424 - super(meta); 346.425 - this.v = v; 346.426 - this.i = i; 346.427 - } 346.428 - 346.429 - public Object first(){ 346.430 - return v.nth(i); 346.431 - } 346.432 - 346.433 - public ISeq next(){ 346.434 - if(i + 1 < v.count()) 346.435 - return new APersistentVector.Seq(v, i + 1); 346.436 - return null; 346.437 - } 346.438 - 346.439 - public int index(){ 346.440 - return i; 346.441 - } 346.442 - 346.443 - public int count(){ 346.444 - return v.count() - i; 346.445 - } 346.446 - 346.447 - public APersistentVector.Seq withMeta(IPersistentMap meta){ 346.448 - return new APersistentVector.Seq(meta, v, i); 346.449 - } 346.450 - 346.451 - public Object reduce(IFn f) throws Exception{ 346.452 - Object ret = v.nth(i); 346.453 - for(int x = i + 1; x < v.count(); x++) 346.454 - ret = f.invoke(ret, v.nth(x)); 346.455 - return ret; 346.456 - } 346.457 - 346.458 - public Object reduce(IFn f, Object start) throws Exception{ 346.459 - Object ret = f.invoke(start, v.nth(i)); 346.460 - for(int x = i + 1; x < v.count(); x++) 346.461 - ret = f.invoke(ret, v.nth(x)); 346.462 - return ret; 346.463 - } 346.464 - } 346.465 - 346.466 -public static class RSeq extends ASeq implements IndexedSeq, Counted{ 346.467 - final IPersistentVector v; 346.468 - final int i; 346.469 - 346.470 - public RSeq(IPersistentVector vector, int i){ 346.471 - this.v = vector; 346.472 - this.i = i; 346.473 - } 346.474 - 346.475 - RSeq(IPersistentMap meta, IPersistentVector v, int i){ 346.476 - super(meta); 346.477 - this.v = v; 346.478 - this.i = i; 346.479 - } 346.480 - 346.481 - public Object first(){ 346.482 - return v.nth(i); 346.483 - } 346.484 - 346.485 - public ISeq next(){ 346.486 - if(i > 0) 346.487 - return new APersistentVector.RSeq(v, i - 1); 346.488 - return null; 346.489 - } 346.490 - 346.491 - public int index(){ 346.492 - return i; 346.493 - } 346.494 - 346.495 - public int count(){ 346.496 - return i + 1; 346.497 - } 346.498 - 346.499 - public APersistentVector.RSeq withMeta(IPersistentMap meta){ 346.500 - return new APersistentVector.RSeq(meta, v, i); 346.501 - } 346.502 -} 346.503 - 346.504 -static class SubVector extends APersistentVector implements IObj{ 346.505 - final IPersistentVector v; 346.506 - final int start; 346.507 - final int end; 346.508 - final IPersistentMap _meta; 346.509 - 346.510 - 346.511 - 346.512 - public SubVector(IPersistentMap meta, IPersistentVector v, int start, int end){ 346.513 - this._meta = meta; 346.514 - 346.515 - if(v instanceof APersistentVector.SubVector) 346.516 - { 346.517 - APersistentVector.SubVector sv = (APersistentVector.SubVector) v; 346.518 - start += sv.start; 346.519 - end += sv.start; 346.520 - v = sv.v; 346.521 - } 346.522 - this.v = v; 346.523 - this.start = start; 346.524 - this.end = end; 346.525 - } 346.526 - 346.527 - public Object nth(int i){ 346.528 - if(start + i >= end) 346.529 - throw new IndexOutOfBoundsException(); 346.530 - return v.nth(start + i); 346.531 - } 346.532 - 346.533 - public IPersistentVector assocN(int i, Object val){ 346.534 - if(start + i > end) 346.535 - throw new IndexOutOfBoundsException(); 346.536 - else if(start + i == end) 346.537 - return cons(val); 346.538 - return new SubVector(_meta, v.assocN(start + i, val), start, end); 346.539 - } 346.540 - 346.541 - public int count(){ 346.542 - return end - start; 346.543 - } 346.544 - 346.545 - public IPersistentVector cons(Object o){ 346.546 - return new SubVector(_meta, v.assocN(end, o), start, end + 1); 346.547 - } 346.548 - 346.549 - public IPersistentCollection empty(){ 346.550 - return PersistentVector.EMPTY.withMeta(meta()); 346.551 - } 346.552 - 346.553 - public IPersistentStack pop(){ 346.554 - if(end - 1 == start) 346.555 - { 346.556 - return PersistentVector.EMPTY; 346.557 - } 346.558 - return new SubVector(_meta, v, start, end - 1); 346.559 - } 346.560 - 346.561 - public SubVector withMeta(IPersistentMap meta){ 346.562 - if(meta == _meta) 346.563 - return this; 346.564 - return new SubVector(meta, v, start, end); 346.565 - } 346.566 - 346.567 - public IPersistentMap meta(){ 346.568 - return _meta; 346.569 - } 346.570 -} 346.571 -}
347.1 --- a/src/clojure/lang/ARef.java Sat Aug 21 06:25:44 2010 -0400 347.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 347.3 @@ -1,107 +0,0 @@ 347.4 -/** 347.5 - * Copyright (c) Rich Hickey. All rights reserved. 347.6 - * The use and distribution terms for this software are covered by the 347.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 347.8 - * which can be found in the file epl-v10.html at the root of this distribution. 347.9 - * By using this software in any fashion, you are agreeing to be bound by 347.10 - * the terms of this license. 347.11 - * You must not remove this notice, or any other, from this software. 347.12 - **/ 347.13 - 347.14 -/* rich Jan 1, 2009 */ 347.15 - 347.16 -package clojure.lang; 347.17 - 347.18 -import java.util.Map; 347.19 - 347.20 -public abstract class ARef extends AReference implements IRef{ 347.21 -protected volatile IFn validator = null; 347.22 -private volatile IPersistentMap watches = PersistentHashMap.EMPTY; 347.23 - 347.24 -public ARef(){ 347.25 - super(); 347.26 -} 347.27 - 347.28 -public ARef(IPersistentMap meta){ 347.29 - super(meta); 347.30 -} 347.31 - 347.32 -void validate(IFn vf, Object val){ 347.33 - try 347.34 - { 347.35 - if(vf != null && !RT.booleanCast(vf.invoke(val))) 347.36 - throw new IllegalStateException("Invalid reference state"); 347.37 - } 347.38 - catch(RuntimeException re) 347.39 - { 347.40 - throw re; 347.41 - } 347.42 - catch(Exception e) 347.43 - { 347.44 - throw new IllegalStateException("Invalid reference state", e); 347.45 - } 347.46 -} 347.47 - 347.48 -void validate(Object val){ 347.49 - validate(validator, val); 347.50 -} 347.51 - 347.52 -public void setValidator(IFn vf){ 347.53 - try 347.54 - { 347.55 - validate(vf, deref()); 347.56 - } 347.57 - catch(Exception e) 347.58 - { 347.59 - throw new RuntimeException(e); 347.60 - } 347.61 - validator = vf; 347.62 -} 347.63 - 347.64 -public IFn getValidator(){ 347.65 - return validator; 347.66 -} 347.67 - 347.68 -public IPersistentMap getWatches(){ 347.69 - return watches; 347.70 -} 347.71 - 347.72 -synchronized public IRef addWatch(Object key, IFn callback){ 347.73 - watches = watches.assoc(key, callback); 347.74 - return this; 347.75 -} 347.76 - 347.77 -synchronized public IRef removeWatch(Object key){ 347.78 - try 347.79 - { 347.80 - watches = watches.without(key); 347.81 - } 347.82 - catch(Exception e) 347.83 - { 347.84 - throw new RuntimeException(e); 347.85 - } 347.86 - 347.87 - return this; 347.88 -} 347.89 - 347.90 -public void notifyWatches(Object oldval, Object newval){ 347.91 - IPersistentMap ws = watches; 347.92 - if(ws.count() > 0) 347.93 - { 347.94 - for(ISeq s = ws.seq(); s != null; s = s.next()) 347.95 - { 347.96 - Map.Entry e = (Map.Entry) s.first(); 347.97 - IFn fn = (IFn) e.getValue(); 347.98 - try 347.99 - { 347.100 - if(fn != null) 347.101 - fn.invoke(e.getKey(), this, oldval, newval); 347.102 - } 347.103 - catch(Exception e1) 347.104 - { 347.105 - throw new RuntimeException(e1); 347.106 - } 347.107 - } 347.108 - } 347.109 -} 347.110 -}
348.1 --- a/src/clojure/lang/AReference.java Sat Aug 21 06:25:44 2010 -0400 348.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 348.3 @@ -1,40 +0,0 @@ 348.4 -/** 348.5 - * Copyright (c) Rich Hickey. All rights reserved. 348.6 - * The use and distribution terms for this software are covered by the 348.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 348.8 - * which can be found in the file epl-v10.html at the root of this distribution. 348.9 - * By using this software in any fashion, you are agreeing to be bound by 348.10 - * the terms of this license. 348.11 - * You must not remove this notice, or any other, from this software. 348.12 - **/ 348.13 - 348.14 -/* rich Dec 31, 2008 */ 348.15 - 348.16 -package clojure.lang; 348.17 - 348.18 -public class AReference implements IReference { 348.19 - private IPersistentMap _meta; 348.20 - 348.21 - public AReference() { 348.22 - this(null); 348.23 - } 348.24 - 348.25 - public AReference(IPersistentMap meta) { 348.26 - _meta = meta; 348.27 - } 348.28 - 348.29 - synchronized public IPersistentMap meta() { 348.30 - return _meta; 348.31 - } 348.32 - 348.33 - synchronized public IPersistentMap alterMeta(IFn alter, ISeq args) throws Exception { 348.34 - _meta = (IPersistentMap) alter.applyTo(new Cons(_meta, args)); 348.35 - return _meta; 348.36 - } 348.37 - 348.38 - synchronized public IPersistentMap resetMeta(IPersistentMap m) { 348.39 - _meta = m; 348.40 - return m; 348.41 - } 348.42 - 348.43 -}
349.1 --- a/src/clojure/lang/ASeq.java Sat Aug 21 06:25:44 2010 -0400 349.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 349.3 @@ -1,259 +0,0 @@ 349.4 -/** 349.5 - * Copyright (c) Rich Hickey. All rights reserved. 349.6 - * The use and distribution terms for this software are covered by the 349.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 349.8 - * which can be found in the file epl-v10.html at the root of this distribution. 349.9 - * By using this software in any fashion, you are agreeing to be bound by 349.10 - * the terms of this license. 349.11 - * You must not remove this notice, or any other, from this software. 349.12 - **/ 349.13 - 349.14 -package clojure.lang; 349.15 - 349.16 -import java.io.Serializable; 349.17 -import java.util.*; 349.18 - 349.19 -public abstract class ASeq extends Obj implements ISeq, List, Serializable { 349.20 -transient int _hash = -1; 349.21 - 349.22 -public String toString(){ 349.23 - return RT.printString(this); 349.24 -} 349.25 - 349.26 -public IPersistentCollection empty(){ 349.27 - return PersistentList.EMPTY; 349.28 -} 349.29 - 349.30 -protected ASeq(IPersistentMap meta){ 349.31 - super(meta); 349.32 -} 349.33 - 349.34 - 349.35 -protected ASeq(){ 349.36 -} 349.37 - 349.38 -public boolean equiv(Object obj){ 349.39 - 349.40 - if(!(obj instanceof Sequential || obj instanceof List)) 349.41 - return false; 349.42 - ISeq ms = RT.seq(obj); 349.43 - for(ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) 349.44 - { 349.45 - if(ms == null || !Util.equiv(s.first(), ms.first())) 349.46 - return false; 349.47 - } 349.48 - return ms == null; 349.49 - 349.50 -} 349.51 - 349.52 -public boolean equals(Object obj){ 349.53 - if(this == obj) return true; 349.54 - if(!(obj instanceof Sequential || obj instanceof List)) 349.55 - return false; 349.56 - ISeq ms = RT.seq(obj); 349.57 - for(ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) 349.58 - { 349.59 - if(ms == null || !Util.equals(s.first(), ms.first())) 349.60 - return false; 349.61 - } 349.62 - return ms == null; 349.63 - 349.64 -} 349.65 - 349.66 -public int hashCode(){ 349.67 - if(_hash == -1) 349.68 - { 349.69 - int hash = 1; 349.70 - for(ISeq s = seq(); s != null; s = s.next()) 349.71 - { 349.72 - hash = 31 * hash + (s.first() == null ? 0 : s.first().hashCode()); 349.73 - } 349.74 - this._hash = hash; 349.75 - } 349.76 - return _hash; 349.77 -} 349.78 - 349.79 - 349.80 -//public Object reduce(IFn f) throws Exception{ 349.81 -// Object ret = first(); 349.82 -// for(ISeq s = rest(); s != null; s = s.rest()) 349.83 -// ret = f.invoke(ret, s.first()); 349.84 -// return ret; 349.85 -//} 349.86 -// 349.87 -//public Object reduce(IFn f, Object start) throws Exception{ 349.88 -// Object ret = f.invoke(start, first()); 349.89 -// for(ISeq s = rest(); s != null; s = s.rest()) 349.90 -// ret = f.invoke(ret, s.first()); 349.91 -// return ret; 349.92 -//} 349.93 - 349.94 -//public Object peek(){ 349.95 -// return first(); 349.96 -//} 349.97 -// 349.98 -//public IPersistentList pop(){ 349.99 -// return rest(); 349.100 -//} 349.101 - 349.102 -public int count(){ 349.103 - int i = 1; 349.104 - for(ISeq s = next(); s != null; s = s.next(), i++) 349.105 - if(s instanceof Counted) 349.106 - return i + s.count(); 349.107 - return i; 349.108 -} 349.109 - 349.110 -final public ISeq seq(){ 349.111 - return this; 349.112 -} 349.113 - 349.114 -public ISeq cons(Object o){ 349.115 - return new Cons(o, this); 349.116 -} 349.117 - 349.118 -public ISeq more(){ 349.119 - ISeq s = next(); 349.120 - if(s == null) 349.121 - return PersistentList.EMPTY; 349.122 - return s; 349.123 -} 349.124 - 349.125 -//final public ISeq rest(){ 349.126 -// Seqable m = more(); 349.127 -// if(m == null) 349.128 -// return null; 349.129 -// return m.seq(); 349.130 -//} 349.131 - 349.132 -// java.util.Collection implementation 349.133 - 349.134 -public Object[] toArray(){ 349.135 - return RT.seqToArray(seq()); 349.136 -} 349.137 - 349.138 -public boolean add(Object o){ 349.139 - throw new UnsupportedOperationException(); 349.140 -} 349.141 - 349.142 -public boolean remove(Object o){ 349.143 - throw new UnsupportedOperationException(); 349.144 -} 349.145 - 349.146 -public boolean addAll(Collection c){ 349.147 - throw new UnsupportedOperationException(); 349.148 -} 349.149 - 349.150 -public void clear(){ 349.151 - throw new UnsupportedOperationException(); 349.152 -} 349.153 - 349.154 -public boolean retainAll(Collection c){ 349.155 - throw new UnsupportedOperationException(); 349.156 -} 349.157 - 349.158 -public boolean removeAll(Collection c){ 349.159 - throw new UnsupportedOperationException(); 349.160 -} 349.161 - 349.162 -public boolean containsAll(Collection c){ 349.163 - for(Object o : c) 349.164 - { 349.165 - if(!contains(o)) 349.166 - return false; 349.167 - } 349.168 - return true; 349.169 -} 349.170 - 349.171 -public Object[] toArray(Object[] a){ 349.172 - if(a.length >= count()) 349.173 - { 349.174 - ISeq s = seq(); 349.175 - for(int i = 0; s != null; ++i, s = s.next()) 349.176 - { 349.177 - a[i] = s.first(); 349.178 - } 349.179 - if(a.length > count()) 349.180 - a[count()] = null; 349.181 - return a; 349.182 - } 349.183 - else 349.184 - return toArray(); 349.185 -} 349.186 - 349.187 -public int size(){ 349.188 - return count(); 349.189 -} 349.190 - 349.191 -public boolean isEmpty(){ 349.192 - return seq() == null; 349.193 -} 349.194 - 349.195 -public boolean contains(Object o){ 349.196 - for(ISeq s = seq(); s != null; s = s.next()) 349.197 - { 349.198 - if(Util.equiv(s.first(), o)) 349.199 - return true; 349.200 - } 349.201 - return false; 349.202 -} 349.203 - 349.204 - 349.205 -public Iterator iterator(){ 349.206 - return new SeqIterator(this); 349.207 -} 349.208 - 349.209 - 349.210 - 349.211 -//////////// List stuff ///////////////// 349.212 -private List reify(){ 349.213 - return Collections.unmodifiableList(new ArrayList(this)); 349.214 -} 349.215 - 349.216 -public List subList(int fromIndex, int toIndex){ 349.217 - return reify().subList(fromIndex, toIndex); 349.218 -} 349.219 - 349.220 -public Object set(int index, Object element){ 349.221 - throw new UnsupportedOperationException(); 349.222 -} 349.223 - 349.224 -public Object remove(int index){ 349.225 - throw new UnsupportedOperationException(); 349.226 -} 349.227 - 349.228 -public int indexOf(Object o){ 349.229 - ISeq s = seq(); 349.230 - for(int i = 0; s != null; s = s.next(), i++) 349.231 - { 349.232 - if(Util.equiv(s.first(), o)) 349.233 - return i; 349.234 - } 349.235 - return -1; 349.236 -} 349.237 - 349.238 -public int lastIndexOf(Object o){ 349.239 - return reify().lastIndexOf(o); 349.240 -} 349.241 - 349.242 -public ListIterator listIterator(){ 349.243 - return reify().listIterator(); 349.244 -} 349.245 - 349.246 -public ListIterator listIterator(int index){ 349.247 - return reify().listIterator(index); 349.248 -} 349.249 - 349.250 -public Object get(int index){ 349.251 - return RT.nth(this, index); 349.252 -} 349.253 - 349.254 -public void add(int index, Object element){ 349.255 - throw new UnsupportedOperationException(); 349.256 -} 349.257 - 349.258 -public boolean addAll(int index, Collection c){ 349.259 - throw new UnsupportedOperationException(); 349.260 -} 349.261 - 349.262 -}
350.1 --- a/src/clojure/lang/ATransientMap.java Sat Aug 21 06:25:44 2010 -0400 350.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 350.3 @@ -1,86 +0,0 @@ 350.4 -/** 350.5 - * Copyright (c) Rich Hickey. All rights reserved. 350.6 - * The use and distribution terms for this software are covered by the 350.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 350.8 - * which can be found in the file epl-v10.html at the root of this distribution. 350.9 - * By using this software in any fashion, you are agreeing to be bound by 350.10 - * the terms of this license. 350.11 - * You must not remove this notice, or any other, from this software. 350.12 - **/ 350.13 - 350.14 -package clojure.lang; 350.15 - 350.16 -import java.util.Map; 350.17 - 350.18 -import clojure.lang.PersistentHashMap.INode; 350.19 - 350.20 -abstract class ATransientMap extends AFn implements ITransientMap { 350.21 - abstract void ensureEditable(); 350.22 - abstract ITransientMap doAssoc(Object key, Object val); 350.23 - abstract ITransientMap doWithout(Object key); 350.24 - abstract Object doValAt(Object key, Object notFound); 350.25 - abstract int doCount(); 350.26 - abstract IPersistentMap doPersistent(); 350.27 - 350.28 - public ITransientMap conj(Object o) { 350.29 - ensureEditable(); 350.30 - if(o instanceof Map.Entry) 350.31 - { 350.32 - Map.Entry e = (Map.Entry) o; 350.33 - 350.34 - return assoc(e.getKey(), e.getValue()); 350.35 - } 350.36 - else if(o instanceof IPersistentVector) 350.37 - { 350.38 - IPersistentVector v = (IPersistentVector) o; 350.39 - if(v.count() != 2) 350.40 - throw new IllegalArgumentException("Vector arg to map conj must be a pair"); 350.41 - return assoc(v.nth(0), v.nth(1)); 350.42 - } 350.43 - 350.44 - ITransientMap ret = this; 350.45 - for(ISeq es = RT.seq(o); es != null; es = es.next()) 350.46 - { 350.47 - Map.Entry e = (Map.Entry) es.first(); 350.48 - ret = ret.assoc(e.getKey(), e.getValue()); 350.49 - } 350.50 - return ret; 350.51 - } 350.52 - 350.53 - public final Object invoke(Object arg1) throws Exception{ 350.54 - return valAt(arg1); 350.55 - } 350.56 - 350.57 - public final Object invoke(Object arg1, Object notFound) throws Exception{ 350.58 - return valAt(arg1, notFound); 350.59 - } 350.60 - 350.61 - public final Object valAt(Object key) { 350.62 - return valAt(key, null); 350.63 - } 350.64 - 350.65 - public final ITransientMap assoc(Object key, Object val) { 350.66 - ensureEditable(); 350.67 - return doAssoc(key, val); 350.68 - } 350.69 - 350.70 - public final ITransientMap without(Object key) { 350.71 - ensureEditable(); 350.72 - return doWithout(key); 350.73 - } 350.74 - 350.75 - public final IPersistentMap persistent() { 350.76 - ensureEditable(); 350.77 - return doPersistent(); 350.78 - } 350.79 - 350.80 - public final Object valAt(Object key, Object notFound) { 350.81 - ensureEditable(); 350.82 - return doValAt(key, notFound); 350.83 - } 350.84 - 350.85 - public final int count() { 350.86 - ensureEditable(); 350.87 - return doCount(); 350.88 - } 350.89 -}
351.1 --- a/src/clojure/lang/ATransientSet.java Sat Aug 21 06:25:44 2010 -0400 351.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 351.3 @@ -1,54 +0,0 @@ 351.4 -/** 351.5 - * Copyright (c) Rich Hickey. All rights reserved. 351.6 - * The use and distribution terms for this software are covered by the 351.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 351.8 - * which can be found in the file epl-v10.html at the root of this distribution. 351.9 - * By using this software in any fashion, you are agreeing to be bound by 351.10 - * the terms of this license. 351.11 - * You must not remove this notice, or any other, from this software. 351.12 - **/ 351.13 - 351.14 -/* rich Mar 3, 2008 */ 351.15 - 351.16 -package clojure.lang; 351.17 - 351.18 -public abstract class ATransientSet extends AFn implements ITransientSet{ 351.19 - ITransientMap impl; 351.20 - 351.21 - ATransientSet(ITransientMap impl) { 351.22 - this.impl = impl; 351.23 - } 351.24 - 351.25 - public int count() { 351.26 - return impl.count(); 351.27 - } 351.28 - 351.29 - public ITransientSet conj(Object val) { 351.30 - ITransientMap m = impl.assoc(val, val); 351.31 - if (m != impl) this.impl = m; 351.32 - return this; 351.33 - } 351.34 - 351.35 - public boolean contains(Object key) { 351.36 - return this != impl.valAt(key, this); 351.37 - } 351.38 - 351.39 - public ITransientSet disjoin(Object key) throws Exception { 351.40 - ITransientMap m = impl.without(key); 351.41 - if (m != impl) this.impl = m; 351.42 - return this; 351.43 - } 351.44 - 351.45 - public Object get(Object key) { 351.46 - return impl.valAt(key); 351.47 - } 351.48 - 351.49 - public Object invoke(Object key, Object notFound) throws Exception { 351.50 - return impl.valAt(key, notFound); 351.51 - } 351.52 - 351.53 - public Object invoke(Object key) throws Exception { 351.54 - return impl.valAt(key); 351.55 - } 351.56 - 351.57 -}
352.1 --- a/src/clojure/lang/Agent.java Sat Aug 21 06:25:44 2010 -0400 352.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 352.3 @@ -1,274 +0,0 @@ 352.4 -/** 352.5 - * Copyright (c) Rich Hickey. All rights reserved. 352.6 - * The use and distribution terms for this software are covered by the 352.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 352.8 - * which can be found in the file epl-v10.html at the root of this distribution. 352.9 - * By using this software in any fashion, you are agreeing to be bound by 352.10 - * the terms of this license. 352.11 - * You must not remove this notice, or any other, from this software. 352.12 - **/ 352.13 - 352.14 -/* rich Nov 17, 2007 */ 352.15 - 352.16 -package clojure.lang; 352.17 - 352.18 -import java.util.concurrent.*; 352.19 -import java.util.concurrent.atomic.AtomicReference; 352.20 -import java.util.Map; 352.21 - 352.22 -public class Agent extends ARef { 352.23 - 352.24 -static class ActionQueue { 352.25 - public final IPersistentStack q; 352.26 - public final Throwable error; // non-null indicates fail state 352.27 - static final ActionQueue EMPTY = new ActionQueue(PersistentQueue.EMPTY, null); 352.28 - 352.29 - public ActionQueue( IPersistentStack q, Throwable error ) 352.30 - { 352.31 - this.q = q; 352.32 - this.error = error; 352.33 - } 352.34 -} 352.35 - 352.36 -static final Keyword CONTINUE = Keyword.intern(null, "continue"); 352.37 -static final Keyword FAIL = Keyword.intern(null, "fail"); 352.38 - 352.39 -volatile Object state; 352.40 - AtomicReference<ActionQueue> aq = new AtomicReference(ActionQueue.EMPTY); 352.41 - 352.42 - volatile Keyword errorMode = CONTINUE; 352.43 - volatile IFn errorHandler = null; 352.44 - 352.45 -final public static ExecutorService pooledExecutor = 352.46 - Executors.newFixedThreadPool(2 + Runtime.getRuntime().availableProcessors()); 352.47 - 352.48 -final public static ExecutorService soloExecutor = Executors.newCachedThreadPool(); 352.49 - 352.50 -final static ThreadLocal<IPersistentVector> nested = new ThreadLocal<IPersistentVector>(); 352.51 - 352.52 - 352.53 -public static void shutdown(){ 352.54 - soloExecutor.shutdown(); 352.55 - pooledExecutor.shutdown(); 352.56 -} 352.57 - 352.58 -static class Action implements Runnable{ 352.59 - final Agent agent; 352.60 - final IFn fn; 352.61 - final ISeq args; 352.62 - final boolean solo; 352.63 - 352.64 - 352.65 - public Action(Agent agent, IFn fn, ISeq args, boolean solo){ 352.66 - this.agent = agent; 352.67 - this.args = args; 352.68 - this.fn = fn; 352.69 - this.solo = solo; 352.70 - } 352.71 - 352.72 - void execute(){ 352.73 - try 352.74 - { 352.75 - if(solo) 352.76 - soloExecutor.execute(this); 352.77 - else 352.78 - pooledExecutor.execute(this); 352.79 - } 352.80 - catch(Throwable error) 352.81 - { 352.82 - if(agent.errorHandler != null) 352.83 - { 352.84 - try 352.85 - { 352.86 - agent.errorHandler.invoke(agent, error); 352.87 - } 352.88 - catch(Throwable e) {} // ignore errorHandler errors 352.89 - } 352.90 - } 352.91 - } 352.92 - 352.93 - static void doRun(Action action){ 352.94 - try 352.95 - { 352.96 - Var.pushThreadBindings(RT.map(RT.AGENT, action.agent)); 352.97 - nested.set(PersistentVector.EMPTY); 352.98 - 352.99 - Throwable error = null; 352.100 - try 352.101 - { 352.102 - Object oldval = action.agent.state; 352.103 - Object newval = action.fn.applyTo(RT.cons(action.agent.state, action.args)); 352.104 - action.agent.setState(newval); 352.105 - action.agent.notifyWatches(oldval,newval); 352.106 - } 352.107 - catch(Throwable e) 352.108 - { 352.109 - error = e; 352.110 - } 352.111 - 352.112 - if(error == null) 352.113 - { 352.114 - releasePendingSends(); 352.115 - } 352.116 - else 352.117 - { 352.118 - nested.set(PersistentVector.EMPTY); 352.119 - if(action.agent.errorHandler != null) 352.120 - { 352.121 - try 352.122 - { 352.123 - action.agent.errorHandler.invoke(action.agent, error); 352.124 - } 352.125 - catch(Throwable e) {} // ignore errorHandler errors 352.126 - } 352.127 - if(action.agent.errorMode == CONTINUE) 352.128 - { 352.129 - error = null; 352.130 - } 352.131 - } 352.132 - 352.133 - boolean popped = false; 352.134 - ActionQueue next = null; 352.135 - while(!popped) 352.136 - { 352.137 - ActionQueue prior = action.agent.aq.get(); 352.138 - next = new ActionQueue(prior.q.pop(), error); 352.139 - popped = action.agent.aq.compareAndSet(prior, next); 352.140 - } 352.141 - 352.142 - if(error == null && next.q.count() > 0) 352.143 - ((Action) next.q.peek()).execute(); 352.144 - } 352.145 - finally 352.146 - { 352.147 - nested.set(null); 352.148 - Var.popThreadBindings(); 352.149 - } 352.150 - } 352.151 - 352.152 - public void run(){ 352.153 - doRun(this); 352.154 - } 352.155 -} 352.156 - 352.157 -public Agent(Object state) throws Exception{ 352.158 - this(state,null); 352.159 -} 352.160 - 352.161 -public Agent(Object state, IPersistentMap meta) throws Exception { 352.162 - super(meta); 352.163 - setState(state); 352.164 -} 352.165 - 352.166 -boolean setState(Object newState) throws Exception{ 352.167 - validate(newState); 352.168 - boolean ret = state != newState; 352.169 - state = newState; 352.170 - return ret; 352.171 -} 352.172 - 352.173 -public Object deref() throws Exception{ 352.174 - return state; 352.175 -} 352.176 - 352.177 -public Throwable getError(){ 352.178 - return aq.get().error; 352.179 -} 352.180 - 352.181 -public void setErrorMode(Keyword k){ 352.182 - errorMode = k; 352.183 -} 352.184 - 352.185 -public Keyword getErrorMode(){ 352.186 - return errorMode; 352.187 -} 352.188 - 352.189 -public void setErrorHandler(IFn f){ 352.190 - errorHandler = f; 352.191 -} 352.192 - 352.193 -public IFn getErrorHandler(){ 352.194 - return errorHandler; 352.195 -} 352.196 - 352.197 -synchronized public Object restart(Object newState, boolean clearActions){ 352.198 - if(getError() == null) 352.199 - { 352.200 - throw new RuntimeException("Agent does not need a restart"); 352.201 - } 352.202 - validate(newState); 352.203 - state = newState; 352.204 - 352.205 - if(clearActions) 352.206 - aq.set(ActionQueue.EMPTY); 352.207 - else 352.208 - { 352.209 - boolean restarted = false; 352.210 - ActionQueue prior = null; 352.211 - while(!restarted) 352.212 - { 352.213 - prior = aq.get(); 352.214 - restarted = aq.compareAndSet(prior, new ActionQueue(prior.q, null)); 352.215 - } 352.216 - 352.217 - if(prior.q.count() > 0) 352.218 - ((Action) prior.q.peek()).execute(); 352.219 - } 352.220 - 352.221 - return newState; 352.222 -} 352.223 - 352.224 -public Object dispatch(IFn fn, ISeq args, boolean solo) { 352.225 - Throwable error = getError(); 352.226 - if(error != null) 352.227 - { 352.228 - throw new RuntimeException("Agent is failed, needs restart", error); 352.229 - } 352.230 - Action action = new Action(this, fn, args, solo); 352.231 - dispatchAction(action); 352.232 - 352.233 - return this; 352.234 -} 352.235 - 352.236 -static void dispatchAction(Action action){ 352.237 - LockingTransaction trans = LockingTransaction.getRunning(); 352.238 - if(trans != null) 352.239 - trans.enqueue(action); 352.240 - else if(nested.get() != null) 352.241 - { 352.242 - nested.set(nested.get().cons(action)); 352.243 - } 352.244 - else 352.245 - action.agent.enqueue(action); 352.246 -} 352.247 - 352.248 -void enqueue(Action action){ 352.249 - boolean queued = false; 352.250 - ActionQueue prior = null; 352.251 - while(!queued) 352.252 - { 352.253 - prior = aq.get(); 352.254 - queued = aq.compareAndSet(prior, new ActionQueue((IPersistentStack)prior.q.cons(action), prior.error)); 352.255 - } 352.256 - 352.257 - if(prior.q.count() == 0 && prior.error == null) 352.258 - action.execute(); 352.259 -} 352.260 - 352.261 -public int getQueueCount(){ 352.262 - return aq.get().q.count(); 352.263 -} 352.264 - 352.265 -static public int releasePendingSends(){ 352.266 - IPersistentVector sends = nested.get(); 352.267 - if(sends == null) 352.268 - return 0; 352.269 - for(int i=0;i<sends.count();i++) 352.270 - { 352.271 - Action a = (Action) sends.valAt(i); 352.272 - a.agent.enqueue(a); 352.273 - } 352.274 - nested.set(PersistentVector.EMPTY); 352.275 - return sends.count(); 352.276 -} 352.277 -}
353.1 --- a/src/clojure/lang/ArrayChunk.java Sat Aug 21 06:25:44 2010 -0400 353.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 353.3 @@ -1,63 +0,0 @@ 353.4 -/** 353.5 - * Copyright (c) Rich Hickey. All rights reserved. 353.6 - * The use and distribution terms for this software are covered by the 353.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 353.8 - * which can be found in the file epl-v10.html at the root of this distribution. 353.9 - * By using this software in any fashion, you are agreeing to be bound by 353.10 - * the terms of this license. 353.11 - * You must not remove this notice, or any other, from this software. 353.12 - **/ 353.13 - 353.14 -/* rich May 24, 2009 */ 353.15 - 353.16 -package clojure.lang; 353.17 - 353.18 -import java.io.Serializable; 353.19 - 353.20 -public final class ArrayChunk implements IChunk, Serializable { 353.21 - 353.22 -final Object[] array; 353.23 -final int off; 353.24 -final int end; 353.25 - 353.26 -public ArrayChunk(Object[] array){ 353.27 - this(array, 0, array.length); 353.28 -} 353.29 - 353.30 -public ArrayChunk(Object[] array, int off){ 353.31 - this(array, off, array.length); 353.32 -} 353.33 - 353.34 -public ArrayChunk(Object[] array, int off, int end){ 353.35 - this.array = array; 353.36 - this.off = off; 353.37 - this.end = end; 353.38 -} 353.39 - 353.40 -public Object nth(int i){ 353.41 - return array[off + i]; 353.42 -} 353.43 - 353.44 -public Object nth(int i, Object notFound){ 353.45 - if(i >= 0 && i < count()) 353.46 - return nth(i); 353.47 - return notFound; 353.48 -} 353.49 - 353.50 -public int count(){ 353.51 - return end - off; 353.52 -} 353.53 - 353.54 -public IChunk dropFirst(){ 353.55 - if(off==end) 353.56 - throw new IllegalStateException("dropFirst of empty chunk"); 353.57 - return new ArrayChunk(array, off + 1, end); 353.58 -} 353.59 - 353.60 -public Object reduce(IFn f, Object start) throws Exception{ 353.61 - Object ret = f.invoke(start, array[off]); 353.62 - for(int x = off + 1; x < end; x++) 353.63 - ret = f.invoke(ret, array[x]); 353.64 - return ret; 353.65 -} 353.66 -}
354.1 --- a/src/clojure/lang/ArraySeq.java Sat Aug 21 06:25:44 2010 -0400 354.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 354.3 @@ -1,692 +0,0 @@ 354.4 -/** 354.5 - * Copyright (c) Rich Hickey. All rights reserved. 354.6 - * The use and distribution terms for this software are covered by the 354.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 354.8 - * which can be found in the file epl-v10.html at the root of this distribution. 354.9 - * By using this software in any fashion, you are agreeing to be bound by 354.10 - * the terms of this license. 354.11 - * You must not remove this notice, or any other, from this software. 354.12 - **/ 354.13 - 354.14 -/* rich Jun 19, 2006 */ 354.15 - 354.16 -package clojure.lang; 354.17 - 354.18 -import java.lang.reflect.Array; 354.19 - 354.20 -public class ArraySeq extends ASeq implements IndexedSeq, IReduce{ 354.21 -public final Object array; 354.22 -final int i; 354.23 -final Object[] oa; 354.24 -//ISeq _rest; 354.25 - 354.26 -static public ArraySeq create(){ 354.27 - return null; 354.28 -} 354.29 - 354.30 -static public ArraySeq create(Object... array){ 354.31 - if(array == null || array.length == 0) 354.32 - return null; 354.33 - return new ArraySeq(array, 0); 354.34 -} 354.35 - 354.36 -static ISeq createFromObject(Object array){ 354.37 - if(array == null || Array.getLength(array) == 0) 354.38 - return null; 354.39 - Class aclass = array.getClass(); 354.40 - if(aclass == int[].class) 354.41 - return new ArraySeq_int(null, (int[]) array, 0); 354.42 - if(aclass == float[].class) 354.43 - return new ArraySeq_float(null, (float[]) array, 0); 354.44 - if(aclass == double[].class) 354.45 - return new ArraySeq_double(null, (double[]) array, 0); 354.46 - if(aclass == long[].class) 354.47 - return new ArraySeq_long(null, (long[]) array, 0); 354.48 - if(aclass == byte[].class) 354.49 - return new ArraySeq_byte(null, (byte[]) array, 0); 354.50 - if(aclass == char[].class) 354.51 - return new ArraySeq_char(null, (char[]) array, 0); 354.52 - if(aclass == boolean[].class) 354.53 - return new ArraySeq_boolean(null, (boolean[]) array, 0); 354.54 - return new ArraySeq(array, 0); 354.55 -} 354.56 - 354.57 -ArraySeq(Object array, int i){ 354.58 - this.array = array; 354.59 - this.i = i; 354.60 - this.oa = (Object[]) (array instanceof Object[] ? array : null); 354.61 -// this._rest = this; 354.62 -} 354.63 - 354.64 -ArraySeq(IPersistentMap meta, Object array, int i){ 354.65 - super(meta); 354.66 - this.array = array; 354.67 - this.i = i; 354.68 - this.oa = (Object[]) (array instanceof Object[] ? array : null); 354.69 -} 354.70 - 354.71 -public Object first(){ 354.72 - if(oa != null) 354.73 - return oa[i]; 354.74 - return Reflector.prepRet(Array.get(array, i)); 354.75 -} 354.76 - 354.77 -public ISeq next(){ 354.78 - if(oa != null) 354.79 - { 354.80 - if(i + 1 < oa.length) 354.81 - return new ArraySeq(array, i + 1); 354.82 - } 354.83 - else 354.84 - { 354.85 - if(i + 1 < Array.getLength(array)) 354.86 - return new ArraySeq(array, i + 1); 354.87 - } 354.88 - return null; 354.89 -} 354.90 - 354.91 -public int count(){ 354.92 - if(oa != null) 354.93 - return oa.length - i; 354.94 - return Array.getLength(array) - i; 354.95 -} 354.96 - 354.97 -public int index(){ 354.98 - return i; 354.99 -} 354.100 - 354.101 -public ArraySeq withMeta(IPersistentMap meta){ 354.102 - return new ArraySeq(meta, array, i); 354.103 -} 354.104 - 354.105 -public Object reduce(IFn f) throws Exception{ 354.106 - if(oa != null) 354.107 - { 354.108 - Object ret = oa[i]; 354.109 - for(int x = i + 1; x < oa.length; x++) 354.110 - ret = f.invoke(ret, oa[x]); 354.111 - return ret; 354.112 - } 354.113 - 354.114 - Object ret = Reflector.prepRet(Array.get(array, i)); 354.115 - for(int x = i + 1; x < Array.getLength(array); x++) 354.116 - ret = f.invoke(ret, Reflector.prepRet(Array.get(array, x))); 354.117 - return ret; 354.118 -} 354.119 - 354.120 -public Object reduce(IFn f, Object start) throws Exception{ 354.121 - if(oa != null) 354.122 - { 354.123 - Object ret = f.invoke(start, oa[i]); 354.124 - for(int x = i + 1; x < oa.length; x++) 354.125 - ret = f.invoke(ret, oa[x]); 354.126 - return ret; 354.127 - } 354.128 - Object ret = f.invoke(start, Reflector.prepRet(Array.get(array, i))); 354.129 - for(int x = i + 1; x < Array.getLength(array); x++) 354.130 - ret = f.invoke(ret, Reflector.prepRet(Array.get(array, x))); 354.131 - return ret; 354.132 -} 354.133 - 354.134 -public int indexOf(Object o) { 354.135 - if (oa != null) { 354.136 - for (int j = i; j < oa.length; j++) 354.137 - if (Util.equals(o, oa[j])) return j - i; 354.138 - } else { 354.139 - int n = Array.getLength(array); 354.140 - for (int j = i; j < n; j++) 354.141 - if (Util.equals(o, Reflector.prepRet(Array.get(array, j)))) return j - i; 354.142 - } 354.143 - return -1; 354.144 -} 354.145 - 354.146 -public int lastIndexOf(Object o) { 354.147 - if (oa != null) { 354.148 - if (o == null) { 354.149 - for (int j = oa.length - 1 ; j >= i; j--) 354.150 - if (oa[j] == null) return j - i; 354.151 - } else { 354.152 - for (int j = oa.length - 1 ; j >= i; j--) 354.153 - if (o.equals(oa[j])) return j - i; 354.154 - } 354.155 - } else { 354.156 - if (o == null) { 354.157 - for (int j = Array.getLength(array) - 1 ; j >= i; j--) 354.158 - if (Reflector.prepRet(Array.get(array, j)) == null) return j - i; 354.159 - } else { 354.160 - for (int j = Array.getLength(array) - 1 ; j >= i; j--) 354.161 - if (o.equals(Reflector.prepRet(Array.get(array, j)))) return j - i; 354.162 - } 354.163 - } 354.164 - return -1; 354.165 -} 354.166 - 354.167 -//////////////////////////////////// specialized primitive versions /////////////////////////////// 354.168 - 354.169 -static public class ArraySeq_int extends ASeq implements IndexedSeq, IReduce{ 354.170 - public final int[] array; 354.171 - final int i; 354.172 - 354.173 - ArraySeq_int(IPersistentMap meta, int[] array, int i){ 354.174 - super(meta); 354.175 - this.array = array; 354.176 - this.i = i; 354.177 - } 354.178 - 354.179 - public Object first(){ 354.180 - return array[i]; 354.181 - } 354.182 - 354.183 - public ISeq next(){ 354.184 - if(i + 1 < array.length) 354.185 - return new ArraySeq_int(meta(), array, i + 1); 354.186 - return null; 354.187 - } 354.188 - 354.189 - public int count(){ 354.190 - return array.length - i; 354.191 - } 354.192 - 354.193 - public int index(){ 354.194 - return i; 354.195 - } 354.196 - 354.197 - public ArraySeq_int withMeta(IPersistentMap meta){ 354.198 - return new ArraySeq_int(meta, array, i); 354.199 - } 354.200 - 354.201 - public Object reduce(IFn f) throws Exception{ 354.202 - Object ret = array[i]; 354.203 - for(int x = i + 1; x < array.length; x++) 354.204 - ret = f.invoke(ret, array[x]); 354.205 - return ret; 354.206 - } 354.207 - 354.208 - public Object reduce(IFn f, Object start) throws Exception{ 354.209 - Object ret = f.invoke(start, array[i]); 354.210 - for(int x = i + 1; x < array.length; x++) 354.211 - ret = f.invoke(ret, array[x]); 354.212 - return ret; 354.213 - } 354.214 - 354.215 - public int indexOf(Object o) { 354.216 - if (o instanceof Integer) { 354.217 - int k = ((Integer) o).intValue(); 354.218 - for (int j = i; j < array.length; j++) 354.219 - if (k == array[j]) return j - i; 354.220 - } 354.221 - if (o == null) { 354.222 - return -1; 354.223 - } 354.224 - for (int j = i; j < array.length; j++) 354.225 - if (o.equals(array[j])) return j - i; 354.226 - return -1; 354.227 - } 354.228 - 354.229 - public int lastIndexOf(Object o) { 354.230 - if (o instanceof Integer) { 354.231 - int k = ((Integer) o).intValue(); 354.232 - for (int j = array.length - 1; j >= i; j--) 354.233 - if (k == array[j]) return j - i; 354.234 - } 354.235 - if (o == null) { 354.236 - return -1; 354.237 - } 354.238 - for (int j = array.length - 1; j >= i; j--) 354.239 - if (o.equals(array[j])) return j - i; 354.240 - return -1; 354.241 - } 354.242 -} 354.243 - 354.244 - 354.245 -static public class ArraySeq_float extends ASeq implements IndexedSeq, IReduce{ 354.246 - public final float[] array; 354.247 - final int i; 354.248 - 354.249 - ArraySeq_float(IPersistentMap meta, float[] array, int i){ 354.250 - super(meta); 354.251 - this.array = array; 354.252 - this.i = i; 354.253 - } 354.254 - 354.255 - public Object first(){ 354.256 - return array[i]; 354.257 - } 354.258 - 354.259 - public ISeq next(){ 354.260 - if(i + 1 < array.length) 354.261 - return new ArraySeq_float(meta(), array, i + 1); 354.262 - return null; 354.263 - } 354.264 - 354.265 - public int count(){ 354.266 - return array.length - i; 354.267 - } 354.268 - 354.269 - public int index(){ 354.270 - return i; 354.271 - } 354.272 - 354.273 - public ArraySeq_float withMeta(IPersistentMap meta){ 354.274 - return new ArraySeq_float(meta, array, i); 354.275 - } 354.276 - 354.277 - public Object reduce(IFn f) throws Exception{ 354.278 - Object ret = array[i]; 354.279 - for(int x = i + 1; x < array.length; x++) 354.280 - ret = f.invoke(ret, array[x]); 354.281 - return ret; 354.282 - } 354.283 - 354.284 - public Object reduce(IFn f, Object start) throws Exception{ 354.285 - Object ret = f.invoke(start, array[i]); 354.286 - for(int x = i + 1; x < array.length; x++) 354.287 - ret = f.invoke(ret, array[x]); 354.288 - return ret; 354.289 - } 354.290 - 354.291 - public int indexOf(Object o) { 354.292 - if (o instanceof Float) { 354.293 - float f = ((Float) o).floatValue(); 354.294 - for (int j = i; j < array.length; j++) 354.295 - if (f == array[j]) return j - i; 354.296 - } 354.297 - if (o == null) { 354.298 - return -1; 354.299 - } 354.300 - for (int j = i; j < array.length; j++) 354.301 - if (o.equals(array[j])) return j - i; 354.302 - return -1; 354.303 - } 354.304 - 354.305 - public int lastIndexOf(Object o) { 354.306 - if (o instanceof Float) { 354.307 - float f = ((Float) o).floatValue(); 354.308 - for (int j = array.length - 1; j >= i; j--) 354.309 - if (f == array[j]) return j - i; 354.310 - } 354.311 - if (o == null) { 354.312 - return -1; 354.313 - } 354.314 - for (int j = array.length - 1; j >= i; j--) 354.315 - if (o.equals(array[j])) return j - i; 354.316 - return -1; 354.317 - } 354.318 -} 354.319 - 354.320 -static public class ArraySeq_double extends ASeq implements IndexedSeq, IReduce{ 354.321 - public final double[] array; 354.322 - final int i; 354.323 - 354.324 - ArraySeq_double(IPersistentMap meta, double[] array, int i){ 354.325 - super(meta); 354.326 - this.array = array; 354.327 - this.i = i; 354.328 - } 354.329 - 354.330 - public Object first(){ 354.331 - return array[i]; 354.332 - } 354.333 - 354.334 - public ISeq next(){ 354.335 - if(i + 1 < array.length) 354.336 - return new ArraySeq_double(meta(), array, i + 1); 354.337 - return null; 354.338 - } 354.339 - 354.340 - public int count(){ 354.341 - return array.length - i; 354.342 - } 354.343 - 354.344 - public int index(){ 354.345 - return i; 354.346 - } 354.347 - 354.348 - public ArraySeq_double withMeta(IPersistentMap meta){ 354.349 - return new ArraySeq_double(meta, array, i); 354.350 - } 354.351 - 354.352 - public Object reduce(IFn f) throws Exception{ 354.353 - Object ret = array[i]; 354.354 - for(int x = i + 1; x < array.length; x++) 354.355 - ret = f.invoke(ret, array[x]); 354.356 - return ret; 354.357 - } 354.358 - 354.359 - public Object reduce(IFn f, Object start) throws Exception{ 354.360 - Object ret = f.invoke(start, array[i]); 354.361 - for(int x = i + 1; x < array.length; x++) 354.362 - ret = f.invoke(ret, array[x]); 354.363 - return ret; 354.364 - } 354.365 - 354.366 - public int indexOf(Object o) { 354.367 - if (o instanceof Double) { 354.368 - double d = ((Double) o).doubleValue(); 354.369 - for (int j = i; j < array.length; j++) 354.370 - if (d == array[j]) return j - i; 354.371 - } 354.372 - if (o == null) { 354.373 - return -1; 354.374 - } 354.375 - for (int j = i; j < array.length; j++) 354.376 - if (o.equals(array[j])) return j - i; 354.377 - return -1; 354.378 - } 354.379 - 354.380 - public int lastIndexOf(Object o) { 354.381 - if (o instanceof Double) { 354.382 - double d = ((Double) o).doubleValue(); 354.383 - for (int j = array.length - 1; j >= i; j--) 354.384 - if (d == array[j]) return j - i; 354.385 - } 354.386 - if (o == null) { 354.387 - return -1; 354.388 - } 354.389 - for (int j = array.length - 1; j >= i; j--) 354.390 - if (o.equals(array[j])) return j - i; 354.391 - return -1; 354.392 - } 354.393 -} 354.394 - 354.395 -static public class ArraySeq_long extends ASeq implements IndexedSeq, IReduce{ 354.396 - public final long[] array; 354.397 - final int i; 354.398 - 354.399 - ArraySeq_long(IPersistentMap meta, long[] array, int i){ 354.400 - super(meta); 354.401 - this.array = array; 354.402 - this.i = i; 354.403 - } 354.404 - 354.405 - public Object first(){ 354.406 - return array[i]; 354.407 - } 354.408 - 354.409 - public ISeq next(){ 354.410 - if(i + 1 < array.length) 354.411 - return new ArraySeq_long(meta(), array, i + 1); 354.412 - return null; 354.413 - } 354.414 - 354.415 - public int count(){ 354.416 - return array.length - i; 354.417 - } 354.418 - 354.419 - public int index(){ 354.420 - return i; 354.421 - } 354.422 - 354.423 - public ArraySeq_long withMeta(IPersistentMap meta){ 354.424 - return new ArraySeq_long(meta, array, i); 354.425 - } 354.426 - 354.427 - public Object reduce(IFn f) throws Exception{ 354.428 - Object ret = array[i]; 354.429 - for(int x = i + 1; x < array.length; x++) 354.430 - ret = f.invoke(ret, array[x]); 354.431 - return ret; 354.432 - } 354.433 - 354.434 - public Object reduce(IFn f, Object start) throws Exception{ 354.435 - Object ret = f.invoke(start, array[i]); 354.436 - for(int x = i + 1; x < array.length; x++) 354.437 - ret = f.invoke(ret, array[x]); 354.438 - return ret; 354.439 - } 354.440 - 354.441 - public int indexOf(Object o) { 354.442 - if (o instanceof Long) { 354.443 - long l = ((Long) o).longValue(); 354.444 - for (int j = i; j < array.length; j++) 354.445 - if (l == array[j]) return j - i; 354.446 - } 354.447 - if (o == null) { 354.448 - return -1; 354.449 - } 354.450 - for (int j = i; j < array.length; j++) 354.451 - if (o.equals(array[j])) return j - i; 354.452 - return -1; 354.453 - } 354.454 - 354.455 - public int lastIndexOf(Object o) { 354.456 - if (o instanceof Long) { 354.457 - long l = ((Long) o).longValue(); 354.458 - for (int j = array.length - 1; j >= i; j--) 354.459 - if (l == array[j]) return j - i; 354.460 - } 354.461 - if (o == null) { 354.462 - return -1; 354.463 - } 354.464 - for (int j = array.length - 1; j >= i; j--) 354.465 - if (o.equals(array[j])) return j - i; 354.466 - return -1; 354.467 - } 354.468 -} 354.469 - 354.470 -static public class ArraySeq_byte extends ASeq implements IndexedSeq, IReduce{ 354.471 - public final byte[] array; 354.472 - final int i; 354.473 - 354.474 - ArraySeq_byte(IPersistentMap meta, byte[] array, int i){ 354.475 - super(meta); 354.476 - this.array = array; 354.477 - this.i = i; 354.478 - } 354.479 - 354.480 - public Object first(){ 354.481 - return array[i]; 354.482 - } 354.483 - 354.484 - public ISeq next(){ 354.485 - if(i + 1 < array.length) 354.486 - return new ArraySeq_byte(meta(), array, i + 1); 354.487 - return null; 354.488 - } 354.489 - 354.490 - public int count(){ 354.491 - return array.length - i; 354.492 - } 354.493 - 354.494 - public int index(){ 354.495 - return i; 354.496 - } 354.497 - 354.498 - public ArraySeq_byte withMeta(IPersistentMap meta){ 354.499 - return new ArraySeq_byte(meta, array, i); 354.500 - } 354.501 - 354.502 - public Object reduce(IFn f) throws Exception{ 354.503 - Object ret = array[i]; 354.504 - for(int x = i + 1; x < array.length; x++) 354.505 - ret = f.invoke(ret, array[x]); 354.506 - return ret; 354.507 - } 354.508 - 354.509 - public Object reduce(IFn f, Object start) throws Exception{ 354.510 - Object ret = f.invoke(start, array[i]); 354.511 - for(int x = i + 1; x < array.length; x++) 354.512 - ret = f.invoke(ret, array[x]); 354.513 - return ret; 354.514 - } 354.515 - 354.516 - public int indexOf(Object o) { 354.517 - if (o instanceof Byte) { 354.518 - byte b = ((Byte) o).byteValue(); 354.519 - for (int j = i; j < array.length; j++) 354.520 - if (b == array[j]) return j - i; 354.521 - } 354.522 - if (o == null) { 354.523 - return -1; 354.524 - } 354.525 - for (int j = i; j < array.length; j++) 354.526 - if (o.equals(array[j])) return j - i; 354.527 - return -1; 354.528 - } 354.529 - 354.530 - public int lastIndexOf(Object o) { 354.531 - if (o instanceof Byte) { 354.532 - byte b = ((Byte) o).byteValue(); 354.533 - for (int j = array.length - 1; j >= i; j--) 354.534 - if (b == array[j]) return j - i; 354.535 - } 354.536 - if (o == null) { 354.537 - return -1; 354.538 - } 354.539 - for (int j = array.length - 1; j >= i; j--) 354.540 - if (o.equals(array[j])) return j - i; 354.541 - return -1; 354.542 - } 354.543 -} 354.544 - 354.545 -static public class ArraySeq_char extends ASeq implements IndexedSeq, IReduce{ 354.546 - public final char[] array; 354.547 - final int i; 354.548 - 354.549 - ArraySeq_char(IPersistentMap meta, char[] array, int i){ 354.550 - super(meta); 354.551 - this.array = array; 354.552 - this.i = i; 354.553 - } 354.554 - 354.555 - public Object first(){ 354.556 - return array[i]; 354.557 - } 354.558 - 354.559 - public ISeq next(){ 354.560 - if(i + 1 < array.length) 354.561 - return new ArraySeq_char(meta(), array, i + 1); 354.562 - return null; 354.563 - } 354.564 - 354.565 - public int count(){ 354.566 - return array.length - i; 354.567 - } 354.568 - 354.569 - public int index(){ 354.570 - return i; 354.571 - } 354.572 - 354.573 - public ArraySeq_char withMeta(IPersistentMap meta){ 354.574 - return new ArraySeq_char(meta, array, i); 354.575 - } 354.576 - 354.577 - public Object reduce(IFn f) throws Exception{ 354.578 - Object ret = array[i]; 354.579 - for(int x = i + 1; x < array.length; x++) 354.580 - ret = f.invoke(ret, array[x]); 354.581 - return ret; 354.582 - } 354.583 - 354.584 - public Object reduce(IFn f, Object start) throws Exception{ 354.585 - Object ret = f.invoke(start, array[i]); 354.586 - for(int x = i + 1; x < array.length; x++) 354.587 - ret = f.invoke(ret, array[x]); 354.588 - return ret; 354.589 - } 354.590 - 354.591 - public int indexOf(Object o) { 354.592 - if (o instanceof Character) { 354.593 - char c = ((Character) o).charValue(); 354.594 - for (int j = i; j < array.length; j++) 354.595 - if (c == array[j]) return j - i; 354.596 - } 354.597 - if (o == null) { 354.598 - return -1; 354.599 - } 354.600 - for (int j = i; j < array.length; j++) 354.601 - if (o.equals(array[j])) return j - i; 354.602 - return -1; 354.603 - } 354.604 - 354.605 - public int lastIndexOf(Object o) { 354.606 - if (o instanceof Character) { 354.607 - char c = ((Character) o).charValue(); 354.608 - for (int j = array.length - 1; j >= i; j--) 354.609 - if (c == array[j]) return j - i; 354.610 - } 354.611 - if (o == null) { 354.612 - return -1; 354.613 - } 354.614 - for (int j = array.length - 1; j >= i; j--) 354.615 - if (o.equals(array[j])) return j - i; 354.616 - return -1; 354.617 - } 354.618 -} 354.619 - 354.620 -static public class ArraySeq_boolean extends ASeq implements IndexedSeq, IReduce{ 354.621 - public final boolean[] array; 354.622 - final int i; 354.623 - 354.624 - ArraySeq_boolean(IPersistentMap meta, boolean[] array, int i){ 354.625 - super(meta); 354.626 - this.array = array; 354.627 - this.i = i; 354.628 - } 354.629 - 354.630 - public Object first(){ 354.631 - return array[i]; 354.632 - } 354.633 - 354.634 - public ISeq next(){ 354.635 - if(i + 1 < array.length) 354.636 - return new ArraySeq_boolean(meta(), array, i + 1); 354.637 - return null; 354.638 - } 354.639 - 354.640 - public int count(){ 354.641 - return array.length - i; 354.642 - } 354.643 - 354.644 - public int index(){ 354.645 - return i; 354.646 - } 354.647 - 354.648 - public ArraySeq_boolean withMeta(IPersistentMap meta){ 354.649 - return new ArraySeq_boolean(meta, array, i); 354.650 - } 354.651 - 354.652 - public Object reduce(IFn f) throws Exception{ 354.653 - Object ret = array[i]; 354.654 - for(int x = i + 1; x < array.length; x++) 354.655 - ret = f.invoke(ret, array[x]); 354.656 - return ret; 354.657 - } 354.658 - 354.659 - public Object reduce(IFn f, Object start) throws Exception{ 354.660 - Object ret = f.invoke(start, array[i]); 354.661 - for(int x = i + 1; x < array.length; x++) 354.662 - ret = f.invoke(ret, array[x]); 354.663 - return ret; 354.664 - } 354.665 - 354.666 - public int indexOf(Object o) { 354.667 - if (o instanceof Boolean) { 354.668 - boolean b = ((Boolean) o).booleanValue(); 354.669 - for (int j = i; j < array.length; j++) 354.670 - if (b == array[j]) return j - i; 354.671 - } 354.672 - if (o == null) { 354.673 - return -1; 354.674 - } 354.675 - for (int j = i; j < array.length; j++) 354.676 - if (o.equals(array[j])) return j - i; 354.677 - return -1; 354.678 - } 354.679 - 354.680 - public int lastIndexOf(Object o) { 354.681 - if (o instanceof Boolean) { 354.682 - boolean b = ((Boolean) o).booleanValue(); 354.683 - for (int j = array.length - 1; j >= i; j--) 354.684 - if (b == array[j]) return j - i; 354.685 - } 354.686 - if (o == null) { 354.687 - return -1; 354.688 - } 354.689 - for (int j = array.length - 1; j >= i; j--) 354.690 - if (o.equals(array[j])) return j - i; 354.691 - return -1; 354.692 - } 354.693 -} 354.694 - 354.695 -}
355.1 --- a/src/clojure/lang/Associative.java Sat Aug 21 06:25:44 2010 -0400 355.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 355.3 @@ -1,19 +0,0 @@ 355.4 -package clojure.lang; 355.5 - 355.6 -/** 355.7 - * Copyright (c) Rich Hickey. All rights reserved. 355.8 - * The use and distribution terms for this software are covered by the 355.9 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 355.10 - * which can be found in the file epl-v10.html at the root of this distribution. 355.11 - * By using this software in any fashion, you are agreeing to be bound by 355.12 - * the terms of this license. 355.13 - * You must not remove this notice, or any other, from this software. 355.14 - */ 355.15 -public interface Associative extends IPersistentCollection, ILookup{ 355.16 -boolean containsKey(Object key); 355.17 - 355.18 -IMapEntry entryAt(Object key); 355.19 - 355.20 -Associative assoc(Object key, Object val); 355.21 - 355.22 -}
356.1 --- a/src/clojure/lang/Atom.java Sat Aug 21 06:25:44 2010 -0400 356.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 356.3 @@ -1,104 +0,0 @@ 356.4 -/** 356.5 - * Copyright (c) Rich Hickey. All rights reserved. 356.6 - * The use and distribution terms for this software are covered by the 356.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 356.8 - * which can be found in the file epl-v10.html at the root of this distribution. 356.9 - * By using this software in any fashion, you are agreeing to be bound by 356.10 - * the terms of this license. 356.11 - * You must not remove this notice, or any other, from this software. 356.12 - **/ 356.13 - 356.14 -/* rich Jan 1, 2009 */ 356.15 - 356.16 -package clojure.lang; 356.17 - 356.18 -import java.util.concurrent.atomic.AtomicReference; 356.19 - 356.20 -final public class Atom extends ARef{ 356.21 -final AtomicReference state; 356.22 - 356.23 -public Atom(Object state){ 356.24 - this.state = new AtomicReference(state); 356.25 -} 356.26 - 356.27 -public Atom(Object state, IPersistentMap meta){ 356.28 - super(meta); 356.29 - this.state = new AtomicReference(state); 356.30 -} 356.31 - 356.32 -public Object deref(){ 356.33 - return state.get(); 356.34 -} 356.35 - 356.36 -public Object swap(IFn f) throws Exception{ 356.37 - for(; ;) 356.38 - { 356.39 - Object v = deref(); 356.40 - Object newv = f.invoke(v); 356.41 - validate(newv); 356.42 - if(state.compareAndSet(v, newv)) 356.43 - { 356.44 - notifyWatches(v, newv); 356.45 - return newv; 356.46 - } 356.47 - } 356.48 -} 356.49 - 356.50 -public Object swap(IFn f, Object arg) throws Exception{ 356.51 - for(; ;) 356.52 - { 356.53 - Object v = deref(); 356.54 - Object newv = f.invoke(v, arg); 356.55 - validate(newv); 356.56 - if(state.compareAndSet(v, newv)) 356.57 - { 356.58 - notifyWatches(v, newv); 356.59 - return newv; 356.60 - } 356.61 - } 356.62 -} 356.63 - 356.64 -public Object swap(IFn f, Object arg1, Object arg2) throws Exception{ 356.65 - for(; ;) 356.66 - { 356.67 - Object v = deref(); 356.68 - Object newv = f.invoke(v, arg1, arg2); 356.69 - validate(newv); 356.70 - if(state.compareAndSet(v, newv)) 356.71 - { 356.72 - notifyWatches(v, newv); 356.73 - return newv; 356.74 - } 356.75 - } 356.76 -} 356.77 - 356.78 -public Object swap(IFn f, Object x, Object y, ISeq args) throws Exception{ 356.79 - for(; ;) 356.80 - { 356.81 - Object v = deref(); 356.82 - Object newv = f.applyTo(RT.listStar(v, x, y, args)); 356.83 - validate(newv); 356.84 - if(state.compareAndSet(v, newv)) 356.85 - { 356.86 - notifyWatches(v, newv); 356.87 - return newv; 356.88 - } 356.89 - } 356.90 -} 356.91 - 356.92 -public boolean compareAndSet(Object oldv, Object newv){ 356.93 - validate(newv); 356.94 - boolean ret = state.compareAndSet(oldv, newv); 356.95 - if(ret) 356.96 - notifyWatches(oldv, newv); 356.97 - return ret; 356.98 -} 356.99 - 356.100 -public Object reset(Object newval){ 356.101 - Object oldval = state.get(); 356.102 - validate(newval); 356.103 - state.set(newval); 356.104 - notifyWatches(oldval, newval); 356.105 - return newval; 356.106 -} 356.107 -}
357.1 --- a/src/clojure/lang/Binding.java Sat Aug 21 06:25:44 2010 -0400 357.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 357.3 @@ -1,26 +0,0 @@ 357.4 -/** 357.5 - * Copyright (c) Rich Hickey. All rights reserved. 357.6 - * The use and distribution terms for this software are covered by the 357.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 357.8 - * which can be found in the file epl-v10.html at the root of this distribution. 357.9 - * By using this software in any fashion, you are agreeing to be bound by 357.10 - * the terms of this license. 357.11 - * You must not remove this notice, or any other, from this software. 357.12 - **/ 357.13 - 357.14 -package clojure.lang; 357.15 - 357.16 -public class Binding<T>{ 357.17 -public T val; 357.18 -public final Binding rest; 357.19 - 357.20 -public Binding(T val){ 357.21 - this.val = val; 357.22 - this.rest = null; 357.23 -} 357.24 - 357.25 -public Binding(T val, Binding rest){ 357.26 - this.val = val; 357.27 - this.rest = rest; 357.28 -} 357.29 -}
358.1 --- a/src/clojure/lang/Box.java Sat Aug 21 06:25:44 2010 -0400 358.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 358.3 @@ -1,22 +0,0 @@ 358.4 -/** 358.5 - * Copyright (c) Rich Hickey. All rights reserved. 358.6 - * The use and distribution terms for this software are covered by the 358.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 358.8 - * which can be found in the file epl-v10.html at the root of this distribution. 358.9 - * By using this software in any fashion, you are agreeing to be bound by 358.10 - * the terms of this license. 358.11 - * You must not remove this notice, or any other, from this software. 358.12 - **/ 358.13 - 358.14 -/* rich Mar 27, 2006 8:40:19 PM */ 358.15 - 358.16 -package clojure.lang; 358.17 - 358.18 -public class Box{ 358.19 - 358.20 -public Object val; 358.21 - 358.22 -public Box(Object val){ 358.23 - this.val = val; 358.24 -} 358.25 -}
359.1 --- a/src/clojure/lang/ChunkBuffer.java Sat Aug 21 06:25:44 2010 -0400 359.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 359.3 @@ -1,37 +0,0 @@ 359.4 -/** 359.5 - * Copyright (c) Rich Hickey. All rights reserved. 359.6 - * The use and distribution terms for this software are covered by the 359.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 359.8 - * which can be found in the file epl-v10.html at the root of this distribution. 359.9 - * By using this software in any fashion, you are agreeing to be bound by 359.10 - * the terms of this license. 359.11 - * You must not remove this notice, or any other, from this software. 359.12 - **/ 359.13 - 359.14 -/* rich May 26, 2009 */ 359.15 - 359.16 -package clojure.lang; 359.17 - 359.18 -final public class ChunkBuffer implements Counted{ 359.19 - Object[] buffer; 359.20 - int end; 359.21 - 359.22 -public ChunkBuffer(int capacity){ 359.23 - buffer = new Object[capacity]; 359.24 - end = 0; 359.25 -} 359.26 - 359.27 -public void add(Object o){ 359.28 - buffer[end++] = o; 359.29 -} 359.30 - 359.31 -public IChunk chunk(){ 359.32 - ArrayChunk ret = new ArrayChunk(buffer, 0, end); 359.33 - buffer = null; 359.34 - return ret; 359.35 -} 359.36 - 359.37 -public int count(){ 359.38 - return end; 359.39 -} 359.40 -}
360.1 --- a/src/clojure/lang/ChunkedCons.java Sat Aug 21 06:25:44 2010 -0400 360.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 360.3 @@ -1,67 +0,0 @@ 360.4 -/** 360.5 - * Copyright (c) Rich Hickey. All rights reserved. 360.6 - * The use and distribution terms for this software are covered by the 360.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 360.8 - * which can be found in the file epl-v10.html at the root of this distribution. 360.9 - * By using this software in any fashion, you are agreeing to be bound by 360.10 - * the terms of this license. 360.11 - * You must not remove this notice, or any other, from this software. 360.12 - **/ 360.13 - 360.14 -/* rich May 25, 2009 */ 360.15 - 360.16 -package clojure.lang; 360.17 - 360.18 -final public class ChunkedCons extends ASeq implements IChunkedSeq{ 360.19 - 360.20 -final IChunk chunk; 360.21 -final ISeq _more; 360.22 - 360.23 -ChunkedCons(IPersistentMap meta, IChunk chunk, ISeq more){ 360.24 - super(meta); 360.25 - this.chunk = chunk; 360.26 - this._more = more; 360.27 -} 360.28 - 360.29 -public ChunkedCons(IChunk chunk, ISeq more){ 360.30 - this(null,chunk, more); 360.31 -} 360.32 - 360.33 -public Obj withMeta(IPersistentMap meta){ 360.34 - if(meta != _meta) 360.35 - return new ChunkedCons(meta, chunk, _more); 360.36 - return this; 360.37 -} 360.38 - 360.39 -public Object first(){ 360.40 - return chunk.nth(0); 360.41 -} 360.42 - 360.43 -public ISeq next(){ 360.44 - if(chunk.count() > 1) 360.45 - return new ChunkedCons(chunk.dropFirst(), _more); 360.46 - return chunkedNext(); 360.47 -} 360.48 - 360.49 -public ISeq more(){ 360.50 - if(chunk.count() > 1) 360.51 - return new ChunkedCons(chunk.dropFirst(), _more); 360.52 - if(_more == null) 360.53 - return PersistentList.EMPTY; 360.54 - return _more; 360.55 -} 360.56 - 360.57 -public IChunk chunkedFirst(){ 360.58 - return chunk; 360.59 -} 360.60 - 360.61 -public ISeq chunkedNext(){ 360.62 - return chunkedMore().seq(); 360.63 -} 360.64 - 360.65 -public ISeq chunkedMore(){ 360.66 - if(_more == null) 360.67 - return PersistentList.EMPTY; 360.68 - return _more; 360.69 -} 360.70 -}
361.1 --- a/src/clojure/lang/Compile.java Sat Aug 21 06:25:44 2010 -0400 361.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 361.3 @@ -1,73 +0,0 @@ 361.4 -/** 361.5 - * Copyright (c) Rich Hickey. All rights reserved. 361.6 - * The use and distribution terms for this software are covered by the 361.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 361.8 - * which can be found in the file epl-v10.html at the root of this distribution. 361.9 - * By using this software in any fashion, you are agreeing to be bound by 361.10 - * the terms of this license. 361.11 - * You must not remove this notice, or any other, from this software. 361.12 - **/ 361.13 - 361.14 - 361.15 -package clojure.lang; 361.16 - 361.17 -import java.io.OutputStreamWriter; 361.18 -import java.io.PrintWriter; 361.19 -import java.io.IOException; 361.20 - 361.21 -// Compiles libs and generates class files stored within the directory 361.22 -// named by the Java System property "clojure.compile.path". Arguments are 361.23 -// strings naming the libs to be compiled. The libs and compile-path must 361.24 -// all be within CLASSPATH. 361.25 - 361.26 -public class Compile{ 361.27 - 361.28 -private static final String PATH_PROP = "clojure.compile.path"; 361.29 -private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection"; 361.30 -private static final Var compile_path = RT.var("clojure.core", "*compile-path*"); 361.31 -private static final Var compile = RT.var("clojure.core", "compile"); 361.32 -private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*"); 361.33 - 361.34 -public static void main(String[] args) throws Exception{ 361.35 - 361.36 - OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref(); 361.37 - PrintWriter err = RT.errPrintWriter(); 361.38 - String path = System.getProperty(PATH_PROP); 361.39 - int count = args.length; 361.40 - 361.41 - if(path == null) 361.42 - { 361.43 - err.println("ERROR: Must set system property " + PATH_PROP + 361.44 - "\nto the location for compiled .class files." + 361.45 - "\nThis directory must also be on your CLASSPATH."); 361.46 - System.exit(1); 361.47 - } 361.48 - 361.49 - boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true"); 361.50 - 361.51 - try 361.52 - { 361.53 - Var.pushThreadBindings(RT.map(compile_path, path, warn_on_reflection, warnOnReflection)); 361.54 - 361.55 - for(String lib : args) 361.56 - { 361.57 - out.write("Compiling " + lib + " to " + path + "\n"); 361.58 - out.flush(); 361.59 - compile.invoke(Symbol.intern(lib)); 361.60 - } 361.61 - } 361.62 - finally 361.63 - { 361.64 - Var.popThreadBindings(); 361.65 - try 361.66 - { 361.67 - out.flush(); 361.68 - out.close(); 361.69 - } 361.70 - catch(IOException e) 361.71 - { 361.72 - e.printStackTrace(err); 361.73 - } 361.74 - } 361.75 -} 361.76 -}
362.1 --- a/src/clojure/lang/Compiler.java Sat Aug 21 06:25:44 2010 -0400 362.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 362.3 @@ -1,6897 +0,0 @@ 362.4 -/** 362.5 - * Copyright (c) Rich Hickey. All rights reserved. 362.6 - * The use and distribution terms for this software are covered by the 362.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 362.8 - * which can be found in the file epl-v10.html at the root of this distribution. 362.9 - * By using this software in any fashion, you are agreeing to be bound by 362.10 - * the terms of this license. 362.11 - * You must not remove this notice, or any other, from this software. 362.12 - **/ 362.13 - 362.14 -/* rich Aug 21, 2007 */ 362.15 - 362.16 -package clojure.lang; 362.17 - 362.18 -//* 362.19 - 362.20 -import clojure.asm.*; 362.21 -import clojure.asm.commons.Method; 362.22 -import clojure.asm.commons.GeneratorAdapter; 362.23 -//*/ 362.24 -/* 362.25 - 362.26 -import org.objectweb.asm.*; 362.27 -import org.objectweb.asm.commons.Method; 362.28 -import org.objectweb.asm.commons.GeneratorAdapter; 362.29 -import org.objectweb.asm.util.TraceClassVisitor; 362.30 -import org.objectweb.asm.util.CheckClassAdapter; 362.31 -//*/ 362.32 - 362.33 -import java.io.*; 362.34 -import java.util.*; 362.35 -import java.lang.reflect.Constructor; 362.36 -import java.lang.reflect.Modifier; 362.37 - 362.38 -public class Compiler implements Opcodes{ 362.39 - 362.40 -static final Symbol DEF = Symbol.create("def"); 362.41 -static final Symbol LOOP = Symbol.create("loop*"); 362.42 -static final Symbol RECUR = Symbol.create("recur"); 362.43 -static final Symbol IF = Symbol.create("if"); 362.44 -static final Symbol LET = Symbol.create("let*"); 362.45 -static final Symbol LETFN = Symbol.create("letfn*"); 362.46 -static final Symbol DO = Symbol.create("do"); 362.47 -static final Symbol FN = Symbol.create("fn*"); 362.48 -static final Symbol QUOTE = Symbol.create("quote"); 362.49 -static final Symbol THE_VAR = Symbol.create("var"); 362.50 -static final Symbol DOT = Symbol.create("."); 362.51 -static final Symbol ASSIGN = Symbol.create("set!"); 362.52 -//static final Symbol TRY_FINALLY = Symbol.create("try-finally"); 362.53 -static final Symbol TRY = Symbol.create("try"); 362.54 -static final Symbol CATCH = Symbol.create("catch"); 362.55 -static final Symbol FINALLY = Symbol.create("finally"); 362.56 -static final Symbol THROW = Symbol.create("throw"); 362.57 -static final Symbol MONITOR_ENTER = Symbol.create("monitor-enter"); 362.58 -static final Symbol MONITOR_EXIT = Symbol.create("monitor-exit"); 362.59 -static final Symbol IMPORT = Symbol.create("clojure.core", "import*"); 362.60 -//static final Symbol INSTANCE = Symbol.create("instance?"); 362.61 -static final Symbol DEFTYPE = Symbol.create("deftype*"); 362.62 -static final Symbol CASE = Symbol.create("case*"); 362.63 - 362.64 -//static final Symbol THISFN = Symbol.create("thisfn"); 362.65 -static final Symbol CLASS = Symbol.create("Class"); 362.66 -static final Symbol NEW = Symbol.create("new"); 362.67 -static final Symbol THIS = Symbol.create("this"); 362.68 -static final Symbol REIFY = Symbol.create("reify*"); 362.69 -//static final Symbol UNQUOTE = Symbol.create("unquote"); 362.70 -//static final Symbol UNQUOTE_SPLICING = Symbol.create("unquote-splicing"); 362.71 -//static final Symbol SYNTAX_QUOTE = Symbol.create("clojure.core", "syntax-quote"); 362.72 -static final Symbol LIST = Symbol.create("clojure.core", "list"); 362.73 -static final Symbol HASHMAP = Symbol.create("clojure.core", "hash-map"); 362.74 -static final Symbol VECTOR = Symbol.create("clojure.core", "vector"); 362.75 -static final Symbol IDENTITY = Symbol.create("clojure.core", "identity"); 362.76 - 362.77 -static final Symbol _AMP_ = Symbol.create("&"); 362.78 -static final Symbol ISEQ = Symbol.create("clojure.lang.ISeq"); 362.79 - 362.80 -static final Keyword inlineKey = Keyword.intern(null, "inline"); 362.81 -static final Keyword inlineAritiesKey = Keyword.intern(null, "inline-arities"); 362.82 - 362.83 -static final Keyword volatileKey = Keyword.intern(null, "volatile"); 362.84 -static final Keyword implementsKey = Keyword.intern(null, "implements"); 362.85 -static final String COMPILE_STUB_PREFIX = "compile__stub"; 362.86 - 362.87 -static final Keyword protocolKey = Keyword.intern(null, "protocol"); 362.88 -static final Keyword onKey = Keyword.intern(null, "on"); 362.89 - 362.90 -static final Symbol NS = Symbol.create("ns"); 362.91 -static final Symbol IN_NS = Symbol.create("in-ns"); 362.92 - 362.93 -//static final Symbol IMPORT = Symbol.create("import"); 362.94 -//static final Symbol USE = Symbol.create("use"); 362.95 - 362.96 -//static final Symbol IFN = Symbol.create("clojure.lang", "IFn"); 362.97 - 362.98 -static final public IPersistentMap specials = PersistentHashMap.create( 362.99 - DEF, new DefExpr.Parser(), 362.100 - LOOP, new LetExpr.Parser(), 362.101 - RECUR, new RecurExpr.Parser(), 362.102 - IF, new IfExpr.Parser(), 362.103 - CASE, new CaseExpr.Parser(), 362.104 - LET, new LetExpr.Parser(), 362.105 - LETFN, new LetFnExpr.Parser(), 362.106 - DO, new BodyExpr.Parser(), 362.107 - FN, null, 362.108 - QUOTE, new ConstantExpr.Parser(), 362.109 - THE_VAR, new TheVarExpr.Parser(), 362.110 - IMPORT, new ImportExpr.Parser(), 362.111 - DOT, new HostExpr.Parser(), 362.112 - ASSIGN, new AssignExpr.Parser(), 362.113 - DEFTYPE, new NewInstanceExpr.DeftypeParser(), 362.114 - REIFY, new NewInstanceExpr.ReifyParser(), 362.115 -// TRY_FINALLY, new TryFinallyExpr.Parser(), 362.116 -TRY, new TryExpr.Parser(), 362.117 -THROW, new ThrowExpr.Parser(), 362.118 -MONITOR_ENTER, new MonitorEnterExpr.Parser(), 362.119 -MONITOR_EXIT, new MonitorExitExpr.Parser(), 362.120 -// INSTANCE, new InstanceExpr.Parser(), 362.121 -// IDENTICAL, new IdenticalExpr.Parser(), 362.122 -//THISFN, null, 362.123 -CATCH, null, 362.124 -FINALLY, null, 362.125 -// CLASS, new ClassExpr.Parser(), 362.126 -NEW, new NewExpr.Parser(), 362.127 -// UNQUOTE, null, 362.128 -// UNQUOTE_SPLICING, null, 362.129 -// SYNTAX_QUOTE, null, 362.130 -_AMP_, null 362.131 -); 362.132 - 362.133 -private static final int MAX_POSITIONAL_ARITY = 20; 362.134 -private static final Type OBJECT_TYPE; 362.135 -private static final Type KEYWORD_TYPE = Type.getType(Keyword.class); 362.136 -private static final Type VAR_TYPE = Type.getType(Var.class); 362.137 -private static final Type SYMBOL_TYPE = Type.getType(Symbol.class); 362.138 -//private static final Type NUM_TYPE = Type.getType(Num.class); 362.139 -private static final Type IFN_TYPE = Type.getType(IFn.class); 362.140 -private static final Type AFUNCTION_TYPE = Type.getType(AFunction.class); 362.141 -private static final Type RT_TYPE = Type.getType(RT.class); 362.142 -final static Type CLASS_TYPE = Type.getType(Class.class); 362.143 -final static Type NS_TYPE = Type.getType(Namespace.class); 362.144 -final static Type UTIL_TYPE = Type.getType(Util.class); 362.145 -final static Type REFLECTOR_TYPE = Type.getType(Reflector.class); 362.146 -final static Type THROWABLE_TYPE = Type.getType(Throwable.class); 362.147 -final static Type BOOLEAN_OBJECT_TYPE = Type.getType(Boolean.class); 362.148 -final static Type IPERSISTENTMAP_TYPE = Type.getType(IPersistentMap.class); 362.149 -final static Type IOBJ_TYPE = Type.getType(IObj.class); 362.150 - 362.151 -private static final Type[][] ARG_TYPES; 362.152 -private static final Type[] EXCEPTION_TYPES = {Type.getType(Exception.class)}; 362.153 - 362.154 -static 362.155 - { 362.156 - OBJECT_TYPE = Type.getType(Object.class); 362.157 - ARG_TYPES = new Type[MAX_POSITIONAL_ARITY + 2][]; 362.158 - for(int i = 0; i <= MAX_POSITIONAL_ARITY; ++i) 362.159 - { 362.160 - Type[] a = new Type[i]; 362.161 - for(int j = 0; j < i; j++) 362.162 - a[j] = OBJECT_TYPE; 362.163 - ARG_TYPES[i] = a; 362.164 - } 362.165 - Type[] a = new Type[MAX_POSITIONAL_ARITY + 1]; 362.166 - for(int j = 0; j < MAX_POSITIONAL_ARITY; j++) 362.167 - a[j] = OBJECT_TYPE; 362.168 - a[MAX_POSITIONAL_ARITY] = Type.getType("[Ljava/lang/Object;"); 362.169 - ARG_TYPES[MAX_POSITIONAL_ARITY + 1] = a; 362.170 - 362.171 - 362.172 - } 362.173 - 362.174 - 362.175 -//symbol->localbinding 362.176 -static final public Var LOCAL_ENV = Var.create(null); 362.177 - 362.178 -//vector<localbinding> 362.179 -static final public Var LOOP_LOCALS = Var.create(); 362.180 - 362.181 -//Label 362.182 -static final public Var LOOP_LABEL = Var.create(); 362.183 - 362.184 -//vector<object> 362.185 -static final public Var CONSTANTS = Var.create(); 362.186 - 362.187 -//IdentityHashMap 362.188 -static final public Var CONSTANT_IDS = Var.create(); 362.189 - 362.190 -//vector<keyword> 362.191 -static final public Var KEYWORD_CALLSITES = Var.create(); 362.192 - 362.193 -//vector<var> 362.194 -static final public Var PROTOCOL_CALLSITES = Var.create(); 362.195 - 362.196 -//vector<var> 362.197 -static final public Var VAR_CALLSITES = Var.create(); 362.198 - 362.199 -//keyword->constid 362.200 -static final public Var KEYWORDS = Var.create(); 362.201 - 362.202 -//var->constid 362.203 -static final public Var VARS = Var.create(); 362.204 - 362.205 -//FnFrame 362.206 -static final public Var METHOD = Var.create(null); 362.207 - 362.208 -//null or not 362.209 -static final public Var IN_CATCH_FINALLY = Var.create(null); 362.210 - 362.211 -//DynamicClassLoader 362.212 -static final public Var LOADER = Var.create(); 362.213 - 362.214 -//String 362.215 -static final public Var SOURCE = Var.intern(Namespace.findOrCreate(Symbol.create("clojure.core")), 362.216 - Symbol.create("*source-path*"), "NO_SOURCE_FILE"); 362.217 - 362.218 -//String 362.219 -static final public Var SOURCE_PATH = Var.intern(Namespace.findOrCreate(Symbol.create("clojure.core")), 362.220 - Symbol.create("*file*"), "NO_SOURCE_PATH"); 362.221 - 362.222 -//String 362.223 -static final public Var COMPILE_PATH = Var.intern(Namespace.findOrCreate(Symbol.create("clojure.core")), 362.224 - Symbol.create("*compile-path*"), null); 362.225 -//boolean 362.226 -static final public Var COMPILE_FILES = Var.intern(Namespace.findOrCreate(Symbol.create("clojure.core")), 362.227 - Symbol.create("*compile-files*"), Boolean.FALSE); 362.228 - 362.229 -static final public Var INSTANCE = Var.intern(Namespace.findOrCreate(Symbol.create("clojure.core")), 362.230 - Symbol.create("instance?")); 362.231 - 362.232 -static final public Var ADD_ANNOTATIONS = Var.intern(Namespace.findOrCreate(Symbol.create("clojure.core")), 362.233 - Symbol.create("add-annotations")); 362.234 - 362.235 -//Integer 362.236 -static final public Var LINE = Var.create(0); 362.237 - 362.238 -//Integer 362.239 -static final public Var LINE_BEFORE = Var.create(0); 362.240 -static final public Var LINE_AFTER = Var.create(0); 362.241 - 362.242 -//Integer 362.243 -static final public Var NEXT_LOCAL_NUM = Var.create(0); 362.244 - 362.245 -//Integer 362.246 -static final public Var RET_LOCAL_NUM = Var.create(); 362.247 - 362.248 - 362.249 -static final public Var COMPILE_STUB_SYM = Var.create(null); 362.250 -static final public Var COMPILE_STUB_CLASS = Var.create(null); 362.251 - 362.252 - 362.253 -//PathNode chain 362.254 -static final public Var CLEAR_PATH = Var.create(null); 362.255 - 362.256 -//tail of PathNode chain 362.257 -static final public Var CLEAR_ROOT = Var.create(null); 362.258 - 362.259 -//LocalBinding -> Set<LocalBindingExpr> 362.260 -static final public Var CLEAR_SITES = Var.create(null); 362.261 - 362.262 - public enum C{ 362.263 - STATEMENT, //value ignored 362.264 - EXPRESSION, //value required 362.265 - RETURN, //tail position relative to enclosing recur frame 362.266 - EVAL 362.267 -} 362.268 - 362.269 -interface Expr{ 362.270 - Object eval() throws Exception; 362.271 - 362.272 - void emit(C context, ObjExpr objx, GeneratorAdapter gen); 362.273 - 362.274 - boolean hasJavaClass() throws Exception; 362.275 - 362.276 - Class getJavaClass() throws Exception; 362.277 -} 362.278 - 362.279 -public static abstract class UntypedExpr implements Expr{ 362.280 - 362.281 - public Class getJavaClass(){ 362.282 - throw new IllegalArgumentException("Has no Java class"); 362.283 - } 362.284 - 362.285 - public boolean hasJavaClass(){ 362.286 - return false; 362.287 - } 362.288 -} 362.289 - 362.290 -interface IParser{ 362.291 - Expr parse(C context, Object form) throws Exception; 362.292 -} 362.293 - 362.294 -static boolean isSpecial(Object sym){ 362.295 - return specials.containsKey(sym); 362.296 -} 362.297 - 362.298 -static Symbol resolveSymbol(Symbol sym){ 362.299 - //already qualified or classname? 362.300 - if(sym.name.indexOf('.') > 0) 362.301 - return sym; 362.302 - if(sym.ns != null) 362.303 - { 362.304 - Namespace ns = namespaceFor(sym); 362.305 - if(ns == null || ns.name.name == sym.ns) 362.306 - return sym; 362.307 - return Symbol.create(ns.name.name, sym.name); 362.308 - } 362.309 - Object o = currentNS().getMapping(sym); 362.310 - if(o == null) 362.311 - return Symbol.intern(currentNS().name.name, sym.name); 362.312 - else if(o instanceof Class) 362.313 - return Symbol.intern(null, ((Class) o).getName()); 362.314 - else if(o instanceof Var) 362.315 - { 362.316 - Var v = (Var) o; 362.317 - return Symbol.create(v.ns.name.name, v.sym.name); 362.318 - } 362.319 - return null; 362.320 - 362.321 -} 362.322 - 362.323 -static class DefExpr implements Expr{ 362.324 - public final Var var; 362.325 - public final Expr init; 362.326 - public final Expr meta; 362.327 - public final boolean initProvided; 362.328 - public final String source; 362.329 - public final int line; 362.330 - final static Method bindRootMethod = Method.getMethod("void bindRoot(Object)"); 362.331 - final static Method setTagMethod = Method.getMethod("void setTag(clojure.lang.Symbol)"); 362.332 - final static Method setMetaMethod = Method.getMethod("void setMeta(clojure.lang.IPersistentMap)"); 362.333 - final static Method symcreate = Method.getMethod("clojure.lang.Symbol create(String, String)"); 362.334 - 362.335 - public DefExpr(String source, int line, Var var, Expr init, Expr meta, boolean initProvided){ 362.336 - this.source = source; 362.337 - this.line = line; 362.338 - this.var = var; 362.339 - this.init = init; 362.340 - this.meta = meta; 362.341 - this.initProvided = initProvided; 362.342 - } 362.343 - 362.344 - private boolean includesExplicitMetadata(MapExpr expr) { 362.345 - for(int i=0; i < expr.keyvals.count(); i += 2) 362.346 - { 362.347 - Keyword k = ((KeywordExpr) expr.keyvals.nth(i)).k; 362.348 - if ((k != RT.FILE_KEY) && 362.349 - (k != RT.DECLARED_KEY) && 362.350 - (k != RT.LINE_KEY)) 362.351 - return true; 362.352 - } 362.353 - return false; 362.354 - } 362.355 - 362.356 - public Object eval() throws Exception{ 362.357 - try 362.358 - { 362.359 - if(initProvided) 362.360 - { 362.361 -// if(init instanceof FnExpr && ((FnExpr) init).closes.count()==0) 362.362 -// var.bindRoot(new FnLoaderThunk((FnExpr) init,var)); 362.363 -// else 362.364 - var.bindRoot(init.eval()); 362.365 - } 362.366 - if(meta != null) 362.367 - { 362.368 - IPersistentMap metaMap = (IPersistentMap) meta.eval(); 362.369 - if (initProvided || includesExplicitMetadata((MapExpr) meta)) 362.370 - var.setMeta((IPersistentMap) meta.eval()); 362.371 - } 362.372 - return var; 362.373 - } 362.374 - catch(Throwable e) 362.375 - { 362.376 - if(!(e instanceof CompilerException)) 362.377 - throw new CompilerException(source, line, e); 362.378 - else 362.379 - throw (CompilerException) e; 362.380 - } 362.381 - } 362.382 - 362.383 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.384 - objx.emitVar(gen, var); 362.385 - if(meta != null) 362.386 - { 362.387 - if (initProvided || includesExplicitMetadata((MapExpr) meta)) 362.388 - { 362.389 - gen.dup(); 362.390 - meta.emit(C.EXPRESSION, objx, gen); 362.391 - gen.checkCast(IPERSISTENTMAP_TYPE); 362.392 - gen.invokeVirtual(VAR_TYPE, setMetaMethod); 362.393 - } 362.394 - } 362.395 - if(initProvided) 362.396 - { 362.397 - gen.dup(); 362.398 - init.emit(C.EXPRESSION, objx, gen); 362.399 - gen.invokeVirtual(VAR_TYPE, bindRootMethod); 362.400 - } 362.401 - 362.402 - if(context == C.STATEMENT) 362.403 - gen.pop(); 362.404 - } 362.405 - 362.406 - public boolean hasJavaClass(){ 362.407 - return true; 362.408 - } 362.409 - 362.410 - public Class getJavaClass(){ 362.411 - return Var.class; 362.412 - } 362.413 - 362.414 - static class Parser implements IParser{ 362.415 - public Expr parse(C context, Object form) throws Exception{ 362.416 - //(def x) or (def x initexpr) 362.417 - if(RT.count(form) > 3) 362.418 - throw new Exception("Too many arguments to def"); 362.419 - else if(RT.count(form) < 2) 362.420 - throw new Exception("Too few arguments to def"); 362.421 - else if(!(RT.second(form) instanceof Symbol)) 362.422 - throw new Exception("First argument to def must be a Symbol"); 362.423 - Symbol sym = (Symbol) RT.second(form); 362.424 - Var v = lookupVar(sym, true); 362.425 - if(v == null) 362.426 - throw new Exception("Can't refer to qualified var that doesn't exist"); 362.427 - if(!v.ns.equals(currentNS())) 362.428 - { 362.429 - if(sym.ns == null) 362.430 - v = currentNS().intern(sym); 362.431 -// throw new Exception("Name conflict, can't def " + sym + " because namespace: " + currentNS().name + 362.432 -// " refers to:" + v); 362.433 - else 362.434 - throw new Exception("Can't create defs outside of current ns"); 362.435 - } 362.436 - IPersistentMap mm = sym.meta(); 362.437 - Object source_path = SOURCE_PATH.get(); 362.438 - source_path = source_path == null ? "NO_SOURCE_FILE" : source_path; 362.439 - mm = (IPersistentMap) RT.assoc(mm, RT.LINE_KEY, LINE.get()).assoc(RT.FILE_KEY, source_path); 362.440 - Expr meta = analyze(context == C.EVAL ? context : C.EXPRESSION, mm); 362.441 - return new DefExpr((String) SOURCE.deref(), (Integer) LINE.deref(), 362.442 - v, analyze(context == C.EVAL ? context : C.EXPRESSION, RT.third(form), v.sym.name), 362.443 - meta, RT.count(form) == 3); 362.444 - } 362.445 - } 362.446 -} 362.447 - 362.448 -public static class AssignExpr implements Expr{ 362.449 - public final AssignableExpr target; 362.450 - public final Expr val; 362.451 - 362.452 - public AssignExpr(AssignableExpr target, Expr val){ 362.453 - this.target = target; 362.454 - this.val = val; 362.455 - } 362.456 - 362.457 - public Object eval() throws Exception{ 362.458 - return target.evalAssign(val); 362.459 - } 362.460 - 362.461 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.462 - target.emitAssign(context, objx, gen, val); 362.463 - } 362.464 - 362.465 - public boolean hasJavaClass() throws Exception{ 362.466 - return val.hasJavaClass(); 362.467 - } 362.468 - 362.469 - public Class getJavaClass() throws Exception{ 362.470 - return val.getJavaClass(); 362.471 - } 362.472 - 362.473 - static class Parser implements IParser{ 362.474 - public Expr parse(C context, Object frm) throws Exception{ 362.475 - ISeq form = (ISeq) frm; 362.476 - if(RT.length(form) != 3) 362.477 - throw new IllegalArgumentException("Malformed assignment, expecting (set! target val)"); 362.478 - Expr target = analyze(C.EXPRESSION, RT.second(form)); 362.479 - if(!(target instanceof AssignableExpr)) 362.480 - throw new IllegalArgumentException("Invalid assignment target"); 362.481 - return new AssignExpr((AssignableExpr) target, analyze(C.EXPRESSION, RT.third(form))); 362.482 - } 362.483 - } 362.484 -} 362.485 - 362.486 -public static class VarExpr implements Expr, AssignableExpr{ 362.487 - public final Var var; 362.488 - public final Object tag; 362.489 - final static Method getMethod = Method.getMethod("Object get()"); 362.490 - final static Method setMethod = Method.getMethod("Object set(Object)"); 362.491 - 362.492 - public VarExpr(Var var, Symbol tag){ 362.493 - this.var = var; 362.494 - this.tag = tag != null ? tag : var.getTag(); 362.495 - } 362.496 - 362.497 - public Object eval() throws Exception{ 362.498 - return var.deref(); 362.499 - } 362.500 - 362.501 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.502 - objx.emitVar(gen, var); 362.503 - gen.invokeVirtual(VAR_TYPE, getMethod); 362.504 - if(context == C.STATEMENT) 362.505 - { 362.506 - gen.pop(); 362.507 - } 362.508 - } 362.509 - 362.510 - public boolean hasJavaClass(){ 362.511 - return tag != null; 362.512 - } 362.513 - 362.514 - public Class getJavaClass() throws Exception{ 362.515 - return HostExpr.tagToClass(tag); 362.516 - } 362.517 - 362.518 - public Object evalAssign(Expr val) throws Exception{ 362.519 - return var.set(val.eval()); 362.520 - } 362.521 - 362.522 - public void emitAssign(C context, ObjExpr objx, GeneratorAdapter gen, 362.523 - Expr val){ 362.524 - objx.emitVar(gen, var); 362.525 - val.emit(C.EXPRESSION, objx, gen); 362.526 - gen.invokeVirtual(VAR_TYPE, setMethod); 362.527 - if(context == C.STATEMENT) 362.528 - gen.pop(); 362.529 - } 362.530 -} 362.531 - 362.532 -public static class TheVarExpr implements Expr{ 362.533 - public final Var var; 362.534 - 362.535 - public TheVarExpr(Var var){ 362.536 - this.var = var; 362.537 - } 362.538 - 362.539 - public Object eval() throws Exception{ 362.540 - return var; 362.541 - } 362.542 - 362.543 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.544 - objx.emitVar(gen, var); 362.545 - if(context == C.STATEMENT) 362.546 - gen.pop(); 362.547 - } 362.548 - 362.549 - public boolean hasJavaClass(){ 362.550 - return true; 362.551 - } 362.552 - 362.553 - public Class getJavaClass() throws ClassNotFoundException{ 362.554 - return Var.class; 362.555 - } 362.556 - 362.557 - static class Parser implements IParser{ 362.558 - public Expr parse(C context, Object form) throws Exception{ 362.559 - Symbol sym = (Symbol) RT.second(form); 362.560 - Var v = lookupVar(sym, false); 362.561 - if(v != null) 362.562 - return new TheVarExpr(v); 362.563 - throw new Exception("Unable to resolve var: " + sym + " in this context"); 362.564 - } 362.565 - } 362.566 -} 362.567 - 362.568 -public static class KeywordExpr implements Expr{ 362.569 - public final Keyword k; 362.570 - 362.571 - public KeywordExpr(Keyword k){ 362.572 - this.k = k; 362.573 - } 362.574 - 362.575 - public Object eval() throws Exception{ 362.576 - return k; 362.577 - } 362.578 - 362.579 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.580 - objx.emitKeyword(gen, k); 362.581 - if(context == C.STATEMENT) 362.582 - gen.pop(); 362.583 - 362.584 - } 362.585 - 362.586 - public boolean hasJavaClass(){ 362.587 - return true; 362.588 - } 362.589 - 362.590 - public Class getJavaClass() throws ClassNotFoundException{ 362.591 - return Keyword.class; 362.592 - } 362.593 -} 362.594 - 362.595 -public static class ImportExpr implements Expr{ 362.596 - public final String c; 362.597 - final static Method forNameMethod = Method.getMethod("Class forName(String)"); 362.598 - final static Method importClassMethod = Method.getMethod("Class importClass(Class)"); 362.599 - final static Method derefMethod = Method.getMethod("Object deref()"); 362.600 - 362.601 - public ImportExpr(String c){ 362.602 - this.c = c; 362.603 - } 362.604 - 362.605 - public Object eval() throws Exception{ 362.606 - Namespace ns = (Namespace) RT.CURRENT_NS.deref(); 362.607 - ns.importClass(RT.classForName(c)); 362.608 - return null; 362.609 - } 362.610 - 362.611 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.612 - gen.getStatic(RT_TYPE,"CURRENT_NS",VAR_TYPE); 362.613 - gen.invokeVirtual(VAR_TYPE, derefMethod); 362.614 - gen.checkCast(NS_TYPE); 362.615 - gen.push(c); 362.616 - gen.invokeStatic(CLASS_TYPE, forNameMethod); 362.617 - gen.invokeVirtual(NS_TYPE, importClassMethod); 362.618 - if(context == C.STATEMENT) 362.619 - gen.pop(); 362.620 - } 362.621 - 362.622 - public boolean hasJavaClass(){ 362.623 - return false; 362.624 - } 362.625 - 362.626 - public Class getJavaClass() throws ClassNotFoundException{ 362.627 - throw new IllegalArgumentException("ImportExpr has no Java class"); 362.628 - } 362.629 - 362.630 - static class Parser implements IParser{ 362.631 - public Expr parse(C context, Object form) throws Exception{ 362.632 - return new ImportExpr((String) RT.second(form)); 362.633 - } 362.634 - } 362.635 -} 362.636 - 362.637 -public static abstract class LiteralExpr implements Expr{ 362.638 - abstract Object val(); 362.639 - 362.640 - public Object eval(){ 362.641 - return val(); 362.642 - } 362.643 -} 362.644 - 362.645 -static interface AssignableExpr{ 362.646 - Object evalAssign(Expr val) throws Exception; 362.647 - 362.648 - void emitAssign(C context, ObjExpr objx, GeneratorAdapter gen, Expr val); 362.649 -} 362.650 - 362.651 -static public interface MaybePrimitiveExpr extends Expr{ 362.652 - public boolean canEmitPrimitive(); 362.653 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen); 362.654 -} 362.655 - 362.656 -static public abstract class HostExpr implements Expr, MaybePrimitiveExpr{ 362.657 - final static Type BOOLEAN_TYPE = Type.getType(Boolean.class); 362.658 - final static Type CHAR_TYPE = Type.getType(Character.class); 362.659 - final static Type INTEGER_TYPE = Type.getType(Integer.class); 362.660 - final static Type LONG_TYPE = Type.getType(Long.class); 362.661 - final static Type FLOAT_TYPE = Type.getType(Float.class); 362.662 - final static Type DOUBLE_TYPE = Type.getType(Double.class); 362.663 - final static Type SHORT_TYPE = Type.getType(Short.class); 362.664 - final static Type BYTE_TYPE = Type.getType(Byte.class); 362.665 - final static Type NUMBER_TYPE = Type.getType(Number.class); 362.666 - 362.667 - final static Method charValueMethod = Method.getMethod("char charValue()"); 362.668 - final static Method booleanValueMethod = Method.getMethod("boolean booleanValue()"); 362.669 - 362.670 - final static Method charValueOfMethod = Method.getMethod("Character valueOf(char)"); 362.671 - final static Method intValueOfMethod = Method.getMethod("Integer valueOf(int)"); 362.672 - final static Method longValueOfMethod = Method.getMethod("Long valueOf(long)"); 362.673 - final static Method floatValueOfMethod = Method.getMethod("Float valueOf(float)"); 362.674 - final static Method doubleValueOfMethod = Method.getMethod("Double valueOf(double)"); 362.675 - final static Method shortValueOfMethod = Method.getMethod("Short valueOf(short)"); 362.676 - final static Method byteValueOfMethod = Method.getMethod("Byte valueOf(byte)"); 362.677 - 362.678 - final static Method intValueMethod = Method.getMethod("int intValue()"); 362.679 - final static Method longValueMethod = Method.getMethod("long longValue()"); 362.680 - final static Method floatValueMethod = Method.getMethod("float floatValue()"); 362.681 - final static Method doubleValueMethod = Method.getMethod("double doubleValue()"); 362.682 - final static Method byteValueMethod = Method.getMethod("byte byteValue()"); 362.683 - final static Method shortValueMethod = Method.getMethod("short shortValue()"); 362.684 - 362.685 - final static Method fromIntMethod = Method.getMethod("clojure.lang.Num from(int)"); 362.686 - final static Method fromLongMethod = Method.getMethod("clojure.lang.Num from(long)"); 362.687 - final static Method fromDoubleMethod = Method.getMethod("clojure.lang.Num from(double)"); 362.688 - 362.689 - 362.690 - //* 362.691 - public static void emitBoxReturn(ObjExpr objx, GeneratorAdapter gen, Class returnType){ 362.692 - if(returnType.isPrimitive()) 362.693 - { 362.694 - if(returnType == boolean.class) 362.695 - { 362.696 - Label falseLabel = gen.newLabel(); 362.697 - Label endLabel = gen.newLabel(); 362.698 - gen.ifZCmp(GeneratorAdapter.EQ, falseLabel); 362.699 - gen.getStatic(BOOLEAN_OBJECT_TYPE, "TRUE", BOOLEAN_OBJECT_TYPE); 362.700 - gen.goTo(endLabel); 362.701 - gen.mark(falseLabel); 362.702 - gen.getStatic(BOOLEAN_OBJECT_TYPE, "FALSE", BOOLEAN_OBJECT_TYPE); 362.703 -// NIL_EXPR.emit(C.EXPRESSION, fn, gen); 362.704 - gen.mark(endLabel); 362.705 - } 362.706 - else if(returnType == void.class) 362.707 - { 362.708 - NIL_EXPR.emit(C.EXPRESSION, objx, gen); 362.709 - } 362.710 - else if(returnType == char.class) 362.711 - { 362.712 - gen.invokeStatic(CHAR_TYPE, charValueOfMethod); 362.713 - } 362.714 - else 362.715 - { 362.716 - if(returnType == int.class) 362.717 - //gen.invokeStatic(NUM_TYPE, fromIntMethod); 362.718 - gen.invokeStatic(INTEGER_TYPE, intValueOfMethod); 362.719 - else if(returnType == float.class) 362.720 - { 362.721 - //gen.visitInsn(F2D); 362.722 - gen.invokeStatic(FLOAT_TYPE, floatValueOfMethod); 362.723 - //m = floatValueOfMethod; 362.724 - } 362.725 - else if(returnType == double.class) 362.726 - gen.invokeStatic(DOUBLE_TYPE, doubleValueOfMethod); 362.727 - else if(returnType == long.class) 362.728 - gen.invokeStatic(LONG_TYPE, longValueOfMethod); 362.729 - else if(returnType == byte.class) 362.730 - gen.invokeStatic(BYTE_TYPE, byteValueOfMethod); 362.731 - else if(returnType == short.class) 362.732 - gen.invokeStatic(SHORT_TYPE, shortValueOfMethod); 362.733 - } 362.734 - } 362.735 - } 362.736 - 362.737 - //*/ 362.738 - public static void emitUnboxArg(ObjExpr objx, GeneratorAdapter gen, Class paramType){ 362.739 - if(paramType.isPrimitive()) 362.740 - { 362.741 - if(paramType == boolean.class) 362.742 - { 362.743 - gen.checkCast(BOOLEAN_TYPE); 362.744 - gen.invokeVirtual(BOOLEAN_TYPE, booleanValueMethod); 362.745 -// Label falseLabel = gen.newLabel(); 362.746 -// Label endLabel = gen.newLabel(); 362.747 -// gen.ifNull(falseLabel); 362.748 -// gen.push(1); 362.749 -// gen.goTo(endLabel); 362.750 -// gen.mark(falseLabel); 362.751 -// gen.push(0); 362.752 -// gen.mark(endLabel); 362.753 - } 362.754 - else if(paramType == char.class) 362.755 - { 362.756 - gen.checkCast(CHAR_TYPE); 362.757 - gen.invokeVirtual(CHAR_TYPE, charValueMethod); 362.758 - } 362.759 - else 362.760 - { 362.761 - Method m = intValueMethod; 362.762 - gen.checkCast(NUMBER_TYPE); 362.763 - if(paramType == int.class) 362.764 - m = intValueMethod; 362.765 - else if(paramType == float.class) 362.766 - m = floatValueMethod; 362.767 - else if(paramType == double.class) 362.768 - m = doubleValueMethod; 362.769 - else if(paramType == long.class) 362.770 - m = longValueMethod; 362.771 - else if(paramType == byte.class) 362.772 - m = byteValueMethod; 362.773 - else if(paramType == short.class) 362.774 - m = shortValueMethod; 362.775 - gen.invokeVirtual(NUMBER_TYPE, m); 362.776 - } 362.777 - } 362.778 - else 362.779 - { 362.780 - gen.checkCast(Type.getType(paramType)); 362.781 - } 362.782 - } 362.783 - 362.784 - static class Parser implements IParser{ 362.785 - public Expr parse(C context, Object frm) throws Exception{ 362.786 - ISeq form = (ISeq) frm; 362.787 - //(. x fieldname-sym) or 362.788 - //(. x 0-ary-method) 362.789 - // (. x methodname-sym args+) 362.790 - // (. x (methodname-sym args?)) 362.791 - if(RT.length(form) < 3) 362.792 - throw new IllegalArgumentException("Malformed member expression, expecting (. target member ...)"); 362.793 - //determine static or instance 362.794 - //static target must be symbol, either fully.qualified.Classname or Classname that has been imported 362.795 - int line = (Integer) LINE.deref(); 362.796 - String source = (String) SOURCE.deref(); 362.797 - Class c = maybeClass(RT.second(form), false); 362.798 - //at this point c will be non-null if static 362.799 - Expr instance = null; 362.800 - if(c == null) 362.801 - instance = analyze(context == C.EVAL ? context : C.EXPRESSION, RT.second(form)); 362.802 - boolean maybeField = RT.length(form) == 3 && 362.803 - (RT.third(form) instanceof Symbol 362.804 - || RT.third(form) instanceof Keyword); 362.805 - if(maybeField && !(RT.third(form) instanceof Keyword)) 362.806 - { 362.807 - Symbol sym = (Symbol) RT.third(form); 362.808 - if(c != null) 362.809 - maybeField = Reflector.getMethods(c, 0, munge(sym.name), true).size() == 0; 362.810 - else if(instance != null && instance.hasJavaClass() && instance.getJavaClass() != null) 362.811 - maybeField = Reflector.getMethods(instance.getJavaClass(), 0, munge(sym.name), false).size() == 0; 362.812 - } 362.813 - if(maybeField) //field 362.814 - { 362.815 - Symbol sym = (RT.third(form) instanceof Keyword)? 362.816 - ((Keyword)RT.third(form)).sym 362.817 - :(Symbol) RT.third(form); 362.818 - Symbol tag = tagOf(form); 362.819 - if(c != null) { 362.820 - return new StaticFieldExpr(line, c, munge(sym.name), tag); 362.821 - } else 362.822 - return new InstanceFieldExpr(line, instance, munge(sym.name), tag); 362.823 - } 362.824 - else 362.825 - { 362.826 - ISeq call = (ISeq) ((RT.third(form) instanceof ISeq) ? RT.third(form) : RT.next(RT.next(form))); 362.827 - if(!(RT.first(call) instanceof Symbol)) 362.828 - throw new IllegalArgumentException("Malformed member expression"); 362.829 - Symbol sym = (Symbol) RT.first(call); 362.830 - Symbol tag = tagOf(form); 362.831 - PersistentVector args = PersistentVector.EMPTY; 362.832 - for(ISeq s = RT.next(call); s != null; s = s.next()) 362.833 - args = args.cons(analyze(context == C.EVAL ? context : C.EXPRESSION, s.first())); 362.834 - if(c != null) 362.835 - return new StaticMethodExpr(source, line, tag, c, munge(sym.name), args); 362.836 - else 362.837 - return new InstanceMethodExpr(source, line, tag, instance, munge(sym.name), args); 362.838 - } 362.839 - } 362.840 - } 362.841 - 362.842 - private static Class maybeClass(Object form, boolean stringOk) throws Exception{ 362.843 - if(form instanceof Class) 362.844 - return (Class) form; 362.845 - Class c = null; 362.846 - if(form instanceof Symbol) 362.847 - { 362.848 - Symbol sym = (Symbol) form; 362.849 - if(sym.ns == null) //if ns-qualified can't be classname 362.850 - { 362.851 - if(Util.equals(sym,COMPILE_STUB_SYM.get())) 362.852 - return (Class) COMPILE_STUB_CLASS.get(); 362.853 - if(sym.name.indexOf('.') > 0 || sym.name.charAt(0) == '[') 362.854 - c = RT.classForName(sym.name); 362.855 - else 362.856 - { 362.857 - Object o = currentNS().getMapping(sym); 362.858 - if(o instanceof Class) 362.859 - c = (Class) o; 362.860 - } 362.861 - } 362.862 - } 362.863 - else if(stringOk && form instanceof String) 362.864 - c = RT.classForName((String) form); 362.865 - return c; 362.866 - } 362.867 - 362.868 - /* 362.869 - private static String maybeClassName(Object form, boolean stringOk){ 362.870 - String className = null; 362.871 - if(form instanceof Symbol) 362.872 - { 362.873 - Symbol sym = (Symbol) form; 362.874 - if(sym.ns == null) //if ns-qualified can't be classname 362.875 - { 362.876 - if(sym.name.indexOf('.') > 0 || sym.name.charAt(0) == '[') 362.877 - className = sym.name; 362.878 - else 362.879 - { 362.880 - IPersistentMap imports = (IPersistentMap) ((Var) RT.NS_IMPORTS.get()).get(); 362.881 - className = (String) imports.valAt(sym); 362.882 - } 362.883 - } 362.884 - } 362.885 - else if(stringOk && form instanceof String) 362.886 - className = (String) form; 362.887 - return className; 362.888 - } 362.889 - */ 362.890 - static Class tagToClass(Object tag) throws Exception{ 362.891 - Class c = maybeClass(tag, true); 362.892 - if(tag instanceof Symbol) 362.893 - { 362.894 - Symbol sym = (Symbol) tag; 362.895 - if(sym.ns == null) //if ns-qualified can't be classname 362.896 - { 362.897 - if(sym.name.equals("objects")) 362.898 - c = Object[].class; 362.899 - else if(sym.name.equals("ints")) 362.900 - c = int[].class; 362.901 - else if(sym.name.equals("longs")) 362.902 - c = long[].class; 362.903 - else if(sym.name.equals("floats")) 362.904 - c = float[].class; 362.905 - else if(sym.name.equals("doubles")) 362.906 - c = double[].class; 362.907 - else if(sym.name.equals("chars")) 362.908 - c = char[].class; 362.909 - else if(sym.name.equals("shorts")) 362.910 - c = short[].class; 362.911 - else if(sym.name.equals("bytes")) 362.912 - c = byte[].class; 362.913 - else if(sym.name.equals("booleans")) 362.914 - c = boolean[].class; 362.915 - } 362.916 - } 362.917 - if(c != null) 362.918 - return c; 362.919 - throw new IllegalArgumentException("Unable to resolve classname: " + tag); 362.920 - } 362.921 -} 362.922 - 362.923 -static abstract class FieldExpr extends HostExpr{ 362.924 -} 362.925 - 362.926 -static class InstanceFieldExpr extends FieldExpr implements AssignableExpr{ 362.927 - public final Expr target; 362.928 - public final Class targetClass; 362.929 - public final java.lang.reflect.Field field; 362.930 - public final String fieldName; 362.931 - public final int line; 362.932 - public final Symbol tag; 362.933 - final static Method invokeNoArgInstanceMember = Method.getMethod("Object invokeNoArgInstanceMember(Object,String)"); 362.934 - final static Method setInstanceFieldMethod = Method.getMethod("Object setInstanceField(Object,String,Object)"); 362.935 - 362.936 - 362.937 - public InstanceFieldExpr(int line, Expr target, String fieldName, Symbol tag) throws Exception{ 362.938 - this.target = target; 362.939 - this.targetClass = target.hasJavaClass() ? target.getJavaClass() : null; 362.940 - this.field = targetClass != null ? Reflector.getField(targetClass, fieldName, false) : null; 362.941 - this.fieldName = fieldName; 362.942 - this.line = line; 362.943 - this.tag = tag; 362.944 - if(field == null && RT.booleanCast(RT.WARN_ON_REFLECTION.deref())) 362.945 - { 362.946 - RT.errPrintWriter() 362.947 - .format("Reflection warning, %s:%d - reference to field %s can't be resolved.\n", 362.948 - SOURCE_PATH.deref(), line, fieldName); 362.949 - } 362.950 - } 362.951 - 362.952 - public Object eval() throws Exception{ 362.953 - return Reflector.invokeNoArgInstanceMember(target.eval(), fieldName); 362.954 - } 362.955 - 362.956 - public boolean canEmitPrimitive(){ 362.957 - return targetClass != null && field != null && 362.958 - Util.isPrimitive(field.getType()); 362.959 - } 362.960 - 362.961 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.962 - gen.visitLineNumber(line, gen.mark()); 362.963 - if(targetClass != null && field != null) 362.964 - { 362.965 - target.emit(C.EXPRESSION, objx, gen); 362.966 - gen.checkCast(getType(targetClass)); 362.967 - gen.getField(getType(targetClass), fieldName, Type.getType(field.getType())); 362.968 - } 362.969 - else 362.970 - throw new UnsupportedOperationException("Unboxed emit of unknown member"); 362.971 - } 362.972 - 362.973 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.974 - gen.visitLineNumber(line, gen.mark()); 362.975 - if(targetClass != null && field != null) 362.976 - { 362.977 - target.emit(C.EXPRESSION, objx, gen); 362.978 - gen.checkCast(getType(targetClass)); 362.979 - gen.getField(getType(targetClass), fieldName, Type.getType(field.getType())); 362.980 - //if(context != C.STATEMENT) 362.981 - HostExpr.emitBoxReturn(objx, gen, field.getType()); 362.982 - if(context == C.STATEMENT) 362.983 - { 362.984 - gen.pop(); 362.985 - } 362.986 - } 362.987 - else 362.988 - { 362.989 - target.emit(C.EXPRESSION, objx, gen); 362.990 - gen.push(fieldName); 362.991 - gen.invokeStatic(REFLECTOR_TYPE, invokeNoArgInstanceMember); 362.992 - if(context == C.STATEMENT) 362.993 - gen.pop(); 362.994 - } 362.995 - } 362.996 - 362.997 - public boolean hasJavaClass() throws Exception{ 362.998 - return field != null || tag != null; 362.999 - } 362.1000 - 362.1001 - public Class getJavaClass() throws Exception{ 362.1002 - return tag != null ? HostExpr.tagToClass(tag) : field.getType(); 362.1003 - } 362.1004 - 362.1005 - public Object evalAssign(Expr val) throws Exception{ 362.1006 - return Reflector.setInstanceField(target.eval(), fieldName, val.eval()); 362.1007 - } 362.1008 - 362.1009 - public void emitAssign(C context, ObjExpr objx, GeneratorAdapter gen, 362.1010 - Expr val){ 362.1011 - gen.visitLineNumber(line, gen.mark()); 362.1012 - if(targetClass != null && field != null) 362.1013 - { 362.1014 - target.emit(C.EXPRESSION, objx, gen); 362.1015 - gen.checkCast(Type.getType(targetClass)); 362.1016 - val.emit(C.EXPRESSION, objx, gen); 362.1017 - gen.dupX1(); 362.1018 - HostExpr.emitUnboxArg(objx, gen, field.getType()); 362.1019 - gen.putField(Type.getType(targetClass), fieldName, Type.getType(field.getType())); 362.1020 - } 362.1021 - else 362.1022 - { 362.1023 - target.emit(C.EXPRESSION, objx, gen); 362.1024 - gen.push(fieldName); 362.1025 - val.emit(C.EXPRESSION, objx, gen); 362.1026 - gen.invokeStatic(REFLECTOR_TYPE, setInstanceFieldMethod); 362.1027 - } 362.1028 - if(context == C.STATEMENT) 362.1029 - gen.pop(); 362.1030 - } 362.1031 -} 362.1032 - 362.1033 -static class StaticFieldExpr extends FieldExpr implements AssignableExpr{ 362.1034 - //final String className; 362.1035 - public final String fieldName; 362.1036 - public final Class c; 362.1037 - public final java.lang.reflect.Field field; 362.1038 - public final Symbol tag; 362.1039 -// final static Method getStaticFieldMethod = Method.getMethod("Object getStaticField(String,String)"); 362.1040 -// final static Method setStaticFieldMethod = Method.getMethod("Object setStaticField(String,String,Object)"); 362.1041 - final int line; 362.1042 - 362.1043 - public StaticFieldExpr(int line, Class c, String fieldName, Symbol tag) throws Exception{ 362.1044 - //this.className = className; 362.1045 - this.fieldName = fieldName; 362.1046 - this.line = line; 362.1047 - //c = Class.forName(className); 362.1048 - this.c = c; 362.1049 - field = c.getField(fieldName); 362.1050 - this.tag = tag; 362.1051 - } 362.1052 - 362.1053 - public Object eval() throws Exception{ 362.1054 - return Reflector.getStaticField(c, fieldName); 362.1055 - } 362.1056 - 362.1057 - public boolean canEmitPrimitive(){ 362.1058 - return Util.isPrimitive(field.getType()); 362.1059 - } 362.1060 - 362.1061 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1062 - gen.visitLineNumber(line, gen.mark()); 362.1063 - gen.getStatic(Type.getType(c), fieldName, Type.getType(field.getType())); 362.1064 - } 362.1065 - 362.1066 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1067 - gen.visitLineNumber(line, gen.mark()); 362.1068 - 362.1069 - gen.getStatic(Type.getType(c), fieldName, Type.getType(field.getType())); 362.1070 - //if(context != C.STATEMENT) 362.1071 - HostExpr.emitBoxReturn(objx, gen, field.getType()); 362.1072 - if(context == C.STATEMENT) 362.1073 - { 362.1074 - gen.pop(); 362.1075 - } 362.1076 -// gen.push(className); 362.1077 -// gen.push(fieldName); 362.1078 -// gen.invokeStatic(REFLECTOR_TYPE, getStaticFieldMethod); 362.1079 - } 362.1080 - 362.1081 - public boolean hasJavaClass(){ 362.1082 - return true; 362.1083 - } 362.1084 - 362.1085 - public Class getJavaClass() throws Exception{ 362.1086 - //Class c = Class.forName(className); 362.1087 - //java.lang.reflect.Field field = c.getField(fieldName); 362.1088 - return tag != null ? HostExpr.tagToClass(tag) : field.getType(); 362.1089 - } 362.1090 - 362.1091 - public Object evalAssign(Expr val) throws Exception{ 362.1092 - return Reflector.setStaticField(c, fieldName, val.eval()); 362.1093 - } 362.1094 - 362.1095 - public void emitAssign(C context, ObjExpr objx, GeneratorAdapter gen, 362.1096 - Expr val){ 362.1097 - gen.visitLineNumber(line, gen.mark()); 362.1098 - val.emit(C.EXPRESSION, objx, gen); 362.1099 - gen.dup(); 362.1100 - HostExpr.emitUnboxArg(objx, gen, field.getType()); 362.1101 - gen.putStatic(Type.getType(c), fieldName, Type.getType(field.getType())); 362.1102 - if(context == C.STATEMENT) 362.1103 - gen.pop(); 362.1104 - } 362.1105 - 362.1106 - 362.1107 -} 362.1108 - 362.1109 -static Class maybePrimitiveType(Expr e){ 362.1110 - try 362.1111 - { 362.1112 - if(e instanceof MaybePrimitiveExpr && e.hasJavaClass() && ((MaybePrimitiveExpr)e).canEmitPrimitive()) 362.1113 - { 362.1114 - Class c = e.getJavaClass(); 362.1115 - if(Util.isPrimitive(c)) 362.1116 - return c; 362.1117 - } 362.1118 - } 362.1119 - catch(Exception ex) 362.1120 - { 362.1121 - throw new RuntimeException(ex); 362.1122 - } 362.1123 - return null; 362.1124 -} 362.1125 - 362.1126 -static abstract class MethodExpr extends HostExpr{ 362.1127 - static void emitArgsAsArray(IPersistentVector args, ObjExpr objx, GeneratorAdapter gen){ 362.1128 - gen.push(args.count()); 362.1129 - gen.newArray(OBJECT_TYPE); 362.1130 - for(int i = 0; i < args.count(); i++) 362.1131 - { 362.1132 - gen.dup(); 362.1133 - gen.push(i); 362.1134 - ((Expr) args.nth(i)).emit(C.EXPRESSION, objx, gen); 362.1135 - gen.arrayStore(OBJECT_TYPE); 362.1136 - } 362.1137 - } 362.1138 - 362.1139 - public static void emitTypedArgs(ObjExpr objx, GeneratorAdapter gen, Class[] parameterTypes, IPersistentVector args){ 362.1140 - for(int i = 0; i < parameterTypes.length; i++) 362.1141 - { 362.1142 - Expr e = (Expr) args.nth(i); 362.1143 - try 362.1144 - { 362.1145 - if(maybePrimitiveType(e) == parameterTypes[i]) 362.1146 - { 362.1147 - ((MaybePrimitiveExpr) e).emitUnboxed(C.EXPRESSION, objx, gen); 362.1148 - } 362.1149 - else 362.1150 - { 362.1151 - e.emit(C.EXPRESSION, objx, gen); 362.1152 - HostExpr.emitUnboxArg(objx, gen, parameterTypes[i]); 362.1153 - } 362.1154 - } 362.1155 - catch(Exception e1) 362.1156 - { 362.1157 - e1.printStackTrace(RT.errPrintWriter()); 362.1158 - } 362.1159 - 362.1160 - } 362.1161 - } 362.1162 -} 362.1163 - 362.1164 -static class InstanceMethodExpr extends MethodExpr{ 362.1165 - public final Expr target; 362.1166 - public final String methodName; 362.1167 - public final IPersistentVector args; 362.1168 - public final String source; 362.1169 - public final int line; 362.1170 - public final Symbol tag; 362.1171 - public final java.lang.reflect.Method method; 362.1172 - 362.1173 - final static Method invokeInstanceMethodMethod = 362.1174 - Method.getMethod("Object invokeInstanceMethod(Object,String,Object[])"); 362.1175 - 362.1176 - 362.1177 - public InstanceMethodExpr(String source, int line, Symbol tag, Expr target, String methodName, IPersistentVector args) 362.1178 - throws Exception{ 362.1179 - this.source = source; 362.1180 - this.line = line; 362.1181 - this.args = args; 362.1182 - this.methodName = methodName; 362.1183 - this.target = target; 362.1184 - this.tag = tag; 362.1185 - if(target.hasJavaClass() && target.getJavaClass() != null) 362.1186 - { 362.1187 - List methods = Reflector.getMethods(target.getJavaClass(), args.count(), methodName, false); 362.1188 - if(methods.isEmpty()) 362.1189 - method = null; 362.1190 - //throw new IllegalArgumentException("No matching method found"); 362.1191 - else 362.1192 - { 362.1193 - int methodidx = 0; 362.1194 - if(methods.size() > 1) 362.1195 - { 362.1196 - ArrayList<Class[]> params = new ArrayList(); 362.1197 - ArrayList<Class> rets = new ArrayList(); 362.1198 - for(int i = 0; i < methods.size(); i++) 362.1199 - { 362.1200 - java.lang.reflect.Method m = (java.lang.reflect.Method) methods.get(i); 362.1201 - params.add(m.getParameterTypes()); 362.1202 - rets.add(m.getReturnType()); 362.1203 - } 362.1204 - methodidx = getMatchingParams(methodName, params, args, rets); 362.1205 - } 362.1206 - java.lang.reflect.Method m = 362.1207 - (java.lang.reflect.Method) (methodidx >= 0 ? methods.get(methodidx) : null); 362.1208 - if(m != null && !Modifier.isPublic(m.getDeclaringClass().getModifiers())) 362.1209 - { 362.1210 - //public method of non-public class, try to find it in hierarchy 362.1211 - m = Reflector.getAsMethodOfPublicBase(m.getDeclaringClass(), m); 362.1212 - } 362.1213 - method = m; 362.1214 - } 362.1215 - } 362.1216 - else 362.1217 - method = null; 362.1218 - 362.1219 - if(method == null && RT.booleanCast(RT.WARN_ON_REFLECTION.deref())) 362.1220 - { 362.1221 - RT.errPrintWriter() 362.1222 - .format("Reflection warning, %s:%d - call to %s can't be resolved.\n", 362.1223 - SOURCE_PATH.deref(), line, methodName); 362.1224 - } 362.1225 - } 362.1226 - 362.1227 - public Object eval() throws Exception{ 362.1228 - try 362.1229 - { 362.1230 - Object targetval = target.eval(); 362.1231 - Object[] argvals = new Object[args.count()]; 362.1232 - for(int i = 0; i < args.count(); i++) 362.1233 - argvals[i] = ((Expr) args.nth(i)).eval(); 362.1234 - if(method != null) 362.1235 - { 362.1236 - LinkedList ms = new LinkedList(); 362.1237 - ms.add(method); 362.1238 - return Reflector.invokeMatchingMethod(methodName, ms, targetval, argvals); 362.1239 - } 362.1240 - return Reflector.invokeInstanceMethod(targetval, methodName, argvals); 362.1241 - } 362.1242 - catch(Throwable e) 362.1243 - { 362.1244 - if(!(e instanceof CompilerException)) 362.1245 - throw new CompilerException(source, line, e); 362.1246 - else 362.1247 - throw (CompilerException) e; 362.1248 - } 362.1249 - } 362.1250 - 362.1251 - public boolean canEmitPrimitive(){ 362.1252 - return method != null && Util.isPrimitive(method.getReturnType()); 362.1253 - } 362.1254 - 362.1255 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1256 - gen.visitLineNumber(line, gen.mark()); 362.1257 - if(method != null) 362.1258 - { 362.1259 - Type type = Type.getType(method.getDeclaringClass()); 362.1260 - target.emit(C.EXPRESSION, objx, gen); 362.1261 - //if(!method.getDeclaringClass().isInterface()) 362.1262 - gen.checkCast(type); 362.1263 - MethodExpr.emitTypedArgs(objx, gen, method.getParameterTypes(), args); 362.1264 - if(context == C.RETURN) 362.1265 - { 362.1266 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.1267 - method.emitClearLocals(gen); 362.1268 - } 362.1269 - Method m = new Method(methodName, Type.getReturnType(method), Type.getArgumentTypes(method)); 362.1270 - if(method.getDeclaringClass().isInterface()) 362.1271 - gen.invokeInterface(type, m); 362.1272 - else 362.1273 - gen.invokeVirtual(type, m); 362.1274 - } 362.1275 - else 362.1276 - throw new UnsupportedOperationException("Unboxed emit of unknown member"); 362.1277 - } 362.1278 - 362.1279 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1280 - gen.visitLineNumber(line, gen.mark()); 362.1281 - if(method != null) 362.1282 - { 362.1283 - Type type = Type.getType(method.getDeclaringClass()); 362.1284 - target.emit(C.EXPRESSION, objx, gen); 362.1285 - //if(!method.getDeclaringClass().isInterface()) 362.1286 - gen.checkCast(type); 362.1287 - MethodExpr.emitTypedArgs(objx, gen, method.getParameterTypes(), args); 362.1288 - if(context == C.RETURN) 362.1289 - { 362.1290 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.1291 - method.emitClearLocals(gen); 362.1292 - } 362.1293 - Method m = new Method(methodName, Type.getReturnType(method), Type.getArgumentTypes(method)); 362.1294 - if(method.getDeclaringClass().isInterface()) 362.1295 - gen.invokeInterface(type, m); 362.1296 - else 362.1297 - gen.invokeVirtual(type, m); 362.1298 - //if(context != C.STATEMENT || method.getReturnType() == Void.TYPE) 362.1299 - HostExpr.emitBoxReturn(objx, gen, method.getReturnType()); 362.1300 - } 362.1301 - else 362.1302 - { 362.1303 - target.emit(C.EXPRESSION, objx, gen); 362.1304 - gen.push(methodName); 362.1305 - emitArgsAsArray(args, objx, gen); 362.1306 - if(context == C.RETURN) 362.1307 - { 362.1308 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.1309 - method.emitClearLocals(gen); 362.1310 - } 362.1311 - gen.invokeStatic(REFLECTOR_TYPE, invokeInstanceMethodMethod); 362.1312 - } 362.1313 - if(context == C.STATEMENT) 362.1314 - gen.pop(); 362.1315 - } 362.1316 - 362.1317 - public boolean hasJavaClass(){ 362.1318 - return method != null || tag != null; 362.1319 - } 362.1320 - 362.1321 - public Class getJavaClass() throws Exception{ 362.1322 - return tag != null ? HostExpr.tagToClass(tag) : method.getReturnType(); 362.1323 - } 362.1324 -} 362.1325 - 362.1326 - 362.1327 -static class StaticMethodExpr extends MethodExpr{ 362.1328 - //final String className; 362.1329 - public final Class c; 362.1330 - public final String methodName; 362.1331 - public final IPersistentVector args; 362.1332 - public final String source; 362.1333 - public final int line; 362.1334 - public final java.lang.reflect.Method method; 362.1335 - public final Symbol tag; 362.1336 - final static Method forNameMethod = Method.getMethod("Class forName(String)"); 362.1337 - final static Method invokeStaticMethodMethod = 362.1338 - Method.getMethod("Object invokeStaticMethod(Class,String,Object[])"); 362.1339 - 362.1340 - 362.1341 - public StaticMethodExpr(String source, int line, Symbol tag, Class c, String methodName, IPersistentVector args) 362.1342 - throws Exception{ 362.1343 - this.c = c; 362.1344 - this.methodName = methodName; 362.1345 - this.args = args; 362.1346 - this.source = source; 362.1347 - this.line = line; 362.1348 - this.tag = tag; 362.1349 - 362.1350 - List methods = Reflector.getMethods(c, args.count(), methodName, true); 362.1351 - if(methods.isEmpty()) 362.1352 - throw new IllegalArgumentException("No matching method: " + methodName); 362.1353 - 362.1354 - int methodidx = 0; 362.1355 - if(methods.size() > 1) 362.1356 - { 362.1357 - ArrayList<Class[]> params = new ArrayList(); 362.1358 - ArrayList<Class> rets = new ArrayList(); 362.1359 - for(int i = 0; i < methods.size(); i++) 362.1360 - { 362.1361 - java.lang.reflect.Method m = (java.lang.reflect.Method) methods.get(i); 362.1362 - params.add(m.getParameterTypes()); 362.1363 - rets.add(m.getReturnType()); 362.1364 - } 362.1365 - methodidx = getMatchingParams(methodName, params, args, rets); 362.1366 - } 362.1367 - method = (java.lang.reflect.Method) (methodidx >= 0 ? methods.get(methodidx) : null); 362.1368 - if(method == null && RT.booleanCast(RT.WARN_ON_REFLECTION.deref())) 362.1369 - { 362.1370 - RT.errPrintWriter() 362.1371 - .format("Reflection warning, %s:%d - call to %s can't be resolved.\n", 362.1372 - SOURCE_PATH.deref(), line, methodName); 362.1373 - } 362.1374 - } 362.1375 - 362.1376 - public Object eval() throws Exception{ 362.1377 - try 362.1378 - { 362.1379 - Object[] argvals = new Object[args.count()]; 362.1380 - for(int i = 0; i < args.count(); i++) 362.1381 - argvals[i] = ((Expr) args.nth(i)).eval(); 362.1382 - if(method != null) 362.1383 - { 362.1384 - LinkedList ms = new LinkedList(); 362.1385 - ms.add(method); 362.1386 - return Reflector.invokeMatchingMethod(methodName, ms, null, argvals); 362.1387 - } 362.1388 - return Reflector.invokeStaticMethod(c, methodName, argvals); 362.1389 - } 362.1390 - catch(Throwable e) 362.1391 - { 362.1392 - if(!(e instanceof CompilerException)) 362.1393 - throw new CompilerException(source, line, e); 362.1394 - else 362.1395 - throw (CompilerException) e; 362.1396 - } 362.1397 - } 362.1398 - 362.1399 - public boolean canEmitPrimitive(){ 362.1400 - return method != null && Util.isPrimitive(method.getReturnType()); 362.1401 - } 362.1402 - 362.1403 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1404 - gen.visitLineNumber(line, gen.mark()); 362.1405 - if(method != null) 362.1406 - { 362.1407 - MethodExpr.emitTypedArgs(objx, gen, method.getParameterTypes(), args); 362.1408 - //Type type = Type.getObjectType(className.replace('.', '/')); 362.1409 - if(context == C.RETURN) 362.1410 - { 362.1411 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.1412 - method.emitClearLocals(gen); 362.1413 - } 362.1414 - Type type = Type.getType(c); 362.1415 - Method m = new Method(methodName, Type.getReturnType(method), Type.getArgumentTypes(method)); 362.1416 - gen.invokeStatic(type, m); 362.1417 - } 362.1418 - else 362.1419 - throw new UnsupportedOperationException("Unboxed emit of unknown member"); 362.1420 - } 362.1421 - 362.1422 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1423 - gen.visitLineNumber(line, gen.mark()); 362.1424 - if(method != null) 362.1425 - { 362.1426 - MethodExpr.emitTypedArgs(objx, gen, method.getParameterTypes(), args); 362.1427 - //Type type = Type.getObjectType(className.replace('.', '/')); 362.1428 - if(context == C.RETURN) 362.1429 - { 362.1430 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.1431 - method.emitClearLocals(gen); 362.1432 - } 362.1433 - Type type = Type.getType(c); 362.1434 - Method m = new Method(methodName, Type.getReturnType(method), Type.getArgumentTypes(method)); 362.1435 - gen.invokeStatic(type, m); 362.1436 - //if(context != C.STATEMENT || method.getReturnType() == Void.TYPE) 362.1437 - HostExpr.emitBoxReturn(objx, gen, method.getReturnType()); 362.1438 - } 362.1439 - else 362.1440 - { 362.1441 - gen.push(c.getName()); 362.1442 - gen.invokeStatic(CLASS_TYPE, forNameMethod); 362.1443 - gen.push(methodName); 362.1444 - emitArgsAsArray(args, objx, gen); 362.1445 - if(context == C.RETURN) 362.1446 - { 362.1447 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.1448 - method.emitClearLocals(gen); 362.1449 - } 362.1450 - gen.invokeStatic(REFLECTOR_TYPE, invokeStaticMethodMethod); 362.1451 - } 362.1452 - if(context == C.STATEMENT) 362.1453 - gen.pop(); 362.1454 - } 362.1455 - 362.1456 - public boolean hasJavaClass(){ 362.1457 - return method != null || tag != null; 362.1458 - } 362.1459 - 362.1460 - public Class getJavaClass() throws Exception{ 362.1461 - return tag != null ? HostExpr.tagToClass(tag) : method.getReturnType(); 362.1462 - } 362.1463 -} 362.1464 - 362.1465 -static class UnresolvedVarExpr implements Expr{ 362.1466 - public final Symbol symbol; 362.1467 - 362.1468 - public UnresolvedVarExpr(Symbol symbol){ 362.1469 - this.symbol = symbol; 362.1470 - } 362.1471 - 362.1472 - public boolean hasJavaClass(){ 362.1473 - return false; 362.1474 - } 362.1475 - 362.1476 - public Class getJavaClass() throws Exception{ 362.1477 - throw new IllegalArgumentException( 362.1478 - "UnresolvedVarExpr has no Java class"); 362.1479 - } 362.1480 - 362.1481 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1482 - } 362.1483 - 362.1484 - public Object eval() throws Exception{ 362.1485 - throw new IllegalArgumentException( 362.1486 - "UnresolvedVarExpr cannot be evalled"); 362.1487 - } 362.1488 -} 362.1489 - 362.1490 -static class ConstantExpr extends LiteralExpr{ 362.1491 - //stuff quoted vals in classloader at compile time, pull out at runtime 362.1492 - //this won't work for static compilation... 362.1493 - public final Object v; 362.1494 - public final int id; 362.1495 - 362.1496 - public ConstantExpr(Object v){ 362.1497 - this.v = v; 362.1498 - this.id = registerConstant(v); 362.1499 -// this.id = RT.nextID(); 362.1500 -// DynamicClassLoader loader = (DynamicClassLoader) LOADER.get(); 362.1501 -// loader.registerQuotedVal(id, v); 362.1502 - } 362.1503 - 362.1504 - Object val(){ 362.1505 - return v; 362.1506 - } 362.1507 - 362.1508 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1509 - objx.emitConstant(gen, id); 362.1510 - if(context == C.STATEMENT) 362.1511 - { 362.1512 - gen.pop(); 362.1513 -// gen.loadThis(); 362.1514 -// gen.invokeVirtual(OBJECT_TYPE, getClassMethod); 362.1515 -// gen.invokeVirtual(CLASS_TYPE, getClassLoaderMethod); 362.1516 -// gen.checkCast(DYNAMIC_CLASSLOADER_TYPE); 362.1517 -// gen.push(id); 362.1518 -// gen.invokeVirtual(DYNAMIC_CLASSLOADER_TYPE, getQuotedValMethod); 362.1519 - } 362.1520 - } 362.1521 - 362.1522 - public boolean hasJavaClass(){ 362.1523 - return Modifier.isPublic(v.getClass().getModifiers()); 362.1524 - //return false; 362.1525 - } 362.1526 - 362.1527 - public Class getJavaClass() throws Exception{ 362.1528 - return v.getClass(); 362.1529 - //throw new IllegalArgumentException("Has no Java class"); 362.1530 - } 362.1531 - 362.1532 - static class Parser implements IParser{ 362.1533 - public Expr parse(C context, Object form){ 362.1534 - Object v = RT.second(form); 362.1535 - 362.1536 - if(v == null) 362.1537 - return NIL_EXPR; 362.1538 -// Class fclass = v.getClass(); 362.1539 -// if(fclass == Keyword.class) 362.1540 -// return registerKeyword((Keyword) v); 362.1541 -// else if(v instanceof Num) 362.1542 -// return new NumExpr((Num) v); 362.1543 -// else if(fclass == String.class) 362.1544 -// return new StringExpr((String) v); 362.1545 -// else if(fclass == Character.class) 362.1546 -// return new CharExpr((Character) v); 362.1547 -// else if(v instanceof IPersistentCollection && ((IPersistentCollection) v).count() == 0) 362.1548 -// return new EmptyExpr(v); 362.1549 - else 362.1550 - return new ConstantExpr(v); 362.1551 - } 362.1552 - } 362.1553 -} 362.1554 - 362.1555 -static class NilExpr extends LiteralExpr{ 362.1556 - Object val(){ 362.1557 - return null; 362.1558 - } 362.1559 - 362.1560 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1561 - gen.visitInsn(Opcodes.ACONST_NULL); 362.1562 - if(context == C.STATEMENT) 362.1563 - gen.pop(); 362.1564 - } 362.1565 - 362.1566 - public boolean hasJavaClass(){ 362.1567 - return true; 362.1568 - } 362.1569 - 362.1570 - public Class getJavaClass() throws Exception{ 362.1571 - return null; 362.1572 - } 362.1573 -} 362.1574 - 362.1575 -final static NilExpr NIL_EXPR = new NilExpr(); 362.1576 - 362.1577 -static class BooleanExpr extends LiteralExpr{ 362.1578 - public final boolean val; 362.1579 - 362.1580 - 362.1581 - public BooleanExpr(boolean val){ 362.1582 - this.val = val; 362.1583 - } 362.1584 - 362.1585 - Object val(){ 362.1586 - return val ? RT.T : RT.F; 362.1587 - } 362.1588 - 362.1589 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1590 - if(val) 362.1591 - gen.getStatic(BOOLEAN_OBJECT_TYPE, "TRUE", BOOLEAN_OBJECT_TYPE); 362.1592 - else 362.1593 - gen.getStatic(BOOLEAN_OBJECT_TYPE, "FALSE", BOOLEAN_OBJECT_TYPE); 362.1594 - if(context == C.STATEMENT) 362.1595 - { 362.1596 - gen.pop(); 362.1597 - } 362.1598 - } 362.1599 - 362.1600 - public boolean hasJavaClass(){ 362.1601 - return true; 362.1602 - } 362.1603 - 362.1604 - public Class getJavaClass() throws Exception{ 362.1605 - return Boolean.class; 362.1606 - } 362.1607 -} 362.1608 - 362.1609 -final static BooleanExpr TRUE_EXPR = new BooleanExpr(true); 362.1610 -final static BooleanExpr FALSE_EXPR = new BooleanExpr(false); 362.1611 - 362.1612 -static class StringExpr extends LiteralExpr{ 362.1613 - public final String str; 362.1614 - 362.1615 - public StringExpr(String str){ 362.1616 - this.str = str; 362.1617 - } 362.1618 - 362.1619 - Object val(){ 362.1620 - return str; 362.1621 - } 362.1622 - 362.1623 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1624 - if(context != C.STATEMENT) 362.1625 - gen.push(str); 362.1626 - } 362.1627 - 362.1628 - public boolean hasJavaClass(){ 362.1629 - return true; 362.1630 - } 362.1631 - 362.1632 - public Class getJavaClass() throws Exception{ 362.1633 - return String.class; 362.1634 - } 362.1635 -} 362.1636 - 362.1637 - 362.1638 -static class MonitorEnterExpr extends UntypedExpr{ 362.1639 - final Expr target; 362.1640 - 362.1641 - public MonitorEnterExpr(Expr target){ 362.1642 - this.target = target; 362.1643 - } 362.1644 - 362.1645 - public Object eval() throws Exception{ 362.1646 - throw new UnsupportedOperationException("Can't eval monitor-enter"); 362.1647 - } 362.1648 - 362.1649 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1650 - target.emit(C.EXPRESSION, objx, gen); 362.1651 - gen.monitorEnter(); 362.1652 - NIL_EXPR.emit(context, objx, gen); 362.1653 - } 362.1654 - 362.1655 - static class Parser implements IParser{ 362.1656 - public Expr parse(C context, Object form) throws Exception{ 362.1657 - return new MonitorEnterExpr(analyze(C.EXPRESSION, RT.second(form))); 362.1658 - } 362.1659 - } 362.1660 -} 362.1661 - 362.1662 -static class MonitorExitExpr extends UntypedExpr{ 362.1663 - final Expr target; 362.1664 - 362.1665 - public MonitorExitExpr(Expr target){ 362.1666 - this.target = target; 362.1667 - } 362.1668 - 362.1669 - public Object eval() throws Exception{ 362.1670 - throw new UnsupportedOperationException("Can't eval monitor-exit"); 362.1671 - } 362.1672 - 362.1673 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1674 - target.emit(C.EXPRESSION, objx, gen); 362.1675 - gen.monitorExit(); 362.1676 - NIL_EXPR.emit(context, objx, gen); 362.1677 - } 362.1678 - 362.1679 - static class Parser implements IParser{ 362.1680 - public Expr parse(C context, Object form) throws Exception{ 362.1681 - return new MonitorExitExpr(analyze(C.EXPRESSION, RT.second(form))); 362.1682 - } 362.1683 - } 362.1684 - 362.1685 -} 362.1686 - 362.1687 -public static class TryExpr implements Expr{ 362.1688 - public final Expr tryExpr; 362.1689 - public final Expr finallyExpr; 362.1690 - public final PersistentVector catchExprs; 362.1691 - public final int retLocal; 362.1692 - public final int finallyLocal; 362.1693 - 362.1694 - public static class CatchClause{ 362.1695 - //final String className; 362.1696 - public final Class c; 362.1697 - public final LocalBinding lb; 362.1698 - public final Expr handler; 362.1699 - Label label; 362.1700 - Label endLabel; 362.1701 - 362.1702 - 362.1703 - public CatchClause(Class c, LocalBinding lb, Expr handler){ 362.1704 - this.c = c; 362.1705 - this.lb = lb; 362.1706 - this.handler = handler; 362.1707 - } 362.1708 - } 362.1709 - 362.1710 - public TryExpr(Expr tryExpr, PersistentVector catchExprs, Expr finallyExpr, int retLocal, int finallyLocal){ 362.1711 - this.tryExpr = tryExpr; 362.1712 - this.catchExprs = catchExprs; 362.1713 - this.finallyExpr = finallyExpr; 362.1714 - this.retLocal = retLocal; 362.1715 - this.finallyLocal = finallyLocal; 362.1716 - } 362.1717 - 362.1718 - public Object eval() throws Exception{ 362.1719 - throw new UnsupportedOperationException("Can't eval try"); 362.1720 - } 362.1721 - 362.1722 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1723 - Label startTry = gen.newLabel(); 362.1724 - Label endTry = gen.newLabel(); 362.1725 - Label end = gen.newLabel(); 362.1726 - Label ret = gen.newLabel(); 362.1727 - Label finallyLabel = gen.newLabel(); 362.1728 - for(int i = 0; i < catchExprs.count(); i++) 362.1729 - { 362.1730 - CatchClause clause = (CatchClause) catchExprs.nth(i); 362.1731 - clause.label = gen.newLabel(); 362.1732 - clause.endLabel = gen.newLabel(); 362.1733 - } 362.1734 - 362.1735 - gen.mark(startTry); 362.1736 - tryExpr.emit(context, objx, gen); 362.1737 - if(context != C.STATEMENT) 362.1738 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), retLocal); 362.1739 - gen.mark(endTry); 362.1740 - if(finallyExpr != null) 362.1741 - finallyExpr.emit(C.STATEMENT, objx, gen); 362.1742 - gen.goTo(ret); 362.1743 - 362.1744 - for(int i = 0; i < catchExprs.count(); i++) 362.1745 - { 362.1746 - CatchClause clause = (CatchClause) catchExprs.nth(i); 362.1747 - gen.mark(clause.label); 362.1748 - //exception should be on stack 362.1749 - //put in clause local 362.1750 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), clause.lb.idx); 362.1751 - clause.handler.emit(context, objx, gen); 362.1752 - if(context != C.STATEMENT) 362.1753 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), retLocal); 362.1754 - gen.mark(clause.endLabel); 362.1755 - 362.1756 - if(finallyExpr != null) 362.1757 - finallyExpr.emit(C.STATEMENT, objx, gen); 362.1758 - gen.goTo(ret); 362.1759 - } 362.1760 - if(finallyExpr != null) 362.1761 - { 362.1762 - gen.mark(finallyLabel); 362.1763 - //exception should be on stack 362.1764 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), finallyLocal); 362.1765 - finallyExpr.emit(C.STATEMENT, objx, gen); 362.1766 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ILOAD), finallyLocal); 362.1767 - gen.throwException(); 362.1768 - } 362.1769 - gen.mark(ret); 362.1770 - if(context != C.STATEMENT) 362.1771 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ILOAD), retLocal); 362.1772 - gen.mark(end); 362.1773 - for(int i = 0; i < catchExprs.count(); i++) 362.1774 - { 362.1775 - CatchClause clause = (CatchClause) catchExprs.nth(i); 362.1776 - gen.visitTryCatchBlock(startTry, endTry, clause.label, clause.c.getName().replace('.', '/')); 362.1777 - } 362.1778 - if(finallyExpr != null) 362.1779 - { 362.1780 - gen.visitTryCatchBlock(startTry, endTry, finallyLabel, null); 362.1781 - for(int i = 0; i < catchExprs.count(); i++) 362.1782 - { 362.1783 - CatchClause clause = (CatchClause) catchExprs.nth(i); 362.1784 - gen.visitTryCatchBlock(clause.label, clause.endLabel, finallyLabel, null); 362.1785 - } 362.1786 - } 362.1787 - for(int i = 0; i < catchExprs.count(); i++) 362.1788 - { 362.1789 - CatchClause clause = (CatchClause) catchExprs.nth(i); 362.1790 - gen.visitLocalVariable(clause.lb.name, "Ljava/lang/Object;", null, clause.label, clause.endLabel, 362.1791 - clause.lb.idx); 362.1792 - } 362.1793 - } 362.1794 - 362.1795 - public boolean hasJavaClass() throws Exception{ 362.1796 - return tryExpr.hasJavaClass(); 362.1797 - } 362.1798 - 362.1799 - public Class getJavaClass() throws Exception{ 362.1800 - return tryExpr.getJavaClass(); 362.1801 - } 362.1802 - 362.1803 - static class Parser implements IParser{ 362.1804 - 362.1805 - public Expr parse(C context, Object frm) throws Exception{ 362.1806 - ISeq form = (ISeq) frm; 362.1807 -// if(context == C.EVAL || context == C.EXPRESSION) 362.1808 - if(context != C.RETURN) 362.1809 - return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form))); 362.1810 - 362.1811 - //(try try-expr* catch-expr* finally-expr?) 362.1812 - //catch-expr: (catch class sym expr*) 362.1813 - //finally-expr: (finally expr*) 362.1814 - 362.1815 - PersistentVector body = PersistentVector.EMPTY; 362.1816 - PersistentVector catches = PersistentVector.EMPTY; 362.1817 - Expr bodyExpr = null; 362.1818 - Expr finallyExpr = null; 362.1819 - boolean caught = false; 362.1820 - 362.1821 - int retLocal = getAndIncLocalNum(); 362.1822 - int finallyLocal = getAndIncLocalNum(); 362.1823 - for(ISeq fs = form.next(); fs != null; fs = fs.next()) 362.1824 - { 362.1825 - Object f = fs.first(); 362.1826 - Object op = (f instanceof ISeq) ? ((ISeq) f).first() : null; 362.1827 - if(!Util.equals(op, CATCH) && !Util.equals(op, FINALLY)) 362.1828 - { 362.1829 - if(caught) 362.1830 - throw new Exception("Only catch or finally clause can follow catch in try expression"); 362.1831 - body = body.cons(f); 362.1832 - } 362.1833 - else 362.1834 - { 362.1835 - if(bodyExpr == null) 362.1836 - bodyExpr = (new BodyExpr.Parser()).parse(context, RT.seq(body)); 362.1837 - if(Util.equals(op, CATCH)) 362.1838 - { 362.1839 - Class c = HostExpr.maybeClass(RT.second(f), false); 362.1840 - if(c == null) 362.1841 - throw new IllegalArgumentException("Unable to resolve classname: " + RT.second(f)); 362.1842 - if(!(RT.third(f) instanceof Symbol)) 362.1843 - throw new IllegalArgumentException( 362.1844 - "Bad binding form, expected symbol, got: " + RT.third(f)); 362.1845 - Symbol sym = (Symbol) RT.third(f); 362.1846 - if(sym.getNamespace() != null) 362.1847 - throw new Exception("Can't bind qualified name:" + sym); 362.1848 - 362.1849 - IPersistentMap dynamicBindings = RT.map(LOCAL_ENV, LOCAL_ENV.deref(), 362.1850 - NEXT_LOCAL_NUM, NEXT_LOCAL_NUM.deref(), 362.1851 - IN_CATCH_FINALLY, RT.T); 362.1852 - try 362.1853 - { 362.1854 - Var.pushThreadBindings(dynamicBindings); 362.1855 - LocalBinding lb = registerLocal(sym, 362.1856 - (Symbol) (RT.second(f) instanceof Symbol ? RT.second(f) 362.1857 - : null), 362.1858 - null,false); 362.1859 - Expr handler = (new BodyExpr.Parser()).parse(context, RT.next(RT.next(RT.next(f)))); 362.1860 - catches = catches.cons(new CatchClause(c, lb, handler)); 362.1861 - } 362.1862 - finally 362.1863 - { 362.1864 - Var.popThreadBindings(); 362.1865 - } 362.1866 - caught = true; 362.1867 - } 362.1868 - else //finally 362.1869 - { 362.1870 - if(fs.next() != null) 362.1871 - throw new Exception("finally clause must be last in try expression"); 362.1872 - try 362.1873 - { 362.1874 - Var.pushThreadBindings(RT.map(IN_CATCH_FINALLY, RT.T)); 362.1875 - finallyExpr = (new BodyExpr.Parser()).parse(C.STATEMENT, RT.next(f)); 362.1876 - } 362.1877 - finally 362.1878 - { 362.1879 - Var.popThreadBindings(); 362.1880 - } 362.1881 - } 362.1882 - } 362.1883 - } 362.1884 - if(bodyExpr == null) 362.1885 - bodyExpr = (new BodyExpr.Parser()).parse(context, RT.seq(body)); 362.1886 - 362.1887 - return new TryExpr(bodyExpr, catches, finallyExpr, retLocal, 362.1888 - finallyLocal); 362.1889 - } 362.1890 - } 362.1891 -} 362.1892 - 362.1893 -//static class TryFinallyExpr implements Expr{ 362.1894 -// final Expr tryExpr; 362.1895 -// final Expr finallyExpr; 362.1896 -// 362.1897 -// 362.1898 -// public TryFinallyExpr(Expr tryExpr, Expr finallyExpr){ 362.1899 -// this.tryExpr = tryExpr; 362.1900 -// this.finallyExpr = finallyExpr; 362.1901 -// } 362.1902 -// 362.1903 -// public Object eval() throws Exception{ 362.1904 -// throw new UnsupportedOperationException("Can't eval try"); 362.1905 -// } 362.1906 -// 362.1907 -// public void emit(C context, FnExpr fn, GeneratorAdapter gen){ 362.1908 -// Label startTry = gen.newLabel(); 362.1909 -// Label endTry = gen.newLabel(); 362.1910 -// Label end = gen.newLabel(); 362.1911 -// Label finallyLabel = gen.newLabel(); 362.1912 -// gen.visitTryCatchBlock(startTry, endTry, finallyLabel, null); 362.1913 -// gen.mark(startTry); 362.1914 -// tryExpr.emit(context, fn, gen); 362.1915 -// gen.mark(endTry); 362.1916 -// finallyExpr.emit(C.STATEMENT, fn, gen); 362.1917 -// gen.goTo(end); 362.1918 -// gen.mark(finallyLabel); 362.1919 -// //exception should be on stack 362.1920 -// finallyExpr.emit(C.STATEMENT, fn, gen); 362.1921 -// gen.throwException(); 362.1922 -// gen.mark(end); 362.1923 -// } 362.1924 -// 362.1925 -// public boolean hasJavaClass() throws Exception{ 362.1926 -// return tryExpr.hasJavaClass(); 362.1927 -// } 362.1928 -// 362.1929 -// public Class getJavaClass() throws Exception{ 362.1930 -// return tryExpr.getJavaClass(); 362.1931 -// } 362.1932 -// 362.1933 -// static class Parser implements IParser{ 362.1934 -// public Expr parse(C context, Object frm) throws Exception{ 362.1935 -// ISeq form = (ISeq) frm; 362.1936 -// //(try-finally try-expr finally-expr) 362.1937 -// if(form.count() != 3) 362.1938 -// throw new IllegalArgumentException( 362.1939 -// "Wrong number of arguments, expecting: (try-finally try-expr finally-expr) "); 362.1940 -// 362.1941 -// if(context == C.EVAL || context == C.EXPRESSION) 362.1942 -// return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form))); 362.1943 -// 362.1944 -// return new TryFinallyExpr(analyze(context, RT.second(form)), 362.1945 -// analyze(C.STATEMENT, RT.third(form))); 362.1946 -// } 362.1947 -// } 362.1948 -//} 362.1949 - 362.1950 -static class ThrowExpr extends UntypedExpr{ 362.1951 - public final Expr excExpr; 362.1952 - 362.1953 - public ThrowExpr(Expr excExpr){ 362.1954 - this.excExpr = excExpr; 362.1955 - } 362.1956 - 362.1957 - 362.1958 - public Object eval() throws Exception{ 362.1959 - throw new Exception("Can't eval throw"); 362.1960 - } 362.1961 - 362.1962 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.1963 - excExpr.emit(C.EXPRESSION, objx, gen); 362.1964 - gen.checkCast(THROWABLE_TYPE); 362.1965 - gen.throwException(); 362.1966 - } 362.1967 - 362.1968 - static class Parser implements IParser{ 362.1969 - public Expr parse(C context, Object form) throws Exception{ 362.1970 - if(context == C.EVAL) 362.1971 - return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form))); 362.1972 - return new ThrowExpr(analyze(C.EXPRESSION, RT.second(form))); 362.1973 - } 362.1974 - } 362.1975 -} 362.1976 - 362.1977 - 362.1978 -static public boolean subsumes(Class[] c1, Class[] c2){ 362.1979 - //presumes matching lengths 362.1980 - Boolean better = false; 362.1981 - for(int i = 0; i < c1.length; i++) 362.1982 - { 362.1983 - if(c1[i] != c2[i])// || c2[i].isPrimitive() && c1[i] == Object.class)) 362.1984 - { 362.1985 - if(!c1[i].isPrimitive() && c2[i].isPrimitive() 362.1986 - //|| Number.class.isAssignableFrom(c1[i]) && c2[i].isPrimitive() 362.1987 - || 362.1988 - c2[i].isAssignableFrom(c1[i])) 362.1989 - better = true; 362.1990 - else 362.1991 - return false; 362.1992 - } 362.1993 - } 362.1994 - return better; 362.1995 -} 362.1996 - 362.1997 -static int getMatchingParams(String methodName, ArrayList<Class[]> paramlists, IPersistentVector argexprs, 362.1998 - List<Class> rets) 362.1999 - throws Exception{ 362.2000 - //presumes matching lengths 362.2001 - int matchIdx = -1; 362.2002 - boolean tied = false; 362.2003 - boolean foundExact = false; 362.2004 - for(int i = 0; i < paramlists.size(); i++) 362.2005 - { 362.2006 - boolean match = true; 362.2007 - ISeq aseq = argexprs.seq(); 362.2008 - int exact = 0; 362.2009 - for(int p = 0; match && p < argexprs.count() && aseq != null; ++p, aseq = aseq.next()) 362.2010 - { 362.2011 - Expr arg = (Expr) aseq.first(); 362.2012 - Class aclass = arg.hasJavaClass() ? arg.getJavaClass() : Object.class; 362.2013 - Class pclass = paramlists.get(i)[p]; 362.2014 - if(arg.hasJavaClass() && aclass == pclass) 362.2015 - exact++; 362.2016 - else 362.2017 - match = Reflector.paramArgTypeMatch(pclass, aclass); 362.2018 - } 362.2019 - if(exact == argexprs.count()) 362.2020 - { 362.2021 - if(!foundExact || matchIdx == -1 || rets.get(matchIdx).isAssignableFrom(rets.get(i))) 362.2022 - matchIdx = i; 362.2023 - foundExact = true; 362.2024 - } 362.2025 - else if(match && !foundExact) 362.2026 - { 362.2027 - if(matchIdx == -1) 362.2028 - matchIdx = i; 362.2029 - else 362.2030 - { 362.2031 - if(subsumes(paramlists.get(i), paramlists.get(matchIdx))) 362.2032 - { 362.2033 - matchIdx = i; 362.2034 - tied = false; 362.2035 - } 362.2036 - else if(Arrays.equals(paramlists.get(matchIdx), paramlists.get(i))) 362.2037 - { 362.2038 - if(rets.get(matchIdx).isAssignableFrom(rets.get(i))) 362.2039 - matchIdx = i; 362.2040 - } 362.2041 - else if(!(subsumes(paramlists.get(matchIdx), paramlists.get(i)))) 362.2042 - tied = true; 362.2043 - } 362.2044 - } 362.2045 - } 362.2046 - if(tied) 362.2047 - throw new IllegalArgumentException("More than one matching method found: " + methodName); 362.2048 - 362.2049 - return matchIdx; 362.2050 -} 362.2051 - 362.2052 -public static class NewExpr implements Expr{ 362.2053 - public final IPersistentVector args; 362.2054 - public final Constructor ctor; 362.2055 - public final Class c; 362.2056 - final static Method invokeConstructorMethod = 362.2057 - Method.getMethod("Object invokeConstructor(Class,Object[])"); 362.2058 -// final static Method forNameMethod = Method.getMethod("Class classForName(String)"); 362.2059 - final static Method forNameMethod = Method.getMethod("Class forName(String)"); 362.2060 - 362.2061 - 362.2062 - public NewExpr(Class c, IPersistentVector args, int line) throws Exception{ 362.2063 - this.args = args; 362.2064 - this.c = c; 362.2065 - Constructor[] allctors = c.getConstructors(); 362.2066 - ArrayList ctors = new ArrayList(); 362.2067 - ArrayList<Class[]> params = new ArrayList(); 362.2068 - ArrayList<Class> rets = new ArrayList(); 362.2069 - for(int i = 0; i < allctors.length; i++) 362.2070 - { 362.2071 - Constructor ctor = allctors[i]; 362.2072 - if(ctor.getParameterTypes().length == args.count()) 362.2073 - { 362.2074 - ctors.add(ctor); 362.2075 - params.add(ctor.getParameterTypes()); 362.2076 - rets.add(c); 362.2077 - } 362.2078 - } 362.2079 - if(ctors.isEmpty()) 362.2080 - throw new IllegalArgumentException("No matching ctor found for " + c); 362.2081 - 362.2082 - int ctoridx = 0; 362.2083 - if(ctors.size() > 1) 362.2084 - { 362.2085 - ctoridx = getMatchingParams(c.getName(), params, args, rets); 362.2086 - } 362.2087 - 362.2088 - this.ctor = ctoridx >= 0 ? (Constructor) ctors.get(ctoridx) : null; 362.2089 - if(ctor == null && RT.booleanCast(RT.WARN_ON_REFLECTION.deref())) 362.2090 - { 362.2091 - RT.errPrintWriter() 362.2092 - .format("Reflection warning, %s:%d - call to %s ctor can't be resolved.\n", 362.2093 - SOURCE_PATH.deref(), line, c.getName()); 362.2094 - } 362.2095 - } 362.2096 - 362.2097 - public Object eval() throws Exception{ 362.2098 - Object[] argvals = new Object[args.count()]; 362.2099 - for(int i = 0; i < args.count(); i++) 362.2100 - argvals[i] = ((Expr) args.nth(i)).eval(); 362.2101 - if(this.ctor != null) 362.2102 - { 362.2103 - return ctor.newInstance(Reflector.boxArgs(ctor.getParameterTypes(), argvals)); 362.2104 - } 362.2105 - return Reflector.invokeConstructor(c, argvals); 362.2106 - } 362.2107 - 362.2108 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2109 - if(this.ctor != null) 362.2110 - { 362.2111 - Type type = getType(c); 362.2112 - gen.newInstance(type); 362.2113 - gen.dup(); 362.2114 - MethodExpr.emitTypedArgs(objx, gen, ctor.getParameterTypes(), args); 362.2115 - if(context == C.RETURN) 362.2116 - { 362.2117 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.2118 - method.emitClearLocals(gen); 362.2119 - } 362.2120 - gen.invokeConstructor(type, new Method("<init>", Type.getConstructorDescriptor(ctor))); 362.2121 - } 362.2122 - else 362.2123 - { 362.2124 - gen.push(destubClassName(c.getName())); 362.2125 - gen.invokeStatic(CLASS_TYPE, forNameMethod); 362.2126 - MethodExpr.emitArgsAsArray(args, objx, gen); 362.2127 - if(context == C.RETURN) 362.2128 - { 362.2129 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.2130 - method.emitClearLocals(gen); 362.2131 - } 362.2132 - gen.invokeStatic(REFLECTOR_TYPE, invokeConstructorMethod); 362.2133 - } 362.2134 - if(context == C.STATEMENT) 362.2135 - gen.pop(); 362.2136 - } 362.2137 - 362.2138 - public boolean hasJavaClass(){ 362.2139 - return true; 362.2140 - } 362.2141 - 362.2142 - public Class getJavaClass() throws Exception{ 362.2143 - return c; 362.2144 - } 362.2145 - 362.2146 - static class Parser implements IParser{ 362.2147 - public Expr parse(C context, Object frm) throws Exception{ 362.2148 - int line = (Integer) LINE.deref(); 362.2149 - ISeq form = (ISeq) frm; 362.2150 - //(new Classname args...) 362.2151 - if(form.count() < 2) 362.2152 - throw new Exception("wrong number of arguments, expecting: (new Classname args...)"); 362.2153 - Class c = HostExpr.maybeClass(RT.second(form), false); 362.2154 - if(c == null) 362.2155 - throw new IllegalArgumentException("Unable to resolve classname: " + RT.second(form)); 362.2156 - PersistentVector args = PersistentVector.EMPTY; 362.2157 - for(ISeq s = RT.next(RT.next(form)); s != null; s = s.next()) 362.2158 - args = args.cons(analyze(context == C.EVAL ? context : C.EXPRESSION, s.first())); 362.2159 - return new NewExpr(c, args, line); 362.2160 - } 362.2161 - } 362.2162 - 362.2163 -} 362.2164 - 362.2165 -public static class MetaExpr implements Expr{ 362.2166 - public final Expr expr; 362.2167 - public final MapExpr meta; 362.2168 - final static Type IOBJ_TYPE = Type.getType(IObj.class); 362.2169 - final static Method withMetaMethod = Method.getMethod("clojure.lang.IObj withMeta(clojure.lang.IPersistentMap)"); 362.2170 - 362.2171 - 362.2172 - public MetaExpr(Expr expr, MapExpr meta){ 362.2173 - this.expr = expr; 362.2174 - this.meta = meta; 362.2175 - } 362.2176 - 362.2177 - public Object eval() throws Exception{ 362.2178 - return ((IObj) expr.eval()).withMeta((IPersistentMap) meta.eval()); 362.2179 - } 362.2180 - 362.2181 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2182 - expr.emit(C.EXPRESSION, objx, gen); 362.2183 - gen.checkCast(IOBJ_TYPE); 362.2184 - meta.emit(C.EXPRESSION, objx, gen); 362.2185 - gen.checkCast(IPERSISTENTMAP_TYPE); 362.2186 - gen.invokeInterface(IOBJ_TYPE, withMetaMethod); 362.2187 - if(context == C.STATEMENT) 362.2188 - { 362.2189 - gen.pop(); 362.2190 - } 362.2191 - } 362.2192 - 362.2193 - public boolean hasJavaClass() throws Exception{ 362.2194 - return expr.hasJavaClass(); 362.2195 - } 362.2196 - 362.2197 - public Class getJavaClass() throws Exception{ 362.2198 - return expr.getJavaClass(); 362.2199 - } 362.2200 -} 362.2201 - 362.2202 -public static class IfExpr implements Expr, MaybePrimitiveExpr{ 362.2203 - public final Expr testExpr; 362.2204 - public final Expr thenExpr; 362.2205 - public final Expr elseExpr; 362.2206 - public final int line; 362.2207 - 362.2208 - 362.2209 - public IfExpr(int line, Expr testExpr, Expr thenExpr, Expr elseExpr){ 362.2210 - this.testExpr = testExpr; 362.2211 - this.thenExpr = thenExpr; 362.2212 - this.elseExpr = elseExpr; 362.2213 - this.line = line; 362.2214 - } 362.2215 - 362.2216 - public Object eval() throws Exception{ 362.2217 - Object t = testExpr.eval(); 362.2218 - if(t != null && t != Boolean.FALSE) 362.2219 - return thenExpr.eval(); 362.2220 - return elseExpr.eval(); 362.2221 - } 362.2222 - 362.2223 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2224 - doEmit(context, objx, gen,false); 362.2225 - } 362.2226 - 362.2227 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2228 - doEmit(context, objx, gen, true); 362.2229 - } 362.2230 - 362.2231 - public void doEmit(C context, ObjExpr objx, GeneratorAdapter gen, boolean emitUnboxed){ 362.2232 - Label nullLabel = gen.newLabel(); 362.2233 - Label falseLabel = gen.newLabel(); 362.2234 - Label endLabel = gen.newLabel(); 362.2235 - 362.2236 - gen.visitLineNumber(line, gen.mark()); 362.2237 - 362.2238 - try 362.2239 - { 362.2240 - if(maybePrimitiveType(testExpr) == boolean.class) 362.2241 - { 362.2242 - ((MaybePrimitiveExpr) testExpr).emitUnboxed(C.EXPRESSION, objx, gen); 362.2243 - gen.ifZCmp(gen.EQ, falseLabel); 362.2244 - } 362.2245 - else 362.2246 - { 362.2247 - testExpr.emit(C.EXPRESSION, objx, gen); 362.2248 - gen.dup(); 362.2249 - gen.ifNull(nullLabel); 362.2250 - gen.getStatic(BOOLEAN_OBJECT_TYPE, "FALSE", BOOLEAN_OBJECT_TYPE); 362.2251 - gen.visitJumpInsn(IF_ACMPEQ, falseLabel); 362.2252 - } 362.2253 - } 362.2254 - catch(Exception e) 362.2255 - { 362.2256 - throw new RuntimeException(e); 362.2257 - } 362.2258 - if(emitUnboxed) 362.2259 - ((MaybePrimitiveExpr)thenExpr).emitUnboxed(context, objx, gen); 362.2260 - else 362.2261 - thenExpr.emit(context, objx, gen); 362.2262 - gen.goTo(endLabel); 362.2263 - gen.mark(nullLabel); 362.2264 - gen.pop(); 362.2265 - gen.mark(falseLabel); 362.2266 - if(emitUnboxed) 362.2267 - ((MaybePrimitiveExpr)elseExpr).emitUnboxed(context, objx, gen); 362.2268 - else 362.2269 - elseExpr.emit(context, objx, gen); 362.2270 - gen.mark(endLabel); 362.2271 - } 362.2272 - 362.2273 - public boolean hasJavaClass() throws Exception{ 362.2274 - return thenExpr.hasJavaClass() 362.2275 - && elseExpr.hasJavaClass() 362.2276 - && 362.2277 - (thenExpr.getJavaClass() == elseExpr.getJavaClass() 362.2278 - || (thenExpr.getJavaClass() == null && !elseExpr.getJavaClass().isPrimitive()) 362.2279 - || (elseExpr.getJavaClass() == null && !thenExpr.getJavaClass().isPrimitive())); 362.2280 - } 362.2281 - 362.2282 - public boolean canEmitPrimitive(){ 362.2283 - try 362.2284 - { 362.2285 - return thenExpr instanceof MaybePrimitiveExpr 362.2286 - && elseExpr instanceof MaybePrimitiveExpr 362.2287 - && thenExpr.getJavaClass() == elseExpr.getJavaClass() 362.2288 - && ((MaybePrimitiveExpr)thenExpr).canEmitPrimitive() 362.2289 - && ((MaybePrimitiveExpr)elseExpr).canEmitPrimitive(); 362.2290 - } 362.2291 - catch(Exception e) 362.2292 - { 362.2293 - return false; 362.2294 - } 362.2295 - } 362.2296 - 362.2297 - public Class getJavaClass() throws Exception{ 362.2298 - Class thenClass = thenExpr.getJavaClass(); 362.2299 - if(thenClass != null) 362.2300 - return thenClass; 362.2301 - return elseExpr.getJavaClass(); 362.2302 - } 362.2303 - 362.2304 - static class Parser implements IParser{ 362.2305 - public Expr parse(C context, Object frm) throws Exception{ 362.2306 - ISeq form = (ISeq) frm; 362.2307 - //(if test then) or (if test then else) 362.2308 - if(form.count() > 4) 362.2309 - throw new Exception("Too many arguments to if"); 362.2310 - else if(form.count() < 3) 362.2311 - throw new Exception("Too few arguments to if"); 362.2312 - PathNode branch = new PathNode(PATHTYPE.BRANCH, (PathNode) CLEAR_PATH.get()); 362.2313 - Expr testexpr = analyze(context == C.EVAL ? context : C.EXPRESSION, RT.second(form)); 362.2314 - Expr thenexpr, elseexpr; 362.2315 - try { 362.2316 - Var.pushThreadBindings( 362.2317 - RT.map(CLEAR_PATH, new PathNode(PATHTYPE.PATH,branch))); 362.2318 - thenexpr = analyze(context, RT.third(form)); 362.2319 - } 362.2320 - finally{ 362.2321 - Var.popThreadBindings(); 362.2322 - } 362.2323 - try { 362.2324 - Var.pushThreadBindings( 362.2325 - RT.map(CLEAR_PATH, new PathNode(PATHTYPE.PATH,branch))); 362.2326 - elseexpr = analyze(context, RT.fourth(form)); 362.2327 - } 362.2328 - finally{ 362.2329 - Var.popThreadBindings(); 362.2330 - } 362.2331 - return new IfExpr((Integer) LINE.deref(), 362.2332 - testexpr, 362.2333 - thenexpr, 362.2334 - elseexpr); 362.2335 - } 362.2336 - } 362.2337 -} 362.2338 - 362.2339 -static final public IPersistentMap CHAR_MAP = 362.2340 - PersistentHashMap.create('-', "_", 362.2341 -// '.', "_DOT_", 362.2342 -':', "_COLON_", 362.2343 -'+', "_PLUS_", 362.2344 -'>', "_GT_", 362.2345 -'<', "_LT_", 362.2346 -'=', "_EQ_", 362.2347 -'~', "_TILDE_", 362.2348 -'!', "_BANG_", 362.2349 -'@', "_CIRCA_", 362.2350 -'#', "_SHARP_", 362.2351 -'$', "_DOLLARSIGN_", 362.2352 -'%', "_PERCENT_", 362.2353 -'^', "_CARET_", 362.2354 -'&', "_AMPERSAND_", 362.2355 -'*', "_STAR_", 362.2356 -'|', "_BAR_", 362.2357 -'{', "_LBRACE_", 362.2358 -'}', "_RBRACE_", 362.2359 -'[', "_LBRACK_", 362.2360 -']', "_RBRACK_", 362.2361 -'/', "_SLASH_", 362.2362 -'\\', "_BSLASH_", 362.2363 -'?', "_QMARK_"); 362.2364 - 362.2365 -static public String munge(String name){ 362.2366 - StringBuilder sb = new StringBuilder(); 362.2367 - for(char c : name.toCharArray()) 362.2368 - { 362.2369 - String sub = (String) CHAR_MAP.valAt(c); 362.2370 - if(sub != null) 362.2371 - sb.append(sub); 362.2372 - else 362.2373 - sb.append(c); 362.2374 - } 362.2375 - return sb.toString(); 362.2376 -} 362.2377 - 362.2378 -public static class EmptyExpr implements Expr{ 362.2379 - public final Object coll; 362.2380 - final static Type HASHMAP_TYPE = Type.getType(PersistentArrayMap.class); 362.2381 - final static Type HASHSET_TYPE = Type.getType(PersistentHashSet.class); 362.2382 - final static Type VECTOR_TYPE = Type.getType(PersistentVector.class); 362.2383 - final static Type LIST_TYPE = Type.getType(PersistentList.class); 362.2384 - final static Type EMPTY_LIST_TYPE = Type.getType(PersistentList.EmptyList.class); 362.2385 - 362.2386 - 362.2387 - public EmptyExpr(Object coll){ 362.2388 - this.coll = coll; 362.2389 - } 362.2390 - 362.2391 - public Object eval() throws Exception{ 362.2392 - return coll; 362.2393 - } 362.2394 - 362.2395 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2396 - if(coll instanceof IPersistentList) 362.2397 - gen.getStatic(LIST_TYPE, "EMPTY", EMPTY_LIST_TYPE); 362.2398 - else if(coll instanceof IPersistentVector) 362.2399 - gen.getStatic(VECTOR_TYPE, "EMPTY", VECTOR_TYPE); 362.2400 - else if(coll instanceof IPersistentMap) 362.2401 - gen.getStatic(HASHMAP_TYPE, "EMPTY", HASHMAP_TYPE); 362.2402 - else if(coll instanceof IPersistentSet) 362.2403 - gen.getStatic(HASHSET_TYPE, "EMPTY", HASHSET_TYPE); 362.2404 - else 362.2405 - throw new UnsupportedOperationException("Unknown Collection type"); 362.2406 - if(context == C.STATEMENT) 362.2407 - { 362.2408 - gen.pop(); 362.2409 - } 362.2410 - } 362.2411 - 362.2412 - public boolean hasJavaClass() throws Exception{ 362.2413 - return true; 362.2414 - } 362.2415 - 362.2416 - public Class getJavaClass() throws Exception{ 362.2417 - if(coll instanceof IPersistentList) 362.2418 - return IPersistentList.class; 362.2419 - else if(coll instanceof IPersistentVector) 362.2420 - return IPersistentVector.class; 362.2421 - else if(coll instanceof IPersistentMap) 362.2422 - return IPersistentMap.class; 362.2423 - else if(coll instanceof IPersistentSet) 362.2424 - return IPersistentSet.class; 362.2425 - else 362.2426 - throw new UnsupportedOperationException("Unknown Collection type"); 362.2427 - } 362.2428 -} 362.2429 - 362.2430 -public static class ListExpr implements Expr{ 362.2431 - public final IPersistentVector args; 362.2432 - final static Method arrayToListMethod = Method.getMethod("clojure.lang.ISeq arrayToList(Object[])"); 362.2433 - 362.2434 - 362.2435 - public ListExpr(IPersistentVector args){ 362.2436 - this.args = args; 362.2437 - } 362.2438 - 362.2439 - public Object eval() throws Exception{ 362.2440 - IPersistentVector ret = PersistentVector.EMPTY; 362.2441 - for(int i = 0; i < args.count(); i++) 362.2442 - ret = (IPersistentVector) ret.cons(((Expr) args.nth(i)).eval()); 362.2443 - return ret.seq(); 362.2444 - } 362.2445 - 362.2446 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2447 - MethodExpr.emitArgsAsArray(args, objx, gen); 362.2448 - gen.invokeStatic(RT_TYPE, arrayToListMethod); 362.2449 - if(context == C.STATEMENT) 362.2450 - gen.pop(); 362.2451 - } 362.2452 - 362.2453 - public boolean hasJavaClass() throws Exception{ 362.2454 - return true; 362.2455 - } 362.2456 - 362.2457 - public Class getJavaClass() throws Exception{ 362.2458 - return IPersistentList.class; 362.2459 - } 362.2460 - 362.2461 -} 362.2462 - 362.2463 -public static class MapExpr implements Expr{ 362.2464 - public final IPersistentVector keyvals; 362.2465 - final static Method mapMethod = Method.getMethod("clojure.lang.IPersistentMap map(Object[])"); 362.2466 - 362.2467 - 362.2468 - public MapExpr(IPersistentVector keyvals){ 362.2469 - this.keyvals = keyvals; 362.2470 - } 362.2471 - 362.2472 - public Object eval() throws Exception{ 362.2473 - Object[] ret = new Object[keyvals.count()]; 362.2474 - for(int i = 0; i < keyvals.count(); i++) 362.2475 - ret[i] = ((Expr) keyvals.nth(i)).eval(); 362.2476 - return RT.map(ret); 362.2477 - } 362.2478 - 362.2479 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2480 - MethodExpr.emitArgsAsArray(keyvals, objx, gen); 362.2481 - gen.invokeStatic(RT_TYPE, mapMethod); 362.2482 - if(context == C.STATEMENT) 362.2483 - gen.pop(); 362.2484 - } 362.2485 - 362.2486 - public boolean hasJavaClass() throws Exception{ 362.2487 - return true; 362.2488 - } 362.2489 - 362.2490 - public Class getJavaClass() throws Exception{ 362.2491 - return IPersistentMap.class; 362.2492 - } 362.2493 - 362.2494 - 362.2495 - static public Expr parse(C context, IPersistentMap form) throws Exception{ 362.2496 - IPersistentVector keyvals = PersistentVector.EMPTY; 362.2497 - for(ISeq s = RT.seq(form); s != null; s = s.next()) 362.2498 - { 362.2499 - IMapEntry e = (IMapEntry) s.first(); 362.2500 - keyvals = (IPersistentVector) keyvals.cons(analyze(context == C.EVAL ? context : C.EXPRESSION, e.key())); 362.2501 - keyvals = (IPersistentVector) keyvals.cons(analyze(context == C.EVAL ? context : C.EXPRESSION, e.val())); 362.2502 - } 362.2503 - Expr ret = new MapExpr(keyvals); 362.2504 - if(form instanceof IObj && ((IObj) form).meta() != null) 362.2505 - return new MetaExpr(ret, (MapExpr) MapExpr 362.2506 - .parse(context == C.EVAL ? context : C.EXPRESSION, ((IObj) form).meta())); 362.2507 - else 362.2508 - return ret; 362.2509 - } 362.2510 -} 362.2511 - 362.2512 -public static class SetExpr implements Expr{ 362.2513 - public final IPersistentVector keys; 362.2514 - final static Method setMethod = Method.getMethod("clojure.lang.IPersistentSet set(Object[])"); 362.2515 - 362.2516 - 362.2517 - public SetExpr(IPersistentVector keys){ 362.2518 - this.keys = keys; 362.2519 - } 362.2520 - 362.2521 - public Object eval() throws Exception{ 362.2522 - Object[] ret = new Object[keys.count()]; 362.2523 - for(int i = 0; i < keys.count(); i++) 362.2524 - ret[i] = ((Expr) keys.nth(i)).eval(); 362.2525 - return RT.set(ret); 362.2526 - } 362.2527 - 362.2528 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2529 - MethodExpr.emitArgsAsArray(keys, objx, gen); 362.2530 - gen.invokeStatic(RT_TYPE, setMethod); 362.2531 - if(context == C.STATEMENT) 362.2532 - gen.pop(); 362.2533 - } 362.2534 - 362.2535 - public boolean hasJavaClass() throws Exception{ 362.2536 - return true; 362.2537 - } 362.2538 - 362.2539 - public Class getJavaClass() throws Exception{ 362.2540 - return IPersistentSet.class; 362.2541 - } 362.2542 - 362.2543 - 362.2544 - static public Expr parse(C context, IPersistentSet form) throws Exception{ 362.2545 - IPersistentVector keys = PersistentVector.EMPTY; 362.2546 - for(ISeq s = RT.seq(form); s != null; s = s.next()) 362.2547 - { 362.2548 - Object e = s.first(); 362.2549 - keys = (IPersistentVector) keys.cons(analyze(context == C.EVAL ? context : C.EXPRESSION, e)); 362.2550 - } 362.2551 - Expr ret = new SetExpr(keys); 362.2552 - if(form instanceof IObj && ((IObj) form).meta() != null) 362.2553 - return new MetaExpr(ret, (MapExpr) MapExpr 362.2554 - .parse(context == C.EVAL ? context : C.EXPRESSION, ((IObj) form).meta())); 362.2555 - else 362.2556 - return ret; 362.2557 - } 362.2558 -} 362.2559 - 362.2560 -public static class VectorExpr implements Expr{ 362.2561 - public final IPersistentVector args; 362.2562 - final static Method vectorMethod = Method.getMethod("clojure.lang.IPersistentVector vector(Object[])"); 362.2563 - 362.2564 - 362.2565 - public VectorExpr(IPersistentVector args){ 362.2566 - this.args = args; 362.2567 - } 362.2568 - 362.2569 - public Object eval() throws Exception{ 362.2570 - IPersistentVector ret = PersistentVector.EMPTY; 362.2571 - for(int i = 0; i < args.count(); i++) 362.2572 - ret = (IPersistentVector) ret.cons(((Expr) args.nth(i)).eval()); 362.2573 - return ret; 362.2574 - } 362.2575 - 362.2576 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2577 - MethodExpr.emitArgsAsArray(args, objx, gen); 362.2578 - gen.invokeStatic(RT_TYPE, vectorMethod); 362.2579 - if(context == C.STATEMENT) 362.2580 - gen.pop(); 362.2581 - } 362.2582 - 362.2583 - public boolean hasJavaClass() throws Exception{ 362.2584 - return true; 362.2585 - } 362.2586 - 362.2587 - public Class getJavaClass() throws Exception{ 362.2588 - return IPersistentVector.class; 362.2589 - } 362.2590 - 362.2591 - static public Expr parse(C context, IPersistentVector form) throws Exception{ 362.2592 - IPersistentVector args = PersistentVector.EMPTY; 362.2593 - for(int i = 0; i < form.count(); i++) 362.2594 - args = (IPersistentVector) args.cons(analyze(context == C.EVAL ? context : C.EXPRESSION, form.nth(i))); 362.2595 - Expr ret = new VectorExpr(args); 362.2596 - if(form instanceof IObj && ((IObj) form).meta() != null) 362.2597 - return new MetaExpr(ret, (MapExpr) MapExpr 362.2598 - .parse(context == C.EVAL ? context : C.EXPRESSION, ((IObj) form).meta())); 362.2599 - else 362.2600 - return ret; 362.2601 - } 362.2602 - 362.2603 -} 362.2604 - 362.2605 -static class KeywordInvokeExpr implements Expr{ 362.2606 - public final KeywordExpr kw; 362.2607 - public final Object tag; 362.2608 - public final Expr target; 362.2609 - public final int line; 362.2610 - public final int siteIndex; 362.2611 - public final String source; 362.2612 - static Type ILOOKUP_TYPE = Type.getType(ILookup.class); 362.2613 - 362.2614 - public KeywordInvokeExpr(String source, int line, Symbol tag, KeywordExpr kw, Expr target){ 362.2615 - this.source = source; 362.2616 - this.kw = kw; 362.2617 - this.target = target; 362.2618 - this.line = line; 362.2619 - this.tag = tag; 362.2620 - this.siteIndex = registerKeywordCallsite(kw.k); 362.2621 - } 362.2622 - 362.2623 - public Object eval() throws Exception{ 362.2624 - try 362.2625 - { 362.2626 - return kw.k.invoke(target.eval()); 362.2627 - } 362.2628 - catch(Throwable e) 362.2629 - { 362.2630 - if(!(e instanceof CompilerException)) 362.2631 - throw new CompilerException(source, line, e); 362.2632 - else 362.2633 - throw (CompilerException) e; 362.2634 - } 362.2635 - } 362.2636 - 362.2637 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2638 - Label endLabel = gen.newLabel(); 362.2639 - Label faultLabel = gen.newLabel(); 362.2640 - 362.2641 - gen.visitLineNumber(line, gen.mark()); 362.2642 - gen.getStatic(objx.objtype, objx.thunkNameStatic(siteIndex),ObjExpr.ILOOKUP_THUNK_TYPE); 362.2643 - gen.dup(); 362.2644 - target.emit(C.EXPRESSION, objx, gen); 362.2645 - gen.dupX2(); 362.2646 - gen.invokeInterface(ObjExpr.ILOOKUP_THUNK_TYPE, Method.getMethod("Object get(Object)")); 362.2647 - gen.dupX2(); 362.2648 - gen.visitJumpInsn(IF_ACMPEQ, faultLabel); 362.2649 - gen.pop(); 362.2650 - gen.goTo(endLabel); 362.2651 - 362.2652 - gen.mark(faultLabel); 362.2653 - gen.swap(); 362.2654 - gen.pop(); 362.2655 - gen.getStatic(objx.objtype, objx.siteNameStatic(siteIndex),ObjExpr.KEYWORD_LOOKUPSITE_TYPE); 362.2656 - gen.swap(); 362.2657 - gen.loadThis(); 362.2658 - gen.invokeInterface(ObjExpr.ILOOKUP_SITE_TYPE, 362.2659 - Method.getMethod("Object fault(Object, clojure.lang.ILookupHost)")); 362.2660 - 362.2661 - gen.mark(endLabel); 362.2662 - if(context == C.STATEMENT) 362.2663 - gen.pop(); 362.2664 - } 362.2665 - 362.2666 - public void emit2(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2667 - Label endLabel = gen.newLabel(); 362.2668 - Label faultLabel = gen.newLabel(); 362.2669 - 362.2670 - gen.visitLineNumber(line, gen.mark()); 362.2671 - target.emit(C.EXPRESSION, objx, gen); 362.2672 - gen.dup(); 362.2673 - gen.getStatic(objx.objtype, objx.thunkNameStatic(siteIndex),ObjExpr.ILOOKUP_THUNK_TYPE); 362.2674 - gen.swap(); 362.2675 - gen.getStatic(objx.objtype, objx.siteNameStatic(siteIndex),ObjExpr.KEYWORD_LOOKUPSITE_TYPE); 362.2676 -/// gen.loadThis(); 362.2677 - gen.invokeInterface(ObjExpr.ILOOKUP_THUNK_TYPE, 362.2678 - Method.getMethod("Object get(Object,clojure.lang.ILookupSite)")); 362.2679 -// gen.invokeInterface(ObjExpr.ILOOKUP_THUNK_TYPE, 362.2680 -// Method.getMethod("Object get(Object,clojure.lang.ILookupSite,clojure.lang.ILookupHost)")); 362.2681 - gen.dup(); 362.2682 - gen.getStatic(objx.objtype, objx.siteNameStatic(siteIndex),ObjExpr.KEYWORD_LOOKUPSITE_TYPE); 362.2683 - gen.visitJumpInsn(IF_ACMPEQ, faultLabel); 362.2684 - gen.swap(); 362.2685 - gen.pop(); 362.2686 - gen.goTo(endLabel); 362.2687 - 362.2688 - gen.mark(faultLabel); 362.2689 - gen.swap(); 362.2690 - gen.loadThis(); 362.2691 - gen.invokeInterface(ObjExpr.ILOOKUP_SITE_TYPE, 362.2692 - Method.getMethod("Object fault(Object, clojure.lang.ILookupHost)")); 362.2693 - 362.2694 - gen.mark(endLabel); 362.2695 - if(context == C.STATEMENT) 362.2696 - gen.pop(); 362.2697 - } 362.2698 - 362.2699 - public void emitInstance(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2700 - gen.visitLineNumber(line, gen.mark()); 362.2701 - gen.loadThis(); 362.2702 - gen.getField(objx.objtype, objx.thunkName(siteIndex),ObjExpr.ILOOKUP_THUNK_TYPE); 362.2703 - target.emit(C.EXPRESSION, objx, gen); 362.2704 - gen.loadThis(); 362.2705 - gen.getField(objx.objtype, objx.siteName(siteIndex),ObjExpr.ILOOKUP_SITE_TYPE); 362.2706 - gen.loadThis(); 362.2707 - gen.checkCast(Type.getType(ILookupHost.class)); 362.2708 - gen.invokeInterface(ObjExpr.ILOOKUP_THUNK_TYPE, 362.2709 - Method.getMethod("Object get(Object,clojure.lang.ILookupSite,clojure.lang.ILookupHost)")); 362.2710 - if(context == C.STATEMENT) 362.2711 - gen.pop(); 362.2712 - } 362.2713 - 362.2714 - public void emitNormal(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2715 - Label slowLabel = gen.newLabel(); 362.2716 - Label endLabel = gen.newLabel(); 362.2717 - 362.2718 - gen.visitLineNumber(line, gen.mark()); 362.2719 - target.emit(C.EXPRESSION, objx, gen); 362.2720 - gen.dup(); 362.2721 - gen.instanceOf(ILOOKUP_TYPE); 362.2722 - gen.ifZCmp(GeneratorAdapter.EQ, slowLabel); 362.2723 - kw.emit(C.EXPRESSION, objx, gen); 362.2724 - gen.invokeInterface(ILOOKUP_TYPE, new Method("valAt", OBJECT_TYPE, ARG_TYPES[1])); 362.2725 - gen.goTo(endLabel); 362.2726 - 362.2727 - gen.mark(slowLabel); 362.2728 - kw.emit(C.EXPRESSION, objx, gen); 362.2729 - gen.invokeStatic(RT_TYPE, new Method("get", OBJECT_TYPE, ARG_TYPES[2])); 362.2730 - 362.2731 - gen.mark(endLabel); 362.2732 - 362.2733 - if(context == C.STATEMENT) 362.2734 - gen.pop(); 362.2735 - } 362.2736 - 362.2737 - public boolean hasJavaClass() throws Exception{ 362.2738 - return tag != null; 362.2739 - } 362.2740 - 362.2741 - public Class getJavaClass() throws Exception{ 362.2742 - return HostExpr.tagToClass(tag); 362.2743 - } 362.2744 - 362.2745 -} 362.2746 -//static class KeywordSiteInvokeExpr implements Expr{ 362.2747 -// public final Expr site; 362.2748 -// public final Object tag; 362.2749 -// public final Expr target; 362.2750 -// public final int line; 362.2751 -// public final String source; 362.2752 -// 362.2753 -// public KeywordSiteInvokeExpr(String source, int line, Symbol tag, Expr site, Expr target){ 362.2754 -// this.source = source; 362.2755 -// this.site = site; 362.2756 -// this.target = target; 362.2757 -// this.line = line; 362.2758 -// this.tag = tag; 362.2759 -// } 362.2760 -// 362.2761 -// public Object eval() throws Exception{ 362.2762 -// try 362.2763 -// { 362.2764 -// KeywordCallSite s = (KeywordCallSite) site.eval(); 362.2765 -// return s.thunk.invoke(s,target.eval()); 362.2766 -// } 362.2767 -// catch(Throwable e) 362.2768 -// { 362.2769 -// if(!(e instanceof CompilerException)) 362.2770 -// throw new CompilerException(source, line, e); 362.2771 -// else 362.2772 -// throw (CompilerException) e; 362.2773 -// } 362.2774 -// } 362.2775 -// 362.2776 -// public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2777 -// gen.visitLineNumber(line, gen.mark()); 362.2778 -// site.emit(C.EXPRESSION, objx, gen); 362.2779 -// gen.dup(); 362.2780 -// gen.getField(Type.getType(KeywordCallSite.class),"thunk",IFN_TYPE); 362.2781 -// gen.swap(); 362.2782 -// target.emit(C.EXPRESSION, objx, gen); 362.2783 -// 362.2784 -// gen.invokeInterface(IFN_TYPE, new Method("invoke", OBJECT_TYPE, ARG_TYPES[2])); 362.2785 -// if(context == C.STATEMENT) 362.2786 -// gen.pop(); 362.2787 -// } 362.2788 -// 362.2789 -// public boolean hasJavaClass() throws Exception{ 362.2790 -// return tag != null; 362.2791 -// } 362.2792 -// 362.2793 -// public Class getJavaClass() throws Exception{ 362.2794 -// return HostExpr.tagToClass(tag); 362.2795 -// } 362.2796 -// 362.2797 -//} 362.2798 - 362.2799 -public static class InstanceOfExpr implements Expr, MaybePrimitiveExpr{ 362.2800 - Expr expr; 362.2801 - Class c; 362.2802 - 362.2803 - public InstanceOfExpr(Class c, Expr expr){ 362.2804 - this.expr = expr; 362.2805 - this.c = c; 362.2806 - } 362.2807 - 362.2808 - public Object eval() throws Exception{ 362.2809 - if(c.isInstance(expr.eval())) 362.2810 - return RT.T; 362.2811 - return RT.F; 362.2812 - } 362.2813 - 362.2814 - public boolean canEmitPrimitive(){ 362.2815 - return true; 362.2816 - } 362.2817 - 362.2818 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2819 - expr.emit(C.EXPRESSION,objx,gen); 362.2820 - gen.instanceOf(Type.getType(c)); 362.2821 - } 362.2822 - 362.2823 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2824 - emitUnboxed(context,objx,gen); 362.2825 - HostExpr.emitBoxReturn(objx,gen,Boolean.TYPE); 362.2826 - if(context == C.STATEMENT) 362.2827 - gen.pop(); 362.2828 - } 362.2829 - 362.2830 - public boolean hasJavaClass() throws Exception{ 362.2831 - return true; 362.2832 - } 362.2833 - 362.2834 - public Class getJavaClass() throws Exception{ 362.2835 - return Boolean.TYPE; 362.2836 - } 362.2837 - 362.2838 -} 362.2839 - 362.2840 -static class InvokeExpr implements Expr{ 362.2841 - public final Expr fexpr; 362.2842 - public final Object tag; 362.2843 - public final IPersistentVector args; 362.2844 - public final int line; 362.2845 - public final String source; 362.2846 - public boolean isProtocol = false; 362.2847 - public boolean isDirect = false; 362.2848 - public int siteIndex = -1; 362.2849 - public Class protocolOn; 362.2850 - public java.lang.reflect.Method onMethod; 362.2851 - static Keyword onKey = Keyword.intern("on"); 362.2852 - static Keyword methodMapKey = Keyword.intern("method-map"); 362.2853 - static Keyword dynamicKey = Keyword.intern("dynamic"); 362.2854 - 362.2855 - public InvokeExpr(String source, int line, Symbol tag, Expr fexpr, IPersistentVector args) throws Exception{ 362.2856 - this.source = source; 362.2857 - this.fexpr = fexpr; 362.2858 - this.args = args; 362.2859 - this.line = line; 362.2860 - if(fexpr instanceof VarExpr) 362.2861 - { 362.2862 - Var fvar = ((VarExpr)fexpr).var; 362.2863 - Var pvar = (Var)RT.get(fvar.meta(), protocolKey); 362.2864 - if(pvar != null && PROTOCOL_CALLSITES.isBound()) 362.2865 - { 362.2866 - this.isProtocol = true; 362.2867 - this.siteIndex = registerProtocolCallsite(((VarExpr)fexpr).var); 362.2868 - Object pon = RT.get(pvar.get(), onKey); 362.2869 - this.protocolOn = HostExpr.maybeClass(pon,false); 362.2870 - if(this.protocolOn != null) 362.2871 - { 362.2872 - IPersistentMap mmap = (IPersistentMap) RT.get(pvar.get(), methodMapKey); 362.2873 - Keyword mmapVal = (Keyword) mmap.valAt(Keyword.intern(fvar.sym)); 362.2874 - if (mmapVal == null) { 362.2875 - throw new IllegalArgumentException( 362.2876 - "No method of interface: " + protocolOn.getName() + 362.2877 - " found for function: " + fvar.sym + " of protocol: " + pvar.sym + 362.2878 - " (The protocol method may have been defined before and removed.)"); 362.2879 - } 362.2880 - String mname = munge(mmapVal.sym.toString()); 362.2881 - List methods = Reflector.getMethods(protocolOn, args.count() - 1, mname, false); 362.2882 - if(methods.size() != 1) 362.2883 - throw new IllegalArgumentException( 362.2884 - "No single method: " + mname + " of interface: " + protocolOn.getName() + 362.2885 - " found for function: " + fvar.sym + " of protocol: " + pvar.sym); 362.2886 - this.onMethod = (java.lang.reflect.Method) methods.get(0); 362.2887 - } 362.2888 - } 362.2889 -// else if(pvar == null && VAR_CALLSITES.isBound() 362.2890 -// && fvar.ns.name.name.startsWith("clojure") 362.2891 -// && !RT.booleanCast(RT.get(RT.meta(fvar),dynamicKey)) 362.2892 -// ) 362.2893 -// { 362.2894 -// //todo - more specific criteria for binding these 362.2895 -// this.isDirect = true; 362.2896 -// this.siteIndex = registerVarCallsite(((VarExpr) fexpr).var); 362.2897 -// } 362.2898 - } 362.2899 - this.tag = tag != null ? tag : (fexpr instanceof VarExpr ? ((VarExpr) fexpr).tag : null); 362.2900 - } 362.2901 - 362.2902 - public Object eval() throws Exception{ 362.2903 - try 362.2904 - { 362.2905 - IFn fn = (IFn) fexpr.eval(); 362.2906 - PersistentVector argvs = PersistentVector.EMPTY; 362.2907 - for(int i = 0; i < args.count(); i++) 362.2908 - argvs = argvs.cons(((Expr) args.nth(i)).eval()); 362.2909 - return fn.applyTo(RT.seq(argvs)); 362.2910 - } 362.2911 - catch(Throwable e) 362.2912 - { 362.2913 - if(!(e instanceof CompilerException)) 362.2914 - throw new CompilerException(source, line, e); 362.2915 - else 362.2916 - throw (CompilerException) e; 362.2917 - } 362.2918 - } 362.2919 - 362.2920 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2921 - gen.visitLineNumber(line, gen.mark()); 362.2922 - if(isProtocol) 362.2923 - { 362.2924 - emitProto(context,objx,gen); 362.2925 - } 362.2926 - else if(isDirect) 362.2927 - { 362.2928 - Label callLabel = gen.newLabel(); 362.2929 - 362.2930 - gen.getStatic(objx.objtype, objx.varCallsiteName(siteIndex), IFN_TYPE); 362.2931 - gen.dup(); 362.2932 - gen.ifNonNull(callLabel); 362.2933 - 362.2934 - gen.pop(); 362.2935 - fexpr.emit(C.EXPRESSION, objx, gen); 362.2936 - gen.checkCast(IFN_TYPE); 362.2937 -// gen.dup(); 362.2938 -// gen.putStatic(objx.objtype, objx.varCallsiteName(siteIndex), IFN_TYPE); 362.2939 - 362.2940 - gen.mark(callLabel); 362.2941 - emitArgsAndCall(0, context,objx,gen); 362.2942 - } 362.2943 - else 362.2944 - { 362.2945 - fexpr.emit(C.EXPRESSION, objx, gen); 362.2946 - gen.checkCast(IFN_TYPE); 362.2947 - emitArgsAndCall(0, context,objx,gen); 362.2948 - } 362.2949 - if(context == C.STATEMENT) 362.2950 - gen.pop(); 362.2951 - } 362.2952 - 362.2953 - public void emitProto(C context, ObjExpr objx, GeneratorAdapter gen){ 362.2954 - Label onLabel = gen.newLabel(); 362.2955 - Label callLabel = gen.newLabel(); 362.2956 - Label endLabel = gen.newLabel(); 362.2957 - 362.2958 - Var v = ((VarExpr)fexpr).var; 362.2959 - 362.2960 - Expr e = (Expr) args.nth(0); 362.2961 - e.emit(C.EXPRESSION, objx, gen); 362.2962 - gen.dup(); //target, target 362.2963 - gen.invokeStatic(UTIL_TYPE,Method.getMethod("Class classOf(Object)")); //target,class 362.2964 - gen.loadThis(); 362.2965 - gen.getField(objx.objtype, objx.cachedClassName(siteIndex),CLASS_TYPE); //target,class,cached-class 362.2966 - gen.visitJumpInsn(IF_ACMPEQ, callLabel); //target 362.2967 - if(protocolOn != null) 362.2968 - { 362.2969 - gen.dup(); //target, target 362.2970 - gen.instanceOf(Type.getType(protocolOn)); 362.2971 - gen.ifZCmp(GeneratorAdapter.NE, onLabel); 362.2972 - } 362.2973 - 362.2974 - gen.mark(callLabel); //target 362.2975 - gen.dup(); //target, target 362.2976 - gen.invokeStatic(UTIL_TYPE,Method.getMethod("Class classOf(Object)")); //target,class 362.2977 - gen.loadThis(); 362.2978 - gen.swap(); 362.2979 - gen.putField(objx.objtype, objx.cachedClassName(siteIndex),CLASS_TYPE); //target 362.2980 - objx.emitVar(gen, v); 362.2981 - gen.invokeVirtual(VAR_TYPE, Method.getMethod("Object getRawRoot()")); //target, proto-fn 362.2982 - gen.swap(); 362.2983 - emitArgsAndCall(1, context,objx,gen); 362.2984 - gen.goTo(endLabel); 362.2985 - 362.2986 - gen.mark(onLabel); //target 362.2987 - if(protocolOn != null) 362.2988 - { 362.2989 - MethodExpr.emitTypedArgs(objx, gen, onMethod.getParameterTypes(), RT.subvec(args,1,args.count())); 362.2990 - if(context == C.RETURN) 362.2991 - { 362.2992 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.2993 - method.emitClearLocals(gen); 362.2994 - } 362.2995 - Method m = new Method(onMethod.getName(), Type.getReturnType(onMethod), Type.getArgumentTypes(onMethod)); 362.2996 - gen.invokeInterface(Type.getType(protocolOn), m); 362.2997 - HostExpr.emitBoxReturn(objx, gen, onMethod.getReturnType()); 362.2998 - } 362.2999 - gen.mark(endLabel); 362.3000 - } 362.3001 - 362.3002 - void emitArgsAndCall(int firstArgToEmit, C context, ObjExpr objx, GeneratorAdapter gen){ 362.3003 - for(int i = firstArgToEmit; i < Math.min(MAX_POSITIONAL_ARITY, args.count()); i++) 362.3004 - { 362.3005 - Expr e = (Expr) args.nth(i); 362.3006 - e.emit(C.EXPRESSION, objx, gen); 362.3007 - } 362.3008 - if(args.count() > MAX_POSITIONAL_ARITY) 362.3009 - { 362.3010 - PersistentVector restArgs = PersistentVector.EMPTY; 362.3011 - for(int i = MAX_POSITIONAL_ARITY; i < args.count(); i++) 362.3012 - { 362.3013 - restArgs = restArgs.cons(args.nth(i)); 362.3014 - } 362.3015 - MethodExpr.emitArgsAsArray(restArgs, objx, gen); 362.3016 - } 362.3017 - 362.3018 - if(context == C.RETURN) 362.3019 - { 362.3020 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.3021 - method.emitClearLocals(gen); 362.3022 - } 362.3023 - 362.3024 - gen.invokeInterface(IFN_TYPE, new Method("invoke", OBJECT_TYPE, ARG_TYPES[Math.min(MAX_POSITIONAL_ARITY + 1, 362.3025 - args.count())])); 362.3026 - } 362.3027 - 362.3028 - public boolean hasJavaClass() throws Exception{ 362.3029 - return tag != null; 362.3030 - } 362.3031 - 362.3032 - public Class getJavaClass() throws Exception{ 362.3033 - return HostExpr.tagToClass(tag); 362.3034 - } 362.3035 - 362.3036 - static public Expr parse(C context, ISeq form) throws Exception{ 362.3037 - if(context != C.EVAL) 362.3038 - context = C.EXPRESSION; 362.3039 - Expr fexpr = analyze(context, form.first()); 362.3040 - if(fexpr instanceof VarExpr && ((VarExpr)fexpr).var.equals(INSTANCE)) 362.3041 - { 362.3042 - if(RT.second(form) instanceof Symbol) 362.3043 - { 362.3044 - Class c = HostExpr.maybeClass(RT.second(form),false); 362.3045 - if(c != null) 362.3046 - return new InstanceOfExpr(c, analyze(context, RT.third(form))); 362.3047 - } 362.3048 - } 362.3049 - 362.3050 - if(fexpr instanceof KeywordExpr && RT.count(form) == 2 && KEYWORD_CALLSITES.isBound()) 362.3051 - { 362.3052 -// fexpr = new ConstantExpr(new KeywordCallSite(((KeywordExpr)fexpr).k)); 362.3053 - Expr target = analyze(context, RT.second(form)); 362.3054 - return new KeywordInvokeExpr((String) SOURCE.deref(), (Integer) LINE.deref(), tagOf(form), 362.3055 - (KeywordExpr) fexpr, target); 362.3056 - } 362.3057 - PersistentVector args = PersistentVector.EMPTY; 362.3058 - for(ISeq s = RT.seq(form.next()); s != null; s = s.next()) 362.3059 - { 362.3060 - args = args.cons(analyze(context, s.first())); 362.3061 - } 362.3062 -// if(args.count() > MAX_POSITIONAL_ARITY) 362.3063 -// throw new IllegalArgumentException( 362.3064 -// String.format("No more than %d args supported", MAX_POSITIONAL_ARITY)); 362.3065 - 362.3066 - return new InvokeExpr((String) SOURCE.deref(), (Integer) LINE.deref(), tagOf(form), fexpr, args); 362.3067 - } 362.3068 -} 362.3069 - 362.3070 -static class SourceDebugExtensionAttribute extends Attribute{ 362.3071 - public SourceDebugExtensionAttribute(){ 362.3072 - super("SourceDebugExtension"); 362.3073 - } 362.3074 - 362.3075 - void writeSMAP(ClassWriter cw, String smap){ 362.3076 - ByteVector bv = write(cw, null, -1, -1, -1); 362.3077 - bv.putUTF8(smap); 362.3078 - } 362.3079 -} 362.3080 - 362.3081 -static public class FnExpr extends ObjExpr{ 362.3082 - final static Type aFnType = Type.getType(AFunction.class); 362.3083 - final static Type restFnType = Type.getType(RestFn.class); 362.3084 - //if there is a variadic overload (there can only be one) it is stored here 362.3085 - FnMethod variadicMethod = null; 362.3086 - IPersistentCollection methods; 362.3087 - // String superName = null; 362.3088 - 362.3089 - public FnExpr(Object tag){ 362.3090 - super(tag); 362.3091 - } 362.3092 - 362.3093 - public boolean hasJavaClass() throws Exception{ 362.3094 - return true; 362.3095 - } 362.3096 - 362.3097 - public Class getJavaClass() throws Exception{ 362.3098 - return AFunction.class; 362.3099 - } 362.3100 - 362.3101 - protected void emitMethods(ClassVisitor cv){ 362.3102 - //override of invoke/doInvoke for each method 362.3103 - for(ISeq s = RT.seq(methods); s != null; s = s.next()) 362.3104 - { 362.3105 - ObjMethod method = (ObjMethod) s.first(); 362.3106 - method.emit(this, cv); 362.3107 - } 362.3108 - 362.3109 - if(isVariadic()) 362.3110 - { 362.3111 - GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC, 362.3112 - Method.getMethod("int getRequiredArity()"), 362.3113 - null, 362.3114 - null, 362.3115 - cv); 362.3116 - gen.visitCode(); 362.3117 - gen.push(variadicMethod.reqParms.count()); 362.3118 - gen.returnValue(); 362.3119 - gen.endMethod(); 362.3120 - } 362.3121 - } 362.3122 - 362.3123 - static Expr parse(C context, ISeq form, String name) throws Exception{ 362.3124 - ISeq origForm = form; 362.3125 - FnExpr fn = new FnExpr(tagOf(form)); 362.3126 - fn.src = form; 362.3127 - ObjMethod enclosingMethod = (ObjMethod) METHOD.deref(); 362.3128 - if(((IMeta) form.first()).meta() != null) 362.3129 - { 362.3130 - fn.onceOnly = RT.booleanCast(RT.get(RT.meta(form.first()), Keyword.intern(null, "once"))); 362.3131 -// fn.superName = (String) RT.get(RT.meta(form.first()), Keyword.intern(null, "super-name")); 362.3132 - } 362.3133 - //fn.thisName = name; 362.3134 - String basename = enclosingMethod != null ? 362.3135 - (enclosingMethod.objx.name + "$") 362.3136 - : //"clojure.fns." + 362.3137 - (munge(currentNS().name.name) + "$"); 362.3138 - if(RT.second(form) instanceof Symbol) 362.3139 - name = ((Symbol) RT.second(form)).name; 362.3140 - String simpleName = name != null ? 362.3141 - (munge(name).replace(".", "_DOT_") 362.3142 - + (enclosingMethod != null ? "__" + RT.nextID() : "")) 362.3143 - : ("fn" 362.3144 - + "__" + RT.nextID()); 362.3145 - fn.name = basename + simpleName; 362.3146 - fn.internalName = fn.name.replace('.', '/'); 362.3147 - fn.objtype = Type.getObjectType(fn.internalName); 362.3148 - try 362.3149 - { 362.3150 - Var.pushThreadBindings( 362.3151 - RT.map(CONSTANTS, PersistentVector.EMPTY, 362.3152 - CONSTANT_IDS, new IdentityHashMap(), 362.3153 - KEYWORDS, PersistentHashMap.EMPTY, 362.3154 - VARS, PersistentHashMap.EMPTY, 362.3155 - KEYWORD_CALLSITES, PersistentVector.EMPTY, 362.3156 - PROTOCOL_CALLSITES, PersistentVector.EMPTY, 362.3157 - VAR_CALLSITES, PersistentVector.EMPTY 362.3158 - )); 362.3159 - 362.3160 - //arglist might be preceded by symbol naming this fn 362.3161 - if(RT.second(form) instanceof Symbol) 362.3162 - { 362.3163 - fn.thisName = ((Symbol) RT.second(form)).name; 362.3164 - form = RT.cons(FN, RT.next(RT.next(form))); 362.3165 - } 362.3166 - 362.3167 - //now (fn [args] body...) or (fn ([args] body...) ([args2] body2...) ...) 362.3168 - //turn former into latter 362.3169 - if(RT.second(form) instanceof IPersistentVector) 362.3170 - form = RT.list(FN, RT.next(form)); 362.3171 - fn.line = (Integer) LINE.deref(); 362.3172 - FnMethod[] methodArray = new FnMethod[MAX_POSITIONAL_ARITY + 1]; 362.3173 - FnMethod variadicMethod = null; 362.3174 - for(ISeq s = RT.next(form); s != null; s = RT.next(s)) 362.3175 - { 362.3176 - FnMethod f = FnMethod.parse(fn, (ISeq) RT.first(s)); 362.3177 - if(f.isVariadic()) 362.3178 - { 362.3179 - if(variadicMethod == null) 362.3180 - variadicMethod = f; 362.3181 - else 362.3182 - throw new Exception("Can't have more than 1 variadic overload"); 362.3183 - } 362.3184 - else if(methodArray[f.reqParms.count()] == null) 362.3185 - methodArray[f.reqParms.count()] = f; 362.3186 - else 362.3187 - throw new Exception("Can't have 2 overloads with same arity"); 362.3188 - } 362.3189 - if(variadicMethod != null) 362.3190 - { 362.3191 - for(int i = variadicMethod.reqParms.count() + 1; i <= MAX_POSITIONAL_ARITY; i++) 362.3192 - if(methodArray[i] != null) 362.3193 - throw new Exception( 362.3194 - "Can't have fixed arity function with more params than variadic function"); 362.3195 - } 362.3196 - 362.3197 - IPersistentCollection methods = null; 362.3198 - for(int i = 0; i < methodArray.length; i++) 362.3199 - if(methodArray[i] != null) 362.3200 - methods = RT.conj(methods, methodArray[i]); 362.3201 - if(variadicMethod != null) 362.3202 - methods = RT.conj(methods, variadicMethod); 362.3203 - 362.3204 - fn.methods = methods; 362.3205 - fn.variadicMethod = variadicMethod; 362.3206 - fn.keywords = (IPersistentMap) KEYWORDS.deref(); 362.3207 - fn.vars = (IPersistentMap) VARS.deref(); 362.3208 - fn.constants = (PersistentVector) CONSTANTS.deref(); 362.3209 - fn.keywordCallsites = (IPersistentVector) KEYWORD_CALLSITES.deref(); 362.3210 - fn.protocolCallsites = (IPersistentVector) PROTOCOL_CALLSITES.deref(); 362.3211 - fn.varCallsites = (IPersistentVector) VAR_CALLSITES.deref(); 362.3212 - 362.3213 - fn.constantsID = RT.nextID(); 362.3214 -// DynamicClassLoader loader = (DynamicClassLoader) LOADER.get(); 362.3215 -// loader.registerConstants(fn.constantsID, fn.constants.toArray()); 362.3216 - } 362.3217 - finally 362.3218 - { 362.3219 - Var.popThreadBindings(); 362.3220 - } 362.3221 - fn.compile(fn.isVariadic() ? "clojure/lang/RestFn" : "clojure/lang/AFunction",null,fn.onceOnly); 362.3222 - fn.getCompiledClass(); 362.3223 - 362.3224 - if(origForm instanceof IObj && ((IObj) origForm).meta() != null) 362.3225 - return new MetaExpr(fn, (MapExpr) MapExpr 362.3226 - .parse(context == C.EVAL ? context : C.EXPRESSION, ((IObj) origForm).meta())); 362.3227 - else 362.3228 - return fn; 362.3229 - } 362.3230 - 362.3231 - public final ObjMethod variadicMethod(){ 362.3232 - return variadicMethod; 362.3233 - } 362.3234 - 362.3235 - boolean isVariadic(){ 362.3236 - return variadicMethod != null; 362.3237 - } 362.3238 - 362.3239 - public final IPersistentCollection methods(){ 362.3240 - return methods; 362.3241 - } 362.3242 -} 362.3243 - 362.3244 -static public class ObjExpr implements Expr{ 362.3245 - static final String CONST_PREFIX = "const__"; 362.3246 - String name; 362.3247 - //String simpleName; 362.3248 - String internalName; 362.3249 - String thisName; 362.3250 - Type objtype; 362.3251 - public final Object tag; 362.3252 - //localbinding->itself 362.3253 - IPersistentMap closes = PersistentHashMap.EMPTY; 362.3254 - //localbndingexprs 362.3255 - IPersistentVector closesExprs = PersistentVector.EMPTY; 362.3256 - //symbols 362.3257 - IPersistentSet volatiles = PersistentHashSet.EMPTY; 362.3258 - 362.3259 - //symbol->lb 362.3260 - IPersistentMap fields = null; 362.3261 - 362.3262 - //Keyword->KeywordExpr 362.3263 - IPersistentMap keywords = PersistentHashMap.EMPTY; 362.3264 - IPersistentMap vars = PersistentHashMap.EMPTY; 362.3265 - Class compiledClass; 362.3266 - int line; 362.3267 - PersistentVector constants; 362.3268 - int constantsID; 362.3269 - int altCtorDrops = 0; 362.3270 - 362.3271 - IPersistentVector keywordCallsites; 362.3272 - IPersistentVector protocolCallsites; 362.3273 - IPersistentVector varCallsites; 362.3274 - boolean onceOnly = false; 362.3275 - 362.3276 - Object src; 362.3277 - 362.3278 - final static Method voidctor = Method.getMethod("void <init>()"); 362.3279 - protected IPersistentMap classMeta; 362.3280 - 362.3281 - public final String name(){ 362.3282 - return name; 362.3283 - } 362.3284 - 362.3285 -// public final String simpleName(){ 362.3286 -// return simpleName; 362.3287 -// } 362.3288 - 362.3289 - public final String internalName(){ 362.3290 - return internalName; 362.3291 - } 362.3292 - 362.3293 - public final String thisName(){ 362.3294 - return thisName; 362.3295 - } 362.3296 - 362.3297 - public final Type objtype(){ 362.3298 - return objtype; 362.3299 - } 362.3300 - 362.3301 - public final IPersistentMap closes(){ 362.3302 - return closes; 362.3303 - } 362.3304 - 362.3305 - public final IPersistentMap keywords(){ 362.3306 - return keywords; 362.3307 - } 362.3308 - 362.3309 - public final IPersistentMap vars(){ 362.3310 - return vars; 362.3311 - } 362.3312 - 362.3313 - public final Class compiledClass(){ 362.3314 - return compiledClass; 362.3315 - } 362.3316 - 362.3317 - public final int line(){ 362.3318 - return line; 362.3319 - } 362.3320 - 362.3321 - public final PersistentVector constants(){ 362.3322 - return constants; 362.3323 - } 362.3324 - 362.3325 - public final int constantsID(){ 362.3326 - return constantsID; 362.3327 - } 362.3328 - 362.3329 - final static Method kwintern = Method.getMethod("clojure.lang.Keyword intern(String, String)"); 362.3330 - final static Method symcreate = Method.getMethod("clojure.lang.Symbol create(String)"); 362.3331 - final static Method varintern = 362.3332 - Method.getMethod("clojure.lang.Var intern(clojure.lang.Symbol, clojure.lang.Symbol)"); 362.3333 - 362.3334 - final static Type DYNAMIC_CLASSLOADER_TYPE = Type.getType(DynamicClassLoader.class); 362.3335 - final static Method getClassMethod = Method.getMethod("Class getClass()"); 362.3336 - final static Method getClassLoaderMethod = Method.getMethod("ClassLoader getClassLoader()"); 362.3337 - final static Method getConstantsMethod = Method.getMethod("Object[] getConstants(int)"); 362.3338 - final static Method readStringMethod = Method.getMethod("Object readString(String)"); 362.3339 - 362.3340 - final static Type ILOOKUP_SITE_TYPE = Type.getType(ILookupSite.class); 362.3341 - final static Type ILOOKUP_THUNK_TYPE = Type.getType(ILookupThunk.class); 362.3342 - final static Type KEYWORD_LOOKUPSITE_TYPE = Type.getType(KeywordLookupSite.class); 362.3343 - 362.3344 - private DynamicClassLoader loader; 362.3345 - private byte[] bytecode; 362.3346 - 362.3347 - public ObjExpr(Object tag){ 362.3348 - this.tag = tag; 362.3349 - } 362.3350 - 362.3351 - static String trimGenID(String name){ 362.3352 - int i = name.lastIndexOf("__"); 362.3353 - return i==-1?name:name.substring(0,i); 362.3354 - } 362.3355 - 362.3356 - 362.3357 - 362.3358 - Type[] ctorTypes(){ 362.3359 - IPersistentVector tv = isDeftype()?PersistentVector.EMPTY:RT.vector(IPERSISTENTMAP_TYPE); 362.3360 - for(ISeq s = RT.keys(closes); s != null; s = s.next()) 362.3361 - { 362.3362 - LocalBinding lb = (LocalBinding) s.first(); 362.3363 - if(lb.getPrimitiveType() != null) 362.3364 - tv = tv.cons(Type.getType(lb.getPrimitiveType())); 362.3365 - else 362.3366 - tv = tv.cons(OBJECT_TYPE); 362.3367 - } 362.3368 - Type[] ret = new Type[tv.count()]; 362.3369 - for(int i = 0; i < tv.count(); i++) 362.3370 - ret[i] = (Type) tv.nth(i); 362.3371 - return ret; 362.3372 - } 362.3373 - 362.3374 - void compile(String superName, String[] interfaceNames, boolean oneTimeUse) throws Exception{ 362.3375 - //create bytecode for a class 362.3376 - //with name current_ns.defname[$letname]+ 362.3377 - //anonymous fns get names fn__id 362.3378 - //derived from AFn/RestFn 362.3379 - if(keywordCallsites.count() > 0) 362.3380 - { 362.3381 - if(interfaceNames == null) 362.3382 - interfaceNames = new String[]{"clojure/lang/ILookupHost"}; 362.3383 - else 362.3384 - { 362.3385 - String[] inames = new String[interfaceNames.length + 1]; 362.3386 - System.arraycopy(interfaceNames,0,inames,0,interfaceNames.length); 362.3387 - inames[interfaceNames.length] = "clojure/lang/ILookupHost"; 362.3388 - interfaceNames = inames; 362.3389 - } 362.3390 - } 362.3391 - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 362.3392 -// ClassWriter cw = new ClassWriter(0); 362.3393 - ClassVisitor cv = cw; 362.3394 -// ClassVisitor cv = new TraceClassVisitor(new CheckClassAdapter(cw), new PrintWriter(System.out)); 362.3395 - //ClassVisitor cv = new TraceClassVisitor(cw, new PrintWriter(System.out)); 362.3396 - cv.visit(V1_5, ACC_PUBLIC + ACC_SUPER + ACC_FINAL, internalName, null,superName,interfaceNames); 362.3397 -// superName != null ? superName : 362.3398 -// (isVariadic() ? "clojure/lang/RestFn" : "clojure/lang/AFunction"), null); 362.3399 - String source = (String) SOURCE.deref(); 362.3400 - int lineBefore = (Integer) LINE_BEFORE.deref(); 362.3401 - int lineAfter = (Integer) LINE_AFTER.deref() + 1; 362.3402 - 362.3403 - if(source != null && SOURCE_PATH.deref() != null) 362.3404 - { 362.3405 - //cv.visitSource(source, null); 362.3406 - String smap = "SMAP\n" + 362.3407 - ((source.lastIndexOf('.') > 0) ? 362.3408 - source.substring(0, source.lastIndexOf('.')) 362.3409 - :source) 362.3410 - // : simpleName) 362.3411 - + ".java\n" + 362.3412 - "Clojure\n" + 362.3413 - "*S Clojure\n" + 362.3414 - "*F\n" + 362.3415 - "+ 1 " + source + "\n" + 362.3416 - (String) SOURCE_PATH.deref() + "\n" + 362.3417 - "*L\n" + 362.3418 - String.format("%d#1,%d:%d\n", lineBefore, lineAfter - lineBefore, lineBefore) + 362.3419 - "*E"; 362.3420 - cv.visitSource(source, smap); 362.3421 - } 362.3422 - addAnnotation(cv, classMeta); 362.3423 - //static fields for constants 362.3424 - for(int i = 0; i < constants.count(); i++) 362.3425 - { 362.3426 - cv.visitField(ACC_PUBLIC + ACC_FINAL 362.3427 - + ACC_STATIC, constantName(i), constantType(i).getDescriptor(), 362.3428 - null, null); 362.3429 - } 362.3430 - 362.3431 - //static fields for lookup sites 362.3432 - for(int i = 0; i < keywordCallsites.count(); i++) 362.3433 - { 362.3434 - cv.visitField(ACC_FINAL 362.3435 - + ACC_STATIC, siteNameStatic(i), KEYWORD_LOOKUPSITE_TYPE.getDescriptor(), 362.3436 - null, null); 362.3437 - cv.visitField(ACC_STATIC, thunkNameStatic(i), ILOOKUP_THUNK_TYPE.getDescriptor(), 362.3438 - null, null); 362.3439 - } 362.3440 - 362.3441 - for(int i=0;i<varCallsites.count();i++) 362.3442 - { 362.3443 - cv.visitField(ACC_PRIVATE + ACC_STATIC + ACC_FINAL 362.3444 - , varCallsiteName(i), IFN_TYPE.getDescriptor(), null, null); 362.3445 - } 362.3446 - 362.3447 - //static init for constants, keywords and vars 362.3448 - GeneratorAdapter clinitgen = new GeneratorAdapter(ACC_PUBLIC + ACC_STATIC, 362.3449 - Method.getMethod("void <clinit> ()"), 362.3450 - null, 362.3451 - null, 362.3452 - cv); 362.3453 - clinitgen.visitCode(); 362.3454 - clinitgen.visitLineNumber(line, clinitgen.mark()); 362.3455 - 362.3456 - if(constants.count() > 0) 362.3457 - { 362.3458 - emitConstants(clinitgen); 362.3459 - } 362.3460 - 362.3461 - if(keywordCallsites.count() > 0) 362.3462 - emitKeywordCallsites(clinitgen); 362.3463 - 362.3464 - for(int i=0;i<varCallsites.count();i++) 362.3465 - { 362.3466 - Label skipLabel = clinitgen.newLabel(); 362.3467 - Label endLabel = clinitgen.newLabel(); 362.3468 - Var var = (Var) varCallsites.nth(i); 362.3469 - clinitgen.push(var.ns.name.toString()); 362.3470 - clinitgen.push(var.sym.toString()); 362.3471 - clinitgen.invokeStatic(RT_TYPE, Method.getMethod("clojure.lang.Var var(String,String)")); 362.3472 - clinitgen.dup(); 362.3473 - clinitgen.invokeVirtual(VAR_TYPE,Method.getMethod("boolean hasRoot()")); 362.3474 - clinitgen.ifZCmp(GeneratorAdapter.EQ,skipLabel); 362.3475 - 362.3476 - clinitgen.invokeVirtual(VAR_TYPE,Method.getMethod("Object getRoot()")); 362.3477 - clinitgen.dup(); 362.3478 - clinitgen.instanceOf(AFUNCTION_TYPE); 362.3479 - clinitgen.ifZCmp(GeneratorAdapter.EQ,skipLabel); 362.3480 - clinitgen.checkCast(IFN_TYPE); 362.3481 - clinitgen.putStatic(objtype, varCallsiteName(i), IFN_TYPE); 362.3482 - clinitgen.goTo(endLabel); 362.3483 - 362.3484 - clinitgen.mark(skipLabel); 362.3485 - clinitgen.pop(); 362.3486 - 362.3487 - clinitgen.mark(endLabel); 362.3488 - } 362.3489 - 362.3490 - clinitgen.returnValue(); 362.3491 - 362.3492 - clinitgen.endMethod(); 362.3493 - if(!isDeftype()) 362.3494 - { 362.3495 - cv.visitField(ACC_FINAL, "__meta", IPERSISTENTMAP_TYPE.getDescriptor(), null, null); 362.3496 - } 362.3497 - //instance fields for closed-overs 362.3498 - for(ISeq s = RT.keys(closes); s != null; s = s.next()) 362.3499 - { 362.3500 - LocalBinding lb = (LocalBinding) s.first(); 362.3501 - if(isDeftype()) 362.3502 - { 362.3503 - int access = isVolatile(lb) ? ACC_VOLATILE : 362.3504 - isMutable(lb) ? 0 : 362.3505 - (ACC_PUBLIC + ACC_FINAL); 362.3506 - FieldVisitor fv; 362.3507 - if(lb.getPrimitiveType() != null) 362.3508 - fv = cv.visitField(access 362.3509 - , lb.name, Type.getType(lb.getPrimitiveType()).getDescriptor(), 362.3510 - null, null); 362.3511 - else 362.3512 - //todo - when closed-overs are fields, use more specific types here and in ctor and emitLocal? 362.3513 - fv = cv.visitField(access 362.3514 - , lb.name, OBJECT_TYPE.getDescriptor(), null, null); 362.3515 - addAnnotation(fv, RT.meta(lb.sym)); 362.3516 - } 362.3517 - else 362.3518 - { 362.3519 - //todo - only enable this non-private+writability for letfns where we need it 362.3520 - if(lb.getPrimitiveType() != null) 362.3521 - cv.visitField(0 + (isVolatile(lb) ? ACC_VOLATILE : 0) 362.3522 - , lb.name, Type.getType(lb.getPrimitiveType()).getDescriptor(), 362.3523 - null, null); 362.3524 - else 362.3525 - cv.visitField(0 //+ (oneTimeUse ? 0 : ACC_FINAL) 362.3526 - , lb.name, OBJECT_TYPE.getDescriptor(), null, null); 362.3527 - } 362.3528 - } 362.3529 - 362.3530 - //instance fields for callsites and thunks 362.3531 - for(int i=0;i<protocolCallsites.count();i++) 362.3532 - { 362.3533 - cv.visitField(ACC_PRIVATE, cachedClassName(i), CLASS_TYPE.getDescriptor(), null, null); 362.3534 - cv.visitField(ACC_PRIVATE, cachedProtoFnName(i), AFUNCTION_TYPE.getDescriptor(), null, null); 362.3535 - cv.visitField(ACC_PRIVATE, cachedProtoImplName(i), IFN_TYPE.getDescriptor(), null, null); 362.3536 - } 362.3537 - 362.3538 - //ctor that takes closed-overs and inits base + fields 362.3539 - Method m = new Method("<init>", Type.VOID_TYPE, ctorTypes()); 362.3540 - GeneratorAdapter ctorgen = new GeneratorAdapter(ACC_PUBLIC, 362.3541 - m, 362.3542 - null, 362.3543 - null, 362.3544 - cv); 362.3545 - Label start = ctorgen.newLabel(); 362.3546 - Label end = ctorgen.newLabel(); 362.3547 - ctorgen.visitCode(); 362.3548 - ctorgen.visitLineNumber(line, ctorgen.mark()); 362.3549 - ctorgen.visitLabel(start); 362.3550 - ctorgen.loadThis(); 362.3551 -// if(superName != null) 362.3552 - ctorgen.invokeConstructor(Type.getObjectType(superName), voidctor); 362.3553 -// else if(isVariadic()) //RestFn ctor takes reqArity arg 362.3554 -// { 362.3555 -// ctorgen.push(variadicMethod.reqParms.count()); 362.3556 -// ctorgen.invokeConstructor(restFnType, restfnctor); 362.3557 -// } 362.3558 -// else 362.3559 -// ctorgen.invokeConstructor(aFnType, voidctor); 362.3560 - if(!isDeftype()) 362.3561 - { 362.3562 - ctorgen.loadThis(); 362.3563 - ctorgen.visitVarInsn(IPERSISTENTMAP_TYPE.getOpcode(Opcodes.ILOAD), 1); 362.3564 - ctorgen.putField(objtype, "__meta", IPERSISTENTMAP_TYPE); 362.3565 - } 362.3566 - 362.3567 - int a = isDeftype()?1:2; 362.3568 - for(ISeq s = RT.keys(closes); s != null; s = s.next(), ++a) 362.3569 - { 362.3570 - LocalBinding lb = (LocalBinding) s.first(); 362.3571 - ctorgen.loadThis(); 362.3572 - Class primc = lb.getPrimitiveType(); 362.3573 - if(primc != null) 362.3574 - { 362.3575 - ctorgen.visitVarInsn(Type.getType(primc).getOpcode(Opcodes.ILOAD), a); 362.3576 - ctorgen.putField(objtype, lb.name, Type.getType(primc)); 362.3577 - if(primc == Long.TYPE || primc == Double.TYPE) 362.3578 - ++a; 362.3579 - } 362.3580 - else 362.3581 - { 362.3582 - ctorgen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ILOAD), a); 362.3583 - ctorgen.putField(objtype, lb.name, OBJECT_TYPE); 362.3584 - } 362.3585 - closesExprs = closesExprs.cons(new LocalBindingExpr(lb, null)); 362.3586 - } 362.3587 - 362.3588 - 362.3589 - ctorgen.visitLabel(end); 362.3590 - 362.3591 - ctorgen.returnValue(); 362.3592 - 362.3593 - ctorgen.endMethod(); 362.3594 - 362.3595 - if(altCtorDrops > 0) 362.3596 - { 362.3597 - //ctor that takes closed-overs and inits base + fields 362.3598 - Type[] ctorTypes = ctorTypes(); 362.3599 - Type[] altCtorTypes = new Type[ctorTypes.length-altCtorDrops]; 362.3600 - for(int i=0;i<altCtorTypes.length;i++) 362.3601 - altCtorTypes[i] = ctorTypes[i]; 362.3602 - Method alt = new Method("<init>", Type.VOID_TYPE, altCtorTypes); 362.3603 - ctorgen = new GeneratorAdapter(ACC_PUBLIC, 362.3604 - alt, 362.3605 - null, 362.3606 - null, 362.3607 - cv); 362.3608 - ctorgen.visitCode(); 362.3609 - ctorgen.loadThis(); 362.3610 - ctorgen.loadArgs(); 362.3611 - for(int i=0;i<altCtorDrops;i++) 362.3612 - ctorgen.visitInsn(Opcodes.ACONST_NULL); 362.3613 - 362.3614 - ctorgen.invokeConstructor(objtype, new Method("<init>", Type.VOID_TYPE, ctorTypes)); 362.3615 - 362.3616 - ctorgen.returnValue(); 362.3617 - ctorgen.endMethod(); 362.3618 - } 362.3619 - 362.3620 - if(!isDeftype()) 362.3621 - { 362.3622 - //ctor that takes closed-overs but not meta 362.3623 - Type[] ctorTypes = ctorTypes(); 362.3624 - Type[] noMetaCtorTypes = new Type[ctorTypes.length-1]; 362.3625 - for(int i=1;i<ctorTypes.length;i++) 362.3626 - noMetaCtorTypes[i-1] = ctorTypes[i]; 362.3627 - Method alt = new Method("<init>", Type.VOID_TYPE, noMetaCtorTypes); 362.3628 - ctorgen = new GeneratorAdapter(ACC_PUBLIC, 362.3629 - alt, 362.3630 - null, 362.3631 - null, 362.3632 - cv); 362.3633 - ctorgen.visitCode(); 362.3634 - ctorgen.loadThis(); 362.3635 - ctorgen.visitInsn(Opcodes.ACONST_NULL); //null meta 362.3636 - ctorgen.loadArgs(); 362.3637 - ctorgen.invokeConstructor(objtype, new Method("<init>", Type.VOID_TYPE, ctorTypes)); 362.3638 - 362.3639 - ctorgen.returnValue(); 362.3640 - ctorgen.endMethod(); 362.3641 - 362.3642 - //meta() 362.3643 - Method meth = Method.getMethod("clojure.lang.IPersistentMap meta()"); 362.3644 - 362.3645 - GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC, 362.3646 - meth, 362.3647 - null, 362.3648 - null, 362.3649 - cv); 362.3650 - gen.visitCode(); 362.3651 - gen.loadThis(); 362.3652 - gen.getField(objtype,"__meta",IPERSISTENTMAP_TYPE); 362.3653 - 362.3654 - gen.returnValue(); 362.3655 - gen.endMethod(); 362.3656 - 362.3657 - //withMeta() 362.3658 - meth = Method.getMethod("clojure.lang.IObj withMeta(clojure.lang.IPersistentMap)"); 362.3659 - 362.3660 - gen = new GeneratorAdapter(ACC_PUBLIC, 362.3661 - meth, 362.3662 - null, 362.3663 - null, 362.3664 - cv); 362.3665 - gen.visitCode(); 362.3666 - gen.newInstance(objtype); 362.3667 - gen.dup(); 362.3668 - gen.loadArg(0); 362.3669 - 362.3670 - for(ISeq s = RT.keys(closes); s != null; s = s.next(), ++a) 362.3671 - { 362.3672 - LocalBinding lb = (LocalBinding) s.first(); 362.3673 - gen.loadThis(); 362.3674 - Class primc = lb.getPrimitiveType(); 362.3675 - if(primc != null) 362.3676 - { 362.3677 - gen.getField(objtype, lb.name, Type.getType(primc)); 362.3678 - } 362.3679 - else 362.3680 - { 362.3681 - gen.getField(objtype, lb.name, OBJECT_TYPE); 362.3682 - } 362.3683 - } 362.3684 - 362.3685 - gen.invokeConstructor(objtype, new Method("<init>", Type.VOID_TYPE, ctorTypes)); 362.3686 - gen.returnValue(); 362.3687 - gen.endMethod(); 362.3688 - } 362.3689 - 362.3690 - emitMethods(cv); 362.3691 - 362.3692 - if(keywordCallsites.count() > 0) 362.3693 - { 362.3694 - Method meth = Method.getMethod("void swapThunk(int,clojure.lang.ILookupThunk)"); 362.3695 - 362.3696 - GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC, 362.3697 - meth, 362.3698 - null, 362.3699 - null, 362.3700 - cv); 362.3701 - gen.visitCode(); 362.3702 - Label endLabel = gen.newLabel(); 362.3703 - 362.3704 - Label[] labels = new Label[keywordCallsites.count()]; 362.3705 - for(int i = 0; i < keywordCallsites.count();i++) 362.3706 - { 362.3707 - labels[i] = gen.newLabel(); 362.3708 - } 362.3709 - gen.loadArg(0); 362.3710 - gen.visitTableSwitchInsn(0,keywordCallsites.count()-1,endLabel,labels); 362.3711 - 362.3712 - for(int i = 0; i < keywordCallsites.count();i++) 362.3713 - { 362.3714 - gen.mark(labels[i]); 362.3715 -// gen.loadThis(); 362.3716 - gen.loadArg(1); 362.3717 - gen.putStatic(objtype, thunkNameStatic(i),ILOOKUP_THUNK_TYPE); 362.3718 - gen.goTo(endLabel); 362.3719 - } 362.3720 - 362.3721 - gen.mark(endLabel); 362.3722 - 362.3723 - gen.returnValue(); 362.3724 - gen.endMethod(); 362.3725 - } 362.3726 - 362.3727 - //end of class 362.3728 - cv.visitEnd(); 362.3729 - 362.3730 - bytecode = cw.toByteArray(); 362.3731 - if(RT.booleanCast(COMPILE_FILES.deref())) 362.3732 - writeClassFile(internalName, bytecode); 362.3733 -// else 362.3734 -// getCompiledClass(); 362.3735 - } 362.3736 - 362.3737 - private void emitKeywordCallsites(GeneratorAdapter clinitgen){ 362.3738 - for(int i=0;i<keywordCallsites.count();i++) 362.3739 - { 362.3740 - Keyword k = (Keyword) keywordCallsites.nth(i); 362.3741 - clinitgen.newInstance(KEYWORD_LOOKUPSITE_TYPE); 362.3742 - clinitgen.dup(); 362.3743 - clinitgen.push(i); 362.3744 - emitValue(k,clinitgen); 362.3745 - clinitgen.invokeConstructor(KEYWORD_LOOKUPSITE_TYPE, 362.3746 - Method.getMethod("void <init>(int,clojure.lang.Keyword)")); 362.3747 - clinitgen.dup(); 362.3748 - clinitgen.putStatic(objtype, siteNameStatic(i), KEYWORD_LOOKUPSITE_TYPE); 362.3749 - clinitgen.putStatic(objtype, thunkNameStatic(i), ILOOKUP_THUNK_TYPE); 362.3750 - } 362.3751 - } 362.3752 - 362.3753 - protected void emitMethods(ClassVisitor gen){ 362.3754 - } 362.3755 - 362.3756 - void emitListAsObjectArray(Object value, GeneratorAdapter gen){ 362.3757 - gen.push(((List) value).size()); 362.3758 - gen.newArray(OBJECT_TYPE); 362.3759 - int i = 0; 362.3760 - for(Iterator it = ((List) value).iterator(); it.hasNext(); i++) 362.3761 - { 362.3762 - gen.dup(); 362.3763 - gen.push(i); 362.3764 - emitValue(it.next(), gen); 362.3765 - gen.arrayStore(OBJECT_TYPE); 362.3766 - } 362.3767 - } 362.3768 - 362.3769 - void emitValue(Object value, GeneratorAdapter gen){ 362.3770 - boolean partial = true; 362.3771 - //System.out.println(value.getClass().toString()); 362.3772 - 362.3773 - if(value instanceof String) 362.3774 - { 362.3775 - gen.push((String) value); 362.3776 - } 362.3777 - else if(value instanceof Integer) 362.3778 - { 362.3779 - gen.push(((Integer) value).intValue()); 362.3780 - gen.invokeStatic(Type.getType(Integer.class), Method.getMethod("Integer valueOf(int)")); 362.3781 - } 362.3782 - else if(value instanceof Double) 362.3783 - { 362.3784 - gen.push(((Double) value).doubleValue()); 362.3785 - gen.invokeStatic(Type.getType(Double.class), Method.getMethod("Double valueOf(double)")); 362.3786 - } 362.3787 - else if(value instanceof Character) 362.3788 - { 362.3789 - gen.push(((Character) value).charValue()); 362.3790 - gen.invokeStatic(Type.getType(Character.class), Method.getMethod("Character valueOf(char)")); 362.3791 - } 362.3792 - else if(value instanceof Class) 362.3793 - { 362.3794 - Class cc = (Class)value; 362.3795 - if(cc.isPrimitive()) 362.3796 - { 362.3797 - Type bt; 362.3798 - if ( cc == boolean.class ) bt = Type.getType(Boolean.class); 362.3799 - else if ( cc == byte.class ) bt = Type.getType(Byte.class); 362.3800 - else if ( cc == char.class ) bt = Type.getType(Character.class); 362.3801 - else if ( cc == double.class ) bt = Type.getType(Double.class); 362.3802 - else if ( cc == float.class ) bt = Type.getType(Float.class); 362.3803 - else if ( cc == int.class ) bt = Type.getType(Integer.class); 362.3804 - else if ( cc == long.class ) bt = Type.getType(Long.class); 362.3805 - else if ( cc == short.class ) bt = Type.getType(Short.class); 362.3806 - else throw new RuntimeException( 362.3807 - "Can't embed unknown primitive in code: " + value); 362.3808 - gen.getStatic( bt, "TYPE", Type.getType(Class.class) ); 362.3809 - } 362.3810 - else 362.3811 - { 362.3812 - gen.push(destubClassName(cc.getName())); 362.3813 - gen.invokeStatic(Type.getType(Class.class), Method.getMethod("Class forName(String)")); 362.3814 - } 362.3815 - } 362.3816 - else if(value instanceof Symbol) 362.3817 - { 362.3818 - gen.push(((Symbol) value).ns); 362.3819 - gen.push(((Symbol) value).name); 362.3820 - gen.invokeStatic(Type.getType(Symbol.class), 362.3821 - Method.getMethod("clojure.lang.Symbol create(String,String)")); 362.3822 - } 362.3823 - else if(value instanceof Keyword) 362.3824 - { 362.3825 - emitValue(((Keyword) value).sym, gen); 362.3826 - gen.invokeStatic(Type.getType(Keyword.class), 362.3827 - Method.getMethod("clojure.lang.Keyword intern(clojure.lang.Symbol)")); 362.3828 - } 362.3829 -// else if(value instanceof KeywordCallSite) 362.3830 -// { 362.3831 -// emitValue(((KeywordCallSite) value).k.sym, gen); 362.3832 -// gen.invokeStatic(Type.getType(KeywordCallSite.class), 362.3833 -// Method.getMethod("clojure.lang.KeywordCallSite create(clojure.lang.Symbol)")); 362.3834 -// } 362.3835 - else if(value instanceof Var) 362.3836 - { 362.3837 - Var var = (Var) value; 362.3838 - gen.push(var.ns.name.toString()); 362.3839 - gen.push(var.sym.toString()); 362.3840 - gen.invokeStatic(RT_TYPE, Method.getMethod("clojure.lang.Var var(String,String)")); 362.3841 - } 362.3842 - else if(value instanceof IPersistentMap) 362.3843 - { 362.3844 - List entries = new ArrayList(); 362.3845 - for(Map.Entry entry : (Set<Map.Entry>) ((Map) value).entrySet()) 362.3846 - { 362.3847 - entries.add(entry.getKey()); 362.3848 - entries.add(entry.getValue()); 362.3849 - } 362.3850 - emitListAsObjectArray(entries, gen); 362.3851 - gen.invokeStatic(RT_TYPE, 362.3852 - Method.getMethod("clojure.lang.IPersistentMap map(Object[])")); 362.3853 - } 362.3854 - else if(value instanceof IPersistentVector) 362.3855 - { 362.3856 - emitListAsObjectArray(value, gen); 362.3857 - gen.invokeStatic(RT_TYPE, Method.getMethod( 362.3858 - "clojure.lang.IPersistentVector vector(Object[])")); 362.3859 - } 362.3860 - else if(value instanceof ISeq || value instanceof IPersistentList) 362.3861 - { 362.3862 - emitListAsObjectArray(value, gen); 362.3863 - gen.invokeStatic(Type.getType(java.util.Arrays.class), 362.3864 - Method.getMethod("java.util.List asList(Object[])")); 362.3865 - gen.invokeStatic(Type.getType(PersistentList.class), 362.3866 - Method.getMethod( 362.3867 - "clojure.lang.IPersistentList create(java.util.List)")); 362.3868 - } 362.3869 - else 362.3870 - { 362.3871 - String cs = null; 362.3872 - try 362.3873 - { 362.3874 - cs = RT.printString(value); 362.3875 - //System.out.println("WARNING SLOW CODE: " + value.getClass() + " -> " + cs); 362.3876 - } 362.3877 - catch(Exception e) 362.3878 - { 362.3879 - throw new RuntimeException( 362.3880 - "Can't embed object in code, maybe print-dup not defined: " + 362.3881 - value); 362.3882 - } 362.3883 - if(cs.length() == 0) 362.3884 - throw new RuntimeException( 362.3885 - "Can't embed unreadable object in code: " + value); 362.3886 - 362.3887 - if(cs.startsWith("#<")) 362.3888 - throw new RuntimeException( 362.3889 - "Can't embed unreadable object in code: " + cs); 362.3890 - 362.3891 - gen.push(cs); 362.3892 - gen.invokeStatic(RT_TYPE, readStringMethod); 362.3893 - partial = false; 362.3894 - } 362.3895 - 362.3896 - if(partial) 362.3897 - { 362.3898 - if(value instanceof IObj && RT.count(((IObj) value).meta()) > 0) 362.3899 - { 362.3900 - gen.checkCast(IOBJ_TYPE); 362.3901 - emitValue(((IObj) value).meta(), gen); 362.3902 - gen.checkCast(IPERSISTENTMAP_TYPE); 362.3903 - gen.invokeInterface(IOBJ_TYPE, 362.3904 - Method.getMethod("clojure.lang.IObj withMeta(clojure.lang.IPersistentMap)")); 362.3905 - } 362.3906 - } 362.3907 - } 362.3908 - 362.3909 - 362.3910 - void emitConstants(GeneratorAdapter clinitgen){ 362.3911 - try 362.3912 - { 362.3913 - Var.pushThreadBindings(RT.map(RT.PRINT_DUP, RT.T)); 362.3914 - 362.3915 - for(int i = 0; i < constants.count(); i++) 362.3916 - { 362.3917 - emitValue(constants.nth(i), clinitgen); 362.3918 - clinitgen.checkCast(constantType(i)); 362.3919 - clinitgen.putStatic(objtype, constantName(i), constantType(i)); 362.3920 - } 362.3921 - } 362.3922 - finally 362.3923 - { 362.3924 - Var.popThreadBindings(); 362.3925 - } 362.3926 - } 362.3927 - 362.3928 - boolean isMutable(LocalBinding lb){ 362.3929 - return isVolatile(lb) || 362.3930 - RT.booleanCast(RT.contains(fields, lb.sym)) && 362.3931 - RT.booleanCast(RT.get(lb.sym.meta(), Keyword.intern("unsynchronized-mutable"))); 362.3932 - } 362.3933 - 362.3934 - boolean isVolatile(LocalBinding lb){ 362.3935 - return RT.booleanCast(RT.contains(fields, lb.sym)) && 362.3936 - RT.booleanCast(RT.get(lb.sym.meta(), Keyword.intern("volatile-mutable"))); 362.3937 - } 362.3938 - 362.3939 - boolean isDeftype(){ 362.3940 - return fields != null; 362.3941 - } 362.3942 - 362.3943 - void emitClearCloses(GeneratorAdapter gen){ 362.3944 -// int a = 1; 362.3945 -// for(ISeq s = RT.keys(closes); s != null; s = s.next(), ++a) 362.3946 -// { 362.3947 -// LocalBinding lb = (LocalBinding) s.first(); 362.3948 -// Class primc = lb.getPrimitiveType(); 362.3949 -// if(primc == null) 362.3950 -// { 362.3951 -// gen.loadThis(); 362.3952 -// gen.visitInsn(Opcodes.ACONST_NULL); 362.3953 -// gen.putField(objtype, lb.name, OBJECT_TYPE); 362.3954 -// } 362.3955 -// } 362.3956 - } 362.3957 - 362.3958 - synchronized Class getCompiledClass(){ 362.3959 - if(compiledClass == null) 362.3960 - try 362.3961 - { 362.3962 -// if(RT.booleanCast(COMPILE_FILES.deref())) 362.3963 -// compiledClass = RT.classForName(name);//loader.defineClass(name, bytecode); 362.3964 -// else 362.3965 - { 362.3966 - loader = (DynamicClassLoader) LOADER.deref(); 362.3967 - compiledClass = loader.defineClass(name, bytecode, src); 362.3968 - } 362.3969 - } 362.3970 - catch(Exception e) 362.3971 - { 362.3972 - throw new RuntimeException(e); 362.3973 - } 362.3974 - return compiledClass; 362.3975 - } 362.3976 - 362.3977 - public Object eval() throws Exception{ 362.3978 - if(isDeftype()) 362.3979 - return null; 362.3980 - return getCompiledClass().newInstance(); 362.3981 - } 362.3982 - 362.3983 - public void emitLetFnInits(GeneratorAdapter gen, ObjExpr objx, IPersistentSet letFnLocals){ 362.3984 - //objx arg is enclosing objx, not this 362.3985 - gen.checkCast(objtype); 362.3986 - 362.3987 - for(ISeq s = RT.keys(closes); s != null; s = s.next()) 362.3988 - { 362.3989 - LocalBinding lb = (LocalBinding) s.first(); 362.3990 - if(letFnLocals.contains(lb)) 362.3991 - { 362.3992 - Class primc = lb.getPrimitiveType(); 362.3993 - gen.dup(); 362.3994 - if(primc != null) 362.3995 - { 362.3996 - objx.emitUnboxedLocal(gen, lb); 362.3997 - gen.putField(objtype, lb.name, Type.getType(primc)); 362.3998 - } 362.3999 - else 362.4000 - { 362.4001 - objx.emitLocal(gen, lb, false); 362.4002 - gen.putField(objtype, lb.name, OBJECT_TYPE); 362.4003 - } 362.4004 - } 362.4005 - } 362.4006 - gen.pop(); 362.4007 - 362.4008 - } 362.4009 - 362.4010 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.4011 - //emitting a Fn means constructing an instance, feeding closed-overs from enclosing scope, if any 362.4012 - //objx arg is enclosing objx, not this 362.4013 -// getCompiledClass(); 362.4014 - if(isDeftype()) 362.4015 - { 362.4016 - gen.visitInsn(Opcodes.ACONST_NULL); 362.4017 - } 362.4018 - else 362.4019 - { 362.4020 - gen.newInstance(objtype); 362.4021 - gen.dup(); 362.4022 - gen.visitInsn(Opcodes.ACONST_NULL); 362.4023 - for(ISeq s = RT.seq(closesExprs); s != null; s = s.next()) 362.4024 - { 362.4025 - LocalBindingExpr lbe = (LocalBindingExpr) s.first(); 362.4026 - LocalBinding lb = lbe.b; 362.4027 - if(lb.getPrimitiveType() != null) 362.4028 - objx.emitUnboxedLocal(gen, lb); 362.4029 - else 362.4030 - objx.emitLocal(gen, lb, lbe.shouldClear); 362.4031 - } 362.4032 - gen.invokeConstructor(objtype, new Method("<init>", Type.VOID_TYPE, ctorTypes())); 362.4033 - } 362.4034 - if(context == C.STATEMENT) 362.4035 - gen.pop(); 362.4036 - } 362.4037 - 362.4038 - public boolean hasJavaClass() throws Exception{ 362.4039 - return true; 362.4040 - } 362.4041 - 362.4042 - public Class getJavaClass() throws Exception{ 362.4043 - return (compiledClass != null) ? compiledClass 362.4044 - : (tag != null) ? HostExpr.tagToClass(tag) 362.4045 - : IFn.class; 362.4046 - } 362.4047 - 362.4048 - public void emitAssignLocal(GeneratorAdapter gen, LocalBinding lb,Expr val){ 362.4049 - if(!isMutable(lb)) 362.4050 - throw new IllegalArgumentException("Cannot assign to non-mutable: " + lb.name); 362.4051 - Class primc = lb.getPrimitiveType(); 362.4052 - gen.loadThis(); 362.4053 - if(primc != null) 362.4054 - { 362.4055 - if(!(val instanceof MaybePrimitiveExpr && ((MaybePrimitiveExpr) val).canEmitPrimitive())) 362.4056 - throw new IllegalArgumentException("Must assign primitive to primitive mutable: " + lb.name); 362.4057 - MaybePrimitiveExpr me = (MaybePrimitiveExpr) val; 362.4058 - me.emitUnboxed(C.EXPRESSION, this, gen); 362.4059 - gen.putField(objtype, lb.name, Type.getType(primc)); 362.4060 - } 362.4061 - else 362.4062 - { 362.4063 - val.emit(C.EXPRESSION, this, gen); 362.4064 - gen.putField(objtype, lb.name, OBJECT_TYPE); 362.4065 - } 362.4066 - } 362.4067 - 362.4068 - private void emitLocal(GeneratorAdapter gen, LocalBinding lb, boolean clear){ 362.4069 - if(closes.containsKey(lb)) 362.4070 - { 362.4071 - Class primc = lb.getPrimitiveType(); 362.4072 - gen.loadThis(); 362.4073 - if(primc != null) 362.4074 - { 362.4075 - gen.getField(objtype, lb.name, Type.getType(primc)); 362.4076 - HostExpr.emitBoxReturn(this, gen, primc); 362.4077 - } 362.4078 - else 362.4079 - { 362.4080 - gen.getField(objtype, lb.name, OBJECT_TYPE); 362.4081 - if(onceOnly && clear && lb.canBeCleared) 362.4082 - { 362.4083 - gen.loadThis(); 362.4084 - gen.visitInsn(Opcodes.ACONST_NULL); 362.4085 - gen.putField(objtype, lb.name, OBJECT_TYPE); 362.4086 - } 362.4087 - } 362.4088 - } 362.4089 - else 362.4090 - { 362.4091 - Class primc = lb.getPrimitiveType(); 362.4092 -// String rep = lb.sym.name + " " + lb.toString().substring(lb.toString().lastIndexOf('@')); 362.4093 - if(lb.isArg) 362.4094 - { 362.4095 - gen.loadArg(lb.idx-1); 362.4096 - if(primc != null) 362.4097 - HostExpr.emitBoxReturn(this, gen, primc); 362.4098 - else 362.4099 - { 362.4100 - if(clear && lb.canBeCleared) 362.4101 - { 362.4102 -// System.out.println("clear: " + rep); 362.4103 - gen.visitInsn(Opcodes.ACONST_NULL); 362.4104 - gen.storeArg(lb.idx - 1); 362.4105 - } 362.4106 - else 362.4107 - { 362.4108 -// System.out.println("use: " + rep); 362.4109 - } 362.4110 - } 362.4111 - } 362.4112 - else 362.4113 - { 362.4114 - if(primc != null) 362.4115 - { 362.4116 - gen.visitVarInsn(Type.getType(primc).getOpcode(Opcodes.ILOAD), lb.idx); 362.4117 - HostExpr.emitBoxReturn(this, gen, primc); 362.4118 - } 362.4119 - else 362.4120 - { 362.4121 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ILOAD), lb.idx); 362.4122 - if(clear && lb.canBeCleared) 362.4123 - { 362.4124 -// System.out.println("clear: " + rep); 362.4125 - gen.visitInsn(Opcodes.ACONST_NULL); 362.4126 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), lb.idx); 362.4127 - } 362.4128 - else 362.4129 - { 362.4130 -// System.out.println("use: " + rep); 362.4131 - } 362.4132 - } 362.4133 - } 362.4134 - } 362.4135 - } 362.4136 - 362.4137 - private void emitUnboxedLocal(GeneratorAdapter gen, LocalBinding lb){ 362.4138 - Class primc = lb.getPrimitiveType(); 362.4139 - if(closes.containsKey(lb)) 362.4140 - { 362.4141 - gen.loadThis(); 362.4142 - gen.getField(objtype, lb.name, Type.getType(primc)); 362.4143 - } 362.4144 - else if(lb.isArg) 362.4145 - gen.loadArg(lb.idx-1); 362.4146 - else 362.4147 - gen.visitVarInsn(Type.getType(primc).getOpcode(Opcodes.ILOAD), lb.idx); 362.4148 - } 362.4149 - 362.4150 - public void emitVar(GeneratorAdapter gen, Var var){ 362.4151 - Integer i = (Integer) vars.valAt(var); 362.4152 - emitConstant(gen, i); 362.4153 - //gen.getStatic(fntype, munge(var.sym.toString()), VAR_TYPE); 362.4154 - } 362.4155 - 362.4156 - public void emitKeyword(GeneratorAdapter gen, Keyword k){ 362.4157 - Integer i = (Integer) keywords.valAt(k); 362.4158 - emitConstant(gen, i); 362.4159 -// gen.getStatic(fntype, munge(k.sym.toString()), KEYWORD_TYPE); 362.4160 - } 362.4161 - 362.4162 - public void emitConstant(GeneratorAdapter gen, int id){ 362.4163 - gen.getStatic(objtype, constantName(id), constantType(id)); 362.4164 - } 362.4165 - 362.4166 - 362.4167 - String constantName(int id){ 362.4168 - return CONST_PREFIX + id; 362.4169 - } 362.4170 - 362.4171 - String siteName(int n){ 362.4172 - return "__site__" + n; 362.4173 - } 362.4174 - 362.4175 - String siteNameStatic(int n){ 362.4176 - return siteName(n) + "__"; 362.4177 - } 362.4178 - 362.4179 - String thunkName(int n){ 362.4180 - return "__thunk__" + n; 362.4181 - } 362.4182 - 362.4183 - String cachedClassName(int n){ 362.4184 - return "__cached_class__" + n; 362.4185 - } 362.4186 - 362.4187 - String cachedProtoFnName(int n){ 362.4188 - return "__cached_proto_fn__" + n; 362.4189 - } 362.4190 - 362.4191 - String cachedProtoImplName(int n){ 362.4192 - return "__cached_proto_impl__" + n; 362.4193 - } 362.4194 - 362.4195 - String varCallsiteName(int n){ 362.4196 - return "__var__callsite__" + n; 362.4197 - } 362.4198 - 362.4199 - String thunkNameStatic(int n){ 362.4200 - return thunkName(n) + "__"; 362.4201 - } 362.4202 - 362.4203 - Type constantType(int id){ 362.4204 - Object o = constants.nth(id); 362.4205 - Class c = o.getClass(); 362.4206 - if(Modifier.isPublic(c.getModifiers())) 362.4207 - { 362.4208 - //can't emit derived fn types due to visibility 362.4209 - if(LazySeq.class.isAssignableFrom(c)) 362.4210 - return Type.getType(ISeq.class); 362.4211 - else if(c == Keyword.class) 362.4212 - return Type.getType(Keyword.class); 362.4213 -// else if(c == KeywordCallSite.class) 362.4214 -// return Type.getType(KeywordCallSite.class); 362.4215 - else if(RestFn.class.isAssignableFrom(c)) 362.4216 - return Type.getType(RestFn.class); 362.4217 - else if(AFn.class.isAssignableFrom(c)) 362.4218 - return Type.getType(AFn.class); 362.4219 - else if(c == Var.class) 362.4220 - return Type.getType(Var.class); 362.4221 - else if(c == String.class) 362.4222 - return Type.getType(String.class); 362.4223 - 362.4224 -// return Type.getType(c); 362.4225 - } 362.4226 - return OBJECT_TYPE; 362.4227 - } 362.4228 - 362.4229 -} 362.4230 - 362.4231 -enum PATHTYPE { 362.4232 - PATH, BRANCH; 362.4233 -} 362.4234 - 362.4235 -static class PathNode{ 362.4236 - final PATHTYPE type; 362.4237 - final PathNode parent; 362.4238 - 362.4239 - PathNode(PATHTYPE type, PathNode parent) { 362.4240 - this.type = type; 362.4241 - this.parent = parent; 362.4242 - } 362.4243 -} 362.4244 - 362.4245 -static PathNode clearPathRoot(){ 362.4246 - return (PathNode) CLEAR_ROOT.get(); 362.4247 -} 362.4248 - 362.4249 -enum PSTATE{ 362.4250 - REQ, REST, DONE 362.4251 -} 362.4252 - 362.4253 -public static class FnMethod extends ObjMethod{ 362.4254 - //localbinding->localbinding 362.4255 - PersistentVector reqParms = PersistentVector.EMPTY; 362.4256 - LocalBinding restParm = null; 362.4257 - 362.4258 - public FnMethod(ObjExpr objx, ObjMethod parent){ 362.4259 - super(objx, parent); 362.4260 - } 362.4261 - 362.4262 - static FnMethod parse(ObjExpr objx, ISeq form) throws Exception{ 362.4263 - //([args] body...) 362.4264 - IPersistentVector parms = (IPersistentVector) RT.first(form); 362.4265 - ISeq body = RT.next(form); 362.4266 - try 362.4267 - { 362.4268 - FnMethod method = new FnMethod(objx, (ObjMethod) METHOD.deref()); 362.4269 - method.line = (Integer) LINE.deref(); 362.4270 - //register as the current method and set up a new env frame 362.4271 - PathNode pnode = (PathNode) CLEAR_PATH.get(); 362.4272 - if(pnode == null) 362.4273 - pnode = new PathNode(PATHTYPE.PATH,null); 362.4274 - Var.pushThreadBindings( 362.4275 - RT.map( 362.4276 - METHOD, method, 362.4277 - LOCAL_ENV, LOCAL_ENV.deref(), 362.4278 - LOOP_LOCALS, null, 362.4279 - NEXT_LOCAL_NUM, 0 362.4280 - ,CLEAR_PATH, pnode 362.4281 - ,CLEAR_ROOT, pnode 362.4282 - ,CLEAR_SITES, PersistentHashMap.EMPTY 362.4283 - )); 362.4284 - 362.4285 - //register 'this' as local 0 362.4286 - //registerLocal(THISFN, null, null); 362.4287 - if(objx.thisName != null) 362.4288 - registerLocal(Symbol.intern(objx.thisName), null, null,false); 362.4289 - else 362.4290 - getAndIncLocalNum(); 362.4291 - PSTATE state = PSTATE.REQ; 362.4292 - PersistentVector argLocals = PersistentVector.EMPTY; 362.4293 - for(int i = 0; i < parms.count(); i++) 362.4294 - { 362.4295 - if(!(parms.nth(i) instanceof Symbol)) 362.4296 - throw new IllegalArgumentException("fn params must be Symbols"); 362.4297 - Symbol p = (Symbol) parms.nth(i); 362.4298 - if(p.getNamespace() != null) 362.4299 - throw new Exception("Can't use qualified name as parameter: " + p); 362.4300 - if(p.equals(_AMP_)) 362.4301 - { 362.4302 - if(state == PSTATE.REQ) 362.4303 - state = PSTATE.REST; 362.4304 - else 362.4305 - throw new Exception("Invalid parameter list"); 362.4306 - } 362.4307 - 362.4308 - else 362.4309 - { 362.4310 - LocalBinding lb = registerLocal(p, state == PSTATE.REST ? ISEQ : tagOf(p), null,true); 362.4311 - argLocals = argLocals.cons(lb); 362.4312 - switch(state) 362.4313 - { 362.4314 - case REQ: 362.4315 - method.reqParms = method.reqParms.cons(lb); 362.4316 - break; 362.4317 - case REST: 362.4318 - method.restParm = lb; 362.4319 - state = PSTATE.DONE; 362.4320 - break; 362.4321 - 362.4322 - default: 362.4323 - throw new Exception("Unexpected parameter"); 362.4324 - } 362.4325 - } 362.4326 - } 362.4327 - if(method.reqParms.count() > MAX_POSITIONAL_ARITY) 362.4328 - throw new Exception("Can't specify more than " + MAX_POSITIONAL_ARITY + " params"); 362.4329 - LOOP_LOCALS.set(argLocals); 362.4330 - method.argLocals = argLocals; 362.4331 - method.body = (new BodyExpr.Parser()).parse(C.RETURN, body); 362.4332 - return method; 362.4333 - } 362.4334 - finally 362.4335 - { 362.4336 - Var.popThreadBindings(); 362.4337 - } 362.4338 - } 362.4339 - 362.4340 - public final PersistentVector reqParms(){ 362.4341 - return reqParms; 362.4342 - } 362.4343 - 362.4344 - public final LocalBinding restParm(){ 362.4345 - return restParm; 362.4346 - } 362.4347 - 362.4348 - boolean isVariadic(){ 362.4349 - return restParm != null; 362.4350 - } 362.4351 - 362.4352 - int numParams(){ 362.4353 - return reqParms.count() + (isVariadic() ? 1 : 0); 362.4354 - } 362.4355 - 362.4356 - String getMethodName(){ 362.4357 - return isVariadic()?"doInvoke":"invoke"; 362.4358 - } 362.4359 - 362.4360 - Type getReturnType(){ 362.4361 - return OBJECT_TYPE; 362.4362 - } 362.4363 - 362.4364 - Type[] getArgTypes(){ 362.4365 - if(isVariadic() && reqParms.count() == MAX_POSITIONAL_ARITY) 362.4366 - { 362.4367 - Type[] ret = new Type[MAX_POSITIONAL_ARITY + 1]; 362.4368 - for(int i = 0;i<MAX_POSITIONAL_ARITY + 1;i++) 362.4369 - ret[i] = OBJECT_TYPE; 362.4370 - return ret; 362.4371 - } 362.4372 - return ARG_TYPES[numParams()]; 362.4373 - } 362.4374 - 362.4375 - void emitClearLocals(GeneratorAdapter gen){ 362.4376 -// for(int i = 1; i < numParams() + 1; i++) 362.4377 -// { 362.4378 -// if(!localsUsedInCatchFinally.contains(i)) 362.4379 -// { 362.4380 -// gen.visitInsn(Opcodes.ACONST_NULL); 362.4381 -// gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i); 362.4382 -// } 362.4383 -// } 362.4384 -// for(int i = numParams() + 1; i < maxLocal + 1; i++) 362.4385 -// { 362.4386 -// if(!localsUsedInCatchFinally.contains(i)) 362.4387 -// { 362.4388 -// LocalBinding b = (LocalBinding) RT.get(indexlocals, i); 362.4389 -// if(b == null || maybePrimitiveType(b.init) == null) 362.4390 -// { 362.4391 -// gen.visitInsn(Opcodes.ACONST_NULL); 362.4392 -// gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i); 362.4393 -// } 362.4394 -// } 362.4395 -// } 362.4396 -// if(((FnExpr)objx).onceOnly) 362.4397 -// { 362.4398 -// objx.emitClearCloses(gen); 362.4399 -// } 362.4400 - } 362.4401 -} 362.4402 - 362.4403 -abstract public static class ObjMethod{ 362.4404 - //when closures are defined inside other closures, 362.4405 - //the closed over locals need to be propagated to the enclosing objx 362.4406 - public final ObjMethod parent; 362.4407 - //localbinding->localbinding 362.4408 - IPersistentMap locals = null; 362.4409 - //num->localbinding 362.4410 - IPersistentMap indexlocals = null; 362.4411 - Expr body = null; 362.4412 - ObjExpr objx; 362.4413 - PersistentVector argLocals; 362.4414 - int maxLocal = 0; 362.4415 - int line; 362.4416 - PersistentHashSet localsUsedInCatchFinally = PersistentHashSet.EMPTY; 362.4417 - protected IPersistentMap methodMeta; 362.4418 - 362.4419 - public final IPersistentMap locals(){ 362.4420 - return locals; 362.4421 - } 362.4422 - 362.4423 - public final Expr body(){ 362.4424 - return body; 362.4425 - } 362.4426 - 362.4427 - public final ObjExpr objx(){ 362.4428 - return objx; 362.4429 - } 362.4430 - 362.4431 - public final PersistentVector argLocals(){ 362.4432 - return argLocals; 362.4433 - } 362.4434 - 362.4435 - public final int maxLocal(){ 362.4436 - return maxLocal; 362.4437 - } 362.4438 - 362.4439 - public final int line(){ 362.4440 - return line; 362.4441 - } 362.4442 - 362.4443 - public ObjMethod(ObjExpr objx, ObjMethod parent){ 362.4444 - this.parent = parent; 362.4445 - this.objx = objx; 362.4446 - } 362.4447 - 362.4448 - abstract int numParams(); 362.4449 - abstract String getMethodName(); 362.4450 - abstract Type getReturnType(); 362.4451 - abstract Type[] getArgTypes(); 362.4452 - 362.4453 - public void emit(ObjExpr fn, ClassVisitor cv){ 362.4454 - Method m = new Method(getMethodName(), getReturnType(), getArgTypes()); 362.4455 - 362.4456 - GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC, 362.4457 - m, 362.4458 - null, 362.4459 - //todo don't hardwire this 362.4460 - EXCEPTION_TYPES, 362.4461 - cv); 362.4462 - gen.visitCode(); 362.4463 - Label loopLabel = gen.mark(); 362.4464 - gen.visitLineNumber(line, loopLabel); 362.4465 - try 362.4466 - { 362.4467 - Var.pushThreadBindings(RT.map(LOOP_LABEL, loopLabel, METHOD, this)); 362.4468 - body.emit(C.RETURN, fn, gen); 362.4469 - Label end = gen.mark(); 362.4470 - gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0); 362.4471 - for(ISeq lbs = argLocals.seq(); lbs != null; lbs = lbs.next()) 362.4472 - { 362.4473 - LocalBinding lb = (LocalBinding) lbs.first(); 362.4474 - gen.visitLocalVariable(lb.name, "Ljava/lang/Object;", null, loopLabel, end, lb.idx); 362.4475 - } 362.4476 - } 362.4477 - finally 362.4478 - { 362.4479 - Var.popThreadBindings(); 362.4480 - } 362.4481 - 362.4482 - gen.returnValue(); 362.4483 - //gen.visitMaxs(1, 1); 362.4484 - gen.endMethod(); 362.4485 - } 362.4486 - 362.4487 - void emitClearLocals(GeneratorAdapter gen){ 362.4488 - } 362.4489 - 362.4490 - void emitClearLocalsOld(GeneratorAdapter gen){ 362.4491 - for(int i=0;i<argLocals.count();i++) 362.4492 - { 362.4493 - LocalBinding lb = (LocalBinding) argLocals.nth(i); 362.4494 - if(!localsUsedInCatchFinally.contains(lb.idx) && lb.getPrimitiveType() == null) 362.4495 - { 362.4496 - gen.visitInsn(Opcodes.ACONST_NULL); 362.4497 - gen.storeArg(lb.idx - 1); 362.4498 - } 362.4499 - 362.4500 - } 362.4501 -// for(int i = 1; i < numParams() + 1; i++) 362.4502 -// { 362.4503 -// if(!localsUsedInCatchFinally.contains(i)) 362.4504 -// { 362.4505 -// gen.visitInsn(Opcodes.ACONST_NULL); 362.4506 -// gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i); 362.4507 -// } 362.4508 -// } 362.4509 - for(int i = numParams() + 1; i < maxLocal + 1; i++) 362.4510 - { 362.4511 - if(!localsUsedInCatchFinally.contains(i)) 362.4512 - { 362.4513 - LocalBinding b = (LocalBinding) RT.get(indexlocals, i); 362.4514 - if(b == null || maybePrimitiveType(b.init) == null) 362.4515 - { 362.4516 - gen.visitInsn(Opcodes.ACONST_NULL); 362.4517 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), i); 362.4518 - } 362.4519 - } 362.4520 - } 362.4521 - } 362.4522 -} 362.4523 - 362.4524 -public static class LocalBinding{ 362.4525 - public final Symbol sym; 362.4526 - public final Symbol tag; 362.4527 - public Expr init; 362.4528 - public final int idx; 362.4529 - public final String name; 362.4530 - public final boolean isArg; 362.4531 - public final PathNode clearPathRoot; 362.4532 - public boolean canBeCleared = true; 362.4533 - 362.4534 - public LocalBinding(int num, Symbol sym, Symbol tag, Expr init, boolean isArg,PathNode clearPathRoot) 362.4535 - throws Exception{ 362.4536 - if(maybePrimitiveType(init) != null && tag != null) 362.4537 - throw new UnsupportedOperationException("Can't type hint a local with a primitive initializer"); 362.4538 - this.idx = num; 362.4539 - this.sym = sym; 362.4540 - this.tag = tag; 362.4541 - this.init = init; 362.4542 - this.isArg = isArg; 362.4543 - this.clearPathRoot = clearPathRoot; 362.4544 - name = munge(sym.name); 362.4545 - } 362.4546 - 362.4547 - public boolean hasJavaClass() throws Exception{ 362.4548 - if(init != null && init.hasJavaClass() 362.4549 - && Util.isPrimitive(init.getJavaClass()) 362.4550 - && !(init instanceof MaybePrimitiveExpr)) 362.4551 - return false; 362.4552 - return tag != null 362.4553 - || (init != null && init.hasJavaClass()); 362.4554 - } 362.4555 - 362.4556 - public Class getJavaClass() throws Exception{ 362.4557 - return tag != null ? HostExpr.tagToClass(tag) 362.4558 - : init.getJavaClass(); 362.4559 - } 362.4560 - 362.4561 - public Class getPrimitiveType(){ 362.4562 - return maybePrimitiveType(init); 362.4563 - } 362.4564 -} 362.4565 - 362.4566 -public static class LocalBindingExpr implements Expr, MaybePrimitiveExpr, AssignableExpr{ 362.4567 - public final LocalBinding b; 362.4568 - public final Symbol tag; 362.4569 - 362.4570 - public final PathNode clearPath; 362.4571 - public final PathNode clearRoot; 362.4572 - public boolean shouldClear = false; 362.4573 - 362.4574 - 362.4575 - public LocalBindingExpr(LocalBinding b, Symbol tag) 362.4576 - throws Exception{ 362.4577 - if(b.getPrimitiveType() != null && tag != null) 362.4578 - throw new UnsupportedOperationException("Can't type hint a primitive local"); 362.4579 - this.b = b; 362.4580 - this.tag = tag; 362.4581 - 362.4582 - this.clearPath = (PathNode)CLEAR_PATH.get(); 362.4583 - this.clearRoot = (PathNode)CLEAR_ROOT.get(); 362.4584 - IPersistentCollection sites = (IPersistentCollection) RT.get(CLEAR_SITES.get(),b); 362.4585 - 362.4586 - if(b.idx > 0) 362.4587 - { 362.4588 -// Object dummy; 362.4589 - 362.4590 - if(sites != null) 362.4591 - { 362.4592 - for(ISeq s = sites.seq();s!=null;s = s.next()) 362.4593 - { 362.4594 - LocalBindingExpr o = (LocalBindingExpr) s.first(); 362.4595 - PathNode common = commonPath(clearPath,o.clearPath); 362.4596 - if(common != null && common.type == PATHTYPE.PATH) 362.4597 - o.shouldClear = false; 362.4598 -// else 362.4599 -// dummy = null; 362.4600 - } 362.4601 - } 362.4602 - 362.4603 - if(clearRoot == b.clearPathRoot) 362.4604 - { 362.4605 - this.shouldClear = true; 362.4606 - sites = RT.conj(sites,this); 362.4607 - CLEAR_SITES.set(RT.assoc(CLEAR_SITES.get(), b, sites)); 362.4608 - } 362.4609 -// else 362.4610 -// dummy = null; 362.4611 - } 362.4612 - } 362.4613 - 362.4614 - public Object eval() throws Exception{ 362.4615 - throw new UnsupportedOperationException("Can't eval locals"); 362.4616 - } 362.4617 - 362.4618 - public boolean canEmitPrimitive(){ 362.4619 - return b.getPrimitiveType() != null; 362.4620 - } 362.4621 - 362.4622 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.4623 - objx.emitUnboxedLocal(gen, b); 362.4624 - } 362.4625 - 362.4626 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.4627 - if(context != C.STATEMENT) 362.4628 - objx.emitLocal(gen, b, shouldClear); 362.4629 - } 362.4630 - 362.4631 - public Object evalAssign(Expr val) throws Exception{ 362.4632 - throw new UnsupportedOperationException("Can't eval locals"); 362.4633 - } 362.4634 - 362.4635 - public void emitAssign(C context, ObjExpr objx, GeneratorAdapter gen, Expr val){ 362.4636 - objx.emitAssignLocal(gen, b,val); 362.4637 - if(context != C.STATEMENT) 362.4638 - objx.emitLocal(gen, b, false); 362.4639 - } 362.4640 - 362.4641 - public boolean hasJavaClass() throws Exception{ 362.4642 - return tag != null || b.hasJavaClass(); 362.4643 - } 362.4644 - 362.4645 - public Class getJavaClass() throws Exception{ 362.4646 - if(tag != null) 362.4647 - return HostExpr.tagToClass(tag); 362.4648 - return b.getJavaClass(); 362.4649 - } 362.4650 - 362.4651 - 362.4652 -} 362.4653 - 362.4654 -public static class BodyExpr implements Expr, MaybePrimitiveExpr{ 362.4655 - PersistentVector exprs; 362.4656 - 362.4657 - public final PersistentVector exprs(){ 362.4658 - return exprs; 362.4659 - } 362.4660 - 362.4661 - public BodyExpr(PersistentVector exprs){ 362.4662 - this.exprs = exprs; 362.4663 - } 362.4664 - 362.4665 - static class Parser implements IParser{ 362.4666 - public Expr parse(C context, Object frms) throws Exception{ 362.4667 - ISeq forms = (ISeq) frms; 362.4668 - if(Util.equals(RT.first(forms), DO)) 362.4669 - forms = RT.next(forms); 362.4670 - PersistentVector exprs = PersistentVector.EMPTY; 362.4671 - for(; forms != null; forms = forms.next()) 362.4672 - { 362.4673 - Expr e = (context != C.EVAL && 362.4674 - (context == C.STATEMENT || forms.next() != null)) ? 362.4675 - analyze(C.STATEMENT, forms.first()) 362.4676 - : 362.4677 - analyze(context, forms.first()); 362.4678 - exprs = exprs.cons(e); 362.4679 - } 362.4680 - if(exprs.count() == 0) 362.4681 - exprs = exprs.cons(NIL_EXPR); 362.4682 - return new BodyExpr(exprs); 362.4683 - } 362.4684 - } 362.4685 - 362.4686 - public Object eval() throws Exception{ 362.4687 - Object ret = null; 362.4688 - for(Object o : exprs) 362.4689 - { 362.4690 - Expr e = (Expr) o; 362.4691 - ret = e.eval(); 362.4692 - } 362.4693 - return ret; 362.4694 - } 362.4695 - 362.4696 - public boolean canEmitPrimitive(){ 362.4697 - return lastExpr() instanceof MaybePrimitiveExpr && ((MaybePrimitiveExpr)lastExpr()).canEmitPrimitive(); 362.4698 - } 362.4699 - 362.4700 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.4701 - for(int i = 0; i < exprs.count() - 1; i++) 362.4702 - { 362.4703 - Expr e = (Expr) exprs.nth(i); 362.4704 - e.emit(C.STATEMENT, objx, gen); 362.4705 - } 362.4706 - MaybePrimitiveExpr last = (MaybePrimitiveExpr) exprs.nth(exprs.count() - 1); 362.4707 - last.emitUnboxed(context, objx, gen); 362.4708 - } 362.4709 - 362.4710 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.4711 - for(int i = 0; i < exprs.count() - 1; i++) 362.4712 - { 362.4713 - Expr e = (Expr) exprs.nth(i); 362.4714 - e.emit(C.STATEMENT, objx, gen); 362.4715 - } 362.4716 - Expr last = (Expr) exprs.nth(exprs.count() - 1); 362.4717 - last.emit(context, objx, gen); 362.4718 - } 362.4719 - 362.4720 - public boolean hasJavaClass() throws Exception{ 362.4721 - return lastExpr().hasJavaClass(); 362.4722 - } 362.4723 - 362.4724 - public Class getJavaClass() throws Exception{ 362.4725 - return lastExpr().getJavaClass(); 362.4726 - } 362.4727 - 362.4728 - private Expr lastExpr(){ 362.4729 - return (Expr) exprs.nth(exprs.count() - 1); 362.4730 - } 362.4731 -} 362.4732 - 362.4733 -public static class BindingInit{ 362.4734 - LocalBinding binding; 362.4735 - Expr init; 362.4736 - 362.4737 - public final LocalBinding binding(){ 362.4738 - return binding; 362.4739 - } 362.4740 - 362.4741 - public final Expr init(){ 362.4742 - return init; 362.4743 - } 362.4744 - 362.4745 - public BindingInit(LocalBinding binding, Expr init){ 362.4746 - this.binding = binding; 362.4747 - this.init = init; 362.4748 - } 362.4749 -} 362.4750 - 362.4751 -public static class LetFnExpr implements Expr{ 362.4752 - public final PersistentVector bindingInits; 362.4753 - public final Expr body; 362.4754 - 362.4755 - public LetFnExpr(PersistentVector bindingInits, Expr body){ 362.4756 - this.bindingInits = bindingInits; 362.4757 - this.body = body; 362.4758 - } 362.4759 - 362.4760 - static class Parser implements IParser{ 362.4761 - public Expr parse(C context, Object frm) throws Exception{ 362.4762 - ISeq form = (ISeq) frm; 362.4763 - //(letfns* [var (fn [args] body) ...] body...) 362.4764 - if(!(RT.second(form) instanceof IPersistentVector)) 362.4765 - throw new IllegalArgumentException("Bad binding form, expected vector"); 362.4766 - 362.4767 - IPersistentVector bindings = (IPersistentVector) RT.second(form); 362.4768 - if((bindings.count() % 2) != 0) 362.4769 - throw new IllegalArgumentException("Bad binding form, expected matched symbol expression pairs"); 362.4770 - 362.4771 - ISeq body = RT.next(RT.next(form)); 362.4772 - 362.4773 - if(context == C.EVAL) 362.4774 - return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form))); 362.4775 - 362.4776 - IPersistentMap dynamicBindings = RT.map(LOCAL_ENV, LOCAL_ENV.deref(), 362.4777 - NEXT_LOCAL_NUM, NEXT_LOCAL_NUM.deref()); 362.4778 - 362.4779 - try 362.4780 - { 362.4781 - Var.pushThreadBindings(dynamicBindings); 362.4782 - 362.4783 - //pre-seed env (like Lisp labels) 362.4784 - PersistentVector lbs = PersistentVector.EMPTY; 362.4785 - for(int i = 0; i < bindings.count(); i += 2) 362.4786 - { 362.4787 - if(!(bindings.nth(i) instanceof Symbol)) 362.4788 - throw new IllegalArgumentException( 362.4789 - "Bad binding form, expected symbol, got: " + bindings.nth(i)); 362.4790 - Symbol sym = (Symbol) bindings.nth(i); 362.4791 - if(sym.getNamespace() != null) 362.4792 - throw new Exception("Can't let qualified name: " + sym); 362.4793 - LocalBinding lb = registerLocal(sym, tagOf(sym), null,false); 362.4794 - lb.canBeCleared = false; 362.4795 - lbs = lbs.cons(lb); 362.4796 - } 362.4797 - PersistentVector bindingInits = PersistentVector.EMPTY; 362.4798 - for(int i = 0; i < bindings.count(); i += 2) 362.4799 - { 362.4800 - Symbol sym = (Symbol) bindings.nth(i); 362.4801 - Expr init = analyze(C.EXPRESSION, bindings.nth(i + 1), sym.name); 362.4802 - LocalBinding lb = (LocalBinding) lbs.nth(i / 2); 362.4803 - lb.init = init; 362.4804 - BindingInit bi = new BindingInit(lb, init); 362.4805 - bindingInits = bindingInits.cons(bi); 362.4806 - } 362.4807 - return new LetFnExpr(bindingInits, (new BodyExpr.Parser()).parse(context, body)); 362.4808 - } 362.4809 - finally 362.4810 - { 362.4811 - Var.popThreadBindings(); 362.4812 - } 362.4813 - } 362.4814 - } 362.4815 - 362.4816 - public Object eval() throws Exception{ 362.4817 - throw new UnsupportedOperationException("Can't eval letfns"); 362.4818 - } 362.4819 - 362.4820 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.4821 - for(int i = 0; i < bindingInits.count(); i++) 362.4822 - { 362.4823 - BindingInit bi = (BindingInit) bindingInits.nth(i); 362.4824 - gen.visitInsn(Opcodes.ACONST_NULL); 362.4825 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), bi.binding.idx); 362.4826 - } 362.4827 - 362.4828 - IPersistentSet lbset = PersistentHashSet.EMPTY; 362.4829 - 362.4830 - for(int i = 0; i < bindingInits.count(); i++) 362.4831 - { 362.4832 - BindingInit bi = (BindingInit) bindingInits.nth(i); 362.4833 - lbset = (IPersistentSet) lbset.cons(bi.binding); 362.4834 - bi.init.emit(C.EXPRESSION, objx, gen); 362.4835 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), bi.binding.idx); 362.4836 - } 362.4837 - 362.4838 - for(int i = 0; i < bindingInits.count(); i++) 362.4839 - { 362.4840 - BindingInit bi = (BindingInit) bindingInits.nth(i); 362.4841 - ObjExpr fe = (ObjExpr) bi.init; 362.4842 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ILOAD), bi.binding.idx); 362.4843 - fe.emitLetFnInits(gen, objx, lbset); 362.4844 - } 362.4845 - 362.4846 - Label loopLabel = gen.mark(); 362.4847 - 362.4848 - body.emit(context, objx, gen); 362.4849 - 362.4850 - Label end = gen.mark(); 362.4851 -// gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0); 362.4852 - for(ISeq bis = bindingInits.seq(); bis != null; bis = bis.next()) 362.4853 - { 362.4854 - BindingInit bi = (BindingInit) bis.first(); 362.4855 - String lname = bi.binding.name; 362.4856 - if(lname.endsWith("__auto__")) 362.4857 - lname += RT.nextID(); 362.4858 - Class primc = maybePrimitiveType(bi.init); 362.4859 - if(primc != null) 362.4860 - gen.visitLocalVariable(lname, Type.getDescriptor(primc), null, loopLabel, end, 362.4861 - bi.binding.idx); 362.4862 - else 362.4863 - gen.visitLocalVariable(lname, "Ljava/lang/Object;", null, loopLabel, end, bi.binding.idx); 362.4864 - } 362.4865 - } 362.4866 - 362.4867 - public boolean hasJavaClass() throws Exception{ 362.4868 - return body.hasJavaClass(); 362.4869 - } 362.4870 - 362.4871 - public Class getJavaClass() throws Exception{ 362.4872 - return body.getJavaClass(); 362.4873 - } 362.4874 -} 362.4875 - 362.4876 -public static class LetExpr implements Expr, MaybePrimitiveExpr{ 362.4877 - public final PersistentVector bindingInits; 362.4878 - public final Expr body; 362.4879 - public final boolean isLoop; 362.4880 - 362.4881 - public LetExpr(PersistentVector bindingInits, Expr body, boolean isLoop){ 362.4882 - this.bindingInits = bindingInits; 362.4883 - this.body = body; 362.4884 - this.isLoop = isLoop; 362.4885 - } 362.4886 - 362.4887 - static class Parser implements IParser{ 362.4888 - public Expr parse(C context, Object frm) throws Exception{ 362.4889 - ISeq form = (ISeq) frm; 362.4890 - //(let [var val var2 val2 ...] body...) 362.4891 - boolean isLoop = RT.first(form).equals(LOOP); 362.4892 - if(!(RT.second(form) instanceof IPersistentVector)) 362.4893 - throw new IllegalArgumentException("Bad binding form, expected vector"); 362.4894 - 362.4895 - IPersistentVector bindings = (IPersistentVector) RT.second(form); 362.4896 - if((bindings.count() % 2) != 0) 362.4897 - throw new IllegalArgumentException("Bad binding form, expected matched symbol expression pairs"); 362.4898 - 362.4899 - ISeq body = RT.next(RT.next(form)); 362.4900 - 362.4901 - if(context == C.EVAL 362.4902 - || (context == C.EXPRESSION && isLoop)) 362.4903 - return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form))); 362.4904 - 362.4905 - IPersistentMap dynamicBindings = RT.map(LOCAL_ENV, LOCAL_ENV.deref(), 362.4906 - NEXT_LOCAL_NUM, NEXT_LOCAL_NUM.deref()); 362.4907 - if(isLoop) 362.4908 - dynamicBindings = dynamicBindings.assoc(LOOP_LOCALS, null); 362.4909 - 362.4910 - try 362.4911 - { 362.4912 - Var.pushThreadBindings(dynamicBindings); 362.4913 - 362.4914 - PersistentVector bindingInits = PersistentVector.EMPTY; 362.4915 - PersistentVector loopLocals = PersistentVector.EMPTY; 362.4916 - for(int i = 0; i < bindings.count(); i += 2) 362.4917 - { 362.4918 - if(!(bindings.nth(i) instanceof Symbol)) 362.4919 - throw new IllegalArgumentException( 362.4920 - "Bad binding form, expected symbol, got: " + bindings.nth(i)); 362.4921 - Symbol sym = (Symbol) bindings.nth(i); 362.4922 - if(sym.getNamespace() != null) 362.4923 - throw new Exception("Can't let qualified name: " + sym); 362.4924 - Expr init = analyze(C.EXPRESSION, bindings.nth(i + 1), sym.name); 362.4925 - //sequential enhancement of env (like Lisp let*) 362.4926 - LocalBinding lb = registerLocal(sym, tagOf(sym), init,false); 362.4927 - BindingInit bi = new BindingInit(lb, init); 362.4928 - bindingInits = bindingInits.cons(bi); 362.4929 - 362.4930 - if(isLoop) 362.4931 - loopLocals = loopLocals.cons(lb); 362.4932 - } 362.4933 - if(isLoop) 362.4934 - LOOP_LOCALS.set(loopLocals); 362.4935 - Expr bodyExpr; 362.4936 - try { 362.4937 - if(isLoop) 362.4938 - { 362.4939 - PathNode root = new PathNode(PATHTYPE.PATH, (PathNode) CLEAR_PATH.get()); 362.4940 - Var.pushThreadBindings( 362.4941 - RT.map(CLEAR_PATH, new PathNode(PATHTYPE.PATH,root), 362.4942 - CLEAR_ROOT, new PathNode(PATHTYPE.PATH,root))); 362.4943 - } 362.4944 - bodyExpr = (new BodyExpr.Parser()).parse(isLoop ? C.RETURN : context, body); 362.4945 - } 362.4946 - finally{ 362.4947 - if(isLoop) 362.4948 - Var.popThreadBindings(); 362.4949 - } 362.4950 - return new LetExpr(bindingInits, bodyExpr, 362.4951 - isLoop); 362.4952 - } 362.4953 - finally 362.4954 - { 362.4955 - Var.popThreadBindings(); 362.4956 - } 362.4957 - } 362.4958 - } 362.4959 - 362.4960 - public Object eval() throws Exception{ 362.4961 - throw new UnsupportedOperationException("Can't eval let/loop"); 362.4962 - } 362.4963 - 362.4964 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.4965 - doEmit(context, objx, gen, false); 362.4966 - } 362.4967 - 362.4968 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.4969 - doEmit(context, objx, gen, true); 362.4970 - } 362.4971 - 362.4972 - 362.4973 - public void doEmit(C context, ObjExpr objx, GeneratorAdapter gen, boolean emitUnboxed){ 362.4974 - for(int i = 0; i < bindingInits.count(); i++) 362.4975 - { 362.4976 - BindingInit bi = (BindingInit) bindingInits.nth(i); 362.4977 - Class primc = maybePrimitiveType(bi.init); 362.4978 - if(primc != null) 362.4979 - { 362.4980 - ((MaybePrimitiveExpr) bi.init).emitUnboxed(C.EXPRESSION, objx, gen); 362.4981 - gen.visitVarInsn(Type.getType(primc).getOpcode(Opcodes.ISTORE), bi.binding.idx); 362.4982 - } 362.4983 - else 362.4984 - { 362.4985 - bi.init.emit(C.EXPRESSION, objx, gen); 362.4986 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), bi.binding.idx); 362.4987 - } 362.4988 - } 362.4989 - Label loopLabel = gen.mark(); 362.4990 - if(isLoop) 362.4991 - { 362.4992 - try 362.4993 - { 362.4994 - Var.pushThreadBindings(RT.map(LOOP_LABEL, loopLabel)); 362.4995 - if(emitUnboxed) 362.4996 - ((MaybePrimitiveExpr)body).emitUnboxed(context, objx, gen); 362.4997 - else 362.4998 - body.emit(context, objx, gen); 362.4999 - } 362.5000 - finally 362.5001 - { 362.5002 - Var.popThreadBindings(); 362.5003 - } 362.5004 - } 362.5005 - else 362.5006 - { 362.5007 - if(emitUnboxed) 362.5008 - ((MaybePrimitiveExpr)body).emitUnboxed(context, objx, gen); 362.5009 - else 362.5010 - body.emit(context, objx, gen); 362.5011 - } 362.5012 - Label end = gen.mark(); 362.5013 -// gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0); 362.5014 - for(ISeq bis = bindingInits.seq(); bis != null; bis = bis.next()) 362.5015 - { 362.5016 - BindingInit bi = (BindingInit) bis.first(); 362.5017 - String lname = bi.binding.name; 362.5018 - if(lname.endsWith("__auto__")) 362.5019 - lname += RT.nextID(); 362.5020 - Class primc = maybePrimitiveType(bi.init); 362.5021 - if(primc != null) 362.5022 - gen.visitLocalVariable(lname, Type.getDescriptor(primc), null, loopLabel, end, 362.5023 - bi.binding.idx); 362.5024 - else 362.5025 - gen.visitLocalVariable(lname, "Ljava/lang/Object;", null, loopLabel, end, bi.binding.idx); 362.5026 - } 362.5027 - } 362.5028 - 362.5029 - public boolean hasJavaClass() throws Exception{ 362.5030 - return body.hasJavaClass(); 362.5031 - } 362.5032 - 362.5033 - public Class getJavaClass() throws Exception{ 362.5034 - return body.getJavaClass(); 362.5035 - } 362.5036 - 362.5037 - public boolean canEmitPrimitive(){ 362.5038 - return body instanceof MaybePrimitiveExpr && ((MaybePrimitiveExpr)body).canEmitPrimitive(); 362.5039 - } 362.5040 - 362.5041 -} 362.5042 - 362.5043 -public static class RecurExpr implements Expr{ 362.5044 - public final IPersistentVector args; 362.5045 - public final IPersistentVector loopLocals; 362.5046 - 362.5047 - public RecurExpr(IPersistentVector loopLocals, IPersistentVector args){ 362.5048 - this.loopLocals = loopLocals; 362.5049 - this.args = args; 362.5050 - } 362.5051 - 362.5052 - public Object eval() throws Exception{ 362.5053 - throw new UnsupportedOperationException("Can't eval recur"); 362.5054 - } 362.5055 - 362.5056 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.5057 - Label loopLabel = (Label) LOOP_LABEL.deref(); 362.5058 - if(loopLabel == null) 362.5059 - throw new IllegalStateException(); 362.5060 - for(int i = 0; i < loopLocals.count(); i++) 362.5061 - { 362.5062 - LocalBinding lb = (LocalBinding) loopLocals.nth(i); 362.5063 - Expr arg = (Expr) args.nth(i); 362.5064 - if(lb.getPrimitiveType() != null) 362.5065 - { 362.5066 - Class primc = lb.getPrimitiveType(); 362.5067 - try 362.5068 - { 362.5069 - if(!(arg instanceof MaybePrimitiveExpr && arg.hasJavaClass() && arg.getJavaClass() == primc)) 362.5070 - throw new IllegalArgumentException("recur arg for primitive local: " + 362.5071 - lb.name + " must be matching primitive"); 362.5072 - } 362.5073 - catch(Exception e) 362.5074 - { 362.5075 - throw new RuntimeException(e); 362.5076 - } 362.5077 - ((MaybePrimitiveExpr) arg).emitUnboxed(C.EXPRESSION, objx, gen); 362.5078 - } 362.5079 - else 362.5080 - { 362.5081 - arg.emit(C.EXPRESSION, objx, gen); 362.5082 - } 362.5083 - } 362.5084 - 362.5085 - for(int i = loopLocals.count() - 1; i >= 0; i--) 362.5086 - { 362.5087 - LocalBinding lb = (LocalBinding) loopLocals.nth(i); 362.5088 - Class primc = lb.getPrimitiveType(); 362.5089 - if(lb.isArg) 362.5090 - gen.storeArg(lb.idx-1); 362.5091 - else 362.5092 - { 362.5093 - if(primc != null) 362.5094 - gen.visitVarInsn(Type.getType(primc).getOpcode(Opcodes.ISTORE), lb.idx); 362.5095 - else 362.5096 - gen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ISTORE), lb.idx); 362.5097 - } 362.5098 - } 362.5099 - 362.5100 - gen.goTo(loopLabel); 362.5101 - } 362.5102 - 362.5103 - public boolean hasJavaClass() throws Exception{ 362.5104 - return true; 362.5105 - } 362.5106 - 362.5107 - public Class getJavaClass() throws Exception{ 362.5108 - return null; 362.5109 - } 362.5110 - 362.5111 - static class Parser implements IParser{ 362.5112 - public Expr parse(C context, Object frm) throws Exception{ 362.5113 - ISeq form = (ISeq) frm; 362.5114 - IPersistentVector loopLocals = (IPersistentVector) LOOP_LOCALS.deref(); 362.5115 - if(context != C.RETURN || loopLocals == null) 362.5116 - throw new UnsupportedOperationException("Can only recur from tail position"); 362.5117 - if(IN_CATCH_FINALLY.deref() != null) 362.5118 - throw new UnsupportedOperationException("Cannot recur from catch/finally"); 362.5119 - PersistentVector args = PersistentVector.EMPTY; 362.5120 - for(ISeq s = RT.seq(form.next()); s != null; s = s.next()) 362.5121 - { 362.5122 - args = args.cons(analyze(C.EXPRESSION, s.first())); 362.5123 - } 362.5124 - if(args.count() != loopLocals.count()) 362.5125 - throw new IllegalArgumentException( 362.5126 - String.format("Mismatched argument count to recur, expected: %d args, got: %d", 362.5127 - loopLocals.count(), args.count())); 362.5128 - return new RecurExpr(loopLocals, args); 362.5129 - } 362.5130 - } 362.5131 -} 362.5132 - 362.5133 -private static LocalBinding registerLocal(Symbol sym, Symbol tag, Expr init, boolean isArg) throws Exception{ 362.5134 - int num = getAndIncLocalNum(); 362.5135 - LocalBinding b = new LocalBinding(num, sym, tag, init, isArg, clearPathRoot()); 362.5136 - IPersistentMap localsMap = (IPersistentMap) LOCAL_ENV.deref(); 362.5137 - LOCAL_ENV.set(RT.assoc(localsMap, b.sym, b)); 362.5138 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.5139 - method.locals = (IPersistentMap) RT.assoc(method.locals, b, b); 362.5140 - method.indexlocals = (IPersistentMap) RT.assoc(method.indexlocals, num, b); 362.5141 - return b; 362.5142 -} 362.5143 - 362.5144 -private static int getAndIncLocalNum(){ 362.5145 - int num = ((Number) NEXT_LOCAL_NUM.deref()).intValue(); 362.5146 - ObjMethod m = (ObjMethod) METHOD.deref(); 362.5147 - if(num > m.maxLocal) 362.5148 - m.maxLocal = num; 362.5149 - NEXT_LOCAL_NUM.set(num + 1); 362.5150 - return num; 362.5151 -} 362.5152 - 362.5153 -public static Expr analyze(C context, Object form) throws Exception{ 362.5154 - return analyze(context, form, null); 362.5155 -} 362.5156 - 362.5157 -private static Expr analyze(C context, Object form, String name) throws Exception{ 362.5158 - //todo symbol macro expansion? 362.5159 - try 362.5160 - { 362.5161 - if(form instanceof LazySeq) 362.5162 - { 362.5163 - form = RT.seq(form); 362.5164 - if(form == null) 362.5165 - form = PersistentList.EMPTY; 362.5166 - } 362.5167 - if(form == null) 362.5168 - return NIL_EXPR; 362.5169 - else if(form == Boolean.TRUE) 362.5170 - return TRUE_EXPR; 362.5171 - else if(form == Boolean.FALSE) 362.5172 - return FALSE_EXPR; 362.5173 - Class fclass = form.getClass(); 362.5174 - if(fclass == Symbol.class) 362.5175 - return analyzeSymbol((Symbol) form); 362.5176 - else if(fclass == Keyword.class) 362.5177 - return registerKeyword((Keyword) form); 362.5178 -// else if(form instanceof Num) 362.5179 -// return new NumExpr((Num) form); 362.5180 - else if(fclass == String.class) 362.5181 - return new StringExpr(((String) form).intern()); 362.5182 -// else if(fclass == Character.class) 362.5183 -// return new CharExpr((Character) form); 362.5184 - else if(form instanceof IPersistentCollection && ((IPersistentCollection) form).count() == 0) 362.5185 - { 362.5186 - Expr ret = new EmptyExpr(form); 362.5187 - if(RT.meta(form) != null) 362.5188 - ret = new MetaExpr(ret, (MapExpr) MapExpr 362.5189 - .parse(context == C.EVAL ? context : C.EXPRESSION, ((IObj) form).meta())); 362.5190 - return ret; 362.5191 - } 362.5192 - else if(form instanceof ISeq) 362.5193 - return analyzeSeq(context, (ISeq) form, name); 362.5194 - else if(form instanceof IPersistentVector) 362.5195 - return VectorExpr.parse(context, (IPersistentVector) form); 362.5196 - else if(form instanceof IPersistentMap) 362.5197 - return MapExpr.parse(context, (IPersistentMap) form); 362.5198 - else if(form instanceof IPersistentSet) 362.5199 - return SetExpr.parse(context, (IPersistentSet) form); 362.5200 - 362.5201 -// else 362.5202 - //throw new UnsupportedOperationException(); 362.5203 - return new ConstantExpr(form); 362.5204 - } 362.5205 - catch(Throwable e) 362.5206 - { 362.5207 - if(!(e instanceof CompilerException)) 362.5208 - throw new CompilerException((String) SOURCE.deref(), (Integer) LINE.deref(), e); 362.5209 - else 362.5210 - throw (CompilerException) e; 362.5211 - } 362.5212 -} 362.5213 - 362.5214 -static public class CompilerException extends Exception{ 362.5215 - 362.5216 - public CompilerException(String source, int line, Throwable cause){ 362.5217 - super(errorMsg(source, line, cause.toString()), cause); 362.5218 - } 362.5219 - 362.5220 - public String toString(){ 362.5221 - return getMessage(); 362.5222 - } 362.5223 -} 362.5224 - 362.5225 -static public Var isMacro(Object op) throws Exception{ 362.5226 - //no local macros for now 362.5227 - if(op instanceof Symbol && referenceLocal((Symbol) op) != null) 362.5228 - return null; 362.5229 - if(op instanceof Symbol || op instanceof Var) 362.5230 - { 362.5231 - Var v = (op instanceof Var) ? (Var) op : lookupVar((Symbol) op, false); 362.5232 - if(v != null && v.isMacro()) 362.5233 - { 362.5234 - if(v.ns != currentNS() && !v.isPublic()) 362.5235 - throw new IllegalStateException("var: " + v + " is not public"); 362.5236 - return v; 362.5237 - } 362.5238 - } 362.5239 - return null; 362.5240 -} 362.5241 - 362.5242 -static public IFn isInline(Object op, int arity) throws Exception{ 362.5243 - //no local inlines for now 362.5244 - if(op instanceof Symbol && referenceLocal((Symbol) op) != null) 362.5245 - return null; 362.5246 - if(op instanceof Symbol || op instanceof Var) 362.5247 - { 362.5248 - Var v = (op instanceof Var) ? (Var) op : lookupVar((Symbol) op, false); 362.5249 - if(v != null) 362.5250 - { 362.5251 - if(v.ns != currentNS() && !v.isPublic()) 362.5252 - throw new IllegalStateException("var: " + v + " is not public"); 362.5253 - IFn ret = (IFn) RT.get(v.meta(), inlineKey); 362.5254 - if(ret != null) 362.5255 - { 362.5256 - IFn arityPred = (IFn) RT.get(v.meta(), inlineAritiesKey); 362.5257 - if(arityPred == null || RT.booleanCast(arityPred.invoke(arity))) 362.5258 - return ret; 362.5259 - } 362.5260 - } 362.5261 - } 362.5262 - return null; 362.5263 -} 362.5264 - 362.5265 -public static boolean namesStaticMember(Symbol sym){ 362.5266 - return sym.ns != null && namespaceFor(sym) == null; 362.5267 -} 362.5268 - 362.5269 -public static Object preserveTag(ISeq src, Object dst) { 362.5270 - Symbol tag = tagOf(src); 362.5271 - if (tag != null && dst instanceof IObj) { 362.5272 - IPersistentMap meta = RT.meta(dst); 362.5273 - return ((IObj) dst).withMeta((IPersistentMap) RT.assoc(meta, RT.TAG_KEY, tag)); 362.5274 - } 362.5275 - return dst; 362.5276 -} 362.5277 - 362.5278 -public static Object macroexpand1(Object x) throws Exception{ 362.5279 - if(x instanceof ISeq) 362.5280 - { 362.5281 - ISeq form = (ISeq) x; 362.5282 - Object op = RT.first(form); 362.5283 - if(isSpecial(op)) 362.5284 - return x; 362.5285 - //macro expansion 362.5286 - Var v = isMacro(op); 362.5287 - if(v != null) 362.5288 - { 362.5289 - return v.applyTo(RT.cons(form,RT.cons(LOCAL_ENV.get(),form.next()))); 362.5290 - } 362.5291 - else 362.5292 - { 362.5293 - if(op instanceof Symbol) 362.5294 - { 362.5295 - Symbol sym = (Symbol) op; 362.5296 - String sname = sym.name; 362.5297 - //(.substring s 2 5) => (. s substring 2 5) 362.5298 - if(sym.name.charAt(0) == '.') 362.5299 - { 362.5300 - if(RT.length(form) < 2) 362.5301 - throw new IllegalArgumentException( 362.5302 - "Malformed member expression, expecting (.member target ...)"); 362.5303 - Symbol meth = Symbol.intern(sname.substring(1)); 362.5304 - Object target = RT.second(form); 362.5305 - if(HostExpr.maybeClass(target, false) != null) 362.5306 - { 362.5307 - target = ((IObj)RT.list(IDENTITY, target)).withMeta(RT.map(RT.TAG_KEY,CLASS)); 362.5308 - } 362.5309 - return preserveTag(form, RT.listStar(DOT, target, meth, form.next().next())); 362.5310 - } 362.5311 - else if(namesStaticMember(sym)) 362.5312 - { 362.5313 - Symbol target = Symbol.intern(sym.ns); 362.5314 - Class c = HostExpr.maybeClass(target, false); 362.5315 - if(c != null) 362.5316 - { 362.5317 - Symbol meth = Symbol.intern(sym.name); 362.5318 - return preserveTag(form, RT.listStar(DOT, target, meth, form.next())); 362.5319 - } 362.5320 - } 362.5321 - else 362.5322 - { 362.5323 - //(s.substring 2 5) => (. s substring 2 5) 362.5324 - //also (package.class.name ...) (. package.class name ...) 362.5325 - int idx = sname.lastIndexOf('.'); 362.5326 -// if(idx > 0 && idx < sname.length() - 1) 362.5327 -// { 362.5328 -// Symbol target = Symbol.intern(sname.substring(0, idx)); 362.5329 -// Symbol meth = Symbol.intern(sname.substring(idx + 1)); 362.5330 -// return RT.listStar(DOT, target, meth, form.rest()); 362.5331 -// } 362.5332 - //(StringBuilder. "foo") => (new StringBuilder "foo") 362.5333 - //else 362.5334 - if(idx == sname.length() - 1) 362.5335 - return RT.listStar(NEW, Symbol.intern(sname.substring(0, idx)), form.next()); 362.5336 - } 362.5337 - } 362.5338 - } 362.5339 - } 362.5340 - return x; 362.5341 -} 362.5342 - 362.5343 -static Object macroexpand(Object form) throws Exception{ 362.5344 - Object exf = macroexpand1(form); 362.5345 - if(exf != form) 362.5346 - return macroexpand(exf); 362.5347 - return form; 362.5348 -} 362.5349 - 362.5350 -private static Expr analyzeSeq(C context, ISeq form, String name) throws Exception{ 362.5351 - Integer line = (Integer) LINE.deref(); 362.5352 - if(RT.meta(form) != null && RT.meta(form).containsKey(RT.LINE_KEY)) 362.5353 - line = (Integer) RT.meta(form).valAt(RT.LINE_KEY); 362.5354 - Var.pushThreadBindings( 362.5355 - RT.map(LINE, line)); 362.5356 - try 362.5357 - { 362.5358 - Object me = macroexpand1(form); 362.5359 - if(me != form) 362.5360 - return analyze(context, me, name); 362.5361 - 362.5362 - Object op = RT.first(form); 362.5363 - if(op == null) 362.5364 - throw new IllegalArgumentException("Can't call nil"); 362.5365 - IFn inline = isInline(op, RT.count(RT.next(form))); 362.5366 - if(inline != null) 362.5367 - return analyze(context, preserveTag(form, inline.applyTo(RT.next(form)))); 362.5368 - IParser p; 362.5369 - if(op.equals(FN)) 362.5370 - return FnExpr.parse(context, form, name); 362.5371 - else if((p = (IParser) specials.valAt(op)) != null) 362.5372 - return p.parse(context, form); 362.5373 - else 362.5374 - return InvokeExpr.parse(context, form); 362.5375 - } 362.5376 - catch(Throwable e) 362.5377 - { 362.5378 - if(!(e instanceof CompilerException)) 362.5379 - throw new CompilerException((String) SOURCE.deref(), (Integer) LINE.deref(), e); 362.5380 - else 362.5381 - throw (CompilerException) e; 362.5382 - } 362.5383 - finally 362.5384 - { 362.5385 - Var.popThreadBindings(); 362.5386 - } 362.5387 -} 362.5388 - 362.5389 -static String errorMsg(String source, int line, String s){ 362.5390 - return String.format("%s (%s:%d)", s, source, line); 362.5391 -} 362.5392 - 362.5393 -public static Object eval(Object form) throws Exception{ 362.5394 - return eval(form, true); 362.5395 -} 362.5396 - 362.5397 -public static Object eval(Object form, boolean freshLoader) throws Exception{ 362.5398 - boolean createdLoader = false; 362.5399 - if(true)//!LOADER.isBound()) 362.5400 - { 362.5401 - Var.pushThreadBindings(RT.map(LOADER, RT.makeClassLoader())); 362.5402 - createdLoader = true; 362.5403 - } 362.5404 - try 362.5405 - { 362.5406 - Integer line = (Integer) LINE.deref(); 362.5407 - if(RT.meta(form) != null && RT.meta(form).containsKey(RT.LINE_KEY)) 362.5408 - line = (Integer) RT.meta(form).valAt(RT.LINE_KEY); 362.5409 - Var.pushThreadBindings(RT.map(LINE, line)); 362.5410 - try 362.5411 - { 362.5412 - form = macroexpand(form); 362.5413 - if(form instanceof IPersistentCollection && Util.equals(RT.first(form), DO)) 362.5414 - { 362.5415 - ISeq s = RT.next(form); 362.5416 - for(; RT.next(s) != null; s = RT.next(s)) 362.5417 - eval(RT.first(s),false); 362.5418 - return eval(RT.first(s),false); 362.5419 - } 362.5420 - else if(form instanceof IPersistentCollection 362.5421 - && !(RT.first(form) instanceof Symbol 362.5422 - && ((Symbol) RT.first(form)).name.startsWith("def"))) 362.5423 - { 362.5424 - ObjExpr fexpr = (ObjExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), 362.5425 - "eval" + RT.nextID()); 362.5426 - IFn fn = (IFn) fexpr.eval(); 362.5427 - return fn.invoke(); 362.5428 - } 362.5429 - else 362.5430 - { 362.5431 - Expr expr = analyze(C.EVAL, form); 362.5432 - return expr.eval(); 362.5433 - } 362.5434 - } 362.5435 - finally 362.5436 - { 362.5437 - Var.popThreadBindings(); 362.5438 - } 362.5439 - } 362.5440 - catch(Throwable e) 362.5441 - { 362.5442 - if(!(e instanceof CompilerException)) 362.5443 - throw new CompilerException((String) SOURCE.deref(), (Integer) LINE.deref(), e); 362.5444 - else 362.5445 - throw (CompilerException) e; 362.5446 - } 362.5447 - finally 362.5448 - { 362.5449 - if(createdLoader) 362.5450 - Var.popThreadBindings(); 362.5451 - } 362.5452 -} 362.5453 - 362.5454 -private static int registerConstant(Object o){ 362.5455 - if(!CONSTANTS.isBound()) 362.5456 - return -1; 362.5457 - PersistentVector v = (PersistentVector) CONSTANTS.deref(); 362.5458 - IdentityHashMap<Object,Integer> ids = (IdentityHashMap<Object,Integer>) CONSTANT_IDS.deref(); 362.5459 - Integer i = ids.get(o); 362.5460 - if(i != null) 362.5461 - return i; 362.5462 - CONSTANTS.set(RT.conj(v, o)); 362.5463 - ids.put(o, v.count()); 362.5464 - return v.count(); 362.5465 -} 362.5466 - 362.5467 -private static KeywordExpr registerKeyword(Keyword keyword){ 362.5468 - if(!KEYWORDS.isBound()) 362.5469 - return new KeywordExpr(keyword); 362.5470 - 362.5471 - IPersistentMap keywordsMap = (IPersistentMap) KEYWORDS.deref(); 362.5472 - Object id = RT.get(keywordsMap, keyword); 362.5473 - if(id == null) 362.5474 - { 362.5475 - KEYWORDS.set(RT.assoc(keywordsMap, keyword, registerConstant(keyword))); 362.5476 - } 362.5477 - return new KeywordExpr(keyword); 362.5478 -// KeywordExpr ke = (KeywordExpr) RT.get(keywordsMap, keyword); 362.5479 -// if(ke == null) 362.5480 -// KEYWORDS.set(RT.assoc(keywordsMap, keyword, ke = new KeywordExpr(keyword))); 362.5481 -// return ke; 362.5482 -} 362.5483 - 362.5484 -private static int registerKeywordCallsite(Keyword keyword){ 362.5485 - if(!KEYWORD_CALLSITES.isBound()) 362.5486 - throw new IllegalAccessError("KEYWORD_CALLSITES is not bound"); 362.5487 - 362.5488 - IPersistentVector keywordCallsites = (IPersistentVector) KEYWORD_CALLSITES.deref(); 362.5489 - 362.5490 - keywordCallsites = keywordCallsites.cons(keyword); 362.5491 - KEYWORD_CALLSITES.set(keywordCallsites); 362.5492 - return keywordCallsites.count()-1; 362.5493 -} 362.5494 - 362.5495 -private static int registerProtocolCallsite(Var v){ 362.5496 - if(!PROTOCOL_CALLSITES.isBound()) 362.5497 - throw new IllegalAccessError("PROTOCOL_CALLSITES is not bound"); 362.5498 - 362.5499 - IPersistentVector protocolCallsites = (IPersistentVector) PROTOCOL_CALLSITES.deref(); 362.5500 - 362.5501 - protocolCallsites = protocolCallsites.cons(v); 362.5502 - PROTOCOL_CALLSITES.set(protocolCallsites); 362.5503 - return protocolCallsites.count()-1; 362.5504 -} 362.5505 - 362.5506 -private static int registerVarCallsite(Var v){ 362.5507 - if(!VAR_CALLSITES.isBound()) 362.5508 - throw new IllegalAccessError("VAR_CALLSITES is not bound"); 362.5509 - 362.5510 - IPersistentVector varCallsites = (IPersistentVector) VAR_CALLSITES.deref(); 362.5511 - 362.5512 - varCallsites = varCallsites.cons(v); 362.5513 - VAR_CALLSITES.set(varCallsites); 362.5514 - return varCallsites.count()-1; 362.5515 -} 362.5516 - 362.5517 -static ISeq fwdPath(PathNode p1){ 362.5518 - ISeq ret = null; 362.5519 - for(;p1 != null;p1 = p1.parent) 362.5520 - ret = RT.cons(p1,ret); 362.5521 - return ret; 362.5522 -} 362.5523 - 362.5524 -static PathNode commonPath(PathNode n1, PathNode n2){ 362.5525 - ISeq xp = fwdPath(n1); 362.5526 - ISeq yp = fwdPath(n2); 362.5527 - if(RT.first(xp) != RT.first(yp)) 362.5528 - return null; 362.5529 - while(RT.second(xp) != null && RT.second(xp) == RT.second(yp)) 362.5530 - { 362.5531 - xp = xp.next(); 362.5532 - yp = yp.next(); 362.5533 - } 362.5534 - return (PathNode) RT.first(xp); 362.5535 -} 362.5536 - 362.5537 -static void addAnnotation(Object visitor, IPersistentMap meta){ 362.5538 - try{ 362.5539 - if(meta != null && ADD_ANNOTATIONS.isBound()) 362.5540 - ADD_ANNOTATIONS.invoke(visitor, meta); 362.5541 - } 362.5542 - catch (Exception e) 362.5543 - { 362.5544 - throw new RuntimeException(e); 362.5545 - } 362.5546 -} 362.5547 - 362.5548 -static void addParameterAnnotation(Object visitor, IPersistentMap meta, int i){ 362.5549 - try{ 362.5550 - if(meta != null && ADD_ANNOTATIONS.isBound()) 362.5551 - ADD_ANNOTATIONS.invoke(visitor, meta, i); 362.5552 - } 362.5553 - catch (Exception e) 362.5554 - { 362.5555 - throw new RuntimeException(e); 362.5556 - } 362.5557 -} 362.5558 - 362.5559 -private static Expr analyzeSymbol(Symbol sym) throws Exception{ 362.5560 - Symbol tag = tagOf(sym); 362.5561 - if(sym.ns == null) //ns-qualified syms are always Vars 362.5562 - { 362.5563 - LocalBinding b = referenceLocal(sym); 362.5564 - if(b != null) 362.5565 - { 362.5566 - return new LocalBindingExpr(b, tag); 362.5567 - } 362.5568 - } 362.5569 - else 362.5570 - { 362.5571 - if(namespaceFor(sym) == null) 362.5572 - { 362.5573 - Symbol nsSym = Symbol.create(sym.ns); 362.5574 - Class c = HostExpr.maybeClass(nsSym, false); 362.5575 - if(c != null) 362.5576 - { 362.5577 - if(Reflector.getField(c, sym.name, true) != null) 362.5578 - return new StaticFieldExpr((Integer) LINE.deref(), c, sym.name, tag); 362.5579 - throw new Exception("Unable to find static field: " + sym.name + " in " + c); 362.5580 - } 362.5581 - } 362.5582 - } 362.5583 - //Var v = lookupVar(sym, false); 362.5584 -// Var v = lookupVar(sym, false); 362.5585 -// if(v != null) 362.5586 -// return new VarExpr(v, tag); 362.5587 - Object o = resolve(sym); 362.5588 - if(o instanceof Var) 362.5589 - { 362.5590 - Var v = (Var) o; 362.5591 - if(isMacro(v) != null) 362.5592 - throw new Exception("Can't take value of a macro: " + v); 362.5593 - registerVar(v); 362.5594 - return new VarExpr(v, tag); 362.5595 - } 362.5596 - else if(o instanceof Class) 362.5597 - return new ConstantExpr(o); 362.5598 - else if(o instanceof Symbol) 362.5599 - return new UnresolvedVarExpr((Symbol) o); 362.5600 - 362.5601 - throw new Exception("Unable to resolve symbol: " + sym + " in this context"); 362.5602 - 362.5603 -} 362.5604 - 362.5605 -static String destubClassName(String className){ 362.5606 - //skip over prefix + '.' or '/' 362.5607 - if(className.startsWith(COMPILE_STUB_PREFIX)) 362.5608 - return className.substring(COMPILE_STUB_PREFIX.length()+1); 362.5609 - return className; 362.5610 -} 362.5611 - 362.5612 -static Type getType(Class c){ 362.5613 - String descriptor = Type.getType(c).getDescriptor(); 362.5614 - if(descriptor.startsWith("L")) 362.5615 - descriptor = "L" + destubClassName(descriptor.substring(1)); 362.5616 - return Type.getType(descriptor); 362.5617 -} 362.5618 - 362.5619 -static Object resolve(Symbol sym, boolean allowPrivate) throws Exception{ 362.5620 - return resolveIn(currentNS(), sym, allowPrivate); 362.5621 -} 362.5622 - 362.5623 -static Object resolve(Symbol sym) throws Exception{ 362.5624 - return resolveIn(currentNS(), sym, false); 362.5625 -} 362.5626 - 362.5627 -static Namespace namespaceFor(Symbol sym){ 362.5628 - return namespaceFor(currentNS(), sym); 362.5629 -} 362.5630 - 362.5631 -static Namespace namespaceFor(Namespace inns, Symbol sym){ 362.5632 - //note, presumes non-nil sym.ns 362.5633 - // first check against currentNS' aliases... 362.5634 - Symbol nsSym = Symbol.create(sym.ns); 362.5635 - Namespace ns = inns.lookupAlias(nsSym); 362.5636 - if(ns == null) 362.5637 - { 362.5638 - // ...otherwise check the Namespaces map. 362.5639 - ns = Namespace.find(nsSym); 362.5640 - } 362.5641 - return ns; 362.5642 -} 362.5643 - 362.5644 -static public Object resolveIn(Namespace n, Symbol sym, boolean allowPrivate) throws Exception{ 362.5645 - //note - ns-qualified vars must already exist 362.5646 - if(sym.ns != null) 362.5647 - { 362.5648 - Namespace ns = namespaceFor(n, sym); 362.5649 - if(ns == null) 362.5650 - throw new Exception("No such namespace: " + sym.ns); 362.5651 - 362.5652 - Var v = ns.findInternedVar(Symbol.create(sym.name)); 362.5653 - if(v == null) 362.5654 - throw new Exception("No such var: " + sym); 362.5655 - else if(v.ns != currentNS() && !v.isPublic() && !allowPrivate) 362.5656 - throw new IllegalStateException("var: " + sym + " is not public"); 362.5657 - return v; 362.5658 - } 362.5659 - else if(sym.name.indexOf('.') > 0 || sym.name.charAt(0) == '[') 362.5660 - { 362.5661 - return RT.classForName(sym.name); 362.5662 - } 362.5663 - else if(sym.equals(NS)) 362.5664 - return RT.NS_VAR; 362.5665 - else if(sym.equals(IN_NS)) 362.5666 - return RT.IN_NS_VAR; 362.5667 - else 362.5668 - { 362.5669 - if(Util.equals(sym,COMPILE_STUB_SYM.get())) 362.5670 - return COMPILE_STUB_CLASS.get(); 362.5671 - Object o = n.getMapping(sym); 362.5672 - if(o == null) 362.5673 - { 362.5674 - if(RT.booleanCast(RT.ALLOW_UNRESOLVED_VARS.deref())) 362.5675 - { 362.5676 - return sym; 362.5677 - } 362.5678 - else 362.5679 - { 362.5680 - throw new Exception("Unable to resolve symbol: " + sym + " in this context"); 362.5681 - } 362.5682 - } 362.5683 - return o; 362.5684 - } 362.5685 -} 362.5686 - 362.5687 - 362.5688 -static public Object maybeResolveIn(Namespace n, Symbol sym) throws Exception{ 362.5689 - //note - ns-qualified vars must already exist 362.5690 - if(sym.ns != null) 362.5691 - { 362.5692 - Namespace ns = namespaceFor(n, sym); 362.5693 - if(ns == null) 362.5694 - return null; 362.5695 - Var v = ns.findInternedVar(Symbol.create(sym.name)); 362.5696 - if(v == null) 362.5697 - return null; 362.5698 - return v; 362.5699 - } 362.5700 - else if(sym.name.indexOf('.') > 0 && !sym.name.endsWith(".") 362.5701 - || sym.name.charAt(0) == '[') 362.5702 - { 362.5703 - return RT.classForName(sym.name); 362.5704 - } 362.5705 - else if(sym.equals(NS)) 362.5706 - return RT.NS_VAR; 362.5707 - else if(sym.equals(IN_NS)) 362.5708 - return RT.IN_NS_VAR; 362.5709 - else 362.5710 - { 362.5711 - Object o = n.getMapping(sym); 362.5712 - return o; 362.5713 - } 362.5714 -} 362.5715 - 362.5716 - 362.5717 -static Var lookupVar(Symbol sym, boolean internNew) throws Exception{ 362.5718 - Var var = null; 362.5719 - 362.5720 - //note - ns-qualified vars in other namespaces must already exist 362.5721 - if(sym.ns != null) 362.5722 - { 362.5723 - Namespace ns = namespaceFor(sym); 362.5724 - if(ns == null) 362.5725 - return null; 362.5726 - //throw new Exception("No such namespace: " + sym.ns); 362.5727 - Symbol name = Symbol.create(sym.name); 362.5728 - if(internNew && ns == currentNS()) 362.5729 - var = currentNS().intern(name); 362.5730 - else 362.5731 - var = ns.findInternedVar(name); 362.5732 - } 362.5733 - else if(sym.equals(NS)) 362.5734 - var = RT.NS_VAR; 362.5735 - else if(sym.equals(IN_NS)) 362.5736 - var = RT.IN_NS_VAR; 362.5737 - else 362.5738 - { 362.5739 - //is it mapped? 362.5740 - Object o = currentNS().getMapping(sym); 362.5741 - if(o == null) 362.5742 - { 362.5743 - //introduce a new var in the current ns 362.5744 - if(internNew) 362.5745 - var = currentNS().intern(Symbol.create(sym.name)); 362.5746 - } 362.5747 - else if(o instanceof Var) 362.5748 - { 362.5749 - var = (Var) o; 362.5750 - } 362.5751 - else 362.5752 - { 362.5753 - throw new Exception("Expecting var, but " + sym + " is mapped to " + o); 362.5754 - } 362.5755 - } 362.5756 - if(var != null) 362.5757 - registerVar(var); 362.5758 - return var; 362.5759 -} 362.5760 - 362.5761 -private static void registerVar(Var var) throws Exception{ 362.5762 - if(!VARS.isBound()) 362.5763 - return; 362.5764 - IPersistentMap varsMap = (IPersistentMap) VARS.deref(); 362.5765 - Object id = RT.get(varsMap, var); 362.5766 - if(id == null) 362.5767 - { 362.5768 - VARS.set(RT.assoc(varsMap, var, registerConstant(var))); 362.5769 - } 362.5770 -// if(varsMap != null && RT.get(varsMap, var) == null) 362.5771 -// VARS.set(RT.assoc(varsMap, var, var)); 362.5772 -} 362.5773 - 362.5774 -static Namespace currentNS(){ 362.5775 - return (Namespace) RT.CURRENT_NS.deref(); 362.5776 -} 362.5777 - 362.5778 -static void closeOver(LocalBinding b, ObjMethod method){ 362.5779 - if(b != null && method != null) 362.5780 - { 362.5781 - if(RT.get(method.locals, b) == null) 362.5782 - { 362.5783 - method.objx.closes = (IPersistentMap) RT.assoc(method.objx.closes, b, b); 362.5784 - closeOver(b, method.parent); 362.5785 - } 362.5786 - else if(IN_CATCH_FINALLY.deref() != null) 362.5787 - { 362.5788 - method.localsUsedInCatchFinally = (PersistentHashSet) method.localsUsedInCatchFinally.cons(b.idx); 362.5789 - } 362.5790 - } 362.5791 -} 362.5792 - 362.5793 - 362.5794 -static LocalBinding referenceLocal(Symbol sym) throws Exception{ 362.5795 - if(!LOCAL_ENV.isBound()) 362.5796 - return null; 362.5797 - LocalBinding b = (LocalBinding) RT.get(LOCAL_ENV.deref(), sym); 362.5798 - if(b != null) 362.5799 - { 362.5800 - ObjMethod method = (ObjMethod) METHOD.deref(); 362.5801 - closeOver(b, method); 362.5802 - } 362.5803 - return b; 362.5804 -} 362.5805 - 362.5806 -private static Symbol tagOf(Object o){ 362.5807 - Object tag = RT.get(RT.meta(o), RT.TAG_KEY); 362.5808 - if(tag instanceof Symbol) 362.5809 - return (Symbol) tag; 362.5810 - else if(tag instanceof String) 362.5811 - return Symbol.intern(null, (String) tag); 362.5812 - return null; 362.5813 -} 362.5814 - 362.5815 -public static Object loadFile(String file) throws Exception{ 362.5816 -// File fo = new File(file); 362.5817 -// if(!fo.exists()) 362.5818 -// return null; 362.5819 - 362.5820 - FileInputStream f = new FileInputStream(file); 362.5821 - try 362.5822 - { 362.5823 - return load(new InputStreamReader(f, RT.UTF8), new File(file).getAbsolutePath(), (new File(file)).getName()); 362.5824 - } 362.5825 - finally 362.5826 - { 362.5827 - f.close(); 362.5828 - } 362.5829 -} 362.5830 - 362.5831 -public static Object load(Reader rdr) throws Exception{ 362.5832 - return load(rdr, null, "NO_SOURCE_FILE"); 362.5833 -} 362.5834 - 362.5835 -public static Object load(Reader rdr, String sourcePath, String sourceName) throws Exception{ 362.5836 - Object EOF = new Object(); 362.5837 - Object ret = null; 362.5838 - LineNumberingPushbackReader pushbackReader = 362.5839 - (rdr instanceof LineNumberingPushbackReader) ? (LineNumberingPushbackReader) rdr : 362.5840 - new LineNumberingPushbackReader(rdr); 362.5841 - Var.pushThreadBindings( 362.5842 - RT.map(LOADER, RT.makeClassLoader(), 362.5843 - SOURCE_PATH, sourcePath, 362.5844 - SOURCE, sourceName, 362.5845 - METHOD, null, 362.5846 - LOCAL_ENV, null, 362.5847 - LOOP_LOCALS, null, 362.5848 - NEXT_LOCAL_NUM, 0, 362.5849 - RT.CURRENT_NS, RT.CURRENT_NS.deref(), 362.5850 - LINE_BEFORE, pushbackReader.getLineNumber(), 362.5851 - LINE_AFTER, pushbackReader.getLineNumber() 362.5852 - )); 362.5853 - 362.5854 - try 362.5855 - { 362.5856 - for(Object r = LispReader.read(pushbackReader, false, EOF, false); r != EOF; 362.5857 - r = LispReader.read(pushbackReader, false, EOF, false)) 362.5858 - { 362.5859 - LINE_AFTER.set(pushbackReader.getLineNumber()); 362.5860 - ret = eval(r,false); 362.5861 - LINE_BEFORE.set(pushbackReader.getLineNumber()); 362.5862 - } 362.5863 - } 362.5864 - catch(LispReader.ReaderException e) 362.5865 - { 362.5866 - throw new CompilerException(sourceName, e.line, e.getCause()); 362.5867 - } 362.5868 - finally 362.5869 - { 362.5870 - Var.popThreadBindings(); 362.5871 - } 362.5872 - return ret; 362.5873 -} 362.5874 - 362.5875 -static public void writeClassFile(String internalName, byte[] bytecode) throws Exception{ 362.5876 - String genPath = (String) COMPILE_PATH.deref(); 362.5877 - if(genPath == null) 362.5878 - throw new Exception("*compile-path* not set"); 362.5879 - String[] dirs = internalName.split("/"); 362.5880 - String p = genPath; 362.5881 - for(int i = 0; i < dirs.length - 1; i++) 362.5882 - { 362.5883 - p += File.separator + dirs[i]; 362.5884 - (new File(p)).mkdir(); 362.5885 - } 362.5886 - String path = genPath + File.separator + internalName + ".class"; 362.5887 - File cf = new File(path); 362.5888 - cf.createNewFile(); 362.5889 - FileOutputStream cfs = new FileOutputStream(cf); 362.5890 - try 362.5891 - { 362.5892 - cfs.write(bytecode); 362.5893 - cfs.flush(); 362.5894 - cfs.getFD().sync(); 362.5895 - } 362.5896 - finally 362.5897 - { 362.5898 - cfs.close(); 362.5899 - } 362.5900 -} 362.5901 - 362.5902 -public static void pushNS(){ 362.5903 - Var.pushThreadBindings(PersistentHashMap.create(Var.intern(Symbol.create("clojure.core"), 362.5904 - Symbol.create("*ns*")), null)); 362.5905 -} 362.5906 - 362.5907 -public static ILookupThunk getLookupThunk(Object target, Keyword k){ 362.5908 - return null; //To change body of created methods use File | Settings | File Templates. 362.5909 -} 362.5910 - 362.5911 -static void compile1(GeneratorAdapter gen, ObjExpr objx, Object form) throws Exception{ 362.5912 - Integer line = (Integer) LINE.deref(); 362.5913 - if(RT.meta(form) != null && RT.meta(form).containsKey(RT.LINE_KEY)) 362.5914 - line = (Integer) RT.meta(form).valAt(RT.LINE_KEY); 362.5915 - Var.pushThreadBindings( 362.5916 - RT.map(LINE, line 362.5917 - ,LOADER, RT.makeClassLoader() 362.5918 - )); 362.5919 - try 362.5920 - { 362.5921 - form = macroexpand(form); 362.5922 - if(form instanceof IPersistentCollection && Util.equals(RT.first(form), DO)) 362.5923 - { 362.5924 - for(ISeq s = RT.next(form); s != null; s = RT.next(s)) 362.5925 - { 362.5926 - compile1(gen, objx, RT.first(s)); 362.5927 - } 362.5928 - } 362.5929 - else 362.5930 - { 362.5931 - Expr expr = analyze(C.EVAL, form); 362.5932 - objx.keywords = (IPersistentMap) KEYWORDS.deref(); 362.5933 - objx.vars = (IPersistentMap) VARS.deref(); 362.5934 - objx.constants = (PersistentVector) CONSTANTS.deref(); 362.5935 - expr.emit(C.EXPRESSION, objx, gen); 362.5936 - expr.eval(); 362.5937 - } 362.5938 - } 362.5939 - finally 362.5940 - { 362.5941 - Var.popThreadBindings(); 362.5942 - } 362.5943 -} 362.5944 - 362.5945 -public static Object compile(Reader rdr, String sourcePath, String sourceName) throws Exception{ 362.5946 - if(COMPILE_PATH.deref() == null) 362.5947 - throw new Exception("*compile-path* not set"); 362.5948 - 362.5949 - Object EOF = new Object(); 362.5950 - Object ret = null; 362.5951 - LineNumberingPushbackReader pushbackReader = 362.5952 - (rdr instanceof LineNumberingPushbackReader) ? (LineNumberingPushbackReader) rdr : 362.5953 - new LineNumberingPushbackReader(rdr); 362.5954 - Var.pushThreadBindings( 362.5955 - RT.map(SOURCE_PATH, sourcePath, 362.5956 - SOURCE, sourceName, 362.5957 - METHOD, null, 362.5958 - LOCAL_ENV, null, 362.5959 - LOOP_LOCALS, null, 362.5960 - NEXT_LOCAL_NUM, 0, 362.5961 - RT.CURRENT_NS, RT.CURRENT_NS.deref(), 362.5962 - LINE_BEFORE, pushbackReader.getLineNumber(), 362.5963 - LINE_AFTER, pushbackReader.getLineNumber(), 362.5964 - CONSTANTS, PersistentVector.EMPTY, 362.5965 - CONSTANT_IDS, new IdentityHashMap(), 362.5966 - KEYWORDS, PersistentHashMap.EMPTY, 362.5967 - VARS, PersistentHashMap.EMPTY 362.5968 - // ,LOADER, RT.makeClassLoader() 362.5969 - )); 362.5970 - 362.5971 - try 362.5972 - { 362.5973 - //generate loader class 362.5974 - ObjExpr objx = new ObjExpr(null); 362.5975 - objx.internalName = sourcePath.replace(File.separator, "/").substring(0, sourcePath.lastIndexOf('.')) 362.5976 - + RT.LOADER_SUFFIX; 362.5977 - 362.5978 - objx.objtype = Type.getObjectType(objx.internalName); 362.5979 - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 362.5980 - ClassVisitor cv = cw; 362.5981 - cv.visit(V1_5, ACC_PUBLIC + ACC_SUPER, objx.internalName, null, "java/lang/Object", null); 362.5982 - 362.5983 - //static load method 362.5984 - GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC + ACC_STATIC, 362.5985 - Method.getMethod("void load ()"), 362.5986 - null, 362.5987 - null, 362.5988 - cv); 362.5989 - gen.visitCode(); 362.5990 - 362.5991 - for(Object r = LispReader.read(pushbackReader, false, EOF, false); r != EOF; 362.5992 - r = LispReader.read(pushbackReader, false, EOF, false)) 362.5993 - { 362.5994 - LINE_AFTER.set(pushbackReader.getLineNumber()); 362.5995 - compile1(gen, objx, r); 362.5996 - LINE_BEFORE.set(pushbackReader.getLineNumber()); 362.5997 - } 362.5998 - //end of load 362.5999 - gen.returnValue(); 362.6000 - gen.endMethod(); 362.6001 - 362.6002 - //static fields for constants 362.6003 - for(int i = 0; i < objx.constants.count(); i++) 362.6004 - { 362.6005 - cv.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, objx.constantName(i), objx.constantType(i).getDescriptor(), 362.6006 - null, null); 362.6007 - } 362.6008 - 362.6009 - //static init for constants, keywords and vars 362.6010 - GeneratorAdapter clinitgen = new GeneratorAdapter(ACC_PUBLIC + ACC_STATIC, 362.6011 - Method.getMethod("void <clinit> ()"), 362.6012 - null, 362.6013 - null, 362.6014 - cv); 362.6015 - clinitgen.visitCode(); 362.6016 - Label startTry = clinitgen.newLabel(); 362.6017 - Label endTry = clinitgen.newLabel(); 362.6018 - Label end = clinitgen.newLabel(); 362.6019 - Label finallyLabel = clinitgen.newLabel(); 362.6020 - 362.6021 - if(objx.constants.count() > 0) 362.6022 - { 362.6023 - objx.emitConstants(clinitgen); 362.6024 - } 362.6025 - clinitgen.invokeStatic(Type.getType(Compiler.class), Method.getMethod("void pushNS()")); 362.6026 - clinitgen.mark(startTry); 362.6027 - clinitgen.invokeStatic(objx.objtype, Method.getMethod("void load()")); 362.6028 - clinitgen.mark(endTry); 362.6029 - clinitgen.invokeStatic(VAR_TYPE, Method.getMethod("void popThreadBindings()")); 362.6030 - clinitgen.goTo(end); 362.6031 - 362.6032 - clinitgen.mark(finallyLabel); 362.6033 - //exception should be on stack 362.6034 - clinitgen.invokeStatic(VAR_TYPE, Method.getMethod("void popThreadBindings()")); 362.6035 - clinitgen.throwException(); 362.6036 - clinitgen.mark(end); 362.6037 - clinitgen.visitTryCatchBlock(startTry, endTry, finallyLabel, null); 362.6038 - 362.6039 - //end of static init 362.6040 - clinitgen.returnValue(); 362.6041 - clinitgen.endMethod(); 362.6042 - 362.6043 - //end of class 362.6044 - cv.visitEnd(); 362.6045 - 362.6046 - writeClassFile(objx.internalName, cw.toByteArray()); 362.6047 - } 362.6048 - catch(LispReader.ReaderException e) 362.6049 - { 362.6050 - throw new CompilerException(sourceName, e.line, e.getCause()); 362.6051 - } 362.6052 - finally 362.6053 - { 362.6054 - Var.popThreadBindings(); 362.6055 - } 362.6056 - return ret; 362.6057 -} 362.6058 - 362.6059 - 362.6060 -static public class NewInstanceExpr extends ObjExpr{ 362.6061 - //IPersistentMap optionsMap = PersistentArrayMap.EMPTY; 362.6062 - IPersistentCollection methods; 362.6063 - 362.6064 - Map<IPersistentVector,java.lang.reflect.Method> mmap; 362.6065 - Map<IPersistentVector,Set<Class>> covariants; 362.6066 - 362.6067 - public NewInstanceExpr(Object tag){ 362.6068 - super(tag); 362.6069 - } 362.6070 - 362.6071 - static class DeftypeParser implements IParser{ 362.6072 - public Expr parse(C context, final Object frm) throws Exception{ 362.6073 - ISeq rform = (ISeq) frm; 362.6074 - //(deftype* tagname classname [fields] :implements [interfaces] :tag tagname methods*) 362.6075 - rform = RT.next(rform); 362.6076 - String tagname = ((Symbol) rform.first()).toString(); 362.6077 - rform = rform.next(); 362.6078 - Symbol classname = (Symbol) rform.first(); 362.6079 - rform = rform.next(); 362.6080 - IPersistentVector fields = (IPersistentVector) rform.first(); 362.6081 - rform = rform.next(); 362.6082 - IPersistentMap opts = PersistentHashMap.EMPTY; 362.6083 - while(rform != null && rform.first() instanceof Keyword) 362.6084 - { 362.6085 - opts = opts.assoc(rform.first(), RT.second(rform)); 362.6086 - rform = rform.next().next(); 362.6087 - } 362.6088 - 362.6089 - ObjExpr ret = build((IPersistentVector)RT.get(opts,implementsKey,PersistentVector.EMPTY),fields,null,tagname, classname, 362.6090 - (Symbol) RT.get(opts,RT.TAG_KEY),rform, frm); 362.6091 - return ret; 362.6092 - } 362.6093 - } 362.6094 - 362.6095 - static class ReifyParser implements IParser{ 362.6096 - public Expr parse(C context, Object frm) throws Exception{ 362.6097 - //(reify this-name? [interfaces] (method-name [args] body)*) 362.6098 - ISeq form = (ISeq) frm; 362.6099 - ObjMethod enclosingMethod = (ObjMethod) METHOD.deref(); 362.6100 - String basename = enclosingMethod != null ? 362.6101 - (trimGenID(enclosingMethod.objx.name) + "$") 362.6102 - : (munge(currentNS().name.name) + "$"); 362.6103 - String simpleName = "reify__" + RT.nextID(); 362.6104 - String classname = basename + simpleName; 362.6105 - 362.6106 - ISeq rform = RT.next(form); 362.6107 - 362.6108 - IPersistentVector interfaces = ((IPersistentVector) RT.first(rform)).cons(Symbol.intern("clojure.lang.IObj")); 362.6109 - 362.6110 - 362.6111 - rform = RT.next(rform); 362.6112 - 362.6113 - 362.6114 - ObjExpr ret = build(interfaces, null, null, classname, Symbol.intern(classname), null, rform, frm); 362.6115 - if(frm instanceof IObj && ((IObj) frm).meta() != null) 362.6116 - return new MetaExpr(ret, (MapExpr) MapExpr 362.6117 - .parse(context == C.EVAL ? context : C.EXPRESSION, ((IObj) frm).meta())); 362.6118 - else 362.6119 - return ret; 362.6120 - } 362.6121 - } 362.6122 - 362.6123 - static ObjExpr build(IPersistentVector interfaceSyms, IPersistentVector fieldSyms, Symbol thisSym, 362.6124 - String tagName, Symbol className, 362.6125 - Symbol typeTag, ISeq methodForms, Object frm) throws Exception{ 362.6126 - NewInstanceExpr ret = new NewInstanceExpr(null); 362.6127 - 362.6128 - ret.src = frm; 362.6129 - ret.name = className.toString(); 362.6130 - ret.classMeta = RT.meta(className); 362.6131 - ret.internalName = ret.name.replace('.', '/'); 362.6132 - ret.objtype = Type.getObjectType(ret.internalName); 362.6133 - 362.6134 - if(thisSym != null) 362.6135 - ret.thisName = thisSym.name; 362.6136 - 362.6137 - if(fieldSyms != null) 362.6138 - { 362.6139 - IPersistentMap fmap = PersistentHashMap.EMPTY; 362.6140 - Object[] closesvec = new Object[2 * fieldSyms.count()]; 362.6141 - for(int i=0;i<fieldSyms.count();i++) 362.6142 - { 362.6143 - Symbol sym = (Symbol) fieldSyms.nth(i); 362.6144 - LocalBinding lb = new LocalBinding(-1, sym, null, 362.6145 - new MethodParamExpr(tagClass(tagOf(sym))),false,null); 362.6146 - fmap = fmap.assoc(sym, lb); 362.6147 - closesvec[i*2] = lb; 362.6148 - closesvec[i*2 + 1] = lb; 362.6149 - } 362.6150 - 362.6151 - //todo - inject __meta et al into closes - when? 362.6152 - //use array map to preserve ctor order 362.6153 - ret.closes = new PersistentArrayMap(closesvec); 362.6154 - ret.fields = fmap; 362.6155 - for(int i=fieldSyms.count()-1;i >= 0 && ((Symbol)fieldSyms.nth(i)).name.startsWith("__");--i) 362.6156 - ret.altCtorDrops++; 362.6157 - } 362.6158 - //todo - set up volatiles 362.6159 -// ret.volatiles = PersistentHashSet.create(RT.seq(RT.get(ret.optionsMap, volatileKey))); 362.6160 - 362.6161 - PersistentVector interfaces = PersistentVector.EMPTY; 362.6162 - for(ISeq s = RT.seq(interfaceSyms);s!=null;s = s.next()) 362.6163 - { 362.6164 - Class c = (Class) resolve((Symbol) s.first()); 362.6165 - if(!c.isInterface()) 362.6166 - throw new IllegalArgumentException("only interfaces are supported, had: " + c.getName()); 362.6167 - interfaces = interfaces.cons(c); 362.6168 - } 362.6169 - Class superClass = Object.class; 362.6170 - Map[] mc = gatherMethods(superClass,RT.seq(interfaces)); 362.6171 - Map overrideables = mc[0]; 362.6172 - Map covariants = mc[1]; 362.6173 - ret.mmap = overrideables; 362.6174 - ret.covariants = covariants; 362.6175 - 362.6176 - String[] inames = interfaceNames(interfaces); 362.6177 - 362.6178 - Class stub = compileStub(slashname(superClass),ret, inames, frm); 362.6179 - Symbol thistag = Symbol.intern(null,stub.getName()); 362.6180 - 362.6181 - try 362.6182 - { 362.6183 - Var.pushThreadBindings( 362.6184 - RT.map(CONSTANTS, PersistentVector.EMPTY, 362.6185 - CONSTANT_IDS, new IdentityHashMap(), 362.6186 - KEYWORDS, PersistentHashMap.EMPTY, 362.6187 - VARS, PersistentHashMap.EMPTY, 362.6188 - KEYWORD_CALLSITES, PersistentVector.EMPTY, 362.6189 - PROTOCOL_CALLSITES, PersistentVector.EMPTY, 362.6190 - VAR_CALLSITES, PersistentVector.EMPTY 362.6191 - )); 362.6192 - if(ret.isDeftype()) 362.6193 - { 362.6194 - Var.pushThreadBindings(RT.map(METHOD, null, 362.6195 - LOCAL_ENV, ret.fields 362.6196 - , COMPILE_STUB_SYM, Symbol.intern(null, tagName) 362.6197 - , COMPILE_STUB_CLASS, stub)); 362.6198 - } 362.6199 - 362.6200 - //now (methodname [args] body)* 362.6201 - ret.line = (Integer) LINE.deref(); 362.6202 - IPersistentCollection methods = null; 362.6203 - for(ISeq s = methodForms; s != null; s = RT.next(s)) 362.6204 - { 362.6205 - NewInstanceMethod m = NewInstanceMethod.parse(ret, (ISeq) RT.first(s),thistag, overrideables); 362.6206 - methods = RT.conj(methods, m); 362.6207 - } 362.6208 - 362.6209 - 362.6210 - ret.methods = methods; 362.6211 - ret.keywords = (IPersistentMap) KEYWORDS.deref(); 362.6212 - ret.vars = (IPersistentMap) VARS.deref(); 362.6213 - ret.constants = (PersistentVector) CONSTANTS.deref(); 362.6214 - ret.constantsID = RT.nextID(); 362.6215 - ret.keywordCallsites = (IPersistentVector) KEYWORD_CALLSITES.deref(); 362.6216 - ret.protocolCallsites = (IPersistentVector) PROTOCOL_CALLSITES.deref(); 362.6217 - ret.varCallsites = (IPersistentVector) VAR_CALLSITES.deref(); 362.6218 - } 362.6219 - finally 362.6220 - { 362.6221 - if(ret.isDeftype()) 362.6222 - Var.popThreadBindings(); 362.6223 - Var.popThreadBindings(); 362.6224 - } 362.6225 - 362.6226 - ret.compile(slashname(superClass),inames,false); 362.6227 - ret.getCompiledClass(); 362.6228 - return ret; 362.6229 - } 362.6230 - 362.6231 - /*** 362.6232 - * Current host interop uses reflection, which requires pre-existing classes 362.6233 - * Work around this by: 362.6234 - * Generate a stub class that has the same interfaces and fields as the class we are generating. 362.6235 - * Use it as a type hint for this, and bind the simple name of the class to this stub (in resolve etc) 362.6236 - * Unmunge the name (using a magic prefix) on any code gen for classes 362.6237 - */ 362.6238 - static Class compileStub(String superName, NewInstanceExpr ret, String[] interfaceNames, Object frm){ 362.6239 - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 362.6240 - ClassVisitor cv = cw; 362.6241 - cv.visit(V1_5, ACC_PUBLIC + ACC_SUPER, COMPILE_STUB_PREFIX + "/" + ret.internalName, 362.6242 - null,superName,interfaceNames); 362.6243 - 362.6244 - //instance fields for closed-overs 362.6245 - for(ISeq s = RT.keys(ret.closes); s != null; s = s.next()) 362.6246 - { 362.6247 - LocalBinding lb = (LocalBinding) s.first(); 362.6248 - int access = ACC_PUBLIC + (ret.isVolatile(lb) ? ACC_VOLATILE : 362.6249 - ret.isMutable(lb) ? 0 : 362.6250 - ACC_FINAL); 362.6251 - if(lb.getPrimitiveType() != null) 362.6252 - cv.visitField(access 362.6253 - , lb.name, Type.getType(lb.getPrimitiveType()).getDescriptor(), 362.6254 - null, null); 362.6255 - else 362.6256 - //todo - when closed-overs are fields, use more specific types here and in ctor and emitLocal? 362.6257 - cv.visitField(access 362.6258 - , lb.name, OBJECT_TYPE.getDescriptor(), null, null); 362.6259 - } 362.6260 - 362.6261 - //ctor that takes closed-overs and does nothing 362.6262 - Method m = new Method("<init>", Type.VOID_TYPE, ret.ctorTypes()); 362.6263 - GeneratorAdapter ctorgen = new GeneratorAdapter(ACC_PUBLIC, 362.6264 - m, 362.6265 - null, 362.6266 - null, 362.6267 - cv); 362.6268 - ctorgen.visitCode(); 362.6269 - ctorgen.loadThis(); 362.6270 - ctorgen.invokeConstructor(Type.getObjectType(superName), voidctor); 362.6271 - ctorgen.returnValue(); 362.6272 - ctorgen.endMethod(); 362.6273 - 362.6274 - if(ret.altCtorDrops > 0) 362.6275 - { 362.6276 - Type[] ctorTypes = ret.ctorTypes(); 362.6277 - Type[] altCtorTypes = new Type[ctorTypes.length-ret.altCtorDrops]; 362.6278 - for(int i=0;i<altCtorTypes.length;i++) 362.6279 - altCtorTypes[i] = ctorTypes[i]; 362.6280 - Method alt = new Method("<init>", Type.VOID_TYPE, altCtorTypes); 362.6281 - ctorgen = new GeneratorAdapter(ACC_PUBLIC, 362.6282 - alt, 362.6283 - null, 362.6284 - null, 362.6285 - cv); 362.6286 - ctorgen.visitCode(); 362.6287 - ctorgen.loadThis(); 362.6288 - ctorgen.loadArgs(); 362.6289 - for(int i=0;i<ret.altCtorDrops;i++) 362.6290 - ctorgen.visitInsn(Opcodes.ACONST_NULL); 362.6291 - 362.6292 - ctorgen.invokeConstructor(Type.getObjectType(COMPILE_STUB_PREFIX + "/" + ret.internalName), 362.6293 - new Method("<init>", Type.VOID_TYPE, ctorTypes)); 362.6294 - 362.6295 - ctorgen.returnValue(); 362.6296 - ctorgen.endMethod(); 362.6297 - } 362.6298 - //end of class 362.6299 - cv.visitEnd(); 362.6300 - 362.6301 - byte[] bytecode = cw.toByteArray(); 362.6302 - DynamicClassLoader loader = (DynamicClassLoader) LOADER.deref(); 362.6303 - return loader.defineClass(COMPILE_STUB_PREFIX + "." + ret.name, bytecode, frm); 362.6304 - } 362.6305 - 362.6306 - static String[] interfaceNames(IPersistentVector interfaces){ 362.6307 - int icnt = interfaces.count(); 362.6308 - String[] inames = icnt > 0 ? new String[icnt] : null; 362.6309 - for(int i=0;i<icnt;i++) 362.6310 - inames[i] = slashname((Class) interfaces.nth(i)); 362.6311 - return inames; 362.6312 - } 362.6313 - 362.6314 - 362.6315 - static String slashname(Class c){ 362.6316 - return c.getName().replace('.', '/'); 362.6317 - } 362.6318 - 362.6319 - 362.6320 - protected void emitMethods(ClassVisitor cv){ 362.6321 - for(ISeq s = RT.seq(methods); s != null; s = s.next()) 362.6322 - { 362.6323 - ObjMethod method = (ObjMethod) s.first(); 362.6324 - method.emit(this, cv); 362.6325 - } 362.6326 - //emit bridge methods 362.6327 - for(Map.Entry<IPersistentVector,Set<Class>> e : covariants.entrySet()) 362.6328 - { 362.6329 - java.lang.reflect.Method m = mmap.get(e.getKey()); 362.6330 - Class[] params = m.getParameterTypes(); 362.6331 - Type[] argTypes = new Type[params.length]; 362.6332 - 362.6333 - for(int i = 0; i < params.length; i++) 362.6334 - { 362.6335 - argTypes[i] = Type.getType(params[i]); 362.6336 - } 362.6337 - 362.6338 - Method target = new Method(m.getName(), Type.getType(m.getReturnType()), argTypes); 362.6339 - 362.6340 - for(Class retType : e.getValue()) 362.6341 - { 362.6342 - Method meth = new Method(m.getName(), Type.getType(retType), argTypes); 362.6343 - 362.6344 - GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC + ACC_BRIDGE, 362.6345 - meth, 362.6346 - null, 362.6347 - //todo don't hardwire this 362.6348 - EXCEPTION_TYPES, 362.6349 - cv); 362.6350 - gen.visitCode(); 362.6351 - gen.loadThis(); 362.6352 - gen.loadArgs(); 362.6353 - gen.invokeInterface(Type.getType(m.getDeclaringClass()),target); 362.6354 - gen.returnValue(); 362.6355 - gen.endMethod(); 362.6356 - } 362.6357 - } 362.6358 - } 362.6359 - 362.6360 - static public IPersistentVector msig(java.lang.reflect.Method m){ 362.6361 - return RT.vector(m.getName(), RT.seq(m.getParameterTypes()),m.getReturnType()); 362.6362 - } 362.6363 - 362.6364 - static void considerMethod(java.lang.reflect.Method m, Map mm){ 362.6365 - IPersistentVector mk = msig(m); 362.6366 - int mods = m.getModifiers(); 362.6367 - 362.6368 - if(!(mm.containsKey(mk) 362.6369 - || !(Modifier.isPublic(mods) || Modifier.isProtected(mods)) 362.6370 - || Modifier.isStatic(mods) 362.6371 - || Modifier.isFinal(mods))) 362.6372 - { 362.6373 - mm.put(mk, m); 362.6374 - } 362.6375 - } 362.6376 - 362.6377 - static void gatherMethods(Class c, Map mm){ 362.6378 - for(; c != null; c = c.getSuperclass()) 362.6379 - { 362.6380 - for(java.lang.reflect.Method m : c.getDeclaredMethods()) 362.6381 - considerMethod(m, mm); 362.6382 - for(java.lang.reflect.Method m : c.getMethods()) 362.6383 - considerMethod(m, mm); 362.6384 - } 362.6385 - } 362.6386 - 362.6387 - static public Map[] gatherMethods(Class sc, ISeq interfaces){ 362.6388 - Map allm = new HashMap(); 362.6389 - gatherMethods(sc, allm); 362.6390 - for(; interfaces != null; interfaces = interfaces.next()) 362.6391 - gatherMethods((Class) interfaces.first(), allm); 362.6392 - 362.6393 - Map<IPersistentVector,java.lang.reflect.Method> mm = new HashMap<IPersistentVector,java.lang.reflect.Method>(); 362.6394 - Map<IPersistentVector,Set<Class>> covariants = new HashMap<IPersistentVector,Set<Class>>(); 362.6395 - for(Object o : allm.entrySet()) 362.6396 - { 362.6397 - Map.Entry e = (Map.Entry) o; 362.6398 - IPersistentVector mk = (IPersistentVector) e.getKey(); 362.6399 - mk = (IPersistentVector) mk.pop(); 362.6400 - java.lang.reflect.Method m = (java.lang.reflect.Method) e.getValue(); 362.6401 - if(mm.containsKey(mk)) //covariant return 362.6402 - { 362.6403 - Set<Class> cvs = covariants.get(mk); 362.6404 - if(cvs == null) 362.6405 - { 362.6406 - cvs = new HashSet<Class>(); 362.6407 - covariants.put(mk,cvs); 362.6408 - } 362.6409 - java.lang.reflect.Method om = mm.get(mk); 362.6410 - if(om.getReturnType().isAssignableFrom(m.getReturnType())) 362.6411 - { 362.6412 - cvs.add(om.getReturnType()); 362.6413 - mm.put(mk, m); 362.6414 - } 362.6415 - else 362.6416 - cvs.add(m.getReturnType()); 362.6417 - } 362.6418 - else 362.6419 - mm.put(mk, m); 362.6420 - } 362.6421 - return new Map[]{mm,covariants}; 362.6422 - } 362.6423 -} 362.6424 - 362.6425 -public static class NewInstanceMethod extends ObjMethod{ 362.6426 - String name; 362.6427 - Type[] argTypes; 362.6428 - Type retType; 362.6429 - Class retClass; 362.6430 - Class[] exclasses; 362.6431 - 362.6432 - static Symbol dummyThis = Symbol.intern(null,"dummy_this_dlskjsdfower"); 362.6433 - private IPersistentVector parms; 362.6434 - 362.6435 - public NewInstanceMethod(ObjExpr objx, ObjMethod parent){ 362.6436 - super(objx, parent); 362.6437 - } 362.6438 - 362.6439 - int numParams(){ 362.6440 - return argLocals.count(); 362.6441 - } 362.6442 - 362.6443 - String getMethodName(){ 362.6444 - return name; 362.6445 - } 362.6446 - 362.6447 - Type getReturnType(){ 362.6448 - return retType; 362.6449 - } 362.6450 - 362.6451 - Type[] getArgTypes(){ 362.6452 - return argTypes; 362.6453 - } 362.6454 - 362.6455 - 362.6456 - 362.6457 - static public IPersistentVector msig(String name,Class[] paramTypes){ 362.6458 - return RT.vector(name,RT.seq(paramTypes)); 362.6459 - } 362.6460 - 362.6461 - static NewInstanceMethod parse(ObjExpr objx, ISeq form, Symbol thistag, 362.6462 - Map overrideables) throws Exception{ 362.6463 - //(methodname [this-name args*] body...) 362.6464 - //this-name might be nil 362.6465 - NewInstanceMethod method = new NewInstanceMethod(objx, (ObjMethod) METHOD.deref()); 362.6466 - Symbol dotname = (Symbol)RT.first(form); 362.6467 - Symbol name = (Symbol) Symbol.intern(null,munge(dotname.name)).withMeta(RT.meta(dotname)); 362.6468 - IPersistentVector parms = (IPersistentVector) RT.second(form); 362.6469 - if(parms.count() == 0) 362.6470 - { 362.6471 - throw new IllegalArgumentException("Must supply at least one argument for 'this' in: " + dotname); 362.6472 - } 362.6473 - Symbol thisName = (Symbol) parms.nth(0); 362.6474 - parms = RT.subvec(parms,1,parms.count()); 362.6475 - ISeq body = RT.next(RT.next(form)); 362.6476 - try 362.6477 - { 362.6478 - method.line = (Integer) LINE.deref(); 362.6479 - //register as the current method and set up a new env frame 362.6480 - PathNode pnode = new PathNode(PATHTYPE.PATH, (PathNode) CLEAR_PATH.get()); 362.6481 - Var.pushThreadBindings( 362.6482 - RT.map( 362.6483 - METHOD, method, 362.6484 - LOCAL_ENV, LOCAL_ENV.deref(), 362.6485 - LOOP_LOCALS, null, 362.6486 - NEXT_LOCAL_NUM, 0 362.6487 - ,CLEAR_PATH, pnode 362.6488 - ,CLEAR_ROOT, pnode 362.6489 - ,CLEAR_SITES, PersistentHashMap.EMPTY 362.6490 - )); 362.6491 - 362.6492 - //register 'this' as local 0 362.6493 - if(thisName != null) 362.6494 - registerLocal((thisName == null) ? dummyThis:thisName,thistag, null,false); 362.6495 - else 362.6496 - getAndIncLocalNum(); 362.6497 - 362.6498 - PersistentVector argLocals = PersistentVector.EMPTY; 362.6499 - method.retClass = tagClass(tagOf(name)); 362.6500 - method.argTypes = new Type[parms.count()]; 362.6501 - boolean hinted = tagOf(name) != null; 362.6502 - Class[] pclasses = new Class[parms.count()]; 362.6503 - Symbol[] psyms = new Symbol[parms.count()]; 362.6504 - 362.6505 - for(int i = 0; i < parms.count(); i++) 362.6506 - { 362.6507 - if(!(parms.nth(i) instanceof Symbol)) 362.6508 - throw new IllegalArgumentException("params must be Symbols"); 362.6509 - Symbol p = (Symbol) parms.nth(i); 362.6510 - Object tag = tagOf(p); 362.6511 - if(tag != null) 362.6512 - hinted = true; 362.6513 - if(p.getNamespace() != null) 362.6514 - p = Symbol.create(p.name); 362.6515 - Class pclass = tagClass(tag); 362.6516 - pclasses[i] = pclass; 362.6517 - psyms[i] = p; 362.6518 - } 362.6519 - Map matches = findMethodsWithNameAndArity(name.name, parms.count(), overrideables); 362.6520 - Object mk = msig(name.name, pclasses); 362.6521 - java.lang.reflect.Method m = null; 362.6522 - if(matches.size() > 0) 362.6523 - { 362.6524 - //multiple methods 362.6525 - if(matches.size() > 1) 362.6526 - { 362.6527 - //must be hinted and match one method 362.6528 - if(!hinted) 362.6529 - throw new IllegalArgumentException("Must hint overloaded method: " + name.name); 362.6530 - m = (java.lang.reflect.Method) matches.get(mk); 362.6531 - if(m == null) 362.6532 - throw new IllegalArgumentException("Can't find matching overloaded method: " + name.name); 362.6533 - if(m.getReturnType() != method.retClass) 362.6534 - throw new IllegalArgumentException("Mismatched return type: " + name.name + 362.6535 - ", expected: " + m.getReturnType().getName() + ", had: " + method.retClass.getName()); 362.6536 - } 362.6537 - else //one match 362.6538 - { 362.6539 - //if hinted, validate match, 362.6540 - if(hinted) 362.6541 - { 362.6542 - m = (java.lang.reflect.Method) matches.get(mk); 362.6543 - if(m == null) 362.6544 - throw new IllegalArgumentException("Can't find matching method: " + name.name + 362.6545 - ", leave off hints for auto match."); 362.6546 - if(m.getReturnType() != method.retClass) 362.6547 - throw new IllegalArgumentException("Mismatched return type: " + name.name + 362.6548 - ", expected: " + m.getReturnType().getName() + ", had: " + method.retClass.getName()); 362.6549 - } 362.6550 - else //adopt found method sig 362.6551 - { 362.6552 - m = (java.lang.reflect.Method) matches.values().iterator().next(); 362.6553 - method.retClass = m.getReturnType(); 362.6554 - pclasses = m.getParameterTypes(); 362.6555 - } 362.6556 - } 362.6557 - } 362.6558 -// else if(findMethodsWithName(name.name,allmethods).size()>0) 362.6559 -// throw new IllegalArgumentException("Can't override/overload method: " + name.name); 362.6560 - else 362.6561 - throw new IllegalArgumentException("Can't define method not in interfaces: " + name.name); 362.6562 - 362.6563 - //else 362.6564 - //validate unque name+arity among additional methods 362.6565 - 362.6566 - method.retType = Type.getType(method.retClass); 362.6567 - method.exclasses = m.getExceptionTypes(); 362.6568 - 362.6569 - for(int i = 0; i < parms.count(); i++) 362.6570 - { 362.6571 - LocalBinding lb = registerLocal(psyms[i], null, new MethodParamExpr(pclasses[i]),true); 362.6572 - argLocals = argLocals.assocN(i,lb); 362.6573 - method.argTypes[i] = Type.getType(pclasses[i]); 362.6574 - } 362.6575 - for(int i = 0; i < parms.count(); i++) 362.6576 - { 362.6577 - if(pclasses[i] == long.class || pclasses[i] == double.class) 362.6578 - getAndIncLocalNum(); 362.6579 - } 362.6580 - LOOP_LOCALS.set(argLocals); 362.6581 - method.name = name.name; 362.6582 - method.methodMeta = RT.meta(name); 362.6583 - method.parms = parms; 362.6584 - method.argLocals = argLocals; 362.6585 - method.body = (new BodyExpr.Parser()).parse(C.RETURN, body); 362.6586 - return method; 362.6587 - } 362.6588 - finally 362.6589 - { 362.6590 - Var.popThreadBindings(); 362.6591 - } 362.6592 - } 362.6593 - 362.6594 - private static Map findMethodsWithNameAndArity(String name, int arity, Map mm){ 362.6595 - Map ret = new HashMap(); 362.6596 - for(Object o : mm.entrySet()) 362.6597 - { 362.6598 - Map.Entry e = (Map.Entry) o; 362.6599 - java.lang.reflect.Method m = (java.lang.reflect.Method) e.getValue(); 362.6600 - if(name.equals(m.getName()) && m.getParameterTypes().length == arity) 362.6601 - ret.put(e.getKey(), e.getValue()); 362.6602 - } 362.6603 - return ret; 362.6604 - } 362.6605 - 362.6606 - private static Map findMethodsWithName(String name, Map mm){ 362.6607 - Map ret = new HashMap(); 362.6608 - for(Object o : mm.entrySet()) 362.6609 - { 362.6610 - Map.Entry e = (Map.Entry) o; 362.6611 - java.lang.reflect.Method m = (java.lang.reflect.Method) e.getValue(); 362.6612 - if(name.equals(m.getName())) 362.6613 - ret.put(e.getKey(), e.getValue()); 362.6614 - } 362.6615 - return ret; 362.6616 - } 362.6617 - 362.6618 - public void emit(ObjExpr obj, ClassVisitor cv){ 362.6619 - Method m = new Method(getMethodName(), getReturnType(), getArgTypes()); 362.6620 - 362.6621 - Type[] extypes = null; 362.6622 - if(exclasses.length > 0) 362.6623 - { 362.6624 - extypes = new Type[exclasses.length]; 362.6625 - for(int i=0;i<exclasses.length;i++) 362.6626 - extypes[i] = Type.getType(exclasses[i]); 362.6627 - } 362.6628 - GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC, 362.6629 - m, 362.6630 - null, 362.6631 - extypes, 362.6632 - cv); 362.6633 - addAnnotation(gen,methodMeta); 362.6634 - for(int i = 0; i < parms.count(); i++) 362.6635 - { 362.6636 - IPersistentMap meta = RT.meta(parms.nth(i)); 362.6637 - addParameterAnnotation(gen, meta, i); 362.6638 - } 362.6639 - gen.visitCode(); 362.6640 - Label loopLabel = gen.mark(); 362.6641 - gen.visitLineNumber(line, loopLabel); 362.6642 - try 362.6643 - { 362.6644 - Var.pushThreadBindings(RT.map(LOOP_LABEL, loopLabel, METHOD, this)); 362.6645 - MaybePrimitiveExpr be = (MaybePrimitiveExpr) body; 362.6646 - if(Util.isPrimitive(retClass) && be.canEmitPrimitive()) 362.6647 - { 362.6648 - if(be.getJavaClass() == retClass) 362.6649 - be.emitUnboxed(C.RETURN,obj,gen); 362.6650 - //todo - support the standard widening conversions 362.6651 - else 362.6652 - throw new IllegalArgumentException("Mismatched primitive return, expected: " 362.6653 - + retClass + ", had: " + be.getJavaClass()); 362.6654 - } 362.6655 - else 362.6656 - { 362.6657 - body.emit(C.RETURN, obj, gen); 362.6658 - if(retClass == void.class) 362.6659 - { 362.6660 - gen.pop(); 362.6661 - } 362.6662 - else 362.6663 - gen.unbox(retType); 362.6664 - } 362.6665 - 362.6666 - Label end = gen.mark(); 362.6667 - gen.visitLocalVariable("this", obj.objtype.getDescriptor(), null, loopLabel, end, 0); 362.6668 - for(ISeq lbs = argLocals.seq(); lbs != null; lbs = lbs.next()) 362.6669 - { 362.6670 - LocalBinding lb = (LocalBinding) lbs.first(); 362.6671 - gen.visitLocalVariable(lb.name, argTypes[lb.idx-1].getDescriptor(), null, loopLabel, end, lb.idx); 362.6672 - } 362.6673 - } 362.6674 - catch(Exception e) 362.6675 - { 362.6676 - throw new RuntimeException(e); 362.6677 - } 362.6678 - finally 362.6679 - { 362.6680 - Var.popThreadBindings(); 362.6681 - } 362.6682 - 362.6683 - gen.returnValue(); 362.6684 - //gen.visitMaxs(1, 1); 362.6685 - gen.endMethod(); 362.6686 - } 362.6687 -} 362.6688 - 362.6689 - static Class primClass(Symbol sym){ 362.6690 - if(sym == null) 362.6691 - return null; 362.6692 - Class c = null; 362.6693 - if(sym.name.equals("int")) 362.6694 - c = int.class; 362.6695 - else if(sym.name.equals("long")) 362.6696 - c = long.class; 362.6697 - else if(sym.name.equals("float")) 362.6698 - c = float.class; 362.6699 - else if(sym.name.equals("double")) 362.6700 - c = double.class; 362.6701 - else if(sym.name.equals("char")) 362.6702 - c = char.class; 362.6703 - else if(sym.name.equals("short")) 362.6704 - c = short.class; 362.6705 - else if(sym.name.equals("byte")) 362.6706 - c = byte.class; 362.6707 - else if(sym.name.equals("boolean")) 362.6708 - c = boolean.class; 362.6709 - else if(sym.name.equals("void")) 362.6710 - c = void.class; 362.6711 - return c; 362.6712 - } 362.6713 - 362.6714 - static Class tagClass(Object tag) throws Exception{ 362.6715 - if(tag == null) 362.6716 - return Object.class; 362.6717 - Class c = null; 362.6718 - if(tag instanceof Symbol) 362.6719 - c = primClass((Symbol) tag); 362.6720 - if(c == null) 362.6721 - c = HostExpr.tagToClass(tag); 362.6722 - return c; 362.6723 - } 362.6724 - 362.6725 -static public class MethodParamExpr implements Expr, MaybePrimitiveExpr{ 362.6726 - final Class c; 362.6727 - 362.6728 - public MethodParamExpr(Class c){ 362.6729 - this.c = c; 362.6730 - } 362.6731 - 362.6732 - public Object eval() throws Exception{ 362.6733 - throw new Exception("Can't eval"); 362.6734 - } 362.6735 - 362.6736 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.6737 - throw new RuntimeException("Can't emit"); 362.6738 - } 362.6739 - 362.6740 - public boolean hasJavaClass() throws Exception{ 362.6741 - return c != null; 362.6742 - } 362.6743 - 362.6744 - public Class getJavaClass() throws Exception{ 362.6745 - return c; 362.6746 - } 362.6747 - 362.6748 - public boolean canEmitPrimitive(){ 362.6749 - return Util.isPrimitive(c); 362.6750 - } 362.6751 - 362.6752 - public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){ 362.6753 - throw new RuntimeException("Can't emit"); 362.6754 - } 362.6755 -} 362.6756 - 362.6757 -public static class CaseExpr extends UntypedExpr{ 362.6758 - public final LocalBindingExpr expr; 362.6759 - public final int shift, mask, low, high; 362.6760 - public final Expr defaultExpr; 362.6761 - public final HashMap<Integer,Expr> tests; 362.6762 - public final HashMap<Integer,Expr> thens; 362.6763 - public final boolean allKeywords; 362.6764 - 362.6765 - public final int line; 362.6766 - 362.6767 - final static Method hashMethod = Method.getMethod("int hash(Object)"); 362.6768 - final static Method hashCodeMethod = Method.getMethod("int hashCode()"); 362.6769 - final static Method equalsMethod = Method.getMethod("boolean equals(Object, Object)"); 362.6770 - 362.6771 - 362.6772 - public CaseExpr(int line, LocalBindingExpr expr, int shift, int mask, int low, int high, Expr defaultExpr, 362.6773 - HashMap<Integer,Expr> tests,HashMap<Integer,Expr> thens, boolean allKeywords){ 362.6774 - this.expr = expr; 362.6775 - this.shift = shift; 362.6776 - this.mask = mask; 362.6777 - this.low = low; 362.6778 - this.high = high; 362.6779 - this.defaultExpr = defaultExpr; 362.6780 - this.tests = tests; 362.6781 - this.thens = thens; 362.6782 - this.line = line; 362.6783 - this.allKeywords = allKeywords; 362.6784 - } 362.6785 - 362.6786 - public Object eval() throws Exception{ 362.6787 - throw new UnsupportedOperationException("Can't eval case"); 362.6788 - } 362.6789 - 362.6790 - public void emit(C context, ObjExpr objx, GeneratorAdapter gen){ 362.6791 - Label defaultLabel = gen.newLabel(); 362.6792 - Label endLabel = gen.newLabel(); 362.6793 - HashMap<Integer,Label> labels = new HashMap(); 362.6794 - 362.6795 - for(Integer i : tests.keySet()) 362.6796 - { 362.6797 - labels.put(i, gen.newLabel()); 362.6798 - } 362.6799 - 362.6800 - Label[] la = new Label[(high-low)+1]; 362.6801 - 362.6802 - for(int i=low;i<=high;i++) 362.6803 - { 362.6804 - la[i-low] = labels.containsKey(i) ? labels.get(i) : defaultLabel; 362.6805 - } 362.6806 - 362.6807 - gen.visitLineNumber(line, gen.mark()); 362.6808 - expr.emit(C.EXPRESSION, objx, gen); 362.6809 - gen.invokeStatic(UTIL_TYPE,hashMethod); 362.6810 - gen.push(shift); 362.6811 - gen.visitInsn(ISHR); 362.6812 - gen.push(mask); 362.6813 - gen.visitInsn(IAND); 362.6814 - gen.visitTableSwitchInsn(low, high, defaultLabel, la); 362.6815 - 362.6816 - for(Integer i : labels.keySet()) 362.6817 - { 362.6818 - gen.mark(labels.get(i)); 362.6819 - expr.emit(C.EXPRESSION, objx, gen); 362.6820 - tests.get(i).emit(C.EXPRESSION, objx, gen); 362.6821 - if(allKeywords) 362.6822 - { 362.6823 - gen.visitJumpInsn(IF_ACMPNE, defaultLabel); 362.6824 - } 362.6825 - else 362.6826 - { 362.6827 - gen.invokeStatic(UTIL_TYPE, equalsMethod); 362.6828 - gen.ifZCmp(GeneratorAdapter.EQ, defaultLabel); 362.6829 - } 362.6830 - thens.get(i).emit(C.EXPRESSION,objx,gen); 362.6831 - gen.goTo(endLabel); 362.6832 - } 362.6833 - 362.6834 - gen.mark(defaultLabel); 362.6835 - defaultExpr.emit(C.EXPRESSION, objx, gen); 362.6836 - gen.mark(endLabel); 362.6837 - if(context == C.STATEMENT) 362.6838 - gen.pop(); 362.6839 - } 362.6840 - 362.6841 - static class Parser implements IParser{ 362.6842 - //(case* expr shift mask low high default map<minhash, [test then]> identity?) 362.6843 - //prepared by case macro and presumed correct 362.6844 - //case macro binds actual expr in let so expr is always a local, 362.6845 - //no need to worry about multiple evaluation 362.6846 - public Expr parse(C context, Object frm) throws Exception{ 362.6847 - ISeq form = (ISeq) frm; 362.6848 - if(context == C.EVAL) 362.6849 - return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form))); 362.6850 - PersistentVector args = PersistentVector.create(form.next()); 362.6851 - HashMap<Integer,Expr> tests = new HashMap(); 362.6852 - HashMap<Integer,Expr> thens = new HashMap(); 362.6853 - 362.6854 - LocalBindingExpr testexpr = (LocalBindingExpr) analyze(C.EXPRESSION, args.nth(0)); 362.6855 - testexpr.shouldClear = false; 362.6856 - 362.6857 - PathNode branch = new PathNode(PATHTYPE.BRANCH, (PathNode) CLEAR_PATH.get()); 362.6858 - for(Object o : ((Map)args.nth(6)).entrySet()) 362.6859 - { 362.6860 - Map.Entry e = (Map.Entry) o; 362.6861 - Integer minhash = (Integer) e.getKey(); 362.6862 - MapEntry me = (MapEntry) e.getValue(); 362.6863 - Expr testExpr = new ConstantExpr(me.getKey()); 362.6864 - tests.put(minhash, testExpr); 362.6865 - Expr thenExpr; 362.6866 - try { 362.6867 - Var.pushThreadBindings( 362.6868 - RT.map(CLEAR_PATH, new PathNode(PATHTYPE.PATH,branch))); 362.6869 - thenExpr = analyze(context, me.getValue()); 362.6870 - } 362.6871 - finally{ 362.6872 - Var.popThreadBindings(); 362.6873 - } 362.6874 - thens.put(minhash, thenExpr); 362.6875 - } 362.6876 - 362.6877 - Expr defaultExpr; 362.6878 - try { 362.6879 - Var.pushThreadBindings( 362.6880 - RT.map(CLEAR_PATH, new PathNode(PATHTYPE.PATH,branch))); 362.6881 - defaultExpr = analyze(context, args.nth(5)); 362.6882 - } 362.6883 - finally{ 362.6884 - Var.popThreadBindings(); 362.6885 - } 362.6886 - 362.6887 - return new CaseExpr((Integer) LINE.deref(), 362.6888 - testexpr, 362.6889 - (Integer)args.nth(1), 362.6890 - (Integer)args.nth(2), 362.6891 - (Integer)args.nth(3), 362.6892 - (Integer)args.nth(4), 362.6893 - defaultExpr, 362.6894 - tests,thens,args.nth(7) != RT.F); 362.6895 - 362.6896 - } 362.6897 - } 362.6898 -} 362.6899 - 362.6900 -}
363.1 --- a/src/clojure/lang/Cons.java Sat Aug 21 06:25:44 2010 -0400 363.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 363.3 @@ -1,55 +0,0 @@ 363.4 -/** 363.5 - * Copyright (c) Rich Hickey. All rights reserved. 363.6 - * The use and distribution terms for this software are covered by the 363.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 363.8 - * which can be found in the file epl-v10.html at the root of this distribution. 363.9 - * By using this software in any fashion, you are agreeing to be bound by 363.10 - * the terms of this license. 363.11 - * You must not remove this notice, or any other, from this software. 363.12 - **/ 363.13 - 363.14 -/* rich Mar 25, 2006 11:01:29 AM */ 363.15 - 363.16 -package clojure.lang; 363.17 - 363.18 -import java.io.Serializable; 363.19 - 363.20 -final public class Cons extends ASeq implements Serializable { 363.21 - 363.22 -private final Object _first; 363.23 -private final ISeq _more; 363.24 - 363.25 -public Cons(Object first, ISeq _more){ 363.26 - this._first = first; 363.27 - this._more = _more; 363.28 -} 363.29 - 363.30 - 363.31 -public Cons(IPersistentMap meta, Object _first, ISeq _more){ 363.32 - super(meta); 363.33 - this._first = _first; 363.34 - this._more = _more; 363.35 -} 363.36 - 363.37 -public Object first(){ 363.38 - return _first; 363.39 -} 363.40 - 363.41 -public ISeq next(){ 363.42 - return more().seq(); 363.43 -} 363.44 - 363.45 -public ISeq more(){ 363.46 - if(_more == null) 363.47 - return PersistentList.EMPTY; 363.48 - return _more; 363.49 -} 363.50 - 363.51 -public int count(){ 363.52 - return 1 + RT.count(_more); 363.53 -} 363.54 - 363.55 -public Cons withMeta(IPersistentMap meta){ 363.56 - return new Cons(meta, _first, _more); 363.57 -} 363.58 -}
364.1 --- a/src/clojure/lang/Counted.java Sat Aug 21 06:25:44 2010 -0400 364.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 364.3 @@ -1,18 +0,0 @@ 364.4 -package clojure.lang; 364.5 - 364.6 -/** 364.7 - * Copyright (c) Rich Hickey. All rights reserved. 364.8 - * The use and distribution terms for this software are covered by the 364.9 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 364.10 - * which can be found in the file epl-v10.html at the root of this distribution. 364.11 - * By using this software in any fashion, you are agreeing to be bound by 364.12 - * the terms of this license. 364.13 - * You must not remove this notice, or any other, from this software. 364.14 - */ 364.15 - 364.16 -/* A class that implements Counted promises that it is a collection 364.17 - * that implement a constant-time count() */ 364.18 - 364.19 -public interface Counted { 364.20 - int count(); 364.21 -}
365.1 --- a/src/clojure/lang/Delay.java Sat Aug 21 06:25:44 2010 -0400 365.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 365.3 @@ -1,38 +0,0 @@ 365.4 -/** 365.5 - * Copyright (c) Rich Hickey. All rights reserved. 365.6 - * The use and distribution terms for this software are covered by the 365.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 365.8 - * which can be found in the file epl-v10.html at the root of this distribution. 365.9 - * By using this software in any fashion, you are agreeing to be bound by 365.10 - * the terms of this license. 365.11 - * You must not remove this notice, or any other, from this software. 365.12 - **/ 365.13 - 365.14 -/* rich Jun 28, 2007 */ 365.15 - 365.16 -package clojure.lang; 365.17 - 365.18 -public class Delay implements IDeref{ 365.19 -Object val; 365.20 -IFn fn; 365.21 - 365.22 -public Delay(IFn fn){ 365.23 - this.fn = fn; 365.24 - this.val = null; 365.25 -} 365.26 - 365.27 -static public Object force(Object x) throws Exception{ 365.28 - return (x instanceof Delay) ? 365.29 - ((Delay) x).deref() 365.30 - : x; 365.31 -} 365.32 - 365.33 -synchronized public Object deref() throws Exception{ 365.34 - if(fn != null) 365.35 - { 365.36 - val = fn.invoke(); 365.37 - fn = null; 365.38 - } 365.39 - return val; 365.40 -} 365.41 -}
366.1 --- a/src/clojure/lang/DynamicClassLoader.java Sat Aug 21 06:25:44 2010 -0400 366.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 366.3 @@ -1,73 +0,0 @@ 366.4 -/** 366.5 - * Copyright (c) Rich Hickey. All rights reserved. 366.6 - * The use and distribution terms for this software are covered by the 366.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 366.8 - * which can be found in the file epl-v10.html at the root of this distribution. 366.9 - * By using this software in any fashion, you are agreeing to be bound by 366.10 - * the terms of this license. 366.11 - * You must not remove this notice, or any other, from this software. 366.12 - **/ 366.13 - 366.14 -/* rich Aug 21, 2007 */ 366.15 - 366.16 -package clojure.lang; 366.17 - 366.18 -import java.util.HashMap; 366.19 -import java.util.Map; 366.20 -import java.util.concurrent.ConcurrentHashMap; 366.21 -import java.net.URLClassLoader; 366.22 -import java.net.URL; 366.23 -import java.lang.ref.ReferenceQueue; 366.24 -import java.lang.ref.SoftReference; 366.25 - 366.26 -public class DynamicClassLoader extends URLClassLoader{ 366.27 -HashMap<Integer, Object[]> constantVals = new HashMap<Integer, Object[]>(); 366.28 -static ConcurrentHashMap<String, SoftReference<Class>>classCache = 366.29 - new ConcurrentHashMap<String, SoftReference<Class> >(); 366.30 - 366.31 -static final URL[] EMPTY_URLS = new URL[]{}; 366.32 - 366.33 -static final ReferenceQueue rq = new ReferenceQueue(); 366.34 - 366.35 -public DynamicClassLoader(){ 366.36 - //pseudo test in lieu of hasContextClassLoader() 366.37 - super(EMPTY_URLS,(Thread.currentThread().getContextClassLoader() == null || 366.38 - Thread.currentThread().getContextClassLoader() == ClassLoader.getSystemClassLoader())? 366.39 - Compiler.class.getClassLoader():Thread.currentThread().getContextClassLoader()); 366.40 -} 366.41 - 366.42 -public DynamicClassLoader(ClassLoader parent){ 366.43 - super(EMPTY_URLS,parent); 366.44 -} 366.45 - 366.46 -public Class defineClass(String name, byte[] bytes, Object srcForm){ 366.47 - Util.clearCache(rq, classCache); 366.48 - Class c = defineClass(name, bytes, 0, bytes.length); 366.49 - classCache.put(name, new SoftReference(c,rq)); 366.50 - return c; 366.51 -} 366.52 - 366.53 -protected Class<?> findClass(String name) throws ClassNotFoundException{ 366.54 - SoftReference<Class> cr = classCache.get(name); 366.55 - if(cr != null) 366.56 - { 366.57 - Class c = cr.get(); 366.58 - if(c != null) 366.59 - return c; 366.60 - } 366.61 - return super.findClass(name); 366.62 -} 366.63 - 366.64 -public void registerConstants(int id, Object[] val){ 366.65 - constantVals.put(id, val); 366.66 -} 366.67 - 366.68 -public Object[] getConstants(int id){ 366.69 - return constantVals.get(id); 366.70 -} 366.71 - 366.72 -public void addURL(URL url){ 366.73 - super.addURL(url); 366.74 -} 366.75 - 366.76 -}
367.1 --- a/src/clojure/lang/EnumerationSeq.java Sat Aug 21 06:25:44 2010 -0400 367.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 367.3 @@ -1,78 +0,0 @@ 367.4 -/** 367.5 - * Copyright (c) Rich Hickey. All rights reserved. 367.6 - * The use and distribution terms for this software are covered by the 367.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 367.8 - * which can be found in the file epl-v10.html at the root of this distribution. 367.9 - * By using this software in any fashion, you are agreeing to be bound by 367.10 - * the terms of this license. 367.11 - * You must not remove this notice, or any other, from this software. 367.12 - **/ 367.13 - 367.14 -/* rich Mar 3, 2008 */ 367.15 - 367.16 -package clojure.lang; 367.17 - 367.18 -import java.io.IOException; 367.19 -import java.io.NotSerializableException; 367.20 -import java.util.Enumeration; 367.21 - 367.22 -public class EnumerationSeq extends ASeq{ 367.23 -final Enumeration iter; 367.24 -final State state; 367.25 - 367.26 - static class State{ 367.27 - volatile Object val; 367.28 - volatile Object _rest; 367.29 -} 367.30 - 367.31 -public static EnumerationSeq create(Enumeration iter){ 367.32 - if(iter.hasMoreElements()) 367.33 - return new EnumerationSeq(iter); 367.34 - return null; 367.35 -} 367.36 - 367.37 -EnumerationSeq(Enumeration iter){ 367.38 - this.iter = iter; 367.39 - state = new State(); 367.40 - this.state.val = state; 367.41 - this.state._rest = state; 367.42 -} 367.43 - 367.44 -EnumerationSeq(IPersistentMap meta, Enumeration iter, State state){ 367.45 - super(meta); 367.46 - this.iter = iter; 367.47 - this.state = state; 367.48 -} 367.49 - 367.50 -public Object first(){ 367.51 - if(state.val == state) 367.52 - synchronized(state) 367.53 - { 367.54 - if(state.val == state) 367.55 - state.val = iter.nextElement(); 367.56 - } 367.57 - return state.val; 367.58 -} 367.59 - 367.60 -public ISeq next(){ 367.61 - if(state._rest == state) 367.62 - synchronized(state) 367.63 - { 367.64 - if(state._rest == state) 367.65 - { 367.66 - first(); 367.67 - state._rest = create(iter); 367.68 - } 367.69 - } 367.70 - return (ISeq) state._rest; 367.71 -} 367.72 - 367.73 -public EnumerationSeq withMeta(IPersistentMap meta){ 367.74 - return new EnumerationSeq(meta, iter, state); 367.75 -} 367.76 - 367.77 -private void writeObject (java.io.ObjectOutputStream out) throws IOException { 367.78 - throw new NotSerializableException(getClass().getName()); 367.79 -} 367.80 - 367.81 -}
368.1 --- a/src/clojure/lang/Fn.java Sat Aug 21 06:25:44 2010 -0400 368.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 368.3 @@ -1,16 +0,0 @@ 368.4 -/** 368.5 - * Copyright (c) Rich Hickey. All rights reserved. 368.6 - * The use and distribution terms for this software are covered by the 368.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 368.8 - * which can be found in the file epl-v10.html at the root of this distribution. 368.9 - * By using this software in any fashion, you are agreeing to be bound by 368.10 - * the terms of this license. 368.11 - * You must not remove this notice, or any other, from this software. 368.12 - **/ 368.13 - 368.14 -/* rich Nov 25, 2008 */ 368.15 - 368.16 -package clojure.lang; 368.17 - 368.18 -public interface Fn{ 368.19 -}
369.1 --- a/src/clojure/lang/IChunk.java Sat Aug 21 06:25:44 2010 -0400 369.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 369.3 @@ -1,20 +0,0 @@ 369.4 -/** 369.5 - * Copyright (c) Rich Hickey. All rights reserved. 369.6 - * The use and distribution terms for this software are covered by the 369.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 369.8 - * which can be found in the file epl-v10.html at the root of this distribution. 369.9 - * By using this software in any fashion, you are agreeing to be bound by 369.10 - * the terms of this license. 369.11 - * You must not remove this notice, or any other, from this software. 369.12 - **/ 369.13 - 369.14 -/* rich Jun 18, 2009 */ 369.15 - 369.16 -package clojure.lang; 369.17 - 369.18 -public interface IChunk extends Indexed{ 369.19 - 369.20 -IChunk dropFirst(); 369.21 - 369.22 -Object reduce(IFn f, Object start) throws Exception; 369.23 -}
370.1 --- a/src/clojure/lang/IChunkedSeq.java Sat Aug 21 06:25:44 2010 -0400 370.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 370.3 @@ -1,23 +0,0 @@ 370.4 -/** 370.5 - * Copyright (c) Rich Hickey. All rights reserved. 370.6 - * The use and distribution terms for this software are covered by the 370.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 370.8 - * which can be found in the file epl-v10.html at the root of this distribution. 370.9 - * By using this software in any fashion, you are agreeing to be bound by 370.10 - * the terms of this license. 370.11 - * You must not remove this notice, or any other, from this software. 370.12 - **/ 370.13 - 370.14 -/* rich May 24, 2009 */ 370.15 - 370.16 -package clojure.lang; 370.17 - 370.18 -public interface IChunkedSeq extends ISeq{ 370.19 - 370.20 -IChunk chunkedFirst() throws Exception; 370.21 - 370.22 -ISeq chunkedNext() throws Exception; 370.23 - 370.24 -ISeq chunkedMore() throws Exception; 370.25 - 370.26 -}
371.1 --- a/src/clojure/lang/IDeref.java Sat Aug 21 06:25:44 2010 -0400 371.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 371.3 @@ -1,17 +0,0 @@ 371.4 -/** 371.5 - * Copyright (c) Rich Hickey. All rights reserved. 371.6 - * The use and distribution terms for this software are covered by the 371.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 371.8 - * which can be found in the file epl-v10.html at the root of this distribution. 371.9 - * By using this software in any fashion, you are agreeing to be bound by 371.10 - * the terms of this license. 371.11 - * You must not remove this notice, or any other, from this software. 371.12 - **/ 371.13 - 371.14 -/* rich Feb 9, 2009 */ 371.15 - 371.16 -package clojure.lang; 371.17 - 371.18 -public interface IDeref{ 371.19 -Object deref() throws Exception; 371.20 -}
372.1 --- a/src/clojure/lang/IEditableCollection.java Sat Aug 21 06:25:44 2010 -0400 372.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 372.3 @@ -1,17 +0,0 @@ 372.4 -/** 372.5 - * Copyright (c) Rich Hickey. All rights reserved. 372.6 - * The use and distribution terms for this software are covered by the 372.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 372.8 - * which can be found in the file epl-v10.html at the root of this distribution. 372.9 - * By using this software in any fashion, you are agreeing to be bound by 372.10 - * the terms of this license. 372.11 - * You must not remove this notice, or any other, from this software. 372.12 - **/ 372.13 - 372.14 -/* rich Jul 17, 2009 */ 372.15 - 372.16 -package clojure.lang; 372.17 - 372.18 -public interface IEditableCollection{ 372.19 -ITransientCollection asTransient(); 372.20 -}
373.1 --- a/src/clojure/lang/IFn.java Sat Aug 21 06:25:44 2010 -0400 373.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 373.3 @@ -1,90 +0,0 @@ 373.4 -/** 373.5 - * Copyright (c) Rich Hickey. All rights reserved. 373.6 - * The use and distribution terms for this software are covered by the 373.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 373.8 - * which can be found in the file epl-v10.html at the root of this distribution. 373.9 - * By using this software in any fashion, you are agreeing to be bound by 373.10 - * the terms of this license. 373.11 - * You must not remove this notice, or any other, from this software. 373.12 - **/ 373.13 - 373.14 -/* rich Mar 25, 2006 3:54:03 PM */ 373.15 - 373.16 -package clojure.lang; 373.17 - 373.18 -import java.util.concurrent.Callable; 373.19 - 373.20 -public interface IFn extends Callable, Runnable{ 373.21 - 373.22 -public Object invoke() throws Exception; 373.23 - 373.24 -public Object invoke(Object arg1) throws Exception; 373.25 - 373.26 -public Object invoke(Object arg1, Object arg2) throws Exception; 373.27 - 373.28 -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception; 373.29 - 373.30 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception; 373.31 - 373.32 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception; 373.33 - 373.34 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception; 373.35 - 373.36 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) 373.37 - throws Exception; 373.38 - 373.39 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.40 - Object arg8) throws Exception; 373.41 - 373.42 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.43 - Object arg8, Object arg9) throws Exception; 373.44 - 373.45 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.46 - Object arg8, Object arg9, Object arg10) throws Exception; 373.47 - 373.48 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.49 - Object arg8, Object arg9, Object arg10, Object arg11) throws Exception; 373.50 - 373.51 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.52 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception; 373.53 - 373.54 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.55 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) throws Exception; 373.56 - 373.57 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.58 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) 373.59 - throws Exception; 373.60 - 373.61 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.62 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 373.63 - Object arg15) throws Exception; 373.64 - 373.65 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.66 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 373.67 - Object arg15, Object arg16) throws Exception; 373.68 - 373.69 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.70 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 373.71 - Object arg15, Object arg16, Object arg17) throws Exception; 373.72 - 373.73 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.74 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 373.75 - Object arg15, Object arg16, Object arg17, Object arg18) throws Exception; 373.76 - 373.77 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.78 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 373.79 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception; 373.80 - 373.81 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.82 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 373.83 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20) 373.84 - throws Exception; 373.85 - 373.86 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 373.87 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 373.88 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20, 373.89 - Object... args) 373.90 - throws Exception; 373.91 - 373.92 -public Object applyTo(ISeq arglist) throws Exception; 373.93 -}
374.1 --- a/src/clojure/lang/IKeywordLookup.java Sat Aug 21 06:25:44 2010 -0400 374.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 374.3 @@ -1,17 +0,0 @@ 374.4 -/** 374.5 - * Copyright (c) Rich Hickey. All rights reserved. 374.6 - * The use and distribution terms for this software are covered by the 374.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 374.8 - * which can be found in the file epl-v10.html at the root of this distribution. 374.9 - * By using this software in any fashion, you are agreeing to be bound by 374.10 - * the terms of this license. 374.11 - * You must not remove this notice, or any other, from this software. 374.12 - **/ 374.13 - 374.14 -/* rich Oct 31, 2009 */ 374.15 - 374.16 -package clojure.lang; 374.17 - 374.18 -public interface IKeywordLookup{ 374.19 -ILookupThunk getLookupThunk(Keyword k); 374.20 -}
375.1 --- a/src/clojure/lang/ILookup.java Sat Aug 21 06:25:44 2010 -0400 375.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 375.3 @@ -1,19 +0,0 @@ 375.4 -/** 375.5 - * Copyright (c) Rich Hickey. All rights reserved. 375.6 - * The use and distribution terms for this software are covered by the 375.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 375.8 - * which can be found in the file epl-v10.html at the root of this distribution. 375.9 - * By using this software in any fashion, you are agreeing to be bound by 375.10 - * the terms of this license. 375.11 - * You must not remove this notice, or any other, from this software. 375.12 - **/ 375.13 - 375.14 -/* rich Aug 2, 2009 */ 375.15 - 375.16 -package clojure.lang; 375.17 - 375.18 -public interface ILookup{ 375.19 -Object valAt(Object key); 375.20 - 375.21 -Object valAt(Object key, Object notFound); 375.22 -}
376.1 --- a/src/clojure/lang/ILookupHost.java Sat Aug 21 06:25:44 2010 -0400 376.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 376.3 @@ -1,19 +0,0 @@ 376.4 -/** 376.5 - * Copyright (c) Rich Hickey. All rights reserved. 376.6 - * The use and distribution terms for this software are covered by the 376.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 376.8 - * which can be found in the file epl-v10.html at the root of this distribution. 376.9 - * By using this software in any fashion, you are agreeing to be bound by 376.10 - * the terms of this license. 376.11 - * You must not remove this notice, or any other, from this software. 376.12 - **/ 376.13 - 376.14 -/* rich Nov 2, 2009 */ 376.15 - 376.16 -package clojure.lang; 376.17 - 376.18 -public interface ILookupHost{ 376.19 - 376.20 -void swapThunk(int n, ILookupThunk thunk); 376.21 - 376.22 -}
377.1 --- a/src/clojure/lang/ILookupSite.java Sat Aug 21 06:25:44 2010 -0400 377.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 377.3 @@ -1,19 +0,0 @@ 377.4 -/** 377.5 - * Copyright (c) Rich Hickey. All rights reserved. 377.6 - * The use and distribution terms for this software are covered by the 377.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 377.8 - * which can be found in the file epl-v10.html at the root of this distribution. 377.9 - * By using this software in any fashion, you are agreeing to be bound by 377.10 - * the terms of this license. 377.11 - * You must not remove this notice, or any other, from this software. 377.12 - **/ 377.13 - 377.14 -/* rich Nov 2, 2009 */ 377.15 - 377.16 -package clojure.lang; 377.17 - 377.18 -public interface ILookupSite{ 377.19 - 377.20 -Object fault(Object target, ILookupHost host); 377.21 - 377.22 -}
378.1 --- a/src/clojure/lang/ILookupThunk.java Sat Aug 21 06:25:44 2010 -0400 378.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 378.3 @@ -1,19 +0,0 @@ 378.4 -/** 378.5 - * Copyright (c) Rich Hickey. All rights reserved. 378.6 - * The use and distribution terms for this software are covered by the 378.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 378.8 - * which can be found in the file epl-v10.html at the root of this distribution. 378.9 - * By using this software in any fashion, you are agreeing to be bound by 378.10 - * the terms of this license. 378.11 - * You must not remove this notice, or any other, from this software. 378.12 - **/ 378.13 - 378.14 -/* rich Nov 2, 2009 */ 378.15 - 378.16 -package clojure.lang; 378.17 - 378.18 -public interface ILookupThunk{ 378.19 - 378.20 -Object get(Object target); 378.21 - 378.22 -}
379.1 --- a/src/clojure/lang/IMapEntry.java Sat Aug 21 06:25:44 2010 -0400 379.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 379.3 @@ -1,19 +0,0 @@ 379.4 -/** 379.5 - * Copyright (c) Rich Hickey. All rights reserved. 379.6 - * The use and distribution terms for this software are covered by the 379.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 379.8 - * which can be found in the file epl-v10.html at the root of this distribution. 379.9 - * By using this software in any fashion, you are agreeing to be bound by 379.10 - * the terms of this license. 379.11 - * You must not remove this notice, or any other, from this software. 379.12 - */ 379.13 - 379.14 -package clojure.lang; 379.15 - 379.16 -import java.util.Map; 379.17 - 379.18 -public interface IMapEntry extends Map.Entry{ 379.19 -Object key(); 379.20 - 379.21 -Object val(); 379.22 -}
380.1 --- a/src/clojure/lang/IMeta.java Sat Aug 21 06:25:44 2010 -0400 380.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 380.3 @@ -1,17 +0,0 @@ 380.4 -/** 380.5 - * Copyright (c) Rich Hickey. All rights reserved. 380.6 - * The use and distribution terms for this software are covered by the 380.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 380.8 - * which can be found in the file epl-v10.html at the root of this distribution. 380.9 - * By using this software in any fashion, you are agreeing to be bound by 380.10 - * the terms of this license. 380.11 - * You must not remove this notice, or any other, from this software. 380.12 - **/ 380.13 - 380.14 -/* rich Dec 31, 2008 */ 380.15 - 380.16 -package clojure.lang; 380.17 - 380.18 -public interface IMeta { 380.19 - IPersistentMap meta(); 380.20 -}
381.1 --- a/src/clojure/lang/IObj.java Sat Aug 21 06:25:44 2010 -0400 381.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 381.3 @@ -1,18 +0,0 @@ 381.4 -/** 381.5 - * Copyright (c) Rich Hickey. All rights reserved. 381.6 - * The use and distribution terms for this software are covered by the 381.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 381.8 - * which can be found in the file epl-v10.html at the root of this distribution. 381.9 - * By using this software in any fashion, you are agreeing to be bound by 381.10 - * the terms of this license. 381.11 - * You must not remove this notice, or any other, from this software. 381.12 - **/ 381.13 - 381.14 -package clojure.lang; 381.15 - 381.16 - 381.17 -public interface IObj extends IMeta { 381.18 - 381.19 - public IObj withMeta(IPersistentMap meta); 381.20 - 381.21 -}
382.1 --- a/src/clojure/lang/IPersistentCollection.java Sat Aug 21 06:25:44 2010 -0400 382.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 382.3 @@ -1,23 +0,0 @@ 382.4 -package clojure.lang; 382.5 - 382.6 -/** 382.7 - * Copyright (c) Rich Hickey. All rights reserved. 382.8 - * The use and distribution terms for this software are covered by the 382.9 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 382.10 - * which can be found in the file epl-v10.html at the root of this distribution. 382.11 - * By using this software in any fashion, you are agreeing to be bound by 382.12 - * the terms of this license. 382.13 - * You must not remove this notice, or any other, from this software. 382.14 - */ 382.15 - 382.16 - 382.17 -public interface IPersistentCollection extends Seqable { 382.18 - 382.19 -int count(); 382.20 - 382.21 -IPersistentCollection cons(Object o); 382.22 - 382.23 -IPersistentCollection empty(); 382.24 - 382.25 -boolean equiv(Object o); 382.26 -}
383.1 --- a/src/clojure/lang/IPersistentList.java Sat Aug 21 06:25:44 2010 -0400 383.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 383.3 @@ -1,16 +0,0 @@ 383.4 -/** 383.5 - * Copyright (c) Rich Hickey. All rights reserved. 383.6 - * The use and distribution terms for this software are covered by the 383.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 383.8 - * which can be found in the file epl-v10.html at the root of this distribution. 383.9 - * By using this software in any fashion, you are agreeing to be bound by 383.10 - * the terms of this license. 383.11 - * You must not remove this notice, or any other, from this software. 383.12 - */ 383.13 - 383.14 -package clojure.lang; 383.15 - 383.16 - 383.17 -public interface IPersistentList extends Sequential, IPersistentStack{ 383.18 - 383.19 -}
384.1 --- a/src/clojure/lang/IPersistentMap.java Sat Aug 21 06:25:44 2010 -0400 384.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 384.3 @@ -1,23 +0,0 @@ 384.4 -/** 384.5 - * Copyright (c) Rich Hickey. All rights reserved. 384.6 - * The use and distribution terms for this software are covered by the 384.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 384.8 - * which can be found in the file epl-v10.html at the root of this distribution. 384.9 - * By using this software in any fashion, you are agreeing to be bound by 384.10 - * the terms of this license. 384.11 - * You must not remove this notice, or any other, from this software. 384.12 - */ 384.13 - 384.14 -package clojure.lang; 384.15 - 384.16 - 384.17 -public interface IPersistentMap extends Iterable, Associative, Counted{ 384.18 - 384.19 - 384.20 -IPersistentMap assoc(Object key, Object val); 384.21 - 384.22 -IPersistentMap assocEx(Object key, Object val) throws Exception; 384.23 - 384.24 -IPersistentMap without(Object key) throws Exception; 384.25 - 384.26 -}
385.1 --- a/src/clojure/lang/IPersistentSet.java Sat Aug 21 06:25:44 2010 -0400 385.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 385.3 @@ -1,19 +0,0 @@ 385.4 -/** 385.5 - * Copyright (c) Rich Hickey. All rights reserved. 385.6 - * The use and distribution terms for this software are covered by the 385.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 385.8 - * which can be found in the file epl-v10.html at the root of this distribution. 385.9 - * By using this software in any fashion, you are agreeing to be bound by 385.10 - * the terms of this license. 385.11 - * You must not remove this notice, or any other, from this software. 385.12 - **/ 385.13 - 385.14 -/* rich Mar 3, 2008 */ 385.15 - 385.16 -package clojure.lang; 385.17 - 385.18 -public interface IPersistentSet extends IPersistentCollection, Counted{ 385.19 - public IPersistentSet disjoin(Object key) throws Exception; 385.20 - public boolean contains(Object key); 385.21 - public Object get(Object key); 385.22 -}
386.1 --- a/src/clojure/lang/IPersistentStack.java Sat Aug 21 06:25:44 2010 -0400 386.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 386.3 @@ -1,19 +0,0 @@ 386.4 -/** 386.5 - * Copyright (c) Rich Hickey. All rights reserved. 386.6 - * The use and distribution terms for this software are covered by the 386.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 386.8 - * which can be found in the file epl-v10.html at the root of this distribution. 386.9 - * By using this software in any fashion, you are agreeing to be bound by 386.10 - * the terms of this license. 386.11 - * You must not remove this notice, or any other, from this software. 386.12 - **/ 386.13 - 386.14 -/* rich Sep 19, 2007 */ 386.15 - 386.16 -package clojure.lang; 386.17 - 386.18 -public interface IPersistentStack extends IPersistentCollection{ 386.19 -Object peek(); 386.20 - 386.21 -IPersistentStack pop(); 386.22 -}
387.1 --- a/src/clojure/lang/IPersistentVector.java Sat Aug 21 06:25:44 2010 -0400 387.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 387.3 @@ -1,20 +0,0 @@ 387.4 -package clojure.lang; 387.5 - 387.6 -/** 387.7 - * Copyright (c) Rich Hickey. All rights reserved. 387.8 - * The use and distribution terms for this software are covered by the 387.9 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 387.10 - * which can be found in the file epl-v10.html at the root of this distribution. 387.11 - * By using this software in any fashion, you are agreeing to be bound by 387.12 - * the terms of this license. 387.13 - * You must not remove this notice, or any other, from this software. 387.14 - */ 387.15 - 387.16 -public interface IPersistentVector extends Associative, Sequential, IPersistentStack, Reversible, Indexed{ 387.17 -int length(); 387.18 - 387.19 -IPersistentVector assocN(int i, Object val); 387.20 - 387.21 -IPersistentVector cons(Object o); 387.22 - 387.23 -}
388.1 --- a/src/clojure/lang/IProxy.java Sat Aug 21 06:25:44 2010 -0400 388.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 388.3 @@ -1,21 +0,0 @@ 388.4 -/** 388.5 - * Copyright (c) Rich Hickey. All rights reserved. 388.6 - * The use and distribution terms for this software are covered by the 388.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 388.8 - * which can be found in the file epl-v10.html at the root of this distribution. 388.9 - * By using this software in any fashion, you are agreeing to be bound by 388.10 - * the terms of this license. 388.11 - * You must not remove this notice, or any other, from this software. 388.12 - **/ 388.13 - 388.14 -/* rich Feb 27, 2008 */ 388.15 - 388.16 -package clojure.lang; 388.17 - 388.18 -public interface IProxy{ 388.19 - 388.20 - public void __initClojureFnMappings(IPersistentMap m); 388.21 - public void __updateClojureFnMappings(IPersistentMap m); 388.22 - public IPersistentMap __getClojureFnMappings(); 388.23 - 388.24 -}
389.1 --- a/src/clojure/lang/IReduce.java Sat Aug 21 06:25:44 2010 -0400 389.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 389.3 @@ -1,19 +0,0 @@ 389.4 -/** 389.5 - * Copyright (c) Rich Hickey. All rights reserved. 389.6 - * The use and distribution terms for this software are covered by the 389.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 389.8 - * which can be found in the file epl-v10.html at the root of this distribution. 389.9 - * By using this software in any fashion, you are agreeing to be bound by 389.10 - * the terms of this license. 389.11 - * You must not remove this notice, or any other, from this software. 389.12 - **/ 389.13 - 389.14 -/* rich Jun 11, 2008 */ 389.15 - 389.16 -package clojure.lang; 389.17 - 389.18 -public interface IReduce{ 389.19 -Object reduce(IFn f) throws Exception; 389.20 - 389.21 -Object reduce(IFn f, Object start) throws Exception; 389.22 -}
390.1 --- a/src/clojure/lang/IRef.java Sat Aug 21 06:25:44 2010 -0400 390.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 390.3 @@ -1,27 +0,0 @@ 390.4 -/** 390.5 - * Copyright (c) Rich Hickey. All rights reserved. 390.6 - * The use and distribution terms for this software are covered by the 390.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 390.8 - * which can be found in the file epl-v10.html at the root of this distribution. 390.9 - * By using this software in any fashion, you are agreeing to be bound by 390.10 - * the terms of this license. 390.11 - * You must not remove this notice, or any other, from this software. 390.12 - **/ 390.13 - 390.14 -/* rich Nov 18, 2007 */ 390.15 - 390.16 -package clojure.lang; 390.17 - 390.18 -public interface IRef extends IDeref{ 390.19 - 390.20 - void setValidator(IFn vf); 390.21 - 390.22 - IFn getValidator(); 390.23 - 390.24 - IPersistentMap getWatches(); 390.25 - 390.26 - IRef addWatch(Object key, IFn callback); 390.27 - 390.28 - IRef removeWatch(Object key); 390.29 - 390.30 -}
391.1 --- a/src/clojure/lang/IReference.java Sat Aug 21 06:25:44 2010 -0400 391.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 391.3 @@ -1,18 +0,0 @@ 391.4 -/** 391.5 - * Copyright (c) Rich Hickey. All rights reserved. 391.6 - * The use and distribution terms for this software are covered by the 391.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 391.8 - * which can be found in the file epl-v10.html at the root of this distribution. 391.9 - * By using this software in any fashion, you are agreeing to be bound by 391.10 - * the terms of this license. 391.11 - * You must not remove this notice, or any other, from this software. 391.12 - **/ 391.13 - 391.14 -/* rich Dec 31, 2008 */ 391.15 - 391.16 -package clojure.lang; 391.17 - 391.18 -public interface IReference extends IMeta { 391.19 - IPersistentMap alterMeta(IFn alter, ISeq args) throws Exception; 391.20 - IPersistentMap resetMeta(IPersistentMap m); 391.21 -}
392.1 --- a/src/clojure/lang/ISeq.java Sat Aug 21 06:25:44 2010 -0400 392.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 392.3 @@ -1,29 +0,0 @@ 392.4 -/** 392.5 - * Copyright (c) Rich Hickey. All rights reserved. 392.6 - * The use and distribution terms for this software are covered by the 392.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 392.8 - * which can be found in the file epl-v10.html at the root of this distribution. 392.9 - * By using this software in any fashion, you are agreeing to be bound by 392.10 - * the terms of this license. 392.11 - * You must not remove this notice, or any other, from this software. 392.12 - */ 392.13 - 392.14 -package clojure.lang; 392.15 - 392.16 -/** 392.17 - * A persistent, functional, sequence interface 392.18 - * <p/> 392.19 - * ISeqs are immutable values, i.e. neither first(), nor rest() changes 392.20 - * or invalidates the ISeq 392.21 - */ 392.22 -public interface ISeq extends IPersistentCollection, Sequential{ 392.23 - 392.24 -Object first(); 392.25 - 392.26 -ISeq next(); 392.27 - 392.28 -ISeq more(); 392.29 - 392.30 -ISeq cons(Object o); 392.31 - 392.32 -}
393.1 --- a/src/clojure/lang/ITransientAssociative.java Sat Aug 21 06:25:44 2010 -0400 393.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 393.3 @@ -1,18 +0,0 @@ 393.4 -/** 393.5 - * Copyright (c) Rich Hickey. All rights reserved. 393.6 - * The use and distribution terms for this software are covered by the 393.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 393.8 - * which can be found in the file epl-v10.html at the root of this distribution. 393.9 - * By using this software in any fashion, you are agreeing to be bound by 393.10 - * the terms of this license. 393.11 - * You must not remove this notice, or any other, from this software. 393.12 - **/ 393.13 - 393.14 -/* rich Jul 17, 2009 */ 393.15 - 393.16 -package clojure.lang; 393.17 - 393.18 -public interface ITransientAssociative extends ITransientCollection, ILookup{ 393.19 - 393.20 -ITransientAssociative assoc(Object key, Object val); 393.21 -}
394.1 --- a/src/clojure/lang/ITransientCollection.java Sat Aug 21 06:25:44 2010 -0400 394.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 394.3 @@ -1,20 +0,0 @@ 394.4 -/** 394.5 - * Copyright (c) Rich Hickey. All rights reserved. 394.6 - * The use and distribution terms for this software are covered by the 394.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 394.8 - * which can be found in the file epl-v10.html at the root of this distribution. 394.9 - * By using this software in any fashion, you are agreeing to be bound by 394.10 - * the terms of this license. 394.11 - * You must not remove this notice, or any other, from this software. 394.12 - **/ 394.13 - 394.14 -/* rich Jul 17, 2009 */ 394.15 - 394.16 -package clojure.lang; 394.17 - 394.18 -public interface ITransientCollection{ 394.19 - 394.20 -ITransientCollection conj(Object val); 394.21 - 394.22 -IPersistentCollection persistent(); 394.23 -}
395.1 --- a/src/clojure/lang/ITransientMap.java Sat Aug 21 06:25:44 2010 -0400 395.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 395.3 @@ -1,22 +0,0 @@ 395.4 -/** 395.5 - * Copyright (c) Rich Hickey. All rights reserved. 395.6 - * The use and distribution terms for this software are covered by the 395.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 395.8 - * which can be found in the file epl-v10.html at the root of this distribution. 395.9 - * By using this software in any fashion, you are agreeing to be bound by 395.10 - * the terms of this license. 395.11 - * You must not remove this notice, or any other, from this software. 395.12 - **/ 395.13 - 395.14 -/* rich Jul 17, 2009 */ 395.15 - 395.16 -package clojure.lang; 395.17 - 395.18 -public interface ITransientMap extends ITransientAssociative, Counted{ 395.19 - 395.20 -ITransientMap assoc(Object key, Object val); 395.21 - 395.22 -ITransientMap without(Object key); 395.23 - 395.24 -IPersistentMap persistent(); 395.25 -}
396.1 --- a/src/clojure/lang/ITransientSet.java Sat Aug 21 06:25:44 2010 -0400 396.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 396.3 @@ -1,19 +0,0 @@ 396.4 -/** 396.5 - * Copyright (c) Rich Hickey. All rights reserved. 396.6 - * The use and distribution terms for this software are covered by the 396.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 396.8 - * which can be found in the file epl-v10.html at the root of this distribution. 396.9 - * By using this software in any fashion, you are agreeing to be bound by 396.10 - * the terms of this license. 396.11 - * You must not remove this notice, or any other, from this software. 396.12 - **/ 396.13 - 396.14 -/* rich Mar 3, 2008 */ 396.15 - 396.16 -package clojure.lang; 396.17 - 396.18 -public interface ITransientSet extends ITransientCollection, Counted{ 396.19 - public ITransientSet disjoin(Object key) throws Exception; 396.20 - public boolean contains(Object key); 396.21 - public Object get(Object key); 396.22 -}
397.1 --- a/src/clojure/lang/ITransientVector.java Sat Aug 21 06:25:44 2010 -0400 397.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 397.3 @@ -1,20 +0,0 @@ 397.4 -/** 397.5 - * Copyright (c) Rich Hickey. All rights reserved. 397.6 - * The use and distribution terms for this software are covered by the 397.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 397.8 - * which can be found in the file epl-v10.html at the root of this distribution. 397.9 - * By using this software in any fashion, you are agreeing to be bound by 397.10 - * the terms of this license. 397.11 - * You must not remove this notice, or any other, from this software. 397.12 - **/ 397.13 - 397.14 -/* rich Jul 17, 2009 */ 397.15 - 397.16 -package clojure.lang; 397.17 - 397.18 -public interface ITransientVector extends ITransientAssociative, Indexed{ 397.19 - 397.20 -ITransientVector assocN(int i, Object val); 397.21 - 397.22 -ITransientVector pop(); 397.23 -}
398.1 --- a/src/clojure/lang/Indexed.java Sat Aug 21 06:25:44 2010 -0400 398.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 398.3 @@ -1,19 +0,0 @@ 398.4 -/** 398.5 - * Copyright (c) Rich Hickey. All rights reserved. 398.6 - * The use and distribution terms for this software are covered by the 398.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 398.8 - * which can be found in the file epl-v10.html at the root of this distribution. 398.9 - * By using this software in any fashion, you are agreeing to be bound by 398.10 - * the terms of this license. 398.11 - * You must not remove this notice, or any other, from this software. 398.12 - **/ 398.13 - 398.14 -/* rich May 24, 2009 */ 398.15 - 398.16 -package clojure.lang; 398.17 - 398.18 -public interface Indexed extends Counted{ 398.19 -Object nth(int i); 398.20 - 398.21 -Object nth(int i, Object notFound); 398.22 -}
399.1 --- a/src/clojure/lang/IndexedSeq.java Sat Aug 21 06:25:44 2010 -0400 399.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 399.3 @@ -1,16 +0,0 @@ 399.4 -/** 399.5 - * Copyright (c) Rich Hickey. All rights reserved. 399.6 - * The use and distribution terms for this software are covered by the 399.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 399.8 - * which can be found in the file epl-v10.html at the root of this distribution. 399.9 - * By using this software in any fashion, you are agreeing to be bound by 399.10 - * the terms of this license. 399.11 - * You must not remove this notice, or any other, from this software. 399.12 - */ 399.13 - 399.14 -package clojure.lang; 399.15 - 399.16 -public interface IndexedSeq extends ISeq, Counted{ 399.17 - 399.18 -public int index(); 399.19 -}
400.1 --- a/src/clojure/lang/IteratorSeq.java Sat Aug 21 06:25:44 2010 -0400 400.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 400.3 @@ -1,75 +0,0 @@ 400.4 -/** 400.5 - * Copyright (c) Rich Hickey. All rights reserved. 400.6 - * The use and distribution terms for this software are covered by the 400.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 400.8 - * which can be found in the file epl-v10.html at the root of this distribution. 400.9 - * By using this software in any fashion, you are agreeing to be bound by 400.10 - * the terms of this license. 400.11 - * You must not remove this notice, or any other, from this software. 400.12 - **/ 400.13 - 400.14 -package clojure.lang; 400.15 - 400.16 -import java.io.IOException; 400.17 -import java.io.NotSerializableException; 400.18 -import java.util.Iterator; 400.19 - 400.20 -public class IteratorSeq extends ASeq{ 400.21 -final Iterator iter; 400.22 -final State state; 400.23 - 400.24 - static class State{ 400.25 - volatile Object val; 400.26 - volatile Object _rest; 400.27 -} 400.28 - 400.29 -public static IteratorSeq create(Iterator iter){ 400.30 - if(iter.hasNext()) 400.31 - return new IteratorSeq(iter); 400.32 - return null; 400.33 -} 400.34 - 400.35 -IteratorSeq(Iterator iter){ 400.36 - this.iter = iter; 400.37 - state = new State(); 400.38 - this.state.val = state; 400.39 - this.state._rest = state; 400.40 -} 400.41 - 400.42 -IteratorSeq(IPersistentMap meta, Iterator iter, State state){ 400.43 - super(meta); 400.44 - this.iter = iter; 400.45 - this.state = state; 400.46 -} 400.47 - 400.48 -public Object first(){ 400.49 - if(state.val == state) 400.50 - synchronized(state) 400.51 - { 400.52 - if(state.val == state) 400.53 - state.val = iter.next(); 400.54 - } 400.55 - return state.val; 400.56 -} 400.57 - 400.58 -public ISeq next(){ 400.59 - if(state._rest == state) 400.60 - synchronized(state) 400.61 - { 400.62 - if(state._rest == state) 400.63 - { 400.64 - first(); 400.65 - state._rest = create(iter); 400.66 - } 400.67 - } 400.68 - return (ISeq) state._rest; 400.69 -} 400.70 - 400.71 -public IteratorSeq withMeta(IPersistentMap meta){ 400.72 - return new IteratorSeq(meta, iter, state); 400.73 -} 400.74 - 400.75 -private void writeObject (java.io.ObjectOutputStream out) throws IOException { 400.76 - throw new NotSerializableException(getClass().getName()); 400.77 -} 400.78 -}
401.1 --- a/src/clojure/lang/Keyword.java Sat Aug 21 06:25:44 2010 -0400 401.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 401.3 @@ -1,225 +0,0 @@ 401.4 -/** 401.5 - * Copyright (c) Rich Hickey. All rights reserved. 401.6 - * The use and distribution terms for this software are covered by the 401.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 401.8 - * which can be found in the file epl-v10.html at the root of this distribution. 401.9 - * By using this software in any fashion, you are agreeing to be bound by 401.10 - * the terms of this license. 401.11 - * You must not remove this notice, or any other, from this software. 401.12 - **/ 401.13 - 401.14 -/* rich Mar 29, 2006 10:39:05 AM */ 401.15 - 401.16 -package clojure.lang; 401.17 - 401.18 -import java.io.ObjectStreamException; 401.19 -import java.io.Serializable; 401.20 -import java.util.concurrent.ConcurrentHashMap; 401.21 -import java.lang.ref.ReferenceQueue; 401.22 -import java.lang.ref.SoftReference; 401.23 - 401.24 - 401.25 -public final class Keyword implements IFn, Comparable, Named, Serializable { 401.26 - 401.27 -private static ConcurrentHashMap<Symbol, SoftReference<Keyword>> table = new ConcurrentHashMap(); 401.28 -static final ReferenceQueue rq = new ReferenceQueue(); 401.29 -public final Symbol sym; 401.30 -final int hash; 401.31 - 401.32 -public static Keyword intern(Symbol sym){ 401.33 - Util.clearCache(rq, table); 401.34 - Keyword k = new Keyword(sym); 401.35 - SoftReference<Keyword> existingRef = table.putIfAbsent(sym, new SoftReference<Keyword>(k,rq)); 401.36 - if(existingRef == null) 401.37 - return k; 401.38 - Keyword existingk = existingRef.get(); 401.39 - if(existingk != null) 401.40 - return existingk; 401.41 - //entry died in the interim, do over 401.42 - return intern(sym); 401.43 -} 401.44 - 401.45 -public static Keyword intern(String ns, String name){ 401.46 - return intern(Symbol.intern(ns, name)); 401.47 -} 401.48 - 401.49 -public static Keyword intern(String nsname){ 401.50 - return intern(Symbol.intern(nsname)); 401.51 -} 401.52 - 401.53 -private Keyword(Symbol sym){ 401.54 - this.sym = sym; 401.55 - hash = sym.hashCode() + 0x9e3779b9; 401.56 -} 401.57 - 401.58 -public final int hashCode(){ 401.59 - return hash; 401.60 -} 401.61 - 401.62 -public String toString(){ 401.63 - return ":" + sym; 401.64 -} 401.65 - 401.66 -public Object throwArity(){ 401.67 - throw new IllegalArgumentException("Wrong number of args passed to keyword: " 401.68 - + toString()); 401.69 -} 401.70 - 401.71 -public Object call() throws Exception{ 401.72 - return throwArity(); 401.73 -} 401.74 - 401.75 -public void run(){ 401.76 - throw new UnsupportedOperationException(); 401.77 -} 401.78 - 401.79 -public Object invoke() throws Exception{ 401.80 - return throwArity(); 401.81 -} 401.82 - 401.83 -public int compareTo(Object o){ 401.84 - return sym.compareTo(((Keyword) o).sym); 401.85 -} 401.86 - 401.87 - 401.88 -public String getNamespace(){ 401.89 - return sym.getNamespace(); 401.90 -} 401.91 - 401.92 -public String getName(){ 401.93 - return sym.getName(); 401.94 -} 401.95 - 401.96 -private Object readResolve() throws ObjectStreamException{ 401.97 - return intern(sym); 401.98 -} 401.99 - 401.100 -/** 401.101 - * Indexer implements IFn for attr access 401.102 - * 401.103 - * @param obj - must be IPersistentMap 401.104 - * @return the value at the key or nil if not found 401.105 - * @throws Exception 401.106 - */ 401.107 -final public Object invoke(Object obj) throws Exception{ 401.108 - if(obj instanceof ILookup) 401.109 - return ((ILookup)obj).valAt(this); 401.110 - return RT.get(obj, this); 401.111 -} 401.112 - 401.113 -final public Object invoke(Object obj, Object notFound) throws Exception{ 401.114 - if(obj instanceof ILookup) 401.115 - return ((ILookup)obj).valAt(this,notFound); 401.116 - return RT.get(obj, this, notFound); 401.117 -} 401.118 - 401.119 -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception{ 401.120 - return throwArity(); 401.121 -} 401.122 - 401.123 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception{ 401.124 - return throwArity(); 401.125 -} 401.126 - 401.127 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception{ 401.128 - return throwArity(); 401.129 -} 401.130 - 401.131 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception{ 401.132 - return throwArity(); 401.133 -} 401.134 - 401.135 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) 401.136 - throws Exception{ 401.137 - return throwArity(); 401.138 -} 401.139 - 401.140 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.141 - Object arg8) throws Exception{ 401.142 - return throwArity(); 401.143 -} 401.144 - 401.145 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.146 - Object arg8, Object arg9) throws Exception{ 401.147 - return throwArity(); 401.148 -} 401.149 - 401.150 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.151 - Object arg8, Object arg9, Object arg10) throws Exception{ 401.152 - return throwArity(); 401.153 -} 401.154 - 401.155 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.156 - Object arg8, Object arg9, Object arg10, Object arg11) throws Exception{ 401.157 - return throwArity(); 401.158 -} 401.159 - 401.160 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.161 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception{ 401.162 - return throwArity(); 401.163 -} 401.164 - 401.165 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.166 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) 401.167 - throws Exception{ 401.168 - return throwArity(); 401.169 -} 401.170 - 401.171 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.172 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) 401.173 - throws Exception{ 401.174 - return throwArity(); 401.175 -} 401.176 - 401.177 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.178 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 401.179 - Object arg15) throws Exception{ 401.180 - return throwArity(); 401.181 -} 401.182 - 401.183 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.184 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 401.185 - Object arg15, Object arg16) throws Exception{ 401.186 - return throwArity(); 401.187 -} 401.188 - 401.189 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.190 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 401.191 - Object arg15, Object arg16, Object arg17) throws Exception{ 401.192 - return throwArity(); 401.193 -} 401.194 - 401.195 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.196 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 401.197 - Object arg15, Object arg16, Object arg17, Object arg18) throws Exception{ 401.198 - return throwArity(); 401.199 -} 401.200 - 401.201 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.202 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 401.203 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception{ 401.204 - return throwArity(); 401.205 -} 401.206 - 401.207 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.208 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 401.209 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20) 401.210 - throws Exception{ 401.211 - return throwArity(); 401.212 -} 401.213 - 401.214 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 401.215 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 401.216 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20, 401.217 - Object... args) 401.218 - throws Exception{ 401.219 - return throwArity(); 401.220 -} 401.221 - 401.222 - 401.223 -public Object applyTo(ISeq arglist) throws Exception{ 401.224 - return AFn.applyToHelper(this, arglist); 401.225 -} 401.226 - 401.227 - 401.228 -}
402.1 --- a/src/clojure/lang/KeywordLookupSite.java Sat Aug 21 06:25:44 2010 -0400 402.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 402.3 @@ -1,65 +0,0 @@ 402.4 -/** 402.5 - * Copyright (c) Rich Hickey. All rights reserved. 402.6 - * The use and distribution terms for this software are covered by the 402.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 402.8 - * which can be found in the file epl-v10.html at the root of this distribution. 402.9 - * By using this software in any fashion, you are agreeing to be bound by 402.10 - * the terms of this license. 402.11 - * You must not remove this notice, or any other, from this software. 402.12 - **/ 402.13 - 402.14 -/* rich Nov 2, 2009 */ 402.15 - 402.16 -package clojure.lang; 402.17 - 402.18 -public final class KeywordLookupSite implements ILookupSite, ILookupThunk{ 402.19 - 402.20 -final int n; 402.21 -final Keyword k; 402.22 - 402.23 -public KeywordLookupSite(int n, Keyword k){ 402.24 - this.n = n; 402.25 - this.k = k; 402.26 -} 402.27 - 402.28 -public Object fault(Object target, ILookupHost host){ 402.29 - if(target instanceof IKeywordLookup) 402.30 - { 402.31 - return install(target, host); 402.32 - } 402.33 - else if(target instanceof ILookup) 402.34 - { 402.35 - host.swapThunk(n,ilookupThunk(target.getClass())); 402.36 - return ((ILookup) target).valAt(k); 402.37 - } 402.38 - host.swapThunk(n,this); 402.39 - return RT.get(target, k); 402.40 -} 402.41 - 402.42 -public Object get(Object target){ 402.43 - if(target instanceof IKeywordLookup || target instanceof ILookup) 402.44 - return this; 402.45 - return RT.get(target,k); 402.46 -} 402.47 - 402.48 -private ILookupThunk ilookupThunk(final Class c){ 402.49 - return new ILookupThunk(){ 402.50 - public Object get(Object target){ 402.51 - if(target != null && target.getClass() == c) 402.52 - return ((ILookup) target).valAt(k); 402.53 - return this; 402.54 - } 402.55 - }; 402.56 -} 402.57 - 402.58 -private Object install(Object target, ILookupHost host){ 402.59 - ILookupThunk t = ((IKeywordLookup)target).getLookupThunk(k); 402.60 - if(t != null) 402.61 - { 402.62 - host.swapThunk(n,t); 402.63 - return t.get(target); 402.64 - } 402.65 - host.swapThunk(n,ilookupThunk(target.getClass())); 402.66 - return ((ILookup) target).valAt(k); 402.67 -} 402.68 -}
403.1 --- a/src/clojure/lang/LazilyPersistentVector.java Sat Aug 21 06:25:44 2010 -0400 403.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 403.3 @@ -1,34 +0,0 @@ 403.4 -/** 403.5 - * Copyright (c) Rich Hickey. All rights reserved. 403.6 - * The use and distribution terms for this software are covered by the 403.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 403.8 - * which can be found in the file epl-v10.html at the root of this distribution. 403.9 - * By using this software in any fashion, you are agreeing to be bound by 403.10 - * the terms of this license. 403.11 - * You must not remove this notice, or any other, from this software. 403.12 - **/ 403.13 - 403.14 -/* rich May 14, 2008 */ 403.15 - 403.16 -package clojure.lang; 403.17 - 403.18 -import java.util.Collection; 403.19 - 403.20 -public class LazilyPersistentVector{ 403.21 - 403.22 - 403.23 -static public IPersistentVector createOwning(Object... items){ 403.24 - if(items.length == 0) 403.25 - return PersistentVector.EMPTY; 403.26 - else if(items.length <= 32) 403.27 - return new PersistentVector(items.length, 5, PersistentVector.EMPTY_NODE,items); 403.28 - return PersistentVector.create(items); 403.29 -} 403.30 - 403.31 -static public IPersistentVector create(Collection coll){ 403.32 - if(!(coll instanceof ISeq) && coll.size() <= 32) 403.33 - return createOwning(coll.toArray()); 403.34 - return PersistentVector.create(RT.seq(coll)); 403.35 -} 403.36 - 403.37 -}
404.1 --- a/src/clojure/lang/LazySeq.java Sat Aug 21 06:25:44 2010 -0400 404.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 404.3 @@ -1,251 +0,0 @@ 404.4 -/** 404.5 - * Copyright (c) Rich Hickey. All rights reserved. 404.6 - * The use and distribution terms for this software are covered by the 404.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 404.8 - * which can be found in the file epl-v10.html at the root of this distribution. 404.9 - * By using this software in any fashion, you are agreeing to be bound by 404.10 - * the terms of this license. 404.11 - * You must not remove this notice, or any other, from this software. 404.12 - **/ 404.13 - 404.14 -/* rich Jan 31, 2009 */ 404.15 - 404.16 -package clojure.lang; 404.17 - 404.18 -import java.util.*; 404.19 - 404.20 -public final class LazySeq extends Obj implements ISeq, List{ 404.21 - 404.22 -private IFn fn; 404.23 -private Object sv; 404.24 -private ISeq s; 404.25 - 404.26 -public LazySeq(IFn fn){ 404.27 - this.fn = fn; 404.28 -} 404.29 - 404.30 -private LazySeq(IPersistentMap meta, ISeq s){ 404.31 - super(meta); 404.32 - this.fn = null; 404.33 - this.s = s; 404.34 -} 404.35 - 404.36 -public Obj withMeta(IPersistentMap meta){ 404.37 - return new LazySeq(meta, seq()); 404.38 -} 404.39 - 404.40 -final synchronized Object sval(){ 404.41 - if(fn != null) 404.42 - { 404.43 - try 404.44 - { 404.45 - sv = fn.invoke(); 404.46 - fn = null; 404.47 - } 404.48 - catch(Exception e) 404.49 - { 404.50 - throw new RuntimeException(e); 404.51 - } 404.52 - } 404.53 - if(sv != null) 404.54 - return sv; 404.55 - return s; 404.56 -} 404.57 - 404.58 -final synchronized public ISeq seq(){ 404.59 - sval(); 404.60 - if(sv != null) 404.61 - { 404.62 - Object ls = sv; 404.63 - sv = null; 404.64 - while(ls instanceof LazySeq) 404.65 - { 404.66 - ls = ((LazySeq)ls).sval(); 404.67 - } 404.68 - s = RT.seq(ls); 404.69 - } 404.70 - return s; 404.71 -} 404.72 - 404.73 -public int count(){ 404.74 - int c = 0; 404.75 - for(ISeq s = seq(); s != null; s = s.next()) 404.76 - ++c; 404.77 - return c; 404.78 -} 404.79 - 404.80 -public Object first(){ 404.81 - seq(); 404.82 - if(s == null) 404.83 - return null; 404.84 - return s.first(); 404.85 -} 404.86 - 404.87 -public ISeq next(){ 404.88 - seq(); 404.89 - if(s == null) 404.90 - return null; 404.91 - return s.next(); 404.92 -} 404.93 - 404.94 -public ISeq more(){ 404.95 - seq(); 404.96 - if(s == null) 404.97 - return PersistentList.EMPTY; 404.98 - return s.more(); 404.99 -} 404.100 - 404.101 -public ISeq cons(Object o){ 404.102 - return RT.cons(o, seq()); 404.103 -} 404.104 - 404.105 -public IPersistentCollection empty(){ 404.106 - return PersistentList.EMPTY; 404.107 -} 404.108 - 404.109 -public boolean equiv(Object o){ 404.110 - return equals(o); 404.111 -} 404.112 - 404.113 -public int hashCode(){ 404.114 - return Util.hash(seq()); 404.115 -} 404.116 - 404.117 -public boolean equals(Object o){ 404.118 - ISeq s = seq(); 404.119 - if(s != null) 404.120 - return s.equiv(o); 404.121 - else 404.122 - return (o instanceof Sequential || o instanceof List) && RT.seq(o) == null; 404.123 -} 404.124 - 404.125 - 404.126 -// java.util.Collection implementation 404.127 - 404.128 -public Object[] toArray(){ 404.129 - return RT.seqToArray(seq()); 404.130 -} 404.131 - 404.132 -public boolean add(Object o){ 404.133 - throw new UnsupportedOperationException(); 404.134 -} 404.135 - 404.136 -public boolean remove(Object o){ 404.137 - throw new UnsupportedOperationException(); 404.138 -} 404.139 - 404.140 -public boolean addAll(Collection c){ 404.141 - throw new UnsupportedOperationException(); 404.142 -} 404.143 - 404.144 -public void clear(){ 404.145 - throw new UnsupportedOperationException(); 404.146 -} 404.147 - 404.148 -public boolean retainAll(Collection c){ 404.149 - throw new UnsupportedOperationException(); 404.150 -} 404.151 - 404.152 -public boolean removeAll(Collection c){ 404.153 - throw new UnsupportedOperationException(); 404.154 -} 404.155 - 404.156 -public boolean containsAll(Collection c){ 404.157 - for(Object o : c) 404.158 - { 404.159 - if(!contains(o)) 404.160 - return false; 404.161 - } 404.162 - return true; 404.163 -} 404.164 - 404.165 -public Object[] toArray(Object[] a){ 404.166 - if(a.length >= count()) 404.167 - { 404.168 - ISeq s = seq(); 404.169 - for(int i = 0; s != null; ++i, s = s.next()) 404.170 - { 404.171 - a[i] = s.first(); 404.172 - } 404.173 - if(a.length > count()) 404.174 - a[count()] = null; 404.175 - return a; 404.176 - } 404.177 - else 404.178 - return toArray(); 404.179 -} 404.180 - 404.181 -public int size(){ 404.182 - return count(); 404.183 -} 404.184 - 404.185 -public boolean isEmpty(){ 404.186 - return seq() == null; 404.187 -} 404.188 - 404.189 -public boolean contains(Object o){ 404.190 - for(ISeq s = seq(); s != null; s = s.next()) 404.191 - { 404.192 - if(Util.equiv(s.first(), o)) 404.193 - return true; 404.194 - } 404.195 - return false; 404.196 -} 404.197 - 404.198 -public Iterator iterator(){ 404.199 - return new SeqIterator(seq()); 404.200 -} 404.201 - 404.202 -//////////// List stuff ///////////////// 404.203 -private List reify(){ 404.204 - return new ArrayList(this); 404.205 -} 404.206 - 404.207 -public List subList(int fromIndex, int toIndex){ 404.208 - return reify().subList(fromIndex, toIndex); 404.209 -} 404.210 - 404.211 -public Object set(int index, Object element){ 404.212 - throw new UnsupportedOperationException(); 404.213 -} 404.214 - 404.215 -public Object remove(int index){ 404.216 - throw new UnsupportedOperationException(); 404.217 -} 404.218 - 404.219 -public int indexOf(Object o){ 404.220 - ISeq s = seq(); 404.221 - for(int i = 0; s != null; s = s.next(), i++) 404.222 - { 404.223 - if(Util.equiv(s.first(), o)) 404.224 - return i; 404.225 - } 404.226 - return -1; 404.227 -} 404.228 - 404.229 -public int lastIndexOf(Object o){ 404.230 - return reify().lastIndexOf(o); 404.231 -} 404.232 - 404.233 -public ListIterator listIterator(){ 404.234 - return reify().listIterator(); 404.235 -} 404.236 - 404.237 -public ListIterator listIterator(int index){ 404.238 - return reify().listIterator(index); 404.239 -} 404.240 - 404.241 -public Object get(int index){ 404.242 - return RT.nth(this, index); 404.243 -} 404.244 - 404.245 -public void add(int index, Object element){ 404.246 - throw new UnsupportedOperationException(); 404.247 -} 404.248 - 404.249 -public boolean addAll(int index, Collection c){ 404.250 - throw new UnsupportedOperationException(); 404.251 -} 404.252 - 404.253 - 404.254 -}
405.1 --- a/src/clojure/lang/LineNumberingPushbackReader.java Sat Aug 21 06:25:44 2010 -0400 405.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 405.3 @@ -1,75 +0,0 @@ 405.4 -/** 405.5 - * Copyright (c) Rich Hickey. All rights reserved. 405.6 - * The use and distribution terms for this software are covered by the 405.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 405.8 - * which can be found in the file epl-v10.html at the root of this distribution. 405.9 - * By using this software in any fashion, you are agreeing to be bound by 405.10 - * the terms of this license. 405.11 - * You must not remove this notice, or any other, from this software. 405.12 - */ 405.13 - 405.14 -package clojure.lang; 405.15 - 405.16 -import java.io.PushbackReader; 405.17 -import java.io.Reader; 405.18 -import java.io.LineNumberReader; 405.19 -import java.io.IOException; 405.20 - 405.21 - 405.22 -public class LineNumberingPushbackReader extends PushbackReader{ 405.23 - 405.24 -// This class is a PushbackReader that wraps a LineNumberReader. The code 405.25 -// here to handle line terminators only mentions '\n' because 405.26 -// LineNumberReader collapses all occurrences of CR, LF, and CRLF into a 405.27 -// single '\n'. 405.28 - 405.29 -private static final int newline = (int) '\n'; 405.30 - 405.31 -private boolean _atLineStart = true; 405.32 -private boolean _prev; 405.33 - 405.34 -public LineNumberingPushbackReader(Reader r){ 405.35 - super(new LineNumberReader(r)); 405.36 -} 405.37 - 405.38 -public int getLineNumber(){ 405.39 - return ((LineNumberReader) in).getLineNumber() + 1; 405.40 -} 405.41 - 405.42 -public int read() throws IOException{ 405.43 - int c = super.read(); 405.44 - _prev = _atLineStart; 405.45 - _atLineStart = (c == newline) || (c == -1); 405.46 - return c; 405.47 -} 405.48 - 405.49 -public void unread(int c) throws IOException{ 405.50 - super.unread(c); 405.51 - _atLineStart = _prev; 405.52 -} 405.53 - 405.54 -public String readLine() throws IOException{ 405.55 - int c = read(); 405.56 - String line; 405.57 - switch (c) { 405.58 - case -1: 405.59 - line = null; 405.60 - break; 405.61 - case newline: 405.62 - line = ""; 405.63 - break; 405.64 - default: 405.65 - String first = String.valueOf((char) c); 405.66 - String rest = ((LineNumberReader)in).readLine(); 405.67 - line = (rest == null) ? first : first + rest; 405.68 - _prev = false; 405.69 - _atLineStart = true; 405.70 - break; 405.71 - } 405.72 - return line; 405.73 -} 405.74 - 405.75 -public boolean atLineStart(){ 405.76 - return _atLineStart; 405.77 -} 405.78 -}
406.1 --- a/src/clojure/lang/LispReader.java Sat Aug 21 06:25:44 2010 -0400 406.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 406.3 @@ -1,1103 +0,0 @@ 406.4 -/** 406.5 - * Copyright (c) Rich Hickey. All rights reserved. 406.6 - * The use and distribution terms for this software are covered by the 406.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 406.8 - * which can be found in the file epl-v10.html at the root of this distribution. 406.9 - * By using this software in any fashion, you are agreeing to be bound by 406.10 - * the terms of this license. 406.11 - * You must not remove this notice, or any other, from this software. 406.12 - **/ 406.13 - 406.14 -package clojure.lang; 406.15 - 406.16 -import java.io.*; 406.17 -import java.util.regex.Pattern; 406.18 -import java.util.regex.Matcher; 406.19 -import java.util.ArrayList; 406.20 -import java.util.List; 406.21 -import java.util.Map; 406.22 -import java.math.BigInteger; 406.23 -import java.math.BigDecimal; 406.24 -import java.lang.*; 406.25 - 406.26 -public class LispReader{ 406.27 - 406.28 -static final Symbol QUOTE = Symbol.create("quote"); 406.29 -static final Symbol THE_VAR = Symbol.create("var"); 406.30 -//static Symbol SYNTAX_QUOTE = Symbol.create(null, "syntax-quote"); 406.31 -static Symbol UNQUOTE = Symbol.create("clojure.core", "unquote"); 406.32 -static Symbol UNQUOTE_SPLICING = Symbol.create("clojure.core", "unquote-splicing"); 406.33 -static Symbol CONCAT = Symbol.create("clojure.core", "concat"); 406.34 -static Symbol SEQ = Symbol.create("clojure.core", "seq"); 406.35 -static Symbol LIST = Symbol.create("clojure.core", "list"); 406.36 -static Symbol APPLY = Symbol.create("clojure.core", "apply"); 406.37 -static Symbol HASHMAP = Symbol.create("clojure.core", "hash-map"); 406.38 -static Symbol HASHSET = Symbol.create("clojure.core", "hash-set"); 406.39 -static Symbol VECTOR = Symbol.create("clojure.core", "vector"); 406.40 -static Symbol WITH_META = Symbol.create("clojure.core", "with-meta"); 406.41 -static Symbol META = Symbol.create("clojure.core", "meta"); 406.42 -static Symbol DEREF = Symbol.create("clojure.core", "deref"); 406.43 -//static Symbol DEREF_BANG = Symbol.create("clojure.core", "deref!"); 406.44 - 406.45 -static IFn[] macros = new IFn[256]; 406.46 -static IFn[] dispatchMacros = new IFn[256]; 406.47 -//static Pattern symbolPat = Pattern.compile("[:]?([\\D&&[^:/]][^:/]*/)?[\\D&&[^:/]][^:/]*"); 406.48 -static Pattern symbolPat = Pattern.compile("[:]?([\\D&&[^/]].*/)?([\\D&&[^/]][^/]*)"); 406.49 -//static Pattern varPat = Pattern.compile("([\\D&&[^:\\.]][^:\\.]*):([\\D&&[^:\\.]][^:\\.]*)"); 406.50 -//static Pattern intPat = Pattern.compile("[-+]?[0-9]+\\.?"); 406.51 -static Pattern intPat = 406.52 - Pattern.compile( 406.53 - "([-+]?)(?:(0)|([1-9][0-9]*)|0[xX]([0-9A-Fa-f]+)|0([0-7]+)|([1-9][0-9]?)[rR]([0-9A-Za-z]+)|0[0-9]+)"); 406.54 -static Pattern ratioPat = Pattern.compile("([-+]?[0-9]+)/([0-9]+)"); 406.55 -static Pattern floatPat = Pattern.compile("([-+]?[0-9]+(\\.[0-9]*)?([eE][-+]?[0-9]+)?)(M)?"); 406.56 -static final Symbol SLASH = Symbol.create("/"); 406.57 -static final Symbol CLOJURE_SLASH = Symbol.create("clojure.core","/"); 406.58 -//static Pattern accessorPat = Pattern.compile("\\.[a-zA-Z_]\\w*"); 406.59 -//static Pattern instanceMemberPat = Pattern.compile("\\.([a-zA-Z_][\\w\\.]*)\\.([a-zA-Z_]\\w*)"); 406.60 -//static Pattern staticMemberPat = Pattern.compile("([a-zA-Z_][\\w\\.]*)\\.([a-zA-Z_]\\w*)"); 406.61 -//static Pattern classNamePat = Pattern.compile("([a-zA-Z_][\\w\\.]*)\\."); 406.62 - 406.63 -//symbol->gensymbol 406.64 -static Var GENSYM_ENV = Var.create(null); 406.65 -//sorted-map num->gensymbol 406.66 -static Var ARG_ENV = Var.create(null); 406.67 - 406.68 - static 406.69 - { 406.70 - macros['"'] = new StringReader(); 406.71 - macros[';'] = new CommentReader(); 406.72 - macros['\''] = new WrappingReader(QUOTE); 406.73 - macros['@'] = new WrappingReader(DEREF);//new DerefReader(); 406.74 - macros['^'] = new MetaReader(); 406.75 - macros['`'] = new SyntaxQuoteReader(); 406.76 - macros['~'] = new UnquoteReader(); 406.77 - macros['('] = new ListReader(); 406.78 - macros[')'] = new UnmatchedDelimiterReader(); 406.79 - macros['['] = new VectorReader(); 406.80 - macros[']'] = new UnmatchedDelimiterReader(); 406.81 - macros['{'] = new MapReader(); 406.82 - macros['}'] = new UnmatchedDelimiterReader(); 406.83 -// macros['|'] = new ArgVectorReader(); 406.84 - macros['\\'] = new CharacterReader(); 406.85 - macros['%'] = new ArgReader(); 406.86 - macros['#'] = new DispatchReader(); 406.87 - 406.88 - 406.89 - dispatchMacros['^'] = new MetaReader(); 406.90 - dispatchMacros['\''] = new VarReader(); 406.91 - dispatchMacros['"'] = new RegexReader(); 406.92 - dispatchMacros['('] = new FnReader(); 406.93 - dispatchMacros['{'] = new SetReader(); 406.94 - dispatchMacros['='] = new EvalReader(); 406.95 - dispatchMacros['!'] = new CommentReader(); 406.96 - dispatchMacros['<'] = new UnreadableReader(); 406.97 - dispatchMacros['_'] = new DiscardReader(); 406.98 - } 406.99 - 406.100 -static boolean isWhitespace(int ch){ 406.101 - return Character.isWhitespace(ch) || ch == ','; 406.102 -} 406.103 - 406.104 -static void unread(PushbackReader r, int ch) throws IOException{ 406.105 - if(ch != -1) 406.106 - r.unread(ch); 406.107 -} 406.108 - 406.109 -public static class ReaderException extends Exception{ 406.110 - final int line; 406.111 - 406.112 - public ReaderException(int line, Throwable cause){ 406.113 - super(cause); 406.114 - this.line = line; 406.115 - } 406.116 -} 406.117 - 406.118 -static public Object read(PushbackReader r, boolean eofIsError, Object eofValue, boolean isRecursive) 406.119 - throws Exception{ 406.120 - 406.121 - try 406.122 - { 406.123 - for(; ;) 406.124 - { 406.125 - int ch = r.read(); 406.126 - 406.127 - while(isWhitespace(ch)) 406.128 - ch = r.read(); 406.129 - 406.130 - if(ch == -1) 406.131 - { 406.132 - if(eofIsError) 406.133 - throw new Exception("EOF while reading"); 406.134 - return eofValue; 406.135 - } 406.136 - 406.137 - if(Character.isDigit(ch)) 406.138 - { 406.139 - Object n = readNumber(r, (char) ch); 406.140 - if(RT.suppressRead()) 406.141 - return null; 406.142 - return n; 406.143 - } 406.144 - 406.145 - IFn macroFn = getMacro(ch); 406.146 - if(macroFn != null) 406.147 - { 406.148 - Object ret = macroFn.invoke(r, (char) ch); 406.149 - if(RT.suppressRead()) 406.150 - return null; 406.151 - //no op macros return the reader 406.152 - if(ret == r) 406.153 - continue; 406.154 - return ret; 406.155 - } 406.156 - 406.157 - if(ch == '+' || ch == '-') 406.158 - { 406.159 - int ch2 = r.read(); 406.160 - if(Character.isDigit(ch2)) 406.161 - { 406.162 - unread(r, ch2); 406.163 - Object n = readNumber(r, (char) ch); 406.164 - if(RT.suppressRead()) 406.165 - return null; 406.166 - return n; 406.167 - } 406.168 - unread(r, ch2); 406.169 - } 406.170 - 406.171 - String token = readToken(r, (char) ch); 406.172 - if(RT.suppressRead()) 406.173 - return null; 406.174 - return interpretToken(token); 406.175 - } 406.176 - } 406.177 - catch(Exception e) 406.178 - { 406.179 - if(isRecursive || !(r instanceof LineNumberingPushbackReader)) 406.180 - throw e; 406.181 - LineNumberingPushbackReader rdr = (LineNumberingPushbackReader) r; 406.182 - //throw new Exception(String.format("ReaderError:(%d,1) %s", rdr.getLineNumber(), e.getMessage()), e); 406.183 - throw new ReaderException(rdr.getLineNumber(), e); 406.184 - } 406.185 -} 406.186 - 406.187 -static private String readToken(PushbackReader r, char initch) throws Exception{ 406.188 - StringBuilder sb = new StringBuilder(); 406.189 - sb.append(initch); 406.190 - 406.191 - for(; ;) 406.192 - { 406.193 - int ch = r.read(); 406.194 - if(ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch)) 406.195 - { 406.196 - unread(r, ch); 406.197 - return sb.toString(); 406.198 - } 406.199 - sb.append((char) ch); 406.200 - } 406.201 -} 406.202 - 406.203 -static private Object readNumber(PushbackReader r, char initch) throws Exception{ 406.204 - StringBuilder sb = new StringBuilder(); 406.205 - sb.append(initch); 406.206 - 406.207 - for(; ;) 406.208 - { 406.209 - int ch = r.read(); 406.210 - if(ch == -1 || isWhitespace(ch) || isMacro(ch)) 406.211 - { 406.212 - unread(r, ch); 406.213 - break; 406.214 - } 406.215 - sb.append((char) ch); 406.216 - } 406.217 - 406.218 - String s = sb.toString(); 406.219 - Object n = matchNumber(s); 406.220 - if(n == null) 406.221 - throw new NumberFormatException("Invalid number: " + s); 406.222 - return n; 406.223 -} 406.224 - 406.225 -static private int readUnicodeChar(String token, int offset, int length, int base) throws Exception{ 406.226 - if(token.length() != offset + length) 406.227 - throw new IllegalArgumentException("Invalid unicode character: \\" + token); 406.228 - int uc = 0; 406.229 - for(int i = offset; i < offset + length; ++i) 406.230 - { 406.231 - int d = Character.digit(token.charAt(i), base); 406.232 - if(d == -1) 406.233 - throw new IllegalArgumentException("Invalid digit: " + (char) d); 406.234 - uc = uc * base + d; 406.235 - } 406.236 - return (char) uc; 406.237 -} 406.238 - 406.239 -static private int readUnicodeChar(PushbackReader r, int initch, int base, int length, boolean exact) throws Exception{ 406.240 - int uc = Character.digit(initch, base); 406.241 - if(uc == -1) 406.242 - throw new IllegalArgumentException("Invalid digit: " + initch); 406.243 - int i = 1; 406.244 - for(; i < length; ++i) 406.245 - { 406.246 - int ch = r.read(); 406.247 - if(ch == -1 || isWhitespace(ch) || isMacro(ch)) 406.248 - { 406.249 - unread(r, ch); 406.250 - break; 406.251 - } 406.252 - int d = Character.digit(ch, base); 406.253 - if(d == -1) 406.254 - throw new IllegalArgumentException("Invalid digit: " + (char) ch); 406.255 - uc = uc * base + d; 406.256 - } 406.257 - if(i != length && exact) 406.258 - throw new IllegalArgumentException("Invalid character length: " + i + ", should be: " + length); 406.259 - return uc; 406.260 -} 406.261 - 406.262 -static private Object interpretToken(String s) throws Exception{ 406.263 - if(s.equals("nil")) 406.264 - { 406.265 - return null; 406.266 - } 406.267 - else if(s.equals("true")) 406.268 - { 406.269 - return RT.T; 406.270 - } 406.271 - else if(s.equals("false")) 406.272 - { 406.273 - return RT.F; 406.274 - } 406.275 - else if(s.equals("/")) 406.276 - { 406.277 - return SLASH; 406.278 - } 406.279 - else if(s.equals("clojure.core//")) 406.280 - { 406.281 - return CLOJURE_SLASH; 406.282 - } 406.283 - Object ret = null; 406.284 - 406.285 - ret = matchSymbol(s); 406.286 - if(ret != null) 406.287 - return ret; 406.288 - 406.289 - throw new Exception("Invalid token: " + s); 406.290 -} 406.291 - 406.292 - 406.293 -private static Object matchSymbol(String s){ 406.294 - Matcher m = symbolPat.matcher(s); 406.295 - if(m.matches()) 406.296 - { 406.297 - int gc = m.groupCount(); 406.298 - String ns = m.group(1); 406.299 - String name = m.group(2); 406.300 - if(ns != null && ns.endsWith(":/") 406.301 - || name.endsWith(":") 406.302 - || s.indexOf("::", 1) != -1) 406.303 - return null; 406.304 - if(s.startsWith("::")) 406.305 - { 406.306 - Symbol ks = Symbol.intern(s.substring(2)); 406.307 - Namespace kns; 406.308 - if(ks.ns != null) 406.309 - kns = Compiler.namespaceFor(ks); 406.310 - else 406.311 - kns = Compiler.currentNS(); 406.312 - //auto-resolving keyword 406.313 - if (kns != null) 406.314 - return Keyword.intern(kns.name.name,ks.name); 406.315 - else 406.316 - return null; 406.317 - } 406.318 - boolean isKeyword = s.charAt(0) == ':'; 406.319 - Symbol sym = Symbol.intern(s.substring(isKeyword ? 1 : 0)); 406.320 - if(isKeyword) 406.321 - return Keyword.intern(sym); 406.322 - return sym; 406.323 - } 406.324 - return null; 406.325 -} 406.326 - 406.327 - 406.328 -private static Object matchNumber(String s){ 406.329 - Matcher m = intPat.matcher(s); 406.330 - if(m.matches()) 406.331 - { 406.332 - if(m.group(2) != null) 406.333 - return 0; 406.334 - boolean negate = (m.group(1).equals("-")); 406.335 - String n; 406.336 - int radix = 10; 406.337 - if((n = m.group(3)) != null) 406.338 - radix = 10; 406.339 - else if((n = m.group(4)) != null) 406.340 - radix = 16; 406.341 - else if((n = m.group(5)) != null) 406.342 - radix = 8; 406.343 - else if((n = m.group(7)) != null) 406.344 - radix = Integer.parseInt(m.group(6)); 406.345 - if(n == null) 406.346 - return null; 406.347 - BigInteger bn = new BigInteger(n, radix); 406.348 - return Numbers.reduce(negate ? bn.negate() : bn); 406.349 - } 406.350 - m = floatPat.matcher(s); 406.351 - if(m.matches()) 406.352 - { 406.353 - if(m.group(4) != null) 406.354 - return new BigDecimal(m.group(1)); 406.355 - return Double.parseDouble(s); 406.356 - } 406.357 - m = ratioPat.matcher(s); 406.358 - if(m.matches()) 406.359 - { 406.360 - return Numbers.divide(new BigInteger(m.group(1)), new BigInteger(m.group(2))); 406.361 - } 406.362 - return null; 406.363 -} 406.364 - 406.365 -static private IFn getMacro(int ch){ 406.366 - if(ch < macros.length) 406.367 - return macros[ch]; 406.368 - return null; 406.369 -} 406.370 - 406.371 -static private boolean isMacro(int ch){ 406.372 - return (ch < macros.length && macros[ch] != null); 406.373 -} 406.374 - 406.375 -static private boolean isTerminatingMacro(int ch){ 406.376 - return (ch != '#' && ch < macros.length && macros[ch] != null); 406.377 -} 406.378 - 406.379 -public static class RegexReader extends AFn{ 406.380 - static StringReader stringrdr = new StringReader(); 406.381 - 406.382 - public Object invoke(Object reader, Object doublequote) throws Exception{ 406.383 - StringBuilder sb = new StringBuilder(); 406.384 - Reader r = (Reader) reader; 406.385 - for(int ch = r.read(); ch != '"'; ch = r.read()) 406.386 - { 406.387 - if(ch == -1) 406.388 - throw new Exception("EOF while reading regex"); 406.389 - sb.append( (char) ch ); 406.390 - if(ch == '\\') //escape 406.391 - { 406.392 - ch = r.read(); 406.393 - if(ch == -1) 406.394 - throw new Exception("EOF while reading regex"); 406.395 - sb.append( (char) ch ) ; 406.396 - } 406.397 - } 406.398 - return Pattern.compile(sb.toString()); 406.399 - } 406.400 -} 406.401 - 406.402 -public static class StringReader extends AFn{ 406.403 - public Object invoke(Object reader, Object doublequote) throws Exception{ 406.404 - StringBuilder sb = new StringBuilder(); 406.405 - Reader r = (Reader) reader; 406.406 - 406.407 - for(int ch = r.read(); ch != '"'; ch = r.read()) 406.408 - { 406.409 - if(ch == -1) 406.410 - throw new Exception("EOF while reading string"); 406.411 - if(ch == '\\') //escape 406.412 - { 406.413 - ch = r.read(); 406.414 - if(ch == -1) 406.415 - throw new Exception("EOF while reading string"); 406.416 - switch(ch) 406.417 - { 406.418 - case 't': 406.419 - ch = '\t'; 406.420 - break; 406.421 - case 'r': 406.422 - ch = '\r'; 406.423 - break; 406.424 - case 'n': 406.425 - ch = '\n'; 406.426 - break; 406.427 - case '\\': 406.428 - break; 406.429 - case '"': 406.430 - break; 406.431 - case 'b': 406.432 - ch = '\b'; 406.433 - break; 406.434 - case 'f': 406.435 - ch = '\f'; 406.436 - break; 406.437 - case 'u': 406.438 - { 406.439 - ch = r.read(); 406.440 - if (Character.digit(ch, 16) == -1) 406.441 - throw new Exception("Invalid unicode escape: \\u" + (char) ch); 406.442 - ch = readUnicodeChar((PushbackReader) r, ch, 16, 4, true); 406.443 - break; 406.444 - } 406.445 - default: 406.446 - { 406.447 - if(Character.isDigit(ch)) 406.448 - { 406.449 - ch = readUnicodeChar((PushbackReader) r, ch, 8, 3, false); 406.450 - if(ch > 0377) 406.451 - throw new Exception("Octal escape sequence must be in range [0, 377]."); 406.452 - } 406.453 - else 406.454 - throw new Exception("Unsupported escape character: \\" + (char) ch); 406.455 - } 406.456 - } 406.457 - } 406.458 - sb.append((char) ch); 406.459 - } 406.460 - return sb.toString(); 406.461 - } 406.462 -} 406.463 - 406.464 -public static class CommentReader extends AFn{ 406.465 - public Object invoke(Object reader, Object semicolon) throws Exception{ 406.466 - Reader r = (Reader) reader; 406.467 - int ch; 406.468 - do 406.469 - { 406.470 - ch = r.read(); 406.471 - } while(ch != -1 && ch != '\n' && ch != '\r'); 406.472 - return r; 406.473 - } 406.474 - 406.475 -} 406.476 - 406.477 -public static class DiscardReader extends AFn{ 406.478 - public Object invoke(Object reader, Object underscore) throws Exception{ 406.479 - PushbackReader r = (PushbackReader) reader; 406.480 - read(r, true, null, true); 406.481 - return r; 406.482 - } 406.483 -} 406.484 - 406.485 -public static class WrappingReader extends AFn{ 406.486 - final Symbol sym; 406.487 - 406.488 - public WrappingReader(Symbol sym){ 406.489 - this.sym = sym; 406.490 - } 406.491 - 406.492 - public Object invoke(Object reader, Object quote) throws Exception{ 406.493 - PushbackReader r = (PushbackReader) reader; 406.494 - Object o = read(r, true, null, true); 406.495 - return RT.list(sym, o); 406.496 - } 406.497 - 406.498 -} 406.499 - 406.500 -public static class DeprecatedWrappingReader extends AFn{ 406.501 - final Symbol sym; 406.502 - final String macro; 406.503 - 406.504 - public DeprecatedWrappingReader(Symbol sym, String macro){ 406.505 - this.sym = sym; 406.506 - this.macro = macro; 406.507 - } 406.508 - 406.509 - public Object invoke(Object reader, Object quote) throws Exception{ 406.510 - System.out.println("WARNING: reader macro " + macro + 406.511 - " is deprecated; use " + sym.getName() + 406.512 - " instead"); 406.513 - PushbackReader r = (PushbackReader) reader; 406.514 - Object o = read(r, true, null, true); 406.515 - return RT.list(sym, o); 406.516 - } 406.517 - 406.518 -} 406.519 - 406.520 -public static class VarReader extends AFn{ 406.521 - public Object invoke(Object reader, Object quote) throws Exception{ 406.522 - PushbackReader r = (PushbackReader) reader; 406.523 - Object o = read(r, true, null, true); 406.524 -// if(o instanceof Symbol) 406.525 -// { 406.526 -// Object v = Compiler.maybeResolveIn(Compiler.currentNS(), (Symbol) o); 406.527 -// if(v instanceof Var) 406.528 -// return v; 406.529 -// } 406.530 - return RT.list(THE_VAR, o); 406.531 - } 406.532 -} 406.533 - 406.534 -/* 406.535 -static class DerefReader extends AFn{ 406.536 - 406.537 - public Object invoke(Object reader, Object quote) throws Exception{ 406.538 - PushbackReader r = (PushbackReader) reader; 406.539 - int ch = r.read(); 406.540 - if(ch == -1) 406.541 - throw new Exception("EOF while reading character"); 406.542 - if(ch == '!') 406.543 - { 406.544 - Object o = read(r, true, null, true); 406.545 - return RT.list(DEREF_BANG, o); 406.546 - } 406.547 - else 406.548 - { 406.549 - r.unread(ch); 406.550 - Object o = read(r, true, null, true); 406.551 - return RT.list(DEREF, o); 406.552 - } 406.553 - } 406.554 - 406.555 -} 406.556 -*/ 406.557 - 406.558 -public static class DispatchReader extends AFn{ 406.559 - public Object invoke(Object reader, Object hash) throws Exception{ 406.560 - int ch = ((Reader) reader).read(); 406.561 - if(ch == -1) 406.562 - throw new Exception("EOF while reading character"); 406.563 - IFn fn = dispatchMacros[ch]; 406.564 - if(fn == null) 406.565 - throw new Exception(String.format("No dispatch macro for: %c", (char) ch)); 406.566 - return fn.invoke(reader, ch); 406.567 - } 406.568 -} 406.569 - 406.570 -static Symbol garg(int n){ 406.571 - return Symbol.intern(null, (n == -1 ? "rest" : ("p" + n)) + "__" + RT.nextID() + "#"); 406.572 -} 406.573 - 406.574 -public static class FnReader extends AFn{ 406.575 - public Object invoke(Object reader, Object lparen) throws Exception{ 406.576 - PushbackReader r = (PushbackReader) reader; 406.577 - if(ARG_ENV.deref() != null) 406.578 - throw new IllegalStateException("Nested #()s are not allowed"); 406.579 - try 406.580 - { 406.581 - Var.pushThreadBindings( 406.582 - RT.map(ARG_ENV, PersistentTreeMap.EMPTY)); 406.583 - r.unread('('); 406.584 - Object form = read(r, true, null, true); 406.585 - 406.586 - PersistentVector args = PersistentVector.EMPTY; 406.587 - PersistentTreeMap argsyms = (PersistentTreeMap) ARG_ENV.deref(); 406.588 - ISeq rargs = argsyms.rseq(); 406.589 - if(rargs != null) 406.590 - { 406.591 - int higharg = (Integer) ((Map.Entry) rargs.first()).getKey(); 406.592 - if(higharg > 0) 406.593 - { 406.594 - for(int i = 1; i <= higharg; ++i) 406.595 - { 406.596 - Object sym = argsyms.valAt(i); 406.597 - if(sym == null) 406.598 - sym = garg(i); 406.599 - args = args.cons(sym); 406.600 - } 406.601 - } 406.602 - Object restsym = argsyms.valAt(-1); 406.603 - if(restsym != null) 406.604 - { 406.605 - args = args.cons(Compiler._AMP_); 406.606 - args = args.cons(restsym); 406.607 - } 406.608 - } 406.609 - return RT.list(Compiler.FN, args, form); 406.610 - } 406.611 - finally 406.612 - { 406.613 - Var.popThreadBindings(); 406.614 - } 406.615 - } 406.616 -} 406.617 - 406.618 -static Symbol registerArg(int n){ 406.619 - PersistentTreeMap argsyms = (PersistentTreeMap) ARG_ENV.deref(); 406.620 - if(argsyms == null) 406.621 - { 406.622 - throw new IllegalStateException("arg literal not in #()"); 406.623 - } 406.624 - Symbol ret = (Symbol) argsyms.valAt(n); 406.625 - if(ret == null) 406.626 - { 406.627 - ret = garg(n); 406.628 - ARG_ENV.set(argsyms.assoc(n, ret)); 406.629 - } 406.630 - return ret; 406.631 -} 406.632 - 406.633 -static class ArgReader extends AFn{ 406.634 - public Object invoke(Object reader, Object pct) throws Exception{ 406.635 - PushbackReader r = (PushbackReader) reader; 406.636 - if(ARG_ENV.deref() == null) 406.637 - { 406.638 - return interpretToken(readToken(r, '%')); 406.639 - } 406.640 - int ch = r.read(); 406.641 - unread(r, ch); 406.642 - //% alone is first arg 406.643 - if(ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch)) 406.644 - { 406.645 - return registerArg(1); 406.646 - } 406.647 - Object n = read(r, true, null, true); 406.648 - if(n.equals(Compiler._AMP_)) 406.649 - return registerArg(-1); 406.650 - if(!(n instanceof Number)) 406.651 - throw new IllegalStateException("arg literal must be %, %& or %integer"); 406.652 - return registerArg(((Number) n).intValue()); 406.653 - } 406.654 -} 406.655 - 406.656 -public static class MetaReader extends AFn{ 406.657 - public Object invoke(Object reader, Object caret) throws Exception{ 406.658 - PushbackReader r = (PushbackReader) reader; 406.659 - int line = -1; 406.660 - if(r instanceof LineNumberingPushbackReader) 406.661 - line = ((LineNumberingPushbackReader) r).getLineNumber(); 406.662 - Object meta = read(r, true, null, true); 406.663 - if(meta instanceof Symbol || meta instanceof Keyword || meta instanceof String) 406.664 - meta = RT.map(RT.TAG_KEY, meta); 406.665 - else if(!(meta instanceof IPersistentMap)) 406.666 - throw new IllegalArgumentException("Metadata must be Symbol,Keyword,String or Map"); 406.667 - 406.668 - Object o = read(r, true, null, true); 406.669 - if(o instanceof IMeta) 406.670 - { 406.671 - if(line != -1 && o instanceof ISeq) 406.672 - meta = ((IPersistentMap) meta).assoc(RT.LINE_KEY, line); 406.673 - if(o instanceof IReference) 406.674 - { 406.675 - ((IReference)o).resetMeta((IPersistentMap) meta); 406.676 - return o; 406.677 - } 406.678 - return ((IObj) o).withMeta((IPersistentMap) meta); 406.679 - } 406.680 - else 406.681 - throw new IllegalArgumentException("Metadata can only be applied to IMetas"); 406.682 - } 406.683 - 406.684 -} 406.685 - 406.686 -public static class SyntaxQuoteReader extends AFn{ 406.687 - public Object invoke(Object reader, Object backquote) throws Exception{ 406.688 - PushbackReader r = (PushbackReader) reader; 406.689 - try 406.690 - { 406.691 - Var.pushThreadBindings( 406.692 - RT.map(GENSYM_ENV, PersistentHashMap.EMPTY)); 406.693 - 406.694 - Object form = read(r, true, null, true); 406.695 - return syntaxQuote(form); 406.696 - } 406.697 - finally 406.698 - { 406.699 - Var.popThreadBindings(); 406.700 - } 406.701 - } 406.702 - 406.703 - static Object syntaxQuote(Object form) throws Exception{ 406.704 - Object ret; 406.705 - if(Compiler.isSpecial(form)) 406.706 - ret = RT.list(Compiler.QUOTE, form); 406.707 - else if(form instanceof Symbol) 406.708 - { 406.709 - Symbol sym = (Symbol) form; 406.710 - if(sym.ns == null && sym.name.endsWith("#")) 406.711 - { 406.712 - IPersistentMap gmap = (IPersistentMap) GENSYM_ENV.deref(); 406.713 - if(gmap == null) 406.714 - throw new IllegalStateException("Gensym literal not in syntax-quote"); 406.715 - Symbol gs = (Symbol) gmap.valAt(sym); 406.716 - if(gs == null) 406.717 - GENSYM_ENV.set(gmap.assoc(sym, gs = Symbol.intern(null, 406.718 - sym.name.substring(0, sym.name.length() - 1) 406.719 - + "__" + RT.nextID() + "__auto__"))); 406.720 - sym = gs; 406.721 - } 406.722 - else if(sym.ns == null && sym.name.endsWith(".")) 406.723 - { 406.724 - Symbol csym = Symbol.intern(null, sym.name.substring(0, sym.name.length() - 1)); 406.725 - csym = Compiler.resolveSymbol(csym); 406.726 - sym = Symbol.intern(null, csym.name.concat(".")); 406.727 - } 406.728 - else if(sym.ns == null && sym.name.startsWith(".")) 406.729 - { 406.730 - // Simply quote method names. 406.731 - } 406.732 - else 406.733 - { 406.734 - Object maybeClass = null; 406.735 - if(sym.ns != null) 406.736 - maybeClass = Compiler.currentNS().getMapping( 406.737 - Symbol.intern(null, sym.ns)); 406.738 - if(maybeClass instanceof Class) 406.739 - { 406.740 - // Classname/foo -> package.qualified.Classname/foo 406.741 - sym = Symbol.intern( 406.742 - ((Class)maybeClass).getName(), sym.name); 406.743 - } 406.744 - else 406.745 - sym = Compiler.resolveSymbol(sym); 406.746 - } 406.747 - ret = RT.list(Compiler.QUOTE, sym); 406.748 - } 406.749 - else if(isUnquote(form)) 406.750 - return RT.second(form); 406.751 - else if(isUnquoteSplicing(form)) 406.752 - throw new IllegalStateException("splice not in list"); 406.753 - else if(form instanceof IPersistentCollection) 406.754 - { 406.755 - if(form instanceof IPersistentMap) 406.756 - { 406.757 - IPersistentVector keyvals = flattenMap(form); 406.758 - ret = RT.list(APPLY, HASHMAP, RT.list(SEQ, RT.cons(CONCAT, sqExpandList(keyvals.seq())))); 406.759 - } 406.760 - else if(form instanceof IPersistentVector) 406.761 - { 406.762 - ret = RT.list(APPLY, VECTOR, RT.list(SEQ, RT.cons(CONCAT, sqExpandList(((IPersistentVector) form).seq())))); 406.763 - } 406.764 - else if(form instanceof IPersistentSet) 406.765 - { 406.766 - ret = RT.list(APPLY, HASHSET, RT.list(SEQ, RT.cons(CONCAT, sqExpandList(((IPersistentSet) form).seq())))); 406.767 - } 406.768 - else if(form instanceof ISeq || form instanceof IPersistentList) 406.769 - { 406.770 - ISeq seq = RT.seq(form); 406.771 - if(seq == null) 406.772 - ret = RT.cons(LIST,null); 406.773 - else 406.774 - ret = RT.list(SEQ, RT.cons(CONCAT, sqExpandList(seq))); 406.775 - } 406.776 - else 406.777 - throw new UnsupportedOperationException("Unknown Collection type"); 406.778 - } 406.779 - else if(form instanceof Keyword 406.780 - || form instanceof Number 406.781 - || form instanceof Character 406.782 - || form instanceof String) 406.783 - ret = form; 406.784 - else 406.785 - ret = RT.list(Compiler.QUOTE, form); 406.786 - 406.787 - if(form instanceof IObj && RT.meta(form) != null) 406.788 - { 406.789 - //filter line numbers 406.790 - IPersistentMap newMeta = ((IObj) form).meta().without(RT.LINE_KEY); 406.791 - if(newMeta.count() > 0) 406.792 - return RT.list(WITH_META, ret, syntaxQuote(((IObj) form).meta())); 406.793 - } 406.794 - return ret; 406.795 - } 406.796 - 406.797 - private static ISeq sqExpandList(ISeq seq) throws Exception{ 406.798 - PersistentVector ret = PersistentVector.EMPTY; 406.799 - for(; seq != null; seq = seq.next()) 406.800 - { 406.801 - Object item = seq.first(); 406.802 - if(isUnquote(item)) 406.803 - ret = ret.cons(RT.list(LIST, RT.second(item))); 406.804 - else if(isUnquoteSplicing(item)) 406.805 - ret = ret.cons(RT.second(item)); 406.806 - else 406.807 - ret = ret.cons(RT.list(LIST, syntaxQuote(item))); 406.808 - } 406.809 - return ret.seq(); 406.810 - } 406.811 - 406.812 - private static IPersistentVector flattenMap(Object form){ 406.813 - IPersistentVector keyvals = PersistentVector.EMPTY; 406.814 - for(ISeq s = RT.seq(form); s != null; s = s.next()) 406.815 - { 406.816 - IMapEntry e = (IMapEntry) s.first(); 406.817 - keyvals = (IPersistentVector) keyvals.cons(e.key()); 406.818 - keyvals = (IPersistentVector) keyvals.cons(e.val()); 406.819 - } 406.820 - return keyvals; 406.821 - } 406.822 - 406.823 -} 406.824 - 406.825 -static boolean isUnquoteSplicing(Object form){ 406.826 - return form instanceof ISeq && Util.equals(RT.first(form),UNQUOTE_SPLICING); 406.827 -} 406.828 - 406.829 -static boolean isUnquote(Object form){ 406.830 - return form instanceof ISeq && Util.equals(RT.first(form),UNQUOTE); 406.831 -} 406.832 - 406.833 -static class UnquoteReader extends AFn{ 406.834 - public Object invoke(Object reader, Object comma) throws Exception{ 406.835 - PushbackReader r = (PushbackReader) reader; 406.836 - int ch = r.read(); 406.837 - if(ch == -1) 406.838 - throw new Exception("EOF while reading character"); 406.839 - if(ch == '@') 406.840 - { 406.841 - Object o = read(r, true, null, true); 406.842 - return RT.list(UNQUOTE_SPLICING, o); 406.843 - } 406.844 - else 406.845 - { 406.846 - unread(r, ch); 406.847 - Object o = read(r, true, null, true); 406.848 - return RT.list(UNQUOTE, o); 406.849 - } 406.850 - } 406.851 - 406.852 -} 406.853 - 406.854 -public static class CharacterReader extends AFn{ 406.855 - public Object invoke(Object reader, Object backslash) throws Exception{ 406.856 - PushbackReader r = (PushbackReader) reader; 406.857 - int ch = r.read(); 406.858 - if(ch == -1) 406.859 - throw new Exception("EOF while reading character"); 406.860 - String token = readToken(r, (char) ch); 406.861 - if(token.length() == 1) 406.862 - return Character.valueOf(token.charAt(0)); 406.863 - else if(token.equals("newline")) 406.864 - return '\n'; 406.865 - else if(token.equals("space")) 406.866 - return ' '; 406.867 - else if(token.equals("tab")) 406.868 - return '\t'; 406.869 - else if(token.equals("backspace")) 406.870 - return '\b'; 406.871 - else if(token.equals("formfeed")) 406.872 - return '\f'; 406.873 - else if(token.equals("return")) 406.874 - return '\r'; 406.875 - else if(token.startsWith("u")) 406.876 - { 406.877 - char c = (char) readUnicodeChar(token, 1, 4, 16); 406.878 - if(c >= '\uD800' && c <= '\uDFFF') // surrogate code unit? 406.879 - throw new Exception("Invalid character constant: \\u" + Integer.toString(c, 16)); 406.880 - return c; 406.881 - } 406.882 - else if(token.startsWith("o")) 406.883 - { 406.884 - int len = token.length() - 1; 406.885 - if(len > 3) 406.886 - throw new Exception("Invalid octal escape sequence length: " + len); 406.887 - int uc = readUnicodeChar(token, 1, len, 8); 406.888 - if(uc > 0377) 406.889 - throw new Exception("Octal escape sequence must be in range [0, 377]."); 406.890 - return (char) uc; 406.891 - } 406.892 - throw new Exception("Unsupported character: \\" + token); 406.893 - } 406.894 - 406.895 -} 406.896 - 406.897 -public static class ListReader extends AFn{ 406.898 - public Object invoke(Object reader, Object leftparen) throws Exception{ 406.899 - PushbackReader r = (PushbackReader) reader; 406.900 - int line = -1; 406.901 - if(r instanceof LineNumberingPushbackReader) 406.902 - line = ((LineNumberingPushbackReader) r).getLineNumber(); 406.903 - List list = readDelimitedList(')', r, true); 406.904 - if(list.isEmpty()) 406.905 - return PersistentList.EMPTY; 406.906 - IObj s = (IObj) PersistentList.create(list); 406.907 -// IObj s = (IObj) RT.seq(list); 406.908 - if(line != -1) 406.909 - return s.withMeta(RT.map(RT.LINE_KEY, line)); 406.910 - else 406.911 - return s; 406.912 - } 406.913 - 406.914 -} 406.915 - 406.916 -static class CtorReader extends AFn{ 406.917 - static final Symbol cls = Symbol.create("class"); 406.918 - 406.919 - public Object invoke(Object reader, Object leftangle) throws Exception{ 406.920 - PushbackReader r = (PushbackReader) reader; 406.921 - // #<class classname> 406.922 - // #<classname args*> 406.923 - // #<classname/staticMethod args*> 406.924 - List list = readDelimitedList('>', r, true); 406.925 - if(list.isEmpty()) 406.926 - throw new Exception("Must supply 'class', classname or classname/staticMethod"); 406.927 - Symbol s = (Symbol) list.get(0); 406.928 - Object[] args = list.subList(1, list.size()).toArray(); 406.929 - if(s.equals(cls)) 406.930 - { 406.931 - return RT.classForName(args[0].toString()); 406.932 - } 406.933 - else if(s.ns != null) //static method 406.934 - { 406.935 - String classname = s.ns; 406.936 - String method = s.name; 406.937 - return Reflector.invokeStaticMethod(classname, method, args); 406.938 - } 406.939 - else 406.940 - { 406.941 - return Reflector.invokeConstructor(RT.classForName(s.name), args); 406.942 - } 406.943 - } 406.944 - 406.945 -} 406.946 - 406.947 -public static class EvalReader extends AFn{ 406.948 - public Object invoke(Object reader, Object eq) throws Exception{ 406.949 - if (!RT.booleanCast(RT.READEVAL.deref())) 406.950 - { 406.951 - throw new Exception("EvalReader not allowed when *read-eval* is false."); 406.952 - } 406.953 - 406.954 - PushbackReader r = (PushbackReader) reader; 406.955 - Object o = read(r, true, null, true); 406.956 - if(o instanceof Symbol) 406.957 - { 406.958 - return RT.classForName(o.toString()); 406.959 - } 406.960 - else if(o instanceof IPersistentList) 406.961 - { 406.962 - Symbol fs = (Symbol) RT.first(o); 406.963 - if(fs.equals(THE_VAR)) 406.964 - { 406.965 - Symbol vs = (Symbol) RT.second(o); 406.966 - return RT.var(vs.ns, vs.name); //Compiler.resolve((Symbol) RT.second(o),true); 406.967 - } 406.968 - if(fs.name.endsWith(".")) 406.969 - { 406.970 - Object[] args = RT.toArray(RT.next(o)); 406.971 - return Reflector.invokeConstructor(RT.classForName(fs.name.substring(0, fs.name.length() - 1)), args); 406.972 - } 406.973 - if(Compiler.namesStaticMember(fs)) 406.974 - { 406.975 - Object[] args = RT.toArray(RT.next(o)); 406.976 - return Reflector.invokeStaticMethod(fs.ns, fs.name, args); 406.977 - } 406.978 - Object v = Compiler.maybeResolveIn(Compiler.currentNS(), fs); 406.979 - if(v instanceof Var) 406.980 - { 406.981 - return ((IFn) v).applyTo(RT.next(o)); 406.982 - } 406.983 - throw new Exception("Can't resolve " + fs); 406.984 - } 406.985 - else 406.986 - throw new IllegalArgumentException("Unsupported #= form"); 406.987 - } 406.988 -} 406.989 - 406.990 -//static class ArgVectorReader extends AFn{ 406.991 -// public Object invoke(Object reader, Object leftparen) throws Exception{ 406.992 -// PushbackReader r = (PushbackReader) reader; 406.993 -// return ArgVector.create(readDelimitedList('|', r, true)); 406.994 -// } 406.995 -// 406.996 -//} 406.997 - 406.998 -public static class VectorReader extends AFn{ 406.999 - public Object invoke(Object reader, Object leftparen) throws Exception{ 406.1000 - PushbackReader r = (PushbackReader) reader; 406.1001 - return LazilyPersistentVector.create(readDelimitedList(']', r, true)); 406.1002 - } 406.1003 - 406.1004 -} 406.1005 - 406.1006 -public static class MapReader extends AFn{ 406.1007 - public Object invoke(Object reader, Object leftparen) throws Exception{ 406.1008 - PushbackReader r = (PushbackReader) reader; 406.1009 - return RT.map(readDelimitedList('}', r, true).toArray()); 406.1010 - } 406.1011 - 406.1012 -} 406.1013 - 406.1014 -public static class SetReader extends AFn{ 406.1015 - public Object invoke(Object reader, Object leftbracket) throws Exception{ 406.1016 - PushbackReader r = (PushbackReader) reader; 406.1017 - return PersistentHashSet.createWithCheck(readDelimitedList('}', r, true)); 406.1018 - } 406.1019 - 406.1020 -} 406.1021 - 406.1022 -public static class UnmatchedDelimiterReader extends AFn{ 406.1023 - public Object invoke(Object reader, Object rightdelim) throws Exception{ 406.1024 - throw new Exception("Unmatched delimiter: " + rightdelim); 406.1025 - } 406.1026 - 406.1027 -} 406.1028 - 406.1029 -public static class UnreadableReader extends AFn{ 406.1030 - public Object invoke(Object reader, Object leftangle) throws Exception{ 406.1031 - throw new Exception("Unreadable form"); 406.1032 - } 406.1033 -} 406.1034 - 406.1035 -public static List readDelimitedList(char delim, PushbackReader r, boolean isRecursive) throws Exception{ 406.1036 - ArrayList a = new ArrayList(); 406.1037 - 406.1038 - for(; ;) 406.1039 - { 406.1040 - int ch = r.read(); 406.1041 - 406.1042 - while(isWhitespace(ch)) 406.1043 - ch = r.read(); 406.1044 - 406.1045 - if(ch == -1) 406.1046 - throw new Exception("EOF while reading"); 406.1047 - 406.1048 - if(ch == delim) 406.1049 - break; 406.1050 - 406.1051 - IFn macroFn = getMacro(ch); 406.1052 - if(macroFn != null) 406.1053 - { 406.1054 - Object mret = macroFn.invoke(r, (char) ch); 406.1055 - //no op macros return the reader 406.1056 - if(mret != r) 406.1057 - a.add(mret); 406.1058 - } 406.1059 - else 406.1060 - { 406.1061 - unread(r, ch); 406.1062 - 406.1063 - Object o = read(r, true, null, isRecursive); 406.1064 - if(o != r) 406.1065 - a.add(o); 406.1066 - } 406.1067 - } 406.1068 - 406.1069 - 406.1070 - return a; 406.1071 -} 406.1072 - 406.1073 -/* 406.1074 -public static void main(String[] args) throws Exception{ 406.1075 - //RT.init(); 406.1076 - PushbackReader rdr = new PushbackReader( new java.io.StringReader( "(+ 21 21)" ) ); 406.1077 - Object input = LispReader.read(rdr, false, new Object(), false ); 406.1078 - System.out.println(Compiler.eval(input)); 406.1079 -} 406.1080 - 406.1081 -public static void main(String[] args){ 406.1082 - LineNumberingPushbackReader r = new LineNumberingPushbackReader(new InputStreamReader(System.in)); 406.1083 - OutputStreamWriter w = new OutputStreamWriter(System.out); 406.1084 - Object ret = null; 406.1085 - try 406.1086 - { 406.1087 - for(; ;) 406.1088 - { 406.1089 - ret = LispReader.read(r, true, null, false); 406.1090 - RT.print(ret, w); 406.1091 - w.write('\n'); 406.1092 - if(ret != null) 406.1093 - w.write(ret.getClass().toString()); 406.1094 - w.write('\n'); 406.1095 - w.flush(); 406.1096 - } 406.1097 - } 406.1098 - catch(Exception e) 406.1099 - { 406.1100 - e.printStackTrace(); 406.1101 - } 406.1102 -} 406.1103 - */ 406.1104 - 406.1105 -} 406.1106 -
407.1 --- a/src/clojure/lang/LockingTransaction.java Sat Aug 21 06:25:44 2010 -0400 407.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 407.3 @@ -1,645 +0,0 @@ 407.4 -/** 407.5 - * Copyright (c) Rich Hickey. All rights reserved. 407.6 - * The use and distribution terms for this software are covered by the 407.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 407.8 - * which can be found in the file epl-v10.html at the root of this distribution. 407.9 - * By using this software in any fashion, you are agreeing to be bound by 407.10 - * the terms of this license. 407.11 - * You must not remove this notice, or any other, from this software. 407.12 - **/ 407.13 - 407.14 -/* rich Jul 26, 2007 */ 407.15 - 407.16 -package clojure.lang; 407.17 - 407.18 -import java.util.*; 407.19 -import java.util.concurrent.atomic.AtomicInteger; 407.20 -import java.util.concurrent.atomic.AtomicLong; 407.21 -import java.util.concurrent.Callable; 407.22 -import java.util.concurrent.TimeUnit; 407.23 -import java.util.concurrent.CountDownLatch; 407.24 - 407.25 -@SuppressWarnings({"SynchronizeOnNonFinalField"}) 407.26 -public class LockingTransaction{ 407.27 - 407.28 -public static final int RETRY_LIMIT = 10000; 407.29 -public static final int LOCK_WAIT_MSECS = 100; 407.30 -public static final long BARGE_WAIT_NANOS = 10 * 1000000; 407.31 -//public static int COMMUTE_RETRY_LIMIT = 10; 407.32 - 407.33 -static final int RUNNING = 0; 407.34 -static final int COMMITTING = 1; 407.35 -static final int RETRY = 2; 407.36 -static final int KILLED = 3; 407.37 -static final int COMMITTED = 4; 407.38 - 407.39 -final static ThreadLocal<LockingTransaction> transaction = new ThreadLocal<LockingTransaction>(); 407.40 - 407.41 - 407.42 -static class RetryEx extends Error{ 407.43 -} 407.44 - 407.45 -static class AbortException extends Exception{ 407.46 -} 407.47 - 407.48 -public static class Info{ 407.49 - final AtomicInteger status; 407.50 - final long startPoint; 407.51 - final CountDownLatch latch; 407.52 - 407.53 - 407.54 - public Info(int status, long startPoint){ 407.55 - this.status = new AtomicInteger(status); 407.56 - this.startPoint = startPoint; 407.57 - this.latch = new CountDownLatch(1); 407.58 - } 407.59 - 407.60 - public boolean running(){ 407.61 - int s = status.get(); 407.62 - return s == RUNNING || s == COMMITTING; 407.63 - } 407.64 -} 407.65 - 407.66 -static class CFn{ 407.67 - final IFn fn; 407.68 - final ISeq args; 407.69 - 407.70 - public CFn(IFn fn, ISeq args){ 407.71 - this.fn = fn; 407.72 - this.args = args; 407.73 - } 407.74 -} 407.75 -//total order on transactions 407.76 -//transactions will consume a point for init, for each retry, and on commit if writing 407.77 -final private static AtomicLong lastPoint = new AtomicLong(); 407.78 - 407.79 -void getReadPoint(){ 407.80 - readPoint = lastPoint.incrementAndGet(); 407.81 -} 407.82 - 407.83 -long getCommitPoint(){ 407.84 - return lastPoint.incrementAndGet(); 407.85 -} 407.86 - 407.87 -void stop(int status){ 407.88 - if(info != null) 407.89 - { 407.90 - synchronized(info) 407.91 - { 407.92 - info.status.set(status); 407.93 - info.latch.countDown(); 407.94 - } 407.95 - info = null; 407.96 - vals.clear(); 407.97 - sets.clear(); 407.98 - commutes.clear(); 407.99 - //actions.clear(); 407.100 - } 407.101 -} 407.102 - 407.103 - 407.104 -Info info; 407.105 -long readPoint; 407.106 -long startPoint; 407.107 -long startTime; 407.108 -final RetryEx retryex = new RetryEx(); 407.109 -final ArrayList<Agent.Action> actions = new ArrayList<Agent.Action>(); 407.110 -final HashMap<Ref, Object> vals = new HashMap<Ref, Object>(); 407.111 -final HashSet<Ref> sets = new HashSet<Ref>(); 407.112 -final TreeMap<Ref, ArrayList<CFn>> commutes = new TreeMap<Ref, ArrayList<CFn>>(); 407.113 - 407.114 -final HashSet<Ref> ensures = new HashSet<Ref>(); //all hold readLock 407.115 - 407.116 - 407.117 -void tryWriteLock(Ref ref){ 407.118 - try 407.119 - { 407.120 - if(!ref.lock.writeLock().tryLock(LOCK_WAIT_MSECS, TimeUnit.MILLISECONDS)) 407.121 - throw retryex; 407.122 - } 407.123 - catch(InterruptedException e) 407.124 - { 407.125 - throw retryex; 407.126 - } 407.127 -} 407.128 - 407.129 -//returns the most recent val 407.130 -Object lock(Ref ref){ 407.131 - //can't upgrade readLock, so release it 407.132 - releaseIfEnsured(ref); 407.133 - 407.134 - boolean unlocked = true; 407.135 - try 407.136 - { 407.137 - tryWriteLock(ref); 407.138 - unlocked = false; 407.139 - 407.140 - if(ref.tvals != null && ref.tvals.point > readPoint) 407.141 - throw retryex; 407.142 - Info refinfo = ref.tinfo; 407.143 - 407.144 - //write lock conflict 407.145 - if(refinfo != null && refinfo != info && refinfo.running()) 407.146 - { 407.147 - if(!barge(refinfo)) 407.148 - { 407.149 - ref.lock.writeLock().unlock(); 407.150 - unlocked = true; 407.151 - return blockAndBail(refinfo); 407.152 - } 407.153 - } 407.154 - ref.tinfo = info; 407.155 - return ref.tvals == null ? null : ref.tvals.val; 407.156 - } 407.157 - finally 407.158 - { 407.159 - if(!unlocked) 407.160 - ref.lock.writeLock().unlock(); 407.161 - } 407.162 -} 407.163 - 407.164 -private Object blockAndBail(Info refinfo){ 407.165 -//stop prior to blocking 407.166 - stop(RETRY); 407.167 - try 407.168 - { 407.169 - refinfo.latch.await(LOCK_WAIT_MSECS, TimeUnit.MILLISECONDS); 407.170 - } 407.171 - catch(InterruptedException e) 407.172 - { 407.173 - //ignore 407.174 - } 407.175 - throw retryex; 407.176 -} 407.177 - 407.178 -private void releaseIfEnsured(Ref ref){ 407.179 - if(ensures.contains(ref)) 407.180 - { 407.181 - ensures.remove(ref); 407.182 - ref.lock.readLock().unlock(); 407.183 - } 407.184 -} 407.185 - 407.186 -void abort() throws AbortException{ 407.187 - stop(KILLED); 407.188 - throw new AbortException(); 407.189 -} 407.190 - 407.191 -private boolean bargeTimeElapsed(){ 407.192 - return System.nanoTime() - startTime > BARGE_WAIT_NANOS; 407.193 -} 407.194 - 407.195 -private boolean barge(Info refinfo){ 407.196 - boolean barged = false; 407.197 - //if this transaction is older 407.198 - // try to abort the other 407.199 - if(bargeTimeElapsed() && startPoint < refinfo.startPoint) 407.200 - { 407.201 - barged = refinfo.status.compareAndSet(RUNNING, KILLED); 407.202 - if(barged) 407.203 - refinfo.latch.countDown(); 407.204 - } 407.205 - return barged; 407.206 -} 407.207 - 407.208 -static LockingTransaction getEx(){ 407.209 - LockingTransaction t = transaction.get(); 407.210 - if(t == null || t.info == null) 407.211 - throw new IllegalStateException("No transaction running"); 407.212 - return t; 407.213 -} 407.214 - 407.215 -static public boolean isRunning(){ 407.216 - return getRunning() != null; 407.217 -} 407.218 - 407.219 -static LockingTransaction getRunning(){ 407.220 - LockingTransaction t = transaction.get(); 407.221 - if(t == null || t.info == null) 407.222 - return null; 407.223 - return t; 407.224 -} 407.225 - 407.226 -static public Object runInTransaction(Callable fn) throws Exception{ 407.227 - LockingTransaction t = transaction.get(); 407.228 - if(t == null) 407.229 - transaction.set(t = new LockingTransaction()); 407.230 - 407.231 - if(t.info != null) 407.232 - return fn.call(); 407.233 - 407.234 - return t.run(fn); 407.235 -} 407.236 - 407.237 -static class Notify{ 407.238 - final public Ref ref; 407.239 - final public Object oldval; 407.240 - final public Object newval; 407.241 - 407.242 - Notify(Ref ref, Object oldval, Object newval){ 407.243 - this.ref = ref; 407.244 - this.oldval = oldval; 407.245 - this.newval = newval; 407.246 - } 407.247 -} 407.248 - 407.249 -Object run(Callable fn) throws Exception{ 407.250 - boolean done = false; 407.251 - Object ret = null; 407.252 - ArrayList<Ref> locked = new ArrayList<Ref>(); 407.253 - ArrayList<Notify> notify = new ArrayList<Notify>(); 407.254 - 407.255 - for(int i = 0; !done && i < RETRY_LIMIT; i++) 407.256 - { 407.257 - try 407.258 - { 407.259 - getReadPoint(); 407.260 - if(i == 0) 407.261 - { 407.262 - startPoint = readPoint; 407.263 - startTime = System.nanoTime(); 407.264 - } 407.265 - info = new Info(RUNNING, startPoint); 407.266 - ret = fn.call(); 407.267 - //make sure no one has killed us before this point, and can't from now on 407.268 - if(info.status.compareAndSet(RUNNING, COMMITTING)) 407.269 - { 407.270 - for(Map.Entry<Ref, ArrayList<CFn>> e : commutes.entrySet()) 407.271 - { 407.272 - Ref ref = e.getKey(); 407.273 - if(sets.contains(ref)) continue; 407.274 - 407.275 - boolean wasEnsured = ensures.contains(ref); 407.276 - //can't upgrade readLock, so release it 407.277 - releaseIfEnsured(ref); 407.278 - tryWriteLock(ref); 407.279 - locked.add(ref); 407.280 - if(wasEnsured && ref.tvals != null && ref.tvals.point > readPoint) 407.281 - throw retryex; 407.282 - 407.283 - Info refinfo = ref.tinfo; 407.284 - if(refinfo != null && refinfo != info && refinfo.running()) 407.285 - { 407.286 - if(!barge(refinfo)) 407.287 - throw retryex; 407.288 - } 407.289 - Object val = ref.tvals == null ? null : ref.tvals.val; 407.290 - vals.put(ref, val); 407.291 - for(CFn f : e.getValue()) 407.292 - { 407.293 - vals.put(ref, f.fn.applyTo(RT.cons(vals.get(ref), f.args))); 407.294 - } 407.295 - } 407.296 - for(Ref ref : sets) 407.297 - { 407.298 - tryWriteLock(ref); 407.299 - locked.add(ref); 407.300 - } 407.301 - 407.302 - //validate and enqueue notifications 407.303 - for(Map.Entry<Ref, Object> e : vals.entrySet()) 407.304 - { 407.305 - Ref ref = e.getKey(); 407.306 - ref.validate(ref.getValidator(), e.getValue()); 407.307 - } 407.308 - 407.309 - //at this point, all values calced, all refs to be written locked 407.310 - //no more client code to be called 407.311 - long msecs = System.currentTimeMillis(); 407.312 - long commitPoint = getCommitPoint(); 407.313 - for(Map.Entry<Ref, Object> e : vals.entrySet()) 407.314 - { 407.315 - Ref ref = e.getKey(); 407.316 - Object oldval = ref.tvals == null ? null : ref.tvals.val; 407.317 - Object newval = e.getValue(); 407.318 - int hcount = ref.histCount(); 407.319 - 407.320 - if(ref.tvals == null) 407.321 - { 407.322 - ref.tvals = new Ref.TVal(newval, commitPoint, msecs); 407.323 - } 407.324 - else if((ref.faults.get() > 0 && hcount < ref.maxHistory) 407.325 - || hcount < ref.minHistory) 407.326 - { 407.327 - ref.tvals = new Ref.TVal(newval, commitPoint, msecs, ref.tvals); 407.328 - ref.faults.set(0); 407.329 - } 407.330 - else 407.331 - { 407.332 - ref.tvals = ref.tvals.next; 407.333 - ref.tvals.val = newval; 407.334 - ref.tvals.point = commitPoint; 407.335 - ref.tvals.msecs = msecs; 407.336 - } 407.337 - if(ref.getWatches().count() > 0) 407.338 - notify.add(new Notify(ref, oldval, newval)); 407.339 - } 407.340 - 407.341 - done = true; 407.342 - info.status.set(COMMITTED); 407.343 - } 407.344 - } 407.345 - catch(RetryEx retry) 407.346 - { 407.347 - //eat this so we retry rather than fall out 407.348 - } 407.349 - finally 407.350 - { 407.351 - for(int k = locked.size() - 1; k >= 0; --k) 407.352 - { 407.353 - locked.get(k).lock.writeLock().unlock(); 407.354 - } 407.355 - locked.clear(); 407.356 - for(Ref r : ensures) 407.357 - { 407.358 - r.lock.readLock().unlock(); 407.359 - } 407.360 - ensures.clear(); 407.361 - stop(done ? COMMITTED : RETRY); 407.362 - try 407.363 - { 407.364 - if(done) //re-dispatch out of transaction 407.365 - { 407.366 - for(Notify n : notify) 407.367 - { 407.368 - n.ref.notifyWatches(n.oldval, n.newval); 407.369 - } 407.370 - for(Agent.Action action : actions) 407.371 - { 407.372 - Agent.dispatchAction(action); 407.373 - } 407.374 - } 407.375 - } 407.376 - finally 407.377 - { 407.378 - notify.clear(); 407.379 - actions.clear(); 407.380 - } 407.381 - } 407.382 - } 407.383 - if(!done) 407.384 - throw new Exception("Transaction failed after reaching retry limit"); 407.385 - return ret; 407.386 -} 407.387 - 407.388 -public void enqueue(Agent.Action action){ 407.389 - actions.add(action); 407.390 -} 407.391 - 407.392 -Object doGet(Ref ref){ 407.393 - if(!info.running()) 407.394 - throw retryex; 407.395 - if(vals.containsKey(ref)) 407.396 - return vals.get(ref); 407.397 - try 407.398 - { 407.399 - ref.lock.readLock().lock(); 407.400 - if(ref.tvals == null) 407.401 - throw new IllegalStateException(ref.toString() + " is unbound."); 407.402 - Ref.TVal ver = ref.tvals; 407.403 - do 407.404 - { 407.405 - if(ver.point <= readPoint) 407.406 - return ver.val; 407.407 - } while((ver = ver.prior) != ref.tvals); 407.408 - } 407.409 - finally 407.410 - { 407.411 - ref.lock.readLock().unlock(); 407.412 - } 407.413 - //no version of val precedes the read point 407.414 - ref.faults.incrementAndGet(); 407.415 - throw retryex; 407.416 - 407.417 -} 407.418 - 407.419 -Object doSet(Ref ref, Object val){ 407.420 - if(!info.running()) 407.421 - throw retryex; 407.422 - if(commutes.containsKey(ref)) 407.423 - throw new IllegalStateException("Can't set after commute"); 407.424 - if(!sets.contains(ref)) 407.425 - { 407.426 - sets.add(ref); 407.427 - lock(ref); 407.428 - } 407.429 - vals.put(ref, val); 407.430 - return val; 407.431 -} 407.432 - 407.433 -void doEnsure(Ref ref){ 407.434 - if(!info.running()) 407.435 - throw retryex; 407.436 - if(ensures.contains(ref)) 407.437 - return; 407.438 - ref.lock.readLock().lock(); 407.439 - 407.440 - //someone completed a write after our snapshot 407.441 - if(ref.tvals != null && ref.tvals.point > readPoint) { 407.442 - ref.lock.readLock().unlock(); 407.443 - throw retryex; 407.444 - } 407.445 - 407.446 - Info refinfo = ref.tinfo; 407.447 - 407.448 - //writer exists 407.449 - if(refinfo != null && refinfo.running()) 407.450 - { 407.451 - ref.lock.readLock().unlock(); 407.452 - 407.453 - if(refinfo != info) //not us, ensure is doomed 407.454 - { 407.455 - blockAndBail(refinfo); 407.456 - } 407.457 - } 407.458 - else 407.459 - ensures.add(ref); 407.460 -} 407.461 - 407.462 -Object doCommute(Ref ref, IFn fn, ISeq args) throws Exception{ 407.463 - if(!info.running()) 407.464 - throw retryex; 407.465 - if(!vals.containsKey(ref)) 407.466 - { 407.467 - Object val = null; 407.468 - try 407.469 - { 407.470 - ref.lock.readLock().lock(); 407.471 - val = ref.tvals == null ? null : ref.tvals.val; 407.472 - } 407.473 - finally 407.474 - { 407.475 - ref.lock.readLock().unlock(); 407.476 - } 407.477 - vals.put(ref, val); 407.478 - } 407.479 - ArrayList<CFn> fns = commutes.get(ref); 407.480 - if(fns == null) 407.481 - commutes.put(ref, fns = new ArrayList<CFn>()); 407.482 - fns.add(new CFn(fn, args)); 407.483 - Object ret = fn.applyTo(RT.cons(vals.get(ref), args)); 407.484 - vals.put(ref, ret); 407.485 - return ret; 407.486 -} 407.487 - 407.488 -/* 407.489 -//for test 407.490 -static CyclicBarrier barrier; 407.491 -static ArrayList<Ref> items; 407.492 - 407.493 -public static void main(String[] args){ 407.494 - try 407.495 - { 407.496 - if(args.length != 4) 407.497 - System.err.println("Usage: LockingTransaction nthreads nitems niters ninstances"); 407.498 - int nthreads = Integer.parseInt(args[0]); 407.499 - int nitems = Integer.parseInt(args[1]); 407.500 - int niters = Integer.parseInt(args[2]); 407.501 - int ninstances = Integer.parseInt(args[3]); 407.502 - 407.503 - if(items == null) 407.504 - { 407.505 - ArrayList<Ref> temp = new ArrayList(nitems); 407.506 - for(int i = 0; i < nitems; i++) 407.507 - temp.add(new Ref(0)); 407.508 - items = temp; 407.509 - } 407.510 - 407.511 - class Incr extends AFn{ 407.512 - public Object invoke(Object arg1) throws Exception{ 407.513 - Integer i = (Integer) arg1; 407.514 - return i + 1; 407.515 - } 407.516 - 407.517 - public Obj withMeta(IPersistentMap meta){ 407.518 - throw new UnsupportedOperationException(); 407.519 - 407.520 - } 407.521 - } 407.522 - 407.523 - class Commuter extends AFn implements Callable{ 407.524 - int niters; 407.525 - List<Ref> items; 407.526 - Incr incr; 407.527 - 407.528 - 407.529 - public Commuter(int niters, List<Ref> items){ 407.530 - this.niters = niters; 407.531 - this.items = items; 407.532 - this.incr = new Incr(); 407.533 - } 407.534 - 407.535 - public Object call() throws Exception{ 407.536 - long nanos = 0; 407.537 - for(int i = 0; i < niters; i++) 407.538 - { 407.539 - long start = System.nanoTime(); 407.540 - LockingTransaction.runInTransaction(this); 407.541 - nanos += System.nanoTime() - start; 407.542 - } 407.543 - return nanos; 407.544 - } 407.545 - 407.546 - public Object invoke() throws Exception{ 407.547 - for(Ref tref : items) 407.548 - { 407.549 - LockingTransaction.getEx().doCommute(tref, incr); 407.550 - } 407.551 - return null; 407.552 - } 407.553 - 407.554 - public Obj withMeta(IPersistentMap meta){ 407.555 - throw new UnsupportedOperationException(); 407.556 - 407.557 - } 407.558 - } 407.559 - 407.560 - class Incrementer extends AFn implements Callable{ 407.561 - int niters; 407.562 - List<Ref> items; 407.563 - 407.564 - 407.565 - public Incrementer(int niters, List<Ref> items){ 407.566 - this.niters = niters; 407.567 - this.items = items; 407.568 - } 407.569 - 407.570 - public Object call() throws Exception{ 407.571 - long nanos = 0; 407.572 - for(int i = 0; i < niters; i++) 407.573 - { 407.574 - long start = System.nanoTime(); 407.575 - LockingTransaction.runInTransaction(this); 407.576 - nanos += System.nanoTime() - start; 407.577 - } 407.578 - return nanos; 407.579 - } 407.580 - 407.581 - public Object invoke() throws Exception{ 407.582 - for(Ref tref : items) 407.583 - { 407.584 - //Transaction.get().doTouch(tref); 407.585 -// LockingTransaction t = LockingTransaction.getEx(); 407.586 -// int val = (Integer) t.doGet(tref); 407.587 -// t.doSet(tref, val + 1); 407.588 - int val = (Integer) tref.get(); 407.589 - tref.set(val + 1); 407.590 - } 407.591 - return null; 407.592 - } 407.593 - 407.594 - public Obj withMeta(IPersistentMap meta){ 407.595 - throw new UnsupportedOperationException(); 407.596 - 407.597 - } 407.598 - } 407.599 - 407.600 - ArrayList<Callable<Long>> tasks = new ArrayList(nthreads); 407.601 - for(int i = 0; i < nthreads; i++) 407.602 - { 407.603 - ArrayList<Ref> si; 407.604 - synchronized(items) 407.605 - { 407.606 - si = (ArrayList<Ref>) items.clone(); 407.607 - } 407.608 - Collections.shuffle(si); 407.609 - tasks.add(new Incrementer(niters, si)); 407.610 - //tasks.add(new Commuter(niters, si)); 407.611 - } 407.612 - ExecutorService e = Executors.newFixedThreadPool(nthreads); 407.613 - 407.614 - if(barrier == null) 407.615 - barrier = new CyclicBarrier(ninstances); 407.616 - System.out.println("waiting for other instances..."); 407.617 - barrier.await(); 407.618 - System.out.println("starting"); 407.619 - long start = System.nanoTime(); 407.620 - List<Future<Long>> results = e.invokeAll(tasks); 407.621 - long estimatedTime = System.nanoTime() - start; 407.622 - System.out.printf("nthreads: %d, nitems: %d, niters: %d, time: %d%n", nthreads, nitems, niters, 407.623 - estimatedTime / 1000000); 407.624 - e.shutdown(); 407.625 - for(Future<Long> result : results) 407.626 - { 407.627 - System.out.printf("%d, ", result.get() / 1000000); 407.628 - } 407.629 - System.out.println(); 407.630 - System.out.println("waiting for other instances..."); 407.631 - barrier.await(); 407.632 - synchronized(items) 407.633 - { 407.634 - for(Ref item : items) 407.635 - { 407.636 - System.out.printf("%d, ", (Integer) item.currentVal()); 407.637 - } 407.638 - } 407.639 - System.out.println("\ndone"); 407.640 - System.out.flush(); 407.641 - } 407.642 - catch(Exception ex) 407.643 - { 407.644 - ex.printStackTrace(); 407.645 - } 407.646 -} 407.647 -*/ 407.648 -}
408.1 --- a/src/clojure/lang/MapEntry.java Sat Aug 21 06:25:44 2010 -0400 408.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 408.3 @@ -1,40 +0,0 @@ 408.4 -/** 408.5 - * Copyright (c) Rich Hickey. All rights reserved. 408.6 - * The use and distribution terms for this software are covered by the 408.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 408.8 - * which can be found in the file epl-v10.html at the root of this distribution. 408.9 - * By using this software in any fashion, you are agreeing to be bound by 408.10 - * the terms of this license. 408.11 - * You must not remove this notice, or any other, from this software. 408.12 - **/ 408.13 - 408.14 -package clojure.lang; 408.15 - 408.16 -import java.util.Iterator; 408.17 - 408.18 -public class MapEntry extends AMapEntry{ 408.19 -final Object _key; 408.20 -final Object _val; 408.21 - 408.22 -public MapEntry(Object key, Object val){ 408.23 - this._key = key; 408.24 - this._val = val; 408.25 -} 408.26 - 408.27 -public Object key(){ 408.28 - return _key; 408.29 -} 408.30 - 408.31 -public Object val(){ 408.32 - return _val; 408.33 -} 408.34 - 408.35 -public Object getKey(){ 408.36 - return key(); 408.37 -} 408.38 - 408.39 -public Object getValue(){ 408.40 - return val(); 408.41 -} 408.42 - 408.43 -}
409.1 --- a/src/clojure/lang/MapEquivalence.java Sat Aug 21 06:25:44 2010 -0400 409.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 409.3 @@ -1,17 +0,0 @@ 409.4 -/** 409.5 - * Copyright (c) Rich Hickey. All rights reserved. 409.6 - * The use and distribution terms for this software are covered by the 409.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 409.8 - * which can be found in the file epl-v10.html at the root of this distribution. 409.9 - * By using this software in any fashion, you are agreeing to be bound by 409.10 - * the terms of this license. 409.11 - * You must not remove this notice, or any other, from this software. 409.12 - **/ 409.13 - 409.14 -/* rich Aug 4, 2010 */ 409.15 - 409.16 -package clojure.lang; 409.17 - 409.18 -//marker interface 409.19 -public interface MapEquivalence{ 409.20 -}
410.1 --- a/src/clojure/lang/MethodImplCache.java Sat Aug 21 06:25:44 2010 -0400 410.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 410.3 @@ -1,66 +0,0 @@ 410.4 -/** 410.5 - * Copyright (c) Rich Hickey. All rights reserved. 410.6 - * The use and distribution terms for this software are covered by the 410.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 410.8 - * which can be found in the file epl-v10.html at the root of this distribution. 410.9 - * By using this software in any fashion, you are agreeing to be bound by 410.10 - * the terms of this license. 410.11 - * You must not remove this notice, or any other, from this software. 410.12 - **/ 410.13 - 410.14 -/* rich Nov 8, 2009 */ 410.15 - 410.16 -package clojure.lang; 410.17 - 410.18 -public final class MethodImplCache{ 410.19 - 410.20 -static public class Entry{ 410.21 - final public Class c; 410.22 - final public IFn fn; 410.23 - 410.24 - public Entry(Class c, IFn fn){ 410.25 - this.c = c; 410.26 - this.fn = fn; 410.27 - } 410.28 -} 410.29 - 410.30 -public final IPersistentMap protocol; 410.31 -public final Keyword methodk; 410.32 -public final int shift; 410.33 -public final int mask; 410.34 -public final Object[] table; //[class, entry. class, entry ...] 410.35 - 410.36 -volatile Entry mre = null; 410.37 - 410.38 -public MethodImplCache(IPersistentMap protocol, Keyword methodk){ 410.39 - this(protocol, methodk, 0, 0, RT.EMPTY_ARRAY); 410.40 -} 410.41 - 410.42 -public MethodImplCache(IPersistentMap protocol, Keyword methodk, int shift, int mask, Object[] table){ 410.43 - this.protocol = protocol; 410.44 - this.methodk = methodk; 410.45 - this.shift = shift; 410.46 - this.mask = mask; 410.47 - this.table = table; 410.48 -} 410.49 - 410.50 -public IFn fnFor(Class c){ 410.51 - Entry last = mre; 410.52 - if(last != null && last.c == c) 410.53 - return last.fn; 410.54 - return findFnFor(c); 410.55 -} 410.56 - 410.57 -IFn findFnFor(Class c){ 410.58 - int idx = ((Util.hash(c) >> shift) & mask) << 1; 410.59 - if(idx < table.length && table[idx] == c) 410.60 - { 410.61 - Entry e = ((Entry) table[idx + 1]); 410.62 - mre = e; 410.63 - return e != null ? e.fn : null; 410.64 - } 410.65 - return null; 410.66 -} 410.67 - 410.68 - 410.69 -}
411.1 --- a/src/clojure/lang/MultiFn.java Sat Aug 21 06:25:44 2010 -0400 411.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 411.3 @@ -1,314 +0,0 @@ 411.4 -/** 411.5 - * Copyright (c) Rich Hickey. All rights reserved. 411.6 - * The use and distribution terms for this software are covered by the 411.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 411.8 - * which can be found in the file epl-v10.html at the root of this distribution. 411.9 - * By using this software in any fashion, you are agreeing to be bound by 411.10 - * the terms of this license. 411.11 - * You must not remove this notice, or any other, from this software. 411.12 - **/ 411.13 - 411.14 -/* rich Sep 13, 2007 */ 411.15 - 411.16 -package clojure.lang; 411.17 - 411.18 -import java.util.Map; 411.19 - 411.20 -public class MultiFn extends AFn{ 411.21 -final public IFn dispatchFn; 411.22 -final public Object defaultDispatchVal; 411.23 -final public IRef hierarchy; 411.24 -final String name; 411.25 -IPersistentMap methodTable; 411.26 -IPersistentMap preferTable; 411.27 -IPersistentMap methodCache; 411.28 -Object cachedHierarchy; 411.29 - 411.30 -static final Var assoc = RT.var("clojure.core", "assoc"); 411.31 -static final Var dissoc = RT.var("clojure.core", "dissoc"); 411.32 -static final Var isa = RT.var("clojure.core", "isa?"); 411.33 -static final Var parents = RT.var("clojure.core", "parents"); 411.34 - 411.35 -public MultiFn(String name, IFn dispatchFn, Object defaultDispatchVal, IRef hierarchy) throws Exception{ 411.36 - this.name = name; 411.37 - this.dispatchFn = dispatchFn; 411.38 - this.defaultDispatchVal = defaultDispatchVal; 411.39 - this.methodTable = PersistentHashMap.EMPTY; 411.40 - this.methodCache = getMethodTable(); 411.41 - this.preferTable = PersistentHashMap.EMPTY; 411.42 - this.hierarchy = hierarchy; 411.43 - cachedHierarchy = null; 411.44 -} 411.45 - 411.46 -synchronized public MultiFn reset(){ 411.47 - methodTable = methodCache = preferTable = PersistentHashMap.EMPTY; 411.48 - cachedHierarchy = null; 411.49 - return this; 411.50 -} 411.51 - 411.52 -synchronized public MultiFn addMethod(Object dispatchVal, IFn method) throws Exception{ 411.53 - methodTable = getMethodTable().assoc(dispatchVal, method); 411.54 - resetCache(); 411.55 - return this; 411.56 -} 411.57 - 411.58 -synchronized public MultiFn removeMethod(Object dispatchVal) throws Exception{ 411.59 - methodTable = getMethodTable().without(dispatchVal); 411.60 - resetCache(); 411.61 - return this; 411.62 -} 411.63 - 411.64 -synchronized public MultiFn preferMethod(Object dispatchValX, Object dispatchValY) throws Exception{ 411.65 - if(prefers(dispatchValY, dispatchValX)) 411.66 - throw new IllegalStateException( 411.67 - String.format("Preference conflict in multimethod '%s': %s is already preferred to %s", 411.68 - name, dispatchValY, dispatchValX)); 411.69 - preferTable = getPreferTable().assoc(dispatchValX, RT.conj((IPersistentCollection) RT.get(getPreferTable(), 411.70 - dispatchValX, 411.71 - PersistentHashSet.EMPTY), 411.72 - dispatchValY)); 411.73 - resetCache(); 411.74 - return this; 411.75 -} 411.76 - 411.77 -private boolean prefers(Object x, Object y) throws Exception{ 411.78 - IPersistentSet xprefs = (IPersistentSet) getPreferTable().valAt(x); 411.79 - if(xprefs != null && xprefs.contains(y)) 411.80 - return true; 411.81 - for(ISeq ps = RT.seq(parents.invoke(y)); ps != null; ps = ps.next()) 411.82 - { 411.83 - if(prefers(x, ps.first())) 411.84 - return true; 411.85 - } 411.86 - for(ISeq ps = RT.seq(parents.invoke(x)); ps != null; ps = ps.next()) 411.87 - { 411.88 - if(prefers(ps.first(), y)) 411.89 - return true; 411.90 - } 411.91 - return false; 411.92 -} 411.93 - 411.94 -private boolean isA(Object x, Object y) throws Exception{ 411.95 - return RT.booleanCast(isa.invoke(hierarchy.deref(), x, y)); 411.96 -} 411.97 - 411.98 -private boolean dominates(Object x, Object y) throws Exception{ 411.99 - return prefers(x, y) || isA(x, y); 411.100 -} 411.101 - 411.102 -private IPersistentMap resetCache() throws Exception{ 411.103 - methodCache = getMethodTable(); 411.104 - cachedHierarchy = hierarchy.deref(); 411.105 - return methodCache; 411.106 -} 411.107 - 411.108 -synchronized public IFn getMethod(Object dispatchVal) throws Exception{ 411.109 - if(cachedHierarchy != hierarchy.deref()) 411.110 - resetCache(); 411.111 - IFn targetFn = (IFn) methodCache.valAt(dispatchVal); 411.112 - if(targetFn != null) 411.113 - return targetFn; 411.114 - targetFn = findAndCacheBestMethod(dispatchVal); 411.115 - if(targetFn != null) 411.116 - return targetFn; 411.117 - targetFn = (IFn) getMethodTable().valAt(defaultDispatchVal); 411.118 - return targetFn; 411.119 -} 411.120 - 411.121 -private IFn getFn(Object dispatchVal) throws Exception{ 411.122 - IFn targetFn = getMethod(dispatchVal); 411.123 - if(targetFn == null) 411.124 - throw new IllegalArgumentException(String.format("No method in multimethod '%s' for dispatch value: %s", 411.125 - name, dispatchVal)); 411.126 - return targetFn; 411.127 -} 411.128 - 411.129 -private IFn findAndCacheBestMethod(Object dispatchVal) throws Exception{ 411.130 - Map.Entry bestEntry = null; 411.131 - for(Object o : getMethodTable()) 411.132 - { 411.133 - Map.Entry e = (Map.Entry) o; 411.134 - if(isA(dispatchVal, e.getKey())) 411.135 - { 411.136 - if(bestEntry == null || dominates(e.getKey(), bestEntry.getKey())) 411.137 - bestEntry = e; 411.138 - if(!dominates(bestEntry.getKey(), e.getKey())) 411.139 - throw new IllegalArgumentException( 411.140 - String.format( 411.141 - "Multiple methods in multimethod '%s' match dispatch value: %s -> %s and %s, and neither is preferred", 411.142 - name, dispatchVal, e.getKey(), bestEntry.getKey())); 411.143 - } 411.144 - } 411.145 - if(bestEntry == null) 411.146 - return null; 411.147 - //ensure basis has stayed stable throughout, else redo 411.148 - if(cachedHierarchy == hierarchy.deref()) 411.149 - { 411.150 - //place in cache 411.151 - methodCache = methodCache.assoc(dispatchVal, bestEntry.getValue()); 411.152 - return (IFn) bestEntry.getValue(); 411.153 - } 411.154 - else 411.155 - { 411.156 - resetCache(); 411.157 - return findAndCacheBestMethod(dispatchVal); 411.158 - } 411.159 -} 411.160 - 411.161 -public Object invoke() throws Exception{ 411.162 - return getFn(dispatchFn.invoke()).invoke(); 411.163 -} 411.164 - 411.165 -public Object invoke(Object arg1) throws Exception{ 411.166 - return getFn(dispatchFn.invoke(arg1)).invoke(arg1); 411.167 -} 411.168 - 411.169 -public Object invoke(Object arg1, Object arg2) throws Exception{ 411.170 - return getFn(dispatchFn.invoke(arg1, arg2)).invoke(arg1, arg2); 411.171 -} 411.172 - 411.173 -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception{ 411.174 - return getFn(dispatchFn.invoke(arg1, arg2, arg3)).invoke(arg1, arg2, arg3); 411.175 -} 411.176 - 411.177 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception{ 411.178 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4)).invoke(arg1, arg2, arg3, arg4); 411.179 -} 411.180 - 411.181 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception{ 411.182 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5)).invoke(arg1, arg2, arg3, arg4, arg5); 411.183 -} 411.184 - 411.185 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception{ 411.186 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6)).invoke(arg1, arg2, arg3, arg4, arg5, arg6); 411.187 -} 411.188 - 411.189 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) 411.190 - throws Exception{ 411.191 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7)) 411.192 - .invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7); 411.193 -} 411.194 - 411.195 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.196 - Object arg8) throws Exception{ 411.197 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)). 411.198 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); 411.199 -} 411.200 - 411.201 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.202 - Object arg8, Object arg9) throws Exception{ 411.203 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)). 411.204 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); 411.205 -} 411.206 - 411.207 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.208 - Object arg8, Object arg9, Object arg10) throws Exception{ 411.209 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)). 411.210 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); 411.211 -} 411.212 - 411.213 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.214 - Object arg8, Object arg9, Object arg10, Object arg11) throws Exception{ 411.215 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)). 411.216 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); 411.217 -} 411.218 - 411.219 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.220 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception{ 411.221 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)). 411.222 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); 411.223 -} 411.224 - 411.225 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.226 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) throws Exception{ 411.227 - return getFn(dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)). 411.228 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); 411.229 -} 411.230 - 411.231 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.232 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) 411.233 - throws Exception{ 411.234 - return getFn( 411.235 - dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)). 411.236 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); 411.237 -} 411.238 - 411.239 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.240 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 411.241 - Object arg15) throws Exception{ 411.242 - return getFn( 411.243 - dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.244 - arg15)) 411.245 - .invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); 411.246 -} 411.247 - 411.248 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.249 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 411.250 - Object arg15, Object arg16) throws Exception{ 411.251 - return getFn( 411.252 - dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.253 - arg15, arg16)) 411.254 - .invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.255 - arg15, arg16); 411.256 -} 411.257 - 411.258 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.259 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 411.260 - Object arg15, Object arg16, Object arg17) throws Exception{ 411.261 - return getFn( 411.262 - dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.263 - arg15, arg16, arg17)) 411.264 - .invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.265 - arg15, arg16, arg17); 411.266 -} 411.267 - 411.268 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.269 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 411.270 - Object arg15, Object arg16, Object arg17, Object arg18) throws Exception{ 411.271 - return getFn( 411.272 - dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.273 - arg15, arg16, arg17, arg18)). 411.274 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.275 - arg15, arg16, arg17, arg18); 411.276 -} 411.277 - 411.278 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.279 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 411.280 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception{ 411.281 - return getFn( 411.282 - dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.283 - arg15, arg16, arg17, arg18, arg19)). 411.284 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.285 - arg15, arg16, arg17, arg18, arg19); 411.286 -} 411.287 - 411.288 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.289 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 411.290 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20) 411.291 - throws Exception{ 411.292 - return getFn( 411.293 - dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.294 - arg15, arg16, arg17, arg18, arg19, arg20)). 411.295 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.296 - arg15, arg16, arg17, arg18, arg19, arg20); 411.297 -} 411.298 - 411.299 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 411.300 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 411.301 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20, Object... args) 411.302 - throws Exception{ 411.303 - return getFn( 411.304 - dispatchFn.invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.305 - arg15, arg16, arg17, arg18, arg19, arg20, args)). 411.306 - invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 411.307 - arg15, arg16, arg17, arg18, arg19, arg20, args); 411.308 -} 411.309 - 411.310 - public IPersistentMap getMethodTable() { 411.311 - return methodTable; 411.312 - } 411.313 - 411.314 - public IPersistentMap getPreferTable() { 411.315 - return preferTable; 411.316 - } 411.317 -}
412.1 --- a/src/clojure/lang/Named.java Sat Aug 21 06:25:44 2010 -0400 412.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 412.3 @@ -1,19 +0,0 @@ 412.4 -/** 412.5 - * Copyright (c) Rich Hickey. All rights reserved. 412.6 - * The use and distribution terms for this software are covered by the 412.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 412.8 - * which can be found in the file epl-v10.html at the root of this distribution. 412.9 - * By using this software in any fashion, you are agreeing to be bound by 412.10 - * the terms of this license. 412.11 - * You must not remove this notice, or any other, from this software. 412.12 - **/ 412.13 - 412.14 -/* rich Sep 20, 2007 */ 412.15 - 412.16 -package clojure.lang; 412.17 - 412.18 -public interface Named{ 412.19 -String getNamespace(); 412.20 - 412.21 -String getName(); 412.22 -}
413.1 --- a/src/clojure/lang/Namespace.java Sat Aug 21 06:25:44 2010 -0400 413.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 413.3 @@ -1,243 +0,0 @@ 413.4 -/** 413.5 - * Copyright (c) Rich Hickey. All rights reserved. 413.6 - * The use and distribution terms for this software are covered by the 413.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 413.8 - * which can be found in the file epl-v10.html at the root of this distribution. 413.9 - * By using this software in any fashion, you are agreeing to be bound by 413.10 - * the terms of this license. 413.11 - * You must not remove this notice, or any other, from this software. 413.12 - **/ 413.13 - 413.14 -/* rich Jan 23, 2008 */ 413.15 - 413.16 -package clojure.lang; 413.17 - 413.18 -import java.io.ObjectStreamException; 413.19 -import java.io.Serializable; 413.20 -import java.util.concurrent.ConcurrentHashMap; 413.21 -import java.util.concurrent.atomic.AtomicReference; 413.22 - 413.23 -public class Namespace extends AReference implements Serializable { 413.24 -final public Symbol name; 413.25 -transient final AtomicReference<IPersistentMap> mappings = new AtomicReference<IPersistentMap>(); 413.26 -transient final AtomicReference<IPersistentMap> aliases = new AtomicReference<IPersistentMap>(); 413.27 - 413.28 -final static ConcurrentHashMap<Symbol, Namespace> namespaces = new ConcurrentHashMap<Symbol, Namespace>(); 413.29 - 413.30 -public String toString(){ 413.31 - return name.toString(); 413.32 -} 413.33 - 413.34 -Namespace(Symbol name){ 413.35 - super(name.meta()); 413.36 - this.name = name; 413.37 - mappings.set(RT.DEFAULT_IMPORTS); 413.38 - aliases.set(RT.map()); 413.39 -} 413.40 - 413.41 -public static ISeq all(){ 413.42 - return RT.seq(namespaces.values()); 413.43 -} 413.44 - 413.45 -public Symbol getName(){ 413.46 - return name; 413.47 -} 413.48 - 413.49 -public IPersistentMap getMappings(){ 413.50 - return mappings.get(); 413.51 -} 413.52 - 413.53 -public Var intern(Symbol sym){ 413.54 - if(sym.ns != null) 413.55 - { 413.56 - throw new IllegalArgumentException("Can't intern namespace-qualified symbol"); 413.57 - } 413.58 - IPersistentMap map = getMappings(); 413.59 - Object o; 413.60 - Var v = null; 413.61 - while((o = map.valAt(sym)) == null) 413.62 - { 413.63 - if(v == null) 413.64 - v = new Var(this, sym); 413.65 - IPersistentMap newMap = map.assoc(sym, v); 413.66 - mappings.compareAndSet(map, newMap); 413.67 - map = getMappings(); 413.68 - } 413.69 - if(o instanceof Var && ((Var) o).ns == this) 413.70 - return (Var) o; 413.71 - 413.72 - if(v == null) 413.73 - v = new Var(this, sym); 413.74 - 413.75 - warnOrFailOnReplace(sym, o, v); 413.76 - 413.77 - 413.78 - while(!mappings.compareAndSet(map, map.assoc(sym, v))) 413.79 - map = getMappings(); 413.80 - 413.81 - return v; 413.82 -} 413.83 - 413.84 -private void warnOrFailOnReplace(Symbol sym, Object o, Object v){ 413.85 - if (o instanceof Var) 413.86 - { 413.87 - Namespace ns = ((Var)o).ns; 413.88 - if (ns == this) 413.89 - return; 413.90 - if (ns != RT.CLOJURE_NS) 413.91 - throw new IllegalStateException(sym + " already refers to: " + o + " in namespace: " + name); 413.92 - } 413.93 - RT.errPrintWriter().println("WARNING: " + sym + " already refers to: " + o + " in namespace: " + name 413.94 - + ", being replaced by: " + v); 413.95 -} 413.96 - 413.97 -Object reference(Symbol sym, Object val){ 413.98 - if(sym.ns != null) 413.99 - { 413.100 - throw new IllegalArgumentException("Can't intern namespace-qualified symbol"); 413.101 - } 413.102 - IPersistentMap map = getMappings(); 413.103 - Object o; 413.104 - while((o = map.valAt(sym)) == null) 413.105 - { 413.106 - IPersistentMap newMap = map.assoc(sym, val); 413.107 - mappings.compareAndSet(map, newMap); 413.108 - map = getMappings(); 413.109 - } 413.110 - if(o == val) 413.111 - return o; 413.112 - 413.113 - warnOrFailOnReplace(sym, o, val); 413.114 - 413.115 - while(!mappings.compareAndSet(map, map.assoc(sym, val))) 413.116 - map = getMappings(); 413.117 - 413.118 - return val; 413.119 - 413.120 -} 413.121 - 413.122 -public static boolean areDifferentInstancesOfSameClassName(Class cls1, Class cls2) { 413.123 - return (cls1 != cls2) && (cls1.getName().equals(cls2.getName())); 413.124 -} 413.125 - 413.126 -Class referenceClass(Symbol sym, Class val){ 413.127 - if(sym.ns != null) 413.128 - { 413.129 - throw new IllegalArgumentException("Can't intern namespace-qualified symbol"); 413.130 - } 413.131 - IPersistentMap map = getMappings(); 413.132 - Class c = (Class) map.valAt(sym); 413.133 - while((c == null) || (areDifferentInstancesOfSameClassName(c, val))) 413.134 - { 413.135 - IPersistentMap newMap = map.assoc(sym, val); 413.136 - mappings.compareAndSet(map, newMap); 413.137 - map = getMappings(); 413.138 - c = (Class) map.valAt(sym); 413.139 - } 413.140 - if(c == val) 413.141 - return c; 413.142 - 413.143 - throw new IllegalStateException(sym + " already refers to: " + c + " in namespace: " + name); 413.144 -} 413.145 - 413.146 -public void unmap(Symbol sym) throws Exception{ 413.147 - if(sym.ns != null) 413.148 - { 413.149 - throw new IllegalArgumentException("Can't unintern namespace-qualified symbol"); 413.150 - } 413.151 - IPersistentMap map = getMappings(); 413.152 - while(map.containsKey(sym)) 413.153 - { 413.154 - IPersistentMap newMap = map.without(sym); 413.155 - mappings.compareAndSet(map, newMap); 413.156 - map = getMappings(); 413.157 - } 413.158 -} 413.159 - 413.160 -public Class importClass(Symbol sym, Class c){ 413.161 - return referenceClass(sym, c); 413.162 - 413.163 -} 413.164 - 413.165 -public Class importClass(Class c){ 413.166 - String n = c.getName(); 413.167 - return importClass(Symbol.intern(n.substring(n.lastIndexOf('.') + 1)), c); 413.168 -} 413.169 - 413.170 -public Var refer(Symbol sym, Var var){ 413.171 - return (Var) reference(sym, var); 413.172 - 413.173 -} 413.174 - 413.175 -public static Namespace findOrCreate(Symbol name){ 413.176 - Namespace ns = namespaces.get(name); 413.177 - if(ns != null) 413.178 - return ns; 413.179 - Namespace newns = new Namespace(name); 413.180 - ns = namespaces.putIfAbsent(name, newns); 413.181 - return ns == null ? newns : ns; 413.182 -} 413.183 - 413.184 -public static Namespace remove(Symbol name){ 413.185 - if(name.equals(RT.CLOJURE_NS.name)) 413.186 - throw new IllegalArgumentException("Cannot remove clojure namespace"); 413.187 - return namespaces.remove(name); 413.188 -} 413.189 - 413.190 -public static Namespace find(Symbol name){ 413.191 - return namespaces.get(name); 413.192 -} 413.193 - 413.194 -public Object getMapping(Symbol name){ 413.195 - return mappings.get().valAt(name); 413.196 -} 413.197 - 413.198 -public Var findInternedVar(Symbol symbol){ 413.199 - Object o = mappings.get().valAt(symbol); 413.200 - if(o != null && o instanceof Var && ((Var) o).ns == this) 413.201 - return (Var) o; 413.202 - return null; 413.203 -} 413.204 - 413.205 - 413.206 -public IPersistentMap getAliases(){ 413.207 - return aliases.get(); 413.208 -} 413.209 - 413.210 -public Namespace lookupAlias(Symbol alias){ 413.211 - IPersistentMap map = getAliases(); 413.212 - return (Namespace) map.valAt(alias); 413.213 -} 413.214 - 413.215 -public void addAlias(Symbol alias, Namespace ns){ 413.216 - if (alias == null || ns == null) 413.217 - throw new NullPointerException("Expecting Symbol + Namespace"); 413.218 - IPersistentMap map = getAliases(); 413.219 - while(!map.containsKey(alias)) 413.220 - { 413.221 - IPersistentMap newMap = map.assoc(alias, ns); 413.222 - aliases.compareAndSet(map, newMap); 413.223 - map = getAliases(); 413.224 - } 413.225 - // you can rebind an alias, but only to the initially-aliased namespace. 413.226 - if(!map.valAt(alias).equals(ns)) 413.227 - throw new IllegalStateException("Alias " + alias + " already exists in namespace " 413.228 - + name + ", aliasing " + map.valAt(alias)); 413.229 -} 413.230 - 413.231 -public void removeAlias(Symbol alias) throws Exception{ 413.232 - IPersistentMap map = getAliases(); 413.233 - while(map.containsKey(alias)) 413.234 - { 413.235 - IPersistentMap newMap = map.without(alias); 413.236 - aliases.compareAndSet(map, newMap); 413.237 - map = getAliases(); 413.238 - } 413.239 -} 413.240 - 413.241 -private Object readResolve() throws ObjectStreamException { 413.242 - // ensures that serialized namespaces are "deserialized" to the 413.243 - // namespace in the present runtime 413.244 - return findOrCreate(name); 413.245 -} 413.246 -}
414.1 --- a/src/clojure/lang/Numbers.java Sat Aug 21 06:25:44 2010 -0400 414.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 414.3 @@ -1,4527 +0,0 @@ 414.4 -/** 414.5 - * Copyright (c) Rich Hickey. All rights reserved. 414.6 - * The use and distribution terms for this software are covered by the 414.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 414.8 - * which can be found in the file epl-v10.html at the root of this distribution. 414.9 - * By using this software in any fashion, you are agreeing to be bound by 414.10 - * the terms of this license. 414.11 - * You must not remove this notice, or any other, from this software. 414.12 - **/ 414.13 - 414.14 -/* rich Mar 31, 2008 */ 414.15 - 414.16 -package clojure.lang; 414.17 - 414.18 -import java.math.BigInteger; 414.19 -import java.math.BigDecimal; 414.20 -import java.math.MathContext; 414.21 - 414.22 -public class Numbers{ 414.23 - 414.24 -static interface Ops{ 414.25 - Ops combine(Ops y); 414.26 - 414.27 - Ops opsWith(IntegerOps x); 414.28 - 414.29 - Ops opsWith(LongOps x); 414.30 - 414.31 - Ops opsWith(FloatOps x); 414.32 - 414.33 - Ops opsWith(DoubleOps x); 414.34 - 414.35 - Ops opsWith(RatioOps x); 414.36 - 414.37 - Ops opsWith(BigIntegerOps x); 414.38 - 414.39 - Ops opsWith(BigDecimalOps x); 414.40 - 414.41 - public boolean isZero(Number x); 414.42 - 414.43 - public boolean isPos(Number x); 414.44 - 414.45 - public boolean isNeg(Number x); 414.46 - 414.47 - public Number add(Number x, Number y); 414.48 - 414.49 - public Number multiply(Number x, Number y); 414.50 - 414.51 - public Number divide(Number x, Number y); 414.52 - 414.53 - public Number quotient(Number x, Number y); 414.54 - 414.55 - public Number remainder(Number x, Number y); 414.56 - 414.57 - public boolean equiv(Number x, Number y); 414.58 - 414.59 - public boolean lt(Number x, Number y); 414.60 - 414.61 - public Number negate(Number x); 414.62 - 414.63 - public Number inc(Number x); 414.64 - 414.65 - public Number dec(Number x); 414.66 -} 414.67 - 414.68 -static interface BitOps{ 414.69 - BitOps combine(BitOps y); 414.70 - 414.71 - BitOps bitOpsWith(IntegerBitOps x); 414.72 - 414.73 - BitOps bitOpsWith(LongBitOps x); 414.74 - 414.75 - BitOps bitOpsWith(BigIntegerBitOps x); 414.76 - 414.77 - public Number not(Number x); 414.78 - 414.79 - public Number and(Number x, Number y); 414.80 - 414.81 - public Number or(Number x, Number y); 414.82 - 414.83 - public Number xor(Number x, Number y); 414.84 - 414.85 - public Number andNot(Number x, Number y); 414.86 - 414.87 - public Number clearBit(Number x, int n); 414.88 - 414.89 - public Number setBit(Number x, int n); 414.90 - 414.91 - public Number flipBit(Number x, int n); 414.92 - 414.93 - public boolean testBit(Number x, int n); 414.94 - 414.95 - public Number shiftLeft(Number x, int n); 414.96 - 414.97 - public Number shiftRight(Number x, int n); 414.98 -} 414.99 - 414.100 - 414.101 -static public boolean isZero(Object x){ 414.102 - return ops(x).isZero((Number)x); 414.103 -} 414.104 - 414.105 -static public boolean isPos(Object x){ 414.106 - return ops(x).isPos((Number)x); 414.107 -} 414.108 - 414.109 -static public boolean isNeg(Object x){ 414.110 - return ops(x).isNeg((Number)x); 414.111 -} 414.112 - 414.113 -static public Number minus(Object x){ 414.114 - return ops(x).negate((Number)x); 414.115 -} 414.116 - 414.117 -static public Number inc(Object x){ 414.118 - return ops(x).inc((Number)x); 414.119 -} 414.120 - 414.121 -static public Number dec(Object x){ 414.122 - return ops(x).dec((Number)x); 414.123 -} 414.124 - 414.125 -static public Number add(Object x, Object y){ 414.126 - return ops(x).combine(ops(y)).add((Number)x, (Number)y); 414.127 -} 414.128 - 414.129 -static public Number minus(Object x, Object y){ 414.130 - Ops yops = ops(y); 414.131 - return ops(x).combine(yops).add((Number)x, yops.negate((Number)y)); 414.132 -} 414.133 - 414.134 -static public Number multiply(Object x, Object y){ 414.135 - return ops(x).combine(ops(y)).multiply((Number)x, (Number)y); 414.136 -} 414.137 - 414.138 -static public Number divide(Object x, Object y){ 414.139 - Ops yops = ops(y); 414.140 - if(yops.isZero((Number)y)) 414.141 - throw new ArithmeticException("Divide by zero"); 414.142 - return ops(x).combine(yops).divide((Number)x, (Number)y); 414.143 -} 414.144 - 414.145 -static public Number quotient(Number x, Number y){ 414.146 - Ops yops = ops(y); 414.147 - if(yops.isZero(y)) 414.148 - throw new ArithmeticException("Divide by zero"); 414.149 - return reduce(ops(x).combine(yops).quotient(x, y)); 414.150 -} 414.151 - 414.152 -static public Number remainder(Number x, Number y){ 414.153 - Ops yops = ops(y); 414.154 - if(yops.isZero(y)) 414.155 - throw new ArithmeticException("Divide by zero"); 414.156 - return reduce(ops(x).combine(yops).remainder(x, y)); 414.157 -} 414.158 - 414.159 -static Number quotient(double n, double d){ 414.160 - double q = n / d; 414.161 - if(q <= Integer.MAX_VALUE && q >= Integer.MIN_VALUE) 414.162 - { 414.163 - return (int) q; 414.164 - } 414.165 - else 414.166 - { //bigint quotient 414.167 - return reduce(new BigDecimal(q).toBigInteger()); 414.168 - } 414.169 -} 414.170 - 414.171 -static Number remainder(double n, double d){ 414.172 - double q = n / d; 414.173 - if(q <= Integer.MAX_VALUE && q >= Integer.MIN_VALUE) 414.174 - { 414.175 - return (n - ((int) q) * d); 414.176 - } 414.177 - else 414.178 - { //bigint quotient 414.179 - Number bq = reduce(new BigDecimal(q).toBigInteger()); 414.180 - return (n - bq.doubleValue() * d); 414.181 - } 414.182 -} 414.183 - 414.184 -static public boolean equiv(Object x, Object y){ 414.185 - return equiv((Number) x, (Number) y); 414.186 -} 414.187 - 414.188 -static public boolean equiv(Number x, Number y){ 414.189 - return ops(x).combine(ops(y)).equiv(x, y); 414.190 -} 414.191 - 414.192 -static public boolean lt(Object x, Object y){ 414.193 - return ops(x).combine(ops(y)).lt((Number)x, (Number)y); 414.194 -} 414.195 - 414.196 -static public boolean lte(Object x, Object y){ 414.197 - return !ops(x).combine(ops(y)).lt((Number)y, (Number)x); 414.198 -} 414.199 - 414.200 -static public boolean gt(Object x, Object y){ 414.201 - return ops(x).combine(ops(y)).lt((Number)y, (Number)x); 414.202 -} 414.203 - 414.204 -static public boolean gte(Object x, Object y){ 414.205 - return !ops(x).combine(ops(y)).lt((Number)x, (Number)y); 414.206 -} 414.207 - 414.208 -static public int compare(Number x, Number y){ 414.209 - Ops ops = ops(x).combine(ops(y)); 414.210 - if(ops.lt(x, y)) 414.211 - return -1; 414.212 - else if(ops.lt(y, x)) 414.213 - return 1; 414.214 - return 0; 414.215 -} 414.216 - 414.217 -static BigInteger toBigInteger(Object x){ 414.218 - if(x instanceof BigInteger) 414.219 - return (BigInteger) x; 414.220 - else 414.221 - return BigInteger.valueOf(((Number) x).longValue()); 414.222 -} 414.223 - 414.224 -static BigDecimal toBigDecimal(Object x){ 414.225 - if(x instanceof BigDecimal) 414.226 - return (BigDecimal) x; 414.227 - else if(x instanceof BigInteger) 414.228 - return new BigDecimal((BigInteger) x); 414.229 - else 414.230 - return BigDecimal.valueOf(((Number) x).longValue()); 414.231 -} 414.232 - 414.233 -static Ratio toRatio(Object x){ 414.234 - if(x instanceof Ratio) 414.235 - return (Ratio) x; 414.236 - else if(x instanceof BigDecimal) 414.237 - { 414.238 - BigDecimal bx = (BigDecimal) x; 414.239 - BigInteger bv = bx.unscaledValue(); 414.240 - int scale = bx.scale(); 414.241 - if(scale < 0) 414.242 - return new Ratio(bv.multiply(BigInteger.TEN.pow(-scale)), BigInteger.ONE); 414.243 - else 414.244 - return new Ratio(bv, BigInteger.TEN.pow(scale)); 414.245 - } 414.246 - return new Ratio(toBigInteger(x), BigInteger.ONE); 414.247 -} 414.248 - 414.249 -static public Number rationalize(Number x){ 414.250 - if(x instanceof Float || x instanceof Double) 414.251 - return rationalize(BigDecimal.valueOf(x.doubleValue())); 414.252 - else if(x instanceof BigDecimal) 414.253 - { 414.254 - BigDecimal bx = (BigDecimal) x; 414.255 - BigInteger bv = bx.unscaledValue(); 414.256 - int scale = bx.scale(); 414.257 - if(scale < 0) 414.258 - return bv.multiply(BigInteger.TEN.pow(-scale)); 414.259 - else 414.260 - return divide(bv, BigInteger.TEN.pow(scale)); 414.261 - } 414.262 - return x; 414.263 -} 414.264 - 414.265 -static public Number reduce(Number val){ 414.266 - if(val instanceof Long) 414.267 - return reduce(val.longValue()); 414.268 - else if (val instanceof BigInteger) 414.269 - return reduce((BigInteger) val); 414.270 - return val; 414.271 -} 414.272 - 414.273 -static public Number reduce(BigInteger val){ 414.274 - int bitLength = val.bitLength(); 414.275 - if(bitLength < 32) 414.276 - return val.intValue(); 414.277 - else if(bitLength < 64) 414.278 - return val.longValue(); 414.279 - else 414.280 - return val; 414.281 -} 414.282 - 414.283 -static public Number reduce(long val){ 414.284 - if(val >= Integer.MIN_VALUE && val <= Integer.MAX_VALUE) 414.285 - return (int) val; 414.286 - else 414.287 - return val; 414.288 -} 414.289 - 414.290 -static public Number divide(BigInteger n, BigInteger d){ 414.291 - if(d.equals(BigInteger.ZERO)) 414.292 - throw new ArithmeticException("Divide by zero"); 414.293 - BigInteger gcd = n.gcd(d); 414.294 - if(gcd.equals(BigInteger.ZERO)) 414.295 - return 0; 414.296 - n = n.divide(gcd); 414.297 - d = d.divide(gcd); 414.298 - if(d.equals(BigInteger.ONE)) 414.299 - return reduce(n); 414.300 - else if(d.equals(BigInteger.ONE.negate())) 414.301 - return reduce(n.negate()); 414.302 - return new Ratio((d.signum() < 0 ? n.negate() : n), 414.303 - (d.signum() < 0 ? d.negate() : d)); 414.304 -} 414.305 - 414.306 -static public Number not(Object x){ 414.307 - return bitOps(x).not((Number)x); 414.308 -} 414.309 - 414.310 - 414.311 -static public Number and(Object x, Object y){ 414.312 - return bitOps(x).combine(bitOps(y)).and((Number)x, (Number)y); 414.313 -} 414.314 - 414.315 -static public Number or(Object x, Object y){ 414.316 - return bitOps(x).combine(bitOps(y)).or((Number)x, (Number)y); 414.317 -} 414.318 - 414.319 -static public Number xor(Object x, Object y){ 414.320 - return bitOps(x).combine(bitOps(y)).xor((Number)x, (Number)y); 414.321 -} 414.322 - 414.323 -static public Number andNot(Number x, Number y){ 414.324 - return bitOps(x).combine(bitOps(y)).andNot(x, y); 414.325 -} 414.326 - 414.327 -static public Number clearBit(Number x, int n){ 414.328 - if(n < 0) 414.329 - throw new ArithmeticException("Negative bit index"); 414.330 - return bitOps(x).clearBit(x, n); 414.331 -} 414.332 - 414.333 -static public Number setBit(Number x, int n){ 414.334 - if(n < 0) 414.335 - throw new ArithmeticException("Negative bit index"); 414.336 - return bitOps(x).setBit(x, n); 414.337 -} 414.338 - 414.339 -static public Number flipBit(Number x, int n){ 414.340 - if(n < 0) 414.341 - throw new ArithmeticException("Negative bit index"); 414.342 - return bitOps(x).flipBit(x, n); 414.343 -} 414.344 - 414.345 -static public boolean testBit(Number x, int n){ 414.346 - if(n < 0) 414.347 - throw new ArithmeticException("Negative bit index"); 414.348 - return bitOps(x).testBit(x, n); 414.349 -} 414.350 - 414.351 -static public Number shiftLeft(Object x, Object n){ 414.352 - return bitOps(x).shiftLeft((Number)x, ((Number)n).intValue()); 414.353 -} 414.354 - 414.355 -static public int shiftLeft(int x, int n){ 414.356 - return x << n; 414.357 -} 414.358 - 414.359 -static public Number shiftRight(Object x, Object n){ 414.360 - return bitOps(x).shiftRight((Number)x, ((Number)n).intValue()); 414.361 -} 414.362 - 414.363 -static public int shiftRight(int x, int n){ 414.364 - return x >> n; 414.365 -} 414.366 - 414.367 -final static class IntegerOps implements Ops{ 414.368 - public Ops combine(Ops y){ 414.369 - return y.opsWith(this); 414.370 - } 414.371 - 414.372 - final public Ops opsWith(IntegerOps x){ 414.373 - return this; 414.374 - } 414.375 - 414.376 - final public Ops opsWith(LongOps x){ 414.377 - return LONG_OPS; 414.378 - } 414.379 - 414.380 - final public Ops opsWith(FloatOps x){ 414.381 - return FLOAT_OPS; 414.382 - } 414.383 - 414.384 - final public Ops opsWith(DoubleOps x){ 414.385 - return DOUBLE_OPS; 414.386 - } 414.387 - 414.388 - final public Ops opsWith(RatioOps x){ 414.389 - return RATIO_OPS; 414.390 - } 414.391 - 414.392 - final public Ops opsWith(BigIntegerOps x){ 414.393 - return BIGINTEGER_OPS; 414.394 - } 414.395 - 414.396 - final public Ops opsWith(BigDecimalOps x){ 414.397 - return BIGDECIMAL_OPS; 414.398 - } 414.399 - 414.400 - public boolean isZero(Number x){ 414.401 - return x.intValue() == 0; 414.402 - } 414.403 - 414.404 - public boolean isPos(Number x){ 414.405 - return x.intValue() > 0; 414.406 - } 414.407 - 414.408 - public boolean isNeg(Number x){ 414.409 - return x.intValue() < 0; 414.410 - } 414.411 - 414.412 - final public Number add(Number x, Number y){ 414.413 - long ret = x.longValue() + y.longValue(); 414.414 - if(ret <= Integer.MAX_VALUE && ret >= Integer.MIN_VALUE) 414.415 - return (int) ret; 414.416 - return ret; 414.417 - } 414.418 - 414.419 - final public Number multiply(Number x, Number y){ 414.420 - long ret = x.longValue() * y.longValue(); 414.421 - if(ret <= Integer.MAX_VALUE && ret >= Integer.MIN_VALUE) 414.422 - return (int) ret; 414.423 - return ret; 414.424 - } 414.425 - 414.426 - static int gcd(int u, int v){ 414.427 - while(v != 0) 414.428 - { 414.429 - int r = u % v; 414.430 - u = v; 414.431 - v = r; 414.432 - } 414.433 - return u; 414.434 - } 414.435 - 414.436 - public Number divide(Number x, Number y){ 414.437 - int n = x.intValue(); 414.438 - int val = y.intValue(); 414.439 - int gcd = gcd(n, val); 414.440 - if(gcd == 0) 414.441 - return 0; 414.442 - 414.443 - n = n / gcd; 414.444 - int d = val / gcd; 414.445 - if(d == 1) 414.446 - return n; 414.447 - if(d < 0) 414.448 - { 414.449 - n = -n; 414.450 - d = -d; 414.451 - } 414.452 - return new Ratio(BigInteger.valueOf(n), BigInteger.valueOf(d)); 414.453 - } 414.454 - 414.455 - public Number quotient(Number x, Number y){ 414.456 - return x.intValue() / y.intValue(); 414.457 - } 414.458 - 414.459 - public Number remainder(Number x, Number y){ 414.460 - return x.intValue() % y.intValue(); 414.461 - } 414.462 - 414.463 - public boolean equiv(Number x, Number y){ 414.464 - return x.intValue() == y.intValue(); 414.465 - } 414.466 - 414.467 - public boolean lt(Number x, Number y){ 414.468 - return x.intValue() < y.intValue(); 414.469 - } 414.470 - 414.471 - //public Number subtract(Number x, Number y); 414.472 - final public Number negate(Number x){ 414.473 - int val = x.intValue(); 414.474 - if(val > Integer.MIN_VALUE) 414.475 - return -val; 414.476 - return -((long) val); 414.477 - } 414.478 - 414.479 - public Number inc(Number x){ 414.480 - int val = x.intValue(); 414.481 - if(val < Integer.MAX_VALUE) 414.482 - return val + 1; 414.483 - return (long) val + 1; 414.484 - } 414.485 - 414.486 - public Number dec(Number x){ 414.487 - int val = x.intValue(); 414.488 - if(val > Integer.MIN_VALUE) 414.489 - return val - 1; 414.490 - return (long) val - 1; 414.491 - } 414.492 -} 414.493 - 414.494 -final static class LongOps implements Ops{ 414.495 - public Ops combine(Ops y){ 414.496 - return y.opsWith(this); 414.497 - } 414.498 - 414.499 - final public Ops opsWith(IntegerOps x){ 414.500 - return this; 414.501 - } 414.502 - 414.503 - final public Ops opsWith(LongOps x){ 414.504 - return this; 414.505 - } 414.506 - 414.507 - final public Ops opsWith(FloatOps x){ 414.508 - return FLOAT_OPS; 414.509 - } 414.510 - 414.511 - final public Ops opsWith(DoubleOps x){ 414.512 - return DOUBLE_OPS; 414.513 - } 414.514 - 414.515 - final public Ops opsWith(RatioOps x){ 414.516 - return RATIO_OPS; 414.517 - } 414.518 - 414.519 - final public Ops opsWith(BigIntegerOps x){ 414.520 - return BIGINTEGER_OPS; 414.521 - } 414.522 - 414.523 - final public Ops opsWith(BigDecimalOps x){ 414.524 - return BIGDECIMAL_OPS; 414.525 - } 414.526 - 414.527 - public boolean isZero(Number x){ 414.528 - return x.longValue() == 0; 414.529 - } 414.530 - 414.531 - public boolean isPos(Number x){ 414.532 - return x.longValue() > 0; 414.533 - } 414.534 - 414.535 - public boolean isNeg(Number x){ 414.536 - return x.longValue() < 0; 414.537 - } 414.538 - 414.539 - final public Number add(Number x, Number y){ 414.540 - long lx = x.longValue(), ly = y.longValue(); 414.541 - long ret = lx + ly; 414.542 - if ((ret ^ lx) < 0 && (ret ^ ly) < 0) 414.543 - return BIGINTEGER_OPS.add(x, y); 414.544 - return ret; 414.545 - } 414.546 - 414.547 - final public Number multiply(Number x, Number y){ 414.548 - long lx = x.longValue(), ly = y.longValue(); 414.549 - long ret = lx * ly; 414.550 - if (ly != 0 && ret/ly != lx) 414.551 - return BIGINTEGER_OPS.multiply(x, y); 414.552 - return ret; 414.553 - } 414.554 - 414.555 - static long gcd(long u, long v){ 414.556 - while(v != 0) 414.557 - { 414.558 - long r = u % v; 414.559 - u = v; 414.560 - v = r; 414.561 - } 414.562 - return u; 414.563 - } 414.564 - 414.565 - public Number divide(Number x, Number y){ 414.566 - long n = x.longValue(); 414.567 - long val = y.longValue(); 414.568 - long gcd = gcd(n, val); 414.569 - if(gcd == 0) 414.570 - return 0; 414.571 - 414.572 - n = n / gcd; 414.573 - long d = val / gcd; 414.574 - if(d == 1) 414.575 - return n; 414.576 - if(d < 0) 414.577 - { 414.578 - n = -n; 414.579 - d = -d; 414.580 - } 414.581 - return new Ratio(BigInteger.valueOf(n), BigInteger.valueOf(d)); 414.582 - } 414.583 - 414.584 - public Number quotient(Number x, Number y){ 414.585 - return x.longValue() / y.longValue(); 414.586 - } 414.587 - 414.588 - public Number remainder(Number x, Number y){ 414.589 - return x.longValue() % y.longValue(); 414.590 - } 414.591 - 414.592 - public boolean equiv(Number x, Number y){ 414.593 - return x.longValue() == y.longValue(); 414.594 - } 414.595 - 414.596 - public boolean lt(Number x, Number y){ 414.597 - return x.longValue() < y.longValue(); 414.598 - } 414.599 - 414.600 - //public Number subtract(Number x, Number y); 414.601 - final public Number negate(Number x){ 414.602 - long val = x.longValue(); 414.603 - if(val > Long.MIN_VALUE) 414.604 - return -val; 414.605 - return BigInteger.valueOf(val).negate(); 414.606 - } 414.607 - 414.608 - public Number inc(Number x){ 414.609 - long val = x.longValue(); 414.610 - if(val < Long.MAX_VALUE) 414.611 - return val + 1; 414.612 - return BIGINTEGER_OPS.inc(x); 414.613 - } 414.614 - 414.615 - public Number dec(Number x){ 414.616 - long val = x.longValue(); 414.617 - if(val > Long.MIN_VALUE) 414.618 - return val - 1; 414.619 - return BIGINTEGER_OPS.dec(x); 414.620 - } 414.621 -} 414.622 - 414.623 -final static class FloatOps implements Ops{ 414.624 - public Ops combine(Ops y){ 414.625 - return y.opsWith(this); 414.626 - } 414.627 - 414.628 - final public Ops opsWith(IntegerOps x){ 414.629 - return this; 414.630 - } 414.631 - 414.632 - final public Ops opsWith(LongOps x){ 414.633 - return this; 414.634 - } 414.635 - 414.636 - final public Ops opsWith(FloatOps x){ 414.637 - return this; 414.638 - } 414.639 - 414.640 - final public Ops opsWith(DoubleOps x){ 414.641 - return DOUBLE_OPS; 414.642 - } 414.643 - 414.644 - final public Ops opsWith(RatioOps x){ 414.645 - return this; 414.646 - } 414.647 - 414.648 - final public Ops opsWith(BigIntegerOps x){ 414.649 - return this; 414.650 - } 414.651 - 414.652 - final public Ops opsWith(BigDecimalOps x){ 414.653 - return this; 414.654 - } 414.655 - 414.656 - public boolean isZero(Number x){ 414.657 - return x.floatValue() == 0; 414.658 - } 414.659 - 414.660 - public boolean isPos(Number x){ 414.661 - return x.floatValue() > 0; 414.662 - } 414.663 - 414.664 - public boolean isNeg(Number x){ 414.665 - return x.floatValue() < 0; 414.666 - } 414.667 - 414.668 - final public Number add(Number x, Number y){ 414.669 - return x.floatValue() + y.floatValue(); 414.670 - } 414.671 - 414.672 - final public Number multiply(Number x, Number y){ 414.673 - return x.floatValue() * y.floatValue(); 414.674 - } 414.675 - 414.676 - public Number divide(Number x, Number y){ 414.677 - return x.floatValue() / y.floatValue(); 414.678 - } 414.679 - 414.680 - public Number quotient(Number x, Number y){ 414.681 - return Numbers.quotient(x.doubleValue(), y.doubleValue()); 414.682 - } 414.683 - 414.684 - public Number remainder(Number x, Number y){ 414.685 - return Numbers.remainder(x.doubleValue(), y.doubleValue()); 414.686 - } 414.687 - 414.688 - public boolean equiv(Number x, Number y){ 414.689 - return x.floatValue() == y.floatValue(); 414.690 - } 414.691 - 414.692 - public boolean lt(Number x, Number y){ 414.693 - return x.floatValue() < y.floatValue(); 414.694 - } 414.695 - 414.696 - //public Number subtract(Number x, Number y); 414.697 - final public Number negate(Number x){ 414.698 - return -x.floatValue(); 414.699 - } 414.700 - 414.701 - public Number inc(Number x){ 414.702 - return x.floatValue() + 1; 414.703 - } 414.704 - 414.705 - public Number dec(Number x){ 414.706 - return x.floatValue() - 1; 414.707 - } 414.708 -} 414.709 - 414.710 -final static class DoubleOps implements Ops{ 414.711 - public Ops combine(Ops y){ 414.712 - return y.opsWith(this); 414.713 - } 414.714 - 414.715 - final public Ops opsWith(IntegerOps x){ 414.716 - return this; 414.717 - } 414.718 - 414.719 - final public Ops opsWith(LongOps x){ 414.720 - return this; 414.721 - } 414.722 - 414.723 - final public Ops opsWith(FloatOps x){ 414.724 - return this; 414.725 - } 414.726 - 414.727 - final public Ops opsWith(DoubleOps x){ 414.728 - return this; 414.729 - } 414.730 - 414.731 - final public Ops opsWith(RatioOps x){ 414.732 - return this; 414.733 - } 414.734 - 414.735 - final public Ops opsWith(BigIntegerOps x){ 414.736 - return this; 414.737 - } 414.738 - 414.739 - final public Ops opsWith(BigDecimalOps x){ 414.740 - return this; 414.741 - } 414.742 - 414.743 - public boolean isZero(Number x){ 414.744 - return x.doubleValue() == 0; 414.745 - } 414.746 - 414.747 - public boolean isPos(Number x){ 414.748 - return x.doubleValue() > 0; 414.749 - } 414.750 - 414.751 - public boolean isNeg(Number x){ 414.752 - return x.doubleValue() < 0; 414.753 - } 414.754 - 414.755 - final public Number add(Number x, Number y){ 414.756 - return x.doubleValue() + y.doubleValue(); 414.757 - } 414.758 - 414.759 - final public Number multiply(Number x, Number y){ 414.760 - return x.doubleValue() * y.doubleValue(); 414.761 - } 414.762 - 414.763 - public Number divide(Number x, Number y){ 414.764 - return x.doubleValue() / y.doubleValue(); 414.765 - } 414.766 - 414.767 - public Number quotient(Number x, Number y){ 414.768 - return Numbers.quotient(x.doubleValue(), y.doubleValue()); 414.769 - } 414.770 - 414.771 - public Number remainder(Number x, Number y){ 414.772 - return Numbers.remainder(x.doubleValue(), y.doubleValue()); 414.773 - } 414.774 - 414.775 - public boolean equiv(Number x, Number y){ 414.776 - return x.doubleValue() == y.doubleValue(); 414.777 - } 414.778 - 414.779 - public boolean lt(Number x, Number y){ 414.780 - return x.doubleValue() < y.doubleValue(); 414.781 - } 414.782 - 414.783 - //public Number subtract(Number x, Number y); 414.784 - final public Number negate(Number x){ 414.785 - return -x.doubleValue(); 414.786 - } 414.787 - 414.788 - public Number inc(Number x){ 414.789 - return x.doubleValue() + 1; 414.790 - } 414.791 - 414.792 - public Number dec(Number x){ 414.793 - return x.doubleValue() - 1; 414.794 - } 414.795 -} 414.796 - 414.797 -final static class RatioOps implements Ops{ 414.798 - public Ops combine(Ops y){ 414.799 - return y.opsWith(this); 414.800 - } 414.801 - 414.802 - final public Ops opsWith(IntegerOps x){ 414.803 - return this; 414.804 - } 414.805 - 414.806 - final public Ops opsWith(LongOps x){ 414.807 - return this; 414.808 - } 414.809 - 414.810 - final public Ops opsWith(FloatOps x){ 414.811 - return FLOAT_OPS; 414.812 - } 414.813 - 414.814 - final public Ops opsWith(DoubleOps x){ 414.815 - return DOUBLE_OPS; 414.816 - } 414.817 - 414.818 - final public Ops opsWith(RatioOps x){ 414.819 - return this; 414.820 - } 414.821 - 414.822 - final public Ops opsWith(BigIntegerOps x){ 414.823 - return this; 414.824 - } 414.825 - 414.826 - final public Ops opsWith(BigDecimalOps x){ 414.827 - return this; 414.828 - } 414.829 - 414.830 - public boolean isZero(Number x){ 414.831 - Ratio r = (Ratio) x; 414.832 - return r.numerator.signum() == 0; 414.833 - } 414.834 - 414.835 - public boolean isPos(Number x){ 414.836 - Ratio r = (Ratio) x; 414.837 - return r.numerator.signum() > 0; 414.838 - } 414.839 - 414.840 - public boolean isNeg(Number x){ 414.841 - Ratio r = (Ratio) x; 414.842 - return r.numerator.signum() < 0; 414.843 - } 414.844 - 414.845 - final public Number add(Number x, Number y){ 414.846 - Ratio rx = toRatio(x); 414.847 - Ratio ry = toRatio(y); 414.848 - return divide(ry.numerator.multiply(rx.denominator) 414.849 - .add(rx.numerator.multiply(ry.denominator)) 414.850 - , ry.denominator.multiply(rx.denominator)); 414.851 - } 414.852 - 414.853 - final public Number multiply(Number x, Number y){ 414.854 - Ratio rx = toRatio(x); 414.855 - Ratio ry = toRatio(y); 414.856 - return Numbers.divide(ry.numerator.multiply(rx.numerator) 414.857 - , ry.denominator.multiply(rx.denominator)); 414.858 - } 414.859 - 414.860 - public Number divide(Number x, Number y){ 414.861 - Ratio rx = toRatio(x); 414.862 - Ratio ry = toRatio(y); 414.863 - return Numbers.divide(ry.denominator.multiply(rx.numerator) 414.864 - , ry.numerator.multiply(rx.denominator)); 414.865 - } 414.866 - 414.867 - public Number quotient(Number x, Number y){ 414.868 - Ratio rx = toRatio(x); 414.869 - Ratio ry = toRatio(y); 414.870 - BigInteger q = rx.numerator.multiply(ry.denominator).divide( 414.871 - rx.denominator.multiply(ry.numerator)); 414.872 - return reduce(q); 414.873 - } 414.874 - 414.875 - public Number remainder(Number x, Number y){ 414.876 - Ratio rx = toRatio(x); 414.877 - Ratio ry = toRatio(y); 414.878 - BigInteger q = rx.numerator.multiply(ry.denominator).divide( 414.879 - rx.denominator.multiply(ry.numerator)); 414.880 - return Numbers.minus(x, Numbers.multiply(q, y)); 414.881 - } 414.882 - 414.883 - public boolean equiv(Number x, Number y){ 414.884 - Ratio rx = toRatio(x); 414.885 - Ratio ry = toRatio(y); 414.886 - return rx.numerator.equals(ry.numerator) 414.887 - && rx.denominator.equals(ry.denominator); 414.888 - } 414.889 - 414.890 - public boolean lt(Number x, Number y){ 414.891 - Ratio rx = toRatio(x); 414.892 - Ratio ry = toRatio(y); 414.893 - return Numbers.lt(rx.numerator.multiply(ry.denominator), ry.numerator.multiply(rx.denominator)); 414.894 - } 414.895 - 414.896 - //public Number subtract(Number x, Number y); 414.897 - final public Number negate(Number x){ 414.898 - Ratio r = (Ratio) x; 414.899 - return new Ratio(r.numerator.negate(), r.denominator); 414.900 - } 414.901 - 414.902 - public Number inc(Number x){ 414.903 - return Numbers.add(x, 1); 414.904 - } 414.905 - 414.906 - public Number dec(Number x){ 414.907 - return Numbers.add(x, -1); 414.908 - } 414.909 - 414.910 -} 414.911 - 414.912 -final static class BigIntegerOps implements Ops{ 414.913 - public Ops combine(Ops y){ 414.914 - return y.opsWith(this); 414.915 - } 414.916 - 414.917 - final public Ops opsWith(IntegerOps x){ 414.918 - return this; 414.919 - } 414.920 - 414.921 - final public Ops opsWith(LongOps x){ 414.922 - return this; 414.923 - } 414.924 - 414.925 - final public Ops opsWith(FloatOps x){ 414.926 - return FLOAT_OPS; 414.927 - } 414.928 - 414.929 - final public Ops opsWith(DoubleOps x){ 414.930 - return DOUBLE_OPS; 414.931 - } 414.932 - 414.933 - final public Ops opsWith(RatioOps x){ 414.934 - return RATIO_OPS; 414.935 - } 414.936 - 414.937 - final public Ops opsWith(BigIntegerOps x){ 414.938 - return this; 414.939 - } 414.940 - 414.941 - final public Ops opsWith(BigDecimalOps x){ 414.942 - return BIGDECIMAL_OPS; 414.943 - } 414.944 - 414.945 - public boolean isZero(Number x){ 414.946 - BigInteger bx = toBigInteger(x); 414.947 - return bx.signum() == 0; 414.948 - } 414.949 - 414.950 - public boolean isPos(Number x){ 414.951 - BigInteger bx = toBigInteger(x); 414.952 - return bx.signum() > 0; 414.953 - } 414.954 - 414.955 - public boolean isNeg(Number x){ 414.956 - BigInteger bx = toBigInteger(x); 414.957 - return bx.signum() < 0; 414.958 - } 414.959 - 414.960 - final public Number add(Number x, Number y){ 414.961 - return reduce(toBigInteger(x).add(toBigInteger(y))); 414.962 - } 414.963 - 414.964 - final public Number multiply(Number x, Number y){ 414.965 - return reduce(toBigInteger(x).multiply(toBigInteger(y))); 414.966 - } 414.967 - 414.968 - public Number divide(Number x, Number y){ 414.969 - return Numbers.divide(toBigInteger(x), toBigInteger(y)); 414.970 - } 414.971 - 414.972 - public Number quotient(Number x, Number y){ 414.973 - return toBigInteger(x).divide(toBigInteger(y)); 414.974 - } 414.975 - 414.976 - public Number remainder(Number x, Number y){ 414.977 - return toBigInteger(x).remainder(toBigInteger(y)); 414.978 - } 414.979 - 414.980 - public boolean equiv(Number x, Number y){ 414.981 - return toBigInteger(x).equals(toBigInteger(y)); 414.982 - } 414.983 - 414.984 - public boolean lt(Number x, Number y){ 414.985 - return toBigInteger(x).compareTo(toBigInteger(y)) < 0; 414.986 - } 414.987 - 414.988 - //public Number subtract(Number x, Number y); 414.989 - final public Number negate(Number x){ 414.990 - return toBigInteger(x).negate(); 414.991 - } 414.992 - 414.993 - public Number inc(Number x){ 414.994 - BigInteger bx = toBigInteger(x); 414.995 - return reduce(bx.add(BigInteger.ONE)); 414.996 - } 414.997 - 414.998 - public Number dec(Number x){ 414.999 - BigInteger bx = toBigInteger(x); 414.1000 - return reduce(bx.subtract(BigInteger.ONE)); 414.1001 - } 414.1002 -} 414.1003 - 414.1004 -final static class BigDecimalOps implements Ops{ 414.1005 - final static Var MATH_CONTEXT = RT.MATH_CONTEXT; 414.1006 - 414.1007 - public Ops combine(Ops y){ 414.1008 - return y.opsWith(this); 414.1009 - } 414.1010 - 414.1011 - final public Ops opsWith(IntegerOps x){ 414.1012 - return this; 414.1013 - } 414.1014 - 414.1015 - final public Ops opsWith(LongOps x){ 414.1016 - return this; 414.1017 - } 414.1018 - 414.1019 - final public Ops opsWith(FloatOps x){ 414.1020 - return FLOAT_OPS; 414.1021 - } 414.1022 - 414.1023 - final public Ops opsWith(DoubleOps x){ 414.1024 - return DOUBLE_OPS; 414.1025 - } 414.1026 - 414.1027 - final public Ops opsWith(RatioOps x){ 414.1028 - return RATIO_OPS; 414.1029 - } 414.1030 - 414.1031 - final public Ops opsWith(BigIntegerOps x){ 414.1032 - return this; 414.1033 - } 414.1034 - 414.1035 - final public Ops opsWith(BigDecimalOps x){ 414.1036 - return this; 414.1037 - } 414.1038 - 414.1039 - public boolean isZero(Number x){ 414.1040 - BigDecimal bx = (BigDecimal) x; 414.1041 - return bx.signum() == 0; 414.1042 - } 414.1043 - 414.1044 - public boolean isPos(Number x){ 414.1045 - BigDecimal bx = (BigDecimal) x; 414.1046 - return bx.signum() > 0; 414.1047 - } 414.1048 - 414.1049 - public boolean isNeg(Number x){ 414.1050 - BigDecimal bx = (BigDecimal) x; 414.1051 - return bx.signum() < 0; 414.1052 - } 414.1053 - 414.1054 - final public Number add(Number x, Number y){ 414.1055 - MathContext mc = (MathContext) MATH_CONTEXT.deref(); 414.1056 - return mc == null 414.1057 - ? toBigDecimal(x).add(toBigDecimal(y)) 414.1058 - : toBigDecimal(x).add(toBigDecimal(y), mc); 414.1059 - } 414.1060 - 414.1061 - final public Number multiply(Number x, Number y){ 414.1062 - MathContext mc = (MathContext) MATH_CONTEXT.deref(); 414.1063 - return mc == null 414.1064 - ? toBigDecimal(x).multiply(toBigDecimal(y)) 414.1065 - : toBigDecimal(x).multiply(toBigDecimal(y), mc); 414.1066 - } 414.1067 - 414.1068 - public Number divide(Number x, Number y){ 414.1069 - MathContext mc = (MathContext) MATH_CONTEXT.deref(); 414.1070 - return mc == null 414.1071 - ? toBigDecimal(x).divide(toBigDecimal(y)) 414.1072 - : toBigDecimal(x).divide(toBigDecimal(y), mc); 414.1073 - } 414.1074 - 414.1075 - public Number quotient(Number x, Number y){ 414.1076 - MathContext mc = (MathContext) MATH_CONTEXT.deref(); 414.1077 - return mc == null 414.1078 - ? toBigDecimal(x).divideToIntegralValue(toBigDecimal(y)) 414.1079 - : toBigDecimal(x).divideToIntegralValue(toBigDecimal(y), mc); 414.1080 - } 414.1081 - 414.1082 - public Number remainder(Number x, Number y){ 414.1083 - MathContext mc = (MathContext) MATH_CONTEXT.deref(); 414.1084 - return mc == null 414.1085 - ? toBigDecimal(x).remainder(toBigDecimal(y)) 414.1086 - : toBigDecimal(x).remainder(toBigDecimal(y), mc); 414.1087 - } 414.1088 - 414.1089 - public boolean equiv(Number x, Number y){ 414.1090 - return toBigDecimal(x).equals(toBigDecimal(y)); 414.1091 - } 414.1092 - 414.1093 - public boolean lt(Number x, Number y){ 414.1094 - return toBigDecimal(x).compareTo(toBigDecimal(y)) < 0; 414.1095 - } 414.1096 - 414.1097 - //public Number subtract(Number x, Number y); 414.1098 - final public Number negate(Number x){ 414.1099 - MathContext mc = (MathContext) MATH_CONTEXT.deref(); 414.1100 - return mc == null 414.1101 - ? ((BigDecimal) x).negate() 414.1102 - : ((BigDecimal) x).negate(mc); 414.1103 - } 414.1104 - 414.1105 - public Number inc(Number x){ 414.1106 - MathContext mc = (MathContext) MATH_CONTEXT.deref(); 414.1107 - BigDecimal bx = (BigDecimal) x; 414.1108 - return mc == null 414.1109 - ? bx.add(BigDecimal.ONE) 414.1110 - : bx.add(BigDecimal.ONE, mc); 414.1111 - } 414.1112 - 414.1113 - public Number dec(Number x){ 414.1114 - MathContext mc = (MathContext) MATH_CONTEXT.deref(); 414.1115 - BigDecimal bx = (BigDecimal) x; 414.1116 - return mc == null 414.1117 - ? bx.subtract(BigDecimal.ONE) 414.1118 - : bx.subtract(BigDecimal.ONE, mc); 414.1119 - } 414.1120 -} 414.1121 - 414.1122 -final static class IntegerBitOps implements BitOps{ 414.1123 - public BitOps combine(BitOps y){ 414.1124 - return y.bitOpsWith(this); 414.1125 - } 414.1126 - 414.1127 - final public BitOps bitOpsWith(IntegerBitOps x){ 414.1128 - return this; 414.1129 - } 414.1130 - 414.1131 - final public BitOps bitOpsWith(LongBitOps x){ 414.1132 - return LONG_BITOPS; 414.1133 - } 414.1134 - 414.1135 - final public BitOps bitOpsWith(BigIntegerBitOps x){ 414.1136 - return BIGINTEGER_BITOPS; 414.1137 - } 414.1138 - 414.1139 - 414.1140 - public Number not(Number x){ 414.1141 - return ~x.intValue(); 414.1142 - } 414.1143 - 414.1144 - public Number and(Number x, Number y){ 414.1145 - return x.intValue() & y.intValue(); 414.1146 - } 414.1147 - 414.1148 - public Number or(Number x, Number y){ 414.1149 - return x.intValue() | y.intValue(); 414.1150 - } 414.1151 - 414.1152 - public Number xor(Number x, Number y){ 414.1153 - return x.intValue() ^ y.intValue(); 414.1154 - } 414.1155 - 414.1156 - public Number andNot(Number x, Number y){ 414.1157 - return x.intValue() & ~y.intValue(); 414.1158 - } 414.1159 - 414.1160 - public Number clearBit(Number x, int n){ 414.1161 - if(n < 31) 414.1162 - return x.intValue() & ~(1 << n); 414.1163 - else if(n < 63) 414.1164 - return x.longValue() & ~(1L << n); 414.1165 - else 414.1166 - return toBigInteger(x).clearBit(n); 414.1167 - } 414.1168 - 414.1169 - public Number setBit(Number x, int n){ 414.1170 - if(n < 31) 414.1171 - return x.intValue() | (1 << n); 414.1172 - else if(n < 63) 414.1173 - return x.longValue() | (1L << n); 414.1174 - else 414.1175 - return toBigInteger(x).setBit(n); 414.1176 - } 414.1177 - 414.1178 - public Number flipBit(Number x, int n){ 414.1179 - if(n < 31) 414.1180 - return x.intValue() ^ (1 << n); 414.1181 - else if(n < 63) 414.1182 - return x.longValue() ^ (1L << n); 414.1183 - else 414.1184 - return toBigInteger(x).flipBit(n); 414.1185 - } 414.1186 - 414.1187 - public boolean testBit(Number x, int n){ 414.1188 - if(n < 32) 414.1189 - return (x.intValue() & (1 << n)) != 0; 414.1190 - else if(n < 64) 414.1191 - return (x.longValue() & (1L << n)) != 0; 414.1192 - else 414.1193 - return toBigInteger(x).testBit(n); 414.1194 - } 414.1195 - 414.1196 - public Number shiftLeft(Number x, int n){ 414.1197 - if(n < 32) 414.1198 - { 414.1199 - if(n < 0) 414.1200 - return shiftRight(x, -n); 414.1201 - return reduce(x.longValue() << n); 414.1202 - } 414.1203 - else 414.1204 - return reduce(toBigInteger(x).shiftLeft(n)); 414.1205 - } 414.1206 - 414.1207 - public Number shiftRight(Number x, int n){ 414.1208 - if(n < 0) 414.1209 - return shiftLeft(x, -n); 414.1210 - return x.intValue() >> n; 414.1211 - } 414.1212 -} 414.1213 - 414.1214 -final static class LongBitOps implements BitOps{ 414.1215 - public BitOps combine(BitOps y){ 414.1216 - return y.bitOpsWith(this); 414.1217 - } 414.1218 - 414.1219 - final public BitOps bitOpsWith(IntegerBitOps x){ 414.1220 - return this; 414.1221 - } 414.1222 - 414.1223 - final public BitOps bitOpsWith(LongBitOps x){ 414.1224 - return this; 414.1225 - } 414.1226 - 414.1227 - final public BitOps bitOpsWith(BigIntegerBitOps x){ 414.1228 - return BIGINTEGER_BITOPS; 414.1229 - } 414.1230 - 414.1231 - public Number not(Number x){ 414.1232 - return ~x.longValue(); 414.1233 - } 414.1234 - 414.1235 - public Number and(Number x, Number y){ 414.1236 - return x.longValue() & y.longValue(); 414.1237 - } 414.1238 - 414.1239 - public Number or(Number x, Number y){ 414.1240 - return x.longValue() | y.longValue(); 414.1241 - } 414.1242 - 414.1243 - public Number xor(Number x, Number y){ 414.1244 - return x.longValue() ^ y.longValue(); 414.1245 - } 414.1246 - 414.1247 - public Number andNot(Number x, Number y){ 414.1248 - return x.longValue() & ~y.longValue(); 414.1249 - } 414.1250 - 414.1251 - public Number clearBit(Number x, int n){ 414.1252 - if(n < 63) 414.1253 - return x.longValue() & ~(1L << n); 414.1254 - else 414.1255 - return toBigInteger(x).clearBit(n); 414.1256 - } 414.1257 - 414.1258 - public Number setBit(Number x, int n){ 414.1259 - if(n < 63) 414.1260 - return x.longValue() | (1L << n); 414.1261 - else 414.1262 - return toBigInteger(x).setBit(n); 414.1263 - } 414.1264 - 414.1265 - public Number flipBit(Number x, int n){ 414.1266 - if(n < 63) 414.1267 - return x.longValue() ^ (1L << n); 414.1268 - else 414.1269 - return toBigInteger(x).flipBit(n); 414.1270 - } 414.1271 - 414.1272 - public boolean testBit(Number x, int n){ 414.1273 - if(n < 64) 414.1274 - return (x.longValue() & (1L << n)) != 0; 414.1275 - else 414.1276 - return toBigInteger(x).testBit(n); 414.1277 - } 414.1278 - 414.1279 - public Number shiftLeft(Number x, int n){ 414.1280 - if(n < 0) 414.1281 - return shiftRight(x, -n); 414.1282 - return reduce(toBigInteger(x).shiftLeft(n)); 414.1283 - } 414.1284 - 414.1285 - public Number shiftRight(Number x, int n){ 414.1286 - if(n < 0) 414.1287 - return shiftLeft(x, -n); 414.1288 - return x.longValue() >> n; 414.1289 - } 414.1290 -} 414.1291 - 414.1292 -final static class BigIntegerBitOps implements BitOps{ 414.1293 - public BitOps combine(BitOps y){ 414.1294 - return y.bitOpsWith(this); 414.1295 - } 414.1296 - 414.1297 - final public BitOps bitOpsWith(IntegerBitOps x){ 414.1298 - return this; 414.1299 - } 414.1300 - 414.1301 - final public BitOps bitOpsWith(LongBitOps x){ 414.1302 - return this; 414.1303 - } 414.1304 - 414.1305 - final public BitOps bitOpsWith(BigIntegerBitOps x){ 414.1306 - return this; 414.1307 - } 414.1308 - 414.1309 - public Number not(Number x){ 414.1310 - return toBigInteger(x).not(); 414.1311 - } 414.1312 - 414.1313 - public Number and(Number x, Number y){ 414.1314 - return toBigInteger(x).and(toBigInteger(y)); 414.1315 - } 414.1316 - 414.1317 - public Number or(Number x, Number y){ 414.1318 - return toBigInteger(x).or(toBigInteger(y)); 414.1319 - } 414.1320 - 414.1321 - public Number xor(Number x, Number y){ 414.1322 - return toBigInteger(x).xor(toBigInteger(y)); 414.1323 - } 414.1324 - 414.1325 - public Number andNot(Number x, Number y){ 414.1326 - return toBigInteger(x).andNot(toBigInteger(y)); 414.1327 - } 414.1328 - 414.1329 - public Number clearBit(Number x, int n){ 414.1330 - return toBigInteger(x).clearBit(n); 414.1331 - } 414.1332 - 414.1333 - public Number setBit(Number x, int n){ 414.1334 - return toBigInteger(x).setBit(n); 414.1335 - } 414.1336 - 414.1337 - public Number flipBit(Number x, int n){ 414.1338 - return toBigInteger(x).flipBit(n); 414.1339 - } 414.1340 - 414.1341 - public boolean testBit(Number x, int n){ 414.1342 - return toBigInteger(x).testBit(n); 414.1343 - } 414.1344 - 414.1345 - public Number shiftLeft(Number x, int n){ 414.1346 - return toBigInteger(x).shiftLeft(n); 414.1347 - } 414.1348 - 414.1349 - public Number shiftRight(Number x, int n){ 414.1350 - return toBigInteger(x).shiftRight(n); 414.1351 - } 414.1352 -} 414.1353 - 414.1354 -static final IntegerOps INTEGER_OPS = new IntegerOps(); 414.1355 -static final LongOps LONG_OPS = new LongOps(); 414.1356 -static final FloatOps FLOAT_OPS = new FloatOps(); 414.1357 -static final DoubleOps DOUBLE_OPS = new DoubleOps(); 414.1358 -static final RatioOps RATIO_OPS = new RatioOps(); 414.1359 -static final BigIntegerOps BIGINTEGER_OPS = new BigIntegerOps(); 414.1360 -static final BigDecimalOps BIGDECIMAL_OPS = new BigDecimalOps(); 414.1361 - 414.1362 -static final IntegerBitOps INTEGER_BITOPS = new IntegerBitOps(); 414.1363 -static final LongBitOps LONG_BITOPS = new LongBitOps(); 414.1364 -static final BigIntegerBitOps BIGINTEGER_BITOPS = new BigIntegerBitOps(); 414.1365 - 414.1366 -static Ops ops(Object x){ 414.1367 - Class xc = x.getClass(); 414.1368 - 414.1369 - if(xc == Integer.class) 414.1370 - return INTEGER_OPS; 414.1371 - else if(xc == Double.class) 414.1372 - return DOUBLE_OPS; 414.1373 - else if(xc == Float.class) 414.1374 - return FLOAT_OPS; 414.1375 - else if(xc == BigInteger.class) 414.1376 - return BIGINTEGER_OPS; 414.1377 - else if(xc == Long.class) 414.1378 - return LONG_OPS; 414.1379 - else if(xc == Ratio.class) 414.1380 - return RATIO_OPS; 414.1381 - else if(xc == BigDecimal.class) 414.1382 - return BIGDECIMAL_OPS; 414.1383 - else 414.1384 - return INTEGER_OPS; 414.1385 -} 414.1386 - 414.1387 -static BitOps bitOps(Object x){ 414.1388 - Class xc = x.getClass(); 414.1389 - 414.1390 - if(xc == Integer.class) 414.1391 - return INTEGER_BITOPS; 414.1392 - else if(xc == Long.class) 414.1393 - return LONG_BITOPS; 414.1394 - else if(xc == BigInteger.class) 414.1395 - return BIGINTEGER_BITOPS; 414.1396 - else if(xc == Double.class || xc == Float.class || xc == BigDecimalOps.class || xc == Ratio.class) 414.1397 - throw new ArithmeticException("bit operation on non integer type: " + xc); 414.1398 - else 414.1399 - return INTEGER_BITOPS; 414.1400 -} 414.1401 - 414.1402 -//final static ExecutorService executor = Executors.newCachedThreadPool(); 414.1403 -//static public int minChunk = 100; 414.1404 -//static int chunkSize(int alength){ 414.1405 -// return Math.max(alength / Runtime.getRuntime().availableProcessors(), minChunk); 414.1406 -//} 414.1407 - 414.1408 -// } 414.1409 -// else 414.1410 -// { 414.1411 -// LinkedList<Callable<Float>> ops = new LinkedList<Callable<Float>>(); 414.1412 -// for(int offset = 0;offset < xs.length;offset+=chunk) 414.1413 -// { 414.1414 -// final int start = offset; 414.1415 -// final int end = Math.min(xs.length, start + chunk); 414.1416 -// ops.add(new Callable<Float>(){ 414.1417 -// public Float call() throws Exception{ 414.1418 -// for(int i=start;i<end;i++) 414.1419 -// xs[i] += ys[i]; 414.1420 -// return null; 414.1421 -// }}); 414.1422 -// } 414.1423 -// executor.invokeAll(ops); 414.1424 -// } 414.1425 - 414.1426 - 414.1427 - static public float[] float_array(int size, Object init){ 414.1428 - float[] ret = new float[size]; 414.1429 - if(init instanceof Number) 414.1430 - { 414.1431 - float f = ((Number) init).floatValue(); 414.1432 - for(int i = 0; i < ret.length; i++) 414.1433 - ret[i] = f; 414.1434 - } 414.1435 - else 414.1436 - { 414.1437 - ISeq s = RT.seq(init); 414.1438 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1439 - ret[i] = ((Number) s.first()).floatValue(); 414.1440 - } 414.1441 - return ret; 414.1442 - } 414.1443 - 414.1444 - static public float[] float_array(Object sizeOrSeq){ 414.1445 - if(sizeOrSeq instanceof Number) 414.1446 - return new float[((Number) sizeOrSeq).intValue()]; 414.1447 - else 414.1448 - { 414.1449 - ISeq s = RT.seq(sizeOrSeq); 414.1450 - int size = RT.count(s); 414.1451 - float[] ret = new float[size]; 414.1452 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1453 - ret[i] = ((Number) s.first()).floatValue(); 414.1454 - return ret; 414.1455 - } 414.1456 - } 414.1457 - 414.1458 -static public double[] double_array(int size, Object init){ 414.1459 - double[] ret = new double[size]; 414.1460 - if(init instanceof Number) 414.1461 - { 414.1462 - double f = ((Number) init).doubleValue(); 414.1463 - for(int i = 0; i < ret.length; i++) 414.1464 - ret[i] = f; 414.1465 - } 414.1466 - else 414.1467 - { 414.1468 - ISeq s = RT.seq(init); 414.1469 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1470 - ret[i] = ((Number) s.first()).doubleValue(); 414.1471 - } 414.1472 - return ret; 414.1473 -} 414.1474 - 414.1475 -static public double[] double_array(Object sizeOrSeq){ 414.1476 - if(sizeOrSeq instanceof Number) 414.1477 - return new double[((Number) sizeOrSeq).intValue()]; 414.1478 - else 414.1479 - { 414.1480 - ISeq s = RT.seq(sizeOrSeq); 414.1481 - int size = RT.count(s); 414.1482 - double[] ret = new double[size]; 414.1483 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1484 - ret[i] = ((Number) s.first()).doubleValue(); 414.1485 - return ret; 414.1486 - } 414.1487 -} 414.1488 - 414.1489 -static public int[] int_array(int size, Object init){ 414.1490 - int[] ret = new int[size]; 414.1491 - if(init instanceof Number) 414.1492 - { 414.1493 - int f = ((Number) init).intValue(); 414.1494 - for(int i = 0; i < ret.length; i++) 414.1495 - ret[i] = f; 414.1496 - } 414.1497 - else 414.1498 - { 414.1499 - ISeq s = RT.seq(init); 414.1500 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1501 - ret[i] = ((Number) s.first()).intValue(); 414.1502 - } 414.1503 - return ret; 414.1504 -} 414.1505 - 414.1506 -static public int[] int_array(Object sizeOrSeq){ 414.1507 - if(sizeOrSeq instanceof Number) 414.1508 - return new int[((Number) sizeOrSeq).intValue()]; 414.1509 - else 414.1510 - { 414.1511 - ISeq s = RT.seq(sizeOrSeq); 414.1512 - int size = RT.count(s); 414.1513 - int[] ret = new int[size]; 414.1514 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1515 - ret[i] = ((Number) s.first()).intValue(); 414.1516 - return ret; 414.1517 - } 414.1518 -} 414.1519 - 414.1520 -static public long[] long_array(int size, Object init){ 414.1521 - long[] ret = new long[size]; 414.1522 - if(init instanceof Number) 414.1523 - { 414.1524 - long f = ((Number) init).longValue(); 414.1525 - for(int i = 0; i < ret.length; i++) 414.1526 - ret[i] = f; 414.1527 - } 414.1528 - else 414.1529 - { 414.1530 - ISeq s = RT.seq(init); 414.1531 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1532 - ret[i] = ((Number) s.first()).longValue(); 414.1533 - } 414.1534 - return ret; 414.1535 -} 414.1536 - 414.1537 -static public long[] long_array(Object sizeOrSeq){ 414.1538 - if(sizeOrSeq instanceof Number) 414.1539 - return new long[((Number) sizeOrSeq).intValue()]; 414.1540 - else 414.1541 - { 414.1542 - ISeq s = RT.seq(sizeOrSeq); 414.1543 - int size = RT.count(s); 414.1544 - long[] ret = new long[size]; 414.1545 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1546 - ret[i] = ((Number) s.first()).longValue(); 414.1547 - return ret; 414.1548 - } 414.1549 -} 414.1550 - 414.1551 -static public short[] short_array(int size, Object init){ 414.1552 - short[] ret = new short[size]; 414.1553 - if(init instanceof Short) 414.1554 - { 414.1555 - short s = (Short) init; 414.1556 - for(int i = 0; i < ret.length; i++) 414.1557 - ret[i] = s; 414.1558 - } 414.1559 - else 414.1560 - { 414.1561 - ISeq s = RT.seq(init); 414.1562 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1563 - ret[i] = (Short) s.first(); 414.1564 - } 414.1565 - return ret; 414.1566 -} 414.1567 - 414.1568 -static public short[] short_array(Object sizeOrSeq){ 414.1569 - if(sizeOrSeq instanceof Number) 414.1570 - return new short[((Number) sizeOrSeq).intValue()]; 414.1571 - else 414.1572 - { 414.1573 - ISeq s = RT.seq(sizeOrSeq); 414.1574 - int size = RT.count(s); 414.1575 - short[] ret = new short[size]; 414.1576 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1577 - ret[i] = (Short) s.first(); 414.1578 - return ret; 414.1579 - } 414.1580 -} 414.1581 - 414.1582 -static public char[] char_array(int size, Object init){ 414.1583 - char[] ret = new char[size]; 414.1584 - if(init instanceof Character) 414.1585 - { 414.1586 - char c = (Character) init; 414.1587 - for(int i = 0; i < ret.length; i++) 414.1588 - ret[i] = c; 414.1589 - } 414.1590 - else 414.1591 - { 414.1592 - ISeq s = RT.seq(init); 414.1593 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1594 - ret[i] = (Character) s.first(); 414.1595 - } 414.1596 - return ret; 414.1597 -} 414.1598 - 414.1599 -static public char[] char_array(Object sizeOrSeq){ 414.1600 - if(sizeOrSeq instanceof Number) 414.1601 - return new char[((Number) sizeOrSeq).intValue()]; 414.1602 - else 414.1603 - { 414.1604 - ISeq s = RT.seq(sizeOrSeq); 414.1605 - int size = RT.count(s); 414.1606 - char[] ret = new char[size]; 414.1607 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1608 - ret[i] = (Character) s.first(); 414.1609 - return ret; 414.1610 - } 414.1611 -} 414.1612 - 414.1613 -static public byte[] byte_array(int size, Object init){ 414.1614 - byte[] ret = new byte[size]; 414.1615 - if(init instanceof Byte) 414.1616 - { 414.1617 - byte b = (Byte) init; 414.1618 - for(int i = 0; i < ret.length; i++) 414.1619 - ret[i] = b; 414.1620 - } 414.1621 - else 414.1622 - { 414.1623 - ISeq s = RT.seq(init); 414.1624 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1625 - ret[i] = (Byte) s.first(); 414.1626 - } 414.1627 - return ret; 414.1628 -} 414.1629 - 414.1630 -static public byte[] byte_array(Object sizeOrSeq){ 414.1631 - if(sizeOrSeq instanceof Number) 414.1632 - return new byte[((Number) sizeOrSeq).intValue()]; 414.1633 - else 414.1634 - { 414.1635 - ISeq s = RT.seq(sizeOrSeq); 414.1636 - int size = RT.count(s); 414.1637 - byte[] ret = new byte[size]; 414.1638 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1639 - ret[i] = (Byte)s.first(); 414.1640 - return ret; 414.1641 - } 414.1642 -} 414.1643 - 414.1644 -static public boolean[] boolean_array(int size, Object init){ 414.1645 - boolean[] ret = new boolean[size]; 414.1646 - if(init instanceof Boolean) 414.1647 - { 414.1648 - boolean b = (Boolean) init; 414.1649 - for(int i = 0; i < ret.length; i++) 414.1650 - ret[i] = b; 414.1651 - } 414.1652 - else 414.1653 - { 414.1654 - ISeq s = RT.seq(init); 414.1655 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1656 - ret[i] = (Boolean)s.first(); 414.1657 - } 414.1658 - return ret; 414.1659 -} 414.1660 - 414.1661 -static public boolean[] boolean_array(Object sizeOrSeq){ 414.1662 - if(sizeOrSeq instanceof Number) 414.1663 - return new boolean[((Number) sizeOrSeq).intValue()]; 414.1664 - else 414.1665 - { 414.1666 - ISeq s = RT.seq(sizeOrSeq); 414.1667 - int size = RT.count(s); 414.1668 - boolean[] ret = new boolean[size]; 414.1669 - for(int i = 0; i < size && s != null; i++, s = s.next()) 414.1670 - ret[i] = (Boolean)s.first(); 414.1671 - return ret; 414.1672 - } 414.1673 -} 414.1674 - 414.1675 -static public boolean[] booleans(Object array){ 414.1676 - return (boolean[]) array; 414.1677 -} 414.1678 - 414.1679 -static public byte[] bytes(Object array){ 414.1680 - return (byte[]) array; 414.1681 -} 414.1682 - 414.1683 -static public char[] chars(Object array){ 414.1684 - return (char[]) array; 414.1685 -} 414.1686 - 414.1687 -static public short[] shorts(Object array){ 414.1688 - return (short[]) array; 414.1689 -} 414.1690 - 414.1691 -static public float[] floats(Object array){ 414.1692 - return (float[]) array; 414.1693 -} 414.1694 - 414.1695 -static public double[] doubles(Object array){ 414.1696 - return (double[]) array; 414.1697 -} 414.1698 - 414.1699 -static public int[] ints(Object array){ 414.1700 - return (int[]) array; 414.1701 -} 414.1702 - 414.1703 -static public long[] longs(Object array){ 414.1704 - return (long[]) array; 414.1705 -} 414.1706 - 414.1707 -static public Number num(Object x){ 414.1708 - return (Number) x; 414.1709 -} 414.1710 - 414.1711 -static public Number num(float x){ 414.1712 - return x; 414.1713 -} 414.1714 - 414.1715 -static public float add(float x, float y){ 414.1716 - return x + y; 414.1717 -} 414.1718 - 414.1719 -static public float minus(float x, float y){ 414.1720 - return x - y; 414.1721 -} 414.1722 - 414.1723 -static public float minus(float x){ 414.1724 - return -x; 414.1725 -} 414.1726 - 414.1727 -static public float inc(float x){ 414.1728 - return x + 1; 414.1729 -} 414.1730 - 414.1731 -static public float dec(float x){ 414.1732 - return x - 1; 414.1733 -} 414.1734 - 414.1735 -static public float multiply(float x, float y){ 414.1736 - return x * y; 414.1737 -} 414.1738 - 414.1739 -static public float divide(float x, float y){ 414.1740 - return x / y; 414.1741 -} 414.1742 - 414.1743 -static public boolean equiv(float x, float y){ 414.1744 - return x == y; 414.1745 -} 414.1746 - 414.1747 -static public boolean lt(float x, float y){ 414.1748 - return x < y; 414.1749 -} 414.1750 - 414.1751 -static public boolean lte(float x, float y){ 414.1752 - return x <= y; 414.1753 -} 414.1754 - 414.1755 -static public boolean gt(float x, float y){ 414.1756 - return x > y; 414.1757 -} 414.1758 - 414.1759 -static public boolean gte(float x, float y){ 414.1760 - return x >= y; 414.1761 -} 414.1762 - 414.1763 -static public boolean isPos(float x){ 414.1764 - return x > 0; 414.1765 -} 414.1766 - 414.1767 -static public boolean isNeg(float x){ 414.1768 - return x < 0; 414.1769 -} 414.1770 - 414.1771 -static public boolean isZero(float x){ 414.1772 - return x == 0; 414.1773 -} 414.1774 - 414.1775 -static public Number num(double x){ 414.1776 - return x; 414.1777 -} 414.1778 - 414.1779 -static public double add(double x, double y){ 414.1780 - return x + y; 414.1781 -} 414.1782 - 414.1783 -static public double minus(double x, double y){ 414.1784 - return x - y; 414.1785 -} 414.1786 - 414.1787 -static public double minus(double x){ 414.1788 - return -x; 414.1789 -} 414.1790 - 414.1791 -static public double inc(double x){ 414.1792 - return x + 1; 414.1793 -} 414.1794 - 414.1795 -static public double dec(double x){ 414.1796 - return x - 1; 414.1797 -} 414.1798 - 414.1799 -static public double multiply(double x, double y){ 414.1800 - return x * y; 414.1801 -} 414.1802 - 414.1803 -static public double divide(double x, double y){ 414.1804 - return x / y; 414.1805 -} 414.1806 - 414.1807 -static public boolean equiv(double x, double y){ 414.1808 - return x == y; 414.1809 -} 414.1810 - 414.1811 -static public boolean lt(double x, double y){ 414.1812 - return x < y; 414.1813 -} 414.1814 - 414.1815 -static public boolean lte(double x, double y){ 414.1816 - return x <= y; 414.1817 -} 414.1818 - 414.1819 -static public boolean gt(double x, double y){ 414.1820 - return x > y; 414.1821 -} 414.1822 - 414.1823 -static public boolean gte(double x, double y){ 414.1824 - return x >= y; 414.1825 -} 414.1826 - 414.1827 -static public boolean isPos(double x){ 414.1828 - return x > 0; 414.1829 -} 414.1830 - 414.1831 -static public boolean isNeg(double x){ 414.1832 - return x < 0; 414.1833 -} 414.1834 - 414.1835 -static public boolean isZero(double x){ 414.1836 - return x == 0; 414.1837 -} 414.1838 - 414.1839 -static int throwIntOverflow(){ 414.1840 - throw new ArithmeticException("integer overflow"); 414.1841 -} 414.1842 - 414.1843 -static public Number num(int x){ 414.1844 - return x; 414.1845 -} 414.1846 - 414.1847 -static public int unchecked_add(int x, int y){ 414.1848 - return x + y; 414.1849 -} 414.1850 - 414.1851 -static public int unchecked_subtract(int x, int y){ 414.1852 - return x - y; 414.1853 -} 414.1854 - 414.1855 -static public int unchecked_negate(int x){ 414.1856 - return -x; 414.1857 -} 414.1858 - 414.1859 -static public int unchecked_inc(int x){ 414.1860 - return x + 1; 414.1861 -} 414.1862 - 414.1863 -static public int unchecked_dec(int x){ 414.1864 - return x - 1; 414.1865 -} 414.1866 - 414.1867 -static public int unchecked_multiply(int x, int y){ 414.1868 - return x * y; 414.1869 -} 414.1870 - 414.1871 -static public int add(int x, int y){ 414.1872 - int ret = x + y; 414.1873 - if ((ret ^ x) < 0 && (ret ^ y) < 0) 414.1874 - return throwIntOverflow(); 414.1875 - return ret; 414.1876 -} 414.1877 - 414.1878 -static public int not(int x){ 414.1879 - return ~x; 414.1880 -} 414.1881 - 414.1882 -static public int and(int x, int y){ 414.1883 - return x & y; 414.1884 -} 414.1885 - 414.1886 -static public int or(int x, int y){ 414.1887 - return x | y; 414.1888 -} 414.1889 - 414.1890 -static public int xor(int x, int y){ 414.1891 - return x ^ y; 414.1892 -} 414.1893 - 414.1894 -static public int minus(int x, int y){ 414.1895 - int ret = x - y; 414.1896 - if (((ret ^ x) < 0 && (ret ^ ~y) < 0)) 414.1897 - return throwIntOverflow(); 414.1898 - return ret; 414.1899 -} 414.1900 - 414.1901 -static public int minus(int x){ 414.1902 - if(x == Integer.MIN_VALUE) 414.1903 - return throwIntOverflow(); 414.1904 - return -x; 414.1905 -} 414.1906 - 414.1907 -static public int inc(int x){ 414.1908 - if(x == Integer.MAX_VALUE) 414.1909 - return throwIntOverflow(); 414.1910 - return x + 1; 414.1911 -} 414.1912 - 414.1913 -static public int dec(int x){ 414.1914 - if(x == Integer.MIN_VALUE) 414.1915 - return throwIntOverflow(); 414.1916 - return x - 1; 414.1917 -} 414.1918 - 414.1919 -static public int multiply(int x, int y){ 414.1920 - int ret = x * y; 414.1921 - if (y != 0 && ret/y != x) 414.1922 - return throwIntOverflow(); 414.1923 - return ret; 414.1924 -} 414.1925 - 414.1926 -static public int unchecked_divide(int x, int y){ 414.1927 - return x / y; 414.1928 -} 414.1929 - 414.1930 -static public int unchecked_remainder(int x, int y){ 414.1931 - return x % y; 414.1932 -} 414.1933 - 414.1934 -static public boolean equiv(int x, int y){ 414.1935 - return x == y; 414.1936 -} 414.1937 - 414.1938 -static public boolean lt(int x, int y){ 414.1939 - return x < y; 414.1940 -} 414.1941 - 414.1942 -static public boolean lte(int x, int y){ 414.1943 - return x <= y; 414.1944 -} 414.1945 - 414.1946 -static public boolean gt(int x, int y){ 414.1947 - return x > y; 414.1948 -} 414.1949 - 414.1950 -static public boolean gte(int x, int y){ 414.1951 - return x >= y; 414.1952 -} 414.1953 - 414.1954 -static public boolean isPos(int x){ 414.1955 - return x > 0; 414.1956 -} 414.1957 - 414.1958 -static public boolean isNeg(int x){ 414.1959 - return x < 0; 414.1960 -} 414.1961 - 414.1962 -static public boolean isZero(int x){ 414.1963 - return x == 0; 414.1964 -} 414.1965 - 414.1966 -static public Number num(long x){ 414.1967 - return x; 414.1968 -} 414.1969 - 414.1970 -static public long unchecked_add(long x, long y){ 414.1971 - return x + y; 414.1972 -} 414.1973 - 414.1974 -static public long unchecked_subtract(long x, long y){ 414.1975 - return x - y; 414.1976 -} 414.1977 - 414.1978 -static public long unchecked_negate(long x){ 414.1979 - return -x; 414.1980 -} 414.1981 - 414.1982 -static public long unchecked_inc(long x){ 414.1983 - return x + 1; 414.1984 -} 414.1985 - 414.1986 -static public long unchecked_dec(long x){ 414.1987 - return x - 1; 414.1988 -} 414.1989 - 414.1990 -static public long unchecked_multiply(long x, long y){ 414.1991 - return x * y; 414.1992 -} 414.1993 - 414.1994 -static public long add(long x, long y){ 414.1995 - long ret = x + y; 414.1996 - if ((ret ^ x) < 0 && (ret ^ y) < 0) 414.1997 - return throwIntOverflow(); 414.1998 - return ret; 414.1999 -} 414.2000 - 414.2001 -static public long minus(long x, long y){ 414.2002 - long ret = x - y; 414.2003 - if (((ret ^ x) < 0 && (ret ^ ~y) < 0)) 414.2004 - return throwIntOverflow(); 414.2005 - return ret; 414.2006 -} 414.2007 - 414.2008 -static public long minus(long x){ 414.2009 - if(x == Long.MIN_VALUE) 414.2010 - return throwIntOverflow(); 414.2011 - return -x; 414.2012 -} 414.2013 - 414.2014 -static public long inc(long x){ 414.2015 - if(x == Long.MAX_VALUE) 414.2016 - return throwIntOverflow(); 414.2017 - return x + 1; 414.2018 -} 414.2019 - 414.2020 -static public long dec(long x){ 414.2021 - if(x == Long.MIN_VALUE) 414.2022 - return throwIntOverflow(); 414.2023 - return x - 1; 414.2024 -} 414.2025 - 414.2026 -static public long multiply(long x, long y){ 414.2027 - long ret = x * y; 414.2028 - if (y != 0 && ret/y != x) 414.2029 - return throwIntOverflow(); 414.2030 - return ret; 414.2031 -} 414.2032 - 414.2033 -static public long unchecked_divide(long x, long y){ 414.2034 - return x / y; 414.2035 -} 414.2036 - 414.2037 -static public long unchecked_remainder(long x, long y){ 414.2038 - return x % y; 414.2039 -} 414.2040 - 414.2041 -static public boolean equiv(long x, long y){ 414.2042 - return x == y; 414.2043 -} 414.2044 - 414.2045 -static public boolean lt(long x, long y){ 414.2046 - return x < y; 414.2047 -} 414.2048 - 414.2049 -static public boolean lte(long x, long y){ 414.2050 - return x <= y; 414.2051 -} 414.2052 - 414.2053 -static public boolean gt(long x, long y){ 414.2054 - return x > y; 414.2055 -} 414.2056 - 414.2057 -static public boolean gte(long x, long y){ 414.2058 - return x >= y; 414.2059 -} 414.2060 - 414.2061 -static public boolean isPos(long x){ 414.2062 - return x > 0; 414.2063 -} 414.2064 - 414.2065 -static public boolean isNeg(long x){ 414.2066 - return x < 0; 414.2067 -} 414.2068 - 414.2069 -static public boolean isZero(long x){ 414.2070 - return x == 0; 414.2071 -} 414.2072 - 414.2073 -/* 414.2074 -static public class F{ 414.2075 - static public float add(float x, float y){ 414.2076 - return x + y; 414.2077 - } 414.2078 - 414.2079 - static public float subtract(float x, float y){ 414.2080 - return x - y; 414.2081 - } 414.2082 - 414.2083 - static public float negate(float x){ 414.2084 - return -x; 414.2085 - } 414.2086 - 414.2087 - static public float inc(float x){ 414.2088 - return x + 1; 414.2089 - } 414.2090 - 414.2091 - static public float dec(float x){ 414.2092 - return x - 1; 414.2093 - } 414.2094 - 414.2095 - static public float multiply(float x, float y){ 414.2096 - return x * y; 414.2097 - } 414.2098 - 414.2099 - static public float divide(float x, float y){ 414.2100 - return x / y; 414.2101 - } 414.2102 - 414.2103 - static public boolean equiv(float x, float y){ 414.2104 - return x == y; 414.2105 - } 414.2106 - 414.2107 - static public boolean lt(float x, float y){ 414.2108 - return x < y; 414.2109 - } 414.2110 - 414.2111 - static public boolean lte(float x, float y){ 414.2112 - return x <= y; 414.2113 - } 414.2114 - 414.2115 - static public boolean gt(float x, float y){ 414.2116 - return x > y; 414.2117 - } 414.2118 - 414.2119 - static public boolean gte(float x, float y){ 414.2120 - return x >= y; 414.2121 - } 414.2122 - 414.2123 - static public boolean pos(float x){ 414.2124 - return x > 0; 414.2125 - } 414.2126 - 414.2127 - static public boolean neg(float x){ 414.2128 - return x < 0; 414.2129 - } 414.2130 - 414.2131 - static public boolean zero(float x){ 414.2132 - return x == 0; 414.2133 - } 414.2134 - 414.2135 - static public float aget(float[] xs, int i){ 414.2136 - return xs[i]; 414.2137 - } 414.2138 - 414.2139 - static public float aset(float[] xs, int i, float v){ 414.2140 - xs[i] = v; 414.2141 - return v; 414.2142 - } 414.2143 - 414.2144 - static public int alength(float[] xs){ 414.2145 - return xs.length; 414.2146 - } 414.2147 - 414.2148 - static public float[] aclone(float[] xs){ 414.2149 - return xs.clone(); 414.2150 - } 414.2151 - 414.2152 - static public float[] vec(int size, Object init){ 414.2153 - float[] ret = new float[size]; 414.2154 - if(init instanceof Number) 414.2155 - { 414.2156 - float f = ((Number) init).floatValue(); 414.2157 - for(int i = 0; i < ret.length; i++) 414.2158 - ret[i] = f; 414.2159 - } 414.2160 - else 414.2161 - { 414.2162 - ISeq s = RT.seq(init); 414.2163 - for(int i = 0; i < size && s != null; i++, s = s.rest()) 414.2164 - ret[i] = ((Number) s.first()).floatValue(); 414.2165 - } 414.2166 - return ret; 414.2167 - } 414.2168 - 414.2169 - static public float[] vec(Object sizeOrSeq){ 414.2170 - if(sizeOrSeq instanceof Number) 414.2171 - return new float[((Number) sizeOrSeq).intValue()]; 414.2172 - else 414.2173 - { 414.2174 - ISeq s = RT.seq(sizeOrSeq); 414.2175 - int size = s.count(); 414.2176 - float[] ret = new float[size]; 414.2177 - for(int i = 0; i < size && s != null; i++, s = s.rest()) 414.2178 - ret[i] = ((Number) s.first()).intValue(); 414.2179 - return ret; 414.2180 - } 414.2181 - } 414.2182 - 414.2183 - 414.2184 - static public float[] vsadd(float[] x, float y){ 414.2185 - final float[] xs = x.clone(); 414.2186 - for(int i = 0; i < xs.length; i++) 414.2187 - xs[i] += y; 414.2188 - return xs; 414.2189 - } 414.2190 - 414.2191 - static public float[] vssub(float[] x, float y){ 414.2192 - final float[] xs = x.clone(); 414.2193 - for(int i = 0; i < xs.length; i++) 414.2194 - xs[i] -= y; 414.2195 - return xs; 414.2196 - } 414.2197 - 414.2198 - static public float[] vsdiv(float[] x, float y){ 414.2199 - final float[] xs = x.clone(); 414.2200 - for(int i = 0; i < xs.length; i++) 414.2201 - xs[i] /= y; 414.2202 - return xs; 414.2203 - } 414.2204 - 414.2205 - static public float[] vsmul(float[] x, float y){ 414.2206 - final float[] xs = x.clone(); 414.2207 - for(int i = 0; i < xs.length; i++) 414.2208 - xs[i] *= y; 414.2209 - return xs; 414.2210 - } 414.2211 - 414.2212 - static public float[] svdiv(float y, float[] x){ 414.2213 - final float[] xs = x.clone(); 414.2214 - for(int i = 0; i < xs.length; i++) 414.2215 - xs[i] = y / xs[i]; 414.2216 - return xs; 414.2217 - } 414.2218 - 414.2219 - static public float[] vsmuladd(float[] x, float y, float[] zs){ 414.2220 - final float[] xs = x.clone(); 414.2221 - for(int i = 0; i < xs.length; i++) 414.2222 - xs[i] = xs[i] * y + zs[i]; 414.2223 - return xs; 414.2224 - } 414.2225 - 414.2226 - static public float[] vsmulsub(float[] x, float y, float[] zs){ 414.2227 - final float[] xs = x.clone(); 414.2228 - for(int i = 0; i < xs.length; i++) 414.2229 - xs[i] = xs[i] * y - zs[i]; 414.2230 - return xs; 414.2231 - } 414.2232 - 414.2233 - static public float[] vsmulsadd(float[] x, float y, float z){ 414.2234 - final float[] xs = x.clone(); 414.2235 - for(int i = 0; i < xs.length; i++) 414.2236 - xs[i] = xs[i] * y + z; 414.2237 - return xs; 414.2238 - } 414.2239 - 414.2240 - static public float[] vsmulssub(float[] x, float y, float z){ 414.2241 - final float[] xs = x.clone(); 414.2242 - for(int i = 0; i < xs.length; i++) 414.2243 - xs[i] = xs[i] * y - z; 414.2244 - return xs; 414.2245 - } 414.2246 - 414.2247 - static public float[] vabs(float[] x){ 414.2248 - final float[] xs = x.clone(); 414.2249 - for(int i = 0; i < xs.length; i++) 414.2250 - xs[i] = Math.abs(xs[i]); 414.2251 - return xs; 414.2252 - } 414.2253 - 414.2254 - static public float[] vnegabs(float[] x){ 414.2255 - final float[] xs = x.clone(); 414.2256 - for(int i = 0; i < xs.length; i++) 414.2257 - xs[i] = -Math.abs(xs[i]); 414.2258 - return xs; 414.2259 - } 414.2260 - 414.2261 - static public float[] vneg(float[] x){ 414.2262 - final float[] xs = x.clone(); 414.2263 - for(int i = 0; i < xs.length; i++) 414.2264 - xs[i] = -xs[i]; 414.2265 - return xs; 414.2266 - } 414.2267 - 414.2268 - static public float[] vsqr(float[] x){ 414.2269 - final float[] xs = x.clone(); 414.2270 - for(int i = 0; i < xs.length; i++) 414.2271 - xs[i] *= xs[i]; 414.2272 - return xs; 414.2273 - } 414.2274 - 414.2275 - static public float[] vsignedsqr(float[] x){ 414.2276 - final float[] xs = x.clone(); 414.2277 - for(int i = 0; i < xs.length; i++) 414.2278 - xs[i] *= Math.abs(xs[i]); 414.2279 - return xs; 414.2280 - } 414.2281 - 414.2282 - static public float[] vclip(float[] x, float low, float high){ 414.2283 - final float[] xs = x.clone(); 414.2284 - for(int i = 0; i < xs.length; i++) 414.2285 - { 414.2286 - if(xs[i] < low) 414.2287 - xs[i] = low; 414.2288 - else if(xs[i] > high) 414.2289 - xs[i] = high; 414.2290 - } 414.2291 - return xs; 414.2292 - } 414.2293 - 414.2294 - static public IPersistentVector vclipcounts(float[] x, float low, float high){ 414.2295 - final float[] xs = x.clone(); 414.2296 - int lowc = 0; 414.2297 - int highc = 0; 414.2298 - 414.2299 - for(int i = 0; i < xs.length; i++) 414.2300 - { 414.2301 - if(xs[i] < low) 414.2302 - { 414.2303 - ++lowc; 414.2304 - xs[i] = low; 414.2305 - } 414.2306 - else if(xs[i] > high) 414.2307 - { 414.2308 - ++highc; 414.2309 - xs[i] = high; 414.2310 - } 414.2311 - } 414.2312 - return RT.vector(xs, lowc, highc); 414.2313 - } 414.2314 - 414.2315 - static public float[] vthresh(float[] x, float thresh, float otherwise){ 414.2316 - final float[] xs = x.clone(); 414.2317 - for(int i = 0; i < xs.length; i++) 414.2318 - { 414.2319 - if(xs[i] < thresh) 414.2320 - xs[i] = otherwise; 414.2321 - } 414.2322 - return xs; 414.2323 - } 414.2324 - 414.2325 - static public float[] vreverse(float[] x){ 414.2326 - final float[] xs = x.clone(); 414.2327 - for(int i = 0; i < xs.length; i++) 414.2328 - xs[i] = xs[xs.length - i - 1]; 414.2329 - return xs; 414.2330 - } 414.2331 - 414.2332 - static public float[] vrunningsum(float[] x){ 414.2333 - final float[] xs = x.clone(); 414.2334 - for(int i = 1; i < xs.length; i++) 414.2335 - xs[i] = xs[i - 1] + xs[i]; 414.2336 - return xs; 414.2337 - } 414.2338 - 414.2339 - static public float[] vsort(float[] x){ 414.2340 - final float[] xs = x.clone(); 414.2341 - Arrays.sort(xs); 414.2342 - return xs; 414.2343 - } 414.2344 - 414.2345 - static public float vdot(float[] xs, float[] ys){ 414.2346 - float ret = 0; 414.2347 - for(int i = 0; i < xs.length; i++) 414.2348 - ret += xs[i] * ys[i]; 414.2349 - return ret; 414.2350 - } 414.2351 - 414.2352 - static public float vmax(float[] xs){ 414.2353 - if(xs.length == 0) 414.2354 - return 0; 414.2355 - float ret = xs[0]; 414.2356 - for(int i = 0; i < xs.length; i++) 414.2357 - ret = Math.max(ret, xs[i]); 414.2358 - return ret; 414.2359 - } 414.2360 - 414.2361 - static public float vmin(float[] xs){ 414.2362 - if(xs.length == 0) 414.2363 - return 0; 414.2364 - float ret = xs[0]; 414.2365 - for(int i = 0; i < xs.length; i++) 414.2366 - ret = Math.min(ret, xs[i]); 414.2367 - return ret; 414.2368 - } 414.2369 - 414.2370 - static public float vmean(float[] xs){ 414.2371 - if(xs.length == 0) 414.2372 - return 0; 414.2373 - return vsum(xs) / xs.length; 414.2374 - } 414.2375 - 414.2376 - static public double vrms(float[] xs){ 414.2377 - if(xs.length == 0) 414.2378 - return 0; 414.2379 - float ret = 0; 414.2380 - for(int i = 0; i < xs.length; i++) 414.2381 - ret += xs[i] * xs[i]; 414.2382 - return Math.sqrt(ret / xs.length); 414.2383 - } 414.2384 - 414.2385 - static public float vsum(float[] xs){ 414.2386 - float ret = 0; 414.2387 - for(int i = 0; i < xs.length; i++) 414.2388 - ret += xs[i]; 414.2389 - return ret; 414.2390 - } 414.2391 - 414.2392 - static public boolean vequiv(float[] xs, float[] ys){ 414.2393 - return Arrays.equals(xs, ys); 414.2394 - } 414.2395 - 414.2396 - static public float[] vadd(float[] x, float[] ys){ 414.2397 - final float[] xs = x.clone(); 414.2398 - for(int i = 0; i < xs.length; i++) 414.2399 - xs[i] += ys[i]; 414.2400 - return xs; 414.2401 - } 414.2402 - 414.2403 - static public float[] vsub(float[] x, float[] ys){ 414.2404 - final float[] xs = x.clone(); 414.2405 - for(int i = 0; i < xs.length; i++) 414.2406 - xs[i] -= ys[i]; 414.2407 - return xs; 414.2408 - } 414.2409 - 414.2410 - static public float[] vaddmul(float[] x, float[] ys, float[] zs){ 414.2411 - final float[] xs = x.clone(); 414.2412 - for(int i = 0; i < xs.length; i++) 414.2413 - xs[i] = (xs[i] + ys[i]) * zs[i]; 414.2414 - return xs; 414.2415 - } 414.2416 - 414.2417 - static public float[] vsubmul(float[] x, float[] ys, float[] zs){ 414.2418 - final float[] xs = x.clone(); 414.2419 - for(int i = 0; i < xs.length; i++) 414.2420 - xs[i] = (xs[i] - ys[i]) * zs[i]; 414.2421 - return xs; 414.2422 - } 414.2423 - 414.2424 - static public float[] vaddsmul(float[] x, float[] ys, float z){ 414.2425 - final float[] xs = x.clone(); 414.2426 - for(int i = 0; i < xs.length; i++) 414.2427 - xs[i] = (xs[i] + ys[i]) * z; 414.2428 - return xs; 414.2429 - } 414.2430 - 414.2431 - static public float[] vsubsmul(float[] x, float[] ys, float z){ 414.2432 - final float[] xs = x.clone(); 414.2433 - for(int i = 0; i < xs.length; i++) 414.2434 - xs[i] = (xs[i] - ys[i]) * z; 414.2435 - return xs; 414.2436 - } 414.2437 - 414.2438 - static public float[] vmulsadd(float[] x, float[] ys, float z){ 414.2439 - final float[] xs = x.clone(); 414.2440 - for(int i = 0; i < xs.length; i++) 414.2441 - xs[i] = (xs[i] * ys[i]) + z; 414.2442 - return xs; 414.2443 - } 414.2444 - 414.2445 - static public float[] vdiv(float[] x, float[] ys){ 414.2446 - final float[] xs = x.clone(); 414.2447 - for(int i = 0; i < xs.length; i++) 414.2448 - xs[i] /= ys[i]; 414.2449 - return xs; 414.2450 - } 414.2451 - 414.2452 - static public float[] vmul(float[] x, float[] ys){ 414.2453 - final float[] xs = x.clone(); 414.2454 - for(int i = 0; i < xs.length; i++) 414.2455 - xs[i] *= ys[i]; 414.2456 - return xs; 414.2457 - } 414.2458 - 414.2459 - static public float[] vmuladd(float[] x, float[] ys, float[] zs){ 414.2460 - final float[] xs = x.clone(); 414.2461 - for(int i = 0; i < xs.length; i++) 414.2462 - xs[i] = (xs[i] * ys[i]) + zs[i]; 414.2463 - return xs; 414.2464 - } 414.2465 - 414.2466 - static public float[] vmulsub(float[] x, float[] ys, float[] zs){ 414.2467 - final float[] xs = x.clone(); 414.2468 - for(int i = 0; i < xs.length; i++) 414.2469 - xs[i] = (xs[i] * ys[i]) - zs[i]; 414.2470 - return xs; 414.2471 - } 414.2472 - 414.2473 - static public float[] vmax(float[] x, float[] ys){ 414.2474 - final float[] xs = x.clone(); 414.2475 - for(int i = 0; i < xs.length; i++) 414.2476 - xs[i] = Math.max(xs[i], ys[i]); 414.2477 - return xs; 414.2478 - } 414.2479 - 414.2480 - static public float[] vmin(float[] x, float[] ys){ 414.2481 - final float[] xs = x.clone(); 414.2482 - for(int i = 0; i < xs.length; i++) 414.2483 - xs[i] = Math.min(xs[i], ys[i]); 414.2484 - return xs; 414.2485 - } 414.2486 - 414.2487 - static public float[] vmap(IFn fn, float[] x) throws Exception{ 414.2488 - float[] xs = x.clone(); 414.2489 - for(int i = 0; i < xs.length; i++) 414.2490 - xs[i] = ((Number) fn.invoke(xs[i])).floatValue(); 414.2491 - return xs; 414.2492 - } 414.2493 - 414.2494 - static public float[] vmap(IFn fn, float[] x, float[] ys) throws Exception{ 414.2495 - float[] xs = x.clone(); 414.2496 - for(int i = 0; i < xs.length; i++) 414.2497 - xs[i] = ((Number) fn.invoke(xs[i], ys[i])).floatValue(); 414.2498 - return xs; 414.2499 - } 414.2500 - 414.2501 -} 414.2502 - 414.2503 -static public class D{ 414.2504 - static public double add(double x, double y){ 414.2505 - return x + y; 414.2506 - } 414.2507 - 414.2508 - static public double subtract(double x, double y){ 414.2509 - return x - y; 414.2510 - } 414.2511 - 414.2512 - static public double negate(double x){ 414.2513 - return -x; 414.2514 - } 414.2515 - 414.2516 - static public double inc(double x){ 414.2517 - return x + 1; 414.2518 - } 414.2519 - 414.2520 - static public double dec(double x){ 414.2521 - return x - 1; 414.2522 - } 414.2523 - 414.2524 - static public double multiply(double x, double y){ 414.2525 - return x * y; 414.2526 - } 414.2527 - 414.2528 - static public double divide(double x, double y){ 414.2529 - return x / y; 414.2530 - } 414.2531 - 414.2532 - static public boolean equiv(double x, double y){ 414.2533 - return x == y; 414.2534 - } 414.2535 - 414.2536 - static public boolean lt(double x, double y){ 414.2537 - return x < y; 414.2538 - } 414.2539 - 414.2540 - static public boolean lte(double x, double y){ 414.2541 - return x <= y; 414.2542 - } 414.2543 - 414.2544 - static public boolean gt(double x, double y){ 414.2545 - return x > y; 414.2546 - } 414.2547 - 414.2548 - static public boolean gte(double x, double y){ 414.2549 - return x >= y; 414.2550 - } 414.2551 - 414.2552 - static public boolean pos(double x){ 414.2553 - return x > 0; 414.2554 - } 414.2555 - 414.2556 - static public boolean neg(double x){ 414.2557 - return x < 0; 414.2558 - } 414.2559 - 414.2560 - static public boolean zero(double x){ 414.2561 - return x == 0; 414.2562 - } 414.2563 - 414.2564 - static public double aget(double[] xs, int i){ 414.2565 - return xs[i]; 414.2566 - } 414.2567 - 414.2568 - static public double aset(double[] xs, int i, double v){ 414.2569 - xs[i] = v; 414.2570 - return v; 414.2571 - } 414.2572 - 414.2573 - static public int alength(double[] xs){ 414.2574 - return xs.length; 414.2575 - } 414.2576 - 414.2577 - static public double[] aclone(double[] xs){ 414.2578 - return xs.clone(); 414.2579 - } 414.2580 - 414.2581 - static public double[] vec(int size, Object init){ 414.2582 - double[] ret = new double[size]; 414.2583 - if(init instanceof Number) 414.2584 - { 414.2585 - double f = ((Number) init).doubleValue(); 414.2586 - for(int i = 0; i < ret.length; i++) 414.2587 - ret[i] = f; 414.2588 - } 414.2589 - else 414.2590 - { 414.2591 - ISeq s = RT.seq(init); 414.2592 - for(int i = 0; i < size && s != null; i++, s = s.rest()) 414.2593 - ret[i] = ((Number) s.first()).doubleValue(); 414.2594 - } 414.2595 - return ret; 414.2596 - } 414.2597 - 414.2598 - static public double[] vec(Object sizeOrSeq){ 414.2599 - if(sizeOrSeq instanceof Number) 414.2600 - return new double[((Number) sizeOrSeq).intValue()]; 414.2601 - else 414.2602 - { 414.2603 - ISeq s = RT.seq(sizeOrSeq); 414.2604 - int size = s.count(); 414.2605 - double[] ret = new double[size]; 414.2606 - for(int i = 0; i < size && s != null; i++, s = s.rest()) 414.2607 - ret[i] = ((Number) s.first()).intValue(); 414.2608 - return ret; 414.2609 - } 414.2610 - } 414.2611 - 414.2612 - static public double[] vsadd(double[] x, double y){ 414.2613 - final double[] xs = x.clone(); 414.2614 - for(int i = 0; i < xs.length; i++) 414.2615 - xs[i] += y; 414.2616 - return xs; 414.2617 - } 414.2618 - 414.2619 - static public double[] vssub(double[] x, double y){ 414.2620 - final double[] xs = x.clone(); 414.2621 - for(int i = 0; i < xs.length; i++) 414.2622 - xs[i] -= y; 414.2623 - return xs; 414.2624 - } 414.2625 - 414.2626 - static public double[] vsdiv(double[] x, double y){ 414.2627 - final double[] xs = x.clone(); 414.2628 - for(int i = 0; i < xs.length; i++) 414.2629 - xs[i] /= y; 414.2630 - return xs; 414.2631 - } 414.2632 - 414.2633 - static public double[] vsmul(double[] x, double y){ 414.2634 - final double[] xs = x.clone(); 414.2635 - for(int i = 0; i < xs.length; i++) 414.2636 - xs[i] *= y; 414.2637 - return xs; 414.2638 - } 414.2639 - 414.2640 - static public double[] svdiv(double y, double[] x){ 414.2641 - final double[] xs = x.clone(); 414.2642 - for(int i = 0; i < xs.length; i++) 414.2643 - xs[i] = y / xs[i]; 414.2644 - return xs; 414.2645 - } 414.2646 - 414.2647 - static public double[] vsmuladd(double[] x, double y, double[] zs){ 414.2648 - final double[] xs = x.clone(); 414.2649 - for(int i = 0; i < xs.length; i++) 414.2650 - xs[i] = xs[i] * y + zs[i]; 414.2651 - return xs; 414.2652 - } 414.2653 - 414.2654 - static public double[] vsmulsub(double[] x, double y, double[] zs){ 414.2655 - final double[] xs = x.clone(); 414.2656 - for(int i = 0; i < xs.length; i++) 414.2657 - xs[i] = xs[i] * y - zs[i]; 414.2658 - return xs; 414.2659 - } 414.2660 - 414.2661 - static public double[] vsmulsadd(double[] x, double y, double z){ 414.2662 - final double[] xs = x.clone(); 414.2663 - for(int i = 0; i < xs.length; i++) 414.2664 - xs[i] = xs[i] * y + z; 414.2665 - return xs; 414.2666 - } 414.2667 - 414.2668 - static public double[] vsmulssub(double[] x, double y, double z){ 414.2669 - final double[] xs = x.clone(); 414.2670 - for(int i = 0; i < xs.length; i++) 414.2671 - xs[i] = xs[i] * y - z; 414.2672 - return xs; 414.2673 - } 414.2674 - 414.2675 - static public double[] vabs(double[] x){ 414.2676 - final double[] xs = x.clone(); 414.2677 - for(int i = 0; i < xs.length; i++) 414.2678 - xs[i] = Math.abs(xs[i]); 414.2679 - return xs; 414.2680 - } 414.2681 - 414.2682 - static public double[] vnegabs(double[] x){ 414.2683 - final double[] xs = x.clone(); 414.2684 - for(int i = 0; i < xs.length; i++) 414.2685 - xs[i] = -Math.abs(xs[i]); 414.2686 - return xs; 414.2687 - } 414.2688 - 414.2689 - static public double[] vneg(double[] x){ 414.2690 - final double[] xs = x.clone(); 414.2691 - for(int i = 0; i < xs.length; i++) 414.2692 - xs[i] = -xs[i]; 414.2693 - return xs; 414.2694 - } 414.2695 - 414.2696 - static public double[] vsqr(double[] x){ 414.2697 - final double[] xs = x.clone(); 414.2698 - for(int i = 0; i < xs.length; i++) 414.2699 - xs[i] *= xs[i]; 414.2700 - return xs; 414.2701 - } 414.2702 - 414.2703 - static public double[] vsignedsqr(double[] x){ 414.2704 - final double[] xs = x.clone(); 414.2705 - for(int i = 0; i < xs.length; i++) 414.2706 - xs[i] *= Math.abs(xs[i]); 414.2707 - return xs; 414.2708 - } 414.2709 - 414.2710 - static public double[] vclip(double[] x, double low, double high){ 414.2711 - final double[] xs = x.clone(); 414.2712 - for(int i = 0; i < xs.length; i++) 414.2713 - { 414.2714 - if(xs[i] < low) 414.2715 - xs[i] = low; 414.2716 - else if(xs[i] > high) 414.2717 - xs[i] = high; 414.2718 - } 414.2719 - return xs; 414.2720 - } 414.2721 - 414.2722 - static public IPersistentVector vclipcounts(double[] x, double low, double high){ 414.2723 - final double[] xs = x.clone(); 414.2724 - int lowc = 0; 414.2725 - int highc = 0; 414.2726 - 414.2727 - for(int i = 0; i < xs.length; i++) 414.2728 - { 414.2729 - if(xs[i] < low) 414.2730 - { 414.2731 - ++lowc; 414.2732 - xs[i] = low; 414.2733 - } 414.2734 - else if(xs[i] > high) 414.2735 - { 414.2736 - ++highc; 414.2737 - xs[i] = high; 414.2738 - } 414.2739 - } 414.2740 - return RT.vector(xs, lowc, highc); 414.2741 - } 414.2742 - 414.2743 - static public double[] vthresh(double[] x, double thresh, double otherwise){ 414.2744 - final double[] xs = x.clone(); 414.2745 - for(int i = 0; i < xs.length; i++) 414.2746 - { 414.2747 - if(xs[i] < thresh) 414.2748 - xs[i] = otherwise; 414.2749 - } 414.2750 - return xs; 414.2751 - } 414.2752 - 414.2753 - static public double[] vreverse(double[] x){ 414.2754 - final double[] xs = x.clone(); 414.2755 - for(int i = 0; i < xs.length; i++) 414.2756 - xs[i] = xs[xs.length - i - 1]; 414.2757 - return xs; 414.2758 - } 414.2759 - 414.2760 - static public double[] vrunningsum(double[] x){ 414.2761 - final double[] xs = x.clone(); 414.2762 - for(int i = 1; i < xs.length; i++) 414.2763 - xs[i] = xs[i - 1] + xs[i]; 414.2764 - return xs; 414.2765 - } 414.2766 - 414.2767 - static public double[] vsort(double[] x){ 414.2768 - final double[] xs = x.clone(); 414.2769 - Arrays.sort(xs); 414.2770 - return xs; 414.2771 - } 414.2772 - 414.2773 - static public double vdot(double[] xs, double[] ys){ 414.2774 - double ret = 0; 414.2775 - for(int i = 0; i < xs.length; i++) 414.2776 - ret += xs[i] * ys[i]; 414.2777 - return ret; 414.2778 - } 414.2779 - 414.2780 - static public double vmax(double[] xs){ 414.2781 - if(xs.length == 0) 414.2782 - return 0; 414.2783 - double ret = xs[0]; 414.2784 - for(int i = 0; i < xs.length; i++) 414.2785 - ret = Math.max(ret, xs[i]); 414.2786 - return ret; 414.2787 - } 414.2788 - 414.2789 - static public double vmin(double[] xs){ 414.2790 - if(xs.length == 0) 414.2791 - return 0; 414.2792 - double ret = xs[0]; 414.2793 - for(int i = 0; i < xs.length; i++) 414.2794 - ret = Math.min(ret, xs[i]); 414.2795 - return ret; 414.2796 - } 414.2797 - 414.2798 - static public double vmean(double[] xs){ 414.2799 - if(xs.length == 0) 414.2800 - return 0; 414.2801 - return vsum(xs) / xs.length; 414.2802 - } 414.2803 - 414.2804 - static public double vrms(double[] xs){ 414.2805 - if(xs.length == 0) 414.2806 - return 0; 414.2807 - double ret = 0; 414.2808 - for(int i = 0; i < xs.length; i++) 414.2809 - ret += xs[i] * xs[i]; 414.2810 - return Math.sqrt(ret / xs.length); 414.2811 - } 414.2812 - 414.2813 - static public double vsum(double[] xs){ 414.2814 - double ret = 0; 414.2815 - for(int i = 0; i < xs.length; i++) 414.2816 - ret += xs[i]; 414.2817 - return ret; 414.2818 - } 414.2819 - 414.2820 - static public boolean vequiv(double[] xs, double[] ys){ 414.2821 - return Arrays.equals(xs, ys); 414.2822 - } 414.2823 - 414.2824 - static public double[] vadd(double[] x, double[] ys){ 414.2825 - final double[] xs = x.clone(); 414.2826 - for(int i = 0; i < xs.length; i++) 414.2827 - xs[i] += ys[i]; 414.2828 - return xs; 414.2829 - } 414.2830 - 414.2831 - static public double[] vsub(double[] x, double[] ys){ 414.2832 - final double[] xs = x.clone(); 414.2833 - for(int i = 0; i < xs.length; i++) 414.2834 - xs[i] -= ys[i]; 414.2835 - return xs; 414.2836 - } 414.2837 - 414.2838 - static public double[] vaddmul(double[] x, double[] ys, double[] zs){ 414.2839 - final double[] xs = x.clone(); 414.2840 - for(int i = 0; i < xs.length; i++) 414.2841 - xs[i] = (xs[i] + ys[i]) * zs[i]; 414.2842 - return xs; 414.2843 - } 414.2844 - 414.2845 - static public double[] vsubmul(double[] x, double[] ys, double[] zs){ 414.2846 - final double[] xs = x.clone(); 414.2847 - for(int i = 0; i < xs.length; i++) 414.2848 - xs[i] = (xs[i] - ys[i]) * zs[i]; 414.2849 - return xs; 414.2850 - } 414.2851 - 414.2852 - static public double[] vaddsmul(double[] x, double[] ys, double z){ 414.2853 - final double[] xs = x.clone(); 414.2854 - for(int i = 0; i < xs.length; i++) 414.2855 - xs[i] = (xs[i] + ys[i]) * z; 414.2856 - return xs; 414.2857 - } 414.2858 - 414.2859 - static public double[] vsubsmul(double[] x, double[] ys, double z){ 414.2860 - final double[] xs = x.clone(); 414.2861 - for(int i = 0; i < xs.length; i++) 414.2862 - xs[i] = (xs[i] - ys[i]) * z; 414.2863 - return xs; 414.2864 - } 414.2865 - 414.2866 - static public double[] vmulsadd(double[] x, double[] ys, double z){ 414.2867 - final double[] xs = x.clone(); 414.2868 - for(int i = 0; i < xs.length; i++) 414.2869 - xs[i] = (xs[i] * ys[i]) + z; 414.2870 - return xs; 414.2871 - } 414.2872 - 414.2873 - static public double[] vdiv(double[] x, double[] ys){ 414.2874 - final double[] xs = x.clone(); 414.2875 - for(int i = 0; i < xs.length; i++) 414.2876 - xs[i] /= ys[i]; 414.2877 - return xs; 414.2878 - } 414.2879 - 414.2880 - static public double[] vmul(double[] x, double[] ys){ 414.2881 - final double[] xs = x.clone(); 414.2882 - for(int i = 0; i < xs.length; i++) 414.2883 - xs[i] *= ys[i]; 414.2884 - return xs; 414.2885 - } 414.2886 - 414.2887 - static public double[] vmuladd(double[] x, double[] ys, double[] zs){ 414.2888 - final double[] xs = x.clone(); 414.2889 - for(int i = 0; i < xs.length; i++) 414.2890 - xs[i] = (xs[i] * ys[i]) + zs[i]; 414.2891 - return xs; 414.2892 - } 414.2893 - 414.2894 - static public double[] vmulsub(double[] x, double[] ys, double[] zs){ 414.2895 - final double[] xs = x.clone(); 414.2896 - for(int i = 0; i < xs.length; i++) 414.2897 - xs[i] = (xs[i] * ys[i]) - zs[i]; 414.2898 - return xs; 414.2899 - } 414.2900 - 414.2901 - static public double[] vmax(double[] x, double[] ys){ 414.2902 - final double[] xs = x.clone(); 414.2903 - for(int i = 0; i < xs.length; i++) 414.2904 - xs[i] = Math.max(xs[i], ys[i]); 414.2905 - return xs; 414.2906 - } 414.2907 - 414.2908 - static public double[] vmin(double[] x, double[] ys){ 414.2909 - final double[] xs = x.clone(); 414.2910 - for(int i = 0; i < xs.length; i++) 414.2911 - xs[i] = Math.min(xs[i], ys[i]); 414.2912 - return xs; 414.2913 - } 414.2914 - 414.2915 - static public double[] vmap(IFn fn, double[] x) throws Exception{ 414.2916 - double[] xs = x.clone(); 414.2917 - for(int i = 0; i < xs.length; i++) 414.2918 - xs[i] = ((Number) fn.invoke(xs[i])).doubleValue(); 414.2919 - return xs; 414.2920 - } 414.2921 - 414.2922 - static public double[] vmap(IFn fn, double[] x, double[] ys) throws Exception{ 414.2923 - double[] xs = x.clone(); 414.2924 - for(int i = 0; i < xs.length; i++) 414.2925 - xs[i] = ((Number) fn.invoke(xs[i], ys[i])).doubleValue(); 414.2926 - return xs; 414.2927 - } 414.2928 -} 414.2929 - 414.2930 -static public class I{ 414.2931 - static public int add(int x, int y){ 414.2932 - return x + y; 414.2933 - } 414.2934 - 414.2935 - static public int subtract(int x, int y){ 414.2936 - return x - y; 414.2937 - } 414.2938 - 414.2939 - static public int negate(int x){ 414.2940 - return -x; 414.2941 - } 414.2942 - 414.2943 - static public int inc(int x){ 414.2944 - return x + 1; 414.2945 - } 414.2946 - 414.2947 - static public int dec(int x){ 414.2948 - return x - 1; 414.2949 - } 414.2950 - 414.2951 - static public int multiply(int x, int y){ 414.2952 - return x * y; 414.2953 - } 414.2954 - 414.2955 - static public int divide(int x, int y){ 414.2956 - return x / y; 414.2957 - } 414.2958 - 414.2959 - static public boolean equiv(int x, int y){ 414.2960 - return x == y; 414.2961 - } 414.2962 - 414.2963 - static public boolean lt(int x, int y){ 414.2964 - return x < y; 414.2965 - } 414.2966 - 414.2967 - static public boolean lte(int x, int y){ 414.2968 - return x <= y; 414.2969 - } 414.2970 - 414.2971 - static public boolean gt(int x, int y){ 414.2972 - return x > y; 414.2973 - } 414.2974 - 414.2975 - static public boolean gte(int x, int y){ 414.2976 - return x >= y; 414.2977 - } 414.2978 - 414.2979 - static public boolean pos(int x){ 414.2980 - return x > 0; 414.2981 - } 414.2982 - 414.2983 - static public boolean neg(int x){ 414.2984 - return x < 0; 414.2985 - } 414.2986 - 414.2987 - static public boolean zero(int x){ 414.2988 - return x == 0; 414.2989 - } 414.2990 - 414.2991 - static public int aget(int[] xs, int i){ 414.2992 - return xs[i]; 414.2993 - } 414.2994 - 414.2995 - static public int aset(int[] xs, int i, int v){ 414.2996 - xs[i] = v; 414.2997 - return v; 414.2998 - } 414.2999 - 414.3000 - static public int alength(int[] xs){ 414.3001 - return xs.length; 414.3002 - } 414.3003 - 414.3004 - static public int[] aclone(int[] xs){ 414.3005 - return xs.clone(); 414.3006 - } 414.3007 - 414.3008 - static public int[] vec(int size, Object init){ 414.3009 - int[] ret = new int[size]; 414.3010 - if(init instanceof Number) 414.3011 - { 414.3012 - int f = ((Number) init).intValue(); 414.3013 - for(int i = 0; i < ret.length; i++) 414.3014 - ret[i] = f; 414.3015 - } 414.3016 - else 414.3017 - { 414.3018 - ISeq s = RT.seq(init); 414.3019 - for(int i = 0; i < size && s != null; i++, s = s.rest()) 414.3020 - ret[i] = ((Number) s.first()).intValue(); 414.3021 - } 414.3022 - return ret; 414.3023 - } 414.3024 - 414.3025 - static public int[] vec(Object sizeOrSeq){ 414.3026 - if(sizeOrSeq instanceof Number) 414.3027 - return new int[((Number) sizeOrSeq).intValue()]; 414.3028 - else 414.3029 - { 414.3030 - ISeq s = RT.seq(sizeOrSeq); 414.3031 - int size = s.count(); 414.3032 - int[] ret = new int[size]; 414.3033 - for(int i = 0; i < size && s != null; i++, s = s.rest()) 414.3034 - ret[i] = ((Number) s.first()).intValue(); 414.3035 - return ret; 414.3036 - } 414.3037 - } 414.3038 - 414.3039 - static public int[] vsadd(int[] x, int y){ 414.3040 - final int[] xs = x.clone(); 414.3041 - for(int i = 0; i < xs.length; i++) 414.3042 - xs[i] += y; 414.3043 - return xs; 414.3044 - } 414.3045 - 414.3046 - static public int[] vssub(int[] x, int y){ 414.3047 - final int[] xs = x.clone(); 414.3048 - for(int i = 0; i < xs.length; i++) 414.3049 - xs[i] -= y; 414.3050 - return xs; 414.3051 - } 414.3052 - 414.3053 - static public int[] vsdiv(int[] x, int y){ 414.3054 - final int[] xs = x.clone(); 414.3055 - for(int i = 0; i < xs.length; i++) 414.3056 - xs[i] /= y; 414.3057 - return xs; 414.3058 - } 414.3059 - 414.3060 - static public int[] vsmul(int[] x, int y){ 414.3061 - final int[] xs = x.clone(); 414.3062 - for(int i = 0; i < xs.length; i++) 414.3063 - xs[i] *= y; 414.3064 - return xs; 414.3065 - } 414.3066 - 414.3067 - static public int[] svdiv(int y, int[] x){ 414.3068 - final int[] xs = x.clone(); 414.3069 - for(int i = 0; i < xs.length; i++) 414.3070 - xs[i] = y / xs[i]; 414.3071 - return xs; 414.3072 - } 414.3073 - 414.3074 - static public int[] vsmuladd(int[] x, int y, int[] zs){ 414.3075 - final int[] xs = x.clone(); 414.3076 - for(int i = 0; i < xs.length; i++) 414.3077 - xs[i] = xs[i] * y + zs[i]; 414.3078 - return xs; 414.3079 - } 414.3080 - 414.3081 - static public int[] vsmulsub(int[] x, int y, int[] zs){ 414.3082 - final int[] xs = x.clone(); 414.3083 - for(int i = 0; i < xs.length; i++) 414.3084 - xs[i] = xs[i] * y - zs[i]; 414.3085 - return xs; 414.3086 - } 414.3087 - 414.3088 - static public int[] vsmulsadd(int[] x, int y, int z){ 414.3089 - final int[] xs = x.clone(); 414.3090 - for(int i = 0; i < xs.length; i++) 414.3091 - xs[i] = xs[i] * y + z; 414.3092 - return xs; 414.3093 - } 414.3094 - 414.3095 - static public int[] vsmulssub(int[] x, int y, int z){ 414.3096 - final int[] xs = x.clone(); 414.3097 - for(int i = 0; i < xs.length; i++) 414.3098 - xs[i] = xs[i] * y - z; 414.3099 - return xs; 414.3100 - } 414.3101 - 414.3102 - static public int[] vabs(int[] x){ 414.3103 - final int[] xs = x.clone(); 414.3104 - for(int i = 0; i < xs.length; i++) 414.3105 - xs[i] = Math.abs(xs[i]); 414.3106 - return xs; 414.3107 - } 414.3108 - 414.3109 - static public int[] vnegabs(int[] x){ 414.3110 - final int[] xs = x.clone(); 414.3111 - for(int i = 0; i < xs.length; i++) 414.3112 - xs[i] = -Math.abs(xs[i]); 414.3113 - return xs; 414.3114 - } 414.3115 - 414.3116 - static public int[] vneg(int[] x){ 414.3117 - final int[] xs = x.clone(); 414.3118 - for(int i = 0; i < xs.length; i++) 414.3119 - xs[i] = -xs[i]; 414.3120 - return xs; 414.3121 - } 414.3122 - 414.3123 - static public int[] vsqr(int[] x){ 414.3124 - final int[] xs = x.clone(); 414.3125 - for(int i = 0; i < xs.length; i++) 414.3126 - xs[i] *= xs[i]; 414.3127 - return xs; 414.3128 - } 414.3129 - 414.3130 - static public int[] vsignedsqr(int[] x){ 414.3131 - final int[] xs = x.clone(); 414.3132 - for(int i = 0; i < xs.length; i++) 414.3133 - xs[i] *= Math.abs(xs[i]); 414.3134 - return xs; 414.3135 - } 414.3136 - 414.3137 - static public int[] vclip(int[] x, int low, int high){ 414.3138 - final int[] xs = x.clone(); 414.3139 - for(int i = 0; i < xs.length; i++) 414.3140 - { 414.3141 - if(xs[i] < low) 414.3142 - xs[i] = low; 414.3143 - else if(xs[i] > high) 414.3144 - xs[i] = high; 414.3145 - } 414.3146 - return xs; 414.3147 - } 414.3148 - 414.3149 - static public IPersistentVector vclipcounts(int[] x, int low, int high){ 414.3150 - final int[] xs = x.clone(); 414.3151 - int lowc = 0; 414.3152 - int highc = 0; 414.3153 - 414.3154 - for(int i = 0; i < xs.length; i++) 414.3155 - { 414.3156 - if(xs[i] < low) 414.3157 - { 414.3158 - ++lowc; 414.3159 - xs[i] = low; 414.3160 - } 414.3161 - else if(xs[i] > high) 414.3162 - { 414.3163 - ++highc; 414.3164 - xs[i] = high; 414.3165 - } 414.3166 - } 414.3167 - return RT.vector(xs, lowc, highc); 414.3168 - } 414.3169 - 414.3170 - static public int[] vthresh(int[] x, int thresh, int otherwise){ 414.3171 - final int[] xs = x.clone(); 414.3172 - for(int i = 0; i < xs.length; i++) 414.3173 - { 414.3174 - if(xs[i] < thresh) 414.3175 - xs[i] = otherwise; 414.3176 - } 414.3177 - return xs; 414.3178 - } 414.3179 - 414.3180 - static public int[] vreverse(int[] x){ 414.3181 - final int[] xs = x.clone(); 414.3182 - for(int i = 0; i < xs.length; i++) 414.3183 - xs[i] = xs[xs.length - i - 1]; 414.3184 - return xs; 414.3185 - } 414.3186 - 414.3187 - static public int[] vrunningsum(int[] x){ 414.3188 - final int[] xs = x.clone(); 414.3189 - for(int i = 1; i < xs.length; i++) 414.3190 - xs[i] = xs[i - 1] + xs[i]; 414.3191 - return xs; 414.3192 - } 414.3193 - 414.3194 - static public int[] vsort(int[] x){ 414.3195 - final int[] xs = x.clone(); 414.3196 - Arrays.sort(xs); 414.3197 - return xs; 414.3198 - } 414.3199 - 414.3200 - static public int vdot(int[] xs, int[] ys){ 414.3201 - int ret = 0; 414.3202 - for(int i = 0; i < xs.length; i++) 414.3203 - ret += xs[i] * ys[i]; 414.3204 - return ret; 414.3205 - } 414.3206 - 414.3207 - static public int vmax(int[] xs){ 414.3208 - if(xs.length == 0) 414.3209 - return 0; 414.3210 - int ret = xs[0]; 414.3211 - for(int i = 0; i < xs.length; i++) 414.3212 - ret = Math.max(ret, xs[i]); 414.3213 - return ret; 414.3214 - } 414.3215 - 414.3216 - static public int vmin(int[] xs){ 414.3217 - if(xs.length == 0) 414.3218 - return 0; 414.3219 - int ret = xs[0]; 414.3220 - for(int i = 0; i < xs.length; i++) 414.3221 - ret = Math.min(ret, xs[i]); 414.3222 - return ret; 414.3223 - } 414.3224 - 414.3225 - static public double vmean(int[] xs){ 414.3226 - if(xs.length == 0) 414.3227 - return 0; 414.3228 - return vsum(xs) / (double) xs.length; 414.3229 - } 414.3230 - 414.3231 - static public double vrms(int[] xs){ 414.3232 - if(xs.length == 0) 414.3233 - return 0; 414.3234 - int ret = 0; 414.3235 - for(int i = 0; i < xs.length; i++) 414.3236 - ret += xs[i] * xs[i]; 414.3237 - return Math.sqrt(ret / (double) xs.length); 414.3238 - } 414.3239 - 414.3240 - static public int vsum(int[] xs){ 414.3241 - int ret = 0; 414.3242 - for(int i = 0; i < xs.length; i++) 414.3243 - ret += xs[i]; 414.3244 - return ret; 414.3245 - } 414.3246 - 414.3247 - static public boolean vequiv(int[] xs, int[] ys){ 414.3248 - return Arrays.equals(xs, ys); 414.3249 - } 414.3250 - 414.3251 - static public int[] vadd(int[] x, int[] ys){ 414.3252 - final int[] xs = x.clone(); 414.3253 - for(int i = 0; i < xs.length; i++) 414.3254 - xs[i] += ys[i]; 414.3255 - return xs; 414.3256 - } 414.3257 - 414.3258 - static public int[] vsub(int[] x, int[] ys){ 414.3259 - final int[] xs = x.clone(); 414.3260 - for(int i = 0; i < xs.length; i++) 414.3261 - xs[i] -= ys[i]; 414.3262 - return xs; 414.3263 - } 414.3264 - 414.3265 - static public int[] vaddmul(int[] x, int[] ys, int[] zs){ 414.3266 - final int[] xs = x.clone(); 414.3267 - for(int i = 0; i < xs.length; i++) 414.3268 - xs[i] = (xs[i] + ys[i]) * zs[i]; 414.3269 - return xs; 414.3270 - } 414.3271 - 414.3272 - static public int[] vsubmul(int[] x, int[] ys, int[] zs){ 414.3273 - final int[] xs = x.clone(); 414.3274 - for(int i = 0; i < xs.length; i++) 414.3275 - xs[i] = (xs[i] - ys[i]) * zs[i]; 414.3276 - return xs; 414.3277 - } 414.3278 - 414.3279 - static public int[] vaddsmul(int[] x, int[] ys, int z){ 414.3280 - final int[] xs = x.clone(); 414.3281 - for(int i = 0; i < xs.length; i++) 414.3282 - xs[i] = (xs[i] + ys[i]) * z; 414.3283 - return xs; 414.3284 - } 414.3285 - 414.3286 - static public int[] vsubsmul(int[] x, int[] ys, int z){ 414.3287 - final int[] xs = x.clone(); 414.3288 - for(int i = 0; i < xs.length; i++) 414.3289 - xs[i] = (xs[i] - ys[i]) * z; 414.3290 - return xs; 414.3291 - } 414.3292 - 414.3293 - static public int[] vmulsadd(int[] x, int[] ys, int z){ 414.3294 - final int[] xs = x.clone(); 414.3295 - for(int i = 0; i < xs.length; i++) 414.3296 - xs[i] = (xs[i] * ys[i]) + z; 414.3297 - return xs; 414.3298 - } 414.3299 - 414.3300 - static public int[] vdiv(int[] x, int[] ys){ 414.3301 - final int[] xs = x.clone(); 414.3302 - for(int i = 0; i < xs.length; i++) 414.3303 - xs[i] /= ys[i]; 414.3304 - return xs; 414.3305 - } 414.3306 - 414.3307 - static public int[] vmul(int[] x, int[] ys){ 414.3308 - final int[] xs = x.clone(); 414.3309 - for(int i = 0; i < xs.length; i++) 414.3310 - xs[i] *= ys[i]; 414.3311 - return xs; 414.3312 - } 414.3313 - 414.3314 - static public int[] vmuladd(int[] x, int[] ys, int[] zs){ 414.3315 - final int[] xs = x.clone(); 414.3316 - for(int i = 0; i < xs.length; i++) 414.3317 - xs[i] = (xs[i] * ys[i]) + zs[i]; 414.3318 - return xs; 414.3319 - } 414.3320 - 414.3321 - static public int[] vmulsub(int[] x, int[] ys, int[] zs){ 414.3322 - final int[] xs = x.clone(); 414.3323 - for(int i = 0; i < xs.length; i++) 414.3324 - xs[i] = (xs[i] * ys[i]) - zs[i]; 414.3325 - return xs; 414.3326 - } 414.3327 - 414.3328 - static public int[] vmax(int[] x, int[] ys){ 414.3329 - final int[] xs = x.clone(); 414.3330 - for(int i = 0; i < xs.length; i++) 414.3331 - xs[i] = Math.max(xs[i], ys[i]); 414.3332 - return xs; 414.3333 - } 414.3334 - 414.3335 - static public int[] vmin(int[] x, int[] ys){ 414.3336 - final int[] xs = x.clone(); 414.3337 - for(int i = 0; i < xs.length; i++) 414.3338 - xs[i] = Math.min(xs[i], ys[i]); 414.3339 - return xs; 414.3340 - } 414.3341 - 414.3342 - static public int[] vmap(IFn fn, int[] x) throws Exception{ 414.3343 - int[] xs = x.clone(); 414.3344 - for(int i = 0; i < xs.length; i++) 414.3345 - xs[i] = ((Number) fn.invoke(xs[i])).intValue(); 414.3346 - return xs; 414.3347 - } 414.3348 - 414.3349 - static public int[] vmap(IFn fn, int[] x, int[] ys) throws Exception{ 414.3350 - int[] xs = x.clone(); 414.3351 - for(int i = 0; i < xs.length; i++) 414.3352 - xs[i] = ((Number) fn.invoke(xs[i], ys[i])).intValue(); 414.3353 - return xs; 414.3354 - } 414.3355 - 414.3356 -} 414.3357 - 414.3358 -static public class L{ 414.3359 - static public long add(long x, long y){ 414.3360 - return x + y; 414.3361 - } 414.3362 - 414.3363 - static public long subtract(long x, long y){ 414.3364 - return x - y; 414.3365 - } 414.3366 - 414.3367 - static public long negate(long x){ 414.3368 - return -x; 414.3369 - } 414.3370 - 414.3371 - static public long inc(long x){ 414.3372 - return x + 1; 414.3373 - } 414.3374 - 414.3375 - static public long dec(long x){ 414.3376 - return x - 1; 414.3377 - } 414.3378 - 414.3379 - static public long multiply(long x, long y){ 414.3380 - return x * y; 414.3381 - } 414.3382 - 414.3383 - static public long divide(long x, long y){ 414.3384 - return x / y; 414.3385 - } 414.3386 - 414.3387 - static public boolean equiv(long x, long y){ 414.3388 - return x == y; 414.3389 - } 414.3390 - 414.3391 - static public boolean lt(long x, long y){ 414.3392 - return x < y; 414.3393 - } 414.3394 - 414.3395 - static public boolean lte(long x, long y){ 414.3396 - return x <= y; 414.3397 - } 414.3398 - 414.3399 - static public boolean gt(long x, long y){ 414.3400 - return x > y; 414.3401 - } 414.3402 - 414.3403 - static public boolean gte(long x, long y){ 414.3404 - return x >= y; 414.3405 - } 414.3406 - 414.3407 - static public boolean pos(long x){ 414.3408 - return x > 0; 414.3409 - } 414.3410 - 414.3411 - static public boolean neg(long x){ 414.3412 - return x < 0; 414.3413 - } 414.3414 - 414.3415 - static public boolean zero(long x){ 414.3416 - return x == 0; 414.3417 - } 414.3418 - 414.3419 - static public long aget(long[] xs, int i){ 414.3420 - return xs[i]; 414.3421 - } 414.3422 - 414.3423 - static public long aset(long[] xs, int i, long v){ 414.3424 - xs[i] = v; 414.3425 - return v; 414.3426 - } 414.3427 - 414.3428 - static public int alength(long[] xs){ 414.3429 - return xs.length; 414.3430 - } 414.3431 - 414.3432 - static public long[] aclone(long[] xs){ 414.3433 - return xs.clone(); 414.3434 - } 414.3435 - 414.3436 - static public long[] vec(int size, Object init){ 414.3437 - long[] ret = new long[size]; 414.3438 - if(init instanceof Number) 414.3439 - { 414.3440 - long f = ((Number) init).longValue(); 414.3441 - for(int i = 0; i < ret.length; i++) 414.3442 - ret[i] = f; 414.3443 - } 414.3444 - else 414.3445 - { 414.3446 - ISeq s = RT.seq(init); 414.3447 - for(int i = 0; i < size && s != null; i++, s = s.rest()) 414.3448 - ret[i] = ((Number) s.first()).longValue(); 414.3449 - } 414.3450 - return ret; 414.3451 - } 414.3452 - 414.3453 - static public long[] vec(Object sizeOrSeq){ 414.3454 - if(sizeOrSeq instanceof Number) 414.3455 - return new long[((Number) sizeOrSeq).intValue()]; 414.3456 - else 414.3457 - { 414.3458 - ISeq s = RT.seq(sizeOrSeq); 414.3459 - int size = s.count(); 414.3460 - long[] ret = new long[size]; 414.3461 - for(int i = 0; i < size && s != null; i++, s = s.rest()) 414.3462 - ret[i] = ((Number) s.first()).intValue(); 414.3463 - return ret; 414.3464 - } 414.3465 - } 414.3466 - 414.3467 - 414.3468 - static public long[] vsadd(long[] x, long y){ 414.3469 - final long[] xs = x.clone(); 414.3470 - for(int i = 0; i < xs.length; i++) 414.3471 - xs[i] += y; 414.3472 - return xs; 414.3473 - } 414.3474 - 414.3475 - static public long[] vssub(long[] x, long y){ 414.3476 - final long[] xs = x.clone(); 414.3477 - for(int i = 0; i < xs.length; i++) 414.3478 - xs[i] -= y; 414.3479 - return xs; 414.3480 - } 414.3481 - 414.3482 - static public long[] vsdiv(long[] x, long y){ 414.3483 - final long[] xs = x.clone(); 414.3484 - for(int i = 0; i < xs.length; i++) 414.3485 - xs[i] /= y; 414.3486 - return xs; 414.3487 - } 414.3488 - 414.3489 - static public long[] vsmul(long[] x, long y){ 414.3490 - final long[] xs = x.clone(); 414.3491 - for(int i = 0; i < xs.length; i++) 414.3492 - xs[i] *= y; 414.3493 - return xs; 414.3494 - } 414.3495 - 414.3496 - static public long[] svdiv(long y, long[] x){ 414.3497 - final long[] xs = x.clone(); 414.3498 - for(int i = 0; i < xs.length; i++) 414.3499 - xs[i] = y / xs[i]; 414.3500 - return xs; 414.3501 - } 414.3502 - 414.3503 - static public long[] vsmuladd(long[] x, long y, long[] zs){ 414.3504 - final long[] xs = x.clone(); 414.3505 - for(int i = 0; i < xs.length; i++) 414.3506 - xs[i] = xs[i] * y + zs[i]; 414.3507 - return xs; 414.3508 - } 414.3509 - 414.3510 - static public long[] vsmulsub(long[] x, long y, long[] zs){ 414.3511 - final long[] xs = x.clone(); 414.3512 - for(int i = 0; i < xs.length; i++) 414.3513 - xs[i] = xs[i] * y - zs[i]; 414.3514 - return xs; 414.3515 - } 414.3516 - 414.3517 - static public long[] vsmulsadd(long[] x, long y, long z){ 414.3518 - final long[] xs = x.clone(); 414.3519 - for(int i = 0; i < xs.length; i++) 414.3520 - xs[i] = xs[i] * y + z; 414.3521 - return xs; 414.3522 - } 414.3523 - 414.3524 - static public long[] vsmulssub(long[] x, long y, long z){ 414.3525 - final long[] xs = x.clone(); 414.3526 - for(int i = 0; i < xs.length; i++) 414.3527 - xs[i] = xs[i] * y - z; 414.3528 - return xs; 414.3529 - } 414.3530 - 414.3531 - static public long[] vabs(long[] x){ 414.3532 - final long[] xs = x.clone(); 414.3533 - for(int i = 0; i < xs.length; i++) 414.3534 - xs[i] = Math.abs(xs[i]); 414.3535 - return xs; 414.3536 - } 414.3537 - 414.3538 - static public long[] vnegabs(long[] x){ 414.3539 - final long[] xs = x.clone(); 414.3540 - for(int i = 0; i < xs.length; i++) 414.3541 - xs[i] = -Math.abs(xs[i]); 414.3542 - return xs; 414.3543 - } 414.3544 - 414.3545 - static public long[] vneg(long[] x){ 414.3546 - final long[] xs = x.clone(); 414.3547 - for(int i = 0; i < xs.length; i++) 414.3548 - xs[i] = -xs[i]; 414.3549 - return xs; 414.3550 - } 414.3551 - 414.3552 - static public long[] vsqr(long[] x){ 414.3553 - final long[] xs = x.clone(); 414.3554 - for(int i = 0; i < xs.length; i++) 414.3555 - xs[i] *= xs[i]; 414.3556 - return xs; 414.3557 - } 414.3558 - 414.3559 - static public long[] vsignedsqr(long[] x){ 414.3560 - final long[] xs = x.clone(); 414.3561 - for(int i = 0; i < xs.length; i++) 414.3562 - xs[i] *= Math.abs(xs[i]); 414.3563 - return xs; 414.3564 - } 414.3565 - 414.3566 - static public long[] vclip(long[] x, long low, long high){ 414.3567 - final long[] xs = x.clone(); 414.3568 - for(int i = 0; i < xs.length; i++) 414.3569 - { 414.3570 - if(xs[i] < low) 414.3571 - xs[i] = low; 414.3572 - else if(xs[i] > high) 414.3573 - xs[i] = high; 414.3574 - } 414.3575 - return xs; 414.3576 - } 414.3577 - 414.3578 - static public IPersistentVector vclipcounts(long[] x, long low, long high){ 414.3579 - final long[] xs = x.clone(); 414.3580 - int lowc = 0; 414.3581 - int highc = 0; 414.3582 - 414.3583 - for(int i = 0; i < xs.length; i++) 414.3584 - { 414.3585 - if(xs[i] < low) 414.3586 - { 414.3587 - ++lowc; 414.3588 - xs[i] = low; 414.3589 - } 414.3590 - else if(xs[i] > high) 414.3591 - { 414.3592 - ++highc; 414.3593 - xs[i] = high; 414.3594 - } 414.3595 - } 414.3596 - return RT.vector(xs, lowc, highc); 414.3597 - } 414.3598 - 414.3599 - static public long[] vthresh(long[] x, long thresh, long otherwise){ 414.3600 - final long[] xs = x.clone(); 414.3601 - for(int i = 0; i < xs.length; i++) 414.3602 - { 414.3603 - if(xs[i] < thresh) 414.3604 - xs[i] = otherwise; 414.3605 - } 414.3606 - return xs; 414.3607 - } 414.3608 - 414.3609 - static public long[] vreverse(long[] x){ 414.3610 - final long[] xs = x.clone(); 414.3611 - for(int i = 0; i < xs.length; i++) 414.3612 - xs[i] = xs[xs.length - i - 1]; 414.3613 - return xs; 414.3614 - } 414.3615 - 414.3616 - static public long[] vrunningsum(long[] x){ 414.3617 - final long[] xs = x.clone(); 414.3618 - for(int i = 1; i < xs.length; i++) 414.3619 - xs[i] = xs[i - 1] + xs[i]; 414.3620 - return xs; 414.3621 - } 414.3622 - 414.3623 - static public long[] vsort(long[] x){ 414.3624 - final long[] xs = x.clone(); 414.3625 - Arrays.sort(xs); 414.3626 - return xs; 414.3627 - } 414.3628 - 414.3629 - static public long vdot(long[] xs, long[] ys){ 414.3630 - long ret = 0; 414.3631 - for(int i = 0; i < xs.length; i++) 414.3632 - ret += xs[i] * ys[i]; 414.3633 - return ret; 414.3634 - } 414.3635 - 414.3636 - static public long vmax(long[] xs){ 414.3637 - if(xs.length == 0) 414.3638 - return 0; 414.3639 - long ret = xs[0]; 414.3640 - for(int i = 0; i < xs.length; i++) 414.3641 - ret = Math.max(ret, xs[i]); 414.3642 - return ret; 414.3643 - } 414.3644 - 414.3645 - static public long vmin(long[] xs){ 414.3646 - if(xs.length == 0) 414.3647 - return 0; 414.3648 - long ret = xs[0]; 414.3649 - for(int i = 0; i < xs.length; i++) 414.3650 - ret = Math.min(ret, xs[i]); 414.3651 - return ret; 414.3652 - } 414.3653 - 414.3654 - static public double vmean(long[] xs){ 414.3655 - if(xs.length == 0) 414.3656 - return 0; 414.3657 - return vsum(xs) / (double) xs.length; 414.3658 - } 414.3659 - 414.3660 - static public double vrms(long[] xs){ 414.3661 - if(xs.length == 0) 414.3662 - return 0; 414.3663 - long ret = 0; 414.3664 - for(int i = 0; i < xs.length; i++) 414.3665 - ret += xs[i] * xs[i]; 414.3666 - return Math.sqrt(ret / (double) xs.length); 414.3667 - } 414.3668 - 414.3669 - static public long vsum(long[] xs){ 414.3670 - long ret = 0; 414.3671 - for(int i = 0; i < xs.length; i++) 414.3672 - ret += xs[i]; 414.3673 - return ret; 414.3674 - } 414.3675 - 414.3676 - static public boolean vequiv(long[] xs, long[] ys){ 414.3677 - return Arrays.equals(xs, ys); 414.3678 - } 414.3679 - 414.3680 - static public long[] vadd(long[] x, long[] ys){ 414.3681 - final long[] xs = x.clone(); 414.3682 - for(int i = 0; i < xs.length; i++) 414.3683 - xs[i] += ys[i]; 414.3684 - return xs; 414.3685 - } 414.3686 - 414.3687 - static public long[] vsub(long[] x, long[] ys){ 414.3688 - final long[] xs = x.clone(); 414.3689 - for(int i = 0; i < xs.length; i++) 414.3690 - xs[i] -= ys[i]; 414.3691 - return xs; 414.3692 - } 414.3693 - 414.3694 - static public long[] vaddmul(long[] x, long[] ys, long[] zs){ 414.3695 - final long[] xs = x.clone(); 414.3696 - for(int i = 0; i < xs.length; i++) 414.3697 - xs[i] = (xs[i] + ys[i]) * zs[i]; 414.3698 - return xs; 414.3699 - } 414.3700 - 414.3701 - static public long[] vsubmul(long[] x, long[] ys, long[] zs){ 414.3702 - final long[] xs = x.clone(); 414.3703 - for(int i = 0; i < xs.length; i++) 414.3704 - xs[i] = (xs[i] - ys[i]) * zs[i]; 414.3705 - return xs; 414.3706 - } 414.3707 - 414.3708 - static public long[] vaddsmul(long[] x, long[] ys, long z){ 414.3709 - final long[] xs = x.clone(); 414.3710 - for(int i = 0; i < xs.length; i++) 414.3711 - xs[i] = (xs[i] + ys[i]) * z; 414.3712 - return xs; 414.3713 - } 414.3714 - 414.3715 - static public long[] vsubsmul(long[] x, long[] ys, long z){ 414.3716 - final long[] xs = x.clone(); 414.3717 - for(int i = 0; i < xs.length; i++) 414.3718 - xs[i] = (xs[i] - ys[i]) * z; 414.3719 - return xs; 414.3720 - } 414.3721 - 414.3722 - static public long[] vmulsadd(long[] x, long[] ys, long z){ 414.3723 - final long[] xs = x.clone(); 414.3724 - for(int i = 0; i < xs.length; i++) 414.3725 - xs[i] = (xs[i] * ys[i]) + z; 414.3726 - return xs; 414.3727 - } 414.3728 - 414.3729 - static public long[] vdiv(long[] x, long[] ys){ 414.3730 - final long[] xs = x.clone(); 414.3731 - for(int i = 0; i < xs.length; i++) 414.3732 - xs[i] /= ys[i]; 414.3733 - return xs; 414.3734 - } 414.3735 - 414.3736 - static public long[] vmul(long[] x, long[] ys){ 414.3737 - final long[] xs = x.clone(); 414.3738 - for(int i = 0; i < xs.length; i++) 414.3739 - xs[i] *= ys[i]; 414.3740 - return xs; 414.3741 - } 414.3742 - 414.3743 - static public long[] vmuladd(long[] x, long[] ys, long[] zs){ 414.3744 - final long[] xs = x.clone(); 414.3745 - for(int i = 0; i < xs.length; i++) 414.3746 - xs[i] = (xs[i] * ys[i]) + zs[i]; 414.3747 - return xs; 414.3748 - } 414.3749 - 414.3750 - static public long[] vmulsub(long[] x, long[] ys, long[] zs){ 414.3751 - final long[] xs = x.clone(); 414.3752 - for(int i = 0; i < xs.length; i++) 414.3753 - xs[i] = (xs[i] * ys[i]) - zs[i]; 414.3754 - return xs; 414.3755 - } 414.3756 - 414.3757 - static public long[] vmax(long[] x, long[] ys){ 414.3758 - final long[] xs = x.clone(); 414.3759 - for(int i = 0; i < xs.length; i++) 414.3760 - xs[i] = Math.max(xs[i], ys[i]); 414.3761 - return xs; 414.3762 - } 414.3763 - 414.3764 - static public long[] vmin(long[] x, long[] ys){ 414.3765 - final long[] xs = x.clone(); 414.3766 - for(int i = 0; i < xs.length; i++) 414.3767 - xs[i] = Math.min(xs[i], ys[i]); 414.3768 - return xs; 414.3769 - } 414.3770 - 414.3771 - static public long[] vmap(IFn fn, long[] x) throws Exception{ 414.3772 - long[] xs = x.clone(); 414.3773 - for(int i = 0; i < xs.length; i++) 414.3774 - xs[i] = ((Number) fn.invoke(xs[i])).longValue(); 414.3775 - return xs; 414.3776 - } 414.3777 - 414.3778 - static public long[] vmap(IFn fn, long[] x, long[] ys) throws Exception{ 414.3779 - long[] xs = x.clone(); 414.3780 - for(int i = 0; i < xs.length; i++) 414.3781 - xs[i] = ((Number) fn.invoke(xs[i], ys[i])).longValue(); 414.3782 - return xs; 414.3783 - } 414.3784 - 414.3785 -} 414.3786 -*/ 414.3787 - 414.3788 - 414.3789 -//overload resolution 414.3790 - 414.3791 -static public Number add(int x, Object y){ 414.3792 - return add((Object)x,y); 414.3793 -} 414.3794 - 414.3795 -static public Number add(Object x, int y){ 414.3796 - return add(x,(Object)y); 414.3797 -} 414.3798 - 414.3799 -static public Number and(int x, Object y){ 414.3800 - return and((Object)x,y); 414.3801 -} 414.3802 - 414.3803 -static public Number and(Object x, int y){ 414.3804 - return and(x,(Object)y); 414.3805 -} 414.3806 - 414.3807 -static public Number or(int x, Object y){ 414.3808 - return or((Object)x,y); 414.3809 -} 414.3810 - 414.3811 -static public Number or(Object x, int y){ 414.3812 - return or(x,(Object)y); 414.3813 -} 414.3814 - 414.3815 -static public Number xor(int x, Object y){ 414.3816 - return xor((Object)x,y); 414.3817 -} 414.3818 - 414.3819 -static public Number xor(Object x, int y){ 414.3820 - return xor(x,(Object)y); 414.3821 -} 414.3822 - 414.3823 -static public Number add(float x, Object y){ 414.3824 - return add((Object)x,y); 414.3825 -} 414.3826 - 414.3827 -static public Number add(Object x, float y){ 414.3828 - return add(x,(Object)y); 414.3829 -} 414.3830 - 414.3831 -static public Number add(long x, Object y){ 414.3832 - return add((Object)x,y); 414.3833 -} 414.3834 - 414.3835 -static public Number add(Object x, long y){ 414.3836 - return add(x,(Object)y); 414.3837 -} 414.3838 - 414.3839 -static public Number add(double x, Object y){ 414.3840 - return add((Object)x,y); 414.3841 -} 414.3842 - 414.3843 -static public Number add(Object x, double y){ 414.3844 - return add(x,(Object)y); 414.3845 -} 414.3846 - 414.3847 -static public Number minus(int x, Object y){ 414.3848 - return minus((Object)x,y); 414.3849 -} 414.3850 - 414.3851 -static public Number minus(Object x, int y){ 414.3852 - return minus(x,(Object)y); 414.3853 -} 414.3854 - 414.3855 -static public Number minus(float x, Object y){ 414.3856 - return minus((Object)x,y); 414.3857 -} 414.3858 - 414.3859 -static public Number minus(Object x, float y){ 414.3860 - return minus(x,(Object)y); 414.3861 -} 414.3862 - 414.3863 -static public Number minus(long x, Object y){ 414.3864 - return minus((Object)x,y); 414.3865 -} 414.3866 - 414.3867 -static public Number minus(Object x, long y){ 414.3868 - return minus(x,(Object)y); 414.3869 -} 414.3870 - 414.3871 -static public Number minus(double x, Object y){ 414.3872 - return minus((Object)x,y); 414.3873 -} 414.3874 - 414.3875 -static public Number minus(Object x, double y){ 414.3876 - return minus(x,(Object)y); 414.3877 -} 414.3878 - 414.3879 -static public Number multiply(int x, Object y){ 414.3880 - return multiply((Object)x,y); 414.3881 -} 414.3882 - 414.3883 -static public Number multiply(Object x, int y){ 414.3884 - return multiply(x,(Object)y); 414.3885 -} 414.3886 - 414.3887 -static public Number multiply(float x, Object y){ 414.3888 - return multiply((Object)x,y); 414.3889 -} 414.3890 - 414.3891 -static public Number multiply(Object x, float y){ 414.3892 - return multiply(x,(Object)y); 414.3893 -} 414.3894 - 414.3895 -static public Number multiply(long x, Object y){ 414.3896 - return multiply((Object)x,y); 414.3897 -} 414.3898 - 414.3899 -static public Number multiply(Object x, long y){ 414.3900 - return multiply(x,(Object)y); 414.3901 -} 414.3902 - 414.3903 -static public Number multiply(double x, Object y){ 414.3904 - return multiply((Object)x,y); 414.3905 -} 414.3906 - 414.3907 -static public Number multiply(Object x, double y){ 414.3908 - return multiply(x,(Object)y); 414.3909 -} 414.3910 - 414.3911 -static public Number divide(int x, Object y){ 414.3912 - return divide((Object)x,y); 414.3913 -} 414.3914 - 414.3915 -static public Number divide(Object x, int y){ 414.3916 - return divide(x,(Object)y); 414.3917 -} 414.3918 - 414.3919 -static public Number divide(float x, Object y){ 414.3920 - return divide((Object)x,y); 414.3921 -} 414.3922 - 414.3923 -static public Number divide(Object x, float y){ 414.3924 - return divide(x,(Object)y); 414.3925 -} 414.3926 - 414.3927 -static public Number divide(long x, Object y){ 414.3928 - return divide((Object)x,y); 414.3929 -} 414.3930 - 414.3931 -static public Number divide(Object x, long y){ 414.3932 - return divide(x,(Object)y); 414.3933 -} 414.3934 - 414.3935 -static public Number divide(double x, Object y){ 414.3936 - return divide((Object)x,y); 414.3937 -} 414.3938 - 414.3939 -static public Number divide(Object x, double y){ 414.3940 - return divide(x,(Object)y); 414.3941 -} 414.3942 - 414.3943 -static public boolean lt(int x, Object y){ 414.3944 - return lt((Object)x,y); 414.3945 -} 414.3946 - 414.3947 -static public boolean lt(Object x, int y){ 414.3948 - return lt(x,(Object)y); 414.3949 -} 414.3950 - 414.3951 -static public boolean lt(float x, Object y){ 414.3952 - return lt((Object)x,y); 414.3953 -} 414.3954 - 414.3955 -static public boolean lt(Object x, float y){ 414.3956 - return lt(x,(Object)y); 414.3957 -} 414.3958 - 414.3959 -static public boolean lt(long x, Object y){ 414.3960 - return lt((Object)x,y); 414.3961 -} 414.3962 - 414.3963 -static public boolean lt(Object x, long y){ 414.3964 - return lt(x,(Object)y); 414.3965 -} 414.3966 - 414.3967 -static public boolean lt(double x, Object y){ 414.3968 - return lt((Object)x,y); 414.3969 -} 414.3970 - 414.3971 -static public boolean lt(Object x, double y){ 414.3972 - return lt(x,(Object)y); 414.3973 -} 414.3974 - 414.3975 -static public boolean lte(int x, Object y){ 414.3976 - return lte((Object)x,y); 414.3977 -} 414.3978 - 414.3979 -static public boolean lte(Object x, int y){ 414.3980 - return lte(x,(Object)y); 414.3981 -} 414.3982 - 414.3983 -static public boolean lte(float x, Object y){ 414.3984 - return lte((Object)x,y); 414.3985 -} 414.3986 - 414.3987 -static public boolean lte(Object x, float y){ 414.3988 - return lte(x,(Object)y); 414.3989 -} 414.3990 - 414.3991 -static public boolean lte(long x, Object y){ 414.3992 - return lte((Object)x,y); 414.3993 -} 414.3994 - 414.3995 -static public boolean lte(Object x, long y){ 414.3996 - return lte(x,(Object)y); 414.3997 -} 414.3998 - 414.3999 -static public boolean lte(double x, Object y){ 414.4000 - return lte((Object)x,y); 414.4001 -} 414.4002 - 414.4003 -static public boolean lte(Object x, double y){ 414.4004 - return lte(x,(Object)y); 414.4005 -} 414.4006 - 414.4007 -static public boolean gt(int x, Object y){ 414.4008 - return gt((Object)x,y); 414.4009 -} 414.4010 - 414.4011 -static public boolean gt(Object x, int y){ 414.4012 - return gt(x,(Object)y); 414.4013 -} 414.4014 - 414.4015 -static public boolean gt(float x, Object y){ 414.4016 - return gt((Object)x,y); 414.4017 -} 414.4018 - 414.4019 -static public boolean gt(Object x, float y){ 414.4020 - return gt(x,(Object)y); 414.4021 -} 414.4022 - 414.4023 -static public boolean gt(long x, Object y){ 414.4024 - return gt((Object)x,y); 414.4025 -} 414.4026 - 414.4027 -static public boolean gt(Object x, long y){ 414.4028 - return gt(x,(Object)y); 414.4029 -} 414.4030 - 414.4031 -static public boolean gt(double x, Object y){ 414.4032 - return gt((Object)x,y); 414.4033 -} 414.4034 - 414.4035 -static public boolean gt(Object x, double y){ 414.4036 - return gt(x,(Object)y); 414.4037 -} 414.4038 - 414.4039 -static public boolean gte(int x, Object y){ 414.4040 - return gte((Object)x,y); 414.4041 -} 414.4042 - 414.4043 -static public boolean gte(Object x, int y){ 414.4044 - return gte(x,(Object)y); 414.4045 -} 414.4046 - 414.4047 -static public boolean gte(float x, Object y){ 414.4048 - return gte((Object)x,y); 414.4049 -} 414.4050 - 414.4051 -static public boolean gte(Object x, float y){ 414.4052 - return gte(x,(Object)y); 414.4053 -} 414.4054 - 414.4055 -static public boolean gte(long x, Object y){ 414.4056 - return gte((Object)x,y); 414.4057 -} 414.4058 - 414.4059 -static public boolean gte(Object x, long y){ 414.4060 - return gte(x,(Object)y); 414.4061 -} 414.4062 - 414.4063 -static public boolean gte(double x, Object y){ 414.4064 - return gte((Object)x,y); 414.4065 -} 414.4066 - 414.4067 -static public boolean gte(Object x, double y){ 414.4068 - return gte(x,(Object)y); 414.4069 -} 414.4070 - 414.4071 - 414.4072 -static public boolean equiv(int x, Object y){ 414.4073 - return equiv((Object)x,y); 414.4074 -} 414.4075 - 414.4076 -static public boolean equiv(Object x, int y){ 414.4077 - return equiv(x,(Object)y); 414.4078 -} 414.4079 - 414.4080 -static public boolean equiv(float x, Object y){ 414.4081 - return equiv((Object)x,y); 414.4082 -} 414.4083 - 414.4084 -static public boolean equiv(Object x, float y){ 414.4085 - return equiv(x,(Object)y); 414.4086 -} 414.4087 - 414.4088 -static public boolean equiv(long x, Object y){ 414.4089 - return equiv((Object)x,y); 414.4090 -} 414.4091 - 414.4092 -static public boolean equiv(Object x, long y){ 414.4093 - return equiv(x,(Object)y); 414.4094 -} 414.4095 - 414.4096 -static public boolean equiv(double x, Object y){ 414.4097 - return equiv((Object)x,y); 414.4098 -} 414.4099 - 414.4100 -static public boolean equiv(Object x, double y){ 414.4101 - return equiv(x,(Object)y); 414.4102 -} 414.4103 - 414.4104 - 414.4105 -static public float add(int x, float y){ 414.4106 - return add((float)x,y); 414.4107 -} 414.4108 - 414.4109 -static public float add(float x, int y){ 414.4110 - return add(x,(float)y); 414.4111 -} 414.4112 - 414.4113 -static public double add(int x, double y){ 414.4114 - return add((double)x,y); 414.4115 -} 414.4116 - 414.4117 -static public double add(double x, int y){ 414.4118 - return add(x,(double)y); 414.4119 -} 414.4120 - 414.4121 -static public long add(int x, long y){ 414.4122 - return add((long)x,y); 414.4123 -} 414.4124 - 414.4125 -static public long add(long x, int y){ 414.4126 - return add(x,(long)y); 414.4127 -} 414.4128 - 414.4129 -static public float add(long x, float y){ 414.4130 - return add((float)x,y); 414.4131 -} 414.4132 - 414.4133 -static public float add(float x, long y){ 414.4134 - return add(x,(float)y); 414.4135 -} 414.4136 - 414.4137 -static public double add(long x, double y){ 414.4138 - return add((double)x,y); 414.4139 -} 414.4140 - 414.4141 -static public double add(double x, long y){ 414.4142 - return add(x,(double)y); 414.4143 -} 414.4144 - 414.4145 -static public double add(float x, double y){ 414.4146 - return add((double)x,y); 414.4147 -} 414.4148 - 414.4149 -static public double add(double x, float y){ 414.4150 - return add(x,(double)y); 414.4151 -} 414.4152 - 414.4153 -static public float minus(int x, float y){ 414.4154 - return minus((float)x,y); 414.4155 -} 414.4156 - 414.4157 -static public float minus(float x, int y){ 414.4158 - return minus(x,(float)y); 414.4159 -} 414.4160 - 414.4161 -static public double minus(int x, double y){ 414.4162 - return minus((double)x,y); 414.4163 -} 414.4164 - 414.4165 -static public double minus(double x, int y){ 414.4166 - return minus(x,(double)y); 414.4167 -} 414.4168 - 414.4169 -static public long minus(int x, long y){ 414.4170 - return minus((long)x,y); 414.4171 -} 414.4172 - 414.4173 -static public long minus(long x, int y){ 414.4174 - return minus(x,(long)y); 414.4175 -} 414.4176 - 414.4177 -static public float minus(long x, float y){ 414.4178 - return minus((float)x,y); 414.4179 -} 414.4180 - 414.4181 -static public float minus(float x, long y){ 414.4182 - return minus(x,(float)y); 414.4183 -} 414.4184 - 414.4185 -static public double minus(long x, double y){ 414.4186 - return minus((double)x,y); 414.4187 -} 414.4188 - 414.4189 -static public double minus(double x, long y){ 414.4190 - return minus(x,(double)y); 414.4191 -} 414.4192 - 414.4193 -static public double minus(float x, double y){ 414.4194 - return minus((double)x,y); 414.4195 -} 414.4196 - 414.4197 -static public double minus(double x, float y){ 414.4198 - return minus(x,(double)y); 414.4199 -} 414.4200 - 414.4201 -static public float multiply(int x, float y){ 414.4202 - return multiply((float)x,y); 414.4203 -} 414.4204 - 414.4205 -static public float multiply(float x, int y){ 414.4206 - return multiply(x,(float)y); 414.4207 -} 414.4208 - 414.4209 -static public double multiply(int x, double y){ 414.4210 - return multiply((double)x,y); 414.4211 -} 414.4212 - 414.4213 -static public double multiply(double x, int y){ 414.4214 - return multiply(x,(double)y); 414.4215 -} 414.4216 - 414.4217 -static public long multiply(int x, long y){ 414.4218 - return multiply((long)x,y); 414.4219 -} 414.4220 - 414.4221 -static public long multiply(long x, int y){ 414.4222 - return multiply(x,(long)y); 414.4223 -} 414.4224 - 414.4225 -static public float multiply(long x, float y){ 414.4226 - return multiply((float)x,y); 414.4227 -} 414.4228 - 414.4229 -static public float multiply(float x, long y){ 414.4230 - return multiply(x,(float)y); 414.4231 -} 414.4232 - 414.4233 -static public double multiply(long x, double y){ 414.4234 - return multiply((double)x,y); 414.4235 -} 414.4236 - 414.4237 -static public double multiply(double x, long y){ 414.4238 - return multiply(x,(double)y); 414.4239 -} 414.4240 - 414.4241 -static public double multiply(float x, double y){ 414.4242 - return multiply((double)x,y); 414.4243 -} 414.4244 - 414.4245 -static public double multiply(double x, float y){ 414.4246 - return multiply(x,(double)y); 414.4247 -} 414.4248 - 414.4249 -static public float divide(int x, float y){ 414.4250 - return divide((float)x,y); 414.4251 -} 414.4252 - 414.4253 -static public float divide(float x, int y){ 414.4254 - return divide(x,(float)y); 414.4255 -} 414.4256 - 414.4257 -static public double divide(int x, double y){ 414.4258 - return divide((double)x,y); 414.4259 -} 414.4260 - 414.4261 -static public double divide(double x, int y){ 414.4262 - return divide(x,(double)y); 414.4263 -} 414.4264 - 414.4265 -static public float divide(long x, float y){ 414.4266 - return divide((float)x,y); 414.4267 -} 414.4268 - 414.4269 -static public float divide(float x, long y){ 414.4270 - return divide(x,(float)y); 414.4271 -} 414.4272 - 414.4273 -static public double divide(long x, double y){ 414.4274 - return divide((double)x,y); 414.4275 -} 414.4276 - 414.4277 -static public double divide(double x, long y){ 414.4278 - return divide(x,(double)y); 414.4279 -} 414.4280 - 414.4281 -static public double divide(float x, double y){ 414.4282 - return divide((double)x,y); 414.4283 -} 414.4284 - 414.4285 -static public double divide(double x, float y){ 414.4286 - return divide(x,(double)y); 414.4287 -} 414.4288 - 414.4289 -static public boolean lt(int x, float y){ 414.4290 - return lt((float)x,y); 414.4291 -} 414.4292 - 414.4293 -static public boolean lt(float x, int y){ 414.4294 - return lt(x,(float)y); 414.4295 -} 414.4296 - 414.4297 -static public boolean lt(int x, double y){ 414.4298 - return lt((double)x,y); 414.4299 -} 414.4300 - 414.4301 -static public boolean lt(double x, int y){ 414.4302 - return lt(x,(double)y); 414.4303 -} 414.4304 - 414.4305 -static public boolean lt(int x, long y){ 414.4306 - return lt((long)x,y); 414.4307 -} 414.4308 - 414.4309 -static public boolean lt(long x, int y){ 414.4310 - return lt(x,(long)y); 414.4311 -} 414.4312 - 414.4313 -static public boolean lt(long x, float y){ 414.4314 - return lt((float)x,y); 414.4315 -} 414.4316 - 414.4317 -static public boolean lt(float x, long y){ 414.4318 - return lt(x,(float)y); 414.4319 -} 414.4320 - 414.4321 -static public boolean lt(long x, double y){ 414.4322 - return lt((double)x,y); 414.4323 -} 414.4324 - 414.4325 -static public boolean lt(double x, long y){ 414.4326 - return lt(x,(double)y); 414.4327 -} 414.4328 - 414.4329 -static public boolean lt(float x, double y){ 414.4330 - return lt((double)x,y); 414.4331 -} 414.4332 - 414.4333 -static public boolean lt(double x, float y){ 414.4334 - return lt(x,(double)y); 414.4335 -} 414.4336 - 414.4337 - 414.4338 -static public boolean lte(int x, float y){ 414.4339 - return lte((float)x,y); 414.4340 -} 414.4341 - 414.4342 -static public boolean lte(float x, int y){ 414.4343 - return lte(x,(float)y); 414.4344 -} 414.4345 - 414.4346 -static public boolean lte(int x, double y){ 414.4347 - return lte((double)x,y); 414.4348 -} 414.4349 - 414.4350 -static public boolean lte(double x, int y){ 414.4351 - return lte(x,(double)y); 414.4352 -} 414.4353 - 414.4354 -static public boolean lte(int x, long y){ 414.4355 - return lte((long)x,y); 414.4356 -} 414.4357 - 414.4358 -static public boolean lte(long x, int y){ 414.4359 - return lte(x,(long)y); 414.4360 -} 414.4361 - 414.4362 -static public boolean lte(long x, float y){ 414.4363 - return lte((float)x,y); 414.4364 -} 414.4365 - 414.4366 -static public boolean lte(float x, long y){ 414.4367 - return lte(x,(float)y); 414.4368 -} 414.4369 - 414.4370 -static public boolean lte(long x, double y){ 414.4371 - return lte((double)x,y); 414.4372 -} 414.4373 - 414.4374 -static public boolean lte(double x, long y){ 414.4375 - return lte(x,(double)y); 414.4376 -} 414.4377 - 414.4378 -static public boolean lte(float x, double y){ 414.4379 - return lte((double)x,y); 414.4380 -} 414.4381 - 414.4382 -static public boolean lte(double x, float y){ 414.4383 - return lte(x,(double)y); 414.4384 -} 414.4385 - 414.4386 -static public boolean gt(int x, float y){ 414.4387 - return gt((float)x,y); 414.4388 -} 414.4389 - 414.4390 -static public boolean gt(float x, int y){ 414.4391 - return gt(x,(float)y); 414.4392 -} 414.4393 - 414.4394 -static public boolean gt(int x, double y){ 414.4395 - return gt((double)x,y); 414.4396 -} 414.4397 - 414.4398 -static public boolean gt(double x, int y){ 414.4399 - return gt(x,(double)y); 414.4400 -} 414.4401 - 414.4402 -static public boolean gt(int x, long y){ 414.4403 - return gt((long)x,y); 414.4404 -} 414.4405 - 414.4406 -static public boolean gt(long x, int y){ 414.4407 - return gt(x,(long)y); 414.4408 -} 414.4409 - 414.4410 -static public boolean gt(long x, float y){ 414.4411 - return gt((float)x,y); 414.4412 -} 414.4413 - 414.4414 -static public boolean gt(float x, long y){ 414.4415 - return gt(x,(float)y); 414.4416 -} 414.4417 - 414.4418 -static public boolean gt(long x, double y){ 414.4419 - return gt((double)x,y); 414.4420 -} 414.4421 - 414.4422 -static public boolean gt(double x, long y){ 414.4423 - return gt(x,(double)y); 414.4424 -} 414.4425 - 414.4426 -static public boolean gt(float x, double y){ 414.4427 - return gt((double)x,y); 414.4428 -} 414.4429 - 414.4430 -static public boolean gt(double x, float y){ 414.4431 - return gt(x,(double)y); 414.4432 -} 414.4433 - 414.4434 -static public boolean gte(int x, float y){ 414.4435 - return gte((float)x,y); 414.4436 -} 414.4437 - 414.4438 -static public boolean gte(float x, int y){ 414.4439 - return gte(x,(float)y); 414.4440 -} 414.4441 - 414.4442 -static public boolean gte(int x, double y){ 414.4443 - return gte((double)x,y); 414.4444 -} 414.4445 - 414.4446 -static public boolean gte(double x, int y){ 414.4447 - return gte(x,(double)y); 414.4448 -} 414.4449 - 414.4450 -static public boolean gte(int x, long y){ 414.4451 - return gte((long)x,y); 414.4452 -} 414.4453 - 414.4454 -static public boolean gte(long x, int y){ 414.4455 - return gte(x,(long)y); 414.4456 -} 414.4457 - 414.4458 -static public boolean gte(long x, float y){ 414.4459 - return gte((float)x,y); 414.4460 -} 414.4461 - 414.4462 -static public boolean gte(float x, long y){ 414.4463 - return gte(x,(float)y); 414.4464 -} 414.4465 - 414.4466 -static public boolean gte(long x, double y){ 414.4467 - return gte((double)x,y); 414.4468 -} 414.4469 - 414.4470 -static public boolean gte(double x, long y){ 414.4471 - return gte(x,(double)y); 414.4472 -} 414.4473 - 414.4474 -static public boolean gte(float x, double y){ 414.4475 - return gte((double)x,y); 414.4476 -} 414.4477 - 414.4478 -static public boolean gte(double x, float y){ 414.4479 - return gte(x,(double)y); 414.4480 -} 414.4481 - 414.4482 -static public boolean equiv(int x, float y){ 414.4483 - return equiv((float)x,y); 414.4484 -} 414.4485 - 414.4486 -static public boolean equiv(float x, int y){ 414.4487 - return equiv(x,(float)y); 414.4488 -} 414.4489 - 414.4490 -static public boolean equiv(int x, double y){ 414.4491 - return equiv((double)x,y); 414.4492 -} 414.4493 - 414.4494 -static public boolean equiv(double x, int y){ 414.4495 - return equiv(x,(double)y); 414.4496 -} 414.4497 - 414.4498 -static public boolean equiv(int x, long y){ 414.4499 - return equiv((long)x,y); 414.4500 -} 414.4501 - 414.4502 -static public boolean equiv(long x, int y){ 414.4503 - return equiv(x,(long)y); 414.4504 -} 414.4505 - 414.4506 -static public boolean equiv(long x, float y){ 414.4507 - return equiv((float)x,y); 414.4508 -} 414.4509 - 414.4510 -static public boolean equiv(float x, long y){ 414.4511 - return equiv(x,(float)y); 414.4512 -} 414.4513 - 414.4514 -static public boolean equiv(long x, double y){ 414.4515 - return equiv((double)x,y); 414.4516 -} 414.4517 - 414.4518 -static public boolean equiv(double x, long y){ 414.4519 - return equiv(x,(double)y); 414.4520 -} 414.4521 - 414.4522 -static public boolean equiv(float x, double y){ 414.4523 - return equiv((double)x,y); 414.4524 -} 414.4525 - 414.4526 -static public boolean equiv(double x, float y){ 414.4527 - return equiv(x,(double)y); 414.4528 -} 414.4529 - 414.4530 -}
415.1 --- a/src/clojure/lang/Obj.java Sat Aug 21 06:25:44 2010 -0400 415.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 415.3 @@ -1,35 +0,0 @@ 415.4 -/** 415.5 - * Copyright (c) Rich Hickey. All rights reserved. 415.6 - * The use and distribution terms for this software are covered by the 415.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 415.8 - * which can be found in the file epl-v10.html at the root of this distribution. 415.9 - * By using this software in any fashion, you are agreeing to be bound by 415.10 - * the terms of this license. 415.11 - * You must not remove this notice, or any other, from this software. 415.12 - **/ 415.13 - 415.14 -/* rich Mar 25, 2006 3:44:58 PM */ 415.15 - 415.16 -package clojure.lang; 415.17 - 415.18 -import java.io.Serializable; 415.19 - 415.20 -public abstract class Obj implements IObj, Serializable { 415.21 - 415.22 -final IPersistentMap _meta; 415.23 - 415.24 -public Obj(IPersistentMap meta){ 415.25 - this._meta = meta; 415.26 -} 415.27 - 415.28 -public Obj(){ 415.29 - _meta = null; 415.30 -} 415.31 - 415.32 -final public IPersistentMap meta(){ 415.33 - return _meta; 415.34 -} 415.35 - 415.36 -abstract public Obj withMeta(IPersistentMap meta); 415.37 - 415.38 -}
416.1 --- a/src/clojure/lang/PersistentArrayMap.java Sat Aug 21 06:25:44 2010 -0400 416.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 416.3 @@ -1,367 +0,0 @@ 416.4 -/** 416.5 - * Copyright (c) Rich Hickey. All rights reserved. 416.6 - * The use and distribution terms for this software are covered by the 416.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 416.8 - * which can be found in the file epl-v10.html at the root of this distribution. 416.9 - * By using this software in any fashion, you are agreeing to be bound by 416.10 - * the terms of this license. 416.11 - * You must not remove this notice, or any other, from this software. 416.12 - **/ 416.13 - 416.14 -package clojure.lang; 416.15 - 416.16 -import java.io.Serializable; 416.17 -import java.util.Arrays; 416.18 -import java.util.Iterator; 416.19 -import java.util.Map; 416.20 - 416.21 -/** 416.22 - * Simple implementation of persistent map on an array 416.23 - * <p/> 416.24 - * Note that instances of this class are constant values 416.25 - * i.e. add/remove etc return new values 416.26 - * <p/> 416.27 - * Copies array on every change, so only appropriate for _very_small_ maps 416.28 - * <p/> 416.29 - * null keys and values are ok, but you won't be able to distinguish a null value via valAt - use contains/entryAt 416.30 - */ 416.31 - 416.32 -public class PersistentArrayMap extends APersistentMap implements IObj, IEditableCollection { 416.33 - 416.34 -final Object[] array; 416.35 -static final int HASHTABLE_THRESHOLD = 16; 416.36 - 416.37 -public static final PersistentArrayMap EMPTY = new PersistentArrayMap(); 416.38 -private final IPersistentMap _meta; 416.39 - 416.40 -static public IPersistentMap create(Map other){ 416.41 - ITransientMap ret = EMPTY.asTransient(); 416.42 - for(Object o : other.entrySet()) 416.43 - { 416.44 - Map.Entry e = (Entry) o; 416.45 - ret = ret.assoc(e.getKey(), e.getValue()); 416.46 - } 416.47 - return ret.persistent(); 416.48 -} 416.49 - 416.50 -protected PersistentArrayMap(){ 416.51 - this.array = new Object[]{}; 416.52 - this._meta = null; 416.53 -} 416.54 - 416.55 -public PersistentArrayMap withMeta(IPersistentMap meta){ 416.56 - return new PersistentArrayMap(meta, array); 416.57 -} 416.58 - 416.59 -PersistentArrayMap create(Object... init){ 416.60 - return new PersistentArrayMap(meta(), init); 416.61 -} 416.62 - 416.63 -IPersistentMap createHT(Object[] init){ 416.64 - return PersistentHashMap.create(meta(), init); 416.65 -} 416.66 - 416.67 -static public PersistentArrayMap createWithCheck(Object[] init){ 416.68 - for(int i=0;i< init.length;i += 2) 416.69 - { 416.70 - for(int j=i+2;j<init.length;j += 2) 416.71 - { 416.72 - if(equalKey(init[i],init[j])) 416.73 - throw new IllegalArgumentException("Duplicate key: " + init[i]); 416.74 - } 416.75 - } 416.76 - return new PersistentArrayMap(init); 416.77 -} 416.78 -/** 416.79 - * This ctor captures/aliases the passed array, so do not modify later 416.80 - * 416.81 - * @param init {key1,val1,key2,val2,...} 416.82 - */ 416.83 -public PersistentArrayMap(Object[] init){ 416.84 - this.array = init; 416.85 - this._meta = null; 416.86 -} 416.87 - 416.88 - 416.89 -public PersistentArrayMap(IPersistentMap meta, Object[] init){ 416.90 - this._meta = meta; 416.91 - this.array = init; 416.92 -} 416.93 - 416.94 -public int count(){ 416.95 - return array.length / 2; 416.96 -} 416.97 - 416.98 -public boolean containsKey(Object key){ 416.99 - return indexOf(key) >= 0; 416.100 -} 416.101 - 416.102 -public IMapEntry entryAt(Object key){ 416.103 - int i = indexOf(key); 416.104 - if(i >= 0) 416.105 - return new MapEntry(array[i],array[i+1]); 416.106 - return null; 416.107 -} 416.108 - 416.109 -public IPersistentMap assocEx(Object key, Object val) throws Exception{ 416.110 - int i = indexOf(key); 416.111 - Object[] newArray; 416.112 - if(i >= 0) 416.113 - { 416.114 - throw new Exception("Key already present"); 416.115 - } 416.116 - else //didn't have key, grow 416.117 - { 416.118 - if(array.length > HASHTABLE_THRESHOLD) 416.119 - return createHT(array).assocEx(key, val); 416.120 - newArray = new Object[array.length + 2]; 416.121 - if(array.length > 0) 416.122 - System.arraycopy(array, 0, newArray, 2, array.length); 416.123 - newArray[0] = key; 416.124 - newArray[1] = val; 416.125 - } 416.126 - return create(newArray); 416.127 -} 416.128 - 416.129 -public IPersistentMap assoc(Object key, Object val){ 416.130 - int i = indexOf(key); 416.131 - Object[] newArray; 416.132 - if(i >= 0) //already have key, same-sized replacement 416.133 - { 416.134 - if(array[i + 1] == val) //no change, no op 416.135 - return this; 416.136 - newArray = array.clone(); 416.137 - newArray[i + 1] = val; 416.138 - } 416.139 - else //didn't have key, grow 416.140 - { 416.141 - if(array.length > HASHTABLE_THRESHOLD) 416.142 - return createHT(array).assoc(key, val); 416.143 - newArray = new Object[array.length + 2]; 416.144 - if(array.length > 0) 416.145 - System.arraycopy(array, 0, newArray, 2, array.length); 416.146 - newArray[0] = key; 416.147 - newArray[1] = val; 416.148 - } 416.149 - return create(newArray); 416.150 -} 416.151 - 416.152 -public IPersistentMap without(Object key){ 416.153 - int i = indexOf(key); 416.154 - if(i >= 0) //have key, will remove 416.155 - { 416.156 - int newlen = array.length - 2; 416.157 - if(newlen == 0) 416.158 - return empty(); 416.159 - Object[] newArray = new Object[newlen]; 416.160 - for(int s = 0, d = 0; s < array.length; s += 2) 416.161 - { 416.162 - if(!equalKey(array[s], key)) //skip removal key 416.163 - { 416.164 - newArray[d] = array[s]; 416.165 - newArray[d + 1] = array[s + 1]; 416.166 - d += 2; 416.167 - } 416.168 - } 416.169 - return create(newArray); 416.170 - } 416.171 - //don't have key, no op 416.172 - return this; 416.173 -} 416.174 - 416.175 -public IPersistentMap empty(){ 416.176 - return (IPersistentMap) EMPTY.withMeta(meta()); 416.177 -} 416.178 - 416.179 -final public Object valAt(Object key, Object notFound){ 416.180 - int i = indexOf(key); 416.181 - if(i >= 0) 416.182 - return array[i + 1]; 416.183 - return notFound; 416.184 -} 416.185 - 416.186 -public Object valAt(Object key){ 416.187 - return valAt(key, null); 416.188 -} 416.189 - 416.190 -public int capacity(){ 416.191 - return count(); 416.192 -} 416.193 - 416.194 -private int indexOf(Object key){ 416.195 - for(int i = 0; i < array.length; i += 2) 416.196 - { 416.197 - if(equalKey(array[i], key)) 416.198 - return i; 416.199 - } 416.200 - return -1; 416.201 -} 416.202 - 416.203 -static boolean equalKey(Object k1, Object k2){ 416.204 - if(k1 == null) 416.205 - return k2 == null; 416.206 - return k1.equals(k2); 416.207 -} 416.208 - 416.209 -public Iterator iterator(){ 416.210 - return new Iter(array); 416.211 -} 416.212 - 416.213 -public ISeq seq(){ 416.214 - if(array.length > 0) 416.215 - return new Seq(array, 0); 416.216 - return null; 416.217 -} 416.218 - 416.219 -public IPersistentMap meta(){ 416.220 - return _meta; 416.221 -} 416.222 - 416.223 -static class Seq extends ASeq implements Counted{ 416.224 - final Object[] array; 416.225 - final int i; 416.226 - 416.227 - Seq(Object[] array, int i){ 416.228 - this.array = array; 416.229 - this.i = i; 416.230 - } 416.231 - 416.232 - public Seq(IPersistentMap meta, Object[] array, int i){ 416.233 - super(meta); 416.234 - this.array = array; 416.235 - this.i = i; 416.236 - } 416.237 - 416.238 - public Object first(){ 416.239 - return new MapEntry(array[i],array[i+1]); 416.240 - } 416.241 - 416.242 - public ISeq next(){ 416.243 - if(i + 2 < array.length) 416.244 - return new Seq(array, i + 2); 416.245 - return null; 416.246 - } 416.247 - 416.248 - public int count(){ 416.249 - return (array.length - i) / 2; 416.250 - } 416.251 - 416.252 - public Obj withMeta(IPersistentMap meta){ 416.253 - return new Seq(meta, array, i); 416.254 - } 416.255 -} 416.256 - 416.257 -static class Iter implements Iterator{ 416.258 - Object[] array; 416.259 - int i; 416.260 - 416.261 - //for iterator 416.262 - Iter(Object[] array){ 416.263 - this(array, -2); 416.264 - } 416.265 - 416.266 - //for entryAt 416.267 - Iter(Object[] array, int i){ 416.268 - this.array = array; 416.269 - this.i = i; 416.270 - } 416.271 - 416.272 - public boolean hasNext(){ 416.273 - return i < array.length - 2; 416.274 - } 416.275 - 416.276 - public Object next(){ 416.277 - i += 2; 416.278 - return new MapEntry(array[i],array[i+1]); 416.279 - } 416.280 - 416.281 - public void remove(){ 416.282 - throw new UnsupportedOperationException(); 416.283 - } 416.284 - 416.285 -} 416.286 - 416.287 -public ITransientMap asTransient(){ 416.288 - return new TransientArrayMap(array); 416.289 -} 416.290 - 416.291 -static final class TransientArrayMap extends ATransientMap { 416.292 - int len; 416.293 - final Object[] array; 416.294 - Thread owner; 416.295 - 416.296 - public TransientArrayMap(Object[] array){ 416.297 - this.owner = Thread.currentThread(); 416.298 - this.array = new Object[Math.max(HASHTABLE_THRESHOLD, array.length)]; 416.299 - System.arraycopy(array, 0, this.array, 0, array.length); 416.300 - this.len = array.length; 416.301 - } 416.302 - 416.303 - private int indexOf(Object key){ 416.304 - for(int i = 0; i < len; i += 2) 416.305 - { 416.306 - if(equalKey(array[i], key)) 416.307 - return i; 416.308 - } 416.309 - return -1; 416.310 - } 416.311 - 416.312 - ITransientMap doAssoc(Object key, Object val){ 416.313 - int i = indexOf(key); 416.314 - if(i >= 0) //already have key, 416.315 - { 416.316 - if(array[i + 1] != val) //no change, no op 416.317 - array[i + 1] = val; 416.318 - } 416.319 - else //didn't have key, grow 416.320 - { 416.321 - if(len >= array.length) 416.322 - return PersistentHashMap.create(array).asTransient().assoc(key, val); 416.323 - array[len++] = key; 416.324 - array[len++] = val; 416.325 - } 416.326 - return this; 416.327 - } 416.328 - 416.329 - ITransientMap doWithout(Object key) { 416.330 - int i = indexOf(key); 416.331 - if(i >= 0) //have key, will remove 416.332 - { 416.333 - if (len >= 2) 416.334 - { 416.335 - array[i] = array[len - 2]; 416.336 - array[i + 1] = array[len - 1]; 416.337 - } 416.338 - len -= 2; 416.339 - } 416.340 - return this; 416.341 - } 416.342 - 416.343 - Object doValAt(Object key, Object notFound) { 416.344 - int i = indexOf(key); 416.345 - if (i >= 0) 416.346 - return array[i + 1]; 416.347 - return notFound; 416.348 - } 416.349 - 416.350 - int doCount() { 416.351 - return len / 2; 416.352 - } 416.353 - 416.354 - IPersistentMap doPersistent(){ 416.355 - ensureEditable(); 416.356 - owner = null; 416.357 - Object[] a = new Object[len]; 416.358 - System.arraycopy(array,0,a,0,len); 416.359 - return new PersistentArrayMap(a); 416.360 - } 416.361 - 416.362 - void ensureEditable(){ 416.363 - if(owner == Thread.currentThread()) 416.364 - return; 416.365 - if(owner != null) 416.366 - throw new IllegalAccessError("Transient used by non-owner thread"); 416.367 - throw new IllegalAccessError("Transient used after persistent! call"); 416.368 - } 416.369 -} 416.370 -}
417.1 --- a/src/clojure/lang/PersistentHashMap.java Sat Aug 21 06:25:44 2010 -0400 417.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 417.3 @@ -1,1054 +0,0 @@ 417.4 -/** 417.5 - * Copyright (c) Rich Hickey. All rights reserved. 417.6 - * The use and distribution terms for this software are covered by the 417.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 417.8 - * which can be found in the file epl-v10.html at the root of this distribution. 417.9 - * By using this software in any fashion, you are agreeing to be bound by 417.10 - * the terms of this license. 417.11 - * You must not remove this notice, or any other, from this software. 417.12 - **/ 417.13 - 417.14 -package clojure.lang; 417.15 - 417.16 -import java.io.Serializable; 417.17 -import java.util.Iterator; 417.18 -import java.util.List; 417.19 -import java.util.Map; 417.20 -import java.util.concurrent.atomic.AtomicReference; 417.21 - 417.22 -/* 417.23 - A persistent rendition of Phil Bagwell's Hash Array Mapped Trie 417.24 - 417.25 - Uses path copying for persistence 417.26 - HashCollision leaves vs. extended hashing 417.27 - Node polymorphism vs. conditionals 417.28 - No sub-tree pools or root-resizing 417.29 - Any errors are my own 417.30 - */ 417.31 - 417.32 -public class PersistentHashMap extends APersistentMap implements IEditableCollection, IObj { 417.33 - 417.34 -final int count; 417.35 -final INode root; 417.36 -final boolean hasNull; 417.37 -final Object nullValue; 417.38 -final IPersistentMap _meta; 417.39 - 417.40 -final public static PersistentHashMap EMPTY = new PersistentHashMap(0, null, false, null); 417.41 -final private static Object NOT_FOUND = new Object(); 417.42 - 417.43 -static public IPersistentMap create(Map other){ 417.44 - ITransientMap ret = EMPTY.asTransient(); 417.45 - for(Object o : other.entrySet()) 417.46 - { 417.47 - Map.Entry e = (Entry) o; 417.48 - ret = ret.assoc(e.getKey(), e.getValue()); 417.49 - } 417.50 - return ret.persistent(); 417.51 -} 417.52 - 417.53 -/* 417.54 - * @param init {key1,val1,key2,val2,...} 417.55 - */ 417.56 -public static PersistentHashMap create(Object... init){ 417.57 - ITransientMap ret = EMPTY.asTransient(); 417.58 - for(int i = 0; i < init.length; i += 2) 417.59 - { 417.60 - ret = ret.assoc(init[i], init[i + 1]); 417.61 - } 417.62 - return (PersistentHashMap) ret.persistent(); 417.63 -} 417.64 - 417.65 -public static PersistentHashMap createWithCheck(Object... init){ 417.66 - ITransientMap ret = EMPTY.asTransient(); 417.67 - for(int i = 0; i < init.length; i += 2) 417.68 - { 417.69 - ret = ret.assoc(init[i], init[i + 1]); 417.70 - if(ret.count() != i/2 + 1) 417.71 - throw new IllegalArgumentException("Duplicate key: " + init[i]); 417.72 - } 417.73 - return (PersistentHashMap) ret.persistent(); 417.74 -} 417.75 - 417.76 -static public PersistentHashMap create(ISeq items){ 417.77 - ITransientMap ret = EMPTY.asTransient(); 417.78 - for(; items != null; items = items.next().next()) 417.79 - { 417.80 - if(items.next() == null) 417.81 - throw new IllegalArgumentException(String.format("No value supplied for key: %s", items.first())); 417.82 - ret = ret.assoc(items.first(), RT.second(items)); 417.83 - } 417.84 - return (PersistentHashMap) ret.persistent(); 417.85 -} 417.86 - 417.87 -static public PersistentHashMap createWithCheck(ISeq items){ 417.88 - ITransientMap ret = EMPTY.asTransient(); 417.89 - for(int i=0; items != null; items = items.next().next(), ++i) 417.90 - { 417.91 - if(items.next() == null) 417.92 - throw new IllegalArgumentException(String.format("No value supplied for key: %s", items.first())); 417.93 - ret = ret.assoc(items.first(), RT.second(items)); 417.94 - if(ret.count() != i + 1) 417.95 - throw new IllegalArgumentException("Duplicate key: " + items.first()); 417.96 - } 417.97 - return (PersistentHashMap) ret.persistent(); 417.98 -} 417.99 - 417.100 -/* 417.101 - * @param init {key1,val1,key2,val2,...} 417.102 - */ 417.103 -public static PersistentHashMap create(IPersistentMap meta, Object... init){ 417.104 - return create(init).withMeta(meta); 417.105 -} 417.106 - 417.107 -PersistentHashMap(int count, INode root, boolean hasNull, Object nullValue){ 417.108 - this.count = count; 417.109 - this.root = root; 417.110 - this.hasNull = hasNull; 417.111 - this.nullValue = nullValue; 417.112 - this._meta = null; 417.113 -} 417.114 - 417.115 -public PersistentHashMap(IPersistentMap meta, int count, INode root, boolean hasNull, Object nullValue){ 417.116 - this._meta = meta; 417.117 - this.count = count; 417.118 - this.root = root; 417.119 - this.hasNull = hasNull; 417.120 - this.nullValue = nullValue; 417.121 -} 417.122 - 417.123 -public boolean containsKey(Object key){ 417.124 - if(key == null) 417.125 - return hasNull; 417.126 - return (root != null) ? root.find(0, Util.hash(key), key, NOT_FOUND) != NOT_FOUND : false; 417.127 -} 417.128 - 417.129 -public IMapEntry entryAt(Object key){ 417.130 - if(key == null) 417.131 - return hasNull ? new MapEntry(null, nullValue) : null; 417.132 - return (root != null) ? root.find(0, Util.hash(key), key) : null; 417.133 -} 417.134 - 417.135 -public IPersistentMap assoc(Object key, Object val){ 417.136 - if(key == null) { 417.137 - if(hasNull && val == nullValue) 417.138 - return this; 417.139 - return new PersistentHashMap(meta(), hasNull ? count : count + 1, root, true, val); 417.140 - } 417.141 - Box addedLeaf = new Box(null); 417.142 - INode newroot = (root == null ? BitmapIndexedNode.EMPTY : root) 417.143 - .assoc(0, Util.hash(key), key, val, addedLeaf); 417.144 - if(newroot == root) 417.145 - return this; 417.146 - return new PersistentHashMap(meta(), addedLeaf.val == null ? count : count + 1, newroot, hasNull, nullValue); 417.147 -} 417.148 - 417.149 -public Object valAt(Object key, Object notFound){ 417.150 - if(key == null) 417.151 - return hasNull ? nullValue : notFound; 417.152 - return root != null ? root.find(0, Util.hash(key), key, notFound) : notFound; 417.153 -} 417.154 - 417.155 -public Object valAt(Object key){ 417.156 - return valAt(key, null); 417.157 -} 417.158 - 417.159 -public IPersistentMap assocEx(Object key, Object val) throws Exception{ 417.160 - if(containsKey(key)) 417.161 - throw new Exception("Key already present"); 417.162 - return assoc(key, val); 417.163 -} 417.164 - 417.165 -public IPersistentMap without(Object key){ 417.166 - if(key == null) 417.167 - return hasNull ? new PersistentHashMap(meta(), count - 1, root, false, null) : this; 417.168 - if(root == null) 417.169 - return this; 417.170 - INode newroot = root.without(0, Util.hash(key), key); 417.171 - if(newroot == root) 417.172 - return this; 417.173 - return new PersistentHashMap(meta(), count - 1, newroot, hasNull, nullValue); 417.174 -} 417.175 - 417.176 -public Iterator iterator(){ 417.177 - return new SeqIterator(seq()); 417.178 -} 417.179 - 417.180 -public int count(){ 417.181 - return count; 417.182 -} 417.183 - 417.184 -public ISeq seq(){ 417.185 - ISeq s = root != null ? root.nodeSeq() : null; 417.186 - return hasNull ? new Cons(new MapEntry(null, nullValue), s) : s; 417.187 -} 417.188 - 417.189 -public IPersistentCollection empty(){ 417.190 - return EMPTY.withMeta(meta()); 417.191 -} 417.192 - 417.193 -static int mask(int hash, int shift){ 417.194 - //return ((hash << shift) >>> 27);// & 0x01f; 417.195 - return (hash >>> shift) & 0x01f; 417.196 -} 417.197 - 417.198 -public PersistentHashMap withMeta(IPersistentMap meta){ 417.199 - return new PersistentHashMap(meta, count, root, hasNull, nullValue); 417.200 -} 417.201 - 417.202 -public TransientHashMap asTransient() { 417.203 - return new TransientHashMap(this); 417.204 -} 417.205 - 417.206 -public IPersistentMap meta(){ 417.207 - return _meta; 417.208 -} 417.209 - 417.210 -static final class TransientHashMap extends ATransientMap { 417.211 - AtomicReference<Thread> edit; 417.212 - INode root; 417.213 - int count; 417.214 - boolean hasNull; 417.215 - Object nullValue; 417.216 - final Box leafFlag = new Box(null); 417.217 - 417.218 - 417.219 - TransientHashMap(PersistentHashMap m) { 417.220 - this(new AtomicReference<Thread>(Thread.currentThread()), m.root, m.count, m.hasNull, m.nullValue); 417.221 - } 417.222 - 417.223 - TransientHashMap(AtomicReference<Thread> edit, INode root, int count, boolean hasNull, Object nullValue) { 417.224 - this.edit = edit; 417.225 - this.root = root; 417.226 - this.count = count; 417.227 - this.hasNull = hasNull; 417.228 - this.nullValue = nullValue; 417.229 - } 417.230 - 417.231 - ITransientMap doAssoc(Object key, Object val) { 417.232 - if (key == null) { 417.233 - if (this.nullValue != val) 417.234 - this.nullValue = val; 417.235 - if (!hasNull) { 417.236 - this.count++; 417.237 - this.hasNull = true; 417.238 - } 417.239 - return this; 417.240 - } 417.241 -// Box leafFlag = new Box(null); 417.242 - leafFlag.val = null; 417.243 - INode n = (root == null ? BitmapIndexedNode.EMPTY : root) 417.244 - .assoc(edit, 0, Util.hash(key), key, val, leafFlag); 417.245 - if (n != this.root) 417.246 - this.root = n; 417.247 - if(leafFlag.val != null) this.count++; 417.248 - return this; 417.249 - } 417.250 - 417.251 - ITransientMap doWithout(Object key) { 417.252 - if (key == null) { 417.253 - if (!hasNull) return this; 417.254 - hasNull = false; 417.255 - nullValue = null; 417.256 - this.count--; 417.257 - return this; 417.258 - } 417.259 - if (root == null) return this; 417.260 -// Box leafFlag = new Box(null); 417.261 - leafFlag.val = null; 417.262 - INode n = root.without(edit, 0, Util.hash(key), key, leafFlag); 417.263 - if (n != root) 417.264 - this.root = n; 417.265 - if(leafFlag.val != null) this.count--; 417.266 - return this; 417.267 - } 417.268 - 417.269 - IPersistentMap doPersistent() { 417.270 - edit.set(null); 417.271 - return new PersistentHashMap(count, root, hasNull, nullValue); 417.272 - } 417.273 - 417.274 - Object doValAt(Object key, Object notFound) { 417.275 - if (key == null) 417.276 - if (hasNull) 417.277 - return nullValue; 417.278 - else 417.279 - return notFound; 417.280 - if (root == null) 417.281 - return null; 417.282 - return root.find(0, Util.hash(key), key, notFound); 417.283 - } 417.284 - 417.285 - int doCount() { 417.286 - return count; 417.287 - } 417.288 - 417.289 - void ensureEditable(){ 417.290 - Thread owner = edit.get(); 417.291 - if(owner == Thread.currentThread()) 417.292 - return; 417.293 - if(owner != null) 417.294 - throw new IllegalAccessError("Transient used by non-owner thread"); 417.295 - throw new IllegalAccessError("Transient used after persistent! call"); 417.296 - } 417.297 -} 417.298 - 417.299 -static interface INode extends Serializable { 417.300 - INode assoc(int shift, int hash, Object key, Object val, Box addedLeaf); 417.301 - 417.302 - INode without(int shift, int hash, Object key); 417.303 - 417.304 - IMapEntry find(int shift, int hash, Object key); 417.305 - 417.306 - Object find(int shift, int hash, Object key, Object notFound); 417.307 - 417.308 - ISeq nodeSeq(); 417.309 - 417.310 - INode assoc(AtomicReference<Thread> edit, int shift, int hash, Object key, Object val, Box addedLeaf); 417.311 - 417.312 - INode without(AtomicReference<Thread> edit, int shift, int hash, Object key, Box removedLeaf); 417.313 -} 417.314 - 417.315 -final static class ArrayNode implements INode{ 417.316 - int count; 417.317 - final INode[] array; 417.318 - final AtomicReference<Thread> edit; 417.319 - 417.320 - ArrayNode(AtomicReference<Thread> edit, int count, INode[] array){ 417.321 - this.array = array; 417.322 - this.edit = edit; 417.323 - this.count = count; 417.324 - } 417.325 - 417.326 - public INode assoc(int shift, int hash, Object key, Object val, Box addedLeaf){ 417.327 - int idx = mask(hash, shift); 417.328 - INode node = array[idx]; 417.329 - if(node == null) 417.330 - return new ArrayNode(null, count + 1, cloneAndSet(array, idx, BitmapIndexedNode.EMPTY.assoc(shift + 5, hash, key, val, addedLeaf))); 417.331 - INode n = node.assoc(shift + 5, hash, key, val, addedLeaf); 417.332 - if(n == node) 417.333 - return this; 417.334 - return new ArrayNode(null, count, cloneAndSet(array, idx, n)); 417.335 - } 417.336 - 417.337 - public INode without(int shift, int hash, Object key){ 417.338 - int idx = mask(hash, shift); 417.339 - INode node = array[idx]; 417.340 - if(node == null) 417.341 - return this; 417.342 - INode n = node.without(shift + 5, hash, key); 417.343 - if(n == node) 417.344 - return this; 417.345 - if (n == null) { 417.346 - if (count <= 8) // shrink 417.347 - return pack(null, idx); 417.348 - return new ArrayNode(null, count - 1, cloneAndSet(array, idx, n)); 417.349 - } else 417.350 - return new ArrayNode(null, count, cloneAndSet(array, idx, n)); 417.351 - } 417.352 - 417.353 - public IMapEntry find(int shift, int hash, Object key){ 417.354 - int idx = mask(hash, shift); 417.355 - INode node = array[idx]; 417.356 - if(node == null) 417.357 - return null; 417.358 - return node.find(shift + 5, hash, key); 417.359 - } 417.360 - 417.361 - public Object find(int shift, int hash, Object key, Object notFound){ 417.362 - int idx = mask(hash, shift); 417.363 - INode node = array[idx]; 417.364 - if(node == null) 417.365 - return notFound; 417.366 - return node.find(shift + 5, hash, key, notFound); 417.367 - } 417.368 - 417.369 - public ISeq nodeSeq(){ 417.370 - return Seq.create(array); 417.371 - } 417.372 - 417.373 - private ArrayNode ensureEditable(AtomicReference<Thread> edit){ 417.374 - if(this.edit == edit) 417.375 - return this; 417.376 - return new ArrayNode(edit, count, this.array.clone()); 417.377 - } 417.378 - 417.379 - private ArrayNode editAndSet(AtomicReference<Thread> edit, int i, INode n){ 417.380 - ArrayNode editable = ensureEditable(edit); 417.381 - editable.array[i] = n; 417.382 - return editable; 417.383 - } 417.384 - 417.385 - 417.386 - private INode pack(AtomicReference<Thread> edit, int idx) { 417.387 - Object[] newArray = new Object[2*(count - 1)]; 417.388 - int j = 1; 417.389 - int bitmap = 0; 417.390 - for(int i = 0; i < idx; i++) 417.391 - if (array[i] != null) { 417.392 - newArray[j] = array[i]; 417.393 - bitmap |= 1 << i; 417.394 - j += 2; 417.395 - } 417.396 - for(int i = idx + 1; i < array.length; i++) 417.397 - if (array[i] != null) { 417.398 - newArray[j] = array[i]; 417.399 - bitmap |= 1 << i; 417.400 - j += 2; 417.401 - } 417.402 - return new BitmapIndexedNode(edit, bitmap, newArray); 417.403 - } 417.404 - 417.405 - public INode assoc(AtomicReference<Thread> edit, int shift, int hash, Object key, Object val, Box addedLeaf){ 417.406 - int idx = mask(hash, shift); 417.407 - INode node = array[idx]; 417.408 - if(node == null) { 417.409 - ArrayNode editable = editAndSet(edit, idx, BitmapIndexedNode.EMPTY.assoc(edit, shift + 5, hash, key, val, addedLeaf)); 417.410 - editable.count++; 417.411 - return editable; 417.412 - } 417.413 - INode n = node.assoc(edit, shift + 5, hash, key, val, addedLeaf); 417.414 - if(n == node) 417.415 - return this; 417.416 - return editAndSet(edit, idx, n); 417.417 - } 417.418 - 417.419 - public INode without(AtomicReference<Thread> edit, int shift, int hash, Object key, Box removedLeaf){ 417.420 - int idx = mask(hash, shift); 417.421 - INode node = array[idx]; 417.422 - if(node == null) 417.423 - return this; 417.424 - INode n = node.without(edit, shift + 5, hash, key, removedLeaf); 417.425 - if(n == node) 417.426 - return this; 417.427 - if(n == null) { 417.428 - if (count <= 8) // shrink 417.429 - return pack(edit, idx); 417.430 - ArrayNode editable = editAndSet(edit, idx, n); 417.431 - editable.count--; 417.432 - return editable; 417.433 - } 417.434 - return editAndSet(edit, idx, n); 417.435 - } 417.436 - 417.437 - static class Seq extends ASeq { 417.438 - final INode[] nodes; 417.439 - final int i; 417.440 - final ISeq s; 417.441 - 417.442 - static ISeq create(INode[] nodes) { 417.443 - return create(null, nodes, 0, null); 417.444 - } 417.445 - 417.446 - private static ISeq create(IPersistentMap meta, INode[] nodes, int i, ISeq s) { 417.447 - if (s != null) 417.448 - return new Seq(meta, nodes, i, s); 417.449 - for(int j = i; j < nodes.length; j++) 417.450 - if (nodes[j] != null) { 417.451 - ISeq ns = nodes[j].nodeSeq(); 417.452 - if (ns != null) 417.453 - return new Seq(meta, nodes, j + 1, ns); 417.454 - } 417.455 - return null; 417.456 - } 417.457 - 417.458 - private Seq(IPersistentMap meta, INode[] nodes, int i, ISeq s) { 417.459 - super(meta); 417.460 - this.nodes = nodes; 417.461 - this.i = i; 417.462 - this.s = s; 417.463 - } 417.464 - 417.465 - public Obj withMeta(IPersistentMap meta) { 417.466 - return new Seq(meta, nodes, i, s); 417.467 - } 417.468 - 417.469 - public Object first() { 417.470 - return s.first(); 417.471 - } 417.472 - 417.473 - public ISeq next() { 417.474 - return create(null, nodes, i, s.next()); 417.475 - } 417.476 - 417.477 - } 417.478 -} 417.479 - 417.480 -final static class BitmapIndexedNode implements INode{ 417.481 - static final BitmapIndexedNode EMPTY = new BitmapIndexedNode(null, 0, new Object[0]); 417.482 - 417.483 - int bitmap; 417.484 - Object[] array; 417.485 - final AtomicReference<Thread> edit; 417.486 - 417.487 - final int index(int bit){ 417.488 - return Integer.bitCount(bitmap & (bit - 1)); 417.489 - } 417.490 - 417.491 - BitmapIndexedNode(AtomicReference<Thread> edit, int bitmap, Object[] array){ 417.492 - this.bitmap = bitmap; 417.493 - this.array = array; 417.494 - this.edit = edit; 417.495 - } 417.496 - 417.497 - public INode assoc(int shift, int hash, Object key, Object val, Box addedLeaf){ 417.498 - int bit = bitpos(hash, shift); 417.499 - int idx = index(bit); 417.500 - if((bitmap & bit) != 0) { 417.501 - Object keyOrNull = array[2*idx]; 417.502 - Object valOrNode = array[2*idx+1]; 417.503 - if(keyOrNull == null) { 417.504 - INode n = ((INode) valOrNode).assoc(shift + 5, hash, key, val, addedLeaf); 417.505 - if(n == valOrNode) 417.506 - return this; 417.507 - return new BitmapIndexedNode(null, bitmap, cloneAndSet(array, 2*idx+1, n)); 417.508 - } 417.509 - if(Util.equals(key, keyOrNull)) { 417.510 - if(val == valOrNode) 417.511 - return this; 417.512 - return new BitmapIndexedNode(null, bitmap, cloneAndSet(array, 2*idx+1, val)); 417.513 - } 417.514 - addedLeaf.val = addedLeaf; 417.515 - return new BitmapIndexedNode(null, bitmap, 417.516 - cloneAndSet(array, 417.517 - 2*idx, null, 417.518 - 2*idx+1, createNode(shift + 5, keyOrNull, valOrNode, hash, key, val))); 417.519 - } else { 417.520 - int n = Integer.bitCount(bitmap); 417.521 - if(n >= 16) { 417.522 - INode[] nodes = new INode[32]; 417.523 - int jdx = mask(hash, shift); 417.524 - nodes[jdx] = EMPTY.assoc(shift + 5, hash, key, val, addedLeaf); 417.525 - int j = 0; 417.526 - for(int i = 0; i < 32; i++) 417.527 - if(((bitmap >>> i) & 1) != 0) { 417.528 - if (array[j] == null) 417.529 - nodes[i] = (INode) array[j+1]; 417.530 - else 417.531 - nodes[i] = EMPTY.assoc(shift + 5, Util.hash(array[j]), array[j], array[j+1], addedLeaf); 417.532 - j += 2; 417.533 - } 417.534 - return new ArrayNode(null, n + 1, nodes); 417.535 - } else { 417.536 - Object[] newArray = new Object[2*(n+1)]; 417.537 - System.arraycopy(array, 0, newArray, 0, 2*idx); 417.538 - newArray[2*idx] = key; 417.539 - addedLeaf.val = addedLeaf; 417.540 - newArray[2*idx+1] = val; 417.541 - System.arraycopy(array, 2*idx, newArray, 2*(idx+1), 2*(n-idx)); 417.542 - return new BitmapIndexedNode(null, bitmap | bit, newArray); 417.543 - } 417.544 - } 417.545 - } 417.546 - 417.547 - public INode without(int shift, int hash, Object key){ 417.548 - int bit = bitpos(hash, shift); 417.549 - if((bitmap & bit) == 0) 417.550 - return this; 417.551 - int idx = index(bit); 417.552 - Object keyOrNull = array[2*idx]; 417.553 - Object valOrNode = array[2*idx+1]; 417.554 - if(keyOrNull == null) { 417.555 - INode n = ((INode) valOrNode).without(shift + 5, hash, key); 417.556 - if (n == valOrNode) 417.557 - return this; 417.558 - if (n != null) 417.559 - return new BitmapIndexedNode(null, bitmap, cloneAndSet(array, 2*idx+1, n)); 417.560 - if (bitmap == bit) 417.561 - return null; 417.562 - return new BitmapIndexedNode(null, bitmap ^ bit, removePair(array, idx)); 417.563 - } 417.564 - if(Util.equals(key, keyOrNull)) 417.565 - // TODO: collapse 417.566 - return new BitmapIndexedNode(null, bitmap ^ bit, removePair(array, idx)); 417.567 - return this; 417.568 - } 417.569 - 417.570 - public IMapEntry find(int shift, int hash, Object key){ 417.571 - int bit = bitpos(hash, shift); 417.572 - if((bitmap & bit) == 0) 417.573 - return null; 417.574 - int idx = index(bit); 417.575 - Object keyOrNull = array[2*idx]; 417.576 - Object valOrNode = array[2*idx+1]; 417.577 - if(keyOrNull == null) 417.578 - return ((INode) valOrNode).find(shift + 5, hash, key); 417.579 - if(Util.equals(key, keyOrNull)) 417.580 - return new MapEntry(keyOrNull, valOrNode); 417.581 - return null; 417.582 - } 417.583 - 417.584 - public Object find(int shift, int hash, Object key, Object notFound){ 417.585 - int bit = bitpos(hash, shift); 417.586 - if((bitmap & bit) == 0) 417.587 - return notFound; 417.588 - int idx = index(bit); 417.589 - Object keyOrNull = array[2*idx]; 417.590 - Object valOrNode = array[2*idx+1]; 417.591 - if(keyOrNull == null) 417.592 - return ((INode) valOrNode).find(shift + 5, hash, key, notFound); 417.593 - if(Util.equals(key, keyOrNull)) 417.594 - return valOrNode; 417.595 - return notFound; 417.596 - } 417.597 - 417.598 - public ISeq nodeSeq(){ 417.599 - return NodeSeq.create(array); 417.600 - } 417.601 - 417.602 - private BitmapIndexedNode ensureEditable(AtomicReference<Thread> edit){ 417.603 - if(this.edit == edit) 417.604 - return this; 417.605 - int n = Integer.bitCount(bitmap); 417.606 - Object[] newArray = new Object[n >= 0 ? 2*(n+1) : 4]; // make room for next assoc 417.607 - System.arraycopy(array, 0, newArray, 0, 2*n); 417.608 - return new BitmapIndexedNode(edit, bitmap, newArray); 417.609 - } 417.610 - 417.611 - private BitmapIndexedNode editAndSet(AtomicReference<Thread> edit, int i, Object a) { 417.612 - BitmapIndexedNode editable = ensureEditable(edit); 417.613 - editable.array[i] = a; 417.614 - return editable; 417.615 - } 417.616 - 417.617 - private BitmapIndexedNode editAndSet(AtomicReference<Thread> edit, int i, Object a, int j, Object b) { 417.618 - BitmapIndexedNode editable = ensureEditable(edit); 417.619 - editable.array[i] = a; 417.620 - editable.array[j] = b; 417.621 - return editable; 417.622 - } 417.623 - 417.624 - private BitmapIndexedNode editAndRemovePair(AtomicReference<Thread> edit, int bit, int i) { 417.625 - if (bitmap == bit) 417.626 - return null; 417.627 - BitmapIndexedNode editable = ensureEditable(edit); 417.628 - editable.bitmap ^= bit; 417.629 - System.arraycopy(editable.array, 2*(i+1), editable.array, 2*i, editable.array.length - 2*(i+1)); 417.630 - editable.array[editable.array.length - 2] = null; 417.631 - editable.array[editable.array.length - 1] = null; 417.632 - return editable; 417.633 - } 417.634 - 417.635 - public INode assoc(AtomicReference<Thread> edit, int shift, int hash, Object key, Object val, Box addedLeaf){ 417.636 - int bit = bitpos(hash, shift); 417.637 - int idx = index(bit); 417.638 - if((bitmap & bit) != 0) { 417.639 - Object keyOrNull = array[2*idx]; 417.640 - Object valOrNode = array[2*idx+1]; 417.641 - if(keyOrNull == null) { 417.642 - INode n = ((INode) valOrNode).assoc(edit, shift + 5, hash, key, val, addedLeaf); 417.643 - if(n == valOrNode) 417.644 - return this; 417.645 - return editAndSet(edit, 2*idx+1, n); 417.646 - } 417.647 - if(Util.equals(key, keyOrNull)) { 417.648 - if(val == valOrNode) 417.649 - return this; 417.650 - return editAndSet(edit, 2*idx+1, val); 417.651 - } 417.652 - addedLeaf.val = addedLeaf; 417.653 - return editAndSet(edit, 2*idx, null, 2*idx+1, 417.654 - createNode(edit, shift + 5, keyOrNull, valOrNode, hash, key, val)); 417.655 - } else { 417.656 - int n = Integer.bitCount(bitmap); 417.657 - if(n*2 < array.length) { 417.658 - addedLeaf.val = addedLeaf; 417.659 - BitmapIndexedNode editable = ensureEditable(edit); 417.660 - System.arraycopy(editable.array, 2*idx, editable.array, 2*(idx+1), 2*(n-idx)); 417.661 - editable.array[2*idx] = key; 417.662 - editable.array[2*idx+1] = val; 417.663 - editable.bitmap |= bit; 417.664 - return editable; 417.665 - } 417.666 - if(n >= 16) { 417.667 - INode[] nodes = new INode[32]; 417.668 - int jdx = mask(hash, shift); 417.669 - nodes[jdx] = EMPTY.assoc(edit, shift + 5, hash, key, val, addedLeaf); 417.670 - int j = 0; 417.671 - for(int i = 0; i < 32; i++) 417.672 - if(((bitmap >>> i) & 1) != 0) { 417.673 - if (array[j] == null) 417.674 - nodes[i] = (INode) array[j+1]; 417.675 - else 417.676 - nodes[i] = EMPTY.assoc(edit, shift + 5, Util.hash(array[j]), array[j], array[j+1], addedLeaf); 417.677 - j += 2; 417.678 - } 417.679 - return new ArrayNode(edit, n + 1, nodes); 417.680 - } else { 417.681 - Object[] newArray = new Object[2*(n+4)]; 417.682 - System.arraycopy(array, 0, newArray, 0, 2*idx); 417.683 - newArray[2*idx] = key; 417.684 - addedLeaf.val = addedLeaf; 417.685 - newArray[2*idx+1] = val; 417.686 - System.arraycopy(array, 2*idx, newArray, 2*(idx+1), 2*(n-idx)); 417.687 - BitmapIndexedNode editable = ensureEditable(edit); 417.688 - editable.array = newArray; 417.689 - editable.bitmap |= bit; 417.690 - return editable; 417.691 - } 417.692 - } 417.693 - } 417.694 - 417.695 - public INode without(AtomicReference<Thread> edit, int shift, int hash, Object key, Box removedLeaf){ 417.696 - int bit = bitpos(hash, shift); 417.697 - if((bitmap & bit) == 0) 417.698 - return this; 417.699 - int idx = index(bit); 417.700 - Object keyOrNull = array[2*idx]; 417.701 - Object valOrNode = array[2*idx+1]; 417.702 - if(keyOrNull == null) { 417.703 - INode n = ((INode) valOrNode).without(edit, shift + 5, hash, key, removedLeaf); 417.704 - if (n == valOrNode) 417.705 - return this; 417.706 - if (n != null) 417.707 - return editAndSet(edit, 2*idx+1, n); 417.708 - if (bitmap == bit) 417.709 - return null; 417.710 - removedLeaf.val = removedLeaf; 417.711 - return editAndRemovePair(edit, bit, idx); 417.712 - } 417.713 - if(Util.equals(key, keyOrNull)) { 417.714 - removedLeaf.val = removedLeaf; 417.715 - // TODO: collapse 417.716 - return editAndRemovePair(edit, bit, idx); 417.717 - } 417.718 - return this; 417.719 - } 417.720 -} 417.721 - 417.722 -final static class HashCollisionNode implements INode{ 417.723 - 417.724 - final int hash; 417.725 - int count; 417.726 - Object[] array; 417.727 - final AtomicReference<Thread> edit; 417.728 - 417.729 - HashCollisionNode(AtomicReference<Thread> edit, int hash, int count, Object... array){ 417.730 - this.edit = edit; 417.731 - this.hash = hash; 417.732 - this.count = count; 417.733 - this.array = array; 417.734 - } 417.735 - 417.736 - public INode assoc(int shift, int hash, Object key, Object val, Box addedLeaf){ 417.737 - if(hash == this.hash) { 417.738 - int idx = findIndex(key); 417.739 - if(idx != -1) { 417.740 - if(array[idx + 1] == val) 417.741 - return this; 417.742 - return new HashCollisionNode(null, hash, count, cloneAndSet(array, idx + 1, val)); 417.743 - } 417.744 - Object[] newArray = new Object[array.length + 2]; 417.745 - System.arraycopy(array, 0, newArray, 0, array.length); 417.746 - newArray[array.length] = key; 417.747 - newArray[array.length + 1] = val; 417.748 - addedLeaf.val = addedLeaf; 417.749 - return new HashCollisionNode(edit, hash, count + 1, newArray); 417.750 - } 417.751 - // nest it in a bitmap node 417.752 - return new BitmapIndexedNode(null, bitpos(this.hash, shift), new Object[] {null, this}) 417.753 - .assoc(shift, hash, key, val, addedLeaf); 417.754 - } 417.755 - 417.756 - public INode without(int shift, int hash, Object key){ 417.757 - int idx = findIndex(key); 417.758 - if(idx == -1) 417.759 - return this; 417.760 - if(count == 1) 417.761 - return null; 417.762 - return new HashCollisionNode(null, hash, count - 1, removePair(array, idx/2)); 417.763 - } 417.764 - 417.765 - public IMapEntry find(int shift, int hash, Object key){ 417.766 - int idx = findIndex(key); 417.767 - if(idx < 0) 417.768 - return null; 417.769 - if(Util.equals(key, array[idx])) 417.770 - return new MapEntry(array[idx], array[idx+1]); 417.771 - return null; 417.772 - } 417.773 - 417.774 - public Object find(int shift, int hash, Object key, Object notFound){ 417.775 - int idx = findIndex(key); 417.776 - if(idx < 0) 417.777 - return notFound; 417.778 - if(Util.equals(key, array[idx])) 417.779 - return array[idx+1]; 417.780 - return notFound; 417.781 - } 417.782 - 417.783 - public ISeq nodeSeq(){ 417.784 - return NodeSeq.create(array); 417.785 - } 417.786 - 417.787 - public int findIndex(Object key){ 417.788 - for(int i = 0; i < 2*count; i+=2) 417.789 - { 417.790 - if(Util.equals(key, array[i])) 417.791 - return i; 417.792 - } 417.793 - return -1; 417.794 - } 417.795 - 417.796 - private HashCollisionNode ensureEditable(AtomicReference<Thread> edit){ 417.797 - if(this.edit == edit) 417.798 - return this; 417.799 - return new HashCollisionNode(edit, hash, count, array); 417.800 - } 417.801 - 417.802 - private HashCollisionNode ensureEditable(AtomicReference<Thread> edit, int count, Object[] array){ 417.803 - if(this.edit == edit) { 417.804 - this.array = array; 417.805 - this.count = count; 417.806 - return this; 417.807 - } 417.808 - return new HashCollisionNode(edit, hash, count, array); 417.809 - } 417.810 - 417.811 - private HashCollisionNode editAndSet(AtomicReference<Thread> edit, int i, Object a) { 417.812 - HashCollisionNode editable = ensureEditable(edit); 417.813 - editable.array[i] = a; 417.814 - return editable; 417.815 - } 417.816 - 417.817 - private HashCollisionNode editAndSet(AtomicReference<Thread> edit, int i, Object a, int j, Object b) { 417.818 - HashCollisionNode editable = ensureEditable(edit); 417.819 - editable.array[i] = a; 417.820 - editable.array[j] = b; 417.821 - return editable; 417.822 - } 417.823 - 417.824 - 417.825 - public INode assoc(AtomicReference<Thread> edit, int shift, int hash, Object key, Object val, Box addedLeaf){ 417.826 - if(hash == this.hash) { 417.827 - int idx = findIndex(key); 417.828 - if(idx != -1) { 417.829 - if(array[idx + 1] == val) 417.830 - return this; 417.831 - return editAndSet(edit, idx+1, val); 417.832 - } 417.833 - if (array.length > 2*count) { 417.834 - addedLeaf.val = addedLeaf; 417.835 - HashCollisionNode editable = editAndSet(edit, 2*count, key, 2*count+1, val); 417.836 - editable.count++; 417.837 - return editable; 417.838 - } 417.839 - Object[] newArray = new Object[array.length + 2]; 417.840 - System.arraycopy(array, 0, newArray, 0, array.length); 417.841 - newArray[array.length] = key; 417.842 - newArray[array.length + 1] = val; 417.843 - addedLeaf.val = addedLeaf; 417.844 - return ensureEditable(edit, count + 1, newArray); 417.845 - } 417.846 - // nest it in a bitmap node 417.847 - return new BitmapIndexedNode(edit, bitpos(this.hash, shift), new Object[] {null, this, null, null}) 417.848 - .assoc(edit, shift, hash, key, val, addedLeaf); 417.849 - } 417.850 - 417.851 - public INode without(AtomicReference<Thread> edit, int shift, int hash, Object key, Box removedLeaf){ 417.852 - int idx = findIndex(key); 417.853 - if(idx == -1) 417.854 - return this; 417.855 - if(count == 1) 417.856 - return null; 417.857 - HashCollisionNode editable = ensureEditable(edit); 417.858 - editable.array[idx] = editable.array[2*count-2]; 417.859 - editable.array[idx+1] = editable.array[2*count-1]; 417.860 - editable.array[2*count-2] = editable.array[2*count-1] = null; 417.861 - editable.count--; 417.862 - return editable; 417.863 - } 417.864 -} 417.865 - 417.866 -/* 417.867 -public static void main(String[] args){ 417.868 - try 417.869 - { 417.870 - ArrayList words = new ArrayList(); 417.871 - Scanner s = new Scanner(new File(args[0])); 417.872 - s.useDelimiter(Pattern.compile("\\W")); 417.873 - while(s.hasNext()) 417.874 - { 417.875 - String word = s.next(); 417.876 - words.add(word); 417.877 - } 417.878 - System.out.println("words: " + words.size()); 417.879 - IPersistentMap map = PersistentHashMap.EMPTY; 417.880 - //IPersistentMap map = new PersistentTreeMap(); 417.881 - //Map ht = new Hashtable(); 417.882 - Map ht = new HashMap(); 417.883 - Random rand; 417.884 - 417.885 - System.out.println("Building map"); 417.886 - long startTime = System.nanoTime(); 417.887 - for(Object word5 : words) 417.888 - { 417.889 - map = map.assoc(word5, word5); 417.890 - } 417.891 - rand = new Random(42); 417.892 - IPersistentMap snapshotMap = map; 417.893 - for(int i = 0; i < words.size() / 200; i++) 417.894 - { 417.895 - map = map.without(words.get(rand.nextInt(words.size() / 2))); 417.896 - } 417.897 - long estimatedTime = System.nanoTime() - startTime; 417.898 - System.out.println("count = " + map.count() + ", time: " + estimatedTime / 1000000); 417.899 - 417.900 - System.out.println("Building ht"); 417.901 - startTime = System.nanoTime(); 417.902 - for(Object word1 : words) 417.903 - { 417.904 - ht.put(word1, word1); 417.905 - } 417.906 - rand = new Random(42); 417.907 - for(int i = 0; i < words.size() / 200; i++) 417.908 - { 417.909 - ht.remove(words.get(rand.nextInt(words.size() / 2))); 417.910 - } 417.911 - estimatedTime = System.nanoTime() - startTime; 417.912 - System.out.println("count = " + ht.size() + ", time: " + estimatedTime / 1000000); 417.913 - 417.914 - System.out.println("map lookup"); 417.915 - startTime = System.nanoTime(); 417.916 - int c = 0; 417.917 - for(Object word2 : words) 417.918 - { 417.919 - if(!map.contains(word2)) 417.920 - ++c; 417.921 - } 417.922 - estimatedTime = System.nanoTime() - startTime; 417.923 - System.out.println("notfound = " + c + ", time: " + estimatedTime / 1000000); 417.924 - System.out.println("ht lookup"); 417.925 - startTime = System.nanoTime(); 417.926 - c = 0; 417.927 - for(Object word3 : words) 417.928 - { 417.929 - if(!ht.containsKey(word3)) 417.930 - ++c; 417.931 - } 417.932 - estimatedTime = System.nanoTime() - startTime; 417.933 - System.out.println("notfound = " + c + ", time: " + estimatedTime / 1000000); 417.934 - System.out.println("snapshotMap lookup"); 417.935 - startTime = System.nanoTime(); 417.936 - c = 0; 417.937 - for(Object word4 : words) 417.938 - { 417.939 - if(!snapshotMap.contains(word4)) 417.940 - ++c; 417.941 - } 417.942 - estimatedTime = System.nanoTime() - startTime; 417.943 - System.out.println("notfound = " + c + ", time: " + estimatedTime / 1000000); 417.944 - } 417.945 - catch(FileNotFoundException e) 417.946 - { 417.947 - e.printStackTrace(); 417.948 - } 417.949 - 417.950 -} 417.951 -*/ 417.952 - 417.953 -private static INode[] cloneAndSet(INode[] array, int i, INode a) { 417.954 - INode[] clone = array.clone(); 417.955 - clone[i] = a; 417.956 - return clone; 417.957 -} 417.958 - 417.959 -private static Object[] cloneAndSet(Object[] array, int i, Object a) { 417.960 - Object[] clone = array.clone(); 417.961 - clone[i] = a; 417.962 - return clone; 417.963 -} 417.964 - 417.965 -private static Object[] cloneAndSet(Object[] array, int i, Object a, int j, Object b) { 417.966 - Object[] clone = array.clone(); 417.967 - clone[i] = a; 417.968 - clone[j] = b; 417.969 - return clone; 417.970 -} 417.971 - 417.972 -private static Object[] removePair(Object[] array, int i) { 417.973 - Object[] newArray = new Object[array.length - 2]; 417.974 - System.arraycopy(array, 0, newArray, 0, 2*i); 417.975 - System.arraycopy(array, 2*(i+1), newArray, 2*i, newArray.length - 2*i); 417.976 - return newArray; 417.977 -} 417.978 - 417.979 -private static INode createNode(int shift, Object key1, Object val1, int key2hash, Object key2, Object val2) { 417.980 - int key1hash = Util.hash(key1); 417.981 - if(key1hash == key2hash) 417.982 - return new HashCollisionNode(null, key1hash, 2, new Object[] {key1, val1, key2, val2}); 417.983 - Box _ = new Box(null); 417.984 - AtomicReference<Thread> edit = new AtomicReference<Thread>(); 417.985 - return BitmapIndexedNode.EMPTY 417.986 - .assoc(edit, shift, key1hash, key1, val1, _) 417.987 - .assoc(edit, shift, key2hash, key2, val2, _); 417.988 -} 417.989 - 417.990 -private static INode createNode(AtomicReference<Thread> edit, int shift, Object key1, Object val1, int key2hash, Object key2, Object val2) { 417.991 - int key1hash = Util.hash(key1); 417.992 - if(key1hash == key2hash) 417.993 - return new HashCollisionNode(null, key1hash, 2, new Object[] {key1, val1, key2, val2}); 417.994 - Box _ = new Box(null); 417.995 - return BitmapIndexedNode.EMPTY 417.996 - .assoc(edit, shift, key1hash, key1, val1, _) 417.997 - .assoc(edit, shift, key2hash, key2, val2, _); 417.998 -} 417.999 - 417.1000 -private static int bitpos(int hash, int shift){ 417.1001 - return 1 << mask(hash, shift); 417.1002 -} 417.1003 - 417.1004 -static final class NodeSeq extends ASeq { 417.1005 - final Object[] array; 417.1006 - final int i; 417.1007 - final ISeq s; 417.1008 - 417.1009 - NodeSeq(Object[] array, int i) { 417.1010 - this(null, array, i, null); 417.1011 - } 417.1012 - 417.1013 - static ISeq create(Object[] array) { 417.1014 - return create(array, 0, null); 417.1015 - } 417.1016 - 417.1017 - private static ISeq create(Object[] array, int i, ISeq s) { 417.1018 - if(s != null) 417.1019 - return new NodeSeq(null, array, i, s); 417.1020 - for(int j = i; j < array.length; j+=2) { 417.1021 - if(array[j] != null) 417.1022 - return new NodeSeq(null, array, j, null); 417.1023 - INode node = (INode) array[j+1]; 417.1024 - if (node != null) { 417.1025 - ISeq nodeSeq = node.nodeSeq(); 417.1026 - if(nodeSeq != null) 417.1027 - return new NodeSeq(null, array, j + 2, nodeSeq); 417.1028 - } 417.1029 - } 417.1030 - return null; 417.1031 - } 417.1032 - 417.1033 - NodeSeq(IPersistentMap meta, Object[] array, int i, ISeq s) { 417.1034 - super(meta); 417.1035 - this.array = array; 417.1036 - this.i = i; 417.1037 - this.s = s; 417.1038 - } 417.1039 - 417.1040 - public Obj withMeta(IPersistentMap meta) { 417.1041 - return new NodeSeq(meta, array, i, s); 417.1042 - } 417.1043 - 417.1044 - public Object first() { 417.1045 - if(s != null) 417.1046 - return s.first(); 417.1047 - return new MapEntry(array[i], array[i+1]); 417.1048 - } 417.1049 - 417.1050 - public ISeq next() { 417.1051 - if(s != null) 417.1052 - return create(array, i, s.next()); 417.1053 - return create(array, i + 2, null); 417.1054 - } 417.1055 -} 417.1056 - 417.1057 -} 417.1058 \ No newline at end of file
418.1 --- a/src/clojure/lang/PersistentHashSet.java Sat Aug 21 06:25:44 2010 -0400 418.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 418.3 @@ -1,128 +0,0 @@ 418.4 -/** 418.5 - * Copyright (c) Rich Hickey. All rights reserved. 418.6 - * The use and distribution terms for this software are covered by the 418.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 418.8 - * which can be found in the file epl-v10.html at the root of this distribution. 418.9 - * By using this software in any fashion, you are agreeing to be bound by 418.10 - * the terms of this license. 418.11 - * You must not remove this notice, or any other, from this software. 418.12 - **/ 418.13 - 418.14 -/* rich Mar 3, 2008 */ 418.15 - 418.16 -package clojure.lang; 418.17 - 418.18 -import java.util.List; 418.19 - 418.20 -public class PersistentHashSet extends APersistentSet implements IObj, IEditableCollection { 418.21 - 418.22 -static public final PersistentHashSet EMPTY = new PersistentHashSet(null, PersistentHashMap.EMPTY); 418.23 - 418.24 -final IPersistentMap _meta; 418.25 - 418.26 -public static PersistentHashSet create(Object... init){ 418.27 - PersistentHashSet ret = EMPTY; 418.28 - for(int i = 0; i < init.length; i++) 418.29 - { 418.30 - ret = (PersistentHashSet) ret.cons(init[i]); 418.31 - } 418.32 - return ret; 418.33 -} 418.34 - 418.35 -public static PersistentHashSet create(List init){ 418.36 - PersistentHashSet ret = EMPTY; 418.37 - for(Object key : init) 418.38 - { 418.39 - ret = (PersistentHashSet) ret.cons(key); 418.40 - } 418.41 - return ret; 418.42 -} 418.43 - 418.44 -static public PersistentHashSet create(ISeq items){ 418.45 - PersistentHashSet ret = EMPTY; 418.46 - for(; items != null; items = items.next()) 418.47 - { 418.48 - ret = (PersistentHashSet) ret.cons(items.first()); 418.49 - } 418.50 - return ret; 418.51 -} 418.52 - 418.53 -public static PersistentHashSet createWithCheck(Object... init){ 418.54 - PersistentHashSet ret = EMPTY; 418.55 - for(int i = 0; i < init.length; i++) 418.56 - { 418.57 - ret = (PersistentHashSet) ret.cons(init[i]); 418.58 - if(ret.count() != i + 1) 418.59 - throw new IllegalArgumentException("Duplicate key: " + init[i]); 418.60 - } 418.61 - return ret; 418.62 -} 418.63 - 418.64 -public static PersistentHashSet createWithCheck(List init){ 418.65 - PersistentHashSet ret = EMPTY; 418.66 - int i=0; 418.67 - for(Object key : init) 418.68 - { 418.69 - ret = (PersistentHashSet) ret.cons(key); 418.70 - if(ret.count() != i + 1) 418.71 - throw new IllegalArgumentException("Duplicate key: " + key); 418.72 - ++i; 418.73 - } 418.74 - return ret; 418.75 -} 418.76 - 418.77 -static public PersistentHashSet createWithCheck(ISeq items){ 418.78 - PersistentHashSet ret = EMPTY; 418.79 - for(int i=0; items != null; items = items.next(), ++i) 418.80 - { 418.81 - ret = (PersistentHashSet) ret.cons(items.first()); 418.82 - if(ret.count() != i + 1) 418.83 - throw new IllegalArgumentException("Duplicate key: " + items.first()); 418.84 - } 418.85 - return ret; 418.86 -} 418.87 - 418.88 -PersistentHashSet(IPersistentMap meta, IPersistentMap impl){ 418.89 - super(impl); 418.90 - this._meta = meta; 418.91 -} 418.92 - 418.93 -public IPersistentSet disjoin(Object key) throws Exception{ 418.94 - if(contains(key)) 418.95 - return new PersistentHashSet(meta(),impl.without(key)); 418.96 - return this; 418.97 -} 418.98 - 418.99 -public IPersistentSet cons(Object o){ 418.100 - if(contains(o)) 418.101 - return this; 418.102 - return new PersistentHashSet(meta(),impl.assoc(o,o)); 418.103 -} 418.104 - 418.105 -public IPersistentCollection empty(){ 418.106 - return EMPTY.withMeta(meta()); 418.107 -} 418.108 - 418.109 -public PersistentHashSet withMeta(IPersistentMap meta){ 418.110 - return new PersistentHashSet(meta, impl); 418.111 -} 418.112 - 418.113 -public ITransientCollection asTransient() { 418.114 - return new TransientHashSet(((PersistentHashMap) impl).asTransient()); 418.115 -} 418.116 - 418.117 -public IPersistentMap meta(){ 418.118 - return _meta; 418.119 -} 418.120 - 418.121 -static final class TransientHashSet extends ATransientSet { 418.122 - TransientHashSet(ITransientMap impl) { 418.123 - super(impl); 418.124 - } 418.125 - 418.126 - public IPersistentCollection persistent() { 418.127 - return new PersistentHashSet(null, impl.persistent()); 418.128 - } 418.129 -} 418.130 - 418.131 -}
419.1 --- a/src/clojure/lang/PersistentList.java Sat Aug 21 06:25:44 2010 -0400 419.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 419.3 @@ -1,311 +0,0 @@ 419.4 -/** 419.5 - * Copyright (c) Rich Hickey. All rights reserved. 419.6 - * The use and distribution terms for this software are covered by the 419.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 419.8 - * which can be found in the file epl-v10.html at the root of this distribution. 419.9 - * By using this software in any fashion, you are agreeing to be bound by 419.10 - * the terms of this license. 419.11 - * You must not remove this notice, or any other, from this software. 419.12 - **/ 419.13 - 419.14 -package clojure.lang; 419.15 - 419.16 -import java.io.Serializable; 419.17 -import java.util.*; 419.18 - 419.19 -public class PersistentList extends ASeq implements IPersistentList, IReduce, List, Counted { 419.20 - 419.21 -private final Object _first; 419.22 -private final IPersistentList _rest; 419.23 -private final int _count; 419.24 - 419.25 -public static IFn creator = new RestFn(){ 419.26 - final public int getRequiredArity(){ 419.27 - return 0; 419.28 - } 419.29 - 419.30 - final protected Object doInvoke(Object args) throws Exception{ 419.31 - if(args instanceof ArraySeq) 419.32 - { 419.33 - Object[] argsarray = (Object[]) ((ArraySeq) args).array; 419.34 - IPersistentList ret = EMPTY; 419.35 - for(int i = argsarray.length - 1; i >= 0; --i) 419.36 - ret = (IPersistentList) ret.cons(argsarray[i]); 419.37 - return ret; 419.38 - } 419.39 - LinkedList list = new LinkedList(); 419.40 - for(ISeq s = RT.seq(args); s != null; s = s.next()) 419.41 - list.add(s.first()); 419.42 - return create(list); 419.43 - } 419.44 - 419.45 - public IObj withMeta(IPersistentMap meta){ 419.46 - throw new UnsupportedOperationException(); 419.47 - } 419.48 - 419.49 - public IPersistentMap meta(){ 419.50 - return null; 419.51 - } 419.52 -}; 419.53 - 419.54 -final public static EmptyList EMPTY = new EmptyList(null); 419.55 - 419.56 -public PersistentList(Object first){ 419.57 - this._first = first; 419.58 - this._rest = null; 419.59 - 419.60 - this._count = 1; 419.61 -} 419.62 - 419.63 -PersistentList(IPersistentMap meta, Object _first, IPersistentList _rest, int _count){ 419.64 - super(meta); 419.65 - this._first = _first; 419.66 - this._rest = _rest; 419.67 - this._count = _count; 419.68 -} 419.69 - 419.70 -public static IPersistentList create(List init){ 419.71 - IPersistentList ret = EMPTY; 419.72 - for(ListIterator i = init.listIterator(init.size()); i.hasPrevious();) 419.73 - { 419.74 - ret = (IPersistentList) ret.cons(i.previous()); 419.75 - } 419.76 - return ret; 419.77 -} 419.78 - 419.79 -public Object first(){ 419.80 - return _first; 419.81 -} 419.82 - 419.83 -public ISeq next(){ 419.84 - if(_count == 1) 419.85 - return null; 419.86 - return (ISeq) _rest; 419.87 -} 419.88 - 419.89 -public Object peek(){ 419.90 - return first(); 419.91 -} 419.92 - 419.93 -public IPersistentList pop(){ 419.94 - if(_rest == null) 419.95 - return EMPTY.withMeta(_meta); 419.96 - return _rest; 419.97 -} 419.98 - 419.99 -public int count(){ 419.100 - return _count; 419.101 -} 419.102 - 419.103 -public PersistentList cons(Object o){ 419.104 - return new PersistentList(meta(), o, this, _count + 1); 419.105 -} 419.106 - 419.107 -public IPersistentCollection empty(){ 419.108 - return EMPTY.withMeta(meta()); 419.109 -} 419.110 - 419.111 -public PersistentList withMeta(IPersistentMap meta){ 419.112 - if(meta != _meta) 419.113 - return new PersistentList(meta, _first, _rest, _count); 419.114 - return this; 419.115 -} 419.116 - 419.117 -public Object reduce(IFn f) throws Exception{ 419.118 - Object ret = first(); 419.119 - for(ISeq s = next(); s != null; s = s.next()) 419.120 - ret = f.invoke(ret, s.first()); 419.121 - return ret; 419.122 -} 419.123 - 419.124 -public Object reduce(IFn f, Object start) throws Exception{ 419.125 - Object ret = f.invoke(start, first()); 419.126 - for(ISeq s = next(); s != null; s = s.next()) 419.127 - ret = f.invoke(ret, s.first()); 419.128 - return ret; 419.129 -} 419.130 - 419.131 - 419.132 - static class EmptyList extends Obj implements IPersistentList, List, ISeq, Counted{ 419.133 - 419.134 - public int hashCode(){ 419.135 - return 1; 419.136 - } 419.137 - 419.138 - public boolean equals(Object o) { 419.139 - return (o instanceof Sequential || o instanceof List) && RT.seq(o) == null; 419.140 - } 419.141 - 419.142 - public boolean equiv(Object o){ 419.143 - return equals(o); 419.144 - } 419.145 - 419.146 - EmptyList(IPersistentMap meta){ 419.147 - super(meta); 419.148 - } 419.149 - 419.150 - public Object first() { 419.151 - return null; 419.152 - } 419.153 - 419.154 - public ISeq next() { 419.155 - return null; 419.156 - } 419.157 - 419.158 - public ISeq more() { 419.159 - return this; 419.160 - } 419.161 - 419.162 - public PersistentList cons(Object o){ 419.163 - return new PersistentList(meta(), o, null, 1); 419.164 - } 419.165 - 419.166 - public IPersistentCollection empty(){ 419.167 - return this; 419.168 - } 419.169 - 419.170 - public EmptyList withMeta(IPersistentMap meta){ 419.171 - if(meta != meta()) 419.172 - return new EmptyList(meta); 419.173 - return this; 419.174 - } 419.175 - 419.176 - public Object peek(){ 419.177 - return null; 419.178 - } 419.179 - 419.180 - public IPersistentList pop(){ 419.181 - throw new IllegalStateException("Can't pop empty list"); 419.182 - } 419.183 - 419.184 - public int count(){ 419.185 - return 0; 419.186 - } 419.187 - 419.188 - public ISeq seq(){ 419.189 - return null; 419.190 - } 419.191 - 419.192 - 419.193 - public int size(){ 419.194 - return 0; 419.195 - } 419.196 - 419.197 - public boolean isEmpty(){ 419.198 - return true; 419.199 - } 419.200 - 419.201 - public boolean contains(Object o){ 419.202 - return false; 419.203 - } 419.204 - 419.205 - public Iterator iterator(){ 419.206 - return new Iterator(){ 419.207 - 419.208 - public boolean hasNext(){ 419.209 - return false; 419.210 - } 419.211 - 419.212 - public Object next(){ 419.213 - throw new NoSuchElementException(); 419.214 - } 419.215 - 419.216 - public void remove(){ 419.217 - throw new UnsupportedOperationException(); 419.218 - } 419.219 - }; 419.220 - } 419.221 - 419.222 - public Object[] toArray(){ 419.223 - return RT.EMPTY_ARRAY; 419.224 - } 419.225 - 419.226 - public boolean add(Object o){ 419.227 - throw new UnsupportedOperationException(); 419.228 - } 419.229 - 419.230 - public boolean remove(Object o){ 419.231 - throw new UnsupportedOperationException(); 419.232 - } 419.233 - 419.234 - public boolean addAll(Collection collection){ 419.235 - throw new UnsupportedOperationException(); 419.236 - } 419.237 - 419.238 - public void clear(){ 419.239 - throw new UnsupportedOperationException(); 419.240 - } 419.241 - 419.242 - public boolean retainAll(Collection collection){ 419.243 - throw new UnsupportedOperationException(); 419.244 - } 419.245 - 419.246 - public boolean removeAll(Collection collection){ 419.247 - throw new UnsupportedOperationException(); 419.248 - } 419.249 - 419.250 - public boolean containsAll(Collection collection){ 419.251 - return collection.isEmpty(); 419.252 - } 419.253 - 419.254 - public Object[] toArray(Object[] objects){ 419.255 - if(objects.length > 0) 419.256 - objects[0] = null; 419.257 - return objects; 419.258 - } 419.259 - 419.260 - //////////// List stuff ///////////////// 419.261 - private List reify(){ 419.262 - return Collections.unmodifiableList(new ArrayList(this)); 419.263 - } 419.264 - 419.265 - public List subList(int fromIndex, int toIndex){ 419.266 - return reify().subList(fromIndex, toIndex); 419.267 - } 419.268 - 419.269 - public Object set(int index, Object element){ 419.270 - throw new UnsupportedOperationException(); 419.271 - } 419.272 - 419.273 - public Object remove(int index){ 419.274 - throw new UnsupportedOperationException(); 419.275 - } 419.276 - 419.277 - public int indexOf(Object o){ 419.278 - ISeq s = seq(); 419.279 - for(int i = 0; s != null; s = s.next(), i++) 419.280 - { 419.281 - if(Util.equiv(s.first(), o)) 419.282 - return i; 419.283 - } 419.284 - return -1; 419.285 - } 419.286 - 419.287 - public int lastIndexOf(Object o){ 419.288 - return reify().lastIndexOf(o); 419.289 - } 419.290 - 419.291 - public ListIterator listIterator(){ 419.292 - return reify().listIterator(); 419.293 - } 419.294 - 419.295 - public ListIterator listIterator(int index){ 419.296 - return reify().listIterator(index); 419.297 - } 419.298 - 419.299 - public Object get(int index){ 419.300 - return RT.nth(this, index); 419.301 - } 419.302 - 419.303 - public void add(int index, Object element){ 419.304 - throw new UnsupportedOperationException(); 419.305 - } 419.306 - 419.307 - public boolean addAll(int index, Collection c){ 419.308 - throw new UnsupportedOperationException(); 419.309 - } 419.310 - 419.311 - 419.312 -} 419.313 - 419.314 -}
420.1 --- a/src/clojure/lang/PersistentQueue.java Sat Aug 21 06:25:44 2010 -0400 420.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 420.3 @@ -1,304 +0,0 @@ 420.4 -/** 420.5 - * Copyright (c) Rich Hickey. All rights reserved. 420.6 - * The use and distribution terms for this software are covered by the 420.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 420.8 - * which can be found in the file epl-v10.html at the root of this distribution. 420.9 - * By using this software in any fashion, you are agreeing to be bound by 420.10 - * the terms of this license. 420.11 - * You must not remove this notice, or any other, from this software. 420.12 - **/ 420.13 - 420.14 -package clojure.lang; 420.15 - 420.16 -import java.util.Collection; 420.17 -import java.util.Iterator; 420.18 -//import java.util.concurrent.ConcurrentLinkedQueue; 420.19 - 420.20 -/** 420.21 - * conses onto rear, peeks/pops from front 420.22 - * See Okasaki's Batched Queues 420.23 - * This differs in that it uses a PersistentArrayList as the rear, which is in-order, 420.24 - * so no reversing or suspensions required for persistent use 420.25 - */ 420.26 - 420.27 -public class PersistentQueue extends Obj implements IPersistentList, Collection{ 420.28 - 420.29 -final public static PersistentQueue EMPTY = new PersistentQueue(null, null, null); 420.30 - 420.31 -//* 420.32 -final ISeq f; 420.33 -final PersistentVector r; 420.34 -//static final int INITIAL_REAR_SIZE = 4; 420.35 -int _hash = -1; 420.36 - 420.37 -PersistentQueue(IPersistentMap meta, ISeq f, PersistentVector r){ 420.38 - super(meta); 420.39 - this.f = f; 420.40 - this.r = r; 420.41 -} 420.42 - 420.43 -public boolean equiv(Object obj){ 420.44 - 420.45 - if(!(obj instanceof Sequential)) 420.46 - return false; 420.47 - ISeq ms = RT.seq(obj); 420.48 - for(ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) 420.49 - { 420.50 - if(ms == null || !Util.equiv(s.first(), ms.first())) 420.51 - return false; 420.52 - } 420.53 - return ms == null; 420.54 - 420.55 -} 420.56 - 420.57 -public boolean equals(Object obj){ 420.58 - 420.59 - if(!(obj instanceof Sequential)) 420.60 - return false; 420.61 - ISeq ms = RT.seq(obj); 420.62 - for(ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) 420.63 - { 420.64 - if(ms == null || !Util.equals(s.first(), ms.first())) 420.65 - return false; 420.66 - } 420.67 - return ms == null; 420.68 - 420.69 -} 420.70 - 420.71 -public int hashCode(){ 420.72 - if(_hash == -1) 420.73 - { 420.74 - int hash = 0; 420.75 - for(ISeq s = seq(); s != null; s = s.next()) 420.76 - { 420.77 - hash = Util.hashCombine(hash, Util.hash(s.first())); 420.78 - } 420.79 - this._hash = hash; 420.80 - } 420.81 - return _hash; 420.82 -} 420.83 - 420.84 -public Object peek(){ 420.85 - return RT.first(f); 420.86 -} 420.87 - 420.88 -public PersistentQueue pop(){ 420.89 - if(f == null) //hmmm... pop of empty queue -> empty queue? 420.90 - return this; 420.91 - //throw new IllegalStateException("popping empty queue"); 420.92 - ISeq f1 = f.next(); 420.93 - PersistentVector r1 = r; 420.94 - if(f1 == null) 420.95 - { 420.96 - f1 = RT.seq(r); 420.97 - r1 = null; 420.98 - } 420.99 - return new PersistentQueue(meta(), f1, r1); 420.100 -} 420.101 - 420.102 -public int count(){ 420.103 - return RT.count(f) + RT.count(r); 420.104 -} 420.105 - 420.106 -public ISeq seq(){ 420.107 - if(f == null) 420.108 - return null; 420.109 - return new Seq(f, RT.seq(r)); 420.110 -} 420.111 - 420.112 -public PersistentQueue cons(Object o){ 420.113 - if(f == null) //empty 420.114 - return new PersistentQueue(meta(), RT.list(o), null); 420.115 - else 420.116 - return new PersistentQueue(meta(), f, (r != null ? r : PersistentVector.EMPTY).cons(o)); 420.117 -} 420.118 - 420.119 -public IPersistentCollection empty(){ 420.120 - return EMPTY.withMeta(meta()); 420.121 -} 420.122 - 420.123 -public PersistentQueue withMeta(IPersistentMap meta){ 420.124 - return new PersistentQueue(meta, f, r); 420.125 -} 420.126 - 420.127 -static class Seq extends ASeq{ 420.128 - final ISeq f; 420.129 - final ISeq rseq; 420.130 - 420.131 - Seq(ISeq f, ISeq rseq){ 420.132 - this.f = f; 420.133 - this.rseq = rseq; 420.134 - } 420.135 - 420.136 - Seq(IPersistentMap meta, ISeq f, ISeq rseq){ 420.137 - super(meta); 420.138 - this.f = f; 420.139 - this.rseq = rseq; 420.140 - } 420.141 - 420.142 - public Object first(){ 420.143 - return f.first(); 420.144 - } 420.145 - 420.146 - public ISeq next(){ 420.147 - ISeq f1 = f.next(); 420.148 - ISeq r1 = rseq; 420.149 - if(f1 == null) 420.150 - { 420.151 - if(rseq == null) 420.152 - return null; 420.153 - f1 = rseq; 420.154 - r1 = null; 420.155 - } 420.156 - return new Seq(f1, r1); 420.157 - } 420.158 - 420.159 - public int count(){ 420.160 - return RT.count(f) + RT.count(rseq); 420.161 - } 420.162 - 420.163 - public Seq withMeta(IPersistentMap meta){ 420.164 - return new Seq(meta, f, rseq); 420.165 - } 420.166 -} 420.167 - 420.168 -// java.util.Collection implementation 420.169 - 420.170 -public Object[] toArray(){ 420.171 - return RT.seqToArray(seq()); 420.172 -} 420.173 - 420.174 -public boolean add(Object o){ 420.175 - throw new UnsupportedOperationException(); 420.176 -} 420.177 - 420.178 -public boolean remove(Object o){ 420.179 - throw new UnsupportedOperationException(); 420.180 -} 420.181 - 420.182 -public boolean addAll(Collection c){ 420.183 - throw new UnsupportedOperationException(); 420.184 -} 420.185 - 420.186 -public void clear(){ 420.187 - throw new UnsupportedOperationException(); 420.188 -} 420.189 - 420.190 -public boolean retainAll(Collection c){ 420.191 - throw new UnsupportedOperationException(); 420.192 -} 420.193 - 420.194 -public boolean removeAll(Collection c){ 420.195 - throw new UnsupportedOperationException(); 420.196 -} 420.197 - 420.198 -public boolean containsAll(Collection c){ 420.199 - for(Object o : c) 420.200 - { 420.201 - if(contains(o)) 420.202 - return true; 420.203 - } 420.204 - return false; 420.205 -} 420.206 - 420.207 -public Object[] toArray(Object[] a){ 420.208 - if(a.length >= count()) 420.209 - { 420.210 - ISeq s = seq(); 420.211 - for(int i = 0; s != null; ++i, s = s.next()) 420.212 - { 420.213 - a[i] = s.first(); 420.214 - } 420.215 - if(a.length >= count()) 420.216 - a[count()] = null; 420.217 - return a; 420.218 - } 420.219 - else 420.220 - return toArray(); 420.221 -} 420.222 - 420.223 -public int size(){ 420.224 - return count(); 420.225 -} 420.226 - 420.227 -public boolean isEmpty(){ 420.228 - return count() == 0; 420.229 -} 420.230 - 420.231 -public boolean contains(Object o){ 420.232 - for(ISeq s = seq(); s != null; s = s.next()) 420.233 - { 420.234 - if(Util.equiv(s.first(), o)) 420.235 - return true; 420.236 - } 420.237 - return false; 420.238 -} 420.239 - 420.240 -public Iterator iterator(){ 420.241 - return new SeqIterator(seq()); 420.242 -} 420.243 - 420.244 -/* 420.245 -public static void main(String[] args){ 420.246 - if(args.length != 1) 420.247 - { 420.248 - System.err.println("Usage: PersistentQueue n"); 420.249 - return; 420.250 - } 420.251 - int n = Integer.parseInt(args[0]); 420.252 - 420.253 - 420.254 - long startTime, estimatedTime; 420.255 - 420.256 - Queue list = new LinkedList(); 420.257 - //Queue list = new ConcurrentLinkedQueue(); 420.258 - System.out.println("Queue"); 420.259 - startTime = System.nanoTime(); 420.260 - for(int i = 0; i < n; i++) 420.261 - { 420.262 - list.add(i); 420.263 - list.add(i); 420.264 - list.remove(); 420.265 - } 420.266 - for(int i = 0; i < n - 10; i++) 420.267 - { 420.268 - list.remove(); 420.269 - } 420.270 - estimatedTime = System.nanoTime() - startTime; 420.271 - System.out.println("time: " + estimatedTime / 1000000); 420.272 - System.out.println("peek: " + list.peek()); 420.273 - 420.274 - 420.275 - PersistentQueue q = PersistentQueue.EMPTY; 420.276 - System.out.println("PersistentQueue"); 420.277 - startTime = System.nanoTime(); 420.278 - for(int i = 0; i < n; i++) 420.279 - { 420.280 - q = q.cons(i); 420.281 - q = q.cons(i); 420.282 - q = q.pop(); 420.283 - } 420.284 -// IPersistentList lastq = null; 420.285 -// IPersistentList lastq2; 420.286 - for(int i = 0; i < n - 10; i++) 420.287 - { 420.288 - //lastq2 = lastq; 420.289 - //lastq = q; 420.290 - q = q.pop(); 420.291 - } 420.292 - estimatedTime = System.nanoTime() - startTime; 420.293 - System.out.println("time: " + estimatedTime / 1000000); 420.294 - System.out.println("peek: " + q.peek()); 420.295 - 420.296 - IPersistentList q2 = q; 420.297 - for(int i = 0; i < 10; i++) 420.298 - { 420.299 - q2 = (IPersistentList) q2.cons(i); 420.300 - } 420.301 -// for(ISeq s = q.seq();s != null;s = s.rest()) 420.302 -// System.out.println("q: " + s.first().toString()); 420.303 -// for(ISeq s = q2.seq();s != null;s = s.rest()) 420.304 -// System.out.println("q2: " + s.first().toString()); 420.305 -} 420.306 -*/ 420.307 -}
421.1 --- a/src/clojure/lang/PersistentStructMap.java Sat Aug 21 06:25:44 2010 -0400 421.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 421.3 @@ -1,233 +0,0 @@ 421.4 -/** 421.5 - * Copyright (c) Rich Hickey. All rights reserved. 421.6 - * The use and distribution terms for this software are covered by the 421.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 421.8 - * which can be found in the file epl-v10.html at the root of this distribution. 421.9 - * By using this software in any fashion, you are agreeing to be bound by 421.10 - * the terms of this license. 421.11 - * You must not remove this notice, or any other, from this software. 421.12 - **/ 421.13 - 421.14 -/* rich Dec 16, 2007 */ 421.15 - 421.16 -package clojure.lang; 421.17 - 421.18 -import java.util.Iterator; 421.19 -import java.util.Map; 421.20 -import java.io.Serializable; 421.21 - 421.22 -public class PersistentStructMap extends APersistentMap implements IObj{ 421.23 - 421.24 -public static class Def implements Serializable{ 421.25 - final ISeq keys; 421.26 - final IPersistentMap keyslots; 421.27 - 421.28 - Def(ISeq keys, IPersistentMap keyslots){ 421.29 - this.keys = keys; 421.30 - this.keyslots = keyslots; 421.31 - } 421.32 -} 421.33 - 421.34 -final Def def; 421.35 -final Object[] vals; 421.36 -final IPersistentMap ext; 421.37 -final IPersistentMap _meta; 421.38 - 421.39 - 421.40 -static public Def createSlotMap(ISeq keys){ 421.41 - if(keys == null) 421.42 - throw new IllegalArgumentException("Must supply keys"); 421.43 - int c = RT.count(keys); 421.44 - Object[] v = new Object[2*c]; 421.45 - int i = 0; 421.46 - for(ISeq s = keys; s != null; s = s.next(), i++) 421.47 - { 421.48 - v[2*i] = s.first(); 421.49 - v[2*i+1] = i; 421.50 - } 421.51 - return new Def(keys, RT.map(v)); 421.52 -} 421.53 - 421.54 -static public PersistentStructMap create(Def def, ISeq keyvals){ 421.55 - Object[] vals = new Object[def.keyslots.count()]; 421.56 - IPersistentMap ext = PersistentHashMap.EMPTY; 421.57 - for(; keyvals != null; keyvals = keyvals.next().next()) 421.58 - { 421.59 - if(keyvals.next() == null) 421.60 - throw new IllegalArgumentException(String.format("No value supplied for key: %s", keyvals.first())); 421.61 - Object k = keyvals.first(); 421.62 - Object v = RT.second(keyvals); 421.63 - Map.Entry e = def.keyslots.entryAt(k); 421.64 - if(e != null) 421.65 - vals[(Integer) e.getValue()] = v; 421.66 - else 421.67 - ext = ext.assoc(k, v); 421.68 - } 421.69 - return new PersistentStructMap(null, def, vals, ext); 421.70 -} 421.71 - 421.72 -static public PersistentStructMap construct(Def def, ISeq valseq){ 421.73 - Object[] vals = new Object[def.keyslots.count()]; 421.74 - IPersistentMap ext = PersistentHashMap.EMPTY; 421.75 - for(int i = 0; i < vals.length && valseq != null; valseq = valseq.next(), i++) 421.76 - { 421.77 - vals[i] = valseq.first(); 421.78 - } 421.79 - if(valseq != null) 421.80 - throw new IllegalArgumentException("Too many arguments to struct constructor"); 421.81 - return new PersistentStructMap(null, def, vals, ext); 421.82 -} 421.83 - 421.84 -static public IFn getAccessor(final Def def, Object key){ 421.85 - Map.Entry e = def.keyslots.entryAt(key); 421.86 - if(e != null) 421.87 - { 421.88 - final int i = (Integer) e.getValue(); 421.89 - return new AFn(){ 421.90 - public Object invoke(Object arg1) throws Exception{ 421.91 - PersistentStructMap m = (PersistentStructMap) arg1; 421.92 - if(m.def != def) 421.93 - throw new Exception("Accessor/struct mismatch"); 421.94 - return m.vals[i]; 421.95 - } 421.96 - }; 421.97 - } 421.98 - throw new IllegalArgumentException("Not a key of struct"); 421.99 -} 421.100 - 421.101 -protected PersistentStructMap(IPersistentMap meta, Def def, Object[] vals, IPersistentMap ext){ 421.102 - this._meta = meta; 421.103 - this.ext = ext; 421.104 - this.def = def; 421.105 - this.vals = vals; 421.106 -} 421.107 - 421.108 -/** 421.109 - * Returns a new instance of PersistentStructMap using the given parameters. 421.110 - * This function is used instead of the PersistentStructMap constructor by 421.111 - * all methods that return a new PersistentStructMap. This is done so as to 421.112 - * allow subclasses to return instances of their class from all 421.113 - * PersistentStructMap methods. 421.114 - */ 421.115 -protected PersistentStructMap makeNew(IPersistentMap meta, Def def, Object[] vals, IPersistentMap ext){ 421.116 - return new PersistentStructMap(meta, def, vals, ext); 421.117 -} 421.118 - 421.119 -public IObj withMeta(IPersistentMap meta){ 421.120 - if(meta == _meta) 421.121 - return this; 421.122 - return makeNew(meta, def, vals, ext); 421.123 -} 421.124 - 421.125 -public IPersistentMap meta(){ 421.126 - return _meta; 421.127 -} 421.128 - 421.129 -public boolean containsKey(Object key){ 421.130 - return def.keyslots.containsKey(key) || ext.containsKey(key); 421.131 -} 421.132 - 421.133 -public IMapEntry entryAt(Object key){ 421.134 - Map.Entry e = def.keyslots.entryAt(key); 421.135 - if(e != null) 421.136 - { 421.137 - return new MapEntry(e.getKey(), vals[(Integer) e.getValue()]); 421.138 - } 421.139 - return ext.entryAt(key); 421.140 -} 421.141 - 421.142 -public IPersistentMap assoc(Object key, Object val){ 421.143 - Map.Entry e = def.keyslots.entryAt(key); 421.144 - if(e != null) 421.145 - { 421.146 - int i = (Integer) e.getValue(); 421.147 - Object[] newVals = vals.clone(); 421.148 - newVals[i] = val; 421.149 - return makeNew(_meta, def, newVals, ext); 421.150 - } 421.151 - return makeNew(_meta, def, vals, ext.assoc(key, val)); 421.152 -} 421.153 - 421.154 -public Object valAt(Object key){ 421.155 - Integer i = (Integer) def.keyslots.valAt(key); 421.156 - if(i != null) 421.157 - { 421.158 - return vals[i]; 421.159 - } 421.160 - return ext.valAt(key); 421.161 -} 421.162 - 421.163 -public Object valAt(Object key, Object notFound){ 421.164 - Integer i = (Integer) def.keyslots.valAt(key); 421.165 - if(i != null) 421.166 - { 421.167 - return vals[i]; 421.168 - } 421.169 - return ext.valAt(key, notFound); 421.170 -} 421.171 - 421.172 -public IPersistentMap assocEx(Object key, Object val) throws Exception{ 421.173 - if(containsKey(key)) 421.174 - throw new Exception("Key already present"); 421.175 - return assoc(key, val); 421.176 -} 421.177 - 421.178 -public IPersistentMap without(Object key) throws Exception{ 421.179 - Map.Entry e = def.keyslots.entryAt(key); 421.180 - if(e != null) 421.181 - throw new Exception("Can't remove struct key"); 421.182 - IPersistentMap newExt = ext.without(key); 421.183 - if(newExt == ext) 421.184 - return this; 421.185 - return makeNew(_meta, def, vals, newExt); 421.186 -} 421.187 - 421.188 -public Iterator iterator(){ 421.189 - return new SeqIterator(seq()); 421.190 -} 421.191 - 421.192 - 421.193 -public int count(){ 421.194 - return vals.length + RT.count(ext); 421.195 -} 421.196 - 421.197 -public ISeq seq(){ 421.198 - return new Seq(null, def.keys, vals, 0, ext); 421.199 -} 421.200 - 421.201 -public IPersistentCollection empty(){ 421.202 - return construct(def, null); 421.203 -} 421.204 - 421.205 -static class Seq extends ASeq{ 421.206 - final int i; 421.207 - final ISeq keys; 421.208 - final Object[] vals; 421.209 - final IPersistentMap ext; 421.210 - 421.211 - 421.212 - public Seq(IPersistentMap meta, ISeq keys, Object[] vals, int i, IPersistentMap ext){ 421.213 - super(meta); 421.214 - this.i = i; 421.215 - this.keys = keys; 421.216 - this.vals = vals; 421.217 - this.ext = ext; 421.218 - } 421.219 - 421.220 - public Obj withMeta(IPersistentMap meta){ 421.221 - if(meta != _meta) 421.222 - return new Seq(meta, keys, vals, i, ext); 421.223 - return this; 421.224 - } 421.225 - 421.226 - public Object first(){ 421.227 - return new MapEntry(keys.first(), vals[i]); 421.228 - } 421.229 - 421.230 - public ISeq next(){ 421.231 - if(i + 1 < vals.length) 421.232 - return new Seq(_meta, keys.next(), vals, i + 1, ext); 421.233 - return ext.seq(); 421.234 - } 421.235 -} 421.236 -}
422.1 --- a/src/clojure/lang/PersistentTreeMap.java Sat Aug 21 06:25:44 2010 -0400 422.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 422.3 @@ -1,1003 +0,0 @@ 422.4 -/** 422.5 - * Copyright (c) Rich Hickey. All rights reserved. 422.6 - * The use and distribution terms for this software are covered by the 422.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 422.8 - * which can be found in the file epl-v10.html at the root of this distribution. 422.9 - * By using this software in any fashion, you are agreeing to be bound by 422.10 - * the terms of this license. 422.11 - * You must not remove this notice, or any other, from this software. 422.12 - **/ 422.13 - 422.14 -/* rich May 20, 2006 */ 422.15 - 422.16 -package clojure.lang; 422.17 - 422.18 -import java.util.*; 422.19 - 422.20 -/** 422.21 - * Persistent Red Black Tree 422.22 - * Note that instances of this class are constant values 422.23 - * i.e. add/remove etc return new values 422.24 - * <p/> 422.25 - * See Okasaki, Kahrs, Larsen et al 422.26 - */ 422.27 - 422.28 -public class PersistentTreeMap extends APersistentMap implements IObj, Reversible, Sorted{ 422.29 - 422.30 -public final Comparator comp; 422.31 -public final Node tree; 422.32 -public final int _count; 422.33 -final IPersistentMap _meta; 422.34 - 422.35 -final static public PersistentTreeMap EMPTY = new PersistentTreeMap(); 422.36 - 422.37 -static public IPersistentMap create(Map other){ 422.38 - IPersistentMap ret = EMPTY; 422.39 - for(Object o : other.entrySet()) 422.40 - { 422.41 - Map.Entry e = (Entry) o; 422.42 - ret = ret.assoc(e.getKey(), e.getValue()); 422.43 - } 422.44 - return ret; 422.45 -} 422.46 - 422.47 -public PersistentTreeMap(){ 422.48 - this(RT.DEFAULT_COMPARATOR); 422.49 -} 422.50 - 422.51 -public PersistentTreeMap withMeta(IPersistentMap meta){ 422.52 - return new PersistentTreeMap(meta, comp, tree, _count); 422.53 -} 422.54 - 422.55 -private PersistentTreeMap(Comparator comp){ 422.56 - this(null, comp); 422.57 -} 422.58 - 422.59 - 422.60 -public PersistentTreeMap(IPersistentMap meta, Comparator comp){ 422.61 - this.comp = comp; 422.62 - this._meta = meta; 422.63 - tree = null; 422.64 - _count = 0; 422.65 -} 422.66 - 422.67 -PersistentTreeMap(IPersistentMap meta, Comparator comp, Node tree, int _count){ 422.68 - this._meta = meta; 422.69 - this.comp = comp; 422.70 - this.tree = tree; 422.71 - this._count = _count; 422.72 -} 422.73 - 422.74 -static public PersistentTreeMap create(ISeq items){ 422.75 - IPersistentMap ret = EMPTY; 422.76 - for(; items != null; items = items.next().next()) 422.77 - { 422.78 - if(items.next() == null) 422.79 - throw new IllegalArgumentException(String.format("No value supplied for key: %s", items.first())); 422.80 - ret = ret.assoc(items.first(), RT.second(items)); 422.81 - } 422.82 - return (PersistentTreeMap) ret; 422.83 -} 422.84 - 422.85 -static public PersistentTreeMap create(Comparator comp, ISeq items){ 422.86 - IPersistentMap ret = new PersistentTreeMap(comp); 422.87 - for(; items != null; items = items.next().next()) 422.88 - { 422.89 - if(items.next() == null) 422.90 - throw new IllegalArgumentException(String.format("No value supplied for key: %s", items.first())); 422.91 - ret = ret.assoc(items.first(), RT.second(items)); 422.92 - } 422.93 - return (PersistentTreeMap) ret; 422.94 -} 422.95 - 422.96 -public boolean containsKey(Object key){ 422.97 - return entryAt(key) != null; 422.98 -} 422.99 - 422.100 -public PersistentTreeMap assocEx(Object key, Object val) throws Exception{ 422.101 - Box found = new Box(null); 422.102 - Node t = add(tree, key, val, found); 422.103 - if(t == null) //null == already contains key 422.104 - { 422.105 - throw new Exception("Key already present"); 422.106 - } 422.107 - return new PersistentTreeMap(comp, t.blacken(), _count + 1, meta()); 422.108 -} 422.109 - 422.110 -public PersistentTreeMap assoc(Object key, Object val){ 422.111 - Box found = new Box(null); 422.112 - Node t = add(tree, key, val, found); 422.113 - if(t == null) //null == already contains key 422.114 - { 422.115 - Node foundNode = (Node) found.val; 422.116 - if(foundNode.val() == val) //note only get same collection on identity of val, not equals() 422.117 - return this; 422.118 - return new PersistentTreeMap(comp, replace(tree, key, val), _count, meta()); 422.119 - } 422.120 - return new PersistentTreeMap(comp, t.blacken(), _count + 1, meta()); 422.121 -} 422.122 - 422.123 - 422.124 -public PersistentTreeMap without(Object key){ 422.125 - Box found = new Box(null); 422.126 - Node t = remove(tree, key, found); 422.127 - if(t == null) 422.128 - { 422.129 - if(found.val == null)//null == doesn't contain key 422.130 - return this; 422.131 - //empty 422.132 - return new PersistentTreeMap(meta(), comp); 422.133 - } 422.134 - return new PersistentTreeMap(comp, t.blacken(), _count - 1, meta()); 422.135 -} 422.136 - 422.137 -public ISeq seq(){ 422.138 - if(_count > 0) 422.139 - return Seq.create(tree, true, _count); 422.140 - return null; 422.141 -} 422.142 - 422.143 -public IPersistentCollection empty(){ 422.144 - return new PersistentTreeMap(meta(), comp); 422.145 -} 422.146 - 422.147 -public ISeq rseq() throws Exception{ 422.148 - if(_count > 0) 422.149 - return Seq.create(tree, false, _count); 422.150 - return null; 422.151 -} 422.152 - 422.153 -public Comparator comparator(){ 422.154 - return comp; 422.155 -} 422.156 - 422.157 -public Object entryKey(Object entry){ 422.158 - return ((IMapEntry) entry).key(); 422.159 -} 422.160 - 422.161 -public ISeq seq(boolean ascending){ 422.162 - if(_count > 0) 422.163 - return Seq.create(tree, ascending, _count); 422.164 - return null; 422.165 -} 422.166 - 422.167 -public ISeq seqFrom(Object key, boolean ascending){ 422.168 - if(_count > 0) 422.169 - { 422.170 - ISeq stack = null; 422.171 - Node t = tree; 422.172 - while(t != null) 422.173 - { 422.174 - int c = doCompare(key, t.key); 422.175 - if(c == 0) 422.176 - { 422.177 - stack = RT.cons(t, stack); 422.178 - return new Seq(stack, ascending); 422.179 - } 422.180 - else if(ascending) 422.181 - { 422.182 - if(c < 0) 422.183 - { 422.184 - stack = RT.cons(t, stack); 422.185 - t = t.left(); 422.186 - } 422.187 - else 422.188 - t = t.right(); 422.189 - } 422.190 - else 422.191 - { 422.192 - if(c > 0) 422.193 - { 422.194 - stack = RT.cons(t, stack); 422.195 - t = t.right(); 422.196 - } 422.197 - else 422.198 - t = t.left(); 422.199 - } 422.200 - } 422.201 - if(stack != null) 422.202 - return new Seq(stack, ascending); 422.203 - } 422.204 - return null; 422.205 -} 422.206 - 422.207 -public NodeIterator iterator(){ 422.208 - return new NodeIterator(tree, true); 422.209 -} 422.210 - 422.211 -public NodeIterator reverseIterator(){ 422.212 - return new NodeIterator(tree, false); 422.213 -} 422.214 - 422.215 -public Iterator keys(){ 422.216 - return keys(iterator()); 422.217 -} 422.218 - 422.219 -public Iterator vals(){ 422.220 - return vals(iterator()); 422.221 -} 422.222 - 422.223 -public Iterator keys(NodeIterator it){ 422.224 - return new KeyIterator(it); 422.225 -} 422.226 - 422.227 -public Iterator vals(NodeIterator it){ 422.228 - return new ValIterator(it); 422.229 -} 422.230 - 422.231 -public Object minKey(){ 422.232 - Node t = min(); 422.233 - return t != null ? t.key : null; 422.234 -} 422.235 - 422.236 -public Node min(){ 422.237 - Node t = tree; 422.238 - if(t != null) 422.239 - { 422.240 - while(t.left() != null) 422.241 - t = t.left(); 422.242 - } 422.243 - return t; 422.244 -} 422.245 - 422.246 -public Object maxKey(){ 422.247 - Node t = max(); 422.248 - return t != null ? t.key : null; 422.249 -} 422.250 - 422.251 -public Node max(){ 422.252 - Node t = tree; 422.253 - if(t != null) 422.254 - { 422.255 - while(t.right() != null) 422.256 - t = t.right(); 422.257 - } 422.258 - return t; 422.259 -} 422.260 - 422.261 -public int depth(){ 422.262 - return depth(tree); 422.263 -} 422.264 - 422.265 -int depth(Node t){ 422.266 - if(t == null) 422.267 - return 0; 422.268 - return 1 + Math.max(depth(t.left()), depth(t.right())); 422.269 -} 422.270 - 422.271 -public Object valAt(Object key, Object notFound){ 422.272 - Node n = entryAt(key); 422.273 - return (n != null) ? n.val() : notFound; 422.274 -} 422.275 - 422.276 -public Object valAt(Object key){ 422.277 - return valAt(key, null); 422.278 -} 422.279 - 422.280 -public int capacity(){ 422.281 - return _count; 422.282 -} 422.283 - 422.284 -public int count(){ 422.285 - return _count; 422.286 -} 422.287 - 422.288 -public Node entryAt(Object key){ 422.289 - Node t = tree; 422.290 - while(t != null) 422.291 - { 422.292 - int c = doCompare(key, t.key); 422.293 - if(c == 0) 422.294 - return t; 422.295 - else if(c < 0) 422.296 - t = t.left(); 422.297 - else 422.298 - t = t.right(); 422.299 - } 422.300 - return t; 422.301 -} 422.302 - 422.303 -public int doCompare(Object k1, Object k2){ 422.304 -// if(comp != null) 422.305 - return comp.compare(k1, k2); 422.306 -// return ((Comparable) k1).compareTo(k2); 422.307 -} 422.308 - 422.309 -Node add(Node t, Object key, Object val, Box found){ 422.310 - if(t == null) 422.311 - { 422.312 - if(val == null) 422.313 - return new Red(key); 422.314 - return new RedVal(key, val); 422.315 - } 422.316 - int c = doCompare(key, t.key); 422.317 - if(c == 0) 422.318 - { 422.319 - found.val = t; 422.320 - return null; 422.321 - } 422.322 - Node ins = c < 0 ? add(t.left(), key, val, found) : add(t.right(), key, val, found); 422.323 - if(ins == null) //found below 422.324 - return null; 422.325 - if(c < 0) 422.326 - return t.addLeft(ins); 422.327 - return t.addRight(ins); 422.328 -} 422.329 - 422.330 -Node remove(Node t, Object key, Box found){ 422.331 - if(t == null) 422.332 - return null; //not found indicator 422.333 - int c = doCompare(key, t.key); 422.334 - if(c == 0) 422.335 - { 422.336 - found.val = t; 422.337 - return append(t.left(), t.right()); 422.338 - } 422.339 - Node del = c < 0 ? remove(t.left(), key, found) : remove(t.right(), key, found); 422.340 - if(del == null && found.val == null) //not found below 422.341 - return null; 422.342 - if(c < 0) 422.343 - { 422.344 - if(t.left() instanceof Black) 422.345 - return balanceLeftDel(t.key, t.val(), del, t.right()); 422.346 - else 422.347 - return red(t.key, t.val(), del, t.right()); 422.348 - } 422.349 - if(t.right() instanceof Black) 422.350 - return balanceRightDel(t.key, t.val(), t.left(), del); 422.351 - return red(t.key, t.val(), t.left(), del); 422.352 -// return t.removeLeft(del); 422.353 -// return t.removeRight(del); 422.354 -} 422.355 - 422.356 -static Node append(Node left, Node right){ 422.357 - if(left == null) 422.358 - return right; 422.359 - else if(right == null) 422.360 - return left; 422.361 - else if(left instanceof Red) 422.362 - { 422.363 - if(right instanceof Red) 422.364 - { 422.365 - Node app = append(left.right(), right.left()); 422.366 - if(app instanceof Red) 422.367 - return red(app.key, app.val(), 422.368 - red(left.key, left.val(), left.left(), app.left()), 422.369 - red(right.key, right.val(), app.right(), right.right())); 422.370 - else 422.371 - return red(left.key, left.val(), left.left(), red(right.key, right.val(), app, right.right())); 422.372 - } 422.373 - else 422.374 - return red(left.key, left.val(), left.left(), append(left.right(), right)); 422.375 - } 422.376 - else if(right instanceof Red) 422.377 - return red(right.key, right.val(), append(left, right.left()), right.right()); 422.378 - else //black/black 422.379 - { 422.380 - Node app = append(left.right(), right.left()); 422.381 - if(app instanceof Red) 422.382 - return red(app.key, app.val(), 422.383 - black(left.key, left.val(), left.left(), app.left()), 422.384 - black(right.key, right.val(), app.right(), right.right())); 422.385 - else 422.386 - return balanceLeftDel(left.key, left.val(), left.left(), black(right.key, right.val(), app, right.right())); 422.387 - } 422.388 -} 422.389 - 422.390 -static Node balanceLeftDel(Object key, Object val, Node del, Node right){ 422.391 - if(del instanceof Red) 422.392 - return red(key, val, del.blacken(), right); 422.393 - else if(right instanceof Black) 422.394 - return rightBalance(key, val, del, right.redden()); 422.395 - else if(right instanceof Red && right.left() instanceof Black) 422.396 - return red(right.left().key, right.left().val(), 422.397 - black(key, val, del, right.left().left()), 422.398 - rightBalance(right.key, right.val(), right.left().right(), right.right().redden())); 422.399 - else 422.400 - throw new UnsupportedOperationException("Invariant violation"); 422.401 -} 422.402 - 422.403 -static Node balanceRightDel(Object key, Object val, Node left, Node del){ 422.404 - if(del instanceof Red) 422.405 - return red(key, val, left, del.blacken()); 422.406 - else if(left instanceof Black) 422.407 - return leftBalance(key, val, left.redden(), del); 422.408 - else if(left instanceof Red && left.right() instanceof Black) 422.409 - return red(left.right().key, left.right().val(), 422.410 - leftBalance(left.key, left.val(), left.left().redden(), left.right().left()), 422.411 - black(key, val, left.right().right(), del)); 422.412 - else 422.413 - throw new UnsupportedOperationException("Invariant violation"); 422.414 -} 422.415 - 422.416 -static Node leftBalance(Object key, Object val, Node ins, Node right){ 422.417 - if(ins instanceof Red && ins.left() instanceof Red) 422.418 - return red(ins.key, ins.val(), ins.left().blacken(), black(key, val, ins.right(), right)); 422.419 - else if(ins instanceof Red && ins.right() instanceof Red) 422.420 - return red(ins.right().key, ins.right().val(), 422.421 - black(ins.key, ins.val(), ins.left(), ins.right().left()), 422.422 - black(key, val, ins.right().right(), right)); 422.423 - else 422.424 - return black(key, val, ins, right); 422.425 -} 422.426 - 422.427 - 422.428 -static Node rightBalance(Object key, Object val, Node left, Node ins){ 422.429 - if(ins instanceof Red && ins.right() instanceof Red) 422.430 - return red(ins.key, ins.val(), black(key, val, left, ins.left()), ins.right().blacken()); 422.431 - else if(ins instanceof Red && ins.left() instanceof Red) 422.432 - return red(ins.left().key, ins.left().val(), 422.433 - black(key, val, left, ins.left().left()), 422.434 - black(ins.key, ins.val(), ins.left().right(), ins.right())); 422.435 - else 422.436 - return black(key, val, left, ins); 422.437 -} 422.438 - 422.439 -Node replace(Node t, Object key, Object val){ 422.440 - int c = doCompare(key, t.key); 422.441 - return t.replace(t.key, 422.442 - c == 0 ? val : t.val(), 422.443 - c < 0 ? replace(t.left(), key, val) : t.left(), 422.444 - c > 0 ? replace(t.right(), key, val) : t.right()); 422.445 -} 422.446 - 422.447 -PersistentTreeMap(Comparator comp, Node tree, int count, IPersistentMap meta){ 422.448 - this._meta = meta; 422.449 - this.comp = comp; 422.450 - this.tree = tree; 422.451 - this._count = count; 422.452 -} 422.453 - 422.454 -static Red red(Object key, Object val, Node left, Node right){ 422.455 - if(left == null && right == null) 422.456 - { 422.457 - if(val == null) 422.458 - return new Red(key); 422.459 - return new RedVal(key, val); 422.460 - } 422.461 - if(val == null) 422.462 - return new RedBranch(key, left, right); 422.463 - return new RedBranchVal(key, val, left, right); 422.464 -} 422.465 - 422.466 -static Black black(Object key, Object val, Node left, Node right){ 422.467 - if(left == null && right == null) 422.468 - { 422.469 - if(val == null) 422.470 - return new Black(key); 422.471 - return new BlackVal(key, val); 422.472 - } 422.473 - if(val == null) 422.474 - return new BlackBranch(key, left, right); 422.475 - return new BlackBranchVal(key, val, left, right); 422.476 -} 422.477 - 422.478 -public IPersistentMap meta(){ 422.479 - return _meta; 422.480 -} 422.481 - 422.482 -static abstract class Node extends AMapEntry{ 422.483 - final Object key; 422.484 - 422.485 - Node(Object key){ 422.486 - this.key = key; 422.487 - } 422.488 - 422.489 - public Object key(){ 422.490 - return key; 422.491 - } 422.492 - 422.493 - public Object val(){ 422.494 - return null; 422.495 - } 422.496 - 422.497 - public Object getKey(){ 422.498 - return key(); 422.499 - } 422.500 - 422.501 - public Object getValue(){ 422.502 - return val(); 422.503 - } 422.504 - 422.505 - Node left(){ 422.506 - return null; 422.507 - } 422.508 - 422.509 - Node right(){ 422.510 - return null; 422.511 - } 422.512 - 422.513 - abstract Node addLeft(Node ins); 422.514 - 422.515 - abstract Node addRight(Node ins); 422.516 - 422.517 - abstract Node removeLeft(Node del); 422.518 - 422.519 - abstract Node removeRight(Node del); 422.520 - 422.521 - abstract Node blacken(); 422.522 - 422.523 - abstract Node redden(); 422.524 - 422.525 - Node balanceLeft(Node parent){ 422.526 - return black(parent.key, parent.val(), this, parent.right()); 422.527 - } 422.528 - 422.529 - Node balanceRight(Node parent){ 422.530 - return black(parent.key, parent.val(), parent.left(), this); 422.531 - } 422.532 - 422.533 - abstract Node replace(Object key, Object val, Node left, Node right); 422.534 - 422.535 -} 422.536 - 422.537 -static class Black extends Node{ 422.538 - public Black(Object key){ 422.539 - super(key); 422.540 - } 422.541 - 422.542 - Node addLeft(Node ins){ 422.543 - return ins.balanceLeft(this); 422.544 - } 422.545 - 422.546 - Node addRight(Node ins){ 422.547 - return ins.balanceRight(this); 422.548 - } 422.549 - 422.550 - Node removeLeft(Node del){ 422.551 - return balanceLeftDel(key, val(), del, right()); 422.552 - } 422.553 - 422.554 - Node removeRight(Node del){ 422.555 - return balanceRightDel(key, val(), left(), del); 422.556 - } 422.557 - 422.558 - Node blacken(){ 422.559 - return this; 422.560 - } 422.561 - 422.562 - Node redden(){ 422.563 - return new Red(key); 422.564 - } 422.565 - 422.566 - Node replace(Object key, Object val, Node left, Node right){ 422.567 - return black(key, val, left, right); 422.568 - } 422.569 - 422.570 -} 422.571 - 422.572 -static class BlackVal extends Black{ 422.573 - final Object val; 422.574 - 422.575 - public BlackVal(Object key, Object val){ 422.576 - super(key); 422.577 - this.val = val; 422.578 - } 422.579 - 422.580 - public Object val(){ 422.581 - return val; 422.582 - } 422.583 - 422.584 - Node redden(){ 422.585 - return new RedVal(key, val); 422.586 - } 422.587 - 422.588 -} 422.589 - 422.590 -static class BlackBranch extends Black{ 422.591 - final Node left; 422.592 - 422.593 - final Node right; 422.594 - 422.595 - public BlackBranch(Object key, Node left, Node right){ 422.596 - super(key); 422.597 - this.left = left; 422.598 - this.right = right; 422.599 - } 422.600 - 422.601 - public Node left(){ 422.602 - return left; 422.603 - } 422.604 - 422.605 - public Node right(){ 422.606 - return right; 422.607 - } 422.608 - 422.609 - Node redden(){ 422.610 - return new RedBranch(key, left, right); 422.611 - } 422.612 - 422.613 -} 422.614 - 422.615 -static class BlackBranchVal extends BlackBranch{ 422.616 - final Object val; 422.617 - 422.618 - public BlackBranchVal(Object key, Object val, Node left, Node right){ 422.619 - super(key, left, right); 422.620 - this.val = val; 422.621 - } 422.622 - 422.623 - public Object val(){ 422.624 - return val; 422.625 - } 422.626 - 422.627 - Node redden(){ 422.628 - return new RedBranchVal(key, val, left, right); 422.629 - } 422.630 - 422.631 -} 422.632 - 422.633 -static class Red extends Node{ 422.634 - public Red(Object key){ 422.635 - super(key); 422.636 - } 422.637 - 422.638 - Node addLeft(Node ins){ 422.639 - return red(key, val(), ins, right()); 422.640 - } 422.641 - 422.642 - Node addRight(Node ins){ 422.643 - return red(key, val(), left(), ins); 422.644 - } 422.645 - 422.646 - Node removeLeft(Node del){ 422.647 - return red(key, val(), del, right()); 422.648 - } 422.649 - 422.650 - Node removeRight(Node del){ 422.651 - return red(key, val(), left(), del); 422.652 - } 422.653 - 422.654 - Node blacken(){ 422.655 - return new Black(key); 422.656 - } 422.657 - 422.658 - Node redden(){ 422.659 - throw new UnsupportedOperationException("Invariant violation"); 422.660 - } 422.661 - 422.662 - Node replace(Object key, Object val, Node left, Node right){ 422.663 - return red(key, val, left, right); 422.664 - } 422.665 - 422.666 -} 422.667 - 422.668 -static class RedVal extends Red{ 422.669 - final Object val; 422.670 - 422.671 - public RedVal(Object key, Object val){ 422.672 - super(key); 422.673 - this.val = val; 422.674 - } 422.675 - 422.676 - public Object val(){ 422.677 - return val; 422.678 - } 422.679 - 422.680 - Node blacken(){ 422.681 - return new BlackVal(key, val); 422.682 - } 422.683 - 422.684 -} 422.685 - 422.686 -static class RedBranch extends Red{ 422.687 - final Node left; 422.688 - 422.689 - final Node right; 422.690 - 422.691 - public RedBranch(Object key, Node left, Node right){ 422.692 - super(key); 422.693 - this.left = left; 422.694 - this.right = right; 422.695 - } 422.696 - 422.697 - public Node left(){ 422.698 - return left; 422.699 - } 422.700 - 422.701 - public Node right(){ 422.702 - return right; 422.703 - } 422.704 - 422.705 - Node balanceLeft(Node parent){ 422.706 - if(left instanceof Red) 422.707 - return red(key, val(), left.blacken(), black(parent.key, parent.val(), right, parent.right())); 422.708 - else if(right instanceof Red) 422.709 - return red(right.key, right.val(), black(key, val(), left, right.left()), 422.710 - black(parent.key, parent.val(), right.right(), parent.right())); 422.711 - else 422.712 - return super.balanceLeft(parent); 422.713 - 422.714 - } 422.715 - 422.716 - Node balanceRight(Node parent){ 422.717 - if(right instanceof Red) 422.718 - return red(key, val(), black(parent.key, parent.val(), parent.left(), left), right.blacken()); 422.719 - else if(left instanceof Red) 422.720 - return red(left.key, left.val(), black(parent.key, parent.val(), parent.left(), left.left()), 422.721 - black(key, val(), left.right(), right)); 422.722 - else 422.723 - return super.balanceRight(parent); 422.724 - } 422.725 - 422.726 - Node blacken(){ 422.727 - return new BlackBranch(key, left, right); 422.728 - } 422.729 - 422.730 -} 422.731 - 422.732 - 422.733 -static class RedBranchVal extends RedBranch{ 422.734 - final Object val; 422.735 - 422.736 - public RedBranchVal(Object key, Object val, Node left, Node right){ 422.737 - super(key, left, right); 422.738 - this.val = val; 422.739 - } 422.740 - 422.741 - public Object val(){ 422.742 - return val; 422.743 - } 422.744 - 422.745 - Node blacken(){ 422.746 - return new BlackBranchVal(key, val, left, right); 422.747 - } 422.748 -} 422.749 - 422.750 - 422.751 -static public class Seq extends ASeq{ 422.752 - final ISeq stack; 422.753 - final boolean asc; 422.754 - final int cnt; 422.755 - 422.756 - public Seq(ISeq stack, boolean asc){ 422.757 - this.stack = stack; 422.758 - this.asc = asc; 422.759 - this.cnt = -1; 422.760 - } 422.761 - 422.762 - public Seq(ISeq stack, boolean asc, int cnt){ 422.763 - this.stack = stack; 422.764 - this.asc = asc; 422.765 - this.cnt = cnt; 422.766 - } 422.767 - 422.768 - Seq(IPersistentMap meta, ISeq stack, boolean asc, int cnt){ 422.769 - super(meta); 422.770 - this.stack = stack; 422.771 - this.asc = asc; 422.772 - this.cnt = cnt; 422.773 - } 422.774 - 422.775 - static Seq create(Node t, boolean asc, int cnt){ 422.776 - return new Seq(push(t, null, asc), asc, cnt); 422.777 - } 422.778 - 422.779 - static ISeq push(Node t, ISeq stack, boolean asc){ 422.780 - while(t != null) 422.781 - { 422.782 - stack = RT.cons(t, stack); 422.783 - t = asc ? t.left() : t.right(); 422.784 - } 422.785 - return stack; 422.786 - } 422.787 - 422.788 - public Object first(){ 422.789 - return stack.first(); 422.790 - } 422.791 - 422.792 - public ISeq next(){ 422.793 - Node t = (Node) stack.first(); 422.794 - ISeq nextstack = push(asc ? t.right() : t.left(), stack.next(), asc); 422.795 - if(nextstack != null) 422.796 - { 422.797 - return new Seq(nextstack, asc, cnt - 1); 422.798 - } 422.799 - return null; 422.800 - } 422.801 - 422.802 - public int count(){ 422.803 - if(cnt < 0) 422.804 - return super.count(); 422.805 - return cnt; 422.806 - } 422.807 - 422.808 - public Obj withMeta(IPersistentMap meta){ 422.809 - return new Seq(meta, stack, asc, cnt); 422.810 - } 422.811 -} 422.812 - 422.813 -static public class NodeIterator implements Iterator{ 422.814 - Stack stack = new Stack(); 422.815 - boolean asc; 422.816 - 422.817 - NodeIterator(Node t, boolean asc){ 422.818 - this.asc = asc; 422.819 - push(t); 422.820 - } 422.821 - 422.822 - void push(Node t){ 422.823 - while(t != null) 422.824 - { 422.825 - stack.push(t); 422.826 - t = asc ? t.left() : t.right(); 422.827 - } 422.828 - } 422.829 - 422.830 - public boolean hasNext(){ 422.831 - return !stack.isEmpty(); 422.832 - } 422.833 - 422.834 - public Object next(){ 422.835 - Node t = (Node) stack.pop(); 422.836 - push(asc ? t.right() : t.left()); 422.837 - return t; 422.838 - } 422.839 - 422.840 - public void remove(){ 422.841 - throw new UnsupportedOperationException(); 422.842 - } 422.843 -} 422.844 - 422.845 -static class KeyIterator implements Iterator{ 422.846 - NodeIterator it; 422.847 - 422.848 - KeyIterator(NodeIterator it){ 422.849 - this.it = it; 422.850 - } 422.851 - 422.852 - public boolean hasNext(){ 422.853 - return it.hasNext(); 422.854 - } 422.855 - 422.856 - public Object next(){ 422.857 - return ((Node) it.next()).key; 422.858 - } 422.859 - 422.860 - public void remove(){ 422.861 - throw new UnsupportedOperationException(); 422.862 - } 422.863 -} 422.864 - 422.865 -static class ValIterator implements Iterator{ 422.866 - NodeIterator it; 422.867 - 422.868 - ValIterator(NodeIterator it){ 422.869 - this.it = it; 422.870 - } 422.871 - 422.872 - public boolean hasNext(){ 422.873 - return it.hasNext(); 422.874 - } 422.875 - 422.876 - public Object next(){ 422.877 - return ((Node) it.next()).val(); 422.878 - } 422.879 - 422.880 - public void remove(){ 422.881 - throw new UnsupportedOperationException(); 422.882 - } 422.883 -} 422.884 -/* 422.885 -static public void main(String args[]){ 422.886 - if(args.length != 1) 422.887 - System.err.println("Usage: RBTree n"); 422.888 - int n = Integer.parseInt(args[0]); 422.889 - Integer[] ints = new Integer[n]; 422.890 - for(int i = 0; i < ints.length; i++) 422.891 - { 422.892 - ints[i] = i; 422.893 - } 422.894 - Collections.shuffle(Arrays.asList(ints)); 422.895 - //force the ListMap class loading now 422.896 -// try 422.897 -// { 422.898 -// 422.899 -// //PersistentListMap.EMPTY.assocEx(1, null).assocEx(2,null).assocEx(3,null); 422.900 -// } 422.901 -// catch(Exception e) 422.902 -// { 422.903 -// e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 422.904 -// } 422.905 - System.out.println("Building set"); 422.906 - //IPersistentMap set = new PersistentArrayMap(); 422.907 - //IPersistentMap set = new PersistentHashtableMap(1001); 422.908 - IPersistentMap set = PersistentHashMap.EMPTY; 422.909 - //IPersistentMap set = new ListMap(); 422.910 - //IPersistentMap set = new ArrayMap(); 422.911 - //IPersistentMap set = new PersistentTreeMap(); 422.912 -// for(int i = 0; i < ints.length; i++) 422.913 -// { 422.914 -// Integer anInt = ints[i]; 422.915 -// set = set.add(anInt); 422.916 -// } 422.917 - long startTime = System.nanoTime(); 422.918 - for(Integer anInt : ints) 422.919 - { 422.920 - set = set.assoc(anInt, anInt); 422.921 - } 422.922 - //System.out.println("_count = " + set.count()); 422.923 - 422.924 -// System.out.println("_count = " + set._count + ", min: " + set.minKey() + ", max: " + set.maxKey() 422.925 -// + ", depth: " + set.depth()); 422.926 - for(Object aSet : set) 422.927 - { 422.928 - IMapEntry o = (IMapEntry) aSet; 422.929 - if(!set.contains(o.key())) 422.930 - System.err.println("Can't find: " + o.key()); 422.931 - //else if(n < 2000) 422.932 - // System.out.print(o.key().toString() + ","); 422.933 - } 422.934 - 422.935 - Random rand = new Random(42); 422.936 - for(int i = 0; i < ints.length / 2; i++) 422.937 - { 422.938 - Integer anInt = ints[rand.nextInt(n)]; 422.939 - set = set.without(anInt); 422.940 - } 422.941 - 422.942 - long estimatedTime = System.nanoTime() - startTime; 422.943 - System.out.println(); 422.944 - 422.945 - System.out.println("_count = " + set.count() + ", time: " + estimatedTime / 1000000); 422.946 - 422.947 - System.out.println("Building ht"); 422.948 - Hashtable ht = new Hashtable(1001); 422.949 - startTime = System.nanoTime(); 422.950 -// for(int i = 0; i < ints.length; i++) 422.951 -// { 422.952 -// Integer anInt = ints[i]; 422.953 -// ht.put(anInt,null); 422.954 -// } 422.955 - for(Integer anInt : ints) 422.956 - { 422.957 - ht.put(anInt, anInt); 422.958 - } 422.959 - //System.out.println("size = " + ht.size()); 422.960 - //Iterator it = ht.entrySet().iterator(); 422.961 - for(Object o1 : ht.entrySet()) 422.962 - { 422.963 - Map.Entry o = (Map.Entry) o1; 422.964 - if(!ht.containsKey(o.getKey())) 422.965 - System.err.println("Can't find: " + o); 422.966 - //else if(n < 2000) 422.967 - // System.out.print(o.toString() + ","); 422.968 - } 422.969 - 422.970 - rand = new Random(42); 422.971 - for(int i = 0; i < ints.length / 2; i++) 422.972 - { 422.973 - Integer anInt = ints[rand.nextInt(n)]; 422.974 - ht.remove(anInt); 422.975 - } 422.976 - estimatedTime = System.nanoTime() - startTime; 422.977 - System.out.println(); 422.978 - System.out.println("size = " + ht.size() + ", time: " + estimatedTime / 1000000); 422.979 - 422.980 - System.out.println("set lookup"); 422.981 - startTime = System.nanoTime(); 422.982 - int c = 0; 422.983 - for(Integer anInt : ints) 422.984 - { 422.985 - if(!set.contains(anInt)) 422.986 - ++c; 422.987 - } 422.988 - estimatedTime = System.nanoTime() - startTime; 422.989 - System.out.println("notfound = " + c + ", time: " + estimatedTime / 1000000); 422.990 - 422.991 - System.out.println("ht lookup"); 422.992 - startTime = System.nanoTime(); 422.993 - c = 0; 422.994 - for(Integer anInt : ints) 422.995 - { 422.996 - if(!ht.containsKey(anInt)) 422.997 - ++c; 422.998 - } 422.999 - estimatedTime = System.nanoTime() - startTime; 422.1000 - System.out.println("notfound = " + c + ", time: " + estimatedTime / 1000000); 422.1001 - 422.1002 -// System.out.println("_count = " + set._count + ", min: " + set.minKey() + ", max: " + set.maxKey() 422.1003 -// + ", depth: " + set.depth()); 422.1004 -} 422.1005 -*/ 422.1006 -}
423.1 --- a/src/clojure/lang/PersistentTreeSet.java Sat Aug 21 06:25:44 2010 -0400 423.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 423.3 @@ -1,90 +0,0 @@ 423.4 -/** 423.5 - * Copyright (c) Rich Hickey. All rights reserved. 423.6 - * The use and distribution terms for this software are covered by the 423.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 423.8 - * which can be found in the file epl-v10.html at the root of this distribution. 423.9 - * By using this software in any fashion, you are agreeing to be bound by 423.10 - * the terms of this license. 423.11 - * You must not remove this notice, or any other, from this software. 423.12 - **/ 423.13 - 423.14 -/* rich Mar 3, 2008 */ 423.15 - 423.16 -package clojure.lang; 423.17 - 423.18 -import java.util.Comparator; 423.19 - 423.20 -public class PersistentTreeSet extends APersistentSet implements IObj, Reversible, Sorted{ 423.21 -static public final PersistentTreeSet EMPTY = new PersistentTreeSet(null, PersistentTreeMap.EMPTY); 423.22 -final IPersistentMap _meta; 423.23 - 423.24 - 423.25 -static public PersistentTreeSet create(ISeq items){ 423.26 - PersistentTreeSet ret = EMPTY; 423.27 - for(; items != null; items = items.next()) 423.28 - { 423.29 - ret = (PersistentTreeSet) ret.cons(items.first()); 423.30 - } 423.31 - return ret; 423.32 -} 423.33 - 423.34 -static public PersistentTreeSet create(Comparator comp, ISeq items){ 423.35 - PersistentTreeSet ret = new PersistentTreeSet(null, new PersistentTreeMap(null, comp)); 423.36 - for(; items != null; items = items.next()) 423.37 - { 423.38 - ret = (PersistentTreeSet) ret.cons(items.first()); 423.39 - } 423.40 - return ret; 423.41 -} 423.42 - 423.43 -PersistentTreeSet(IPersistentMap meta, IPersistentMap impl){ 423.44 - super(impl); 423.45 - this._meta = meta; 423.46 -} 423.47 - 423.48 -public IPersistentSet disjoin(Object key) throws Exception{ 423.49 - if(contains(key)) 423.50 - return new PersistentTreeSet(meta(),impl.without(key)); 423.51 - return this; 423.52 -} 423.53 - 423.54 -public IPersistentSet cons(Object o){ 423.55 - if(contains(o)) 423.56 - return this; 423.57 - return new PersistentTreeSet(meta(),impl.assoc(o,o)); 423.58 -} 423.59 - 423.60 -public IPersistentCollection empty(){ 423.61 - return new PersistentTreeSet(meta(),(PersistentTreeMap)impl.empty()); 423.62 -} 423.63 - 423.64 -public ISeq rseq() throws Exception{ 423.65 - return APersistentMap.KeySeq.create(((Reversible) impl).rseq()); 423.66 -} 423.67 - 423.68 -public PersistentTreeSet withMeta(IPersistentMap meta){ 423.69 - return new PersistentTreeSet(meta, impl); 423.70 -} 423.71 - 423.72 -public Comparator comparator(){ 423.73 - return ((Sorted)impl).comparator(); 423.74 -} 423.75 - 423.76 -public Object entryKey(Object entry){ 423.77 - return entry; 423.78 -} 423.79 - 423.80 -public ISeq seq(boolean ascending){ 423.81 - PersistentTreeMap m = (PersistentTreeMap) impl; 423.82 - return RT.keys(m.seq(ascending)); 423.83 -} 423.84 - 423.85 -public ISeq seqFrom(Object key, boolean ascending){ 423.86 - PersistentTreeMap m = (PersistentTreeMap) impl; 423.87 - return RT.keys(m.seqFrom(key,ascending)); 423.88 -} 423.89 - 423.90 -public IPersistentMap meta(){ 423.91 - return _meta; 423.92 -} 423.93 -}
424.1 --- a/src/clojure/lang/PersistentVector.java Sat Aug 21 06:25:44 2010 -0400 424.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 424.3 @@ -1,748 +0,0 @@ 424.4 -/** 424.5 - * Copyright (c) Rich Hickey. All rights reserved. 424.6 - * The use and distribution terms for this software are covered by the 424.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 424.8 - * which can be found in the file epl-v10.html at the root of this distribution. 424.9 - * By using this software in any fashion, you are agreeing to be bound by 424.10 - * the terms of this license. 424.11 - * You must not remove this notice, or any other, from this software. 424.12 - **/ 424.13 - 424.14 -/* rich Jul 5, 2007 */ 424.15 - 424.16 -package clojure.lang; 424.17 - 424.18 -import java.io.Serializable; 424.19 -import java.util.List; 424.20 -import java.util.concurrent.atomic.AtomicReference; 424.21 - 424.22 -public class PersistentVector extends APersistentVector implements IObj, IEditableCollection{ 424.23 - 424.24 -static class Node implements Serializable { 424.25 - transient final AtomicReference<Thread> edit; 424.26 - final Object[] array; 424.27 - 424.28 - Node(AtomicReference<Thread> edit, Object[] array){ 424.29 - this.edit = edit; 424.30 - this.array = array; 424.31 - } 424.32 - 424.33 - Node(AtomicReference<Thread> edit){ 424.34 - this.edit = edit; 424.35 - this.array = new Object[32]; 424.36 - } 424.37 -} 424.38 - 424.39 -final static AtomicReference<Thread> NOEDIT = new AtomicReference<Thread>(null); 424.40 -final static Node EMPTY_NODE = new Node(NOEDIT, new Object[32]); 424.41 - 424.42 -final int cnt; 424.43 -final int shift; 424.44 -final Node root; 424.45 -final Object[] tail; 424.46 -final IPersistentMap _meta; 424.47 - 424.48 - 424.49 -public final static PersistentVector EMPTY = new PersistentVector(0, 5, EMPTY_NODE, new Object[]{}); 424.50 - 424.51 -static public PersistentVector create(ISeq items){ 424.52 - TransientVector ret = EMPTY.asTransient(); 424.53 - for(; items != null; items = items.next()) 424.54 - ret = ret.conj(items.first()); 424.55 - return ret.persistent(); 424.56 -} 424.57 - 424.58 -static public PersistentVector create(List items){ 424.59 - TransientVector ret = EMPTY.asTransient(); 424.60 - for(Object item : items) 424.61 - ret = ret.conj(item); 424.62 - return ret.persistent(); 424.63 -} 424.64 - 424.65 -static public PersistentVector create(Object... items){ 424.66 - TransientVector ret = EMPTY.asTransient(); 424.67 - for(Object item : items) 424.68 - ret = ret.conj(item); 424.69 - return ret.persistent(); 424.70 -} 424.71 - 424.72 -PersistentVector(int cnt, int shift, Node root, Object[] tail){ 424.73 - this._meta = null; 424.74 - this.cnt = cnt; 424.75 - this.shift = shift; 424.76 - this.root = root; 424.77 - this.tail = tail; 424.78 -} 424.79 - 424.80 - 424.81 -PersistentVector(IPersistentMap meta, int cnt, int shift, Node root, Object[] tail){ 424.82 - this._meta = meta; 424.83 - this.cnt = cnt; 424.84 - this.shift = shift; 424.85 - this.root = root; 424.86 - this.tail = tail; 424.87 -} 424.88 - 424.89 -public TransientVector asTransient(){ 424.90 - return new TransientVector(this); 424.91 -} 424.92 - 424.93 -final int tailoff(){ 424.94 - if(cnt < 32) 424.95 - return 0; 424.96 - return ((cnt - 1) >>> 5) << 5; 424.97 -} 424.98 - 424.99 -public Object[] arrayFor(int i){ 424.100 - if(i >= 0 && i < cnt) 424.101 - { 424.102 - if(i >= tailoff()) 424.103 - return tail; 424.104 - Node node = root; 424.105 - for(int level = shift; level > 0; level -= 5) 424.106 - node = (Node) node.array[(i >>> level) & 0x01f]; 424.107 - return node.array; 424.108 - } 424.109 - throw new IndexOutOfBoundsException(); 424.110 -} 424.111 - 424.112 -public Object nth(int i){ 424.113 - Object[] node = arrayFor(i); 424.114 - return node[i & 0x01f]; 424.115 -} 424.116 - 424.117 -public Object nth(int i, Object notFound){ 424.118 - if(i >= 0 && i < cnt) 424.119 - return nth(i); 424.120 - return notFound; 424.121 -} 424.122 - 424.123 -public PersistentVector assocN(int i, Object val){ 424.124 - if(i >= 0 && i < cnt) 424.125 - { 424.126 - if(i >= tailoff()) 424.127 - { 424.128 - Object[] newTail = new Object[tail.length]; 424.129 - System.arraycopy(tail, 0, newTail, 0, tail.length); 424.130 - newTail[i & 0x01f] = val; 424.131 - 424.132 - return new PersistentVector(meta(), cnt, shift, root, newTail); 424.133 - } 424.134 - 424.135 - return new PersistentVector(meta(), cnt, shift, doAssoc(shift, root, i, val), tail); 424.136 - } 424.137 - if(i == cnt) 424.138 - return cons(val); 424.139 - throw new IndexOutOfBoundsException(); 424.140 -} 424.141 - 424.142 -private static Node doAssoc(int level, Node node, int i, Object val){ 424.143 - Node ret = new Node(node.edit,node.array.clone()); 424.144 - if(level == 0) 424.145 - { 424.146 - ret.array[i & 0x01f] = val; 424.147 - } 424.148 - else 424.149 - { 424.150 - int subidx = (i >>> level) & 0x01f; 424.151 - ret.array[subidx] = doAssoc(level - 5, (Node) node.array[subidx], i, val); 424.152 - } 424.153 - return ret; 424.154 -} 424.155 - 424.156 -public int count(){ 424.157 - return cnt; 424.158 -} 424.159 - 424.160 -public PersistentVector withMeta(IPersistentMap meta){ 424.161 - return new PersistentVector(meta, cnt, shift, root, tail); 424.162 -} 424.163 - 424.164 -public IPersistentMap meta(){ 424.165 - return _meta; 424.166 -} 424.167 - 424.168 - 424.169 -public PersistentVector cons(Object val){ 424.170 - int i = cnt; 424.171 - //room in tail? 424.172 -// if(tail.length < 32) 424.173 - if(cnt - tailoff() < 32) 424.174 - { 424.175 - Object[] newTail = new Object[tail.length + 1]; 424.176 - System.arraycopy(tail, 0, newTail, 0, tail.length); 424.177 - newTail[tail.length] = val; 424.178 - return new PersistentVector(meta(), cnt + 1, shift, root, newTail); 424.179 - } 424.180 - //full tail, push into tree 424.181 - Node newroot; 424.182 - Node tailnode = new Node(root.edit,tail); 424.183 - int newshift = shift; 424.184 - //overflow root? 424.185 - if((cnt >>> 5) > (1 << shift)) 424.186 - { 424.187 - newroot = new Node(root.edit); 424.188 - newroot.array[0] = root; 424.189 - newroot.array[1] = newPath(root.edit,shift, tailnode); 424.190 - newshift += 5; 424.191 - } 424.192 - else 424.193 - newroot = pushTail(shift, root, tailnode); 424.194 - return new PersistentVector(meta(), cnt + 1, newshift, newroot, new Object[]{val}); 424.195 -} 424.196 - 424.197 -private Node pushTail(int level, Node parent, Node tailnode){ 424.198 - //if parent is leaf, insert node, 424.199 - // else does it map to an existing child? -> nodeToInsert = pushNode one more level 424.200 - // else alloc new path 424.201 - //return nodeToInsert placed in copy of parent 424.202 - int subidx = ((cnt - 1) >>> level) & 0x01f; 424.203 - Node ret = new Node(parent.edit, parent.array.clone()); 424.204 - Node nodeToInsert; 424.205 - if(level == 5) 424.206 - { 424.207 - nodeToInsert = tailnode; 424.208 - } 424.209 - else 424.210 - { 424.211 - Node child = (Node) parent.array[subidx]; 424.212 - nodeToInsert = (child != null)? 424.213 - pushTail(level-5,child, tailnode) 424.214 - :newPath(root.edit,level-5, tailnode); 424.215 - } 424.216 - ret.array[subidx] = nodeToInsert; 424.217 - return ret; 424.218 -} 424.219 - 424.220 -private static Node newPath(AtomicReference<Thread> edit,int level, Node node){ 424.221 - if(level == 0) 424.222 - return node; 424.223 - Node ret = new Node(edit); 424.224 - ret.array[0] = newPath(edit, level - 5, node); 424.225 - return ret; 424.226 -} 424.227 - 424.228 -public IChunkedSeq chunkedSeq(){ 424.229 - if(count() == 0) 424.230 - return null; 424.231 - return new ChunkedSeq(this,0,0); 424.232 -} 424.233 - 424.234 -public ISeq seq(){ 424.235 - return chunkedSeq(); 424.236 -} 424.237 - 424.238 -static public final class ChunkedSeq extends ASeq implements IChunkedSeq{ 424.239 - 424.240 - public final PersistentVector vec; 424.241 - final Object[] node; 424.242 - final int i; 424.243 - public final int offset; 424.244 - 424.245 - public ChunkedSeq(PersistentVector vec, int i, int offset){ 424.246 - this.vec = vec; 424.247 - this.i = i; 424.248 - this.offset = offset; 424.249 - this.node = vec.arrayFor(i); 424.250 - } 424.251 - 424.252 - ChunkedSeq(IPersistentMap meta, PersistentVector vec, Object[] node, int i, int offset){ 424.253 - super(meta); 424.254 - this.vec = vec; 424.255 - this.node = node; 424.256 - this.i = i; 424.257 - this.offset = offset; 424.258 - } 424.259 - 424.260 - ChunkedSeq(PersistentVector vec, Object[] node, int i, int offset){ 424.261 - this.vec = vec; 424.262 - this.node = node; 424.263 - this.i = i; 424.264 - this.offset = offset; 424.265 - } 424.266 - 424.267 - public IChunk chunkedFirst() throws Exception{ 424.268 - return new ArrayChunk(node, offset); 424.269 - } 424.270 - 424.271 - public ISeq chunkedNext(){ 424.272 - if(i + node.length < vec.cnt) 424.273 - return new ChunkedSeq(vec,i+ node.length,0); 424.274 - return null; 424.275 - } 424.276 - 424.277 - public ISeq chunkedMore(){ 424.278 - ISeq s = chunkedNext(); 424.279 - if(s == null) 424.280 - return PersistentList.EMPTY; 424.281 - return s; 424.282 - } 424.283 - 424.284 - public Obj withMeta(IPersistentMap meta){ 424.285 - if(meta == this._meta) 424.286 - return this; 424.287 - return new ChunkedSeq(meta, vec, node, i, offset); 424.288 - } 424.289 - 424.290 - public Object first(){ 424.291 - return node[offset]; 424.292 - } 424.293 - 424.294 - public ISeq next(){ 424.295 - if(offset + 1 < node.length) 424.296 - return new ChunkedSeq(vec, node, i, offset + 1); 424.297 - return chunkedNext(); 424.298 - } 424.299 -} 424.300 - 424.301 -public IPersistentCollection empty(){ 424.302 - return EMPTY.withMeta(meta()); 424.303 -} 424.304 - 424.305 -//private Node pushTail(int level, Node node, Object[] tailNode, Box expansion){ 424.306 -// Object newchild; 424.307 -// if(level == 0) 424.308 -// { 424.309 -// newchild = tailNode; 424.310 -// } 424.311 -// else 424.312 -// { 424.313 -// newchild = pushTail(level - 5, (Object[]) arr[arr.length - 1], tailNode, expansion); 424.314 -// if(expansion.val == null) 424.315 -// { 424.316 -// Object[] ret = arr.clone(); 424.317 -// ret[arr.length - 1] = newchild; 424.318 -// return ret; 424.319 -// } 424.320 -// else 424.321 -// newchild = expansion.val; 424.322 -// } 424.323 -// //expansion 424.324 -// if(arr.length == 32) 424.325 -// { 424.326 -// expansion.val = new Object[]{newchild}; 424.327 -// return arr; 424.328 -// } 424.329 -// Object[] ret = new Object[arr.length + 1]; 424.330 -// System.arraycopy(arr, 0, ret, 0, arr.length); 424.331 -// ret[arr.length] = newchild; 424.332 -// expansion.val = null; 424.333 -// return ret; 424.334 -//} 424.335 - 424.336 -public PersistentVector pop(){ 424.337 - if(cnt == 0) 424.338 - throw new IllegalStateException("Can't pop empty vector"); 424.339 - if(cnt == 1) 424.340 - return EMPTY.withMeta(meta()); 424.341 - //if(tail.length > 1) 424.342 - if(cnt-tailoff() > 1) 424.343 - { 424.344 - Object[] newTail = new Object[tail.length - 1]; 424.345 - System.arraycopy(tail, 0, newTail, 0, newTail.length); 424.346 - return new PersistentVector(meta(), cnt - 1, shift, root, newTail); 424.347 - } 424.348 - Object[] newtail = arrayFor(cnt - 2); 424.349 - 424.350 - Node newroot = popTail(shift, root); 424.351 - int newshift = shift; 424.352 - if(newroot == null) 424.353 - { 424.354 - newroot = EMPTY_NODE; 424.355 - } 424.356 - if(shift > 5 && newroot.array[1] == null) 424.357 - { 424.358 - newroot = (Node) newroot.array[0]; 424.359 - newshift -= 5; 424.360 - } 424.361 - return new PersistentVector(meta(), cnt - 1, newshift, newroot, newtail); 424.362 -} 424.363 - 424.364 -private Node popTail(int level, Node node){ 424.365 - int subidx = ((cnt-2) >>> level) & 0x01f; 424.366 - if(level > 5) 424.367 - { 424.368 - Node newchild = popTail(level - 5, (Node) node.array[subidx]); 424.369 - if(newchild == null && subidx == 0) 424.370 - return null; 424.371 - else 424.372 - { 424.373 - Node ret = new Node(root.edit, node.array.clone()); 424.374 - ret.array[subidx] = newchild; 424.375 - return ret; 424.376 - } 424.377 - } 424.378 - else if(subidx == 0) 424.379 - return null; 424.380 - else 424.381 - { 424.382 - Node ret = new Node(root.edit, node.array.clone()); 424.383 - ret.array[subidx] = null; 424.384 - return ret; 424.385 - } 424.386 -} 424.387 - 424.388 -static final class TransientVector extends AFn implements ITransientVector, Counted{ 424.389 - int cnt; 424.390 - int shift; 424.391 - Node root; 424.392 - Object[] tail; 424.393 - 424.394 - TransientVector(int cnt, int shift, Node root, Object[] tail){ 424.395 - this.cnt = cnt; 424.396 - this.shift = shift; 424.397 - this.root = root; 424.398 - this.tail = tail; 424.399 - } 424.400 - 424.401 - TransientVector(PersistentVector v){ 424.402 - this(v.cnt, v.shift, editableRoot(v.root), editableTail(v.tail)); 424.403 - } 424.404 - 424.405 - public int count(){ 424.406 - ensureEditable(); 424.407 - return cnt; 424.408 - } 424.409 - 424.410 - Node ensureEditable(Node node){ 424.411 - if(node.edit == root.edit) 424.412 - return node; 424.413 - return new Node(root.edit, node.array.clone()); 424.414 - } 424.415 - 424.416 - void ensureEditable(){ 424.417 - Thread owner = root.edit.get(); 424.418 - if(owner == Thread.currentThread()) 424.419 - return; 424.420 - if(owner != null) 424.421 - throw new IllegalAccessError("Transient used by non-owner thread"); 424.422 - throw new IllegalAccessError("Transient used after persistent! call"); 424.423 - 424.424 -// root = editableRoot(root); 424.425 -// tail = editableTail(tail); 424.426 - } 424.427 - 424.428 - static Node editableRoot(Node node){ 424.429 - return new Node(new AtomicReference<Thread>(Thread.currentThread()), node.array.clone()); 424.430 - } 424.431 - 424.432 - public PersistentVector persistent(){ 424.433 - ensureEditable(); 424.434 -// Thread owner = root.edit.get(); 424.435 -// if(owner != null && owner != Thread.currentThread()) 424.436 -// { 424.437 -// throw new IllegalAccessError("Mutation release by non-owner thread"); 424.438 -// } 424.439 - root.edit.set(null); 424.440 - Object[] trimmedTail = new Object[cnt-tailoff()]; 424.441 - System.arraycopy(tail,0,trimmedTail,0,trimmedTail.length); 424.442 - return new PersistentVector(cnt, shift, root, trimmedTail); 424.443 - } 424.444 - 424.445 - static Object[] editableTail(Object[] tl){ 424.446 - Object[] ret = new Object[32]; 424.447 - System.arraycopy(tl,0,ret,0,tl.length); 424.448 - return ret; 424.449 - } 424.450 - 424.451 - public TransientVector conj(Object val){ 424.452 - ensureEditable(); 424.453 - int i = cnt; 424.454 - //room in tail? 424.455 - if(i - tailoff() < 32) 424.456 - { 424.457 - tail[i & 0x01f] = val; 424.458 - ++cnt; 424.459 - return this; 424.460 - } 424.461 - //full tail, push into tree 424.462 - Node newroot; 424.463 - Node tailnode = new Node(root.edit, tail); 424.464 - tail = new Object[32]; 424.465 - tail[0] = val; 424.466 - int newshift = shift; 424.467 - //overflow root? 424.468 - if((cnt >>> 5) > (1 << shift)) 424.469 - { 424.470 - newroot = new Node(root.edit); 424.471 - newroot.array[0] = root; 424.472 - newroot.array[1] = newPath(root.edit,shift, tailnode); 424.473 - newshift += 5; 424.474 - } 424.475 - else 424.476 - newroot = pushTail(shift, root, tailnode); 424.477 - root = newroot; 424.478 - shift = newshift; 424.479 - ++cnt; 424.480 - return this; 424.481 - } 424.482 - 424.483 - private Node pushTail(int level, Node parent, Node tailnode){ 424.484 - //if parent is leaf, insert node, 424.485 - // else does it map to an existing child? -> nodeToInsert = pushNode one more level 424.486 - // else alloc new path 424.487 - //return nodeToInsert placed in parent 424.488 - parent = ensureEditable(parent); 424.489 - int subidx = ((cnt - 1) >>> level) & 0x01f; 424.490 - Node ret = parent; 424.491 - Node nodeToInsert; 424.492 - if(level == 5) 424.493 - { 424.494 - nodeToInsert = tailnode; 424.495 - } 424.496 - else 424.497 - { 424.498 - Node child = (Node) parent.array[subidx]; 424.499 - nodeToInsert = (child != null) ? 424.500 - pushTail(level - 5, child, tailnode) 424.501 - : newPath(root.edit, level - 5, tailnode); 424.502 - } 424.503 - ret.array[subidx] = nodeToInsert; 424.504 - return ret; 424.505 - } 424.506 - 424.507 - final private int tailoff(){ 424.508 - if(cnt < 32) 424.509 - return 0; 424.510 - return ((cnt-1) >>> 5) << 5; 424.511 - } 424.512 - 424.513 - private Object[] arrayFor(int i){ 424.514 - if(i >= 0 && i < cnt) 424.515 - { 424.516 - if(i >= tailoff()) 424.517 - return tail; 424.518 - Node node = root; 424.519 - for(int level = shift; level > 0; level -= 5) 424.520 - node = (Node) node.array[(i >>> level) & 0x01f]; 424.521 - return node.array; 424.522 - } 424.523 - throw new IndexOutOfBoundsException(); 424.524 - } 424.525 - 424.526 - public Object valAt(Object key){ 424.527 - //note - relies on ensureEditable in 2-arg valAt 424.528 - return valAt(key, null); 424.529 - } 424.530 - 424.531 - public Object valAt(Object key, Object notFound){ 424.532 - ensureEditable(); 424.533 - if(Util.isInteger(key)) 424.534 - { 424.535 - int i = ((Number) key).intValue(); 424.536 - if(i >= 0 && i < cnt) 424.537 - return nth(i); 424.538 - } 424.539 - return notFound; 424.540 - } 424.541 - 424.542 - public Object invoke(Object arg1) throws Exception{ 424.543 - //note - relies on ensureEditable in nth 424.544 - if(Util.isInteger(arg1)) 424.545 - return nth(((Number) arg1).intValue()); 424.546 - throw new IllegalArgumentException("Key must be integer"); 424.547 - } 424.548 - 424.549 - public Object nth(int i){ 424.550 - ensureEditable(); 424.551 - Object[] node = arrayFor(i); 424.552 - return node[i & 0x01f]; 424.553 - } 424.554 - 424.555 - public Object nth(int i, Object notFound){ 424.556 - if(i >= 0 && i < count()) 424.557 - return nth(i); 424.558 - return notFound; 424.559 - } 424.560 - 424.561 - public TransientVector assocN(int i, Object val){ 424.562 - ensureEditable(); 424.563 - if(i >= 0 && i < cnt) 424.564 - { 424.565 - if(i >= tailoff()) 424.566 - { 424.567 - tail[i & 0x01f] = val; 424.568 - return this; 424.569 - } 424.570 - 424.571 - root = doAssoc(shift, root, i, val); 424.572 - return this; 424.573 - } 424.574 - if(i == cnt) 424.575 - return conj(val); 424.576 - throw new IndexOutOfBoundsException(); 424.577 - } 424.578 - 424.579 - public TransientVector assoc(Object key, Object val){ 424.580 - //note - relies on ensureEditable in assocN 424.581 - if(Util.isInteger(key)) 424.582 - { 424.583 - int i = ((Number) key).intValue(); 424.584 - return assocN(i, val); 424.585 - } 424.586 - throw new IllegalArgumentException("Key must be integer"); 424.587 - } 424.588 - 424.589 - private Node doAssoc(int level, Node node, int i, Object val){ 424.590 - node = ensureEditable(node); 424.591 - Node ret = node; 424.592 - if(level == 0) 424.593 - { 424.594 - ret.array[i & 0x01f] = val; 424.595 - } 424.596 - else 424.597 - { 424.598 - int subidx = (i >>> level) & 0x01f; 424.599 - ret.array[subidx] = doAssoc(level - 5, (Node) node.array[subidx], i, val); 424.600 - } 424.601 - return ret; 424.602 - } 424.603 - 424.604 - public TransientVector pop(){ 424.605 - ensureEditable(); 424.606 - if(cnt == 0) 424.607 - throw new IllegalStateException("Can't pop empty vector"); 424.608 - if(cnt == 1) 424.609 - { 424.610 - cnt = 0; 424.611 - return this; 424.612 - } 424.613 - int i = cnt - 1; 424.614 - //pop in tail? 424.615 - if((i & 0x01f) > 0) 424.616 - { 424.617 - --cnt; 424.618 - return this; 424.619 - } 424.620 - 424.621 - Object[] newtail = arrayFor(cnt - 2); 424.622 - 424.623 - Node newroot = popTail(shift, root); 424.624 - int newshift = shift; 424.625 - if(newroot == null) 424.626 - { 424.627 - newroot = new Node(root.edit); 424.628 - } 424.629 - if(shift > 5 && newroot.array[1] == null) 424.630 - { 424.631 - newroot = ensureEditable((Node) newroot.array[0]); 424.632 - newshift -= 5; 424.633 - } 424.634 - root = newroot; 424.635 - shift = newshift; 424.636 - --cnt; 424.637 - tail = newtail; 424.638 - return this; 424.639 - } 424.640 - 424.641 - private Node popTail(int level, Node node){ 424.642 - node = ensureEditable(node); 424.643 - int subidx = ((cnt - 2) >>> level) & 0x01f; 424.644 - if(level > 5) 424.645 - { 424.646 - Node newchild = popTail(level - 5, (Node) node.array[subidx]); 424.647 - if(newchild == null && subidx == 0) 424.648 - return null; 424.649 - else 424.650 - { 424.651 - Node ret = node; 424.652 - ret.array[subidx] = newchild; 424.653 - return ret; 424.654 - } 424.655 - } 424.656 - else if(subidx == 0) 424.657 - return null; 424.658 - else 424.659 - { 424.660 - Node ret = node; 424.661 - ret.array[subidx] = null; 424.662 - return ret; 424.663 - } 424.664 - } 424.665 -} 424.666 -/* 424.667 -static public void main(String[] args){ 424.668 - if(args.length != 3) 424.669 - { 424.670 - System.err.println("Usage: PersistentVector size writes reads"); 424.671 - return; 424.672 - } 424.673 - int size = Integer.parseInt(args[0]); 424.674 - int writes = Integer.parseInt(args[1]); 424.675 - int reads = Integer.parseInt(args[2]); 424.676 -// Vector v = new Vector(size); 424.677 - ArrayList v = new ArrayList(size); 424.678 -// v.setSize(size); 424.679 - //PersistentArray p = new PersistentArray(size); 424.680 - PersistentVector p = PersistentVector.EMPTY; 424.681 -// MutableVector mp = p.mutable(); 424.682 - 424.683 - for(int i = 0; i < size; i++) 424.684 - { 424.685 - v.add(i); 424.686 -// v.set(i, i); 424.687 - //p = p.set(i, 0); 424.688 - p = p.cons(i); 424.689 -// mp = mp.conj(i); 424.690 - } 424.691 - 424.692 - Random rand; 424.693 - 424.694 - rand = new Random(42); 424.695 - long tv = 0; 424.696 - System.out.println("ArrayList"); 424.697 - long startTime = System.nanoTime(); 424.698 - for(int i = 0; i < writes; i++) 424.699 - { 424.700 - v.set(rand.nextInt(size), i); 424.701 - } 424.702 - for(int i = 0; i < reads; i++) 424.703 - { 424.704 - tv += (Integer) v.get(rand.nextInt(size)); 424.705 - } 424.706 - long estimatedTime = System.nanoTime() - startTime; 424.707 - System.out.println("time: " + estimatedTime / 1000000); 424.708 - System.out.println("PersistentVector"); 424.709 - rand = new Random(42); 424.710 - startTime = System.nanoTime(); 424.711 - long tp = 0; 424.712 - 424.713 -// PersistentVector oldp = p; 424.714 - //Random rand2 = new Random(42); 424.715 - 424.716 - MutableVector mp = p.mutable(); 424.717 - for(int i = 0; i < writes; i++) 424.718 - { 424.719 -// p = p.assocN(rand.nextInt(size), i); 424.720 - mp = mp.assocN(rand.nextInt(size), i); 424.721 -// mp = mp.assoc(rand.nextInt(size), i); 424.722 - //dummy set to force perverse branching 424.723 - //oldp = oldp.assocN(rand2.nextInt(size), i); 424.724 - } 424.725 - for(int i = 0; i < reads; i++) 424.726 - { 424.727 -// tp += (Integer) p.nth(rand.nextInt(size)); 424.728 - tp += (Integer) mp.nth(rand.nextInt(size)); 424.729 - } 424.730 -// p = mp.immutable(); 424.731 - //mp.cons(42); 424.732 - estimatedTime = System.nanoTime() - startTime; 424.733 - System.out.println("time: " + estimatedTime / 1000000); 424.734 - for(int i = 0; i < size / 2; i++) 424.735 - { 424.736 - mp = mp.pop(); 424.737 -// p = p.pop(); 424.738 - v.remove(v.size() - 1); 424.739 - } 424.740 - p = (PersistentVector) mp.immutable(); 424.741 - //mp.pop(); //should fail 424.742 - for(int i = 0; i < size / 2; i++) 424.743 - { 424.744 - tp += (Integer) p.nth(i); 424.745 - tv += (Integer) v.get(i); 424.746 - } 424.747 - System.out.println("Done: " + tv + ", " + tp); 424.748 - 424.749 -} 424.750 -// */ 424.751 -}
425.1 --- a/src/clojure/lang/ProxyHandler.java Sat Aug 21 06:25:44 2010 -0400 425.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 425.3 @@ -1,72 +0,0 @@ 425.4 -/** 425.5 - * Copyright (c) Rich Hickey. All rights reserved. 425.6 - * The use and distribution terms for this software are covered by the 425.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 425.8 - * which can be found in the file epl-v10.html at the root of this distribution. 425.9 - * By using this software in any fashion, you are agreeing to be bound by 425.10 - * the terms of this license. 425.11 - * You must not remove this notice, or any other, from this software. 425.12 - **/ 425.13 - 425.14 -/* rich Oct 4, 2007 */ 425.15 - 425.16 -package clojure.lang; 425.17 - 425.18 -import java.lang.reflect.InvocationHandler; 425.19 -import java.lang.reflect.Method; 425.20 - 425.21 -public class ProxyHandler implements InvocationHandler{ 425.22 -//method-name-string->fn 425.23 -final IPersistentMap fns; 425.24 - 425.25 - 425.26 -public ProxyHandler(IPersistentMap fns){ 425.27 - this.fns = fns; 425.28 -} 425.29 - 425.30 -public Object invoke(Object proxy, Method method, Object[] args) throws Throwable{ 425.31 - Class rt = method.getReturnType(); 425.32 - IFn fn = (IFn) fns.valAt(method.getName()); 425.33 - if(fn == null) 425.34 - { 425.35 - if(rt == Void.TYPE) 425.36 - return null; 425.37 - else if(method.getName().equals("equals")) 425.38 - { 425.39 - return proxy == args[0]; 425.40 - } 425.41 - else if(method.getName().equals("hashCode")) 425.42 - { 425.43 - return System.identityHashCode(proxy); 425.44 - } 425.45 - else if(method.getName().equals("toString")) 425.46 - { 425.47 - return "Proxy: " + System.identityHashCode(proxy); 425.48 - } 425.49 - throw new UnsupportedOperationException(); 425.50 - } 425.51 - Object ret = fn.applyTo(ArraySeq.create(args)); 425.52 - if(rt == Void.TYPE) 425.53 - return null; 425.54 - else if(rt.isPrimitive()) 425.55 - { 425.56 - if(rt == Character.TYPE) 425.57 - return ret; 425.58 - else if(rt == Integer.TYPE) 425.59 - return ((Number) ret).intValue(); 425.60 - else if(rt == Long.TYPE) 425.61 - return ((Number) ret).longValue(); 425.62 - else if(rt == Float.TYPE) 425.63 - return ((Number) ret).floatValue(); 425.64 - else if(rt == Double.TYPE) 425.65 - return ((Number) ret).doubleValue(); 425.66 - else if(rt == Boolean.TYPE && !(ret instanceof Boolean)) 425.67 - return ret == null ? Boolean.FALSE : Boolean.TRUE; 425.68 - else if(rt == Byte.TYPE) 425.69 - return (byte) ((Number) ret).intValue(); 425.70 - else if(rt == Short.TYPE) 425.71 - return (short) ((Number) ret).intValue(); 425.72 - } 425.73 - return ret; 425.74 -} 425.75 -}
426.1 --- a/src/clojure/lang/RT.java Sat Aug 21 06:25:44 2010 -0400 426.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 426.3 @@ -1,1735 +0,0 @@ 426.4 -/** 426.5 - * Copyright (c) Rich Hickey. All rights reserved. 426.6 - * The use and distribution terms for this software are covered by the 426.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 426.8 - * which can be found in the file epl-v10.html at the root of this distribution. 426.9 - * By using this software in any fashion, you are agreeing to be bound by 426.10 - * the terms of this license. 426.11 - * You must not remove this notice, or any other, from this software. 426.12 - **/ 426.13 - 426.14 -/* rich Mar 25, 2006 4:28:27 PM */ 426.15 - 426.16 -package clojure.lang; 426.17 - 426.18 -import java.util.concurrent.atomic.AtomicInteger; 426.19 -import java.util.concurrent.Callable; 426.20 -import java.util.*; 426.21 -import java.util.regex.Matcher; 426.22 -import java.util.regex.Pattern; 426.23 -import java.io.*; 426.24 -import java.lang.reflect.Array; 426.25 -import java.math.BigDecimal; 426.26 -import java.math.BigInteger; 426.27 -import java.security.AccessController; 426.28 -import java.security.PrivilegedAction; 426.29 -import java.net.URL; 426.30 -import java.net.JarURLConnection; 426.31 -import java.nio.charset.Charset; 426.32 - 426.33 -public class RT{ 426.34 - 426.35 -static final public Boolean T = Boolean.TRUE;//Keyword.intern(Symbol.create(null, "t")); 426.36 -static final public Boolean F = Boolean.FALSE;//Keyword.intern(Symbol.create(null, "t")); 426.37 -static final public String LOADER_SUFFIX = "__init"; 426.38 - 426.39 -//simple-symbol->class 426.40 -final static IPersistentMap DEFAULT_IMPORTS = map( 426.41 -// Symbol.create("RT"), "clojure.lang.RT", 426.42 -// Symbol.create("Num"), "clojure.lang.Num", 426.43 -// Symbol.create("Symbol"), "clojure.lang.Symbol", 426.44 -// Symbol.create("Keyword"), "clojure.lang.Keyword", 426.45 -// Symbol.create("Var"), "clojure.lang.Var", 426.46 -// Symbol.create("Ref"), "clojure.lang.Ref", 426.47 -// Symbol.create("IFn"), "clojure.lang.IFn", 426.48 -// Symbol.create("IObj"), "clojure.lang.IObj", 426.49 -// Symbol.create("ISeq"), "clojure.lang.ISeq", 426.50 -// Symbol.create("IPersistentCollection"), 426.51 -// "clojure.lang.IPersistentCollection", 426.52 -// Symbol.create("IPersistentMap"), "clojure.lang.IPersistentMap", 426.53 -// Symbol.create("IPersistentList"), "clojure.lang.IPersistentList", 426.54 -// Symbol.create("IPersistentVector"), "clojure.lang.IPersistentVector", 426.55 -Symbol.create("Boolean"), Boolean.class, 426.56 -Symbol.create("Byte"), Byte.class, 426.57 -Symbol.create("Character"), Character.class, 426.58 -Symbol.create("Class"), Class.class, 426.59 -Symbol.create("ClassLoader"), ClassLoader.class, 426.60 -Symbol.create("Compiler"), Compiler.class, 426.61 -Symbol.create("Double"), Double.class, 426.62 -Symbol.create("Enum"), Enum.class, 426.63 -Symbol.create("Float"), Float.class, 426.64 -Symbol.create("InheritableThreadLocal"), InheritableThreadLocal.class, 426.65 -Symbol.create("Integer"), Integer.class, 426.66 -Symbol.create("Long"), Long.class, 426.67 -Symbol.create("Math"), Math.class, 426.68 -Symbol.create("Number"), Number.class, 426.69 -Symbol.create("Object"), Object.class, 426.70 -Symbol.create("Package"), Package.class, 426.71 -Symbol.create("Process"), Process.class, 426.72 -Symbol.create("ProcessBuilder"), ProcessBuilder.class, 426.73 -Symbol.create("Runtime"), Runtime.class, 426.74 -Symbol.create("RuntimePermission"), RuntimePermission.class, 426.75 -Symbol.create("SecurityManager"), SecurityManager.class, 426.76 -Symbol.create("Short"), Short.class, 426.77 -Symbol.create("StackTraceElement"), StackTraceElement.class, 426.78 -Symbol.create("StrictMath"), StrictMath.class, 426.79 -Symbol.create("String"), String.class, 426.80 -Symbol.create("StringBuffer"), StringBuffer.class, 426.81 -Symbol.create("StringBuilder"), StringBuilder.class, 426.82 -Symbol.create("System"), System.class, 426.83 -Symbol.create("Thread"), Thread.class, 426.84 -Symbol.create("ThreadGroup"), ThreadGroup.class, 426.85 -Symbol.create("ThreadLocal"), ThreadLocal.class, 426.86 -Symbol.create("Throwable"), Throwable.class, 426.87 -Symbol.create("Void"), Void.class, 426.88 -Symbol.create("Appendable"), Appendable.class, 426.89 -Symbol.create("CharSequence"), CharSequence.class, 426.90 -Symbol.create("Cloneable"), Cloneable.class, 426.91 -Symbol.create("Comparable"), Comparable.class, 426.92 -Symbol.create("Iterable"), Iterable.class, 426.93 -Symbol.create("Readable"), Readable.class, 426.94 -Symbol.create("Runnable"), Runnable.class, 426.95 -Symbol.create("Callable"), Callable.class, 426.96 -Symbol.create("BigInteger"), BigInteger.class, 426.97 -Symbol.create("BigDecimal"), BigDecimal.class, 426.98 -Symbol.create("ArithmeticException"), ArithmeticException.class, 426.99 -Symbol.create("ArrayIndexOutOfBoundsException"), ArrayIndexOutOfBoundsException.class, 426.100 -Symbol.create("ArrayStoreException"), ArrayStoreException.class, 426.101 -Symbol.create("ClassCastException"), ClassCastException.class, 426.102 -Symbol.create("ClassNotFoundException"), ClassNotFoundException.class, 426.103 -Symbol.create("CloneNotSupportedException"), CloneNotSupportedException.class, 426.104 -Symbol.create("EnumConstantNotPresentException"), EnumConstantNotPresentException.class, 426.105 -Symbol.create("Exception"), Exception.class, 426.106 -Symbol.create("IllegalAccessException"), IllegalAccessException.class, 426.107 -Symbol.create("IllegalArgumentException"), IllegalArgumentException.class, 426.108 -Symbol.create("IllegalMonitorStateException"), IllegalMonitorStateException.class, 426.109 -Symbol.create("IllegalStateException"), IllegalStateException.class, 426.110 -Symbol.create("IllegalThreadStateException"), IllegalThreadStateException.class, 426.111 -Symbol.create("IndexOutOfBoundsException"), IndexOutOfBoundsException.class, 426.112 -Symbol.create("InstantiationException"), InstantiationException.class, 426.113 -Symbol.create("InterruptedException"), InterruptedException.class, 426.114 -Symbol.create("NegativeArraySizeException"), NegativeArraySizeException.class, 426.115 -Symbol.create("NoSuchFieldException"), NoSuchFieldException.class, 426.116 -Symbol.create("NoSuchMethodException"), NoSuchMethodException.class, 426.117 -Symbol.create("NullPointerException"), NullPointerException.class, 426.118 -Symbol.create("NumberFormatException"), NumberFormatException.class, 426.119 -Symbol.create("RuntimeException"), RuntimeException.class, 426.120 -Symbol.create("SecurityException"), SecurityException.class, 426.121 -Symbol.create("StringIndexOutOfBoundsException"), StringIndexOutOfBoundsException.class, 426.122 -Symbol.create("TypeNotPresentException"), TypeNotPresentException.class, 426.123 -Symbol.create("UnsupportedOperationException"), UnsupportedOperationException.class, 426.124 -Symbol.create("AbstractMethodError"), AbstractMethodError.class, 426.125 -Symbol.create("AssertionError"), AssertionError.class, 426.126 -Symbol.create("ClassCircularityError"), ClassCircularityError.class, 426.127 -Symbol.create("ClassFormatError"), ClassFormatError.class, 426.128 -Symbol.create("Error"), Error.class, 426.129 -Symbol.create("ExceptionInInitializerError"), ExceptionInInitializerError.class, 426.130 -Symbol.create("IllegalAccessError"), IllegalAccessError.class, 426.131 -Symbol.create("IncompatibleClassChangeError"), IncompatibleClassChangeError.class, 426.132 -Symbol.create("InstantiationError"), InstantiationError.class, 426.133 -Symbol.create("InternalError"), InternalError.class, 426.134 -Symbol.create("LinkageError"), LinkageError.class, 426.135 -Symbol.create("NoClassDefFoundError"), NoClassDefFoundError.class, 426.136 -Symbol.create("NoSuchFieldError"), NoSuchFieldError.class, 426.137 -Symbol.create("NoSuchMethodError"), NoSuchMethodError.class, 426.138 -Symbol.create("OutOfMemoryError"), OutOfMemoryError.class, 426.139 -Symbol.create("StackOverflowError"), StackOverflowError.class, 426.140 -Symbol.create("ThreadDeath"), ThreadDeath.class, 426.141 -Symbol.create("UnknownError"), UnknownError.class, 426.142 -Symbol.create("UnsatisfiedLinkError"), UnsatisfiedLinkError.class, 426.143 -Symbol.create("UnsupportedClassVersionError"), UnsupportedClassVersionError.class, 426.144 -Symbol.create("VerifyError"), VerifyError.class, 426.145 -Symbol.create("VirtualMachineError"), VirtualMachineError.class, 426.146 -Symbol.create("Thread$UncaughtExceptionHandler"), Thread.UncaughtExceptionHandler.class, 426.147 -Symbol.create("Thread$State"), Thread.State.class, 426.148 -Symbol.create("Deprecated"), Deprecated.class, 426.149 -Symbol.create("Override"), Override.class, 426.150 -Symbol.create("SuppressWarnings"), SuppressWarnings.class 426.151 - 426.152 -// Symbol.create("Collection"), "java.util.Collection", 426.153 -// Symbol.create("Comparator"), "java.util.Comparator", 426.154 -// Symbol.create("Enumeration"), "java.util.Enumeration", 426.155 -// Symbol.create("EventListener"), "java.util.EventListener", 426.156 -// Symbol.create("Formattable"), "java.util.Formattable", 426.157 -// Symbol.create("Iterator"), "java.util.Iterator", 426.158 -// Symbol.create("List"), "java.util.List", 426.159 -// Symbol.create("ListIterator"), "java.util.ListIterator", 426.160 -// Symbol.create("Map"), "java.util.Map", 426.161 -// Symbol.create("Map$Entry"), "java.util.Map$Entry", 426.162 -// Symbol.create("Observer"), "java.util.Observer", 426.163 -// Symbol.create("Queue"), "java.util.Queue", 426.164 -// Symbol.create("RandomAccess"), "java.util.RandomAccess", 426.165 -// Symbol.create("Set"), "java.util.Set", 426.166 -// Symbol.create("SortedMap"), "java.util.SortedMap", 426.167 -// Symbol.create("SortedSet"), "java.util.SortedSet" 426.168 -); 426.169 - 426.170 -// single instance of UTF-8 Charset, so as to avoid catching UnsupportedCharsetExceptions everywhere 426.171 -static public Charset UTF8 = Charset.forName("UTF-8"); 426.172 - 426.173 -static public final Namespace CLOJURE_NS = Namespace.findOrCreate(Symbol.create("clojure.core")); 426.174 -//static final Namespace USER_NS = Namespace.findOrCreate(Symbol.create("user")); 426.175 -final static public Var OUT = 426.176 - Var.intern(CLOJURE_NS, Symbol.create("*out*"), new OutputStreamWriter(System.out)); 426.177 -final static public Var IN = 426.178 - Var.intern(CLOJURE_NS, Symbol.create("*in*"), 426.179 - new LineNumberingPushbackReader(new InputStreamReader(System.in))); 426.180 -final static public Var ERR = 426.181 - Var.intern(CLOJURE_NS, Symbol.create("*err*"), 426.182 - new PrintWriter(new OutputStreamWriter(System.err), true)); 426.183 -final static Keyword TAG_KEY = Keyword.intern(null, "tag"); 426.184 -final static public Var AGENT = Var.intern(CLOJURE_NS, Symbol.create("*agent*"), null); 426.185 -final static public Var READEVAL = Var.intern(CLOJURE_NS, Symbol.create("*read-eval*"), T); 426.186 -final static public Var ASSERT = Var.intern(CLOJURE_NS, Symbol.create("*assert*"), T); 426.187 -final static public Var MATH_CONTEXT = Var.intern(CLOJURE_NS, Symbol.create("*math-context*"), null); 426.188 -static Keyword LINE_KEY = Keyword.intern(null, "line"); 426.189 -static Keyword FILE_KEY = Keyword.intern(null, "file"); 426.190 -static Keyword DECLARED_KEY = Keyword.intern(null, "declared"); 426.191 -final static public Var USE_CONTEXT_CLASSLOADER = 426.192 - Var.intern(CLOJURE_NS, Symbol.create("*use-context-classloader*"), T); 426.193 -//final static public Var CURRENT_MODULE = Var.intern(Symbol.create("clojure.core", "current-module"), 426.194 -// Module.findOrCreateModule("clojure/user")); 426.195 - 426.196 -final static Symbol LOAD_FILE = Symbol.create("load-file"); 426.197 -final static Symbol IN_NAMESPACE = Symbol.create("in-ns"); 426.198 -final static Symbol NAMESPACE = Symbol.create("ns"); 426.199 -static final Symbol IDENTICAL = Symbol.create("identical?"); 426.200 -final static Var CMD_LINE_ARGS = Var.intern(CLOJURE_NS, Symbol.create("*command-line-args*"), null); 426.201 -//symbol 426.202 -final public static Var CURRENT_NS = Var.intern(CLOJURE_NS, Symbol.create("*ns*"), 426.203 - CLOJURE_NS); 426.204 - 426.205 -final static Var FLUSH_ON_NEWLINE = Var.intern(CLOJURE_NS, Symbol.create("*flush-on-newline*"), T); 426.206 -final static Var PRINT_META = Var.intern(CLOJURE_NS, Symbol.create("*print-meta*"), F); 426.207 -final static Var PRINT_READABLY = Var.intern(CLOJURE_NS, Symbol.create("*print-readably*"), T); 426.208 -final static Var PRINT_DUP = Var.intern(CLOJURE_NS, Symbol.create("*print-dup*"), F); 426.209 -final static Var WARN_ON_REFLECTION = Var.intern(CLOJURE_NS, Symbol.create("*warn-on-reflection*"), F); 426.210 -final static Var ALLOW_UNRESOLVED_VARS = Var.intern(CLOJURE_NS, Symbol.create("*allow-unresolved-vars*"), F); 426.211 - 426.212 -final static Var IN_NS_VAR = Var.intern(CLOJURE_NS, Symbol.create("in-ns"), F); 426.213 -final static Var NS_VAR = Var.intern(CLOJURE_NS, Symbol.create("ns"), F); 426.214 -static final Var PRINT_INITIALIZED = Var.intern(CLOJURE_NS, Symbol.create("print-initialized")); 426.215 -static final Var PR_ON = Var.intern(CLOJURE_NS, Symbol.create("pr-on")); 426.216 -//final static Var IMPORTS = Var.intern(CLOJURE_NS, Symbol.create("*imports*"), DEFAULT_IMPORTS); 426.217 -final static IFn inNamespace = new AFn(){ 426.218 - public Object invoke(Object arg1) throws Exception{ 426.219 - Symbol nsname = (Symbol) arg1; 426.220 - Namespace ns = Namespace.findOrCreate(nsname); 426.221 - CURRENT_NS.set(ns); 426.222 - return ns; 426.223 - } 426.224 -}; 426.225 - 426.226 -final static IFn bootNamespace = new AFn(){ 426.227 - public Object invoke(Object __form, Object __env,Object arg1) throws Exception{ 426.228 - Symbol nsname = (Symbol) arg1; 426.229 - Namespace ns = Namespace.findOrCreate(nsname); 426.230 - CURRENT_NS.set(ns); 426.231 - return ns; 426.232 - } 426.233 -}; 426.234 - 426.235 -public static List<String> processCommandLine(String[] args){ 426.236 - List<String> arglist = Arrays.asList(args); 426.237 - int split = arglist.indexOf("--"); 426.238 - if(split >= 0) { 426.239 - CMD_LINE_ARGS.bindRoot(RT.seq(arglist.subList(split + 1, args.length))); 426.240 - return arglist.subList(0, split); 426.241 - } 426.242 - return arglist; 426.243 -} 426.244 - 426.245 -// duck typing stderr plays nice with e.g. swank 426.246 -public static PrintWriter errPrintWriter(){ 426.247 - Writer w = (Writer) ERR.deref(); 426.248 - if (w instanceof PrintWriter) { 426.249 - return (PrintWriter) w; 426.250 - } else { 426.251 - return new PrintWriter(w); 426.252 - } 426.253 -} 426.254 - 426.255 -static public final Object[] EMPTY_ARRAY = new Object[]{}; 426.256 -static public final Comparator DEFAULT_COMPARATOR = new DefaultComparator(); 426.257 - 426.258 -private static final class DefaultComparator implements Comparator, Serializable { 426.259 - public int compare(Object o1, Object o2){ 426.260 - return Util.compare(o1, o2); 426.261 - } 426.262 - 426.263 - private Object readResolve() throws ObjectStreamException { 426.264 - // ensures that we aren't hanging onto a new default comparator for every 426.265 - // sorted set, etc., we deserialize 426.266 - return DEFAULT_COMPARATOR; 426.267 - } 426.268 -} 426.269 - 426.270 -static AtomicInteger id = new AtomicInteger(1); 426.271 - 426.272 -static public void addURL(Object url) throws Exception{ 426.273 - URL u = (url instanceof String) ? (new URL((String) url)) : (URL) url; 426.274 - ClassLoader ccl = Thread.currentThread().getContextClassLoader(); 426.275 - if(ccl instanceof DynamicClassLoader) 426.276 - ((DynamicClassLoader)ccl).addURL(u); 426.277 - else 426.278 - throw new IllegalAccessError("Context classloader is not a DynamicClassLoader"); 426.279 -} 426.280 - 426.281 -static{ 426.282 - Keyword dockw = Keyword.intern(null, "doc"); 426.283 - Keyword arglistskw = Keyword.intern(null, "arglists"); 426.284 - Symbol namesym = Symbol.create("name"); 426.285 - OUT.setTag(Symbol.create("java.io.Writer")); 426.286 - CURRENT_NS.setTag(Symbol.create("clojure.lang.Namespace")); 426.287 - AGENT.setMeta(map(dockw, "The agent currently running an action on this thread, else nil")); 426.288 - AGENT.setTag(Symbol.create("clojure.lang.Agent")); 426.289 - MATH_CONTEXT.setTag(Symbol.create("java.math.MathContext")); 426.290 - Var nv = Var.intern(CLOJURE_NS, NAMESPACE, bootNamespace); 426.291 - nv.setMacro(); 426.292 - Var v; 426.293 - v = Var.intern(CLOJURE_NS, IN_NAMESPACE, inNamespace); 426.294 - v.setMeta(map(dockw, "Sets *ns* to the namespace named by the symbol, creating it if needed.", 426.295 - arglistskw, list(vector(namesym)))); 426.296 - v = Var.intern(CLOJURE_NS, LOAD_FILE, 426.297 - new AFn(){ 426.298 - public Object invoke(Object arg1) throws Exception{ 426.299 - return Compiler.loadFile((String) arg1); 426.300 - } 426.301 - }); 426.302 - v.setMeta(map(dockw, "Sequentially read and evaluate the set of forms contained in the file.", 426.303 - arglistskw, list(vector(namesym)))); 426.304 - try { 426.305 - doInit(); 426.306 - } 426.307 - catch(Exception e) { 426.308 - throw new RuntimeException(e); 426.309 - } 426.310 -} 426.311 - 426.312 - 426.313 -static public Var var(String ns, String name){ 426.314 - return Var.intern(Namespace.findOrCreate(Symbol.intern(null, ns)), Symbol.intern(null, name)); 426.315 -} 426.316 - 426.317 -static public Var var(String ns, String name, Object init){ 426.318 - return Var.intern(Namespace.findOrCreate(Symbol.intern(null, ns)), Symbol.intern(null, name), init); 426.319 -} 426.320 - 426.321 -public static void loadResourceScript(String name) throws Exception{ 426.322 - loadResourceScript(name, true); 426.323 -} 426.324 - 426.325 -public static void maybeLoadResourceScript(String name) throws Exception{ 426.326 - loadResourceScript(name, false); 426.327 -} 426.328 - 426.329 -public static void loadResourceScript(String name, boolean failIfNotFound) throws Exception{ 426.330 - loadResourceScript(RT.class, name, failIfNotFound); 426.331 -} 426.332 - 426.333 -public static void loadResourceScript(Class c, String name) throws Exception{ 426.334 - loadResourceScript(c, name, true); 426.335 -} 426.336 - 426.337 -public static void loadResourceScript(Class c, String name, boolean failIfNotFound) throws Exception{ 426.338 - int slash = name.lastIndexOf('/'); 426.339 - String file = slash >= 0 ? name.substring(slash + 1) : name; 426.340 - InputStream ins = baseLoader().getResourceAsStream(name); 426.341 - if(ins != null) { 426.342 - try { 426.343 - Compiler.load(new InputStreamReader(ins, UTF8), name, file); 426.344 - } 426.345 - finally { 426.346 - ins.close(); 426.347 - } 426.348 - } 426.349 - else if(failIfNotFound) { 426.350 - throw new FileNotFoundException("Could not locate Clojure resource on classpath: " + name); 426.351 - } 426.352 -} 426.353 - 426.354 -static public void init() throws Exception{ 426.355 - RT.errPrintWriter().println("No need to call RT.init() anymore"); 426.356 -} 426.357 - 426.358 -static public long lastModified(URL url, String libfile) throws Exception{ 426.359 - if(url.getProtocol().equals("jar")) { 426.360 - return ((JarURLConnection) url.openConnection()).getJarFile().getEntry(libfile).getTime(); 426.361 - } 426.362 - else { 426.363 - return url.openConnection().getLastModified(); 426.364 - } 426.365 -} 426.366 - 426.367 -static void compile(String cljfile) throws Exception{ 426.368 - InputStream ins = baseLoader().getResourceAsStream(cljfile); 426.369 - if(ins != null) { 426.370 - try { 426.371 - Compiler.compile(new InputStreamReader(ins, UTF8), cljfile, 426.372 - cljfile.substring(1 + cljfile.lastIndexOf("/"))); 426.373 - } 426.374 - finally { 426.375 - ins.close(); 426.376 - } 426.377 - 426.378 - } 426.379 - else 426.380 - throw new FileNotFoundException("Could not locate Clojure resource on classpath: " + cljfile); 426.381 -} 426.382 - 426.383 -static public void load(String scriptbase) throws Exception{ 426.384 - load(scriptbase, true); 426.385 -} 426.386 - 426.387 -static public void load(String scriptbase, boolean failIfNotFound) throws Exception{ 426.388 - String classfile = scriptbase + LOADER_SUFFIX + ".class"; 426.389 - String cljfile = scriptbase + ".clj"; 426.390 - URL classURL = baseLoader().getResource(classfile); 426.391 - URL cljURL = baseLoader().getResource(cljfile); 426.392 - boolean loaded = false; 426.393 - 426.394 - if((classURL != null && 426.395 - (cljURL == null 426.396 - || lastModified(classURL, classfile) > lastModified(cljURL, cljfile))) 426.397 - || classURL == null) { 426.398 - try { 426.399 - Var.pushThreadBindings( 426.400 - RT.map(CURRENT_NS, CURRENT_NS.deref(), 426.401 - WARN_ON_REFLECTION, WARN_ON_REFLECTION.deref())); 426.402 - loaded = (loadClassForName(scriptbase.replace('/', '.') + LOADER_SUFFIX) != null); 426.403 - } 426.404 - finally { 426.405 - Var.popThreadBindings(); 426.406 - } 426.407 - } 426.408 - if(!loaded && cljURL != null) { 426.409 - if(booleanCast(Compiler.COMPILE_FILES.deref())) 426.410 - compile(cljfile); 426.411 - else 426.412 - loadResourceScript(RT.class, cljfile); 426.413 - } 426.414 - else if(!loaded && failIfNotFound) 426.415 - throw new FileNotFoundException(String.format("Could not locate %s or %s on classpath: ", classfile, cljfile)); 426.416 -} 426.417 - 426.418 -static void doInit() throws Exception{ 426.419 - load("clojure/core"); 426.420 - load("clojure/zip", false); 426.421 - load("clojure/xml", false); 426.422 - load("clojure/set", false); 426.423 - 426.424 - Var.pushThreadBindings( 426.425 - RT.map(CURRENT_NS, CURRENT_NS.deref(), 426.426 - WARN_ON_REFLECTION, WARN_ON_REFLECTION.deref())); 426.427 - try { 426.428 - Symbol USER = Symbol.create("user"); 426.429 - Symbol CLOJURE = Symbol.create("clojure.core"); 426.430 - 426.431 - Var in_ns = var("clojure.core", "in-ns"); 426.432 - Var refer = var("clojure.core", "refer"); 426.433 - in_ns.invoke(USER); 426.434 - refer.invoke(CLOJURE); 426.435 - maybeLoadResourceScript("user.clj"); 426.436 - } 426.437 - finally { 426.438 - Var.popThreadBindings(); 426.439 - } 426.440 -} 426.441 - 426.442 -static public int nextID(){ 426.443 - return id.getAndIncrement(); 426.444 -} 426.445 - 426.446 - 426.447 -////////////// Collections support ///////////////////////////////// 426.448 - 426.449 -static public ISeq seq(Object coll){ 426.450 - if(coll instanceof ASeq) 426.451 - return (ASeq) coll; 426.452 - else if(coll instanceof LazySeq) 426.453 - return ((LazySeq) coll).seq(); 426.454 - else 426.455 - return seqFrom(coll); 426.456 -} 426.457 - 426.458 -static ISeq seqFrom(Object coll){ 426.459 - if(coll instanceof Seqable) 426.460 - return ((Seqable) coll).seq(); 426.461 - else if(coll == null) 426.462 - return null; 426.463 - else if(coll instanceof Iterable) 426.464 - return IteratorSeq.create(((Iterable) coll).iterator()); 426.465 - else if(coll.getClass().isArray()) 426.466 - return ArraySeq.createFromObject(coll); 426.467 - else if(coll instanceof CharSequence) 426.468 - return StringSeq.create((CharSequence) coll); 426.469 - else if(coll instanceof Map) 426.470 - return seq(((Map) coll).entrySet()); 426.471 - else { 426.472 - Class c = coll.getClass(); 426.473 - Class sc = c.getSuperclass(); 426.474 - throw new IllegalArgumentException("Don't know how to create ISeq from: " + c.getName()); 426.475 - } 426.476 -} 426.477 - 426.478 -static public ISeq keys(Object coll){ 426.479 - return APersistentMap.KeySeq.create(seq(coll)); 426.480 -} 426.481 - 426.482 -static public ISeq vals(Object coll){ 426.483 - return APersistentMap.ValSeq.create(seq(coll)); 426.484 -} 426.485 - 426.486 -static public IPersistentMap meta(Object x){ 426.487 - if(x instanceof IMeta) 426.488 - return ((IMeta) x).meta(); 426.489 - return null; 426.490 -} 426.491 - 426.492 -public static int count(Object o){ 426.493 - if(o instanceof Counted) 426.494 - return ((Counted) o).count(); 426.495 - return countFrom(Util.ret1(o, o = null)); 426.496 -} 426.497 - 426.498 -static int countFrom(Object o){ 426.499 - if(o == null) 426.500 - return 0; 426.501 - else if(o instanceof IPersistentCollection) { 426.502 - ISeq s = seq(o); 426.503 - o = null; 426.504 - int i = 0; 426.505 - for(; s != null; s = s.next()) { 426.506 - if(s instanceof Counted) 426.507 - return i + s.count(); 426.508 - i++; 426.509 - } 426.510 - return i; 426.511 - } 426.512 - else if(o instanceof CharSequence) 426.513 - return ((CharSequence) o).length(); 426.514 - else if(o instanceof Collection) 426.515 - return ((Collection) o).size(); 426.516 - else if(o instanceof Map) 426.517 - return ((Map) o).size(); 426.518 - else if(o.getClass().isArray()) 426.519 - return Array.getLength(o); 426.520 - 426.521 - throw new UnsupportedOperationException("count not supported on this type: " + o.getClass().getSimpleName()); 426.522 -} 426.523 - 426.524 -static public IPersistentCollection conj(IPersistentCollection coll, Object x){ 426.525 - if(coll == null) 426.526 - return new PersistentList(x); 426.527 - return coll.cons(x); 426.528 -} 426.529 - 426.530 -static public ISeq cons(Object x, Object coll){ 426.531 - //ISeq y = seq(coll); 426.532 - if(coll == null) 426.533 - return new PersistentList(x); 426.534 - else if(coll instanceof ISeq) 426.535 - return new Cons(x, (ISeq) coll); 426.536 - else 426.537 - return new Cons(x, seq(coll)); 426.538 -} 426.539 - 426.540 -static public Object first(Object x){ 426.541 - if(x instanceof ISeq) 426.542 - return ((ISeq) x).first(); 426.543 - ISeq seq = seq(x); 426.544 - if(seq == null) 426.545 - return null; 426.546 - return seq.first(); 426.547 -} 426.548 - 426.549 -static public Object second(Object x){ 426.550 - return first(next(x)); 426.551 -} 426.552 - 426.553 -static public Object third(Object x){ 426.554 - return first(next(next(x))); 426.555 -} 426.556 - 426.557 -static public Object fourth(Object x){ 426.558 - return first(next(next(next(x)))); 426.559 -} 426.560 - 426.561 -static public ISeq next(Object x){ 426.562 - if(x instanceof ISeq) 426.563 - return ((ISeq) x).next(); 426.564 - ISeq seq = seq(x); 426.565 - if(seq == null) 426.566 - return null; 426.567 - return seq.next(); 426.568 -} 426.569 - 426.570 -static public ISeq more(Object x){ 426.571 - if(x instanceof ISeq) 426.572 - return ((ISeq) x).more(); 426.573 - ISeq seq = seq(x); 426.574 - if(seq == null) 426.575 - return PersistentList.EMPTY; 426.576 - return seq.more(); 426.577 -} 426.578 - 426.579 -//static public Seqable more(Object x){ 426.580 -// Seqable ret = null; 426.581 -// if(x instanceof ISeq) 426.582 -// ret = ((ISeq) x).more(); 426.583 -// else 426.584 -// { 426.585 -// ISeq seq = seq(x); 426.586 -// if(seq == null) 426.587 -// ret = PersistentList.EMPTY; 426.588 -// else 426.589 -// ret = seq.more(); 426.590 -// } 426.591 -// if(ret == null) 426.592 -// ret = PersistentList.EMPTY; 426.593 -// return ret; 426.594 -//} 426.595 - 426.596 -static public Object peek(Object x){ 426.597 - if(x == null) 426.598 - return null; 426.599 - return ((IPersistentStack) x).peek(); 426.600 -} 426.601 - 426.602 -static public Object pop(Object x){ 426.603 - if(x == null) 426.604 - return null; 426.605 - return ((IPersistentStack) x).pop(); 426.606 -} 426.607 - 426.608 -static public Object get(Object coll, Object key){ 426.609 - if(coll instanceof ILookup) 426.610 - return ((ILookup) coll).valAt(key); 426.611 - return getFrom(coll, key); 426.612 -} 426.613 - 426.614 -static Object getFrom(Object coll, Object key){ 426.615 - if(coll == null) 426.616 - return null; 426.617 - else if(coll instanceof Map) { 426.618 - Map m = (Map) coll; 426.619 - return m.get(key); 426.620 - } 426.621 - else if(coll instanceof IPersistentSet) { 426.622 - IPersistentSet set = (IPersistentSet) coll; 426.623 - return set.get(key); 426.624 - } 426.625 - else if(key instanceof Number && (coll instanceof String || coll.getClass().isArray())) { 426.626 - int n = ((Number) key).intValue(); 426.627 - if(n >= 0 && n < count(coll)) 426.628 - return nth(coll, n); 426.629 - return null; 426.630 - } 426.631 - 426.632 - return null; 426.633 -} 426.634 - 426.635 -static public Object get(Object coll, Object key, Object notFound){ 426.636 - if(coll instanceof ILookup) 426.637 - return ((ILookup) coll).valAt(key, notFound); 426.638 - return getFrom(coll, key, notFound); 426.639 -} 426.640 - 426.641 -static Object getFrom(Object coll, Object key, Object notFound){ 426.642 - if(coll == null) 426.643 - return notFound; 426.644 - else if(coll instanceof Map) { 426.645 - Map m = (Map) coll; 426.646 - if(m.containsKey(key)) 426.647 - return m.get(key); 426.648 - return notFound; 426.649 - } 426.650 - else if(coll instanceof IPersistentSet) { 426.651 - IPersistentSet set = (IPersistentSet) coll; 426.652 - if(set.contains(key)) 426.653 - return set.get(key); 426.654 - return notFound; 426.655 - } 426.656 - else if(key instanceof Number && (coll instanceof String || coll.getClass().isArray())) { 426.657 - int n = ((Number) key).intValue(); 426.658 - return n >= 0 && n < count(coll) ? nth(coll, n) : notFound; 426.659 - } 426.660 - return notFound; 426.661 - 426.662 -} 426.663 - 426.664 -static public Associative assoc(Object coll, Object key, Object val){ 426.665 - if(coll == null) 426.666 - return new PersistentArrayMap(new Object[]{key, val}); 426.667 - return ((Associative) coll).assoc(key, val); 426.668 -} 426.669 - 426.670 -static public Object contains(Object coll, Object key){ 426.671 - if(coll == null) 426.672 - return F; 426.673 - else if(coll instanceof Associative) 426.674 - return ((Associative) coll).containsKey(key) ? T : F; 426.675 - else if(coll instanceof IPersistentSet) 426.676 - return ((IPersistentSet) coll).contains(key) ? T : F; 426.677 - else if(coll instanceof Map) { 426.678 - Map m = (Map) coll; 426.679 - return m.containsKey(key) ? T : F; 426.680 - } 426.681 - else if(key instanceof Number && (coll instanceof String || coll.getClass().isArray())) { 426.682 - int n = ((Number) key).intValue(); 426.683 - return n >= 0 && n < count(coll); 426.684 - } 426.685 - return F; 426.686 -} 426.687 - 426.688 -static public Object find(Object coll, Object key){ 426.689 - if(coll == null) 426.690 - return null; 426.691 - else if(coll instanceof Associative) 426.692 - return ((Associative) coll).entryAt(key); 426.693 - else { 426.694 - Map m = (Map) coll; 426.695 - if(m.containsKey(key)) 426.696 - return new MapEntry(key, m.get(key)); 426.697 - return null; 426.698 - } 426.699 -} 426.700 - 426.701 -//takes a seq of key,val,key,val 426.702 - 426.703 -//returns tail starting at val of matching key if found, else null 426.704 -static public ISeq findKey(Keyword key, ISeq keyvals) throws Exception{ 426.705 - while(keyvals != null) { 426.706 - ISeq r = keyvals.next(); 426.707 - if(r == null) 426.708 - throw new Exception("Malformed keyword argslist"); 426.709 - if(keyvals.first() == key) 426.710 - return r; 426.711 - keyvals = r.next(); 426.712 - } 426.713 - return null; 426.714 -} 426.715 - 426.716 -static public Object dissoc(Object coll, Object key) throws Exception{ 426.717 - if(coll == null) 426.718 - return null; 426.719 - return ((IPersistentMap) coll).without(key); 426.720 -} 426.721 - 426.722 -static public Object nth(Object coll, int n){ 426.723 - if(coll instanceof Indexed) 426.724 - return ((Indexed) coll).nth(n); 426.725 - return nthFrom(Util.ret1(coll, coll = null), n); 426.726 -} 426.727 - 426.728 -static Object nthFrom(Object coll, int n){ 426.729 - if(coll == null) 426.730 - return null; 426.731 - else if(coll instanceof CharSequence) 426.732 - return Character.valueOf(((CharSequence) coll).charAt(n)); 426.733 - else if(coll.getClass().isArray()) 426.734 - return Reflector.prepRet(Array.get(coll, n)); 426.735 - else if(coll instanceof RandomAccess) 426.736 - return ((List) coll).get(n); 426.737 - else if(coll instanceof Matcher) 426.738 - return ((Matcher) coll).group(n); 426.739 - 426.740 - else if(coll instanceof Map.Entry) { 426.741 - Map.Entry e = (Map.Entry) coll; 426.742 - if(n == 0) 426.743 - return e.getKey(); 426.744 - else if(n == 1) 426.745 - return e.getValue(); 426.746 - throw new IndexOutOfBoundsException(); 426.747 - } 426.748 - 426.749 - else if(coll instanceof Sequential) { 426.750 - ISeq seq = RT.seq(coll); 426.751 - coll = null; 426.752 - for(int i = 0; i <= n && seq != null; ++i, seq = seq.next()) { 426.753 - if(i == n) 426.754 - return seq.first(); 426.755 - } 426.756 - throw new IndexOutOfBoundsException(); 426.757 - } 426.758 - else 426.759 - throw new UnsupportedOperationException( 426.760 - "nth not supported on this type: " + coll.getClass().getSimpleName()); 426.761 -} 426.762 - 426.763 -static public Object nth(Object coll, int n, Object notFound){ 426.764 - if(coll instanceof Indexed) { 426.765 - Indexed v = (Indexed) coll; 426.766 - return v.nth(n, notFound); 426.767 - } 426.768 - return nthFrom(coll, n, notFound); 426.769 -} 426.770 - 426.771 -static Object nthFrom(Object coll, int n, Object notFound){ 426.772 - if(coll == null) 426.773 - return notFound; 426.774 - else if(n < 0) 426.775 - return notFound; 426.776 - 426.777 - else if(coll instanceof CharSequence) { 426.778 - CharSequence s = (CharSequence) coll; 426.779 - if(n < s.length()) 426.780 - return Character.valueOf(s.charAt(n)); 426.781 - return notFound; 426.782 - } 426.783 - else if(coll.getClass().isArray()) { 426.784 - if(n < Array.getLength(coll)) 426.785 - return Reflector.prepRet(Array.get(coll, n)); 426.786 - return notFound; 426.787 - } 426.788 - else if(coll instanceof RandomAccess) { 426.789 - List list = (List) coll; 426.790 - if(n < list.size()) 426.791 - return list.get(n); 426.792 - return notFound; 426.793 - } 426.794 - else if(coll instanceof Matcher) { 426.795 - Matcher m = (Matcher) coll; 426.796 - if(n < m.groupCount()) 426.797 - return m.group(n); 426.798 - return notFound; 426.799 - } 426.800 - else if(coll instanceof Map.Entry) { 426.801 - Map.Entry e = (Map.Entry) coll; 426.802 - if(n == 0) 426.803 - return e.getKey(); 426.804 - else if(n == 1) 426.805 - return e.getValue(); 426.806 - return notFound; 426.807 - } 426.808 - else if(coll instanceof Sequential) { 426.809 - ISeq seq = RT.seq(coll); 426.810 - coll = null; 426.811 - for(int i = 0; i <= n && seq != null; ++i, seq = seq.next()) { 426.812 - if(i == n) 426.813 - return seq.first(); 426.814 - } 426.815 - return notFound; 426.816 - } 426.817 - else 426.818 - throw new UnsupportedOperationException( 426.819 - "nth not supported on this type: " + coll.getClass().getSimpleName()); 426.820 -} 426.821 - 426.822 -static public Object assocN(int n, Object val, Object coll){ 426.823 - if(coll == null) 426.824 - return null; 426.825 - else if(coll instanceof IPersistentVector) 426.826 - return ((IPersistentVector) coll).assocN(n, val); 426.827 - else if(coll instanceof Object[]) { 426.828 - //hmm... this is not persistent 426.829 - Object[] array = ((Object[]) coll); 426.830 - array[n] = val; 426.831 - return array; 426.832 - } 426.833 - else 426.834 - return null; 426.835 -} 426.836 - 426.837 -static boolean hasTag(Object o, Object tag){ 426.838 - return Util.equals(tag, RT.get(RT.meta(o), TAG_KEY)); 426.839 -} 426.840 - 426.841 -/** 426.842 - * ********************* Boxing/casts ****************************** 426.843 - */ 426.844 -static public Object box(Object x){ 426.845 - return x; 426.846 -} 426.847 - 426.848 -static public Character box(char x){ 426.849 - return Character.valueOf(x); 426.850 -} 426.851 - 426.852 -static public Object box(boolean x){ 426.853 - return x ? T : F; 426.854 -} 426.855 - 426.856 -static public Object box(Boolean x){ 426.857 - return x;// ? T : null; 426.858 -} 426.859 - 426.860 -static public Number box(byte x){ 426.861 - return x;//Num.from(x); 426.862 -} 426.863 - 426.864 -static public Number box(short x){ 426.865 - return x;//Num.from(x); 426.866 -} 426.867 - 426.868 -static public Number box(int x){ 426.869 - return x;//Num.from(x); 426.870 -} 426.871 - 426.872 -static public Number box(long x){ 426.873 - return x;//Num.from(x); 426.874 -} 426.875 - 426.876 -static public Number box(float x){ 426.877 - return x;//Num.from(x); 426.878 -} 426.879 - 426.880 -static public Number box(double x){ 426.881 - return x;//Num.from(x); 426.882 -} 426.883 - 426.884 -static public char charCast(Object x){ 426.885 - if(x instanceof Character) 426.886 - return ((Character) x).charValue(); 426.887 - 426.888 - long n = ((Number) x).longValue(); 426.889 - if(n < Character.MIN_VALUE || n > Character.MAX_VALUE) 426.890 - throw new IllegalArgumentException("Value out of range for char: " + x); 426.891 - 426.892 - return (char) n; 426.893 -} 426.894 - 426.895 -static public boolean booleanCast(Object x){ 426.896 - if(x instanceof Boolean) 426.897 - return ((Boolean) x).booleanValue(); 426.898 - return x != null; 426.899 -} 426.900 - 426.901 -static public boolean booleanCast(boolean x){ 426.902 - return x; 426.903 -} 426.904 - 426.905 -static public byte byteCast(Object x){ 426.906 - long n = ((Number) x).longValue(); 426.907 - if(n < Byte.MIN_VALUE || n > Byte.MAX_VALUE) 426.908 - throw new IllegalArgumentException("Value out of range for byte: " + x); 426.909 - 426.910 - return (byte) n; 426.911 -} 426.912 - 426.913 -static public short shortCast(Object x){ 426.914 - long n = ((Number) x).longValue(); 426.915 - if(n < Short.MIN_VALUE || n > Short.MAX_VALUE) 426.916 - throw new IllegalArgumentException("Value out of range for short: " + x); 426.917 - 426.918 - return (short) n; 426.919 -} 426.920 - 426.921 -static public int intCast(Object x){ 426.922 - if(x instanceof Integer) 426.923 - return ((Integer)x).intValue(); 426.924 - if(x instanceof Number) 426.925 - return intCast(((Number) x).longValue()); 426.926 - return ((Character) x).charValue(); 426.927 -} 426.928 - 426.929 -static public int intCast(char x){ 426.930 - return x; 426.931 -} 426.932 - 426.933 -static public int intCast(byte x){ 426.934 - return x; 426.935 -} 426.936 - 426.937 -static public int intCast(short x){ 426.938 - return x; 426.939 -} 426.940 - 426.941 -static public int intCast(int x){ 426.942 - return x; 426.943 -} 426.944 - 426.945 -static public int intCast(float x){ 426.946 - if(x < Integer.MIN_VALUE || x > Integer.MAX_VALUE) 426.947 - throw new IllegalArgumentException("Value out of range for int: " + x); 426.948 - return (int) x; 426.949 -} 426.950 - 426.951 -static public int intCast(long x){ 426.952 - if(x < Integer.MIN_VALUE || x > Integer.MAX_VALUE) 426.953 - throw new IllegalArgumentException("Value out of range for int: " + x); 426.954 - return (int) x; 426.955 -} 426.956 - 426.957 -static public int intCast(double x){ 426.958 - if(x < Integer.MIN_VALUE || x > Integer.MAX_VALUE) 426.959 - throw new IllegalArgumentException("Value out of range for int: " + x); 426.960 - return (int) x; 426.961 -} 426.962 - 426.963 -static public long longCast(Object x){ 426.964 - return ((Number) x).longValue(); 426.965 -} 426.966 - 426.967 -static public long longCast(int x){ 426.968 - return x; 426.969 -} 426.970 - 426.971 -static public long longCast(float x){ 426.972 - if(x < Long.MIN_VALUE || x > Long.MAX_VALUE) 426.973 - throw new IllegalArgumentException("Value out of range for long: " + x); 426.974 - return (long) x; 426.975 -} 426.976 - 426.977 -static public long longCast(long x){ 426.978 - return x; 426.979 -} 426.980 - 426.981 -static public long longCast(double x){ 426.982 - if(x < Long.MIN_VALUE || x > Long.MAX_VALUE) 426.983 - throw new IllegalArgumentException("Value out of range for long: " + x); 426.984 - return (long) x; 426.985 -} 426.986 - 426.987 -static public float floatCast(Object x){ 426.988 - if(x instanceof Float) 426.989 - return ((Float) x).floatValue(); 426.990 - 426.991 - double n = ((Number) x).doubleValue(); 426.992 - if(n < -Float.MAX_VALUE || n > Float.MAX_VALUE) 426.993 - throw new IllegalArgumentException("Value out of range for float: " + x); 426.994 - 426.995 - return (float) n; 426.996 - 426.997 -} 426.998 - 426.999 -static public float floatCast(int x){ 426.1000 - return x; 426.1001 -} 426.1002 - 426.1003 -static public float floatCast(float x){ 426.1004 - return x; 426.1005 -} 426.1006 - 426.1007 -static public float floatCast(long x){ 426.1008 - return x; 426.1009 -} 426.1010 - 426.1011 -static public float floatCast(double x){ 426.1012 - if(x < -Float.MAX_VALUE || x > Float.MAX_VALUE) 426.1013 - throw new IllegalArgumentException("Value out of range for float: " + x); 426.1014 - 426.1015 - return (float) x; 426.1016 -} 426.1017 - 426.1018 -static public double doubleCast(Object x){ 426.1019 - return ((Number) x).doubleValue(); 426.1020 -} 426.1021 - 426.1022 -static public double doubleCast(int x){ 426.1023 - return x; 426.1024 -} 426.1025 - 426.1026 -static public double doubleCast(float x){ 426.1027 - return x; 426.1028 -} 426.1029 - 426.1030 -static public double doubleCast(long x){ 426.1031 - return x; 426.1032 -} 426.1033 - 426.1034 -static public double doubleCast(double x){ 426.1035 - return x; 426.1036 -} 426.1037 - 426.1038 -static public IPersistentMap map(Object... init){ 426.1039 - if(init == null) 426.1040 - return PersistentArrayMap.EMPTY; 426.1041 - else if(init.length <= PersistentArrayMap.HASHTABLE_THRESHOLD) 426.1042 - return PersistentArrayMap.createWithCheck(init); 426.1043 - return PersistentHashMap.createWithCheck(init); 426.1044 -} 426.1045 - 426.1046 -static public IPersistentSet set(Object... init){ 426.1047 - return PersistentHashSet.createWithCheck(init); 426.1048 -} 426.1049 - 426.1050 -static public IPersistentVector vector(Object... init){ 426.1051 - return LazilyPersistentVector.createOwning(init); 426.1052 -} 426.1053 - 426.1054 -static public IPersistentVector subvec(IPersistentVector v, int start, int end){ 426.1055 - if(end < start || start < 0 || end > v.count()) 426.1056 - throw new IndexOutOfBoundsException(); 426.1057 - if(start == end) 426.1058 - return PersistentVector.EMPTY; 426.1059 - return new APersistentVector.SubVector(null, v, start, end); 426.1060 -} 426.1061 - 426.1062 -/** 426.1063 - * **************************************** list support ******************************* 426.1064 - */ 426.1065 - 426.1066 - 426.1067 -static public ISeq list(){ 426.1068 - return null; 426.1069 -} 426.1070 - 426.1071 -static public ISeq list(Object arg1){ 426.1072 - return new PersistentList(arg1); 426.1073 -} 426.1074 - 426.1075 -static public ISeq list(Object arg1, Object arg2){ 426.1076 - return listStar(arg1, arg2, null); 426.1077 -} 426.1078 - 426.1079 -static public ISeq list(Object arg1, Object arg2, Object arg3){ 426.1080 - return listStar(arg1, arg2, arg3, null); 426.1081 -} 426.1082 - 426.1083 -static public ISeq list(Object arg1, Object arg2, Object arg3, Object arg4){ 426.1084 - return listStar(arg1, arg2, arg3, arg4, null); 426.1085 -} 426.1086 - 426.1087 -static public ISeq list(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5){ 426.1088 - return listStar(arg1, arg2, arg3, arg4, arg5, null); 426.1089 -} 426.1090 - 426.1091 -static public ISeq listStar(Object arg1, ISeq rest){ 426.1092 - return (ISeq) cons(arg1, rest); 426.1093 -} 426.1094 - 426.1095 -static public ISeq listStar(Object arg1, Object arg2, ISeq rest){ 426.1096 - return (ISeq) cons(arg1, cons(arg2, rest)); 426.1097 -} 426.1098 - 426.1099 -static public ISeq listStar(Object arg1, Object arg2, Object arg3, ISeq rest){ 426.1100 - return (ISeq) cons(arg1, cons(arg2, cons(arg3, rest))); 426.1101 -} 426.1102 - 426.1103 -static public ISeq listStar(Object arg1, Object arg2, Object arg3, Object arg4, ISeq rest){ 426.1104 - return (ISeq) cons(arg1, cons(arg2, cons(arg3, cons(arg4, rest)))); 426.1105 -} 426.1106 - 426.1107 -static public ISeq listStar(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq rest){ 426.1108 - return (ISeq) cons(arg1, cons(arg2, cons(arg3, cons(arg4, cons(arg5, rest))))); 426.1109 -} 426.1110 - 426.1111 -static public ISeq arrayToList(Object[] a) throws Exception{ 426.1112 - ISeq ret = null; 426.1113 - for(int i = a.length - 1; i >= 0; --i) 426.1114 - ret = (ISeq) cons(a[i], ret); 426.1115 - return ret; 426.1116 -} 426.1117 - 426.1118 -static public Object[] object_array(Object sizeOrSeq){ 426.1119 - if(sizeOrSeq instanceof Number) 426.1120 - return new Object[((Number) sizeOrSeq).intValue()]; 426.1121 - else 426.1122 - { 426.1123 - ISeq s = RT.seq(sizeOrSeq); 426.1124 - int size = RT.count(s); 426.1125 - Object[] ret = new Object[size]; 426.1126 - for(int i = 0; i < size && s != null; i++, s = s.next()) 426.1127 - ret[i] = s.first(); 426.1128 - return ret; 426.1129 - } 426.1130 -} 426.1131 - 426.1132 -static public Object[] toArray(Object coll) throws Exception{ 426.1133 - if(coll == null) 426.1134 - return EMPTY_ARRAY; 426.1135 - else if(coll instanceof Object[]) 426.1136 - return (Object[]) coll; 426.1137 - else if(coll instanceof Collection) 426.1138 - return ((Collection) coll).toArray(); 426.1139 - else if(coll instanceof Map) 426.1140 - return ((Map) coll).entrySet().toArray(); 426.1141 - else if(coll instanceof String) { 426.1142 - char[] chars = ((String) coll).toCharArray(); 426.1143 - Object[] ret = new Object[chars.length]; 426.1144 - for(int i = 0; i < chars.length; i++) 426.1145 - ret[i] = chars[i]; 426.1146 - return ret; 426.1147 - } 426.1148 - else if(coll.getClass().isArray()) { 426.1149 - ISeq s = (seq(coll)); 426.1150 - Object[] ret = new Object[count(s)]; 426.1151 - for(int i = 0; i < ret.length; i++, s = s.next()) 426.1152 - ret[i] = s.first(); 426.1153 - return ret; 426.1154 - } 426.1155 - else 426.1156 - throw new Exception("Unable to convert: " + coll.getClass() + " to Object[]"); 426.1157 -} 426.1158 - 426.1159 -static public Object[] seqToArray(ISeq seq){ 426.1160 - int len = length(seq); 426.1161 - Object[] ret = new Object[len]; 426.1162 - for(int i = 0; seq != null; ++i, seq = seq.next()) 426.1163 - ret[i] = seq.first(); 426.1164 - return ret; 426.1165 -} 426.1166 - 426.1167 -static public Object seqToTypedArray(ISeq seq) throws Exception{ 426.1168 - Class type = (seq != null) ? seq.first().getClass() : Object.class; 426.1169 - return seqToTypedArray(type, seq); 426.1170 -} 426.1171 - 426.1172 -static public Object seqToTypedArray(Class type, ISeq seq) throws Exception{ 426.1173 - Object ret = Array.newInstance(type, length(seq)); 426.1174 - for(int i = 0; seq != null; ++i, seq = seq.next()) 426.1175 - Array.set(ret, i, seq.first()); 426.1176 - return ret; 426.1177 -} 426.1178 - 426.1179 -static public int length(ISeq list){ 426.1180 - int i = 0; 426.1181 - for(ISeq c = list; c != null; c = c.next()) { 426.1182 - i++; 426.1183 - } 426.1184 - return i; 426.1185 -} 426.1186 - 426.1187 -static public int boundedLength(ISeq list, int limit) throws Exception{ 426.1188 - int i = 0; 426.1189 - for(ISeq c = list; c != null && i <= limit; c = c.next()) { 426.1190 - i++; 426.1191 - } 426.1192 - return i; 426.1193 -} 426.1194 - 426.1195 -///////////////////////////////// reader support //////////////////////////////// 426.1196 - 426.1197 -static Character readRet(int ret){ 426.1198 - if(ret == -1) 426.1199 - return null; 426.1200 - return box((char) ret); 426.1201 -} 426.1202 - 426.1203 -static public Character readChar(Reader r) throws Exception{ 426.1204 - int ret = r.read(); 426.1205 - return readRet(ret); 426.1206 -} 426.1207 - 426.1208 -static public Character peekChar(Reader r) throws Exception{ 426.1209 - int ret; 426.1210 - if(r instanceof PushbackReader) { 426.1211 - ret = r.read(); 426.1212 - ((PushbackReader) r).unread(ret); 426.1213 - } 426.1214 - else { 426.1215 - r.mark(1); 426.1216 - ret = r.read(); 426.1217 - r.reset(); 426.1218 - } 426.1219 - 426.1220 - return readRet(ret); 426.1221 -} 426.1222 - 426.1223 -static public int getLineNumber(Reader r){ 426.1224 - if(r instanceof LineNumberingPushbackReader) 426.1225 - return ((LineNumberingPushbackReader) r).getLineNumber(); 426.1226 - return 0; 426.1227 -} 426.1228 - 426.1229 -static public LineNumberingPushbackReader getLineNumberingReader(Reader r){ 426.1230 - if(isLineNumberingReader(r)) 426.1231 - return (LineNumberingPushbackReader) r; 426.1232 - return new LineNumberingPushbackReader(r); 426.1233 -} 426.1234 - 426.1235 -static public boolean isLineNumberingReader(Reader r){ 426.1236 - return r instanceof LineNumberingPushbackReader; 426.1237 -} 426.1238 - 426.1239 -static public String resolveClassNameInContext(String className){ 426.1240 - //todo - look up in context var 426.1241 - return className; 426.1242 -} 426.1243 - 426.1244 -static public boolean suppressRead(){ 426.1245 - //todo - look up in suppress-read var 426.1246 - return false; 426.1247 -} 426.1248 - 426.1249 -static public String printString(Object x){ 426.1250 - try { 426.1251 - StringWriter sw = new StringWriter(); 426.1252 - print(x, sw); 426.1253 - return sw.toString(); 426.1254 - } 426.1255 - catch(Exception e) { 426.1256 - throw new RuntimeException(e); 426.1257 - } 426.1258 -} 426.1259 - 426.1260 -static public Object readString(String s){ 426.1261 - PushbackReader r = new PushbackReader(new StringReader(s)); 426.1262 - try { 426.1263 - return LispReader.read(r, true, null, false); 426.1264 - } 426.1265 - catch(Exception e) { 426.1266 - throw new RuntimeException(e); 426.1267 - } 426.1268 -} 426.1269 - 426.1270 -static public void print(Object x, Writer w) throws Exception{ 426.1271 - //call multimethod 426.1272 - if(PRINT_INITIALIZED.isBound() && RT.booleanCast(PRINT_INITIALIZED.deref())) 426.1273 - PR_ON.invoke(x, w); 426.1274 -//* 426.1275 - else { 426.1276 - boolean readably = booleanCast(PRINT_READABLY.deref()); 426.1277 - if(x instanceof Obj) { 426.1278 - Obj o = (Obj) x; 426.1279 - if(RT.count(o.meta()) > 0 && 426.1280 - ((readably && booleanCast(PRINT_META.deref())) 426.1281 - || booleanCast(PRINT_DUP.deref()))) { 426.1282 - IPersistentMap meta = o.meta(); 426.1283 - w.write("#^"); 426.1284 - if(meta.count() == 1 && meta.containsKey(TAG_KEY)) 426.1285 - print(meta.valAt(TAG_KEY), w); 426.1286 - else 426.1287 - print(meta, w); 426.1288 - w.write(' '); 426.1289 - } 426.1290 - } 426.1291 - if(x == null) 426.1292 - w.write("nil"); 426.1293 - else if(x instanceof ISeq || x instanceof IPersistentList) { 426.1294 - w.write('('); 426.1295 - printInnerSeq(seq(x), w); 426.1296 - w.write(')'); 426.1297 - } 426.1298 - else if(x instanceof String) { 426.1299 - String s = (String) x; 426.1300 - if(!readably) 426.1301 - w.write(s); 426.1302 - else { 426.1303 - w.write('"'); 426.1304 - //w.write(x.toString()); 426.1305 - for(int i = 0; i < s.length(); i++) { 426.1306 - char c = s.charAt(i); 426.1307 - switch(c) { 426.1308 - case '\n': 426.1309 - w.write("\\n"); 426.1310 - break; 426.1311 - case '\t': 426.1312 - w.write("\\t"); 426.1313 - break; 426.1314 - case '\r': 426.1315 - w.write("\\r"); 426.1316 - break; 426.1317 - case '"': 426.1318 - w.write("\\\""); 426.1319 - break; 426.1320 - case '\\': 426.1321 - w.write("\\\\"); 426.1322 - break; 426.1323 - case '\f': 426.1324 - w.write("\\f"); 426.1325 - break; 426.1326 - case '\b': 426.1327 - w.write("\\b"); 426.1328 - break; 426.1329 - default: 426.1330 - w.write(c); 426.1331 - } 426.1332 - } 426.1333 - w.write('"'); 426.1334 - } 426.1335 - } 426.1336 - else if(x instanceof IPersistentMap) { 426.1337 - w.write('{'); 426.1338 - for(ISeq s = seq(x); s != null; s = s.next()) { 426.1339 - IMapEntry e = (IMapEntry) s.first(); 426.1340 - print(e.key(), w); 426.1341 - w.write(' '); 426.1342 - print(e.val(), w); 426.1343 - if(s.next() != null) 426.1344 - w.write(", "); 426.1345 - } 426.1346 - w.write('}'); 426.1347 - } 426.1348 - else if(x instanceof IPersistentVector) { 426.1349 - IPersistentVector a = (IPersistentVector) x; 426.1350 - w.write('['); 426.1351 - for(int i = 0; i < a.count(); i++) { 426.1352 - print(a.nth(i), w); 426.1353 - if(i < a.count() - 1) 426.1354 - w.write(' '); 426.1355 - } 426.1356 - w.write(']'); 426.1357 - } 426.1358 - else if(x instanceof IPersistentSet) { 426.1359 - w.write("#{"); 426.1360 - for(ISeq s = seq(x); s != null; s = s.next()) { 426.1361 - print(s.first(), w); 426.1362 - if(s.next() != null) 426.1363 - w.write(" "); 426.1364 - } 426.1365 - w.write('}'); 426.1366 - } 426.1367 - else if(x instanceof Character) { 426.1368 - char c = ((Character) x).charValue(); 426.1369 - if(!readably) 426.1370 - w.write(c); 426.1371 - else { 426.1372 - w.write('\\'); 426.1373 - switch(c) { 426.1374 - case '\n': 426.1375 - w.write("newline"); 426.1376 - break; 426.1377 - case '\t': 426.1378 - w.write("tab"); 426.1379 - break; 426.1380 - case ' ': 426.1381 - w.write("space"); 426.1382 - break; 426.1383 - case '\b': 426.1384 - w.write("backspace"); 426.1385 - break; 426.1386 - case '\f': 426.1387 - w.write("formfeed"); 426.1388 - break; 426.1389 - case '\r': 426.1390 - w.write("return"); 426.1391 - break; 426.1392 - default: 426.1393 - w.write(c); 426.1394 - } 426.1395 - } 426.1396 - } 426.1397 - else if(x instanceof Class) { 426.1398 - w.write("#="); 426.1399 - w.write(((Class) x).getName()); 426.1400 - } 426.1401 - else if(x instanceof BigDecimal && readably) { 426.1402 - w.write(x.toString()); 426.1403 - w.write('M'); 426.1404 - } 426.1405 - else if(x instanceof Var) { 426.1406 - Var v = (Var) x; 426.1407 - w.write("#=(var " + v.ns.name + "/" + v.sym + ")"); 426.1408 - } 426.1409 - else if(x instanceof Pattern) { 426.1410 - Pattern p = (Pattern) x; 426.1411 - w.write("#\"" + p.pattern() + "\""); 426.1412 - } 426.1413 - else w.write(x.toString()); 426.1414 - } 426.1415 - //*/ 426.1416 -} 426.1417 - 426.1418 -private static void printInnerSeq(ISeq x, Writer w) throws Exception{ 426.1419 - for(ISeq s = x; s != null; s = s.next()) { 426.1420 - print(s.first(), w); 426.1421 - if(s.next() != null) 426.1422 - w.write(' '); 426.1423 - } 426.1424 -} 426.1425 - 426.1426 -static public void formatAesthetic(Writer w, Object obj) throws IOException{ 426.1427 - if(obj == null) 426.1428 - w.write("null"); 426.1429 - else 426.1430 - w.write(obj.toString()); 426.1431 -} 426.1432 - 426.1433 -static public void formatStandard(Writer w, Object obj) throws IOException{ 426.1434 - if(obj == null) 426.1435 - w.write("null"); 426.1436 - else if(obj instanceof String) { 426.1437 - w.write('"'); 426.1438 - w.write((String) obj); 426.1439 - w.write('"'); 426.1440 - } 426.1441 - else if(obj instanceof Character) { 426.1442 - w.write('\\'); 426.1443 - char c = ((Character) obj).charValue(); 426.1444 - switch(c) { 426.1445 - case '\n': 426.1446 - w.write("newline"); 426.1447 - break; 426.1448 - case '\t': 426.1449 - w.write("tab"); 426.1450 - break; 426.1451 - case ' ': 426.1452 - w.write("space"); 426.1453 - break; 426.1454 - case '\b': 426.1455 - w.write("backspace"); 426.1456 - break; 426.1457 - case '\f': 426.1458 - w.write("formfeed"); 426.1459 - break; 426.1460 - default: 426.1461 - w.write(c); 426.1462 - } 426.1463 - } 426.1464 - else 426.1465 - w.write(obj.toString()); 426.1466 -} 426.1467 - 426.1468 -static public Object format(Object o, String s, Object... args) throws Exception{ 426.1469 - Writer w; 426.1470 - if(o == null) 426.1471 - w = new StringWriter(); 426.1472 - else if(Util.equals(o, T)) 426.1473 - w = (Writer) OUT.deref(); 426.1474 - else 426.1475 - w = (Writer) o; 426.1476 - doFormat(w, s, ArraySeq.create(args)); 426.1477 - if(o == null) 426.1478 - return w.toString(); 426.1479 - return null; 426.1480 -} 426.1481 - 426.1482 -static public ISeq doFormat(Writer w, String s, ISeq args) throws Exception{ 426.1483 - for(int i = 0; i < s.length();) { 426.1484 - char c = s.charAt(i++); 426.1485 - switch(Character.toLowerCase(c)) { 426.1486 - case '~': 426.1487 - char d = s.charAt(i++); 426.1488 - switch(Character.toLowerCase(d)) { 426.1489 - case '%': 426.1490 - w.write('\n'); 426.1491 - break; 426.1492 - case 't': 426.1493 - w.write('\t'); 426.1494 - break; 426.1495 - case 'a': 426.1496 - if(args == null) 426.1497 - throw new IllegalArgumentException("Missing argument"); 426.1498 - RT.formatAesthetic(w, RT.first(args)); 426.1499 - args = RT.next(args); 426.1500 - break; 426.1501 - case 's': 426.1502 - if(args == null) 426.1503 - throw new IllegalArgumentException("Missing argument"); 426.1504 - RT.formatStandard(w, RT.first(args)); 426.1505 - args = RT.next(args); 426.1506 - break; 426.1507 - case '{': 426.1508 - int j = s.indexOf("~}", i); //note - does not nest 426.1509 - if(j == -1) 426.1510 - throw new IllegalArgumentException("Missing ~}"); 426.1511 - String subs = s.substring(i, j); 426.1512 - for(ISeq sargs = RT.seq(RT.first(args)); sargs != null;) 426.1513 - sargs = doFormat(w, subs, sargs); 426.1514 - args = RT.next(args); 426.1515 - i = j + 2; //skip ~} 426.1516 - break; 426.1517 - case '^': 426.1518 - if(args == null) 426.1519 - return null; 426.1520 - break; 426.1521 - case '~': 426.1522 - w.write('~'); 426.1523 - break; 426.1524 - default: 426.1525 - throw new IllegalArgumentException("Unsupported ~ directive: " + d); 426.1526 - } 426.1527 - break; 426.1528 - default: 426.1529 - w.write(c); 426.1530 - } 426.1531 - } 426.1532 - return args; 426.1533 -} 426.1534 -///////////////////////////////// values ////////////////////////// 426.1535 - 426.1536 -static public Object[] setValues(Object... vals){ 426.1537 - //ThreadLocalData.setValues(vals); 426.1538 - if(vals.length > 0) 426.1539 - return vals;//[0]; 426.1540 - return null; 426.1541 -} 426.1542 - 426.1543 - 426.1544 -static public ClassLoader makeClassLoader(){ 426.1545 - return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction(){ 426.1546 - public Object run(){ 426.1547 - try{ 426.1548 - Var.pushThreadBindings(RT.map(USE_CONTEXT_CLASSLOADER, RT.T)); 426.1549 -// getRootClassLoader(); 426.1550 - return new DynamicClassLoader(baseLoader()); 426.1551 - } 426.1552 - finally{ 426.1553 - Var.popThreadBindings(); 426.1554 - } 426.1555 - } 426.1556 - }); 426.1557 -} 426.1558 - 426.1559 -static public ClassLoader baseLoader(){ 426.1560 - if(Compiler.LOADER.isBound()) 426.1561 - return (ClassLoader) Compiler.LOADER.deref(); 426.1562 - else if(booleanCast(USE_CONTEXT_CLASSLOADER.deref())) 426.1563 - return Thread.currentThread().getContextClassLoader(); 426.1564 - return Compiler.class.getClassLoader(); 426.1565 -} 426.1566 - 426.1567 -static public Class classForName(String name) throws ClassNotFoundException{ 426.1568 - 426.1569 - return Class.forName(name, true, baseLoader()); 426.1570 -} 426.1571 - 426.1572 -static public Class loadClassForName(String name) throws ClassNotFoundException{ 426.1573 - try 426.1574 - { 426.1575 - Class.forName(name, false, baseLoader()); 426.1576 - } 426.1577 - catch(ClassNotFoundException e) 426.1578 - { 426.1579 - return null; 426.1580 - } 426.1581 - return Class.forName(name, true, baseLoader()); 426.1582 -} 426.1583 - 426.1584 -static public float aget(float[] xs, int i){ 426.1585 - return xs[i]; 426.1586 -} 426.1587 - 426.1588 -static public float aset(float[] xs, int i, float v){ 426.1589 - xs[i] = v; 426.1590 - return v; 426.1591 -} 426.1592 - 426.1593 -static public int alength(float[] xs){ 426.1594 - return xs.length; 426.1595 -} 426.1596 - 426.1597 -static public float[] aclone(float[] xs){ 426.1598 - return xs.clone(); 426.1599 -} 426.1600 - 426.1601 -static public double aget(double[] xs, int i){ 426.1602 - return xs[i]; 426.1603 -} 426.1604 - 426.1605 -static public double aset(double[] xs, int i, double v){ 426.1606 - xs[i] = v; 426.1607 - return v; 426.1608 -} 426.1609 - 426.1610 -static public int alength(double[] xs){ 426.1611 - return xs.length; 426.1612 -} 426.1613 - 426.1614 -static public double[] aclone(double[] xs){ 426.1615 - return xs.clone(); 426.1616 -} 426.1617 - 426.1618 -static public int aget(int[] xs, int i){ 426.1619 - return xs[i]; 426.1620 -} 426.1621 - 426.1622 -static public int aset(int[] xs, int i, int v){ 426.1623 - xs[i] = v; 426.1624 - return v; 426.1625 -} 426.1626 - 426.1627 -static public int alength(int[] xs){ 426.1628 - return xs.length; 426.1629 -} 426.1630 - 426.1631 -static public int[] aclone(int[] xs){ 426.1632 - return xs.clone(); 426.1633 -} 426.1634 - 426.1635 -static public long aget(long[] xs, int i){ 426.1636 - return xs[i]; 426.1637 -} 426.1638 - 426.1639 -static public long aset(long[] xs, int i, long v){ 426.1640 - xs[i] = v; 426.1641 - return v; 426.1642 -} 426.1643 - 426.1644 -static public int alength(long[] xs){ 426.1645 - return xs.length; 426.1646 -} 426.1647 - 426.1648 -static public long[] aclone(long[] xs){ 426.1649 - return xs.clone(); 426.1650 -} 426.1651 - 426.1652 -static public char aget(char[] xs, int i){ 426.1653 - return xs[i]; 426.1654 -} 426.1655 - 426.1656 -static public char aset(char[] xs, int i, char v){ 426.1657 - xs[i] = v; 426.1658 - return v; 426.1659 -} 426.1660 - 426.1661 -static public int alength(char[] xs){ 426.1662 - return xs.length; 426.1663 -} 426.1664 - 426.1665 -static public char[] aclone(char[] xs){ 426.1666 - return xs.clone(); 426.1667 -} 426.1668 - 426.1669 -static public byte aget(byte[] xs, int i){ 426.1670 - return xs[i]; 426.1671 -} 426.1672 - 426.1673 -static public byte aset(byte[] xs, int i, byte v){ 426.1674 - xs[i] = v; 426.1675 - return v; 426.1676 -} 426.1677 - 426.1678 -static public int alength(byte[] xs){ 426.1679 - return xs.length; 426.1680 -} 426.1681 - 426.1682 -static public byte[] aclone(byte[] xs){ 426.1683 - return xs.clone(); 426.1684 -} 426.1685 - 426.1686 -static public short aget(short[] xs, int i){ 426.1687 - return xs[i]; 426.1688 -} 426.1689 - 426.1690 -static public short aset(short[] xs, int i, short v){ 426.1691 - xs[i] = v; 426.1692 - return v; 426.1693 -} 426.1694 - 426.1695 -static public int alength(short[] xs){ 426.1696 - return xs.length; 426.1697 -} 426.1698 - 426.1699 -static public short[] aclone(short[] xs){ 426.1700 - return xs.clone(); 426.1701 -} 426.1702 - 426.1703 -static public boolean aget(boolean[] xs, int i){ 426.1704 - return xs[i]; 426.1705 -} 426.1706 - 426.1707 -static public boolean aset(boolean[] xs, int i, boolean v){ 426.1708 - xs[i] = v; 426.1709 - return v; 426.1710 -} 426.1711 - 426.1712 -static public int alength(boolean[] xs){ 426.1713 - return xs.length; 426.1714 -} 426.1715 - 426.1716 -static public boolean[] aclone(boolean[] xs){ 426.1717 - return xs.clone(); 426.1718 -} 426.1719 - 426.1720 -static public Object aget(Object[] xs, int i){ 426.1721 - return xs[i]; 426.1722 -} 426.1723 - 426.1724 -static public Object aset(Object[] xs, int i, Object v){ 426.1725 - xs[i] = v; 426.1726 - return v; 426.1727 -} 426.1728 - 426.1729 -static public int alength(Object[] xs){ 426.1730 - return xs.length; 426.1731 -} 426.1732 - 426.1733 -static public Object[] aclone(Object[] xs){ 426.1734 - return xs.clone(); 426.1735 -} 426.1736 - 426.1737 - 426.1738 -}
427.1 --- a/src/clojure/lang/Range.java Sat Aug 21 06:25:44 2010 -0400 427.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 427.3 @@ -1,64 +0,0 @@ 427.4 -/** 427.5 - * Copyright (c) Rich Hickey. All rights reserved. 427.6 - * The use and distribution terms for this software are covered by the 427.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 427.8 - * which can be found in the file epl-v10.html at the root of this distribution. 427.9 - * By using this software in any fashion, you are agreeing to be bound by 427.10 - * the terms of this license. 427.11 - * You must not remove this notice, or any other, from this software. 427.12 - **/ 427.13 - 427.14 -/* rich Apr 1, 2008 */ 427.15 - 427.16 -package clojure.lang; 427.17 - 427.18 -public class Range extends ASeq implements IReduce, Counted{ 427.19 -final int end; 427.20 -final int n; 427.21 - 427.22 -public Range(int start, int end){ 427.23 - this.end = end; 427.24 - this.n = start; 427.25 -} 427.26 - 427.27 -public Range(IPersistentMap meta, int start, int end){ 427.28 - super(meta); 427.29 - this.end = end; 427.30 - this.n = start; 427.31 -} 427.32 - 427.33 -public Obj withMeta(IPersistentMap meta){ 427.34 - if(meta == meta()) 427.35 - return this; 427.36 - return new Range(meta(), end, n); 427.37 -} 427.38 - 427.39 -public Object first(){ 427.40 - return n; 427.41 -} 427.42 - 427.43 -public ISeq next(){ 427.44 - if(n < end-1) 427.45 - return new Range(_meta, n + 1, end); 427.46 - return null; 427.47 -} 427.48 - 427.49 -public Object reduce(IFn f) throws Exception{ 427.50 - Object ret = n; 427.51 - for(int x = n+1;x < end;x++) 427.52 - ret = f.invoke(ret, x); 427.53 - return ret; 427.54 -} 427.55 - 427.56 -public Object reduce(IFn f, Object start) throws Exception{ 427.57 - Object ret = f.invoke(start,n); 427.58 - for(int x = n+1;x < end;x++) 427.59 - ret = f.invoke(ret, x); 427.60 - return ret; 427.61 -} 427.62 - 427.63 -public int count() { 427.64 - return end - n; 427.65 - } 427.66 - 427.67 -}
428.1 --- a/src/clojure/lang/Ratio.java Sat Aug 21 06:25:44 2010 -0400 428.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 428.3 @@ -1,78 +0,0 @@ 428.4 -/** 428.5 - * Copyright (c) Rich Hickey. All rights reserved. 428.6 - * The use and distribution terms for this software are covered by the 428.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 428.8 - * which can be found in the file epl-v10.html at the root of this distribution. 428.9 - * By using this software in any fashion, you are agreeing to be bound by 428.10 - * the terms of this license. 428.11 - * You must not remove this notice, or any other, from this software. 428.12 - **/ 428.13 - 428.14 -/* rich Mar 31, 2008 */ 428.15 - 428.16 -package clojure.lang; 428.17 - 428.18 -import java.math.BigInteger; 428.19 -import java.math.BigDecimal; 428.20 -import java.math.MathContext; 428.21 - 428.22 -public class Ratio extends Number implements Comparable{ 428.23 -final public BigInteger numerator; 428.24 -final public BigInteger denominator; 428.25 - 428.26 -public Ratio(BigInteger numerator, BigInteger denominator){ 428.27 - this.numerator = numerator; 428.28 - this.denominator = denominator; 428.29 -} 428.30 - 428.31 -public boolean equals(Object arg0){ 428.32 - return arg0 != null 428.33 - && arg0 instanceof Ratio 428.34 - && ((Ratio) arg0).numerator.equals(numerator) 428.35 - && ((Ratio) arg0).denominator.equals(denominator); 428.36 -} 428.37 - 428.38 -public int hashCode(){ 428.39 - return numerator.hashCode() ^ denominator.hashCode(); 428.40 -} 428.41 - 428.42 -public String toString(){ 428.43 - return numerator.toString() + "/" + denominator.toString(); 428.44 -} 428.45 - 428.46 -public int intValue(){ 428.47 - return (int) doubleValue(); 428.48 -} 428.49 - 428.50 -public long longValue(){ 428.51 - return bigIntegerValue().longValue(); 428.52 -} 428.53 - 428.54 -public float floatValue(){ 428.55 - return (float)doubleValue(); 428.56 -} 428.57 - 428.58 -public double doubleValue(){ 428.59 - return decimalValue(MathContext.DECIMAL64).doubleValue(); 428.60 -} 428.61 - 428.62 -public BigDecimal decimalValue(){ 428.63 - return decimalValue(MathContext.UNLIMITED); 428.64 -} 428.65 - 428.66 -public BigDecimal decimalValue(MathContext mc){ 428.67 - BigDecimal numerator = new BigDecimal(this.numerator); 428.68 - BigDecimal denominator = new BigDecimal(this.denominator); 428.69 - 428.70 - return numerator.divide(denominator, mc); 428.71 -} 428.72 - 428.73 -public BigInteger bigIntegerValue(){ 428.74 - return numerator.divide(denominator); 428.75 -} 428.76 - 428.77 -public int compareTo(Object o){ 428.78 - Number other = (Number)o; 428.79 - return Numbers.compare(this, other); 428.80 -} 428.81 -}
429.1 --- a/src/clojure/lang/Ref.java Sat Aug 21 06:25:44 2010 -0400 429.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 429.3 @@ -1,379 +0,0 @@ 429.4 -/** 429.5 - * Copyright (c) Rich Hickey. All rights reserved. 429.6 - * The use and distribution terms for this software are covered by the 429.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 429.8 - * which can be found in the file epl-v10.html at the root of this distribution. 429.9 - * By using this software in any fashion, you are agreeing to be bound by 429.10 - * the terms of this license. 429.11 - * You must not remove this notice, or any other, from this software. 429.12 - **/ 429.13 - 429.14 -/* rich Jul 25, 2007 */ 429.15 - 429.16 -package clojure.lang; 429.17 - 429.18 -import java.util.concurrent.atomic.AtomicInteger; 429.19 -import java.util.concurrent.atomic.AtomicLong; 429.20 -import java.util.concurrent.locks.ReentrantReadWriteLock; 429.21 - 429.22 -public class Ref extends ARef implements IFn, Comparable<Ref>, IRef{ 429.23 - public int compareTo(Ref ref) { 429.24 - if(this.id == ref.id) 429.25 - return 0; 429.26 - else if(this.id < ref.id) 429.27 - return -1; 429.28 - else 429.29 - return 1; 429.30 - } 429.31 - 429.32 -public int getMinHistory(){ 429.33 - return minHistory; 429.34 -} 429.35 - 429.36 -public Ref setMinHistory(int minHistory){ 429.37 - this.minHistory = minHistory; 429.38 - return this; 429.39 -} 429.40 - 429.41 -public int getMaxHistory(){ 429.42 - return maxHistory; 429.43 -} 429.44 - 429.45 -public Ref setMaxHistory(int maxHistory){ 429.46 - this.maxHistory = maxHistory; 429.47 - return this; 429.48 -} 429.49 - 429.50 -public static class TVal{ 429.51 - Object val; 429.52 - long point; 429.53 - long msecs; 429.54 - TVal prior; 429.55 - TVal next; 429.56 - 429.57 - TVal(Object val, long point, long msecs, TVal prior){ 429.58 - this.val = val; 429.59 - this.point = point; 429.60 - this.msecs = msecs; 429.61 - this.prior = prior; 429.62 - this.next = prior.next; 429.63 - this.prior.next = this; 429.64 - this.next.prior = this; 429.65 - } 429.66 - 429.67 - TVal(Object val, long point, long msecs){ 429.68 - this.val = val; 429.69 - this.point = point; 429.70 - this.msecs = msecs; 429.71 - this.next = this; 429.72 - this.prior = this; 429.73 - } 429.74 - 429.75 -} 429.76 - 429.77 -TVal tvals; 429.78 -final AtomicInteger faults; 429.79 -final ReentrantReadWriteLock lock; 429.80 -LockingTransaction.Info tinfo; 429.81 -//IFn validator; 429.82 -final long id; 429.83 - 429.84 -volatile int minHistory = 0; 429.85 -volatile int maxHistory = 10; 429.86 - 429.87 -static final AtomicLong ids = new AtomicLong(); 429.88 - 429.89 -public Ref(Object initVal) throws Exception{ 429.90 - this(initVal, null); 429.91 -} 429.92 - 429.93 -public Ref(Object initVal,IPersistentMap meta) throws Exception{ 429.94 - super(meta); 429.95 - this.id = ids.getAndIncrement(); 429.96 - this.faults = new AtomicInteger(); 429.97 - this.lock = new ReentrantReadWriteLock(); 429.98 - tvals = new TVal(initVal, 0, System.currentTimeMillis()); 429.99 -} 429.100 - 429.101 -//the latest val 429.102 - 429.103 -// ok out of transaction 429.104 -Object currentVal(){ 429.105 - try 429.106 - { 429.107 - lock.readLock().lock(); 429.108 - if(tvals != null) 429.109 - return tvals.val; 429.110 - throw new IllegalStateException(this.toString() + " is unbound."); 429.111 - } 429.112 - finally 429.113 - { 429.114 - lock.readLock().unlock(); 429.115 - } 429.116 -} 429.117 - 429.118 -//* 429.119 - 429.120 -public Object deref(){ 429.121 - LockingTransaction t = LockingTransaction.getRunning(); 429.122 - if(t == null) 429.123 - return currentVal(); 429.124 - return t.doGet(this); 429.125 -} 429.126 - 429.127 -//void validate(IFn vf, Object val){ 429.128 -// try{ 429.129 -// if(vf != null && !RT.booleanCast(vf.invoke(val))) 429.130 -// throw new IllegalStateException("Invalid ref state"); 429.131 -// } 429.132 -// catch(RuntimeException re) 429.133 -// { 429.134 -// throw re; 429.135 -// } 429.136 -// catch(Exception e) 429.137 -// { 429.138 -// throw new IllegalStateException("Invalid ref state", e); 429.139 -// } 429.140 -//} 429.141 -// 429.142 -//public void setValidator(IFn vf){ 429.143 -// try 429.144 -// { 429.145 -// lock.writeLock().lock(); 429.146 -// validate(vf,currentVal()); 429.147 -// validator = vf; 429.148 -// } 429.149 -// finally 429.150 -// { 429.151 -// lock.writeLock().unlock(); 429.152 -// } 429.153 -//} 429.154 -// 429.155 -//public IFn getValidator(){ 429.156 -// try 429.157 -// { 429.158 -// lock.readLock().lock(); 429.159 -// return validator; 429.160 -// } 429.161 -// finally 429.162 -// { 429.163 -// lock.readLock().unlock(); 429.164 -// } 429.165 -//} 429.166 - 429.167 -public Object set(Object val){ 429.168 - return LockingTransaction.getEx().doSet(this, val); 429.169 -} 429.170 - 429.171 -public Object commute(IFn fn, ISeq args) throws Exception{ 429.172 - return LockingTransaction.getEx().doCommute(this, fn, args); 429.173 -} 429.174 - 429.175 -public Object alter(IFn fn, ISeq args) throws Exception{ 429.176 - LockingTransaction t = LockingTransaction.getEx(); 429.177 - return t.doSet(this, fn.applyTo(RT.cons(t.doGet(this), args))); 429.178 -} 429.179 - 429.180 -public void touch(){ 429.181 - LockingTransaction.getEx().doEnsure(this); 429.182 -} 429.183 - 429.184 -//*/ 429.185 -boolean isBound(){ 429.186 - try 429.187 - { 429.188 - lock.readLock().lock(); 429.189 - return tvals != null; 429.190 - } 429.191 - finally 429.192 - { 429.193 - lock.readLock().unlock(); 429.194 - } 429.195 -} 429.196 - 429.197 - 429.198 -public void trimHistory(){ 429.199 - try 429.200 - { 429.201 - lock.writeLock().lock(); 429.202 - if(tvals != null) 429.203 - { 429.204 - tvals.next = tvals; 429.205 - tvals.prior = tvals; 429.206 - } 429.207 - } 429.208 - finally 429.209 - { 429.210 - lock.writeLock().unlock(); 429.211 - } 429.212 -} 429.213 - 429.214 -public int getHistoryCount(){ 429.215 - try 429.216 - { 429.217 - lock.writeLock().lock(); 429.218 - return histCount(); 429.219 - } 429.220 - finally 429.221 - { 429.222 - lock.writeLock().unlock(); 429.223 - } 429.224 -} 429.225 - 429.226 -int histCount(){ 429.227 - if(tvals == null) 429.228 - return 0; 429.229 - else 429.230 - { 429.231 - int count = 0; 429.232 - for(TVal tv = tvals.next;tv != tvals;tv = tv.next) 429.233 - count++; 429.234 - return count; 429.235 - } 429.236 -} 429.237 - 429.238 -final public IFn fn(){ 429.239 - return (IFn) deref(); 429.240 -} 429.241 - 429.242 -public Object call() throws Exception{ 429.243 - return invoke(); 429.244 -} 429.245 - 429.246 -public void run(){ 429.247 - try 429.248 - { 429.249 - invoke(); 429.250 - } 429.251 - catch(Exception e) 429.252 - { 429.253 - throw new RuntimeException(e); 429.254 - } 429.255 -} 429.256 - 429.257 -public Object invoke() throws Exception{ 429.258 - return fn().invoke(); 429.259 -} 429.260 - 429.261 -public Object invoke(Object arg1) throws Exception{ 429.262 - return fn().invoke(arg1); 429.263 -} 429.264 - 429.265 -public Object invoke(Object arg1, Object arg2) throws Exception{ 429.266 - return fn().invoke(arg1, arg2); 429.267 -} 429.268 - 429.269 -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception{ 429.270 - return fn().invoke(arg1, arg2, arg3); 429.271 -} 429.272 - 429.273 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception{ 429.274 - return fn().invoke(arg1, arg2, arg3, arg4); 429.275 -} 429.276 - 429.277 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception{ 429.278 - return fn().invoke(arg1, arg2, arg3, arg4, arg5); 429.279 -} 429.280 - 429.281 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception{ 429.282 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6); 429.283 -} 429.284 - 429.285 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) 429.286 - throws Exception{ 429.287 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7); 429.288 -} 429.289 - 429.290 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.291 - Object arg8) throws Exception{ 429.292 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); 429.293 -} 429.294 - 429.295 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.296 - Object arg8, Object arg9) throws Exception{ 429.297 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); 429.298 -} 429.299 - 429.300 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.301 - Object arg8, Object arg9, Object arg10) throws Exception{ 429.302 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); 429.303 -} 429.304 - 429.305 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.306 - Object arg8, Object arg9, Object arg10, Object arg11) throws Exception{ 429.307 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); 429.308 -} 429.309 - 429.310 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.311 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception{ 429.312 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); 429.313 -} 429.314 - 429.315 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.316 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) 429.317 - throws Exception{ 429.318 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); 429.319 -} 429.320 - 429.321 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.322 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) 429.323 - throws Exception{ 429.324 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); 429.325 -} 429.326 - 429.327 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.328 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 429.329 - Object arg15) throws Exception{ 429.330 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); 429.331 -} 429.332 - 429.333 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.334 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 429.335 - Object arg15, Object arg16) throws Exception{ 429.336 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 429.337 - arg16); 429.338 -} 429.339 - 429.340 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.341 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 429.342 - Object arg15, Object arg16, Object arg17) throws Exception{ 429.343 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 429.344 - arg16, arg17); 429.345 -} 429.346 - 429.347 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.348 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 429.349 - Object arg15, Object arg16, Object arg17, Object arg18) throws Exception{ 429.350 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 429.351 - arg16, arg17, arg18); 429.352 -} 429.353 - 429.354 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.355 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 429.356 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception{ 429.357 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 429.358 - arg16, arg17, arg18, arg19); 429.359 -} 429.360 - 429.361 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.362 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 429.363 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20) 429.364 - throws Exception{ 429.365 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 429.366 - arg16, arg17, arg18, arg19, arg20); 429.367 -} 429.368 - 429.369 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 429.370 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 429.371 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20, 429.372 - Object... args) 429.373 - throws Exception{ 429.374 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 429.375 - arg16, arg17, arg18, arg19, arg20, args); 429.376 -} 429.377 - 429.378 -public Object applyTo(ISeq arglist) throws Exception{ 429.379 - return AFn.applyToHelper(this, arglist); 429.380 -} 429.381 - 429.382 -}
430.1 --- a/src/clojure/lang/Reflector.java Sat Aug 21 06:25:44 2010 -0400 430.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 430.3 @@ -1,451 +0,0 @@ 430.4 -/** 430.5 - * Copyright (c) Rich Hickey. All rights reserved. 430.6 - * The use and distribution terms for this software are covered by the 430.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 430.8 - * which can be found in the file epl-v10.html at the root of this distribution. 430.9 - * By using this software in any fashion, you are agreeing to be bound by 430.10 - * the terms of this license. 430.11 - * You must not remove this notice, or any other, from this software. 430.12 - **/ 430.13 - 430.14 -/* rich Apr 19, 2006 */ 430.15 - 430.16 -package clojure.lang; 430.17 - 430.18 -import java.lang.reflect.*; 430.19 -import java.util.ArrayList; 430.20 -import java.util.Iterator; 430.21 -import java.util.List; 430.22 -import java.util.Arrays; 430.23 - 430.24 -public class Reflector{ 430.25 - 430.26 -public static Object invokeInstanceMethod(Object target, String methodName, Object[] args) throws Exception{ 430.27 - try 430.28 - { 430.29 - Class c = target.getClass(); 430.30 - List methods = getMethods(c, args.length, methodName, false); 430.31 - return invokeMatchingMethod(methodName, methods, target, args); 430.32 - } 430.33 - catch(InvocationTargetException e) 430.34 - { 430.35 - if(e.getCause() instanceof Exception) 430.36 - throw (Exception) e.getCause(); 430.37 - else if(e.getCause() instanceof Error) 430.38 - throw (Error) e.getCause(); 430.39 - throw e; 430.40 - } 430.41 -} 430.42 - 430.43 -private static String noMethodReport(String methodName, Object target){ 430.44 - return "No matching method found: " + methodName 430.45 - + (target==null?"":" for " + target.getClass()); 430.46 -} 430.47 -static Object invokeMatchingMethod(String methodName, List methods, Object target, Object[] args) 430.48 - throws Exception{ 430.49 - Method m = null; 430.50 - Object[] boxedArgs = null; 430.51 - if(methods.isEmpty()) 430.52 - { 430.53 - throw new IllegalArgumentException(noMethodReport(methodName,target)); 430.54 - } 430.55 - else if(methods.size() == 1) 430.56 - { 430.57 - m = (Method) methods.get(0); 430.58 - boxedArgs = boxArgs(m.getParameterTypes(), args); 430.59 - } 430.60 - else //overloaded w/same arity 430.61 - { 430.62 - Method foundm = null; 430.63 - for(Iterator i = methods.iterator(); i.hasNext();) 430.64 - { 430.65 - m = (Method) i.next(); 430.66 - 430.67 - Class[] params = m.getParameterTypes(); 430.68 - if(isCongruent(params, args)) 430.69 - { 430.70 - if(foundm == null || Compiler.subsumes(params, foundm.getParameterTypes())) 430.71 - { 430.72 - foundm = m; 430.73 - boxedArgs = boxArgs(params, args); 430.74 - } 430.75 - } 430.76 - } 430.77 - m = foundm; 430.78 - } 430.79 - if(m == null) 430.80 - throw new IllegalArgumentException(noMethodReport(methodName,target)); 430.81 - 430.82 - if(!Modifier.isPublic(m.getDeclaringClass().getModifiers())) 430.83 - { 430.84 - //public method of non-public class, try to find it in hierarchy 430.85 - Method oldm = m; 430.86 - m = getAsMethodOfPublicBase(m.getDeclaringClass(), m); 430.87 - if(m == null) 430.88 - throw new IllegalArgumentException("Can't call public method of non-public class: " + 430.89 - oldm.toString()); 430.90 - } 430.91 - try 430.92 - { 430.93 - return prepRet(m.invoke(target, boxedArgs)); 430.94 - } 430.95 - catch(InvocationTargetException e) 430.96 - { 430.97 - if(e.getCause() instanceof Exception) 430.98 - throw (Exception) e.getCause(); 430.99 - else if(e.getCause() instanceof Error) 430.100 - throw (Error) e.getCause(); 430.101 - throw e; 430.102 - } 430.103 - 430.104 -} 430.105 - 430.106 -public static Method getAsMethodOfPublicBase(Class c, Method m){ 430.107 - for(Class iface : c.getInterfaces()) 430.108 - { 430.109 - for(Method im : iface.getMethods()) 430.110 - { 430.111 - if(im.getName().equals(m.getName()) 430.112 - && Arrays.equals(m.getParameterTypes(), im.getParameterTypes())) 430.113 - { 430.114 - return im; 430.115 - } 430.116 - } 430.117 - } 430.118 - Class sc = c.getSuperclass(); 430.119 - if(sc == null) 430.120 - return null; 430.121 - for(Method scm : sc.getMethods()) 430.122 - { 430.123 - if(scm.getName().equals(m.getName()) 430.124 - && Arrays.equals(m.getParameterTypes(), scm.getParameterTypes()) 430.125 - && Modifier.isPublic(scm.getDeclaringClass().getModifiers())) 430.126 - { 430.127 - return scm; 430.128 - } 430.129 - } 430.130 - return getAsMethodOfPublicBase(sc, m); 430.131 -} 430.132 - 430.133 -public static Object invokeConstructor(Class c, Object[] args) throws Exception{ 430.134 - try 430.135 - { 430.136 - Constructor[] allctors = c.getConstructors(); 430.137 - ArrayList ctors = new ArrayList(); 430.138 - for(int i = 0; i < allctors.length; i++) 430.139 - { 430.140 - Constructor ctor = allctors[i]; 430.141 - if(ctor.getParameterTypes().length == args.length) 430.142 - ctors.add(ctor); 430.143 - } 430.144 - if(ctors.isEmpty()) 430.145 - { 430.146 - throw new IllegalArgumentException("No matching ctor found" 430.147 - + " for " + c); 430.148 - } 430.149 - else if(ctors.size() == 1) 430.150 - { 430.151 - Constructor ctor = (Constructor) ctors.get(0); 430.152 - return ctor.newInstance(boxArgs(ctor.getParameterTypes(), args)); 430.153 - } 430.154 - else //overloaded w/same arity 430.155 - { 430.156 - for(Iterator iterator = ctors.iterator(); iterator.hasNext();) 430.157 - { 430.158 - Constructor ctor = (Constructor) iterator.next(); 430.159 - Class[] params = ctor.getParameterTypes(); 430.160 - if(isCongruent(params, args)) 430.161 - { 430.162 - Object[] boxedArgs = boxArgs(params, args); 430.163 - return ctor.newInstance(boxedArgs); 430.164 - } 430.165 - } 430.166 - throw new IllegalArgumentException("No matching ctor found" 430.167 - + " for " + c); 430.168 - } 430.169 - } 430.170 - catch(InvocationTargetException e) 430.171 - { 430.172 - if(e.getCause() instanceof Exception) 430.173 - throw (Exception) e.getCause(); 430.174 - else if(e.getCause() instanceof Error) 430.175 - throw (Error) e.getCause(); 430.176 - throw e; 430.177 - } 430.178 -} 430.179 - 430.180 -public static Object invokeStaticMethodVariadic(String className, String methodName, Object... args) throws Exception{ 430.181 - return invokeStaticMethod(className, methodName, args); 430.182 - 430.183 -} 430.184 - 430.185 -public static Object invokeStaticMethod(String className, String methodName, Object[] args) throws Exception{ 430.186 - Class c = RT.classForName(className); 430.187 - try 430.188 - { 430.189 - return invokeStaticMethod(c, methodName, args); 430.190 - } 430.191 - catch(InvocationTargetException e) 430.192 - { 430.193 - if(e.getCause() instanceof Exception) 430.194 - throw (Exception) e.getCause(); 430.195 - else if(e.getCause() instanceof Error) 430.196 - throw (Error) e.getCause(); 430.197 - throw e; 430.198 - } 430.199 -} 430.200 - 430.201 -public static Object invokeStaticMethod(Class c, String methodName, Object[] args) throws Exception{ 430.202 - if(methodName.equals("new")) 430.203 - return invokeConstructor(c, args); 430.204 - List methods = getMethods(c, args.length, methodName, true); 430.205 - return invokeMatchingMethod(methodName, methods, null, args); 430.206 -} 430.207 - 430.208 -public static Object getStaticField(String className, String fieldName) throws Exception{ 430.209 - Class c = RT.classForName(className); 430.210 - return getStaticField(c, fieldName); 430.211 -} 430.212 - 430.213 -public static Object getStaticField(Class c, String fieldName) throws Exception{ 430.214 -// if(fieldName.equals("class")) 430.215 -// return c; 430.216 - Field f = getField(c, fieldName, true); 430.217 - if(f != null) 430.218 - { 430.219 - return prepRet(f.get(null)); 430.220 - } 430.221 - throw new IllegalArgumentException("No matching field found: " + fieldName 430.222 - + " for " + c); 430.223 -} 430.224 - 430.225 -public static Object setStaticField(String className, String fieldName, Object val) throws Exception{ 430.226 - Class c = RT.classForName(className); 430.227 - return setStaticField(c, fieldName, val); 430.228 -} 430.229 - 430.230 -public static Object setStaticField(Class c, String fieldName, Object val) throws Exception{ 430.231 - Field f = getField(c, fieldName, true); 430.232 - if(f != null) 430.233 - { 430.234 - f.set(null, boxArg(f.getType(), val)); 430.235 - return val; 430.236 - } 430.237 - throw new IllegalArgumentException("No matching field found: " + fieldName 430.238 - + " for " + c); 430.239 -} 430.240 - 430.241 -public static Object getInstanceField(Object target, String fieldName) throws Exception{ 430.242 - Class c = target.getClass(); 430.243 - Field f = getField(c, fieldName, false); 430.244 - if(f != null) 430.245 - { 430.246 - return prepRet(f.get(target)); 430.247 - } 430.248 - throw new IllegalArgumentException("No matching field found: " + fieldName 430.249 - + " for " + target.getClass()); 430.250 -} 430.251 - 430.252 -public static Object setInstanceField(Object target, String fieldName, Object val) throws Exception{ 430.253 - Class c = target.getClass(); 430.254 - Field f = getField(c, fieldName, false); 430.255 - if(f != null) 430.256 - { 430.257 - f.set(target, boxArg(f.getType(), val)); 430.258 - return val; 430.259 - } 430.260 - throw new IllegalArgumentException("No matching field found: " + fieldName 430.261 - + " for " + target.getClass()); 430.262 -} 430.263 - 430.264 -public static Object invokeNoArgInstanceMember(Object target, String name) throws Exception{ 430.265 - //favor method over field 430.266 - List meths = getMethods(target.getClass(), 0, name, false); 430.267 - if(meths.size() > 0) 430.268 - return invokeMatchingMethod(name, meths, target, RT.EMPTY_ARRAY); 430.269 - else 430.270 - return getInstanceField(target, name); 430.271 -} 430.272 - 430.273 -public static Object invokeInstanceMember(Object target, String name) throws Exception{ 430.274 - //check for field first 430.275 - Class c = target.getClass(); 430.276 - Field f = getField(c, name, false); 430.277 - if(f != null) //field get 430.278 - { 430.279 - return prepRet(f.get(target)); 430.280 - } 430.281 - return invokeInstanceMethod(target, name, RT.EMPTY_ARRAY); 430.282 -} 430.283 - 430.284 -public static Object invokeInstanceMember(String name, Object target, Object arg1) throws Exception{ 430.285 - //check for field first 430.286 - Class c = target.getClass(); 430.287 - Field f = getField(c, name, false); 430.288 - if(f != null) //field set 430.289 - { 430.290 - f.set(target, boxArg(f.getType(), arg1)); 430.291 - return arg1; 430.292 - } 430.293 - return invokeInstanceMethod(target, name, new Object[]{arg1}); 430.294 -} 430.295 - 430.296 -public static Object invokeInstanceMember(String name, Object target, Object... args) throws Exception{ 430.297 - return invokeInstanceMethod(target, name, args); 430.298 -} 430.299 - 430.300 - 430.301 -static public Field getField(Class c, String name, boolean getStatics){ 430.302 - Field[] allfields = c.getFields(); 430.303 - for(int i = 0; i < allfields.length; i++) 430.304 - { 430.305 - if(name.equals(allfields[i].getName()) 430.306 - && Modifier.isStatic(allfields[i].getModifiers()) == getStatics) 430.307 - return allfields[i]; 430.308 - } 430.309 - return null; 430.310 -} 430.311 - 430.312 -static public List getMethods(Class c, int arity, String name, boolean getStatics){ 430.313 - Method[] allmethods = c.getMethods(); 430.314 - ArrayList methods = new ArrayList(); 430.315 - ArrayList bridgeMethods = new ArrayList(); 430.316 - for(int i = 0; i < allmethods.length; i++) 430.317 - { 430.318 - Method method = allmethods[i]; 430.319 - if(name.equals(method.getName()) 430.320 - && Modifier.isStatic(method.getModifiers()) == getStatics 430.321 - && method.getParameterTypes().length == arity) 430.322 - { 430.323 - try 430.324 - { 430.325 - if(method.isBridge() 430.326 - && c.getMethod(method.getName(), method.getParameterTypes()) 430.327 - .equals(method)) 430.328 - bridgeMethods.add(method); 430.329 - else 430.330 - methods.add(method); 430.331 - } 430.332 - catch(NoSuchMethodException e) 430.333 - { 430.334 - } 430.335 - } 430.336 -// && (!method.isBridge() 430.337 -// || (c == StringBuilder.class && 430.338 -// c.getMethod(method.getName(), method.getParameterTypes()) 430.339 -// .equals(method)))) 430.340 -// { 430.341 -// methods.add(allmethods[i]); 430.342 -// } 430.343 - } 430.344 - 430.345 - if(methods.isEmpty()) 430.346 - methods.addAll(bridgeMethods); 430.347 - 430.348 - if(!getStatics && c.isInterface()) 430.349 - { 430.350 - allmethods = Object.class.getMethods(); 430.351 - for(int i = 0; i < allmethods.length; i++) 430.352 - { 430.353 - if(name.equals(allmethods[i].getName()) 430.354 - && Modifier.isStatic(allmethods[i].getModifiers()) == getStatics 430.355 - && allmethods[i].getParameterTypes().length == arity) 430.356 - { 430.357 - methods.add(allmethods[i]); 430.358 - } 430.359 - } 430.360 - } 430.361 - return methods; 430.362 -} 430.363 - 430.364 - 430.365 -static Object boxArg(Class paramType, Object arg){ 430.366 - if(!paramType.isPrimitive()) 430.367 - return paramType.cast(arg); 430.368 - else if(paramType == boolean.class) 430.369 - return Boolean.class.cast(arg); 430.370 - else if(paramType == char.class) 430.371 - return Character.class.cast(arg); 430.372 - else if(arg instanceof Number) 430.373 - { 430.374 - Number n = (Number) arg; 430.375 - if(paramType == int.class) 430.376 - return n.intValue(); 430.377 - else if(paramType == float.class) 430.378 - return n.floatValue(); 430.379 - else if(paramType == double.class) 430.380 - return n.doubleValue(); 430.381 - else if(paramType == long.class) 430.382 - return n.longValue(); 430.383 - else if(paramType == short.class) 430.384 - return n.shortValue(); 430.385 - else if(paramType == byte.class) 430.386 - return n.byteValue(); 430.387 - } 430.388 - throw new IllegalArgumentException("Unexpected param type, expected: " + paramType + 430.389 - ", given: " + arg.getClass().getName()); 430.390 -} 430.391 - 430.392 -static Object[] boxArgs(Class[] params, Object[] args){ 430.393 - if(params.length == 0) 430.394 - return null; 430.395 - Object[] ret = new Object[params.length]; 430.396 - for(int i = 0; i < params.length; i++) 430.397 - { 430.398 - Object arg = args[i]; 430.399 - Class paramType = params[i]; 430.400 - ret[i] = boxArg(paramType, arg); 430.401 - } 430.402 - return ret; 430.403 -} 430.404 - 430.405 -static public boolean paramArgTypeMatch(Class paramType, Class argType){ 430.406 - if(argType == null) 430.407 - return !paramType.isPrimitive(); 430.408 - if(paramType == argType || paramType.isAssignableFrom(argType)) 430.409 - return true; 430.410 - if(paramType == int.class) 430.411 - return argType == Integer.class;// || argType == FixNum.class; 430.412 - else if(paramType == float.class) 430.413 - return argType == Float.class; 430.414 - else if(paramType == double.class) 430.415 - return argType == Double.class;// || argType == DoubleNum.class; 430.416 - else if(paramType == long.class) 430.417 - return argType == Long.class;// || argType == BigNum.class; 430.418 - else if(paramType == char.class) 430.419 - return argType == Character.class; 430.420 - else if(paramType == short.class) 430.421 - return argType == Short.class; 430.422 - else if(paramType == byte.class) 430.423 - return argType == Byte.class; 430.424 - else if(paramType == boolean.class) 430.425 - return argType == Boolean.class; 430.426 - return false; 430.427 -} 430.428 - 430.429 -static boolean isCongruent(Class[] params, Object[] args){ 430.430 - boolean ret = false; 430.431 - if(args == null) 430.432 - return params.length == 0; 430.433 - if(params.length == args.length) 430.434 - { 430.435 - ret = true; 430.436 - for(int i = 0; ret && i < params.length; i++) 430.437 - { 430.438 - Object arg = args[i]; 430.439 - Class argType = (arg == null) ? null : arg.getClass(); 430.440 - Class paramType = params[i]; 430.441 - ret = paramArgTypeMatch(paramType, argType); 430.442 - } 430.443 - } 430.444 - return ret; 430.445 -} 430.446 - 430.447 -public static Object prepRet(Object x){ 430.448 -// if(c == boolean.class) 430.449 -// return ((Boolean) x).booleanValue() ? RT.T : null; 430.450 - if(x instanceof Boolean) 430.451 - return ((Boolean) x)?Boolean.TRUE:Boolean.FALSE; 430.452 - return x; 430.453 -} 430.454 -}
431.1 --- a/src/clojure/lang/Repl.java Sat Aug 21 06:25:44 2010 -0400 431.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 431.3 @@ -1,22 +0,0 @@ 431.4 -/** 431.5 - * Copyright (c) Rich Hickey. All rights reserved. 431.6 - * The use and distribution terms for this software are covered by the 431.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 431.8 - * which can be found in the file epl-v10.html at the root of this distribution. 431.9 - * By using this software in any fashion, you are agreeing to be bound by 431.10 - * the terms of this license. 431.11 - * You must not remove this notice, or any other, from this software. 431.12 - **/ 431.13 - 431.14 -/* rich Oct 18, 2007 */ 431.15 - 431.16 -package clojure.lang; 431.17 - 431.18 -import clojure.main; 431.19 - 431.20 -public class Repl { 431.21 - 431.22 -public static void main(String[] args) throws Exception{ 431.23 - main.legacy_repl(args); 431.24 -} 431.25 -}
432.1 --- a/src/clojure/lang/RestFn.java Sat Aug 21 06:25:44 2010 -0400 432.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 432.3 @@ -1,1366 +0,0 @@ 432.4 -/** 432.5 - * Copyright (c) Rich Hickey. All rights reserved. 432.6 - * The use and distribution terms for this software are covered by the 432.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 432.8 - * which can be found in the file epl-v10.html at the root of this distribution. 432.9 - * By using this software in any fashion, you are agreeing to be bound by 432.10 - * the terms of this license. 432.11 - * You must not remove this notice, or any other, from this software. 432.12 - **/ 432.13 -package clojure.lang; 432.14 - 432.15 -public abstract class RestFn extends AFunction{ 432.16 - 432.17 -abstract public int getRequiredArity(); 432.18 - 432.19 -protected Object doInvoke(Object args) throws Exception{ 432.20 - return null; 432.21 -} 432.22 - 432.23 -protected Object doInvoke(Object arg1, Object args) throws Exception{ 432.24 - return null; 432.25 -} 432.26 - 432.27 -protected Object doInvoke(Object arg1, Object arg2, Object args) throws Exception{ 432.28 - return null; 432.29 -} 432.30 - 432.31 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object args) throws Exception{ 432.32 - return null; 432.33 -} 432.34 - 432.35 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object args) throws Exception{ 432.36 - return null; 432.37 -} 432.38 - 432.39 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object args) 432.40 - throws Exception{ 432.41 - return null; 432.42 -} 432.43 - 432.44 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object args) 432.45 - throws Exception{ 432.46 - return null; 432.47 -} 432.48 - 432.49 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.50 - Object args) throws Exception{ 432.51 - return null; 432.52 -} 432.53 - 432.54 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.55 - Object arg8, Object args) throws Exception{ 432.56 - return null; 432.57 -} 432.58 - 432.59 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.60 - Object arg8, Object arg9, Object args) throws Exception{ 432.61 - return null; 432.62 -} 432.63 - 432.64 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.65 - Object arg8, Object arg9, Object arg10, Object args) throws Exception{ 432.66 - return null; 432.67 -} 432.68 - 432.69 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.70 - Object arg8, Object arg9, Object arg10, Object arg11, Object args) throws Exception{ 432.71 - return null; 432.72 -} 432.73 - 432.74 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.75 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object args) 432.76 - throws Exception{ 432.77 - return null; 432.78 -} 432.79 - 432.80 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.81 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object args) 432.82 - throws Exception{ 432.83 - return null; 432.84 -} 432.85 - 432.86 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.87 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, 432.88 - Object arg14, Object args) throws Exception{ 432.89 - return null; 432.90 -} 432.91 - 432.92 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.93 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, 432.94 - Object arg14, Object arg15, Object args) throws Exception{ 432.95 - return null; 432.96 -} 432.97 - 432.98 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.99 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, 432.100 - Object arg14, Object arg15, Object arg16, Object args) throws Exception{ 432.101 - return null; 432.102 -} 432.103 - 432.104 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.105 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, 432.106 - Object arg14, Object arg15, Object arg16, Object arg17, Object args) throws Exception{ 432.107 - return null; 432.108 -} 432.109 - 432.110 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.111 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, 432.112 - Object arg14, Object arg15, Object arg16, Object arg17, Object arg18, Object args) 432.113 - throws Exception{ 432.114 - return null; 432.115 -} 432.116 - 432.117 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.118 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, 432.119 - Object arg14, Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, 432.120 - Object args) 432.121 - throws Exception{ 432.122 - return null; 432.123 -} 432.124 - 432.125 -protected Object doInvoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.126 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, 432.127 - Object arg14, Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, 432.128 - Object arg20, Object args) throws Exception{ 432.129 - return null; 432.130 -} 432.131 - 432.132 - 432.133 -public Object applyTo(ISeq args) throws Exception{ 432.134 - if(RT.boundedLength(args, getRequiredArity()) <= getRequiredArity()) 432.135 - { 432.136 - return AFn.applyToHelper(this, Util.ret1(args,args = null)); 432.137 - } 432.138 - switch(getRequiredArity()) 432.139 - { 432.140 - case 0: 432.141 - return doInvoke(Util.ret1(args,args = null)); 432.142 - case 1: 432.143 - return doInvoke(args.first() 432.144 - , Util.ret1(args.next(),args=null)); 432.145 - case 2: 432.146 - return doInvoke(args.first() 432.147 - , (args = args.next()).first() 432.148 - , Util.ret1(args.next(),args=null)); 432.149 - case 3: 432.150 - return doInvoke(args.first() 432.151 - , (args = args.next()).first() 432.152 - , (args = args.next()).first() 432.153 - , Util.ret1(args.next(),args=null)); 432.154 - case 4: 432.155 - return doInvoke(args.first() 432.156 - , (args = args.next()).first() 432.157 - , (args = args.next()).first() 432.158 - , (args = args.next()).first() 432.159 - , Util.ret1(args.next(),args=null)); 432.160 - case 5: 432.161 - return doInvoke(args.first() 432.162 - , (args = args.next()).first() 432.163 - , (args = args.next()).first() 432.164 - , (args = args.next()).first() 432.165 - , (args = args.next()).first() 432.166 - , Util.ret1(args.next(),args=null)); 432.167 - case 6: 432.168 - return doInvoke(args.first() 432.169 - , (args = args.next()).first() 432.170 - , (args = args.next()).first() 432.171 - , (args = args.next()).first() 432.172 - , (args = args.next()).first() 432.173 - , (args = args.next()).first() 432.174 - , Util.ret1(args.next(),args=null)); 432.175 - case 7: 432.176 - return doInvoke(args.first() 432.177 - , (args = args.next()).first() 432.178 - , (args = args.next()).first() 432.179 - , (args = args.next()).first() 432.180 - , (args = args.next()).first() 432.181 - , (args = args.next()).first() 432.182 - , (args = args.next()).first() 432.183 - , Util.ret1(args.next(),args=null)); 432.184 - case 8: 432.185 - return doInvoke(args.first() 432.186 - , (args = args.next()).first() 432.187 - , (args = args.next()).first() 432.188 - , (args = args.next()).first() 432.189 - , (args = args.next()).first() 432.190 - , (args = args.next()).first() 432.191 - , (args = args.next()).first() 432.192 - , (args = args.next()).first() 432.193 - , Util.ret1(args.next(),args=null)); 432.194 - case 9: 432.195 - return doInvoke(args.first() 432.196 - , (args = args.next()).first() 432.197 - , (args = args.next()).first() 432.198 - , (args = args.next()).first() 432.199 - , (args = args.next()).first() 432.200 - , (args = args.next()).first() 432.201 - , (args = args.next()).first() 432.202 - , (args = args.next()).first() 432.203 - , (args = args.next()).first() 432.204 - , Util.ret1(args.next(),args=null)); 432.205 - case 10: 432.206 - return doInvoke(args.first() 432.207 - , (args = args.next()).first() 432.208 - , (args = args.next()).first() 432.209 - , (args = args.next()).first() 432.210 - , (args = args.next()).first() 432.211 - , (args = args.next()).first() 432.212 - , (args = args.next()).first() 432.213 - , (args = args.next()).first() 432.214 - , (args = args.next()).first() 432.215 - , (args = args.next()).first() 432.216 - , Util.ret1(args.next(),args=null)); 432.217 - case 11: 432.218 - return doInvoke(args.first() 432.219 - , (args = args.next()).first() 432.220 - , (args = args.next()).first() 432.221 - , (args = args.next()).first() 432.222 - , (args = args.next()).first() 432.223 - , (args = args.next()).first() 432.224 - , (args = args.next()).first() 432.225 - , (args = args.next()).first() 432.226 - , (args = args.next()).first() 432.227 - , (args = args.next()).first() 432.228 - , (args = args.next()).first() 432.229 - , Util.ret1(args.next(),args=null)); 432.230 - case 12: 432.231 - return doInvoke(args.first() 432.232 - , (args = args.next()).first() 432.233 - , (args = args.next()).first() 432.234 - , (args = args.next()).first() 432.235 - , (args = args.next()).first() 432.236 - , (args = args.next()).first() 432.237 - , (args = args.next()).first() 432.238 - , (args = args.next()).first() 432.239 - , (args = args.next()).first() 432.240 - , (args = args.next()).first() 432.241 - , (args = args.next()).first() 432.242 - , (args = args.next()).first() 432.243 - , Util.ret1(args.next(),args=null)); 432.244 - case 13: 432.245 - return doInvoke(args.first() 432.246 - , (args = args.next()).first() 432.247 - , (args = args.next()).first() 432.248 - , (args = args.next()).first() 432.249 - , (args = args.next()).first() 432.250 - , (args = args.next()).first() 432.251 - , (args = args.next()).first() 432.252 - , (args = args.next()).first() 432.253 - , (args = args.next()).first() 432.254 - , (args = args.next()).first() 432.255 - , (args = args.next()).first() 432.256 - , (args = args.next()).first() 432.257 - , (args = args.next()).first() 432.258 - , Util.ret1(args.next(),args=null)); 432.259 - case 14: 432.260 - return doInvoke(args.first() 432.261 - , (args = args.next()).first() 432.262 - , (args = args.next()).first() 432.263 - , (args = args.next()).first() 432.264 - , (args = args.next()).first() 432.265 - , (args = args.next()).first() 432.266 - , (args = args.next()).first() 432.267 - , (args = args.next()).first() 432.268 - , (args = args.next()).first() 432.269 - , (args = args.next()).first() 432.270 - , (args = args.next()).first() 432.271 - , (args = args.next()).first() 432.272 - , (args = args.next()).first() 432.273 - , (args = args.next()).first() 432.274 - , Util.ret1(args.next(),args=null)); 432.275 - case 15: 432.276 - return doInvoke(args.first() 432.277 - , (args = args.next()).first() 432.278 - , (args = args.next()).first() 432.279 - , (args = args.next()).first() 432.280 - , (args = args.next()).first() 432.281 - , (args = args.next()).first() 432.282 - , (args = args.next()).first() 432.283 - , (args = args.next()).first() 432.284 - , (args = args.next()).first() 432.285 - , (args = args.next()).first() 432.286 - , (args = args.next()).first() 432.287 - , (args = args.next()).first() 432.288 - , (args = args.next()).first() 432.289 - , (args = args.next()).first() 432.290 - , (args = args.next()).first() 432.291 - , Util.ret1(args.next(),args=null)); 432.292 - case 16: 432.293 - return doInvoke(args.first() 432.294 - , (args = args.next()).first() 432.295 - , (args = args.next()).first() 432.296 - , (args = args.next()).first() 432.297 - , (args = args.next()).first() 432.298 - , (args = args.next()).first() 432.299 - , (args = args.next()).first() 432.300 - , (args = args.next()).first() 432.301 - , (args = args.next()).first() 432.302 - , (args = args.next()).first() 432.303 - , (args = args.next()).first() 432.304 - , (args = args.next()).first() 432.305 - , (args = args.next()).first() 432.306 - , (args = args.next()).first() 432.307 - , (args = args.next()).first() 432.308 - , (args = args.next()).first() 432.309 - , Util.ret1(args.next(),args=null)); 432.310 - case 17: 432.311 - return doInvoke(args.first() 432.312 - , (args = args.next()).first() 432.313 - , (args = args.next()).first() 432.314 - , (args = args.next()).first() 432.315 - , (args = args.next()).first() 432.316 - , (args = args.next()).first() 432.317 - , (args = args.next()).first() 432.318 - , (args = args.next()).first() 432.319 - , (args = args.next()).first() 432.320 - , (args = args.next()).first() 432.321 - , (args = args.next()).first() 432.322 - , (args = args.next()).first() 432.323 - , (args = args.next()).first() 432.324 - , (args = args.next()).first() 432.325 - , (args = args.next()).first() 432.326 - , (args = args.next()).first() 432.327 - , (args = args.next()).first() 432.328 - , Util.ret1(args.next(),args=null)); 432.329 - case 18: 432.330 - return doInvoke(args.first() 432.331 - , (args = args.next()).first() 432.332 - , (args = args.next()).first() 432.333 - , (args = args.next()).first() 432.334 - , (args = args.next()).first() 432.335 - , (args = args.next()).first() 432.336 - , (args = args.next()).first() 432.337 - , (args = args.next()).first() 432.338 - , (args = args.next()).first() 432.339 - , (args = args.next()).first() 432.340 - , (args = args.next()).first() 432.341 - , (args = args.next()).first() 432.342 - , (args = args.next()).first() 432.343 - , (args = args.next()).first() 432.344 - , (args = args.next()).first() 432.345 - , (args = args.next()).first() 432.346 - , (args = args.next()).first() 432.347 - , (args = args.next()).first() 432.348 - , Util.ret1(args.next(),args=null)); 432.349 - case 19: 432.350 - return doInvoke(args.first() 432.351 - , (args = args.next()).first() 432.352 - , (args = args.next()).first() 432.353 - , (args = args.next()).first() 432.354 - , (args = args.next()).first() 432.355 - , (args = args.next()).first() 432.356 - , (args = args.next()).first() 432.357 - , (args = args.next()).first() 432.358 - , (args = args.next()).first() 432.359 - , (args = args.next()).first() 432.360 - , (args = args.next()).first() 432.361 - , (args = args.next()).first() 432.362 - , (args = args.next()).first() 432.363 - , (args = args.next()).first() 432.364 - , (args = args.next()).first() 432.365 - , (args = args.next()).first() 432.366 - , (args = args.next()).first() 432.367 - , (args = args.next()).first() 432.368 - , (args = args.next()).first() 432.369 - , Util.ret1(args.next(),args=null)); 432.370 - case 20: 432.371 - return doInvoke(args.first() 432.372 - , (args = args.next()).first() 432.373 - , (args = args.next()).first() 432.374 - , (args = args.next()).first() 432.375 - , (args = args.next()).first() 432.376 - , (args = args.next()).first() 432.377 - , (args = args.next()).first() 432.378 - , (args = args.next()).first() 432.379 - , (args = args.next()).first() 432.380 - , (args = args.next()).first() 432.381 - , (args = args.next()).first() 432.382 - , (args = args.next()).first() 432.383 - , (args = args.next()).first() 432.384 - , (args = args.next()).first() 432.385 - , (args = args.next()).first() 432.386 - , (args = args.next()).first() 432.387 - , (args = args.next()).first() 432.388 - , (args = args.next()).first() 432.389 - , (args = args.next()).first() 432.390 - , (args = args.next()).first() 432.391 - , Util.ret1(args.next(),args=null)); 432.392 - 432.393 - } 432.394 - return throwArity(-1); 432.395 -} 432.396 - 432.397 -public Object invoke() throws Exception{ 432.398 - switch(getRequiredArity()) 432.399 - { 432.400 - case 0: 432.401 - return doInvoke(null); 432.402 - default: 432.403 - return throwArity(0); 432.404 - } 432.405 - 432.406 -} 432.407 - 432.408 -public Object invoke(Object arg1) throws Exception{ 432.409 - switch(getRequiredArity()) 432.410 - { 432.411 - case 0: 432.412 - return doInvoke(ArraySeq.create(Util.ret1(arg1, arg1 = null))); 432.413 - case 1: 432.414 - return doInvoke(Util.ret1(arg1, arg1 = null), null); 432.415 - default: 432.416 - return throwArity(1); 432.417 - } 432.418 - 432.419 -} 432.420 - 432.421 -public Object invoke(Object arg1, Object arg2) throws Exception{ 432.422 - switch(getRequiredArity()) 432.423 - { 432.424 - case 0: 432.425 - return doInvoke(ArraySeq.create(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null))); 432.426 - case 1: 432.427 - return doInvoke(Util.ret1(arg1, arg1 = null), ArraySeq.create(Util.ret1(arg2, arg2 = null))); 432.428 - case 2: 432.429 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), null); 432.430 - default: 432.431 - return throwArity(2); 432.432 - } 432.433 - 432.434 -} 432.435 - 432.436 -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception{ 432.437 - switch(getRequiredArity()) 432.438 - { 432.439 - case 0: 432.440 - return doInvoke(ArraySeq.create(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), 432.441 - Util.ret1(arg3, arg3 = null))); 432.442 - case 1: 432.443 - return doInvoke(Util.ret1(arg1, arg1 = null), 432.444 - ArraySeq.create(Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null))); 432.445 - case 2: 432.446 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), 432.447 - ArraySeq.create(Util.ret1(arg3, arg3 = null))); 432.448 - case 3: 432.449 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.450 - null); 432.451 - default: 432.452 - return throwArity(3); 432.453 - } 432.454 - 432.455 -} 432.456 - 432.457 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception{ 432.458 - switch(getRequiredArity()) 432.459 - { 432.460 - case 0: 432.461 - return doInvoke(ArraySeq.create(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), 432.462 - Util.ret1(arg3, arg3 = null), Util.ret1(arg4, arg4 = null))); 432.463 - case 1: 432.464 - return doInvoke(Util.ret1(arg1, arg1 = null), 432.465 - ArraySeq.create(Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.466 - Util.ret1(arg4, arg4 = null))); 432.467 - case 2: 432.468 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), 432.469 - ArraySeq.create(Util.ret1(arg3, arg3 = null), Util.ret1(arg4, arg4 = null))); 432.470 - case 3: 432.471 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.472 - ArraySeq.create(Util.ret1(arg4, arg4 = null))); 432.473 - case 4: 432.474 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.475 - Util.ret1(arg4, arg4 = null), null); 432.476 - default: 432.477 - return throwArity(4); 432.478 - } 432.479 - 432.480 -} 432.481 - 432.482 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception{ 432.483 - switch(getRequiredArity()) 432.484 - { 432.485 - case 0: 432.486 - return doInvoke(ArraySeq.create(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), 432.487 - Util.ret1(arg3, arg3 = null), Util.ret1(arg4, arg4 = null), 432.488 - Util.ret1(arg5, arg5 = null))); 432.489 - case 1: 432.490 - return doInvoke(Util.ret1(arg1, arg1 = null), 432.491 - ArraySeq.create(Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.492 - Util.ret1(arg4, arg4 = null), Util.ret1(arg5, arg5 = null))); 432.493 - case 2: 432.494 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), 432.495 - ArraySeq.create(Util.ret1(arg3, arg3 = null), Util.ret1(arg4, arg4 = null), 432.496 - Util.ret1(arg5, arg5 = null))); 432.497 - case 3: 432.498 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.499 - ArraySeq.create(Util.ret1(arg4, arg4 = null), Util.ret1(arg5, arg5 = null))); 432.500 - case 4: 432.501 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.502 - Util.ret1(arg4, arg4 = null), ArraySeq.create(Util.ret1(arg5, arg5 = null))); 432.503 - case 5: 432.504 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.505 - Util.ret1(arg4, arg4 = null), Util.ret1(arg5, arg5 = null), null); 432.506 - default: 432.507 - return throwArity(5); 432.508 - } 432.509 - 432.510 -} 432.511 - 432.512 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception{ 432.513 - switch(getRequiredArity()) 432.514 - { 432.515 - case 0: 432.516 - return doInvoke(ArraySeq.create(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), 432.517 - Util.ret1(arg3, arg3 = null), Util.ret1(arg4, arg4 = null), 432.518 - Util.ret1(arg5, arg5 = null), Util.ret1(arg6, arg6 = null))); 432.519 - case 1: 432.520 - return doInvoke(Util.ret1(arg1, arg1 = null), 432.521 - ArraySeq.create(Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.522 - Util.ret1(arg4, arg4 = null), Util.ret1(arg5, arg5 = null), 432.523 - Util.ret1(arg6, arg6 = null))); 432.524 - case 2: 432.525 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), 432.526 - ArraySeq.create(Util.ret1(arg3, arg3 = null), Util.ret1(arg4, arg4 = null), 432.527 - Util.ret1(arg5, arg5 = null), Util.ret1(arg6, arg6 = null))); 432.528 - case 3: 432.529 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.530 - ArraySeq.create(Util.ret1(arg4, arg4 = null), Util.ret1(arg5, arg5 = null), 432.531 - Util.ret1(arg6, arg6 = null))); 432.532 - case 4: 432.533 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.534 - Util.ret1(arg4, arg4 = null), 432.535 - ArraySeq.create(Util.ret1(arg5, arg5 = null), Util.ret1(arg6, arg6 = null))); 432.536 - case 5: 432.537 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.538 - Util.ret1(arg4, arg4 = null), Util.ret1(arg5, arg5 = null), 432.539 - ArraySeq.create(Util.ret1(arg6, arg6 = null))); 432.540 - case 6: 432.541 - return doInvoke(Util.ret1(arg1, arg1 = null), Util.ret1(arg2, arg2 = null), Util.ret1(arg3, arg3 = null), 432.542 - Util.ret1(arg4, arg4 = null), Util.ret1(arg5, arg5 = null), Util.ret1(arg6, arg6 = null), 432.543 - null); 432.544 - default: 432.545 - return throwArity(6); 432.546 - } 432.547 - 432.548 -} 432.549 - 432.550 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) 432.551 - throws Exception{ 432.552 - switch(getRequiredArity()) 432.553 - { 432.554 - case 0: 432.555 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7)); 432.556 - case 1: 432.557 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7)); 432.558 - case 2: 432.559 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7)); 432.560 - case 3: 432.561 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7)); 432.562 - case 4: 432.563 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7)); 432.564 - case 5: 432.565 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7)); 432.566 - case 6: 432.567 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7)); 432.568 - case 7: 432.569 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, null); 432.570 - default: 432.571 - return throwArity(7); 432.572 - } 432.573 - 432.574 -} 432.575 - 432.576 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.577 - Object arg8) throws Exception{ 432.578 - switch(getRequiredArity()) 432.579 - { 432.580 - case 0: 432.581 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); 432.582 - case 1: 432.583 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8)); 432.584 - case 2: 432.585 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8)); 432.586 - case 3: 432.587 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8)); 432.588 - case 4: 432.589 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8)); 432.590 - case 5: 432.591 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8)); 432.592 - case 6: 432.593 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8)); 432.594 - case 7: 432.595 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8)); 432.596 - case 8: 432.597 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, null); 432.598 - default: 432.599 - return throwArity(8); 432.600 - } 432.601 - 432.602 -} 432.603 - 432.604 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.605 - Object arg8, Object arg9) throws Exception{ 432.606 - switch(getRequiredArity()) 432.607 - { 432.608 - case 0: 432.609 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); 432.610 - case 1: 432.611 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); 432.612 - case 2: 432.613 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9)); 432.614 - case 3: 432.615 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9)); 432.616 - case 4: 432.617 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9)); 432.618 - case 5: 432.619 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9)); 432.620 - case 6: 432.621 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9)); 432.622 - case 7: 432.623 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9)); 432.624 - case 8: 432.625 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9)); 432.626 - case 9: 432.627 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, null); 432.628 - default: 432.629 - return throwArity(9); 432.630 - } 432.631 - 432.632 -} 432.633 - 432.634 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.635 - Object arg8, Object arg9, Object arg10) throws Exception{ 432.636 - switch(getRequiredArity()) 432.637 - { 432.638 - case 0: 432.639 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); 432.640 - case 1: 432.641 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); 432.642 - case 2: 432.643 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); 432.644 - case 3: 432.645 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10)); 432.646 - case 4: 432.647 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10)); 432.648 - case 5: 432.649 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10)); 432.650 - case 6: 432.651 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10)); 432.652 - case 7: 432.653 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10)); 432.654 - case 8: 432.655 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10)); 432.656 - case 9: 432.657 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ArraySeq.create(arg10)); 432.658 - case 10: 432.659 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, null); 432.660 - default: 432.661 - return throwArity(10); 432.662 - } 432.663 - 432.664 -} 432.665 - 432.666 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.667 - Object arg8, Object arg9, Object arg10, Object arg11) throws Exception{ 432.668 - switch(getRequiredArity()) 432.669 - { 432.670 - case 0: 432.671 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); 432.672 - case 1: 432.673 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); 432.674 - case 2: 432.675 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); 432.676 - case 3: 432.677 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); 432.678 - case 4: 432.679 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11)); 432.680 - case 5: 432.681 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11)); 432.682 - case 6: 432.683 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11)); 432.684 - case 7: 432.685 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10, arg11)); 432.686 - case 8: 432.687 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10, arg11)); 432.688 - case 9: 432.689 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ArraySeq.create(arg10, arg11)); 432.690 - case 10: 432.691 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, ArraySeq.create(arg11)); 432.692 - case 11: 432.693 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, null); 432.694 - default: 432.695 - return throwArity(11); 432.696 - } 432.697 - 432.698 -} 432.699 - 432.700 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.701 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception{ 432.702 - switch(getRequiredArity()) 432.703 - { 432.704 - case 0: 432.705 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); 432.706 - case 1: 432.707 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); 432.708 - case 2: 432.709 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); 432.710 - case 3: 432.711 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); 432.712 - case 4: 432.713 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); 432.714 - case 5: 432.715 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12)); 432.716 - case 6: 432.717 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12)); 432.718 - case 7: 432.719 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10, arg11, arg12)); 432.720 - case 8: 432.721 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10, arg11, arg12)); 432.722 - case 9: 432.723 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ArraySeq.create(arg10, arg11, arg12)); 432.724 - case 10: 432.725 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, ArraySeq.create(arg11, arg12)); 432.726 - case 11: 432.727 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, ArraySeq.create(arg12)); 432.728 - case 12: 432.729 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, null); 432.730 - default: 432.731 - return throwArity(12); 432.732 - } 432.733 - 432.734 -} 432.735 - 432.736 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.737 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) 432.738 - throws Exception{ 432.739 - switch(getRequiredArity()) 432.740 - { 432.741 - case 0: 432.742 - return doInvoke( 432.743 - ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); 432.744 - case 1: 432.745 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.746 - arg13)); 432.747 - case 2: 432.748 - return doInvoke(arg1, arg2, 432.749 - ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); 432.750 - case 3: 432.751 - return doInvoke(arg1, arg2, arg3, 432.752 - ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); 432.753 - case 4: 432.754 - return doInvoke(arg1, arg2, arg3, arg4, 432.755 - ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); 432.756 - case 5: 432.757 - return doInvoke(arg1, arg2, arg3, arg4, arg5, 432.758 - ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); 432.759 - case 6: 432.760 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, 432.761 - ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13)); 432.762 - case 7: 432.763 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, 432.764 - ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13)); 432.765 - case 8: 432.766 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 432.767 - ArraySeq.create(arg9, arg10, arg11, arg12, arg13)); 432.768 - case 9: 432.769 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 432.770 - ArraySeq.create(arg10, arg11, arg12, arg13)); 432.771 - case 10: 432.772 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, 432.773 - ArraySeq.create(arg11, arg12, arg13)); 432.774 - case 11: 432.775 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.776 - ArraySeq.create(arg12, arg13)); 432.777 - case 12: 432.778 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.779 - ArraySeq.create(arg13)); 432.780 - case 13: 432.781 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, null); 432.782 - default: 432.783 - return throwArity(13); 432.784 - } 432.785 - 432.786 -} 432.787 - 432.788 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.789 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) 432.790 - throws Exception{ 432.791 - switch(getRequiredArity()) 432.792 - { 432.793 - case 0: 432.794 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.795 - arg13, arg14)); 432.796 - case 1: 432.797 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.798 - arg13, arg14)); 432.799 - case 2: 432.800 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.801 - arg13, arg14)); 432.802 - case 3: 432.803 - return doInvoke(arg1, arg2, arg3, 432.804 - ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); 432.805 - case 4: 432.806 - return doInvoke(arg1, arg2, arg3, arg4, 432.807 - ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); 432.808 - case 5: 432.809 - return doInvoke(arg1, arg2, arg3, arg4, arg5, 432.810 - ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); 432.811 - case 6: 432.812 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, 432.813 - ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); 432.814 - case 7: 432.815 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, 432.816 - ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14)); 432.817 - case 8: 432.818 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 432.819 - ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14)); 432.820 - case 9: 432.821 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 432.822 - ArraySeq.create(arg10, arg11, arg12, arg13, arg14)); 432.823 - case 10: 432.824 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, 432.825 - ArraySeq.create(arg11, arg12, arg13, arg14)); 432.826 - case 11: 432.827 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.828 - ArraySeq.create(arg12, arg13, arg14)); 432.829 - case 12: 432.830 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.831 - ArraySeq.create(arg13, arg14)); 432.832 - case 13: 432.833 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, 432.834 - ArraySeq.create(arg14)); 432.835 - case 14: 432.836 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.837 - null); 432.838 - default: 432.839 - return throwArity(14); 432.840 - } 432.841 - 432.842 -} 432.843 - 432.844 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.845 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 432.846 - Object arg15) throws Exception{ 432.847 - switch(getRequiredArity()) 432.848 - { 432.849 - case 0: 432.850 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.851 - arg13, arg14, arg15)); 432.852 - case 1: 432.853 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.854 - arg13, arg14, arg15)); 432.855 - case 2: 432.856 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.857 - arg13, arg14, arg15)); 432.858 - case 3: 432.859 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.860 - arg13, arg14, arg15)); 432.861 - case 4: 432.862 - return doInvoke(arg1, arg2, arg3, arg4, 432.863 - ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); 432.864 - case 5: 432.865 - return doInvoke(arg1, arg2, arg3, arg4, arg5, 432.866 - ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); 432.867 - case 6: 432.868 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, 432.869 - ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); 432.870 - case 7: 432.871 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, 432.872 - ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); 432.873 - case 8: 432.874 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 432.875 - ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14, arg15)); 432.876 - case 9: 432.877 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 432.878 - ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15)); 432.879 - case 10: 432.880 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, 432.881 - ArraySeq.create(arg11, arg12, arg13, arg14, arg15)); 432.882 - case 11: 432.883 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.884 - ArraySeq.create(arg12, arg13, arg14, arg15)); 432.885 - case 12: 432.886 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.887 - ArraySeq.create(arg13, arg14, arg15)); 432.888 - case 13: 432.889 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, 432.890 - ArraySeq.create(arg14, arg15)); 432.891 - case 14: 432.892 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.893 - ArraySeq.create(arg15)); 432.894 - case 15: 432.895 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.896 - arg15, null); 432.897 - default: 432.898 - return throwArity(15); 432.899 - } 432.900 - 432.901 -} 432.902 - 432.903 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.904 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 432.905 - Object arg15, Object arg16) throws Exception{ 432.906 - switch(getRequiredArity()) 432.907 - { 432.908 - case 0: 432.909 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.910 - arg13, arg14, arg15, arg16)); 432.911 - case 1: 432.912 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.913 - arg13, arg14, arg15, arg16)); 432.914 - case 2: 432.915 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.916 - arg13, arg14, arg15, arg16)); 432.917 - case 3: 432.918 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.919 - arg13, arg14, arg15, arg16)); 432.920 - case 4: 432.921 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.922 - arg13, arg14, arg15, arg16)); 432.923 - case 5: 432.924 - return doInvoke(arg1, arg2, arg3, arg4, arg5, 432.925 - ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); 432.926 - case 6: 432.927 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, 432.928 - ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); 432.929 - case 7: 432.930 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, 432.931 - ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); 432.932 - case 8: 432.933 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 432.934 - ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); 432.935 - case 9: 432.936 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 432.937 - ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15, arg16)); 432.938 - case 10: 432.939 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, 432.940 - ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16)); 432.941 - case 11: 432.942 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.943 - ArraySeq.create(arg12, arg13, arg14, arg15, arg16)); 432.944 - case 12: 432.945 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.946 - ArraySeq.create(arg13, arg14, arg15, arg16)); 432.947 - case 13: 432.948 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, 432.949 - ArraySeq.create(arg14, arg15, arg16)); 432.950 - case 14: 432.951 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.952 - ArraySeq.create(arg15, arg16)); 432.953 - case 15: 432.954 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.955 - arg15, ArraySeq.create(arg16)); 432.956 - case 16: 432.957 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.958 - arg15, arg16, null); 432.959 - default: 432.960 - return throwArity(16); 432.961 - } 432.962 - 432.963 -} 432.964 - 432.965 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.966 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 432.967 - Object arg15, Object arg16, Object arg17) throws Exception{ 432.968 - switch(getRequiredArity()) 432.969 - { 432.970 - case 0: 432.971 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.972 - arg13, arg14, arg15, arg16, arg17)); 432.973 - case 1: 432.974 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.975 - arg13, arg14, arg15, arg16, arg17)); 432.976 - case 2: 432.977 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.978 - arg13, arg14, arg15, arg16, arg17)); 432.979 - case 3: 432.980 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.981 - arg13, arg14, arg15, arg16, arg17)); 432.982 - case 4: 432.983 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.984 - arg13, arg14, arg15, arg16, arg17)); 432.985 - case 5: 432.986 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.987 - arg13, arg14, arg15, arg16, arg17)); 432.988 - case 6: 432.989 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, 432.990 - ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17)); 432.991 - case 7: 432.992 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, 432.993 - ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17)); 432.994 - case 8: 432.995 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 432.996 - ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17)); 432.997 - case 9: 432.998 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 432.999 - ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17)); 432.1000 - case 10: 432.1001 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, 432.1002 - ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16, arg17)); 432.1003 - case 11: 432.1004 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1005 - ArraySeq.create(arg12, arg13, arg14, arg15, arg16, arg17)); 432.1006 - case 12: 432.1007 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1008 - ArraySeq.create(arg13, arg14, arg15, arg16, arg17)); 432.1009 - case 13: 432.1010 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, 432.1011 - ArraySeq.create(arg14, arg15, arg16, arg17)); 432.1012 - case 14: 432.1013 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1014 - ArraySeq.create(arg15, arg16, arg17)); 432.1015 - case 15: 432.1016 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1017 - arg15, ArraySeq.create(arg16, arg17)); 432.1018 - case 16: 432.1019 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1020 - arg15, arg16, ArraySeq.create(arg17)); 432.1021 - case 17: 432.1022 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1023 - arg15, arg16, arg17, null); 432.1024 - default: 432.1025 - return throwArity(17); 432.1026 - } 432.1027 - 432.1028 -} 432.1029 - 432.1030 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.1031 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 432.1032 - Object arg15, Object arg16, Object arg17, Object arg18) throws Exception{ 432.1033 - switch(getRequiredArity()) 432.1034 - { 432.1035 - case 0: 432.1036 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1037 - arg13, arg14, arg15, arg16, arg17, arg18)); 432.1038 - case 1: 432.1039 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1040 - arg13, arg14, arg15, arg16, arg17, arg18)); 432.1041 - case 2: 432.1042 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1043 - arg13, arg14, arg15, arg16, arg17, arg18)); 432.1044 - case 3: 432.1045 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1046 - arg13, arg14, arg15, arg16, arg17, arg18)); 432.1047 - case 4: 432.1048 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1049 - arg13, arg14, arg15, arg16, arg17, arg18)); 432.1050 - case 5: 432.1051 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1052 - arg13, arg14, arg15, arg16, arg17, arg18)); 432.1053 - case 6: 432.1054 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, 432.1055 - arg13, arg14, arg15, arg16, arg17, 432.1056 - arg18)); 432.1057 - case 7: 432.1058 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, 432.1059 - ArraySeq.create(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18)); 432.1060 - case 8: 432.1061 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 432.1062 - ArraySeq.create(arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18)); 432.1063 - case 9: 432.1064 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 432.1065 - ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18)); 432.1066 - case 10: 432.1067 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, 432.1068 - ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18)); 432.1069 - case 11: 432.1070 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1071 - ArraySeq.create(arg12, arg13, arg14, arg15, arg16, arg17, arg18)); 432.1072 - case 12: 432.1073 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1074 - ArraySeq.create(arg13, arg14, arg15, arg16, arg17, arg18)); 432.1075 - case 13: 432.1076 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, 432.1077 - ArraySeq.create(arg14, arg15, arg16, arg17, arg18)); 432.1078 - case 14: 432.1079 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1080 - ArraySeq.create(arg15, arg16, arg17, arg18)); 432.1081 - case 15: 432.1082 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1083 - arg15, ArraySeq.create(arg16, arg17, arg18)); 432.1084 - case 16: 432.1085 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1086 - arg15, arg16, ArraySeq.create(arg17, arg18)); 432.1087 - case 17: 432.1088 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1089 - arg15, arg16, arg17, ArraySeq.create(arg18)); 432.1090 - case 18: 432.1091 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1092 - arg15, arg16, arg17, arg18, null); 432.1093 - default: 432.1094 - return throwArity(18); 432.1095 - } 432.1096 - 432.1097 -} 432.1098 - 432.1099 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.1100 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 432.1101 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception{ 432.1102 - switch(getRequiredArity()) 432.1103 - { 432.1104 - case 0: 432.1105 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1106 - arg13, arg14, arg15, arg16, arg17, arg18, arg19)); 432.1107 - case 1: 432.1108 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1109 - arg13, arg14, arg15, arg16, arg17, arg18, arg19)); 432.1110 - case 2: 432.1111 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1112 - arg13, arg14, arg15, arg16, arg17, arg18, arg19)); 432.1113 - case 3: 432.1114 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1115 - arg13, arg14, arg15, arg16, arg17, arg18, arg19)); 432.1116 - case 4: 432.1117 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1118 - arg13, arg14, arg15, arg16, arg17, arg18, arg19)); 432.1119 - case 5: 432.1120 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1121 - arg13, arg14, arg15, arg16, arg17, arg18, 432.1122 - arg19)); 432.1123 - case 6: 432.1124 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, 432.1125 - arg13, arg14, arg15, arg16, arg17, 432.1126 - arg18, arg19)); 432.1127 - case 7: 432.1128 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10, arg11, arg12, 432.1129 - arg13, arg14, arg15, arg16, arg17, 432.1130 - arg18, arg19)); 432.1131 - case 8: 432.1132 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10, arg11, arg12, 432.1133 - arg13, arg14, arg15, arg16, 432.1134 - arg17, arg18, arg19)); 432.1135 - case 9: 432.1136 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 432.1137 - ArraySeq.create(arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19)); 432.1138 - case 10: 432.1139 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, 432.1140 - ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19)); 432.1141 - case 11: 432.1142 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1143 - ArraySeq.create(arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19)); 432.1144 - case 12: 432.1145 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1146 - ArraySeq.create(arg13, arg14, arg15, arg16, arg17, arg18, arg19)); 432.1147 - case 13: 432.1148 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, 432.1149 - ArraySeq.create(arg14, arg15, arg16, arg17, arg18, arg19)); 432.1150 - case 14: 432.1151 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1152 - ArraySeq.create(arg15, arg16, arg17, arg18, arg19)); 432.1153 - case 15: 432.1154 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1155 - arg15, ArraySeq.create(arg16, arg17, arg18, arg19)); 432.1156 - case 16: 432.1157 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1158 - arg15, arg16, ArraySeq.create(arg17, arg18, arg19)); 432.1159 - case 17: 432.1160 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1161 - arg15, arg16, arg17, ArraySeq.create(arg18, arg19)); 432.1162 - case 18: 432.1163 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1164 - arg15, arg16, arg17, arg18, ArraySeq.create(arg19)); 432.1165 - case 19: 432.1166 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1167 - arg15, arg16, arg17, arg18, arg19, null); 432.1168 - default: 432.1169 - return throwArity(19); 432.1170 - } 432.1171 - 432.1172 -} 432.1173 - 432.1174 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.1175 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 432.1176 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20) 432.1177 - throws Exception{ 432.1178 - switch(getRequiredArity()) 432.1179 - { 432.1180 - case 0: 432.1181 - return doInvoke(ArraySeq.create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1182 - arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1183 - case 1: 432.1184 - return doInvoke(arg1, ArraySeq.create(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1185 - arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1186 - case 2: 432.1187 - return doInvoke(arg1, arg2, ArraySeq.create(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1188 - arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1189 - case 3: 432.1190 - return doInvoke(arg1, arg2, arg3, ArraySeq.create(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1191 - arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1192 - case 4: 432.1193 - return doInvoke(arg1, arg2, arg3, arg4, ArraySeq.create(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1194 - arg13, arg14, arg15, arg16, arg17, arg18, arg19, 432.1195 - arg20)); 432.1196 - case 5: 432.1197 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ArraySeq.create(arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1198 - arg13, arg14, arg15, arg16, arg17, arg18, 432.1199 - arg19, arg20)); 432.1200 - case 6: 432.1201 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ArraySeq.create(arg7, arg8, arg9, arg10, arg11, arg12, 432.1202 - arg13, arg14, arg15, arg16, arg17, 432.1203 - arg18, arg19, arg20)); 432.1204 - case 7: 432.1205 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ArraySeq.create(arg8, arg9, arg10, arg11, arg12, 432.1206 - arg13, arg14, arg15, arg16, arg17, 432.1207 - arg18, arg19, arg20)); 432.1208 - case 8: 432.1209 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ArraySeq.create(arg9, arg10, arg11, arg12, 432.1210 - arg13, arg14, arg15, arg16, 432.1211 - arg17, arg18, arg19, 432.1212 - arg20)); 432.1213 - case 9: 432.1214 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ArraySeq.create(arg10, arg11, arg12, 432.1215 - arg13, arg14, arg15, 432.1216 - arg16, arg17, arg18, 432.1217 - arg19, arg20)); 432.1218 - case 10: 432.1219 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, 432.1220 - ArraySeq.create(arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1221 - case 11: 432.1222 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1223 - ArraySeq.create(arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1224 - case 12: 432.1225 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1226 - ArraySeq.create(arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1227 - case 13: 432.1228 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, 432.1229 - ArraySeq.create(arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1230 - case 14: 432.1231 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1232 - ArraySeq.create(arg15, arg16, arg17, arg18, arg19, arg20)); 432.1233 - case 15: 432.1234 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1235 - arg15, ArraySeq.create(arg16, arg17, arg18, arg19, arg20)); 432.1236 - case 16: 432.1237 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1238 - arg15, arg16, ArraySeq.create(arg17, arg18, arg19, arg20)); 432.1239 - case 17: 432.1240 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1241 - arg15, arg16, arg17, ArraySeq.create(arg18, arg19, arg20)); 432.1242 - case 18: 432.1243 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1244 - arg15, arg16, arg17, arg18, ArraySeq.create(arg19, arg20)); 432.1245 - case 19: 432.1246 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1247 - arg15, arg16, arg17, arg18, arg19, ArraySeq.create(arg20)); 432.1248 - case 20: 432.1249 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1250 - arg15, arg16, arg17, arg18, arg19, arg20, null); 432.1251 - default: 432.1252 - return throwArity(20); 432.1253 - } 432.1254 - 432.1255 -} 432.1256 - 432.1257 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 432.1258 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 432.1259 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20, Object... args) 432.1260 - throws Exception{ 432.1261 - switch(getRequiredArity()) 432.1262 - { 432.1263 - case 0: 432.1264 - return doInvoke(ontoArrayPrepend(args, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1265 - arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1266 - case 1: 432.1267 - return doInvoke(arg1, ontoArrayPrepend(args, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1268 - arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1269 - case 2: 432.1270 - return doInvoke(arg1, arg2, ontoArrayPrepend(args, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1271 - arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, 432.1272 - arg20)); 432.1273 - case 3: 432.1274 - return doInvoke(arg1, arg2, arg3, ontoArrayPrepend(args, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1275 - arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, 432.1276 - arg20)); 432.1277 - case 4: 432.1278 - return doInvoke(arg1, arg2, arg3, arg4, ontoArrayPrepend(args, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1279 - arg12, arg13, arg14, arg15, arg16, arg17, arg18, 432.1280 - arg19, arg20)); 432.1281 - case 5: 432.1282 - return doInvoke(arg1, arg2, arg3, arg4, arg5, ontoArrayPrepend(args, arg6, arg7, arg8, arg9, arg10, arg11, 432.1283 - arg12, arg13, arg14, arg15, arg16, arg17, 432.1284 - arg18, arg19, arg20)); 432.1285 - case 6: 432.1286 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, ontoArrayPrepend(args, arg7, arg8, arg9, arg10, arg11, 432.1287 - arg12, arg13, arg14, arg15, arg16, 432.1288 - arg17, arg18, arg19, arg20)); 432.1289 - case 7: 432.1290 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ontoArrayPrepend(args, arg8, arg9, arg10, arg11, 432.1291 - arg12, arg13, arg14, arg15, 432.1292 - arg16, arg17, arg18, arg19, 432.1293 - arg20)); 432.1294 - case 8: 432.1295 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ontoArrayPrepend(args, arg9, arg10, arg11, 432.1296 - arg12, arg13, arg14, arg15, 432.1297 - arg16, arg17, arg18, arg19, 432.1298 - arg20)); 432.1299 - case 9: 432.1300 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, ontoArrayPrepend(args, arg10, arg11, 432.1301 - arg12, arg13, arg14, 432.1302 - arg15, arg16, arg17, 432.1303 - arg18, arg19, 432.1304 - arg20)); 432.1305 - case 10: 432.1306 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, ontoArrayPrepend(args, arg11, 432.1307 - arg12, arg13, 432.1308 - arg14, arg15, 432.1309 - arg16, arg17, 432.1310 - arg18, arg19, 432.1311 - arg20)); 432.1312 - case 11: 432.1313 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, 432.1314 - ontoArrayPrepend(args, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1315 - case 12: 432.1316 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, 432.1317 - ontoArrayPrepend(args, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1318 - case 13: 432.1319 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, 432.1320 - ontoArrayPrepend(args, arg14, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1321 - case 14: 432.1322 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1323 - ontoArrayPrepend(args, arg15, arg16, arg17, arg18, arg19, arg20)); 432.1324 - case 15: 432.1325 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1326 - arg15, ontoArrayPrepend(args, arg16, arg17, arg18, arg19, arg20)); 432.1327 - case 16: 432.1328 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1329 - arg15, arg16, ontoArrayPrepend(args, arg17, arg18, arg19, arg20)); 432.1330 - case 17: 432.1331 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1332 - arg15, arg16, arg17, ontoArrayPrepend(args, arg18, arg19, arg20)); 432.1333 - case 18: 432.1334 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1335 - arg15, arg16, arg17, arg18, ontoArrayPrepend(args, arg19, arg20)); 432.1336 - case 19: 432.1337 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1338 - arg15, arg16, arg17, arg18, arg19, ontoArrayPrepend(args, arg20)); 432.1339 - case 20: 432.1340 - return doInvoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, 432.1341 - arg15, arg16, arg17, arg18, arg19, arg20, ArraySeq.create(args)); 432.1342 - default: 432.1343 - return throwArity(21); 432.1344 - } 432.1345 - 432.1346 -} 432.1347 - 432.1348 - 432.1349 -protected static ISeq ontoArrayPrepend(Object[] array, Object... args){ 432.1350 - ISeq ret = ArraySeq.create(array); 432.1351 - for(int i = args.length - 1; i >= 0; --i) 432.1352 - ret = RT.cons(args[i], ret); 432.1353 - return ret; 432.1354 -} 432.1355 - 432.1356 -protected static ISeq findKey(Object key, ISeq args){ 432.1357 - while(args != null) 432.1358 - { 432.1359 - if(key == args.first()) 432.1360 - return args.next(); 432.1361 - args = RT.next(args); 432.1362 - args = RT.next(args); 432.1363 - } 432.1364 - return null; 432.1365 -} 432.1366 - 432.1367 - 432.1368 -} 432.1369 -
433.1 --- a/src/clojure/lang/Reversible.java Sat Aug 21 06:25:44 2010 -0400 433.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 433.3 @@ -1,17 +0,0 @@ 433.4 -/** 433.5 - * Copyright (c) Rich Hickey. All rights reserved. 433.6 - * The use and distribution terms for this software are covered by the 433.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 433.8 - * which can be found in the file epl-v10.html at the root of this distribution. 433.9 - * By using this software in any fashion, you are agreeing to be bound by 433.10 - * the terms of this license. 433.11 - * You must not remove this notice, or any other, from this software. 433.12 - **/ 433.13 - 433.14 -/* rich Jan 5, 2008 */ 433.15 - 433.16 -package clojure.lang; 433.17 - 433.18 -public interface Reversible{ 433.19 -ISeq rseq() throws Exception; 433.20 -}
434.1 --- a/src/clojure/lang/Script.java Sat Aug 21 06:25:44 2010 -0400 434.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 434.3 @@ -1,22 +0,0 @@ 434.4 -/** 434.5 - * Copyright (c) Rich Hickey. All rights reserved. 434.6 - * The use and distribution terms for this software are covered by the 434.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 434.8 - * which can be found in the file epl-v10.html at the root of this distribution. 434.9 - * By using this software in any fashion, you are agreeing to be bound by 434.10 - * the terms of this license. 434.11 - * You must not remove this notice, or any other, from this software. 434.12 - **/ 434.13 - 434.14 -/* rich Oct 18, 2007 */ 434.15 - 434.16 -package clojure.lang; 434.17 - 434.18 -import clojure.main; 434.19 - 434.20 -public class Script { 434.21 - 434.22 -public static void main(String[] args) throws Exception{ 434.23 - main.legacy_script(args); 434.24 -} 434.25 -}
435.1 --- a/src/clojure/lang/SeqEnumeration.java Sat Aug 21 06:25:44 2010 -0400 435.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 435.3 @@ -1,33 +0,0 @@ 435.4 -/** 435.5 - * Copyright (c) Rich Hickey. All rights reserved. 435.6 - * The use and distribution terms for this software are covered by the 435.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 435.8 - * which can be found in the file epl-v10.html at the root of this distribution. 435.9 - * By using this software in any fashion, you are agreeing to be bound by 435.10 - * the terms of this license. 435.11 - * You must not remove this notice, or any other, from this software. 435.12 - **/ 435.13 - 435.14 -/* rich Mar 3, 2008 */ 435.15 - 435.16 -package clojure.lang; 435.17 - 435.18 -import java.util.Enumeration; 435.19 - 435.20 -public class SeqEnumeration implements Enumeration{ 435.21 -ISeq seq; 435.22 - 435.23 -public SeqEnumeration(ISeq seq){ 435.24 - this.seq = seq; 435.25 -} 435.26 - 435.27 -public boolean hasMoreElements(){ 435.28 - return seq != null; 435.29 -} 435.30 - 435.31 -public Object nextElement(){ 435.32 - Object ret = RT.first(seq); 435.33 - seq = RT.next(seq); 435.34 - return ret; 435.35 -} 435.36 -}
436.1 --- a/src/clojure/lang/SeqIterator.java Sat Aug 21 06:25:44 2010 -0400 436.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 436.3 @@ -1,41 +0,0 @@ 436.4 -/** 436.5 - * Copyright (c) Rich Hickey. All rights reserved. 436.6 - * The use and distribution terms for this software are covered by the 436.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 436.8 - * which can be found in the file epl-v10.html at the root of this distribution. 436.9 - * By using this software in any fashion, you are agreeing to be bound by 436.10 - * the terms of this license. 436.11 - * You must not remove this notice, or any other, from this software. 436.12 - **/ 436.13 - 436.14 -/* rich Jun 19, 2007 */ 436.15 - 436.16 -package clojure.lang; 436.17 - 436.18 -import java.util.Iterator; 436.19 -import java.util.NoSuchElementException; 436.20 - 436.21 -public class SeqIterator implements Iterator{ 436.22 - 436.23 -ISeq seq; 436.24 - 436.25 -public SeqIterator(ISeq seq){ 436.26 - this.seq = seq; 436.27 -} 436.28 - 436.29 -public boolean hasNext(){ 436.30 - return seq != null; 436.31 -} 436.32 - 436.33 -public Object next() throws NoSuchElementException { 436.34 - if(seq == null) 436.35 - throw new NoSuchElementException(); 436.36 - Object ret = RT.first(seq); 436.37 - seq = RT.next(seq); 436.38 - return ret; 436.39 -} 436.40 - 436.41 -public void remove(){ 436.42 -throw new UnsupportedOperationException(); 436.43 -} 436.44 -}
437.1 --- a/src/clojure/lang/Seqable.java Sat Aug 21 06:25:44 2010 -0400 437.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 437.3 @@ -1,17 +0,0 @@ 437.4 -/** 437.5 - * Copyright (c) Rich Hickey. All rights reserved. 437.6 - * The use and distribution terms for this software are covered by the 437.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 437.8 - * which can be found in the file epl-v10.html at the root of this distribution. 437.9 - * By using this software in any fashion, you are agreeing to be bound by 437.10 - * the terms of this license. 437.11 - * You must not remove this notice, or any other, from this software. 437.12 - **/ 437.13 - 437.14 -/* rich Jan 28, 2009 */ 437.15 - 437.16 -package clojure.lang; 437.17 - 437.18 -public interface Seqable { 437.19 - ISeq seq(); 437.20 -}
438.1 --- a/src/clojure/lang/Sequential.java Sat Aug 21 06:25:44 2010 -0400 438.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 438.3 @@ -1,13 +0,0 @@ 438.4 -package clojure.lang; 438.5 - 438.6 -/** 438.7 - * Copyright (c) Rich Hickey. All rights reserved. 438.8 - * The use and distribution terms for this software are covered by the 438.9 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 438.10 - * which can be found in the file epl-v10.html at the root of this distribution. 438.11 - * By using this software in any fashion, you are agreeing to be bound by 438.12 - * the terms of this license. 438.13 - * You must not remove this notice, or any other, from this software. 438.14 - */ 438.15 -public interface Sequential { 438.16 -}
439.1 --- a/src/clojure/lang/Settable.java Sat Aug 21 06:25:44 2010 -0400 439.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 439.3 @@ -1,18 +0,0 @@ 439.4 -/** 439.5 - * Copyright (c) Rich Hickey. All rights reserved. 439.6 - * The use and distribution terms for this software are covered by the 439.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 439.8 - * which can be found in the file epl-v10.html at the root of this distribution. 439.9 - * By using this software in any fashion, you are agreeing to be bound by 439.10 - * the terms of this license. 439.11 - * You must not remove this notice, or any other, from this software. 439.12 - **/ 439.13 - 439.14 -/* rich Dec 31, 2008 */ 439.15 - 439.16 -package clojure.lang; 439.17 - 439.18 -public interface Settable { 439.19 - Object doSet(Object val) throws Exception; 439.20 - Object doReset(Object val) throws Exception; 439.21 -}
440.1 --- a/src/clojure/lang/Sorted.java Sat Aug 21 06:25:44 2010 -0400 440.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 440.3 @@ -1,25 +0,0 @@ 440.4 -/** 440.5 - * Copyright (c) Rich Hickey. All rights reserved. 440.6 - * The use and distribution terms for this software are covered by the 440.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 440.8 - * which can be found in the file epl-v10.html at the root of this distribution. 440.9 - * By using this software in any fashion, you are agreeing to be bound by 440.10 - * the terms of this license. 440.11 - * You must not remove this notice, or any other, from this software. 440.12 - **/ 440.13 - 440.14 -/* rich Apr 15, 2008 */ 440.15 - 440.16 -package clojure.lang; 440.17 - 440.18 -import java.util.Comparator; 440.19 - 440.20 -public interface Sorted{ 440.21 -Comparator comparator(); 440.22 - 440.23 -Object entryKey(Object entry); 440.24 - 440.25 -ISeq seq(boolean ascending); 440.26 - 440.27 -ISeq seqFrom(Object key, boolean ascending); 440.28 -}
441.1 --- a/src/clojure/lang/StringSeq.java Sat Aug 21 06:25:44 2010 -0400 441.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 441.3 @@ -1,54 +0,0 @@ 441.4 -/** 441.5 - * Copyright (c) Rich Hickey. All rights reserved. 441.6 - * The use and distribution terms for this software are covered by the 441.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 441.8 - * which can be found in the file epl-v10.html at the root of this distribution. 441.9 - * By using this software in any fashion, you are agreeing to be bound by 441.10 - * the terms of this license. 441.11 - * You must not remove this notice, or any other, from this software. 441.12 - **/ 441.13 - 441.14 -/* rich Dec 6, 2007 */ 441.15 - 441.16 -package clojure.lang; 441.17 - 441.18 -public class StringSeq extends ASeq implements IndexedSeq{ 441.19 -public final CharSequence s; 441.20 -public final int i; 441.21 - 441.22 -static public StringSeq create(CharSequence s){ 441.23 - if(s.length() == 0) 441.24 - return null; 441.25 - return new StringSeq(null, s, 0); 441.26 -} 441.27 - 441.28 -StringSeq(IPersistentMap meta, CharSequence s, int i){ 441.29 - super(meta); 441.30 - this.s = s; 441.31 - this.i = i; 441.32 -} 441.33 - 441.34 -public Obj withMeta(IPersistentMap meta){ 441.35 - if(meta == meta()) 441.36 - return this; 441.37 - return new StringSeq(meta, s, i); 441.38 -} 441.39 - 441.40 -public Object first(){ 441.41 - return Character.valueOf(s.charAt(i)); 441.42 -} 441.43 - 441.44 -public ISeq next(){ 441.45 - if(i + 1 < s.length()) 441.46 - return new StringSeq(_meta, s, i + 1); 441.47 - return null; 441.48 -} 441.49 - 441.50 -public int index(){ 441.51 - return i; 441.52 -} 441.53 - 441.54 -public int count(){ 441.55 - return s.length() - i; 441.56 -} 441.57 -}
442.1 --- a/src/clojure/lang/Symbol.java Sat Aug 21 06:25:44 2010 -0400 442.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 442.3 @@ -1,126 +0,0 @@ 442.4 -/** 442.5 - * Copyright (c) Rich Hickey. All rights reserved. 442.6 - * The use and distribution terms for this software are covered by the 442.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 442.8 - * which can be found in the file epl-v10.html at the root of this distribution. 442.9 - * By using this software in any fashion, you are agreeing to be bound by 442.10 - * the terms of this license. 442.11 - * You must not remove this notice, or any other, from this software. 442.12 - **/ 442.13 - 442.14 -/* rich Mar 25, 2006 11:42:47 AM */ 442.15 - 442.16 -package clojure.lang; 442.17 - 442.18 -import java.io.Serializable; 442.19 -import java.io.ObjectStreamException; 442.20 - 442.21 - 442.22 -public class Symbol extends AFn implements IObj, Comparable, Named, Serializable{ 442.23 -//these must be interned strings! 442.24 -final String ns; 442.25 -final String name; 442.26 -final int hash; 442.27 -final IPersistentMap _meta; 442.28 - 442.29 -public String toString(){ 442.30 - if(ns != null) 442.31 - return ns + "/" + name; 442.32 - return name; 442.33 -} 442.34 - 442.35 -public String getNamespace(){ 442.36 - return ns; 442.37 -} 442.38 - 442.39 -public String getName(){ 442.40 - return name; 442.41 -} 442.42 - 442.43 -static public Symbol intern(String ns, String name){ 442.44 - return new Symbol(ns == null ? null : ns.intern(), name.intern()); 442.45 -} 442.46 - 442.47 -static public Symbol intern(String nsname){ 442.48 - int i = nsname.lastIndexOf('/'); 442.49 - if(i == -1 || nsname.equals("/")) 442.50 - return new Symbol(null, nsname.intern()); 442.51 - else 442.52 - return new Symbol(nsname.substring(0, i).intern(), nsname.substring(i + 1).intern()); 442.53 -} 442.54 - 442.55 -static public Symbol create(String name_interned){ 442.56 - return new Symbol(null, name_interned); 442.57 -} 442.58 - 442.59 -static public Symbol create(String ns_interned, String name_interned){ 442.60 - return new Symbol(ns_interned, name_interned); 442.61 -} 442.62 - 442.63 -private Symbol(String ns_interned, String name_interned){ 442.64 - this.name = name_interned; 442.65 - this.ns = ns_interned; 442.66 - this.hash = Util.hashCombine(name.hashCode(), Util.hash(ns)); 442.67 - this._meta = null; 442.68 -} 442.69 - 442.70 -public boolean equals(Object o){ 442.71 - if(this == o) 442.72 - return true; 442.73 - if(!(o instanceof Symbol)) 442.74 - return false; 442.75 - 442.76 - Symbol symbol = (Symbol) o; 442.77 - 442.78 - //identity compares intended, names are interned 442.79 - return name == symbol.name && ns == symbol.ns; 442.80 -} 442.81 - 442.82 -public int hashCode(){ 442.83 - return hash; 442.84 -} 442.85 - 442.86 -public IObj withMeta(IPersistentMap meta){ 442.87 - return new Symbol(meta, ns, name); 442.88 -} 442.89 - 442.90 -private Symbol(IPersistentMap meta, String ns, String name){ 442.91 - this.name = name; 442.92 - this.ns = ns; 442.93 - this._meta = meta; 442.94 - this.hash = Util.hashCombine(name.hashCode(), Util.hash(ns)); 442.95 -} 442.96 - 442.97 -public int compareTo(Object o){ 442.98 - Symbol s = (Symbol) o; 442.99 - if(this.equals(o)) 442.100 - return 0; 442.101 - if(this.ns == null && s.ns != null) 442.102 - return -1; 442.103 - if(this.ns != null) 442.104 - { 442.105 - if(s.ns == null) 442.106 - return 1; 442.107 - int nsc = this.ns.compareTo(s.ns); 442.108 - if(nsc != 0) 442.109 - return nsc; 442.110 - } 442.111 - return this.name.compareTo(s.name); 442.112 -} 442.113 - 442.114 -private Object readResolve() throws ObjectStreamException{ 442.115 - return intern(ns, name); 442.116 -} 442.117 - 442.118 -public Object invoke(Object obj) throws Exception{ 442.119 - return RT.get(obj, this); 442.120 -} 442.121 - 442.122 -public Object invoke(Object obj, Object notFound) throws Exception{ 442.123 - return RT.get(obj, this, notFound); 442.124 -} 442.125 - 442.126 -public IPersistentMap meta(){ 442.127 - return _meta; 442.128 -} 442.129 -}
443.1 --- a/src/clojure/lang/TransactionalHashMap.java Sat Aug 21 06:25:44 2010 -0400 443.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 443.3 @@ -1,197 +0,0 @@ 443.4 -/** 443.5 - * Copyright (c) Rich Hickey. All rights reserved. 443.6 - * The use and distribution terms for this software are covered by the 443.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 443.8 - * which can be found in the file epl-v10.html at the root of this distribution. 443.9 - * By using this software in any fashion, you are agreeing to be bound by 443.10 - * the terms of this license. 443.11 - * You must not remove this notice, or any other, from this software. 443.12 - **/ 443.13 - 443.14 -/* rich Jul 31, 2008 */ 443.15 - 443.16 -package clojure.lang; 443.17 - 443.18 -import java.util.concurrent.ConcurrentMap; 443.19 -import java.util.*; 443.20 - 443.21 -public class TransactionalHashMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K, V>{ 443.22 -final Ref[] bins; 443.23 - 443.24 -IPersistentMap mapAt(int bin){ 443.25 - return (IPersistentMap) bins[bin].deref(); 443.26 -} 443.27 - 443.28 -final int binFor(Object k){ 443.29 - //spread hashes, a la Cliff Click 443.30 - int h = k.hashCode(); 443.31 - h ^= (h >>> 20) ^ (h >>> 12); 443.32 - h ^= (h >>> 7) ^ (h >>> 4); 443.33 - return h % bins.length; 443.34 -// return k.hashCode() % bins.length; 443.35 -} 443.36 - 443.37 -Entry entryAt(Object k){ 443.38 - return mapAt(binFor(k)).entryAt(k); 443.39 -} 443.40 - 443.41 -public TransactionalHashMap() throws Exception{ 443.42 - this(421); 443.43 -} 443.44 - 443.45 -public TransactionalHashMap(int nBins) throws Exception{ 443.46 - bins = new Ref[nBins]; 443.47 - for(int i = 0; i < nBins; i++) 443.48 - bins[i] = new Ref(PersistentHashMap.EMPTY); 443.49 -} 443.50 - 443.51 -public TransactionalHashMap(Map<? extends K, ? extends V> m) throws Exception{ 443.52 - this(m.size()); 443.53 - putAll(m); 443.54 -} 443.55 - 443.56 -public int size(){ 443.57 - int n = 0; 443.58 - for(int i = 0; i < bins.length; i++) 443.59 - { 443.60 - n += mapAt(i).count(); 443.61 - } 443.62 - return n; 443.63 -} 443.64 - 443.65 -public boolean isEmpty(){ 443.66 - return size() == 0; 443.67 -} 443.68 - 443.69 -public boolean containsKey(Object k){ 443.70 - return entryAt(k) != null; 443.71 -} 443.72 - 443.73 -public V get(Object k){ 443.74 - Entry e = entryAt(k); 443.75 - if(e != null) 443.76 - return (V) e.getValue(); 443.77 - return null; 443.78 -} 443.79 - 443.80 -public V put(K k, V v){ 443.81 - Ref r = bins[binFor(k)]; 443.82 - IPersistentMap map = (IPersistentMap) r.deref(); 443.83 - Object ret = map.valAt(k); 443.84 - r.set(map.assoc(k, v)); 443.85 - return (V) ret; 443.86 -} 443.87 - 443.88 -public V remove(Object k){ 443.89 - Ref r = bins[binFor(k)]; 443.90 - IPersistentMap map = (IPersistentMap) r.deref(); 443.91 - Object ret = map.valAt(k); 443.92 - //checked exceptions are a bad idea, especially in an interface 443.93 - try 443.94 - { 443.95 - r.set(map.without(k)); 443.96 - } 443.97 - catch(Exception e) 443.98 - { 443.99 - throw new RuntimeException(e); 443.100 - } 443.101 - return (V) ret; 443.102 -} 443.103 - 443.104 -public void putAll(Map<? extends K, ? extends V> map){ 443.105 - for(Iterator i = map.entrySet().iterator(); i.hasNext();) 443.106 - { 443.107 - Entry<K, V> e = (Entry) i.next(); 443.108 - put(e.getKey(), e.getValue()); 443.109 - } 443.110 -} 443.111 - 443.112 -public void clear(){ 443.113 - for(int i = 0; i < bins.length; i++) 443.114 - { 443.115 - Ref r = bins[i]; 443.116 - IPersistentMap map = (IPersistentMap) r.deref(); 443.117 - if(map.count() > 0) 443.118 - { 443.119 - r.set(PersistentHashMap.EMPTY); 443.120 - } 443.121 - } 443.122 -} 443.123 - 443.124 -public Set<Entry<K, V>> entrySet(){ 443.125 - final ArrayList<Map.Entry<K, V>> entries = new ArrayList(bins.length); 443.126 - for(int i = 0; i < bins.length; i++) 443.127 - { 443.128 - IPersistentMap map = mapAt(i); 443.129 - if(map.count() > 0) 443.130 - entries.addAll((Collection) RT.seq(map)); 443.131 - } 443.132 - return new AbstractSet<Entry<K, V>>(){ 443.133 - public Iterator iterator(){ 443.134 - return Collections.unmodifiableList(entries).iterator(); 443.135 - } 443.136 - 443.137 - public int size(){ 443.138 - return entries.size(); 443.139 - } 443.140 - }; 443.141 -} 443.142 - 443.143 -public V putIfAbsent(K k, V v){ 443.144 - Ref r = bins[binFor(k)]; 443.145 - IPersistentMap map = (IPersistentMap) r.deref(); 443.146 - Entry e = map.entryAt(k); 443.147 - if(e == null) 443.148 - { 443.149 - r.set(map.assoc(k, v)); 443.150 - return null; 443.151 - } 443.152 - else 443.153 - return (V) e.getValue(); 443.154 -} 443.155 - 443.156 -public boolean remove(Object k, Object v){ 443.157 - Ref r = bins[binFor(k)]; 443.158 - IPersistentMap map = (IPersistentMap) r.deref(); 443.159 - Entry e = map.entryAt(k); 443.160 - if(e != null && e.getValue().equals(v)) 443.161 - { 443.162 - //checked exceptions are a bad idea, especially in an interface 443.163 - try 443.164 - { 443.165 - r.set(map.without(k)); 443.166 - } 443.167 - catch(Exception ex) 443.168 - { 443.169 - throw new RuntimeException(ex); 443.170 - } 443.171 - return true; 443.172 - } 443.173 - return false; 443.174 -} 443.175 - 443.176 -public boolean replace(K k, V oldv, V newv){ 443.177 - Ref r = bins[binFor(k)]; 443.178 - IPersistentMap map = (IPersistentMap) r.deref(); 443.179 - Entry e = map.entryAt(k); 443.180 - if(e != null && e.getValue().equals(oldv)) 443.181 - { 443.182 - r.set(map.assoc(k, newv)); 443.183 - return true; 443.184 - } 443.185 - return false; 443.186 -} 443.187 - 443.188 -public V replace(K k, V v){ 443.189 - Ref r = bins[binFor(k)]; 443.190 - IPersistentMap map = (IPersistentMap) r.deref(); 443.191 - Entry e = map.entryAt(k); 443.192 - if(e != null) 443.193 - { 443.194 - r.set(map.assoc(k, v)); 443.195 - return (V) e.getValue(); 443.196 - } 443.197 - return null; 443.198 -} 443.199 - 443.200 -}
444.1 --- a/src/clojure/lang/Util.java Sat Aug 21 06:25:44 2010 -0400 444.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 444.3 @@ -1,116 +0,0 @@ 444.4 -/** 444.5 - * Copyright (c) Rich Hickey. All rights reserved. 444.6 - * The use and distribution terms for this software are covered by the 444.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 444.8 - * which can be found in the file epl-v10.html at the root of this distribution. 444.9 - * By using this software in any fashion, you are agreeing to be bound by 444.10 - * the terms of this license. 444.11 - * You must not remove this notice, or any other, from this software. 444.12 - **/ 444.13 - 444.14 -/* rich Apr 19, 2008 */ 444.15 - 444.16 -package clojure.lang; 444.17 - 444.18 -import java.math.BigInteger; 444.19 -import java.util.Map; 444.20 -import java.util.concurrent.ConcurrentHashMap; 444.21 -import java.lang.ref.SoftReference; 444.22 -import java.lang.ref.ReferenceQueue; 444.23 -import java.lang.ref.Reference; 444.24 - 444.25 -public class Util{ 444.26 -static public boolean equiv(Object k1, Object k2){ 444.27 - if(k1 == k2) 444.28 - return true; 444.29 - if(k1 != null) 444.30 - { 444.31 - if(k1 instanceof Number && k2 instanceof Number) 444.32 - return Numbers.equiv(k1, k2); 444.33 - else if(k1 instanceof IPersistentCollection || k2 instanceof IPersistentCollection) 444.34 - return pcequiv(k1,k2); 444.35 - return k1.equals(k2); 444.36 - } 444.37 - return false; 444.38 -} 444.39 - 444.40 -static public boolean pcequiv(Object k1, Object k2){ 444.41 - if(k1 instanceof IPersistentCollection) 444.42 - return ((IPersistentCollection)k1).equiv(k2); 444.43 - return ((IPersistentCollection)k2).equiv(k1); 444.44 -} 444.45 - 444.46 -static public boolean equals(Object k1, Object k2){ 444.47 - if(k1 == k2) 444.48 - return true; 444.49 - return k1 != null && k1.equals(k2); 444.50 -} 444.51 - 444.52 -static public boolean identical(Object k1, Object k2){ 444.53 - return k1 == k2; 444.54 -} 444.55 - 444.56 -static public Class classOf(Object x){ 444.57 - if(x != null) 444.58 - return x.getClass(); 444.59 - return null; 444.60 -} 444.61 - 444.62 -static public int compare(Object k1, Object k2){ 444.63 - if(k1 == k2) 444.64 - return 0; 444.65 - if(k1 != null) 444.66 - { 444.67 - if(k2 == null) 444.68 - return 1; 444.69 - if(k1 instanceof Number) 444.70 - return Numbers.compare((Number) k1, (Number) k2); 444.71 - return ((Comparable) k1).compareTo(k2); 444.72 - } 444.73 - return -1; 444.74 -} 444.75 - 444.76 -static public int hash(Object o){ 444.77 - if(o == null) 444.78 - return 0; 444.79 - return o.hashCode(); 444.80 -} 444.81 - 444.82 -static public int hashCombine(int seed, int hash){ 444.83 - //a la boost 444.84 - seed ^= hash + 0x9e3779b9 + (seed << 6) + (seed >> 2); 444.85 - return seed; 444.86 -} 444.87 - 444.88 -static public boolean isPrimitive(Class c){ 444.89 - return c != null && c.isPrimitive() && !(c == Void.TYPE); 444.90 -} 444.91 - 444.92 -static public boolean isInteger(Object x){ 444.93 - return x instanceof Integer 444.94 - || x instanceof Long 444.95 - || x instanceof BigInteger; 444.96 -} 444.97 - 444.98 -static public Object ret1(Object ret, Object nil){ 444.99 - return ret; 444.100 -} 444.101 - 444.102 -static public ISeq ret1(ISeq ret, Object nil){ 444.103 - return ret; 444.104 -} 444.105 - 444.106 -static public <K,V> void clearCache(ReferenceQueue rq, ConcurrentHashMap<K, SoftReference<V>> cache){ 444.107 - //cleanup any dead entries 444.108 - if(rq.poll() != null) 444.109 - { 444.110 - while(rq.poll() != null) 444.111 - ; 444.112 - for(Map.Entry<K, SoftReference<V>> e : cache.entrySet()) 444.113 - { 444.114 - if(e.getValue().get() == null) 444.115 - cache.remove(e.getKey(), e.getValue()); 444.116 - } 444.117 - } 444.118 -} 444.119 -}
445.1 --- a/src/clojure/lang/Var.java Sat Aug 21 06:25:44 2010 -0400 445.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 445.3 @@ -1,497 +0,0 @@ 445.4 -/** 445.5 - * Copyright (c) Rich Hickey. All rights reserved. 445.6 - * The use and distribution terms for this software are covered by the 445.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 445.8 - * which can be found in the file epl-v10.html at the root of this distribution. 445.9 - * By using this software in any fashion, you are agreeing to be bound by 445.10 - * the terms of this license. 445.11 - * You must not remove this notice, or any other, from this software. 445.12 - **/ 445.13 - 445.14 -/* rich Jul 31, 2007 */ 445.15 - 445.16 -package clojure.lang; 445.17 - 445.18 -import java.util.concurrent.atomic.AtomicInteger; 445.19 - 445.20 - 445.21 -public final class Var extends ARef implements IFn, IRef, Settable{ 445.22 - 445.23 - 445.24 -static class Frame{ 445.25 - //Var->Box 445.26 - Associative bindings; 445.27 - //Var->val 445.28 - Associative frameBindings; 445.29 - Frame prev; 445.30 - 445.31 - 445.32 - public Frame(){ 445.33 - this(PersistentHashMap.EMPTY, PersistentHashMap.EMPTY, null); 445.34 - } 445.35 - 445.36 - public Frame(Associative frameBindings, Associative bindings, Frame prev){ 445.37 - this.frameBindings = frameBindings; 445.38 - this.bindings = bindings; 445.39 - this.prev = prev; 445.40 - } 445.41 -} 445.42 - 445.43 -static ThreadLocal<Frame> dvals = new ThreadLocal<Frame>(){ 445.44 - 445.45 - protected Frame initialValue(){ 445.46 - return new Frame(); 445.47 - } 445.48 -}; 445.49 - 445.50 -static Keyword privateKey = Keyword.intern(null, "private"); 445.51 -static IPersistentMap privateMeta = new PersistentArrayMap(new Object[]{privateKey, Boolean.TRUE}); 445.52 -static Keyword macroKey = Keyword.intern(null, "macro"); 445.53 -static Keyword nameKey = Keyword.intern(null, "name"); 445.54 -static Keyword nsKey = Keyword.intern(null, "ns"); 445.55 -//static Keyword tagKey = Keyword.intern(null, "tag"); 445.56 - 445.57 -volatile Object root; 445.58 -transient final AtomicInteger count; 445.59 -public final Symbol sym; 445.60 -public final Namespace ns; 445.61 - 445.62 -//IPersistentMap _meta; 445.63 - 445.64 -public static Var intern(Namespace ns, Symbol sym, Object root){ 445.65 - return intern(ns, sym, root, true); 445.66 -} 445.67 - 445.68 -public static Var intern(Namespace ns, Symbol sym, Object root, boolean replaceRoot){ 445.69 - Var dvout = ns.intern(sym); 445.70 - if(!dvout.hasRoot() || replaceRoot) 445.71 - dvout.bindRoot(root); 445.72 - return dvout; 445.73 -} 445.74 - 445.75 - 445.76 -public String toString(){ 445.77 - if(ns != null) 445.78 - return "#'" + ns.name + "/" + sym; 445.79 - return "#<Var: " + (sym != null ? sym.toString() : "--unnamed--") + ">"; 445.80 -} 445.81 - 445.82 -public static Var find(Symbol nsQualifiedSym){ 445.83 - if(nsQualifiedSym.ns == null) 445.84 - throw new IllegalArgumentException("Symbol must be namespace-qualified"); 445.85 - Namespace ns = Namespace.find(Symbol.create(nsQualifiedSym.ns)); 445.86 - if(ns == null) 445.87 - throw new IllegalArgumentException("No such namespace: " + nsQualifiedSym.ns); 445.88 - return ns.findInternedVar(Symbol.create(nsQualifiedSym.name)); 445.89 -} 445.90 - 445.91 -public static Var intern(Symbol nsName, Symbol sym){ 445.92 - Namespace ns = Namespace.findOrCreate(nsName); 445.93 - return intern(ns, sym); 445.94 -} 445.95 - 445.96 -public static Var internPrivate(String nsName, String sym){ 445.97 - Namespace ns = Namespace.findOrCreate(Symbol.intern(nsName)); 445.98 - Var ret = intern(ns, Symbol.intern(sym)); 445.99 - ret.setMeta(privateMeta); 445.100 - return ret; 445.101 -} 445.102 - 445.103 -public static Var intern(Namespace ns, Symbol sym){ 445.104 - return ns.intern(sym); 445.105 -} 445.106 - 445.107 - 445.108 -public static Var create(){ 445.109 - return new Var(null, null); 445.110 -} 445.111 - 445.112 -public static Var create(Object root){ 445.113 - return new Var(null, null, root); 445.114 -} 445.115 - 445.116 -Var(Namespace ns, Symbol sym){ 445.117 - this.ns = ns; 445.118 - this.sym = sym; 445.119 - this.count = new AtomicInteger(); 445.120 - this.root = dvals; //use dvals as magic not-bound value 445.121 - setMeta(PersistentHashMap.EMPTY); 445.122 -} 445.123 - 445.124 -Var(Namespace ns, Symbol sym, Object root){ 445.125 - this(ns, sym); 445.126 - this.root = root; 445.127 -} 445.128 - 445.129 -public boolean isBound(){ 445.130 - return hasRoot() || (count.get() > 0 && dvals.get().bindings.containsKey(this)); 445.131 -} 445.132 - 445.133 -final public Object get(){ 445.134 - if(count.get() == 0 && root != dvals) 445.135 - return root; 445.136 - return deref(); 445.137 -} 445.138 - 445.139 -final public Object deref(){ 445.140 - Box b = getThreadBinding(); 445.141 - if(b != null) 445.142 - return b.val; 445.143 - if(hasRoot()) 445.144 - return root; 445.145 - throw new IllegalStateException(String.format("Var %s/%s is unbound.", ns, sym)); 445.146 -} 445.147 - 445.148 -public void setValidator(IFn vf){ 445.149 - if(hasRoot()) 445.150 - validate(vf, getRoot()); 445.151 - validator = vf; 445.152 -} 445.153 - 445.154 -public Object alter(IFn fn, ISeq args) throws Exception{ 445.155 - set(fn.applyTo(RT.cons(deref(), args))); 445.156 - return this; 445.157 -} 445.158 - 445.159 -public Object set(Object val){ 445.160 - validate(getValidator(), val); 445.161 - Box b = getThreadBinding(); 445.162 - if(b != null) 445.163 - return (b.val = val); 445.164 - //jury still out on this 445.165 -// if(hasRoot()) 445.166 -// { 445.167 -// bindRoot(val); 445.168 -// return val; 445.169 -// } 445.170 - throw new IllegalStateException(String.format("Can't change/establish root binding of: %s with set", sym)); 445.171 -} 445.172 - 445.173 -public Object doSet(Object val) throws Exception { 445.174 - return set(val); 445.175 - } 445.176 - 445.177 -public Object doReset(Object val) throws Exception { 445.178 - bindRoot(val); 445.179 - return val; 445.180 - } 445.181 - 445.182 -public void setMeta(IPersistentMap m) { 445.183 - //ensure these basis keys 445.184 - resetMeta(m.assoc(nameKey, sym).assoc(nsKey, ns)); 445.185 -} 445.186 - 445.187 -public void setMacro() { 445.188 - try 445.189 - { 445.190 - alterMeta(assoc, RT.list(macroKey, RT.T)); 445.191 - } 445.192 - catch (Exception e) 445.193 - { 445.194 - throw new RuntimeException(e); 445.195 - } 445.196 -} 445.197 - 445.198 -public boolean isMacro(){ 445.199 - return RT.booleanCast(meta().valAt(macroKey)); 445.200 -} 445.201 - 445.202 -//public void setExported(boolean state){ 445.203 -// _meta = _meta.assoc(privateKey, state); 445.204 -//} 445.205 - 445.206 -public boolean isPublic(){ 445.207 - return !RT.booleanCast(meta().valAt(privateKey)); 445.208 -} 445.209 - 445.210 -public Object getRoot(){ 445.211 - if(hasRoot()) 445.212 - return root; 445.213 - throw new IllegalStateException(String.format("Var %s/%s is unbound.", ns, sym)); 445.214 -} 445.215 - 445.216 -public Object getRawRoot(){ 445.217 - return root; 445.218 -} 445.219 - 445.220 -public Object getTag(){ 445.221 - return meta().valAt(RT.TAG_KEY); 445.222 -} 445.223 - 445.224 -public void setTag(Symbol tag) { 445.225 - try 445.226 - { 445.227 - alterMeta(assoc, RT.list(RT.TAG_KEY, tag)); 445.228 - } 445.229 - catch (Exception e) 445.230 - { 445.231 - throw new RuntimeException(e); 445.232 - } 445.233 -} 445.234 - 445.235 -final public boolean hasRoot(){ 445.236 - return root != dvals; 445.237 -} 445.238 - 445.239 -//binding root always clears macro flag 445.240 -synchronized public void bindRoot(Object root){ 445.241 - validate(getValidator(), root); 445.242 - Object oldroot = hasRoot()?this.root:null; 445.243 - this.root = root; 445.244 - try 445.245 - { 445.246 - alterMeta(dissoc, RT.list(macroKey)); 445.247 - } 445.248 - catch (Exception e) 445.249 - { 445.250 - throw new RuntimeException(e); 445.251 - } 445.252 - notifyWatches(oldroot,this.root); 445.253 -} 445.254 - 445.255 -synchronized void swapRoot(Object root){ 445.256 - validate(getValidator(), root); 445.257 - Object oldroot = hasRoot()?this.root:null; 445.258 - this.root = root; 445.259 - notifyWatches(oldroot,root); 445.260 -} 445.261 - 445.262 -synchronized public void unbindRoot(){ 445.263 - this.root = dvals; 445.264 -} 445.265 - 445.266 -synchronized public void commuteRoot(IFn fn) throws Exception{ 445.267 - Object newRoot = fn.invoke(root); 445.268 - validate(getValidator(), newRoot); 445.269 - Object oldroot = getRoot(); 445.270 - this.root = newRoot; 445.271 - notifyWatches(oldroot,newRoot); 445.272 -} 445.273 - 445.274 -synchronized public Object alterRoot(IFn fn, ISeq args) throws Exception{ 445.275 - Object newRoot = fn.applyTo(RT.cons(root, args)); 445.276 - validate(getValidator(), newRoot); 445.277 - Object oldroot = getRoot(); 445.278 - this.root = newRoot; 445.279 - notifyWatches(oldroot,newRoot); 445.280 - return newRoot; 445.281 -} 445.282 - 445.283 -public static void pushThreadBindings(Associative bindings){ 445.284 - Frame f = dvals.get(); 445.285 - Associative bmap = f.bindings; 445.286 - for(ISeq bs = bindings.seq(); bs != null; bs = bs.next()) 445.287 - { 445.288 - IMapEntry e = (IMapEntry) bs.first(); 445.289 - Var v = (Var) e.key(); 445.290 - v.validate(v.getValidator(), e.val()); 445.291 - v.count.incrementAndGet(); 445.292 - bmap = bmap.assoc(v, new Box(e.val())); 445.293 - } 445.294 - dvals.set(new Frame(bindings, bmap, f)); 445.295 -} 445.296 - 445.297 -public static void popThreadBindings(){ 445.298 - Frame f = dvals.get(); 445.299 - if(f.prev == null) 445.300 - throw new IllegalStateException("Pop without matching push"); 445.301 - for(ISeq bs = RT.keys(f.frameBindings); bs != null; bs = bs.next()) 445.302 - { 445.303 - Var v = (Var) bs.first(); 445.304 - v.count.decrementAndGet(); 445.305 - } 445.306 - dvals.set(f.prev); 445.307 -} 445.308 - 445.309 -public static void releaseThreadBindings(){ 445.310 - Frame f = dvals.get(); 445.311 - if(f.prev == null) 445.312 - throw new IllegalStateException("Release without full unwind"); 445.313 - for(ISeq bs = RT.keys(f.bindings); bs != null; bs = bs.next()) 445.314 - { 445.315 - Var v = (Var) bs.first(); 445.316 - v.count.decrementAndGet(); 445.317 - } 445.318 - dvals.set(null); 445.319 -} 445.320 - 445.321 -public static Associative getThreadBindings(){ 445.322 - Frame f = dvals.get(); 445.323 - IPersistentMap ret = PersistentHashMap.EMPTY; 445.324 - for(ISeq bs = f.bindings.seq(); bs != null; bs = bs.next()) 445.325 - { 445.326 - IMapEntry e = (IMapEntry) bs.first(); 445.327 - Var v = (Var) e.key(); 445.328 - Box b = (Box) e.val(); 445.329 - ret = ret.assoc(v, b.val); 445.330 - } 445.331 - return ret; 445.332 -} 445.333 - 445.334 -public final Box getThreadBinding(){ 445.335 - if(count.get() > 0) 445.336 - { 445.337 - IMapEntry e = dvals.get().bindings.entryAt(this); 445.338 - if(e != null) 445.339 - return (Box) e.val(); 445.340 - } 445.341 - return null; 445.342 -} 445.343 - 445.344 -final public IFn fn(){ 445.345 - return (IFn) deref(); 445.346 -} 445.347 - 445.348 -public Object call() throws Exception{ 445.349 - return invoke(); 445.350 -} 445.351 - 445.352 -public void run(){ 445.353 - try 445.354 - { 445.355 - invoke(); 445.356 - } 445.357 - catch(Exception e) 445.358 - { 445.359 - throw new RuntimeException(e); 445.360 - } 445.361 -} 445.362 - 445.363 -public Object invoke() throws Exception{ 445.364 - return fn().invoke(); 445.365 -} 445.366 - 445.367 -public Object invoke(Object arg1) throws Exception{ 445.368 - return fn().invoke(arg1); 445.369 -} 445.370 - 445.371 -public Object invoke(Object arg1, Object arg2) throws Exception{ 445.372 - return fn().invoke(arg1, arg2); 445.373 -} 445.374 - 445.375 -public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception{ 445.376 - return fn().invoke(arg1, arg2, arg3); 445.377 -} 445.378 - 445.379 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception{ 445.380 - return fn().invoke(arg1, arg2, arg3, arg4); 445.381 -} 445.382 - 445.383 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception{ 445.384 - return fn().invoke(arg1, arg2, arg3, arg4, arg5); 445.385 -} 445.386 - 445.387 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception{ 445.388 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6); 445.389 -} 445.390 - 445.391 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) 445.392 - throws Exception{ 445.393 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7); 445.394 -} 445.395 - 445.396 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.397 - Object arg8) throws Exception{ 445.398 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); 445.399 -} 445.400 - 445.401 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.402 - Object arg8, Object arg9) throws Exception{ 445.403 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); 445.404 -} 445.405 - 445.406 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.407 - Object arg8, Object arg9, Object arg10) throws Exception{ 445.408 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); 445.409 -} 445.410 - 445.411 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.412 - Object arg8, Object arg9, Object arg10, Object arg11) throws Exception{ 445.413 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); 445.414 -} 445.415 - 445.416 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.417 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception{ 445.418 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); 445.419 -} 445.420 - 445.421 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.422 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) 445.423 - throws Exception{ 445.424 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); 445.425 -} 445.426 - 445.427 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.428 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) 445.429 - throws Exception{ 445.430 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); 445.431 -} 445.432 - 445.433 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.434 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 445.435 - Object arg15) throws Exception{ 445.436 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); 445.437 -} 445.438 - 445.439 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.440 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 445.441 - Object arg15, Object arg16) throws Exception{ 445.442 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 445.443 - arg16); 445.444 -} 445.445 - 445.446 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.447 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 445.448 - Object arg15, Object arg16, Object arg17) throws Exception{ 445.449 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 445.450 - arg16, arg17); 445.451 -} 445.452 - 445.453 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.454 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 445.455 - Object arg15, Object arg16, Object arg17, Object arg18) throws Exception{ 445.456 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 445.457 - arg16, arg17, arg18); 445.458 -} 445.459 - 445.460 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.461 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 445.462 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception{ 445.463 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 445.464 - arg16, arg17, arg18, arg19); 445.465 -} 445.466 - 445.467 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.468 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 445.469 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20) 445.470 - throws Exception{ 445.471 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 445.472 - arg16, arg17, arg18, arg19, arg20); 445.473 -} 445.474 - 445.475 -public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, 445.476 - Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, 445.477 - Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20, 445.478 - Object... args) 445.479 - throws Exception{ 445.480 - return fn().invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, 445.481 - arg16, arg17, arg18, arg19, arg20, args); 445.482 -} 445.483 - 445.484 -public Object applyTo(ISeq arglist) throws Exception{ 445.485 - return AFn.applyToHelper(this, arglist); 445.486 -} 445.487 - 445.488 -static IFn assoc = new AFn(){ 445.489 - @Override 445.490 - public Object invoke(Object m, Object k, Object v) throws Exception { 445.491 - return RT.assoc(m, k, v); 445.492 - } 445.493 -}; 445.494 -static IFn dissoc = new AFn() { 445.495 - @Override 445.496 - public Object invoke(Object c, Object k) throws Exception { 445.497 - return RT.dissoc(c, k); 445.498 - } 445.499 -}; 445.500 -}
446.1 --- a/src/clojure/lang/XMLHandler.java Sat Aug 21 06:25:44 2010 -0400 446.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 446.3 @@ -1,89 +0,0 @@ 446.4 -/** 446.5 - * Copyright (c) Rich Hickey. All rights reserved. 446.6 - * The use and distribution terms for this software are covered by the 446.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 446.8 - * which can be found in the file epl-v10.html at the root of this distribution. 446.9 - * By using this software in any fashion, you are agreeing to be bound by 446.10 - * the terms of this license. 446.11 - * You must not remove this notice, or any other, from this software. 446.12 - **/ 446.13 - 446.14 -/* rich Dec 17, 2007 */ 446.15 - 446.16 -package clojure.lang; 446.17 - 446.18 -import org.xml.sax.Attributes; 446.19 -import org.xml.sax.ContentHandler; 446.20 -import org.xml.sax.Locator; 446.21 -import org.xml.sax.SAXException; 446.22 -import org.xml.sax.helpers.DefaultHandler; 446.23 - 446.24 -public class XMLHandler extends DefaultHandler{ 446.25 -ContentHandler h; 446.26 - 446.27 - 446.28 -public XMLHandler(ContentHandler h){ 446.29 - this.h = h; 446.30 -} 446.31 - 446.32 -public void setDocumentLocator(Locator locator){ 446.33 - h.setDocumentLocator(locator); 446.34 -} 446.35 - 446.36 -public void startDocument() throws SAXException{ 446.37 - h.startDocument(); 446.38 -} 446.39 - 446.40 -public void endDocument() throws SAXException{ 446.41 - h.endDocument(); 446.42 -} 446.43 - 446.44 -public void startPrefixMapping(String prefix, String uri) throws SAXException{ 446.45 - h.startPrefixMapping(prefix, uri); 446.46 -} 446.47 - 446.48 -public void endPrefixMapping(String prefix) throws SAXException{ 446.49 - h.endPrefixMapping(prefix); 446.50 -} 446.51 - 446.52 -public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException{ 446.53 - h.startElement(uri, localName, qName, atts); 446.54 -} 446.55 - 446.56 -public void endElement(String uri, String localName, String qName) throws SAXException{ 446.57 - h.endElement(uri, localName, qName); 446.58 -} 446.59 - 446.60 -public void characters(char ch[], int start, int length) throws SAXException{ 446.61 - h.characters(ch, start, length); 446.62 -} 446.63 - 446.64 -public void ignorableWhitespace(char ch[], int start, int length) throws SAXException{ 446.65 - h.ignorableWhitespace(ch, start, length); 446.66 -} 446.67 - 446.68 -public void processingInstruction(String target, String data) throws SAXException{ 446.69 - h.processingInstruction(target, data); 446.70 -} 446.71 - 446.72 -public void skippedEntity(String name) throws SAXException{ 446.73 - h.skippedEntity(name); 446.74 -} 446.75 - 446.76 -/* 446.77 -public static void main(String[] args){ 446.78 - try 446.79 - { 446.80 - ContentHandler dummy = new DefaultHandler(); 446.81 - SAXParserFactory f = SAXParserFactory.newInstance(); 446.82 - //f.setNamespaceAware(true); 446.83 - SAXParser p = f.newSAXParser(); 446.84 - p.parse("http://arstechnica.com/journals.rssx",new XMLHandler(dummy)); 446.85 - } 446.86 - catch(Exception e) 446.87 - { 446.88 - e.printStackTrace(); 446.89 - } 446.90 -} 446.91 -//*/ 446.92 -}
447.1 --- a/src/clojure/main.clj Sat Aug 21 06:25:44 2010 -0400 447.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 447.3 @@ -1,358 +0,0 @@ 447.4 -;; Copyright (c) Rich Hickey All rights reserved. The use and 447.5 -;; distribution terms for this software are covered by the Eclipse Public 447.6 -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can be found 447.7 -;; in the file epl-v10.html at the root of this distribution. By using this 447.8 -;; software in any fashion, you are agreeing to be bound by the terms of 447.9 -;; this license. You must not remove this notice, or any other, from this 447.10 -;; software. 447.11 - 447.12 -;; Originally contributed by Stephen C. Gilardi 447.13 - 447.14 -(ns ^{:doc "Top-level main function for Clojure REPL and scripts." 447.15 - :author "Stephen C. Gilardi and Rich Hickey"} 447.16 - clojure.main 447.17 - (:refer-clojure :exclude [with-bindings]) 447.18 - (:import (clojure.lang Compiler Compiler$CompilerException 447.19 - LineNumberingPushbackReader RT))) 447.20 - 447.21 -(declare main) 447.22 - 447.23 -(defmacro with-bindings 447.24 - "Executes body in the context of thread-local bindings for several vars 447.25 - that often need to be set!: *ns* *warn-on-reflection* *math-context* 447.26 - *print-meta* *print-length* *print-level* *compile-path* 447.27 - *command-line-args* *1 *2 *3 *e" 447.28 - [& body] 447.29 - `(binding [*ns* *ns* 447.30 - *warn-on-reflection* *warn-on-reflection* 447.31 - *math-context* *math-context* 447.32 - *print-meta* *print-meta* 447.33 - *print-length* *print-length* 447.34 - *print-level* *print-level* 447.35 - *compile-path* (System/getProperty "clojure.compile.path" "classes") 447.36 - *command-line-args* *command-line-args* 447.37 - *assert* *assert* 447.38 - *1 nil 447.39 - *2 nil 447.40 - *3 nil 447.41 - *e nil] 447.42 - ~@body)) 447.43 - 447.44 -(defn repl-prompt 447.45 - "Default :prompt hook for repl" 447.46 - [] 447.47 - (printf "%s=> " (ns-name *ns*))) 447.48 - 447.49 -(defn skip-if-eol 447.50 - "If the next character on stream s is a newline, skips it, otherwise 447.51 - leaves the stream untouched. Returns :line-start, :stream-end, or :body 447.52 - to indicate the relative location of the next character on s. The stream 447.53 - must either be an instance of LineNumberingPushbackReader or duplicate 447.54 - its behavior of both supporting .unread and collapsing all of CR, LF, and 447.55 - CRLF to a single \\newline." 447.56 - [s] 447.57 - (let [c (.read s)] 447.58 - (cond 447.59 - (= c (int \newline)) :line-start 447.60 - (= c -1) :stream-end 447.61 - :else (do (.unread s c) :body)))) 447.62 - 447.63 -(defn skip-whitespace 447.64 - "Skips whitespace characters on stream s. Returns :line-start, :stream-end, 447.65 - or :body to indicate the relative location of the next character on s. 447.66 - Interprets comma as whitespace and semicolon as comment to end of line. 447.67 - Does not interpret #! as comment to end of line because only one 447.68 - character of lookahead is available. The stream must either be an 447.69 - instance of LineNumberingPushbackReader or duplicate its behavior of both 447.70 - supporting .unread and collapsing all of CR, LF, and CRLF to a single 447.71 - \\newline." 447.72 - [s] 447.73 - (loop [c (.read s)] 447.74 - (cond 447.75 - (= c (int \newline)) :line-start 447.76 - (= c -1) :stream-end 447.77 - (= c (int \;)) (do (.readLine s) :line-start) 447.78 - (or (Character/isWhitespace c) (= c (int \,))) (recur (.read s)) 447.79 - :else (do (.unread s c) :body)))) 447.80 - 447.81 -(defn repl-read 447.82 - "Default :read hook for repl. Reads from *in* which must either be an 447.83 - instance of LineNumberingPushbackReader or duplicate its behavior of both 447.84 - supporting .unread and collapsing all of CR, LF, and CRLF into a single 447.85 - \\newline. repl-read: 447.86 - - skips whitespace, then 447.87 - - returns request-prompt on start of line, or 447.88 - - returns request-exit on end of stream, or 447.89 - - reads an object from the input stream, then 447.90 - - skips the next input character if it's end of line, then 447.91 - - returns the object." 447.92 - [request-prompt request-exit] 447.93 - (or ({:line-start request-prompt :stream-end request-exit} 447.94 - (skip-whitespace *in*)) 447.95 - (let [input (read)] 447.96 - (skip-if-eol *in*) 447.97 - input))) 447.98 - 447.99 -(defn- root-cause 447.100 - "Returns the initial cause of an exception or error by peeling off all of 447.101 - its wrappers" 447.102 - [^Throwable throwable] 447.103 - (loop [cause throwable] 447.104 - (if-let [cause (.getCause cause)] 447.105 - (recur cause) 447.106 - cause))) 447.107 - 447.108 -(defn repl-exception 447.109 - "Returns CompilerExceptions in tact, but only the root cause of other 447.110 - throwables" 447.111 - [throwable] 447.112 - (if (instance? Compiler$CompilerException throwable) 447.113 - throwable 447.114 - (root-cause throwable))) 447.115 - 447.116 -(defn repl-caught 447.117 - "Default :caught hook for repl" 447.118 - [e] 447.119 - (.println *err* (repl-exception e))) 447.120 - 447.121 -(defn repl 447.122 - "Generic, reusable, read-eval-print loop. By default, reads from *in*, 447.123 - writes to *out*, and prints exception summaries to *err*. If you use the 447.124 - default :read hook, *in* must either be an instance of 447.125 - LineNumberingPushbackReader or duplicate its behavior of both supporting 447.126 - .unread and collapsing CR, LF, and CRLF into a single \\newline. Options 447.127 - are sequential keyword-value pairs. Available options and their defaults: 447.128 - 447.129 - - :init, function of no arguments, initialization hook called with 447.130 - bindings for set!-able vars in place. 447.131 - default: #() 447.132 - 447.133 - - :need-prompt, function of no arguments, called before each 447.134 - read-eval-print except the first, the user will be prompted if it 447.135 - returns true. 447.136 - default: (if (instance? LineNumberingPushbackReader *in*) 447.137 - #(.atLineStart *in*) 447.138 - #(identity true)) 447.139 - 447.140 - - :prompt, function of no arguments, prompts for more input. 447.141 - default: repl-prompt 447.142 - 447.143 - - :flush, function of no arguments, flushes output 447.144 - default: flush 447.145 - 447.146 - - :read, function of two arguments, reads from *in*: 447.147 - - returns its first argument to request a fresh prompt 447.148 - - depending on need-prompt, this may cause the repl to prompt 447.149 - before reading again 447.150 - - returns its second argument to request an exit from the repl 447.151 - - else returns the next object read from the input stream 447.152 - default: repl-read 447.153 - 447.154 - - :eval, funtion of one argument, returns the evaluation of its 447.155 - argument 447.156 - default: eval 447.157 - 447.158 - - :print, function of one argument, prints its argument to the output 447.159 - default: prn 447.160 - 447.161 - - :caught, function of one argument, a throwable, called when 447.162 - read, eval, or print throws an exception or error 447.163 - default: repl-caught" 447.164 - [& options] 447.165 - (let [cl (.getContextClassLoader (Thread/currentThread))] 447.166 - (.setContextClassLoader (Thread/currentThread) (clojure.lang.DynamicClassLoader. cl))) 447.167 - (let [{:keys [init need-prompt prompt flush read eval print caught] 447.168 - :or {init #() 447.169 - need-prompt (if (instance? LineNumberingPushbackReader *in*) 447.170 - #(.atLineStart ^LineNumberingPushbackReader *in*) 447.171 - #(identity true)) 447.172 - prompt repl-prompt 447.173 - flush flush 447.174 - read repl-read 447.175 - eval eval 447.176 - print prn 447.177 - caught repl-caught}} 447.178 - (apply hash-map options) 447.179 - request-prompt (Object.) 447.180 - request-exit (Object.) 447.181 - read-eval-print 447.182 - (fn [] 447.183 - (try 447.184 - (let [input (read request-prompt request-exit)] 447.185 - (or (#{request-prompt request-exit} input) 447.186 - (let [value (eval input)] 447.187 - (print value) 447.188 - (set! *3 *2) 447.189 - (set! *2 *1) 447.190 - (set! *1 value)))) 447.191 - (catch Throwable e 447.192 - (caught e) 447.193 - (set! *e e))))] 447.194 - (with-bindings 447.195 - (try 447.196 - (init) 447.197 - (catch Throwable e 447.198 - (caught e) 447.199 - (set! *e e))) 447.200 - (use '[clojure.repl :only (source apropos dir)]) 447.201 - (use '[clojure.java.javadoc :only (javadoc)]) 447.202 - (use '[clojure.pprint :only (pp pprint)]) 447.203 - (prompt) 447.204 - (flush) 447.205 - (loop [] 447.206 - (when-not 447.207 - (try (= (read-eval-print) request-exit) 447.208 - (catch Throwable e 447.209 - (caught e) 447.210 - (set! *e e) 447.211 - nil)) 447.212 - (when (need-prompt) 447.213 - (prompt) 447.214 - (flush)) 447.215 - (recur)))))) 447.216 - 447.217 -(defn load-script 447.218 - "Loads Clojure source from a file or resource given its path. Paths 447.219 - beginning with @ or @/ are considered relative to classpath." 447.220 - [^String path] 447.221 - (if (.startsWith path "@") 447.222 - (RT/loadResourceScript 447.223 - (.substring path (if (.startsWith path "@/") 2 1))) 447.224 - (Compiler/loadFile path))) 447.225 - 447.226 -(defn- init-opt 447.227 - "Load a script" 447.228 - [path] 447.229 - (load-script path)) 447.230 - 447.231 -(defn- eval-opt 447.232 - "Evals expressions in str, prints each non-nil result using prn" 447.233 - [str] 447.234 - (let [eof (Object.) 447.235 - reader (LineNumberingPushbackReader. (java.io.StringReader. str))] 447.236 - (loop [input (read reader false eof)] 447.237 - (when-not (= input eof) 447.238 - (let [value (eval input)] 447.239 - (when-not (nil? value) 447.240 - (prn value)) 447.241 - (recur (read reader false eof))))))) 447.242 - 447.243 -(defn- init-dispatch 447.244 - "Returns the handler associated with an init opt" 447.245 - [opt] 447.246 - ({"-i" init-opt 447.247 - "--init" init-opt 447.248 - "-e" eval-opt 447.249 - "--eval" eval-opt} opt)) 447.250 - 447.251 -(defn- initialize 447.252 - "Common initialize routine for repl, script, and null opts" 447.253 - [args inits] 447.254 - (in-ns 'user) 447.255 - (set! *command-line-args* args) 447.256 - (doseq [[opt arg] inits] 447.257 - ((init-dispatch opt) arg))) 447.258 - 447.259 -(defn- repl-opt 447.260 - "Start a repl with args and inits. Print greeting if no eval options were 447.261 - present" 447.262 - [[_ & args] inits] 447.263 - (when-not (some #(= eval-opt (init-dispatch (first %))) inits) 447.264 - (println "Clojure" (clojure-version))) 447.265 - (repl :init #(initialize args inits)) 447.266 - (prn) 447.267 - (System/exit 0)) 447.268 - 447.269 -(defn- script-opt 447.270 - "Run a script from a file, resource, or standard in with args and inits" 447.271 - [[path & args] inits] 447.272 - (with-bindings 447.273 - (initialize args inits) 447.274 - (if (= path "-") 447.275 - (load-reader *in*) 447.276 - (load-script path)))) 447.277 - 447.278 -(defn- null-opt 447.279 - "No repl or script opt present, just bind args and run inits" 447.280 - [args inits] 447.281 - (with-bindings 447.282 - (initialize args inits))) 447.283 - 447.284 -(defn- help-opt 447.285 - "Print help text for main" 447.286 - [_ _] 447.287 - (println (:doc (meta (var main))))) 447.288 - 447.289 -(defn- main-dispatch 447.290 - "Returns the handler associated with a main option" 447.291 - [opt] 447.292 - (or 447.293 - ({"-r" repl-opt 447.294 - "--repl" repl-opt 447.295 - nil null-opt 447.296 - "-h" help-opt 447.297 - "--help" help-opt 447.298 - "-?" help-opt} opt) 447.299 - script-opt)) 447.300 - 447.301 -(defn- legacy-repl 447.302 - "Called by the clojure.lang.Repl.main stub to run a repl with args 447.303 - specified the old way" 447.304 - [args] 447.305 - (println "WARNING: clojure.lang.Repl is deprecated. 447.306 -Instead, use clojure.main like this: 447.307 -java -cp clojure.jar clojure.main -i init.clj -r args...") 447.308 - (let [[inits [sep & args]] (split-with (complement #{"--"}) args)] 447.309 - (repl-opt (concat ["-r"] args) (map vector (repeat "-i") inits)))) 447.310 - 447.311 -(defn- legacy-script 447.312 - "Called by the clojure.lang.Script.main stub to run a script with args 447.313 - specified the old way" 447.314 - [args] 447.315 - (println "WARNING: clojure.lang.Script is deprecated. 447.316 -Instead, use clojure.main like this: 447.317 -java -cp clojure.jar clojure.main -i init.clj script.clj args...") 447.318 - (let [[inits [sep & args]] (split-with (complement #{"--"}) args)] 447.319 - (null-opt args (map vector (repeat "-i") inits)))) 447.320 - 447.321 -(defn main 447.322 - "Usage: java -cp clojure.jar clojure.main [init-opt*] [main-opt] [arg*] 447.323 - 447.324 - With no options or args, runs an interactive Read-Eval-Print Loop 447.325 - 447.326 - init options: 447.327 - -i, --init path Load a file or resource 447.328 - -e, --eval string Evaluate expressions in string; print non-nil values 447.329 - 447.330 - main options: 447.331 - -r, --repl Run a repl 447.332 - path Run a script from from a file or resource 447.333 - - Run a script from standard input 447.334 - -h, -?, --help Print this help message and exit 447.335 - 447.336 - operation: 447.337 - 447.338 - - Establishes thread-local bindings for commonly set!-able vars 447.339 - - Enters the user namespace 447.340 - - Binds *command-line-args* to a seq of strings containing command line 447.341 - args that appear after any main option 447.342 - - Runs all init options in order 447.343 - - Runs a repl or script if requested 447.344 - 447.345 - The init options may be repeated and mixed freely, but must appear before 447.346 - any main option. The appearance of any eval option before running a repl 447.347 - suppresses the usual repl greeting message: \"Clojure ~(clojure-version)\". 447.348 - 447.349 - Paths may be absolute or relative in the filesystem or relative to 447.350 - classpath. Classpath-relative paths have prefix of @ or @/" 447.351 - [& args] 447.352 - (try 447.353 - (if args 447.354 - (loop [[opt arg & more :as args] args inits []] 447.355 - (if (init-dispatch opt) 447.356 - (recur more (conj inits [opt arg])) 447.357 - ((main-dispatch opt) args inits))) 447.358 - (repl-opt nil nil)) 447.359 - (finally 447.360 - (flush)))) 447.361 -
448.1 --- a/src/clojure/main.java Sat Aug 21 06:25:44 2010 -0400 448.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 448.3 @@ -1,39 +0,0 @@ 448.4 -/** 448.5 - * Copyright (c) Rich Hickey. All rights reserved. 448.6 - * The use and distribution terms for this software are covered by the 448.7 - * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 448.8 - * which can be found in the file epl-v10.html at the root of this distribution. 448.9 - * By using this software in any fashion, you are agreeing to be bound by 448.10 - * the terms of this license. 448.11 - * You must not remove this notice, or any other, from this software. 448.12 - **/ 448.13 - 448.14 -package clojure; 448.15 - 448.16 -import clojure.lang.Symbol; 448.17 -import clojure.lang.Var; 448.18 -import clojure.lang.RT; 448.19 - 448.20 -public class main{ 448.21 - 448.22 -final static private Symbol CLOJURE_MAIN = Symbol.intern("clojure.main"); 448.23 -final static private Var REQUIRE = RT.var("clojure.core", "require"); 448.24 -final static private Var LEGACY_REPL = RT.var("clojure.main", "legacy-repl"); 448.25 -final static private Var LEGACY_SCRIPT = RT.var("clojure.main", "legacy-script"); 448.26 -final static private Var MAIN = RT.var("clojure.main", "main"); 448.27 - 448.28 -public static void legacy_repl(String[] args) throws Exception{ 448.29 - REQUIRE.invoke(CLOJURE_MAIN); 448.30 - LEGACY_REPL.invoke(RT.seq(args)); 448.31 -} 448.32 - 448.33 -public static void legacy_script(String[] args) throws Exception{ 448.34 - REQUIRE.invoke(CLOJURE_MAIN); 448.35 - LEGACY_SCRIPT.invoke(RT.seq(args)); 448.36 -} 448.37 - 448.38 -public static void main(String[] args) throws Exception{ 448.39 - REQUIRE.invoke(CLOJURE_MAIN); 448.40 - MAIN.applyTo(RT.seq(args)); 448.41 -} 448.42 -}
449.1 --- a/src/clojure/parallel.clj Sat Aug 21 06:25:44 2010 -0400 449.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 449.3 @@ -1,250 +0,0 @@ 449.4 -; Copyright (c) Rich Hickey. All rights reserved. 449.5 -; The use and distribution terms for this software are covered by the 449.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 449.7 -; which can be found in the file epl-v10.html at the root of this distribution. 449.8 -; By using this software in any fashion, you are agreeing to be bound by 449.9 -; the terms of this license. 449.10 -; You must not remove this notice, or any other, from this software. 449.11 - 449.12 -(ns ^{:doc "DEPRECATED Wrapper of the ForkJoin library (JSR-166)." 449.13 - :author "Rich Hickey"} 449.14 - clojure.parallel) 449.15 -(alias 'parallel 'clojure.parallel) 449.16 - 449.17 -(comment " 449.18 -The parallel library wraps the ForkJoin library scheduled for inclusion in JDK 7: 449.19 - 449.20 -http://gee.cs.oswego.edu/dl/concurrency-interest/index.html 449.21 - 449.22 -You'll need jsr166y.jar in your classpath in order to use this 449.23 -library. The basic idea is that Clojure collections, and most 449.24 -efficiently vectors, can be turned into parallel arrays for use by 449.25 -this library with the function par, although most of the functions 449.26 -take collections and will call par if needed, so normally you will 449.27 -only need to call par explicitly in order to attach bound/filter/map 449.28 -ops. Parallel arrays support the attachment of bounds, filters and 449.29 -mapping functions prior to realization/calculation, which happens as 449.30 -the result of any of several operations on the 449.31 -array (pvec/psort/pfilter-nils/pfilter-dupes). Rather than perform 449.32 -composite operations in steps, as would normally be done with 449.33 -sequences, maps and filters are instead attached and thus composed by 449.34 -providing ops to par. Note that there is an order sensitivity to the 449.35 -attachments - bounds precede filters precede mappings. All operations 449.36 -then happen in parallel, using multiple threads and a sophisticated 449.37 -work-stealing system supported by fork-join, either when the array is 449.38 -realized, or to perform aggregate operations like preduce/pmin/pmax 449.39 -etc. A parallel array can be realized into a Clojure vector using 449.40 -pvec. 449.41 -") 449.42 - 449.43 -(import '(jsr166y.forkjoin ParallelArray ParallelArrayWithBounds ParallelArrayWithFilter 449.44 - ParallelArrayWithMapping 449.45 - Ops$Op Ops$BinaryOp Ops$Reducer Ops$Predicate Ops$BinaryPredicate 449.46 - Ops$IntAndObjectPredicate Ops$IntAndObjectToObject)) 449.47 - 449.48 -(defn- op [f] 449.49 - (proxy [Ops$Op] [] 449.50 - (op [x] (f x)))) 449.51 - 449.52 -(defn- binary-op [f] 449.53 - (proxy [Ops$BinaryOp] [] 449.54 - (op [x y] (f x y)))) 449.55 - 449.56 -(defn- int-and-object-to-object [f] 449.57 - (proxy [Ops$IntAndObjectToObject] [] 449.58 - (op [i x] (f x i)))) 449.59 - 449.60 -(defn- reducer [f] 449.61 - (proxy [Ops$Reducer] [] 449.62 - (op [x y] (f x y)))) 449.63 - 449.64 -(defn- predicate [f] 449.65 - (proxy [Ops$Predicate] [] 449.66 - (op [x] (boolean (f x))))) 449.67 - 449.68 -(defn- binary-predicate [f] 449.69 - (proxy [Ops$BinaryPredicate] [] 449.70 - (op [x y] (boolean (f x y))))) 449.71 - 449.72 -(defn- int-and-object-predicate [f] 449.73 - (proxy [Ops$IntAndObjectPredicate] [] 449.74 - (op [i x] (boolean (f x i))))) 449.75 - 449.76 -(defn par 449.77 - "Creates a parallel array from coll. ops, if supplied, perform 449.78 - on-the-fly filtering or transformations during parallel realization 449.79 - or calculation. ops form a chain, and bounds must precede filters, 449.80 - must precede maps. ops must be a set of keyword value pairs of the 449.81 - following forms: 449.82 - 449.83 - :bound [start end] 449.84 - 449.85 - Only elements from start (inclusive) to end (exclusive) will be 449.86 - processed when the array is realized. 449.87 - 449.88 - :filter pred 449.89 - 449.90 - Filter preds remove elements from processing when the array is realized. pred 449.91 - must be a function of one argument whose return will be processed 449.92 - via boolean. 449.93 - 449.94 - :filter-index pred2 449.95 - 449.96 - pred2 must be a function of two arguments, which will be an element 449.97 - of the collection and the corresponding index, whose return will be 449.98 - processed via boolean. 449.99 - 449.100 - :filter-with [pred2 coll2] 449.101 - 449.102 - pred2 must be a function of two arguments, which will be 449.103 - corresponding elements of the 2 collections. 449.104 - 449.105 - :map f 449.106 - 449.107 - Map fns will be used to transform elements when the array is 449.108 - realized. f must be a function of one argument. 449.109 - 449.110 - :map-index f2 449.111 - 449.112 - f2 must be a function of two arguments, which will be an element of 449.113 - the collection and the corresponding index. 449.114 - 449.115 - :map-with [f2 coll2] 449.116 - 449.117 - f2 must be a function of two arguments, which will be corresponding 449.118 - elements of the 2 collections." 449.119 - 449.120 - ([coll] 449.121 - (if (instance? ParallelArrayWithMapping coll) 449.122 - coll 449.123 - (. ParallelArray createUsingHandoff 449.124 - (to-array coll) 449.125 - (. ParallelArray defaultExecutor)))) 449.126 - ([coll & ops] 449.127 - (reduce (fn [pa [op args]] 449.128 - (cond 449.129 - (= op :bound) (. pa withBounds (args 0) (args 1)) 449.130 - (= op :filter) (. pa withFilter (predicate args)) 449.131 - (= op :filter-with) (. pa withFilter (binary-predicate (args 0)) (par (args 1))) 449.132 - (= op :filter-index) (. pa withIndexedFilter (int-and-object-predicate args)) 449.133 - (= op :map) (. pa withMapping (parallel/op args)) 449.134 - (= op :map-with) (. pa withMapping (binary-op (args 0)) (par (args 1))) 449.135 - (= op :map-index) (. pa withIndexedMapping (int-and-object-to-object args)) 449.136 - :else (throw (Exception. (str "Unsupported par op: " op))))) 449.137 - (par coll) 449.138 - (partition 2 ops)))) 449.139 - 449.140 -;;;;;;;;;;;;;;;;;;;;; aggregate operations ;;;;;;;;;;;;;;;;;;;;;; 449.141 -(defn pany 449.142 - "Returns some (random) element of the coll if it satisfies the bound/filter/map" 449.143 - [coll] 449.144 - (. (par coll) any)) 449.145 - 449.146 -(defn pmax 449.147 - "Returns the maximum element, presuming Comparable elements, unless 449.148 - a Comparator comp is supplied" 449.149 - ([coll] (. (par coll) max)) 449.150 - ([coll comp] (. (par coll) max comp))) 449.151 - 449.152 -(defn pmin 449.153 - "Returns the minimum element, presuming Comparable elements, unless 449.154 - a Comparator comp is supplied" 449.155 - ([coll] (. (par coll) min)) 449.156 - ([coll comp] (. (par coll) min comp))) 449.157 - 449.158 -(defn- summary-map [s] 449.159 - {:min (.min s) :max (.max s) :size (.size s) :min-index (.indexOfMin s) :max-index (.indexOfMax s)}) 449.160 - 449.161 -(defn psummary 449.162 - "Returns a map of summary statistics (min. max, size, min-index, max-index, 449.163 - presuming Comparable elements, unless a Comparator comp is supplied" 449.164 - ([coll] (summary-map (. (par coll) summary))) 449.165 - ([coll comp] (summary-map (. (par coll) summary comp)))) 449.166 - 449.167 -(defn preduce 449.168 - "Returns the reduction of the realized elements of coll 449.169 - using function f. Note f will not necessarily be called 449.170 - consecutively, and so must be commutative. Also note that 449.171 - (f base an-element) might be performed many times, i.e. base is not 449.172 - an initial value as with sequential reduce." 449.173 - [f base coll] 449.174 - (. (par coll) (reduce (reducer f) base))) 449.175 - 449.176 -;;;;;;;;;;;;;;;;;;;;; collection-producing operations ;;;;;;;;;;;;;;;;;;;;;; 449.177 - 449.178 -(defn- pa-to-vec [pa] 449.179 - (vec (. pa getArray))) 449.180 - 449.181 -(defn- pall 449.182 - "Realizes a copy of the coll as a parallel array, with any bounds/filters/maps applied" 449.183 - [coll] 449.184 - (if (instance? ParallelArrayWithMapping coll) 449.185 - (. coll all) 449.186 - (par coll))) 449.187 - 449.188 -(defn pvec 449.189 - "Returns the realized contents of the parallel array pa as a Clojure vector" 449.190 - [pa] (pa-to-vec (pall pa))) 449.191 - 449.192 -(defn pdistinct 449.193 - "Returns a parallel array of the distinct elements of coll" 449.194 - [coll] 449.195 - (pa-to-vec (. (pall coll) allUniqueElements))) 449.196 - 449.197 -;this doesn't work, passes null to reducer? 449.198 -(defn- pcumulate [coll f init] 449.199 - (.. (pall coll) (precumulate (reducer f) init))) 449.200 - 449.201 -(defn psort 449.202 - "Returns a new vector consisting of the realized items in coll, sorted, 449.203 - presuming Comparable elements, unless a Comparator comp is supplied" 449.204 - ([coll] (pa-to-vec (. (pall coll) sort))) 449.205 - ([coll comp] (pa-to-vec (. (pall coll) sort comp)))) 449.206 - 449.207 -(defn pfilter-nils 449.208 - "Returns a vector containing the non-nil (realized) elements of coll" 449.209 - [coll] 449.210 - (pa-to-vec (. (pall coll) removeNulls))) 449.211 - 449.212 -(defn pfilter-dupes 449.213 - "Returns a vector containing the (realized) elements of coll, 449.214 - without any consecutive duplicates" 449.215 - [coll] 449.216 - (pa-to-vec (. (pall coll) removeConsecutiveDuplicates))) 449.217 - 449.218 - 449.219 -(comment 449.220 -(load-file "src/parallel.clj") 449.221 -(refer 'parallel) 449.222 -(pdistinct [1 2 3 2 1]) 449.223 -;(pcumulate [1 2 3 2 1] + 0) ;broken, not exposed 449.224 -(def a (make-array Object 1000000)) 449.225 -(dotimes i (count a) 449.226 - (aset a i (rand-int i))) 449.227 -(time (reduce + 0 a)) 449.228 -(time (preduce + 0 a)) 449.229 -(time (count (distinct a))) 449.230 -(time (count (pdistinct a))) 449.231 - 449.232 -(preduce + 0 [1 2 3 2 1]) 449.233 -(preduce + 0 (psort a)) 449.234 -(pvec (par [11 2 3 2] :filter-index (fn [x i] (> i x)))) 449.235 -(pvec (par [11 2 3 2] :filter-with [(fn [x y] (> y x)) [110 2 33 2]])) 449.236 - 449.237 -(psummary ;or pvec/pmax etc 449.238 - (par [11 2 3 2] 449.239 - :filter-with [(fn [x y] (> y x)) 449.240 - [110 2 33 2]] 449.241 - :map #(* % 2))) 449.242 - 449.243 -(preduce + 0 449.244 - (par [11 2 3 2] 449.245 - :filter-with [< [110 2 33 2]])) 449.246 - 449.247 -(time (reduce + 0 (map #(* % %) (range 1000000)))) 449.248 -(time (preduce + 0 (par (range 1000000) :map-index *))) 449.249 -(def v (range 1000000)) 449.250 -(time (preduce + 0 (par v :map-index *))) 449.251 -(time (preduce + 0 (par v :map #(* % %)))) 449.252 -(time (reduce + 0 (map #(* % %) v))) 449.253 -) 449.254 \ No newline at end of file
450.1 --- a/src/clojure/pprint.clj Sat Aug 21 06:25:44 2010 -0400 450.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 450.3 @@ -1,48 +0,0 @@ 450.4 -;;; pprint.clj -- Pretty printer and Common Lisp compatible format function (cl-format) for Clojure 450.5 - 450.6 -; Copyright (c) Rich Hickey. All rights reserved. 450.7 -; The use and distribution terms for this software are covered by the 450.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 450.9 -; which can be found in the file epl-v10.html at the root of this distribution. 450.10 -; By using this software in any fashion, you are agreeing to be bound by 450.11 -; the terms of this license. 450.12 -; You must not remove this notice, or any other, from this software. 450.13 - 450.14 -;; Author: Tom Faulhaber 450.15 -;; April 3, 2009 450.16 - 450.17 -(ns 450.18 - ^{:author "Tom Faulhaber", 450.19 - :doc "A Pretty Printer for Clojure 450.20 - 450.21 -clojure.pprint implements a flexible system for printing structured data 450.22 -in a pleasing, easy-to-understand format. Basic use of the pretty printer is 450.23 -simple, just call pprint instead of println. More advanced users can use 450.24 -the building blocks provided to create custom output formats. 450.25 - 450.26 -Out of the box, pprint supports a simple structured format for basic data 450.27 -and a specialized format for Clojure source code. More advanced formats, 450.28 -including formats that don't look like Clojure data at all like XML and 450.29 -JSON, can be rendered by creating custom dispatch functions. 450.30 - 450.31 -In addition to the pprint function, this module contains cl-format, a text 450.32 -formatting function which is fully compatible with the format function in 450.33 -Common Lisp. Because pretty printing directives are directly integrated with 450.34 -cl-format, it supports very concise custom dispatch. It also provides 450.35 -a more powerful alternative to Clojure's standard format function. 450.36 - 450.37 -See documentation for pprint and cl-format for more information or 450.38 -complete documentation on the the clojure web site on github.", 450.39 - :added "1.2"} 450.40 - clojure.pprint 450.41 - (:refer-clojure :exclude (deftype))) 450.42 - 450.43 - 450.44 -(load "pprint/utilities") 450.45 -(load "pprint/column_writer") 450.46 -(load "pprint/pretty_writer") 450.47 -(load "pprint/pprint_base") 450.48 -(load "pprint/cl_format") 450.49 -(load "pprint/dispatch") 450.50 - 450.51 -nil
451.1 --- a/src/clojure/pprint/cl_format.clj Sat Aug 21 06:25:44 2010 -0400 451.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 451.3 @@ -1,1890 +0,0 @@ 451.4 -;;; cl_format.clj -- part of the pretty printer for Clojure 451.5 - 451.6 -; Copyright (c) Rich Hickey. All rights reserved. 451.7 -; The use and distribution terms for this software are covered by the 451.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 451.9 -; which can be found in the file epl-v10.html at the root of this distribution. 451.10 -; By using this software in any fashion, you are agreeing to be bound by 451.11 -; the terms of this license. 451.12 -; You must not remove this notice, or any other, from this software. 451.13 - 451.14 -;; Author: Tom Faulhaber 451.15 -;; April 3, 2009 451.16 - 451.17 - 451.18 -;; This module implements the Common Lisp compatible format function as documented 451.19 -;; in "Common Lisp the Language, 2nd edition", Chapter 22 (available online at: 451.20 -;; http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node200.html#SECTION002633000000000000000) 451.21 - 451.22 -(in-ns 'clojure.pprint) 451.23 - 451.24 -;;; Forward references 451.25 -(declare compile-format) 451.26 -(declare execute-format) 451.27 -(declare init-navigator) 451.28 -;;; End forward references 451.29 - 451.30 -(defn cl-format 451.31 - "An implementation of a Common Lisp compatible format function. cl-format formats its 451.32 -arguments to an output stream or string based on the format control string given. It 451.33 -supports sophisticated formatting of structured data. 451.34 - 451.35 -Writer is an instance of java.io.Writer, true to output to *out* or nil to output 451.36 -to a string, format-in is the format control string and the remaining arguments 451.37 -are the data to be formatted. 451.38 - 451.39 -The format control string is a string to be output with embedded 'format directives' 451.40 -describing how to format the various arguments passed in. 451.41 - 451.42 -If writer is nil, cl-format returns the formatted result string. Otherwise, cl-format 451.43 -returns nil. 451.44 - 451.45 -For example: 451.46 - (let [results [46 38 22]] 451.47 - (cl-format true \"There ~[are~;is~:;are~]~:* ~d result~:p: ~{~d~^, ~}~%\" 451.48 - (count results) results)) 451.49 - 451.50 -Prints to *out*: 451.51 - There are 3 results: 46, 38, 22 451.52 - 451.53 -Detailed documentation on format control strings is available in the \"Common Lisp the 451.54 -Language, 2nd edition\", Chapter 22 (available online at: 451.55 -http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node200.html#SECTION002633000000000000000) 451.56 -and in the Common Lisp HyperSpec at 451.57 -http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm 451.58 -" 451.59 - {:added "1.2", 451.60 - :see-also [["http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node200.html#SECTION002633000000000000000" 451.61 - "Common Lisp the Language"] 451.62 - ["http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm" 451.63 - "Common Lisp HyperSpec"]]} 451.64 - [writer format-in & args] 451.65 - (let [compiled-format (if (string? format-in) (compile-format format-in) format-in) 451.66 - navigator (init-navigator args)] 451.67 - (execute-format writer compiled-format navigator))) 451.68 - 451.69 -(def ^{:private true} *format-str* nil) 451.70 - 451.71 -(defn- format-error [message offset] 451.72 - (let [full-message (str message \newline *format-str* \newline 451.73 - (apply str (repeat offset \space)) "^" \newline)] 451.74 - (throw (RuntimeException. full-message)))) 451.75 - 451.76 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.77 -;;; Argument navigators manage the argument list 451.78 -;;; as the format statement moves through the list 451.79 -;;; (possibly going forwards and backwards as it does so) 451.80 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.81 - 451.82 -(defstruct ^{:private true} 451.83 - arg-navigator :seq :rest :pos ) 451.84 - 451.85 -(defn- init-navigator 451.86 - "Create a new arg-navigator from the sequence with the position set to 0" 451.87 - {:skip-wiki true} 451.88 - [s] 451.89 - (let [s (seq s)] 451.90 - (struct arg-navigator s s 0))) 451.91 - 451.92 -;; TODO call format-error with offset 451.93 -(defn- next-arg [ navigator ] 451.94 - (let [ rst (:rest navigator) ] 451.95 - (if rst 451.96 - [(first rst) (struct arg-navigator (:seq navigator ) (next rst) (inc (:pos navigator)))] 451.97 - (throw (new Exception "Not enough arguments for format definition"))))) 451.98 - 451.99 -(defn- next-arg-or-nil [navigator] 451.100 - (let [rst (:rest navigator)] 451.101 - (if rst 451.102 - [(first rst) (struct arg-navigator (:seq navigator ) (next rst) (inc (:pos navigator)))] 451.103 - [nil navigator]))) 451.104 - 451.105 -;; Get an argument off the arg list and compile it if it's not already compiled 451.106 -(defn- get-format-arg [navigator] 451.107 - (let [[raw-format navigator] (next-arg navigator) 451.108 - compiled-format (if (instance? String raw-format) 451.109 - (compile-format raw-format) 451.110 - raw-format)] 451.111 - [compiled-format navigator])) 451.112 - 451.113 -(declare relative-reposition) 451.114 - 451.115 -(defn- absolute-reposition [navigator position] 451.116 - (if (>= position (:pos navigator)) 451.117 - (relative-reposition navigator (- (:pos navigator) position)) 451.118 - (struct arg-navigator (:seq navigator) (drop position (:seq navigator)) position))) 451.119 - 451.120 -(defn- relative-reposition [navigator position] 451.121 - (let [newpos (+ (:pos navigator) position)] 451.122 - (if (neg? position) 451.123 - (absolute-reposition navigator newpos) 451.124 - (struct arg-navigator (:seq navigator) (drop position (:rest navigator)) newpos)))) 451.125 - 451.126 -(defstruct ^{:private true} 451.127 - compiled-directive :func :def :params :offset) 451.128 - 451.129 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.130 -;;; When looking at the parameter list, we may need to manipulate 451.131 -;;; the argument list as well (for 'V' and '#' parameter types). 451.132 -;;; We hide all of this behind a function, but clients need to 451.133 -;;; manage changing arg navigator 451.134 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.135 - 451.136 -;; TODO: validate parameters when they come from arg list 451.137 -(defn- realize-parameter [[param [raw-val offset]] navigator] 451.138 - (let [[real-param new-navigator] 451.139 - (cond 451.140 - (contains? #{ :at :colon } param) ;pass flags through unchanged - this really isn't necessary 451.141 - [raw-val navigator] 451.142 - 451.143 - (= raw-val :parameter-from-args) 451.144 - (next-arg navigator) 451.145 - 451.146 - (= raw-val :remaining-arg-count) 451.147 - [(count (:rest navigator)) navigator] 451.148 - 451.149 - true 451.150 - [raw-val navigator])] 451.151 - [[param [real-param offset]] new-navigator])) 451.152 - 451.153 -(defn- realize-parameter-list [parameter-map navigator] 451.154 - (let [[pairs new-navigator] 451.155 - (map-passing-context realize-parameter navigator parameter-map)] 451.156 - [(into {} pairs) new-navigator])) 451.157 - 451.158 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.159 -;;; Functions that support individual directives 451.160 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.161 - 451.162 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.163 -;;; Common handling code for ~A and ~S 451.164 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.165 - 451.166 -(declare opt-base-str) 451.167 - 451.168 -(def ^{:private true} 451.169 - special-radix-markers {2 "#b" 8 "#o", 16 "#x"}) 451.170 - 451.171 -(defn- format-simple-number [n] 451.172 - (cond 451.173 - (integer? n) (if (= *print-base* 10) 451.174 - (str n (if *print-radix* ".")) 451.175 - (str 451.176 - (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r"))) 451.177 - (opt-base-str *print-base* n))) 451.178 - (ratio? n) (str 451.179 - (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r"))) 451.180 - (opt-base-str *print-base* (.numerator n)) 451.181 - "/" 451.182 - (opt-base-str *print-base* (.denominator n))) 451.183 - :else nil)) 451.184 - 451.185 -(defn- format-ascii [print-func params arg-navigator offsets] 451.186 - (let [ [arg arg-navigator] (next-arg arg-navigator) 451.187 - ^String base-output (or (format-simple-number arg) (print-func arg)) 451.188 - base-width (.length base-output) 451.189 - min-width (+ base-width (:minpad params)) 451.190 - width (if (>= min-width (:mincol params)) 451.191 - min-width 451.192 - (+ min-width 451.193 - (* (+ (quot (- (:mincol params) min-width 1) 451.194 - (:colinc params) ) 451.195 - 1) 451.196 - (:colinc params)))) 451.197 - chars (apply str (repeat (- width base-width) (:padchar params)))] 451.198 - (if (:at params) 451.199 - (print (str chars base-output)) 451.200 - (print (str base-output chars))) 451.201 - arg-navigator)) 451.202 - 451.203 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.204 -;;; Support for the integer directives ~D, ~X, ~O, ~B and some 451.205 -;;; of ~R 451.206 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.207 - 451.208 -(defn- integral? 451.209 - "returns true if a number is actually an integer (that is, has no fractional part)" 451.210 - [x] 451.211 - (cond 451.212 - (integer? x) true 451.213 - (decimal? x) (>= (.ulp (.stripTrailingZeros (bigdec 0))) 1) ; true iff no fractional part 451.214 - (float? x) (= x (Math/floor x)) 451.215 - (ratio? x) (let [^clojure.lang.Ratio r x] 451.216 - (= 0 (rem (.numerator r) (.denominator r)))) 451.217 - :else false)) 451.218 - 451.219 -(defn- remainders 451.220 - "Return the list of remainders (essentially the 'digits') of val in the given base" 451.221 - [base val] 451.222 - (reverse 451.223 - (first 451.224 - (consume #(if (pos? %) 451.225 - [(rem % base) (quot % base)] 451.226 - [nil nil]) 451.227 - val)))) 451.228 - 451.229 -;;; TODO: xlated-val does not seem to be used here. 451.230 -(defn- base-str 451.231 - "Return val as a string in the given base" 451.232 - [base val] 451.233 - (if (zero? val) 451.234 - "0" 451.235 - (let [xlated-val (cond 451.236 - (float? val) (bigdec val) 451.237 - (ratio? val) (let [^clojure.lang.Ratio r val] 451.238 - (/ (.numerator r) (.denominator r))) 451.239 - :else val)] 451.240 - (apply str 451.241 - (map 451.242 - #(if (< % 10) (char (+ (int \0) %)) (char (+ (int \a) (- % 10)))) 451.243 - (remainders base val)))))) 451.244 - 451.245 -(def ^{:private true} 451.246 - java-base-formats {8 "%o", 10 "%d", 16 "%x"}) 451.247 - 451.248 -(defn- opt-base-str 451.249 - "Return val as a string in the given base, using clojure.core/format if supported 451.250 -for improved performance" 451.251 - [base val] 451.252 - (let [format-str (get java-base-formats base)] 451.253 - (if (and format-str (integer? val)) 451.254 - (clojure.core/format format-str val) 451.255 - (base-str base val)))) 451.256 - 451.257 -(defn- group-by* [unit lis] 451.258 - (reverse 451.259 - (first 451.260 - (consume (fn [x] [(seq (reverse (take unit x))) (seq (drop unit x))]) (reverse lis))))) 451.261 - 451.262 -(defn- format-integer [base params arg-navigator offsets] 451.263 - (let [[arg arg-navigator] (next-arg arg-navigator)] 451.264 - (if (integral? arg) 451.265 - (let [neg (neg? arg) 451.266 - pos-arg (if neg (- arg) arg) 451.267 - raw-str (opt-base-str base pos-arg) 451.268 - group-str (if (:colon params) 451.269 - (let [groups (map #(apply str %) (group-by* (:commainterval params) raw-str)) 451.270 - commas (repeat (count groups) (:commachar params))] 451.271 - (apply str (next (interleave commas groups)))) 451.272 - raw-str) 451.273 - ^String signed-str (cond 451.274 - neg (str "-" group-str) 451.275 - (:at params) (str "+" group-str) 451.276 - true group-str) 451.277 - padded-str (if (< (.length signed-str) (:mincol params)) 451.278 - (str (apply str (repeat (- (:mincol params) (.length signed-str)) 451.279 - (:padchar params))) 451.280 - signed-str) 451.281 - signed-str)] 451.282 - (print padded-str)) 451.283 - (format-ascii print-str {:mincol (:mincol params) :colinc 1 :minpad 0 451.284 - :padchar (:padchar params) :at true} 451.285 - (init-navigator [arg]) nil)) 451.286 - arg-navigator)) 451.287 - 451.288 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.289 -;;; Support for english formats (~R and ~:R) 451.290 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.291 - 451.292 -(def ^{:private true} 451.293 - english-cardinal-units 451.294 - ["zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" 451.295 - "ten" "eleven" "twelve" "thirteen" "fourteen" 451.296 - "fifteen" "sixteen" "seventeen" "eighteen" "nineteen"]) 451.297 - 451.298 -(def ^{:private true} 451.299 - english-ordinal-units 451.300 - ["zeroth" "first" "second" "third" "fourth" "fifth" "sixth" "seventh" "eighth" "ninth" 451.301 - "tenth" "eleventh" "twelfth" "thirteenth" "fourteenth" 451.302 - "fifteenth" "sixteenth" "seventeenth" "eighteenth" "nineteenth"]) 451.303 - 451.304 -(def ^{:private true} 451.305 - english-cardinal-tens 451.306 - ["" "" "twenty" "thirty" "forty" "fifty" "sixty" "seventy" "eighty" "ninety"]) 451.307 - 451.308 -(def ^{:private true} 451.309 - english-ordinal-tens 451.310 - ["" "" "twentieth" "thirtieth" "fortieth" "fiftieth" 451.311 - "sixtieth" "seventieth" "eightieth" "ninetieth"]) 451.312 - 451.313 -;; We use "short scale" for our units (see http://en.wikipedia.org/wiki/Long_and_short_scales) 451.314 -;; Number names from http://www.jimloy.com/math/billion.htm 451.315 -;; We follow the rules for writing numbers from the Blue Book 451.316 -;; (http://www.grammarbook.com/numbers/numbers.asp) 451.317 -(def ^{:private true} 451.318 - english-scale-numbers 451.319 - ["" "thousand" "million" "billion" "trillion" "quadrillion" "quintillion" 451.320 - "sextillion" "septillion" "octillion" "nonillion" "decillion" 451.321 - "undecillion" "duodecillion" "tredecillion" "quattuordecillion" 451.322 - "quindecillion" "sexdecillion" "septendecillion" 451.323 - "octodecillion" "novemdecillion" "vigintillion"]) 451.324 - 451.325 -(defn- format-simple-cardinal 451.326 - "Convert a number less than 1000 to a cardinal english string" 451.327 - [num] 451.328 - (let [hundreds (quot num 100) 451.329 - tens (rem num 100)] 451.330 - (str 451.331 - (if (pos? hundreds) (str (nth english-cardinal-units hundreds) " hundred")) 451.332 - (if (and (pos? hundreds) (pos? tens)) " ") 451.333 - (if (pos? tens) 451.334 - (if (< tens 20) 451.335 - (nth english-cardinal-units tens) 451.336 - (let [ten-digit (quot tens 10) 451.337 - unit-digit (rem tens 10)] 451.338 - (str 451.339 - (if (pos? ten-digit) (nth english-cardinal-tens ten-digit)) 451.340 - (if (and (pos? ten-digit) (pos? unit-digit)) "-") 451.341 - (if (pos? unit-digit) (nth english-cardinal-units unit-digit))))))))) 451.342 - 451.343 -(defn- add-english-scales 451.344 - "Take a sequence of parts, add scale numbers (e.g., million) and combine into a string 451.345 -offset is a factor of 10^3 to multiply by" 451.346 - [parts offset] 451.347 - (let [cnt (count parts)] 451.348 - (loop [acc [] 451.349 - pos (dec cnt) 451.350 - this (first parts) 451.351 - remainder (next parts)] 451.352 - (if (nil? remainder) 451.353 - (str (apply str (interpose ", " acc)) 451.354 - (if (and (not (empty? this)) (not (empty? acc))) ", ") 451.355 - this 451.356 - (if (and (not (empty? this)) (pos? (+ pos offset))) 451.357 - (str " " (nth english-scale-numbers (+ pos offset))))) 451.358 - (recur 451.359 - (if (empty? this) 451.360 - acc 451.361 - (conj acc (str this " " (nth english-scale-numbers (+ pos offset))))) 451.362 - (dec pos) 451.363 - (first remainder) 451.364 - (next remainder)))))) 451.365 - 451.366 -(defn- format-cardinal-english [params navigator offsets] 451.367 - (let [[arg navigator] (next-arg navigator)] 451.368 - (if (= 0 arg) 451.369 - (print "zero") 451.370 - (let [abs-arg (if (neg? arg) (- arg) arg) ; some numbers are too big for Math/abs 451.371 - parts (remainders 1000 abs-arg)] 451.372 - (if (<= (count parts) (count english-scale-numbers)) 451.373 - (let [parts-strs (map format-simple-cardinal parts) 451.374 - full-str (add-english-scales parts-strs 0)] 451.375 - (print (str (if (neg? arg) "minus ") full-str))) 451.376 - (format-integer ;; for numbers > 10^63, we fall back on ~D 451.377 - 10 451.378 - { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true} 451.379 - (init-navigator [arg]) 451.380 - { :mincol 0, :padchar 0, :commachar 0 :commainterval 0})))) 451.381 - navigator)) 451.382 - 451.383 -(defn- format-simple-ordinal 451.384 - "Convert a number less than 1000 to a ordinal english string 451.385 -Note this should only be used for the last one in the sequence" 451.386 - [num] 451.387 - (let [hundreds (quot num 100) 451.388 - tens (rem num 100)] 451.389 - (str 451.390 - (if (pos? hundreds) (str (nth english-cardinal-units hundreds) " hundred")) 451.391 - (if (and (pos? hundreds) (pos? tens)) " ") 451.392 - (if (pos? tens) 451.393 - (if (< tens 20) 451.394 - (nth english-ordinal-units tens) 451.395 - (let [ten-digit (quot tens 10) 451.396 - unit-digit (rem tens 10)] 451.397 - (if (and (pos? ten-digit) (not (pos? unit-digit))) 451.398 - (nth english-ordinal-tens ten-digit) 451.399 - (str 451.400 - (if (pos? ten-digit) (nth english-cardinal-tens ten-digit)) 451.401 - (if (and (pos? ten-digit) (pos? unit-digit)) "-") 451.402 - (if (pos? unit-digit) (nth english-ordinal-units unit-digit)))))) 451.403 - (if (pos? hundreds) "th"))))) 451.404 - 451.405 -(defn- format-ordinal-english [params navigator offsets] 451.406 - (let [[arg navigator] (next-arg navigator)] 451.407 - (if (= 0 arg) 451.408 - (print "zeroth") 451.409 - (let [abs-arg (if (neg? arg) (- arg) arg) ; some numbers are too big for Math/abs 451.410 - parts (remainders 1000 abs-arg)] 451.411 - (if (<= (count parts) (count english-scale-numbers)) 451.412 - (let [parts-strs (map format-simple-cardinal (drop-last parts)) 451.413 - head-str (add-english-scales parts-strs 1) 451.414 - tail-str (format-simple-ordinal (last parts))] 451.415 - (print (str (if (neg? arg) "minus ") 451.416 - (cond 451.417 - (and (not (empty? head-str)) (not (empty? tail-str))) 451.418 - (str head-str ", " tail-str) 451.419 - 451.420 - (not (empty? head-str)) (str head-str "th") 451.421 - :else tail-str)))) 451.422 - (do (format-integer ;; for numbers > 10^63, we fall back on ~D 451.423 - 10 451.424 - { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true} 451.425 - (init-navigator [arg]) 451.426 - { :mincol 0, :padchar 0, :commachar 0 :commainterval 0}) 451.427 - (let [low-two-digits (rem arg 100) 451.428 - not-teens (or (< 11 low-two-digits) (> 19 low-two-digits)) 451.429 - low-digit (rem low-two-digits 10)] 451.430 - (print (cond 451.431 - (and (= low-digit 1) not-teens) "st" 451.432 - (and (= low-digit 2) not-teens) "nd" 451.433 - (and (= low-digit 3) not-teens) "rd" 451.434 - :else "th"))))))) 451.435 - navigator)) 451.436 - 451.437 - 451.438 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.439 -;;; Support for roman numeral formats (~@R and ~@:R) 451.440 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.441 - 451.442 -(def ^{:private true} 451.443 - old-roman-table 451.444 - [[ "I" "II" "III" "IIII" "V" "VI" "VII" "VIII" "VIIII"] 451.445 - [ "X" "XX" "XXX" "XXXX" "L" "LX" "LXX" "LXXX" "LXXXX"] 451.446 - [ "C" "CC" "CCC" "CCCC" "D" "DC" "DCC" "DCCC" "DCCCC"] 451.447 - [ "M" "MM" "MMM"]]) 451.448 - 451.449 -(def ^{:private true} 451.450 - new-roman-table 451.451 - [[ "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX"] 451.452 - [ "X" "XX" "XXX" "XL" "L" "LX" "LXX" "LXXX" "XC"] 451.453 - [ "C" "CC" "CCC" "CD" "D" "DC" "DCC" "DCCC" "CM"] 451.454 - [ "M" "MM" "MMM"]]) 451.455 - 451.456 -(defn- format-roman 451.457 - "Format a roman numeral using the specified look-up table" 451.458 - [table params navigator offsets] 451.459 - (let [[arg navigator] (next-arg navigator)] 451.460 - (if (and (number? arg) (> arg 0) (< arg 4000)) 451.461 - (let [digits (remainders 10 arg)] 451.462 - (loop [acc [] 451.463 - pos (dec (count digits)) 451.464 - digits digits] 451.465 - (if (empty? digits) 451.466 - (print (apply str acc)) 451.467 - (let [digit (first digits)] 451.468 - (recur (if (= 0 digit) 451.469 - acc 451.470 - (conj acc (nth (nth table pos) (dec digit)))) 451.471 - (dec pos) 451.472 - (next digits)))))) 451.473 - (format-integer ;; for anything <= 0 or > 3999, we fall back on ~D 451.474 - 10 451.475 - { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true} 451.476 - (init-navigator [arg]) 451.477 - { :mincol 0, :padchar 0, :commachar 0 :commainterval 0})) 451.478 - navigator)) 451.479 - 451.480 -(defn- format-old-roman [params navigator offsets] 451.481 - (format-roman old-roman-table params navigator offsets)) 451.482 - 451.483 -(defn- format-new-roman [params navigator offsets] 451.484 - (format-roman new-roman-table params navigator offsets)) 451.485 - 451.486 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.487 -;;; Support for character formats (~C) 451.488 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.489 - 451.490 -(def ^{:private true} 451.491 - special-chars { 8 "Backspace", 9 "Tab", 10 "Newline", 13 "Return", 32 "Space"}) 451.492 - 451.493 -(defn- pretty-character [params navigator offsets] 451.494 - (let [[c navigator] (next-arg navigator) 451.495 - as-int (int c) 451.496 - base-char (bit-and as-int 127) 451.497 - meta (bit-and as-int 128) 451.498 - special (get special-chars base-char)] 451.499 - (if (> meta 0) (print "Meta-")) 451.500 - (print (cond 451.501 - special special 451.502 - (< base-char 32) (str "Control-" (char (+ base-char 64))) 451.503 - (= base-char 127) "Control-?" 451.504 - :else (char base-char))) 451.505 - navigator)) 451.506 - 451.507 -(defn- readable-character [params navigator offsets] 451.508 - (let [[c navigator] (next-arg navigator)] 451.509 - (condp = (:char-format params) 451.510 - \o (cl-format true "\\o~3,'0o" (int c)) 451.511 - \u (cl-format true "\\u~4,'0x" (int c)) 451.512 - nil (pr c)) 451.513 - navigator)) 451.514 - 451.515 -(defn- plain-character [params navigator offsets] 451.516 - (let [[char navigator] (next-arg navigator)] 451.517 - (print char) 451.518 - navigator)) 451.519 - 451.520 -;; Check to see if a result is an abort (~^) construct 451.521 -;; TODO: move these funcs somewhere more appropriate 451.522 -(defn- abort? [context] 451.523 - (let [token (first context)] 451.524 - (or (= :up-arrow token) (= :colon-up-arrow token)))) 451.525 - 451.526 -;; Handle the execution of "sub-clauses" in bracket constructions 451.527 -(defn- execute-sub-format [format args base-args] 451.528 - (second 451.529 - (map-passing-context 451.530 - (fn [element context] 451.531 - (if (abort? context) 451.532 - [nil context] ; just keep passing it along 451.533 - (let [[params args] (realize-parameter-list (:params element) context) 451.534 - [params offsets] (unzip-map params) 451.535 - params (assoc params :base-args base-args)] 451.536 - [nil (apply (:func element) [params args offsets])]))) 451.537 - args 451.538 - format))) 451.539 - 451.540 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.541 -;;; Support for real number formats 451.542 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.543 - 451.544 -;; TODO - return exponent as int to eliminate double conversion 451.545 -(defn- float-parts-base 451.546 - "Produce string parts for the mantissa (normalized 1-9) and exponent" 451.547 - [^Object f] 451.548 - (let [^String s (.toLowerCase (.toString f)) 451.549 - exploc (.indexOf s (int \e))] 451.550 - (if (neg? exploc) 451.551 - (let [dotloc (.indexOf s (int \.))] 451.552 - (if (neg? dotloc) 451.553 - [s (str (dec (count s)))] 451.554 - [(str (subs s 0 dotloc) (subs s (inc dotloc))) (str (dec dotloc))])) 451.555 - [(str (subs s 0 1) (subs s 2 exploc)) (subs s (inc exploc))]))) 451.556 - 451.557 - 451.558 -(defn- float-parts 451.559 - "Take care of leading and trailing zeros in decomposed floats" 451.560 - [f] 451.561 - (let [[m ^String e] (float-parts-base f) 451.562 - m1 (rtrim m \0) 451.563 - m2 (ltrim m1 \0) 451.564 - delta (- (count m1) (count m2)) 451.565 - ^String e (if (and (pos? (count e)) (= (nth e 0) \+)) (subs e 1) e)] 451.566 - (if (empty? m2) 451.567 - ["0" 0] 451.568 - [m2 (- (Integer/valueOf e) delta)]))) 451.569 - 451.570 -(defn- round-str [m e d w] 451.571 - (if (or d w) 451.572 - (let [len (count m) 451.573 - round-pos (if d (+ e d 1)) 451.574 - round-pos (if (and w (< (inc e) (dec w)) 451.575 - (or (nil? round-pos) (< (dec w) round-pos))) 451.576 - (dec w) 451.577 - round-pos) 451.578 - [m1 e1 round-pos len] (if (= round-pos 0) 451.579 - [(str "0" m) (inc e) 1 (inc len)] 451.580 - [m e round-pos len])] 451.581 - (if round-pos 451.582 - (if (neg? round-pos) 451.583 - ["0" 0 false] 451.584 - (if (> len round-pos) 451.585 - (let [round-char (nth m1 round-pos) 451.586 - ^String result (subs m1 0 round-pos)] 451.587 - (if (>= (int round-char) (int \5)) 451.588 - (let [result-val (Integer/valueOf result) 451.589 - leading-zeros (subs result 0 (min (prefix-count result \0) (- round-pos 1))) 451.590 - round-up-result (str leading-zeros 451.591 - (String/valueOf (+ result-val 451.592 - (if (neg? result-val) -1 1)))) 451.593 - expanded (> (count round-up-result) (count result))] 451.594 - [round-up-result e1 expanded]) 451.595 - [result e1 false])) 451.596 - [m e false])) 451.597 - [m e false])) 451.598 - [m e false])) 451.599 - 451.600 -(defn- expand-fixed [m e d] 451.601 - (let [m1 (if (neg? e) (str (apply str (repeat (dec (- e)) \0)) m) m) 451.602 - len (count m1) 451.603 - target-len (if d (+ e d 1) (inc e))] 451.604 - (if (< len target-len) 451.605 - (str m1 (apply str (repeat (- target-len len) \0))) 451.606 - m1))) 451.607 - 451.608 -(defn- insert-decimal 451.609 - "Insert the decimal point at the right spot in the number to match an exponent" 451.610 - [m e] 451.611 - (if (neg? e) 451.612 - (str "." m) 451.613 - (let [loc (inc e)] 451.614 - (str (subs m 0 loc) "." (subs m loc))))) 451.615 - 451.616 -(defn- get-fixed [m e d] 451.617 - (insert-decimal (expand-fixed m e d) e)) 451.618 - 451.619 -(defn- insert-scaled-decimal 451.620 - "Insert the decimal point at the right spot in the number to match an exponent" 451.621 - [m k] 451.622 - (if (neg? k) 451.623 - (str "." m) 451.624 - (str (subs m 0 k) "." (subs m k)))) 451.625 - 451.626 -;; the function to render ~F directives 451.627 -;; TODO: support rationals. Back off to ~D/~A is the appropriate cases 451.628 -(defn- fixed-float [params navigator offsets] 451.629 - (let [w (:w params) 451.630 - d (:d params) 451.631 - [arg navigator] (next-arg navigator) 451.632 - [sign abs] (if (neg? arg) ["-" (- arg)] ["+" arg]) 451.633 - [mantissa exp] (float-parts abs) 451.634 - scaled-exp (+ exp (:k params)) 451.635 - add-sign (or (:at params) (neg? arg)) 451.636 - append-zero (and (not d) (<= (dec (count mantissa)) scaled-exp)) 451.637 - [rounded-mantissa scaled-exp expanded] (round-str mantissa scaled-exp 451.638 - d (if w (- w (if add-sign 1 0)))) 451.639 - fixed-repr (get-fixed rounded-mantissa (if expanded (inc scaled-exp) scaled-exp) d) 451.640 - prepend-zero (= (first fixed-repr) \.)] 451.641 - (if w 451.642 - (let [len (count fixed-repr) 451.643 - signed-len (if add-sign (inc len) len) 451.644 - prepend-zero (and prepend-zero (not (>= signed-len w))) 451.645 - append-zero (and append-zero (not (>= signed-len w))) 451.646 - full-len (if (or prepend-zero append-zero) 451.647 - (inc signed-len) 451.648 - signed-len)] 451.649 - (if (and (> full-len w) (:overflowchar params)) 451.650 - (print (apply str (repeat w (:overflowchar params)))) 451.651 - (print (str 451.652 - (apply str (repeat (- w full-len) (:padchar params))) 451.653 - (if add-sign sign) 451.654 - (if prepend-zero "0") 451.655 - fixed-repr 451.656 - (if append-zero "0"))))) 451.657 - (print (str 451.658 - (if add-sign sign) 451.659 - (if prepend-zero "0") 451.660 - fixed-repr 451.661 - (if append-zero "0")))) 451.662 - navigator)) 451.663 - 451.664 - 451.665 -;; the function to render ~E directives 451.666 -;; TODO: support rationals. Back off to ~D/~A is the appropriate cases 451.667 -;; TODO: define ~E representation for Infinity 451.668 -(defn- exponential-float [params navigator offsets] 451.669 - (let [[arg navigator] (next-arg navigator)] 451.670 - (loop [[mantissa exp] (float-parts (if (neg? arg) (- arg) arg))] 451.671 - (let [w (:w params) 451.672 - d (:d params) 451.673 - e (:e params) 451.674 - k (:k params) 451.675 - expchar (or (:exponentchar params) \E) 451.676 - add-sign (or (:at params) (neg? arg)) 451.677 - prepend-zero (<= k 0) 451.678 - ^Integer scaled-exp (- exp (dec k)) 451.679 - scaled-exp-str (str (Math/abs scaled-exp)) 451.680 - scaled-exp-str (str expchar (if (neg? scaled-exp) \- \+) 451.681 - (if e (apply str 451.682 - (repeat 451.683 - (- e 451.684 - (count scaled-exp-str)) 451.685 - \0))) 451.686 - scaled-exp-str) 451.687 - exp-width (count scaled-exp-str) 451.688 - base-mantissa-width (count mantissa) 451.689 - scaled-mantissa (str (apply str (repeat (- k) \0)) 451.690 - mantissa 451.691 - (if d 451.692 - (apply str 451.693 - (repeat 451.694 - (- d (dec base-mantissa-width) 451.695 - (if (neg? k) (- k) 0)) \0)))) 451.696 - w-mantissa (if w (- w exp-width)) 451.697 - [rounded-mantissa _ incr-exp] (round-str 451.698 - scaled-mantissa 0 451.699 - (cond 451.700 - (= k 0) (dec d) 451.701 - (pos? k) d 451.702 - (neg? k) (dec d)) 451.703 - (if w-mantissa 451.704 - (- w-mantissa (if add-sign 1 0)))) 451.705 - full-mantissa (insert-scaled-decimal rounded-mantissa k) 451.706 - append-zero (and (= k (count rounded-mantissa)) (nil? d))] 451.707 - (if (not incr-exp) 451.708 - (if w 451.709 - (let [len (+ (count full-mantissa) exp-width) 451.710 - signed-len (if add-sign (inc len) len) 451.711 - prepend-zero (and prepend-zero (not (= signed-len w))) 451.712 - full-len (if prepend-zero (inc signed-len) signed-len) 451.713 - append-zero (and append-zero (< full-len w))] 451.714 - (if (and (or (> full-len w) (and e (> (- exp-width 2) e))) 451.715 - (:overflowchar params)) 451.716 - (print (apply str (repeat w (:overflowchar params)))) 451.717 - (print (str 451.718 - (apply str 451.719 - (repeat 451.720 - (- w full-len (if append-zero 1 0) ) 451.721 - (:padchar params))) 451.722 - (if add-sign (if (neg? arg) \- \+)) 451.723 - (if prepend-zero "0") 451.724 - full-mantissa 451.725 - (if append-zero "0") 451.726 - scaled-exp-str)))) 451.727 - (print (str 451.728 - (if add-sign (if (neg? arg) \- \+)) 451.729 - (if prepend-zero "0") 451.730 - full-mantissa 451.731 - (if append-zero "0") 451.732 - scaled-exp-str))) 451.733 - (recur [rounded-mantissa (inc exp)])))) 451.734 - navigator)) 451.735 - 451.736 -;; the function to render ~G directives 451.737 -;; This just figures out whether to pass the request off to ~F or ~E based 451.738 -;; on the algorithm in CLtL. 451.739 -;; TODO: support rationals. Back off to ~D/~A is the appropriate cases 451.740 -;; TODO: refactor so that float-parts isn't called twice 451.741 -(defn- general-float [params navigator offsets] 451.742 - (let [[arg _] (next-arg navigator) 451.743 - [mantissa exp] (float-parts (if (neg? arg) (- arg) arg)) 451.744 - w (:w params) 451.745 - d (:d params) 451.746 - e (:e params) 451.747 - n (if (= arg 0.0) 0 (inc exp)) 451.748 - ee (if e (+ e 2) 4) 451.749 - ww (if w (- w ee)) 451.750 - d (if d d (max (count mantissa) (min n 7))) 451.751 - dd (- d n)] 451.752 - (if (<= 0 dd d) 451.753 - (let [navigator (fixed-float {:w ww, :d dd, :k 0, 451.754 - :overflowchar (:overflowchar params), 451.755 - :padchar (:padchar params), :at (:at params)} 451.756 - navigator offsets)] 451.757 - (print (apply str (repeat ee \space))) 451.758 - navigator) 451.759 - (exponential-float params navigator offsets)))) 451.760 - 451.761 -;; the function to render ~$ directives 451.762 -;; TODO: support rationals. Back off to ~D/~A is the appropriate cases 451.763 -(defn- dollar-float [params navigator offsets] 451.764 - (let [[^Double arg navigator] (next-arg navigator) 451.765 - [mantissa exp] (float-parts (Math/abs arg)) 451.766 - d (:d params) ; digits after the decimal 451.767 - n (:n params) ; minimum digits before the decimal 451.768 - w (:w params) ; minimum field width 451.769 - add-sign (or (:at params) (neg? arg)) 451.770 - [rounded-mantissa scaled-exp expanded] (round-str mantissa exp d nil) 451.771 - ^String fixed-repr (get-fixed rounded-mantissa (if expanded (inc scaled-exp) scaled-exp) d) 451.772 - full-repr (str (apply str (repeat (- n (.indexOf fixed-repr (int \.))) \0)) fixed-repr) 451.773 - full-len (+ (count full-repr) (if add-sign 1 0))] 451.774 - (print (str 451.775 - (if (and (:colon params) add-sign) (if (neg? arg) \- \+)) 451.776 - (apply str (repeat (- w full-len) (:padchar params))) 451.777 - (if (and (not (:colon params)) add-sign) (if (neg? arg) \- \+)) 451.778 - full-repr)) 451.779 - navigator)) 451.780 - 451.781 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.782 -;;; Support for the '~[...~]' conditional construct in its 451.783 -;;; different flavors 451.784 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.785 - 451.786 -;; ~[...~] without any modifiers chooses one of the clauses based on the param or 451.787 -;; next argument 451.788 -;; TODO check arg is positive int 451.789 -(defn- choice-conditional [params arg-navigator offsets] 451.790 - (let [arg (:selector params) 451.791 - [arg navigator] (if arg [arg arg-navigator] (next-arg arg-navigator)) 451.792 - clauses (:clauses params) 451.793 - clause (if (or (neg? arg) (>= arg (count clauses))) 451.794 - (first (:else params)) 451.795 - (nth clauses arg))] 451.796 - (if clause 451.797 - (execute-sub-format clause navigator (:base-args params)) 451.798 - navigator))) 451.799 - 451.800 -;; ~:[...~] with the colon reads the next argument treating it as a truth value 451.801 -(defn- boolean-conditional [params arg-navigator offsets] 451.802 - (let [[arg navigator] (next-arg arg-navigator) 451.803 - clauses (:clauses params) 451.804 - clause (if arg 451.805 - (second clauses) 451.806 - (first clauses))] 451.807 - (if clause 451.808 - (execute-sub-format clause navigator (:base-args params)) 451.809 - navigator))) 451.810 - 451.811 -;; ~@[...~] with the at sign executes the conditional if the next arg is not 451.812 -;; nil/false without consuming the arg 451.813 -(defn- check-arg-conditional [params arg-navigator offsets] 451.814 - (let [[arg navigator] (next-arg arg-navigator) 451.815 - clauses (:clauses params) 451.816 - clause (if arg (first clauses))] 451.817 - (if arg 451.818 - (if clause 451.819 - (execute-sub-format clause arg-navigator (:base-args params)) 451.820 - arg-navigator) 451.821 - navigator))) 451.822 - 451.823 - 451.824 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.825 -;;; Support for the '~{...~}' iteration construct in its 451.826 -;;; different flavors 451.827 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.828 - 451.829 - 451.830 -;; ~{...~} without any modifiers uses the next argument as an argument list that 451.831 -;; is consumed by all the iterations 451.832 -(defn- iterate-sublist [params navigator offsets] 451.833 - (let [max-count (:max-iterations params) 451.834 - param-clause (first (:clauses params)) 451.835 - [clause navigator] (if (empty? param-clause) 451.836 - (get-format-arg navigator) 451.837 - [param-clause navigator]) 451.838 - [arg-list navigator] (next-arg navigator) 451.839 - args (init-navigator arg-list)] 451.840 - (loop [count 0 451.841 - args args 451.842 - last-pos -1] 451.843 - (if (and (not max-count) (= (:pos args) last-pos) (> count 1)) 451.844 - ;; TODO get the offset in here and call format exception 451.845 - (throw (RuntimeException. "%{ construct not consuming any arguments: Infinite loop!"))) 451.846 - (if (or (and (empty? (:rest args)) 451.847 - (or (not (:colon (:right-params params))) (> count 0))) 451.848 - (and max-count (>= count max-count))) 451.849 - navigator 451.850 - (let [iter-result (execute-sub-format clause args (:base-args params))] 451.851 - (if (= :up-arrow (first iter-result)) 451.852 - navigator 451.853 - (recur (inc count) iter-result (:pos args)))))))) 451.854 - 451.855 -;; ~:{...~} with the colon treats the next argument as a list of sublists. Each of the 451.856 -;; sublists is used as the arglist for a single iteration. 451.857 -(defn- iterate-list-of-sublists [params navigator offsets] 451.858 - (let [max-count (:max-iterations params) 451.859 - param-clause (first (:clauses params)) 451.860 - [clause navigator] (if (empty? param-clause) 451.861 - (get-format-arg navigator) 451.862 - [param-clause navigator]) 451.863 - [arg-list navigator] (next-arg navigator)] 451.864 - (loop [count 0 451.865 - arg-list arg-list] 451.866 - (if (or (and (empty? arg-list) 451.867 - (or (not (:colon (:right-params params))) (> count 0))) 451.868 - (and max-count (>= count max-count))) 451.869 - navigator 451.870 - (let [iter-result (execute-sub-format 451.871 - clause 451.872 - (init-navigator (first arg-list)) 451.873 - (init-navigator (next arg-list)))] 451.874 - (if (= :colon-up-arrow (first iter-result)) 451.875 - navigator 451.876 - (recur (inc count) (next arg-list)))))))) 451.877 - 451.878 -;; ~@{...~} with the at sign uses the main argument list as the arguments to the iterations 451.879 -;; is consumed by all the iterations 451.880 -(defn- iterate-main-list [params navigator offsets] 451.881 - (let [max-count (:max-iterations params) 451.882 - param-clause (first (:clauses params)) 451.883 - [clause navigator] (if (empty? param-clause) 451.884 - (get-format-arg navigator) 451.885 - [param-clause navigator])] 451.886 - (loop [count 0 451.887 - navigator navigator 451.888 - last-pos -1] 451.889 - (if (and (not max-count) (= (:pos navigator) last-pos) (> count 1)) 451.890 - ;; TODO get the offset in here and call format exception 451.891 - (throw (RuntimeException. "%@{ construct not consuming any arguments: Infinite loop!"))) 451.892 - (if (or (and (empty? (:rest navigator)) 451.893 - (or (not (:colon (:right-params params))) (> count 0))) 451.894 - (and max-count (>= count max-count))) 451.895 - navigator 451.896 - (let [iter-result (execute-sub-format clause navigator (:base-args params))] 451.897 - (if (= :up-arrow (first iter-result)) 451.898 - (second iter-result) 451.899 - (recur 451.900 - (inc count) iter-result (:pos navigator)))))))) 451.901 - 451.902 -;; ~@:{...~} with both colon and at sign uses the main argument list as a set of sublists, one 451.903 -;; of which is consumed with each iteration 451.904 -(defn- iterate-main-sublists [params navigator offsets] 451.905 - (let [max-count (:max-iterations params) 451.906 - param-clause (first (:clauses params)) 451.907 - [clause navigator] (if (empty? param-clause) 451.908 - (get-format-arg navigator) 451.909 - [param-clause navigator]) 451.910 - ] 451.911 - (loop [count 0 451.912 - navigator navigator] 451.913 - (if (or (and (empty? (:rest navigator)) 451.914 - (or (not (:colon (:right-params params))) (> count 0))) 451.915 - (and max-count (>= count max-count))) 451.916 - navigator 451.917 - (let [[sublist navigator] (next-arg-or-nil navigator) 451.918 - iter-result (execute-sub-format clause (init-navigator sublist) navigator)] 451.919 - (if (= :colon-up-arrow (first iter-result)) 451.920 - navigator 451.921 - (recur (inc count) navigator))))))) 451.922 - 451.923 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.924 -;;; The '~< directive has two completely different meanings 451.925 -;;; in the '~<...~>' form it does justification, but with 451.926 -;;; ~<...~:>' it represents the logical block operation of the 451.927 -;;; pretty printer. 451.928 -;;; 451.929 -;;; Unfortunately, the current architecture decides what function 451.930 -;;; to call at form parsing time before the sub-clauses have been 451.931 -;;; folded, so it is left to run-time to make the decision. 451.932 -;;; 451.933 -;;; TODO: make it possible to make these decisions at compile-time. 451.934 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.935 - 451.936 -(declare format-logical-block) 451.937 -(declare justify-clauses) 451.938 - 451.939 -(defn- logical-block-or-justify [params navigator offsets] 451.940 - (if (:colon (:right-params params)) 451.941 - (format-logical-block params navigator offsets) 451.942 - (justify-clauses params navigator offsets))) 451.943 - 451.944 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.945 -;;; Support for the '~<...~>' justification directive 451.946 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.947 - 451.948 -(defn- render-clauses [clauses navigator base-navigator] 451.949 - (loop [clauses clauses 451.950 - acc [] 451.951 - navigator navigator] 451.952 - (if (empty? clauses) 451.953 - [acc navigator] 451.954 - (let [clause (first clauses) 451.955 - [iter-result result-str] (binding [*out* (java.io.StringWriter.)] 451.956 - [(execute-sub-format clause navigator base-navigator) 451.957 - (.toString *out*)])] 451.958 - (if (= :up-arrow (first iter-result)) 451.959 - [acc (second iter-result)] 451.960 - (recur (next clauses) (conj acc result-str) iter-result)))))) 451.961 - 451.962 -;; TODO support for ~:; constructions 451.963 -(defn- justify-clauses [params navigator offsets] 451.964 - (let [[[eol-str] new-navigator] (when-let [else (:else params)] 451.965 - (render-clauses else navigator (:base-args params))) 451.966 - navigator (or new-navigator navigator) 451.967 - [else-params new-navigator] (when-let [p (:else-params params)] 451.968 - (realize-parameter-list p navigator)) 451.969 - navigator (or new-navigator navigator) 451.970 - min-remaining (or (first (:min-remaining else-params)) 0) 451.971 - max-columns (or (first (:max-columns else-params)) 451.972 - (get-max-column *out*)) 451.973 - clauses (:clauses params) 451.974 - [strs navigator] (render-clauses clauses navigator (:base-args params)) 451.975 - slots (max 1 451.976 - (+ (dec (count strs)) (if (:colon params) 1 0) (if (:at params) 1 0))) 451.977 - chars (reduce + (map count strs)) 451.978 - mincol (:mincol params) 451.979 - minpad (:minpad params) 451.980 - colinc (:colinc params) 451.981 - minout (+ chars (* slots minpad)) 451.982 - result-columns (if (<= minout mincol) 451.983 - mincol 451.984 - (+ mincol (* colinc 451.985 - (+ 1 (quot (- minout mincol 1) colinc))))) 451.986 - total-pad (- result-columns chars) 451.987 - pad (max minpad (quot total-pad slots)) 451.988 - extra-pad (- total-pad (* pad slots)) 451.989 - pad-str (apply str (repeat pad (:padchar params)))] 451.990 - (if (and eol-str (> (+ (get-column (:base @@*out*)) min-remaining result-columns) 451.991 - max-columns)) 451.992 - (print eol-str)) 451.993 - (loop [slots slots 451.994 - extra-pad extra-pad 451.995 - strs strs 451.996 - pad-only (or (:colon params) 451.997 - (and (= (count strs) 1) (not (:at params))))] 451.998 - (if (seq strs) 451.999 - (do 451.1000 - (print (str (if (not pad-only) (first strs)) 451.1001 - (if (or pad-only (next strs) (:at params)) pad-str) 451.1002 - (if (pos? extra-pad) (:padchar params)))) 451.1003 - (recur 451.1004 - (dec slots) 451.1005 - (dec extra-pad) 451.1006 - (if pad-only strs (next strs)) 451.1007 - false)))) 451.1008 - navigator)) 451.1009 - 451.1010 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1011 -;;; Support for case modification with ~(...~). 451.1012 -;;; We do this by wrapping the underlying writer with 451.1013 -;;; a special writer to do the appropriate modification. This 451.1014 -;;; allows us to support arbitrary-sized output and sources 451.1015 -;;; that may block. 451.1016 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1017 - 451.1018 -(defn- downcase-writer 451.1019 - "Returns a proxy that wraps writer, converting all characters to lower case" 451.1020 - [^java.io.Writer writer] 451.1021 - (proxy [java.io.Writer] [] 451.1022 - (close [] (.close writer)) 451.1023 - (flush [] (.flush writer)) 451.1024 - (write ([^chars cbuf ^Integer off ^Integer len] 451.1025 - (.write writer cbuf off len)) 451.1026 - ([x] 451.1027 - (condp = (class x) 451.1028 - String 451.1029 - (let [s ^String x] 451.1030 - (.write writer (.toLowerCase s))) 451.1031 - 451.1032 - Integer 451.1033 - (let [c ^Character x] 451.1034 - (.write writer (int (Character/toLowerCase (char c)))))))))) 451.1035 - 451.1036 -(defn- upcase-writer 451.1037 - "Returns a proxy that wraps writer, converting all characters to upper case" 451.1038 - [^java.io.Writer writer] 451.1039 - (proxy [java.io.Writer] [] 451.1040 - (close [] (.close writer)) 451.1041 - (flush [] (.flush writer)) 451.1042 - (write ([^chars cbuf ^Integer off ^Integer len] 451.1043 - (.write writer cbuf off len)) 451.1044 - ([x] 451.1045 - (condp = (class x) 451.1046 - String 451.1047 - (let [s ^String x] 451.1048 - (.write writer (.toUpperCase s))) 451.1049 - 451.1050 - Integer 451.1051 - (let [c ^Character x] 451.1052 - (.write writer (int (Character/toUpperCase (char c)))))))))) 451.1053 - 451.1054 -(defn- capitalize-string 451.1055 - "Capitalizes the words in a string. If first? is false, don't capitalize the 451.1056 - first character of the string even if it's a letter." 451.1057 - [s first?] 451.1058 - (let [^Character f (first s) 451.1059 - s (if (and first? f (Character/isLetter f)) 451.1060 - (str (Character/toUpperCase f) (subs s 1)) 451.1061 - s)] 451.1062 - (apply str 451.1063 - (first 451.1064 - (consume 451.1065 - (fn [s] 451.1066 - (if (empty? s) 451.1067 - [nil nil] 451.1068 - (let [m (re-matcher #"\W\w" s) 451.1069 - match (re-find m) 451.1070 - offset (and match (inc (.start m)))] 451.1071 - (if offset 451.1072 - [(str (subs s 0 offset) 451.1073 - (Character/toUpperCase ^Character (nth s offset))) 451.1074 - (subs s (inc offset))] 451.1075 - [s nil])))) 451.1076 - s))))) 451.1077 - 451.1078 -(defn- capitalize-word-writer 451.1079 - "Returns a proxy that wraps writer, captializing all words" 451.1080 - [^java.io.Writer writer] 451.1081 - (let [last-was-whitespace? (ref true)] 451.1082 - (proxy [java.io.Writer] [] 451.1083 - (close [] (.close writer)) 451.1084 - (flush [] (.flush writer)) 451.1085 - (write 451.1086 - ([^chars cbuf ^Integer off ^Integer len] 451.1087 - (.write writer cbuf off len)) 451.1088 - ([x] 451.1089 - (condp = (class x) 451.1090 - String 451.1091 - (let [s ^String x] 451.1092 - (.write writer 451.1093 - ^String (capitalize-string (.toLowerCase s) @last-was-whitespace?)) 451.1094 - (dosync 451.1095 - (ref-set last-was-whitespace? 451.1096 - (Character/isWhitespace 451.1097 - ^Character (nth s (dec (count s))))))) 451.1098 - 451.1099 - Integer 451.1100 - (let [c (char x)] 451.1101 - (let [mod-c (if @last-was-whitespace? (Character/toUpperCase ^Character (char x)) c)] 451.1102 - (.write writer (int mod-c)) 451.1103 - (dosync (ref-set last-was-whitespace? (Character/isWhitespace ^Character (char x)))))))))))) 451.1104 - 451.1105 -(defn- init-cap-writer 451.1106 - "Returns a proxy that wraps writer, capitalizing the first word" 451.1107 - [^java.io.Writer writer] 451.1108 - (let [capped (ref false)] 451.1109 - (proxy [java.io.Writer] [] 451.1110 - (close [] (.close writer)) 451.1111 - (flush [] (.flush writer)) 451.1112 - (write ([^chars cbuf ^Integer off ^Integer len] 451.1113 - (.write writer cbuf off len)) 451.1114 - ([x] 451.1115 - (condp = (class x) 451.1116 - String 451.1117 - (let [s (.toLowerCase ^String x)] 451.1118 - (if (not @capped) 451.1119 - (let [m (re-matcher #"\S" s) 451.1120 - match (re-find m) 451.1121 - offset (and match (.start m))] 451.1122 - (if offset 451.1123 - (do (.write writer 451.1124 - (str (subs s 0 offset) 451.1125 - (Character/toUpperCase ^Character (nth s offset)) 451.1126 - (.toLowerCase ^String (subs s (inc offset))))) 451.1127 - (dosync (ref-set capped true))) 451.1128 - (.write writer s))) 451.1129 - (.write writer (.toLowerCase s)))) 451.1130 - 451.1131 - Integer 451.1132 - (let [c ^Character (char x)] 451.1133 - (if (and (not @capped) (Character/isLetter c)) 451.1134 - (do 451.1135 - (dosync (ref-set capped true)) 451.1136 - (.write writer (int (Character/toUpperCase c)))) 451.1137 - (.write writer (int (Character/toLowerCase c))))))))))) 451.1138 - 451.1139 -(defn- modify-case [make-writer params navigator offsets] 451.1140 - (let [clause (first (:clauses params))] 451.1141 - (binding [*out* (make-writer *out*)] 451.1142 - (execute-sub-format clause navigator (:base-args params))))) 451.1143 - 451.1144 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1145 -;;; If necessary, wrap the writer in a PrettyWriter object 451.1146 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1147 - 451.1148 -(defn get-pretty-writer 451.1149 - "Returns the java.io.Writer passed in wrapped in a pretty writer proxy, unless it's 451.1150 -already a pretty writer. Generally, it is unneccesary to call this function, since pprint, 451.1151 -write, and cl-format all call it if they need to. However if you want the state to be 451.1152 -preserved across calls, you will want to wrap them with this. 451.1153 - 451.1154 -For example, when you want to generate column-aware output with multiple calls to cl-format, 451.1155 -do it like in this example: 451.1156 - 451.1157 - (defn print-table [aseq column-width] 451.1158 - (binding [*out* (get-pretty-writer *out*)] 451.1159 - (doseq [row aseq] 451.1160 - (doseq [col row] 451.1161 - (cl-format true \"~4D~7,vT\" col column-width)) 451.1162 - (prn)))) 451.1163 - 451.1164 -Now when you run: 451.1165 - 451.1166 - user> (print-table (map #(vector % (* % %) (* % % %)) (range 1 11)) 8) 451.1167 - 451.1168 -It prints a table of squares and cubes for the numbers from 1 to 10: 451.1169 - 451.1170 - 1 1 1 451.1171 - 2 4 8 451.1172 - 3 9 27 451.1173 - 4 16 64 451.1174 - 5 25 125 451.1175 - 6 36 216 451.1176 - 7 49 343 451.1177 - 8 64 512 451.1178 - 9 81 729 451.1179 - 10 100 1000" 451.1180 - {:added "1.2"} 451.1181 - [writer] 451.1182 - (if (pretty-writer? writer) 451.1183 - writer 451.1184 - (pretty-writer writer *print-right-margin* *print-miser-width*))) 451.1185 - 451.1186 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1187 -;;; Support for column-aware operations ~&, ~T 451.1188 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1189 - 451.1190 -(defn fresh-line 451.1191 - "Make a newline if *out* is not already at the beginning of the line. If *out* is 451.1192 -not a pretty writer (which keeps track of columns), this function always outputs a newline." 451.1193 - {:added "1.2"} 451.1194 - [] 451.1195 - (if (instance? clojure.lang.IDeref *out*) 451.1196 - (if (not (= 0 (get-column (:base @@*out*)))) 451.1197 - (prn)) 451.1198 - (prn))) 451.1199 - 451.1200 -(defn- absolute-tabulation [params navigator offsets] 451.1201 - (let [colnum (:colnum params) 451.1202 - colinc (:colinc params) 451.1203 - current (get-column (:base @@*out*)) 451.1204 - space-count (cond 451.1205 - (< current colnum) (- colnum current) 451.1206 - (= colinc 0) 0 451.1207 - :else (- colinc (rem (- current colnum) colinc)))] 451.1208 - (print (apply str (repeat space-count \space)))) 451.1209 - navigator) 451.1210 - 451.1211 -(defn- relative-tabulation [params navigator offsets] 451.1212 - (let [colrel (:colnum params) 451.1213 - colinc (:colinc params) 451.1214 - start-col (+ colrel (get-column (:base @@*out*))) 451.1215 - offset (if (pos? colinc) (rem start-col colinc) 0) 451.1216 - space-count (+ colrel (if (= 0 offset) 0 (- colinc offset)))] 451.1217 - (print (apply str (repeat space-count \space)))) 451.1218 - navigator) 451.1219 - 451.1220 - 451.1221 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1222 -;;; Support for accessing the pretty printer from a format 451.1223 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1224 - 451.1225 -;; TODO: support ~@; per-line-prefix separator 451.1226 -;; TODO: get the whole format wrapped so we can start the lb at any column 451.1227 -(defn- format-logical-block [params navigator offsets] 451.1228 - (let [clauses (:clauses params) 451.1229 - clause-count (count clauses) 451.1230 - prefix (cond 451.1231 - (> clause-count 1) (:string (:params (first (first clauses)))) 451.1232 - (:colon params) "(") 451.1233 - body (nth clauses (if (> clause-count 1) 1 0)) 451.1234 - suffix (cond 451.1235 - (> clause-count 2) (:string (:params (first (nth clauses 2)))) 451.1236 - (:colon params) ")") 451.1237 - [arg navigator] (next-arg navigator)] 451.1238 - (pprint-logical-block :prefix prefix :suffix suffix 451.1239 - (execute-sub-format 451.1240 - body 451.1241 - (init-navigator arg) 451.1242 - (:base-args params))) 451.1243 - navigator)) 451.1244 - 451.1245 -(defn- set-indent [params navigator offsets] 451.1246 - (let [relative-to (if (:colon params) :current :block)] 451.1247 - (pprint-indent relative-to (:n params)) 451.1248 - navigator)) 451.1249 - 451.1250 -;;; TODO: support ~:T section options for ~T 451.1251 - 451.1252 -(defn- conditional-newline [params navigator offsets] 451.1253 - (let [kind (if (:colon params) 451.1254 - (if (:at params) :mandatory :fill) 451.1255 - (if (:at params) :miser :linear))] 451.1256 - (pprint-newline kind) 451.1257 - navigator)) 451.1258 - 451.1259 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1260 -;;; The table of directives we support, each with its params, 451.1261 -;;; properties, and the compilation function 451.1262 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1263 - 451.1264 -;; We start with a couple of helpers 451.1265 -(defn- process-directive-table-element [ [ char params flags bracket-info & generator-fn ] ] 451.1266 - [char, 451.1267 - {:directive char, 451.1268 - :params `(array-map ~@params), 451.1269 - :flags flags, 451.1270 - :bracket-info bracket-info, 451.1271 - :generator-fn (concat '(fn [ params offset]) generator-fn) }]) 451.1272 - 451.1273 -(defmacro ^{:private true} 451.1274 - defdirectives 451.1275 - [ & directives ] 451.1276 - `(def ^{:private true} 451.1277 - directive-table (hash-map ~@(mapcat process-directive-table-element directives)))) 451.1278 - 451.1279 -(defdirectives 451.1280 - (\A 451.1281 - [ :mincol [0 Integer] :colinc [1 Integer] :minpad [0 Integer] :padchar [\space Character] ] 451.1282 - #{ :at :colon :both} {} 451.1283 - #(format-ascii print-str %1 %2 %3)) 451.1284 - 451.1285 - (\S 451.1286 - [ :mincol [0 Integer] :colinc [1 Integer] :minpad [0 Integer] :padchar [\space Character] ] 451.1287 - #{ :at :colon :both} {} 451.1288 - #(format-ascii pr-str %1 %2 %3)) 451.1289 - 451.1290 - (\D 451.1291 - [ :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 451.1292 - :commainterval [ 3 Integer]] 451.1293 - #{ :at :colon :both } {} 451.1294 - #(format-integer 10 %1 %2 %3)) 451.1295 - 451.1296 - (\B 451.1297 - [ :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 451.1298 - :commainterval [ 3 Integer]] 451.1299 - #{ :at :colon :both } {} 451.1300 - #(format-integer 2 %1 %2 %3)) 451.1301 - 451.1302 - (\O 451.1303 - [ :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 451.1304 - :commainterval [ 3 Integer]] 451.1305 - #{ :at :colon :both } {} 451.1306 - #(format-integer 8 %1 %2 %3)) 451.1307 - 451.1308 - (\X 451.1309 - [ :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 451.1310 - :commainterval [ 3 Integer]] 451.1311 - #{ :at :colon :both } {} 451.1312 - #(format-integer 16 %1 %2 %3)) 451.1313 - 451.1314 - (\R 451.1315 - [:base [nil Integer] :mincol [0 Integer] :padchar [\space Character] :commachar [\, Character] 451.1316 - :commainterval [ 3 Integer]] 451.1317 - #{ :at :colon :both } {} 451.1318 - (do 451.1319 - (cond ; ~R is overloaded with bizareness 451.1320 - (first (:base params)) #(format-integer (:base %1) %1 %2 %3) 451.1321 - (and (:at params) (:colon params)) #(format-old-roman %1 %2 %3) 451.1322 - (:at params) #(format-new-roman %1 %2 %3) 451.1323 - (:colon params) #(format-ordinal-english %1 %2 %3) 451.1324 - true #(format-cardinal-english %1 %2 %3)))) 451.1325 - 451.1326 - (\P 451.1327 - [ ] 451.1328 - #{ :at :colon :both } {} 451.1329 - (fn [params navigator offsets] 451.1330 - (let [navigator (if (:colon params) (relative-reposition navigator -1) navigator) 451.1331 - strs (if (:at params) ["y" "ies"] ["" "s"]) 451.1332 - [arg navigator] (next-arg navigator)] 451.1333 - (print (if (= arg 1) (first strs) (second strs))) 451.1334 - navigator))) 451.1335 - 451.1336 - (\C 451.1337 - [:char-format [nil Character]] 451.1338 - #{ :at :colon :both } {} 451.1339 - (cond 451.1340 - (:colon params) pretty-character 451.1341 - (:at params) readable-character 451.1342 - :else plain-character)) 451.1343 - 451.1344 - (\F 451.1345 - [ :w [nil Integer] :d [nil Integer] :k [0 Integer] :overflowchar [nil Character] 451.1346 - :padchar [\space Character] ] 451.1347 - #{ :at } {} 451.1348 - fixed-float) 451.1349 - 451.1350 - (\E 451.1351 - [ :w [nil Integer] :d [nil Integer] :e [nil Integer] :k [1 Integer] 451.1352 - :overflowchar [nil Character] :padchar [\space Character] 451.1353 - :exponentchar [nil Character] ] 451.1354 - #{ :at } {} 451.1355 - exponential-float) 451.1356 - 451.1357 - (\G 451.1358 - [ :w [nil Integer] :d [nil Integer] :e [nil Integer] :k [1 Integer] 451.1359 - :overflowchar [nil Character] :padchar [\space Character] 451.1360 - :exponentchar [nil Character] ] 451.1361 - #{ :at } {} 451.1362 - general-float) 451.1363 - 451.1364 - (\$ 451.1365 - [ :d [2 Integer] :n [1 Integer] :w [0 Integer] :padchar [\space Character]] 451.1366 - #{ :at :colon :both} {} 451.1367 - dollar-float) 451.1368 - 451.1369 - (\% 451.1370 - [ :count [1 Integer] ] 451.1371 - #{ } {} 451.1372 - (fn [params arg-navigator offsets] 451.1373 - (dotimes [i (:count params)] 451.1374 - (prn)) 451.1375 - arg-navigator)) 451.1376 - 451.1377 - (\& 451.1378 - [ :count [1 Integer] ] 451.1379 - #{ :pretty } {} 451.1380 - (fn [params arg-navigator offsets] 451.1381 - (let [cnt (:count params)] 451.1382 - (if (pos? cnt) (fresh-line)) 451.1383 - (dotimes [i (dec cnt)] 451.1384 - (prn))) 451.1385 - arg-navigator)) 451.1386 - 451.1387 - (\| 451.1388 - [ :count [1 Integer] ] 451.1389 - #{ } {} 451.1390 - (fn [params arg-navigator offsets] 451.1391 - (dotimes [i (:count params)] 451.1392 - (print \formfeed)) 451.1393 - arg-navigator)) 451.1394 - 451.1395 - (\~ 451.1396 - [ :n [1 Integer] ] 451.1397 - #{ } {} 451.1398 - (fn [params arg-navigator offsets] 451.1399 - (let [n (:n params)] 451.1400 - (print (apply str (repeat n \~))) 451.1401 - arg-navigator))) 451.1402 - 451.1403 - (\newline ;; Whitespace supression is handled in the compilation loop 451.1404 - [ ] 451.1405 - #{:colon :at} {} 451.1406 - (fn [params arg-navigator offsets] 451.1407 - (if (:at params) 451.1408 - (prn)) 451.1409 - arg-navigator)) 451.1410 - 451.1411 - (\T 451.1412 - [ :colnum [1 Integer] :colinc [1 Integer] ] 451.1413 - #{ :at :pretty } {} 451.1414 - (if (:at params) 451.1415 - #(relative-tabulation %1 %2 %3) 451.1416 - #(absolute-tabulation %1 %2 %3))) 451.1417 - 451.1418 - (\* 451.1419 - [ :n [1 Integer] ] 451.1420 - #{ :colon :at } {} 451.1421 - (fn [params navigator offsets] 451.1422 - (let [n (:n params)] 451.1423 - (if (:at params) 451.1424 - (absolute-reposition navigator n) 451.1425 - (relative-reposition navigator (if (:colon params) (- n) n))) 451.1426 - ))) 451.1427 - 451.1428 - (\? 451.1429 - [ ] 451.1430 - #{ :at } {} 451.1431 - (if (:at params) 451.1432 - (fn [params navigator offsets] ; args from main arg list 451.1433 - (let [[subformat navigator] (get-format-arg navigator)] 451.1434 - (execute-sub-format subformat navigator (:base-args params)))) 451.1435 - (fn [params navigator offsets] ; args from sub-list 451.1436 - (let [[subformat navigator] (get-format-arg navigator) 451.1437 - [subargs navigator] (next-arg navigator) 451.1438 - sub-navigator (init-navigator subargs)] 451.1439 - (execute-sub-format subformat sub-navigator (:base-args params)) 451.1440 - navigator)))) 451.1441 - 451.1442 - 451.1443 - (\( 451.1444 - [ ] 451.1445 - #{ :colon :at :both} { :right \), :allows-separator nil, :else nil } 451.1446 - (let [mod-case-writer (cond 451.1447 - (and (:at params) (:colon params)) 451.1448 - upcase-writer 451.1449 - 451.1450 - (:colon params) 451.1451 - capitalize-word-writer 451.1452 - 451.1453 - (:at params) 451.1454 - init-cap-writer 451.1455 - 451.1456 - :else 451.1457 - downcase-writer)] 451.1458 - #(modify-case mod-case-writer %1 %2 %3))) 451.1459 - 451.1460 - (\) [] #{} {} nil) 451.1461 - 451.1462 - (\[ 451.1463 - [ :selector [nil Integer] ] 451.1464 - #{ :colon :at } { :right \], :allows-separator true, :else :last } 451.1465 - (cond 451.1466 - (:colon params) 451.1467 - boolean-conditional 451.1468 - 451.1469 - (:at params) 451.1470 - check-arg-conditional 451.1471 - 451.1472 - true 451.1473 - choice-conditional)) 451.1474 - 451.1475 - (\; [:min-remaining [nil Integer] :max-columns [nil Integer]] 451.1476 - #{ :colon } { :separator true } nil) 451.1477 - 451.1478 - (\] [] #{} {} nil) 451.1479 - 451.1480 - (\{ 451.1481 - [ :max-iterations [nil Integer] ] 451.1482 - #{ :colon :at :both} { :right \}, :allows-separator false } 451.1483 - (cond 451.1484 - (and (:at params) (:colon params)) 451.1485 - iterate-main-sublists 451.1486 - 451.1487 - (:colon params) 451.1488 - iterate-list-of-sublists 451.1489 - 451.1490 - (:at params) 451.1491 - iterate-main-list 451.1492 - 451.1493 - true 451.1494 - iterate-sublist)) 451.1495 - 451.1496 - 451.1497 - (\} [] #{:colon} {} nil) 451.1498 - 451.1499 - (\< 451.1500 - [:mincol [0 Integer] :colinc [1 Integer] :minpad [0 Integer] :padchar [\space Character]] 451.1501 - #{:colon :at :both :pretty} { :right \>, :allows-separator true, :else :first } 451.1502 - logical-block-or-justify) 451.1503 - 451.1504 - (\> [] #{:colon} {} nil) 451.1505 - 451.1506 - ;; TODO: detect errors in cases where colon not allowed 451.1507 - (\^ [:arg1 [nil Integer] :arg2 [nil Integer] :arg3 [nil Integer]] 451.1508 - #{:colon} {} 451.1509 - (fn [params navigator offsets] 451.1510 - (let [arg1 (:arg1 params) 451.1511 - arg2 (:arg2 params) 451.1512 - arg3 (:arg3 params) 451.1513 - exit (if (:colon params) :colon-up-arrow :up-arrow)] 451.1514 - (cond 451.1515 - (and arg1 arg2 arg3) 451.1516 - (if (<= arg1 arg2 arg3) [exit navigator] navigator) 451.1517 - 451.1518 - (and arg1 arg2) 451.1519 - (if (= arg1 arg2) [exit navigator] navigator) 451.1520 - 451.1521 - arg1 451.1522 - (if (= arg1 0) [exit navigator] navigator) 451.1523 - 451.1524 - true ; TODO: handle looking up the arglist stack for info 451.1525 - (if (if (:colon params) 451.1526 - (empty? (:rest (:base-args params))) 451.1527 - (empty? (:rest navigator))) 451.1528 - [exit navigator] navigator))))) 451.1529 - 451.1530 - (\W 451.1531 - [] 451.1532 - #{:at :colon :both} {} 451.1533 - (if (or (:at params) (:colon params)) 451.1534 - (let [bindings (concat 451.1535 - (if (:at params) [:level nil :length nil] []) 451.1536 - (if (:colon params) [:pretty true] []))] 451.1537 - (fn [params navigator offsets] 451.1538 - (let [[arg navigator] (next-arg navigator)] 451.1539 - (if (apply write arg bindings) 451.1540 - [:up-arrow navigator] 451.1541 - navigator)))) 451.1542 - (fn [params navigator offsets] 451.1543 - (let [[arg navigator] (next-arg navigator)] 451.1544 - (if (write-out arg) 451.1545 - [:up-arrow navigator] 451.1546 - navigator))))) 451.1547 - 451.1548 - (\_ 451.1549 - [] 451.1550 - #{:at :colon :both} {} 451.1551 - conditional-newline) 451.1552 - 451.1553 - (\I 451.1554 - [:n [0 Integer]] 451.1555 - #{:colon} {} 451.1556 - set-indent) 451.1557 - ) 451.1558 - 451.1559 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1560 -;;; Code to manage the parameters and flags associated with each 451.1561 -;;; directive in the format string. 451.1562 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 451.1563 - 451.1564 -(def ^{:private true} 451.1565 - param-pattern #"^([vV]|#|('.)|([+-]?\d+)|(?=,))") 451.1566 -(def ^{:private true} 451.1567 - special-params #{ :parameter-from-args :remaining-arg-count }) 451.1568 - 451.1569 -(defn- extract-param [[s offset saw-comma]] 451.1570 - (let [m (re-matcher param-pattern s) 451.1571 - param (re-find m)] 451.1572 - (if param 451.1573 - (let [token-str (first (re-groups m)) 451.1574 - remainder (subs s (.end m)) 451.1575 - new-offset (+ offset (.end m))] 451.1576 - (if (not (= \, (nth remainder 0))) 451.1577 - [ [token-str offset] [remainder new-offset false]] 451.1578 - [ [token-str offset] [(subs remainder 1) (inc new-offset) true]])) 451.1579 - (if saw-comma 451.1580 - (format-error "Badly formed parameters in format directive" offset) 451.1581 - [ nil [s offset]])))) 451.1582 - 451.1583 - 451.1584 -(defn- extract-params [s offset] 451.1585 - (consume extract-param [s offset false])) 451.1586 - 451.1587 -(defn- translate-param 451.1588 - "Translate the string representation of a param to the internalized 451.1589 - representation" 451.1590 - [[^String p offset]] 451.1591 - [(cond 451.1592 - (= (.length p) 0) nil 451.1593 - (and (= (.length p) 1) (contains? #{\v \V} (nth p 0))) :parameter-from-args 451.1594 - (and (= (.length p) 1) (= \# (nth p 0))) :remaining-arg-count 451.1595 - (and (= (.length p) 2) (= \' (nth p 0))) (nth p 1) 451.1596 - true (new Integer p)) 451.1597 - offset]) 451.1598 - 451.1599 -(def ^{:private true} 451.1600 - flag-defs { \: :colon, \@ :at }) 451.1601 - 451.1602 -(defn- extract-flags [s offset] 451.1603 - (consume 451.1604 - (fn [[s offset flags]] 451.1605 - (if (empty? s) 451.1606 - [nil [s offset flags]] 451.1607 - (let [flag (get flag-defs (first s))] 451.1608 - (if flag 451.1609 - (if (contains? flags flag) 451.1610 - (format-error 451.1611 - (str "Flag \"" (first s) "\" appears more than once in a directive") 451.1612 - offset) 451.1613 - [true [(subs s 1) (inc offset) (assoc flags flag [true offset])]]) 451.1614 - [nil [s offset flags]])))) 451.1615 - [s offset {}])) 451.1616 - 451.1617 -(defn- check-flags [def flags] 451.1618 - (let [allowed (:flags def)] 451.1619 - (if (and (not (:at allowed)) (:at flags)) 451.1620 - (format-error (str "\"@\" is an illegal flag for format directive \"" (:directive def) "\"") 451.1621 - (nth (:at flags) 1))) 451.1622 - (if (and (not (:colon allowed)) (:colon flags)) 451.1623 - (format-error (str "\":\" is an illegal flag for format directive \"" (:directive def) "\"") 451.1624 - (nth (:colon flags) 1))) 451.1625 - (if (and (not (:both allowed)) (:at flags) (:colon flags)) 451.1626 - (format-error (str "Cannot combine \"@\" and \":\" flags for format directive \"" 451.1627 - (:directive def) "\"") 451.1628 - (min (nth (:colon flags) 1) (nth (:at flags) 1)))))) 451.1629 - 451.1630 -(defn- map-params 451.1631 - "Takes a directive definition and the list of actual parameters and 451.1632 -a map of flags and returns a map of the parameters and flags with defaults 451.1633 -filled in. We check to make sure that there are the right types and number 451.1634 -of parameters as well." 451.1635 - [def params flags offset] 451.1636 - (check-flags def flags) 451.1637 - (if (> (count params) (count (:params def))) 451.1638 - (format-error 451.1639 - (cl-format 451.1640 - nil 451.1641 - "Too many parameters for directive \"~C\": ~D~:* ~[were~;was~:;were~] specified but only ~D~:* ~[are~;is~:;are~] allowed" 451.1642 - (:directive def) (count params) (count (:params def))) 451.1643 - (second (first params)))) 451.1644 - (doall 451.1645 - (map #(let [val (first %1)] 451.1646 - (if (not (or (nil? val) (contains? special-params val) 451.1647 - (instance? (second (second %2)) val))) 451.1648 - (format-error (str "Parameter " (name (first %2)) 451.1649 - " has bad type in directive \"" (:directive def) "\": " 451.1650 - (class val)) 451.1651 - (second %1))) ) 451.1652 - params (:params def))) 451.1653 - 451.1654 - (merge ; create the result map 451.1655 - (into (array-map) ; start with the default values, make sure the order is right 451.1656 - (reverse (for [[name [default]] (:params def)] [name [default offset]]))) 451.1657 - (reduce #(apply assoc %1 %2) {} (filter #(first (nth % 1)) (zipmap (keys (:params def)) params))) ; add the specified parameters, filtering out nils 451.1658 - flags)) ; and finally add the flags 451.1659 - 451.1660 -(defn- compile-directive [s offset] 451.1661 - (let [[raw-params [rest offset]] (extract-params s offset) 451.1662 - [_ [rest offset flags]] (extract-flags rest offset) 451.1663 - directive (first rest) 451.1664 - def (get directive-table (Character/toUpperCase ^Character directive)) 451.1665 - params (if def (map-params def (map translate-param raw-params) flags offset))] 451.1666 - (if (not directive) 451.1667 - (format-error "Format string ended in the middle of a directive" offset)) 451.1668 - (if (not def) 451.1669 - (format-error (str "Directive \"" directive "\" is undefined") offset)) 451.1670 - [(struct compiled-directive ((:generator-fn def) params offset) def params offset) 451.1671 - (let [remainder (subs rest 1) 451.1672 - offset (inc offset) 451.1673 - trim? (and (= \newline (:directive def)) 451.1674 - (not (:colon params))) 451.1675 - trim-count (if trim? (prefix-count remainder [\space \tab]) 0) 451.1676 - remainder (subs remainder trim-count) 451.1677 - offset (+ offset trim-count)] 451.1678 - [remainder offset])])) 451.1679 - 451.1680 -(defn- compile-raw-string [s offset] 451.1681 - (struct compiled-directive (fn [_ a _] (print s) a) nil { :string s } offset)) 451.1682 - 451.1683 -(defn- right-bracket [this] (:right (:bracket-info (:def this)))) 451.1684 -(defn- separator? [this] (:separator (:bracket-info (:def this)))) 451.1685 -(defn- else-separator? [this] 451.1686 - (and (:separator (:bracket-info (:def this))) 451.1687 - (:colon (:params this)))) 451.1688 - 451.1689 - 451.1690 -(declare collect-clauses) 451.1691 - 451.1692 -(defn- process-bracket [this remainder] 451.1693 - (let [[subex remainder] (collect-clauses (:bracket-info (:def this)) 451.1694 - (:offset this) remainder)] 451.1695 - [(struct compiled-directive 451.1696 - (:func this) (:def this) 451.1697 - (merge (:params this) (tuple-map subex (:offset this))) 451.1698 - (:offset this)) 451.1699 - remainder])) 451.1700 - 451.1701 -(defn- process-clause [bracket-info offset remainder] 451.1702 - (consume 451.1703 - (fn [remainder] 451.1704 - (if (empty? remainder) 451.1705 - (format-error "No closing bracket found." offset) 451.1706 - (let [this (first remainder) 451.1707 - remainder (next remainder)] 451.1708 - (cond 451.1709 - (right-bracket this) 451.1710 - (process-bracket this remainder) 451.1711 - 451.1712 - (= (:right bracket-info) (:directive (:def this))) 451.1713 - [ nil [:right-bracket (:params this) nil remainder]] 451.1714 - 451.1715 - (else-separator? this) 451.1716 - [nil [:else nil (:params this) remainder]] 451.1717 - 451.1718 - (separator? this) 451.1719 - [nil [:separator nil nil remainder]] ;; TODO: check to make sure that there are no params on ~; 451.1720 - 451.1721 - true 451.1722 - [this remainder])))) 451.1723 - remainder)) 451.1724 - 451.1725 -(defn- collect-clauses [bracket-info offset remainder] 451.1726 - (second 451.1727 - (consume 451.1728 - (fn [[clause-map saw-else remainder]] 451.1729 - (let [[clause [type right-params else-params remainder]] 451.1730 - (process-clause bracket-info offset remainder)] 451.1731 - (cond 451.1732 - (= type :right-bracket) 451.1733 - [nil [(merge-with concat clause-map 451.1734 - {(if saw-else :else :clauses) [clause] 451.1735 - :right-params right-params}) 451.1736 - remainder]] 451.1737 - 451.1738 - (= type :else) 451.1739 - (cond 451.1740 - (:else clause-map) 451.1741 - (format-error "Two else clauses (\"~:;\") inside bracket construction." offset) 451.1742 - 451.1743 - (not (:else bracket-info)) 451.1744 - (format-error "An else clause (\"~:;\") is in a bracket type that doesn't support it." 451.1745 - offset) 451.1746 - 451.1747 - (and (= :first (:else bracket-info)) (seq (:clauses clause-map))) 451.1748 - (format-error 451.1749 - "The else clause (\"~:;\") is only allowed in the first position for this directive." 451.1750 - offset) 451.1751 - 451.1752 - true ; if the ~:; is in the last position, the else clause 451.1753 - ; is next, this was a regular clause 451.1754 - (if (= :first (:else bracket-info)) 451.1755 - [true [(merge-with concat clause-map { :else [clause] :else-params else-params}) 451.1756 - false remainder]] 451.1757 - [true [(merge-with concat clause-map { :clauses [clause] }) 451.1758 - true remainder]])) 451.1759 - 451.1760 - (= type :separator) 451.1761 - (cond 451.1762 - saw-else 451.1763 - (format-error "A plain clause (with \"~;\") follows an else clause (\"~:;\") inside bracket construction." offset) 451.1764 - 451.1765 - (not (:allows-separator bracket-info)) 451.1766 - (format-error "A separator (\"~;\") is in a bracket type that doesn't support it." 451.1767 - offset) 451.1768 - 451.1769 - true 451.1770 - [true [(merge-with concat clause-map { :clauses [clause] }) 451.1771 - false remainder]])))) 451.1772 - [{ :clauses [] } false remainder]))) 451.1773 - 451.1774 -(defn- process-nesting 451.1775 - "Take a linearly compiled format and process the bracket directives to give it 451.1776 - the appropriate tree structure" 451.1777 - [format] 451.1778 - (first 451.1779 - (consume 451.1780 - (fn [remainder] 451.1781 - (let [this (first remainder) 451.1782 - remainder (next remainder) 451.1783 - bracket (:bracket-info (:def this))] 451.1784 - (if (:right bracket) 451.1785 - (process-bracket this remainder) 451.1786 - [this remainder]))) 451.1787 - format))) 451.1788 - 451.1789 -(defn- compile-format 451.1790 - "Compiles format-str into a compiled format which can be used as an argument 451.1791 -to cl-format just like a plain format string. Use this function for improved 451.1792 -performance when you're using the same format string repeatedly" 451.1793 - [ format-str ] 451.1794 -; (prlabel compiling format-str) 451.1795 - (binding [*format-str* format-str] 451.1796 - (process-nesting 451.1797 - (first 451.1798 - (consume 451.1799 - (fn [[^String s offset]] 451.1800 - (if (empty? s) 451.1801 - [nil s] 451.1802 - (let [tilde (.indexOf s (int \~))] 451.1803 - (cond 451.1804 - (neg? tilde) [(compile-raw-string s offset) ["" (+ offset (.length s))]] 451.1805 - (zero? tilde) (compile-directive (subs s 1) (inc offset)) 451.1806 - true 451.1807 - [(compile-raw-string (subs s 0 tilde) offset) [(subs s tilde) (+ tilde offset)]])))) 451.1808 - [format-str 0]))))) 451.1809 - 451.1810 -(defn- needs-pretty 451.1811 - "determine whether a given compiled format has any directives that depend on the 451.1812 -column number or pretty printing" 451.1813 - [format] 451.1814 - (loop [format format] 451.1815 - (if (empty? format) 451.1816 - false 451.1817 - (if (or (:pretty (:flags (:def (first format)))) 451.1818 - (some needs-pretty (first (:clauses (:params (first format))))) 451.1819 - (some needs-pretty (first (:else (:params (first format)))))) 451.1820 - true 451.1821 - (recur (next format)))))) 451.1822 - 451.1823 -(defn- execute-format 451.1824 - "Executes the format with the arguments." 451.1825 - {:skip-wiki true} 451.1826 - ([stream format args] 451.1827 - (let [^java.io.Writer real-stream (cond 451.1828 - (not stream) (java.io.StringWriter.) 451.1829 - (true? stream) *out* 451.1830 - :else stream) 451.1831 - ^java.io.Writer wrapped-stream (if (and (needs-pretty format) 451.1832 - (not (pretty-writer? real-stream))) 451.1833 - (get-pretty-writer real-stream) 451.1834 - real-stream)] 451.1835 - (binding [*out* wrapped-stream] 451.1836 - (try 451.1837 - (execute-format format args) 451.1838 - (finally 451.1839 - (if-not (identical? real-stream wrapped-stream) 451.1840 - (.flush wrapped-stream)))) 451.1841 - (if (not stream) (.toString real-stream))))) 451.1842 - ([format args] 451.1843 - (map-passing-context 451.1844 - (fn [element context] 451.1845 - (if (abort? context) 451.1846 - [nil context] 451.1847 - (let [[params args] (realize-parameter-list 451.1848 - (:params element) context) 451.1849 - [params offsets] (unzip-map params) 451.1850 - params (assoc params :base-args args)] 451.1851 - [nil (apply (:func element) [params args offsets])]))) 451.1852 - args 451.1853 - format) 451.1854 - nil)) 451.1855 - 451.1856 -;;; This is a bad idea, but it prevents us from leaking private symbols 451.1857 -;;; This should all be replaced by really compiled formats anyway. 451.1858 -(def ^{:private true} cached-compile (memoize compile-format)) 451.1859 - 451.1860 -(defmacro formatter 451.1861 - "Makes a function which can directly run format-in. The function is 451.1862 -fn [stream & args] ... and returns nil unless the stream is nil (meaning 451.1863 -output to a string) in which case it returns the resulting string. 451.1864 - 451.1865 -format-in can be either a control string or a previously compiled format." 451.1866 - {:added "1.2"} 451.1867 - [format-in] 451.1868 - `(let [format-in# ~format-in 451.1869 - my-c-c# (var-get (get (ns-interns (the-ns 'clojure.pprint)) 451.1870 - '~'cached-compile)) 451.1871 - my-e-f# (var-get (get (ns-interns (the-ns 'clojure.pprint)) 451.1872 - '~'execute-format)) 451.1873 - my-i-n# (var-get (get (ns-interns (the-ns 'clojure.pprint)) 451.1874 - '~'init-navigator)) 451.1875 - cf# (if (string? format-in#) (my-c-c# format-in#) format-in#)] 451.1876 - (fn [stream# & args#] 451.1877 - (let [navigator# (my-i-n# args#)] 451.1878 - (my-e-f# stream# cf# navigator#))))) 451.1879 - 451.1880 -(defmacro formatter-out 451.1881 - "Makes a function which can directly run format-in. The function is 451.1882 -fn [& args] ... and returns nil. This version of the formatter macro is 451.1883 -designed to be used with *out* set to an appropriate Writer. In particular, 451.1884 -this is meant to be used as part of a pretty printer dispatch method. 451.1885 - 451.1886 -format-in can be either a control string or a previously compiled format." 451.1887 - {:added "1.2"} 451.1888 - [format-in] 451.1889 - `(let [format-in# ~format-in 451.1890 - cf# (if (string? format-in#) (#'clojure.pprint/cached-compile format-in#) format-in#)] 451.1891 - (fn [& args#] 451.1892 - (let [navigator# (#'clojure.pprint/init-navigator args#)] 451.1893 - (#'clojure.pprint/execute-format cf# navigator#)))))
452.1 --- a/src/clojure/pprint/column_writer.clj Sat Aug 21 06:25:44 2010 -0400 452.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 452.3 @@ -1,79 +0,0 @@ 452.4 -;;; column_writer.clj -- part of the pretty printer for Clojure 452.5 - 452.6 - 452.7 -; Copyright (c) Rich Hickey. All rights reserved. 452.8 -; The use and distribution terms for this software are covered by the 452.9 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 452.10 -; which can be found in the file epl-v10.html at the root of this distribution. 452.11 -; By using this software in any fashion, you are agreeing to be bound by 452.12 -; the terms of this license. 452.13 -; You must not remove this notice, or any other, from this software. 452.14 - 452.15 -;; Author: Tom Faulhaber 452.16 -;; April 3, 2009 452.17 -;; Revised to use proxy instead of gen-class April 2010 452.18 - 452.19 -;; This module implements a column-aware wrapper around an instance of java.io.Writer 452.20 - 452.21 -(in-ns 'clojure.pprint) 452.22 - 452.23 -(import [clojure.lang IDeref] 452.24 - [java.io Writer]) 452.25 - 452.26 -(def ^{:private true} *default-page-width* 72) 452.27 - 452.28 -(defn- get-field [^Writer this sym] 452.29 - (sym @@this)) 452.30 - 452.31 -(defn- set-field [^Writer this sym new-val] 452.32 - (alter @this assoc sym new-val)) 452.33 - 452.34 -(defn- get-column [this] 452.35 - (get-field this :cur)) 452.36 - 452.37 -(defn- get-line [this] 452.38 - (get-field this :line)) 452.39 - 452.40 -(defn- get-max-column [this] 452.41 - (get-field this :max)) 452.42 - 452.43 -(defn- set-max-column [this new-max] 452.44 - (dosync (set-field this :max new-max)) 452.45 - nil) 452.46 - 452.47 -(defn- get-writer [this] 452.48 - (get-field this :base)) 452.49 - 452.50 -(defn- c-write-char [^Writer this ^Integer c] 452.51 - (dosync (if (= c (int \newline)) 452.52 - (do 452.53 - (set-field this :cur 0) 452.54 - (set-field this :line (inc (get-field this :line)))) 452.55 - (set-field this :cur (inc (get-field this :cur))))) 452.56 - (.write ^Writer (get-field this :base) c)) 452.57 - 452.58 -(defn- column-writer 452.59 - ([writer] (column-writer writer *default-page-width*)) 452.60 - ([writer max-columns] 452.61 - (let [fields (ref {:max max-columns, :cur 0, :line 0 :base writer})] 452.62 - (proxy [Writer IDeref] [] 452.63 - (deref [] fields) 452.64 - (write 452.65 - ([^chars cbuf ^Integer off ^Integer len] 452.66 - (let [^Writer writer (get-field this :base)] 452.67 - (.write writer cbuf off len))) 452.68 - ([x] 452.69 - (condp = (class x) 452.70 - String 452.71 - (let [^String s x 452.72 - nl (.lastIndexOf s (int \newline))] 452.73 - (dosync (if (neg? nl) 452.74 - (set-field this :cur (+ (get-field this :cur) (count s))) 452.75 - (do 452.76 - (set-field this :cur (- (count s) nl 1)) 452.77 - (set-field this :line (+ (get-field this :line) 452.78 - (count (filter #(= % \newline) s))))))) 452.79 - (.write ^Writer (get-field this :base) s)) 452.80 - 452.81 - Integer 452.82 - (c-write-char this x))))))))
453.1 --- a/src/clojure/pprint/dispatch.clj Sat Aug 21 06:25:44 2010 -0400 453.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 453.3 @@ -1,467 +0,0 @@ 453.4 -;; dispatch.clj -- part of the pretty printer for Clojure 453.5 - 453.6 -; Copyright (c) Rich Hickey. All rights reserved. 453.7 -; The use and distribution terms for this software are covered by the 453.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 453.9 -; which can be found in the file epl-v10.html at the root of this distribution. 453.10 -; By using this software in any fashion, you are agreeing to be bound by 453.11 -; the terms of this license. 453.12 -; You must not remove this notice, or any other, from this software. 453.13 - 453.14 -;; Author: Tom Faulhaber 453.15 -;; April 3, 2009 453.16 - 453.17 - 453.18 -;; This module implements the default dispatch tables for pretty printing code and 453.19 -;; data. 453.20 - 453.21 -(in-ns 'clojure.pprint) 453.22 - 453.23 -(defn- use-method 453.24 - "Installs a function as a new method of multimethod associated with dispatch-value. " 453.25 - [multifn dispatch-val func] 453.26 - (. multifn addMethod dispatch-val func)) 453.27 - 453.28 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.29 -;; Implementations of specific dispatch table entries 453.30 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.31 - 453.32 -;;; Handle forms that can be "back-translated" to reader macros 453.33 -;;; Not all reader macros can be dealt with this way or at all. 453.34 -;;; Macros that we can't deal with at all are: 453.35 -;;; ; - The comment character is aborbed by the reader and never is part of the form 453.36 -;;; ` - Is fully processed at read time into a lisp expression (which will contain concats 453.37 -;;; and regular quotes). 453.38 -;;; ~@ - Also fully eaten by the processing of ` and can't be used outside. 453.39 -;;; , - is whitespace and is lost (like all other whitespace). Formats can generate commas 453.40 -;;; where they deem them useful to help readability. 453.41 -;;; ^ - Adding metadata completely disappears at read time and the data appears to be 453.42 -;;; completely lost. 453.43 -;;; 453.44 -;;; Most other syntax stuff is dealt with directly by the formats (like (), [], {}, and #{}) 453.45 -;;; or directly by printing the objects using Clojure's built-in print functions (like 453.46 -;;; :keyword, \char, or ""). The notable exception is #() which is special-cased. 453.47 - 453.48 -(def ^{:private true} reader-macros 453.49 - {'quote "'", 'clojure.core/deref "@", 453.50 - 'var "#'", 'clojure.core/unquote "~"}) 453.51 - 453.52 -(defn- pprint-reader-macro [alis] 453.53 - (let [^String macro-char (reader-macros (first alis))] 453.54 - (when (and macro-char (= 2 (count alis))) 453.55 - (.write ^java.io.Writer *out* macro-char) 453.56 - (write-out (second alis)) 453.57 - true))) 453.58 - 453.59 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.60 -;; Dispatch for the basic data types when interpreted 453.61 -;; as data (as opposed to code). 453.62 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.63 - 453.64 -;;; TODO: inline these formatter statements into funcs so that we 453.65 -;;; are a little easier on the stack. (Or, do "real" compilation, a 453.66 -;;; la Common Lisp) 453.67 - 453.68 -;;; (def pprint-simple-list (formatter-out "~:<~@{~w~^ ~_~}~:>")) 453.69 -(defn- pprint-simple-list [alis] 453.70 - (pprint-logical-block :prefix "(" :suffix ")" 453.71 - (loop [alis (seq alis)] 453.72 - (when alis 453.73 - (write-out (first alis)) 453.74 - (when (next alis) 453.75 - (.write ^java.io.Writer *out* " ") 453.76 - (pprint-newline :linear) 453.77 - (recur (next alis))))))) 453.78 - 453.79 -(defn- pprint-list [alis] 453.80 - (if-not (pprint-reader-macro alis) 453.81 - (pprint-simple-list alis))) 453.82 - 453.83 -;;; (def pprint-vector (formatter-out "~<[~;~@{~w~^ ~_~}~;]~:>")) 453.84 -(defn- pprint-vector [avec] 453.85 - (pprint-logical-block :prefix "[" :suffix "]" 453.86 - (loop [aseq (seq avec)] 453.87 - (when aseq 453.88 - (write-out (first aseq)) 453.89 - (when (next aseq) 453.90 - (.write ^java.io.Writer *out* " ") 453.91 - (pprint-newline :linear) 453.92 - (recur (next aseq))))))) 453.93 - 453.94 -(def ^{:private true} pprint-array (formatter-out "~<[~;~@{~w~^, ~:_~}~;]~:>")) 453.95 - 453.96 -;;; (def pprint-map (formatter-out "~<{~;~@{~<~w~^ ~_~w~:>~^, ~_~}~;}~:>")) 453.97 -(defn- pprint-map [amap] 453.98 - (pprint-logical-block :prefix "{" :suffix "}" 453.99 - (loop [aseq (seq amap)] 453.100 - (when aseq 453.101 - (pprint-logical-block 453.102 - (write-out (ffirst aseq)) 453.103 - (.write ^java.io.Writer *out* " ") 453.104 - (pprint-newline :linear) 453.105 - (write-out (fnext (first aseq)))) 453.106 - (when (next aseq) 453.107 - (.write ^java.io.Writer *out* ", ") 453.108 - (pprint-newline :linear) 453.109 - (recur (next aseq))))))) 453.110 - 453.111 -(def ^{:private true} pprint-set (formatter-out "~<#{~;~@{~w~^ ~:_~}~;}~:>")) 453.112 - 453.113 -;;; TODO: don't block on promise (currently impossible) 453.114 - 453.115 -(def ^{:private true} 453.116 - type-map {"core$future_call" "Future", 453.117 - "core$promise" "Promise"}) 453.118 - 453.119 -(defn- map-ref-type 453.120 - "Map ugly type names to something simpler" 453.121 - [name] 453.122 - (or (when-let [match (re-find #"^[^$]+\$[^$]+" name)] 453.123 - (type-map match)) 453.124 - name)) 453.125 - 453.126 -(defn- pprint-ideref [o] 453.127 - (let [prefix (format "#<%s@%x%s: " 453.128 - (map-ref-type (.getSimpleName (class o))) 453.129 - (System/identityHashCode o) 453.130 - (if (and (instance? clojure.lang.Agent o) 453.131 - (agent-error o)) 453.132 - " FAILED" 453.133 - ""))] 453.134 - (pprint-logical-block :prefix prefix :suffix ">" 453.135 - (pprint-indent :block (-> (count prefix) (- 2) -)) 453.136 - (pprint-newline :linear) 453.137 - (write-out (cond 453.138 - (and (future? o) (not (future-done? o))) :pending 453.139 - :else @o))))) 453.140 - 453.141 -(def ^{:private true} pprint-pqueue (formatter-out "~<<-(~;~@{~w~^ ~_~}~;)-<~:>")) 453.142 - 453.143 -(defn- pprint-simple-default [obj] 453.144 - (cond 453.145 - (.isArray (class obj)) (pprint-array obj) 453.146 - (and *print-suppress-namespaces* (symbol? obj)) (print (name obj)) 453.147 - :else (pr obj))) 453.148 - 453.149 - 453.150 -(defmulti 453.151 - simple-dispatch 453.152 - "The pretty print dispatch function for simple data structure format." 453.153 - {:added "1.2" :arglists '[[object]]} 453.154 - class) 453.155 - 453.156 -(use-method simple-dispatch clojure.lang.ISeq pprint-list) 453.157 -(use-method simple-dispatch clojure.lang.IPersistentVector pprint-vector) 453.158 -(use-method simple-dispatch clojure.lang.IPersistentMap pprint-map) 453.159 -(use-method simple-dispatch clojure.lang.IPersistentSet pprint-set) 453.160 -(use-method simple-dispatch clojure.lang.PersistentQueue pprint-pqueue) 453.161 -(use-method simple-dispatch clojure.lang.IDeref pprint-ideref) 453.162 -(use-method simple-dispatch nil pr) 453.163 -(use-method simple-dispatch :default pprint-simple-default) 453.164 - 453.165 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.166 -;;; Dispatch for the code table 453.167 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.168 - 453.169 -(declare pprint-simple-code-list) 453.170 - 453.171 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.172 -;;; Format something that looks like a simple def (sans metadata, since the reader 453.173 -;;; won't give it to us now). 453.174 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.175 - 453.176 -(def ^{:private true} pprint-hold-first (formatter-out "~:<~w~^ ~@_~w~^ ~_~@{~w~^ ~_~}~:>")) 453.177 - 453.178 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.179 -;;; Format something that looks like a defn or defmacro 453.180 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.181 - 453.182 -;;; Format the params and body of a defn with a single arity 453.183 -(defn- single-defn [alis has-doc-str?] 453.184 - (if (seq alis) 453.185 - (do 453.186 - (if has-doc-str? 453.187 - ((formatter-out " ~_")) 453.188 - ((formatter-out " ~@_"))) 453.189 - ((formatter-out "~{~w~^ ~_~}") alis)))) 453.190 - 453.191 -;;; Format the param and body sublists of a defn with multiple arities 453.192 -(defn- multi-defn [alis has-doc-str?] 453.193 - (if (seq alis) 453.194 - ((formatter-out " ~_~{~w~^ ~_~}") alis))) 453.195 - 453.196 -;;; TODO: figure out how to support capturing metadata in defns (we might need a 453.197 -;;; special reader) 453.198 -(defn- pprint-defn [alis] 453.199 - (if (next alis) 453.200 - (let [[defn-sym defn-name & stuff] alis 453.201 - [doc-str stuff] (if (string? (first stuff)) 453.202 - [(first stuff) (next stuff)] 453.203 - [nil stuff]) 453.204 - [attr-map stuff] (if (map? (first stuff)) 453.205 - [(first stuff) (next stuff)] 453.206 - [nil stuff])] 453.207 - (pprint-logical-block :prefix "(" :suffix ")" 453.208 - ((formatter-out "~w ~1I~@_~w") defn-sym defn-name) 453.209 - (if doc-str 453.210 - ((formatter-out " ~_~w") doc-str)) 453.211 - (if attr-map 453.212 - ((formatter-out " ~_~w") attr-map)) 453.213 - ;; Note: the multi-defn case will work OK for malformed defns too 453.214 - (cond 453.215 - (vector? (first stuff)) (single-defn stuff (or doc-str attr-map)) 453.216 - :else (multi-defn stuff (or doc-str attr-map))))) 453.217 - (pprint-simple-code-list alis))) 453.218 - 453.219 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.220 -;;; Format something with a binding form 453.221 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.222 - 453.223 -(defn- pprint-binding-form [binding-vec] 453.224 - (pprint-logical-block :prefix "[" :suffix "]" 453.225 - (loop [binding binding-vec] 453.226 - (when (seq binding) 453.227 - (pprint-logical-block binding 453.228 - (write-out (first binding)) 453.229 - (when (next binding) 453.230 - (.write ^java.io.Writer *out* " ") 453.231 - (pprint-newline :miser) 453.232 - (write-out (second binding)))) 453.233 - (when (next (rest binding)) 453.234 - (.write ^java.io.Writer *out* " ") 453.235 - (pprint-newline :linear) 453.236 - (recur (next (rest binding)))))))) 453.237 - 453.238 -(defn- pprint-let [alis] 453.239 - (let [base-sym (first alis)] 453.240 - (pprint-logical-block :prefix "(" :suffix ")" 453.241 - (if (and (next alis) (vector? (second alis))) 453.242 - (do 453.243 - ((formatter-out "~w ~1I~@_") base-sym) 453.244 - (pprint-binding-form (second alis)) 453.245 - ((formatter-out " ~_~{~w~^ ~_~}") (next (rest alis)))) 453.246 - (pprint-simple-code-list alis))))) 453.247 - 453.248 - 453.249 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.250 -;;; Format something that looks like "if" 453.251 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.252 - 453.253 -(def ^{:private true} pprint-if (formatter-out "~:<~1I~w~^ ~@_~w~@{ ~_~w~}~:>")) 453.254 - 453.255 -(defn- pprint-cond [alis] 453.256 - (pprint-logical-block :prefix "(" :suffix ")" 453.257 - (pprint-indent :block 1) 453.258 - (write-out (first alis)) 453.259 - (when (next alis) 453.260 - (.write ^java.io.Writer *out* " ") 453.261 - (pprint-newline :linear) 453.262 - (loop [alis (next alis)] 453.263 - (when alis 453.264 - (pprint-logical-block alis 453.265 - (write-out (first alis)) 453.266 - (when (next alis) 453.267 - (.write ^java.io.Writer *out* " ") 453.268 - (pprint-newline :miser) 453.269 - (write-out (second alis)))) 453.270 - (when (next (rest alis)) 453.271 - (.write ^java.io.Writer *out* " ") 453.272 - (pprint-newline :linear) 453.273 - (recur (next (rest alis))))))))) 453.274 - 453.275 -(defn- pprint-condp [alis] 453.276 - (if (> (count alis) 3) 453.277 - (pprint-logical-block :prefix "(" :suffix ")" 453.278 - (pprint-indent :block 1) 453.279 - (apply (formatter-out "~w ~@_~w ~@_~w ~_") alis) 453.280 - (loop [alis (seq (drop 3 alis))] 453.281 - (when alis 453.282 - (pprint-logical-block alis 453.283 - (write-out (first alis)) 453.284 - (when (next alis) 453.285 - (.write ^java.io.Writer *out* " ") 453.286 - (pprint-newline :miser) 453.287 - (write-out (second alis)))) 453.288 - (when (next (rest alis)) 453.289 - (.write ^java.io.Writer *out* " ") 453.290 - (pprint-newline :linear) 453.291 - (recur (next (rest alis))))))) 453.292 - (pprint-simple-code-list alis))) 453.293 - 453.294 -;;; The map of symbols that are defined in an enclosing #() anonymous function 453.295 -(def ^{:private true} *symbol-map* {}) 453.296 - 453.297 -(defn- pprint-anon-func [alis] 453.298 - (let [args (second alis) 453.299 - nlis (first (rest (rest alis)))] 453.300 - (if (vector? args) 453.301 - (binding [*symbol-map* (if (= 1 (count args)) 453.302 - {(first args) "%"} 453.303 - (into {} 453.304 - (map 453.305 - #(vector %1 (str \% %2)) 453.306 - args 453.307 - (range 1 (inc (count args))))))] 453.308 - ((formatter-out "~<#(~;~@{~w~^ ~_~}~;)~:>") nlis)) 453.309 - (pprint-simple-code-list alis)))) 453.310 - 453.311 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.312 -;;; The master definitions for formatting lists in code (that is, (fn args...) or 453.313 -;;; special forms). 453.314 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 453.315 - 453.316 -;;; This is the equivalent of (formatter-out "~:<~1I~@{~w~^ ~_~}~:>"), but is 453.317 -;;; easier on the stack. 453.318 - 453.319 -(defn- pprint-simple-code-list [alis] 453.320 - (pprint-logical-block :prefix "(" :suffix ")" 453.321 - (pprint-indent :block 1) 453.322 - (loop [alis (seq alis)] 453.323 - (when alis 453.324 - (write-out (first alis)) 453.325 - (when (next alis) 453.326 - (.write ^java.io.Writer *out* " ") 453.327 - (pprint-newline :linear) 453.328 - (recur (next alis))))))) 453.329 - 453.330 -;;; Take a map with symbols as keys and add versions with no namespace. 453.331 -;;; That is, if ns/sym->val is in the map, add sym->val to the result. 453.332 -(defn- two-forms [amap] 453.333 - (into {} 453.334 - (mapcat 453.335 - identity 453.336 - (for [x amap] 453.337 - [x [(symbol (name (first x))) (second x)]])))) 453.338 - 453.339 -(defn- add-core-ns [amap] 453.340 - (let [core "clojure.core"] 453.341 - (into {} 453.342 - (map #(let [[s f] %] 453.343 - (if (not (or (namespace s) (special-symbol? s))) 453.344 - [(symbol core (name s)) f] 453.345 - %)) 453.346 - amap)))) 453.347 - 453.348 -(def ^{:private true} *code-table* 453.349 - (two-forms 453.350 - (add-core-ns 453.351 - {'def pprint-hold-first, 'defonce pprint-hold-first, 453.352 - 'defn pprint-defn, 'defn- pprint-defn, 'defmacro pprint-defn, 'fn pprint-defn, 453.353 - 'let pprint-let, 'loop pprint-let, 'binding pprint-let, 453.354 - 'with-local-vars pprint-let, 'with-open pprint-let, 'when-let pprint-let, 453.355 - 'if-let pprint-let, 'doseq pprint-let, 'dotimes pprint-let, 453.356 - 'when-first pprint-let, 453.357 - 'if pprint-if, 'if-not pprint-if, 'when pprint-if, 'when-not pprint-if, 453.358 - 'cond pprint-cond, 'condp pprint-condp, 453.359 - 'fn* pprint-anon-func, 453.360 - '. pprint-hold-first, '.. pprint-hold-first, '-> pprint-hold-first, 453.361 - 'locking pprint-hold-first, 'struct pprint-hold-first, 453.362 - 'struct-map pprint-hold-first, 453.363 - }))) 453.364 - 453.365 -(defn- pprint-code-list [alis] 453.366 - (if-not (pprint-reader-macro alis) 453.367 - (if-let [special-form (*code-table* (first alis))] 453.368 - (special-form alis) 453.369 - (pprint-simple-code-list alis)))) 453.370 - 453.371 -(defn- pprint-code-symbol [sym] 453.372 - (if-let [arg-num (sym *symbol-map*)] 453.373 - (print arg-num) 453.374 - (if *print-suppress-namespaces* 453.375 - (print (name sym)) 453.376 - (pr sym)))) 453.377 - 453.378 -(defmulti 453.379 - code-dispatch 453.380 - "The pretty print dispatch function for pretty printing Clojure code." 453.381 - {:added "1.2" :arglists '[[object]]} 453.382 - class) 453.383 - 453.384 -(use-method code-dispatch clojure.lang.ISeq pprint-code-list) 453.385 -(use-method code-dispatch clojure.lang.Symbol pprint-code-symbol) 453.386 - 453.387 -;; The following are all exact copies of simple-dispatch 453.388 -(use-method code-dispatch clojure.lang.IPersistentVector pprint-vector) 453.389 -(use-method code-dispatch clojure.lang.IPersistentMap pprint-map) 453.390 -(use-method code-dispatch clojure.lang.IPersistentSet pprint-set) 453.391 -(use-method code-dispatch clojure.lang.PersistentQueue pprint-pqueue) 453.392 -(use-method code-dispatch clojure.lang.IDeref pprint-ideref) 453.393 -(use-method code-dispatch nil pr) 453.394 -(use-method code-dispatch :default pprint-simple-default) 453.395 - 453.396 -(set-pprint-dispatch simple-dispatch) 453.397 - 453.398 - 453.399 -;;; For testing 453.400 -(comment 453.401 - 453.402 -(with-pprint-dispatch code-dispatch 453.403 - (pprint 453.404 - '(defn cl-format 453.405 - "An implementation of a Common Lisp compatible format function" 453.406 - [stream format-in & args] 453.407 - (let [compiled-format (if (string? format-in) (compile-format format-in) format-in) 453.408 - navigator (init-navigator args)] 453.409 - (execute-format stream compiled-format navigator))))) 453.410 - 453.411 -(with-pprint-dispatch code-dispatch 453.412 - (pprint 453.413 - '(defn cl-format 453.414 - [stream format-in & args] 453.415 - (let [compiled-format (if (string? format-in) (compile-format format-in) format-in) 453.416 - navigator (init-navigator args)] 453.417 - (execute-format stream compiled-format navigator))))) 453.418 - 453.419 -(with-pprint-dispatch code-dispatch 453.420 - (pprint 453.421 - '(defn- -write 453.422 - ([this x] 453.423 - (condp = (class x) 453.424 - String 453.425 - (let [s0 (write-initial-lines this x) 453.426 - s (.replaceFirst s0 "\\s+$" "") 453.427 - white-space (.substring s0 (count s)) 453.428 - mode (getf :mode)] 453.429 - (if (= mode :writing) 453.430 - (dosync 453.431 - (write-white-space this) 453.432 - (.col_write this s) 453.433 - (setf :trailing-white-space white-space)) 453.434 - (add-to-buffer this (make-buffer-blob s white-space)))) 453.435 - 453.436 - Integer 453.437 - (let [c ^Character x] 453.438 - (if (= (getf :mode) :writing) 453.439 - (do 453.440 - (write-white-space this) 453.441 - (.col_write this x)) 453.442 - (if (= c (int \newline)) 453.443 - (write-initial-lines this "\n") 453.444 - (add-to-buffer this (make-buffer-blob (str (char c)) nil)))))))))) 453.445 - 453.446 -(with-pprint-dispatch code-dispatch 453.447 - (pprint 453.448 - '(defn pprint-defn [writer alis] 453.449 - (if (next alis) 453.450 - (let [[defn-sym defn-name & stuff] alis 453.451 - [doc-str stuff] (if (string? (first stuff)) 453.452 - [(first stuff) (next stuff)] 453.453 - [nil stuff]) 453.454 - [attr-map stuff] (if (map? (first stuff)) 453.455 - [(first stuff) (next stuff)] 453.456 - [nil stuff])] 453.457 - (pprint-logical-block writer :prefix "(" :suffix ")" 453.458 - (cl-format true "~w ~1I~@_~w" defn-sym defn-name) 453.459 - (if doc-str 453.460 - (cl-format true " ~_~w" doc-str)) 453.461 - (if attr-map 453.462 - (cl-format true " ~_~w" attr-map)) 453.463 - ;; Note: the multi-defn case will work OK for malformed defns too 453.464 - (cond 453.465 - (vector? (first stuff)) (single-defn stuff (or doc-str attr-map)) 453.466 - :else (multi-defn stuff (or doc-str attr-map))))) 453.467 - (pprint-simple-code-list writer alis))))) 453.468 -) 453.469 -nil 453.470 -
454.1 --- a/src/clojure/pprint/pprint_base.clj Sat Aug 21 06:25:44 2010 -0400 454.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 454.3 @@ -1,374 +0,0 @@ 454.4 -;;; pprint_base.clj -- part of the pretty printer for Clojure 454.5 - 454.6 -; Copyright (c) Rich Hickey. All rights reserved. 454.7 -; The use and distribution terms for this software are covered by the 454.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 454.9 -; which can be found in the file epl-v10.html at the root of this distribution. 454.10 -; By using this software in any fashion, you are agreeing to be bound by 454.11 -; the terms of this license. 454.12 -; You must not remove this notice, or any other, from this software. 454.13 - 454.14 -;; Author: Tom Faulhaber 454.15 -;; April 3, 2009 454.16 - 454.17 - 454.18 -;; This module implements the generic pretty print functions and special variables 454.19 - 454.20 -(in-ns 'clojure.pprint) 454.21 - 454.22 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 454.23 -;; Variables that control the pretty printer 454.24 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 454.25 - 454.26 -;;; 454.27 -;;; *print-length*, *print-level* and *print-dup* are defined in clojure.core 454.28 -;;; TODO: use *print-dup* here (or is it supplanted by other variables?) 454.29 -;;; TODO: make dispatch items like "(let..." get counted in *print-length* 454.30 -;;; constructs 454.31 - 454.32 - 454.33 -(def 454.34 - ^{:doc "Bind to true if you want write to use pretty printing", :added "1.2"} 454.35 - *print-pretty* true) 454.36 - 454.37 -(defonce ; If folks have added stuff here, don't overwrite 454.38 - ^{:doc "The pretty print dispatch function. Use with-pprint-dispatch or set-pprint-dispatch 454.39 -to modify.", 454.40 - :added "1.2"} 454.41 - *print-pprint-dispatch* nil) 454.42 - 454.43 -(def 454.44 - ^{:doc "Pretty printing will try to avoid anything going beyond this column. 454.45 -Set it to nil to have pprint let the line be arbitrarily long. This will ignore all 454.46 -non-mandatory newlines.", 454.47 - :added "1.2"} 454.48 - *print-right-margin* 72) 454.49 - 454.50 -(def 454.51 - ^{:doc "The column at which to enter miser style. Depending on the dispatch table, 454.52 -miser style add newlines in more places to try to keep lines short allowing for further 454.53 -levels of nesting.", 454.54 - :added "1.2"} 454.55 - *print-miser-width* 40) 454.56 - 454.57 -;;; TODO implement output limiting 454.58 -(def 454.59 - ^{:private true, 454.60 - :doc "Maximum number of lines to print in a pretty print instance (N.B. This is not yet used)"} 454.61 - *print-lines* nil) 454.62 - 454.63 -;;; TODO: implement circle and shared 454.64 -(def 454.65 - ^{:private true, 454.66 - :doc "Mark circular structures (N.B. This is not yet used)"} 454.67 - *print-circle* nil) 454.68 - 454.69 -;;; TODO: should we just use *print-dup* here? 454.70 -(def 454.71 - ^{:private true, 454.72 - :doc "Mark repeated structures rather than repeat them (N.B. This is not yet used)"} 454.73 - *print-shared* nil) 454.74 - 454.75 -(def 454.76 - ^{:doc "Don't print namespaces with symbols. This is particularly useful when 454.77 -pretty printing the results of macro expansions" 454.78 - :added "1.2"} 454.79 - *print-suppress-namespaces* nil) 454.80 - 454.81 -;;; TODO: support print-base and print-radix in cl-format 454.82 -;;; TODO: support print-base and print-radix in rationals 454.83 -(def 454.84 - ^{:doc "Print a radix specifier in front of integers and rationals. If *print-base* is 2, 8, 454.85 -or 16, then the radix specifier used is #b, #o, or #x, respectively. Otherwise the 454.86 -radix specifier is in the form #XXr where XX is the decimal value of *print-base* " 454.87 - :added "1.2"} 454.88 - *print-radix* nil) 454.89 - 454.90 -(def 454.91 - ^{:doc "The base to use for printing integers and rationals." 454.92 - :added "1.2"} 454.93 - *print-base* 10) 454.94 - 454.95 - 454.96 - 454.97 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 454.98 -;; Internal variables that keep track of where we are in the 454.99 -;; structure 454.100 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 454.101 - 454.102 -(def ^{ :private true } *current-level* 0) 454.103 - 454.104 -(def ^{ :private true } *current-length* nil) 454.105 - 454.106 -;; TODO: add variables for length, lines. 454.107 - 454.108 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 454.109 -;; Support for the write function 454.110 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 454.111 - 454.112 -(declare format-simple-number) 454.113 - 454.114 -(def ^{:private true} orig-pr pr) 454.115 - 454.116 -(defn- pr-with-base [x] 454.117 - (if-let [s (format-simple-number x)] 454.118 - (print s) 454.119 - (orig-pr x))) 454.120 - 454.121 -(def ^{:private true} write-option-table 454.122 - {;:array *print-array* 454.123 - :base 'clojure.pprint/*print-base*, 454.124 - ;;:case *print-case*, 454.125 - :circle 'clojure.pprint/*print-circle*, 454.126 - ;;:escape *print-escape*, 454.127 - ;;:gensym *print-gensym*, 454.128 - :length 'clojure.core/*print-length*, 454.129 - :level 'clojure.core/*print-level*, 454.130 - :lines 'clojure.pprint/*print-lines*, 454.131 - :miser-width 'clojure.pprint/*print-miser-width*, 454.132 - :dispatch 'clojure.pprint/*print-pprint-dispatch*, 454.133 - :pretty 'clojure.pprint/*print-pretty*, 454.134 - :radix 'clojure.pprint/*print-radix*, 454.135 - :readably 'clojure.core/*print-readably*, 454.136 - :right-margin 'clojure.pprint/*print-right-margin*, 454.137 - :suppress-namespaces 'clojure.pprint/*print-suppress-namespaces*}) 454.138 - 454.139 - 454.140 -(defmacro ^{:private true} binding-map [amap & body] 454.141 - (let [] 454.142 - `(do 454.143 - (. clojure.lang.Var (pushThreadBindings ~amap)) 454.144 - (try 454.145 - ~@body 454.146 - (finally 454.147 - (. clojure.lang.Var (popThreadBindings))))))) 454.148 - 454.149 -(defn- table-ize [t m] 454.150 - (apply hash-map (mapcat 454.151 - #(when-let [v (get t (key %))] [(find-var v) (val %)]) 454.152 - m))) 454.153 - 454.154 -(defn- pretty-writer? 454.155 - "Return true iff x is a PrettyWriter" 454.156 - [x] (and (instance? clojure.lang.IDeref x) (:pretty-writer @@x))) 454.157 - 454.158 -(defn- make-pretty-writer 454.159 - "Wrap base-writer in a PrettyWriter with the specified right-margin and miser-width" 454.160 - [base-writer right-margin miser-width] 454.161 - (pretty-writer base-writer right-margin miser-width)) 454.162 - 454.163 -(defmacro ^{:private true} with-pretty-writer [base-writer & body] 454.164 - `(let [base-writer# ~base-writer 454.165 - new-writer# (not (pretty-writer? base-writer#))] 454.166 - (binding [*out* (if new-writer# 454.167 - (make-pretty-writer base-writer# *print-right-margin* *print-miser-width*) 454.168 - base-writer#)] 454.169 - ~@body 454.170 - (.flush *out*)))) 454.171 - 454.172 - 454.173 -;;;TODO: if pretty print is not set, don't use pr but rather something that respects *print-base*, etc. 454.174 -(defn write-out 454.175 - "Write an object to *out* subject to the current bindings of the printer control 454.176 -variables. Use the kw-args argument to override individual variables for this call (and 454.177 -any recursive calls). 454.178 - 454.179 -*out* must be a PrettyWriter if pretty printing is enabled. This is the responsibility 454.180 -of the caller. 454.181 - 454.182 -This method is primarily intended for use by pretty print dispatch functions that 454.183 -already know that the pretty printer will have set up their environment appropriately. 454.184 -Normal library clients should use the standard \"write\" interface. " 454.185 - {:added "1.2"} 454.186 - [object] 454.187 - (let [length-reached (and 454.188 - *current-length* 454.189 - *print-length* 454.190 - (>= *current-length* *print-length*))] 454.191 - (if-not *print-pretty* 454.192 - (pr object) 454.193 - (if length-reached 454.194 - (print "...") 454.195 - (do 454.196 - (if *current-length* (set! *current-length* (inc *current-length*))) 454.197 - (*print-pprint-dispatch* object)))) 454.198 - length-reached)) 454.199 - 454.200 -(defn write 454.201 - "Write an object subject to the current bindings of the printer control variables. 454.202 -Use the kw-args argument to override individual variables for this call (and any 454.203 -recursive calls). Returns the string result if :stream is nil or nil otherwise. 454.204 - 454.205 -The following keyword arguments can be passed with values: 454.206 - Keyword Meaning Default value 454.207 - :stream Writer for output or nil true (indicates *out*) 454.208 - :base Base to use for writing rationals Current value of *print-base* 454.209 - :circle* If true, mark circular structures Current value of *print-circle* 454.210 - :length Maximum elements to show in sublists Current value of *print-length* 454.211 - :level Maximum depth Current value of *print-level* 454.212 - :lines* Maximum lines of output Current value of *print-lines* 454.213 - :miser-width Width to enter miser mode Current value of *print-miser-width* 454.214 - :dispatch The pretty print dispatch function Current value of *print-pprint-dispatch* 454.215 - :pretty If true, do pretty printing Current value of *print-pretty* 454.216 - :radix If true, prepend a radix specifier Current value of *print-radix* 454.217 - :readably* If true, print readably Current value of *print-readably* 454.218 - :right-margin The column for the right margin Current value of *print-right-margin* 454.219 - :suppress-namespaces If true, no namespaces in symbols Current value of *print-suppress-namespaces* 454.220 - 454.221 - * = not yet supported 454.222 -" 454.223 - {:added "1.2"} 454.224 - [object & kw-args] 454.225 - (let [options (merge {:stream true} (apply hash-map kw-args))] 454.226 - (binding-map (table-ize write-option-table options) 454.227 - (binding-map (if (or (not (= *print-base* 10)) *print-radix*) {#'pr pr-with-base} {}) 454.228 - (let [optval (if (contains? options :stream) 454.229 - (:stream options) 454.230 - true) 454.231 - base-writer (condp = optval 454.232 - nil (java.io.StringWriter.) 454.233 - true *out* 454.234 - optval)] 454.235 - (if *print-pretty* 454.236 - (with-pretty-writer base-writer 454.237 - (write-out object)) 454.238 - (binding [*out* base-writer] 454.239 - (pr object))) 454.240 - (if (nil? optval) 454.241 - (.toString ^java.io.StringWriter base-writer))))))) 454.242 - 454.243 - 454.244 -(defn pprint 454.245 - "Pretty print object to the optional output writer. If the writer is not provided, 454.246 -print the object to the currently bound value of *out*." 454.247 - {:added "1.2"} 454.248 - ([object] (pprint object *out*)) 454.249 - ([object writer] 454.250 - (with-pretty-writer writer 454.251 - (binding [*print-pretty* true] 454.252 - (binding-map (if (or (not (= *print-base* 10)) *print-radix*) {#'pr pr-with-base} {}) 454.253 - (write-out object))) 454.254 - (if (not (= 0 (get-column *out*))) 454.255 - (.write *out* (int \newline)))))) 454.256 - 454.257 -(defmacro pp 454.258 - "A convenience macro that pretty prints the last thing output. This is 454.259 -exactly equivalent to (pprint *1)." 454.260 - {:added "1.2"} 454.261 - [] `(pprint *1)) 454.262 - 454.263 -(defn set-pprint-dispatch 454.264 - "Set the pretty print dispatch function to a function matching (fn [obj] ...) 454.265 -where obj is the object to pretty print. That function will be called with *out* set 454.266 -to a pretty printing writer to which it should do its printing. 454.267 - 454.268 -For example functions, see simple-dispatch and code-dispatch in 454.269 -clojure.pprint.dispatch.clj." 454.270 - {:added "1.2"} 454.271 - [function] 454.272 - (let [old-meta (meta #'*print-pprint-dispatch*)] 454.273 - (alter-var-root #'*print-pprint-dispatch* (constantly function)) 454.274 - (alter-meta! #'*print-pprint-dispatch* (constantly old-meta))) 454.275 - nil) 454.276 - 454.277 -(defmacro with-pprint-dispatch 454.278 - "Execute body with the pretty print dispatch function bound to function." 454.279 - {:added "1.2"} 454.280 - [function & body] 454.281 - `(binding [*print-pprint-dispatch* ~function] 454.282 - ~@body)) 454.283 - 454.284 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 454.285 -;; Support for the functional interface to the pretty printer 454.286 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 454.287 - 454.288 -(defn- parse-lb-options [opts body] 454.289 - (loop [body body 454.290 - acc []] 454.291 - (if (opts (first body)) 454.292 - (recur (drop 2 body) (concat acc (take 2 body))) 454.293 - [(apply hash-map acc) body]))) 454.294 - 454.295 -(defn- check-enumerated-arg [arg choices] 454.296 - (if-not (choices arg) 454.297 - (throw 454.298 - (IllegalArgumentException. 454.299 - ;; TODO clean up choices string 454.300 - (str "Bad argument: " arg ". It must be one of " choices))))) 454.301 - 454.302 -(defn- level-exceeded [] 454.303 - (and *print-level* (>= *current-level* *print-level*))) 454.304 - 454.305 -(defmacro pprint-logical-block 454.306 - "Execute the body as a pretty printing logical block with output to *out* which 454.307 -must be a pretty printing writer. When used from pprint or cl-format, this can be 454.308 -assumed. 454.309 - 454.310 -This function is intended for use when writing custom dispatch functions. 454.311 - 454.312 -Before the body, the caller can optionally specify options: :prefix, :per-line-prefix, 454.313 -and :suffix." 454.314 - {:added "1.2", :arglists '[[options* body]]} 454.315 - [& args] 454.316 - (let [[options body] (parse-lb-options #{:prefix :per-line-prefix :suffix} args)] 454.317 - `(do (if (#'clojure.pprint/level-exceeded) 454.318 - (.write ^java.io.Writer *out* "#") 454.319 - (do 454.320 - (push-thread-bindings {#'clojure.pprint/*current-level* 454.321 - (inc (var-get #'clojure.pprint/*current-level*)) 454.322 - #'clojure.pprint/*current-length* 0}) 454.323 - (try 454.324 - (#'clojure.pprint/start-block *out* 454.325 - ~(:prefix options) ~(:per-line-prefix options) ~(:suffix options)) 454.326 - ~@body 454.327 - (#'clojure.pprint/end-block *out*) 454.328 - (finally 454.329 - (pop-thread-bindings))))) 454.330 - nil))) 454.331 - 454.332 -(defn pprint-newline 454.333 - "Print a conditional newline to a pretty printing stream. kind specifies if the 454.334 -newline is :linear, :miser, :fill, or :mandatory. 454.335 - 454.336 -This function is intended for use when writing custom dispatch functions. 454.337 - 454.338 -Output is sent to *out* which must be a pretty printing writer." 454.339 - {:added "1.2"} 454.340 - [kind] 454.341 - (check-enumerated-arg kind #{:linear :miser :fill :mandatory}) 454.342 - (nl *out* kind)) 454.343 - 454.344 -(defn pprint-indent 454.345 - "Create an indent at this point in the pretty printing stream. This defines how 454.346 -following lines are indented. relative-to can be either :block or :current depending 454.347 -whether the indent should be computed relative to the start of the logical block or 454.348 -the current column position. n is an offset. 454.349 - 454.350 -This function is intended for use when writing custom dispatch functions. 454.351 - 454.352 -Output is sent to *out* which must be a pretty printing writer." 454.353 - {:added "1.2"} 454.354 - [relative-to n] 454.355 - (check-enumerated-arg relative-to #{:block :current}) 454.356 - (indent *out* relative-to n)) 454.357 - 454.358 -;; TODO a real implementation for pprint-tab 454.359 -(defn pprint-tab 454.360 - "Tab at this point in the pretty printing stream. kind specifies whether the tab 454.361 -is :line, :section, :line-relative, or :section-relative. 454.362 - 454.363 -Colnum and colinc specify the target column and the increment to move the target 454.364 -forward if the output is already past the original target. 454.365 - 454.366 -This function is intended for use when writing custom dispatch functions. 454.367 - 454.368 -Output is sent to *out* which must be a pretty printing writer. 454.369 - 454.370 -THIS FUNCTION IS NOT YET IMPLEMENTED." 454.371 - {:added "1.2"} 454.372 - [kind colnum colinc] 454.373 - (check-enumerated-arg kind #{:line :section :line-relative :section-relative}) 454.374 - (throw (UnsupportedOperationException. "pprint-tab is not yet implemented"))) 454.375 - 454.376 - 454.377 -nil
455.1 --- a/src/clojure/pprint/pretty_writer.clj Sat Aug 21 06:25:44 2010 -0400 455.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 455.3 @@ -1,483 +0,0 @@ 455.4 -;;; pretty_writer.clj -- part of the pretty printer for Clojure 455.5 - 455.6 -; Copyright (c) Rich Hickey. All rights reserved. 455.7 -; The use and distribution terms for this software are covered by the 455.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 455.9 -; which can be found in the file epl-v10.html at the root of this distribution. 455.10 -; By using this software in any fashion, you are agreeing to be bound by 455.11 -; the terms of this license. 455.12 -; You must not remove this notice, or any other, from this software. 455.13 - 455.14 -;; Author: Tom Faulhaber 455.15 -;; April 3, 2009 455.16 -;; Revised to use proxy instead of gen-class April 2010 455.17 - 455.18 -;; This module implements a wrapper around a java.io.Writer which implements the 455.19 -;; core of the XP algorithm. 455.20 - 455.21 -(in-ns 'clojure.pprint) 455.22 - 455.23 -(import [clojure.lang IDeref] 455.24 - [java.io Writer]) 455.25 - 455.26 -;; TODO: Support for tab directives 455.27 - 455.28 - 455.29 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.30 -;;; Forward declarations 455.31 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.32 - 455.33 -(declare get-miser-width) 455.34 - 455.35 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.36 -;;; Macros to simplify dealing with types and classes. These are 455.37 -;;; really utilities, but I'm experimenting with them here. 455.38 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.39 - 455.40 -(defmacro ^{:private true} 455.41 - getf 455.42 - "Get the value of the field a named by the argument (which should be a keyword)." 455.43 - [sym] 455.44 - `(~sym @@~'this)) 455.45 - 455.46 -(defmacro ^{:private true} 455.47 - setf [sym new-val] 455.48 - "Set the value of the field SYM to NEW-VAL" 455.49 - `(alter @~'this assoc ~sym ~new-val)) 455.50 - 455.51 -(defmacro ^{:private true} 455.52 - deftype [type-name & fields] 455.53 - (let [name-str (name type-name)] 455.54 - `(do 455.55 - (defstruct ~type-name :type-tag ~@fields) 455.56 - (alter-meta! #'~type-name assoc :private true) 455.57 - (defn- ~(symbol (str "make-" name-str)) 455.58 - [& vals#] (apply struct ~type-name ~(keyword name-str) vals#)) 455.59 - (defn- ~(symbol (str name-str "?")) [x#] (= (:type-tag x#) ~(keyword name-str)))))) 455.60 - 455.61 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.62 -;;; The data structures used by pretty-writer 455.63 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.64 - 455.65 -(defstruct ^{:private true} logical-block 455.66 - :parent :section :start-col :indent 455.67 - :done-nl :intra-block-nl 455.68 - :prefix :per-line-prefix :suffix 455.69 - :logical-block-callback) 455.70 - 455.71 -(defn- ancestor? [parent child] 455.72 - (loop [child (:parent child)] 455.73 - (cond 455.74 - (nil? child) false 455.75 - (identical? parent child) true 455.76 - :else (recur (:parent child))))) 455.77 - 455.78 -(defstruct ^{:private true} section :parent) 455.79 - 455.80 -(defn- buffer-length [l] 455.81 - (let [l (seq l)] 455.82 - (if l 455.83 - (- (:end-pos (last l)) (:start-pos (first l))) 455.84 - 0))) 455.85 - 455.86 -; A blob of characters (aka a string) 455.87 -(deftype buffer-blob :data :trailing-white-space :start-pos :end-pos) 455.88 - 455.89 -; A newline 455.90 -(deftype nl-t :type :logical-block :start-pos :end-pos) 455.91 - 455.92 -(deftype start-block-t :logical-block :start-pos :end-pos) 455.93 - 455.94 -(deftype end-block-t :logical-block :start-pos :end-pos) 455.95 - 455.96 -(deftype indent-t :logical-block :relative-to :offset :start-pos :end-pos) 455.97 - 455.98 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.99 -;;; Functions to write tokens in the output buffer 455.100 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.101 - 455.102 -(declare emit-nl) 455.103 - 455.104 -(defmulti ^{:private true} write-token #(:type-tag %2)) 455.105 -(defmethod write-token :start-block-t [^Writer this token] 455.106 - (when-let [cb (getf :logical-block-callback)] (cb :start)) 455.107 - (let [lb (:logical-block token)] 455.108 - (dosync 455.109 - (when-let [^String prefix (:prefix lb)] 455.110 - (.write (getf :base) prefix)) 455.111 - (let [col (get-column (getf :base))] 455.112 - (ref-set (:start-col lb) col) 455.113 - (ref-set (:indent lb) col))))) 455.114 - 455.115 -(defmethod write-token :end-block-t [^Writer this token] 455.116 - (when-let [cb (getf :logical-block-callback)] (cb :end)) 455.117 - (when-let [^String suffix (:suffix (:logical-block token))] 455.118 - (.write (getf :base) suffix))) 455.119 - 455.120 -(defmethod write-token :indent-t [^Writer this token] 455.121 - (let [lb (:logical-block token)] 455.122 - (ref-set (:indent lb) 455.123 - (+ (:offset token) 455.124 - (condp = (:relative-to token) 455.125 - :block @(:start-col lb) 455.126 - :current (get-column (getf :base))))))) 455.127 - 455.128 -(defmethod write-token :buffer-blob [^Writer this token] 455.129 - (.write (getf :base) ^String (:data token))) 455.130 - 455.131 -(defmethod write-token :nl-t [^Writer this token] 455.132 -; (prlabel wt @(:done-nl (:logical-block token))) 455.133 -; (prlabel wt (:type token) (= (:type token) :mandatory)) 455.134 - (if (or (= (:type token) :mandatory) 455.135 - (and (not (= (:type token) :fill)) 455.136 - @(:done-nl (:logical-block token)))) 455.137 - (emit-nl this token) 455.138 - (if-let [^String tws (getf :trailing-white-space)] 455.139 - (.write (getf :base) tws))) 455.140 - (dosync (setf :trailing-white-space nil))) 455.141 - 455.142 -(defn- write-tokens [^Writer this tokens force-trailing-whitespace] 455.143 - (doseq [token tokens] 455.144 - (if-not (= (:type-tag token) :nl-t) 455.145 - (if-let [^String tws (getf :trailing-white-space)] 455.146 - (.write (getf :base) tws))) 455.147 - (write-token this token) 455.148 - (setf :trailing-white-space (:trailing-white-space token))) 455.149 - (let [^String tws (getf :trailing-white-space)] 455.150 - (when (and force-trailing-whitespace tws) 455.151 - (.write (getf :base) tws) 455.152 - (setf :trailing-white-space nil)))) 455.153 - 455.154 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.155 -;;; emit-nl? method defs for each type of new line. This makes 455.156 -;;; the decision about whether to print this type of new line. 455.157 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.158 - 455.159 - 455.160 -(defn- tokens-fit? [^Writer this tokens] 455.161 -;;; (prlabel tf? (get-column (getf :base) (buffer-length tokens)) 455.162 - (let [maxcol (get-max-column (getf :base))] 455.163 - (or 455.164 - (nil? maxcol) 455.165 - (< (+ (get-column (getf :base)) (buffer-length tokens)) maxcol)))) 455.166 - 455.167 -(defn- linear-nl? [this lb section] 455.168 -; (prlabel lnl? @(:done-nl lb) (tokens-fit? this section)) 455.169 - (or @(:done-nl lb) 455.170 - (not (tokens-fit? this section)))) 455.171 - 455.172 -(defn- miser-nl? [^Writer this lb section] 455.173 - (let [miser-width (get-miser-width this) 455.174 - maxcol (get-max-column (getf :base))] 455.175 - (and miser-width maxcol 455.176 - (>= @(:start-col lb) (- maxcol miser-width)) 455.177 - (linear-nl? this lb section)))) 455.178 - 455.179 -(defmulti ^{:private true} emit-nl? (fn [t _ _ _] (:type t))) 455.180 - 455.181 -(defmethod emit-nl? :linear [newl this section _] 455.182 - (let [lb (:logical-block newl)] 455.183 - (linear-nl? this lb section))) 455.184 - 455.185 -(defmethod emit-nl? :miser [newl this section _] 455.186 - (let [lb (:logical-block newl)] 455.187 - (miser-nl? this lb section))) 455.188 - 455.189 -(defmethod emit-nl? :fill [newl this section subsection] 455.190 - (let [lb (:logical-block newl)] 455.191 - (or @(:intra-block-nl lb) 455.192 - (not (tokens-fit? this subsection)) 455.193 - (miser-nl? this lb section)))) 455.194 - 455.195 -(defmethod emit-nl? :mandatory [_ _ _ _] 455.196 - true) 455.197 - 455.198 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.199 -;;; Various support functions 455.200 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.201 - 455.202 - 455.203 -(defn- get-section [buffer] 455.204 - (let [nl (first buffer) 455.205 - lb (:logical-block nl) 455.206 - section (seq (take-while #(not (and (nl-t? %) (ancestor? (:logical-block %) lb))) 455.207 - (next buffer)))] 455.208 - [section (seq (drop (inc (count section)) buffer))])) 455.209 - 455.210 -(defn- get-sub-section [buffer] 455.211 - (let [nl (first buffer) 455.212 - lb (:logical-block nl) 455.213 - section (seq (take-while #(let [nl-lb (:logical-block %)] 455.214 - (not (and (nl-t? %) (or (= nl-lb lb) (ancestor? nl-lb lb))))) 455.215 - (next buffer)))] 455.216 - section)) 455.217 - 455.218 -(defn- update-nl-state [lb] 455.219 - (dosync 455.220 - (ref-set (:intra-block-nl lb) false) 455.221 - (ref-set (:done-nl lb) true) 455.222 - (loop [lb (:parent lb)] 455.223 - (if lb 455.224 - (do (ref-set (:done-nl lb) true) 455.225 - (ref-set (:intra-block-nl lb) true) 455.226 - (recur (:parent lb))))))) 455.227 - 455.228 -(defn- emit-nl [^Writer this nl] 455.229 - (.write (getf :base) (int \newline)) 455.230 - (dosync (setf :trailing-white-space nil)) 455.231 - (let [lb (:logical-block nl) 455.232 - ^String prefix (:per-line-prefix lb)] 455.233 - (if prefix 455.234 - (.write (getf :base) prefix)) 455.235 - (let [^String istr (apply str (repeat (- @(:indent lb) (count prefix)) 455.236 - \space))] 455.237 - (.write (getf :base) istr)) 455.238 - (update-nl-state lb))) 455.239 - 455.240 -(defn- split-at-newline [tokens] 455.241 - (let [pre (seq (take-while #(not (nl-t? %)) tokens))] 455.242 - [pre (seq (drop (count pre) tokens))])) 455.243 - 455.244 -;;; Methods for showing token strings for debugging 455.245 - 455.246 -(defmulti ^{:private true} tok :type-tag) 455.247 -(defmethod tok :nl-t [token] 455.248 - (:type token)) 455.249 -(defmethod tok :buffer-blob [token] 455.250 - (str \" (:data token) (:trailing-white-space token) \")) 455.251 -(defmethod tok :default [token] 455.252 - (:type-tag token)) 455.253 -(defn- toks [toks] (map tok toks)) 455.254 - 455.255 -;;; write-token-string is called when the set of tokens in the buffer 455.256 -;;; is longer than the available space on the line 455.257 - 455.258 -(defn- write-token-string [this tokens] 455.259 - (let [[a b] (split-at-newline tokens)] 455.260 -;; (prlabel wts (toks a) (toks b)) 455.261 - (if a (write-tokens this a false)) 455.262 - (if b 455.263 - (let [[section remainder] (get-section b) 455.264 - newl (first b)] 455.265 -;; (prlabel wts (toks section)) (prlabel wts (:type newl)) (prlabel wts (toks remainder)) 455.266 - (let [do-nl (emit-nl? newl this section (get-sub-section b)) 455.267 - result (if do-nl 455.268 - (do 455.269 -;; (prlabel emit-nl (:type newl)) 455.270 - (emit-nl this newl) 455.271 - (next b)) 455.272 - b) 455.273 - long-section (not (tokens-fit? this result)) 455.274 - result (if long-section 455.275 - (let [rem2 (write-token-string this section)] 455.276 -;;; (prlabel recurse (toks rem2)) 455.277 - (if (= rem2 section) 455.278 - (do ; If that didn't produce any output, it has no nls 455.279 - ; so we'll force it 455.280 - (write-tokens this section false) 455.281 - remainder) 455.282 - (into [] (concat rem2 remainder)))) 455.283 - result) 455.284 -;; ff (prlabel wts (toks result)) 455.285 - ] 455.286 - result))))) 455.287 - 455.288 -(defn- write-line [^Writer this] 455.289 - (dosync 455.290 - (loop [buffer (getf :buffer)] 455.291 -;; (prlabel wl1 (toks buffer)) 455.292 - (setf :buffer (into [] buffer)) 455.293 - (if (not (tokens-fit? this buffer)) 455.294 - (let [new-buffer (write-token-string this buffer)] 455.295 -;; (prlabel wl new-buffer) 455.296 - (if-not (identical? buffer new-buffer) 455.297 - (recur new-buffer))))))) 455.298 - 455.299 -;;; Add a buffer token to the buffer and see if it's time to start 455.300 -;;; writing 455.301 -(defn- add-to-buffer [^Writer this token] 455.302 -; (prlabel a2b token) 455.303 - (dosync 455.304 - (setf :buffer (conj (getf :buffer) token)) 455.305 - (if (not (tokens-fit? this (getf :buffer))) 455.306 - (write-line this)))) 455.307 - 455.308 -;;; Write all the tokens that have been buffered 455.309 -(defn- write-buffered-output [^Writer this] 455.310 - (write-line this) 455.311 - (if-let [buf (getf :buffer)] 455.312 - (do 455.313 - (write-tokens this buf true) 455.314 - (setf :buffer [])))) 455.315 - 455.316 -;;; If there are newlines in the string, print the lines up until the last newline, 455.317 -;;; making the appropriate adjustments. Return the remainder of the string 455.318 -(defn- write-initial-lines 455.319 - [^Writer this ^String s] 455.320 - (let [lines (.split s "\n" -1)] 455.321 - (if (= (count lines) 1) 455.322 - s 455.323 - (dosync 455.324 - (let [^String prefix (:per-line-prefix (first (getf :logical-blocks))) 455.325 - ^String l (first lines)] 455.326 - (if (= :buffering (getf :mode)) 455.327 - (let [oldpos (getf :pos) 455.328 - newpos (+ oldpos (count l))] 455.329 - (setf :pos newpos) 455.330 - (add-to-buffer this (make-buffer-blob l nil oldpos newpos)) 455.331 - (write-buffered-output this)) 455.332 - (.write (getf :base) l)) 455.333 - (.write (getf :base) (int \newline)) 455.334 - (doseq [^String l (next (butlast lines))] 455.335 - (.write (getf :base) l) 455.336 - (.write (getf :base) (int \newline)) 455.337 - (if prefix 455.338 - (.write (getf :base) prefix))) 455.339 - (setf :buffering :writing) 455.340 - (last lines)))))) 455.341 - 455.342 - 455.343 -(defn- write-white-space [^Writer this] 455.344 - (if-let [^String tws (getf :trailing-white-space)] 455.345 - (dosync 455.346 - (.write (getf :base) tws) 455.347 - (setf :trailing-white-space nil)))) 455.348 - 455.349 -(defn- p-write-char [^Writer this ^Integer c] 455.350 - (if (= (getf :mode) :writing) 455.351 - (do 455.352 - (write-white-space this) 455.353 - (.write (getf :base) c)) 455.354 - (if (= c \newline) 455.355 - (write-initial-lines this "\n") 455.356 - (let [oldpos (getf :pos) 455.357 - newpos (inc oldpos)] 455.358 - (dosync 455.359 - (setf :pos newpos) 455.360 - (add-to-buffer this (make-buffer-blob (str (char c)) nil oldpos newpos))))))) 455.361 - 455.362 - 455.363 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.364 -;;; Initialize the pretty-writer instance 455.365 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.366 - 455.367 - 455.368 -(defn- pretty-writer [writer max-columns miser-width] 455.369 - (let [lb (struct logical-block nil nil (ref 0) (ref 0) (ref false) (ref false)) 455.370 - fields (ref {:pretty-writer true 455.371 - :base (column-writer writer max-columns) 455.372 - :logical-blocks lb 455.373 - :sections nil 455.374 - :mode :writing 455.375 - :buffer [] 455.376 - :buffer-block lb 455.377 - :buffer-level 1 455.378 - :miser-width miser-width 455.379 - :trailing-white-space nil 455.380 - :pos 0})] 455.381 - (proxy [Writer IDeref] [] 455.382 - (deref [] fields) 455.383 - 455.384 - (write 455.385 - ([x] 455.386 - ;; (prlabel write x (getf :mode)) 455.387 - (condp = (class x) 455.388 - String 455.389 - (let [^String s0 (write-initial-lines this x) 455.390 - ^String s (.replaceFirst s0 "\\s+$" "") 455.391 - white-space (.substring s0 (count s)) 455.392 - mode (getf :mode)] 455.393 - (dosync 455.394 - (if (= mode :writing) 455.395 - (do 455.396 - (write-white-space this) 455.397 - (.write (getf :base) s) 455.398 - (setf :trailing-white-space white-space)) 455.399 - (let [oldpos (getf :pos) 455.400 - newpos (+ oldpos (count s0))] 455.401 - (setf :pos newpos) 455.402 - (add-to-buffer this (make-buffer-blob s white-space oldpos newpos)))))) 455.403 - 455.404 - Integer 455.405 - (p-write-char this x)))) 455.406 - 455.407 - (flush [] 455.408 - (if (= (getf :mode) :buffering) 455.409 - (dosync 455.410 - (write-tokens this (getf :buffer) true) 455.411 - (setf :buffer [])) 455.412 - (write-white-space this))) 455.413 - 455.414 - (close [] 455.415 - (.flush this))))) 455.416 - 455.417 - 455.418 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.419 -;;; Methods for pretty-writer 455.420 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455.421 - 455.422 -(defn- start-block 455.423 - [^Writer this 455.424 - ^String prefix ^String per-line-prefix ^String suffix] 455.425 - (dosync 455.426 - (let [lb (struct logical-block (getf :logical-blocks) nil (ref 0) (ref 0) 455.427 - (ref false) (ref false) 455.428 - prefix per-line-prefix suffix)] 455.429 - (setf :logical-blocks lb) 455.430 - (if (= (getf :mode) :writing) 455.431 - (do 455.432 - (write-white-space this) 455.433 - (when-let [cb (getf :logical-block-callback)] (cb :start)) 455.434 - (if prefix 455.435 - (.write (getf :base) prefix)) 455.436 - (let [col (get-column (getf :base))] 455.437 - (ref-set (:start-col lb) col) 455.438 - (ref-set (:indent lb) col))) 455.439 - (let [oldpos (getf :pos) 455.440 - newpos (+ oldpos (if prefix (count prefix) 0))] 455.441 - (setf :pos newpos) 455.442 - (add-to-buffer this (make-start-block-t lb oldpos newpos))))))) 455.443 - 455.444 -(defn- end-block [^Writer this] 455.445 - (dosync 455.446 - (let [lb (getf :logical-blocks) 455.447 - ^String suffix (:suffix lb)] 455.448 - (if (= (getf :mode) :writing) 455.449 - (do 455.450 - (write-white-space this) 455.451 - (if suffix 455.452 - (.write (getf :base) suffix)) 455.453 - (when-let [cb (getf :logical-block-callback)] (cb :end))) 455.454 - (let [oldpos (getf :pos) 455.455 - newpos (+ oldpos (if suffix (count suffix) 0))] 455.456 - (setf :pos newpos) 455.457 - (add-to-buffer this (make-end-block-t lb oldpos newpos)))) 455.458 - (setf :logical-blocks (:parent lb))))) 455.459 - 455.460 -(defn- nl [^Writer this type] 455.461 - (dosync 455.462 - (setf :mode :buffering) 455.463 - (let [pos (getf :pos)] 455.464 - (add-to-buffer this (make-nl-t type (getf :logical-blocks) pos pos))))) 455.465 - 455.466 -(defn- indent [^Writer this relative-to offset] 455.467 - (dosync 455.468 - (let [lb (getf :logical-blocks)] 455.469 - (if (= (getf :mode) :writing) 455.470 - (do 455.471 - (write-white-space this) 455.472 - (ref-set (:indent lb) 455.473 - (+ offset (condp = relative-to 455.474 - :block @(:start-col lb) 455.475 - :current (get-column (getf :base)))))) 455.476 - (let [pos (getf :pos)] 455.477 - (add-to-buffer this (make-indent-t lb relative-to offset pos pos))))))) 455.478 - 455.479 -(defn- get-miser-width [^Writer this] 455.480 - (getf :miser-width)) 455.481 - 455.482 -(defn- set-miser-width [^Writer this new-miser-width] 455.483 - (dosync (setf :miser-width new-miser-width))) 455.484 - 455.485 -(defn- set-logical-block-callback [^Writer this f] 455.486 - (dosync (setf :logical-block-callback f)))
456.1 --- a/src/clojure/pprint/utilities.clj Sat Aug 21 06:25:44 2010 -0400 456.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 456.3 @@ -1,104 +0,0 @@ 456.4 -;;; utilities.clj -- part of the pretty printer for Clojure 456.5 - 456.6 -; Copyright (c) Rich Hickey. All rights reserved. 456.7 -; The use and distribution terms for this software are covered by the 456.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 456.9 -; which can be found in the file epl-v10.html at the root of this distribution. 456.10 -; By using this software in any fashion, you are agreeing to be bound by 456.11 -; the terms of this license. 456.12 -; You must not remove this notice, or any other, from this software. 456.13 - 456.14 -;; Author: Tom Faulhaber 456.15 -;; April 3, 2009 456.16 - 456.17 -;; This module implements some utility function used in formatting and pretty 456.18 -;; printing. The functions here could go in a more general purpose library, 456.19 -;; perhaps. 456.20 - 456.21 -(in-ns 'clojure.pprint) 456.22 - 456.23 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 456.24 -;;; Helper functions for digesting formats in the various 456.25 -;;; phases of their lives. 456.26 -;;; These functions are actually pretty general. 456.27 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 456.28 - 456.29 -(defn- map-passing-context [func initial-context lis] 456.30 - (loop [context initial-context 456.31 - lis lis 456.32 - acc []] 456.33 - (if (empty? lis) 456.34 - [acc context] 456.35 - (let [this (first lis) 456.36 - remainder (next lis) 456.37 - [result new-context] (apply func [this context])] 456.38 - (recur new-context remainder (conj acc result)))))) 456.39 - 456.40 -(defn- consume [func initial-context] 456.41 - (loop [context initial-context 456.42 - acc []] 456.43 - (let [[result new-context] (apply func [context])] 456.44 - (if (not result) 456.45 - [acc new-context] 456.46 - (recur new-context (conj acc result)))))) 456.47 - 456.48 -(defn- consume-while [func initial-context] 456.49 - (loop [context initial-context 456.50 - acc []] 456.51 - (let [[result continue new-context] (apply func [context])] 456.52 - (if (not continue) 456.53 - [acc context] 456.54 - (recur new-context (conj acc result)))))) 456.55 - 456.56 -(defn- unzip-map [m] 456.57 - "Take a map that has pairs in the value slots and produce a pair of maps, 456.58 - the first having all the first elements of the pairs and the second all 456.59 - the second elements of the pairs" 456.60 - [(into {} (for [[k [v1 v2]] m] [k v1])) 456.61 - (into {} (for [[k [v1 v2]] m] [k v2]))]) 456.62 - 456.63 -(defn- tuple-map [m v1] 456.64 - "For all the values, v, in the map, replace them with [v v1]" 456.65 - (into {} (for [[k v] m] [k [v v1]]))) 456.66 - 456.67 -(defn- rtrim [s c] 456.68 - "Trim all instances of c from the end of sequence s" 456.69 - (let [len (count s)] 456.70 - (if (and (pos? len) (= (nth s (dec (count s))) c)) 456.71 - (loop [n (dec len)] 456.72 - (cond 456.73 - (neg? n) "" 456.74 - (not (= (nth s n) c)) (subs s 0 (inc n)) 456.75 - true (recur (dec n)))) 456.76 - s))) 456.77 - 456.78 -(defn- ltrim [s c] 456.79 - "Trim all instances of c from the beginning of sequence s" 456.80 - (let [len (count s)] 456.81 - (if (and (pos? len) (= (nth s 0) c)) 456.82 - (loop [n 0] 456.83 - (if (or (= n len) (not (= (nth s n) c))) 456.84 - (subs s n) 456.85 - (recur (inc n)))) 456.86 - s))) 456.87 - 456.88 -(defn- prefix-count [aseq val] 456.89 - "Return the number of times that val occurs at the start of sequence aseq, 456.90 -if val is a seq itself, count the number of times any element of val occurs at the 456.91 -beginning of aseq" 456.92 - (let [test (if (coll? val) (set val) #{val})] 456.93 - (loop [pos 0] 456.94 - (if (or (= pos (count aseq)) (not (test (nth aseq pos)))) 456.95 - pos 456.96 - (recur (inc pos)))))) 456.97 - 456.98 -(defn- prerr [& args] 456.99 - "Println to *err*" 456.100 - (binding [*out* *err*] 456.101 - (apply println args))) 456.102 - 456.103 -(defmacro ^{:private true} prlabel [prefix arg & more-args] 456.104 - "Print args to *err* in name = value format" 456.105 - `(prerr ~@(cons (list 'quote prefix) (mapcat #(list (list 'quote %) "=" %) 456.106 - (cons arg (seq more-args)))))) 456.107 -
457.1 --- a/src/clojure/repl.clj Sat Aug 21 06:25:44 2010 -0400 457.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 457.3 @@ -1,74 +0,0 @@ 457.4 -; Copyright (c) Chris Houser, Dec 2008. All rights reserved. 457.5 -; The use and distribution terms for this software are covered by the 457.6 -; Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 457.7 -; which can be found in the file CPL.TXT at the root of this distribution. 457.8 -; By using this software in any fashion, you are agreeing to be bound by 457.9 -; the terms of this license. 457.10 -; You must not remove this notice, or any other, from this software. 457.11 - 457.12 -; Utilities meant to be used interactively at the REPL 457.13 - 457.14 -(ns 457.15 - #^{:author "Chris Houser, Christophe Grand, Stephen Gilardi, Michel Salim, Christophe Grande" 457.16 - :doc "Utilities meant to be used interactively at the REPL"} 457.17 - clojure.repl 457.18 - (:import (java.io LineNumberReader InputStreamReader PushbackReader) 457.19 - (clojure.lang RT Reflector))) 457.20 - 457.21 -;; ---------------------------------------------------------------------- 457.22 -;; Examine Clojure functions (Vars, really) 457.23 - 457.24 -(defn source-fn 457.25 - "Returns a string of the source code for the given symbol, if it can 457.26 - find it. This requires that the symbol resolve to a Var defined in 457.27 - a namespace for which the .clj is in the classpath. Returns nil if 457.28 - it can't find the source. For most REPL usage, 'source' is more 457.29 - convenient. 457.30 - 457.31 - Example: (source-fn 'filter)" 457.32 - [x] 457.33 - (when-let [v (resolve x)] 457.34 - (when-let [filepath (:file (meta v))] 457.35 - (when-let [strm (.getResourceAsStream (RT/baseLoader) filepath)] 457.36 - (with-open [rdr (LineNumberReader. (InputStreamReader. strm))] 457.37 - (dotimes [_ (dec (:line (meta v)))] (.readLine rdr)) 457.38 - (let [text (StringBuilder.) 457.39 - pbr (proxy [PushbackReader] [rdr] 457.40 - (read [] (let [i (proxy-super read)] 457.41 - (.append text (char i)) 457.42 - i)))] 457.43 - (read (PushbackReader. pbr)) 457.44 - (str text))))))) 457.45 - 457.46 -(defmacro source 457.47 - "Prints the source code for the given symbol, if it can find it. 457.48 - This requires that the symbol resolve to a Var defined in a 457.49 - namespace for which the .clj is in the classpath. 457.50 - 457.51 - Example: (source filter)" 457.52 - [n] 457.53 - `(println (or (source-fn '~n) (str "Source not found")))) 457.54 - 457.55 -(defn apropos 457.56 - "Given a regular expression or stringable thing, return a seq of 457.57 -all definitions in all currently-loaded namespaces that match the 457.58 -str-or-pattern." 457.59 - [str-or-pattern] 457.60 - (let [matches? (if (instance? java.util.regex.Pattern str-or-pattern) 457.61 - #(re-find str-or-pattern (str %)) 457.62 - #(.contains (str %) (str str-or-pattern)))] 457.63 - (mapcat (fn [ns] 457.64 - (filter matches? (keys (ns-publics ns)))) 457.65 - (all-ns)))) 457.66 - 457.67 -(defn dir-fn 457.68 - "Returns a sorted seq of symbols naming public vars in 457.69 - a namespace" 457.70 - [ns] 457.71 - (sort (map first (ns-publics (the-ns ns))))) 457.72 - 457.73 -(defmacro dir 457.74 - "Prints a sorted directory of public vars in a namespace" 457.75 - [nsname] 457.76 - `(doseq [v# (dir-fn '~nsname)] 457.77 - (println v#)))
458.1 --- a/src/clojure/set.clj Sat Aug 21 06:25:44 2010 -0400 458.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 458.3 @@ -1,177 +0,0 @@ 458.4 -; Copyright (c) Rich Hickey. All rights reserved. 458.5 -; The use and distribution terms for this software are covered by the 458.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 458.7 -; which can be found in the file epl-v10.html at the root of this distribution. 458.8 -; By using this software in any fashion, you are agreeing to be bound by 458.9 -; the terms of this license. 458.10 -; You must not remove this notice, or any other, from this software. 458.11 - 458.12 -(ns ^{:doc "Set operations such as union/intersection." 458.13 - :author "Rich Hickey"} 458.14 - clojure.set) 458.15 - 458.16 -(defn- bubble-max-key [k coll] 458.17 - "Move a maximal element of coll according to fn k (which returns a number) 458.18 - to the front of coll." 458.19 - (let [max (apply max-key k coll)] 458.20 - (cons max (remove #(identical? max %) coll)))) 458.21 - 458.22 -(defn union 458.23 - "Return a set that is the union of the input sets" 458.24 - {:added "1.0"} 458.25 - ([] #{}) 458.26 - ([s1] s1) 458.27 - ([s1 s2] 458.28 - (if (< (count s1) (count s2)) 458.29 - (reduce conj s2 s1) 458.30 - (reduce conj s1 s2))) 458.31 - ([s1 s2 & sets] 458.32 - (let [bubbled-sets (bubble-max-key count (conj sets s2 s1))] 458.33 - (reduce into (first bubbled-sets) (rest bubbled-sets))))) 458.34 - 458.35 -(defn intersection 458.36 - "Return a set that is the intersection of the input sets" 458.37 - {:added "1.0"} 458.38 - ([s1] s1) 458.39 - ([s1 s2] 458.40 - (if (< (count s2) (count s1)) 458.41 - (recur s2 s1) 458.42 - (reduce (fn [result item] 458.43 - (if (contains? s2 item) 458.44 - result 458.45 - (disj result item))) 458.46 - s1 s1))) 458.47 - ([s1 s2 & sets] 458.48 - (let [bubbled-sets (bubble-max-key #(- (count %)) (conj sets s2 s1))] 458.49 - (reduce intersection (first bubbled-sets) (rest bubbled-sets))))) 458.50 - 458.51 -(defn difference 458.52 - "Return a set that is the first set without elements of the remaining sets" 458.53 - {:added "1.0"} 458.54 - ([s1] s1) 458.55 - ([s1 s2] 458.56 - (if (< (count s1) (count s2)) 458.57 - (reduce (fn [result item] 458.58 - (if (contains? s2 item) 458.59 - (disj result item) 458.60 - result)) 458.61 - s1 s1) 458.62 - (reduce disj s1 s2))) 458.63 - ([s1 s2 & sets] 458.64 - (reduce difference s1 (conj sets s2)))) 458.65 - 458.66 - 458.67 -(defn select 458.68 - "Returns a set of the elements for which pred is true" 458.69 - {:added "1.0"} 458.70 - [pred xset] 458.71 - (reduce (fn [s k] (if (pred k) s (disj s k))) 458.72 - xset xset)) 458.73 - 458.74 -(defn project 458.75 - "Returns a rel of the elements of xrel with only the keys in ks" 458.76 - {:added "1.0"} 458.77 - [xrel ks] 458.78 - (set (map #(select-keys % ks) xrel))) 458.79 - 458.80 -(defn rename-keys 458.81 - "Returns the map with the keys in kmap renamed to the vals in kmap" 458.82 - {:added "1.0"} 458.83 - [map kmap] 458.84 - (reduce 458.85 - (fn [m [old new]] 458.86 - (if (and (not= old new) 458.87 - (contains? m old)) 458.88 - (-> m (assoc new (get m old)) (dissoc old)) 458.89 - m)) 458.90 - map kmap)) 458.91 - 458.92 -(defn rename 458.93 - "Returns a rel of the maps in xrel with the keys in kmap renamed to the vals in kmap" 458.94 - {:added "1.0"} 458.95 - [xrel kmap] 458.96 - (set (map #(rename-keys % kmap) xrel))) 458.97 - 458.98 -(defn index 458.99 - "Returns a map of the distinct values of ks in the xrel mapped to a 458.100 - set of the maps in xrel with the corresponding values of ks." 458.101 - {:added "1.0"} 458.102 - [xrel ks] 458.103 - (reduce 458.104 - (fn [m x] 458.105 - (let [ik (select-keys x ks)] 458.106 - (assoc m ik (conj (get m ik #{}) x)))) 458.107 - {} xrel)) 458.108 - 458.109 -(defn map-invert 458.110 - "Returns the map with the vals mapped to the keys." 458.111 - {:added "1.0"} 458.112 - [m] (reduce (fn [m [k v]] (assoc m v k)) {} m)) 458.113 - 458.114 -(defn join 458.115 - "When passed 2 rels, returns the rel corresponding to the natural 458.116 - join. When passed an additional keymap, joins on the corresponding 458.117 - keys." 458.118 - {:added "1.0"} 458.119 - ([xrel yrel] ;natural join 458.120 - (if (and (seq xrel) (seq yrel)) 458.121 - (let [ks (intersection (set (keys (first xrel))) (set (keys (first yrel)))) 458.122 - [r s] (if (<= (count xrel) (count yrel)) 458.123 - [xrel yrel] 458.124 - [yrel xrel]) 458.125 - idx (index r ks)] 458.126 - (reduce (fn [ret x] 458.127 - (let [found (idx (select-keys x ks))] 458.128 - (if found 458.129 - (reduce #(conj %1 (merge %2 x)) ret found) 458.130 - ret))) 458.131 - #{} s)) 458.132 - #{})) 458.133 - ([xrel yrel km] ;arbitrary key mapping 458.134 - (let [[r s k] (if (<= (count xrel) (count yrel)) 458.135 - [xrel yrel (map-invert km)] 458.136 - [yrel xrel km]) 458.137 - idx (index r (vals k))] 458.138 - (reduce (fn [ret x] 458.139 - (let [found (idx (rename-keys (select-keys x (keys k)) k))] 458.140 - (if found 458.141 - (reduce #(conj %1 (merge %2 x)) ret found) 458.142 - ret))) 458.143 - #{} s)))) 458.144 - 458.145 -(defn subset? 458.146 - "Is set1 a subset of set2?" 458.147 - {:added "1.2", 458.148 - :tag Boolean} 458.149 - [set1 set2] 458.150 - (and (<= (count set1) (count set2)) 458.151 - (every? set2 set1))) 458.152 - 458.153 -(defn superset? 458.154 - "Is set1 a superset of set2?" 458.155 - {:added "1.2", 458.156 - :tag Boolean} 458.157 - [set1 set2] 458.158 - (and (>= (count set1) (count set2)) 458.159 - (every? set1 set2))) 458.160 - 458.161 -(comment 458.162 -(refer 'set) 458.163 -(def xs #{{:a 11 :b 1 :c 1 :d 4} 458.164 - {:a 2 :b 12 :c 2 :d 6} 458.165 - {:a 3 :b 3 :c 3 :d 8 :f 42}}) 458.166 - 458.167 -(def ys #{{:a 11 :b 11 :c 11 :e 5} 458.168 - {:a 12 :b 11 :c 12 :e 3} 458.169 - {:a 3 :b 3 :c 3 :e 7 }}) 458.170 - 458.171 -(join xs ys) 458.172 -(join xs (rename ys {:b :yb :c :yc}) {:a :a}) 458.173 - 458.174 -(union #{:a :b :c} #{:c :d :e }) 458.175 -(difference #{:a :b :c} #{:c :d :e}) 458.176 -(intersection #{:a :b :c} #{:c :d :e}) 458.177 - 458.178 -(index ys [:b]) 458.179 -) 458.180 -
459.1 --- a/src/clojure/stacktrace.clj Sat Aug 21 06:25:44 2010 -0400 459.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 459.3 @@ -1,79 +0,0 @@ 459.4 -; Copyright (c) Rich Hickey. All rights reserved. 459.5 -; The use and distribution terms for this software are covered by the 459.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 459.7 -; which can be found in the file epl-v10.html at the root of this distribution. 459.8 -; By using this software in any fashion, you are agreeing to be bound by 459.9 -; the terms of this license. 459.10 -; You must not remove this notice, or any other, from this software. 459.11 - 459.12 -;;; stacktrace.clj: print Clojure-centric stack traces 459.13 - 459.14 -;; by Stuart Sierra 459.15 -;; January 6, 2009 459.16 - 459.17 -(ns ^{:doc "Print stack traces oriented towards Clojure, not Java." 459.18 - :author "Stuart Sierra"} 459.19 - clojure.stacktrace) 459.20 - 459.21 -(defn root-cause 459.22 - "Returns the last 'cause' Throwable in a chain of Throwables." 459.23 - {:added "1.1"} 459.24 - [tr] 459.25 - (if-let [cause (.getCause tr)] 459.26 - (recur cause) 459.27 - tr)) 459.28 - 459.29 -(defn print-trace-element 459.30 - "Prints a Clojure-oriented view of one element in a stack trace." 459.31 - {:added "1.1"} 459.32 - [e] 459.33 - (let [class (.getClassName e) 459.34 - method (.getMethodName e)] 459.35 - (let [match (re-matches #"^([A-Za-z0-9_.-]+)\$(\w+)__\d+$" class)] 459.36 - (if (and match (= "invoke" method)) 459.37 - (apply printf "%s/%s" (rest match)) 459.38 - (printf "%s.%s" class method)))) 459.39 - (printf " (%s:%d)" (or (.getFileName e) "") (.getLineNumber e))) 459.40 - 459.41 -(defn print-throwable 459.42 - "Prints the class and message of a Throwable." 459.43 - {:added "1.1"} 459.44 - [tr] 459.45 - (printf "%s: %s" (.getName (class tr)) (.getMessage tr))) 459.46 - 459.47 -(defn print-stack-trace 459.48 - "Prints a Clojure-oriented stack trace of tr, a Throwable. 459.49 - Prints a maximum of n stack frames (default: unlimited). 459.50 - Does not print chained exceptions (causes)." 459.51 - {:added "1.1"} 459.52 - ([tr] (print-stack-trace tr nil)) 459.53 - ([tr n] 459.54 - (let [st (.getStackTrace tr)] 459.55 - (print-throwable tr) 459.56 - (newline) 459.57 - (print " at ") 459.58 - (print-trace-element (first st)) 459.59 - (newline) 459.60 - (doseq [e (if (nil? n) 459.61 - (rest st) 459.62 - (take (dec n) (rest st)))] 459.63 - (print " ") 459.64 - (print-trace-element e) 459.65 - (newline))))) 459.66 - 459.67 -(defn print-cause-trace 459.68 - "Like print-stack-trace but prints chained exceptions (causes)." 459.69 - {:added "1.1"} 459.70 - ([tr] (print-cause-trace tr nil)) 459.71 - ([tr n] 459.72 - (print-stack-trace tr n) 459.73 - (when-let [cause (.getCause tr)] 459.74 - (print "Caused by: " ) 459.75 - (recur cause n)))) 459.76 - 459.77 -(defn e 459.78 - "REPL utility. Prints a brief stack trace for the root cause of the 459.79 - most recent exception." 459.80 - {:added "1.1"} 459.81 - [] 459.82 - (print-stack-trace (root-cause *e) 8))
460.1 --- a/src/clojure/string.clj Sat Aug 21 06:25:44 2010 -0400 460.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 460.3 @@ -1,254 +0,0 @@ 460.4 -; Copyright (c) Rich Hickey. All rights reserved. 460.5 -; The use and distribution terms for this software are covered by the 460.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 460.7 -; which can be found in the file epl-v10.html at the root of this distribution. 460.8 -; By using this software in any fashion, you are agreeing to be bound by 460.9 -; the terms of this license. 460.10 -; You must not remove this notice, or any other, from this software. 460.11 - 460.12 -(ns ^{:doc "Clojure String utilities 460.13 - 460.14 -It is poor form to (:use clojure.string). Instead, use require 460.15 -with :as to specify a prefix, e.g. 460.16 - 460.17 -(ns your.namespace.here 460.18 - (:require '[clojure.string :as str])) 460.19 - 460.20 -Design notes for clojure.string: 460.21 - 460.22 -1. Strings are objects (as opposed to sequences). As such, the 460.23 - string being manipulated is the first argument to a function; 460.24 - passing nil will result in a NullPointerException unless 460.25 - documented otherwise. If you want sequence-y behavior instead, 460.26 - use a sequence. 460.27 - 460.28 -2. Functions are generally not lazy, and call straight to host 460.29 - methods where those are available and efficient. 460.30 - 460.31 -3. Functions take advantage of String implementation details to 460.32 - write high-performing loop/recurs instead of using higher-order 460.33 - functions. (This is not idiomatic in general-purpose application 460.34 - code.) 460.35 - 460.36 -4. When a function is documented to accept a string argument, it 460.37 - will take any implementation of the correct *interface* on the 460.38 - host platform. In Java, this is CharSequence, which is more 460.39 - general than String. In ordinary usage you will almost always 460.40 - pass concrete strings. If you are doing something unusual, 460.41 - e.g. passing a mutable implementation of CharSequence, then 460.42 - thead-safety is your responsibility." 460.43 - :author "Stuart Sierra, Stuart Halloway, David Liebke"} 460.44 - clojure.string 460.45 - (:refer-clojure :exclude (replace reverse)) 460.46 - (:import (java.util.regex Pattern) 460.47 - clojure.lang.LazilyPersistentVector)) 460.48 - 460.49 -(defn ^String reverse 460.50 - "Returns s with its characters reversed." 460.51 - {:added "1.2"} 460.52 - [^CharSequence s] 460.53 - (.toString (.reverse (StringBuilder. s)))) 460.54 - 460.55 -(defn- replace-by 460.56 - [^CharSequence s re f] 460.57 - (let [m (re-matcher re s)] 460.58 - (let [buffer (StringBuffer. (.length s))] 460.59 - (loop [] 460.60 - (if (.find m) 460.61 - (do (.appendReplacement m buffer (f (re-groups m))) 460.62 - (recur)) 460.63 - (do (.appendTail m buffer) 460.64 - (.toString buffer))))))) 460.65 - 460.66 -(defn ^String replace 460.67 - "Replaces all instance of match with replacement in s. 460.68 - 460.69 - match/replacement can be: 460.70 - 460.71 - string / string 460.72 - char / char 460.73 - pattern / (string or function of match). 460.74 - 460.75 - See also replace-first." 460.76 - {:added "1.2"} 460.77 - [^CharSequence s match replacement] 460.78 - (let [s (.toString s)] 460.79 - (cond 460.80 - (instance? Character match) (.replace s ^Character match ^Character replacement) 460.81 - (instance? CharSequence match) (.replace s ^CharSequence match ^CharSequence replacement) 460.82 - (instance? Pattern match) (if (instance? CharSequence replacement) 460.83 - (.replaceAll (re-matcher ^Pattern match s) 460.84 - (.toString ^CharSequence replacement)) 460.85 - (replace-by s match replacement)) 460.86 - :else (throw (IllegalArgumentException. (str "Invalid match arg: " match)))))) 460.87 - 460.88 -(defn- replace-first-by 460.89 - [^CharSequence s ^Pattern re f] 460.90 - (let [m (re-matcher re s)] 460.91 - (let [buffer (StringBuffer. (.length s))] 460.92 - (if (.find m) 460.93 - (let [rep (f (re-groups m))] 460.94 - (.appendReplacement m buffer rep) 460.95 - (.appendTail m buffer) 460.96 - (str buffer)))))) 460.97 - 460.98 -(defn- replace-first-char 460.99 - [^CharSequence s ^Character match replace] 460.100 - (let [s (.toString s) 460.101 - i (.indexOf s (int match))] 460.102 - (if (= -1 i) 460.103 - s 460.104 - (str (subs s 0 i) replace (subs s (inc i)))))) 460.105 - 460.106 -(defn ^String replace-first 460.107 - "Replaces the first instance of match with replacement in s. 460.108 - 460.109 - match/replacement can be: 460.110 - 460.111 - char / char 460.112 - string / string 460.113 - pattern / (string or function of match). 460.114 - 460.115 - See also replace-all." 460.116 - {:added "1.2"} 460.117 - [^CharSequence s match replacement] 460.118 - (let [s (.toString s)] 460.119 - (cond 460.120 - (instance? Character match) 460.121 - (replace-first-char s match replacement) 460.122 - (instance? CharSequence match) 460.123 - (.replaceFirst s (Pattern/quote (.toString ^CharSequence match)) 460.124 - (.toString ^CharSequence replacement)) 460.125 - (instance? Pattern match) 460.126 - (if (instance? CharSequence replacement) 460.127 - (.replaceFirst (re-matcher ^Pattern match s) 460.128 - (.toString ^CharSequence replacement)) 460.129 - (replace-first-by s match replacement)) 460.130 - :else (throw (IllegalArgumentException. (str "Invalid match arg: " match)))))) 460.131 - 460.132 - 460.133 -(defn ^String join 460.134 - "Returns a string of all elements in coll, separated by 460.135 - an optional separator. Like Perl's join." 460.136 - {:added "1.2"} 460.137 - ([coll] 460.138 - (apply str coll)) 460.139 - ([separator [x & more]] 460.140 - (loop [sb (StringBuilder. (str x)) 460.141 - more more 460.142 - sep (str separator)] 460.143 - (if more 460.144 - (recur (-> sb (.append sep) (.append (str (first more)))) 460.145 - (next more) 460.146 - sep) 460.147 - (str sb))))) 460.148 - 460.149 -(defn ^String capitalize 460.150 - "Converts first character of the string to upper-case, all other 460.151 - characters to lower-case." 460.152 - {:added "1.2"} 460.153 - [^CharSequence s] 460.154 - (let [s (.toString s)] 460.155 - (if (< (count s) 2) 460.156 - (.toUpperCase s) 460.157 - (str (.toUpperCase (subs s 0 1)) 460.158 - (.toLowerCase (subs s 1)))))) 460.159 - 460.160 -(defn ^String upper-case 460.161 - "Converts string to all upper-case." 460.162 - {:added "1.2"} 460.163 - [^CharSequence s] 460.164 - (.. s toString toUpperCase)) 460.165 - 460.166 -(defn ^String lower-case 460.167 - "Converts string to all lower-case." 460.168 - {:added "1.2"} 460.169 - [^CharSequence s] 460.170 - (.. s toString toLowerCase)) 460.171 - 460.172 -(defn split 460.173 - "Splits string on a regular expression. Optional argument limit is 460.174 - the maximum number of splits. Not lazy. Returns vector of the splits." 460.175 - {:added "1.2"} 460.176 - ([^CharSequence s ^Pattern re] 460.177 - (LazilyPersistentVector/createOwning (.split re s))) 460.178 - ([ ^CharSequence s ^Pattern re limit] 460.179 - (LazilyPersistentVector/createOwning (.split re s limit)))) 460.180 - 460.181 -(defn split-lines 460.182 - "Splits s on \\n or \\r\\n." 460.183 - {:added "1.2"} 460.184 - [^CharSequence s] 460.185 - (split s #"\r?\n")) 460.186 - 460.187 -(defn ^String trim 460.188 - "Removes whitespace from both ends of string." 460.189 - {:added "1.2"} 460.190 - [^CharSequence s] 460.191 - (.. s toString trim)) 460.192 - 460.193 -(defn ^String triml 460.194 - "Removes whitespace from the left side of string." 460.195 - {:added "1.2"} 460.196 - [^CharSequence s] 460.197 - (loop [index (int 0)] 460.198 - (if (= (.length s) index) 460.199 - "" 460.200 - (if (Character/isWhitespace (.charAt s index)) 460.201 - (recur (inc index)) 460.202 - (.. s (subSequence index (.length s)) toString))))) 460.203 - 460.204 -(defn ^String trimr 460.205 - "Removes whitespace from the right side of string." 460.206 - {:added "1.2"} 460.207 - [^CharSequence s] 460.208 - (loop [index (.length s)] 460.209 - (if (zero? index) 460.210 - "" 460.211 - (if (Character/isWhitespace (.charAt s (dec index))) 460.212 - (recur (dec index)) 460.213 - (.. s (subSequence 0 index) toString))))) 460.214 - 460.215 -(defn ^String trim-newline 460.216 - "Removes all trailing newline \\n or return \\r characters from 460.217 - string. Similar to Perl's chomp." 460.218 - {:added "1.2"} 460.219 - [^CharSequence s] 460.220 - (loop [index (.length s)] 460.221 - (if (zero? index) 460.222 - "" 460.223 - (let [ch (.charAt s (dec index))] 460.224 - (if (or (= ch \newline) (= ch \return)) 460.225 - (recur (dec index)) 460.226 - (.. s (subSequence 0 index) toString)))))) 460.227 - 460.228 -(defn blank? 460.229 - "True if s is nil, empty, or contains only whitespace." 460.230 - {:added "1.2"} 460.231 - [^CharSequence s] 460.232 - (if s 460.233 - (loop [index (int 0)] 460.234 - (if (= (.length s) index) 460.235 - true 460.236 - (if (Character/isWhitespace (.charAt s index)) 460.237 - (recur (inc index)) 460.238 - false))) 460.239 - true)) 460.240 - 460.241 -(defn ^String escape 460.242 - "Return a new string, using cmap to escape each character ch 460.243 - from s as follows: 460.244 - 460.245 - If (cmap ch) is nil, append ch to the new string. 460.246 - If (cmap ch) is non-nil, append (str (cmap ch)) instead." 460.247 - {:added "1.2"} 460.248 - [^CharSequence s cmap] 460.249 - (loop [index (int 0) 460.250 - buffer (StringBuilder. (.length s))] 460.251 - (if (= (.length s) index) 460.252 - (.toString buffer) 460.253 - (let [ch (.charAt s index)] 460.254 - (if-let [replacement (cmap ch)] 460.255 - (.append buffer replacement) 460.256 - (.append buffer ch)) 460.257 - (recur (inc index) buffer)))))
461.1 --- a/src/clojure/template.clj Sat Aug 21 06:25:44 2010 -0400 461.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 461.3 @@ -1,55 +0,0 @@ 461.4 -; Copyright (c) Rich Hickey. All rights reserved. 461.5 -; The use and distribution terms for this software are covered by the 461.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 461.7 -; which can be found in the file epl-v10.html at the root of this distribution. 461.8 -; By using this software in any fashion, you are agreeing to be bound by 461.9 -; the terms of this license. 461.10 -; You must not remove this notice, or any other, from this software. 461.11 - 461.12 -;;; template.clj - anonymous functions that pre-evaluate sub-expressions 461.13 - 461.14 -;; By Stuart Sierra 461.15 -;; June 23, 2009 461.16 - 461.17 -;; CHANGE LOG 461.18 -;; 461.19 -;; June 23, 2009: complete rewrite, eliminated _1,_2,... argument 461.20 -;; syntax 461.21 -;; 461.22 -;; January 20, 2009: added "template?" and checks for valid template 461.23 -;; expressions. 461.24 -;; 461.25 -;; December 15, 2008: first version 461.26 - 461.27 - 461.28 -(ns ^{:doc "Macros that expand to repeated copies of a template expression." 461.29 - :author "Stuart Sierra"} 461.30 - clojure.template 461.31 - (:require [clojure.walk :as walk])) 461.32 - 461.33 -(defn apply-template 461.34 - "For use in macros. argv is an argument list, as in defn. expr is 461.35 - a quoted expression using the symbols in argv. values is a sequence 461.36 - of values to be used for the arguments. 461.37 - 461.38 - apply-template will recursively replace argument symbols in expr 461.39 - with their corresponding values, returning a modified expr. 461.40 - 461.41 - Example: (apply-template '[x] '(+ x x) '[2]) 461.42 - ;=> (+ 2 2)" 461.43 - [argv expr values] 461.44 - (assert (vector? argv)) 461.45 - (assert (every? symbol? argv)) 461.46 - (walk/prewalk-replace (zipmap argv values) expr)) 461.47 - 461.48 -(defmacro do-template 461.49 - "Repeatedly copies expr (in a do block) for each group of arguments 461.50 - in values. values are automatically partitioned by the number of 461.51 - arguments in argv, an argument vector as in defn. 461.52 - 461.53 - Example: (macroexpand '(do-template [x y] (+ y x) 2 4 3 5)) 461.54 - ;=> (do (+ 4 2) (+ 5 3))" 461.55 - [argv expr & values] 461.56 - (let [c (count argv)] 461.57 - `(do ~@(map (fn [a] (apply-template argv expr a)) 461.58 - (partition c values)))))
462.1 --- a/src/clojure/test.clj Sat Aug 21 06:25:44 2010 -0400 462.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 462.3 @@ -1,758 +0,0 @@ 462.4 -; Copyright (c) Rich Hickey. All rights reserved. 462.5 -; The use and distribution terms for this software are covered by the 462.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 462.7 -; which can be found in the file epl-v10.html at the root of this distribution. 462.8 -; By using this software in any fashion, you are agreeing to be bound by 462.9 -; the terms of this license. 462.10 -; You must not remove this notice, or any other, from this software. 462.11 - 462.12 -;;; test.clj: test framework for Clojure 462.13 - 462.14 -;; by Stuart Sierra 462.15 -;; March 28, 2009 462.16 - 462.17 -;; Thanks to Chas Emerick, Allen Rohner, and Stuart Halloway for 462.18 -;; contributions and suggestions. 462.19 - 462.20 -(ns 462.21 - ^{:author "Stuart Sierra, with contributions and suggestions by 462.22 - Chas Emerick, Allen Rohner, and Stuart Halloway", 462.23 - :doc "A unit testing framework. 462.24 - 462.25 - ASSERTIONS 462.26 - 462.27 - The core of the library is the \"is\" macro, which lets you make 462.28 - assertions of any arbitrary expression: 462.29 - 462.30 - (is (= 4 (+ 2 2))) 462.31 - (is (instance? Integer 256)) 462.32 - (is (.startsWith \"abcde\" \"ab\")) 462.33 - 462.34 - You can type an \"is\" expression directly at the REPL, which will 462.35 - print a message if it fails. 462.36 - 462.37 - user> (is (= 5 (+ 2 2))) 462.38 - 462.39 - FAIL in (:1) 462.40 - expected: (= 5 (+ 2 2)) 462.41 - actual: (not (= 5 4)) 462.42 - false 462.43 - 462.44 - The \"expected:\" line shows you the original expression, and the 462.45 - \"actual:\" shows you what actually happened. In this case, it 462.46 - shows that (+ 2 2) returned 4, which is not = to 5. Finally, the 462.47 - \"false\" on the last line is the value returned from the 462.48 - expression. The \"is\" macro always returns the result of the 462.49 - inner expression. 462.50 - 462.51 - There are two special assertions for testing exceptions. The 462.52 - \"(is (thrown? c ...))\" form tests if an exception of class c is 462.53 - thrown: 462.54 - 462.55 - (is (thrown? ArithmeticException (/ 1 0))) 462.56 - 462.57 - \"(is (thrown-with-msg? c re ...))\" does the same thing and also 462.58 - tests that the message on the exception matches the regular 462.59 - expression re: 462.60 - 462.61 - (is (thrown-with-msg? ArithmeticException #\"Divide by zero\" 462.62 - (/ 1 0))) 462.63 - 462.64 - DOCUMENTING TESTS 462.65 - 462.66 - \"is\" takes an optional second argument, a string describing the 462.67 - assertion. This message will be included in the error report. 462.68 - 462.69 - (is (= 5 (+ 2 2)) \"Crazy arithmetic\") 462.70 - 462.71 - In addition, you can document groups of assertions with the 462.72 - \"testing\" macro, which takes a string followed by any number of 462.73 - assertions. The string will be included in failure reports. 462.74 - Calls to \"testing\" may be nested, and all of the strings will be 462.75 - joined together with spaces in the final report, in a style 462.76 - similar to RSpec <http://rspec.info/> 462.77 - 462.78 - (testing \"Arithmetic\" 462.79 - (testing \"with positive integers\" 462.80 - (is (= 4 (+ 2 2))) 462.81 - (is (= 7 (+ 3 4)))) 462.82 - (testing \"with negative integers\" 462.83 - (is (= -4 (+ -2 -2))) 462.84 - (is (= -1 (+ 3 -4))))) 462.85 - 462.86 - Note that, unlike RSpec, the \"testing\" macro may only be used 462.87 - INSIDE a \"deftest\" or \"with-test\" form (see below). 462.88 - 462.89 - 462.90 - DEFINING TESTS 462.91 - 462.92 - There are two ways to define tests. The \"with-test\" macro takes 462.93 - a defn or def form as its first argument, followed by any number 462.94 - of assertions. The tests will be stored as metadata on the 462.95 - definition. 462.96 - 462.97 - (with-test 462.98 - (defn my-function [x y] 462.99 - (+ x y)) 462.100 - (is (= 4 (my-function 2 2))) 462.101 - (is (= 7 (my-function 3 4)))) 462.102 - 462.103 - As of Clojure SVN rev. 1221, this does not work with defmacro. 462.104 - See http://code.google.com/p/clojure/issues/detail?id=51 462.105 - 462.106 - The other way lets you define tests separately from the rest of 462.107 - your code, even in a different namespace: 462.108 - 462.109 - (deftest addition 462.110 - (is (= 4 (+ 2 2))) 462.111 - (is (= 7 (+ 3 4)))) 462.112 - 462.113 - (deftest subtraction 462.114 - (is (= 1 (- 4 3))) 462.115 - (is (= 3 (- 7 4)))) 462.116 - 462.117 - This creates functions named \"addition\" and \"subtraction\", which 462.118 - can be called like any other function. Therefore, tests can be 462.119 - grouped and composed, in a style similar to the test framework in 462.120 - Peter Seibel's \"Practical Common Lisp\" 462.121 - <http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html> 462.122 - 462.123 - (deftest arithmetic 462.124 - (addition) 462.125 - (subtraction)) 462.126 - 462.127 - The names of the nested tests will be joined in a list, like 462.128 - \"(arithmetic addition)\", in failure reports. You can use nested 462.129 - tests to set up a context shared by several tests. 462.130 - 462.131 - 462.132 - RUNNING TESTS 462.133 - 462.134 - Run tests with the function \"(run-tests namespaces...)\": 462.135 - 462.136 - (run-tests 'your.namespace 'some.other.namespace) 462.137 - 462.138 - If you don't specify any namespaces, the current namespace is 462.139 - used. To run all tests in all namespaces, use \"(run-all-tests)\". 462.140 - 462.141 - By default, these functions will search for all tests defined in 462.142 - a namespace and run them in an undefined order. However, if you 462.143 - are composing tests, as in the \"arithmetic\" example above, you 462.144 - probably do not want the \"addition\" and \"subtraction\" tests run 462.145 - separately. In that case, you must define a special function 462.146 - named \"test-ns-hook\" that runs your tests in the correct order: 462.147 - 462.148 - (defn test-ns-hook [] 462.149 - (arithmetic)) 462.150 - 462.151 - 462.152 - OMITTING TESTS FROM PRODUCTION CODE 462.153 - 462.154 - You can bind the variable \"*load-tests*\" to false when loading or 462.155 - compiling code in production. This will prevent any tests from 462.156 - being created by \"with-test\" or \"deftest\". 462.157 - 462.158 - 462.159 - FIXTURES (new) 462.160 - 462.161 - Fixtures allow you to run code before and after tests, to set up 462.162 - the context in which tests should be run. 462.163 - 462.164 - A fixture is just a function that calls another function passed as 462.165 - an argument. It looks like this: 462.166 - 462.167 - (defn my-fixture [f] 462.168 - Perform setup, establish bindings, whatever. 462.169 - (f) Then call the function we were passed. 462.170 - Tear-down / clean-up code here. 462.171 - ) 462.172 - 462.173 - Fixtures are attached to namespaces in one of two ways. \"each\" 462.174 - fixtures are run repeatedly, once for each test function created 462.175 - with \"deftest\" or \"with-test\". \"each\" fixtures are useful for 462.176 - establishing a consistent before/after state for each test, like 462.177 - clearing out database tables. 462.178 - 462.179 - \"each\" fixtures can be attached to the current namespace like this: 462.180 - (use-fixtures :each fixture1 fixture2 ...) 462.181 - The fixture1, fixture2 are just functions like the example above. 462.182 - They can also be anonymous functions, like this: 462.183 - (use-fixtures :each (fn [f] setup... (f) cleanup...)) 462.184 - 462.185 - The other kind of fixture, a \"once\" fixture, is only run once, 462.186 - around ALL the tests in the namespace. \"once\" fixtures are useful 462.187 - for tasks that only need to be performed once, like establishing 462.188 - database connections, or for time-consuming tasks. 462.189 - 462.190 - Attach \"once\" fixtures to the current namespace like this: 462.191 - (use-fixtures :once fixture1 fixture2 ...) 462.192 - 462.193 - 462.194 - SAVING TEST OUTPUT TO A FILE 462.195 - 462.196 - All the test reporting functions write to the var *test-out*. By 462.197 - default, this is the same as *out*, but you can rebind it to any 462.198 - PrintWriter. For example, it could be a file opened with 462.199 - clojure.java.io/writer. 462.200 - 462.201 - 462.202 - EXTENDING TEST-IS (ADVANCED) 462.203 - 462.204 - You can extend the behavior of the \"is\" macro by defining new 462.205 - methods for the \"assert-expr\" multimethod. These methods are 462.206 - called during expansion of the \"is\" macro, so they should return 462.207 - quoted forms to be evaluated. 462.208 - 462.209 - You can plug in your own test-reporting framework by rebinding 462.210 - the \"report\" function: (report event) 462.211 - 462.212 - The 'event' argument is a map. It will always have a :type key, 462.213 - whose value will be a keyword signaling the type of event being 462.214 - reported. Standard events with :type value of :pass, :fail, and 462.215 - :error are called when an assertion passes, fails, and throws an 462.216 - exception, respectively. In that case, the event will also have 462.217 - the following keys: 462.218 - 462.219 - :expected The form that was expected to be true 462.220 - :actual A form representing what actually occurred 462.221 - :message The string message given as an argument to 'is' 462.222 - 462.223 - The \"testing\" strings will be a list in \"*testing-contexts*\", and 462.224 - the vars being tested will be a list in \"*testing-vars*\". 462.225 - 462.226 - Your \"report\" function should wrap any printing calls in the 462.227 - \"with-test-out\" macro, which rebinds *out* to the current value 462.228 - of *test-out*. 462.229 - 462.230 - For additional event types, see the examples in the code. 462.231 -"} 462.232 - clojure.test 462.233 - (:require [clojure.template :as temp] 462.234 - [clojure.stacktrace :as stack])) 462.235 - 462.236 -;; Nothing is marked "private" here, so you can rebind things to plug 462.237 -;; in your own testing or reporting frameworks. 462.238 - 462.239 - 462.240 -;;; USER-MODIFIABLE GLOBALS 462.241 - 462.242 -(defonce 462.243 - ^{:doc "True by default. If set to false, no test functions will 462.244 - be created by deftest, set-test, or with-test. Use this to omit 462.245 - tests when compiling or loading production code." 462.246 - :added "1.1"} 462.247 - *load-tests* true) 462.248 - 462.249 -(def 462.250 - ^{:doc "The maximum depth of stack traces to print when an Exception 462.251 - is thrown during a test. Defaults to nil, which means print the 462.252 - complete stack trace." 462.253 - :added "1.1"} 462.254 - *stack-trace-depth* nil) 462.255 - 462.256 - 462.257 -;;; GLOBALS USED BY THE REPORTING FUNCTIONS 462.258 - 462.259 -(def *report-counters* nil) ; bound to a ref of a map in test-ns 462.260 - 462.261 -(def *initial-report-counters* ; used to initialize *report-counters* 462.262 - {:test 0, :pass 0, :fail 0, :error 0}) 462.263 - 462.264 -(def *testing-vars* (list)) ; bound to hierarchy of vars being tested 462.265 - 462.266 -(def *testing-contexts* (list)) ; bound to hierarchy of "testing" strings 462.267 - 462.268 -(def *test-out* *out*) ; PrintWriter for test reporting output 462.269 - 462.270 -(defmacro with-test-out 462.271 - "Runs body with *out* bound to the value of *test-out*." 462.272 - {:added "1.1"} 462.273 - [& body] 462.274 - `(binding [*out* *test-out*] 462.275 - ~@body)) 462.276 - 462.277 -;;; UTILITIES FOR REPORTING FUNCTIONS 462.278 - 462.279 -(defn file-position 462.280 - "Returns a vector [filename line-number] for the nth call up the 462.281 - stack. 462.282 - 462.283 - Deprecated in 1.2: The information needed for test reporting is 462.284 - now on :file and :line keys in the result map." 462.285 - {:added "1.1" 462.286 - :deprecated "1.2"} 462.287 - [n] 462.288 - (let [^StackTraceElement s (nth (.getStackTrace (new java.lang.Throwable)) n)] 462.289 - [(.getFileName s) (.getLineNumber s)])) 462.290 - 462.291 -(defn testing-vars-str 462.292 - "Returns a string representation of the current test. Renders names 462.293 - in *testing-vars* as a list, then the source file and line of 462.294 - current assertion." 462.295 - {:added "1.1"} 462.296 - [m] 462.297 - (let [{:keys [file line]} m] 462.298 - (str 462.299 - ;; Uncomment to include namespace in failure report: 462.300 - ;;(ns-name (:ns (meta (first *testing-vars*)))) "/ " 462.301 - (reverse (map #(:name (meta %)) *testing-vars*)) 462.302 - " (" file ":" line ")"))) 462.303 - 462.304 -(defn testing-contexts-str 462.305 - "Returns a string representation of the current test context. Joins 462.306 - strings in *testing-contexts* with spaces." 462.307 - {:added "1.1"} 462.308 - [] 462.309 - (apply str (interpose " " (reverse *testing-contexts*)))) 462.310 - 462.311 -(defn inc-report-counter 462.312 - "Increments the named counter in *report-counters*, a ref to a map. 462.313 - Does nothing if *report-counters* is nil." 462.314 - {:added "1.1"} 462.315 - [name] 462.316 - (when *report-counters* 462.317 - (dosync (commute *report-counters* assoc name 462.318 - (inc (or (*report-counters* name) 0)))))) 462.319 - 462.320 -;;; TEST RESULT REPORTING 462.321 - 462.322 -(defmulti 462.323 - ^{:doc "Generic reporting function, may be overridden to plug in 462.324 - different report formats (e.g., TAP, JUnit). Assertions such as 462.325 - 'is' call 'report' to indicate results. The argument given to 462.326 - 'report' will be a map with a :type key. See the documentation at 462.327 - the top of test_is.clj for more information on the types of 462.328 - arguments for 'report'." 462.329 - :dynamic true 462.330 - :added "1.1"} 462.331 - report :type) 462.332 - 462.333 -(defn- file-and-line 462.334 - [exception depth] 462.335 - (let [^StackTraceElement s (nth (.getStackTrace exception) depth)] 462.336 - {:file (.getFileName s) :line (.getLineNumber s)})) 462.337 - 462.338 -(defn do-report 462.339 - "Add file and line information to a test result and call report. 462.340 - If you are writing a custom assert-expr method, call this function 462.341 - to pass test results to report." 462.342 - {:added "1.2"} 462.343 - [m] 462.344 - (report 462.345 - (case 462.346 - (:type m) 462.347 - :fail (merge (file-and-line (new java.lang.Throwable) 1) m) 462.348 - :error (merge (file-and-line (:actual m) 0) m) 462.349 - m))) 462.350 - 462.351 -(defmethod report :default [m] 462.352 - (with-test-out (prn m))) 462.353 - 462.354 -(defmethod report :pass [m] 462.355 - (with-test-out (inc-report-counter :pass))) 462.356 - 462.357 -(defmethod report :fail [m] 462.358 - (with-test-out 462.359 - (inc-report-counter :fail) 462.360 - (println "\nFAIL in" (testing-vars-str m)) 462.361 - (when (seq *testing-contexts*) (println (testing-contexts-str))) 462.362 - (when-let [message (:message m)] (println message)) 462.363 - (println "expected:" (pr-str (:expected m))) 462.364 - (println " actual:" (pr-str (:actual m))))) 462.365 - 462.366 -(defmethod report :error [m] 462.367 - (with-test-out 462.368 - (inc-report-counter :error) 462.369 - (println "\nERROR in" (testing-vars-str m)) 462.370 - (when (seq *testing-contexts*) (println (testing-contexts-str))) 462.371 - (when-let [message (:message m)] (println message)) 462.372 - (println "expected:" (pr-str (:expected m))) 462.373 - (print " actual: ") 462.374 - (let [actual (:actual m)] 462.375 - (if (instance? Throwable actual) 462.376 - (stack/print-cause-trace actual *stack-trace-depth*) 462.377 - (prn actual))))) 462.378 - 462.379 -(defmethod report :summary [m] 462.380 - (with-test-out 462.381 - (println "\nRan" (:test m) "tests containing" 462.382 - (+ (:pass m) (:fail m) (:error m)) "assertions.") 462.383 - (println (:fail m) "failures," (:error m) "errors."))) 462.384 - 462.385 -(defmethod report :begin-test-ns [m] 462.386 - (with-test-out 462.387 - (println "\nTesting" (ns-name (:ns m))))) 462.388 - 462.389 -;; Ignore these message types: 462.390 -(defmethod report :end-test-ns [m]) 462.391 -(defmethod report :begin-test-var [m]) 462.392 -(defmethod report :end-test-var [m]) 462.393 - 462.394 - 462.395 - 462.396 -;;; UTILITIES FOR ASSERTIONS 462.397 - 462.398 -(defn get-possibly-unbound-var 462.399 - "Like var-get but returns nil if the var is unbound." 462.400 - {:added "1.1"} 462.401 - [v] 462.402 - (try (var-get v) 462.403 - (catch IllegalStateException e 462.404 - nil))) 462.405 - 462.406 -(defn function? 462.407 - "Returns true if argument is a function or a symbol that resolves to 462.408 - a function (not a macro)." 462.409 - {:added "1.1"} 462.410 - [x] 462.411 - (if (symbol? x) 462.412 - (when-let [v (resolve x)] 462.413 - (when-let [value (get-possibly-unbound-var v)] 462.414 - (and (fn? value) 462.415 - (not (:macro (meta v)))))) 462.416 - (fn? x))) 462.417 - 462.418 -(defn assert-predicate 462.419 - "Returns generic assertion code for any functional predicate. The 462.420 - 'expected' argument to 'report' will contains the original form, the 462.421 - 'actual' argument will contain the form with all its sub-forms 462.422 - evaluated. If the predicate returns false, the 'actual' form will 462.423 - be wrapped in (not...)." 462.424 - {:added "1.1"} 462.425 - [msg form] 462.426 - (let [args (rest form) 462.427 - pred (first form)] 462.428 - `(let [values# (list ~@args) 462.429 - result# (apply ~pred values#)] 462.430 - (if result# 462.431 - (do-report {:type :pass, :message ~msg, 462.432 - :expected '~form, :actual (cons ~pred values#)}) 462.433 - (do-report {:type :fail, :message ~msg, 462.434 - :expected '~form, :actual (list '~'not (cons '~pred values#))})) 462.435 - result#))) 462.436 - 462.437 -(defn assert-any 462.438 - "Returns generic assertion code for any test, including macros, Java 462.439 - method calls, or isolated symbols." 462.440 - {:added "1.1"} 462.441 - [msg form] 462.442 - `(let [value# ~form] 462.443 - (if value# 462.444 - (do-report {:type :pass, :message ~msg, 462.445 - :expected '~form, :actual value#}) 462.446 - (do-report {:type :fail, :message ~msg, 462.447 - :expected '~form, :actual value#})) 462.448 - value#)) 462.449 - 462.450 - 462.451 - 462.452 -;;; ASSERTION METHODS 462.453 - 462.454 -;; You don't call these, but you can add methods to extend the 'is' 462.455 -;; macro. These define different kinds of tests, based on the first 462.456 -;; symbol in the test expression. 462.457 - 462.458 -(defmulti assert-expr 462.459 - (fn [msg form] 462.460 - (cond 462.461 - (nil? form) :always-fail 462.462 - (seq? form) (first form) 462.463 - :else :default))) 462.464 - 462.465 -(defmethod assert-expr :always-fail [msg form] 462.466 - ;; nil test: always fail 462.467 - `(do-report {:type :fail, :message ~msg})) 462.468 - 462.469 -(defmethod assert-expr :default [msg form] 462.470 - (if (and (sequential? form) (function? (first form))) 462.471 - (assert-predicate msg form) 462.472 - (assert-any msg form))) 462.473 - 462.474 -(defmethod assert-expr 'instance? [msg form] 462.475 - ;; Test if x is an instance of y. 462.476 - `(let [klass# ~(nth form 1) 462.477 - object# ~(nth form 2)] 462.478 - (let [result# (instance? klass# object#)] 462.479 - (if result# 462.480 - (do-report {:type :pass, :message ~msg, 462.481 - :expected '~form, :actual (class object#)}) 462.482 - (do-report {:type :fail, :message ~msg, 462.483 - :expected '~form, :actual (class object#)})) 462.484 - result#))) 462.485 - 462.486 -(defmethod assert-expr 'thrown? [msg form] 462.487 - ;; (is (thrown? c expr)) 462.488 - ;; Asserts that evaluating expr throws an exception of class c. 462.489 - ;; Returns the exception thrown. 462.490 - (let [klass (second form) 462.491 - body (nthnext form 2)] 462.492 - `(try ~@body 462.493 - (do-report {:type :fail, :message ~msg, 462.494 - :expected '~form, :actual nil}) 462.495 - (catch ~klass e# 462.496 - (do-report {:type :pass, :message ~msg, 462.497 - :expected '~form, :actual e#}) 462.498 - e#)))) 462.499 - 462.500 -(defmethod assert-expr 'thrown-with-msg? [msg form] 462.501 - ;; (is (thrown-with-msg? c re expr)) 462.502 - ;; Asserts that evaluating expr throws an exception of class c. 462.503 - ;; Also asserts that the message string of the exception matches 462.504 - ;; (with re-find) the regular expression re. 462.505 - (let [klass (nth form 1) 462.506 - re (nth form 2) 462.507 - body (nthnext form 3)] 462.508 - `(try ~@body 462.509 - (do-report {:type :fail, :message ~msg, :expected '~form, :actual nil}) 462.510 - (catch ~klass e# 462.511 - (let [m# (.getMessage e#)] 462.512 - (if (re-find ~re m#) 462.513 - (do-report {:type :pass, :message ~msg, 462.514 - :expected '~form, :actual e#}) 462.515 - (do-report {:type :fail, :message ~msg, 462.516 - :expected '~form, :actual e#}))) 462.517 - e#)))) 462.518 - 462.519 - 462.520 -(defmacro try-expr 462.521 - "Used by the 'is' macro to catch unexpected exceptions. 462.522 - You don't call this." 462.523 - {:added "1.1"} 462.524 - [msg form] 462.525 - `(try ~(assert-expr msg form) 462.526 - (catch Throwable t# 462.527 - (do-report {:type :error, :message ~msg, 462.528 - :expected '~form, :actual t#})))) 462.529 - 462.530 - 462.531 - 462.532 -;;; ASSERTION MACROS 462.533 - 462.534 -;; You use these in your tests. 462.535 - 462.536 -(defmacro is 462.537 - "Generic assertion macro. 'form' is any predicate test. 462.538 - 'msg' is an optional message to attach to the assertion. 462.539 - 462.540 - Example: (is (= 4 (+ 2 2)) \"Two plus two should be 4\") 462.541 - 462.542 - Special forms: 462.543 - 462.544 - (is (thrown? c body)) checks that an instance of c is thrown from 462.545 - body, fails if not; then returns the thing thrown. 462.546 - 462.547 - (is (thrown-with-msg? c re body)) checks that an instance of c is 462.548 - thrown AND that the message on the exception matches (with 462.549 - re-find) the regular expression re." 462.550 - {:added "1.1"} 462.551 - ([form] `(is ~form nil)) 462.552 - ([form msg] `(try-expr ~msg ~form))) 462.553 - 462.554 -(defmacro are 462.555 - "Checks multiple assertions with a template expression. 462.556 - See clojure.template/do-template for an explanation of 462.557 - templates. 462.558 - 462.559 - Example: (are [x y] (= x y) 462.560 - 2 (+ 1 1) 462.561 - 4 (* 2 2)) 462.562 - Expands to: 462.563 - (do (is (= 2 (+ 1 1))) 462.564 - (is (= 4 (* 2 2)))) 462.565 - 462.566 - Note: This breaks some reporting features, such as line numbers." 462.567 - {:added "1.1"} 462.568 - [argv expr & args] 462.569 - `(temp/do-template ~argv (is ~expr) ~@args)) 462.570 - 462.571 -(defmacro testing 462.572 - "Adds a new string to the list of testing contexts. May be nested, 462.573 - but must occur inside a test function (deftest)." 462.574 - {:added "1.1"} 462.575 - [string & body] 462.576 - `(binding [*testing-contexts* (conj *testing-contexts* ~string)] 462.577 - ~@body)) 462.578 - 462.579 - 462.580 - 462.581 -;;; DEFINING TESTS 462.582 - 462.583 -(defmacro with-test 462.584 - "Takes any definition form (that returns a Var) as the first argument. 462.585 - Remaining body goes in the :test metadata function for that Var. 462.586 - 462.587 - When *load-tests* is false, only evaluates the definition, ignoring 462.588 - the tests." 462.589 - {:added "1.1"} 462.590 - [definition & body] 462.591 - (if *load-tests* 462.592 - `(doto ~definition (alter-meta! assoc :test (fn [] ~@body))) 462.593 - definition)) 462.594 - 462.595 - 462.596 -(defmacro deftest 462.597 - "Defines a test function with no arguments. Test functions may call 462.598 - other tests, so tests may be composed. If you compose tests, you 462.599 - should also define a function named test-ns-hook; run-tests will 462.600 - call test-ns-hook instead of testing all vars. 462.601 - 462.602 - Note: Actually, the test body goes in the :test metadata on the var, 462.603 - and the real function (the value of the var) calls test-var on 462.604 - itself. 462.605 - 462.606 - When *load-tests* is false, deftest is ignored." 462.607 - {:added "1.1"} 462.608 - [name & body] 462.609 - (when *load-tests* 462.610 - `(def ~(vary-meta name assoc :test `(fn [] ~@body)) 462.611 - (fn [] (test-var (var ~name)))))) 462.612 - 462.613 -(defmacro deftest- 462.614 - "Like deftest but creates a private var." 462.615 - {:added "1.1"} 462.616 - [name & body] 462.617 - (when *load-tests* 462.618 - `(def ~(vary-meta name assoc :test `(fn [] ~@body) :private true) 462.619 - (fn [] (test-var (var ~name)))))) 462.620 - 462.621 - 462.622 -(defmacro set-test 462.623 - "Experimental. 462.624 - Sets :test metadata of the named var to a fn with the given body. 462.625 - The var must already exist. Does not modify the value of the var. 462.626 - 462.627 - When *load-tests* is false, set-test is ignored." 462.628 - {:added "1.1"} 462.629 - [name & body] 462.630 - (when *load-tests* 462.631 - `(alter-meta! (var ~name) assoc :test (fn [] ~@body)))) 462.632 - 462.633 - 462.634 - 462.635 -;;; DEFINING FIXTURES 462.636 - 462.637 -(defn- add-ns-meta 462.638 - "Adds elements in coll to the current namespace metadata as the 462.639 - value of key." 462.640 - {:added "1.1"} 462.641 - [key coll] 462.642 - (alter-meta! *ns* assoc key coll)) 462.643 - 462.644 -(defmulti use-fixtures 462.645 - "Wrap test runs in a fixture function to perform setup and 462.646 - teardown. Using a fixture-type of :each wraps every test 462.647 - individually, while:once wraps the whole run in a single function." 462.648 - {:added "1.1"} 462.649 - (fn [fixture-type & args] fixture-type)) 462.650 - 462.651 -(defmethod use-fixtures :each [fixture-type & args] 462.652 - (add-ns-meta ::each-fixtures args)) 462.653 - 462.654 -(defmethod use-fixtures :once [fixture-type & args] 462.655 - (add-ns-meta ::once-fixtures args)) 462.656 - 462.657 -(defn- default-fixture 462.658 - "The default, empty, fixture function. Just calls its argument." 462.659 - {:added "1.1"} 462.660 - [f] 462.661 - (f)) 462.662 - 462.663 -(defn compose-fixtures 462.664 - "Composes two fixture functions, creating a new fixture function 462.665 - that combines their behavior." 462.666 - {:added "1.1"} 462.667 - [f1 f2] 462.668 - (fn [g] (f1 (fn [] (f2 g))))) 462.669 - 462.670 -(defn join-fixtures 462.671 - "Composes a collection of fixtures, in order. Always returns a valid 462.672 - fixture function, even if the collection is empty." 462.673 - {:added "1.1"} 462.674 - [fixtures] 462.675 - (reduce compose-fixtures default-fixture fixtures)) 462.676 - 462.677 - 462.678 - 462.679 - 462.680 -;;; RUNNING TESTS: LOW-LEVEL FUNCTIONS 462.681 - 462.682 -(defn test-var 462.683 - "If v has a function in its :test metadata, calls that function, 462.684 - with *testing-vars* bound to (conj *testing-vars* v)." 462.685 - {:dynamic true, :added "1.1"} 462.686 - [v] 462.687 - (when-let [t (:test (meta v))] 462.688 - (binding [*testing-vars* (conj *testing-vars* v)] 462.689 - (do-report {:type :begin-test-var, :var v}) 462.690 - (inc-report-counter :test) 462.691 - (try (t) 462.692 - (catch Throwable e 462.693 - (do-report {:type :error, :message "Uncaught exception, not in assertion." 462.694 - :expected nil, :actual e}))) 462.695 - (do-report {:type :end-test-var, :var v})))) 462.696 - 462.697 -(defn test-all-vars 462.698 - "Calls test-var on every var interned in the namespace, with fixtures." 462.699 - {:added "1.1"} 462.700 - [ns] 462.701 - (let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns))) 462.702 - each-fixture-fn (join-fixtures (::each-fixtures (meta ns)))] 462.703 - (once-fixture-fn 462.704 - (fn [] 462.705 - (doseq [v (vals (ns-interns ns))] 462.706 - (when (:test (meta v)) 462.707 - (each-fixture-fn (fn [] (test-var v))))))))) 462.708 - 462.709 -(defn test-ns 462.710 - "If the namespace defines a function named test-ns-hook, calls that. 462.711 - Otherwise, calls test-all-vars on the namespace. 'ns' is a 462.712 - namespace object or a symbol. 462.713 - 462.714 - Internally binds *report-counters* to a ref initialized to 462.715 - *inital-report-counters*. Returns the final, dereferenced state of 462.716 - *report-counters*." 462.717 - {:added "1.1"} 462.718 - [ns] 462.719 - (binding [*report-counters* (ref *initial-report-counters*)] 462.720 - (let [ns-obj (the-ns ns)] 462.721 - (do-report {:type :begin-test-ns, :ns ns-obj}) 462.722 - ;; If the namespace has a test-ns-hook function, call that: 462.723 - (if-let [v (find-var (symbol (str (ns-name ns-obj)) "test-ns-hook"))] 462.724 - ((var-get v)) 462.725 - ;; Otherwise, just test every var in the namespace. 462.726 - (test-all-vars ns-obj)) 462.727 - (do-report {:type :end-test-ns, :ns ns-obj})) 462.728 - @*report-counters*)) 462.729 - 462.730 - 462.731 - 462.732 -;;; RUNNING TESTS: HIGH-LEVEL FUNCTIONS 462.733 - 462.734 -(defn run-tests 462.735 - "Runs all tests in the given namespaces; prints results. 462.736 - Defaults to current namespace if none given. Returns a map 462.737 - summarizing test results." 462.738 - {:added "1.1"} 462.739 - ([] (run-tests *ns*)) 462.740 - ([& namespaces] 462.741 - (let [summary (assoc (apply merge-with + (map test-ns namespaces)) 462.742 - :type :summary)] 462.743 - (do-report summary) 462.744 - summary))) 462.745 - 462.746 -(defn run-all-tests 462.747 - "Runs all tests in all namespaces; prints results. 462.748 - Optional argument is a regular expression; only namespaces with 462.749 - names matching the regular expression (with re-matches) will be 462.750 - tested." 462.751 - {:added "1.1"} 462.752 - ([] (apply run-tests (all-ns))) 462.753 - ([re] (apply run-tests (filter #(re-matches re (name (ns-name %))) (all-ns))))) 462.754 - 462.755 -(defn successful? 462.756 - "Returns true if the given test summary indicates all tests 462.757 - were successful, false otherwise." 462.758 - {:added "1.1"} 462.759 - [summary] 462.760 - (and (zero? (:fail summary 0)) 462.761 - (zero? (:error summary 0))))
463.1 --- a/src/clojure/test/junit.clj Sat Aug 21 06:25:44 2010 -0400 463.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 463.3 @@ -1,194 +0,0 @@ 463.4 -; Copyright (c) Rich Hickey. All rights reserved. 463.5 -; The use and distribution terms for this software are covered by the 463.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 463.7 -; which can be found in the file epl-v10.html at the root of this distribution. 463.8 -; By using this software in any fashion, you are agreeing to be bound by 463.9 -; the terms of this license. 463.10 -; You must not remove this notice, or any other, from this software. 463.11 - 463.12 -;; test/junit.clj: Extension to clojure.test for JUnit-compatible XML output 463.13 - 463.14 -;; by Jason Sankey 463.15 -;; June 2009 463.16 - 463.17 -;; DOCUMENTATION 463.18 -;; 463.19 - 463.20 -(ns ^{:doc "clojure.test extension for JUnit-compatible XML output. 463.21 - 463.22 - JUnit (http://junit.org/) is the most popular unit-testing library 463.23 - for Java. As such, tool support for JUnit output formats is 463.24 - common. By producing compatible output from tests, this tool 463.25 - support can be exploited. 463.26 - 463.27 - To use, wrap any calls to clojure.test/run-tests in the 463.28 - with-junit-output macro, like this: 463.29 - 463.30 - (use 'clojure.test) 463.31 - (use 'clojure.test.junit) 463.32 - 463.33 - (with-junit-output 463.34 - (run-tests 'my.cool.library)) 463.35 - 463.36 - To write the output to a file, rebind clojure.test/*test-out* to 463.37 - your own PrintWriter (perhaps opened using 463.38 - clojure.java.io/writer)." 463.39 - :author "Jason Sankey"} 463.40 - clojure.test.junit 463.41 - (:require [clojure.stacktrace :as stack] 463.42 - [clojure.test :as t])) 463.43 - 463.44 -;; copied from clojure.contrib.lazy-xml 463.45 -(def ^{:private true} 463.46 - escape-xml-map 463.47 - (zipmap "'<>\"&" (map #(str \& % \;) '[apos lt gt quot amp]))) 463.48 -(defn- escape-xml [text] 463.49 - (apply str (map #(escape-xml-map % %) text))) 463.50 - 463.51 -(def *var-context*) 463.52 -(def *depth*) 463.53 - 463.54 -(defn indent 463.55 - [] 463.56 - (dotimes [n (* *depth* 4)] (print " "))) 463.57 - 463.58 -(defn start-element 463.59 - [tag pretty & [attrs]] 463.60 - (if pretty (indent)) 463.61 - (print (str "<" tag)) 463.62 - (if (seq attrs) 463.63 - (doseq [[key value] attrs] 463.64 - (print (str " " (name key) "=\"" (escape-xml value) "\"")))) 463.65 - (print ">") 463.66 - (if pretty (println)) 463.67 - (set! *depth* (inc *depth*))) 463.68 - 463.69 -(defn element-content 463.70 - [content] 463.71 - (print (escape-xml content))) 463.72 - 463.73 -(defn finish-element 463.74 - [tag pretty] 463.75 - (set! *depth* (dec *depth*)) 463.76 - (if pretty (indent)) 463.77 - (print (str "</" tag ">")) 463.78 - (if pretty (println))) 463.79 - 463.80 -(defn test-name 463.81 - [vars] 463.82 - (apply str (interpose "." 463.83 - (reverse (map #(:name (meta %)) vars))))) 463.84 - 463.85 -(defn package-class 463.86 - [name] 463.87 - (let [i (.lastIndexOf name ".")] 463.88 - (if (< i 0) 463.89 - [nil name] 463.90 - [(.substring name 0 i) (.substring name (+ i 1))]))) 463.91 - 463.92 -(defn start-case 463.93 - [name classname] 463.94 - (start-element 'testcase true {:name name :classname classname})) 463.95 - 463.96 -(defn finish-case 463.97 - [] 463.98 - (finish-element 'testcase true)) 463.99 - 463.100 -(defn suite-attrs 463.101 - [package classname] 463.102 - (let [attrs {:name classname}] 463.103 - (if package 463.104 - (assoc attrs :package package) 463.105 - attrs))) 463.106 - 463.107 -(defn start-suite 463.108 - [name] 463.109 - (let [[package classname] (package-class name)] 463.110 - (start-element 'testsuite true (suite-attrs package classname)))) 463.111 - 463.112 -(defn finish-suite 463.113 - [] 463.114 - (finish-element 'testsuite true)) 463.115 - 463.116 -(defn message-el 463.117 - [tag message expected-str actual-str] 463.118 - (indent) 463.119 - (start-element tag false (if message {:message message} {})) 463.120 - (element-content 463.121 - (let [[file line] (t/file-position 5) 463.122 - detail (apply str (interpose 463.123 - "\n" 463.124 - [(str "expected: " expected-str) 463.125 - (str " actual: " actual-str) 463.126 - (str " at: " file ":" line)]))] 463.127 - (if message (str message "\n" detail) detail))) 463.128 - (finish-element tag false) 463.129 - (println)) 463.130 - 463.131 -(defn failure-el 463.132 - [message expected actual] 463.133 - (message-el 'failure message (pr-str expected) (pr-str actual))) 463.134 - 463.135 -(defn error-el 463.136 - [message expected actual] 463.137 - (message-el 'error 463.138 - message 463.139 - (pr-str expected) 463.140 - (if (instance? Throwable actual) 463.141 - (with-out-str (stack/print-cause-trace actual t/*stack-trace-depth*)) 463.142 - (prn actual)))) 463.143 - 463.144 -;; This multimethod will override test-is/report 463.145 -(defmulti junit-report :type) 463.146 - 463.147 -(defmethod junit-report :begin-test-ns [m] 463.148 - (t/with-test-out 463.149 - (start-suite (name (ns-name (:ns m)))))) 463.150 - 463.151 -(defmethod junit-report :end-test-ns [_] 463.152 - (t/with-test-out 463.153 - (finish-suite))) 463.154 - 463.155 -(defmethod junit-report :begin-test-var [m] 463.156 - (t/with-test-out 463.157 - (let [var (:var m)] 463.158 - (binding [*var-context* (conj *var-context* var)] 463.159 - (start-case (test-name *var-context*) (name (ns-name (:ns (meta var))))))))) 463.160 - 463.161 -(defmethod junit-report :end-test-var [m] 463.162 - (t/with-test-out 463.163 - (finish-case))) 463.164 - 463.165 -(defmethod junit-report :pass [m] 463.166 - (t/with-test-out 463.167 - (t/inc-report-counter :pass))) 463.168 - 463.169 -(defmethod junit-report :fail [m] 463.170 - (t/with-test-out 463.171 - (t/inc-report-counter :fail) 463.172 - (failure-el (:message m) 463.173 - (:expected m) 463.174 - (:actual m)))) 463.175 - 463.176 -(defmethod junit-report :error [m] 463.177 - (t/with-test-out 463.178 - (t/inc-report-counter :error) 463.179 - (error-el (:message m) 463.180 - (:expected m) 463.181 - (:actual m)))) 463.182 - 463.183 -(defmethod junit-report :default [_]) 463.184 - 463.185 -(defmacro with-junit-output 463.186 - "Execute body with modified test-is reporting functions that write 463.187 - JUnit-compatible XML output." 463.188 - {:added "1.1"} 463.189 - [& body] 463.190 - `(binding [t/report junit-report 463.191 - *var-context* (list) 463.192 - *depth* 1] 463.193 - (println "<?xml version=\"1.0\" encoding=\"UTF-8\"?>") 463.194 - (println "<testsuites>") 463.195 - (let [result# ~@body] 463.196 - (println "</testsuites>") 463.197 - result#)))
464.1 --- a/src/clojure/test/tap.clj Sat Aug 21 06:25:44 2010 -0400 464.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 464.3 @@ -1,116 +0,0 @@ 464.4 -; Copyright (c) Rich Hickey. All rights reserved. 464.5 -; The use and distribution terms for this software are covered by the 464.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 464.7 -; which can be found in the file epl-v10.html at the root of this distribution. 464.8 -; By using this software in any fashion, you are agreeing to be bound by 464.9 -; the terms of this license. 464.10 -; You must not remove this notice, or any other, from this software. 464.11 - 464.12 -;;; test_is/tap.clj: Extension to test for TAP output 464.13 - 464.14 -;; by Stuart Sierra 464.15 -;; March 31, 2009 464.16 - 464.17 -;; Inspired by ClojureCheck by Meikel Brandmeyer: 464.18 -;; http://kotka.de/projects/clojure/clojurecheck.html 464.19 - 464.20 - 464.21 -;; DOCUMENTATION 464.22 -;; 464.23 - 464.24 - 464.25 - 464.26 -(ns ^{:doc "clojure.test extensions for the Test Anything Protocol (TAP) 464.27 - 464.28 - TAP is a simple text-based syntax for reporting test results. TAP 464.29 - was originally develped for Perl, and now has implementations in 464.30 - several languages. For more information on TAP, see 464.31 - http://testanything.org/ and 464.32 - http://search.cpan.org/~petdance/TAP-1.0.0/TAP.pm 464.33 - 464.34 - To use this library, wrap any calls to 464.35 - clojure.test/run-tests in the with-tap-output macro, 464.36 - like this: 464.37 - 464.38 - (use 'clojure.test) 464.39 - (use 'clojure.test.tap) 464.40 - 464.41 - (with-tap-output 464.42 - (run-tests 'my.cool.library))" 464.43 - :author "Stuart Sierra"} 464.44 - clojure.test.tap 464.45 - (:require [clojure.test :as t] 464.46 - [clojure.stacktrace :as stack])) 464.47 - 464.48 -(defn print-tap-plan 464.49 - "Prints a TAP plan line like '1..n'. n is the number of tests" 464.50 - {:added "1.1"} 464.51 - [n] 464.52 - (println (str "1.." n))) 464.53 - 464.54 -(defn print-tap-diagnostic 464.55 - "Prints a TAP diagnostic line. data is a (possibly multi-line) 464.56 - string." 464.57 - {:added "1.1"} 464.58 - [data] 464.59 - (doseq [line (.split ^String data "\n")] 464.60 - (println "#" line))) 464.61 - 464.62 -(defn print-tap-pass 464.63 - "Prints a TAP 'ok' line. msg is a string, with no line breaks" 464.64 - {:added "1.1"} 464.65 - [msg] 464.66 - (println "ok" msg)) 464.67 - 464.68 -(defn print-tap-fail 464.69 - "Prints a TAP 'not ok' line. msg is a string, with no line breaks" 464.70 - {:added "1.1"} 464.71 - [msg] 464.72 - (println "not ok" msg)) 464.73 - 464.74 -;; This multimethod will override test/report 464.75 -(defmulti tap-report (fn [data] (:type data))) 464.76 - 464.77 -(defmethod tap-report :default [data] 464.78 - (t/with-test-out 464.79 - (print-tap-diagnostic (pr-str data)))) 464.80 - 464.81 -(defmethod tap-report :pass [data] 464.82 - (t/with-test-out 464.83 - (t/inc-report-counter :pass) 464.84 - (print-tap-pass (t/testing-vars-str)) 464.85 - (when (seq t/*testing-contexts*) 464.86 - (print-tap-diagnostic (t/testing-contexts-str))) 464.87 - (when (:message data) 464.88 - (print-tap-diagnostic (:message data))) 464.89 - (print-tap-diagnostic (str "expected:" (pr-str (:expected data)))) 464.90 - (print-tap-diagnostic (str " actual:" (pr-str (:actual data)))))) 464.91 - 464.92 -(defmethod tap-report :error [data] 464.93 - (t/with-test-out 464.94 - (t/inc-report-counter :error) 464.95 - (print-tap-fail (t/testing-vars-str)) 464.96 - (when (seq t/*testing-contexts*) 464.97 - (print-tap-diagnostic (t/testing-contexts-str))) 464.98 - (when (:message data) 464.99 - (print-tap-diagnostic (:message data))) 464.100 - (print-tap-diagnostic "expected:" (pr-str (:expected data))) 464.101 - (print-tap-diagnostic " actual: ") 464.102 - (print-tap-diagnostic 464.103 - (with-out-str 464.104 - (if (instance? Throwable (:actual data)) 464.105 - (stack/print-cause-trace (:actual data) t/*stack-trace-depth*) 464.106 - (prn (:actual data))))))) 464.107 - 464.108 -(defmethod tap-report :summary [data] 464.109 - (t/with-test-out 464.110 - (print-tap-plan (+ (:pass data) (:fail data) (:error data))))) 464.111 - 464.112 - 464.113 -(defmacro with-tap-output 464.114 - "Execute body with modified test reporting functions that produce 464.115 - TAP output" 464.116 - {:added "1.1"} 464.117 - [& body] 464.118 - `(binding [t/report tap-report] 464.119 - ~@body))
465.1 --- a/src/clojure/test_clojure.clj Sat Aug 21 06:25:44 2010 -0400 465.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 465.3 @@ -1,99 +0,0 @@ 465.4 -; Copyright (c) Rich Hickey. All rights reserved. 465.5 -; The use and distribution terms for this software are covered by the 465.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 465.7 -; which can be found in the file epl-v10.html at the root of this distribution. 465.8 -; By using this software in any fashion, you are agreeing to be bound by 465.9 -; the terms of this license. 465.10 -; You must not remove this notice, or any other, from this software. 465.11 -; 465.12 - 465.13 -;; clojure.test-clojure 465.14 -;; 465.15 -;; Tests for the facilities provided by Clojure 465.16 -;; 465.17 -;; scgilardi (gmail) 465.18 -;; Created 22 October 2008 465.19 - 465.20 -(ns clojure.test-clojure 465.21 - (:require [clojure.test :as t]) 465.22 - (:gen-class)) 465.23 - 465.24 -(def test-names 465.25 - [:reader 465.26 - :printer 465.27 - :compilation 465.28 - :evaluation 465.29 - :special 465.30 - :macros 465.31 - :metadata 465.32 - :ns-libs 465.33 - :logic 465.34 - :predicates 465.35 - :control 465.36 - :data-structures 465.37 - :numbers 465.38 - :sequences 465.39 - :for 465.40 - :multimethods 465.41 - :other-functions 465.42 - :vars 465.43 - :refs 465.44 - :agents 465.45 - :atoms 465.46 - :parallel 465.47 - :java-interop 465.48 - :test 465.49 - :test-fixtures 465.50 - ;; libraries 465.51 - :clojure-set 465.52 - :clojure-xml 465.53 - :clojure-zip 465.54 - :protocols 465.55 - :genclass 465.56 - :main 465.57 - :vectors 465.58 - :annotations 465.59 - :pprint 465.60 - :serialization 465.61 - :rt 465.62 - :repl 465.63 - :java.io 465.64 - :string 465.65 - :java.javadoc 465.66 - :java.shell 465.67 - :transients 465.68 - :def 465.69 - ]) 465.70 - 465.71 -(def test-namespaces 465.72 - (map #(symbol (str "clojure.test-clojure." (name %))) 465.73 - test-names)) 465.74 - 465.75 -(defn run 465.76 - "Runs all defined tests" 465.77 - [] 465.78 - (println "Loading tests...") 465.79 - (apply require :reload-all test-namespaces) 465.80 - (apply t/run-tests test-namespaces)) 465.81 - 465.82 -(defn run-ant 465.83 - "Runs all defined tests, prints report to *err*, throw if failures. This works well for running in an ant java task." 465.84 - [] 465.85 - (let [rpt t/report] 465.86 - (binding [;; binding to *err* because, in ant, when the test target 465.87 - ;; runs after compile-clojure, *out* doesn't print anything 465.88 - *out* *err* 465.89 - t/*test-out* *err* 465.90 - t/report (fn report [m] 465.91 - (if (= :summary (:type m)) 465.92 - (do (rpt m) 465.93 - (if (or (pos? (:fail m)) (pos? (:error m))) 465.94 - (throw (new Exception (str (:fail m) " failures, " (:error m) " errors."))))) 465.95 - (rpt m)))] 465.96 - (run)))) 465.97 - 465.98 -(defn -main 465.99 - "Run all defined tests from the command line" 465.100 - [& args] 465.101 - (run) 465.102 - (System/exit 0))
466.1 --- a/src/clojure/test_clojure/agents.clj Sat Aug 21 06:25:44 2010 -0400 466.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 466.3 @@ -1,120 +0,0 @@ 466.4 -; Copyright (c) Rich Hickey. All rights reserved. 466.5 -; The use and distribution terms for this software are covered by the 466.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 466.7 -; which can be found in the file epl-v10.html at the root of this distribution. 466.8 -; By using this software in any fashion, you are agreeing to be bound by 466.9 -; the terms of this license. 466.10 -; You must not remove this notice, or any other, from this software. 466.11 - 466.12 -;; Author: Shawn Hoover 466.13 - 466.14 -(ns clojure.test-clojure.agents 466.15 - (:use clojure.test)) 466.16 - 466.17 -(deftest handle-all-throwables-during-agent-actions 466.18 - ;; Bug fixed in r1198; previously hung Clojure or didn't report agent errors 466.19 - ;; after OutOfMemoryError, yet wouldn't execute new actions. 466.20 - (let [agt (agent nil)] 466.21 - (send agt (fn [state] (throw (Throwable. "just testing Throwables")))) 466.22 - (try 466.23 - ;; Let the action finish; eat the "agent has errors" error that bubbles up 466.24 - (await-for 100 agt) 466.25 - (catch RuntimeException _)) 466.26 - (is (instance? Throwable (first (agent-errors agt)))) 466.27 - (is (= 1 (count (agent-errors agt)))) 466.28 - 466.29 - ;; And now send an action that should work 466.30 - (clear-agent-errors agt) 466.31 - (is (= nil @agt)) 466.32 - (send agt nil?) 466.33 - (is (true? (await-for 100 agt))) 466.34 - (is (true? @agt)))) 466.35 - 466.36 -(deftest default-modes 466.37 - (is (= :fail (error-mode (agent nil)))) 466.38 - (is (= :continue (error-mode (agent nil :error-handler println))))) 466.39 - 466.40 -(deftest continue-handler 466.41 - (let [err (atom nil) 466.42 - agt (agent 0 :error-mode :continue :error-handler #(reset! err %&))] 466.43 - (send agt /) 466.44 - (is (true? (await-for 100 agt))) 466.45 - (is (= 0 @agt)) 466.46 - (is (nil? (agent-error agt))) 466.47 - (is (= agt (first @err))) 466.48 - (is (true? (instance? ArithmeticException (second @err)))))) 466.49 - 466.50 -(deftest fail-handler 466.51 - (let [err (atom nil) 466.52 - agt (agent 0 :error-mode :fail :error-handler #(reset! err %&))] 466.53 - (send agt /) 466.54 - (Thread/sleep 100) 466.55 - (is (true? (instance? ArithmeticException (agent-error agt)))) 466.56 - (is (= 0 @agt)) 466.57 - (is (= agt (first @err))) 466.58 - (is (true? (instance? ArithmeticException (second @err)))) 466.59 - (is (thrown? RuntimeException (send agt inc))))) 466.60 - 466.61 -(deftest restart-no-clear 466.62 - (let [p (promise) 466.63 - agt (agent 1 :error-mode :fail)] 466.64 - (send agt (fn [v] @p)) 466.65 - (send agt /) 466.66 - (send agt inc) 466.67 - (send agt inc) 466.68 - (deliver p 0) 466.69 - (Thread/sleep 100) 466.70 - (is (= 0 @agt)) 466.71 - (is (= ArithmeticException (class (agent-error agt)))) 466.72 - (restart-agent agt 10) 466.73 - (is (true? (await-for 100 agt))) 466.74 - (is (= 12 @agt)) 466.75 - (is (nil? (agent-error agt))))) 466.76 - 466.77 -(deftest restart-clear 466.78 - (let [p (promise) 466.79 - agt (agent 1 :error-mode :fail)] 466.80 - (send agt (fn [v] @p)) 466.81 - (send agt /) 466.82 - (send agt inc) 466.83 - (send agt inc) 466.84 - (deliver p 0) 466.85 - (Thread/sleep 100) 466.86 - (is (= 0 @agt)) 466.87 - (is (= ArithmeticException (class (agent-error agt)))) 466.88 - (restart-agent agt 10 :clear-actions true) 466.89 - (is (true? (await-for 100 agt))) 466.90 - (is (= 10 @agt)) 466.91 - (is (nil? (agent-error agt))) 466.92 - (send agt inc) 466.93 - (is (true? (await-for 100 agt))) 466.94 - (is (= 11 @agt)) 466.95 - (is (nil? (agent-error agt))))) 466.96 - 466.97 -(deftest invalid-restart 466.98 - (let [p (promise) 466.99 - agt (agent 2 :error-mode :fail :validator even?)] 466.100 - (is (thrown? RuntimeException (restart-agent agt 4))) 466.101 - (send agt (fn [v] @p)) 466.102 - (send agt (partial + 2)) 466.103 - (send agt (partial + 2)) 466.104 - (deliver p 3) 466.105 - (Thread/sleep 100) 466.106 - (is (= 2 @agt)) 466.107 - (is (= IllegalStateException (class (agent-error agt)))) 466.108 - (is (thrown? RuntimeException (restart-agent agt 5))) 466.109 - (restart-agent agt 6) 466.110 - (is (true? (await-for 100 agt))) 466.111 - (is (= 10 @agt)) 466.112 - (is (nil? (agent-error agt))))) 466.113 - 466.114 -; http://clojure.org/agents 466.115 - 466.116 -; agent 466.117 -; deref, @-reader-macro, agent-errors 466.118 -; send send-off clear-agent-errors 466.119 -; await await-for 466.120 -; set-validator get-validator 466.121 -; add-watch remove-watch 466.122 -; shutdown-agents 466.123 -
467.1 --- a/src/clojure/test_clojure/annotations.clj Sat Aug 21 06:25:44 2010 -0400 467.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 467.3 @@ -1,29 +0,0 @@ 467.4 -; Copyright (c) Rich Hickey. All rights reserved. 467.5 -; The use and distribution terms for this software are covered by the 467.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 467.7 -; which can be found in the file epl-v10.html at the root of this distribution. 467.8 -; By using this software in any fashion, you are agreeing to be bound by 467.9 -; the terms of this license. 467.10 -; You must not remove this notice, or any other, from this software. 467.11 - 467.12 -;; Authors: Stuart Halloway, Rich Hickey 467.13 - 467.14 -(ns clojure.test-clojure.annotations 467.15 - (:use clojure.test)) 467.16 - 467.17 -(defn vm-has-ws-annotations? 467.18 - "Does the vm have the ws annotations we use to test some 467.19 - annotation features. If not, fall back to Java 5 tests." 467.20 - [] 467.21 - (try 467.22 - (doseq [n ["javax.xml.ws.soap.Addressing" 467.23 - "javax.xml.ws.WebServiceRef" 467.24 - "javax.xml.ws.WebServiceRefs"]] 467.25 - (Class/forName n)) 467.26 - true 467.27 - (catch ClassNotFoundException e 467.28 - false))) 467.29 - 467.30 -(if (vm-has-ws-annotations?) 467.31 - (load "annotations/java_6_and_later") 467.32 - (load "annotations/java_5"))
468.1 --- a/src/clojure/test_clojure/annotations/java_5.clj Sat Aug 21 06:25:44 2010 -0400 468.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 468.3 @@ -1,54 +0,0 @@ 468.4 -;; java 5 annotation tests 468.5 -(in-ns 'clojure.test-clojure.annotations) 468.6 - 468.7 -(import [java.lang.annotation Annotation Retention RetentionPolicy Target ElementType]) 468.8 -(definterface Foo (foo [])) 468.9 - 468.10 -(deftype #^{Deprecated true 468.11 - Retention RetentionPolicy/RUNTIME} 468.12 - Bar [#^int a 468.13 - #^{:tag int 468.14 - Deprecated true 468.15 - Retention RetentionPolicy/RUNTIME} b] 468.16 - Foo (#^{Deprecated true 468.17 - Retention RetentionPolicy/RUNTIME} 468.18 - foo [this] 42)) 468.19 - 468.20 -(defn annotation->map 468.21 - "Converts a Java annotation (which conceals data) 468.22 - into a map (which makes is usable). Not lazy. 468.23 - Works recursively. Returns non-annotations unscathed." 468.24 - [#^java.lang.annotation.Annotation o] 468.25 - (cond 468.26 - (instance? Annotation o) 468.27 - (let [type (.annotationType o) 468.28 - itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation)) 468.29 - data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))] 468.30 - (into 468.31 - {:annotationType (.annotationType o)} 468.32 - (map 468.33 - (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))]) 468.34 - data-methods))) 468.35 - (or (sequential? o) (.isArray (class o))) 468.36 - (map annotation->map o) 468.37 - :else o)) 468.38 - 468.39 -(def expected-annotations 468.40 - #{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME} 468.41 - {:annotationType java.lang.Deprecated}}) 468.42 - 468.43 -(deftest test-annotations-on-type 468.44 - (is (= 468.45 - expected-annotations 468.46 - (into #{} (map annotation->map (.getAnnotations Bar)))))) 468.47 - 468.48 -(deftest test-annotations-on-field 468.49 - (is (= 468.50 - expected-annotations 468.51 - (into #{} (map annotation->map (.getAnnotations (.getField Bar "b"))))))) 468.52 - 468.53 -(deftest test-annotations-on-method 468.54 - (is (= 468.55 - expected-annotations 468.56 - (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil))))))) 468.57 -
469.1 --- a/src/clojure/test_clojure/annotations/java_6_and_later.clj Sat Aug 21 06:25:44 2010 -0400 469.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 469.3 @@ -1,73 +0,0 @@ 469.4 -;; java 6 annotation tests 469.5 -(in-ns 'clojure.test-clojure.annotations) 469.6 - 469.7 -(import [java.lang.annotation Annotation Retention RetentionPolicy Target ElementType] 469.8 - [javax.xml.ws WebServiceRef WebServiceRefs]) 469.9 -(definterface Foo (foo [])) 469.10 - 469.11 -(deftype #^{Deprecated true 469.12 - Retention RetentionPolicy/RUNTIME 469.13 - javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"] 469.14 - javax.xml.ws.soap.Addressing {:enabled false :required true} 469.15 - WebServiceRefs [(WebServiceRef {:name "fred" :type String}) 469.16 - (WebServiceRef {:name "ethel" :mappedName "lucy"})]} 469.17 - Bar [#^int a 469.18 - #^{:tag int 469.19 - Deprecated true 469.20 - Retention RetentionPolicy/RUNTIME 469.21 - javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"] 469.22 - javax.xml.ws.soap.Addressing {:enabled false :required true} 469.23 - WebServiceRefs [(WebServiceRef {:name "fred" :type String}) 469.24 - (WebServiceRef {:name "ethel" :mappedName "lucy"})]} 469.25 - b] 469.26 - Foo (#^{Deprecated true 469.27 - Retention RetentionPolicy/RUNTIME 469.28 - javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"] 469.29 - javax.xml.ws.soap.Addressing {:enabled false :required true} 469.30 - WebServiceRefs [(WebServiceRef {:name "fred" :type String}) 469.31 - (WebServiceRef {:name "ethel" :mappedName "lucy"})]} 469.32 - foo [this] 42)) 469.33 - 469.34 -(defn annotation->map 469.35 - "Converts a Java annotation (which conceals data) 469.36 - into a map (which makes is usable). Not lazy. 469.37 - Works recursively. Returns non-annotations unscathed." 469.38 - [#^java.lang.annotation.Annotation o] 469.39 - (cond 469.40 - (instance? Annotation o) 469.41 - (let [type (.annotationType o) 469.42 - itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation)) 469.43 - data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))] 469.44 - (into 469.45 - {:annotationType (.annotationType o)} 469.46 - (map 469.47 - (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))]) 469.48 - data-methods))) 469.49 - (or (sequential? o) (.isArray (class o))) 469.50 - (map annotation->map o) 469.51 - :else o)) 469.52 - 469.53 -(def expected-annotations 469.54 - #{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME} 469.55 - {:annotationType javax.xml.ws.WebServiceRefs, 469.56 - :value [{:annotationType javax.xml.ws.WebServiceRef, :name "fred", :mappedName "", :type java.lang.String, :wsdlLocation "", :value java.lang.Object} 469.57 - {:annotationType javax.xml.ws.WebServiceRef, :name "ethel", :mappedName "lucy", :type java.lang.Object, :wsdlLocation "", :value java.lang.Object}]} 469.58 - {:annotationType javax.xml.ws.soap.Addressing, :enabled false, :required true} 469.59 - {:annotationType javax.annotation.processing.SupportedOptions, :value ["foo" "bar" "baz"]} 469.60 - {:annotationType java.lang.Deprecated}}) 469.61 - 469.62 -(deftest test-annotations-on-type 469.63 - (is (= 469.64 - expected-annotations 469.65 - (into #{} (map annotation->map (.getAnnotations Bar)))))) 469.66 - 469.67 -(deftest test-annotations-on-field 469.68 - (is (= 469.69 - expected-annotations 469.70 - (into #{} (map annotation->map (.getAnnotations (.getField Bar "b"))))))) 469.71 - 469.72 -(deftest test-annotations-on-method 469.73 - (is (= 469.74 - expected-annotations 469.75 - (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil))))))) 469.76 -
470.1 --- a/src/clojure/test_clojure/atoms.clj Sat Aug 21 06:25:44 2010 -0400 470.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 470.3 @@ -1,20 +0,0 @@ 470.4 -; Copyright (c) Rich Hickey. All rights reserved. 470.5 -; The use and distribution terms for this software are covered by the 470.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 470.7 -; which can be found in the file epl-v10.html at the root of this distribution. 470.8 -; By using this software in any fashion, you are agreeing to be bound by 470.9 -; the terms of this license. 470.10 -; You must not remove this notice, or any other, from this software. 470.11 - 470.12 -;;Author: Frantisek Sodomka 470.13 - 470.14 -(ns clojure.test-clojure.atoms 470.15 - (:use clojure.test)) 470.16 - 470.17 -; http://clojure.org/atoms 470.18 - 470.19 -; atom 470.20 -; deref, @-reader-macro 470.21 -; swap! reset! 470.22 -; compare-and-set! 470.23 -
471.1 --- a/src/clojure/test_clojure/clojure_set.clj Sat Aug 21 06:25:44 2010 -0400 471.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 471.3 @@ -1,206 +0,0 @@ 471.4 -; Copyright (c) Rich Hickey. All rights reserved. 471.5 -; The use and distribution terms for this software are covered by the 471.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 471.7 -; which can be found in the file epl-v10.html at the root of this distribution. 471.8 -; By using this software in any fashion, you are agreeing to be bound by 471.9 -; the terms of this license. 471.10 -; You must not remove this notice, or any other, from this software. 471.11 - 471.12 -;; Author: Frantisek Sodomka 471.13 - 471.14 - 471.15 -(ns clojure.test-clojure.clojure-set 471.16 - (:use clojure.test) 471.17 - (:require [clojure.set :as set])) 471.18 - 471.19 -(deftest test-union 471.20 - (are [x y] (= x y) 471.21 - (set/union) #{} 471.22 - 471.23 - ; identity 471.24 - (set/union #{}) #{} 471.25 - (set/union #{1}) #{1} 471.26 - (set/union #{1 2 3}) #{1 2 3} 471.27 - 471.28 - ; 2 sets, at least one is empty 471.29 - (set/union #{} #{}) #{} 471.30 - (set/union #{} #{1}) #{1} 471.31 - (set/union #{} #{1 2 3}) #{1 2 3} 471.32 - (set/union #{1} #{}) #{1} 471.33 - (set/union #{1 2 3} #{}) #{1 2 3} 471.34 - 471.35 - ; 2 sets 471.36 - (set/union #{1} #{2}) #{1 2} 471.37 - (set/union #{1} #{1 2}) #{1 2} 471.38 - (set/union #{2} #{1 2}) #{1 2} 471.39 - (set/union #{1 2} #{3}) #{1 2 3} 471.40 - (set/union #{1 2} #{2 3}) #{1 2 3} 471.41 - 471.42 - ; 3 sets, some are empty 471.43 - (set/union #{} #{} #{}) #{} 471.44 - (set/union #{1} #{} #{}) #{1} 471.45 - (set/union #{} #{1} #{}) #{1} 471.46 - (set/union #{} #{} #{1}) #{1} 471.47 - (set/union #{1 2} #{2 3} #{}) #{1 2 3} 471.48 - 471.49 - ; 3 sets 471.50 - (set/union #{1 2} #{3 4} #{5 6}) #{1 2 3 4 5 6} 471.51 - (set/union #{1 2} #{2 3} #{1 3 4}) #{1 2 3 4} 471.52 - 471.53 - ; different data types 471.54 - (set/union #{1 2} #{:a :b} #{nil} #{false true} #{\c "abc"} #{[] [1 2]} 471.55 - #{{} {:a 1}} #{#{} #{1 2}}) 471.56 - #{1 2 :a :b nil false true \c "abc" [] [1 2] {} {:a 1} #{} #{1 2}} 471.57 - 471.58 - ; different types of sets 471.59 - (set/union (hash-set) (hash-set 1 2) (hash-set 2 3)) 471.60 - (hash-set 1 2 3) 471.61 - (set/union (sorted-set) (sorted-set 1 2) (sorted-set 2 3)) 471.62 - (sorted-set 1 2 3) 471.63 - (set/union (hash-set) (hash-set 1 2) (hash-set 2 3) 471.64 - (sorted-set) (sorted-set 4 5) (sorted-set 5 6)) 471.65 - (hash-set 1 2 3 4 5 6) ; also equals (sorted-set 1 2 3 4 5 6) 471.66 -)) 471.67 - 471.68 -(deftest test-intersection 471.69 - ; at least one argument is needed 471.70 - (is (thrown? IllegalArgumentException (set/intersection))) 471.71 - 471.72 - (are [x y] (= x y) 471.73 - ; identity 471.74 - (set/intersection #{}) #{} 471.75 - (set/intersection #{1}) #{1} 471.76 - (set/intersection #{1 2 3}) #{1 2 3} 471.77 - 471.78 - ; 2 sets, at least one is empty 471.79 - (set/intersection #{} #{}) #{} 471.80 - (set/intersection #{} #{1}) #{} 471.81 - (set/intersection #{} #{1 2 3}) #{} 471.82 - (set/intersection #{1} #{}) #{} 471.83 - (set/intersection #{1 2 3} #{}) #{} 471.84 - 471.85 - ; 2 sets 471.86 - (set/intersection #{1 2} #{1 2}) #{1 2} 471.87 - (set/intersection #{1 2} #{3 4}) #{} 471.88 - (set/intersection #{1 2} #{1}) #{1} 471.89 - (set/intersection #{1 2} #{2}) #{2} 471.90 - (set/intersection #{1 2 4} #{2 3 4 5}) #{2 4} 471.91 - 471.92 - ; 3 sets, some are empty 471.93 - (set/intersection #{} #{} #{}) #{} 471.94 - (set/intersection #{1} #{} #{}) #{} 471.95 - (set/intersection #{1} #{1} #{}) #{} 471.96 - (set/intersection #{1} #{} #{1}) #{} 471.97 - (set/intersection #{1 2} #{2 3} #{}) #{} 471.98 - 471.99 - ; 3 sets 471.100 - (set/intersection #{1 2} #{2 3} #{5 2}) #{2} 471.101 - (set/intersection #{1 2 3} #{1 3 4} #{1 3}) #{1 3} 471.102 - (set/intersection #{1 2 3} #{3 4 5} #{8 2 3}) #{3} 471.103 - 471.104 - ; different types of sets 471.105 - (set/intersection (hash-set 1 2) (hash-set 2 3)) #{2} 471.106 - (set/intersection (sorted-set 1 2) (sorted-set 2 3)) #{2} 471.107 - (set/intersection 471.108 - (hash-set 1 2) (hash-set 2 3) 471.109 - (sorted-set 1 2) (sorted-set 2 3)) #{2} )) 471.110 - 471.111 -(deftest test-difference 471.112 - (are [x y] (= x y) 471.113 - ; identity 471.114 - (set/difference #{}) #{} 471.115 - (set/difference #{1}) #{1} 471.116 - (set/difference #{1 2 3}) #{1 2 3} 471.117 - 471.118 - ; 2 sets 471.119 - (set/difference #{1 2} #{1 2}) #{} 471.120 - (set/difference #{1 2} #{3 4}) #{1 2} 471.121 - (set/difference #{1 2} #{1}) #{2} 471.122 - (set/difference #{1 2} #{2}) #{1} 471.123 - (set/difference #{1 2 4} #{2 3 4 5}) #{1} 471.124 - 471.125 - ; 3 sets 471.126 - (set/difference #{1 2} #{2 3} #{5 2}) #{1} 471.127 - (set/difference #{1 2 3} #{1 3 4} #{1 3}) #{2} 471.128 - (set/difference #{1 2 3} #{3 4 5} #{8 2 3}) #{1} )) 471.129 - 471.130 -(deftest test-select 471.131 - (are [x y] (= x y) 471.132 - (set/select integer? #{}) #{} 471.133 - (set/select integer? #{1 2}) #{1 2} 471.134 - (set/select integer? #{1 2 :a :b :c}) #{1 2} 471.135 - (set/select integer? #{:a :b :c}) #{}) ) 471.136 - 471.137 -(def compositions 471.138 - #{{:name "Art of the Fugue" :composer "J. S. Bach"} 471.139 - {:name "Musical Offering" :composer "J. S. Bach"} 471.140 - {:name "Requiem" :composer "Giuseppe Verdi"} 471.141 - {:name "Requiem" :composer "W. A. Mozart"}}) 471.142 - 471.143 -(deftest test-project 471.144 - (are [x y] (= x y) 471.145 - (set/project compositions [:name]) #{{:name "Art of the Fugue"} 471.146 - {:name "Requiem"} 471.147 - {:name "Musical Offering"}} 471.148 - (set/project compositions [:composer]) #{{:composer "W. A. Mozart"} 471.149 - {:composer "Giuseppe Verdi"} 471.150 - {:composer "J. S. Bach"}} 471.151 - (set/project compositions [:year]) #{{}} 471.152 - (set/project #{{}} [:name]) #{{}} )) 471.153 - 471.154 -(deftest test-rename 471.155 - (are [x y] (= x y) 471.156 - (set/rename compositions {:name :title}) #{{:title "Art of the Fugue" :composer "J. S. Bach"} 471.157 - {:title "Musical Offering" :composer "J. S. Bach"} 471.158 - {:title "Requiem" :composer "Giuseppe Verdi"} 471.159 - {:title "Requiem" :composer "W. A. Mozart"}} 471.160 - (set/rename compositions {:year :decade}) #{{:name "Art of the Fugue" :composer "J. S. Bach"} 471.161 - {:name "Musical Offering" :composer "J. S. Bach"} 471.162 - {:name "Requiem" :composer "Giuseppe Verdi"} 471.163 - {:name "Requiem" :composer "W. A. Mozart"}} 471.164 - (set/rename #{{}} {:year :decade}) #{{}})) 471.165 - 471.166 -(deftest test-rename-keys 471.167 - (are [x y] (= x y) 471.168 - (set/rename-keys {:a "one" :b "two"} {:a :z}) {:z "one" :b "two"} 471.169 - )) 471.170 - 471.171 -(deftest test-index 471.172 - (are [x y] (= x y) 471.173 - (set/index #{{:c 2} {:b 1} {:a 1 :b 2}} [:b]) {{:b 2} #{{:a 1 :b 2}}, {:b 1} #{{:b 1}} {} #{{:c 2}}} 471.174 - )) 471.175 - 471.176 -(deftest test-join 471.177 - (are [x y] (= x y) 471.178 - (set/join compositions compositions) compositions 471.179 - (set/join compositions #{{:name "Art of the Fugue" :genre "Classical"}}) 471.180 - #{{:name "Art of the Fugue" :composer "J. S. Bach" :genre "Classical"}} 471.181 - )) 471.182 - 471.183 -(deftest test-map-invert 471.184 - (are [x y] (= x y) 471.185 - (set/map-invert {:a "one" :b "two"}) {"one" :a "two" :b})) 471.186 - 471.187 -(deftest test-subset? 471.188 - (are [sub super] (set/subset? sub super) 471.189 - #{} #{} 471.190 - #{} #{1} 471.191 - #{1} #{1} 471.192 - #{1 2} #{1 2} 471.193 - #{1 2} #{1 2 42}) 471.194 - (are [notsub super] (not (set/subset? notsub super)) 471.195 - #{1} #{} 471.196 - #{2} #{1} 471.197 - #{1 3} #{1})) 471.198 - 471.199 -(deftest test-superset? 471.200 - (are [super sub] (set/superset? super sub) 471.201 - #{} #{} 471.202 - #{1} #{} 471.203 - #{1} #{1} 471.204 - #{1 2} #{1 2} 471.205 - #{1 2 42} #{1 2}) 471.206 - (are [notsuper sub] (not (set/superset? notsuper sub)) 471.207 - #{} #{1} 471.208 - #{2} #{1} 471.209 - #{1} #{1 3}))
472.1 --- a/src/clojure/test_clojure/clojure_xml.clj Sat Aug 21 06:25:44 2010 -0400 472.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 472.3 @@ -1,21 +0,0 @@ 472.4 -; Copyright (c) Rich Hickey. All rights reserved. 472.5 -; The use and distribution terms for this software are covered by the 472.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 472.7 -; which can be found in the file epl-v10.html at the root of this distribution. 472.8 -; By using this software in any fashion, you are agreeing to be bound by 472.9 -; the terms of this license. 472.10 -; You must not remove this notice, or any other, from this software. 472.11 - 472.12 -;;Author: Frantisek Sodomka 472.13 - 472.14 - 472.15 -(ns clojure.test-clojure.clojure-xml 472.16 - (:use clojure.test) 472.17 - (:require [clojure.xml :as xml])) 472.18 - 472.19 - 472.20 -; parse 472.21 - 472.22 -; emit-element 472.23 -; emit 472.24 -
473.1 --- a/src/clojure/test_clojure/clojure_zip.clj Sat Aug 21 06:25:44 2010 -0400 473.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 473.3 @@ -1,48 +0,0 @@ 473.4 -; Copyright (c) Rich Hickey. All rights reserved. 473.5 -; The use and distribution terms for this software are covered by the 473.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 473.7 -; which can be found in the file epl-v10.html at the root of this distribution. 473.8 -; By using this software in any fashion, you are agreeing to be bound by 473.9 -; the terms of this license. 473.10 -; You must not remove this notice, or any other, from this software. 473.11 - 473.12 -; Author: Frantisek Sodomka 473.13 - 473.14 - 473.15 -(ns clojure.test-clojure.clojure-zip 473.16 - (:use clojure.test) 473.17 - (:require [clojure.zip :as zip])) 473.18 - 473.19 - 473.20 -; zipper 473.21 -; 473.22 -; seq-zip 473.23 -; vector-zip 473.24 -; xml-zip 473.25 -; 473.26 -; node 473.27 -; branch? 473.28 -; children 473.29 -; make-node 473.30 -; path 473.31 -; lefts 473.32 -; rights 473.33 -; down 473.34 -; up 473.35 -; root 473.36 -; right 473.37 -; rightmost 473.38 -; left 473.39 -; leftmost 473.40 -; 473.41 -; insert-left 473.42 -; insert-right 473.43 -; replace 473.44 -; edit 473.45 -; insert-child 473.46 -; append-child 473.47 -; next 473.48 -; prev 473.49 -; end? 473.50 -; remove 473.51 -
474.1 --- a/src/clojure/test_clojure/compilation.clj Sat Aug 21 06:25:44 2010 -0400 474.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 474.3 @@ -1,52 +0,0 @@ 474.4 -; Copyright (c) Rich Hickey. All rights reserved. 474.5 -; The use and distribution terms for this software are covered by the 474.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 474.7 -; which can be found in the file epl-v10.html at the root of this distribution. 474.8 -; By using this software in any fashion, you are agreeing to be bound by 474.9 -; the terms of this license. 474.10 -; You must not remove this notice, or any other, from this software. 474.11 - 474.12 -; Author: Frantisek Sodomka 474.13 - 474.14 - 474.15 -(ns clojure.test-clojure.compilation 474.16 - (:use clojure.test)) 474.17 - 474.18 -; http://clojure.org/compilation 474.19 - 474.20 -; compile 474.21 -; gen-class, gen-interface 474.22 - 474.23 - 474.24 -(deftest test-compiler-metadata 474.25 - (let [m (meta #'when)] 474.26 - (are [x y] (= x y) 474.27 - (list? (:arglists m)) true 474.28 - (> (count (:arglists m)) 0) true 474.29 - 474.30 - (string? (:doc m)) true 474.31 - (> (.length (:doc m)) 0) true 474.32 - 474.33 - (string? (:file m)) true 474.34 - (> (.length (:file m)) 0) true 474.35 - 474.36 - (integer? (:line m)) true 474.37 - (> (:line m) 0) true 474.38 - 474.39 - (:macro m) true 474.40 - (:name m) 'when ))) 474.41 - 474.42 -(deftest test-embedded-constants 474.43 - (testing "Embedded constants" 474.44 - (is (eval `(= Boolean/TYPE ~Boolean/TYPE))) 474.45 - (is (eval `(= Byte/TYPE ~Byte/TYPE))) 474.46 - (is (eval `(= Character/TYPE ~Character/TYPE))) 474.47 - (is (eval `(= Double/TYPE ~Double/TYPE))) 474.48 - (is (eval `(= Float/TYPE ~Float/TYPE))) 474.49 - (is (eval `(= Integer/TYPE ~Integer/TYPE))) 474.50 - (is (eval `(= Long/TYPE ~Long/TYPE))) 474.51 - (is (eval `(= Short/TYPE ~Short/TYPE))))) 474.52 - 474.53 -(deftest test-compiler-resolution 474.54 - (testing "resolve nonexistent class create should return nil (assembla #262)" 474.55 - (is (nil? (resolve 'NonExistentClass.)))))
475.1 --- a/src/clojure/test_clojure/control.clj Sat Aug 21 06:25:44 2010 -0400 475.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 475.3 @@ -1,333 +0,0 @@ 475.4 -; Copyright (c) Rich Hickey. All rights reserved. 475.5 -; The use and distribution terms for this software are covered by the 475.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 475.7 -; which can be found in the file epl-v10.html at the root of this distribution. 475.8 -; By using this software in any fashion, you are agreeing to be bound by 475.9 -; the terms of this license. 475.10 -; You must not remove this notice, or any other, from this software. 475.11 - 475.12 -; Author: Frantisek Sodomka, Mike Hinchey, Stuart Halloway 475.13 - 475.14 -;; 475.15 -;; Test "flow control" constructs. 475.16 -;; 475.17 - 475.18 -(ns clojure.test-clojure.control 475.19 - (:use clojure.test 475.20 - [clojure.test-clojure.helpers :only (exception)])) 475.21 - 475.22 -;; *** Helper functions *** 475.23 - 475.24 -(defn maintains-identity [f] 475.25 - (are [x] (= (f x) x) 475.26 - nil 475.27 - false true 475.28 - 0 42 475.29 - 0.0 3.14 475.30 - 2/3 475.31 - 0M 1M 475.32 - \c 475.33 - "" "abc" 475.34 - 'sym 475.35 - :kw 475.36 - () '(1 2) 475.37 - [] [1 2] 475.38 - {} {:a 1 :b 2} 475.39 - #{} #{1 2} )) 475.40 - 475.41 - 475.42 -; http://clojure.org/special_forms 475.43 -; http://clojure.org/macros 475.44 - 475.45 -(deftest test-do 475.46 - (are [x y] (= x y) 475.47 - ; no params => nil 475.48 - (do) nil 475.49 - 475.50 - ; return last 475.51 - (do 1) 1 475.52 - (do 1 2) 2 475.53 - (do 1 2 3 4 5) 5 475.54 - 475.55 - ; evaluate and return last 475.56 - (let [a (atom 0)] 475.57 - (do (reset! a (+ @a 1)) ; 1 475.58 - (reset! a (+ @a 1)) ; 2 475.59 - (reset! a (+ @a 1)) ; 3 475.60 - @a)) 3 ) 475.61 - 475.62 - ; identity (= (do x) x) 475.63 - (maintains-identity (fn [_] (do _))) ) 475.64 - 475.65 - 475.66 -;; loop/recur 475.67 -(deftest test-loop 475.68 - (are [x y] (= x y) 475.69 - 1 (loop [] 475.70 - 1) 475.71 - 3 (loop [a 1] 475.72 - (if (< a 3) 475.73 - (recur (inc a)) 475.74 - a)) 475.75 - [2 4 6] (loop [a [] 475.76 - b [1 2 3]] 475.77 - (if (seq b) 475.78 - (recur (conj a (* 2 (first b))) 475.79 - (next b)) 475.80 - a)) 475.81 - [6 4 2] (loop [a () 475.82 - b [1 2 3]] 475.83 - (if (seq b) 475.84 - (recur (conj a (* 2 (first b))) 475.85 - (next b)) 475.86 - a)) 475.87 - ) 475.88 - ) 475.89 - 475.90 - 475.91 -;; throw, try 475.92 - 475.93 -; if: see logic.clj 475.94 - 475.95 -(deftest test-when 475.96 - (are [x y] (= x y) 475.97 - 1 (when true 1) 475.98 - nil (when true) 475.99 - nil (when false) 475.100 - nil (when false (exception)) 475.101 - )) 475.102 - 475.103 -(deftest test-when-not 475.104 - (are [x y] (= x y) 475.105 - 1 (when-not false 1) 475.106 - nil (when-not true) 475.107 - nil (when-not false) 475.108 - nil (when-not true (exception)) 475.109 - )) 475.110 - 475.111 -(deftest test-if-not 475.112 - (are [x y] (= x y) 475.113 - 1 (if-not false 1) 475.114 - 1 (if-not false 1 (exception)) 475.115 - nil (if-not true 1) 475.116 - 2 (if-not true 1 2) 475.117 - nil (if-not true (exception)) 475.118 - 1 (if-not true (exception) 1) 475.119 - )) 475.120 - 475.121 -(deftest test-when-let 475.122 - (are [x y] (= x y) 475.123 - 1 (when-let [a 1] 475.124 - a) 475.125 - 2 (when-let [[a b] '(1 2)] 475.126 - b) 475.127 - nil (when-let [a false] 475.128 - (exception)) 475.129 - )) 475.130 - 475.131 -(deftest test-if-let 475.132 - (are [x y] (= x y) 475.133 - 1 (if-let [a 1] 475.134 - a) 475.135 - 2 (if-let [[a b] '(1 2)] 475.136 - b) 475.137 - nil (if-let [a false] 475.138 - (exception)) 475.139 - 1 (if-let [a false] 475.140 - a 1) 475.141 - 1 (if-let [[a b] nil] 475.142 - b 1) 475.143 - 1 (if-let [a false] 475.144 - (exception) 475.145 - 1) 475.146 - )) 475.147 - 475.148 -(deftest test-when-first 475.149 - (are [x y] (= x y) 475.150 - 1 (when-first [a [1 2]] 475.151 - a) 475.152 - 2 (when-first [[a b] '((1 2) 3)] 475.153 - b) 475.154 - nil (when-first [a nil] 475.155 - (exception)) 475.156 - )) 475.157 - 475.158 - 475.159 -(deftest test-cond 475.160 - (are [x y] (= x y) 475.161 - (cond) nil 475.162 - 475.163 - (cond nil true) nil 475.164 - (cond false true) nil 475.165 - 475.166 - (cond true 1 true (exception)) 1 475.167 - (cond nil 1 false 2 true 3 true 4) 3 475.168 - (cond nil 1 false 2 true 3 true (exception)) 3 ) 475.169 - 475.170 - ; false 475.171 - (are [x] (= (cond x :a true :b) :b) 475.172 - nil false ) 475.173 - 475.174 - ; true 475.175 - (are [x] (= (cond x :a true :b) :a) 475.176 - true 475.177 - 0 42 475.178 - 0.0 3.14 475.179 - 2/3 475.180 - 0M 1M 475.181 - \c 475.182 - "" "abc" 475.183 - 'sym 475.184 - :kw 475.185 - () '(1 2) 475.186 - [] [1 2] 475.187 - {} {:a 1 :b 2} 475.188 - #{} #{1 2} ) 475.189 - 475.190 - ; evaluation 475.191 - (are [x y] (= x y) 475.192 - (cond (> 3 2) (+ 1 2) true :result true (exception)) 3 475.193 - (cond (< 3 2) (+ 1 2) true :result true (exception)) :result ) 475.194 - 475.195 - ; identity (= (cond true x) x) 475.196 - (maintains-identity (fn [_] (cond true _))) ) 475.197 - 475.198 - 475.199 -(deftest test-condp 475.200 - (are [x] (= :pass x) 475.201 - (condp = 1 475.202 - 1 :pass 475.203 - 2 :fail) 475.204 - (condp = 1 475.205 - 2 :fail 475.206 - 1 :pass) 475.207 - (condp = 1 475.208 - 2 :fail 475.209 - :pass) 475.210 - (condp = 1 475.211 - :pass) 475.212 - (condp = 1 475.213 - 2 :fail 475.214 - ;; doc of condp says result-expr is returned 475.215 - ;; shouldn't it say similar to cond: "evaluates and returns 475.216 - ;; the value of the corresponding expr and doesn't evaluate any of the 475.217 - ;; other tests or exprs." 475.218 - (identity :pass)) 475.219 - (condp + 1 475.220 - 1 :>> #(if (= % 2) :pass :fail)) 475.221 - (condp + 1 475.222 - 1 :>> #(if (= % 3) :fail :pass)) 475.223 - ) 475.224 - (is (thrown? IllegalArgumentException 475.225 - (condp = 1) 475.226 - )) 475.227 - (is (thrown? IllegalArgumentException 475.228 - (condp = 1 475.229 - 2 :fail) 475.230 - )) 475.231 - ) 475.232 - 475.233 - 475.234 -; [for, doseq (for.clj)] 475.235 - 475.236 -(deftest test-dotimes 475.237 - ;; dotimes always returns nil 475.238 - (is (= nil (dotimes [n 1] n))) 475.239 - ;; test using an atom since dotimes is for modifying 475.240 - ;; test executes n times 475.241 - (is (= 3 475.242 - (let [a (atom 0)] 475.243 - (dotimes [n 3] 475.244 - (swap! a inc)) 475.245 - @a) 475.246 - )) 475.247 - ;; test all values of n 475.248 - (is (= [0 1 2] 475.249 - (let [a (atom [])] 475.250 - (dotimes [n 3] 475.251 - (swap! a conj n)) 475.252 - @a))) 475.253 - (is (= [] 475.254 - (let [a (atom [])] 475.255 - (dotimes [n 0] 475.256 - (swap! a conj n)) 475.257 - @a))) 475.258 - ) 475.259 - 475.260 -(deftest test-while 475.261 - (is (= nil (while nil (throw (Exception. "never"))))) 475.262 - (is (= [0 nil] 475.263 - ;; a will dec to 0 475.264 - ;; while always returns nil 475.265 - (let [a (atom 3) 475.266 - w (while (pos? @a) 475.267 - (swap! a dec))] 475.268 - [@a w]))) 475.269 - (is (thrown? Exception (while true (throw (Exception. "expected to throw"))))) 475.270 - ) 475.271 - 475.272 -; locking, monitor-enter, monitor-exit 475.273 - 475.274 -; case 475.275 -(deftest test-case 475.276 - (testing "can match many kinds of things" 475.277 - (let [two 2 475.278 - test-fn 475.279 - #(case % 475.280 - 1 :number 475.281 - "foo" :string 475.282 - \a :char 475.283 - pow :symbol 475.284 - :zap :keyword 475.285 - (2 \b "bar") :one-of-many 475.286 - [1 2] :sequential-thing 475.287 - {:a 2} :map 475.288 - {:r 2 :d 2} :droid 475.289 - #{2 3 4 5} :set 475.290 - [1 [[[2]]]] :deeply-nested 475.291 - :default)] 475.292 - (are [result input] (= result (test-fn input)) 475.293 - :number 1 475.294 - :string "foo" 475.295 - :char \a 475.296 - :keyword :zap 475.297 - :symbol 'pow 475.298 - :one-of-many 2 475.299 - :one-of-many \b 475.300 - :one-of-many "bar" 475.301 - :sequential-thing [1 2] 475.302 - :sequential-thing (list 1 2) 475.303 - :sequential-thing [1 two] 475.304 - :map {:a 2} 475.305 - :map {:a two} 475.306 - :set #{2 3 4 5} 475.307 - :set #{two 3 4 5} 475.308 - :default #{2 3 4 5 6} 475.309 - :droid {:r 2 :d 2} 475.310 - :deeply-nested [1 [[[two]]]] 475.311 - :default :anything-not-appearing-above))) 475.312 - (testing "throws IllegalArgumentException if no match" 475.313 - (is (thrown-with-msg? 475.314 - IllegalArgumentException #"No matching clause: 2" 475.315 - (case 2 1 :ok)))) 475.316 - (testing "sorting doesn't matter" 475.317 - (let [test-fn 475.318 - #(case % 475.319 - {:b 2 :a 1} :map 475.320 - #{3 2 1} :set 475.321 - :default)] 475.322 - (are [result input] (= result (test-fn input)) 475.323 - :map {:a 1 :b 2} 475.324 - :map (sorted-map :a 1 :b 2) 475.325 - :set #{3 2 1} 475.326 - :set (sorted-set 2 1 3)))) 475.327 - (testing "test constants are *not* evaluated" 475.328 - (let [test-fn 475.329 - ;; never write code like this... 475.330 - #(case % 475.331 - (throw (RuntimeException. "boom")) :piece-of-throw-expr 475.332 - :no-match)] 475.333 - (are [result input] (= result (test-fn input)) 475.334 - :piece-of-throw-expr 'throw 475.335 - :piece-of-throw-expr '[RuntimeException. "boom"] 475.336 - :no-match nil))))
476.1 --- a/src/clojure/test_clojure/data_structures.clj Sat Aug 21 06:25:44 2010 -0400 476.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 476.3 @@ -1,830 +0,0 @@ 476.4 -; Copyright (c) Rich Hickey. All rights reserved. 476.5 -; The use and distribution terms for this software are covered by the 476.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 476.7 -; which can be found in the file epl-v10.html at the root of this distribution. 476.8 -; By using this software in any fashion, you are agreeing to be bound by 476.9 -; the terms of this license. 476.10 -; You must not remove this notice, or any other, from this software. 476.11 - 476.12 -; Author: Frantisek Sodomka 476.13 - 476.14 - 476.15 -(ns clojure.test-clojure.data-structures 476.16 - (:use clojure.test)) 476.17 - 476.18 - 476.19 -;; *** Helper functions *** 476.20 - 476.21 -(defn diff [s1 s2] 476.22 - (seq (reduce disj (set s1) (set s2)))) 476.23 - 476.24 - 476.25 -;; *** General *** 476.26 - 476.27 -(defstruct equality-struct :a :b) 476.28 - 476.29 -(deftest test-equality 476.30 - ; nil is not equal to any other value 476.31 - (are [x] (not (= nil x)) 476.32 - true false 476.33 - 0 0.0 476.34 - \space 476.35 - "" #"" 476.36 - () [] #{} {} 476.37 - (lazy-seq nil) ; SVN 1292: fixed (= (lazy-seq nil) nil) 476.38 - (lazy-seq ()) 476.39 - (lazy-seq []) 476.40 - (lazy-seq {}) 476.41 - (lazy-seq #{}) 476.42 - (lazy-seq "") 476.43 - (lazy-seq (into-array [])) 476.44 - (new Object) ) 476.45 - 476.46 - ; numbers equality across types (see tests below - NOT IMPLEMENTED YET) 476.47 - 476.48 - ; ratios 476.49 - (is (= 1/2 0.5)) 476.50 - (is (= 1/1000 0.001)) 476.51 - (is (not= 2/3 0.6666666666666666)) 476.52 - 476.53 - ; vectors equal other seqs by items equality 476.54 - (are [x y] (= x y) 476.55 - '() [] ; regression fixed in r1208; was not equal 476.56 - '(1) [1] 476.57 - '(1 2) [1 2] 476.58 - 476.59 - [] '() ; same again, but vectors first 476.60 - [1] '(1) 476.61 - [1 2] '(1 2) ) 476.62 - (is (not= [1 2] '(2 1))) ; order of items matters 476.63 - 476.64 - ; list and vector vs. set and map 476.65 - (are [x y] (not= x y) 476.66 - ; only () equals [] 476.67 - () #{} 476.68 - () {} 476.69 - [] #{} 476.70 - [] {} 476.71 - #{} {} 476.72 - ; only '(1) equals [1] 476.73 - '(1) #{1} 476.74 - [1] #{1} ) 476.75 - 476.76 - ; sorted-map, hash-map and array-map - classes differ, but content is equal 476.77 - 476.78 -;; TODO: reimplement all-are with new do-template? 476.79 -;; (all-are (not= (class _1) (class _2)) 476.80 -;; (sorted-map :a 1) 476.81 -;; (hash-map :a 1) 476.82 -;; (array-map :a 1)) 476.83 -;; (all-are (= _1 _2) 476.84 -;; (sorted-map) 476.85 -;; (hash-map) 476.86 -;; (array-map)) 476.87 -;; (all-are (= _1 _2) 476.88 -;; (sorted-map :a 1) 476.89 -;; (hash-map :a 1) 476.90 -;; (array-map :a 1)) 476.91 -;; (all-are (= _1 _2) 476.92 -;; (sorted-map :a 1 :z 3 :c 2) 476.93 -;; (hash-map :a 1 :z 3 :c 2) 476.94 -;; (array-map :a 1 :z 3 :c 2)) 476.95 - 476.96 - ; struct-map vs. sorted-map, hash-map and array-map 476.97 - (are [x] (and (not= (class (struct equality-struct 1 2)) (class x)) 476.98 - (= (struct equality-struct 1 2) x)) 476.99 - (sorted-map-by compare :a 1 :b 2) 476.100 - (sorted-map :a 1 :b 2) 476.101 - (hash-map :a 1 :b 2) 476.102 - (array-map :a 1 :b 2)) 476.103 - 476.104 - ; sorted-set vs. hash-set 476.105 - (is (not= (class (sorted-set 1)) (class (hash-set 1)))) 476.106 - (are [x y] (= x y) 476.107 - (sorted-set-by <) (hash-set) 476.108 - (sorted-set-by < 1) (hash-set 1) 476.109 - (sorted-set-by < 3 2 1) (hash-set 3 2 1) 476.110 - (sorted-set) (hash-set) 476.111 - (sorted-set 1) (hash-set 1) 476.112 - (sorted-set 3 2 1) (hash-set 3 2 1) )) 476.113 - 476.114 - 476.115 -;; *** Collections *** 476.116 - 476.117 -(deftest test-count 476.118 - (are [x y] (= x y) 476.119 - (count nil) 0 476.120 - 476.121 - (count ()) 0 476.122 - (count '(1)) 1 476.123 - (count '(1 2 3)) 3 476.124 - 476.125 - (count []) 0 476.126 - (count [1]) 1 476.127 - (count [1 2 3]) 3 476.128 - 476.129 - (count #{}) 0 476.130 - (count #{1}) 1 476.131 - (count #{1 2 3}) 3 476.132 - 476.133 - (count {}) 0 476.134 - (count {:a 1}) 1 476.135 - (count {:a 1 :b 2 :c 3}) 3 476.136 - 476.137 - (count "") 0 476.138 - (count "a") 1 476.139 - (count "abc") 3 476.140 - 476.141 - (count (into-array [])) 0 476.142 - (count (into-array [1])) 1 476.143 - (count (into-array [1 2 3])) 3 476.144 - 476.145 - (count (java.util.ArrayList. [])) 0 476.146 - (count (java.util.ArrayList. [1])) 1 476.147 - (count (java.util.ArrayList. [1 2 3])) 3 476.148 - 476.149 - (count (java.util.HashMap. {})) 0 476.150 - (count (java.util.HashMap. {:a 1})) 1 476.151 - (count (java.util.HashMap. {:a 1 :b 2 :c 3})) 3 ) 476.152 - 476.153 - ; different types 476.154 - (are [x] (= (count [x]) 1) 476.155 - nil true false 476.156 - 0 0.0 "" \space 476.157 - () [] #{} {} )) 476.158 - 476.159 - 476.160 -(deftest test-conj 476.161 - ; doesn't work on strings or arrays 476.162 - (is (thrown? ClassCastException (conj "" \a))) 476.163 - (is (thrown? ClassCastException (conj (into-array []) 1))) 476.164 - 476.165 - (are [x y] (= x y) 476.166 - (conj nil 1) '(1) 476.167 - (conj nil 3 2 1) '(1 2 3) 476.168 - 476.169 - (conj nil nil) '(nil) 476.170 - (conj nil nil nil) '(nil nil) 476.171 - (conj nil nil nil 1) '(1 nil nil) 476.172 - 476.173 - ; list -> conj puts the item at the front of the list 476.174 - (conj () 1) '(1) 476.175 - (conj () 1 2) '(2 1) 476.176 - 476.177 - (conj '(2 3) 1) '(1 2 3) 476.178 - (conj '(2 3) 1 4 3) '(3 4 1 2 3) 476.179 - 476.180 - (conj () nil) '(nil) 476.181 - (conj () ()) '(()) 476.182 - 476.183 - ; vector -> conj puts the item at the end of the vector 476.184 - (conj [] 1) [1] 476.185 - (conj [] 1 2) [1 2] 476.186 - 476.187 - (conj [2 3] 1) [2 3 1] 476.188 - (conj [2 3] 1 4 3) [2 3 1 4 3] 476.189 - 476.190 - (conj [] nil) [nil] 476.191 - (conj [] []) [[]] 476.192 - 476.193 - ; map -> conj expects another (possibly single entry) map as the item, 476.194 - ; and returns a new map which is the old map plus the entries 476.195 - ; from the new, which may overwrite entries of the old. 476.196 - ; conj also accepts a MapEntry or a vector of two items (key and value). 476.197 - (conj {} {}) {} 476.198 - (conj {} {:a 1}) {:a 1} 476.199 - (conj {} {:a 1 :b 2}) {:a 1 :b 2} 476.200 - (conj {} {:a 1 :b 2} {:c 3}) {:a 1 :b 2 :c 3} 476.201 - (conj {} {:a 1 :b 2} {:a 3 :c 4}) {:a 3 :b 2 :c 4} 476.202 - 476.203 - (conj {:a 1} {:a 7}) {:a 7} 476.204 - (conj {:a 1} {:b 2}) {:a 1 :b 2} 476.205 - (conj {:a 1} {:a 7 :b 2}) {:a 7 :b 2} 476.206 - (conj {:a 1} {:a 7 :b 2} {:c 3}) {:a 7 :b 2 :c 3} 476.207 - (conj {:a 1} {:a 7 :b 2} {:b 4 :c 5}) {:a 7 :b 4 :c 5} 476.208 - 476.209 - (conj {} (first {:a 1})) {:a 1} ; MapEntry 476.210 - (conj {:a 1} (first {:b 2})) {:a 1 :b 2} 476.211 - (conj {:a 1} (first {:a 7})) {:a 7} 476.212 - (conj {:a 1} (first {:b 2}) (first {:a 5})) {:a 5 :b 2} 476.213 - 476.214 - (conj {} [:a 1]) {:a 1} ; vector 476.215 - (conj {:a 1} [:b 2]) {:a 1 :b 2} 476.216 - (conj {:a 1} [:a 7]) {:a 7} 476.217 - (conj {:a 1} [:b 2] [:a 5]) {:a 5 :b 2} 476.218 - 476.219 - (conj {} {nil {}}) {nil {}} 476.220 - (conj {} {{} nil}) {{} nil} 476.221 - (conj {} {{} {}}) {{} {}} 476.222 - 476.223 - ; set 476.224 - (conj #{} 1) #{1} 476.225 - (conj #{} 1 2 3) #{1 2 3} 476.226 - 476.227 - (conj #{2 3} 1) #{3 1 2} 476.228 - (conj #{3 2} 1) #{1 2 3} 476.229 - 476.230 - (conj #{2 3} 2) #{2 3} 476.231 - (conj #{2 3} 2 3) #{2 3} 476.232 - (conj #{2 3} 4 1 2 3) #{1 2 3 4} 476.233 - 476.234 - (conj #{} nil) #{nil} 476.235 - (conj #{} #{}) #{#{}} )) 476.236 - 476.237 - 476.238 -;; *** Lists and Vectors *** 476.239 - 476.240 -(deftest test-peek 476.241 - ; doesn't work for sets and maps 476.242 - (is (thrown? ClassCastException (peek #{1}))) 476.243 - (is (thrown? ClassCastException (peek {:a 1}))) 476.244 - 476.245 - (are [x y] (= x y) 476.246 - (peek nil) nil 476.247 - 476.248 - ; list = first 476.249 - (peek ()) nil 476.250 - (peek '(1)) 1 476.251 - (peek '(1 2 3)) 1 476.252 - 476.253 - (peek '(nil)) nil ; special cases 476.254 - (peek '(1 nil)) 1 476.255 - (peek '(nil 2)) nil 476.256 - (peek '(())) () 476.257 - (peek '(() nil)) () 476.258 - (peek '(() 2 nil)) () 476.259 - 476.260 - ; vector = last 476.261 - (peek []) nil 476.262 - (peek [1]) 1 476.263 - (peek [1 2 3]) 3 476.264 - 476.265 - (peek [nil]) nil ; special cases 476.266 - (peek [1 nil]) nil 476.267 - (peek [nil 2]) 2 476.268 - (peek [[]]) [] 476.269 - (peek [[] nil]) nil 476.270 - (peek [[] 2 nil]) nil )) 476.271 - 476.272 - 476.273 -(deftest test-pop 476.274 - ; doesn't work for sets and maps 476.275 - (is (thrown? ClassCastException (pop #{1}))) 476.276 - (is (thrown? ClassCastException (pop #{:a 1}))) 476.277 - 476.278 - ; collection cannot be empty 476.279 - (is (thrown? IllegalStateException (pop ()))) 476.280 - (is (thrown? IllegalStateException (pop []))) 476.281 - 476.282 - (are [x y] (= x y) 476.283 - (pop nil) nil 476.284 - 476.285 - ; list - pop first 476.286 - (pop '(1)) () 476.287 - (pop '(1 2 3)) '(2 3) 476.288 - 476.289 - (pop '(nil)) () 476.290 - (pop '(1 nil)) '(nil) 476.291 - (pop '(nil 2)) '(2) 476.292 - (pop '(())) () 476.293 - (pop '(() nil)) '(nil) 476.294 - (pop '(() 2 nil)) '(2 nil) 476.295 - 476.296 - ; vector - pop last 476.297 - (pop [1]) [] 476.298 - (pop [1 2 3]) [1 2] 476.299 - 476.300 - (pop [nil]) [] 476.301 - (pop [1 nil]) [1] 476.302 - (pop [nil 2]) [nil] 476.303 - (pop [[]]) [] 476.304 - (pop [[] nil]) [[]] 476.305 - (pop [[] 2 nil]) [[] 2] )) 476.306 - 476.307 - 476.308 -;; *** Lists (IPersistentList) *** 476.309 - 476.310 -(deftest test-list 476.311 - (are [x] (list? x) 476.312 - () 476.313 - '() 476.314 - (list) 476.315 - (list 1 2 3) ) 476.316 - 476.317 - ; order is important 476.318 - (are [x y] (not (= x y)) 476.319 - (list 1 2) (list 2 1) 476.320 - (list 3 1 2) (list 1 2 3) ) 476.321 - 476.322 - (are [x y] (= x y) 476.323 - '() () 476.324 - (list) '() 476.325 - (list 1) '(1) 476.326 - (list 1 2) '(1 2) 476.327 - 476.328 - ; nesting 476.329 - (list 1 (list 2 3) (list 3 (list 4 5 (list 6 (list 7))))) 476.330 - '(1 (2 3) (3 (4 5 (6 (7))))) 476.331 - 476.332 - ; different data structures 476.333 - (list true false nil) 476.334 - '(true false nil) 476.335 - (list 1 2.5 2/3 "ab" \x 'cd :kw) 476.336 - '(1 2.5 2/3 "ab" \x cd :kw) 476.337 - (list (list 1 2) [3 4] {:a 1 :b 2} #{:c :d}) 476.338 - '((1 2) [3 4] {:a 1 :b 2} #{:c :d}) 476.339 - 476.340 - ; evaluation 476.341 - (list (+ 1 2) [(+ 2 3) 'a] (list (* 2 3) 8)) 476.342 - '(3 [5 a] (6 8)) 476.343 - 476.344 - ; special cases 476.345 - (list nil) '(nil) 476.346 - (list 1 nil) '(1 nil) 476.347 - (list nil 2) '(nil 2) 476.348 - (list ()) '(()) 476.349 - (list 1 ()) '(1 ()) 476.350 - (list () 2) '(() 2) )) 476.351 - 476.352 - 476.353 -;; *** Maps (IPersistentMap) *** 476.354 - 476.355 -(deftest test-find 476.356 - (are [x y] (= x y) 476.357 - (find {} :a) nil 476.358 - 476.359 - (find {:a 1} :a) [:a 1] 476.360 - (find {:a 1} :b) nil 476.361 - 476.362 - (find {:a 1 :b 2} :a) [:a 1] 476.363 - (find {:a 1 :b 2} :b) [:b 2] 476.364 - (find {:a 1 :b 2} :c) nil 476.365 - 476.366 - (find {} nil) nil 476.367 - (find {:a 1} nil) nil 476.368 - (find {:a 1 :b 2} nil) nil )) 476.369 - 476.370 - 476.371 -(deftest test-contains? 476.372 - ; contains? is designed to work preferably on maps and sets 476.373 - (are [x y] (= x y) 476.374 - (contains? {} :a) false 476.375 - (contains? {} nil) false 476.376 - 476.377 - (contains? {:a 1} :a) true 476.378 - (contains? {:a 1} :b) false 476.379 - (contains? {:a 1} nil) false 476.380 - 476.381 - (contains? {:a 1 :b 2} :a) true 476.382 - (contains? {:a 1 :b 2} :b) true 476.383 - (contains? {:a 1 :b 2} :c) false 476.384 - (contains? {:a 1 :b 2} nil) false 476.385 - 476.386 - ; sets 476.387 - (contains? #{} 1) false 476.388 - (contains? #{} nil) false 476.389 - 476.390 - (contains? #{1} 1) true 476.391 - (contains? #{1} 2) false 476.392 - (contains? #{1} nil) false 476.393 - 476.394 - (contains? #{1 2 3} 1) true 476.395 - (contains? #{1 2 3} 3) true 476.396 - (contains? #{1 2 3} 10) false 476.397 - (contains? #{1 2 3} nil) false) 476.398 - 476.399 - ; numerically indexed collections (e.g. vectors and Java arrays) 476.400 - ; => test if the numeric key is WITHIN THE RANGE OF INDEXES 476.401 - (are [x y] (= x y) 476.402 - (contains? [] 0) false 476.403 - (contains? [] -1) false 476.404 - (contains? [] 1) false 476.405 - 476.406 - (contains? [1] 0) true 476.407 - (contains? [1] -1) false 476.408 - (contains? [1] 1) false 476.409 - 476.410 - (contains? [1 2 3] 0) true 476.411 - (contains? [1 2 3] 2) true 476.412 - (contains? [1 2 3] 3) false 476.413 - (contains? [1 2 3] -1) false 476.414 - 476.415 - ; arrays 476.416 - (contains? (into-array []) 0) false 476.417 - (contains? (into-array []) -1) false 476.418 - (contains? (into-array []) 1) false 476.419 - 476.420 - (contains? (into-array [1]) 0) true 476.421 - (contains? (into-array [1]) -1) false 476.422 - (contains? (into-array [1]) 1) false 476.423 - 476.424 - (contains? (into-array [1 2 3]) 0) true 476.425 - (contains? (into-array [1 2 3]) 2) true 476.426 - (contains? (into-array [1 2 3]) 3) false 476.427 - (contains? (into-array [1 2 3]) -1) false) 476.428 - 476.429 - ; 'contains?' operates constant or logarithmic time, 476.430 - ; it WILL NOT perform a linear search for a value. 476.431 - (are [x] (= x false) 476.432 - (contains? '(1 2 3) 0) 476.433 - (contains? '(1 2 3) 1) 476.434 - (contains? '(1 2 3) 3) 476.435 - (contains? '(1 2 3) 10) 476.436 - (contains? '(1 2 3) nil) 476.437 - (contains? '(1 2 3) ()) )) 476.438 - 476.439 - 476.440 -(deftest test-keys 476.441 - (are [x y] (= x y) ; other than map data structures 476.442 - (keys ()) nil 476.443 - (keys []) nil 476.444 - (keys #{}) nil 476.445 - (keys "") nil ) 476.446 - 476.447 - (are [x y] (= x y) 476.448 - ; (class {:a 1}) => clojure.lang.PersistentArrayMap 476.449 - (keys {}) nil 476.450 - (keys {:a 1}) '(:a) 476.451 - (diff (keys {:a 1 :b 2}) '(:a :b)) nil ; (keys {:a 1 :b 2}) '(:a :b) 476.452 - 476.453 - ; (class (sorted-map :a 1)) => clojure.lang.PersistentTreeMap 476.454 - (keys (sorted-map)) nil 476.455 - (keys (sorted-map :a 1)) '(:a) 476.456 - (diff (keys (sorted-map :a 1 :b 2)) '(:a :b)) nil ; (keys (sorted-map :a 1 :b 2)) '(:a :b) 476.457 - 476.458 - ; (class (hash-map :a 1)) => clojure.lang.PersistentHashMap 476.459 - (keys (hash-map)) nil 476.460 - (keys (hash-map :a 1)) '(:a) 476.461 - (diff (keys (hash-map :a 1 :b 2)) '(:a :b)) nil )) ; (keys (hash-map :a 1 :b 2)) '(:a :b) 476.462 - 476.463 - 476.464 -(deftest test-vals 476.465 - (are [x y] (= x y) ; other than map data structures 476.466 - (vals ()) nil 476.467 - (vals []) nil 476.468 - (vals #{}) nil 476.469 - (vals "") nil ) 476.470 - 476.471 - (are [x y] (= x y) 476.472 - ; (class {:a 1}) => clojure.lang.PersistentArrayMap 476.473 - (vals {}) nil 476.474 - (vals {:a 1}) '(1) 476.475 - (diff (vals {:a 1 :b 2}) '(1 2)) nil ; (vals {:a 1 :b 2}) '(1 2) 476.476 - 476.477 - ; (class (sorted-map :a 1)) => clojure.lang.PersistentTreeMap 476.478 - (vals (sorted-map)) nil 476.479 - (vals (sorted-map :a 1)) '(1) 476.480 - (diff (vals (sorted-map :a 1 :b 2)) '(1 2)) nil ; (vals (sorted-map :a 1 :b 2)) '(1 2) 476.481 - 476.482 - ; (class (hash-map :a 1)) => clojure.lang.PersistentHashMap 476.483 - (vals (hash-map)) nil 476.484 - (vals (hash-map :a 1)) '(1) 476.485 - (diff (vals (hash-map :a 1 :b 2)) '(1 2)) nil )) ; (vals (hash-map :a 1 :b 2)) '(1 2) 476.486 - 476.487 - 476.488 -(deftest test-key 476.489 - (are [x] (= (key (first (hash-map x :value))) x) 476.490 - nil 476.491 - false true 476.492 - 0 42 476.493 - 0.0 3.14 476.494 - 2/3 476.495 - 0M 1M 476.496 - \c 476.497 - "" "abc" 476.498 - 'sym 476.499 - :kw 476.500 - () '(1 2) 476.501 - [] [1 2] 476.502 - {} {:a 1 :b 2} 476.503 - #{} #{1 2} )) 476.504 - 476.505 - 476.506 -(deftest test-val 476.507 - (are [x] (= (val (first (hash-map :key x))) x) 476.508 - nil 476.509 - false true 476.510 - 0 42 476.511 - 0.0 3.14 476.512 - 2/3 476.513 - 0M 1M 476.514 - \c 476.515 - "" "abc" 476.516 - 'sym 476.517 - :kw 476.518 - () '(1 2) 476.519 - [] [1 2] 476.520 - {} {:a 1 :b 2} 476.521 - #{} #{1 2} )) 476.522 - 476.523 -(deftest test-get 476.524 - (let [m {:a 1, :b 2, :c {:d 3, :e 4}, :f nil, :g false, nil {:h 5}}] 476.525 - (is (thrown? IllegalArgumentException (get-in {:a 1} 5))) 476.526 - (are [x y] (= x y) 476.527 - (get m :a) 1 476.528 - (get m :e) nil 476.529 - (get m :e 0) 0 476.530 - (get m :b 0) 2 476.531 - (get m :f 0) nil 476.532 - 476.533 - (get-in m [:c :e]) 4 476.534 - (get-in m '(:c :e)) 4 476.535 - (get-in m [:c :x]) nil 476.536 - (get-in m [:f]) nil 476.537 - (get-in m [:g]) false 476.538 - (get-in m [:h]) nil 476.539 - (get-in m []) m 476.540 - (get-in m nil) m 476.541 - 476.542 - (get-in m [:c :e] 0) 4 476.543 - (get-in m '(:c :e) 0) 4 476.544 - (get-in m [:c :x] 0) 0 476.545 - (get-in m [:b] 0) 2 476.546 - (get-in m [:f] 0) nil 476.547 - (get-in m [:g] 0) false 476.548 - (get-in m [:h] 0) 0 476.549 - (get-in m [:x :y] {:y 1}) {:y 1} 476.550 - (get-in m [] 0) m 476.551 - (get-in m nil 0) m))) 476.552 - 476.553 -;; *** Sets *** 476.554 - 476.555 -(deftest test-hash-set 476.556 - (are [x] (set? x) 476.557 - #{} 476.558 - #{1 2} 476.559 - (hash-set) 476.560 - (hash-set 1 2) ) 476.561 - 476.562 - ; order isn't important 476.563 - (are [x y] (= x y) 476.564 - #{1 2} #{2 1} 476.565 - #{3 1 2} #{1 2 3} 476.566 - (hash-set 1 2) (hash-set 2 1) 476.567 - (hash-set 3 1 2) (hash-set 1 2 3) ) 476.568 - 476.569 - 476.570 - (are [x y] (= x y) 476.571 - ; equal classes 476.572 - (class #{}) (class (hash-set)) 476.573 - (class #{1 2}) (class (hash-set 1 2)) 476.574 - 476.575 - ; creating 476.576 - (hash-set) #{} 476.577 - (hash-set 1) #{1} 476.578 - (hash-set 1 2) #{1 2} 476.579 - 476.580 - ; nesting 476.581 - (hash-set 1 (hash-set 2 3) (hash-set 3 (hash-set 4 5 (hash-set 6 (hash-set 7))))) 476.582 - #{1 #{2 3} #{3 #{4 5 #{6 #{7}}}}} 476.583 - 476.584 - ; different data structures 476.585 - (hash-set true false nil) 476.586 - #{true false nil} 476.587 - (hash-set 1 2.5 2/3 "ab" \x 'cd :kw) 476.588 - #{1 2.5 2/3 "ab" \x 'cd :kw} 476.589 - (hash-set (list 1 2) [3 4] {:a 1 :b 2} #{:c :d}) 476.590 - #{'(1 2) [3 4] {:a 1 :b 2} #{:c :d}} 476.591 - 476.592 - ; evaluation 476.593 - (hash-set (+ 1 2) [(+ 2 3) :a] (hash-set (* 2 3) 8)) 476.594 - #{3 [5 :a] #{6 8}} 476.595 - 476.596 - ; special cases 476.597 - (hash-set nil) #{nil} 476.598 - (hash-set 1 nil) #{1 nil} 476.599 - (hash-set nil 2) #{nil 2} 476.600 - (hash-set #{}) #{#{}} 476.601 - (hash-set 1 #{}) #{1 #{}} 476.602 - (hash-set #{} 2) #{#{} 2} )) 476.603 - 476.604 - 476.605 -(deftest test-sorted-set 476.606 - ; only compatible types can be used 476.607 - (is (thrown? ClassCastException (sorted-set 1 "a"))) 476.608 - (is (thrown? ClassCastException (sorted-set '(1 2) [3 4]))) 476.609 - 476.610 - ; creates set? 476.611 - (are [x] (set? x) 476.612 - (sorted-set) 476.613 - (sorted-set 1 2) ) 476.614 - 476.615 - ; equal and unique 476.616 - (are [x] (and (= (sorted-set x) #{x}) 476.617 - (= (sorted-set x x) (sorted-set x))) 476.618 - nil 476.619 - false true 476.620 - 0 42 476.621 - 0.0 3.14 476.622 - 2/3 476.623 - 0M 1M 476.624 - \c 476.625 - "" "abc" 476.626 - 'sym 476.627 - :kw 476.628 - () ; '(1 2) 476.629 - [] [1 2] 476.630 - {} ; {:a 1 :b 2} 476.631 - #{} ; #{1 2} 476.632 - ) 476.633 - ; cannot be cast to java.lang.Comparable 476.634 - (is (thrown? ClassCastException (sorted-set '(1 2) '(1 2)))) 476.635 - (is (thrown? ClassCastException (sorted-set {:a 1 :b 2} {:a 1 :b 2}))) 476.636 - (is (thrown? ClassCastException (sorted-set #{1 2} #{1 2}))) 476.637 - 476.638 - (are [x y] (= x y) 476.639 - ; generating 476.640 - (sorted-set) #{} 476.641 - (sorted-set 1) #{1} 476.642 - (sorted-set 1 2) #{1 2} 476.643 - 476.644 - ; sorting 476.645 - (seq (sorted-set 5 4 3 2 1)) '(1 2 3 4 5) 476.646 - 476.647 - ; special cases 476.648 - (sorted-set nil) #{nil} 476.649 - (sorted-set 1 nil) #{nil 1} 476.650 - (sorted-set nil 2) #{nil 2} 476.651 - (sorted-set #{}) #{#{}} )) 476.652 - 476.653 - 476.654 -(deftest test-sorted-set-by 476.655 - ; only compatible types can be used 476.656 - ; NB: not a ClassCastException, but a RuntimeException is thrown, 476.657 - ; requires discussion on whether this should be symmetric with test-sorted-set 476.658 - (is (thrown? Exception (sorted-set-by < 1 "a"))) 476.659 - (is (thrown? Exception (sorted-set-by < '(1 2) [3 4]))) 476.660 - 476.661 - ; creates set? 476.662 - (are [x] (set? x) 476.663 - (sorted-set-by <) 476.664 - (sorted-set-by < 1 2) ) 476.665 - 476.666 - ; equal and unique 476.667 - (are [x] (and (= (sorted-set-by compare x) #{x}) 476.668 - (= (sorted-set-by compare x x) (sorted-set-by compare x))) 476.669 - nil 476.670 - false true 476.671 - 0 42 476.672 - 0.0 3.14 476.673 - 2/3 476.674 - 0M 1M 476.675 - \c 476.676 - "" "abc" 476.677 - 'sym 476.678 - :kw 476.679 - () ; '(1 2) 476.680 - [] [1 2] 476.681 - {} ; {:a 1 :b 2} 476.682 - #{} ; #{1 2} 476.683 - ) 476.684 - ; cannot be cast to java.lang.Comparable 476.685 - ; NB: not a ClassCastException, but a RuntimeException is thrown, 476.686 - ; requires discussion on whether this should be symmetric with test-sorted-set 476.687 - (is (thrown? Exception (sorted-set-by compare '(1 2) '(1 2)))) 476.688 - (is (thrown? Exception (sorted-set-by compare {:a 1 :b 2} {:a 1 :b 2}))) 476.689 - (is (thrown? Exception (sorted-set-by compare #{1 2} #{1 2}))) 476.690 - 476.691 - (are [x y] (= x y) 476.692 - ; generating 476.693 - (sorted-set-by >) #{} 476.694 - (sorted-set-by > 1) #{1} 476.695 - (sorted-set-by > 1 2) #{1 2} 476.696 - 476.697 - ; sorting 476.698 - (seq (sorted-set-by < 5 4 3 2 1)) '(1 2 3 4 5) 476.699 - 476.700 - ; special cases 476.701 - (sorted-set-by compare nil) #{nil} 476.702 - (sorted-set-by compare 1 nil) #{nil 1} 476.703 - (sorted-set-by compare nil 2) #{nil 2} 476.704 - (sorted-set-by compare #{}) #{#{}} )) 476.705 - 476.706 - 476.707 -(deftest test-set 476.708 - ; set? 476.709 - (are [x] (set? (set x)) 476.710 - () '(1 2) 476.711 - [] [1 2] 476.712 - #{} #{1 2} 476.713 - {} {:a 1 :b 2} 476.714 - (into-array []) (into-array [1 2]) 476.715 - "" "abc" ) 476.716 - 476.717 - ; unique 476.718 - (are [x] (= (set [x x]) #{x}) 476.719 - nil 476.720 - false true 476.721 - 0 42 476.722 - 0.0 3.14 476.723 - 2/3 476.724 - 0M 1M 476.725 - \c 476.726 - "" "abc" 476.727 - 'sym 476.728 - :kw 476.729 - () '(1 2) 476.730 - [] [1 2] 476.731 - {} {:a 1 :b 2} 476.732 - #{} #{1 2} ) 476.733 - 476.734 - ; conversion 476.735 - (are [x y] (= (set x) y) 476.736 - () #{} 476.737 - '(1 2) #{1 2} 476.738 - 476.739 - [] #{} 476.740 - [1 2] #{1 2} 476.741 - 476.742 - #{} #{} ; identity 476.743 - #{1 2} #{1 2} ; identity 476.744 - 476.745 - {} #{} 476.746 - {:a 1 :b 2} #{[:a 1] [:b 2]} 476.747 - 476.748 - (into-array []) #{} 476.749 - (into-array [1 2]) #{1 2} 476.750 - 476.751 - "" #{} 476.752 - "abc" #{\a \b \c} )) 476.753 - 476.754 - 476.755 -(deftest test-disj 476.756 - ; doesn't work on lists, vectors or maps 476.757 - (is (thrown? ClassCastException (disj '(1 2) 1))) 476.758 - (is (thrown? ClassCastException (disj [1 2] 1))) 476.759 - (is (thrown? ClassCastException (disj {:a 1} :a))) 476.760 - 476.761 - ; identity 476.762 - (are [x] (= (disj x) x) 476.763 - nil 476.764 - #{} 476.765 - #{1 2 3} 476.766 - ; different data types 476.767 - #{nil 476.768 - false true 476.769 - 0 42 476.770 - 0.0 3.14 476.771 - 2/3 476.772 - 0M 1M 476.773 - \c 476.774 - "" "abc" 476.775 - 'sym 476.776 - :kw 476.777 - [] [1 2] 476.778 - {} {:a 1 :b 2} 476.779 - #{} #{1 2}} ) 476.780 - 476.781 - ; type identity 476.782 - (are [x] (= (class (disj x)) (class x)) 476.783 - (hash-set) 476.784 - (hash-set 1 2) 476.785 - (sorted-set) 476.786 - (sorted-set 1 2) ) 476.787 - 476.788 - (are [x y] (= x y) 476.789 - (disj nil :a) nil 476.790 - (disj nil :a :b) nil 476.791 - 476.792 - (disj #{} :a) #{} 476.793 - (disj #{} :a :b) #{} 476.794 - 476.795 - (disj #{:a} :a) #{} 476.796 - (disj #{:a} :a :b) #{} 476.797 - (disj #{:a} :c) #{:a} 476.798 - 476.799 - (disj #{:a :b :c :d} :a) #{:b :c :d} 476.800 - (disj #{:a :b :c :d} :a :d) #{:b :c} 476.801 - (disj #{:a :b :c :d} :a :b :c) #{:d} 476.802 - (disj #{:a :b :c :d} :d :a :c :b) #{} 476.803 - 476.804 - (disj #{nil} :a) #{nil} 476.805 - (disj #{nil} #{}) #{nil} 476.806 - (disj #{nil} nil) #{} 476.807 - 476.808 - (disj #{#{}} nil) #{#{}} 476.809 - (disj #{#{}} #{}) #{} 476.810 - (disj #{#{nil}} #{nil}) #{} )) 476.811 - 476.812 - 476.813 -;; *** Queues *** 476.814 - 476.815 -(deftest test-queues 476.816 - (let [EMPTY clojure.lang.PersistentQueue/EMPTY] 476.817 - (are [x y] (= x y) 476.818 - EMPTY EMPTY 476.819 - (into EMPTY (range 50)) (into EMPTY (range 50)) 476.820 - (range 5) (into EMPTY (range 5)) 476.821 - (range 1 6) (-> EMPTY 476.822 - (into (range 6)) 476.823 - pop)) 476.824 - (are [x y] (not= x y) 476.825 - (range 5) (into EMPTY (range 6)) 476.826 - (range 6) (into EMPTY (range 5)) 476.827 - (range 0 6) (-> EMPTY 476.828 - (into (range 6)) 476.829 - pop) 476.830 - (range 1 6) (-> EMPTY 476.831 - (into (range 7)) 476.832 - pop)))) 476.833 -
477.1 --- a/src/clojure/test_clojure/def.clj Sat Aug 21 06:25:44 2010 -0400 477.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 477.3 @@ -1,16 +0,0 @@ 477.4 -; Copyright (c) Rich Hickey. All rights reserved. 477.5 -; The use and distribution terms for this software are covered by the 477.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 477.7 -; which can be found in the file epl-v10.html at the root of this distribution. 477.8 -; By using this software in any fashion, you are agreeing to be bound by 477.9 -; the terms of this license. 477.10 -; You must not remove this notice, or any other, from this software. 477.11 - 477.12 -(ns clojure.test-clojure.def 477.13 - (:use clojure.test clojure.test-clojure.helpers 477.14 - clojure.test-clojure.protocols)) 477.15 - 477.16 -(deftest defn-error-messages 477.17 - (testing "bad arglist forms" 477.18 - (is (fails-with-cause? IllegalArgumentException '#"Parameter declaration arg1 should be a vector" 477.19 - (eval-in-temp-ns (defn foo (arg1 arg2)))))))
478.1 --- a/src/clojure/test_clojure/evaluation.clj Sat Aug 21 06:25:44 2010 -0400 478.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 478.3 @@ -1,225 +0,0 @@ 478.4 -; Copyright (c) Rich Hickey. All rights reserved. 478.5 -; The use and distribution terms for this software are covered by the 478.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 478.7 -; which can be found in the file epl-v10.html at the root of this distribution. 478.8 -; By using this software in any fashion, you are agreeing to be bound by 478.9 -; the terms of this license. 478.10 -; You must not remove this notice, or any other, from this software. 478.11 - 478.12 - 478.13 -;; Tests for the Clojure functions documented at the URL: 478.14 -;; 478.15 -;; http://clojure.org/Evaluation 478.16 -;; 478.17 -;; by J. McConnell 478.18 -;; Created 22 October 2008 478.19 - 478.20 -(ns clojure.test-clojure.evaluation 478.21 - (:use clojure.test)) 478.22 - 478.23 -(import '(java.lang Boolean) 478.24 - '(clojure.lang Compiler Compiler$CompilerException)) 478.25 - 478.26 -(defmacro test-that 478.27 - "Provides a useful way for specifying the purpose of tests. If the first-level 478.28 - forms are lists that make a call to a clojure.test function, it supplies the 478.29 - purpose as the msg argument to those functions. Otherwise, the purpose just 478.30 - acts like a comment and the forms are run unchanged." 478.31 - [purpose & test-forms] 478.32 - (let [tests (map 478.33 - #(if (= (:ns (meta (resolve (first %)))) 478.34 - (the-ns 'clojure.test)) 478.35 - (concat % (list purpose)) 478.36 - %) 478.37 - test-forms)] 478.38 - `(do ~@tests))) 478.39 - 478.40 -(deftest Eval 478.41 - (is (= (eval '(+ 1 2 3)) (Compiler/eval '(+ 1 2 3)))) 478.42 - (is (= (eval '(list 1 2 3)) '(1 2 3))) 478.43 - (is (= (eval '(list + 1 2 3)) (list clojure.core/+ 1 2 3))) 478.44 - (test-that "Non-closure fns are supported as code" 478.45 - (is (= (eval (eval '(list + 1 2 3))) 6))) 478.46 - (is (= (eval (list '+ 1 2 3)) 6))) 478.47 - 478.48 -; not using Clojure's RT/classForName since a bug in it could hide a bug in 478.49 -; eval's resolution 478.50 -(defn class-for-name [name] 478.51 - (java.lang.Class/forName name)) 478.52 - 478.53 -(defmacro in-test-ns [& body] 478.54 - `(binding [*ns* *ns*] 478.55 - (in-ns 'clojure.test-clojure.evaluation) 478.56 - ~@body)) 478.57 - 478.58 -;;; Literals tests ;;; 478.59 - 478.60 -(defmacro #^{:private true} evaluates-to-itself? [expr] 478.61 - `(let [v# ~expr 478.62 - q# (quote ~expr)] 478.63 - (is (= (eval q#) q#) (str q# " does not evaluate to itself")))) 478.64 - 478.65 -(deftest Literals 478.66 - ; Strings, numbers, characters, nil and keywords should evaluate to themselves 478.67 - (evaluates-to-itself? "test") 478.68 - (evaluates-to-itself? "test 478.69 - multi-line 478.70 - string") 478.71 - (evaluates-to-itself? 1) 478.72 - (evaluates-to-itself? 1.0) 478.73 - (evaluates-to-itself? 1.123456789) 478.74 - (evaluates-to-itself? 1/2) 478.75 - (evaluates-to-itself? 1M) 478.76 - (evaluates-to-itself? 999999999999999999) 478.77 - (evaluates-to-itself? \a) 478.78 - (evaluates-to-itself? \newline) 478.79 - (evaluates-to-itself? nil) 478.80 - (evaluates-to-itself? :test) 478.81 - ; Boolean literals should evaluate to Boolean.{TRUE|FALSE} 478.82 - (is (identical? (eval true) Boolean/TRUE)) 478.83 - (is (identical? (eval false) Boolean/FALSE))) 478.84 - 478.85 -;;; Symbol resolution tests ;;; 478.86 - 478.87 -(def foo "abc") 478.88 -(in-ns 'resolution-test) 478.89 -(def bar 123) 478.90 -(def #^{:private true} baz 456) 478.91 -(in-ns 'clojure.test-clojure.evaluation) 478.92 - 478.93 -(defn a-match? [re s] (not (nil? (re-matches re s)))) 478.94 - 478.95 -(defmacro throws-with-msg 478.96 - ([re form] `(throws-with-msg ~re ~form Exception)) 478.97 - ([re form x] `(throws-with-msg 478.98 - ~re 478.99 - ~form 478.100 - ~(if (instance? Exception x) x Exception) 478.101 - ~(if (instance? String x) x nil))) 478.102 - ([re form class msg] 478.103 - `(let [ex# (try 478.104 - ~form 478.105 - (catch ~class e# e#) 478.106 - (catch Exception e# 478.107 - (let [cause# (.getCause e#)] 478.108 - (if (= ~class (class cause#)) cause# (throw e#)))))] 478.109 - (is (a-match? ~re (.toString ex#)) 478.110 - (or ~msg 478.111 - (str "Expected exception that matched " (pr-str ~re) 478.112 - ", but got exception with message: \"" ex#)))))) 478.113 - 478.114 -(deftest SymbolResolution 478.115 - (test-that 478.116 - "If a symbol is namespace-qualified, the evaluated value is the value 478.117 - of the binding of the global var named by the symbol" 478.118 - (is (= (eval 'resolution-test/bar) 123))) 478.119 - 478.120 - (test-that 478.121 - "It is an error if there is no global var named by the symbol" 478.122 - (throws-with-msg 478.123 - #".*Unable to resolve symbol: bar.*" (eval 'bar))) 478.124 - 478.125 - (test-that 478.126 - "It is an error if the symbol reference is to a non-public var in a 478.127 - different namespace" 478.128 - (throws-with-msg 478.129 - #".*resolution-test/baz is not public.*" 478.130 - (eval 'resolution-test/baz) 478.131 - Compiler$CompilerException)) 478.132 - 478.133 - (test-that 478.134 - "If a symbol is package-qualified, its value is the Java class named by the 478.135 - symbol" 478.136 - (is (= (eval 'java.lang.Math) (class-for-name "java.lang.Math")))) 478.137 - 478.138 - (test-that 478.139 - "If a symbol is package-qualified, it is an error if there is no Class named 478.140 - by the symbol" 478.141 - (is (thrown? Compiler$CompilerException (eval 'java.lang.FooBar)))) 478.142 - 478.143 - (test-that 478.144 - "If a symbol is not qualified, the following applies, in this order: 478.145 - 478.146 - 1. If it names a special form it is considered a special form, and must 478.147 - be utilized accordingly. 478.148 - 478.149 - 2. A lookup is done in the current namespace to see if there is a mapping 478.150 - from the symbol to a class. If so, the symbol is considered to name a 478.151 - Java class object. 478.152 - 478.153 - 3. If in a local scope (i.e. in a function definition), a lookup is done 478.154 - to see if it names a local binding (e.g. a function argument or 478.155 - let-bound name). If so, the value is the value of the local binding. 478.156 - 478.157 - 4. A lookup is done in the current namespace to see if there is a mapping 478.158 - from the symbol to a var. If so, the value is the value of the binding 478.159 - of the var referred-to by the symbol. 478.160 - 478.161 - 5. It is an error." 478.162 - 478.163 - ; First 478.164 - (doall (for [form '(def if do let quote var fn loop recur throw try 478.165 - monitor-enter monitor-exit)] 478.166 - (is (thrown? Compiler$CompilerException (eval form))))) 478.167 - (let [if "foo"] 478.168 - (is (thrown? Compiler$CompilerException (eval 'if))) 478.169 - 478.170 - ; Second 478.171 - (is (= (eval 'Boolean) (class-for-name "java.lang.Boolean")))) 478.172 - (let [Boolean "foo"] 478.173 - (is (= (eval 'Boolean) (class-for-name "java.lang.Boolean")))) 478.174 - 478.175 - ; Third 478.176 - (is (= (eval '(let [foo "bar"] foo)) "bar")) 478.177 - 478.178 - ; Fourth 478.179 - (in-test-ns (is (= (eval 'foo) "abc"))) 478.180 - (is (thrown? Compiler$CompilerException (eval 'bar))) ; not in this namespace 478.181 - 478.182 - ; Fifth 478.183 - (is (thrown? Compiler$CompilerException (eval 'foobar))))) 478.184 - 478.185 -;;; Metadata tests ;;; 478.186 - 478.187 -(defstruct struct-with-symbols (with-meta 'k {:a "A"})) 478.188 - 478.189 -(deftest Metadata 478.190 - 478.191 - (test-that 478.192 - "find returns key symbols and their metadata" 478.193 - (let [s (struct struct-with-symbols 1)] 478.194 - (is (= {:a "A"} (meta (first (find s 'k)))))))) 478.195 - 478.196 -;;; Collections tests ;;; 478.197 -(def x 1) 478.198 -(def y 2) 478.199 - 478.200 -(deftest Collections 478.201 - (in-test-ns 478.202 - (test-that 478.203 - "Vectors and Maps yield vectors and (hash) maps whose contents are the 478.204 - evaluated values of the objects they contain." 478.205 - (is (= (eval '[x y 3]) [1 2 3])) 478.206 - (is (= (eval '{:x x :y y :z 3}) {:x 1 :y 2 :z 3})) 478.207 - (is (instance? clojure.lang.IPersistentMap (eval '{:x x :y y}))))) 478.208 - 478.209 - (in-test-ns 478.210 - (test-that 478.211 - "Metadata maps yield maps whose contents are the evaluated values of 478.212 - the objects they contain. If a vector or map has metadata, the evaluated 478.213 - metadata map will become the metadata of the resulting value." 478.214 - (is (= (eval #^{:x x} '[x y]) #^{:x 1} [1 2])))) 478.215 - 478.216 - (test-that 478.217 - "An empty list () evaluates to an empty list." 478.218 - (is (= (eval '()) ())) 478.219 - (is (empty? (eval ()))) 478.220 - (is (= (eval (list)) ()))) 478.221 - 478.222 - (test-that 478.223 - "Non-empty lists are considered calls" 478.224 - (is (thrown? Compiler$CompilerException (eval '(1 2 3)))))) 478.225 - 478.226 -(deftest Macros) 478.227 - 478.228 -(deftest Loading)
479.1 --- a/src/clojure/test_clojure/for.clj Sat Aug 21 06:25:44 2010 -0400 479.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 479.3 @@ -1,128 +0,0 @@ 479.4 -; Copyright (c) Rich Hickey. All rights reserved. 479.5 -; The use and distribution terms for this software are covered by the 479.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 479.7 -; which can be found in the file epl-v10.html at the root of this distribution. 479.8 -; By using this software in any fashion, you are agreeing to be bound by 479.9 -; the terms of this license. 479.10 -; You must not remove this notice, or any other, from this software. 479.11 - 479.12 -;; Tests for the Clojure 'for' macro 479.13 -;; 479.14 -;; by Chouser 479.15 -;; Created Dec 2008 479.16 - 479.17 -(ns clojure.test-clojure.for 479.18 - (:use clojure.test)) 479.19 - 479.20 -(deftest Docstring-Example 479.21 - (is (= (take 100 (for [x (range 100000000) 479.22 - y (range 1000000) :while (< y x)] 479.23 - [x y])) 479.24 - '([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3] 479.25 - [5 0] [5 1] [5 2] [5 3] [5 4] 479.26 - [6 0] [6 1] [6 2] [6 3] [6 4] [6 5] 479.27 - [7 0] [7 1] [7 2] [7 3] [7 4] [7 5] [7 6] 479.28 - [8 0] [8 1] [8 2] [8 3] [8 4] [8 5] [8 6] [8 7] 479.29 - [9 0] [9 1] [9 2] [9 3] [9 4] [9 5] [9 6] [9 7] [9 8] 479.30 - [10 0] [10 1] [10 2] [10 3] [10 4] [10 5] [10 6] [10 7] [10 8] [10 9] 479.31 - [11 0] [11 1] [11 2] [11 3] [11 4] [11 5] [11 6] [11 7] [11 8] [11 9] 479.32 - [11 10] 479.33 - [12 0] [12 1] [12 2] [12 3] [12 4] [12 5] [12 6] [12 7] [12 8] [12 9] 479.34 - [12 10] [12 11] 479.35 - [13 0] [13 1] [13 2] [13 3] [13 4] [13 5] [13 6] [13 7] [13 8] [13 9] 479.36 - [13 10] [13 11] [13 12] 479.37 - [14 0] [14 1] [14 2] [14 3] [14 4] [14 5] [14 6] [14 7] [14 8])))) 479.38 - 479.39 -(defmacro deftest-both [txt & ises] 479.40 - `(do 479.41 - (deftest ~(symbol (str "For-" txt)) ~@ises) 479.42 - (deftest ~(symbol (str "Doseq-" txt)) 479.43 - ~@(map (fn [[x-is [x-= [x-for binds body] value]]] 479.44 - (when (and (= x-is 'is) (= x-= '=) (= x-for 'for)) 479.45 - `(is (= (let [acc# (atom [])] 479.46 - (doseq ~binds (swap! acc# conj ~body)) 479.47 - @acc#) 479.48 - ~value)))) 479.49 - ises)))) 479.50 - 479.51 -(deftest-both When 479.52 - (is (= (for [x (range 10) :when (odd? x)] x) '(1 3 5 7 9))) 479.53 - (is (= (for [x (range 4) y (range 4) :when (odd? y)] [x y]) 479.54 - '([0 1] [0 3] [1 1] [1 3] [2 1] [2 3] [3 1] [3 3]))) 479.55 - (is (= (for [x (range 4) y (range 4) :when (odd? x)] [x y]) 479.56 - '([1 0] [1 1] [1 2] [1 3] [3 0] [3 1] [3 2] [3 3]))) 479.57 - (is (= (for [x (range 4) :when (odd? x) y (range 4)] [x y]) 479.58 - '([1 0] [1 1] [1 2] [1 3] [3 0] [3 1] [3 2] [3 3]))) 479.59 - (is (= (for [x (range 5) y (range 5) :when (< x y)] [x y]) 479.60 - '([0 1] [0 2] [0 3] [0 4] [1 2] [1 3] [1 4] [2 3] [2 4] [3 4])))) 479.61 - 479.62 -(defn only 479.63 - "Returns a lazy seq of increasing ints starting at 0. Trying to get 479.64 - the nth+1 value of the seq throws an exception. This is meant to 479.65 - help detecting over-eagerness in lazy seq consumers." 479.66 - [n] 479.67 - (lazy-cat (range n) 479.68 - (throw (Exception. "consumer went too far in lazy seq")))) 479.69 - 479.70 -(deftest-both While 479.71 - (is (= (for [x (only 6) :while (< x 5)] x) '(0 1 2 3 4))) 479.72 - (is (= (for [x (range 4) y (only 4) :while (< y 3)] [x y]) 479.73 - '([0 0] [0 1] [0 2] [1 0] [1 1] [1 2] 479.74 - [2 0] [2 1] [2 2] [3 0] [3 1] [3 2]))) 479.75 - (is (= (for [x (range 4) y (range 4) :while (< x 3)] [x y]) 479.76 - '([0 0] [0 1] [0 2] [0 3] [1 0] [1 1] [1 2] [1 3] 479.77 - [2 0] [2 1] [2 2] [2 3]))) 479.78 - (is (= (for [x (only 4) :while (< x 3) y (range 4)] [x y]) 479.79 - '([0 0] [0 1] [0 2] [0 3] [1 0] [1 1] [1 2] [1 3] 479.80 - [2 0] [2 1] [2 2] [2 3]))) 479.81 - (is (= (for [x (range 4) y (range 4) :while (even? x)] [x y]) 479.82 - '([0 0] [0 1] [0 2] [0 3] [2 0] [2 1] [2 2] [2 3]))) 479.83 - (is (= (for [x (only 2) :while (even? x) y (range 4)] [x y]) 479.84 - '([0 0] [0 1] [0 2] [0 3]))) 479.85 - (is (= (for [x (range 4) y (only 4) :while (< y x)] [x y]) 479.86 - '([1 0] [2 0] [2 1] [3 0] [3 1] [3 2])))) 479.87 - 479.88 -(deftest-both While-and-When 479.89 - (is (= (for [x (only 6) :while (< x 5) y (range 4) :when (odd? y)] [x y]) 479.90 - '([0 1] [0 3] [1 1] [1 3] [2 1] [2 3] [3 1] [3 3] [4 1] [4 3]))) 479.91 - (is (= (for [x (range 4) :when (odd? x) y (only 6) :while (< y 5)] [x y]) 479.92 - '([1 0] [1 1] [1 2] [1 3] [1 4] [3 0] [3 1] [3 2] [3 3] [3 4]))) 479.93 - (is (= (for [x (only 6) :while (< x 5) y (range 4) :when (odd? (+ x y))] 479.94 - [x y]) 479.95 - '([0 1] [0 3] [1 0] [1 2] [2 1] [2 3] [3 0] [3 2] [4 1] [4 3]))) 479.96 - (is (= (for [x (range 4) :when (odd? x) y (only 2) :while (odd? (+ x y))] 479.97 - [x y]) 479.98 - '([1 0] [3 0])))) 479.99 - 479.100 -(deftest-both While-and-When-Same-Binding 479.101 - (is (= (for [x (only 6) :while (< x 5) :when (odd? x)] x) '(1 3))) 479.102 - (is (= (for [x (only 6) 479.103 - :while (< x 5) ; if :while is false, :when should not be evaled 479.104 - :when (do (if (< x 5) (odd? x)))] x) '(1 3))) 479.105 - (is (= (for [a (range -2 5) 479.106 - :when (not= a 0) ; :when may guard :while 479.107 - :while (> (Math/abs (/ 1.0 a)) 1/3)] a) '(-2 -1 1 2)))) 479.108 - 479.109 -(deftest-both Nesting 479.110 - (is (= (for [x '(a b) y (interpose x '(1 2)) z (list x y)] [x y z]) 479.111 - '([a 1 a] [a 1 1] [a a a] [a a a] [a 2 a] [a 2 2] 479.112 - [b 1 b] [b 1 1] [b b b] [b b b] [b 2 b] [b 2 2]))) 479.113 - (is (= (for [x ['a nil] y [x 'b]] [x y]) 479.114 - '([a a] [a b] [nil nil] [nil b])))) 479.115 - 479.116 -(deftest-both Destructuring 479.117 - (is (= (for [{:syms [a b c]} (map #(zipmap '(a b c) (range % 5)) (range 3)) 479.118 - x [a b c]] 479.119 - (Integer. (str a b c x))) 479.120 - '(120 121 122 1231 1232 1233 2342 2343 2344)))) 479.121 - 479.122 -(deftest-both Let 479.123 - (is (= (for [x (range 3) y (range 3) :let [z (+ x y)] :when (odd? z)] [x y z]) 479.124 - '([0 1 1] [1 0 1] [1 2 3] [2 1 3]))) 479.125 - (is (= (for [x (range 6) :let [y (rem x 2)] :when (even? y) z [8 9]] [x z]) 479.126 - '([0 8] [0 9] [2 8] [2 9] [4 8] [4 9])))) 479.127 - 479.128 -; :while must skip all subsequent chunks as well as the remainder of 479.129 -; the current chunk: 479.130 -(deftest-both Chunked-While 479.131 - (is (= (for [x (range 100) :while (even? x)] x) '(0))))
480.1 --- a/src/clojure/test_clojure/genclass.clj Sat Aug 21 06:25:44 2010 -0400 480.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 480.3 @@ -1,65 +0,0 @@ 480.4 -; Copyright (c) Rich Hickey. All rights reserved. 480.5 -; The use and distribution terms for this software are covered by the 480.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 480.7 -; which can be found in the file epl-v10.html at the root of this distribution. 480.8 -; By using this software in any fashion, you are agreeing to be bound by 480.9 -; the terms of this license. 480.10 -; You must not remove this notice, or any other, from this software. 480.11 - 480.12 -(ns ^{:doc "Tests for clojure.core/gen-class" 480.13 - :author "Stuart Halloway, Daniel Solano Gómez"} 480.14 - clojure.test-clojure.genclass 480.15 - (:use clojure.test clojure.test-clojure.helpers) 480.16 - (:import [clojure.test_clojure.genclass.examples ExampleClass 480.17 - ExampleAnnotationClass] 480.18 - [java.lang.annotation ElementType 480.19 - Retention 480.20 - RetentionPolicy 480.21 - Target])) 480.22 - 480.23 -(deftest arg-support 480.24 - (let [example (ExampleClass.) 480.25 - o (Object.)] 480.26 - (is (= "foo with o, o" (.foo example o o))) 480.27 - (is (= "foo with o, i" (.foo example o (int 1)))) 480.28 - (is (thrown? java.lang.UnsupportedOperationException (.foo example o))))) 480.29 - 480.30 -(deftest name-munging 480.31 - (testing "mapping from Java fields to Clojure vars" 480.32 - (is (= #'clojure.test-clojure.genclass.examples/-foo-Object-int 480.33 - (get-field ExampleClass 'foo_Object_int__var))) 480.34 - (is (= #'clojure.test-clojure.genclass.examples/-toString 480.35 - (get-field ExampleClass 'toString__var))))) 480.36 - 480.37 -(deftest test-annotations 480.38 - (let [annot-class ExampleAnnotationClass 480.39 - foo-method (.getDeclaredMethod annot-class "foo" (into-array [String]))] 480.40 - (testing "Class annotations:" 480.41 - (is (= 2 (count (.getDeclaredAnnotations annot-class)))) 480.42 - (testing "@Deprecated" 480.43 - (let [deprecated (.getAnnotation annot-class Deprecated)] 480.44 - (is deprecated))) 480.45 - (testing "@Target([])" 480.46 - (let [resource (.getAnnotation annot-class Target)] 480.47 - (is (= 0 (count (.value resource))))))) 480.48 - (testing "Method annotations:" 480.49 - (testing "@Deprecated void foo(String):" 480.50 - (is (= 1 (count (.getDeclaredAnnotations foo-method)))) 480.51 - (is (.getAnnotation foo-method Deprecated)))) 480.52 - (testing "Parameter annotations:" 480.53 - (let [param-annots (.getParameterAnnotations foo-method)] 480.54 - (is (= 1 (alength param-annots))) 480.55 - (let [first-param-annots (aget param-annots 0)] 480.56 - (is (= 2 (alength first-param-annots))) 480.57 - (testing "void foo(@Retention(…) String)" 480.58 - (let [retention (aget first-param-annots 0)] 480.59 - (is (instance? Retention retention)) 480.60 - (= RetentionPolicy/SOURCE (.value retention)))) 480.61 - (testing "void foo(@Target(…) String)" 480.62 - (let [target (aget first-param-annots 1)] 480.63 - (is (instance? Target target)) 480.64 - (is (= [ElementType/TYPE ElementType/PARAMETER] (seq (.value target))))))))))) 480.65 - 480.66 -(deftest genclass-option-validation 480.67 - (is (fails-with-cause? IllegalArgumentException #"Not a valid method name: has-hyphen" 480.68 - (@#'clojure.core/validate-generate-class-options {:methods '[[fine [] void] [has-hyphen [] void]]}))))
481.1 --- a/src/clojure/test_clojure/genclass/examples.clj Sat Aug 21 06:25:44 2010 -0400 481.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 481.3 @@ -1,42 +0,0 @@ 481.4 -; Copyright (c) Rich Hickey. All rights reserved. 481.5 -; The use and distribution terms for this software are covered by the 481.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 481.7 -; which can be found in the file epl-v10.html at the root of this distribution. 481.8 -; By using this software in any fashion, you are agreeing to be bound by 481.9 -; the terms of this license. 481.10 -; You must not remove this notice, or any other, from this software. 481.11 - 481.12 -(ns ^{:doc "Test classes that are AOT-compile for the tests in 481.13 - clojure.test-clojure.genclass." 481.14 - :author "Stuart Halloway, Daniel Solano Gómez"} 481.15 - clojure.test-clojure.genclass.examples) 481.16 - 481.17 -(definterface ExampleInterface 481.18 - (foo [a]) 481.19 - (foo [a b]) 481.20 - (foo [a #^int b])) 481.21 - 481.22 -(gen-class :name clojure.test_clojure.genclass.examples.ExampleClass 481.23 - :implements [clojure.test_clojure.genclass.examples.ExampleInterface]) 481.24 - 481.25 -;; -foo-Object unimplemented to test missing fn case 481.26 - 481.27 -(defn -foo-Object-Object 481.28 - [_ o1 o2] 481.29 - "foo with o, o") 481.30 - 481.31 -(defn -foo-Object-int 481.32 - [_ o i] 481.33 - "foo with o, i") 481.34 - 481.35 -(gen-class :name ^{Deprecated {} 481.36 - SuppressWarnings ["Warning1"] ; discarded 481.37 - java.lang.annotation.Target []} 481.38 - clojure.test_clojure.genclass.examples.ExampleAnnotationClass 481.39 - :prefix "annot-" 481.40 - :methods [[^{Deprecated {} 481.41 - Override {}} ;discarded 481.42 - foo [^{java.lang.annotation.Retention java.lang.annotation.RetentionPolicy/SOURCE 481.43 - java.lang.annotation.Target [java.lang.annotation.ElementType/TYPE 481.44 - java.lang.annotation.ElementType/PARAMETER]} 481.45 - String] void]])
482.1 --- a/src/clojure/test_clojure/helpers.clj Sat Aug 21 06:25:44 2010 -0400 482.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 482.3 @@ -1,86 +0,0 @@ 482.4 -; The use and distribution terms for this software are covered by the 482.5 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 482.6 -; which can be found in the file epl-v10.html at the root of this distribution. 482.7 -; By using this software in any fashion, you are agreeing to be bound by 482.8 -; the terms of this license. 482.9 -; You must not remove this notice, or any other, from this software. 482.10 - 482.11 -; Author: Stuart Halloway 482.12 - 482.13 -(ns clojure.test-clojure.helpers 482.14 - (:use clojure.test)) 482.15 - 482.16 -(defn temp-ns 482.17 - "Create and return a temporary ns, using clojure.core + uses" 482.18 - [& uses] 482.19 - (binding [*ns* *ns*] 482.20 - (in-ns (gensym)) 482.21 - (apply clojure.core/use 'clojure.core uses) 482.22 - *ns*)) 482.23 - 482.24 -(defmacro eval-in-temp-ns [& forms] 482.25 - `(binding [*ns* *ns*] 482.26 - (in-ns (gensym)) 482.27 - (clojure.core/use 'clojure.core) 482.28 - (eval 482.29 - '(do ~@forms)))) 482.30 - 482.31 -(defn causes 482.32 - [^Throwable throwable] 482.33 - (loop [causes [] 482.34 - t throwable] 482.35 - (if t (recur (conj causes t) (.getCause t)) causes))) 482.36 - 482.37 -;; this is how I wish clojure.test/thrown? worked... 482.38 -;; Does body throw expected exception, anywhere in the .getCause chain? 482.39 -(defmethod assert-expr 'fails-with-cause? 482.40 - [msg [_ exception-class msg-re & body :as form]] 482.41 - `(try 482.42 - ~@body 482.43 - (report {:type :fail, :message ~msg, :expected '~form, :actual nil}) 482.44 - (catch Throwable t# 482.45 - (if (some (fn [cause#] 482.46 - (and 482.47 - (= ~exception-class (class cause#)) 482.48 - (re-find ~msg-re (.getMessage cause#)))) 482.49 - (causes t#)) 482.50 - (report {:type :pass, :message ~msg, 482.51 - :expected '~form, :actual t#}) 482.52 - (report {:type :fail, :message ~msg, 482.53 - :expected '~form, :actual t#}))))) 482.54 - 482.55 - 482.56 -(defn get-field 482.57 - "Access to private or protected field. field-name is a symbol or 482.58 - keyword." 482.59 - ([klass field-name] 482.60 - (get-field klass field-name nil)) 482.61 - ([klass field-name inst] 482.62 - (-> klass (.getDeclaredField (name field-name)) 482.63 - (doto (.setAccessible true)) 482.64 - (.get inst)))) 482.65 - 482.66 -(defn set-var-roots 482.67 - [maplike] 482.68 - (doseq [[var val] maplike] 482.69 - (alter-var-root var (fn [_] val)))) 482.70 - 482.71 -(defn with-var-roots* 482.72 - "Temporarily set var roots, run block, then put original roots back." 482.73 - [root-map f & args] 482.74 - (let [originals (doall (map (fn [[var _]] [var @var]) root-map))] 482.75 - (set-var-roots root-map) 482.76 - (try 482.77 - (apply f args) 482.78 - (finally 482.79 - (set-var-roots originals))))) 482.80 - 482.81 -(defmacro with-var-roots 482.82 - [root-map & body] 482.83 - `(with-var-roots* ~root-map (fn [] ~@body))) 482.84 - 482.85 -(defn exception 482.86 - "Use this function to ensure that execution of a program doesn't 482.87 - reach certain point." 482.88 - [] 482.89 - (throw (new Exception "Exception which should never occur")))
483.1 --- a/src/clojure/test_clojure/java/io.clj Sat Aug 21 06:25:44 2010 -0400 483.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 483.3 @@ -1,206 +0,0 @@ 483.4 -; Copyright (c) Rich Hickey. All rights reserved. 483.5 -; The use and distribution terms for this software are covered by the 483.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 483.7 -; which can be found in the file epl-v10.html at the root of this distribution. 483.8 -; By using this software in any fashion, you are agreeing to be bound by 483.9 -; the terms of this license. 483.10 -; You must not remove this notice, or any other, from this software. 483.11 - 483.12 -(ns clojure.test-clojure.java.io 483.13 - (:use clojure.test clojure.java.io) 483.14 - (:import (java.io File BufferedInputStream 483.15 - FileInputStream InputStreamReader InputStream 483.16 - FileOutputStream OutputStreamWriter OutputStream 483.17 - ByteArrayInputStream ByteArrayOutputStream) 483.18 - (java.net URL URI Socket ServerSocket))) 483.19 - 483.20 -(defn temp-file 483.21 - [prefix suffix] 483.22 - (doto (File/createTempFile prefix suffix) 483.23 - (.deleteOnExit))) 483.24 - 483.25 -(deftest test-spit-and-slurp 483.26 - (let [f (temp-file "clojure.java.io" "test")] 483.27 - (spit f "foobar") 483.28 - (is (= "foobar" (slurp f))) 483.29 - (spit f "foobar" :encoding "UTF-16") 483.30 - (is (= "foobar" (slurp f :encoding "UTF-16"))) 483.31 - (testing "deprecated arity" 483.32 - (is (= 483.33 - "WARNING: (slurp f enc) is deprecated, use (slurp f :encoding enc).\n" 483.34 - (with-out-str 483.35 - (is (= "foobar" (slurp f "UTF-16"))))))))) 483.36 - 483.37 -(deftest test-streams-defaults 483.38 - (let [f (temp-file "clojure.java.io" "test-reader-writer") 483.39 - content "testing"] 483.40 - (try 483.41 - (is (thrown? Exception (reader (Object.)))) 483.42 - (is (thrown? Exception (writer (Object.)))) 483.43 - 483.44 - (are [write-to read-from] (= content (do 483.45 - (spit write-to content :encoding "UTF-8") 483.46 - (slurp read-from :encoding "UTF-8"))) 483.47 - f f 483.48 - (.getAbsolutePath f) (.getAbsolutePath f) 483.49 - (.toURL f) (.toURL f) 483.50 - (.toURI f) (.toURI f) 483.51 - (FileOutputStream. f) (FileInputStream. f) 483.52 - (OutputStreamWriter. (FileOutputStream. f) "UTF-8") (reader f :encoding "UTF-8") 483.53 - f (FileInputStream. f) 483.54 - (writer f :encoding "UTF-8") (InputStreamReader. (FileInputStream. f) "UTF-8")) 483.55 - 483.56 - (is (= content (slurp (.getBytes content "UTF-8")))) 483.57 - (is (= content (slurp (.toCharArray content)))) 483.58 - (finally 483.59 - (.delete f))))) 483.60 - 483.61 -(defn bytes-should-equal [byte-array-1 byte-array-2 msg] 483.62 - (is (= @#'clojure.java.io/byte-array-type (class byte-array-1) (class byte-array-2)) msg) 483.63 - (is (= (into [] byte-array-1) (into [] byte-array-2)) msg)) 483.64 - 483.65 -(defn data-fixture 483.66 - "in memory fixture data for tests" 483.67 - [encoding] 483.68 - (let [bs (.getBytes "hello" encoding) 483.69 - cs (.toCharArray "hello") 483.70 - i (ByteArrayInputStream. bs) 483.71 - r (InputStreamReader. i) 483.72 - o (ByteArrayOutputStream.) 483.73 - w (OutputStreamWriter. o)] 483.74 - {:bs bs 483.75 - :i i 483.76 - :r r 483.77 - :o o 483.78 - :s "hello" 483.79 - :cs cs 483.80 - :w w})) 483.81 - 483.82 -(deftest test-copy 483.83 - (dorun 483.84 - (for [{:keys [in out flush] :as test} 483.85 - [{:in :i :out :o} 483.86 - {:in :i :out :w} 483.87 - {:in :r :out :o} 483.88 - {:in :r :out :w} 483.89 - {:in :cs :out :o} 483.90 - {:in :cs :out :w} 483.91 - {:in :bs :out :o} 483.92 - {:in :bs :out :w}] 483.93 - 483.94 - opts 483.95 - [{} {:buffer-size 256}]] 483.96 - (let [{:keys [s o] :as d} (data-fixture "UTF-8")] 483.97 - (apply copy (in d) (out d) (flatten (vec opts))) 483.98 - #_(when (= out :w) (.flush (:w d))) 483.99 - (.flush (out d)) 483.100 - (bytes-should-equal (.getBytes s "UTF-8") 483.101 - (.toByteArray o) 483.102 - (str "combination " test opts)))))) 483.103 - 483.104 -(deftest test-copy-encodings 483.105 - (testing "from inputstream UTF-16 to writer UTF-8" 483.106 - (let [{:keys [i s o w bs]} (data-fixture "UTF-16")] 483.107 - (copy i w :encoding "UTF-16") 483.108 - (.flush w) 483.109 - (bytes-should-equal (.getBytes s "UTF-8") (.toByteArray o) ""))) 483.110 - (testing "from reader UTF-8 to output-stream UTF-16" 483.111 - (let [{:keys [r o s]} (data-fixture "UTF-8")] 483.112 - (copy r o :encoding "UTF-16") 483.113 - (bytes-should-equal (.getBytes s "UTF-16") (.toByteArray o) "")))) 483.114 - 483.115 -(deftest test-as-file 483.116 - (are [result input] (= result (as-file input)) 483.117 - (File. "foo") "foo" 483.118 - (File. "bar") (File. "bar") 483.119 - (File. "baz") (URL. "file:baz") 483.120 - (File. "quux") (URI. "file:quux") 483.121 - nil nil)) 483.122 - 483.123 -(deftest test-file 483.124 - (are [result args] (= (File. result) (apply file args)) 483.125 - "foo" ["foo"] 483.126 - "foo/bar" ["foo" "bar"] 483.127 - "foo/bar/baz" ["foo" "bar" "baz"])) 483.128 -(deftest test-as-url 483.129 - (are [file-part input] (= (URL. (str "file:" file-part)) (as-url input)) 483.130 - "foo" "file:foo" 483.131 - "baz" (URL. "file:baz") 483.132 - "quux" (URI. "file:quux")) 483.133 - (is (nil? (as-url nil)))) 483.134 - 483.135 -(deftest test-delete-file 483.136 - (let [file (temp-file "test" "deletion") 483.137 - not-file (File. (str (java.util.UUID/randomUUID)))] 483.138 - (delete-file (.getAbsolutePath file)) 483.139 - (is (not (.exists file))) 483.140 - (is (thrown? java.io.IOException (delete-file not-file))) 483.141 - (is (= :silently (delete-file not-file :silently))))) 483.142 - 483.143 -(deftest test-as-relative-path 483.144 - (testing "strings" 483.145 - (is (= "foo" (as-relative-path "foo")))) 483.146 - (testing "absolute path strings are forbidden" 483.147 - (is (thrown? IllegalArgumentException (as-relative-path (.getAbsolutePath (File. "baz")))))) 483.148 - (testing "relative File paths" 483.149 - (is (= "bar" (as-relative-path (File. "bar"))))) 483.150 - (testing "absolute File paths are forbidden" 483.151 - (is (thrown? IllegalArgumentException (as-relative-path (File. (.getAbsolutePath (File. "quux")))))))) 483.152 - 483.153 -(defn stream-should-have [stream expected-bytes msg] 483.154 - (let [actual-bytes (byte-array (alength expected-bytes))] 483.155 - (.read stream actual-bytes) 483.156 - (is (= -1 (.read stream)) (str msg " : should be end of stream")) 483.157 - (is (= (seq expected-bytes) (seq actual-bytes)) (str msg " : byte arrays should match")))) 483.158 - 483.159 -(deftest test-input-stream 483.160 - (let [file (temp-file "test-input-stream" "txt") 483.161 - bytes (.getBytes "foobar")] 483.162 - (spit file "foobar") 483.163 - (doseq [[expr msg] 483.164 - [[file File] 483.165 - [(FileInputStream. file) FileInputStream] 483.166 - [(BufferedInputStream. (FileInputStream. file)) BufferedInputStream] 483.167 - [(.. file toURI) URI] 483.168 - [(.. file toURI toURL) URL] 483.169 - [(.. file toURI toURL toString) "URL as String"] 483.170 - [(.. file toString) "File as String"]]] 483.171 - (with-open [s (input-stream expr)] 483.172 - (stream-should-have s bytes msg))))) 483.173 - 483.174 -(deftest test-streams-buffering 483.175 - (let [data (.getBytes "")] 483.176 - (is (instance? java.io.BufferedReader (reader data))) 483.177 - (is (instance? java.io.BufferedWriter (writer (java.io.ByteArrayOutputStream.)))) 483.178 - (is (instance? java.io.BufferedInputStream (input-stream data))) 483.179 - (is (instance? java.io.BufferedOutputStream (output-stream (java.io.ByteArrayOutputStream.)))))) 483.180 - 483.181 -(deftest test-resource 483.182 - (is (nil? (resource "non/existent/resource"))) 483.183 - (is (instance? URL (resource "clojure/core.clj"))) 483.184 - (let [file (temp-file "test-resource" "txt") 483.185 - url (as-url (.getParentFile file)) 483.186 - loader (java.net.URLClassLoader. (into-array [url]))] 483.187 - (is (nil? (resource "non/existent/resource" loader))) 483.188 - (is (instance? URL (resource (.getName file) loader))))) 483.189 - 483.190 -(deftest test-make-parents 483.191 - (let [tmp (System/getProperty "java.io.tmpdir")] 483.192 - (delete-file (file tmp "test-make-parents" "child" "grandchild") :silently) 483.193 - (delete-file (file tmp "test-make-parents" "child") :silently) 483.194 - (delete-file (file tmp "test-make-parents") :silently) 483.195 - (make-parents tmp "test-make-parents" "child" "grandchild") 483.196 - (is (.isDirectory (file tmp "test-make-parents" "child"))) 483.197 - (is (not (.isDirectory (file tmp "test-make-parents" "child" "grandchild")))) 483.198 - (delete-file (file tmp "test-make-parents" "child")) 483.199 - (delete-file (file tmp "test-make-parents")))) 483.200 - 483.201 -(deftest test-socket-iofactory 483.202 - (let [port 65321 483.203 - server-socket (ServerSocket. port) 483.204 - client-socket (Socket. "localhost" port)] 483.205 - (try 483.206 - (is (instance? InputStream (input-stream client-socket))) 483.207 - (is (instance? OutputStream (output-stream client-socket))) 483.208 - (finally (.close server-socket) 483.209 - (.close client-socket)))))
484.1 --- a/src/clojure/test_clojure/java/javadoc.clj Sat Aug 21 06:25:44 2010 -0400 484.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 484.3 @@ -1,22 +0,0 @@ 484.4 -; Copyright (c) Rich Hickey. All rights reserved. 484.5 -; The use and distribution terms for this software are covered by the 484.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 484.7 -; which can be found in the file epl-v10.html at the root of this distribution. 484.8 -; By using this software in any fashion, you are agreeing to be bound by 484.9 -; the terms of this license. 484.10 -; You must not remove this notice, or any other, from this software. 484.11 - 484.12 -(ns clojure.test-clojure.java.javadoc 484.13 - (:use clojure.test 484.14 - [clojure.java.javadoc :as j]) 484.15 - (:import (java.io File))) 484.16 - 484.17 -(deftest javadoc-url-test 484.18 - (testing "for a core api" 484.19 - (binding [*feeling-lucky* false] 484.20 - (are [x y] (= x (#'j/javadoc-url y)) 484.21 - nil "foo.Bar" 484.22 - (str *core-java-api* "java/lang/String.html") "java.lang.String"))) 484.23 - (testing "for a remote javadoc" 484.24 - (binding [*remote-javadocs* (ref (sorted-map "java." "http://example.com/"))] 484.25 - (is (= "http://example.com/java/lang/Number.html" (#'j/javadoc-url "java.lang.Number"))))))
485.1 --- a/src/clojure/test_clojure/java/shell.clj Sat Aug 21 06:25:44 2010 -0400 485.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 485.3 @@ -1,41 +0,0 @@ 485.4 -; Copyright (c) Rich Hickey. All rights reserved. 485.5 -; The use and distribution terms for this software are covered by the 485.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 485.7 -; which can be found in the file epl-v10.html at the root of this distribution. 485.8 -; By using this software in any fashion, you are agreeing to be bound by 485.9 -; the terms of this license. 485.10 -; You must not remove this notice, or any other, from this software. 485.11 - 485.12 -(ns clojure.test-clojure.java.shell 485.13 - (:use clojure.test 485.14 - [clojure.java.shell :as sh]) 485.15 - (:import (java.io File))) 485.16 - 485.17 -(def platform-enc (.name (java.nio.charset.Charset/defaultCharset))) 485.18 -(def default-enc "UTF-8") 485.19 - 485.20 -(deftest test-parse-args 485.21 - (are [x y] (= x y) 485.22 - [[] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args []) 485.23 - [["ls"] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args ["ls"]) 485.24 - [["ls" "-l"] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args ["ls" "-l"]) 485.25 - [["ls"] {:in-enc default-enc :out-enc "ISO-8859-1" :dir nil :env nil}] (#'sh/parse-args ["ls" :out-enc "ISO-8859-1"]) 485.26 - [[] {:in-enc platform-enc :out-enc platform-enc :dir nil :env nil}] (#'sh/parse-args [:in-enc platform-enc :out-enc platform-enc]))) 485.27 - 485.28 -(deftest test-with-sh-dir 485.29 - (are [x y] (= x y) 485.30 - nil *sh-dir* 485.31 - "foo" (with-sh-dir "foo" *sh-dir*))) 485.32 - 485.33 -(deftest test-with-sh-env 485.34 - (are [x y] (= x y) 485.35 - nil *sh-env* 485.36 - {:KEY "VAL"} (with-sh-env {:KEY "VAL"} *sh-env*))) 485.37 - 485.38 -(deftest test-as-env-strings 485.39 - (are [x y] (= x y) 485.40 - nil (#'sh/as-env-strings nil) 485.41 - ["FOO=BAR"] (seq (#'sh/as-env-strings {"FOO" "BAR"})) 485.42 - ["FOO_SYMBOL=BAR"] (seq (#'sh/as-env-strings {'FOO_SYMBOL "BAR"})) 485.43 - ["FOO_KEYWORD=BAR"] (seq (#'sh/as-env-strings {:FOO_KEYWORD "BAR"})))) 485.44 -
486.1 --- a/src/clojure/test_clojure/java_interop.clj Sat Aug 21 06:25:44 2010 -0400 486.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 486.3 @@ -1,427 +0,0 @@ 486.4 -; Copyright (c) Rich Hickey. All rights reserved. 486.5 -; The use and distribution terms for this software are covered by the 486.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 486.7 -; which can be found in the file epl-v10.html at the root of this distribution. 486.8 -; By using this software in any fashion, you are agreeing to be bound by 486.9 -; the terms of this license. 486.10 -; You must not remove this notice, or any other, from this software. 486.11 - 486.12 -; Author: Frantisek Sodomka 486.13 - 486.14 - 486.15 -(ns clojure.test-clojure.java-interop 486.16 - (:use clojure.test)) 486.17 - 486.18 -; http://clojure.org/java_interop 486.19 -; http://clojure.org/compilation 486.20 - 486.21 - 486.22 -(deftest test-dot 486.23 - ; (.instanceMember instance args*) 486.24 - (are [x] (= x "FRED") 486.25 - (.toUpperCase "fred") 486.26 - (. "fred" toUpperCase) 486.27 - (. "fred" (toUpperCase)) ) 486.28 - 486.29 - (are [x] (= x true) 486.30 - (.startsWith "abcde" "ab") 486.31 - (. "abcde" startsWith "ab") 486.32 - (. "abcde" (startsWith "ab")) ) 486.33 - 486.34 - ; (.instanceMember Classname args*) 486.35 - (are [x] (= x "java.lang.String") 486.36 - (.getName String) 486.37 - (. (identity String) getName) 486.38 - (. (identity String) (getName)) ) 486.39 - 486.40 - ; (Classname/staticMethod args*) 486.41 - (are [x] (= x 7) 486.42 - (Math/abs -7) 486.43 - (. Math abs -7) 486.44 - (. Math (abs -7)) ) 486.45 - 486.46 - ; Classname/staticField 486.47 - (are [x] (= x 2147483647) 486.48 - Integer/MAX_VALUE 486.49 - (. Integer MAX_VALUE) )) 486.50 - 486.51 - 486.52 -(deftest test-double-dot 486.53 - (is (= (.. System (getProperties) (get "os.name")) 486.54 - (. (. System (getProperties)) (get "os.name"))))) 486.55 - 486.56 - 486.57 -(deftest test-doto 486.58 - (let [m (doto (new java.util.HashMap) 486.59 - (.put "a" 1) 486.60 - (.put "b" 2))] 486.61 - (are [x y] (= x y) 486.62 - (class m) java.util.HashMap 486.63 - m {"a" 1 "b" 2} ))) 486.64 - 486.65 - 486.66 -(deftest test-new 486.67 - ; Integer 486.68 - (are [expr cls value] (and (= (class expr) cls) 486.69 - (= expr value)) 486.70 - (new java.lang.Integer 42) java.lang.Integer 42 486.71 - (java.lang.Integer. 123) java.lang.Integer 123 ) 486.72 - 486.73 - ; Date 486.74 - (are [x] (= (class x) java.util.Date) 486.75 - (new java.util.Date) 486.76 - (java.util.Date.) )) 486.77 - 486.78 - 486.79 -(deftest test-instance? 486.80 - ; evaluation 486.81 - (are [x y] (= x y) 486.82 - (instance? java.lang.Integer (+ 1 2)) true 486.83 - (instance? java.lang.Long (+ 1 2)) false ) 486.84 - 486.85 - ; different types 486.86 - (are [type literal] (instance? literal type) 486.87 - 1 java.lang.Integer 486.88 - 1.0 java.lang.Double 486.89 - 1M java.math.BigDecimal 486.90 - \a java.lang.Character 486.91 - "a" java.lang.String ) 486.92 - 486.93 - ; it is an int, nothing else 486.94 - (are [x y] (= (instance? x 42) y) 486.95 - java.lang.Integer true 486.96 - java.lang.Long false 486.97 - java.lang.Character false 486.98 - java.lang.String false )) 486.99 - 486.100 - 486.101 -; set! 486.102 - 486.103 -; memfn 486.104 - 486.105 - 486.106 -(deftest test-bean 486.107 - (let [b (bean java.awt.Color/black)] 486.108 - (are [x y] (= x y) 486.109 - (map? b) true 486.110 - 486.111 - (:red b) 0 486.112 - (:green b) 0 486.113 - (:blue b) 0 486.114 - (:RGB b) -16777216 486.115 - 486.116 - (:alpha b) 255 486.117 - (:transparency b) 1 486.118 - 486.119 - (:class b) java.awt.Color ))) 486.120 - 486.121 - 486.122 -; proxy, proxy-super 486.123 - 486.124 - 486.125 -(deftest test-bases 486.126 - (are [x y] (= x y) 486.127 - (bases java.lang.Math) 486.128 - (list java.lang.Object) 486.129 - (bases java.lang.Integer) 486.130 - (list java.lang.Number java.lang.Comparable) )) 486.131 - 486.132 -(deftest test-supers 486.133 - (are [x y] (= x y) 486.134 - (supers java.lang.Math) 486.135 - #{java.lang.Object} 486.136 - (supers java.lang.Integer) 486.137 - #{java.lang.Number java.lang.Object 486.138 - java.lang.Comparable java.io.Serializable} )) 486.139 - 486.140 - 486.141 -; Arrays: [alength] aget aset [make-array to-array into-array to-array-2d aclone] 486.142 -; [float-array, int-array, etc] 486.143 -; amap, areduce 486.144 - 486.145 -(defmacro deftest-type-array [type-array type] 486.146 - `(deftest ~(symbol (str "test-" type-array)) 486.147 - ; correct type 486.148 - (is (= (class (first (~type-array [1 2]))) (class (~type 1)))) 486.149 - 486.150 - ; given size (and empty) 486.151 - (are [x] (and (= (alength (~type-array x)) x) 486.152 - (= (vec (~type-array x)) (repeat x 0))) 486.153 - 0 1 5 ) 486.154 - 486.155 - ; copy of a sequence 486.156 - (are [x] (and (= (alength (~type-array x)) (count x)) 486.157 - (= (vec (~type-array x)) x)) 486.158 - [] 486.159 - [1] 486.160 - [1 -2 3 0 5] ) 486.161 - 486.162 - ; given size and init-value 486.163 - (are [x] (and (= (alength (~type-array x 42)) x) 486.164 - (= (vec (~type-array x 42)) (repeat x 42))) 486.165 - 0 1 5 ) 486.166 - 486.167 - ; given size and init-seq 486.168 - (are [x y z] (and (= (alength (~type-array x y)) x) 486.169 - (= (vec (~type-array x y)) z)) 486.170 - 0 [] [] 486.171 - 0 [1] [] 486.172 - 0 [1 2 3] [] 486.173 - 1 [] [0] 486.174 - 1 [1] [1] 486.175 - 1 [1 2 3] [1] 486.176 - 5 [] [0 0 0 0 0] 486.177 - 5 [1] [1 0 0 0 0] 486.178 - 5 [1 2 3] [1 2 3 0 0] 486.179 - 5 [1 2 3 4 5] [1 2 3 4 5] 486.180 - 5 [1 2 3 4 5 6 7] [1 2 3 4 5] ))) 486.181 - 486.182 -(deftest-type-array int-array int) 486.183 -(deftest-type-array long-array long) 486.184 -(deftest-type-array float-array float) 486.185 -(deftest-type-array double-array double) 486.186 - 486.187 -; separate test for exceptions (doesn't work with above macro...) 486.188 -(deftest test-type-array-exceptions 486.189 - (are [x] (thrown? NegativeArraySizeException x) 486.190 - (int-array -1) 486.191 - (long-array -1) 486.192 - (float-array -1) 486.193 - (double-array -1) )) 486.194 - 486.195 - 486.196 -(deftest test-make-array 486.197 - ; negative size 486.198 - (is (thrown? NegativeArraySizeException (make-array Integer -1))) 486.199 - 486.200 - ; one-dimensional 486.201 - (are [x] (= (alength (make-array Integer x)) x) 486.202 - 0 1 5 ) 486.203 - 486.204 - (let [a (make-array Integer 5)] 486.205 - (aset a 3 42) 486.206 - (are [x y] (= x y) 486.207 - (aget a 3) 42 486.208 - (class (aget a 3)) Integer )) 486.209 - 486.210 - ; multi-dimensional 486.211 - (let [a (make-array Integer 3 2 4)] 486.212 - (aset a 0 1 2 987) 486.213 - (are [x y] (= x y) 486.214 - (alength a) 3 486.215 - (alength (first a)) 2 486.216 - (alength (first (first a))) 4 486.217 - 486.218 - (aget a 0 1 2) 987 486.219 - (class (aget a 0 1 2)) Integer ))) 486.220 - 486.221 - 486.222 -(deftest test-to-array 486.223 - (let [v [1 "abc" :kw \c []] 486.224 - a (to-array v)] 486.225 - (are [x y] (= x y) 486.226 - ; length 486.227 - (alength a) (count v) 486.228 - 486.229 - ; content 486.230 - (vec a) v 486.231 - (class (aget a 0)) (class (nth v 0)) 486.232 - (class (aget a 1)) (class (nth v 1)) 486.233 - (class (aget a 2)) (class (nth v 2)) 486.234 - (class (aget a 3)) (class (nth v 3)) 486.235 - (class (aget a 4)) (class (nth v 4)) )) 486.236 - 486.237 - ; different kinds of collections 486.238 - (are [x] (and (= (alength (to-array x)) (count x)) 486.239 - (= (vec (to-array x)) (vec x))) 486.240 - () 486.241 - '(1 2) 486.242 - [] 486.243 - [1 2] 486.244 - (sorted-set) 486.245 - (sorted-set 1 2) 486.246 - 486.247 - (int-array 0) 486.248 - (int-array [1 2 3]) 486.249 - 486.250 - (to-array []) 486.251 - (to-array [1 2 3]) )) 486.252 - 486.253 - 486.254 -(deftest test-into-array 486.255 - ; compatible types only 486.256 - (is (thrown? IllegalArgumentException (into-array [1 "abc" :kw]))) 486.257 - (is (thrown? IllegalArgumentException (into-array [1.2 4]))) 486.258 - (is (thrown? IllegalArgumentException (into-array [(byte 2) (short 3)]))) 486.259 - 486.260 - ; simple case 486.261 - (let [v [1 2 3 4 5] 486.262 - a (into-array v)] 486.263 - (are [x y] (= x y) 486.264 - (alength a) (count v) 486.265 - (vec a) v 486.266 - (class (first a)) (class (first v)) )) 486.267 - 486.268 - ; given type 486.269 - (let [a (into-array Integer/TYPE [(byte 2) (short 3) (int 4)])] 486.270 - (are [x] (= x Integer) 486.271 - (class (aget a 0)) 486.272 - (class (aget a 1)) 486.273 - (class (aget a 2)) )) 486.274 - 486.275 - ; different kinds of collections 486.276 - (are [x] (and (= (alength (into-array x)) (count x)) 486.277 - (= (vec (into-array x)) (vec x)) 486.278 - (= (alength (into-array Integer/TYPE x)) (count x)) 486.279 - (= (vec (into-array Integer/TYPE x)) (vec x))) 486.280 - () 486.281 - '(1 2) 486.282 - [] 486.283 - [1 2] 486.284 - (sorted-set) 486.285 - (sorted-set 1 2) 486.286 - 486.287 - (int-array 0) 486.288 - (int-array [1 2 3]) 486.289 - 486.290 - (to-array []) 486.291 - (to-array [1 2 3]) )) 486.292 - 486.293 - 486.294 -(deftest test-to-array-2d 486.295 - ; needs to be a collection of collection(s) 486.296 - (is (thrown? Exception (to-array-2d [1 2 3]))) 486.297 - 486.298 - ; ragged array 486.299 - (let [v [[1] [2 3] [4 5 6]] 486.300 - a (to-array-2d v)] 486.301 - (are [x y] (= x y) 486.302 - (alength a) (count v) 486.303 - (alength (aget a 0)) (count (nth v 0)) 486.304 - (alength (aget a 1)) (count (nth v 1)) 486.305 - (alength (aget a 2)) (count (nth v 2)) 486.306 - 486.307 - (vec (aget a 0)) (nth v 0) 486.308 - (vec (aget a 1)) (nth v 1) 486.309 - (vec (aget a 2)) (nth v 2) )) 486.310 - 486.311 - ; empty array 486.312 - (let [a (to-array-2d [])] 486.313 - (are [x y] (= x y) 486.314 - (alength a) 0 486.315 - (vec a) [] ))) 486.316 - 486.317 - 486.318 -(deftest test-alength 486.319 - (are [x] (= (alength x) 0) 486.320 - (int-array 0) 486.321 - (long-array 0) 486.322 - (float-array 0) 486.323 - (double-array 0) 486.324 - (boolean-array 0) 486.325 - (byte-array 0) 486.326 - (char-array 0) 486.327 - (short-array 0) 486.328 - (make-array Integer/TYPE 0) 486.329 - (to-array []) 486.330 - (into-array []) 486.331 - (to-array-2d []) ) 486.332 - 486.333 - (are [x] (= (alength x) 1) 486.334 - (int-array 1) 486.335 - (long-array 1) 486.336 - (float-array 1) 486.337 - (double-array 1) 486.338 - (boolean-array 1) 486.339 - (byte-array 1) 486.340 - (char-array 1) 486.341 - (short-array 1) 486.342 - (make-array Integer/TYPE 1) 486.343 - (to-array [1]) 486.344 - (into-array [1]) 486.345 - (to-array-2d [[1]]) ) 486.346 - 486.347 - (are [x] (= (alength x) 3) 486.348 - (int-array 3) 486.349 - (long-array 3) 486.350 - (float-array 3) 486.351 - (double-array 3) 486.352 - (boolean-array 3) 486.353 - (byte-array 3) 486.354 - (char-array 3) 486.355 - (short-array 3) 486.356 - (make-array Integer/TYPE 3) 486.357 - (to-array [1 "a" :k]) 486.358 - (into-array [1 2 3]) 486.359 - (to-array-2d [[1] [2 3] [4 5 6]]) )) 486.360 - 486.361 - 486.362 -(deftest test-aclone 486.363 - ; clone all arrays except 2D 486.364 - (are [x] (and (= (alength (aclone x)) (alength x)) 486.365 - (= (vec (aclone x)) (vec x))) 486.366 - (int-array 0) 486.367 - (long-array 0) 486.368 - (float-array 0) 486.369 - (double-array 0) 486.370 - (boolean-array 0) 486.371 - (byte-array 0) 486.372 - (char-array 0) 486.373 - (short-array 0) 486.374 - (make-array Integer/TYPE 0) 486.375 - (to-array []) 486.376 - (into-array []) 486.377 - 486.378 - (int-array [1 2 3]) 486.379 - (long-array [1 2 3]) 486.380 - (float-array [1 2 3]) 486.381 - (double-array [1 2 3]) 486.382 - (boolean-array [true false]) 486.383 - (byte-array [(byte 1) (byte 2)]) 486.384 - (char-array [\a \b \c]) 486.385 - (short-array [(short 1) (short 2)]) 486.386 - (make-array Integer/TYPE 3) 486.387 - (to-array [1 "a" :k]) 486.388 - (into-array [1 2 3]) ) 486.389 - 486.390 - ; clone 2D 486.391 - (are [x] (and (= (alength (aclone x)) (alength x)) 486.392 - (= (map alength (aclone x)) (map alength x)) 486.393 - (= (map vec (aclone x)) (map vec x))) 486.394 - (to-array-2d []) 486.395 - (to-array-2d [[1] [2 3] [4 5 6]]) )) 486.396 - 486.397 - 486.398 -; Type Hints, *warn-on-reflection* 486.399 -; #^ints, #^floats, #^longs, #^doubles 486.400 - 486.401 -; Coercions: [int, long, float, double, char, boolean, short, byte] 486.402 -; num 486.403 -; ints/longs/floats/doubles 486.404 - 486.405 -(deftest test-boolean 486.406 - (are [x y] (and (instance? java.lang.Boolean (boolean x)) 486.407 - (= (boolean x) y)) 486.408 - nil false 486.409 - false false 486.410 - true true 486.411 - 486.412 - 0 true 486.413 - 1 true 486.414 - () true 486.415 - [1] true 486.416 - 486.417 - "" true 486.418 - \space true 486.419 - :kw true )) 486.420 - 486.421 - 486.422 -(deftest test-char 486.423 - ; int -> char 486.424 - (is (instance? java.lang.Character (char 65))) 486.425 - 486.426 - ; char -> char 486.427 - (is (instance? java.lang.Character (char \a))) 486.428 - (is (= (char \a) \a))) 486.429 - 486.430 -;; Note: More coercions in numbers.clj
487.1 --- a/src/clojure/test_clojure/logic.clj Sat Aug 21 06:25:44 2010 -0400 487.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 487.3 @@ -1,205 +0,0 @@ 487.4 -; Copyright (c) Rich Hickey. All rights reserved. 487.5 -; The use and distribution terms for this software are covered by the 487.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 487.7 -; which can be found in the file epl-v10.html at the root of this distribution. 487.8 -; By using this software in any fashion, you are agreeing to be bound by 487.9 -; the terms of this license. 487.10 -; You must not remove this notice, or any other, from this software. 487.11 - 487.12 -; Author: Frantisek Sodomka 487.13 - 487.14 -;; 487.15 -;; Created 1/29/2009 487.16 - 487.17 -(ns clojure.test-clojure.logic 487.18 - (:use clojure.test 487.19 - [clojure.test-clojure.helpers :only (exception)])) 487.20 - 487.21 - 487.22 -;; *** Tests *** 487.23 - 487.24 -(deftest test-if 487.25 - ; true/false/nil 487.26 - (are [x y] (= x y) 487.27 - (if true :t) :t 487.28 - (if true :t :f) :t 487.29 - (if true :t (exception)) :t 487.30 - 487.31 - (if false :t) nil 487.32 - (if false :t :f) :f 487.33 - (if false (exception) :f) :f 487.34 - 487.35 - (if nil :t) nil 487.36 - (if nil :t :f) :f 487.37 - (if nil (exception) :f) :f ) 487.38 - 487.39 - ; zero/empty is true 487.40 - (are [x] (= (if x :t :f) :t) 487.41 - (byte 0) 487.42 - (short 0) 487.43 - (int 0) 487.44 - (long 0) 487.45 - (bigint 0) 487.46 - (float 0) 487.47 - (double 0) 487.48 - (bigdec 0) 487.49 - 487.50 - 0/2 487.51 - "" 487.52 - #"" 487.53 - (symbol "") 487.54 - 487.55 - () 487.56 - [] 487.57 - {} 487.58 - #{} 487.59 - (into-array []) ) 487.60 - 487.61 - ; anything except nil/false is true 487.62 - (are [x] (= (if x :t :f) :t) 487.63 - (byte 2) 487.64 - (short 2) 487.65 - (int 2) 487.66 - (long 2) 487.67 - (bigint 2) 487.68 - (float 2) 487.69 - (double 2) 487.70 - (bigdec 2) 487.71 - 487.72 - 2/3 487.73 - \a 487.74 - "abc" 487.75 - #"a*b" 487.76 - 'abc 487.77 - :kw 487.78 - 487.79 - '(1 2) 487.80 - [1 2] 487.81 - {:a 1 :b 2} 487.82 - #{1 2} 487.83 - (into-array [1 2]) 487.84 - 487.85 - (new java.util.Date) )) 487.86 - 487.87 - 487.88 -(deftest test-nil-punning 487.89 - (are [x y] (= (if x :no :yes) y) 487.90 - (first []) :yes 487.91 - (next [1]) :yes 487.92 - (rest [1]) :no 487.93 - 487.94 - (butlast [1]) :yes 487.95 - 487.96 - (seq nil) :yes 487.97 - (seq []) :yes 487.98 - 487.99 - (sequence nil) :no 487.100 - (sequence []) :no 487.101 - 487.102 - (lazy-seq nil) :no 487.103 - (lazy-seq []) :no 487.104 - 487.105 - (filter #(> % 10) [1 2 3]) :no 487.106 - (map identity []) :no 487.107 - (apply concat []) :no 487.108 - 487.109 - (concat) :no 487.110 - (concat []) :no 487.111 - 487.112 - (reverse nil) :no 487.113 - (reverse []) :no 487.114 - 487.115 - (sort nil) :no 487.116 - (sort []) :no )) 487.117 - 487.118 - 487.119 -(deftest test-and 487.120 - (are [x y] (= x y) 487.121 - (and) true 487.122 - (and true) true 487.123 - (and nil) nil 487.124 - (and false) false 487.125 - 487.126 - (and true nil) nil 487.127 - (and true false) false 487.128 - 487.129 - (and 1 true :kw 'abc "abc") "abc" 487.130 - 487.131 - (and 1 true :kw nil 'abc "abc") nil 487.132 - (and 1 true :kw nil (exception) 'abc "abc") nil 487.133 - 487.134 - (and 1 true :kw 'abc "abc" false) false 487.135 - (and 1 true :kw 'abc "abc" false (exception)) false )) 487.136 - 487.137 - 487.138 -(deftest test-or 487.139 - (are [x y] (= x y) 487.140 - (or) nil 487.141 - (or true) true 487.142 - (or nil) nil 487.143 - (or false) false 487.144 - 487.145 - (or nil false true) true 487.146 - (or nil false 1 2) 1 487.147 - (or nil false "abc" :kw) "abc" 487.148 - 487.149 - (or false nil) nil 487.150 - (or nil false) false 487.151 - (or nil nil nil false) false 487.152 - 487.153 - (or nil true false) true 487.154 - (or nil true (exception) false) true 487.155 - (or nil false "abc" (exception)) "abc" )) 487.156 - 487.157 - 487.158 -(deftest test-not 487.159 - (is (thrown? IllegalArgumentException (not))) 487.160 - (are [x] (= (not x) true) 487.161 - nil 487.162 - false ) 487.163 - (are [x] (= (not x) false) 487.164 - true 487.165 - 487.166 - ; numbers 487.167 - 0 487.168 - 0.0 487.169 - 42 487.170 - 1.2 487.171 - 0/2 487.172 - 2/3 487.173 - 487.174 - ; characters 487.175 - \space 487.176 - \tab 487.177 - \a 487.178 - 487.179 - ; strings 487.180 - "" 487.181 - "abc" 487.182 - 487.183 - ; regexes 487.184 - #"" 487.185 - #"a*b" 487.186 - 487.187 - ; symbols 487.188 - (symbol "") 487.189 - 'abc 487.190 - 487.191 - ; keywords 487.192 - :kw 487.193 - 487.194 - ; collections/arrays 487.195 - () 487.196 - '(1 2) 487.197 - [] 487.198 - [1 2] 487.199 - {} 487.200 - {:a 1 :b 2} 487.201 - #{} 487.202 - #{1 2} 487.203 - (into-array []) 487.204 - (into-array [1 2]) 487.205 - 487.206 - ; Java objects 487.207 - (new java.util.Date) )) 487.208 -
488.1 --- a/src/clojure/test_clojure/macros.clj Sat Aug 21 06:25:44 2010 -0400 488.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 488.3 @@ -1,18 +0,0 @@ 488.4 -; Copyright (c) Rich Hickey. All rights reserved. 488.5 -; The use and distribution terms for this software are covered by the 488.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 488.7 -; which can be found in the file epl-v10.html at the root of this distribution. 488.8 -; By using this software in any fashion, you are agreeing to be bound by 488.9 -; the terms of this license. 488.10 -; You must not remove this notice, or any other, from this software. 488.11 - 488.12 -; Author: Frantisek Sodomka 488.13 - 488.14 -(ns clojure.test-clojure.macros 488.15 - (:use clojure.test)) 488.16 - 488.17 -; http://clojure.org/macros 488.18 - 488.19 -; -> 488.20 -; defmacro definline macroexpand-1 macroexpand 488.21 -
489.1 --- a/src/clojure/test_clojure/main.clj Sat Aug 21 06:25:44 2010 -0400 489.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 489.3 @@ -1,50 +0,0 @@ 489.4 -; Copyright (c) Rich Hickey. All rights reserved. 489.5 -; The use and distribution terms for this software are covered by the 489.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 489.7 -; which can be found in the file epl-v10.html at the root of this distribution. 489.8 -; By using this software in any fashion, you are agreeing to be bound by 489.9 -; the terms of this license. 489.10 -; You must not remove this notice, or any other, from this software. 489.11 - 489.12 -; Author: Stuart Halloway 489.13 - 489.14 - 489.15 -(ns clojure.test-clojure.main 489.16 - (:use clojure.test) 489.17 - (:require [clojure.main :as main])) 489.18 - 489.19 -(deftest eval-opt 489.20 - (testing "evals and prints forms" 489.21 - (is (= "2\n4\n" (with-out-str (#'clojure.main/eval-opt "(+ 1 1) (+ 2 2)"))))) 489.22 - 489.23 - (testing "skips printing nils" 489.24 - (is (= ":a\n:c\n" (with-out-str (#'clojure.main/eval-opt ":a nil :c"))))) 489.25 - 489.26 - (testing "does not block access to *in* (#299)" 489.27 - (with-in-str "(+ 1 1)" 489.28 - (is (= "(+ 1 1)\n" (with-out-str (#'clojure.main/eval-opt "(read)"))))))) 489.29 - 489.30 -(defmacro with-err-str 489.31 - "Evaluates exprs in a context in which *err* is bound to a fresh 489.32 - StringWriter. Returns the string created by any nested printing 489.33 - calls." 489.34 - [& body] 489.35 - `(let [s# (new java.io.StringWriter) 489.36 - p# (new java.io.PrintWriter s#)] 489.37 - (binding [*err* p#] 489.38 - ~@body 489.39 - (str s#)))) 489.40 - 489.41 -(defn run-repl-and-return-err 489.42 - "Run repl, swallowing stdout and returing stderr." 489.43 - [in-str] 489.44 - (with-err-str 489.45 - (with-out-str 489.46 - (with-in-str in-str 489.47 - (main/repl))))) 489.48 - 489.49 -(deftest repl-exception-safety 489.50 - (testing "catches and prints exception on bad equals" 489.51 - (is (re-matches #"java\.lang\.NullPointerException\r?\n" 489.52 - (run-repl-and-return-err 489.53 - "(proxy [Object] [] (equals [o] (.toString nil)))")))))
490.1 --- a/src/clojure/test_clojure/metadata.clj Sat Aug 21 06:25:44 2010 -0400 490.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 490.3 @@ -1,76 +0,0 @@ 490.4 -; Copyright (c) Rich Hickey. All rights reserved. 490.5 -; The use and distribution terms for this software are covered by the 490.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 490.7 -; which can be found in the file epl-v10.html at the root of this distribution. 490.8 -; By using this software in any fashion, you are agreeing to be bound by 490.9 -; the terms of this license. 490.10 -; You must not remove this notice, or any other, from this software. 490.11 - 490.12 -; Authors: Stuart Halloway, Frantisek Sodomka 490.13 - 490.14 -(ns clojure.test-clojure.metadata 490.15 - (:use clojure.test 490.16 - [clojure.test-clojure.helpers :only (eval-in-temp-ns)])) 490.17 - 490.18 -(def public-namespaces 490.19 - '[clojure.core 490.20 - clojure.pprint 490.21 - clojure.inspector 490.22 - clojure.set 490.23 - clojure.stacktrace 490.24 - clojure.test 490.25 - clojure.walk 490.26 - clojure.xml 490.27 - clojure.zip 490.28 - clojure.java.io 490.29 - clojure.java.browse 490.30 - clojure.java.javadoc 490.31 - clojure.java.shell 490.32 - clojure.string]) 490.33 - 490.34 -(doseq [ns public-namespaces] 490.35 - (require ns)) 490.36 - 490.37 -(def public-vars 490.38 - (mapcat #(vals (ns-publics %)) public-namespaces)) 490.39 - 490.40 -(def public-vars-with-docstrings 490.41 - (filter (comp :doc meta) public-vars)) 490.42 - 490.43 -(deftest public-vars-with-docstrings-have-added 490.44 - (is (= [] (remove (comp :added meta) public-vars-with-docstrings)))) 490.45 - 490.46 -(deftest interaction-of-def-with-metadata 490.47 - (testing "initial def sets metadata" 490.48 - (let [v (eval-in-temp-ns 490.49 - (def ^{:a 1} foo 0) 490.50 - #'foo)] 490.51 - (is (= 1 (-> v meta :a))))) 490.52 - (testing "subsequent declare doesn't overwrite metadata" 490.53 - (let [v (eval-in-temp-ns 490.54 - (def ^{:b 2} bar 0) 490.55 - (declare bar) 490.56 - #'bar)] 490.57 - (is (= 2 (-> v meta :b)))) 490.58 - (testing "when compiled" 490.59 - (let [v (eval-in-temp-ns 490.60 - (def ^{:c 3} bar 0) 490.61 - (defn declare-bar [] 490.62 - (declare bar)) 490.63 - (declare-bar) 490.64 - #'bar)] 490.65 - (is (= 3 (-> v meta :c)))))) 490.66 - (testing "subsequent def with init-expr *does* overwrite metadata" 490.67 - (let [v (eval-in-temp-ns 490.68 - (def ^{:d 4} quux 0) 490.69 - (def quux 1) 490.70 - #'quux)] 490.71 - (is (nil? (-> v meta :d)))) 490.72 - (testing "when compiled" 490.73 - (let [v (eval-in-temp-ns 490.74 - (def ^{:e 5} quux 0) 490.75 - (defn def-quux [] 490.76 - (def quux 1)) 490.77 - (def-quux) 490.78 - #'quux)] 490.79 - (is (nil? (-> v meta :e)))))))
491.1 --- a/src/clojure/test_clojure/multimethods.clj Sat Aug 21 06:25:44 2010 -0400 491.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 491.3 @@ -1,160 +0,0 @@ 491.4 -; Copyright (c) Rich Hickey. All rights reserved. 491.5 -; The use and distribution terms for this software are covered by the 491.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 491.7 -; which can be found in the file epl-v10.html at the root of this distribution. 491.8 -; By using this software in any fashion, you are agreeing to be bound by 491.9 -; the terms of this license. 491.10 -; You must not remove this notice, or any other, from this software. 491.11 - 491.12 -; Author: Frantisek Sodomka, Robert Lachlan 491.13 - 491.14 -(ns clojure.test-clojure.multimethods 491.15 - (:use clojure.test [clojure.test-clojure.helpers :only (with-var-roots)]) 491.16 - (:require [clojure.set :as set])) 491.17 - 491.18 -; http://clojure.org/multimethods 491.19 - 491.20 -; defmulti 491.21 -; defmethod 491.22 -; remove-method 491.23 -; prefer-method 491.24 -; methods 491.25 -; prefers 491.26 - 491.27 -(defmacro for-all 491.28 - [& args] 491.29 - `(dorun (for ~@args))) 491.30 - 491.31 -(defn hierarchy-tags 491.32 - "Return all tags in a derivation hierarchy" 491.33 - [h] 491.34 - (set/select 491.35 - #(instance? clojure.lang.Named %) 491.36 - (reduce into #{} (map keys (vals h))))) 491.37 - 491.38 -(defn transitive-closure 491.39 - "Return all objects reachable by calling f starting with o, 491.40 - not including o itself. f should return a collection." 491.41 - [o f] 491.42 - (loop [results #{} 491.43 - more #{o}] 491.44 - (let [new-objects (set/difference more results)] 491.45 - (if (seq new-objects) 491.46 - (recur (set/union results more) (reduce into #{} (map f new-objects))) 491.47 - (disj results o))))) 491.48 - 491.49 -(defn tag-descendants 491.50 - "Set of descedants which are tags (i.e. Named)." 491.51 - [& args] 491.52 - (set/select 491.53 - #(instance? clojure.lang.Named %) 491.54 - (or (apply descendants args) #{}))) 491.55 - 491.56 -(defn assert-valid-hierarchy 491.57 - [h] 491.58 - (let [tags (hierarchy-tags h)] 491.59 - (testing "ancestors are the transitive closure of parents" 491.60 - (for-all [tag tags] 491.61 - (is (= (transitive-closure tag #(parents h %)) 491.62 - (or (ancestors h tag) #{}))))) 491.63 - (testing "ancestors are transitive" 491.64 - (for-all [tag tags] 491.65 - (is (= (transitive-closure tag #(ancestors h %)) 491.66 - (or (ancestors h tag) #{}))))) 491.67 - (testing "tag descendants are transitive" 491.68 - (for-all [tag tags] 491.69 - (is (= (transitive-closure tag #(tag-descendants h %)) 491.70 - (or (tag-descendants h tag) #{}))))) 491.71 - (testing "a tag isa? all of its parents" 491.72 - (for-all [tag tags 491.73 - :let [parents (parents h tag)] 491.74 - parent parents] 491.75 - (is (isa? h tag parent)))) 491.76 - (testing "a tag isa? all of its ancestors" 491.77 - (for-all [tag tags 491.78 - :let [ancestors (ancestors h tag)] 491.79 - ancestor ancestors] 491.80 - (is (isa? h tag ancestor)))) 491.81 - (testing "all my descendants have me as an ancestor" 491.82 - (for-all [tag tags 491.83 - :let [descendants (descendants h tag)] 491.84 - descendant descendants] 491.85 - (is (isa? h descendant tag)))) 491.86 - (testing "there are no cycles in parents" 491.87 - (for-all [tag tags] 491.88 - (is (not (contains? (transitive-closure tag #(parents h %)) tag))))) 491.89 - (testing "there are no cycles in descendants" 491.90 - (for-all [tag tags] 491.91 - (is (not (contains? (descendants h tag) tag))))))) 491.92 - 491.93 -(def family 491.94 - (reduce #(apply derive (cons %1 %2)) (make-hierarchy) 491.95 - [[::parent-1 ::ancestor-1] 491.96 - [::parent-1 ::ancestor-2] 491.97 - [::parent-2 ::ancestor-2] 491.98 - [::child ::parent-2] 491.99 - [::child ::parent-1]])) 491.100 - 491.101 -(deftest cycles-are-forbidden 491.102 - (testing "a tag cannot be its own parent" 491.103 - (is (thrown-with-msg? Throwable #"\(not= tag parent\)" 491.104 - (derive family ::child ::child)))) 491.105 - (testing "a tag cannot be its own ancestor" 491.106 - (is (thrown-with-msg? Throwable #"Cyclic derivation: :clojure.test-clojure.multimethods/child has :clojure.test-clojure.multimethods/ancestor-1 as ancestor" 491.107 - (derive family ::ancestor-1 ::child))))) 491.108 - 491.109 -(deftest using-diamond-inheritance 491.110 - (let [diamond (reduce #(apply derive (cons %1 %2)) (make-hierarchy) 491.111 - [[::mammal ::animal] 491.112 - [::bird ::animal] 491.113 - [::griffin ::mammal] 491.114 - [::griffin ::bird]]) 491.115 - bird-no-more (underive diamond ::griffin ::bird)] 491.116 - (assert-valid-hierarchy diamond) 491.117 - (assert-valid-hierarchy bird-no-more) 491.118 - (testing "a griffin is a mammal, indirectly through mammal and bird" 491.119 - (is (isa? diamond ::griffin ::animal))) 491.120 - (testing "a griffin is a bird" 491.121 - (is (isa? diamond ::griffin ::bird))) 491.122 - (testing "after underive, griffin is no longer a bird" 491.123 - (is (not (isa? bird-no-more ::griffin ::bird)))) 491.124 - (testing "but it is still an animal, via mammal" 491.125 - (is (isa? bird-no-more ::griffin ::animal))))) 491.126 - 491.127 -(deftest derivation-world-bridges-to-java-inheritance 491.128 - (let [h (derive (make-hierarchy) java.util.Map ::map)] 491.129 - (testing "a Java class can be isa? a tag" 491.130 - (is (isa? h java.util.Map ::map))) 491.131 - (testing "if a Java class isa? a tag, so are its subclasses..." 491.132 - (is (isa? h java.util.HashMap ::map))) 491.133 - (testing "...but not its superclasses!" 491.134 - (is (not (isa? h java.util.Collection ::map)))))) 491.135 - 491.136 -(deftest global-hierarchy-test 491.137 - (with-var-roots {#'clojure.core/global-hierarchy (make-hierarchy)} 491.138 - (assert-valid-hierarchy @#'clojure.core/global-hierarchy) 491.139 - (testing "when you add some derivations..." 491.140 - (derive ::lion ::cat) 491.141 - (derive ::manx ::cat) 491.142 - (assert-valid-hierarchy @#'clojure.core/global-hierarchy)) 491.143 - (testing "...isa? sees the derivations" 491.144 - (is (isa? ::lion ::cat)) 491.145 - (is (not (isa? ::cat ::lion)))) 491.146 - (testing "... you can traverse the derivations" 491.147 - (is (= #{::manx ::lion} (descendants ::cat))) 491.148 - (is (= #{::cat} (parents ::manx))) 491.149 - (is (= #{::cat} (ancestors ::manx)))) 491.150 - (testing "then, remove a derivation..." 491.151 - (underive ::manx ::cat)) 491.152 - (testing "... traversals update accordingly" 491.153 - (is (= #{::lion} (descendants ::cat))) 491.154 - (is (nil? (parents ::manx))) 491.155 - (is (nil? (ancestors ::manx)))))) 491.156 - 491.157 -#_(defmacro for-all 491.158 - "Better than the actual for-all, if only it worked." 491.159 - [& args] 491.160 - `(reduce 491.161 - #(and %1 %2) 491.162 - (map true? (for ~@args)))) 491.163 -
492.1 --- a/src/clojure/test_clojure/ns_libs.clj Sat Aug 21 06:25:44 2010 -0400 492.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 492.3 @@ -1,85 +0,0 @@ 492.4 -; Copyright (c) Rich Hickey. All rights reserved. 492.5 -; The use and distribution terms for this software are covered by the 492.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 492.7 -; which can be found in the file epl-v10.html at the root of this distribution. 492.8 -; By using this software in any fashion, you are agreeing to be bound by 492.9 -; the terms of this license. 492.10 -; You must not remove this notice, or any other, from this software. 492.11 - 492.12 -; Authors: Frantisek Sodomka, Stuart Halloway 492.13 - 492.14 -(ns clojure.test-clojure.ns-libs 492.15 - (:use clojure.test)) 492.16 - 492.17 -; http://clojure.org/namespaces 492.18 - 492.19 -; in-ns ns create-ns 492.20 -; alias import intern refer 492.21 -; all-ns find-ns 492.22 -; ns-name ns-aliases ns-imports ns-interns ns-map ns-publics ns-refers 492.23 -; resolve ns-resolve namespace 492.24 -; ns-unalias ns-unmap remove-ns 492.25 - 492.26 - 492.27 -; http://clojure.org/libs 492.28 - 492.29 -; require use 492.30 -; loaded-libs 492.31 - 492.32 -(deftest test-require 492.33 - (is (thrown? Exception (require :foo))) 492.34 - (is (thrown? Exception (require)))) 492.35 - 492.36 -(deftest test-use 492.37 - (is (thrown? Exception (use :foo))) 492.38 - (is (thrown? Exception (use)))) 492.39 - 492.40 -(deftest reimporting-deftypes 492.41 - (let [inst1 (binding [*ns* *ns*] 492.42 - (eval '(do (ns exporter) 492.43 - (defrecord ReimportMe [a]) 492.44 - (ns importer) 492.45 - (import exporter.ReimportMe) 492.46 - (ReimportMe. 1)))) 492.47 - inst2 (binding [*ns* *ns*] 492.48 - (eval '(do (ns exporter) 492.49 - (defrecord ReimportMe [a b]) 492.50 - (ns importer) 492.51 - (import exporter.ReimportMe) 492.52 - (ReimportMe. 1 2))))] 492.53 - (testing "you can reimport a changed class and see the changes" 492.54 - (is (= [:a] (keys inst1))) 492.55 - (is (= [:a :b] (keys inst2)))) 492.56 - (testing "you cannot import same local name from a different namespace" 492.57 - (is (thrown? clojure.lang.Compiler$CompilerException 492.58 - #"ReimportMe already refers to: class exporter.ReimportMe in namespace: importer" 492.59 - (binding [*ns* *ns*] 492.60 - (eval '(do (ns exporter-2) 492.61 - (defrecord ReimportMe [a b]) 492.62 - (ns importer) 492.63 - (import exporter-2.ReimportMe) 492.64 - (ReimportMe. 1 2))))))))) 492.65 - 492.66 -(deftest naming-types 492.67 - (testing "you cannot use a name already referred from another namespace" 492.68 - (is (thrown? IllegalStateException 492.69 - #"String already refers to: class java.lang.String" 492.70 - (definterface String))) 492.71 - (is (thrown? IllegalStateException 492.72 - #"StringBuffer already refers to: class java.lang.StringBuffer" 492.73 - (deftype StringBuffer []))) 492.74 - (is (thrown? IllegalStateException 492.75 - #"Integer already refers to: class java.lang.Integer" 492.76 - (defrecord Integer []))))) 492.77 - 492.78 -(deftest refer-error-messages 492.79 - (let [temp-ns (gensym)] 492.80 - (binding [*ns* *ns*] 492.81 - (in-ns temp-ns) 492.82 - (eval '(def ^{:private true} hidden-var))) 492.83 - (testing "referring to something that does not exist" 492.84 - (is (thrown-with-msg? IllegalAccessError #"nonexistent-var does not exist" 492.85 - (refer temp-ns :only '(nonexistent-var))))) 492.86 - (testing "referring to something non-public" 492.87 - (is (thrown-with-msg? IllegalAccessError #"hidden-var is not public" 492.88 - (refer temp-ns :only '(hidden-var)))))))
493.1 --- a/src/clojure/test_clojure/numbers.clj Sat Aug 21 06:25:44 2010 -0400 493.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 493.3 @@ -1,444 +0,0 @@ 493.4 -; Copyright (c) Rich Hickey. All rights reserved. 493.5 -; The use and distribution terms for this software are covered by the 493.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 493.7 -; which can be found in the file epl-v10.html at the root of this distribution. 493.8 -; By using this software in any fashion, you are agreeing to be bound by 493.9 -; the terms of this license. 493.10 -; You must not remove this notice, or any other, from this software. 493.11 - 493.12 -; Author: Stephen C. Gilardi 493.13 -;; scgilardi (gmail) 493.14 -;; Created 30 October 2008 493.15 -;; 493.16 - 493.17 -(ns clojure.test-clojure.numbers 493.18 - (:use clojure.test)) 493.19 - 493.20 - 493.21 -; TODO: 493.22 -; == 493.23 -; and more... 493.24 - 493.25 - 493.26 -;; *** Types *** 493.27 - 493.28 -(deftest Coerced-Byte 493.29 - (let [v (byte 3)] 493.30 - (are [x] (true? x) 493.31 - (instance? Byte v) 493.32 - (number? v) 493.33 - (integer? v) 493.34 - (rational? v)))) 493.35 - 493.36 -(deftest Coerced-Short 493.37 - (let [v (short 3)] 493.38 - (are [x] (true? x) 493.39 - (instance? Short v) 493.40 - (number? v) 493.41 - (integer? v) 493.42 - (rational? v)))) 493.43 - 493.44 -(deftest Coerced-Integer 493.45 - (let [v (int 3)] 493.46 - (are [x] (true? x) 493.47 - (instance? Integer v) 493.48 - (number? v) 493.49 - (integer? v) 493.50 - (rational? v)))) 493.51 - 493.52 -(deftest Coerced-Long 493.53 - (let [v (long 3)] 493.54 - (are [x] (true? x) 493.55 - (instance? Long v) 493.56 - (number? v) 493.57 - (integer? v) 493.58 - (rational? v)))) 493.59 - 493.60 -(deftest Coerced-BigInteger 493.61 - (let [v (bigint 3)] 493.62 - (are [x] (true? x) 493.63 - (instance? BigInteger v) 493.64 - (number? v) 493.65 - (integer? v) 493.66 - (rational? v)))) 493.67 - 493.68 -(deftest Coerced-Float 493.69 - (let [v (float 3)] 493.70 - (are [x] (true? x) 493.71 - (instance? Float v) 493.72 - (number? v) 493.73 - (float? v)))) 493.74 - 493.75 -(deftest Coerced-Double 493.76 - (let [v (double 3)] 493.77 - (are [x] (true? x) 493.78 - (instance? Double v) 493.79 - (number? v) 493.80 - (float? v)))) 493.81 - 493.82 -(deftest Coerced-BigDecimal 493.83 - (let [v (bigdec 3)] 493.84 - (are [x] (true? x) 493.85 - (instance? BigDecimal v) 493.86 - (number? v) 493.87 - (decimal? v) 493.88 - (not (float? v))))) 493.89 - 493.90 - 493.91 -;; *** Functions *** 493.92 - 493.93 -(defonce DELTA 1e-12) 493.94 - 493.95 -(deftest test-add 493.96 - (are [x y] (= x y) 493.97 - (+) 0 493.98 - (+ 1) 1 493.99 - (+ 1 2) 3 493.100 - (+ 1 2 3) 6 493.101 - 493.102 - (+ -1) -1 493.103 - (+ -1 -2) -3 493.104 - (+ -1 +2 -3) -2 493.105 - 493.106 - (+ 1 -1) 0 493.107 - (+ -1 1) 0 493.108 - 493.109 - (+ 2/3) 2/3 493.110 - (+ 2/3 1) 5/3 493.111 - (+ 2/3 1/3) 1 ) 493.112 - 493.113 - (are [x y] (< (- x y) DELTA) 493.114 - (+ 1.2) 1.2 493.115 - (+ 1.1 2.4) 3.5 493.116 - (+ 1.1 2.2 3.3) 6.6 ) 493.117 - 493.118 - (is (> (+ Integer/MAX_VALUE 10) Integer/MAX_VALUE)) ; no overflow 493.119 - (is (thrown? ClassCastException (+ "ab" "cd"))) ) ; no string concatenation 493.120 - 493.121 - 493.122 -(deftest test-subtract 493.123 - (is (thrown? IllegalArgumentException (-))) 493.124 - (are [x y] (= x y) 493.125 - (- 1) -1 493.126 - (- 1 2) -1 493.127 - (- 1 2 3) -4 493.128 - 493.129 - (- -2) 2 493.130 - (- 1 -2) 3 493.131 - (- 1 -2 -3) 6 493.132 - 493.133 - (- 1 1) 0 493.134 - (- -1 -1) 0 493.135 - 493.136 - (- 2/3) -2/3 493.137 - (- 2/3 1) -1/3 493.138 - (- 2/3 1/3) 1/3 ) 493.139 - 493.140 - (are [x y] (< (- x y) DELTA) 493.141 - (- 1.2) -1.2 493.142 - (- 2.2 1.1) 1.1 493.143 - (- 6.6 2.2 1.1) 3.3 ) 493.144 - 493.145 - (is (< (- Integer/MIN_VALUE 10) Integer/MIN_VALUE)) ) ; no underflow 493.146 - 493.147 - 493.148 -(deftest test-multiply 493.149 - (are [x y] (= x y) 493.150 - (*) 1 493.151 - (* 2) 2 493.152 - (* 2 3) 6 493.153 - (* 2 3 4) 24 493.154 - 493.155 - (* -2) -2 493.156 - (* 2 -3) -6 493.157 - (* 2 -3 -1) 6 493.158 - 493.159 - (* 1/2) 1/2 493.160 - (* 1/2 1/3) 1/6 493.161 - (* 1/2 1/3 -1/4) -1/24 ) 493.162 - 493.163 - (are [x y] (< (- x y) DELTA) 493.164 - (* 1.2) 1.2 493.165 - (* 2.0 1.2) 2.4 493.166 - (* 3.5 2.0 1.2) 8.4 ) 493.167 - 493.168 - (is (> (* 3 (int (/ Integer/MAX_VALUE 2.0))) Integer/MAX_VALUE)) ) ; no overflow 493.169 - 493.170 -(deftest test-ratios-simplify-to-ints-where-appropriate 493.171 - (testing "negative denominator (assembla #275)" 493.172 - (is (integer? (/ 1 -1/2))) 493.173 - (is (integer? (/ 0 -1/2))))) 493.174 - 493.175 -(deftest test-divide 493.176 - (are [x y] (= x y) 493.177 - (/ 1) 1 493.178 - (/ 2) 1/2 493.179 - (/ 3 2) 3/2 493.180 - (/ 4 2) 2 493.181 - (/ 24 3 2) 4 493.182 - (/ 24 3 2 -1) -4 493.183 - 493.184 - (/ -1) -1 493.185 - (/ -2) -1/2 493.186 - (/ -3 -2) 3/2 493.187 - (/ -4 -2) 2 493.188 - (/ -4 2) -2 ) 493.189 - 493.190 - (are [x y] (< (- x y) DELTA) 493.191 - (/ 4.5 3) 1.5 493.192 - (/ 4.5 3.0 3.0) 0.5 ) 493.193 - 493.194 - (is (thrown? ArithmeticException (/ 0))) 493.195 - (is (thrown? ArithmeticException (/ 2 0))) 493.196 - (is (thrown? IllegalArgumentException (/))) ) 493.197 - 493.198 - 493.199 -;; mod 493.200 -;; http://en.wikipedia.org/wiki/Modulo_operation 493.201 -;; http://mathforum.org/library/drmath/view/52343.html 493.202 -;; 493.203 -;; is mod correct? 493.204 -;; http://groups.google.com/group/clojure/browse_frm/thread/2a0ee4d248f3d131# 493.205 -;; 493.206 -;; Issue 23: mod (modulo) operator 493.207 -;; http://code.google.com/p/clojure/issues/detail?id=23 493.208 - 493.209 -(deftest test-mod 493.210 - ; wrong number of args 493.211 - (is (thrown? IllegalArgumentException (mod))) 493.212 - (is (thrown? IllegalArgumentException (mod 1))) 493.213 - (is (thrown? IllegalArgumentException (mod 3 2 1))) 493.214 - 493.215 - ; divide by zero 493.216 - (is (thrown? ArithmeticException (mod 9 0))) 493.217 - (is (thrown? ArithmeticException (mod 0 0))) 493.218 - 493.219 - (are [x y] (= x y) 493.220 - (mod 4 2) 0 493.221 - (mod 3 2) 1 493.222 - (mod 6 4) 2 493.223 - (mod 0 5) 0 493.224 - 493.225 - (mod 2 1/2) 0 493.226 - (mod 2/3 1/2) 1/6 493.227 - (mod 1 2/3) 1/3 493.228 - 493.229 - (mod 4.0 2.0) 0.0 493.230 - (mod 4.5 2.0) 0.5 493.231 - 493.232 - ; |num| > |div|, num != k * div 493.233 - (mod 42 5) 2 ; (42 / 5) * 5 + (42 mod 5) = 8 * 5 + 2 = 42 493.234 - (mod 42 -5) -3 ; (42 / -5) * (-5) + (42 mod -5) = -9 * (-5) + (-3) = 42 493.235 - (mod -42 5) 3 ; (-42 / 5) * 5 + (-42 mod 5) = -9 * 5 + 3 = -42 493.236 - (mod -42 -5) -2 ; (-42 / -5) * (-5) + (-42 mod -5) = 8 * (-5) + (-2) = -42 493.237 - 493.238 - ; |num| > |div|, num = k * div 493.239 - (mod 9 3) 0 ; (9 / 3) * 3 + (9 mod 3) = 3 * 3 + 0 = 9 493.240 - (mod 9 -3) 0 493.241 - (mod -9 3) 0 493.242 - (mod -9 -3) 0 493.243 - 493.244 - ; |num| < |div| 493.245 - (mod 2 5) 2 ; (2 / 5) * 5 + (2 mod 5) = 0 * 5 + 2 = 2 493.246 - (mod 2 -5) -3 ; (2 / -5) * (-5) + (2 mod -5) = (-1) * (-5) + (-3) = 2 493.247 - (mod -2 5) 3 ; (-2 / 5) * 5 + (-2 mod 5) = (-1) * 5 + 3 = -2 493.248 - (mod -2 -5) -2 ; (-2 / -5) * (-5) + (-2 mod -5) = 0 * (-5) + (-2) = -2 493.249 - 493.250 - ; num = 0, div != 0 493.251 - (mod 0 3) 0 ; (0 / 3) * 3 + (0 mod 3) = 0 * 3 + 0 = 0 493.252 - (mod 0 -3) 0 493.253 - ) 493.254 -) 493.255 - 493.256 -;; rem & quot 493.257 -;; http://en.wikipedia.org/wiki/Remainder 493.258 - 493.259 -(deftest test-rem 493.260 - ; wrong number of args 493.261 - (is (thrown? IllegalArgumentException (rem))) 493.262 - (is (thrown? IllegalArgumentException (rem 1))) 493.263 - (is (thrown? IllegalArgumentException (rem 3 2 1))) 493.264 - 493.265 - ; divide by zero 493.266 - (is (thrown? ArithmeticException (rem 9 0))) 493.267 - (is (thrown? ArithmeticException (rem 0 0))) 493.268 - 493.269 - (are [x y] (= x y) 493.270 - (rem 4 2) 0 493.271 - (rem 3 2) 1 493.272 - (rem 6 4) 2 493.273 - (rem 0 5) 0 493.274 - 493.275 - (rem 2 1/2) 0 493.276 - (rem 2/3 1/2) 1/6 493.277 - (rem 1 2/3) 1/3 493.278 - 493.279 - (rem 4.0 2.0) 0.0 493.280 - (rem 4.5 2.0) 0.5 493.281 - 493.282 - ; |num| > |div|, num != k * div 493.283 - (rem 42 5) 2 ; (8 * 5) + 2 == 42 493.284 - (rem 42 -5) 2 ; (-8 * -5) + 2 == 42 493.285 - (rem -42 5) -2 ; (-8 * 5) + -2 == -42 493.286 - (rem -42 -5) -2 ; (8 * -5) + -2 == -42 493.287 - 493.288 - ; |num| > |div|, num = k * div 493.289 - (rem 9 3) 0 493.290 - (rem 9 -3) 0 493.291 - (rem -9 3) 0 493.292 - (rem -9 -3) 0 493.293 - 493.294 - ; |num| < |div| 493.295 - (rem 2 5) 2 493.296 - (rem 2 -5) 2 493.297 - (rem -2 5) -2 493.298 - (rem -2 -5) -2 493.299 - 493.300 - ; num = 0, div != 0 493.301 - (rem 0 3) 0 493.302 - (rem 0 -3) 0 493.303 - ) 493.304 -) 493.305 - 493.306 -(deftest test-quot 493.307 - ; wrong number of args 493.308 - (is (thrown? IllegalArgumentException (quot))) 493.309 - (is (thrown? IllegalArgumentException (quot 1))) 493.310 - (is (thrown? IllegalArgumentException (quot 3 2 1))) 493.311 - 493.312 - ; divide by zero 493.313 - (is (thrown? ArithmeticException (quot 9 0))) 493.314 - (is (thrown? ArithmeticException (quot 0 0))) 493.315 - 493.316 - (are [x y] (= x y) 493.317 - (quot 4 2) 2 493.318 - (quot 3 2) 1 493.319 - (quot 6 4) 1 493.320 - (quot 0 5) 0 493.321 - 493.322 - (quot 2 1/2) 4 493.323 - (quot 2/3 1/2) 1 493.324 - (quot 1 2/3) 1 493.325 - 493.326 - (quot 4.0 2.0) 2.0 493.327 - (quot 4.5 2.0) 2.0 493.328 - 493.329 - ; |num| > |div|, num != k * div 493.330 - (quot 42 5) 8 ; (8 * 5) + 2 == 42 493.331 - (quot 42 -5) -8 ; (-8 * -5) + 2 == 42 493.332 - (quot -42 5) -8 ; (-8 * 5) + -2 == -42 493.333 - (quot -42 -5) 8 ; (8 * -5) + -2 == -42 493.334 - 493.335 - ; |num| > |div|, num = k * div 493.336 - (quot 9 3) 3 493.337 - (quot 9 -3) -3 493.338 - (quot -9 3) -3 493.339 - (quot -9 -3) 3 493.340 - 493.341 - ; |num| < |div| 493.342 - (quot 2 5) 0 493.343 - (quot 2 -5) 0 493.344 - (quot -2 5) 0 493.345 - (quot -2 -5) 0 493.346 - 493.347 - ; num = 0, div != 0 493.348 - (quot 0 3) 0 493.349 - (quot 0 -3) 0 493.350 - ) 493.351 -) 493.352 - 493.353 - 493.354 -;; *** Predicates *** 493.355 - 493.356 -;; pos? zero? neg? 493.357 - 493.358 -(deftest test-pos?-zero?-neg? 493.359 - (let [nums [[(byte 2) (byte 0) (byte -2)] 493.360 - [(short 3) (short 0) (short -3)] 493.361 - [(int 4) (int 0) (int -4)] 493.362 - [(long 5) (long 0) (long -5)] 493.363 - [(bigint 6) (bigint 0) (bigint -6)] 493.364 - [(float 7) (float 0) (float -7)] 493.365 - [(double 8) (double 0) (double -8)] 493.366 - [(bigdec 9) (bigdec 0) (bigdec -9)] 493.367 - [2/3 0 -2/3]] 493.368 - pred-result [[pos? [true false false]] 493.369 - [zero? [false true false]] 493.370 - [neg? [false false true]]] ] 493.371 - (doseq [pr pred-result] 493.372 - (doseq [n nums] 493.373 - (is (= (map (first pr) n) (second pr)) 493.374 - (pr-str (first pr) n)))))) 493.375 - 493.376 - 493.377 -;; even? odd? 493.378 - 493.379 -(deftest test-even? 493.380 - (are [x] (true? x) 493.381 - (even? -4) 493.382 - (not (even? -3)) 493.383 - (even? 0) 493.384 - (not (even? 5)) 493.385 - (even? 8)) 493.386 - (is (thrown? ArithmeticException (even? 1/2))) 493.387 - (is (thrown? ArithmeticException (even? (double 10))))) 493.388 - 493.389 -(deftest test-odd? 493.390 - (are [x] (true? x) 493.391 - (not (odd? -4)) 493.392 - (odd? -3) 493.393 - (not (odd? 0)) 493.394 - (odd? 5) 493.395 - (not (odd? 8))) 493.396 - (is (thrown? ArithmeticException (odd? 1/2))) 493.397 - (is (thrown? ArithmeticException (odd? (double 10))))) 493.398 - 493.399 -(defn- expt 493.400 - "clojure.contrib.math/expt is a better and much faster impl, but this works. 493.401 -Math/pow overflows to Infinity." 493.402 - [x n] (apply * (replicate n x))) 493.403 - 493.404 -(deftest test-bit-shift-left 493.405 - (are [x y] (= x y) 493.406 - 2r10 (bit-shift-left 2r1 1) 493.407 - 2r100 (bit-shift-left 2r1 2) 493.408 - 2r1000 (bit-shift-left 2r1 3) 493.409 - 2r00101110 (bit-shift-left 2r00010111 1) 493.410 - 2r00101110 (apply bit-shift-left [2r00010111 1]) 493.411 - 2r01 (bit-shift-left 2r10 -1) 493.412 - (expt 2 32) (bit-shift-left 1 32) 493.413 - (expt 2 10000) (bit-shift-left 1 10000) 493.414 - )) 493.415 - 493.416 -(deftest test-bit-shift-right 493.417 - (are [x y] (= x y) 493.418 - 2r0 (bit-shift-right 2r1 1) 493.419 - 2r010 (bit-shift-right 2r100 1) 493.420 - 2r001 (bit-shift-right 2r100 2) 493.421 - 2r000 (bit-shift-right 2r100 3) 493.422 - 2r0001011 (bit-shift-right 2r00010111 1) 493.423 - 2r0001011 (apply bit-shift-right [2r00010111 1]) 493.424 - 2r100 (bit-shift-right 2r10 -1) 493.425 - 1 (bit-shift-right (expt 2 32) 32) 493.426 - 1 (bit-shift-right (expt 2 10000) 10000) 493.427 - )) 493.428 - 493.429 - 493.430 -;; arrays 493.431 -(deftest test-array-types 493.432 - (are [x y z] (= (Class/forName x) (class y) (class z)) 493.433 - "[Z" (boolean-array 1) (booleans (boolean-array 1 true)) 493.434 - "[B" (byte-array 1) (bytes (byte-array 1 (byte 1))) 493.435 - "[C" (char-array 1) (chars (char-array 1 \a)) 493.436 - "[S" (short-array 1) (shorts (short-array 1 (short 1))) 493.437 - "[F" (float-array 1) (floats (float-array 1 1)) 493.438 - "[D" (double-array 1) (doubles (double-array 1 1)) 493.439 - "[I" (int-array 1) (ints (int-array 1 1)) 493.440 - "[J" (long-array 1) (longs (long-array 1 1)))) 493.441 - 493.442 - 493.443 -(deftest test-ratios 493.444 - (is (= (denominator 1/2) 2)) 493.445 - (is (= (numerator 1/2) 1)) 493.446 - (is (= (bigint (/ 100000000000000000000 3)) 33333333333333333333)) 493.447 - (is (= (long 10000000000000000000/3) 3333333333333333333)))
494.1 --- a/src/clojure/test_clojure/other_functions.clj Sat Aug 21 06:25:44 2010 -0400 494.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 494.3 @@ -1,86 +0,0 @@ 494.4 -; Copyright (c) Rich Hickey. All rights reserved. 494.5 -; The use and distribution terms for this software are covered by the 494.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 494.7 -; which can be found in the file epl-v10.html at the root of this distribution. 494.8 -; By using this software in any fashion, you are agreeing to be bound by 494.9 -; the terms of this license. 494.10 -; You must not remove this notice, or any other, from this software. 494.11 - 494.12 -; Author: Frantisek Sodomka 494.13 - 494.14 - 494.15 -(ns clojure.test-clojure.other-functions 494.16 - (:use clojure.test)) 494.17 - 494.18 -; http://clojure.org/other_functions 494.19 - 494.20 -; [= not= (tests in data_structures.clj and elsewhere)] 494.21 - 494.22 - 494.23 -(deftest test-identity 494.24 - ; exactly 1 argument needed 494.25 - (is (thrown? IllegalArgumentException (identity))) 494.26 - (is (thrown? IllegalArgumentException (identity 1 2))) 494.27 - 494.28 - (are [x] (= (identity x) x) 494.29 - nil 494.30 - false true 494.31 - 0 42 494.32 - 0.0 3.14 494.33 - 2/3 494.34 - 0M 1M 494.35 - \c 494.36 - "" "abc" 494.37 - 'sym 494.38 - :kw 494.39 - () '(1 2) 494.40 - [] [1 2] 494.41 - {} {:a 1 :b 2} 494.42 - #{} #{1 2} ) 494.43 - 494.44 - ; evaluation 494.45 - (are [x y] (= (identity x) y) 494.46 - (+ 1 2) 3 494.47 - (> 5 0) true )) 494.48 - 494.49 - 494.50 -(deftest test-name 494.51 - (are [x y] (= x (name y)) 494.52 - "foo" :foo 494.53 - "bar" 'bar 494.54 - "quux" "quux")) 494.55 - 494.56 -(deftest test-fnil 494.57 - (let [f1 (fnil vector :a) 494.58 - f2 (fnil vector :a :b) 494.59 - f3 (fnil vector :a :b :c)] 494.60 - (are [result input] (= result [(apply f1 input) (apply f2 input) (apply f3 input)]) 494.61 - [[1 2 3 4] [1 2 3 4] [1 2 3 4]] [1 2 3 4] 494.62 - [[:a 2 3 4] [:a 2 3 4] [:a 2 3 4]] [nil 2 3 4] 494.63 - [[:a nil 3 4] [:a :b 3 4] [:a :b 3 4]] [nil nil 3 4] 494.64 - [[:a nil nil 4] [:a :b nil 4] [:a :b :c 4]] [nil nil nil 4] 494.65 - [[:a nil nil nil] [:a :b nil nil] [:a :b :c nil]] [nil nil nil nil])) 494.66 - (are [x y] (= x y) 494.67 - ((fnil + 0) nil 42) 42 494.68 - ((fnil conj []) nil 42) [42] 494.69 - (reduce #(update-in %1 [%2] (fnil inc 0)) {} 494.70 - ["fun" "counting" "words" "fun"]) 494.71 - {"words" 1, "counting" 1, "fun" 2} 494.72 - (reduce #(update-in %1 [(first %2)] (fnil conj []) (second %2)) {} 494.73 - [[:a 1] [:a 2] [:b 3]]) 494.74 - {:b [3], :a [1 2]})) 494.75 - 494.76 -; time assert comment doc 494.77 - 494.78 -; partial 494.79 -; comp 494.80 -; complement 494.81 -; constantly 494.82 - 494.83 -; Printing 494.84 -; pr prn print println newline 494.85 -; pr-str prn-str print-str println-str [with-out-str (vars.clj)] 494.86 - 494.87 -; Regex Support 494.88 -; re-matcher re-find re-matches re-groups re-seq 494.89 -
495.1 --- a/src/clojure/test_clojure/parallel.clj Sat Aug 21 06:25:44 2010 -0400 495.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 495.3 @@ -1,29 +0,0 @@ 495.4 -; Copyright (c) Rich Hickey. All rights reserved. 495.5 -; The use and distribution terms for this software are covered by the 495.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 495.7 -; which can be found in the file epl-v10.html at the root of this distribution. 495.8 -; By using this software in any fashion, you are agreeing to be bound by 495.9 -; the terms of this license. 495.10 -; You must not remove this notice, or any other, from this software. 495.11 - 495.12 -; Author: Frantisek Sodomka 495.13 - 495.14 - 495.15 -(ns clojure.test-clojure.parallel 495.16 - (:use clojure.test)) 495.17 - 495.18 -;; !! Tests for the parallel library will be in a separate file clojure_parallel.clj !! 495.19 - 495.20 -; future-call 495.21 -; future 495.22 -; pmap 495.23 -; pcalls 495.24 -; pvalues 495.25 - 495.26 - 495.27 -;; pmap 495.28 -;; 495.29 -(deftest pmap-does-its-thing 495.30 - ;; regression fixed in r1218; was OutOfMemoryError 495.31 - (is (= '(1) (pmap inc [0])))) 495.32 -
496.1 --- a/src/clojure/test_clojure/pprint.clj Sat Aug 21 06:25:44 2010 -0400 496.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 496.3 @@ -1,18 +0,0 @@ 496.4 -; Copyright (c) Rich Hickey. All rights reserved. 496.5 -; The use and distribution terms for this software are covered by the 496.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 496.7 -; which can be found in the file epl-v10.html at the root of this distribution. 496.8 -; By using this software in any fashion, you are agreeing to be bound by 496.9 -; the terms of this license. 496.10 -; You must not remove this notice, or any other, from this software. 496.11 - 496.12 -;; Author: Tom Faulhaber 496.13 - 496.14 -(ns clojure.test-clojure.pprint 496.15 - (:refer-clojure :exclude [format]) 496.16 - (:use [clojure.test :only (deftest are run-tests)] 496.17 - clojure.test-clojure.pprint.test-helper 496.18 - clojure.pprint)) 496.19 - 496.20 -(load "pprint/test_cl_format") 496.21 -(load "pprint/test_pretty")
497.1 --- a/src/clojure/test_clojure/pprint/test_cl_format.clj Sat Aug 21 06:25:44 2010 -0400 497.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 497.3 @@ -1,688 +0,0 @@ 497.4 -;;; test_cl_format.clj -- part of the pretty printer for Clojure 497.5 - 497.6 -; Copyright (c) Rich Hickey. All rights reserved. 497.7 -; The use and distribution terms for this software are covered by the 497.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 497.9 -; which can be found in the file epl-v10.html at the root of this distribution. 497.10 -; By using this software in any fashion, you are agreeing to be bound by 497.11 -; the terms of this license. 497.12 -; You must not remove this notice, or any other, from this software. 497.13 - 497.14 -;; Author: Tom Faulhaber 497.15 -;; April 3, 2009 497.16 - 497.17 -;; This test set tests the basic cl-format functionality 497.18 - 497.19 - 497.20 -(in-ns 'clojure.test-clojure.pprint) 497.21 - 497.22 -(def format cl-format) 497.23 - 497.24 -;; TODO tests for ~A, ~D, etc. 497.25 -;; TODO add tests for ~F, etc.: 0.0, 9.9999 with rounding, 9.9999E99 with rounding 497.26 - 497.27 -(simple-tests d-tests 497.28 - (cl-format nil "~D" 0) "0" 497.29 - (cl-format nil "~D" 2e6) "2000000" 497.30 - (cl-format nil "~D" 2000000) "2000000" 497.31 - (cl-format nil "~:D" 2000000) "2,000,000" 497.32 - (cl-format nil "~D" 1/2) "1/2" 497.33 - (cl-format nil "~D" 'fred) "fred" 497.34 -) 497.35 - 497.36 -(simple-tests base-tests 497.37 - (cl-format nil "~{~2r~^ ~}~%" (range 10)) 497.38 - "0 1 10 11 100 101 110 111 1000 1001\n" 497.39 - (with-out-str 497.40 - (dotimes [i 35] 497.41 - (binding [*print-base* (+ i 2)] ;print the decimal number 40 497.42 - (write 40) ;in each base from 2 to 36 497.43 - (if (zero? (mod i 10)) (prn) (cl-format true " "))))) 497.44 - "101000 497.45 -1111 220 130 104 55 50 44 40 37 34 497.46 -31 2c 2a 28 26 24 22 20 1j 1i 497.47 -1h 1g 1f 1e 1d 1c 1b 1a 19 18 497.48 -17 16 15 14 " 497.49 - (with-out-str 497.50 - (doseq [pb [2 3 8 10 16]] 497.51 - (binding [*print-radix* true ;print the integer 10 and 497.52 - *print-base* pb] ;the ratio 1/10 in bases 2, 497.53 - (cl-format true "~&~S ~S~%" 10 1/10)))) ;3, 8, 10, 16 497.54 - "#b1010 #b1/1010 497.55 -#3r101 #3r1/101 497.56 -#o12 #o1/12 497.57 -10. #10r1/10 497.58 -#xa #x1/a 497.59 -") 497.60 - 497.61 - 497.62 - 497.63 -(simple-tests cardinal-tests 497.64 - (cl-format nil "~R" 0) "zero" 497.65 - (cl-format nil "~R" 4) "four" 497.66 - (cl-format nil "~R" 15) "fifteen" 497.67 - (cl-format nil "~R" -15) "minus fifteen" 497.68 - (cl-format nil "~R" 25) "twenty-five" 497.69 - (cl-format nil "~R" 20) "twenty" 497.70 - (cl-format nil "~R" 200) "two hundred" 497.71 - (cl-format nil "~R" 203) "two hundred three" 497.72 - 497.73 - (cl-format nil "~R" 44879032) 497.74 - "forty-four million, eight hundred seventy-nine thousand, thirty-two" 497.75 - 497.76 - (cl-format nil "~R" -44879032) 497.77 - "minus forty-four million, eight hundred seventy-nine thousand, thirty-two" 497.78 - 497.79 - (cl-format nil "~R = ~:*~:D" 44000032) 497.80 - "forty-four million, thirty-two = 44,000,032" 497.81 - 497.82 - (cl-format nil "~R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094) 497.83 - "four hundred forty-eight septendecillion, seven hundred ninety sexdecillion, three hundred twenty-nine quindecillion, four hundred eighty quattuordecillion, nine hundred forty-eight tredecillion, two hundred nine duodecillion, three hundred eighty-four undecillion, three hundred eighty-nine decillion, four hundred twenty-nine nonillion, three hundred eighty-four octillion, twenty-nine septillion, three hundred eighty-four sextillion, twenty-nine quintillion, eight hundred forty-two quadrillion, ninety-eight trillion, four hundred twenty billion, nine hundred eighty-nine million, eight hundred forty-two thousand, ninety-four = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094" 497.84 - 497.85 - (cl-format nil "~R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094490320942058747587584758375847593475) 497.86 - "448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475 = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475" 497.87 - 497.88 - (cl-format nil "~R = ~:*~:D" 2e6) 497.89 - "two million = 2,000,000" 497.90 - 497.91 - (cl-format nil "~R = ~:*~:D" 200000200000) 497.92 - "two hundred billion, two hundred thousand = 200,000,200,000") 497.93 - 497.94 -(simple-tests ordinal-tests 497.95 - (cl-format nil "~:R" 0) "zeroth" 497.96 - (cl-format nil "~:R" 4) "fourth" 497.97 - (cl-format nil "~:R" 15) "fifteenth" 497.98 - (cl-format nil "~:R" -15) "minus fifteenth" 497.99 - (cl-format nil "~:R" 25) "twenty-fifth" 497.100 - (cl-format nil "~:R" 20) "twentieth" 497.101 - (cl-format nil "~:R" 200) "two hundredth" 497.102 - (cl-format nil "~:R" 203) "two hundred third" 497.103 - 497.104 - (cl-format nil "~:R" 44879032) 497.105 - "forty-four million, eight hundred seventy-nine thousand, thirty-second" 497.106 - 497.107 - (cl-format nil "~:R" -44879032) 497.108 - "minus forty-four million, eight hundred seventy-nine thousand, thirty-second" 497.109 - 497.110 - (cl-format nil "~:R = ~:*~:D" 44000032) 497.111 - "forty-four million, thirty-second = 44,000,032" 497.112 - 497.113 - (cl-format nil "~:R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094) 497.114 - "four hundred forty-eight septendecillion, seven hundred ninety sexdecillion, three hundred twenty-nine quindecillion, four hundred eighty quattuordecillion, nine hundred forty-eight tredecillion, two hundred nine duodecillion, three hundred eighty-four undecillion, three hundred eighty-nine decillion, four hundred twenty-nine nonillion, three hundred eighty-four octillion, twenty-nine septillion, three hundred eighty-four sextillion, twenty-nine quintillion, eight hundred forty-two quadrillion, ninety-eight trillion, four hundred twenty billion, nine hundred eighty-nine million, eight hundred forty-two thousand, ninety-fourth = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094" 497.115 - (cl-format nil "~:R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094490320942058747587584758375847593475) 497.116 - "448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475th = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,475" 497.117 - (cl-format nil "~:R = ~:*~:D" 448790329480948209384389429384029384029842098420989842094490320942058747587584758375847593471) 497.118 - "448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,471st = 448,790,329,480,948,209,384,389,429,384,029,384,029,842,098,420,989,842,094,490,320,942,058,747,587,584,758,375,847,593,471" 497.119 - (cl-format nil "~:R = ~:*~:D" 2e6) 497.120 - "two millionth = 2,000,000") 497.121 - 497.122 -(simple-tests ordinal1-tests 497.123 - (cl-format nil "~:R" 1) "first" 497.124 - (cl-format nil "~:R" 11) "eleventh" 497.125 - (cl-format nil "~:R" 21) "twenty-first" 497.126 - (cl-format nil "~:R" 20) "twentieth" 497.127 - (cl-format nil "~:R" 220) "two hundred twentieth" 497.128 - (cl-format nil "~:R" 200) "two hundredth" 497.129 - (cl-format nil "~:R" 999) "nine hundred ninety-ninth" 497.130 - ) 497.131 - 497.132 -(simple-tests roman-tests 497.133 - (cl-format nil "~@R" 3) "III" 497.134 - (cl-format nil "~@R" 4) "IV" 497.135 - (cl-format nil "~@R" 9) "IX" 497.136 - (cl-format nil "~@R" 29) "XXIX" 497.137 - (cl-format nil "~@R" 429) "CDXXIX" 497.138 - (cl-format nil "~@:R" 429) "CCCCXXVIIII" 497.139 - (cl-format nil "~@:R" 3429) "MMMCCCCXXVIIII" 497.140 - (cl-format nil "~@R" 3429) "MMMCDXXIX" 497.141 - (cl-format nil "~@R" 3479) "MMMCDLXXIX" 497.142 - (cl-format nil "~@R" 3409) "MMMCDIX" 497.143 - (cl-format nil "~@R" 300) "CCC" 497.144 - (cl-format nil "~@R ~D" 300 20) "CCC 20" 497.145 - (cl-format nil "~@R" 5000) "5,000" 497.146 - (cl-format nil "~@R ~D" 5000 20) "5,000 20" 497.147 - (cl-format nil "~@R" "the quick") "the quick") 497.148 - 497.149 -(simple-tests c-tests 497.150 - (cl-format nil "~{~c~^, ~}~%" "hello") "h, e, l, l, o\n" 497.151 - (cl-format nil "~{~:c~^, ~}~%" "hello") "h, e, l, l, o\n" 497.152 - (cl-format nil "~@C~%" \m) "\\m\n" 497.153 - (cl-format nil "~@C~%" (char 222)) "\\Þ\n" 497.154 - (cl-format nil "~@C~%" (char 8)) "\\backspace\n" 497.155 - (cl-format nil "~@C~%" (char 3)) "\\\n") 497.156 - 497.157 -(simple-tests e-tests 497.158 - (cl-format nil "*~E*" 0.0) "*0.0E+0*" 497.159 - (cl-format nil "*~6E*" 0.0) "*0.0E+0*" 497.160 - (cl-format nil "*~6,0E*" 0.0) "* 0.E+0*" 497.161 - (cl-format nil "*~7,2E*" 0.0) "*0.00E+0*" 497.162 - (cl-format nil "*~5E*" 0.0) "*0.E+0*" 497.163 - (cl-format nil "*~10,2,2,,'?E*" 2.8E120) "*??????????*" 497.164 - (cl-format nil "*~10,2E*" 9.99999) "* 1.00E+1*" 497.165 - (cl-format nil "*~10,2E*" 9.99999E99) "* 1.00E+100*" 497.166 - (cl-format nil "*~10,2,2E*" 9.99999E99) "* 1.00E+100*" 497.167 - (cl-format nil "*~10,2,2,,'?E*" 9.99999E99) "*??????????*" 497.168 - ) 497.169 - 497.170 -(simple-tests $-tests 497.171 - (cl-format nil "~$" 22.3) "22.30" 497.172 - (cl-format nil "~$" 22.375) "22.38" 497.173 - (cl-format nil "~3,5$" 22.375) "00022.375" 497.174 - (cl-format nil "~3,5,8$" 22.375) "00022.375" 497.175 - (cl-format nil "~3,5,10$" 22.375) " 00022.375" 497.176 - (cl-format nil "~3,5,14@$" 22.375) " +00022.375" 497.177 - (cl-format nil "~3,5,14@$" 22.375) " +00022.375" 497.178 - (cl-format nil "~3,5,14@:$" 22.375) "+ 00022.375" 497.179 - (cl-format nil "~3,,14@:$" 0.375) "+ 0.375" 497.180 - (cl-format nil "~1,1$" -12.0) "-12.0" 497.181 - (cl-format nil "~1,1$" 12.0) "12.0" 497.182 - (cl-format nil "~1,1$" 12.0) "12.0" 497.183 - (cl-format nil "~1,1@$" 12.0) "+12.0" 497.184 - (cl-format nil "~1,1,8,' @:$" 12.0) "+ 12.0" 497.185 - (cl-format nil "~1,1,8,' @$" 12.0) " +12.0" 497.186 - (cl-format nil "~1,1,8,' :$" 12.0) " 12.0" 497.187 - (cl-format nil "~1,1,8,' $" 12.0) " 12.0" 497.188 - (cl-format nil "~1,1,8,' @:$" -12.0) "- 12.0" 497.189 - (cl-format nil "~1,1,8,' @$" -12.0) " -12.0" 497.190 - (cl-format nil "~1,1,8,' :$" -12.0) "- 12.0" 497.191 - (cl-format nil "~1,1,8,' $" -12.0) " -12.0" 497.192 - (cl-format nil "~1,1$" 0.001) "0.0" 497.193 - (cl-format nil "~2,1$" 0.001) "0.00" 497.194 - (cl-format nil "~1,1,6$" 0.001) " 0.0" 497.195 - (cl-format nil "~1,1,6$" 0.0015) " 0.0" 497.196 - (cl-format nil "~2,1,6$" 0.005) " 0.01" 497.197 - (cl-format nil "~2,1,6$" 0.01) " 0.01" 497.198 - (cl-format nil "~$" 0.099) "0.10" 497.199 - (cl-format nil "~1$" 0.099) "0.1" 497.200 - (cl-format nil "~1$" 0.1) "0.1" 497.201 - (cl-format nil "~1$" 0.99) "1.0" 497.202 - (cl-format nil "~1$" -0.99) "-1.0") 497.203 - 497.204 -(simple-tests f-tests 497.205 - (cl-format nil "~,1f" -12.0) "-12.0" 497.206 - (cl-format nil "~,0f" 9.4) "9." 497.207 - (cl-format nil "~,0f" 9.5) "10." 497.208 - (cl-format nil "~,0f" -0.99) "-1." 497.209 - (cl-format nil "~,1f" -0.99) "-1.0" 497.210 - (cl-format nil "~,2f" -0.99) "-0.99" 497.211 - (cl-format nil "~,3f" -0.99) "-0.990" 497.212 - (cl-format nil "~,0f" 0.99) "1." 497.213 - (cl-format nil "~,1f" 0.99) "1.0" 497.214 - (cl-format nil "~,2f" 0.99) "0.99" 497.215 - (cl-format nil "~,3f" 0.99) "0.990" 497.216 - (cl-format nil "~f" -1) "-1.0" 497.217 - (cl-format nil "~2f" -1) "-1." 497.218 - (cl-format nil "~3f" -1) "-1." 497.219 - (cl-format nil "~4f" -1) "-1.0" 497.220 - (cl-format nil "~8f" -1) " -1.0" 497.221 - (cl-format nil "~1,1f" 0.1) ".1") 497.222 - 497.223 -(simple-tests ampersand-tests 497.224 - (cl-format nil "The quick brown ~a jumped over ~d lazy dogs" 'elephant 5) 497.225 - "The quick brown elephant jumped over 5 lazy dogs" 497.226 - (cl-format nil "The quick brown ~&~a jumped over ~d lazy dogs" 'elephant 5) 497.227 - "The quick brown \nelephant jumped over 5 lazy dogs" 497.228 - (cl-format nil "The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5) 497.229 - "The quick brown \nelephant jumped\n over 5 lazy dogs" 497.230 - (cl-format nil "~&The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5) 497.231 - "The quick brown \nelephant jumped\n over 5 lazy dogs" 497.232 - (cl-format nil "~3&The quick brown ~&~a jumped\n~& over ~d lazy dogs" 'elephant 5) 497.233 - "\n\nThe quick brown \nelephant jumped\n over 5 lazy dogs" 497.234 - (cl-format nil "~@{~&The quick brown ~a jumped over ~d lazy dogs~}" 'elephant 5 'fox 10) 497.235 - "The quick brown elephant jumped over 5 lazy dogs\nThe quick brown fox jumped over 10 lazy dogs" 497.236 - (cl-format nil "I ~[don't ~:;d~&o ~]have one~%" 0) "I don't have one\n" 497.237 - (cl-format nil "I ~[don't ~:;d~&o ~]have one~%" 1) "I d\no have one\n") 497.238 - 497.239 -(simple-tests t-tests 497.240 - (cl-format nil "~@{~&~A~8,4T~:*~A~}" 497.241 - 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa) 497.242 - "a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa" 497.243 - (cl-format nil "~@{~&~A~,4T~:*~A~}" 497.244 - 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa) 497.245 - "a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa" 497.246 - (cl-format nil "~@{~&~A~2,6@T~:*~A~}" 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa) 497.247 - "a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa" 497.248 -) 497.249 - 497.250 -(simple-tests paren-tests 497.251 - (cl-format nil "~(PLEASE SPEAK QUIETLY IN HERE~)") "please speak quietly in here" 497.252 - (cl-format nil "~@(PLEASE SPEAK QUIETLY IN HERE~)") "Please speak quietly in here" 497.253 - (cl-format nil "~@:(but this Is imporTant~)") "BUT THIS IS IMPORTANT" 497.254 - (cl-format nil "~:(the greAt gatsby~)!") "The Great Gatsby!" 497.255 - ;; Test cases from CLtL 18.3 - string-upcase, et al. 497.256 - (cl-format nil "~@:(~A~)" "Dr. Livingstone, I presume?") "DR. LIVINGSTONE, I PRESUME?" 497.257 - (cl-format nil "~(~A~)" "Dr. Livingstone, I presume?") "dr. livingstone, i presume?" 497.258 - (cl-format nil "~:(~A~)" " hello ") " Hello " 497.259 - (cl-format nil "~:(~A~)" "occlUDeD cASEmenTs FOreSTAll iNADVertent DEFenestraTION") 497.260 - "Occluded Casements Forestall Inadvertent Defenestration" 497.261 - (cl-format nil "~:(~A~)" 'kludgy-hash-search) "Kludgy-Hash-Search" 497.262 - (cl-format nil "~:(~A~)" "DON'T!") "Don'T!" ;not "Don't!" 497.263 - (cl-format nil "~:(~A~)" "pipe 13a, foo16c") "Pipe 13a, Foo16c" 497.264 -) 497.265 - 497.266 -(simple-tests square-bracket-tests 497.267 - ;; Tests for format without modifiers 497.268 - (cl-format nil "I ~[don't ~]have one~%" 0) "I don't have one\n" 497.269 - (cl-format nil "I ~[don't ~]have one~%" 1) "I have one\n" 497.270 - (cl-format nil "I ~[don't ~;do ~]have one~%" 0) "I don't have one\n" 497.271 - (cl-format nil "I ~[don't ~;do ~]have one~%" 1) "I do have one\n" 497.272 - (cl-format nil "I ~[don't ~;do ~]have one~%" 2) "I have one\n" 497.273 - (cl-format nil "I ~[don't ~:;do ~]have one~%" 0) "I don't have one\n" 497.274 - (cl-format nil "I ~[don't ~:;do ~]have one~%" 1) "I do have one\n" 497.275 - (cl-format nil "I ~[don't ~:;do ~]have one~%" 2) "I do have one\n" 497.276 - (cl-format nil "I ~[don't ~:;do ~]have one~%" 700) "I do have one\n" 497.277 - 497.278 - ;; Tests for format with a colon 497.279 - (cl-format nil "I ~:[don't ~;do ~]have one~%" true) "I do have one\n" 497.280 - (cl-format nil "I ~:[don't ~;do ~]have one~%" 700) "I do have one\n" 497.281 - (cl-format nil "I ~:[don't ~;do ~]have one~%" '(a b)) "I do have one\n" 497.282 - (cl-format nil "I ~:[don't ~;do ~]have one~%" nil) "I don't have one\n" 497.283 - (cl-format nil "I ~:[don't ~;do ~]have one~%" false) "I don't have one\n" 497.284 - 497.285 - ;; Tests for format with an at sign 497.286 - (cl-format nil "We had ~D wins~@[ (out of ~D tries)~].~%" 15 nil) "We had 15 wins.\n" 497.287 - (cl-format nil "We had ~D wins~@[ (out of ~D tries)~].~%" 15 17) 497.288 - "We had 15 wins (out of 17 tries).\n" 497.289 - 497.290 - ;; Format tests with directives 497.291 - (cl-format nil "Max ~D: ~[Blue team ~D~;Red team ~D~:;No team ~A~].~%" 15, 0, 7) 497.292 - "Max 15: Blue team 7.\n" 497.293 - (cl-format nil "Max ~D: ~[Blue team ~D~;Red team ~D~:;No team ~A~].~%" 15, 1, 12) 497.294 - "Max 15: Red team 12.\n" 497.295 - (cl-format nil "Max ~D: ~[Blue team ~D~;Red team ~D~:;No team ~A~].~%" 497.296 - 15, -1, "(system failure)") 497.297 - "Max 15: No team (system failure).\n" 497.298 - 497.299 - ;; Nested format tests 497.300 - (cl-format nil "Max ~D: ~[Blue team ~D~:[~; (complete success)~]~;Red team ~D~:;No team ~].~%" 497.301 - 15, 0, 7, true) 497.302 - "Max 15: Blue team 7 (complete success).\n" 497.303 - (cl-format nil "Max ~D: ~[Blue team ~D~:[~; (complete success)~]~;Red team ~D~:;No team ~].~%" 497.304 - 15, 0, 7, false) 497.305 - "Max 15: Blue team 7.\n" 497.306 - 497.307 - ;; Test the selector as part of the argument 497.308 - (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~].") 497.309 - "The answer is nothing." 497.310 - (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 4) 497.311 - "The answer is 4." 497.312 - (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 7 22) 497.313 - "The answer is 7 out of 22." 497.314 - (cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 1 2 3 4) 497.315 - "The answer is something crazy." 497.316 -) 497.317 - 497.318 -(simple-tests curly-brace-plain-tests 497.319 - ;; Iteration from sublist 497.320 - (cl-format nil "Coordinates are~{ [~D,~D]~}~%" [ 0, 1, 1, 0, 3, 5, 2, 1 ]) 497.321 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 497.322 - 497.323 - (cl-format nil "Coordinates are~2{ [~D,~D]~}~%" [ 0, 1, 1, 0, 3, 5, 2, 1 ]) 497.324 - "Coordinates are [0,1] [1,0]\n" 497.325 - 497.326 - (cl-format nil "Coordinates are~{ ~#[none~;<~D>~:;[~D,~D]~]~}~%" [ ]) 497.327 - "Coordinates are\n" 497.328 - 497.329 - (cl-format nil "Coordinates are~{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [ ]) 497.330 - "Coordinates are none\n" 497.331 - 497.332 - (cl-format nil "Coordinates are~{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [2 3 1]) 497.333 - "Coordinates are [2,3] <1>\n" 497.334 - 497.335 - (cl-format nil "Coordinates are~{~:}~%" "" []) 497.336 - "Coordinates are\n" 497.337 - 497.338 - (cl-format nil "Coordinates are~{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [2 3 1]) 497.339 - "Coordinates are [2,3] <1>\n" 497.340 - 497.341 - (cl-format nil "Coordinates are~{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [ ]) 497.342 - "Coordinates are none\n" 497.343 -) 497.344 - 497.345 - 497.346 -(simple-tests curly-brace-colon-tests 497.347 - ;; Iteration from list of sublists 497.348 - (cl-format nil "Coordinates are~:{ [~D,~D]~}~%" [ [0, 1], [1, 0], [3, 5], [2, 1] ]) 497.349 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 497.350 - 497.351 - (cl-format nil "Coordinates are~:{ [~D,~D]~}~%" [ [0, 1, 0], [1, 0, 12], [3, 5], [2, 1] ]) 497.352 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 497.353 - 497.354 - (cl-format nil "Coordinates are~2:{ [~D,~D]~}~%" [ [0, 1], [1, 0], [3, 5], [2, 1] ]) 497.355 - "Coordinates are [0,1] [1,0]\n" 497.356 - 497.357 - (cl-format nil "Coordinates are~:{ ~#[none~;<~D>~:;[~D,~D]~]~}~%" [ ]) 497.358 - "Coordinates are\n" 497.359 - 497.360 - (cl-format nil "Coordinates are~:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [ ]) 497.361 - "Coordinates are none\n" 497.362 - 497.363 - (cl-format nil "Coordinates are~:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [[2 3] [1]]) 497.364 - "Coordinates are [2,3] <1>\n" 497.365 - 497.366 - (cl-format nil "Coordinates are~:{~:}~%" "" []) 497.367 - "Coordinates are\n" 497.368 - 497.369 - (cl-format nil "Coordinates are~:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [[2 3] [1]]) 497.370 - "Coordinates are [2,3] <1>\n" 497.371 - 497.372 - (cl-format nil "Coordinates are~:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [ ]) 497.373 - "Coordinates are none\n" 497.374 -) 497.375 - 497.376 -(simple-tests curly-brace-at-tests 497.377 - ;; Iteration from main list 497.378 - (cl-format nil "Coordinates are~@{ [~D,~D]~}~%" 0, 1, 1, 0, 3, 5, 2, 1) 497.379 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 497.380 - 497.381 - (cl-format nil "Coordinates are~2@{ [~D,~D]~}~%" 0, 1, 1, 0, 3, 5, 2, 1) 497.382 - "Coordinates are [0,1] [1,0]\n" 497.383 - 497.384 - (cl-format nil "Coordinates are~@{ ~#[none~;<~D>~:;[~D,~D]~]~}~%") 497.385 - "Coordinates are\n" 497.386 - 497.387 - (cl-format nil "Coordinates are~@{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%") 497.388 - "Coordinates are none\n" 497.389 - 497.390 - (cl-format nil "Coordinates are~@{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" 2 3 1) 497.391 - "Coordinates are [2,3] <1>\n" 497.392 - 497.393 - (cl-format nil "Coordinates are~@{~:}~%" "") 497.394 - "Coordinates are\n" 497.395 - 497.396 - (cl-format nil "Coordinates are~@{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" 2 3 1) 497.397 - "Coordinates are [2,3] <1>\n" 497.398 - 497.399 - (cl-format nil "Coordinates are~@{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]") 497.400 - "Coordinates are none\n" 497.401 -) 497.402 - 497.403 -(simple-tests curly-brace-colon-at-tests 497.404 - ;; Iteration from sublists on the main arg list 497.405 - (cl-format nil "Coordinates are~@:{ [~D,~D]~}~%" [0, 1], [1, 0], [3, 5], [2, 1] ) 497.406 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 497.407 - 497.408 - (cl-format nil "Coordinates are~@:{ [~D,~D]~}~%" [0, 1, 0], [1, 0, 12], [3, 5], [2, 1] ) 497.409 - "Coordinates are [0,1] [1,0] [3,5] [2,1]\n" 497.410 - 497.411 - (cl-format nil "Coordinates are~2@:{ [~D,~D]~}~%" [0, 1], [1, 0], [3, 5], [2, 1]) 497.412 - "Coordinates are [0,1] [1,0]\n" 497.413 - 497.414 - (cl-format nil "Coordinates are~@:{ ~#[none~;<~D>~:;[~D,~D]~]~}~%") 497.415 - "Coordinates are\n" 497.416 - 497.417 - (cl-format nil "Coordinates are~@:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%") 497.418 - "Coordinates are none\n" 497.419 - 497.420 - (cl-format nil "Coordinates are~@:{ ~#[none~;<~D>~:;[~D,~D]~]~:}~%" [2 3] [1]) 497.421 - "Coordinates are [2,3] <1>\n" 497.422 - 497.423 - (cl-format nil "Coordinates are~@:{~:}~%" "") 497.424 - "Coordinates are\n" 497.425 - 497.426 - (cl-format nil "Coordinates are~@:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [2 3] [1]) 497.427 - "Coordinates are [2,3] <1>\n" 497.428 - 497.429 - (cl-format nil "Coordinates are~@:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]") 497.430 - "Coordinates are none\n" 497.431 -) 497.432 - 497.433 -;; TODO tests for ~^ in ~[ constructs and other brackets 497.434 -;; TODO test ~:^ generates an error when used improperly 497.435 -;; TODO test ~:^ works in ~@:{...~} 497.436 -(let [aseq '(a quick brown fox jumped over the lazy dog) 497.437 - lseq (mapcat identity (for [x aseq] [x (.length (name x))]))] 497.438 - (simple-tests up-tests 497.439 - (cl-format nil "~{~a~^, ~}" aseq) "a, quick, brown, fox, jumped, over, the, lazy, dog" 497.440 - (cl-format nil "~{~a~0^, ~}" aseq) "a" 497.441 - (cl-format nil "~{~a~#,3^, ~}" aseq) "a, quick, brown, fox, jumped, over" 497.442 - (cl-format nil "~{~a~v,3^, ~}" lseq) "a, quick, brown, fox" 497.443 - (cl-format nil "~{~a~3,v,4^, ~}" lseq) "a, quick, brown, fox" 497.444 -)) 497.445 - 497.446 -(simple-tests angle-bracket-tests 497.447 - (cl-format nil "~<foo~;bar~;baz~>") "foobarbaz" 497.448 - (cl-format nil "~20<foo~;bar~;baz~>") "foo bar baz" 497.449 - (cl-format nil "~,,2<foo~;bar~;baz~>") "foo bar baz" 497.450 - (cl-format nil "~20<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz" 497.451 - (cl-format nil "~20:<~A~;~A~;~A~>" "foo" "bar" "baz") " foo bar baz" 497.452 - (cl-format nil "~20@<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz " 497.453 - (cl-format nil "~20@:<~A~;~A~;~A~>" "foo" "bar" "baz") " foo bar baz " 497.454 - (cl-format nil "~10,,2<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz" 497.455 - (cl-format nil "~10,10,2<~A~;~A~;~A~>" "foo" "bar" "baz") "foo bar baz" 497.456 - (cl-format nil "~10,10<~A~;~A~;~A~>" "foo" "bar" "baz") "foo barbaz" 497.457 - (cl-format nil "~20<~A~;~^~A~;~^~A~>" "foo" "bar" "baz") "foo bar baz" 497.458 - (cl-format nil "~20<~A~;~^~A~;~^~A~>" "foo" "bar") "foo bar" 497.459 - (cl-format nil "~20@<~A~;~^~A~;~^~A~>" "foo") "foo " 497.460 - (cl-format nil "~20:<~A~;~^~A~;~^~A~>" "foo") " foo" 497.461 -) 497.462 - 497.463 -(simple-tests angle-bracket-max-column-tests 497.464 - (cl-format nil "~%;; ~{~<~%;; ~1,50:; ~A~>~}.~%" (into [] (.split "This function computes the circular thermodynamic coefficient of the thrombulator angle for use in determining the reaction distance" "\\s"))) 497.465 - "\n;; This function computes the circular\n;; thermodynamic coefficient of the thrombulator\n;; angle for use in determining the reaction\n;; distance.\n" 497.466 -(cl-format true "~%;; ~{~<~%;; ~:; ~A~>~}.~%" (into [] (.split "This function computes the circular thermodynamic coefficient of the thrombulator angle for use in determining the reaction distance." "\\s")))) 497.467 - 497.468 -(defn list-to-table [aseq column-width] 497.469 - (let [stream (get-pretty-writer (java.io.StringWriter.))] 497.470 - (binding [*out* stream] 497.471 - (doseq [row aseq] 497.472 - (doseq [col row] 497.473 - (cl-format true "~4D~7,vT" col column-width)) 497.474 - (prn))) 497.475 - (.flush stream) 497.476 - (.toString (:base @@(:base @@stream))))) 497.477 - 497.478 -(simple-tests column-writer-test 497.479 - (list-to-table (map #(vector % (* % %) (* % % %)) (range 1 21)) 8) 497.480 - " 1 1 1 \n 2 4 8 \n 3 9 27 \n 4 16 64 \n 5 25 125 \n 6 36 216 \n 7 49 343 \n 8 64 512 \n 9 81 729 \n 10 100 1000 \n 11 121 1331 \n 12 144 1728 \n 13 169 2197 \n 14 196 2744 \n 15 225 3375 \n 16 256 4096 \n 17 289 4913 \n 18 324 5832 \n 19 361 6859 \n 20 400 8000 \n") 497.481 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 497.482 -;; The following tests are the various examples from the format 497.483 -;; documentation in Common Lisp, the Language, 2nd edition, Chapter 22.3 497.484 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 497.485 - 497.486 -(defn expt [base pow] (reduce * (repeat pow base))) 497.487 - 497.488 -(let [x 5, y "elephant", n 3] 497.489 - (simple-tests cltl-intro-tests 497.490 - (format nil "foo") "foo" 497.491 - (format nil "The answer is ~D." x) "The answer is 5." 497.492 - (format nil "The answer is ~3D." x) "The answer is 5." 497.493 - (format nil "The answer is ~3,'0D." x) "The answer is 005." 497.494 - (format nil "The answer is ~:D." (expt 47 x)) "The answer is 229,345,007." 497.495 - (format nil "Look at the ~A!" y) "Look at the elephant!" 497.496 - (format nil "Type ~:C to ~A." (char 4) "delete all your files") 497.497 - "Type Control-D to delete all your files." 497.498 - (format nil "~D item~:P found." n) "3 items found." 497.499 - (format nil "~R dog~:[s are~; is~] here." n (= n 1)) "three dogs are here." 497.500 - (format nil "~R dog~:*~[s are~; is~:;s are~] here." n) "three dogs are here." 497.501 - (format nil "Here ~[are~;is~:;are~] ~:*~R pupp~:@P." n) "Here are three puppies.")) 497.502 - 497.503 -(simple-tests cltl-B-tests 497.504 - ;; CLtL didn't have the colons here, but the spec requires them 497.505 - (format nil "~,,' ,4:B" 0xFACE) "1111 1010 1100 1110" 497.506 - (format nil "~,,' ,4:B" 0x1CE) "1 1100 1110" 497.507 - (format nil "~19,,' ,4:B" 0xFACE) "1111 1010 1100 1110" 497.508 - ;; This one was a nice idea, but nothing in the spec supports it working this way 497.509 - ;; (and SBCL doesn't work this way either) 497.510 - ;(format nil "~19,,' ,4:B" 0x1CE) "0000 0001 1100 1110") 497.511 - ) 497.512 - 497.513 -(simple-tests cltl-P-tests 497.514 - (format nil "~D tr~:@P/~D win~:P" 7 1) "7 tries/1 win" 497.515 - (format nil "~D tr~:@P/~D win~:P" 1 0) "1 try/0 wins" 497.516 - (format nil "~D tr~:@P/~D win~:P" 1 3) "1 try/3 wins") 497.517 - 497.518 -(defn foo [x] 497.519 - (format nil "~6,2F|~6,2,1,'*F|~6,2,,'?F|~6F|~,2F|~F" 497.520 - x x x x x x)) 497.521 - 497.522 -(simple-tests cltl-F-tests 497.523 - (foo 3.14159) " 3.14| 31.42| 3.14|3.1416|3.14|3.14159" 497.524 - (foo -3.14159) " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159" 497.525 - (foo 100.0) "100.00|******|100.00| 100.0|100.00|100.0" 497.526 - (foo 1234.0) "1234.00|******|??????|1234.0|1234.00|1234.0" 497.527 - (foo 0.006) " 0.01| 0.06| 0.01| 0.006|0.01|0.006") 497.528 - 497.529 -(defn foo-e [x] 497.530 - (format nil 497.531 - "~9,2,1,,'*E|~10,3,2,2,'?,,'$E|~9,3,2,-2,'%@E|~9,2E" 497.532 - x x x x)) 497.533 - 497.534 -;; Clojure doesn't support float/double differences in representation 497.535 -(simple-tests cltl-E-tests 497.536 - (foo-e 0.0314159) " 3.14E-2| 31.42$-03|+.003E+01| 3.14E-2" ; Added this one 497.537 - (foo-e 3.14159) " 3.14E+0| 31.42$-01|+.003E+03| 3.14E+0" 497.538 - (foo-e -3.14159) " -3.14E+0|-31.42$-01|-.003E+03| -3.14E+0" 497.539 - (foo-e 1100.0) " 1.10E+3| 11.00$+02|+.001E+06| 1.10E+3" 497.540 -; In Clojure, this is identical to the above 497.541 -; (foo-e 1100.0L0) " 1.10L+3| 11.00$+02|+.001L+06| 1.10L+3" 497.542 - (foo-e 1.1E13) "*********| 11.00$+12|+.001E+16| 1.10E+13" 497.543 - (foo-e 1.1E120) "*********|??????????|%%%%%%%%%|1.10E+120" 497.544 -; Clojure doesn't support real numbers this large 497.545 -; (foo-e 1.1L1200) "*********|??????????|%%%%%%%%%|1.10L+1200" 497.546 -) 497.547 - 497.548 -(simple-tests cltl-E-scale-tests 497.549 - (map 497.550 - (fn [k] (format nil "Scale factor ~2D~:*: |~13,6,2,VE|" 497.551 - (- k 5) 3.14159)) ;Prints 13 lines 497.552 - (range 13)) 497.553 - '("Scale factor -5: | 0.000003E+06|" 497.554 - "Scale factor -4: | 0.000031E+05|" 497.555 - "Scale factor -3: | 0.000314E+04|" 497.556 - "Scale factor -2: | 0.003142E+03|" 497.557 - "Scale factor -1: | 0.031416E+02|" 497.558 - "Scale factor 0: | 0.314159E+01|" 497.559 - "Scale factor 1: | 3.141590E+00|" 497.560 - "Scale factor 2: | 31.41590E-01|" 497.561 - "Scale factor 3: | 314.1590E-02|" 497.562 - "Scale factor 4: | 3141.590E-03|" 497.563 - "Scale factor 5: | 31415.90E-04|" 497.564 - "Scale factor 6: | 314159.0E-05|" 497.565 - "Scale factor 7: | 3141590.E-06|")) 497.566 - 497.567 -(defn foo-g [x] 497.568 - (format nil 497.569 - "~9,2,1,,'*G|~9,3,2,3,'?,,'$G|~9,3,2,0,'%G|~9,2G" 497.570 - x x x x)) 497.571 - 497.572 -;; Clojure doesn't support float/double differences in representation 497.573 -(simple-tests cltl-G-tests 497.574 - (foo-g 0.0314159) " 3.14E-2|314.2$-04|0.314E-01| 3.14E-2" 497.575 - (foo-g 0.314159) " 0.31 |0.314 |0.314 | 0.31 " 497.576 - (foo-g 3.14159) " 3.1 | 3.14 | 3.14 | 3.1 " 497.577 - (foo-g 31.4159) " 31. | 31.4 | 31.4 | 31. " 497.578 - (foo-g 314.159) " 3.14E+2| 314. | 314. | 3.14E+2" 497.579 - (foo-g 3141.59) " 3.14E+3|314.2$+01|0.314E+04| 3.14E+3" 497.580 -; In Clojure, this is identical to the above 497.581 -; (foo-g 3141.59L0) " 3.14L+3|314.2$+01|0.314L+04| 3.14L+3" 497.582 - (foo-g 3.14E12) "*********|314.0$+10|0.314E+13| 3.14E+12" 497.583 - (foo-g 3.14E120) "*********|?????????|%%%%%%%%%|3.14E+120" 497.584 -; Clojure doesn't support real numbers this large 497.585 -; (foo-g 3.14L1200) "*********|?????????|%%%%%%%%%|3.14L+1200" 497.586 -) 497.587 - 497.588 -(defn type-clash-error [fun nargs argnum right-type wrong-type] 497.589 - (format nil ;; CLtL has this format string slightly wrong 497.590 - "~&Function ~S requires its ~:[~:R ~;~*~]~ 497.591 - argument to be of type ~S,~%but it was called ~ 497.592 - with an argument of type ~S.~%" 497.593 - fun (= nargs 1) argnum right-type wrong-type)) 497.594 - 497.595 -(simple-tests cltl-Newline-tests 497.596 - (type-clash-error 'aref nil 2 'integer 'vector) 497.597 -"Function aref requires its second argument to be of type integer, 497.598 -but it was called with an argument of type vector.\n" 497.599 - (type-clash-error 'car 1 1 'list 'short-float) 497.600 -"Function car requires its argument to be of type list, 497.601 -but it was called with an argument of type short-float.\n") 497.602 - 497.603 -(simple-tests cltl-?-tests 497.604 - (format nil "~? ~D" "<~A ~D>" '("Foo" 5) 7) "<Foo 5> 7" 497.605 - (format nil "~? ~D" "<~A ~D>" '("Foo" 5 14) 7) "<Foo 5> 7" 497.606 - (format nil "~@? ~D" "<~A ~D>" "Foo" 5 7) "<Foo 5> 7" 497.607 - (format nil "~@? ~D" "<~A ~D>" "Foo" 5 14 7) "<Foo 5> 14") 497.608 - 497.609 -(defn f [n] (format nil "~@(~R~) error~:P detected." n)) 497.610 - 497.611 -(simple-tests cltl-paren-tests 497.612 - (format nil "~@R ~(~@R~)" 14 14) "XIV xiv" 497.613 - (f 0) "Zero errors detected." 497.614 - (f 1) "One error detected." 497.615 - (f 23) "Twenty-three errors detected.") 497.616 - 497.617 -(let [*print-level* nil *print-length* 5] 497.618 - (simple-tests cltl-bracket-tests 497.619 - (format nil "~@[ print level = ~D~]~@[ print length = ~D~]" 497.620 - *print-level* *print-length*) 497.621 - " print length = 5")) 497.622 - 497.623 -(let [foo "Items:~#[ none~; ~S~; ~S and ~S~ 497.624 - ~:;~@{~#[~; and~] ~ 497.625 - ~S~^,~}~]."] 497.626 - (simple-tests cltl-bracket1-tests 497.627 - (format nil foo) "Items: none." 497.628 - (format nil foo 'foo) "Items: foo." 497.629 - (format nil foo 'foo 'bar) "Items: foo and bar." 497.630 - (format nil foo 'foo 'bar 'baz) "Items: foo, bar, and baz." 497.631 - (format nil foo 'foo 'bar 'baz 'quux) "Items: foo, bar, baz, and quux.")) 497.632 - 497.633 -(simple-tests cltl-curly-bracket-tests 497.634 - (format nil 497.635 - "The winners are:~{ ~S~}." 497.636 - '(fred harry jill)) 497.637 - "The winners are: fred harry jill." 497.638 - 497.639 - (format nil "Pairs:~{ <~S,~S>~}." '(a 1 b 2 c 3)) 497.640 - "Pairs: <a,1> <b,2> <c,3>." 497.641 - 497.642 - (format nil "Pairs:~:{ <~S,~S>~}." '((a 1) (b 2) (c 3))) 497.643 - "Pairs: <a,1> <b,2> <c,3>." 497.644 - 497.645 - (format nil "Pairs:~@{ <~S,~S>~}." 'a 1 'b 2 'c 3) 497.646 - "Pairs: <a,1> <b,2> <c,3>." 497.647 - 497.648 - (format nil "Pairs:~:@{ <~S,~S>~}." '(a 1) '(b 2) '(c 3)) 497.649 - "Pairs: <a,1> <b,2> <c,3>.") 497.650 - 497.651 -(simple-tests cltl-angle-bracket-tests 497.652 - (format nil "~10<foo~;bar~>") "foo bar" 497.653 - (format nil "~10:<foo~;bar~>") " foo bar" 497.654 - (format nil "~10:@<foo~;bar~>") " foo bar " 497.655 - (format nil "~10<foobar~>") " foobar" 497.656 - (format nil "~10:<foobar~>") " foobar" 497.657 - (format nil "~10@<foobar~>") "foobar " 497.658 - (format nil "~10:@<foobar~>") " foobar ") 497.659 - 497.660 -(let [donestr "Done.~^ ~D warning~:P.~^ ~D error~:P." 497.661 - tellstr "~@{~@(~@[~R~^ ~]~A~)~}."] ;; The CLtL example is a little wrong here 497.662 - 497.663 - (simple-tests cltl-up-tests 497.664 - (format nil donestr) "Done." 497.665 - (format nil donestr 3) "Done. 3 warnings." 497.666 - (format nil donestr 1 5) "Done. 1 warning. 5 errors." 497.667 - (format nil tellstr 23) "Twenty-three." 497.668 - (format nil tellstr nil "losers") "Losers." 497.669 - (format nil tellstr 23 "losers") "Twenty-three losers." 497.670 - (format nil "~15<~S~;~^~S~;~^~S~>" 'foo) 497.671 - " foo" 497.672 - (format nil "~15<~S~;~^~S~;~^~S~>" 'foo 'bar) 497.673 - "foo bar" 497.674 - (format nil "~15<~S~;~^~S~;~^~S~>" 'foo 'bar 'baz) 497.675 - "foo bar baz")) 497.676 - 497.677 -(simple-tests cltl-up-x3j13-tests 497.678 - (format nil 497.679 - "~:{/~S~^ ...~}" 497.680 - '((hot dog) (hamburger) (ice cream) (french fries))) 497.681 - "/hot .../hamburger/ice .../french ..." 497.682 - (format nil 497.683 - "~:{/~S~:^ ...~}" 497.684 - '((hot dog) (hamburger) (ice cream) (french fries))) 497.685 - "/hot .../hamburger .../ice .../french" 497.686 - 497.687 - (format nil 497.688 - "~:{/~S~#:^ ...~}" ;; This is wrong in CLtL 497.689 - '((hot dog) (hamburger) (ice cream) (french fries))) 497.690 - "/hot .../hamburger") 497.691 -
498.1 --- a/src/clojure/test_clojure/pprint/test_helper.clj Sat Aug 21 06:25:44 2010 -0400 498.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 498.3 @@ -1,27 +0,0 @@ 498.4 -;;; test_helper.clj -- part of the pretty printer for Clojure 498.5 - 498.6 -; Copyright (c) Rich Hickey. All rights reserved. 498.7 -; The use and distribution terms for this software are covered by the 498.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 498.9 -; which can be found in the file epl-v10.html at the root of this distribution. 498.10 -; By using this software in any fashion, you are agreeing to be bound by 498.11 -; the terms of this license. 498.12 -; You must not remove this notice, or any other, from this software. 498.13 - 498.14 -;; Author: Tom Faulhaber 498.15 -;; April 3, 2009 498.16 - 498.17 - 498.18 -;; This is just a macro to make my tests a little cleaner 498.19 - 498.20 -(ns clojure.test-clojure.pprint.test-helper 498.21 - (:use [clojure.test :only (deftest is)])) 498.22 - 498.23 -(defn- back-match [x y] (re-matches y x)) 498.24 -(defmacro simple-tests [name & test-pairs] 498.25 - `(deftest ~name 498.26 - ~@(for [[x y] (partition 2 test-pairs)] 498.27 - (if (instance? java.util.regex.Pattern y) 498.28 - `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y)) 498.29 - `(is (= ~x ~y)))))) 498.30 -
499.1 --- a/src/clojure/test_clojure/pprint/test_pretty.clj Sat Aug 21 06:25:44 2010 -0400 499.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 499.3 @@ -1,275 +0,0 @@ 499.4 -;;; test_pretty.clj -- part of the pretty printer for Clojure 499.5 - 499.6 -; Copyright (c) Rich Hickey. All rights reserved. 499.7 -; The use and distribution terms for this software are covered by the 499.8 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 499.9 -; which can be found in the file epl-v10.html at the root of this distribution. 499.10 -; By using this software in any fashion, you are agreeing to be bound by 499.11 -; the terms of this license. 499.12 -; You must not remove this notice, or any other, from this software. 499.13 - 499.14 -;; Author: Tom Faulhaber 499.15 -;; April 3, 2009 499.16 - 499.17 - 499.18 -(in-ns 'clojure.test-clojure.pprint) 499.19 - 499.20 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 499.21 -;;; 499.22 -;;; Unit tests for the pretty printer 499.23 -;;; 499.24 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 499.25 - 499.26 -(simple-tests xp-fill-test 499.27 - (binding [*print-pprint-dispatch* simple-dispatch 499.28 - *print-right-margin* 38 499.29 - *print-miser-width* nil] 499.30 - (cl-format nil "(let ~:<~@{~:<~w ~_~w~:>~^ ~:_~}~:>~_ ...)~%" 499.31 - '((x 4) (*print-length* nil) (z 2) (list nil)))) 499.32 - "(let ((x 4) (*print-length* nil)\n (z 2) (list nil))\n ...)\n" 499.33 - 499.34 - (binding [*print-pprint-dispatch* simple-dispatch 499.35 - *print-right-margin* 22] 499.36 - (cl-format nil "(let ~:<~@{~:<~w ~_~w~:>~^ ~:_~}~:>~_ ...)~%" 499.37 - '((x 4) (*print-length* nil) (z 2) (list nil)))) 499.38 - "(let ((x 4)\n (*print-length*\n nil)\n (z 2)\n (list nil))\n ...)\n") 499.39 - 499.40 -(simple-tests xp-miser-test 499.41 - (binding [*print-pprint-dispatch* simple-dispatch 499.42 - *print-right-margin* 10, *print-miser-width* 9] 499.43 - (cl-format nil "~:<LIST ~@_~W ~@_~W ~@_~W~:>" '(first second third))) 499.44 - "(LIST\n first\n second\n third)" 499.45 - 499.46 - (binding [*print-pprint-dispatch* simple-dispatch 499.47 - *print-right-margin* 10, *print-miser-width* 8] 499.48 - (cl-format nil "~:<LIST ~@_~W ~@_~W ~@_~W~:>" '(first second third))) 499.49 - "(LIST first second third)") 499.50 - 499.51 -(simple-tests mandatory-fill-test 499.52 - (cl-format nil 499.53 - "<pre>~%~<Usage: ~:I~@{*~a*~^~:@_~}~:>~%</pre>~%" 499.54 - [ "hello" "gooodbye" ]) 499.55 - "<pre> 499.56 -Usage: *hello* 499.57 - *gooodbye* 499.58 -</pre> 499.59 -") 499.60 - 499.61 -(simple-tests prefix-suffix-test 499.62 - (binding [*print-pprint-dispatch* simple-dispatch 499.63 - *print-right-margin* 10, *print-miser-width* 10] 499.64 - (cl-format nil "~<{~;LIST ~@_~W ~@_~W ~@_~W~;}~:>" '(first second third))) 499.65 - "{LIST\n first\n second\n third}") 499.66 - 499.67 -(simple-tests pprint-test 499.68 - (binding [*print-pprint-dispatch* simple-dispatch] 499.69 - (write '(defn foo [x y] 499.70 - (let [result (* x y)] 499.71 - (if (> result 400) 499.72 - (cl-format true "That number is too big") 499.73 - (cl-format true "The result of ~d x ~d is ~d" x y result)))) 499.74 - :stream nil)) 499.75 - "(defn 499.76 - foo 499.77 - [x y] 499.78 - (let 499.79 - [result (* x y)] 499.80 - (if 499.81 - (> result 400) 499.82 - (cl-format true \"That number is too big\") 499.83 - (cl-format true \"The result of ~d x ~d is ~d\" x y result))))" 499.84 - 499.85 - (with-pprint-dispatch code-dispatch 499.86 - (write '(defn foo [x y] 499.87 - (let [result (* x y)] 499.88 - (if (> result 400) 499.89 - (cl-format true "That number is too big") 499.90 - (cl-format true "The result of ~d x ~d is ~d" x y result)))) 499.91 - :stream nil)) 499.92 - "(defn foo [x y] 499.93 - (let [result (* x y)] 499.94 - (if (> result 400) 499.95 - (cl-format true \"That number is too big\") 499.96 - (cl-format true \"The result of ~d x ~d is ~d\" x y result))))" 499.97 - 499.98 - (binding [*print-pprint-dispatch* simple-dispatch 499.99 - *print-right-margin* 15] 499.100 - (write '(fn (cons (car x) (cdr y))) :stream nil)) 499.101 - "(fn\n (cons\n (car x)\n (cdr y)))" 499.102 - 499.103 - (with-pprint-dispatch code-dispatch 499.104 - (binding [*print-right-margin* 52] 499.105 - (write 499.106 - '(add-to-buffer this (make-buffer-blob (str (char c)) nil)) 499.107 - :stream nil))) 499.108 - "(add-to-buffer\n this\n (make-buffer-blob (str (char c)) nil))" 499.109 - ) 499.110 - 499.111 - 499.112 - 499.113 -(simple-tests pprint-reader-macro-test 499.114 - (with-pprint-dispatch code-dispatch 499.115 - (write (read-string "(map #(first %) [[1 2 3] [4 5 6] [7]])") 499.116 - :stream nil)) 499.117 - "(map #(first %) [[1 2 3] [4 5 6] [7]])" 499.118 - 499.119 - (with-pprint-dispatch code-dispatch 499.120 - (write (read-string "@@(ref (ref 1))") 499.121 - :stream nil)) 499.122 - "@@(ref (ref 1))" 499.123 - 499.124 - (with-pprint-dispatch code-dispatch 499.125 - (write (read-string "'foo") 499.126 - :stream nil)) 499.127 - "'foo" 499.128 -) 499.129 - 499.130 -(simple-tests code-block-tests 499.131 - (with-out-str 499.132 - (with-pprint-dispatch code-dispatch 499.133 - (pprint 499.134 - '(defn cl-format 499.135 - "An implementation of a Common Lisp compatible format function" 499.136 - [stream format-in & args] 499.137 - (let [compiled-format (if (string? format-in) (compile-format format-in) format-in) 499.138 - navigator (init-navigator args)] 499.139 - (execute-format stream compiled-format navigator)))))) 499.140 - "(defn cl-format 499.141 - \"An implementation of a Common Lisp compatible format function\" 499.142 - [stream format-in & args] 499.143 - (let [compiled-format (if (string? format-in) 499.144 - (compile-format format-in) 499.145 - format-in) 499.146 - navigator (init-navigator args)] 499.147 - (execute-format stream compiled-format navigator))) 499.148 -" 499.149 - 499.150 - (with-out-str 499.151 - (with-pprint-dispatch code-dispatch 499.152 - (pprint 499.153 - '(defn pprint-defn [writer alis] 499.154 - (if (next alis) 499.155 - (let [[defn-sym defn-name & stuff] alis 499.156 - [doc-str stuff] (if (string? (first stuff)) 499.157 - [(first stuff) (next stuff)] 499.158 - [nil stuff]) 499.159 - [attr-map stuff] (if (map? (first stuff)) 499.160 - [(first stuff) (next stuff)] 499.161 - [nil stuff])] 499.162 - (pprint-logical-block writer :prefix "(" :suffix ")" 499.163 - (cl-format true "~w ~1I~@_~w" defn-sym defn-name) 499.164 - (if doc-str 499.165 - (cl-format true " ~_~w" doc-str)) 499.166 - (if attr-map 499.167 - (cl-format true " ~_~w" attr-map)) 499.168 - ;; Note: the multi-defn case will work OK for malformed defns too 499.169 - (cond 499.170 - (vector? (first stuff)) (single-defn stuff (or doc-str attr-map)) 499.171 - :else (multi-defn stuff (or doc-str attr-map))))) 499.172 - (pprint-simple-code-list writer alis)))))) 499.173 - "(defn pprint-defn [writer alis] 499.174 - (if (next alis) 499.175 - (let [[defn-sym defn-name & stuff] alis 499.176 - [doc-str stuff] (if (string? (first stuff)) 499.177 - [(first stuff) (next stuff)] 499.178 - [nil stuff]) 499.179 - [attr-map stuff] (if (map? (first stuff)) 499.180 - [(first stuff) (next stuff)] 499.181 - [nil stuff])] 499.182 - (pprint-logical-block 499.183 - writer 499.184 - :prefix 499.185 - \"(\" 499.186 - :suffix 499.187 - \")\" 499.188 - (cl-format true \"~w ~1I~@_~w\" defn-sym defn-name) 499.189 - (if doc-str (cl-format true \" ~_~w\" doc-str)) 499.190 - (if attr-map (cl-format true \" ~_~w\" attr-map)) 499.191 - (cond 499.192 - (vector? (first stuff)) (single-defn 499.193 - stuff 499.194 - (or doc-str attr-map)) 499.195 - :else (multi-defn stuff (or doc-str attr-map))))) 499.196 - (pprint-simple-code-list writer alis))) 499.197 -") 499.198 - 499.199 - 499.200 -(defn tst-pprint 499.201 - "A helper function to pprint to a string with a restricted right margin" 499.202 - [right-margin obj] 499.203 - (binding [*print-right-margin* right-margin 499.204 - *print-pretty* true] 499.205 - (write obj :stream nil))) 499.206 - 499.207 -;;; A bunch of predefined data to print 499.208 -(def future-filled (future-call (fn [] 100))) 499.209 -@future-filled 499.210 -(def future-unfilled (future-call (fn [] (.acquire (java.util.concurrent.Semaphore. 0))))) 499.211 -(def promise-filled (promise)) 499.212 -(deliver promise-filled '(first second third)) 499.213 -(def promise-unfilled (promise)) 499.214 -(def basic-agent (agent '(first second third))) 499.215 -(defn failed-agent 499.216 - "must be a fn because you cannot await agents during load" 499.217 - [] 499.218 - (let [a (agent "foo")] 499.219 - (send a +) 499.220 - (try (await-for 100 failed-agent) (catch RuntimeException re)) 499.221 - a)) 499.222 -(def basic-atom (atom '(first second third))) 499.223 -(def basic-ref (ref '(first second third))) 499.224 -(def delay-forced (delay '(first second third))) 499.225 -(force delay-forced) 499.226 -(def delay-unforced (delay '(first second third))) 499.227 -(defrecord pprint-test-rec [a b c]) 499.228 - 499.229 -(simple-tests pprint-datastructures-tests 499.230 - (tst-pprint 20 future-filled) #"#<Future@[0-9a-f]+: \n 100>" 499.231 - (tst-pprint 20 future-unfilled) #"#<Future@[0-9a-f]+: \n :pending>" 499.232 - (tst-pprint 20 promise-filled) #"#<Promise@[0-9a-f]+: \n \(first\n second\n third\)>" 499.233 - ;; This hangs currently, cause we can't figure out whether a promise is filled 499.234 - ;;(tst-pprint 20 promise-unfilled) #"#<Promise@[0-9a-f]+: \n :pending>" 499.235 - (tst-pprint 20 basic-agent) #"#<Agent@[0-9a-f]+: \n \(first\n second\n third\)>" 499.236 - (tst-pprint 20 (failed-agent)) #"#<Agent@[0-9a-f]+ FAILED: \n \"foo\">" 499.237 - (tst-pprint 20 basic-atom) #"#<Atom@[0-9a-f]+: \n \(first\n second\n third\)>" 499.238 - (tst-pprint 20 basic-ref) #"#<Ref@[0-9a-f]+: \n \(first\n second\n third\)>" 499.239 - (tst-pprint 20 delay-forced) #"#<Delay@[0-9a-f]+: \n \(first\n second\n third\)>" 499.240 - ;; Currently no way not to force the delay 499.241 - ;;(tst-pprint 20 delay-unforced) #"#<Delay@[0-9a-f]+: \n :pending>" 499.242 - (tst-pprint 20 (pprint-test-rec. 'first 'second 'third)) "{:a first,\n :b second,\n :c third}" 499.243 - 499.244 - ;; basic java arrays: fails owing to assembla ticket #346 499.245 - ;;(tst-pprint 10 (int-array (range 7))) "[0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6]" 499.246 - (tst-pprint 15 (reduce conj clojure.lang.PersistentQueue/EMPTY (range 10))) 499.247 - "<-(0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9)-<" 499.248 - ) 499.249 - 499.250 - 499.251 -;;; Some simple tests of dispatch 499.252 - 499.253 -(defmulti 499.254 - test-dispatch 499.255 - "A test dispatch method" 499.256 - {:added "1.2" :arglists '[[object]]} 499.257 - #(and (seq %) (not (string? %)))) 499.258 - 499.259 -(defmethod test-dispatch true [avec] 499.260 - (pprint-logical-block :prefix "[" :suffix "]" 499.261 - (loop [aseq (seq avec)] 499.262 - (when aseq 499.263 - (write-out (first aseq)) 499.264 - (when (next aseq) 499.265 - (.write ^java.io.Writer *out* " ") 499.266 - (pprint-newline :linear) 499.267 - (recur (next aseq))))))) 499.268 - 499.269 -(defmethod test-dispatch false [aval] (pr aval)) 499.270 - 499.271 -(simple-tests dispatch-tests 499.272 - (with-pprint-dispatch test-dispatch 499.273 - (with-out-str 499.274 - (pprint '("hello" "there")))) 499.275 - "[\"hello\" \"there\"]\n" 499.276 -) 499.277 - 499.278 -
500.1 --- a/src/clojure/test_clojure/predicates.clj Sat Aug 21 06:25:44 2010 -0400 500.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 500.3 @@ -1,142 +0,0 @@ 500.4 -; Copyright (c) Rich Hickey. All rights reserved. 500.5 -; The use and distribution terms for this software are covered by the 500.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 500.7 -; which can be found in the file epl-v10.html at the root of this distribution. 500.8 -; By using this software in any fashion, you are agreeing to be bound by 500.9 -; the terms of this license. 500.10 -; You must not remove this notice, or any other, from this software. 500.11 - 500.12 -; Author: Frantisek Sodomka 500.13 - 500.14 -;; 500.15 -;; Created 1/28/2009 500.16 - 500.17 -(ns clojure.test-clojure.predicates 500.18 - (:use clojure.test)) 500.19 - 500.20 - 500.21 -;; *** Type predicates *** 500.22 - 500.23 -(def myvar 42) 500.24 - 500.25 -(def sample-data { 500.26 - :nil nil 500.27 - 500.28 - :bool-true true 500.29 - :bool-false false 500.30 - 500.31 - :byte (byte 7) 500.32 - :short (short 7) 500.33 - :int (int 7) 500.34 - :long (long 7) 500.35 - :bigint (bigint 7) 500.36 - :float (float 7) 500.37 - :double (double 7) 500.38 - :bigdec (bigdec 7) 500.39 - 500.40 - :ratio 2/3 500.41 - 500.42 - :character \a 500.43 - :symbol 'abc 500.44 - :keyword :kw 500.45 - 500.46 - :empty-string "" 500.47 - :empty-regex #"" 500.48 - :empty-list () 500.49 - :empty-lazy-seq (lazy-seq nil) 500.50 - :empty-vector [] 500.51 - :empty-map {} 500.52 - :empty-set #{} 500.53 - :empty-array (into-array []) 500.54 - 500.55 - :string "abc" 500.56 - :regex #"a*b" 500.57 - :list '(1 2 3) 500.58 - :lazy-seq (lazy-seq [1 2 3]) 500.59 - :vector [1 2 3] 500.60 - :map {:a 1 :b 2 :c 3} 500.61 - :set #{1 2 3} 500.62 - :array (into-array [1 2 3]) 500.63 - 500.64 - :fn (fn [x] (* 2 x)) 500.65 - 500.66 - :class java.util.Date 500.67 - :object (new java.util.Date) 500.68 - 500.69 - :var (var myvar) 500.70 - :delay (delay (+ 1 2)) 500.71 -}) 500.72 - 500.73 - 500.74 -(def type-preds { 500.75 - nil? [:nil] 500.76 - 500.77 - true? [:bool-true] 500.78 - false? [:bool-false] 500.79 - ; boolean? 500.80 - 500.81 - integer? [:byte :short :int :long :bigint] 500.82 - float? [:float :double] 500.83 - decimal? [:bigdec] 500.84 - ratio? [:ratio] 500.85 - rational? [:byte :short :int :long :bigint :ratio :bigdec] 500.86 - number? [:byte :short :int :long :bigint :ratio :bigdec :float :double] 500.87 - 500.88 - ; character? 500.89 - symbol? [:symbol] 500.90 - keyword? [:keyword] 500.91 - 500.92 - string? [:empty-string :string] 500.93 - ; regex? 500.94 - 500.95 - list? [:empty-list :list] 500.96 - vector? [:empty-vector :vector] 500.97 - map? [:empty-map :map] 500.98 - set? [:empty-set :set] 500.99 - 500.100 - coll? [:empty-list :list 500.101 - :empty-lazy-seq :lazy-seq 500.102 - :empty-vector :vector 500.103 - :empty-map :map 500.104 - :empty-set :set] 500.105 - 500.106 - seq? [:empty-list :list 500.107 - :empty-lazy-seq :lazy-seq] 500.108 - ; array? 500.109 - 500.110 - fn? [:fn] 500.111 - ifn? [:fn 500.112 - :empty-vector :vector :empty-map :map :empty-set :set 500.113 - :keyword :symbol :var] 500.114 - 500.115 - class? [:class] 500.116 - var? [:var] 500.117 - delay? [:delay] 500.118 -}) 500.119 - 500.120 - 500.121 -;; Test all type predicates against all data types 500.122 -;; 500.123 -(defn- get-fn-name [f] 500.124 - (str 500.125 - (apply str (nthnext (first (.split (str f) "_")) 500.126 - (count "clojure.core$"))) 500.127 - "?")) 500.128 - 500.129 -(deftest test-type-preds 500.130 - (doseq [tp type-preds] 500.131 - (doseq [dt sample-data] 500.132 - (if (some #(= % (first dt)) (second tp)) 500.133 - (is ((first tp) (second dt)) 500.134 - (pr-str (list (get-fn-name (first tp)) (second dt)))) 500.135 - (is (not ((first tp) (second dt))) 500.136 - (pr-str (list 'not (list (get-fn-name (first tp)) (second dt))))))))) 500.137 - 500.138 - 500.139 -;; Additional tests: 500.140 -;; http://groups.google.com/group/clojure/browse_thread/thread/537761a06edb4b06/bfd4f0705b746a38 500.141 -;; 500.142 -(deftest test-string?-more 500.143 - (are [x] (not (string? x)) 500.144 - (new java.lang.StringBuilder "abc") 500.145 - (new java.lang.StringBuffer "xyz")))
501.1 --- a/src/clojure/test_clojure/printer.clj Sat Aug 21 06:25:44 2010 -0400 501.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 501.3 @@ -1,83 +0,0 @@ 501.4 -; Copyright (c) Rich Hickey. All rights reserved. 501.5 -; The use and distribution terms for this software are covered by the 501.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 501.7 -; which can be found in the file epl-v10.html at the root of this distribution. 501.8 -; By using this software in any fashion, you are agreeing to be bound by 501.9 -; the terms of this license. 501.10 -; You must not remove this notice, or any other, from this software. 501.11 - 501.12 -; Author: Stephen C. Gilardi 501.13 - 501.14 -;; clojure.test-clojure.printer 501.15 -;; 501.16 -;; scgilardi (gmail) 501.17 -;; Created 29 October 2008 501.18 - 501.19 -(ns clojure.test-clojure.printer 501.20 - (:use clojure.test)) 501.21 - 501.22 -(deftest print-length-empty-seq 501.23 - (let [coll () val "()"] 501.24 - (is (= val (binding [*print-length* 0] (print-str coll)))) 501.25 - (is (= val (binding [*print-length* 1] (print-str coll)))))) 501.26 - 501.27 -(deftest print-length-seq 501.28 - (let [coll (range 5) 501.29 - length-val '((0 "(...)") 501.30 - (1 "(0 ...)") 501.31 - (2 "(0 1 ...)") 501.32 - (3 "(0 1 2 ...)") 501.33 - (4 "(0 1 2 3 ...)") 501.34 - (5 "(0 1 2 3 4)"))] 501.35 - (doseq [[length val] length-val] 501.36 - (binding [*print-length* length] 501.37 - (is (= val (print-str coll))))))) 501.38 - 501.39 -(deftest print-length-empty-vec 501.40 - (let [coll [] val "[]"] 501.41 - (is (= val (binding [*print-length* 0] (print-str coll)))) 501.42 - (is (= val (binding [*print-length* 1] (print-str coll)))))) 501.43 - 501.44 -(deftest print-length-vec 501.45 - (let [coll [0 1 2 3 4] 501.46 - length-val '((0 "[...]") 501.47 - (1 "[0 ...]") 501.48 - (2 "[0 1 ...]") 501.49 - (3 "[0 1 2 ...]") 501.50 - (4 "[0 1 2 3 ...]") 501.51 - (5 "[0 1 2 3 4]"))] 501.52 - (doseq [[length val] length-val] 501.53 - (binding [*print-length* length] 501.54 - (is (= val (print-str coll))))))) 501.55 - 501.56 -(deftest print-level-seq 501.57 - (let [coll '(0 (1 (2 (3 (4))))) 501.58 - level-val '((0 "#") 501.59 - (1 "(0 #)") 501.60 - (2 "(0 (1 #))") 501.61 - (3 "(0 (1 (2 #)))") 501.62 - (4 "(0 (1 (2 (3 #))))") 501.63 - (5 "(0 (1 (2 (3 (4)))))"))] 501.64 - (doseq [[level val] level-val] 501.65 - (binding [*print-level* level] 501.66 - (is (= val (print-str coll))))))) 501.67 - 501.68 -(deftest print-level-length-coll 501.69 - (let [coll '(if (member x y) (+ (first x) 3) (foo (a b c d "Baz"))) 501.70 - level-length-val 501.71 - '((0 1 "#") 501.72 - (1 1 "(if ...)") 501.73 - (1 2 "(if # ...)") 501.74 - (1 3 "(if # # ...)") 501.75 - (1 4 "(if # # #)") 501.76 - (2 1 "(if ...)") 501.77 - (2 2 "(if (member x ...) ...)") 501.78 - (2 3 "(if (member x y) (+ # 3) ...)") 501.79 - (3 2 "(if (member x ...) ...)") 501.80 - (3 3 "(if (member x y) (+ (first x) 3) ...)") 501.81 - (3 4 "(if (member x y) (+ (first x) 3) (foo (a b c d ...)))") 501.82 - (3 5 "(if (member x y) (+ (first x) 3) (foo (a b c d Baz)))"))] 501.83 - (doseq [[level length val] level-length-val] 501.84 - (binding [*print-level* level 501.85 - *print-length* length] 501.86 - (is (= val (print-str coll)))))))
502.1 --- a/src/clojure/test_clojure/protocols.clj Sat Aug 21 06:25:44 2010 -0400 502.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 502.3 @@ -1,300 +0,0 @@ 502.4 -; Copyright (c) Rich Hickey. All rights reserved. 502.5 -; The use and distribution terms for this software are covered by the 502.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 502.7 -; which can be found in the file epl-v10.html at the root of this distribution. 502.8 -; By using this software in any fashion, you are agreeing to be bound by 502.9 -; the terms of this license. 502.10 -; You must not remove this notice, or any other, from this software. 502.11 - 502.12 -; Author: Stuart Halloway 502.13 - 502.14 -(ns clojure.test-clojure.protocols 502.15 - (:use clojure.test clojure.test-clojure.protocols.examples) 502.16 - (:require [clojure.test-clojure.protocols.more-examples :as other] 502.17 - [clojure.set :as set] 502.18 - clojure.test-clojure.helpers) 502.19 - (:import [clojure.test_clojure.protocols.examples ExampleInterface])) 502.20 - 502.21 -;; temporary hack until I decide how to cleanly reload protocol 502.22 -(defn reload-example-protocols 502.23 - [] 502.24 - (alter-var-root #'clojure.test-clojure.protocols.examples/ExampleProtocol 502.25 - assoc :impls {}) 502.26 - (alter-var-root #'clojure.test-clojure.protocols.more-examples/SimpleProtocol 502.27 - assoc :impls {}) 502.28 - (require :reload 502.29 - 'clojure.test-clojure.protocols.examples 502.30 - 'clojure.test-clojure.protocols.more-examples)) 502.31 - 502.32 -(defn method-names 502.33 - "return sorted list of method names on a class" 502.34 - [c] 502.35 - (->> (.getMethods c) 502.36 - (map #(.getName %)) 502.37 - (sort))) 502.38 - 502.39 -(defrecord EmptyRecord []) 502.40 -(defrecord TestRecord [a b]) 502.41 -(defn r 502.42 - ([a b] (TestRecord. a b)) 502.43 - ([a b meta ext] (TestRecord. a b meta ext))) 502.44 -(defrecord MapEntry [k v] 502.45 - java.util.Map$Entry 502.46 - (getKey [_] k) 502.47 - (getValue [_] v)) 502.48 - 502.49 -(deftest protocols-test 502.50 - (testing "protocol fns have useful metadata" 502.51 - (let [common-meta {:ns (find-ns 'clojure.test-clojure.protocols.examples) 502.52 - :protocol #'ExampleProtocol}] 502.53 - (are [m f] (= (merge (quote m) common-meta) 502.54 - (meta (var f))) 502.55 - {:name foo :arglists ([a]) :doc "method with one arg"} foo 502.56 - {:name bar :arglists ([a b]) :doc "method with two args"} bar 502.57 - {:name baz :arglists ([a] [a b]) :doc "method with multiple arities" :tag String} baz 502.58 - {:name with-quux :arglists ([a]) :doc "method name with a hyphen"} with-quux))) 502.59 - (testing "protocol fns throw IllegalArgumentException if no impl matches" 502.60 - (is (thrown-with-msg? 502.61 - IllegalArgumentException 502.62 - #"No implementation of method: :foo of protocol: #'clojure.test-clojure.protocols.examples/ExampleProtocol found for class: java.lang.Integer" 502.63 - (foo 10)))) 502.64 - (testing "protocols generate a corresponding interface using _ instead of - for method names" 502.65 - (is (= ["bar" "baz" "baz" "foo" "with_quux"] (method-names clojure.test_clojure.protocols.examples.ExampleProtocol)))) 502.66 - (testing "protocol will work with instances of its interface (use for interop, not in Clojure!)" 502.67 - (let [obj (proxy [clojure.test_clojure.protocols.examples.ExampleProtocol] [] 502.68 - (foo [] "foo!"))] 502.69 - (is (= "foo!" (.foo obj)) "call through interface") 502.70 - (is (= "foo!" (foo obj)) "call through protocol"))) 502.71 - (testing "you can implement just part of a protocol if you want" 502.72 - (let [obj (reify ExampleProtocol 502.73 - (baz [a b] "two-arg baz!"))] 502.74 - (is (= "two-arg baz!" (baz obj nil))) 502.75 - (is (thrown? AbstractMethodError (baz obj))))) 502.76 - (testing "you can redefine a protocol with different methods" 502.77 - (eval '(defprotocol Elusive (old-method [x]))) 502.78 - (eval '(defprotocol Elusive (new-method [x]))) 502.79 - (is (= :new-method (eval '(new-method (reify Elusive (new-method [x] :new-method)))))) 502.80 - (is (fails-with-cause? IllegalArgumentException #"No method of interface: user\.Elusive found for function: old-method of protocol: Elusive \(The protocol method may have been defined before and removed\.\)" 502.81 - (eval '(old-method (reify Elusive (new-method [x] :new-method)))))))) 502.82 - 502.83 -(deftype ExtendTestWidget [name]) 502.84 -(deftype HasProtocolInline [] 502.85 - ExampleProtocol 502.86 - (foo [this] :inline)) 502.87 -(deftest extend-test 502.88 - (testing "you can extend a protocol to a class" 502.89 - (extend String ExampleProtocol 502.90 - {:foo identity}) 502.91 - (is (= "pow" (foo "pow")))) 502.92 - (testing "you can have two methods with the same name. Just use namespaces!" 502.93 - (extend String other/SimpleProtocol 502.94 - {:foo (fn [s] (.toUpperCase s))}) 502.95 - (is (= "POW" (other/foo "pow")))) 502.96 - (testing "you can extend deftype types" 502.97 - (extend 502.98 - ExtendTestWidget 502.99 - ExampleProtocol 502.100 - {:foo (fn [this] (str "widget " (.name this)))}) 502.101 - (is (= "widget z" (foo (ExtendTestWidget. "z")))))) 502.102 - 502.103 -(deftest illegal-extending 502.104 - (testing "you cannot extend a protocol to a type that implements the protocol inline" 502.105 - (is (fails-with-cause? IllegalArgumentException #".*HasProtocolInline already directly implements interface" 502.106 - (eval '(extend clojure.test-clojure.protocols.HasProtocolInline 502.107 - clojure.test-clojure.protocols.examples/ExampleProtocol 502.108 - {:foo (fn [_] :extended)}))))) 502.109 - (testing "you cannot extend to an interface" 502.110 - (is (fails-with-cause? IllegalArgumentException #"interface clojure.test_clojure.protocols.examples.ExampleProtocol is not a protocol" 502.111 - (eval '(extend clojure.test-clojure.protocols.HasProtocolInline 502.112 - clojure.test_clojure.protocols.examples.ExampleProtocol 502.113 - {:foo (fn [_] :extended)})))))) 502.114 - 502.115 -(deftype ExtendsTestWidget [] 502.116 - ExampleProtocol) 502.117 -(deftest extends?-test 502.118 - (reload-example-protocols) 502.119 - (testing "returns false if a type does not implement the protocol at all" 502.120 - (is (false? (extends? other/SimpleProtocol ExtendsTestWidget)))) 502.121 - (testing "returns true if a type implements the protocol directly" ;; semantics changed 4/15/2010 502.122 - (is (true? (extends? ExampleProtocol ExtendsTestWidget)))) 502.123 - (testing "returns true if a type explicitly extends protocol" 502.124 - (extend 502.125 - ExtendsTestWidget 502.126 - other/SimpleProtocol 502.127 - {:foo identity}) 502.128 - (is (true? (extends? other/SimpleProtocol ExtendsTestWidget))))) 502.129 - 502.130 -(deftype ExtendersTestWidget []) 502.131 -(deftest extenders-test 502.132 - (reload-example-protocols) 502.133 - (testing "a fresh protocol has no extenders" 502.134 - (is (nil? (extenders ExampleProtocol)))) 502.135 - (testing "extending with no methods doesn't count!" 502.136 - (deftype Something []) 502.137 - (extend ::Something ExampleProtocol) 502.138 - (is (nil? (extenders ExampleProtocol)))) 502.139 - (testing "extending a protocol (and including an impl) adds an entry to extenders" 502.140 - (extend ExtendersTestWidget ExampleProtocol {:foo identity}) 502.141 - (is (= [ExtendersTestWidget] (extenders ExampleProtocol))))) 502.142 - 502.143 -(deftype SatisfiesTestWidget [] 502.144 - ExampleProtocol) 502.145 -(deftest satisifies?-test 502.146 - (reload-example-protocols) 502.147 - (let [whatzit (SatisfiesTestWidget.)] 502.148 - (testing "returns false if a type does not implement the protocol at all" 502.149 - (is (false? (satisfies? other/SimpleProtocol whatzit)))) 502.150 - (testing "returns true if a type implements the protocol directly" 502.151 - (is (true? (satisfies? ExampleProtocol whatzit)))) 502.152 - (testing "returns true if a type explicitly extends protocol" 502.153 - (extend 502.154 - SatisfiesTestWidget 502.155 - other/SimpleProtocol 502.156 - {:foo identity}) 502.157 - (is (true? (satisfies? other/SimpleProtocol whatzit))))) ) 502.158 - 502.159 -(deftype ReExtendingTestWidget []) 502.160 -(deftest re-extending-test 502.161 - (reload-example-protocols) 502.162 - (extend 502.163 - ReExtendingTestWidget 502.164 - ExampleProtocol 502.165 - {:foo (fn [_] "first foo") 502.166 - :baz (fn [_] "first baz")}) 502.167 - (testing "if you re-extend, the old implementation is replaced (not merged!)" 502.168 - (extend 502.169 - ReExtendingTestWidget 502.170 - ExampleProtocol 502.171 - {:baz (fn [_] "second baz") 502.172 - :bar (fn [_ _] "second bar")}) 502.173 - (let [whatzit (ReExtendingTestWidget.)] 502.174 - (is (thrown? IllegalArgumentException (foo whatzit))) 502.175 - (is (= "second bar" (bar whatzit nil))) 502.176 - (is (= "second baz" (baz whatzit)))))) 502.177 - 502.178 -(defrecord DefrecordObjectMethodsWidgetA [a]) 502.179 -(defrecord DefrecordObjectMethodsWidgetB [a]) 502.180 -(deftest defrecord-object-methods-test 502.181 - (testing "= depends on fields and type" 502.182 - (is (true? (= (DefrecordObjectMethodsWidgetA. 1) (DefrecordObjectMethodsWidgetA. 1)))) 502.183 - (is (false? (= (DefrecordObjectMethodsWidgetA. 1) (DefrecordObjectMethodsWidgetA. 2)))) 502.184 - (is (false? (= (DefrecordObjectMethodsWidgetA. 1) (DefrecordObjectMethodsWidgetB. 1)))))) 502.185 - 502.186 -(deftest defrecord-acts-like-a-map 502.187 - (let [rec (r 1 2)] 502.188 - (is (.equals (r 1 3 {} {:c 4}) (merge rec {:b 3 :c 4}))) 502.189 - (is (.equals {:foo 1 :b 2} (set/rename-keys rec {:a :foo}))) 502.190 - (is (.equals {:a 11 :b 2 :c 10} (merge-with + rec {:a 10 :c 10}))))) 502.191 - 502.192 -(deftest degenerate-defrecord-test 502.193 - (let [empty (EmptyRecord.)] 502.194 - (is (nil? (seq empty))) 502.195 - (is (not (.containsValue empty :a))))) 502.196 - 502.197 -(deftest defrecord-interfaces-test 502.198 - (testing "java.util.Map" 502.199 - (let [rec (r 1 2)] 502.200 - (is (= 2 (.size rec))) 502.201 - (is (= 3 (.size (assoc rec :c 3)))) 502.202 - (is (not (.isEmpty rec))) 502.203 - (is (.isEmpty (EmptyRecord.))) 502.204 - (is (.containsKey rec :a)) 502.205 - (is (not (.containsKey rec :c))) 502.206 - (is (.containsValue rec 1)) 502.207 - (is (not (.containsValue rec 3))) 502.208 - (is (= 1 (.get rec :a))) 502.209 - (is (thrown? UnsupportedOperationException (.put rec :a 1))) 502.210 - (is (thrown? UnsupportedOperationException (.remove rec :a))) 502.211 - (is (thrown? UnsupportedOperationException (.putAll rec {}))) 502.212 - (is (thrown? UnsupportedOperationException (.clear rec))) 502.213 - (is (= #{:a :b} (.keySet rec))) 502.214 - (is (= #{1 2} (set (.values rec)))) 502.215 - (is (= #{[:a 1] [:b 2]} (.entrySet rec))) 502.216 - 502.217 - )) 502.218 - (testing "IPersistentCollection" 502.219 - (testing ".cons" 502.220 - (let [rec (r 1 2)] 502.221 - (are [x] (= rec (.cons rec x)) 502.222 - nil {}) 502.223 - (is (= (r 1 3) (.cons rec {:b 3}))) 502.224 - (is (= (r 1 4) (.cons rec [:b 4]))) 502.225 - (is (= (r 1 5) (.cons rec (MapEntry. :b 5)))))))) 502.226 - 502.227 -(defrecord RecordWithSpecificFieldNames [this that k m o]) 502.228 -(deftest defrecord-with-specific-field-names 502.229 - (let [rec (new RecordWithSpecificFieldNames 1 2 3 4 5)] 502.230 - (is (= rec rec)) 502.231 - (is (= 1 (:this (with-meta rec {:foo :bar})))) 502.232 - (is (= 3 (get rec :k))) 502.233 - (is (= (seq rec) '([:this 1] [:that 2] [:k 3] [:m 4] [:o 5]))) 502.234 - (is (= (dissoc rec :k) {:this 1, :that 2, :m 4, :o 5})))) 502.235 - 502.236 -(deftest reify-test 502.237 - (testing "of an interface" 502.238 - (let [s :foo 502.239 - r (reify 502.240 - java.util.List 502.241 - (contains [_ o] (= s o)))] 502.242 - (testing "implemented methods" 502.243 - (is (true? (.contains r :foo))) 502.244 - (is (false? (.contains r :bar)))) 502.245 - (testing "unimplemented methods" 502.246 - (is (thrown? AbstractMethodError (.add r :baz)))))) 502.247 - (testing "of two interfaces" 502.248 - (let [r (reify 502.249 - java.util.List 502.250 - (contains [_ o] (= :foo o)) 502.251 - java.util.Collection 502.252 - (isEmpty [_] false))] 502.253 - (is (true? (.contains r :foo))) 502.254 - (is (false? (.contains r :bar))) 502.255 - (is (false? (.isEmpty r))))) 502.256 - (testing "you can't define a method twice" 502.257 - (is (fails-with-cause? 502.258 - java.lang.ClassFormatError #"^(Repetitive|Duplicate) method name" 502.259 - (eval '(reify 502.260 - java.util.List 502.261 - (size [_] 10) 502.262 - java.util.Collection 502.263 - (size [_] 20)))))) 502.264 - (testing "you can't define a method not on an interface/protocol/j.l.Object" 502.265 - (is (fails-with-cause? 502.266 - IllegalArgumentException #"^Can't define method not in interfaces: foo" 502.267 - (eval '(reify java.util.List (foo [_])))))) 502.268 - (testing "of a protocol" 502.269 - (let [r (reify 502.270 - ExampleProtocol 502.271 - (bar [this o] o) 502.272 - (baz [this] 1) 502.273 - (baz [this o] 2))] 502.274 - (= :foo (.bar r :foo)) 502.275 - (= 1 (.baz r)) 502.276 - (= 2 (.baz r nil)))) 502.277 - (testing "destructuring in method def" 502.278 - (let [r (reify 502.279 - ExampleProtocol 502.280 - (bar [this [_ _ item]] item))] 502.281 - (= :c (.bar r [:a :b :c])))) 502.282 - (testing "methods can recur" 502.283 - (let [r (reify 502.284 - java.util.List 502.285 - (get [_ index] 502.286 - (if (zero? index) 502.287 - :done 502.288 - (recur (dec index)))))] 502.289 - (is (= :done (.get r 0))) 502.290 - (is (= :done (.get r 1))))) 502.291 - (testing "disambiguating with type hints" 502.292 - (testing "you must hint an overloaded method" 502.293 - (is (fails-with-cause? 502.294 - IllegalArgumentException #"Must hint overloaded method: hinted" 502.295 - (eval '(reify clojure.test_clojure.protocols.examples.ExampleInterface (hinted [_ o])))))) 502.296 - (testing "hinting" 502.297 - (let [r (reify 502.298 - ExampleInterface 502.299 - (hinted [_ ^int i] (inc i)) 502.300 - (hinted [_ ^String s] (str s s)))] 502.301 - (is (= 2 (.hinted r 1))) 502.302 - (is (= "xoxo" (.hinted r "xo"))))))) 502.303 -
503.1 --- a/src/clojure/test_clojure/protocols/examples.clj Sat Aug 21 06:25:44 2010 -0400 503.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 503.3 @@ -1,14 +0,0 @@ 503.4 -(ns clojure.test-clojure.protocols.examples) 503.5 - 503.6 -(defprotocol ExampleProtocol 503.7 - "example protocol used by clojure tests" 503.8 - 503.9 - (foo [a] "method with one arg") 503.10 - (bar [a b] "method with two args") 503.11 - (^String baz [a] [a b] "method with multiple arities") 503.12 - (with-quux [a] "method name with a hyphen")) 503.13 - 503.14 -(definterface ExampleInterface 503.15 - (hinted [^int i]) 503.16 - (hinted [^String s])) 503.17 -
504.1 --- a/src/clojure/test_clojure/protocols/more_examples.clj Sat Aug 21 06:25:44 2010 -0400 504.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 504.3 @@ -1,7 +0,0 @@ 504.4 -(ns clojure.test-clojure.protocols.more-examples) 504.5 - 504.6 -(defprotocol SimpleProtocol 504.7 - "example protocol used by clojure tests. Note that 504.8 - foo collides with examples/ExampleProtocol." 504.9 - 504.10 - (foo [a] ""))
505.1 --- a/src/clojure/test_clojure/reader.clj Sat Aug 21 06:25:44 2010 -0400 505.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 505.3 @@ -1,319 +0,0 @@ 505.4 -; Copyright (c) Rich Hickey. All rights reserved. 505.5 -; The use and distribution terms for this software are covered by the 505.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 505.7 -; which can be found in the file epl-v10.html at the root of this distribution. 505.8 -; By using this software in any fashion, you are agreeing to be bound by 505.9 -; the terms of this license. 505.10 -; You must not remove this notice, or any other, from this software. 505.11 - 505.12 -; Author: Stephen C. Gilardi 505.13 - 505.14 -;; 505.15 -;; Tests for the Clojure functions documented at the URL: 505.16 -;; 505.17 -;; http://clojure.org/Reader 505.18 -;; 505.19 -;; scgilardi (gmail) 505.20 -;; Created 22 October 2008 505.21 - 505.22 -(ns clojure.test-clojure.reader 505.23 - (:use clojure.test)) 505.24 - 505.25 -;; Symbols 505.26 - 505.27 -(deftest Symbols 505.28 - (is (= 'abc (symbol "abc"))) 505.29 - (is (= '*+!-_? (symbol "*+!-_?"))) 505.30 - (is (= 'abc:def:ghi (symbol "abc:def:ghi"))) 505.31 - (is (= 'abc/def (symbol "abc" "def"))) 505.32 - (is (= 'abc.def/ghi (symbol "abc.def" "ghi"))) 505.33 - (is (= 'abc/def.ghi (symbol "abc" "def.ghi"))) 505.34 - (is (= 'abc:def/ghi:jkl.mno (symbol "abc:def" "ghi:jkl.mno"))) 505.35 - (is (instance? clojure.lang.Symbol 'alphabet)) 505.36 - ) 505.37 - 505.38 -;; Literals 505.39 - 505.40 -(deftest Literals 505.41 - ; 'nil 'false 'true are reserved by Clojure and are not symbols 505.42 - (is (= 'nil nil)) 505.43 - (is (= 'false false)) 505.44 - (is (= 'true true)) ) 505.45 - 505.46 -;; Strings 505.47 - 505.48 -(deftest Strings 505.49 - (is (= "abcde" (str \a \b \c \d \e))) 505.50 - (is (= "abc 505.51 - def" (str \a \b \c \newline \space \space \d \e \f))) 505.52 - ) 505.53 - 505.54 -;; Numbers 505.55 - 505.56 -(deftest Numbers 505.57 - 505.58 - ; Read Integer 505.59 - (is (instance? Integer 2147483647)) 505.60 - (is (instance? Integer +1)) 505.61 - (is (instance? Integer 1)) 505.62 - (is (instance? Integer +0)) 505.63 - (is (instance? Integer 0)) 505.64 - (is (instance? Integer -0)) 505.65 - (is (instance? Integer -1)) 505.66 - (is (instance? Integer -2147483648)) 505.67 - 505.68 - ; Read Long 505.69 - (is (instance? Long 2147483648)) 505.70 - (is (instance? Long -2147483649)) 505.71 - (is (instance? Long 9223372036854775807)) 505.72 - (is (instance? Long -9223372036854775808)) 505.73 - 505.74 - ;; Numeric constants of different types don't wash out. Regression fixed in 505.75 - ;; r1157. Previously the compiler saw 0 and 0.0 as the same constant and 505.76 - ;; caused the sequence to be built of Doubles. 505.77 - (let [x 0.0] 505.78 - (let [sequence (loop [i 0 l '()] 505.79 - (if (< i 5) 505.80 - (recur (inc i) (conj l i)) 505.81 - l))] 505.82 - (is (= [4 3 2 1 0] sequence)) 505.83 - (is (every? #(instance? Integer %) 505.84 - sequence)))) 505.85 - 505.86 - ; Read BigInteger 505.87 - (is (instance? BigInteger 9223372036854775808)) 505.88 - (is (instance? BigInteger -9223372036854775809)) 505.89 - (is (instance? BigInteger 10000000000000000000000000000000000000000000000000)) 505.90 - (is (instance? BigInteger -10000000000000000000000000000000000000000000000000)) 505.91 - 505.92 - ; Read Double 505.93 - (is (instance? Double +1.0e+1)) 505.94 - (is (instance? Double +1.e+1)) 505.95 - (is (instance? Double +1e+1)) 505.96 - 505.97 - (is (instance? Double +1.0e1)) 505.98 - (is (instance? Double +1.e1)) 505.99 - (is (instance? Double +1e1)) 505.100 - 505.101 - (is (instance? Double +1.0e-1)) 505.102 - (is (instance? Double +1.e-1)) 505.103 - (is (instance? Double +1e-1)) 505.104 - 505.105 - (is (instance? Double 1.0e+1)) 505.106 - (is (instance? Double 1.e+1)) 505.107 - (is (instance? Double 1e+1)) 505.108 - 505.109 - (is (instance? Double 1.0e1)) 505.110 - (is (instance? Double 1.e1)) 505.111 - (is (instance? Double 1e1)) 505.112 - 505.113 - (is (instance? Double 1.0e-1)) 505.114 - (is (instance? Double 1.e-1)) 505.115 - (is (instance? Double 1e-1)) 505.116 - 505.117 - (is (instance? Double -1.0e+1)) 505.118 - (is (instance? Double -1.e+1)) 505.119 - (is (instance? Double -1e+1)) 505.120 - 505.121 - (is (instance? Double -1.0e1)) 505.122 - (is (instance? Double -1.e1)) 505.123 - (is (instance? Double -1e1)) 505.124 - 505.125 - (is (instance? Double -1.0e-1)) 505.126 - (is (instance? Double -1.e-1)) 505.127 - (is (instance? Double -1e-1)) 505.128 - 505.129 - (is (instance? Double +1.0)) 505.130 - (is (instance? Double +1.)) 505.131 - 505.132 - (is (instance? Double 1.0)) 505.133 - (is (instance? Double 1.)) 505.134 - 505.135 - (is (instance? Double +0.0)) 505.136 - (is (instance? Double +0.)) 505.137 - 505.138 - (is (instance? Double 0.0)) 505.139 - (is (instance? Double 0.)) 505.140 - 505.141 - (is (instance? Double -0.0)) 505.142 - (is (instance? Double -0.)) 505.143 - 505.144 - (is (instance? Double -1.0)) 505.145 - (is (instance? Double -1.)) 505.146 - 505.147 - ; Read BigDecimal 505.148 - (is (instance? BigDecimal 9223372036854775808M)) 505.149 - (is (instance? BigDecimal -9223372036854775809M)) 505.150 - (is (instance? BigDecimal 2147483647M)) 505.151 - (is (instance? BigDecimal +1M)) 505.152 - (is (instance? BigDecimal 1M)) 505.153 - (is (instance? BigDecimal +0M)) 505.154 - (is (instance? BigDecimal 0M)) 505.155 - (is (instance? BigDecimal -0M)) 505.156 - (is (instance? BigDecimal -1M)) 505.157 - (is (instance? BigDecimal -2147483648M)) 505.158 - 505.159 - (is (instance? BigDecimal +1.0e+1M)) 505.160 - (is (instance? BigDecimal +1.e+1M)) 505.161 - (is (instance? BigDecimal +1e+1M)) 505.162 - 505.163 - (is (instance? BigDecimal +1.0e1M)) 505.164 - (is (instance? BigDecimal +1.e1M)) 505.165 - (is (instance? BigDecimal +1e1M)) 505.166 - 505.167 - (is (instance? BigDecimal +1.0e-1M)) 505.168 - (is (instance? BigDecimal +1.e-1M)) 505.169 - (is (instance? BigDecimal +1e-1M)) 505.170 - 505.171 - (is (instance? BigDecimal 1.0e+1M)) 505.172 - (is (instance? BigDecimal 1.e+1M)) 505.173 - (is (instance? BigDecimal 1e+1M)) 505.174 - 505.175 - (is (instance? BigDecimal 1.0e1M)) 505.176 - (is (instance? BigDecimal 1.e1M)) 505.177 - (is (instance? BigDecimal 1e1M)) 505.178 - 505.179 - (is (instance? BigDecimal 1.0e-1M)) 505.180 - (is (instance? BigDecimal 1.e-1M)) 505.181 - (is (instance? BigDecimal 1e-1M)) 505.182 - 505.183 - (is (instance? BigDecimal -1.0e+1M)) 505.184 - (is (instance? BigDecimal -1.e+1M)) 505.185 - (is (instance? BigDecimal -1e+1M)) 505.186 - 505.187 - (is (instance? BigDecimal -1.0e1M)) 505.188 - (is (instance? BigDecimal -1.e1M)) 505.189 - (is (instance? BigDecimal -1e1M)) 505.190 - 505.191 - (is (instance? BigDecimal -1.0e-1M)) 505.192 - (is (instance? BigDecimal -1.e-1M)) 505.193 - (is (instance? BigDecimal -1e-1M)) 505.194 - 505.195 - (is (instance? BigDecimal +1.0M)) 505.196 - (is (instance? BigDecimal +1.M)) 505.197 - 505.198 - (is (instance? BigDecimal 1.0M)) 505.199 - (is (instance? BigDecimal 1.M)) 505.200 - 505.201 - (is (instance? BigDecimal +0.0M)) 505.202 - (is (instance? BigDecimal +0.M)) 505.203 - 505.204 - (is (instance? BigDecimal 0.0M)) 505.205 - (is (instance? BigDecimal 0.M)) 505.206 - 505.207 - (is (instance? BigDecimal -0.0M)) 505.208 - (is (instance? BigDecimal -0.M)) 505.209 - 505.210 - (is (instance? BigDecimal -1.0M)) 505.211 - (is (instance? BigDecimal -1.M)) 505.212 -) 505.213 - 505.214 -;; Characters 505.215 - 505.216 -(deftest t-Characters) 505.217 - 505.218 -;; nil 505.219 - 505.220 -(deftest t-nil) 505.221 - 505.222 -;; Booleans 505.223 - 505.224 -(deftest t-Booleans) 505.225 - 505.226 -;; Keywords 505.227 - 505.228 -(deftest t-Keywords 505.229 - (is (= :abc (keyword "abc"))) 505.230 - (is (= :abc (keyword 'abc))) 505.231 - (is (= :*+!-_? (keyword "*+!-_?"))) 505.232 - (is (= :abc:def:ghi (keyword "abc:def:ghi"))) 505.233 - (is (= :abc/def (keyword "abc" "def"))) 505.234 - (is (= :abc/def (keyword 'abc/def))) 505.235 - (is (= :abc.def/ghi (keyword "abc.def" "ghi"))) 505.236 - (is (= :abc/def.ghi (keyword "abc" "def.ghi"))) 505.237 - (is (= :abc:def/ghi:jkl.mno (keyword "abc:def" "ghi:jkl.mno"))) 505.238 - (is (instance? clojure.lang.Keyword :alphabet)) 505.239 - ) 505.240 - 505.241 -(deftest reading-keywords 505.242 - (are [x y] (= x (read-string y)) 505.243 - :foo ":foo" 505.244 - :foo/bar ":foo/bar" 505.245 - :user/foo "::foo") 505.246 - (are [err msg form] (thrown-with-msg? err msg (read-string form)) 505.247 - Exception #"Invalid token: foo:" "foo:" 505.248 - Exception #"Invalid token: :bar/" ":bar/" 505.249 - Exception #"Invalid token: ::does.not/exist" "::does.not/exist")) 505.250 -;; Lists 505.251 - 505.252 -(deftest t-Lists) 505.253 - 505.254 -;; Vectors 505.255 - 505.256 -(deftest t-Vectors) 505.257 - 505.258 -;; Maps 505.259 - 505.260 -(deftest t-Maps) 505.261 - 505.262 -;; Sets 505.263 - 505.264 -(deftest t-Sets) 505.265 - 505.266 -;; Macro characters 505.267 - 505.268 -;; Quote (') 505.269 - 505.270 -(deftest t-Quote) 505.271 - 505.272 -;; Character (\) 505.273 - 505.274 -(deftest t-Character) 505.275 - 505.276 -;; Comment (;) 505.277 - 505.278 -(deftest t-Comment) 505.279 - 505.280 -;; Meta (^) 505.281 - 505.282 -(deftest t-Meta) 505.283 - 505.284 -;; Deref (@) 505.285 - 505.286 -(deftest t-Deref) 505.287 - 505.288 -;; Dispatch (#) 505.289 - 505.290 -;; #{} - see Sets above 505.291 - 505.292 -;; Regex patterns (#"pattern") 505.293 - 505.294 -(deftest t-Regex) 505.295 - 505.296 -;; Metadata (#^) 505.297 - 505.298 -(deftest t-Metadata) 505.299 - 505.300 -;; Var-quote (#') 505.301 - 505.302 -(deftest t-Var-quote) 505.303 - 505.304 -;; Anonymous function literal (#()) 505.305 - 505.306 -(deftest t-Anonymouns-function-literal) 505.307 - 505.308 -;; Syntax-quote (`, note, the "backquote" character), Unquote (~) and 505.309 -;; Unquote-splicing (~@) 505.310 - 505.311 -(deftest t-Syntax-quote 505.312 - (are [x y] (= x y) 505.313 - `() () ; was NPE before SVN r1337 505.314 - )) 505.315 - 505.316 -;; (read) 505.317 -;; (read stream) 505.318 -;; (read stream eof-is-error) 505.319 -;; (read stream eof-is-error eof-value) 505.320 -;; (read stream eof-is-error eof-value is-recursive) 505.321 - 505.322 -(deftest t-read)
506.1 --- a/src/clojure/test_clojure/refs.clj Sat Aug 21 06:25:44 2010 -0400 506.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 506.3 @@ -1,22 +0,0 @@ 506.4 -; Copyright (c) Rich Hickey. All rights reserved. 506.5 -; The use and distribution terms for this software are covered by the 506.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 506.7 -; which can be found in the file epl-v10.html at the root of this distribution. 506.8 -; By using this software in any fashion, you are agreeing to be bound by 506.9 -; the terms of this license. 506.10 -; You must not remove this notice, or any other, from this software. 506.11 - 506.12 -; Author: Frantisek Sodomka 506.13 - 506.14 - 506.15 -(ns clojure.test-clojure.refs 506.16 - (:use clojure.test)) 506.17 - 506.18 -; http://clojure.org/refs 506.19 - 506.20 -; ref 506.21 -; deref, @-reader-macro 506.22 -; dosync io! 506.23 -; ensure ref-set alter commute 506.24 -; set-validator get-validator 506.25 -
507.1 --- a/src/clojure/test_clojure/repl.clj Sat Aug 21 06:25:44 2010 -0400 507.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 507.3 @@ -1,30 +0,0 @@ 507.4 -(ns clojure.test-clojure.repl 507.5 - (:use clojure.test 507.6 - clojure.repl 507.7 - clojure.test-clojure.repl.example)) 507.8 - 507.9 -(deftest test-source 507.10 - (is (= "(defn foo [])" (source-fn 'clojure.test-clojure.repl.example/foo))) 507.11 - (is (= "(defn foo [])\n" (with-out-str (source clojure.test-clojure.repl.example/foo)))) 507.12 - (is (nil? (source-fn 'non-existent-fn)))) 507.13 - 507.14 -(deftest test-dir 507.15 - (is (thrown? Exception (dir-fn 'non-existent-ns))) 507.16 - (is (= '[bar foo] (dir-fn 'clojure.test-clojure.repl.example))) 507.17 - (is (= "bar\nfoo\n" (with-out-str (dir clojure.test-clojure.repl.example))))) 507.18 - 507.19 -(deftest test-apropos 507.20 - (testing "with a regular expression" 507.21 - (is (= '[defmacro] (apropos #"^defmacro$"))) 507.22 - (is (some #{'defmacro} (apropos #"def.acr."))) 507.23 - (is (= [] (apropos #"nothing-has-this-name")))) 507.24 - 507.25 - (testing "with a string" 507.26 - (is (some #{'defmacro} (apropos "defmacro"))) 507.27 - (is (some #{'defmacro} (apropos "efmac"))) 507.28 - (is (= [] (apropos "nothing-has-this-name")))) 507.29 - 507.30 - (testing "with a symbol" 507.31 - (is (some #{'defmacro} (apropos 'defmacro))) 507.32 - (is (some #{'defmacro} (apropos 'efmac))) 507.33 - (is (= [] (apropos 'nothing-has-this-name)))))
508.1 --- a/src/clojure/test_clojure/repl/example.clj Sat Aug 21 06:25:44 2010 -0400 508.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 508.3 @@ -1,5 +0,0 @@ 508.4 -(ns clojure.test-clojure.repl.example) 508.5 - 508.6 -;; sample namespace for repl tests, don't add anything here 508.7 -(defn foo []) 508.8 -(defn bar [])
509.1 --- a/src/clojure/test_clojure/rt.clj Sat Aug 21 06:25:44 2010 -0400 509.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 509.3 @@ -1,111 +0,0 @@ 509.4 -; Copyright (c) Rich Hickey. All rights reserved. 509.5 -; The use and distribution terms for this software are covered by the 509.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 509.7 -; which can be found in the file epl-v10.html at the root of this distribution. 509.8 -; By using this software in any fashion, you are agreeing to be bound by 509.9 -; the terms of this license. 509.10 -; You must not remove this notice, or any other, from this software. 509.11 - 509.12 -; Author: Stuart Halloway 509.13 - 509.14 -(ns clojure.test-clojure.rt 509.15 - (:use clojure.test clojure.test-clojure.helpers)) 509.16 - 509.17 -(defmacro with-err-print-writer 509.18 - "Evaluate with err pointing to a temporary PrintWriter, and 509.19 - return err contents as a string." 509.20 - [& body] 509.21 - `(let [s# (java.io.StringWriter.) 509.22 - p# (java.io.PrintWriter. s#)] 509.23 - (binding [*err* p#] 509.24 - ~@body 509.25 - (str s#)))) 509.26 - 509.27 -(defmacro with-err-string-writer 509.28 - "Evaluate with err pointing to a temporary StringWriter, and 509.29 - return err contents as a string." 509.30 - [& body] 509.31 - `(let [s# (java.io.StringWriter.)] 509.32 - (binding [*err* s#] 509.33 - ~@body 509.34 - (str s#)))) 509.35 - 509.36 -(defmacro should-print-err-message 509.37 - "Turn on all warning flags, and test that error message prints 509.38 - correctly for all semi-reasonable bindings of *err*." 509.39 - [msg-re form] 509.40 - `(binding [*warn-on-reflection* true] 509.41 - (is (re-matches ~msg-re (with-err-string-writer (eval-in-temp-ns ~form)))) 509.42 - (is (re-matches ~msg-re (with-err-print-writer (eval-in-temp-ns ~form)))))) 509.43 - 509.44 -(defn bare-rt-print 509.45 - "Return string RT would print prior to print-initialize" 509.46 - [x] 509.47 - (with-out-str 509.48 - (try 509.49 - (push-thread-bindings {#'clojure.core/print-initialized false}) 509.50 - (clojure.lang.RT/print x *out*) 509.51 - (finally 509.52 - (pop-thread-bindings))))) 509.53 - 509.54 -(deftest rt-print-prior-to-print-initialize 509.55 - (testing "pattern literals" 509.56 - (is (= "#\"foo\"" (bare-rt-print #"foo"))))) 509.57 - 509.58 -(deftest error-messages 509.59 - (testing "binding a core var that already refers to something" 509.60 - (should-print-err-message 509.61 - #"WARNING: prefers already refers to: #'clojure.core/prefers in namespace: .*\r?\n" 509.62 - (defn prefers [] (throw (RuntimeException. "rebound!"))))) 509.63 - (testing "reflection cannot resolve field" 509.64 - (should-print-err-message 509.65 - #"Reflection warning, NO_SOURCE_PATH:\d+ - reference to field blah can't be resolved\.\r?\n" 509.66 - (defn foo [x] (.blah x)))) 509.67 - (testing "reflection cannot resolve instance method" 509.68 - (should-print-err-message 509.69 - #"Reflection warning, NO_SOURCE_PATH:\d+ - call to zap can't be resolved\.\r?\n" 509.70 - (defn foo [x] (.zap x 1)))) 509.71 - (testing "reflection cannot resolve static method" 509.72 - (should-print-err-message 509.73 - #"Reflection warning, NO_SOURCE_PATH:\d+ - call to valueOf can't be resolved\.\r?\n" 509.74 - (defn foo [] (Integer/valueOf #"boom")))) 509.75 - (testing "reflection cannot resolve constructor" 509.76 - (should-print-err-message 509.77 - #"Reflection warning, NO_SOURCE_PATH:\d+ - call to java.lang.String ctor can't be resolved\.\r?\n" 509.78 - (defn foo [] (String. 1 2 3))))) 509.79 - 509.80 -(def example-var) 509.81 -(deftest binding-root-clears-macro-metadata 509.82 - (alter-meta! #'example-var assoc :macro true) 509.83 - (is (contains? (meta #'example-var) :macro)) 509.84 - (.bindRoot #'example-var 0) 509.85 - (is (not (contains? (meta #'example-var) :macro)))) 509.86 - 509.87 -(deftest last-var-wins-for-core 509.88 - (testing "you can replace a core name, with warning" 509.89 - (let [ns (temp-ns) 509.90 - replacement (gensym)] 509.91 - (with-err-string-writer (intern ns 'prefers replacement)) 509.92 - (is (= replacement @('prefers (ns-publics ns)))))) 509.93 - (testing "you can replace a name you defined before" 509.94 - (let [ns (temp-ns) 509.95 - s (gensym) 509.96 - v1 (intern ns 'foo s) 509.97 - v2 (intern ns 'bar s)] 509.98 - (with-err-string-writer (.refer ns 'flatten v1)) 509.99 - (.refer ns 'flatten v2) 509.100 - (is (= v2 (ns-resolve ns 'flatten))))) 509.101 - (testing "you cannot intern over an existing non-core name" 509.102 - (let [ns (temp-ns 'clojure.set) 509.103 - replacement (gensym)] 509.104 - (is (thrown? IllegalStateException 509.105 - (intern ns 'subset? replacement))) 509.106 - (is (nil? ('subset? (ns-publics ns)))) 509.107 - (is (= #'clojure.set/subset? ('subset? (ns-refers ns)))))) 509.108 - (testing "you cannot refer over an existing non-core name" 509.109 - (let [ns (temp-ns 'clojure.set) 509.110 - replacement (gensym)] 509.111 - (is (thrown? IllegalStateException 509.112 - (.refer ns 'subset? #'clojure.set/intersection))) 509.113 - (is (nil? ('subset? (ns-publics ns)))) 509.114 - (is (= #'clojure.set/subset? ('subset? (ns-refers ns)))))))
510.1 --- a/src/clojure/test_clojure/sequences.clj Sat Aug 21 06:25:44 2010 -0400 510.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 510.3 @@ -1,1162 +0,0 @@ 510.4 -; Copyright (c) Rich Hickey. All rights reserved. 510.5 -; The use and distribution terms for this software are covered by the 510.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 510.7 -; which can be found in the file epl-v10.html at the root of this distribution. 510.8 -; By using this software in any fashion, you are agreeing to be bound by 510.9 -; the terms of this license. 510.10 -; You must not remove this notice, or any other, from this software. 510.11 - 510.12 -; Author: Frantisek Sodomka 510.13 -; Contributors: Stuart Halloway 510.14 - 510.15 -(ns clojure.test-clojure.sequences 510.16 - (:use clojure.test)) 510.17 - 510.18 -;; *** Tests *** 510.19 - 510.20 -; TODO: 510.21 -; apply, map, filter, remove 510.22 -; and more... 510.23 - 510.24 -(deftest test-reduce-from-chunked-into-unchunked 510.25 - (= [1 2 \a \b] (into [] (concat [1 2] "ab")))) 510.26 - 510.27 -(deftest test-reduce 510.28 - (let [int+ (fn [a b] (+ (int a) (int b))) 510.29 - arange (range 100) ;; enough to cross nodes 510.30 - avec (into [] arange) 510.31 - alist (into () arange) 510.32 - obj-array (into-array arange) 510.33 - int-array (into-array Integer/TYPE arange) 510.34 - long-array (into-array Long/TYPE arange) 510.35 - float-array (into-array Float/TYPE arange) 510.36 - char-array (into-array Character/TYPE (map char arange)) 510.37 - double-array (into-array Double/TYPE arange) 510.38 - byte-array (into-array Byte/TYPE (map byte arange)) 510.39 - int-vec (into (vector-of :int) arange) 510.40 - long-vec (into (vector-of :long) arange) 510.41 - float-vec (into (vector-of :float) arange) 510.42 - char-vec (into (vector-of :char) (map char arange)) 510.43 - double-vec (into (vector-of :double) arange) 510.44 - byte-vec (into (vector-of :byte) (map byte arange)) 510.45 - all-true (into-array Boolean/TYPE (repeat 10 true))] 510.46 - (is (= 4950 510.47 - (reduce + arange) 510.48 - (reduce + avec) 510.49 - (reduce + alist) 510.50 - (reduce + obj-array) 510.51 - (reduce + int-array) 510.52 - (reduce + long-array) 510.53 - (reduce + float-array) 510.54 - (reduce int+ char-array) 510.55 - (reduce + double-array) 510.56 - (reduce int+ byte-array) 510.57 - (reduce + int-vec) 510.58 - (reduce + long-vec) 510.59 - (reduce + float-vec) 510.60 - (reduce int+ char-vec) 510.61 - (reduce + double-vec) 510.62 - (reduce int+ byte-vec))) 510.63 - (is (= 4951 510.64 - (reduce + 1 arange) 510.65 - (reduce + 1 avec) 510.66 - (reduce + 1 alist) 510.67 - (reduce + 1 obj-array) 510.68 - (reduce + 1 int-array) 510.69 - (reduce + 1 long-array) 510.70 - (reduce + 1 float-array) 510.71 - (reduce int+ 1 char-array) 510.72 - (reduce + 1 double-array) 510.73 - (reduce int+ 1 byte-array) 510.74 - (reduce + 1 int-vec) 510.75 - (reduce + 1 long-vec) 510.76 - (reduce + 1 float-vec) 510.77 - (reduce int+ 1 char-vec) 510.78 - (reduce + 1 double-vec) 510.79 - (reduce int+ 1 byte-vec))) 510.80 - (is (= true 510.81 - (reduce #(and %1 %2) all-true) 510.82 - (reduce #(and %1 %2) true all-true))))) 510.83 - 510.84 -(deftest test-equality 510.85 - ; lazy sequences 510.86 - (are [x y] (= x y) 510.87 - ; fixed SVN 1288 - LazySeq and EmptyList equals/equiv 510.88 - ; http://groups.google.com/group/clojure/browse_frm/thread/286d807be9cae2a5# 510.89 - (map inc nil) () 510.90 - (map inc ()) () 510.91 - (map inc []) () 510.92 - (map inc #{}) () 510.93 - (map inc {}) () )) 510.94 - 510.95 - 510.96 -(deftest test-lazy-seq 510.97 - (are [x] (seq? x) 510.98 - (lazy-seq nil) 510.99 - (lazy-seq []) 510.100 - (lazy-seq [1 2])) 510.101 - 510.102 - (are [x y] (= x y) 510.103 - (lazy-seq nil) () 510.104 - (lazy-seq [nil]) '(nil) 510.105 - 510.106 - (lazy-seq ()) () 510.107 - (lazy-seq []) () 510.108 - (lazy-seq #{}) () 510.109 - (lazy-seq {}) () 510.110 - (lazy-seq "") () 510.111 - (lazy-seq (into-array [])) () 510.112 - 510.113 - (lazy-seq (list 1 2)) '(1 2) 510.114 - (lazy-seq [1 2]) '(1 2) 510.115 - (lazy-seq (sorted-set 1 2)) '(1 2) 510.116 - (lazy-seq (sorted-map :a 1 :b 2)) '([:a 1] [:b 2]) 510.117 - (lazy-seq "abc") '(\a \b \c) 510.118 - (lazy-seq (into-array [1 2])) '(1 2) )) 510.119 - 510.120 - 510.121 -(deftest test-seq 510.122 - (is (not (seq? (seq [])))) 510.123 - (is (seq? (seq [1 2]))) 510.124 - 510.125 - (are [x y] (= x y) 510.126 - (seq nil) nil 510.127 - (seq [nil]) '(nil) 510.128 - 510.129 - (seq ()) nil 510.130 - (seq []) nil 510.131 - (seq #{}) nil 510.132 - (seq {}) nil 510.133 - (seq "") nil 510.134 - (seq (into-array [])) nil 510.135 - 510.136 - (seq (list 1 2)) '(1 2) 510.137 - (seq [1 2]) '(1 2) 510.138 - (seq (sorted-set 1 2)) '(1 2) 510.139 - (seq (sorted-map :a 1 :b 2)) '([:a 1] [:b 2]) 510.140 - (seq "abc") '(\a \b \c) 510.141 - (seq (into-array [1 2])) '(1 2) )) 510.142 - 510.143 - 510.144 -(deftest test-cons 510.145 - (is (thrown? IllegalArgumentException (cons 1 2))) 510.146 - (are [x y] (= x y) 510.147 - (cons 1 nil) '(1) 510.148 - (cons nil nil) '(nil) 510.149 - 510.150 - (cons \a nil) '(\a) 510.151 - (cons \a "") '(\a) 510.152 - (cons \a "bc") '(\a \b \c) 510.153 - 510.154 - (cons 1 ()) '(1) 510.155 - (cons 1 '(2 3)) '(1 2 3) 510.156 - 510.157 - (cons 1 []) [1] 510.158 - (cons 1 [2 3]) [1 2 3] 510.159 - 510.160 - (cons 1 #{}) '(1) 510.161 - (cons 1 (sorted-set 2 3)) '(1 2 3) 510.162 - 510.163 - (cons 1 (into-array [])) '(1) 510.164 - (cons 1 (into-array [2 3])) '(1 2 3) )) 510.165 - 510.166 - 510.167 -(deftest test-empty 510.168 - (are [x y] (and (= (empty x) y) 510.169 - (= (class (empty x)) (class y))) 510.170 - nil nil 510.171 - 510.172 - () () 510.173 - '(1 2) () 510.174 - 510.175 - [] [] 510.176 - [1 2] [] 510.177 - 510.178 - {} {} 510.179 - {:a 1 :b 2} {} 510.180 - 510.181 - (sorted-map) (sorted-map) 510.182 - (sorted-map :a 1 :b 2) (sorted-map) 510.183 - 510.184 - #{} #{} 510.185 - #{1 2} #{} 510.186 - 510.187 - (sorted-set) (sorted-set) 510.188 - (sorted-set 1 2) (sorted-set) 510.189 - 510.190 - (seq ()) nil ; (seq ()) => nil 510.191 - (seq '(1 2)) () 510.192 - 510.193 - (seq []) nil ; (seq []) => nil 510.194 - (seq [1 2]) () 510.195 - 510.196 - (seq "") nil ; (seq "") => nil 510.197 - (seq "ab") () 510.198 - 510.199 - (lazy-seq ()) () 510.200 - (lazy-seq '(1 2)) () 510.201 - 510.202 - (lazy-seq []) () 510.203 - (lazy-seq [1 2]) () 510.204 - 510.205 - ; non-coll, non-seq => nil 510.206 - 42 nil 510.207 - 1.2 nil 510.208 - "abc" nil )) 510.209 - 510.210 -;Tests that the comparator is preservered 510.211 -;The first element should be the same in each set if preserved. 510.212 -(deftest test-empty-sorted 510.213 - (let [inv-compare (comp - compare)] 510.214 - (are [x y] (= (first (into (empty x) x)) 510.215 - (first y)) 510.216 - (sorted-set 1 2 3) (sorted-set 1 2 3) 510.217 - (sorted-set-by inv-compare 1 2 3) (sorted-set-by inv-compare 1 2 3) 510.218 - 510.219 - (sorted-map 1 :a 2 :b 3 :c) (sorted-map 1 :a 2 :b 3 :c) 510.220 - (sorted-map-by inv-compare 1 :a 2 :b 3 :c) (sorted-map-by inv-compare 1 :a 2 :b 3 :c)))) 510.221 - 510.222 - 510.223 -(deftest test-not-empty 510.224 - ; empty coll/seq => nil 510.225 - (are [x] (= (not-empty x) nil) 510.226 - () 510.227 - [] 510.228 - {} 510.229 - #{} 510.230 - (seq ()) 510.231 - (seq []) 510.232 - (lazy-seq ()) 510.233 - (lazy-seq []) ) 510.234 - 510.235 - ; non-empty coll/seq => identity 510.236 - (are [x] (and (= (not-empty x) x) 510.237 - (= (class (not-empty x)) (class x))) 510.238 - '(1 2) 510.239 - [1 2] 510.240 - {:a 1} 510.241 - #{1 2} 510.242 - (seq '(1 2)) 510.243 - (seq [1 2]) 510.244 - (lazy-seq '(1 2)) 510.245 - (lazy-seq [1 2]) )) 510.246 - 510.247 - 510.248 -(deftest test-first 510.249 - (is (thrown? IllegalArgumentException (first))) 510.250 - (is (thrown? IllegalArgumentException (first true))) 510.251 - (is (thrown? IllegalArgumentException (first false))) 510.252 - (is (thrown? IllegalArgumentException (first 1))) 510.253 - (is (thrown? IllegalArgumentException (first 1 2))) 510.254 - (is (thrown? IllegalArgumentException (first \a))) 510.255 - (is (thrown? IllegalArgumentException (first 's))) 510.256 - (is (thrown? IllegalArgumentException (first :k))) 510.257 - (are [x y] (= x y) 510.258 - (first nil) nil 510.259 - 510.260 - ; string 510.261 - (first "") nil 510.262 - (first "a") \a 510.263 - (first "abc") \a 510.264 - 510.265 - ; list 510.266 - (first ()) nil 510.267 - (first '(1)) 1 510.268 - (first '(1 2 3)) 1 510.269 - 510.270 - (first '(nil)) nil 510.271 - (first '(1 nil)) 1 510.272 - (first '(nil 2)) nil 510.273 - (first '(())) () 510.274 - (first '(() nil)) () 510.275 - (first '(() 2 nil)) () 510.276 - 510.277 - ; vector 510.278 - (first []) nil 510.279 - (first [1]) 1 510.280 - (first [1 2 3]) 1 510.281 - 510.282 - (first [nil]) nil 510.283 - (first [1 nil]) 1 510.284 - (first [nil 2]) nil 510.285 - (first [[]]) [] 510.286 - (first [[] nil]) [] 510.287 - (first [[] 2 nil]) [] 510.288 - 510.289 - ; set 510.290 - (first #{}) nil 510.291 - (first #{1}) 1 510.292 - (first (sorted-set 1 2 3)) 1 510.293 - 510.294 - (first #{nil}) nil 510.295 - (first (sorted-set 1 nil)) nil 510.296 - (first (sorted-set nil 2)) nil 510.297 - (first #{#{}}) #{} 510.298 - (first (sorted-set #{} nil)) nil 510.299 - ;(first (sorted-set #{} 2 nil)) nil 510.300 - 510.301 - ; map 510.302 - (first {}) nil 510.303 - (first (sorted-map :a 1)) '(:a 1) 510.304 - (first (sorted-map :a 1 :b 2 :c 3)) '(:a 1) 510.305 - 510.306 - ; array 510.307 - (first (into-array [])) nil 510.308 - (first (into-array [1])) 1 510.309 - (first (into-array [1 2 3])) 1 510.310 - (first (to-array [nil])) nil 510.311 - (first (to-array [1 nil])) 1 510.312 - (first (to-array [nil 2])) nil )) 510.313 - 510.314 - 510.315 -(deftest test-next 510.316 - (is (thrown? IllegalArgumentException (next))) 510.317 - (is (thrown? IllegalArgumentException (next true))) 510.318 - (is (thrown? IllegalArgumentException (next false))) 510.319 - (is (thrown? IllegalArgumentException (next 1))) 510.320 - (is (thrown? IllegalArgumentException (next 1 2))) 510.321 - (is (thrown? IllegalArgumentException (next \a))) 510.322 - (is (thrown? IllegalArgumentException (next 's))) 510.323 - (is (thrown? IllegalArgumentException (next :k))) 510.324 - (are [x y] (= x y) 510.325 - (next nil) nil 510.326 - 510.327 - ; string 510.328 - (next "") nil 510.329 - (next "a") nil 510.330 - (next "abc") '(\b \c) 510.331 - 510.332 - ; list 510.333 - (next ()) nil 510.334 - (next '(1)) nil 510.335 - (next '(1 2 3)) '(2 3) 510.336 - 510.337 - (next '(nil)) nil 510.338 - (next '(1 nil)) '(nil) 510.339 - (next '(1 ())) '(()) 510.340 - (next '(nil 2)) '(2) 510.341 - (next '(())) nil 510.342 - (next '(() nil)) '(nil) 510.343 - (next '(() 2 nil)) '(2 nil) 510.344 - 510.345 - ; vector 510.346 - (next []) nil 510.347 - (next [1]) nil 510.348 - (next [1 2 3]) [2 3] 510.349 - 510.350 - (next [nil]) nil 510.351 - (next [1 nil]) [nil] 510.352 - (next [1 []]) [[]] 510.353 - (next [nil 2]) [2] 510.354 - (next [[]]) nil 510.355 - (next [[] nil]) [nil] 510.356 - (next [[] 2 nil]) [2 nil] 510.357 - 510.358 - ; set 510.359 - (next #{}) nil 510.360 - (next #{1}) nil 510.361 - (next (sorted-set 1 2 3)) '(2 3) 510.362 - 510.363 - (next #{nil}) nil 510.364 - (next (sorted-set 1 nil)) '(1) 510.365 - (next (sorted-set nil 2)) '(2) 510.366 - (next #{#{}}) nil 510.367 - (next (sorted-set #{} nil)) '(#{}) 510.368 - ;(next (sorted-set #{} 2 nil)) #{} 510.369 - 510.370 - ; map 510.371 - (next {}) nil 510.372 - (next (sorted-map :a 1)) nil 510.373 - (next (sorted-map :a 1 :b 2 :c 3)) '((:b 2) (:c 3)) 510.374 - 510.375 - ; array 510.376 - (next (into-array [])) nil 510.377 - (next (into-array [1])) nil 510.378 - (next (into-array [1 2 3])) '(2 3) 510.379 - 510.380 - (next (to-array [nil])) nil 510.381 - (next (to-array [1 nil])) '(nil) 510.382 - ;(next (to-array [1 (into-array [])])) (list (into-array [])) 510.383 - (next (to-array [nil 2])) '(2) 510.384 - (next (to-array [(into-array [])])) nil 510.385 - (next (to-array [(into-array []) nil])) '(nil) 510.386 - (next (to-array [(into-array []) 2 nil])) '(2 nil) )) 510.387 - 510.388 - 510.389 -(deftest test-last 510.390 - (are [x y] (= x y) 510.391 - (last nil) nil 510.392 - 510.393 - ; list 510.394 - (last ()) nil 510.395 - (last '(1)) 1 510.396 - (last '(1 2 3)) 3 510.397 - 510.398 - (last '(nil)) nil 510.399 - (last '(1 nil)) nil 510.400 - (last '(nil 2)) 2 510.401 - (last '(())) () 510.402 - (last '(() nil)) nil 510.403 - (last '(() 2 nil)) nil 510.404 - 510.405 - ; vector 510.406 - (last []) nil 510.407 - (last [1]) 1 510.408 - (last [1 2 3]) 3 510.409 - 510.410 - (last [nil]) nil 510.411 - (last [1 nil]) nil 510.412 - (last [nil 2]) 2 510.413 - (last [[]]) [] 510.414 - (last [[] nil]) nil 510.415 - (last [[] 2 nil]) nil 510.416 - 510.417 - ; set 510.418 - (last #{}) nil 510.419 - (last #{1}) 1 510.420 - (last (sorted-set 1 2 3)) 3 510.421 - 510.422 - (last #{nil}) nil 510.423 - (last (sorted-set 1 nil)) 1 510.424 - (last (sorted-set nil 2)) 2 510.425 - (last #{#{}}) #{} 510.426 - (last (sorted-set #{} nil)) #{} 510.427 - ;(last (sorted-set #{} 2 nil)) nil 510.428 - 510.429 - ; map 510.430 - (last {}) nil 510.431 - (last (sorted-map :a 1)) [:a 1] 510.432 - (last (sorted-map :a 1 :b 2 :c 3)) [:c 3] 510.433 - 510.434 - ; string 510.435 - (last "") nil 510.436 - (last "a") \a 510.437 - (last "abc") \c 510.438 - 510.439 - ; array 510.440 - (last (into-array [])) nil 510.441 - (last (into-array [1])) 1 510.442 - (last (into-array [1 2 3])) 3 510.443 - (last (to-array [nil])) nil 510.444 - (last (to-array [1 nil])) nil 510.445 - (last (to-array [nil 2])) 2 )) 510.446 - 510.447 - 510.448 -;; (ffirst coll) = (first (first coll)) 510.449 -;; 510.450 -(deftest test-ffirst 510.451 - (is (thrown? IllegalArgumentException (ffirst))) 510.452 - (are [x y] (= x y) 510.453 - (ffirst nil) nil 510.454 - 510.455 - (ffirst ()) nil 510.456 - (ffirst '((1 2) (3 4))) 1 510.457 - 510.458 - (ffirst []) nil 510.459 - (ffirst [[1 2] [3 4]]) 1 510.460 - 510.461 - (ffirst {}) nil 510.462 - (ffirst {:a 1}) :a 510.463 - 510.464 - (ffirst #{}) nil 510.465 - (ffirst #{[1 2]}) 1 )) 510.466 - 510.467 - 510.468 -;; (fnext coll) = (first (next coll)) = (second coll) 510.469 -;; 510.470 -(deftest test-fnext 510.471 - (is (thrown? IllegalArgumentException (fnext))) 510.472 - (are [x y] (= x y) 510.473 - (fnext nil) nil 510.474 - 510.475 - (fnext ()) nil 510.476 - (fnext '(1)) nil 510.477 - (fnext '(1 2 3 4)) 2 510.478 - 510.479 - (fnext []) nil 510.480 - (fnext [1]) nil 510.481 - (fnext [1 2 3 4]) 2 510.482 - 510.483 - (fnext {}) nil 510.484 - (fnext (sorted-map :a 1)) nil 510.485 - (fnext (sorted-map :a 1 :b 2)) [:b 2] 510.486 - 510.487 - (fnext #{}) nil 510.488 - (fnext #{1}) nil 510.489 - (fnext (sorted-set 1 2 3 4)) 2 )) 510.490 - 510.491 - 510.492 -;; (nfirst coll) = (next (first coll)) 510.493 -;; 510.494 -(deftest test-nfirst 510.495 - (is (thrown? IllegalArgumentException (nfirst))) 510.496 - (are [x y] (= x y) 510.497 - (nfirst nil) nil 510.498 - 510.499 - (nfirst ()) nil 510.500 - (nfirst '((1 2 3) (4 5 6))) '(2 3) 510.501 - 510.502 - (nfirst []) nil 510.503 - (nfirst [[1 2 3] [4 5 6]]) '(2 3) 510.504 - 510.505 - (nfirst {}) nil 510.506 - (nfirst {:a 1}) '(1) 510.507 - 510.508 - (nfirst #{}) nil 510.509 - (nfirst #{[1 2]}) '(2) )) 510.510 - 510.511 - 510.512 -;; (nnext coll) = (next (next coll)) 510.513 -;; 510.514 -(deftest test-nnext 510.515 - (is (thrown? IllegalArgumentException (nnext))) 510.516 - (are [x y] (= x y) 510.517 - (nnext nil) nil 510.518 - 510.519 - (nnext ()) nil 510.520 - (nnext '(1)) nil 510.521 - (nnext '(1 2)) nil 510.522 - (nnext '(1 2 3 4)) '(3 4) 510.523 - 510.524 - (nnext []) nil 510.525 - (nnext [1]) nil 510.526 - (nnext [1 2]) nil 510.527 - (nnext [1 2 3 4]) '(3 4) 510.528 - 510.529 - (nnext {}) nil 510.530 - (nnext (sorted-map :a 1)) nil 510.531 - (nnext (sorted-map :a 1 :b 2)) nil 510.532 - (nnext (sorted-map :a 1 :b 2 :c 3 :d 4)) '([:c 3] [:d 4]) 510.533 - 510.534 - (nnext #{}) nil 510.535 - (nnext #{1}) nil 510.536 - (nnext (sorted-set 1 2)) nil 510.537 - (nnext (sorted-set 1 2 3 4)) '(3 4) )) 510.538 - 510.539 - 510.540 -(deftest test-nth 510.541 - ; maps, sets are not supported 510.542 - (is (thrown? UnsupportedOperationException (nth {} 0))) 510.543 - (is (thrown? UnsupportedOperationException (nth {:a 1 :b 2} 0))) 510.544 - (is (thrown? UnsupportedOperationException (nth #{} 0))) 510.545 - (is (thrown? UnsupportedOperationException (nth #{1 2 3} 0))) 510.546 - 510.547 - ; out of bounds 510.548 - (is (thrown? IndexOutOfBoundsException (nth '() 0))) 510.549 - (is (thrown? IndexOutOfBoundsException (nth '(1 2 3) 5))) 510.550 - (is (thrown? IndexOutOfBoundsException (nth '() -1))) 510.551 - (is (thrown? IndexOutOfBoundsException (nth '(1 2 3) -1))) 510.552 - 510.553 - (is (thrown? IndexOutOfBoundsException (nth [] 0))) 510.554 - (is (thrown? IndexOutOfBoundsException (nth [1 2 3] 5))) 510.555 - (is (thrown? IndexOutOfBoundsException (nth [] -1))) 510.556 - (is (thrown? IndexOutOfBoundsException (nth [1 2 3] -1))) ; ??? 510.557 - 510.558 - (is (thrown? IndexOutOfBoundsException (nth (into-array []) 0))) 510.559 - (is (thrown? IndexOutOfBoundsException (nth (into-array [1 2 3]) 5))) 510.560 - (is (thrown? IndexOutOfBoundsException (nth (into-array []) -1))) 510.561 - (is (thrown? IndexOutOfBoundsException (nth (into-array [1 2 3]) -1))) 510.562 - 510.563 - (is (thrown? StringIndexOutOfBoundsException (nth "" 0))) 510.564 - (is (thrown? StringIndexOutOfBoundsException (nth "abc" 5))) 510.565 - (is (thrown? StringIndexOutOfBoundsException (nth "" -1))) 510.566 - (is (thrown? StringIndexOutOfBoundsException (nth "abc" -1))) 510.567 - 510.568 - (is (thrown? IndexOutOfBoundsException (nth (java.util.ArrayList. []) 0))) 510.569 - (is (thrown? IndexOutOfBoundsException (nth (java.util.ArrayList. [1 2 3]) 5))) 510.570 - (is (thrown? IndexOutOfBoundsException (nth (java.util.ArrayList. []) -1))) ; ??? 510.571 - (is (thrown? IndexOutOfBoundsException (nth (java.util.ArrayList. [1 2 3]) -1))) ; ??? 510.572 - 510.573 - (are [x y] (= x y) 510.574 - (nth '(1) 0) 1 510.575 - (nth '(1 2 3) 0) 1 510.576 - (nth '(1 2 3 4 5) 1) 2 510.577 - (nth '(1 2 3 4 5) 4) 5 510.578 - (nth '(1 2 3) 5 :not-found) :not-found 510.579 - 510.580 - (nth [1] 0) 1 510.581 - (nth [1 2 3] 0) 1 510.582 - (nth [1 2 3 4 5] 1) 2 510.583 - (nth [1 2 3 4 5] 4) 5 510.584 - (nth [1 2 3] 5 :not-found) :not-found 510.585 - 510.586 - (nth (into-array [1]) 0) 1 510.587 - (nth (into-array [1 2 3]) 0) 1 510.588 - (nth (into-array [1 2 3 4 5]) 1) 2 510.589 - (nth (into-array [1 2 3 4 5]) 4) 5 510.590 - (nth (into-array [1 2 3]) 5 :not-found) :not-found 510.591 - 510.592 - (nth "a" 0) \a 510.593 - (nth "abc" 0) \a 510.594 - (nth "abcde" 1) \b 510.595 - (nth "abcde" 4) \e 510.596 - (nth "abc" 5 :not-found) :not-found 510.597 - 510.598 - (nth (java.util.ArrayList. [1]) 0) 1 510.599 - (nth (java.util.ArrayList. [1 2 3]) 0) 1 510.600 - (nth (java.util.ArrayList. [1 2 3 4 5]) 1) 2 510.601 - (nth (java.util.ArrayList. [1 2 3 4 5]) 4) 5 510.602 - (nth (java.util.ArrayList. [1 2 3]) 5 :not-found) :not-found ) 510.603 - 510.604 - ; regex Matchers 510.605 - (let [m (re-matcher #"(a)(b)" "ababaa")] 510.606 - (re-find m) ; => ["ab" "a" "b"] 510.607 - (are [x y] (= x y) 510.608 - (nth m 0) "ab" 510.609 - (nth m 1) "a" 510.610 - (nth m 2) "b" 510.611 - (nth m 3 :not-found) :not-found 510.612 - (nth m -1 :not-found) :not-found ) 510.613 - (is (thrown? IndexOutOfBoundsException (nth m 3))) 510.614 - (is (thrown? IndexOutOfBoundsException (nth m -1)))) 510.615 - 510.616 - (let [m (re-matcher #"c" "ababaa")] 510.617 - (re-find m) ; => nil 510.618 - (are [x y] (= x y) 510.619 - (nth m 0 :not-found) :not-found 510.620 - (nth m 2 :not-found) :not-found 510.621 - (nth m -1 :not-found) :not-found ) 510.622 - (is (thrown? IllegalStateException (nth m 0))) 510.623 - (is (thrown? IllegalStateException (nth m 2))) 510.624 - (is (thrown? IllegalStateException (nth m -1))))) 510.625 - 510.626 - 510.627 -; distinct was broken for nil & false: 510.628 -; fixed in rev 1278: 510.629 -; http://code.google.com/p/clojure/source/detail?r=1278 510.630 -; 510.631 -(deftest test-distinct 510.632 - (are [x y] (= x y) 510.633 - (distinct ()) () 510.634 - (distinct '(1)) '(1) 510.635 - (distinct '(1 2 3)) '(1 2 3) 510.636 - (distinct '(1 2 3 1 1 1)) '(1 2 3) 510.637 - (distinct '(1 1 1 2)) '(1 2) 510.638 - (distinct '(1 2 1 2)) '(1 2) 510.639 - 510.640 - (distinct []) () 510.641 - (distinct [1]) '(1) 510.642 - (distinct [1 2 3]) '(1 2 3) 510.643 - (distinct [1 2 3 1 2 2 1 1]) '(1 2 3) 510.644 - (distinct [1 1 1 2]) '(1 2) 510.645 - (distinct [1 2 1 2]) '(1 2) 510.646 - 510.647 - (distinct "") () 510.648 - (distinct "a") '(\a) 510.649 - (distinct "abc") '(\a \b \c) 510.650 - (distinct "abcabab") '(\a \b \c) 510.651 - (distinct "aaab") '(\a \b) 510.652 - (distinct "abab") '(\a \b) ) 510.653 - 510.654 - (are [x] (= (distinct [x x]) [x]) 510.655 - nil 510.656 - false true 510.657 - 0 42 510.658 - 0.0 3.14 510.659 - 2/3 510.660 - 0M 1M 510.661 - \c 510.662 - "" "abc" 510.663 - 'sym 510.664 - :kw 510.665 - () '(1 2) 510.666 - [] [1 2] 510.667 - {} {:a 1 :b 2} 510.668 - #{} #{1 2} )) 510.669 - 510.670 - 510.671 -(deftest test-interpose 510.672 - (are [x y] (= x y) 510.673 - (interpose 0 []) () 510.674 - (interpose 0 [1]) '(1) 510.675 - (interpose 0 [1 2]) '(1 0 2) 510.676 - (interpose 0 [1 2 3]) '(1 0 2 0 3) )) 510.677 - 510.678 - 510.679 -(deftest test-interleave 510.680 - (are [x y] (= x y) 510.681 - (interleave [1 2] [3 4]) '(1 3 2 4) 510.682 - 510.683 - (interleave [1] [3 4]) '(1 3) 510.684 - (interleave [1 2] [3]) '(1 3) 510.685 - 510.686 - (interleave [] [3 4]) () 510.687 - (interleave [1 2] []) () 510.688 - (interleave [] []) () )) 510.689 - 510.690 - 510.691 -(deftest test-zipmap 510.692 - (are [x y] (= x y) 510.693 - (zipmap [:a :b] [1 2]) {:a 1 :b 2} 510.694 - 510.695 - (zipmap [:a] [1 2]) {:a 1} 510.696 - (zipmap [:a :b] [1]) {:a 1} 510.697 - 510.698 - (zipmap [] [1 2]) {} 510.699 - (zipmap [:a :b] []) {} 510.700 - (zipmap [] []) {} )) 510.701 - 510.702 - 510.703 -(deftest test-concat 510.704 - (are [x y] (= x y) 510.705 - (concat) () 510.706 - 510.707 - (concat []) () 510.708 - (concat [1 2]) '(1 2) 510.709 - 510.710 - (concat [1 2] [3 4]) '(1 2 3 4) 510.711 - (concat [] [3 4]) '(3 4) 510.712 - (concat [1 2] []) '(1 2) 510.713 - (concat [] []) () 510.714 - 510.715 - (concat [1 2] [3 4] [5 6]) '(1 2 3 4 5 6) )) 510.716 - 510.717 - 510.718 -(deftest test-cycle 510.719 - (are [x y] (= x y) 510.720 - (cycle []) () 510.721 - 510.722 - (take 3 (cycle [1])) '(1 1 1) 510.723 - (take 5 (cycle [1 2 3])) '(1 2 3 1 2) 510.724 - 510.725 - (take 3 (cycle [nil])) '(nil nil nil) )) 510.726 - 510.727 - 510.728 -(deftest test-partition 510.729 - (are [x y] (= x y) 510.730 - (partition 2 [1 2 3]) '((1 2)) 510.731 - (partition 2 [1 2 3 4]) '((1 2) (3 4)) 510.732 - (partition 2 []) () 510.733 - 510.734 - (partition 2 3 [1 2 3 4 5 6 7]) '((1 2) (4 5)) 510.735 - (partition 2 3 [1 2 3 4 5 6 7 8]) '((1 2) (4 5) (7 8)) 510.736 - (partition 2 3 []) () 510.737 - 510.738 - (partition 1 []) () 510.739 - (partition 1 [1 2 3]) '((1) (2) (3)) 510.740 - 510.741 - (partition 5 [1 2 3]) () 510.742 - 510.743 -; (partition 0 [1 2 3]) (repeat nil) ; infinite sequence of nil 510.744 - (partition -1 [1 2 3]) () 510.745 - (partition -2 [1 2 3]) () )) 510.746 - 510.747 - 510.748 -(deftest test-reverse 510.749 - (are [x y] (= x y) 510.750 - (reverse nil) () ; since SVN 1294 510.751 - (reverse []) () 510.752 - (reverse [1]) '(1) 510.753 - (reverse [1 2 3]) '(3 2 1) )) 510.754 - 510.755 - 510.756 -(deftest test-take 510.757 - (are [x y] (= x y) 510.758 - (take 1 [1 2 3 4 5]) '(1) 510.759 - (take 3 [1 2 3 4 5]) '(1 2 3) 510.760 - (take 5 [1 2 3 4 5]) '(1 2 3 4 5) 510.761 - (take 9 [1 2 3 4 5]) '(1 2 3 4 5) 510.762 - 510.763 - (take 0 [1 2 3 4 5]) () 510.764 - (take -1 [1 2 3 4 5]) () 510.765 - (take -2 [1 2 3 4 5]) () )) 510.766 - 510.767 - 510.768 -(deftest test-drop 510.769 - (are [x y] (= x y) 510.770 - (drop 1 [1 2 3 4 5]) '(2 3 4 5) 510.771 - (drop 3 [1 2 3 4 5]) '(4 5) 510.772 - (drop 5 [1 2 3 4 5]) () 510.773 - (drop 9 [1 2 3 4 5]) () 510.774 - 510.775 - (drop 0 [1 2 3 4 5]) '(1 2 3 4 5) 510.776 - (drop -1 [1 2 3 4 5]) '(1 2 3 4 5) 510.777 - (drop -2 [1 2 3 4 5]) '(1 2 3 4 5) )) 510.778 - 510.779 - 510.780 -(deftest test-take-nth 510.781 - (are [x y] (= x y) 510.782 - (take-nth 1 [1 2 3 4 5]) '(1 2 3 4 5) 510.783 - (take-nth 2 [1 2 3 4 5]) '(1 3 5) 510.784 - (take-nth 3 [1 2 3 4 5]) '(1 4) 510.785 - (take-nth 4 [1 2 3 4 5]) '(1 5) 510.786 - (take-nth 5 [1 2 3 4 5]) '(1) 510.787 - (take-nth 9 [1 2 3 4 5]) '(1) 510.788 - 510.789 - ; infinite seq of 1s = (repeat 1) 510.790 - ;(take-nth 0 [1 2 3 4 5]) 510.791 - ;(take-nth -1 [1 2 3 4 5]) 510.792 - ;(take-nth -2 [1 2 3 4 5]) 510.793 - )) 510.794 - 510.795 - 510.796 -(deftest test-take-while 510.797 - (are [x y] (= x y) 510.798 - (take-while pos? []) () 510.799 - (take-while pos? [1 2 3 4]) '(1 2 3 4) 510.800 - (take-while pos? [1 2 3 -1]) '(1 2 3) 510.801 - (take-while pos? [1 -1 2 3]) '(1) 510.802 - (take-while pos? [-1 1 2 3]) () 510.803 - (take-while pos? [-1 -2 -3]) () )) 510.804 - 510.805 - 510.806 -(deftest test-drop-while 510.807 - (are [x y] (= x y) 510.808 - (drop-while pos? []) () 510.809 - (drop-while pos? [1 2 3 4]) () 510.810 - (drop-while pos? [1 2 3 -1]) '(-1) 510.811 - (drop-while pos? [1 -1 2 3]) '(-1 2 3) 510.812 - (drop-while pos? [-1 1 2 3]) '(-1 1 2 3) 510.813 - (drop-while pos? [-1 -2 -3]) '(-1 -2 -3) )) 510.814 - 510.815 - 510.816 -(deftest test-butlast 510.817 - (are [x y] (= x y) 510.818 - (butlast []) nil 510.819 - (butlast [1]) nil 510.820 - (butlast [1 2 3]) '(1 2) )) 510.821 - 510.822 - 510.823 -(deftest test-drop-last 510.824 - (are [x y] (= x y) 510.825 - ; as butlast 510.826 - (drop-last []) () 510.827 - (drop-last [1]) () 510.828 - (drop-last [1 2 3]) '(1 2) 510.829 - 510.830 - ; as butlast, but lazy 510.831 - (drop-last 1 []) () 510.832 - (drop-last 1 [1]) () 510.833 - (drop-last 1 [1 2 3]) '(1 2) 510.834 - 510.835 - (drop-last 2 []) () 510.836 - (drop-last 2 [1]) () 510.837 - (drop-last 2 [1 2 3]) '(1) 510.838 - 510.839 - (drop-last 5 []) () 510.840 - (drop-last 5 [1]) () 510.841 - (drop-last 5 [1 2 3]) () 510.842 - 510.843 - (drop-last 0 []) () 510.844 - (drop-last 0 [1]) '(1) 510.845 - (drop-last 0 [1 2 3]) '(1 2 3) 510.846 - 510.847 - (drop-last -1 []) () 510.848 - (drop-last -1 [1]) '(1) 510.849 - (drop-last -1 [1 2 3]) '(1 2 3) 510.850 - 510.851 - (drop-last -2 []) () 510.852 - (drop-last -2 [1]) '(1) 510.853 - (drop-last -2 [1 2 3]) '(1 2 3) )) 510.854 - 510.855 - 510.856 -(deftest test-split-at 510.857 - (is (vector? (split-at 2 []))) 510.858 - (is (vector? (split-at 2 [1 2 3]))) 510.859 - 510.860 - (are [x y] (= x y) 510.861 - (split-at 2 []) [() ()] 510.862 - (split-at 2 [1 2 3 4 5]) [(list 1 2) (list 3 4 5)] 510.863 - 510.864 - (split-at 5 [1 2 3]) [(list 1 2 3) ()] 510.865 - (split-at 0 [1 2 3]) [() (list 1 2 3)] 510.866 - (split-at -1 [1 2 3]) [() (list 1 2 3)] 510.867 - (split-at -5 [1 2 3]) [() (list 1 2 3)] )) 510.868 - 510.869 - 510.870 -(deftest test-split-with 510.871 - (is (vector? (split-with pos? []))) 510.872 - (is (vector? (split-with pos? [1 2 -1 0 3 4]))) 510.873 - 510.874 - (are [x y] (= x y) 510.875 - (split-with pos? []) [() ()] 510.876 - (split-with pos? [1 2 -1 0 3 4]) [(list 1 2) (list -1 0 3 4)] 510.877 - 510.878 - (split-with pos? [-1 2 3 4 5]) [() (list -1 2 3 4 5)] 510.879 - (split-with number? [1 -2 "abc" \x]) [(list 1 -2) (list "abc" \x)] )) 510.880 - 510.881 - 510.882 -(deftest test-repeat 510.883 - (is (thrown? IllegalArgumentException (repeat))) 510.884 - 510.885 - ; infinite sequence => use take 510.886 - (are [x y] (= x y) 510.887 - (take 0 (repeat 7)) () 510.888 - (take 1 (repeat 7)) '(7) 510.889 - (take 2 (repeat 7)) '(7 7) 510.890 - (take 5 (repeat 7)) '(7 7 7 7 7) ) 510.891 - 510.892 - ; limited sequence 510.893 - (are [x y] (= x y) 510.894 - (repeat 0 7) () 510.895 - (repeat 1 7) '(7) 510.896 - (repeat 2 7) '(7 7) 510.897 - (repeat 5 7) '(7 7 7 7 7) 510.898 - 510.899 - (repeat -1 7) () 510.900 - (repeat -3 7) () ) 510.901 - 510.902 - ; test different data types 510.903 - (are [x] (= (repeat 3 x) (list x x x)) 510.904 - nil 510.905 - false true 510.906 - 0 42 510.907 - 0.0 3.14 510.908 - 2/3 510.909 - 0M 1M 510.910 - \c 510.911 - "" "abc" 510.912 - 'sym 510.913 - :kw 510.914 - () '(1 2) 510.915 - [] [1 2] 510.916 - {} {:a 1 :b 2} 510.917 - #{} #{1 2} )) 510.918 - 510.919 - 510.920 -(deftest test-range 510.921 - (are [x y] (= x y) 510.922 - (range 0) () ; exclusive end! 510.923 - (range 1) '(0) 510.924 - (range 5) '(0 1 2 3 4) 510.925 - 510.926 - (range -1) () 510.927 - (range -3) () 510.928 - 510.929 - (range 2.5) '(0 1 2) 510.930 - (range 7/3) '(0 1 2) 510.931 - 510.932 - (range 0 3) '(0 1 2) 510.933 - (range 0 1) '(0) 510.934 - (range 0 0) () 510.935 - (range 0 -3) () 510.936 - 510.937 - (range 3 6) '(3 4 5) 510.938 - (range 3 4) '(3) 510.939 - (range 3 3) () 510.940 - (range 3 1) () 510.941 - (range 3 0) () 510.942 - (range 3 -2) () 510.943 - 510.944 - (range -2 5) '(-2 -1 0 1 2 3 4) 510.945 - (range -2 0) '(-2 -1) 510.946 - (range -2 -1) '(-2) 510.947 - (range -2 -2) () 510.948 - (range -2 -5) () 510.949 - 510.950 - (range 3 9 0) () 510.951 - (range 3 9 1) '(3 4 5 6 7 8) 510.952 - (range 3 9 2) '(3 5 7) 510.953 - (range 3 9 3) '(3 6) 510.954 - (range 3 9 10) '(3) 510.955 - (range 3 9 -1) () )) 510.956 - 510.957 - 510.958 -(deftest test-empty? 510.959 - (are [x] (empty? x) 510.960 - nil 510.961 - () 510.962 - (lazy-seq nil) ; => () 510.963 - [] 510.964 - {} 510.965 - #{} 510.966 - "" 510.967 - (into-array []) ) 510.968 - 510.969 - (are [x] (not (empty? x)) 510.970 - '(1 2) 510.971 - (lazy-seq [1 2]) 510.972 - [1 2] 510.973 - {:a 1 :b 2} 510.974 - #{1 2} 510.975 - "abc" 510.976 - (into-array [1 2]) )) 510.977 - 510.978 - 510.979 -(deftest test-every? 510.980 - ; always true for nil or empty coll/seq 510.981 - (are [x] (= (every? pos? x) true) 510.982 - nil 510.983 - () [] {} #{} 510.984 - (lazy-seq []) 510.985 - (into-array []) ) 510.986 - 510.987 - (are [x y] (= x y) 510.988 - true (every? pos? [1]) 510.989 - true (every? pos? [1 2]) 510.990 - true (every? pos? [1 2 3 4 5]) 510.991 - 510.992 - false (every? pos? [-1]) 510.993 - false (every? pos? [-1 -2]) 510.994 - false (every? pos? [-1 -2 3]) 510.995 - false (every? pos? [-1 2]) 510.996 - false (every? pos? [1 -2]) 510.997 - false (every? pos? [1 2 -3]) 510.998 - false (every? pos? [1 2 -3 4]) ) 510.999 - 510.1000 - (are [x y] (= x y) 510.1001 - true (every? #{:a} [:a :a]) 510.1002 -;! false (every? #{:a} [:a :b]) ; Issue 68: every? returns nil instead of false 510.1003 -;! false (every? #{:a} [:b :b]) ; http://code.google.com/p/clojure/issues/detail?id=68 510.1004 - )) 510.1005 - 510.1006 - 510.1007 -(deftest test-not-every? 510.1008 - ; always false for nil or empty coll/seq 510.1009 - (are [x] (= (not-every? pos? x) false) 510.1010 - nil 510.1011 - () [] {} #{} 510.1012 - (lazy-seq []) 510.1013 - (into-array []) ) 510.1014 - 510.1015 - (are [x y] (= x y) 510.1016 - false (not-every? pos? [1]) 510.1017 - false (not-every? pos? [1 2]) 510.1018 - false (not-every? pos? [1 2 3 4 5]) 510.1019 - 510.1020 - true (not-every? pos? [-1]) 510.1021 - true (not-every? pos? [-1 -2]) 510.1022 - true (not-every? pos? [-1 -2 3]) 510.1023 - true (not-every? pos? [-1 2]) 510.1024 - true (not-every? pos? [1 -2]) 510.1025 - true (not-every? pos? [1 2 -3]) 510.1026 - true (not-every? pos? [1 2 -3 4]) ) 510.1027 - 510.1028 - (are [x y] (= x y) 510.1029 - false (not-every? #{:a} [:a :a]) 510.1030 - true (not-every? #{:a} [:a :b]) 510.1031 - true (not-every? #{:a} [:b :b]) )) 510.1032 - 510.1033 - 510.1034 -(deftest test-not-any? 510.1035 - ; always true for nil or empty coll/seq 510.1036 - (are [x] (= (not-any? pos? x) true) 510.1037 - nil 510.1038 - () [] {} #{} 510.1039 - (lazy-seq []) 510.1040 - (into-array []) ) 510.1041 - 510.1042 - (are [x y] (= x y) 510.1043 - false (not-any? pos? [1]) 510.1044 - false (not-any? pos? [1 2]) 510.1045 - false (not-any? pos? [1 2 3 4 5]) 510.1046 - 510.1047 - true (not-any? pos? [-1]) 510.1048 - true (not-any? pos? [-1 -2]) 510.1049 - 510.1050 - false (not-any? pos? [-1 -2 3]) 510.1051 - false (not-any? pos? [-1 2]) 510.1052 - false (not-any? pos? [1 -2]) 510.1053 - false (not-any? pos? [1 2 -3]) 510.1054 - false (not-any? pos? [1 2 -3 4]) ) 510.1055 - 510.1056 - (are [x y] (= x y) 510.1057 - false (not-any? #{:a} [:a :a]) 510.1058 - false (not-any? #{:a} [:a :b]) 510.1059 - true (not-any? #{:a} [:b :b]) )) 510.1060 - 510.1061 - 510.1062 -(deftest test-some 510.1063 - ;; always nil for nil or empty coll/seq 510.1064 - (are [x] (= (some pos? x) nil) 510.1065 - nil 510.1066 - () [] {} #{} 510.1067 - (lazy-seq []) 510.1068 - (into-array [])) 510.1069 - 510.1070 - (are [x y] (= x y) 510.1071 - nil (some nil nil) 510.1072 - 510.1073 - true (some pos? [1]) 510.1074 - true (some pos? [1 2]) 510.1075 - 510.1076 - nil (some pos? [-1]) 510.1077 - nil (some pos? [-1 -2]) 510.1078 - true (some pos? [-1 2]) 510.1079 - true (some pos? [1 -2]) 510.1080 - 510.1081 - :a (some #{:a} [:a :a]) 510.1082 - :a (some #{:a} [:b :a]) 510.1083 - nil (some #{:a} [:b :b]) 510.1084 - 510.1085 - :a (some #{:a} '(:a :b)) 510.1086 - :a (some #{:a} #{:a :b}) 510.1087 - )) 510.1088 - 510.1089 -(deftest test-flatten-present 510.1090 - (are [expected nested-val] (= (flatten nested-val) expected) 510.1091 - ;simple literals 510.1092 - [] nil 510.1093 - [] 1 510.1094 - [] 'test 510.1095 - [] :keyword 510.1096 - [] 1/2 510.1097 - [] #"[\r\n]" 510.1098 - [] true 510.1099 - [] false 510.1100 - ;vectors 510.1101 - [1 2 3 4 5] [[1 2] [3 4 [5]]] 510.1102 - [1 2 3 4 5] [1 2 3 4 5] 510.1103 - [#{1 2} 3 4 5] [#{1 2} 3 4 5] 510.1104 - ;sets 510.1105 - [] #{} 510.1106 - [] #{#{1 2} 3 4 5} 510.1107 - [] #{1 2 3 4 5} 510.1108 - [] #{#{1 2} 3 4 5} 510.1109 - ;lists 510.1110 - [] '() 510.1111 - [1 2 3 4 5] `(1 2 3 4 5) 510.1112 - ;maps 510.1113 - [] {:a 1 :b 2} 510.1114 - [:a 1 :b 2] (seq {:a 1 :b 2}) 510.1115 - [] {[:a :b] 1 :c 2} 510.1116 - [:a :b 1 :c 2] (seq {[:a :b] 1 :c 2}) 510.1117 - [:a 1 2 :b 3] (seq {:a [1 2] :b 3}) 510.1118 - ;Strings 510.1119 - [] "12345" 510.1120 - [\1 \2 \3 \4 \5] (seq "12345") 510.1121 - ;fns 510.1122 - [] count 510.1123 - [count even? odd?] [count even? odd?])) 510.1124 - 510.1125 -(deftest test-group-by 510.1126 - (is (= (group-by even? [1 2 3 4 5]) 510.1127 - {false [1 3 5], true [2 4]}))) 510.1128 - 510.1129 -(deftest test-partition-by 510.1130 - (are [test-seq] (= (partition-by (comp even? count) test-seq) 510.1131 - [["a"] ["bb" "cccc" "dd"] ["eee" "f"] ["" "hh"]]) 510.1132 - ["a" "bb" "cccc" "dd" "eee" "f" "" "hh"] 510.1133 - '("a" "bb" "cccc" "dd" "eee" "f" "" "hh")) 510.1134 - (is (=(partition-by #{\a \e \i \o \u} "abcdefghijklm") 510.1135 - [[\a] [\b \c \d] [\e] [\f \g \h] [\i] [\j \k \l \m]]))) 510.1136 - 510.1137 -(deftest test-frequencies 510.1138 - (are [expected test-seq] (= (frequencies test-seq) expected) 510.1139 - {\p 2, \s 4, \i 4, \m 1} "mississippi" 510.1140 - {1 4 2 2 3 1} [1 1 1 1 2 2 3] 510.1141 - {1 4 2 2 3 1} '(1 1 1 1 2 2 3))) 510.1142 - 510.1143 -(deftest test-reductions 510.1144 - (is (= (reductions + nil) 510.1145 - [0])) 510.1146 - (is (= (reductions + [1 2 3 4 5]) 510.1147 - [1 3 6 10 15])) 510.1148 - (is (= (reductions + 10 [1 2 3 4 5]) 510.1149 - [10 11 13 16 20 25]))) 510.1150 - 510.1151 -(deftest test-rand-nth-invariants 510.1152 - (let [elt (rand-nth [:a :b :c :d])] 510.1153 - (is (#{:a :b :c :d} elt)))) 510.1154 - 510.1155 -(deftest test-partition-all 510.1156 - (is (= (partition-all 4 [1 2 3 4 5 6 7 8 9]) 510.1157 - [[1 2 3 4] [5 6 7 8] [9]])) 510.1158 - (is (= (partition-all 4 2 [1 2 3 4 5 6 7 8 9]) 510.1159 - [[1 2 3 4] [3 4 5 6] [5 6 7 8] [7 8 9] [9]]))) 510.1160 - 510.1161 -(deftest test-shuffle-invariants 510.1162 - (is (= (count (shuffle [1 2 3 4])) 4)) 510.1163 - (let [shuffled-seq (shuffle [1 2 3 4])] 510.1164 - (is (every? #{1 2 3 4} shuffled-seq)))) 510.1165 -
511.1 --- a/src/clojure/test_clojure/serialization.clj Sat Aug 21 06:25:44 2010 -0400 511.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 511.3 @@ -1,158 +0,0 @@ 511.4 -; Copyright (c) Rich Hickey. All rights reserved. 511.5 -; The use and distribution terms for this software are covered by the 511.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 511.7 -; which can be found in the file epl-v10.html at the root of this distribution. 511.8 -; By using this software in any fashion, you are agreeing to be bound by 511.9 -; the terms of this license. 511.10 -; You must not remove this notice, or any other, from this software. 511.11 - 511.12 -;; Author: Chas Emerick 511.13 -;; cemerick@snowtide.com 511.14 - 511.15 -(ns clojure.test-clojure.serialization 511.16 - (:use clojure.test) 511.17 - (:import (java.io ObjectOutputStream ObjectInputStream 511.18 - ByteArrayOutputStream ByteArrayInputStream))) 511.19 - 511.20 -(defn- serialize 511.21 - "Serializes a single object, returning a byte array." 511.22 - [v] 511.23 - (with-open [bout (ByteArrayOutputStream.) 511.24 - oos (ObjectOutputStream. bout)] 511.25 - (.writeObject oos v) 511.26 - (.flush oos) 511.27 - (.toByteArray bout))) 511.28 - 511.29 -(defn- deserialize 511.30 - "Deserializes and returns a single object from the given byte array." 511.31 - [bytes] 511.32 - (with-open [ois (-> bytes ByteArrayInputStream. ObjectInputStream.)] 511.33 - (.readObject ois))) 511.34 - 511.35 -(defrecord SerializationRecord [a b c]) 511.36 -(defstruct SerializationStruct :a :b :c) 511.37 - 511.38 -(defn- build-via-transient 511.39 - [coll] 511.40 - (persistent! 511.41 - (reduce conj! (transient coll) (map vec (partition 2 (range 1000)))))) 511.42 - 511.43 -(defn- roundtrip 511.44 - [v] 511.45 - (let [rt (-> v serialize deserialize) 511.46 - rt-seq (-> v seq serialize deserialize)] 511.47 - (and (= v rt) 511.48 - (= (seq v) (seq rt)) 511.49 - (= (seq v) rt-seq)))) 511.50 - 511.51 -(deftest sequable-serialization 511.52 - (are [val] (roundtrip val) 511.53 - ; lists and related 511.54 - (list) 511.55 - (apply list (range 10)) 511.56 - (cons 0 nil) 511.57 - (clojure.lang.Cons. 0 nil) 511.58 - 511.59 - ; vectors 511.60 - [] 511.61 - (into [] (range 10)) 511.62 - (into [] (range 25)) 511.63 - (into [] (range 100)) 511.64 - (into [] (range 500)) 511.65 - (into [] (range 1000)) 511.66 - 511.67 - ; maps 511.68 - {} 511.69 - {:a 5 :b 0} 511.70 - (apply array-map (range 100)) 511.71 - (apply hash-map (range 100)) 511.72 - 511.73 - ; sets 511.74 - #{} 511.75 - #{'a 'b 'c} 511.76 - (set (range 10)) 511.77 - (set (range 25)) 511.78 - (set (range 100)) 511.79 - (set (range 500)) 511.80 - (set (range 1000)) 511.81 - (sorted-set) 511.82 - (sorted-set 'a 'b 'c) 511.83 - (apply sorted-set (reverse (range 10))) 511.84 - (apply sorted-set (reverse (range 25))) 511.85 - (apply sorted-set (reverse (range 100))) 511.86 - (apply sorted-set (reverse (range 500))) 511.87 - (apply sorted-set (reverse (range 1000))) 511.88 - 511.89 - ; queues 511.90 - clojure.lang.PersistentQueue/EMPTY 511.91 - (into clojure.lang.PersistentQueue/EMPTY (range 50)) 511.92 - 511.93 - ; lazy seqs 511.94 - (lazy-seq nil) 511.95 - (lazy-seq (range 50)) 511.96 - 511.97 - ; transient / persistent! round-trip 511.98 - (build-via-transient []) 511.99 - (build-via-transient {}) 511.100 - (build-via-transient #{}) 511.101 - 511.102 - ; array-seqs 511.103 - (seq (make-array Object 10)) 511.104 - (seq (make-array Boolean/TYPE 10)) 511.105 - (seq (make-array Byte/TYPE 10)) 511.106 - (seq (make-array Character/TYPE 10)) 511.107 - (seq (make-array Double/TYPE 10)) 511.108 - (seq (make-array Float/TYPE 10)) 511.109 - (seq (make-array Integer/TYPE 10)) 511.110 - (seq (make-array Long/TYPE 10)) 511.111 - 511.112 - ; "records" 511.113 - (SerializationRecord. 0 :foo (range 20)) 511.114 - (struct SerializationStruct 0 :foo (range 20)) 511.115 - 511.116 - ; misc seqs 511.117 - (seq "s11n") 511.118 - (range 50) 511.119 - (rseq (apply sorted-set (reverse (range 100)))))) 511.120 - 511.121 -(deftest misc-serialization 511.122 - (are [v] (= v (-> v serialize deserialize)) 511.123 - 25/3 511.124 - :keyword 511.125 - ::namespaced-keyword 511.126 - 'symbol)) 511.127 - 511.128 -(deftest interned-serializations 511.129 - (are [v] (identical? v (-> v serialize deserialize)) 511.130 - clojure.lang.RT/DEFAULT_COMPARATOR 511.131 - 511.132 - ; namespaces just get deserialized back into the same-named ns in the present runtime 511.133 - ; (they're referred to by defrecord instances) 511.134 - *ns*)) 511.135 - 511.136 -(deftest function-serialization 511.137 - (let [capture 5] 511.138 - (are [f] (= capture ((-> f serialize deserialize))) 511.139 - (constantly 5) 511.140 - (fn [] 5) 511.141 - #(do 5) 511.142 - (constantly capture) 511.143 - (fn [] capture) 511.144 - #(do capture)))) 511.145 - 511.146 -(deftest check-unserializable-objects 511.147 - (are [t] (thrown? java.io.NotSerializableException (serialize t)) 511.148 - ;; transients 511.149 - (transient []) 511.150 - (transient {}) 511.151 - (transient #{}) 511.152 - 511.153 - ;; reference types 511.154 - (atom nil) 511.155 - (ref nil) 511.156 - (agent nil) 511.157 - #'+ 511.158 - 511.159 - ;; stateful seqs 511.160 - (enumeration-seq (java.util.Collections/enumeration (range 50))) 511.161 - (iterator-seq (.iterator (range 50))))) 511.162 \ No newline at end of file
512.1 --- a/src/clojure/test_clojure/special.clj Sat Aug 21 06:25:44 2010 -0400 512.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 512.3 @@ -1,24 +0,0 @@ 512.4 -; Copyright (c) Rich Hickey. All rights reserved. 512.5 -; The use and distribution terms for this software are covered by the 512.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 512.7 -; which can be found in the file epl-v10.html at the root of this distribution. 512.8 -; By using this software in any fashion, you are agreeing to be bound by 512.9 -; the terms of this license. 512.10 -; You must not remove this notice, or any other, from this software. 512.11 - 512.12 -; Author: Frantisek Sodomka 512.13 - 512.14 -;; 512.15 -;; Test special forms, macros and metadata 512.16 -;; 512.17 - 512.18 -(ns clojure.test-clojure.special 512.19 - (:use clojure.test)) 512.20 - 512.21 -; http://clojure.org/special_forms 512.22 - 512.23 -; let, letfn 512.24 -; quote 512.25 -; var 512.26 -; fn 512.27 -
513.1 --- a/src/clojure/test_clojure/string.clj Sat Aug 21 06:25:44 2010 -0400 513.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 513.3 @@ -1,120 +0,0 @@ 513.4 -(ns clojure.test-clojure.string 513.5 - (:require [clojure.string :as s]) 513.6 - (:use clojure.test)) 513.7 - 513.8 -(deftest t-split 513.9 - (is (= ["a" "b"] (s/split "a-b" #"-"))) 513.10 - (is (= ["a" "b-c"] (s/split "a-b-c" #"-" 2))) 513.11 - (is (vector? (s/split "abc" #"-")))) 513.12 - 513.13 -(deftest t-reverse 513.14 - (is (= "tab" (s/reverse "bat")))) 513.15 - 513.16 -(deftest t-replace 513.17 - (is (= "faabar" (s/replace "foobar" \o \a))) 513.18 - (is (= "barbarbar" (s/replace "foobarfoo" "foo" "bar"))) 513.19 - (is (= "FOObarFOO" (s/replace "foobarfoo" #"foo" s/upper-case)))) 513.20 - 513.21 -(deftest t-replace-first 513.22 - (is (= "barbarfoo" (s/replace-first "foobarfoo" "foo" "bar"))) 513.23 - (is (= "barbarfoo" (s/replace-first "foobarfoo" #"foo" "bar"))) 513.24 - (is (= "z.ology" (s/replace-first "zoology" \o \.))) 513.25 - (is (= "FOObarfoo" (s/replace-first "foobarfoo" #"foo" s/upper-case)))) 513.26 - 513.27 -(deftest t-join 513.28 - (are [x coll] (= x (s/join coll)) 513.29 - "" nil 513.30 - "" [] 513.31 - "1" [1] 513.32 - "12" [1 2]) 513.33 - (are [x sep coll] (= x (s/join sep coll)) 513.34 - "1,2,3" \, [1 2 3] 513.35 - "" \, [] 513.36 - "1" \, [1] 513.37 - "1 and-a 2 and-a 3" " and-a " [1 2 3])) 513.38 - 513.39 -(deftest t-trim-newline 513.40 - (is (= "foo" (s/trim-newline "foo\n"))) 513.41 - (is (= "foo" (s/trim-newline "foo\r\n"))) 513.42 - (is (= "foo" (s/trim-newline "foo"))) 513.43 - (is (= "" (s/trim-newline "")))) 513.44 - 513.45 -(deftest t-capitalize 513.46 - (is (= "Foobar" (s/capitalize "foobar"))) 513.47 - (is (= "Foobar" (s/capitalize "FOOBAR")))) 513.48 - 513.49 -(deftest t-triml 513.50 - (is (= "foo " (s/triml " foo "))) 513.51 - (is (= "" (s/triml " ")))) 513.52 - 513.53 -(deftest t-trimr 513.54 - (is (= " foo" (s/trimr " foo "))) 513.55 - (is (= "" (s/trimr " ")))) 513.56 - 513.57 -(deftest t-trim 513.58 - (is (= "foo" (s/trim " foo \r\n")))) 513.59 - 513.60 -(deftest t-upper-case 513.61 - (is (= "FOOBAR" (s/upper-case "Foobar")))) 513.62 - 513.63 -(deftest t-lower-case 513.64 - (is (= "foobar" (s/lower-case "FooBar")))) 513.65 - 513.66 -(deftest nil-handling 513.67 - (are [f args] (thrown? NullPointerException (apply f args)) 513.68 - s/reverse [nil] 513.69 - s/replace [nil #"foo" "bar"] 513.70 - s/replace-first [nil #"foo" "bar"] 513.71 - s/capitalize [nil] 513.72 - s/upper-case [nil] 513.73 - s/lower-case [nil] 513.74 - s/split [nil #"-"] 513.75 - s/split [nil #"-" 1] 513.76 - s/trim [nil] 513.77 - s/triml [nil] 513.78 - s/trimr [nil] 513.79 - s/trim-newline [nil])) 513.80 - 513.81 -(deftest char-sequence-handling 513.82 - (are [result f args] (let [[^CharSequence s & more] args] 513.83 - (= result (apply f (StringBuffer. s) more))) 513.84 - "paz" s/reverse ["zap"] 513.85 - "foo:bar" s/replace ["foo-bar" \- \:] 513.86 - "ABC" s/replace ["abc" #"\w" s/upper-case] 513.87 - "faa" s/replace ["foo" #"o" (StringBuffer. "a")] 513.88 - "baz::quux" s/replace-first ["baz--quux" #"--" "::"] 513.89 - "baz::quux" s/replace-first ["baz--quux" (StringBuffer. "--") (StringBuffer. "::")] 513.90 - "zim-zam" s/replace-first ["zim zam" #" " (StringBuffer. "-")] 513.91 - "Pow" s/capitalize ["POW"] 513.92 - "BOOM" s/upper-case ["boom"] 513.93 - "whimper" s/lower-case ["whimPER"] 513.94 - ["foo" "bar"] s/split ["foo-bar" #"-"] 513.95 - "calvino" s/trim [" calvino "] 513.96 - "calvino " s/triml [" calvino "] 513.97 - " calvino" s/trimr [" calvino "] 513.98 - "the end" s/trim-newline ["the end\r\n\r\r\n"] 513.99 - true s/blank? [" "] 513.100 - ["a" "b"] s/split-lines ["a\nb"] 513.101 - "fa la la" s/escape ["fo lo lo" {\o \a}])) 513.102 - 513.103 -(deftest t-escape 513.104 - (is (= "<foo&bar>" 513.105 - (s/escape "<foo&bar>" {\& "&" \< "<" \> ">"}))) 513.106 - (is (= " \\\"foo\\\" " 513.107 - (s/escape " \"foo\" " {\" "\\\""}))) 513.108 - (is (= "faabor" 513.109 - (s/escape "foobar" {\a \o, \o \a})))) 513.110 - 513.111 -(deftest t-blank 513.112 - (is (s/blank? nil)) 513.113 - (is (s/blank? "")) 513.114 - (is (s/blank? " ")) 513.115 - (is (s/blank? " \t \n \r ")) 513.116 - (is (not (s/blank? " foo ")))) 513.117 - 513.118 -(deftest t-split-lines 513.119 - (let [result (s/split-lines "one\ntwo\r\nthree")] 513.120 - (is (= ["one" "two" "three"] result)) 513.121 - (is (vector? result))) 513.122 - (is (= (list "foo") (s/split-lines "foo")))) 513.123 -
514.1 --- a/src/clojure/test_clojure/test.clj Sat Aug 21 06:25:44 2010 -0400 514.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 514.3 @@ -1,115 +0,0 @@ 514.4 -; Copyright (c) Rich Hickey. All rights reserved. 514.5 -; The use and distribution terms for this software are covered by the 514.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 514.7 -; which can be found in the file epl-v10.html at the root of this distribution. 514.8 -; By using this software in any fashion, you are agreeing to be bound by 514.9 -; the terms of this license. 514.10 -; You must not remove this notice, or any other, from this software. 514.11 - 514.12 -;;; test_clojure/test.clj: unit tests for test.clj 514.13 - 514.14 -;; by Stuart Sierra 514.15 -;; January 16, 2009 514.16 - 514.17 -;; Thanks to Chas Emerick, Allen Rohner, and Stuart Halloway for 514.18 -;; contributions and suggestions. 514.19 - 514.20 - 514.21 -(ns clojure.test-clojure.test 514.22 - (:use clojure.test)) 514.23 - 514.24 -(deftest can-test-symbol 514.25 - (let [x true] 514.26 - (is x "Should pass")) 514.27 - (let [x false] 514.28 - (is x "Should fail"))) 514.29 - 514.30 -(deftest can-test-boolean 514.31 - (is true "Should pass") 514.32 - (is false "Should fail")) 514.33 - 514.34 -(deftest can-test-nil 514.35 - (is nil "Should fail")) 514.36 - 514.37 -(deftest can-test-= 514.38 - (is (= 2 (+ 1 1)) "Should pass") 514.39 - (is (= 3 (+ 2 2)) "Should fail")) 514.40 - 514.41 -(deftest can-test-instance 514.42 - (is (instance? Integer (+ 2 2)) "Should pass") 514.43 - (is (instance? Float (+ 1 1)) "Should fail")) 514.44 - 514.45 -(deftest can-test-thrown 514.46 - (is (thrown? ArithmeticException (/ 1 0)) "Should pass") 514.47 - ;; No exception is thrown: 514.48 - (is (thrown? Exception (+ 1 1)) "Should fail") 514.49 - ;; Wrong class of exception is thrown: 514.50 - (is (thrown? ArithmeticException (throw (RuntimeException.))) "Should error")) 514.51 - 514.52 -(deftest can-test-thrown-with-msg 514.53 - (is (thrown-with-msg? ArithmeticException #"Divide by zero" (/ 1 0)) "Should pass") 514.54 - ;; Wrong message string: 514.55 - (is (thrown-with-msg? ArithmeticException #"Something else" (/ 1 0)) "Should fail") 514.56 - ;; No exception is thrown: 514.57 - (is (thrown? Exception (+ 1 1)) "Should fail") 514.58 - ;; Wrong class of exception is thrown: 514.59 - (is (thrown-with-msg? IllegalArgumentException #"Divide by zero" (/ 1 0)) "Should error")) 514.60 - 514.61 -(deftest can-catch-unexpected-exceptions 514.62 - (is (= 1 (throw (Exception.))) "Should error")) 514.63 - 514.64 -(deftest can-test-method-call 514.65 - (is (.startsWith "abc" "a") "Should pass") 514.66 - (is (.startsWith "abc" "d") "Should fail")) 514.67 - 514.68 -(deftest can-test-anonymous-fn 514.69 - (is (#(.startsWith % "a") "abc") "Should pass") 514.70 - (is (#(.startsWith % "d") "abc") "Should fail")) 514.71 - 514.72 -(deftest can-test-regexps 514.73 - (is (re-matches #"^ab.*$" "abbabba") "Should pass") 514.74 - (is (re-matches #"^cd.*$" "abbabba") "Should fail") 514.75 - (is (re-find #"ab" "abbabba") "Should pass") 514.76 - (is (re-find #"cd" "abbabba") "Should fail")) 514.77 - 514.78 -(deftest #^{:has-meta true} can-add-metadata-to-tests 514.79 - (is (:has-meta (meta #'can-add-metadata-to-tests)) "Should pass")) 514.80 - 514.81 -;; still have to declare the symbol before testing unbound symbols 514.82 -(declare does-not-exist) 514.83 - 514.84 -(deftest can-test-unbound-symbol 514.85 - (is (= nil does-not-exist) "Should error")) 514.86 - 514.87 -(deftest can-test-unbound-function 514.88 - (is (does-not-exist) "Should error")) 514.89 - 514.90 - 514.91 -;; Here, we create an alternate version of test/report, that 514.92 -;; compares the event with the message, then calls the original 514.93 -;; 'report' with modified arguments. 514.94 - 514.95 -(declare original-report) 514.96 - 514.97 -(defn custom-report [data] 514.98 - (let [event (:type data) 514.99 - msg (:message data) 514.100 - expected (:expected data) 514.101 - actual (:actual data) 514.102 - passed (cond 514.103 - (= event :fail) (= msg "Should fail") 514.104 - (= event :pass) (= msg "Should pass") 514.105 - (= event :error) (= msg "Should error") 514.106 - :else true)] 514.107 - (if passed 514.108 - (original-report {:type :pass, :message msg, 514.109 - :expected expected, :actual actual}) 514.110 - (original-report {:type :fail, :message (str msg " but got " event) 514.111 - :expected expected, :actual actual})))) 514.112 - 514.113 -;; test-ns-hook will be used by test/test-ns to run tests in this 514.114 -;; namespace. 514.115 -(defn test-ns-hook [] 514.116 - (binding [original-report report 514.117 - report custom-report] 514.118 - (test-all-vars (find-ns 'clojure.test-clojure.test))))
515.1 --- a/src/clojure/test_clojure/test_fixtures.clj Sat Aug 21 06:25:44 2010 -0400 515.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 515.3 @@ -1,50 +0,0 @@ 515.4 -; Copyright (c) Rich Hickey. All rights reserved. 515.5 -; The use and distribution terms for this software are covered by the 515.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 515.7 -; which can be found in the file epl-v10.html at the root of this distribution. 515.8 -; By using this software in any fashion, you are agreeing to be bound by 515.9 -; the terms of this license. 515.10 -; You must not remove this notice, or any other, from this software. 515.11 -; 515.12 -;;; test_fixtures.clj: unit tests for fixtures in test.clj 515.13 - 515.14 -;; by Stuart Sierra 515.15 -;; March 28, 2009 515.16 - 515.17 -(ns clojure.test-clojure.test-fixtures 515.18 - (:use clojure.test)) 515.19 - 515.20 -(declare *a* *b* *c* *d*) 515.21 - 515.22 -(def *n* 0) 515.23 - 515.24 -(defn fixture-a [f] 515.25 - (binding [*a* 3] (f))) 515.26 - 515.27 -(defn fixture-b [f] 515.28 - (binding [*b* 5] (f))) 515.29 - 515.30 -(defn fixture-c [f] 515.31 - (binding [*c* 7] (f))) 515.32 - 515.33 -(defn fixture-d [f] 515.34 - (binding [*d* 11] (f))) 515.35 - 515.36 -(defn inc-n-fixture [f] 515.37 - (binding [*n* (inc *n*)] (f))) 515.38 - 515.39 -(use-fixtures :once fixture-a fixture-b) 515.40 - 515.41 -(use-fixtures :each fixture-c fixture-d inc-n-fixture) 515.42 -(use-fixtures :each fixture-c fixture-d inc-n-fixture) 515.43 - 515.44 -(deftest can-use-once-fixtures 515.45 - (is (= 3 *a*)) 515.46 - (is (= 5 *b*))) 515.47 - 515.48 -(deftest can-use-each-fixtures 515.49 - (is (= 7 *c*)) 515.50 - (is (= 11 *d*))) 515.51 - 515.52 -(deftest use-fixtures-replaces 515.53 - (is (= *n* 1))) 515.54 \ No newline at end of file
516.1 --- a/src/clojure/test_clojure/transients.clj Sat Aug 21 06:25:44 2010 -0400 516.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 516.3 @@ -1,12 +0,0 @@ 516.4 -(ns clojure.test-clojure.transients 516.5 - (:use clojure.test)) 516.6 - 516.7 -(deftest popping-off 516.8 - (testing "across a node boundary" 516.9 - (are [n] 516.10 - (let [v (-> (range n) vec)] 516.11 - (= (subvec v 0 (- n 2)) (-> v transient pop! pop! persistent!))) 516.12 - 33 (+ 32 (inc (* 32 32))) (+ 32 (inc (* 32 32 32))))) 516.13 - (testing "off the end" 516.14 - (is (thrown-with-msg? IllegalStateException #"Can't pop empty vector" 516.15 - (-> [] transient pop!)))))
517.1 --- a/src/clojure/test_clojure/vars.clj Sat Aug 21 06:25:44 2010 -0400 517.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 517.3 @@ -1,56 +0,0 @@ 517.4 -; Copyright (c) Rich Hickey. All rights reserved. 517.5 -; The use and distribution terms for this software are covered by the 517.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 517.7 -; which can be found in the file epl-v10.html at the root of this distribution. 517.8 -; By using this software in any fashion, you are agreeing to be bound by 517.9 -; the terms of this license. 517.10 -; You must not remove this notice, or any other, from this software. 517.11 - 517.12 -; Author: Frantisek Sodomka, Stephen C. Gilardi 517.13 - 517.14 - 517.15 -(ns clojure.test-clojure.vars 517.16 - (:use clojure.test)) 517.17 - 517.18 -; http://clojure.org/vars 517.19 - 517.20 -; def 517.21 -; defn defn- defonce 517.22 - 517.23 -; declare intern binding find-var var 517.24 - 517.25 -(def a) 517.26 -(deftest test-binding 517.27 - (are [x y] (= x y) 517.28 - (eval `(binding [a 4] a)) 4 ; regression in Clojure SVN r1370 517.29 - )) 517.30 - 517.31 -; with-local-vars var-get var-set alter-var-root [var? (predicates.clj)] 517.32 -; with-in-str with-out-str 517.33 -; with-open 517.34 -; with-precision 517.35 - 517.36 -(deftest test-with-precision 517.37 - (are [x y] (= x y) 517.38 - (with-precision 4 (+ 3.5555555M 1)) 4.556M 517.39 - (with-precision 6 (+ 3.5555555M 1)) 4.55556M 517.40 - (with-precision 6 :rounding CEILING (+ 3.5555555M 1)) 4.55556M 517.41 - (with-precision 6 :rounding FLOOR (+ 3.5555555M 1)) 4.55555M 517.42 - (with-precision 6 :rounding HALF_UP (+ 3.5555555M 1)) 4.55556M 517.43 - (with-precision 6 :rounding HALF_DOWN (+ 3.5555555M 1)) 4.55556M 517.44 - (with-precision 6 :rounding HALF_EVEN (+ 3.5555555M 1)) 4.55556M 517.45 - (with-precision 6 :rounding UP (+ 3.5555555M 1)) 4.55556M 517.46 - (with-precision 6 :rounding DOWN (+ 3.5555555M 1)) 4.55555M 517.47 - (with-precision 6 :rounding UNNECESSARY (+ 3.5555M 1)) 4.5555M)) 517.48 - 517.49 -(deftest test-settable-math-context 517.50 - (is (= 517.51 - (clojure.main/with-bindings 517.52 - (set! *math-context* (java.math.MathContext. 8)) 517.53 - (+ 3.55555555555555M 1)) 517.54 - 4.5555556M))) 517.55 - 517.56 -; set-validator get-validator 517.57 - 517.58 -; doc find-doc test 517.59 -
518.1 --- a/src/clojure/test_clojure/vectors.clj Sat Aug 21 06:25:44 2010 -0400 518.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 518.3 @@ -1,304 +0,0 @@ 518.4 -; Copyright (c) Rich Hickey. All rights reserved. 518.5 -; The use and distribution terms for this software are covered by the 518.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 518.7 -; which can be found in the file epl-v10.html at the root of this distribution. 518.8 -; By using this software in any fashion, you are agreeing to be bound by 518.9 -; the terms of this license. 518.10 -; You must not remove this notice, or any other, from this software. 518.11 - 518.12 -; Author: Stuart Halloway, Daniel Solano Gómez 518.13 - 518.14 -(ns clojure.test-clojure.vectors 518.15 - (:use clojure.test)) 518.16 - 518.17 -(deftest test-reversed-vec 518.18 - (let [r (range 6) 518.19 - v (into (vector-of :int) r) 518.20 - reversed (.rseq v)] 518.21 - (testing "returns the right impl" 518.22 - (is (= clojure.lang.APersistentVector$RSeq (class reversed)))) 518.23 - (testing "RSeq methods" 518.24 - (is (= [5 4 3 2 1 0] reversed)) 518.25 - (is (= 5 (.index reversed))) 518.26 - (is (= 5 (.first reversed))) 518.27 - (is (= [4 3 2 1 0] (.next reversed))) 518.28 - (is (= [3 2 1 0] (.. reversed next next))) 518.29 - (is (= 6 (.count reversed)))) 518.30 - (testing "clojure calling through" 518.31 - (is (= 5 (first reversed))) 518.32 - (is (= 5 (nth reversed 0)))) 518.33 - (testing "empty reverses to nil" 518.34 - (is (nil? (.. v empty rseq)))))) 518.35 - 518.36 -(deftest test-vecseq 518.37 - (let [r (range 100) 518.38 - vs (into (vector-of :int) r) 518.39 - vs-1 (next vs) 518.40 - vs-32 (.chunkedNext (seq vs))] 518.41 - (testing "=" 518.42 - (are [a b] (= a b) 518.43 - vs vs 518.44 - vs-1 vs-1 518.45 - vs-32 vs-32) 518.46 - (are [a b] (not= a b) 518.47 - vs vs-1 518.48 - vs-1 vs 518.49 - vs vs-32 518.50 - vs-32 vs)) 518.51 - (testing "IPersistentCollection.empty" 518.52 - (are [a] (identical? clojure.lang.PersistentList/EMPTY (.empty (seq a))) 518.53 - vs vs-1 vs-32)) 518.54 - (testing "IPersistentCollection.cons" 518.55 - (are [result input] (= result (.cons input :foo)) 518.56 - [:foo 1] (seq (into (vector-of :int) [1])))) 518.57 - (testing "IPersistentCollection.count" 518.58 - (are [ct s] (= ct (.count (seq s))) 518.59 - 100 vs 518.60 - 99 vs-1 518.61 - 68 vs-32) 518.62 - ;; can't manufacture this scenario: ASeq defers to Counted, but 518.63 - ;; LazySeq doesn't, so Counted never gets checked on reified seq below 518.64 - #_(testing "hops to counted when available" 518.65 - (is (= 200 518.66 - (.count (concat 518.67 - (seq vs) 518.68 - (reify clojure.lang.ISeq 518.69 - (seq [this] this) 518.70 - clojure.lang.Counted 518.71 - (count [_] 100)))))))) 518.72 - (testing "IPersistentCollection.equiv" 518.73 - (are [a b] (true? (.equiv a b)) 518.74 - vs vs 518.75 - vs-1 vs-1 518.76 - vs-32 vs-32 518.77 - vs r) 518.78 - (are [a b] (false? (.equiv a b)) 518.79 - vs vs-1 518.80 - vs-1 vs 518.81 - vs vs-32 518.82 - vs-32 vs 518.83 - vs nil)))) 518.84 - 518.85 -(deftest test-vec-compare 518.86 - (let [nums (range 1 100) 518.87 - ; randomly replaces a single item with the given value 518.88 - rand-replace (fn[val] 518.89 - (let [r (rand-int 99)] 518.90 - (concat (take r nums) [val] (drop (inc r) nums)))) 518.91 - ; all num sequences in map 518.92 - num-seqs {:standard nums 518.93 - :empty '() 518.94 - ; different lengths 518.95 - :longer (concat nums [100]) 518.96 - :shorter (drop-last nums) 518.97 - ; greater by value 518.98 - :first-greater (concat [100] (next nums)) 518.99 - :last-greater (concat (drop-last nums) [100]) 518.100 - :rand-greater-1 (rand-replace 100) 518.101 - :rand-greater-2 (rand-replace 100) 518.102 - :rand-greater-3 (rand-replace 100) 518.103 - ; lesser by value 518.104 - :first-lesser (concat [0] (next nums)) 518.105 - :last-lesser (concat (drop-last nums) [0]) 518.106 - :rand-lesser-1 (rand-replace 0) 518.107 - :rand-lesser-2 (rand-replace 0) 518.108 - :rand-lesser-3 (rand-replace 0)} 518.109 - ; a way to create compare values based on num-seqs 518.110 - create-vals (fn[base-val] 518.111 - (zipmap (keys num-seqs) 518.112 - (map #(into base-val %1) (vals num-seqs)))) 518.113 - ; Vecs made of int primitives 518.114 - int-vecs (create-vals (vector-of :int)) 518.115 - ; Vecs made of long primitives 518.116 - long-vecs (create-vals (vector-of :long)) 518.117 - ; standard boxing vectors 518.118 - regular-vecs (create-vals []) 518.119 - ; the standard int Vec for comparisons 518.120 - int-vec (:standard int-vecs)] 518.121 - (testing "compare" 518.122 - (testing "identical" 518.123 - (is (= 0 (compare int-vec int-vec)))) 518.124 - (testing "equivalent" 518.125 - (are [x y] (= 0 (compare x y)) 518.126 - ; standard 518.127 - int-vec (:standard long-vecs) 518.128 - (:standard long-vecs) int-vec 518.129 - int-vec (:standard regular-vecs) 518.130 - (:standard regular-vecs) int-vec 518.131 - ; empty 518.132 - (:empty int-vecs) (:empty long-vecs) 518.133 - (:empty long-vecs) (:empty int-vecs))) 518.134 - (testing "lesser" 518.135 - (are [x] (= -1 (compare int-vec x)) 518.136 - (:longer int-vecs) 518.137 - (:longer long-vecs) 518.138 - (:longer regular-vecs) 518.139 - (:first-greater int-vecs) 518.140 - (:first-greater long-vecs) 518.141 - (:first-greater regular-vecs) 518.142 - (:last-greater int-vecs) 518.143 - (:last-greater long-vecs) 518.144 - (:last-greater regular-vecs) 518.145 - (:rand-greater-1 int-vecs) 518.146 - (:rand-greater-1 long-vecs) 518.147 - (:rand-greater-1 regular-vecs) 518.148 - (:rand-greater-2 int-vecs) 518.149 - (:rand-greater-2 long-vecs) 518.150 - (:rand-greater-2 regular-vecs) 518.151 - (:rand-greater-3 int-vecs) 518.152 - (:rand-greater-3 long-vecs) 518.153 - (:rand-greater-3 regular-vecs)) 518.154 - (are [x] (= -1 (compare x int-vec)) 518.155 - nil 518.156 - (:empty int-vecs) 518.157 - (:empty long-vecs) 518.158 - (:empty regular-vecs) 518.159 - (:shorter int-vecs) 518.160 - (:shorter long-vecs) 518.161 - (:shorter regular-vecs) 518.162 - (:first-lesser int-vecs) 518.163 - (:first-lesser long-vecs) 518.164 - (:first-lesser regular-vecs) 518.165 - (:last-lesser int-vecs) 518.166 - (:last-lesser long-vecs) 518.167 - (:last-lesser regular-vecs) 518.168 - (:rand-lesser-1 int-vecs) 518.169 - (:rand-lesser-1 long-vecs) 518.170 - (:rand-lesser-1 regular-vecs) 518.171 - (:rand-lesser-2 int-vecs) 518.172 - (:rand-lesser-2 long-vecs) 518.173 - (:rand-lesser-2 regular-vecs) 518.174 - (:rand-lesser-3 int-vecs) 518.175 - (:rand-lesser-3 long-vecs) 518.176 - (:rand-lesser-3 regular-vecs))) 518.177 - (testing "greater" 518.178 - (are [x] (= 1 (compare int-vec x)) 518.179 - nil 518.180 - (:empty int-vecs) 518.181 - (:empty long-vecs) 518.182 - (:empty regular-vecs) 518.183 - (:shorter int-vecs) 518.184 - (:shorter long-vecs) 518.185 - (:shorter regular-vecs) 518.186 - (:first-lesser int-vecs) 518.187 - (:first-lesser long-vecs) 518.188 - (:first-lesser regular-vecs) 518.189 - (:last-lesser int-vecs) 518.190 - (:last-lesser long-vecs) 518.191 - (:last-lesser regular-vecs) 518.192 - (:rand-lesser-1 int-vecs) 518.193 - (:rand-lesser-1 long-vecs) 518.194 - (:rand-lesser-1 regular-vecs) 518.195 - (:rand-lesser-2 int-vecs) 518.196 - (:rand-lesser-2 long-vecs) 518.197 - (:rand-lesser-2 regular-vecs) 518.198 - (:rand-lesser-3 int-vecs) 518.199 - (:rand-lesser-3 long-vecs) 518.200 - (:rand-lesser-3 regular-vecs)) 518.201 - (are [x] (= 1 (compare x int-vec)) 518.202 - (:longer int-vecs) 518.203 - (:longer long-vecs) 518.204 - (:longer regular-vecs) 518.205 - (:first-greater int-vecs) 518.206 - (:first-greater long-vecs) 518.207 - (:first-greater regular-vecs) 518.208 - (:last-greater int-vecs) 518.209 - (:last-greater long-vecs) 518.210 - (:last-greater regular-vecs) 518.211 - (:rand-greater-1 int-vecs) 518.212 - (:rand-greater-1 long-vecs) 518.213 - (:rand-greater-1 regular-vecs) 518.214 - (:rand-greater-2 int-vecs) 518.215 - (:rand-greater-2 long-vecs) 518.216 - (:rand-greater-2 regular-vecs) 518.217 - (:rand-greater-3 int-vecs) 518.218 - (:rand-greater-3 long-vecs) 518.219 - (:rand-greater-3 regular-vecs)))) 518.220 - (testing "Comparable.compareTo" 518.221 - (testing "incompatible" 518.222 - (is (thrown? NullPointerException (.compareTo int-vec nil))) 518.223 - (are [x] (thrown? ClassCastException (.compareTo int-vec x)) 518.224 - '() 518.225 - {} 518.226 - #{} 518.227 - (sorted-set) 518.228 - (sorted-map) 518.229 - nums 518.230 - 1)) 518.231 - (testing "identical" 518.232 - (is (= 0 (.compareTo int-vec int-vec)))) 518.233 - (testing "equivalent" 518.234 - (are [x] (= 0 (.compareTo int-vec x)) 518.235 - (:standard long-vecs) 518.236 - (:standard regular-vecs))) 518.237 - (testing "lesser" 518.238 - (are [x] (= -1 (.compareTo int-vec x)) 518.239 - (:longer int-vecs) 518.240 - (:longer long-vecs) 518.241 - (:longer regular-vecs) 518.242 - (:first-greater int-vecs) 518.243 - (:first-greater long-vecs) 518.244 - (:first-greater regular-vecs) 518.245 - (:last-greater int-vecs) 518.246 - (:last-greater long-vecs) 518.247 - (:last-greater regular-vecs) 518.248 - (:rand-greater-1 int-vecs) 518.249 - (:rand-greater-1 long-vecs) 518.250 - (:rand-greater-1 regular-vecs) 518.251 - (:rand-greater-2 int-vecs) 518.252 - (:rand-greater-2 long-vecs) 518.253 - (:rand-greater-2 regular-vecs) 518.254 - (:rand-greater-3 int-vecs) 518.255 - (:rand-greater-3 long-vecs) 518.256 - (:rand-greater-3 regular-vecs))) 518.257 - (testing "greater" 518.258 - (are [x] (= 1 (.compareTo int-vec x)) 518.259 - (:empty int-vecs) 518.260 - (:empty long-vecs) 518.261 - (:empty regular-vecs) 518.262 - (:shorter int-vecs) 518.263 - (:shorter long-vecs) 518.264 - (:shorter regular-vecs) 518.265 - (:first-lesser int-vecs) 518.266 - (:first-lesser long-vecs) 518.267 - (:first-lesser regular-vecs) 518.268 - (:last-lesser int-vecs) 518.269 - (:last-lesser long-vecs) 518.270 - (:last-lesser regular-vecs) 518.271 - (:rand-lesser-1 int-vecs) 518.272 - (:rand-lesser-1 long-vecs) 518.273 - (:rand-lesser-1 regular-vecs) 518.274 - (:rand-lesser-2 int-vecs) 518.275 - (:rand-lesser-2 long-vecs) 518.276 - (:rand-lesser-2 regular-vecs) 518.277 - (:rand-lesser-3 int-vecs) 518.278 - (:rand-lesser-3 long-vecs) 518.279 - (:rand-lesser-3 regular-vecs)))))) 518.280 - 518.281 -(deftest test-vec-associative 518.282 - (let [empty-v (vector-of :long) 518.283 - v (into empty-v (range 1 6))] 518.284 - (testing "Associative.containsKey" 518.285 - (are [x] (.containsKey v x) 518.286 - 0 1 2 3 4) 518.287 - (are [x] (not (.containsKey v x)) 518.288 - -1 -100 nil [] "" #"" #{} 5 100) 518.289 - (are [x] (not (.containsKey empty-v x)) 518.290 - 0 1)) 518.291 - (testing "contains?" 518.292 - (are [x] (contains? v x) 518.293 - 0 2 4) 518.294 - (are [x] (not (contains? v x)) 518.295 - -1 -100 nil "" 5 100) 518.296 - (are [x] (not (contains? empty-v x)) 518.297 - 0 1)) 518.298 - (testing "Associative.entryAt" 518.299 - (are [idx val] (= (clojure.lang.MapEntry. idx val) 518.300 - (.entryAt v idx)) 518.301 - 0 1 518.302 - 2 3 518.303 - 4 5) 518.304 - (are [idx] (nil? (.entryAt v idx)) 518.305 - -5 -1 5 10 nil "") 518.306 - (are [idx] (nil? (.entryAt empty-v idx)) 518.307 - 0 1))))
519.1 --- a/src/clojure/walk.clj Sat Aug 21 06:25:44 2010 -0400 519.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 519.3 @@ -1,132 +0,0 @@ 519.4 -; Copyright (c) Rich Hickey. All rights reserved. 519.5 -; The use and distribution terms for this software are covered by the 519.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 519.7 -; which can be found in the file epl-v10.html at the root of this distribution. 519.8 -; By using this software in any fashion, you are agreeing to be bound by 519.9 -; the terms of this license. 519.10 -; You must not remove this notice, or any other, from this software. 519.11 - 519.12 -;;; walk.clj - generic tree walker with replacement 519.13 - 519.14 -;; by Stuart Sierra 519.15 -;; December 15, 2008 519.16 - 519.17 -;; CHANGE LOG: 519.18 -;; 519.19 -;; * December 15, 2008: replaced 'walk' with 'prewalk' & 'postwalk' 519.20 -;; 519.21 -;; * December 9, 2008: first version 519.22 - 519.23 - 519.24 -(ns 519.25 - ^{:author "Stuart Sierra", 519.26 - :doc "This file defines a generic tree walker for Clojure data 519.27 -structures. It takes any data structure (list, vector, map, set, 519.28 -seq), calls a function on every element, and uses the return value 519.29 -of the function in place of the original. This makes it fairly 519.30 -easy to write recursive search-and-replace functions, as shown in 519.31 -the examples. 519.32 - 519.33 -Note: \"walk\" supports all Clojure data structures EXCEPT maps 519.34 -created with sorted-map-by. There is no (obvious) way to retrieve 519.35 -the sorting function."} 519.36 - clojure.walk) 519.37 - 519.38 -(defn walk 519.39 - "Traverses form, an arbitrary data structure. inner and outer are 519.40 - functions. Applies inner to each element of form, building up a 519.41 - data structure of the same type, then applies outer to the result. 519.42 - Recognizes all Clojure data structures except sorted-map-by. 519.43 - Consumes seqs as with doall." 519.44 - {:added "1.1"} 519.45 - [inner outer form] 519.46 - (cond 519.47 - (list? form) (outer (apply list (map inner form))) 519.48 - (seq? form) (outer (doall (map inner form))) 519.49 - (vector? form) (outer (vec (map inner form))) 519.50 - (map? form) (outer (into (if (sorted? form) (sorted-map) {}) 519.51 - (map inner form))) 519.52 - (set? form) (outer (into (if (sorted? form) (sorted-set) #{}) 519.53 - (map inner form))) 519.54 - :else (outer form))) 519.55 - 519.56 -(defn postwalk 519.57 - "Performs a depth-first, post-order traversal of form. Calls f on 519.58 - each sub-form, uses f's return value in place of the original. 519.59 - Recognizes all Clojure data structures except sorted-map-by. 519.60 - Consumes seqs as with doall." 519.61 - {:added "1.1"} 519.62 - [f form] 519.63 - (walk (partial postwalk f) f form)) 519.64 - 519.65 -(defn prewalk 519.66 - "Like postwalk, but does pre-order traversal." 519.67 - {:added "1.1"} 519.68 - [f form] 519.69 - (walk (partial prewalk f) identity (f form))) 519.70 - 519.71 - 519.72 -;; Note: I wanted to write: 519.73 -;; 519.74 -;; (defn walk 519.75 -;; [f form] 519.76 -;; (let [pf (partial walk f)] 519.77 -;; (if (coll? form) 519.78 -;; (f (into (empty form) (map pf form))) 519.79 -;; (f form)))) 519.80 -;; 519.81 -;; but this throws a ClassCastException when applied to a map. 519.82 - 519.83 - 519.84 -(defn postwalk-demo 519.85 - "Demonstrates the behavior of postwalk by printing each form as it is 519.86 - walked. Returns form." 519.87 - {:added "1.1"} 519.88 - [form] 519.89 - (postwalk (fn [x] (print "Walked: ") (prn x) x) form)) 519.90 - 519.91 -(defn prewalk-demo 519.92 - "Demonstrates the behavior of prewalk by printing each form as it is 519.93 - walked. Returns form." 519.94 - {:added "1.1"} 519.95 - [form] 519.96 - (prewalk (fn [x] (print "Walked: ") (prn x) x) form)) 519.97 - 519.98 -(defn keywordize-keys 519.99 - "Recursively transforms all map keys from strings to keywords." 519.100 - {:added "1.1"} 519.101 - [m] 519.102 - (let [f (fn [[k v]] (if (string? k) [(keyword k) v] [k v]))] 519.103 - ;; only apply to maps 519.104 - (postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m))) 519.105 - 519.106 -(defn stringify-keys 519.107 - "Recursively transforms all map keys from keywords to strings." 519.108 - {:added "1.1"} 519.109 - [m] 519.110 - (let [f (fn [[k v]] (if (keyword? k) [(name k) v] [k v]))] 519.111 - ;; only apply to maps 519.112 - (postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m))) 519.113 - 519.114 -(defn prewalk-replace 519.115 - "Recursively transforms form by replacing keys in smap with their 519.116 - values. Like clojure/replace but works on any data structure. Does 519.117 - replacement at the root of the tree first." 519.118 - {:added "1.1"} 519.119 - [smap form] 519.120 - (prewalk (fn [x] (if (contains? smap x) (smap x) x)) form)) 519.121 - 519.122 -(defn postwalk-replace 519.123 - "Recursively transforms form by replacing keys in smap with their 519.124 - values. Like clojure/replace but works on any data structure. Does 519.125 - replacement at the leaves of the tree first." 519.126 - {:added "1.1"} 519.127 - [smap form] 519.128 - (postwalk (fn [x] (if (contains? smap x) (smap x) x)) form)) 519.129 - 519.130 -(defn macroexpand-all 519.131 - "Recursively performs all possible macroexpansions in form." 519.132 - {:added "1.1"} 519.133 - [form] 519.134 - (prewalk (fn [x] (if (seq? x) (macroexpand x) x)) form)) 519.135 -
520.1 --- a/src/clojure/xml.clj Sat Aug 21 06:25:44 2010 -0400 520.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 520.3 @@ -1,118 +0,0 @@ 520.4 -; Copyright (c) Rich Hickey. All rights reserved. 520.5 -; The use and distribution terms for this software are covered by the 520.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 520.7 -; which can be found in the file epl-v10.html at the root of this distribution. 520.8 -; By using this software in any fashion, you are agreeing to be bound by 520.9 -; the terms of this license. 520.10 -; You must not remove this notice, or any other, from this software. 520.11 - 520.12 -(ns ^{:doc "XML reading/writing." 520.13 - :author "Rich Hickey"} 520.14 - clojure.xml 520.15 - (:import (org.xml.sax ContentHandler Attributes SAXException) 520.16 - (javax.xml.parsers SAXParser SAXParserFactory))) 520.17 - 520.18 -(def *stack*) 520.19 -(def *current*) 520.20 -(def *state*) ; :element :chars :between 520.21 -(def *sb*) 520.22 - 520.23 -(defstruct element :tag :attrs :content) 520.24 - 520.25 -(def tag (accessor element :tag)) 520.26 -(def attrs (accessor element :attrs)) 520.27 -(def content (accessor element :content)) 520.28 - 520.29 -(def content-handler 520.30 - (let [push-content (fn [e c] 520.31 - (assoc e :content (conj (or (:content e) []) c))) 520.32 - push-chars (fn [] 520.33 - (when (and (= *state* :chars) 520.34 - (some (complement #(Character/isWhitespace (char %))) (str *sb*))) 520.35 - (set! *current* (push-content *current* (str *sb*)))))] 520.36 - (new clojure.lang.XMLHandler 520.37 - (proxy [ContentHandler] [] 520.38 - (startElement [uri local-name q-name ^Attributes atts] 520.39 - (let [attrs (fn [ret i] 520.40 - (if (neg? i) 520.41 - ret 520.42 - (recur (assoc ret 520.43 - (clojure.lang.Keyword/intern (symbol (.getQName atts i))) 520.44 - (.getValue atts (int i))) 520.45 - (dec i)))) 520.46 - e (struct element 520.47 - (. clojure.lang.Keyword (intern (symbol q-name))) 520.48 - (when (pos? (.getLength atts)) 520.49 - (attrs {} (dec (.getLength atts)))))] 520.50 - (push-chars) 520.51 - (set! *stack* (conj *stack* *current*)) 520.52 - (set! *current* e) 520.53 - (set! *state* :element)) 520.54 - nil) 520.55 - (endElement [uri local-name q-name] 520.56 - (push-chars) 520.57 - (set! *current* (push-content (peek *stack*) *current*)) 520.58 - (set! *stack* (pop *stack*)) 520.59 - (set! *state* :between) 520.60 - nil) 520.61 - (characters [^chars ch start length] 520.62 - (when-not (= *state* :chars) 520.63 - (set! *sb* (new StringBuilder))) 520.64 - (let [^StringBuilder sb *sb*] 520.65 - (.append sb ch (int start) (int length)) 520.66 - (set! *state* :chars)) 520.67 - nil) 520.68 - (setDocumentLocator [locator]) 520.69 - (startDocument []) 520.70 - (endDocument []) 520.71 - (startPrefixMapping [prefix uri]) 520.72 - (endPrefixMapping [prefix]) 520.73 - (ignorableWhitespace [ch start length]) 520.74 - (processingInstruction [target data]) 520.75 - (skippedEntity [name]) 520.76 - )))) 520.77 - 520.78 -(defn startparse-sax [s ch] 520.79 - (.. SAXParserFactory (newInstance) (newSAXParser) (parse s ch))) 520.80 - 520.81 -(defn parse 520.82 - "Parses and loads the source s, which can be a File, InputStream or 520.83 - String naming a URI. Returns a tree of the xml/element struct-map, 520.84 - which has the keys :tag, :attrs, and :content. and accessor fns tag, 520.85 - attrs, and content. Other parsers can be supplied by passing 520.86 - startparse, a fn taking a source and a ContentHandler and returning 520.87 - a parser" 520.88 - {:added "1.0"} 520.89 - ([s] (parse s startparse-sax)) 520.90 - ([s startparse] 520.91 - (binding [*stack* nil 520.92 - *current* (struct element) 520.93 - *state* :between 520.94 - *sb* nil] 520.95 - (startparse s content-handler) 520.96 - ((:content *current*) 0)))) 520.97 - 520.98 -(defn emit-element [e] 520.99 - (if (instance? String e) 520.100 - (println e) 520.101 - (do 520.102 - (print (str "<" (name (:tag e)))) 520.103 - (when (:attrs e) 520.104 - (doseq [attr (:attrs e)] 520.105 - (print (str " " (name (key attr)) "='" (val attr)"'")))) 520.106 - (if (:content e) 520.107 - (do 520.108 - (println ">") 520.109 - (doseq [c (:content e)] 520.110 - (emit-element c)) 520.111 - (println (str "</" (name (:tag e)) ">"))) 520.112 - (println "/>"))))) 520.113 - 520.114 -(defn emit [x] 520.115 - (println "<?xml version='1.0' encoding='UTF-8'?>") 520.116 - (emit-element x)) 520.117 - 520.118 -;(export '(tag attrs content parse element emit emit-element)) 520.119 - 520.120 -;(load-file "/Users/rich/dev/clojure/src/xml.clj") 520.121 -;(def x (xml/parse "http://arstechnica.com/journals.rssx"))
521.1 --- a/src/clojure/zip.clj Sat Aug 21 06:25:44 2010 -0400 521.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 521.3 @@ -1,318 +0,0 @@ 521.4 -; Copyright (c) Rich Hickey. All rights reserved. 521.5 -; The use and distribution terms for this software are covered by the 521.6 -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 521.7 -; which can be found in the file epl-v10.html at the root of this distribution. 521.8 -; By using this software in any fashion, you are agreeing to be bound by 521.9 -; the terms of this license. 521.10 -; You must not remove this notice, or any other, from this software. 521.11 - 521.12 -;functional hierarchical zipper, with navigation, editing and enumeration 521.13 -;see Huet 521.14 - 521.15 -(ns ^{:doc "Functional hierarchical zipper, with navigation, editing, 521.16 - and enumeration. See Huet" 521.17 - :author "Rich Hickey"} 521.18 - clojure.zip 521.19 - (:refer-clojure :exclude (replace remove next))) 521.20 - 521.21 -(defn zipper 521.22 - "Creates a new zipper structure. 521.23 - 521.24 - branch? is a fn that, given a node, returns true if can have 521.25 - children, even if it currently doesn't. 521.26 - 521.27 - children is a fn that, given a branch node, returns a seq of its 521.28 - children. 521.29 - 521.30 - make-node is a fn that, given an existing node and a seq of 521.31 - children, returns a new branch node with the supplied children. 521.32 - root is the root node." 521.33 - {:added "1.0"} 521.34 - [branch? children make-node root] 521.35 - ^{:zip/branch? branch? :zip/children children :zip/make-node make-node} 521.36 - [root nil]) 521.37 - 521.38 -(defn seq-zip 521.39 - "Returns a zipper for nested sequences, given a root sequence" 521.40 - {:added "1.0"} 521.41 - [root] 521.42 - (zipper seq? 521.43 - identity 521.44 - (fn [node children] (with-meta children (meta node))) 521.45 - root)) 521.46 - 521.47 -(defn vector-zip 521.48 - "Returns a zipper for nested vectors, given a root vector" 521.49 - {:added "1.0"} 521.50 - [root] 521.51 - (zipper vector? 521.52 - seq 521.53 - (fn [node children] (with-meta (vec children) (meta node))) 521.54 - root)) 521.55 - 521.56 -(defn xml-zip 521.57 - "Returns a zipper for xml elements (as from xml/parse), 521.58 - given a root element" 521.59 - {:added "1.0"} 521.60 - [root] 521.61 - (zipper (complement string?) 521.62 - (comp seq :content) 521.63 - (fn [node children] 521.64 - (assoc node :content (and children (apply vector children)))) 521.65 - root)) 521.66 - 521.67 -(defn node 521.68 - "Returns the node at loc" 521.69 - {:added "1.0"} 521.70 - [loc] (loc 0)) 521.71 - 521.72 -(defn branch? 521.73 - "Returns true if the node at loc is a branch" 521.74 - {:added "1.0"} 521.75 - [loc] 521.76 - ((:zip/branch? (meta loc)) (node loc))) 521.77 - 521.78 -(defn children 521.79 - "Returns a seq of the children of node at loc, which must be a branch" 521.80 - {:added "1.0"} 521.81 - [loc] 521.82 - (if (branch? loc) 521.83 - ((:zip/children (meta loc)) (node loc)) 521.84 - (throw (Exception. "called children on a leaf node")))) 521.85 - 521.86 -(defn make-node 521.87 - "Returns a new branch node, given an existing node and new 521.88 - children. The loc is only used to supply the constructor." 521.89 - {:added "1.0"} 521.90 - [loc node children] 521.91 - ((:zip/make-node (meta loc)) node children)) 521.92 - 521.93 -(defn path 521.94 - "Returns a seq of nodes leading to this loc" 521.95 - {:added "1.0"} 521.96 - [loc] 521.97 - (:pnodes (loc 1))) 521.98 - 521.99 -(defn lefts 521.100 - "Returns a seq of the left siblings of this loc" 521.101 - {:added "1.0"} 521.102 - [loc] 521.103 - (seq (:l (loc 1)))) 521.104 - 521.105 -(defn rights 521.106 - "Returns a seq of the right siblings of this loc" 521.107 - {:added "1.0"} 521.108 - [loc] 521.109 - (:r (loc 1))) 521.110 - 521.111 - 521.112 -(defn down 521.113 - "Returns the loc of the leftmost child of the node at this loc, or 521.114 - nil if no children" 521.115 - {:added "1.0"} 521.116 - [loc] 521.117 - (when (branch? loc) 521.118 - (let [[node path] loc 521.119 - [c & cnext :as cs] (children loc)] 521.120 - (when cs 521.121 - (with-meta [c {:l [] 521.122 - :pnodes (if path (conj (:pnodes path) node) [node]) 521.123 - :ppath path 521.124 - :r cnext}] (meta loc)))))) 521.125 - 521.126 -(defn up 521.127 - "Returns the loc of the parent of the node at this loc, or nil if at 521.128 - the top" 521.129 - {:added "1.0"} 521.130 - [loc] 521.131 - (let [[node {l :l, ppath :ppath, pnodes :pnodes r :r, changed? :changed?, :as path}] loc] 521.132 - (when pnodes 521.133 - (let [pnode (peek pnodes)] 521.134 - (with-meta (if changed? 521.135 - [(make-node loc pnode (concat l (cons node r))) 521.136 - (and ppath (assoc ppath :changed? true))] 521.137 - [pnode ppath]) 521.138 - (meta loc)))))) 521.139 - 521.140 -(defn root 521.141 - "zips all the way up and returns the root node, reflecting any 521.142 - changes." 521.143 - {:added "1.0"} 521.144 - [loc] 521.145 - (if (= :end (loc 1)) 521.146 - (node loc) 521.147 - (let [p (up loc)] 521.148 - (if p 521.149 - (recur p) 521.150 - (node loc))))) 521.151 - 521.152 -(defn right 521.153 - "Returns the loc of the right sibling of the node at this loc, or nil" 521.154 - {:added "1.0"} 521.155 - [loc] 521.156 - (let [[node {l :l [r & rnext :as rs] :r :as path}] loc] 521.157 - (when (and path rs) 521.158 - (with-meta [r (assoc path :l (conj l node) :r rnext)] (meta loc))))) 521.159 - 521.160 -(defn rightmost 521.161 - "Returns the loc of the rightmost sibling of the node at this loc, or self" 521.162 - {:added "1.0"} 521.163 - [loc] 521.164 - (let [[node {l :l r :r :as path}] loc] 521.165 - (if (and path r) 521.166 - (with-meta [(last r) (assoc path :l (apply conj l node (butlast r)) :r nil)] (meta loc)) 521.167 - loc))) 521.168 - 521.169 -(defn left 521.170 - "Returns the loc of the left sibling of the node at this loc, or nil" 521.171 - {:added "1.0"} 521.172 - [loc] 521.173 - (let [[node {l :l r :r :as path}] loc] 521.174 - (when (and path (seq l)) 521.175 - (with-meta [(peek l) (assoc path :l (pop l) :r (cons node r))] (meta loc))))) 521.176 - 521.177 -(defn leftmost 521.178 - "Returns the loc of the leftmost sibling of the node at this loc, or self" 521.179 - {:added "1.0"} 521.180 - [loc] 521.181 - (let [[node {l :l r :r :as path}] loc] 521.182 - (if (and path (seq l)) 521.183 - (with-meta [(first l) (assoc path :l [] :r (concat (rest l) [node] r))] (meta loc)) 521.184 - loc))) 521.185 - 521.186 -(defn insert-left 521.187 - "Inserts the item as the left sibling of the node at this loc, 521.188 - without moving" 521.189 - {:added "1.0"} 521.190 - [loc item] 521.191 - (let [[node {l :l :as path}] loc] 521.192 - (if (nil? path) 521.193 - (throw (new Exception "Insert at top")) 521.194 - (with-meta [node (assoc path :l (conj l item) :changed? true)] (meta loc))))) 521.195 - 521.196 -(defn insert-right 521.197 - "Inserts the item as the right sibling of the node at this loc, 521.198 - without moving" 521.199 - {:added "1.0"} 521.200 - [loc item] 521.201 - (let [[node {r :r :as path}] loc] 521.202 - (if (nil? path) 521.203 - (throw (new Exception "Insert at top")) 521.204 - (with-meta [node (assoc path :r (cons item r) :changed? true)] (meta loc))))) 521.205 - 521.206 -(defn replace 521.207 - "Replaces the node at this loc, without moving" 521.208 - {:added "1.0"} 521.209 - [loc node] 521.210 - (let [[_ path] loc] 521.211 - (with-meta [node (assoc path :changed? true)] (meta loc)))) 521.212 - 521.213 -(defn edit 521.214 - "Replaces the node at this loc with the value of (f node args)" 521.215 - {:added "1.0"} 521.216 - [loc f & args] 521.217 - (replace loc (apply f (node loc) args))) 521.218 - 521.219 -(defn insert-child 521.220 - "Inserts the item as the leftmost child of the node at this loc, 521.221 - without moving" 521.222 - {:added "1.0"} 521.223 - [loc item] 521.224 - (replace loc (make-node loc (node loc) (cons item (children loc))))) 521.225 - 521.226 -(defn append-child 521.227 - "Inserts the item as the rightmost child of the node at this loc, 521.228 - without moving" 521.229 - {:added "1.0"} 521.230 - [loc item] 521.231 - (replace loc (make-node loc (node loc) (concat (children loc) [item])))) 521.232 - 521.233 -(defn next 521.234 - "Moves to the next loc in the hierarchy, depth-first. When reaching 521.235 - the end, returns a distinguished loc detectable via end?. If already 521.236 - at the end, stays there." 521.237 - {:added "1.0"} 521.238 - [loc] 521.239 - (if (= :end (loc 1)) 521.240 - loc 521.241 - (or 521.242 - (and (branch? loc) (down loc)) 521.243 - (right loc) 521.244 - (loop [p loc] 521.245 - (if (up p) 521.246 - (or (right (up p)) (recur (up p))) 521.247 - [(node p) :end]))))) 521.248 - 521.249 -(defn prev 521.250 - "Moves to the previous loc in the hierarchy, depth-first. If already 521.251 - at the root, returns nil." 521.252 - {:added "1.0"} 521.253 - [loc] 521.254 - (if-let [lloc (left loc)] 521.255 - (loop [loc lloc] 521.256 - (if-let [child (and (branch? loc) (down loc))] 521.257 - (recur (rightmost child)) 521.258 - loc)) 521.259 - (up loc))) 521.260 - 521.261 -(defn end? 521.262 - "Returns true if loc represents the end of a depth-first walk" 521.263 - {:added "1.0"} 521.264 - [loc] 521.265 - (= :end (loc 1))) 521.266 - 521.267 -(defn remove 521.268 - "Removes the node at loc, returning the loc that would have preceded 521.269 - it in a depth-first walk." 521.270 - {:added "1.0"} 521.271 - [loc] 521.272 - (let [[node {l :l, ppath :ppath, pnodes :pnodes, rs :r, :as path}] loc] 521.273 - (if (nil? path) 521.274 - (throw (new Exception "Remove at top")) 521.275 - (if (pos? (count l)) 521.276 - (loop [loc (with-meta [(peek l) (assoc path :l (pop l) :changed? true)] (meta loc))] 521.277 - (if-let [child (and (branch? loc) (down loc))] 521.278 - (recur (rightmost child)) 521.279 - loc)) 521.280 - (with-meta [(make-node loc (peek pnodes) rs) 521.281 - (and ppath (assoc ppath :changed? true))] 521.282 - (meta loc)))))) 521.283 - 521.284 -(comment 521.285 - 521.286 -(load-file "/Users/rich/dev/clojure/src/zip.clj") 521.287 -(refer 'zip) 521.288 -(def data '[[a * b] + [c * d]]) 521.289 -(def dz (vector-zip data)) 521.290 - 521.291 -(right (down (right (right (down dz))))) 521.292 -(lefts (right (down (right (right (down dz)))))) 521.293 -(rights (right (down (right (right (down dz)))))) 521.294 -(up (up (right (down (right (right (down dz))))))) 521.295 -(path (right (down (right (right (down dz)))))) 521.296 - 521.297 -(-> dz down right right down right) 521.298 -(-> dz down right right down right (replace '/) root) 521.299 -(-> dz next next (edit str) next next next (replace '/) root) 521.300 -(-> dz next next next next next next next next next remove root) 521.301 -(-> dz next next next next next next next next next remove (insert-right 'e) root) 521.302 -(-> dz next next next next next next next next next remove up (append-child 'e) root) 521.303 - 521.304 -(end? (-> dz next next next next next next next next next remove next)) 521.305 - 521.306 -(-> dz next remove next remove root) 521.307 - 521.308 -(loop [loc dz] 521.309 - (if (end? loc) 521.310 - (root loc) 521.311 - (recur (next (if (= '* (node loc)) 521.312 - (replace loc '/) 521.313 - loc))))) 521.314 - 521.315 -(loop [loc dz] 521.316 - (if (end? loc) 521.317 - (root loc) 521.318 - (recur (next (if (= '* (node loc)) 521.319 - (remove loc) 521.320 - loc))))) 521.321 -)
522.1 --- a/src/laser/rasterize.clj Sat Aug 21 06:25:44 2010 -0400 522.2 +++ b/src/laser/rasterize.clj Tue Aug 24 19:06:45 2010 -0400 522.3 @@ -13,14 +13,14 @@ 522.4 (import '(java.io BufferedReader InputStreamReader)) 522.5 (import '(java.awt.image BufferedImage)) 522.6 522.7 -(use 'clojure.contrib.str-utils) 522.8 -(use 'clojure.contrib.seq-utils) 522.9 -(use 'clojure.contrib.combinatorics) 522.10 -(use 'clojure.contrib.duck-streams) 522.11 +;(use 'clojure.contrib.str-utils) 522.12 +;(use 'clojure.contrib.seq-utils) 522.13 +;(use 'clojure.contrib.combinatorics) 522.14 +;(use 'clojure.contrib.duck-streams) 522.15 522.16 -(use 'clojure.contrib.repl-utils) 522.17 +;(use 'clojure.contrib.repl-utils) 522.18 522.19 -(set! *print-length* 20) 522.20 +;(set! *print-length* 20) 522.21 522.22 522.23 522.24 @@ -77,7 +77,7 @@ 522.25 (def white {:r 255, :g 255, :b 255}) 522.26 (def black {:r 0, :g 0, :b 0}) 522.27 522.28 -(def expt #(Math/pow %1 %2)) 522.29 + 522.30 522.31 (defn rgb-euclidian 522.32 [{r1 :r g1 :g b1 :b} {r2 :r g2 :g b2 :b} ] 522.33 @@ -205,34 +205,40 @@ 522.34 ; (println prevoius) 522.35 ; (println range-start) 522.36 (if (<= new-n (+ prevoius 1)) 522.37 - (do ;(println "join") 522.38 + (do ;(println "join") 522.39 ;(println (butlast collection)) 522.40 - (conj (apply vector (butlast collection)) (vector range-start new-n))) 522.41 - (conj collection (vector new-n new-n))))) 522.42 + (conj (apply vector (butlast collection)) 522.43 + (vector range-start new-n))) 522.44 + (conj collection (vector new-n new-n))))) 522.45 522.46 base 522.47 - (map first row)))) 522.48 + (map first row)))) 522.49 + 522.50 522.51 522.52 522.53 (defn row->gmask [[x-dpi y-dpi] forward? row] 522.54 +; (println forward?) 522.55 + (let [start (float (* (/ x-dpi) (first (first 522.56 + (if forward? 522.57 + (reverse row) row)))))] 522.58 522.59 - (let [start (float (* (/ x-dpi) (first (first row))))] 522.60 - 522.61 - (let [preamble (if forward? 522.62 - (str 522.63 + (let [preamble (if-not forward? 522.64 (format "0 0 0 %.3f\n" start) 522.65 - (format "0 0 1 %.3f\n" start))) 522.66 + (format "0 0 1 %.3f\n" start)) 522.67 body 522.68 - (for [[x y] (gather-row row)] 522.69 + (for [[x y] 522.70 + (if forward? 522.71 + (reverse (gather-row row)) 522.72 + (gather-row row))] 522.73 (let [x (float (* x (/ x-dpi))) 522.74 y (float (* y (/ x-dpi)))] 522.75 - (if forward? 522.76 + (if-not forward? 522.77 (str (format "0 0 1 %.3f\n" x) 522.78 (format "0 1 1 %.3f\n" y)) 522.79 522.80 - (str (format "0 0 0 %.3f\n" x) 522.81 - (format "0 1 0 %.3f\n" y)))))] 522.82 + (str (format "0 0 0 %.3f\n" y) 522.83 + (format "0 1 0 %.3f\n" x)))))] 522.84 522.85 (str preamble (str-join "" body))))) 522.86 522.87 @@ -251,9 +257,10 @@ 522.88 522.89 (str "1 0 0 0\n" 522.90 (str-join "" (map (fn [[index row]] 522.91 - (row->gmask dpi (odd? index) row)) 522.92 + (row->gmask dpi (even? index) row)) 522.93 (indexed (make-rows pic)))))) 522.94 522.95 + 522.96 ;; 1 0 0 0 522.97 ;; 0 0 1 2.881 522.98 ;; 0 0 0 2.881 522.99 @@ -302,7 +309,26 @@ 522.100 (spit "/home/r/kevin/out.gmask" (generate-gmask image)) 522.101 image)) 522.102 522.103 - 522.104 + 522.105 + 522.106 +(defn update-state [] 522.107 +(def sing "/home/r/lasercutter/graster/signer4laser2x1.png") 522.108 + 522.109 +(def pic (frame-hash (let [image (ImagePlus. sing)] 522.110 + (.rotate (.getChannelProcessor image) 180) 522.111 + image))) 522.112 + 522.113 +(def pic (b&w pic))) 522.114 + 522.115 + 522.116 + 522.117 + 522.118 + 522.119 + 522.120 + 522.121 + 522.122 + 522.123 + 522.124 522.125 ;;;; testing 522.126 522.127 @@ -339,6 +365,6 @@ 522.128 (.start 522.129 (Thread. 522.130 (fn [] 522.131 - (with-bindings {#'clojure.core/*out* temp} 522.132 + (with-bindings {#'*out* temp} 522.133 (Thread/sleep 5000) 522.134 (println "hi")))))))