-
Notifications
You must be signed in to change notification settings - Fork 2
/
RunRepl.fs
57 lines (52 loc) · 1.7 KB
/
RunRepl.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Shen.Repl
open System
open Kl
open Kl.Values
open Kl.Evaluator
open Shen.Runtime
open ShenSharp.Shared
let private printVersion globals =
let shenVersion =
match retrieve globals "*version*" with
| Str s -> s
| _ -> "Unknown"
printfn "%s" shenVersion
printfn "ShenSharp %s" Revision
let rec private evalOptions globals = function
| [] -> true
| ("-v" | "--version") :: _ ->
printVersion globals
Environment.Exit 0
false
| ("-h" | "--help") :: _ ->
printVersion globals
printfn ""
printfn "Usage: shen [OPTIONS...]"
printfn " -v, --version : Prints Shen, ShenSharp version numbers and exits"
printfn " -h, --help : Shows this help and exits"
printfn " -e, --eval <expr> : Evaluates expr and prints result"
printfn " -l, --load <file> : Reads and evaluates file"
printfn ""
printfn "Evaluates options in order"
printfn "Starts the REPL if no eval/load options specified"
Environment.Exit 0
false
| ("-e" | "--eval") :: expr :: rest ->
printfn "%O" (evalSyntax globals expr)
evalOptions globals rest |> ignore
false
| ("-l" | "--load") :: file :: rest ->
load globals file
evalOptions globals rest |> ignore
false
| _ :: rest ->
evalOptions globals rest
let private runRepl args () =
try
let globals = newRuntime ()
if evalOptions globals args then
toCons [Sym "shen.repl"] |> eval globals |> ignore
with
e -> printfn "Unhandled error: %s" e.Message
[<EntryPoint>]
let main args = separateThread16MB (runRepl (Array.toList args))