-
Notifications
You must be signed in to change notification settings - Fork 38
Introduce protocol-based structure for generating code #249
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
base: main
Are you sure you want to change the base?
Conversation
@rintaro I could use a bit of your thoughts here. Currently, it seems like the visitor depends on translated types, specifically this function
used in places like
This stuff seems FFM specific, so should really live in the FFM implementation of the protocol and the visitor should not depend on it. It seems like the property |
@@ -0,0 +1,3 @@ | |||
protocol Swift2JavaGenerator { | |||
func generate() throws |
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.
It seems kind of weird that this protocol just has an "empty" function with no arguments. But, I did that to prevent having to pass AnalysisResult
to a bunch of sub-functions in print...
So instead the implementations can receive them as initializer arguments.
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.
It's not clear for me how this protocol will be used. The main flow can be just like:
try translator.analyze()
if shouldGenerateFFM {
FFMSwift2JavaGenerator(analysis, ...).generate()
}
if shouldGenrateJNI {
JNISwift2JavaGenerator(analysis, ...).generate()
}
Could you explain why we'd want this protocol?
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 that’s pretty equivalent. The protocol being just the generate method seemed nicer to me, and we’d swap out what we generate with but it’s equivalent to that if statement. Since there’s not much to share either approach is fine i think, modeling wise i like the protocol but we could do the if
@@ -88,6 +88,13 @@ extension Swift2JavaTranslator { | |||
/// a checked truncation operation at the Java/Swift board. | |||
var javaPrimitiveForSwiftInt: JavaType { .long } | |||
|
|||
var result: AnalysisResult { |
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.
Perhaps this should just be the return value of analyze()
?
I'm totally fine with delaying FFM There are a couple of reasons I didn't do that:
That being said, I now feel sharing var translatedSignatures: [ImportedFunc: TranslatedFunctionSignature] |
Cool, that’s the outcome I was hoping for here — when we delay the translated signature the analysis can remain detached of the output, and FFM and JNI can do their own translation/lowering based on that result 👍 |
Okay, I am moving the FFM translation part to after @madsodgaard Sorry for the conflicts, but I believe this makes JNI additions easier. |
Thank you Rintaro! :) |
c668a45
to
08aa68d
Compare
@rintaro @ktoso I think this is ready for a first pass. For now, I have just kept the protocol, but as @rintaro pointed out, we don't actually do any dynamic swapping it in that way, but I'll just keep it around for now. Otherwise, most of the stuff is just moving the previous translator stuff into |
This goal of this PR is to introduce a protocol
Swift2JavaGenerator
, which does all the code generation. This will allow us to provide multiple generation modes, such as FFM or JNI.Most of the stuff from
Swift2JavaTranslator+...
has been moved intoFFMSwift2JavaGenerator
.