| 1 |
/* |
| 2 |
* The Regina Rexx Interpreter |
| 3 |
* Copyright (C) 1992 Anders Christensen <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
written = 0 |
| 23 |
|
| 24 |
call notify 'drop' |
| 25 |
foo = 'bar' |
| 26 |
drop foo |
| 27 |
|
| 28 |
if foo^=='FOO' then |
| 29 |
call complain 'Plain DROP does not work' |
| 30 |
|
| 31 |
|
| 32 |
/* === is a stem-symbol's value different from the value of the |
| 33 |
compound-symbol that has the same stem and a null tail? ====== */ |
| 34 |
|
| 35 |
foo. = 'here' |
| 36 |
bar = "" |
| 37 |
foo.bar = 'there' |
| 38 |
|
| 39 |
if (foo.=='there') then |
| 40 |
call complain 'Stem symbol set when compound with null tail is set' |
| 41 |
|
| 42 |
|
| 43 |
/* === is assignment to a stem destructive for *all* |
| 44 |
compound variables with that stem? ========================= */ |
| 45 |
|
| 46 |
foo.bar = 'here' |
| 47 |
foo. = 'there' |
| 48 |
if (foo.bar^=='there') then |
| 49 |
call complain 'Old compound symbols not destroyed when stem set' |
| 50 |
|
| 51 |
|
| 52 |
/* === default value of simple variables === */ |
| 53 |
|
| 54 |
drop bar foo.bar foo foobar |
| 55 |
|
| 56 |
if foobar^=='FOOBAR' then |
| 57 |
call complain 'Simple variables have incorrect default value' |
| 58 |
|
| 59 |
if foo.bar ^=='FOO.BAR' then |
| 60 |
call complain 'Something is wrong with the dropping of variables.' |
| 61 |
|
| 62 |
drop foo. |
| 63 |
bar = 'hepp' |
| 64 |
if foo.bar == 'FOO.HEPP' then |
| 65 |
call complain 'Tail part of uninitialized compound vars are upcased.' |
| 66 |
|
| 67 |
else if foo.bar ^== 'FOO.hepp' then |
| 68 |
call complain 'Compound vars with lower case tails have wrong def value.' |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
/* === HEAD.tail is different from HEAD.TAIL === */ |
| 73 |
upper = 'TAIL' |
| 74 |
lower = 'tail' |
| 75 |
space = ' tail ' |
| 76 |
|
| 77 |
head.upper = 'upper' |
| 78 |
head.lower = 'lower' |
| 79 |
head.space = 'space' |
| 80 |
|
| 81 |
if head.lower == head.upper then |
| 82 |
call complain "Compound vars don't differ between upper and lower case." |
| 83 |
|
| 84 |
if head.lower == head.space then |
| 85 |
call complain 'Tail of compound var is spaced before interpretation.' |
| 86 |
|
| 87 |
|
| 88 |
/* === stems and collections only on first level === */ |
| 89 |
drop foo. bar barf |
| 90 |
foo.bar. = 'hepp' |
| 91 |
if foo.bar.barf == 'hepp' then |
| 92 |
call complain 'Stems seems to multidimentional' |
| 93 |
|
| 94 |
|
| 95 |
/* === nothing magic about dots === */ |
| 96 |
foo.1.2 = hei |
| 97 |
drop foo. bar barf baz |
| 98 |
bar = 1 |
| 99 |
baz = 2 |
| 100 |
barf = 1.2 |
| 101 |
|
| 102 |
foo.barf = 'hepp' |
| 103 |
if foo.bar.baz ^== 'hepp' then |
| 104 |
call complain 'Multidimentional compound must be retrieved in same dim.' |
| 105 |
|
| 106 |
barf = 2.1 |
| 107 |
foo.baz.bar = 'hopp' |
| 108 |
if foo.barf ^== 'hopp' then |
| 109 |
call complain 'Multidim. compounds must be retrived in same dimention.' |
| 110 |
|
| 111 |
|
| 112 |
/* === tails can contain any char === */ |
| 113 |
/* |
| 114 |
* Sigh, this does not check that all the chacters are actually |
| 115 |
* used, since (let's say) one of the characters might be deleted |
| 116 |
* from the tail. |
| 117 |
*/ |
| 118 |
bar = xrange("00"x, "23"x) |
| 119 |
drop foo. |
| 120 |
foo.bar = 'hepp' |
| 121 |
if (foo.bar ^== 'hepp') then |
| 122 |
call complain "Tail in compound vars don't work with stange chars" |
| 123 |
|
| 124 |
/* |
| 125 |
* But at least specifically check for the null character, since some |
| 126 |
* programmers might be attempted to use that as string terminator |
| 127 |
*/ |
| 128 |
drop foo. |
| 129 |
bar = 'hepp' || "00"x || 'hopp' |
| 130 |
baz = 'hepp' || "00"x || 'hipp' |
| 131 |
foo.bar = 'first' |
| 132 |
foo.baz = 'second' |
| 133 |
|
| 134 |
if (foo.bar == foo.baz) then |
| 135 |
call complain 'Nul char seems to terminate name string' |
| 136 |
|
| 137 |
|
| 138 |
/* === 'reserved' words can be used in assignments === */ |
| 139 |
/* |
| 140 |
* To get a better testing of this, it might be best to run the |
| 141 |
* program block.rexx, which use 'reserved' words rather extensively |
| 142 |
*/ |
| 143 |
address = 1 ; value = 2 ; arg = 3 ; call = 4 |
| 144 |
on = 5 ; off = 6 ; name = 7 ; do = 8 |
| 145 |
end = 9 ; to = 10 ; by = 11 ; for = 12 |
| 146 |
forever = 13 ; while = 14 ; until = 15 ; drop = 16 |
| 147 |
exit = 17 ; if = 18 ; then = 19 ; else = 20 |
| 148 |
interpret = 21 ; iterate = 22 ; leave = 23 ; nop = 24 |
| 149 |
numeric = 25 ; digits = 26 ; form = 27 ; scientific = 28 |
| 150 |
engineering = 29 ; fuzz = 30 ; options = 31 ; parse = 32 |
| 151 |
upper = 33 ; linein = 34 ; pull = 35 ; source = 36 |
| 152 |
with = 37 ; var = 38 ; version = 39 ; procedure = 40 |
| 153 |
expose = 41 ; push = 42 ; queue = 43 ; return = 44 |
| 154 |
say = 45 ; select = 46 ; when = 47 ; otherwise = 48 |
| 155 |
signal = 49 ; trace = 50 |
| 156 |
|
| 157 |
all = ' 'address value arg call on off name do end to by for forever, |
| 158 |
while until drop exit if then else interpret iterate leave, |
| 159 |
nop numeric digits form scientific engineering fuzz options, |
| 160 |
parse upper linein pull source with var version procedure, |
| 161 |
expose push queue return say select when otherwise signal, |
| 162 |
trace |
| 163 |
|
| 164 |
sum = '' |
| 165 |
do i=1 to 50 |
| 166 |
sum = sum i |
| 167 |
end |
| 168 |
|
| 169 |
if sum ^== all then |
| 170 |
call complain 'Using "reserved" words as var names does not work' |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
/* === when stem is set, all compound with that stem is dropped === */ |
| 175 |
drop foo. bar baz barf |
| 176 |
foo.bar = 'hepp' |
| 177 |
foo. = 'hopp' |
| 178 |
if (foo.bar == 'hepp') then |
| 179 |
call complain 'Compound not dropped when stem was set' |
| 180 |
else if foo.bar ^== 'hopp' then |
| 181 |
call complain 'Compound has wrong value after stem was set' |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
/* Check that drop works correctly */ |
| 186 |
|
| 187 |
drop foo. bar |
| 188 |
foo. = 'first' |
| 189 |
bar = 'baz' |
| 190 |
foo.bar = 'second' |
| 191 |
|
| 192 |
drop bar |
| 193 |
if (foo.bar ^== 'first') then |
| 194 |
call complain 'Dropped simple var is not properly dropped' |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
/*----- more checking of drop ----------------------------------------*/ |
| 199 |
|
| 200 |
vars = 'baz foo.bar foo' |
| 201 |
drop foo (vars) barf (vars) vars |
| 202 |
|
| 203 |
if foo barf foo.bar baz vars ^== 'FOO BARF FOO.BAR BAZ VARS' then |
| 204 |
call complain 'indirect drop does not seem to work' |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
/*----- */ |
| 209 |
|
| 210 |
foo = '' |
| 211 |
call recursive 4, 1, 2, 3 |
| 212 |
|
| 213 |
facit = ' 4 1 1 2 2 3 3 1 1 2 2 3 3 -2 -2 -4 -4 -6 -6 4 -2 -2 -4 -4 -6 -6', |
| 214 |
'3 -2 -2 -4 -4 -6 -6 -2 -2 -4 -4 -6 -6 4 4 8 8 12 12', |
| 215 |
'3 4 4 8 8 12 12 2 4 4 8 8 12 12 4 4 8 8 12 12 -8 -8 -16 -16', |
| 216 |
'-24 -24 2 -8 -8 -16 -16 -24 -24 1 -8 -8 -16 -16 -24 -24 -8 -8', |
| 217 |
'-16 -16 -24 -24 16 16 32 32 48 48 1 16 16 32 32 48 48' |
| 218 |
|
| 219 |
if foo\==facit then |
| 220 |
call complain 'Recurive treatment of variables did not work' |
| 221 |
|
| 222 |
signal after_recursive |
| 223 |
|
| 224 |
recursive: procedure expose foo |
| 225 |
parse arg num, st, st., ts.1 |
| 226 |
if num=0 then return |
| 227 |
|
| 228 |
foo = foo num st value('st') st. value('st.') ts.1 value('ts.1') |
| 229 |
call check_rec |
| 230 |
foo = foo num st value('st') st. value('st.') ts.1 value('ts.1') |
| 231 |
|
| 232 |
call recursive num-1, st, st., ts.1 |
| 233 |
return |
| 234 |
|
| 235 |
check_rec: procedure expose foo st st. ts.1 |
| 236 |
foo = foo st value('st') st. value('st.') ts.1 value('ts.1') |
| 237 |
st = st * -2 |
| 238 |
st. = st. * -2 |
| 239 |
ts.1 = ts.1 * -2 |
| 240 |
foo = foo st value('st') st. value('st.') ts.1 value('ts.1') |
| 241 |
return |
| 242 |
|
| 243 |
after_recursive: |
| 244 |
|
| 245 |
|
| 246 |
say ' ' |
| 247 |
exit 0 |
| 248 |
|
| 249 |
|
| 250 |
ch: procedure expose sigl |
| 251 |
parse arg first, second |
| 252 |
if first ^== second then do |
| 253 |
say |
| 254 |
say "first= /"first"/" |
| 255 |
say "second=/"second"/" |
| 256 |
say "FuncTrip: error in " sigl":" sourceline(sigl) ; end |
| 257 |
return |
| 258 |
|
| 259 |
|
| 260 |
notify: |
| 261 |
parse arg word . |
| 262 |
written = written + length(word) + 2 |
| 263 |
if written>75 then do |
| 264 |
written = length(word) |
| 265 |
say ' ' |
| 266 |
end |
| 267 |
call charout , word || ', ' |
| 268 |
return |
| 269 |
|
| 270 |
|
| 271 |
error: |
| 272 |
say 'Error discovered in function insert()' |
| 273 |
return |
| 274 |
|
| 275 |
complain: |
| 276 |
say ' ...' |
| 277 |
say 'Tripped in line' sigl':' arg(1)'.' |
| 278 |
length = charout(,' (') |
| 279 |
return |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|