Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file spectec.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252moduleTyp=Runtime.Type.TypmoduleValue=Runtime.ValuemoduleCCache=Runtime.Dynamic.Caches.CallCachemoduleRun=Runtime.Dynamic_Runner.SignatureopenErroropenUtil.Source(* A wrapper for SpecTec interfaces, providing apis for caching boot/unboots *)moduletypeINTERFACE_SPECTEC=sigincludeRun.INTERFACE(* Interface cache *)typecachevalmake_cache:unit->cachevalpush_cache:cache->unitvalpop_cache:unit->unitvalcache_enable:cache->unitvalcache_disable_reset:cache->unitvalcache_clear:cache->unit(* Boot / unboots *)valboot_value:Value.t->Value.tvalboot_values:Value.tlist->Value.tvalunboot_id:Value.t->stringphrasevalunboot_typs:Value.t->Typ.tlistvalunboot_values:Value.t->Value.tlistend(* The null layer *)moduleMake_null(Interface_SpecTec:INTERFACE_SPECTEC)(Interp_AL:Run.INTERP_AL)(Interp_SL:Run.INTERP_SL)(Interp_PL:Run.INTERP_PL):Run.EXTERN=struct(* Mode initialization *)letcall_func=ref(fun___->assertfalse)letinit_modemode_=letcall_func_nametypsvalues=(matchmode_with|Run.AL_mode->Interp_AL.eval_funcnametypsvalues|Run.SL_mode->Interp_SL.eval_funcnametypsvalues|Run.PL_mode->Interp_PL.eval_funcnametypsvalues|Run.Empty_mode->assertfalse)|>function|Passvalue->value|Fail(at,msg)->erroratmsgincall_func:=call_func_;()(* Threading extern calls to the interpreter *)letcall_builtin_func(values_input:Value.tlist):Value.tlist=letvalue_id,value_typs,value_values=matchvalues_inputwith|[value_id;value_typs;value_values]->(value_id,value_typs,value_values)|_->error_no_region"unexpected number of arguments to call_builtin_func"inletid=value_id|>Interface_SpecTec.unboot_idinlettyps=value_typs|>Interface_SpecTec.unboot_typsinletvalues=value_values|>Interface_SpecTec.unboot_valuesinletvalue_output=!call_funcid.ittypsvaluesinletvalue_value_output=Interface_SpecTec.boot_valuevalue_outputinletvalue_value_output_res=Value.Make.("OK val"<|[value_value_output]<<|"valres")in[value_value_output_res](* Cache management *)(* Externs *)leteval_extern_rel(name:string)(values_input:Value.tlist):Run.rel_result=tryRun.Pass(matchnamewith|"Call_builtin_func"->call_builtin_funcvalues_input|_->errorno_region(Format.asprintf"unimplemented extern relation: %s"name))withUtil.Error.ExternError(at,msg)->Run.Fail(at,msg)leteval_extern_func(name:string)(_typs:Typ.tlist)(_values_input:Value.tlist):Run.func_result=tryRun.Pass(matchnamewith|_->errorno_region(Format.asprintf"unimplemented extern function: %s"name))withUtil.Error.ExternError(at,msg)->Run.Fail(at,msg)(* State management *)letcheckpoint():int=0letseff(before:int)(after:int):bool=before<>after(* Clear the cache *)letclear():unit=()(* Cache management *)moduleCache=structletcache_on()=()letcache_off()=()endend(* The intermediate layer *)moduleMake_parametric(Runner:Run.RUNNER)(Interface_SpecTec:INTERFACE_SPECTEC)():Run.EXTERN=struct(* Mode initialization *)letinit_mode_=()(* Caches
* an interface cache for storing results of booting and unbooting values, types, and mixops *)typecache={interface:Interface_SpecTec.cache}letcache:cache=letinterface=Interface_SpecTec.make_cache()in{interface}moduleCache=structletcache_on()=Interface_SpecTec.cache_enablecache.interfaceletcache_off()=Interface_SpecTec.cache_disable_resetcache.interfaceend(* Threading extern calls to the runner *)letcall_builtin_func(values_input:Value.tlist):Value.tlist=letvalue_id,value_typs,value_values=matchvalues_inputwith|[value_id;value_typs;value_values]->(value_id,value_typs,value_values)|_->error_no_region"unexpected number of arguments to call_builtin_func"inInterface_SpecTec.push_cachecache.interface;letid=value_id|>Interface_SpecTec.unboot_idinlettyps=value_typs|>Interface_SpecTec.unboot_typsinletvalues=value_values|>Interface_SpecTec.unboot_valuesinletvalue_output=matchRunner.Interp.eval_funcid.ittypsvalueswith|Passvalue_output->value_output|Fail(at,msg)->erroratmsginletvalue_value_output=Interface_SpecTec.boot_valuevalue_outputinletvalue_value_output_res=Value.Make.("OK val"<|[value_value_output]<<|"valres")inInterface_SpecTec.pop_cache();[value_value_output_res]letcall_extern_func(values_input:Value.tlist):Value.tlist=letvalue_id,value_typs,value_values=matchvalues_inputwith|[value_id;value_typs;value_values]->(value_id,value_typs,value_values)|_->error_no_region"unexpected number of arguments to call_extern_rel"inInterface_SpecTec.push_cachecache.interface;letid=value_id|>Interface_SpecTec.unboot_idinlettyps=value_typs|>Interface_SpecTec.unboot_typsinletvalues=value_values|>Interface_SpecTec.unboot_valuesinletvalue_output=matchRunner.Interp.eval_funcid.ittypsvalueswith|Passvalue_output->value_output|Fail(at,msg)->erroratmsginletvalue_value_output=Interface_SpecTec.boot_valuevalue_outputinletvalue_value_output_res=Value.Make.("OK val"<|[value_value_output]<<|"valsres")inInterface_SpecTec.pop_cache();[value_value_output_res]letcall_extern_rel(values_input:Value.tlist):Value.tlist=letvalue_id,value_values=matchvalues_inputwith|[value_id;value_values]->(value_id,value_values)|_->error_no_region"unexpected number of arguments to call_extern_rel"inInterface_SpecTec.push_cachecache.interface;letid=value_id|>Interface_SpecTec.unboot_idinletvalues=value_values|>Interface_SpecTec.unboot_valuesinletvalues_output=matchRunner.Interp.eval_relid.itvalueswith|Passvalues_output->values_output|Fail(at,msg)->erroratmsginletvalue_values_output=Interface_SpecTec.boot_valuesvalues_outputinletvalue_values_output_res=Value.Make.("OK val*"<|[value_values_output]<<|"valsres")inInterface_SpecTec.pop_cache();[value_values_output_res](* Extern handlers *)leteval_extern_rel(name:string)(values_input:Value.tlist):Run.rel_result=tryRun.Pass(matchnamewith|"Call_builtin_func"->call_builtin_funcvalues_input|"Call_extern_func"->call_extern_funcvalues_input|"Call_extern_rel"->call_extern_relvalues_input|_->errorno_region(Format.asprintf"unimplemented extern relation: %s"name))withUtil.Error.ExternError(at,msg)->Run.Fail(at,msg)leteval_extern_func(name:string)(_typs:Typ.tlist)(_values_input:Value.tlist):Run.func_result=tryRun.Pass(matchnamewith|_->errorno_region(Format.asprintf"unimplemented extern function: %s"name))withUtil.Error.ExternError(at,msg)->Run.Fail(at,msg)(* State management *)letcheckpoint():int=Runner.Interface.checkpoint()letseff(before:int)(after:int):bool=Runner.Interface.seffbeforeafter(* Clear the cache *)letclear_cache_interface():unit=Interface_SpecTec.cache_clearcache.interfaceletclear():unit=clear_cache_interface()end