Ignore:
Timestamp:
05/11/09 21:12:17 (14 years ago)
Author:
astalla
Message:
  • loading:

added a new primitive sys::load-returning-last-result which behaves like
load but returns the last value produced instead of T

  • JSR-223:
    • used the new load-returning-last-result to evaluate both interpreted and compiled code for consistency (with a caveat, see the wiki page on JSR-223)
    • bindings established through ScriptContext? are now declared special
    • compilation using the runtime compiler has been removed due to inconsistencies with evaluation and file-based compilation
    • updated the example as suggested on the ML to show both modes of getting the AbclScriptEngine?


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/scripting/lisp/abcl-script.lisp

    r11839 r11856  
    5252      bindings)))
    5353
     54(defun generate-special-declarations (bindings)
     55  (let ((*package* (find-package :abcl-script-user)))
     56    `(declare (special
     57         ,@(mapcar (lambda (binding) (read-from-string (car binding)))
     58       bindings)))))
     59
    5460(defun generate-java-bindings (bindings-list actual-bindings java-bindings)
    5561  (loop :for binding  :in actual-bindings
     
    7379       (eval `(let (,@,actual-global-bindings)
    7480    (let (,@,actual-engine-bindings)
     81      ,(generate-special-declarations ,global-bindings)
     82      ,(generate-special-declarations ,engine-bindings)
    7583      (prog1
    7684          (progn ,@,body)
     
    8896        code-string script-context)
    8997  (eval-in-script-context (global-bindings engine-bindings stdin stdout script-context)
    90     (read-from-string
    91      (concatenate 'string "(" code-string ")"))))
     98    `((with-input-from-string (str ,code-string)
     99  (sys::load-returning-last-result str)))))
    92100
    93101(defun eval-compiled-script (global-bindings engine-bindings stdin stdout
     
    97105
    98106(defun compile-script (code-string)
    99   (if *compile-using-temp-files*
    100       (let* ((tmp-file (jstatic (jmethod "java.io.File" "createTempFile" "java.lang.String" "java.lang.String")
    101         nil "abcl-src-file-" ".lisp"))
    102        (tmp-file-path (jcall (jmethod "java.io.File" "getAbsolutePath") tmp-file)))
    103   (jcall (jmethod "java.io.File" "deleteOnExit") tmp-file) ;to be really-really-really sure...
    104   (unwind-protect
    105        (progn
    106          (with-open-file (stream tmp-file-path :direction :output)
    107      (princ "(in-package :abcl-script-user)" stream)
    108      (princ code-string stream)
    109      (finish-output stream))
    110          (let ((compiled-file (compile-file tmp-file-path)))
    111      (jcall (jmethod "java.io.File" "deleteOnExit")
    112       (jnew (jconstructor "java.io.File" "java.lang.String")
    113             (namestring compiled-file)))
    114      (lambda ()
    115        (let ((*package* (find-package :abcl-script-user)))
    116          (load compiled-file :verbose t :print t)))))
    117     (delete-file tmp-file-path)))
    118       (eval
    119        `(compile
    120    nil
    121    (lambda ()
    122      ,@(let ((*package* (find-package :abcl-script-user)))
    123          (read-from-string
    124     (concatenate 'string "(" code-string " cl:t)")))))))) ;return T in conformity of what LOAD does.
     107  (let* ((tmp-file (jstatic (jmethod "java.io.File" "createTempFile" "java.lang.String" "java.lang.String")
     108          nil "abcl-src-file-" ".lisp"))
     109   (tmp-file-path (jcall (jmethod "java.io.File" "getAbsolutePath") tmp-file)))
     110    (jcall (jmethod "java.io.File" "deleteOnExit") tmp-file) ;to be really-really-really sure...
     111    (unwind-protect
     112   (progn
     113     (with-open-file (stream tmp-file-path :direction :output)
     114       (princ "(in-package :abcl-script-user)" stream)
     115       (princ code-string stream)
     116       (finish-output stream))
     117     (let ((compiled-file (compile-file tmp-file-path)))
     118       (jcall (jmethod "java.io.File" "deleteOnExit")
     119        (jnew (jconstructor "java.io.File" "java.lang.String")
     120        (namestring compiled-file)))
     121       (lambda ()
     122         (let ((*package* (find-package :abcl-script-user)))
     123     (sys::load-returning-last-result compiled-file)))))
     124      (delete-file tmp-file-path))))
    125125
    126126;;Java interface implementation - TODO
Note: See TracChangeset for help on using the changeset viewer.