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

Added __LINE__ const #180

Merged
merged 4 commits into from Feb 16, 2018

Conversation

@CrazyHackGUT
Copy link
Contributor

CrazyHackGUT commented Feb 14, 2018

Added __line const. He always equals current code line.

Test code:

#include <sourcemod>

public void OnPluginStart()
{
    PrintToServer("Check magic Pawn consts...");

    PrintToServer("cellbits = %d", cellbits);
    PrintToServer("cellmax  = %d", cellmax);
    PrintToServer("cellmin  = %d", cellmin);

    PrintToServer("charbits = %d", charbits);
    PrintToServer("charmax  = %d", charmax);
    PrintToServer("charmin  = %d", charmin);

    PrintToServer("debug    = %d", debug);

    PrintToServer("__Pawn   = %x", __Pawn);
    PrintToServer("__line   = %d", __line);

    PrintToServer("ucharmax = %d", ucharmax);
}

example running test code
line number

@Drifter321

This comment has been minimized.

Copy link
Member

Drifter321 commented Feb 14, 2018

This should probably be __LINE__ to be the same as the amxmodx one since it matches other languages. https://github.com/alliedmodders/amxmodx/blob/1a56577f7a3c8167f34cec0bbd443402f5636dcf/compiler/libpc300/sc1.c#L1463

@@ -388,6 +389,9 @@ static void readline(unsigned char *line)
line+=strlen((char*)line);
} /* if */
fline+=1;
sym=findconst("__line",NULL);
assert(sym!=NULL);
sym->addr_=fline;

This comment has been minimized.

Copy link
@rsKliPPy

rsKliPPy Feb 14, 2018

Contributor

You should probably do sym->setAddr(fline); instead to be consistent.

This comment has been minimized.

Copy link
@CrazyHackGUT

CrazyHackGUT Feb 14, 2018

Author Contributor

Thanks.

@CrazyHackGUT CrazyHackGUT changed the title Added __line const Added __LINE__ const Feb 14, 2018
@dvander

This comment has been minimized.

Copy link
Member

dvander commented Feb 16, 2018

this looks fine but it deserves additions to compiler/tests - ideally two, one testing that __LINE__ works as normal and another that it works in macro expansions. If you need assistance writing a test let me know - if you look in the folder it's straightforward, you just need an ok-blah.sp file and an ok-blah.out file containing the expected stdout.

@CrazyHackGUT

This comment has been minimized.

Copy link
Contributor Author

CrazyHackGUT commented Feb 16, 2018

Thanks. I added tests.

@dvander

This comment has been minimized.

Copy link
Member

dvander commented Feb 16, 2018

Thanks!

@dvander dvander merged commit cb79295 into alliedmodders:master Feb 16, 2018
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@CrazyHackGUT CrazyHackGUT deleted the CrazyHackGUT:line-const branch Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.