Commits

camlspotter committed b2e9d96

start to add lazy type special compilation

  • Participants
  • Parent commits 2568d25
  • Branches coinductive_type

Comments (0)

Files changed (3)

bytecomp/translcore.ml

 
 (* Translation of expressions *)
 
+(* CR jfuruse: move to somewhere else *)
+let is_lazy_type env t = 
+  match (Ctype.repr t).desc with
+  | Tconstr (p, _, _) ->
+      (try (Env.find_type p env).type_lazy with Not_found -> assert false)
+  | _ -> assert false
+
 let rec transl_exp e =
   let eval_once =
     (* Whether classes for immediate objects must be cached *)
       with Not_constant ->
         Lprim(Pmakeblock(0, Immutable), ll)
       end
+  | Texp_construct(cstr, args) when is_lazy_type e.exp_env cstr.cstr_res ->
+      let ll = transl_list args in
+      begin match cstr.cstr_tag with
+        Cstr_constant n ->
+          Lconst(Const_pointer n)
+      | Cstr_block n ->
+          begin try
+            Lconst(Const_block(n, List.map extract_constant ll))
+          with Not_constant ->
+            Lprim(Pmakeblock(n, Immutable), ll)
+          end
+      | Cstr_exception path ->
+          Lprim(Pmakeblock(0, Immutable), transl_path path :: ll)
+      end
   | Texp_construct(cstr, args) ->
       let ll = transl_list args in
       begin match cstr.cstr_tag with

typing/includecore.ml

   | Kind
   | Constraint
   | Manifest
+  | Lazy
   | Variance
   | Field_type of string
   | Field_mutable of string
   | Kind -> pr "Their kinds differ"
   | Constraint -> pr "Their constraints differ"
   | Manifest -> ()
+  | Lazy -> pr "Their lazyness do not agree"
   | Variance -> pr "Their variances do not agree"
   | Field_type s ->
       pr "The types for field %s are not equal" s
         else [Constraint]
   in
   if err <> [] then err else
+  if decl1.type_lazy <> decl2.type_lazy then [Lazy] else  
   if match decl2.type_kind with
   | Type_record (_,_) | Type_variant _ -> decl2.type_private = Private
   | Type_abstract ->

typing/includecore.mli

   | Kind
   | Constraint
   | Manifest
+  | Lazy
   | Variance
   | Field_type of string
   | Field_mutable of string