Sean Hinchee <
henes...@gmail.com> writes:
> One other thing maybe worth voicing here, I wasn't sure if it was
> possible, but I was never able to get a polymorphic function on top of
> a polymorphic ADT (method?) declared.
...
> # Skip white space
> Rd[T].ws(rd: self ref Rd[T]): int {
> while(isspace(c := rd.t.getb()))
> {}
>
> return c;
> }
This will work (and it works in generics.b) as long as it's in the same
module. If you try importing the polymorphic ADT (Rd, in this case)
from another module, things start to melt-down. (Try it.)
The odd thing is that it WORKS on the first invocation, where the
argument is a pick ADT, but fails in the second invocation, where the
argument is a polymorthic ADT.
> I wondered if the polymorphism features of the language require a module to
> be loaded that support them.
Well, the obvious soulution would be to specify from which module
variable to import the fromstring function (method), something like:
putval("345", valref->bar);
But the compiler objects to such an attempt to module-qualify the
variable, and complains that bar isn't a member of ValRef (which is
correct). I would THINK that bar would get its implementation from Val,
which is specifically imported from ValRef at the top of storer.b. I
can't find anyplace in Limbo's syntax that allows me to provide any
additional module qualification to appease the compiler. :(
> Running disdump on them didn't provide any clues.
I ran wm/deb on the code, and discovered that it was failing where
Val[ValT].fromstring calls ValT.fromstring, here:
Val[ValT].fromstring(n: self ref Val[ValT], strval: string): ref Val[ValT] {
if (n.vref != nil) return ref Val[ValT](n.vref.fromstring(strval));
else return nil;
}
It looks like the Limbo compiler has some trouble figuring out which
implementation module is associated with the ADT data member vref. I
think I've stumbled upon a bug in the compiler, here. I tried
simplifying the code to see if I could isolate the problem (see the
other attachment I posted, kicker.b) but the limbo compiler can't even
compile it. The compiler dies with "Limbo":dereference of nil. So, it
looks like there are some cases (i.e., this one) which the compiler
isn't handling correctly.
Unfortunately, debugging the compiler is a bit beyond me. The code is a
bit ...cryptic, and the principles of its internal operation don't
appear to be documented anywhere. I'd have to spend a lot of time
studying the compiler to figure out where the problem is. I'm hoping
someone on this list with a better understanding of the compiler's
internals will be able to identify what's broken.