\chapter{Detaillierte Compilerschnittstelle}
\label{cha_tlcompiler}

In diesem Abschnitt ist die Schnittstelle f"ur die detaillierte
Compilerschnittstelle dargestellt.

\begin{alltt}
\textbf{interface} TLCompiler
{\slshape(* System : Tycoon Compiler TLMin
   File   : TLCompiler.ti
   Author : CK
   Date   : 27-NOV-1996
   Purpose: low level interface to the TLMin Compiler
   Update : 
*)}
\textbf{import}
  errorLog :ErrorLog
  environment :Environment
\textbf{export}
  Switches <:\textbf{Ok}
  \textbf{Let} List = Oper(A <:\textbf{Ok}) \textbf{Ok}
  \textbf{Let} Position = \textbf{Tuple}
    where :String
    line, column :Int
  \textbf{end}
  noWhere :Position
  \textbf{Let} Source = \textbf{Tuple}
    \textbf{var} current :\textbf{Fun}() :Char
      \textsl{(* Return current character, initially " " *)}
    \textbf{var} next :\textbf{Fun}() :\textbf{Ok}
      \textsl{(* Advance current character position. 
        An exception will be raised
        if reading past of input *)}
    \textbf{var} position :Fun() :Position
      \textsl{(* Current source position *)}
    \textbf{var} close :Fun() :Ok
      \textsl{(* Terminate input fromthis source *)}
  \textbf{end}
  \textbf{Let} Identifier = Tuple
    pos :Position
    \textbf{var} name :String
  \textbf{end}
  \textbf{Let} Identifiers = List(Identifier)
  Value <:\textbf{Ok}
  Type <:\textbf{Ok}
  State <:\textbf{Ok}
  CheckedBindings <:\textbf{Ok}
  Bindings <:\textbf{Ok}
  wrongBindings :Bindings
  Grammar <:\textbf{Ok}
  EGrammar <:\textbf{Ok}
  Parser <:\textbf{Ok}
  InitialEnvironment <: \textbf{Ok}
  \textbf{Let} Context = \textbf{Tuple}
    switches :Switches
    \textbf{var} src :Source
    errLog :errorLog.T
    \textbf{var} gram :Grammar
    \textbf{var} parser :Parser
    \textbf{var} initialEnvironment :InitialEnvironment
    \textbf{var} env :environment.T
  \textbf{end}
  wrongSyntaxTree :environment.SyntaxTree
grammarError :Exception \textbf{end}
parseError :Exception \textbf{end}
typeCheckError :Exception \textbf{end}
translateError :Exception \textbf{end}
generateCodeError :Exception \textbf{end}

\textsl{(* functions to manipulate the compiler switches *)}
\textsl{(* switches used by type checker *)}
setTypeCheck (switches :Switches value :Bool) :\textbf{Ok}
setTraceSubType (switches :Switches value :Bool) :\textbf{Ok}
setTraceType (switches :Switches value :Bool) :\textbf{Ok}
setTraceValue (switches :Switches value :Bool) :\textbf{Ok}
setTraceApply (switches :Switches value :Bool) :\textbf{Ok}
setPrintIndices (switches :Switches value :Bool) :\textbf{Ok}
setPrintBackendIndices (switches :Switches value :Bool) :\textbf{Ok}
setCacheSubTyping (switches :Switches value :Bool) :\textbf{Ok}
setCacheLocalSubTyping (switches :Switches value :Bool) :\textbf{Ok}
setCacheExposing (switches :Switches value :Bool) :\textbf{Ok}

\textsl{(* switches used by tml-code-generation *)}
setExpandTuningPos (switches :Switches value :Int) :\textbf{Ok}
setExpandTuningPosRec (switches :Switches value :Int) :\textbf{Ok}
setExpandTuningNeg (switches :Switches value :Int) :\textbf{Ok}
setTraceReducer (switches :Switches value :Bool) :\textbf{Ok}
setTraceExpander (switches :Switches value :Bool) :\textbf{Ok}
setNotifyOptimization (switches :Switches value :Bool) :\textbf{Ok}

\textsl{(* switches used by backend *)}
setPrintTVM (switches :Switches value :Bool) :\textbf{Ok}
setExecutionLoops (switches :Switches value :Int) :\textbf{Ok}

\textsl{(* other switches *)}
setTypedOutput (switches :Switches value :Bool) :\textbf{Ok}
setTypedOutputDepth (switches :Switches value :Int) :\textbf{Ok}

sourceFromFile(name :String) :Source
sourceFromString(s :String) :Source
newSwitches() :Switches
newLog() :errorLog.T
newGrammar() :Grammar
getEGrammar(gram :Grammar) :EGrammar
printGrammarEnv(gram :Grammar) :\textbf{Ok}
printGrammar(gram :Grammar) :\textbf{Ok}
newParser(gram :Grammar) :Parser
newInitialEnvironment() :InitialEnvironment
newEnvironment() :environment.T
initEnvironment(initEnv :InitialEnvironment env :environment.T
                log :errorLog.T) :InitialEnvironment
printEnvironment(env :environment.T) :\textbf{Ok}
parse(\textbf{var} parser :Parser \textbf{var} gram :Grammar
      src :Source log :errorLog.T) :Bindings
typeCheck(switches :Switches 
          initialEnvironment :InitialEnvironment
          env :environment.T  
          bindings :Bindings
          log :errorLog.T) :environment.SyntaxTree
\end{alltt}
\newpage
\begin{alltt}
printSyntaxTree(switches :Switches 
                syntaxTree :environment.SyntaxTree 
                log :errorLog.T) :\textbf{Ok}
printSignature(switches :Switches 
               signature :environment.Signature
               log :errorLog.T) :\textbf{Ok}
translate(switches :Switches 
          initialEnvironment :InitialEnvironment
          env :environment.T 
          syntaxTree :environment.SyntaxTree
          log :errorLog.T) :environment.TMLCode
optimize(switches :Switches 
         tmlCode :environment.TMLCode 
         log :errorLog.T) :environment.TMLCode
printTMLCode(tmlCode :environment.TMLCode 
             log :errorLog.T) :\textbf{Ok}
generateCode(switches :Switches 
             env :environment.T 
             tmlCode :environment.TMLCode 
             log :errorLog.T) :environment.TVMCode
execute(switches :Switches 
        env :environment.T 
        tvmCode :environment.TVMCode 
        log :errorLog.T) :environment.Result
printResult(switches :Switches 
            result :environment.Result 
            log :errorLog.T) :\textbf{Ok}
printResultValue(result :environment.Result 
                 log :errorLog.T) :\textbf{Ok}
saveSystem(log :errorLog.T) :\textbf{Ok}
printLog(log :errorLog.T) :\textbf{Ok}
printLogClear(log :errorLog.T) :\textbf{Ok}
clearLog(log :errorLog.T) :\textbf{Ok}
\textbf{end};
\end{alltt}