-
-
Notifications
You must be signed in to change notification settings - Fork 670
Add a compiler flag to override the start function #566
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
Comments
Is it possible to make the compiler run all of the Use case: Library developers who need custom glue code. |
Could you explain your scenario? Asking because something like this happens under the hood: Each file's top-level statements become wrapped in a start function for this exact file. Each such function is called whenever the file is imported. The entry file's function becomes the module's start entry (which can be worked around if necessary with the This issue also made me think that the |
Scenario: A developer wants to call a web assembly imported function when someone consumes their library. // inside "./node_modules/my_library/assembly/index.ts"
@external("env", "alert") declare function alert(value: string): void;
@start
function main() {
alert("Hello World!");
} Now I understand that there's an ambient context where statements are compiled and executed before the module is exported completely without a I, however, think this makes the developer's intention way clearer if used to organize startup code. In short: Thanks for letting me voice my opinion. 👍 |
Why wouldn't this work for you? // inside "./node_modules/my_library/assembly/index.ts"
@external("env", "alert") declare function alert(value: string): void;
alert("Hello World!"); |
I admitted this already. I was only stating that it might make code look clearer. |
Thanks for the clarification, wasn't sure what was meant. Going to think about this a bit more, but my immediate feeling is that we should keep this as straight-forward as possible, as |
@dcodeIO Would it be also possible to disable generation of |
If the start function exists in the binary, it is most likely necessary for some parts of top-level code. Likewise, if there is no top-level code that needs to execute any instructions, there won't be a start function. One mechanism in place so far is |
@dcodeIO Understood. I mitigated generating a "start" node by marking my global for variables of basic types (i.e. Anyway, there's still something strange that I don't understand about initializing code that's part of export enum Error {
Ok = 0,
EarlyEndOfStream = 1,
}
@lazy
let lastError = Error.Ok;
export function GetLastError(): Error {
return lastError;
}
export function SetLastError(error: Error): void {
lastError = error;
} Now, no matter what, a |
Closing this issue as part of 2020 vacuum because it has been superseded by a new mechanism, |
Currently, execution of top level statements can be delayed until a custom start function is called with
It has recently been suggested to also provide a compiler flag doing this, essentially marking a function as the entry function using the command line. This could look like:
with either
becoming the function kicking off top-level statements, or alternatively generating a function of that name if it isn't present.
The text was updated successfully, but these errors were encountered: