Commit Graph

1128 Commits

Author SHA1 Message Date
begly
da1f457e3b Fix Typo in langref.html.in 2023-06-20 11:51:11 -07:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
Arya-Elfren
c13ac52972 Fix a confusing comment in langref.html.in 2023-06-18 09:19:23 -07:00
Andrew Kelley
9370fb8b81
Merge pull request #14844 from perillo/fix-issue-13280
Fix issue 13280
2023-06-17 13:37:28 -07:00
Manlio Perillo
366e3c657f
Langref misc fix and improvement (#14695)
* langref: improve the Hello World section

Clarify that a Zig source file must have the .zig extension.

Fix a typo.

* langref: improve the Comments section

  - Document how doc comments are used by -femit-docs
  - Rename "Doc comments" to "Doc Comments", for consistency
  - Clarify that placing a doc comment in an unexpected place is a
    compiler error and add two incorrect examples
  - Document the current Autodoc behavior, when normal comments are
    interleaved with doc comments
  - Rewrite the documentation for top-level doc comments

* langref: improve the Zig Test section

Document that the test name can also be an identifier, in addition to a
string literal.

Update the test output for the first test.

Closes #14085
2023-06-17 16:35:50 -04:00
John Zhang
e95fc2023f Change outdated filename in langref 2023-06-16 23:12:45 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
jcalabro
666ae24816 Clarify @sin, @cos, @tan use radians 2023-06-14 06:04:52 -07:00
Eric Joldasov
d884d7050e
all: replace comptime try with try comptime
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-13 23:46:58 +06:00
Jacob Young
f94c66825e langref: fix error set order 2023-06-10 20:51:10 -07:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
tison
bfe02ff61a
make @boolToInt always return a u1
Signed-off-by: tison <wander4096@gmail.com>
2023-05-24 00:01:48 +00:00
Linus Groh
2088e8dc6f docgen: Rename Action enum values to snake case 2023-05-20 21:58:23 +01:00
Linus Groh
3c1bdc9781 docgen: Rename Code.Id enum values to snake case 2023-05-20 21:56:59 +01:00
Linus Groh
83d419630c docgen: Rename ExpectedOutcome enum values to snake case 2023-05-20 21:55:31 +01:00
Linus Groh
0dfe6233c0 docgen: Rename Tokenizer.State enum values to snake case 2023-05-20 21:53:12 +01:00
Linus Groh
dc4a7188dd docgen: Rename Token.Id enum values to snake case 2023-05-20 21:51:57 +01:00
Roman Frołow
21b7c48043 Add wasi_ prefix to wasm files 2023-05-15 23:34:43 +03:00
notcancername
2ce9122a00 Remove incorrect statements that the source argument to @memcpy needs to be mutable 2023-05-14 04:40:36 -07:00
Ryan Liptak
2129f28953 Update all std.mem.split calls to their appropriate function
Everywhere that can now use `splitScalar` should get a nice little performance boost.
2023-05-13 13:45:05 -07:00
Jonta
3062f9b02a Fix typo in langref
- 768 -> 786
- The link seems to be correct
- The link-text points to a seemingly unrelated issue
2023-05-12 13:39:30 +03:00
Andrew Kelley
7f7bd206dc
Merge pull request #15519 from dweiller/issue-15482
Optimize lowering of `s[start..][0..len]`
2023-05-11 08:59:44 -07:00
jcalabro
16314e0e19 Fix langref typo 2023-05-08 19:41:28 +03:00
dweiller
5bb8e9cd97 langref: mention slice-by-length pattern 2023-05-07 15:55:21 +10:00
Arnau
14c68e847a langref: Documented extern "..." use
The use of `extern "..."` for specifying the library that has the definition was undocumented.
Fixes #13906
2023-05-03 08:35:30 +03:00
Andrew Kelley
bd6f01c751 langref: fix compile error 2023-04-25 11:23:41 -07:00
Andrew Kelley
edb5e493e6 update @memcpy to require equal src and dest lens
* Sema: upgrade operands to array pointers if possible when emitting
   AIR.
 * Implement safety checks for length mismatch and aliasing.
 * AIR: make ptrtoint support slice operands. Implement in LLVM backend.
 * C backend: implement new `@memset` semantics. `@memcpy` is not done
   yet.
2023-04-25 11:23:40 -07:00
Andrew Kelley
a5c910adb6 change semantics of @memcpy and @memset
Now they use slices or array pointers with any element type instead of
requiring byte pointers.

This is a breaking enhancement to the language.

The safety check for overlapping pointers will be implemented in a
future commit.

closes #14040
2023-04-25 11:23:40 -07:00
mlugg
35d82d31be Add @inComptime builtin
Resolves: #868
2023-04-23 13:16:42 -07:00
zooster
bc8e1e1de4
Improvements to docs and text
* docs(std.math): elaborate on difference between absCast and absInt

* docs(std.rand.Random.weightedIndex): elaborate on likelihood

I think this makes it easier to understand.

* langref: add small reminder

* docs(std.fs.path.extension): brevity

* docs(std.bit_set.StaticBitSet): mention the specific types

* std.debug.TTY: explain what purpose this struct serves

This should also make it clearer that this struct is not supposed to provide unrelated terminal manipulation functionality such as setting the cursor position or something because terminals are complicated and we should keep this struct simple and focused on debugging.

* langref(package listing): brevity

* langref: explain what exactly `threadlocal` causes to happen

* std.array_list: link between swapRemove and orderedRemove

Maybe this can serve as a TLDR and make it easier to decide.

* PrefetchOptions.locality: clarify docs that this is a range

This confused me previously and I thought I can only use either 0 or 3.

* fix typos and more

* std.builtin.CallingConvention: document some CCs

* langref: explain possibly cryptic names

I think it helps knowing what exactly these acronyms (@clz and @ctz) and
abbreviations (@popCount) mean.

* variadic function error: add missing preposition

* std.fmt.format docs: nicely hyphenate

* help menu: say what to optimize for

I think this is slightly more specific than just calling it
"optimizations". These are speed optimizations. I used the word
"performance" here.
2023-04-23 21:06:21 +03:00
Manlio Perillo
658b4db223
langref: improve for loop documentation
- Add an example of iterating over consecutive integers using the
    range syntax
  - Add an example of iterating over multiple objects
  - Update the "nested break" and "nested continue" tests to use the
    range syntax, instead of a temporary array
2023-04-23 21:00:10 +03:00
Bogdan Romanyuk
316812786c langref: add documentation for noinline keyword 2023-04-23 20:56:06 +03:00
dweiller
68e4a57847 docgen: fix exe_build_err code snippets
Fixes #15297.
2023-04-22 14:30:08 +03:00
mlugg
07b7c3b31b doc: clarifications to comptime section in langref after #14819 2023-04-18 19:57:47 -07:00
Andrew Kelley
d5eab33fd2 docgen: avoid use of --enable-cache 2023-04-11 08:41:52 -07:00
jagt
c964e10821 docgen: add additional_option token; fix wasm-freestanding example
- Fix usage string `--skip-code-test` to `--skip-code-tests`.
- Added a token `{#additonal_option|-rdynamic#}` which introduce arbitrary flag to `build-exe/obj/lib` example.
- Fix wasm freestanding example, it now needs explicit export symbols to work.
2023-03-30 22:56:33 +03:00
Robin Voetter
3357c59ceb new builtins: @workItemId, @workGroupId, @workGroupSize
* @workItemId returns the index of the work item in a work group for a
  dimension.
* @workGroupId returns the index of the work group in the kernel dispatch for a
  dimension.
* @workGroupSize returns the size of the work group for a dimension.

These builtins are mainly useful for GPU backends. They are currently only
implemented for the AMDGCN LLVM backend.
2023-03-30 12:20:24 +03:00
Manlio Perillo
7ca052a6fb docgen: improve the termColor function
Make the termColor function more robust, ensuring that the generated
HTML classes are more consistent and that they are supported in the CSS.

Add documentation about the ANSI codes generated by Zig, and remove the
previous comment with the supported colors.

Improve test coverage for the termColor function, and move the tests at
the end of the file before the printShell tests.

Rename the "term color" test to "term supported colors" and add an
additional "term output from zig" test, using test data generated from
the Zig compiler.

Update the langref.html.in CSS to use the new names and remove incorrect
or obsolete colors like .t0_1, .t37 and .t37_1.

Fix support for the 1m color. Change font-weight to normal for the kbd
element, to avoid both the command (like `zig build-exe`) and the first
line of the error message having a bold font.

Rename the "shell parsed" test to "printShell".
2023-03-27 12:10:49 +02:00
Manlio Perillo
1dd26042cc docgen: remove line support in printShell
Line support in printShell breaks the support to terminal colors, when a
color is active over multiple lines. An example is when printing
reference traces.

Remove line support in printShell, since they are not really necessary
like in printSourceBlock.

In genHtml, remove an empty line when printing the execution of the
executable generated by `zig build-exe`.

Update the "shell parsed" tests.
Remove the call to log.emerg, since it is no longer supported.
Add an extra space after "--build-option1 \", as documented.

Fixes #13280
2023-03-27 12:10:49 +02:00
Phil Eaton
38ee46dda3
Two more examples of possible syntax when dealing with errors (#15042)
Add an example of if with try without else switch; add example of catch with block returning value
2023-03-23 10:06:46 +01:00
r00ster91
8642770eff langref: add missing return types to builtin functions
This should add all remaining missing return types to all builtin
functions.
For @clz, @ctz, and @popCount it uses anytype for the lack of a better
alternative. We already use this return type for other builtin functions in the langref
to indicate that the type is not always the same.
It is not possible to use anytype as the return type for regular
functions but builtin functions are special.
2023-03-21 15:05:57 +02:00
Andrew Kelley
b4d58e93ea make docgen accept --zig-lib-dir 2023-03-16 15:43:51 -07:00
Andrew Kelley
2c491d734e docgen: don't print progress in dumb terminals 2023-03-15 10:48:14 -07:00
Hashi364
4942e4e870
Resolve docs inconsistency with Overflow builtins
In 41 (Undefined Behavior) . 5 (Integer Overflow) . 3 (Builtin Overflow Functions), it is stated that

> These builtins return a bool of whether or not overflow occurred, as well as returning the overflowed bits:
> * @addWithOverflow
> * @subWithOverflow
> * @mulWithOverflow
> * @shlWithOverflow

but in their definition says that it returns a `tuple`/`struct`.

Example;
`@addWithOverflow(a: anytype, b: anytype) struct { @TypeOf(a, b), u1 }`

Co-authored-by: zooster <r00ster91@proton.me>
2023-03-13 14:47:20 +00:00
Techatrix
10c74631b3 langref: add missing comma in assembly expressions 2023-03-12 23:51:46 +02:00
Andrew Kelley
fb04ff45cd langref: small clarification to @trap 2023-03-05 17:11:46 -07:00
Andrew Kelley
e7f128c205
Merge pull request #14782 from r00ster91/trap
add `@trap` builtin
2023-03-04 16:20:31 -05:00
tranquillity-codes
c9d990d790 fix doc Build Mode 2023-03-04 23:13:15 +02:00
r00ster91
65368683ad add @trap builtin
This introduces a new builtin function that compiles down to something that results in an illegal instruction exception/interrupt.
It can be used to exit a program abnormally.

This implements the builtin for all backends.
2023-03-04 12:08:19 +01:00
Andrew Kelley
0bb178bbb2
Merge pull request #14671 from ziglang/multi-object-for
implement multi-object for loops
2023-02-19 10:10:59 -05:00