Skip to content

Commit d4ea73c

Browse files
committed
Cleaned up the PyBuiltinFunction hierarchy as a preface to merging things using
PyBuiltinFunctionSet to live inside it. Removed inst_call stuff in favor of just binding and calling Updated newstyle stuff in packages other than core by hand as gderived.py can't handle things out of core
1 parent e2d8db1 commit d4ea73c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4162
-10234
lines changed
Lines changed: 54 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
11
package org.python.core;
22

3-
public abstract class PyBuiltinFunction extends PyObject implements PyType.Newstyle {
3+
public abstract class PyBuiltinFunction extends PyObject implements
4+
PyType.Newstyle {
45

5-
public static final String exposed_name="builtin_function_or_method";
6+
public static final String exposed_name = "builtin_function_or_method";
67

7-
public static void typeSetup(PyObject dict,PyType.Newstyle marker) {
8+
public static void typeSetup(PyObject dict, PyType.Newstyle marker) {
89
dict.__setitem__("__name__", new PyGetSetDescr("__name__",
9-
PyBuiltinFunction.class, "fastGetName", null));
10+
PyBuiltinFunction.class,
11+
"fastGetName",
12+
null));
1013
dict.__setitem__("__self__", new PyGetSetDescr("__self__",
11-
PyBuiltinFunction.class, "getSelf", null));
14+
PyBuiltinFunction.class,
15+
"getSelf",
16+
null));
1217
dict.__setitem__("__doc__", new PyGetSetDescr("__doc__",
13-
PyBuiltinFunction.class, "fastGetDoc", null));
18+
PyBuiltinFunction.class,
19+
"fastGetDoc",
20+
null));
1421
dict.__setitem__("__call__", new PyGetSetDescr("__call__",
15-
PyBuiltinFunction.class, "makeCall", null));
22+
PyBuiltinFunction.class,
23+
"makeCall",
24+
null));
1625
}
17-
26+
1827
public interface Info {
28+
1929
String getName();
30+
2031
int getMaxargs();
32+
2133
int getMinargs();
34+
2235
PyException unexpectedCall(int nargs, boolean keywords);
2336
}
2437

2538
public static class DefaultInfo implements Info {
2639

27-
public DefaultInfo(String name,int minargs,int maxargs) {
40+
public DefaultInfo(String name, int minargs, int maxargs) {
2841
this.name = name;
2942
this.minargs = minargs;
3043
this.maxargs = maxargs;
3144
}
3245

33-
public DefaultInfo(String name,int nargs) {
34-
this(name,nargs,nargs);
46+
public DefaultInfo(String name, int nargs) {
47+
this(name, nargs, nargs);
3548
}
3649

3750
private String name;
51+
3852
private int maxargs, minargs;
3953

4054
public String getName() {
@@ -44,56 +58,52 @@ public String getName() {
4458
public int getMaxargs() {
4559
return maxargs;
4660
}
61+
4762
public int getMinargs() {
4863
return minargs;
4964
}
5065

51-
public static boolean check(int nargs,int minargs,int maxargs) {
52-
if (nargs < minargs)
66+
public static boolean check(int nargs, int minargs, int maxargs) {
67+
if(nargs < minargs)
5368
return false;
54-
if (maxargs != -1 && nargs > maxargs)
69+
if(maxargs != -1 && nargs > maxargs)
5570
return false;
5671
return true;
5772
}
5873

59-
public static PyException unexpectedCall(
60-
int nargs,
61-
boolean keywords,
62-
String name,
63-
int minargs,
64-
int maxargs) {
65-
if (keywords)
74+
public static PyException unexpectedCall(int nargs,
75+
boolean keywords,
76+
String name,
77+
int minargs,
78+
int maxargs) {
79+
if(keywords)
6680
return Py.TypeError(name + "() takes no keyword arguments");
6781
String argsblurb;
68-
if (minargs == maxargs) {
69-
if (minargs == 0)
82+
if(minargs == maxargs) {
83+
if(minargs == 0)
7084
argsblurb = "no arguments";
71-
else if (minargs == 1)
85+
else if(minargs == 1)
7286
argsblurb = "exactly one argument";
7387
else
7488
argsblurb = minargs + " arguments";
75-
} else if (maxargs == -1) {
76-
return Py.TypeError(name + "() requires at least " +
77-
minargs + " (" + nargs + " given)");
89+
} else if(maxargs == -1) {
90+
return Py.TypeError(name + "() requires at least " + minargs
91+
+ " (" + nargs + " given)");
7892
} else {
79-
if (minargs <= 0)
80-
argsblurb = "at most "+ maxargs + " arguments";
93+
if(minargs <= 0)
94+
argsblurb = "at most " + maxargs + " arguments";
8195
else
8296
argsblurb = minargs + "-" + maxargs + " arguments";
8397
}
84-
85-
return Py.TypeError(
86-
name + "() takes " + argsblurb + " (" + nargs + " given)");
98+
return Py.TypeError(name + "() takes " + argsblurb + " (" + nargs
99+
+ " given)");
87100
}
88101

89102
public PyException unexpectedCall(int nargs, boolean keywords) {
90103
return unexpectedCall(nargs, keywords, name, minargs, maxargs);
91104
}
92-
93105
}
94106

95-
protected PyBuiltinFunction() {}
96-
97107
protected PyBuiltinFunction(Info info) {
98108
this.info = info;
99109
}
@@ -104,58 +114,35 @@ public void setInfo(Info info) {
104114
this.info = info;
105115
}
106116

107-
abstract protected PyBuiltinFunction makeBound(PyObject self);
117+
/**
118+
* @return a new instance of this type of PyBuiltinFunction bound to self
119+
*/
120+
abstract protected PyBuiltinFunction bind(PyObject self);
108121

109122
public PyObject getSelf() {
110123
return null;
111124
}
112125

113126
public String toString() {
114127
PyObject self = getSelf();
115-
if (self == null)
128+
if(self == null)
116129
return "<built-in function " + info.getName() + ">";
117130
else {
118131
String typename = self.getType().fastGetName();
119-
return "<built-in method "
120-
+ info.getName()
121-
+ " of "
122-
+ typename
123-
+ " object>";
132+
return "<built-in method " + info.getName() + " of " + typename
133+
+ " object>";
124134
}
125135
}
126136

127-
abstract public PyObject inst_call(PyObject self);
128-
abstract public PyObject inst_call(PyObject self, PyObject arg0);
129-
abstract public PyObject inst_call(
130-
PyObject self,
131-
PyObject arg0,
132-
PyObject arg1);
133-
abstract public PyObject inst_call(
134-
PyObject self,
135-
PyObject arg0,
136-
PyObject arg1,
137-
PyObject arg2);
138-
abstract public PyObject inst_call(
139-
PyObject self,
140-
PyObject arg0,
141-
PyObject arg1,
142-
PyObject arg2,
143-
PyObject arg3);
144-
abstract public PyObject inst_call(PyObject self, PyObject[] args);
145-
abstract public PyObject inst_call(
146-
PyObject self,
147-
PyObject[] args,
148-
String[] keywords);
149-
150137
public PyObject fastGetName() {
151138
return Py.newString(this.info.getName());
152139
}
153140

154141
public PyObject fastGetDoc() {
155142
return Py.None;
156143
}
157-
158-
public PyObject makeCall(){
144+
145+
public PyObject makeCall() {
159146
return this;
160147
}
161148
}

src/org/python/core/PyBuiltinFunctionNarrow.java

Lines changed: 0 additions & 123 deletions
This file was deleted.

src/org/python/core/PyBuiltinFunctionWide.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)