namespace; include rt, run; struct point { int x, y; }; struct rect { point a, b; int tag; }; struct list { int len; T* items; }; struct node { int v; node* next; }; type num = int; int counter = 5; int[4] squares; point origin; int area(rect* r) { return (r.b.x - r.a.x) * (r.b.y - r.a.y); } list*.u mklist(int cap) { list* l = rt.new(list); l.len = 0; l.items = rt.new(T, cap) as T*; return u*l; } T first(list* l) { return l.items[0]; } int sum(node* n) { int s = 0; while (n) { s += n.v; n = n.next; } return s; } fn main() { rect r; r.a.x = 1; r.a.y = 2; r.b.x = 4; r.b.y = 6; rt.put_n(area(&r)); rt.put_c(' '); rt.put_n(sizeof(rect)); rt.put_c(' '); rt.put_n(sizeof(point)); rt.put_c(' '); rt.put_n(sizeof(rect[3])); rt.put_c(' '); let p = rt.new(point); // let infers *point p.x = 7; p->y = 8; rt.put_n(p.x * p.y); rt.put_c(' '); rt.free(d*p); list* l = mklist(4); l.items[0] = 42; l.len = 1; rt.put_n(first(l)); rt.put_c(' '); rt.free(d*l); node* a = rt.new(node), b = rt.new(node); a.v = 3; b.v = 4; a.next = b; rt.put_n(sum(a)); rt.put_c(' '); rt.free(d*a); // b went with it: a.next = b made a its owner point[3] pts; pts[2].y = 9; rt.put_n(pts[2].y + counter); rt.put_c(' '); num k = 3; rt.put_n(k); rt.put_c(10); // reflection run.tprint(typeof(r)); rt.put_c(' '); run.tprint(typeof(&r)); rt.put_c(' '); run.tprint(typeof(l)); rt.put_c(' '); run.tprint(run.sigof(mklist)); rt.put_c(' '); run.tprint(run.sigof(first)); rt.put_c(' '); run.tprint(run.sigofs("free")); rt.put_c(10); let t = typeof(r), i = 0; while (i < run.tnfields(t)) { rt.put_s(run.tfname(t, i)); rt.put_c(':'); run.tprint(run.tftype(t, i)); rt.put_c('@'); rt.put_n(run.tfoff(t, i)); rt.put_c(' '); i++; } rt.put_c(10); point* q = rt.new(point); run.tprint(rt.typeof_obj(q)); rt.put_c(' '); rt.put_n(rt.typeof_obj(q) == typeof(point)); rt.put_c(' '); rt.put_n(run.tkind(rt.typeof_obj(q)) == run.TY_STRUCT); rt.free(d*q); rt.put_c(10); return 0; }