> With DECLARE_TRANSLATED(FOO) the translator knows (even without having
> an explicit definition for FOO) that $FOO can be called as lisp
> function and that MFUNCTION-CALL is not needed. But I think that this
> doesn't work currently
although it can be easily fixed.
The current definition of MFUNCTION-CALL (by DEFMACRO in fcall.lisp)
does not honour DECLARE_TRANSLATED, but transq.lisp has a definition
by DEFOPT which does. It is not used because DEFOPT itself has only a
bogus definition. I propose the following trivial fix (note that at
the beginning of defopt.lisp somebody put a comment explaining the
purpose of DEFOPT)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Index: defopt.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/defopt.lisp,v
retrieving revision 1.1.1.1
diff -C2 -r1.1.1.1 defopt.lisp
*** defopt.lisp 8 May 2000 06:09:41 -0000 1.1.1.1
--- defopt.lisp 30 Mar 2003 23:42:53 -0000
***************
*** 62,68 ****
! #-lispm
! (defmacro defopt (name &rest other) name other nil)
!
#+(and lispm CL)
--- 62,68 ----
! #+(and cl (not lispm))
! (defmacro defopt (&rest other)
! `(define-compiler-macro ,.other))
#+(and lispm CL)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(For GCL as of v. 2.5.2 I am assuming that SI::DEFINE-COMPILER-MACRO
has been made accessible.)
So MFUNCTION-CALL will remain in the *.LISP file and the compiler may
choose to eliminate it (or rather some function call to which the
macro would expand, see the example below). As an illustration of
this assume the file dcm.mac consists of
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
declare_translated(foo);
bar():=true;
dcm_test():=
(foo(),
bar(),
quux())$
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The relevant part of dcm.LISP will look like
(DEFMTRFUN (|$dcm_test| $ANY MDEFINE NIL NIL) NIL NIL
(PROGN (SIMPLIFY (MFUNCTION-CALL |$foo|))
(MFUNCTION-CALL |$bar|)
(SIMPLIFY (MFUNCTION-CALL |$quux|))))
and Clisp's byte-code disassembly gives
Disassembly of function |$dcm_test|
(CONST 0) = |$foo|
(CONST 1) = SIMPLIFYA
(CONST 2) = |$bar|
(CONST 3) = |$quux|
(CONST 4) = LISPM-MFUNCTION-CALL-AUX
0 required arguments
0 optional arguments
No rest parameter
No keyword parameters
11 byte-code instructions:
0 (CALL0 0) ; |$foo|
2 (PUSH)
3 (NIL&PUSH)
4 (CALL2 1) ; SIMPLIFYA
6 (CALL0 2) ; |$bar|
8 (CONST&PUSH 3) ; |$quux|
9 (PUSH-NIL 3)
11 (CALL&PUSH 4 4) ; LISPM-MFUNCTION-CALL-AUX
14 (NIL&PUSH)
15 (CALL2 1) ; SIMPLIFYA
17 (SKIP&RET 1)
#<COMPILED-CLOSURE $dcm_test>
Note that $foo and $bar are called directly, while $quux is called via
LISPM-MFUNCTION-CALL-AUX (to which MFUNCTION-CALL expands in this
case).
Apparently, the various DEFOPTs in transq.lisp don't mess up anything,
except that the way too radical optimisation of TRD-MSYMEVAL has to be
commented out (or rewritten).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Index: transq.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/transq.lisp,v
retrieving revision 1.1.1.1
diff -C2 -r1.1.1.1 transq.lisp
*** transq.lisp 8 May 2000 06:09:41 -0000 1.1.1.1
--- transq.lisp 31 Mar 2003 02:44:14 -0000
***************
*** 64,69 ****
(setq ,v ,a))))
! (DEFOPT TRD-MSYMEVAL (VAR &rest ignore)
! VAR)
(DEFVAR *MAX-EXPT$-EXPAND* 7)
--- 64,70 ----
(setq ,v ,a))))
! ;; To do.
! ;; (DEFOPT TRD-MSYMEVAL (VAR &rest ignore)
! ;; VAR)
(DEFVAR *MAX-EXPT$-EXPAND* 7)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At least, with DECLARE_TRANSLATED in place, ode2 can be compiled,
maxima passes the test suite, other files like facexp can be compiled
and (their demos) continue to work.
Finally, IMO the translator should write its own suggestion for the
DECLARE_TRANSLATED form to the UNLISP file and not to the LISP file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Index: transs.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/transs.lisp,v
retrieving revision 1.5
diff -C2 -r1.5 transs.lisp
*** transs.lisp 5 Mar 2003 01:36:26 -0000 1.5
--- transs.lisp 31 Mar 2003 02:44:34 -0000
***************
*** 388,397 ****
collecting v into warns
finally (cond (warns
! (format stream "~2%;;The following functions declaration should ~
! ;;go at the front of your macsyma file ~
! ~%;;" )
(mgrind `(($eval_when) $translate (($declare_translated) ,@ warns))
stream)
! (format t "~%See the extra declarations at the end of the translated file. They ~
should be included in you macsyma file, and you should retranslate.")))))
--- 388,395 ----
collecting v into warns
finally (cond (warns
! (format stream "~2%;; The following functions declaration should~%;; go at the front of your macsyma file~%")
(mgrind `(($eval_when) $translate (($declare_translated) ,@ warns))
stream)
! (format t "~%See the extra declarations at the end of the UNLISP file. They ~
should be included in you macsyma file, and you should retranslate.")))))
***************
*** 434,438 ****
(pathname in-stream))
(CALL-BATCH1 in-stream out-stream)
! (insert-necessary-function-declares out-stream)
;; BATCH1 calls TRANSLATE-MACEXPR-toplevel on each expression read.
(cons '(mlist)
--- 432,436 ----
(pathname in-stream))
(CALL-BATCH1 in-stream out-stream)
! (insert-necessary-function-declares warn-stream)
;; BATCH1 calls TRANSLATE-MACEXPR-toplevel on each expression read.
(cons '(mlist)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I think the four patches in this thread should eliminate the
translation troubles you reported.
Wolfgang