Skip to content

Commit 0cf3003

Browse files
committed
Support signatures GETITERFUNC, ITERNEXTFUNC, BINARYFUNC, INITPROC, TERNARYFUNC, INQUIRY, LENFUNC, SSIZEARGFUNC
1 parent ce662c9 commit 0cf3003

File tree

2 files changed

+279
-44
lines changed

2 files changed

+279
-44
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
108108
import com.oracle.graal.python.util.OverflowException;
109109
import com.oracle.graal.python.util.PythonUtils;
110+
import com.oracle.truffle.api.CompilerAsserts;
110111
import com.oracle.truffle.api.CompilerDirectives;
111112
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
112113
import com.oracle.truffle.api.CompilerDirectives.ValueType;
@@ -117,6 +118,7 @@
117118
import com.oracle.truffle.api.dsl.GenerateUncached;
118119
import com.oracle.truffle.api.dsl.Specialization;
119120
import com.oracle.truffle.api.frame.Frame;
121+
import com.oracle.truffle.api.frame.VirtualFrame;
120122
import com.oracle.truffle.api.interop.ArityException;
121123
import com.oracle.truffle.api.interop.InteropException;
122124
import com.oracle.truffle.api.interop.InteropLibrary;
@@ -343,8 +345,7 @@ static PBuiltinFunction doIt(GraalHPyContext context, Object enclosingType, Obje
343345
throw raiseNode.raise(PythonBuiltinClassType.TypeError, "Cannot access struct member 'ml_flags' or 'ml_meth'.");
344346
}
345347

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);
348349

349350
// write doc string; we need to directly write to the storage otherwise it is
350351
// disallowed writing to builtin types.
@@ -722,9 +723,8 @@ static HPyProperty doIt(GraalHPyContext context, Object enclosingType, Object sl
722723

723724
String methodNameStr = methodName instanceof HiddenKey ? ((HiddenKey) methodName).getName() : (String) methodName;
724725

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);
728728
return new HPyProperty(methodName, function);
729729
}
730730

@@ -1001,7 +1001,7 @@ static Object doGeneric(@SuppressWarnings("unused") CExtContext hpyContext, Obje
10011001

10021002
public abstract static class HPyConvertArgsToSulongNode extends PNodeWithContext {
10031003

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);
10051005
}
10061006

10071007
public abstract static class HPyVarargsToSulongNode extends HPyConvertArgsToSulongNode {
@@ -1092,6 +1092,47 @@ static void doConvert(GraalHPyContext hpyContext, Object[] args, int argsOffset,
10921092
}
10931093
}
10941094

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+
10951136
@GenerateUncached
10961137
abstract static class HPyLongFromLong extends Node {
10971138
public abstract Object execute(int value, boolean signed);

0 commit comments

Comments
 (0)