comparison src/cjr_print.sml @ 288:4260ad920c36

Converting string to int
author Adam Chlipala <adamc@hcoop.net>
date Sun, 07 Sep 2008 11:33:13 -0400
parents c0e4ac23522d
children df00701f2323
comparison
equal deleted inserted replaced
287:3ed7a7c7b060 288:4260ad920c36
88 (box [string "struct", 88 (box [string "struct",
89 space, 89 space,
90 string ("__lwd_" ^ #1 (E.lookupDatatype env n) ^ "_" ^ Int.toString n ^ "*")] 90 string ("__lwd_" ^ #1 (E.lookupDatatype env n) ^ "_" ^ Int.toString n ^ "*")]
91 handle CjrEnv.UnboundNamed _ => string ("__lwd_UNBOUND__" ^ Int.toString n)) 91 handle CjrEnv.UnboundNamed _ => string ("__lwd_UNBOUND__" ^ Int.toString n))
92 | TFfi (m, x) => box [string "lw_", string m, string "_", string x] 92 | TFfi (m, x) => box [string "lw_", string m, string "_", string x]
93 | TOption t =>
94 (case #1 t of
95 TDatatype _ => p_typ' par env t
96 | TFfi ("Basis", "string") => p_typ' par env t
97 | _ => box [p_typ' par env t,
98 string "*"])
93 99
94 and p_typ env = p_typ' false env 100 and p_typ env = p_typ' false env
95 101
96 fun p_rel env n = string ("__lwr_" ^ #1 (E.lookupERel env n) ^ "_" ^ Int.toString (E.countERels env - n - 1)) 102 fun p_rel env n = string ("__lwr_" ^ #1 (E.lookupERel env n) ^ "_" ^ Int.toString (E.countERels env - n - 1))
97 handle CjrEnv.UnboundRel _ => string ("__lwr_UNBOUND_" ^ Int.toString (E.countERels env - n - 1)) 103 handle CjrEnv.UnboundRel _ => string ("__lwr_UNBOUND_" ^ Int.toString (E.countERels env - n - 1))
125 let 131 let
126 val (pp', env) = p_pat_preamble env p 132 val (pp', env) = p_pat_preamble env p
127 in 133 in
128 (box [pp', pp], env) 134 (box [pp', pp], env)
129 end) (box [], env) xps 135 end) (box [], env) xps
136 | PNone _ => (box [], env)
137 | PSome (_, p) => p_pat_preamble env p
130 138
131 fun p_patCon env pc = 139 fun p_patCon env pc =
132 case pc of 140 case pc of
133 PConVar n => p_con_named env n 141 PConVar n => p_con_named env n
134 | PConFfi {mod = m, con, ...} => string ("lw_" ^ m ^ "_" ^ con) 142 | PConFfi {mod = m, con, ...} => string ("lw_" ^ m ^ "_" ^ con)
288 in 296 in
289 (p, env) 297 (p, env)
290 end) env xps 298 end) env xps
291 in 299 in
292 (p_list_sep newline (fn x => x) xps, 300 (p_list_sep newline (fn x => x) xps,
301 env)
302 end
303
304 | PNone t =>
305 (box [string "if",
306 space,
307 string "(disc",
308 string (Int.toString depth),
309 space,
310 string "!=",
311 space,
312 string "NULL)",
313 space,
314 exit,
315 newline],
316 env)
317
318 | PSome (t, p) =>
319 let
320 val (p, env) =
321 let
322 val (p, env) = p_pat (env, exit, depth + 1) p
323 in
324 (box [string "{",
325 newline,
326 p_typ env t,
327 space,
328 string "disc",
329 string (Int.toString (depth + 1)),
330 space,
331 string "=",
332 space,
333 case #1 t of
334 TDatatype _ => box [string "disc",
335 string (Int.toString depth)]
336 | TFfi ("Basis", "string") => box [string "disc",
337 string (Int.toString depth)]
338 | _ => box [string "*disc",
339 string (Int.toString depth)],
340 string ";",
341 newline,
342 p,
343 newline,
344 string "}"],
345 env)
346 end
347 in
348 (box [string "if",
349 space,
350 string "(disc",
351 string (Int.toString depth),
352 space,
353 string "==",
354 space,
355 string "NULL)",
356 space,
357 exit,
358 newline,
359 p],
293 env) 360 env)
294 end 361 end
295 362
296 local 363 local
297 val count = ref 0 364 val count = ref 0