Shells in OCaml
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Simplify evaluation

There was a lot of duplicated code, now there is less.

+10 -49
+5 -49
src/lib/eval.ml
··· 277 277 let ctx = collect_assignments ~update:false ctx prefix in 278 278 loop ctx job (pgid, stdout_of_previous) 279 279 (Ast.SimpleCommand (Named (executable, suffix)) :: rest) 280 - | Ast.SimpleCommand (Named (executable, None)) :: rest -> ( 280 + | Ast.SimpleCommand (Named (executable, suffix)) :: rest -> ( 281 281 let ctx, executable = expand_cst ctx executable in 282 282 let executable = handle_word_components_to_string ctx executable in 283 - let some_read, some_write = 284 - stdout_for_pipeline ctx ~sw:pipeline_switch rest 285 - in 286 - let is_global, some_write = 287 - match some_write with 288 - | `Global p -> (true, p) 289 - | `Local p -> (false, p) 283 + let ctx, suffix = 284 + match suffix with 285 + | None -> (ctx, []) 286 + | Some suffix -> expand_redirects (ctx, []) suffix 290 287 in 291 - match Built_ins.of_args [ executable ] with 292 - | Some (Ok bi) -> 293 - let ctx = handle_built_in ctx bi in 294 - let built_in = ctx >|= fun _ -> () in 295 - let job = handle_job ~pgid job (`Built_in built_in) in 296 - loop (Exit.value ctx) job (pgid, stdout_of_previous) rest 297 - | Some (Error _) -> 298 - (ctx, handle_job ~pgid job (`Built_in (Exit.nonzero () 1))) 299 - | None -> ( 300 - let saved_ctx = ctx in 301 - match 302 - let ctx = { ctx with stdout = some_write } in 303 - handle_function_application ctx ~name:executable [ executable ] 304 - with 305 - | Some ctx -> 306 - close_stdout ~is_global some_write; 307 - (* TODO: Proper job stuff and redirects etc. *) 308 - let job = 309 - handle_job ~pgid job (`Built_in (ctx >|= fun _ -> ())) 310 - in 311 - loop saved_ctx job (pgid, some_read) rest 312 - | None -> ( 313 - match stdout_of_previous with 314 - | None -> 315 - let ctx, job = 316 - exec_process ctx job ~stdout:some_write ~pgid 317 - [ executable ] 318 - in 319 - close_stdout ~is_global some_write; 320 - loop ctx job (pgid, some_read) rest 321 - | Some stdout -> 322 - let ctx, job = 323 - exec_process ctx job ~stdin:stdout ~stdout:some_write 324 - ~pgid [ executable ] 325 - in 326 - close_stdout ~is_global some_write; 327 - loop ctx job (pgid, some_read) rest))) 328 - | Ast.SimpleCommand (Named (executable, Some suffix)) :: rest -> ( 329 - let ctx, executable = expand_cst ctx executable in 330 - let executable = handle_word_components_to_string ctx executable in 331 - let ctx, suffix = expand_redirects (ctx, []) suffix in 332 288 let args = args ctx suffix in 333 289 let some_read, some_write = 334 290 stdout_for_pipeline ~sw:pipeline_switch ctx rest
+5
test/simple.t
··· 55 55 $ msh -c "FOO=bar; env | grep FOO" 56 56 [1] 57 57 58 + $ sh -c "FOO=bar echo hello | env | grep FOO" 59 + [1] 60 + $ msh -c "FOO=bar echo hello | env | grep FOO" 61 + [1] 62 + 58 63 2. Pipelines with And|Or 59 64 60 65 2.1 Simple Or