text
stringlengths
12
786k
module Prim_make ( Resolved : sig type t struct type t = | Null | String | Bool | Number | Any | Object | List | Self | Resolved of Resolved . t let of_string s ~ resolve = match String . lowercase_ascii s with | " null " -> Null | " string " -> String | " boolean " -> Bool | " n...
module rec Resolved : ( S with type ident := Prim . t ) = Make ( Prim )
let subst unresolved = object val params = String . Map . empty val inside = None method inside s = { < inside = Some s } > method resolve n = match String . Map . find params n with | Some [ ] -> assert false | Some ( x :: _ ) -> ` Resolved x | None -> if inside = Some n then ` ...
let rec resolve_all ts ( ~ names : Unresolved . t String . Map . t ) : Resolved . t list = let names = subst names in List . map ts ~ f ( : resolve ~ names ) let data : Resolved . decl = match t . data with | Interface i -> Interface ( resolve_interface { t with data = i } ~ na...
type pattern = { p_node : pattern_node ; p_ty : ty ; p_loc : Location . t option ; [ @ printer fun fmt _ -> fprintf fmt " < Location . t " ] > } | Pwild | Pvar of vsymbol | Papp of lsymbol * pattern list | Por of pattern * pattern | Pas of pattern * vsymbol | Pinterval of char *...
type binop = Tand | Tand_asym | Tor | Tor_asym | Timplies | Tiff
type quant = Tforall | Texists | Tlambda [ @@ deriving show ]
type term = { t_node : term_node ; t_ty : ty option ; t_attrs : string list ; t_loc : Location . t ; [ @ printer fun fmt _ -> fprintf fmt " < Location . t " ] > } | Tvar of vsymbol | Tconst of constant [ @ printer fun fmt _ -> fprintf fmt " < constant " ] > | Tapp of ls...
let rec p_vars p = match p . p_node with | Pwild | Pconst _ | Pinterval _ -> Svs . empty | Pvar vs -> Svs . singleton vs | Papp ( _ , pl ) -> List . fold_left ( fun vsl p -> Svs . union ( p_vars p ) vsl ) Svs . empty pl | Por ( p1 , p2 ) -> Svs . union ( p_vars p1 ) ...
let rec t_free_vars t = match t . t_node with | Tvar vs -> Svs . singleton vs | Tconst _ -> Svs . empty | Tapp ( _ , tl ) -> List . fold_left ( fun fvs t -> Svs . union ( t_free_vars t ) fvs ) Svs . empty tl | Tfield ( t , _ ) -> t_free_vars t | Tif ( t1 , t2 , t3 ) ...
let t_free_vs_in_set svs t = let diff = Svs . diff ( t_free_vars t ) svs in if not ( Svs . is_empty diff ) then W . error ~ loc : t . t_loc ( W . Free_variables ( Svs . elements diff |> List . map ( fun vs -> vs . vs_name . id_str ) ) )
let t_prop t = if t . t_ty = None then t else W . error ~ loc : t . t_loc W . Formula_expected
let t_type t = match t . t_ty with | Some ty -> ty | None -> W . error ~ loc : t . t_loc W . Formula_expected
let t_ty_check t ty = match ( ty , t . t_ty ) with | Some l , Some r -> ty_equal_check l r | Some _ , None -> W . error ~ loc : t . t_loc W . Term_expected | None , Some _ -> W . error ~ loc : t . t_loc W . Formula_expected | None , None -> ( )
let ls_arg_inst ls tl = try List . fold_left2 ( fun tvm ty t -> ty_match tvm ty ( t_type t ) ) Mtv . empty ls . ls_args tl with Invalid_argument _ -> let loc = ( List . hd tl ) . t_loc in W . error ~ loc ( W . Bad_arity ( ls . ls_name . id_str , List . length ls . ls_args ,...
let ls_app_inst ls tl ty = let s = ls_arg_inst ls tl in match ( ls . ls_value , ty ) with | Some _ , None -> W . error ~ loc : Location . none ( W . Predicate_symbol_expected ls . ls_name . id_str ) | None , Some _ -> W . error ~ loc : Location . none ( W . Function_symbol_...
let mk_pattern p_node p_ty = { p_node ; p_ty ; p_loc = None }
let p_wild ty = mk_pattern Pwild ty
let p_var vs = mk_pattern ( Pvar vs ) vs . vs_ty
let p_app ls pl ty = mk_pattern ( Papp ( ls , pl ) ) ty
let p_or p1 p2 = mk_pattern ( Por ( p1 , p2 ) ) p1 . p_ty
let p_as p vs = mk_pattern ( Pas ( p , vs ) ) p . p_ty
let p_interval c1 c2 = mk_pattern ( Pinterval ( c1 , c2 ) ) ty_char
let p_const c = match c with | Pconst_integer _ -> mk_pattern ( Pconst c ) ty_int | Pconst_char _ -> mk_pattern ( Pconst c ) ty_char | Pconst_string _ -> mk_pattern ( Pconst c ) ty_string | Pconst_float _ -> mk_pattern ( Pconst c ) ty_float
let mk_term t_node t_ty t_loc = { t_node ; t_ty ; t_attrs = [ ] ; t_loc }
let t_var vs = mk_term ( Tvar vs ) ( Some vs . vs_ty )
let t_const c ty = mk_term ( Tconst c ) ( Some ty )
let t_app ls tl ty = ignore ( ls_app_inst ls tl ty : ty Mtv . t ) ; mk_term ( Tapp ( ls , tl ) ) ty
let t_field t ls ty = ignore ( ls_app_inst ls [ t ] ty : ty Mtv . t ) ; mk_term ( Tfield ( t , ls ) ) ty
let t_if t1 t2 t3 = mk_term ( Tif ( t1 , t2 , t3 ) ) t2 . t_ty
let t_let vs t1 t2 = mk_term ( Tlet ( vs , t1 , t2 ) ) t2 . t_ty
let t_case t1 ptl = match ptl with | [ ] -> assert false | ( _ , t ) :: _ -> mk_term ( Tcase ( t1 , ptl ) ) t . t_ty
let t_quant q vsl t ty = mk_term ( Tquant ( q , vsl , t ) ) ty
let t_binop b t1 t2 = mk_term ( Tbinop ( b , t1 , t2 ) ) None
let t_not t = mk_term ( Tnot t ) None
let t_old t = mk_term ( Told t ) t . t_ty
let t_true = mk_term Ttrue None
let t_false = mk_term Tfalse None
let t_attr_set attr t = { t with t_attrs = attr }
let t_bool_true = mk_term ( Tapp ( fs_bool_true , [ ] ) ) ( Some ty_bool )
let t_bool_false = mk_term ( Tapp ( fs_bool_false , [ ] ) ) ( Some ty_bool )
let t_equ t1 t2 = t_app ps_equ [ t1 ; t2 ] None
let t_neq t1 t2 loc = t_not ( t_equ t1 t2 loc )
let f_binop op f1 f2 = t_binop op ( t_prop f1 ) ( t_prop f2 )
let f_not f = t_not ( t_prop f )
let t_quant q vsl t ty loc = match ( q , vsl ) with | Tlambda , [ ] -> t | _ , [ ] -> t_prop t | Tlambda , _ -> t_quant q vsl t ty loc | _ , _ -> if ty <> None then W . error ~ loc W . Formula_expected ; t_quant q vsl ( t_prop t ) None loc
let f_forall = t_quant Tforall
let f_exists = t_quant Texists
let t_lambda = t_quant Tlambda
let f_and = f_binop Tand
let f_and_asym = f_binop Tand_asym
let f_or = f_binop Tor
let f_or_asym = f_binop Tor_asym
let f_implies = f_binop Timplies
let f_iff = f_binop Tiff
let print_vs fmt { vs_name ; vs_ty } = pp fmt " [ @% a :% a ] " @ Ident . pp vs_name print_ty vs_ty
let print_ls_decl fmt { ls_name ; ls_args ; ls_value ; _ } = let is_func = Option . is_some ls_value in let print_unnamed_arg fmt ty = pp fmt " ( _ :% a ) " print_ty ty in pp fmt " % s % a % a % s % a " ( if is_func then " function " else " predicate " ) Ident . pp ls_na...
let print_ls_nm fmt { ls_name ; _ } = pp fmt " % a " Ident . pp ls_name
let protect_on x s = if x then " ( " ^^ s ^^ " ) " else s
let rec print_pat_node pri fmt p = match p . p_node with | Pwild -> pp fmt " _ " | Pvar v -> print_vs fmt v | Pas ( p , v ) -> pp fmt ( protect_on ( pri > 1 ) " % a as % a " ) ( print_pat_node 1 ) p print_vs v | Por ( p , q ) -> pp fmt ( protect_on ( pri > 0 ) " ...
let print_pattern = print_pat_node 0
let print_binop fmt = function | Tand -> pp fmt " " /\\ | Tor -> pp fmt " " \\/ | Timplies -> pp fmt " " -> | Tiff -> pp fmt " " <-> | Tand_asym -> pp fmt " " && | Tor_asym -> pp fmt " " ||
let print_quantifier fmt = function | Tforall -> pp fmt " forall " | Texists -> pp fmt " exists " | Tlambda -> pp fmt " fun "
let rec print_term fmt { t_node ; t_ty ; t_attrs ; _ } = let print_ty fmt ty = match ty with None -> pp fmt " : prop " | Some ty -> pp fmt " :% a " print_ty ty in let print_t_node fmt t_node = match t_node with | Tconst c -> pp fmt " % a % a " Opprintast . constant c print_ty t_ty ...
let board_width = 10 and board_height = 22
let term_color_map = function | Cyan -> cyan | Yellow -> yellow | Purple -> lred | Green -> green | Red -> red | Blue -> lblue | Orange -> lyellow
let cell_color = function | Empty -> black | Color x -> term_color_map x
let cell_char = function | Empty -> S " " | Color _ -> S " " #
type event_or_tick = LEvent of LTerm_event . t | LTick
let wait_for_event ui = LTerm_ui . wait ui >>= fun x -> return ( LEvent x )
let wait_for_tick ( ) = Lwt_unix . sleep ( gravity_period gravity ) >>= fun ( ) -> return ( LTick )
let rec loop ui state event_thread tick_thread = Lwt . choose [ event_thread ; tick_thread ] >>= fun e -> let cstate = ! state in let rstate = initial_state cstate . width cstate . height in LTerm_ui . draw ui ; match e with | LEvent ( LTerm_event . Key { code = Up } ) -> state := if...
let draw_cell ctx v x y = LTerm_draw . draw_styled ctx y ( x + 1 ) ( eval [ B_bg ( cell_color v ) ; ( cell_char v ) ; E_fg ] )
let draw_tetromino ctx state = ignore ( BatList . map ( ( fun ( x , y ) -> draw_cell ctx ( Color state . tetromino . color ) x y ) % ( xyplus state . position ) % ( rotate ( rotation_matrix state . rotation ) state . tetromino . center ) ) state . tetromino . geomet...
let draw ui matrix state = let size = LTerm_ui . size ui in let ctx = LTerm_draw . context matrix size in LTerm_draw . clear ctx ; let draw_legend = let lctx = LTerm_draw . sub ctx { row1 = 0 ; col1 = state . width + 6 ; row2 = state . height ; col2 = 60 } in LTerm_draw . draw_sty...
let rec write_glyph ttf key glyf =
let write_font ch ttf glyphs = ( )
let to_canvas ttf range_str =
type header = { }
type entry = { }
type glyf_header = { }
type glyf_simple = { }
type glyf_component = { }
type hmtx = { }
type cmap_subtable_header = { }
type cmap_format_0 = { }
type cmap_format_4 = { }
type cmap_format_6 = { }
type cmap_format_12_group = { }
type cmap_format_12 = { }
type cmap_subtable = { }
type cmap = { }
type kern_subtable_header = { }
type kern_pair = { }
type kern_format_0 = { }
type kern_format_2 = { }
type kern_subtable = { }
type kern = { }
type name_record = { }
type name = { }