Skip to content
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

Assignment to array in definition #728

Closed
melex750 opened this issue Mar 10, 2016 · 12 comments
Closed

Assignment to array in definition #728

melex750 opened this issue Mar 10, 2016 · 12 comments

Comments

@melex750
Copy link
Contributor

From issue #624:

object[] item; // CBot doesn't allow assigning to array in definition (:/)

From issue #698:

The following code crashes the game:

int array[2] = {1,2,3};

It should give a compilation error.

@krzys-h krzys-h changed the title assignment to array in definition Assignment to array in definition Mar 10, 2016
@MrSimbax
Copy link
Contributor

Could you open a pull request?

@melex750
Copy link
Contributor Author

I made it require a semicolon if it was defined with a number.

int i[2];
int j[] = { 1, 2 };
int k[2] = <--Semicolon terminator missing

CBot doesn't count the elements during compilation,
so there's no easy way match definition with assignment.
But at least the game won't crash.
If that sounds ok, I'll try to do a pull request.

I just found another issue. { {123,234,111} {223,454,342} }
The missing comma between brackets in the middle crashes the game.
I believe I have this fixed too, but haven't tested it yet.

@melex750
Copy link
Contributor Author

Does this need a new issue?

These should not compile

int issue[true]; // compiles, crash at run

int j["string"]; // compiles, crash at run

int k[] = 1; // crash on compile

These don't compile:

int l[] = {}; //<-----doesn't work, missing semicolon

int x = 1, y = 1, z = 1;
int r[x]; // <--------- compiles, crash at run
int q[] = {x, y, z}; // compiles, crash at run

and as in the comment above: missing comma crashes the game

There's more but, it's a long list already.

I have all of it fixed, if you like.

It was mostly broken syntax checking.

@krzys-h krzys-h reopened this Mar 16, 2016
@krzys-h krzys-h self-assigned this Mar 16, 2016
@krzys-h krzys-h added this to the alpha-0.1.7 milestone Mar 16, 2016
@melex750
Copy link
Contributor Author

I was gonna mention that I had to do alot of little edits
across seven files to get it to work in functions and classes.

I also have a clean fix for issue 30(Title), i did a few days ago.

@melex750
Copy link
Contributor Author

After testing these changes in depth, i can say that it fixes several issues.
The ones above and "31, 32, 312, 437, 706, 730, and of course 661"
If nothing else, it's a good map to where these problems were found.
Is there any interest in this right now? Can I offer a .zip or a few PRs?

@krzys-h
Copy link
Member

krzys-h commented Mar 19, 2016

It would be best if you could make a PR because that makes reviewing and discussing changes a lot easier.
That looks like a big amount of issues you fixed, I'm really interested in how big the changes to make this work are.

@melex750
Copy link
Contributor Author

Ok, the fix for "31, 312" is small and stands on it's own, i'll do it separately.

@melex750
Copy link
Contributor Author

Shall I go ahead with the PR on this? (fix for "31 and 312" not yet included, but I can add it)
I hope there aren't too many style issues.

@MrSimbax
Copy link
Contributor

If you want to contribute to the project and have done something, then just open a pull request without asking anyone. It's their purpose. The worst that could happen is that we'll just close your PR without merging. It's just a lot easier to review and discuss changes in PR.

@krzys-h krzys-h removed their assignment Mar 20, 2016
@krzys-h krzys-h modified the milestones: alpha-0.1.8, alpha-0.1.7 Mar 20, 2016
@krzys-h
Copy link
Member

krzys-h commented Apr 3, 2016

Status after #737 :

The following code hangs the script, but not the whole game:

extern void object::New()
{

    int l[] = {};

    int x = 1, y = 1, z = 1;
    int r[x];
    int q[] = {x, y, z}; // hangs on "x"


}

@melex750

@krzys-h krzys-h modified the milestones: alpha-0.2.0, alpha-0.1.8 Apr 3, 2016
@melex750
Copy link
Contributor Author

melex750 commented Apr 4, 2016

It's the same testing with 0.1.6 and localrepo but i get failed assert, I haven't tested dev yet,
and:

int q[] = {x};       // works
int p[] = {1, y};    // works
int i[] = {1, 2, z}; // works

I thought it was working but now i'm not sure.

It only hangs for me if i comment out the assert();
virtual bool CBot::CBotInstr::ExecuteVar(CBot::CBotVar*&, CBot::CBotStack*&, CBot::CBotToken*, bool, bool): Assertion 0' failed.`

The problem seems to be in the execution part, and calling the baseclass method.
I tried to figure it out, with no luck.

I also found another hangover from 0.1.6 and probably before that.

int i[3] = {1,2,3};
// i[0] = i[0] + 1; // it works if you do this first

i[0] += 1; // compiler throws "variable not initialized" ??

++i[0]; // works
i[0]++; // works

The same goes for other compound operators-= *= /=

krzys-h added a commit that referenced this issue Jul 4, 2016
Fix some bugs in CBOT

This fixes #728 (comment) and #626
@krzys-h
Copy link
Member

krzys-h commented Jul 4, 2016

Fixed in #793

@krzys-h krzys-h closed this as completed Jul 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants