12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(* 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!Stdlibtypet=string*intexceptionBad_magic_numberofstringexceptionBad_magic_versionoftletsize=12letkind_of_string=function|"Caml1999X"->"exe"|"Caml1999I"->"cmi"|"Caml1999O"->"cmo"|"Caml1999A"->"cma"|"Caml1999Y"->"cmx"|"Caml1999Z"->"cmxa"|"Caml2007D"->"cmxs"|"Caml2012T"->"cmt"|"Caml1999M"->"impl"|"Caml1999N"->"intf"|_->raiseNot_foundletof_strings=tryifString.lengths<>sizethenraiseNot_found;letkind=String.subs~pos:0~len:9inletv=String.subs~pos:9~len:3inlet_=kind_of_stringkindinkind,int_of_stringvwith_->raise(Bad_magic_numbers)letkind(s,_)=matchkind_of_stringswith|"exe"->`Exe|"cmo"->`Cmo|"cma"->`Cma|other->`Otherotherletto_string(k,v)=Printf.sprintf"%s%03d"kvletcompare(p1,n1)(p2,n2)=matchString.comparep1p2with|0->comparen1n2|n->nletequalab=compareab=0letv=letcurrent=Ocaml_version.currentinmatchcurrentwith|4::08::_->25|4::09::_->26|4::10::_->27|4::11::_->28|4::12::_->29|4::13::_->30|4::14::_->31|5::00::_->32|5::01::_->33|5::02::_->34|5::03::_->35|_->ifOcaml_version.comparecurrent[4;8]<0thenfailwith"OCaml version unsupported. Upgrade to OCaml 4.08 or newer."else(assert(Ocaml_version.comparecurrent[5;4]>=0);failwith"OCaml version unsupported. Upgrade js_of_ocaml.")letcurrent_exe="Caml1999X",vletcurrent_cmo="Caml1999O",vletcurrent_cma="Caml1999A",vletcurrent=function|`Exe->current_exe|`Cmo->current_cmo|`Cma->current_cma