Mercurial > urweb
comparison src/jscomp.sml @ 974:b851675a2c3d
Compiled an 'option' pattern-match
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 22 Sep 2009 14:15:29 -0400 |
parents | e30c2409c9d0 |
children | 68eda5b0636d |
comparison
equal
deleted
inserted
replaced
973:e30c2409c9d0 | 974:b851675a2c3d |
---|---|
461 | PCon (Option, _, NONE) => | 461 | PCon (Option, _, NONE) => |
462 str "{c:\"c\",v:null}" | 462 str "{c:\"c\",v:null}" |
463 | PCon (Option, PConVar n, SOME p) => | 463 | PCon (Option, PConVar n, SOME p) => |
464 (case IM.find (someTs, n) of | 464 (case IM.find (someTs, n) of |
465 NONE => raise Fail "Jscomp: Not in someTs" | 465 NONE => raise Fail "Jscomp: Not in someTs" |
466 | SOME t => strcat [str ("{c:\"s\",n:" | 466 | SOME t => |
467 ^ (if isNullable t then | 467 strcat [str ("{c:\"s\",n:" |
468 "true" | 468 ^ (if isNullable t then |
469 else | 469 "true" |
470 "false") | 470 else |
471 ^ ",p:"), | 471 "false") |
472 jsPat p, | 472 ^ ",p:"), |
473 str "}"]) | 473 jsPat p, |
474 | PCon (_, pc, NONE) => strcat [str "{c:\"0\",n:", | 474 str "}"]) |
475 | PCon (_, pc, NONE) => strcat [str "{c:\"c\",v:", | |
475 patCon pc, | 476 patCon pc, |
476 str "}"] | 477 str "}"] |
477 | PCon (_, pc, SOME p) => strcat [str "{c:\"1\",n:", | 478 | PCon (_, pc, SOME p) => strcat [str "{c:\"1\",n:", |
478 patCon pc, | 479 patCon pc, |
479 str ",p:", | 480 str ",p:", |
558 decoders = #decoders st, | 559 decoders = #decoders st, |
559 maxName = #maxName st} | 560 maxName = #maxName st} |
560 | 561 |
561 val old = e | 562 val old = e |
562 val (e, st) = jsExp mode [] (e, st) | 563 val (e, st) = jsExp mode [] (e, st) |
563 val new = e | |
564 val e = deStrcat 0 e | 564 val e = deStrcat 0 e |
565 | 565 |
566 val sc = "urfuncs[" ^ Int.toString n ^ "] = " ^ e ^ ";\n" | 566 val sc = "urfuncs[" ^ Int.toString n ^ "] = " ^ e ^ ";\n" |
567 in | 567 in |
568 (*Print.prefaces "jsify'" [("old", MonoPrint.p_exp MonoEnv.empty old), | 568 (*Print.prefaces "jsify'" [("old", MonoPrint.p_exp MonoEnv.empty old), |
789 val (e', st) = jsE inner (e', st) | 789 val (e', st) = jsE inner (e', st) |
790 | 790 |
791 val (ps, st) = | 791 val (ps, st) = |
792 foldr (fn ((p, e), (ps, st)) => | 792 foldr (fn ((p, e), (ps, st)) => |
793 let | 793 let |
794 val (e, st) = jsE inner (e, st) | 794 val (e, st) = jsE (inner + E.patBindsN p) (e, st) |
795 in | 795 in |
796 (strcat [str "cons({p:", | 796 (strcat [str "cons({p:", |
797 jsPat p, | 797 jsPat p, |
798 str ",b:", | 798 str ",b:", |
799 e, | 799 e, |
803 st) | 803 st) |
804 end) | 804 end) |
805 (str "null", st) pes | 805 (str "null", st) pes |
806 in | 806 in |
807 (strcat [str "{c:\"m\",e:", | 807 (strcat [str "{c:\"m\",e:", |
808 e, | 808 e', |
809 str ",p:", | 809 str ",p:", |
810 ps, | 810 ps, |
811 str "}"], st) | 811 str "}"], st) |
812 end | 812 end |
813 | 813 |