Skip to content

Commit 380a21f

Browse files
committed
[GR-11992] Revert "Use str() to convert values toString and print using repr internally for interactive sources"
PullRequest: graalpython/220
2 parents df96ec9 + dc54d1e commit 380a21f

File tree

3 files changed

+11
-35
lines changed

3 files changed

+11
-35
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/nodes/control/TopLevelExceptionHandler.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,9 @@
4141
package com.oracle.graal.python.nodes.control;
4242

4343
import static com.oracle.graal.python.nodes.SpecialMethodNames.__STR__;
44-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__;
4544
import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemExit;
4645

4746
import java.io.IOException;
48-
import java.io.OutputStream;
49-
import java.nio.charset.StandardCharsets;
5047

5148
import com.oracle.graal.python.PythonLanguage;
5249
import com.oracle.graal.python.builtins.objects.PNone;
@@ -84,7 +81,6 @@ public class TopLevelExceptionHandler extends RootNode {
8481

8582
@Child private CreateArgumentsNode createArgs = CreateArgumentsNode.create();
8683
@Child private LookupAndCallUnaryNode callStrNode = LookupAndCallUnaryNode.create(__STR__);
87-
@Child private LookupAndCallUnaryNode callReprNode = LookupAndCallUnaryNode.create(__REPR__);
8884
@Child private CallNode callNode = CallNode.create();
8985

9086
public TopLevelExceptionHandler(PythonLanguage language, RootNode child) {
@@ -110,9 +106,8 @@ public Object execute(VirtualFrame frame) {
110106
return null;
111107
} else {
112108
assert context.get().getCurrentException() == null;
113-
Object result;
114109
try {
115-
result = run(frame);
110+
return run(frame);
116111
} catch (PException e) {
117112
printExc(e);
118113
return null;
@@ -125,26 +120,6 @@ public Object execute(VirtualFrame frame) {
125120
}
126121
throw e;
127122
}
128-
if (getSourceSection().getSource().isInteractive()) {
129-
printResult(result);
130-
}
131-
return result;
132-
}
133-
}
134-
135-
@TruffleBoundary
136-
private void printResult(Object result) {
137-
if (result instanceof PNone) {
138-
return;
139-
}
140-
OutputStream out = getCurrentContext(PythonLanguage.class).getStandardOut();
141-
String stringResult = callReprNode.executeObject(result).toString();
142-
try {
143-
out.write(stringResult.getBytes(StandardCharsets.UTF_8));
144-
out.write(System.getProperty("line.separator").getBytes(StandardCharsets.UTF_8));
145-
} catch (IOException ioex) {
146-
// out stream has problems.
147-
throw new IllegalStateException(ioex);
148123
}
149124
}
150125

0 commit comments

Comments
 (0)