[v5,2/2] resolve ihandle and xt handle in the input command (like for the output)

Message ID 20180323114224.20407-3-lvivier@redhat.com
State Superseded
Headers show
Series
  • Fix output word
Related show

Commit Message

Laurent Vivier March 23, 2018, 11:42 a.m.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 slof/fs/term-io.fs | 89 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 46 insertions(+), 43 deletions(-)

Comments

Thomas Huth March 26, 2018, 11:18 a.m. | #1
On 23.03.2018 12:42, Laurent Vivier wrote:
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  slof/fs/term-io.fs | 89 ++++++++++++++++++++++++++++--------------------------
>  1 file changed, 46 insertions(+), 43 deletions(-)
> 
> diff --git a/slof/fs/term-io.fs b/slof/fs/term-io.fs
> index 97d02a4..2db0968 100644
> --- a/slof/fs/term-io.fs
> +++ b/slof/fs/term-io.fs
> @@ -10,10 +10,20 @@
>  \ *     IBM Corporation - initial implementation
>  \ ****************************************************************************/
>  
> +0 VALUE read-xt
>  0 VALUE write-xt
>  
> +VARIABLE stdin
>  VARIABLE stdout
>  
> +: set-stdin ( ihandle -- )
> +   \ Close old stdin:
> +   stdin @ ?dup IF close-dev THEN
> +   \ Now set the new stdin:
> +   dup stdin !
> +   encode-int s" stdin"  set-chosen
> +;
> +
>  : set-stdout ( ihandle -- )
>     \ Close old stdout:
>     stdout @ ?dup IF close-dev THEN
> @@ -24,12 +34,15 @@ VARIABLE stdout
>  
>  : input  ( dev-str dev-len -- )
>     open-dev ?dup IF
> -      \ Close old stdin:
> -      s" stdin" get-chosen IF
> -         decode-int nip nip ?dup IF close-dev THEN
> +      \ find new ihandle and xt handle
> +      dup s" read" rot ihandle>phandle find-method
> +      0= IF
> +         drop
> +         cr ." Cannot find the read method for the given input console " cr
> +         EXIT
>        THEN
> -      \ Now set the new stdin:
> -      encode-int s" stdin"  set-chosen
> +      to read-xt
> +      set-stdin
>     THEN
>  ;
>  
> @@ -64,17 +77,12 @@ VARIABLE stdout
>  ' term-io-emit to emit
>  
>  : term-io-key  ( -- char )
> -   s" stdin" get-chosen IF
> -      decode-int nip nip dup 0= IF 0 EXIT THEN
> -      >r BEGIN
> -         (term-io-char-buf) 1 s" read" r@ $call-method
> -         0 >
> -      UNTIL
> -      (term-io-char-buf) c@
> -      r> drop
> -   ELSE
> -      [ ' key behavior compile, ]
> -   THEN
> +   read-xt 0= IF 0 EXIT THEN

Please keep the "[ ' key behavior compile, ]" here instead of "0"

> +   BEGIN
> +     (term-io-char-buf) 1 read-xt stdin @ call-package
> +     0 >
> +   UNTIL
> +   (term-io-char-buf) c@
>  ;
>  
>  ' term-io-key to key
> @@ -85,35 +93,30 @@ VARIABLE stdout
>  \ - if it's an hv console, use hvterm-key?
>  \ otherwise it will always return false
>  : term-io-key?  ( -- true|false )
> -   s" stdin" get-chosen IF
> -      decode-int nip nip dup 0= IF drop 0 EXIT THEN \ return false and exit if no stdin set
> -      >r \ store ihandle on return stack
> -      s" device_type" r@ ihandle>phandle ( propstr len phandle )
> -      get-property ( true | data dlen false )
> -      IF
> -         \ device_type not found, return false and exit
> -         false
> -      ELSE
> -         1 - \ remove 1 from length to ignore null-termination char
> -         \ device_type found, check wether it is serial or keyboard
> -         2dup s" serial" str= IF
> -	    2drop serial-key? r> drop EXIT
> -	 THEN \ call serial-key, cleanup return-stack, exit
> -         2dup s" keyboard" str= IF 
> -            2drop ( )
> -            \ keyboard found, check for key-available? method, execute it or return false 
> -            s" key-available?" r@ ihandle>phandle find-method IF 
> -               drop s" key-available?" r@ $call-method  
> -            ELSE 
> -               false 
> -            THEN
> -            r> drop EXIT \ cleanup return-stack, exit
> +   stdin @ ?dup 0= IF false EXIT THEN \ stdin not set, return false

stdin @ ?dup 0= IF [ ' key? behaviour compile, ] EXIT THEN

Or maybe even:

stdin @ ?dup 0= IF
  [ ' key? behaviour compile, ]
ELSE
  ...

to keep the original indentation of the following code, so that the
patch gets easier to review?

> +   >r \ store ihandle on return stack
> +   s" device_type" r@ ihandle>phandle ( propstr len phandle )
> +   get-property ( true | data dlen false )
> +   IF
> +      \ device_type not found, return false and exit
> +      false
> +   ELSE
> +      1 - \ remove 1 from length to ignore null-termination char
> +      \ device_type found, check wether it is serial or keyboard
> +      2dup s" serial" str= IF
> +         2drop serial-key? r> drop EXIT
> +      THEN \ call serial-key, cleanup return-stack, exit
> +      2dup s" keyboard" str= IF
> +         2drop ( )
> +         \ keyboard found, check for key-available? method, execute it or return false
> +         s" key-available?" r@ ihandle>phandle find-method IF
> +            drop s" key-available?" r@ $call-method
> +         ELSE
> +            false
>           THEN
> -         2drop r> drop false EXIT \ unknown device_type cleanup return-stack, return false
> +         r> drop EXIT \ cleanup return-stack, exit
>        THEN
> -   ELSE
> -      \ stdin not set, return false
> -      false
> +      2drop r> drop false EXIT \ unknown device_type cleanup return-stack, return false
>     THEN
>  ;

 Thomas

Patch

diff --git a/slof/fs/term-io.fs b/slof/fs/term-io.fs
index 97d02a4..2db0968 100644
--- a/slof/fs/term-io.fs
+++ b/slof/fs/term-io.fs
@@ -10,10 +10,20 @@ 
 \ *     IBM Corporation - initial implementation
 \ ****************************************************************************/
 
+0 VALUE read-xt
 0 VALUE write-xt
 
+VARIABLE stdin
 VARIABLE stdout
 
+: set-stdin ( ihandle -- )
+   \ Close old stdin:
+   stdin @ ?dup IF close-dev THEN
+   \ Now set the new stdin:
+   dup stdin !
+   encode-int s" stdin"  set-chosen
+;
+
 : set-stdout ( ihandle -- )
    \ Close old stdout:
    stdout @ ?dup IF close-dev THEN
@@ -24,12 +34,15 @@  VARIABLE stdout
 
 : input  ( dev-str dev-len -- )
    open-dev ?dup IF
-      \ Close old stdin:
-      s" stdin" get-chosen IF
-         decode-int nip nip ?dup IF close-dev THEN
+      \ find new ihandle and xt handle
+      dup s" read" rot ihandle>phandle find-method
+      0= IF
+         drop
+         cr ." Cannot find the read method for the given input console " cr
+         EXIT
       THEN
-      \ Now set the new stdin:
-      encode-int s" stdin"  set-chosen
+      to read-xt
+      set-stdin
    THEN
 ;
 
@@ -64,17 +77,12 @@  VARIABLE stdout
 ' term-io-emit to emit
 
 : term-io-key  ( -- char )
-   s" stdin" get-chosen IF
-      decode-int nip nip dup 0= IF 0 EXIT THEN
-      >r BEGIN
-         (term-io-char-buf) 1 s" read" r@ $call-method
-         0 >
-      UNTIL
-      (term-io-char-buf) c@
-      r> drop
-   ELSE
-      [ ' key behavior compile, ]
-   THEN
+   read-xt 0= IF 0 EXIT THEN
+   BEGIN
+     (term-io-char-buf) 1 read-xt stdin @ call-package
+     0 >
+   UNTIL
+   (term-io-char-buf) c@
 ;
 
 ' term-io-key to key
@@ -85,35 +93,30 @@  VARIABLE stdout
 \ - if it's an hv console, use hvterm-key?
 \ otherwise it will always return false
 : term-io-key?  ( -- true|false )
-   s" stdin" get-chosen IF
-      decode-int nip nip dup 0= IF drop 0 EXIT THEN \ return false and exit if no stdin set
-      >r \ store ihandle on return stack
-      s" device_type" r@ ihandle>phandle ( propstr len phandle )
-      get-property ( true | data dlen false )
-      IF
-         \ device_type not found, return false and exit
-         false
-      ELSE
-         1 - \ remove 1 from length to ignore null-termination char
-         \ device_type found, check wether it is serial or keyboard
-         2dup s" serial" str= IF
-	    2drop serial-key? r> drop EXIT
-	 THEN \ call serial-key, cleanup return-stack, exit
-         2dup s" keyboard" str= IF 
-            2drop ( )
-            \ keyboard found, check for key-available? method, execute it or return false 
-            s" key-available?" r@ ihandle>phandle find-method IF 
-               drop s" key-available?" r@ $call-method  
-            ELSE 
-               false 
-            THEN
-            r> drop EXIT \ cleanup return-stack, exit
+   stdin @ ?dup 0= IF false EXIT THEN \ stdin not set, return false
+   >r \ store ihandle on return stack
+   s" device_type" r@ ihandle>phandle ( propstr len phandle )
+   get-property ( true | data dlen false )
+   IF
+      \ device_type not found, return false and exit
+      false
+   ELSE
+      1 - \ remove 1 from length to ignore null-termination char
+      \ device_type found, check wether it is serial or keyboard
+      2dup s" serial" str= IF
+         2drop serial-key? r> drop EXIT
+      THEN \ call serial-key, cleanup return-stack, exit
+      2dup s" keyboard" str= IF
+         2drop ( )
+         \ keyboard found, check for key-available? method, execute it or return false
+         s" key-available?" r@ ihandle>phandle find-method IF
+            drop s" key-available?" r@ $call-method
+         ELSE
+            false
          THEN
-         2drop r> drop false EXIT \ unknown device_type cleanup return-stack, return false
+         r> drop EXIT \ cleanup return-stack, exit
       THEN
-   ELSE
-      \ stdin not set, return false
-      false
+      2drop r> drop false EXIT \ unknown device_type cleanup return-stack, return false
    THEN
 ;