3683 Commits

Author SHA1 Message Date
Benjamin Feng
df910b33f4 Add ppc Linux bits 2021-04-10 22:47:22 -05:00
Isaac Freund
5b9ea5dd1e zig fmt: fix line comment detection
Previously hasComment() would consider a string literal "//" to be a
line comment. Fix this by only searching the bytes between tokens.
2021-04-10 23:10:24 +02:00
Meghan Denny
ab43f2376e lib/std: remove empty init from HashMapUnmanaged 2021-04-10 12:49:02 -07:00
Lewis Gaul
ecf555c693
zig fmt: render array init on one line if no trailing comma
Continue to insert a trailing comma if there is a comment or multiline
string literal present.
2021-04-10 16:39:26 +02:00
Andrew Kelley
f75cdd1acd
Merge pull request #8470 from ziglang/stage2-start
stage2: blaze the trail for std lib integration
2021-04-09 10:15:46 -07:00
Andrew Kelley
952032b40c
Merge pull request #8439 from Luukdegram/wasm-mem
stage2: wasm - "Hello world"
2021-04-09 10:08:21 -07:00
LemonBoy
bfc8500390 testing: Avoid @import-ing builtins module
Use std.builtins instead.
2021-04-09 10:04:16 -07:00
LemonBoy
b0e905a30d testing: Avoid printing expected line twice
When the line has trailing whitespace we already print it with a
carriage return symbol at the end, don't print it one more time.
2021-04-09 10:04:16 -07:00
LemonBoy
1943c2dc68 testing: Use indexOfScalar instead of indexOf 2021-04-09 10:04:16 -07:00
LemonBoy
5ebcd8ccaf zig fmt: Fix rendering of arrays with single row
rowSize used to return null if all the elements were placed on the same
line as the right brace, making the rendering logic skip the whole set
of elements.

Given the usage of rowSize let's just drop the null and always return
the number of elements.

Fixes #8423
2021-04-09 10:03:45 -07:00
Andrew Kelley
9a2de796bd stage2: clean up pretty printing compile errors 2021-04-09 00:19:44 -07:00
jacob gw
99ec511c4c stage2: pretty print compilation errors 2021-04-08 23:17:36 -07:00
Andrew Kelley
482b995a49 stage2: blaze the trail for std lib integration
This branch adds "builtin" and "std" to the import table when using the
self-hosted backend.

"builtin" gains one additional item:

```
pub const zig_is_stage2 = true; // false when using stage1 backend
```

This allows the std lib to do conditional compilation based on detecting
which backend is being used. This will be removed from builtin as soon
as self-hosted catches up to feature parity with stage1.
Keep a sharp eye out - people are going to be tempted to abuse this.
The general rule of thumb is do not use `builtin.zig_is_stage2`. However
this commit breaks the rule so that we can gain limited start.zig support
as we incrementally improve the self-hosted compiler.

This commit also implements `fullyQualifiedNameHash` and related
functionality, which effectively puts all Decls in their proper
namespaces. `fullyQualifiedName` is not yet implemented.

Stop printing "todo" log messages for test decls unless we are in test
mode.

Add "previous definition here" error notes for Decl name collisions.

This commit does not bring us yet to a newly passing test case.

Here's what I'm working towards:

```zig
const std = @import("std");

export fn main() c_int {
    const a = std.fs.base64_alphabet[0];
    return a - 'A';
}
```

Current output:

```
$ ./zig-cache/bin/zig build-exe test.zig
test.zig:3:1: error: TODO implement more analyze elemptr
zig-cache/lib/zig/std/start.zig:38:46: error: TODO implement structInitExpr ty
```

So the next steps are clear:
 * Sema: improve elemptr
 * AstGen: implement structInitExpr
