2015-02-24 07:22:58 +03:00
|
|
|
module REPL
|
|
|
|
open System
|
|
|
|
|
2015-07-02 21:39:54 +03:00
|
|
|
let READ input =
|
2015-03-01 07:07:55 +03:00
|
|
|
try
|
2015-03-01 18:49:55 +03:00
|
|
|
Reader.read_str input
|
2015-03-01 07:07:55 +03:00
|
|
|
with
|
2015-05-02 09:50:09 +03:00
|
|
|
| Error.ReaderError(msg) ->
|
2015-03-05 04:14:07 +03:00
|
|
|
printfn "%s" msg
|
|
|
|
[]
|
2015-02-24 07:22:58 +03:00
|
|
|
|
2015-07-02 21:39:54 +03:00
|
|
|
let EVAL ast =
|
2015-03-01 07:07:55 +03:00
|
|
|
Some(ast)
|
2015-02-24 07:22:58 +03:00
|
|
|
|
2015-07-02 21:39:54 +03:00
|
|
|
let PRINT v =
|
2015-02-24 07:22:58 +03:00
|
|
|
v
|
2015-03-26 22:05:02 +03:00
|
|
|
|> Seq.singleton
|
2015-02-24 07:22:58 +03:00
|
|
|
|> Printer.pr_str
|
2015-03-01 07:07:55 +03:00
|
|
|
|> printfn "%s"
|
2015-02-24 07:22:58 +03:00
|
|
|
|
2015-07-02 21:39:54 +03:00
|
|
|
let REP input =
|
|
|
|
READ input
|
2015-03-05 04:14:07 +03:00
|
|
|
|> Seq.ofList
|
2015-07-02 21:39:54 +03:00
|
|
|
|> Seq.map (fun form -> EVAL form)
|
2015-03-05 04:14:07 +03:00
|
|
|
|> Seq.filter Option.isSome
|
2015-07-02 21:39:54 +03:00
|
|
|
|> Seq.iter (fun value -> PRINT value.Value)
|
2015-03-01 07:07:55 +03:00
|
|
|
|
2015-07-03 03:04:33 +03:00
|
|
|
let getReadlineMode args =
|
|
|
|
if args |> Array.exists (fun e -> e = "--raw") then
|
2015-03-01 07:07:55 +03:00
|
|
|
Readline.Mode.Raw
|
|
|
|
else
|
|
|
|
Readline.Mode.Terminal
|
2015-02-24 07:22:58 +03:00
|
|
|
|
|
|
|
[<EntryPoint>]
|
Test uncaught throw, catchless try* . Fix 46 impls.
Fixes made to: ada, c, chuck, clojure, coffee, common-lisp, cpp,
crystal, d, dart, elm, erlang, es6, factor, fsharp, gnu-smalltalk,
groovy, guile, haxe, hy, js, livescript, matlab, miniMAL, nasm, nim,
objc, objpascal, ocaml, perl, perl6, php, plsql, ps, python, r,
rpython, ruby, scheme, swift3, tcl, ts, vb, vimscript, wasm, yorick.
Catchless try* test is an optional test. Not all implementations
support catchless try* but a number were fixed so they at least don't
crash on catchless try*.
2018-12-03 22:20:44 +03:00
|
|
|
let main args =
|
2015-03-01 07:07:55 +03:00
|
|
|
let mode = getReadlineMode args
|
Test uncaught throw, catchless try* . Fix 46 impls.
Fixes made to: ada, c, chuck, clojure, coffee, common-lisp, cpp,
crystal, d, dart, elm, erlang, es6, factor, fsharp, gnu-smalltalk,
groovy, guile, haxe, hy, js, livescript, matlab, miniMAL, nasm, nim,
objc, objpascal, ocaml, perl, perl6, php, plsql, ps, python, r,
rpython, ruby, scheme, swift3, tcl, ts, vb, vimscript, wasm, yorick.
Catchless try* test is an optional test. Not all implementations
support catchless try* but a number were fixed so they at least don't
crash on catchless try*.
2018-12-03 22:20:44 +03:00
|
|
|
let rec loop () =
|
|
|
|
match Readline.read "user> " mode with
|
|
|
|
| null -> 0
|
|
|
|
| input ->
|
|
|
|
REP input
|
|
|
|
loop()
|
|
|
|
loop ()
|