Skip to content

Commit dc6cda6

Browse files
committed
Added some comments on project.json. Methods mentioned to be useful for all types.
1 parent 2abab23 commit dc6cda6

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

src/content/docs/FAQ/index.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,31 @@ int a = @test() {} + @test() {};
379379

380380
C3 strives for a simple grammar, and so the trade-off of having to use `;` was a fairly low price to pay for this feature.
381381

382+
## Choices in tooling
383+
384+
**Q:** Why does C3 have comments in the default `project.json`?
385+
386+
**A:** This was done as a way for users to understand what the various fields were used for. While this would more properly be
387+
a `.json5` file, many json parsers could ignore comments anyway. As tooling improves, comments will be phased out. Already it's
388+
possible to manipulate the project file from the command line.
389+
390+
**Q:** Why does C3 use JSON for `project.json`, why not YAML, TOML or something else?
391+
392+
**A:** JSON is a format with a parser in almost any language, plus it is straightforward to write a parser for.
393+
394+
Originally C3 used TOML, which is great for manual configs. However, we moved away from this exactly because the project files
395+
should be easily generated and manipulated by tools, with no strict requirement that formatting remains the same.
396+
397+
If tools manipulated hand-written TOML, there would be an expectation to retain formatting and comments in the same style, which
398+
would put a burden on tool writers.
399+
400+
**Q:** Will C3 have a package manager?
401+
402+
**A:** There will be some standard API for uploading and downloading C3 libraries. However, it will not be a full dependency manager.
403+
In an attempt to limit over-use of dependencies, each dependency will need to be downloaded separately, rather than automatically.
404+
405+
See for example the discussion here: https://github.com/c3lang/c3c/issues/2077
406+
382407
## Cross-compiling To Windows From Linux
383408
**Q:** How do I cross-compile my C3 program for Windows on Linux?
384409

src/content/docs/Language Fundamentals/functions.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ fn void print_input_with_chaining()
285285

286286
## Methods
287287

288-
Methods look exactly like functions, but are prefixed with the type name and is (usually)
289-
invoked using dot syntax:
288+
Methods look exactly like functions, but are prefixed with a type name and is (usually)
289+
invoked using dot syntax, on an instance of the type.
290290

291291
```c3
292292
struct Point
@@ -331,6 +331,21 @@ fn bool State.may_open(State state)
331331
}
332332
```
333333

334+
You can add methods to all runtime types, including built-in types:
335+
336+
```c3
337+
fn int int.add(int i, int other)
338+
{
339+
return i + other;
340+
}
341+
342+
fn void test()
343+
{
344+
int i = 3;
345+
int j = i.add(4);
346+
}
347+
```
348+
334349
### Implicit first parameters
335350

336351
Because the type of the first argument is known, it may be left out. To indicate a pointer `&` is used.
@@ -349,7 +364,7 @@ It is customary to use `self` as the name of the first parameter, but it is not
349364
### Restrictions on methods
350365

351366
- Methods on a struct/union may not have the same name as a member.
352-
- Methods only work on `typedef`, `struct`, `union` and `enum` types.
367+
- Methods on enums may not have the same name as an associated value.
353368
- When taking a function pointer of a method, use the full name.
354369
- Using subtypes, overlapping function names will be shadowed.
355370

src/content/docs/Language Overview/types.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -751,15 +751,14 @@ Const enums *cannot* have associated values and do not have the `nameof` propert
751751
### Enum type properties
752752

753753
Enum types have the following additional properties in addition to the usual properties for
754-
user defined types:
754+
user-defined types:
755755

756756
1. `associated` returns an untyped list of types for the associated values.
757757
2. `inner` returns the type of the ordinal as a `typeid`.
758-
3. `lookup(value)` lookup an enum by inlined value.
759-
4. `lookup_field(field_name, value)` lookup an enum by associated value.
760-
5. `names` returns a list containing the names of all enums.
761-
6. `from_ordinal(value)` convert an integer to an enum.
762-
7. `values` return a list containing all the enum values of an enum.
758+
3. `lookup_field(field_name, value)` lookup an enum by associated value.
759+
4. `names` returns a list containing the names of all enums.
760+
5. `from_ordinal(value)` convert an integer to an enum.
761+
6. `values` return a list containing all the enum values of an enum.
763762

764763
## Struct types
765764

@@ -878,7 +877,7 @@ union Integral
878877
}
879878
```
880879

881-
As usual unions are used to hold one of many possible values:
880+
As usual, unions are used to hold one of many possible values:
882881

883882
```c3
884883
fn void test()
@@ -927,10 +926,10 @@ which returns a list of struct members.
927926

928927
## Bitstructs
929928

930-
Bitstructs allows storing fields in a specific bit layout. A bitstruct may only contain
929+
Bitstructs allow storing fields in a specific bit layout. A bitstruct may only contain
931930
integer types and booleans, in most other respects it works like a struct.
932931

933-
The main differences is that the bitstruct has a *backing type* and each field
932+
The main difference is that the bitstruct has a *backing type* and each field
934933
has a specific bit range. In addition, it's not possible *to take the address* of a
935934
bitstruct field.
936935

@@ -983,8 +982,8 @@ fn void test()
983982
}
984983
```
985984

986-
It is however possible to pick a different endianness, in which case the entire representation
987-
will internally assume big endian layout:
985+
It is, however, possible to pick a different endianness, in which case the entire representation
986+
will internally assume big-endian layout:
988987

989988
```c3
990989
bitstruct Test : uint @bigendian

0 commit comments

Comments
 (0)