2021-04-08 19:05:05 -07:00
xackus
c28d1fe173 std docs: fix layout broken by the banner 2021-04-09 00:36:59 +02:00
Luuk de Gram
ff5774d93d
Refactor link/wasm.zig to use offset table
This refactor inserts an offset table into wasm's data section
where each offset points to the actual data region.
This means we can keep offset indexes consistant and do not
have to perform any computer to determine where in the data section
something like a static string exists. Instead during runtime
it will load the data offset onto the stack.
2021-04-08 22:47:08 +02:00
Timon Kruiper
ac14b52e85 stage2: add support for start.zig
This adds a simplified start2.zig that the current stage2 compiler is
able to generate code for.
2021-04-08 14:23:18 +02:00
xackus
2d2316f5c0 translate-c: fix meta.cast to ?*c_void 2021-04-08 08:33:26 +03:00
Andrew Kelley
d4f61f9842
Merge pull request #8449 from ziglang/stage2-enums
stage2: implement simple enums
2021-04-07 22:29:28 -07:00
Michael Dusan
341dc03b63 netbsd: minor fixes to allow stage1 to build 2021-04-07 16:26:21 -07:00
Michael Dusan
2871d32be7 test: fix std.time timing tests to skip on failure 2021-04-07 08:33:32 -04:00
Andrew Kelley
2adeace905 std: modernize zig parser perf test
use the file size formatting functions
2021-04-06 22:34:48 -07:00
Andrew Kelley
ec212c82be
Merge pull request #8416 from gracefuu/grace/wasm-ops
stage2 wasm codegen: refactor Opcode, add `sub` and `mul` operators
2021-04-06 11:48:40 -07:00
Evan Haas
8de14a98a6 translate-c: Add support for vector expressions
Includes vector types, __builtin_shufflevector, and __builtin_convertvector
2021-04-06 11:22:27 -07:00
Michael Holmes
38d8aab4d2 std/build: fix ?[:0]const u8 build options
As per the other string types, `?[:0]const u8` needs its own case
as otherwise it will raise an error about using `{}` with slices.

There's no reasonable workaround for this, as you would have to
either discount the use of the empty string value or manually
rework the string to be sentinel-terminated at runtime. It's
useful for passing build options to code making use of C libraries
that make strong use of sentinel-terminated arrays for strings.
2021-04-06 11:09:54 -07:00
LemonBoy
89df41e5d8 stage2: Default AVR generic cpu to avr2
The avr1 target is a very minimal subset of the AVR ISA, quoting the GCC
manual:

> This ISA is implemented by the minimal AVR core and supported for
> assembler only.

Default to avr2 as GCC and Clang do.
2021-04-06 10:18:11 -07:00
lithdew
2bfc6d14d5 os/linux: return error on EALREADY for connect() and getsockoptError()
When a connected socket file descriptor on Linux is re-acquired
    after being closed, through fuzz testing, it appears that a
    subsequent attempt to establish a connection with the file
    descriptor causes EALREADY to be reported.

    Instead of panicking, choose to return error.ConnectionPending
    to allow for users to handle this fairly rare case.
