Skip to content

Commit

Permalink
add gravity files
Browse files Browse the repository at this point in the history
  • Loading branch information
strongcourage committed Apr 5, 2020
1 parent 7ca47e4 commit d5aaf2c
Show file tree
Hide file tree
Showing 1,041 changed files with 12,539 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gravity/1.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,25 @@
#unittest {
name: "Test class instantiation.";
error: NONE;
result: 3;
};

class foo {
var a = 1;
var b = 2;

func f1() {
return self.a;
}

func f2() {
return b;
}
}

func main() {
var f = foo();
var a = f.f1();
var b = f.f2();
return a b;
}
19 changes: 19 additions & 0 deletions gravity/12.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,19 @@
#unittest {
name: "Test combined init/call init.";
error: NONE;
result: 150;
};

// no init
class c1 {
var p1;
func f1() {
p1 = 150;
return p1;
}
}

func main() {
var x1 = c1().f1();
return x1;
}
19 changes: 19 additions & 0 deletions gravity/13.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,19 @@
#unittest {
name: "Test self set/get init.";
error: NONE;
result: 150;
};

// no init
class c1 {
var p1;
func f1() {
self.p1 = 150;
return self.p1;
}
}

func main() {
var x1 = c1().f1();
return x1;
}
23 changes: 23 additions & 0 deletions gravity/2.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@
#unittest {
name: "Test class instantiation.";
error: NONE;
result: 3;
};

class foo {
var a = 1;
var b = 2;

func f1() {
return self.a;
}

func f2() {
return b;
}
}

func main() {
var f = foo();
return f.f1() f.f2();
}
23 changes: 23 additions & 0 deletions gravity/3.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@
#unittest {
name: "Test class instantiation.";
error: NONE;
result: 3;
};

class foo {
var a = 1;
var b = 2;

func f1() {
return a;
}

func f2() {
return b;
}
}

func main() {
var f = foo();
return f.f1() f.f2();
}
23 changes: 23 additions & 0 deletions gravity/4.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@
#unittest {
name: "Test class instantiation.";
error: NONE;
result: 3;
};

class foo {
var a = 1;
var b = 2;

func f1() {
return self.a;
}

func f2() {
return self.b;
}
}

func main() {
var f = foo();
return f.f1() f.f2();
}
25 changes: 25 additions & 0 deletions gravity/5.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,25 @@
#unittest {
name: "Test class instantiation.";
error: NONE;
result: 30;
};

class foo {
var a = 1;
var b = 2;

func f1() {
return a;
}

func f2() {
return b;
}
}

func main() {
var f = foo();
f.a = 10;
f.b = 20;
return f.f1() f.f2();
}
27 changes: 27 additions & 0 deletions gravity/6.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,27 @@
#unittest {
name: "Test class instantiation.";
error: NONE;
result: 783;
};

class foo {
var a = 1;
var b = 2;

func f1() {
return self.a self.b;
}

func f2() {
self.a = 50;
self.b = 730;
}
}

func main() {
var f = foo();
var n1 = f.f1();
f.f2();
var n2 = f.f1();
return n1 n2;
}
27 changes: 27 additions & 0 deletions gravity/7.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,27 @@
#unittest {
name: "Test class instantiation.";
error: NONE;
result: 783;
};

class foo {
var a = 1;
var b = 2;

func f1() {
return a b;
}

func f2() {
a = 50;
b = 730;
}
}

func main() {
var f = foo();
var n1 = f.f1();
f.f2();
var n2 = f.f1();
return n1 n2;
}
21 changes: 21 additions & 0 deletions gravity/8.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,21 @@
#unittest {
name: "Test class ivar (a) and lookup (b).";
error: NONE;
result: 3;
};

class foo {
var a = 1;
func b() {return 2;}

func f1() {
var n1 = a;
var n2 = b;
return n1 n2();
}
}

func main() {
var f = foo();
return f.f1();
}
14 changes: 14 additions & 0 deletions gravity/_func.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,14 @@
#unittest {
name: "Test _func keyword.";
error: NONE;
result: 6765;
};

func fibonacci (n) {
if (n<2) return n;
return _func(n-2) _func(n-1);
}

func main() {
return fibonacci(20);
}
14 changes: 14 additions & 0 deletions gravity/add_operation_and_function_calls.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,14 @@
#unittest {
name: "ADD operation and function calls;";
error: NONE;
result: "classname: (bar)";
};

class foo {}
class bar:foo {}

func main() {
var v = bar();
var log = "classname: (" v.Class().name() ")";
return log;
}
40 changes: 40 additions & 0 deletions gravity/anon_class_test.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,40 @@
#unittest {
name: "Anonimous class test";
result: 666
};

var Window1;

class _Window1 {
var button;

class _Button1 {
func test() {
return 777;
}
}

func setup() {
button = _Button1();
button.bind("action", {var a = Window1.action(); return a;})
}

func action() {
return 666;
}
}

func main() {
Window1 = _Window1();
Window1.setup();

var test = Window1.action();
var button = Window1.button;
button.test();
var temp = button.action();

// force GC to run
var l = [1,2,3];

return temp;
}
17 changes: 17 additions & 0 deletions gravity/arg_expression.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,17 @@
#unittest {
name: "_args used in expression.";
error: NONE;
result: 640;
};

func sum() {
var tot = 0;
_args.loop(func (value) {tot =value});
return tot;
}

func main() {
var a = 10;
var b = 20;
return sum(a, b, a*(a b 9) (b-a), a, a*b)
}
13 changes: 13 additions & 0 deletions gravity/arguments_1.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,13 @@
#unittest {
name: "Test arguments keyword.";
error: NONE;
result: 100;
};

func sum (a,b,c) {
return _args[-1];
}

func main() {
return sum(10,20,30,40,50,60,70,80,90,100);
}
13 changes: 13 additions & 0 deletions gravity/arguments_2.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,13 @@
#unittest {
name: "Test arguments keyword.";
error: NONE;
result: 10;
};

func sum (a,b,c) {
return _args.count;
}

func main() {
return sum(10,20,30,40,50,60,70,80,90,100);
}
17 changes: 17 additions & 0 deletions gravity/arguments_sum.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,17 @@
#unittest {
name: "Test arguments keyword.";
error: NONE;
result: 550;
};

func sum () {
var tot = 0;
for (var i in 0..<_args.count) {
tot = _args[i];
}
return tot;
}

func main() {
return sum(10,20,30,40,50,60,70,80,90,100);
}
12 changes: 12 additions & 0 deletions gravity/arithmetic_expression_a.gravity
Original file line number Diff line number Diff line change
@@ -0,0 1,12 @@
#unittest {
name: "Arithmetic expression ( ,-) with multiple subnodes, testing operator execution order.";
error: NONE;
result: 5;
};

func main() {
var a = 5;
var b = 2;
var c = 2;
return a - b c;
}
Loading

0 comments on commit d5aaf2c

Please sign in to comment.