Skip to content

Commit

Permalink
REPL renamed to CONSOLE (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
draegtun committed Apr 29, 2017
1 parent cb11ba7 commit 00def28
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 44 deletions.
5 changes: 4 additions & 1 deletion src/boot/sysobj.r
Expand Up @@ -591,8 +591,11 @@ user: construct [] [
; trace: _
;]

repl: _ ;; repl object created in host-start (os/host-start.r)
console: _ ;; console (repl) object created in host-start (os/host-start.r)

; Below is original console construct (unused and comment-out in r3/ren-c)
; Left here for reference (for future development)
;
;console: construct [] [
; hide-types: _ ; types not to print
; history: _ ; Log of user inputs
Expand Down
20 changes: 10 additions & 10 deletions src/os/host-repl.r → src/os/host-console.r
@@ -1,6 +1,6 @@
REBOL [
System: "REBOL [R3] Language Interpreter and Run-time Environment"
Title: "Host Read-Eval-Print-Loop (REPL)"
Title: "Host Console (Rebol's Read-Eval-Print-Loop, ie. REPL)"
Rights: {
Copyright 2016-2017 Rebol Open Source Contributors
REBOL is a trademark of REBOL Technologies
Expand All @@ -13,11 +13,11 @@ REBOL [
This implements a simple interactive command line. It gathers strings
to be executed but does not actually run them with DO--instead it
returns a block to C code which does the actual execution. The
reason it is done this way is to avoid having Rebol REPL stack frames
reason it is done this way is to avoid having Rebol CONSOLE stack frames
hanging around when debug commands are executed (e.g. one does not
want BACKTRACE to see a FOREVER [] loop of gathering input, or the DO)
Though not implemented in C as the R3-Alpha REPL was, it still relies
Though not implemented in C as the R3-Alpha CONSOLE was, it still relies
upon INPUT to receive lines. INPUT reads lines from the "console
port", which is C code that is linked to STDTERM on POSIX and the
Win32 Console API on Windows. Thus, the ability to control the cursor
Expand All @@ -36,7 +36,7 @@ REBOL [
; https://github.com/red/red/issues/2487
;
; They are not implemented yet, but ECHO is moved here to signify the known
; issue that the REPL must collaborate specifically with ECHO to achieve
; issue that the CONSOLE must collaborate specifically with ECHO to achieve
; this.
;
echo: procedure [
Expand Down Expand Up @@ -153,14 +153,14 @@ echo: procedure [
]


host-repl: function [
host-console: function [
{Implements one Print-and-Read step of a Read-Eval-Print-Loop (REPL).}

return: [block! error!]
{Code to run or syntax error in the string input that tried to LOAD}

last-result [<opt> any-value!]
{The result from the last time HOST-REPL ran to display (if any)}
{The result from the last time HOST-CONSOLE ran to display (if any)}

last-failed [logic!]
{TRUE if the last-result is an ERROR! that FAILed vs just a result}
Expand All @@ -178,11 +178,11 @@ host-repl: function [
RE_SCAN_EXTRA (2002)
RE_SCAN_MISMATCH (2003)
][
; REPL is an external object for skinning the behaviour & appearance
; CONSOLE is an external object for skinning the behaviour & appearance
;
; /cycle - updates internal counter and print greeting on first rotation (ie. once)
;
repl: system/repl
repl: system/console
repl/cycle

source: copy {} ;-- source code potentially built of multiple lines
Expand Down Expand Up @@ -269,7 +269,7 @@ host-repl: function [
; Ren Garden does (though it takes two lines). It should not be
; applied to input that is pasted as text from another source,
; and arguably this could be disruptive to multi-line strings even
; if being entered in the REPL.
; if being entered in the CONSOLE
;
code: error

Expand Down Expand Up @@ -310,7 +310,7 @@ host-repl: function [
]

; There is a question of how it should be decided whether the code
; in the REPL should be locked as read-only or not. It may be a
; in the CONSOLE should be locked as read-only or not. It may be a
; configuration switch, as it also may be an option for a module or
; a special type of function which does not lock its source.
;
Expand Down
82 changes: 50 additions & 32 deletions src/os/host-start.r
Expand Up @@ -223,12 +223,12 @@ host-script-pre-load: procedure [
host-start: function [
"Loads extras, handles args, security, scripts."
return: [integer! function!]
{If integer, host should exit with that status; else a REPL FUNCTION!}
{If integer, host should exit with that status; else a CONSOLE FUNCTION!}
argv [block!]
{Raw command line argument block received by main() as STRING!s}
boot-exts [block! blank!]
{Extensions (modules) loaded at boot}
<with> host-prot repl!
<with> host-prot
<has>
o (system/options) ;-- shorthand since options are often read/written
][
Expand Down Expand Up @@ -288,7 +288,7 @@ host-start: function [

do-string: _ ;-- will be set if a string is given with --do

quit-when-done: _ ;-- by default run REPL
quit-when-done: _ ;-- by default run CONSOLE

o/home: what-dir ;-- save the current directory

Expand Down Expand Up @@ -577,67 +577,82 @@ comment [
boot-print boot-help


; REPL skinning:
; Instantiate REPL! object into system/repl
; This object can be updated from %repl-skin.reb (if found in system/user/rebol)
; See /os/host-repl.r where this object is called from
; CONSOLE skinning:
;
; Instantiate console! object into system/console
; This object can be updated from console!/skin-file
; - default is %console-skin.reb
; - if found in system/user/rebol
;
; See /os/host-console.r where this object is called from
;

proto-skin: []
skin-file: if system/user/rebol [join-of system/user/rebol %repl-skin.reb]
proto-skin: make console! [
skin-file: if system/user/rebol [join-of system/user/rebol %console-skin.reb]
]

if skin-file [
boot-print [newline "REPL skinning:" newline]
if skin-file: proto-skin/skin-file [
boot-print [newline "CONSOLE skinning:" newline]
trap/with [
;; load & run skin if found
if loaded-skin?: exists? skin-file [
if exists? skin-file [
new-skin: do load skin-file

;; if loaded skin returns REPL! object then use as prototype
;; if loaded skin returns console! object then use as prototype
if all [
object? new-skin
true? select new-skin 'repl ;; quacks like a REPL!
] [proto-skin: new-skin]
true? select new-skin 'repl ;; quacks like a REPL so its a console!
][
proto-skin: make new-skin compose [
skin-file: (skin-file)
updated?: true
]
]

proto-skin/loaded?: true
]

boot-print [
space space
either/only loaded-skin? {Loaded skin} {Skin does not exist}
either/only proto-skin/loaded? {Loaded skin} {Skin does not exist}
"-" skin-file
unspaced ["(" if/only empty? proto-skin {not } "updated REPL)"]
unspaced ["(" unless/only proto-skin/updated? {not } "updated CONSOLE)"]
]
] func [error] [
boot-print [
{ Error loading skin -} skin-file | |
error | |
{ Fix error and restart REPL}
{ Fix error and restart CONSOLE}
]
]

boot-print {}
]

system/repl: make repl! proto-skin
system/console: proto-skin


; Rather than have the host C code look up the REPL function by name, it
; Rather than have the host C code look up the CONSOLE function by name, it
; is returned as a function value from calling the start. It's a bit of
; a hack, and might be better with something like the SYS_FUNC table that
; lets the core call Rebol code.
;
return :host-repl
return :host-console
]


; Define REPL! object for skinning - stub for elsewhere?
; Define console! object for skinning - stub for elsewhere?
;

repl!: make object! [
repl: true
console!: make object! [
repl: true ;-- used to identify this as a console! object (quack!)
skin-file: _
loaded?: false ;-- if true then this is a loaded (external) skin
updated?: false ;-- if true then console! object found in loaded skin
counter: 0
last-result: _ ;-- last evaluated result (sent by HOST-REPL)
last-result: _ ;-- last evaluated result (sent by HOST-CONSOLE)

; Called on every line of input by HOST-REPL in %os/host-repl.r
; Called on every line of input by HOST-CONSOLE in %os/host-console.r
;
cycle: does [
if zero? ++ counter [print-greeting] ;-- only load skin on first cycle
Expand All @@ -663,31 +678,34 @@ repl!: make object! [
;; BEHAVIOR (can be overridden)

input-hook: func [
{Receives line input, parse/transform, send back to repl eval}
{Receives line input, parse/transform, send back to CONSOLE eval}
s
][
s
]

dialect-hook: func [
{Receives code block, parse/transform, send back to repl eval}
{Receives code block, parse/transform, send back to CONSOLE eval}
s
][
s
]

shortcuts: make object! [
q: [quit]
list-shortcuts: [print system/repl/shortcuts]
list-shortcuts: [print system/console/shortcuts]
]

;; HELPERS (could be overridden!)

add-shortcut: proc [
{Add/Change REPL shortcut}
name [any-word!] {shortcut name}
block [block!] {command(s) expanded to}
{Add/Change console shortcut}
name [any-word!]
{shortcut name}
block [block!]
{command(s) expanded to}
][
extend shortcuts name block
]
]

2 changes: 1 addition & 1 deletion src/tools/make-host-init.r
Expand Up @@ -111,7 +111,7 @@ load-files: function [
host-start: load-files [
%encap.reb
%unzip.reb
%host-repl.r
%host-console.r
%host-start.r
]

Expand Down

0 comments on commit 00def28

Please sign in to comment.