From 00def285ea26abbba200e87761da6067bcd7876e Mon Sep 17 00:00:00 2001 From: Barry Walsh Date: Sat, 29 Apr 2017 17:13:03 +0100 Subject: [PATCH] REPL renamed to CONSOLE (#484) --- src/boot/sysobj.r | 5 +- src/os/{host-repl.r => host-console.r} | 20 +++---- src/os/host-start.r | 82 ++++++++++++++++---------- src/tools/make-host-init.r | 2 +- 4 files changed, 65 insertions(+), 44 deletions(-) rename src/os/{host-repl.r => host-console.r} (94%) diff --git a/src/boot/sysobj.r b/src/boot/sysobj.r index 2a5b346e6a..18625bac8a 100644 --- a/src/boot/sysobj.r +++ b/src/boot/sysobj.r @@ -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 diff --git a/src/os/host-repl.r b/src/os/host-console.r similarity index 94% rename from src/os/host-repl.r rename to src/os/host-console.r index 24bc01ac16..54f1bb4b47 100644 --- a/src/os/host-repl.r +++ b/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 @@ -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 @@ -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 [ @@ -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 [ 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} @@ -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 @@ -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 @@ -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. ; diff --git a/src/os/host-start.r b/src/os/host-start.r index 0834f568f7..ddef41d9c0 100644 --- a/src/os/host-start.r +++ b/src/os/host-start.r @@ -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} - host-prot repl! + host-prot o (system/options) ;-- shorthand since options are often read/written ][ @@ -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 @@ -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 @@ -663,14 +678,14 @@ 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 @@ -678,16 +693,19 @@ repl!: make object! [ 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 ] ] + diff --git a/src/tools/make-host-init.r b/src/tools/make-host-init.r index 5f0c2f8b7d..0e9476231a 100644 --- a/src/tools/make-host-init.r +++ b/src/tools/make-host-init.r @@ -111,7 +111,7 @@ load-files: function [ host-start: load-files [ %encap.reb %unzip.reb - %host-repl.r + %host-console.r %host-start.r ]