# test recs containing rcaps containing arrays of ops

# also test troublesome rec in rcap:
# got segm fault from importing rec of cap of resource exporting an optype

resource ugh
   type rectype = rec (cap ugh c )
   optype simpleop ()
body ugh ()
   write ("resource `ugh' here")
end


resource r
    op o ()
    op p[4] (int)
    op q[7] (int)
body r ()
    import ugh
    type t = rec (int a, b; cap r c ; int d )
    t  v, a[3] 

    process pp  [ i = 1 to 4 ] {
	in p[i](n) -> write ("p", i, ":", n) ni
    }

    process qq [ i = lb(q) to ub(q) ] {
	in q[i](n) -> write ("q", i, ":", n) ni
    }

    proc o ()  {
	write ("o here")
    }

    a[1] = t (123, 456, noop, 789)
    a[2] = t (234, 567, myresource(), 890)
    a[3] = t (345, 678, null, 123)
    if (a[1].c ~= noop) { write ("rcap not null oops") }
    if (a[3].c ~= null) { write ("ooprcap not noop s") }
    if (a[1].c.o ~= noop) { write ("ocap not null oops") }
    if (a[2].c.o ~= o   ) { write ("oopocap not o s") }
    if (a[3].c.o ~= null) { write ("oopocap not noop s") }
    a[1].c.o ()
    a[2].c.o ()
    for [ i = 1 to 4 ] { a[2].c.p[i](101 * i) }
    for [ i = 1 to 7 ] { a[2].c.q[i](1001 * i) }
    for [ i = 1 to 3 ] { write (a[i].a, a[i].b, a[i].d) }

    create ugh ()
end
