-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
refactor(developer): improve the callbacks for kmcmplib 🌋 #12031
refactor(developer): improve the callbacks for kmcmplib 🌋 #12031
Conversation
* Removes redundant calls * Uses C++ classes on the interface side * Removes global callbacks from the Javascript side In preparation for cleanup of compiler messages
User Test ResultsTest specification and instructions User tests are not required |
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.
I have a few notes from my review so far. I don't understand enough of the changes yet to be comfortable giving an 'approve', but I can at least post these notes up for now.
const compiler = this; | ||
const wasm_callbacks = Module.WasmCallbackInterface.implement({ | ||
message: function(message: KmnCompilerResultMessage) { | ||
compiler.callbacks.reportMessage(mapErrorFromKmcmplib(message.lineNumber, message.errorCode, message.message)); | ||
}, | ||
loadFile: function(filename: string, baseFilename: string): number[] { | ||
const data: Uint8Array = compiler.callbacks.loadFile(compiler.callbacks.resolveFilename(baseFilename, filename)); | ||
return data ? Array.from(data) : null; | ||
} | ||
}); |
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.
Is there a reason to not use arrow functions here?
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.
Not really, no, but it's just syntactic sugar right?
std::copy(bufvec.begin(), bufvec.end(), infile); | ||
infile[sz] = 0; // zero-terminate for safety, not technically needed but helps avoid memory bugs |
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.
Null-termination after copying the string?
message: function(message: KmnCompilerResultMessage) { | ||
compiler.callbacks.reportMessage(mapErrorFromKmcmplib(message.lineNumber, message.errorCode, message.message)); | ||
}, | ||
loadFile: function(filename: string, baseFilename: string): number[] { |
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.
Was loadFileCallback
. Obviously, it's been dramatically simplified from the original.
(I didn't realize this before; only learned via paired review. Documenting this for future reference.)
Changes in this pull request will be available for download in Keyman version 18.0.81-alpha |
This is a significant rework of the callbacks from kmcmplib -- using
std::vector
and other C++ std classes to remove memory management calls and simplify the WASM bindings.loadFileProc
(akaloadFile
in the new pattern)In preparation for cleanup of compiler messages.
Relates-to: #10866
@keymanapp-test-bot skip