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

Argv input doesn't work #7

Open
Sh3b0 opened this issue Mar 6, 2022 · 3 comments
Open

Argv input doesn't work #7

Sh3b0 opened this issue Mar 6, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@Sh3b0
Copy link
Owner

Sh3b0 commented Mar 6, 2022

Code to reproduce

routine main(x: integer) : integer is
	println x;
	return 0;
end
$ ./cplus -d source.cp
$ ./a.out 5

Expected output

Prints 5

Actual output

Prints other random value, although the generated ir.ll seems correct.

@Sh3b0 Sh3b0 added the bug Something isn't working label Mar 6, 2022
@TonyDecvA180XN
Copy link
Collaborator

In clang (and also others C++ compilers) the main function is linked against the CRT definition:

int main(int argc, char *argv[])

which is a number of arguments and array of strings, that are arguments themselves parsed by space.
Linking process happens consequently and involves one-by-one check of ABI compatility. In our case, we expect the integer variable in both function signatures, which is fine, but missing second array of strings, which is also fine, surprisingly.
That way, the variable x in the program is linked against argc. This can be demonstrated here:
image
P. S. Note that first argument is always name of executable, a.exe in my case.

@Sh3b0
Copy link
Owner Author

Sh3b0 commented Mar 16, 2022

Got it, my bad.
Well, we obviously need to implement the required behavior without having to introduce arrays of character pointers in the language.

I suggest to fix this by internally calling main() with the appropriate arguments then.

@TonyDecvA180XN
Copy link
Collaborator

Yeah, but the problem of static typing does not allow us to do that. CMD Arguments are always captured as string, so we would need to embed string to int conversion code into out program, which is something I don't think we have right now. Also, for unified conversion we would need to embed all these other functions such as str to float, str to bool into CPlus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants