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

Parameters are passed in reverse order #9

Closed
tsbockman opened this issue Mar 15, 2014 · 5 comments
Closed

Parameters are passed in reverse order #9

tsbockman opened this issue Mar 15, 2014 · 5 comments
Assignees
Labels
bug Weird outcome is probably not what the mod programmer expected.

Comments

@tsbockman
Copy link

The parameter list of a script is passed to it backwards. Example script test.txt:

declare parameter p0.
declare parameter p1.
declare parameter p2.
declare parameter p3.

print "0: " + p0.
print "1: " + p1.
print "2: " + p2.
print "3: " + p3.

Call it from the terminal as follows:

run test(0, 1, 2, 3).

The expected result would be:

0: 0
1: 1
2: 2
3: 3

But, the actual result is:

0: 3
1: 2
2: 1
3: 0

I believe this bug also effects some or all built-in functions (but not constructors):

print mod(21, 6).

According to the documentation, this command should return 3. However, it actually returns 6. But, it gives the expected answer if we flip the parameters:

print mod(6, 21).
@marianoapp
Copy link
Contributor

Parameters must be popped in reverse order since the first parameter is deeper in the stack. It worked fine when multiple parameters were declared in the same statement, but for more than one statement it didn't know which one was the last.
Now it scan the whole AST looking for parameters and adds them to a list, and when it finish they're pushed in the correct order.
An interesting side effect of the solution is that the declaration of parameters no longer need to be the first line of the program, in fact, you can write them any where you want.

Edit: Also fixed the MOD function parameter order, although that was an unrelated problem.

@marianoapp marianoapp reopened this Mar 15, 2014
@marianoapp marianoapp added the bug label Mar 15, 2014
@marianoapp marianoapp self-assigned this Mar 15, 2014
@tsbockman
Copy link
Author

Thanks! All the work you guys put into this mod is much appreciated.

Also, I never even knew I could do this:

declare parameter p0, p1, p2, p3.

Much easier! I guess I was the first to notice this bug because everyone else uses the better syntax...

@Dunbaratu
Copy link
Member

No I use your syntax too, because I want to put comments explaining the parameters in the code.

@tsbockman
Copy link
Author

@Dunbaratu How about something like this?

declare parameter
 p0, // Comment 0
 p1, // Comment 1
 p2, // Comment 2
 p3. // Comment 3

That way you can comment each parameter, while being more concise and DRY.

@Dunbaratu
Copy link
Member

The older parsers were very finicky and didn't like putting comments like that in the middle of multi-line syntax.

erendrake pushed a commit that referenced this issue Apr 9, 2015
Pulling development branch updates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Weird outcome is probably not what the mod programmer expected.
Projects
None yet
Development

No branches or pull requests

3 participants