diff src/cjr_print.sml @ 167:2be573fec9a6

Unurlifying a datatype; longjmp-based error signaling mechanism
author Adam Chlipala <adamc@hcoop.net>
date Tue, 29 Jul 2008 15:25:42 -0400
parents a991431b77eb
children 25b169416ea8
line wrap: on
line diff
--- a/src/cjr_print.sml	Tue Jul 29 14:28:44 2008 -0400
+++ b/src/cjr_print.sml	Tue Jul 29 15:25:42 2008 -0400
@@ -211,7 +211,7 @@
                  newline,
                  string "struct",
                  space,
-                 string ("_lwd_" ^ x ^ "_" ^ Int.toString n),
+                 string ("__lwd_" ^ x ^ "_" ^ Int.toString n),
                  space,
                  string "{",
                  newline,
@@ -451,34 +451,48 @@
 
                     fun doEm xncs =
                         case xncs of
-                            [] => string "Uh oh"
-                          | (x, n, to) :: rest =>
-                            box [string "(!strcmp(request, \"",
-                                 string x,
-                                 string "\") ? ({",
+                            [] => string ("(lw_error(ctx, FATAL, \"Error unurlifying datatype " ^ x ^ "\"), NULL)")
+                          | (x', n, to) :: rest =>
+                            box [string "((!strncmp(request, \"",
+                                 string x',
+                                 string "\", ",
+                                 string (Int.toString (size x')),
+                                 string ") && (request[",
+                                 string (Int.toString (size x')),
+                                 string "] == 0 || request[",
+                                 string (Int.toString (size x')),
+                                 string "] == '/')) ? ({",
                                  newline,
+                                 string "struct",
+                                 space,
                                  string ("__lwd_" ^ x ^ "_" ^ Int.toString i),
                                  space,
-                                 string "__lw_tmp;",
+                                 string "*__lw_tmp = lw_malloc(ctx, sizeof(struct __lwd_",
+                                 string x,
+                                 string "_",
+                                 string (Int.toString i),
+                                 string "));",
                                  newline,
-                                 string "__lw_tmp.tag",
+                                 string "__lw_tmp->tag",
                                  space,
                                  string "=",
                                  space,
-                                 string ("__lwc_" ^ x ^ "_" ^ Int.toString n),
+                                 string ("__lwc_" ^ x' ^ "_" ^ Int.toString n),
                                  string ";",
                                  newline,
                                  string "request",
                                  space,
                                  string "+=",
                                  space,
-                                 string (Int.toString (size x)),
+                                 string (Int.toString (size x')),
                                  string ";",
                                  newline,
+                                 string "if (request[0] == '/') ++request;",
+                                 newline,
                                  case to of
                                      NONE => box []
-                                   | SOME t => box [string "__lw_tmp.data.",
-                                                    string x,
+                                   | SOME t => box [string "__lw_tmp->data.",
+                                                    string x',
                                                     space,
                                                     string "=",
                                                     space,