|
|
last edited 13 years ago by page |
1 2 3 4 5 6 7 | ||
Editor: Bill Page
Time: 2011/03/08 12:27:22 GMT-8 |
||
Note: dynamically load compiler |
changed: -Waldek Hebisch helped me with writing the following Lisp code to call the SPAD compiler from the FriCAS/AXIOM interpreter. Waldek Hebisch helped me to write the following Lisp code to call the SPAD compiler from the FriCAS/AXIOM interpreter. changed: -Unfortunately it fails with an obscure error message This function can be called from the interpreter to compile a SPAD program. The program source is passed as a List of Strings which is sent to the compiler as a text stream. Several flags and parameters must be set and dynamical loading of the compiler itself must be performed before calling the compiler. The parameter nil instructs the compiler to read form standard input, which in turn has been re-directed to the text stream. changed: -)lisp (defun string2spad (the-string-list) (let* ( ($LISPLIB t) (|$QuickLet| t) (|$QuickCode| t) (|$InteractiveMode| nil) (*standard-input* (make-string-input-stream (format nil "~{~A~^~%~}" the-string-list))) ) (declare (special $LISPLIB |$InteractiveMode|)) (|spadCompile| nil) )) )lisp (defun string2spad (the-string-list) (let* ( ($LISPLIB t) (|$QuickLet| t) (|$QuickCode| t) (|$InteractiveMode| nil) (*standard-input* (make-string-input-stream (format nil "~{~A~^~%~}" the-string-list))) ) (declare (special $LISPLIB |$InteractiveMode|)) (|oldCompilerAutoloadOnceTrigger|) (|spadCompile| nil) )) added: For example: changed: -unless if we first compile something else using a ')comiple file.spad' command -\begin{spad} -)abbrev domain YYY yyy -yyy():BasicType==Integer -\end{spad} - -After we have actually compiled something once it now works The output is sent to the console but the text stream can be captured as a string and returned to the caller as follows: removed: -So presumablly something is being loaded dynamically.
Waldek Hebisch helped me to write the following Lisp code to call the SPAD compiler from the FriCAS?/AXIOM interpreter.
)set output algebra on
)set output tex off
This function can be called from the interpreter to compile a SPAD program. The program source is passed as a List of Strings which is sent to the compiler as a text stream. Several flags and parameters must be set and dynamical loading of the compiler itself must be performed before calling the compiler. The parameter nil instructs the compiler to read form standard input, which in turn has been re-directed to the text stream.
)lisp (defun string2spad (the-string-list) (let* ( ($LISPLIB t) (|$QuickLet| t) (|$QuickCode| t) (|$InteractiveMode| nil) (*standard-input* (make-string-input-stream (format nil "~{~A~^~%~}" the-string-list))) ) (declare (special $LISPLIB |$InteractiveMode|)) (|oldCompilerAutoloadOnceTrigger|) (|spadCompile| nil) ))
Value = STRING2SPAD
For example:
S:=[")abbrev domain XXX xxx","xxx():BasicType == Integer"]
(1) [")abbrev domain XXX xxx","xxx():BasicType == Integer"]
STRING2SPAD(S)$Lisp
XXX abbreviates domain xxx ------------------------------------------------------------------------ initializing NRLIB XXX for xxx compiling into NRLIB XXX (time taken in buildFunctor: 0)
;;; *** |xxx| REDEFINED
;;; *** |xxx| REDEFINED Time: 0.03 SEC.
Cumulative Statistics for Constructor xxx Time: 0.03 seconds
--------------non extending category---------------------- .. xxx of cat (|BasicType|) has no (|IntegerNumberSystem|) finalizing NRLIB XXX Processing xxx for Browser database: --->-->xxx(): Missing Description ; compiling file "/var/zope2/var/LatexWiki/XXX.NRLIB/XXX.lsp" (written 08 MAR 2011 12:27:21 PM): ; compiling (DEFUN |xxx| ...) ; compiling (DEFUN |xxx;| ...) ; compiling (MAKEPROP (QUOTE |xxx|) ...) ; compiling (MAKEPROP (QUOTE |xxx|) ...)
; /var/zope2/var/LatexWiki/XXX.NRLIB/XXX.fasl written ; compilation finished in 0:00:00.082 ------------------------------------------------------------------------ xxx is now explicitly exposed in frame initial xxx will be automatically loaded when needed from /var/zope2/var/LatexWiki/XXX.NRLIB/XXX
(2) T
The output is sent to the console but the text stream can be captured as a string and returned to the caller as follows:
)lisp (defun string2spad (the-string-list) (let* ( ($LISPLIB t) (|$QuickLet| t) (|$QuickCode| t) (|$InteractiveMode| nil) (*standard-input* (make-string-input-stream (format nil "~{~A~^~%~}" the-string-list))) (*standard-output* (make-string-output-stream)) ) (declare (special $LISPLIB |$InteractiveMode|)) (|spadCompile| nil) (get-output-stream-string *standard-output* ) ))
Value = STRING2SPAD
and we can get the result as a string
result:=string STRING2SPAD(S)$Lisp
(3) ";)abbrev domain XXX xxx XXX abbreviates domain xxx ;xxx():BasicType == I nteger ---------------------------------------------------------------------- -- initializing NRLIB XXX for xxx compiling into NRLIB XXX (time take n in buildFunctor: 0)
;;; *** |xxx| REDEFINED
;;; *** |xxx| REDEFINED Time: 0.02 SEC.
Cumulative Statistics for Constructor xx x Time: 0.02 seconds
--------------non extending category------------ ---------- .. xxx of cat (|BasicType|) has no (|IntegerNumberSystem|) finalizing NRLIB XXX Processing xxx for Browser database: --->NIL-->xxx() : Missing Description ; compiling file "/var/zope2/var/LatexWiki/XXX.NRLIB/XX X.lsp" (written 08 MAR 2011 12:27:22 PM): ; compiling (DEFUN |xxx| ...) ; com piling (DEFUN |xxx;| ...) ; compiling (MAKEPROP (QUOTE |xxx|) ...) ; compilin g (MAKEPROP (QUOTE |xxx|) ...)
; /var/zope2/var/LatexWiki/XXX.NRLIB/XXX.fasl written ; compilation finished in 0:00:00.040 ------------------------------ ------------------------------------------ xxx is already explicitly expos ed in frame initial xxx will be automatically loaded when needed from
/var/zope2/var/LatexWiki/XXX.NRLIB/XXX
"