Commit Graph

1266 Commits

Author SHA1 Message Date
Yujiri
577f9fdbae doc/langref: clarify behavior of slicing with constant indexes
Fixes #11219.
2022-07-15 10:17:22 +03:00
Andrew Kelley
1b9a9ee4ba langref: disable an example that regressed from LLVM 14 2022-07-07 12:19:48 -07:00
Pierre Curto
76f8328277 doc: update std.builtin.TypeInfo to std.builtin.Type 2022-06-27 19:48:52 +03:00
r00ster
b3672e0738 Fix grammatical error
Fixes #11675
2022-05-27 01:00:15 -04:00
Vincenzo Palazzo
80f3c8d276
docs: add documentation on errdefer with caputure syntax
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-05-17 21:08:32 +02:00
Vincenzo Palazzo
8328f5ed51
docs: add documentation about return stm in the defer method
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-05-17 18:34:28 +02:00
Koakuma
fb0692334e target: Rename sparcv9 -> sparc64
Rename all references of sparcv9 to sparc64, to make Zig align more with
other projects. Also, added new function to convert glibc arch name to Zig
arch name, since it refers to the architecture as sparcv9.

This is based on the suggestion by @kubkon in PR 11847.
(https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-13 16:43:59 -04:00
Jonathan Marler
9e89000ffc Update usages of process.getEnvMap and change BufMap -> EnvMap where applicable
# Conflicts:
#	lib/std/build/RunStep.zig
2022-05-11 18:40:53 -06:00
Kirk Scheibelhut
67c4b16d6e docs: T.bit_count -> @typeInfo(T).Int.bits
bit_count was removed in #6246
2022-05-10 17:28:44 -04:00
Andrew Kelley
ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00
Andrew Kelley
09f1d62bdf add new builtin function @tan
The reason for having `@tan` is that we already have `@sin` and `@cos`
because some targets have machine code instructions for them, but in the
case that the implementation needs to go into compiler-rt, sin, cos, and
tan all share a common dependency which includes a table of data. To
avoid duplicating this table of data, we promote tan to become a builtin
alongside sin and cos.

ZIR: The tag enum is at capacity so this commit moves
`field_call_bind_named` to be `extended`. I measured this as one of
the least used tags in the zig codebase.

Fix libc math suffix for `f32` being wrong in both stage1 and stage2.
stage1: add missing libc prefix for float functions.
2022-04-27 16:45:23 -07:00
Motiejus Jakštys
6d0283e6bc
[doc update] add size_t (#11482)
For those souls looking for a zig `size_t` equivalent, and not
lucky/educated enough (that was me yesterday) to know it's the same as
`uintptr_t`.

From a recent discussion on IRC.
2022-04-21 14:33:42 -04:00
Cody Tapscott
7b090df668 stdlib std.os: Improve wasi-libc parity for WASI CWD emulation
Two major changes here:
  1. We store the CWD as a simple `[]const u8` and lookup Preopens for
     every absolute or CWD-referenced file operation, based on the
     Preopen with the longest match (i.e. most specific path)
  2. Preorders are normalized to POSIX absolute paths at init time.
     Behavior depends on the "cwd_root" parameter of `initPreopensWasi`:

	`cwd_root` is used for any Preopens that start with "."

	  For example:
            "./foo/bar" - inits to -> "{cwd_root}/foo/bar"
            "foo/bar"   - inits to -> "/foo/bar"
	    "/foo/bar"  - inits to -> "/foo/bar"

        `cwd_root` must be an absolute path.

	Using "/" as `cwd_root` gives behavior similar to wasi-libc.
2022-04-16 18:08:05 +02:00
Kirk Scheibelhut
971ef7b9c2 Remove primitive values from keyword reference
5a53ab28 removed these as keywords, and the Primitive Values section
of the docs already exists to describe them.
2022-04-09 12:48:36 +02:00
Philipp Lühmann
795f075790 langref: rename incorrect expect to assert 2022-04-04 15:44:01 +03:00
dxps
9a127501f6 chore: doc fixes, closes 11091 2022-03-25 11:22:30 +02:00
Robin Voetter
5c3325588e stage1: make type names more unique 2022-03-19 19:40:46 -04:00
Andrew Kelley
f3f5a5d05b stage2: improve @typeName
* make it always return a fully qualified name. stage1 is inconsistent
   about this.
 * AstGen: fix anon_name_strategy to correctly be `func` when anon type
   creation happens in the operand of the return expression.
 * Sema: implement type names for the "function" naming strategy.
 * Put "enum", "union", "opaque", or "struct" in place of "anon" when
   creating respective anonymous Decl names.
 * std.testing: add `expectStringStartsWith`. Didn't end up using it
   after all.

Also this enables the real test runner for stage2 LLVM backend (sans
wasm32) since it works now.
2022-03-18 00:12:22 -07:00
Andrew Kelley
73e51133c3 langref: small clarification of @reduce 2022-03-17 17:22:57 -07:00
Andrew Kelley
d42d31f72f basic language features do not belong in std.meta 2022-03-14 00:11:46 -07:00
Andrew Kelley
627209253c langref: fix a stray anyopaque that should be a void 2022-03-08 14:58:53 -07:00
The Depressed Milkman
cd43f323d2 correct @frameSize() params in documentation
The documentation omitted the primary parameter, making it difficult to
understand what this function actually does.
2022-03-06 10:32:07 +02:00
Exonorid
91a88a789f
Add documentation for common mistakes in errdefer scoping 2022-02-23 14:33:51 +02:00
Veikka Tuominen
c9dde10f86 stage1: improve error message when casting tuples 2022-02-17 17:39:54 +02:00
Andrew Kelley
dc6553d93e CI: update download page and langref for 0.9.1 2022-02-14 20:08:04 -07:00
Andrew Kelley
1e49d1fca8 langref: correct info about type info of declarations 2022-02-14 12:26:55 -07:00
Andrew Kelley
210ee1067b update more API usage of std.Progress
fixes regression introduced in 5a00e24963
2022-02-08 17:49:40 -07:00
Kirk Scheibelhut
71321b6941
Various documentation fixes
Co-authored-by: Kirk Scheibelhut <kjs@scheibo.com>
Co-authored-by: extrasharp <genericpb@gmail.com>
2022-02-04 21:27:50 +02:00
GithubPrankster
23e981bbd1 Correct f80 description 2022-02-02 15:54:30 +02:00
PhaseMage
8a97807d68
Full response file (*.rsp) support
I hit the "quotes in an RSP file" issue when trying to compile gRPC using
"zig cc". As a fun exercise, I decided to see if I could fix it myself.
I'm fully open to this code being flat-out rejected. Or I can take feedback
to fix it up.

This modifies (and renames) _ArgIteratorWindows_ in process.zig such that
it works with arbitrary strings (or the contents of an RSP file).

In main.zig, this new _ArgIteratorGeneral_ is used to address the "TODO"
listed in _ClangArgIterator_.

This change closes #4833.

**Pros:**

- It has the nice attribute of handling "RSP file" arguments in the same way it
  handles "cmd_line" arguments.
- High Performance, minimal allocations
- Fixed bug in previous _ArgIteratorWindows_, where final trailing backslashes
  in a command line were entirely dropped
- Added a test case for the above bug
- Harmonized the _ArgIteratorXxxx._initWithAllocator()_ and _next()_ interface
  across Windows/Posix/Wasi (Moved Windows errors to _initWithAllocator()_
  rather than _next()_)
- Likely perf benefit on Windows by doing _utf16leToUtf8AllocZ()_ only once
  for the entire cmd_line

**Cons:**

- Breaking Change in std library on Windows: Call
  _ArgIterator.initWithAllocator()_ instead of _ArgIterator.init()_
- PhaseMage is new with contributions to Zig, might need a lot of hand-holding
- PhaseMage is a Windows person, non-Windows stuff will need to be double-checked

**Testing Done:**

- Wrote a few new test cases in process.zig
- zig.exe build test -Dskip-release (no new failures seen)
- zig cc now builds gRPC without error
2022-01-30 21:27:52 +02:00
Sage Hane
e288148f60
fs: Use OpenMode enum instead of read/write flags. 2022-01-29 15:52:08 +02:00
Veikka Tuominen
67d04a988a std: add f80 bits 2022-01-28 11:45:04 -07:00
praschke
6d1b1374f7 docs: reorganize @truncate and @intCast for clarity 2022-01-27 19:51:17 +02:00
Philipp Lühmann
db1edb6535 fix precedence in langref or example 2022-01-27 19:39:35 +02:00
Exonorid
3e6952ad16 Added documentation for implicit struct pointer dereferencing 2022-01-27 19:33:07 +02:00
r00ster
dd076d8cba Add missing package to the langref that's always available 2022-01-07 14:18:47 -05:00
ominitay
7e16bb36d8 Change ArgIterator.next() return type
Changes the return type of `ArgIterator.next()` from
`?(NextError![:0]u8)` to `NextError!?[:0]u8`.
2021-12-21 11:15:33 -08:00
John Schmidt
0d09b87c14 Langref: replace mentions of c_void with anyopaque 2021-12-21 11:13:21 -08:00
Andrew Kelley
a18bf7a7bf Release 0.9.0 2021-12-20 13:13:19 -07:00
Andrew Kelley
80b21cef5a langref: fix tidy html error
regressed in 8468b544e8
2021-12-18 23:57:00 -07:00
Isaac Freund
9f9f215305
stage1, stage2: rename c_void to anyopaque (#10316)
zig fmt now replaces c_void with anyopaque to make updating
code easy.
2021-12-19 00:24:45 -05:00
bnprks
8468b544e8
Add Vector documentation (#10303)
* Create Vector language documentation

Main changes to docs:
1. Create brief documentation on Zig vector types with code example
2. Get rid of the SIMD sub-heading under the main Vectors heading,
and update links accordingly
3. Add an example to the `@shuffle` docs
2021-12-18 23:40:57 -05:00
Isaac Freund
516945d7d9
langref: document @prefetch() builtin 2021-12-11 00:29:31 +01:00
Michael Byrne
7e2fae10c9
Add documentation for sentinel-terminated slicing (#10010)
closes #9680
2021-12-03 20:37:48 -05:00
Andrew Kelley
f3edff439e improve detection of how to execute binaries on the host
`getExternalExecutor` is moved from `std.zig.CrossTarget` to
`std.zig.system.NativeTargetInfo.getExternalExecutor`.

The function also now communicates a bit more information about *why*
the host is unable to execute a binary. The CLI is updated to report
this information in a useful manner.

`getExternalExecutor` is also improved to detect such patterns as:
 * x86_64 is able to execute x86 binaries
 * aarch64 is able to execute arm binaries
 * etc.

Added qemu-hexagon support to `getExternalExecutor`.

`std.Target.canExecBinaries` of is removed; callers should use the more
powerful `getExternalExecutor` instead.

Now that `zig test` tries to run the resulting binary no matter what,
this commit has a follow-up change to the build system and docgen to
utilize the `getExternalExecutor` function and pass `--test-no-exec`
in some cases to avoid getting the error.

Additionally:

 * refactor: extract NativePaths and NativeTargetInfo into their own
   files named after the structs.
 * small improvement to langref to reduce the complexity of the `callconv`
   expression in a couple examples.
2021-12-02 21:51:14 -07:00
Lee Cannon
02e5e0ba1f
allocgate: apply missed changes 2021-11-30 23:32:48 +00:00
Lee Cannon
1093b09a98
allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Lee Cannon
75548b50ff
allocgate: stage 1 and 2 building 2021-11-30 23:32:47 +00:00
Lee Cannon
85de022c56
allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Andrew Kelley
902df103c6 std lib API deprecations for the upcoming 0.9.0 release
See #3811
2021-11-30 00:13:07 -07:00
Michael Byrne
ee98d87008 Minor rewording of "Shadowing" section within language reference 2021-10-23 02:57:20 -04:00
Andrew Kelley
7f006287ae
Merge pull request #9878 from pfgithub/patch-4
Add line numbers to langref
2021-10-12 14:21:28 -04:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Mr. Paul
65e4926c5b langref: Explain Zig Test
Updates the Language Reference sections: Comments, Values, and Zig Test.

Zig Test section moved down with the goal "make sure it can be read top to
bottom sensibly" in mind (issue #1524).

Comments and Values section examples changed test declarations to a main
function and expect statement to print statements.

A print statement was added to the "String Literals and Unicode Code Point"
section's example to demonstrate the "u" format specifier.

Zig Test Section:
* Addresses the question: "How does the syntax work?".
* Partially answers the question: "What can I do with the zig test tool?" but
should be sufficient to understand the examples in all of this document.
* Addresses the question: "How does a top-level test block differ from a function definition?"
* Provides a example to run multiple test.

Lacks clear definitions of containers, top-level, order independence, lazy
analysis, resolve, reference.

GitHub Issues: #8221, #8234
2021-10-04 15:35:01 -04:00
pfg
5d8f8cdca5 fix assuming multiline string tokens end with '\n' 2021-10-03 16:32:30 -04:00
pfg
a92b144260 switch back to peg for the grammar type 2021-10-03 16:27:12 -04:00
pfg
0b440d9e29 fix the erroring tests 2021-10-02 17:04:51 -04:00
pfg
224423ac27 fix grammer file name and .y file type 2021-10-02 16:54:05 -04:00
pfg
cfbbd97075 fix incorrectly escaped html 2021-10-02 16:33:58 -04:00
pfg
d82b3e2fb1 fix fmt 2021-10-01 16:53:58 -04:00
pfg
ebdd9e8719 fix style in th 2021-10-01 16:23:58 -04:00
pfg
d5c5824c80 fix line numbers on multiline strings, add line numbers to peg grammar 2021-10-01 16:06:30 -04:00
pfg
de92925897 Add line numbers to langref (fixes #9870) 2021-10-01 15:43:23 -04:00
Nathan Michaels
c4cd592f0e Fix a typo in @ceil documentation. 2021-09-30 23:32:09 -04:00
Andrew Kelley
5467582444 saturating arithmetic modifications
* Remove the builtins `@addWithSaturation`, `@subWithSaturation`,
   `@mulWithSaturation`, and `@shlWithSaturation` now that we have
   first-class syntax for saturating arithmetic.
 * langref: Clarify the behavior of `@shlExact`.
 * Ast: rename `bit_shift_left` to `shl` and `bit_shift_right` to `shr`
   for consistency.
 * Air: rename to include underscore separator with consistency with
   the rest of the ops.
 * Air: add shl_exact instruction
 * Use non-extended tags for saturating arithmetic, to keep it
   simple so that all the arithmetic operations can be done the same
   way.
   - Sema: unify analyzeArithmetic with analyzeSatArithmetic
     - implement comptime `+|`, `-|`, and `*|`
     - allow float operands to saturating arithmetic
 * `<<|` allows any integer type for the RHS.
 * C backend: fix rebase conflicts
 * LLVM backend: reduce the amount of branching for arithmetic ops
 * zig.h: fix magic number not matching actual size of C integer types
2021-09-28 19:19:28 -07:00
Travis Staloch
fd8383545a sat-arithmetic: langref - use <th> tags 2021-09-28 17:03:43 -07:00
Travis Staloch
1d86eae526 sat-arithmetic: langref - remove syntax disclaimer 2021-09-28 17:03:43 -07:00
Travis Staloch
0f246257be sat-arithmetic: update langref 2021-09-28 17:03:43 -07:00
Travis Staloch
6ba9f7474f sat-arithmetic: fix docgen 2021-09-28 17:03:43 -07:00
Mr. Paul
25266d0804 Langref: fix HTML escaped symbol WASM JavaScript code example
docgen HTML escapes characters inside of `syntax_block`s. This commit replaces the escaped
greater than with the `>` character. No other occurrences were found.

Fixes #9840
2021-09-27 18:22:56 +03:00
Josh Soref
664941bf14
Spelling corrections (#9833)
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2021-09-24 13:39:20 -04:00
Andrew Kelley
1ad905c71e
Merge pull request #9649 from Snektron/address-space
Address Spaces
2021-09-20 20:37:04 -04:00
Andrew Kelley
f8b914fcf3 Merge branch 'address-space' of Snektron/zig into Snektron-address-space
There were two things to resolve here:
 * Snektron's branch edited Zir printing, but in master branch
   I moved the printing code from Zir.zig to print_zir.zig. So that
   just had to be moved over.
 * In master branch I fleshed out coerceInMemory a bit more, which
   caused one of Snektron's test cases to fail, so I had to add
   addrspace awareness to that. Once I did that the tests passed again.
2021-09-20 17:32:52 -07:00
Mr. Paul
380ca26855 docgen: re-enable syntax checking for code blocks
In a previous commit (f4d3d29), syntax checking for code blocks with the
`syntax` type was disabled due to a change in astgen now checking the existence of
identifiers. The change in astgen caused some code samples in the language
reference to cause compilation errors.

This commit updates the code samples in the language reference and
re-enables syntax checking. Some code samples have been changed to unchecked
syntax blocks using `{#syntax_block#}` when suitable.
2021-09-20 19:54:57 -04:00
Rory O’Kane
b3ae69d80b langref: define the inferred error set syntax more explicitly
This edit allows the reader to understand the syntax this section is talking about more quickly – they don’t have to read the whole code block and understand which part of it demonstrates the feature being described.

Affects https://ziglang.org/documentation/master/#Inferred-Error-Sets
2021-09-20 02:04:31 -04:00
Robin Voetter
7a5d0cdf45 Address Spaces: Render addrspace token in docgen 2021-09-20 02:29:04 +02:00
Andrew Kelley
b67d1810be stage2: implement @atomicRmw and @atomicLoad
* langref: add some more "see also" links for atomics
 * Add the following AIR instructions
   - atomic_load
   - atomic_store_unordered
   - atomic_store_monotonic
   - atomic_store_release
   - atomic_store_seq_cst
   - atomic_rmw
 * Implement those AIR instructions in LLVM and C backends.
 * AstGen: make the `ty` result locations for `@atomicRmw`, `@atomicLoad`,
   and `@atomicStore` be `coerced_ty` to avoid unnecessary ZIR
   instructions when Sema will be doing the coercions redundantly.
 * Sema for `@atomicLoad` and `@atomicRmw` is done, however Sema for
   `@atomicStore` is not yet implemented.
   - comptime eval for `@atomicRmw` is not yet implemented.
 * Sema: flesh out `coerceInMemoryAllowed` a little bit more. It can now
   handle pointers.
2021-09-15 19:00:35 -07:00
Mr. Paul
0c091feb5a Improve HTML semantics and a11y of language reference
The language reference's HTML has been updated to be more semantically correct.
This also helps to improve the document's accessibility concerns.

* Document structure has single h1, other header sections start at h2, nav sections w/ aria labels, main section
* Zig's homepage is linked, Zig Standard Library section link to it
* Tables have caption and scoping rows and columns
* Code blocks are figures with figure captions citing source files
* Change line height 1.5 to include table of contents as well
* Luminosity contrast ratios have been adjusted to 7:1
* Dark mode colors adjusted to reduce eye strain
* Links have default browser underline with hover and focus effects
* Asides, definition lists, keyboard inputs, program outputs are represented semantically

Tools used to check:
WAVE plugin https://wave.webaim.org/
Firefox Accessibility Developer Tool
Lighthouse Accessibility Tool
2021-09-10 14:23:32 -04:00
Andrew Kelley
16c3cd3d19 langref: update link to 0.8.1 docs 2021-09-07 01:14:08 -07:00
Andrew Kelley
feec4b0614 langref: new usingnamespace semantics 2021-09-01 17:54:07 -07:00
Andrew Kelley
f4d3d29f92 docgen: syntax blocks don't actually run the code 2021-09-01 17:54:07 -07:00
travisstaloch
21a5769afe
saturating arithmetic builtins: add, sub, mul, shl (#9619)
- adds 1 simple behavior tests for each
  which does integer and vector ops at
  runtime and comptime
- adds bigint_*_sat() methods for each

- use CreateIntrinsic() which accepts a
  variable number of arguments to pass
  the scale parameter

* update langref
- added case to test/compile_errors.zig given floats

- explain upstream bug in llvm.smul.fix.sat and link to #9643 in langref and commented out test cases

* sat-arithmetic: skip mul tests if arch == .wasm32 because ci is erroring with 'LLVM ERROR: Unable to expand fixed point multiplication' when compiling for wasm32
2021-09-01 14:17:45 -04:00
Philipp Lühmann
76b85cd665 fix typo 2021-08-31 14:05:44 -04:00
Andrew Kelley
05cf44933d stage2: delete keywords true, false, undefined, null
The grammar does not need these as keywords; they are merely primitives
provided by the language the same as `void`, `u32`, etc.
2021-08-28 12:10:55 -07:00
Andrew Kelley
bb38931c71 stage1: @intToEnum implicitly does an @intCast
This is a backwards-compatible language change.

Previously, `@intToEnum` coerced its integer operand to the integer tag
type of the destination enum type, often requiring the callsite to
additionally wrap the operand in an `@intCast`. Now, the `@intCast` is
implicit, and any integer operand can be passed to `@intToEnum`.

The same as before, it is illegal behavior to pass any integer which does
not have a corresponding enum tag.
2021-08-23 15:30:57 -07:00
bnprks
cfb2827b0a Clarify async/await language documentation.
The async/await documentation was somewhat hard for me to follow when first learning. Two particular sticking points were
1. The alphabet example constructing the string "abcdefghi" breaks the stated rule that every async has a matching await.
2. It was somewhat unclear to me what the rules for control flow were around async/await constructs.
I've tried to improve this documentation with some minimal explanatory edits, which are correct to the best of my beginner's understanding & experimentation.
2021-08-20 14:16:04 +03:00
Paul
ddaca72864
Make clearer inline code blocks in language reference paragraphs (#9317)
* Make clearer inline code blocks in language reference paragraphs

This commit makes the inline code blocks within paragraphs standout against the
descriptive text. The code blocks within tables are left un-styled.

The line-height of the paragraphs has been set to 1.7 based on recommendations
from MDN Web Docs and W3C. The value is unitless based on the recommendation.

Closes #9316, #6313

* Make clearer inline code blocks in language reference paragraphs

Goal: To improve legibility of inline code blocks in the language reference.

This commit alters the styles of code HTML elements in paragraphs, unordered
lists, ordered lists, tables, and preformatted text elements.

Most of the changes here are taken from suggestions from @dbandstra on GitHub
in response to a code review.

* p, ul, ol, but not #toc are set to the same line-height
* p, ul, ol, and table have the same inline code styles
* The inline code background color set to match the preformatted code blocks in
the light theme and dark theme. The border colors are adjusted as well.
* The preformatted code block font size is set to default. The 12pt setting was removed.

The line-height of paragraphs is set to 1.5. This value is chosen based on
recommendations from W3C [1] via MDN Web Docs [2] and the contents of the
language reference.

The MDN Web Docs offers two recommendations:

  1. Use a unitless number for line-height.
  2. Use a minimum value of 1.5 for main paragraph content.

[1] https://www.w3.org/TR/WCAG21/#visual-presentation
[2] https://developer.mozilla.org/en-US/docs/Web/CSS/line-height

Closes #6313, #9316

* Set language reference line-height and pre code border color

This commit is an update to a group of commits with the goal of improving the
legibility of the language reference. In this commit, the line-height is now set
in the `#contents` ID and reset to normal for preformatted code blocks. This
change better separates lines of all main content text for legibility.

Closes: #9316, #6313

* Style the language reference code elements

This commit sets the style of the HTML code element. Since preformatted code
blocks have an overriding style, this is safe to set for all inline code elements.
2021-08-20 13:02:14 +03:00
Meghan
7e52a096db
langref- fix packed struct error code 2021-08-01 12:42:48 +03:00
Meghan
32069d2330
langref- fix use after block error code 2021-08-01 12:42:05 +03:00
Andrew Kelley
dc88864c97 stage2: implement @boolToInt
This is the first commit in which some behavior tests are passing for
both stage1 and stage2.
2021-07-27 17:08:37 -07:00
Robin Voetter
cdeea3b094 minimum/maximum builtins 2021-07-26 20:41:00 -04:00
Robin Voetter
50a29f7c21 Add @select
@select(
    comptime T: type,
    pred: std.meta.Vector(len, bool),
    a: std.meta.Vector(len, T),
    b: std.meta.Vector(len, T)
) std.meta.Vector(len, T)

Constructs a vector from a & b, based on the values in the predicate vector. For indices where the predicate value is true, the corresponding
element from the a vector is selected, and otherwise from b.
2021-07-26 20:05:48 -04:00
Auguste Rame
dd796154be Doc fixes for clz + ctz 2021-07-25 22:58:58 -04:00
Auguste Rame
ecca829bcb Add vector support for @popCount 2021-07-25 20:35:55 -04:00
David May
e5b476209a
Docs fix array/pointer/slice type coercion section (#9392)
* removed deprecated coercion: [X]T => [] const T

* Fixed tests and added desc for first test

* Improved heading
2021-07-23 09:32:20 +03: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
Isaac Freund
00e944f718 langref: remove incorrect statement on c_void
c_void is *not* simply `const c_void = opaque{};`. It has unique
semantics as any pointer type may coerce to `*c_void` which is not true
for an arbitrary `*opaque{}`.
2021-07-19 20:03:26 -04:00
Jonathan Marler
9086452ff9 clarify @bitSizeOf behavior 2021-07-13 10:14:39 +03:00
Mr. Paul
a201d80253 Introduce Zig Test earlier in Language Reference
The "Zig Test" section of the language reference has been moved between the
current "Hello World" section and the "Comments" section. This was done to
introduce the Zig test syntax before it is used in later sections.

The description of the Zig test feature has NOT been updated in this commit.

Closes #5837
2021-07-08 14:33:53 -04:00
yetanothercheer
7935e83b1d Fix indentation in langref.html.in 2021-07-08 00:05:29 -04:00
Andrew Kelley
b7da1b2d45
Merge pull request #9175 from kprotty/thread
std.Thread enhancements
2021-07-04 22:31:02 -04:00
Nulo
5d0dad9acd Link to the GPA now that it's on upstream 2021-07-04 15:44:29 -04:00
Andrew Kelley
a6bf68ccf9 langref: fix test cases now that AST Lowering has priority 2021-07-02 16:22:09 -07:00
Andrew Kelley
22b20f20b6 AstGen: fix missing compile error for unreachable @TypeOf argument 2021-07-02 13:26:50 -07:00
kprotty
f0fa129e9b std.Thread: more cleanup & testing 2021-06-30 21:49:00 -05:00
Andrew Kelley
06129d7e3d std: implement a cross platform file locking abstraction
This modifies the lock semantics from using AccessMode to using
NtLockFile/NtUnlockFile.

This is a breaking change.
2021-06-29 14:25:04 -07:00
Evan Haas
3be682bac9
translate-c: Add documentation for zig translate-c 2021-06-27 12:25:32 +03:00
Jacob G-W
4adcd560ce langref: make @setRuntimeSafety more correct 2021-06-25 08:57:03 +03:00
Andrew Kelley
3259532080 langref: fix unused vars 2021-06-23 11:32:28 -07:00
Veikka Tuominen
29945fb8b3 fix typos in langref.html
I thought I built the docs locally but apparently not.
2021-06-23 09:20:39 +03:00
Roman Frołow
ce3679aa45
Docs clarification: local static variable (#8381) 2021-06-23 08:45:36 +03:00
Jacob G-W
da063ebd96 docs: top level global assembly -> container level 2021-06-23 08:44:52 +03:00
Jacob G-W
641ecc260f std, src, doc, test: remove unused variables 2021-06-21 17:03:03 -07:00
Dmitry Matveyev
00982f75e9
stage2: Remove special double ampersand parsing case (#9114)
* Remove parser error on double ampersand

* Add failing test for double ampersand case

* Add error when encountering double ampersand in AstGen

"Bit and" operator should not make sense when one of its operands
is an address.

* Check that 2 ampersands are adjacent to each other in source string

* Remove cases of unused variables in tests
2021-06-20 21:04:14 +03:00
Daniele Cocca
9e88356282 embedFile: change notation from [X:0] to [N:0]
This is for consistency with the documentation on sentinel-terminated
{arrays,slices,pointers} which already use `N` for a comptime-inferred
size rather than `X`.

Also adds a behavioral test to assert that a string literal is returned.
2021-06-16 22:03:02 +01:00
Daniele Cocca
9be2f76741 typeName: amend return type to string literal
This was already the case, but the documentation failed to point out
that the returned value is of type `*const [N:0]u8`, i.e. that of a
string literal.

Also adds a behavioral test to assert that this is the case.
2021-06-16 22:03:02 +01:00
Daniele Cocca
171102ea7c errorName: return a null-terminated slice 2021-06-16 22:02:52 +01:00
Daniele Cocca
00e1c0082c tagName: return a null-terminated slice 2021-06-16 22:02:42 +01:00
Andrew Kelley
515d6430c0 AstGen: support @export with field access
The Zig language specification will support identifiers and field access
in order to refer to which declaration to export with `@export`.

This commit implements the change in AstGen and updates the language
reference.
2021-06-15 14:08:57 -07:00
Jarred Sumner
540b52931a Improve error message when std.fmt.format is missing arguments
Use fmt in fmt so the number in the error message is fmt'd
2021-06-13 10:33:49 +03:00
Exonorid
f63338195d Renamed @byteOffsetOf to @offsetOf 2021-06-12 19:16:01 +03:00
Norberto Martínez
9f8d1a9ff3 Documentation TOC item color changed 2021-06-10 22:12:46 +03:00
Andrew Kelley
f62f35e346 langref: link to 0.7.1 not 0.7.0 for the previous docs 2021-06-09 11:17:43 -07:00
Andrew Kelley
87562b50fc langref: remove paragraph that mentions IRC
I want the language reference to be divorced from any particular
community. Also remove the call to action since the docs are
known to be incomplete and are not the current focus of the project.

Closes #9055
2021-06-09 11:15:30 -07:00
Andrew Kelley
a642552faf Release 0.8.0 2021-06-04 11:21:32 -07:00
Isaac Freund
05b677f0c4 langref: sync grammar with zig-spec repo 2021-06-04 01:18:45 -04:00
viri
ce072894a1 docs: minor spelling fix 2021-06-04 01:18:14 -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
Matthew Borkowski
b01e5d9301 fix position of .* and .? in operator precedence table documentation 2021-05-25 00:09:28 -04:00
Matthew Borkowski
46d8e010a0 fix position of orelse and catch in precedence table and remove misplaced error union operator 2021-05-24 16:58:20 -04:00
Jakub Konka
fbd96907c9 wasm: build static archive unless -dynamic specified
This matches the behaviour for other targets in that

```
zig build-lib math.zig -target wasm32-freestanding
```

produces now `libmath.a` while

```
zig build-lib math.zig -dynamic -target wasm32-freestanding
```

is required to create a loadable Wasm module.
2021-05-21 20:24:13 +02:00
Jakub Konka
3a5d0f7700 wasm: link dynamically by default when targeting wasm
This matches the behaviour of other languages and leaves us
the ability to create actual static Wasm archives with

```
zig build-lib -static some.zig
```

which can then be combined with other Wasm object files and linked
into either a Wasm lib or executable using `wasm-ld`.

Update langref to reflect the fact we now ship WASI libc.
2021-05-20 16:54:00 +02:00
Andrew Kelley
8cfa231104 update langref, compile-error tests, safety tests
for the std.builtin re-arranging
2021-05-17 15:25:27 -07:00
Andrew Kelley
5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00
Veikka Tuominen
08b6baca12 update usage of std.testing in langref.html 2021-05-08 15:16:05 +03:00
Andrew Kelley
dc28f5c3ec Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
	lib/std/crypto/25519/field.zig
	lib/std/crypto/poly1305.zig

I had resolved those by removing `comptime` but master branch decided to
make the parameters `comptime`.

This also pulls in the updated default `zig build` install directory.
2021-04-30 23:13:17 -07:00
Devin Bayer
5fcc922ff2
add doc in Anonymous Struct Literal section for special @"0" syntax. (#8630) 2021-05-01 01:05:45 +02:00
Frank Denis
33cb660838
Doc: zig-cache/bin -> zig-out/bin (#8659) 2021-05-01 00:41:59 +02:00
Andrew Kelley
e86cee258c Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted the change that makes `suspend;` illegal in the
parser.
2021-04-24 10:44:41 -07:00
LemonBoy
0aede1a8fc stage1: Require a block after suspend
Closes #8603
2021-04-24 10:25:43 +02:00
Andrew Kelley
8dd7378013 delete packed enums from the language
No need for any such thing. Instead, provide an integer tag type for the
enum.
2021-04-22 19:21:50 -07:00
Andrew Kelley
41efdc73b9 langref: add docs for @extern 2021-04-22 16:24:14 -07:00
Devin Bayer
ca3aa02206 Update doc for struct field alignment. 2021-04-13 14:53:44 +02:00
Carlos Zúñiga
ecd38c70cc Fix langref.html anchor navigation 2021-04-10 12:51:39 -07:00
Andrew Kelley
12e2523730 docgen: correct the progress bar
It wasn't showing progress for non-code nodes.
2021-04-02 13:57:16 -07:00
Mathieu Guay-Paquet
f270bef9a4
docs: document the nosuspend keyword (#7972)
* docs: document the nosuspend keyword

* Specify that resuming from suspend is allowed in nosuspend

* Fix the description of the requirements of nosuspend

* Make use of nosuspend in some example code.

This is mainly motivated by the incorrect claim that "there would be
no way to collect the return value of amain, if it were something
other than void".
2021-04-02 14:57:42 -04:00
jacob gw
cdc5921073 docgen: fix typo
zig test test.zig-OReleaseFast -> zig test test.zig -OReleaseFast
2021-04-02 12:08:52 -04:00
Frank Denis
6993087edc Remove the base64 unsafe decoder 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
LemonBoy
d33f0d3375 docgen: Use Progress API
Really slow as usual but now looks slightly better.
2021-03-14 17:22:48 -04:00
Dave Gauer
95eb711ca8
langref: Use "single-item pointer" and "many-item pointer" (#8217)
These terms give short, descriptive names for the two pointer
types which reflect the names used in src/type.zig.
2021-03-12 20:10:55 -05:00
Josh Wolfe
a7c0234eee docgen --skip-code-tests 2021-03-07 14:52:52 +02:00
Josh Wolfe
7fbe9e7d60
update docs and grammar to allow CRLF line endings (#8063) 2021-03-03 14:30:46 -05:00
LemonBoy
d3d3e55fae langref: Update usage of Thread.spawn() 2021-02-28 17:01:30 +01:00
Andrew Kelley
8e6c2b7a47 Merge remote-tracking branch 'origin/master' into ast-memory-layout 2021-02-24 15:08:23 -07:00
Josh Wolfe
8b9434871e
Avoid concept of a "Unicode character" in documentation and error messages (#8059) 2021-02-24 08:26:13 -05:00
Veikka Tuominen
4758e0c9a6
update docgen to use new ast 2021-02-22 21:52:22 +02:00
Tadeo Kondrak
5dfe0e7e8f
Convert inline fn to callconv(.Inline) everywhere 2021-02-10 20:06:12 -07:00
Ryan Liptak
5e81b048a0 docs: Clarify that @field can work on declarations 2021-02-01 12:29:50 -08:00
Tadeo Kondrak
0b5f3c2ef9
Replace @TagType uses, mostly with std.meta.Tag 2021-01-30 22:26:44 +02:00
Tadeo Kondrak
1637d8ac80
remove @TagType 2021-01-30 13:19:58 +02:00
Jay Petacat
1595ce273e Remove deprecated stream aliases 2021-01-08 16:54:56 -05:00
Jay Petacat
a9b505fa77 Reduce use of deprecated IO types
Related: #4917
2021-01-07 23:48:58 -08:00
LemonBoy
1fbe89dc2e langref: Update langref to use {s} 2021-01-02 17:12:57 -07:00
Eleanor Bartle
49ca51fc3a Clarify condusing wording regarding % and /
Previous wording made it seem like any signed or floating-point value would be allowed at comptime, whereas negative values do not work with `%`, and negative integers do not work with `/`.
2020-12-23 17:05:37 +02:00
g-w1
51a904677c
update depreciated code (#7502)
* `zig env`:

* fix depreciated interface, update outStream -> writer
* make code more readable by updating `anytype` -> `std.fs.File.Writer`
2020-12-23 13:01:29 +02:00
Josh Holland
e93cb22541 Improve documentation for string slices.
Closes #7454.
2020-12-17 19:01:13 +02:00
Martin Wickham
676e416c86 Fix operator precedence documentation 2020-12-09 14:26:29 -05:00
LemonBoy
3f0a4ffbf4 langref: Update setEvalBranchQuota prototype 2020-12-09 20:15:58 +01:00
Vexu
98d5bfbd4d
update grammar in langref 2020-11-22 21:30:09 +02:00
Tadeo Kondrak
c002a5026a
Update code to not use unsupported calling conventions for target 2020-11-19 14:01:07 +02:00
xackus
27b73cc395 std: make meta.IntType a compile error
the function signature changed
also update langref
2020-11-18 12:57:49 +02:00
Jonas Carpay
c9dc30daf7 Fix backticked code in langref 2020-11-11 15:34:01 +02:00
data-man
99932042dc Fix reduce documentation 2020-11-09 11:47:43 +01:00
Andrew Kelley
9af53f8e02 langref: add 0.7.0 link 2020-11-09 00:37:35 -07:00
Andrew Kelley
f4ed5d7d48 langref tidy html fixup 2020-11-01 14:39:45 -07:00
LemonBoy
577b994507 docs: Add @reduce documentation 2020-11-01 14:30:31 -07:00
Veikka Tuominen
80dd432137
Merge pull request #6858 from travv0/no-star-after-dot-star
don't allow a token starting with an asterisk directly following .*
2020-10-30 16:08:04 +02:00
LemonBoy
490cafe2c5 stage1: Error out when trying to execute unreachable
Closes #6802
2020-10-29 20:06:52 -04:00
Travis
f54605ecc2 add missing Invalid_periodasterisks case in docgen 2020-10-29 14:02:08 -05:00
=
6f3c84834d Changed macosx to macos in support os to better relfect the output of zig targets 2020-10-29 14:35:29 -04:00
Paul Espinosa
ddd39b994b Use std.testing.expect in language reference samples
In this commit, the code samples in the language reference have been changed to
use `std.testing.expect` rather than `std.debug.assert` when they are
written in `test` code. This will teach Zig learners best practices when
they write their own test code.

Not all uses of `std.debug.assert` have been replaced. There are examples where
using `assert` fits the context of the sample.

Using `std.debug.assert` in test code can lead to errors if running tests in
ReleaseFast mode. In ReleaseFast mode, the `unreachable` in `assert` is
undefined behavior. It is possible that `assert` always causes `zig test` to
pass thus possibly leading to incorrect test code outcomes. The goal is to
prevent incorrect code from passing test cases.

Closes #5836
2020-10-22 15:54:57 -07:00
Andrew Kelley
e6ac082437
Merge pull request #6744 from LemonBoy/intcast-vec
stage1: Implement `@intCast` between vectors
2020-10-22 17:36:18 -04:00
Rocknest
a123378141 langref: fix equations 2020-10-20 23:22:08 +03:00
LemonBoy
475fc2934b Update langref errors 2020-10-20 10:05:44 +02:00
Nathan Bourgeois
3ab4d112e0 Update Documentation to use -O instead 2020-10-19 13:00:04 +03:00
Andrew Kelley
9ca8bcb4d9 langref cleanups
* move the opaque section to after struct, enum, union, and add
   hyperlinks
 * improve the introduction of the zig build system. don't link to the
   wiki.
 * update to the latest zig init-exe example code
 * rename headers to avoid redundant words such as "zig"
 * simplify example code
2020-10-16 21:29:33 -07:00
Nathan Michaels
eb80cc2b9e Add some basic examples for the Zig Build System. 2020-10-16 21:29:22 -07:00
Isaac Freund
7b150dd05e docs: snake_case enums/unions in langref examples
This follows the accepted change to the style guide:
https://github.com/ziglang/zig/issues/2101
2020-10-15 18:55:57 +03:00
Jakub Konka
53c63bdb73 Update WASI preopens doc section to use GPA
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-10 20:07:16 +02:00
Tadeo Kondrak
6b8ae6fffb
langref: update for opaque {} syntax 2020-10-06 22:08:29 -06:00
Tadeo Kondrak
069fbb3c01
Add opaque type syntax 2020-10-06 22:08:24 -06:00
Andrew Kelley
750b00c642 Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-29 00:27:48 -07:00
Andrew Kelley
9d0da1612e langref: use general purpose allocator in the wasi example 2020-09-29 00:24:17 -07:00
Andrew Kelley
b6556c944b fix another round of regressions in this branch
* std.log: still print error messages in ReleaseSmall builds.
   - when start code gets an error code from main, it uses std.log.err
     to report the error. this resulted in a test failure because
     ReleaseSmall wasn't printing `error: TheErrorCode` when an error
     was returned from main. But that seems like it should keep working.
     So I changed the std.log defaults. I plan to follow this up with a
     proposal to change the names of and reduce the quantity of the
     log levels.
 * warning emitted when using -femit-h when using stage1 backend; fatal
   log message when using -femit-h with self-hosted backend (because the
   feature is not yet available)
 * fix double `test-cli` build steps in zig's build.zig
 * update docgen to use new CLI
 * translate-c uses `-x c` and generates a temporary basename with a
   `.h` extension. Otherwise clang reports an error.
 * --show-builtin implies -fno-emit-bin
 * restore the compile error for using an extern "c" function without
   putting -lc on the build line. we have to know about the libc
   dependency up front.
 * Fix ReleaseFast and ReleaseSmall getting swapped when passing the
   value to the stage1 backend.
 * correct the zig0 CLI usage text.
 * update test harness code to the new CLI.
2020-09-26 21:03:38 -07:00
Ogromny
bba4576281 Fix typo in documentation 2020-09-24 13:14:03 -04:00
Isaac Freund
72f4cdb2b4 docs: update implementation status for @Type() 2020-09-24 00:01:57 -04:00
Andrew Kelley
0c70bb4fce Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-21 21:16:46 -07:00
Nathan Michaels
7801a6d17f Fix a typo. 2020-09-15 22:49:53 -04:00
Andrew Kelley
c803d334d0 update the zen of zig 2020-09-15 13:40:01 -07:00
Veikka Tuominen
41bbadbb9a
Merge pull request #6246 from Vexu/field
Remove deprecated fields on `type`
2020-09-05 13:58:02 +03:00
Vexu
09c861b829
update rest of tests 2020-09-04 22:49:14 +03:00
Vexu
6b2f4fd20d
langref: atomic ops are allowed on pointers
Closes #6217
2020-09-04 22:02:39 +03:00
Andrew Kelley
212fe21d68 zen of zig: reword the last one a little bit 2020-08-31 14:40:08 -07:00
extrasharp
d4b1ed1bc9 Add "table-wrapper" div 2020-08-24 17:29:53 -05:00
extrasharp
4d1710c899 Make changes 2020-08-24 13:12:23 -05:00
extrasharp
7d6ed1cd85 Add Keyword Reference section 2020-08-24 11:11:42 -05:00
Andrew Kelley
624e643872
Merge pull request #6046 from heidezomp/std-log-scoped-part2
std.log: (breaking) remove scope parameter from logging functions
2020-08-17 16:59:27 -04:00
Andrew Kelley
4adc052f0b langref: fix html error
thanks tidy
2020-08-14 09:33:45 -07:00
Maks S
50139aa232
langref: explain why comptime_float cannot be divided by comptime_int
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2020-08-13 22:08:37 +03:00
heidezomp
2439f67061 std.log: update documentation and example for scoped logging 2020-08-13 17:12:16 +02:00
Josias
67d684d89a docs: Fix reference to General Purpose Allocator 2020-08-12 05:08:41 -04:00
Andrew Kelley
051aadd781 std lib general purpose allocator: disable stack tracing on mips
Sadly, trying to collect stack frames goes into an infinite loop on
mips. This sets the default number of stack frames to collect to 0 on
mips.
2020-08-08 02:38:32 -07:00
Andrew Kelley
72b5ceed66 update langref in light of new general purpose allocator 2020-08-08 02:15:34 -07:00
Ashok Gautham
d1755e7f16
Add meta viewport to fix mobile rendering, add missing <code> block
Co-authored-by: Vexu <git@vexu.eu>
2020-07-27 17:10:55 +03:00
data-man
3cdc0f104e Vectors clarification in docs 2020-07-16 16:22:28 +03:00
Nathan Michaels
bc900cdeaf Document top-level doc comments, per #2288. 2020-07-13 22:57:23 +00:00
Andrew Kelley
fabdef44a8
Merge pull request #5831 from paulespinosa/langref-hello-world-more
Explain Language Ref's Hello World
2020-07-13 22:45:32 +00:00
Paul Espinosa
a8d8ce9733 Use Writer for Language Reference Hello World Example
`OutStream` has been deprecated, so the "Hello, World!" example has been
updated to use `Writer`.
2020-07-13 22:41:57 +00:00
Vexu
be1507a7af
update compile error tests and some doc comments 2020-07-12 00:54:07 +03:00
Vexu
8110639c79
add 'anytype' to stage1 and langref 2020-07-11 17:41:33 +03:00
Paul Espinosa
b45a2d72c8 Introduce Error Union and Use Writer
This commit edits the "Hello, World!" introduction. It introduces Error Union
Types. Also, it changes `outStream` to `writer` in the code example and description.
2020-07-11 18:08:00 +07:00
Paul
e57458a94f
Update doc/langref.html.in
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-11 09:10:08 +07:00
Paul
50df1334f3
Update doc/langref.html.in
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-11 09:09:57 +07:00
Paul
656b640e79
Update doc/langref.html.in
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-11 09:09:43 +07:00
Paul
5afa7f2545
Update doc/langref.html.in
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-11 09:09:07 +07:00
Paul Espinosa
f510f38592 Explain Language Ref's Hello World
To introduce the Zig programming language, the "Hello, world!" code sample now has
documentation to explain some of the features shown in the code sample
and contains links to those features in the rest of the documentation.

Writing style goals:
* Balance writing style to keep beginner and experience programmers interested.
* Be concise: allow the rest of the documentation to clarify language features.
2020-07-09 21:32:51 +07:00
Ryan Liptak
12a7dedb1f langref: Expand "if error union with optional" test case
Follow-up to #5818, closes #5819
2020-07-09 03:30:35 +00:00
xackus
2064e84cdd ci: check langref.html for html errors 2020-07-08 19:34:44 +00:00
Ryan Liptak
f77c968cf8 langref: Add test case for "if error union with optional"
This is an edge case that isn't too uncommon but is rather confusing to try to deduce without documentation, since it feels like `else` is being overloaded in this scenario and there's no obvious 'correct' behavior here. This just adds a test demonstrating how Zig currently behaves in this scenario.
2020-07-08 19:32:15 +00:00
Paul Espinosa
eeae3a8f9d Rename langref's Index to Contents (TOC)
The language reference's Index is a list of the documentation's contents in
order of appearance. This commit renames "Index" to "Contents" as in table of
contents. It also renames the HTML/CSS identifiers from "index" to "toc".
2020-07-08 19:31:38 +00:00
Andrew Kelley
3a89f214aa update more HashMap API usage 2020-07-05 21:11:42 +00:00
Chris Watson
b8d5b3e611 Add documentation for @src() builtin 2020-07-01 22:22:30 +00:00
CodeMyst
7eed220924 in docs removed "path can be absolute" for imports 2020-07-01 22:12:44 +00:00
Alexandros Naskos
ff2ddcf38d Updated @asyncCall docs 2020-06-24 19:01:38 +03:00
Jakub Konka
66e5205047 Refactor PreopenList.find()
This commit generalizes `std.fs.wasi.PreopenList.find(...)` allowing
search by `std.fs.wasi.PreopenType` union type rather than by dir
name. In the future releases of WASI, it is expected to have more
preopen types (or capabilities) than just directories. This commit
aligns itself with that vision.

This is a potentially breaking change. However, since `std.fs.wasi.PreopenList`
wasn't made part of any Zig release yet, I think we should be OK
to introduce those changes without pointing to any deprecations.
2020-06-23 21:54:36 +02:00
Sebastian
8527718350
langref - document that This works on enums too 2020-06-20 12:16:57 +01:00
Eleanor NB
605769ec25 Replaced all occurrences of std.debug.warn in the docs with std.debug.print 2020-06-19 19:03:37 -04:00
Andrew Kelley
866651a5a3
Merge pull request #5589 from kubkon/preopens-example
Add doc example for extracting WASI preopens
2020-06-12 13:40:30 -04:00
Veikka Tuominen
7d8fd45267
Merge pull request #5595 from ifreund/doc-arraylist-fix
docs: fix mention of deprecated ArrayList.span()
2020-06-12 19:10:47 +03:00
Isaac Freund
a254297953
docs: fix mention of deprecated ArrayList.span() 2020-06-12 17:58:43 +02:00
Jakub Konka
e4a8598ddd Add doc example for extracting WASI preopens 2020-06-11 22:30:02 +02:00
Jakub Konka
42c95a64d6 Update langref.html.in 2020-06-09 00:22:34 -04:00
Jakub Konka
660eef9a43 Document the builtins 2020-06-09 00:22:34 -04:00
Andrew Kelley
2952604d5d update docgen to new ast API 2020-05-23 20:40:09 -04:00
Vexu
758de71d97
Merge pull request #5353 from Vexu/parser
Self-hosted parser fixes
2020-05-16 15:56:03 +03:00
Vexu
b2f16d4484
fix infinite loop with mismatced bracket 2020-05-15 23:50:47 +03:00
Vexu
f8b99331a2
Merge pull request #5336 from Vexu/parser
Make self-hosted parser more error tolerant
2020-05-15 14:15:30 +03:00
Vexu
ac319b2734
remove useless nosuspend parsing
nosuspend cannot be used in a type expression and
all other use casesare covered by PrimaryExpr
2020-05-14 11:19:14 +03:00
Vexu
4b898893e2
Merge pull request #5254 from ifreund/top-level-struct-file-names
Apply naming conventions of structs to files
2020-05-13 19:28:14 +03:00
熊鑫
0363f3c6f3
mem.eql need slice type 2020-05-10 20:35:21 +08:00
Andrew Kelley
ba43492c0e
Merge pull request #5268 from tadeokondrak/remove-callconv-redundant-syntax
Remove syntax redundant with callconv
2020-05-07 12:42:26 -04:00
Lann
eb4fa63d3d
Remove reference to import type (#5279)
* Remove reference to import type
* Improve language in `@This()` doc
2020-05-05 19:13:35 -04:00
Tadeo Kondrak
84a0a9688c
update docs/tests for async/extern fn removal 2020-05-05 10:31:32 -06:00
Tadeo Kondrak
7ada59f873
remove nakedcc/stdcallcc/async fn/extern fn fnproto 2020-05-05 09:37:28 -06:00
Tadeo Kondrak
8d5636ebe4
Rename noasync to nosuspend in self-hosted, add rewriter 2020-05-05 05:17:33 -06:00
Isaac Freund
3a397795be
Apply naming conventions of structs to files 2020-05-02 23:28:44 +02:00
Andrew Kelley
5929e5ca0e
Merge pull request #5196 from tadeokondrak/@vector-to-@type-vector
`@Vector` -> `@Type(.Vector)`
2020-04-28 16:25:40 -04:00
Tadeo Kondrak
0673a8d576
Update language reference for std.meta.Vector 2020-04-28 00:47:14 -06:00
Tadeo Kondrak
2ef0795bfb
Update language reference for recent @Type changes 2020-04-28 00:02:14 -06:00
Andrew Kelley
448f8c2eb8 langref: add link to 0.6.0 version 2020-04-13 21:33:08 -04:00
Sören Tempel
6f5a7b8457 Update documentation of @panic
The default panic handler implementation was moved to `builtin.zig`.
2020-04-12 13:08:50 +02:00
Andrew Kelley
eefe6956fd
clarify what "not valid" means 2020-04-11 16:43:19 -04:00
emekoi
1a4f46ae7d add note about @tagName for non-exhaustive enums 2020-04-11 01:01:37 -05:00
joachimschmidt557
f1360bee1c Update docgen to new ArrayList API 2020-04-09 14:57:14 -04:00
markfirmware
c3afaa1f58 Update langref.html.in 2020-04-08 21:00:43 -04:00
xackus
b7f116a774 langref: small updates 2020-04-07 14:54:53 -04:00
daurnimator
e535057364
std: use std.ArrayList(u8).OutStream instead of std.Buffer.OutStream 2020-04-01 10:36:38 -04:00
Andrew Kelley
9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
Andrew Kelley
463b90b977
ci: fix aarch64 linux
This patch adds a workaround for #4822, disables one failing langref
example, and enables the rest of the test suite.

You win some, you lose some.
2020-03-26 19:42:28 -04:00
Andrew Kelley
93c7fa105f
Merge remote-tracking branch 'origin/llvm10'
LLVM 10 was released today
2020-03-24 09:57:09 -04:00
Andrew Kelley
13d04f9963
Merge pull request #4741 from momumi/master
allow `_` separators in number literals (stage 1)
2020-03-23 00:54:54 -04:00
Andrew Kelley
53b5aa812b
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-19 22:19:24 -04:00
Andrew Kelley
61266d2621
test & docs fixups to work with new semantics 2020-03-19 09:53:55 -04:00
Andrew Kelley
46ffc798b6
fix swapped logic for Windows
Remove `std.fs.deleteTree`. Callers instead should use
`std.fs.cwd().deleteTree`.

Add `std.fs.deleteTreeAbsolute` for when the caller has an absolute
path.
2020-03-18 16:42:47 -04:00
momumi
7aac21c6f5 allow _ separators in number literals (stage 1)
* Underscores `_` may be placed between two digits in a int/float literal
* Consecutive underscores are not allowed
* Fixed parsing bug in exponents of hexadecimal float literals.
  Exponents should always be base 10, but hex characters would be parsed
  inside the exponent and everything after them would be ignored. eg:
  `0x1.0p1ab1` would be parsed as `0x1.0p1`.
2020-03-15 12:38:35 +10:00
Andrew Kelley
faa3c40b54
fix docgen, which relied on stdout being path to binary 2020-03-14 00:46:40 -04:00
Andrew Kelley
656ba530d8
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-13 15:17:53 -04:00
Andrew Kelley
f51bec321b
Merge pull request #4707 from Vexu/small-atomics
Support atomic operations with bools and non power of two integers
2020-03-12 18:55:16 -04:00
Vexu
ec906a9771
fix codegen, update docs 2020-03-11 13:55:52 +02:00
Andrew Kelley
2bff0dda79
fix regressions found by test suite 2020-03-10 20:22:30 -04:00
Andrew Kelley
96c07674fc
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-07 12:18:41 -05:00
Andrew Kelley
0e5b48d1a2
fix @embedFile docs 2020-03-06 16:01:26 -05:00
Andrew Kelley
116e2a93f1
update docs for @TypeOf 2020-03-04 18:05:14 -05:00
Andrew Kelley
3178807657
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-04 15:35:46 -05:00
Andrew Kelley
8aaab75af0
docs: remove reference to deprecated builtins
closes #3959
2020-03-03 22:14:29 -05:00
Andrew Kelley
c4f81586f1
update docgen to new std.fs API 2020-03-03 16:01:09 -05:00
Andrew Kelley
d1cb16aace
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-03 09:44:13 -05:00
Andrew Kelley
662b5f7c60
update docs to latest Target API 2020-02-28 14:51:55 -05:00
Andrew Kelley
70bf8874d7
update docgen to new Target API 2020-02-28 14:51:55 -05:00
Andrew Kelley
dbe4d72bcf
separate std.Target and std.zig.CrossTarget
Zig now supports a more fine-grained sense of what is native and what is
not. Some examples:

This is now allowed:
-target native

Different OS but native CPU, default Windows C ABI:
-target native-windows
This could be useful for example when running in Wine.

Different CPU but native OS, native C ABI.
-target x86_64-native -mcpu=skylake

Different C ABI but otherwise native target:
-target native-native-musl
-target native-native-gnu

Lots of breaking changes to related std lib APIs.
Calls to getOs() will need to be changed to getOsTag().
Calls to getArch() will need to be changed to getCpuArch().

Usage of Target.Cross and Target.Native need to be updated to use
CrossTarget API.

`std.build.Builder.standardTargetOptions` is changed to accept its
parameters as a struct with default values. It now has the ability to
specify a whitelist of targets allowed, as well as the default target.
Rather than two different ways of collecting the target, it's now always
a string that is validated, and prints helpful diagnostics for invalid
targets. This feature should now be actually useful, and contributions
welcome to further improve the user experience.

`std.build.LibExeObjStep.setTheTarget` is removed.
`std.build.LibExeObjStep.setTarget` is updated to take a CrossTarget
parameter.

`std.build.LibExeObjStep.setTargetGLibC` is removed. glibc versions are
handled in the CrossTarget API and can be specified with the `-target`
triple.

`std.builtin.Version` gains a `format` method.
2020-02-28 14:51:54 -05:00
Andrew Kelley
f33bf48af7
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-25 16:30:40 -05:00
Vexu
d56115ef41
remove @IntType and @ArgType (mostly) from the compiler 2020-02-25 01:27:34 +02:00
Vexu
538d9a5dd8
remove uses of @ArgType and @IntType 2020-02-24 23:39:03 +02:00
Vexu
3458fb891d
remove @typeId, @memberCount, @memberName and @memberType from the compiler 2020-02-24 23:21:11 +02:00
xackus
7664c3bc11 remove @bytesToSlice, @sliceToBytes from tests, docs 2020-02-23 18:03:50 +01:00
LemonBoy
eb5e6259aa
docs: Fix wrong extern fn definition 2020-02-18 18:18:29 -05:00
Andrew Kelley
cdc5070f21
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-10 00:26:33 -05:00
Andrew Kelley
eddca50059
fix regression in docgen
I used the wrong function here
2020-02-08 00:03:06 -05:00
Andrew Kelley
4a60689309
more carefully calculate llvm field indexes
more correctly solves #4403
2020-02-07 14:54:58 -05:00
Andrew Kelley
d0b12d7726
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-03 17:30:38 -05:00
Andrew Kelley
17c8f108a4
drop @newStackCall
this was causing unrelated behavior tests to fail.

if this commit is reverted, the docs are good, but `@newStackCall` is
already deprecated in favor of `@call`, supplying the `stack` property.
2020-01-30 17:51:55 -05:00
Andrew Kelley
a95dce15ae
Merge remote-tracking branch 'origin/master' into llvm10 2020-01-29 23:33:12 -05:00
Benjamin Feng
837877ea37 Update docs to reflect new testing.allocator usage 2020-01-29 22:22:01 -06:00
Benjamin Feng
b077f3ab7d Promoted "leak_count_allocator" to the main testing.allocator 2020-01-29 22:22:00 -06:00
Benjamin Feng
c4e6e5fad6 Add explicit free to docs 2020-01-29 14:47:17 -06:00
Benjamin Feng
aa9caf5064 Create leak_count_allocator 2020-01-29 14:37:01 -06:00
Benjamin Feng
4d134a01f5 Move debug.global_allocator to testing.allocator 2020-01-29 12:21:29 -06:00
Zac
926a7adb3a Update langref.html.in
Fix typo
2020-01-27 21:39:29 -05:00
Andrew Kelley
97b2ac598b
Merge remote-tracking branch 'origin/master' into llvm10 2020-01-22 12:12:36 -05:00
Andrew Kelley
b5ac079f88
Merge pull request #4191 from Vexu/non-exhaustive-enums
Implement non-exhaustive enums
2020-01-17 14:26:12 -05:00
Vexu
df03fcf5f0 implement @bitSizeOf 2020-01-16 13:13:45 -05:00
Andrew Kelley
fbe6af81fd
Merge remote-tracking branch 'origin/master' into llvm10 2020-01-16 13:01:36 -05:00
Vexu
d84569895c
turn panics into compile errors, require at least 1 field in non-exhaustive enum 2020-01-16 09:04:11 +02:00
Vexu
02e5cb1cd4
add non-exhaustive enum to langref 2020-01-15 23:05:52 +02:00
Vexu
0ea96c11ef disallow multiline strings in test and library names 2020-01-15 14:20:48 -05:00
Shritesh
4c87281b5c [docs] Add libc dependency to sentinel-term ptr example
Fixes "dependency on library c must be explicitly specified in the build command" error
2020-01-14 13:07:08 -05:00
Emilio G. Cota
2be12b24bc doc/langref: mention that x is the sentinel in [N:x]T
Without looking at the example it is not possible to know
whether N or x is the sentinel value. Fix it.
2020-01-13 11:49:46 -05:00
hryx
c4770e7aa5 docs: update grammar to remove C strings and add anon literals 2020-01-12 04:35:45 -05:00
data-man
860d88037a Correct TypeId docs 2020-01-11 15:59:00 -05:00
LemonBoy
5ab5de89c0 New @export() handling
Use a struct as second parameter to be future proof (and also allows to
specify default values for the parameters)

Closes #2679 as it was just a matter of a few lines of code.
2020-01-09 13:43:06 -05:00
data-man
02ace4569e Correct @mulAdd's doc 2020-01-08 13:56:16 -05:00
Andrew Kelley
c0e8837ce9
update docs with regards to callconv 2020-01-06 18:26:20 -05:00
Andrew Kelley
be2483c576
fix test suite regressions 2020-01-06 18:20:31 -05:00
Andrew Kelley
0a9daeb37e
Merge branch 'cc-work' of https://github.com/LemonBoy/zig into LemonBoy-cc-work 2020-01-06 14:07:56 -05:00
Andrew Kelley
213ff939f1
fix comptime vector float ops and add test coverage
also rename `@ln` to `@log` to match libc convention.
2020-01-02 14:01:48 -05:00
LemonBoy
563d9ebfe5 Implement the callconv() annotation 2020-01-02 18:53:16 +01:00
Andrew Kelley
cb56b26900
fix float ops with respect to vectors
also remove the redundant type parameter
2020-01-01 23:27:43 -05:00
Andrew Kelley
73e535e112
Merge pull request #3683 from Vexu/atomic-float
Support floats with some atomic operations
2019-12-30 19:19:05 -05:00
Andrew Kelley
a3d04b9228
update readme tagline 2019-12-30 18:17:13 -05:00
MateuszOkulus
6c3ccea29b Make it more obvious that ifs are expressions 2019-12-28 14:26:10 -05:00
Vexu
8bb1e04449
support some atomic operations with floats 2019-12-23 11:54:47 +02:00
Nathan Michaels
f389e5e61f Clarify allowzero's interaction with optional pointers. 2019-12-17 15:44:34 -05:00
xackus
cb5a5ebb20 langref table of contents in a separate column on large displays 2019-12-16 12:25:56 -05:00
Andrew Kelley
b3cbf290c8
remove misleading documentation 2019-12-16 12:07:05 -05:00
LemonBoy
19ddbd9e9e Make sure the address is aligned for intToPtr ops
Closes #773
2019-12-15 14:41:05 -05:00
Jonathan Marler
4cb4148b35 Document sentinel type in langref 2019-12-12 19:01:22 -05:00
Robin Voetter
30715560c8
Rename @typeOf to @TypeOf in the language reference 2019-12-10 11:09:41 -05:00
Andrew Kelley
a3f6a58c77
remove var args from the language
closes #208
2019-12-09 15:27:27 -05:00
Andrew Kelley
f205d23e65
implement async function call with @call
this removes the last usage of var args in zig std lib
2019-12-09 15:27:26 -05:00
Andrew Kelley
8b3c0bbeee
update docgen to new format API 2019-12-09 00:18:01 -05:00
Andrew Kelley
03396b3caa
update docs to new fmt API 2019-12-08 23:46:50 -05:00
Andrew Kelley
525b1e8fb4
Merge pull request #3856 from ziglang/builtin-call
introduce `@call` and remove other builtin calls
2019-12-06 15:49:47 -05:00
Andrew Kelley
656cc33f8d
allow calling with a new stack to regress a bit
Calling with a new stack, with a runtime-known stack pointer (e.g.
not a global variable) is regressed with this branch. It is now a
compile-error, due to the Runtime Hint system not being smart enough
to mix a compile-time modifier field with a runtime stack field.
I'm OK with this regression because this feature is flawed (see #3268)
and may be deleted from the language.
2019-12-06 15:25:00 -05:00
Andrew Kelley
71b7f4b47f
remove @newStackCall from zig 2019-12-06 14:52:09 -05:00
Andrew Kelley
343987cd05
remove @inlineCall from zig 2019-12-06 14:12:01 -05:00
Andrew Kelley
ef83358eb6
remove @noInlineCall from zig 2019-12-05 17:37:29 -05:00
xackus
cb96a096cb docs: fix duplicate closing tag generation 2019-12-05 22:56:56 +01:00
xackus
71354498c9 docs: add html lang and minor fixes 2019-12-05 22:40:58 +01:00
xackus
ba78d71b09 docs: fix assembly example 2019-12-05 22:40:47 +01:00