Browse Source

Deleted trailing whitespace in src/, api/, and docs/

Filippo Costa 8 years ago
parent
commit
4fe5134d16
95 changed files with 2348 additions and 2348 deletions
  1. 2 2
      api/Makefile
  2. 33 33
      api/exec_c.c
  3. 14 14
      api/exec_gravity.c
  4. 20 20
      docs/api.html
  5. 29 29
      docs/classes.html
  6. 10 10
      docs/closures.html
  7. 7 7
      docs/contributing.html
  8. 6 6
      docs/control-flow.html
  9. 11 11
      docs/enum.html
  10. 8 8
      docs/fibers.html
  11. 26 26
      docs/functions.html
  12. 1 1
      docs/getting-started.html
  13. 7 7
      docs/index.html
  14. 12 12
      docs/internals/1_changelog.html
  15. 12 12
      docs/internals/1_files.html
  16. 11 11
      docs/internals/2_array.html
  17. 11 11
      docs/internals/2_class.html
  18. 11 11
      docs/internals/2_hash.html
  19. 11 11
      docs/internals/2_json.html
  20. 11 11
      docs/internals/2_memory.html
  21. 11 11
      docs/internals/2_overview.html
  22. 11 11
      docs/internals/2_utils.html
  23. 11 11
      docs/internals/2_visitor.html
  24. 11 11
      docs/internals/2_vm.html
  25. 11 11
      docs/internals/3_ast.html
  26. 11 11
      docs/internals/3_bytecode.html
  27. 11 11
      docs/internals/3_codegen.html
  28. 11 11
      docs/internals/3_grammar.html
  29. 11 11
      docs/internals/3_ircode.html
  30. 11 11
      docs/internals/3_lexer.html
  31. 11 11
      docs/internals/3_opcodes.html
  32. 11 11
      docs/internals/3_optimizer.html
  33. 11 11
      docs/internals/3_overview.html
  34. 11 11
      docs/internals/3_parser.html
  35. 11 11
      docs/internals/3_prattparser.html
  36. 11 11
      docs/internals/3_semantic.html
  37. 11 11
      docs/internals/3_symboltable.html
  38. 11 11
      docs/internals/4_base.html
  39. 11 11
      docs/internals/4_gc.html
  40. 11 11
      docs/internals/4_memory.html
  41. 11 11
      docs/internals/4_objmodel.html
  42. 11 11
      docs/internals/4_overview.html
  43. 11 11
      docs/internals/4_performance.html
  44. 11 11
      docs/internals/4_vm.html
  45. 11 11
      docs/internals/5_jit.html
  46. 11 11
      docs/internals/5_overview.html
  47. 12 12
      docs/internals/index.html
  48. 16 16
      docs/lists.html
  49. 13 13
      docs/loops.html
  50. 13 13
      docs/maps.html
  51. 10 10
      docs/operators.html
  52. 1 1
      docs/stylesheets/styles.css
  53. 16 16
      docs/syntax.html
  54. 17 17
      docs/system.html
  55. 18 18
      docs/types.html
  56. 7 7
      docs/unit-test.html
  57. 35 35
      src/cli/gravity.c
  58. 30 30
      src/cli/unittest.c
  59. 1 1
      src/compiler/debug_macros.h
  60. 54 54
      src/compiler/gravity_ast.c
  61. 2 2
      src/compiler/gravity_ast.h
  62. 155 155
      src/compiler/gravity_codegen.c
  63. 23 23
      src/compiler/gravity_compiler.c
  64. 36 36
      src/compiler/gravity_ircode.c
  65. 58 58
      src/compiler/gravity_lexer.c
  66. 4 4
      src/compiler/gravity_lexer.h
  67. 61 61
      src/compiler/gravity_optimizer.c
  68. 160 160
      src/compiler/gravity_parser.c
  69. 4 4
      src/compiler/gravity_parser.h
  70. 24 24
      src/compiler/gravity_semacheck1.c
  71. 8 8
      src/compiler/gravity_semacheck1.h
  72. 158 158
      src/compiler/gravity_semacheck2.c
  73. 9 9
      src/compiler/gravity_semacheck2.h
  74. 14 14
      src/compiler/gravity_symboltable.c
  75. 23 23
      src/compiler/gravity_token.c
  76. 4 4
      src/compiler/gravity_token.h
  77. 7 7
      src/compiler/gravity_visitor.c
  78. 5 5
      src/compiler/gravity_visitor.h
  79. 79 79
      src/optionals/gravity_math.c
  80. 154 154
      src/runtime/gravity_core.c
  81. 1 1
      src/runtime/gravity_core.h
  82. 176 176
      src/runtime/gravity_vm.c
  83. 1 1
      src/runtime/gravity_vm.h
  84. 1 1
      src/shared/gravity_array.h
  85. 2 2
      src/shared/gravity_delegate.h
  86. 47 47
      src/shared/gravity_hash.c
  87. 1 1
      src/shared/gravity_hash.h
  88. 28 28
      src/shared/gravity_memory.c
  89. 13 13
      src/shared/gravity_opcodes.h
  90. 155 155
      src/shared/gravity_value.c
  91. 18 18
      src/shared/gravity_value.h
  92. 33 33
      src/utils/gravity_debug.c
  93. 39 39
      src/utils/gravity_json.c
  94. 9 9
      src/utils/gravity_json.h
  95. 54 54
      src/utils/gravity_utils.c

+ 2 - 2
api/Makefile

@@ -24,7 +24,7 @@ else
 		LDFLAGS = -lm
 	else ifeq ($(UNAME_S),NetBSD)
 		# NetBSD
-		LDFLAGS = -lm 
+		LDFLAGS = -lm
 	else ifeq ($(UNAME_S),OpenBSD)
 		# OpenBSD
 		LDFLAGS = -lm
@@ -38,7 +38,7 @@ all: exec_gravity exec_c
 
 exec_gravity:	$(OBJ) $(EXEC_GRAVITY_SRC)
 	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
-	
+
 exec_c:	$(OBJ) $(EXEC_C_SRC)
 	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
 

+ 33 - 33
api/exec_c.c

@@ -36,7 +36,7 @@ static void report_error (error_type_t error_type, const char *message,
 		case GRAVITY_WARNING: type = "WARNING"; break;
 		case GRAVITY_ERROR_IO: type = "I/O"; break;
 	}
-	
+
 	if (error_type == GRAVITY_ERROR_RUNTIME) printf("RUNTIME ERROR: ");
 	else printf("%s ERROR on %d (%d,%d): ", type, error_desc.fileid, error_desc.lineno, error_desc.colno);
 	printf("%s\n", message);
@@ -54,17 +54,17 @@ static bool math_log (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 	// missing parameters check here
 	// 1. number of args
 	// 2. args type
-	
+
 	// assuming arg of type float (in a real example there should be a conversion if not float)
 	gravity_float_t n = VALUE_AS_FLOAT(args[1]);
-	
+
 	// gravity can be compiled with FLOAT as 32 or 64 bit
 	#if GRAVITY_ENABLE_DOUBLE
 	gravity_float_t result = (gravity_float_t)log(n);
 	#else
 	gravity_float_t result = (gravity_float_t)logf(n);
 	#endif
-	
+
 	gravity_vm_setslot(vm, VALUE_FROM_FLOAT(result), rindex);
 	return true;
 }
@@ -73,15 +73,15 @@ static bool math_pow (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 	// missing parameters check here
 	// 1. number of args
 	// 2. args type
-	
+
 	// assuming arg 1 of type float (in a real example there should be a conversion if not float)
 	gravity_float_t n1 = VALUE_AS_FLOAT(args[1]);
-	
+
 	// assuming arg 2 of type float (in a real example there should be a conversion if not float)
 	gravity_float_t n2 = VALUE_AS_FLOAT(args[2]);
-	
+
 	double result = pow((double)n1, (double)n2);
-	
+
 	gravity_vm_setslot(vm, VALUE_FROM_FLOAT((gravity_float_t)result), rindex);
 	return true;
 }
