carbon
carbon copied to clipboard
An object-oriented programming language
Carbon is a simple embeddable, object-oriented, dynamic-typed, bytecode-interpreted, scripting language written in C++11 with smart pointers for safe memory deallocation. Carbon is syntactically similar to C/C++, it's analyzer and backend written using GDScript as a reference.
What Carbon looks like
class Vector {
// non-static members
var x = 0, y = 0;
// constructor
func Vector (x = 0, y = 0) {
this.x = x;
this.y = y;
}
// built-in operator overriding
func __add(v) {
return Vector(x + v.x, y + v.y);
}
// built-in String conversion overriding
func to_string() {
return "Vector(%s, %s)" % [x, y];
}
}
func main() {
// construct a new vector object
var v1 = Vector(1,2);
// construct a new vector object
var v2 = Vector(3,4);
// call '__add' function in the vector object
var v3 = v1 + v2;
// prints "Vector(4, 6)"
println(v3);
}
Features
- Minimal setup
- Embeddable
- Dynamic typing
- Reference counting
- Object-oriented
- Enums and switch statements
- Reference, default argument
- Static, non-static members
- Operator overriding
- First class types, functions
- Callables and Iterables
Building from source
For a non-development install/embedding with a single header use carbon.h header, you only need a C++11 compiler. For more details. read usage in carbon.h
.
Requirenment
- C++11 compiler (Compiler that supports C++11 are GCC version 4.6+ and Microsoft Visual Studio 2017 or newer.)
- git (version control)
- scons 3.0 (python based build system. for Visual Studio 2019 required v3.1.1+)
- python 3.6+ (3.6+ for f-string)
Install scons
python -m pip install scons
In Linux if scons using python2 instead of 3 you'll have to edit /usr/local/bin/scons
or ~/.local/bin/scons
to ensure that it points to /usr/bin/env python3
and not python
Clone & Build
git clone https://github.com/ThakeeNathees/carbon.git
cd carbon
scons
You can specify the number of jobs scons to use to speed up the building process using the -j
flag (-j6
, -j8
). To generate Visual Studio project files add vsproj=true
argument when building. To compile using mingw in windows use use_mingw=true
argument. If your build failed feel free to open an issue. Once a successful compile the bytecode-interpreter and unit-test binaries are found in bin/
directory of the carbon root directory.