123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120(* 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(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"})letinit_loclbfilename=Location.initlbfilename;(* [Location.init] points [input_lexbuf] at [lb]; clear it so rendered errors
do not inline a source excerpt (locations are reported on their own). *)Location.input_lexbuf:=None(* Reimplements [Toploop.use_silently] so that the toplevel's in-process ppx
rewriters are applied (via [Ppx.preprocess_phrase]); [use_silently] only
knows about external [-ppx] executables, which cannot run in the browser. *)letuse?(print_outcome=false)ffpcontent=letlb=Lexing.from_stringcontentininit_loclb"//toplevel//";tryList.iter~f:(funphr->ifnot(Toploop.execute_phraseprint_outcomeffpphr)thenraiseExitelseFormat.pp_print_flushffp())(List.map~f:Ppx.preprocess_phrase(!Toploop.parse_use_filelb));flush_all();truewith|Exit->flush_all();false|x->flush_all();Errors.report_errorffpx;falseletexecuteprintval?pp_code?highlight_locationpp_answers=letlb=Lexing.from_function(Refill.lexbufs(ref0)pp_code)ininit_loclb"//toplevel//";(trywhiletruedotryletphr=!Toploop.parse_toplevel_phraselbinletphr=Ppx.preprocess_phrasephrinignore(Toploop.execute_phraseprintvalpp_answerphr:bool)with|End_of_file->raiseEnd_of_file|x->(matchhighlight_locationwith|None->()|Somef->(matchError_loc.locxwith|None->()|Someloc->floc));Errors.report_errorFormat.err_formatterxdonewithEnd_of_file->());flush_all()letinitialized=reffalseletreset_toplevel_env()=(* Register the directory holding the runtime cmi bundles both before and
after [initialize_toplevel_env]: before, so building the environment can
load Stdlib from there; after, because [initialize_toplevel_env] resets the
load path and later lookups of other libraries would otherwise fail. *)Topdirs.dir_directory"/static/cmis";Toploop.initialize_toplevel_env();Topdirs.dir_directory"/static/cmis"letinitialize()=ifnot!initializedthen(initialized:=true;Sys.interactive:=false;Lazy.forcesetup;reset_toplevel_env();Toploop.input_name:="//toplevel//";Sys.interactive:=true)