src/Pure/ML/ml_compiler.ML
changeset 62873 2f9c8a18f832
parent 62821 48c24d0b6d85
child 62878 1cec457e0a03
equal deleted inserted replaced
62872:bf1b4d3440a3 62873:2f9c8a18f832
     5 *)
     5 *)
     6 
     6 
     7 signature ML_COMPILER =
     7 signature ML_COMPILER =
     8 sig
     8 sig
     9   type flags =
     9   type flags =
    10     {SML: bool, exchange: bool, redirect: bool, verbose: bool,
    10     {SML_syntax: bool, SML_env: bool, exchange: bool, redirect: bool, verbose: bool,
    11       debug: bool option, writeln: string -> unit, warning: string -> unit}
    11       debug: bool option, writeln: string -> unit, warning: string -> unit}
    12   val debug_flags: bool option -> flags
    12   val debug_flags: bool option -> flags
    13   val flags: flags
    13   val flags: flags
    14   val verbose: bool -> flags -> flags
    14   val verbose: bool -> flags -> flags
    15   val eval: flags -> Position.T -> ML_Lex.token list -> unit
    15   val eval: flags -> Position.T -> ML_Lex.token list -> unit
    19 struct
    19 struct
    20 
    20 
    21 (* flags *)
    21 (* flags *)
    22 
    22 
    23 type flags =
    23 type flags =
    24   {SML: bool, exchange: bool, redirect: bool, verbose: bool,
    24   {SML_syntax: bool, SML_env: bool, exchange: bool, redirect: bool, verbose: bool,
    25     debug: bool option, writeln: string -> unit, warning: string -> unit};
    25     debug: bool option, writeln: string -> unit, warning: string -> unit};
    26 
    26 
    27 fun debug_flags opt_debug : flags =
    27 fun debug_flags opt_debug : flags =
    28   {SML = false, exchange = false, redirect = false, verbose = false,
    28   {SML_syntax = false, SML_env = false, exchange = false, redirect = false, verbose = false,
    29     debug = opt_debug, writeln = writeln, warning = warning};
    29     debug = opt_debug, writeln = writeln, warning = warning};
    30 
    30 
    31 val flags = debug_flags NONE;
    31 val flags = debug_flags NONE;
    32 
    32 
    33 fun verbose b (flags: flags) =
    33 fun verbose b (flags: flags) =
    34   {SML = #SML flags, exchange = #exchange flags, redirect = #redirect flags,
    34   {SML_syntax = #SML_syntax flags, SML_env = #SML_env flags, exchange = #exchange flags,
    35     verbose = b, debug = #debug flags, writeln = #writeln flags, warning = #warning flags};
    35     redirect = #redirect flags, verbose = b, debug = #debug flags,
       
    36     writeln = #writeln flags, warning = #warning flags};
    36 
    37 
    37 
    38 
    38 (* parse trees *)
    39 (* parse trees *)
    39 
    40 
    40 fun breakpoint_position loc =
    41 fun breakpoint_position loc =
   142 
   143 
   143 (* eval ML source tokens *)
   144 (* eval ML source tokens *)
   144 
   145 
   145 fun eval (flags: flags) pos toks =
   146 fun eval (flags: flags) pos toks =
   146   let
   147   let
   147     val space = ML_Env.make_name_space {SML = #SML flags, exchange = #exchange flags};
   148     val space = ML_Env.make_name_space {SML = #SML_env flags, exchange = #exchange flags};
   148     val opt_context = Context.thread_data ();
   149     val opt_context = Context.thread_data ();
   149 
   150 
   150 
   151 
   151     (* input *)
   152     (* input *)
   152 
   153 
   153     val location_props = op ^ (YXML.output_markup (":", #props (Position.dest pos)));
   154     val location_props = op ^ (YXML.output_markup (":", #props (Position.dest pos)));
   154 
   155 
   155     val input_explode =
   156     val input_explode =
   156       if #SML flags then String.explode
   157       if #SML_syntax flags then String.explode
   157       else maps (String.explode o Symbol.esc) o Symbol.explode;
   158       else maps (String.explode o Symbol.esc) o Symbol.explode;
   158 
   159 
   159     val input_buffer =
   160     val input_buffer =
   160       Unsynchronized.ref (toks |> map (`(input_explode o ML_Lex.check_content_of)));
   161       Unsynchronized.ref (toks |> map (`(input_explode o ML_Lex.check_content_of)));
   161 
   162