mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
small optim in preprocessor
This commit is contained in:
parent
0364929a99
commit
e9e959eb6c
1 changed files with 18 additions and 16 deletions
|
|
@ -23,10 +23,6 @@ let prefix ~pre s =
|
||||||
check 0
|
check 0
|
||||||
)
|
)
|
||||||
|
|
||||||
type state =
|
|
||||||
| St_normal
|
|
||||||
| St_parsing_cond
|
|
||||||
|
|
||||||
let eval ~major ~minor op i j =
|
let eval ~major ~minor op i j =
|
||||||
match op with
|
match op with
|
||||||
| Le -> (major,minor) <= (i,j)
|
| Le -> (major,minor) <= (i,j)
|
||||||
|
|
@ -43,17 +39,19 @@ let preproc_lines ~file ~major ~minor (ic:in_channel) : unit =
|
||||||
| line ->
|
| line ->
|
||||||
let line' = String.trim line in
|
let line' = String.trim line in
|
||||||
incr pos;
|
incr pos;
|
||||||
if prefix line' ~pre:"[@@@ifle" then
|
if line' <> "" && line'.[0] = '[' then (
|
||||||
Scanf.sscanf line' "[@@@ifle %d.%d]" (fun x y -> If(Le,x,y))
|
if prefix line' ~pre:"[@@@ifle" then
|
||||||
else if prefix line' ~pre:"[@@@ifge" then
|
Scanf.sscanf line' "[@@@ifle %d.%d]" (fun x y -> If(Le,x,y))
|
||||||
Scanf.sscanf line' "[@@@ifge %d.%d]" (fun x y -> If(Ge,x,y))
|
else if prefix line' ~pre:"[@@@ifge" then
|
||||||
else if prefix line' ~pre:"[@@@elifle" then
|
Scanf.sscanf line' "[@@@ifge %d.%d]" (fun x y -> If(Ge,x,y))
|
||||||
Scanf.sscanf line' "[@@@elifle %d.%d]" (fun x y -> Elseif(Le,x,y))
|
else if prefix line' ~pre:"[@@@elifle" then
|
||||||
else if prefix line' ~pre:"[@@@elifge" then
|
Scanf.sscanf line' "[@@@elifle %d.%d]" (fun x y -> Elseif(Le,x,y))
|
||||||
Scanf.sscanf line' "[@@@elifge %d.%d]" (fun x y -> Elseif(Ge,x,y))
|
else if prefix line' ~pre:"[@@@elifge" then
|
||||||
else if line'="[@@@else_]" then Else
|
Scanf.sscanf line' "[@@@elifge %d.%d]" (fun x y -> Elseif(Ge,x,y))
|
||||||
else if line'="[@@@endif]" then Endif
|
else if line'="[@@@else_]" then Else
|
||||||
else Raw line
|
else if line'="[@@@endif]" then Endif
|
||||||
|
else Raw line
|
||||||
|
) else Raw line
|
||||||
in
|
in
|
||||||
|
|
||||||
(* entry point *)
|
(* entry point *)
|
||||||
|
|
@ -100,10 +98,14 @@ let preproc_lines ~file ~major ~minor (ic:in_channel) : unit =
|
||||||
top()
|
top()
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
|
let t0 = Unix.gettimeofday()in
|
||||||
let file = Sys.argv.(1) in
|
let file = Sys.argv.(1) in
|
||||||
let c = C.create "main" in
|
let c = C.create "main" in
|
||||||
let version = C.ocaml_config_var_exn c "version" in
|
let version = C.ocaml_config_var_exn c "version" in
|
||||||
let major, minor = Scanf.sscanf version "%u.%u" (fun maj min -> maj, min) in
|
let major, minor = Scanf.sscanf version "%u.%u" (fun maj min -> maj, min) in
|
||||||
|
|
||||||
let ic = open_in file in
|
let ic = open_in file in
|
||||||
preproc_lines ~file ~major ~minor ic
|
preproc_lines ~file ~major ~minor ic;
|
||||||
|
|
||||||
|
Printf.printf "(* file preprocessed in %.3fs *)\n" (Unix.gettimeofday() -. t0);
|
||||||
|
()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue