aboutsummaryrefslogtreecommitdiff
path: root/src/interp/i-util.boot
blob: e4f54ccea455d5b4e640d8ebeba978a1a5da68aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
-- Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are
-- met:
--
--     - Redistributions of source code must retain the above copyright
--       notice, this list of conditions and the following disclaimer.
--
--     - Redistributions in binary form must reproduce the above copyright
--       notice, this list of conditions and the following disclaimer in
--       the documentation and/or other materials provided with the
--       distribution.
--
--     - Neither the name of The Numerical ALgorithms Group Ltd. nor the
--       names of its contributors may be used to endorse or promote products
--       derived from this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import g_-util
namespace BOOT

module i_-util

--% 

$intTopLevel ==
  "top__level"

--% The function for making prompts
 
inputPrompt str ==
  -- replaces older INPUT-PROMPT
  atom (x := $SCREENSIZE()) => NIL
  p := CAR(x) - 2
  y := $OLDLINE
  SETQ($OLDLINE,NIL)
  y => _$SHOWLINE(STRCONC(str,EBCDIC 19,y),p)
  0 = SIZE str => NIL
  _$SHOWLINE(STRCONC(str,EBCDIC 19),p)
 
protectedPrompt(:p) ==
  [str,:br] := p
  0 = SIZE str => inputPrompt str
  msg := EBCDIC 29                       -- start of field
  msg :=
    if br then STRCONC(msg,EBCDIC 232)   -- bright write protect
    else       STRCONC(msg,EBCDIC  96)   -- write protect
  msg := STRCONC(msg,str,EBCDIC 29,EBCDIC 64)  -- unprotect again
  inputPrompt msg
 
MKPROMPT() ==
  $inputPromptType = 'none    => '""
  $inputPromptType = 'plain   => '"-> "
  $inputPromptType = 'step    =>
    STRCONC('"(",STRINGIMAGE $IOindex,'") -> ")
  $inputPromptType = 'frame   =>
    STRCONC(STRINGIMAGE $interpreterFrameName,
      '" (",STRINGIMAGE $IOindex,'") -> ")
  STRCONC(STRINGIMAGE $interpreterFrameName,
   '" [", SUBSTRING(CURRENTTIME(),8,NIL),'"] [",
    STRINGIMAGE $IOindex, '"] -> ")
 

printPrompt(flush? == false) ==
  PRINC(MKPROMPT(), $OutputStream)
  if flush? then
    FORCE_-OUTPUT $OutputStream

--% Miscellaneous
 
$ZeroVecCache := nil
Zeros n ==
  #$ZeroVecCache = n => $ZeroVecCache
  $ZeroVecCache := MAKE_-VEC n
  for i in 0..n-1 repeat $ZeroVecCache.i:=0
  $ZeroVecCache
 
LZeros n ==
  n < 1 => nil
  l := [0]
  for i in 2..n repeat l := [0, :l]
  l
 
-- bpi2FunctionName x ==
--   s:= BPINAME x  => s
--   x
 
-- subrToName x == BPINAME x

-- formerly in clammed.boot

isSubDomain(d1,d2) ==
  -- d1 and d2 are different domains
  subDomainList := '(Integer NonNegativeInteger PositiveInteger)
  ATOM d1 or ATOM d2 => nil
  l := MEMQ(CAR d2, subDomainList) =>
    MEMQ(CAR d1, CDR l)
  nil

$variableNumberAlist := nil

variableNumber(x) ==
  p := ASSQ(x, $variableNumberAlist)
  null p => 
    $variableNumberAlist := [[x,:0], :$variableNumberAlist]
    0
  RPLACD(p, 1+CDR p)
  CDR p

newType? t == nil


-- functions used at run-time which were formerly in the compiler files

Undef(:u) ==
  u':= LAST u
  [[domain,slot],op,sig]:= u'
  domain':=eval mkEvalable domain
  ^EQ(CAR ELT(domain',slot), function Undef) =>
-- OK - thefunction is now defined
    [:u'',.]:=u
    if $reportBottomUpFlag then
      sayMessage concat ['"   Retrospective determination of slot",'%b,
        slot,'%d,'"of",'%b,:prefix2String domain,'%d]
    APPLY(CAR ELT(domain',slot),[:u'',CDR ELT(domain',slot)])
  throwKeyedMsg("S2IF0008",[formatOpSignature(op,sig),domain])
 
makeInitialModemapFrame() == 
  COPY $InitialModemapFrame
 
isCapitalWord x ==
  (y := PNAME x) and and/[UPPER_-CASE_-P y.i for i in 0..MAXINDEX y]
 
$newCompilerUnionFlag := true

orderUnionEntries l ==
  $newCompilerUnionFlag => l
  first l is [":",.,.] => l  -- new style Unions
  [a,b]:=
    split(l,nil,nil) where
      split(l,a,b) ==
        l is [x,:l'] =>
          (STRINGP x => split(l',[x,:a],b); split(l',a,[x,:b]))
        [a,b]
  [:orderList a,:orderList b]
 
mkPredList listOfEntries ==
  $newCompilerUnionFlag =>
     [['EQCAR,"#1",i] for arg in listOfEntries for i in 0..]
  first listOfEntries is [":",.,.] =>   -- new Tagged Unions
     [['EQCAR,"#1",MKQ tag] for [.,tag,.] in listOfEntries]
  --1. generate list of type-predicate pairs from union specification
  initTypePredList:=
    [selTypePred for x in listOfEntries] where
      selTypePred() ==
        STRINGP x => [x,'EQUAL,"#1",x]
        [x,:GETL(opOf x,"BasicPredicate")]
  typeList:= ASSOCLEFT initTypePredList
  initPredList:= ASSOCRIGHT initTypePredList
  hasDuplicatePredicate:=
    fn initPredList where
      fn x ==
        null x => false
        first x and member(first x,rest x) => true
        fn rest x
                                 --if duplicate predicate, kill them all
  if hasDuplicatePredicate then initPredList:= [nil for x in initPredList]
  nonEmptyPredList:= [p for p in initPredList | p^=nil]
  numberWithoutPredicate:= #listOfEntries-#nonEmptyPredList
  predList:=
    numberWithoutPredicate=0 and not hasDuplicatePredicate => initPredList
    numberWithoutPredicate=1 and null LAST initPredList and
      [STRINGP x for x in rest REVERSE listOfEntries] =>
        allButLast:= rest REVERSE initPredList
        NREVERSE [['NULL,MKPF(allButLast,"OR")],:allButLast]
  --otherwise, generate a tagged-union
  --we have made an even number of REVERSE operations, therefore
  --the original order is preserved.  JHD 25.Sept.1983
    tagPredList:= [["EQCAR","#1",i] for i in 1..numberWithoutPredicate]
    [addPredIfNecessary for p in initPredList] where
      addPredIfNecessary() ==
        p => p
        [u,:tagPredList]:= tagPredList
        u
  predList