manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

31.5.4 Safety

It is possible to generate safe or unsafe code. The safety’s scope is type, arity, version and range. Let’s see an example:

(define (foo f v indice)
   (car (f (vector-ref v indice))))

In safe mode, the result of the compilation will be:

(define (foo f v indice)
  (let ((pair 
        (if (and (procedure? f)
              ;; type check
              (= (procedure-arity f) 1))
              ;; arity check
           (if (vector? v)
              ;; type check
              (if (and (integer? k)
                    ;; type check
                    (>= k 0)
                    ;; range check
                    (< k (vector-length v)))
                    ;; range check
                (f (vector-ref v indice))
                (error ...))
              (error ...))
           (error ...))))
    (if (pair? pair)
       ;; type check
       (car pair)
       (error ...))))

It is possible to remove some or all safe checks. For example, here is the result of the compilation where safe check on types have been removed:

(define (foo f v indice)
  (let ((pair (if (= (procedure-arity f) 1)
             ;; arity check
             (if (and (>= k 0)
                   ;; range check
                   (< k (vector-length v)))
                   ;; range check
                (f (vector-ref v indice))
                (error ...))
             (error ...))))
     (car pair)))

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on October 23, 2011 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.