caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] native-code and byte-code compiler differences
@ 2002-03-29 21:00 Attila Kondacs
  2002-03-31 18:59 ` Michel Quercia
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Attila Kondacs @ 2002-03-29 21:00 UTC (permalink / raw)
  To: caml-list

the following is a code segment that opens a window and if 'q' is
pressed  on the keyboard it closes it. It works with the byte code
compiler fine but does not react to pressed keys when compiled with the
native code compiler (using ocaml 3.04 for debian - from the unstable
distribution).

According to the ocaml manual this may happen if there is devision by 0
caught as an exception, or stack overflow, or if signal handling is
involved. The first two cases are out of question here, and as far as I
know reading mouse and keyboard events do not involve signals. So what's
wrong here? and how can it be put right?

here is the code:


open Graphics;;
let rec find_char_action_pair = fun pairlist (a:char) ->
  match pairlist with
    | hd::tl -> if (fst hd) = a then (snd hd) else find_char_action_pair
tl a
    | [] -> (fun () -> ());;
	
let map_keyboard = fun  ?(mouse_action = (fun () -> ())) charactionlist ->
  let st = ref true in
    while !st = true do
      if mouse_action != (fun () -> ())
      then (if (try button_down() with Graphic_failure _
	      -> (open_graph ""; button_down ()))
	    then mouse_action ());
      if key_pressed()
      then (match read_key() with
	      | 'q' -> 
		  begin
		    ((find_char_action_pair charactionlist 'q' )());
		    st := false 
		  end
	      | a -> ((find_char_action_pair charactionlist a )()));
    done;;

open_graph "";;

map_keyboard
  [ ' ' , (fun () -> print_string "\n yes, it works!!")];;

close_graph();;	

 
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-04-02 20:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-29 21:00 [Caml-list] native-code and byte-code compiler differences Attila Kondacs
2002-03-31 18:59 ` Michel Quercia
2002-03-31 19:09 ` Sylvain LE GALL
2002-03-31 19:32 ` Tim Freeman
2002-04-02 17:14 ` Andrej Bauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).