Gravity Programming Language

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

Marco Bambini e9d58beddf Minor typo fixed 5 лет назад
.github 2c71dec8ad Create codeql-analysis.yml 5 лет назад
api a387695a1a Replaced all TABs with 4 spaces (now official indentation setting). 7 лет назад
docs 892ecd2a8c Merge pull request #333 from RobLoach/patch-2 5 лет назад
examples 985e63eb77 Updated makefile and added example.c 5 лет назад
gravity.xcodeproj a1446b95b0 Added new gravity_config.h to Xcode project 5 лет назад
gravity_visualstudio f96dc7a996 gravity_config.h - platform specific configuration. removes requiring public include dependency on gravity_visualstudio/unistd.h 5 лет назад
src e9d58beddf Minor typo fixed 5 лет назад
test 471355a274 Added ternary expr and switch stmt codegen 5 лет назад
.gitattributes 5ab3c4a9e0 Update .gitattributes 8 лет назад
.gitignore c79e185158 Update .gitignore 5 лет назад
.travis.yml 22686f96e1 Update .travis.yml 5 лет назад
CMakeLists.txt a400b138de cmake: Add BUILD_CLI option 5 лет назад
CONTRIBUTING.md b8dc2c4ee0 Fixed a Spelling mistake and MD syntax 9 лет назад
CONTRIBUTORS 795cd4533b Added my(Matan Silver) email to the contributors file 8 лет назад
LICENSE 0b8e0e047f Initial commit 9 лет назад
Makefile 985e63eb77 Updated makefile and added example.c 5 лет назад
README.md 10907e8ea5 Copy editing :) 5 лет назад
TODO.md 54696eede6 Added documentation for the import statement. 9 лет назад

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 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.

What Gravity code looks like

class Vector {
	// instance variables
	var x = 0;
	var y = 0;
	var z = 0;

	// constructor
	func init (a = 0, b = 0, 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 "[1,2,3] + [4,5,6] = [5,7,9]"
    	return "\(v1) + \(v2) = \(v3)";
 }

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
  • optional semicolons

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. 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 Gravity.

Contributing

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

License

Gravity is available under the permissive MIT license.