-
Notifications
You must be signed in to change notification settings - Fork 0
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
Declaration of custom local variables #32
Comments
Semantic highlighting #28 should account for custom variables. |
I was thinking more along the lines of including a type declaration as part of the const..end construct just so I wouldn't need to update things in two sections when I shuffle my locals around..
I've been having other issues with using constants for local variables. Sanny protests when I try to use a constant as an array. There's no problem using constants as an array index, but not to define the array in the same manner as a global variable. Also, the type declarations of @v, or more to the point with arrays, @s wouldn't work with locals named as constants without the @. Also, for string arrays, the s would be used for assigning constant indexes, but not in the array. I've got it in my mind now that it doesn't make much sense to use constants for arrays, I should use a local or global variable instead, which is what Sanny reports. One format that seems to make more sense:
Or maybe not, but at least the example illustrates the issues nicely. |
Custom variables have been implemented. The only thing remaining is allowing them in SCM: scripts created with 004F or 00D7, missions and external scripts. This will be tracked in #284 |
Background
Currently it's possible to assign a custom name to the local variable using CONST..END:
then declare a type for this variable using VAR..END or the shorter form of declaration:
Proposal
Get rid of the const declaration step when the shorter form of declaration is used, i.e. given an expression like:
the compiler should assign
x
to the first available local variable index (0
) and compile it as0@ = 5
. then if another variable gets declared (e.g.int y = 6
) it gets assigned to the next index (1
), and so on:Known Limitations
Conclusion
Given the limitations, for the first iteration of this feature:
only allow the local variable declaration in a CLEO script
always assign the first declared variable to
0@
, the second one to1@
, etc. The compiler would still validate if the number of defined variables exceeds the limit for the scriptit's possible to use indexed local variables (
0@
,1@
, etc) and they may possibly clash with declared variables:the compiler would throw an error if both forms of local variables are used. the first used form controls (i.e. if you have 0@ in the script first you would be unable to use custom variables as described above, and vice versa)
the documentation should clearly state that the order of variables assignment is undetermined and may change in the future (i.e. you should not assume that the first custom variable is always
0@
)The text was updated successfully, but these errors were encountered: