This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: module loading


   From: Aleksandar Bakic <bakicale@cps.msu.edu>
   Date: Thu, 16 Oct 1997 15:32:56 -0400 (EDT)
   Cc: bakicale@cps.msu.edu, guile@cygnus.com
   X-Mailer: ELM [version 2.4 PL25]
   Content-Type: text
   Sender: owner-guile@cygnus.com
   Precedence: bulk
   X-UIDL: 2c1eac17de5386d7f07da0a6f134ab52

   Not just all. It just seems natural to me have one module for both C
   and Scheme code that implement a logically same thing. I don't need to
   merge several C files or several Scheme files, but just one C file
   with one Scheme file that has "the same" module name. I will try your
   solution if what I would want is too much :)

   Thanks,
   Aleks

   > What you seem to want, is to have Guile find and merge *all* possible
   > sources into one module.  If there is both a shared library and a
   > Scheme source file that could provide the module, you want them to be
   > *both* activated and merged.  Right?
   > 

You can put both into one file.  Put Scheme code into a string and
call scm_ldstr().  Here is a code fragment:

			      -=-=-=-=-

void init_pci()
{
  init_iprocs(subr2s, tc7_subr_2);
  init_iprocs(subr3s, tc7_subr_3);
  make_subr(s_inpw, tc7_subr_1, l_inpw);
  make_subr(s_inp, tc7_subr_1, l_inp);
  make_subr("pci-bios-present", tc7_subr_0, pbp);
  make_subr(s_scm_address, tc7_lsubr, scm_address);
  add_feature("pci");
  scm_ldstr("\n\
(define pci-bios-present? pci-bios-present)\n\
(define (physical-base base-ptr valid-offset)\n\
  (- (physical-address base-ptr (quotient valid-offset 4)) valid-offset))\n\
");
}

			     -=-=-=-=-=-

File: scm.info,  Node: Callbacks,  Next: Type Conversions,  Prev: Calling Scheme From C,  Up: Operations

Callbacks
---------

SCM now has routines to make calling back to Scheme procedures easier.
The source code for these routines are found in `rope.c'.

 - Function: int scm_ldfile (char *FILE)
     Loads the Scheme source file FILE.  Returns 0 if successful, non-0
     if not.  This function is used to load SCM's initialization file
     `Init.scm'.

 - Function: int scm_ldprog (char *FILE)
     Loads the Scheme source file `(in-vicinity (program-vicinity)
     FILE)'.  Returns 0 if successful, non-0 if not.

     This function is useful for compiled code init_ functions to load
     non-compiled Scheme (source) files.  `program-vicinity' is the
     directory from which the calling code was loaded (*note Vicinity:
     (slib)Vicinity.).

 - Function: SCM scm_evstr (char *STR)
     Returns the result of reading an expression from STR and
     evaluating it.

 - Function: void scm_ldstr (char *STR)
     Reads and evaluates all the expressions from STR.

If you wish to catch errors during execution of Scheme code, then you
can use a wrapper like this for your Scheme procedures:

     (define (srv:protect proc)
       (lambda args
         (define result #f)                  ; put default value here
         (call-with-current-continuation
          (lambda (cont)
            (dynamic-wind (lambda () #t)
                          (lambda ()
                            (set! result (apply proc args))
                            (set! cont #f))
                          (lambda ()
                            (if cont (cont #f))))))
         result))

Calls to procedures so wrapped will return even if an error occurs.