123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148(* Js_of_ocaml compiler
* http://www.ocsigen.org/js_of_ocaml/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)open!Stdlibletrecconstant_of_const:_->Code.constant=letopenLambdainletopenAsttypesinfunction|Const_base(Const_inti)->Int(Int32.of_int_warning_on_overflowi)|Const_base(Const_charc)->Int(Int32.of_int(Char.codec))|((Const_base(Const_string(s,_)))[@ifocaml_version<(4,11,0)])|((Const_base(Const_string(s,_,_)))[@ifocaml_version>=(4,11,0)])->Strings|Const_base(Const_floats)->Float(float_of_strings)|Const_base(Const_int32i)->Inti|Const_base(Const_int64i)->Int64i|Const_base(Const_nativeinti)->Int(Int32.of_nativeint_warning_on_overflowi)|Const_immstrings->Strings|Const_float_arraysl->letl=List.map~f:(funf->Code.Float(float_of_stringf))slinTuple(Obj.double_array_tag,Array.of_listl,Unknown)|((Const_pointeri)[@ifocaml_version<(4,12,0)])->Int(Int32.of_int_warning_on_overflowi)|Const_block(tag,l)->letl=Array.of_list(List.mapl~f:constant_of_const)inTuple(tag,l,Unknown)letrecfind_loc_in_summaryident'=function|Env.Env_empty->None|Env.Env_value(_summary,ident,description)whenPoly.(ident=ident')->Somedescription.Types.val_loc|Env.Env_value(summary,_,_)|Env.Env_type(summary,_,_)|Env.Env_extension(summary,_,_)|Env.Env_module(summary,_,_,_)|Env.Env_modtype(summary,_,_)|Env.Env_class(summary,_,_)|Env.Env_cltype(summary,_,_)|Env.Env_open(summary,_)|Env.Env_functor_arg(summary,_)|Env.Env_constraints(summary,_)|((Env.Env_copy_types(summary,_))[@ifocaml_version<(4,10,0)])|((Env.Env_copy_typessummary)[@ifocaml_version>=(4,10,0)])|Env.Env_persistent(summary,_)|((Env.Env_value_unbound(summary,_,_))[@ifocaml_version>=(4,10,0)])|((Env.Env_module_unbound(summary,_,_))[@ifocaml_version>=(4,10,0)])->find_loc_in_summaryident'summarymoduleSymtable=struct(* Copied from ocaml/bytecomp/symtable.ml *)moduleNum_tbl(M:Map.S)=struct[@@@ocaml.warning"-32"]typet={cnt:int;(* The next number *)tbl:intM.t(* The table of already numbered objects *)}letempty={cnt=0;tbl=M.empty}letfindkeynt=M.findkeynt.tblletiterfnt=M.iterfnt.tblletfoldfnta=M.foldfnt.tblaletenterntkey=letn=!nt.cntinnt:={cnt=n+1;tbl=M.addkeyn!nt.tbl};nletincrnt=letn=!nt.cntinnt:={cnt=n+1;tbl=!nt.tbl};nendmoduleGlobalMap=structmoduleGlobalMap=Num_tbl(Ident.Map)includeGlobalMapletfilter_global_map(p:Ident.t->bool)(gmap:t)=letnewtbl=refIdent.Map.emptyinIdent.Map.iter(funidnum->ifpidthennewtbl:=Ident.Map.addidnum!newtbl)gmap.tbl;{cnt=gmap.cnt;tbl=!newtbl}endletreloc_identname=letbuf=Bytes.create4inlet()=trySymtable.patch_object[|buf|][Reloc_getglobal(Ident.create_persistentname),0]with_->Symtable.patch_object[|buf|][Reloc_setglobal(Ident.create_persistentname),0]inletgeti=Char.code(Bytes.getbufi)inletn=get0+(get1lsl8)+(get2lsl16)+(get3lsl24)innendmoduleIdent=struct[@@@ocaml.warning"-unused-field"](* Copied from ocaml/typing/ident.ml *)type'atbl'=|Empty|Nodeof'atbl'*'adata*'atbl'*intand'adata={ident:Ident.t;data:'a;previous:'adataoption}type'atbl='aIdent.tblletrectable_contents_rectrem=matchtwith|Empty->rem|Node(l,v,r,_)->table_contents_recl((v.data,v.ident)::table_contents_recrrem)lettable_contents(t:'atbl)=table_contents_rec(Obj.magic(t:'atbl):'atbl')[]end