diff src/cjr_print.sml @ 758:8323c1beef2e

Subforms type-checks; lists urlified and unurlified
author Adam Chlipala <adamc@hcoop.net>
date Thu, 30 Apr 2009 11:48:56 -0400
parents fa2019a63ea4
children 67cd8326f743
line wrap: on
line diff
--- a/src/cjr_print.sml	Thu Apr 30 11:07:29 2009 -0400
+++ b/src/cjr_print.sml	Thu Apr 30 11:48:56 2009 -0400
@@ -333,10 +333,6 @@
                 in
                     (box [string "{",
                           newline,
-                          string "/* ",
-                          string (ErrorMsg.spanToString loc),
-                          string "*/",
-                          newline,
                           p_typ env t,
                           space,
                           string "disc",
@@ -864,6 +860,77 @@
                              string "})"]
                     end
 
+              | TList (t', i) =>
+                if IS.member (rf, i) then
+                    box [string "unurlify_list_",
+                         string (Int.toString i),
+                         string "()"]
+                else
+                    let
+                        val rf = IS.add (rf, i)
+                    in
+                        box [string "({",
+                             space,
+                             p_typ env (t, loc),
+                             space,
+                             string "unurlify_list_",
+                             string (Int.toString i),
+                             string "(void) {",
+                             newline,
+                             box [string "return (request[0] == '/' ? ++request : request,",
+                                  newline,
+                                  string "((!strncmp(request, \"Nil\", 3) && (request[3] == 0 ",
+                                  string "|| request[3] == '/')) ? (request",
+                                  space,
+                                  string "+=",
+                                  space,
+                                  string "3, NULL) : ((!strncmp(request, \"Cons\", 4) && (request[4] == 0 ",
+                                  string "|| request[4] == '/')) ? (request",
+                                  space,
+                                  string "+=",
+                                  space,
+                                  string "4, (request[0] == '/' ? ++request : NULL), ",
+                                  newline,
+                                  
+                                  string "({",
+                                  newline,
+                                  p_typ env (t, loc),
+                                  space,
+                                  string "tmp",
+                                  space,
+                                  string "=",
+                                  space,
+                                  string "uw_malloc(ctx, sizeof(struct __uws_",
+                                  string (Int.toString i),
+                                  string "));",
+                                  newline,
+                                  string "*tmp",
+                                  space,
+                                  string "=",
+                                  space,
+                                  unurlify' rf (TRecord i),
+                                  string ";",
+                                  newline,
+                                  string "tmp;",
+                                  newline,
+                                  string "})",
+                                  string ")",
+                                  newline,
+                                  string ":",
+                                  space,
+                                  string ("(uw_error(ctx, FATAL, \"Error unurlifying list\"), NULL))));"),
+                                  newline],
+                             string "}",
+                             newline,
+                             newline,
+
+                             string "unurlify_list_",
+                             string (Int.toString i),
+                             string "();",
+                             newline,
+                             string "})"]
+                    end
+
               | TOption t =>
                 box [string "(request[0] == '/' ? ++request : request, ",
                      string "((!strncmp(request, \"None\", 4) ",