-
Notifications
You must be signed in to change notification settings - Fork 46
[jextract] Generate code for free functions with primitive types in JNI mode #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[jextract] Generate code for free functions with primitive types in JNI mode #269
Conversation
private func printFunctionBinding(_ printer: inout CodePrinter, _ decl: ImportedFunc) { | ||
let returnType = decl.functionSignature.result.type.javaType | ||
let params = decl.functionSignature.parameters.map { | ||
"\($0.type.javaType) \($0.parameterName!)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably safeguard the same way FFM does, by just naming them _0
, _1
etc.. however, I am not sure when parameterName
actually can be nil
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func foo(_: Int)
case should be nil
. Not so common, but for example:
protocol SomeProtocol {
init()
}
func foo<T: SomeProtocol>(_: T.Type) -> T {
return T.init()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we should handle the nil, it's not very common but we should handle it.
We can maybe centralize it somehow to provide some one place where we do effectiveJavaParameters()
? The impl of naming those could be just:
[...].enumerated().map { idx, param in
"\(param.type.javaType) \(param.paremeterName ?? "arg\(idx)")"
}
At the same time maybe it's a good time to then fix them to become maybe arg0
which is a common Java way to spell those "when names are unknown" 🤔
Good first step -- consider adding a test as well so we can keep the generated signatures tested using unit tests. I'd be happy to just merge these small steps one by one but let's add a small test here maybe? 👍 |
The last thing I need to handle in this PR, is the unsigned integers which do not conform to |
Yeah totally ok to do that separately 👍 Please file an issue about it so we don't forget :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :-) Great first step and thanks for adding the tests!
df1a93a
to
1491950
Compare
This PR adds support for a new mode for
jextract
that would generate JNI code instead.We will start of with generating Java bindings and Swift thunks for free functions and primitive types.