src/Pure/Syntax/syn_trans.ML
changeset 639 c88d56f7f33b
parent 616 2b1e384fae33
child 922 196ca0973a6d
equal deleted inserted replaced
638:7f25cc9067e7 639:c88d56f7f33b
   112 (* meta implication *)
   112 (* meta implication *)
   113 
   113 
   114 fun bigimpl_ast_tr (*"_bigimpl"*) [asms, concl] =
   114 fun bigimpl_ast_tr (*"_bigimpl"*) [asms, concl] =
   115       fold_ast_p "==>" (unfold_ast "_asms" asms, concl)
   115       fold_ast_p "==>" (unfold_ast "_asms" asms, concl)
   116   | bigimpl_ast_tr (*"_bigimpl"*) asts = raise_ast "bigimpl_ast_tr" asts;
   116   | bigimpl_ast_tr (*"_bigimpl"*) asts = raise_ast "bigimpl_ast_tr" asts;
   117 
       
   118 
       
   119 (* explode strings *)
       
   120 
       
   121 fun explode_tr (*"_explode"*) (ts as [consC, nilC, bit0, bit1, txt]) =
       
   122       let
       
   123         fun mk_list [] = nilC
       
   124           | mk_list (t :: ts) = consC $ t $ mk_list ts;
       
   125 
       
   126         fun encode_bit 0 = bit0
       
   127           | encode_bit 1 = bit1
       
   128           | encode_bit _ = sys_error "encode_bit";
       
   129 
       
   130         fun encode_char c =
       
   131           let val bits = radixpand (2, ord c) in
       
   132             mk_list (map encode_bit (replicate (8 - length bits) 0 @ bits))
       
   133           end;
       
   134 
       
   135         val str =
       
   136           (case txt of
       
   137             Free (s, _) => s
       
   138           | Const (s, _) => s
       
   139           | _ => raise_term "explode_tr" ts);
       
   140       in
       
   141         mk_list (map encode_char (explode str))
       
   142       end
       
   143   | explode_tr (*"_explode"*) ts = raise_term "explode_tr" ts;
       
   144 
   117 
   145 
   118 
   146 
   119 
   147 (** print (ast) translations **)
   120 (** print (ast) translations **)
   148 
   121 
   274         in list_comb (const q $ Free (x', T) $ A $ B', ts) end
   247         in list_comb (const q $ Free (x', T) $ A $ B', ts) end
   275       else list_comb (const r $ A $ B, ts)
   248       else list_comb (const r $ A $ B, ts)
   276   | dependent_tr' _ _ = raise Match;
   249   | dependent_tr' _ _ = raise Match;
   277 
   250 
   278 
   251 
   279 (* implode strings *)
       
   280 
       
   281 fun implode_ast_tr' (*"_implode"*) (asts as [Constant cons_name, nilC,
       
   282     bit0, bit1, bitss]) =
       
   283       let
       
   284         fun err () = raise_ast "implode_ast_tr'" asts;
       
   285 
       
   286         fun strip_list lst =
       
   287           let val (xs, y) = unfold_ast_p cons_name lst
       
   288           in if y = nilC then xs else err ()
       
   289           end;
       
   290 
       
   291         fun decode_bit bit =
       
   292           if bit = bit0 then "0"
       
   293           else if bit = bit1 then "1"
       
   294           else err ();
       
   295 
       
   296         fun decode_char bits =
       
   297           chr (#1 (scan_radixint (2, map decode_bit (strip_list bits))));
       
   298       in
       
   299         Variable ("''" ^ implode (map decode_char (strip_list bitss)) ^ "''")
       
   300       end
       
   301   | implode_ast_tr' (*"_implode"*) asts = raise_ast "implode_ast_tr'" asts;
       
   302 
       
   303 
       
   304 
   252 
   305 (** pure_trfuns **)
   253 (** pure_trfuns **)
   306 
   254 
   307 val pure_trfuns =
   255 val pure_trfuns =
   308  ([(applC, appl_ast_tr), ("_lambda", lambda_ast_tr), ("_idtyp", idtyp_ast_tr),
   256  ([(applC, appl_ast_tr), ("_lambda", lambda_ast_tr), ("_idtyp", idtyp_ast_tr),
   309     ("_bigimpl", bigimpl_ast_tr)],
   257     ("_bigimpl", bigimpl_ast_tr)],
   310   [("_abs", abs_tr), ("_aprop", aprop_tr), ("_ofclass", ofclass_tr),
   258   [("_abs", abs_tr), ("_aprop", aprop_tr), ("_ofclass", ofclass_tr), ("_K", k_tr)],
   311     ("_K", k_tr), ("_explode", explode_tr)],
       
   312   [],
   259   [],
   313   [("_abs", abs_ast_tr'), ("_idts", idts_ast_tr'), ("==>", impl_ast_tr'),
   260   [("_abs", abs_ast_tr'), ("_idts", idts_ast_tr'), ("==>", impl_ast_tr')]);
   314     ("_implode", implode_ast_tr')]);
       
   315 
   261 
   316 
   262 
   317 
   263 
   318 (** pt_to_ast **)
   264 (** pt_to_ast **)
   319 
   265