92 Commits

Author SHA1 Message Date
Alexandros Naskos
a4fe438d39
std.fmt.comptimePrint: bufPrint cannot return an error 2020-10-02 00:39:19 +03:00
Tadeo Kondrak
236af776fd
std.fmt: add comptimePrint 2020-09-25 12:53:35 -06:00
LemonBoy
27adb82fda std: Respect user-specified alignment when formatting ints
This implementation tries to do the right thing (TM) by treating the
sign as part of the number itself, therefore the alignment parameter
applies to both the sign and the digits.

In other words the format string `{:>4}` with -1 as input will not
output `-  1` but `  -1`.

And let's default to right alignment for everything as that's what users
want, especially when printing numbers. Many implementations use
different defaults for numeric vs non-numeric types, let's strive for a
consistent behaviour here.
2020-09-17 00:53:08 +02:00
LemonBoy
bb9a4ad6e9 std: Fix {*} printing of non-pointer types
Fixes a regression introduced in #6246.
Adds a test to make sure this won't happen again.
2020-09-16 13:45:54 +02:00
Tadeo Kondrak
771f35c593
Use less inefficient method of replacing TypeInfo.UnionField.enum_field 2020-09-07 06:23:27 -06:00
Tadeo Kondrak
ac19ccf595
Update standard library for removal of TypeInfo.UnionField.enum_field 2020-09-07 06:23:26 -06:00
Veikka Tuominen
41bbadbb9a
Merge pull request #6246 from Vexu/field
Remove deprecated fields on `type`
2020-09-05 13:58:02 +03:00
yettinmoor
0c43b6ef5c
document how to escape curly braces in fmt.format 2020-09-04 22:11:09 +03:00
Vexu
1df0f3ac24
update uses of deprecated type field access 2020-09-03 18:10:40 +03:00
daurnimator
fb3c5b84ed std: add fmt option to escape non-printable characters 2020-09-02 19:18:36 -04:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Felix Queißner
6701046cdd
Uses getWritten instead of .pos + slicing
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-08-09 17:40:58 +02:00
Felix (xq) Queißner
ada06e2996 Makes formatFloatValue not return error.NoSpaceLeft anymore. 2020-08-09 14:09:02 +02:00
Felix (xq) Queißner
06a1184c92 Fixes double alignment 2020-08-09 12:48:26 +02:00
Andrew Kelley
a2bb246db4 Revert "std.fmt.format: small optimization to avoid runtime bloat"
This reverts commit 11d38a7e520f485206b7b010f64127d864194e4c.

The benefits of this commit are not enough to justify the compromise
that it made.

closes #5977
2020-08-05 13:30:43 -07:00
Andrew Kelley
11d38a7e52 std.fmt.format: small optimization to avoid runtime bloat
When there are no format parameters, it simply calls `writeAll`. This
has the effect of no longer emitting a compile error for using `{}` and
not having any parameters, however, at this point in the development
process of Zig I think that tradeoff is worthwhile.

