Skip to content

Instantly share code, notes, and snippets.

@jimbaker
Created January 14, 2015 23:59
Show Gist options
  • Save jimbaker/da1468693a2e588a900d to your computer and use it in GitHub Desktop.
Save jimbaker/da1468693a2e588a900d to your computer and use it in GitHub Desktop.
Decompilation of Jython module
import org.python.compiler.*;
import org.python.core.*;
@APIVersion(36)
@MTime(1421279812000L)
@Filename("fact.py")
public class fact$py extends PyFunctionTable implements PyRunnable
{
static fact$py self;
static final PyCode f$0;
static final PyCode fact$1;
public PyObject f$0(final PyFrame pyFrame, final ThreadState threadState) {
pyFrame.setline(1);
pyFrame.setlocal("fact", (PyObject)new PyFunction(pyFrame.f_globals, Py.EmptyObjects, fact$py.fact$1, (PyObject)null));
pyFrame.f_lasti = -1;
return Py.None;
}
public PyObject fact$1(final PyFrame pyFrame, final ThreadState threadState) {
pyFrame.setline(2);
if (pyFrame.getglobal("__debug__").__nonzero__() && !pyFrame.getlocal(0)._ge((PyObject)Py.newInteger(0)).__nonzero__()) {
throw Py.makeException(pyFrame.getglobal("AssertionError"), (PyObject)PyString.fromInterned("n must be >= 0"));
}
pyFrame.setline(3);
if (pyFrame.getlocal(0)._eq((PyObject)Py.newInteger(0)).__nonzero__()) {
pyFrame.setline(4);
final PyInteger integer = Py.newInteger(1);
pyFrame.f_lasti = -1;
return (PyObject)integer;
}
pyFrame.setline(6);
final PyObject mul = pyFrame.getlocal(0)._mul(pyFrame.getglobal("fact").__call__(threadState, pyFrame.getlocal(0)._sub((PyObject)Py.newInteger(1))));
pyFrame.f_lasti = -1;
return mul;
}
public fact$py(final String s) {
super();
fact$py.self = this;
f$0 = Py.newCode(0, new String[0], s, "<module>", 0, false, false, (PyFunctionTable)fact$py.self, 0, (String[])null, (String[])null, 0, 4096);
fact$1 = Py.newCode(1, new String[] { "n" }, s, "fact", 1, false, false, (PyFunctionTable)fact$py.self, 1, (String[])null, (String[])null, 0, 4097);
}
public PyCode getMain() {
return fact$py.f$0;
}
public static void main(final String[] array) {
Py.runMain(CodeLoader.createSimpleBootstrap(new fact$py("fact$py").getMain()), array);
}
public static CodeBootstrap getCodeBootstrap() {
return PyRunnableBootstrap.getFilenameConstructorReflectionBootstrap((Class)fact$py.class);
}
public PyObject call_function(final int n, final PyFrame pyFrame, final ThreadState threadState) {
switch (n) {
case 0: {
return this.f$0(pyFrame, threadState);
}
case 1: {
return this.fact$1(pyFrame, threadState);
}
default: {
return null;
}
}
}
}
def fact(n):
assert n >= 0, "n must be >= 0"
if n == 0:
return 1
else:
return n * fact(n-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment