Marco Bambini f82bd06179 Update index.html hai 1 semana
..
assets 1f14e125c2 Updated CSS %!s(int64=2) %!d(string=hai) anos
.nojekyll 1a1a74a2d6 New documentation engine (much more simpler to update and expand). %!s(int64=7) %!d(string=hai) anos
README.md 8dd9375cb1 Update README.md %!s(int64=6) %!d(string=hai) anos
_coverpage.md b53ffa8df4 Update _coverpage.md %!s(int64=5) %!d(string=hai) anos
_navbar.md 1a1a74a2d6 New documentation engine (much more simpler to update and expand). %!s(int64=7) %!d(string=hai) anos
_sidebar.md cec5deab43 Update _sidebar.md %!s(int64=5) %!d(string=hai) anos
bool.md 6558f66c9e Create bool.md %!s(int64=6) %!d(string=hai) anos
class.md dd10ebcd48 Add constructor and destructor to class documentation %!s(int64=4) %!d(string=hai) anos
closure.md 1a1a74a2d6 New documentation engine (much more simpler to update and expand). %!s(int64=7) %!d(string=hai) anos
contrib.md 8478d73ee6 Update contrib.md %!s(int64=6) %!d(string=hai) anos
controlflow.md 1a1a74a2d6 New documentation engine (much more simpler to update and expand). %!s(int64=7) %!d(string=hai) anos
embedding.md 6804919d33 Update embedding.md %!s(int64=5) %!d(string=hai) anos
enum.md 10ce3a3f6f Update enum.md %!s(int64=6) %!d(string=hai) anos
env.md 5c9b8c1ba2 Add documentation for ENV.argc and ENV.argv %!s(int64=5) %!d(string=hai) anos
extending.md 109756fb67 Update extending.md %!s(int64=5) %!d(string=hai) anos
fiber.md abe3b5919a Update fiber.md %!s(int64=7) %!d(string=hai) anos
file.md 4a90d3a060 Update file.md %!s(int64=5) %!d(string=hai) anos
float.md 4fe9d31bf3 Update float.md %!s(int64=6) %!d(string=hai) anos
func.md 1a1a74a2d6 New documentation engine (much more simpler to update and expand). %!s(int64=7) %!d(string=hai) anos
index.html f82bd06179 Update index.html hai 1 semana
int.md 62877fc936 Update int.md %!s(int64=6) %!d(string=hai) anos
introspection.md d588c41848 Update introspection.md %!s(int64=6) %!d(string=hai) anos
list.md ba6c168274 Update list.md %!s(int64=5) %!d(string=hai) anos
loop.md 1a1a74a2d6 New documentation engine (much more simpler to update and expand). %!s(int64=7) %!d(string=hai) anos
map.md d2b4c12af7 Update map.md %!s(int64=6) %!d(string=hai) anos
math.md 9e416fe550 Update math.md %!s(int64=7) %!d(string=hai) anos
null.md d1fcf802f4 Create null.md %!s(int64=6) %!d(string=hai) anos
object.md 1e72a5226b Update object.md %!s(int64=6) %!d(string=hai) anos
operators.md 1a1a74a2d6 New documentation engine (much more simpler to update and expand). %!s(int64=7) %!d(string=hai) anos
quickstart.md 8499492057 Removed separate unittest command line tool, replaced by gravity -t option. %!s(int64=7) %!d(string=hai) anos
range.md 348d9c6d94 Update range.md %!s(int64=6) %!d(string=hai) anos
string.md b15485b23b Update string.md %!s(int64=5) %!d(string=hai) anos
syntax.md 1a1a74a2d6 New documentation engine (much more simpler to update and expand). %!s(int64=7) %!d(string=hai) anos
system.md 8b57a2272a Update system.md %!s(int64=6) %!d(string=hai) anos
types.md 818fc3534a Update types.md %!s(int64=6) %!d(string=hai) anos
unittest.md 3476649c67 Update unittest.md %!s(int64=7) %!d(string=hai) anos

README.md

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

Comments in the C code make it easy to read and understand.

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 (manifest typing coming soon)
  • 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