50 val (n, pattern) = print_pattern 0 p |
50 val (n, pattern) = print_pattern 0 p |
51 val pattern = |
51 val pattern = |
52 if exists_string Symbol.is_ascii_blank pattern then "(" ^ pattern ^")" |
52 if exists_string Symbol.is_ascii_blank pattern then "(" ^ pattern ^")" |
53 else pattern |
53 else pattern |
54 |
54 |
55 fun print_term d (Var x) = (*if x < d then "Var "^(str x) else "x"^(str (n-(x-d)-1))*) |
55 fun print_term d (Var x) = "Var " ^ str x |
56 "Var " ^ str x |
|
57 | print_term d (Const c) = "c" ^ str c |
56 | print_term d (Const c) = "c" ^ str c |
58 | print_term d (App (a,b)) = "App (" ^ print_term d a ^ ", " ^ print_term d b ^ ")" |
57 | print_term d (App (a,b)) = "App (" ^ print_term d a ^ ", " ^ print_term d b ^ ")" |
59 | print_term d (Abs c) = "Abs (" ^ print_term (d + 1) c ^ ")" |
58 | print_term d (Abs c) = "Abs (" ^ print_term (d + 1) c ^ ")" |
60 | print_term d (Computed c) = print_term d c |
59 | print_term d (Computed c) = print_term d c |
61 |
60 |
189 case !compiled_rewriter of |
188 case !compiled_rewriter of |
190 NONE => raise (Compile "cannot communicate with compiled function") |
189 NONE => raise (Compile "cannot communicate with compiled function") |
191 | SOME r => (compiled_rewriter := NONE; r) |
190 | SOME r => (compiled_rewriter := NONE; r) |
192 end |
191 end |
193 |
192 |
194 fun compile cache_patterns const_arity eqs = |
193 fun compile _ _ eqs = |
195 let |
194 let |
196 val _ = if exists (fn (a,b,c) => not (null a)) eqs then raise Compile ("cannot deal with guards") else () |
195 val _ = if exists (fn (a,_,_) => not (null a)) eqs then raise Compile ("cannot deal with guards") else () |
197 val eqs = map (fn (a,b,c) => (b,c)) eqs |
196 val eqs = map (fn (_,b,c) => (b,c)) eqs |
198 fun check (p, r) = if check_freevars (count_patternvars p) r then () else raise Compile ("unbound variables in rule") |
197 fun check (p, r) = if check_freevars (count_patternvars p) r then () else raise Compile ("unbound variables in rule") |
199 val _ = map (fn (p, r) => |
198 val _ = map (fn (p, r) => |
200 (check (p, r); |
199 (check (p, r); |
201 case p of PVar => raise (Compile "pattern is just a variable") | _ => ())) eqs |
200 case p of PVar => raise (Compile "pattern is just a variable") | _ => ())) eqs |
202 in |
201 in |
203 load_rules "AM_Compiler" "AM_compiled_code" eqs |
202 load_rules "AM_Compiler" "AM_compiled_code" eqs |
204 end |
203 end |
205 |
204 |
206 fun run prog t = (prog t) |
205 fun run prog t = (prog t) |
207 |
206 |
208 fun discard p = () |
207 fun discard _ = () |
209 |
208 |
210 end |
209 end |
211 |
210 |