[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Feb 1 10:14:55 1998 
Subject:pop11 to Java translator 
From:Jonathan L Cunningham 
Volume-ID:980201.02 

This started off as a P.S. to my other post, but got too long, so I've
started a new thread :-).


For my own amusement I am currently writing a translator to
convert a subset of CLOS/Common Lisp to C++/Java. (Yes, both, they are
similar enough syntactically that I'm doing both at the same time, with
the output language determined by a boolean flag.) Behaviour will be
unpredictable outside that subset [e.g. a CLOS class using multiple
inheritance will be translated into C++ with multiple inheritance,
but into a Java class that inherits from one parent, and "implements"
the interface of the other parents - so it will compile, but is
unlikely to run correctly. Similar problems for multi-methods in both
C++ and Java.]

I have no (immediate) intention that the translation should be
efficient, merely that it should run correctly (as long as it
uses the appropriate subset of the source langauge). (It's just an
interesting way to (a) convert my existing private CLOS libraries,
and (b) get a _thorough_ knowledge of Java.)

It would be fairly easy (bordering on trivial) to extend it to also
do a fair subset of pop11*. The bulk of the work (for either Lisp
or pop11) is in writing the run-time library (i.e. all the "built-in",
functions) but most of the necessary code already exists in the
usual Java and C++ libraries (I haven't decided what approach to take
to GC in C++ yet, but it is not a problem for Java).

  *I'll probably simplify/rationalise the language a bit, so maybe
   it would be better to call it pop98 (optimistically) or pop99
   (looks prettier, but is probably pessimistic (i think)).

The approach would be to define a "standard" subset of pop11, and
generate a parse tree, (as nested lists) which would be handled
almost identically to the Lisp translation. I have no intention of
"compiling" the pop11 to pop VM. [A Pop VM to Java decompiler, or
a Pop VM to Java VM translator would both be interesting projects,
and would be better from a serious software engineering POV, but
would be more work and are not what I am currently doing. Porting the
poplog VM to the Java VM would instantly make Poplog available on
Windows 95, Windows NT and the Macintosh, but would be a big job.]

My target is to be able to write an applet in pop11, run it
through the translator (which will end up as a stand-alone Java
program - I will certainly test it on itself :-), and then be able
to use the resulting java applet in a web page.

(I'm currently using a compiler** which accepts "plug-ins", so I
should be able to use the translator as a plug-in. This would give
me a combined pop11, lisp, C++, Java, etc.* IDE (integrated development
environment), in which I could edit syntax-coloured pop11 source code,
and compile and run it with a single mouse-click. Or build a
stand-alone application. Maybe I should set up in competition to
poplog :-).

   * The "etc." is (yukk) Pascal. :-)

   ** Alright then, it's the Metrowerks compiler, which runs on MacOS,
   Win95 or NT, and as well as targeting them, also targets various
   other things, such as BeOS, the PlayStation Game Console etc. But
   don't yet take this as a recommendation -- I haven't been using it
   long enough yet to form an opinion, although I used an earlier
   release and my initial reaction to this release is still favourable.

I would be interesting in any suggestions about what subset of pop11
to aim for, if anyone is interested in telling me, e.g.
   define, lvars, for*, repeat, while, until, if, unless,
   procedure, <strings>, <words>, <numbers>, <characters>,
   <lists>, <vectors>, [], <booleans>, readline(), matches,
   valof(), catch, throw, lookup(), present() ...

   *But only the simple cases, i.e. 'for <var> in <list> do ...'
    and 'for <var> from ...'

What else?

I can't remember the syntax of objectclass, not having used it enough.
Anyone got a specification of it (grammer and informal semantics)?
I suppose I could download the REF file from somewhere?

What about threads? It would be possible to implement the behaviour
or poplog "processes" (actually implemented as co-routines) by
using java threads. I could make _runproc_ cause the calling
thread to block until control was transferred back to it. Or would
it be better to allow the threads to run in parallel? In which case
it would not be easy to test the code before translation in any
other pop environment. (AFAIK, the JVM spec does not *require*
that threads execute in parallel, precisely so that such a simple
scheduling algorithm (i.e. run until blocked, instead of pre-emptive
multi-tasking) would be conformant. But it would *seem* like a bug
to most Java programmers.)

Are there any plans to extend poplog with threads (perhaps by adding
an extra argument to the existing process procedures?). I believe
that most operating systems now support threads (lightweight
processes).

It's not strictly necessary, but anything (on a Web page) which does
a reasonable amount of computation ought to spawn a new thread and
return control to the browser. And since what I'm aiming for is
likely to be a dialect of pop, with some significant simplifications,
maybe 100% backward compatibility is not necessary? (I.e., if the
behaviour is the same on simple programs, but different if you do
anything too sophisticated, that should be ok. I think.)

Comments?

Jonathan


-- 
Home: jlc@sofluc.demon.co.uk |
Work: jlc@bmtech.co.uk       |