wren-lang / wren

The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.
http://wren.io
MIT License
6.9k stars 552 forks source link

Multiple problems prevent building with MSVC #52

Closed vadz closed 9 years ago

vadz commented 9 years ago

You mentioned that it would be nice to have project files for MSVS to go with the existing Xcode project and makefiles, so I tried to make one, but the problem is that the code is too MSVC-unfriendly to have a realistic chance of compiling it in the current state.

Just in case you're interested in fixing this, here are the problems I found:

  1. C99 is a problem on its own. It's not supported (and never will be) by Microsoft C front-end, so the only chance of building this code is by compiling it with the C++ compiler. This, in turn, means that a lot of casts that are implicit in C (e.g. void* result of malloc() to char*) need to be made explicit which would be already pretty ugly, probably, so this looks like a show stopper all on its own.
  2. But the code also uses some gcc extensions which are not even C99 (and hence not supported by even the C++ compiler): unless I totally forgot my C (which is possible to be honest...), WrenConfiguration struct initializer in main.c is not in C99. And neither are computed gotos used extensively in wren_vm.c, and while they can already be disabled by a config option, this really should be done automatically when using a non-gcc compiler (testing for gcc would cover clang too).
  3. getline() is also POSIX and not C99 and is not available with MSVC.

There are probably many more problems but the above was enough to stop me.

munificent commented 9 years ago

Thank you for trying this out! I definitely want to resolve these issues. Windows is super important, even though its lack of C99 support is frustrating to say the least.

For 1, my hope was I could stay within the subset of C99 that MSVC can handle, though I'm not sure if that's feasible. If compiling it with the C++ compiler is the better avenue, I'm up for that too. I would like Wren to be usable from C++ too, so having it compile with a C++ compiler is a good idea in general.

At some point, I'll probably just have to get my hands on a Windows box so I can hack on this myself, but can you give me some more details on what kinds of casts and other changes would be needed?

unless I totally forgot my C (which is possible to be honest...), WrenConfiguration struct initializer in main.c is not in C99.

If it's not, it's a mistake on my part. I can certainly change that bit of code to use regular initialization. This is my first C99 project (the last time I used straight C was a surprisingly long time ago!) so I'm still learning what's in it and what isn't.

this really should be done automatically when using a non-gcc compiler (testing for gcc would cover clang too).

I'm totally fine with that. I made it explicit because I wasn't sure how best to detect it (and because it's also nice to be able to manually set it for testing), but I definitely want it to do the right thing automatically when not explicitly set.

getline() is also POSIX and not C99 and is not available with MSVC.

That function is a thorn in my side. I should just take it out and roll my own.

If you want to throw pull requests at me for some of these please do. In the meantime, I'll try to clean up what I can to make this easier. Thanks!

vadz commented 9 years ago

The subset of C99 that MSVC can handle is basically C89 with the extension of C++-style comments -- and that's it. Notably, it doesn't support declaring variables other than at the start of the block. And, again, Microsoft has said many times that this is not going to change.

So, strange as it is, C++ is definitely more portable than C99. But C++ is, of course, a different language, with different rules and notably is more strict with implicit pointer conversions, which are used in many places. I'm not sure if it's less work to make the code compile in both C and C++ or just switch to the lowest common denominator, i.e. C89. I'm not sure what would be less ugly neither :-(

You don't really need to use Windows to see the compilation problems in C++ mode, just do make CC='g++' CFLAGS='-std=c++98' to see (at least some of) them.

munificent commented 9 years ago

I definitely think it's useful for Wren to be able to compile as C++. I did some preliminary investigation and it looks like it will be a good chunk of work, and probably best for me to do it since it touches lots of internals.

Thanks for the tip about compiling with g++. I'll try to gradually get the errors fixed, but it will take me a while. Until then, your best bet on Windows may be some other C99 compiler. :-/

munificent commented 9 years ago

OK, I did it! Wren should now compile just fine as C++98 or (I hope) any other later version of C++. That should give you a reasonable way to compile it with VS.

Let me know if you run into any more issues!