[Ecls-list] UPDATE: Embedding ECL - how?

Dr. Edmund Weitz edi at agharta.de
Tue Jan 22 15:06:25 UTC 2002


Juan Jose Garcia-Ripoll <Juan.Ripoll at mpq.mpg.de> writes:

> There is a hidden feature in the compiler, which I added in order to
> keep compiled code smaller. It is a special proclamation
> 
> (in-package "MYP")
> (proclaim '(si::c-export-fname foo))
> (defun foo (x)
> ...)
> 
> By compiling the code above you get a publicly defined mypLfoo() C
> function which you can call. This is undocumented I cannot assure
> that it will stay like that because I do not like it that much.

That would be the feature I was looking for! Why do consider removing
it?

However, it didn't work for me:

Here's my file "fac.lisp":
 
  (in-package "FACTEST")
   
  (defun fac (n)
    (if (= n 0)
        1
        (* n (fac (1- n)))))
  
  (proclaim '(si::c-export-fname prfac))
  
  (defun prfac ()
    (print (fac 100))
    (values))

Now, in a freshly started ECL image I did:
  
  > (make-package "FACTEST" :use '("COMMON-LISP"))
  #<"FACTEST" package>
  > (compile-file "fac.lisp" :system-p t)
  ;;; Compiling fac.lisp.
  ;;; Compiling (DEFUN FAC ...).
  ;;; Compiling (DEFUN PRFAC ...).
  ;;; End of Pass 1.  
  ;;; Emitting code for FAC.
  ;;; Emitting code for PRFAC.
  ;;; Calling the C compiler... 
  "gcc -g -O2 -Dlinux  -O -I/usr/local/lib/ecl//h -w -c fac.c -o fac.o" 
  ;;; OPTIMIZE levels: Safety=0 (No runtime error checking), Space=0, Speed=3
  ;;; Finished compiling fac.lisp.
  #P"fac.o"
  
but...
  
  edi at bird:~> nm fac.o
  00000000 b Cblock
           U Cnil_body
  000000b0 t L1
  00000120 t L2
  00000156 t Letext
           U MF
           U NValues
  00000004 b VV
           U clLfuncall
  00000000 r compiler_data_text
  00000000 T init_FAC
           U number_compare
           U number_times
           U one_minus
           U print
           U siLselect_package
  
...so it's still L1, L2 there.

(I get the same behaviour if I work in the default package instead of
my "FACTEST" package.)

Here's the behaviour that I get if I start with LOAD. Looks like
SI::MANGLE-NAME doesn't mangle the package name. The questions remains
why COMPILE-FILE tried to create the C function 'COMMON-LISPLprfac'
while it should have created 'FACTESTLprfac' instead (and why I have
to call LOAD first to 'invoke' SI::C-EXPORT-NAME).
  
  > (make-package "FACTEST" :use '("COMMON-LISP"))
  #<"FACTEST" package>
  > (load "fac.lisp")
  ;;; Loading /home/edi/fac.lisp
  #P"/home/edi/fac.lisp"
  > (compile-file "fac.lisp" :system-p t)
  ;;; Compiling fac.lisp.
  ;;; Compiling (DEFUN FAC ...).
  ;;; Compiling (DEFUN PRFAC ...).
  ;;; End of Pass 1.  
  ;;; Emitting code for FAC.
  ;;; Emitting code for PRFAC.
  ;;; Calling the C compiler... 
  "gcc -g -O2 -Dlinux  -O -I/usr/local/lib/ecl//h -w -c fac.c -o fac.o"In file included from fac.c:3:
  fac.h:9: parse error before `-'
  In file included from fac.c:3:
  fac.h: In function `init_FAC':
  fac.h:44: `COMMON' undeclared (first use in this function)
  fac.h:44: (Each undeclared identifier is reported only once
  fac.h:44: for each function it appears in.)
  fac.h:44: `LISPLprfac' undeclared (first use in this function)
  fac.c: At top level:
  fac.c:19: parse error before `-'
  fac.c:22: parse error before `:'
  fac.c:24: parse error before `('
  fac.c:25: conflicting types for `value0'
  fac.c:21: previous declaration of `value0'
  fac.c:26: parse error before `return'
   
  (SYSTEM "gcc -g -O2 -Dlinux  -O -I/usr/local/lib/ecl//h -w -c fac.c -o fac.o") returned non-zero value 1
  Broken at COMPILE-FILE.
 
Thanks again,
Edi.




More information about the ecl-devel mailing list