Core.Std.Stack

Reviewed By: cristianoc

Differential Revision: D4232443

fbshipit-source-id: 0ef7f9e
master
Josh Berdine 8 years ago committed by Facebook Github Bot
parent 7e6278baeb
commit f86fc2ce2d

@ -1761,11 +1761,11 @@ end = struct
let stack = Stack.create () let stack = Stack.create ()
let init es = let init es =
Stack.clear stack; Stack.clear stack;
IList.iter (fun e -> Stack.push e stack) (IList.rev es) IList.iter (fun e -> Stack.push stack e) (IList.rev es)
let final () = Stack.clear stack let final () = Stack.clear stack
let is_empty () = Stack.is_empty stack let is_empty () = Stack.is_empty stack
let push e = Stack.push e stack let push e = Stack.push stack e
let pop () = Stack.pop stack let pop () = Stack.pop_exn stack
end end
let sigma_get_start_lexps_sort sigma = let sigma_get_start_lexps_sort sigma =

@ -78,8 +78,8 @@ let run_jobs_in_parallel jobs_stack gen_prog prog_to_string =
let run_job () = let run_job () =
let jobs_map = ref PidMap.empty in let jobs_map = ref PidMap.empty in
let current_jobs_count = start_current_jobs_count () in let current_jobs_count = start_current_jobs_count () in
while not (Caml.Stack.is_empty jobs_stack) do while not (Stack.is_empty jobs_stack) do
let job_prog = Caml.Stack.pop jobs_stack in let job_prog = Stack.pop_exn jobs_stack in
let (dir_opt, prog, args, env) = gen_prog job_prog in let (dir_opt, prog, args, env) = gen_prog job_prog in
Pervasives.incr current_jobs_count; Pervasives.incr current_jobs_count;
match Unix.fork () with match Unix.fork () with
@ -90,7 +90,7 @@ let run_jobs_in_parallel jobs_stack gen_prog prog_to_string =
|> never_returns |> never_returns
| `In_the_parent pid_child -> | `In_the_parent pid_child ->
jobs_map := PidMap.add pid_child (prog_to_string job_prog) !jobs_map; jobs_map := PidMap.add pid_child (prog_to_string job_prog) !jobs_map;
if Caml.Stack.length jobs_stack = 0 || !current_jobs_count >= Config.jobs then if Stack.length jobs_stack = 0 || !current_jobs_count >= Config.jobs then
wait_for_child (pid_to_program !jobs_map) current_jobs_count jobs_map wait_for_child (pid_to_program !jobs_map) current_jobs_count jobs_map
done in done in
run_job (); run_job ();

@ -30,7 +30,11 @@ module Nativeint = Core.Std.Nativeint
module Option = Core.Std.Option module Option = Core.Std.Option
module Pid = Core.Std.Pid module Pid = Core.Std.Pid
module Printexc = Core.Std.Printexc module Printexc = Core.Std.Printexc
module Printf = Core.Std.Printf
module Queue = Core.Std.Queue
module Random = Core.Std.Random
module Signal = Core.Std.Signal module Signal = Core.Std.Signal
module Stack = Core.Std.Stack
module String = Core.Std.String module String = Core.Std.String
module Sys = struct module Sys = struct
include Core.Std.Sys include Core.Std.Sys

@ -30,7 +30,11 @@ module Nativeint = Core.Std.Nativeint
module Option = Core.Std.Option module Option = Core.Std.Option
module Pid = Core.Std.Pid module Pid = Core.Std.Pid
module Printexc = Core.Std.Printexc module Printexc = Core.Std.Printexc
module Printf = Core.Std.Printf
module Queue = Core.Std.Queue
module Random = Core.Std.Random
module Signal = Core.Std.Signal module Signal = Core.Std.Signal
module Stack = Core.Std.Stack
module String = Core.Std.String module String = Core.Std.String
module Sys : module type of Core.Std.Sys module Sys : module type of Core.Std.Sys
module Unix = Core.Std.Unix module Unix = Core.Std.Unix

@ -136,7 +136,7 @@ module Debug = struct
let node = {id = t.next_id; content} in let node = {id = t.next_id; content} in
let create_subtree root = Tree (root, []) in let create_subtree root = Tree (root, []) in
let subtree' = create_subtree node in let subtree' = create_subtree node in
Stack.push subtree' t.eval_stack; Stack.push t.eval_stack subtree';
{t with next_id = t.next_id + 1} {t with next_id = t.next_id + 1}
let eval_end t result = let eval_end t result =
@ -145,16 +145,16 @@ module Debug = struct
| false -> Eval_false in | false -> Eval_false in
if Stack.is_empty t.eval_stack then if Stack.is_empty t.eval_stack then
raise (Empty_stack "Unbalanced number of eval_begin/eval_end invocations"); raise (Empty_stack "Unbalanced number of eval_begin/eval_end invocations");
let evaluated_tree = match Stack.pop t.eval_stack with let evaluated_tree = match Stack.pop_exn t.eval_stack with
| Tree ({id = _; content} as node, children) -> | Tree ({id = _; content} as node, children) ->
let content' = {content with eval_result = eval_result_of_bool result} in let content' = {content with eval_result = eval_result_of_bool result} in
Tree ({node with content = content'}, children) in Tree ({node with content = content'}, children) in
let forest' = let forest' =
if Stack.is_empty t.eval_stack then evaluated_tree :: t.forest if Stack.is_empty t.eval_stack then evaluated_tree :: t.forest
else else
let parent = match Stack.pop t.eval_stack with let parent = match Stack.pop_exn t.eval_stack with
Tree (node, children) -> Tree (node, evaluated_tree :: children) in Tree (node, children) -> Tree (node, evaluated_tree :: children) in
Stack.push parent t.eval_stack; Stack.push t.eval_stack parent;
t.forest in t.forest in
{t with forest = forest'} {t with forest = forest'}

@ -50,7 +50,7 @@ let add_flavor_to_targets args =
let create_files_stack compilation_database should_capture_file = let create_files_stack compilation_database should_capture_file =
let stack = Stack.create () in let stack = Stack.create () in
let add_to_stack file _ = if should_capture_file file then let add_to_stack file _ = if should_capture_file file then
Stack.push file stack in Stack.push stack file in
CompilationDatabase.iter compilation_database add_to_stack; CompilationDatabase.iter compilation_database add_to_stack;
stack stack

Loading…
Cancel
Save