Path: news.daimi.aau.dk!not-for-mail From: Erik Ernst Newsgroups: comp.lang.beta Subject: Re: Loki Paper 1: Overview Date: 19 Mar 1998 17:38:54 +0100 Organization: DAIMI, Computer Science Dept. of Aarhus Univ. Lines: 111 Message-ID: References: <199803190903.KAA17185@noatun.mjolner.dk> NNTP-Posting-Host: fraxinus.daimi.aau.dk X-Newsreader: Gnus v5.3/Emacs 19.34 Xref: news.daimi.aau.dk comp.lang.beta:11468 John Cowan writes: > > The Loki Papers is a series of documents which I will be posting off and > on to comp.lang.beta in the hope of stirring some interest. The purpose > of the Loki Project, which these papers document, is to provide a > compiler and support classes for translating Beta into the Java > language. Although Beta and Java are very different languages in syntax > as well as semantics, Java is flexible enough that compiling Beta into > it does not seem an utterly impossible proposition. You intend to translate to Java or to JVM byte-code? Anyway, I think that the type verification phase will demand equivalent casts in byte code as the ones needed for a BETA-source to (correct) Java-source translation. Do you plan to use fixed classes in place of virtual classes and then insert downcasts wherever the virtual class (according to the BETA static analysis) is known to be more specialized? That's like: p: (# v:< object; x: @v #); q: p(# v::< (# y: @integer #) do 1->x.y #) --> class v_0 = Object; class p = { public x: v_0; }; class v_1 = v_0 { public y: integer; }; class q = p { public void theDoPart() { ((v_1)x).y = 1; }; }; (Ermm, I really don't know Java syntax, so I'm not even trying to write correct Java, but I'm going to read that "The Java Language Specification" book any day now!! Hope the message comes through anyway ;^) This works for some things, only. Now consider (# p: (# v:< (# exit 1 #) exit v #); q: p(# v::< (# exit 2 #) #); i,j: @integer; do &p->i; &q->(i,j); #) You cannot annotate the occurrence of `v' in the exit list of `p' with a cast, because the statically known type of the exited value differs depending on _the static knowledge about the enclosing p/q/... object at the point of the evaluation_. One solution seems to be to insert the cast at the place of the evaluation (semi-ignoring the multiple-return-value problem): (i,j) = (some_packet_of_two_integers)((new q).theExitpart); but the point of the evaluation can be arbitrarily "far away," (# a_0: (# exit (a_1,a_2) #); a_1: (# exit (a_2,a_3) #); ... a_(k-1): (# exit (a_k,'whatever') #); a_k: (# exit q #) do (* the following presumably translates to some rather involved * "unpacking" code which needs to "remember" that the deeply * buried packet for 'q' must have a cast *) a_0 -> ... #) So, we cannot just insert a cast at the "point of original reference" in that exit-list of `p', but instead have to insert the cast into all sorts of expressions that depend on it. That does not necessarily make the translation impossible, but certainly harder.. Moreover, it's probably necessary to reconstruct the entire BETA static analysis to know where to insert casts, and what casts to insert. > I do not have the resources to actually write and deliver Loki to the > astonished world. I wish I did. Ah, that's a pity. But one step is better than none! It is a really interesting project.. > [..] > The Beta fragment architecture is mostly abstracted away by the > compiler. It is not yet clear to me whether it should attempt to do > more than syntax and static semantics checking when compiling less > than a complete program. Generation of Java code may need to wait until > all the Beta code is available. The fragment visibility model, at any > rate, is incompatible with Java's visibility model: all Beta classes > and members would be declared "public" in the Java code. Of course, the Mjolner compiler generates native machine code directly from code fragments, and a complete program is assembled by a standard linker. That's the reason why supporting yet another non-terminal (e.g. `MainPart', to supplement `DoPart', `Descriptor', and `Attributes') is not trivial. But the entire fragment language could be ignored to get started, because no BETA program "essentially" needs it. Just transform the program using cut-n-paste until it's all in one file and all SLOTs are gone. (Well, there are some name clash issues, too, but it almost works like that :-) cheers, -- Erik Ernst eernst@daimi.aau.dk Computer Science Department of Aarhus University, Denmark