Commit Graph

230 Commits

Author SHA1 Message Date
hryx e07888e54c expr: FunctionToPointerDecay & ArrayToPointerDecay for ImplicitCastExpr 2019-05-27 18:18:27 -07:00
hryx 22299869ba Prevent infinite recursion 2019-05-27 17:54:40 -07:00
hryx e1f3eec9cc Merge branch 'master' into translate-c-userland 2019-05-27 17:24:21 -07:00
Andrew Kelley 3fccc07479 self-hosted translate-c: fix bad memory arena references 2019-05-27 20:22:15 -04:00
hryx 2aa1c5da5d Remove unused local struct type 2019-05-27 15:58:21 -07:00
hryx 3bbee1ba2e expr: BitCast for ImplicitCastExpr 2019-05-27 14:38:09 -07:00
Andrew Kelley 0c6ab61b22 tests passing on linux 2019-05-26 23:35:26 -04:00
hryx 9c437f9032 var decl: ImplicitCastExpr 2019-05-26 19:14:50 -07:00
hryx 1a8f8c6262 var decl: init node 2019-05-26 17:36:47 -07:00
hryx c79b8aeaef var decl: threadlocal 2019-05-26 17:05:49 -07:00
hryx 99f0b28d39 var decl: mut_token, create child scope 2019-05-26 16:51:25 -07:00
hryx fceedada5c WIP translate var decl 2019-05-26 15:43:13 -07:00
Andrew Kelley 2f040a23c8 clean up references to os 2019-05-26 18:32:44 -04:00
Andrew Kelley 5a57610039 clean up code now that #769 is implemented 2019-05-14 19:23:31 -04:00
hryx 3a3a738478 Recursive rewrite of stage2 parser, part 3 2019-05-12 02:01:45 -07:00
Andrew Kelley 10e9d47b49 stage2 translate-c: implement functions with no prototype
stage1 translate-c actually has this wrong. When exporting a function,
it's ok to use empty parameters. But for prototypes, "no prototype"
means that it has to be emitted as a function that accepts anything,
e.g. extern fn foo(...) void;

See #1964
2019-05-11 12:09:11 -04:00
Andrew Kelley 5f4c3e6557 stage2 translate-c: simple function definitions
See #1964
2019-05-10 23:35:46 -04:00
Andrew Kelley dbb5da14f4 stage2 translate-c: builtin types and pub
See #1964
2019-05-10 17:56:00 -04:00
Andrew Kelley 82219b1fd5 translate-c: better handling of restore points 2019-05-10 17:44:47 -04:00
Andrew Kelley a6f7a9ce2b translate-c: we have our first test of self-hosted
See #1964
2019-05-10 16:03:54 -04:00
Andrew Kelley 1c0223899c translate-c: progress on self-hosted function prototypes
See #1964
2019-05-10 01:24:00 -04:00
Andrew Kelley eea2de108d translate-c: progress on self-hosted function prototypes
See #1964
2019-05-09 16:52:30 -04:00
Andrew Kelley 46e1c34fcf self-hosted translate-c progress on function decls
See #1964
2019-05-08 22:05:59 -04:00
Andrew Kelley 9bbd71c9ab add --bundle-compiler-rt function to link options
and use it when building libuserland.a

The self-hosted part of stage1 relies on zig's compiler-rt, and so we
include it in libuserland.a.

This should potentially be the default, but for now it's behind a linker
option.

self-hosted translate-c: small progress on translating functions.
2019-05-08 20:51:49 -04:00
Andrew Kelley a7f99c8ee9 self-hosted translate-c: iterate over top level decls
See #1964
2019-04-30 00:21:45 -04:00
Shritesh Bhattarai d02489fd9a fix missing semicolon 2019-04-26 21:01:20 -04:00
Andrew Kelley 2d6520d5d4 zig fmt is built directly into stage1 rather than child process
Previously, `zig fmt` on the stage1 compiler (which is what we currently
ship) would perform what equates to `zig run std/special/fmt_runner.zig`

Now, `zig fmt` is implemented with the hybrid zig/C++ strategy outlined
by #1964.

This means Zig no longer has to ship some of the stage2 .zig files, and
there is no longer a delay when running `zig fmt` for the first time.
2019-04-26 20:46:28 -04:00
Andrew Kelley 28071ac637 self-hosted translate-c emits a hello world AST
Also breaking std lib API change: the return value of
std.zig.parse returns `*ast.Tree` rather than `ast.Tree`.

