CIS 461/561 Fall 2002
Tour of the Mawl Compiler
Mawl
Mawl is a domain specific language for programming web services.
It was developed several years ago in the (now defunct) Software
Production Research Department at Bell Labs. After an initial
prototype of the language was created, I implemented a C++ object
oriented compiler for Mawl and pushed the Mawl language itself
toward a more C/C++/Java like syntax. This version of the Mawl
compiler can serve as a useful example for understanding general
compiler architecture.
Overview of the Mawl Language
The original Bell Labs website on Mawl can be found
here.
The basic thrust of Mawl is that it separates the service programming
logic of a web application from the design layout of the web pages
which constitute the user interface. The view of a Mawl program is that
it is a single program containing the logic and control flow for a web based service.
(Think of a web service such as a shopping basket, where the user begins the
service, navigates through many pages, entering various data, and eventually
reaches the end of the service completing a purchase. On the server side, the
most cohesive view would be that this look like a single program that was
started, followed various logic paths according to user actions, and
eventually terminates.)
The interaction with the user is by serving up forms and obtaining input
when the forms are submitted. However, since HTTP is stateless, this presents
a problem for the service logic - interactions with the user appear to be
disconnected events and any data continuity must be explicitly arranged for
by the service logic (e.g., the use of cookies for providing handles to
stored service program state information).
Mawl addresses the issue at the programming language level by providing
strict type checked interfaces to the user and hiding all the details
necessary to give the appearance of a seamless single executable program
on the server side. Language constructs are provided to serve up a form to
the user (a form put) and arrangements are made for the process to continue
at that point when the form is submitted. Mawl makes this programming
activity look like a simple method call to put a form to the user and
get as a return value the data entered by the user and submitted. All
messy details of how to restore the program state to the right place when
the form is submitted are hidden.
Mawl also has the concept of a service session, and resolves contention for
data common to all sessions of the same service.
Additionally, Mawl views the forms as an opportunity for performing static
type checking. That is, a form in Mawl corresponds to a template of HTML that
is to be populated with values from the Mawl service logic. Likewise, a
form specifies the type of data expected to be filled in by the user and
returned to the Mawl service logic. The Mawl compiler can perform static
type checking on the form input (values to populate the form) and form
output (data entered by the user and submitted). Moreover, the service
logic sees forms essentially as method signatures, so the actual HTML
design of the form is completely separate from the service logic.
Documents
The Mawl Quick Reference gives a definition
of the Mawl language. Examples and explanation of Mawl programs can
be found in the Mawl Tutorial.
Information about the compiler implementation can be found in a set
of old slides.
Examples of Mawl programs can be found in the Mawl Zoo.
Design of the Mawl Compiler
The Mawl compiler design is fundamentally an object oriented design
in C++.
Yacc and lex are used to generate the parser for the compiler of the
Mawl language as well as generating a compiler for the HTML templates
(MHTML files) used by a Mawl service. (MHTML is a small extension of
HTML and essentially constitutes a mini language within the Mawl language.)
The source for the Mawl compiler is found here.
Mawl Compiler Code Generation
This is a simple example of a mawl program and the C++ code generated
by the compiler to implement the program:
Note that in the generated C++, each session in the Mawl source gives rise to
a corresponding Sesssion class, and there is a special global Session class
that serves as a common base.
The Session class lays out the stack frame for the Mawl session with
methods to set up the variables and registers. The execution of the session
is done by the Step method, which steps through the execution beginning
with the passed program counter. This program counter allows execution
to resume after an interaction with a user, i.e., execution terminates
with a form sent to the user, and variable state along with the program
counter is saved, allowing execution to be restarted at the right place
and with the right data once the user submits the form.
Here is an example with more complicated data structures, multiple
sessions, and subsessions:
Note in this example that the typedef in Mawl gives rise to a typedef in C++.
This allows any C++ code in the Mawl source file to know about the Mawl
data types. In particular, Mawl code can call C++ functions, passing
the Mawl data.
datkins@cs.uoregon.edu