Christoffer Lerno 4da36dfed9 Optimized and improved aggregate initialization. Compound literal updated to Foo({ 1, 2 })-style. ".name = x" style initialization for named arguments and designated initializers. Added runtime messages on panics. subarrays convert implictly to pointers. len/len() functions. Fix taking slice of pointer. Vararg fixes
Consistent length typedef.

First stab at initializers.

Change compound literal to Foo({ 1, 2 }) style.

Fixed up some tests.

Optimize the zero struct codegen.

Optimize union empty initializer.

Fix issues with unions. Added alignment to globals. Added some union tests.

Use puts to emit error messages during runtime. Fixup of int[] -> int* style conversions.

Fix implicit conversion of int[3]* -> int*

Fix int[] size. Use () to invoke the length of a subarray. Fix taking a slice of a pointer. Limit the number of members in a struct.

Fixes to vararg using debug and cleanups to slices.
2020-12-22 21:55:52 +01:00
2020-03-29 17:40:03 +02:00
2020-08-09 19:01:46 +02:00
2020-06-17 12:49:04 +02:00
2019-12-29 02:56:42 +01:00
2020-11-22 22:16:19 +01:00

C3 Language

C3 is a C-like language trying to be "an incremental improvement over C" rather than a whole new language. C3 owes a lot to the ideas of the C2 language: to iterate on top of C without trying to be a whole new language.

C3 tries to be an alternative in the the C/C++ niche: fast and close to the metal.

Design Principles

  • Procedural "get things done"-type of language.
  • Try to stay close to C - only change where truly needed.
  • C ABI compatibility and excellent C integration.
  • Learning C3 should be easy for a C programmer.
  • Data is inert.
  • Avoid "big ideas" & the "more is better" fallacy.
  • Introduce some higher level conveniences where the value is great.

Example code

module hello_world;
import std::io;

func void main()
{
   io::printf("Hello, world!\n");
}

In what ways do C3 differ from C?

  • No mandatory header files
  • New semantic macro system
  • Generic modules
  • Module based
  • Subarrays (slices) and vararrays built in
  • Compile time reflection
  • Enhanced compile time execution
  • "Result" based zero overhead error handling
  • Defer
  • Value methods
  • Associated enum data
  • Built in strings
  • No preprocessor
  • Undefined behaviour trapped on debug by default
  • Optional pre and post conditions

Current status

It's possible to try out the current C3 compiler in the browser: https://ide.judge0.com/?1EFo this is courtesy of the developer of Judge0.

Design work is still being done in the design draft here: https://c3lang.github.io/c3docs/. If you have any suggestions, send a mail to christoffer@aegik.com, [file an issue] (https://github.com/c3lang/c3c/issues) or discuss C3 on its dedicated Discord: https://discord.gg/qN76R87 you are also welcome to discuss in the C3 channel on the r/ProgrammingLanguages Discord: https://discord.gg/cfu4wdk

Todo / done

  • For/while/do
  • if/ternary
  • Structs
  • Union
  • Enums
  • Value methods
  • Compound literals
  • Designated initalizers
  • Slicing syntax
  • Arrays and subarrays
  • Modules
  • $unreachable
  • Compile time assert with $assert
  • Compiler guiding assert
  • C code calling by declaring methods extern
  • Compile time variables
  • Basic macros
  • 4cc, 8cc, 2cc
  • Enum type inference in switch/assignment
  • Integer type inference
  • Error type
  • Failable error handling
  • try for conditional execution
  • catch for error handling
  • Implicit unwrap after catch
  • sizeof
  • typeof
  • 2s complement wrapping operators
  • Labelled break / continue
  • next statement
  • Expression blocks
  • Do-without-while
  • Foreach statement
  • All attributes
  • Associative array literals
  • CT type constants
  • Reflection methods
  • Anonymous structs
  • Distinct types
  • LTO/ThinLTO setup
  • Built-in linking
  • global / shared for globals
  • Complex macros
  • CT only macros evaluating to constants
  • Escape macros
  • Implicit capturing macros
  • Trailing body macros
  • Subarray initializers
  • slice initializers e.g. { [1..2] = 2 }
  • Bitstructs
  • asm section
  • $switch
  • $for
  • Pre-post conditions
  • Stdlib inclusion
  • Generic modules
  • String functions
  • Vararrays e.g. int[*]
  • Compile time incremental arrays
  • [-] Complete C ABI conformance in progress
  • Generic functions
  • [-] Debug info in progress
  • Simd vectors
  • Complex types

What can you help with?

  • If you wish to contribute with ideas, please file issues on the c3docs: https://github.com/c3lang/c3docs instead of the compiler.
  • Discuss the language on discord to help iron out syntax.
  • Stdlib work will soon start, do you want to help out building the C3 std lib?
  • Do you want to do real compiler work? Everyone is welcome to contribute.
Description
Compiler for the C3 language
Readme MIT 29 MiB
Languages
C 96.4%
CMake 0.9%
Yacc 0.7%
Shell 0.5%
C++ 0.3%
Other 1.1%