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

..03-May-2022-

.github/workflows/H22-Jul-2021-7260

api/H22-Jul-2021-896734

binding/H22-Jul-2021-2,9402,470

docs/H07-May-2022-2,1521,732

examples/H22-Jul-2021-837677

gravity.xcodeproj/H22-Jul-2021-648634

gravity_visualstudio/H22-Jul-2021-1,3911,352

src/H03-May-2022-27,57818,938

test/H22-Jul-2021-12,94010,759

.gitattributesH A D22-Jul-202162 32

.gitignoreH A D22-Jul-20215.4 KiB327269

.travis.ymlH A D22-Jul-2021106 1110

CONTRIBUTING.mdH A D22-Jul-20211.4 KiB2721

CONTRIBUTORSH A D22-Jul-2021404 98

LICENSEH A D22-Jul-20211 KiB2217

MakefileH A D22-Jul-20211.6 KiB7456

README.mdH A D22-Jul-20214.4 KiB9474

TODO.mdH A D22-Jul-2021349 1210

README.md

1[![Build Status](https://travis-ci.com/marcobambini/gravity.svg?branch=master)](https://travis-ci.com/marcobambini/gravity)
2
3<p align="center" >
4<img src="https://raw.githubusercontent.com/marcobambini/gravity/master/docs/assets/images/logo-gravity.png" height="74px" alt="Gravity Programming Language" title="Gravity Programming Language">
5</p>
6
7**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 modern <a href="https://github.com/apple/swift">Swift</a>-like syntax.
8
9**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.
10
11**Gravity** has been developed from scratch for the <a href="http://creolabs.com" target="_blank">Creo</a> 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.
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
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* **optional semicolons**
71
72## Special thanks
73Gravity was supported by a couple of open-source projects. The inspiration for closures comes from the elegant <a href="http://www.lua.org" target="_blank">Lua</a> programming language; specifically from the document <a href="http://www.cs.tufts.edu/~nr/cs257/archive/roberto-ierusalimschy/closures-draft.pdf">Closures in Lua</a>. For fibers, upvalues handling and some parts of the garbage collector, my gratitude goes to <a href="http://journal.stuffwithstuff.com" target="_blank">Bob Nystrom</a> and his excellent <a href="https://github.com/munificent/wren">Wren</a> programming language. A very special thanks should also go to my friend **Andrea Donetti** who helped me debugging and testing various aspects of the language.
74
75## Documentation
76The <a href="https://marcobambini.github.io/gravity/#/README">Getting Started</a> page is a guide for downloading and compiling the language. There is also a more extensive <a href="http://gravity-lang.org">language documentation</a>. Official [wiki](https://github.com/marcobambini/gravity/wiki) is used to collect related projects and tools.
77
78## Community
79Seems like a good idea to make a group chat for people to discuss Gravity.<br> [![Join the chat at https://gitter.im/gravity-lang/](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gravity-lang/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
80
81## Contributing
82Contributions to Gravity are welcomed and encouraged!<br>
83More information is available in the official [CONTRIBUTING](CONTRIBUTING.md) file.
84* <a href="https://github.com/marcobambini/gravity/issues/new">Open an issue</a>:
85	* if you need help
86	* if you find a bug
87	* if you have a feature request
88	* to ask a general question
89* <a href="https://github.com/marcobambini/gravity/pulls">Submit a pull request</a>:
90	* if you want to contribute
91
92## License
93Gravity is available under the permissive MIT license.
94