anchor.diff:  (* Reading queries and writing responses *)
   (*****************************************)
   
  -let json_to_str = function
  +let json_debug = function
     | JsonNull -> "null"
     | JsonBool b -> Util.format1 "bool (%s)" (if b then "true" else "false")
     | JsonInt i -> Util.format1 "int (%s)" (Util.string_of_int i)
  
positive.code:   | InvalidQuery msg -> { qid = qid; qq = ProtocolViolation msg }
    | UnexpectedJsonType (expected, got) -> wrap_js_failure qid expected got
  
  let read_interactive_query stream : query =
    match Util.read_line stream with
    | None -> exit 0
    | Some line ->
      match Util.json_of_string line with
      | None -> { qid = "?"; qq = ProtocolViolation "Json parsing failed." }
      | Some request -> safe_unpack_interactive_query request
  
  let safe_unpack_interactive_query js_query =
    try
      unpack_interactive_query js_query
    with
    | InvalidQuery msg -> { qid = "?"; qq = ProtocolViolation msg }
    | UnexpectedJsonType (expected, got) -> wrap_js_failure "?" expected got
  
  let json_of_opt json_of_a opt_a =
    Util.dflt JsonNull (Util.map_option json_of_a opt_a)
  
negative.code:           { qid = q.qid; qq = GenericError "Current module unset" }
          | _ -> q
  
  let validate_and_run_query st query =
    run_query st (validate_query st query).qq
  
  (** This is the body of the JavaScript port's main loop. **)
  let js_repl_eval st query =
    let (status, response), st_opt = validate_and_run_query st query in
    let js_response = json_of_response query.qid status response in
    js_response, st_opt
  
  let js_repl_eval_js st query_js =
    js_repl_eval st (deserialize_interactive_query query_js)
  
  let js_repl_eval_str st query_str =
    let js_response, st_opt =
      js_repl_eval st (parse_interactive_query query_str) in
    (Util.string_of_json js_response), st_opt
  
  (** This too is called from FStar.js **)
  let js_repl_init_opts () =
    let res, fnames = Options.parse_cmd_line () in
    match fnames with
    | _ :: _ -> failwith "repl_init: Unexpected: file names in option list"
    | [] ->
       match res with
       | Getopt.Help -> failwith "repl_init: --help unexpected"
       | Getopt.Error msg -> failwith ("repl_init: " ^ msg)
       | Getopt.Success -> () (* FIXME could do more validation here *)
  
  (** This is the main loop for the desktop version **)
  let rec go st : int =
    let query = read_interactive_query st.repl_stdin in
    let (status, response), state_opt = validate_and_run_query st query in
    write_response query.qid status response;
    match state_opt with
    | Inl st' -> go st'
  