1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancments. ;;;;;
5 ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
6 ;;; All rights reserved ;;;;;
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9 ;;; Compilation environment for TRANSLATED MACSYMA code. ;;;
10 ;;; (c) Copyright 1980 Massachusetts Institute of Technology ;;;
11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15 ;;; this are COMPILE-TIME macros for TRANSLATE MACSYMA code.
17 (macsyma-module transq macro
)
19 (load-macsyma-macros transm
)
21 (defmacro def-mtrvar
(v a
&optional
(priority 1))
22 (declare (ignore priority
))
23 ;; ignored variable around for TRANSLATED files pre
24 ;; 3:03pm Thursday, 11 March 1982 -gjc
26 (declare-top (special ,v
))
28 (if (or (not (boundp ',v
))
29 ;; a SYMBOL SET to ITSELF is considered to be
30 ;; UNBOUND for our purposes in Macsyma.
34 (define-compiler-macro mfunction-call
(f &rest l
&aux l1
)
36 (cond ((or (fboundp f
)
37 (get f
'once-translated
)
40 (t `(lispm-mfunction-call-aux ',f
', l1
(list ,@ l1
) nil
))))
43 ;;; macros for compiled environments.
45 ;;; (FUNGEN&ENV-for-meval <eval vars list> <late eval vars list> . <EXP>)
46 ;;; will define a function globally with a unique name
47 ;;; (defun <name> <list of variables> <exp>). And return
48 ;;; `((<name>) ,@<eval>> . <late eval>). The resulting expression may
49 ;;; then be passed to a function which will bind variables from
50 ;;; the <late eval vars list> and possibly other variables free in
51 ;;; <exp> and then call MEVAL on the expression.
52 ;;; the expression was translated using TR-LAMBDA.
54 (defvar *infile-name-key
* '||
55 "This is a key gotten from the infile name, in the interpreter
56 other completely hackish things with FSUBRS will go on.")
58 (defun skip-declare-exprs (l)
60 ((not (and (consp (car l
))
61 (eq (caar l
) 'declare
)))
64 (defun vanilla-lambda (bvl body
)
66 (declare (special ,@bvl
))
67 ,@(skip-declare-exprs body
)))
69 (defun rest-arg-lambda (bvl body
)
70 (let ((req-args (butlast bvl
))
71 (rest-arg (car (last bvl
))))
72 `(lambda (,@req-args
&rest
,rest-arg
)
73 (declare (special ,@bvl
))
74 (push '(mlist) ,rest-arg
)
75 ,@(skip-declare-exprs body
))))
77 (defun lambda-with-free-vars (bvl fvl cfvl lambda-header body
)
78 (let* ((lfvl (set-difference fvl cfvl
))
79 (lexicals (mapcar (lambda (x) (gensym (symbol-name x
))) cfvl
))
80 (symevals (mapcar (lambda (x) `(maybe-msymeval ',x
)) lfvl
)))
81 `(let ,(mapcar #'list lexicals cfvl
)
82 ,(funcall lambda-header bvl
83 `((let (,@(mapcar #'list cfvl lexicals
)
84 ,@(mapcar #'list lfvl symevals
))
85 (declare (special ,@cfvl
,@lfvl
))
88 (defun make-tlambda (bvl fvl cfvl rest-p body
)
89 (let ((lambda-header (if rest-p
#'rest-arg-lambda
#'vanilla-lambda
)))
91 (funcall lambda-header bvl body
)
92 (lambda-with-free-vars bvl fvl cfvl lambda-header body
))))
94 ;;; Lambda expressions emitted by the translator.
96 ;; lambda([u,...],...) where any free unquoted variable in the body is
97 ;; either unbound or globally bound or locally bound in some
98 ;; non-enclosing block.
99 (defmacro m-tlambda
(bvl &rest body
)
100 (make-tlambda bvl
'() '() nil body
))
102 ;; lambda([u,...,[v]],...) with the same condition as above.
103 (defmacro m-tlambda
& (bvl &rest body
)
104 (make-tlambda bvl
'() '() t body
))
106 ;; lambda([u,...],...) with free unquoted variables in the body which
107 ;; have a local binding in some enclosing block, but no global one,
108 ;; i.e, the complement of the condition for m-tlambda above.
110 ;; fvl is a list of all free vars. cfvl is a list of the free vars
112 (defmacro m-tlambda
&env
((bvl fvl cfvl
) &rest body
)
113 (make-tlambda bvl fvl cfvl nil body
))
115 ;; lambda([u,...,[v]],...) with the same condition as above.
116 (defmacro m-tlambda
&env
& ((bvl fvl cfvl
) &rest body
)
117 (make-tlambda bvl fvl cfvl t body
))
119 ;; Problem: You can pass a lambda expression around in macsyma
120 ;; because macsyma "general-rep" has a CAR which is a list.
121 ;; Solution: Just as well anyway.
124 ;;the lexical scoping handles the environment in most cases
125 ;;and it is messy to queue things
127 ;;; this is the important case for numerical hackery.
130 ;;; This is not optimal code.
131 ;;; I.E. IT SUCKS ROCKS.
133 (defmacro set-vals-into-list
(argl var
)
135 (argl argl
(cdr argl
))
136 (l nil
`((setf (nth ,j
,var
) ,(car argl
)) ,@l
)))
137 ((null argl
) `(progn ,@l
))))