|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.lib;
|
42 | 42 |
|
43 |
| -import static com.oracle.graal.python.lib.PyUnicodeAsEncodedString.ENC_UTF8; |
| 43 | +import static com.oracle.graal.python.nodes.BuiltinNames._CODECS; |
44 | 44 | import static com.oracle.graal.python.nodes.ErrorMessages.DECODER_S_RETURNED_P_INSTEAD_OF_STR;
|
| 45 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.DECODE; |
45 | 46 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
|
46 | 47 |
|
47 | 48 | import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
|
48 |
| -import com.oracle.graal.python.builtins.objects.PNone; |
49 | 49 | import com.oracle.graal.python.nodes.PGuards;
|
50 |
| -import com.oracle.graal.python.nodes.PNodeWithRaise; |
| 50 | +import com.oracle.graal.python.nodes.PNodeWithContext; |
| 51 | +import com.oracle.graal.python.nodes.PRaiseNode; |
| 52 | +import com.oracle.graal.python.runtime.PythonContext; |
51 | 53 | import com.oracle.truffle.api.dsl.Cached;
|
| 54 | +import com.oracle.truffle.api.dsl.GenerateUncached; |
52 | 55 | import com.oracle.truffle.api.dsl.ImportStatic;
|
53 | 56 | import com.oracle.truffle.api.dsl.Specialization;
|
| 57 | +import com.oracle.truffle.api.frame.Frame; |
54 | 58 | import com.oracle.truffle.api.frame.VirtualFrame;
|
55 | 59 |
|
56 | 60 | /**
|
57 | 61 | * Equivalent of CPython's {@code PyUnicode_Decode}.
|
58 | 62 | */
|
59 | 63 | @ImportStatic(PyUnicodeAsEncodedString.class)
|
60 |
| -public abstract class PyUnicodeDecode extends PNodeWithRaise { |
61 |
| - public abstract Object execute(VirtualFrame frame, Object object, Object encoding, Object errors); |
| 64 | +@GenerateUncached |
| 65 | +public abstract class PyUnicodeDecode extends PNodeWithContext { |
| 66 | + public abstract Object execute(Frame frame, Object object, Object encoding, Object errors); |
62 | 67 |
|
63 |
| - @Specialization(guards = "isCommon(encoding)") |
64 |
| - Object doCommon(VirtualFrame frame, Object object, String encoding, String errors, |
65 |
| - @Cached CodecsModuleBuiltins.CodecsDecodeNode decodeNode) { |
66 |
| - return decodeNode.execute(frame, object, encoding, errors, false); |
67 |
| - } |
68 |
| - |
69 |
| - @Specialization(guards = "!isCommon(encoding)") |
70 |
| - Object doRegistry(VirtualFrame frame, Object object, String encoding, String errors, |
71 |
| - @Cached CodecsModuleBuiltins.DecodeNode decodeNode) { |
| 68 | + @Specialization(guards = "frame != null") |
| 69 | + Object doFast(VirtualFrame frame, Object object, Object encoding, Object errors, |
| 70 | + @Cached CodecsModuleBuiltins.DecodeNode decodeNode, |
| 71 | + @Cached PRaiseNode raiseNode) { |
72 | 72 | final Object unicode = decodeNode.execute(frame, object, encoding, errors);
|
73 | 73 | if (!PGuards.isString(unicode)) {
|
74 |
| - throw raise(TypeError, DECODER_S_RETURNED_P_INSTEAD_OF_STR, encoding, unicode); |
| 74 | + throw raiseNode.raise(TypeError, DECODER_S_RETURNED_P_INSTEAD_OF_STR, encoding, unicode); |
75 | 75 | }
|
76 | 76 | return unicode;
|
77 | 77 | }
|
78 | 78 |
|
79 |
| - @Specialization(guards = "isNoValue(encoding)") |
80 |
| - Object doNoEncoding(VirtualFrame frame, Object object, @SuppressWarnings("unused") PNone encoding, Object errors, |
81 |
| - @Cached CodecsModuleBuiltins.CodecsDecodeNode decodeNode) { |
82 |
| - return decodeNode.execute(frame, object, ENC_UTF8, errors, false); |
| 79 | + @Specialization(replaces = "doFast") |
| 80 | + Object doWithCall(Object object, Object encoding, Object errors, |
| 81 | + @Cached PyObjectCallMethodObjArgs callNode) { |
| 82 | + return callNode.execute(null, PythonContext.get(this).getCore().lookupBuiltinModule(_CODECS), DECODE, object, encoding, errors); |
83 | 83 | }
|
84 | 84 | }
|
0 commit comments