Permalink
Browse files

merge from master

  • Loading branch information...
paulk-asert committed Mar 30, 2012
2 parents 9057be3 + 42186ec commit 322578724aac0b5d7a60e85313471e1046c766ba
Showing with 4,010 additions and 2,942 deletions.
  1. +16 −16 .classpath
  2. +23 −22 .externalToolBuilders/Groovy ensureGrammars.launch
  3. +0 −1 .project
  4. +9 −11 benchmark/bench/ackermann.groovy
  5. +4 −4 benchmark/bench/ackermann.java
  6. +9 −9 benchmark/bench/ary.groovy
  7. +9 −9 benchmark/bench/ary.java
  8. +49 −48 benchmark/bench/binarytrees.groovy
  9. +63 −63 benchmark/bench/binarytrees.java
  10. +123 −123 benchmark/bench/chameneos.java
  11. +49 −49 benchmark/bench/echo.java
  12. +29 −29 benchmark/bench/except.java
  13. +7 −6 benchmark/bench/fannkuch.groovy
  14. +21 −21 benchmark/bench/fannkuchredux.java
  15. +4 −4 benchmark/bench/fibo.java
  16. +18 −18 benchmark/bench/hash.java
  17. +21 −21 benchmark/bench/hash2.java
  18. +43 −43 benchmark/bench/heapsort.groovy
  19. +40 −40 benchmark/bench/heapsort.java
  20. +6 −9 benchmark/bench/hello.groovy
  21. +1 −1 benchmark/bench/hello.java
  22. +97 −97 benchmark/bench/knucleotide.java
  23. +47 −47 benchmark/bench/lists.java
  24. +36 −46 benchmark/bench/mandelbrot.groovy
  25. +32 −32 benchmark/bench/matrix.java
  26. +26 −26 benchmark/bench/methcall.java
  27. +154 −154 benchmark/bench/nbody.java
  28. +10 −10 benchmark/bench/nestedloop.java
  29. +34 −33 benchmark/bench/nsieve.groovy
  30. +30 −30 benchmark/bench/objinst.java
  31. +8 −15 benchmark/bench/random.groovy
  32. +10 −10 benchmark/bench/random.java
  33. +77 −77 benchmark/bench/raytracer.java
  34. +25 −26 benchmark/bench/recursive.groovy
  35. +40 −34 benchmark/bench/regexdna.groovy
  36. +51 −52 benchmark/bench/revcomp.groovy
  37. +24 −18 benchmark/bench/revcomp.java
  38. +19 −19 benchmark/bench/sieve.java
  39. +17 −21 benchmark/bench/spectralnorm.groovy
  40. +69 −69 benchmark/bench/spectralnorm.java
  41. +17 −17 benchmark/bench/spellcheck.java
  42. +5 −5 benchmark/bench/strcat.java
  43. +8 −8 benchmark/bench/takfp.java
  44. +46 −46 benchmark/bench/threadring.groovy
  45. +1 −1 benchmark/bench/wc.java
  46. +12 −29 benchmark/bench/wordfreq.groovy
  47. +7 −6 benchmark/bench/wordfreq.java
  48. +7 −8 build.gradle
  49. +2 −0 build.properties
  50. +37 −14 build.xml
  51. +18 −18 config/codenarc/codenarc.groovy
  52. +3 −2 config/maven/groovy-tools.pom
  53. +11 −10 pom.xml
  54. +12 −12 src/main/groovy/lang/GroovyClassLoader.java
  55. +5 −5 src/main/groovy/lang/MetaClassImpl.java
  56. +11 −11 src/main/groovy/util/GroovyScriptEngine.java
  57. +29 −29 src/main/org/codehaus/groovy/antlr/java/Groovifier.java
  58. +202 −202 src/main/org/codehaus/groovy/antlr/java/Java2GroovyConverter.java
  59. +3 −3 src/main/org/codehaus/groovy/antlr/java/Java2GroovyMain.java
  60. +69 −69 src/main/org/codehaus/groovy/antlr/java/PreJava2GroovyConverter.java
  61. +9 −0 src/main/org/codehaus/groovy/ast/CompileUnit.java
  62. +8 −8 src/main/org/codehaus/groovy/ast/expr/MethodCallExpression.java
  63. +4 −4 src/main/org/codehaus/groovy/ast/tools/WideningCategories.java
  64. +65 −67 src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
  65. +26 −13 src/main/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java
  66. +22 −12 src/main/org/codehaus/groovy/classgen/asm/BinaryExpressionMultiTypeDispatcher.java
  67. +179 −179 src/main/org/codehaus/groovy/classgen/asm/CompileStack.java
  68. +6 −6 src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
  69. +14 −9 src/main/org/codehaus/groovy/classgen/asm/StatementWriter.java
  70. +24 −2 src/main/org/codehaus/groovy/classgen/asm/WriterController.java
  71. +204 −0 src/main/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java
  72. +46 −6 src/main/org/codehaus/groovy/control/CompilationUnit.java
  73. +4 −0 src/main/org/codehaus/groovy/reflection/ParameterTypes.java
  74. +2 −0 src/main/org/codehaus/groovy/reflection/ReflectionUtils.java
  75. +8 −8 src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
  76. +33 −33 src/main/org/codehaus/groovy/runtime/GroovyCategorySupport.java
  77. +6 −6 src/main/org/codehaus/groovy/runtime/InvokerHelper.java
  78. +8 −10 src/main/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
  79. +5 −3 src/main/org/codehaus/groovy/runtime/callsite/GroovySunClassLoader.java
  80. +23 −0 src/main/org/codehaus/groovy/runtime/metaclass/DefaultMetaClassInfo.java
  81. +1 −0 src/main/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
  82. +4 −0 src/main/org/codehaus/groovy/runtime/metaclass/ReflectionMetaMethod.java
  83. +2 −2 src/main/org/codehaus/groovy/runtime/metaclass/TemporaryMethodKey.java
  84. +1 −1 src/main/org/codehaus/groovy/tools/DgmConverter.java
  85. +1 −0 src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
  86. +11 −11 src/main/org/codehaus/groovy/tools/javac/JavaAwareCompilationUnit.java
  87. +4 −4 src/main/org/codehaus/groovy/transform/StaticTypesTransformation.java
  88. +23 −23 src/main/org/codehaus/groovy/transform/stc/SharedVariableCollector.java
  89. +2 −2 src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
  90. +66 −69 src/main/org/codehaus/groovy/vmplugin/VMPluginFactory.java
  91. +699 −0 src/main/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
  92. +2 −2 src/test-resources/stubgenerator/circularLanguageReference/Shape.java
  93. +4 −4 src/test-resources/stubgenerator/circularLanguageReference/Square.java
  94. +2 −2 src/test/gls/generics/GenericsTestBase.java
  95. +1 −1 src/test/groovy/StaticImportTarget.groovy
  96. +1 −1 src/test/groovy/bugs/Groovy3208Bug.groovy
  97. +2 −2 src/test/groovy/bugs/Groovy3465Helper.groovy
  98. +27 −27 src/test/groovy/bugs/Groovy5030Bug.groovy
  99. +3 −3 src/test/groovy/bugs/Groovy5033Bug.groovy
  100. +38 −38 src/test/groovy/bugs/Groovy5056Bug.groovy
  101. +18 −18 src/test/groovy/bugs/Groovy5193Bug.groovy
  102. +27 −27 src/test/groovy/bugs/VerifyErrorBug.groovy
  103. +2 −2 src/test/groovy/lang/MixinAnnotationTest.groovy
  104. +3 −3 src/test/groovy/lang/MixinTest.groovy
  105. +60 −60 src/test/org/codehaus/groovy/benchmarks/vm5/spectralnorm.java
  106. +4 −3 src/test/org/codehaus/groovy/classgen/DumpingClassLoader.java
  107. +2 −2 src/test/org/codehaus/groovy/classgen/JO.java
  108. +12 −31 src/test/org/codehaus/groovy/classgen/asm/AbstractBytecodeTestCase.groovy
  109. +1 −1 src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
  110. +278 −223 subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
  111. +4 −2 subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/VerifyClass.java
  112. +2 −2 subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapter.groovy
  113. +1 −1 subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
  114. +3 −3 ...ojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/ReflectionCompletor.groovy
  115. +21 −21 subprojects/groovy-swing/src/main/groovy/groovy/swing/factory/CellEditorFactory.groovy
  116. +31 −31 subprojects/groovy-swing/src/main/groovy/groovy/swing/factory/ColumnFactory.groovy
  117. +96 −96 subprojects/groovy-swing/src/main/groovy/groovy/swing/impl/ClosureCellEditor.groovy
