From: <th...@us...> - 2009-03-02 15:59:24
|
Revision: 6055 http://jython.svn.sourceforge.net/jython/?rev=6055&view=rev Author: thobes Date: 2009-03-02 15:59:20 +0000 (Mon, 02 Mar 2009) Log Message: ----------- Moving the advanced branch. All useful things imported. At this point there are two patches to jython for integrating the advanced compiler: * One patch to make the flags that are passed around in compilation type safe. * One patch to decouple the compiler implementation and provide an extension point where a new compiler can be inserted. Modified Paths: -------------- trunk/sandbox/tobias/.hg/patches/series trunk/sandbox/tobias/.hgignore trunk/sandbox/tobias/README.txt trunk/sandbox/tobias/compiler/src/org/python/compiler/AdvancedCompiler.java trunk/sandbox/tobias/compiler/src/org/python/compiler/AdvancedPreferences.java trunk/sandbox/tobias/compiler/src/org/python/compiler/CodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/CompilerDirector.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ConstantChecker.java trunk/sandbox/tobias/compiler/src/org/python/compiler/DirectCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/DirectGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/FlowGraphBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/FlowGraphGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/GeneratedCodeState.java trunk/sandbox/tobias/compiler/src/org/python/compiler/IntermediateCodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/IntermediateCodeGeneratorFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/PragmaParser.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopeInformation.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopesBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/EnvironmentHolder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/Block.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/CodeGraph.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/Constant.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/ValueOperation.java Added Paths: ----------- trunk/sandbox/tobias/.classpath trunk/sandbox/tobias/.externalToolBuilders/ trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch trunk/sandbox/tobias/.hg/hgrc trunk/sandbox/tobias/.hg/patches/decouple.patch trunk/sandbox/tobias/.hg/patches/types.patch trunk/sandbox/tobias/.project trunk/sandbox/tobias/.settings/ trunk/sandbox/tobias/.settings/org.eclipse.jdt.core.prefs trunk/sandbox/tobias/agent/ trunk/sandbox/tobias/agent/build.xml trunk/sandbox/tobias/agent/src/ trunk/sandbox/tobias/agent/src/org/python/javaagent/InstrumentationProxy.java trunk/sandbox/tobias/build.xml trunk/sandbox/tobias/bytecode/ trunk/sandbox/tobias/bytecode/build.xml trunk/sandbox/tobias/bytecode/src/ trunk/sandbox/tobias/bytecode/src/org/ trunk/sandbox/tobias/bytecode/src/org/python/ trunk/sandbox/tobias/bytecode/src/org/python/bytecode/ trunk/sandbox/tobias/compiler/build.xml trunk/sandbox/tobias/compiler/src/ trunk/sandbox/tobias/compiler/src/org/ trunk/sandbox/tobias/compiler/src/org/python/ trunk/sandbox/tobias/compiler/src/org/python/compiler/ trunk/sandbox/tobias/compiler/src/org/python/compiler/BytecodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/BytecodeCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/CodeGeneratorGraphVisitor.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/BlockBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/BlockBuilderImpl.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/BlockState.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/BlockTermination.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/CodeGraphFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/CodeGraphVisitor.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/CodeReference.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/ConsumerCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/GraphInfo.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/Instruction.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/ProducerCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/flowgraph/SimpleCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/ trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/Construct.java trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/Define.java trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/Exception.java trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/Import.java trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/Invocation.java trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/MemoryOperation.java trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/Operator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/SystemCalls.java trunk/sandbox/tobias/compiler/src/org/python/compiler/instructions/TypeOperation.java trunk/sandbox/tobias/compiler/src/org/thobe/ trunk/sandbox/tobias/compiler/src/org/thobe/compiler/ trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Graph.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/GraphVisitor.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/HandlerBlock.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/IfNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Node.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/OpNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/PhiNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/SwitchNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Value.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ValueNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ValueOperation.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ValueType.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/VariableLocation.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/VoidOperation.java trunk/sandbox/tobias/util/ trunk/sandbox/tobias/util/build.xml trunk/sandbox/tobias/util/src/ trunk/sandbox/tobias/util/src/org/ trunk/sandbox/tobias/util/src/org/python/ trunk/sandbox/tobias/util/src/org/python/code/ trunk/sandbox/tobias/util/src/org/python/hash/ Property Changed: ---------------- trunk/sandbox/tobias/ trunk/sandbox/tobias/.hg/patches/ trunk/sandbox/tobias/compiler/ Property changes on: trunk/sandbox/tobias ___________________________________________________________________ Modified: svn:externals - jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython + jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython frame https://projects.thobe.org/svn/public/javaframe Added: svn:ignore + target Added: trunk/sandbox/tobias/.classpath =================================================================== --- trunk/sandbox/tobias/.classpath (rev 0) +++ trunk/sandbox/tobias/.classpath 2009-03-02 15:59:20 UTC (rev 6055) @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry excluding="com/ziclix/python/sql/|com/ziclix/python/sql/connect/|com/ziclix/python/sql/handler/|com/ziclix/python/sql/pipe/|com/ziclix/python/sql/pipe/csv/|com/ziclix/python/sql/pipe/db/|com/ziclix/python/sql/procedure/|com/ziclix/python/sql/resource/|com/ziclix/python/sql/util/" kind="src" path="jython/src"/> + <classpathentry excluding="org/python/compiler/advanced/ast/" kind="src" path="compiler/src"/> + <classpathentry kind="src" path="util/src"/> + <classpathentry kind="src" path="bytecode/src"/> + <classpathentry kind="src" path="agent/src"/> + <classpathentry kind="src" path="frame/src"/> + <classpathentry kind="src" path="frame/test"/> + <classpathentry kind="src" path="jython/build/gensrc"/> + <classpathentry kind="src" path="jython/tests/java"/> + <classpathentry kind="lib" path="jython/Demo/jreload/example.jar"/> + <classpathentry kind="lib" path="jython/extlibs/antlr-2.7.7.jar"/> + <classpathentry kind="lib" path="jython/extlibs/asm-3.1.jar"/> + <classpathentry kind="lib" path="jython/extlibs/asm-commons-3.1.jar"/> + <classpathentry kind="lib" path="jython/extlibs/asm-util-3.1.jar"/> + <classpathentry kind="lib" path="jython/extlibs/constantine-0.4.jar"/> + <classpathentry kind="lib" path="jython/extlibs/cpptasks/cpptasks.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jarjar-0.7.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jline-0.9.94.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jna-posix.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jna.jar"/> + <classpathentry kind="lib" path="jython/extlibs/junit-3.8.2.jar"/> + <classpathentry kind="lib" path="jython/extlibs/libreadline-java-0.8.jar"/> + <classpathentry kind="lib" path="jython/extlibs/mysql-connector-java-5.1.6.jar"/> + <classpathentry kind="lib" path="jython/extlibs/postgresql-8.3-603.jdbc4.jar"/> + <classpathentry kind="lib" path="jython/extlibs/profile.jar"/> + <classpathentry kind="lib" path="jython/extlibs/servlet-api-2.5.jar"/> + <classpathentry kind="lib" path="jython/extlibs/stringtemplate-3.2.jar"/> + <classpathentry kind="lib" path="jython/extlibs/svnant-jars/svnant.jar"/> + <classpathentry kind="lib" path="jython/extlibs/svnant-jars/svnClientAdapter.jar"/> + <classpathentry kind="lib" path="jython/extlibs/svnant-jars/svnjavahl.jar"/> + <classpathentry kind="lib" path="jython/extlibs/xercesImpl-2.9.1.jar"/> + <classpathentry kind="lib" path="jython/Lib/test/blob.jar"/> + <classpathentry kind="lib" path="jython/Lib/test/bug1239.jar"/> + <classpathentry kind="lib" path="jython/Lib/test/classimport_Lib.jar"/> + <classpathentry kind="lib" path="jython/Lib/test/classimport.jar"/> + <classpathentry kind="lib" path="jython/Lib/test/syspath_import.jar"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5.0 (Mac OS X default)"/> + <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> + <classpathentry kind="lib" path="jython/extlibs/antlr-3.1.2.jar"/> + <classpathentry kind="lib" path="jython/extlibs/antlr-runtime-3.1.2.jar"/> + <classpathentry kind="output" path="target/build"/> +</classpath> Added: trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch =================================================================== --- trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch (rev 0) +++ trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-03-02 15:59:20 UTC (rev 6055) @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?><launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="antlr_gen,"/> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="antlr_gen,"/> +<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="/advanced-compiler/jython/build.xml"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="1"/> +</listAttribute> +<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="advanced-compiler"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/advanced-compiler/jython/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"/> +</launchConfiguration> Added: trunk/sandbox/tobias/.hg/hgrc =================================================================== --- trunk/sandbox/tobias/.hg/hgrc (rev 0) +++ trunk/sandbox/tobias/.hg/hgrc 2009-03-02 15:59:20 UTC (rev 6055) @@ -0,0 +1,3 @@ +[diff] +nodates=1 +git=1 Property changes on: trunk/sandbox/tobias/.hg/patches ___________________________________________________________________ Modified: svn:ignore - status + status guards Added: trunk/sandbox/tobias/.hg/patches/decouple.patch =================================================================== --- trunk/sandbox/tobias/.hg/patches/decouple.patch (rev 0) +++ trunk/sandbox/tobias/.hg/patches/decouple.patch 2009-03-02 15:59:20 UTC (rev 6055) @@ -0,0 +1,375 @@ +diff --git a/jython/src/org/python/compiler/LegacyCompiler.java b/jython/src/org/python/compiler/LegacyCompiler.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/compiler/LegacyCompiler.java +@@ -0,0 +1,72 @@ ++package org.python.compiler; ++ ++import java.io.ByteArrayOutputStream; ++import java.io.OutputStream; ++ ++import org.python.antlr.base.mod; ++import org.python.core.BytecodeLoader; ++import org.python.core.CompilerFlags; ++import org.python.core.Py; ++import org.python.core.PyCode; ++import org.python.core.PythonCodeBundle; ++import org.python.core.PythonCompiler; ++ ++public class LegacyCompiler implements PythonCompiler { ++ ++ public PythonCodeBundle compile(mod node, String name, String filename, ++ boolean linenumbers, boolean printResults, CompilerFlags cflags) { ++ return new LazyLegacyBundle(node, name, filename, linenumbers, ++ printResults, cflags); ++ } ++ ++ private static class LazyLegacyBundle implements PythonCodeBundle { ++ ++ private final mod node; ++ private final String name; ++ private final String filename; ++ private final boolean linenumbers; ++ private final boolean printResults; ++ private final CompilerFlags cflags; ++ private ByteArrayOutputStream ostream = null; ++ ++ public LazyLegacyBundle(mod node, String name, String filename, ++ boolean linenumbers, boolean printResults, CompilerFlags cflags) { ++ this.node = node; ++ this.name = name; ++ this.filename = filename; ++ this.linenumbers = linenumbers; ++ this.printResults = printResults; ++ this.cflags = cflags; ++ } ++ ++ public PyCode loadCode() throws Exception { ++ return BytecodeLoader.makeCode(name, ostream().toByteArray(), ++ filename); ++ } ++ ++ public void writeTo(OutputStream stream) throws Exception { ++ if (this.ostream != null) { ++ stream.write(ostream.toByteArray()); ++ } else { ++ Module.compile(node, stream, name, filename, linenumbers, ++ printResults, cflags); ++ } ++ } ++ ++ public void saveCode(String directory) throws Exception { ++ // FIXME: this is slightly broken, it should use the directory ++ Py.saveClassFile(name, ostream()); ++ } ++ ++ private ByteArrayOutputStream ostream() throws Exception { ++ if (ostream == null) { ++ ostream = new ByteArrayOutputStream(); ++ Module.compile(node, ostream, name, filename, linenumbers, ++ printResults, cflags); ++ } ++ return ostream; ++ } ++ ++ } ++ ++} +diff --git a/jython/src/org/python/compiler/Module.java b/jython/src/org/python/compiler/Module.java +--- a/jython/src/org/python/compiler/Module.java ++++ b/jython/src/org/python/compiler/Module.java +@@ -12,10 +12,14 @@ + + import org.objectweb.asm.Label; + import org.objectweb.asm.Opcodes; ++import org.python.core.CodeBootstrap; + import org.python.core.CodeFlag; ++import org.python.core.CodeLoader; + import org.python.core.CompilerFlags; + import org.python.core.Py; + import org.python.core.PyException; ++import org.python.core.PyRunnableBootstrap; ++import org.objectweb.asm.Type; + import org.python.antlr.ParseException; + import org.python.antlr.PythonTree; + import org.python.antlr.ast.Suite; +@@ -541,10 +545,26 @@ + c.dup(); + c.ldc(classfile.name); + c.invokespecial(classfile.name, "<init>", "(" + $str + ")V"); ++ c.invokevirtual(classfile.name, "getMain", "()" + $pyCode); ++ String bootstrap = Type.getDescriptor(CodeBootstrap.class); ++ c.invokestatic(Type.getInternalName(CodeLoader.class), ++ CodeLoader.SIMPLE_FACTORY_METHOD_NAME, ++ "(" + $pyCode + ")" + bootstrap); + c.aload(0); +- c.invokestatic("org/python/core/Py", "runMain", "(" + $pyRunnable + $strArr + ")V"); ++ c.invokestatic("org/python/core/Py", "runMain", "(" + bootstrap + $strArr + ")V"); + c.return_(); + } ++ ++ public void addBootstrap() throws IOException { ++ Code c = classfile.addMethod(CodeLoader.GET_BOOTSTRAP_METHOD_NAME, ++ "()" + Type.getDescriptor(CodeBootstrap.class), ++ ACC_PUBLIC | ACC_STATIC); ++ c.ldc(Type.getType("L" + classfile.name + ";")); ++ c.invokestatic(Type.getInternalName(PyRunnableBootstrap.class), ++ PyRunnableBootstrap.REFLECTION_METHOD_NAME, ++ "(" + $clss + ")" + Type.getDescriptor(CodeBootstrap.class)); ++ c.areturn(); ++ } + + public void addConstants(Code c) throws IOException { + classfile.addField("self", "L"+classfile.name+";", +@@ -599,6 +619,7 @@ + addInit(); + addRunnable(); + addMain(); ++ addBootstrap(); + + addFunctions(); + +diff --git a/jython/src/org/python/core/CodeBootstrap.java b/jython/src/org/python/core/CodeBootstrap.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/CodeBootstrap.java +@@ -0,0 +1,7 @@ ++package org.python.core; ++ ++public interface CodeBootstrap { ++ ++ PyCode loadCode(CodeLoader loader); ++ ++} +diff --git a/jython/src/org/python/core/CodeLoader.java b/jython/src/org/python/core/CodeLoader.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/CodeLoader.java +@@ -0,0 +1,60 @@ ++package org.python.core; ++ ++import java.lang.reflect.InvocationTargetException; ++import java.lang.reflect.Method; ++import java.lang.reflect.Modifier; ++ ++public final class CodeLoader { ++ ++ public static final String GET_BOOTSTRAP_METHOD_NAME = "getCodeBootstrap"; ++ public final String name; ++ public final String filename; ++ ++ private CodeLoader(String name, String filename) { ++ this.name = name; ++ this.filename = filename; ++ } ++ ++ public static boolean canLoad(Class<?> cls) { ++ try { ++ Method getBootstrap = cls.getMethod(GET_BOOTSTRAP_METHOD_NAME); ++ return Modifier.isStatic(getBootstrap.getModifiers()); ++ } catch (Exception e) { ++ return false; ++ } ++ } ++ ++ public static PyCode loadCode(Class<?> cls, String name, String filename) ++ throws SecurityException, NoSuchMethodException, ++ IllegalArgumentException, IllegalAccessException, ++ InvocationTargetException { ++ Method getBootstrap = cls.getMethod(GET_BOOTSTRAP_METHOD_NAME); ++ CodeBootstrap bootstrap = (CodeBootstrap) getBootstrap.invoke(null); ++ return loadCode(bootstrap, name, filename); ++ } ++ ++ public static PyCode loadCode(Class<?> cls) throws SecurityException, ++ IllegalArgumentException, NoSuchMethodException, ++ IllegalAccessException, InvocationTargetException { ++ return loadCode(cls, null, null); ++ } ++ ++ public static PyCode loadCode(CodeBootstrap bootstrap, String name, ++ String filename) { ++ return bootstrap.loadCode(new CodeLoader(name, filename)); ++ } ++ ++ public static PyCode loadCode(CodeBootstrap bootstrap) { ++ return loadCode(bootstrap, null, null); ++ } ++ ++ public static final String SIMPLE_FACTORY_METHOD_NAME = "createSimpleBootstrap"; ++ ++ public static CodeBootstrap createSimpleBootstrap(final PyCode code) { ++ return new CodeBootstrap() { ++ public PyCode loadCode(CodeLoader loader) { ++ return code; ++ } ++ }; ++ } ++} +diff --git a/jython/src/org/python/core/CompilerFacade.java b/jython/src/org/python/core/CompilerFacade.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/CompilerFacade.java +@@ -0,0 +1,39 @@ ++package org.python.core; ++ ++import org.python.antlr.base.mod; ++import org.python.compiler.LegacyCompiler; ++ ++/** ++ * Facade for different compiler implementations. ++ * ++ * The static methods of this class act as a Facade for the compiler subsystem. ++ * This is so that the rest of Jython (even generated code) can statically link ++ * to the static interface of this class, while allowing for different ++ * implementations of the various components of the compiler subsystem. ++ * ++ * @author Tobias Ivarsson ++ */ ++public class CompilerFacade { ++ ++ private static volatile PythonCompiler compiler = loadDefaultCompiler(); ++ ++ public static void setCompiler(PythonCompiler compiler) { ++ CompilerFacade.compiler = compiler; ++ } ++ ++ private static PythonCompiler loadDefaultCompiler() { ++ return new LegacyCompiler(); ++ } ++ ++ public static PyCode compile(mod node, String name, String filename, ++ boolean linenumbers, boolean printResults, CompilerFlags cflags) { ++ try { ++ PythonCodeBundle bundle = compiler.compile(node, name, filename, ++ linenumbers, printResults, cflags); ++ bundle.saveCode(Options.proxyDebugDirectory); ++ return bundle.loadCode(); ++ } catch (Throwable t) { ++ throw ParserFacade.fixParseError(null, t, filename); ++ } ++ } ++} +diff --git a/jython/src/org/python/core/Py.java b/jython/src/org/python/core/Py.java +--- a/jython/src/org/python/core/Py.java ++++ b/jython/src/org/python/core/Py.java +@@ -862,9 +862,19 @@ + * Called by the code generated in {@link Module#addMain()} + */ + public static void runMain(PyRunnable main, String[] args) throws Exception { ++ runMain(new PyRunnableBootstrap(main), args); ++ } ++ ++ /** ++ * Initializes a default PythonInterpreter and runs the code loaded from the ++ * {@link CodeBootstrap} as __main__ Called by the code generated in ++ * {@link Module#addMain()} ++ */ ++ public static void runMain(CodeBootstrap main, String[] args) ++ throws Exception { + PySystemState.initialize(null, null, args, main.getClass().getClassLoader()); + try { +- imp.createFromCode("__main__", main.getMain()); ++ imp.createFromCode("__main__", CodeLoader.loadCode(main)); + } catch (PyException e) { + Py.getSystemState().callExitFunc(); + if (Py.matchException(e, Py.SystemExit)) { +@@ -1632,6 +1642,8 @@ + public static PyCode compile_flags(mod node, String name, String filename, + boolean linenumbers, boolean printResults, + CompilerFlags cflags) { ++ return CompilerFacade.compile(node, name, filename, linenumbers, printResults, cflags); ++ /* + try { + ByteArrayOutputStream ostream = new ByteArrayOutputStream(); + Module.compile(node, ostream, name, filename, linenumbers, printResults, cflags); +@@ -1642,6 +1654,7 @@ + } catch (Throwable t) { + throw ParserFacade.fixParseError(null, t, filename); + } ++ */ + } + + public static PyCode compile_flags(mod node, String filename, +diff --git a/jython/src/org/python/core/PyRunnableBootstrap.java b/jython/src/org/python/core/PyRunnableBootstrap.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/PyRunnableBootstrap.java +@@ -0,0 +1,43 @@ ++package org.python.core; ++ ++import java.lang.reflect.Constructor; ++ ++public class PyRunnableBootstrap implements CodeBootstrap { ++ ++ public static final String REFLECTION_METHOD_NAME = "getFilenameConstructorReflectionBootstrap"; ++ private final PyRunnable runnable; ++ ++ PyRunnableBootstrap(PyRunnable runnable) { ++ this.runnable = runnable; ++ } ++ ++ public PyCode loadCode(CodeLoader loader) { ++ return runnable.getMain(); ++ } ++ ++ public static CodeBootstrap getFilenameConstructorReflectionBootstrap( ++ Class<? extends PyRunnable> cls) { ++ final Constructor<? extends PyRunnable> constructor; ++ try { ++ constructor = cls.getConstructor(String.class); ++ } catch (Exception e) { ++ throw new IllegalArgumentException( ++ "PyRunnable class does not specify apropriate constructor.", ++ e); ++ } ++ return new CodeBootstrap() { ++ ++ public PyCode loadCode(CodeLoader loader) { ++ try { ++ return constructor.newInstance(loader.filename).getMain(); ++ } catch (Exception e) { ++ throw new IllegalArgumentException( ++ "PyRunnable class constructor does not support instantiation protocol.", ++ e); ++ } ++ } ++ ++ }; ++ } ++ ++} +diff --git a/jython/src/org/python/core/PythonCodeBundle.java b/jython/src/org/python/core/PythonCodeBundle.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/PythonCodeBundle.java +@@ -0,0 +1,13 @@ ++package org.python.core; ++ ++import java.io.OutputStream; ++ ++public interface PythonCodeBundle { ++ ++ PyCode loadCode() throws Exception; ++ ++ void writeTo(OutputStream stream) throws Exception; ++ ++ void saveCode(String directory) throws Exception; ++ ++} +diff --git a/jython/src/org/python/core/PythonCompiler.java b/jython/src/org/python/core/PythonCompiler.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/PythonCompiler.java +@@ -0,0 +1,11 @@ ++package org.python.core; ++ ++import org.python.antlr.base.mod; ++ ++public interface PythonCompiler { ++ ++ PythonCodeBundle compile(mod node, String name, String filename, ++ boolean linenumbers, boolean printResults, CompilerFlags cflags) ++ throws Exception; ++ ++} Modified: trunk/sandbox/tobias/.hg/patches/series =================================================================== --- trunk/sandbox/tobias/.hg/patches/series 2009-03-02 03:29:30 UTC (rev 6054) +++ trunk/sandbox/tobias/.hg/patches/series 2009-03-02 15:59:20 UTC (rev 6055) @@ -0,0 +1,2 @@ +types.patch #+trunk #-advanced +decouple.patch #+trunk #-advanced Added: trunk/sandbox/tobias/.hg/patches/types.patch =================================================================== --- trunk/sandbox/tobias/.hg/patches/types.patch (rev 0) +++ trunk/sandbox/tobias/.hg/patches/types.patch 2009-03-02 15:59:20 UTC (rev 6055) @@ -0,0 +1,1546 @@ +diff --git a/jython/Lib/codeop.py b/jython/Lib/codeop.py +--- a/jython/Lib/codeop.py ++++ b/jython/Lib/codeop.py +@@ -57,8 +57,8 @@ + """ + + # import internals, not guaranteed interface +-from org.python.core import Py,CompilerFlags +-from org.python.core.PyTableCode import PyCF_DONT_IMPLY_DEDENT ++from org.python.core import Py,CompilerFlags,CompileMode ++from org.python.core.CompilerFlags import PyCF_DONT_IMPLY_DEDENT + + # public interface + +@@ -84,6 +84,7 @@ + """ + if symbol not in ['single','eval']: + raise ValueError,"symbol arg must be either single or eval" ++ symbol = CompileMode.getMode(symbol) + return Py.compile_command_flags(source,filename,symbol,Py.getCompilerFlags(),0) + + class Compile: +@@ -95,6 +96,7 @@ + self._cflags = CompilerFlags() + + def __call__(self, source, filename, symbol): ++ symbol = CompileMode.getMode(symbol) + return Py.compile_flags(source, filename, symbol, self._cflags) + + class CommandCompiler: +@@ -128,5 +130,6 @@ + """ + if symbol not in ['single','eval']: + raise ValueError,"symbol arg must be either single or eval" ++ symbol = CompileMode.getMode(symbol) + return Py.compile_command_flags(source,filename,symbol,self._cflags,0) + +diff --git a/jython/src/org/python/Version.java b/jython/src/org/python/Version.java +--- a/jython/src/org/python/Version.java ++++ b/jython/src/org/python/Version.java +@@ -3,7 +3,13 @@ + + import java.io.InputStream; + import java.io.IOException; ++import java.util.Arrays; ++import java.util.Collection; ++import java.util.EnumSet; + import java.util.Properties; ++import java.util.Set; ++ ++import org.python.core.CodeFlag; + + /** + * Jython version information. +@@ -36,6 +42,10 @@ + /** Short version of branch, e.g. asm. */ + public static String SHORT_BRANCH; + ++ /** The flags that are set by default in a code object. */ ++ private static final Collection<CodeFlag> defaultCodeFlags = Arrays.asList( ++ CodeFlag.CO_NESTED, CodeFlag.CO_GENERATOR_ALLOWED); ++ + private static final String headURL = + "$HeadURL: https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython/src/org/python/Version.java $"; + +@@ -144,4 +154,8 @@ + public static String getVersion() { + return String.format("%.80s (%.80s) %.80s", PY_VERSION, getBuildInfo(), getVM()); + } ++ ++ public static Set<CodeFlag> getDefaultCodeFlags() { ++ return EnumSet.copyOf(defaultCodeFlags); ++ } + } +diff --git a/jython/src/org/python/antlr/BaseParser.java b/jython/src/org/python/antlr/BaseParser.java +--- a/jython/src/org/python/antlr/BaseParser.java ++++ b/jython/src/org/python/antlr/BaseParser.java +@@ -1,15 +1,31 @@ + package org.python.antlr; + + import org.antlr.runtime.CharStream; ++import org.antlr.runtime.CommonTokenStream; ++import org.antlr.runtime.RecognitionException; + import org.antlr.runtime.Token; ++import org.python.antlr.base.mod; + + public class BaseParser { + +- protected CharStream charStream; +- protected boolean partial; +- protected String filename; +- protected String encoding; ++ protected final CharStream charStream; ++ @Deprecated ++ protected final boolean partial; ++ protected final String filename; ++ protected final String encoding; + protected ErrorHandler errorHandler = new FailFastHandler(); ++ ++ public BaseParser(CharStream stream, String filename, String encoding) { ++ this(stream, filename, encoding, false); ++ } ++ ++ @Deprecated ++ public BaseParser(CharStream stream, String filename, String encoding, boolean partial) { ++ this.charStream = stream; ++ this.filename = filename; ++ this.encoding = encoding; ++ this.partial = partial; ++ } + + public void setAntlrErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; +@@ -25,4 +41,60 @@ + return super.nextToken(); + } + } ++ ++ private CharStream charStream(boolean single) { ++ return charStream; ++ } ++ ++ private PythonParser setupParser(boolean single) { ++ PythonLexer lexer = new PyLexer(this.charStream(single)); ++ lexer.setErrorHandler(errorHandler); ++ CommonTokenStream tokens = new CommonTokenStream(lexer); ++ PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename, single); ++ tokens = new CommonTokenStream(indentedSource); ++ PythonParser parser = new PythonParser(tokens, encoding); ++ parser.setErrorHandler(errorHandler); ++ parser.setTreeAdaptor(new PythonTreeAdaptor()); ++ return parser; ++ } ++ ++ public mod parseExpression() { ++ mod tree = null; ++ PythonParser parser = setupParser(false); ++ try { ++ PythonParser.eval_input_return r = parser.eval_input(); ++ tree = (mod)r.tree; ++ } catch (RecognitionException e) { ++ //XXX: this can't happen. Need to strip the throws from antlr ++ // generated code. ++ } ++ return tree; ++ } ++ ++ public mod parseInteractive() { ++ mod tree = null; ++ PythonParser parser = setupParser(true); ++ try { ++ PythonParser.single_input_return r = parser.single_input(); ++ tree = (mod)r.tree; ++ } catch (RecognitionException e) { ++ //I am only throwing ParseExceptions, but "throws RecognitionException" still gets ++ //into the generated code. ++ System.err.println("FIXME: pretty sure this can't happen -- but needs to be checked"); ++ } ++ return tree; ++ } ++ ++ public mod parseModule() { ++ mod tree = null; ++ PythonParser parser = setupParser(false); ++ try { ++ PythonParser.file_input_return r = parser.file_input(); ++ tree = (mod)r.tree; ++ } catch (RecognitionException e) { ++ //XXX: this can't happen. Need to strip the throws from antlr ++ // generated code. ++ } ++ return tree; ++ } + } +diff --git a/jython/src/org/python/antlr/ExpressionParser.java b/jython/src/org/python/antlr/ExpressionParser.java +deleted file mode 100644 +--- a/jython/src/org/python/antlr/ExpressionParser.java ++++ /dev/null +@@ -1,36 +0,0 @@ +-package org.python.antlr; +- +-import org.antlr.runtime.CharStream; +-import org.antlr.runtime.CommonTokenStream; +-import org.antlr.runtime.RecognitionException; +-import org.python.antlr.base.mod; +- +-public class ExpressionParser extends BaseParser { +- +- public ExpressionParser(CharStream cs, String filename, String encoding) { +- this.charStream = cs; +- this.filename = filename; +- this.encoding = encoding; +- } +- +- public mod parse() { +- mod tree = null; +- PythonLexer lexer = new PyLexer(this.charStream); +- lexer.setErrorHandler(errorHandler); +- CommonTokenStream tokens = new CommonTokenStream(lexer); +- PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); +- tokens = new CommonTokenStream(indentedSource); +- PythonParser parser = new PythonParser(tokens, encoding); +- parser.setErrorHandler(errorHandler); +- parser.setTreeAdaptor(new PythonTreeAdaptor()); +- +- try { +- PythonParser.eval_input_return r = parser.eval_input(); +- tree = (mod)r.tree; +- } catch (RecognitionException e) { +- //XXX: this can't happen. Need to strip the throws from antlr +- // generated code. +- } +- return tree; +- } +-} +diff --git a/jython/src/org/python/antlr/InteractiveParser.java b/jython/src/org/python/antlr/InteractiveParser.java +deleted file mode 100644 +--- a/jython/src/org/python/antlr/InteractiveParser.java ++++ /dev/null +@@ -1,41 +0,0 @@ +-package org.python.antlr; +- +-import java.io.BufferedReader; +-import java.io.IOException; +- +-import org.antlr.runtime.CommonTokenStream; +-import org.antlr.runtime.RecognitionException; +-import org.python.antlr.base.mod; +- +-public class InteractiveParser extends BaseParser { +- +- private BufferedReader bufreader; +- +- public InteractiveParser(BufferedReader br, String filename, String encoding) { +- this.bufreader = br; +- this.filename = filename; +- this.encoding = encoding; +- } +- +- public mod parse() throws IOException { +- mod tree = null; +- PythonLexer lexer = new PyLexer(new NoCloseReaderStream(bufreader)); +- lexer.setErrorHandler(errorHandler); +- CommonTokenStream tokens = new CommonTokenStream(lexer); +- PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename, true); +- tokens = new CommonTokenStream(indentedSource); +- PythonParser parser = new PythonParser(tokens, encoding); +- parser.setErrorHandler(errorHandler); +- parser.setTreeAdaptor(new PythonTreeAdaptor()); +- +- try { +- PythonParser.single_input_return r = parser.single_input(); +- tree = (mod)r.tree; +- } catch (RecognitionException e) { +- //I am only throwing ParseExceptions, but "throws RecognitionException" still gets +- //into the generated code. +- System.err.println("FIXME: pretty sure this can't happen -- but needs to be checked"); +- } +- return tree; +- } +-} +diff --git a/jython/src/org/python/antlr/ModuleParser.java b/jython/src/org/python/antlr/ModuleParser.java +deleted file mode 100644 +--- a/jython/src/org/python/antlr/ModuleParser.java ++++ /dev/null +@@ -1,39 +0,0 @@ +-package org.python.antlr; +- +-import org.antlr.runtime.CharStream; +-import org.antlr.runtime.CommonTokenStream; +-import org.antlr.runtime.RecognitionException; +-import org.python.antlr.base.mod; +- +-public class ModuleParser extends BaseParser { +- public ModuleParser(CharStream cs, String filename, String encoding) { +- this(cs, filename, encoding, false); +- } +- +- public ModuleParser(CharStream cs, String filename, String encoding, boolean partial) { +- this.charStream = cs; +- this.filename = filename; +- this.encoding = encoding; +- this.partial = partial; +- } +- +- public mod file_input() { +- mod tree = null; +- PythonLexer lexer = new PyLexer(this.charStream); +- lexer.setErrorHandler(errorHandler); +- CommonTokenStream tokens = new CommonTokenStream(lexer); +- PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); +- tokens = new CommonTokenStream(indentedSource); +- PythonParser parser = new PythonParser(tokens, encoding); +- parser.setErrorHandler(errorHandler); +- parser.setTreeAdaptor(new PythonTreeAdaptor()); +- try { +- PythonParser.file_input_return r = parser.file_input(); +- tree = (mod)r.tree; +- } catch (RecognitionException e) { +- //XXX: this can't happen. Need to strip the throws from antlr +- // generated code. +- } +- return tree; +- } +-} +diff --git a/jython/src/org/python/antlr/ast/AstModule.java b/jython/src/org/python/antlr/ast/AstModule.java +--- a/jython/src/org/python/antlr/ast/AstModule.java ++++ b/jython/src/org/python/antlr/ast/AstModule.java +@@ -8,12 +8,12 @@ + import org.python.antlr.op.*; + import org.python.core.AstList; + import org.python.core.ClassDictInit; ++import org.python.core.CompilerFlags; + import org.python.core.imp; + import org.python.core.Py; + import org.python.core.PyInteger; + import org.python.core.PyObject; + import org.python.core.PyString; +-import org.python.core.PyTableCode; + import org.python.core.PyType; + + import org.python.antlr.AST; +@@ -27,7 +27,7 @@ + dict.__setitem__("__doc__", Py.None); + dict.__setitem__("__name__", new PyString("_ast")); + dict.__setitem__("__version__", new PyString("62047")); +- dict.__setitem__("PyCF_ONLY_AST", new PyInteger(PyTableCode.PyCF_ONLY_AST)); ++ dict.__setitem__("PyCF_ONLY_AST", new PyInteger(CompilerFlags.PyCF_ONLY_AST)); + + dict.__setitem__("astlist", AstList.TYPE); + +diff --git a/jython/src/org/python/compiler/Future.java b/jython/src/org/python/compiler/Future.java +--- a/jython/src/org/python/compiler/Future.java ++++ b/jython/src/org/python/compiler/Future.java +@@ -8,73 +8,65 @@ + import org.python.antlr.ast.Interactive; + import org.python.antlr.ast.Module; + import org.python.antlr.ast.Str; ++import org.python.antlr.ast.alias; + import org.python.antlr.base.mod; + import org.python.antlr.base.stmt; ++import org.python.core.CodeFlag; ++import org.python.core.FutureFeature; ++import org.python.core.Pragma; ++import org.python.core.PragmaReceiver; + ++import java.util.EnumSet; + import java.util.List; ++import java.util.Set; + + public class Future { ++ Set<FutureFeature> featureSet = EnumSet.noneOf(FutureFeature.class); ++ private final PragmaReceiver features = new PragmaReceiver() { + +- private boolean division = false; +- private boolean with_statement = false; +- private boolean absolute_import = false; ++ public void add(Pragma pragma) { ++ if (pragma instanceof FutureFeature) { ++ FutureFeature feature = (FutureFeature) pragma; ++ featureSet.add(feature); ++ } ++ } + +- private static final String FUTURE = "__future__"; ++ }; + + private boolean check(ImportFrom cand) throws Exception { +- if (!cand.getInternalModule().equals(FUTURE)) ++ if (!cand.getInternalModule().equals(FutureFeature.MODULE_NAME)) + return false; +- int n = cand.getInternalNames().size(); +- if (n == 0) { +- throw new ParseException("future statement does not support import *", cand); ++ if (cand.getInternalNames().isEmpty()) { ++ throw new ParseException( ++ "future statement does not support import *", cand); + } +- for (int i = 0; i < n; i++) { +- String feature = cand.getInternalNames().get(i).getInternalName(); +- // *known* features +- if (feature.equals("nested_scopes")) { +- continue; ++ try { ++ for (alias feature : cand.getInternalNames()) { ++ // *known* features ++ FutureFeature.addFeature(feature.getInternalName(), features); + } +- if (feature.equals("division")) { +- division = true; +- continue; +- } +- if (feature.equals("generators")) { +- continue; +- } +- if (feature.equals("with_statement")) { +- with_statement = true; +- continue; +- } +- if (feature.equals("absolute_import")) { +- absolute_import = true; +- continue; +- } +- if (feature.equals("braces")) { +- throw new ParseException("not a chance", cand); +- } +- if (feature.equals("GIL") || feature.equals("global_interpreter_lock")) { +- throw new ParseException("Never going to happen!", cand); +- } +- throw new ParseException("future feature " + feature + " is not defined", cand); ++ } catch (ParseException pe) { ++ throw new ParseException(pe.getMessage(), cand); + } + return true; + } + +- public void preprocessFutures(mod node, +- org.python.core.CompilerFlags cflags) +- throws Exception +- { ++ public void preprocessFutures(mod node, org.python.core.CompilerFlags cflags) ++ throws Exception { + if (cflags != null) { +- division = cflags.division; +- with_statement = cflags.with_statement; +- absolute_import = cflags.absolute_import; ++ if (cflags.isFlagSet(CodeFlag.CO_FUTURE_DIVISION)) ++ FutureFeature.division.addTo(features); ++ if (cflags.isFlagSet(CodeFlag.CO_FUTURE_WITH_STATEMENT)) ++ FutureFeature.with_statement.addTo(features); ++ if (cflags.isFlagSet(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT)) ++ FutureFeature.absolute_import.addTo(features); + } + int beg = 0; + List<stmt> suite = null; + if (node instanceof Module) { + suite = ((Module) node).getInternalBody(); +- if (suite.size() > 0 && suite.get(0) instanceof Expr && +- ((Expr) suite.get(0)).getInternalValue() instanceof Str) { ++ if (suite.size() > 0 && suite.get(0) instanceof Expr ++ && ((Expr) suite.get(0)).getInternalValue() instanceof Str) { + beg++; + } + } else if (node instanceof Interactive) { +@@ -85,45 +77,36 @@ + + for (int i = beg; i < suite.size(); i++) { + stmt s = suite.get(i); +- if (!(s instanceof ImportFrom)) +- break; ++ if (!(s instanceof ImportFrom)) break; + s.from_future_checked = true; +- if (!check((ImportFrom)s)) +- break; ++ if (!check((ImportFrom) s)) break; + } + + if (cflags != null) { +- cflags.division = cflags.division || division; +- } +- if (cflags != null) { +- cflags.with_statement = cflags.with_statement || with_statement; +- } +- if (cflags != null) { +- cflags.absolute_import = cflags.absolute_import || absolute_import; ++ for (FutureFeature feature : featureSet) { ++ feature.setFlag(cflags); ++ } + } + } + +- + public static void checkFromFuture(ImportFrom node) throws Exception { +- if (node.from_future_checked) +- return; +- if (node.getInternalModule().equals(FUTURE)) { +- throw new ParseException("from __future__ imports must occur " + +- "at the beginning of the file",node); ++ if (node.from_future_checked) return; ++ if (node.getInternalModule().equals(FutureFeature.MODULE_NAME)) { ++ throw new ParseException("from __future__ imports must occur " ++ + "at the beginning of the file", node); + } + node.from_future_checked = true; + } + + public boolean areDivisionOn() { +- return division; ++ return featureSet.contains(FutureFeature.division); + } + + public boolean withStatementSupported() { +- return with_statement; ++ return featureSet.contains(FutureFeature.with_statement); + } + + public boolean isAbsoluteImportOn() { +- return absolute_import; ++ return featureSet.contains(FutureFeature.absolute_import); + } +- + } +diff --git a/jython/src/org/python/compiler/Module.java b/jython/src/org/python/compiler/Module.java +--- a/jython/src/org/python/compiler/Module.java ++++ b/jython/src/org/python/compiler/Module.java +@@ -12,6 +12,7 @@ + + import org.objectweb.asm.Label; + import org.objectweb.asm.Opcodes; ++import org.python.core.CodeFlag; + import org.python.core.CompilerFlags; + import org.python.core.Py; + import org.python.core.PyException; +@@ -500,17 +501,17 @@ + code.jy_npurecell = scope.jy_npurecell; + + if (compiler.optimizeGlobals) { +- code.moreflags |= org.python.core.PyTableCode.CO_OPTIMIZED; ++ code.moreflags |= org.python.core.CodeFlag.CO_OPTIMIZED.flag; + } + if (compiler.my_scope.generator) { +- code.moreflags |= org.python.core.PyTableCode.CO_GENERATOR; ++ code.moreflags |= org.python.core.CodeFlag.CO_GENERATOR.flag; + } + if (cflags != null) { +- if (cflags.generator_allowed) { +- code.moreflags |= org.python.core.PyTableCode.CO_GENERATOR_ALLOWED; ++ if (cflags.isFlagSet(CodeFlag.CO_GENERATOR_ALLOWED)) { ++ code.moreflags |= org.python.core.CodeFlag.CO_GENERATOR_ALLOWED.flag; + } +- if (cflags.division) { +- code.moreflags |= org.python.core.PyTableCode.CO_FUTUREDIVISION; ++ if (cflags.isFlagSet(CodeFlag.CO_FUTURE_DIVISION)) { ++ code.moreflags |= org.python.core.CodeFlag.CO_FUTURE_DIVISION.flag; + } + } + +diff --git a/jython/src/org/python/compiler/pbc/Bytecode.java b/jython/src/org/python/compiler/pbc/Bytecode.java +--- a/jython/src/org/python/compiler/pbc/Bytecode.java ++++ b/jython/src/org/python/compiler/pbc/Bytecode.java +@@ -14,6 +14,8 @@ + import java.util.List; + import java.util.Map; + import java.util.Set; ++ ++import org.python.core.CodeFlag; + import org.python.core.Py; + import org.python.core.Opcode; + import org.python.core.PyBaseCode; +@@ -25,7 +27,7 @@ + + private int co_argcount = 0; + private int co_stacksize = 0; +- private int co_flags = PyBaseCode.CO_OPTIMIZED | PyBaseCode.CO_NEWLOCALS; // typical usage ++ private int co_flags = CodeFlag.CO_OPTIMIZED.flag | CodeFlag.CO_NEWLOCALS.flag; // typical usage + // co_filename = '<generated code>' + // co_name = '<lambda>' + // co_firstlineno = 0 +@@ -135,7 +137,7 @@ + + public void YIELD_VALUE() { + stackchange(1, 1); +- co_flags |= PyBaseCode.CO_GENERATOR; ++ co_flags |= CodeFlag.CO_GENERATOR.flag; + emit(Opcode.YIELD_VALUE); + } + +diff --git a/jython/src/org/python/core/CodeFlag.java b/jython/src/org/python/core/CodeFlag.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/CodeFlag.java +@@ -0,0 +1,106 @@ ++package org.python.core; ++ ++import java.util.Arrays; ++import java.util.Collections; ++import java.util.Iterator; ++ ++/** ++ * Represents flags that can be set on code objects. ++ * ++ * @author Tobias Ivarsson ++ */ ++public enum CodeFlag { ++ /** ++ * Denotes that the code block uses fast locals. ++ */ ++ CO_OPTIMIZED(0x0001), ++ /** ++ * Denotes that a new dictionary should be created for the code block. ++ */ ++ CO_NEWLOCALS(0x0002), ++ /** ++ * The compiled code block has a varargs argument. ++ */ ++ CO_VARARGS(0x0004), ++ /** ++ * The compiled code block has a varkeyword argument. ++ */ ++ CO_VARKEYWORDS(0x0008), ++ /** ++ * The compiled code block is a generator code block. ++ */ ++ CO_GENERATOR(0x0020), ++ /** ++ * Denotes that nested scopes are enabled in the code block. ++ */ ++ CO_NESTED(0x0010), ++ /** ++ * Denotes that generators are enabled in the code block. ++ */ ++ CO_GENERATOR_ALLOWED(0x1000), ++ /** ++ * Standard division of integers returns float, truncating division needs to ++ * be enforced. ++ */ ++ CO_FUTURE_DIVISION(0x2000), ++ /** ++ * Absolute import. ++ */ ++ CO_FUTURE_ABSOLUTE_IMPORT(0x4000), ++ /** ++ * With statement. ++ */ ++ CO_FUTURE_WITH_STATEMENT(0x8000); ++ ++ public final int flag; ++ private static Iterable<CodeFlag> allFlags = Collections.unmodifiableList(Arrays.asList(values())); ++ ++ private CodeFlag(int flag) { ++ this.flag = flag; ++ } ++ ++ public boolean isFlagBitSetIn(int flags) { ++ return (flags & flag) != 0; ++ } ++ ++ static Iterable<CodeFlag> parse(final int flags) { ++ return new Iterable<CodeFlag>() { ++ ++ public Iterator<CodeFlag> iterator() { ++ return new Iterator<CodeFlag>() { ++ Iterator<CodeFlag> all = allFlags.iterator(); ++ CodeFlag next = null; ++ ++ public boolean hasNext() { ++ if (next != null) { ++ return true; ++ } ++ while (all.hasNext()) { ++ CodeFlag flag = all.next(); ++ if (flag.isFlagBitSetIn(flags)) { ++ next = flag; ++ return true; ++ } ++ } ++ return false; ++ } ++ ++ public CodeFlag next() { ++ if (hasNext()) try { ++ return next; ++ } finally { ++ next = null; ++ } ++ throw new IllegalStateException(); ++ } ++ ++ public void remove() { ++ throw new UnsupportedOperationException(); ++ } ++ ++ }; ++ } ++ ++ }; ++ } ++} +diff --git a/jython/src/org/python/core/CompileMode.java b/jython/src/org/python/core/CompileMode.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/CompileMode.java +@@ -0,0 +1,33 @@ ++package org.python.core; ++ ++import org.python.antlr.BaseParser; ++import org.python.antlr.base.mod; ++ ++public enum CompileMode { ++ eval { ++ @Override ++ mod dispatch(BaseParser parser) { ++ return parser.parseExpression(); ++ } ++ }, ++ single { ++ @Override ++ mod dispatch(BaseParser parser) { ++ return parser.parseInteractive(); ++ } ++ }, ++ exec { ++ @Override ++ mod dispatch(BaseParser parser) { ++ return parser.parseModule(); ++ } ++ }; ++ abstract mod dispatch(BaseParser parser); ++ ++ public static CompileMode getMode(String mode) { ++ if (!mode.equals("exec") && !mode.equals("eval") && !mode.equals("single")) { ++ throw Py.ValueError("compile() arg 3 must be 'exec' or 'eval' or 'single'"); ++ } ++ return valueOf(mode); ++ } ++} +diff --git a/jython/src/org/python/core/CompilerFlags.java b/jython/src/org/python/core/CompilerFlags.java +--- a/jython/src/org/python/core/CompilerFlags.java ++++ b/jython/src/org/python/core/CompilerFlags.java +@@ -1,46 +1,84 @@ + + package org.python.core; + ++import java.util.Set; ++ ++import org.python.Version; ++ + public class CompilerFlags { +- +- private int co_flags; +- +- public boolean nested_scopes = true; +- public boolean division; +- public boolean generator_allowed = true; +- public boolean with_statement; +- public boolean absolute_import; +- ++ // These flags don't mean anything to the code, only to the compiler ++ public static final int PyCF_SOURCE_IS_UTF8 = 0x0100; ++ public static final int PyCF_DONT_IMPLY_DEDENT = 0x0200; ++ public static final int PyCF_ONLY_AST = 0x0400; + public boolean only_ast; + public boolean dont_imply_dedent; + public boolean source_is_utf8; + + public String encoding; ++ private final Set<CodeFlag> flags = Version.getDefaultCodeFlags(); + + public CompilerFlags() {} + + public CompilerFlags(int co_flags) { +- this.co_flags = co_flags; +- nested_scopes = isEnabled(PyTableCode.CO_NESTED); +- division = isEnabled(PyTableCode.CO_FUTUREDIVISION); +- generator_allowed = isEnabled(PyTableCode.CO_GENERATOR_ALLOWED); +- absolute_import = isEnabled(PyTableCode.CO_FUTURE_ABSOLUTE_IMPORT); +- with_statement = isEnabled(PyTableCode.CO_WITH_STATEMENT); +- only_ast = isEnabled(PyTableCode.PyCF_ONLY_AST); +- dont_imply_dedent = isEnabled(PyTableCode.PyCF_DONT_IMPLY_DEDENT); +- source_is_utf8 = isEnabled(PyTableCode.PyCF_SOURCE_IS_UTF8); ++ for (CodeFlag flag : CodeFlag.parse(co_flags)) { ++ setFlag(flag); ++ } ++ only_ast = isEnabled(co_flags, PyCF_ONLY_AST); ++ dont_imply_dedent = isEnabled(co_flags, PyCF_DONT_IMPLY_DEDENT); ++ source_is_utf8 = isEnabled(co_flags, PyCF_SOURCE_IS_UTF8); + } + +- private boolean isEnabled(int codeConstant) { ++ private boolean isEnabled(int co_flags, int codeConstant) { + return (co_flags & codeConstant) != 0; + } + +- public String toString() { +- return String.format("CompilerFlags[division=%s nested_scopes=%s generators=%s " +- + "with_statement=%s absolute_import=%s only_ast=%s " +- + "dont_imply_dedent=%s source_is_utf8=%s]", division, nested_scopes, +- generator_allowed, with_statement, absolute_import, only_ast, +- dont_imply_dedent, source_is_utf8); ++ public void setFlag(CodeFlag flag) { ++ flags.add(flag); + } + ++ public boolean isFlagSet(CodeFlag flag) { ++ return flags.contains(flag); ++ } ++ ++ public String toString() { ++ return String.format( ++ "CompilerFlags[division=%s nested_scopes=%s generators=%s " ++ + "with_statement=%s absolute_import=%s only_ast=%s " ++ + "dont_imply_dedent=%s source_is_utf8=%s]", ++ isFlagSet(CodeFlag.CO_FUTURE_DIVISION), ++ isFlagSet(CodeFlag.CO_NESTED), ++ isFlagSet(CodeFlag.CO_GENERATOR_ALLOWED), ++ isFlagSet(CodeFlag.CO_FUTURE_WITH_STATEMENT), ++ isFlagSet(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT), ++ only_ast, dont_imply_dedent, source_is_utf8); ++ } ++ ++ public static CompilerFlags getCompilerFlags() { ++ return getCompilerFlags(0, false); ++ } ++ ++ private static final int CO_ALL_FEATURES = CompilerFlags.PyCF_DONT_IMPLY_DEDENT ++ | CompilerFlags.PyCF_ONLY_AST ++ | CompilerFlags.PyCF_SOURCE_IS_UTF8 ++ | CodeFlag.CO_NESTED.flag ++ | CodeFlag.CO_GENERATOR_ALLOWED.flag ++ | CodeFlag.CO_FUTURE_DIVISION.flag ++ | CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT.flag ++ | CodeFlag.CO_FUTURE_WITH_STATEMENT.flag; ++ ++ public static CompilerFlags getCompilerFlags(int flags, boolean dont_inherit) { ++ if ((flags & ~CO_ALL_FEATURES) != 0) { ++ throw Py.ValueError("compile(): unrecognised flags"); ++ } ++ CompilerFlags cflags = null; ++ if (dont_inherit) { ++ cflags = new CompilerFlags(flags); ++ } else { ++ PyFrame frame = Py.getFrame(); ++ if (frame != null && frame.f_code != null) { ++ cflags = new CompilerFlags(frame.f_code.co_flags | flags); ++ } ++ } ++ return cflags; ++ } + } +diff --git a/jython/src/org/python/core/FutureFeature.java b/jython/src/org/python/core/FutureFeature.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/FutureFeature.java +@@ -0,0 +1,101 @@ ++package org.python.core; ++ ++import org.python.antlr.ParseException; ++ ++public enum FutureFeature implements Pragma { ++ /** ++ * Enables nested scopes. ++ */ ++ nested_scopes(CodeFlag.CO_NESTED), ++ /** ++ * Makes integer / integer division return float. ++ */ ++ division(CodeFlag.CO_FUTURE_DIVISION), ++ /** ++ * Enables generators. ++ */ ++ generators(CodeFlag.CO_GENERATOR_ALLOWED), ++ /** ++ * Enables absolute imports. ++ */ ++ absolute_import(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT), ++ /** ++ * Enables the with statement. ++ */ ++ with_statement(CodeFlag.CO_FUTURE_WITH_STATEMENT), ++ /** ++ * Use braces for block delimiters instead of indentation. ++ */ ++ braces { ++ @Override ++ public void addTo(PragmaReceiver features) { ++ throw new ParseException("not a chance"); ++ } ++ }, ++ /** ++ * Enable the Global Interpreter Lock in Jython. ++ */ ++ GIL { ++ @Override ++ public void addTo(PragmaReceiver features) { ++ throw new ParseException("Never going to happen!"); ++ } ++ }, ++ /** ++ * Enable the Global Interpreter Loc... [truncated message content] |
From: <th...@us...> - 2009-03-30 15:57:43
|
Revision: 6121 http://jython.svn.sourceforge.net/jython/?rev=6121&view=rev Author: thobes Date: 2009-03-30 15:57:27 +0000 (Mon, 30 Mar 2009) Log Message: ----------- Checking in current progress on the advanced compiler before diving in to the PyCon sprinting session. Modified Paths: -------------- trunk/sandbox/tobias/.classpath trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch trunk/sandbox/tobias/.hg/patches/series trunk/sandbox/tobias/.hg/patches/types.patch trunk/sandbox/tobias/build.xml trunk/sandbox/tobias/bytecode/build.xml trunk/sandbox/tobias/bytecode/src/org/python/bytecode/ReferenceResolver.java trunk/sandbox/tobias/compiler/build.xml trunk/sandbox/tobias/compiler/src/org/python/compiler/AdvancedCompiler.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/YieldPoint.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Graph.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/IfNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Node.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/OpNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/PhiNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/SwitchNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Value.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ValueNode.java trunk/sandbox/tobias/util/build.xml trunk/sandbox/tobias/util/src/org/python/code/CodeTable.java trunk/sandbox/tobias/util/src/org/python/code/SpecializedCode.java Added Paths: ----------- trunk/sandbox/tobias/.hg/patches/frames.patch trunk/sandbox/tobias/.hg/patches/grammar.patch trunk/sandbox/tobias/.hg/patches/parrot.patch trunk/sandbox/tobias/bin/ trunk/sandbox/tobias/bin/jython trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Assignment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/AssignmentGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/AugAssignCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/BytecodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/BytecodeCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CompilerDirector.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Constant.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstantChecker.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstantCodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstantOwner.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstantPool.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstraintsDefinition.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/IntermediateCodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/IntermediateCodeGeneratorFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/PragmaParser.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Preferences.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeAnalyzer.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeInformation.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopesBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/SyntaxErrorPolicy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/direct/ trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/direct/DirectCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/direct/DirectGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/ trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/CodeGeneratorGraphVisitor.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/FlowGraphBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/FlowGraphGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/GeneratedCodeState.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/ trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/NodeSeaBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/NodeSeaConstantGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/NodeSeaGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/SeaScope.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/ValueCarrier.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/ trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/BlockCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/CallStrategy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/FrameStrategy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/GeneratorCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/GraphBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/InvocationStrategy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/LoopCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/LoopHandle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/PythonOperation.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/PythonTypes.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/SelectionCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/StateCarrier.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/SuperGraph.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/SupergraphVisitor.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/UnrollerCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/Variable.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ArrayNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ArrayValue.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/CodeGenerationTraverser.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Continuation.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ExceptionValue.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/GraphBuilder.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/GraphTraverser.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/InvocationNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/InvocationType.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/LoadNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/NamespacePopulator.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/NodeSorter.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Selection.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/SerializationTraverser.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/StoreNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ThrowNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/TransformationTraverser.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/VariableFactory.java trunk/sandbox/tobias/compiler/test/ trunk/sandbox/tobias/compiler/test/org/ trunk/sandbox/tobias/compiler/test/org/python/ trunk/sandbox/tobias/compiler/test/org/python/compiler/ trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/ trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/output/ trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/output/GraphvizOutput.java trunk/sandbox/tobias/util/src/META-INF/ trunk/sandbox/tobias/util/src/META-INF/services/ trunk/sandbox/tobias/util/src/META-INF/services/org.python.core.FrameAccessor$Factory trunk/sandbox/tobias/util/src/org/python/frame/ trunk/sandbox/tobias/util/src/org/python/frame/JavaFrameAccessor.java Removed Paths: ------------- trunk/sandbox/tobias/compiler/src/org/python/compiler/AdvancedPreferences.java trunk/sandbox/tobias/compiler/src/org/python/compiler/BytecodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/BytecodeCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/CodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/CodeGeneratorGraphVisitor.java trunk/sandbox/tobias/compiler/src/org/python/compiler/CompilerDirector.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ConstantChecker.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ConstraintsDefinition.java trunk/sandbox/tobias/compiler/src/org/python/compiler/DirectCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/DirectGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/FlowGraphBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/FlowGraphGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/GeneratedCodeState.java trunk/sandbox/tobias/compiler/src/org/python/compiler/IntermediateCodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/IntermediateCodeGeneratorFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/PragmaParser.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopeBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopeFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopeInformation.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopesBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/SyntaxErrorPolicy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/AbstractEnvironment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/BytecodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/BytecodeLoader.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ClassEnvironment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CodeInfo.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CompilerFlag.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CompilerPolicy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CompilerVariable.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Environment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/EnvironmentError.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/EnvironmentHolder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/EnvironmentInfo.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/FunctionEnvironment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Future.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/GlobalEnvironment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeInfo.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ast/ trunk/sandbox/tobias/compiler/src/org/python/compiler/bytecode/ Modified: trunk/sandbox/tobias/.classpath =================================================================== --- trunk/sandbox/tobias/.classpath 2009-03-30 14:21:06 UTC (rev 6120) +++ trunk/sandbox/tobias/.classpath 2009-03-30 15:57:27 UTC (rev 6121) @@ -9,6 +9,7 @@ <classpathentry kind="src" path="frame/test"/> <classpathentry kind="src" path="jython/build/gensrc"/> <classpathentry kind="src" path="jython/tests/java"/> + <classpathentry kind="src" path="compiler/test"/> <classpathentry kind="lib" path="jython/Demo/jreload/example.jar"/> <classpathentry kind="lib" path="jython/extlibs/antlr-2.7.7.jar"/> <classpathentry kind="lib" path="jython/extlibs/asm-3.1.jar"/> Modified: trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch =================================================================== --- trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-03-30 14:21:06 UTC (rev 6120) +++ trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-03-30 15:57:27 UTC (rev 6121) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?><launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> -<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="antlr_gen,"/> -<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="antlr_gen,"/> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="brand-version,antlr_gen,"/> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="brand-version,antlr_gen,"/> <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"> @@ -13,7 +13,16 @@ <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="advanced-compiler"/> +<mapAttribute key="org.eclipse.ui.externaltools.ATTR_ANT_PROPERTIES"> +<mapEntry key="eclipse.pdebuild.scripts" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/scripts/"/> +<mapEntry key="eclipse.running" value="true"/> +<mapEntry key="eclipse.pdebuild.home" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/./"/> +<mapEntry key="eclipse.home" value="/Library/eclipse"/> +<mapEntry key="compile.dir" value="${project_loc}/target/build"/> +<mapEntry key="eclipse.pdebuild.templates" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/templates/"/> +</mapAttribute> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/advanced-compiler/jython/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="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/> </launchConfiguration> Added: trunk/sandbox/tobias/.hg/patches/frames.patch =================================================================== --- trunk/sandbox/tobias/.hg/patches/frames.patch (rev 0) +++ trunk/sandbox/tobias/.hg/patches/frames.patch 2009-03-30 15:57:27 UTC (rev 6121) @@ -0,0 +1,1646 @@ +diff --git a/jython/src/org/python/compiler/ClassConstants.java b/jython/src/org/python/compiler/ClassConstants.java +--- a/jython/src/org/python/compiler/ClassConstants.java ++++ b/jython/src/org/python/compiler/ClassConstants.java +@@ -7,6 +7,7 @@ + final static String $pyStr = "Lorg/python/core/PyString;"; + final static String $pyUnicode = "Lorg/python/core/PyUnicode;"; + final static String $pyExc = "Lorg/python/core/PyException;"; ++ final static String $pyBaseFrame= "Lorg/python/core/PyBaseFrame;"; + final static String $pyFrame = "Lorg/python/core/PyFrame;"; + final static String $pyCode = "Lorg/python/core/PyCode;"; + final static String $pyInteger = "Lorg/python/core/PyInteger;"; +diff --git a/jython/src/org/python/compiler/CodeCompiler.java b/jython/src/org/python/compiler/CodeCompiler.java +--- a/jython/src/org/python/compiler/CodeCompiler.java ++++ b/jython/src/org/python/compiler/CodeCompiler.java +@@ -164,7 +164,7 @@ + } + + private void loadf_back() throws Exception { +- code.getfield("org/python/core/PyFrame", "f_back", $pyFrame); ++ code.getfield("org/python/core/PyFrame", "f_back", $pyBaseFrame); + } + + public int storeTop() throws Exception { +@@ -376,7 +376,7 @@ + } + SymInfo symInfo = upTbl.get(scope.freevars.elementAt(i)); + code.iconst(symInfo.env_index); +- code.invokevirtual("org/python/core/PyFrame", "getclosure", "(I)" + $pyObj); ++ code.invokevirtual("org/python/core/PyBaseFrame", "getclosure", "(I)" + $pyObj); + code.aastore(); + } + +@@ -780,7 +780,7 @@ + asname = a.getInternalAsname(); + code.ldc(name); + loadFrame(); +- code.invokestatic("org/python/core/imp", "importOneAs", "(" + $str + $pyFrame + ")" + $pyObj); ++ code.invokestatic("org/python/core/imp", "importOneAs", "(" + $str + $pyBaseFrame + ")" + $pyObj); + } else { + String name = a.getInternalName(); + asname = name; +@@ -788,7 +788,7 @@ + asname = asname.substring(0, asname.indexOf('.')); + code.ldc(name); + loadFrame(); +- code.invokestatic("org/python/core/imp", "importOne", "(" + $str + $pyFrame + ")" + $pyObj); ++ code.invokestatic("org/python/core/imp", "importOne", "(" + $str + $pyBaseFrame + ")" + $pyObj); + } + set(new Name(a, asname, expr_contextType.Store)); + } +@@ -826,7 +826,7 @@ + } + + loadFrame(); +- code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); ++ code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyBaseFrame + ")V"); + } else { + java.util.List<String> fromNames = new ArrayList<String>();//[names.size()]; + java.util.List<String> asnames = new ArrayList<String>();//[names.size()]; +@@ -851,7 +851,7 @@ + } else { + code.iconst(node.getInternalLevel()); + } +- code.invokestatic("org/python/core/imp", "importFrom", "(" + $str + $strArr + $pyFrame + "I" + ")" + $pyObjArr); ++ code.invokestatic("org/python/core/imp", "importFrom", "(" + $str + $strArr + $pyBaseFrame + "I" + ")" + $pyObjArr); + int tmp = storeTop(); + for (int i = 0; i < names.size(); i++) { + code.aload(tmp); +@@ -1188,7 +1188,7 @@ + code.aload(excLocal); + loadFrame(); + +- code.invokestatic("org/python/core/Py", "addTraceback", "(" + $throwable + $pyFrame + ")V"); ++ code.invokestatic("org/python/core/Py", "addTraceback", "(" + $throwable + $pyBaseFrame + ")V"); + + inlineFinally(inFinally); + code.aload(excLocal); +@@ -1271,7 +1271,7 @@ + + loadFrame(); + +- code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); ++ code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyBaseFrame + ")" + $pyExc); + + int exc = code.getFinallyLocal("java/lang/Throwable"); + code.astore(exc); +@@ -2315,7 +2315,7 @@ + code.label(label_catch); + + loadFrame(); +- code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); ++ code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyBaseFrame + ")" + $pyExc); + code.pop(); + + code.invokestatic("org/python/core/Py", "getThreadState", "()Lorg/python/core/ThreadState;"); +diff --git a/jython/src/org/python/core/CompilerFlags.java b/jython/src/org/python/core/CompilerFlags.java +--- a/jython/src/org/python/core/CompilerFlags.java ++++ b/jython/src/org/python/core/CompilerFlags.java +@@ -83,7 +83,7 @@ + | CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT.flag + | CodeFlag.CO_FUTURE_WITH_STATEMENT.flag; + +- public static CompilerFlags getCompilerFlags(int flags, PyFrame frame) { ++ public static CompilerFlags getCompilerFlags(int flags, PyBaseFrame frame) { + if ((flags & ~CO_ALL_FEATURES) != 0) { + throw Py.ValueError("compile(): unrecognised flags"); + } +@@ -91,9 +91,9 @@ + } + + public static CompilerFlags getCompilerFlags(CompilerFlags flags, +- PyFrame frame) { +- if (frame != null && frame.f_code != null) { +- return frame.f_code.co_flags.combine(flags); ++ PyBaseFrame frame) { ++ if (frame != null && frame.getCode() != null) { ++ return frame.getCode().co_flags.combine(flags); + } else { + return flags; + } +diff --git a/jython/src/org/python/core/FrameAccessor.java b/jython/src/org/python/core/FrameAccessor.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/FrameAccessor.java +@@ -0,0 +1,51 @@ ++package org.python.core; ++ ++import java.util.Comparator; ++import java.util.SortedSet; ++import java.util.TreeSet; ++ ++import org.python.util.ServiceLoader; ++ ++public abstract class FrameAccessor { ++ ++ protected abstract PyBaseFrame getFrame(); ++ ++ protected abstract void setFrame(PyBaseFrame frame); ++ ++ public static abstract class Factory { ++ protected abstract FrameAccessor createAccessor(); ++ ++ @Override ++ public final boolean equals(Object other) { ++ return other != null && getClass().equals(other.getClass()); ++ } ++ ++ protected abstract boolean isAvailable(); ++ ++ @Override ++ public final int hashCode() { ++ return getClass().hashCode(); ++ } ++ } ++ ++ static Factory getFactory() { ++ return best_factory; ++ } ++ ++ private static final Factory best_factory; ++ static { ++ SortedSet<Factory> factories = new TreeSet<Factory>( ++ new Comparator<Factory>() { ++ public int compare(Factory one, Factory two) { ++ throw new UnsupportedOperationException( ++ /* TODO: */"Need a way to sort Frame Accessor factories."); ++ } ++ }); ++ for (Factory candidate : ServiceLoader.load(Factory.class)) { ++ if (candidate.isAvailable()) { ++ factories.add(candidate); ++ } ++ } ++ best_factory = factories.isEmpty() ? null : factories.first(); ++ } ++} +diff --git a/jython/src/org/python/core/NewCompilerResources.java b/jython/src/org/python/core/NewCompilerResources.java +--- a/jython/src/org/python/core/NewCompilerResources.java ++++ b/jython/src/org/python/core/NewCompilerResources.java +@@ -16,7 +16,7 @@ + * Called from jython generated code when a statement like "from spam.eggs + * import *" is executed. + */ +- public static void importAll(PyObject module, PyFrame frame) { ++ public static void importAll(PyObject module, PyBaseFrame frame) { + // System.out.println("importAll(" + mod + ")"); + PyObject names; + boolean filter = true; +diff --git a/jython/src/org/python/core/Py.java b/jython/src/org/python/core/Py.java +--- a/jython/src/org/python/core/Py.java ++++ b/jython/src/org/python/core/Py.java +@@ -925,11 +925,11 @@ + printException(t, null, null); + } + +- public static void printException(Throwable t, PyFrame f) { ++ public static void printException(Throwable t, PyBaseFrame f) { + printException(t, f, null); + } + +- public static synchronized void printException(Throwable t, PyFrame f, ++ public static synchronized void printException(Throwable t, PyBaseFrame f, + PyObject file) { + StdoutWrapper stderr = Py.stderr; + +@@ -1122,12 +1122,12 @@ + } + + /* Helpers to implement finally clauses */ +- public static void addTraceback(Throwable t, PyFrame frame) { ++ public static void addTraceback(Throwable t, PyBaseFrame frame) { + Py.JavaError(t).tracebackHere(frame, true); + } + + /* Helpers to implement except clauses */ +- public static PyException setException(Throwable t, PyFrame frame) { ++ public static PyException setException(Throwable t, PyBaseFrame frame) { + PyException pye = Py.JavaError(t); + pye.normalize(); + pye.tracebackHere(frame); +@@ -1203,7 +1203,7 @@ + } + + if (globals == null || globals == Py.None) { +- globals = Py.getFrame().f_globals; ++ globals = Py.getFrame().getGlobals(); + } + + PyTableCode tc = null; +@@ -1275,16 +1275,16 @@ + } + + /* Get and set the current frame */ +- public static PyFrame getFrame() { ++ public static PyBaseFrame getFrame() { + ThreadState ts = getThreadState(); + if (ts == null) { + return null; + } +- return ts.frame; ++ return ts.getFrame(); + } + +- public static void setFrame(PyFrame f) { +- getThreadState().frame = f; ++ public static void setFrame(PyBaseFrame f) { ++ getThreadState().setFrame(f); + } + + /* A collection of functions for implementing the print statement */ +@@ -1530,7 +1530,7 @@ + public static PyObject makeClass(String name, PyObject[] bases, + PyCode code, PyObject doc, + PyObject[] closure_cells) { +- PyObject globals = getFrame().f_globals; ++ PyObject globals = getFrame().getGlobals(); + PyObject dict = code.call(Py.EmptyObjects, Py.NoKeywords, globals, Py.EmptyObjects, + new PyTuple(closure_cells)); + if (doc != null && dict.__finditem__("__doc__") == null) { +@@ -1554,7 +1554,7 @@ + * @return a new Python Class PyObject + */ + public static PyObject makeClass(String name, PyObject[] bases, PyObject dict) { +- PyFrame frame = getFrame(); ++ PyBaseFrame frame = getFrame(); + if (dict.__finditem__("__module__") == null) { + PyObject module = frame.getglobal("__name__"); + if (module != null) { +@@ -1572,7 +1572,7 @@ + metaclass = base.getType(); + } + } else { +- PyObject globals = frame.f_globals; ++ PyObject globals = frame.getGlobals(); + if (globals != null) { + metaclass = globals.__finditem__("__metaclass__"); + } +@@ -1617,7 +1617,7 @@ + } + + public static CompilerFlags getCompilerFlags(int flags, boolean dont_inherit) { +- final PyFrame frame; ++ final PyBaseFrame frame; + if (dont_inherit) { + frame = null; + } else { +@@ -1627,7 +1627,7 @@ + } + + public static CompilerFlags getCompilerFlags(CompilerFlags flags, boolean dont_inherit) { +- final PyFrame frame; ++ final PyBaseFrame frame; + if (dont_inherit) { + frame = null; + } else { +@@ -1984,7 +1984,7 @@ + } + } + +- public PyObject call(PyFrame frame, PyObject closure) { ++ public PyObject call(PyBaseFrame frame, PyObject closure) { + //XXX: what the heck is this? Looks like debug code, but it's + // been here a long time... + System.out.println("call #1"); +diff --git a/jython/src/org/python/core/PyBaseCode.java b/jython/src/org/python/core/PyBaseCode.java +--- a/jython/src/org/python/core/PyBaseCode.java ++++ b/jython/src/org/python/core/PyBaseCode.java +@@ -22,8 +22,9 @@ + return co_freevars != null && co_freevars.length > 0; + } + +- public PyObject call(PyFrame frame, PyObject closure) { ++ public PyObject call(PyBaseFrame _frame, PyObject closure) { + // System.err.println("tablecode call: "+co_name); ++ PyFrame frame = (PyFrame)_frame; + ThreadState ts = Py.getThreadState(); + if (ts.systemState == null) { + ts.systemState = Py.defaultSystemState; +@@ -34,26 +35,26 @@ + PyException previous_exception = ts.exception; + + // Push frame +- frame.f_back = ts.frame; +- if (frame.f_builtins == null) { +- if (frame.f_back != null) { +- frame.f_builtins = frame.f_back.f_builtins; ++ frame.setPrevious(ts.getFrame()); ++ if (frame.getBuiltins() == null) { ++ if (frame.getPrevious() != null) { ++ frame.setBuiltins(frame.getPrevious().getBuiltins()); + } else { + //System.err.println("ts: "+ts); + //System.err.println("ss: "+ts.systemState); +- frame.f_builtins = PySystemState.builtins; ++ frame.setBuiltins(PySystemState.builtins); + } + } + // nested scopes: setup env with closure + // this should only be done once, so let the frame take care of it + frame.setupEnv((PyTuple)closure); + +- ts.frame = frame; ++ ts.setFrame(frame); + + // Handle trace function for debugging + if (ts.tracefunc != null) { +- frame.f_lineno = co_firstlineno; +- frame.tracefunc = ts.tracefunc.traceCall(frame); ++ frame.setLineno(co_firstlineno); ++ frame.setTraceFunction(ts.tracefunc.traceCall(frame)); + } + + // Handle trace function for profiling +@@ -69,10 +70,11 @@ + PyException pye = Py.JavaError(t); + pye.tracebackHere(frame); + +- frame.f_lasti = -1; ++ frame.setLastI(-1); + +- if (frame.tracefunc != null) { +- frame.tracefunc.traceException(frame, pye); ++ TraceFunction tracefunc = frame.getTraceFunction(); ++ if (tracefunc != null) { ++ tracefunc.traceException(frame, pye); + } + if (ts.profilefunc != null) { + ts.profilefunc.traceException(frame, pye); +@@ -80,12 +82,13 @@ + + // Rethrow the exception to the next stack frame + ts.exception = previous_exception; +- ts.frame = ts.frame.f_back; ++ ts.setFrame(ts.getFrame().getPrevious()); + throw pye; + } + +- if (frame.tracefunc != null) { +- frame.tracefunc.traceReturn(frame, ret); ++ TraceFunction tracefunc = frame.getTraceFunction(); ++ if (tracefunc != null) { ++ tracefunc.traceReturn(frame, ret); + } + // Handle trace function for profiling + if (ts.profilefunc != null) { +@@ -95,7 +98,7 @@ + // Restore previously defined exception + ts.exception = previous_exception; + +- ts.frame = ts.frame.f_back; ++ ts.setFrame(ts.getFrame().getPrevious()); + + // Check for interruption, which is used for restarting the interpreter + // on Jython +@@ -288,7 +291,7 @@ + protected abstract PyObject interpret(PyFrame f, ThreadState ts); + + protected int getline(PyFrame f) { +- return f.f_lineno; ++ return f.getLineno(); + } + + // returns the augmented version of CompilerFlags (instead of just as a bit vector int) +diff --git a/jython/src/org/python/core/PyBaseFrame.java b/jython/src/org/python/core/PyBaseFrame.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/PyBaseFrame.java +@@ -0,0 +1,121 @@ ++package org.python.core; ++ ++public abstract class PyBaseFrame extends PyObject { ++ ++ private static final String[] __members__ = {"f_back", "f_code", "f_locals", "f_globals", ++ "f_lineno", "f_builtins", "f_trace"}; ++ ++ public PyBaseFrame(PyType objtype) { ++ super(objtype); ++ } ++ ++ public PyBaseFrame(boolean ignored) { ++ super(ignored); ++ } ++ ++ public abstract void setderef(int index, PyObject value); ++ ++ public abstract PyObject getderef(int index); ++ ++ public abstract PyObject getclosure(int index); ++ ++ public abstract void delglobal(String index); ++ ++ public abstract void dellocal(String index); ++ ++ public abstract void dellocal(int index); ++ ++ public abstract void setglobal(String index, PyObject value); ++ ++ public abstract void setlocal(String index, PyObject value); ++ ++ public abstract void setlocal(int index, PyObject value); ++ ++ public abstract PyObject getglobal(String index); ++ ++ public abstract PyObject getname_or_null(String index); ++ ++ public abstract PyObject getname(String index); ++ ++ public abstract PyObject getlocal(int index); ++ ++ public abstract PyObject getLocals(); ++ ++ public abstract int getLastI(); ++ ++ public abstract void setLastI(int f_lasti); ++ ++ public abstract PyObject getBuiltins(); ++ ++ public abstract int getLineno(); ++ ++ public abstract PyObject getGlobals(); ++ ++ public abstract PyBaseCode getCode(); ++ ++ public abstract PyBaseFrame getPrevious(); ++ ++ public abstract TraceFunction getTraceFunction(); ++ ++ public abstract void setTraceFunction(TraceFunction trace); ++ ++ public PyBaseFrame() { ++ super(); ++ } ++ ++ public PyObject __dir__() { ++ PyString members[] = new PyString[__members__.length]; ++ for (int i = 0; i < __members__.length; i++) { ++ members[i] = new PyString(__members__[i]); ++ } ++ return new PyList(members); ++ } ++ ++ private void throwReadonly(String name) { ++ for (String member : __members__) { ++ if (member == name) { ++ throw Py.TypeError("readonly attribute"); ++ } ++ } ++ throw Py.AttributeError(name); ++ } ++ ++ public void __setattr__(String name, PyObject value) { ++ // In CPython, some of the frame's attributes are read/writeable ++ if (name == "f_trace") { ++ setTraceFunction(new PythonTraceFunction(value)); ++ } else { ++ throwReadonly(name); ++ } ++ // not yet implemented: ++ // f_exc_type ++ // f_exc_value ++ // f_exc_traceback ++ } ++ ++ public void __delattr__(String name) { ++ if (name == "f_trace") { ++ setTraceFunction(null); ++ } else { ++ throwReadonly(name); ++ } ++ // not yet implemented: ++ // f_exc_type ++ // f_exc_value ++ // f_exc_traceback ++ } ++ ++ public PyObject __findattr_ex__(String name) { ++ if (name == "f_locals") { ++ return getLocals(); ++ } else if (name == "f_trace") { ++ TraceFunction tracefunc = getTraceFunction(); ++ if (tracefunc instanceof PythonTraceFunction) { ++ return ((PythonTraceFunction)tracefunc).tracefunc; ++ } ++ return Py.None; ++ } ++ return super.__findattr_ex__(name); ++ } ++ ++} +\ No newline at end of file +diff --git a/jython/src/org/python/core/PyBytecode.java b/jython/src/org/python/core/PyBytecode.java +--- a/jython/src/org/python/core/PyBytecode.java ++++ b/jython/src/org/python/core/PyBytecode.java +@@ -204,11 +204,11 @@ + } + + private static String stringify_blocks(PyFrame f) { +- if (f.f_exits == null || f.f_lineno == 0) { ++ if (f.f_exits == null || f.getLineno() == 0) { + return "[]"; + } + StringBuilder buf = new StringBuilder("["); +- int len = f.f_lineno; ++ int len = f.getLineno(); + for (int i = 0; i < len; i++) { + buf.append(f.f_exits[i].toString()); + if (i < len - 1) { +@@ -222,7 +222,7 @@ + private void print_debug(int count, int next_instr, int line, int opcode, int oparg, PyStack stack, PyFrame f) { + if (debug) { + System.err.println(co_name + " " + line + ":" + +- count + "," + f.f_lasti + "> " + ++ count + "," + f.getLastI() + "> " + + get_opname().__getitem__(Py.newInteger(opcode)) + + (opcode >= Opcode.HAVE_ARGUMENT ? " " + oparg : "") + + ", stack: " + stack.toString() + +@@ -270,7 +270,7 @@ + // in a shadow version of the frame that we copy back to on entry/exit and downcalls + + if (debug) { +- System.err.println(co_name + ":" + f.f_lasti + "/" + co_code.length + ++ System.err.println(co_name + ":" + f.getLastI() + "/" + co_code.length + + ", cells:" + Arrays.toString(co_cellvars) + ", free:" + Arrays.toString(co_freevars)); + int i = 0; + for (String cellvar : co_cellvars) { +@@ -282,11 +282,11 @@ + get_dis().invoke("disassemble", this); + + } +- if (f.f_lasti >= co_code.length) { ++ if (f.getLastI() >= co_code.length) { + throw Py.SystemError(""); // XXX - chose an appropriate error!!! + } + +- next_instr = f.f_lasti; ++ next_instr = f.getLastI(); + + // the restore stack aspects should occur ONLY after a yield + boolean checkGeneratorInput = false; +@@ -301,7 +301,7 @@ + + while (!debug || (maxCount == -1 || count < maxCount)) { // XXX - replace with while(true) + +- if (f.tracefunc != null || debug) { ++ if (f.getTraceFunction() != null || debug) { + if (lineCache == null) { + lineCache = new LineCache(); + if (debug) { +@@ -334,7 +334,7 @@ + + count += 1; + next_instr += 1; +- f.f_lasti = next_instr; ++ f.setLastI(next_instr); + + switch (opcode) { + case Opcode.NOP: +@@ -702,7 +702,7 @@ + } + + case Opcode.LOAD_LOCALS: +- stack.push(f.f_locals); ++ stack.push(f.getf_locals()); + break; + + case Opcode.RETURN_VALUE: +@@ -828,7 +828,7 @@ + cell.ob_ref = f.f_fastlocals[i]; + } + } else { +- cell.ob_ref = f.f_locals.__finditem__(name); ++ cell.ob_ref = f.getf_locals().__finditem__(name); + } + } + stack.push(cell); +@@ -862,7 +862,7 @@ + cell.ob_ref = f.f_fastlocals[i]; + } + } else { +- cell.ob_ref = f.f_locals.__finditem__(name); ++ cell.ob_ref = f.getf_locals().__finditem__(name); + } + } + stack.push(cell.ob_ref); +@@ -941,7 +941,7 @@ + } + + case Opcode.IMPORT_NAME: { +- PyObject __import__ = f.f_builtins.__finditem__("__import__"); ++ PyObject __import__ = f.getBuiltins().__finditem__("__import__"); + if (__import__ == null) { + throw Py.ImportError("__import__ not found"); + } +@@ -950,9 +950,9 @@ + PyObject level = stack.pop(); + + if (level.asInt() != -1) { +- stack.push(__import__.__call__(new PyObject[]{name, f.f_globals, f.f_locals, fromlist, level})); ++ stack.push(__import__.__call__(new PyObject[]{name, f.getGlobals(), f.getf_locals(), fromlist, level})); + } else { +- stack.push(__import__.__call__(new PyObject[]{name, f.f_globals, f.f_locals, fromlist})); ++ stack.push(__import__.__call__(new PyObject[]{name, f.getGlobals(), f.getf_locals(), fromlist})); + } + break; + } +@@ -1118,7 +1118,7 @@ + if (code instanceof PyBytecode && ((PyBytecode) code).co_consts.length > 0) { + doc = ((PyBytecode) code).co_consts[0]; + } +- PyFunction func = new PyFunction(f.f_globals, defaults, code, doc); ++ PyFunction func = new PyFunction(f.getGlobals(), defaults, code, doc); + stack.push(func); + break; + } +@@ -1131,7 +1131,7 @@ + if (code instanceof PyBytecode && ((PyBytecode) code).co_consts.length > 0) { + doc = ((PyBytecode) code).co_consts[0]; + } +- PyFunction func = new PyFunction(f.f_globals, defaults, code, doc, closure_cells); ++ PyFunction func = new PyFunction(f.getGlobals(), defaults, code, doc, closure_cells); + stack.push(func); + break; + } +@@ -1154,7 +1154,7 @@ + Py.print(Py.getSystemState().stderr, + Py.newString( + String.format("XXX lineno: %d, opcode: %d\n", +- f.f_lasti, opcode))); ++ f.getLastI(), opcode))); + throw Py.SystemError("unknown opcode"); + + } // end switch +@@ -1236,10 +1236,10 @@ + f.f_savedlocals = stack.popN(stack.size()); + } + +- f.f_lasti = next_instr; // need to update on function entry, etc ++ f.setLastI(next_instr); // need to update on function entry, etc + + if (debug) { +- System.err.println(count + "," + f.f_lasti + "> Returning from " + why + ": " + retval + ++ System.err.println(count + "," + f.getLastI() + "> Returning from " + why + ": " + retval + + ", stack: " + stack.toString() + + ", blocks: " + stringify_blocks(f)); + } +@@ -1249,7 +1249,7 @@ + } + + if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR) && why == Why.RETURN && retval == Py.None) { +- f.f_lasti = -1; ++ f.setLastI(-1); + } + + return retval; +@@ -1503,7 +1503,7 @@ + + @Override + protected int getline(PyFrame f) { +- int addrq = f.f_lasti; ++ int addrq = f.getLastI(); + int size = co_lnotab.length / 2; + int p = 0; + int line = co_firstlineno; +diff --git a/jython/src/org/python/core/PyClass.java b/jython/src/org/python/core/PyClass.java +--- a/jython/src/org/python/core/PyClass.java ++++ b/jython/src/org/python/core/PyClass.java +@@ -62,9 +62,9 @@ + protected void findModule(PyObject dict) { + PyObject module = dict.__finditem__("__module__"); + if (module == null || module == Py.None) { +- PyFrame f = Py.getFrame(); ++ PyBaseFrame f = Py.getFrame(); + if (f != null) { +- PyObject nm = f.f_globals.__finditem__("__name__"); ++ PyObject nm = f.getGlobals().__finditem__("__name__"); + if (nm != null) { + dict.__setitem__("__module__", nm); + } +diff --git a/jython/src/org/python/core/PyCode.java b/jython/src/org/python/core/PyCode.java +--- a/jython/src/org/python/core/PyCode.java ++++ b/jython/src/org/python/core/PyCode.java +@@ -8,9 +8,9 @@ + { + public String co_name; + +- abstract public PyObject call(PyFrame frame, PyObject closure); ++ abstract public PyObject call(PyBaseFrame frame, PyObject closure); + +- public PyObject call(PyFrame frame) { ++ public PyObject call(PyBaseFrame frame) { + return call(frame, null); + } + +diff --git a/jython/src/org/python/core/PyException.java b/jython/src/org/python/core/PyException.java +--- a/jython/src/org/python/core/PyException.java ++++ b/jython/src/org/python/core/PyException.java +@@ -136,7 +136,7 @@ + * + * @param here the current PyFrame + */ +- public void tracebackHere(PyFrame here) { ++ public void tracebackHere(PyBaseFrame here) { + tracebackHere(here, false); + } + +@@ -146,7 +146,7 @@ + * @param here the current PyFrame + * @param isFinally whether caller is a Python finally block + */ +- public void tracebackHere(PyFrame here, boolean isFinally) { ++ public void tracebackHere(PyBaseFrame here, boolean isFinally) { + if (!isReRaise && here != null) { + // the frame is either inapplicable or already registered (from a finally) + // during a re-raise +diff --git a/jython/src/org/python/core/PyFrame.java b/jython/src/org/python/core/PyFrame.java +--- a/jython/src/org/python/core/PyFrame.java ++++ b/jython/src/org/python/core/PyFrame.java +@@ -4,11 +4,13 @@ + /** + * A Python frame object. + */ +-public class PyFrame extends PyObject ++public class PyFrame extends PyBaseFrame + { +- public PyFrame f_back; ++ // These are public because they are accessed from generated code ++ ++ public PyBaseFrame f_back; + +- public PyBaseCode f_code; ++ public final PyBaseCode f_code; + + public PyObject f_locals; + +@@ -18,6 +20,10 @@ + + public PyObject f_builtins; + ++ public int f_lasti; ++ ++ // Internal ++ + public PyObject[] f_fastlocals; + + /** nested scopes: cell + free env. */ +@@ -27,8 +33,6 @@ + + public int f_nfreevars; + +- public int f_lasti; +- + public Object[] f_savedlocals; + + private int env_j = 0; +@@ -36,11 +40,11 @@ + private Object generatorInput = Py.None; + + // with context exits - used by generated bytecode +- public PyObject[] f_exits; ++ public PyObject[] f_exits; // Impl. + + /** an interface to functions suitable for tracing, e.g. via + * sys.settrace(). */ +- public TraceFunction tracefunc; ++ private TraceFunction tracefunc; // Publ. + + private static final String NAME_ERROR_MSG = "name '%.200s' is not defined"; + +@@ -49,8 +53,62 @@ + private static final String UNBOUNDLOCAL_ERROR_MSG = + "local variable '%.200s' referenced before assignment"; + +- private static final String[] __members__ = {"f_back", "f_code", "f_locals", "f_globals", +- "f_lineno", "f_builtins", "f_trace"}; ++ @Override ++ public PyBaseFrame getPrevious() { ++ return f_back; ++ } ++ ++ void setPrevious(PyBaseFrame f_back) { ++ this.f_back = f_back; ++ } ++ ++ @Override ++ public PyBaseCode getCode() { ++ return f_code; ++ } ++ ++ @Override ++ public PyObject getGlobals() { ++ return f_globals; ++ } ++ ++ void setLineno(int f_lineno) { ++ this.f_lineno = f_lineno; ++ } ++ ++ @Override ++ public int getLineno() { ++ return f_lineno; ++ } ++ ++ void setBuiltins(PyObject f_builtins) { ++ this.f_builtins = f_builtins; ++ } ++ ++ @Override ++ public PyObject getBuiltins() { ++ return f_builtins; ++ } ++ ++ @Override ++ public void setLastI(int f_lasti) { ++ this.f_lasti = f_lasti; ++ } ++ ++ @Override ++ public int getLastI() { ++ return f_lasti; ++ } ++ ++ @Override ++ public TraceFunction getTraceFunction() { ++ return tracefunc; ++ } ++ ++ @Override ++ public void setTraceFunction(TraceFunction trace) { ++ tracefunc = trace; ++ } + + public PyFrame(PyBaseCode code, PyObject locals, PyObject globals, + PyObject builtins) +@@ -106,14 +164,6 @@ + } + } + +- public PyObject __dir__() { +- PyString members[] = new PyString[__members__.length]; +- for (int i = 0; i < __members__.length; i++) { +- members[i] = new PyString(__members__[i]); +- } +- return new PyList(members); +- } +- + void setGeneratorInput(Object value) { + generatorInput = value; + } +@@ -128,58 +178,13 @@ + return generatorInput; + } + +- private void throwReadonly(String name) { +- for (String member : __members__) { +- if (member == name) { +- throw Py.TypeError("readonly attribute"); +- } +- } +- throw Py.AttributeError(name); +- } +- +- public void __setattr__(String name, PyObject value) { +- // In CPython, some of the frame's attributes are read/writeable +- if (name == "f_trace") { +- tracefunc = new PythonTraceFunction(value); +- } else { +- throwReadonly(name); +- } +- // not yet implemented: +- // f_exc_type +- // f_exc_value +- // f_exc_traceback +- } +- +- public void __delattr__(String name) { +- if (name == "f_trace") { +- tracefunc = null; +- } else { +- throwReadonly(name); +- } +- // not yet implemented: +- // f_exc_type +- // f_exc_value +- // f_exc_traceback +- } +- +- public PyObject __findattr_ex__(String name) { +- if (name == "f_locals") { +- return getLocals(); +- } else if (name == "f_trace") { +- if (tracefunc instanceof PythonTraceFunction) { +- return ((PythonTraceFunction)tracefunc).tracefunc; +- } +- return Py.None; +- } +- return super.__findattr_ex__(name); +- } +- + /** + * Return the locals dict. First merges the fast locals into + * f_locals, then returns the updated f_locals. + * + * @return a PyObject mapping of locals + */ ++ @Override + public PyObject getLocals() { + if (f_locals == null) { + f_locals = new PyStringMap(); +@@ -241,6 +246,7 @@ + return f_code.getline(this); + } + ++ @Override + public PyObject getlocal(int index) { + if (f_fastlocals != null) { + PyObject ret = f_fastlocals[index]; +@@ -259,6 +265,7 @@ + throw Py.UnboundLocalError(String.format(UNBOUNDLOCAL_ERROR_MSG, name)); + } + ++ @Override + public PyObject getname(String index) { + PyObject ret; + if (f_locals == null || f_locals == f_globals) { +@@ -276,6 +283,7 @@ + throw Py.NameError(String.format(NAME_ERROR_MSG, index)); + } + ++ @Override + public PyObject getname_or_null(String index) { + PyObject ret; + if (f_locals == null || f_locals == f_globals) { +@@ -290,6 +298,7 @@ + return ret; + } + ++ @Override + public PyObject getglobal(String index) { + PyObject ret = doGetglobal(index); + if (ret != null) { +@@ -311,6 +320,7 @@ + return f_builtins.__finditem__(index); + } + ++ @Override + public void setlocal(int index, PyObject value) { + if (f_fastlocals != null) { + f_fastlocals[index] = value; +@@ -319,6 +329,7 @@ + } + } + ++ @Override + public void setlocal(String index, PyObject value) { + if (f_locals != null) { + f_locals.__setitem__(index, value); +@@ -327,10 +338,12 @@ + } + } + ++ @Override + public void setglobal(String index, PyObject value) { + f_globals.__setitem__(index, value); + } + ++ @Override + public void dellocal(int index) { + if (f_fastlocals != null) { + if (f_fastlocals[index] == null) { +@@ -343,6 +356,7 @@ + } + } + ++ @Override + public void dellocal(String index) { + if (f_locals != null) { + try { +@@ -358,6 +372,7 @@ + } + } + ++ @Override + public void delglobal(String index) { + try { + f_globals.__delitem__(index); +@@ -371,10 +386,12 @@ + + // nested scopes helpers + ++ @Override + public PyObject getclosure(int index) { + return f_env[index]; + } + ++ @Override + public PyObject getderef(int index) { + PyObject obj = f_env[index].ob_ref; + if (obj != null) { +@@ -389,6 +406,7 @@ + throw Py.UnboundLocalError(String.format(UNBOUNDLOCAL_ERROR_MSG, name)); + } + ++ @Override + public void setderef(int index, PyObject value) { + f_env[index].ob_ref = value; + } +diff --git a/jython/src/org/python/core/PyObject.java b/jython/src/org/python/core/PyObject.java +--- a/jython/src/org/python/core/PyObject.java ++++ b/jython/src/org/python/core/PyObject.java +@@ -3459,7 +3459,7 @@ + } + } else { + ThreadState ts = Py.getThreadState(); +- if (ts.frame == null) { ++ if (ts.getFrame() == null) { + Py.maybeSystemExit(e); + } + if (Options.showPythonProxyExceptions) { +diff --git a/jython/src/org/python/core/PySystemState.java b/jython/src/org/python/core/PySystemState.java +--- a/jython/src/org/python/core/PySystemState.java ++++ b/jython/src/org/python/core/PySystemState.java +@@ -140,6 +140,8 @@ + public PyObject __dict__; + + private int recursionlimit = 1000; ++ ++ private final FrameAccessor.Factory frameAccessorFactory = FrameAccessor.getFactory(); + + public PySystemState() { + initialize(); +@@ -1157,21 +1159,42 @@ + Py.getThreadState().exception = null; + } + +- public static PyFrame _getframe() { ++ public static PyBaseFrame _getframe() { + return _getframe(-1); + } + +- public static PyFrame _getframe(int depth) { +- PyFrame f = Py.getFrame(); ++ public static PyBaseFrame _getframe(int depth) { ++ PyBaseFrame f = Py.getFrame(); + + while (depth > 0 && f != null) { +- f = f.f_back; ++ f = f.getPrevious(); + --depth; + } + if (f == null) + throw Py.ValueError("call stack is not deep enough"); + return f; + } ++ ++ FrameAccessor newFrameAccessor() { ++ if (frameAccessorFactory != null) { ++ return frameAccessorFactory.createAccessor(); ++ } else { ++ return new FrameStore(); ++ } ++ } ++} ++ ++final class FrameStore extends FrameAccessor { ++ private PyBaseFrame frame = null; ++ @Override ++ protected PyBaseFrame getFrame() { ++ return frame; ++ } ++ ++ @Override ++ protected void setFrame(PyBaseFrame frame) { ++ this.frame = frame; ++ } + } + + class PySystemStateFunctions extends PyBuiltinFunctionSet +diff --git a/jython/src/org/python/core/PyTableCode.java b/jython/src/org/python/core/PyTableCode.java +--- a/jython/src/org/python/core/PyTableCode.java ++++ b/jython/src/org/python/core/PyTableCode.java +@@ -122,8 +122,9 @@ + } + + @Override +- public PyObject call(PyFrame frame, PyObject closure) { ++ public PyObject call(PyBaseFrame _frame, PyObject closure) { + // System.err.println("tablecode call: "+co_name); ++ PyFrame frame = (PyFrame)_frame; + ThreadState ts = Py.getThreadState(); + if (ts.systemState == null) { + ts.systemState = Py.defaultSystemState; +@@ -134,26 +135,26 @@ + PyException previous_exception = ts.exception; + + // Push frame +- frame.f_back = ts.frame; +- if (frame.f_builtins == null) { +- if (frame.f_back != null) { +- frame.f_builtins = frame.f_back.f_builtins; ++ frame.setPrevious(ts.getFrame()); ++ if (frame.getBuiltins() == null) { ++ if (frame.getPrevious() != null) { ++ frame.setBuiltins(frame.getPrevious().getBuiltins()); + } else { + //System.err.println("ts: "+ts); + //System.err.println("ss: "+ts.systemState); +- frame.f_builtins = PySystemState.builtins; ++ frame.setBuiltins(PySystemState.builtins); + } + } + // nested scopes: setup env with closure + // this should only be done once, so let the frame take care of it + frame.setupEnv((PyTuple)closure); + +- ts.frame = frame; ++ ts.setFrame(frame); + + // Handle trace function for debugging + if (ts.tracefunc != null) { +- frame.f_lineno = co_firstlineno; +- frame.tracefunc = ts.tracefunc.traceCall(frame); ++ frame.setLineno(co_firstlineno); ++ frame.setTraceFunction(ts.tracefunc.traceCall(frame)); + } + + // Handle trace function for profiling +@@ -169,10 +170,11 @@ + PyException pye = Py.JavaError(t); + pye.tracebackHere(frame); + +- frame.f_lasti = -1; ++ frame.setLastI(-1); + +- if (frame.tracefunc != null) { +- frame.tracefunc.traceException(frame, pye); ++ TraceFunction tracefunc = frame.getTraceFunction(); ++ if (tracefunc != null) { ++ tracefunc.traceException(frame, pye); + } + if (ts.profilefunc != null) { + ts.profilefunc.traceException(frame, pye); +@@ -180,12 +182,13 @@ + + // Rethrow the exception to the next stack frame + ts.exception = previous_exception; +- ts.frame = ts.frame.f_back; ++ ts.setFrame(ts.getFrame().getPrevious()); + throw pye; + } + +- if (frame.tracefunc != null) { +- frame.tracefunc.traceReturn(frame, ret); ++ TraceFunction tracefunc = frame.getTraceFunction(); ++ if (tracefunc != null) { ++ tracefunc.traceReturn(frame, ret); + } + // Handle trace function for profiling + if (ts.profilefunc != null) { +@@ -195,7 +198,7 @@ + // Restore previously defined exception + ts.exception = previous_exception; + +- ts.frame = ts.frame.f_back; ++ ts.setFrame(ts.getFrame().getPrevious()); + + // Check for interruption, which is used for restarting the interpreter + // on Jython +diff --git a/jython/src/org/python/core/PyTraceback.java b/jython/src/org/python/core/PyTraceback.java +--- a/jython/src/org/python/core/PyTraceback.java ++++ b/jython/src/org/python/core/PyTraceback.java +@@ -17,27 +17,27 @@ + public PyObject tb_next; + + @ExposedGet +- public PyFrame tb_frame; ++ public PyBaseFrame tb_frame; + + @ExposedGet + public int tb_lineno; + +- public PyTraceback(PyTraceback next, PyFrame frame) { ++ public PyTraceback(PyTraceback next, PyBaseFrame frame) { + tb_next = next; + tb_frame = frame; +- tb_lineno = frame.getline(); ++ tb_lineno = frame.getLineno(); + } + + private String tracebackInfo() { +- if (tb_frame == null || tb_frame.f_code == null) { ++ if (tb_frame == null || tb_frame.getCode() == null) { + return String.format(" (no code object) at line %s\n", tb_lineno); + } + String line = null; +- if (tb_frame.f_code.co_filename != null) { +- line = getLine(tb_frame.f_code.co_filename, tb_lineno); ++ if (tb_frame.getCode().co_filename != null) { ++ line = getLine(tb_frame.getCode().co_filename, tb_lineno); + } + return String.format(" File \"%.500s\", line %d, in %.500s\n%s", +- tb_frame.f_code.co_filename, tb_lineno, tb_frame.f_code.co_name, ++ tb_frame.getCode().co_filename, tb_linen... [truncated message content] |
From: <th...@us...> - 2009-04-01 02:22:21
|
Revision: 6145 http://jython.svn.sourceforge.net/jython/?rev=6145&view=rev Author: thobes Date: 2009-04-01 01:45:35 +0000 (Wed, 01 Apr 2009) Log Message: ----------- Added benchmarks. Added Paths: ----------- trunk/sandbox/tobias/tests/ trunk/sandbox/tobias/tests/functions.py trunk/sandbox/tobias/tests/parrotbench/ trunk/sandbox/tobias/tests/parrotbench/Makefile trunk/sandbox/tobias/tests/parrotbench/README.txt trunk/sandbox/tobias/tests/parrotbench/b.py trunk/sandbox/tobias/tests/parrotbench/b0.py trunk/sandbox/tobias/tests/parrotbench/b1.py trunk/sandbox/tobias/tests/parrotbench/b2.py trunk/sandbox/tobias/tests/parrotbench/b3.py trunk/sandbox/tobias/tests/parrotbench/b4.py trunk/sandbox/tobias/tests/parrotbench/b5.py trunk/sandbox/tobias/tests/parrotbench/b6.py trunk/sandbox/tobias/tests/parrotbench/t.py Added: trunk/sandbox/tobias/tests/functions.py =================================================================== --- trunk/sandbox/tobias/tests/functions.py (rev 0) +++ trunk/sandbox/tobias/tests/functions.py 2009-04-01 01:45:35 UTC (rev 6145) @@ -0,0 +1,23 @@ +def func(x): + z = x + +def bench(times): + for x in xrange(times): + func(x) + +def main(script, times='10000', warmups='20000', reps='3'): + from time import time + warmups = int(warmups); reps = int(reps); times = int(times) + for i in xrange(warmups): + bench(times) + res = [] + for i in xrange(reps): + t = time() + bench(times) + t = time() - t + res.append(t) + print min(res), max(res) + +if __name__ == '__main__': + import sys + main(*sys.argv) Property changes on: trunk/sandbox/tobias/tests/parrotbench ___________________________________________________________________ Added: svn:ignore + *.pyo *.pyc *.class out out? @out Added: trunk/sandbox/tobias/tests/parrotbench/Makefile =================================================================== --- trunk/sandbox/tobias/tests/parrotbench/Makefile (rev 0) +++ trunk/sandbox/tobias/tests/parrotbench/Makefile 2009-04-01 01:45:35 UTC (rev 6145) @@ -0,0 +1,81 @@ +PYTHON= echo SPECIFY PYTHON +DIFF= diff +ECHO= echo +TIME= time +CMP= cmp +SCP= scp +RM= rm + +FILES= README.txt Makefile b.py b[0-9].py t.py out out[0-9] +TARFILE=parrotbench.tgz +TARGET= python.org:~ftp/pub/python/parrotbench/parrotbench.tgz + +time: + $(TIME) $(PYTHON) b.py >@out + $(CMP) @out out + +cmp: + $(PYTHON) -O b.py >@out + $(CMP) @out out + +diff: + $(PYTHON) -O b.py >@out + $(DIFF) @out out + +dist: $(TARFILE) + +$(TARFILE): $(FILES) + tar czf $(TARFILE) $(FILES) + +upload: dist + $(SCP) $(TARFILE) $(TARGET) + +clean: + -$(RM) -f @* *~ *.pyc *.pyo $(TARFILE) + +times: + for i in 0 1 2 3 4 5 6; do \ + $(ECHO) b$$i.py; \ + $(TIME) $(PYTHON) b$$i.py >@out$$i; \ + $(CMP) @out$$i out$$i; \ + done + +cmps: + for i in 0 1 2 3 4 5 6; do \ + $(ECHO) b$$i.py; \ + $(PYTHON) b$$i.py >@out$$i; \ + $(CMP) @out$$i out$$i; \ + done + +diffs: + for i in 0 1 2 3 4 5 6; do \ + $(ECHO) b$$i.py; \ + $(PYTHON) b$$i.py >@out$$i; \ + $(DIFF) @out$$i out$$i; \ + done + +all: out out0 out1 out2 out3 out4 out5 out6 + +out: b.py b?.py + $(PYTHON) -O b.py >out + +out0: b0.py + $(PYTHON) b0.py >out0 + +out1: b1.py + $(PYTHON) b1.py >out1 + +out2: b2.py + $(PYTHON) b2.py >out2 + +out3: b3.py + $(PYTHON) b3.py >out3 + +out4: b4.py b0.py + $(PYTHON) b4.py >out4 + +out5: b5.py + $(PYTHON) b5.py >out5 + +out6: b6.py + $(PYTHON) b6.py >out6 Added: trunk/sandbox/tobias/tests/parrotbench/README.txt =================================================================== --- trunk/sandbox/tobias/tests/parrotbench/README.txt (rev 0) +++ trunk/sandbox/tobias/tests/parrotbench/README.txt 2009-04-01 01:45:35 UTC (rev 6145) @@ -0,0 +1,87 @@ +Parrot benchmark 1.0.4 +====================== + +[This is version 1.0.4, with a bugfix for the Mac OSX issue that Dan +reported, two further bugfixes for the dict ordering problem noted by +Samuele Pedroni, and an updated Makefile and t.py driver for Windows.] + +This is a benchmark to be run in front of a live audience at OSCON +2004 between Python and Parrot. The bytecode must be Python 2.3 +bytecode frozen in December 2003 (which is almost over as I write this +:-). + +For some more background, see the python-dev thread around + http://mail.python.org/pipermail/python-dev/2003-December/040977.html + +The benchmark here is intended to make Dan Sugalski's life difficult: +there are some standard benchmark thingies (simple random algorithms +using basic data types) but also a lot of play with odd corners of the +language definition, and Python's extremely dynamic object model: +funky descriptors, mutable classes, that sort of thing. The benchmark +is supposed to run with either Python 2.3 or Python 2.4. + +Brief description per file: + +Makefile -- Various ways of running the benchmark and sub-benchmarks. + +b.py -- The full benchmark output is defined as "python -O b.py". + +b0.py -- Lots of fun with a parser for a subset of Python (just + because this is a classic OO-heavy application). + +b1.py -- Explore recursion. Unbounded recursion is expected to raise + RuntimeError after about 1000 levels. (If Parrot supports much + more, this part will be slower; the point is to be able to + tweak the recursion limit.) + +b2.py -- Calculate PI using a generator. + +b3.py -- Sorting, and various ways of setting the comparison function + for list.sort(). + +b4.py -- Another test for the code from b0.py, this time with code + derived from Python 2.3's heapq.py. + +b5.py -- Test the standard library, including three standard Unicode + codecs (ASCII, Latin-1 and UTF-8), various descriptors, and + mutable classes. + +b6.py -- Check speed of iterating over several common iterators. + +Note that per agreement I'm not allowed to use any built-in extension +modules, not even __builtin__ or sys. This means there's no access to +sys.args (so no command line arguments), sys.stdout (but we have +"print >>file") or to sys.exc_info(). Dan could save some nanoseconds +by not supporting tracebacks. But that would be cheating. Also +cheating would be to do all the work at compile time (this is +theoretically possible since the program has no input). + +Per agreement the following builtins are out: open(), file(), input(), +raw_input(), compile(), eval(), execfile(), and the exec statement. +But I assume the print statement is okay (the program must communicate +its success or failure *somehow*). + +I'm being nice, and am voluntarily refraining from using __builtins__, +basestring, callable(), __import__(), reload(), dir(), globals(), +locals(), vars(), help(), apply(), buffer(), coerce(), or intern(). +I'm also not digging around in the func_code attribute of function +objects. + +On the use of __debug__: this is a built-in variable, set to True +normally and to False when Python is invoked with -O. I use this to +produce verbose output without -O but minimal output with it. For the +actual benchmark, Python should use -O, and Dan can simply set +__debug__ to False in the builtins if he prefers. + +On timing: there's a requirement that the benchmark runs for at least +30 seconds. It currently runs for nearly a minute on my home box, +which is a four-year-old 650 MHz Pentium box. If the contest hardware +is so fast that it runs under a minute, there's a number in b.py that +can be cranked up to increase the number of runs. (It takes 27 +seconds on my recent work desktop, and on my screaming IBM T40 laptop +it runs in 15 seconds, so I suspect that we should at least double the +number of runs from 2 to 4.) + +December 31, 2003, + +--Guido van Rossum (home page: http://www.python.org/~guido/) Added: trunk/sandbox/tobias/tests/parrotbench/b.py =================================================================== --- trunk/sandbox/tobias/tests/parrotbench/b.py (rev 0) +++ trunk/sandbox/tobias/tests/parrotbench/b.py 2009-04-01 01:45:35 UTC (rev 6145) @@ -0,0 +1,46 @@ +import b0 +import b1 +import b2 +import b3 +import b4 +import b5 +import b6 + +import sys +from time import time + +WARMUP = 0 +TIMES = 3 +NUMBER = 1 +ITERATIONS = 1 + +def run(module, iteration): + print >>sys.stderr, "-->", module.__name__ + res = [] + for i in range(TIMES): + t = time() + for i in range(NUMBER): + module.main() + t = time() - t + res.append(t/NUMBER) + return res + +if 'java' in sys.platform: + def run(module, iteration, run=run): + if not iteration: + for i in range(WARMUP): + module.main() + return run(module, iteration) + +def main(): + t = time() + for i in range(ITERATIONS): + print >>sys.stderr, "--> iteration", i + for module in (b0, b2, b3, b4, b5, b6): # b1 ommitted + mt = min(run(module, i)) + print >>sys.stderr, "best of 3:", mt + t = time() - t + print >>sys.stderr, "--> All done.", t + +if __name__ == '__main__': + main() Added: trunk/sandbox/tobias/tests/parrotbench/b0.py =================================================================== --- trunk/sandbox/tobias/tests/parrotbench/b0.py (rev 0) +++ trunk/sandbox/tobias/tests/parrotbench/b0.py 2009-04-01 01:45:35 UTC (rev 6145) @@ -0,0 +1,938 @@ +def check(a, b): + if not a == b: + raise AssertionError("%.30r != %.30r" % (a, b)) + +def proto___new__(cls, name): + if name in cls.name2num: + return cls.name2num[name] + cls.name2num[name] = obj = int.__new__(cls, cls.next) + cls.num2name[obj] = name + cls.next += 1 + return obj + +def proto___repr__(self): + return self.__class__.num2name[self] + +class MetaToken(type): + def __new__(metacls, name, bases, vars): + cls = type.__new__(metacls, name, bases, vars) + cls.__new__ = staticmethod(proto___new__) + cls.__repr__ = cls.__str__ = proto___repr__ + cls.next = 0 + cls.name2num = {} + cls.num2name = {} + return cls + +Token = MetaToken('Token', (int,), {}) + +EOF = Token('EOF') +INDENT = Token('INDENT') +DEDENT = Token('DEDENT') +NEWLINE = Token('NEWLINE') +NAME = Token('NAME') +NUMBER = Token('NUMBER') +STRING = Token('STRING') +OPERATOR = Token('OPERATOR') + +class Scanner(object): + + # A vaguely Pythonic tokenizer + + def __init__(self, getc): + self.getc = getc + self.indents = [0] + + def tokenize(self, + eolchars = ('', '\r', '\n'), + quotes = ('"', '\''), + hspaces = (' ', '\t'), + longops = dict.fromkeys( + ('<<', '>>', '<=', '>=', '==', '!=', '//', '**'))): + # A generator yielding successive tokens to the parser + # Each token is a (tokentype, value) pair + getc = self.getc + nextc = getc() + while True: + col = 0 + while nextc.isspace(): + if nextc == '\t': + col = ((col//8) + 1)*8 + elif nextc == ' ': + col += 1 + else: + col = 0 # \f, \v, \r, \n all reset the column + nextc = getc() + if nextc == '#': + while nextc not in eolchars: + nextc = getc() + continue + if col != self.indents[-1]: + while col < self.indents[-1]: + yield DEDENT, '' + del self.indents[-1] + # This will yield DEDENT + INDENT for inconsistent dedent + if col > self.indents[-1]: + yield INDENT, '' + self.indents.append(col) + while nextc not in eolchars: + if nextc.isalpha() or nextc == '_': + name = '' + while nextc.isalnum() or nextc == '_': + name += nextc + nextc = getc() + yield NAME, name + elif nextc.isdigit(): + number = '' + while nextc.isdigit(): + number += nextc + nextc = getc() + yield NUMBER, number + elif nextc in quotes: + quote = nextc + s = nextc + nextc = getc() + while nextc != quote: + if nextc in eolchars: + if not nextc: + raise SyntaxError("EOF in string") + raise SyntaxError("unescaped %r in string" % nextc) + s += nextc + if nextc == '\\': + nextc = getc() + s += nextc + nextc = getc() + s += nextc + nextc = getc() + yield STRING, s + elif nextc == '#': + while nextc not in eolchars: + nextc = getc() + elif nextc in hspaces: + nextc = getc() + else: + c1 = nextc + nextc = getc() + if c1+nextc in longops: + c2 = nextc + nextc = getc() + yield OPERATOR, c1+c2 + else: + yield OPERATOR, c1 + yield NEWLINE, '' + nextc = getc() + if not nextc: + while self.indents[-1]: + yield DEDENT, '' + del self.indents[-1] + break + yield EOF, '' + +class Link(object): + __slots__ = ['value', 'next'] + def __init__(self): + self.value = None + self.next = None + +class Clone(object): + __slots__ = ['link', 'itnext'] + def __init__(self, it, link=None): + if isinstance(it, Clone): + self.itnext = it.itnext + self.link = it.link + else: + self.itnext = it.next + self.link = Link() + def __iter__(self): + return self + def next(self): + next = self.link.next + if next is None: + self.link.value = value = self.itnext() + self.link.next = next = Link() + else: + value = self.link.value + self.link = next + return value + +def getcFromString(s): + for c in s: + yield c + while True: + yield '' + +sample = ''' +def pi(): + # Compute digits of Pi. Algorithm due to LGLT Meertens. + k, a, b, a1, b1 = 2, 4, 1, 12, 4 + while 1: + p, q, k = k*k, 2*k+1, k+1 + a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 + d, d1 = a//b, a1//b1 + while d == d1: + yield d + a, a1 = 10*(a%b), 10*(a1%b1) + d, d1 = a//b, a1//b1 +def strhash(s): + # Python 2.x string hash algorithm + if s == '': + return 0 + x = ord(s[0])<<7 + for c in s: + x = ((1000003*x) ^ ord(c)) & 4294967295 # 0xffffffff + return x^len(s) +''' + +operators = { + '<': 1, + '<=': 1, + '==': 1, + '!=': 1, + '>': 1, + '>=': 1, + '|': 2, + '^': 3, + '&': 4, + '<<': 5, + '>>': 5, + '+': 6, + '-': 6, + '*': 7, + '/': 7, + '//': 7, + '%': 7, + '**': 8, +} + +dispatch = { + '<': lambda x, y: x < y, + '<=': lambda x, y: x <= y, + '==': lambda x, y: x == y, + '!=': lambda x, y: x != y, + '>': lambda x, y: x > y, + '>=': lambda x, y: x >= y, + + '|': lambda x, y: x | y, + '^': lambda x, y: x ^ y, + '&': lambda x, y: x & y, + '<<': lambda x, y: x << y, + '>>': lambda x, y: x >> y, + + '+': lambda x, y: x + y, + '-': lambda x, y: x - y, + + '*': lambda x, y: x * y, + '/': lambda x, y: x / y, + '%': lambda x, y: x % y, + '//': lambda x, y: x // y, + + '**': lambda x, y: x ** y, + } + +class DoReturn(Exception): + def __init__(self, value=None): + self.value = value + +class DoBreak(Exception): + pass + +def eval(body, globals, locals): + for stmt in body: + stmt.eval(globals, locals) + +def geneval(body, globals, locals): + for stmt in body: + for value in stmt.geneval(globals, locals): + yield value + +def isgenerator(body): + for stmt in body: + if stmt.isgenerator(): + return True + return False + +class Dict(dict): + + def __repr__(self): + keys = self.keys() + keys.sort() + L = [] + for key in keys: + L.append(repr(key) + ": " + repr(self[key])) + return "{" + ", ".join(L) + "}" + +class Function(object): + makeLocals = Dict + def __init__(self, name, args, body, globals): + self.name = name + self.args = args + self.body = body + self.globals = globals + def __call__(self, *args): + check(len(args), len(self.args)) + locals = self.makeLocals(zip(self.args, args)) + try: + eval(self.body, self.globals, locals) + except DoReturn, exc: + return exc.value + +class Generator(Function): + def __call__(self, *args): + check(len(args), len(self.args)) + locals = self.makeLocals(zip(self.args, args)) + try: + for value in geneval(self.body, self.globals, locals): + yield value + except DoReturn, exc: + if exc.value is not None: + raise RuntimeError("'return' with argument in generator") + return + +class Node(object): + def isgenerator(self): + return False + def geneval(self, globals, locals): + self.eval(globals, locals) + if False: + yield None +class Define(Node): + def __init__(self, name, args, body): + self.name = name + self.args = args + self.body = body + def __repr__(self): + return "%s(%r, %r, ...)" % (self.__class__.__name__, + self.name, self.args) + def eval(self, globals, locals): + if isgenerator(self.body): + obj = Generator(self.name, self.args, self.body, globals) + else: + obj = Function(self.name, self.args, self.body, globals) + globals[self.name] = obj +class For(Node): + def __init__(self, var, seq, body): + self.var = var + self.seq = seq + self.body = body + def __repr__(self): + return "%s(%r, %r, ...)" % (self.__class__.__name__, + self.var, self.seq) + def eval(self, globals, locals): + for value in self.seq.eval(globals, locals): + self.var.assign(value, globals, locals) + try: + eval(self.body, globals, locals) + except DoBreak: + break + def geneval(self, globals, locals): + for value in self.seq.eval(globals, locals): + self.var.assign(value, globals, locals) + try: + for v in geneval(self.body, globals, locals): + yield v + except DoBreak: + break +class While(Node): + def __init__(self, test, body): + self.test = test + self.body = body + def __repr__(self): + return "%s(%r, ...)" % (self.__class__.__name__, self.test) + def isgenerator(self): + return isgenerator(self.body) + def eval(self, globals, locals): + while self.test.eval(globals, locals): + try: + eval(self.body, globals, locals) + except DoBreak: + break + def geneval(self, globals, locals): + while self.test.eval(globals, locals): + try: + for value in geneval(self.body, globals, locals): + yield value + except DoBreak: + break +class If(Node): + def __init__(self, test, body, elsebody=None): + self.test = test + self.body = body + self.elsebody = elsebody + def __repr__(self): + return "%s(%r, ...)" % (self.__class__.__name__, self.test) + def isgenerator(self): + return isgenerator(self.body) or (self.elsebody is not None and + isgenerator(self.elsebody)) + def eval(self, globals, locals): + if self.test.eval(globals, locals): + eval(self.body, globals, locals) + elif self.elsebody is not None: + eval(self.elsebody, globals, locals) + def geneval(self, globals, locals): + if self.test.eval(globals, locals): + for value in geneval(self.body, globals, locals): + yield value + elif self.elsebody is not None: + for value in geneval(self.elsebody, globals, locals): + yield value +class Return(Node): + def __init__(self, expr=None): + self.expr = expr + def __repr__(self): + return "%s(%r)" % (self.__class__.__name__, self.expr) + def eval(self, globals, locals): + if self.expr is None: + value = None + else: + value = self.expr.eval(globals, locals) + raise DoReturn(value) +class Yield(Node): + def __init__(self, expr): + self.expr = expr + def __repr__(self): + return "%s(%r)" % (self.__class__.__name__, self.expr) + def isgenerator(self): + return True + def geneval(self, globals, locals): + if self.expr is None: + value = None + else: + value = self.expr.eval(globals, locals) + yield value +class Break(Node): + def __repr__(self): + return "%s()" % (self.__class__.__name__,) + def eval(self, globals, locals): + raise DoBreak() +class Print(Node): + def __init__(self, exprs): + if not isinstance(exprs, list): + exprs = [exprs] + self.exprs = exprs + def eval(self, globals, locals): + for e in self.exprs: + print e.eval(globals, locals), + print +class Assign(Node): + def __init__(self, lhs, expr): + self.lhs = lhs + self.expr = expr + def __repr__(self): + return "%s(%r, %r)" % (self.__class__.__name__, self.lhs, self.expr) + def eval(self, globals, locals): + value = self.expr.eval(globals, locals) + for v in self.lhs: + v.assign(value, globals, locals) +class Exprs(Node): + def __init__(self, exprs): + self.exprs = exprs + def __repr__(self): + return "%s(%r)" % (self.__class__.__name__, self.exprs) + def eval(self, globals, locals): + return tuple([e.eval(globals, locals) for e in self.exprs]) + def assign(self, value, globals, locals): + if len(self.exprs) != len(value): + raise TypeError("multi-assign length mismatch") + for e, v in zip(self.exprs, value): + e.assign(v, globals, locals) +class Binop(Node): + def __init__(self, left, op, right): + self.left = left + self.op = op + self.right = right + self.opeval = dispatch[self.op] + def __repr__(self): + return "%s(%r, %r, %r)" % (self.__class__.__name__, + self.left, self.op, self.right) + def eval(self, globals, locals): + return self.opeval(self.left.eval(globals, locals), + self.right.eval(globals, locals)) +class Attribute(Node): + def __init__(self, expr, name): + self.expr = expr + self.name = name + def __repr__(self): + return "%s(%r, %r)" % (self.__class__.__name__, self.expr, self.name) + def eval(self, globals, locals): + v = self.expr.eval(globals, locals) + return getattr(v, self.name) +class Index(Node): + def __init__(self, expr, index): + self.expr = expr + self.index = index + def __repr__(self): + return "%s(%r, %r)" % (self.__class__.__name__, self.expr, self.index) + def eval(self, globals, locals): + v = self.expr.eval(globals, locals) + return v[self.index.eval(globals, locals)] + def assign(self, value, globals, locals): + v = self.expr.eval(globals, locals) + v[self.index.eval(globals, locals)] = value +class Call(Node): + def __init__(self, expr, args): + if not isinstance(args, list): + args = [args] + self.expr = expr + self.args = args + def __repr__(self): + return "%s(%r, %r)" % (self.__class__.__name__, self.expr, self.args) + def eval(self, globals, locals): + f = self.expr.eval(globals, locals) + args = [a.eval(globals, locals) for a in self.args] + return f(*args) +class Literal(Node): + def __init__(self, literal): + self.literal = literal + self.value = self.evalit() + def eval(self, globals, locals): + return self.value + def __repr__(self): + return "%s(%r)" % (self.__class__.__name__, self.literal) +simple_escapes = {"a": "\a", + "b": "\b", + "f": "\f", + "n": "\n", + "r": "\r", + "t": "\t", + "v": "\v", + "'": "'", + '"': '"', + "\\": "\\"} +class String(Literal): + def evalit(self, octals='01234567'): + s = self.literal[1:-1] + if '\\' not in s: + return s + L = [] + it = iter(range(len(s))) + for i in it: + c = s[i] + if c != '\\': + L.append(c) + else: + i = it.next() + c = s[i] + if c == 'x': + if i+2 >= len(s): + raise ValueError("incomplete \\x escape in string") + d1 = s[it.next()] + d2 = s[it.next()] + L.append(chr(int(d1+d2, 16))) + elif c in octals: + if i+1 < len(s) and s[i+1] in octals: + c += s[it.next()] + if i+2 < len(s) and s[i+2] in octals: + c += s[it.next()] + L.append(chr(int(c, 8))) + else: + L.append(simple_escapes.get(c, '\\' + c)) + return "".join(L) +class Number(Literal): + def evalit(self): + return int(self.literal) +class Name(Node): + def __init__(self, name): + self.name = name + def __repr__(self): + return "Name(%r)" % self.name + def eval(self, globals, locals): + if self.name in locals: + return locals[self.name] + if self.name in globals: + return globals[self.name] + if self.name == 'ord': + return ord + if self.name == 'len': + return len + raise NameError(self.name) + def assign(self, value, globals, locals): + locals[self.name] = value + +class Parser(object): + def __init__(self, scanner): + self.scanner = scanner + self.nexttoken() + def nexttoken(self): + self.token, self.value = rv = self.scanner.next() + ##print rv + return rv + def expect(self, token, value=None): + if self.token != token: + raise SyntaxError + if value is not None and self.value != value: + raise SyntaxError + value = self.value + self.nexttoken() + return value + def parse(self): + stmts = [] + while self.token != EOF: + stmts.append(self.parse_stmt()) + return stmts + def parse_stmt(self, + keywords=('def', 'for', 'while', 'if', + 'print', 'return', 'yield', 'break')): + if self.value in keywords: + return getattr(self, 'parse_' + self.value)() + else: + return self.parse_simple() + def parse_def(self): + self.expect(NAME, 'def') + name = self.expect(NAME) + self.expect(OPERATOR, '(') + args = [] + if self.value != ')': + args.append(self.expect(NAME)) + while self.value == ',': + self.nexttoken() + args.append(self.expect(NAME)) + self.expect(OPERATOR, ')') + self.expect(OPERATOR, ':') + self.expect(NEWLINE) + body = self.parse_body() + return Define(name, args, body) + def parse_for(self): + self.expect(NAME, 'for') + var = self.parse_expr() + self.expect(NAME, 'in') + seq = self.parse_expr() + self.expect(OPERATOR, ':') + self.expect(NEWLINE) + body = self.parse_body() + return For(var, seq, body) + def parse_while(self): + self.expect(NAME, 'while') + test = self.parse_expr() + self.expect(OPERATOR, ':') + self.expect(NEWLINE) + body = self.parse_body() + return While(test, body) + def parse_if(self): + self.expect(NAME, 'if') + test = self.parse_expr() + self.expect(OPERATOR, ':') + self.expect(NEWLINE) + body = self.parse_body() + if self.value != 'else': + elsebody = None + else: + self.expect(NAME, 'else') + self.expect(OPERATOR, ':') + self.expect(NEWLINE) + elsebody = self.parse_body() + return If(test, body, elsebody) + def parse_body(self): + self.expect(INDENT) + body = [self.parse_stmt()] + while self.token != DEDENT: + body.append(self.parse_stmt()) + self.expect(DEDENT) + return body + def parse_print(self): + self.expect(NAME, 'print') + exprs = self.parse_exprs() + self.expect(NEWLINE) + return Print(exprs) + def parse_return(self): + self.expect(NAME, 'return') + if self.token == NEWLINE: + e = None + else: + e = self.parse_exprs() + self.expect(NEWLINE) + return Return(e) + def parse_yield(self): + self.expect(NAME, 'yield') + e = self.parse_exprs() + self.expect(NEWLINE) + return Yield(e) + def parse_break(self): + self.expect(NAME, 'break') + self.expect(NEWLINE) + return Break() + def parse_simple(self): + e = self.parse_exprs() + if self.value == '=': + lhs = [] + while self.value == '=': + self.nexttoken() + lhs.append(e) + e = self.parse_exprs() + self.expect(NEWLINE) + return Assign(lhs, e) + else: + self.expect(NEWLINE) + return e + def parse_exprs(self): + e = self.parse_expr() + if self.value != ',': + return e + exprs = [e] + while self.value == ',': + self.nexttoken() + exprs.append(self.parse_expr()) + return Exprs(exprs) + def parse_expr(self, prio=0): + left = self.parse_term() + while self.value in operators and operators[self.value] > prio: + op = self.expect(OPERATOR) + right = self.parse_expr(operators[op]) + left = Binop(left, op, right) + return left + def parse_term(self): + t = self.parse_atom() + while self.value in ('.', '[', '('): + if self.value == '.': + self.nexttoken() + name = self.expect(NAME) + t = Attribute(t, name) + elif self.value == '[': + self.nexttoken() + index = self.parse_exprs() + self.expect(OPERATOR, ']') + t = Index(t, index) + elif self.value == '(': + self.nexttoken() + if self.value == ')': + args = [] + else: + args = self.parse_exprs() + if isinstance(args, Exprs): + args = args.exprs + self.expect(OPERATOR, ')') + t = Call(t, args) + else: + raise AssertionError("shouldn't get here") + return t + def parse_atom(self): + if self.value == '(': + self.nexttoken() + exprs = self.parse_exprs() + self.expect(OPERATOR, ')') + return exprs + if self.token is STRING: + return String(self.expect(STRING)) + if self.token is NAME: + return Name(self.expect(NAME)) + if self.token is NUMBER: + return Number(self.expect(NUMBER)) + raise SyntaxError + +class List(list): + __setitem__ = list.__setitem__ + __getitem__ = list.__getitem__ + +class Str(str): + __getitem__ = str.__getitem__ + +class OutputFile(object): + def __init__(self): + self.data = [] + self.softspace = True + reset = __init__ + def write(self, s): + self.data.append(s) + def getvalue(self): + r = "".join(self.data) + self.data = List() + return r + +output = OutputFile() + +def cleanup(s): + s = str(s).replace('<__main__.', '<').replace('<b0.', '<') + i = s.find(' at 0x') + while i > 0: + j = s.find('>', i+6) + if j < 0: + break + digits = s[i+4:j] + try: + number = int(digits, 0) + except ValueError: + break + else: + s = s[:i+5] + s[j:] + i = s.find(' at 0x') + return s + +def write(s): + s = cleanup(s) + if __debug__: + print s, + print >>output, s, + +def writeln(s=''): + write(str(s) + '\n') + +def myhash(s, ord=ord): + if not s: + return 0 + x = ord(s[0])<<7 + for c in s: + x = ((1000003*x) ^ ord(c)) & 0xffffffffL + return x^len(s) + +def checkoutput(n=0): + outputtext = output.getvalue() + check(strhash(outputtext), n) + +strhash = myhash + +indent = "" + +def instrumentClass(cls): + cname = cls.__name__ + '.' + for name in cls.__dict__: + if name == '__dict__': + continue + descr = cls.__dict__[name] + if hasattr(descr, '__get__'): + setattr(cls, name, instrumentDescriptor(cname+name, descr)) + +def unInstrumentClass(cls): + for name in cls.__dict__: + descr = cls.__dict__[name] + if isinstance(descr, instrumentDescriptor): + setattr(cls, name, descr.obj) + +class instrumentDescriptor(object): + def __init__(self, name, obj): + self.name = name + self.obj = obj + def __get__(self, *args): + result = self.obj.__get__(*args) + if not hasattr(result, '__call__'): + return result + return instrumentCall(self.name, result) + +class instrumentCall(object): + def __init__(self, name, obj): + self.name = name + self.obj = obj + def __call__(self, *args): + global indent + oldindent = indent + try: + indent = indent + " " + argreprs = map(repr, args) + for i, s in enumerate(argreprs): + s = cleanup(s) + if len(s) >= 45: + s = s[:20] + "..." + s[-20:] + argreprs[i] = s + writeln(indent + "%s(%r)" % (self.name, ", ".join(argreprs))) + try: + result = self.obj(*args) + except Exception, exc: + writeln(indent + "raise %r" % (exc,)) + raise + else: + if result is None: + writeln(indent + "return") + else: + writeln(indent + "return %r" % (result,)) + return result + finally: + indent = oldindent + +def instrumentTree(base): + instrumentClass(base) + for cls in base.__subclasses__(): + instrumentTree(cls) + +def unInstrumentTree(base): + unInstrumentClass(base) + for cls in base.__subclasses__(): + unInstrumentTree(cls) + +def main(): + output.reset() + + s = Scanner(getcFromString(sample).next) + it = Clone(s.tokenize()) + it2 = Clone(it) + L = [] + for pair in it: + L.append(pair) + L2 = list(it2) + check(L, L2) + + scanner = Scanner(getcFromString(sample).next).tokenize() + parser = Parser(scanner) + instrumentClass(Parser) + root = parser.parse() + + checkoutput(1413352820) + + env = Dict() + eval(root, env, env) + g = env['pi']() + for i in range(1000): + write(g.next()) + writeln('') + strhash = env['strhash'] + + for x in '', 'x', 'abc', 'abc'*100: + check(strhash(x), myhash(x)) + + strhash = myhash + checkoutput(3960406533) + + it = Clone(getcFromString(unicode(sample, "utf8"))) + it2 = Clone(it) + scanner = Scanner(it.next).tokenize() + parser = Parser(scanner) + root = parser.parse() + checkoutput(3827423707)#checkoutput(1308798191) + env = Dict() + eval(root, env, env) + g = env['pi']() + for i in range(1000): + write(g.next()) + writeln() + checkoutput(3960406533) + + instrumentTree(Node) + scanner = Clone(Scanner(it2.next).tokenize()) + scanner2 = Clone(scanner) + parser = Parser(scanner) + root = parser.parse() + checkoutput(3257889492) + env = Dict() + eval(root, env, env) + g = env['pi']() + digits = [] + for i in range(10): + digits.append(g.next()) + checkoutput(2705414689)#checkoutput(3259608361) + print "".join(map(str, digits)) + + unInstrumentTree(Node) + unInstrumentClass(Parser) + parser = Parser(scanner2) + root = parser.parse() + checkoutput(0) + env = Dict() + eval(root, env, env) + g = env['pi']() + digits = [] + for i in range(10): + digits.append(g.next()) + print "".join(map(str, digits)) + out2 = output.getvalue() + checkoutput(0) + + class TrackingDict(Dict): + def __setitem__(self, *args): + writeln("%s = %.50r" % args) + super(TrackingDict, self).__setitem__(*args) + Function.makeLocals = TrackingDict + g = env['pi']() + digits = [] + for i in range(100): + digits.append(g.next()) + checkoutput(902386495) + Function.makeLocals = Dict + +if __name__ == '__main__': + main() Added: trunk/sandbox/tobias/tests/parrotbench/b1.py =================================================================== --- trunk/sandbox/tobias/tests/parrotbench/b1.py (rev 0) +++ trunk/sandbox/tobias/tests/parrotbench/b1.py 2009-04-01 01:45:35 UTC (rev 6145) @@ -0,0 +1,37 @@ +def depth0(n): + try: + n = depth0(n+1) + except RuntimeError: + pass + return n + +def depth1(n, pea): + p = (pea, pea) + for i in xrange(n): + p = (p, pea) + try: + n, p = depth1(n+1, p) + except RuntimeError: + pass + return n, p + +def main(): + print depth0(0) >= 996 + pea = [] + base, p = depth1(0, pea) + print base >= 996 + pea.append(p) + while p[1] is not pea: + q = p[1] + n = 0 + while p[1] is q: + n += 1 + p = p[0] + if n != base+1: + raise RuntimeError, (n, base) + base -= 1 + print base + del pea[:] + +if __name__ == '__main__': + main() Added: trunk/sandbox/tobias/tests/parrotbench/b2.py =================================================================== --- trunk/sandbox/tobias/tests/parrotbench/b2.py (rev 0) +++ trunk/sandbox/tobias/tests/parrotbench/b2.py 2009-04-01 01:45:35 UTC (rev 6145) @@ -0,0 +1,43 @@ +def izip(*args): + args = map(iter, args) + while 1: + yield tuple([x.next() for x in args]) + +class PI(object): + def __iter__(self): + k, a, b, a1, b1 = 2, 4, 1, 12, 4 + while 1: + p, q, k = k*k, 2*k+1, k+1 + a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 + d, d1 = a//b, a1//b1 + while d == d1: + yield d + a, a1 = 10*(a%b), 10*(a1%b1) + d, d1 = a//b, a1//b1 + self.a1 = a1 + +tests = { + 99: 44251238236192885942548145627920559612834490019477028496725657079267312460031559302172150714110203307954379217477379106929168768496503354540899921113305213841256909892518928098307564463751633347248940009920269109969147590732355948788056064000000000000000000000000000000000, + 199: 1000596230862142822590229503409372398669386421051058756167623955196210292140473223995201364067656314884093070923379776058593112593572415388874119773448702613069929696236969954099574382312021625484547051647005317079077091903572365445691946982207111619679684359784089545801152269560862321544414943514190096631259179363627029133476495865659666812167626608236901769581685802712761140555948794720353924341042650072696819415055421183957924869318180281662429407332762869255321912813711898750492786968744984544308467386273640507277517829133760299081875243110913120665600000000000000000000000000000000000000000000000000000000000000000, + 299: 21435887192948215614003242240833359745116667655295850182859413191163731683078952650094326080502769326477126925083216343548170734614172935170340269921309820711302999200539819947867212813551107194027554006207604344128185286047718105667902068109038526051946371288160859880626765253522805513232333491975220030085760604224065673379016506268781757490866758397031010384977255107445504115787686395015630645137203786798858795200871880590717053675063928230569710372699708910775901232998621866511805494494875255496291270721486641615650345940568291905806263698337995119757061129615716444504290546816572960918445558805410505143000167480199333531897643812998836381668261331434305825321676717544726859895857274900170645624087291170408290210800888136650695682668742663263729788760787553650802761860581841523193434651375248115751262481847514479478467508156570863734207165375573520453327647345580868727572348946580766720000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, + 399: 8561869806834798989612544773400323313179941907807794568262440743112858898989689026704576126118595731944427372856665962019724479801384062969795859298394962551328689077803363555807984316902252940902014889926277022833163566635584197843427728248130112186455323888931447608868707068434776186855353396855833436850229162071581300162579548898284489248532968742303181986647234058212952485789589428331561779973912890270787218670895308761530690791268509970600822462460658693835169935042766248145148420454545182598329186640466821688459819069501551463819641554408111110110151692239551586768176506251155525099233988638762885805917822379263713549352362861698409524070686169569736102177070749091831233867352657647277185192372387156966362270318951122024815096048593017226290871189781143762422618457018186519922454408157004798904710507709224018924427721086955924703838793251170380074666507887931281809304737450536142489860864008197549841329444837980614206463968734383477281485253049376604442937718053220015067951581390345559841730246517326234188422995410478560583662283465682728995404843025593838691776410644612449087517702830166590175727603809091974002341560317871295071902646575676785149353532452189474547463794343581915053692213809212940949327454179290314595392041251528682462248960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, + 499: 76766108631940210937325132198465864457610296920889901883030849944249491732767613231460026747961565950406551576277982908797232709115573397680840144587889878137072051513231549168224623486940739011824470282874235014299280185292476357855772342908560617765615433859648152443400651562464645577267133565969609608350684571285655853054712724572601634219899681603288076555568556603519768176952205317390973803424356164269999588467102540378584128532600037700811666341008358928602746642205050531572408717173194538376392544677893444983399212894400285344939556094505296780409965886324800278706769664438849417755796690865276144102933659458633433715362955199895852120250371111523601408509601075849463319256275384860431711268141908667883149791804139967338545358206127158990156425480764804297397170597657279674744907448120365194723760375846968550637839625396799787981542068069955660525855300927415620426941417314885401820985001913260101401230309399239801959598342546866307638278153091955749126275448041244876145703346573865766318100310570772620069178810413227974410262538853025115028173981758758325369986648321051017250246765567173447382346682177940131720445933725662183060319023268847648849199144024316405375647697684691770109145226746285626861260128121857903981514928439560981950894568063766637808949718925624322085933716705575498276564370619232206346293654148202964613950060056885972213718288213503135634713342418000998239413319648014225323725957085146390629354204147053598603318165064363587092287902579232811848133423379877761425679796787506376625832936596918827500201870173625427859893528696839243761272981017048564872611531028386533983068887010900245332623360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, + 599: 2120272365916624093549573503339645760249925590629691905298380620826238336680485250775748238851715242513568106491781607325637843266230182543159994052803483210198817868787245904539293723939615230218367927170630181008508608682473786334989642773309671087946382125393064054429291378005365307369932354974406782493586482693959468507929142578311374952191246685196652549840632791830721769718961140786765636611636126263231624375986806336404014991356931344468888703169171934706250411475009307785661110741777527324954571089817794240318090318731138065871311050896639596947512824176632981670282022349794742982306588866780679141100000979482012703431996529614153969006965379857532250140411692707925832547131496348527554204126276904033851312192294719407040113066259294928824359144110570802157647067643172691886034509485269315724734491380423529629749223874238867299576969461404272650055836211201773406419214625694511195241201118512536217548368603119794507877569790693417734860149658615068452866115479874379764219274786787905887717695084355702688921163181942859261931462396527992761425892799259213253073620895655262890187342553757398412577032172382168869416402722279336223791913538036339921582169629706204936615017408331600286347593291767969984872197163003714688529499720018226023559039421196525971154371211007274491079331581462202803270308044945895467086216358487714539723075423709132632711104176237158591348264918119231549610638101215271635751068862184966089290055162842592702917037089658541420657556777630476720227083286444062812384078931053717097690428021828828314330897267550018034334466896893522629282170940447351039396227633740743904716345874216287187030893375694818646093977919289909500326805873535353890952168548557367192114315242338374030375201461534835392764765715654233759268109399742689152068054720118040413609079726305828412608467329058007828176699982184798481881032984952414016677410029974950886156526807807461864142760141455419659333722571838033134676308170730229830331659493070917764742995587861083129433623003009634591950055674021412864000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, + 699: 54571787430958399400005671895793395810514965360222657069233155257869831245514703898329984842599345345797192550495348877752750716462799995262238897879189712362792599540276947290240369738995122870036473426596166137781512133732841079442335809215673962548136751501962395101508082458022910749004870763777751025686143054266560789699467897488208314352497922931109255090615845989365253963697070552088326927571730238674587343725408556548847027815257453311184273200959063948470485405418687785822617652671609706936044865165112267634536255942342137737568633616435112070199187087675353099732490445262584463118808715533880843287282323502172455874549895164201021082781039664171931972950867328706112021059604060340338606871763348783573247509755207096610318069014034226371127241365822041636184401808035853347524245498756203483212762819194058857286022123510755206330238728338540936417830717262921800876426685863489447721974523840880601732138137563579815785444094205972614263669956513740906383728059662729451143837852557411654864608820606495589950458165214874335528071914274226508583618548221498046257433189345079263951024381261213067438755400772554918420156611989161275819373340626340095277962552853128100524758416265525218190626769969209796740560920753972479878773975562043659464796071536492340776053077906431346958246988865607675041671683462291933241209943247185229400300531069434821908210393754215270727867860747889887039965048681895147820192799637449521165944356200714071125353390157596677223069290303004608406259263260481747075716421783084148765931010321931117509077808771925529544210503591442107960112359151446110353540208471607107935843590192610650273333834161753099980189676608843057569018657095864002224328579690446259626925339472680838762568611923981193711770106009098171810029820020455115170724929203588390317815053369572788421300357832205199443876759544538582639402241883694827090801385537555747373037489025563879252287165075989079784157761408131323383708336366882662138204724992104184118234360573248835518448645547172342375665655653335218281979099552819760633230580536381778069677840715358530867566196795457417775340310424672192141977398974880862555283206621628790868960591215870136675469162920111812154003932444777532696287441691534774646863311895804406055064912499462089287403059782748799895590902455779428144219297715674077436643273687702239680646741926247202392605642085420467071089682849156330161168666278561180452156752478501391564800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, + 799: 1165019969951028145448474870606694745628445847100063691175045426809524271280385211025149309439736889668431363205043295468478227885516089826430304252028412665878074268391689531376676369814346541259212014204219732753532556283167763492813491981617042686520428375483043823229347180225027527767892288494222400268347648277077085092324780438909293027666621101974271603717458184633691745699246613625445708958093814173789616468299755424767037016330877693069425266688538600904598289113523091543776886739998104937757229618512461155015780709364046160704463608630709906484636013448672656426886594747044346764985843639265457373603772739772415706169602575546300922342271055004256781082363315561913547648640954959000371679492600850323235849380042831378495135583566599574416729516620087245906062795758387578224336805373895492794645806096068657974185136831114580747646909717985162654700150389838526549868770885629372149350446773860669388038471776557526515910033467628431871878316408982723876203877207112913665539371348724351835198296871265983857890498623536324848877236019869092878781427110113542625110041789002286754615039920319343770043455657828924442170211652589212117516714709894518726603532996156030790024814913146519305169722564850597797774298352669973544466122022123500758687471133096300448171087716127901248915474363042779227724255413335477296839171260050411230913787907606725169016351209025747882086625397286625248376528998919634710302520393941530723973487259019187136668425367426482695231240294671376146585312211926447150542843171266291876037378067256463777431998792250381914496818845072319002851834894280540179694233589184751221721345515353061996569633890293841751623667699605067183984407638732497881628999347219982736106675680165842644133894916782230987223224828685930858657631697327168501437432678530579280064943872275218623486567776580213001821563007802859121520206862366831214550454660201924592069971928484116327345227633650931220240412989380696156101840018564700065411677388328804161110162279193672651278988425644004188569635636717470803677943610275223854671409519817008772946235477341217799495629951132446716193818794636841421507151304976152511616538200203214016457449981017869162192339882870379247422061597402496664647115346984746108902369843975335083490551753570803795438395111351577474760022446140821780548147639308232794984562286077490121188360571079033300272391145791202144846667875284539709679647945779713567130240017333648976286204155043105228295725874012316502327195124092416348347162737242449541649547547864777887315161229040122603297586496999009079092644539172087825680666618082263897443172558909377634579572489890372823889386192559147381373832288039653312458442917119615324859008094386594830981911977813106096806546361863080294950465184145762955879704231094550954751577536624215411479046060449038350499002129406780206980907086223769600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, + 899: 1961047400783793689152743738482061418112144594775859100963826903299941791245038595034363753615746408049289952725779309407444199325053710536522401903643581802543713504158806047235695705896380364921365885372696677158825553172792575130365677811577035805389273355225725863414284665498055318575649394451227797767110728923709058788425788790167032831982217805891947591307310391793051324726126078967699521915868839204118521519682024094610098117626863292184721906092521438801341497303557767071828077146885364536554032450624100316867547877010778603956083487035270791818649067384276377414249363983383717773036457804718062695046059095787213719308297709919175747285036636352990899483938970896812239613605956608649083554411609657838220544027128950682327843798882711829991989817881303883990647876969994768271897974773455464646523348820392471256024577102382204328939384060235197563409904986708133897802121211859685551906620747824874847127776411443039694389051592145124635490844378130255642752765693890407120283111284316765000645749180288822505352501861257195960128525960418404774436619529817773459198268065709767064598308082608109337158602927125644880036055446842995394476366770872364117175239884406760485305848864493739499504392963295387516098554438251252486287315978444632100288391159069513665622892184147377430660017269064216314044538754986908504965776567592061950572488346266774840439392992871099154439658791611017807192708601473794082677034875991711712839230126426791071352984543648012937947037753575375040046764495862676093683555226439651695465214815214564045671683209573744703248122302073524235222782011551736047484049940566608761314884952385623657426286984431299387264223494331247251695035920997630045288051985796581735253031855095734994702323372767680434320372371358208514386161807824094211406017077057681618563506824462507672499213262962050653636150604636813302357401076353456780306366770399402263353459513732101609057936629596760862766436204974584026785745826067150601651416509653311312257323521470962454567693169469818165574943846754385013710385609445073226065759614555740278029180864101039640157003847772681461933766608520730602890319871123179941870008811420475967031993019721292183133758093949406939652398599519672662411049142220315039805474111098855767170048770783560759174013367296946638271656238787420981851702619053744806332012493178141602213898668388712998512756036771357385206948329239298807516694953814693720048229647293048056331265195037121054022115441868442670280473506498551412297880384312473713380564764159899942048060356745863908010902230964075673990385182437331505988923117412916700150241837983775128046411352228138119876809545584444570443347872856695813698044037133648970190072128464354669077148179236958137004869599834164764747494805309536229934978506910688264436888356383974787838537387187841566823557909442831563769727985839249267304457033791105118767948473474042809317178565809335268316324420040570235176099114072999727457879465811886218940986224633055296998229833996940360896329868864364653862830780554332074293100857235815847819975826812991652016737242925678140172314816371649578265526072666356756752517107018796020915298198762366163369556351250086487862926783601433251979292229580324497550784524234395521051827588464289592550437275513651200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, + 999: 5142120423742675471974126287955809574535357068046529599000560728039399275930931304341705443290300229914422726794668177537968264648144118498487805119226260378528650131991088676902836811857270541513296947526699705880730381294593006898814262085704336473825201541006210955753704810537413120555128907013106764170210420629126960215958541001171658832595950907229541457834088209412944936905053972218397142776849344658277652614892680821674419697222923130014645284479895717056274392491034125201955158674450551217874664620940928171427683754069233736509184926590369183895070592006924781272099864100239363770546451883318349964152398948931966679860602627409906331644763679137682497780242630009822921710929339761344862731457826420617686381968911400073392366124777065987424836126250033579686085082101266467177145863298853308178221540976580228331239763953108737488691493181833643401836558191778626398618442140468218270066858025640661491000558898610528392279711579575345703200785278416348411772675840280709593777527474095922179716471353719960201704105588347086479022160191444830756096400533705391196695396662879167956803453360810349846148441318082659273788717329596246494808484632922731776348571012795857047452180584628986442772443700080676049673819149856254912408951932826185765196259801406717427502413558108931158666261380067455659044728430258922799402098021392057660641081228877422498521314624574441740894508178111385410004911439667702696237159978509689180822381441616419582068514764153876222307554547594732358511527444499897458759372982433792122654903561638842618444515784825627448071849634297643169362409668516222758076203698145001415117323006038425703965914796426427671784982873817168224589258130683058917988733709001146483964613456875437013984505541825689086094075705760437211402385873368677829365976836468858431398089165749482066656712849497341765168981001121722892025503801609269782750165912686412855279381595779876529427944264414478121201023565907692108302876619530698352008605101070206468704706785269261493986427523865931377207048551250785411318329249855779517786463477651967611696076738366693440412084695489984239864456563532165840963582864286049480561230753012702462130127137450345350359359867882547235683710571018784016493910038168014978153353097170254842715035335189179028979337119830781198392063337314155334478636683363262982739406004002266047843272582071916617807353681712781581451680468476890933136639338084566580809048080468359779806934561186367642359343545836729611491944504786419220499142487390760086756065236043333233346060550395020264308177305185193132970079897858502314955851005175681382393415134546851874491465839660269856799739588390788616285622308116117137884072465953587955513347680498150094614231017861871571733053758969929765508087588060032519546969078084262395141708005237055101766716471322442729268007817300289076611523200827716220759305897838985100568942910630581392931521412710812611627780351475138825434194100790648741408739165327268324724814490022832365413572546951682824848375315512140247418809107217287405055515586541323054413736009057491568285635589733988075995955259789133788061014117612372700229521937709121536568616897024085971931708565098241621955888612739889590429896488315826527248677547766604473044643680531889217189519948956302468329241617445146397986279285610720245607340812533508949433972935867033257871847610121142227746914970178327007585588874258396444641885137938545... [truncated message content] |
From: <th...@us...> - 2009-04-01 02:22:50
|
Revision: 6144 http://jython.svn.sourceforge.net/jython/?rev=6144&view=rev Author: thobes Date: 2009-04-01 01:37:23 +0000 (Wed, 01 Apr 2009) Log Message: ----------- Moved the SSA compiler to Kenai. Modified Paths: -------------- trunk/sandbox/tobias/.classpath trunk/sandbox/tobias/build.xml Removed Paths: ------------- trunk/sandbox/tobias/compiler/src/org/thobe/ Property Changed: ---------------- trunk/sandbox/tobias/ Property changes on: trunk/sandbox/tobias ___________________________________________________________________ Modified: svn:externals - jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython frame https://kenai.com/svn/jvm-frame-introspect~svn/frame + jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython frame https://kenai.com/svn/jvm-frame-introspect~svn/frame ssa https://kenai.com/svn/ssa-compiler~svn-temprep/trunk Modified: trunk/sandbox/tobias/.classpath =================================================================== --- trunk/sandbox/tobias/.classpath 2009-04-01 00:07:49 UTC (rev 6143) +++ trunk/sandbox/tobias/.classpath 2009-04-01 01:37:23 UTC (rev 6144) @@ -1,8 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry excluding="com/ziclix/python/sql/|com/ziclix/python/sql/connect/|com/ziclix/python/sql/handler/|com/ziclix/python/sql/pipe/|com/ziclix/python/sql/pipe/csv/|com/ziclix/python/sql/pipe/db/|com/ziclix/python/sql/procedure/|com/ziclix/python/sql/resource/|com/ziclix/python/sql/util/" kind="src" path="jython/src"/> + <classpathentry kind="src" path="ssa/src"/> <classpathentry excluding="org/python/compiler/advanced/ast/" kind="src" path="compiler/src"/> - <classpathentry kind="src" path="util/src"/> + <classpathentry excluding="org/python/code/CodeTable.java|org/python/code/SpecializedCode.java|org/python/frame/JavaFrameAccessor.java" kind="src" path="util/src"/> <classpathentry kind="src" path="bytecode/src"/> <classpathentry kind="src" path="agent/src"/> <classpathentry kind="src" path="frame/src"/> Modified: trunk/sandbox/tobias/build.xml =================================================================== --- trunk/sandbox/tobias/build.xml 2009-04-01 00:07:49 UTC (rev 6143) +++ trunk/sandbox/tobias/build.xml 2009-04-01 01:37:23 UTC (rev 6144) @@ -56,7 +56,7 @@ <target name="setup target"> <mkdir dir="${target.dir}"/> </target> - <target name="clean" depends="clean jython,clean compiler,clean agent,clean bytecode,clean util,clean frame"> + <target name="clean" depends="clean jython,clean compiler,clean ssa,clean agent,clean bytecode,clean util,clean frame"> <delete dir="${target.dir}"/> </target> @@ -79,10 +79,23 @@ </ant> </target> - <target name="compiler" depends="setup target,jython,agent,util,bytecode"> + <target name="ssa"> + <echo>Building the SSA subproject</echo> + <ant dir="${basedir}/ssa" inheritAll="false"> + <property name="target.dir" location="${target.dir}"/> + </ant> + </target> + <target name="clean ssa"> + <ant dir="${basedir}/ssa" inheritAll="false" target="clean"> + <property name="target.dir" location="${target.dir}"/> + </ant> + </target> + + <target name="compiler" depends="setup target,jython,ssa,agent,util,bytecode"> <echo>Building the compiler subproject</echo> <ant dir="${basedir}/compiler" inheritAll="false"> <property name="jython.jar" location="${target.dir}/dist/jython-dev.jar"/> + <property name="ssa.jar" location="${target.dir}/ssa.jar"/> <property name="agent.jar" location="${target.dir}/agent-user.jar"/> <property name="antlr.jar" location="${target.dir}/dist/javalib/antlr-runtime-3.1.2.jar"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-04-01 04:28:24
|
Revision: 6146 http://jython.svn.sourceforge.net/jython/?rev=6146&view=rev Author: thobes Date: 2009-04-01 04:28:21 +0000 (Wed, 01 Apr 2009) Log Message: ----------- Moved the code for exercising the SSA graph to the Kenai project. Modified Paths: -------------- trunk/sandbox/tobias/.classpath Removed Paths: ------------- trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/output/BuildGraph.java Modified: trunk/sandbox/tobias/.classpath =================================================================== --- trunk/sandbox/tobias/.classpath 2009-04-01 01:45:35 UTC (rev 6145) +++ trunk/sandbox/tobias/.classpath 2009-04-01 04:28:21 UTC (rev 6146) @@ -11,6 +11,7 @@ <classpathentry kind="src" path="jython/build/gensrc"/> <classpathentry kind="src" path="jython/tests/java"/> <classpathentry kind="src" path="compiler/test"/> + <classpathentry kind="src" path="ssa/test"/> <classpathentry kind="lib" path="jython/Demo/jreload/example.jar"/> <classpathentry kind="lib" path="jython/extlibs/antlr-2.7.7.jar"/> <classpathentry kind="lib" path="jython/extlibs/asm-3.1.jar"/> Deleted: trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/output/BuildGraph.java =================================================================== --- trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/output/BuildGraph.java 2009-04-01 01:45:35 UTC (rev 6145) +++ trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/output/BuildGraph.java 2009-04-01 04:28:21 UTC (rev 6146) @@ -1,34 +0,0 @@ -package org.python.compiler.sea.output; - -import org.python.compiler.sea.PythonOperation; -import org.thobe.compiler.sea.GraphBuilder; -import org.thobe.compiler.sea.GraphVisitor; -import org.thobe.compiler.sea.NamespacePopulator; -import org.thobe.compiler.sea.Node; -import org.thobe.compiler.sea.ValueNode; -import org.thobe.compiler.sea.VariableFactory; - -public final class BuildGraph extends GraphBuilder { - protected BuildGraph(NamespacePopulator populator) { - super(populator); - } - - public static void main(String[] args) { - BuildGraph builder = new BuildGraph(new NamespacePopulator() { - public void populate(VariableFactory factory) { - factory.createLocalVariable("x"); - factory.createLocalVariable("y"); - } - }); - ValueNode load_x = builder.loadVariable(builder.variable("x")); - ValueNode load_y = builder.loadVariable(builder.variable("y")); - ValueNode add = builder.schedule(builder.invoke( - PythonOperation.BINARY_ADD, load_x.result(), load_y.result())); - builder.schedule(builder.returnValue(add.result())); - builder.build().serialize(new GraphVisitor() { - public void node(Node node) { - System.out.println(node); - } - }); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-08-23 22:46:59
|
Revision: 6714 http://jython.svn.sourceforge.net/jython/?rev=6714&view=rev Author: thobes Date: 2009-08-23 22:46:49 +0000 (Sun, 23 Aug 2009) Log Message: ----------- Added a bootstrap script that sets up Jython with basic libraries. Also added the beginnings of a benchmarking library with more flexibility than timeit. Modified Paths: -------------- trunk/sandbox/tobias/.classpath trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch trunk/sandbox/tobias/build.xml trunk/sandbox/tobias/tests/parrotbench/b.py Added Paths: ----------- trunk/sandbox/tobias/bootstrap trunk/sandbox/tobias/lib/ trunk/sandbox/tobias/lib/benchmark.py trunk/sandbox/tobias/lib/benchmark.sh Modified: trunk/sandbox/tobias/.classpath =================================================================== --- trunk/sandbox/tobias/.classpath 2009-08-23 19:47:55 UTC (rev 6713) +++ trunk/sandbox/tobias/.classpath 2009-08-23 22:46:49 UTC (rev 6714) @@ -20,7 +20,6 @@ <classpathentry kind="lib" path="jython/extlibs/constantine-0.4.jar"/> <classpathentry kind="lib" path="jython/extlibs/cpptasks/cpptasks.jar"/> <classpathentry kind="lib" path="jython/extlibs/jarjar-0.7.jar"/> - <classpathentry kind="lib" path="jython/extlibs/jline-0.9.94.jar"/> <classpathentry kind="lib" path="jython/extlibs/jna-posix.jar"/> <classpathentry kind="lib" path="jython/extlibs/jna.jar"/> <classpathentry kind="lib" path="jython/extlibs/junit-3.8.2.jar"/> @@ -41,7 +40,9 @@ <classpathentry kind="lib" path="jython/Lib/test/syspath_import.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5.0 (Mac OS X default)"/> <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> - <classpathentry kind="lib" path="jython/extlibs/antlr-3.1.2.jar"/> - <classpathentry kind="lib" path="jython/extlibs/antlr-runtime-3.1.2.jar"/> + <classpathentry kind="lib" path="jython/extlibs/antlr-3.1.3.jar"/> + <classpathentry kind="lib" path="jython/extlibs/antlr-runtime-3.1.3.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jline-0.9.95-SNAPSHOT.jar"/> + <classpathentry kind="lib" path="jython/extlibs/livetribe-jsr223-2.0.5.jar"/> <classpathentry kind="output" path="target/build"/> </classpath> Modified: trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch =================================================================== --- trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-08-23 19:47:55 UTC (rev 6713) +++ trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-08-23 22:46:49 UTC (rev 6714) @@ -1,4 +1,5 @@ -<?xml version="1.0" encoding="UTF-8"?><launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> +<?xml version="1.0" encoding="UTF-8"?> +<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> <stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="brand-version,antlr_gen,"/> <stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="brand-version,antlr_gen,"/> <booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> @@ -18,7 +19,7 @@ <mapEntry key="eclipse.running" value="true"/> <mapEntry key="eclipse.pdebuild.home" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/./"/> <mapEntry key="eclipse.home" value="/Library/eclipse"/> -<mapEntry key="compile.dir" value="${project_loc}/target/build"/> +<mapEntry key="compile.dir" value="${project_loc:/target/build}"/> <mapEntry key="eclipse.pdebuild.templates" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/templates/"/> </mapAttribute> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/advanced-compiler/jython/build.xml}"/> Added: trunk/sandbox/tobias/bootstrap =================================================================== --- trunk/sandbox/tobias/bootstrap (rev 0) +++ trunk/sandbox/tobias/bootstrap 2009-08-23 22:46:49 UTC (rev 6714) @@ -0,0 +1,267 @@ +#!/bin/sh + +# <configuration> +# <command names> +CMD_JYTHON=jython +CMD_INSTALL=easy_jython_install +CMD_VIRTUAL=virtualjython +CMD_BENCH=benchmark_jython +# </command names> +# <config files> +CLASSPATH_FILE=~/.jython.classpath +JYTHONPATH_FILE=~/.jython.path +JYTHONOPTIONS_FILE=~/.jython.options +JAVAHOME_FILE=~/.jython.java_home +# </config files> +DEFAULT_INSTALL_PATH=~/bin +BIN_OFFSET=target/dist/bin +EZ_SETUP=http://peak.telecommunity.com/dist/ez_setup.py +BUILD_TARGET= +TEMP_DIR=/tmp +# </configuration> + +install() +{ + if [ -n "$1" ]; then + INSTALL_PATH=$1 + else + echo -n "Enter installation path [$DEFAULT_INSTALL_PATH]: " + read INSTALL_PATH + if [ -z "$INSTALL_PATH" ]; then + INSTALL_PATH=$DEFAULT_INSTALL_PATH + fi + fi + if [ "`dirname ${INSTALL_PATH}x`" != "`dirname $INSTALL_PATH`" ]; then + INSTALL_PATH=`dirname ${INSTALL_PATH}x` + fi + if [ ! -e "$BASE/lib/benchmark.sh" ]; then + CMD_BENCH= + fi + TARGET=$BASE/`basename $EXE` + for SCRIPT in {$CMD_JYTHON,$CMD_INSTALL,$CMD_VIRTUAL,$CMD_BENCH}; do + if ln -is $TARGET $INSTALL_PATH/$SCRIPT; then + echo installed $INSTALL_PATH/$SCRIPT + fi + done +} + +build() +{ + CUR_DIR=`pwd` + cd $BASE + if [ -z "`which ant`" ]; then + echo ERROR: cannot build Jython, could not find ant + exit 1 + fi + echo Rebuilding Jython + ant clean + if [ -n "`which svn`" ]; then + echo Updating working copy + svn up + fi + echo Building Jython + ant $BUILD_TARGET + cd $CUR_DIR +} + +jython() +{ + JYTHON_COMMAND=$BIN_DIR/jython + if [ ! -e "$JYTHON_COMMAND" ]; then + build + elif [ 0 -eq 0 ]; then + # disable the next branch - it is too slow... + echo -n + elif [ -n "`which svn`" ]; then + # TODO: speed up this comparison - then it can be enabled... + BASE_REVISION=`svn info | grep ^Revision` + if [ $? -ne 0 ]; then + echo ERROR: broken working copy + exit 1 + fi + HEAD_REVISION=`svn info -r HEAD | grep ^Revision` + if [ $? -eq 0 ]; then + if [ "$BASE_REVISION" != "$HEAD_REVISION" ]; then + build + fi + fi + fi + if [ -e "$JYTHONOPTIONS_FILE" ]; then + JYTHON_OPTIONS=`lam -s -J $JYTHONOPTIONS_FILE | paste -s -d \ -` + fi + while [ "${1:0:2}" == '-J' ]; do + case "${1:2}" in + # Classpath parameters have arguments + -cp) + JYTHON_OPTIONS="$JYTHON_OPTIONS $1 $2" + shift + ;; + -classpath) + JYTHON_OPTIONS="$JYTHON_OPTIONS $1 $2" + shift + ;; + *) + JYTHON_OPTIONS="$JYTHON_OPTIONS $1" + ;; + esac + shift + done + if [ "$1" == "-m" -a "$2" == "benchmark" ]; then + # benchmarking special case add timing to jython + if [ -e "$BASE/lib/benchmark.sh" ]; then + source $BASE/lib/benchmark.sh + fi + fi + $JYTHON_COMMAND $JYTHON_OPTIONS "$@" + if [ "$1" == "--help" ]; then + echo Bootstrap launcher configuration files: + echo $CLASSPATH_FILE - Configure CLASSPATH, one path per line + echo $JYTHONPATH_FILE - Configure JYTHONPATH, one path per line + echo $JYTHONOPTIONS_FILE - Options passed to the JVM, one per line + fi +} + +benchmark_jython() +{ + for VM in {client,server}; do + echo "=== Benchmarking Jython ($VM VM) ===" + if [ -n "$JAVA_HOME" ]; then + echo " * JAVA_HOME = $JAVA_HOME" + fi + jython -J-$VM -m benchmark "$@" + done +} + +benchmark() +{ + while [ $# -gt 0 ] ; do + case "$1" in + --help) + echo "Run benchmarking of a Python module in CPython and Jython" + echo + echo "Usage:" + echo " $0 <options> <script>.py" + echo "Where <options> can be one or several of the following:" + echo " --jython Run the benchmark in Jython only" + echo " --help Print this message and exit" + exit 0 + ;; + --jython) + JYTHON_ONLY="true" + ;; + *) + break + ;; + esac + shift + done + if [ -z "$1" ]; then + echo "ERROR: No script supplied" + echo "See '$0 --help' for options" + exit 1 + fi + if [ -z "$JYTHON_ONLY" ]; then + echo "=== Benchmarking CPython ===" + time python $BASE/lib/benchmark.py --scripted "$@" + fi + if [ -e "$JAVAHOME_FILE" ]; then + for JAVA_HOME in `cat $JAVAHOME_FILE`; do + export JAVA_HOME + benchmark_jython --scripted "$@" + done + else + benchmark_jython --scripted "$@" + fi +} + +easy_install() +{ + if [ ! -e "$BIN_DIR/easy_install" ]; then + if [ -n "`which wget`" ]; then + wget --output-document=$TEMP_DIR/ez_setup.py $EZ_SETUP + elif [ -n "`which curl`" ]; then + curl -o $TEMP_DIR/ez_setup.py $EZ_SETUP + else + echo ERROR: could not install setuptools + exit 1 + fi + jython $TEMP_DIR/ez_setup.py + rm $TEMP_DIR/ez_setup.py + fi + $BIN_DIR/easy_install "$@" +} + +virtualenv() +{ + if [ ! -e "$BIN_DIR/virtualenv" ]; then + easy_install virtualenv + fi + $BIN_DIR/virtualenv "$@" +} + +NAME=`basename $0` +EXE=$0 +while [ -L "$EXE" ]; do + EXE=`readlink $EXE` +done +BASE=`dirname $EXE` +BASE=`cd $BASE; pwd` +BIN_DIR=$BASE/$BIN_OFFSET + +if [ "$EXE" == "$0" ]; then + install "$@" +else + # Setup CLASSPATH + if [ -e "$CLASSPATH_FILE" ]; then + LOCAL_CLASSPATH=`paste -s -d : $CLASSPATH_FILE` + fi + if [ -n "$CLASSPATH" ]; then + if [ -n "$LOCAL_CLASSPATH" ]; then + export CLASSPATH=$LOCAL_CLASSPATH:$CLASSPATH + fi + else + export CLASSPATH=$LOCAL_CLASSPATH + fi + # Setup JYTHONPATH + if [ -e "$JYTHONPATH_FILE" ]; then + LOCAL_JYTHONPATH=`paste -s -d : $JYTHONPATH_FILE` + fi + if [ -n $"JYTHONPATH" ]; then + if [ -n "$LOCAL_JYTHONPATH" ]; then + export JYTHONPATH=$LOCAL_JYTHONPATH:$BASE/lib:$JYTHONPATH + else + export JYTHONPATH=$BASE/lib:$JYTHONPATH + fi + else + if [ -n "$LOCAL_JYTHONPATH" ]; then + export JYTHONPATH=$LOCAL_JYTHONPATH:$BASE/lib + else + export JYTHONPATH=$BASE/lib + fi + fi + # Setup JAVA_HOME + if [ -z "$JAVA_HOME" ]; then + if [ -e "$JAVAHOME_FILE" ]; then + export JAVA_HOME=`head -n 1 $JAVAHOME_FILE` + fi + fi + # Dispatch command + case "$NAME" in + $CMD_JYTHON) + jython "$@" + ;; + $CMD_INSTALL) + easy_install "$@" + ;; + $CMD_VIRTUAL) + virtualenv "$@" + ;; + $CMD_BENCH) + benchmark "$@" + ;; + *) + echo ERROR: unknown command \"$NAME\" + exit 1 + ;; + esac +fi Property changes on: trunk/sandbox/tobias/bootstrap ___________________________________________________________________ Added: svn:executable + * Modified: trunk/sandbox/tobias/build.xml =================================================================== --- trunk/sandbox/tobias/build.xml 2009-08-23 19:47:55 UTC (rev 6713) +++ trunk/sandbox/tobias/build.xml 2009-08-23 22:46:49 UTC (rev 6714) @@ -53,6 +53,9 @@ </exec> </target> + <target name="source dist"> + </target> + <target name="setup target"> <mkdir dir="${target.dir}"/> </target> Property changes on: trunk/sandbox/tobias/lib ___________________________________________________________________ Added: svn:ignore + *.class *.pyc Added: trunk/sandbox/tobias/lib/benchmark.py =================================================================== --- trunk/sandbox/tobias/lib/benchmark.py (rev 0) +++ trunk/sandbox/tobias/lib/benchmark.py 2009-08-23 22:46:49 UTC (rev 6714) @@ -0,0 +1,143 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Python benchmarking module + +Command line usage: + %(prog)s <module> [<module> ...] +""" + +from __future__ import with_statement + +import sys, traceback + +if __name__ == '__main__': + from benchmark import __main__ + try: + __main__(*sys.argv) + except: + traceback.print_exc() + sys.exit(1) + else: + sys.exit(0) + +__all__ = ('benchmark', 'run') + +def benchmark(*args, **params): + if len(args) > 1: + raise ValueError("Illegal use of benchmark decorator.") + def decorator(func): + func.__benchmark__ = params + return func + if args: + return decorator(*args) + else: + return decorator + +def run(*cases, **params): + if not cases: + if hasattr(sys, '_getframe'): + frame = sys._getframe(1) + while frame and frame.f_globals['__name__'] == __name__: + frame = frame.f_back + if frame: + cases = (frame.f_globals['__name__'],) + benchmarks = [] + for case in cases: + if isstring(case): + if case.endswith('.py'): + env = {'__name__':'__benchmark__', '__file__':case} + try: + with open(case) as file: + exec(file.read(), env) + except: + print("Error in benchmark file '%s'." % (case,)) + traceback.print_exc() + continue + else: + module = _Dummy() + module.__benchmarks__ = env.get('__benchmarks__', ()) + elif case in sys.modules: + module = sys.modules[case] + else: + env = {} + try: + exec("import %s as module" % (case,), env) + except: + print("No such benchmark module '%s'." % (case,)) + continue + else: + module = env['module'] + name = case + for case in getattr(module, '__benchmarks__', ()): + if isstring(case): + try: + benchmarks.append(getattr(module, case)) + except: + print("No such benchmark case '%s' in module '%s'." % + (case, name)) + else: + benchmarks.append((name, case)) + else: + benchmarks.append((None, case)) + _run(benchmarks, params) + +benchmark.run = run + +try: + basestring +except: + def isstring(string): + return isinstance(string, str) +else: + def isstring(string): + return isinstance(string, basestring) + +__DEFAULT__ = object() +class _Dummy(object): pass + +def _run(cases, params): + warmup = params.get('warmup', __DEFAULT__) + if warmup is __DEFAULT__: + pass + elif warmup is None: + pass + else: + pass + for module, case in cases: + name = ('%s.%s' % (module, case.__name__)) if module else case.__name__ + print name + +if sys.platform.lower().startswith('java'): + def _warmup(params): + warmup = params.pop('warmup', None) + if warmup is INTERACTIVE_WARMUP: + pass + elif warmup is not None: + return dict( + iterations=int(warmup), + ) +else: + def _warmup(params): + params.pop('warmup',None) + + +def __main__(script, *args): + from optparse import OptionParser + parser = OptionParser() + parser.add_option('--verbose', action='store_true', default=False) + parser.add_option('--scripted', action='store_true', default=False) + parser.add_option('--runs', type='int', default=1) + parser.add_option('--loops', type='int', default=10) + parser.add_option('--warmup-runs', type='int', default=1) + parser.add_option('--warmup-loops', type='int', default=1) + parser.add_option('--repetitions', '--reps', type='int', default=None) + options, args = parser.parse_args(list(args)) + + params = {'verbose': options.verbose + } + if options.repetitions is not None: + params['repetitions'] = options.repetitions + if not args: + print(__doc__ % {'prog': script}) + else: + run(*args,**params) Added: trunk/sandbox/tobias/lib/benchmark.sh =================================================================== --- trunk/sandbox/tobias/lib/benchmark.sh (rev 0) +++ trunk/sandbox/tobias/lib/benchmark.sh 2009-08-23 22:46:49 UTC (rev 6714) @@ -0,0 +1 @@ +JYTHON_COMMAND="time $JYTHON_COMMAND" Modified: trunk/sandbox/tobias/tests/parrotbench/b.py =================================================================== --- trunk/sandbox/tobias/tests/parrotbench/b.py 2009-08-23 19:47:55 UTC (rev 6713) +++ trunk/sandbox/tobias/tests/parrotbench/b.py 2009-08-23 22:46:49 UTC (rev 6714) @@ -9,7 +9,8 @@ import sys from time import time -WARMUP = 0 +WARMUP = 250 +#WARMUP = 0 TIMES = 3 NUMBER = 1 ITERATIONS = 1 @@ -38,7 +39,7 @@ print >>sys.stderr, "--> iteration", i for module in (b0, b2, b3, b4, b5, b6): # b1 ommitted mt = min(run(module, i)) - print >>sys.stderr, "best of 3:", mt + print >>sys.stderr, "best of %s:" % TIMES, mt t = time() - t print >>sys.stderr, "--> All done.", t This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-09-13 16:26:37
|
Revision: 6794 http://jython.svn.sourceforge.net/jython/?rev=6794&view=rev Author: thobes Date: 2009-09-13 16:26:28 +0000 (Sun, 13 Sep 2009) Log Message: ----------- Preparing SoC code submission. Modified Paths: -------------- trunk/sandbox/tobias/README.txt trunk/sandbox/tobias/build.xml Property Changed: ---------------- trunk/sandbox/tobias/ Property changes on: trunk/sandbox/tobias ___________________________________________________________________ Modified: svn:externals - jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython frame https://kenai.com/svn/jvm-frame-introspect~svn/frame ssa https://kenai.com/svn/ssa-compiler~svn-temprep/trunk + jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython frame https://kenai.com/svn/jvm-frame-introspect~svn/frame ssa https://kenai.com/svn/ssa-compiler~svn-temprep/trunk mlvm https://kenai.com/svn/jvm-frame-introspect~svn/mlvm/ Modified: trunk/sandbox/tobias/README.txt =================================================================== --- trunk/sandbox/tobias/README.txt 2009-09-13 10:00:14 UTC (rev 6793) +++ trunk/sandbox/tobias/README.txt 2009-09-13 16:26:28 UTC (rev 6794) @@ -1,5 +1,8 @@ This sandbox contains Tobias projects. Most notably the "advanced" compiler. +The most recent version can be found at: + https://jython.svn.sourceforge.net/svnroot/jython/trunk/sandbox/tobias + Here double version control systems are used. Subversion is used at the base. All sub projects are managed in subversion. The main Jython code is linked using svn:externals. Modified: trunk/sandbox/tobias/build.xml =================================================================== --- trunk/sandbox/tobias/build.xml 2009-09-13 10:00:14 UTC (rev 6793) +++ trunk/sandbox/tobias/build.xml 2009-09-13 16:26:28 UTC (rev 6794) @@ -1,8 +1,5 @@ <project name="advanced" default="all" basedir="."> <target name="all" depends="jython,compiler,frame,util,bytecode,agent"/> - <target name="version"> - <echo message="${ant.version.minor}"/> - </target> <property name="target.dir" location="${basedir}/target"/> @@ -54,6 +51,32 @@ </target> <target name="source dist"> + <tar destfile="${target.dir}/Tobias_Ivarsson.tar.gz" compression="gzip"> + <tarfileset dir="${basedir}"> + <not> + <filename name="**/.svn/**" /> + </not> + <or> + <!-- files --> + <filename name="README.txt" /> + <filename name="bootstrap" /> + <filename name="build.xml" /> + <!-- subdirectories --> + <filename name="agent/**" /> + <filename name="bytecode/**" /> + <filename name="compiler/**" /> + <filename name="frame/**" /> + <filename name="lib/**" /> + <filename name="mlvm/**" /> + <filename name="ssa/**" /> + <filename name="tests/**" /> + <filename name="util/**" /> + </or> + </tarfileset> + <tarfileset dir="${basedir}/.hg/patches" prefix="patches/"> + <filename name="*.patch" /> + </tarfileset> + </tar> </target> <target name="setup target"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-12-01 09:51:46
|
Revision: 6953 http://jython.svn.sourceforge.net/jython/?rev=6953&view=rev Author: thobes Date: 2009-12-01 09:51:33 +0000 (Tue, 01 Dec 2009) Log Message: ----------- Updated bootstrap script and eclipse build configurations in my sandbox. Modified Paths: -------------- trunk/sandbox/tobias/.classpath trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch trunk/sandbox/tobias/bootstrap Modified: trunk/sandbox/tobias/.classpath =================================================================== --- trunk/sandbox/tobias/.classpath 2009-11-30 23:27:03 UTC (rev 6952) +++ trunk/sandbox/tobias/.classpath 2009-12-01 09:51:33 UTC (rev 6953) @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry excluding="com/ziclix/python/sql/|com/ziclix/python/sql/connect/|com/ziclix/python/sql/handler/|com/ziclix/python/sql/pipe/|com/ziclix/python/sql/pipe/csv/|com/ziclix/python/sql/pipe/db/|com/ziclix/python/sql/procedure/|com/ziclix/python/sql/resource/|com/ziclix/python/sql/util/" kind="src" path="jython/src"/> - <classpathentry kind="src" path="ssa/src"/> <classpathentry excluding="org/python/compiler/advanced/ast/" kind="src" path="compiler/src"/> <classpathentry excluding="org/python/code/CodeTable.java|org/python/code/SpecializedCode.java|org/python/frame/JavaFrameAccessor.java" kind="src" path="util/src"/> <classpathentry kind="src" path="bytecode/src"/> @@ -11,17 +10,20 @@ <classpathentry kind="src" path="jython/build/gensrc"/> <classpathentry kind="src" path="jython/tests/java"/> <classpathentry kind="src" path="compiler/test"/> - <classpathentry kind="src" path="ssa/test"/> + <classpathentry kind="src" path="ssa/src/main/java"/> + <classpathentry kind="src" path="ssa/src/test/java"/> <classpathentry kind="lib" path="jython/Demo/jreload/example.jar"/> <classpathentry kind="lib" path="jython/extlibs/antlr-2.7.7.jar"/> <classpathentry kind="lib" path="jython/extlibs/asm-3.1.jar"/> <classpathentry kind="lib" path="jython/extlibs/asm-commons-3.1.jar"/> <classpathentry kind="lib" path="jython/extlibs/asm-util-3.1.jar"/> - <classpathentry kind="lib" path="jython/extlibs/constantine-0.4.jar"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="lib" path="jython/extlibs/constantine.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jffi-Darwin.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jffi.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jnr-posix.jar"/> <classpathentry kind="lib" path="jython/extlibs/cpptasks/cpptasks.jar"/> <classpathentry kind="lib" path="jython/extlibs/jarjar-0.7.jar"/> - <classpathentry kind="lib" path="jython/extlibs/jna-posix.jar"/> - <classpathentry kind="lib" path="jython/extlibs/jna.jar"/> <classpathentry kind="lib" path="jython/extlibs/junit-3.8.2.jar"/> <classpathentry kind="lib" path="jython/extlibs/libreadline-java-0.8.jar"/> <classpathentry kind="lib" path="jython/extlibs/mysql-connector-java-5.1.6.jar"/> @@ -38,7 +40,6 @@ <classpathentry kind="lib" path="jython/Lib/test/classimport_Lib.jar"/> <classpathentry kind="lib" path="jython/Lib/test/classimport.jar"/> <classpathentry kind="lib" path="jython/Lib/test/syspath_import.jar"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5.0 (Mac OS X default)"/> <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> <classpathentry kind="lib" path="jython/extlibs/antlr-3.1.3.jar"/> <classpathentry kind="lib" path="jython/extlibs/antlr-runtime-3.1.3.jar"/> Modified: trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch =================================================================== --- trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-11-30 23:27:03 UTC (rev 6952) +++ trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-12-01 09:51:33 UTC (rev 6953) @@ -1,28 +1,24 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?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="brand-version,antlr_gen,"/> <stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="brand-version,antlr_gen,"/> <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="/advanced-compiler/jython/build.xml"/> -</listAttribute> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="1"/> -</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"/> <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="advanced-compiler"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/> <mapAttribute key="org.eclipse.ui.externaltools.ATTR_ANT_PROPERTIES"> -<mapEntry key="eclipse.pdebuild.scripts" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/scripts/"/> <mapEntry key="eclipse.running" value="true"/> -<mapEntry key="eclipse.pdebuild.home" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/./"/> -<mapEntry key="eclipse.home" value="/Library/eclipse"/> <mapEntry key="compile.dir" value="${project_loc:/target/build}"/> +<mapEntry key="eclipse.home" value="/Library/eclipse"/> <mapEntry key="eclipse.pdebuild.templates" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/templates/"/> +<mapEntry key="eclipse.pdebuild.home" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/./"/> +<mapEntry key="eclipse.pdebuild.scripts" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/scripts/"/> </mapAttribute> -<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/advanced-compiler/jython/build.xml}"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/jython-extended/jython/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="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/> Modified: trunk/sandbox/tobias/bootstrap =================================================================== --- trunk/sandbox/tobias/bootstrap 2009-11-30 23:27:03 UTC (rev 6952) +++ trunk/sandbox/tobias/bootstrap 2009-12-01 09:51:33 UTC (rev 6953) @@ -71,7 +71,7 @@ build elif [ 0 -eq 0 ]; then # disable the next branch - it is too slow... - echo -n + false elif [ -n "`which svn`" ]; then # TODO: speed up this comparison - then it can be enabled... BASE_REVISION=`svn info | grep ^Revision` This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |