Commit Graph

1346 Commits

Author SHA1 Message Date
Andrew Kelley
21f344b3b9 add null terminated pointers and arrays to self-hosted
as well as `@typeInfo` and `@Type`
2019-11-21 20:43:41 -05:00
LemonBoy
a11da37734 Update discriminant value also for zero-sized unions
Fixes #3681
2019-11-14 17:07:20 +00:00
Andrew Kelley
d89f39d719 rework layout of struct type fields
This removes the remaining hack in the implementation of anonymous
struct literals, and they can now therefore now have greater than 16
fields/elements.
2019-11-14 03:52:39 -05:00
Andrew Kelley
f2f698a888 rework comptime struct value layout, removing 1/2 hacks
in the implementation of anonymous struct literals
2019-11-14 03:52:36 -05:00
Andrew Kelley
8bae70454d Merge pull request #3675 from Vexu/atomic-store
Add @atomicStore builtin
2019-11-13 03:06:55 +00:00
Andrew Kelley
32b37e695a fix anonymous struct literal assigned to variable
closes #3667
2019-11-12 21:57:25 -05:00
Andrew Kelley
37318bf151 fn parameters participate in result location semantics
See #3665
2019-11-12 18:55:17 -05:00
Vexu
110ef2e528 add @atomicStore builtin 2019-11-13 00:25:44 +02:00
Andrew Kelley
bf8870a60b fix unresolved type making it to codegen
found this trying to build oxid
2019-11-11 22:11:22 -05:00
Andrew Kelley
2a6fbbd8fb introduce @as builtin for type coercion
This commit also hooks up type coercion (previously called implicit
casting) into the result location mechanism, and additionally hooks up
variable declarations, maintaining the property that:

    var a: T = b;

is semantically equivalent to:

    var a = @as(T, b);

See #1757
2019-11-08 15:57:24 -05:00
Shawn Landden
2e52fafac5 correctly use llvm undef in release modes 2019-11-07 02:51:04 -05:00
LemonBoy
528908a06e Fix ptrCast of array references to fn
Closes #3607
2019-11-07 02:46:10 -05:00
Andrew Kelley
cbaa10fc3b implement storing vector elements via runtime index 2019-11-05 12:11:57 -05:00
Andrew Kelley
70be308c43 implement loading vector elements via runtime index 2019-11-05 12:11:40 -05:00
Andrew Kelley
76d188551e implement store of vector element with comptime index 2019-11-05 12:11:18 -05:00
Andrew Kelley
55e54d98c4 runtime load vector element with comptime index 2019-11-05 12:11:16 -05:00
Andrew Kelley
4f594527c0 detect async fn recursion and emit compile error 2019-10-28 15:10:48 -04:00
Andrew Kelley
f2d0d9820d synchronize the target features for compiling C code
d91fc0fdd8 changed zig's behavior to
disable the SSE feature when cross compiling for i386-freestanding.

