Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file value.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139(* SPDX-License-Identifier: MIT *)(* Copyright (C) 2023-2024 formalsec *)(* Written by the Smtml programmers *)openTytypet=|True|False|Unit|Intofint|Realoffloat|Strofstring|NumofNum.t|BitvofBitvector.t|Listoftlist|App:[>`Opofstring]*tlist->t|Nothinglettype_of(v:t):Ty.t=matchvwith|True|False->Ty_bool|Unit->Ty_unit|Int_->Ty_int|Real_->Ty_real|Str_->Ty_str|Numn->Num.type_ofn|Bitvbv->Ty_bitv(Bitvector.numbitsbv)|List_->Ty_list|App_->Ty_app|Nothing->Ty_noneletdiscr=function|True->0|False->1|Unit->2|Int_->3|Real_->4|Str_->5|Num_->6|Bitv_->7|List_->8|App_->9|Nothing->10letreccompare(a:t)(b:t):int=match(a,b)with|True,True|False,False|Unit,Unit|Nothing,Nothing->0|False,True->-1|True,False->1|Inta,Intb->Int.compareab|Reala,Realb->Float.compareab|Stra,Strb->String.compareab|Numa,Numb->Num.compareab|Bitva,Bitvb->Bitvector.compareab|Lista,Listb->List.comparecompareab|App(`Opop1,vs1),App(`Opop2,vs2)->letc=String.compareop1op2inifc=0thenList.comparecomparevs1vs2elsec|((True|False|Unit|Int_|Real_|Str_|Num_|Bitv_|List_|App_|Nothing),_)->(* TODO: I don't know if this is always semantically correct *)Int.compare(discra)(discrb)letrecequal(v1:t)(v2:t):bool=match(v1,v2)with|True,True|False,False|Unit,Unit|Nothing,Nothing->true|Inta,Intb->Int.equalab|Reala,Realb->Float.equalab|Stra,Strb->String.equalab|Numa,Numb->Num.equalab|Bitva,Bitvb->Bitvector.equalab|Listl1,Listl2->List.equalequall1l2|App(`Opop1,vs1),App(`Opop2,vs2)->String.equalop1op2&&List.equalequalvs1vs2|((True|False|Unit|Int_|Real_|Str_|Num_|Bitv_|List_|App_|Nothing),_)->falseletmapvf=matchvwithNothing->Nothing|_->fvlet(let+)=mapletrecppfmt=function|True->Fmt.stringfmt"true"|False->Fmt.stringfmt"false"|Unit->Fmt.stringfmt"unit"|Intx->Fmt.intfmtx|Realx->Fmt.pffmt"%F"x|Numx->Num.ppfmtx|Bitvbv->Bitvector.ppfmtbv|Strx->Fmt.pffmt"%S"x|Listl->(Fmt.hovbox~indent:1(Fmt.list~sep:Fmt.commapp))fmtl|App(`Opop,vs)->Fmt.pffmt"@[<hov 1>%s(%a)@]"op(Fmt.list~sep:Fmt.commapp)vs|Nothing->Fmt.stringfmt"none"|App_->assertfalseletto_string(v:t):string=Fmt.str"%a"ppvletof_string(cast:Ty.t)v=letopenResultinmatchcastwith|Ty_bitvm->Ok(Bitv(Bitvector.make(Z.of_stringv)m))|Ty_fp_->let+n=Num.of_stringcastvinNumn|Ty_bool->(matchvwith|"true"->OkTrue|"false"->OkFalse|_->Fmt.error_msg"invalid value %s, expected boolean"v)|Ty_int->(matchint_of_string_optvwith|None->Fmt.error_msg"invalid value %s, expected integer"v|Somen->Ok(Intn))|Ty_real->(matchfloat_of_string_optvwith|None->Fmt.error_msg"invalid value %s, expected real"v|Somen->Ok(Realn))|Ty_str->Ok(Strv)|Ty_app|Ty_list|Ty_none|Ty_unit|Ty_regexp|Ty_roundingMode->Fmt.error_msg"unsupported parsing values of type %a"Ty.ppcastletrecto_json(v:t):Yojson.Basic.t=matchvwith|True->`Booltrue|False->`Boolfalse|Unit->`String"unit"|Intint->`Intint|Realreal->`Floatreal|Strstr->`Stringstr|Numn->Num.to_jsonn|Bitvbv->Bitvector.to_jsonbv|Listl->`List(List.mapto_jsonl)|Nothing->`Null|App_->assertfalse