README.md
1<p align="center">
2<img src="assets/images/logo.png" height="90px" alt="Gravity Programming Language" title="Gravity Programming Language">
3</p>
4
5**Gravity** is a powerful, dynamically typed, lightweight, embeddable programming language written in C without any external dependencies (except for stdlib). It is a class-based concurrent scripting language with a modern [Swift](https://github.com/apple/swift) like syntax.
6
7**Gravity** supports procedural programming, object-oriented programming, functional programming and data-driven programming. Thanks to special built-in methods, it can also be used as a prototype-based programming language.
8
9**Gravity** has been developed from scratch for the [Creo](https://creolabs.com) project in order to offer an easy way to write portable code for the iOS and Android platforms. It is written in portable C code that can be compiled on any platform using a C99 compiler. The VM code is about 4K lines long, the multipass compiler code is about 7K lines and the shared code is about 3K lines long. The compiler and virtual machine combined, add less than 200KB to the executable on a 64 bit system.
10
11> Comments in the C code make it easy to read and understand.
12
13## What Gravity code looks like
14
15```swift
16class Vector {
17 // instance variables
18 var x = 0;
19 var y = 0;
20 var z = 0;
21
22 // constructor
23 func init (a = 0, b = 0, c = 0) {
24 x = a; y = b; z = c;
25 }
26
27 // instance method (built-in operator overriding)
28 func + (v) {
29 if (v is Int) return Vector(x+v, y+v, z+v);
30 else if (v is Vector) return Vector(x+v.x, y+v.y, z+v.z);
31 return null;
32 }
33
34 // instance method (built-in String conversion overriding)
35 func String() {
36 // string interpolation support
37 return "[\(x),\(y),\(z)]";
38 }
39}
40
41func main() {
42 // initialize a new vector object
43 var v1 = Vector(1,2,3);
44
45 // initialize a new vector object
46 var v2 = Vector(4,5,6);
47
48 // call + function in the vector object
49 var v3 = v1 + v2;
50
51 // returns string "[1,2,3] + [4,5,6] = [5,7,9]"
52 return "\(v1) + \(v2) = \(v3)";
53 }
54 ```
55
56## Features
57* multipass compiler
58* dynamic typing (manifest typing coming soon)
59* classes and inheritance
60* higher order functions and classes
61* lexical scoping
62* coroutines (via fibers)
63* nested classes
64* closures
65* garbage collection
66* operator overriding
67* powerful embedding api
68* built-in unit tests
69* built-in JSON serializer/deserializer
70