<commit_before>﻿(* -------------------------------------------------------------------- *)
#light "off"

module Microsoft.FStar.Backends.OCaml.ASTTrans

open System
open System.Text

open Microsoft.FStar
open Microsoft.FStar.Util
open Microsoft.FStar.Range
open Microsoft.FStar.Absyn.Syntax
open Microsoft.FStar.Absyn.Util
open Microsoft.FStar.Backends.OCaml.Syntax
open FSharp.Format

(* -------------------------------------------------------------------- *)
type mlenv = { mle_name : mlpath; }

let mk_mlenv (name : mlpath) = { mle_name = name; }

(* -------------------------------------------------------------------- *)
let outmod = [
    ["Prims"];
    ["System"];
    ["ST"];
    ["Option"];
    ["String"];
    ["Char"];
    ["Bytes"];
    ["List"];
    ["Array"];
    ["Set"];
    ["Map"];
    ["Heap"];
    ["DST"];
    ["IO"];
    ["Tcp"];
    ["Crypto"];
    ["Collections"];
    ["Microsoft"; "FStar"; "Bytes"];
    ["Microsoft"; "FStar"; "Platform"];
    ["Microsoft"; "FStar"; "Util"];
    ["Microsoft"; "FStar"; "Getopt"];
    ["Microsoft"; "FStar"; "Unionfind"];
    ["Microsoft"; "FStar"; "Range"];
    ["Microsoft"; "FStar"; "Parser"; "Util"];
]

(* -------------------------------------------------------------------- *)
let path_of_ns mlenv ns =
    let ns = List.map (fun x -> x.idText) ns in

    let rec insupport = function
    | [], _ -> true
    | x1::t1, x2::t2 when (x1 = x2) -> insupport (t1, t2)
    | _, _ -> false

    and outsupport = fun (ns1,ns2) ->  if ns1 = ns2 then [] else [String.concat "_" ns2]
    
    (*function
    | x1 :: p1, x2 :: p2 when x1 = x2 -> outsupport (p1, p2)
    | _, p -> p
    *)
    in let chkin sns = if insupport (sns, ns) then Some sns else None
    in match List.tryPick chkin outmod with
    | None -> 
        (match List.tryPick chkin (!Microsoft.FStar.Options.codegen_libs) with
         | Some ns -> ns
         | None -> outsupport ((fst mlenv.mle_name) @ [snd mlenv.mle_name], ns))
    | Some sns -> "Support" :: ns

let mlpath_of_lident (mlenv : mlenv) (x : lident) : mlpath =
    let ns = x.ns in
    let x  = x.ident.idText in
    (path_of_ns mlenv ns, x)

(* -------------------------------------------------------------------- *)
type error =
| Unexpected      of string
| Unsupported     of string
| UnboundVar      of string
| UnboundTyVar    of string
| DuplicatedLocal of string * string

exception OCamlFailure of Range.range * error

let string_of_error (error : error) =
    match error with
    | Unexpected      s -> "unexpected: "^ s
    | Unsupported     s -> "unsupported: "^ s
    | UnboundVar      s -> "unbound-var: "^ s
    | UnboundTyVar    s -> "unbound-ty-var: "^ s
    | DuplicatedLocal _ -> "duplicated-local"

let unexpected (rg : range) (what : string) =
    raise (OCamlFailure (rg, Unexpected what))

let unsupported (rg : range) (what : string) =
    raise (OCamlFailure (rg, Unsupported what))
<commit_msg>(fix nit)<commit_after>﻿(* -------------------------------------------------------------------- *)
#light "off"

module Microsoft.FStar.Backends.OCaml.ASTTrans

open System
open System.Text

open Microsoft.FStar
open Microsoft.FStar.Util
open Microsoft.FStar.Range
open Microsoft.FStar.Absyn.Syntax
open Microsoft.FStar.Absyn.Util
open Microsoft.FStar.Backends.OCaml.Syntax
open FSharp.Format

(* -------------------------------------------------------------------- *)
type mlenv = { mle_name : mlpath; }

let mk_mlenv (name : mlpath) = { mle_name = name; }

(* -------------------------------------------------------------------- *)
let outmod = [
    ["Prims"];
    ["System"];
    ["ST"];
    ["Option"];
    ["String"];
    ["Char"];
    ["Bytes"];
    ["List"];
    ["Array"];
    ["Set"];
    ["Map"];
    ["Heap"];
    ["DST"];
    ["IO"];
    ["Tcp"];
    ["Crypto"];
    ["Collections"];
    ["Microsoft"; "FStar"; "Bytes"];
    ["Microsoft"; "FStar"; "Platform"];
    ["Microsoft"; "FStar"; "Util"];
    ["Microsoft"; "FStar"; "Getopt"];
    ["Microsoft"; "FStar"; "Unionfind"];
    ["Microsoft"; "FStar"; "Range"];
    ["Microsoft"; "FStar"; "Parser"; "Util"];
]

(* -------------------------------------------------------------------- *)
let path_of_ns mlenv ns =
    let ns = List.map (fun x -> x.idText) ns in

    let rec insupport = function
    | [], _ -> true
    | x1::t1, x2::t2 when (x1 = x2) -> insupport (t1, t2)
    | _, _ -> false

    and outsupport = fun (ns1,ns2) ->  if ns1 = ns2 then [] else [String.concat "_" ns2]
    
    (*function
    | x1 :: p1, x2 :: p2 when x1 = x2 -> outsupport (p1, p2)
    | _, p -> p
    *)
    in let chkin sns = if insupport (sns, ns) then Some sns else None
    in match List.tryPick chkin outmod with
    | None -> 
        (match List.tryPick chkin (!Microsoft.FStar.Options.codegen_libs) with
         | None -> outsupport ((fst mlenv.mle_name) @ [snd mlenv.mle_name], ns)
         | _ -> ns)
    | Some sns -> "Support" :: ns

let mlpath_of_lident (mlenv : mlenv) (x : lident) : mlpath =
    let ns = x.ns in
    let x  = x.ident.idText in
    (path_of_ns mlenv ns, x)

(* -------------------------------------------------------------------- *)
type error =
| Unexpected      of string
| Unsupported     of string
| UnboundVar      of string
| UnboundTyVar    of string
| DuplicatedLocal of string * string

exception OCamlFailure of Range.range * error

let string_of_error (error : error) =
    match error with
    | Unexpected      s -> "unexpected: "^ s
    | Unsupported     s -> "unsupported: "^ s
    | UnboundVar      s -> "unbound-var: "^ s
    | UnboundTyVar    s -> "unbound-ty-var: "^ s
    | DuplicatedLocal _ -> "duplicated-local"

let unexpected (rg : range) (what : string) =
    raise (OCamlFailure (rg, Unexpected what))

let unsupported (rg : range) (what : string) =
    raise (OCamlFailure (rg, Unsupported what))

{'fraction_non_alphanumeric': 0.26384588923288615, 'fraction_numerical': 0.007223942208462332, 'mean_word_length': 1.8241864983001457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '6514036', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1839, 'n_words': 503}