prompt p -> (******************************************) (* Initial version *) let rec fib n = if n<2 then n else (let fn1 = fib (n-1) in let fn2 = fib (n-2) in fn1+fn2) in (******************************************) (* New version *) let rec fib_num n = if n<2 then num_of_int n else (let fn1 = fib_num (n-1) in let fn2 = fib_num (n-2) in fn1+/fn2) in (******************************************) (* update from fixed-size to arbitrary *) (* precision integer *) (* if n is after 44, r has overflowed so *) (* return fib_new n else r is correct *) let ifnotover n r = if n > 44 then fib_num n else r in (* call graph: *) (* fib : L1 -> fib *) (* fib : L2 -> fib *) (* [root]: Lroot -> fib *) (* _ : Lupdt -> update *) (* to the fib node in the call graph: *) let rec match_fib_callers r k = match_cont k with (* - L1: r is fib (n-1) *) as hd :: tl -> (* check whether r has overflowed *) let fn1 = ifnotover (n-1) r in let fn2 = fib_num (n-2) in (* back to the caller: fib *) match_fib_callers (fn1+/fn2) tl (* - L2: r is fib (n-2) & fn1 is fib (n-1)*) | as hd :: tl -> (* check whether fn1 has overflowed *) let nfn1 = ifnotover (n-1) (num_of_int fn1) in (* check whether r has overflowed *) let nfn2 = ifnotover (n-2) r in (* back to the caller: fib *) match_fib_callers (nfn1+/nfn2) tl (* - Lroot: r is the result of the program*) | as hd :: tl -> reinstate tl r | _ -> (* error *) (0/-/1/) in (* compensation fib -> fib_num *) let compensate r k = match_cont k with as hd :: tl -> (* we "know" that we are in fib *) match_fib_callers (num_of_int r) tl | _ -> (* error *) (0/-/2/) in (******************************************) (* main program *) (* register the compensation *) let compensate_ = set_update_routine (fun r -> capture upto p as k in compensate r k) in (* initial call *) num_of_int (fib 12345)