123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125(* Js_of_ocaml compiler
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2010 Jérôme Vouillon
* Laboratoire PPS - CNRS Université Paris Diderot
*
* 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!Stdlibletaliases=Hashtbl.create17letrecresolvenm=tryresolve(Hashtbl.findaliasesnm)withNot_found->nm(****)typekind=[`Pure|`Mutable|`Mutator]typekind_arg=[`Shallow_const|`Object_literal|`Const|`Mutable]typecondition=[`Ifofstring|`Ifnotofstring]typet=[`Requiresofstringlist|`Providesofstring*kind*kind_arglistoption|`Versionof((int->int->bool)*string)list|`Weakdef|`Always|`Aliasofstring|`Deprecatedofstring|condition]letstring_of_kind=function|`Pure->"pure"|`Mutable->"mutable"|`Mutator->"mutator"letkinds=Hashtbl.create37letkind_args_tbl=Hashtbl.create37letarities=Hashtbl.create37letkindnm=tryHashtbl.findkinds(resolvenm)withNot_found->`Mutatorletkind_argsnm=trySome(Hashtbl.findkind_args_tbl(resolvenm))withNot_found->Noneletaritynm=Hashtbl.findarities(resolvenm)lethas_aritynma=tryHashtbl.findarities(resolvenm)=awithNot_found->falseletis_purenm=matchnmwith|"%identity"|"%direct_int_div"|"%direct_int_mod"|"%direct_int_mul"->true|_->Poly.(kindnm<>`Mutator)letexistsp=Hashtbl.memkindspletexternals=refStringSet.emptyletadd_externalname=externals:=StringSet.addname!externalsletget_external()=!externalsletregisterpkkargsarity=(matchHashtbl.findkinds(resolvep)with|exceptionNot_found->()|k'whenPoly.(k=k')->()|k'->warn"Warning: overriding the purity of the primitive %s: %s -> %s@."p(string_of_kindk')(string_of_kindk));add_externalp;(matcharitywith|Somea->Hashtbl.replacearitiespa|_->());(matchkargswith|Somek->Hashtbl.replacekind_args_tblpk|_->());Hashtbl.replacekindspkletaliasnmnm'=add_externalnm';add_externalnm;Hashtbl.replacealiasesnmnm'letnamed_values=refStringSet.emptyletneed_named_values=StringSet.mems!named_valuesletregister_named_values=named_values:=StringSet.adds!named_valuesletreset()=Hashtbl.clearkinds;Hashtbl.clearkind_args_tbl;Hashtbl.cleararities;Hashtbl.clearaliases;named_values:=StringSet.empty