next up previous contents
Next: Tutorial Formatting Up: Command-Line Compiler Previous: Project Files   Contents

Building an Application

To compile project P.urp, simply run

urweb P
The output executable is a standalone web server. Run it with the command-line argument -h to see which options it takes. If the project file lists a database, the web server will attempt to connect to that database on startup. See Section 10 for an explanation of the URI mapping convention, which determines how each page of your application may be accessed via URLs.

To time how long the different compiler phases run, without generating an executable, run

urweb -timing P

To stop the compilation process after type-checking, run

urweb -tc P
It is often worthwhile to run urweb in this mode, because later phases of compilation can take significantly longer than type-checking alone, and the type checker catches many errors that would traditionally be found through debugging a running application.

A related option is -dumpTypes, which, as long as parsing succeeds, outputs to stdout a summary of the kinds of all identifiers declared with con and the types of all identifiers declared with val or val rec. This information is dumped even if there are errors during type inference. Compiler error messages go to stderr, not stdout, so it is easy to distinguish the two kinds of output programmatically. A refined version of this option is -dumpTypesOnError, which only has an effect when there are compilation errors.

It may be useful to combine another option -unifyMore with -dumpTypes. Ur/Web type inference proceeds in a series of stages, where the first is standard Hindley-Milner type inference as in ML, and the later phases add more complex aspects. By default, an error detected in one phase cuts off the execution of later phases. However, the later phases might still determine more values of unification variables. These value choices might be ``misguided,'' since earlier phases have not come up with reasonable types at a coarser detail level; but the unification decisions may still be useful for debugging and program understanding. So, if a run with -dumpTypes leaves unification variables undetermined in positions where you would like to see best-effort guesses instead, consider -unifyMore. Note that -unifyMore has no effect when type inference succeeds fully, but it may lead to many more error messages when inference fails.

To output information relevant to CSS stylesheets (and not finish regular compilation), run

urweb -css P
The first output line is a list of categories of CSS properties that would be worth setting on the document body. The remaining lines are space-separated pairs of CSS class names and categories of properties that would be worth setting for that class. The category codes are divided into two varieties. Codes that reveal properties of a tag or its (recursive) children are B for block-level elements, C for table captions, D for table cells, L for lists, and T for tables. Codes that reveal properties of the precise tag that uses a class are b for block-level elements, t for tables, d for table cells, - for table rows, H for the possibility to set a height, N for non-replaced inline-level elements, R for replaced inline elements, and W for the possibility to set a width.

Ur/Web type inference can take a significant amount of time, so it can be helpful to cache type-inferred versions of source files. This mode can be activated by running

urweb daemon start
Further urweb invocations in the same working directory will send requests to a background daemon process that reuses type inference results whenever possible, tracking source file dependencies and modification times. To stop the background daemon, run
urweb daemon stop
Communication happens via a UNIX domain socket in file .urweb_daemon in the working directory.


Some other command-line parameters are accepted:

There is an additional convenience method for invoking urweb. If the main argument is FOO, and FOO.ur exists but FOO.urp doesn't, then the invocation is interpreted as if called on a .urp file containing FOO as its only main entry, with an additional rewrite all FOO/* directive.


next up previous contents
Next: Tutorial Formatting Up: Command-Line Compiler Previous: Project Files   Contents
2014-07-14