| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-19 15:10:40 -04:00
										 |  |  | USING: kernel parser words continuations namespaces debugger | 
					
						
							| 
									
										
										
										
											2008-04-20 18:17:48 -04:00
										 |  |  |        sequences combinators splitting prettyprint | 
					
						
							| 
									
										
										
										
											2008-05-16 19:14:36 -04:00
										 |  |  |        system io io.files io.launcher io.encodings.utf8 io.pipes sequences.deep | 
					
						
							| 
									
										
										
										
											2008-06-24 14:47:54 -04:00
										 |  |  |        accessors multi-methods newfx shell.parser | 
					
						
							|  |  |  |        combinators.short-circuit ;
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | IN: shell | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : cd ( args -- )
 | 
					
						
							|  |  |  |   dup empty?
 | 
					
						
							|  |  |  |     [ drop home set-current-directory ] | 
					
						
							|  |  |  |     [ first     set-current-directory ] | 
					
						
							|  |  |  |   if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : pwd ( args -- )
 | 
					
						
							|  |  |  |   drop
 | 
					
						
							|  |  |  |   current-directory get
 | 
					
						
							|  |  |  |   print ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : swords ( -- seq ) { "cd" "pwd" } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GENERIC: expand ( expr -- expr )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | METHOD: expand { single-quoted-expr } expr>> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | METHOD: expand { double-quoted-expr } expr>> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-17 20:46:28 -04:00
										 |  |  | METHOD: expand { variable-expr } expr>> os-env ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | METHOD: expand { glob-expr } | 
					
						
							|  |  |  |   expr>> | 
					
						
							|  |  |  |   dup "*" =
 | 
					
						
							|  |  |  |     [ drop current-directory get directory [ first ] map ] | 
					
						
							|  |  |  |     [ ] | 
					
						
							|  |  |  |   if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-19 15:10:40 -04:00
										 |  |  | METHOD: expand { factor-expr } expr>> eval unparse ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-20 18:17:48 -04:00
										 |  |  | DEFER: expansion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | METHOD: expand { back-quoted-expr } | 
					
						
							|  |  |  |   expr>> | 
					
						
							|  |  |  |   expr | 
					
						
							|  |  |  |   ast>> | 
					
						
							|  |  |  |   command>> | 
					
						
							|  |  |  |   expansion | 
					
						
							|  |  |  |   utf8 <process-stream> | 
					
						
							|  |  |  |   contents
 | 
					
						
							|  |  |  |   " \n" split | 
					
						
							|  |  |  |   "" remove ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | METHOD: expand { object } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-17 20:46:28 -04:00
										 |  |  | : expansion ( command -- command ) [ expand ] map flatten ;
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-19 15:10:40 -04:00
										 |  |  | : run-sword ( basic-expr -- )
 | 
					
						
							|  |  |  |   command>> expansion unclip "shell" lookup execute ;
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : run-foreground ( process -- )
 | 
					
						
							|  |  |  |   [ try-process ] [ print-error drop ] recover ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : run-background ( process -- ) run-detached drop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : run-basic-expr ( basic-expr -- )
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  |   <process> | 
					
						
							|  |  |  |     over command>> expansion >>command | 
					
						
							|  |  |  |     over stdin>>             >>stdin | 
					
						
							|  |  |  |     over stdout>>            >>stdout | 
					
						
							|  |  |  |   swap background>> | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  |     [ run-background ] | 
					
						
							|  |  |  |     [ run-foreground ] | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  |   if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | : basic-chant ( basic-expr -- )
 | 
					
						
							| 
									
										
										
										
											2008-04-17 20:46:28 -04:00
										 |  |  |   dup command>> first swords member-of? | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  |     [ run-sword ] | 
					
						
							|  |  |  |     [ run-basic-expr ] | 
					
						
							|  |  |  |   if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-16 19:14:36 -04:00
										 |  |  | : pipeline-chant ( pipeline-chant -- ) commands>> run-pipeline drop ;
 | 
					
						
							| 
									
										
										
										
											2008-04-18 20:23:30 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : chant ( obj -- )
 | 
					
						
							|  |  |  |   dup basic-expr? | 
					
						
							|  |  |  |     [ basic-chant    ] | 
					
						
							|  |  |  |     [ pipeline-chant ] | 
					
						
							| 
									
										
										
										
											2008-04-17 20:46:28 -04:00
										 |  |  |   if ;
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : prompt ( -- )
 | 
					
						
							|  |  |  |   current-directory get write
 | 
					
						
							|  |  |  |   " $ " write
 | 
					
						
							|  |  |  |   flush ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-17 20:46:28 -04:00
										 |  |  | 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 ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | : shell ( -- )
 | 
					
						
							|  |  |  |   prompt | 
					
						
							|  |  |  |   readln
 | 
					
						
							| 
									
										
										
										
											2008-04-17 20:46:28 -04:00
										 |  |  |   handle ;
 | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2008-04-17 17:05:49 -04:00
										 |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ix ( -- ) shell ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MAIN: ix |