1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162(* This file is part of ppx_cstubs (https://github.com/fdopen/ppx_cstubs)
* Copyright (c) 2018-2019 fdopen
*
* 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.
*)openStd.Resultletreal_inittop=Main.inittopincludePpxc__script_reallet_inittop=lettop=matchtopwith|Somet->t|None->objectmethodevalexpr=letp1=Merlin_state.to_child()inlets=Marshal.to_string(p1,expr)[]inletb=Buffer.create8192inletprog=ifSys.win32then"ppx_cstubs.exe"else"ppx_cstubs"inletargs=["--run-merlin-top"]inleteb=Buffer.create128inletec=matchRun.run~stdin:(`Strings)~stdout:(`Bufferb)~stderr:(`Buffereb)progargswith|exception(Unix.Unix_error_ase)->Std.Util.error"failed to call ppx_cstubs: %s\n"(Printexc.to_stringe)|x->xinifec<>0thenBuffer.contentseb|>Std.Util.error"ipc error: child exit with %d (%S)"ec;lets=Buffer.contentsbinmatchMarshal.from_strings0with|exception((Failure_|Invalid_argument_)ase)->Std.Util.error"ipc error: marshaling from ppx_cstubs failed: %s"(Printexc.to_stringe)|Oks->Merlin_state.from_childs|Errore->Merlin_state.raise_erroremethodinit~nopervasives:_~pkgs:_~use_threads:_~cma_files:_()=()endinreal_inittop