From 733aef627660b769d1d74ec5ff38173b064c2860 Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Thu, 17 Apr 2008 19:46:28 -0500
Subject: [PATCH 1/2] shell: Add environment variable lookup

---
 extra/shell/parser/parser.factor |  6 ++++-
 extra/shell/shell.factor         | 46 +++++++++++++++++++++-----------
 2 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/extra/shell/parser/parser.factor b/extra/shell/parser/parser.factor
index 846ff9cbf1..4e3ae8069c 100644
--- a/extra/shell/parser/parser.factor
+++ b/extra/shell/parser/parser.factor
@@ -14,6 +14,8 @@ TUPLE: double-quoted-expr expr ;
 TUPLE: back-quoted-expr   expr ;
 TUPLE: glob-expr          expr ;
 
+TUPLE: variable-expr expr ;
+
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : <single-quoted-expr> single-quoted-expr boa ;
@@ -45,6 +47,8 @@ bquote = "`"
 
 back-quoted = bquote (!(bquote) .)* bquote => [[ second >string <back-quoted-expr> ]]
 
+variable = "$" other => [[ second variable-expr boa ]]
+
 glob-char = ("*" | "?")
 
 non-glob-char = !(glob-char | white) .
@@ -57,7 +61,7 @@ glob = glob-beginning-string glob-char (glob-rest-string | glob-char)* => [[ fla
 
 other = (!(white | "&" | ">" | ">>" | "<") .)+ => [[ >string ]]
 
-element = (single-quoted | double-quoted | back-quoted | glob | other)
+element = (single-quoted | double-quoted | back-quoted | variable | glob | other)
 
 to-file = ">" whitespace other => [[ second ]]
 
diff --git a/extra/shell/shell.factor b/extra/shell/shell.factor
index 25ac09cbba..f36b6f6400 100644
--- a/extra/shell/shell.factor
+++ b/extra/shell/shell.factor
@@ -1,6 +1,6 @@
 
 USING: kernel words continuations namespaces debugger sequences combinators
-       io io.files io.launcher
+       system io io.files io.launcher sequences.deep
        accessors multi-methods newfx shell.parser ;
 
 IN: shell
@@ -32,11 +32,20 @@ METHOD: expand { single-quoted-expr } expr>> ;
 
 METHOD: expand { double-quoted-expr } expr>> ;
 
+METHOD: expand { variable-expr } expr>> os-env ;
+
+METHOD: expand { glob-expr }
+  expr>>
+  dup "*" =
+    [ drop current-directory get directory [ first ] map ]
+    [ ]
+  if ;
+
 METHOD: expand { object } ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: expansion ( command -- command ) [ expand ] map ;
+: expansion ( command -- command ) [ expand ] map flatten ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -53,10 +62,10 @@ METHOD: expand { object } ;
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : chant ( incantation -- )
-    dup command>> first swords member-of?
-      [ command>> unclip "shell" lookup execute ]
-      [ run-incantation ]
-    if ;
+  dup command>> first swords member-of?
+    [ command>> unclip "shell" lookup execute ]
+    [ run-incantation ]
+  if ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -67,18 +76,25 @@ METHOD: expand { object } ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
+DEFER: shell
+
+: handle ( input -- )
+  {
+    { [ dup f = ]      [ drop ] }
+    { [ dup "exit" = ] [ drop ] }
+    { [ dup "" = ]     [ drop shell ] }
+    { [ dup expr ]     [ expr ast>> chant shell ] }
+    { [ t ]            [ drop "ix: ignoring input" print shell ] }
+  }
+    cond ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
 : shell ( -- )
   prompt
   readln
-    {
-      { [ dup f = ] [ drop ] }
-      { [ dup "exit" = ] [ drop ] }
-      { [ dup "" = ] [ drop shell ] }
-      { [ dup expr ] [ expr ast>> chant shell ] }
-      { [ t ]        [ drop shell ] }
-    }
-  cond ;
-
+  handle ;
+  
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : ix ( -- ) shell ;

From 305b8e61389abf70d898539202b0a7bca2a96a51 Mon Sep 17 00:00:00 2001
From: Slava Pestov <slava@oberon.internal.stack-effects.com>
Date: Thu, 17 Apr 2008 19:54:52 -0500
Subject: [PATCH 2/2] Fix blum blum shub unit tests on big endian

---
 .../blum-blum-shub/blum-blum-shub-tests.factor       | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/extra/random/blum-blum-shub/blum-blum-shub-tests.factor b/extra/random/blum-blum-shub/blum-blum-shub-tests.factor
index a92f256eeb..c882dd2b4d 100644
--- a/extra/random/blum-blum-shub/blum-blum-shub-tests.factor
+++ b/extra/random/blum-blum-shub/blum-blum-shub-tests.factor
@@ -1,27 +1,29 @@
 USING: kernel math tools.test namespaces random
-random.blum-blum-shub ;
+random.blum-blum-shub alien.c-types sequences splitting ;
 IN: blum-blum-shub.tests
 
 [ 887708070 ] [
-    T{ blum-blum-shub f 590695557939 811977232793 } random-32*
+    T{ blum-blum-shub f 590695557939 811977232793 } clone random-32*
 ] unit-test
 
 
 [ 887708070 ] [
-    T{ blum-blum-shub f 590695557939 811977232793 } [
+    T{ blum-blum-shub f 590695557939 811977232793 } clone [
         32 random-bits
+        little-endian? [ <uint> reverse *uint ] unless
     ] with-random
 ] unit-test
 
 [ 5726770047455156646 ] [
-    T{ blum-blum-shub f 590695557939 811977232793 } [
+    T{ blum-blum-shub f 590695557939 811977232793 } clone [
         64 random-bits
+        little-endian? [ <ulonglong> 4 group [ reverse ] map concat *ulonglong ] unless
     ] with-random
 ] unit-test
 
 [ 3716213681 ]
 [
-    100 T{ blum-blum-shub f 200352954495 846054538649 } tuck [
+    100 T{ blum-blum-shub f 200352954495 846054538649 } clone tuck [
         random-32* drop
     ] curry times
     random-32*