comparison src/jscomp.sml @ 646:fb2a0e76dcef

ListEdit demo, minus prose
author Adam Chlipala <adamc@hcoop.net>
date Tue, 10 Mar 2009 12:44:40 -0400
parents b98f547a6a45
children 96ebc6bdb5a0
comparison
equal deleted inserted replaced
645:1b571a05874c 646:fb2a0e76dcef
407 407
408 | _ => (EM.errorAt loc "Don't know how to unurlify type in JavaScript"; 408 | _ => (EM.errorAt loc "Don't know how to unurlify type in JavaScript";
409 Print.prefaces "Can't unurlify" [("t", MonoPrint.p_typ MonoEnv.empty t)]; 409 Print.prefaces "Can't unurlify" [("t", MonoPrint.p_typ MonoEnv.empty t)];
410 ("ERROR", st)) 410 ("ERROR", st))
411 411
412 fun padWith (ch, s, len) =
413 if size s < len then
414 padWith (ch, String.str ch ^ s, len - 1)
415 else
416 s
417
412 fun jsExp mode skip outer = 418 fun jsExp mode skip outer =
413 let 419 let
414 val len = length outer 420 val len = length outer
415 421
416 fun jsE inner (e as (_, loc), st) = 422 fun jsE inner (e as (_, loc), st) =
446 if mode = Script then 452 if mode = Script then
447 "<" 453 "<"
448 else 454 else
449 "\\074" 455 "\\074"
450 | #"\\" => "\\\\" 456 | #"\\" => "\\\\"
451 | ch => String.str ch) s 457 | #"\n" => "\\n"
458 | #"\r" => "\\r"
459 | #"\t" => "\\t"
460 | ch =>
461 if Char.isPrint ch then
462 String.str ch
463 else
464 "\\" ^ padWith (#"0",
465 Int.fmt StringCvt.OCT (ord ch),
466 3)) s
452 ^ "\"") 467 ^ "\"")
453 | _ => str (Prim.toString p) 468 | _ => str (Prim.toString p)
454 469
455 fun jsPat depth inner (p, _) succ fail = 470 fun jsPat depth inner (p, _) succ fail =
456 case p of 471 case p of
876 | EClosure _ => unsupported "EClosure" 891 | EClosure _ => unsupported "EClosure"
877 | EQuery _ => unsupported "Query" 892 | EQuery _ => unsupported "Query"
878 | EDml _ => unsupported "DML" 893 | EDml _ => unsupported "DML"
879 | ENextval _ => unsupported "Nextval" 894 | ENextval _ => unsupported "Nextval"
880 | EUnurlify _ => unsupported "EUnurlify" 895 | EUnurlify _ => unsupported "EUnurlify"
896 | EJavaScript (_, e as (EAbs _, _), _) =>
897 let
898 val (e, st) = jsE inner (e, st)
899 in
900 (strcat [str "\"cr(\"+ca(",
901 e,
902 str ")+\")\""],
903 st)
904 end
881 | EJavaScript (_, e, _) => 905 | EJavaScript (_, e, _) =>
882 let 906 let
883 val (e, st) = jsE inner (e, st) 907 val (e, st) = jsE inner (e, st)
884 in 908 in
885 (strcat [str "\"cr(\"+ca(function(){return ", 909 (strcat [str "\"cr(\"+ca(function(){return ",