PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/portable-rep.scm

http://github.com/pablomarx/Thomas
Scheme | 92 lines | 47 code | 5 blank | 40 comment | 0 complexity | 5fedc46e41ba427533f30d659de2233e MD5 | raw file
  1. ;* Copyright 1992 Digital Equipment Corporation
  2. ;* All Rights Reserved
  3. ;*
  4. ;* Permission to use, copy, and modify this software and its documentation is
  5. ;* hereby granted only under the following terms and conditions. Both the
  6. ;* above copyright notice and this permission notice must appear in all copies
  7. ;* of the software, derivative works or modified versions, and any portions
  8. ;* thereof, and both notices must appear in supporting documentation.
  9. ;*
  10. ;* Users of this software agree to the terms and conditions set forth herein,
  11. ;* and hereby grant back to Digital a non-exclusive, unrestricted, royalty-free
  12. ;* right and license under any changes, enhancements or extensions made to the
  13. ;* core functions of the software, including but not limited to those affording
  14. ;* compatibility with other hardware or software environments, but excluding
  15. ;* applications which incorporate this software. Users further agree to use
  16. ;* their best efforts to return to Digital any such changes, enhancements or
  17. ;* extensions that they make and inform Digital of noteworthy uses of this
  18. ;* software. Correspondence should be provided to Digital at:
  19. ;*
  20. ;* Director, Cambridge Research Lab
  21. ;* Digital Equipment Corp
  22. ;* One Kendall Square, Bldg 700
  23. ;* Cambridge MA 02139
  24. ;*
  25. ;* This software may be distributed (but not offered for sale or transferred
  26. ;* for compensation) to third parties, provided such third parties agree to
  27. ;* abide by the terms and conditions of this notice.
  28. ;*
  29. ;* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  30. ;* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  31. ;* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
  32. ;* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  33. ;* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  34. ;* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  35. ;* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  36. ;* SOFTWARE.
  37. ; $Id: portable-rep.scm,v 1.8 1992/09/21 21:30:56 birkholz Exp $
  38. ;;; Just use current (user?) environment and keep a list of known module
  39. ;;; variables in thomas-rep-module-variables.
  40. (define thomas-rep-module-variables '())
  41. (define (empty-thomas-environment!)
  42. ;; Just dump thomas-rep-module-variables.
  43. (set! thomas-rep-module-variables '()))
  44. (define (thomas-rep)
  45. (newline)
  46. (display "Entering Thomas read-eval-print-loop.")
  47. (newline)
  48. (display "Exit by typing \"thomas:done\"")
  49. (newline)
  50. (dylan::catch-all-conditions
  51. (lambda ()
  52. (let loop ()
  53. (newline)
  54. (display "? ")
  55. (let ((input (read)))
  56. (newline)
  57. (if (and (eq? input 'thomas:done))
  58. 'thomas:done
  59. (compile-expression
  60. input '!MULTIPLE-VALUES thomas-rep-module-variables
  61. (lambda (new-vars preamble compiled-output)
  62. (implementation-specific:eval
  63. `(BEGIN
  64. ,@preamble
  65. (LET* ((!MULTIPLE-VALUES (VECTOR '()))
  66. (!RESULT ,compiled-output))
  67. (IF (EQ? !RESULT !MULTIPLE-VALUES)
  68. (LET RESULT-LOOP
  69. ((COUNT 1)
  70. (RESULTS (VECTOR-REF !MULTIPLE-VALUES 0)))
  71. (IF (PAIR? RESULTS)
  72. (LET ((RESULT (CAR RESULTS)))
  73. (NEWLINE)
  74. (DISPLAY ";Value[")(DISPLAY COUNT)
  75. (DISPLAY "]: ")(WRITE RESULT)
  76. (RESULT-LOOP (+ 1 COUNT) (CDR RESULTS)))
  77. (NEWLINE)))
  78. (BEGIN
  79. (NEWLINE)(DISPLAY ";Value: ")(WRITE !RESULT)
  80. (NEWLINE))))))
  81. (set! thomas-rep-module-variables
  82. (append new-vars thomas-rep-module-variables))
  83. (loop)))))))))
  84. (display "
  85. Apply thomas-rep to start a Thomas read-eval-print loop.
  86. ")