Mercurial > urweb
comparison src/cjr_print.sml @ 1979:81bc76aa4acd
Merge in upstream changes.
author | Patrick Hurst <phurst@mit.edu> |
---|---|
date | Sat, 18 Jan 2014 18:26:24 -0500 |
parents | ac1be85e91ad |
children | ced78ef1c82f 01c8aceac480 |
comparison
equal
deleted
inserted
replaced
1978:c5143edaf3c7 | 1979:81bc76aa4acd |
---|---|
1626 string ");", | 1626 string ");", |
1627 newline, | 1627 newline, |
1628 string "tmp;", | 1628 string "tmp;", |
1629 newline, | 1629 newline, |
1630 string "})"] | 1630 string "})"] |
1631 | EReturnBlob {blob, mimeType, t} => | 1631 | EReturnBlob {blob = SOME blob, mimeType, t} => |
1632 box [string "({", | 1632 box [string "({", |
1633 newline, | 1633 newline, |
1634 string "uw_Basis_blob", | 1634 string "uw_Basis_blob", |
1635 space, | 1635 space, |
1636 string "blob", | 1636 string "blob", |
1652 p_typ env t, | 1652 p_typ env t, |
1653 space, | 1653 space, |
1654 string "tmp;", | 1654 string "tmp;", |
1655 newline, | 1655 newline, |
1656 string "uw_return_blob(ctx, blob, mimeType);", | 1656 string "uw_return_blob(ctx, blob, mimeType);", |
1657 newline, | |
1658 string "tmp;", | |
1659 newline, | |
1660 string "})"] | |
1661 | EReturnBlob {blob = NONE, mimeType, t} => | |
1662 box [string "({", | |
1663 newline, | |
1664 string "uw_Basis_string", | |
1665 space, | |
1666 string "mimeType", | |
1667 space, | |
1668 string "=", | |
1669 space, | |
1670 p_exp' false false env mimeType, | |
1671 string ";", | |
1672 newline, | |
1673 p_typ env t, | |
1674 space, | |
1675 string "tmp;", | |
1676 newline, | |
1677 string "uw_return_blob_from_page(ctx, mimeType);", | |
1657 newline, | 1678 newline, |
1658 string "tmp;", | 1679 string "tmp;", |
1659 newline, | 1680 newline, |
1660 string "})"] | 1681 string "})"] |
1661 | ERedirect (e, t) => | 1682 | ERedirect (e, t) => |
2077 p_exp' false false env initial, | 2098 p_exp' false false env initial, |
2078 string ";", | 2099 string ";", |
2079 newline, | 2100 newline, |
2080 string "int dummy = (uw_begin_region(ctx), 0);", | 2101 string "int dummy = (uw_begin_region(ctx), 0);", |
2081 newline, | 2102 newline, |
2103 string "uw_ensure_transaction(ctx);", | |
2104 newline, | |
2082 | 2105 |
2083 case prepared of | 2106 case prepared of |
2084 NONE => | 2107 NONE => |
2085 box [string "char *query = ", | 2108 box [string "char *query = ", |
2086 p_exp' false false env query, | 2109 p_exp' false false env query, |
2137 newline, | 2160 newline, |
2138 case prepared of | 2161 case prepared of |
2139 NONE => box [string "char *dml = ", | 2162 NONE => box [string "char *dml = ", |
2140 p_exp' false false env dml, | 2163 p_exp' false false env dml, |
2141 string ";", | 2164 string ";", |
2165 newline, | |
2166 string "uw_ensure_transaction(ctx);", | |
2142 newline, | 2167 newline, |
2143 newline, | 2168 newline, |
2144 #dml (Settings.currentDbms ()) (loc, mode)] | 2169 #dml (Settings.currentDbms ()) (loc, mode)] |
2145 | SOME {id, dml = dml'} => | 2170 | SOME {id, dml = dml'} => |
2146 let | 2171 let |
2157 space, | 2182 space, |
2158 p_exp' false false env e, | 2183 p_exp' false false env e, |
2159 string ";"]) | 2184 string ";"]) |
2160 inputs, | 2185 inputs, |
2161 newline, | 2186 newline, |
2187 string "uw_ensure_transaction(ctx);", | |
2162 newline, | 2188 newline, |
2163 | 2189 newline, |
2190 | |
2164 #dmlPrepared (Settings.currentDbms ()) {loc = loc, | 2191 #dmlPrepared (Settings.currentDbms ()) {loc = loc, |
2165 id = id, | 2192 id = id, |
2166 dml = dml', | 2193 dml = dml', |
2167 inputs = map #2 inputs, | 2194 inputs = map #2 inputs, |
2168 mode = mode}] | 2195 mode = mode}] |
2181 | 2208 |
2182 | ENextval {seq, prepared} => | 2209 | ENextval {seq, prepared} => |
2183 box [string "({", | 2210 box [string "({", |
2184 newline, | 2211 newline, |
2185 string "uw_Basis_int n;", | 2212 string "uw_Basis_int n;", |
2213 newline, | |
2214 string "uw_ensure_transaction(ctx);", | |
2186 newline, | 2215 newline, |
2187 | 2216 |
2188 case prepared of | 2217 case prepared of |
2189 NONE => #nextval (Settings.currentDbms ()) {loc = loc, | 2218 NONE => #nextval (Settings.currentDbms ()) {loc = loc, |
2190 seqE = p_exp' false false env seq, | 2219 seqE = p_exp' false false env seq, |
2201 newline, | 2230 newline, |
2202 string "})"] | 2231 string "})"] |
2203 | 2232 |
2204 | ESetval {seq, count} => | 2233 | ESetval {seq, count} => |
2205 box [string "({", | 2234 box [string "({", |
2235 newline, | |
2236 string "uw_ensure_transaction(ctx);", | |
2206 newline, | 2237 newline, |
2207 | 2238 |
2208 #setval (Settings.currentDbms ()) {loc = loc, | 2239 #setval (Settings.currentDbms ()) {loc = loc, |
2209 seqE = p_exp' false false env seq, | 2240 seqE = p_exp' false false env seq, |
2210 count = p_exp' false false env count}, | 2241 count = p_exp' false false env count}, |
2968 | _ => raise Fail "CjrPrint: Last argument to an action isn't a record") | 2999 | _ => raise Fail "CjrPrint: Last argument to an action isn't a record") |
2969 | _ => (List.take (ts, length ts - 1), string "", string "", NONE) | 3000 | _ => (List.take (ts, length ts - 1), string "", string "", NONE) |
2970 | 3001 |
2971 fun couldWrite ek = | 3002 fun couldWrite ek = |
2972 case ek of | 3003 case ek of |
2973 Link => false | 3004 Link _ => false |
2974 | Action ef => ef = ReadCookieWrite | 3005 | Action ef => ef = ReadCookieWrite |
2975 | Rpc ef => ef = ReadCookieWrite | 3006 | Rpc ef => ef = ReadCookieWrite |
2976 | Extern _ => false | 3007 | Extern _ => false |
3008 | |
3009 fun couldWriteDb ek = | |
3010 case ek of | |
3011 Link ef => ef <> ReadOnly | |
3012 | Action ef => ef <> ReadOnly | |
3013 | Rpc ef => ef <> ReadOnly | |
3014 | Extern ef => ef <> ReadOnly | |
2977 | 3015 |
2978 val s = | 3016 val s = |
2979 case Settings.getUrlPrefix () of | 3017 case Settings.getUrlPrefix () of |
2980 "" => s | 3018 "" => s |
2981 | "/" => s | 3019 | "/" => s |
3039 box (case ek of | 3077 box (case ek of |
3040 Core.Rpc _ => [string "uw_write_header(ctx, \"Content-type: text/plain\\r\\n\");", | 3078 Core.Rpc _ => [string "uw_write_header(ctx, \"Content-type: text/plain\\r\\n\");", |
3041 newline] | 3079 newline] |
3042 | _ => [string "uw_write_header(ctx, \"Content-type: text/html; charset=utf-8\\r\\n\");", | 3080 | _ => [string "uw_write_header(ctx, \"Content-type: text/html; charset=utf-8\\r\\n\");", |
3043 newline, | 3081 newline, |
3044 string "uw_write_header(ctx, \"Content-script-type: text/javascript\\r\\n\");", | 3082 case side of |
3045 newline, | 3083 ServerOnly => box [] |
3046 string "uw_write(ctx, begin_xhtml);", | 3084 | _ => box [string "uw_write_header(ctx, \"Content-script-type: text/javascript\\r\\n\");", |
3085 newline], | |
3086 string ("uw_write(ctx, uw_begin_" ^ | |
3087 (if Settings.getIsHtml5 () then | |
3088 "html5" | |
3089 else | |
3090 "xhtml") ^ ");"), | |
3047 newline, | 3091 newline, |
3048 string "uw_mayReturnIndirectly(ctx);", | 3092 string "uw_mayReturnIndirectly(ctx);", |
3049 newline, | 3093 newline, |
3050 string "uw_set_script_header(ctx, \"", | 3094 string "uw_set_script_header(ctx, \"", |
3051 let | 3095 let |
3056 in | 3100 in |
3057 string scripts | 3101 string scripts |
3058 end, | 3102 end, |
3059 string "\");", | 3103 string "\");", |
3060 newline]), | 3104 newline]), |
3105 string "uw_set_could_write_db(ctx, ", | |
3106 string (if couldWriteDb ek then "1" else "0"), | |
3107 string ");", | |
3108 newline, | |
3061 string "uw_set_needs_push(ctx, ", | 3109 string "uw_set_needs_push(ctx, ", |
3062 string (case side of | 3110 string (case side of |
3063 ServerAndPullAndPush => "1" | 3111 ServerAndPullAndPush => "1" |
3064 | _ => "0"), | 3112 | _ => "0"), |
3065 string ");", | 3113 string ");", |
3168 | EBinop (_, e1, e2) => expDb e1 orelse expDb e2 | 3216 | EBinop (_, e1, e2) => expDb e1 orelse expDb e2 |
3169 | ERecord (_, xes) => List.exists (expDb o #2) xes | 3217 | ERecord (_, xes) => List.exists (expDb o #2) xes |
3170 | EField (e, _) => expDb e | 3218 | EField (e, _) => expDb e |
3171 | ECase (e, pes, _) => expDb e orelse List.exists (expDb o #2) pes | 3219 | ECase (e, pes, _) => expDb e orelse List.exists (expDb o #2) pes |
3172 | EError (e, _) => expDb e | 3220 | EError (e, _) => expDb e |
3173 | EReturnBlob {blob = e1, mimeType = e2, ...} => expDb e1 orelse expDb e2 | 3221 | EReturnBlob {blob = NONE, mimeType = e2, ...} => expDb e2 |
3222 | EReturnBlob {blob = SOME e1, mimeType = e2, ...} => expDb e1 orelse expDb e2 | |
3174 | ERedirect (e, _) => expDb e | 3223 | ERedirect (e, _) => expDb e |
3175 | EWrite e => expDb e | 3224 | EWrite e => expDb e |
3176 | ESeq (e1, e2) => expDb e1 orelse expDb e2 | 3225 | ESeq (e1, e2) => expDb e1 orelse expDb e2 |
3177 | ELet (_, _, e1, e2) => expDb e1 orelse expDb e2 | 3226 | ELet (_, _, e1, e2) => expDb e1 orelse expDb e2 |
3178 | EQuery _ => true | 3227 | EQuery _ => true |
3317 else | 3366 else |
3318 box [string "static void uw_client_init(void) { };", | 3367 box [string "static void uw_client_init(void) { };", |
3319 newline, | 3368 newline, |
3320 string "static void uw_db_init(uw_context ctx) { };", | 3369 string "static void uw_db_init(uw_context ctx) { };", |
3321 newline, | 3370 newline, |
3322 string "static int uw_db_begin(uw_context ctx) { return 0; };", | 3371 string "static int uw_db_begin(uw_context ctx, int could_write) { return 0; };", |
3323 newline, | 3372 newline, |
3324 string "static void uw_db_close(uw_context ctx) { };", | 3373 string "static void uw_db_close(uw_context ctx) { };", |
3325 newline, | 3374 newline, |
3326 string "static int uw_db_commit(uw_context ctx) { return 0; };", | 3375 string "static int uw_db_commit(uw_context ctx) { return 0; };", |
3327 newline, | 3376 newline, |
3328 string "static int uw_db_rollback(uw_context ctx) { return 0; };"], | 3377 string "static int uw_db_rollback(uw_context ctx) { return 0; };"], |
3329 newline, | 3378 newline, |
3330 newline, | 3379 newline, |
3331 | 3380 |
3332 string "static const char begin_xhtml[] = \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\" ?>\\n<!DOCTYPE html PUBLIC \\\"-//W3C//DTD XHTML 1.0 Transitional//EN\\\" \\\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\\\">\\n<html xmlns=\\\"http://www.w3.org/1999/xhtml\\\" xml:lang=\\\"en\\\" lang=\\\"en\\\">\";", | |
3333 newline, | |
3334 newline, | |
3335 | 3381 |
3336 p_list_sep newline (fn x => x) pds, | 3382 p_list_sep newline (fn x => x) pds, |
3337 newline, | 3383 newline, |
3338 newline, | 3384 newline, |
3339 string "static int uw_input_num(const char *name) {", | 3385 string "static int uw_input_num(const char *name) {", |
3541 "uw_client_init", "uw_initializer", "uw_expunger", | 3587 "uw_client_init", "uw_initializer", "uw_expunger", |
3542 "uw_db_init", "uw_db_begin", "uw_db_commit", "uw_db_rollback", "uw_db_close", | 3588 "uw_db_init", "uw_db_begin", "uw_db_commit", "uw_db_rollback", "uw_db_close", |
3543 "uw_handle", | 3589 "uw_handle", |
3544 "uw_input_num", "uw_cookie_sig", "uw_check_url", "uw_check_mime", "uw_check_requestHeader", "uw_check_responseHeader", "uw_check_envVar", | 3590 "uw_input_num", "uw_cookie_sig", "uw_check_url", "uw_check_mime", "uw_check_requestHeader", "uw_check_responseHeader", "uw_check_envVar", |
3545 case onError of NONE => "NULL" | SOME _ => "uw_onError", "my_periodics", | 3591 case onError of NONE => "NULL" | SOME _ => "uw_onError", "my_periodics", |
3546 "\"" ^ Prim.toCString (Settings.getTimeFormat ()) ^ "\""], | 3592 "\"" ^ Prim.toCString (Settings.getTimeFormat ()) ^ "\"", |
3593 if Settings.getIsHtml5 () then "1" else "0"], | |
3547 string "};", | 3594 string "};", |
3548 newline] | 3595 newline] |
3549 end | 3596 end |
3550 | 3597 |
3551 fun p_sql env (ds, _) = | 3598 fun p_sql env (ds, _) = |