Commit Graph

3179 Commits

Author SHA1 Message Date
Veikka Tuominen
4b72b0560d make remaining enums in build.zig snake_case 2021-06-11 16:01:30 +03:00
Felix (xq) Queißner
1c1ea2baa7 Code quality improvements to GeneratedFile, and manual implementation of Builder.addObjectSource. 2021-06-11 10:43:52 +03:00
Felix (xq) Queißner
27bd0971bb Changes to .path instead of .getPathFn. Changes LibExeObjStep to also provide FileSource. 2021-06-11 10:39:50 +03:00
Felix (xq) Queißner
07acb1ccc9 Changes createExecutable parameter is_dynamic to a enum to make code more readable . 2021-06-11 10:38:57 +03:00
Andrew Kelley
138afd5cbf zig fmt 2021-06-10 20:13:43 -07:00
LemonBoy
43a09f7efc stage1: Fix handling of C ABI parameters split in multiple regs
Take into account the increased number of parameters when flattening a
structure into one or more SSE registers.

Fixes #9061
2021-06-10 12:50:25 -04:00
daurnimator
916b645fc1 Have std.fmt functions take case as an enum 2021-06-10 08:33:42 +03:00
Jakub Konka
e8e305b67c Re-enable multiple wasm32 vector tests
Fixes #5339
2021-06-09 23:54:23 -04:00
Lee Cannon
629e2e7844
Add a logging allocator that uses std.log (#8511) 2021-06-09 21:42:07 +03:00
Lee Cannon
50822530d3
Provide method to set logging level per scope (#8584) 2021-06-09 12:23:45 +03:00
jacob gw
b57ac48773 stage2: compile error for ambiguous decl refrences
std: fix compile errors from this change. This is a stage1 bug.
2021-06-08 18:13:12 -04:00
Andrew Kelley
ccfa168284
Merge pull request #9030 from Vexu/stage2
Stage2: implement comptime variables
2021-06-08 14:16:57 -04:00
Matthew Borkowski
9ac6d28614 stage1: make @truncate to an integer type of different sign an error at comptime too 2021-06-08 20:58:30 +03:00
Veikka Tuominen
d41a5105cd stage2: fix repeat_inline skipping first instruction in block
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2021-06-08 10:15:34 +03:00
Jakub Konka
b0ee911c23 wasi: always grant fd_readdir right
Since v0.23 release of Wasmtime, if we want to iterate a directory
Y then directory Y needed to have been granted `fd_readdir` right.
However, it is now also required for directory X to carry `fd_readdir`
right, and so on, up-chain all the way until we reach the preopen
(which possesses all rights by default).

This caused problems for us since our libstd implementation is more
fine-grained and allowed for parent dirs not to carry the right while
allow for iterating on its children. My proposal here is to always
grant `fd_readdir` right as part of
`std.fs.Dir.OpenDirOptions.access_sub_paths`. This seems to be the
approach taken by Rust also, plus we should be justified to take this
approach since WASI is experimental and snapshot1 will be discontinued
eventually and replaced with a new approach to access management
that will require a complete rewrite of our libstd anyhow.
2021-06-08 05:48:33 +02:00
Veikka Tuominen
7efd7bc3b8 stage2: implement comptime variables 2021-06-07 22:15:56 +03:00
Evan Haas
fa6546ba74 translate-c: properly handle enums used as boolean expressions 2021-06-07 15:51:42 +03:00
LemonBoy
fc8791c133 stage1: Allow array-like initialization for tuple types
This small change makes working with tuple types much easier, allowing
the use of anonymous (eg. obtained with meta.ArgsTuple) tuples in more
places without the need for specifying each (quoted!) field name in the
initializer.
2021-06-06 21:21:42 -04:00
LemonBoy
616c82e446 Revert "tests: disable i386-linux-gnu -lc target due to CI failures"
This reverts commit 97a2f4e7ae.
2021-06-06 18:04:16 -07:00
Michael Dusan
0bda8435e0 test: re-enable dragonfly tests
Tests with LLVM assertions enabled are no longer failing.

closes #3563
2021-06-05 22:08:36 -04:00
Martin Wickham
fc9430f567 Breaking hash map changes for 0.8.0
- hash/eql functions moved into a Context object
- *Context functions pass an explicit context
- *Adapted functions pass specialized keys and contexts
- new getPtr() function returns a pointer to value
- remove functions renamed to fetchRemove
- new remove functions return bool
- removeAssertDiscard deleted, use assert(remove(...)) instead
- Keys and values are stored in separate arrays
- Entry is now {*K, *V}, the new KV is {K, V}
- BufSet/BufMap functions renamed to match other set/map types
- fixed iterating-while-modifying bug in src/link/C.zig
2021-06-03 17:02:16 -05:00
Veikka Tuominen
c6a0a4e728 translate-c: support designated initializers in macros 2021-06-01 23:40:43 -04:00
Isaac Freund
608bc1cbd5
stage2: disallow 1.e9 and 0x1.p9 as float literals
Instead require `1e9` and `0x1p9`, disallowing the trailing dot.

This change to the grammar is consistent with forbidding `1.` and `0x1.`
as float literals and ensures there is only one way to do things here.
2021-05-31 19:51:11 +00:00
Andrew Kelley
c12704a339
Merge pull request #8918 from ziglang/stage1-tokenizer
stage1: rework tokenizer to match stage2
2021-05-28 21:54:01 -04:00
Andrew Kelley
3f5ca3920a AstGen: properly restore previous state after temporary changes
Before this, if a compile error occurred, it would cause the previous
value for e.g. the function scope to not get reset. If the AstGen
process continued, it would result in a violation of the data
guarantees that it relies on.

This commit takes advantage of defer to ensure the previous value is
always reset, even in the case of an error.

Closes #8920
2021-05-28 17:29:56 -07:00
Andrew Kelley
97a2f4e7ae tests: disable i386-linux-gnu -lc target due to CI failures
See #8930
2021-05-28 16:31:09 -07:00
LemonBoy
d3fb9f9532 stage1: Fix for atomicrmw xchg on fp types
Bitcast the pointer and operands to integer types having the same size,
working around LLVM inability to lower a LL/SC operation when the
operands have floating-point types (and are reasonably sized).

Closes #4457
2021-05-28 19:18:42 -04:00
Andrew Kelley
52b3daa90e stage1: get test-compile-errors passing again 2021-05-28 14:19:08 -07:00
Andrew Kelley
2a990d6966 stage1: rework tokenizer to match stage2
* Extracts AstGen logic from ir.cpp into astgen.cpp. Reduces the
   largest file of stage1 from 33,551 lines to 25,510.
 * tokenizer: rework it completely to match the stage2 tokenizer logic.
   They can now be maintained together; when one is changed, the other
   can be changed in the same way.
   - Each token now takes up 13 bytes instead of 64 bytes. The tokenizer
     does not parse char literals, string literals, integer literals,
     etc into meaningful data. Instead, that happens during parsing or
     astgen.
   - no longer store line offsets. Error messages scan source
     files to find the line/column as needed (same as stage2).
   - main loop: instead of checking the loop, handle a null byte
     explicitly in the switch statements. This is a nice improvement
     that we may want to backport to stage2.
   - delete some dead tokens, artifacts of past syntax that no longer
     exists.
 * Parser: fix a TODO by parsing builtin functions as tokens rather than
   `@` as a separate token. This is how stage2 does it.
 * Remove some debugging infrastructure. These will need to be redone,
   if at all, as the code migrates to match stage2.
   - remove the ast_render code.
   - remove the IR debugging stuff
   - remove teh token printing code
2021-05-28 12:58:40 -07:00
Luuk de Gram
5cbe930e36
wasm: Add stage2 tests for error unions 2021-05-28 12:58:17 +02:00
xavier
32154fbf0d add a standalone for zig as a c/c++ compiler 2021-05-25 00:42:31 +02:00
xavier
7e4f28fac9 standalone tests may now test cross targets and build modes. 2021-05-25 00:19:23 +02:00
Andrew Kelley
55811d8dac stage2: introduce clangAssemblerSupportsMcpuArg
Clang has a completely inconsistent CLI for its integrated assembler for
each target architecture. For x86_64, for example, it does not accept
an -mcpu parameter, and emits "warning: unused parameter". However, for
ARM, -mcpu is needed in order to properly lower assembly to machine code
instructions (see new standalone test case provided thanks to @g-w1).

This is a compromise between
b8f85a805b and
afb9f695b1.
2021-05-23 21:51:10 -07:00
Michael Dusan
0f26120377 overhaul elf csu (c-runtime startup) logic
- more support for linux, android, freebsd, netbsd, openbsd, dragonfly
- centralize musl utils; musl logic is no longer intertwined with csu
- fix musl compilation to build crti/crtn for full archs list
- fix openbsd to support `zig build-lib -dynamic`
- initial dragonfly linking success (with a warning)

ancillary:

- fix emutls (openbsd) tests to use `try`
2021-05-23 15:38:57 -04:00
Evan Haas
d321a4b765 translate-c: Translate FnDecl's that appear within functions 2021-05-23 15:42:36 +03:00
Andrew Kelley
1c636e2564
Merge pull request #8844 from ifreund/inline
Support inline keyword as well as callconv(.Inline)
2021-05-22 20:56:30 -04:00
jacob gw
9baf891772 stage2: astgen error for return or try in defer block 2021-05-22 20:54:14 -04:00
Jakub Konka
2b0d322ea0 zld: permit system static libs
This commits permits passing in static archives using the system
lib flag `-la`. With this commit, `zig ld` will now look firstly for
a dynamic library (which always takes precedence), and will fall back
on `liba.a` if the dylib is not found. The static archive is searched
for in the system lib search dirs like the dylibs.
2021-05-22 16:12:45 +02:00
Andrew Kelley
0267abfe9b
Merge pull request #8847 from Luukdegram/wasm-struct-switch
stage2: wasm - Structs and switch support
2021-05-20 18:55:49 -04:00
Isaac Freund
563ea60a86
translate-c: use inline keyword instead of callconv(.Inline) 2021-05-20 21:59:46 +02:00
Andrew Kelley
df56bf94a2
Merge pull request #8789 from Luukdegram/wasm-enum
stage2: wasm backend - Enums
2021-05-20 14:03:54 -04:00
Luuk de Gram
0ac56e7f3a
Add test cases for switches 2021-05-20 19:59:37 +02:00
Luuk de Gram
87a9c6946d
wasm backend: implement multi_value for WValue
This allows us to differentiate between regular locals and variables that create multiple locals
on the stack such as optionals and structs.
Now `struct_a = struct_b;` works and only updates a reference, rather than update all local's values.

Also created more test cases to test against this.
2021-05-20 09:25:02 +02:00
Evan Haas
1273bc277f translate-c: add support for __cleanup__ attribute
Use a `defer` statement to implement the C __cleanup__ attribute.

See https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
2021-05-19 12:12:18 +03:00
Luuk de Gram
6962647862
Do not create a local for the struct itself + test cases 2021-05-19 10:37:44 +02:00
Luuk de Gram
141a0cbb5a
Explicit return & more complex wasm enum test
- When returning within a block, we must use an explicit return opcode. For now always emit the opcode when calling return, rather than using implicit return statements.
- Also added a more comprehensive test case to test for enum values using conditions
2021-05-19 10:35:45 +02:00
Luuk de Gram
9ddede2950
Add enum test case for wasm backend 2021-05-19 08:59:11 +02:00
Andrew Kelley
2c12f5f55b stage2 tests: fix missing 'pub' in one of the test cases 2021-05-18 12:53:23 -07:00
Andrew Kelley
a9cd9b021b Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
I want the updated Drone CI stuff to get the CI green.
2021-05-18 12:37:03 -07:00
Andrew Kelley
ab8f8465a3 stage2: fix deletion of Decls that get re-referenced
When scanDecls happens, we create stub Decl objects that
have not been semantically analyzed. When they get referenced,
they get semantically analyzed.

Before this commit, when they got unreferenced, they were completely
deleted, including deleted from the containing Namespace.

However, if the update did not cause the containing Namespace to get
deleted, for example, if `std.builtin.ExportOptions` is no longer
referenced, but `std.builtin` is still referenced, and then `ExportOptions`
gets referenced again, the Namespace would be incorrectly missing the
Decl, so we get an incorrect "no such member" error.

The solution is to, when dealing with a no longer referenced Decl
objects during an update, clear them to the state they would be in
on a fresh scanDecl, rather than completely deleting them.
2021-05-18 12:35:36 -07:00