module Idris.SetOptions import Core.Contextimport Core.Directoryimport Core.Metadataimport Core.Optionsimport Core.Unify import Idris.CommandLineimport Idris.REPLimport Idris.Syntaximport Idris.Version import YafflePaths import System -- TODO: Version numbers on dependenciesexportaddPkgDir : {auto c : Ref Ctxt Defs} -> String -> Core ()addPkgDir p = do defs <- get Ctxt addExtraDir (dir_prefix (dirs (options defs)) ++ dirSep ++ "idris2-" ++ showVersion False version ++ dirSep ++ p) dirOption : Dirs -> DirCommand -> Core ()dirOption dirs LibDir = coreLift $ putStrLn (dir_prefix dirs ++ dirSep ++ "idris2-" ++ showVersion False version ++ dirSep) -- Options to be processed before type checking. Return whether to continue.exportpreOptions : {auto c : Ref Ctxt Defs} -> {auto o : Ref ROpts REPLOpts} -> List CLOpt -> Core BoolpreOptions [] = pure TruepreOptions (NoBanner :: opts) = do setSession (record { nobanner = True } !getSession) preOptions opts-- These things are processed later, but imply nobanner toopreOptions (OutputFile _ :: opts) = do setSession (record { nobanner = True } !getSession) preOptions optspreOptions (ExecFn _ :: opts) = do setSession (record { nobanner = True } !getSession) preOptions optspreOptions (IdeMode :: opts) = do setSession (record { nobanner = True } !getSession) preOptions optspreOptions (CheckOnly :: opts) = do setSession (record { nobanner = True } !getSession) preOptions optspreOptions (Quiet :: opts) = do setOutput (REPL True) preOptions optspreOptions (NoPrelude :: opts) = do setSession (record { noprelude = True } !getSession) preOptions optspreOptions (SetCG e :: opts) = case getCG e of Just cg => do setCG cg preOptions opts Nothing => do coreLift $ putStrLn "No such code generator" coreLift $ putStrLn $ "Code generators available: " ++ showSep ", " (map fst availableCGs) coreLift $ exit 1preOptions (PkgPath p :: opts) = do addPkgDir p preOptions optspreOptions (Directory d :: opts) = do defs <- get Ctxt dirOption (dirs (options defs)) d pure FalsepreOptions (Timing :: opts) = do setLogTimings True preOptions optspreOptions (DebugElabCheck :: opts) = do setDebugElabCheck True preOptions optspreOptions (RunREPL _ :: opts) = do setOutput (REPL True) setSession (record { nobanner = True } !getSession) preOptions optspreOptions (FindIPKG :: opts) = do setSession (record { findipkg = True } !getSession) preOptions optspreOptions (DumpCases f :: opts) = do setSession (record { dumpcases = Just f } !getSession) preOptions optspreOptions (DumpLifted f :: opts) = do setSession (record { dumplifted = Just f } !getSession) preOptions optspreOptions (_ :: opts) = preOptions opts -- Options to be processed after type checking. Returns whether execution-- should continue (i.e., whether to start a REPL)exportpostOptions : {auto c : Ref Ctxt Defs} -> {auto u : Ref UST UState} -> {auto s : Ref Syn SyntaxInfo} -> {auto m : Ref MD Metadata} -> {auto o : Ref ROpts REPLOpts} -> List CLOpt -> Core BoolpostOptions [] = pure TruepostOptions (OutputFile outfile :: rest) = do compileExp (PRef (MkFC "(script)" (0, 0) (0, 0)) (UN "main")) outfile postOptions rest pure FalsepostOptions (ExecFn str :: rest) = do execExp (PRef (MkFC "(script)" (0, 0) (0, 0)) (UN str)) postOptions rest pure FalsepostOptions (CheckOnly :: rest) = do postOptions rest pure FalsepostOptions (RunREPL str :: rest) = do replCmd str pure FalsepostOptions (_ :: rest) = postOptions rest exportideMode : List CLOpt -> BoolideMode [] = FalseideMode (IdeMode :: _) = TrueideMode (_ :: xs) = ideMode xs exportideModeSocket : List CLOpt -> BoolideModeSocket [] = FalseideModeSocket (IdeModeSocket _ :: _) = TrueideModeSocket (_ :: xs) = ideModeSocket xs
module Idris.SetOptions
import Core.Context
import Core.Directory
import Core.Metadata
import Core.Options
import Core.Unify
import Idris.CommandLine
import Idris.REPL
import Idris.Syntax
import Idris.Version
import YafflePaths
import System
-- TODO: Version numbers on dependencies
export
addPkgDir : {auto c : Ref Ctxt Defs} ->
String -> Core ()
addPkgDir p
= do defs <- get Ctxt
addExtraDir (dir_prefix (dirs (options defs)) ++ dirSep ++
"idris2-" ++ showVersion False version ++ dirSep ++ p)
dirOption : Dirs -> DirCommand -> Core ()
dirOption dirs LibDir
= coreLift $ putStrLn
(dir_prefix dirs ++ dirSep ++ "idris2-" ++ showVersion False version ++ dirSep)
-- Options to be processed before type checking. Return whether to continue.
export
preOptions : {auto c : Ref Ctxt Defs} ->
{auto o : Ref ROpts REPLOpts} ->
List CLOpt -> Core Bool
preOptions [] = pure True
preOptions (NoBanner :: opts)
= do setSession (record { nobanner = True } !getSession)
preOptions opts
-- These things are processed later, but imply nobanner too
preOptions (OutputFile _ :: opts)
= do setSession (record { nobanner = True } !getSession)
preOptions opts
preOptions (ExecFn _ :: opts)
= do setSession (record { nobanner = True } !getSession)
preOptions opts
preOptions (IdeMode :: opts)
= do setSession (record { nobanner = True } !getSession)
preOptions opts
preOptions (CheckOnly :: opts)
= do setSession (record { nobanner = True } !getSession)
preOptions opts
preOptions (Quiet :: opts)
= do setOutput (REPL True)
preOptions opts
preOptions (NoPrelude :: opts)
= do setSession (record { noprelude = True } !getSession)
preOptions opts
preOptions (SetCG e :: opts)
= case getCG e of
Just cg => do setCG cg
preOptions opts
Nothing =>
do coreLift $ putStrLn "No such code generator"
coreLift $ putStrLn $ "Code generators available: " ++
showSep ", " (map fst availableCGs)
coreLift $ exit 1
preOptions (PkgPath p :: opts)
= do addPkgDir p
preOptions opts
preOptions (Directory d :: opts)
= do defs <- get Ctxt
dirOption (dirs (options defs)) d
pure False
preOptions (Timing :: opts)
= do setLogTimings True
preOptions opts
preOptions (DebugElabCheck :: opts)
= do setDebugElabCheck True
preOptions opts
preOptions (RunREPL _ :: opts)
= do setOutput (REPL True)
setSession (record { nobanner = True } !getSession)
preOptions opts
preOptions (FindIPKG :: opts)
= do setSession (record { findipkg = True } !getSession)
preOptions opts
preOptions (DumpCases f :: opts)
= do setSession (record { dumpcases = Just f } !getSession)
preOptions opts
preOptions (DumpLifted f :: opts)
= do setSession (record { dumplifted = Just f } !getSession)
preOptions opts
preOptions (_ :: opts) = preOptions opts
-- Options to be processed after type checking. Returns whether execution
-- should continue (i.e., whether to start a REPL)
export
postOptions : {auto c : Ref Ctxt Defs} ->
{auto u : Ref UST UState} ->
{auto s : Ref Syn SyntaxInfo} ->
{auto m : Ref MD Metadata} ->
{auto o : Ref ROpts REPLOpts} ->
List CLOpt -> Core Bool
postOptions [] = pure True
postOptions (OutputFile outfile :: rest)
= do compileExp (PRef (MkFC "(script)" (0, 0) (0, 0)) (UN "main")) outfile
postOptions rest
pure False
postOptions (ExecFn str :: rest)
= do execExp (PRef (MkFC "(script)" (0, 0) (0, 0)) (UN str))
postOptions rest
pure False
postOptions (CheckOnly :: rest)
= do postOptions rest
pure False
postOptions (RunREPL str :: rest)
= do replCmd str
pure False
postOptions (_ :: rest) = postOptions rest
export
ideMode : List CLOpt -> Bool
ideMode [] = False
ideMode (IdeMode :: _) = True
ideMode (_ :: xs) = ideMode xs
export
ideModeSocket : List CLOpt -> Bool
ideModeSocket [] = False
ideModeSocket (IdeModeSocket _ :: _) = True
ideModeSocket (_ :: xs) = ideModeSocket xs