@@ -416,78 +416,97 @@ function load_REPL()
416416end
417417
418418global active_repl
419+ global active_repl_backend = nothing
420+
421+ function run_fallback_repl (interactive:: Bool )
422+ let input = stdin
423+ if isa (input, File) || isa (input, IOStream)
424+ # for files, we can slurp in the whole thing at once
425+ ex = parse_input_line (read (input, String))
426+ if Meta. isexpr (ex, :toplevel )
427+ # if we get back a list of statements, eval them sequentially
428+ # as if we had parsed them sequentially
429+ for stmt in ex. args
430+ eval_user_input (stderr , stmt, true )
431+ end
432+ body = ex. args
433+ else
434+ eval_user_input (stderr , ex, true )
435+ end
436+ else
437+ while ! eof (input)
438+ if interactive
439+ print (" julia> " )
440+ flush (stdout )
441+ end
442+ try
443+ line = " "
444+ ex = nothing
445+ while ! eof (input)
446+ line *= readline (input, keep= true )
447+ ex = parse_input_line (line)
448+ if ! (isa (ex, Expr) && ex. head === :incomplete )
449+ break
450+ end
451+ end
452+ eval_user_input (stderr , ex, true )
453+ catch err
454+ isa (err, InterruptException) ? print (" \n\n " ) : rethrow ()
455+ end
456+ end
457+ end
458+ end
459+ nothing
460+ end
461+
462+ function run_std_repl (REPL:: Module , quiet:: Bool , banner:: Symbol , history_file:: Bool )
463+ term_env = get (ENV , " TERM" , @static Sys. iswindows () ? " " : " dumb" )
464+ term = REPL. Terminals. TTYTerminal (term_env, stdin , stdout , stderr )
465+ banner == :no || REPL. banner (term, short= banner== :short )
466+ if term. term_type == " dumb"
467+ repl = REPL. BasicREPL (term)
468+ quiet || @warn " Terminal not fully functional"
469+ else
470+ repl = REPL. LineEditREPL (term, get (stdout , :color , false ), true )
471+ repl. history_file = history_file
472+ end
473+ # Make sure any displays pushed in .julia/config/startup.jl ends up above the
474+ # REPLDisplay
475+ d = REPL. REPLDisplay (repl)
476+ last_active_repl = @isdefined (active_repl) ? active_repl : nothing
477+ last_active_repl_backend = active_repl_backend
478+ global active_repl = repl
479+ pushdisplay (d)
480+ try
481+ global active_repl = repl
482+ _atreplinit (repl)
483+ REPL. run_repl (repl, backend-> (global active_repl_backend = backend))
484+ finally
485+ popdisplay (d)
486+ active_repl = last_active_repl
487+ active_repl_backend = last_active_repl_backend
488+ end
489+ nothing
490+ end
419491
420492# run the requested sort of evaluation loop on stdio
421493function run_main_repl (interactive:: Bool , quiet:: Bool , banner:: Symbol , history_file:: Bool )
422494 fallback_repl = parse (Bool, get (ENV , " JULIA_FALLBACK_REPL" , " false" ))
423495 if ! fallback_repl && interactive
424496 load_InteractiveUtils ()
425- if ! isassigned (REPL_MODULE_REF)
497+ REPL = REPL_MODULE_REF[]
498+ if REPL === Base
426499 load_REPL ()
427500 end
428501 end
429- # TODO cleanup REPL_MODULE_REF
430- if ! fallback_repl && interactive && isassigned (REPL_MODULE_REF)
431- invokelatest (REPL_MODULE_REF[]) do REPL
432- term_env = get (ENV , " TERM" , @static Sys. iswindows () ? " " : " dumb" )
433- term = REPL. Terminals. TTYTerminal (term_env, stdin , stdout , stderr )
434- banner == :no || REPL. banner (term, short= banner== :short )
435- if term. term_type == " dumb"
436- repl = REPL. BasicREPL (term)
437- quiet || @warn " Terminal not fully functional"
438- else
439- repl = REPL. LineEditREPL (term, get (stdout , :color , false ), true )
440- repl. history_file = history_file
441- end
442- global active_repl = repl
443- # Make sure any displays pushed in .julia/config/startup.jl ends up above the
444- # REPLDisplay
445- pushdisplay (REPL. REPLDisplay (repl))
446- _atreplinit (repl)
447- REPL. run_repl (repl, backend-> (global active_repl_backend = backend))
448- end
502+ REPL = REPL_MODULE_REF[]
503+ if ! fallback_repl && interactive && REPL != = Base
504+ invokelatest (run_std_repl, REPL, quiet, banner, history_file)
449505 else
450- # otherwise provide a simple fallback
451506 if ! fallback_repl && interactive && ! quiet
452507 @warn " REPL provider not available: using basic fallback" LOAD_PATH = join (Base. LOAD_PATH , Sys. iswindows () ? ' ;' : ' :' )
453508 end
454- let input = stdin
455- if isa (input, File) || isa (input, IOStream)
456- # for files, we can slurp in the whole thing at once
457- ex = parse_input_line (read (input, String))
458- if Meta. isexpr (ex, :toplevel )
459- # if we get back a list of statements, eval them sequentially
460- # as if we had parsed them sequentially
461- for stmt in ex. args
462- eval_user_input (stderr , stmt, true )
463- end
464- body = ex. args
465- else
466- eval_user_input (stderr , ex, true )
467- end
468- else
469- while ! eof (input)
470- if interactive
471- print (" julia> " )
472- flush (stdout )
473- end
474- try
475- line = " "
476- ex = nothing
477- while ! eof (input)
478- line *= readline (input, keep= true )
479- ex = parse_input_line (line)
480- if ! (isa (ex, Expr) && ex. head === :incomplete )
481- break
482- end
483- end
484- eval_user_input (stderr , ex, true )
485- catch err
486- isa (err, InterruptException) ? print (" \n\n " ) : rethrow ()
487- end
488- end
489- end
490- end
509+ run_fallback_repl (interactive)
491510 end
492511 nothing
493512end
0 commit comments