view tests/jscomp.ur @ 1739:c414850f206f

Add support for -boot flag, which allows in-tree execution of Ur/Web The boot flag rewrites most hardcoded paths to point to the build directory, and also forces static compilation. This is convenient for developing Ur/Web, or if you cannot 'sudo make install' Ur/Web. The following changes were made: * Header files were moved to include/urweb instead of include; this lets FFI users point their C_INCLUDE_PATH at this directory at write <urweb/urweb.h>. For internal Ur/Web executables, we simply pass -I$PATH/include/urweb as normal. * Differentiate between LIB and SRCLIB; SRCLIB is Ur and JavaScript source files, while LIB is compiled products from libtool. For in-tree compilation these live in different places. * No longer reference Config for paths; instead use Settings; these settings can be changed dynamically by Compiler.enableBoot () (TODO: add a disableBoot function.) * config.h is now generated directly in include/urweb/config.h, for consistency's sake (especially since it gets installed along with the rest of the headers!) * All of the autotools build products got updated. * The linkStatic field in protocols now only contains the name of the build product, and not the absolute path. Future users have to be careful not to reference the Settings files to early, lest they get an old version (this was the source of two bugs during development of this patch.)
author Edward Z. Yang <ezyang@mit.edu>
date Wed, 02 May 2012 17:17:57 -0400
parents 8fe576c0bee9
children
line wrap: on
line source
fun fst [a] [b] (x : a) (y : b) = x
fun snd [a] [b] (x : a) (y : b) = y

fun fact n =
    case n of
        0 => 1
      | _ => n * fact (n - 1)

datatype t =
         A
       | B of {C : int, D : float}
       | E of t * t

fun render x =
    case x of
        A => "A"
      | B {C = n1, D = n2} => "B(" ^ show n1 ^ "," ^ show n2 ^ ")"
      | E (x, y) => "C(" ^ render x ^ "," ^ render y ^ ")"

fun main () =
    s <- source "";
    s' <- source "";
    f <- source (plus 1);
    f2 <- source fst;
    r <- source {A = "x", B = "y"};
    t <- source (E (A, B {C = 10, D = 1.23}));
    ht <- source <xml>Nothing here yet.</xml>;

    return <xml><body>
      <ctextbox source={s}/> <ctextbox source={s'}/><br/><br/>

      Function: <button value="+1" onclick={set f (plus 1)}/>
      <button value="*3" onclick={set f (times 3)}/><br/><br/>

      Function2: <button value="Fst" onclick={set f2 fst}/>
      <button value="Snd" onclick={set f2 snd}/><br/><br/>

      Both: <button value="*3,Snd" onclick={set f (times 3); set f2 snd}/><br/><br/>

      <button value="Echo" onclick={s <- get s; alert s}/>
      <button value="Echo2" onclick={s <- get s; alert s; alert s}/>
      <button value="-" onclick={s <- get s; alert (show (-(readError s : int)))}/>
      <button value="+1" onclick={s <- get s; alert (show (readError s + 1))}/>
      <button value="*3" onclick={s <- get s; alert (show ((readError s) * 3))}/>
      <button value="!" onclick={s <- get s; alert (show (fact (readError s)))}/>
      <button value="f" onclick={s <- get s; f <- get f; alert (show (f (readError s)))}/>
      <button value="+1P" onclick={s <- get s; case read s of
                                                   None => alert "Nada!"
                                                 | Some (n : int) => alert (show (n + 1))}/>

      <button value="f2" onclick={s <- get s; s' <- get s'; f2 <- get f2; alert (f2 s s')}/><br/><br/>

      <button value="A" onclick={r <- get r; alert r.A}/>
      <button value="B" onclick={r <- get r; alert r.B}/><br/><br/>

      <button value="render" onclick={t <- get t; alert (render t)}/><br/><br/>

      <dyn signal={signal ht}/>
      <button value="Set" onclick={s <- get s;
                                   set ht <xml><button value="Dynamic!" onclick={alert s}/></xml>}/>
    </body></xml>