This commit does the same when compiling C Code.
2019-10-28 14:37:32 -04:00
Noam Preil
d91fc0fdd8 Don't use SSE on freestanding 2019-10-26 16:46:43 -04:00
Noam Preil
b8305b5648 Don't save/restore stack on newStackCall to noreturn function 2019-10-26 16:45:46 -04:00
Timon Kruiper
d04c58816d Translate-c: Fix a segfault when to many errors are emitted
This was already fixed when doing `@cImport`, but not yet when
running `zig translate-c`.
2019-10-26 13:09:23 -04:00
Michael Dusan
3aeb1b115d stage1: fix compile error on macOS Xcode 11.2
src/codegen.cpp:7713:33: error: unused variable 'global_linkage_values' [-Werror,-Wunused-const-variable]
static const GlobalLinkageValue global_linkage_values[] = {
2019-10-25 17:49:01 -04:00
Andrew Kelley
ad438a95c5 avoid passing -march=native when not supported
Clang does not support -march=native for all targets.
Arguably it should always work, but in reality it gives:
error: the clang compiler does not support '-march=native'
If we move CPU detection logic into Zig itelf, we will not need this,
instead we will always pass target features and CPU configuration explicitly.
For now, we simply avoid passing the flag when it is known to not be
supported.
2019-10-24 19:43:56 -04:00
Andrew Kelley
f8bd1cd3b1 implement partial C ABI support for aarch64 2019-10-24 19:13:21 -04:00
Andrew Kelley
17eb24a7e4 move types from builtin to std
* All the data types from `@import("builtin")` are moved to
  `@import("std").builtin`. The target-related types are moved
  to `std.Target`. This allows the data types to have methods, such as
  `std.Target.current.isDarwin()`.
 * `std.os.windows.subsystem` is moved to
   `std.Target.current.subsystem`.
 * Remove the concept of the panic package from the compiler
   implementation. Instead, `std.builtin.panic` is always the panic
   function. It checks for `@hasDecl(@import("root"), "panic")`,
   or else provides a default implementation.

This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 19:09:49 -04:00
Andrew Kelley
e98e5dda52 implement safety for resuming non-suspended function
closes #3469
2019-10-22 23:43:27 -04:00
Andrew Kelley
f65b1d4680 integrate stage1 progress display with semantic analysis 2019-10-22 17:52:12 -04:00
LemonBoy
bab93e7561 Fix crash when generating constant unions with single field 2019-10-19 13:47:49 -04:00
Andrew Kelley
2d5b2bf1c9 improve progress reporting
* use erase rest of line escape code.
 * use `stderr.supportsAnsiEscapeCodes` rather than `isTty`.
 * respect `--color off`
 * avoid unnecessary recursion
 * add `Progress.log`
 * disable the progress std lib test since it's noisy and uses
   `time.sleep()`.
 * enable/integrate progress printing with the default test runner
2019-10-17 21:55:49 -04:00
Andrew Kelley
299991019d rework the progress module and integrate with stage1 2019-10-17 20:20:22 -04:00
Andrew Kelley
9050cd847a fix non-byte-aligned packed struct field...
...passed as generic fn parameter causing invalid LLVM IR.

closes #3460
2019-10-15 18:00:16 -04:00
Andrew Kelley
30a555eed4 merge dumps tool: merging ast nodes
-fgenerate-docs is replaced ith -femit-docs
-fno-emit-bin is added to prevent outputting binary
2019-10-11 18:13:24 -04:00
Andrew Kelley
7b20205e68 codegen.cpp: remove unused variable 2019-10-10 21:24:44 -04:00
LemonBoy
9ae293ae3b Remove x86/Windows name mangling hack
Let's fix this properly by generating the correct lib files from the
mingw sources.
2019-10-09 22:44:36 +02:00
Andrew Kelley
a5714ddb97 add comments about why we choose pentium4 for i386 target
See #3389
2019-10-09 15:06:37 -04:00
Andrew Kelley
2286003666 improve names of error sets when using merge error sets operator 2019-10-09 13:35:19 -04:00
Andrew Kelley
f929a58d5f Merge pull request #3389 from LemonBoy/win32
Win32
2019-10-09 13:22:16 -04:00
Andrew Kelley
86171afb9b generated docs: docs/ instead of doc/
This appears to be more of a standard directory name.

See #21
2019-10-06 14:48:01 -04:00
LemonBoy
93a49076f7 Initial support for i386-windows-msvc target 2019-10-06 14:27:36 +02:00
Andrew Kelley
dca6e74fec proof of concept of stage1 doc generation
This commit adds `-fgenerate-docs` CLI option, and it outputs:
 * doc/index.html
 * doc/data.js
 * doc/main.js

In this strategy, we have 1 static html page and 1 static javascript
file, which loads the semantic analysis dump directly and renders it
using dom manipulation.

Currently, all it does is list the declarations. But there is a lot more
data available to work with. The next step would be making the
declarations hyperlinks, and handling page navigation.

Another strategy would be to generate a static site with no javascript,
based on the semantic analysis dump that zig now provides. I invite the
Zig community to take on such a project. However this version which
heavily relies on javascript will also be a direction explored.

I also welcome contributors to improve the html, css, and javascript of
what this commit started, as well as whatever improvements are necessary
to the static analysis dumping code to provide more information.

See #21.
2019-10-04 20:18:06 -04:00
Andrew Kelley
071af5c1d6 fix noreturn attribute for msvc 2019-10-03 22:51:00 -04:00
Andrew Kelley
59ac7b91da add -fdump-analysis to dump type information to json
This commit adds -fdump-analysis which creates
a `$NAME-analysis.json` file with all of the finished
semantic analysis that the stage1 compiler produced.
It contains types, packages, declarations, and files.

This is an initial implementation; some data will be
missing. However it's easy to improve the implementation,
which is in `src/dump_analysis.cpp`.

The next step for #21 will be to create Zig code which parses
this json file and creates user-facing HTML documentation.

This feature has other uses, however; for example, it could
be used for IDE integration features until the self-hosted
compiler is available.
2019-10-03 17:58:22 -04:00
Andrew Kelley
a8d6954c23 fix tripping LLVM assertion in const unions 2019-10-01 17:41:03 -04:00
Andrew Kelley
339f621735 detect the shared windows include dir as well 2019-09-29 14:12:06 -04:00
Andrew Kelley
c8e967f43d detect the windows um include directory 2019-09-29 14:04:23 -04:00
Andrew Kelley
dc7016344e remove --override-std-dir. fix issues caused by moving std lib 2019-09-25 23:59:07 -04:00
Andrew Kelley
53210b2304 better default enabled features for riscv
Until ability to specify target CPU features (#2883) is done, this
commit gives riscv target better default features.

This side-steps #3275 which is a deficiency in compiler-rt when features
do not include 32 bit integer division.

With this commit, RISC-V compiler-rt tests pass and Hello World works
both pure-zig and with musl libc.
2019-09-24 20:56:04 -04:00
Jay Weisskopf
0bdc85181c Create user-specified output-dir
Fixes #2637
2019-09-24 00:20:29 -04:00
Andrew Kelley
f3a7c346dd Merge pull request #3278 from LemonBoy/struct-gen
A few steps towards AArch64 & ARM passing the behavior tests
2019-09-21 13:46:13 -04:00
LemonBoy
093ffe9f16 Correct stack alignment for new stack 2019-09-21 11:39:50 +02:00