2021-04-06 11:30:20 +02:00
gracefu
3648e43dda
std/wasm: add buildOpcode to help construction of Opcodes 2021-04-05 14:44:00 +08:00
Edward Dean
83a2665772 Fixed error types for GetSeekPosError 2021-04-04 17:04:46 -07:00
Lewis Gaul
7302b096bd
Tidy-up in json test module (#8431)
* Switch json testing 'roundTrip()' to use FixedBufferStream, improve error handling, remove comptime from param

* Add 'try' to calls to roundTrip() that can now return an error

* Remove comptime from params in json testing, replace expect(false) with letting error propagate

* Add 'try' to calls to ok() that can now return an error

Co-authored-by: Lewis Gaul <legaul@cisco.com>
2021-04-04 19:27:47 -04:00
Hannu Hartikainen
c9ffb6f734 std docs: enhance search browser history UX
Before this change every keypress in the search field causes a browser
history entry, which makes navigating back annoying.

On first keypress in the search field, a new history entry is created.
On subsequent keypresses, the most recent history entry is replaced.
Therefore a typical history after searching and navigating to an entry
might look like

1. documentation root
2. search page "print"
3. docs for `std.debug.print`


Co-authored-by: Žiga Željko <ziga.zeljko@gmail.com>
2021-04-04 16:25:47 -07:00
Vincent Rischmann
5ce4524027 os/bits/linux: add IPv6 socket options 2021-04-04 20:43:41 +03:00
Lewis Gaul
74fd7107e8
Switch std.json to use an ordered hashmap 2021-04-04 10:16:59 +02:00
Frank Denis
6fc822a948
Merge pull request #8410 from antlilja/remove-undefined-math
Make sqrt and log functions undefined for signed integer types
2021-04-03 19:27:37 +02:00
antlilja
d4dc2eb807
Compile error for signed integer math
Output compile errors when signed integer types are used on functions
where the answer might've been a complex number but that functionality hasn't
been implemented.

This applies to sqrt, log, log2, log10 and ln.

A test which used a signed integer was also changed to use an unsigned
integer instead.
2021-04-03 13:09:20 +02:00
Loris Cro
354c14d6a2 make visited links readable in the stdlib docs warning bar 2021-04-02 20:22:02 +02:00
Loris Cro
4fef1d2982 added warning banner to stdlib docs 2021-04-02 20:13:55 +02:00
Andrew Kelley
d780848ae4
Merge pull request #7792 from zanderxyz/zanderxyz/priority-dequeue
std: Add Priority Dequeue
2021-04-02 10:52:23 -07:00
Michael Dusan
cc435dab2f test: fix io_uring timing test to skip on failure 2021-04-02 07:12:09 -04:00
lithdew
59035ae3e9 os: handle ECONNRESET for connect() syscall 2021-04-01 14:18:49 +02:00
Andrew Kelley
070a28e493
Merge pull request #8266 from ziglang/zir-memory-layout
rework ZIR memory layout; overhaul source locations
2021-03-31 23:11:15 -07:00
Andrew Kelley
b27d052676 stage2: finish source location reworkings in the branch
* remove the LazySrcLoc.todo tag
 * finish updating Sema and AstGen, remove the last of the
   `@panic("TODO")`.
2021-03-31 21:36:32 -07:00
Matthew Borkowski
501b4aff99 Add tests for the fill functions of the Isaac64, Pcg, Sfc64, and Xoroshiro128 PRNGs 2021-03-29 09:22:06 +02:00
Matthew Borkowski
a5cc5f7854 Fix typo in Pcg.zig's fill function
When filling the last (len % 4) bytes of a buffer, the random number n was only being shifted right by 4 bits for each byte instead of 8. A random u16, for example, would always have its middle two nybbles be equal when generated this way. For comparison, Isaac64.zig, Sfc64.zig, and Xoroshiro128.zig all correctly shift right by 8 bits for each of the last bytes in their nearly identical fill functions.
2021-03-29 09:22:06 +02:00
Andrew Kelley
281a7baaea Merge remote-tracking branch 'origin/master' into zir-memory-layout
Wanted to make sure those new test cases still pass.

Also grab that CI fix so we can get those green check marks.
2021-03-28 19:42:43 -07:00
Andrew Kelley
bb5cfbcb72
Merge pull request #8305 from jedisct1/base64
std/base64: cleanups & support url-safe and other non-padded variants
2021-03-28 17:11:07 -07:00
Jonathan Knezek
bbe6a0dddd Add a test & fix for std.fmt.fmtDuration 2021-03-28 15:44:15 +02:00
Frank Denis
6993087edc Remove the base64 unsafe decoder 2021-03-28 14:32:34 +02:00
Frank Denis
99bed37fc7 Add more variants 2021-03-28 14:32:34 +02:00
Frank Denis
b8c019ef49 std/base64: cleanups & support url-safe and other non-padded variants
This makes a few changes to the base64 codecs.

* The padding character is optional. The common "URL-safe" variant, in
particular, is generally not used with padding. This is also the case for
password hashes, so having this will avoid code duplication with bcrypt,
scrypt and other functions.
* The URL-safe variant is added. Instead of having individual constants
for each parameter of each variant, we are now grouping these in a
struct. So, `standard_pad_char` just becomes `standard.pad_char`.
* Types are not `snake_case`'d any more. So, `standard_encoder` becomes
`standard.Encoder`, as it is a type.
* Creating a decoder with ignored characters required the alphabet and
padding. Now, `standard.decoderWithIgnore(<ignored chars>)` returns a
decoder with the standard parameters and the set of ignored chars.
* Whatever applies to `standard.*` obviously also works with `url_safe.*`
* the `calcSize()` interface was inconsistent, taking a length in the
encoder, and a slice in the encoder. Rename the variant that takes a
slice to `calcSizeForSlice()`.
* In the decoder with ignored characters, add `calcSizeUpperBound()`,
which is more useful than the one that takes a slice in order to size
a fixed buffer before we have the data.
* Return `error.InvalidCharacter` when the input actually contains
characters that are neither padding nor part of the alphabet. If we
hit a padding issue (which includes extra bits at the end),
consistently return `error.InvalidPadding`.
* Don't keep the `char_in_alphabet` array permanently in a decoder;
it is only required for sanity checks during initialization.
* Tests are unchanged, but now cover both the standard (padded) and
the url-safe (non-padded) variants.
* Add an error set, rename `OutputTooSmallError` to `NoSpaceLeft`
to match the `hex2bin` equivalent.
2021-03-28 14:32:34 +02:00
lithdew
c8d721aa42 array_hash_map: decrement entries slice len after popping from entries in pop() to prevent oob 2021-03-28 11:02:37 +02:00