diff --git a/books/bookvol9.pamphlet b/books/bookvol9.pamphlet index bf39800..f02a36f 100644 --- a/books/bookvol9.pamphlet +++ b/books/bookvol9.pamphlet @@ -4266,231 +4266,6 @@ leave it alone." \end{chunk} -\defvar{current-fragment} -A string containing remaining chars from readline; needed because -Symbolics read-line returns embedded newlines in a c-m-Y. -\begin{chunk}{initvars} -(defvar current-fragment nil) - -\end{chunk} - -\defun{read-a-line}{read-a-line} -\calls{read-a-line}{subseq} -\calls{read-a-line}{Line-New-Line} -\calls{read-a-line}{read-a-line} -\uses{read-a-line}{*eof*} -\uses{read-a-line}{File-Closed} -\begin{chunk}{defun read-a-line} -(defun read-a-line (&optional (stream t)) - (let (cp) - (declare (special *eof* File-Closed)) - (if (and Current-Fragment (> (length Current-Fragment) 0)) - (let ((line (with-input-from-string - (s Current-Fragment :index cp :start 0) - (read-line s nil nil)))) - (setq Current-Fragment (subseq Current-Fragment cp)) - line) - (prog nil - (when (stream-eof in-stream) - (setq File-Closed t) - (setq *eof* t) - (Line-New-Line (make-string 0) Current-Line) - (return nil)) - (when (setq Current-Fragment (read-line stream)) - (return (read-a-line stream))))))) - -\end{chunk} - -\section{Line Handling} - -\subsection{Line Buffer} -The philosophy of lines is that -\begin{itemize} -\item NEXT LINE will always return a non-blank line or fail. -\item Every line is terminated by a blank character. -\end{itemize} -Hence there is always a current character, because there is never a -non-blank line, and there is always a separator character between tokens -on separate lines. Also, when a line is read, the character pointer is -always positioned ON the first character. -\defstruct{line} -\begin{chunk}{initvars} -(defstruct line "Line of input file to parse." - (buffer (make-string 0) :type string) - (current-char #\Return :type character) - (current-index 1 :type fixnum) - (last-index 0 :type fixnum) - (number 0 :type fixnum)) - -\end{chunk} - -\defvar{current-line} -The current input line. -\begin{chunk}{initvars} -(defvar current-line (make-line)) - -\end{chunk} - - -\defmacro{line-clear} -\usesstruct{line-clear}{line} -\begin{chunk}{defmacro line-clear} -(defmacro line-clear (line) - `(let ((l ,line)) - (setf (line-buffer l) (make-string 0)) - (setf (line-current-char l) #\return) - (setf (line-current-index l) 1) - (setf (line-last-index l) 0) - (setf (line-number l) 0))) - -\end{chunk} - -\defun{line-print}{line-print} -\usesstruct{line-print}{line} -\refsdollar{line-print}{out-stream} -\begin{chunk}{defun line-print} -(defun line-print (line) - (declare (special out-stream)) - (format out-stream "~&~5D> ~A~%" (Line-Number line) (Line-Buffer Line)) - (format out-stream "~v@T^~%" (+ 7 (Line-Current-Index line)))) - -\end{chunk} - -\defun{line-at-end-p}{line-at-end-p} -\usesstruct{line-at-end-p}{line} -\begin{chunk}{defun line-at-end-p} -(defun line-at-end-p (line) - "Tests if line is empty or positioned past the last character." - (>= (line-current-index line) (line-last-index line))) - -\end{chunk} - -\defun{line-past-end-p}{line-past-end-p} -\usesstruct{line-past-end-p}{line} -\begin{chunk}{defun line-past-end-p} -(defun line-past-end-p (line) - "Tests if line is empty or positioned past the last character." - (> (line-current-index line) (line-last-index line))) - -\end{chunk} - -\defun{line-next-char}{line-next-char} -\usesstruct{line-next-char}{line} -\begin{chunk}{defun line-next-char} -(defun line-next-char (line) - (elt (line-buffer line) (1+ (line-current-index line)))) - -\end{chunk} - -\defun{line-advance-char}{line-advance-char} -\usesstruct{line-advance-char}{line} -\begin{chunk}{defun line-advance-char} -(defun line-advance-char (line) - (setf (line-current-char line) - (elt (line-buffer line) (incf (line-current-index line))))) - -\end{chunk} - -\defun{line-current-segment}{line-current-segment} -\usesstruct{line-print}{line} -\begin{chunk}{defun line-current-segment} -(defun line-current-segment (line) - "Buffer from current index to last index." - (if (line-at-end-p line) - (make-string 0) - (subseq (line-buffer line) - (line-current-index line) - (line-last-index line)))) - -\end{chunk} - -\defun{line-new-line}{line-new-line} -\usesstruct{line-new-line}{line} -\begin{chunk}{defun line-new-line} -(defun line-new-line (string line &optional (linenum nil)) - "Sets string to be the next line stored in line." - (setf (line-last-index line) (1- (length string))) - (setf (line-current-index line) 0) - (setf (line-current-char line) - (or (and (> (length string) 0) (elt string 0)) #\Return)) - (setf (line-buffer line) string) - (setf (line-number line) (or linenum (1+ (line-number line))))) - -\end{chunk} - -\defun{next-line}{next-line} -\refsdollar{next-line}{in-stream} -\begin{chunk}{defun next-line} -(defun next-line (&optional (in-stream t)) - (declare (special in-stream)) - (funcall Line-Handler in-stream)) - -\end{chunk} - -\defun{Advance-Char}{Advance-Char} -\calls{Advance-Char}{Line-At-End-P} -\calls{Advance-Char}{Line-Advance-Char} -\calls{Advance-Char}{next-line} -\calls{Advance-Char}{current-char} -\refsdollar{Advance-Char}{in-stream} -\usesstruct{Advance-Char}{line} -\begin{chunk}{defun Advance-Char} -(defun Advance-Char () - "Advances IN-STREAM, invoking Next Line if necessary." - (declare (special in-stream)) - (loop - (cond - ((not (Line-At-End-P Current-Line)) - (return (Line-Advance-Char Current-Line))) - ((next-line in-stream) - (return (current-char))) - ((return nil))))) - -\end{chunk} - -\defun{storeblanks}{storeblanks} -\begin{chunk}{defun storeblanks} -(defun storeblanks (line n) - (do ((i 0 (1+ i))) - ((= i n) line) - (setf (char line i) #\ ))) - -\end{chunk} - -\defun{initial-substring}{initial-substring} -\calls{initial-substring}{mismatch} -\begin{chunk}{defun initial-substring} -(defun initial-substring (pattern line) - (let ((ind (mismatch pattern line))) - (or (null ind) (eql ind (size pattern))))) - -\end{chunk} - -\defun{get-a-line}{get-a-line} -\calls{get-a-line}{is-console} -\seebook{get-a-line}{mkprompt}{5} -\calls{get-a-line}{read-a-line} -\calls{get-a-line}{make-string-adjustable} -\begin{chunk}{defun get-a-line} -(defun get-a-line (stream) - (when (is-console stream) (princ (mkprompt))) - (let ((ll (read-a-line stream))) - (if (stringp ll) - (make-string-adjustable ll) - ll))) - -\end{chunk} - -\defun{make-string-adjustable}{make-string-adjustable} -\begin{chunk}{defun make-string-adjustable} -(defun make-string-adjustable (s) - (if (adjustable-array-p s) - s - (make-array (array-dimensions s) :element-type 'string-char - :adjustable t :initial-contents s))) - -\end{chunk} - \subsection{Parsing stack} \defstruct{stack} \begin{chunk}{initvars} @@ -6417,7 +6192,7 @@ $\rightarrow$ (|get| op '|isCategory| |$CategoryFrame|)) (cons op (loop for x in argl - collect (|quotifyCategoryArgument| x)))) + collect (mkq x)))) (t (setq tmp1 (|compOrCroak| c |$EmptyMode| |$e|)) (setq x (car tmp1)) @@ -6596,6 +6371,317 @@ $\rightarrow$ \end{chunk} +\defun{compile}{compile} +\calls{compile}{member} +\calls{compile}{getmode} +\calls{compile}{pairp} +\calls{compile}{qcar} +\calls{compile}{qcdr} +\calls{compile}{get} +\calls{compile}{modeEqual} +\calls{compile}{userError} +\calls{compile}{encodeItem} +\calls{compile}{strconc} +\calls{compile}{encodeItem} +\calls{compile}{isPackageFunction} +\calls{compile}{nequal} +\calls{compile}{kar} +\calls{compile}{encodeFunctionName} +\calls{compile}{splitEncodedFunctionName} +\calls{compile}{sayBrightly} +\calls{compile}{optimizeFunctionDef} +\calls{compile}{putInLocalDomainReferences} +\calls{compile}{constructMacro} +\calls{compile}{spadCompileOrSetq} +\calls{compile}{elapsedTime} +\calls{compile}{addStats} +\calls{compile}{printStats} +\refsdollar{compile}{functionStats} +\refsdollar{compile}{macroIfTrue} +\refsdollar{compile}{doNotCompileJustPrint} +\refsdollar{compile}{insideCapsuleFunctionIfTrue} +\refsdollar{compile}{saveableItems} +\refsdollar{compile}{lisplibItemsAlreadyThere} +\refsdollar{compile}{splitUpItemsAlreadyThere} +\refsdollar{compile}{lisplib} +\refsdollar{compile}{compileOnlyCertainItems} +\refsdollar{compile}{functorForm} +\refsdollar{compile}{signatureOfForm} +\refsdollar{compile}{suffix} +\refsdollar{compile}{prefix} +\refsdollar{compile}{signatureOfForm} +\refsdollar{compile}{e} +\defsdollar{compile}{functionStats} +\defsdollar{compile}{savableItems} +\defsdollar{compile}{suffix} +\begin{chunk}{defun compile} +(defun |compile| (u) + (labels ( + (isLocalFunction (op) + (let (tmp1) + (declare (special |$e| |$formalArgList|)) + (and (null (|member| op |$formalArgList|)) + (progn + (setq tmp1 (|getmode| op |$e|)) + (and (pairp tmp1) (eq (qcar tmp1) '|Mapping|))))))) + (let (op lamExpr DC sig sel opexport opmodes opp parts s tt unew + optimizedBody stuffToCompile result functionStats) + (declare (special |$functionStats| |$macroIfTrue| |$doNotCompileJustPrint| + |$insideCapsuleFunctionIfTrue| |$saveableItems| |$e| + |$lisplibItemsAlreadyThere| |$splitUpItemsAlreadyThere| + |$compileOnlyCertainItems| $LISPLIB |$suffix| + |$signatureOfForm| |$functorForm| |$prefix| + |$savableItems|)) + (setq op (first u)) + (setq lamExpr (second u)) + (when |$suffix| + (setq |$suffix| (1+ |$suffix|)) + (setq opp + (progn + (setq opexport nil) + (setq opmodes + (loop for item in (|get| op '|modemap| |$e|) + do + (setq dc (caar item)) + (setq sig (cdar item)) + (setq sel (cadadr item)) + when (and (eq dc '$) + (setq opexport t) + (let ((result t)) + (loop for x in sig for y in |$signatureOfForm| + do (setq result (|modeEqual| x y))) + result)) + collect sel)) + (cond + ((isLocalFunction op) + (when opexport + (|userError| (list '|%b| op '|%d| " is local and exported"))) + (intern (strconc (|encodeItem| |$prefix|) ";" (|encodeItem| op)))) + ((and (|isPackageFunction|) + (nequal (kar |$functorForm|) '|CategoryDefaults|)) + (when (null opmodes) (|userError| (list "no modemap for " op))) + (cond + ((and (pairp opmodes) (eq (qcdr opmodes) nil) (pairp (qcar opmodes)) + (eq (qcar (qcar opmodes)) 'pac) (pairp (qcdr (qcar opmodes))) + (pairp (qcdr (qcdr (qcar opmodes)))) + (eq (qcdr (qcdr (qcdr (qcar opmodes)))) nil)) + (qcar (qcdr (qcdr (qcar opmodes))))) + (t + (|encodeFunctionName| op |$functorForm| |$signatureOfForm| + '|;| |$suffix|)))) + (t + (|encodeFunctionName| op |$functorForm| |$signatureOfForm| + '|;| |$suffix|))))) + (setq u (list opp lamExpr))) + (when (and $lisplib |$compileOnlyCertainItems|) + (setq parts (|splitEncodedFunctionName| (elt u 0) '|;|)) + (cond + ((eq parts '|inner|) + (setq |$savableItems| (cons (elt u 0) |$savableItems|))) + (t + (setq unew nil) + (loop for item in |$splitUpItemsAlreadyThere| + do + (setq s (first item)) + (setq tt (second item)) + (when + (and (equal (elt parts 0) (elt s 0)) + (equal (elt parts 1) (elt s 1)) + (equal (elt parts 2) (elt s 2))) + (setq unew tt))) + (cond + ((null unew) + (|sayBrightly| (list " Error: Item did not previously exist")) + (|sayBrightly| (cons " Item not saved: " (|bright| (elt u 0)))) + (|sayBrightly| + (list " What's there is: " |$lisplibItemsAlreadyThere|)) + nil) + (t + (|sayBrightly| (list " Renaming " (elt u 0) " as " unew)) + (setq u (cons unew (cdr u))) + (setq |$savableItems| (cons unew |$saveableItems|))))))) + (setq optimizedBody (|optimizeFunctionDef| u)) + (setq stuffToCompile + (if |$insideCapsuleFunctionIfTrue| + (|putInLocalDomainReferences| optimizedBody) + optimizedBody)) + (cond + ((eq |$doNotCompileJustPrint| t) + (prettyprint stuffToCompile) + opp) + (|$macroIfTrue| (|constructMacro| stuffToCompile)) + (t + (setq result (|spadCompileOrSetq| stuffToCompile)) + (setq functionStats (list 0 (|elapsedTime|))) + (setq |$functionStats| (|addStats| |$functionStats| functionStats)) + (|printStats| functionStats) + result))))) + +\end{chunk} + +\defun{constructMacro}{constructMacro} +constructMacro (form is [nam,[lam,vl,body]]) +\calls{constructMacro}{stackSemanticError} +\calls{constructMacro}{identp} +\begin{chunk}{defun constructMacro} +(defun |constructMacro| (form) + (let (vl body) + (setq vl (cadadr form)) + (setq body (car (cddadr form))) + (cond + ((null (let ((result t)) + (loop for x in vl + do (setq result (and result (atom x)))) + result)) + (|stackSemanticError| (list '|illegal parameters for macro: | vl) nil)) + (t + (list 'xlam (loop for x in vl when (identp x) collect x) body))))) + +\end{chunk} + +\defun{spadCompileOrSetq}{spadCompileOrSetq} +\calls{spadCompileOrSetq}{pairp} +\calls{spadCompileOrSetq}{qcar} +\calls{spadCompileOrSetq}{qcdr} +\calls{spadCompileOrSetq}{contained} +\calls{spadCompileOrSetq}{sayBrightly} +\calls{spadCompileOrSetq}{bright} +\calls{spadCompileOrSetq}{LAM,EVALANDFILEACTQ} +\calls{spadCompileOrSetq}{mkq} +\calls{spadCompileOrSetq}{comp} +\calls{spadCompileOrSetq}{compileConstructor} +\refsdollar{spadCompileOrSetq}{insideCapsuleFunctionIfTrue} +\begin{chunk}{defun spadCompileOrSetq} +(defun |spadCompileOrSetq| (form) + (let (nam lam vl body namp tmp1 e vlp macform) + (declare (special |$insideCapsuleFunctionIfTrue|)) + (setq nam (car form)) + (setq lam (caadr form)) + (setq vl (cadadr form)) + (setq body (car (cddadr form))) + (cond + ((contained (intern " " "BOOT") body) + (|sayBrightly| (cons " " (append (|bright| nam) (list " not compiled"))))) + (t + (cond + ((and (pairp vl) (progn (setq tmp1 (reverse vl)) t) + (pairp tmp1) + (progn + (setq e (qcar tmp1)) + (setq vlp (qcdr tmp1)) + t) + (progn (setq vlp (nreverse vlp)) t) + (pairp body) + (progn (setq namp (qcar body)) t) + (equal (qcdr body) vlp)) + (|LAM,EVALANDFILEACTQ| + (list 'put (mkq nam) (mkq '|SPADreplace|) (mkq namp))) + (|sayBrightly| + (cons " " (append (|bright| nam) + (cons "is replaced by" (|bright| namp)))))) + ((and (or (atom body) + (let ((result t)) + (loop for x in body + do (setq result (and result (atom x)))) + result)) + (pairp vl) + (progn (setq tmp1 (reverse vl)) t) + (pairp tmp1) + (progn + (setq e (qcar tmp1)) + (setq vlp (qcdr tmp1)) + t) + (progn (setq vlp (nreverse vlp)) t) + (null (contained e body))) + (setq macform (list 'xlam vlp body)) + (|LAM,EVALANDFILEACTQ| + (list 'put (mkq nam) (mkq '|SPADreplace|) (mkq macform))) + (|sayBrightly| (cons " " (append (|bright| nam) + (cons "is replaced by" (|bright| body)))))) + (t nil)) + (if |$insideCapsuleFunctionIfTrue| + (car (comp (list form))) + (|compileConstructor| form)))))) + +\end{chunk} + +\defun{compileConstructor}{compileConstructor} +\calls{compileConstructor}{compileConstructor1} +\calls{compileConstructor}{clearClams} +\begin{chunk}{defun compileConstructor} +(defun |compileConstructor| (form) + (let (u) + (setq u (|compileConstructor1| form)) + (|clearClams|) + u)) + +\end{chunk} + +\defun{compileConstructor1}{compileConstructor1} +\calls{compileConstructor1}{getdatabase} +\calls{compileConstructor1}{compAndDefine} +\calls{compileConstructor1}{comp} +\calls{compileConstructor1}{clearConstructorCache} +\refsdollar{compileConstructor1}{mutableDomain} +\refsdollar{compileConstructor1}{ConstructorCache} +\refsdollar{compileConstructor1}{clamList} +\defsdollar{compileConstructor1}{clamList} +\begin{chunk}{defun compileConstructor1} +(defun |compileConstructor1| (form) + (let (|$clamList| fn key vl bodyl lambdaOrSlam compForm u) + (declare (special |$clamList| |$ConstructorCache| |$mutableDomain|)) + (setq fn (car form)) + (setq key (caadr form)) + (setq vl (cadadr form)) + (setq bodyl (cddadr form)) + (setq |$clamList| nil) + (setq lambdaOrSlam + (cond + ((eq (getdatabase fn 'constructorkind) '|category|) 'spadslam) + (|$mutableDomain| 'lambda) + (t + (setq |$clamList| + (cons (list fn '|$ConstructorCache| '|domainEqualList| '|count|) + |$clamList|)) + 'lambda))) + (setq compForm (list (list fn (cons lambdaorslam (cons vl bodyl))))) + (if (eq (getdatabase fn 'constructorkind) '|category|) + (setq u (|compAndDefine| compForm)) + (setq u (comp compForm))) + (|clearConstructorCache| fn) + (car u))) + +\end{chunk} + +\defun{putInLocalDomainReferences}{putInLocalDomainReferences} +\calls{putInLocalDomainReferences}{NRTputInTail} +\refsdollar{putInLocalDomainReferences}{QuickCode} +\defsdollar{putInLocalDomainReferences}{elt} +\begin{chunk}{defun putInLocalDomainReferences} +(defun |putInLocalDomainReferences| (def) + (let (|$elt| opName lam varl body) + (declare (special |$elt| |$QuickCode|)) + (setq opName (car def)) + (setq lam (caadr def)) + (setq varl (cadadr def)) + (setq body (car (cddadr def))) + (setq |$elt| (if |$QuickCode| 'qrefelt 'elt)) + (|NRTputInTail| (cddadr def)) + def)) + +\end{chunk} + +\defun{getArgumentModeOrMoan}{getArgumentModeOrMoan} +\calls{getArgumentModeOrMoan}{getArgumentMode} +\calls{getArgumentModeOrMoan}{stackSemanticError} +\begin{chunk}{defun getArgumentModeOrMoan} +(defun |getArgumentModeOrMoan| (x form env) + (or (|getArgumentMode| x env) + (|stackSemanticError| + (list '|argument | x '| of | form '| is not declared|) nil))) + +\end{chunk} + \defun{augLisplibModemapsFromCategory}{augLisplibModemapsFromCategory} \calls{augLisplibModemapsFromCategory}{sublis} \calls{augLisplibModemapsFromCategory}{mkAlistOfExplicitCategoryOps} @@ -7676,6 +7762,23 @@ where item has form \end{chunk} +\defun{compMakeCategoryObject}{compMakeCategoryObject} +\calls{compMakeCategoryObject}{isCategoryForm} +\calls{compMakeCategoryObject}{mkEvalableCategoryForm} +\refsdollar{compMakeCategoryObject}{e} +\refsdollar{compMakeCategoryObject}{Category} +\begin{chunk}{defun compMakeCategoryObject} +(defun |compMakeCategoryObject| (c |$e|) + (declare (special |$e|)) + (let (u) + (declare (special |$Category|)) + (cond + ((null (|isCategoryForm| c |$e|)) nil) + ((setq u (|mkEvalableCategoryForm| c)) (list (|eval| u) |$Category| |$e|)) + (t nil)))) + +\end{chunk} + \defun{mergeSignatureAndLocalVarAlists}{mergeSignatureAndLocalVarAlists} \calls{mergeSignatureAndLocalVarAlists}{lassoc} \begin{chunk}{defun mergeSignatureAndLocalVarAlists} @@ -7721,7 +7824,6 @@ where item has form \defun{compDefineFunctor1}{compDefineFunctor1} \calls{compDefineFunctor1}{isCategoryPackageName} \calls{compDefineFunctor1}{getArgumentModeOrMoan} -\calls{compDefineFunctor1}{modemap2Signature} \calls{compDefineFunctor1}{getModemap} \calls{compDefineFunctor1}{giveFormalParametersValues} \calls{compDefineFunctor1}{compMakeCategoryObject} @@ -7923,7 +8025,7 @@ where item has form (setq |$form| (cons |$op| argl)) (setq |$functorForm| |$form|) (unless (car signaturep) - (setq signaturep (|modemap2Signature| (|getModemap| |$form| |$e|)))) + (setq signaturep (cdar (|getModemap| |$form| |$e|)))) (setq target (first signaturep)) (setq |$functorTarget| target) (setq |$e| (|giveFormalParametersValues| argl |$e|)) @@ -8218,6 +8320,22 @@ where item has form \end{chunk} +\defun{bootStrapError}{bootStrapError} +\calls{bootStrapError}{mkq} +\calls{bootStrapError}{namestring} +\calls{bootStrapError}{mkDomainConstructor} +\begin{chunk}{defun bootStrapError} +(defun |bootStrapError| (functorForm sourceFile) + (list 'cond + (list '|$bootStrapMode| + (list 'vector (|mkDomainConstructor| functorForm) nil nil nil nil nil)) + (list ''t + (list '|systemError| + (list 'list ''|%b| (MKQ (CAR functorForm)) ''|%d| "from" ''|%b| + (mkq (|namestring| sourceFile)) ''|%d| "needs to be compiled"))))) + +\end{chunk} + \defun{reportOnFunctorCompilation}{reportOnFunctorCompilation} \calls{reportOnFunctorCompilation}{displayMissingFunctions} \calls{reportOnFunctorCompilation}{sayBrightly} @@ -8653,6 +8771,46 @@ where item has form \end{chunk} +\defun{orderByDependency}{orderByDependency} +\calls{orderByDependency}{say} +\calls{orderByDependency}{userError} +\calls{orderByDependency}{intersection} +\calls{orderByDependency}{member} +\calls{orderByDependency}{remdup} +\begin{chunk}{defun orderByDependency} +(defun |orderByDependency| (vl dl) + (let (selfDependents fatalError newl orderedVarList vlp dlp) + (setq selfDependents + (loop for v in vl for d in dl + when (member v d) + collect v)) + (loop for v in vl for d in dl + when (member v d) + do (say v "depends on itself") + (setq fatalError t)) + (cond + (fatalError (|userError| "Parameter specification error")) + (t + (loop until (null vl) do + (setq newl + (loop for v in vl for d in dl + when (null (|intersection| d vl)) + collect v)) + (if (null newl) + (setq vl nil) ; force loop exit + (progn + (setq orderedVarList (append newl orderedVarList)) + (setq vlp (setdifference vl newl)) + (setq dlp + (loop for x in vl for d in dl + when (|member| x vlp) + collect (setdifference d newl))) + (setq vl vlp) + (setq dl dlp)))) + (when (and newl orderedVarList) (remdup (nreverse orderedVarList))))))) + +\end{chunk} + \section{Functions to manipulate modemaps} \defun{addDomain}{addDomain} @@ -9037,43 +9195,6 @@ The way XLAMs work: \end{chunk} -\defun{addModemapKnown}{addModemapKnown} -\calls{addModemapKnown}{addModemap0} -\refsdollar{addModemapKnown}{e} -\refsdollar{CapsuleModemapFrame}{insideCapsuleFunctionIfTrue} -\defsdollar{addModemapKnown}{CapsuleModemapFrame} -\begin{chunk}{defun addModemapKnown} -(defun |addModemapKnown| (op mc sig pred fn |$e|) - (declare (special |$e| |$CapsuleModemapFrame| |$insideCapsuleFunctionIfTrue|)) - (if (eq |$insideCapsuleFunctionIfTrue| t) - (progn - (setq |$CapsuleModemapFrame| - (|addModemap0| op mc sig pred fn |$CapsuleModemapFrame|)) - |$e|) - (|addModemap0| op mc sig pred fn |$e|))) - -\end{chunk} - -\defun{addModemap0}{addModemap0} -\calls{addModemap0}{pairp} -\calls{addModemap0}{qcar} -\calls{addModemap0}{addEltModemap} -\calls{addModemap0}{addModemap1} -\refsdollar{addModemap0}{functorForm} -\begin{chunk}{defun addModemap0} -(defun |addModemap0| (op mc sig pred fn env) - (declare (special |$functorForm|)) - (cond - ((and (pairp |$functorForm|) - (eq (qcar |$functorForm|) '|CategoryDefaults|) - (eq mc '$)) - env) - ((or (eq op '|elt|) (eq op '|setelt|)) - (|addEltModemap| op mc sig pred fn env)) - (t (|addModemap1| op mc sig pred fn env)))) - -\end{chunk} - \defun{addEltModemap}{addEltModemap} This is a hack to change selectors from strings to identifiers; and to add flag identifiers as literals in the environment @@ -9118,29 +9239,6 @@ add flag identifiers as literals in the environment \end{chunk} -\defun{addModemap1}{addModemap1} -\calls{addModemap1}{msubst} -\calls{addModemap1}{getProplist} -\calls{addModemap1}{mkNewModemapList} -\calls{addModemap1}{lassoc} -\calls{addModemap1}{augProplist} -\calls{addModemap1}{unErrorRef} -\calls{addModemap1}{addBinding} -\begin{chunk}{defun addModemap1} -(defun |addModemap1| (op mc sig pred fn env) - (let (currentProplist newModemapList newProplist newProplistp) - (when (eq mc '|Rep|) (setq sig (msubst '$ '|Rep| sig))) - (setq currentProplist (or (|getProplist| op env) nil)) - (setq newModemapList - (|mkNewModemapList| mc sig pred fn - (lassoc '|modemap| currentProplist) env nil)) - (setq newProplist (|augProplist| currentProplist '|modemap| newModemapList)) - (setq newProplistp (|augProplist| newProplist 'fluid t)) - (|unErrorRef| op) - (|addBinding| op newProplistp env))) - -\end{chunk} - \defun{mkNewModemapList}{mkNewModemapList} \calls{mkNewModemapList}{member} \calls{mkNewModemapList}{assoc} @@ -9245,6 +9343,19 @@ add flag identifiers as literals in the environment \end{chunk} +\defun{TruthP}{TruthP} +\calls{TruthP}{qcar} +\calls{TruthP}{pairp} +\begin{chunk}{defun TruthP} +(defun |TruthP| (x) + (cond + ((null x) nil) + ((eq x t) t) + ((and (pairp x) (eq (qcar x) 'quote)) t) + (t nil))) + +\end{chunk} + \defun{evalAndSub}{evalAndSub} \calls{evalAndSub}{isCategory} \calls{evalAndSub}{substNames} @@ -9399,6 +9510,103 @@ add flag identifiers as literals in the environment \end{chunk} +\section{Maintaining Modemaps} +\defun{addModemapKnown}{addModemapKnown} +\calls{addModemapKnown}{addModemap0} +\refsdollar{addModemapKnown}{e} +\refsdollar{CapsuleModemapFrame}{insideCapsuleFunctionIfTrue} +\defsdollar{addModemapKnown}{CapsuleModemapFrame} +\begin{chunk}{defun addModemapKnown} +(defun |addModemapKnown| (op mc sig pred fn |$e|) + (declare (special |$e| |$CapsuleModemapFrame| |$insideCapsuleFunctionIfTrue|)) + (if (eq |$insideCapsuleFunctionIfTrue| t) + (progn + (setq |$CapsuleModemapFrame| + (|addModemap0| op mc sig pred fn |$CapsuleModemapFrame|)) + |$e|) + (|addModemap0| op mc sig pred fn |$e|))) + +\end{chunk} + +\defun{addModemap}{addModemap} +\calls{addModemap}{addModemap0} +\calls{addModemap}{knownInfo} +\refsdollar{addModemap}{e} +\refsdollar{addModemap}{InteractiveMode} +\refsdollar{addModemap}{insideCapsuleFunctionIfTrue} +\refsdollar{addModemap}{CapsuleModemapFrame} +\defsdollar{addModemap}{CapsuleModemapFrame} +\begin{chunk}{defun addModemap} +;addModemap(op,mc,sig,pred,fn,$e) == +; $InteractiveMode => $e +; if knownInfo pred then pred:=true +; $insideCapsuleFunctionIfTrue=true => +; $CapsuleModemapFrame := +; addModemap0(op,mc,sig,pred,fn,$CapsuleModemapFrame) +; $e +; addModemap0(op,mc,sig,pred,fn,$e) + +(defun |addModemap| (op mc sig pred fn |$e|) + (declare (special |$e| |$CapsuleModemapFrame| |$InteractiveMode| + |$insideCapsuleFunctionIfTrue|)) + (cond + (|$InteractiveMode| |$e|) + (t + (when (|knownInfo| pred) (setq pred t)) + (cond + ((eq |$insideCapsuleFunctionIfTrue| t) + (setq |$CapsuleModemapFrame| + (|addModemap0| op mc sig pred fn |$CapsuleModemapFrame|)) + |$e|) + (t + (|addModemap0| op mc sig pred fn |$e|)))))) + +\end{chunk} + +\defun{addModemap0}{addModemap0} +\calls{addModemap0}{pairp} +\calls{addModemap0}{qcar} +\calls{addModemap0}{addEltModemap} +\calls{addModemap0}{addModemap1} +\refsdollar{addModemap0}{functorForm} +\begin{chunk}{defun addModemap0} +(defun |addModemap0| (op mc sig pred fn env) + (declare (special |$functorForm|)) + (cond + ((and (pairp |$functorForm|) + (eq (qcar |$functorForm|) '|CategoryDefaults|) + (eq mc '$)) + env) + ((or (eq op '|elt|) (eq op '|setelt|)) + (|addEltModemap| op mc sig pred fn env)) + (t (|addModemap1| op mc sig pred fn env)))) + +\end{chunk} + +\defun{addModemap1}{addModemap1} +\calls{addModemap1}{msubst} +\calls{addModemap1}{getProplist} +\calls{addModemap1}{mkNewModemapList} +\calls{addModemap1}{lassoc} +\calls{addModemap1}{augProplist} +\calls{addModemap1}{unErrorRef} +\calls{addModemap1}{addBinding} +\begin{chunk}{defun addModemap1} +(defun |addModemap1| (op mc sig pred fn env) + (let (currentProplist newModemapList newProplist newProplistp) + (when (eq mc '|Rep|) (setq sig (msubst '$ '|Rep| sig))) + (setq currentProplist (or (|getProplist| op env) nil)) + (setq newModemapList + (|mkNewModemapList| mc sig pred fn + (lassoc '|modemap| currentProplist) env nil)) + (setq newProplist (|augProplist| currentProplist '|modemap| newModemapList)) + (setq newProplistp (|augProplist| newProplist 'fluid t)) + (|unErrorRef| op) + (|addBinding| op newProplistp env))) + +\end{chunk} + + \section{Indirect called comp routines} In the {\bf compExpression} function there is the code: \begin{verbatim} @@ -9517,6 +9725,16 @@ in the body of the add. \end{chunk} +\defun{compTuple2Record}{compTuple2Record} +\begin{chunk}{defun compTuple2Record} +(defun |compTuple2Record| (u) + (let ((i 0)) + (cons '|Record| + (loop for x in (rest u) + collect (list '|:| (incf i) x))))) + +\end{chunk} + \defplist{capsule}{compCapsule plist} \begin{chunk}{postvars} (eval-when (eval load) @@ -9579,6 +9797,258 @@ in the body of the add. \end{chunk} +\defun{compCapsuleItems}{compCapsuleItems} +The variable data appears to be unbound at runtime. Optimized +code won't check for this but interpreted code fails. We should +PROVE that data is unbound at runtime but have not done so yet. +Rather than remove the code entirely (since there MIGHT be a +path where it is used) we check for the runtime bound case and +assign \verb|$myFunctorBody| if data has a value. + +The compCapsuleInner function in this file LOOKS like it sets +data and expects code to manipulate the assigned data structure. +Since we can't be sure we take the least disruptive course of action. + +\calls{compCapsuleItems}{compSingleCapsuleItem} +\defsdollar{compCapsuleItems}{top-level} +\defsdollar{compCapsuleItems}{myFunctorBody} +\defsdollar{compCapsuleItems}{signatureOfForm} +\defsdollar{compCapsuleItems}{suffix} +\defsdollar{compCapsuleItems}{e} +\refsdollar{compCapsuleItems}{pred} +\refsdollar{compCapsuleItems}{e} +\begin{chunk}{defun compCapsuleItems} +(defun |compCapsuleItems| (itemlist |$predl| |$e|) + (declare (special |$predl| |$e|)) + (let ($top_level |$myFunctorBody| |$signatureOfForm| |$suffix|) + (declare (special $top_level |$myFunctorBody| |$signatureOfForm| |$suffix|)) + (setq $top_level nil) + (setq |$myFunctorBody| nil) + (when (boundp '|data|) (setq |$myFunctorBody| |data|)) + (setq |$signatureOfForm| nil) + (setq |$suffix| 0) + (loop for item in itemlist do + (setq |$e| (|compSingleCapsuleItem| item |$predl| |$e|))) + |$e|)) + +\end{chunk} + +;compSingleCapsuleItem(item,$predl,$e) == +; doIt(macroExpandInPlace(item,$e),$predl) +; $e + +\defun{compSingleCapsuleItem}{compSingleCapsuleItem} +\calls{compSingleCapsuleItem}{doit} +\refsdollar{compSingleCapsuleItem}{pred} +\refsdollar{compSingleCapsuleItem}{e} +\calls{compSingleCapsuleItem}{macroExpandInPlace} +\begin{chunk}{defun compSingleCapsuleItem} +(defun |compSingleCapsuleItem| (item |$predl| |$e|) + (declare (special |$predl| |$e|)) + (|doIt| (|macroExpandInPlace| item |$e|) |$predl|) + |$e|) + +\end{chunk} + +\defun{doIt}{doIt} +\calls{doIt}{pairp} +\calls{doIt}{qcar} +\calls{doIt}{qcdr} +\calls{doIt}{lastnode} +\calls{doIt}{compSingleCapsuleItem} +\calls{doIt}{isDomainForm} +\calls{doIt}{stackWarning} +\calls{doIt}{doIt} +\calls{doIt}{compOrCroak} +\calls{doIt}{stackSemanticError} +\calls{doIt}{bright} +\calls{doIt}{member} +\calls{doIt}{kar} +\calls{doIt}{|isFunctor} +\calls{doIt}{insert} +\calls{doIt}{opOf} +\calls{doIt}{get} +\calls{doIt}{NRTgetLocalIndex} +\calls{doIt}{sublis} +\calls{doIt}{NRTgetLocalIndexClear} +\calls{doIt}{compOrCroak} +\calls{doIt}{sayBrightly} +\calls{doIt}{formatUnabbreviated} +\calls{doIt}{doItIf} +\calls{doIt}{isMacro} +\calls{doIt}{put} +\calls{doIt}{cannotDo} +\refsdollar{doIt}{predl} +\refsdollar{doIt}{e} +\refsdollar{doIt}{EmptyMode} +\refsdollar{doIt}{NonMentionableDomainNames} +\refsdollar{doIt}{functorLocalParameters} +\refsdollar{doIt}{functorsUsed} +\refsdollar{doIt}{packagesUsed} +\refsdollar{doIt}{NRTopt} +\refsdollar{doIt}{Representation} +\refsdollar{doIt}{LocalDomainAlist} +\refsdollar{doIt}{QuickCode} +\refsdollar{doIt}{signatureOfForm} +\defsdollar{doIt}{genno} +\defsdollar{doIt}{e} +\defsdollar{doIt}{functorLocalParameters} +\defsdollar{doIt}{functorsUsed} +\defsdollar{doIt}{packagesUsed} +\defsdollar{doIt}{Representation} +\defsdollar{doIt}{LocalDomainAlist} +\begin{chunk}{defun doIt} +(defun |doIt| (item |$predl|) + (declare (special |$predl|)) + (prog ($genno x rhs tmp3 lhsp lhs rhsp rhsCode a doms b z tmp1 + tmp2 tmp6 op body tt functionPart u code) + (declare (special $genno |$e| |$EmptyMode| |$signatureOfForm| + |$QuickCode| |$LocalDomainAlist| |$Representation| + |$NRTopt| |$packagesUsed| |$functorsUsed| + |$functorLocalParameters| |$NonMentionableDomainNames|)) + (setq $genno 0) + (cond + ((and (pairp item) (eq (qcar item) 'seq) (pairp (qcdr item)) + (progn (setq tmp6 (reverse (qcdr item))) t) + (pairp tmp6) (pairp (qcar tmp6)) + (eq (qcar (qcar tmp6)) '|exit|) + (pairp (qcdr (qcar tmp6))) + (equal (qcar (qcdr (qcar tmp6))) 1) + (pairp (qcdr (qcdr (qcar tmp6)))) + (eq (qcdr (qcdr (qcdr (qcar tmp6)))) nil)) + (setq x (qcar (qcdr (qcdr (qcar tmp6))))) + (setq z (qcdr tmp6)) + (setq z (nreverse z)) + (rplaca item 'progn) + (rplaca (lastnode item) x) + (loop for it1 in (rest item) + do (setq |$e| (|compSingleCapsuleItem| it1 |$predl| |$e|)))) + ((|isDomainForm| item |$e|) + (setq u (list '|import| (cons (car item) (cdr item)))) + (|stackWarning| (list '|Use: import | (cons (car item) (cdr item)))) + (rplaca item (car u)) + (rplacd item (cdr u)) + (|doIt| item |$predl|)) + ((and (pairp item) (eq (qcar item) 'let) (pairp (qcdr item)) + (pairp (qcdr (qcdr item)))) + (setq lhs (qcar (qcdr item))) + (setq rhs (qcar (qcdr (qcdr item)))) + (cond + ((null (progn + (setq tmp2 (|compOrCroak| item |$EmptyMode| |$e|)) + (and (pairp tmp2) + (progn + (setq code (qcar tmp2)) + (and (pairp (qcdr tmp2)) + (progn + (and (pairp (qcdr (qcdr tmp2))) + (eq (qcdr (qcdr (qcdr tmp2))) nil) + (PROGN + (setq |$e| (qcar (qcdr (qcdr tmp2)))) + t)))))))) + (|stackSemanticError| + (cons '|cannot compile assigned value to| (|bright| lhs)) + nil)) + ((null (and (pairp code) (eq (qcar code) 'let) + (progn + (and (pairp (qcdr code)) + (progn + (setq lhsp (qcar (qcdr code))) + (and (pairp (qcdr (qcdr code))))))) + (atom (qcar (qcdr code))))) + (cond + ((and (pairp code) (eq (qcar code) 'progn)) + (|stackSemanticError| + (list '|multiple assignment | item '| not allowed|) + nil)) + (t + (rplaca item (car code)) + (rplacd item (cdr code))))) + (t + (setq lhs lhsp) + (cond + ((and (null (|member| (kar rhs) |$NonMentionableDomainNames|)) + (null (member lhs |$functorLocalParameters|))) + (setq |$functorLocalParameters| + (append |$functorLocalParameters| (list lhs))))) + (cond + ((and (pairp code) (eq (qcar code) 'let) + (progn + (setq tmp2 (qcdr code)) + (and (pairp tmp2) + (progn + (setq tmp6 (qcdr tmp2)) + (and (pairp tmp6) + (progn + (setq rhsp (qcar tmp6)) + t))))) + (|isDomainForm| rhsp |$e|)) + (cond + ((|isFunctor| rhsp) + (setq |$functorsUsed| (|insert| (|opOf| rhsp) |$functorsUsed|)) + (setq |$packagesUsed| (|insert| (list (|opOf| rhsp)) + |$packagesUsed|)))) + (cond + ((eq lhs '|Rep|) + (setq |$Representation| (elt (|get| '|Rep| '|value| |$e|) 0)) + (cond + ((eq |$NRTopt| t) + (|NRTgetLocalIndex| |$Representation|)) + (t nil)))) + (setq |$LocalDomainAlist| + (cons (cons lhs + (sublis |$LocalDomainAlist| (elt (|get| lhs '|value| |$e|) 0))) + |$LocalDomainAlist|)))) + (cond + ((and (pairp code) (eq (qcar code) 'let)) + (rplaca item (if |$QuickCode| 'qsetrefv 'setelt)) + (setq rhsCode rhsp) + (rplacd item (list '$ (|NRTgetLocalIndexClear| lhs) rhsCode))) + (t + (rplaca item (car code)) + (rplacd item (cdr code))))))) + ((and (pairp item) (eq (qcar item) '|:|) (pairp (qcdr item)) + (pairp (qcdr (qcdr item))) (eq (qcdr (qcdr (qcdr item))) nil)) + (setq tmp1 (|compOrCroak| item |$EmptyMode| |$e|)) + (setq |$e| (caddr tmp1)) + tmp1) + ((and (pairp item) (eq (qcar item) '|import|)) + (loop for dom in (qcdr item) + do (|sayBrightly| (cons " importing " (|formatUnabbreviated| dom)))) + (setq tmp1 (|compOrCroak| item |$EmptyMode| |$e|)) + (setq |$e| (caddr tmp1)) + (rplaca item 'progn) + (rplacd item nil)) + ((and (pairp item) (eq (qcar item) 'if)) + (|doItIf| item |$predl| |$e|)) + ((and (pairp item) (eq (qcar item) '|where|) (pairp (qcdr item))) + (|compOrCroak| item |$EmptyMode| |$e|)) + ((and (pairp item) (eq (qcar item) 'mdef)) + (setq tmp1 (|compOrCroak| item |$EmptyMode| |$e|)) + (setq |$e| (caddr tmp1)) tmp1) + ((and (pairp item) (eq (qcar item) 'def) (pairp (qcdr item)) + (pairp (qcar (qcdr item)))) + (setq op (qcar (qcar (qcdr item)))) + (cond + ((setq body (|isMacro| item |$e|)) + (setq |$e| (|put| op '|macro| body |$e|))) + (t + (setq tt (|compOrCroak| item |$EmptyMode| |$e|)) + (setq |$e| (caddr tt)) + (rplaca item '|CodeDefine|) + (rplacd (cadr item) (list |$signatureOfForm|)) + (setq functionPart (list '|dispatchFunction| (car tt))) + (rplaca (cddr item) functionPart) + (rplacd (cddr item) nil)))) + ((setq u (|compOrCroak| item |$EmptyMode| |$e|)) + (setq code (car u)) + (setq |$e| (caddr u)) + (rplaca item (car code)) + (rplacd item (cdr code))) + (t (|cannotDo|))))) + +\end{chunk} + \defplist{case}{compCase plist} \begin{chunk}{postvars} (eval-when (eval load) @@ -10167,6 +10637,593 @@ An angry JHD - August 15th., 1984 \end{chunk} +\defun{getSignatureFromMode}{getSignatureFromMode} +\calls{getSignatureFromMode}{getmode} +\calls{getSignatureFromMode}{opOf} +\calls{getSignatureFromMode}{pairp} +\calls{getSignatureFromMode}{qcar} +\calls{getSignatureFromMode}{qcdr} +\calls{getSignatureFromMode}{nequal} +\calls{getSignatureFromMode}{length} +\calls{getSignatureFromMode}{stackAndThrow} +\calls{getSignatureFromMode}{eqsubstlist} +\calls{getSignatureFromMode}{take} +\refsdollar{getSignatureFromMode}{FormalMapVariableList} +\begin{chunk}{defun getSignatureFromMode} +(defun |getSignatureFromMode| (form env) + (let (tmp1 signature) + (declare (special |$FormalMapVariableList|)) + (setq tmp1 (|getmode| (|opOf| form) env)) + (when (and (pairp tmp1) (eq (qcar tmp1) '|Mapping|)) + (setq signature (qcdr tmp1)) + (if (nequal (|#| form) (|#| signature)) + (|stackAndThrow| (list '|Wrong number of arguments: | form)) + (eqsubstlist (cdr form) + (take (|#| (cdr form)) |$FormalMapVariableList|) + signature))))) + +\end{chunk} + +\defun{compInternalFunction}{compInternalFunction} +\calls{compInternalFunction}{identp} +\calls{compInternalFunction}{stackAndThrow} +\begin{chunk}{defun compInternalFunction} +(defun |compInternalFunction| (df m env) + (let (form signature specialCases body op argl nbody nf ress) + (setq form (second df)) + (setq signature (third df)) + (setq specialCases (fourth df)) + (setq body (fifth df)) + (setq op (first form)) + (setq argl (rest form)) + (cond + ((null (identp op)) + (|stackAndThrow| (list '|Bad name for internal function:| op))) + ((eql (|#| argl) 0) + (|stackAndThrow| + (list '|Argumentless internal functions unsupported:| op ))) + (t + (setq nbody (list '+-> argl body)) + (setq nf (list 'let (list '|:| op (cons '|Mapping| signature)) nbody)) + (setq ress (|comp| nf m env)) ress)))) + +\end{chunk} + +\defun{compDefineCapsuleFunction}{compDefineCapsuleFunction} +\calls{compDefineCapsuleFunction}{length} +\calls{compDefineCapsuleFunction}{get} +\calls{compDefineCapsuleFunction}{profileRecord} +\calls{compDefineCapsuleFunction}{compArgumentConditions} +\calls{compDefineCapsuleFunction}{addDomain} +\calls{compDefineCapsuleFunction}{giveFormalParametersValues} +\calls{compDefineCapsuleFunction}{getSignature} +\calls{compDefineCapsuleFunction}{put} +\calls{compDefineCapsuleFunction}{stripOffSubdomainConditions} +\calls{compDefineCapsuleFunction}{getArgumentModeOrMoan} +\calls{compDefineCapsuleFunction}{checkAndDeclare} +\calls{compDefineCapsuleFunction}{hasSigInTargetCategory} +\calls{compDefineCapsuleFunction}{stripOffArgumentConditions} +\calls{compDefineCapsuleFunction}{resolve} +\calls{compDefineCapsuleFunction}{member} +\calls{compDefineCapsuleFunction}{getmode} +\calls{compDefineCapsuleFunction}{formatUnabbreviated} +\calls{compDefineCapsuleFunction}{sayBrightly} +\calls{compDefineCapsuleFunction}{compOrCroak} +\calls{compDefineCapsuleFunction}{NRTassignCapsuleFunctionSlot} +\calls{compDefineCapsuleFunction}{mkq} +\calls{compDefineCapsuleFunction}{replaceExitEtc} +\calls{compDefineCapsuleFunction}{addArgumentConditions} +\calls{compDefineCapsuleFunction}{compileCases} +\calls{compDefineCapsuleFunction}{addStats} +\refsdollar{compDefineCapsuleFunction}{semanticErrorStack} +\refsdollar{compDefineCapsuleFunction}{DomainsInScope} +\refsdollar{compDefineCapsuleFunction}{op} +\refsdollar{compDefineCapsuleFunction}{formalArgList} +\refsdollar{compDefineCapsuleFunction}{signatureOfForm} +\refsdollar{compDefineCapsuleFunction}{functionLocations} +\refsdollar{compDefineCapsuleFunction}{profileCompiler} +\refsdollar{compDefineCapsuleFunction}{compileOnlyCertainItems} +\refsdollar{compDefineCapsuleFunction}{returnMode} +\refsdollar{compDefineCapsuleFunction}{functorStats} +\refsdollar{compDefineCapsuleFunction}{functionStats} +\defsdollar{compDefineCapsuleFunction}{form} +\defsdollar{compDefineCapsuleFunction}{functionStats} +\defsdollar{compDefineCapsuleFunction}{argumentConditionList} +\defsdollar{compDefineCapsuleFunction}{finalEnv} +\defsdollar{compDefineCapsuleFunction}{initCapsuleErrorCount} +\defsdollar{compDefineCapsuleFunction}{insideCapsuleFunctionIfTrue} +\defsdollar{compDefineCapsuleFunction}{CapsuleModemapFrame} +\defsdollar{compDefineCapsuleFunction}{CapsuleDomainsInScope} +\defsdollar{compDefineCapsuleFunction}{insideExpressionIfTrue} +\defsdollar{compDefineCapsuleFunction}{returnMode} +\defsdollar{compDefineCapsuleFunction}{op} +\defsdollar{compDefineCapsuleFunction}{formalArgList} +\defsdollar{compDefineCapsuleFunction}{signatureOfForm} +\defsdollar{compDefineCapsuleFunction}{functionLocations} +\begin{chunk}{defun compDefineCapsuleFunction} +(defun |compDefineCapsuleFunction| (df m oldE |$prefix| |$formalArgList|) + (declare (special |$prefix| |$formalArgList|)) + (let (|$form| |$op| |$functionStats| |$argumentConditionList| |$finalEnv| + |$initCapsuleErrorCount| |$insideCapsuleFunctionIfTrue| + |$CapsuleModemapFrame| |$CapsuleDomainsInScope| + |$insideExpressionIfTrue| form signature body tmp1 lineNumber + specialCases argl identSig argModeList signaturep e rettype tmp2 + localOrExported formattedSig tt catchTag bodyp finalBody fun val) + (declare (special |$form| |$op| |$functionStats| |$functorStats| + |$argumentConditionList| |$finalEnv| |$returnMode| + |$initCapsuleErrorCount| |$newCompCompare| |$NoValueMode| + |$insideCapsuleFunctionIfTrue| + |$CapsuleModemapFrame| |$CapsuleDomainsInScope| + |$insideExpressionIfTrue| |$compileOnlyCertainItems| + |$profileCompiler| |$functionLocations| |$finalEnv| + |$signatureOfForm| |$semanticErrorStack|)) + (setq form (second df)) + (setq signature (third df)) + (setq specialCases (fourth df)) + (setq body (fifth df)) + (setq tmp1 specialCases) + (setq lineNumber (first tmp1)) + (setq specialCases (rest tmp1)) + (setq e oldE) +;-1. bind global variables + (setq |$form| nil) + (setq |$op| nil) + (setq |$functionStats| (list 0 0)) + (setq |$argumentConditionList| nil) + (setq |$finalEnv| nil) +; used by ReplaceExitEtc to get a common environment + (setq |$initCapsuleErrorCount| (|#| |$semanticErrorStack|)) + (setq |$insideCapsuleFunctionIfTrue| t) + (setq |$CapsuleModemapFrame| e) + (setq |$CapsuleDomainsInScope| (|get| '|$DomainsInScope| 'special e)) + (setq |$insideExpressionIfTrue| t) + (setq |$returnMode| m) + (setq |$op| (first form)) + (setq argl (rest form)) + (setq |$form| (cons |$op| argl)) + (setq argl (|stripOffArgumentConditions| argl)) + (setq |$formalArgList| (append argl |$formalArgList|)) +; let target and local signatures help determine modes of arguments + (setq argModeList + (cond + ((setq identSig (|hasSigInTargetCategory| argl form (car signature) e)) + (setq e (|checkAndDeclare| argl form identSig e)) + (cdr identSig)) + (t + (loop for a in argl + collect (|getArgumentModeOrMoan| a form e))))) + (setq argModeList (|stripOffSubdomainConditions| argModeList argl)) + (setq signaturep (cons (car signature) argModeList)) + (unless identSig + (setq oldE (|put| |$op| '|mode| (cons '|Mapping| signaturep) oldE))) +; obtain target type if not given + (cond + ((null (car signaturep)) + (setq signaturep + (cond + (identSig identSig) + (t (|getSignature| |$op| (cdr signaturep) e)))))) + (when signaturep + (setq e (|giveFormalParametersValues| argl e)) + (setq |$signatureOfForm| signaturep) + (setq |$functionLocations| + (cons (cons (list |$op| |$signatureOfForm|) lineNumber) + |$functionLocations|)) + (setq e (|addDomain| (car signaturep) e)) + (setq e (|compArgumentConditions| e)) + (when |$profileCompiler| + (loop for x in argl for y in signaturep + do (|profileRecord| '|arguments| x y))) +; 4. introduce needed domains into extendedEnv + (loop for domain in signaturep + do (setq e (|addDomain| domain e))) +; 6. compile body in environment with extended environment + (setq rettype (|resolve| (car signaturep) |$returnMode|)) + (setq localOrExported + (cond + ((and (null (|member| |$op| |$formalArgList|)) + (progn + (setq tmp2 (|getmode| |$op| e)) + (and (pairp tmp2) (eq (qcar tmp2) '|Mapping|)))) + '|local|) + (t '|exported|))) +; 6a skip if compiling only certain items but not this one +; could be moved closer to the top + (setq formattedSig (|formatUnabbreviated| (cons '|Mapping| signaturep))) + (cond + ((and |$compileOnlyCertainItems| + (null (|member| |$op| |$compileOnlyCertainItems|))) + (|sayBrightly| + (cons " skipping " (cons localOrExported (|bright| |$op|)))) + (list nil (cons '|Mapping| signaturep) oldE)) + (t + (|sayBrightly| + (cons " compiling " (cons localOrExported (append (|bright| |$op|) + (cons ": " formattedSig))))) + (setq tt + (or (catch '|compCapsuleBody| (|compOrCroak| body rettype e)) + (list (intern " " "BOOT") rettype e))) + (|NRTassignCapsuleFunctionSlot| |$op| signaturep) +; A THROW to the above CATCH occurs if too many semantic errors occur +; see stackSemanticError + (setq catchTag (mkq (gensym))) + (setq fun + (progn + (setq bodyp + (|replaceExitEtc| (car tt) catchTag '|TAGGEDreturn| |$returnMode|)) + (setq bodyp (|addArgumentConditions| bodyp |$op|)) + (setq finalBody (list 'catch catchTag bodyp)) + (|compileCases| + (list |$op| (list 'lam (append argl (list '$)) finalBody)) + oldE))) + (setq |$functorStats| (|addStats| |$functorStats| |$functionStats|)) +; 7. give operator a 'value property + (setq val (list fun signaturep e)) + (list fun (list '|Mapping| signaturep) oldE)))))) + +\end{chunk} + +\defun{compileCases}{compileCases} +\calls{compileCases}{eval} +\calls{compileCases}{pairp} +\calls{compileCases}{qcar} +\calls{compileCases}{qcdr} +\calls{compileCases}{msubst} +\calls{compileCases}{compile} +\calls{compileCases}{getSpecialCaseAssoc} +\calls{compileCases}{get} +\calls{compileCases}{assocleft} +\calls{compileCases}{outerProduct} +\calls{compileCases}{assocright} +\calls{compileCases}{mkpf} +\refsdollar{compileCases}{getDomainCode} +\refsdollar{compileCases}{insideFunctorIfTrue} +\defsdollar{compileCases}{specialCaseKeyList} +\begin{chunk}{defun compileCases} +(defun |compileCases| (x |$e|) + (declare (special |$e|)) + (labels ( + (isEltArgumentIn (Rlist x) + (cond + ((atom x) nil) + ((and (pairp x) (eq (qcar x) 'elt) (pairp (qcdr x)) + (pairp (qcdr (qcdr x))) (eq (qcdr (qcdr (qcdr x))) nil)) + (or (member (second x) Rlist) + (isEltArgumentIn Rlist (cdr x)))) + ((and (pairp x) (eq (qcar x) 'qrefelt) (pairp (qcdr x)) + (pairp (qcdr (qcdr x))) (eq (qcdr (qcdr (qcdr x))) nil)) + (or (member (second x) Rlist) + (isEltArgumentIn Rlist (cdr x)))) + (t + (or (isEltArgumentIn Rlist (car x)) + (isEltArgumentIn Rlist (CDR x)))))) + (FindNamesFor (r rp) + (let (v u) + (declare (special |$getDomainCode|)) + (cons r + (loop for item in |$getDomainCode| + do + (setq v (second item)) + (setq u (third item)) + when (and (equal (second u) r) (|eval| (msubst rp r u))) + collect v))))) + (let (|$specialCaseKeyList| specialCaseAssoc listOfDomains listOfAllCases cl) + (declare (special |$specialCaseKeyList| |$true| |$insideFunctorIfTrue|)) + (setq |$specialCaseKeyList| nil) + (cond + ((null (eq |$insideFunctorIfTrue| t)) (|compile| x)) + (t + (setq specialCaseAssoc + (loop for y in (|getSpecialCaseAssoc|) + when (and (null (|get| (first y) '|specialCase| |$e|)) + (isEltArgumentIn (FindNamesFor (first y) (second y)) x)) + collect y)) + (cond + ((null specialCaseAssoc) (|compile| x)) + (t + (setq listOfDomains (assocleft specialCaseAssoc)) + (setq listOfAllCases (|outerProduct| (assocright specialCaseAssoc))) + (setq cl + (loop for z in listOfAllCases + collect + (progn + (setq |$specialCaseKeyList| + (loop for d in listOfDomains for c in z + collect (cons d c))) + (cons + (mkpf + (loop for d in listOfDomains for c in z + collect (list 'equal d c)) + 'and) + (list (|compile| (copy x))))))) + (setq |$specialCaseKeyList| nil) + (cons 'cond (append cl (list (list |$true| (|compile| x)))))))))))) + +\end{chunk} + +\defun{getSpecialCaseAssoc}{getSpecialCaseAssoc} +\refsdollar{getSpecialCaseAssoc}{functorForm} +\refsdollar{getSpecialCaseAssoc}{functorSpecialCases} +\begin{chunk}{defun getSpecialCaseAssoc} +(defun |getSpecialCaseAssoc| () + (declare (special |$functorSpecialCases| |$functorForm|)) + (loop for r in (rest |$functorForm|) + for z in (rest |$functorSpecialCases|) + when z + collect (cons r z))) + +\end{chunk} + +\defun{addArgumentConditions}{addArgumentConditions} +\calls{addArgumentConditions}{pairp} +\calls{addArgumentConditions}{qcar} +\calls{addArgumentConditions}{qcdr} +\calls{addArgumentConditions}{mkq} +\calls{addArgumentConditions}{systemErrorHere} +\refsdollar{addArgumentConditions}{true} +\refsdollar{addArgumentConditions}{functionName} +\refsdollar{addArgumentConditions}{body} +\refsdollar{addArgumentConditions}{argumentConditionList} +\defsdollar{addArgumentConditions}{argumentConditionList} +\begin{chunk}{defun addArgumentConditions} +(defun |addArgumentConditions| (|$body| |$functionName|) + (declare (special |$body| |$functionName| |$argumentConditionList| |$true|)) + (labels ( + (fn (clist) + (let (n untypedCondition typedCondition) + (cond + ((and (pairp clist) (pairp (qcar clist)) (pairp (qcdr (qcar clist))) + (pairp (qcdr (qcdr (qcar clist)))) + (eq (qcdr (qcdr (qcdr (qcar clist)))) nil)) + (setq n (qcar (qcar clist))) + (setq untypedCondition (qcar (qcdr (qcar clist)))) + (setq typedCondition (qcar (qcdr (qcdr (qcar clist))))) + (list 'cond + (list typedCondition (fn (cdr clist))) + (list |$true| + (list '|argumentDataError| n + (mkq untypedCondition) (mkq |$functionName|))))) + ((null clist) |$body|) + (t (|systemErrorHere| "addArgumentConditions")))))) + (if |$argumentConditionList| + (fn |$argumentConditionList|) + |$body|))) + + +\end{chunk} + +\defun{compArgumentConditions}{compArgumentConditions} +\calls{compArgumentConditions}{msubst} +\calls{compArgumentConditions}{compOrCroak} +\refsdollar{compArgumentConditions}{Boolean} +\refsdollar{compArgumentConditions}{argumentConditionList} +\defsdollar{compArgumentConditions}{argumentConditionList} +\begin{chunk}{defun compArgumentConditions} +(defun |compArgumentConditions| (env) + (let (n a x y tmp1) + (declare (special |$Boolean| |$argumentConditionList|)) + (setq |$argumentConditionList| + (loop for item in |$argumentConditionList| + do + (setq n (first item)) + (setq a (second item)) + (setq x (third item)) + (setq y (msubst a '|#1| x)) + (setq tmp1 (|compOrCroak| y |$Boolean| env)) + (setq env (third tmp1)) + collect + (list n x (first tmp1)))) + env)) + +\end{chunk} + +\defun{stripOffSubdomainConditions}{stripOffSubdomainConditions} +\calls{stripOffSubdomainConditions}{pairp} +\calls{stripOffSubdomainConditions}{qcar} +\calls{stripOffSubdomainConditions}{qcdr} +\calls{stripOffSubdomainConditions}{assoc} +\calls{stripOffSubdomainConditions}{mkpf} +\refsdollar{stripOffSubdomainConditions}{argumentConditionList} +\defsdollar{stripOffSubdomainConditions}{argumentConditionList} +\begin{chunk}{defun stripOffSubdomainConditions} +(defun |stripOffSubdomainConditions| (margl argl) + (let (pair (i 0)) + (declare (special |$argumentConditionList|)) + (loop for x in margl for arg in argl + do (incf i) + collect + (cond + ((and (pairp x) (eq (qcar x) '|SubDomain|) (pairp (qcdr x)) + (pairp (qcdr (qcdr x))) (eq (qcdr (qcdr (qcdr x))) nil)) + (cond + ((setq pair (|assoc| i |$argumentConditionList|)) + (rplac (cadr pair) (mkpf (list (third x) (cadr pair)) 'and)) + (second x)) + (t + (setq |$argumentConditionList| + (cons (list i arg (third x)) |$argumentConditionList|)) + (second x)))) + (t x))))) + +\end{chunk} + +\defun{stripOffArgumentConditions}{stripOffArgumentConditions} +\calls{stripOffArgumentConditions}{pairp} +\calls{stripOffArgumentConditions}{qcar} +\calls{stripOffArgumentConditions}{qcdr} +\calls{stripOffArgumentConditions}{msubst} +\refsdollar{stripOffArgumentConditions}{argumentConditionList} +\defsdollar{stripOffArgumentConditions}{argumentConditionList} +\begin{chunk}{defun stripOffArgumentConditions} +(defun |stripOffArgumentConditions| (argl) + (let (condition (i 0)) + (declare (special |$argumentConditionList|)) + (loop for x in argl + do (incf i) + collect + (cond + ((and (pairp x) (eq (qcar x) '|\||) (pairp (qcdr x)) + (pairp (qcdr (qcdr x))) (eq (qcdr (qcdr (qcdr x))) nil)) + (setq condition (msubst '|#1| (second x) (third x))) + (setq |$argumentConditionList| + (cons (list i (second x) condition) |$argumentConditionList|)) + (second x)) + (t x))))) + +\end{chunk} + +\defun{getSignature}{getSignature} +Try to return a signature. If there isn't one, complain and return nil. +If there are more than one then remove any that are subsumed. If there +is still more than one complain else return the only signature. +\calls{getSignature}{get} +\calls{getSignature}{length} +\calls{getSignature}{remdup} +\calls{getSignature}{knownInfo} +\calls{getSignature}{getmode} +\calls{getSignature}{pairp} +\calls{getSignature}{qcar} +\calls{getSignature}{qcdr} +\calls{getSignature}{say} +\calls{getSignature}{printSignature} +\calls{getSignature}{SourceLevelSubsume} +\calls{getSignature}{stackSemanticError} +\refsdollar{getSignature{e} +\begin{chunk}{defun getSignature} +(defun |getSignature| (op argModeList |$e|) + (declare (special |$e|)) + (let (mmList pred u tmp1 dc sig sigl) + (setq mmList (|get| op '|modemap| |$e|)) + (cond + ((eql 1 + (|#| (setq sigl (remdup + (loop for item in mmList + do + (setq dc (caar item)) + (setq sig (cdar item)) + (setq pred (caadr item)) + when (and (eq dc '$) (equal (cdr sig) argModeList) (|knownInfo| pred)) + collect sig))))) + (car sigl)) + ((null sigl) + (cond + ((progn + (setq tmp1 (setq u (|getmode| op |$e|))) + (and (pairp tmp1) (eq (qcar tmp1) '|Mapping|))) + (qcdr tmp1)) + (t + (say "************* USER ERROR **********") + (say "available signatures for " op ": ") + (cond + ((null mmList) (say " NONE")) + (t + (loop for item in mmList + do (|printSignature| '| | op (cdar item))) + (|printSignature| '|NEED | op (cons '? argModeList)))) + nil))) + (t + ; Before we complain about duplicate signatures, we should + ; check that we do not have for example, a partial - as + ; well as a total one. SourceLevelSubsume should do this + (loop for u in sigl do + (loop for v in sigl + when (null (equal u v)) + do (when (|SourceLevelSubsume| u v) (setq sigl (|delete| v sigl))))) + (cond + ((eql 1 (|#| sigl)) (car sigl)) + (t + (|stackSemanticError| + (list '|duplicate signatures for | op '|: | argModeList) nil))))))))) + +\end{chunk} + +\defun{checkAndDeclare}{checkAndDeclare} +\calls{checkAndDeclare}{getArgumentMode} +\calls{checkAndDeclare}{modeEqual} +\calls{checkAndDeclare}{put} +\calls{checkAndDeclare}{sayBrightly} +\calls{checkAndDeclare}{bright} +\begin{chunk}{defun checkAndDeclare} +(defun |checkAndDeclare| (argl form sig env) + (let (m1 stack) + (loop for a in argl for m in (rest sig) + do + (if (setq m1 (|getArgumentMode| a env)) + (if (null (|modeEqual| m1 m)) + (setq stack + (cons '| | (append (|bright| a) + (cons "must have type " + (cons m + (cons " not " + (cons m1 + (cons '|%l| stack))))))))) + (setq env (|put| a '|mode| m env)))) + (when stack + (|sayBrightly| + (cons " Parameters of " + (append (|bright| (car form)) + (cons " are of wrong type:" + (cons '|%l| stack)))))) + env)) + +\end{chunk} + +\defun{hasSigInTargetCategory}{hasSigInTargetCategory} +\calls{hasSigInTargetCategory}{getArgumentMode} +\calls{hasSigInTargetCategory}{remdup} +\calls{hasSigInTargetCategory}{length} +\calls{hasSigInTargetCategory}{getSignatureFromMode} +\calls{hasSigInTargetCategory}{stackWarning} +\calls{hasSigInTargetCategory}{compareMode2Arg} +\calls{hasSigInTargetCategory}{bright} +\refsdollar{hasSigInTargetCategory}{domainShell} +\begin{chunk}{defun hasSigInTargetCategory} +(defun |hasSigInTargetCategory| (argl form opsig env) + (labels ( + (fn (opName sig opsig mList form) + (declare (special |$op|)) + (and + (and + (and (equal opName |$op|) (equal (|#| sig) (|#| form))) + (or (null opsig) (equal opsig (car sig)))) + (let ((result t)) + (loop for x in mList for y in (rest sig) + do (setq result (and result (or (null x) (|modeEqual| x y))))) + result)))) + (let (mList potentialSigList c sig) + (declare (special |$domainShell|)) + (setq mList + (loop for x in argl + collect (|getArgumentMode| x env))) + (setq potentialSigList + (remdup + (loop for item in (elt |$domainShell| 1) + when (fn (caar item) (cadar item) opsig mList form) + collect (cadar item)))) + (setq c (|#| potentialSigList)) + (cond + ((eql 1 c) (car potentialSigList)) + ((eql 0 c) + (when (equal (|#| (setq sig (|getSignatureFromMode| form env))) (|#| form)) + sig)) + ((> c 1) + (setq sig (car potentialSigList)) + (|stackWarning| + (cons '|signature of lhs not unique:| + (append (|bright| sig) (list '|chosen|)))) + sig) + (t nil))))) + +\end{chunk} + +\defun{getArgumentMode}{getArgumentMode} +\calls{getArgumentMode}{get} +\begin{chunk}{defun getArgumentMode} +(defun |getArgumentMode| (x e) + (if (stringp x) x (|get| x '|mode| e))) + +\end{chunk} + \defplist{elt}{compElt plist} \begin{chunk}{postvars} (eval-when (eval load) @@ -10789,6 +11846,18 @@ An angry JHD - August 15th., 1984 \end{chunk} +\defun{compForMode}{compForMode} +\calls{compForMode}{comp} +\defsdollar{compForMode}{compForModeIfTrue} +\begin{chunk}{defun compForMode} +(defun |compForMode| (x m e) + (let (|$compForModeIfTrue|) + (declare (special |$compForModeIfTrue|)) + (setq |$compForModeIfTrue| t) + (|comp| x m e))) + +\end{chunk} + \defplist{$+->$}{compLambda plist} \begin{chunk}{postvars} (eval-when (eval load) @@ -11390,6 +12459,18 @@ An angry JHD - August 15th., 1984 \end{chunk} +\defun{uncons}{uncons} +\calls{uncons}{uncons} +\begin{chunk}{defun uncons} +(defun |uncons| (x) + (cond + ((atom x) x) + ((and (pairp x) (eq (qcar x) 'cons) (pairp (qcdr x)) + (pairp (qcdr (qcdr x))) (eq (qcdr (qcdr (qcdr x))) nil)) + (cons (second x) (|uncons| (third x)))))) + +\end{chunk} + \defun{setqMultiple}{setqMultiple} \calls{setqMultiple}{nreverse0} \calls{setqMultiple}{pairp} @@ -11836,6 +12917,14 @@ An angry JHD - August 15th., 1984 \end{chunk} +\defun{lispize}{lispize} +\calls{lispize}{optimize} +\begin{chunk}{defun lispize} +(defun |lispize| (x) + (car (|optimize| (list x)))) + +\end{chunk} + \defplist{SubsetCategory}{compSubsetCategory plist} \begin{chunk}{postvars} (eval-when (eval load) @@ -19803,6 +20892,226 @@ if \verb|$InteractiveMode| then use a null outputstream \end{chunk} +\chapter{Level 1} + +\defvar{current-fragment} +A string containing remaining chars from readline; needed because +Symbolics read-line returns embedded newlines in a c-m-Y. +\begin{chunk}{initvars} +(defvar current-fragment nil) + +\end{chunk} + +\defun{read-a-line}{read-a-line} +\calls{read-a-line}{subseq} +\calls{read-a-line}{Line-New-Line} +\calls{read-a-line}{read-a-line} +\uses{read-a-line}{*eof*} +\uses{read-a-line}{File-Closed} +\begin{chunk}{defun read-a-line} +(defun read-a-line (&optional (stream t)) + (let (cp) + (declare (special *eof* File-Closed)) + (if (and Current-Fragment (> (length Current-Fragment) 0)) + (let ((line (with-input-from-string + (s Current-Fragment :index cp :start 0) + (read-line s nil nil)))) + (setq Current-Fragment (subseq Current-Fragment cp)) + line) + (prog nil + (when (stream-eof in-stream) + (setq File-Closed t) + (setq *eof* t) + (Line-New-Line (make-string 0) Current-Line) + (return nil)) + (when (setq Current-Fragment (read-line stream)) + (return (read-a-line stream))))))) + +\end{chunk} + + +\chapter{Level 0} +\section{Line Handling} + +\subsection{Line Buffer} +The philosophy of lines is that +\begin{itemize} +\item NEXT LINE will always return a non-blank line or fail. +\item Every line is terminated by a blank character. +\end{itemize} +Hence there is always a current character, because there is never a +non-blank line, and there is always a separator character between tokens +on separate lines. Also, when a line is read, the character pointer is +always positioned ON the first character. +\defstruct{line} +\begin{chunk}{initvars} +(defstruct line "Line of input file to parse." + (buffer (make-string 0) :type string) + (current-char #\Return :type character) + (current-index 1 :type fixnum) + (last-index 0 :type fixnum) + (number 0 :type fixnum)) + +\end{chunk} + +\defvar{current-line} +The current input line. +\begin{chunk}{initvars} +(defvar current-line (make-line)) + +\end{chunk} + + +\defmacro{line-clear} +\usesstruct{line-clear}{line} +\begin{chunk}{defmacro line-clear} +(defmacro line-clear (line) + `(let ((l ,line)) + (setf (line-buffer l) (make-string 0)) + (setf (line-current-char l) #\return) + (setf (line-current-index l) 1) + (setf (line-last-index l) 0) + (setf (line-number l) 0))) + +\end{chunk} + +\defun{line-print}{line-print} +\usesstruct{line-print}{line} +\refsdollar{line-print}{out-stream} +\begin{chunk}{defun line-print} +(defun line-print (line) + (declare (special out-stream)) + (format out-stream "~&~5D> ~A~%" (Line-Number line) (Line-Buffer Line)) + (format out-stream "~v@T^~%" (+ 7 (Line-Current-Index line)))) + +\end{chunk} + +\defun{line-at-end-p}{line-at-end-p} +\usesstruct{line-at-end-p}{line} +\begin{chunk}{defun line-at-end-p} +(defun line-at-end-p (line) + "Tests if line is empty or positioned past the last character." + (>= (line-current-index line) (line-last-index line))) + +\end{chunk} + +\defun{line-past-end-p}{line-past-end-p} +\usesstruct{line-past-end-p}{line} +\begin{chunk}{defun line-past-end-p} +(defun line-past-end-p (line) + "Tests if line is empty or positioned past the last character." + (> (line-current-index line) (line-last-index line))) + +\end{chunk} + +\defun{line-next-char}{line-next-char} +\usesstruct{line-next-char}{line} +\begin{chunk}{defun line-next-char} +(defun line-next-char (line) + (elt (line-buffer line) (1+ (line-current-index line)))) + +\end{chunk} + +\defun{line-advance-char}{line-advance-char} +\usesstruct{line-advance-char}{line} +\begin{chunk}{defun line-advance-char} +(defun line-advance-char (line) + (setf (line-current-char line) + (elt (line-buffer line) (incf (line-current-index line))))) + +\end{chunk} + +\defun{line-current-segment}{line-current-segment} +\usesstruct{line-print}{line} +\begin{chunk}{defun line-current-segment} +(defun line-current-segment (line) + "Buffer from current index to last index." + (if (line-at-end-p line) + (make-string 0) + (subseq (line-buffer line) + (line-current-index line) + (line-last-index line)))) + +\end{chunk} + +\defun{line-new-line}{line-new-line} +\usesstruct{line-new-line}{line} +\begin{chunk}{defun line-new-line} +(defun line-new-line (string line &optional (linenum nil)) + "Sets string to be the next line stored in line." + (setf (line-last-index line) (1- (length string))) + (setf (line-current-index line) 0) + (setf (line-current-char line) + (or (and (> (length string) 0) (elt string 0)) #\Return)) + (setf (line-buffer line) string) + (setf (line-number line) (or linenum (1+ (line-number line))))) + +\end{chunk} + +\defun{next-line}{next-line} +\refsdollar{next-line}{in-stream} +\begin{chunk}{defun next-line} +(defun next-line (&optional (in-stream t)) + (declare (special in-stream)) + (funcall Line-Handler in-stream)) + +\end{chunk} + +\defun{Advance-Char}{Advance-Char} +\calls{Advance-Char}{Line-At-End-P} +\calls{Advance-Char}{Line-Advance-Char} +\calls{Advance-Char}{next-line} +\calls{Advance-Char}{current-char} +\refsdollar{Advance-Char}{in-stream} +\usesstruct{Advance-Char}{line} +\begin{chunk}{defun Advance-Char} +(defun Advance-Char () + "Advances IN-STREAM, invoking Next Line if necessary." + (declare (special in-stream)) + (loop + (cond + ((not (Line-At-End-P Current-Line)) + (return (Line-Advance-Char Current-Line))) + ((next-line in-stream) + (return (current-char))) + ((return nil))))) + +\end{chunk} + +\defun{storeblanks}{storeblanks} +\begin{chunk}{defun storeblanks} +(defun storeblanks (line n) + (do ((i 0 (1+ i))) + ((= i n) line) + (setf (char line i) #\ ))) + +\end{chunk} + +\defun{initial-substring}{initial-substring} +\calls{initial-substring}{mismatch} +\begin{chunk}{defun initial-substring} +(defun initial-substring (pattern line) + (let ((ind (mismatch pattern line))) + (or (null ind) (eql ind (size pattern))))) + +\end{chunk} + +\defun{get-a-line}{get-a-line} +\calls{get-a-line}{is-console} +\seebook{get-a-line}{mkprompt}{5} +\calls{get-a-line}{read-a-line} +\begin{chunk}{defun get-a-line} +(defun get-a-line (stream) + (when (is-console stream) (princ (mkprompt))) + (let ((ll (read-a-line stream))) + (if (and (stringp ll) (adjustable-array-p ll)) + (make-array (array-dimensions ll) :element-type 'string-char + :adjustable t :initial-contents ll) + ll))) + +\end{chunk} + +\chapter{The Chunks} \begin{chunk}{Compiler} (in-package "BOOT") @@ -19826,12 +21135,14 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defmacro star} \getchunk{defun action} +\getchunk{defun addArgumentConditions} \getchunk{defun addclose} \getchunk{defun addConstructorModemaps} \getchunk{defun addDomain} \getchunk{defun addEltModemap} \getchunk{defun addEmptyCapsuleIfNecessary} \getchunk{defun addModemapKnown} +\getchunk{defun addModemap} \getchunk{defun addModemap0} \getchunk{defun addModemap1} \getchunk{defun addNewDomain} @@ -19853,11 +21164,13 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun autoCoerceByModemap} \getchunk{defun blankp} +\getchunk{defun bootStrapError} \getchunk{defun bumperrorcount} \getchunk{defun canReturn} \getchunk{defun char-eq} \getchunk{defun char-ne} +\getchunk{defun checkAndDeclare} \getchunk{defun checkWarning} \getchunk{defun coerce} \getchunk{defun coerceable} @@ -19872,12 +21185,14 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun comp2} \getchunk{defun comp3} \getchunk{defun compAdd} +\getchunk{defun compArgumentConditions} \getchunk{defun compArgumentsAndTryAgain} \getchunk{defun compAtom} \getchunk{defun compAtSign} \getchunk{defun compBoolean} \getchunk{defun compCapsule} \getchunk{defun compCapsuleInner} +\getchunk{defun compCapsuleItems} \getchunk{defun compCase} \getchunk{defun compCase1} \getchunk{defun compCat} @@ -19893,6 +21208,7 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun compDefine} \getchunk{defun compDefine1} \getchunk{defun compDefineAddSignature} +\getchunk{defun compDefineCapsuleFunction} \getchunk{defun compDefineCategory} \getchunk{defun compDefineCategory1} \getchunk{defun compDefineCategory2} @@ -19909,27 +21225,34 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun compForm2} \getchunk{defun compForm3} \getchunk{defun compFormMatch} +\getchunk{defun compForMode} \getchunk{defun compFormPartiallyBottomUp} \getchunk{defun compFromIf} \getchunk{defun compFunctorBody} \getchunk{defun compHas} \getchunk{defun compHasFormat} \getchunk{defun compIf} +\getchunk{defun compile} +\getchunk{defun compileCases} +\getchunk{defun compileConstructor} +\getchunk{defun compileConstructor1} +\getchunk{defun compileDocumentation} \getchunk{defun compileFileQuietly} \getchunk{defun compile-lib-file} \getchunk{defun compiler} -\getchunk{defun compileDocumentation} \getchunk{defun compilerDoit} \getchunk{defun compilerDoitWithScreenedLisplib} \getchunk{defun compileSpad2Cmd} \getchunk{defun compileSpadLispCmd} \getchunk{defun compImport} +\getchunk{defun compInternalFunction} \getchunk{defun compIs} \getchunk{defun compJoin} \getchunk{defun compLambda} \getchunk{defun compLeave} \getchunk{defun compList} \getchunk{defun compMacro} +\getchunk{defun compMakeCategoryObject} \getchunk{defun compMakeDeclaration} \getchunk{defun compNoStacking} \getchunk{defun compNoStacking1} @@ -19945,10 +21268,9 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun compSeq} \getchunk{defun compSeqItem} \getchunk{defun compSeq1} -\getchunk{defun setqSetelt} -\getchunk{defun setqSingle} \getchunk{defun compSetq} \getchunk{defun compSetq1} +\getchunk{defun compSingleCapsuleItem} \getchunk{defun compString} \getchunk{defun compSubDomain} \getchunk{defun compSubDomain1} @@ -19956,12 +21278,14 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun compSubsetCategory} \getchunk{defun compSuchthat} \getchunk{defun compTopLevel} +\getchunk{defun compTuple2Record} \getchunk{defun compTypeOf} \getchunk{defun compUniquely} \getchunk{defun compVector} \getchunk{defun compWhere} \getchunk{defun compWithMappingMode} \getchunk{defun compWithMappingMode1} +\getchunk{defun constructMacro} \getchunk{defun containsBang} \getchunk{defun convert} \getchunk{defun convertOpAlist2compilerInfo} @@ -19977,6 +21301,7 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun disallowNilAttribute} \getchunk{defun displayMissingFunctions} \getchunk{defun displayPreCompilationErrors} +\getchunk{defun doIt} \getchunk{defun dollarTran} \getchunk{defun domainMember} \getchunk{defun drop} @@ -19998,6 +21323,8 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun freelist} \getchunk{defun get-a-line} +\getchunk{defun getArgumentMode} +\getchunk{defun getArgumentModeOrMoan} \getchunk{defun getCategoryOpsAndAtts} \getchunk{defun getConstructorOpsAndAtts} \getchunk{defun getDomainsInScope} @@ -20009,8 +21336,11 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun getModemapListFromDomain} \getchunk{defun getOperationAlist} \getchunk{defun getScriptName} +\getchunk{defun getSignature} +\getchunk{defun getSignatureFromMode} \getchunk{defun getSlotFromCategoryForm} \getchunk{defun getSlotFromFunctor} +\getchunk{defun getSpecialCaseAssoc} \getchunk{defun getSuccessEnvironment} \getchunk{defun getTargetFromRhs} \getchunk{defun get-token} @@ -20029,6 +21359,7 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun hasAplExtension} \getchunk{defun hasFormalMapVariable} \getchunk{defun hasFullSignature} +\getchunk{defun hasSigInTargetCategory} \getchunk{defun hasType} \getchunk{defun indent-pos} @@ -20058,6 +21389,7 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun line-past-end-p} \getchunk{defun line-print} \getchunk{defun line-new-line} +\getchunk{defun lispize} \getchunk{defun lisplibDoRename} \getchunk{defun lisplibWrite} \getchunk{defun loadIfNecessary} @@ -20069,7 +21401,6 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun makeCategoryPredicates} \getchunk{defun makeFunctorArgumentParameters} \getchunk{defun makeSimplePredicateOrNil} -\getchunk{defun make-string-adjustable} \getchunk{defun make-symbol-of} \getchunk{defun match-advance-string} \getchunk{defun match-current-token} @@ -20103,6 +21434,7 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun nonblankloc} \getchunk{defun optional} +\getchunk{defun orderByDependency} \getchunk{defun orderPredicateItems} \getchunk{defun orderPredTran} \getchunk{defun outputComp} @@ -20299,6 +21631,7 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun print-defun} \getchunk{defun push-reduction} \getchunk{defun putDomainsInScope} +\getchunk{defun putInLocalDomainReferences} \getchunk{defun quote-if-string} @@ -20317,17 +21650,22 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun seteltModemapFilter} \getchunk{defun setqMultiple} \getchunk{defun setqMultipleExplicit} +\getchunk{defun setqSetelt} +\getchunk{defun setqSingle} \getchunk{defun signatureTran} \getchunk{defun skip-blanks} \getchunk{defun skip-ifblock} \getchunk{defun skip-to-endif} \getchunk{defun spad} +\getchunk{defun spadCompileOrSetq} \getchunk{defun spad-fixed-arg} \getchunk{defun stack-clear} \getchunk{defun stack-load} \getchunk{defun stack-pop} \getchunk{defun stack-push} \getchunk{defun storeblanks} +\getchunk{defun stripOffArgumentConditions} +\getchunk{defun stripOffSubdomainConditions} \getchunk{defun substituteCategoryArguments} \getchunk{defun substNames} \getchunk{defun substVars} @@ -20341,12 +21679,14 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun transIs1} \getchunk{defun translabel} \getchunk{defun translabel1} +\getchunk{defun TruthP} \getchunk{defun try-get-token} \getchunk{defun tuple2List} \getchunk{defun underscore} \getchunk{defun unget-tokens} \getchunk{defun unknownTypeError} +\getchunk{defun uncons} \getchunk{defun unTuple} \getchunk{defun updateCategoryFrameForCategory} \getchunk{defun updateCategoryFrameForConstructor} diff --git a/changelog b/changelog index 5baaa13..3305292 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +20110824 tpd src/axiom-website/patches.html 20110824.01.tpd.patch +20110824 tpd src/interp/i-util.lisp treeshake compiler +20110824 tpd src/interp/define.lisp treeshake compiler +20110824 tpd books/bookvol9 treeshake compiler 20110818 tpd src/axiom-website/patches.html 20110818.02.tpd.patch 20110818 tpd src/interp/Makefile remove foam_l 20110818 tpd src/interp/foam_l.lisp removed diff --git a/src/axiom-website/patches.html b/src/axiom-website/patches.html index 9db656e..414c4ff 100644 --- a/src/axiom-website/patches.html +++ b/src/axiom-website/patches.html @@ -3592,5 +3592,7 @@ books/bookvol9 treeshake compiler
books/bookvol9 treeshake compiler, remove compiler.lisp
20110818.02.tpd.patch src/interp/Makefile remove foam_l
+20110824.01.tpd.patch +books/bookvol9 treeshake compiler
diff --git a/src/interp/define.lisp.pamphlet b/src/interp/define.lisp.pamphlet index ce7a9af..94580b8 100644 --- a/src/interp/define.lisp.pamphlet +++ b/src/interp/define.lisp.pamphlet @@ -12,1099 +12,6 @@ \begin{chunk}{*} (IN-PACKAGE "BOOT" ) -;orderByDependency(vl,dl) == -; -- vl is list of variables, dl is list of dependency-lists -; selfDependents:= [v for v in vl for d in dl | MEMQ(v,d)] -; for v in vl for d in dl | MEMQ(v,d) repeat -; (SAY(v," depends on itself"); fatalError:= true) -; fatalError => userError '"Parameter specification error" -; until (null vl) repeat -; newl:= -; [v for v in vl for d in dl | null setIntersection(d,vl)] or return nil -; orderedVarList:= [:newl,:orderedVarList] -; vl':= setDifference(vl,newl) -; dl':= [setDifference(d,newl) for x in vl for d in dl | MEMBER(x,vl')] -; vl:= vl' -; dl:= dl' -; REMDUP NREVERSE orderedVarList --ordered so ith is indep. of jth if i < j - -(DEFUN |orderByDependency| (|vl| |dl|) - (PROG (|selfDependents| |fatalError| |newl| |orderedVarList| |vl'| - |dl'|) - (RETURN - (SEQ (PROGN - (SPADLET |selfDependents| - (PROG (G168215) - (SPADLET G168215 NIL) - (RETURN - (DO ((G168222 |vl| (CDR G168222)) - (|v| NIL) - (G168223 |dl| (CDR G168223)) - (|d| NIL)) - ((OR (ATOM G168222) - (PROGN - (SETQ |v| (CAR G168222)) - NIL) - (ATOM G168223) - (PROGN - (SETQ |d| (CAR G168223)) - NIL)) - (NREVERSE0 G168215)) - (SEQ (EXIT (COND - ((member |v| |d|) - (SETQ G168215 - (CONS |v| G168215)))))))))) - (DO ((G168239 |vl| (CDR G168239)) (|v| NIL) - (G168240 |dl| (CDR G168240)) (|d| NIL)) - ((OR (ATOM G168239) - (PROGN (SETQ |v| (CAR G168239)) NIL) - (ATOM G168240) - (PROGN (SETQ |d| (CAR G168240)) NIL)) - NIL) - (SEQ (EXIT (COND - ((member |v| |d|) - (PROGN - (SAY |v| - " depends on itself") - (SPADLET |fatalError| 'T))))))) - (COND - (|fatalError| - (|userError| - "Parameter specification error")) - ('T - (DO ((G168258 NIL (NULL |vl|))) (G168258 NIL) - (SEQ (EXIT (PROGN - (SPADLET |newl| - (OR - (PROG (G168268) - (SPADLET G168268 NIL) - (RETURN - (DO - ((G168275 |vl| - (CDR G168275)) - (|v| NIL) - (G168276 |dl| - (CDR G168276)) - (|d| NIL)) - ((OR (ATOM G168275) - (PROGN - (SETQ |v| - (CAR G168275)) - NIL) - (ATOM G168276) - (PROGN - (SETQ |d| - (CAR G168276)) - NIL)) - (NREVERSE0 G168268)) - (SEQ - (EXIT - (COND - ((NULL - (|intersection| - |d| |vl|)) - (SETQ G168268 - (CONS |v| - G168268))))))))) - (RETURN NIL))) - (SPADLET |orderedVarList| - (APPEND |newl| - |orderedVarList|)) - (SPADLET |vl'| - (SETDIFFERENCE |vl| |newl|)) - (SPADLET |dl'| - (PROG (G168291) - (SPADLET G168291 NIL) - (RETURN - (DO - ((G168298 |vl| - (CDR G168298)) - (|x| NIL) - (G168299 |dl| - (CDR G168299)) - (|d| NIL)) - ((OR (ATOM G168298) - (PROGN - (SETQ |x| - (CAR G168298)) - NIL) - (ATOM G168299) - (PROGN - (SETQ |d| - (CAR G168299)) - NIL)) - (NREVERSE0 G168291)) - (SEQ - (EXIT - (COND - ((|member| |x| |vl'|) - (SETQ G168291 - (CONS - (SETDIFFERENCE |d| - |newl|) - G168291)))))))))) - (SPADLET |vl| |vl'|) - (SPADLET |dl| |dl'|))))) - (REMDUP (NREVERSE |orderedVarList|))))))))) - -;compInternalFunction(df is ['DEF,form,signature,specialCases,body],m,e) == -; -- $insideExpressionIfTrue:=false -; [op,:argl]:=form -; not(IDENTP(op)) => -; stackAndThrow ["Bad name for internal function:",op] -; #argl=0 => -; stackAndThrow ["Argumentless internal functions unsupported:",op] -; --nf:=["where",["LET",[":",op,["Mapping",:signature]],nbody],_ -; -- :whereList1,:whereList2] -; nbody:=["+->",argl,body] -; nf:=["LET",[":",op,["Mapping",:signature]],nbody] -; ress:=comp(nf,m,e) -; ress - -(DEFUN |compInternalFunction| (|df| |m| |e|) - (PROG (|form| |signature| |specialCases| |body| |op| |argl| |nbody| - |nf| |ress|) - (RETURN - (PROGN - (SPADLET |form| (CADR |df|)) - (SPADLET |signature| (CADDR |df|)) - (SPADLET |specialCases| (CADDDR |df|)) - (SPADLET |body| (CAR (CDDDDR |df|))) - (SPADLET |op| (CAR |form|)) - (SPADLET |argl| (CDR |form|)) - (COND - ((NULL (IDENTP |op|)) - (|stackAndThrow| - (CONS '|Bad name for internal function:| - (CONS |op| NIL)))) - ((EQL (|#| |argl|) 0) - (|stackAndThrow| - (CONS '|Argumentless internal functions unsupported:| - (CONS |op| NIL)))) - ('T - (SPADLET |nbody| - (CONS '+-> (CONS |argl| (CONS |body| NIL)))) - (SPADLET |nf| - (CONS 'LET - (CONS (CONS '|:| - (CONS |op| - (CONS - (CONS '|Mapping| |signature|) - NIL))) - (CONS |nbody| NIL)))) - (SPADLET |ress| (|comp| |nf| |m| |e|)) |ress|)))))) - -;compDefineCapsuleFunction(df is ['DEF,form,signature,specialCases,body], -; m,oldE,$prefix,$formalArgList) == -; [lineNumber,:specialCases] := specialCases -; e := oldE -; --1. bind global variables -; $form: local := nil -; $op: local := nil -; $functionStats: local:= [0,0] -; $argumentConditionList: local := nil -; $finalEnv: local := nil -; --used by ReplaceExitEtc to get a common environment -; $initCapsuleErrorCount: local:= #$semanticErrorStack -; $insideCapsuleFunctionIfTrue: local:= true -; $CapsuleModemapFrame: local:= e -; $CapsuleDomainsInScope: local:= get("$DomainsInScope","special",e) -; $insideExpressionIfTrue: local:= true -; $returnMode:= m -; [$op,:argl]:= form -; $form:= [$op,:argl] -; argl:= stripOffArgumentConditions argl -; $formalArgList:= [:argl,:$formalArgList] -; -; --let target and local signatures help determine modes of arguments -; argModeList:= -; identSig:= hasSigInTargetCategory(argl,form,first signature,e) => -; (e:= checkAndDeclare(argl,form,identSig,e); rest identSig) -; [getArgumentModeOrMoan(a,form,e) for a in argl] -; argModeList:= stripOffSubdomainConditions(argModeList,argl) -; signature':= [first signature,:argModeList] -; if null identSig then --make $op a local function -; oldE := put($op,'mode,['Mapping,:signature'],oldE) -; -; --obtain target type if not given -; if null first signature' then signature':= -; identSig => identSig -; getSignature($op,rest signature',e) or return nil -; e:= giveFormalParametersValues(argl,e) -; -; $signatureOfForm:= signature' --this global is bound in compCapsuleItems -; $functionLocations := [[[$op,$signatureOfForm],:lineNumber], -; :$functionLocations] -; e:= addDomain(first signature',e) -; e:= compArgumentConditions e -; -; if $profileCompiler then -; for x in argl for t in rest signature' repeat profileRecord('arguments,x,t) -; --4. introduce needed domains into extendedEnv -; for domain in signature' repeat e:= addDomain(domain,e) -; -; --6. compile body in environment with extended environment -; rettype:= resolve(signature'.target,$returnMode) -; -; localOrExported := -; null MEMBER($op,$formalArgList) and -; getmode($op,e) is ['Mapping,:.] => 'local -; 'exported -; -; --6a skip if compiling only certain items but not this one -; -- could be moved closer to the top -; formattedSig := formatUnabbreviated ['Mapping,:signature'] -; $compileOnlyCertainItems and _ -; not MEMBER($op, $compileOnlyCertainItems) => -; sayBrightly ['" skipping ", localOrExported,:bright $op] -; [nil,['Mapping,:signature'],oldE] -; sayBrightly ['" compiling ",localOrExported, -; :bright $op,'": ",:formattedSig] -; -; if $newComp = true then -; wholeBody := ['DEF, form, signature', specialCases, body] -; T := CATCH('compCapsuleBody, newComp(wholeBody,$NoValueMode,e)) -; or [" ",rettype,e] -; T := [T.expr.2.2, rettype, T.env] -; if $newCompCompare=true then -; oldT := CATCH('compCapsuleBody, compOrCroak(body,rettype,e)) -; or [" ",rettype,e] -; SAY '"The old compiler generates:" -; prTriple oldT -; SAY '"The new compiler generates:" -; prTriple T -; else -; T := CATCH('compCapsuleBody, compOrCroak(body,rettype,e)) -; or [" ",rettype,e] -;--+ -; NRTassignCapsuleFunctionSlot($op,signature') -; if $newCompCompare=true then -; SAY '"The old compiler generates:" -; prTriple T -;-- A THROW to the above CATCH occurs if too many semantic errors occur -;-- see stackSemanticError -; catchTag:= MKQ GENSYM() -; fun:= -; body':= replaceExitEtc(T.expr,catchTag,"TAGGEDreturn",$returnMode) -; body':= addArgumentConditions(body',$op) -; finalBody:= ["CATCH",catchTag,body'] -; compileCases([$op,["LAM",[:argl,'_$],finalBody]],oldE) -; $functorStats:= addStats($functorStats,$functionStats) -; -; -;-- 7. give operator a 'value property -; val:= [fun,signature',e] -; [fun,['Mapping,:signature'],oldE] -- oldE:= put($op,'value,removeEnv val,e) - -(DEFUN |compDefineCapsuleFunction| - (|df| |m| |oldE| |$prefix| |$formalArgList|) - (DECLARE (SPECIAL |$prefix| |$formalArgList|)) - (PROG (|$form| |$op| |$functionStats| |$argumentConditionList| - |$finalEnv| |$initCapsuleErrorCount| - |$insideCapsuleFunctionIfTrue| |$CapsuleModemapFrame| - |$CapsuleDomainsInScope| |$insideExpressionIfTrue| - |form| |signature| |body| |LETTMP#1| |lineNumber| - |specialCases| |argl| |identSig| |argModeList| - |signature'| |e| |rettype| |ISTMP#1| |localOrExported| - |formattedSig| |wholeBody| |oldT| T$ |catchTag| - |body'| |finalBody| |fun| |val|) - (DECLARE (SPECIAL |$form| |$op| |$functionStats| |$functorStats| - |$argumentConditionList| |$finalEnv| |$returnMode| - |$initCapsuleErrorCount| |$newCompCompare| |$NoValueMode| - |$insideCapsuleFunctionIfTrue| - |$CapsuleModemapFrame| |$CapsuleDomainsInScope| - |$insideExpressionIfTrue| |$compileOnlyCertainItems| - |$profileCompiler| |$functionLocations| |$finalEnv| - |$signatureOfForm| |$semanticErrorStack|)) - (RETURN - (SEQ (PROGN - (SPADLET |form| (CADR |df|)) - (SPADLET |signature| (CADDR |df|)) - (SPADLET |specialCases| (CADDDR |df|)) - (SPADLET |body| (CAR (CDDDDR |df|))) - (SPADLET |LETTMP#1| |specialCases|) - (SPADLET |lineNumber| (CAR |LETTMP#1|)) - (SPADLET |specialCases| (CDR |LETTMP#1|)) - (SPADLET |e| |oldE|) - (SPADLET |$form| NIL) - (SPADLET |$op| NIL) - (SPADLET |$functionStats| (CONS 0 (CONS 0 NIL))) - (SPADLET |$argumentConditionList| NIL) - (SPADLET |$finalEnv| NIL) - (SPADLET |$initCapsuleErrorCount| - (|#| |$semanticErrorStack|)) - (SPADLET |$insideCapsuleFunctionIfTrue| 'T) - (SPADLET |$CapsuleModemapFrame| |e|) - (SPADLET |$CapsuleDomainsInScope| - (|get| '|$DomainsInScope| 'special |e|)) - (SPADLET |$insideExpressionIfTrue| 'T) - (SPADLET |$returnMode| |m|) - (SPADLET |$op| (CAR |form|)) - (SPADLET |argl| (CDR |form|)) - (SPADLET |$form| (CONS |$op| |argl|)) - (SPADLET |argl| (|stripOffArgumentConditions| |argl|)) - (SPADLET |$formalArgList| - (APPEND |argl| |$formalArgList|)) - (SPADLET |argModeList| - (COND - ((SPADLET |identSig| - (|hasSigInTargetCategory| |argl| - |form| (CAR |signature|) |e|)) - (SPADLET |e| - (|checkAndDeclare| |argl| |form| - |identSig| |e|)) - (CDR |identSig|)) - ('T - (PROG (G168401) - (SPADLET G168401 NIL) - (RETURN - (DO ((G168406 |argl| (CDR G168406)) - (|a| NIL)) - ((OR (ATOM G168406) - (PROGN - (SETQ |a| (CAR G168406)) - NIL)) - (NREVERSE0 G168401)) - (SEQ (EXIT - (SETQ G168401 - (CONS - (|getArgumentModeOrMoan| |a| - |form| |e|) - G168401)))))))))) - (SPADLET |argModeList| - (|stripOffSubdomainConditions| |argModeList| - |argl|)) - (SPADLET |signature'| - (CONS (CAR |signature|) |argModeList|)) - (COND - ((NULL |identSig|) - (SPADLET |oldE| - (|put| |$op| '|mode| - (CONS '|Mapping| |signature'|) |oldE|)))) - (COND - ((NULL (CAR |signature'|)) - (SPADLET |signature'| - (COND - (|identSig| |identSig|) - ('T - (OR (|getSignature| |$op| - (CDR |signature'|) |e|) - (RETURN NIL))))))) - (SPADLET |e| (|giveFormalParametersValues| |argl| |e|)) - (SPADLET |$signatureOfForm| |signature'|) - (SPADLET |$functionLocations| - (CONS (CONS (CONS |$op| - (CONS |$signatureOfForm| NIL)) - |lineNumber|) - |$functionLocations|)) - (SPADLET |e| (|addDomain| (CAR |signature'|) |e|)) - (SPADLET |e| (|compArgumentConditions| |e|)) - (COND - (|$profileCompiler| - (DO ((G168416 |argl| (CDR G168416)) (|x| NIL) - (G168417 (CDR |signature'|) (CDR G168417)) - (|t| NIL)) - ((OR (ATOM G168416) - (PROGN (SETQ |x| (CAR G168416)) NIL) - (ATOM G168417) - (PROGN (SETQ |t| (CAR G168417)) NIL)) - NIL) - (SEQ (EXIT (|profileRecord| '|arguments| |x| |t|)))))) - (DO ((G168429 |signature'| (CDR G168429)) - (|domain| NIL)) - ((OR (ATOM G168429) - (PROGN (SETQ |domain| (CAR G168429)) NIL)) - NIL) - (SEQ (EXIT (SPADLET |e| (|addDomain| |domain| |e|))))) - (SPADLET |rettype| - (|resolve| (CAR |signature'|) |$returnMode|)) - (SPADLET |localOrExported| - (COND - ((AND (NULL (|member| |$op| |$formalArgList|)) - (PROGN - (SPADLET |ISTMP#1| - (|getmode| |$op| |e|)) - (AND (PAIRP |ISTMP#1|) - (EQ (QCAR |ISTMP#1|) '|Mapping|)))) - '|local|) - ('T '|exported|))) - (SPADLET |formattedSig| - (|formatUnabbreviated| - (CONS '|Mapping| |signature'|))) - (COND - ((AND |$compileOnlyCertainItems| - (NULL (|member| |$op| |$compileOnlyCertainItems|))) - (|sayBrightly| - (CONS " skipping " - (CONS |localOrExported| (|bright| |$op|)))) - (CONS NIL - (CONS (CONS '|Mapping| |signature'|) - (CONS |oldE| NIL)))) - ('T - (|sayBrightly| - (CONS " compiling " - (CONS |localOrExported| - (APPEND (|bright| |$op|) - (CONS ": " - |formattedSig|))))) - (SPADLET T$ - (OR (CATCH '|compCapsuleBody| - (|compOrCroak| |body| |rettype| |e|)) - (CONS (INTERN " " "BOOT") - (CONS |rettype| (CONS |e| NIL))))) - (|NRTassignCapsuleFunctionSlot| |$op| |signature'|) - (SPADLET |catchTag| (MKQ (GENSYM))) - (SPADLET |fun| - (PROGN - (SPADLET |body'| - (|replaceExitEtc| (CAR T$) - |catchTag| '|TAGGEDreturn| - |$returnMode|)) - (SPADLET |body'| - (|addArgumentConditions| |body'| - |$op|)) - (SPADLET |finalBody| - (CONS 'CATCH - (CONS |catchTag| - (CONS |body'| NIL)))) - (|compileCases| - (CONS |$op| - (CONS - (CONS 'LAM - (CONS - (APPEND |argl| (CONS '$ NIL)) - (CONS |finalBody| NIL))) - NIL)) - |oldE|))) - (SPADLET |$functorStats| - (|addStats| |$functorStats| |$functionStats|)) - (SPADLET |val| - (CONS |fun| - (CONS |signature'| (CONS |e| NIL)))) - (CONS |fun| - (CONS (CONS '|Mapping| |signature'|) - (CONS |oldE| NIL)))))))))) - -;getSignatureFromMode(form,e) == -; getmode(opOf form,e) is ['Mapping,:signature] => -; #form^=#signature => stackAndThrow ["Wrong number of arguments: ",form] -; EQSUBSTLIST(rest form,take(#rest form,$FormalMapVariableList),signature) - -(DEFUN |getSignatureFromMode| (|form| |e|) - (PROG (|ISTMP#1| |signature|) - (declare (special |$FormalMapVariableList|)) - (RETURN - (SEQ (COND - ((PROGN - (SPADLET |ISTMP#1| (|getmode| (|opOf| |form|) |e|)) - (AND (PAIRP |ISTMP#1|) (EQ (QCAR |ISTMP#1|) '|Mapping|) - (PROGN (SPADLET |signature| (QCDR |ISTMP#1|)) 'T))) - (EXIT (COND - ((NEQUAL (|#| |form|) (|#| |signature|)) - (|stackAndThrow| - (CONS '|Wrong number of arguments: | - (CONS |form| NIL)))) - ('T - (EQSUBSTLIST (CDR |form|) - (TAKE (|#| (CDR |form|)) - |$FormalMapVariableList|) - |signature|)))))))))) - -;hasSigInTargetCategory(argl,form,opsig,e) == -; mList:= [getArgumentMode(x,e) for x in argl] -; --each element is a declared mode for the variable or nil if none exists -; potentialSigList:= -; REMDUP -; [sig -; for [[opName,sig,:.],:.] in $domainShell.(1) | -; fn(opName,sig,opsig,mList,form)] where -; fn(opName,sig,opsig,mList,form) == -; opName=$op and #sig=#form and (null opsig or opsig=first sig) and -; (and/[compareMode2Arg(x,m) for x in mList for m in rest sig]) -; c:= #potentialSigList -; 1=c => first potentialSigList -; --accept only those signatures op right length which match declared modes -; 0=c => (#(sig:= getSignatureFromMode(form,e))=#form => sig; nil) -; 1 -; sig:= first potentialSigList -; stackWarning ["signature of lhs not unique:",:bright sig,"chosen"] -; sig -; nil --this branch will force all arguments to be declared - -(DEFUN |hasSigInTargetCategory,fn| (|opName| |sig| |opsig| |mList| |form|) - (PROG () - (declare (special |$op|)) - (RETURN - (SEQ (AND (AND (AND (BOOT-EQUAL |opName| |$op|) - (BOOT-EQUAL (|#| |sig|) (|#| |form|))) - (OR (NULL |opsig|) - (BOOT-EQUAL |opsig| (CAR |sig|)))) - (PROG (G168523) - (SPADLET G168523 'T) - (RETURN - (DO ((G168530 NIL (NULL G168523)) - (G168531 |mList| (CDR G168531)) (|x| NIL) - (G168532 (CDR |sig|) (CDR G168532)) - (|m| NIL)) - ((OR G168530 (ATOM G168531) - (PROGN (SETQ |x| (CAR G168531)) NIL) - (ATOM G168532) - (PROGN (SETQ |m| (CAR G168532)) NIL)) - G168523) - (SEQ (EXIT (SETQ G168523 - (AND G168523 - (|compareMode2Arg| |x| |m|))))))))))))) - -(DEFUN |hasSigInTargetCategory| (|argl| |form| |opsig| |e|) - (PROG (|mList| |opName| |potentialSigList| |c| |sig|) - (declare (special |$domainShell|)) - (RETURN - (SEQ (PROGN - (SPADLET |mList| - (PROG (G168561) - (SPADLET G168561 NIL) - (RETURN - (DO ((G168566 |argl| (CDR G168566)) - (|x| NIL)) - ((OR (ATOM G168566) - (PROGN - (SETQ |x| (CAR G168566)) - NIL)) - (NREVERSE0 G168561)) - (SEQ (EXIT (SETQ G168561 - (CONS - (|getArgumentMode| |x| |e|) - G168561)))))))) - (SPADLET |potentialSigList| - (REMDUP (PROG (G168578) - (SPADLET G168578 NIL) - (RETURN - (DO ((G168585 - (ELT |$domainShell| 1) - (CDR G168585)) - (G168546 NIL)) - ((OR (ATOM G168585) - (PROGN - (SETQ G168546 - (CAR G168585)) - NIL) - (PROGN - (PROGN - (SPADLET |opName| - (CAAR G168546)) - (SPADLET |sig| - (CADAR G168546)) - G168546) - NIL)) - (NREVERSE0 G168578)) - (SEQ - (EXIT - (COND - ((|hasSigInTargetCategory,fn| - |opName| |sig| |opsig| - |mList| |form|) - (SETQ G168578 - (CONS |sig| G168578))))))))))) - (SPADLET |c| (|#| |potentialSigList|)) - (COND - ((EQL 1 |c|) (CAR |potentialSigList|)) - ((EQL 0 |c|) - (COND - ((BOOT-EQUAL - (|#| (SPADLET |sig| - (|getSignatureFromMode| |form| - |e|))) - (|#| |form|)) - |sig|) - ('T NIL))) - ((> |c| 1) (SPADLET |sig| (CAR |potentialSigList|)) - (|stackWarning| - (CONS '|signature of lhs not unique:| - (APPEND (|bright| |sig|) - (CONS '|chosen| NIL)))) - |sig|) - ('T NIL))))))) - -;compareMode2Arg(x,m) == null x or modeEqual(x,m) - -(DEFUN |compareMode2Arg| (|x| |m|) - (OR (NULL |x|) (|modeEqual| |x| |m|))) - -;getArgumentModeOrMoan(x,form,e) == -; getArgumentMode(x,e) or -; stackSemanticError(["argument ",x," of ",form," is not declared"],nil) - -(DEFUN |getArgumentModeOrMoan| (|x| |form| |e|) - (OR (|getArgumentMode| |x| |e|) - (|stackSemanticError| - (CONS '|argument | - (CONS |x| - (CONS '| of | - (CONS |form| - (CONS '| is not declared| NIL))))) - NIL))) - -;getArgumentMode(x,e) == -; STRINGP x => x -; m:= get(x,'mode,e) => m - -(DEFUN |getArgumentMode| (|x| |e|) - (PROG (|m|) - (RETURN - (COND - ((STRINGP |x|) |x|) - ((SPADLET |m| (|get| |x| '|mode| |e|)) |m|))))) - -;checkAndDeclare(argl,form,sig,e) == -; -;-- arguments with declared types must agree with those in sig; -;-- those that don't get declarations put into e -; for a in argl for m in rest sig repeat -; m1:= getArgumentMode(a,e) => -; ^modeEqual(m1,m) => -; stack:= [" ",:bright a,'"must have type ",m, -; '" not ",m1,'%l,:stack] -; e:= put(a,'mode,m,e) -; if stack then -; sayBrightly ['" Parameters of ",:bright first form, -; '" are of wrong type:",'%l,:stack] -; e - -(DEFUN |checkAndDeclare| (|argl| |form| |sig| |e|) - (PROG (|m1| |stack|) - (RETURN - (SEQ (PROGN - (DO ((G168621 |argl| (CDR G168621)) (|a| NIL) - (G168622 (CDR |sig|) (CDR G168622)) (|m| NIL)) - ((OR (ATOM G168621) - (PROGN (SETQ |a| (CAR G168621)) NIL) - (ATOM G168622) - (PROGN (SETQ |m| (CAR G168622)) NIL)) - NIL) - (SEQ (COND - ((SPADLET |m1| (|getArgumentMode| |a| |e|)) - (COND - ((NULL (|modeEqual| |m1| |m|)) - (EXIT (SPADLET |stack| - (CONS '| | - (APPEND (|bright| |a|) - (CONS - "must have type " - (CONS |m| - (CONS " not " - (CONS |m1| - (CONS '|%l| |stack|)))))))))))) - ('T (SPADLET |e| (|put| |a| '|mode| |m| |e|)))))) - (COND - (|stack| (|sayBrightly| - (CONS " Parameters of " - (APPEND (|bright| (CAR |form|)) - (CONS - " are of wrong type:" - (CONS '|%l| |stack|))))))) - |e|))))) - -;getSignature(op,argModeList,$e) == -; --tpd mmList:= get(op,'modemap,$e) -; --tpd for [[dc,:sig],:.] in mmList repeat printSignature(" ",op,sig) -; 1=# -; (sigl:= -; REMDUP -; [sig -; for [[dc,:sig],[pred,:.]] in (mmList:= get(op,'modemap,$e)) | dc='_$ -; and rest sig=argModeList and knownInfo pred]) => first sigl -; null sigl => -; (u:= getmode(op,$e)) is ['Mapping,:sig] => sig -; SAY '"************* USER ERROR **********" -; SAY("available signatures for ",op,": ") -; if null mmList -; then SAY " NONE" -; else for [[dc,:sig],:.] in mmList repeat printSignature(" ",op,sig) -; printSignature("NEED ",op,["?",:argModeList]) -; nil -; for u in sigl repeat -; for v in sigl | not (u=v) repeat -; if SourceLevelSubsume(u,v) then sigl:= DELETE(v,sigl) -; --before we complain about duplicate signatures, we should -; --check that we do not have for example, a partial - as -; --well as a total one. SourceLevelSubsume (from CATEGORY BOOT) -; --should do this -; 1=#sigl => first sigl -; stackSemanticError(["duplicate signatures for ",op,": ",argModeList],nil) - -(DEFUN |getSignature| (|op| |argModeList| |$e|) - (DECLARE (SPECIAL |$e|)) - (PROG (|mmList| |pred| |u| |ISTMP#1| |dc| |sig| |sigl|) - (RETURN - (SEQ (COND - ((EQL 1 - (|#| (SPADLET |sigl| - (REMDUP (PROG (G168658) - (SPADLET G168658 NIL) - (RETURN - (DO - ((G168665 - (SPADLET |mmList| - (|get| |op| '|modemap| - |$e|)) - (CDR G168665)) - (G168637 NIL)) - ((OR (ATOM G168665) - (PROGN - (SETQ G168637 - (CAR G168665)) - NIL) - (PROGN - (PROGN - (SPADLET |dc| - (CAAR G168637)) - (SPADLET |sig| - (CDAR G168637)) - (SPADLET |pred| - (CAADR G168637)) - G168637) - NIL)) - (NREVERSE0 G168658)) - (SEQ - (EXIT - (COND - ((AND - (BOOT-EQUAL |dc| - '$) - (BOOT-EQUAL - (CDR |sig|) - |argModeList|) - (|knownInfo| - |pred|)) - (SETQ G168658 - (CONS |sig| - G168658))))))))))))) - (CAR |sigl|)) - ((NULL |sigl|) - (COND - ((PROGN - (SPADLET |ISTMP#1| - (SPADLET |u| (|getmode| |op| |$e|))) - (AND (PAIRP |ISTMP#1|) - (EQ (QCAR |ISTMP#1|) '|Mapping|) - (PROGN (SPADLET |sig| (QCDR |ISTMP#1|)) 'T))) - |sig|) - ('T - (SAY "************* USER ERROR **********") - (SAY "available signatures for " |op| - ": ") - (COND - ((NULL |mmList|) (SAY " NONE")) - ('T - (DO ((G168676 |mmList| (CDR G168676)) - (G168646 NIL)) - ((OR (ATOM G168676) - (PROGN - (SETQ G168646 (CAR G168676)) - NIL) - (PROGN - (PROGN - (SPADLET |dc| (CAAR G168646)) - (SPADLET |sig| (CDAR G168646)) - G168646) - NIL)) - NIL) - (SEQ (EXIT (|printSignature| '| | |op| |sig|)))))) - (|printSignature| '|NEED | |op| - (CONS '? |argModeList|)) - NIL))) - ('T - (DO ((G168686 |sigl| (CDR G168686)) (|u| NIL)) - ((OR (ATOM G168686) - (PROGN (SETQ |u| (CAR G168686)) NIL)) - NIL) - (SEQ (EXIT (DO ((G168696 |sigl| (CDR G168696)) - (|v| NIL)) - ((OR (ATOM G168696) - (PROGN - (SETQ |v| (CAR G168696)) - NIL)) - NIL) - (SEQ (EXIT (COND - ((NULL (BOOT-EQUAL |u| |v|)) - (COND - ((|SourceLevelSubsume| |u| - |v|) - (SPADLET |sigl| - (|delete| |v| |sigl|))) - ('T NIL)))))))))) - (COND - ((EQL 1 (|#| |sigl|)) (CAR |sigl|)) - ('T - (|stackSemanticError| - (CONS '|duplicate signatures for | - (CONS |op| - (CONS '|: | (CONS |argModeList| NIL)))) - NIL))))))))) - -;--% ARGUMENT CONDITION CODE -; -;stripOffArgumentConditions argl == -; [f for x in argl for i in 1..] where -; f() == -; x is ["|",arg,condition] => -; condition:= SUBST('_#1,arg,condition) -; -- in case conditions are given in terms of argument names, replace -; $argumentConditionList:= [[i,arg,condition],:$argumentConditionList] -; arg -; x - -(DEFUN |stripOffArgumentConditions| (|argl|) - (PROG (|ISTMP#1| |arg| |ISTMP#2| |condition|) - (declare (special |$argumentConditionList|)) - (RETURN - (SEQ (PROG (G168756) - (SPADLET G168756 NIL) - (RETURN - (DO ((G168769 |argl| (CDR G168769)) (|x| NIL) - (|i| 1 (QSADD1 |i|))) - ((OR (ATOM G168769) - (PROGN (SETQ |x| (CAR G168769)) NIL)) - (NREVERSE0 G168756)) - (SEQ (EXIT (SETQ G168756 - (CONS (COND - ((AND (PAIRP |x|) - (EQ (QCAR |x|) '|\||) - (PROGN - (SPADLET |ISTMP#1| - (QCDR |x|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |arg| - (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| - (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (EQ (QCDR |ISTMP#2|) - NIL) - (PROGN - (SPADLET - |condition| - (QCAR |ISTMP#2|)) - 'T)))))) - (SPADLET |condition| - (MSUBST '|#1| |arg| - |condition|)) - (SPADLET - |$argumentConditionList| - (CONS - (CONS |i| - (CONS |arg| - (CONS |condition| NIL))) - |$argumentConditionList|)) - |arg|) - ('T |x|)) - G168756))))))))))) - -;stripOffSubdomainConditions(margl,argl) == -; [f for x in margl for arg in argl for i in 1..] where -; f == -; x is ['SubDomain,marg,condition] => -; pair:= ASSOC(i,$argumentConditionList) => -; (RPLAC(CADR pair,MKPF([condition,CADR pair],'AND)); marg) -; $argumentConditionList:= [[i,arg,condition],:$argumentConditionList] -; marg -; x - -(DEFUN |stripOffSubdomainConditions| (|margl| |argl|) - (PROG (|ISTMP#1| |marg| |ISTMP#2| |condition| |pair|) - (declare (special |$argumentConditionList|)) - (RETURN - (SEQ (PROG (G168825) - (SPADLET G168825 NIL) - (RETURN - (DO ((G168839 |margl| (CDR G168839)) (|x| NIL) - (G168840 |argl| (CDR G168840)) (|arg| NIL) - (|i| 1 (QSADD1 |i|))) - ((OR (ATOM G168839) - (PROGN (SETQ |x| (CAR G168839)) NIL) - (ATOM G168840) - (PROGN (SETQ |arg| (CAR G168840)) NIL)) - (NREVERSE0 G168825)) - (SEQ (EXIT (SETQ G168825 - (CONS (COND - ((AND (PAIRP |x|) - (EQ (QCAR |x|) - '|SubDomain|) - (PROGN - (SPADLET |ISTMP#1| - (QCDR |x|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |marg| - (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| - (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (EQ (QCDR |ISTMP#2|) - NIL) - (PROGN - (SPADLET - |condition| - (QCAR |ISTMP#2|)) - 'T)))))) - (COND - ((SPADLET |pair| - (|assoc| |i| - |$argumentConditionList|)) - (RPLAC (CADR |pair|) - (MKPF - (CONS |condition| - (CONS (CADR |pair|) - NIL)) - 'AND)) - |marg|) - ('T - (SPADLET - |$argumentConditionList| - (CONS - (CONS |i| - (CONS |arg| - (CONS |condition| - NIL))) - |$argumentConditionList|)) - |marg|))) - ('T |x|)) - G168825))))))))))) - -;compArgumentConditions e == -; $argumentConditionList:= -; [f for [n,a,x] in $argumentConditionList] where -; f == -; y:= SUBST(a,'_#1,x) -; T := [.,.,e]:= compOrCroak(y,$Boolean,e) -; [n,x,T.expr] -; e - -(DEFUN |compArgumentConditions| (|e|) - (PROG (|n| |a| |x| |y| |LETTMP#1| T$) - (declare (special |$Boolean| |$argumentConditionList|)) - (RETURN - (SEQ (PROGN - (SPADLET |$argumentConditionList| - (PROG (G168890) - (SPADLET G168890 NIL) - (RETURN - (DO ((G168902 |$argumentConditionList| - (CDR G168902)) - (G168865 NIL)) - ((OR (ATOM G168902) - (PROGN - (SETQ G168865 (CAR G168902)) - NIL) - (PROGN - (PROGN - (SPADLET |n| (CAR G168865)) - (SPADLET |a| (CADR G168865)) - (SPADLET |x| (CADDR G168865)) - G168865) - NIL)) - (NREVERSE0 G168890)) - (SEQ (EXIT (SETQ G168890 - (CONS - (PROGN - (SPADLET |y| - (MSUBST |a| '|#1| |x|)) - (SPADLET T$ - (PROGN - (SPADLET |LETTMP#1| - (|compOrCroak| |y| - |$Boolean| |e|)) - (SPADLET |e| - (CADDR |LETTMP#1|)) - |LETTMP#1|)) - (CONS |n| - (CONS |x| - (CONS (CAR T$) NIL)))) - G168890)))))))) - |e|))))) - -;addArgumentConditions($body,$functionName) == -; $argumentConditionList => -; --$body is only used in this function -; fn $argumentConditionList where -; fn clist == -; clist is [[n,untypedCondition,typedCondition],:.] => -; ['COND,[typedCondition,fn rest clist], -; [$true,["argumentDataError",n, -; MKQ untypedCondition,MKQ $functionName]]] -; null clist => $body -; systemErrorHere '"addArgumentConditions" -; $body - -(DEFUN |addArgumentConditions,fn| (|clist|) - (PROG (|ISTMP#1| |n| |ISTMP#2| |untypedCondition| |ISTMP#3| |typedCondition|) - (declare (special |$body| |$functionName| |$true|)) - (RETURN - (SEQ (IF (AND (PAIRP |clist|) - (PROGN - (SPADLET |ISTMP#1| (QCAR |clist|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |n| (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (PROGN - (SPADLET |untypedCondition| - (QCAR |ISTMP#2|)) - (SPADLET |ISTMP#3| - (QCDR |ISTMP#2|)) - (AND (PAIRP |ISTMP#3|) - (EQ (QCDR |ISTMP#3|) NIL) - (PROGN - (SPADLET |typedCondition| - (QCAR |ISTMP#3|)) - 'T)))))))) - (EXIT (CONS 'COND - (CONS (CONS |typedCondition| - (CONS - (|addArgumentConditions,fn| - (CDR |clist|)) - NIL)) - (CONS (CONS |$true| - (CONS - (CONS '|argumentDataError| - (CONS |n| - (CONS - (MKQ |untypedCondition|) - (CONS (MKQ |$functionName|) - NIL)))) - NIL)) - NIL))))) - (IF (NULL |clist|) (EXIT |$body|)) - (EXIT (|systemErrorHere| - "addArgumentConditions")))))) - -(DEFUN |addArgumentConditions| (|$body| |$functionName|) - (DECLARE (SPECIAL |$body| |$functionName| |$argumentConditionList|)) - (COND - (|$argumentConditionList| - (|addArgumentConditions,fn| |$argumentConditionList|)) - ('T |$body|))) - -;putInLocalDomainReferences (def := [opName,[lam,varl,body]]) == -; $elt: local := ($QuickCode => 'QREFELT; 'ELT) -;--+ -; NRTputInTail CDDADR def -; def - -(DEFUN |putInLocalDomainReferences| (|def|) - (PROG (|$elt| |opName| |lam| |varl| |body|) - (DECLARE (SPECIAL |$elt| |$QuickCode|)) - (RETURN - (PROGN - (SPADLET |opName| (CAR |def|)) - (SPADLET |lam| (CAADR |def|)) - (SPADLET |varl| (CADADR |def|)) - (SPADLET |body| (CAR (CDDADR |def|))) - (SPADLET |$elt| (COND (|$QuickCode| 'QREFELT) ('T 'ELT))) - (|NRTputInTail| (CDDADR |def|)) - |def|)))) ;canCacheLocalDomain(dom,elt)== ; dom is [op,'_$,n] and MEMQ(op,'(ELT QREFELT)) => nil @@ -1174,767 +81,6 @@ (SPADLET |$funcLocLen| (PLUS |$funcLocLen| 1))) ('T NIL))))) -;compileCases(x,$e) == -- $e is referenced in compile -; $specialCaseKeyList: local := nil -; not ($insideFunctorIfTrue=true) => compile x -; specialCaseAssoc:= -; [y for y in getSpecialCaseAssoc() | not get(first y,"specialCase",$e) and -; ([R,R']:= y) and isEltArgumentIn(FindNamesFor(R,R'),x)] where -; FindNamesFor(R,R') == -; [R,: -; [v -; for ['LET,v,u,:.] in $getDomainCode | CADR u=R and -; eval substitute(R',R,u)]] -; isEltArgumentIn(Rlist,x) == -; atom x => nil -; x is ['ELT,R,.] => MEMQ(R,Rlist) or isEltArgumentIn(Rlist,rest x) -; x is ["QREFELT",R,.] => MEMQ(R,Rlist) or isEltArgumentIn(Rlist,rest x) -; isEltArgumentIn(Rlist,first x) or isEltArgumentIn(Rlist,rest x) -; null specialCaseAssoc => compile x -; listOfDomains:= ASSOCLEFT specialCaseAssoc -; listOfAllCases:= outerProduct ASSOCRIGHT specialCaseAssoc -; cl:= -; [u for l in listOfAllCases] where -; u() == -; $specialCaseKeyList:= [[D,:C] for D in listOfDomains for C in l] -; [MKPF([["EQUAL",D,C] for D in listOfDomains for C in l],"AND"), -; compile COPY x] -; $specialCaseKeyList:= nil -; ["COND",:cl,[$true,compile x]] - -(DEFUN |compileCases,isEltArgumentIn| (|Rlist| |x|) - (PROG (|ISTMP#1| R |ISTMP#2|) - (RETURN - (SEQ (IF (ATOM |x|) (EXIT NIL)) - (IF (AND (PAIRP |x|) (EQ (QCAR |x|) 'ELT) - (PROGN - (SPADLET |ISTMP#1| (QCDR |x|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET R (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (EQ (QCDR |ISTMP#2|) NIL)))))) - (EXIT (OR (member R |Rlist|) - (|compileCases,isEltArgumentIn| |Rlist| - (CDR |x|))))) - (IF (AND (PAIRP |x|) (EQ (QCAR |x|) 'QREFELT) - (PROGN - (SPADLET |ISTMP#1| (QCDR |x|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET R (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (EQ (QCDR |ISTMP#2|) NIL)))))) - (EXIT (OR (member R |Rlist|) - (|compileCases,isEltArgumentIn| |Rlist| - (CDR |x|))))) - (EXIT (OR (|compileCases,isEltArgumentIn| |Rlist| (CAR |x|)) - (|compileCases,isEltArgumentIn| |Rlist| (CDR |x|)))))))) - -(DEFUN |compileCases,FindNamesFor| (R |R'|) - (PROG (|v| |u|) - (declare (special |$getDomainCode|)) - (RETURN - (SEQ (CONS R - (PROG (G169091) - (SPADLET G169091 NIL) - (RETURN - (DO ((G169098 |$getDomainCode| (CDR G169098)) - (G169051 NIL)) - ((OR (ATOM G169098) - (PROGN - (SETQ G169051 (CAR G169098)) - NIL) - (PROGN - (PROGN - (SPADLET |v| (CADR G169051)) - (SPADLET |u| (CADDR G169051)) - G169051) - NIL)) - (NREVERSE0 G169091)) - (SEQ (EXIT (COND - ((AND (BOOT-EQUAL (CADR |u|) R) - (|eval| (MSUBST |R'| R |u|))) - (SETQ G169091 - (CONS |v| G169091)))))))))))))) - -(DEFUN |compileCases| (|x| |$e|) - (DECLARE (SPECIAL |$e|)) - (PROG (|$specialCaseKeyList| R |R'| |specialCaseAssoc| - |listOfDomains| |listOfAllCases| |cl|) - (DECLARE (SPECIAL |$specialCaseKeyList| |$true| |$insideFunctorIfTrue|)) - (RETURN - (SEQ (PROGN - (SPADLET |$specialCaseKeyList| NIL) - (COND - ((NULL (BOOT-EQUAL |$insideFunctorIfTrue| 'T)) - (|compile| |x|)) - ('T - (SPADLET |specialCaseAssoc| - (PROG (G169126) - (SPADLET G169126 NIL) - (RETURN - (DO ((G169132 (|getSpecialCaseAssoc|) - (CDR G169132)) - (|y| NIL)) - ((OR (ATOM G169132) - (PROGN - (SETQ |y| (CAR G169132)) - NIL)) - (NREVERSE0 G169126)) - (SEQ (EXIT - (COND - ((AND - (NULL - (|get| (CAR |y|) - '|specialCase| |$e|)) - (PROGN - (SPADLET R (CAR |y|)) - (SPADLET |R'| (CADR |y|)) - |y|) - (|compileCases,isEltArgumentIn| - (|compileCases,FindNamesFor| - R |R'|) - |x|)) - (SETQ G169126 - (CONS |y| G169126)))))))))) - (COND - ((NULL |specialCaseAssoc|) (|compile| |x|)) - ('T - (SPADLET |listOfDomains| - (ASSOCLEFT |specialCaseAssoc|)) - (SPADLET |listOfAllCases| - (|outerProduct| - (ASSOCRIGHT |specialCaseAssoc|))) - (SPADLET |cl| - (PROG (G169144) - (SPADLET G169144 NIL) - (RETURN - (DO ((G169151 |listOfAllCases| - (CDR G169151)) - (|l| NIL)) - ((OR (ATOM G169151) - (PROGN - (SETQ |l| (CAR G169151)) - NIL)) - (NREVERSE0 G169144)) - (SEQ (EXIT - (SETQ G169144 - (CONS - (PROGN - (SPADLET - |$specialCaseKeyList| - (PROG (G169162) - (SPADLET G169162 NIL) - (RETURN - (DO - ((G169168 - |listOfDomains| - (CDR G169168)) - (D NIL) - (G169169 |l| - (CDR G169169)) - (C NIL)) - ((OR (ATOM G169168) - (PROGN - (SETQ D - (CAR G169168)) - NIL) - (ATOM G169169) - (PROGN - (SETQ C - (CAR G169169)) - NIL)) - (NREVERSE0 - G169162)) - (SEQ - (EXIT - (SETQ G169162 - (CONS (CONS D C) - G169162)))))))) - (CONS - (MKPF - (PROG (G169183) - (SPADLET G169183 NIL) - (RETURN - (DO - ((G169189 - |listOfDomains| - (CDR G169189)) - (D NIL) - (G169190 |l| - (CDR G169190)) - (C NIL)) - ((OR - (ATOM G169189) - (PROGN - (SETQ D - (CAR G169189)) - NIL) - (ATOM G169190) - (PROGN - (SETQ C - (CAR G169190)) - NIL)) - (NREVERSE0 - G169183)) - (SEQ - (EXIT - (SETQ G169183 - (CONS - (CONS 'EQUAL - (CONS D - (CONS C NIL))) - G169183))))))) - 'AND) - (CONS - (|compile| (COPY |x|)) - NIL))) - G169144)))))))) - (SPADLET |$specialCaseKeyList| NIL) - (CONS 'COND - (APPEND |cl| - (CONS (CONS |$true| - (CONS (|compile| |x|) NIL)) - NIL)))))))))))) - -;getSpecialCaseAssoc() == -; [[R,:l] for R in rest $functorForm -; for l in rest $functorSpecialCases | l] - -(DEFUN |getSpecialCaseAssoc| () - (PROG () - (declare (special |$functorSpecialCases| |$functorForm|)) - (RETURN - (SEQ (PROG (G169224) - (SPADLET G169224 NIL) - (RETURN - (DO ((G169231 (CDR |$functorForm|) (CDR G169231)) - (R NIL) - (G169232 (CDR |$functorSpecialCases|) - (CDR G169232)) - (|l| NIL)) - ((OR (ATOM G169231) - (PROGN (SETQ R (CAR G169231)) NIL) - (ATOM G169232) - (PROGN (SETQ |l| (CAR G169232)) NIL)) - (NREVERSE0 G169224)) - (SEQ (EXIT (COND - (|l| (SETQ G169224 - (CONS (CONS R |l|) G169224))))))))))))) - -;compile u == -; [op,lamExpr] := u -; if $suffix then -; $suffix:= $suffix+1 -; op':= -; opexport:=nil -; opmodes:= -; [sel -; for [[DC,:sig],[.,sel]] in get(op,'modemap,$e) | -; DC='_$ and (opexport:=true) and -; (and/[modeEqual(x,y) for x in sig for y in $signatureOfForm])] -; isLocalFunction op => -; if opexport then userError ['%b,op,'%d,'" is local and exported"] -; INTERN STRCONC(encodeItem $prefix,'";",encodeItem op) where -; isLocalFunction op == -; null MEMBER(op,$formalArgList) and -; getmode(op,$e) is ['Mapping,:.] -; isPackageFunction() and KAR $functorForm^="CategoryDefaults" => -; if null opmodes then userError ['"no modemap for ",op] -; opmodes is [['PAC,.,name]] => name -; encodeFunctionName(op,$functorForm,$signatureOfForm,";",$suffix) -; encodeFunctionName(op,$functorForm,$signatureOfForm,";",$suffix) -; u:= [op',lamExpr] -; -- If just updating certain functions, check for previous existence. -; -- Deduce old sequence number and use it (items have been skipped). -; if $LISPLIB and $compileOnlyCertainItems then -; parts := splitEncodedFunctionName(u.0, ";") -;-- Next line JHD/SMWATT 7/17/86 to deal with inner functions -; parts='inner => $savableItems:=[u.0,:$savableItems] -; unew := nil -; for [s,t] in $splitUpItemsAlreadyThere repeat -; if parts.0=s.0 and parts.1=s.1 and parts.2=s.2 then unew := t -; null unew => -; sayBrightly ['" Error: Item did not previously exist"] -; sayBrightly ['" Item not saved: ", :bright u.0] -; sayBrightly ['" What's there is: ", $lisplibItemsAlreadyThere] -; nil -; sayBrightly ['" Renaming ", u.0, '" as ", unew] -; u := [unew, :rest u] -; $savableItems := [unew, :$saveableItems] -- tested by embedded RWRITE -; optimizedBody:= optimizeFunctionDef u -; stuffToCompile:= -; if null $insideCapsuleFunctionIfTrue -; then optimizedBody -; else putInLocalDomainReferences optimizedBody -; $doNotCompileJustPrint=true => (PRETTYPRINT stuffToCompile; op') -; $macroIfTrue => constructMacro stuffToCompile -; result:= spadCompileOrSetq stuffToCompile -; functionStats:=[0,elapsedTime()] -; $functionStats:= addStats($functionStats,functionStats) -; printStats functionStats -; result - -(DEFUN |compile,isLocalFunction| (|op|) - (PROG (|ISTMP#1|) - (declare (special |$e| |$formalArgList|)) - (RETURN - (AND (NULL (|member| |op| |$formalArgList|)) - (PROGN - (SPADLET |ISTMP#1| (|getmode| |op| |$e|)) - (AND (PAIRP |ISTMP#1|) (EQ (QCAR |ISTMP#1|) '|Mapping|))))))) - -(DEFUN |compile| (|u|) - (PROG (|op| |lamExpr| DC |sig| |sel| |opexport| |opmodes| |ISTMP#1| - |ISTMP#2| |ISTMP#3| |name| |op'| |parts| |s| |t| |unew| - |optimizedBody| |stuffToCompile| |result| - |functionStats|) - (declare (special |$functionStats| |$macroIfTrue| |$doNotCompileJustPrint| - |$insideCapsuleFunctionIfTrue| |$saveableItems| |$e| - |$lisplibItemsAlreadyThere| |$splitUpItemsAlreadyThere| - |$compileOnlyCertainItems| $LISPLIB |$suffix| - |$signatureOfForm| |$functorForm| |$prefix| - |$savableItems|)) - (RETURN - (SEQ (PROGN - (SPADLET |op| (CAR |u|)) - (SPADLET |lamExpr| (CADR |u|)) - (COND - (|$suffix| (SPADLET |$suffix| (PLUS |$suffix| 1)) - (SPADLET |op'| - (PROGN - (SPADLET |opexport| NIL) - (SPADLET |opmodes| - (PROG (G169296) - (SPADLET G169296 NIL) - (RETURN - (DO - ((G169303 - (|get| |op| '|modemap| - |$e|) - (CDR G169303)) - (G169248 NIL)) - ((OR (ATOM G169303) - (PROGN - (SETQ G169248 - (CAR G169303)) - NIL) - (PROGN - (PROGN - (SPADLET DC - (CAAR G169248)) - (SPADLET |sig| - (CDAR G169248)) - (SPADLET |sel| - (CADADR G169248)) - G169248) - NIL)) - (NREVERSE0 G169296)) - (SEQ - (EXIT - (COND - ((AND - (BOOT-EQUAL DC '$) - (SPADLET |opexport| - 'T) - (PROG (G169310) - (SPADLET G169310 - 'T) - (RETURN - (DO - ((G169317 NIL - (NULL - G169310)) - (G169318 - |sig| - (CDR - G169318)) - (|x| NIL) - (G169319 - |$signatureOfForm| - (CDR - G169319)) - (|y| NIL)) - ((OR G169317 - (ATOM - G169318) - (PROGN - (SETQ |x| - (CAR - G169318)) - NIL) - (ATOM - G169319) - (PROGN - (SETQ |y| - (CAR - G169319)) - NIL)) - G169310) - (SEQ - (EXIT - (SETQ - G169310 - (AND - G169310 - (|modeEqual| - |x| |y|))))))))) - (SETQ G169296 - (CONS |sel| - G169296)))))))))) - (COND - ((|compile,isLocalFunction| |op|) - (COND - (|opexport| - (|userError| - (CONS '|%b| - (CONS |op| - (CONS '|%d| - (CONS - " is local and exported" - NIL))))))) - (INTERN (STRCONC - (|encodeItem| |$prefix|) - ";" - (|encodeItem| |op|)))) - ((AND (|isPackageFunction|) - (NEQUAL (KAR |$functorForm|) - '|CategoryDefaults|)) - (COND - ((NULL |opmodes|) - (|userError| - (CONS - "no modemap for " - (CONS |op| NIL))))) - (COND - ((AND (PAIRP |opmodes|) - (EQ (QCDR |opmodes|) NIL) - (PROGN - (SPADLET |ISTMP#1| - (QCAR |opmodes|)) - (AND (PAIRP |ISTMP#1|) - (EQ (QCAR |ISTMP#1|) 'PAC) - (PROGN - (SPADLET |ISTMP#2| - (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (PROGN - (SPADLET |ISTMP#3| - (QCDR |ISTMP#2|)) - (AND (PAIRP |ISTMP#3|) - (EQ (QCDR |ISTMP#3|) NIL) - (PROGN - (SPADLET |name| - (QCAR |ISTMP#3|)) - 'T)))))))) - |name|) - ('T - (|encodeFunctionName| |op| - |$functorForm| |$signatureOfForm| - '|;| |$suffix|)))) - ('T - (|encodeFunctionName| |op| - |$functorForm| |$signatureOfForm| - '|;| |$suffix|))))) - (SPADLET |u| (CONS |op'| (CONS |lamExpr| NIL))))) - (COND - ((AND $LISPLIB |$compileOnlyCertainItems|) - (SPADLET |parts| - (|splitEncodedFunctionName| (ELT |u| 0) '|;|)) - (COND - ((BOOT-EQUAL |parts| '|inner|) - (SPADLET |$savableItems| - (CONS (ELT |u| 0) |$savableItems|))) - ('T (SPADLET |unew| NIL) - (DO ((G169333 |$splitUpItemsAlreadyThere| - (CDR G169333)) - (G169282 NIL)) - ((OR (ATOM G169333) - (PROGN - (SETQ G169282 (CAR G169333)) - NIL) - (PROGN - (PROGN - (SPADLET |s| (CAR G169282)) - (SPADLET |t| (CADR G169282)) - G169282) - NIL)) - NIL) - (SEQ (EXIT (COND - ((AND - (BOOT-EQUAL (ELT |parts| 0) - (ELT |s| 0)) - (BOOT-EQUAL (ELT |parts| 1) - (ELT |s| 1)) - (BOOT-EQUAL (ELT |parts| 2) - (ELT |s| 2))) - (SPADLET |unew| |t|)) - ('T NIL))))) - (COND - ((NULL |unew|) - (|sayBrightly| - (CONS " Error: Item did not previously exist" - NIL)) - (|sayBrightly| - (CONS " Item not saved: " - (|bright| (ELT |u| 0)))) - (|sayBrightly| - (CONS " What's there is: " - (CONS |$lisplibItemsAlreadyThere| NIL))) - NIL) - ('T - (|sayBrightly| - (CONS " Renaming " - (CONS (ELT |u| 0) - (CONS " as " - (CONS |unew| NIL))))) - (SPADLET |u| (CONS |unew| (CDR |u|))) - (SPADLET |$savableItems| - (CONS |unew| |$saveableItems|)))))))) - (SPADLET |optimizedBody| (|optimizeFunctionDef| |u|)) - (SPADLET |stuffToCompile| - (COND - ((NULL |$insideCapsuleFunctionIfTrue|) - |optimizedBody|) - ('T - (|putInLocalDomainReferences| |optimizedBody|)))) - (COND - ((BOOT-EQUAL |$doNotCompileJustPrint| 'T) - (PRETTYPRINT |stuffToCompile|) |op'|) - (|$macroIfTrue| (|constructMacro| |stuffToCompile|)) - ('T - (SPADLET |result| - (|spadCompileOrSetq| |stuffToCompile|)) - (SPADLET |functionStats| - (CONS 0 (CONS (|elapsedTime|) NIL))) - (SPADLET |$functionStats| - (|addStats| |$functionStats| |functionStats|)) - (|printStats| |functionStats|) |result|))))))) - -;spadCompileOrSetq (form is [nam,[lam,vl,body]]) == -; --bizarre hack to take account of the existence of "known" functions -; --good for performance (LISPLLIB size, BPI size, NILSEC) -; CONTAINED(" ",body) => sayBrightly ['" ",:bright nam,'" not compiled"] -; if vl is [:vl',E] and body is [nam',: =vl'] then -; LAM_,EVALANDFILEACTQ ['PUT,MKQ nam,MKQ 'SPADreplace,MKQ nam'] -; sayBrightly ['" ",:bright nam,'"is replaced by",:bright nam'] -; else if (ATOM body or and/[ATOM x for x in body]) -; and vl is [:vl',E] and not CONTAINED(E,body) then -; macform := ['XLAM,vl',body] -; LAM_,EVALANDFILEACTQ ['PUT,MKQ nam,MKQ 'SPADreplace,MKQ macform] -; sayBrightly ['" ",:bright nam,'"is replaced by",:bright body] -; $insideCapsuleFunctionIfTrue => first COMP LIST form -; compileConstructor form - -(DEFUN |spadCompileOrSetq| (|form|) - (PROG (|nam| |lam| |vl| |body| |nam'| |ISTMP#1| E |vl'| |macform|) - (declare (special |$insideCapsuleFunctionIfTrue|)) - (RETURN - (SEQ (PROGN - (SPADLET |nam| (CAR |form|)) - (SPADLET |lam| (CAADR |form|)) - (SPADLET |vl| (CADADR |form|)) - (SPADLET |body| (CAR (CDDADR |form|))) - (COND - ((CONTAINED (INTERN " " "BOOT") |body|) - (|sayBrightly| - (CONS " " - (APPEND (|bright| |nam|) - (CONS " not compiled" - NIL))))) - ('T - (COND - ((AND (PAIRP |vl|) - (PROGN (SPADLET |ISTMP#1| (REVERSE |vl|)) 'T) - (PAIRP |ISTMP#1|) - (PROGN - (SPADLET E (QCAR |ISTMP#1|)) - (SPADLET |vl'| (QCDR |ISTMP#1|)) - 'T) - (PROGN (SPADLET |vl'| (NREVERSE |vl'|)) 'T) - (PAIRP |body|) - (PROGN (SPADLET |nam'| (QCAR |body|)) 'T) - (EQUAL (QCDR |body|) |vl'|)) - (|LAM,EVALANDFILEACTQ| - (CONS 'PUT - (CONS (MKQ |nam|) - (CONS (MKQ '|SPADreplace|) - (CONS (MKQ |nam'|) NIL))))) - (|sayBrightly| - (CONS " " - (APPEND (|bright| |nam|) - (CONS - "is replaced by" - (|bright| |nam'|)))))) - ((AND (OR (ATOM |body|) - (PROG (G169410) - (SPADLET G169410 'T) - (RETURN - (DO ((G169416 NIL (NULL G169410)) - (G169417 |body| (CDR G169417)) - (|x| NIL)) - ((OR G169416 (ATOM G169417) - (PROGN - (SETQ |x| (CAR G169417)) - NIL)) - G169410) - (SEQ (EXIT - (SETQ G169410 - (AND G169410 (ATOM |x|))))))))) - (PAIRP |vl|) - (PROGN (SPADLET |ISTMP#1| (REVERSE |vl|)) 'T) - (PAIRP |ISTMP#1|) - (PROGN - (SPADLET E (QCAR |ISTMP#1|)) - (SPADLET |vl'| (QCDR |ISTMP#1|)) - 'T) - (PROGN (SPADLET |vl'| (NREVERSE |vl'|)) 'T) - (NULL (CONTAINED E |body|))) - (SPADLET |macform| - (CONS 'XLAM (CONS |vl'| (CONS |body| NIL)))) - (|LAM,EVALANDFILEACTQ| - (CONS 'PUT - (CONS (MKQ |nam|) - (CONS (MKQ '|SPADreplace|) - (CONS (MKQ |macform|) NIL))))) - (|sayBrightly| - (CONS " " - (APPEND (|bright| |nam|) - (CONS - "is replaced by" - (|bright| |body|)))))) - ('T NIL)) - (COND - (|$insideCapsuleFunctionIfTrue| - (CAR (COMP (LIST |form|)))) - ('T (|compileConstructor| |form|)))))))))) - -;compileConstructor form == -; u:= compileConstructor1 form -; clearClams() --clear all CLAMmed functions -; u - -(DEFUN |compileConstructor| (|form|) - (PROG (|u|) - (RETURN - (PROGN - (SPADLET |u| (|compileConstructor1| |form|)) - (|clearClams|) - |u|)))) - -;compileConstructor1 (form:=[fn,[key,vl,:bodyl]]) == -;-- fn is the name of some category/domain/package constructor; -;-- we will cache all of its values on $ConstructorCache with reference -;-- counts -; $clamList: local := nil -; lambdaOrSlam := -; GETDATABASE(fn,'CONSTRUCTORKIND) = 'category => 'SPADSLAM -; $mutableDomain => 'LAMBDA -; $clamList:= -; [[fn,"$ConstructorCache",'domainEqualList,'count],:$clamList] -; 'LAMBDA -; compForm:= LIST [fn,[lambdaOrSlam,vl,:bodyl]] -; if GETDATABASE(fn,'CONSTRUCTORKIND) = 'category -; then u:= compAndDefine compForm -; else u:=COMP compForm -; clearConstructorCache fn --clear cache for constructor -; first u - -(DEFUN |compileConstructor1| (|form|) - (PROG (|$clamList| |fn| |key| |vl| |bodyl| |lambdaOrSlam| |compForm| - |u|) - (DECLARE (SPECIAL |$clamList| |$ConstructorCache| |$mutableDomain|)) - (RETURN - (PROGN - (SPADLET |fn| (CAR |form|)) - (SPADLET |key| (CAADR |form|)) - (SPADLET |vl| (CADADR |form|)) - (SPADLET |bodyl| (CDDADR |form|)) - (SPADLET |$clamList| NIL) - (SPADLET |lambdaOrSlam| - (COND - ((BOOT-EQUAL (GETDATABASE |fn| 'CONSTRUCTORKIND) - '|category|) - 'SPADSLAM) - (|$mutableDomain| 'LAMBDA) - ('T - (SPADLET |$clamList| - (CONS (CONS |fn| - (CONS '|$ConstructorCache| - (CONS '|domainEqualList| - (CONS '|count| NIL)))) - |$clamList|)) - 'LAMBDA))) - (SPADLET |compForm| - (LIST (CONS |fn| - (CONS (CONS |lambdaOrSlam| - (CONS |vl| |bodyl|)) - NIL)))) - (COND - ((BOOT-EQUAL (GETDATABASE |fn| 'CONSTRUCTORKIND) '|category|) - (SPADLET |u| (|compAndDefine| |compForm|))) - ('T (SPADLET |u| (COMP |compForm|)))) - (|clearConstructorCache| |fn|) - (CAR |u|))))) - -;constructMacro (form is [nam,[lam,vl,body]]) == -; ^(and/[atom x for x in vl]) => -; stackSemanticError(["illegal parameters for macro: ",vl],nil) -; ["XLAM",vl':= [x for x in vl | IDENTP x],body] - -(DEFUN |constructMacro| (|form|) - (PROG (|nam| |lam| |vl| |body| |vl'|) - (RETURN - (SEQ (PROGN - (SPADLET |nam| (CAR |form|)) - (SPADLET |lam| (CAADR |form|)) - (SPADLET |vl| (CADADR |form|)) - (SPADLET |body| (CAR (CDDADR |form|))) - (COND - ((NULL (PROG (G169489) - (SPADLET G169489 'T) - (RETURN - (DO ((G169495 NIL (NULL G169489)) - (G169496 |vl| (CDR G169496)) - (|x| NIL)) - ((OR G169495 (ATOM G169496) - (PROGN - (SETQ |x| (CAR G169496)) - NIL)) - G169489) - (SEQ (EXIT (SETQ G169489 - (AND G169489 (ATOM |x|))))))))) - (|stackSemanticError| - (CONS '|illegal parameters for macro: | - (CONS |vl| NIL)) - NIL)) - ('T - (CONS 'XLAM - (CONS (SPADLET |vl'| - (PROG (G169508) - (SPADLET G169508 NIL) - (RETURN - (DO - ((G169514 |vl| - (CDR G169514)) - (|x| NIL)) - ((OR (ATOM G169514) - (PROGN - (SETQ |x| - (CAR G169514)) - NIL)) - (NREVERSE0 G169508)) - (SEQ - (EXIT - (COND - ((IDENTP |x|) - (SETQ G169508 - (CONS |x| G169508)))))))))) - (CONS |body| NIL)))))))))) - ;listInitialSegment(u,v) == ; null u => true ; null v => nil @@ -1948,97 +94,6 @@ (AND (BOOT-EQUAL (CAR |u|) (CAR |v|)) (|listInitialSegment| (CDR |u|) (CDR |v|)))))) -; --returns true iff u.i=v.i for i in 1..(#u)-1 -; -;modemap2Signature [[.,:sig],:.] == sig - -(DEFUN |modemap2Signature| (G169534) - (PROG (|sig|) - (RETURN (PROGN (SPADLET |sig| (CDAR G169534)) |sig|)))) - -;uncons x == -; atom x => x -; x is ["CONS",a,b] => [a,:uncons b] - -(DEFUN |uncons| (|x|) - (PROG (|ISTMP#1| |a| |ISTMP#2| |b|) - (RETURN - (COND - ((ATOM |x|) |x|) - ((AND (PAIRP |x|) (EQ (QCAR |x|) 'CONS) - (PROGN - (SPADLET |ISTMP#1| (QCDR |x|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |a| (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) (EQ (QCDR |ISTMP#2|) NIL) - (PROGN (SPADLET |b| (QCAR |ISTMP#2|)) 'T)))))) - (CONS |a| (|uncons| |b|))))))) - -;--% CAPSULE -; -;bootStrapError(functorForm,sourceFile) == -; ['COND, _ -; ['$bootStrapMode, _ -; ['VECTOR,mkDomainConstructor functorForm,nil,nil,nil,nil,nil]], -; [''T, ['systemError,['LIST,''%b,MKQ CAR functorForm,''%d,'"from", _ -; ''%b,MKQ namestring sourceFile,''%d,'"needs to be compiled"]]]] - -(DEFUN |bootStrapError| (|functorForm| |sourceFile|) - (declare (special |$bootStrapMode|)) - (CONS 'COND - (CONS (CONS '|$bootStrapMode| - (CONS (CONS 'VECTOR - (CONS (|mkDomainConstructor| - |functorForm|) - (CONS NIL - (CONS NIL - (CONS NIL - (CONS NIL (CONS NIL NIL))))))) - NIL)) - (CONS (CONS ''T - (CONS (CONS '|systemError| - (CONS - (CONS 'LIST - (CONS ''|%b| - (CONS - (MKQ (CAR |functorForm|)) - (CONS ''|%d| - (CONS "from" - (CONS ''|%b| - (CONS - (MKQ - (|namestring| - |sourceFile|)) - (CONS ''|%d| - (CONS - "needs to be compiled" - NIL))))))))) - NIL)) - NIL)) - NIL)))) - -;compTuple2Record u == ['Record,:[[":",i,x] for i in 1.. for x in rest u]] - -(DEFUN |compTuple2Record| (|u|) - (PROG () - (RETURN - (SEQ (CONS '|Record| - (PROG (G169701) - (SPADLET G169701 NIL) - (RETURN - (DO ((|i| 1 (QSADD1 |i|)) - (G169707 (CDR |u|) (CDR G169707)) - (|x| NIL)) - ((OR (ATOM G169707) - (PROGN (SETQ |x| (CAR G169707)) NIL)) - (NREVERSE0 G169701)) - (SEQ (EXIT (SETQ G169701 - (CONS - (CONS '|:| - (CONS |i| (CONS |x| NIL))) - G169701)))))))))))) ;--% PROCESS FUNCTOR CODE ; @@ -2054,381 +109,6 @@ (|error| '|CategoryDefaults is a reserved name|)) ('T (|buildFunctor| |form| |signature| |data| |localParList| |e|)))) -\end{chunk} -\section{compCapsuleItems} -The variable [[data]] appears to be unbound at runtime. Optimized -code won't check for this but interpreted code fails. We should -PROVE that data is unbound at runtime but have not done so yet. -Rather than remove the code entirely (since there MIGHT be a -path where it is used) we check for the runtime bound case and -assign [[$myFunctorBody]] if data has a value. - -The [[compCapsuleInner]] function in this file LOOKS like it sets -data and expects code to manipulate the assigned data structure. -Since we can't be sure we take the least disruptive course of action. - -\begin{chunk}{*} -;compCapsuleItems(itemlist,$predl,$e) == -; $TOP__LEVEL: local := nil -; $myFunctorBody :local -- := data ---needed for translator -; if (BOUNDP 'data) then $myFunctorBody:=data -- unbound at runtime? -; $signatureOfForm: local := nil -; $suffix: local:= 0 -; for item in itemlist repeat $e:= compSingleCapsuleItem(item,$predl,$e) -; $e - -(DEFUN |compCapsuleItems| (|itemlist| |$predl| |$e|) - (DECLARE (SPECIAL |$predl| |$e|)) - (PROG ($TOP_LEVEL |$myFunctorBody| |$signatureOfForm| |$suffix|) - (DECLARE (SPECIAL $TOP_LEVEL |$myFunctorBody| |$signatureOfForm| - |$suffix|)) - (RETURN - (SEQ (PROGN - (SPADLET $TOP_LEVEL NIL) - (SPADLET |$myFunctorBody| NIL) - (COND - ((BOUNDP '|data|) (SPADLET |$myFunctorBody| |data|))) - (SPADLET |$signatureOfForm| NIL) - (SPADLET |$suffix| 0) - (DO ((G169805 |itemlist| (CDR G169805)) (|item| NIL)) - ((OR (ATOM G169805) - (PROGN (SETQ |item| (CAR G169805)) NIL)) - NIL) - (SEQ (EXIT (SPADLET |$e| - (|compSingleCapsuleItem| |item| - |$predl| |$e|))))) - |$e|))))) - -;compSingleCapsuleItem(item,$predl,$e) == -; doIt(macroExpandInPlace(item,$e),$predl) -; $e - -(DEFUN |compSingleCapsuleItem| (|item| |$predl| |$e|) - (DECLARE (SPECIAL |$predl| |$e|)) - (PROGN (|doIt| (|macroExpandInPlace| |item| |$e|) |$predl|) |$e|)) - -;doIt(item,$predl) == -; $GENNO: local:= 0 -; item is ['SEQ,:l,['exit,1,x]] => -; RPLACA(item,"PROGN") -; RPLACA(LASTNODE item,x) -; for it1 in rest item repeat $e:= compSingleCapsuleItem(it1,$predl,$e) -; --This will RPLAC as appropriate -; isDomainForm(item,$e) => -; -- convert naked top level domains to import -; u:= ['import, [first item,:rest item]] -; stackWarning ["Use: import ", [first item,:rest item]] -; RPLACA(item,first u) -; RPLACD(item,rest u) -; doIt(item,$predl) -; item is ['LET,lhs,rhs,:.] => -; not (compOrCroak(item,$EmptyMode,$e) is [code,.,$e]) => -; stackSemanticError(["cannot compile assigned value to",:bright lhs],nil) -; not (code is ['LET,lhs',rhs',:.] and atom lhs') => -; code is ["PROGN",:.] => -; stackSemanticError(["multiple assignment ",item," not allowed"],nil) -; RPLACA(item,first code) -; RPLACD(item,rest code) -; lhs:= lhs' -; if not MEMBER(KAR rhs,$NonMentionableDomainNames) and -; not MEMQ(lhs, $functorLocalParameters) then -; $functorLocalParameters:= [:$functorLocalParameters,lhs] -; if code is ['LET,.,rhs',:.] and isDomainForm(rhs',$e) then -; if isFunctor rhs' then -; $functorsUsed:= insert(opOf rhs',$functorsUsed) -; $packagesUsed:= insert([opOf rhs'],$packagesUsed) -; if lhs="Rep" then -; $Representation:= (get("Rep",'value,$e)).(0) -; --$Representation bound by compDefineFunctor, used in compNoStacking -;--+ -; if $NRTopt = true -; then NRTgetLocalIndex $Representation -;--+ -; $LocalDomainAlist:= --see genDeltaEntry -; [[lhs,:SUBLIS($LocalDomainAlist,get(lhs,'value,$e).0)],:$LocalDomainAlist] -;--+ -; code is ['LET,:.] => -; RPLACA(item,($QuickCode => 'QSETREFV;'SETELT)) -; rhsCode:= -; rhs' -; RPLACD(item,['$,NRTgetLocalIndexClear lhs,rhsCode]) -; RPLACA(item,first code) -; RPLACD(item,rest code) -; item is [":",a,t] => [.,.,$e]:= compOrCroak(item,$EmptyMode,$e) -; item is ['import,:doms] => -; for dom in doms repeat -; sayBrightly ['" importing ",:formatUnabbreviated dom] -; [.,.,$e] := compOrCroak(item,$EmptyMode,$e) -; RPLACA(item,'PROGN) -; RPLACD(item,NIL) -- creates a no-op -; item is ["IF",:.] => doItIf(item,$predl,$e) -; item is ["where",b,:l] => compOrCroak(item,$EmptyMode,$e) -; item is ["MDEF",:.] => [.,.,$e]:= compOrCroak(item,$EmptyMode,$e) -; item is ['DEF,[op,:.],:.] => -; body:= isMacro(item,$e) => $e:= put(op,'macro,body,$e) -; [.,.,$e]:= t:= compOrCroak(item,$EmptyMode,$e) -; RPLACA(item,"CodeDefine") -; --Note that DescendCode, in CodeDefine, is looking for this -; RPLACD(CADR item,[$signatureOfForm]) -; --This is how the signature is updated for buildFunctor to recognise -;--+ -; functionPart:= ['dispatchFunction,t.expr] -; RPLACA(CDDR item,functionPart) -; RPLACD(CDDR item,nil) -; u:= compOrCroak(item,$EmptyMode,$e) => -; ([code,.,$e]:= u; RPLACA(item,first code); RPLACD(item,rest code)) -; true => cannotDo() - -(DEFUN |doIt| (|item| |$predl|) - (DECLARE (SPECIAL |$predl|)) - (PROG ($GENNO |ISTMP#4| |ISTMP#5| |x| |rhs| |ISTMP#3| |lhs'| |lhs| - |rhs'| |rhsCode| |a| |doms| |b| |l| |LETTMP#1| - |ISTMP#1| |ISTMP#2| |op| |body| |t| |functionPart| |u| - |code|) - (DECLARE (SPECIAL $GENNO |$e| |$EmptyMode| |$signatureOfForm| - |$QuickCode| |$LocalDomainAlist| |$Representation| - |$NRTopt| |$packagesUsed| |$functorsUsed| - |$functorLocalParameters| |$NonMentionableDomainNames|)) - (RETURN - (SEQ (PROGN - (SPADLET $GENNO 0) - (COND - ((AND (PAIRP |item|) (EQ (QCAR |item|) 'SEQ) - (PROGN - (SPADLET |ISTMP#1| (QCDR |item|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |ISTMP#2| (REVERSE |ISTMP#1|)) - 'T) - (PAIRP |ISTMP#2|) - (PROGN - (SPADLET |ISTMP#3| (QCAR |ISTMP#2|)) - (AND (PAIRP |ISTMP#3|) - (EQ (QCAR |ISTMP#3|) '|exit|) - (PROGN - (SPADLET |ISTMP#4| - (QCDR |ISTMP#3|)) - (AND (PAIRP |ISTMP#4|) - (EQUAL (QCAR |ISTMP#4|) 1) - (PROGN - (SPADLET |ISTMP#5| - (QCDR |ISTMP#4|)) - (AND (PAIRP |ISTMP#5|) - (EQ (QCDR |ISTMP#5|) NIL) - (PROGN - (SPADLET |x| - (QCAR |ISTMP#5|)) - 'T))))))) - (PROGN (SPADLET |l| (QCDR |ISTMP#2|)) 'T) - (PROGN (SPADLET |l| (NREVERSE |l|)) 'T)))) - (RPLACA |item| 'PROGN) (RPLACA (LASTNODE |item|) |x|) - (DO ((G170009 (CDR |item|) (CDR G170009)) - (|it1| NIL)) - ((OR (ATOM G170009) - (PROGN (SETQ |it1| (CAR G170009)) NIL)) - NIL) - (SEQ (EXIT (SPADLET |$e| - (|compSingleCapsuleItem| |it1| - |$predl| |$e|)))))) - ((|isDomainForm| |item| |$e|) - (SPADLET |u| - (CONS '|import| - (CONS (CONS (CAR |item|) (CDR |item|)) - NIL))) - (|stackWarning| - (CONS '|Use: import | - (CONS (CONS (CAR |item|) (CDR |item|)) NIL))) - (RPLACA |item| (CAR |u|)) (RPLACD |item| (CDR |u|)) - (|doIt| |item| |$predl|)) - ((AND (PAIRP |item|) (EQ (QCAR |item|) 'LET) - (PROGN - (SPADLET |ISTMP#1| (QCDR |item|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |lhs| (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (PROGN - (SPADLET |rhs| (QCAR |ISTMP#2|)) - 'T)))))) - (COND - ((NULL (PROGN - (SPADLET |ISTMP#1| - (|compOrCroak| |item| |$EmptyMode| - |$e|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |code| (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (PROGN - (SPADLET |ISTMP#3| - (QCDR |ISTMP#2|)) - (AND (PAIRP |ISTMP#3|) - (EQ (QCDR |ISTMP#3|) NIL) - (PROGN - (SPADLET |$e| - (QCAR |ISTMP#3|)) - 'T)))))))) - (|stackSemanticError| - (CONS '|cannot compile assigned value to| - (|bright| |lhs|)) - NIL)) - ((NULL (AND (PAIRP |code|) (EQ (QCAR |code|) 'LET) - (PROGN - (SPADLET |ISTMP#1| (QCDR |code|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |lhs'| - (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| - (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (PROGN - (SPADLET |rhs'| - (QCAR |ISTMP#2|)) - 'T))))) - (ATOM |lhs'|))) - (COND - ((AND (PAIRP |code|) (EQ (QCAR |code|) 'PROGN)) - (|stackSemanticError| - (CONS '|multiple assignment | - (CONS |item| - (CONS '| not allowed| NIL))) - NIL)) - ('T (RPLACA |item| (CAR |code|)) - (RPLACD |item| (CDR |code|))))) - ('T (SPADLET |lhs| |lhs'|) - (COND - ((AND (NULL (|member| (KAR |rhs|) - |$NonMentionableDomainNames|)) - (NULL (member |lhs| |$functorLocalParameters|))) - (SPADLET |$functorLocalParameters| - (APPEND |$functorLocalParameters| - (CONS |lhs| NIL))))) - (COND - ((AND (PAIRP |code|) (EQ (QCAR |code|) 'LET) - (PROGN - (SPADLET |ISTMP#1| (QCDR |code|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |ISTMP#2| - (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (PROGN - (SPADLET |rhs'| - (QCAR |ISTMP#2|)) - 'T))))) - (|isDomainForm| |rhs'| |$e|)) - (COND - ((|isFunctor| |rhs'|) - (SPADLET |$functorsUsed| - (|insert| (|opOf| |rhs'|) - |$functorsUsed|)) - (SPADLET |$packagesUsed| - (|insert| (CONS (|opOf| |rhs'|) NIL) - |$packagesUsed|)))) - (COND - ((BOOT-EQUAL |lhs| '|Rep|) - (SPADLET |$Representation| - (ELT (|get| '|Rep| '|value| |$e|) 0)) - (COND - ((BOOT-EQUAL |$NRTopt| 'T) - (|NRTgetLocalIndex| |$Representation|)) - ('T NIL)))) - (SPADLET |$LocalDomainAlist| - (CONS (CONS |lhs| - (SUBLIS |$LocalDomainAlist| - (ELT (|get| |lhs| '|value| |$e|) - 0))) - |$LocalDomainAlist|)))) - (COND - ((AND (PAIRP |code|) (EQ (QCAR |code|) 'LET)) - (RPLACA |item| - (COND - (|$QuickCode| 'QSETREFV) - ('T 'SETELT))) - (SPADLET |rhsCode| |rhs'|) - (RPLACD |item| - (CONS '$ - (CONS - (|NRTgetLocalIndexClear| |lhs|) - (CONS |rhsCode| NIL))))) - ('T (RPLACA |item| (CAR |code|)) - (RPLACD |item| (CDR |code|))))))) - ((AND (PAIRP |item|) (EQ (QCAR |item|) '|:|) - (PROGN - (SPADLET |ISTMP#1| (QCDR |item|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |a| (QCAR |ISTMP#1|)) - (SPADLET |ISTMP#2| (QCDR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (EQ (QCDR |ISTMP#2|) NIL) - (PROGN - (SPADLET |t| (QCAR |ISTMP#2|)) - 'T)))))) - (SPADLET |LETTMP#1| - (|compOrCroak| |item| |$EmptyMode| |$e|)) - (SPADLET |$e| (CADDR |LETTMP#1|)) |LETTMP#1|) - ((AND (PAIRP |item|) (EQ (QCAR |item|) '|import|) - (PROGN (SPADLET |doms| (QCDR |item|)) 'T)) - (DO ((G170018 |doms| (CDR G170018)) (|dom| NIL)) - ((OR (ATOM G170018) - (PROGN (SETQ |dom| (CAR G170018)) NIL)) - NIL) - (SEQ (EXIT (|sayBrightly| - (CONS " importing " - (|formatUnabbreviated| |dom|)))))) - (SPADLET |LETTMP#1| - (|compOrCroak| |item| |$EmptyMode| |$e|)) - (SPADLET |$e| (CADDR |LETTMP#1|)) - (RPLACA |item| 'PROGN) (RPLACD |item| NIL)) - ((AND (PAIRP |item|) (EQ (QCAR |item|) 'IF)) - (|doItIf| |item| |$predl| |$e|)) - ((AND (PAIRP |item|) (EQ (QCAR |item|) '|where|) - (PROGN - (SPADLET |ISTMP#1| (QCDR |item|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |b| (QCAR |ISTMP#1|)) - (SPADLET |l| (QCDR |ISTMP#1|)) - 'T)))) - (|compOrCroak| |item| |$EmptyMode| |$e|)) - ((AND (PAIRP |item|) (EQ (QCAR |item|) 'MDEF)) - (SPADLET |LETTMP#1| - (|compOrCroak| |item| |$EmptyMode| |$e|)) - (SPADLET |$e| (CADDR |LETTMP#1|)) |LETTMP#1|) - ((AND (PAIRP |item|) (EQ (QCAR |item|) 'DEF) - (PROGN - (SPADLET |ISTMP#1| (QCDR |item|)) - (AND (PAIRP |ISTMP#1|) - (PROGN - (SPADLET |ISTMP#2| (QCAR |ISTMP#1|)) - (AND (PAIRP |ISTMP#2|) - (PROGN - (SPADLET |op| (QCAR |ISTMP#2|)) - 'T)))))) - (COND - ((SPADLET |body| (|isMacro| |item| |$e|)) - (SPADLET |$e| (|put| |op| '|macro| |body| |$e|))) - ('T - (SPADLET |t| - (|compOrCroak| |item| |$EmptyMode| |$e|)) - (SPADLET |$e| (CADDR |t|)) - (RPLACA |item| '|CodeDefine|) - (RPLACD (CADR |item|) (CONS |$signatureOfForm| NIL)) - (SPADLET |functionPart| - (CONS '|dispatchFunction| - (CONS (CAR |t|) NIL))) - (RPLACA (CDDR |item|) |functionPart|) - (RPLACD (CDDR |item|) NIL)))) - ((SPADLET |u| (|compOrCroak| |item| |$EmptyMode| |$e|)) - (SPADLET |code| (CAR |u|)) (SPADLET |$e| (CADDR |u|)) - (RPLACA |item| (CAR |code|)) - (RPLACD |item| (CDR |code|))) - ('T (|cannotDo|)))))))) - ;isMacro(x,e) == ; x is ['DEF,[op,:args],signature,specialCases,body] and ; null get(op,'modemap,e) and null args and null get(op,'mode,e) @@ -2637,35 +317,9 @@ Since we can't be sure we take the least disruptive course of action. (|convert| T$ |m|)) ('T NIL)))))) -;compForMode(x,m,e) == -; $compForModeIfTrue: local:= true -; comp(x,m,e) - -(DEFUN |compForMode| (|x| |m| |e|) - (PROG (|$compForModeIfTrue|) - (DECLARE (SPECIAL |$compForModeIfTrue|)) - (RETURN - (PROGN (SPADLET |$compForModeIfTrue| 'T) (|comp| |x| |m| |e|))))) - -;compMakeCategoryObject(c,$e) == -; not isCategoryForm(c,$e) => nil -; u:= mkEvalableCategoryForm c => [eval u,$Category,$e] -; nil - -(DEFUN |compMakeCategoryObject| (|c| |$e|) - (DECLARE (SPECIAL |$e|)) - (PROG (|u|) - (declare (special |$Category|)) - (RETURN - (COND - ((NULL (|isCategoryForm| |c| |$e|)) NIL) - ((SPADLET |u| (|mkEvalableCategoryForm| |c|)) - (CONS (|eval| |u|) (CONS |$Category| (CONS |$e| NIL)))) - ('T NIL))))) - ;quotifyCategoryArgument x == MKQ x -(DEFUN |quotifyCategoryArgument| (|x|) (MKQ |x|)) +;(DEFUN |quotifyCategoryArgument| (|x|) (MKQ |x|)) ;makeCategoryForm(c,e) == ; not isCategoryForm(c,e) => nil diff --git a/src/interp/i-util.lisp.pamphlet b/src/interp/i-util.lisp.pamphlet index 5f77dd3..532aabf 100644 --- a/src/interp/i-util.lisp.pamphlet +++ b/src/interp/i-util.lisp.pamphlet @@ -365,70 +365,12 @@ lisp code is unwrapped. (SPADLET |sig| (CADR G166208)) (|compiledLookup| |op| |sig| |domain|))))) -;--HasCategory(domain,catform') == -;-- catform' is ['SIGNATURE,:f] => HasSignature(domain,f) -;-- catform' is ['ATTRIBUTE,f] => HasAttribute(domain,f) -;-- catform:= devaluate catform' -;-- domain0:=domain.0 -;-- isNewWorldDomain domain => newHasCategory(domain,catform) -;-- slot4 := domain.4 -;-- catlist := slot4.1 -;-- member(catform,catlist) or -;-- MEMQ(opOf(catform),'(Object Type)) or --temporary hack -;-- or/[compareSigEqual(catform,cat,domain0,domain) for cat in catlist] -; -;addModemap(op,mc,sig,pred,fn,$e) == -; $InteractiveMode => $e -; if knownInfo pred then pred:=true -; $insideCapsuleFunctionIfTrue=true => -; $CapsuleModemapFrame := -; addModemap0(op,mc,sig,pred,fn,$CapsuleModemapFrame) -; $e -; addModemap0(op,mc,sig,pred,fn,$e) - -(DEFUN |addModemap| (|op| |mc| |sig| |pred| |fn| |$e|) - (DECLARE (SPECIAL |$e| |$CapsuleModemapFrame| |$InteractiveMode| - |$insideCapsuleFunctionIfTrue|)) - (COND - (|$InteractiveMode| |$e|) - ('T (COND ((|knownInfo| |pred|) (SPADLET |pred| 'T))) - (COND - ((BOOT-EQUAL |$insideCapsuleFunctionIfTrue| 'T) - (SPADLET |$CapsuleModemapFrame| - (|addModemap0| |op| |mc| |sig| |pred| |fn| - |$CapsuleModemapFrame|)) - |$e|) - ('T (|addModemap0| |op| |mc| |sig| |pred| |fn| |$e|)))))) - -;isCapitalWord x == -; (y := PNAME x) and and/[UPPER_-CASE_-P y.i for i in 0..MAXINDEX y] - -(DEFUN |isCapitalWord| (|x|) - (PROG (|y|) - (RETURN - (SEQ (AND (SPADLET |y| (PNAME |x|)) - (PROG (G166230) - (SPADLET G166230 'T) - (RETURN - (DO ((G166236 NIL (NULL G166230)) - (G166237 (MAXINDEX |y|)) - (|i| 0 (QSADD1 |i|))) - ((OR G166236 (QSGREATERP |i| G166237)) - G166230) - (SEQ (EXIT (SETQ G166230 - (AND G166230 - (UPPER-CASE-P (ELT |y| |i|)))))))))))))) - ;domainEqual(a,b) == ; devaluate(a) = devaluate(b) (DEFUN |domainEqual| (|a| |b|) (BOOT-EQUAL (|devaluate| |a|) (|devaluate| |b|))) -;lispize x == first optimize [x] - -(DEFUN |lispize| (|x|) (CAR (|optimize| (CONS |x| NIL)))) - ;$newCompilerUnionFlag := true (SPADLET |$newCompilerUnionFlag| 'T) @@ -722,19 +664,6 @@ lisp code is unwrapped. G166448)))))))))) |predList|)))))) -;TruthP x == -; --True if x is a predicate that's always true -; x is nil => nil -; x=true => true -; x is ['QUOTE,:.] => true -; nil - -(DEFUN |TruthP| (|x|) - (COND - ((NULL |x|) NIL) - ((BOOT-EQUAL |x| 'T) 'T) - ((AND (PAIRP |x|) (EQ (QCAR |x|) 'QUOTE)) 'T) - ('T NIL))) \end{chunk} \eject