summaryrefslogtreecommitdiff
path: root/src/cjr_print.sml
diff options
context:
space:
mode:
authorGravatar Ziv Scully <ziv@mit.edu>2015-05-06 14:50:29 -0400
committerGravatar Ziv Scully <ziv@mit.edu>2015-05-06 14:50:29 -0400
commitf242d9d14317ee01328b8a071502133696f78aa8 (patch)
treecad1a3757e46ac47962bc76e1175d4149a88e765 /src/cjr_print.sml
parent7b20c054a5362ababbf699e19407ecc38bb747ec (diff)
Factor out cache implementation from Sqlcache.
Diffstat (limited to 'src/cjr_print.sml')
-rw-r--r--src/cjr_print.sml106
1 files changed, 1 insertions, 105 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index 1b1d656d..12ad309a 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -3404,111 +3404,7 @@ fun p_file env (ds, ps) =
newline,
(* For sqlcache. *)
- box (List.map
- (fn {index, params} =>
- let val i = Int.toString index
- fun paramRepeat itemi sep =
- let
- fun f n =
- if n < 0 then ""
- else if n = 0 then itemi (Int.toString 0)
- else f (n-1) ^ sep ^ itemi (Int.toString n)
- in
- f (params - 1)
- end
- fun paramRepeatInit itemi sep =
- if params = 0 then "" else sep ^ paramRepeat itemi sep
- val args = paramRepeatInit (fn p => "uw_Basis_string p" ^ p) ", "
- val decls = paramRepeat (fn p => "uw_Basis_string param" ^ i ^ "_"
- ^ p ^ " = NULL;")
- "\n"
- val sets = paramRepeat (fn p => "param" ^ i ^ "_" ^ p
- ^ " = strdup(p" ^ p ^ ");")
- "\n"
- val frees = paramRepeat (fn p => "free(param" ^ i ^ "_" ^ p ^ ");")
- "\n"
- val eqs = paramRepeatInit (fn p => "strcmp(param" ^ i ^ "_" ^ p
- ^ ", p" ^ p ^ ")")
- " || "
- (* Using [!=] instead of [==] to mimic [strcmp]. *)
- val eqsNull = paramRepeatInit (fn p => "(p" ^ p ^ " == NULL || "
- ^ "!strcmp(param" ^ i ^ "_"
- ^ p ^ ", p" ^ p ^ "))")
- " && "
- in box [string "static char *cacheQuery",
- string i,
- string " = NULL;",
- newline,
- string "static char *cacheWrite",
- string i,
- string " = NULL;",
- newline,
- string decls,
- newline,
- string "static uw_Basis_string uw_Sqlcache_check",
- string i,
- string "(uw_context ctx",
- string args,
- string ") {\n if (cacheQuery",
- string i,
- (* ASK: is returning the pointer okay? Should we duplicate? *)
- string " == NULL",
- string eqs,
- string ") {\n puts(\"SQLCACHE: miss ",
- string i,
- string ".\");\n uw_recordingStart(ctx);\n return NULL;\n } else {\n puts(\"SQLCACHE: hit ",
- string i,
- string ".\");\n uw_write(ctx, cacheWrite",
- string i,
- string ");\n return cacheQuery",
- string i,
- string ";\n } };",
- newline,
- string "static uw_unit uw_Sqlcache_store",
- string i,
- string "(uw_context ctx, uw_Basis_string s",
- string args,
- string ") {\n free(cacheQuery",
- string i,
- string "); free(cacheWrite",
- string i,
- string ");",
- newline,
- string frees,
- newline,
- string "cacheQuery",
- string i,
- string " = strdup(s); cacheWrite",
- string i,
- string " = uw_recordingRead(ctx);",
- newline,
- string sets,
- newline,
- string "puts(\"SQLCACHE: store ",
- string i,
- string ".\");\n return uw_unit_v;\n };",
- newline,
- string "static uw_unit uw_Sqlcache_flush",
- string i,
- string "(uw_context ctx",
- string args,
- string ") {\n if (cacheQuery",
- string i,
- string " != NULL",
- string eqsNull,
- string ") {\n free(cacheQuery",
- string i,
- string ");\n cacheQuery",
- string i,
- string " = NULL;\n puts(\"SQLCACHE: flush ",
- string i,
- string ".\");}\n else { puts(\"SQLCACHE: keep ",
- string i,
- string ".\"); } return uw_unit_v;\n };",
- newline,
- newline]
- end)
- (Sqlcache.getFfiInfo ())),
+ box (List.map ToyCache.setupQuery (Sqlcache.getFfiInfo ())),
newline,
p_list_sep newline (fn x => x) pds,