local open Fnlib in

(* version string *)
#include "../config/defs.h"
val version = VERSION_S

(* Integer ranges *)

val maxint_byte = 255
and minint_byte = 0
and maxint_short = 32767
and minint_short = ~32768
and maxint_int31 = 1073741823
and minint_int31 = ~1073741824
;

(* The default name for executable bytecode files. *)

#ifdef unix
val default_exec_name = "a.out";
#endif
#ifdef macintosh
val default_exec_name = "Mosml.out";
#endif
#if defined(msdos) || defined(win32)
val default_exec_name = "mosmlout.exe";
#endif

(* Prompts *)

val toplevel_input_prompt = "- ";
val toplevel_output_prompt = "> ";
val toplevel_output_cont_prompt = "  ";
val toplevel_error_prompt = "! ";
val batch_output_prompt = "> ";
val batch_output_cont_prompt = "  ";
val batch_error_prompt = "! ";

(* Run-time values: MUST AGREE with runtime/mlvalues.h *)

val realTag     = 254;	
val stringTag   = 253;	
val refTag      = 250;	
val closureTag  = 249 ;
val maxBlockTag = closureTag-1;

(* Unit sets *)

(* The empty "none" set is defined in Mainc.sml, Mainl.sml, and Maint.sml *)

val reservedUnitNames = ["General", "Top", "Meta"];
val pervasiveOpenedUnits = ["General"];

val fulllib = ["Option", "List", "ListPair", "Strbase", "Char", "String",
	       "StringCvt", "TextIO", "BasicIO", "Vector",
	       "Array", "VectorSlice", "ArraySlice", "Misc", "Substring",
	       "Bool", "Int", "Real", "Math",
	       "Word", "Word8", "Word8Vector", "Word8Array", 
	       "Word8VectorSlice", "Word8ArraySlice", "Byte",
	       "BinIO", "CharVector", "CharArray",
	       "CharVectorSlice", "CharArraySlice",
	       "Time", "Timer", "Date", "Path",
	       "FileSys", "Process", "OS", 
	       "Mosml", "PP", "CommandLine"]

val preloadedUnitSets = [
  ("default",  ["Option", "List", "Strbase", "Char", "String",
		"StringCvt", "TextIO", "BasicIO", "Vector",
		"Array", "Misc"]),
  ("full",     fulllib),
  ("sml90",    ["Option", "List", "Strbase", "Char", "String",
                "StringCvt", "TextIO", "BasicIO", "Vector",
		"Array", "Misc", "SML90"]),
  ("nj93",     ["Option", "List", "Strbase", "Char", "String",
		"StringCvt", "TextIO", "BasicIO", "NJ93", "Vector",
		"Array", "Misc"])
];

val preopenedPreloadedUnitSets = [
  ("default",  ["Misc"]),
  ("full",     ["Misc"]),
  ("sml90",    ["Misc", "SML90"]),
  ("nj93",     ["Misc", "NJ93"])
];

#ifdef msdos

val kosherUnitNames = [
  ("Arraysli", "ArraySlice"),
  ("Basicio",  "BasicIO"),
  ("Binio",    "BinIO"),
  ("Chararra", "CharArray"),
  ("Charvect", "CharVector"),
  ("Commandl", "CommandLine"),
  ("Filesys",  "FileSys"),
  ("Listpair", "ListPair"),
  ("Nj93",     "NJ93"),
  ("Os",       "OS"),
  ("Pp",       "PP"),
  ("Sml90",    "SML90"),
  ("Stringcv", "StringCvt"),
  ("Substrin", "Substring"),
  ("Textio",   "TextIO"),
  ("Vectorsl", "VectorSlice"),
  ("Word8arr", "Word8Array"),
  ("Word8vec", "Word8Vector")
];
#endif

#ifdef win32
val kosherUnitNames = [
  ("Arrayslice",       "ArraySlice"),
  ("Basicio",          "BasicIO"),
  ("Binio",            "BinIO"),
  ("Chararray",        "CharArray"),
  ("Chararrayslice",   "CharArraySlice"),
  ("Charvector",       "CharVector"),
  ("Charvectorslice",  "CharVectorSlice"),
  ("Commandline",      "CommandLine"),
  ("Filesys",          "FileSys"),
  ("Listpair",         "ListPair"),
  ("Nj93",             "NJ93"),
  ("Os",               "OS"),
  ("Pp",               "PP"),
  ("Sml90",            "SML90"),
  ("Stringcvt",        "StringCvt"),
  ("Substring",        "Substring"),
  ("Textio",           "TextIO"),
  ("Vectorslice",      "VectorSlice"),
  ("Word8array",       "Word8Array"),
  ("Word8arrayslice",  "Word8ArraySlice"),
  ("Word8vector",      "Word8Vector"),
  ("Word8vectorslice", "Word8VectorSlice")
];
#endif

#if defined(msdos) || defined(win32)
local open CharVector; infix 9 sub; in

  fun normalizedFileName s = Fnlib.stringToLower s;

  fun normalizedUnitName s =
    let val len = size s
        val () = if len = 0 then raise SysErr("Empty unit name", NONE)
		 else ()
#ifdef msdos
        val len0 = if len>8 then 8 else len
#else
        val len0 = len
#endif
        val s0 = tabulate(len0, fn i =>
          (case i of 0 => Char.toUpper
                   | _ => Char.toLower) (s sub i))
    in
      lookup s0 kosherUnitNames
        handle Subscript => s0
    end;

end;

#else
fun normalizedFileName s = s;
fun normalizedUnitName s = s;
#endif

(* To translate escape sequences *)

val char_for_backslash = fn
#ifdef macintosh
(* *)    #"n" => #"\013"
(* *)  | #"r" => #"\010"
#else
(* *)    #"n" => #"\010"
(* *)  | #"r" => #"\013"
#endif
(* *)  | #"a" => #"\007"
(* *)  | #"b" => #"\008"
(* *)  | #"t" => #"\009"
(* *)  | #"v" => #"\011"
(* *)  | #"f" => #"\012"
(* *)  | c => c
;

end;
