Skip to content

Commit 131bd18

Browse files
committed
update to 0.8.0
1 parent 791c7bd commit 131bd18

4 files changed

Lines changed: 27 additions & 22 deletions

File tree

content/Basics/5-for.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ weight: 5
88
C3 `for` loops are the same as in C.<br>
99
A `for` loop is made of 3 sections that are enclosed in parentheses and separated by semicolons:
1010
- the init section, which is is run once when the loop is first started and
11-
usually used to declare the counter (eg `usz i = 0`).
11+
usually used to declare the counter (eg `sz i = 0`).
1212
- the condition section, which is checked before the code in the loop body is
1313
executed each iteration of the loop. The loop will continue running until the
1414
condition is no longer true.
@@ -26,7 +26,7 @@ import std::io;
2626
fn void main()
2727
{
2828
const TIMES = 5;
29-
for (usz i = 0; i < TIMES; i = i + 1)
29+
for (sz i = 0; i < TIMES; i = i + 1)
3030
{
3131
io::printfn("Iteration %s", i);
3232
}
@@ -41,7 +41,7 @@ import std::io;
4141
fn void main()
4242
{
4343
const TIMES = 10;
44-
for (usz i = 0; i < TIMES; i++)
44+
for (sz i = 0; i < TIMES; i++)
4545
{
4646
if (i == 3)
4747
{
@@ -65,7 +65,7 @@ array or hashmap with a `for` loop can become a bit cumbersome, this is where
6565
fn void main()
6666
{
6767
int[3] items = {123, 456, 789};
68-
for (usz i = 0; i < items.len; i++)
68+
for (sz i = 0; i < items.len; i++)
6969
{
7070
items[i] += items[i];
7171
}

content/More/15-distinct type type alias.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,25 @@ weight: 15
99
- Uses the uniform `alias` syntax.
1010
- Regular type aliases are the same as C `typedef`, C3 `typedef` creates a distinct type.
1111
- Distinct types are type aliases that doesn't implicitly convert to the aliased type.
12-
- `typedef inline` types can automatically convert to its underlying type and inherit the methods of its underlying type, but otherwise works as distinct types.
12+
- `typedef inline` types can automatically convert to their underlying type and inherit the methods of their underlying type, but otherwise work as distinct types.
13+
- By default constants of the underlying type have to be cast to a distinct type, but using the `@constinit` attribute will allow implicit conversion.
1314
{{<end>}}
1415

1516
{{<defcod>}}
1617
import std::io;
1718

1819
alias MyInt = int;
19-
typedef MyId = int;
20+
typedef MyId @constinit = int;
21+
typedef StrongId = int;
2022

2123
fn void main()
2224
{
2325
MyInt x = 27;
2426
MyId y = 3;
2527
int a = x;
26-
// int b = y; <- This doesn't work
28+
StrongId b = (StrongId)42; // An explicit cast is required
29+
30+
// int c = y; <- This doesn't work
2731

2832
// Explicit conversion works
2933
x += (int)y;

content/More/19-examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,22 @@ import std::io;
6464
6565
fn void main()
6666
{
67-
usz count = 5;
67+
sz count = 5;
6868
int starting_value = 0;
6969
String res = some_func(mem, count, starting_value);
7070
io::printn(res);
7171
mem::free(res);
7272
}
7373
74-
fn String some_func(Allocator alloc, usz count, int starting_value)
74+
fn String some_func(Allocator alloc, sz count, int starting_value)
7575
{
7676
@pool()
7777
{
7878
DString buf;
7979
// Initialise the string builder using the temporary allocator
8080
// The `@pool()` ensures it will be automatically freed when the function exits
8181
buf.init(tmem);
82-
for (usz i = 0; i < count; i++) buf.appendf("[%s]", starting_value + i);
82+
for (sz i = 0; i < count; i++) buf.appendf("[%s]", starting_value + i);
8383
// Copy the final string into the passed allocator
8484
return buf.copy_str(alloc);
8585
};

content/More/6-reflection.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ weight: 6
77
---
88
{{<start>}}
99
- There are several built-in functions to inspect the code during compile time.
10-
- `.len` on arrays return their length.
10+
- `.len` on arrays and slices returns their length.
1111
- `$defined(<expr>)` returns true if the expression inside is defined.
12-
- `$alignof(<expr>)` returns alignment.
13-
- `$sizeof(<expr>)` returns size.
14-
- `$qnameof(<identifier>)` to get the qualified name of the identifier, e.g `std::io::printf`
15-
- `$nameof(<identifier>)` to get the base name of the identifier, e.g. `printf`
16-
- `$typeof(<expr>)` returns the type of the expression.
12+
- `$reflect(<identifier>)` returns a struct containing information about the identifier, often including the following properties:
13+
- `.size`: the size of the value in bytes, the stdlib provides the `@sizeof(x)` macro as a shorthand for `$reflect(x).size`.
14+
- `.alignment`: the alignment of the value in bytes, the stdlib provides `@alignof(x)` as a shorthand.
15+
- `.qname`: the qualified name of the identifier, e.g `std::io::printf`. The stdlib provides `@qnameof(x)` as a shorthand.
16+
- `.name`: the base name of the identifier, e.g. `printf`. The stdlib provides `@nameof(x)` as a shorthand.
17+
- `$Typeof(<expr>)` returns the type of the expression.
1718
- `$stringify(<expr>)` returns the expression as a string.
18-
- `<type>.sizeof` returns the size of a type.
19-
- `<type>.alignof` returns the alignment of a type.
20-
- `<type>.nameof` return the name of a type.
19+
- `<type>::size` returns the size of a type.
20+
- `<type>::align` returns the alignment of a type.
21+
- `<type>::name` return the name of a type.
2122

2223
See https://c3-lang.org/generic-programming/reflection/ for the full details.
2324
{{<end>}}
@@ -34,8 +35,8 @@ fn void main()
3435
{
3536
io::printfn("hello, world");
3637
}
37-
io::printfn($qnameof(io::printfn));
38-
io::printfn("%s %s", $sizeof(x), $sizeof(y));
39-
io::printfn("isz has size: %d", isz.sizeof);
38+
io::printfn($reflect(io::printfn).qname);
39+
io::printfn("%s %s", $reflect(x).size, @sizeof(y));
40+
io::printfn("sz has size: %d", sz::size);
4041
}
4142
{{</defcod>}}

0 commit comments

Comments
 (0)