See #1964
2019-04-26 15:43:36 -04:00
Andrew Kelley 535d419590 translate-c: self-hosted implementation can detect C errors
See #1964
2019-04-25 00:06:58 -04:00
Andrew Kelley 712274997e translate-c: unify API for self-hosted and C++ translate-c
See #1964
2019-04-25 00:06:57 -04:00
Andrew Kelley 976080462c translate-c: a little closer to self-hosted implementation 2019-04-25 00:06:54 -04:00
Andrew Kelley ff3cdbc3a0 stage1 assertions always on, and have stack traces 2019-04-17 15:58:20 -04:00
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
Marc Tiehuis 78af62a19a Pack big.Int sign and length fields
This effectively takes one-bit from the length field and uses it as the
sign bit. It reduces the size of an Int from 40 bits to 32 bits on a
64-bit arch.

This also reduces std.Rational from 80 bits to 64 bits.
2019-04-11 19:36:35 +12:00
Andrew Kelley d0551db5cd introduce the enum literal type
see #683
2019-03-24 00:44:18 -04:00
Andrew Kelley 64dddd7afe add compile error for ignoring error
closes #772
2019-03-23 19:33:00 -04:00
Andrew Kelley a581f4f0e2 Merge remote-tracking branch 'origin/master' into llvm8 2019-03-18 20:03:23 -04:00
Andrew Kelley 9c13e9b7ed breaking changes to std.mem.Allocator interface API
Before, allocator implementations had to provide `allocFn`,
`reallocFn`, and `freeFn`.

Now, they must provide only `reallocFn` and `shrinkFn`.
Reallocating from a zero length slice is allocation, and
shrinking to a zero length slice is freeing.

When the new memory size is less than or equal to the
previous allocation size, `reallocFn` now has the option
to return `error.OutOfMemory` to indicate that the allocator
would not be able to take advantage of the new size.

For more details see #1306. This commit closes #1306.

This commit paves the way to solving #2009.

This commit also introduces a memory leak to all coroutines.
There is an issue where a coroutine calls the function and it
frees its own stack frame, but then the return value of `shrinkFn`
is a slice, which is implemented as an sret struct. Writing to
the return pointer causes invalid memory write. We could work
around it by having a global helper function which has a void
return type and calling that instead. But instead this hack will
suffice until I rework coroutines to be non-allocating. Basically
coroutines are not supported right now until they are reworked as
in #1194.
2019-03-15 17:57:21 -04:00
Andrew Kelley 4cb55d3af6 Merge remote-tracking branch 'origin/master' into llvm8 2019-03-10 18:07:28 -04:00
Andrew Kelley 918dbd4551 std.zig: this is no longer a keyword 2019-03-10 15:55:54 -04: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 582fdc2869 fix dependency loops, pub, tests, use decls, root source
* fix dependency loop detection
   - closes #679
   - closes #1500
 * fix `pub`
 * fix tests
 * fix use decls
 * main package file gets a special "" namespace path
2019-03-01 15:35:29 -05:00
Andrew Kelley 0fd64e6c69 stage2: update for changes regarding sub-architecture 2019-02-28 14:10:45 -05:00
Andrew Kelley 5424b4320d remove namespace type; files are empty structs
closes #1047
2019-02-28 10:11:32 -05:00
Andrew Kelley 2dcf1a2392 Merge remote-tracking branch 'origin/master' into llvm8 2019-02-28 09:19:18 -05:00
Andrew Kelley 33174f11ef fix regressions on Windows 2019-02-26 16:24:32 -05:00
Andrew Kelley ade10387a5 breaking changes to the way targets work in zig
* CLI: `-target [name]` instead of `--target-*` args.
   This matches clang's API.
 * `builtin.Environ` renamed to `builtin.Abi`
   - likewise `builtin.environ` renamed to `builtin.abi`
 * stop hiding the concept of sub-arch. closes #1526
 * `zig targets` only shows available targets. closes #438
 * include all targets in readme, even those that don't
   print with `zig targets` but note they are Tier 4
 * refactor target.cpp and make the naming conventions
   more consistent
 * introduce the concept of a "default C ABI" for a given
   OS/Arch combo. As a rule of thumb, if the system compiler
   is clang or gcc then the default C ABI is the gnu ABI.
2019-02-26 15:58:10 -05:00
Andrew Kelley c9fb5240d6 remove --no-rosegment workaround now that valgrind bug is fixed
See #896

Zig 0.3.0+ and Valgrind 3.14+ do not need the workaround.
2019-02-19 08:39:36 -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