|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
General Java Scriptic: Doing the Processes in Java
Scriptic: Doing the Processes in Java
By: Andre Van Delft
Feb. 1, 1996 12:00 AM
Introduction Java is a big step forward in programming, but like many other languages, it falls short in two areas: user interaction and parallelism. This is because it mainly supports the traditional paradigm of sequential actions controlled by deterministic constructs. Scriptic tries to improve on Java by adding explicit support for parallelism and non-deterministic choice.
Example: The Game of Life Earlier we found a fine color Life applet somewhere on the World Wide Web. It had the same keyboard interface. The author commented on a few problems. A previous version would hang if the space bar was pressed while the program was already in the evolutions mode. When even this simple user interface leads to problems, it is apparent that building user interfaces is error-prone. Let's see how the user interface of the color applet had been implemented; then we'll look at the Scriptic alternative.
Java Version
public void start() {(new GenerationThread(this)).start();}
public boolean keyDown(Event e, int key) {
class GenerationThread extends Thread { The communication between the two threads by means of boolean variables is rather cumbersome, and prone to errors like the one the author encountered. In general, if you look at the source code of an interactive Java program, it is not directly clear what parts are executed inside handleEvent' functions (including keyDown'), and what parts are in different threads. Communication between threads using wait() and notify() functions may even be harder. The Life applet is still small; bigger ones would need more such boolean variables or wait/notify calls, leading to more potential problems. This is where Scriptic may help with better support for user input and parallelism.
Scriptic Version clear = key(c'!); {doClear()} key(c'!) means that the c' key has been pressed. The subsequent action {doClear()} is a Java code fragment enclosed in braces; it takes care of clearing the cells.
Likewise the script randomize:
changes = while(true); Another use of the ||' operator is in the main script which is named live'. It is launched in its own thread from the applet's start' function. Life's live' script is an or-parallel composition of the eternal changes' script and exit'. exit' waits for the user to press x' to terminate the program in case the Life program is run as a frame rather than an applet:
exit = if (!(frame instanceof Applet)) key(x'!)
multiSteps = key(\n'!); ({*while(true) key (int k) = {.Event.KEY_PRESS: k=event.key} An alternative for the earlier clear' script: suppose it needs as well to be controlled by a screen button and a menu item, apart from the c' button. Then the following would do: clear = ( key(c' !)
+ clearButton.action Finally a few words about iterations in Scriptic. You can use while' and for' constructs, but not just for sequential iterations; you may as well build parallel and alternative iterations. Scriptic has also a very special iteration symbol: ..' (ellipsis). This specifies an optional exit point in a loop. This kind of looping is also known from parser generators such as Yacc. It allows you to write very concise syntax descriptions, e.g., identList = (identifier; ..; comma); endOfInput This could well parse a comma-separated identifier list, such as "A,B,C". Rather than a boolean expression, the context determines whether the loop ends: the availability of a comma versus the end of input.
Implementation Then, in two months, Ari Schot created a totally new version of the preprocessor, which does a far better job; it contains also half a Java compiler, and has 800 Kb Java code in 140 classes. The virtual machine has about 320 Kb of Java source in eighty classes and interfaces. It takes care of activating scripts, executing Java code fragments, thread management etc. Its main data structure is an activation graph, rather than a call stack. The virtual machine system is far more complicated than the preprocessor; it is comparable to both an interpreter and an operating system. Java proved to be an excellent vehicle for implementing Scriptic. From existing C++ and Smalltalk knowledge, it is easy to learn. It is far less complicated than C++. Java makes it harder to make errors, especially with memory management. The threading support is only rudimentary but powerful. (For most applications I would recommend Scriptic, of course). The implementor's productivity may have been from two to five times as high as it may have been with C++, but this is a subjective conjecture. The virtual machine was mainly implemented in the early Java days (winterof 1995/96); only command-line utilities such as Sun's compiler and debugger were available. The command-line compiler was invoked on Windows 95 from the Programmer's File Editor. I did not use the debugger because I disliked its user interface, and it happened not to be necessary. Errors like null-references and illegal type casts resulted in clear run-time exceptions and were then easily spotted. As a whole, this simple and free development environment seemed to work about as nicely as Microsoft Visual C++ 1.5. Now with dedicated Java development environments around, things have even improved. The virtual machine runs pretty fast, since it does lots of list processing rather than array access. The Life example runs in the Scriptic version as fast as in a plain Java version. On the downside of this efficiency, the typical speed gain from Symantec's Jit compiler is only a factor 2. Much to our surprise, Scriptic works pretty well with the Abstract Windowing Toolkit. We expected a collision, since both systems seem to grab control. This makes us feel that the basic design of the AWT is good; the existing problems with the AWT are mainly a matter of implementation and solvable.
Availability
Roots Scriptic is based on the theory Process Algebra, developed in the eighties in The Netherlands. In short, Process Algebra studies processes as the kind of mathematical objects like numbers and booleans. It treats sequential and alternative operations as a kind of multiplication and addition, the main difference being that sequential composition is not commutative. Other forms of process composition such as parallelism can be expressed in terms of sequence and choice. This way Process Algebra can precisely define the meaning of parallel programs; it shows how to computate' the behavior of parallel programs. That is what the Scriptic Virtual Machine does. Reader Feedback: Page 1 of 1
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News |
|||||||||||||||||||||||||||||||||||||||||||||||||