Mercurial > urweb
comparison src/lru_cache.sml @ 2281:75cb60a7f6f1
Simplify C interface.
author | Ziv Scully <ziv@mit.edu> |
---|---|
date | Thu, 12 Nov 2015 09:15:50 -0500 |
parents | 32a407902d3b |
children | 472b4504aef2 |
comparison
equal
deleted
inserted
replaced
2280:985c8016b592 | 2281:75cb60a7f6f1 |
---|---|
60 | 60 |
61 val typedArgs = paramRepeatInit (fn p => "uw_Basis_string p" ^ p) ", " | 61 val typedArgs = paramRepeatInit (fn p => "uw_Basis_string p" ^ p) ", " |
62 | 62 |
63 val revArgs = paramRepeatRev (fn p => "p" ^ p) ", " | 63 val revArgs = paramRepeatRev (fn p => "p" ^ p) ", " |
64 | 64 |
65 val numArgs = Int.toString params | |
66 | |
67 in | 65 in |
68 Print.box | 66 Print.box |
69 [string ("static uw_Sqlcache_Cache cacheStruct" ^ i ^ " = {"), | 67 [string ("static uw_Sqlcache_Cache cacheStruct" ^ i ^ " = {"), |
70 newline, | 68 newline, |
71 string " .table = NULL,", | 69 string " .table = NULL,", |
70 newline, | |
71 string (" .numKeys = " ^ Int.toString params ^ ","), | |
72 newline, | 72 newline, |
73 string " .timeInvalid = 0,", | 73 string " .timeInvalid = 0,", |
74 newline, | 74 newline, |
75 string " .timeNow = 0};", | 75 string " .timeNow = 0};", |
76 newline, | 76 newline, |
81 string ("static uw_Basis_string uw_Sqlcache_check" ^ i), | 81 string ("static uw_Basis_string uw_Sqlcache_check" ^ i), |
82 string ("(uw_context ctx" ^ typedArgs ^ ") {"), | 82 string ("(uw_context ctx" ^ typedArgs ^ ") {"), |
83 newline, | 83 newline, |
84 string (" char *ks[] = {" ^ revArgs ^ "};"), | 84 string (" char *ks[] = {" ^ revArgs ^ "};"), |
85 newline, | 85 newline, |
86 string " uw_Sqlcache_Value *v = ", | 86 string (" uw_Sqlcache_Value *v = uw_Sqlcache_check(cache" ^ i ^ ", ks);"), |
87 string ("uw_Sqlcache_check(cache" ^ i ^ ", ks, " ^ numArgs ^ ");"), | |
88 newline, | 87 newline, |
89 (* If the output is null, it means we had too much recursion, so it's a miss. *) | 88 (* If the output is null, it means we had too much recursion, so it's a miss. *) |
90 string " if (v && v->output != NULL) {", | 89 string " if (v && v->output != NULL) {", |
91 newline, | 90 newline, |
92 string (" puts(\"SQLCACHE: hit " ^ i ^ ".\");"), | 91 string (" puts(\"SQLCACHE: hit " ^ i ^ ".\");"), |
120 newline, | 119 newline, |
121 string " v->output = uw_recordingRead(ctx);", | 120 string " v->output = uw_recordingRead(ctx);", |
122 newline, | 121 newline, |
123 string (" puts(\"SQLCACHE: stored " ^ i ^ ".\");"), | 122 string (" puts(\"SQLCACHE: stored " ^ i ^ ".\");"), |
124 newline, | 123 newline, |
125 string (" uw_Sqlcache_store(cache" ^ i ^ ", ks, " ^ numArgs ^ ", v);"), | 124 string (" uw_Sqlcache_store(cache" ^ i ^ ", ks, v);"), |
126 newline, | 125 newline, |
127 string " return uw_unit_v;", | 126 string " return uw_unit_v;", |
128 newline, | 127 newline, |
129 string "}", | 128 string "}", |
130 newline, | 129 newline, |
133 string ("static uw_unit uw_Sqlcache_flush" ^ i), | 132 string ("static uw_unit uw_Sqlcache_flush" ^ i), |
134 string ("(uw_context ctx" ^ typedArgs ^ ") {"), | 133 string ("(uw_context ctx" ^ typedArgs ^ ") {"), |
135 newline, | 134 newline, |
136 string (" char *ks[] = {" ^ revArgs ^ "};"), | 135 string (" char *ks[] = {" ^ revArgs ^ "};"), |
137 newline, | 136 newline, |
138 string (" uw_Sqlcache_flush(cache" ^ i ^ ", ks, " ^ numArgs ^ ");"), | 137 string (" uw_Sqlcache_flush(cache" ^ i ^ ", ks);"), |
139 newline, | 138 newline, |
140 string " return uw_unit_v;", | 139 string " return uw_unit_v;", |
141 newline, | 140 newline, |
142 string "}", | 141 string "}", |
143 newline, | 142 newline, |