Array of struct

7 views
Skip to first unread message

bak...@gmail.com

unread,
Jan 17, 2009, 12:21:30 PM1/17/09
to Whiteoak
Hi,

Is it possible?

The following code dies on me (WO 2.1):

public class Main {

public static class C {
public int m(int a) {
return a + 1;
};
}

public static class B {
public int m(int a) {
return a - 1;
};
}

public static struct A {
public int m(int a);
}

public static void main(String args[]) {
A[] a = new A[2];
a[0] = new C();
a[1] = new B();
}
}


P.S.

Is there a full manual for the language (besides the paper by Itai and
Yogi)?

imaman

unread,
Jan 18, 2009, 1:38:55 AM1/18/09
to Whiteoak
Hi,

No, arrays of structs cannot be supported. The runtime type check that
takes place whenever a value is inserted into an array is hard-wired
into the JVM. Thus, support for such arrays will require changing the
JVM which is against Whiteoak's philosophy. The next build of Whiteoak
should include a specific check that guards against the declaration of
such arrays.

Currently, there is no language spec. document. I hope to finish
writing one within a few months.

-Itay

Itay Maman
http://javadots.blogspot.com

bak...@gmail.com

unread,
Jan 20, 2009, 5:45:02 PM1/20/09
to Whiteoak
Thanks for the quick reply.
More questions:

What's wrong with this code:

public class Main {
public static class A {
public void foo() {
System.out.println("A");
}
};

public static struct S = A;

public static void main(String args[]) {
S s = new A();
s.foo();
}
}


Also, I noticed that the Eclipse plug-in's editor is not treating
single line comments (in fact other comments too).
Since (after some code checking) i see that the problem is in a
Whiteoak's internal class, I'm thinking that it's worth mentioning.

In "TokenExtractorScanner" class ("TokenExtractor.java") there's an
overloading of processComment method. This is done (correct me if I'm
wrong)
under the assumption that this method will be called when a comment
was detected. Actually, this method will be invoked only when an
ENTIRE
comment was detected.

This means that for a buffer containing only a comment -
processComment will not be called. I'm guessing that when processing
entire files this will
not be noticed but this is quickly pops up in the editor.

P.S.

Whiteoak looks great. Keep on the good job.


On Jan 18, 8:38 am, imaman <itay.ma...@gmail.com> wrote:
> Hi,
>
> No, arrays of structs cannot be supported. The runtime type check that
> takes place whenever a value is inserted into an array is hard-wired
> into the JVM. Thus, support for such arrays will require changing the
> JVM which is against Whiteoak's philosophy. The next build of Whiteoak
> should include a specific check that guards against the declaration of
> such arrays.
>
> Currently, there is no language spec. document. I hope to finish
> writing one within a few months.
>
> -Itay
>
> Itay Mamanhttp://javadots.blogspot.com

imaman

unread,
Jan 22, 2009, 9:42:38 AM1/22/09
to Whiteoak
Hi,

The first issue is due to a bug in the Whiteoak compiler
(specifically, in the part that extracts a structural type from a
nominal one).
I expect this to be fixed within a few weeks. Anyway, you can
workaround this, at the expense of additional key strokes,
by specifying S's methods explicitly.

The second issue you mention is in the Eclipse plugin. The plugin
reuses much of code of the Java plugins. However, the Java
plugins where not designed for reuse in the context of implementing
support for other languages (for example, many of the Java stuff is
implemented
in classes from "internal" packages which may change without notice at
the next release of Eclipse). Thus, providing full support
for Whiteoak requires a significant effort, which is beyond my
abilities at the moment. Of course, I would be glad if someone from
the open source community will pick this challenge.

Thanks for the compliment.
-Itay
Reply all
Reply to author
Forward
0 new messages