Commit Graph

332 Commits (bc2d60c11f7e90f401a4412d3dc6fca985071169)

Author SHA1 Message Date
Andrew Kelley 89763c9a0d
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.

Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.

Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.

Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.

As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).

This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.

This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.

See #1964
2019-04-16 19:12:20 -04:00
Shritesh Bhattarai 93d43d4529 wasi: add std/os/wasi{,/core}.zig to CMakeLists.txt 2019-04-13 22:51:18 -05:00
Marc Tiehuis 5f4fcd5030 Add initial big.Rational type 2019-04-11 19:36:35 +12:00
Andrew Kelley bddbbef32b
Release 0.4.0 2019-04-08 15:41:41 -04:00
vegecode d72239d339 Add divdf3 to compiler_rt
Also adds __aeabi_ddiv for arm32 targets
2019-04-05 18:10:19 -04:00
Andrew Kelley 1dc6751721
fix NaN comparing equal to itself
This was broken both in comptime code and in runtime code.

closes #1174
2019-04-04 22:07:15 -04:00
Andrew Kelley be0f656c21
fix `@divFloor` returning incorrect value and add `__modti3`
Closes #2152
See #1290
2019-04-04 15:45:37 -04:00
vegecode 12c4ab3927 Add divsf3 to compiler rt 2019-04-04 15:38:09 -04:00
vegecode 779137be41 Add __aeabi_{f,d}neg and __neg{s,d,X}f2 to compiler-rt 2019-03-31 15:54:02 -05:00
emekoi cf4e9a27c5 removed static build flags on mingw 2019-03-27 12:49:26 -04:00
Andrew Kelley d83836825f
add mulXf3 to compiler-rt
this adds the following functions to compiler-rt:

 * `__mulsf3`
 * `__muldf3`
 * `__multf3`

See #1290
2019-03-22 17:46:49 -04:00
Shawn Landden b76398c993 std: add ascii with C ASCII character classes
Does NOT look at the locale the way the C functions do.

       int isalnum(int c);
       int isalpha(int c);
       int iscntrl(int c);
       int isdigit(int c);
       int isgraph(int c);
       int islower(int c);
       int isprint(int c);
       int ispunct(int c);
       int isspace(int c);
       int isupper(int c);
       int isxdigit(int c);

       int isascii(int c);
       int isblank(int c);

       int toupper(int c);
       int tolower(int c);

Tested to match glibc (when using C locale) with this program:

const c = @cImport({
    // See https://github.com/ziglang/zig/issues/515
    @cDefine("_NO_CRT_STDIO_INLINE", "1");
    @cInclude("stdio.h");
    @cInclude("string.h");
    @cInclude("ctype.h");
});

const std = @import("std");
const ascii = std.ascii;
const abort = std.os.abort;

export fn main(argc: c_int, argv: **u8) c_int {
    var i: u8 = undefined;
    i = 0;
    while (true) {
        if (ascii.isAlNum(i) != (c.isalnum(i) > 0)) { abort(); }
        if (ascii.isAlpha(i) != (c.isalpha(i) > 0)) { abort(); }
        if (ascii.isCtrl(i) != (c.iscntrl(i) > 0)) { abort(); }
        if (ascii.isDigit(i) != (c.isdigit(i) > 0)) { abort(); }
        if (ascii.isGraph(i) != (c.isgraph(i) > 0)) { abort(); }
        if (ascii.isLower(i) != (c.islower(i) > 0)) { abort(); }
        if (ascii.isPrint(i) != (c.isprint(i) > 0)) { abort(); }
        if (ascii.isPunct(i) != (c.ispunct(i) > 0)) { abort(); }
        if (ascii.isSpace(i) != (c.isspace(i) > 0)) { abort(); }
        if (ascii.isUpper(i) != (c.isupper(i) > 0)) { abort(); }
        if (ascii.isXDigit(i) != (c.isxdigit(i) > 0)) { abort(); }
        if (i == 255) { break; }
        i += 1;
    }

    _ = c.printf(c"Success!\n");
    return 0;
}
2019-03-22 16:25:56 -04:00
Andrew Kelley 4615ed5ea0
float literals now parse using musl's 128 bit float code
fixes float literals not having 128 bit precision
2019-03-22 14:56:03 -04:00
Andrew Kelley a581f4f0e2
Merge remote-tracking branch 'origin/master' into llvm8 2019-03-18 20:03:23 -04:00
Andrew Kelley db0e188f0e update macos static build for llvm8 2019-03-18 18:36:35 -04:00
Andrew Kelley 7dfbeca13e
libc: separate linux headers from musl/glibc 2019-03-18 13:47:59 -04:00
Andrew Kelley c8453454e1
add missing std lib file rb.zig to cmakelists.txt 2019-03-17 13:52:45 -04:00
Andrew Kelley d213708333
this empty import workaround no longer necessary 2019-03-13 14:13:09 -04:00
Andrew Kelley 54edbc6815 Merge remote-tracking branch 'origin/master' into llvm8 2019-03-13 12:56:58 -04:00
emekoi 1ed38a682e added z3 and fixed dynamic linker on mingw 2019-03-13 10:37:53 -04:00
Andrew Kelley c73cd05468
musl: remove files that have case conflicts 2019-03-13 01:00:12 -04:00
Andrew Kelley 9741b2aab4
avoid a string that is too long for msvc 2019-03-12 18:09:40 -04:00
Andrew Kelley 5570bc986b
remove accidental swap file 2019-03-12 17:44:03 -04:00
Andrew Kelley 62486c35a4
ability to build musl from source
bundles musl 1.1.21

