-
Notifications
You must be signed in to change notification settings - Fork 160
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
New compiler: Initializer functions for new
#2529
base: ags4
Are you sure you want to change the base?
Conversation
– Call `cc_compile(input, options, scrip, message_handler)` instead of `cc_compile(input, scrip)` – Read the error and warning(s) that the compiler issues from the `message_handler` instead of from static variables – Avoid `ccSetOption()`, pass the respective options directly to the compiler so that they are safe from being clobbered before the compiler can read them – Avoid reading the static variables `currentline` and `ccCurScriptName`
Make googletests use the new compiler calling convention use `compile(source, options, scrip, messages)`
Provide the bytes that the test should generate
This would be a great addition!, but I am bothered by the chosen hardcoded name What was a reason to use this name? |
We could have it that way, too. Something along the lines of the following?
|
I also propose that constructor should be enforced to be I'd even say that it should be typeless, but idk if ags script can handle that now. |
IIRC correctly, this started when someone ( So the first remedy was to make the new compiler accept this syntax, too, so that it could grok ‘old’ code. But I stuck a warning into it that this wasn't really implemented yet. At that time, I brought up the idea to have an initialize function that would be called with the parameters between the parens whenever a struct would have such an initializer. We hadn't decided on anything definite yet, and as I said, the old compiler seemingly doesn't do anything whatsoever with this syntax. See it more as a proposal than as a definite decision on any specifics. |
I tested this, and it works in principle. But, as I mentioned previously, in my opinion, the "initializer" should rather comply to classic constructor syntax, where:
|
Okay, thanks for testing and thanks for the feedback. I'll take that as a “go” and implement the modifications you suggest, within this PR. |
Please test this!
Please note that this PR relies on the PR #2528.
Managed structs can have an initializer: i.e, a struct function that must be named
initialize
.void
(orint
so that it is possible to define it with thefunction
keyword).When a struct has an initializer that the compiler knows about, the compiler will insert a call to this function directly after an object has been created with
new
. You must give the parameters for the function call directly afternew XX
, the compiler will no longer allow you to create objects of that type without any parameter ist.On the other hand, when a struct does not have an initializer function, you can use
new
on it either with an empty parameter list or without any parameter list.