Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file defun.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343open!Core_kernelopen!Async_kernelopen!ImportincludeDefun_intfmoduleQ=structletdefalias="defalias"|>Symbol.internendmoduleF=structopen!Funcallopen!Value.Typeletdefalias=Q.defalias<:Symbol.type_@->Symbol.type_@->optionstring@->returnnil;;endmoduleT0=structtype_t=|Return:'a->'at|Map:'at*('a->'b)->'bt|Both:'at*'bt->('a*'b)t|Required:Symbol.t*'aValue.Type.t->'at|Optional:Symbol.t*'aoptionValue.Type.t->'aoptiont|Rest:Symbol.t*'aValue.Type.t->'alisttletrecsexp_of_t:typea.(a->Sexp.t)->at->Sexp.t=funsexp_of_a->function|Returna->[%message"Return"~_:(a:a)]|Map(t,_)->[%message"Map"~_:(t:_t)]|Both(t1,t2)->[%message"Both"~_:(t1:_t)~_:(t2:_t)]|Required(symbol,type_)->[%message"Required"~_:(symbol:Symbol.t)~_:(type_:aValue.Type.t)]|Optional(symbol,type_)->[%message"Optional"~_:(symbol:Symbol.t)~_:(type_:aValue.Type.t)]|Rest(symbol,type_)->[%message"Rest"~_:(symbol:Symbol.t)~_:(type_:_Value.Type.t)];;letreturnx=Returnxletmapt~f=Map(t,f)letbothtt'=Both(t,t')letapplyfx=bothfx|>map~f:(fun(f,x)->fx)letmap=`CustommapendmoduleT=structincludeT0includeApplicative.Make(T0)letrequirednametype_=Required(name,type_)letoptionalnametype_=Optional(name,Value.Type.optiontype_)letrestnametype_=Rest(name,type_)letoptional_with_nilnametype_=map(optionalnametype_)~f:(function|None->type_.of_value_exnValue.nil|Somex->x);;letoptional_with_defaultnamedefaulttype_=map(optionalnametype_)~f:(Option.value~default);;include(Value.Type:Value.Type.S)endincludeTmoduleOpen_on_rhs_intf=structmoduletypeS=Swithtype'at='atendincludeApplicative.Make_let_syntax(T)(Open_on_rhs_intf)(T)letapplytargs=letlen=Array.lengthargsinletpos=ref0inletconsume_arg(type_:_Value.Type.t)=letarg=type_.of_value_exnargs.(!pos)inincrpos;arginletrecloop:typea.at->a=funt->matchtwith|Returna->a|Map(t,f)->f(loopt)|Both(t1,t2)->letx1=loopt1inletx2=loopt2inx1,x2|Required(_,type_)->ifInt.(>=)!poslenthenraise_s[%message"Not enough arguments. Emacs should have raised wrong-number-of-arguments."]elseconsume_argtype_|Optional(_,type_)->ifInt.(>=)!poslenthenNoneelseconsume_argtype_|Rest(_,type_)->letretval=Array.subargs~pos:!pos~len:(len-!pos)|>Array.map~f:type_.of_value_exn|>Array.to_listinpos:=len;retvalinletresult=looptinletpos=!posinifInt.(<>)poslenthenraise_s[%message"Extra arguments. Emacs should have raised wrong-number-of-arguments."~used:(pos:int)(args:Value.tarray)];result;;moduleArgs=structtypet={required:Symbol.tlist;optional:Symbol.tlist;rest:Symbol.toption}letempty={required=[];optional=[];rest=None}letadd_requiredts={twithrequired=s::t.required}letadd_optionalts={twithoptional=s::t.optional}letadd_restts=matcht.restwith|None->{twithrest=Somes}|Somerest->raise_s[%message"Multiple rest arguments"~_:([rest;s]:Symbol.tlist)];;endletget_argst=letrecloop:typea.at->_->_=funtargs->matchtwith|Return_->args|Map(t,_)->looptargs|Both(t1,t2)->loopt1(loopt2args)|Required(name,_)->Args.add_requiredargsname|Optional(name,_)->Args.add_optionalargsname|Rest(name,_)->Args.add_restargsnameinlooptArgs.empty;;moduleReturns=structtype'at=|Returnsof'aValue.Type.t|Returns_unit_deferred:unitDeferred.tt[@@derivingsexp_of]endletblock_on_async:(Source_code_position.t->?context:Sexp.tLazy.t->(unit->unitDeferred.t)->unit)Set_once.t=Set_once.create();;letcall(typea)(t:at)here~function_~args~(returns:aReturns.t)=matchreturnswith|Returnsreturns->returns.to_value(applytargs)|Returns_unit_deferred->letblock_on_async=Set_once.get_exnblock_on_async[%here]inblock_on_asynchere~context:(lazy(List(function_::(args|>Array.map~f:Value.sexp_of_t|>Array.to_list))))(fun()->applytargs);Value.nil;;moduleInteractive=structtypet=|No_arg|Ignored|Promptofstring|Raw_prefix|Regionletto_string=function|No_arg->""|Ignored->"i"|Promptprompt->sprintf"s%s"prompt|Raw_prefix->"P"|Region->"r";;let({Value.Type.of_value_exn;to_value;_}astype_)=Value.Type.(mapstring~name:[%message"interactive-code"]~of_:(function|""->No_arg|"i"->Ignored|"P"->Raw_prefix|"r"->Region|s->(matchString.chop_prefixs~prefix:"s"with|Someprompt->Promptprompt|None->raise_s[%sexp"Unimplemented interactive code",(s:string)]))~to_:to_string);;endmoduleFor_testing=structletdefun_symbols=ref[]endletadd_to_load_historysymbolhere=Load_history.add_entryhere(Funsymbol);For_testing.defun_symbols:=symbol::!For_testing.defun_symbols;;letdefaliassymbolhere?docstring~alias_of()=add_to_load_historysymbolhere;F.defaliassymbolalias_of(docstring|>Option.map~f:String.strip);;letdefine_obsolete_aliasobsoletehere?docstring~alias_of~since()=defaliasobsoletehere?docstring~alias_of();Obsolete.make_function_obsoleteobsolete~current:alias_of~since;;letdefun_rawsymbolhere?docstring?interactive~args?optional_args?rest_argf=add_to_load_historysymbolhere;Symbol.set_functionsymbol(Function.createhere?docstring?interactive~args?optional_args?rest_argf|>Function.to_value);;letdefun_internalsymbolhere?docstring?(define_keys=[])?obsoletes?interactivetfn=letargs=get_argstindefun_rawsymbolhere?docstring?interactive:(Option.mapinteractive~f:Interactive.to_string)~args:args.required~optional_args:args.optional?rest_arg:args.restfn;List.iterdefine_keys~f:(fun(keymap,keys)->Keymap.define_keykeymap(Key_sequence.create_exnkeys)(Symbolsymbol));Option.iterobsoletes~f:(funobsolete->define_obsolete_aliasobsoletehere~alias_of:symbol~since:"who knows when"());;letdefunsymbolhere?docstring?define_keys?obsoletes?interactivereturnst=letfunction_=[%sexp(symbol:Symbol.t)]indefun_internal?docstring?define_keys?obsoletes?interactivesymbolheret(funargs->callthere~function_~args~returns);;letdefun_nullarysymbolhere?docstring?define_keys?obsoletes?interactivereturnsf=defunsymbolhere?docstring?define_keys?obsoletes?interactivereturns(letopenLet_syntaxinlet%map_open()=return()inf());;letdefun_nullary_nilsymbolhere?docstring?define_keys?obsoletes?interactivef=defun_nullarysymbolhere?docstring?define_keys?obsoletes?interactive(ReturnsValue.Type.unit)f;;letlambdahere?docstring?interactivereturnst=letfunction_=[%message"Defun.lambda"]inletargs=get_argstinFunction.createhere?docstring?interactive:(Option.mapinteractive~f:Interactive.to_string)~optional_args:args.optional?rest_arg:args.rest~args:args.required(funargs->callthere~function_~args~returns);;letlambda_nullaryhere?docstring?interactivereturnsf=lambdahere?docstring?interactivereturns(letopenLet_syntaxinlet%map_open()=return()inf());;letlambda_nullary_nilhere?docstring?interactivef=lambda_nullaryhere?docstring?interactive(ReturnsValue.Type.unit)f;;modulePrivate=structletblock_on_async=block_on_asyncend