src/Pure/Tools/nbe_codegen.ML
changeset 19795 746274ca400b
parent 19482 9f11af8f7ef9
child 19830 b81d803dfaa4
equal deleted inserted replaced
19794:100ba10eee64 19795:746274ca400b
   139       end
   139       end
   140   | generate _ _ = "";
   140   | generate _ _ = "";
   141 
   141 
   142 open NBE_Eval;
   142 open NBE_Eval;
   143 
   143 
       
   144 val tcount = ref 0;
       
   145 
       
   146 (* FIXME get rid of TVar case!!! *)
       
   147 fun varifyT ty =
       
   148   let val ty' = map_type_tvar (fn ((s,i),S) => TypeInfer.param (!tcount + i) (s,S)) ty;
       
   149       val _ = (tcount := !tcount + maxidx_of_typ ty + 1);
       
   150       val ty'' = map_type_tfree (TypeInfer.param (!tcount)) ty'
       
   151   in tcount := !tcount+1; ty'' end;
       
   152 
   144 fun nterm_to_term thy t =
   153 fun nterm_to_term thy t =
   145   let
   154   let
   146     fun consts_of (C s) = insert (op =) s
   155     fun consts_of (C s) = insert (op =) s
   147       | consts_of (V _) = I
   156       | consts_of (V _) = I
   148       | consts_of (B _) = I
   157       | consts_of (B _) = I
   149       | consts_of (A (t1, t2)) = consts_of t1 #> consts_of t2
   158       | consts_of (A (t1, t2)) = consts_of t1 #> consts_of t2
   150       | consts_of (AbsN (_, t)) = consts_of t;
   159       | consts_of (AbsN (_, t)) = consts_of t;
   151     val consts = consts_of t [];
   160     val consts = consts_of t [];
   152     val the_const = the o AList.lookup (op =)
   161     val ctab = consts ~~ CodegenPackage.consts_of_idfs thy consts;
   153       (consts ~~ CodegenPackage.consts_of_idfs thy consts);
   162     val the_const = apsnd varifyT o the o AList.lookup (op =) ctab;
   154     fun to_term bounds (C s) = Const (the_const s)
   163     fun to_term bounds (C s) = Const (the_const s)
   155       | to_term bounds (V s) = Free (s, dummyT)
   164       | to_term bounds (V s) = Free (s, dummyT)
   156       | to_term bounds (B i) = Bound (find_index (fn j => i = j) bounds)
   165       | to_term bounds (B i) = Bound (find_index (fn j => i = j) bounds)
   157       | to_term bounds (A (t1, t2)) = to_term bounds t1 $ to_term bounds t2
   166       | to_term bounds (A (t1, t2)) = to_term bounds t1 $ to_term bounds t2
   158       | to_term bounds (AbsN (i, t)) =
   167       | to_term bounds (AbsN (i, t)) =
   159           Abs("u", dummyT, to_term (i::bounds) t);
   168           Abs("u", dummyT, to_term (i::bounds) t);
   160   in to_term [] t end;
   169   in tcount := 0; to_term [] t end;
   161 
   170 
   162 end;
   171 end;