Commit Graph

4753 Commits (8ce130de3cf38e09cfbcbd1b22da34ae5b27a040)

Author SHA1 Message Date
Andrew Kelley 22dd0db9bf
improve docs for unions and switching on tagged unions
closes #1943
2019-02-26 22:57:01 -05:00
Andrew Kelley 0d48011f5e fix stage1 zig fmt on macos 2019-02-26 21:33:46 -05:00
Andrew Kelley 557983e502
fix handling when there are multiple externs and
an export in the same object

closes #529
2019-02-26 19:43:12 -05:00
Andrew Kelley 763357c9c3
add test coverage for type used as switch case
closes #996
2019-02-26 19:41:36 -05:00
Andrew Kelley d5fc826437
add test coverage for binary OR on error sets
closes #1074
2019-02-26 19:34:22 -05:00
Andrew Kelley 1d7e5479b0
fix .gitignore file and add commit missing std lib file 2019-02-26 18:33:27 -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
Andrew Kelley 6365f5a9f3 introduce sys_include_dir for when sys/* files are not with stdlib.h 2019-02-26 17:26:34 -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 1ec1097bd3
use -nostdinc and sometimes -nolibc when compiling C code 2019-02-26 14:59:36 -05:00
John Schmidt 0eed72d687 Add priority queue 2019-02-26 13:21:11 -05:00
Andrew Kelley 6fd2816431
use -nostdinc++ when compiling C code 2019-02-26 10:15:48 -05:00
Andrew Kelley 3932b6474e
use -nobuiltininc when compiling c code 2019-02-26 08:16:03 -05:00
Andrew Kelley 82fafca375 fix the libc compile error tests to only run on linux 2019-02-25 21:46:32 -05:00
Andrew Kelley 7571db05de
fix incorrectly trying to memset at comptime
closes #718
2019-02-25 20:33:40 -05:00
Andrew Kelley 4b7e285b76
add a regression test for #704
closes #704
2019-02-25 20:18:35 -05:00
Andrew Kelley 152db27146
better error message when forgetting to link against libc
closes #1698
2019-02-25 20:09:18 -05:00
Andrew Kelley 3ca861c7dd
add a compile error note when C import fails and not linking libc
closes #558
2019-02-25 19:31:30 -05:00
Andrew Kelley 0f54728cf0
fix not finding libgcc_s when looking for native libc
closes #2011
2019-02-25 19:10:48 -05:00
Andrew Kelley aab8e13529
add docs for zero bit types and pointers to zero bit types
closes #1561
2019-02-25 18:31:37 -05:00
Andrew Kelley 39605a7965
delete incorrect TODO comment
The code path is tested by behavior tests.

Thanks to various contributors, but mostly Marc Tiehuis,
bigint.cpp now has full coverage.

closes #405
2019-02-25 16:36:18 -05:00
Andrew Kelley 7b8c5578c6
fix infinite recursion in type_has_one_possible_value
closes #2006
2019-02-25 16:28:23 -05:00
Andrew Kelley 33cbb29def
zig build: 2 improvements
* `linkLibrary` will make the target depend on libc if the source does
 * when building C source file(s), don't try to generate .h files
2019-02-25 14:27:03 -05:00
Andrew Kelley 6003b1ea70
Merge pull request #2005 from ziglang/c-source
first class support for compiling C code
2019-02-25 14:11:54 -05:00
Andrew Kelley 0d4db8828a
`@cImport` works with `--cache on`
We pass -MD -MF args to clang when doing `@cImport`, which
gives us a complete list of files that the C code read from.
Then we add these to the cache. So even when using `@cImport`
Zig's caching system remains perfect. This is a proof of concept
for the mechanism that the self-hosted compiler will use to
watch and rebuild files.
2019-02-25 14:03:36 -05:00
Andrew Kelley 525c2eaf5d building DLLs on Windows works better 2019-02-25 13:34:25 -05:00
Andrew Kelley e76ce2c1d0
first class support for compiling C code
New CLI parameter: --c-source [options] [file]

It even works with `--cache on` when there are transitive dependencies.

Instead of `builder.addCExecutable`, use `builder.addExecutable` and pass
`null` for the root source file. Then use `builder.addCSourceFile`,
which takes the path to the C code, and a list of C compiler args.
Be sure to linkSystemLibrary("c") if you want libc headers to be
available.

Merge TestStep into LibExeObjStep. That was long overdue.
2019-02-25 11:45:00 -05:00
Andrew Kelley e5d4862e14
Merge pull request #2003 from ziglang/zig-cc
add `zig cc` command to act like a C compiler
2019-02-24 16:28:49 -05:00
Andrew Kelley 8c2c6368f9
zig cc: work around clang calling GetCommandLine on Windows 2019-02-24 15:31:02 -05:00
Andrew Kelley bcca76b3c4 zig cc: remove "polly" which was an undefined symbol on macos 2019-02-24 13:37:41 -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 98869edb8b
fix `zig fmt` arg0 handled incorrectly 2019-02-23 20:25:33 -05:00
Andrew Kelley 00d8f4a1bb
introduce std.debug.captureStackTrace
and fix the implementation of writeStackTrace
it was printing the first frame in the wrong place
2019-02-23 13:19:06 -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
Andrew Kelley 52bb71867d
implement vector negation
also fix vector behavior tests, they weren't actually testing
runtime vectors, but now they are.

See #903
2019-02-22 13:28:57 -05:00
Andrew Kelley 2fe8a0831f
add regression test for bitcast to array
closes #421
2019-02-22 11:09:17 -05:00
Andrew Kelley d0c39895aa
docs for packed structs
closes #1513
2019-02-22 10:56:49 -05:00
Andrew Kelley 0c5f897904
fix `@bitCast` when src/dest types have mismatched handle_is_ptr
* separate BitCast and BitCastGen instructions
 * closes #991
 * closes #1934
 * unrelated: fix typo in docs (thanks gamester for pointing it out)
2019-02-22 08:49:27 -05:00
Andrew Kelley cbce61a209
better field access of types which have one possible value
* When you do field access of a type which only has one possible
   value, the result is comptime-known.
 * StorePtr instructions which operate on pointers to types which
   only have one possible value, the result is a comptime no-op.

closes #1554
2019-02-21 16:09:14 -05:00
Andrew Kelley 1066004b79
better handling of arrays in packed structs
* Separate LoadPtr IR instructions into pass1 and pass2 variants.
 * Define `type_size_bits` for extern structs to be the same as
   their `@sizeOf(T) * 8` and allow them in packed structs.
 * More helpful error messages when trying to use types in
   packed structs that are not allowed.
 * Support arrays in packed structs even when they are not
   byte-aligned.
 * Add compile error for using arrays in packed structs when the
   padding bits would be problematic. This is necessary since
   we do not have packed arrays.

closes #677
2019-02-21 14:44:14 -05:00
Andrew Kelley 2bb795dc45
`@sliceToBytes` works at comptime
closes #262
2019-02-21 10:07:11 -05:00
Andrew Kelley db31c2524d
extern structs support comptime bitcasting 2019-02-21 08:46:43 -05:00
Andrew Kelley 3ee9d06cbd
packed structs support comptime bitcasting
* `type_size_store` is no longer a thing. loading and storing a pointer
   to a value may dereference up to `@sizeOf(T)` bytes, even for
   integers such as `u24`.
 * fix `types_have_same_zig_comptime_repr` to not think that the
   same `ZigTypeId` means the `ConstExprValue` neccesarily has the
   same representation.
 * implement `buf_write_value_bytes` and `buf_read_value_bytes` for
   `ContainerLayoutPacked`

closes #1120
2019-02-20 22:40:41 -05:00
daurnimator 7bbccfc7f3
Use valgrind marks from Allocator 2019-02-21 11:43:09 +11:00
Andrew Kelley 079728752e
deduplicate compile errors for undeclared identifiers
closes #111
2019-02-20 08:04:46 -05:00
daurnimator d68ae35c11
std: when a FixedBufferAllocator is initialised, set the buffer to undefined 2019-02-20 16:52:23 +11:00
daurnimator da7880b4cf
std: Add valgrind module 2019-02-20 16:52:20 +11:00
Andrew Kelley 067968c57f
Merge branch 'matthew-mcallister-slice-deref-failure' 2019-02-19 15:35:00 -05:00
Andrew Kelley c8ce351ec9
pull request fixups 2019-02-19 15:34:44 -05:00