View
@@ -9,39 +9,39 @@
<classpathentry kind="src" output="bin" path="subprojects/groovy-jmx/src/test/groovy"/>
<classpathentry kind="src" output="bin" path="subprojects/groovy-jmx/src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.8.1/ant-1.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.8.2/ant-1.8.2.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/servlet/jsp-api/2.0/jsp-api-2.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm-tree/3.2/asm-tree-3.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm/4.0/asm-4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-analysis/4.0/asm-analysis-4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-commons/4.0/asm-commons-4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-tree/4.0/asm-tree-4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-util/4.0/asm-util-4.0.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar" sourcepath="M2_REPO/javax/servlet/servlet-api/2.4/servlet-api-2.4-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/bsf/bsf/2.4.0/bsf-2.4.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar"/>
+ <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.7/antlr-2.7.7.jar"/>
<classpathentry kind="var" path="M2_REPO/jmock/jmock-cglib/1.2.0/jmock-cglib-1.2.0.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-junit/1.8.2/ant-junit-1.8.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/commons-cli/commons-cli/1.0/commons-cli-1.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar"/>
- <classpathentry kind="var" path="M2_REPO/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm-analysis/3.2/asm-analysis-3.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-cli/commons-cli/1.2/commons-cli-1.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/hsqldb/hsqldb/1.8.0.10/hsqldb-1.8.0.10.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/thoughtworks/xstream/xstream/1.4.1/xstream-1.4.1.jar"/>
<classpathentry kind="var" path="M2_REPO/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar"/>
<classpathentry kind="var" path="M2_REPO/jmock/jmock/1.2.0/jmock-1.2.0.jar"/>
<classpathentry kind="var" path="M2_REPO/openejb/openejb-loader/1.0/openejb-loader-1.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm/3.2/asm-3.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/asm/asm-util/3.2/asm-util-3.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.8.1/ant-launcher-1.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.8.2/ant-launcher-1.8.2.jar"/>
<classpathentry kind="lib" path="security/GroovyJarTest.jar"/>
<classpathentry kind="var" path="M2_REPO/jline/jline/0.9.94/jline-0.9.94.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-testutil/1.8.2/ant-testutil-1.8.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.10/junit-4.10.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
<classpathentry kind="var" path="M2_REPO/xmlunit/xmlunit/1.3/xmlunit-1.3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/fusesource/jansi/jansi/1.2.1/jansi-1.2.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/fusesource/jansi/jansi/1.7/jansi-1.7.jar"/>
<classpathentry kind="var" path="M2_REPO/ch/qos/logback/logback-classic/0.9.21/logback-classic-0.9.21.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/objectweb/asm/com.springsource.org.objectweb.asm.commons/2.2.3/com.springsource.org.objectweb.asm.commons-2.2.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/com/thoughtworks/qdox/qdox/1.8/qdox-1.8.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/thoughtworks/qdox/qdox/1.12/qdox-1.12.jar"/>
<classpathentry kind="var" path="M2_REPO/ch/qos/logback/logback-core/0.9.21/logback-core-0.9.21.jar"/>
<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.0/slf4j-api-1.6.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/jcl-over-slf4j/1.6.0/jcl-over-slf4j-1.6.0.jar"/>
<classpathentry kind="lib" path="target/classes"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -1,22 +1,23 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
-<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="ensureGrammars,"/>
-<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="ensureGrammars,"/>
-<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
-<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/groovy/build.xml"/>
-</listAttribute>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="1"/>
-</listAttribute>
-<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
-<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
-<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="groovy"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/groovy/build.xml}"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
-<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${project_loc:/groovy}"/>
-</launchConfiguration>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
+<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="ensureGrammars,"/>
+<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="ensureGrammars,"/>
+<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
+<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/groovy/build.xml"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
+<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
+<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
+<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="true"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc:build.xml}"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
+<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${project_loc:}"/>
+</launchConfiguration>
View
@@ -24,6 +24,5 @@
<natures>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.codehaus.groovy.eclipse.groovyNature</nature>
</natures>
</projectDescription>
@@ -1,18 +1,16 @@
/*
-The Computer Language Shootout
-http://shootout.alioth.debian.org/
-
-contributed by Jochen Hinrichsen
-*/
+ * The Computer Language Shootout
+ * http://shootout.alioth.debian.org/
+ *
+ * contributed by Jochen Hinrichsen
+ */
def A(x, y) {
- // TODO: return statement is stated optional, but does not work w/o
- if (x == 0) return y+1
- if (y == 0) return A(x-1, 1)
- return A(x-1, A(x, y-1))
+ if (x == 0) return y+1
+ if (y == 0) return A(x-1, 1)
+ return A(x-1, A(x, y-1))
}
-def n = this.args[0].toInteger()
+def n = args[0].toInteger()
def result = A(3, n)
println("Ack(3,${n}): ${result}")
-
@@ -3,11 +3,11 @@
public class ackermann {
public static void main(String[] args) {
- int num = Integer.parseInt(args[0]);
- System.out.println("Ack(3," + num + "): " + Ack(3, num));
+ int num = Integer.parseInt(args[0]);
+ System.out.println("Ack(3," + num + "): " + Ack(3, num));
}
public static int Ack(int m, int n) {
- return (m == 0) ? (n + 1) : ((n == 0) ? Ack(m-1, 1) :
- Ack(m-1, Ack(m, n - 1)));
+ return (m == 0) ? (n + 1) : ((n == 0) ? Ack(m-1, 1) :
+ Ack(m-1, Ack(m, n - 1)));
}
}
View
@@ -10,16 +10,16 @@
public class ary {
public static void main(String[] args) {
- int i, j, k, n = Integer.parseInt(args[0]);
- int[] x = new int[n];
- int[] y = new int[n];
+ int i, j, k, n = Integer.parseInt(args[0]);
+ int[] x = new int[n];
+ int[] y = new int[n];
- for (i = 0; i < n; i++)
- x[i] = i + 1;
- for (k = 0; k < 1000; k++ )
- for (j = n-1; j >= 0; j--)
- y[j] += x[j];
+ for (i = 0; i < n; i++)
+ x[i] = i + 1;
+ for (k = 0; k < 1000; k++ )
+ for (j = n-1; j >= 0; j--)
+ y[j] += x[j];
- System.out.println(y[0] + " " + y[n-1]);
+ System.out.println(y[0] + " " + y[n-1]);
}
}
View
@@ -12,16 +12,16 @@
public class ary {
public static void main(String args[]) {
- int i, j, k, n = Integer.parseInt(args[0]);
- int x[] = new int[n];
- int y[] = new int[n];
+ int i, j, k, n = Integer.parseInt(args[0]);
+ int x[] = new int[n];
+ int y[] = new int[n];
- for (i = 0; i < n; i++)
- x[i] = i + 1;
- for (k = 0; k < 1000; k++ )
- for (j = n-1; j >= 0; j--)
- y[j] += x[j];
+ for (i = 0; i < n; i++)
+ x[i] = i + 1;
+ for (k = 0; k < 1000; k++ )
+ for (j = n-1; j >= 0; j--)
+ y[j] += x[j];
- System.out.println(y[0] + " " + y[n-1]);
+ System.out.println(y[0] + " " + y[n-1]);
}
}
@@ -1,63 +1,64 @@
-/* The Computer Language Benchmarks Game
- http://shootout.alioth.debian.org/
- contributed by Jochen Hinrichsen
- modified by Marko Kocic
-*/
+/*
+ * The Computer Language Benchmarks Game
+ * http://shootout.alioth.debian.org/
+ *
+ * contributed by Jochen Hinrichsen
+ * modified by Marko Kocic
+ */
final class TreeNode {
- private final left, right, item
-
- TreeNode(item){
- this.item = item
- }
-
- private static bottomUpTree(item, depth) {
- if (depth>0) {
- return new TreeNode(
- bottomUpTree(2*item-1, depth-1)
- , bottomUpTree(2*item, depth-1)
- , item
- )
- } else {
- return new TreeNode(item)
- }
- }
-
- TreeNode(left, right, item){
- this.left = left
- this.right = right
- this.item = item
- }
-
- private itemCheck(){
- // if necessary deallocate here
- if (left==null) return item
- else return item + left.itemCheck() - right.itemCheck()
- }
-}
+ private final left, right, item
+
+ TreeNode(item) {
+ this.item = item
+ }
+
+ private static bottomUpTree(item, depth) {
+ if (depth > 0) {
+ return new TreeNode(
+ bottomUpTree(2*item-1, depth-1),
+ bottomUpTree(2*item, depth-1),
+ item
+ )
+ } else {
+ return new TreeNode(item)
+ }
+ }
+ TreeNode(left, right, item) {
+ this.left = left
+ this.right = right
+ this.item = item
+ }
+
+ private itemCheck() {
+ // if necessary deallocate here
+ if (left == null) return item
+ else return item + left.itemCheck() - right.itemCheck()
+ }
+}
def n = (args.length == 0) ? 10 : args[0].toInteger()
def minDepth = 4
-def maxDepth = [ minDepth + 2, n].max()
+def maxDepth = [minDepth + 2, n].max()
def stretchDepth = maxDepth + 1
-def check = (TreeNode.bottomUpTree(0,stretchDepth)).itemCheck()
+def check = (TreeNode.bottomUpTree(0, stretchDepth)).itemCheck()
println "stretch tree of depth ${stretchDepth}\t check: ${check}"
-def longLivedTree = TreeNode.bottomUpTree(0,maxDepth)
+def longLivedTree = TreeNode.bottomUpTree(0, maxDepth)
-def depth=minDepth
-while (depth<=maxDepth) {
- def iterations = 1 << (maxDepth - depth + minDepth)
- check = 0
- for (i in 1..iterations) {
- check += (TreeNode.bottomUpTree(i,depth)).itemCheck()
- check += (TreeNode.bottomUpTree(-i,depth)).itemCheck()
- }
+def depth = minDepth
+while (depth <= maxDepth) {
+ def iterations = 1 << (maxDepth - depth + minDepth)
+ check = 0
+ for (i in 1..iterations) {
+ check += (TreeNode.bottomUpTree(i, depth)).itemCheck()
+ check += (TreeNode.bottomUpTree(-i,depth)).itemCheck()
+ }
- println "${iterations*2}\t trees of depth ${depth}\t check: ${check}"
- depth+=2
+ println "${iterations*2}\t trees of depth ${depth}\t check: ${check}"
+ depth += 2
}
println "long lived tree of depth ${maxDepth}\t check: ${longLivedTree.itemCheck()}"
Oops, something went wrong.

0 comments on commit 3225787

Please sign in to comment.