-
Notifications
You must be signed in to change notification settings - Fork 162
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: as VARTYPE
clause in expressions
#2693
New compiler: as VARTYPE
clause in expressions
#2693
Conversation
Googletests change that use symbol numbers (RTTI)
I gave this a quick test, and this seem to work, if merged with #2665. Please tell, how should this instruction be modified using AX instead? is the logic same, just using AX instead of MAR, or there should be more arguments? I can do necessary changes to #2665 right away, then merge your PR first, and rebase 2665 after. |
Let's go with SCMD_DYNAMICCAST works on the AX register instead of the MAR register, other logic unchanged. |
575b221
to
d2f3d00
Compare
Implemented the changes: Assume that SCMD_DYNAMICCAST works on AX; shut up the compiler warnings about (Had to force-push) |
Tested again, and the cast itself is working well (so long if I modify the engine correspondingly), which is great. I found that there's a problem with chaining calls though. Consider following script:
I expect this to work, but compiler cannot handle this expression and throws error:
(is not '.' an operator?) |
No, unfortunately it isn't. This is a left-over from the old compiler. The compiler treats whole concatenations of literal, identifier, This is not the usual way of handling This might be the occasion to change this at long last. But l'd suggest making a separate PR for it. |
Alright then. I've been testing for syntax problems further, and found something else: Label label = lblGameName as UNDEFINED_TYPE; Compiler reports:
I would expect it to say that |
I confirm that the last commit fixes the issue. |
Provide syntax to dynamically cast a pointer to a managed type to a pointer to another managed type.
The compiler will generate bytecode to check at runtime whether the object actually has the new type. (opcode 76). The engine must be able to interpret that bytecode, of course; work which is provided in #2665 .
Currently, the compiler assumes that opcode 76 expects a managed pointer in MAR. If this were changed to AX then the compiler could generate more compact code.Typical code:
As concerns the third line from the bottom:
new Grandchild
yields aGrandchild *
, i.e., a dynpointer. It wouldn't make sense to convert a pointer to a non-pointer, so the compiler implies a*
in the clauseas Child
.m
is a variable that acceptsMe *
whereMe
is an ancester ofChild
, so the compiler can prove statically that the expression can go intom
. It does not generate a dynamic check.As concerns the second line from the bottom:
Me
is an ancester ofGrandchild
, so the compiler can't know at compile time whetherm
, which is aMe *
, can be converted to aGrandchild *
. So it does generate a dynamic check (opcode 76). If that check fails at runtime, theng
will receive anull
.