Discussion:
[Ecls-list] c:build-program and -eval
Gabriel Dos Reis
2007-03-10 09:02:15 UTC
Permalink
Hi,

I'm new to ECL, so my question may be an FAQ -- but I missed the
corresponding entry in the documentations. I apologize in advance.

I'm trying to test a Lisp system with ECL -- so far, I've been
able to use GCL, CLISP, and SBCL with success. For the testing, the
ability to invoke ECL in "batch" more with -eval is quite essential.

I tried to reproduce the examples

http://ecls.sourceforge.net/ecldev/Compiler-examples.html

using only the -eval option. So far, I can compile hello.lisp to
an object file using the command:

% ecl -eval '(progn (compile-file "hello.lisp" :system-p t) (quit))'
;;; Loading #P"/home/gdr/lib/ecl/cmp.fas"
;;; Loading #P"/home/gdr/lib/ecl/sysfun.lsp"
;;; Compiling hello.lisp.
;;; End of Pass 1.
;;; Calling the C compiler...
;;; Note: Invoking external command:
;;; gcc -D_GNU_SOURCE -g -O2 -fPIC -fstrict-aliasing -Dlinux -O "-I/home/gdr/lib/ecl/" -w -c "/home/gdr/tmp/hello.c" -o "/home/gdr/tmp/hello.o"

;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3
;;; Finished compiling hello.lisp.


However, the "c:build-program" step invariably fails, with error to
the effect that ECL cannot find the external symbol build-program from
package c.

% ecl -eval '(progn (c:build-progam "hello.lisp" :lisp-file (quote ("hello.o"))) (quit))'
An error occurred during initialization:
Cannot find the external symbol BUILD-PROGAM in #<"C" package>..


Notice that the same error occurs when I start eval afresh in
interactive mode and tries to complete the c:build-program step.
Any idea how to get that part work?

Thanks in advance,

-- Gaby
Juan Jose Garcia-Ripoll
2007-03-10 09:11:57 UTC
Permalink
Hi Gabriel,

you are missing an important step:
(require 'cmp)

The compiler is not loaded by default, to save memory. Your example
then should probably read

% ecl -eval '(progn (require 'cmp) (c::build-progam "hello.lisp"
:lisp-file (quote ("hello.o"))) (quit))'
--
Dpto. de Fisica Teorica I, Fac. de CC Fisicas, Universidad Complutense,
Ciudad Universitaria s/n Madrid 28040 (Spain)
http://juanjose.garciaripoll.googlepages.com
Gabriel Dos Reis
2007-03-10 09:45:33 UTC
Permalink
"Juan Jose Garcia-Ripoll" <***@users.sourceforge.net> writes:

| Hi Gabriel,
|
| you are missing an important step:
| (require 'cmp)

Dear Juan,

That was fast! Many thanks.

| The compiler is not loaded by default, to save memory. Your example
| then should probably read
|
| % ecl -eval '(progn (require 'cmp) (c::build-progam "hello.lisp"
| :lisp-file (quote ("hello.o"))) (quit))'

Requiring "cmp" indeed does the trick. However, I suspect there might
be a bug: The form:

% ecl -eval '(progn (require (quote cmp)) (c:build-program "hello" :lisp-files (quote ("hello.o"))) (quit))'

produces the same error as before. However, if I split the -eval
argument into two chunks, first requiring "cmp", then building the
program, it appears to work:

% ecl -eval '(require (quote cmp))' -eval '(progn (c:build-program "hello" :lisp-files (quote ("hello.o"))) (quit))'

Thanks!

-- Gaby
Juan Jose Garcia-Ripoll
2007-03-10 10:12:33 UTC
Permalink
Post by Gabriel Dos Reis
Requiring "cmp" indeed does the trick. However, I suspect there might
% ecl -eval '(progn (require (quote cmp)) (c:build-program "hello" :lisp-files (quote ("hello.o"))) (quit))'
produces the same error as before.
No, that is not an error. Look at the symbol "c:build-program". You
are asking for an exported symbol, but at the moment the reader sees
your form the C package is empty because the form (require 'cmp) has
not yet taken effect. Hence, the reader finds no external symbol.

If you rather use c::build-program the reader will create an internal
symbol which will get replaced when the compiler is loaded.

If you split the statement into two -eval forms, then first the
compiler is loaded and then the second string is parsed into a lisp
form and evaluated.

Juanjo
--
Dpto. de Fisica Teorica I, Fac. de CC Fisicas, Universidad Complutense,
Ciudad Universitaria s/n Madrid 28040 (Spain)
http://juanjose.garciaripoll.googlepages.com
Gabriel Dos Reis
2007-03-10 10:15:42 UTC
Permalink
On Sat, 10 Mar 2007, Juan Jose Garcia-Ripoll wrote:

| 10 Mar 2007 03:45:33 -0600, Gabriel Dos Reis <***@cs.tamu.edu>:
| > Requiring "cmp" indeed does the trick. However, I suspect there might
| > be a bug: The form:
| >
| > % ecl -eval '(progn (require (quote cmp)) (c:build-program "hello" :lisp-files (quote ("hello.o"))) (quit))'
| >
| > produces the same error as before.
|
| No, that is not an error. Look at the symbol "c:build-program". You
| are asking for an exported symbol, but at the moment the reader sees
| your form the C package is empty because the form (require 'cmp) has
| not yet taken effect. Hence, the reader finds no external symbol.

Aha!

| If you rather use c::build-program the reader will create an internal
| symbol which will get replaced when the compiler is loaded.
|
| If you split the statement into two -eval forms, then first the
| compiler is loaded and then the second string is parsed into a lisp
| form and evaluated.

OK, thanks for the explanation. Faré sent me similar explanation.

Thanks!

-- Gaby

Loading...