--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+[[accumulate]] float f() {
+ print("a");
+ return = 1;
+}
+
+[[accumulate]] float f() {
+ print("b");
+ return;
+}
+
+[[accumulate]] float f() {
+ print("c");
+ return 3;
+}
+
+[[accumulate]] float f() {
+ print("d");
+}
+
+void main() {
+ print(ftos(f()));
+}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+
+float sum3(float a, float b, float c)
+{
+ return a + b + c;
+}
+
+typedef float(float, float, float) op3func_t;
+var float(float a, float b, float c) f;
+op3func_t g;
+
+void main() {
+ f = sum3;
+ g = f;
+ print(ftos(g(1, 2, 3)), "\n"); // prints 6
+}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+void p() {
+ print("\n");
+}
+
+void pn(float n) = {
+ print(ftos(n), "\n");
+}
+
+// ======================================
+
+void v2v() { print(ftos(5)); }
+float v2f() { return 6; }
+void f2v(float x) { print(ftos(x)); }
+float f2f(float x) { return x; }
+
+void ret_v2v()() { return v2v; }
+void ret_v2f()() { return v2f; }
+void ret_f2v(float)() { return f2v; }
+void ret_f2f(float)() { return f2f; }
+
+float ret()() { return v2f; }
+float f(float)();// { return f2f; }
+
+//float()() xxx { return ret; }
+
+void() ret_v2f_2() { return v2f; }
+
+void main() {
+ void() local_v2v_1 = v2v;
+ void() local_v2v_2 = ret_v2v();
+
+ float() local_v2f_1 = v2f;
+ //float() local_v2f_2 = ret_v2f();
+
+ void(float) local_f2v_1 = f2v;
+ void(float) local_f2v_2 = ret_f2v();
+
+ float(float) local_f2f_1 = f2f;
+ //float(float) local_f2f_2 = ret_f2f();
+
+ pn(ret()());
+ pn(f()(666));
+ pn(f()(666));
+
+ ret_v2f_2()();
+}
--- /dev/null
+entity () spawn = #3;
+
+float TICK_LENGTH = 0.016;
+
+.float health;
+.float energy;
+
+void regenerate_resource(entity player, .float res, float dt) {
+ player.(res) += 0.5 * dt;
+}
+
+void main() {
+ entity player = spawn();
+ regenerate_resource(player, health, TICK_LENGTH);
+ regenerate_resource(player, energy, TICK_LENGTH);
+}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+void p() {
+ print("\n");
+}
+
+void pn(float n) {
+ print(ftos(n), "\n");
+}
+
+// ======================================
+
+float global_f;
+.float field_f;
+
+float global_af[5];
+//float[5] global_af_2; NOPE
+
+float(float) fn_f2f;
+float fn_f2f_2(float);
+float fn_f2f(float) { return 0; }
+float fn_f2f_2(float a) { return a; }
+
+.float() field_v2f_1;
+.float(void) field_v2f_2;
+.float(float) field_f2f;
+.float fn_f2pf(float);
+.float fn_f2pf(float) { return field_f; }
+
+float fn_f_f2f_2_f(float a, float(float wat) f2f) {
+ return f2f(a);
+}
+
+float fn_f_f2f_2_f_2(float a, float f2f(float wat)) {
+ return f2f(a);
+}
+
+typedef .float(float) Fn_f2pf;
+var Fn_f2pf var_fn_f2pf;
+//var .float(float) var_fn_f2pf_2;
+//.Fn_v2pf idk;
+//..float() idk2;
+//Fn_v2pf fn_v2pf() = { return field_f; }
+//.Fn_v2pf field_v2pf;
+
+typedef float(float) Fn_f2f;
+typedef float ty_f;
+typedef float ty_f5[5];
+
+var float(float) var_fn_f2f;
+
+float idk() { return 5; };
+float idk2()() { return idk; }
+float wtf(float, void) { return 6; }
+float wtf2()(float, void) { return wtf; }
+
+.float sanity;
+//.float(float) madness { return sanity; }
+void aaaaaa() {}
+.float(.float(float a) a()()()) cthulhu(.float a)(float, void, ...)(.float a(float))()()()() { return aaaaaa; }
+
+float unused;
+
+void main() {
+ //cthulhu(madness);
+
+ unused = 1;
+
+ global_f = 666;
+ global_af[4] = 10;
+ entity e = spawn();
+ e.field_f = 667;
+ //var_fn_f2pf_2 = fn_f2pf;
+ //var_fn_f2pf = fn_f2pf;
+ //e.field_v2pf = fn_v2pf;
+ //e.idk();
+ //idk = 6;
+ //idk2 = 7;
+
+ pn(global_f);
+ pn(e.field_f);
+ p();
+
+ pn(fn_f2f(1));
+ pn(fn_f2f_2(1));
+ p();
+
+ e.field_f2f = fn_f2f;
+ pn(e.field_f2f(2));
+ e.field_f2f = fn_f2f_2;
+ pn(e.field_f2f(2));
+ p();
+
+ pn(e.(fn_f2pf(3)));
+ p();
+
+ .float loc_field_f = fn_f2pf(3);
+ pn(e.loc_field_f);
+ pn(e.(loc_field_f));
+ p();
+
+ var_fn_f2f = fn_f2f_2;
+ pn(var_fn_f2f(4));
+ p();
+
+ pn(fn_f_f2f_2_f(5, fn_f2f_2));
+ pn(fn_f_f2f_2_f_2(5, fn_f2f_2));
+ p();
+
+ float x, y = 1;
+ //pn(x);
+ pn(y);
+}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+void main() {
+ string x;
+ string n = nil;
+ print(ftos(x == n));
+ print(ftos(x == ""));
+ print(ftos("" == n));
+}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+void main() {}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+void p() {
+ print("\n");
+}
+
+void pn(float n) {
+ print(ftos(n), "\n");
+}
+
+// ======================================
+
+.float x, y;
+
+const .float mine, his = mine;
+
+void pe(entity e) {
+ print(ftos(e.x), ftos(e.y), ftos(e.mine), ftos(e.his), "\n");
+}
+
+void main() {
+ entity e = spawn();
+
+ pe(e);
+ .float x_bak = x;
+ e.x = 1;
+ e.y = 2;
+ e.mine = 3;
+ pn(e.x_bak);
+ pe(e);
+ x = y;
+ .float pf = mine;
+ pn(e.pf);
+ pe(e);
+ e.his = 4;
+ x = x_bak;
+ pn(e.pf);
+ pe(e);
+}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+void p() {
+ print("\n");
+}
+
+void pn(float n) {
+ print(ftos(n), "\n");
+}
+
+// ======================================
+
+float(float) sqrt1 = #13;
+float sqrt2(float) = #13;
+
+void main() {
+ pn(sqrt1(4));
+ pn(sqrt2(4));
+}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+void p() {
+ print("\n");
+}
+
+void pn(float n) {
+ print(ftos(n), "\n");
+}
+
+// ======================================
+
+//<graphitemaster> . always declares a field for all entities
+//<graphitemaster> if you want to assign something to it, it's done on a per-entity basis
+//<graphitemaster> .type fn_name(params) is an alias for .type(params) fn_name
+//<graphitemaster> if you want a field that is a function returning a field you want something like `.(.type(...)(params) name`
+//<graphitemaster> er, `.(.type(...))(params) name` I mean
+
+// actually:
+// `.type fn_name(params)` declares functions that return fields
+// `.type(params) fn_name` declare fields that are functions that return `type`
+
+float global_of_float;
+
+.float field_of_float;
+
+float(float f) fn_float_to_float_1;
+float(float f) fn_float_to_float_1 { return f; }
+float fn_float_to_float_2(float f);
+float fn_float_to_float_2(float f) { return f; }
+
+.float fn_float_to_field_of_float(float f);
+.float fn_float_to_field_of_float(float f) { return field_of_float; }
+//.float(float f) fn_float_to_field_of_float_bad { return field_of_float; }
+.float(float f) field_of_fn_float_to_float;
+
+.float(float f1) fn_float_to_field_of_fn_float_to_float(float f2);
+.float(float f1) fn_float_to_field_of_fn_float_to_float(float f2) { return field_of_fn_float_to_float; }
+
+var .float global_of_field_of_float;
+
+var float(float f) global_of_fn_float_to_float_1;
+var float global_of_fn_float_to_float_2(float f);
+
+var .float global_of_fn_float_to_field_of_float(float f);
+
+var .float(float f) todo1;
+
+var .float(float f1) todo2(float f2);
+
+void main() {
+
+ entity e1 = spawn();
+
+ // globals
+
+ pn(fn_float_to_float_1(10));
+
+ e1.(fn_float_to_field_of_float(5)) = 100;
+ pn(e1.field_of_float);
+
+ e1.field_of_fn_float_to_float = fn_float_to_float_1;
+ pn(e1.field_of_fn_float_to_float(30));
+ e1.field_of_fn_float_to_float = fn_float_to_float_2;
+ pn(e1.field_of_fn_float_to_float(30));
+
+ //pn(e1.fn_float_to_field_of_fn_float_to_float(6)(66));
+ pn(e1.(fn_float_to_field_of_fn_float_to_float(6))(66));
+
+ global_of_field_of_float = field_of_float;
+ pn(e1.(global_of_field_of_float));
+
+ global_of_fn_float_to_float_1 = fn_float_to_float_2;
+ pn(global_of_fn_float_to_float_1(-10));
+
+ global_of_fn_float_to_float_2 = fn_float_to_float_1;
+ pn(global_of_fn_float_to_float_2(-10));
+
+ global_of_fn_float_to_field_of_float = fn_float_to_field_of_float;
+ pn(e1.(global_of_fn_float_to_field_of_float(-5)));
+
+ p();
+
+ // locals
+
+ .float local_of_field_of_float = field_of_float;
+ pn(e1.(local_of_field_of_float));
+
+ float(float f) local_of_fn_float_to_float_1;
+ local_of_fn_float_to_float_1 = fn_float_to_float_1;
+ pn(local_of_fn_float_to_float_1(11));
+ local_of_fn_float_to_float_1 = fn_float_to_float_2;
+ pn(local_of_fn_float_to_float_1(11));
+
+ float local_of_fn_float_to_float_2(float f);
+ local_of_fn_float_to_float_2 = fn_float_to_float_1;
+ pn(local_of_fn_float_to_float_2(12));
+ local_of_fn_float_to_float_2 = local_of_fn_float_to_float_1;
+ pn(local_of_fn_float_to_float_2(12));
+
+ .float local_of_fn_float_to_field_of_float(float f);
+ //local_of_fn_float_to_field_of_float = field_of_fn_float_to_float; // cannot assign .float(float) to .float(float)
+ local_of_fn_float_to_field_of_float = fn_float_to_field_of_float;
+ pn(e1.(local_of_fn_float_to_field_of_float(7)));
+
+ .float(float f) local_of_field_of_fn_float_to_float;
+ local_of_field_of_fn_float_to_float = field_of_fn_float_to_float;
+ //local_of_field_of_fn_float_to_float = fn_float_to_field_of_float; // cannot assign .float(float) to .float(float)
+ pn(e1.local_of_field_of_fn_float_to_float(13));
+
+ .float(float f1) local_of_fn_float_to_field_of_fn_float_to_float(float f2);
+ local_of_fn_float_to_field_of_fn_float_to_float = fn_float_to_field_of_fn_float_to_float;
+ pn(e1.(local_of_fn_float_to_field_of_fn_float_to_float(8))(14));
+}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+void p() {
+ print("\n");
+}
+
+void pn(float n) {
+ print(ftos(n), "\n");
+}
+
+// ======================================
+
+void f(float x) {
+ if (x == 0) return;
+
+ float xs[2];
+ xs[0] = x;
+ pn(xs[0]);
+ f(x - 1);
+ pn(xs[0]);
+}
+
+void main() {
+ f(3);
+}
--- /dev/null
+void (string str, ...) print = #1;
+string (float val) ftos = #2;
+entity () spawn = #3;
+void (entity ent) kill = #4;
+string (vector vec) vtos = #5;
+void (string str) error = #6;
+float (vector vec) vlen = #7;
+string (entity ent) etos = #8;
+float (string str) stof = #9;
+string (...) strcat = #10;
+float (string str1, string str2) strcmp = #11;
+vector (vector vec) normalize = #12;
+float (float val) sqrt = #13;
+float (float val) floor = #14;
+float (float val1, float val2) pow = #15;
+vector (string str) stov = #16;
+
+void p() {
+ print("\n");
+}
+
+void pn(float n) {
+ print(ftos(n), "\n");
+}
+
+// ======================================
+
+// note: the comments are from wiki, they're wrong
+// https://gitlab.com/xonotic/xonotic/wikis/NewQC
+
+float global; // global variable
+//float .foo; // entity field
+
+.float field; // fieldpointer
+//.float .foo; // entity field of type fieldpointer
+
+float function_void_to_float(void) { return 5; } // function
+//float foo*(void); // function pointer
+
+.float foo(void) { return field; } // function returning a fieldpointer .float
+//.float foo*(void); // function pointer, returning a fieldpointer .float
+
+//float .foo(void); // entity field of type function returning float
+//.float .foo(void); // entity field of type function returning fieldpointer
+
+void main() {
+ foo();
+}