From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA12041 for caml-redistribution; Fri, 10 Dec 1999 14:17:13 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA13620 for ; Fri, 10 Dec 1999 09:21:20 +0100 (MET) Received: from isil.maya.com (HOPKINS.PC.CS.CMU.EDU [128.2.215.35]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id JAA24255 for ; Fri, 10 Dec 1999 09:21:16 +0100 (MET) Received: (from prevost@localhost) by isil.maya.com (8.9.3/8.9.3) id DAA14433; Fri, 10 Dec 1999 03:12:14 -0500 X-Authentication-Warning: isil.maya.com: prevost set sender to prevost@maya.com using -f Sender: weis To: caml-list@inria.fr Subject: Internals details for cmmgen.ml From: John Prevost Date: 10 Dec 1999 03:12:14 -0500 Message-ID: <87emcv5i5d.fsf@isil.maya.com> User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Recently I posted about my work to add support for fast byte access to regions of memory outside the O'Caml heap. Since Francois Rouaix helfully pointed me at fcntl for being sure of the access rights on file descriptors, I'm continuing to polish things up. My main focus has been on adding small bits of code to asmcomp/cmmgen.ml for the new functionality. Two of the new primitives (Pregionrefs and Pregionsets) need to check the protection bits recorded for the region before trying to access it, and somehow raise an exception if the access check fails. I'm currently using the following kludge to make bad region access checks fail: let region_checkaccess exp = function | Reg_Read -> Cifthenelse( Cop(Cand, [region_prot exp; Cconst_int 1]), Cconst_pointer 1, Cop(Ccheckbound, [Cconst_int 0; Cconst_int 0])) | Reg_Write -> Cifthenelse( Cop(Cand, [region_prot exp; Cconst_int 2]), Cconst_pointer 1, Cop(Ccheckbound, [Cconst_int 0; Cconst_int 0])) (* XXX Bounds check on 0 is a kludge to force exception *) (Please pardon my code--I may not know enough about C-- to produce the best possible output, even without trying to finagle this access check.) Is there a better way for me to cause an exception to be thrown at this point? Do I need to fall back to a Cextcall to ask someone to throw an exception for me? Or could (and should) I actually use Craise with arcane knowledge that a certain exception maps to a certain integer value? John P.S. Kudos to everyone who's involved with the O'Caml compiler. Now that I'm getting into the internals a bit, I'm enjoying myself immensely. I'm convinced I could never deal with this style of hackery in the Perl source. Not only is the code of the various parts of the compiler fairly easy to follow, but static typing has saved me from burning myself several times already while modifying cmmgen.ml and the associated type definitions. Again, thanks!