Changeset 11856
- Timestamp:
- 05/11/09 21:12:17 (14 years ago)
- Location:
- trunk/abcl
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/examples/abcl/jsr-223/JSR223Example.java
r11623 r11856 4 4 5 5 public static void main(String[] args) { 6 //Script Engine instantiation 7 ScriptEngine lispEngine = new ScriptEngineManager().getEngineByExtension("lisp"); 6 //Script Engine instantiation using ServiceProvider - this will 7 //look in the classpath for a file 8 // /META-INF/services/javax.script.ScriptEngineFactory 9 //where the AbclScriptEngineFactory is registered 10 ScriptEngine lispEngine = new ScriptEngineManager().getEngineByExtension("lisp"); 11 12 //Alternatively, you can directly instantiate the script engine: 13 14 //ScriptEngineManager scriptManager = new ScriptEngineManager(); 15 //scriptManager.registerEngineExtension("lisp", new AbclScriptEngineFactory()); 16 //ScriptEngine lispEngine = scriptManager.getEngineByExtension("lisp"); 17 18 //(thanks to Peter Tsenter for suggesting this) 8 19 9 20 //Accessing variables -
trunk/abcl/src/org/armedbear/lisp/Load.java
r11824 r11856 91 91 boolean print, 92 92 boolean ifDoesNotExist) 93 throws ConditionThrowable { 94 return load(pathname, filename, verbose, print, ifDoesNotExist, false); 95 } 96 97 98 public static final LispObject load(Pathname pathname, 99 String filename, 100 boolean verbose, 101 boolean print, 102 boolean ifDoesNotExist, 103 boolean returnLastResult) 93 104 throws ConditionThrowable 94 105 { … … 154 165 return loadFileFromStream(null, truename, 155 166 new Stream(in, Symbol.CHARACTER), 156 verbose, print, false );167 verbose, print, false, returnLastResult); 157 168 } 158 169 catch (FaslVersionMismatch e) { … … 381 392 boolean print, 382 393 boolean auto) 394 throws ConditionThrowable { 395 return loadFileFromStream(pathname, truename, in, verbose, print, auto, false); 396 } 397 398 private static final LispObject loadFileFromStream(LispObject pathname, 399 String truename, 400 Stream in, 401 boolean verbose, 402 boolean print, 403 boolean auto, 404 boolean returnLastResult) 383 405 throws ConditionThrowable 384 406 { … … 416 438 out._writeLine(" ..."); 417 439 out._finishOutput(); 418 LispObject result = loadStream(in, print, thread );440 LispObject result = loadStream(in, print, thread, returnLastResult); 419 441 long elapsed = System.currentTimeMillis() - start; 420 442 out.freshLine(); … … 428 450 return result; 429 451 } else 430 return loadStream(in, print, thread );452 return loadStream(in, print, thread, returnLastResult); 431 453 } 432 454 finally { … … 445 467 private static final LispObject loadStream(Stream in, boolean print, 446 468 LispThread thread) 469 throws ConditionThrowable { 470 return loadStream(in, print, thread, false); 471 } 472 473 private static final LispObject loadStream(Stream in, boolean print, 474 LispThread thread, boolean returnLastResult) 447 475 throws ConditionThrowable 448 476 { … … 455 483 try { 456 484 final Environment env = new Environment(); 485 LispObject result = NIL; 457 486 while (true) { 458 487 sourcePositionBinding.value = Fixnum.getInstance(in.getOffset()); … … 460 489 if (obj == EOF) 461 490 break; 462 LispObjectresult = eval(obj, env, thread);491 result = eval(obj, env, thread); 463 492 if (print) { 464 493 Stream out = … … 468 497 } 469 498 } 470 return T; 499 if(returnLastResult) { 500 return result; 501 } else { 502 return T; 503 } 471 504 } 472 505 finally { … … 481 514 final Environment env = new Environment(); 482 515 final SpecialBinding lastSpecialBinding = thread.lastSpecialBinding; 516 LispObject result = NIL; 483 517 try { 484 518 thread.bindSpecial(_FASL_ANONYMOUS_PACKAGE_, new Package()); … … 487 521 if (obj == EOF) 488 522 break; 489 eval(obj, env, thread);523 result = eval(obj, env, thread); 490 524 } 491 525 } … … 493 527 thread.lastSpecialBinding = lastSpecialBinding; 494 528 } 495 return T; 529 return result; 530 //There's no point in using here the returnLastResult flag like in 531 //loadStream(): this function is only called from init-fasl, which is 532 //only called from load, which already has its own policy for choosing 533 //whether to return T or the last value. 496 534 } 497 535 … … 563 601 @Override 564 602 public LispObject execute(LispObject filespec, LispObject verbose, 565 LispObject print, LispObject ifDoesNotExist) 566 throws ConditionThrowable 567 { 568 if (filespec instanceof Stream) { 569 if (((Stream)filespec).isOpen()) { 570 LispObject pathname; 571 if (filespec instanceof FileStream) 572 pathname = ((FileStream)filespec).getPathname(); 573 else 574 pathname = NIL; 575 String truename; 576 if (pathname instanceof Pathname) 577 truename = ((Pathname)pathname).getNamestring(); 578 else 579 truename = null; 580 return loadFileFromStream(pathname, 581 truename, 582 (Stream) filespec, 583 verbose != NIL, 584 print != NIL, 585 false); 586 } 587 // If stream is closed, fall through... 588 } 589 Pathname pathname = coerceToPathname(filespec); 590 if (pathname instanceof LogicalPathname) 591 pathname = LogicalPathname.translateLogicalPathname((LogicalPathname)pathname); 592 return load(pathname, 593 pathname.getNamestring(), 594 verbose != NIL, 595 print != NIL, 596 ifDoesNotExist != NIL); 597 } 603 LispObject print, LispObject ifDoesNotExist) 604 throws ConditionThrowable { 605 return load(filespec, verbose, print, ifDoesNotExist, NIL); 606 } 598 607 }; 608 609 // ### %load-returning-last-result filespec verbose print if-does-not-exist => object 610 private static final Primitive _LOAD_RETURNING_LAST_RESULT = 611 new Primitive("%load-returning-last-result", PACKAGE_SYS, false, 612 "filespec verbose print if-does-not-exist") 613 { 614 @Override 615 public LispObject execute(LispObject filespec, LispObject verbose, 616 LispObject print, LispObject ifDoesNotExist) 617 throws ConditionThrowable { 618 return load(filespec, verbose, print, ifDoesNotExist, T); 619 } 620 }; 621 622 private static final LispObject load(LispObject filespec, 623 LispObject verbose, 624 LispObject print, 625 LispObject ifDoesNotExist, 626 LispObject returnLastResult) 627 throws ConditionThrowable { 628 if (filespec instanceof Stream) { 629 if (((Stream)filespec).isOpen()) { 630 LispObject pathname; 631 if (filespec instanceof FileStream) 632 pathname = ((FileStream)filespec).getPathname(); 633 else 634 pathname = NIL; 635 String truename; 636 if (pathname instanceof Pathname) 637 truename = ((Pathname)pathname).getNamestring(); 638 else 639 truename = null; 640 return loadFileFromStream(pathname, 641 truename, 642 (Stream) filespec, 643 verbose != NIL, 644 print != NIL, 645 false, 646 returnLastResult != NIL); 647 } 648 // If stream is closed, fall through... 649 } 650 Pathname pathname = coerceToPathname(filespec); 651 if (pathname instanceof LogicalPathname) 652 pathname = LogicalPathname.translateLogicalPathname((LogicalPathname)pathname); 653 return load(pathname, 654 pathname.getNamestring(), 655 verbose != NIL, 656 print != NIL, 657 ifDoesNotExist != NIL, 658 returnLastResult != NIL); 659 } 599 660 600 661 // ### load-system-file -
trunk/abcl/src/org/armedbear/lisp/load.lisp
r11391 r11856 43 43 (merge-pathnames (pathname filespec))) 44 44 verbose print if-does-not-exist)) 45 46 (defun load-returning-last-result (filespec 47 &key 48 (verbose *load-verbose*) 49 (print *load-print*) 50 (if-does-not-exist t) 51 (external-format :default)) 52 (declare (ignore external-format)) ; FIXME 53 (%load-returning-last-result (if (streamp filespec) 54 filespec 55 (merge-pathnames (pathname filespec))) 56 verbose print if-does-not-exist)) -
trunk/abcl/src/org/armedbear/lisp/scripting/lisp/abcl-script.lisp
r11839 r11856 52 52 bindings))) 53 53 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 54 60 (defun generate-java-bindings (bindings-list actual-bindings java-bindings) 55 61 (loop :for binding :in actual-bindings … … 73 79 (eval `(let (,@,actual-global-bindings) 74 80 (let (,@,actual-engine-bindings) 81 ,(generate-special-declarations ,global-bindings) 82 ,(generate-special-declarations ,engine-bindings) 75 83 (prog1 76 84 (progn ,@,body) … … 88 96 code-string script-context) 89 97 (eval-in-script-context (global-bindings engine-bindings stdin stdout script-context) 90 (read-from-string91 (concatenate 'string "(" code-string ")"))))98 `((with-input-from-string (str ,code-string) 99 (sys::load-returning-last-result str))))) 92 100 93 101 (defun eval-compiled-script (global-bindings engine-bindings stdin stdout … … 97 105 98 106 (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)))) 125 125 126 126 ;;Java interface implementation - TODO -
trunk/abcl/src/org/armedbear/lisp/scripting/lisp/config.lisp
r11839 r11856 40 40 (defparameter *use-throwing-debugger* t) 41 41 42 (defparameter *compile-using-temp-files* t)43 44 42 (defun configure-abcl (abcl-script-engine) 45 43 (when *launch-swank-at-startup*
Note: See TracChangeset
for help on using the changeset viewer.