Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -Bwiu --recursive ../Caml4.00/src.OLD/ocaml-4.00.1/utils/misc.ml build/ocaml-4.00.1/utils/misc.ml
- --- ../Caml4.00/src.OLD/ocaml-4.00.1/utils/misc.ml 2012-07-30 11:59:07.000000000 -0700
- +++ build/ocaml-4.00.1/utils/misc.ml 2013-03-25 13:29:03.077942186 -0700
- @@ -224,3 +224,52 @@
- let fst4 (x, _, _, _) = x
- let snd4 (_,x,_, _) = x
- let thd4 (_,_,x,_) = x
- +
- +(* Long string *)
- +
- +module LongString = struct
- + type t = string array
- +
- + let create str_size =
- + let tbl_size = str_size / Sys.max_string_length + 1 in
- + let tbl = Array.make tbl_size "" in
- + for i = 0 to tbl_size - 2 do
- + tbl.(i) <- String.create Sys.max_string_length;
- + done;
- + tbl.(tbl_size - 1) <- String.create (str_size mod Sys.max_string_length);
- + tbl
- + ;;
- +
- + let length tbl =
- + let tbl_size = Array.length tbl in
- + Sys.max_string_length * (tbl_size - 1) + String.length tbl.(tbl_size - 1)
- + ;;
- +
- + let get tbl ind =
- + tbl.(ind / Sys.max_string_length).[ind mod Sys.max_string_length]
- + ;;
- +
- + let set tbl ind c =
- + tbl.(ind / Sys.max_string_length).[ind mod Sys.max_string_length] <- c;
- + ;;
- +
- + let blit src srcoff dst dstoff len =
- + for i = 0 to len - 1 do set dst (dstoff + i) (get src (srcoff + i)) done
- + ;;
- +
- + let output oc tbl pos len =
- + for i = pos to pos + len - 1 do output_char oc (get tbl i) done;
- + ;;
- +
- + let unsafe_blit src srcoff dst dstoff len =
- + for i = 0 to len - 1 do
- + String.unsafe_set dst (dstoff + i) (get src (srcoff + i))
- + done;
- + ;;
- +
- + let input_bytes ic len =
- + let tbl = create len in
- + Array.iter (fun str -> really_input ic str 0 (String.length str)) tbl;
- + tbl
- + ;;
- +end;;
- diff -Bwiu --recursive ../Caml4.00/src.OLD/ocaml-4.00.1/utils/misc.mli build/ocaml-4.00.1/utils/misc.mli
- --- ../Caml4.00/src.OLD/ocaml-4.00.1/utils/misc.mli 2012-05-30 06:29:48.000000000 -0700
- +++ build/ocaml-4.00.1/utils/misc.mli 2013-03-25 13:29:03.077942186 -0700
- @@ -122,3 +122,16 @@
- val fst4: 'a * 'b * 'c * 'd -> 'a
- val snd4: 'a * 'b * 'c * 'd -> 'b
- val thd4: 'a * 'b * 'c * 'd -> 'c
- +
- +module LongString :
- + sig
- + type t = string array
- + val create : int -> string array
- + val length : string array -> int
- + val get : string array -> int -> char
- + val set : string array -> int -> char -> unit
- + val blit : string array -> int -> string array -> int -> int -> unit
- + val output : out_channel -> string array -> int -> int -> unit
- + val unsafe_blit : string array -> int -> string -> int -> int -> unit
- + val input_bytes : in_channel -> int -> t
- + end
- diff -Bwiu --recursive ../Caml4.00/src.OLD/ocaml-4.00.1/bytecomp/bytelink.ml build/ocaml-4.00.1/bytecomp/bytelink.ml
- --- ../Caml4.00/src.OLD/ocaml-4.00.1/bytecomp/bytelink.ml 2012-04-16 08:27:42.000000000 -0700
- +++ build/ocaml-4.00.1/bytecomp/bytelink.ml 2013-03-25 13:37:38.017927130 -0700
- @@ -188,21 +188,21 @@
- (* Record compilation events *)
- -let debug_info = ref ([] : (int * string) list)
- +let debug_info = ref ([] : (int * LongString.t) list)
- (* Link in a compilation unit *)
- let link_compunit ppf output_fun currpos_fun inchan file_name compunit =
- check_consistency ppf file_name compunit;
- seek_in inchan compunit.cu_pos;
- - let code_block = input_bytes inchan compunit.cu_codesize in
- - Symtable.patch_object code_block compunit.cu_reloc;
- + let code_block = LongString.input_bytes inchan compunit.cu_codesize in
- + Symtable.ls_patch_object code_block compunit.cu_reloc;
- if !Clflags.debug && compunit.cu_debug > 0 then begin
- seek_in inchan compunit.cu_debug;
- - let buffer = input_bytes inchan compunit.cu_debugsize in
- + let buffer = LongString.input_bytes inchan compunit.cu_debugsize in
- debug_info := (currpos_fun(), buffer) :: !debug_info
- end;
- - output_fun code_block;
- + Array.iter output_fun code_block;
- if !Clflags.link_everything then
- List.iter Symtable.require_primitive compunit.cu_primitives
- @@ -255,7 +255,7 @@
- let output_debug_info oc =
- output_binary_int oc (List.length !debug_info);
- List.iter
- - (fun (ofs, evl) -> output_binary_int oc ofs; output_string oc evl)
- + (fun (ofs, evl) -> output_binary_int oc ofs; Array.iter (output_string oc) evl)
- !debug_info;
- debug_info := []
- diff -Bwiu --recursive ../Caml4.00/src.OLD/ocaml-4.00.1/bytecomp/emitcode.ml build/ocaml-4.00.1/bytecomp/emitcode.ml
- --- ../Caml4.00/src.OLD/ocaml-4.00.1/bytecomp/emitcode.ml 2011-07-27 07:17:02.000000000 -0700
- +++ build/ocaml-4.00.1/bytecomp/emitcode.ml 2013-03-25 13:29:03.077942186 -0700
- @@ -24,21 +24,21 @@
- (* Buffering of bytecode *)
- -let out_buffer = ref(String.create 1024)
- +let out_buffer = ref(LongString.create 1024)
- and out_position = ref 0
- let out_word b1 b2 b3 b4 =
- let p = !out_position in
- - if p >= String.length !out_buffer then begin
- - let len = String.length !out_buffer in
- - let new_buffer = String.create (2 * len) in
- - String.blit !out_buffer 0 new_buffer 0 len;
- + if p >= LongString.length !out_buffer then begin
- + let len = LongString.length !out_buffer in
- + let new_buffer = LongString.create (2 * len) in
- + LongString.blit !out_buffer 0 new_buffer 0 len;
- out_buffer := new_buffer
- end;
- - String.unsafe_set !out_buffer p (Char.unsafe_chr b1);
- - String.unsafe_set !out_buffer (p+1) (Char.unsafe_chr b2);
- - String.unsafe_set !out_buffer (p+2) (Char.unsafe_chr b3);
- - String.unsafe_set !out_buffer (p+3) (Char.unsafe_chr b4);
- + LongString.set !out_buffer p (Char.unsafe_chr b1);
- + LongString.set !out_buffer (p+1) (Char.unsafe_chr b2);
- + LongString.set !out_buffer (p+2) (Char.unsafe_chr b3);
- + LongString.set !out_buffer (p+3) (Char.unsafe_chr b4);
- out_position := p + 4
- let out opcode =
- @@ -88,10 +88,10 @@
- let backpatch (pos, orig) =
- let displ = (!out_position - orig) asr 2 in
- - !out_buffer.[pos] <- Char.unsafe_chr displ;
- - !out_buffer.[pos+1] <- Char.unsafe_chr (displ asr 8);
- - !out_buffer.[pos+2] <- Char.unsafe_chr (displ asr 16);
- - !out_buffer.[pos+3] <- Char.unsafe_chr (displ asr 24)
- + LongString.set !out_buffer pos (Char.unsafe_chr displ);
- + LongString.set !out_buffer (pos+1) (Char.unsafe_chr (displ asr 8));
- + LongString.set !out_buffer (pos+2) (Char.unsafe_chr (displ asr 16));
- + LongString.set !out_buffer (pos+3) (Char.unsafe_chr (displ asr 24))
- let define_label lbl =
- if lbl >= Array.length !label_table then extend_label_table lbl;
- @@ -359,7 +359,7 @@
- output_binary_int outchan 0;
- let pos_code = pos_out outchan in
- emit code;
- - output outchan !out_buffer 0 !out_position;
- + LongString.output outchan !out_buffer 0 !out_position;
- let (pos_debug, size_debug) =
- if !Clflags.debug then begin
- let p = pos_out outchan in
- @@ -392,7 +392,7 @@
- emit init_code;
- emit fun_code;
- let code = Meta.static_alloc !out_position in
- - String.unsafe_blit !out_buffer 0 code 0 !out_position;
- + LongString.unsafe_blit !out_buffer 0 code 0 !out_position;
- let reloc = List.rev !reloc_info
- and code_size = !out_position in
- init();
- @@ -403,7 +403,7 @@
- let to_packed_file outchan code =
- init();
- emit code;
- - output outchan !out_buffer 0 !out_position;
- + LongString.output outchan !out_buffer 0 !out_position;
- let reloc = !reloc_info in
- init();
- reloc
- diff -Bwiu --recursive ../Caml4.00/src.OLD/ocaml-4.00.1/bytecomp/symtable.ml build/ocaml-4.00.1/bytecomp/symtable.ml
- --- ../Caml4.00/src.OLD/ocaml-4.00.1/bytecomp/symtable.ml 2012-06-21 08:55:03.000000000 -0700
- +++ build/ocaml-4.00.1/bytecomp/symtable.ml 2013-03-25 13:29:03.077942186 -0700
- @@ -177,25 +177,28 @@
- (* Must use the unsafe String.set here because the block may be
- a "fake" string as returned by Meta.static_alloc. *)
- -let patch_int buff pos n =
- - String.unsafe_set buff pos (Char.unsafe_chr n);
- - String.unsafe_set buff (pos + 1) (Char.unsafe_chr (n asr 8));
- - String.unsafe_set buff (pos + 2) (Char.unsafe_chr (n asr 16));
- - String.unsafe_set buff (pos + 3) (Char.unsafe_chr (n asr 24))
- +let gen_patch_int str_set buff pos n =
- + str_set buff pos (Char.unsafe_chr n);
- + str_set buff (pos + 1) (Char.unsafe_chr (n asr 8));
- + str_set buff (pos + 2) (Char.unsafe_chr (n asr 16));
- + str_set buff (pos + 3) (Char.unsafe_chr (n asr 24))
- -let patch_object buff patchlist =
- +let gen_patch_object str_set buff patchlist =
- List.iter
- (function
- (Reloc_literal sc, pos) ->
- - patch_int buff pos (slot_for_literal sc)
- + gen_patch_int str_set buff pos (slot_for_literal sc)
- | (Reloc_getglobal id, pos) ->
- - patch_int buff pos (slot_for_getglobal id)
- + gen_patch_int str_set buff pos (slot_for_getglobal id)
- | (Reloc_setglobal id, pos) ->
- - patch_int buff pos (slot_for_setglobal id)
- + gen_patch_int str_set buff pos (slot_for_setglobal id)
- | (Reloc_primitive name, pos) ->
- - patch_int buff pos (num_of_prim name))
- + gen_patch_int str_set buff pos (num_of_prim name))
- patchlist
- +let patch_object = gen_patch_object String.unsafe_set
- +let ls_patch_object = gen_patch_object LongString.set
- +
- (* Translate structured constants *)
- let rec transl_const = function
- diff -Bwiu --recursive ../Caml4.00/src.OLD/ocaml-4.00.1/bytecomp/symtable.mli build/ocaml-4.00.1/bytecomp/symtable.mli
- --- ../Caml4.00/src.OLD/ocaml-4.00.1/bytecomp/symtable.mli 2011-12-13 09:50:08.000000000 -0800
- +++ build/ocaml-4.00.1/bytecomp/symtable.mli 2013-03-25 13:29:03.077942186 -0700
- @@ -20,6 +20,7 @@
- val init: unit -> unit
- val patch_object: string -> (reloc_info * int) list -> unit
- +val ls_patch_object: Misc.LongString.t -> (reloc_info * int) list -> unit
- val require_primitive: string -> unit
- val initial_global_table: unit -> Obj.t array
- val output_global_map: out_channel -> unit
Add Comment
Please, Sign In to add comment