comparison doc/manual.tex @ 1979:81bc76aa4acd

Merge in upstream changes.
author Patrick Hurst <phurst@mit.edu>
date Sat, 18 Jan 2014 18:26:24 -0500
parents 93f3e35a7967
children 0652f295e0fa
comparison
equal deleted inserted replaced
1978:c5143edaf3c7 1979:81bc76aa4acd
62 apt-get install mlton libssl-dev 62 apt-get install mlton libssl-dev
63 \end{verbatim} 63 \end{verbatim}
64 64
65 To build programs that access SQL databases, you also need one of these client libraries for supported backends. 65 To build programs that access SQL databases, you also need one of these client libraries for supported backends.
66 \begin{verbatim} 66 \begin{verbatim}
67 apt-get install libpq-dev libmysqlclient15-dev libsqlite3-dev 67 apt-get install libpq-dev libmysqlclient-dev libsqlite3-dev
68 \end{verbatim} 68 \end{verbatim}
69 69
70 It is also possible to access the modules of the Ur/Web compiler interactively, within Standard ML of New Jersey. To install the prerequisites in Debian testing: 70 It is also possible to access the modules of the Ur/Web compiler interactively, within Standard ML of New Jersey. To install the prerequisites in Debian testing:
71 \begin{verbatim} 71 \begin{verbatim}
72 apt-get install smlnj libsmlnj-smlnj ml-yacc ml-lpt 72 apt-get install smlnj libsmlnj-smlnj ml-yacc ml-lpt
75 To begin an interactive session with the Ur compiler modules, run \texttt{make smlnj}, and then, from within an \texttt{sml} session, run \texttt{CM.make "src/urweb.cm";}. The \texttt{Compiler} module is the main entry point. 75 To begin an interactive session with the Ur compiler modules, run \texttt{make smlnj}, and then, from within an \texttt{sml} session, run \texttt{CM.make "src/urweb.cm";}. The \texttt{Compiler} module is the main entry point.
76 76
77 To run an SQL-backed application with a backend besides SQLite, you will probably want to install one of these servers. 77 To run an SQL-backed application with a backend besides SQLite, you will probably want to install one of these servers.
78 78
79 \begin{verbatim} 79 \begin{verbatim}
80 apt-get install postgresql-8.4 mysql-server-5.1 80 apt-get install postgresql mysql-server
81 \end{verbatim} 81 \end{verbatim}
82 82
83 To use the Emacs mode, you must have a modern Emacs installed. We assume that you already know how to do this, if you're in the business of looking for an Emacs mode. The demo generation facility of the compiler will also call out to Emacs to syntax-highlight code, and that process depends on the \texttt{htmlize} module, which can be installed in Debian testing via: 83 To use the Emacs mode, you must have a modern Emacs installed. We assume that you already know how to do this, if you're in the business of looking for an Emacs mode. The demo generation facility of the compiler will also call out to Emacs to syntax-highlight code, and that process depends on the \texttt{htmlize} module, which can be installed in Debian testing via:
84 84
85 \begin{verbatim} 85 \begin{verbatim}
144 \item \texttt{database DBSTRING} sets the string to pass to libpq to open a database connection. 144 \item \texttt{database DBSTRING} sets the string to pass to libpq to open a database connection.
145 \item \texttt{debug} saves some intermediate C files, which is mostly useful to help in debugging the compiler itself. 145 \item \texttt{debug} saves some intermediate C files, which is mostly useful to help in debugging the compiler itself.
146 \item \texttt{effectful Module.ident} registers an FFI function or transaction as having side effects. The optimizer avoids removing, moving, or duplicating calls to such functions. This is the default behavior for \texttt{transaction}-based types. 146 \item \texttt{effectful Module.ident} registers an FFI function or transaction as having side effects. The optimizer avoids removing, moving, or duplicating calls to such functions. This is the default behavior for \texttt{transaction}-based types.
147 \item \texttt{exe FILENAME} sets the filename to which to write the output executable. The default for file \texttt{P.urp} is \texttt{P.exe}. 147 \item \texttt{exe FILENAME} sets the filename to which to write the output executable. The default for file \texttt{P.urp} is \texttt{P.exe}.
148 \item \texttt{ffi FILENAME} reads the file \texttt{FILENAME.urs} to determine the interface to a new FFI module. The name of the module is calculated from \texttt{FILENAME} in the same way as for normal source files. See the files \texttt{include/urweb/urweb\_cpp.h} and \texttt{src/c/urweb.c} for examples of C headers and implementations for FFI modules. In general, every type or value \texttt{Module.ident} becomes \texttt{uw\_Module\_ident} in C. 148 \item \texttt{ffi FILENAME} reads the file \texttt{FILENAME.urs} to determine the interface to a new FFI module. The name of the module is calculated from \texttt{FILENAME} in the same way as for normal source files. See the files \texttt{include/urweb/urweb\_cpp.h} and \texttt{src/c/urweb.c} for examples of C headers and implementations for FFI modules. In general, every type or value \texttt{Module.ident} becomes \texttt{uw\_Module\_ident} in C.
149 \item \texttt{html5} activates work-in-progress support for generating HTML5 instead of XHTML. For now, this option only affects the first few tokens on any page, which are always the same.
149 \item \texttt{include FILENAME} adds \texttt{FILENAME} to the list of files to be \texttt{\#include}d in C sources. This is most useful for interfacing with new FFI modules. 150 \item \texttt{include FILENAME} adds \texttt{FILENAME} to the list of files to be \texttt{\#include}d in C sources. This is most useful for interfacing with new FFI modules.
150 \item \texttt{jsFunc Module.ident=name} gives the JavaScript name of an FFI value. 151 \item \texttt{jsFunc Module.ident=name} gives the JavaScript name of an FFI value.
151 \item \texttt{library FILENAME} parses \texttt{FILENAME.urp} and merges its contents with the rest of the current file's contents. If \texttt{FILENAME.urp} doesn't exist, the compiler also tries \texttt{FILENAME/lib.urp}. 152 \item \texttt{library FILENAME} parses \texttt{FILENAME.urp} and merges its contents with the rest of the current file's contents. If \texttt{FILENAME.urp} doesn't exist, the compiler also tries \texttt{FILENAME/lib.urp}.
152 \item \texttt{limit class num} sets a resource usage limit for generated applications. The limit \texttt{class} will be set to the non-negative integer \texttt{num}. The classes are: 153 \item \texttt{limit class num} sets a resource usage limit for generated applications. The limit \texttt{class} will be set to the non-negative integer \texttt{num}. The classes are:
153 \begin{itemize} 154 \begin{itemize}
168 \end{itemize} 169 \end{itemize}
169 \item \texttt{link FILENAME} adds \texttt{FILENAME} to the list of files to be passed to the linker at the end of compilation. This is most useful for importing extra libraries needed by new FFI modules. 170 \item \texttt{link FILENAME} adds \texttt{FILENAME} to the list of files to be passed to the linker at the end of compilation. This is most useful for importing extra libraries needed by new FFI modules.
170 \item \texttt{linker CMD} sets \texttt{CMD} as the command line prefix to use for linking C object files. The command line will be completed with a space-separated list of \texttt{.o} and \texttt{.a} files, \texttt{-L} and \texttt{-l} flags, and finally with a \texttt{-o} flag to set the location where the executable should be written. 171 \item \texttt{linker CMD} sets \texttt{CMD} as the command line prefix to use for linking C object files. The command line will be completed with a space-separated list of \texttt{.o} and \texttt{.a} files, \texttt{-L} and \texttt{-l} flags, and finally with a \texttt{-o} flag to set the location where the executable should be written.
171 \item \texttt{minHeap NUMBYTES} sets the initial size for thread-local heaps used in handling requests. These heaps grow automatically as needed (up to any maximum set with \texttt{limit}), but each regrow requires restarting the request handling process. 172 \item \texttt{minHeap NUMBYTES} sets the initial size for thread-local heaps used in handling requests. These heaps grow automatically as needed (up to any maximum set with \texttt{limit}), but each regrow requires restarting the request handling process.
172 \item \texttt{monoInline TREESIZE} sets how many nodes the AST of a function definition may have before the optimizer stops trying hard to inline calls to that function. (This is one of two options for one of two intermediate languages within the compiler.) 173 \item \texttt{monoInline TREESIZE} sets how many nodes the AST of a function definition may have before the optimizer stops trying hard to inline calls to that function. (This is one of two options for one of two intermediate languages within the compiler.)
174 \item \texttt{noMangleSql} avoids adding a \texttt{uw\_} prefix in front of each identifier in SQL. With this experimental feature, the burden is on the programmer to avoid naming tables or columns after SQL keywords!
173 \item \texttt{noXsrfProtection URIPREFIX} turns off automatic cross-site request forgery protection for the page handler identified by the given URI prefix. This will avoid checking cryptographic signatures on cookies, which is generally a reasonable idea for some pages, such as login pages that are going to discard all old cookie values, anyway. 175 \item \texttt{noXsrfProtection URIPREFIX} turns off automatic cross-site request forgery protection for the page handler identified by the given URI prefix. This will avoid checking cryptographic signatures on cookies, which is generally a reasonable idea for some pages, such as login pages that are going to discard all old cookie values, anyway.
174 \item \texttt{onError Module.var} changes the handling of fatal application errors. Instead of displaying a default, ugly error 500 page, the error page will be generated by calling function \texttt{Module.var} on a piece of XML representing the error message. The error handler should have type $\mt{xbody} \to \mt{transaction} \; \mt{page}$. Note that the error handler \emph{cannot} be in the application's main module, since that would register it as explicitly callable via URLs. 176 \item \texttt{onError Module.var} changes the handling of fatal application errors. Instead of displaying a default, ugly error 500 page, the error page will be generated by calling function \texttt{Module.var} on a piece of XML representing the error message. The error handler should have type $\mt{xbody} \to \mt{transaction} \; \mt{page}$. Note that the error handler \emph{cannot} be in the application's main module, since that would register it as explicitly callable via URLs.
175 \item \texttt{path NAME=VALUE} creates a mapping from \texttt{NAME} to \texttt{VALUE}. This mapping may be used at the beginnings of filesystem paths given to various other configuration directives. A path like \texttt{\$NAME/rest} is expanded to \texttt{VALUE/rest}. There is an initial mapping from the empty name (for paths like \texttt{\$/list}) to the directory where the Ur/Web standard library is installed. If you accept the default \texttt{configure} options, this directory is \texttt{/usr/local/lib/urweb/ur}. 177 \item \texttt{path NAME=VALUE} creates a mapping from \texttt{NAME} to \texttt{VALUE}. This mapping may be used at the beginnings of filesystem paths given to various other configuration directives. A path like \texttt{\$NAME/rest} is expanded to \texttt{VALUE/rest}. There is an initial mapping from the empty name (for paths like \texttt{\$/list}) to the directory where the Ur/Web standard library is installed. If you accept the default \texttt{configure} options, this directory is \texttt{/usr/local/lib/urweb/ur}.
176 \item \texttt{prefix PREFIX} sets the prefix included before every URI within the generated application. The default is \texttt{/}. 178 \item \texttt{prefix PREFIX} sets the prefix included before every URI within the generated application. The default is \texttt{/}.
177 \item \texttt{profile} generates an executable that may be used with gprof. 179 \item \texttt{profile} generates an executable that may be used with gprof.
272 \item \texttt{-path NAME VALUE}: Set the value of path variable \texttt{\$NAME} to \texttt{VALUE}, for use in \texttt{.urp} files. 274 \item \texttt{-path NAME VALUE}: Set the value of path variable \texttt{\$NAME} to \texttt{VALUE}, for use in \texttt{.urp} files.
273 275
274 \item \texttt{-prefix PREFIX}: Equivalent to the \texttt{prefix} directive from \texttt{.urp} files 276 \item \texttt{-prefix PREFIX}: Equivalent to the \texttt{prefix} directive from \texttt{.urp} files
275 277
276 \item \texttt{-print-ccompiler}: Print the C compiler being used. 278 \item \texttt{-print-ccompiler}: Print the C compiler being used.
279
280 \item \texttt{-print-cinclude}: Print the name of the directory where C/C++ header files are installed.
277 281
278 \item \texttt{-protocol [http|cgi|fastcgi|static]}: Set the protocol that the generated application speaks. 282 \item \texttt{-protocol [http|cgi|fastcgi|static]}: Set the protocol that the generated application speaks.
279 \begin{itemize} 283 \begin{itemize}
280 \item \texttt{http}: This is the default. It is for building standalone web servers that can be accessed by web browsers directly. 284 \item \texttt{http}: This is the default. It is for building standalone web servers that can be accessed by web browsers directly.
281 285
2101 $$\begin{array}{l} 2105 $$\begin{array}{l}
2102 \mt{val} \; \mt{preventDefault} : \mt{transaction} \; \mt{unit} \\ 2106 \mt{val} \; \mt{preventDefault} : \mt{transaction} \; \mt{unit} \\
2103 \mt{val} \; \mt{stopPropagation} : \mt{transaction} \; \mt{unit} 2107 \mt{val} \; \mt{stopPropagation} : \mt{transaction} \; \mt{unit}
2104 \end{array}$$ 2108 \end{array}$$
2105 2109
2110 Finally, here is an HTML tag to leave a marker in the \cd{<head>} of a document asking for some side-effecting code to be run. This pattern is \emph{much} less common in Ur/Web applications than in normal HTML/JavaScript applications; see Section \ref{signals} for the more idiomatic, functional way of manipulating the visible page.
2111
2112 $$\begin{array}{l}
2113 \mt{val} \; \mt{script} : \mt{unit} \to \mt{tag} \; [\mt{Code} = \mt{transaction} \; \mt{unit}] \; \mt{head} \; [] \; [] \; []
2114 \end{array}$$
2115
2116 Note that the Ur/Web version of \cd{<script>} is used like \cd{<script code=\{...\}/>}, rather than \cd{<script>...</script>}.
2117
2106 \subsubsection{Node IDs} 2118 \subsubsection{Node IDs}
2107 2119
2108 There is an abstract type of node IDs that may be assigned to \cd{id} attributes of most HTML tags. 2120 There is an abstract type of node IDs that may be assigned to \cd{id} attributes of most HTML tags.
2109 2121
2110 $$\begin{array}{l} 2122 $$\begin{array}{l}
2182 $$\begin{array}{l} 2194 $$\begin{array}{l}
2183 \mt{type} \; \mt{client} \\ 2195 \mt{type} \; \mt{client} \\
2184 \mt{val} \; \mt{self} : \mt{transaction} \; \mt{client} 2196 \mt{val} \; \mt{self} : \mt{transaction} \; \mt{client}
2185 \end{array}$$ 2197 \end{array}$$
2186 2198
2187 \emph{Channels} are the means of message-passing. Each channel is created in the context of a client and belongs to that client; no other client may receive the channel's messages. Each channel type includes the type of values that may be sent over the channel. Sending and receiving are asynchronous, in the sense that a client need not be ready to receive a message right away. Rather, sent messages may queue up, waiting to be processed. 2199 \emph{Channels} are the means of message-passing. Each channel is created in the context of a client and belongs to that client; no other client may receive the channel's messages. Note that here \emph{client} has a technical Ur/Web meaning so that it describes only \emph{single page views}, so a user following a traditional link within an application will remove the ability for \emph{any} code to receive messages on the channels associated with the previous client. Each channel type includes the type of values that may be sent over the channel. Sending and receiving are asynchronous, in the sense that a client need not be ready to receive a message right away. Rather, sent messages may queue up, waiting to be processed.
2188 2200
2189 $$\begin{array}{l} 2201 $$\begin{array}{l}
2190 \mt{con} \; \mt{channel} :: \mt{Type} \to \mt{Type} \\ 2202 \mt{con} \; \mt{channel} :: \mt{Type} \to \mt{Type} \\
2191 \mt{val} \; \mt{channel} : \mt{t} ::: \mt{Type} \to \mt{transaction} \; (\mt{channel} \; \mt{t}) \\ 2203 \mt{val} \; \mt{channel} : \mt{t} ::: \mt{Type} \to \mt{transaction} \; (\mt{channel} \; \mt{t}) \\
2192 \mt{val} \; \mt{send} : \mt{t} ::: \mt{Type} \to \mt{channel} \; \mt{t} \to \mt{t} \to \mt{transaction} \; \mt{unit} \\ 2204 \mt{val} \; \mt{send} : \mt{t} ::: \mt{Type} \to \mt{channel} \; \mt{t} \to \mt{t} \to \mt{transaction} \; \mt{unit} \\