customize-rlisp-for-emode.sl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. %
  2. % CUSTOMIZE-RLISP-FOR-EMODE.SL - "customizations" to support EMODE.
  3. %
  4. % Author: William F. Galway
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 14 July 1982
  9. % Copyright (c) 1982 University of Utah
  10. %
  11. % This file makes a few changes to the "innards" of RLISP to customize it
  12. % for the building of EMODE. Also adds a few utilities that should
  13. % (perhaps) become part of the standard PSL.
  14. % Set things up so SETF knows about IGETV and IGETS. ("Fast" string and
  15. % vector accessors.)
  16. (BothTimes % BothTimes?
  17. (progn
  18. (put 'IGETV 'ASSIGN-OP 'IPUTV)
  19. (put 'IGETS 'ASSIGN-OP 'IPUTS)))
  20. % Return true is x is a "list". (I.e., a pair or NIL.)
  21. (de listp (x)
  22. (or (null x) (pairp x)))
  23. % Return lst with its first n entries dropped.
  24. (de tail (lst n)
  25. (cond
  26. ((null lst) NIL)
  27. ((eqn n 0) lst)
  28. (T (tail (cdr lst) (sub1 n)))))
  29. % Routines for reading from and printing into strings.
  30. (fluid
  31. '(
  32. string_for_read_from_string
  33. index_for_string
  34. string_input_channel
  35. string_output_channel
  36. print_dest_string
  37. print_indx
  38. flush_output))
  39. % Set up the channels at load time.
  40. (LoadTime
  41. (progn
  42. (setf SpecialWriteFunction* 'ReadOnlyChannel)
  43. (setf SpecialReadFunction* 'channel_read_from_string)
  44. (setf SpecialCloseFunction* 'DummyClose)
  45. (setf string_input_channel (open "string_reader" 'SPECIAL))
  46. (setf SpecialWriteFunction* 'channel_write_into_string)
  47. (setf SpecialReadFunction* 'WriteOnlyChannel)
  48. (setf string_output_channel (open "string_writer" 'SPECIAL))))
  49. % READ from a string. Argument is a fluid.
  50. (de read_from_string (string_for_read_from_string)
  51. (prog (index_for_string value)
  52. (setf index_for_string 0) % index_for_string is also fluid.
  53. % Kludge to flush out input channel.
  54. (ChannelUnReadChar string_input_channel 0)
  55. % Read the value from the "magic" string reading channel.
  56. % Use ErrorSet to catch problems (such as trying to read an unbalanced
  57. % expression). Rebind fluid !*BREAK to prevent a break loop if the
  58. % read fails.
  59. (let ((*BREAK NIL))
  60. (setf value
  61. (ErrorSet
  62. `(channelRead ,string_input_channel)
  63. T % Allow error messages to be printed
  64. NIL))) % but, don't print backtrace stuff.
  65. (return
  66. (cond
  67. ((pairp value) (car value))
  68. % If there was an error in reading the string, just return NIL???
  69. % Or, pass the error on down?
  70. (T NIL)))))
  71. % Ignore the channel argument, read next character from string in fluid
  72. % "string_for_read_from_string", if any. Return an end of file if none
  73. % left.
  74. (de channel_read_from_string (chn)
  75. (prog (val)
  76. (cond
  77. % If past end of string, return an EOF.
  78. ((GreaterP index_for_string (size string_for_read_from_string))
  79. (return (char EOF))))
  80. % Otherwise, return the appropriate character from the string.
  81. (setf val (indx string_for_read_from_string index_for_string))
  82. (setf index_for_string (add1 index_for_string))
  83. (return val)))
  84. % PrintF into the string "print_dest_string", starting at index
  85. % "print_indx". (Both of which are FLUIDS.) Return the "printed into"
  86. % string. This code should probably be made more efficient (SysLispified?)
  87. % someday. Also, the number of legal arguments is sort of flakey. Roughly
  88. % modeled after the code for BldMsg.
  89. (de PrintF_into_string
  90. (print_dest_string print_indx format
  91. arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10)
  92. (prog old_outchan
  93. % Switch to special channel for printing into strings.
  94. (setf old_outchan OUT*)
  95. (setf OUT* string_output_channel)
  96. % Kludge to clear the line position counter
  97. (setf flush_output T)
  98. (WriteChar (char EOL))
  99. (setf flush_output NIL)
  100. % Now use PrintF to the appropriate "magic" channel.
  101. (PrintF format arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10)
  102. % Select original channel
  103. (setf OUT* old_outchan)
  104. % Return the printed into string.
  105. (return print_dest_string)))
  106. (de channel_write_into_string (chn chr)
  107. % Ignore the channel argument, write character into fluid
  108. % "print_dest_string", at location print_indx.
  109. % We're careful to check bounds, since bad things could happen if we try to
  110. % print an error message during this process!
  111. (cond
  112. % If "flush" flag is clear, and everything is within bounds.
  113. ((and
  114. (null flush_output)
  115. (leq 0 print_indx)
  116. (leq print_indx (size print_dest_string)))
  117. % then print into the string
  118. (progn
  119. (setf (indx print_dest_string print_indx) chr)
  120. (setf print_indx (add1 print_indx))))))
  121. % Dummy routine to close up channel I/O.
  122. (de DummyClose (chn)
  123. NIL)