Gravity Programming Language

#language #scripting #library #script-engine #c #vm

Marco Bambini 45f6192cb1 Fixed issue 147, modules are not yet supported. 8 rokov pred
api e198a3561f Added sample code to show how to execute c methods in a c class from within Gravity. 8 rokov pred
docs 9771489462 String loadat now supports substrings using ranges 8 rokov pred
gravity.xcodeproj 1e16e6af2e Disabled default command line argument. 8 rokov pred
gravity_visualstudio b0a48bf696 Fixed most warnings 8 rokov pred
projects c5718e8649 Update README.md 8 rokov pred
src 45f6192cb1 Fixed issue 147, modules are not yet supported. 8 rokov pred
test 45f6192cb1 Fixed issue 147, modules are not yet supported. 8 rokov pred
.gitattributes 5ab3c4a9e0 Update .gitattributes 8 rokov pred
.gitignore 1602c6162c Re-added unittest folder. 8 rokov pred
.travis.yml 2402a1712e Create .travis.yml 8 rokov pred
CMakeLists.txt a6831b6a2f Use Cmake's build types to drive -g / -O2 flags 8 rokov pred
CONTRIBUTING.md b8dc2c4ee0 Fixed a Spelling mistake and MD syntax 8 rokov pred
CONTRIBUTORS b2e3aa6368 Added C++ include support and created Makefile command to build a shared object. 8 rokov pred
LICENSE 0b8e0e047f Initial commit 8 rokov pred
Makefile c2b4cb19be Renamed GRAVITY_DLL macro to GRAVITY_API to be more generic for other implementations. 8 rokov pred
README.md 7c37a1762d Indented bullets under opening an issue and PR in README 8 rokov pred
TODO.md 54696eede6 Added documentation for the import statement. 8 rokov pred
gravity.sln 371152de2f Renamed gravity to gravity_visualstudio 8 rokov pred

README.md

Build Status

Gravity Programming Language

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 Swift-like syntax.

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.

Gravity has been developed from scratch for the Creo 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 2K lines long, the multipass compiler code is about 3K lines and the shared code is about 2K lines long. The compiler and virtual machine combined add less than 200KB to the executable on a 64 bit system.

What Gravity code looks like

class Vector {
	// instance variables
	var x = 0;
	var y = 0;
	var z = 0;
	
	// constructor
	func init (a, b, c) {
		if (!a) a = 0;
		if (!b) b = 0;
		if (!c) c = 0;
		x = a; y = b; z = c;
	}
	
	// instance method (built-in operator overriding)
	func + (v) {
		if (v is Int) return Vector(x+v, y+v, z+v);
		else if (v is Vector) return Vector(x+v.x, y+v.y, z+v.z);
		return null;
	}
  	
	// instance method (built-in String conversion overriding)
	func String() {
	        // string interpolation support
		return "[\(x),\(y),\(z)]";
	}
}

func main() {
	// initialize a new vector object
	var v1 = Vector(1,2,3);
	// initialize a new vector object
	var v2 = Vector(4,5,6);
	// call + function in the vector object
	var v3 = v1 + v2;
	// returns string "[5,7,9]"
	return v3.String();
 }

Features

  • multipass compiler
  • dynamic typing
  • classes and inheritance
  • higher order functions and classes
  • lexical scoping
  • coroutines (via fibers)
  • nested classes
  • closures
  • garbage collection
  • operator overriding
  • powerful embedding api
  • built-in unit tests
  • built-in JSON serializer/deserializer

Special thanks

Gravity was supported by a couple of open source projects. The inspiration for closures comes from the elegant Lua programming language; specifically from the document Closures in Lua. For fibers, upvalues handling and some parts of the garbage collector, my gratitude goes to Bob Nystrom and his excellent Wren 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.

Documentation

The Getting Started page is a guide for downloading and compiling the language. There is also a more extensive language documentation and an internals book, which is currently in progress.
Official wiki is used to collect related projects and tools.

Community

Seems like a good idea to make a group chat for people to discuss about Gravity.

Contributing

Contributions to Gravity are welcomed and encouraged!
More information are available in the official CONTRIBUTING file.

License

Gravity is available under the permissive MIT license.