@@ -91,51 +91,51 @@ static bool math_pow (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 static void create_math_class (gravity_vm *vm) {
 	// create a new class (a pair of classes since we are creating a class and its meta-class)
 	gravity_class_t *c = gravity_class_new_pair(NULL, CLASS_NAME, NULL, 0, 0);
-	
+
 	// we want to register properties and methods callback to its meta-class
 	// so user can access Math.property and Math.method without the need to instantiate it
-	
+
 	// get its meta-class
 	gravity_class_t *meta = gravity_class_get_meta(c);
-	
+
 	// start binding methods and properties (special methods) to the meta class
-	
+
 	// *** LOG METHOD ***
 	// 1. create a gravity_function_t from the c function
 	gravity_function_t *logf = gravity_function_new_internal(NULL, NULL, math_log, 0);
-	
+
 	// 2. create a closure from the gravity_function_t
 	gravity_closure_t *logc = gravity_closure_new(NULL, logf);
-	
+
 	// 3. bind closure VALUE to meta class
 	gravity_class_bind(meta, "log", VALUE_FROM_OBJECT(logc));
-	
+
 	// *** POW METHOD ***
 	// 1. create a gravity_function_t from the c function
 	gravity_function_t *powf = gravity_function_new_internal(NULL, NULL, math_pow, 0);
-	
+
 	// 2. create a closure from the gravity_function_t
 	gravity_closure_t *powc = gravity_closure_new(NULL, powf);
-	
+
 	// 3. bind closure VALUE to meta class
 	gravity_class_bind(meta, "pow", VALUE_FROM_OBJECT(powc));
-	
+
 	// *** PI PROPERTY (getter only) ***
 	// 1. create a gravity_function_t from the c function
 	gravity_function_t *pif = gravity_function_new_internal(NULL, NULL, math_pi, 0);
-	
+
 	// 2. create a closure from the gravity_function_t
 	gravity_closure_t *pi_getter = gravity_closure_new(NULL, pif);
-	
+
 	// 3. create a new special function to represents getter and setter (NULL in this case)
 	gravity_function_t *f = gravity_function_new_special(vm, NULL, GRAVITY_COMPUTED_INDEX, pi_getter, NULL);
-	
+
 	// 4. create a closure for the special function
 	gravity_closure_t *closure_property = gravity_closure_new(NULL, f);
-	
+
 	// 5. bind closure VALUE to meta class
 	gravity_class_bind(meta, "pi", VALUE_FROM_OBJECT(closure_property));
-	
+
 	// LAST STEP
 	// register newly defined C class into Gravity VM
 	gravity_vm_setvalue(vm, CLASS_NAME, VALUE_FROM_OBJECT(c));
@@ -144,45 +144,45 @@ static void create_math_class (gravity_vm *vm) {
 // MARK: -
 
 int main(int argc, const char * argv[]) {
-	
+
 	// setup a minimal delegate
 	gravity_delegate_t delegate = {
 		.error_callback = report_error
 	};
-	
+
 	// compile source into a closure
 	gravity_compiler_t *compiler = gravity_compiler_create(&delegate);
 	gravity_closure_t *closure = gravity_compiler_run(compiler, source, strlen(source), 0, true);
 	if (!closure) return -1;
-	
+
 	// setup a new VM and a new fiber
 	gravity_vm *vm = gravity_vm_new(&delegate);
-	
+
 	// transfer memory from compiler to VM and then free compiler
 	gravity_compiler_transfer(compiler, vm);
 	gravity_compiler_free(compiler);
-	
+
 	// create a new math class with methods and properties and register it to the VM
 	create_math_class(vm);
-	
+
 	// expected result: 12.387436
 	// pi = 3.1415
 	// n1 = log(pi) => 1.1447
 	// n2 = pow(pi, 2.12) => 11.3221
-	
+
 	// Math class is now available from Gravity code so we can start excuting previously compiled closure
 	if (gravity_vm_runmain(vm, closure)) {
 		gravity_value_t result = gravity_vm_result(vm);
 		double t = gravity_vm_time(vm);
-		
+
 		char buffer[512];
 		gravity_value_dump(result, buffer, sizeof(buffer));
 		printf("RESULT: %s (in %.4f ms)\n\n", buffer, t);
 	}
-	
+
 	// our Math C class was not exposed to the GC (we passed NULL as vm parameter) so we would need to manually free it here
 	// free class and its methods here
-	
+
 	// free vm and base classes
 	if (vm) gravity_vm_free(vm);
 	gravity_core_free();

+ 14 - 14
api/exec_gravity.c

@@ -26,7 +26,7 @@ static void report_error (error_type_t error_type, const char *message,
 		case GRAVITY_WARNING: type = "WARNING"; break;
 		case GRAVITY_ERROR_IO: type = "I/O"; break;
 	}
-	
+
 	if (error_type == GRAVITY_ERROR_RUNTIME) printf("RUNTIME ERROR: ");
 	else printf("%s ERROR on %d (%d,%d): ", type, error_desc.fileid, error_desc.lineno, error_desc.colno);
 	printf("%s\n", message);
@@ -34,57 +34,57 @@ static void report_error (error_type_t error_type, const char *message,
 
 
 int main(int argc, const char * argv[]) {
-	
+
 	// setup a minimal delegate
 	gravity_delegate_t delegate = {
 		.error_callback = report_error
 	};
-	
+
 	// compile source into a closure
 	gravity_compiler_t *compiler = gravity_compiler_create(&delegate);
 	gravity_closure_t *closure = gravity_compiler_run(compiler, source, strlen(source), 0, true);
 	if (!closure) return -1;
-	
+
 	// setup a new VM and a new fiber
-	gravity_vm *vm = gravity_vm_new(&delegate);	
-	
+	gravity_vm *vm = gravity_vm_new(&delegate);
+
 	// transfer memory from compiler to VM and then free compiler
 	gravity_compiler_transfer(compiler, vm);
 	gravity_compiler_free(compiler);
-	
+
 	// load closure into VM context
 	gravity_vm_loadclosure(vm, closure);
-	
+
 	// create parameters (that must be boxed) for the closure
 	gravity_value_t n1 = VALUE_FROM_INT(30);
 	gravity_value_t n2 = VALUE_FROM_INT(50);
 	gravity_value_t params[2] = {n1, n2};
-	
+
 	// lookup add closure
 	gravity_value_t add = gravity_vm_getvalue(vm, "add", strlen("add"));
 	if (!VALUE_ISA_CLOSURE(add)) return -2;
-	
+
 	// execute add closure and print result
 	if (gravity_vm_runclosure(vm, VALUE_AS_CLOSURE(add), add, params, 2)) {
 		gravity_value_t result = gravity_vm_result(vm);
 		printf("add result ");
 		gravity_value_dump(result, NULL, 0);
 	}
-	
+
 	// lookup mul closure
 	gravity_value_t mul = gravity_vm_getvalue(vm, "mul", strlen("mul"));
 	if (!VALUE_ISA_CLOSURE(mul)) return -3;
-	
+
 	// execute mul closure and print result
 	if (gravity_vm_runclosure(vm, VALUE_AS_CLOSURE(mul), mul, params, 2)) {
 		gravity_value_t result = gravity_vm_result(vm);
 		printf("mul result ");
 		gravity_value_dump(result, NULL, 0);
 	}
-	
+
 	// free vm and core classes
 	gravity_vm_free(vm);
 	gravity_core_free();
-	
+
     return 0;
 }

+ 20 - 20
docs/api.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -73,11 +73,11 @@
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">API</h1><hr>
-         				
+
 			<p class="section-content">
 				Gravity can be extended at runtime using C API. The right step to proceed is usually to create a new class, then add methods and proporties to it and finally register that class inside the VM.
 			</p>
@@ -88,53 +88,53 @@
 		printf("%s\n", message);
 		exit(0);
 	}
-	
-	// function to be execute inside Gravity VM		
+
+	// function to be execute inside Gravity VM
 	bool my_function (gravity_vm *vm, gravity_value_t *args,
 	                  uint16_t nargs, uint32_t rindex) {
 		// do something useful here
 	}
-	
-	// Configure VM delegate		
+
+	// Configure VM delegate
 	gravity_delegate_t delegate = {.error_callback = report_error};
-	
+
 	// Create a new VM
 	gravity_vm *vm = gravity_vm_new(&delegate);
-	
+
 	// Create a new class
 	gravity_class_t *c = gravity_class_new_pair (vm, "MyClass", NULL, 0, 0);
-	
+
 	// Allocate and bind closures to the newly created class
 	gravity_closure_t *closure = gravity_closure_new(vm, my_function);
 	gravity_class_bind(c, "myfunc", VALUE_FROM_OBJECT(closure));
-	
+
 	// Register class inside VM
 	gravity_vm_setvalue(vm, "MyClass", VALUE_FROM_OBJECT(c));
 			</code></pre>
-			
+
 			<p>Using the above C code a "MyClass" class has been registered inside the VM and ready to be used by Gravity:</p>
-			<pre><code class="swift">		
+			<pre><code class="swift">
 	func main() {
 		// allocate a new class
 		var foo = MyClass();
-		
+
 		// execute the myfunc C function
 		foo.myfunc();
 	}
 			</code></pre>
-			
+
 			<!--<h4 class="section-h4">Execute Gravity code from C</h4>
 			<p></p>
 			<pre><code class="cpp">
 			</code></pre>-->
-			
+
 			<h4 class="section-h4">Bridge API</h4>
 			<p>Gravity C API offers much more flexibility using the delegate bridge API.
 			<br>TO DO: more information here.</p>
 			<br>TO DO: post objc bridge.</p>
          	</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -147,14 +147,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 29 - 29
docs/classes.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,24 +75,24 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Class</h1><hr>
-			
+
 			<p class="section-content">
 			Every value in Gravity is an object, and every object is an instance of a class. Classes define an object's behavior and state. Behavior is defined by methods which live in the class. Every object of the same class supports the same methods. State is defined in fields, whose values are stored in each instance.<br><br>Like <a href="functions.html">functions</a> a <strong>Class is a first class object</strong>, that means that it can be stored in local variables (even in <a href="list.html">Lists</a> or <a href="map.html">Maps</a>), passed as a function parameter or returned by a function. Gravity supports <strong>nested classes</strong> and <strong>single inheritance</strong>.
 			</p>
-			
+
 			<h4 class="section-h4">Defining a class</h4>
 			<p>Like most programming languages the class keyword is used to declare a new class:</p>
 			<pre><code class="swift">
 	class Italy {
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Instantiate a class</h4>
 			<p>A class in gravity can be instantiated by simply executing it (without the new keyword):</p>
 			<pre><code class="swift">
 	var instance = Italy();
 			</code></pre>
-			
+
 			<h4 class="section-h4">Methods</h4>
 			<p>Functions declared inside a class are called methods and are used to add behaviors to objects that belongs to a specific class:</p>
 			<pre><code class="swift">
@@ -102,43 +102,43 @@
 		}
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Properties</h4>
 			<p>Variables declared inside a class are called properties and are used to add states to objects that belongs to a specific class:</p>
 			<pre><code class="swift">
 	class Italy {
 		var population = 60656000;
 		var area = 301340; // in km2
-				
+
 		func density() {
 			return population/area;
 		}
 	}
-			
+
 	func main() {
 		var it = Italy();
 		return it.density();	// returns 201.287582
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Class methods and properties</h4>
 			<p>A class method (or property) is a method (or property) that operates on class objects rather than instances of the class. In Gravity you can specify a class method (or property) using the static keyword:</p>
 			<pre><code class="swift">
 	class Italy {
 		static var population = 60656000;
 		static var area = 301340; // in km2
-				
+
 		static func density() {
 			return population/area;
 		}
 	}
-			
+
 	func main() {
 		return Italy.density();
 	}
-			
+
 			</code></pre>
-			
+
 			<h4 class="section-h4">Getters and Setters:</h4>
 			<p>As a convenient way to execute some code when a property is read or written, Gravity fully support custom getters and setters:</p>
 			<pre><code class="swift">
@@ -153,60 +153,60 @@
 			set (newb) {_a = newb * 50;}	// parameter name can be specified
 		};
 	}
-			
+
 	func main() {
 		var f = foo();
 		f.a = 14;		// 14*100 = 1400
 		return f.a;		// 1400/2 = 700
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Adding methods at runtime:</h4>
 			<p>Sometimes you need to add methods at runtime to a particular instance, this is far more efficient than subclassing and in many cases it could be a decision than can be applied only at runtime. Gravity provides a convenient <strong>bind</strong> method specifically developed to manage this feature:</p>
 			<pre><code class="swift">
 	class foo {
 		func f1() {System.print("Hello from f1");}
 	}
-	
+
 	func main() {
 		var obj = foo();
 		obj.f1();	// Output: Hello from f1
-		
+
 		// add a new f2 method to obj instance
 		obj.bind("f2", {System.print("Hello from f2");});
 		obj.f2();	// Output: Hello from f2
-		
+
 		// replace f1 method
 		obj.bind("f1", {System.print("Hello from f1 new");});
 		obj.f1();	// Output: Hello from f1 new
-		
+
 		// with unbind you can remove an existing method
 		obj.unbind("f2");
 		obj.f2();	// RUNTIME ERROR: Unable to find f2
 	}
 
 			</code></pre>
-			
+
 			<h4 class="section-h4">Nested classes:</h4>
 			<p>There are many cases where nested classes can lead to more readable and maintainable code, for example as a way of logically grouping classes that are only used in one place:</p>
 			<pre><code class="swift">
 	class Database {
 		public var query;
-	
+
 		class RecordSet {
 			public var sql;
-		
+
 			public func run() {
 				if (!sql) return 0;
 				System.print(sql);
 				return sql.length();
 			}
-		
+
 			func init() {
 				System.print("RecordSet init called");
 			}
 		}
-	
+
 		func init() {
 			System.print("Database init called");
 			query = RecordSet();
@@ -219,10 +219,10 @@
 		return db.query.run();
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Access specifiers</h4>
 			<p>The public and private keywords can be used to restrict access to specific part of code.</p>
-			
+
          	</div>
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
@@ -236,14 +236,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 10 - 10
docs/closures.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,7 +75,7 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Closure</h1><hr>
-			
+
 			<p class="section-content">
 			Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures can capture and store references to any constants and variables from the context in which they are defined. Closures can be nested and can be anonymous (without a name):
 			</p>
@@ -91,25 +91,25 @@
 		return addTen(20);	// result is 30
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Disassemble</h4>
 			<p>A closure can be disassembled in order to reveal its bytecode:</p>
 			<pre><code class="swift">
 	func sum (a,b) {
 		return a + b;
 	}
-	
+
 	func main() {
 		System.print(sum.disassemble());
 	}
-	
+
 	// Output:
 	// 000000 ADD 3 1 2
 	// 000001 RET 3
 			</code></pre>
-			
+
 			<p>TO DO: more examples and explanations</p>
-			
+
          	</div>
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
@@ -123,14 +123,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 7 - 7
docs/contributing.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -73,11 +73,11 @@
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Contributing</h1><hr>
-         				
+
 			<p class="section-content">
 				If you find any grammatical issue, please report it using Github Issues. Or, if some sentence or paragraph is difficult to understand, feel free to make a pull request. This book is in active development and I'll regularly update and improve it. I am not a native English speaker so feel free to correct me if something is not properly written.<br><br>If you have any question related to the material or the development of the book, feel free to open a GitHub issue or to contact me.</p>
 				<h4 class="section-h4">About me</h4>
@@ -89,7 +89,7 @@
 			</p>
          	</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -102,14 +102,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 6 - 6
docs/control-flow.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,11 +75,11 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Control flow</h1><hr>
-			
+
 			<p class="section-content">
 			Gravity provides a variety of control flow statements. Control flow is used to determine which chunks of code are executed and how many times. Branching statements and expressions decide whether or not to execute some code and looping ones execute something more than once.
 			</p>
-			
+
 			<h4 class="section-h4">If statement</h4>
 			<p>It is often useful to execute different pieces of code based on certain conditions. You might want to run an extra piece of code when an error occurs, or to display a message when a value becomes too high or too low. To do this, you make parts of your code conditional. In its simplest form, the if statement has a single if condition. It executes a set of statements only if that condition is true:</p>
 			<pre><code class="swift">
@@ -125,14 +125,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/enum.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,9 +75,9 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Enum</h1><hr>
-			
+
 			<p class="section-content">
-			Enums defines a common type for a group of related values, if you are familiar with C, you will know that C enumerations assign related names to a set of integer values, enum in Gravity are much more flexible and enables you to assign even non integer values: 
+			Enums defines a common type for a group of related values, if you are familiar with C, you will know that C enumerations assign related names to a set of integer values, enum in Gravity are much more flexible and enables you to assign even non integer values:
 			</p>
 			<pre><code class="swift">
 	enum state {
@@ -87,31 +87,31 @@
 		undetermined = 666,
 		error			// 667
 	};
-	
+
 	enum math {
 		pi = 3.141592,
 		e = 2.718281,
 		goldratio = 1.618033
 	};
-	
+
 	enum company {
 		ceo = "Gauss",
 		cto = "Eurel",
 		cfo = "Nostradamus"
 	}
-	
+
 	enum mixed {
 		one = "Hello World",
 		two = 3.1415,
 		three = 666,
 		four = true
 	}
-	
+
 	func main() {
 		var a = state.active;	// a = 1
 		var b = math.pi;	// b = 3.1415
 		var c = company.ceo;	// c = "Gauss"
-		var d = mixed.four;	// d = true 
+		var d = mixed.four;	// d = true
 	}
 			</code></pre>
 			<p>Enum is a static operator, which means that at compile time the real value of the enum item is automatically replaced by Gravity.</p>
@@ -128,14 +128,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 8 - 8
docs/fibers.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -73,11 +73,11 @@
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Fiber</h1><hr>
-         				
+
 			<p class="section-content">
 			A Fibers (or coroutine as called in other languages) are special functions that can be interrupted at any time by the user. When a conventional function is invoked, execution begins at the start, and once a function exits, it is finished. By contrast, Fibers can exit by calling other Fibers, which may later return to the point where they were invoked in the original coroutine:
 			</p>
@@ -88,7 +88,7 @@
 			Fiber.yield()
 			System.print("fiber 2");
 		});
-	
+
 		System.print("main 1");
 		fiber()
 		System.print("main 2");
@@ -105,7 +105,7 @@
 			<p>TO DO: more explanations and examples</p>
          	</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -118,14 +118,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 26 - 26
docs/functions.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,7 +75,7 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Function</h1><hr>
-			
+
 			<p class="section-content">
 			Functions are first class objects like <a href="types.html">Int</a> or <a href="types.html">String</a> and can be stored in local variables (even in <a href="list.html">Lists</a> or <a href="map.html">Maps</a>), passed as function parameters or returned by a function. Functions can be implemented in Gravity or in a <a href="api.html">native language</a> with calling conventions compatible with ANSI C.<br><br>Functions are called by value. This means that foo(1) calls the function which is the value of the variable foo. Calling a value that is not a function will raise a runtime error.
 			</p>
@@ -86,62 +86,62 @@
 		return a + b;
 	}
 			</code></pre>
-			
+
 			<pre><code class="swift">
 	func f1() {
 		return 10;
 	}
-			
+
 	func f2() {
 		return f1;
 	}
-			
+
 	func main() {
 		// a is now function f2
 		var a = f2;
-				
+
 		// b is now the return value of f2 which is function f1
 		var b = a();
-				
+
 		// return value is f1() which is 10
 		return b();
-				
+
 		// above code is equivalent to
 		return f2()();
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Function parameters</h4>
-			<p>Functions aren’t very useful if you can’t pass values to them so you can provide a parameter list in the function declaration. Gravity performs no check on the number of parameters so you can call a function providing more or less parameters.</p> 
+			<p>Functions aren’t very useful if you can’t pass values to them so you can provide a parameter list in the function declaration. Gravity performs no check on the number of parameters so you can call a function providing more or less parameters.</p>
 			<pre><code class="swift">
 	func sum(a, b) {
 		return a + b;
 	}
-			
+
 	// execute the sum function
 	// and returns 30 as result
 	sum(10,20);
 			</code></pre>
-			
+
 			<p>If a function is called with missing arguments (less than declared), the missing values are set to <strong>undefined</strong>.</p>
 			<pre><code class="swift">
 	// sum modified to take in account missing arguments
 	func sum(a, b) {
 		// equivalent to if (a == undefined) a = 30;
 		if (!a) a = 30;
-		
+
 		// equivalent to if (b == undefined) b = 50;
 		if (!b) b = 50;
-		
+
 		return a + b;
 	}
-			
+
 	// execute the sum function without any argument
 	// a has a 30 default value and b has a 50 default value
 	// return value is 80
 	sum();
 			</code></pre>
-			
+
 			<p>If a function is called with more arguments (more than declared), the additional arguments can be accessed using the <strong>_args</strong> array.</p>
 			<pre><code class="swift">
 	// sum modified to accept a variable number of arguments
@@ -152,29 +152,29 @@
 		}
 		return tot;
 	}
-			
+
 	// execute the sum function with a variable number
 	// of arguments returns 550 as result
 	sum(10,20,30,40,50,60,70,80,90,100);
 			</code></pre>
-			
+
 			<h4 class="section-h4">Recursion</h4>
-			<p>Function recursion is fully supported in Gravity (current function can be accessed using the _func reserved keyword):</p> 
+			<p>Function recursion is fully supported in Gravity (current function can be accessed using the _func reserved keyword):</p>
 			<pre><code class="swift">
 	func fibonacci (n) {
 		if (n<2) return n;
 		// could be written as return _func(n-2) + _func(n-1)
 		return fibonacci(n-2) + fibonacci(n-1);
  	}
- 
+
 	func main() {
 		return fibonacci(20);
  	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Returning values</h4>
-			<p>A function without a return statement returns <strong>null</strong> by default. You can explicitly return a value using a return statement.</p> 
-			
+			<p>A function without a return statement returns <strong>null</strong> by default. You can explicitly return a value using a return statement.</p>
+
          	</div>
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
@@ -188,14 +188,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 1 - 1
docs/getting-started.html

@@ -108,7 +108,7 @@
 				<ul>
 					<li><a href="https://github.com/Dohxis/vscode-gravity">Visual Studio Code</a></li>
 					<li><a href="https://github.com/Tribex/atom-language-gravity">Atom</a></li>
-					<li><a href="https://github.com/hallzy/gravity.vim">vim</a></li> 
+					<li><a href="https://github.com/hallzy/gravity.vim">vim</a></li>
 					<li><a href="https://github.com/marcobambini/bbedit-gravity">BBEdit/TextWrangler</a></li>
 				</ul>
 			</p>

+ 7 - 7
docs/index.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -73,11 +73,11 @@
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Introduction</h1><hr>
-         				
+
 			<p class="section-content">
 				<strong>Gravity</strong> is a powerful, dynamically typed, lightweight, embeddable programming language written in C without any external dependency (except stdlib). It is a class based concurrent scripting language with a modern <a href="https://github.com/apple/swift">Swift</a> like syntax.<br><br>
 				<strong>Gravity</strong> supports procedural programming, object-oriented programming, functional programming and data-driven programming. Thanks to built-in special methods it can also be used as a prototype-based programming language.</p>
@@ -85,7 +85,7 @@
 				<p><strong>Gravity</strong> has been developed from scratch for the <a href="http://creolabs.com/">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 in any platform using a C99 compiler. VM code is about 2K lines long, multipass compiler code is about 3K lines and shared code is about 2K lines. Compiler and virtual machine together add less than 200KB to the executable size in a 64bit system.</p>
          	</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -98,14 +98,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 12 - 12
docs/internals/1_changelog.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html" class="active"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,17 +89,17 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Change log</h1><hr>
@@ -107,10 +107,10 @@
 				<ul>
 					<li>First public release</li>
 				</ul>
-				
+
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -123,14 +123,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 12 - 12
docs/internals/1_files.html

@@ -39,7 +39,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -49,7 +49,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html" class="active"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -62,7 +62,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -79,7 +79,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -90,21 +90,21 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Gravity files</h1><hr>
-         				
+
 			<p class="section-content">
 				In order to increase modularity, Gravity is divided into 4 main components and each one (except shared) is completely independent from the others. In this way there is a clear separation between the compiler itself that end up producing the bytecode and the virtual machine that is responsible to execute that bytecode.
 			</p>
@@ -149,7 +149,7 @@
 			</ul>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -162,14 +162,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/2_array.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Array</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/2_class.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html" class="active"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Class and metaclass</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/2_hash.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Hash</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/2_json.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">JSON</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/2_memory.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Memory</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/2_overview.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html" class="active"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Overview</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/2_utils.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Utils</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/2_visitor.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Visitor Pattern</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/2_vm.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html" class="active"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Stack vs Register VM</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_ast.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Abstract Syntax Tree</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_bytecode.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html" class="active"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Bytecode</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_codegen.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Code Generation</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_grammar.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Grammar</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_ircode.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Intermediate Representation</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_lexer.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Lexer</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_opcodes.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">VM Opcodes</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_optimizer.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html" class="active"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Optimizer</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_overview.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html" class="active"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Compiler Overview</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_parser.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Parser</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_prattparser.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Pratt Parser</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_semantic.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Semantic Analyses</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/3_symboltable.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Symbol Table</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/4_base.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html" class="active"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Base Classes</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/4_gc.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html" class="active"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Garbage Collector</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/4_memory.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Memory Ownership</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/4_objmodel.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Object Model</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/4_overview.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html" class="active"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Runtime Overview</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/4_performance.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Efficient Interpreter</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/4_vm.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Virtual Machine</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/5_jit.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html" class="active"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">LLVM JIT</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 11 - 11
docs/internals/5_overview.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,24 +89,24 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html" class="active"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">LLVM Overview</h1><hr>
          	<p>Content will be available soon.</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -119,14 +119,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 12 - 12
docs/internals/index.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -48,7 +48,7 @@
 					<li><a href="1_changelog.html"><span>Changelog</span></a></li>
 					<li><a href="1_files.html"><span>Gravity files</span></a></li>
 				</ul>
-				
+
 				<h4>2. PREREQUISITES</h4>
 				<ul>
 					<li><a href="2_overview.html"><span>Overview</span></a></li>
@@ -61,7 +61,7 @@
 					<li><a href="2_vm.html"><span>Stack vs Register VM</span></a></li>
 					<li><a href="2_class.html"><span>Class and metaclass</span></a></li>
 				</ul>
-				
+
 				<h4>3. COMPILER</h4>
 				<ul>
 					<li><a href="3_overview.html"><span>Overview</span></a></li>
@@ -78,7 +78,7 @@
 					<li><a href="3_optimizer.html"><span>Optimizer</span></a></li>
 					<li><a href="3_bytecode.html"><span>Bytecode</span></a></li>
 				</ul>
-				
+
 				<h4>4. RUNTIME</h4>
 				<ul>
 					<li><a href="4_overview.html"><span>Overview</span></a></li>
@@ -89,21 +89,21 @@
 					<li><a href="4_base.html"><span>Base Classes</span></a></li>
 					<li><a href="4_gc.html"><span>Garbage Collector</span></a></li>
 				</ul>
-				
+
 				<h4>5. LLVM</h4>
 				<ul>
 					<li><a href="5_overview.html"><span>Overview</span></a></li>
 					<li><a href="5_jit.html"><span>LLVM JIT</span></a></li>
 				</ul>
-				
+
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Introduction</h1><hr>
-         				
+
 			<p class="section-content">
 				When I started developing the Gravity programming language I knew nothing about how to develop an interpreter or how to traverse an AST. This project proved to be an invaluable experience to me and I am sure that developing a programming language from scratch is the best way to become a much better developer with a deeper understanding about what happens inside the compiler we use every single day.<br><br>
 				I'd like to collect all my experience in this book, trying to not assume any prior knowledge except the C language. This book guides you to gain the foundational knowledge required to write a new programming language from scratch and will give you concrete answers to questions like what is really a closure or how a garbage collector works under the hood.<br><br></p>
@@ -118,7 +118,7 @@
 				</p>
 			</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -131,14 +131,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="../scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 16 - 16
docs/lists.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,17 +75,17 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">List</h1><hr>
-			
+
 			<p class="section-content">
 			Lists (or arrays) are simple sequence of objects, their size is dynamic and their index starts always from 0. They provide fast random access to their elements. You can create a list by placing a sequence of comma-separated expressions inside square brackets:
 			</p>
 			<pre><code class="swift">
 	var r = [1, 2, "Hello", 3.1415, true];
-	
+
 	// list has a count property
 	var n = r.count;	// n is 5
 			</code></pre>
-			
+
 			<h4 class="section-h4">Accessing elements</h4>
 			<p>You can access an element from a list by calling the subscript operator [] on it with the index of the element you want. Like most languages, indices start at zero:
 			</p>
@@ -94,32 +94,32 @@
 	names[0];	// "Mark"
 	names[2];	// "Paul"
 			</code></pre>
-			
+
 			<p>Negative indices counts backwards from the end:</p>
 			<pre><code class="swift">
 	var names = ["Mark", "Andrew", "Paul", "Ross", "Frank", "Max"];
 	names[-1];	// "Max"
 	names[-2];	// "Frank"
 			</code></pre>
-			
+
 			<h4 class="section-h4">Iterating elements</h4>
-			<p>The subscript operator works well for finding values when you know the key you’re looking for, but sometimes you want to see everything that’s in the list. Since the List class implements the iterator method, you can easily use it in a for loop:</p> 
+			<p>The subscript operator works well for finding values when you know the key you’re looking for, but sometimes you want to see everything that’s in the list. Since the List class implements the iterator method, you can easily use it in a for loop:</p>
 			<pre><code class="swift">
 	var people = ["Mark", "Andrew", "Paul", "Ross", "Frank", "Max"];
 	for (var name in people) {
 		System.print("Current name is " + name);
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Adding elements</h4>
 			<p>A List instance can be expanded by setting an index that is greater than the current size of the list:</p>
 			<pre><code class="swift">
 	var list = [10,20,30,40,50];
 	list[30] = 22;	// list contains now 31 elements (index 0...30)
 			</code></pre>
-			
+
 			<h4 class="section-h4">List as a stack</h4>
-			<p>The List class implements the push/pop methods as a convenient way to treat a list as a stack:</p> 
+			<p>The List class implements the push/pop methods as a convenient way to treat a list as a stack:</p>
 			<pre><code class="swift">
 	var list = [10,20,30,40,50];
 	list.push(100);		// add 100 to the list
@@ -133,15 +133,15 @@
 	var list = [1, 2, "Hello", 3.1415, true];
 	return list.contains(3.1415); // Returns: true
 			</code></pre>
-            
+
 			<h4 class="section-h4">List Joins</h4>
 			<p>The List class implements the join method as a convenient way to
-			interpret a list as a string:</p> 
+			interpret a list as a string:</p>
 			<pre><code class="swift">
 	var list = [1,2,3,4,5];
 	list.join(" + "); // Becomes: "1 + 2 + 3 + 4 + 5"
 			</code></pre>
-            
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -154,14 +154,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 13 - 13
docs/loops.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,38 +75,38 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Loop</h1><hr>
-			
+
 			<p class="section-content">
-			
+
 			<h4 class="section-h4">While loop</h4>
 			<p>A while loop performs a set of statements until a condition becomes false. These kinds of loops are best used when the number of iterations is not known before the first iteration begins.</p>
 			<pre><code class="swift">
 	func main() {
 		var i = 0;
-			
+
 		while (i < 50000) {
 			i += 1;
 		}
-			
+
 		return i;
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Repeat-while loop</h4>
 			<p>The other variation of the while loop, known as the repeat-while loop, performs a single pass through the loop block first, before considering the loop’s condition. It then continues to repeat the loop until the condition is false.
 			</p>
 			<pre><code class="swift">
 	func main() {
 		var i = 0;
-				
+
 		repeat {
 			i += 1;
 		} while (i < 50000);
-				
+
 		return i;
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">For loop</h4>
 			<p>You can access an element from a list by calling the subscript operator [] on it with the index of the element you want. Like most languages, indices start at zero:</p>
 			<pre><code class="swift">
@@ -117,7 +117,7 @@
 	return count;
 			</code></pre>
 			<p>The for in loop can be used over any object that supports iteration, such as <a href="lists.html">Lists</a>, Strings or <a href="maps.html">Maps</a>.</p>
-         	
+
          	<h4 class="section-h4">Loop method</h4>
          	<p>Performing a loop is very common operation in any programming language, so Gravity adds a very convenient way to run a loop by adding a special loop method to some classes (Int, Range, List, String and Map) that accepts a <a href="closures.html">closure</a> as parameter:</p>
          	<pre><code class="swift">
@@ -205,14 +205,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 13 - 13
docs/maps.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,7 +75,7 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Map</h1><hr>
-			
+
 			<p class="section-content">
 			Maps are associative containers implemented as pairs each of which maps a key to a value.
 			You can create a map by placing a series of comma-separated entries inside square brackets. Each entry is a key and a value separated by a colon:
@@ -83,14 +83,14 @@
 			<pre><code class="swift">
 	// create a new map with 4 entries
 	var d = ["Mark":1, "Andrew":2, "Paul":3, "Ross":4];
-	
+
 	// map has a count property
 	var n = d.count;	// n is 4
-	
+
 	// create an empty map
 	var map = [:];
 			</code></pre>
-			
+
 			<h4 class="section-h4">Looking up values</h4>
 			<p>You can access an element from a list by calling the subscript operator [] on it with the key of the element you want:
 			</p>
@@ -99,23 +99,23 @@
 	names["Mark"];		// 1
 	names["Andrew"];	// 2
 			</code></pre>
-			
+
 			<h4 class="section-h4">Iterating elements</h4>
-			<p>The subscript operator works well for finding values when you know the key you’re looking for, but sometimes you want to see everything that’s in the map. Since the Map class implements the iterator method (through the keys method), you can easily use it in a for loop:</p> 
+			<p>The subscript operator works well for finding values when you know the key you’re looking for, but sometimes you want to see everything that’s in the map. Since the Map class implements the iterator method (through the keys method), you can easily use it in a for loop:</p>
 			<pre><code class="swift">
 	var people = ["Mark":1, "Andrew":2, "Paul":3, "Ross":4];
 	for (var name in people.keys()) {
 		System.print("Current name is " + name);
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Adding elements</h4>
 			<p>An item can be added to a map by simply setting a key/value:</p>
 			<pre><code class="swift">
 	var people = ["Mark":1, "Andrew":2, "Paul":3, "Ross":4];
 	people["Kiara"] = 5;	// people now contains the "Kiara" key with value 5
 			</code></pre>
-			
+
 			<h4 class="section-h4">Removing elements</h4>
 			<p>The remove method has been added to the map class as a conveniente way to remove keys:</p>
 			<pre><code class="swift">
@@ -124,7 +124,7 @@
 	people.remove("Ross");
 	return people.count; // 2 is returned in this case
 			</code></pre>
-			
+
          	</div>
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
@@ -138,14 +138,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 10 - 10
docs/operators.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,13 +75,13 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Operators</h1><hr>
-			
+
 			<p class="section-content">
 			An operator is a special symbol or phrase that you use to check, change, or combine values. For example, the addition operator (+) adds two numbers, as in <strong>var i = 1 + 2</strong>, and the logical AND operator (&&) combines two Boolean values, as in <strong>if (flag1 && flag2)</strong>.
 			<br><br>
 			Gravity supports most standard C operators and improves several capabilities to eliminate common coding errors. The assignment operator (=) does not return a value, to prevent it from being mistakenly used when the equal to operator (==) is intended. Gravity also provides two <a href="types.html">range</a> operators as a shortcut for expressing a range of values.
 			</p>
-			
+
 			<!-- ARITHMETIC -->
 			<h4 class="section-h4">Arithmetic Operators</h4>
 			<p>
@@ -101,7 +101,7 @@
 	var n5 = 9 % 4		// equals 1
 			</code></pre>
 			<p>Special attention has been placed in the division operator. A Division between two Int usually result in a Float in order to not truncate any decimal.</p>
-			
+
 			<!-- ASSIGNMENT -->
 			<h4 class="section-h4">Assignment Operator</h4>
 			<p>The assignment operator = initialize or update a value:</p>
@@ -157,7 +157,7 @@
 	1 || 0		// true because one of the two values is true
 			</code></pre>
 			<p>In order to improve code readability the reserved keywords <strong>not, and, or</strong> has been introduces as an alisas to logical operators.</p>
-			
+
 			<!-- BITWISE -->
 			<h4 class="section-h4">Bitwise Operators</h4>
 			<p>
@@ -179,7 +179,7 @@
 	var n5 = n ^ 0B00001111		// equals 00111100
 	var n6 = ~n;			// equals 11001100
 			</code></pre>
-			
+
 			<!-- COMPOUND -->
 			<h4 class="section-h4">Compound Assignment Operators</h4>
 			<p>As a shortcut, assignment and operators can be combined together:
@@ -196,7 +196,7 @@
 				<li>Bitwise OR and assign (|=)</li>
 			</ul>
 			</p>
-			
+
          	</div>
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
@@ -210,14 +210,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 1 - 1
docs/stylesheets/styles.css

@@ -53,7 +53,7 @@ pre {
 
 .sidebar-nav h4 {
 	font-size: 12px;
-	text-transform: uppercase; 
+	text-transform: uppercase;
 	color: #BBB;
 	margin-bottom: 10px;
 }

+ 16 - 16
docs/syntax.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -76,7 +76,7 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Syntax</h1><hr>
-			
+
 			<p class="section-content">
 			<strong>Gravity</strong> syntax is designed to be familiar to people coming from C-like languages like Javascript, Swift, C++, C# and many more. We started working on this new language a year before Apple announced Swift and we were happily surprised to discovered how similar both syntax appear. Semicolon separator <strong>;</strong> is optional.
 			<br><br>
@@ -86,28 +86,28 @@
 		// instance variables
 		var width;
 		var height;
-				
+
 		// instance method
 		func area() {
 			return width*height;
 		}
-				
+
 		// constructor
 		func init(w, h) {
 			width = w;
 			height = h;
 		}
 	}
-			
+
 	func main() {
 		// initialize a new Rectangle object
 		var r = Rectangle(20, 10);
-				
+
 		// return value is 20*10 = 200
 		return r.area();
 	}
 			</code></pre>
-			
+
 			<!-- COMMENTS -->
 			<h4 class="section-h4">Comments</h4>
 			<p>Gravity supports both line comments:</p>
@@ -154,12 +154,12 @@
 		System.print("5+4=" + add(5,4));
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Import</h4>
 			<p>While #include is used to include file at compilation time, the import statement enables you to load modules at runtime...</p>
 			<!--<p>Gravity supports importing code from other gravity files using the
 			import statement:</p>-->
-			
+
 			<!-- RESERVED KEYWORDS -->
 			<h4 class="section-h4">Reserved Keywords</h4>
 			<p>Like many other programming languages Gravity has some reserved keywords that assumes a very specific meaning in the context of the source code:</p>
@@ -169,7 +169,7 @@
 	_args struct repeat switch return public static extern
 	import module default private continue internal undefined
 			</code></pre>
-			
+
 			<!-- IDENTIFIERS -->
 			<h4 class="section-h4">Identifiers</h4>
 			<p>Identifiers represent a naming rule used to identify objects inside your source code.
@@ -181,7 +181,7 @@
 	foo123
 	BYE_BYE
 			</code></pre>
-			
+
 			<!-- BLOCKS -->
 			<h4 class="section-h4">Blocks and Scope</h4>
 			<p>Every named identifier introduced in some portion of the source code is introduced in a scope. The scope is the largest part of the source code in which that identifier is valid. The names declared by a declaration are introduced into a specific scope based on the context of the declaration. For instance, local variable declarations introduce the name into the block scope, whereas class member variable declarations introduce the name into class scope.<br><br>There are three scopes defined: <strong>block scope</strong>, <strong>class scope</strong> and <strong>file scope</strong>. Names declared in the block scope become visible immediately after its completed declarator.  This means you cannot refer to a name within the block scope until after it has been fully declared. Names declared in the file and class scopes become visible immediately upon executing the starting statement of the script. This means you can refer to a name within the file or class scopes before it has been fully declared.<br><br>These are all valid scopes:</p>
@@ -194,7 +194,7 @@
 	func f2() {
 	    return 42;
 	}
-			
+
 	// block scope can be nested and
 	// can hide other local variables
 	func f3() {
@@ -206,7 +206,7 @@
 		return a;
 	}
 			</code></pre>
-			
+
          	</div>
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
@@ -220,14 +220,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 17 - 17
docs/system.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -73,11 +73,11 @@
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">System</h1><hr>
-         				
+
 			<p class="section-content">
 				System class is a class registered in every Gravity VM that offers some useful methods and properties.</p>
 				<h4 class="section-h4">Print methods</h4>
@@ -85,33 +85,33 @@
 	func main() {
 		// print to stdout and add a newline character
 		System.print("Hello World");
-		
+
 		// print to stdout without any newline character appended
 		System.put("Hello World");
 	}
 				</code></pre>
-				
+
 				<h4 class="section-h4">Garbage collector methods</h4>
 				<p>Gravity automatically manage memory for you using a tri-colour marking garbage collector, using the System class the user has the ability to change some of its settings and even disable it when certain performance critical tasks need to be performed:</p>
 				<pre><code class="swift">
 	func main() {
 		// disable GC
 		System.gcenabled = false;
-		
+
 		// ratio used during automatic recomputation of the new gcthreshold value
 		var ratio = System.gcratio;
-		
+
 		// minimum GC threshold size
 		var minthreshold = System.gcminthreshold;
-		
+
 		// memory required to trigger a GC
 		var threshold = System.gcthreshold;
-		
+
 		// enable GC
 		System.gcenabled = true;
 	}
 				</code></pre>
-				
+
 				<h4 class="section-h4">Time related methods</h4>
 				<p>There are times where it could be really useful to easily measure how much time is spent in a given task:</p>
 				<pre><code class="swift">
@@ -119,12 +119,12 @@
 		var t1 = System.nanotime();
 		perform_my_task();
 		var t2 = System.nanotime();
-		
+
 		// return elapsed time in ms
 		return ((t2-t1) / 1000000.0);
 	}
 				</code></pre>
-				
+
 				<h4 class="section-h4">System Exit</h4>
 				<p>There are times where it could be useful to have main() return an
 				error code back to your shell:</p>
@@ -139,10 +139,10 @@
 	# Returns: 5
 	$ echo $?
 				</code></pre>
-				
+
          	</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -155,14 +155,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 18 - 18
docs/types.html

@@ -37,7 +37,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -75,14 +75,14 @@
 
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Values and Types</h1><hr>
-			
+
 			<p class="section-content">
 			Gravity is a dynamically typed language so variables do not have a type, although they refer to a value that does have a type. In Gravity everything is an object (with methods you can call and instance variables you can use). Basic intrinsic types are of class Object, Int, Float, String, Bool, Null, <a href="classes.html">Class</a>, <a href="functions.html">Function</a>, Fiber, Instance, <a href="lists.html">List</a>, <a href="maps.html">Map</a> and Range.
 			</p>
-			
+
 			<h4 class="section-h4">Object</h4>
 			<p>Object is the root class of every object inside Gravity. Through the Object class, objects inherit a basic interface to the runtime system and the ability to behave as Gravity objects.</p>
-			
+
 			<h4 class="section-h4">Int</h4>
 			<p>An Int represents a 64 bits (can optionally be compiled as 32bit) signed number:</p>
 			<pre><code class="swift">
@@ -96,7 +96,7 @@
 	var f = 30.radians // returns the result of converting 30 degrees to radians
 	var f = 3.degrees // returns the result of converting 3 radians to degrees
 			</code></pre>
-			
+
 			<h4 class="section-h4">Float</h4>
 			<p>A float represents a 32 bits (or better) floating point number:</p>
 			<pre><code class="swift">
@@ -106,13 +106,13 @@
 	var f = 30.5.radians // returns the result of converting 30.5 degrees to radians
 	var f = 3.14.degrees // returns the result of converting 3.14 radians to degrees
 			</code></pre>
-			
+
 			<h4 class="section-h4">String</h4>
 			<p>Strings are an immutable sequence of characters. String literals can be surrounded in double or single quotes.</p>
 			<pre><code class="swift">
 	var a = "Hello World";  // double quotes
 	var b = 'Hello World';  // single quotes
-	
+
 	// Strings have also a length property
 	var n = b.length;       // n is now 11
 
@@ -150,14 +150,14 @@
 	n = a[-5...10]          // n is now "World"
 	n = a[-1...-5]          // n is now "dlroW"
 			</code></pre>
-			
+
 			<h4 class="section-h4">Bool</h4>
 			<p>The bool data type can have only two values, they are the literals true and false. A Bool value expresses the validity of a condition (tells whether the condition is true or false).</p>
 			<pre><code class="swift">
 	var a = true;
 	var b = false;
 			</code></pre>
-			
+
 			<h4 class="section-h4">Null</h4>
 			<p>It indicates the absence of a value. If you call a method that doesn’t return anything and get its returned value, you get null back. The null data type is also used to initialize uninitialized variables with a default value.</p>
 			<pre><code class="swift">
@@ -168,35 +168,35 @@
 			return mass * acceleration;
 		}
 	}
-			
+
 	func f2() {
 		var sir = Newton();
 		// acceleration instance variable has no default value
 		// so it is automatically set to null
 		return sir.force();
 	}
-			
+
 	func f1() {
 		var a;
 		// a is uninitialized so it has a default null value
 		return a;
 	}
 			</code></pre>
-			
+
 			<h4 class="section-h4">Range</h4>
 			<p>A range is an object that represents a consecutive range of numbers. Syntax for this type has been directly inspired by Swift.</p>
 			<pre><code class="swift">
 	// a represents a range with values 1,2,3
 	var a = 1...3;
-	
+
 	// b represents a range with values 1,2
 	var b = 1..<3;
-	
+
 	// Ranges have also a conveniente count property
 	var n1 = a.count;	// n1 is now 3
 	var n2 = b.count;	// n2 is now 2
 			</code></pre>
-			
+
          	</div>
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
@@ -210,14 +210,14 @@
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 7 - 7
docs/unit-test.html

@@ -38,7 +38,7 @@
 	<div class="container body-container">
 		<div class="main-content">
 			<div class="row">
-       	
+
        		<!-- BEGIN SIDEBAR -->
        		<div class="col-sm-3 border-right section-left">
 				<div saveheight="1" class="sidebar-nav">
@@ -73,11 +73,11 @@
 				</div>
 			</div>
 			<!-- END SIDEBAR -->
-			
+
 			<!-- BEGIN CONTENT -->
        		<div class="col-sm-9 border-left section-right">
          	<h1 class="section-header">Unit Test</h1><hr>
-         				
+
 			<p class="section-content">
 				Unit testing is so important (expecially for a programming language) that Gravity has built-in unit testing capabilities. What a user needs to do is setup some delegate C methods in order to be able to correctly setup a unit-test. Gravity already has a unit-test executable so in order to add your code to it you need to create a .gravity file using the special #unittest preprocessor macro:</p>
 			<pre><code class="swift">
@@ -96,7 +96,7 @@ func main() {
 			<p>A unittest can also be written in order to be able to check for syntax, semantic and runtime errors. For syntax and semantic errors the user can also specify row and column of the expected generated error.</p>
          	</div>
          	<!-- END CONTENT -->
-         	
+
        	</div> <!-- /row -->
        </div> <!-- /main-content -->
      </div> <!-- /container -->
@@ -109,14 +109,14 @@ func main() {
 		</div>
 	</footer>
     <!-- END FOOTER -->
-	
+
 	<!-- Bootstrap JS -->
 	<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
-	
+
 	<!-- Highlights JS -->
     <script src="scripts/highlight/highlight.min.js"></script>
     <script>hljs.initHighlightingOnLoad();</script>
-    
+
 	</body>
 </html>

+ 35 - 35
src/cli/gravity.c

@@ -37,7 +37,7 @@ static void report_error (error_type_t error_type, const char *message, error_de
 		case GRAVITY_WARNING: type = "WARNING"; break;
 		case GRAVITY_ERROR_IO: type = "I/O"; break;
 	}
-	
+
 	if (error_type == GRAVITY_ERROR_RUNTIME) printf("RUNTIME ERROR: ");
 	else printf("%s ERROR on %d (%d,%d): ", type, error_desc.fileid, error_desc.lineno, error_desc.colno);
 	printf("%s\n", message);
@@ -45,30 +45,30 @@ static void report_error (error_type_t error_type, const char *message, error_de
 
 static const char *load_file (const char *file, size_t *size, uint32_t *fileid, void *xdata) {
 	#pragma unused(fileid, xdata)
-	
+
 	// this callback is called each time an import statement is parsed
 	// file arg represents what user wrote after the import keyword, for example:
 	// import "file2"
 	// import "file2.gravity"
 	// import "../file2"
 	// import "/full_path_to_file2"
-	
+
 	// it is callback's responsability to resolve file path based on current working directory
 	// or based on user defined search paths
 	// and returns:
 	// size of file in *size
 	// fileid (if any) in *fileid
 	// content of file as return value of the function
-	
+
 	// fileid will then be used each time an error is reported by the compiler
 	// so it is responsability of this function to map somewhere the association
 	// between fileid and real file/path name
-	
+
 	// fileid is not used in this example
 	// xdata not used here but it the xdata field set in the delegate
 	// please note than in this simple example the imported file must be
 	// in the same folder as the main input file
-	
+
 	if (!file_exists(file)) return NULL;
 	return file_read(file, size);
 }
@@ -95,17 +95,17 @@ static void print_help (void) {
 
 static op_type parse_args (int argc, const char* argv[]) {
 	if (argc == 1) return OP_REPL;
-	
+
 	if (argc == 2 && strcmp(argv[1], "--version") == 0) {
 		print_version();
 		exit(0);
 	}
-	
+
 	if (argc == 2 && strcmp(argv[1], "--help") == 0) {
 		print_help();
 		exit(0);
 	}
-	
+
 	op_type type = OP_RUN;
 	for (int i=1; i<argc; ++i) {
 		if ((strcmp(argv[i], "-c") == 0) && (i+1 < argc)) {
@@ -131,7 +131,7 @@ static op_type parse_args (int argc, const char* argv[]) {
 			type = OP_COMPILE_RUN;
 		}
 	}
-	
+
 	return type;
 }
 
@@ -140,13 +140,13 @@ static op_type parse_args (int argc, const char* argv[]) {
 static void gravity_repl (void) {
 	printf("REPL not yet implemented.\n");
 	exit(0);
-	
+
 	/*
 	// setup compiler/VM delegate
 	gravity_delegate_t delegate = {
 		.error_callback = report_error,
 	};
-	
+
 	gravity_compiler_t	*compiler = gravity_compiler_create(&delegate);
 	gravity_vm	*vm = gravity_vm_new(&delegate);
 	char		*line = NULL;
@@ -158,7 +158,7 @@ static void gravity_repl (void) {
 		//	gravity_compiler_eval(compiler, vm, line, length);
 		free(line);
 	}
-	
+
 	gravity_compiler_free(compiler);
 	gravity_vm_free(vm);
 	 */
@@ -169,48 +169,48 @@ static void gravity_repl (void) {
 int main (int argc, const char* argv[]) {
 	// parse arguments and return operation type
 	op_type type = parse_args(argc, argv);
-	
+
 	// special repl case
 	if (type == OP_REPL) gravity_repl();
-	
+
 	// initialize memory debugger (if activated)
 	mem_init();
-	
+
 	// closure to execute/serialize
 	gravity_closure_t *closure = NULL;
-	
+
 	// optional compiler
 	gravity_compiler_t *compiler = NULL;
-	
+
 	// setup compiler/VM delegate
 	gravity_delegate_t delegate = {
 		.error_callback = report_error,
 		.loadfile_callback = load_file
 	};
-	
+
 	// create VM
 	gravity_vm *vm = gravity_vm_new(&delegate);
-	
+
 	// check if input file is source code that needs to be compiled
 	if ((type == OP_COMPILE) || (type == OP_COMPILE_RUN) || (type == OP_INLINE_RUN)) {
-		
+
 		// load source code
         size_t size = 0;
         const char *source_code = NULL;
-        
+
         if (type == OP_INLINE_RUN) {
             source_code = input_file;
             size = strlen(input_file);
         } else {
             source_code = file_read(input_file, &size);
         }
-        
+
         // sanity check
         if (!source_code || !size) {
             printf("Error loading %s %s\n", (type == OP_INLINE_RUN) ? "source" : "file", input_file);
             goto cleanup;
         }
-        
+
         // create closure to execute inline code
         if (type == OP_INLINE_RUN) {
             char *buffer = mem_alloc(size+1024);
@@ -218,24 +218,24 @@ int main (int argc, const char* argv[]) {
             size = snprintf(buffer, size+1024, "func main() {%s};", input_file);
             source_code = buffer;
         }
-		
+
 		// create compiler
 		compiler = gravity_compiler_create(&delegate);
-		
+
 		// compile source code into a closure
 		closure = gravity_compiler_run(compiler, source_code, size, 0, false);
 		if (!closure) goto cleanup;
-		
+
 		// check if closure needs to be serialized
 		if (type == OP_COMPILE) {
 			bool result = gravity_compiler_serialize_infile(compiler, closure, output_file);
 			if (!result) printf("Error serializing file %s\n", output_file);
 			goto cleanup;
 		}
-		
+
 		// op is OP_COMPILE_RUN so transfer memory from compiler to VM
 		gravity_compiler_transfer(compiler, vm);
-		
+
 	} else if (type == OP_RUN) {
 		// unserialize file
 		closure = gravity_vm_loadfile(vm, input_file);
@@ -244,26 +244,26 @@ int main (int argc, const char* argv[]) {
 			goto cleanup;
 		}
     }
-	
+
 	// sanity check
 	assert(closure);
-	
+
 	if (gravity_vm_runmain(vm, closure)) {
 		gravity_value_t result = gravity_vm_result(vm);
 		double t = gravity_vm_time(vm);
-		
+
 		char buffer[512];
 		gravity_value_dump(vm, result, buffer, sizeof(buffer));
 		if (!quiet_flag) {
 			printf("RESULT: %s (in %.4f ms)\n\n", buffer, t);
 		}
 	}
-	
+
 cleanup:
 	if (compiler) gravity_compiler_free(compiler);
 	if (vm) gravity_vm_free(vm);
 	gravity_core_free();
-	
+
 	#if GRAVITY_MEMORY_DEBUG
 	size_t current_memory = mem_leaks();
 	if (current_memory != 0) {
@@ -273,6 +273,6 @@ cleanup:
 		printf("\tNo VM leaks found!\n");
 	}
 	#endif
-	
+
 	return 0;
 }

+ 30 - 30
src/cli/unittest.c

@@ -14,11 +14,11 @@
 typedef struct {
 	bool			processed;
     bool            is_fuzzy;
-	
+
 	uint32_t		ncount;
 	uint32_t		nsuccess;
 	uint32_t		nfailure;
-	
+
 	error_type_t	expected_error;
 	gravity_value_t expected_value;
 	int32_t			expected_row;
@@ -43,7 +43,7 @@ static void	unittest_callback (error_type_t error_type, const char *description,
 	data->expected_value = value;
 	data->expected_row = row;
 	data->expected_col = col;
-	
+
 	if (notes) printf("\tNOTE: %s\n", notes);
 	printf("\t%s\n", description);
 }
@@ -52,30 +52,30 @@ static void	unittest_callback (error_type_t error_type, const char *description,
 
 static void callback_error (error_type_t error_type, const char *message, error_desc_t error_desc, void *xdata) {
 	test_data *data = (test_data *)xdata;
-	
+
 	if (data->processed == true) return; // ignore 2nd error
 	data->processed = true;
-	
+
 	const char *type = "NONE";
 	if (error_type == GRAVITY_ERROR_SYNTAX) type = "SYNTAX";
 	else if (error_type == GRAVITY_ERROR_SEMANTIC) type = "SEMANTIC";
 	else if (error_type == GRAVITY_ERROR_RUNTIME) type = "RUNTIME";
 	else if (error_type == GRAVITY_WARNING) type = "WARNING";
-	
+
 	if (error_type == GRAVITY_ERROR_RUNTIME) printf("\tRUNTIME ERROR: ");
 	else printf("\t%s ERROR on %d (%d,%d): ", type, error_desc.fileid, error_desc.lineno, error_desc.colno);
 	printf("%s\n", message);
-	
+
 	bool same_error = (data->expected_error == error_type);
 	bool same_row = (data->expected_row != -1) ? (data->expected_row == error_desc.lineno) : true;
 	bool same_col = (data->expected_col != -1) ? (data->expected_col == error_desc.colno) : true;
-	
+
     if (data->is_fuzzy) {
         ++data->nsuccess;
         printf("\tSUCCESS\n");
         return;
     }
-    
+
 	if (same_error && same_row && same_col) {
 		++data->nsuccess;
 		printf("\tSUCCESS\n");
@@ -88,57 +88,57 @@ static void callback_error (error_type_t error_type, const char *message, error_
 static const char *callback_read (const char *path, size_t *size, uint32_t *fileid, void *xdata) {
 	#pragma unused(fileid,xdata)
 	if (file_exists(path)) return file_read(path, size);
-	
+
 	// this unittest is able to resolve path only next to main test folder (not in nested folders)
 	const char *newpath = file_buildpath(path, test_folder_path);
 	if (!newpath) return NULL;
-	
+
 	const char *buffer = file_read(newpath, size);
 	mem_free(newpath);
-	
+
 	return buffer;
 }
 
 static void test_folder (const char *folder_path, test_data *data) {
 	DIRREF dir = directory_init(folder_path);
 	if (!dir) return;
-	
+
 	const char *target_file;
 	while ((target_file = directory_read(dir))) {
-		
+
 		#ifdef WIN32
 		const char winbuffer[MAX_PATH];
 		WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)target_file, -1, winbuffer, sizeof(winbuffer), NULL, NULL );
 		target_file = (const char *)winbuffer;
 		#endif
-		
+
 		// if file is a folder then start recursion
 		const char *full_path = file_buildpath(target_file, folder_path);
 		if (is_directory(full_path)) {
 			// skip disabled folder
 			if (strcmp(target_file, "disabled") == 0) continue;
-			
+
 			test_folder(full_path, data);
 			continue;
 		}
-		
+
 		// test only files with a .gravity extension
 		if (strstr(full_path, ".gravity") == NULL) continue;
         data->is_fuzzy = (strstr(full_path, "/fuzzy/") != NULL);
-		
+
 		// load source code
 		size_t size = 0;
 		const char *source_code = file_read(full_path, &size);
 		assert(source_code);
-		
+
 		// start unit test
 		unittest_init(target_file, data);
-		
+
 		// compile and run source code
 		printf("\n%d\tTest file: %s\n", data->ncount, target_file);
 		printf("\tTest path: %s\n", full_path);
 		mem_free(full_path);
-		
+
 		// initialize compiler and delegates
 		gravity_delegate_t delegate = {
 			.xdata = (void *)data,
@@ -146,13 +146,13 @@ static void test_folder (const char *folder_path, test_data *data) {
 			.unittest_callback = unittest_callback,
 			.loadfile_callback = callback_read
 		};
-		
+
 		gravity_compiler_t *compiler = gravity_compiler_create(&delegate);
 		gravity_closure_t *closure = gravity_compiler_run(compiler, source_code, size, 0, false);
 		gravity_vm *vm = gravity_vm_new(&delegate);
 		gravity_compiler_transfer(compiler, vm);
 		gravity_compiler_free(compiler);
-		
+
 		if (closure) {
 			if (gravity_vm_runmain(vm, closure)) {
 				data->processed = true;
@@ -168,13 +168,13 @@ static void test_folder (const char *folder_path, test_data *data) {
 			}
 		}
 		gravity_vm_free(vm);
-		
+
 		// case for empty files or simple declarations test
 		if (!data->processed) {
 			++data->nsuccess;
 			printf("\tSUCCESS\n");
 		}
-		
+
 		// cleanup unitest
 		unittest_cleanup(target_file, data);
 	}
@@ -186,25 +186,25 @@ int main (int argc, const char* argv[]) {
 		.nsuccess = 0,
 		.nfailure = 0
 	};
-	
+
 	if (argc != 2) {
 		printf("Usage: unittest /path/to/unitest/\n");
 		return 1;
 	}
-	
+
 	// print console header
 	printf("==============================================\n");
 	printf("Gravity UnitTest\n");
 	printf("Gravity version %s\n", GRAVITY_VERSION);
 	printf("Build date: %s\n", GRAVITY_BUILD_DATE);
 	printf("==============================================\n");
-	
+
 	mem_init();
 	nanotime_t tstart = nanotime();
 	test_folder_path = argv[1];
 	test_folder(argv[1], &data);
 	nanotime_t tend = nanotime();
-	
+
 	double result = ((double)((data.nsuccess * 100)) / (double)data.ncount);
 	printf("\n\n");
 	printf("==============================================\n");
@@ -215,7 +215,7 @@ int main (int argc, const char* argv[]) {
 	printf("Time: %.4f ms\n", millitime(tstart, tend));
 	printf("==============================================\n");
 	printf("\n");
-	
+
 	// If we have 1 or more failures, return an error.
 	if (data.nfailure != 0) {
 		return 1;

+ 1 - 1
src/compiler/debug_macros.h

@@ -14,7 +14,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
-#include <stdarg.h> 
+#include <stdarg.h>
 #include <assert.h>
 #include <unistd.h>
 #include <limits.h>

+ 54 - 54
src/compiler/gravity_ast.c

@@ -39,18 +39,18 @@ gnode_r *gnode_array_create (void) {
 
 void gnode_array_sethead(gnode_r *list, gnode_t *node) {
     if (!list || !node) return;
-    
+
 	// get old size
 	size_t list_size = gnode_array_size(list);
-	
+
 	// push node at the end to trigger memory allocation (if needed)
 	gnode_array_push(list, node);
-	
+
 	// shift elements in array
 	for (size_t i=list_size; i>0; --i) {
 		list->p[i] = list->p[i-1];
 	}
-	
+
 	// set new array head
 	list->p[0] = node;
 }
@@ -59,7 +59,7 @@ gnode_r *gnode_array_remove_byindex(gnode_r *old_list, size_t index) {
 	// get old size
 	size_t list_size = gnode_array_size(old_list);
 	if (index >= list_size) return NULL;
-	
+
 	gnode_r *new_list = gnode_array_create();
 	for (size_t i=0; i<list_size; ++i) {
 		if (i == index) continue;
@@ -76,14 +76,14 @@ gupvalue_t *gnode_function_add_upvalue(gnode_function_decl_t *f, gnode_var_t *sy
 		f->uplist = mem_alloc(sizeof(gupvalue_r));
 		gnode_array_init(f->uplist);
 	}
-	
+
 	// lookup symbol in uplist (if any)
 	gtype_array_each(f->uplist, {
 		// symbol already found in uplist so return its index
 		gnode_var_t *node = (gnode_var_t *)val->node;
 		if (strcmp(node->identifier, symbol->identifier) == 0) return val;
 	}, gupvalue_t *);
-	
+
 	// symbol not found in uplist so add it
 	gupvalue_t *upvalue = mem_alloc(sizeof(gupvalue_t));
 	upvalue->node = (gnode_t *)symbol;
@@ -91,7 +91,7 @@ gupvalue_t *gnode_function_add_upvalue(gnode_function_decl_t *f, gnode_var_t *sy
 	upvalue->selfindex = (uint32_t)gnode_array_size(f->uplist);
 	upvalue->is_direct = (n == 1);
 	marray_push(gupvalue_t*, *f->uplist, upvalue);
-	
+
 	// return symbol position in uplist
 	return upvalue;
 }
@@ -100,7 +100,7 @@ gupvalue_t *gnode_function_add_upvalue(gnode_function_decl_t *f, gnode_var_t *sy
 
 gnode_t *gnode_jump_stat_create (gtoken_s token, gnode_t *expr, gnode_t *decl) {
 	gnode_jump_stmt_t *node = (gnode_jump_stmt_t *)mem_alloc(sizeof(gnode_jump_stmt_t));
-	
+
 	SETBASE(node, NODE_JUMP_STAT, token, NULL);
     SETDECL(node, decl);
 	node->expr = expr;
@@ -109,7 +109,7 @@ gnode_t *gnode_jump_stat_create (gtoken_s token, gnode_t *expr, gnode_t *decl) {
 
 gnode_t *gnode_label_stat_create (gtoken_s token, gnode_t *expr, gnode_t *stmt, gnode_t *decl) {
 	gnode_label_stmt_t *node = (gnode_label_stmt_t *)mem_alloc(sizeof(gnode_label_stmt_t));
-	
+
 	SETBASE(node, NODE_LABEL_STAT, token, NULL);
     SETDECL(node, decl);
 	node->expr = expr;
@@ -119,7 +119,7 @@ gnode_t *gnode_label_stat_create (gtoken_s token, gnode_t *expr, gnode_t *stmt,
 
 gnode_t *gnode_flow_stat_create (gtoken_s token, gnode_t *cond, gnode_t *stmt1, gnode_t *stmt2, gnode_t *decl) {
 	gnode_flow_stmt_t *node = (gnode_flow_stmt_t *)mem_alloc(sizeof(gnode_flow_stmt_t));
-	
+
 	SETBASE(node, NODE_FLOW_STAT, token, NULL);
     SETDECL(node, decl);
 	node->cond = cond;
@@ -130,7 +130,7 @@ gnode_t *gnode_flow_stat_create (gtoken_s token, gnode_t *cond, gnode_t *stmt1,
 
 gnode_t *gnode_loop_stat_create (gtoken_s token, gnode_t *cond, gnode_t *stmt, gnode_t *expr, gnode_t *decl) {
 	gnode_loop_stmt_t *node = (gnode_loop_stmt_t *)mem_alloc(sizeof(gnode_loop_stmt_t));
-	
+
 	SETBASE(node, NODE_LOOP_STAT, token, NULL);
     SETDECL(node, decl);
 	node->cond = cond;
@@ -142,7 +142,7 @@ gnode_t *gnode_loop_stat_create (gtoken_s token, gnode_t *cond, gnode_t *stmt, g
 
 gnode_t *gnode_block_stat_create (gnode_n type, gtoken_s token, gnode_r *stmts, gnode_t *decl) {
 	gnode_compound_stmt_t *node = (gnode_compound_stmt_t *)mem_alloc(sizeof(gnode_compound_stmt_t));
-	
+
 	SETBASE(node, type, token, NULL);
     SETDECL(node, decl);
 	node->stmts = stmts;
@@ -152,7 +152,7 @@ gnode_t *gnode_block_stat_create (gnode_n type, gtoken_s token, gnode_r *stmts,
 
 gnode_t *gnode_empty_stat_create (gtoken_s token, gnode_t *decl) {
 	gnode_empty_stmt_t *node = (gnode_empty_stmt_t *)mem_alloc(sizeof(gnode_empty_stmt_t));
-	
+
 	SETBASE(node, NODE_EMPTY_STAT, token, NULL);
     SETDECL(node, decl);
 	return (gnode_t *)node;
@@ -163,7 +163,7 @@ gnode_t *gnode_empty_stat_create (gtoken_s token, gnode_t *decl) {
 gnode_t *gnode_class_decl_create (gtoken_s token, const char *identifier, gtoken_t access_specifier, gtoken_t storage_specifier, gnode_t *superclass, gnode_r *protocols, gnode_r *declarations, bool is_struct, void *meta, gnode_t *decl) {
 	gnode_class_decl_t *node = (gnode_class_decl_t *)mem_alloc(sizeof(gnode_class_decl_t));
 	node->is_struct = is_struct;
-	
+
 	SETBASE(node, NODE_CLASS_DECL, token, meta);
     SETDECL(node, decl);
 	node->bridge = false;
@@ -175,39 +175,39 @@ gnode_t *gnode_class_decl_create (gtoken_s token, const char *identifier, gtoken
 	node->decls = declarations;
 	node->nivar = 0;
 	node->nsvar = 0;
-	
+
 	return (gnode_t *)node;
 }
 
 gnode_t *gnode_module_decl_create (gtoken_s token, const char *identifier, gtoken_t access_specifier, gtoken_t storage_specifier, gnode_r *declarations, void *meta, gnode_t *decl) {
 	gnode_module_decl_t *node = (gnode_module_decl_t *)mem_alloc(sizeof(gnode_module_decl_t));
-	
+
 	SETBASE(node, NODE_MODULE_DECL, token, meta);
     SETDECL(node, decl);
 	node->identifier = identifier;
 	node->access = access_specifier;
 	node->storage = storage_specifier;
 	node->decls = declarations;
-	
+
 	return (gnode_t *)node;
 }
 
 gnode_t *gnode_enum_decl_create (gtoken_s token, const char *identifier, gtoken_t access_specifier, gtoken_t storage_specifier, symboltable_t *symtable, void *meta, gnode_t *decl) {
 	gnode_enum_decl_t *node = (gnode_enum_decl_t *)mem_alloc(sizeof(gnode_enum_decl_t));
-	
+
 	SETBASE(node, NODE_ENUM_DECL, token, meta);
     SETDECL(node, decl);
 	node->identifier = identifier;
 	node->access = access_specifier;
 	node->storage = storage_specifier;
 	node->symtable= symtable;
-	
+
 	return (gnode_t *)node;
 }
 
 gnode_t *gnode_function_decl_create (gtoken_s token, const char *identifier, gtoken_t access_specifier, gtoken_t storage_specifier, gnode_r *params, gnode_compound_stmt_t *block, void *meta, gnode_t *decl) {
 	gnode_function_decl_t *node = (gnode_function_decl_t *)mem_alloc(sizeof(gnode_function_decl_t));
-	
+
 	SETBASE(node, NODE_FUNCTION_DECL, token, meta);
     SETDECL(node, decl);
 	node->identifier = identifier;
@@ -217,26 +217,26 @@ gnode_t *gnode_function_decl_create (gtoken_s token, const char *identifier, gto
 	node->block = block;
 	node->nlocals = 0;
 	node->uplist = NULL;
-    
+
 	return (gnode_t *)node;
 }
 
 gnode_t *gnode_variable_decl_create (gtoken_s token, gtoken_t type, gtoken_t access_specifier, gtoken_t storage_specifier, gnode_r *declarations, void *meta, gnode_t *decl) {
 	gnode_variable_decl_t *node = (gnode_variable_decl_t *)mem_alloc(sizeof(gnode_variable_decl_t));
-	
+
 	SETBASE(node, NODE_VARIABLE_DECL, token, meta);
     SETDECL(node, decl);
 	node->type = type;
 	node->access = access_specifier;
 	node->storage = storage_specifier;
 	node->decls = declarations;
-    
+
 	return (gnode_t *)node;
 }
 
 gnode_t *gnode_variable_create (gtoken_s token, const char *identifier, const char *annotation_type, gtoken_t access_specifier, gnode_t *expr, gnode_t *decl) {
 	gnode_var_t *node = (gnode_var_t *)mem_alloc(sizeof(gnode_var_t));
-	
+
 	SETBASE(node, NODE_VARIABLE, token, NULL);
     SETDECL(node, decl);
 	node->identifier = identifier;
@@ -297,7 +297,7 @@ bool gnode_is_literal_number (gnode_t *node) {
 
 gnode_t *gnode_binary_expr_create (gtoken_t op, gnode_t *left, gnode_t *right, gnode_t *decl) {
 	if (!left || !right) return NULL;
-	
+
 	gnode_binary_expr_t	*node = (gnode_binary_expr_t *)mem_alloc(sizeof(gnode_binary_expr_t));
 	SETBASE(node, NODE_BINARY_EXPR, left->token, NULL);
     SETDECL(node, decl);
@@ -309,7 +309,7 @@ gnode_t *gnode_binary_expr_create (gtoken_t op, gnode_t *left, gnode_t *right, g
 
 gnode_t *gnode_unary_expr_create (gtoken_t op, gnode_t *expr, gnode_t *decl) {
 	if (!expr) return NULL;
-	
+
 	gnode_unary_expr_t *node = (gnode_unary_expr_t *)mem_alloc(sizeof(gnode_unary_expr_t));
 	SETBASE(node, NODE_UNARY_EXPR, expr->token, NULL);
     SETDECL(node, decl);
@@ -320,7 +320,7 @@ gnode_t *gnode_unary_expr_create (gtoken_t op, gnode_t *expr, gnode_t *decl) {
 
 gnode_t *gnode_file_expr_create (gtoken_s token, cstring_r *list, gnode_t *decl) {
 	if (!list) return NULL;
-	
+
 	gnode_file_expr_t *node = (gnode_file_expr_t *)mem_alloc(sizeof(gnode_file_expr_t));
 	SETBASE(node, NODE_FILE_EXPR, token, NULL);
     SETDECL(node, decl);
@@ -330,7 +330,7 @@ gnode_t *gnode_file_expr_create (gtoken_s token, cstring_r *list, gnode_t *decl)
 
 gnode_t *gnode_identifier_expr_create (gtoken_s token, const char *identifier, const char *identifier2, gnode_t *decl) {
 	if (!identifier) return NULL;
-	
+
 	gnode_identifier_expr_t *node = (gnode_identifier_expr_t *)mem_alloc(sizeof(gnode_identifier_expr_t));
 	SETBASE(node, NODE_IDENTIFIER_EXPR, token, NULL);
     SETDECL(node, decl);
@@ -352,12 +352,12 @@ void gnode_literal_dump (gnode_literal_expr_t *node, char *buffer, int buffersiz
 
 static gnode_t *gnode_literal_value_expr_create (gtoken_s token, gliteral_t type, const char *s, double d, int64_t n64, gnode_t *decl) {
 	gnode_literal_expr_t *node = (gnode_literal_expr_t *)mem_alloc(sizeof(gnode_literal_expr_t));
-	
+
 	SETBASE(node, NODE_LITERAL_EXPR, token, NULL);
     SETDECL(node, decl);
 	node->type = type;
 	node->len = 0;
-	
+
 	switch (type) {
 		case LITERAL_STRING: node->value.str = (char *)s; break;
 		case LITERAL_FLOAT: node->value.d = d; node->len = (d < FLT_MAX) ? 32 : 64; break;
@@ -366,7 +366,7 @@ static gnode_t *gnode_literal_value_expr_create (gtoken_s token, gliteral_t type
 		case LITERAL_STRING_INTERPOLATED: break;
 		default: assert(0); // should never reach this point
 	}
-	
+
 	return (gnode_t *)node;
 }
 
@@ -375,10 +375,10 @@ gnode_t *gnode_string_interpolation_create (gtoken_s token, gnode_r *r, gnode_t
 	node->value.r = r;
 	return (gnode_t *)node;
 }
-	
+
 gnode_t *gnode_literal_string_expr_create (gtoken_s token, char *s, uint32_t len, bool allocated, gnode_t *decl) {
 	gnode_literal_expr_t *node = (gnode_literal_expr_t *)gnode_literal_value_expr_create(token, LITERAL_STRING, NULL, 0, 0, decl);
-	
+
 		node->len = len;
 	if (allocated) {
 		node->value.str = s;
@@ -386,7 +386,7 @@ gnode_t *gnode_literal_string_expr_create (gtoken_s token, char *s, uint32_t len
 		node->value.str = (char *)mem_alloc(len+1);
 		memcpy((void *)node->value.str, (const void *)s, len);
 	}
-	
+
 	return (gnode_t *)node;
 }
 
@@ -404,7 +404,7 @@ gnode_t *gnode_literal_bool_expr_create (gtoken_s token, int32_t n, gnode_t *dec
 
 gnode_t *gnode_keyword_expr_create (gtoken_s token, gnode_t *decl) {
 	gnode_keyword_expr_t *node = (gnode_keyword_expr_t *)mem_alloc(sizeof(gnode_keyword_expr_t));
-	
+
 	SETBASE(node, NODE_KEYWORD_EXPR, token, NULL);
     SETDECL(node, decl);
 	return (gnode_t *)node;
@@ -412,7 +412,7 @@ gnode_t *gnode_keyword_expr_create (gtoken_s token, gnode_t *decl) {
 
 gnode_t *gnode_postfix_subexpr_create (gtoken_s token, gnode_n type, gnode_t *expr, gnode_r *list, gnode_t *decl) {
 	gnode_postfix_subexpr_t *node = (gnode_postfix_subexpr_t *)mem_alloc(sizeof(gnode_postfix_subexpr_t));
-	
+
     SETBASE(node, type, token, NULL);
     SETDECL(node, decl);
 	if (type == NODE_CALL_EXPR)
@@ -424,7 +424,7 @@ gnode_t *gnode_postfix_subexpr_create (gtoken_s token, gnode_n type, gnode_t *ex
 
 gnode_t *gnode_postfix_expr_create (gtoken_s token, gnode_t *id, gnode_r *list, gnode_t *decl) {
 	gnode_postfix_expr_t *node = (gnode_postfix_expr_t *)mem_alloc(sizeof(gnode_postfix_expr_t));
-	
+
 	SETBASE(node, NODE_POSTFIX_EXPR, token, NULL);
     SETDECL(node, decl);
 	node->id = id;
@@ -434,7 +434,7 @@ gnode_t *gnode_postfix_expr_create (gtoken_s token, gnode_t *id, gnode_r *list,
 
 gnode_t *gnode_list_expr_create (gtoken_s token, gnode_r *list1, gnode_r *list2, bool ismap, gnode_t *decl) {
 	gnode_list_expr_t *node = (gnode_list_expr_t *)mem_alloc(sizeof(gnode_list_expr_t));
-	
+
 	SETBASE(node, NODE_LIST_EXPR, token, NULL);
     SETDECL(node, decl);
 	node->ismap = ismap;
@@ -447,13 +447,13 @@ gnode_t *gnode_list_expr_create (gtoken_s token, gnode_r *list1, gnode_r *list2,
 
 gnode_t *gnode_duplicate (gnode_t *node, bool deep) {
 	if (!node) return NULL;
-	
+
 	if (deep == true) {
 		// deep is true so I need to examine node and perform a real duplication (only of the outer nodes)
 		// deep is true ONLY when node can also be part of an assignment and its assignment flag can be
 		// true is node is on the left and false when node is on the right
 		// true flag is used only by adjust_assignment_expression in parser.c
-		
+
 		// node can be: identifier, file or postfix
 		if (NODE_ISA(node, NODE_IDENTIFIER_EXPR)) {
 			gnode_identifier_expr_t *expr = (gnode_identifier_expr_t *)node;
@@ -501,7 +501,7 @@ static void free_list_stmt (gvisitor_t *self, gnode_compound_stmt_t *node) {
 	CHECK_REFCOUNT(node);
 	gnode_array_each(node->stmts, {visit(val);});
 	if (node->stmts) gnode_array_free(node->stmts);
-	
+
 	if (node->symtable) symboltable_free(node->symtable);
 	mem_free((gnode_t*)node);
 }
@@ -510,7 +510,7 @@ static void free_compound_stmt (gvisitor_t *self, gnode_compound_stmt_t *node) {
 	CHECK_REFCOUNT(node);
 	gnode_array_each(node->stmts, {visit(val);});
 	if (node->stmts) gnode_array_free(node->stmts);
-	
+
 	if (node->symtable) symboltable_free(node->symtable);
 	mem_free((gnode_t*)node);
 }
@@ -566,7 +566,7 @@ static void free_function_decl (gvisitor_t *self, gnode_function_decl_t *node) {
 		gnode_array_each(node->params, {free_variable(self, (gnode_var_t *)val);});
 		gnode_array_free(node->params);
 	}
-	
+
 	if (node->block) visit((gnode_t *)node->block);
 	if (node->uplist) {
 		gtype_array_each(node->uplist, {mem_free(val);}, gupvalue_t*);
@@ -635,7 +635,7 @@ static void free_unary_expr (gvisitor_t *self, gnode_unary_expr_t *node) {
 
 static void free_postfix_subexpr (gvisitor_t *self, gnode_postfix_subexpr_t *subnode) {
 	CHECK_REFCOUNT(subnode);
-	
+
 	gnode_n tag = subnode->base.tag;
 	if (tag == NODE_CALL_EXPR) {
 		if (subnode->args) {
@@ -645,15 +645,15 @@ static void free_postfix_subexpr (gvisitor_t *self, gnode_postfix_subexpr_t *sub
 	} else {
 		visit(subnode->expr);
 	}
-	
+
 	mem_free((gnode_t*)subnode);
 }
 
 static void free_postfix_expr (gvisitor_t *self, gnode_postfix_expr_t *node) {
 	CHECK_REFCOUNT(node);
-	
+
 	visit(node->id);
-	
+
 	// node->list can be NULL due to enum static conversion
 	size_t count = gnode_array_size(node->list);
 	for (size_t i=0; i<count; ++i) {
@@ -670,7 +670,7 @@ static void free_file_expr (gvisitor_t *self, gnode_file_expr_t *node) {
 	cstring_array_each(node->identifiers, {
 		mem_free((void *)val);
 	});
-	
+
 	if (node->identifiers) gnode_array_free(node->identifiers);
 	mem_free((void *)node);
 }
@@ -720,11 +720,11 @@ void gnode_free (gnode_t *ast) {
 		.nerr = 0,
 		.data = NULL,
 		.delegate = NULL,
-		
+
         // COMMON
         .visit_pre = NULL,
         .visit_post = NULL,
-        
+
 		// STATEMENTS: 7
 		.visit_list_stmt = free_list_stmt,
 		.visit_compound_stmt = free_compound_stmt,
@@ -733,14 +733,14 @@ void gnode_free (gnode_t *ast) {
 		.visit_loop_stmt = free_loop_stmt,
 		.visit_jump_stmt = free_jump_stmt,
 		.visit_empty_stmt = free_empty_stmt,
-		
+
 		// DECLARATIONS: 5
 		.visit_function_decl = free_function_decl,
 		.visit_variable_decl = free_variable_decl,
 		.visit_enum_decl = free_enum_decl,
 		.visit_class_decl = free_class_decl,
 		.visit_module_decl = free_module_decl,
-		
+
 		// EXPRESSIONS: 7+1
 		.visit_binary_expr = free_binary_expr,
 		.visit_unary_expr = free_unary_expr,
@@ -751,6 +751,6 @@ void gnode_free (gnode_t *ast) {
 		.visit_list_expr = free_list_expr,
 		.visit_postfix_expr = free_postfix_expr
 	};
-	
+
     gvisit(&visitor, ast);
 }

+ 2 - 2
src/compiler/gravity_ast.h

@@ -25,11 +25,11 @@ typedef enum {
 
 	// declarations: 6
 	NODE_ENUM_DECL, NODE_FUNCTION_DECL, NODE_VARIABLE_DECL, NODE_CLASS_DECL, NODE_MODULE_DECL, NODE_VARIABLE,
-	
+
 	// expressions: 8
 	NODE_BINARY_EXPR, NODE_UNARY_EXPR, NODE_FILE_EXPR, NODE_LIST_EXPR, NODE_LITERAL_EXPR, NODE_IDENTIFIER_EXPR,
 	NODE_POSTFIX_EXPR, NODE_KEYWORD_EXPR,
-	
+
 	// postfix subexpression type
 	NODE_CALL_EXPR, NODE_SUBSCRIPT_EXPR, NODE_ACCESS_EXPR
 } gnode_n;

File diff suppressed because it is too large
+ 155 - 155
src/compiler/gravity_codegen.c


+ 23 - 23
src/compiler/gravity_compiler.c

@@ -34,18 +34,18 @@ static void internal_vm_transfer (gravity_vm *vm, gravity_object_t *obj) {
 
 static void internal_free_class (gravity_hash_t *hashtable, gravity_value_t key, gravity_value_t value, void *data) {
 	#pragma unused (hashtable, data)
-	
+
 	// sanity checks
 	if (!VALUE_ISA_FUNCTION(value)) return;
 	if (!VALUE_ISA_STRING(key)) return;
-	
+
 	// check for special function
 	gravity_function_t *f = VALUE_AS_FUNCTION(value);
 	if (f->tag == EXEC_TYPE_SPECIAL) {
 		if (f->special[0]) gravity_function_free(NULL, (gravity_function_t *)f->special[0]);
 		if (f->special[1]) gravity_function_free(NULL, (gravity_function_t *)f->special[1]);
 	}
-	
+
 	// a super special init constructor is a string that begins with $init AND it is longer than strlen($init)
 	gravity_string_t *s = VALUE_AS_STRING(key);
 	bool is_super_function = ((s->len > 5) && (string_casencmp(s->s, CLASS_INTERNAL_INIT_NAME, 5) == 0));
@@ -70,7 +70,7 @@ static void internal_vm_cleanup (gravity_vm *vm) {
 gravity_compiler_t *gravity_compiler_create (gravity_delegate_t *delegate) {
 	gravity_compiler_t *compiler = mem_alloc(sizeof(gravity_compiler_t));
 	if (!compiler) return NULL;
-	
+
 	compiler->ast = NULL;
 	compiler->objects = void_array_create();
 	compiler->delegate = delegate;
@@ -83,21 +83,21 @@ static void gravity_compiler_reset (gravity_compiler_t *compiler, bool free_core
 		cstring_array_each(compiler->storage, {mem_free((void *)val);});
 		gnode_array_free(compiler->storage);
 	}
-	
+
 	// first ast then parser, don't change the release order
 	if (compiler->ast) gnode_free(compiler->ast);
 	if (compiler->parser) gravity_parser_free(compiler->parser);
-	
+
 	// at the end free mini VM and objects array
 	if (compiler->vm) gravity_vm_free(compiler->vm);
 	if (compiler->objects) {
 		marray_destroy(*compiler->objects);
 		mem_free((void*)compiler->objects);
 	}
-	
+
 	// feel free to free core if someone requires it
     if (free_core) gravity_core_free();
-	
+
 	// reset internal pointers
 	compiler->vm = NULL;
 	compiler->ast = NULL;
@@ -117,7 +117,7 @@ gnode_t *gravity_compiler_ast (gravity_compiler_t *compiler) {
 
 void gravity_compiler_transfer(gravity_compiler_t *compiler, gravity_vm *vm) {
 	if (!compiler->objects) return;
-	
+
 	// transfer each object from compiler mini VM to exec VM
 	gravity_gc_setenabled(vm, false);
 	size_t count = marray_size(*compiler->objects);
@@ -125,7 +125,7 @@ void gravity_compiler_transfer(gravity_compiler_t *compiler, gravity_vm *vm) {
 		gravity_object_t *obj = marray_pop(*compiler->objects);
 		gravity_vm_transfer(vm, obj);
 		if (!OBJECT_ISA_CLOSURE(obj)) continue;
-		
+
 		// $moduleinit closure needs to be explicitly initialized
 		gravity_closure_t *closure = (gravity_closure_t *)obj;
 		if ((closure->f->identifier) && strcmp(closure->f->identifier, INITMODULE_NAME) == 0) {
@@ -134,7 +134,7 @@ void gravity_compiler_transfer(gravity_compiler_t *compiler, gravity_vm *vm) {
 			gravity_vm_initmodule(vm, closure->f);
 		}
 	}
-	
+
 	gravity_gc_setenabled(vm, true);
 }
 
@@ -142,43 +142,43 @@ void gravity_compiler_transfer(gravity_compiler_t *compiler, gravity_vm *vm) {
 
 gravity_closure_t *gravity_compiler_run (gravity_compiler_t *compiler, const char *source, size_t len, uint32_t fileid, bool is_static) {
 	if ((source == NULL) || (len == 0)) return NULL;
-	
+
 	// CHECK cleanup first
 	if (compiler->ast) gnode_free(compiler->ast);
 	if (!compiler->objects) compiler->objects = void_array_create();
-	
+
 	// CODEGEN requires a mini vm in order to be able to handle garbage collector
 	compiler->vm = gravity_vm_newmini();
 	gravity_vm_setdata(compiler->vm, (void *)compiler);
 	gravity_vm_set_callbacks(compiler->vm, internal_vm_transfer, internal_vm_cleanup);
 	gravity_core_register(compiler->vm);
-	
+
 	// STEP 0: CREATE PARSER
 	compiler->parser = gravity_parser_create(source, len, fileid, is_static);
 	if (!compiler->parser) return NULL;
-	
+
 	// STEP 1: SYNTAX CHECK
 	compiler->ast = gravity_parser_run(compiler->parser, compiler->delegate);
 	if (!compiler->ast) goto abort_compilation;
 	gravity_parser_free(compiler->parser);
 	compiler->parser = NULL;
-	
+
 	// STEP 2a: SEMANTIC CHECK (NON-LOCAL DECLARATIONS)
 	bool b1 = gravity_semacheck1(compiler->ast, compiler->delegate);
 	if (!b1) goto abort_compilation;
-	
+
 	// STEP 2b: SEMANTIC CHECK (LOCAL DECLARATIONS)
 	bool b2 = gravity_semacheck2(compiler->ast, compiler->delegate);
 	if (!b2) goto abort_compilation;
-	
+
 	// STEP 3: INTERMEDIATE CODE GENERATION (stack based VM)
 	gravity_function_t *f = gravity_codegen(compiler->ast, compiler->delegate, compiler->vm);
 	if (!f) goto abort_compilation;
-	
+
 	// STEP 4: CODE GENERATION (register based VM)
 	f = gravity_optimizer(f);
 	if (f) return gravity_closure_new(compiler->vm, f);
-	
+
 abort_compilation:
 	gravity_compiler_reset(compiler, false);
 	return NULL;
@@ -186,12 +186,12 @@ abort_compilation:
 
 json_t *gravity_compiler_serialize (gravity_compiler_t *compiler, gravity_closure_t *closure) {
 	#pragma unused(compiler)
-	
+
 	json_t *json = json_new();
 	json_begin_object(json, NULL);
-	
+
 	gravity_function_serialize(closure->f, json);
-	
+
 	json_end_object(json);
 	return json;
 }

+ 36 - 36
src/compiler/gravity_ircode.c

@@ -15,16 +15,16 @@ typedef marray_t(bool *)		context_r;
 
 struct ircode_t {
 	code_r		*list;						// array of ircode instructions
-	
+
 	uint32_r	label_true;					// labels used in loops
 	uint32_r	label_false;
 	uint32_t	label_counter;
-	
+
 	uint32_t	maxtemp;					// maximum number of temp registers used in this ircode
 	uint32_t	ntemps;						// current number of temp registers in use
 	uint16_t	nlocals;					// number of local registers (params + local variables)
 	bool		error;						// error flag set when no more registers are availables
-	
+
 	bool		state[MAX_REGISTERS];		// registers mask
 	bool		skipclear[MAX_REGISTERS];	// registers protection for temps used in for loop
 	uint32_r	registers;					// registers stack
@@ -38,14 +38,14 @@ ircode_t *ircode_create (uint16_t nlocals) {
 	code->ntemps = 0;
 	code->maxtemp = 0;
 	code->error = false;
-	
+
 	code->list = mem_alloc(sizeof(code_r));
 	marray_init(*code->list);
 	marray_init(code->label_true);
 	marray_init(code->label_false);
 	marray_init(code->registers);
 	marray_init(code->context);
-	
+
 	// init state array (register 0 is reserved)
 	bzero(code->state, MAX_REGISTERS * sizeof(bool));
 	code->state[0] = true;
@@ -61,7 +61,7 @@ void ircode_free (ircode_t *code) {
 		inst_t *inst = marray_get(*code->list, i);
 		mem_free(inst);
 	}
-	
+
 	marray_destroy(*code->list);
     marray_destroy(code->context);
 	marray_destroy(code->registers);
@@ -90,14 +90,14 @@ bool ircode_iserror (ircode_t *code) {
 // MARK: -
 
 static inst_t *inst_new (opcode_t op, uint32_t p1, uint32_t p2, uint32_t p3, optag_t tag, int64_t n, double d) {
-	
+
 	// debug code
 	#if GRAVITY_OPCODE_DEBUG
 	if (tag == LABEL_TAG) {
 		DEBUG_OPCODE("LABEL %d", p1);
 	} else {
 		const char *op_name = opcode_name(op);
-		
+
 		if (op == LOADI) {
 			if (tag == DOUBLE_TAG)
 				printf("%s %d %.2f\n", op_name, p1, d);
@@ -117,17 +117,17 @@ static inst_t *inst_new (opcode_t op, uint32_t p1, uint32_t p2, uint32_t p3, opt
 		}
 	}
 	#endif
-	
+
 	inst_t *inst = (inst_t *)mem_alloc(sizeof(inst_t));
 	inst->op = op;
 	inst->tag = tag;
 	inst->p1 = p1;
 	inst->p2 = p2;
 	inst->p3 = p3;
-	
+
 	if (tag == DOUBLE_TAG) inst->d = d;
 	else if (tag == INT_TAG) inst->n = n;
-	
+
 	assert(inst);
 	return inst;
 }
@@ -142,35 +142,35 @@ void ircode_patch_init (ircode_t *code, uint16_t index) {
 	// LOAD  temp 0 temp
 	// MOVE  temp+1 0
 	// CALL  temp temp 1
-	
+
 	// load constant
 	uint32_t dest = ircode_register_push_temp(code);
 	inst_t *inst1 = inst_new(LOADK, dest, index, 0, NO_TAG, 0, 0.0);
-	
+
 	// load from lookup
 	inst_t *inst2 = inst_new(LOAD, dest, 0, dest, NO_TAG, 0, 0.0);
-	
+
 	// prepare parameter
 	uint32_t dest2 = ircode_register_push_temp(code);
 	inst_t *inst3 = inst_new(MOVE, dest2, 0, 0, NO_TAG, 0, 0.0);
 	ircode_register_pop(code);
-	
+
 	// execute call
 	inst_t *inst4 = inst_new(CALL, dest, dest, 1, NO_TAG, 0, 0.0);
-	
+
 	// pop temps used
 	ircode_register_pop(code);
-	
+
 	// create new instruction list
 	code_r		*list = mem_alloc(sizeof(code_r));
 	marray_init(*list);
-	
+
 	// add newly create instructions
 	marray_push(inst_t*, *list, inst1);
 	marray_push(inst_t*, *list, inst2);
 	marray_push(inst_t*, *list, inst3);
 	marray_push(inst_t*, *list, inst4);
-	
+
 	// then copy original instructions
 	code_r *orig_list = code->list;
 	uint32_t count = ircode_count(code);
@@ -178,11 +178,11 @@ void ircode_patch_init (ircode_t *code, uint16_t index) {
 		inst_t *inst = marray_get(*orig_list, i);
 		marray_push(inst_t*, *list, inst);
 	}
-	
+
 	// free dest list
 	marray_destroy(*orig_list);
 	mem_free(code->list);
-	
+
 	// replace dest list with the newly created list
 	code->list = list;
 }
@@ -247,7 +247,7 @@ uint8_t opcode_numop (opcode_t op) {
 		case RESERVED5:
 		case RESERVED6: return 0;
 	}
-	
+
 	assert(0);
 	return 0;
 }
@@ -256,12 +256,12 @@ void ircode_dump  (void *_code) {
 	ircode_t	*code = (ircode_t *)_code;
 	code_r		*list = code->list;
 	uint32_t	count = ircode_count(code);
-	
+
 	if (count == 0) {
 		printf("NONE\n");
 		return;
 	}
-	
+
 	for (uint32_t i=0, line=0; i<count; ++i) {
 		inst_t *inst = marray_get(*list, i);
 		opcode_t	op = inst->op;
@@ -271,19 +271,19 @@ void ircode_dump  (void *_code) {
 		if (inst->tag == SKIP_TAG) continue;
 		if (inst->tag == PRAGMA_MOVE_OPTIMIZATION) continue;
 		if (inst->tag == LABEL_TAG) {printf("LABEL %d:\n", p1); continue;}
-		
+
 		uint8_t n = opcode_numop(op);
 		if ((op == SETLIST) && (p2 == 0)) n = 2;
-		
+
 		switch (n) {
 			case 0: {
 				printf("%05d\t%s\n", line, opcode_name(op));
 			}
-			
+
 			case 1: {
 				printf("%05d\t%s %d\n", line, opcode_name(op), p1);
 			} break;
-				
+
 			case 2: {
 				if (op == LOADI) {
 					if (inst->tag == DOUBLE_TAG) printf("%05d\t%s %d %.2f\n", line, opcode_name(op), p1, inst->d);
@@ -299,11 +299,11 @@ void ircode_dump  (void *_code) {
 					printf("%05d\t%s %d %d\n", line, opcode_name(op), p1, p2);
 				}
 			} break;
-				
+
 			case 3: {
 				printf("%05d\t%s %d %d %d\n", line, opcode_name(op), p1, p2, p3);
 			} break;
-				
+
 			default: assert(0);
 		}
 		++line;
@@ -426,15 +426,15 @@ void ircode_pop_context (ircode_t *code) {
 uint32_t ircode_register_pop_context_protect (ircode_t *code, bool protect) {
 	if (marray_size(code->registers) == 0) return REGISTER_ERROR;
 	uint32_t value = (uint32_t)marray_pop(code->registers);
-	
+
 	if (protect) code->state[value] = true;
 	else if (value >= code->nlocals) code->state[value] = false;
-	
+
 	if (protect && value >= code->nlocals) {
 		bool *context = marray_last(code->context);
 		context[value] = true;
 	}
-	
+
 	DEBUG_REGISTER("POP REGISTER %d", value);
 	return value;
 }
@@ -470,7 +470,7 @@ static uint32_t ircode_register_new (ircode_t *code) {
 uint32_t ircode_register_push (ircode_t *code, uint32_t nreg) {
 	marray_push(uint32_t, code->registers, nreg);
 	if (ircode_register_istemp(code, nreg)) ++code->ntemps;
-	
+
 	DEBUG_REGISTER("PUSH REGISTER %d", nreg);
 	return nreg;
 }
@@ -479,7 +479,7 @@ uint32_t ircode_register_push_temp (ircode_t *code) {
 	uint32_t value = ircode_register_new(code);
 	marray_push(uint32_t, code->registers, value);
 	if (value > code->maxtemp) {code->maxtemp = value; ++code->ntemps;}
-	
+
 	DEBUG_REGISTER("PUSH REGISTER %d", value);
 	return value;
 }
@@ -532,7 +532,7 @@ void ircode_register_unset_skip_clear (ircode_t *code, uint32_t nreg) {
 	code->skipclear[nreg] = false;
 }
 
-void ircode_register_clear_temps (ircode_t *code) {	
+void ircode_register_clear_temps (ircode_t *code) {
 	// clear all temporary registers (if not protected)
 	for (uint32_t i=code->nlocals; i<=code->maxtemp; ++i) {
 		if (!code->skipclear[i]) code->state[i] = false;

+ 58 - 58
src/compiler/gravity_lexer.c

@@ -20,7 +20,7 @@ struct gravity_lexer_t {
 	uint32_t					lineno;			// line counter
 	uint32_t					colno;			// column counter
 	uint32_t					fileid;			// current file id
-	
+
 	gtoken_s					token;			// current token
 	bool						peeking;		// flag to check if a peek operation is in progress
 	bool						is_static;		// flag to check if buffer is static and must not be freed
@@ -75,30 +75,30 @@ static inline bool is_newline (gravity_lexer_t *lexer, int c) {
 	// CR: Carriage Return, U+000D (UTF-8 in hex: 0D)
 	// LF: Line Feed, U+000A (UTF-8 in hex: 0A)
 	// CR+LF: CR (U+000D) followed by LF (U+000A) (UTF-8 in hex: 0D0A)
-	
+
 	// LF
 	if (c == 0x0A) return true;
-	
+
 	// CR+LF or CR
 	if (c == 0x0D) {
 		if (PEEK_NEXT == 0x0A) {NEXT; return true;}
 		return true;
 	}
-	
+
 	// UTF-8 cases https://en.wikipedia.org/wiki/Newline#Unicode
-	
+
 	// NEL: Next Line, U+0085 (UTF-8 in hex: C285)
 	if ((c == 0xC2) && (PEEK_NEXT == 0x85)) {
 		NEXT;
 		return true;
 	}
-	
+
 	// LS: Line Separator, U+2028 (UTF-8 in hex: E280A8)
 	if ((c == 0xE2) && (PEEK_NEXT == 0x80) && (PEEK_NEXT2 == 0xA8)) {
 		NEXT; NEXT;
 		return true;
 	}
-		
+
 	// and probably more not handled here
 	return false;
 }
@@ -138,7 +138,7 @@ static inline bool is_builtin_operator (int c) {
 	// . ; : ? ,
 	// OPERATORS
 	// + - * / < > ! = | & ^ % ~
-	
+
 	return ((c == '+') || (c == '-') || (c == '*') || (c == '/') ||
 			(c == '<') || (c == '>') || (c == '!') || (c == '=') ||
 			(c == '|') || (c == '&') || (c == '^') || (c == '%') ||
@@ -173,37 +173,37 @@ static gtoken_t lexer_error(gravity_lexer_t *lexer, const char *message) {
 static inline bool next_utf8(gravity_lexer_t *lexer, int *result) {
 	int c = NEXT;
 	INC_TOKLEN;
-	
+
 	uint32_t len = utf8_charbytes((const char *)&c, 0);
 	if (len == 0) return false;
-	
+
 	switch(len) {
 		case 1: break;
 		case 2: INC_OFFSET; INC_TOKBYTES; break;
 		case 3: INC_OFFSET; INC_OFFSET; INC_TOKBYTES; INC_TOKBYTES; break;
 		case 4: INC_OFFSET; INC_OFFSET; INC_OFFSET; INC_TOKBYTES; INC_TOKBYTES; INC_TOKBYTES; INC_POSITION; INC_TOKUTF8LEN; break;
 	}
-	
+
 	if (result) *result = c;
 	return true;
 }
 
 static gtoken_t lexer_scan_comment(gravity_lexer_t *lexer) {
 	bool isLineComment = (PEEK_NEXT == '/');
-	
+
 	TOKEN_RESET;
 	INC_OFFSET_POSITION;
 	INC_OFFSET_POSITION;
-	
+
 	// because I already scanned /* or //
 	lexer->token.bytes = lexer->token.length = 2;
-	
+
 	// count variable used only to support nested comments
 	int count = 1;
 	while (!IS_EOF) {
 		int c = 0;
 		next_utf8(lexer, &c);
-		
+
 		if (isLineComment){
 			if (is_newline(lexer, c)) {INC_LINE; break;}
 		} else {
@@ -214,15 +214,15 @@ static gtoken_t lexer_scan_comment(gravity_lexer_t *lexer) {
 			if (is_newline(lexer, c)) {INC_LINE;}
 		}
 	}
-	
+
 	// comment is from buffer->[nseek] and it is nlen length
 	TOKEN_FINALIZE(TOK_COMMENT);
-	
+
 	// comments callback is called directly from the scan function and not from the main scan loop
 	if ((lexer->delegate) && (lexer->delegate->parser_callback)) {
 		lexer->delegate->parser_callback(&lexer->token, lexer->delegate->xdata);
 	}
-	
+
 	DEBUG_LEXEM("Found comment");
 	return TOK_COMMENT;
 }
@@ -232,29 +232,29 @@ static gtoken_t lexer_scan_semicolon(gravity_lexer_t *lexer) {
 	INC_TOKLEN;
 	INC_OFFSET_POSITION;
 	TOKEN_FINALIZE(TOK_OP_SEMICOLON);
-	
+
 	return TOK_OP_SEMICOLON;
 }
 
-static gtoken_t lexer_scan_identifier(gravity_lexer_t *lexer) {	
+static gtoken_t lexer_scan_identifier(gravity_lexer_t *lexer) {
 	TOKEN_RESET;
 	while (is_identifier(PEEK_CURRENT)) {
 		INC_OFFSET_POSITION;
 		INC_TOKLEN;
 	}
 	TOKEN_FINALIZE(TOK_IDENTIFIER);
-	
+
     // check if identifier is a special built-in case
     gtoken_t type = token_special_builtin(&lexer->token);
     // then check if it is a reserved word (otherwise reports it as an identifier)
     if (type == TOK_IDENTIFIER) type = token_keyword(lexer->token.value, lexer->token.bytes);
 	SET_TOKTYPE(type);
-	
+
 	#if GRAVITY_LEXEM_DEBUG
 	if (type == TOK_IDENTIFIER) DEBUG_LEXEM("Found identifier: %.*s", TOKEN_BYTES(lexer->token), TOKEN_VALUE(lexer->token));
 	else DEBUG_LEXEM("Found keyword: %s", token_name(type));
 	#endif
-	
+
 	return type;
 }
 
@@ -266,14 +266,14 @@ static gtoken_t lexer_scan_number(gravity_lexer_t *lexer) {
 	bool		expFound = false;
 	int			c, expChar = 'e', floatChar = '.';
 	int			plusSign = '+', minusSign = '-';
-	
+
 	gravity_number_type	ntype = NUMBER_INTEGER;
 	if (PEEK_CURRENT == '0') {
 		if (toupper(PEEK_NEXT) == 'X') {ntype = NUMBER_HEX; floatAllowed = false; expAllowed = false;}
 		else if (toupper(PEEK_NEXT) == 'B') {ntype = NUMBER_BIN; floatAllowed = false; expAllowed = false;}
 		else if (toupper(PEEK_NEXT) == 'O') {ntype = NUMBER_OCT; floatAllowed = false; expAllowed = false;}
 	}
-	
+
 	TOKEN_RESET;
 	if (ntype != NUMBER_INTEGER) {
 		// skip first 0* number marker
@@ -282,7 +282,7 @@ static gtoken_t lexer_scan_number(gravity_lexer_t *lexer) {
 		INC_OFFSET_POSITION;
 		INC_OFFSET_POSITION;
 	}
-	
+
 	// supported exp formats:
 	// 12345	// decimal
 	// 3.1415	// float
@@ -291,16 +291,16 @@ static gtoken_t lexer_scan_number(gravity_lexer_t *lexer) {
 	// 0xFFFF	// hex
 	// 0B0101	// binary
 	// 0O7777	// octal
-	
+
 loop:
 	c = PEEK_CURRENT;
-	
+
 	// explicitly list all accepted cases
 	if (IS_EOF) goto report_token;
 	if (is_digit(c, ntype)) goto accept_char;
 	if (is_whitespace(c)) goto report_token;
 	if (is_newline(lexer, c)) goto report_token;
-	
+
 	if (expAllowed) {
 		if ((c == expChar) && (!expFound)) {expFound = true; signAllowed = true; goto accept_char;}
 	}
@@ -313,10 +313,10 @@ loop:
 	}
 	if (is_builtin_operator(c)) goto report_token;
 	if (is_semicolon(c)) goto report_token;
-	
+
 	// any other case is an error
 	goto report_error;
-	
+
 accept_char:
 	INC_TOKLEN;
 	INC_OFFSET_POSITION;
@@ -325,48 +325,48 @@ accept_char:
 report_token:
 	// number is from buffer->[nseek] and it is bytes length
 	TOKEN_FINALIZE(TOK_NUMBER);
-	
+
 	DEBUG_LEXEM("Found number: %.*s", TOKEN_BYTES(lexer->token), TOKEN_VALUE(lexer->token));
 	return TOK_NUMBER;
-	
+
 report_error:
 	return lexer_error(lexer, "Malformed number expression.");
 }
 
 static gtoken_t lexer_scan_string(gravity_lexer_t *lexer) {
 	int c, c2;
-	
+
 	// no memory allocation here
 	c = NEXT;					// save escaped character
 	TOKEN_RESET;				// save offset
-	
+
 	while ((c2 = (unsigned char)PEEK_CURRENT) != c) {
 		if (IS_EOF) return lexer_error(lexer, "Unexpected EOF inside a string literal");
 		if (is_newline(lexer, c2)) INC_LINE;
-		
+
 		// handle escaped characters
 		if (c2 == '\\') {
 			INC_OFFSET_POSITION;
 			INC_OFFSET_POSITION;
 			INC_TOKLEN;
 			INC_TOKLEN;
-            
+
             // sanity check
             if (IS_EOF) return lexer_error(lexer, "Unexpected EOF inside a string literal");
 			continue;
 		}
-		
+
 		// scan next
 		if (!next_utf8(lexer, NULL)) return lexer_error(lexer, "Unknown character inside a string literal");
         if (IS_EOF) return lexer_error(lexer, "Unexpected EOF inside a string literal");
 	}
-	
+
 	// skip last escape character
 	INC_OFFSET_POSITION;
-	
+
 	// string is from buffer->[nseek] and it is nlen length
 	TOKEN_FINALIZE(TOK_STRING);
-	
+
 	DEBUG_LEXEM("Found string: %.*s", TOKEN_BYTES(lexer->token), TOKEN_VALUE(lexer->token));
 	return TOK_STRING;
 }
@@ -374,11 +374,11 @@ static gtoken_t lexer_scan_string(gravity_lexer_t *lexer) {
 static gtoken_t lexer_scan_operator(gravity_lexer_t *lexer) {
 	TOKEN_RESET;
 	INC_TOKLEN;
-	
+
 	int c = NEXT;
 	int c2 = PEEK_CURRENT;
 	int tok = 0;
-	
+
 	switch (c) {
 		case '=':
 			if (c2 == '=') {
@@ -495,13 +495,13 @@ static gtoken_t lexer_scan_operator(gravity_lexer_t *lexer) {
 			break;
 		default:
 			return lexer_error(lexer, "Unrecognized Operator");
-			
+
 	}
-	
+
 	TOKEN_FINALIZE(tok);
-	
+
 	DEBUG_LEXEM("Found operator: %s", token_name(tok));
-	return tok;	
+	return tok;
 }
 
 static gtoken_t lexer_scan_special(gravity_lexer_t *lexer) {
@@ -509,7 +509,7 @@ static gtoken_t lexer_scan_special(gravity_lexer_t *lexer) {
 	INC_TOKLEN;
 	INC_OFFSET_POSITION;
 	TOKEN_FINALIZE(TOK_SPECIAL);
-	
+
 	return TOK_SPECIAL;
 }
 
@@ -518,7 +518,7 @@ static gtoken_t lexer_scan_preprocessor(gravity_lexer_t *lexer) {
 	INC_TOKLEN;
 	INC_OFFSET_POSITION;
 	TOKEN_FINALIZE(TOK_MACRO);
-	
+
 	return TOK_MACRO;
 }
 
@@ -528,7 +528,7 @@ gravity_lexer_t *gravity_lexer_create (const char *source, size_t len, uint32_t
 	gravity_lexer_t *lexer = mem_alloc(sizeof(gravity_lexer_t));
 	if (!lexer) return NULL;
 	bzero(lexer, sizeof(gravity_lexer_t));
-	
+
 	lexer->is_static = is_static;
 	lexer->lineno = 1;
 	lexer->buffer = source;
@@ -545,27 +545,27 @@ void gravity_lexer_setdelegate (gravity_lexer_t *lexer, gravity_delegate_t *dele
 gtoken_t gravity_lexer_peek (gravity_lexer_t *lexer) {
 	lexer->peeking = true;
 	gravity_lexer_t saved = *lexer;
-	
+
 	gtoken_t result = gravity_lexer_next(lexer);
-	
+
 	*lexer = saved;
 	lexer->peeking = false;
-	
+
 	return result;
 }
 
 gtoken_t gravity_lexer_next (gravity_lexer_t *lexer) {
 	int			c;
 	gtoken_t	token;
-	
+
 loop:
 	if (IS_EOF) return TOK_EOF;
 	c = PEEK_CURRENT;
-	
+
 	if (is_whitespace(c)) {INC_OFFSET_POSITION; goto loop;}
 	if (is_newline(lexer, c)) {INC_OFFSET_POSITION; INC_LINE; goto loop;}
 	if (is_comment(c, PEEK_NEXT)) {lexer_scan_comment(lexer); goto loop;}
-	
+
 	if (is_semicolon(c)) {token = lexer_scan_semicolon(lexer); goto return_result;}
 	if (is_alpha(c)) {token = lexer_scan_identifier(lexer); goto return_result;}
 	if (is_digit(c, false)) {token = lexer_scan_number(lexer); goto return_result;}
@@ -573,9 +573,9 @@ loop:
 	if (is_builtin_operator(c)) {token = lexer_scan_operator(lexer); goto return_result;}
 	if (is_special(c)) {token = lexer_scan_special(lexer); goto return_result;}
 	if (is_preprocessor(c)) {token = lexer_scan_preprocessor(lexer); goto return_result;}
-	
+
 	return lexer_error(lexer, "Unrecognized token");
-	
+
 return_result:
 	LEXER_CALL_CALLBACK();
 	return token;

+ 4 - 4
src/compiler/gravity_lexer.h

@@ -16,24 +16,24 @@
 /*
 	Lexer is built in such a way that no memory allocations are necessary during usage
 	(except for the gravity_lexer_t opaque datatype allocated within gravity_lexer_create).
- 
+
 	Example:
 	gravity_lexer *lexer = gravity_lexer_create(...);
 	while (gravity_lexer_next(lexer)) {
 		// do something here
 	}
 	gravity_lexer_free(lexer);
-	
+
 	gravity_lexer_next (and gravity_lexer_peek) returns an int token (gtoken_t)
 	which represents what has been currently scanned. When EOF is reached TOK_EOF is
 	returned (with value 0) and the while loop exits.
-	
+
 	In order to have token details, gravity_lexer_token must be called.
 	In case of a scan error TOK_ERROR is returned and error details can be extracted
 	from the token itself. In order to be able to not allocate any memory during
 	tokenization STRINGs and NUMBERs are just sanity checked but not converted.
 	It is parser responsability to perform the right conversion.
- 
+
  */
 
 // opaque datatype

+ 61 - 61
src/compiler/gravity_optimizer.c

@@ -54,7 +54,7 @@ static void finalize_function (gravity_function_t *f) {
 	uint32_t		notpure = 0;
 	uint32_t		*bytecode = NULL;
 	gravity_hash_t	*labels = gravity_hash_create(0, hash_compute, hash_isequal, NULL, NULL);
-	
+
 	// determine how big bytecode buffer must be
 	// and collect all LABEL instructions
 	for (uint32_t i=0; i<count; ++i) {
@@ -68,19 +68,19 @@ static void finalize_function (gravity_function_t *f) {
 		}
 		++ninst;
 	}
-	
+
 	// +1 is just a trick so the VM switch loop terminates with an implicit RET0 instruction (RET0 has opcode 0)
 	f->ninsts = ninst;
 	bytecode = (uint32_t *)mem_alloc((ninst+1) * sizeof(uint32_t));
 	assert(bytecode);
-	
+
 	uint32_t j=0;
 	for (uint32_t i=0; i<count; ++i) {
 		inst_t *inst = ircode_get(code, i);
 		if (IS_SKIP(inst)) continue;
 		if (IS_LABEL(inst)) continue;
 		if (IS_PRAGMA_MOVE_OPT(inst)) continue;
-		
+
 		uint32_t op = 0x0;
 		switch (inst->op) {
 			case HALT:
@@ -88,7 +88,7 @@ static void finalize_function (gravity_function_t *f) {
 			case NOP:
 				OPCODE_SET(op, inst->op);
 				break;
-			
+
 			case LOAD:
 			case STORE:
 				++notpure;	// not sure here
@@ -122,11 +122,11 @@ static void finalize_function (gravity_function_t *f) {
 			case NOT:
 				OPCODE_SET_TWO8bit_ONE10bit(op, inst->op, inst->p1, inst->p2, inst->p3);
 				break;
-			
+
 			case LOADI:
 				OPCODE_SET_ONE8bit_SIGN_ONE17bit(op, inst->op, inst->p1, (inst->n < 0) ? 1 : 0, inst->n);
 				break;
-				
+
 			case JUMPF: {
 				gravity_value_t *v = gravity_hash_lookup(labels, VALUE_FROM_INT(inst->p2));
 				assert(v); // key MUST exists!
@@ -136,11 +136,11 @@ static void finalize_function (gravity_function_t *f) {
 				//OPCODE_SET_ONE8bit_ONE18bit(op, inst->op, inst->p1, njump);
 				break;
 			}
-			
+
 			case RET:
 				OPCODE_SET_ONE8bit(op, inst->op, inst->p1);
 				break;
-				
+
 			case JUMP: {
 				gravity_value_t *v = gravity_hash_lookup(labels, VALUE_FROM_INT(inst->p1));
 				assert(v); // key MUST exists!
@@ -148,7 +148,7 @@ static void finalize_function (gravity_function_t *f) {
 				OPCODE_SET_ONE26bit(op, inst->op, njump);
 				break;
 			}
-			
+
 			case LOADG:
 			case STOREG:
 				++notpure;
@@ -156,21 +156,21 @@ static void finalize_function (gravity_function_t *f) {
 			case LOADK:
 				OPCODE_SET_ONE8bit_ONE18bit(op, inst->op, inst->p1, inst->p2);
 				break;
-				
+
 			case CALL:
 				OPCODE_SET_TWO8bit_ONE10bit(op, inst->op, inst->p1, inst->p2, inst->p3);
 				break;
-			
+
 			case SETLIST:
 				OPCODE_SET_TWO8bit_ONE10bit(op, inst->op, inst->p1, inst->p2, inst->p3);
 				break;
-				
+
 			case LOADU:
 			case STOREU:
 				++notpure;
 				OPCODE_SET_ONE8bit_ONE18bit(op, inst->op, inst->p1, inst->p2);
 				break;
-			
+
 			case RANGENEW: {
 				uint8_t flag = (inst->tag == RANGE_INCLUDE_TAG) ? 0 : 1;
 				OPCODE_SET_THREE8bit_ONE2bit(op, inst->op, inst->p1, inst->p2, inst->p3, flag);
@@ -180,16 +180,16 @@ static void finalize_function (gravity_function_t *f) {
 			case LISTNEW:
 				OPCODE_SET_ONE8bit_ONE18bit(op, inst->op, inst->p1, inst->p2);
 				break;
-				
+
 			case SWITCH:
 				assert(0);
 				break;
-				
+
 			case CLOSURE:
 			case CLOSE:
 				OPCODE_SET_ONE8bit_ONE18bit(op, inst->op, inst->p1, inst->p2);
 				break;
-				
+
 			case RESERVED1:
 			case RESERVED2:
 			case RESERVED3:
@@ -199,14 +199,14 @@ static void finalize_function (gravity_function_t *f) {
 				assert(0);
 				break;
 		}
-		
+
 		// store encoded instruction
 		bytecode[j++] = op;
 	}
-	
+
 	ircode_free(code);
 	gravity_hash_free(labels);
-	
+
 	f->bytecode = bytecode;
 	f->purity = (notpure == 0) ? 1.0f : ((float)(notpure * 100) / (float)ninst) / 100.0f;
 }
@@ -215,7 +215,7 @@ static void finalize_function (gravity_function_t *f) {
 
 inline static bool pop1_instruction (ircode_t *code, uint32_t index, inst_t **inst1) {
 	*inst1 = NULL;
-	
+
 	for (int32_t i=index-1; i>=0; --i) {
 		inst_t *inst = ircode_get(code, i);
 		if ((inst != NULL) && (inst->tag != SKIP_TAG)) {
@@ -223,14 +223,14 @@ inline static bool pop1_instruction (ircode_t *code, uint32_t index, inst_t **in
 			return true;
 		}
 	}
-	
+
 	return false;
 }
 
 inline static bool pop2_instructions (ircode_t *code, uint32_t index, inst_t **inst1, inst_t **inst2) {
 	*inst1 = NULL;
 	*inst2 = NULL;
-	
+
 	for (int32_t i=index-1; i>=0; --i) {
 		inst_t *inst = ircode_get(code, i);
 		if ((inst != NULL) && (inst->tag != SKIP_TAG)) {
@@ -241,7 +241,7 @@ inline static bool pop2_instructions (ircode_t *code, uint32_t index, inst_t **i
 			}
 		}
 	}
-	
+
 	return false;
 }
 
@@ -252,7 +252,7 @@ inline static inst_t *current_instruction (ircode_t *code, uint32_t i) {
 		if (inst->tag != SKIP_TAG) return inst;
 		++i;
 	}
-	
+
 	return NULL;
 }
 
@@ -266,11 +266,11 @@ static bool optimize_const_instruction (inst_t *inst, inst_t *inst1, inst_t *ins
 	optag_t	type;
 	double	d = 0.0, d1 = 0.0, d2 = 0.0;
 	int64_t	n = 0, n1 = 0, n2 = 0;
-	
+
 	// compute types
 	if (inst1->tag == inst2->tag) type = inst1->tag;
 	else type = DOUBLE_TAG;
-	
+
 	// compute operands
 	if (type == DOUBLE_TAG) {
 		d1 = (inst1->tag == INT_TAG) ? (double)inst1->n : inst1->d;
@@ -279,45 +279,45 @@ static bool optimize_const_instruction (inst_t *inst, inst_t *inst1, inst_t *ins
 		n1 = (inst1->tag == INT_TAG) ? inst1->n : (int64_t)inst1->d;
 		n2 = (inst2->tag == INT_TAG) ? inst2->n : (int64_t)inst2->d;
 	}
-	
+
 	// perform operation
 	switch (inst->op) {
 		case ADD:
 			if (type == DOUBLE_TAG) d = d1 + d2;
 			else n = n1 + n2;
 			break;
-			
+
 		case SUB:
 			if (type == DOUBLE_TAG) d = d1 - d2;
 			else n = n1 - n2;
 			break;
-			
+
 		case MUL:
 			if (type == DOUBLE_TAG) d = d1 * d2;
 			else n = n1 * n2;
 			break;
-			
+
 		case DIV:
 			// don't optimize in case of division by 0
 			if ((int64_t)d2 == 0) return false;
 			if (type == DOUBLE_TAG) d = d1 / d2;
 			else n = n1 / n2;
 			break;
-			
+
 		case REM:
 			if ((int64_t)d2 == 0) return false;
 			if (type == DOUBLE_TAG) d = (double)((int64_t)d1 % (int64_t)d2);
 			else n = n1 % n2;
 			break;
-			
+
 		default:
 			assert(0);
 	}
-	
+
 	// adjust IRCODE
 	inst_setskip(inst1);
 	inst_setskip(inst2);
-	
+
 	// convert an ADD instruction to a LOADI instruction
 	// ADD A B C	=> R(A) = R(B) + R(C)
 	// LOADI A B	=> R(A) = N
@@ -326,7 +326,7 @@ static bool optimize_const_instruction (inst_t *inst, inst_t *inst1, inst_t *ins
 	inst->p2 = inst->p3 = 0;
 	if (type == DOUBLE_TAG) inst->d = d;
 	else inst->n = n;
-	
+
 	return true;
 }
 
@@ -337,7 +337,7 @@ static bool optimize_neg_instruction (ircode_t *code, inst_t *inst, uint32_t i)
 	if (inst1->op != LOADI) return false;
 	if (inst1->p1 != inst->p2) return false;
 	if (!ircode_register_istemp(code, inst1->p1)) return false;
-	
+
 	uint64_t n = inst1->n;
 	if (n>131072) return false;
 	inst1->p1 = inst->p2;
@@ -350,11 +350,11 @@ static bool optimize_math_instruction (ircode_t *code, inst_t *inst, uint32_t i)
 	uint8_t count = opcode_numop(inst->op) - 1;
 	inst_t *inst1 = NULL, *inst2 = NULL;
 	bool	flag = false;
-	
+
 	if (count == 2) {
 		pop2_instructions(code, i, &inst2, &inst1);
 		if (IS_NUM(inst1) && IS_NUM(inst2)) flag = optimize_const_instruction(inst, inst1, inst2);
-		
+
 		// process inst2
 		if (IS_MOVE(inst2)) {
 			bool b1 = ircode_register_istemp(code, inst->p3);
@@ -365,7 +365,7 @@ static bool optimize_math_instruction (ircode_t *code, inst_t *inst, uint32_t i)
 				flag = true;
 			}
 		}
-		
+
 		// process inst1
 		if (IS_MOVE(inst1)) {
 			bool b1 = ircode_register_istemp(code, inst->p2);
@@ -376,7 +376,7 @@ static bool optimize_math_instruction (ircode_t *code, inst_t *inst, uint32_t i)
 				flag = true;
 			}
 		}
-		
+
 	}
 	else {
 		pop1_instruction(code, i, &inst1);
@@ -391,38 +391,38 @@ static bool optimize_move_instruction (ircode_t *code, inst_t *inst, uint32_t i)
 	pop1_instruction(code, i, &inst1);
 	if (inst1 == NULL) return false;
 	if ((inst1->op != LOADI) && (inst1->op != LOADG) && (inst1->op != LOADK)) return false;
-	
+
 	bool b1 = ircode_register_istemp(code, inst->p2);
 	bool b2 = ((inst1) && ircode_register_istemp(code, inst1->p1));
-	
+
 	if ((b1) && (b2) && (inst->p2 == inst1->p1)) {
 		inst1->p1 = inst->p1;
 		inst_setskip(inst);
 		return true;
 	}
-	
+
 	return false;
 }
 
 static bool optimize_return_instruction (ircode_t *code, inst_t *inst, uint32_t i) {
 	inst_t *inst1 = NULL;
 	pop1_instruction(code, i, &inst1);
-	
+
 	if (!ircode_register_istemp(code, inst->p1)) return false;
 	if ((IS_MOVE(inst1)) && (inst->p1 == inst1->p1)) {
 		inst->p1 = inst1->p2;
 		inst_setskip(inst1);
 		return true;
 	}
-	
+
 	return false;
 }
 
 static bool optimize_num_instruction (inst_t *inst, gravity_function_t *f) {
-	
+
 	// double values always added to constant pool
 	bool add_cpool = (inst->tag == DOUBLE_TAG);
-	
+
 	// LOADI is a 32bit instruction
 	// 32 - 6 (OPCODE) - 8 (register) - 1 bit sign = 17
 	// range is from MAX_INLINE_INT-1 to MAX_INLINE_INT
@@ -432,7 +432,7 @@ static bool optimize_num_instruction (inst_t *inst, gravity_function_t *f) {
 		int64_t n = inst->n;
 		add_cpool = ((n < -MAX_INLINE_INT + 1) || (n > MAX_INLINE_INT));
 	}
-	
+
 	if (add_cpool) {
 		uint16_t index = 0;
 		if (inst->tag == INT_TAG) {
@@ -442,13 +442,13 @@ static bool optimize_num_instruction (inst_t *inst, gravity_function_t *f) {
 			// always add floating point values as double in constant pool (then VM will be configured to interpret it as float or double)
 			index = gravity_function_cpool_add(NULL, f, VALUE_FROM_FLOAT(inst->d));
 		}
-		
+
 		// replace LOADI with a LOADK instruction
 		inst->op = LOADK;
 		inst->p2 = index;
 		inst->tag = NO_TAG;
 	}
-	
+
 	return true;
 }
 
@@ -456,13 +456,13 @@ static bool optimize_num_instruction (inst_t *inst, gravity_function_t *f) {
 
 gravity_function_t *gravity_optimizer(gravity_function_t *f) {
 	if (f->bytecode == NULL) return f;
-	
+
 	ircode_t	*code = (ircode_t *)f->bytecode;
 	uint32_t	count = ircode_count(code);
 	bool		optimizer = true;
-	
+
 	f->ntemps = ircode_ntemps(code);
-	
+
 	loop_neg:
 	for (uint32_t i=0; i<count; ++i) {
 		inst_t *inst = current_instruction(code, i);
@@ -471,7 +471,7 @@ gravity_function_t *gravity_optimizer(gravity_function_t *f) {
 			if (b) goto loop_neg;
 		}
 	}
-	
+
 	loop_math:
 	for (uint32_t i=0; i<count; ++i) {
 		inst_t *inst = current_instruction(code, i);
@@ -480,7 +480,7 @@ gravity_function_t *gravity_optimizer(gravity_function_t *f) {
 			if (b) goto loop_math;
 		}
 	}
-	
+
 	loop_move:
 	optimizer = true;
 	for (uint32_t i=0; i<count; ++i) {
@@ -491,7 +491,7 @@ gravity_function_t *gravity_optimizer(gravity_function_t *f) {
 			if (b) goto loop_move;
 		}
 	}
-	
+
 	loop_ret:
 	for (uint32_t i=0; i<count; ++i) {
 		inst_t *inst = current_instruction(code, i);
@@ -500,19 +500,19 @@ gravity_function_t *gravity_optimizer(gravity_function_t *f) {
 			if (b) goto loop_ret;
 		}
 	}
-	
+
 	for (uint32_t i=0; i<count; ++i) {
 		inst_t *inst = current_instruction(code, i);
 		if (IS_NUM(inst)) optimize_num_instruction (inst, f);
 	}
-	
+
 	// dump optimized version
 	#if GRAVITY_BYTECODE_DEBUG
 	gravity_function_dump(f, ircode_dump);
 	#endif
-	
+
 	// finalize function
 	finalize_function(f);
-	
+
 	return f;
 }

File diff suppressed because it is too large
+ 160 - 160
src/compiler/gravity_parser.c


+ 4 - 4
src/compiler/gravity_parser.h

@@ -16,16 +16,16 @@
 /*
 	Parser is responsible to build the AST, convert strings and number from tokens and
 	implement syntax error recovery strategy.
-	
+
 	Notes about error recovery:
 	Each parse* function can return NULL in case of error but each function is RESPONSIBLE
-	to make appropriate actions in order to handle/recover errors. 
-	
+	to make appropriate actions in order to handle/recover errors.
+
 	Error recovery techniques can be:
 	Shallow Error Recovery
 	Deep Error Recovery
 	https://javacc.java.net/doc/errorrecovery.html
- 
+
  */
 
 // opaque datatype

+ 24 - 24
src/compiler/gravity_semacheck1.c

@@ -32,11 +32,11 @@ static int ident =0;
 static void report_error (gvisitor_t *self, gnode_t *node, const char *format, ...) {
 	// increment internal error counter
 	++self->nerr;
-	
+
 	// get error callback (if any)
 	void *data = (self->delegate) ? ((gravity_delegate_t *)self->delegate)->xdata : NULL;
 	gravity_error_callback error_fn = (self->delegate) ? ((gravity_delegate_t *)self->delegate)->error_callback : NULL;
-	
+
 	// build error message
 	char		buffer[1024];
 	va_list		arg;
@@ -45,7 +45,7 @@ static void report_error (gvisitor_t *self, gnode_t *node, const char *format, .
 		vsnprintf(buffer, sizeof(buffer), format, arg);
 		va_end (arg);
 	}
-	
+
 	// setup error struct
 	error_desc_t error_desc = {
 		.lineno = node->token.lineno,
@@ -54,7 +54,7 @@ static void report_error (gvisitor_t *self, gnode_t *node, const char *format, .
 		.offset = node->token.position,
         .meta = meta_from_node(node)
 	};
-	
+
 	// finally call error callback
 	if (error_fn) error_fn(GRAVITY_ERROR_SEMANTIC, buffer, error_desc, data);
 	else printf("%s\n", buffer);
@@ -64,27 +64,27 @@ static void report_error (gvisitor_t *self, gnode_t *node, const char *format, .
 
 static void visit_list_stmt (gvisitor_t *self, gnode_compound_stmt_t *node) {
 	DECLARE_SYMTABLE;
-	
+
 	node->symtable = symtable;	// GLOBALS
 	gnode_array_each(node->stmts, {visit(val);});
 }
 
 static void visit_function_decl (gvisitor_t *self, gnode_function_decl_t *node) {
 	DECLARE_SYMTABLE;
-	
+
 	DEBUG_SYMTABLE("function: %s", node->identifier);
-	
+
 	// function identifier
 	if (!symboltable_insert(symtable, node->identifier, (void *)node))
 		REPORT_ERROR(node, "Identifier %s redeclared.", node->identifier);
-	
+
 	// we are just interested in non-local declarations so don't further scan function node
 	// node->symtable is NULL here and it will be created in semacheck2
 }
 
 static void visit_variable_decl (gvisitor_t *self, gnode_variable_decl_t *node) {
 	DECLARE_SYMTABLE;
-	
+
 	gnode_array_each(node->decls, {
 		gnode_var_t *p = (gnode_var_t *)val;
 		DEBUG_SYMTABLE("variable: %s", p->identifier);
@@ -95,9 +95,9 @@ static void visit_variable_decl (gvisitor_t *self, gnode_variable_decl_t *node)
 
 static void visit_enum_decl (gvisitor_t *self, gnode_enum_decl_t *node) {
 	DECLARE_SYMTABLE;
-	
+
 	DEBUG_SYMTABLE("enum: %s", node->identifier);
-	
+
 	// check enum identifier uniqueness in current symbol table
 	if (!symboltable_insert(symtable, node->identifier, (void *)node))
 		REPORT_ERROR(node, "Identifier %s redeclared.", node->identifier);
@@ -105,13 +105,13 @@ static void visit_enum_decl (gvisitor_t *self, gnode_enum_decl_t *node) {
 
 static void visit_class_decl (gvisitor_t *self, gnode_class_decl_t *node) {
 	DECLARE_SYMTABLE;
-	
+
 	DEBUG_SYMTABLE("class: %s", node->identifier);
-	
+
 	// class identifier
 	if (!symboltable_insert(symtable, node->identifier, (void *)node))
 		REPORT_ERROR(node, "Identifier %s redeclared.", node->identifier);
-	
+
 	CREATE_SYMTABLE;
 	gnode_array_each(node->decls, {
 		visit(val);
@@ -121,13 +121,13 @@ static void visit_class_decl (gvisitor_t *self, gnode_class_decl_t *node) {
 
 static void visit_module_decl (gvisitor_t *self, gnode_module_decl_t *node) {
 	DECLARE_SYMTABLE;
-	
+
 	DEBUG_SYMTABLE("module: %s", node->identifier);
-	
+
 	// module identifier
 	if (!symboltable_insert(symtable, node->identifier, (void *)node))
 		REPORT_ERROR(node, "Identifier %s redeclared.", node->identifier);
-	
+
 	CREATE_SYMTABLE;
 	gnode_array_each(node->decls, {
 		visit(val);
@@ -139,16 +139,16 @@ static void visit_module_decl (gvisitor_t *self, gnode_module_decl_t *node) {
 
 bool gravity_semacheck1 (gnode_t *node, gravity_delegate_t *delegate) {
 	symboltable_t *context = symboltable_create(false);
-	
+
 	gvisitor_t visitor = {
 		.nerr = 0,							// used to store number of found errors
 		.data = (void *)context,			// used to store a pointer to the symbol table
 		.delegate = (void *)delegate,		// compiler delegate to report errors
-		
+
         // COMMON
         .visit_pre = NULL,
         .visit_post = NULL,
-        
+
 		// STATEMENTS: 7
 		.visit_list_stmt = visit_list_stmt,
 		.visit_compound_stmt = NULL,
@@ -157,14 +157,14 @@ bool gravity_semacheck1 (gnode_t *node, gravity_delegate_t *delegate) {
 		.visit_loop_stmt = NULL,
 		.visit_jump_stmt = NULL,
 		.visit_empty_stmt = NULL,
-		
+
 		// DECLARATIONS: 5
 		.visit_function_decl = visit_function_decl,
 		.visit_variable_decl = visit_variable_decl,
 		.visit_enum_decl = visit_enum_decl,
 		.visit_class_decl = visit_class_decl,
 		.visit_module_decl = visit_module_decl,
-		
+
 		// EXPRESSIONS: 8
 		.visit_binary_expr = NULL,
 		.visit_unary_expr = NULL,
@@ -175,10 +175,10 @@ bool gravity_semacheck1 (gnode_t *node, gravity_delegate_t *delegate) {
 		.visit_list_expr = NULL,
 		.visit_postfix_expr = NULL,
 	};
-	
+
 	DEBUG_SYMTABLE("=== SYMBOL TABLE ===");
 	gvisit(&visitor, node);
 	DEBUG_SYMTABLE("====================\n");
-	
+
 	return (visitor.nerr == 0);
 }

+ 8 - 8
src/compiler/gravity_semacheck1.h

@@ -23,30 +23,30 @@
 		function foo() {
 			return bar();
 		}
-	
+
 		function bar() {
 			...
 		}
- 
+
 		or
- 
+
 		class foo:bar {
 			...
 		}
- 
+
 		class bar {
 			...
 		}
- 
+
 		and
- 
+
 		class foo {
 			var a;
- 
+
 			function bar() {
 				return a + b;
 			}
- 
+
 			var b;
 		}
  */

File diff suppressed because it is too large
+ 158 - 158
src/compiler/gravity_semacheck2.c


+ 9 - 9
src/compiler/gravity_semacheck2.h

@@ -13,14 +13,14 @@
 #include "gravity_delegate.h"
 
 // Responsible to gather and check local identifiers
-// Complete check for all identifiers and report not found errors 
+// Complete check for all identifiers and report not found errors
 
 bool gravity_semacheck2(gnode_t *node, gravity_delegate_t *delegate);
 
 /*
- 
+
 	The following table summarizes what can be defined inside a declaration:
- 
+
     -------+---------------------------------------------------------+
 	       |   func   |   var   |   enum   |   class   |   module    |
 	-------+---------------------------------------------------------+
@@ -34,29 +34,29 @@ bool gravity_semacheck2(gnode_t *node, gravity_delegate_t *delegate);
     -------+---------------------------------------------------------+
 	module |   NO     |   NO    |   NO     |   NO      |   NO        |
     -------+---------------------------------------------------------+
- 
+
 	Everything declared inside a func is a local, so for example:
- 
+
 	func foo {
 		func a...;
 		enum b...;
 		class c..;
 	}
- 
+
 	is converted by codegen to:
-	
+
 	func foo {
 		var a = func...;
 		var b = enum...;
 		var c = class..;
 	}
- 
+
 	Even if the ONLY valid syntax is anonymous func assignment, user will not be able
 	to assign an anonymous enum or class to a variable. Restriction is applied by parser
 	and reported as a syntax error.
 	Define a module inside a function is not allowed (no real technical reason but I found
 	it a very bad programming practice), restriction is applied by samantic checker.
- 
+
  */
 
 

+ 14 - 14
src/compiler/gravity_symboltable.c

@@ -35,7 +35,7 @@ struct symboltable_t {
 
 static void check_upvalue_inscope (gravity_hash_t *hashtable, gravity_value_t key, gravity_value_t value, void *data) {
 	#pragma unused(hashtable, key)
-	
+
 	uint32_t index = *(uint32_t *)data;
 	gnode_t *node = VALUE_AS_NODE(value);
 	if (NODE_ISA(node, NODE_VARIABLE)) {
@@ -45,7 +45,7 @@ static void check_upvalue_inscope (gravity_hash_t *hashtable, gravity_value_t ke
 		}
 	}
 }
-	
+
 // MARK: -
 
 static void symboltable_hash_free (gravity_hash_t *hashtable, gravity_value_t key, gravity_value_t value, void *data) {
@@ -67,38 +67,38 @@ symboltable_t *symboltable_create (bool is_enum) {
 	gravity_hash_t	*hash = gravity_hash_create(0, gravity_value_hash, gravity_value_equals,
 												(is_enum) ? symboltable_keyvalue_free : symboltable_hash_free, NULL);
 	if (!table) return NULL;
-	
+
 	// init symbol table
 	table->counter = 0;
 	table->stack = mem_alloc(sizeof(ghash_r));
 	scope_stack_init(table->stack);
 	scope_stack_push(table->stack, hash);
-	
+
 	return table;
 }
 
 void symboltable_free (symboltable_t *table) {
 	size_t i, n = scope_stack_size(table->stack);
-	
+
 	for (i=0; i<n; ++i) {
 		gravity_hash_t *h = scope_stack_get(table->stack, i);
 		gravity_hash_free(h);
 	}
-	
+
 	if (table->stack) {
 		scope_stack_free(table->stack);
 		mem_free(table->stack);
 	}
-	
+
 	mem_free(table);
 }
 
 bool symboltable_insert (symboltable_t *table, const char *identifier, gnode_t *node) {
     if (!identifier) return false;
-    
+
 	size_t			n = scope_stack_size(table->stack);
 	gravity_hash_t	*h = scope_stack_get(table->stack, n-1);
-	
+
 	// insert node with key identifier into hash table (and check if already exists in current scope)
 	gravity_value_t key = VALUE_FROM_CSTRING(NULL, identifier);
 	if (gravity_hash_lookup(h, key) != NULL) {
@@ -106,21 +106,21 @@ bool symboltable_insert (symboltable_t *table, const char *identifier, gnode_t *
 		return false;
 	}
 	gravity_hash_insert(h, key, VALUE_FROM_NODE(node));
-						
+
 	++table->counter;
 	return true;
 }
 
 gnode_t *symboltable_lookup (symboltable_t *table, const char *identifier) {
 	STATICVALUE_FROM_STRING(key, identifier, strlen(identifier));
-	
+
 	size_t n = scope_stack_size(table->stack);
 	for (int i=(int)n-1; i>=0; --i) {
 		gravity_hash_t *h = scope_stack_get(table->stack, i);
 		gravity_value_t *v = gravity_hash_lookup(h, key);
 		if (v) return VALUE_AS_NODE(*v);
 	}
-	
+
 	return NULL;
 }
 
@@ -134,7 +134,7 @@ uint32_t symboltable_count (symboltable_t *table, uint32_t index) {
 gnode_t *symboltable_global_lookup (symboltable_t *table, const char *identifier) {
 	gravity_hash_t *h = scope_stack_get(table->stack, 0);
 	STATICVALUE_FROM_STRING(key, identifier, strlen(identifier));
-	
+
 	gravity_value_t *v = gravity_hash_lookup(h, key);
 	return (v) ? VALUE_AS_NODE(*v) : NULL;
 }
@@ -160,7 +160,7 @@ uint32_t symboltable_exit_scope (symboltable_t *table, uint32_t *nlevel) {
 
 void symboltable_dump (symboltable_t *table) {
 	size_t n = scope_stack_size(table->stack);
-	
+
 	for (int i=(int)n-1; i>=0; --i) {
 		gravity_hash_t *h = (gravity_hash_t *)scope_stack_get(table->stack, i);
 		gravity_hash_dump(h);

+ 23 - 23
src/compiler/gravity_token.c

@@ -24,7 +24,7 @@ const char *token_name (gtoken_t token) {
 		case TOK_IDENTIFIER: return "IDENTIFIER";
 		case TOK_SPECIAL: return "SPECIAL";
 		case TOK_MACRO: return "MACRO";
-		
+
 		// keywords
 		case TOK_KEY_FILE: return "file";
 		case TOK_KEY_FUNC: return "func";
@@ -62,7 +62,7 @@ const char *token_name (gtoken_t token) {
 		case TOK_KEY_ISA: return "is";
 		case TOK_KEY_CURRARGS: return "_args";
 		case TOK_KEY_CURRFUNC: return "_func";
-		
+
 		// operators
 		case TOK_OP_ADD: return "+";
 		case TOK_OP_SUB: return "-";
@@ -101,7 +101,7 @@ const char *token_name (gtoken_t token) {
 		case TOK_OP_BIT_AND_ASSIGN: return "&=";
 		case TOK_OP_BIT_OR_ASSIGN: return "|=";
 		case TOK_OP_BIT_XOR_ASSIGN: return "^=";
-		
+
 		case TOK_OP_OPEN_PARENTHESIS: return "(";
 		case TOK_OP_CLOSED_PARENTHESIS: return ")";
 		case TOK_OP_OPEN_SQUAREBRACKET: return "[";
@@ -112,10 +112,10 @@ const char *token_name (gtoken_t token) {
 		case TOK_OP_COLON: return ":";
 		case TOK_OP_COMMA: return ",";
 		case TOK_OP_DOT: return ".";
-		
+
 		case TOK_END: return "";
 	}
-	
+
 	// should never reach this point
 	return "UNRECOGNIZED TOKEN";
 }
@@ -128,7 +128,7 @@ void token_keywords_indexes (uint32_t *idx_start, uint32_t *idx_end) {
 gtoken_t token_special_builtin(gtoken_s *token) {
     const char *buffer = token->value;
     int32_t len = token->bytes;
-    
+
     switch (len) {
         case 8:
             if (string_casencmp(buffer, "__LINE__", len) == 0) {
@@ -140,21 +140,21 @@ gtoken_t token_special_builtin(gtoken_s *token) {
                 return TOK_STRING;
             }
             break;
-        
+
         case 9:
             if (string_casencmp(buffer, "__CLASS__", len) == 0) {
                 token->builtin = BUILTIN_CLASS;
                 return TOK_STRING;
             }
             break;
-            
+
         case 10:
             if (string_casencmp(buffer, "__COLUMN__", len) == 0) {
                 token->builtin = BUILTIN_COLUMN;
                 return TOK_NUMBER;
             }
             break;
-            
+
         case 12:
             if (string_casencmp(buffer, "__FUNCTION__", len) == 0) {
                 token->builtin = BUILTIN_FUNC;
@@ -162,7 +162,7 @@ gtoken_t token_special_builtin(gtoken_s *token) {
             }
             break;
     }
-    
+
     return TOK_IDENTIFIER;
 }
 
@@ -174,14 +174,14 @@ gtoken_t token_keyword (const char *buffer, int32_t len) {
 			if (string_casencmp(buffer, "or", len) == 0) return TOK_OP_OR;
 			if (string_casencmp(buffer, "is", len) == 0) return TOK_KEY_ISA;
 			break;
-			
+
 		case 3:
 			if (string_casencmp(buffer, "for", len) == 0) return TOK_KEY_FOR;
 			if (string_casencmp(buffer, "var", len) == 0) return TOK_KEY_VAR;
 			if (string_casencmp(buffer, "and", len) == 0) return TOK_OP_AND;
 			if (string_casencmp(buffer, "not", len) == 0) return TOK_OP_NOT;
 			break;
-			
+
 		case 4:
 			if (string_casencmp(buffer, "func", len) == 0) return TOK_KEY_FUNC;
 			if (string_casencmp(buffer, "else", len) == 0) return TOK_KEY_ELSE;
@@ -192,7 +192,7 @@ gtoken_t token_keyword (const char *buffer, int32_t len) {
 			if (string_casencmp(buffer, "file", len) == 0) return TOK_KEY_FILE;
 			if (string_casencmp(buffer, "lazy", len) == 0) return TOK_KEY_LAZY;
 			break;
-			
+
 		case 5:
 			if (string_casencmp(buffer, "super", len) == 0) return TOK_KEY_SUPER;
 			if (string_casencmp(buffer, "false", len) == 0) return TOK_KEY_FALSE;
@@ -204,7 +204,7 @@ gtoken_t token_keyword (const char *buffer, int32_t len) {
 			if (string_casencmp(buffer, "_func", len) == 0) return TOK_KEY_CURRFUNC;
 			if (string_casencmp(buffer, "_args", len) == 0) return TOK_KEY_CURRARGS;
 			break;
-			
+
 		case 6:
 			if (string_casencmp(buffer, "struct", len) == 0) return TOK_KEY_STRUCT;
 			if (string_casencmp(buffer, "repeat", len) == 0) return TOK_KEY_REPEAT;
@@ -216,22 +216,22 @@ gtoken_t token_keyword (const char *buffer, int32_t len) {
 			if (string_casencmp(buffer, "import", len) == 0) return TOK_KEY_IMPORT;
 			if (string_casencmp(buffer, "module", len) == 0) return TOK_KEY_MODULE;
 			break;
-			
+
 		case 7:
 			if (string_casencmp(buffer, "default", len) == 0) return TOK_KEY_DEFAULT;
 			if (string_casencmp(buffer, "private", len) == 0) return TOK_KEY_PRIVATE;
 			break;
-			
+
 		case 8:
 			if (string_casencmp(buffer, "continue", len) == 0) return TOK_KEY_CONTINUE;
 			if (string_casencmp(buffer, "internal", len) == 0) return TOK_KEY_INTERNAL;
 			break;
-			
+
 		case 9:
 			if (string_casencmp(buffer, "undefined", len) == 0) return TOK_KEY_UNDEFINED;
 			break;
 	}
-	
+
 	return TOK_IDENTIFIER;
 }
 
@@ -256,7 +256,7 @@ bool token_isvariable_declaration (gtoken_t token) {
 
 bool token_isstatement (gtoken_t token) {
 	if (token == TOK_EOF) return false;
-	
+
 	// label_statement (case, default)
 	// expression_statement ('+' | '-' | '!' | 'not' | new | raise | file | isPrimaryExpression)
 	// flow_statement (if, select)
@@ -266,7 +266,7 @@ bool token_isstatement (gtoken_t token) {
 	// declaration_statement (isDeclarationStatement)
 	// empty_statement (;)
 	// import_statement (import)
-	
+
 	return (token_islabel_statement(token) || token_isexpression_statement(token) || token_isflow_statement(token) ||
 			token_isloop_statement(token) || token_isjump_statement(token) || token_iscompound_statement(token) ||
 			token_isdeclaration_statement(token) || token_isempty_statement(token) || token_isimport_statement(token) ||
@@ -305,7 +305,7 @@ bool token_isprimary_expression (gtoken_t token) {
 	// function_expression
 	// list_expression
 	// map_expression
-	
+
 	return ((token == TOK_NUMBER) || (token == TOK_STRING) || (token == TOK_KEY_TRUE) ||
 			(token == TOK_KEY_FALSE) || (token == TOK_IDENTIFIER) || (token == TOK_KEY_NULL) ||
 			(token == TOK_KEY_SUPER) || (token == TOK_KEY_FUNC) || (token == TOK_KEY_UNDEFINED) ||
@@ -319,7 +319,7 @@ bool token_isexpression_statement (gtoken_t token) {
 	// postfix_expression: primary_expression | 'module' (was file)
 	// unary_operator: '+' | '-' | '!' | 'not'
 	// raise_expression: 'raise'
-	
+
 	return (token_isprimary_expression(token) || (token == TOK_OP_ADD) || (token == TOK_OP_SUB) ||
 			(token == TOK_OP_NOT) || (token == TOK_KEY_CURRARGS) || (token == TOK_KEY_CURRFUNC));
 }
@@ -352,7 +352,7 @@ bool token_isdeclaration_statement (gtoken_t token) {
 	// module_declaration (MODULE)
 	// event_declaration_statement (EVENT)
 	// empty_declaration (;)
-	
+
 	return ((token_isaccess_specifier(token) || token_isstorage_specifier(token) || token_isvariable_declaration(token) ||
 			(token == TOK_KEY_FUNC)	|| (token == TOK_KEY_CLASS) || (token == TOK_KEY_STRUCT) || (token == TOK_KEY_ENUM) ||
 			(token == TOK_KEY_MODULE) || (token == TOK_KEY_EVENT)  || (token == TOK_OP_SEMICOLON)));

+ 4 - 4
src/compiler/gravity_token.h

@@ -63,7 +63,7 @@
 typedef enum {
 	// General (8)
 	TOK_EOF	= 0, TOK_ERROR, TOK_COMMENT, TOK_STRING, TOK_NUMBER, TOK_IDENTIFIER, TOK_SPECIAL, TOK_MACRO,
-	
+
 	// Keywords (36)
 	// remember to keep in sync functions token_keywords_indexes and token_name
 	TOK_KEY_FUNC, TOK_KEY_SUPER, TOK_KEY_DEFAULT, TOK_KEY_TRUE, TOK_KEY_FALSE, TOK_KEY_IF,
@@ -72,7 +72,7 @@ typedef enum {
 	TOK_KEY_FILE, TOK_KEY_INTERNAL, TOK_KEY_PUBLIC, TOK_KEY_STATIC, TOK_KEY_EXTERN, TOK_KEY_LAZY, TOK_KEY_CONST,
 	TOK_KEY_VAR, TOK_KEY_MODULE, TOK_KEY_IMPORT, TOK_KEY_CASE, TOK_KEY_EVENT, TOK_KEY_NULL, TOK_KEY_UNDEFINED,
 	TOK_KEY_ISA, TOK_KEY_CURRFUNC, TOK_KEY_CURRARGS,
-	
+
 	// Operators (36)
 	TOK_OP_SHIFT_LEFT, TOK_OP_SHIFT_RIGHT, TOK_OP_MUL, TOK_OP_DIV, TOK_OP_REM, TOK_OP_BIT_AND, TOK_OP_ADD, TOK_OP_SUB,
 	TOK_OP_BIT_OR, TOK_OP_BIT_XOR, TOK_OP_BIT_NOT, TOK_OP_RANGE_EXCLUDED, TOK_OP_RANGE_INCLUDED, TOK_OP_LESS, TOK_OP_LESS_EQUAL,
@@ -80,11 +80,11 @@ typedef enum {
 	TOK_OP_PATTERN_MATCH, TOK_OP_AND, TOK_OP_OR, TOK_OP_TERNARY, TOK_OP_ASSIGN, TOK_OP_MUL_ASSIGN, TOK_OP_DIV_ASSIGN,
 	TOK_OP_REM_ASSIGN, TOK_OP_ADD_ASSIGN, TOK_OP_SUB_ASSIGN, TOK_OP_SHIFT_LEFT_ASSIGN, TOK_OP_SHIFT_RIGHT_ASSIGN,
 	TOK_OP_BIT_AND_ASSIGN, TOK_OP_BIT_OR_ASSIGN, TOK_OP_BIT_XOR_ASSIGN, TOK_OP_NOT,
-	
+
 	// Punctuators (10)
 	TOK_OP_SEMICOLON, TOK_OP_OPEN_PARENTHESIS, TOK_OP_COLON, TOK_OP_COMMA, TOK_OP_DOT, TOK_OP_CLOSED_PARENTHESIS,
 	TOK_OP_OPEN_SQUAREBRACKET, TOK_OP_CLOSED_SQUAREBRACKET, TOK_OP_OPEN_CURLYBRACE, TOK_OP_CLOSED_CURLYBRACE,
-	
+
 	// Mark end of tokens (1)
 	TOK_END
 } gtoken_t;

+ 7 - 7
src/compiler/gravity_visitor.c

@@ -23,12 +23,12 @@ void gvisit(gvisitor_t *self, gnode_t *node) {
 	// this line added after implemented getter and setter,
 	// because they are functions inside a COMPOUND_STATEMENT and can be NULL
 	if (!node) return;
-	
+
     // pre-visit
     if (self->visit_pre) self->visit_pre(self, node);
-    
+
 	switch (node->tag) {
-		
+
 		// statements (7)
 		case NODE_LIST_STAT: VISIT(list_stmt);
 		case NODE_COMPOUND_STAT: VISIT(compound_stmt);
@@ -37,7 +37,7 @@ void gvisit(gvisitor_t *self, gnode_t *node) {
 		case NODE_JUMP_STAT: VISIT(jump_stmt);
 		case NODE_LOOP_STAT: VISIT(loop_stmt);
 		case NODE_EMPTY_STAT: VISIT(empty_stmt);
-		
+
 		// declarations (5)
 		case NODE_ENUM_DECL: VISIT(enum_decl);
 		case NODE_FUNCTION_DECL: VISIT(function_decl);
@@ -45,7 +45,7 @@ void gvisit(gvisitor_t *self, gnode_t *node) {
 		case NODE_CLASS_DECL: VISIT(class_decl);
 		case NODE_MODULE_DECL: VISIT(module_decl);
 		// NODE_VARIABLE is handled by NODE_VARIABLE_DECL
-			
+
 		// expressions (8)
 		case NODE_BINARY_EXPR: VISIT(binary_expr);
 		case NODE_UNARY_EXPR: VISIT(unary_expr);
@@ -55,11 +55,11 @@ void gvisit(gvisitor_t *self, gnode_t *node) {
 		case NODE_IDENTIFIER_EXPR: VISIT(identifier_expr);
 		case NODE_KEYWORD_EXPR: VISIT(keyword_expr);
 		case NODE_POSTFIX_EXPR: VISIT(postfix_expr);
-			
+
 		// default assert
 		default: default_action(node);
 	}
-    
+
     // post-visit
     if (self->visit_post) self->visit_post(self, node);
 }

+ 5 - 5
src/compiler/gravity_visitor.h

@@ -17,13 +17,13 @@ typedef struct gvisitor {
 	uint32_t	nerr;			// to store err counter state
 	void		*data;			// to store a ptr state
 	void		*delegate;		// delegate callback
-	
+
     // COMMON
     void (* visit_pre)(struct gvisitor *self, gnode_t *node);
     void (* visit_post)(struct gvisitor *self, gnode_t *node);
-    
+
 	// count must be equal to enum gnode_n defined in gravity_ast.h less 3
-	
+
 	// STATEMENTS: 7
 	void (* visit_list_stmt)(struct gvisitor *self, gnode_compound_stmt_t *node);
 	void (* visit_compound_stmt)(struct gvisitor *self, gnode_compound_stmt_t *node);
@@ -32,14 +32,14 @@ typedef struct gvisitor {
 	void (* visit_jump_stmt)(struct gvisitor *self, gnode_jump_stmt_t *node);
 	void (* visit_loop_stmt)(struct gvisitor *self, gnode_loop_stmt_t *node);
 	void (* visit_empty_stmt)(struct gvisitor *self, gnode_empty_stmt_t *node);
-	
+
 	// DECLARATIONS: 5+1 (NODE_VARIABLE handled by NODE_VARIABLE_DECL case)
 	void (* visit_function_decl)(struct gvisitor *self, gnode_function_decl_t *node);
 	void (* visit_variable_decl)(struct gvisitor *self, gnode_variable_decl_t *node);
 	void (* visit_enum_decl)(struct gvisitor *self, gnode_enum_decl_t *node);
 	void (* visit_class_decl)(struct gvisitor *self, gnode_class_decl_t *node);
 	void (* visit_module_decl)(struct gvisitor *self, gnode_module_decl_t *node);
-	
+
 	// EXPRESSIONS: 7+3 (CALL EXPRESSIONS handled by one callback)
 	void (* visit_binary_expr)(struct gvisitor *self, gnode_binary_expr_t *node);
 	void (* visit_unary_expr)(struct gvisitor *self, gnode_unary_expr_t *node);

+ 79 - 79
src/optionals/gravity_math.c

@@ -62,11 +62,11 @@ static uint32_t                     refcount = 0;
 static bool math_abs (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_int_t computed_value;
         #ifdef GRAVITY_ENABLE_INT64
@@ -76,7 +76,7 @@ static bool math_abs (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
         #endif
         RETURN_VALUE(VALUE_FROM_INT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value;
         #ifdef GRAVITY_ENABLE_DOUBLE
@@ -86,7 +86,7 @@ static bool math_abs (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
         #endif
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -95,21 +95,21 @@ static bool math_abs (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 static bool math_acos (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ACOS((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ACOS((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -118,21 +118,21 @@ static bool math_acos (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, ui
 static bool math_asin (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ASIN((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ASIN((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -141,21 +141,21 @@ static bool math_asin (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, ui
 static bool math_atan (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ATAN((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ATAN((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -163,31 +163,31 @@ static bool math_atan (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, ui
 // returns the arctangent of the quotient of its arguments
 static bool math_atan2 (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm)
-    
+
     if (nargs != 3) RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
-    
+
     gravity_value_t value = GET_VALUE(1);
     gravity_value_t value2 = GET_VALUE(2);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     gravity_float_t n2;
     if (VALUE_ISA_INT(value2)) n2 = (gravity_float_t)value2.n;
     else if (VALUE_ISA_FLOAT(value2)) n2 = (gravity_float_t)value2.f;
     else RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ATAN2((gravity_float_t)value.n, n2);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ATAN2((gravity_float_t)value.f, n2);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -252,21 +252,21 @@ static bool math_xrt (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 static bool math_ceil (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)CEIL((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)CEIL((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -275,21 +275,21 @@ static bool math_ceil (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, ui
 static bool math_cos (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)COS((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)COS((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -298,21 +298,21 @@ static bool math_cos (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 static bool math_exp (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)EXP((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)EXP((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -321,21 +321,21 @@ static bool math_exp (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 static bool math_floor (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)FLOOR((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)FLOOR((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -397,21 +397,21 @@ static bool math_lcm (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 static bool math_log (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)LOG((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)LOG((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -477,7 +477,7 @@ static bool math_logx (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, ui
 static bool math_max (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     gravity_float_t n = FLOAT_MIN;
     gravity_value_t result = VALUE_FROM_UNDEFINED;
-    
+
     for (uint16_t i = 1; i<nargs; ++i) {
         gravity_value_t value = GET_VALUE(i);
         if (VALUE_ISA_INT(value)) {
@@ -486,7 +486,7 @@ static bool math_max (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
             if (value.f > n) result = value;
         } else continue;
     }
-    
+
     RETURN_VALUE(result, rindex);
 }
 
@@ -494,7 +494,7 @@ static bool math_max (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 static bool math_min (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     gravity_float_t n = FLOAT_MAX;
     gravity_value_t result = VALUE_FROM_UNDEFINED;
-    
+
     for (uint16_t i = 1; i<nargs; ++i) {
         gravity_value_t value = GET_VALUE(i);
         if (VALUE_ISA_INT(value)) {
@@ -503,38 +503,38 @@ static bool math_min (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
             if (value.f < n) result = value;
         } else continue;
     }
-    
+
     RETURN_VALUE(result, rindex);
 }
 
 // returns the value of x to the power of y
 static bool math_pow (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm)
-    
+
     if (nargs != 3) RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
-    
+
     gravity_value_t value = GET_VALUE(1);
     gravity_value_t value2 = GET_VALUE(2);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     gravity_float_t n2;
     if (VALUE_ISA_INT(value2)) n2 = (gravity_float_t)value2.n;
     else if (VALUE_ISA_FLOAT(value2)) n2 = (gravity_float_t)value2.f;
     else RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)POW((gravity_float_t)value.n, n2);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)POW((gravity_float_t)value.f, n2);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -542,14 +542,14 @@ static bool math_pow (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 // returns a random number between 0 and 1
 static bool math_random (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, args, nargs)
-    
+
     // only seed once
     static bool already_seeded = false;
     if (!already_seeded) {
         srand((unsigned)time(NULL));
         already_seeded = true;
     }
-    
+
     int r = rand();
     RETURN_VALUE(VALUE_FROM_FLOAT((float)r / RAND_MAX), rindex);
 }
@@ -558,21 +558,21 @@ static bool math_random (gravity_vm *vm, gravity_value_t *args, uint16_t nargs,
 static bool math_round (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ROUND((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)ROUND((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -581,21 +581,21 @@ static bool math_round (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, u
 static bool math_sin (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)SIN((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)SIN((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -604,21 +604,21 @@ static bool math_sin (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uin
 static bool math_sqrt (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)SQRT((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)SQRT((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -627,21 +627,21 @@ static bool math_sqrt (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, ui
 static bool math_tan (gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex) {
     #pragma unused(vm, nargs)
     gravity_value_t value = GET_VALUE(1);
-    
+
     if (VALUE_ISA_NULL(value)) {
         RETURN_VALUE(VALUE_FROM_INT(0), rindex);
     }
-    
+
     if (VALUE_ISA_INT(value)) {
         gravity_float_t computed_value = (gravity_float_t)TAN((gravity_float_t)value.n);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     if (VALUE_ISA_FLOAT(value)) {
         gravity_float_t computed_value = (gravity_float_t)TAN((gravity_float_t)value.f);
         RETURN_VALUE(VALUE_FROM_FLOAT(computed_value), rindex);
     }
-    
+
     // should be NaN
     RETURN_VALUE(VALUE_FROM_UNDEFINED, rindex);
 }
@@ -700,7 +700,7 @@ static bool math_SQRT1_2 (gravity_vm *vm, gravity_value_t *args, uint16_t nargs,
 static void create_optional_class (void) {
     gravity_class_math = gravity_class_new_pair(NULL, MATH_CLASS_NAME, NULL, 0, 0);
     gravity_class_t *meta = gravity_class_get_meta(gravity_class_math);
-    
+
     gravity_class_bind(meta, "abs", NEW_CLOSURE_VALUE(math_abs));
     gravity_class_bind(meta, "acos", NEW_CLOSURE_VALUE(math_acos));
     gravity_class_bind(meta, "asin", NEW_CLOSURE_VALUE(math_asin));
@@ -725,7 +725,7 @@ static void create_optional_class (void) {
     gravity_class_bind(meta, "sin", NEW_CLOSURE_VALUE(math_sin));
     gravity_class_bind(meta, "sqrt", NEW_CLOSURE_VALUE(math_sqrt));
     gravity_class_bind(meta, "tan", NEW_CLOSURE_VALUE(math_tan));
-    
+
     gravity_closure_t *closure = NULL;
     closure = computed_property_create(NULL, NEW_FUNCTION(math_PI), NULL);
     gravity_class_bind(meta, "PI", VALUE_FROM_OBJECT(closure));
@@ -743,7 +743,7 @@ static void create_optional_class (void) {
     gravity_class_bind(meta, "SQRT2", VALUE_FROM_OBJECT(closure));
     closure = computed_property_create(NULL, NEW_FUNCTION(math_SQRT1_2), NULL);
     gravity_class_bind(meta, "SQRT1_2", VALUE_FROM_OBJECT(closure));
-    
+
     SETMETA_INITED(gravity_class_math);
 }
 
@@ -760,17 +760,17 @@ const char *gravity_math_name (void) {
 void gravity_math_register (gravity_vm *vm) {
     if (!gravity_class_math) create_optional_class();
     ++refcount;
-    
+
     if (!vm || gravity_vm_ismini(vm)) return;
     gravity_vm_setvalue(vm, MATH_CLASS_NAME, VALUE_FROM_OBJECT(gravity_class_math));
 }
 
 void gravity_math_free (void) {
     if (!gravity_class_math) return;
-    
+
     --refcount;
     if (refcount) return;
-    
+
     mem_check(false);
     gravity_class_t *meta = gravity_class_get_meta(gravity_class_math);
     computed_property_free(meta, "PI", true);
@@ -784,7 +784,7 @@ void gravity_math_free (void) {
     gravity_class_free_core(NULL, meta);
     gravity_class_free_core(NULL, gravity_class_math);
     mem_check(true);
-    
+
     gravity_class_math = NULL;
 }
 

File diff suppressed because it is too large
+ 154 - 154
src/runtime/gravity_core.c


+ 1 - 1
src/runtime/gravity_core.h

@@ -31,7 +31,7 @@ gravity_value_t convert_value2string (gravity_vm *vm, gravity_value_t v);
 // internal functions
 gravity_closure_t *computed_property_create (gravity_vm *vm, gravity_function_t *getter_func, gravity_function_t *setter_func);
 void              computed_property_free (gravity_class_t *c, const char *name, bool remove_flag);
-    
+
 #ifdef __cplusplus
 }
 #endif

File diff suppressed because it is too large
+ 176 - 176
src/runtime/gravity_vm.c


+ 1 - 1
src/runtime/gravity_vm.h

@@ -43,7 +43,7 @@ GRAVITY_API gravity_value_t		gravity_vm_keyindex (gravity_vm *vm, uint32_t index
 GRAVITY_API bool				gravity_vm_isaborted (gravity_vm *vm);
 GRAVITY_API void				gravity_vm_setaborted (gravity_vm *vm);
 GRAVITY_API gravity_closure_t   *gravity_vm_getclosure (gravity_vm *vm);
-    
+
 
 GRAVITY_API void				gravity_gray_value (gravity_vm* vm, gravity_value_t v);
 GRAVITY_API void				gravity_gray_object (gravity_vm* vm, gravity_object_t *obj);

+ 1 - 1
src/shared/gravity_array.h

@@ -9,7 +9,7 @@
 #ifndef __GRAVITY_MUTABLE_ARRAY__
 #define __GRAVITY_MUTABLE_ARRAY__
 
-#include <stdint.h> 
+#include <stdint.h>
 
 // Inspired by https://github.com/attractivechaos/klib/blob/master/kvec.h
 

+ 2 - 2
src/shared/gravity_delegate.h

@@ -54,7 +54,7 @@ typedef void				(*gravity_bridge_free) (gravity_vm *vm, gravity_object_t *obj);
 typedef struct {
 	// user data
 	void						*xdata;					// optional user data transparently passed between callbacks
-	
+
 	// callbacks
 	gravity_log_callback		log_callback;			// log reporting callback
 	gravity_error_callback		error_callback;			// error reporting callback
@@ -63,7 +63,7 @@ typedef struct {
 	gravity_precode_callback	precode_callback;		// called at parse time in order to give the opportunity to add custom source code
 	gravity_loadfile_callback	loadfile_callback;		// callback to give the opportunity to load a file from an import statement
 	gravity_filename_callback	filename_callback;		// called while reporting an error in order to be able to convert a fileid to a real filename
-	
+
 	// bridge
 	gravity_bridge_initinstance	bridge_initinstance;	// init class
 	gravity_bridge_setvalue		bridge_setvalue;		// setter

+ 47 - 47
src/shared/gravity_hash.c

@@ -34,7 +34,7 @@ struct gravity_hash_t {
 	gravity_hash_isequal_fn	isequal_fn;
 	gravity_hash_iterate_fn free_fn;
 	void					*data;
-	
+
 	// stats
 	#if GRAVITYHASH_ENABLE_STATS
 	uint32_t				ncollision;
@@ -47,15 +47,15 @@ struct gravity_hash_t {
 /*
 	Hash algorithm used in Gravity Hash Table is DJB2 which does a pretty good job with string keys and it is fast.
 	Original algorithm is: http://www.cse.yorku.ca/~oz/hash.html
-	
+
 	DJBX33A (Daniel J. Bernstein, Times 33 with Addition)
- 
+
 	This is Daniel J. Bernstein's popular `times 33' hash function as
 	posted by him years ago on comp.lang.c. It basically uses a function
 	like ``hash(i) = hash(i-1) 	33 + str[i]''. This is one of the best
 	known hash functions for strings. Because it is both computed very
 	fast and distributes very well.
-	
+
 	Why 33? (<< 5 in the code)
 	The magic of number 33, i.e. why it works better than many other
 	constants, prime or not, has never been adequately explained by
@@ -65,7 +65,7 @@ struct gravity_hash_t {
 	(except for the number 1) work more or less all equally well. They
 	all distribute in an acceptable way and this way fill a hash table
 	with an average percent of approx. 86%.
-	
+
 	If one compares the Chi^2 values of the variants, the number 33 not
 	even has the best value. But the number 33 and a few other equally
 	good numbers like 17, 31, 63, 127 and 129 have nevertheless a great
@@ -76,19 +76,19 @@ struct gravity_hash_t {
 	distribute good _and_ has to be very fast to compute, those few
 	numbers should be preferred and seems to be the reason why Daniel J.
 	Bernstein also preferred it.
- 
+
 	Why 5381?
 	1. odd number
 	2. prime number
 	3. deficient number (https://en.wikipedia.org/wiki/Deficient_number)
 	4. 001/010/100/000/101 b
-	
+
 	Practically any good multiplier works. I think you're worrying about
 	the fact that 31c + d doesn't cover any reasonable range of hash values
 	if c and d are between 0 and 255. That's why, when I discovered the 33 hash
 	function and started using it in my compressors, I started with a hash value
 	of 5381. I think you'll find that this does just as well as a 261 multiplier.
- 
+
 	Note that the starting value of the hash (5381) makes no difference for strings
 	of equal lengths, but will play a role in generating different hash values for
 	strings of different lengths.
@@ -107,9 +107,9 @@ static inline uint32_t murmur3_32 (const char *key, uint32_t len, uint32_t seed)
 	static const uint32_t r2 = 13;
 	static const uint32_t m = 5;
 	static const uint32_t n = 0xe6546b64;
-	
+
 	uint32_t hash = seed;
-	
+
 	const int nblocks = len / 4;
 	const uint32_t *blocks = (const uint32_t *) key;
 	for (int i = 0; i < nblocks; i++) {
@@ -117,14 +117,14 @@ static inline uint32_t murmur3_32 (const char *key, uint32_t len, uint32_t seed)
 		k *= c1;
 		k = ROT32(k, r1);
 		k *= c2;
-		
+
 		hash ^= k;
 		hash = ROT32(hash, r2) * m + n;
 	}
-	
+
 	const uint8_t *tail = (const uint8_t *) (key + nblocks * 4);
 	uint32_t k1 = 0;
-	
+
 	switch (len & 3) {
 		case 3:
 			k1 ^= tail[2] << 16;
@@ -132,20 +132,20 @@ static inline uint32_t murmur3_32 (const char *key, uint32_t len, uint32_t seed)
 			k1 ^= tail[1] << 8;
 		case 1:
 			k1 ^= tail[0];
-			
+
 			k1 *= c1;
 			k1 = ROT32(k1, r1);
 			k1 *= c2;
 			hash ^= k1;
 	}
-	
+
 	hash ^= len;
 	hash ^= (hash >> 16);
 	hash *= 0x85ebca6b;
 	hash ^= (hash >> 13);
 	hash *= 0xc2b2ae35;
 	hash ^= (hash >> 16);
-	
+
 	return hash;
 }
 
@@ -161,11 +161,11 @@ static void table_dump (gravity_hash_t *hashtable, gravity_value_t key, gravity_
 gravity_hash_t *gravity_hash_create (uint32_t size, gravity_hash_compute_fn compute, gravity_hash_isequal_fn isequal, gravity_hash_iterate_fn free_fn, void *data) {
 	if ((!compute) || (!isequal)) return NULL;
 	if (size == 0) size = GRAVITYHASH_DEFAULT_SIZE;
-	
+
 	gravity_hash_t *hashtable = (gravity_hash_t *)mem_alloc(sizeof(gravity_hash_t));
 	if (!hashtable) return NULL;
 	if (!(hashtable->nodes = mem_calloc(size, sizeof(hash_node_t*)))) {mem_free(hashtable); return NULL;}
-	
+
 	hashtable->compute_fn = compute;
 	hashtable->isequal_fn = isequal;
 	hashtable->free_fn = free_fn;
@@ -177,7 +177,7 @@ gravity_hash_t *gravity_hash_create (uint32_t size, gravity_hash_compute_fn comp
 void gravity_hash_free (gravity_hash_t *hashtable) {
 	if (!hashtable) return;
 	gravity_hash_iterate_fn free_fn = hashtable->free_fn;
-	
+
 	for (uint32_t n = 0; n < hashtable->size; ++n) {
 		hash_node_t *node = hashtable->nodes[n];
         hashtable->nodes[n] = NULL;
@@ -212,7 +212,7 @@ static inline int gravity_hash_resize (gravity_hash_t *hashtable) {
 		.compute_fn = hashtable->compute_fn
 	};
 	if (!(newtbl.nodes = mem_calloc(size, sizeof(hash_node_t*)))) return -1;
-	
+
 	hash_node_t *node, *next;
 	for (uint32_t n = 0; n < hashtable->size; ++n) {
 		for (node = hashtable->nodes[n]; node; node = next) {
@@ -226,20 +226,20 @@ static inline int gravity_hash_resize (gravity_hash_t *hashtable) {
 			hashtable->free_fn = free_fn;
 		}
 	}
-	
+
 	mem_free(hashtable->nodes);
 	hashtable->size = newtbl.size;
 	hashtable->count = newtbl.count;
 	hashtable->nodes = newtbl.nodes;
 	INC_RESIZE(hashtable);
-	
+
 	return 0;
 }
 
 bool gravity_hash_remove (gravity_hash_t *hashtable, gravity_value_t key) {
 	register uint32_t hash = hashtable->compute_fn(key);
 	register uint32_t position = hash % hashtable->size;
-	
+
 	gravity_hash_iterate_fn free_fn = hashtable->free_fn;
 	hash_node_t *node = hashtable->nodes[position];
 	hash_node_t *prevnode = NULL;
@@ -252,21 +252,21 @@ bool gravity_hash_remove (gravity_hash_t *hashtable, gravity_value_t key) {
 			hashtable->count--;
 			return true;
 		}
-		
+
 		prevnode = node;
 		node = node->next;
 	}
-	
+
 	return false;
 }
 
 bool gravity_hash_insert (gravity_hash_t *hashtable, gravity_value_t key, gravity_value_t value) {
 	register uint32_t hash = hashtable->compute_fn(key);
 	register uint32_t position = hash % hashtable->size;
-	
+
 	hash_node_t *node = hashtable->nodes[position];
 	if (node) INC_COLLISION(hashtable);
-	
+
 	// check if the key is already in the table
 	while (node) {
 		if ((node->hash == hash) && (hashtable->isequal_fn(key, node->key))) {
@@ -275,7 +275,7 @@ bool gravity_hash_insert (gravity_hash_t *hashtable, gravity_value_t key, gravit
 		}
 		node = node->next;
 	}
-	
+
 	// resize table if the threshold is exceeded
 	// default threshold is: <table size> * <load factor GRAVITYHASH_THRESHOLD>
 	if (hashtable->count >= hashtable->size * GRAVITYHASH_THRESHOLD) {
@@ -283,7 +283,7 @@ bool gravity_hash_insert (gravity_hash_t *hashtable, gravity_value_t key, gravit
 		// recompute position here because hashtable->size has changed!
 		position = hash % hashtable->size;
 	}
-	
+
 	// allocate new entry and set new data
 	if (!(node = mem_alloc(sizeof(hash_node_t)))) return -1;
 	node->key = key;
@@ -292,20 +292,20 @@ bool gravity_hash_insert (gravity_hash_t *hashtable, gravity_value_t key, gravit
 	node->next = hashtable->nodes[position];
 	hashtable->nodes[position] = node;
 	++hashtable->count;
-	
+
 	return true;
 }
 
 gravity_value_t *gravity_hash_lookup (gravity_hash_t *hashtable, gravity_value_t key) {
 	register uint32_t hash = hashtable->compute_fn(key);
 	register uint32_t position = hash % hashtable->size;
-	
+
 	hash_node_t *node = hashtable->nodes[position];
 	while (node) {
 		if ((node->hash == hash) && (hashtable->isequal_fn(key, node->key))) return &node->value;
 		node = node->next;
 	}
-	
+
 	return NULL;
 }
 
@@ -347,11 +347,11 @@ void gravity_hash_stat (gravity_hash_t *hashtable) {
 
 void gravity_hash_transform (gravity_hash_t *hashtable, gravity_hash_transform_fn transform, void *data) {
 	if ((!hashtable) || (!transform)) return;
-	
+
 	for (uint32_t i=0; i<hashtable->size; ++i) {
 		hash_node_t *node = hashtable->nodes[i];
 		if (!node) continue;
-		
+
 		while (node) {
 			transform(hashtable, node->key, &node->value, data);
 			node = node->next;
@@ -361,11 +361,11 @@ void gravity_hash_transform (gravity_hash_t *hashtable, gravity_hash_transform_f
 
 void gravity_hash_iterate (gravity_hash_t *hashtable, gravity_hash_iterate_fn iterate, void *data) {
 	if ((!hashtable) || (!iterate)) return;
-	
+
 	for (uint32_t i=0; i<hashtable->size; ++i) {
 		hash_node_t *node = hashtable->nodes[i];
 		if (!node) continue;
-		
+
 		while (node) {
 			iterate(hashtable, node->key, node->value, data);
 			node = node->next;
@@ -375,11 +375,11 @@ void gravity_hash_iterate (gravity_hash_t *hashtable, gravity_hash_iterate_fn it
 
 void gravity_hash_iterate2 (gravity_hash_t *hashtable, gravity_hash_iterate2_fn iterate, void *data1, void *data2) {
 	if ((!hashtable) || (!iterate)) return;
-	
+
 	for (uint32_t i=0; i<hashtable->size; ++i) {
 		hash_node_t *node = hashtable->nodes[i];
 		if (!node) continue;
-		
+
 		while (node) {
 			iterate(hashtable, node->key, node->value, data1, data2);
 			node = node->next;
@@ -395,7 +395,7 @@ void gravity_hash_append (gravity_hash_t *hashtable1, gravity_hash_t *hashtable2
 	for (uint32_t i=0; i<hashtable2->size; ++i) {
 		hash_node_t *node = hashtable2->nodes[i];
 		if (!node) continue;
-		
+
 		while (node) {
 			gravity_hash_insert(hashtable1, node->key, node->value);
 			node = node->next;
@@ -410,7 +410,7 @@ void gravity_hash_resetfree (gravity_hash_t *hashtable) {
 bool gravity_hash_compare (gravity_hash_t *hashtable1, gravity_hash_t *hashtable2, gravity_hash_compare_fn compare, void *data) {
     if (hashtable1->count != hashtable2->count) return false;
     if (!compare) return false;
-    
+
     // 1. allocate arrays of keys and values
     gravity_value_r keys1; gravity_value_r values1;
     gravity_value_r keys2; gravity_value_r values2;
@@ -420,7 +420,7 @@ bool gravity_hash_compare (gravity_hash_t *hashtable1, gravity_hash_t *hashtable
     marray_resize(gravity_value_t, keys2, hashtable1->count + MARRAY_DEFAULT_SIZE);
     marray_resize(gravity_value_t, values1, hashtable1->count + MARRAY_DEFAULT_SIZE);
     marray_resize(gravity_value_t, values2, hashtable1->count + MARRAY_DEFAULT_SIZE);
-    
+
     // 2. build arrays of keys and values for hashtable1
     for (uint32_t i=0; i<hashtable1->size; ++i) {
         hash_node_t *node = hashtable1->nodes[i];
@@ -431,7 +431,7 @@ bool gravity_hash_compare (gravity_hash_t *hashtable1, gravity_hash_t *hashtable
             node = node->next;
         }
     }
-    
+
     // 3. build arrays of keys and values for hashtable2
     for (uint32_t i=0; i<hashtable2->size; ++i) {
         hash_node_t *node = hashtable2->nodes[i];
@@ -442,25 +442,25 @@ bool gravity_hash_compare (gravity_hash_t *hashtable1, gravity_hash_t *hashtable
             node = node->next;
         }
     }
-    
+
     // sanity check
     bool result = false;
     uint32_t count = (uint32_t)marray_size(keys1);
     if (count != (uint32_t)marray_size(keys2)) goto cleanup;
-    
+
     // 4. compare keys and values
     for (uint32_t i=0; i<count; ++i) {
         if (!compare(marray_get(keys1, i), marray_get(keys2, i), data)) goto cleanup;
         if (!compare(marray_get(values1, i), marray_get(values2, i), data)) goto cleanup;
     }
-    
+
     result = true;
-    
+
 cleanup:
     marray_destroy(keys1);
     marray_destroy(keys2);
     marray_destroy(values1);
     marray_destroy(values2);
-    
+
     return result;
 }

+ 1 - 1
src/shared/gravity_hash.h

@@ -59,7 +59,7 @@ GRAVITY_API void				gravity_hash_append (gravity_hash_t *hashtable1, gravity_has
 GRAVITY_API void				gravity_hash_resetfree (gravity_hash_t *hashtable);
 
 GRAVITY_API bool                gravity_hash_compare (gravity_hash_t *hashtable1, gravity_hash_t *hashtable2, gravity_hash_compare_fn compare, void *data);
-    
+
 #ifdef __cplusplus
 }
 #endif

+ 28 - 28
src/shared/gravity_memory.c

@@ -37,11 +37,11 @@ typedef struct {
 	void					*ptr;
 	size_t					size;
 	size_t					nrealloc;
-	
+
 	// record where it has been allocated/reallocated
 	size_t					nframe;
 	char					**frames;
-	
+
 	// record where is has been freed
 	size_t					nframe2;
 	char					**frames2;
@@ -67,28 +67,28 @@ static void memdebug_report (char *str, char **stack, size_t nstack, memslot *sl
 		if (_is_internal(stack[i])) continue;
 		printf("%s\n", stack[i]);
 	}
-	
+
 	if (slot) {
 		printf("\nallocated:\n");
 		for (size_t i=0; i<slot->nframe; ++i) {
 			if (_is_internal(slot->frames[i])) continue;
 			printf("%s\n", slot->frames[i]);
 		}
-		
+
 		printf("\nfreed:\n");
 		for (size_t i=0; i<slot->nframe2; ++i) {
 			if (_is_internal(slot->frames2[i])) continue;
 			printf("%s\n", slot->frames2[i]);
 		}
 	}
-	
+
 	abort();
 }
 
 void memdebug_init (void) {
 	if (memdebug.slot) free(memdebug.slot);
 	bzero(&memdebug, sizeof(_memdebug));
-	
+
 	memdebug.slot = (memslot *) malloc(sizeof(memslot) * SLOT_MIN);
 	memdebug.aslot = SLOT_MIN;
 }
@@ -101,7 +101,7 @@ void *memdebug_malloc(size_t size) {
 		memdebug_report(current_error, stack, n, NULL);
 		return NULL;
 	}
-	
+
 	_ptr_add(ptr, size);
 	return ptr;
 }
@@ -118,7 +118,7 @@ void *memdebug_calloc(size_t num, size_t size) {
 		memdebug_report(current_error, stack, n, NULL);
 		return NULL;
 	}
-	
+
 	_ptr_add(ptr, num*size);
 	return ptr;
 }
@@ -132,7 +132,7 @@ void *memdebug_realloc(void *ptr, size_t new_size) {
 		memdebug_report(current_error, stack, n, NULL);
 		return NULL;
 	}
-	
+
 	void *new_ptr = realloc(ptr, new_size);
 	if (!ptr) {
 		BUILD_ERROR("Unable to reallocate a block of %zu bytes", new_size);
@@ -140,7 +140,7 @@ void *memdebug_realloc(void *ptr, size_t new_size) {
 		memdebug_report(current_error, stack, n, &memdebug.slot[index]);
 		return NULL;
 	}
-	
+
 	_ptr_replace(ptr, new_ptr, new_size);
 	return new_ptr;
 }
@@ -155,7 +155,7 @@ bool memdebug_remove(void *ptr) {
 			memdebug_report(current_error, stack, n, NULL);
 			return false;
 		}
-		
+
 		memslot m = memdebug.slot[index];
 		if (m.deleted) {
 			BUILD_ERROR("Pointer already freed");
@@ -164,7 +164,7 @@ bool memdebug_remove(void *ptr) {
 			return false;
 		}
 	}
-	
+
 	_ptr_remove(ptr);
 	return true;
 }
@@ -185,13 +185,13 @@ void memdebug_stat(void) {
 	printf("Leaked: %d (bytes)\n", memdebug.currmem);
 	printf("Max memory usage: %d (bytes)\n", memdebug.maxmem);
 	printf("==================================\n\n");
-	
+
 	if (memdebug.currmem > 0) {
 		printf("\n");
 		for (uint32_t i=0; i<memdebug.nslot; ++i) {
 			memslot m = memdebug.slot[i];
 			if ((!m.ptr) || (m.deleted)) continue;
-						
+
 			printf("Block %p size: %zu (reallocated %zu)\n", m.ptr, m.size, m.nrealloc);
 			printf("Call stack:\n");
 			printf("===========\n");
@@ -215,7 +215,7 @@ size_t memdebug_leaks (void) {
 // Internals
 void _ptr_add (void *ptr, size_t size) {
 	CHECK_FLAG();
-	
+
 	if (memdebug.nslot + 1 >= memdebug.aslot) {
 		size_t old_size = sizeof(memslot) * memdebug.nslot;
 		size_t new_size = sizeof(memslot) * SLOT_MIN;
@@ -228,7 +228,7 @@ void _ptr_add (void *ptr, size_t size) {
 		memdebug.slot = new_slot;
 		memdebug.aslot += SLOT_MIN;
 	}
-	
+
 	memslot slot = {
 		.deleted = false,
 		.ptr = ptr,
@@ -238,10 +238,10 @@ void _ptr_add (void *ptr, size_t size) {
 		.frames = NULL
 	};
 	slot.frames = _ptr_stacktrace(&slot.nframe);
-		
+
 	memdebug.slot[memdebug.nslot] = slot;
 	++memdebug.nslot;
-	
+
 	++memdebug.nalloc;
 	memdebug.currmem += size;
 	if (memdebug.currmem > memdebug.maxmem)
@@ -250,14 +250,14 @@ void _ptr_add (void *ptr, size_t size) {
 
 void _ptr_replace (void *old_ptr, void *new_ptr, size_t new_size) {
 	CHECK_FLAG();
-	
+
 	uint32_t index = _ptr_lookup(old_ptr);
-	
+
 	if (index == SLOT_NOTFOUND) {
 		BUILD_ERROR("Unable to find old pointer to realloc");
 		memdebug_report(current_error, NULL, 0, NULL);
 	}
-	
+
 	memslot slot = memdebug.slot[index];
 	if (slot.deleted) {
 		BUILD_ERROR("Pointer already freed");
@@ -270,7 +270,7 @@ void _ptr_replace (void *old_ptr, void *new_ptr, size_t new_size) {
 	if (slot.frames) free((void *)slot.frames);
 	slot.frames = _ptr_stacktrace(&slot.nframe);
 	++slot.nrealloc;
-	
+
 	memdebug.slot[index] = slot;
 	++memdebug.nrealloc;
 	memdebug.currmem += (new_size - old_size);
@@ -280,25 +280,25 @@ void _ptr_replace (void *old_ptr, void *new_ptr, size_t new_size) {
 
 void _ptr_remove (void *ptr) {
 	CHECK_FLAG();
-	
+
 	uint32_t index = _ptr_lookup(ptr);
-	
+
 	if (index == SLOT_NOTFOUND) {
 		BUILD_ERROR("Unable to find old pointer to realloc");
 		memdebug_report(current_error, NULL, 0, NULL);
 	}
-	
+
 	memslot slot = memdebug.slot[index];
 	if (slot.deleted) {
 		BUILD_ERROR("Pointer already freed");
 		BUILD_STACK(n, stack);
 		memdebug_report(current_error, stack, n, &slot);
 	}
-	
+
 	size_t old_size = memdebug.slot[index].size;
 	memdebug.slot[index].deleted = true;
 	memdebug.slot[index].frames2 = _ptr_stacktrace(&memdebug.slot[index].nframe2);
-	
+
 	++memdebug.nfree;
 	memdebug.currmem -= old_size;
 }
@@ -326,7 +326,7 @@ char **_ptr_stacktrace (size_t *nframes) {
 // Default callback
 bool _is_internal(const char *s) {
 	static const char *reserved[] = {"??? ", "libdyld.dylib ", "memdebug_", "_ptr_", NULL};
-	
+
 	const char **r = reserved;
 	while (*r) {
 		if (strstr(s, *r)) return true;

+ 13 - 13
src/shared/gravity_opcodes.h

@@ -11,7 +11,7 @@
 
 /*
 		Big-endian vs Little-endian machines
- 
+
 		ARM architecture runs both little & big endianess, but the android, iOS, and windows phone platforms run little endian.
 		95% of modern desktop computers are little-endian.
 		All x86 desktops (which is nearly all desktops with the demise of the PowerPC-based Macs several years ago) are little-endian.
@@ -22,22 +22,22 @@
 
 /*
 		Instructions are 32bit in lenght
- 
+
 		// 2 registers and 1 register/constant
 		+------------------------------------+
 		|  OP  |   Ax   |   Bx   |    Cx/K   |
 		+------------------------------------+
- 
+
 		// instructions with no parameters
 		+------------------------------------+
 		|  OP  |0                            |
 		+------------------------------------+
- 
+
 		// unconditional JUMP
 		+------------------------------------+
 		|  OP  |             N1              |
 		+------------------------------------+
- 
+
 		// LOADI and JUMPF
 		+------------------------------------+
 		|  OP  |   Ax   |S|       N2         |
@@ -53,7 +53,7 @@
  */
 
 typedef enum {
-	
+
 	//		****************************************************************************************************
 	//		56 OPCODE INSTRUCTIONS (for a register based virtual machine)
 	//		opcode is a 6 bit value so at maximum 2^6 = 64 opcodes can be declared
@@ -69,7 +69,7 @@ typedef enum {
 			NOP,			//	NONE		//	NOP									http://en.wikipedia.org/wiki/NOP
 			RET,			//  A			//	return from a function				R(-1) = R(A)
 			CALL,			//	A, B, C		//	call a function						R(A) = B(C0...Cn) B is callable object and C is num args
-	
+
 											//	*** LOAD/STORE OPERATIONS (11) ***
 			LOAD,			//	A, B, C		//	load C from B and store in A		R(A) = R(B)[C]
 			LOADS,			//	A, B, C		//	load C from B and store in A		R(A) = R(B)[C] (super variant)
@@ -83,12 +83,12 @@ typedef enum {
 			STOREAT,		//	A, B, C		//	store A into R(B)[C]				R(B)[C] = R(A)
 			STOREG,			//	A, B		//	store global						G[K(B)] = R(A)
 			STOREU,			//	A, B		//	store upvalue						U(B) = R(A)
-	
+
 											//	*** JUMP OPERATIONS (3) ***
 			JUMP,			//	A			//	unconditional jump					PC += A
 			JUMPF,			//	A, B		//	jump if R(A) is false				(R(A) == 0)	? PC += B : 0
 			SWITCH,			//				//	switch statement
-	
+
 											//	*** MATH OPERATIONS (19) ***
 			ADD,			//	A, B, C		//	add operation						R(A) = R(B) + R(C)
 			SUB,			//	A, B, C		//	sub operation						R(A) = R(B) - R(C)
@@ -109,7 +109,7 @@ typedef enum {
 			MATCH,			//	A, B, C		//	=~ pattern match					R(A) = R(B) =~ R(C)
 			NEG,			//	A, B		//	neg operation						R(A) = -R(B)
 			NOT,			//	A, B		//	not operation						R(A) = !R(B)
-	
+
 											// *** BIT OPERATIONS (6) ***
 			LSHIFT,			//	A, B, C		// shift left							R(A) = R(B) << R(C)
 			RSHIFT,			//	A, B, C		// shift right							R(A) = R(B) >> R(C)
@@ -117,17 +117,17 @@ typedef enum {
 			BOR,			//	A, B, C		// bit or								R(A) = R(B) | R(C)
 			BXOR,			//	A, B, C		// bit xor								R(A) = R(B) ^ R(C)
 			BNOT,			//	A, B		// bit not								R(A) = ~R(B)
-	
+
 											// *** ARRAY/MAP/RANGE OPERATIONS (4) ***
 			MAPNEW,			//	A, B		//	create a new map					R(A) = Alloc a MAP(B)
 			LISTNEW,		//	A, B		//	create a new array					R(A) = Alloc a LIST(B)
 			RANGENEW,		//	A, B, C, f	//	create a new range					R(A) = Alloc a RANGE(B,C) f flag tells if B inclusive or exclusive
 			SETLIST,		//	A, B, C		//	set list/map items
-	
+
 											// *** CLOSURES (2) ***
 			CLOSURE,		//	A, B		//	create a new closure				R(A) = closure(K(B))
 			CLOSE,			//	A			//  close all upvalues from R(A)
-	
+
 											// *** UNUSED (6) ***
 			RESERVED1,		//				// reserved for future use
 			RESERVED2,		//				// reserved for future use

File diff suppressed because it is too large
+ 155 - 155
src/shared/gravity_value.c


+ 18 - 18
src/shared/gravity_value.h

@@ -77,15 +77,15 @@ extern "C" {
 #ifndef GRAVITY_ENABLE_INT64
 #define GRAVITY_ENABLE_INT64				1			// if 1 enable gravity_int_t to be a 64bit int (intead of a 32bit int)
 #endif
-    
+
 #ifndef GRAVITY_COMPUTED_GOTO
 #define GRAVITY_COMPUTED_GOTO				1			// if 1 enable faster computed goto (instead of switch) for compilers that support it
 #endif
-    
+
 #ifndef GRAVITY_NULL_SILENT
 #define GRAVITY_NULL_SILENT					1			// if 1 then messages sent to null does not produce any runtime error
 #endif
-    
+
 #ifndef GRAVITY_MAP_DOTSUGAR
 #define GRAVITY_MAP_DOTSUGAR				1			// if 1 then map objects can be accessed with both map[key] and map.key
 #endif
@@ -254,10 +254,10 @@ typedef struct {
 			float			purity;				// experimental value
 			bool			useargs;			// flag set by the compiler to optimize the creation of the arguments array only if needed
 		};
-		
+
 		// tag == EXEC_TYPE_INTERNAL
 		gravity_c_internal	internal;			// function callback
-		
+
 		// tag == EXEC_TYPE_SPECIAL
 		struct {
 			uint16_t		index;				// property index to speed-up default getter and setter
@@ -269,7 +269,7 @@ typedef struct {
 typedef struct upvalue_s {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	gravity_value_t			*value;				// ptr to open value on the stack or to closed value on this struct
 	gravity_value_t			closed;				// copy of the value once has been closed
 	struct upvalue_s		*next;				// ptr to the next open upvalue
@@ -278,7 +278,7 @@ typedef struct upvalue_s {
 typedef struct {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	gravity_function_t		*f;					// function prototype
 	gravity_upvalue_t		**upvalue;			// upvalue array
 } gravity_closure_t;
@@ -286,14 +286,14 @@ typedef struct {
 typedef struct {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	gravity_value_r			array;				// dinamic array of values
 } gravity_list_t;
 
 typedef struct {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	gravity_hash_t			*hash;				// hash table
 } gravity_map_t;
 
@@ -312,17 +312,17 @@ typedef struct {
 typedef struct fiber_s {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	gravity_value_t			*stack;				// stack buffer (grown as needed and it holds locals and temps)
 	gravity_value_t			*stacktop;			// current stack ptr
 	uint32_t				stackalloc;			// number of allocated values
-	
+
 	gravity_callframe_t		*frames;			// callframes buffer (grown as needed but never shrinks)
 	uint32_t				nframes;			// number of frames currently in use
 	uint32_t				framesalloc;		// number of allocated frames
-	
+
 	gravity_upvalue_t		*upvalues;			// linked list used to keep track of open upvalues
-	
+
 	char					*error;				// runtime error message
 	bool					trying;				// set when the try flag is set by the user
 	struct fiber_s			*caller;			// optional caller fiber
@@ -332,7 +332,7 @@ typedef struct fiber_s {
 typedef struct gravity_class_s {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	gravity_class_t			*objclass;			// meta class
 	const char				*identifier;		// class name
 	bool					has_outer;			// flag used to automatically set ivar 0 to outer class (if any)
@@ -350,7 +350,7 @@ typedef struct gravity_class_s {
 typedef struct {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	const char				*identifier;		// module name
 	gravity_hash_t			*htable;			// hash table
 } gravity_module_t;
@@ -358,7 +358,7 @@ typedef struct {
 typedef struct {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	gravity_class_t			*objclass;			// real instance class
 	void					*xdata;				// extra bridged data
 	gravity_value_t			ivars[];			// instance variables (MUST BE LAST in the struct!)
@@ -367,7 +367,7 @@ typedef struct {
 typedef struct {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	char					*s;					// pointer to NULL terminated string
 	uint32_t				hash;				// string hash (type to be keeped in sync with gravity_hash_size_t)
 	uint32_t				len;				// actual string length
@@ -377,7 +377,7 @@ typedef struct {
 typedef struct {
 	gravity_class_t			*isa;				// to be an object
 	gravity_gc_t			gc;					// to be collectable by the garbage collector
-	
+
 	gravity_int_t			from;				// range start
 	gravity_int_t			to;					// range end
 } gravity_range_t;

+ 33 - 33
src/utils/gravity_debug.c

@@ -50,12 +50,12 @@ const char *gravity_disassemble (const char *bcode, uint32_t blen, bool deserial
 	uint32_t	*ip = NULL;
 	uint32_t	pc = 0, inst = 0, ninsts = 0;
 	opcode_t	op;
-	
+
 	const int	rowlen = 256;
 	uint32_t	bindex = 0;
 	uint32_t	balloc = 0;
 	char		*buffer = NULL;
-	
+
 	if (deserialize) {
 		// decode textual buffer to real bytecode
 		ip = gravity_bytecode_deserialize(bcode, blen, &ninsts);
@@ -64,37 +64,37 @@ const char *gravity_disassemble (const char *bcode, uint32_t blen, bool deserial
 		ip = (uint32_t *)bcode;
 		ninsts = blen;
 	}
-		
+
 	// allocate a buffer big enought to fit all disassembled bytecode
 	// I assume that each instruction (each row) will be 256 chars long
 	balloc = ninsts * rowlen;
 	buffer = mem_alloc(balloc);
 	if (!buffer) goto abort_disassemble;
-		
+
 	// conversion loop
 	while (pc < ninsts) {
 		inst = *ip++;
 		op = (opcode_t)OPCODE_GET_OPCODE(inst);
-		
+
 		switch (op) {
 			case NOP: {
 				DUMP_VM(buffer, bindex, "NOP");
 				break;
 			}
-				
+
 			case MOVE: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, const uint32_t r1, const uint32_t r2);
 				DUMP_VM(buffer, bindex, "MOVE %d %d", r1, r2);
 				break;
 			}
-				
+
 			case LOADI: {
 				//OPCODE_GET_ONE8bit_ONE18bit(inst, uint32_t r1, int32_t value); if no support for signed int
 				OPCODE_GET_ONE8bit_SIGN_ONE17bit(inst, const uint32_t r1, const int32_t value);
 				DUMP_VM(buffer, bindex, "LOADI %d %d", r1, value);
 				break;
 			}
-				
+
 			case LOADK: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, const uint32_t r1, const uint32_t index);
 				if (index < CPOOL_INDEX_MAX) {
@@ -115,13 +115,13 @@ const char *gravity_disassemble (const char *bcode, uint32_t blen, bool deserial
 				}
 				break;
 			}
-				
+
 			case LOADG: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, uint32_t r1, int32_t index);
 				DUMP_VM(buffer, bindex, "LOADG %d %d", r1, index);
 				break;
 			}
-			
+
 			case LOAD:
 			case LOADS:
 			case LOADAT: {
@@ -129,32 +129,32 @@ const char *gravity_disassemble (const char *bcode, uint32_t blen, bool deserial
 				DUMP_VM(buffer, bindex, "%s %d %d %d", (op == LOAD) ? "LOAD" : "LOADAT", r1, r2, r3);
 				break;
 			}
-				
+
 			case LOADU: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, const uint32_t r1, const uint32_t r2);
 				DUMP_VM(buffer, bindex, "LOADU %d %d", r1, r2);
 				break;
 			}
-				
+
 			case STOREG: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, uint32_t r1, int32_t index);
 				DUMP_VM(buffer, bindex, "STOREG %d %d", r1, index);
 				break;
 			}
-				
+
 			case STOREU: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, const uint32_t r1, const uint32_t r2);
 				DUMP_VM(buffer, bindex, "STOREU %d %d", r1, r2);
 				break;
 			}
-				
+
 			case STORE:
 			case STOREAT: {
 				OPCODE_GET_TWO8bit_ONE10bit(inst, const uint32_t r1, const uint32_t r2, const uint32_t r3);
 				DUMP_VM(buffer, bindex, "%s %d %d %d", (op == STORE) ? "STORE" : "STOREAT", r1, r2, r3);
 				break;
 			}
-			
+
 			case EQQ:
 			case NEQQ:
 			case ISA:
@@ -169,7 +169,7 @@ const char *gravity_disassemble (const char *bcode, uint32_t blen, bool deserial
 				DUMP_VM(buffer, bindex, "%s %d %d %d", opcode_name(op), r1, r2, r3);
 				break;
 			}
-				
+
 			// binary operators
 			case LSHIFT:
 			case RSHIFT:
@@ -187,7 +187,7 @@ const char *gravity_disassemble (const char *bcode, uint32_t blen, bool deserial
 				DUMP_VM(buffer, bindex, "%s %d %d %d", opcode_name(op), r1, r2, r3);
 				break;
 			}
-				
+
 			// unary operators
 			case BNOT:
 			case NEG:
@@ -197,32 +197,32 @@ const char *gravity_disassemble (const char *bcode, uint32_t blen, bool deserial
 				DUMP_VM(buffer, bindex, "%s %d %d %d", opcode_name(op), r1, r2, r3);
 				break;
 			}
-			
+
 			case RANGENEW: {
 				OPCODE_GET_TWO8bit_ONE10bit(inst, const uint32_t r1, const uint32_t r2, const uint32_t r3);
 				DUMP_VM(buffer, bindex, "%s %d %d %d", opcode_name(op), r1, r2, r3);
 				break;
 			}
-			
+
 			case JUMPF: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, const uint32_t r1, const int32_t value);
 				DUMP_VM(buffer, bindex, "JUMPF %d %d", r1, value);
 				break;
 			}
-				
+
 			case JUMP: {
 				OPCODE_GET_ONE26bit(inst, const uint32_t value);
 				DUMP_VM(buffer, bindex, "JUMP %d", value);
 				break;
 			}
-				
+
 			case CALL: {
 				// CALL A B C => R(A) = B(C0... CN)
 				OPCODE_GET_THREE8bit(inst, const uint32_t r1, const uint32_t r2, uint32_t r3);
 				DUMP_VM(buffer, bindex, "CALL %d %d %d", r1, r2, r3);
 				break;
 			}
-				
+
 			case RET0:
 			case RET: {
 				if (op == RET0) {
@@ -233,49 +233,49 @@ const char *gravity_disassemble (const char *bcode, uint32_t blen, bool deserial
 				}
 				break;
 			}
-				
+
 			case HALT: {
 				DUMP_VM(buffer, bindex, "HALT");
 				break;
 			}
-				
+
 			case SWITCH: {
 				DUMP_VM(buffer, bindex, "SWITCH instruction not yet implemented");
 				break;
 			}
-				
+
 			case MAPNEW: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, const uint32_t r1, const uint32_t n);
 				DUMP_VM(buffer, bindex, "MAPNEW %d %d", r1, n);
 				break;
 			}
-				
+
 			case LISTNEW: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, const uint32_t r1, const uint32_t n);
 				DUMP_VM(buffer, bindex, "LISTNEW %d %d", r1, n);
 				break;
 			}
-				
+
 			case SETLIST: {
 				OPCODE_GET_TWO8bit_ONE10bit(inst, const uint32_t r1, uint32_t r2, const uint32_t r3);
 				#pragma unused(r3)
 				DUMP_VM(buffer, bindex, "SETLIST %d %d", r1, r2);
 				break;
 			}
-			
+
 			case CLOSURE: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, const uint32_t r1, const uint32_t r2);
 				DUMP_VM(buffer, bindex, "CLOSURE %d %d", r1, r2);
 				break;
 			}
-				
+
 			case CLOSE: {
 				OPCODE_GET_ONE8bit_ONE18bit(inst, const uint32_t r1, const uint32_t r2);
 				#pragma unused(r2)
 				DUMP_VM(buffer, bindex, "CLOSE %d", r1);
 				break;
 			}
-				
+
 			case RESERVED1:
 			case RESERVED2:
 			case RESERVED3:
@@ -286,12 +286,12 @@ const char *gravity_disassemble (const char *bcode, uint32_t blen, bool deserial
 				break;
 			}
 		}
-		
+
 		++pc;
 	}
-	
+
 	return buffer;
-	
+
 abort_disassemble:
 	if (ip && deserialize) mem_free(ip);
 	if (buffer) mem_free(buffer);

+ 39 - 39
src/utils/gravity_json.c

@@ -76,7 +76,7 @@ struct json_t {
 	size_t		blen;
 	size_t		bused;
 	uint32_t	ident;
-	
+
 	json_ctx_t	ctx[JSON_MAX_NESTED];
 	size_t		ctxidx;
 };
@@ -84,22 +84,22 @@ struct json_t {
 json_t *json_new (void) {
 	json_t *json = mem_alloc(sizeof(json_t));
 	assert(json);
-	
+
 	json->buffer = mem_alloc(JSON_MINSIZE);
 	assert(json->buffer);
-	
+
 	json->blen = JSON_MINSIZE;
 	json->bused = 0;
 	json->ident = 0;
 	json->ctxidx = 0;
-	
+
 	return json;
 }
 
 static void json_write_raw (json_t *json, const char *buffer, size_t len, bool escape, bool is_pretty) {
 	size_t	prettylen = (is_pretty) ? (json->ident * JSON_PRETTYSIZE)+1 : 0;
 	size_t	escapelen = (escape) ? 2 : 0;
-	
+
 	// check buffer reallocation
 	size_t reqlen = json->bused + len + prettylen + escapelen + JSON_MINSIZE;
 	if (reqlen >= json->blen) {
@@ -107,22 +107,22 @@ static void json_write_raw (json_t *json, const char *buffer, size_t len, bool e
 		assert(json->buffer);
 		json->blen += reqlen;
 	}
-	
+
 	if (is_pretty) {
 		for (uint32_t i=0; i<json->ident; ++i) {
 			memcpy(json->buffer+json->bused, JSON_PRETTYLINE, JSON_PRETTYSIZE);
 			json->bused += JSON_PRETTYSIZE;
 		}
 	}
-	
+
 	if (escape) {
 		memcpy(json->buffer+json->bused, "\"", 1);
 		json->bused += 1;
 	}
-	
+
 	memcpy(json->buffer+json->bused, buffer, len);
 	json->bused += len;
-	
+
 	if (escape) {
 		memcpy(json->buffer+json->bused, "\"", 1);
 		json->bused += 1;
@@ -134,11 +134,11 @@ static void json_write_escaped (json_t *json, const char *buffer, size_t len, bo
 		json_write_raw(json, "", 0, escape, is_pretty);
 		return;
 	}
-	
+
 	char	*new_buffer = mem_alloc (len*2);
 	size_t	j = 0;
 	assert(new_buffer);
-	
+
 	for (size_t i=0; i<len; ++i) {
 		char c = buffer[i];
 		switch (c) {
@@ -149,11 +149,11 @@ static void json_write_escaped (json_t *json, const char *buffer, size_t len, bo
 			case '\n': JSON_ESCAPE ('n');   continue;
 			case '\r': JSON_ESCAPE ('r');   continue;
 			case '\t': JSON_ESCAPE ('t');   continue;
-				
+
 			default: new_buffer[j] = c; ++j;break;
 		};
 	}
-	
+
 	json_write_raw(json, new_buffer, j, escape, is_pretty);
 	mem_free(new_buffer);
 }
@@ -169,25 +169,25 @@ void json_begin_object (json_t *json, const char *key) {
 		json_write_raw (json, key, strlen(key), true, true);
 		JSON_WRITE_SEP;
 	}
-	
+
 	JSON_PUSH_CTX(json, json_ctx_object);
 	json_write_raw(json, "{", 1, false, (key == NULL));
 	json_write_raw(json, JSON_NEWLINE, 1, false, false);
-	
+
 	++json->ident;
 }
 
 void json_end_object (json_t *json) {
 	--json->ident;
 	JSON_POP_CTX(json);
-	
+
 	// check latest 2 characters
 	if ((json->buffer[json->bused-1] == JSON_NEWLINE_CHAR) && (json->buffer[json->bused-2] == ',')) {
 		json->buffer[json->bused-2] = JSON_NEWLINE_CHAR;
 		json->buffer[json->bused-1] = 0;
 		--json->bused;
 	}
-	
+
 	json_write_raw(json, "}", 1, false, true);
 	if (json->ident) {JSON_TERM_FIELD;}
 	else json_write_raw(json, JSON_NEWLINE, 1, false, false);
@@ -203,25 +203,25 @@ void json_begin_array (json_t *json, const char *key) {
 		json_write_raw (json, key, strlen(key), true, true);
 		JSON_WRITE_SEP;
 	}
-	
+
 	JSON_PUSH_CTX(json, json_ctx_array);
 	json_write_raw(json, "[", 1, false, (key == NULL));
 	json_write_raw(json, JSON_NEWLINE, 1, false, false);
-	
+
 	++json->ident;
 }
 
 void json_end_array (json_t *json) {
 	--json->ident;
 	JSON_POP_CTX(json);
-	
+
 	// check latest 2 characters
 	if ((json->buffer[json->bused-1] == JSON_NEWLINE_CHAR) && (json->buffer[json->bused-2] == ',')) {
 		json->buffer[json->bused-2] = JSON_NEWLINE_CHAR;
 		json->buffer[json->bused-1] = 0;
 		--json->bused;
 	}
-	
+
 	json_write_raw(json, "]", 1, false, true);
 	JSON_TERM_FIELD;
 }
@@ -231,12 +231,12 @@ void json_add_string (json_t *json, const char *key, const char *value, size_t l
 		json_add_null(json, key);
 		return;
 	}
-	
+
 	if (key) {
 		json_write_raw (json, key, strlen(key), true, true);
 		JSON_WRITE_SEP;
 	}
-	
+
 	// check if string value needs to be escaped
 	bool write_escaped = false;
 	for (size_t i=0; i<len; ++i) {
@@ -244,7 +244,7 @@ void json_add_string (json_t *json, const char *key, const char *value, size_t l
 	}
 	if (len == 0)
 		write_escaped = true;
-	
+
 	if (write_escaped)
 		json_write_escaped(json, value, len, true, (key == NULL));
 	else
@@ -259,20 +259,20 @@ void json_add_cstring (json_t *json, const char *key, const char *value) {
 void json_add_int (json_t *json, const char *key, int64_t value) {
 	char buffer[512];
 	size_t len = snprintf(buffer, sizeof(buffer), "%" PRId64, value);
-	
+
 	if (key) {
 		json_write_raw (json, key, strlen(key), true, true);
 		JSON_WRITE_SEP;
 	}
 	json_write_raw(json, buffer, len, false, (key == NULL));
 	JSON_TERM_FIELD;
-	
+
 }
 
 void json_add_double (json_t *json, const char *key, double value) {
 	char buffer[512];
 	size_t len = snprintf(buffer, sizeof(buffer), "%f", value);
-	
+
 	if (key) {
 		json_write_raw (json, key, strlen(key), true, true);
 		JSON_WRITE_SEP;
@@ -283,7 +283,7 @@ void json_add_double (json_t *json, const char *key, double value) {
 
 void json_add_bool (json_t *json, const char *key, bool bvalue) {
 	const char *value = (bvalue) ? "true" : "false";
-	
+
 	if (key) {
 		json_write_raw (json, key, strlen(key), true, true);
 		JSON_WRITE_SEP;
@@ -499,7 +499,7 @@ static const long
    flag_next             = 1 << 0,
    flag_reproc           = 1 << 1,
    flag_need_comma       = 1 << 2,
-   flag_seek_value       = 1 << 3, 
+   flag_seek_value       = 1 << 3,
    flag_escaped          = 1 << 4,
    flag_string           = 1 << 5,
    flag_need_colon       = 1 << 6,
@@ -567,7 +567,7 @@ json_value * json_parse_ex (json_settings * settings,
       for (state.ptr = json ;; ++ state.ptr)
       {
          json_char b = (state.ptr == end ? 0 : *state.ptr);
-         
+
          if (flags & flag_string)
          {
             if (!b)
@@ -591,7 +591,7 @@ json_value * json_parse_ex (json_settings * settings,
                   case 't':  string_add ('\t');  break;
                   case 'u':
 
-                    if (end - state.ptr < 4 || 
+                    if (end - state.ptr < 4 ||
                         (uc_b1 = hex_value (*++ state.ptr)) == 0xFF ||
                         (uc_b2 = hex_value (*++ state.ptr)) == 0xFF ||
                         (uc_b3 = hex_value (*++ state.ptr)) == 0xFF ||
@@ -607,7 +607,7 @@ json_value * json_parse_ex (json_settings * settings,
 
                     if ((uchar & 0xF800) == 0xD800) {
                         json_uchar uchar2;
-                        
+
                         if (end - state.ptr < 6 || (*++ state.ptr) != '\\' || (*++ state.ptr) != 'u' ||
                             (uc_b1 = hex_value (*++ state.ptr)) == 0xFF ||
                             (uc_b2 = hex_value (*++ state.ptr)) == 0xFF ||
@@ -621,7 +621,7 @@ json_value * json_parse_ex (json_settings * settings,
                         uc_b1 = (uc_b1 << 4) | uc_b2;
                         uc_b2 = (uc_b3 << 4) | uc_b4;
                         uchar2 = (uc_b1 << 8) | uc_b2;
-                        
+
                         uchar = 0x010000 | ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF);
                     }
 
@@ -651,7 +651,7 @@ json_value * json_parse_ex (json_settings * settings,
                            string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F);
                            string [string_length ++] = 0x80 | (uchar & 0x3F);
                         }
-                        
+
                         break;
                     }
 
@@ -701,7 +701,7 @@ json_value * json_parse_ex (json_settings * settings,
                      if (state.first_pass)
                         (*(json_char **) &top->u.object.values) += string_length + 1;
                      else
-                     {  
+                     {
                         top->u.object.values [top->u.object.length].name
                            = (json_char *) top->_reserved.object_mem;
 
@@ -846,7 +846,7 @@ json_value * json_parse_ex (json_settings * settings,
                         continue;
                      }
                      else
-                     { 
+                     {
                         sprintf (error, "%d:%d: Expected : before %c",
                                  state.cur_line, state.cur_col, b);
 
@@ -984,7 +984,7 @@ json_value * json_parse_ex (json_settings * settings,
             switch (top->type)
             {
             case json_object:
-               
+
                switch (b)
                {
                   whitespace:
@@ -1003,7 +1003,7 @@ json_value * json_parse_ex (json_settings * settings,
                      string_length = 0;
 
                      break;
-                  
+
                   case '}':
 
                      flags = (flags & ~ flag_need_comma) | flag_next;
@@ -1159,7 +1159,7 @@ json_value * json_parse_ex (json_settings * settings,
 
             if (top->parent->type == json_array)
                flags |= flag_seek_value;
-               
+
             if (!state.first_pass)
             {
                json_value * parent = top->parent;

+ 9 - 9
src/utils/gravity_json.h

@@ -117,14 +117,14 @@ typedef enum
 } json_type;
 
 extern const struct _json_value json_value_none;
-       
+
 typedef struct _json_object_entry
 {
     json_char * name;
     unsigned int name_length;
-    
+
     struct _json_value * value;
-    
+
 } json_object_entry;
 
 typedef struct _json_value
@@ -219,7 +219,7 @@ typedef struct _json_value
          }
 
          inline const struct _json_value &operator [] (const char * index) const
-         { 
+         {
             if (type != json_object)
                return json_value_none;
 
@@ -231,7 +231,7 @@ typedef struct _json_value
          }
 
          inline operator const char * () const
-         {  
+         {
             switch (type)
             {
                case json_string:
@@ -243,7 +243,7 @@ typedef struct _json_value
          }
 
          inline operator json_int_t () const
-         {  
+         {
             switch (type)
             {
                case json_integer:
@@ -258,7 +258,7 @@ typedef struct _json_value
          }
 
          inline operator bool () const
-         {  
+         {
             if (type != json_boolean)
                return false;
 
@@ -266,7 +266,7 @@ typedef struct _json_value
          }
 
          inline operator double () const
-         {  
+         {
             switch (type)
             {
                case json_integer:
@@ -286,7 +286,7 @@ typedef struct _json_value
 
 #define EMPTY_SETTINGS_STRUCT	{0,0,0,0,0,0}
 #define EMPTY_STATE_STRUCT		{0,0,0,EMPTY_SETTINGS_STRUCT,0,0,0,0}
-       
+
 json_value * json_parse (const json_char * json,
                          size_t length);
 

+ 54 - 54
src/utils/gravity_utils.c

@@ -35,44 +35,44 @@
 
 nanotime_t nanotime (void) {
 	nanotime_t value;
-	
+
 	#if defined(_WIN32)
 	static LARGE_INTEGER	win_frequency;
 	QueryPerformanceFrequency(&win_frequency);
 	LARGE_INTEGER			t;
-	
+
 	if (!QueryPerformanceCounter(&t)) return 0;
 	value = (t.QuadPart / win_frequency.QuadPart) * 1000000000;
 	value += (t.QuadPart % win_frequency.QuadPart) * 1000000000 / win_frequency.QuadPart;
-	
+
 	#elif defined(__MACH__)
 	mach_timebase_info_data_t	info;
 	kern_return_t				r;
 	nanotime_t					t;
-	
+
 	t = mach_absolute_time();
 	r = mach_timebase_info(&info);
 	if (r != 0) return 0;
 	value = (t / info.denom) * info.numer;
 	value += (t % info.denom) * info.numer / info.denom;
-	
+
 	#elif defined(__linux)
 	struct timespec ts;
 	int				r;
-	
+
 	r = clock_gettime(CLOCK_MONOTONIC, &ts);
 	if (r != 0) return 0;
 	value = ts.tv_sec * (nanotime_t)1000000000 + ts.tv_nsec;
-	
+
 	#else
 	struct timeval	tv;
 	int				r;
-	
+
 	r = gettimeofday(&tv, 0);
 	if (r != 0) return 0;
 	value = tv.tv_sec * (nanotime_t)1000000000 + tv.tv_usec * 1000;
 	#endif
-	
+
 	return value;
 }
 
@@ -96,7 +96,7 @@ static ssize_t getline (char **lineptr, size_t *n, FILE *stream) {
 	// see http://stackoverflow.com/questions/3302255/c-scanf-vs-gets-vs-fgets
 	// we should implement something like ggets here
 	// http://web.archive.org/web/20080525133110/http://cbfalconer.home.att.net/download/
-	
+
 	return -1;
 }
 #endif
@@ -104,13 +104,13 @@ static ssize_t getline (char **lineptr, size_t *n, FILE *stream) {
 char *readline (char *prompt, int *length) {
 	char	*line = NULL;
 	size_t	size = 0;
-	
+
 	printf("%s", prompt);
 	fflush(stdout);
-	
+
 	ssize_t nread = getline(&line, &size, stdin);
 	if (nread == -1 || feof(stdin)) return NULL;
-	
+
 	*length = (int)nread;
 	return line;
 }
@@ -134,24 +134,24 @@ const char *file_read(const char *path, size_t *len) {
 	off_t	fsize = 0;
 	size_t	fsize2 = 0;
 	char	*buffer = NULL;
-	
+
 	fsize = (size_t) file_size(path);
 	if (fsize < 0) goto abort_read;
-	
+
 	fd = open(path, O_RDONLY);
 	if (fd < 0) goto abort_read;
-	
+
 	buffer = (char *)mem_alloc((size_t)fsize + 1);
 	if (buffer == NULL) goto abort_read;
 	buffer[fsize] = 0;
-	
+
 	fsize2 = read(fd, buffer, (size_t)fsize);
 	if (fsize2 == -1) goto abort_read;
-	
+
 	if (len) *len = fsize2;
 	close(fd);
 	return (const char *)buffer;
-	
+
 abort_read:
 	if (buffer) mem_free((void *)buffer);
 	if (fd >= 0) close(fd);
@@ -162,23 +162,23 @@ bool file_exists (const char *path) {
 	#ifdef WIN32
 	BOOL isDirectory;
 	DWORD attributes = GetFileAttributesA(path);
-	
+
 	// special directory case to drive the network path check
 	if (attributes == INVALID_FILE_ATTRIBUTES)
 		isDirectory = (GetLastError() == ERROR_BAD_NETPATH);
 	else
 		isDirectory = (FILE_ATTRIBUTE_DIRECTORY & attributes);
-	
+
 	if (isDirectory) {
 		if (PathIsNetworkPathA(path)) return true;
 		if (PathIsUNCA(path)) return true;
 	}
-	
+
 	if (PathFileExistsA(path) == 1) return true;
 	#else
 	if (access(path, F_OK)==0) return true;
 	#endif
-	
+
 	return false;
 }
 
@@ -189,16 +189,16 @@ const char *file_buildpath (const char *filename, const char *dirpath) {
 	size_t len1 = strlen(filename);
 	size_t len2 = strlen(dirpath);
 	size_t len = len1+len2+2;
-	
+
 	char *full_path = (char *)mem_alloc(len);
 	if (!full_path) return NULL;
-	
+
 	if ((len2) && (dirpath[len2-1] != '/'))
 		snprintf(full_path, len, "%s/%s", dirpath, filename);
 	else
 		snprintf(full_path, len, "%s%s", dirpath, filename);
 //	#endif
-	
+
 	return (const char *)full_path;
 }
 
@@ -209,13 +209,13 @@ bool file_write (const char *path, const char *buffer, size_t len) {
 	#else
 	mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
 	#endif
-	
+
 	int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
 	if (fd < 0) return false;
-	
+
 	ssize_t nwrite = write(fd, buffer, len);
 	close(fd);
-	
+
 	return (nwrite == len);
 }
 
@@ -224,17 +224,17 @@ bool file_write (const char *path, const char *buffer, size_t len) {
 bool is_directory (const char *path) {
 	#ifdef WIN32
 	DWORD dwAttrs;
-	
+
 	dwAttrs = GetFileAttributesA(path);
 	if (dwAttrs == INVALID_FILE_ATTRIBUTES) return false;
 	if (dwAttrs & FILE_ATTRIBUTE_DIRECTORY) return true;
 	#else
 	struct stat buf;
-	
+
 	if (lstat(path, &buf) < 0) return false;
 	if (S_ISDIR(buf.st_mode)) return true;
 	#endif
-	
+
 	return false;
 }
 
@@ -248,10 +248,10 @@ DIRREF directory_init (const char *dirpath) {
 
 	// convert dirpath to dirpathW
 	MultiByteToWideChar(CP_UTF8, 0, dirpath, -1, dirpathW, MAX_PATH);
-	
+
 	// in this way I can be sure that the first file returned (and lost) is .
 	PathCombineW(path, dirpathW, _T("*"));
-	
+
 	// if the path points to a symbolic link, the WIN32_FIND_DATA buffer contains
 	// information about the symbolic link, not the target
 	return FindFirstFileW(path, &findData);
@@ -262,12 +262,12 @@ DIRREF directory_init (const char *dirpath) {
 
 const char *directory_read (DIRREF ref) {
 	if (ref == NULL) return NULL;
-	
+
 	while (1) {
 		#ifdef WIN32
 		WIN32_FIND_DATA findData;
 		char 			*file_name;
-		
+
 		if (FindNextFile(ref, &findData) == 0) {
 			FindClose(ref);
 			return NULL;
@@ -299,7 +299,7 @@ int string_nocasencmp(const char *s1, const char *s2, size_t n) {
 		s2++;
 		n--;
 	}
-	
+
 	if(n == 0) return 0;
 	return tolower((unsigned char)*s1) - tolower((unsigned char)*s2);
 }
@@ -311,7 +311,7 @@ int string_casencmp(const char *s1, const char *s2, size_t n) {
 		s2++;
 		n--;
 	}
-	
+
 	if(n == 0) return 0;
 	return ((unsigned char)*s1) - ((unsigned char)*s2);
 }
@@ -324,7 +324,7 @@ int string_cmp (const char *s1, const char *s2) {
 const char *string_dup (const char *s1) {
 	size_t	len = (size_t)strlen(s1);
 	char	*s = (char *)mem_alloc(len + 1);
-	
+
 	memcpy(s, s1, len);
 	return s;
 }
@@ -351,7 +351,7 @@ uint32_t string_size (const char *p) {
 char *string_strnstr(const char *s, const char *find, size_t slen) {
     char c, sc;
     size_t len;
-    
+
     if ((c = *find++) != '\0') {
         len = strlen(find);
         do {
@@ -382,18 +382,18 @@ char *string_strnstr(const char *s, const char *find, size_t slen) {
 	UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
 				  %xF4 %x80-8F 2( UTF8-tail )
 	UTF8-tail   = %x80-BF
- 
+
  */
 
 inline uint32_t utf8_charbytes (const char *s, uint32_t i) {
 	unsigned char c = s[i];
-	
+
 	// determine bytes needed for character, based on RFC 3629
 	if ((c > 0) && (c <= 127)) return 1;
 	if ((c >= 194) && (c <= 223)) return 2;
 	if ((c >= 224) && (c <= 239)) return 3;
 	if ((c >= 240) && (c <= 244)) return 4;
-	
+
 	// means error
 	return 0;
 }
@@ -410,13 +410,13 @@ uint32_t utf8_nbytes (uint32_t n) {
 // from: https://github.com/munificent/wren/blob/master/src/vm/wren_utils.c
 uint32_t utf8_encode(char *buffer, uint32_t value) {
 	char *bytes = buffer;
-	
+
 	if (value <= 0x7f) {
 		// single byte (i.e. fits in ASCII).
 		*bytes = value & 0x7f;
 		return 1;
 	}
-	
+
 	if (value <= 0x7ff) {
 		// two byte sequence: 110xxxxx 10xxxxxx.
 		*bytes = 0xc0 | ((value & 0x7c0) >> 6);
@@ -424,7 +424,7 @@ uint32_t utf8_encode(char *buffer, uint32_t value) {
 		*bytes = 0x80 | (value & 0x3f);
 		return 2;
 	}
-	
+
 	if (value <= 0xffff) {
 		// three byte sequence: 1110xxxx 10xxxxxx 10xxxxxx.
 		*bytes = 0xe0 | ((value & 0xf000) >> 12);
@@ -434,7 +434,7 @@ uint32_t utf8_encode(char *buffer, uint32_t value) {
 		*bytes = 0x80 | (value & 0x3f);
 		return 3;
 	}
-	
+
 	if (value <= 0x10ffff) {
 		// four byte sequence: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx.
 		*bytes = 0xf0 | ((value & 0x1c0000) >> 18);
@@ -446,23 +446,23 @@ uint32_t utf8_encode(char *buffer, uint32_t value) {
 		*bytes = 0x80 | (value & 0x3f);
 		return 4;
 	}
-	
+
 	return 0;
 }
 
 uint32_t utf8_len (const char *s, uint32_t nbytes) {
 	if (nbytes == 0) nbytes = (uint32_t)strlen(s);
-	
+
 	uint32_t pos = 1;
 	uint32_t len = 0;
-	
+
 	while (pos <= nbytes) {
 		++len;
 		uint32_t n = utf8_charbytes(s, pos);
 		if (n == 0) return 0; // means error
 		pos += n;
 	}
-	
+
 	return len;
 }
 
@@ -470,7 +470,7 @@ uint32_t utf8_len (const char *s, uint32_t nbytes) {
 bool utf8_reverse (char *p) {
 	char *q = p;
 	string_reverse(p);
-	
+
 	// now fix bass-ackwards UTF chars.
 	while(q && *q) ++q; // find eos
 	while(p < --q)
@@ -508,7 +508,7 @@ uint32_t power_of2_ceil (uint32_t n) {
 	n |= n >> 8;
 	n |= n >> 16;
 	n++;
-	
+
 	return n;
 }
 
@@ -524,7 +524,7 @@ int64_t number_from_oct (const char *s, uint32_t len) {
 
 int64_t number_from_bin (const char *s, uint32_t len) {
 	int64_t value = 0;
-	
+
 	for (uint32_t i=0; i<len; ++i) {
 		int c = s[i];
 		value = (value << 1) + (c - '0');

Some files were not shown because too many files changed in this diff