Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
692 changes: 306 additions & 386 deletions compiler/aether_module.c

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions compiler/analysis/typechecker.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion compiler/codegen/codegen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions compiler/codegen/codegen_stmt.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion docs/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ <h3>tar</h3>
<a href="tcp.html" class="module-card">
<h3>tcp</h3>
<p>std.tcp - TCP Socket Operations (alias for std.net) Raw externs end in `_raw` and return NULL/int in C-style.</p>
<span class="count">73 exports</span>
<span class="count">75 exports</span>
</a>
<a href="time.html" class="module-card">
<h3>time</h3>
Expand Down Expand Up @@ -2897,6 +2897,7 @@ <h2>Search Results</h2>
<li class="function-item" data-name="receive_raw"><a href="tcp.html#receive_raw"><span class="fn-name">receive_raw</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="receive_n_raw"><a href="tcp.html#receive_n_raw"><span class="fn-name">receive_n_raw</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="close"><a href="tcp.html#close"><span class="fn-name">close</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="close_reset_raw"><a href="tcp.html#close_reset_raw"><span class="fn-name">close_reset_raw</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="listen_raw"><a href="tcp.html#listen_raw"><span class="fn-name">listen_raw</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="listen_on_raw"><a href="tcp.html#listen_on_raw"><span class="fn-name">listen_on_raw</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="accept_raw"><a href="tcp.html#accept_raw"><span class="fn-name">accept_raw</span><span class="fn-module">tcp</span></a></li>
Expand Down Expand Up @@ -2943,6 +2944,7 @@ <h2>Search Results</h2>
<li class="function-item" data-name="wait_writable"><a href="tcp.html#wait_writable"><span class="fn-name">wait_writable</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="write_some"><a href="tcp.html#write_some"><span class="fn-name">write_some</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="close_drained"><a href="tcp.html#close_drained"><span class="fn-name">close_drained</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="close_reset"><a href="tcp.html#close_reset"><span class="fn-name">close_reset</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="connect_until_raw"><a href="tcp.html#connect_until_raw"><span class="fn-name">connect_until_raw</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="set_deadline_raw"><a href="tcp.html#set_deadline_raw"><span class="fn-name">set_deadline_raw</span><span class="fn-module">tcp</span></a></li>
<li class="function-item" data-name="deadline_raw"><a href="tcp.html#deadline_raw"><span class="fn-name">deadline_raw</span><span class="fn-module">tcp</span></a></li>
Expand Down
13 changes: 13 additions & 0 deletions docs/api/tcp.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h2>Exports</h2>
<li><a href="#receive_raw">receive_raw</a></li>
<li><a href="#receive_n_raw">receive_n_raw</a></li>
<li><a href="#close">close</a></li>
<li><a href="#close_reset_raw">close_reset_raw</a></li>
<li><a href="#listen_raw">listen_raw</a></li>
<li><a href="#listen_on_raw">listen_on_raw</a></li>
<li><a href="#accept_raw">accept_raw</a></li>
Expand Down Expand Up @@ -68,6 +69,7 @@ <h2>Exports</h2>
<li><a href="#wait_writable">wait_writable</a></li>
<li><a href="#write_some">write_some</a></li>
<li><a href="#close_drained">close_drained</a></li>
<li><a href="#close_reset">close_reset</a></li>
<li><a href="#connect_until_raw">connect_until_raw</a></li>
<li><a href="#set_deadline_raw">set_deadline_raw</a></li>
<li><a href="#deadline_raw">deadline_raw</a></li>
Expand Down Expand Up @@ -231,6 +233,11 @@ <h3 class="function-name">close <span class="kind">extern</span></h3>
<pre class="usage"><code>close(sock) <span class="arrow">-&gt;</span> int</code></pre>
<p class="signature"><span class="sig-params">sock: ptr</span></p>
</div>
<div class="function" id="close_reset_raw" data-name="close_reset_raw">
<h3 class="function-name">close_reset_raw <span class="kind">extern</span></h3>
<pre class="usage"><code>close_reset_raw(sock) <span class="arrow">-&gt;</span> int</code></pre>
<p class="signature"><span class="sig-params">sock: ptr</span></p>
</div>
<div class="function" id="listen_raw" data-name="listen_raw">
<h3 class="function-name">listen_raw <span class="kind">extern</span></h3>
<pre class="usage"><code>listen_raw(port) <span class="arrow">-&gt;</span> ptr</code></pre>
Expand Down Expand Up @@ -488,6 +495,12 @@ <h3 class="function-name">close_drained <span class="kind">fn</span></h3>
<p class="signature"><span class="sig-params">sock: ptr</span></p>
<p class="doc">Close `sock` once what the peer has already sent is read and dropped. A socket closed with bytes unread ends with a reset, and a peer that gets one may discard what it had not read yet: an alert just sent, which the peer then sees as a bare close. Bounded: at most 256 KiB, and 5 ms for each more to arrive. For the close after an error the peer must still read (the pure TLS stack's, #3368); a plain close is tcp.close.</p>
</div>
<div class="function" id="close_reset" data-name="close_reset">
<h3 class="function-name">close_reset <span class="kind">fn</span></h3>
<pre class="usage"><code>close_reset(sock)</code></pre>
<p class="signature"><span class="sig-params">sock: ptr</span></p>
<p class="doc">Close `sock` with a reset instead of an orderly close: the peer's next read or write fails with &quot;connection reset&quot; rather than seeing the end of the stream, and anything still queued to send is dropped. Closing with bytes unread resets on Linux, macOS and Windows but not on FreeBSD; this resets everywhere. For a test peer that must fail a connection the hard way; a plain close is tcp.close.</p>
</div>
<div class="function" id="connect_until_raw" data-name="connect_until_raw">
<h3 class="function-name">connect_until_raw <span class="kind">extern</span></h3>
<pre class="usage"><code>connect_until_raw(host, port, due_ms, cancel) <span class="arrow">-&gt;</span> (ptr, string)</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion docs/language-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ main() {

**A local has one type: the one its first binding gave it.** A later bare assignment is an assignment, not a new variable, so `x = 5` then `x = "s"` (or `x = true`, `x = null`) is a compile error, *cannot re-bind 'x' as string: it was bound as int by its first assignment*, rather than a C error about `const char*`. Use a new name for the other value. A name first bound inside a branch or loop body and **used after it** is one variable for the whole function: it takes the join of every binding, the one an if-expression's branches take (`if a { n = 1 } else { n = 4000000000 }` makes `n` a `long`; `f = 1.5` in one branch and `f = 2` in the other keeps `f` a `float`; `x = -1` beside a `uint32` makes `x` a `long`, and a signed value beside a `uint64` is the error below, as it is in an if-expression), unless a binding writes its type: `uint64 x = 7` in one branch makes `x` a `uint64` wherever the others are, and a binding of a value it does not hold (`x = -1` or an `int` beside it, `x = 1.5` beside `int x = 0`, `x = 300` beside `uint8 x = 7`, `x = "s"` beside `int x = 1`), or one that writes another type, is a compile error in either order: *cannot bind 'x' to this int value: it is written as uint64 in another branch or loop body of this function, which does not hold the value*. A binding of another kind anywhere in the function, or of another struct or pointer type, is the same kind of error: *cannot bind 'v' as int: it is bound as string in another branch or loop body of this function*. A `switch` case is a branch here as an `if` arm is, and so is the body of a `match` arm ([Match Statements](#match-statements)). A local of a `while` body is declared before the loop, and a name both arms of an `if`/`else` (or every case of a `switch` with a `default`, or every arm of a `match` that runs an arm for every value) bind is declared before the `if` (or `switch`, or `match`), so each is one variable whether or not it is used after them: `view = p as *Apple` in one `while` and `view = p as *Pear` in the next is that error, where a bare `ptr` or `null` binding would fit either. A read of such a local in the body before its binding, which sees the value the previous pass bound, has the binding's type (`out = "${out}${prev}"` ahead of `prev = "p${i}"` reads a string). A name bound in the bodies of separate `if`s or `for` loops and used only inside them is a separate variable per body, except a `string` local, which is always one variable for the whole function. The conversions the [table below](#casting-between-types) permits still apply at a re-bind, and the local keeps its first type: after `f = 1.5`, `f = 2` stores `2.0` and `f` stays a `float`; after `int x = 0`, `x = 2.5` stores `2`. A `string` accepts `null` (it is a nullable `const char*`), and a value that would not fit an *inferred* `int` (a 64-bit integer, a `uint32`, a float) is the narrowing error described there. Each slot of a tuple destructure that names a bound local re-binds it the same way, whether the local is in the same scope or is an outer one a closure writes (`a, b = two()` in a closure after `a, b = names()`): a slot of another kind is the same error, reported at the slot, a slot C converts is stored as the local's type, and an `int` slot binds an inferred `int`, as `x = 5` does (#2762).

**A local's scope starts after its initializer.** In `count = count() + 1` the call is the function `count`, and from that binding on, to the end of the function, `count` is the local. So is a local declared ahead of its binding because both arms of an `if` bind it: until the checker reaches the first binding in source order, the name is still the function's. A reference that comes before the binding, such as the function passed as a value, is the function too:
**A local's scope starts after its initializer.** In `count = count() + 1` the call is the function `count`, and from that binding on, to the end of the function, `count` is the local. So is a local declared ahead of its binding because both arms of an `if` bind it: until the checker reaches the first binding in source order, the name is still the function's. It lasts to the end of the function, not of the block that bound it: a local first bound in a loop or `if` body hides the function after that body too, so calling the function there is E0301. A closure's own local is the closure's, and after the closure the name is the function's again. A reference that comes before the binding, such as the function passed as a value, is the function too:

```aether,run
count() -> int { return 41 }
Expand Down
Loading
Loading