See #514
2019-03-12 17:32:32 -04:00
Andrew Kelley 5734b7a37a
building musl start files from source 2019-03-12 13:18:52 -04:00
Andrew Kelley b7c331eb61
add musl headers 2019-03-12 10:30:12 -04:00
Andrew Kelley 5362ca204f
Merge branch 'valgrind' of https://github.com/daurnimator/zig into daurnimator-valgrind 2019-03-11 13:27:04 -04:00
Andrew Kelley 3cdd2c0bdd Merge remote-tracking branch 'origin/master' into llvm8 2019-03-10 13:48:06 -04:00
Andrew Kelley 8369ddb09c
glibc: add missing linux header 2019-03-09 01:24:30 -05:00
Jay Weisskopf cddc77dd97 Remove glibc compat shim with restrictive license
Unlike the other glibc source code checked into the repo, `csu/init.c`
did not have a license clause that allowed linking without restrictions.

`_IO_stdin_used` is the only symbol in the file and appears to be a 20
year old compatibility shim for the glibc 2.0 ABI. Obsolete in 2.1.
2019-03-08 08:46:06 -05:00
Andrew Kelley ce76de35f1
multi-arch glibc headers 2019-03-07 12:16:10 -05:00
Andrew Kelley 697b1233f0
support other architectures for glibc startup files 2019-03-06 12:10:03 -05:00
Andrew Kelley b554f6294f
add popcountdi2 to compiler_rt 2019-03-05 23:09:00 -05:00
Andrew Kelley ba144b366c
build libunwind.a from source and link it 2019-03-05 22:45:41 -05:00
Andrew Kelley 4c386436ea
support glibc dl, m, pthread, rt 2019-03-05 18:17:22 -05:00
Andrew Kelley c5fdea59d3
building glibc from source 2019-03-05 13:26:59 -05:00
Andrew Kelley aeb16010f3
initial glibc support 2019-03-04 22:15:53 -05:00
Andrew Kelley 0714e19598
Merge remote-tracking branch 'origin/master' into llvm8 2019-03-04 08:24:56 -05:00
Andrew Kelley e402455704
rename std lib files to new convention 2019-03-02 16:46:04 -05:00
Andrew Kelley 67b4de33d2
compile error for import outside package path
closes #2024

there's a new cli option `--main-pkg-path` which you can use to choose
a different root package directory besides the one inferred from the
root source file

and a corresponding build.zig API:
foo.setMainPkgPath(path)
2019-03-02 10:38:27 -05:00
Andrew Kelley 2dcf1a2392
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-28 09:19:18 -05:00
Andrew Kelley 4563f6b424
add builder.addFmt API and use it to test stage1 zig fmt
closes #1968
2019-02-26 18:10:40 -05:00
John Schmidt 0eed72d687 Add priority queue 2019-02-26 13:21:11 -05:00
Andrew Kelley a77a17e2c2
add `zig cc` command to act like a C compiler
closes #490
2019-02-24 12:53:28 -05:00
Andrew Kelley 6fd8d455bc
better libc detection (#1996)
* better libc detection

This introduces a new command `zig libc` which prints
the various paths of libc files. It outputs them to stdout
in a simple text file format that it is capable of parsing.
You can use `zig libc libc.txt` to validate a file.

These arguments are gone:
--libc-lib-dir [path]        directory where libc crt1.o resides
--libc-static-lib-dir [path] directory where libc crtbegin.o resides
--msvc-lib-dir [path]        (windows) directory where vcruntime.lib resides
--kernel32-lib-dir [path]    (windows) directory where kernel32.lib resides

Instead we have this argument:
--libc [file]                Provide a file which specifies libc paths

This is used to pass a libc text file (which can be generated with
`zig libc`). So it is easier to manage multiple cross compilation
environments.

`--cache on` now works when linking against libc.

`ZigTarget` now has a bool field `is_native`

Better error messaging when you try to link against libc or use
`@cImport` but the various paths cannot be found. It should also be
faster.

* save native_libc.txt in zig-cache

This avoids having to detect libc at runtime on every invocation.
2019-02-23 09:35:56 -05:00
daurnimator da7880b4cf
std: Add valgrind module 2019-02-20 16:52:20 +11:00
Andrew Kelley 3e586264e5
Merge pull request #1972 from coypoop/netbsd
Add NetBSD support
2019-02-18 00:10:31 -05:00
Maya Rashish bc10382ec1 Add NetBSD support
Mostly picking the same paths as FreeBSD.
We need a little special handling for crt files, as netbsd uses its
own (and not GCC's) for those, with slightly different names.
2019-02-17 09:17:34 +02:00
Andrew Kelley 356cfa08f4
translate-c: proof of concept for transitioning to userland
See #1964
2019-02-16 15:26:44 -05:00
Andrew Kelley ba56f365c8
bring zig fmt to stage1 2019-02-16 00:53:32 -05:00