|
107 | 107 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
108 | 108 | import com.oracle.graal.python.util.OverflowException;
|
109 | 109 | import com.oracle.graal.python.util.PythonUtils;
|
| 110 | +import com.oracle.truffle.api.CompilerAsserts; |
110 | 111 | import com.oracle.truffle.api.CompilerDirectives;
|
111 | 112 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
112 | 113 | import com.oracle.truffle.api.CompilerDirectives.ValueType;
|
|
117 | 118 | import com.oracle.truffle.api.dsl.GenerateUncached;
|
118 | 119 | import com.oracle.truffle.api.dsl.Specialization;
|
119 | 120 | import com.oracle.truffle.api.frame.Frame;
|
| 121 | +import com.oracle.truffle.api.frame.VirtualFrame; |
120 | 122 | import com.oracle.truffle.api.interop.ArityException;
|
121 | 123 | import com.oracle.truffle.api.interop.InteropException;
|
122 | 124 | import com.oracle.truffle.api.interop.InteropLibrary;
|
@@ -343,8 +345,7 @@ static PBuiltinFunction doIt(GraalHPyContext context, Object enclosingType, Obje
|
343 | 345 | throw raiseNode.raise(PythonBuiltinClassType.TypeError, "Cannot access struct member 'ml_flags' or 'ml_meth'.");
|
344 | 346 | }
|
345 | 347 |
|
346 |
| - PRootNode rootNode = HPyExternalFunctionNodes.createHPyWrapperRootNode(language, signature, methodName, methodFunctionPointer); |
347 |
| - PBuiltinFunction function = HPyExternalFunctionNodes.createWrapperFunction(factory, methodName, enclosingType, rootNode); |
| 348 | + PBuiltinFunction function = HPyExternalFunctionNodes.createWrapperFunction(language, signature, methodName, methodFunctionPointer, enclosingType, factory); |
348 | 349 |
|
349 | 350 | // write doc string; we need to directly write to the storage otherwise it is
|
350 | 351 | // disallowed writing to builtin types.
|
@@ -722,9 +723,8 @@ static HPyProperty doIt(GraalHPyContext context, Object enclosingType, Object sl
|
722 | 723 |
|
723 | 724 | String methodNameStr = methodName instanceof HiddenKey ? ((HiddenKey) methodName).getName() : (String) methodName;
|
724 | 725 |
|
725 |
| - PRootNode rootNode = HPyExternalFunctionNodes.createHPyWrapperRootNode(language, slot.getSignature(), methodNameStr, methodFunctionPointer); |
726 |
| - PBuiltinFunction function = HPyExternalFunctionNodes.createWrapperFunction(factory, methodNameStr, HPY_TP_NEW.equals(slot) ? null : enclosingType, rootNode); |
727 |
| - |
| 726 | + PBuiltinFunction function = HPyExternalFunctionNodes.createWrapperFunction(language, slot.getSignature(), methodNameStr, methodFunctionPointer, |
| 727 | + HPY_TP_NEW.equals(slot) ? null : enclosingType, factory); |
728 | 728 | return new HPyProperty(methodName, function);
|
729 | 729 | }
|
730 | 730 |
|
@@ -1001,7 +1001,7 @@ static Object doGeneric(@SuppressWarnings("unused") CExtContext hpyContext, Obje
|
1001 | 1001 |
|
1002 | 1002 | public abstract static class HPyConvertArgsToSulongNode extends PNodeWithContext {
|
1003 | 1003 |
|
1004 |
| - public abstract void executeInto(GraalHPyContext hpyContext, Object[] args, int argsOffset, Object[] dest, int destOffset); |
| 1004 | + public abstract void executeInto(VirtualFrame frame, GraalHPyContext hpyContext, Object[] args, int argsOffset, Object[] dest, int destOffset); |
1005 | 1005 | }
|
1006 | 1006 |
|
1007 | 1007 | public abstract static class HPyVarargsToSulongNode extends HPyConvertArgsToSulongNode {
|
@@ -1092,6 +1092,47 @@ static void doConvert(GraalHPyContext hpyContext, Object[] args, int argsOffset,
|
1092 | 1092 | }
|
1093 | 1093 | }
|
1094 | 1094 |
|
| 1095 | + /** |
| 1096 | + * Converts {@code self} to an HPy handle and any other argument to {@code HPy_ssize_t}. |
| 1097 | + */ |
| 1098 | + public abstract static class HPySSizeArgFuncToSulongNode extends HPyConvertArgsToSulongNode { |
| 1099 | + |
| 1100 | + @Specialization(guards = {"isArity(args.length, argsOffset, 2)"}) |
| 1101 | + @ExplodeLoop |
| 1102 | + static void doHandleSsizeT(VirtualFrame frame, GraalHPyContext hpyContext, Object[] args, int argsOffset, Object[] dest, int destOffset, |
| 1103 | + @Cached HPyAsHandleNode asHandleNode, |
| 1104 | + @Cached ConvertPIntToPrimitiveNode asSsizeTNode) { |
| 1105 | + CompilerAsserts.partialEvaluationConstant(argsOffset); |
| 1106 | + dest[destOffset] = asHandleNode.execute(hpyContext, args[argsOffset]); |
| 1107 | + dest[destOffset + 1] = asSsizeTNode.execute(frame, args[argsOffset + 1], 1, Long.BYTES); |
| 1108 | + } |
| 1109 | + |
| 1110 | + @Specialization(guards = {"isArity(args.length, argsOffset, 3)"}) |
| 1111 | + @ExplodeLoop |
| 1112 | + static void doHandleSsizeTSsizeT(VirtualFrame frame, GraalHPyContext hpyContext, Object[] args, int argsOffset, Object[] dest, int destOffset, |
| 1113 | + @Cached HPyAsHandleNode asHandleNode, |
| 1114 | + @Cached ConvertPIntToPrimitiveNode asSsizeTNode) { |
| 1115 | + CompilerAsserts.partialEvaluationConstant(argsOffset); |
| 1116 | + dest[destOffset] = asHandleNode.execute(hpyContext, args[argsOffset]); |
| 1117 | + dest[destOffset + 1] = asSsizeTNode.execute(frame, args[argsOffset + 1], 1, Long.BYTES); |
| 1118 | + dest[destOffset + 2] = asSsizeTNode.execute(frame, args[argsOffset + 2], 1, Long.BYTES); |
| 1119 | + } |
| 1120 | + |
| 1121 | + @Specialization(replaces = {"doHandleSsizeT", "doHandleSsizeTSsizeT"}) |
| 1122 | + static void doGeneric(VirtualFrame frame, @SuppressWarnings("unused") GraalHPyContext hpyContext, Object[] args, int argsOffset, Object[] dest, int destOffset, |
| 1123 | + @Cached HPyAsHandleNode asHandleNode, |
| 1124 | + @Cached ConvertPIntToPrimitiveNode asSsizeTNode) { |
| 1125 | + dest[destOffset] = asHandleNode.execute(hpyContext, args[argsOffset]); |
| 1126 | + for (int i = 1; i < args.length - argsOffset; i++) { |
| 1127 | + dest[destOffset + i] = asSsizeTNode.execute(frame, args[argsOffset + i], 1, Long.BYTES); |
| 1128 | + } |
| 1129 | + } |
| 1130 | + |
| 1131 | + static boolean isArity(int len, int off, int expected) { |
| 1132 | + return len - off == expected; |
| 1133 | + } |
| 1134 | + } |
| 1135 | + |
1095 | 1136 | @GenerateUncached
|
1096 | 1137 | abstract static class HPyLongFromLong extends Node {
|
1097 | 1138 | public abstract Object execute(int value, boolean signed);
|
|
0 commit comments