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.
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);
}
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
.
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
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.