summaryrefslogtreecommitdiff
path: root/src/cjr_print.sml
diff options
context:
space:
mode:
authorGravatar Ziv Scully <ziv@mit.edu>2014-11-10 22:04:40 -0500
committerGravatar Ziv Scully <ziv@mit.edu>2014-11-10 22:04:40 -0500
commitdc5e7102563b9c0714391f86b6dcf852445ee192 (patch)
treec3d3413da82cff5b180dd917ad98e4963a48d64c /src/cjr_print.sml
parent7b94f3433f47e4e5010dc2af6010181da49637e8 (diff)
Progress towards invalidation based on equalities of fields.
Diffstat (limited to 'src/cjr_print.sml')
-rw-r--r--src/cjr_print.sml23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index c150631c..56310b81 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -3400,19 +3400,24 @@ fun p_file env (ds, ps) =
let val i = Int.toString index
fun paramRepeat itemi sep =
let
- val rec f =
- fn 0 => itemi (Int.toString 0)
- | n => f (n-1) ^ itemi (Int.toString n)
+ 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
- val args = paramRepeat (fn p => "uw_Basis_string p" ^ p) ", "
+ 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 = paramRepeat (fn p => "strcmp(param" ^ i ^ "_" ^ p
- ^ ", p" ^ p ^ ")") " || "
+ (* Starting || makes logic easier when there are no parameters. *)
+ val eqs = paramRepeatInit (fn p => "strcmp(param" ^ i ^ "_" ^ p
+ ^ ", p" ^ p ^ ")")
+ " || "
in box [string "static char *cacheQuery",
string i,
string " = NULL;",
@@ -3425,14 +3430,14 @@ fun p_file env (ds, ps) =
newline,
string "static uw_Basis_string uw_Sqlcache_check",
string i,
- string "(uw_context ctx, ",
+ string "(uw_context ctx",
string args,
string ") {\n puts(\"SQLCACHE: checked ",
string i,
string ".\");\n if (cacheQuery",
string i,
(* ASK: is returning the pointer okay? Should we duplicate? *)
- string " == NULL || ",
+ string " == NULL",
string eqs,
string ") {\n puts(\"miss D:\");\n uw_recordingStart(ctx);\n return NULL;\n } else {\n puts(\"hit :D\");\n uw_write(ctx, cacheWrite",
string i,
@@ -3442,7 +3447,7 @@ fun p_file env (ds, ps) =
newline,
string "static uw_unit uw_Sqlcache_store",
string i,
- string "(uw_context ctx, uw_Basis_string s, ",
+ string "(uw_context ctx, uw_Basis_string s",
string args,
string ") {\n free(cacheQuery",
string i,