-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Compiling Wren: some math, strtol and %g format string issues #104
Comments
That's great news! You now have float formatting and modf. Name clashes are in scope since there's still a lot of technical debt to pay off in terms of removing functions I whipped up on the fly for the sake of moving quickly. In terms of all the posix headers, what I'm hoping we can get away with is a shell script example code snippet that looks something like this: mkdir include
for x in string stdio stdlib ...; do
touch include/$x.h
done In which case the Let me know what else you need! |
This is really awesome, thanks! With the new float formatting and the math functions I was able to rebuild Wren with only a couple of makefile changes and name clashes. We're down to only 15 tests failing. I'll take a look at exactly why they're failing a bit later on and report back. The touching of empty headers is the approach I was taking, and it seems to work well for most projects. Just a little script to touch the standard ISO C set plus a few of the POSIX ones should get people a long way. |
Next problem was formatting hex numbers, which should be fixed in the PR I just opened. Now we are down to just 3 errors in the Wren test suite. |
Nice. I like this Wren language. Can't wait to see it up and running. Thanks again for the PR. I've now configured Travis to provide build/test feedback on any future ones you send. The latency is two minutes, which is pretty good, if we consider that it needs to compile and run about 400 executables. |
It's all looking pretty good now with the changes from #107 and #110, just two more errors to pin down:
Both of these are to do with parsing a ridiculously large number. I'm still not convinced my changes for I don't think this language is worthy of being included in the distro, since it's a fair bit bigger (and a lot less popular) than Lua, but I agree that it's kind of nice to see a clean OO scripting language compile pretty simply against Cosmopolitan. Their |
One thing worth noting is that other libraries define intmax as long but we define it as the standard says which is the largest integer type supported by the compiler. I'll take a look too and see if I can further test the implementation a bit. |
What you did appears correct so far. It helps if you encode two's complement bane in its unreadable decimal form: errno = 0;
EXPECT_EQ(0x7fffffffffffffff, strtol("0x8000000000000000", NULL, 0));
EXPECT_EQ(ERANGE, errno);
errno = 0;
EXPECT_EQ(0x8000000000000000, strtol("-0x8000000000000001", NULL, 0));
EXPECT_EQ(ERANGE, errno);
errno = 0;
EXPECT_EQ(0x8000000000000001, strtol("-9223372036854775807", NULL, 0));
EXPECT_EQ(0, errno);
errno = 0;
EXPECT_EQ(0x8000000000000000, strtol("-9223372036854775808", NULL, 0));
EXPECT_EQ(0, errno); I was a little unhappy when I first learned about that. I came to the conclusion that negative numbers and hexadecimal are dangerous when put the two together and I've sought to avoid that ever since. |
Hmm, this is interesting, it seems that For this file: #ifdef NO_COSMO
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#endif
int main() {
errno = 0;
double d = strtod("9007199254740992", NULL);
printf("d = %g errno = %d\n", d, errno);
double d2 = strtod("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", NULL);
printf("d2 = %g errno = %d\n", d2, errno);
} Compiled with and without Cosmopolitan:
So, the outstanding error of Wren seems to be |
Right now the build is configured with |
Perfect! Removing I wonder if we should
It'd have to be a pretty awesome Whatever we decide to do with the With regard to the name clashes, these were with standard functions |
Thanks for the work on this btw, I've been following Cosmopolitan and it's nice to see Wren making it's way there relatively painlessly! ✨ |
The -fno-math-errno flag shouldn't impact libraries since it's mostly intended for permitting the compiler to generate sqrt() instructions.
Thank you for pointing out the GCC doc. It's pretty clear in that case the flag is intended to let the compiler emit Needing to not clash with standard library functions is a calculated tradeoff with the amalgamation header. I believe it should be possible to workaround in your build config, possibly by defining a wrapper header like this: /* cosmopolitan2.h */
#define remove __redacted_remove
#define write __redacted_write
#include "cosmopolitan.h"
#undef remove
#undef write Nice to meet you @ruby0x1. I hope Cosmopolitan proves beneficial to your work and helps it reach a broader audience. Using Cosmopolitan with Wren is painless as of today and we can thank @alisonatwork for that. For the past few years this project has been like a model train set for me, that many people have loved and encouraged so much that we're rapidly turning it into a high-speed rail. I appreciate all the support wrinkling out bugs and I hope you continue to follow its future going forward. |
@alisonatwork howdy! I wondered if you happened to transfer this repo elsewhere, or simply nuked it? If anyone can spot a fork, I'm interested ^__^ cc: @ruby0x1 |
Hi @shmup I don't have my Wren branch any more that I built with Cosmopolitan, but the reason I nuked it is because it was pretty trivial by the time this issue was closed. With the changes that were made in both projects, the build ran pretty much clean. By the sounds of it Cosmopolitan has come a long way in the past year, so it should be even easier now. If I recall the two main things I needed to do were:
Both are standard things required to get any project compiling with Cosmopolitan. If the Wren maintainer is open to the idea, it should be viable to add a whole separate target in |
Ah, just looking back through the Wren source code, I remember why I stopped work on my branch. The makefiles in |
FWIW, Premake is a nice tool and uses Lua for its scripts. |
Inspired by @ahgamut's work with Lua on #61 I thought I'd try compile Wren just for fun. It worked pretty well with just a few minor changes. I cloned here with my changes on the
cosmopolitan
branch: https://github.com/alisonatwork/wren/tree/cosmopolitanChanges required were:
#include <stdio.h>
and so onmodf
%g
format string problemif (trunc(f) == f) sprintf(s, "%ld", (long) f)
to at least get the int-ish doubles printing as expected and%f
for best-effort on the floaty doublesWith these changes, 797 tests pass and 42 fail. Almost all of these are format string related like this:
But there are a few suspicious ones that I still need to investigate.
For now, the great news is that this language almost completely works!
The bug reports:
modf
missing%g
format stringRequests for input:
#ifdef __COSMOPOLITAN__
everywhere?The text was updated successfully, but these errors were encountered: