src/Doc/System/Scala.thy
author haftmann
Mon Feb 06 20:56:34 2017 +0100 (2017-02-06)
changeset 64990 c6a7de505796
parent 63680 6e1e8b5abbfa
permissions -rw-r--r--
more explicit errors in pathological cases
wenzelm@61656
     1
(*:maxLineLen=78:*)
wenzelm@61575
     2
wenzelm@47825
     3
theory Scala
wenzelm@47825
     4
imports Base
wenzelm@47825
     5
begin
wenzelm@47825
     6
wenzelm@58618
     7
chapter \<open>Isabelle/Scala development tools\<close>
wenzelm@47825
     8
wenzelm@61575
     9
text \<open>
wenzelm@61575
    10
  Isabelle/ML and Isabelle/Scala are the two main language environments for
wenzelm@61575
    11
  Isabelle tool implementations. There are some basic command-line tools to
wenzelm@61575
    12
  work with the underlying Java Virtual Machine, the Scala toplevel and
wenzelm@61575
    13
  compiler. Note that Isabelle/jEdit @{cite "isabelle-jedit"} provides a Scala
wenzelm@61575
    14
  Console for interactive experimentation within the running application.
wenzelm@61575
    15
\<close>
wenzelm@47825
    16
wenzelm@47825
    17
wenzelm@58618
    18
section \<open>Java Runtime Environment within Isabelle \label{sec:tool-java}\<close>
wenzelm@47825
    19
wenzelm@61575
    20
text \<open>
wenzelm@61575
    21
  The @{tool_def java} tool is a direct wrapper for the Java Runtime
wenzelm@61575
    22
  Environment, within the regular Isabelle settings environment
wenzelm@61575
    23
  (\secref{sec:settings}). The command line arguments are that of the
wenzelm@61575
    24
  underlying Java version. It is run in \<^verbatim>\<open>-server\<close> mode if possible, to
wenzelm@61575
    25
  improve performance (at the cost of extra startup time).
wenzelm@47825
    26
wenzelm@61575
    27
  The \<^verbatim>\<open>java\<close> executable is the one within @{setting ISABELLE_JDK_HOME},
wenzelm@61575
    28
  according to the standard directory layout for official JDK distributions.
wenzelm@61575
    29
  The class loader is augmented such that the name space of
wenzelm@61575
    30
  \<^verbatim>\<open>Isabelle/Pure.jar\<close> is available, which is the main Isabelle/Scala module.
wenzelm@47825
    31
wenzelm@61575
    32
  For example, the following command-line invokes the main method of class
wenzelm@61575
    33
  \<^verbatim>\<open>isabelle.GUI_Setup\<close>, which opens a windows with some diagnostic
wenzelm@61575
    34
  information about the Isabelle environment:
wenzelm@61407
    35
  @{verbatim [display] \<open>isabelle java isabelle.GUI_Setup\<close>}
wenzelm@58618
    36
\<close>
wenzelm@47825
    37
wenzelm@47825
    38
wenzelm@58618
    39
section \<open>Scala toplevel \label{sec:tool-scala}\<close>
wenzelm@47825
    40
wenzelm@61575
    41
text \<open>
wenzelm@61575
    42
  The @{tool_def scala} tool is a direct wrapper for the Scala toplevel; see
wenzelm@61575
    43
  also @{tool java} above. The command line arguments are that of the
wenzelm@61575
    44
  underlying Scala version.
wenzelm@47825
    45
wenzelm@47825
    46
  This allows to interact with Isabelle/Scala in TTY mode like this:
wenzelm@61407
    47
  @{verbatim [display]
wenzelm@61407
    48
\<open>isabelle scala
wenzelm@61407
    49
scala> isabelle.Isabelle_System.getenv("ISABELLE_HOME")
wenzelm@61407
    50
scala> val options = isabelle.Options.init()
wenzelm@61407
    51
scala> options.bool("browser_info")
wenzelm@61407
    52
scala> options.string("document")\<close>}
wenzelm@58618
    53
\<close>
wenzelm@47825
    54
wenzelm@47825
    55
wenzelm@58618
    56
section \<open>Scala compiler \label{sec:tool-scalac}\<close>
wenzelm@47825
    57
wenzelm@61575
    58
text \<open>
wenzelm@61575
    59
  The @{tool_def scalac} tool is a direct wrapper for the Scala compiler; see
wenzelm@61575
    60
  also @{tool scala} above. The command line arguments are that of the
wenzelm@61575
    61
  underlying Scala version.
wenzelm@47825
    62
wenzelm@47825
    63
  This allows to compile further Scala modules, depending on existing
wenzelm@61575
    64
  Isabelle/Scala functionality. The resulting class or jar files can be added
wenzelm@61575
    65
  to the Java classpath using the \<^verbatim>\<open>classpath\<close> Bash function that is provided
wenzelm@61575
    66
  by the Isabelle process environment. Thus add-on components can register
wenzelm@61575
    67
  themselves in a modular manner, see also \secref{sec:components}.
wenzelm@47825
    68
wenzelm@61575
    69
  Note that jEdit @{cite "isabelle-jedit"} has its own mechanisms for adding
wenzelm@61575
    70
  plugin components, which needs special attention since it overrides the
wenzelm@61575
    71
  standard Java class loader.
wenzelm@61575
    72
\<close>
wenzelm@47825
    73
wenzelm@52116
    74
wenzelm@58618
    75
section \<open>Scala script wrapper\<close>
wenzelm@52116
    76
wenzelm@61575
    77
text \<open>
wenzelm@61575
    78
  The executable @{executable "$ISABELLE_HOME/bin/isabelle_scala_script"}
wenzelm@61575
    79
  allows to run Isabelle/Scala source files stand-alone programs, by using a
wenzelm@62415
    80
  suitable ``hash-bang'' line and executable file permissions. For example:
wenzelm@61407
    81
  @{verbatim [display]
wenzelm@61407
    82
\<open>#!/usr/bin/env isabelle_scala_script
wenzelm@52116
    83
wenzelm@52116
    84
val options = isabelle.Options.init()
wenzelm@52116
    85
Console.println("browser_info = " + options.bool("browser_info"))
wenzelm@61407
    86
Console.println("document = " + options.string("document"))\<close>}
wenzelm@52116
    87
wenzelm@62415
    88
  This assumes that the executable may be found via the @{setting PATH} from
wenzelm@62415
    89
  the process environment: this is the case when Isabelle settings are active,
wenzelm@62415
    90
  e.g.\ in the context of the main Isabelle tool wrapper
wenzelm@63680
    91
  \secref{sec:isabelle-tool}. Alternatively, the full
wenzelm@63680
    92
  \<^file>\<open>$ISABELLE_HOME/bin/isabelle_scala_script\<close> may be specified in expanded
wenzelm@62415
    93
  form.
wenzelm@61575
    94
\<close>
wenzelm@52116
    95
wenzelm@47825
    96
end