comparison src/cjr_print.sml @ 641:b98f547a6a45

RPC returning an option
author Adam Chlipala <adamc@hcoop.net>
date Sun, 08 Mar 2009 13:41:55 -0400
parents 63b0bcacd535
children aa2290c32ce2
comparison
equal deleted inserted replaced
640:63b0bcacd535 641:b98f547a6a45
1085 newline, 1085 newline,
1086 string "});", 1086 string "});",
1087 newline] 1087 newline]
1088 end 1088 end
1089 1089
1090 | TOption t => box [] 1090 | TOption t =>
1091 (*box [string "(request[0] == '/' ? ++request : request, ", 1091 box [string "if (it",
1092 string "((!strncmp(request, \"None\", 4) ", 1092 string (Int.toString level),
1093 string "&& (request[4] == 0 || request[4] == '/')) ", 1093 string ") {",
1094 string "? (request += 4, NULL) ", 1094 if isUnboxable t then
1095 string ": ((!strncmp(request, \"Some\", 4) ", 1095 box [string "uw_write(ctx, \"Some/\");",
1096 string "&& request[4] == '/') ", 1096 newline,
1097 string "? (request += 5, ", 1097 urlify' rf level t]
1098 if isUnboxable t then
1099 unurlify' rf (#1 t)
1100 else 1098 else
1101 box [string "({", 1099 box [p_typ env t,
1102 newline,
1103 p_typ env t,
1104 space, 1100 space,
1105 string "*tmp", 1101 string "it",
1102 string (Int.toString (level + 1)),
1106 space, 1103 space,
1107 string "=", 1104 string "=",
1108 space, 1105 space,
1109 string "uw_malloc(ctx, sizeof(", 1106 string "*it",
1110 p_typ env t, 1107 string (Int.toString level),
1111 string "));",
1112 newline,
1113 string "*tmp",
1114 space,
1115 string "=",
1116 space,
1117 unurlify' rf (#1 t),
1118 string ";", 1108 string ";",
1119 newline, 1109 newline,
1120 string "tmp;", 1110 string "uw_write(ctx, \"Some/\");",
1121 newline, 1111 newline,
1122 string "})"], 1112 urlify' rf (level + 1) t,
1123 string ") :", 1113 string ";",
1124 space, 1114 newline],
1125 string "(uw_error(ctx, FATAL, \"Error unurlifying option type\"), NULL))))"]*) 1115 string "} else {",
1116 box [string "uw_write(ctx, \"None\");",
1117 newline],
1118 string "}",
1119 newline]
1126 1120
1127 | _ => (ErrorMsg.errorAt loc "Unable to choose a URL encoding function"; 1121 | _ => (ErrorMsg.errorAt loc "Unable to choose a URL encoding function";
1128 space) 1122 space)
1129 in 1123 in
1130 urlify' IS.empty 0 t 1124 urlify' IS.empty 0 t