C3C Programming Language and Compiler

repository·master·Indexed 26 days ago

https://github.com/c3lang/c3c

C3C is a programming language and compiler toolchain. Documentation includes release notes from v0.7.9 to v0.8.3 covering standard library updates, new language features like @feat and $feat, and compiler flags such as --print-large-functions and --custom-libc. It also provides detailed C and C3 coding style guidelines, including naming conventions, formatting rules, and memory management patterns using arena allocators.

Tokens
8.5K
Snippets
11
Records
123
Agent score
91%

What's inside C3C

  1. Use new C3 language features (v0.6.7 and v0.6.8)

    master

    Several language features were introduced or modified in recent versions:

    • Generic Syntax (v0.6.8): Use --enable-new-generics to enable Foo{int} syntax.
    • Short Function Syntax (v0.6.7): Supports fn int test() => @pool() { return 1; }.
    • Compile-time Array Operations (v0.6.7): Supports compile-time array assignment, increment/decrement, and assignment operators (e.g., $c[1] += 3).
    • Array Initialization (v0.6.7): Supports cast-style initialization like (int[*]) { 1, 2 } and +++ on all array types.
    • Contracts (v0.6.7): @require and @ensure contracts are no longer treated as conditionals; they must explicitly evaluate to a bool.
    • Deprecations (v0.6.8): The {| |} expression blocks are deprecated. The @operator(construct) macro is also deprecated.
  2. Configure execution and output directories in C3C

    master

    In version 0.7.2, new options were added to control where executables run and where header files are generated:

    • --run-dir: Specify the directory for running the executable when using compile-run or run commands.
    • header-output: A project.json option to control the header output folder.
    • --header-output: A CLI flag to control the header output folder.
    • run-dir: A project.json option to specify the directory for running the executable.
    • quiet: A project.json option to enable quiet mode.
  3. Pass arguments to test and benchmark runners

    master

    In version 0.6.6, you can pass arguments directly to @test or @benchmark runners by using the -- separator. This allows you to pass flags and options to the underlying test runner.

    Example:

    c3c test[benchmark] -- -o --opt1 <arg1>
  4. Migrate to updated String and Mem stdlib naming (v0.7.0)

    master

    Version 0.7.0 introduced significant renaming in the standard library. If you are upgrading from a version prior to 0.7.0, update your calls as follows:

    Old NameNew Name
    string::new_from_*string::from_*
    String.to_utf16_copyString.to_utf16
    String.to_utf16_tcopyString.to_temp_utf16
    mem::temp_newmem::tnew
    mem::temp_allocmem::talloc
    mem::temp_new_arraymem::temp_array
  5. Configure default build output directories

    master

    As of version 0.6.8, c3c uses the following default directory structures for build artifacts:

    • Object files: /.build/obj/<platform>
    • LLVM assembly: llvm/<platform>
    • Assembly files: asm/<platform>
  6. Follow C3C Naming Conventions for C Source

    master

    When contributing to the C source code of c3c, follow these naming rules:

    • Constants: UPPER_SNAKE_CASE (e.g., THIS_IS_A_CONSTANT)
    • Macros: UPPER_SNAKE_CASE (e.g., MY_MACRO(123))
    • User-defined types: CapitalizedCamelCase (e.g., MyLittleType)
    • Function names: snake_case (e.g., my_little_function(123))
    • Variables: snake_case (e.g., context)

    Object-oriented pattern: Functions acting on a specific type should be prefixed with that type name in snake case (e.g., type_info_new instead of new_type_info).

  7. Update syntax for control flow (v0.7.0)

    master

    Version 0.7.0 changed the syntax for several control flow structures. Replace the old syntax with the new trailing colon format:

    • $foreach: Use $foreach $x, $y : $foo: instead of $foreach ($x, $y) : $foo.
    • $for: Use $for var $x = 0; $x < FOO; $x++: instead of $for ($x = 0; $x < FOO; $x++).
    • $switch: Use $switch $Type: instead of $switch ($Type).