Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromc3lang/c3c

Fork of C3C that adds VXCC backend support

License

LGPL-3.0, MIT licenses found

Licenses found

LGPL-3.0
LICENSE
MIT
LICENSE_STDLIB
NotificationsYou must be signed in to change notification settings

alex-s168/c3c

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2,555 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

C3 is a programming language that builds on the syntax and semantics of the C language,with the goal of evolving it while still retaining familiarity for C programmers.

It's an evolution, not a revolution: the C-likefor programmers who like C.

Precompiled binaries for the following operating systems are available:

The manual for C3 can be found atwww.c3-lang.org.

vkQuake

Thanks to full ABI compatibility with C, it's possible to mix C and C3 in the same project with no effort. As a demonstration, vkQuake was compiled with a small portion of the code converted to C3 and compiled with the c3c compiler. (The fork can be found athttps://github.com/c3lang/vkQuake)

Design Principles

  • Procedural "get things done"-type of language.
  • Try to stay close to C - only change what's really necessary.
  • 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.

C3 owes its inspiration to theC2 language: to iterate on top of C without trying to be awhole new language.

Example code

The following code showsgeneric modules (more examples can be found athttps://c3-lang.org/references/docs/examples/).

modulestack (<Type>);// Above: the parameterized type is applied to the entire module.structStack{    usz capacity;    usz size;    Type* elems;}// The type methods offers dot syntax calls,// so this function can either be called// Stack.push(&my_stack, ...) or// my_stack.push(...)fnvoid Stack.push(Stack*this, Type element){if (this.capacity ==this.size)    {this.capacity *=2;if (this.capacity <16)this.capacity =16;this.elems =realloc(this.elems, Type.sizeof *this.capacity);    }this.elems[this.size++] = element;}fn Type Stack.pop(Stack*this){assert(this.size >0);returnthis.elems[--this.size];}fnbool Stack.empty(Stack*this){return !this.size;}

Testing it out:

import stack;// Define our new types, the first will implicitly create// a complete copy of the entire Stack module with "Type" set to "int"def IntStack = Stack(<int>);// The second creates another copy with "Type" set to "double"def DoubleStack = Stack(<double>);// If we had added "define IntStack2 = Stack(<int>)"// no additional copy would have been made (since we already// have an parameterization of Stack(<int>)) so it would// be same as declaring IntStack2 an alias of IntStack// Importing an external C function is straightforward// here is an example of importing libc's printf:extern fnintprintf(char* format, ...);fnvoidmain(){    IntStack stack;// Note that C3 uses zero initialization by default// so the above is equivalent to IntStack stack = {};        stack.push(1);// The above can also be written IntStack.push(&stack, 1);        stack.push(2);// Prints pop: 2printf("pop: %d\n", stack.pop());// Prints pop: 1printf("pop: %d\n", stack.pop());        DoubleStack dstack;    dstack.push(2.3);    dstack.push(3.141);    dstack.push(1.1235);// Prints pop: 1.123500printf("pop: %f\n", dstack.pop());}

In what ways does C3 differ from C?

  • No mandatory header files
  • New semantic macro system
  • Module based name spacing
  • Slices
  • Compile time reflection
  • Enhanced compile time execution
  • Generics based on generic modules
  • "Result"-based zero overhead error handling
  • Defer
  • Value methods
  • Associated enum data
  • No preprocessor
  • Less undefined behaviour and added runtime checks in "safe" mode
  • Limited operator overloading to enable userland dynamic arrays
  • Optional pre and post conditions

Current status

The current stable version of the compiler isversion 0.6.5.

The upcoming 0.6.x releases will focus on expanding the standard library.Follow the issueshere.

If you have suggestions on how to improve the language, eitherfile an issueor discuss C3 on its dedicated Discord:https://discord.gg/qN76R87.

The compiler is currently verified to compile on Linux, Windows and MacOS.

Support matrix

PlatformNative C3 compiler available?Target supportedStack traceThreadsSocketsInline asm
Win32 x64YesYes + cross compilationYesYesYesYes*
Win32 Aarch64UntestedUntestedUntestedUntestedUntestedYes*
MacOS x64YesYes + cross compilationYesYesYesYes*
MacOS Aarch64YesYes + cross compilationYesYesYesYes*
iOS Aarch64NoUntestedUntestedYesYesYes*
Linux x86YesYesYesYesYesYes*
Linux x64YesYesYesYesYesYes*
Linux Aarch64YesYesYesYesYesYes*
Linux Riscv32YesYesYesYesYesUntested
Linux Riscv64YesYesYesYesYesUntested
ELF freestanding x86NoUntestedNoNoNoYes*
ELF freestanding x64NoUntestedNoNoNoYes*
ELF freestanding Aarch64NoUntestedNoNoNoYes*
ELF freestanding Riscv64NoUntestedNoNoNoUntested
ELF freestanding Riscv32NoUntestedNoNoNoUntested
FreeBSD x86UntestedUntestedNoYesUntestedYes*
FreeBSD x64UntestedUntestedNoYesUntestedYes*
NetBSD x86UntestedUntestedNoYesUntestedYes*
NetBSD x64UntestedUntestedNoYesUntestedYes*
OpenBSD x86UntestedUntestedNoYesUntestedYes*
OpenBSD x64UntestedUntestedNoYesUntestedYes*
MCU x86NoUntestedNoNoNoYes*
Wasm32NoYesNoNoNoNo
Wasm64NoUntestedNoNoNoNo

* Inline asm is still a work in progress

More platforms will be supported in the future.

What can you help with?

  • If you wish to contribute with ideas, please file issues or discuss on Discord.
  • Interested in contributing to the stdlib? Please get in touch on Discord.
  • Compilation instructions for other Linux and Unix variants are appreciated.
  • Would you like to contribute bindings to some library? It would be nice to have support for SDL, Raylib and more.
  • Build something with C3 and show it off and give feedback. The language is still open for significant tweaks.
  • Start work on the C -> C3 converter which takes C code and does a "best effort" to translate it to C3. The first version only needs to work on C headers.
  • Do you have some specific area you have deep knowledge of and could help make C3 even better at doing? File or comment on issues.

Installing

Installing on Windows with precompiled binaries

  1. Download the zip file:https://github.com/c3lang/c3c/releases/download/latest/c3-windows.zip(debug versionhere)
  2. Unzip exe and standard lib.
  3. If you don't have Visual Studio 17 installed you can either do so, or run themsvc_build_libraries.py Python script which will download the necessary files to compile on Windows.
  4. Runc3c.exe.

Installing on Debian with precompiled binaries

  1. Download tar file:https://github.com/c3lang/c3c/releases/download/latest/c3-linux.tar.gz(debug versionhere)
  2. Unpack executable and standard lib.
  3. Run./c3c.

Installing on Ubuntu with precompiled binaries

  1. Download tar file:https://github.com/c3lang/c3c/releases/download/latest/c3-ubuntu-20.tar.gz(debug versionhere)
  2. Unpack executable and standard lib.
  3. Run./c3c.

Installing on MacOS with precompiled binaries

  1. Make sure you have XCode with command line tools installed.
  2. Download the zip file:https://github.com/c3lang/c3c/releases/download/latest/c3-macos.zip(debug versionhere)
  3. Unzip executable and standard lib.
  4. Run./c3c.

(*Note that there is a known issue with debug symbol generation on MacOS 13, seeissue #1086)

Installing on Arch Linux

Arch includes c3c in the official 'extra' repo. It can be easily installed the usual way:

sudo pacman -S c3c# or paru -S c3c# or yay -S c3c# or aura -A c3c

There is also an AUR package for the c3c compiler :c3c-git.

You can use your AUR package manager:

paru -S c3c-git# or yay -S c3c-git# or aura -A c3c-git

Or clone it manually:

git clone https://aur.archlinux.org/c3c-git.gitcd c3c-gitmakepkg -si

Building via Docker

You can buildc3c using either an Ubuntu 18.04 or 20.04 container:

./build-with-docker.sh 18

Replace18 with20 to build through Ubuntu 20.04.

For a release build specify:

./build-with-docker.sh 20 Release

Ac3c executable will be found underbin/.

Installing on OS X using Homebrew

  1. Install CMake:brew install cmake
  2. Install LLVM 17+:brew install llvm
  3. Clone the C3C github repository:git clone https://github.com/c3lang/c3c.git
  4. Enter the C3C directorycd c3c.
  5. Create a build directorymkdir build
  6. Change directory to the build directorycd build
  7. Set up CMake build for debug:cmake ..
  8. Build:cmake --build .

Getting started with a "hello world"

Create amain.c3 file with:

module hello_world;import std::io;fnvoidmain(){io::printn("Hello, world!");}

Make sure you have the standard libraries at either../lib/std/ or/lib/std/.

Then run

c3c compile main.c3

The generated binary will by default be named after the module that contains the mainfunction. In our case that ishello_world, so the resulting binary will becalledhello_world orhello_world.exedepending on platform.

Compiling

Compiling on Windows

  1. Make sure you have Visual Studio 17 2022 installed or alternatively install the "Buildtools for Visual Studio" (https://aka.ms/vs/17/release/vs_BuildTools.exe) and then select "Desktop development with C++"
  2. Install CMake
  3. Clone the C3C github repository:git clone https://github.com/c3lang/c3c.git
  4. Enter the C3C directorycd c3c.
  5. Set up the CMake buildcmake -B build -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release
  6. Build:cmake --build build --config Release
  7. You should now have the c3c.exe

You should now have ac3c executable.

You can try it out by running some sample code:c3c.exe compile ../resources/examples/hash.c3

Note that if you run into linking issues when building, make sure that you are using the latest version of VS17.

Compiling on Ubuntu 24.04 LTS

  1. Make sure you have a C compiler that handles C11 and a C++ compiler, such as GCC or Clang. Git also needs to be installed.
  2. Install LLVM 18sudo apt-get install cmake git clang zlib1g zlib1g-dev libllvm18 llvm llvm-dev llvm-runtime liblld-dev liblld-18 libpolly-18-dev
  3. Clone the C3C github repository:git clone https://github.com/c3lang/c3c.git
  4. Enter the C3C directorycd c3c.
  5. Create a build directorymkdir build
  6. Change directory to the build directorycd build
  7. Set up CMake build:cmake ..
  8. Build:cmake --build .

You should now have ac3c executable.

You can try it out by running some sample code:./c3c compile ../resources/examples/hash.c3

Compiling on Void Linux

  1. As root, ensure that all project dependencies are installed:xbps-install git cmake llvm17 llvm17-devel lld17-devel libcurl-devel ncurses-devel zlib-devel libzstd-devel libxml2-devel
  2. Clone the C3C repository:git clone https://github.com/c3lang/c3c.git
    • If you only need the latest commit, you may want to make a shallow clone instead:git clone https://github.com/c3lang/c3c.git --depth=1
  3. Enter the directory:cd c3c
  4. Create a build directory:mkdir build
  5. Enter the build directory:cd build
  6. Create the CMake build cache:cmake ..
  7. Build:cmake --build .

Your c3c executable should have compiled properly. You may want to test it:./c3c compile ../resources/examples/hash.c3
For a sytem-wide installation, run the following as root:cmake --install .

Compiling on other Linux / Unix variants

  1. Install CMake.
  2. Install or compile LLVM and LLDlibraries (version 17+ or higher)
  3. Clone the C3C github repository:git clone https://github.com/c3lang/c3c.git
  4. Enter the C3C directorycd c3c.
  5. Create a build directorymkdir build
  6. Change directory to the build directorycd build
  7. Set up CMake build for debug:cmake ... At this point you may need to manuallyprovide the link path to the LLVM CMake directories, e.g.cmake -DLLVM_DIR=/usr/local/opt/llvm/lib/cmake/llvm/ ..
  8. Build:cmake --build .

A note on compiling for Linux/Unix/MacOS: to be able to fetch vendor librarieslibcurl is needed. The CMake script should detect it if it is available. Note thatthis functionality is non-essential and it is perfectly fine to user the compiler without it.

Licensing

The C3 compiler is licensed under LGPL 3.0, the standard library itself isMIT licensed.

Editor plugins

Editor plugins can be found athttps://github.com/c3lang/editor-plugins.

Contributing unit tests

  1. Write the test, either adding to existing test files in/test/unit/ or adda new file. (If testing the standard library, put it in the/test/unit/stdlib/ subdirectory).
  2. Make sure that the test functions have the@test attribute.
  3. Run tests and see that they pass. (Recommended settings:c3c compile-test -O0 test/unit.
    • in this exampletest/unit/ is the relative path to the test directory, so adjust as required)
  4. Make a pull request for the new tests.

Thank yous

A hugeTHANK YOU goes out to all contributors and sponsors.

A special thank you to sponsorsCaleb-o anddevdad for going the extra mile.

About

Fork of C3C that adds VXCC backend support

Resources

License

LGPL-3.0, MIT licenses found

Licenses found

LGPL-3.0
LICENSE
MIT
LICENSE_STDLIB

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C96.5%
  • CMake0.8%
  • Yacc0.8%
  • Python0.6%
  • C++0.4%
  • Roff0.3%
  • Other0.6%

[8]ページ先頭

©2009-2026 Movatter.jp