123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113(* Js_of_ocaml library
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2014 Hugo Heuzard
*
* 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.
*)openJs_of_ocaml_compileropenJs_of_ocaml_compiler.Stdlibletsetup=lazy(Topdirs.dir_directory"/static/cmis";Toploop.add_directive"enable"(Toploop.Directive_stringConfig.Flag.enable){section="js_of_ocaml";doc="Enable the given flag"};Toploop.add_directive"disable"(Toploop.Directive_stringConfig.Flag.disable){section="js_of_ocaml";doc="Disable the given flag"};Toploop.add_directive"debug_on"(Toploop.Directive_stringDebug.enable){section="js_of_ocaml";doc="Enable debug for the given section"};Toploop.add_directive"debug_off"(Toploop.Directive_stringDebug.disable){section="js_of_ocaml";doc="Disable debug for the given section"};Toploop.add_directive"tailcall"(Toploop.Directive_string(Config.Param.set"tc")){section="js_of_ocaml";doc="Set the depth of tail calls before going through a trampoline"})letrefill_lexbufspppfbufferlen=if!p=String.lengthsthen0elseletlen',nl=tryString.index_froms!p'\n'-!p+1,falsewith_->String.lengths-!p,trueinletlen''=minlenlen'inString.blit~src:s~src_pos:!p~dst:buffer~dst_pos:0~len:len'';(matchppfwith|Someppf->Format.fprintfppf"%s"(Bytes.sub_stringbuffer~pos:0~len:len'');ifnlthenFormat.pp_print_newlineppf();Format.pp_print_flushppf()|None->());p:=!p+len'';len''letuseffpcontent=letfname,oc=Filename.open_temp_file~mode:[Open_binary]"jsoo_toplevel""fake_stdin"inoutput_stringoccontent;close_outoc;tryletb=Toploop.use_silentlyffpfnameinSys.removefname;bwithe->Sys.removefname;raisee[@@ifocaml_version<(4,14,0)]letuseffpcontent=Toploop.use_silentlyffp(Stringcontent)[@@ifocaml_version>=(4,14,0)]letexecuteprintval?pp_code?highlight_locationpp_answers=letlb=Lexing.from_function(refill_lexbufs(ref0)pp_code)in(trywhiletruedotryletphr=!Toploop.parse_toplevel_phraselbinletphr=JsooTopPpx.preprocess_phrasephrinignore(Toploop.execute_phraseprintvalpp_answerphr:bool)with|End_of_file->raiseEnd_of_file|x->(matchhighlight_locationwith|None->()|Somef->(matchJsooTopError.locxwith|None->()|Someloc->floc));Errors.report_errorFormat.err_formatterxdonewithEnd_of_file->());flush_all()letinitialize()=Sys.interactive:=false;Lazy.forcesetup;Toploop.initialize_toplevel_env();Toploop.input_name:="//toplevel//";Sys.interactive:=true