Skip to content

Commit b8add24

Browse files
committed
Merge branch 'master' into bugfix/GR-11981
2 parents 7cc2910 + 4d97ba6 commit b8add24

File tree

23 files changed

+121
-127
lines changed

23 files changed

+121
-127
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/interop/JavaInteropTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void accessSuitePy() throws IOException {
238238
}
239239
}
240240
assertNotNull("Dacapo found", dacapo);
241-
assertEquals("e39957904b7e79caf4fa54f30e8e4ee74d4e9e37", dacapo.getMember("sha1").toString());
241+
assertEquals("'e39957904b7e79caf4fa54f30e8e4ee74d4e9e37'", dacapo.getMember("sha1").toString());
242242
}
243243

244244
public static class ForeignObjectWithOOInvoke implements TruffleObject {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@
3434
import org.graalvm.options.OptionDescriptors;
3535

3636
import com.oracle.graal.python.builtins.Python3Core;
37-
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
37+
import com.oracle.graal.python.builtins.objects.PNone;
3838
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
3939
import com.oracle.graal.python.builtins.objects.function.PArguments;
4040
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
4141
import com.oracle.graal.python.builtins.objects.function.PKeyword;
42+
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
43+
import com.oracle.graal.python.builtins.objects.module.PythonModule;
4244
import com.oracle.graal.python.builtins.objects.object.PythonObject;
43-
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
45+
import com.oracle.graal.python.nodes.BuiltinNames;
4446
import com.oracle.graal.python.nodes.NodeFactory;
4547
import com.oracle.graal.python.nodes.PNode;
46-
import com.oracle.graal.python.nodes.SpecialMethodNames;
4748
import com.oracle.graal.python.nodes.call.InvokeNode;
4849
import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
4950
import com.oracle.graal.python.nodes.expression.ExpressionNode;
@@ -328,7 +329,7 @@ public static PythonCore getCore() {
328329

329330
@Override
330331
protected boolean isVisible(PythonContext context, Object value) {
331-
return false;
332+
return value != PNone.NONE && value != PNone.NO_VALUE;
332333
}
333334

334335
@Override
@@ -362,12 +363,12 @@ protected Iterable<Scope> findTopScopes(PythonContext context) {
362363

363364
@Override
364365
protected String toString(PythonContext context, Object value) {
365-
PythonBuiltinClass strType = context.getCore().lookupType(PythonBuiltinClassType.PString);
366-
PBuiltinFunction strConstructor = (PBuiltinFunction) strType.getAttribute(SpecialMethodNames.__NEW__);
366+
final PythonModule builtins = context.getBuiltins();
367+
PBuiltinFunction reprMethod = ((PBuiltinMethod) builtins.getAttribute(BuiltinNames.REPR)).getFunction();
367368
Object[] userArgs = PArguments.create(2);
368-
PArguments.setArgument(userArgs, 0, strType);
369+
PArguments.setArgument(userArgs, 0, PNone.NONE);
369370
PArguments.setArgument(userArgs, 1, value);
370-
Object res = InvokeNode.create(strConstructor).execute(null, userArgs, PKeyword.EMPTY_KEYWORDS);
371+
Object res = InvokeNode.create(reprMethod).execute(null, userArgs, PKeyword.EMPTY_KEYWORDS);
371372
return res.toString();
372373
}
373374

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@
142142
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
143143
import com.oracle.truffle.api.TruffleFile;
144144
import com.oracle.truffle.api.TruffleLanguage.Env;
145-
import com.oracle.truffle.api.nodes.Node;
146145
import com.oracle.truffle.api.source.Source;
147146

148147
/**
@@ -435,41 +434,16 @@ public PythonClass getErrorClass(PythonErrorType type) {
435434
}
436435

437436
@Override
438-
public PException raise(PBaseException exception, Node node) {
439-
PException pException = new PException(exception, node);
440-
exception.setException(pException);
441-
throw pException;
442-
}
443-
444-
@Override
445-
public PException raise(PythonErrorType type, Node node, String format, Object... args) {
437+
@TruffleBoundary
438+
public PException raise(PythonErrorType type, String format, Object... args) {
446439
PBaseException instance;
447440
PythonClass exceptionType = getErrorClass(type);
448441
if (format != null) {
449442
instance = factory.createBaseException(exceptionType, format, args);
450443
} else {
451-
instance = factory.createBaseException(exceptionType, factory.createEmptyTuple());
444+
instance = factory.createBaseException(exceptionType);
452445
}
453-
throw raise(instance, node);
454-
}
455-
456-
@Override
457-
public PException raise(PythonErrorType type, String format, Object... args) {
458-
return raise(type, null, format, args);
459-
}
460-
461-
@Override
462-
public PException raise(PythonErrorType type) {
463-
throw raise(factory.createBaseException(getErrorClass(type)), null);
464-
}
465-
466-
@Override
467-
public PException raise(PythonClass exceptionType, Node node) {
468-
throw raise(factory.createBaseException(exceptionType), node);
469-
}
470-
471-
public PException raise(PythonErrorType type, Node node) {
472-
throw raise(factory.createBaseException(getErrorClass(type)), node);
446+
throw PException.fromObject(instance, null);
473447
}
474448

475449
private void publishBuiltinModules() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private PComplex convertStringToComplex(String str, PythonClass cls) {
314314
}
315315

316316
if (s == n) {
317-
throw getCore().raise(ValueError, "empty string for complex()");
317+
throw raise(ValueError, "empty string for complex()");
318318
}
319319

320320
double z = -1.0;
@@ -379,7 +379,7 @@ private PComplex convertStringToComplex(String str, PythonClass cls) {
379379
int end = endDouble(str, s);
380380
z = Double.valueOf(str.substring(s, end)).doubleValue();
381381
if (z == Double.POSITIVE_INFINITY) {
382-
throw getCore().raise(ValueError, String.format("float() out of range: %.150s", str));
382+
throw raise(ValueError, String.format("float() out of range: %.150s", str));
383383
}
384384

385385
s = end;
@@ -407,7 +407,7 @@ private PComplex convertStringToComplex(String str, PythonClass cls) {
407407
} while (s < n && !swError);
408408

409409
if (swError) {
410-
throw getCore().raise(ValueError, "malformed string for complex() %s", str.substring(s));
410+
throw raise(ValueError, "malformed string for complex() %s", str.substring(s));
411411
}
412412

413413
return factory().createComplex(cls, x, y);
@@ -640,7 +640,7 @@ private double convertStringToDouble(String str) {
640640
for (int i = 0; i < n; i++) {
641641
char ch = str.charAt(i);
642642
if (ch == '\u0000') {
643-
throw getCore().raise(ValueError, "empty string for complex()");
643+
throw raise(ValueError, "empty string for complex()");
644644
}
645645
if (Character.isDigit(ch)) {
646646
if (s == null) {
@@ -667,7 +667,7 @@ private double convertStringToDouble(String str) {
667667
return Double.valueOf(sval).doubleValue();
668668
} catch (NumberFormatException exc) {
669669
// throw Py.ValueError("invalid literal for __float__: " + str);
670-
throw getCore().raise(ValueError, "could not convert string to float: %s", str);
670+
throw raise(ValueError, "could not convert string to float: %s", str);
671671
}
672672
}
673673

@@ -814,7 +814,7 @@ private Object stringToInt(String num, int base) {
814814
return bi.intValue();
815815
}
816816
} else {
817-
throw getCore().raise(ValueError, "base is out of range for int()");
817+
throw raise(ValueError, "base is out of range for int()");
818818
}
819819
}
820820

@@ -836,7 +836,7 @@ private Object toInt(Object arg1, Object arg2) {
836836
if (arg1 instanceof String && arg2 instanceof Integer) {
837837
return stringToInt((String) arg1, (Integer) arg2);
838838
} else {
839-
throw getCore().raise(ValueError, "invalid base or val for int()");
839+
throw raise(ValueError, "invalid base or val for int()");
840840
}
841841
}
842842

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ public Object repr(Object obj,
12461246
if (isString.profile(result instanceof String) || isPString.profile(result instanceof PString)) {
12471247
return result;
12481248
}
1249-
throw getCore().raise(TypeError, "__repr__ returned non-string (type %p)", obj);
1249+
throw raise(TypeError, "__repr__ returned non-string (type %p)", obj);
12501250
}
12511251
}
12521252

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ String decodeBytes(ByteBuffer bytes, String encoding, String errors) {
441441
CharBuffer decoded = charset.newDecoder().onMalformedInput(errorAction).onUnmappableCharacter(errorAction).decode(bytes);
442442
return String.valueOf(decoded);
443443
} catch (IllegalArgumentException e) {
444-
throw this.getCore().raise(LookupError, "unknown encoding: %s", encoding);
444+
throw this.raise(LookupError, "unknown encoding: %s", encoding);
445445
} catch (CharacterCodingException e) {
446446
throw raise(UnicodeDecodeError, "%s", e.getMessage());
447447
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ protected GetStackTraceRootNode(PythonLanguage language) {
226226
@Override
227227
public Object execute(VirtualFrame frame) {
228228
CompilerDirectives.transferToInterpreter();
229-
throw contextRef.get().getCore().raise(ValueError);
229+
throw contextRef.get().getCore().raise(ValueError, null);
230230
}
231231

232232
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TruffleCextBuiltins.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ Object run(@SuppressWarnings("unused") PythonClass typ, PBaseException val, @Sup
325325
if (val.getException() != null) {
326326
getContext().setCurrentException(val.getException());
327327
} else {
328-
PException pException = new PException(val, this);
329-
val.setException(pException);
328+
PException pException = PException.fromObject(val, this);
330329
getContext().setCurrentException(pException);
331330
}
332331
return PNone.NONE;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ Object run(PDict self, Object key,
319319
if (delItemNode.execute(self, self.getDictStorage(), key)) {
320320
return PNone.NONE;
321321
}
322-
throw getCore().raise(KeyError, this, "%s", key);
322+
throw raise(KeyError, "%s", key);
323323
}
324324
}
325325

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ Object sendThrow(VirtualFrame frame, PGenerator self, PythonClass typ, @Suppress
155155
@Cached("create(__CALL__)") LookupAndCallVarargsNode callTyp) {
156156
Object instance = callTyp.execute(frame, typ, new Object[0]);
157157
if (instance instanceof PBaseException) {
158-
PException pException = new PException((PBaseException) instance, this);
159-
((PBaseException) instance).setException(pException);
158+
PException pException = PException.fromObject((PBaseException) instance, this);
160159
PArguments.setSpecialArgument(self.getArguments(), pException);
161160
} else {
162161
throw raise(TypeError, "exceptions must derive from BaseException");
@@ -169,8 +168,7 @@ Object sendThrow(VirtualFrame frame, PGenerator self, PythonClass typ, PTuple va
169168
@Cached("create(__CALL__)") LookupAndCallVarargsNode callTyp) {
170169
Object instance = callTyp.execute(frame, typ, val.getArray());
171170
if (instance instanceof PBaseException) {
172-
PException pException = new PException((PBaseException) instance, this);
173-
((PBaseException) instance).setException(pException);
171+
PException pException = PException.fromObject((PBaseException) instance, this);
174172
PArguments.setSpecialArgument(self.getArguments(), pException);
175173
} else {
176174
throw raise(TypeError, "exceptions must derive from BaseException");
@@ -183,8 +181,7 @@ Object sendThrow(VirtualFrame frame, PGenerator self, PythonClass typ, Object va
183181
@Cached("create(__CALL__)") LookupAndCallVarargsNode callTyp) {
184182
Object instance = callTyp.execute(frame, typ, new Object[]{val});
185183
if (instance instanceof PBaseException) {
186-
PException pException = new PException((PBaseException) instance, this);
187-
((PBaseException) instance).setException(pException);
184+
PException pException = PException.fromObject((PBaseException) instance, this);
188185
PArguments.setSpecialArgument(self.getArguments(), pException);
189186
} else {
190187
throw raise(TypeError, "exceptions must derive from BaseException");
@@ -194,16 +191,14 @@ Object sendThrow(VirtualFrame frame, PGenerator self, PythonClass typ, Object va
194191

195192
@Specialization
196193
Object sendThrow(PGenerator self, PBaseException instance, @SuppressWarnings("unused") PNone val, @SuppressWarnings("unused") PNone tb) {
197-
PException pException = new PException(instance, this);
198-
instance.setException(pException);
194+
PException pException = PException.fromObject(instance, this);
199195
PArguments.setSpecialArgument(self.getArguments(), pException);
200196
return resumeGenerator(self);
201197
}
202198

203199
@Specialization
204200
Object sendThrow(PGenerator self, @SuppressWarnings("unused") PythonClass typ, PBaseException instance, PTraceback tb) {
205-
PException pException = new PException(instance, this);
206-
instance.setException(pException);
201+
PException pException = PException.fromObject(instance, this);
207202
instance.setTraceback(tb);
208203
PArguments.setSpecialArgument(self.getArguments(), pException);
209204
return resumeGenerator(self);

0 commit comments

Comments
 (0)