<commit_before>open CoreUtils

module type BackendParameters = sig
  val output_file : string
end

module Backend (P : BackendParameters) : BackendSignature.T = struct
  (* ------------------------------------------------------------------------ *)
  (* Setup *)

  type state = {prog: NoEffSyntax.cmd list; typing: ExplicitInfer.state}

  let initial_state = {prog= []; typing= ExplicitInfer.initial_state}

  (* Auxiliary functions *)
  let update state cmd explicit_st =
    Print.debug "%t@?" (NoEffPrint.pp_cmd cmd) ;
    {prog= state.prog @ [cmd]; typing= explicit_st}

  let process_type ty = NoEffCompile.compile_type (Types.source_to_target ty)

  (* ------------------------------------------------------------------------ *)
  (* Processing functions *)
  let process_computation state c ty = 
    let ex_st', {ExplicitInfer.computation = exeff_c} = ExplicitInfer.type_computation state.typing c in
     update state (NoEffSyntax.Term (NoEffCompile.compile_comp exeff_c)) ex_st'

  let process_type_of state c ty = failwith __LOC__  (* not implemented *)

  let process_def_effect state (eff, (ty1, ty2)) = 
    update state (NoEffSyntax.DefEffect (eff, (process_type ty1, process_type ty2))) state.typing

  let process_top_let state defs vars = failwith __LOC__ (* not implemented *)

  let process_top_let_rec state defs vars = failwith __LOC__ (* not implemented *)

  let process_external state (x, ty, f) = update state (NoEffSyntax.External (x, process_type ty, f)) state.typing

  let process_tydef state tydefs = failwith __LOC__ (* not implemented *)

  let finalize state = 
    let channel = open_out P.output_file in
    let output_ppf = Format.formatter_of_out_channel channel in
    NoEffPrint.pp_header output_ppf ;
    List.iter (fun cmd -> NoEffPrint.pp_cmd cmd output_ppf) state.prog ;
    close_out channel
end<commit_msg>Update the typing state of NoEff compiler<commit_after>open CoreUtils

module type BackendParameters = sig
  val output_file : string
end

module Backend (P : BackendParameters) : BackendSignature.T = struct
  (* ------------------------------------------------------------------------ *)
  (* Setup *)

  type state = {prog: NoEffSyntax.cmd list; typing: ExplicitInfer.state}

  let initial_state = {prog= []; typing= ExplicitInfer.initial_state}

  (* Auxiliary functions *)
  let update state cmd explicit_st =
    Print.debug "%t@?" (NoEffPrint.pp_cmd cmd) ;
    {prog= state.prog @ [cmd]; typing= explicit_st}

  let process_type ty = NoEffCompile.compile_type (Types.source_to_target ty)

  (* ------------------------------------------------------------------------ *)
  (* Processing functions *)
  let process_computation state c ty = 
    let ex_st', {ExplicitInfer.computation = exeff_c} = ExplicitInfer.type_computation state.typing c in
     update state (NoEffSyntax.Term (NoEffCompile.compile_comp exeff_c)) ex_st'

  let process_type_of state c ty = failwith __LOC__  (* not implemented *)

  let process_def_effect state (eff, (ty1, ty2)) = 
    update state (NoEffSyntax.DefEffect (eff, (process_type ty1, process_type ty2)))
    (ExplicitInfer.add_effect eff (ty1, ty2) state.typing)

  let process_top_let state defs vars = failwith __LOC__ (* not implemented *)

  let process_top_let_rec state defs vars = failwith __LOC__ (* not implemented *)

  let process_external state (x, ty, f) =
    let ty' = Types.source_to_target ty in
    let typing_state' =
      ExplicitInfer.add_external state.typing x ty'
    in
    update state (NoEffSyntax.External (x, process_type ty, f)) typing_state'

  let process_tydef state tydefs = failwith __LOC__ (* not implemented *)

  let finalize state = 
    let channel = open_out P.output_file in
    let output_ppf = Format.formatter_of_out_channel channel in
    NoEffPrint.pp_header output_ppf ;
    List.iter (fun cmd -> NoEffPrint.pp_cmd cmd output_ppf) state.prog ;
    close_out channel
end
{'fraction_non_alphanumeric': 0.15648171823063156, 'fraction_numerical': 0.0025568908207619537, 'mean_word_length': 2.927710843373494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5197382', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1167, 'n_words': 343}