• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

assets/H22-Jul-2021-8578

README.mdH A D22-Jul-20212.3 KiB7055

_coverpage.mdH A D22-Jul-2021377 1410

_sidebar.mdH A D22-Jul-2021831 4734

bool.mdH A D22-Jul-2021236 86

class.mdH A D22-Jul-20215.2 KiB205163

closure.mdH A D22-Jul-2021677 3326

contrib.mdH A D22-Jul-2021684 96

controlflow.mdH A D22-Jul-20211.3 KiB3530

embedding.mdH A D22-Jul-20215 KiB177139

enum.mdH A D22-Jul-20211 KiB4234

env.mdH A D22-Jul-2021361 2116

extending.mdH A D22-Jul-20212.9 KiB8867

fiber.mdH A D22-Jul-20212.2 KiB9573

file.mdH A D22-Jul-20211.9 KiB8768

float.mdH A D22-Jul-20211.4 KiB3123

func.mdH A D22-Jul-20212.7 KiB9980

int.mdH A D22-Jul-20211.4 KiB4031

introspection.mdH A D22-Jul-20211.3 KiB2519

list.mdH A D22-Jul-20213.8 KiB12598

loop.mdH A D22-Jul-20213 KiB120106

map.mdH A D22-Jul-20212.2 KiB6351

math.mdH A D22-Jul-20212.8 KiB9380

null.mdH A D22-Jul-2021610 2622

object.mdH A D22-Jul-20211.7 KiB3829

operators.mdH A D22-Jul-20213.4 KiB10787

quickstart.mdH A D22-Jul-20211.7 KiB5747

range.mdH A D22-Jul-2021519 2217

string.mdH A D22-Jul-20212 KiB6248

syntax.mdH A D22-Jul-20214 KiB124107

system.mdH A D22-Jul-20211.6 KiB6352

types.mdH A D22-Jul-2021937 2115

unittest.mdH A D22-Jul-2021768 2015

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