#!/usr/local/bin/rune -x # # Demonstrate the use of lvalue scope. lvalue scope may be applied # to individual procedural arguments or to the return value. It # causes the caller to pass the object by reference instead of by # value, allowing the procedure to modify the contents of the # object. # # This feature is most often used when implementing operators that # require lvalues, such as "++" and "&=", but it can be used to # great effect with normal procedures as well. import "sys"; import ; class Fubar { int x; int y; heap lvalue int z; Fubar *link; method void test1() { this.x = 1; } method Fubar * test2() { return(&this); } method int test3() { return this.test4() + 1; } method int test4() { return this.y + 2; } } Fubar *g; Fubar gg; int main(int ac, char **av) { unlocked Fubar *a; Fubar **aa; Fubar *b; Fubar c; int x; (Fubar *xx, Fubar *yy) cc; unlocked int *xp; int **xpp; cc.xx = a; cc.yy = a; a = b; g = ≫ a.new(); aa = &a; (*aa).new(); a->x = 1; a->x = 2; a->x = 3; a->test1(); b = a->test2(); b = g->test2(); xp = &x; xpp = &xp; *xpp = xp; # clearing *xpp (i.e. contents of xp) before assignment XXX *xpp = xp; **xpp = 45; **xpp = 46; **xpp = 47; b.new(); b->x = 4; b->x = 5; b->x = 6; a->test3(); b->link.new(); # if (a->y < b->y) # x = 7; # else # x = 8; # if (c.z < c.z) # x = 9; # else # x = 10; } int * xfubar(int *z) { return z; }