ocaml/test4
ocaml/test_format
ocaml/sudoku
+ocaml/test_buffer
+ocaml/test_overflow
ocaml/*.exe
ocaml/*.cmi
ocaml/*.cmx
# Test programs for testing out the cross-compiler.
all: test1 test1.exe test2 test2.exe test3 test3.exe test4 test4.exe \
- test_format test_format.exe sudoku sudoku.exe
+ test_format test_format.exe sudoku sudoku.exe \
+ test_buffer test_buffer.exe test_overflow test_overflow.exe
test1: test1.ml
ocamlopt $< -o $@
sudoku.exe: sudoku.ml
i686-pc-mingw32-ocamlopt $< -o $@
+test_buffer: test_buffer.ml
+ ocamlopt $< -o $@
+
+test_buffer.exe: test_buffer.ml
+ i686-pc-mingw32-ocamlopt $< -o $@
+
+test_overflow: test_overflow.ml
+ ocamlopt $< -o $@
+
+test_overflow.exe: test_overflow.ml
+ i686-pc-mingw32-ocamlopt $< -o $@
+
clean:
- rm -f test[1-4] test_format sudoku *.exe *.cmi *.cmx *.o
+ rm -f test[1-4] test_format sudoku test_buffer test_overflow \
+ *.exe *.cmi *.cmx *.o
--- /dev/null
+(* Test the Buffer module. *)
+
+let () =
+ let buf = Buffer.create 100 in
+ for i = 0 to 10 do
+ Buffer.add_char buf 'a';
+ Buffer.add_string buf "b";
+ Buffer.add_char buf 'c'
+ done;
+ let str = Buffer.contents buf in
+ Printf.printf "contents of buffer = %S\n%!" str
open Format
-let debug = false
+let debug = true
let () =
- if debug then Printf.printf "creating buffer ...\n%!";
let buf = Buffer.create 100 in
- if debug then Printf.printf "creating formatter ...\n%!";
let fmt = formatter_of_buffer buf in
- if debug then Printf.printf "open box ...\n%!";
+
+ if debug then
+ Printf.printf "pp_max_boxes before open_box = %d\n"
+ (pp_get_max_boxes fmt ());
+
pp_open_box fmt 0;
- if debug then Printf.printf "print string ...\n%!";
+
+ if debug then
+ Printf.printf "pp_max_boxes before open_box = %d\n"
+ (pp_get_max_boxes fmt ());
+
pp_print_string fmt "This is a string";
- if debug then Printf.printf "close box ...\n%!";
pp_close_box fmt ();
- if debug then Printf.printf "flush ...\n%!";
pp_print_flush fmt ();
- if debug then Printf.printf "get buffer contents ...\n%!";
let str = Buffer.contents buf in
Printf.printf "contents of buffer = %S\n%!" str
--- /dev/null
+(* Look for assembler errors like this:
+ * 'Warning: 9223372036854775807 shortened to 4294967295'
+ * Try to reproduce and fix.
+ *)
+
+open Printf
+
+let () =
+ let i = max_int in (* Different on 32 & 64 bit platforms.*)
+ printf "max_int = %d\n" i;
+ let i = min_int in
+ printf "min_int = %d\n" i;
+ let i64 = Int64.max_int in (* Same on all platforms. *)
+ printf "Int64.max_int = %Ld\n" i64;
+ let i32 = Int32.max_int in
+ printf "Int32.max_int = %ld\n" i32;
+
+ (* This is how the stdlib computes min_int:
+ * min_int = 1 lsl (if 1 lsl 31 = 0 (* ie. 32 bit *) then 30 else 62)
+ *)
+ printf "1 lsl 31 = %d\n" (1 lsl 31);
+ printf "1 lsl 30 = %d\n" (1 lsl 30);
+ printf "1 lsl 62 = %d\n" (1 lsl 62)