#!/usr/local/bin/rune -x # # Demonstrate global elements in classes, procedures, and compound # types. # limport "sys"; import "stdio"; alias stdio.File *stdout = stdio.stdout; class Test { int a = 2; global int b = 6; global const int c1 = 1; global const int c2 = 2; global const int c3 = 3; int c; myint_t z; } typedef int myint_t = 99; class Fx1 { # 4 + (4 pad) + 40 + 8 int f1data; Fx2 *f2ptr; Fx2 f2obj; } class Fx2 { # 8 bytes int f2data; Fx3 f3obj; } class Fx3 { int f3data; } # note that ( 7 ) is not compound, but Rune will always cast a non-compound # expression to compound in the resolver if the resolver needs a compound # expression. (7) initializes the 'y', not the 'x', because 'x' is a # global field within the object and thus out-of-band (even though the # object itself is being declared as a global, multiple instances of the # object will share 'x'). # (global int x = 2, int y = 6) A = ( 7 ); myint_t B = 8; myint_t C; Fx2 fx2; Fx1 fx1 = ( 1, &fx2, ( 2, ( 3 ) ) ); Fx1 fxx = ( puref1(1), purefx2(), ( puref1(2), ( puref1(3) ) ) ); int X; int *Y = &X; const int xsize = 8192; const int xmask = (xsize - 1); public int main(int ac, char **av) { Fs fs; int i; Test t1 = ( 3, 4 ); Test t2; Test t3; Test t4 = ( 8, 9, 10 ); void *v; myint_t x; fs.setfd(1); stdout->show("fx1 should be (1, 2, 3): ", fx1.f1data, fx1.f2obj.f2data, fx1.f2obj.f3obj.f3data); stdout->show("sizeof(A) should be 4:", sizeof(A)); stdout->show("A.x should be 2:", A.x); stdout->show("A.y should be 7:", A.y); stdout->show("B should be 8:", B); stdout->show("C should be 99:", C); stdout->show("t1.a should be 3:", t1.a); stdout->show("t1.c should be 4:", t1.c); stdout->show("t2.a should be 2:", t2.a); stdout->show("t3.z should be 99:", t3.z); stdout->show("t4.z should be 10:", t4.z); stdout->show("xsize should be 8192:", xsize); stdout->show("xmask should be 8191:", xmask); stdout->show("t4.z should be 10:", t4.z); fs.write("\n", 1); return(0); } pure int puref1(int n) { return n; } pure Fx2 * purefx2() { return &fx2; }