Commit graph

4260 commits

Author SHA1 Message Date
Mahdi Khanalizadeh
15bec20b00 linux: add mknod and mknodat syscalls 2021-07-28 18:15:41 -04:00
Matt Knight
2f9e498c6f add build dependency when linkerscript is a generated file 2021-07-28 18:10:53 -04:00
Zach Banks
9c028b2078 std/ArrayList: Allow ArrayList(u0) to be created
Enable creating ArrayList with zero-sized types.
This type still tracks length, but does not allocate
additional memory.
2021-07-28 18:05:40 -04:00
Ominitay
c1285a1bbe Move fs.Walker to fs.Dir.Walker
fs.Walker has been replaced with fs.Dir.Walker. Paths of entries
returned are relative to the Dir.
2021-07-28 21:39:36 +03:00
Evan Haas
d4d3a9dcc9
translate-c: handle floating point NAN and INFINITY macros 2021-07-28 08:06:22 -07:00
Austin Clements
eb010ce65d Skip empty strings in std.fs.path.join function 2021-07-28 09:51:48 +03:00
Andrew Kelley
a8e8927c49 fix old references to verbose-ir to be verbose-air 2021-07-27 18:33:49 -07:00
Lee Cannon
c234d4790e
Add option to hide build command on compilation error to build_runner (#8513)
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-07-27 21:30:53 -04:00
Jarred Sumner
ba71b96fe6 Add zld.id to list of files to skip 2021-07-27 07:54:25 +02:00
Andrew Kelley
7b8cb881df stage2: improvements towards zig test
* There is now a main_pkg in addition to root_pkg. They are usually the
   same. When using `zig test`, main_pkg is the user's source file and
   root_pkg has the test runner.
 * scanDecl no longer looks for test decls outside the package being
   tested. honoring `--test-filter` is still TODO.
 * test runner main function has a void return value rather than
   `anyerror!void`
 * Sema is improved to generate better AIR for for loops on slices.
 * Sema: fix incorrect capacity calculation in zirBoolBr
 * Sema: add compile errors for trying to use slice fields as an lvalue.
 * Sema: fix type coercion for error unions
 * Sema: fix analyzeVarRef generating garbage AIR
 * C codegen: fix renderValue for error unions with 0 bit payload
 * C codegen: implement function pointer calls
 * CLI: fix usage text

 Adds 4 new AIR instructions:

  * slice_len, slice_ptr: to get the ptr and len fields of a slice.
  * slice_elem_val, ptr_slice_elem_val: to get the element value of
    a slice, and a pointer to a slice.

AstGen gains a new functionality:

 * One of the unused flags of struct decls is now used to indicate
   structs that are known to have non-zero size based on the AST alone.
2021-07-23 22:42:31 -07:00
Veikka Tuominen
8ad23d7beb
Merge pull request #9265 from ehaas/translate-c-macro-matching
translate-c: add framework for special-casing macros
2021-07-23 09:29:25 +03:00
Andrew Kelley
e3fe3acce0
Merge pull request #9440 from ziglang/emit-bc
add -femit-llvm-bc CLI option and implement it, and improve -fcompiler-rt support
2021-07-23 02:22:23 -04:00
Andrew Kelley
a5fb28070f add -femit-llvm-bc CLI option and implement it
* Added doc comments for `std.Target.ObjectFormat` enum
 * `std.Target.oFileExt` is removed because it is incorrect for Plan-9
   targets. Instead, use `std.Target.ObjectFormat.fileExt` and pass a
   CPU architecture.
 * Added `Compilation.Directory.joinZ` for when a null byte is desired.
 * Improvements to `Compilation.create` logic for computing `use_llvm`
   and reporting errors in contradictory flags. `-femit-llvm-ir` and
   `-femit-llvm-bc` will now imply `-fLLVM`.
 * Fix compilation when passing `.bc` files on the command line.
 * Improvements to the stage2 LLVM backend:
   - cleaned up error messages and error reporting. Properly bubble up
     some errors rather than dumping to stderr; others turn into panics.
   - properly call ZigLLVMCreateTargetMachine and
     ZigLLVMTargetMachineEmitToFile and implement calculation of the
     respective parameters (cpu features, code model, abi name, lto,
     tsan, etc).
   - LLVM module verification only runs in debug builds of the compiler
   - use LLVMDumpModule rather than printToString because in the case
     that we incorrectly pass a null pointer to LLVM it may crash during
     dumping the module and having it partially printed is helpful in
     this case.
   - support -femit-asm, -fno-emit-bin, -femit-llvm-ir, -femit-llvm-bc
   - Support LLVM backend when used with Mach-O and WASM linkers.
2021-07-22 19:51:32 -07:00
Evan Haas
b33efa3739
translate-c: Handle ambiguous cast or call macro
Fixes #9425
2021-07-22 11:50:12 -07:00
Evan Haas
dc4fa83dd7
translate-c: add framework for special-casing macros
Some macros (for example any macro that uses token pasting) cannot be
directly translated to Zig, but may nevertheless still admit a Zig
implementation. This provides a mechanism for matching macros against
templates and mapping them to functions implemented in c_translation.zig.

A macro matches a template if it contains the same sequence of tokens, except
that the name and parameters may be renamed. No attempt is made to
semantically analyze the macro. For example the following two macros are
considered equivalent:

```C
```

But the following two are not:

```C
```
2021-07-22 08:09:46 -07:00
Michal Ziulek
18b8738069
Fixed compile error: 'bMenu' needs to casted. (#9426) 2021-07-22 01:28:21 +02:00
Biolunar
093e10b66e
linux stdlib: fix definition of RW flags (#9428) 2021-07-22 01:27:59 +02:00
Frank Denis
680fa880d6
std.crypto: handle the top bit in 25519.field.fromBytes64() (#9435)
The only known use case for this is the hash-to-curve operation where the top bit is always cleared.

But the function is public, so let's make it work as one would expect in the general case.

Also fix the comment by the way.
2021-07-22 01:27:42 +02:00
Andrew Kelley
36295d712f remove 'pe' object format
Portable Executable is an executable format, not an object format.
Everywhere in the entire zig codebase, we treated coff and pe as if they
were the same. Remove confusion by not including pe in the
std.Target.ObjectFormat enum.
2021-07-21 12:45:32 -07:00
Tau
8d0671157c Correct hasUniqueRepresentation for vectors
Closes #9333.
2021-07-21 15:19:57 -04:00
Andrew Kelley
f7ee3b4ca5 std.Progress: revert to the older strategy
This reverts the most recent big changes to `std.Progress` changing the
strategy for printing. Before the changes, it would leave the cursor after
the progress line, having better behavior when a stray print happened,
and supporting sub-process progress without any coordination.

After the changes, the cursor was left at the beginning of the line,
making any prints print garbage and often interfering with stack traces
or other debug information.

This commit reverts to before the changes.

Revert "std: Use more common escape sequences in Progress"
This reverts commit 8ebb18d9da.

Revert "Handle some weird edge cases of Win32 API"
This reverts commit b0724a350f.

Revert "Fix many thinkos"
This reverts commit b5a50a26eb.

Revert "Fix Progress printing on Windows systems"
This reverts commit 3010bfb08a.

Revert "std: Better handling of line-wrapping in Progress"
This reverts commit 4fc2e92876.
2021-07-20 19:11:47 -07:00
Andrew Kelley
495e60d641 std.ArrayList: add missing assertion in appendSliceAssumeCapacity 2021-07-20 12:19:17 -07:00
Andrew Kelley
d17f492017 stage2: miscellaneous fixes for the branch
* Breaking language change: inline assembly must use string literal
   syntax. This is in preparation for inline assembly improvements that
   involve more integration with the Zig language. This means we cannot
   rely on text substitution.
 * Liveness: properly handle inline assembly and function calls with
   more than 3 operands.
   - More than 35 operands is not yet supported. This is a low priority
     to implement.
   - This required implementation in codegen.zig as well.
 * Liveness: fix bug causing incorrect tomb bits.
 * Sema: enable switch expressions that are evaluated at compile-time.
   - Runtime switch instructions still need to be reworked in this
     branch. There was a TODO left here (by me) with a suggestion to do
     some bigger changes as part of the AIR memory reworking. Now that
     time has come and I plan to honor the suggestion in a future commit
     before merging this branch.
 * AIR printing: fix missing ')' on alive instructions.

We're back to "hello world" working for the x86_64 backend.
2021-07-20 12:19:16 -07:00
charlieman
bfe2005167
std: remove dead code in std.os.read 2021-07-20 10:22:06 +02:00
Evan Haas
3e67ef5c9f translate-c: Handle underscore when used as an identifier
Use `@` syntax to escape `_` when used as an identifier.

Remove the stage1 astgen prohibition against assigning from `_`

Note: there a few stage1 bugs preventing `_` from being used as an identifier
for a local variable or function parameter; these will be fixed by stage2.
They are unlikely to arise in real C code since identifiers starting with
underscore are reserved for the implementation.
2021-07-19 12:56:23 +03:00
Tizoner
c905056562 fix style warning in json.zig 2021-07-19 12:55:05 +03:00
Adam C
95e5fac412
FIX typo in doc comment for std.math.hypot (#9413) 2021-07-18 23:53:06 +02:00
Jonathan Marler
08e5daa7d5 Add std.unicode.fmtUtf16le 2021-07-15 20:37:16 +03:00
g-w1
ee173d5127
parser: require block in suspend expression 2021-07-15 10:55:22 +03:00
Ryan Liptak
4ea7470417 Add inotify_rm_watch definition to c/linux.zig
Also make inotify_add_watch's pathname marked as nul-terminated
2021-07-15 10:54:05 +03:00
Ryan Liptak
a84402d796 Add NotDir as possible error for os.inotify_add_watch
Possible when "mask contains IN_ONLYDIR and pathname is not a directory."
2021-07-15 10:51:25 +03:00
Isaac Freund
03156e5899 std/hash_map: fix ensureUnusedCapacity() over-allocating
Currently this function adds the desired unused capactiy to the current
total capacity instead of the current used capactiy.
2021-07-12 11:31:36 -07:00
Kenta Iwasaki
aa2a31612f io_uring: add sqe prep methods for epoll_ctl, poll_add, and poll_remove
Implement io_uring submission queue entry preparation methods for
epoll_ctl, poll_add and poll_remove.

Poll masks are designated as 32-bit little-endian integers as
specified in liburing's definitions.

Updated io_uring_prep_rw to take in an unsigned 64-bit address instead
of an anytype. io_uring_sqe by default assumes that the address
specified in a submission queue entry is an unsigned 64-bit integer.
2021-07-11 09:15:54 +00:00
Jacob G-W
968d1ecf17 stage2 plan9: add aarch64 support 2021-07-11 01:58:26 -04:00
Malcolm Still
a3703745eb
Add waitid syscall on linux (#9335) 2021-07-10 16:56:41 -04:00
Andrew Kelley
7b8a968f14
Merge pull request #9105 from g-w1/plan9
stage2: bringup plan9 target and linker
2021-07-08 17:30:28 -04:00
Andrew Kelley
476faef97a plan9 cleanups
* rename files to adhere to conventions
 * remove unnecessary function / optionality
 * fix merge conflict
 * better panic message
 * remove unnecessary TODO comment
 * proper namespacing of declarations
 * clean up documentation comments
 * no copyright header needed for a brand new zig file that is not
   copied from anywhere
2021-07-08 14:24:16 -07:00
Frank Denis
b4b90af4e0
Switch rand.DefaultPrng to Xoshiro256++ (#9301)
Xoroshiro128+ is the current default non-cryptographic random
number generator.

This algorithm was designed to generate floating-point numbers, by
only using the top 53 bits. Lower bits have a significant bias, that
contradicts the documented properties for `rand.DefaultPrng`. This
also has implications on everything using `Random.fill()`, including
the way we generate random floating-point numbers.

In addition, Xoroshiro128+ has known issues. See for example:
- https://lemire.me/blog/2017/08/22/cracking-random-number-generators-xoroshiro128/
- https://www.pcg-random.org/posts/xoroshiro-fails-truncated.html

Xoshiro256++ addresses these issues, while remaining very fast.
2021-07-08 23:19:49 +02:00
Jacob G-W
1c2facaf6b stage2: include enough inline asm support for more plan9 syscalls
Also make the exit more correct by exiting 0 rather than random
stuff on the stack.
2021-07-08 14:12:08 -07:00
Jacob G-W
f1aadfa77b plan9 linker: remove panics and improve 64 bit support
Don't @intCast when we do not need to, and change
some panics to unreachable when they can never happen.
2021-07-08 14:12:08 -07:00
Jacob G-W
72bb6bb143 plan9 linker: produce an object file that can actually work!!! 2021-07-08 14:10:49 -07:00
jacob gw
34c21affa2 initial plan9 boilerplate
The code now compiles and fails with Plan9ObjectFormatUnimplemented
2021-07-08 14:10:49 -07:00
Martin Wickham
e2b954c273 Add support for NO_COLOR 2021-07-08 14:30:45 -04:00
Andrew Kelley
62d27fcfb6
Merge pull request #9325 from ziglang/stage2-inferred-error-sets
Stage2 inferred error sets and `@panic`
2021-07-08 02:04:53 -04:00
Andrew Kelley
ec63411905 Revert "Skip over CRs at the end of multiline literals"
This reverts commit 9de452f9a6.

No CRs allowed in multiline string literals - this is intentional.
2021-07-07 18:00:04 -07:00
Daniele Cocca
9de452f9a6 Skip over CRs at the end of multiline literals
Fixes #9257.
This is needed when tokenizing input containing DOS line endings, i.e.
the CRLF sequence.
2021-07-07 20:03:19 +03:00
Andrew Kelley
d481acc7db std.builtin.panic: simpler default panic for stage2
until it catches up to stage1 in terms of supported language features
2021-07-07 00:38:46 -07:00
Andrew Kelley
298a65ff4b std.HashMap: add ensureUnusedCapacity and ensureTotalCapacity
and deprecated ensureCapacity. This matches the pattern set by ArrayList
and ArrayHashMap already.
2021-07-07 00:38:10 -07:00
Carlos Zúñiga
b936bbd2f1 Fixed builtin.Target -> std.Target 2021-07-07 07:54:38 +03:00
Andrew Kelley
b7da1b2d45
Merge pull request #9175 from kprotty/thread
std.Thread enhancements
2021-07-04 22:31:02 -04:00