12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455(* Js_of_ocaml compiler
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2019 Ty Overby, Jane Street Group LLC
*
* 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!Stdlibclassmacro_mapper=object(m)inheritJs_traverse.mapassupermethodexpressionx=letmoduleJ=Javascriptinmatchxwith|J.ECall(J.EVar(J.S{name;_}),args,_)->(matchname,argswith|"BLOCK",(J.ENumtag,`Not_spread)::(_::_asargs)whenList.for_allargs~f:(function|_,`Not_spread->true|_->false)->lettag=Int32.to_int(J.Num.to_int32tag)inletargs=List.mapargs~f:(fun(e,_)->m#expressione)inMlvalue.Block.make~tag~args|"TAG",[(e,`Not_spread)]->Mlvalue.Block.tag(m#expressione)|"LENGTH",[(e,`Not_spread)]->Mlvalue.Array.length(m#expressione)|"FIELD",[(e,`Not_spread);(J.ENumn,`Not_spread)]->letidx=Int32.to_int(J.Num.to_int32n)inMlvalue.Block.field(m#expressione)idx|"FIELD",[_;(J.EUn(J.Neg,_),`Not_spread)]->failwith"Negative field indexes are not allowed"|"ISBLOCK",[(e,`Not_spread)]->Mlvalue.is_block(m#expressione)|("BLOCK"|"TAG"|"LENGTH"|"FIELD"|"ISBLOCK"),_->failwith(Format.sprintf"macro %s called with inappropriate arguments"name)|_->super#expressionx)|_->super#expressionxendletfjs=lettrav=newmacro_mapperintrav#programjs