123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133(** {1 Stream}*)openLogtkletstat_stream_create=Util.mk_stat"stream.create"letsection=Util.Section.make~parent:Const.section"stm"(** {2 Signature} *)moduletypeS=Stream_intf.SmoduletypeARG=sigmoduleCtx:Ctx.SmoduleC:Clause.SwithmoduleCtx=CtxendmoduleMake(A:ARG)=structmoduleCtx=A.CtxmoduleC=A.Ctypet={id:int;(** unique ID of the stream *)parents:C.tlist;(** parent clauses for inference generating this stream *)mutablepenalty:int;(** heuristic penalty, increased by every drip *)mutablehits:int;(** how many attemts to retrieve unifier were there *)mutablestm:C.toptionOSeq.t;(** the stream itself *)}exceptionEmpty_StreamexceptionDrip_n_UnfinishedofC.toptionlist*int*intletid_count_=ref0(** {2 Basics} *)letmake?penalty:(p=1)~parentss=Util.incr_statstat_stream_create;letid=!id_count_inincrid_count_;{id;penalty=p;hits=0;stm=s;parents}letppouts=Format.fprintfout"stm %i/%i/%i"s.ids.penaltys.hits;()letequals1s2=s1.id=s2.idletcompares1s2=Pervasives.compares1.ids2.idletids=s.idlethashs=Hashtbl.hashs.id(* TODO: does it really pop an element? *)(* normally it should be fine, check with Simon *)letis_emptys=OSeq.is_emptys.stm(* No length function because some streams are infinite *)letpenaltys=s.penaltyletclause_penaltys=function|None->s.hits<-s.hits+1;max2(s.hits-16)|Somec->s.hits<-s.hits+1;max(C.penaltyc)(s.hits-64)letis_orphaneds=List.existsC.is_redundants.parentsletdrips=letorig_penalty=s.penaltyinletres=ifClauseQueue.ignore_orphans()&&is_orphanedsthen(s.penalty<-max_int;s.stm<-OSeq.empty;raiseEmpty_Stream)else(matchs.stm()with|OSeq.Nil->s.penalty<-max_int;raiseEmpty_Stream|OSeq.Cons(hd,tl)->s.stm<-tl;letcl_p=(clause_penaltyshd)ins.penalty<-s.penalty+cl_p;hd)inUtil.debugf~section1"drip:%d->@[%a@]:@. @[%a@]@."(funk->korig_penaltypps(CCOpt.ppC.pp)res);resletdrip_nsnguard=letrec_drip_nstnguard=ifguard=0then(st,0,[])elsematchnwith|0->(st,0,[])|_->matchst()with|OSeq.Nil->raise(Drip_n_Unfinished([],0,n))|OSeq.Cons(hd,tl)->letp=clause_penaltyshdinmatchhdwith|None->(trylet(s',p_tl,tl_res)=_drip_ntln(guard-1)in(s',p+p_tl,tl_res)with|Drip_n_Unfinished(partial_res,p_partial,n')->raise(Drip_n_Unfinished((hd::partial_res),p+p_partial,n')))|_->(trylet(s',p_tl,tl_res)=_drip_ntl(n-1)(guard-1)in(s',p+p_tl,(hd::tl_res))with|Drip_n_Unfinished(partial_res,p_partial,n')->raise(Drip_n_Unfinished((hd::partial_res),p+p_partial,n')))inletorig_penalty=s.penaltyinletres=trylet(s',p_add,cl)=_drip_ns.stmnguardins.penalty<-s.penalty+p_add;s.stm<-s';clwith|Drip_n_Unfinished(res,p_add,n')->s.stm<-OSeq.empty;s.penalty<-s.penalty+p_add;raise(Drip_n_Unfinished(res,p_add,n'))inUtil.debugf~section1"drip_n:%d->@[%a@]:@. @[%a@]@."(funk->korig_penaltypps(CCList.pp(CCOpt.ppC.pp))res);resend