123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566openCoremoduleField=structmoduleT=structincludeFdd.Fieldletcompare(x:t)(y:t)=Int.compare(Obj.magicx)(Obj.magicy)endincludeTincludeComparator.Make(T)endmoduleT0=structtypet=int64Base.Map.M(Field).t[@@derivingcompare,sexp,hash]endmoduleT=structincludeT0includeComparator.Make(T0)endincludeTletempty=Map.empty(moduleField)letapply_action_seq(seq:Fdd.Value.tFdd.Action.Seq.t)(pk:t):t=Map.to_alistseq|>List.fold~init:pk~f:(funpk->function|Ff,Constv->Map.setpk~key:f~data:v|F_,_->failwith"unexpected action"|K,_->pk)letapply_action(act:Fdd.Action.t)(pk:t):Set.M(T).t=Set.map(moduleT)act~f:(funseq->apply_action_seqseqpk)letrecapply_fdd(fdd:Fdd.FDD.t)(pk:t):Fdd.Action.t=letopenFddinmatchFDD.ungetfddwith|Leafact->act|Branch{test=(f,Constv);tru;fls;_}->beginmatchMap.findpkfwith|None->Field.to_stringf|>Format.sprintf"packet underspecified: missing value for field %s"|>failwith|Somev'->ifInt64.equalvv'thenapply_fddtrupkelseapply_fddflspkend|Branch_->failwith"only constant tests supported"leteval_e_fdd(e:Fdd.FDD.t)(pk:t):Set.M(T).t=letact=apply_fddepkinapply_actionactpkleteval_d_fdd(d:Fdd.FDD.t)(pk:t):int64Map.M(T).t=apply_fdddpk|>Set.to_list|>List.map~f:(funseq->matchMap.findseqFdd.Action.Kwith|Some(Constv)->(apply_action_seqseqpk,v)|_->failwith "malformed D-FDD; continuation missing or invalid")|>Map.of_alist_exn (moduleT)