123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105openBasemodulePath:sigtypetvalempty:tvalappend:t->string->tvalnames:t->stringlistend=structtypet=stringlistletempty=[]letappendtv=v::tletnamest=List.revtendtypet={path:Path.t;types:unitIdent.Tbl.t;modules:unitIdent.Tbl.t;parent:toption}letpatht=t.pathletcreate()={path=Path.empty;types=Ident.Tbl.create4;modules=Ident.Tbl.create4;parent=None};;letenter_modulet~module_ident=letmodule_t={path=Path.appendt.path(Ident.namemodule_ident);types=Ident.Tbl.create4;modules=Ident.Tbl.create4;parent=Somet}inIdent.Tbl.replacet.modulesmodule_ident();module_t;;letadd_typet~type_ident=Ident.Tbl.replacet.typestype_ident()letfind_typet~type_ident=letrecwalkt=ifIdent.Tbl.memt.typestype_identthenSomet.pathelse(matcht.parentwith|None->None|Someparent->walkparent)inwalkt;;letfind_modulet~module_ident=letrecwalkt=ifIdent.Tbl.memt.modulesmodule_identthenSomet.pathelse(matcht.parentwith|None->None|Someparent->walkparent)inwalkt;;let%expect_test"module-env"=letpath_to_stringpath=Path.namespath|>String.concat~sep:"."inlett=create()inletident_t=Ident.create_local"t"inletident_t2=Ident.create_local"t"inletident_u=Ident.create_local"u"inletident_v=Ident.create_local"v"inletident_w=Ident.create_local"w"inletmodule_ident=Ident.create_local"module-ident"inadd_typet~type_ident:ident_t;add_typet~type_ident:ident_u;add_typet~type_ident:ident_v;letsubmodule_t=enter_modulet~module_identinadd_typesubmodule_t~type_ident:ident_t2;add_typesubmodule_t~type_ident:ident_u;letfind_and_printident=matchfind_typesubmodule_t~type_ident:identwith|None->Stdio.printf"cannot find %s\n"(Ident.nameident)|Somepath->Stdio.printf"found %s.%s\n"(path_to_stringpath)(Ident.nameident)infind_and_printident_t;find_and_printident_t2;find_and_printident_u;find_and_printident_v;find_and_printident_w;[%expect{|
found .t
found module-ident.t
found module-ident.u
found .v
cannot find w
|}];;