Skip to content

Commit

Permalink
Yet another implementation of Str.global_replace
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Adams committed Aug 2, 2012
1 parent 3cd3488 commit 3022a4a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/cg_c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,21 @@ let ccall f args = C.Call(C.ID f, args)
let cg_entry e =
let name,args,stmt = e in

let cname name =
let rec cname name =
(* No batteries, so the below line doesn't work *)
(* Str.global_replace (Str.regexp "\\.") "__" name in *)
String.map (function | '.' -> '_' | x -> x) name
(* No ocaml 4.0, so the below line doesn't work either. Sigh *)
(* String.map (function | '.' -> '_' | x -> x) name *)
let len = String.length name in
try begin
let first_dot = String.index name '.' in
let rest = "__" ^ (cname (String.sub name (first_dot+1) (len-first_dot-1))) in
match first_dot with
| 0 -> rest
| _ ->
let first = (String.sub name 0 first_dot) in
first ^ rest
end with Not_found -> name
in

let carg_decl = function
Expand Down Expand Up @@ -185,6 +196,10 @@ let cg_entry e =

C.Block ([scratch_init], prod @ cons @ free)

| Print (_)
| Assert (_, _) ->
Printf.printf "TODO: skipping codegen of Print/Assert in C backend\n";
C.Block([], [])
| s -> failwith (Printf.sprintf "Can't codegen: %s" (Ir_printer.string_of_stmt s))

and cg_for name min size stmt =
Expand Down

0 comments on commit 3022a4a

Please sign in to comment.