src/Pure/ML/ml_compiler.ML
author wenzelm
Sat Apr 19 17:23:05 2014 +0200 (2014-04-19)
changeset 56618 874bdedb2313
parent 56304 40274e4f5ebf
child 60858 7bf2188a0998
permissions -rw-r--r--
added command 'SML_export' and 'SML_import' for exchange of toplevel bindings;
     1 (*  Title:      Pure/ML/ml_compiler.ML
     2     Author:     Makarius
     3 
     4 Runtime compilation and evaluation -- generic version.
     5 *)
     6 
     7 signature ML_COMPILER =
     8 sig
     9   type flags = {SML: bool, exchange: bool, redirect: bool, verbose: bool}
    10   val flags: flags
    11   val verbose: bool -> flags -> flags
    12   val eval: flags -> Position.T -> ML_Lex.token list -> unit
    13 end
    14 
    15 structure ML_Compiler: ML_COMPILER =
    16 struct
    17 
    18 type flags = {SML: bool, exchange: bool, redirect: bool, verbose: bool};
    19 val flags = {SML = false, exchange = false, redirect = false, verbose = false};
    20 
    21 fun verbose b (flags: flags) =
    22   {SML = #SML flags, exchange = #exchange flags, redirect = #redirect flags, verbose = b};
    23 
    24 fun eval (flags: flags) pos toks =
    25   let
    26     val _ = if #SML flags then error ("Standard ML is unsupported on " ^ ML_System.name) else ();
    27     val line = the_default 1 (Position.line_of pos);
    28     val file = the_default "ML" (Position.file_of pos);
    29     val text = ML_Lex.flatten toks;
    30   in Secure.use_text ML_Env.local_context (line, file) (#verbose flags) text end;
    31 
    32 end;
    33