On the other hand, it might be OK to simply define formatting to work
this way. It's a common pattern to use the formatting function's format
string `"like this", .{}` instead of `"{}", .{"like this"}`, which can
lead to accidentally putting control characters in the formatting
string, however, with this change that works just fine.
2020-07-29 02:29:36 -07:00
~nue
03f14c3102
Added octal formatting fo fmt functions. (#5867)
* Added octal formatting (specifier "o") to `formatIntValue` function.
* Added octal specifier test case in `fmt.zig` (under the "int.specifier" case)
2020-07-14 02:27:58 -04:00
Vexu
be1507a7af
update compile error tests and some doc comments 2020-07-12 00:54:07 +03:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Alluet
a0a93f2091 Rewrite std.fmt.parseInt 2020-07-05 22:56:06 +00:00
Jonathan Marler
27c1e0b453 Fix issue 5757: increase branch quota for formatting enums 2020-07-05 22:27:50 +00:00
data-man
5229f6ec68 Use writer in std.fmt 2020-06-20 18:23:57 +00:00
Alexandros Naskos
1bc92b1fde Fix formatting of floating point values with the B and Bi specifiers 2020-06-12 13:38:12 -04:00
Jakub Konka
4f24ab9cfc Fix skipping condition (skip when wasm32) 2020-05-29 00:06:26 +02:00
Jakub Konka
3dbe376c77 Link issue to the failing test case targeting wasm 2020-05-28 23:32:17 +02:00
Dmitry Atamanov
dd62f63c04
fmt padding correction (#5403)
* Make .Left as default
2020-05-26 20:53:51 +03:00
Andrew Kelley
62fefe8648 std.fmt: non-exhaustive enums: avoid the loop when it's not necessary 2020-05-26 12:15:08 -04:00
daurnimator
5cdeac3b0e std: in fmt, use tag names of non-exhaustive enums when available 2020-05-26 12:00:33 -04:00
daurnimator
292d515e91 std: allow specifiying enums to be formatted as numbers 2020-05-26 12:00:33 -04:00
data-man
0ecdbdb3cb Support comptime floats in std.fmt 2020-05-25 12:48:59 -04:00
Jakub Konka
d43c08a3e5 Add/fix missing WASI functionality to pass libstd tests
This rather large commit adds/fixes missing WASI functionality
in `libstd` needed to pass the `libstd` tests. As such, now by
default tests targeting `wasm32-wasi` target are enabled in
`test/tests.zig` module. However, they can be disabled by passing
the `-Dskip-wasi=true` flag when invoking the `zig build test`
command. When the flag is set to `false`, i.e., when WASI tests are
included, `wasmtime` with `--dir=.` is used as the default testing
command.

Since the majority of `libstd` tests were relying on `fs.cwd()`
call to get current working directory handle wrapped in `Dir`
struct, in order to make the tests WASI-friendly, `fs.cwd()`
call was replaced with `testing.getTestDir()` function which
resolved to either `fs.cwd()` for non-WASI targets, or tries to
fetch the preopen list from the WASI runtime and extract a
preopen for '.' path.

The summary of changes introduced by this commit:
* implement `Dir.makeDir` and `Dir.openDir` targeting WASI
* implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI
* fix `os.close` and map errors in `unlinkat`
* move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi`
  to `std.os` module
* implement `lseek_{SET, CUR, END}` targeting WASI
* implement `futimens` targeting WASI
* implement `ftruncate` targeting WASI
* implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI
* make sure ANSI escape codes are _not_ used in stderr or stdout
  in WASI, as WASI always sanitizes stderr, and sanitizes stdout if
  fd is a TTY
* fix specifying WASI rights when opening/creating files/dirs
* tweak `AtomicFile` to be WASI-compatible
* implement `os.renameatWasi` for WASI-compliant `os.renameat` function
* implement sleep() targeting WASI
* fix `process.getEnvMap` targeting WASI
2020-05-18 16:09:49 +02:00
data-man
6647c3f054 Fixes fmt padding for some types 2020-05-16 12:45:43 -04:00
Andrew Kelley
8766821157 rework std.math.big.Int
Now there are 3 types:
 * std.math.big.int.Const
   - the memory is immutable, only stores limbs and is_positive
   - all methods operating on constant data go here
 * std.math.big.int.Mutable
   - the memory is mutable, stores capacity in addition to limbs and
     is_positive
   - methods here have some Mutable parameters and some Const
     parameters. These methods expect callers to pre-calculate the
     amount of resources required, and asserts that the resources are
     available.
 * std.math.big.int.Managed
   - the memory is mutable and additionally stores an allocator.
   - methods here perform the resource calculations for the programmer.
   - this is the high level abstraction from before

Each of these 3 types can be converted to the other ones.

You can see the use case for this in the self-hosted compiler, where we
only store limbs, and construct the big ints as needed.

This gets rid of the hack where the allocator was optional and the
notion of "fixed" versions of the struct. Such things are now modeled
with the `big.int.Const` type.
2020-05-01 06:47:56 -04:00
Tadeo Kondrak
350b2adacd
std.meta.IntType -> std.meta.Int 2020-04-28 19:11:31 -06:00
Tadeo Kondrak
f977155fdb
@Vector -> std.meta.Vector 2020-04-28 00:47:13 -06:00
Timon Kruiper
c829f2f7b7 Add mips support to standard library 2020-04-24 15:28:55 -04:00
markfirmware
203d6554b1 Update fmt.zig 2020-04-03 12:12:40 -04:00
Andrew Kelley
53b5aa812b
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-19 22:19:24 -04:00
Andrew Kelley
7fa88cc0a6
std lib fixups for new semantics
std lib tests are passing now
2020-03-19 09:53:55 -04:00
Andrew Kelley
656ba530d8
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-13 15:17:53 -04:00
Andrew Kelley
4905102901
fix all the TODOs from the pull request
* `std.Buffer.print` is removed; use `buffer.outStream().print`
 * `std.fmt.count` returns a `u64`
 * `std.Fifo.print` is removed; use `fifo.outStream().print`
 * `std.fmt.bufPrint` error is renamed from `BufferTooSmall`
   to `NoSpaceLeft` to match `std.os.write`.
 * `std.io.FixedBufferStream.getWritten` returns mutable buffer
   if the buffer is mutable.
2020-03-13 12:02:58 -04:00
Benjamin Feng
4aae55b4cc Replace fmt with new fmtstream 2020-03-12 10:41:09 -05:00
Michael Dusan
83f6f730cd std: simplify format enum-literals 2020-03-10 18:09:41 -04:00
Andrew Kelley
96c07674fc
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-07 12:18:41 -05:00
daurnimator
4114b63d75
std: use std.ArrayList instead of std.Buffer in std/fmt.zig tests 2020-03-06 18:49:13 -05:00
Michael Dusan
1091fee242 std: format enum-literals 2020-03-05 16:03:12 -05:00
daurnimator
488ba1560f
std: fix math.absCast on i1 2020-03-05 16:00:19 +11:00
daurnimator
4f58bfe1a8
std: fix formatting of i1 integers 2020-03-05 15:52:19 +11:00
daurnimator
d5359ea541
std: use testing.expectEqualSlices from tests 2020-03-05 15:51:21 +11:00
Andrew Kelley
d1cb16aace
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-03 09:44:13 -05:00