Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | // This file is automatically generated by scheme2js, except for the |
michael@0 | 2 | // benchmark harness code at the beginning and end of the file. |
michael@0 | 3 | |
michael@0 | 4 | var EarleyBoyer = new BenchmarkSuite('EarleyBoyer', 666463, [ |
michael@0 | 5 | new Benchmark("Earley", function () { BgL_earleyzd2benchmarkzd2(); }), |
michael@0 | 6 | new Benchmark("Boyer", function () { BgL_nboyerzd2benchmarkzd2(); }) |
michael@0 | 7 | ]); |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | /************* GENERATED FILE - DO NOT EDIT *************/ |
michael@0 | 11 | /************* GENERATED FILE - DO NOT EDIT *************/ |
michael@0 | 12 | /************* GENERATED FILE - DO NOT EDIT *************/ |
michael@0 | 13 | /************* GENERATED FILE - DO NOT EDIT *************/ |
michael@0 | 14 | /************* GENERATED FILE - DO NOT EDIT *************/ |
michael@0 | 15 | /************* GENERATED FILE - DO NOT EDIT *************/ |
michael@0 | 16 | /************* GENERATED FILE - DO NOT EDIT *************/ |
michael@0 | 17 | /************* GENERATED FILE - DO NOT EDIT *************/ |
michael@0 | 18 | /* |
michael@0 | 19 | * To use write/prints/... the default-output port has to be set first. |
michael@0 | 20 | * Simply setting SC_DEFAULT_OUT and SC_ERROR_OUT to the desired values |
michael@0 | 21 | * should do the trick. |
michael@0 | 22 | * In the following example the std-out and error-port are redirected to |
michael@0 | 23 | * a DIV. |
michael@0 | 24 | function initRuntime() { |
michael@0 | 25 | function escapeHTML(s) { |
michael@0 | 26 | var tmp = s; |
michael@0 | 27 | tmp = tmp.replace(/&/g, "&"); |
michael@0 | 28 | tmp = tmp.replace(/</g, "<"); |
michael@0 | 29 | tmp = tmp.replace(/>/g, ">"); |
michael@0 | 30 | tmp = tmp.replace(/ /g, " "); |
michael@0 | 31 | tmp = tmp.replace(/\n/g, "<br />"); |
michael@0 | 32 | tmp = tmp.replace(/\t/g, "  "); |
michael@0 | 33 | return tmp; |
michael@0 | 34 | |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | document.write("<div id='stdout'></div>"); |
michael@0 | 38 | SC_DEFAULT_OUT = new sc_GenericOutputPort( |
michael@0 | 39 | function(s) { |
michael@0 | 40 | var stdout = document.getElementById('stdout'); |
michael@0 | 41 | stdout.innerHTML = stdout.innerHTML + escapeHTML(s); |
michael@0 | 42 | }); |
michael@0 | 43 | SC_ERROR_OUT = SC_DEFAULT_OUT; |
michael@0 | 44 | } |
michael@0 | 45 | */ |
michael@0 | 46 | |
michael@0 | 47 | |
michael@0 | 48 | function sc_print_debug() { |
michael@0 | 49 | sc_print.apply(null, arguments); |
michael@0 | 50 | } |
michael@0 | 51 | /*** META ((export *js*)) */ |
michael@0 | 52 | var sc_JS_GLOBALS = this; |
michael@0 | 53 | |
michael@0 | 54 | var __sc_LINE=-1; |
michael@0 | 55 | var __sc_FILE=""; |
michael@0 | 56 | |
michael@0 | 57 | /*** META ((export #t)) */ |
michael@0 | 58 | function sc_alert() { |
michael@0 | 59 | var len = arguments.length; |
michael@0 | 60 | var s = ""; |
michael@0 | 61 | var i; |
michael@0 | 62 | |
michael@0 | 63 | for( i = 0; i < len; i++ ) { |
michael@0 | 64 | s += sc_toDisplayString(arguments[ i ]); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | return alert( s ); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | /*** META ((export #t)) */ |
michael@0 | 71 | function sc_typeof( x ) { |
michael@0 | 72 | return typeof x; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | /*** META ((export #t)) */ |
michael@0 | 76 | function sc_error() { |
michael@0 | 77 | var a = [sc_jsstring2symbol("*error*")]; |
michael@0 | 78 | for (var i = 0; i < arguments.length; i++) { |
michael@0 | 79 | a[i+1] = arguments[i]; |
michael@0 | 80 | } |
michael@0 | 81 | throw a; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | /*** META ((export #t) |
michael@0 | 85 | (peephole (prefix "throw "))) |
michael@0 | 86 | */ |
michael@0 | 87 | function sc_raise(obj) { |
michael@0 | 88 | throw obj; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | /*** META ((export with-handler-lambda)) */ |
michael@0 | 92 | function sc_withHandlerLambda(handler, body) { |
michael@0 | 93 | try { |
michael@0 | 94 | return body(); |
michael@0 | 95 | } catch(e) { |
michael@0 | 96 | if (!e._internalException) |
michael@0 | 97 | return handler(e); |
michael@0 | 98 | else |
michael@0 | 99 | throw e; |
michael@0 | 100 | } |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | var sc_properties = new Object(); |
michael@0 | 104 | |
michael@0 | 105 | /*** META ((export #t)) */ |
michael@0 | 106 | function sc_putpropBang(sym, key, val) { |
michael@0 | 107 | var ht = sc_properties[sym]; |
michael@0 | 108 | if (!ht) { |
michael@0 | 109 | ht = new Object(); |
michael@0 | 110 | sc_properties[sym] = ht; |
michael@0 | 111 | } |
michael@0 | 112 | ht[key] = val; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | /*** META ((export #t)) */ |
michael@0 | 116 | function sc_getprop(sym, key) { |
michael@0 | 117 | var ht = sc_properties[sym]; |
michael@0 | 118 | if (ht) { |
michael@0 | 119 | if (key in ht) |
michael@0 | 120 | return ht[key]; |
michael@0 | 121 | else |
michael@0 | 122 | return false; |
michael@0 | 123 | } else |
michael@0 | 124 | return false; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | /*** META ((export #t)) */ |
michael@0 | 128 | function sc_rempropBang(sym, key) { |
michael@0 | 129 | var ht = sc_properties[sym]; |
michael@0 | 130 | if (ht) |
michael@0 | 131 | delete ht[key]; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | /*** META ((export #t)) */ |
michael@0 | 135 | function sc_any2String(o) { |
michael@0 | 136 | return jsstring2string(sc_toDisplayString(o)); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | /*** META ((export #t) |
michael@0 | 140 | (peephole (infix 2 2 "===")) |
michael@0 | 141 | (type bool)) |
michael@0 | 142 | */ |
michael@0 | 143 | function sc_isEqv(o1, o2) { |
michael@0 | 144 | return (o1 === o2); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | /*** META ((export #t) |
michael@0 | 148 | (peephole (infix 2 2 "===")) |
michael@0 | 149 | (type bool)) |
michael@0 | 150 | */ |
michael@0 | 151 | function sc_isEq(o1, o2) { |
michael@0 | 152 | return (o1 === o2); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | /*** META ((export #t) |
michael@0 | 156 | (type bool)) |
michael@0 | 157 | */ |
michael@0 | 158 | function sc_isNumber(n) { |
michael@0 | 159 | return (typeof n === "number"); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | /*** META ((export #t) |
michael@0 | 163 | (type bool)) |
michael@0 | 164 | */ |
michael@0 | 165 | function sc_isComplex(n) { |
michael@0 | 166 | return sc_isNumber(n); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | /*** META ((export #t) |
michael@0 | 170 | (type bool)) |
michael@0 | 171 | */ |
michael@0 | 172 | function sc_isReal(n) { |
michael@0 | 173 | return sc_isNumber(n); |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | /*** META ((export #t) |
michael@0 | 177 | (type bool)) |
michael@0 | 178 | */ |
michael@0 | 179 | function sc_isRational(n) { |
michael@0 | 180 | return sc_isReal(n); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | /*** META ((export #t) |
michael@0 | 184 | (type bool)) |
michael@0 | 185 | */ |
michael@0 | 186 | function sc_isInteger(n) { |
michael@0 | 187 | return (parseInt(n) === n); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | /*** META ((export #t) |
michael@0 | 191 | (type bool) |
michael@0 | 192 | (peephole (postfix ", false"))) |
michael@0 | 193 | */ |
michael@0 | 194 | // we don't have exact numbers... |
michael@0 | 195 | function sc_isExact(n) { |
michael@0 | 196 | return false; |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | /*** META ((export #t) |
michael@0 | 200 | (peephole (postfix ", true")) |
michael@0 | 201 | (type bool)) |
michael@0 | 202 | */ |
michael@0 | 203 | function sc_isInexact(n) { |
michael@0 | 204 | return true; |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | /*** META ((export = =fx =fl) |
michael@0 | 208 | (type bool) |
michael@0 | 209 | (peephole (infix 2 2 "==="))) |
michael@0 | 210 | */ |
michael@0 | 211 | function sc_equal(x) { |
michael@0 | 212 | for (var i = 1; i < arguments.length; i++) |
michael@0 | 213 | if (x !== arguments[i]) |
michael@0 | 214 | return false; |
michael@0 | 215 | return true; |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | /*** META ((export < <fx <fl) |
michael@0 | 219 | (type bool) |
michael@0 | 220 | (peephole (infix 2 2 "<"))) |
michael@0 | 221 | */ |
michael@0 | 222 | function sc_less(x) { |
michael@0 | 223 | for (var i = 1; i < arguments.length; i++) { |
michael@0 | 224 | if (x >= arguments[i]) |
michael@0 | 225 | return false; |
michael@0 | 226 | x = arguments[i]; |
michael@0 | 227 | } |
michael@0 | 228 | return true; |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | /*** META ((export > >fx >fl) |
michael@0 | 232 | (type bool) |
michael@0 | 233 | (peephole (infix 2 2 ">"))) |
michael@0 | 234 | */ |
michael@0 | 235 | function sc_greater(x, y) { |
michael@0 | 236 | for (var i = 1; i < arguments.length; i++) { |
michael@0 | 237 | if (x <= arguments[i]) |
michael@0 | 238 | return false; |
michael@0 | 239 | x = arguments[i]; |
michael@0 | 240 | } |
michael@0 | 241 | return true; |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | /*** META ((export <= <=fx <=fl) |
michael@0 | 245 | (type bool) |
michael@0 | 246 | (peephole (infix 2 2 "<="))) |
michael@0 | 247 | */ |
michael@0 | 248 | function sc_lessEqual(x, y) { |
michael@0 | 249 | for (var i = 1; i < arguments.length; i++) { |
michael@0 | 250 | if (x > arguments[i]) |
michael@0 | 251 | return false; |
michael@0 | 252 | x = arguments[i]; |
michael@0 | 253 | } |
michael@0 | 254 | return true; |
michael@0 | 255 | } |
michael@0 | 256 | |
michael@0 | 257 | /*** META ((export >= >=fl >=fx) |
michael@0 | 258 | (type bool) |
michael@0 | 259 | (peephole (infix 2 2 ">="))) |
michael@0 | 260 | */ |
michael@0 | 261 | function sc_greaterEqual(x, y) { |
michael@0 | 262 | for (var i = 1; i < arguments.length; i++) { |
michael@0 | 263 | if (x < arguments[i]) |
michael@0 | 264 | return false; |
michael@0 | 265 | x = arguments[i]; |
michael@0 | 266 | } |
michael@0 | 267 | return true; |
michael@0 | 268 | } |
michael@0 | 269 | |
michael@0 | 270 | /*** META ((export #t) |
michael@0 | 271 | (type bool) |
michael@0 | 272 | (peephole (postfix "=== 0"))) |
michael@0 | 273 | */ |
michael@0 | 274 | function sc_isZero(x) { |
michael@0 | 275 | return (x === 0); |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | /*** META ((export #t) |
michael@0 | 279 | (type bool) |
michael@0 | 280 | (peephole (postfix "> 0"))) |
michael@0 | 281 | */ |
michael@0 | 282 | function sc_isPositive(x) { |
michael@0 | 283 | return (x > 0); |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | /*** META ((export #t) |
michael@0 | 287 | (type bool) |
michael@0 | 288 | (peephole (postfix "< 0"))) |
michael@0 | 289 | */ |
michael@0 | 290 | function sc_isNegative(x) { |
michael@0 | 291 | return (x < 0); |
michael@0 | 292 | } |
michael@0 | 293 | |
michael@0 | 294 | /*** META ((export #t) |
michael@0 | 295 | (type bool) |
michael@0 | 296 | (peephole (postfix "%2===1"))) |
michael@0 | 297 | */ |
michael@0 | 298 | function sc_isOdd(x) { |
michael@0 | 299 | return (x % 2 === 1); |
michael@0 | 300 | } |
michael@0 | 301 | |
michael@0 | 302 | /*** META ((export #t) |
michael@0 | 303 | (type bool) |
michael@0 | 304 | (peephole (postfix "%2===0"))) |
michael@0 | 305 | */ |
michael@0 | 306 | function sc_isEven(x) { |
michael@0 | 307 | return (x % 2 === 0); |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | /*** META ((export #t)) */ |
michael@0 | 311 | var sc_max = Math.max; |
michael@0 | 312 | /*** META ((export #t)) */ |
michael@0 | 313 | var sc_min = Math.min; |
michael@0 | 314 | |
michael@0 | 315 | /*** META ((export + +fx +fl) |
michael@0 | 316 | (peephole (infix 0 #f "+" "0"))) |
michael@0 | 317 | */ |
michael@0 | 318 | function sc_plus() { |
michael@0 | 319 | var sum = 0; |
michael@0 | 320 | for (var i = 0; i < arguments.length; i++) |
michael@0 | 321 | sum += arguments[i]; |
michael@0 | 322 | return sum; |
michael@0 | 323 | } |
michael@0 | 324 | |
michael@0 | 325 | /*** META ((export * *fx *fl) |
michael@0 | 326 | (peephole (infix 0 #f "*" "1"))) |
michael@0 | 327 | */ |
michael@0 | 328 | function sc_multi() { |
michael@0 | 329 | var product = 1; |
michael@0 | 330 | for (var i = 0; i < arguments.length; i++) |
michael@0 | 331 | product *= arguments[i]; |
michael@0 | 332 | return product; |
michael@0 | 333 | } |
michael@0 | 334 | |
michael@0 | 335 | /*** META ((export - -fx -fl) |
michael@0 | 336 | (peephole (minus))) |
michael@0 | 337 | */ |
michael@0 | 338 | function sc_minus(x) { |
michael@0 | 339 | if (arguments.length === 1) |
michael@0 | 340 | return -x; |
michael@0 | 341 | else { |
michael@0 | 342 | var res = x; |
michael@0 | 343 | for (var i = 1; i < arguments.length; i++) |
michael@0 | 344 | res -= arguments[i]; |
michael@0 | 345 | return res; |
michael@0 | 346 | } |
michael@0 | 347 | } |
michael@0 | 348 | |
michael@0 | 349 | /*** META ((export / /fl) |
michael@0 | 350 | (peephole (div))) |
michael@0 | 351 | */ |
michael@0 | 352 | function sc_div(x) { |
michael@0 | 353 | if (arguments.length === 1) |
michael@0 | 354 | return 1/x; |
michael@0 | 355 | else { |
michael@0 | 356 | var res = x; |
michael@0 | 357 | for (var i = 1; i < arguments.length; i++) |
michael@0 | 358 | res /= arguments[i]; |
michael@0 | 359 | return res; |
michael@0 | 360 | } |
michael@0 | 361 | } |
michael@0 | 362 | |
michael@0 | 363 | /*** META ((export #t)) */ |
michael@0 | 364 | var sc_abs = Math.abs; |
michael@0 | 365 | |
michael@0 | 366 | /*** META ((export quotient /fx) |
michael@0 | 367 | (peephole (hole 2 "parseInt(" x "/" y ")"))) |
michael@0 | 368 | */ |
michael@0 | 369 | function sc_quotient(x, y) { |
michael@0 | 370 | return parseInt(x / y); |
michael@0 | 371 | } |
michael@0 | 372 | |
michael@0 | 373 | /*** META ((export #t) |
michael@0 | 374 | (peephole (infix 2 2 "%"))) |
michael@0 | 375 | */ |
michael@0 | 376 | function sc_remainder(x, y) { |
michael@0 | 377 | return x % y; |
michael@0 | 378 | } |
michael@0 | 379 | |
michael@0 | 380 | /*** META ((export #t) |
michael@0 | 381 | (peephole (modulo))) |
michael@0 | 382 | */ |
michael@0 | 383 | function sc_modulo(x, y) { |
michael@0 | 384 | var remainder = x % y; |
michael@0 | 385 | // if they don't have the same sign |
michael@0 | 386 | if ((remainder * y) < 0) |
michael@0 | 387 | return remainder + y; |
michael@0 | 388 | else |
michael@0 | 389 | return remainder; |
michael@0 | 390 | } |
michael@0 | 391 | |
michael@0 | 392 | function sc_euclid_gcd(a, b) { |
michael@0 | 393 | var temp; |
michael@0 | 394 | if (a === 0) return b; |
michael@0 | 395 | if (b === 0) return a; |
michael@0 | 396 | if (a < 0) {a = -a;}; |
michael@0 | 397 | if (b < 0) {b = -b;}; |
michael@0 | 398 | if (b > a) {temp = a; a = b; b = temp;}; |
michael@0 | 399 | while (true) { |
michael@0 | 400 | a %= b; |
michael@0 | 401 | if(a === 0) {return b;}; |
michael@0 | 402 | b %= a; |
michael@0 | 403 | if(b === 0) {return a;}; |
michael@0 | 404 | }; |
michael@0 | 405 | return b; |
michael@0 | 406 | } |
michael@0 | 407 | |
michael@0 | 408 | /*** META ((export #t)) */ |
michael@0 | 409 | function sc_gcd() { |
michael@0 | 410 | var gcd = 0; |
michael@0 | 411 | for (var i = 0; i < arguments.length; i++) |
michael@0 | 412 | gcd = sc_euclid_gcd(gcd, arguments[i]); |
michael@0 | 413 | return gcd; |
michael@0 | 414 | } |
michael@0 | 415 | |
michael@0 | 416 | /*** META ((export #t)) */ |
michael@0 | 417 | function sc_lcm() { |
michael@0 | 418 | var lcm = 1; |
michael@0 | 419 | for (var i = 0; i < arguments.length; i++) { |
michael@0 | 420 | var f = Math.round(arguments[i] / sc_euclid_gcd(arguments[i], lcm)); |
michael@0 | 421 | lcm *= Math.abs(f); |
michael@0 | 422 | } |
michael@0 | 423 | return lcm; |
michael@0 | 424 | } |
michael@0 | 425 | |
michael@0 | 426 | // LIMITATION: numerator and denominator don't make sense in floating point world. |
michael@0 | 427 | //var SC_MAX_DECIMALS = 1000000 |
michael@0 | 428 | // |
michael@0 | 429 | // function sc_numerator(x) { |
michael@0 | 430 | // var rounded = Math.round(x * SC_MAX_DECIMALS); |
michael@0 | 431 | // return Math.round(rounded / sc_euclid_gcd(rounded, SC_MAX_DECIMALS)); |
michael@0 | 432 | // } |
michael@0 | 433 | |
michael@0 | 434 | // function sc_denominator(x) { |
michael@0 | 435 | // var rounded = Math.round(x * SC_MAX_DECIMALS); |
michael@0 | 436 | // return Math.round(SC_MAX_DECIMALS / sc_euclid_gcd(rounded, SC_MAX_DECIMALS)); |
michael@0 | 437 | // } |
michael@0 | 438 | |
michael@0 | 439 | /*** META ((export #t)) */ |
michael@0 | 440 | var sc_floor = Math.floor; |
michael@0 | 441 | /*** META ((export #t)) */ |
michael@0 | 442 | var sc_ceiling = Math.ceil; |
michael@0 | 443 | /*** META ((export #t)) */ |
michael@0 | 444 | var sc_truncate = parseInt; |
michael@0 | 445 | /*** META ((export #t)) */ |
michael@0 | 446 | var sc_round = Math.round; |
michael@0 | 447 | |
michael@0 | 448 | // LIMITATION: sc_rationalize doesn't make sense in a floating point world. |
michael@0 | 449 | |
michael@0 | 450 | /*** META ((export #t)) */ |
michael@0 | 451 | var sc_exp = Math.exp; |
michael@0 | 452 | /*** META ((export #t)) */ |
michael@0 | 453 | var sc_log = Math.log; |
michael@0 | 454 | /*** META ((export #t)) */ |
michael@0 | 455 | var sc_sin = Math.sin; |
michael@0 | 456 | /*** META ((export #t)) */ |
michael@0 | 457 | var sc_cos = Math.cos; |
michael@0 | 458 | /*** META ((export #t)) */ |
michael@0 | 459 | var sc_tan = Math.tan; |
michael@0 | 460 | /*** META ((export #t)) */ |
michael@0 | 461 | var sc_asin = Math.asin; |
michael@0 | 462 | /*** META ((export #t)) */ |
michael@0 | 463 | var sc_acos = Math.acos; |
michael@0 | 464 | /*** META ((export #t)) */ |
michael@0 | 465 | var sc_atan = Math.atan; |
michael@0 | 466 | |
michael@0 | 467 | /*** META ((export #t)) */ |
michael@0 | 468 | var sc_sqrt = Math.sqrt; |
michael@0 | 469 | /*** META ((export #t)) */ |
michael@0 | 470 | var sc_expt = Math.pow; |
michael@0 | 471 | |
michael@0 | 472 | // LIMITATION: we don't have complex numbers. |
michael@0 | 473 | // LIMITATION: the following functions are hence not implemented. |
michael@0 | 474 | // LIMITATION: make-rectangular, make-polar, real-part, imag-part, magnitude, angle |
michael@0 | 475 | // LIMITATION: 2 argument atan |
michael@0 | 476 | |
michael@0 | 477 | /*** META ((export #t) |
michael@0 | 478 | (peephole (id))) |
michael@0 | 479 | */ |
michael@0 | 480 | function sc_exact2inexact(x) { |
michael@0 | 481 | return x; |
michael@0 | 482 | } |
michael@0 | 483 | |
michael@0 | 484 | /*** META ((export #t) |
michael@0 | 485 | (peephole (id))) |
michael@0 | 486 | */ |
michael@0 | 487 | function sc_inexact2exact(x) { |
michael@0 | 488 | return x; |
michael@0 | 489 | } |
michael@0 | 490 | |
michael@0 | 491 | function sc_number2jsstring(x, radix) { |
michael@0 | 492 | if (radix) |
michael@0 | 493 | return x.toString(radix); |
michael@0 | 494 | else |
michael@0 | 495 | return x.toString(); |
michael@0 | 496 | } |
michael@0 | 497 | |
michael@0 | 498 | function sc_jsstring2number(s, radix) { |
michael@0 | 499 | if (s === "") return false; |
michael@0 | 500 | |
michael@0 | 501 | if (radix) { |
michael@0 | 502 | var t = parseInt(s, radix); |
michael@0 | 503 | if (!t && t !== 0) return false; |
michael@0 | 504 | // verify that each char is in range. (parseInt ignores leading |
michael@0 | 505 | // white and trailing chars) |
michael@0 | 506 | var allowedChars = "01234567890abcdefghijklmnopqrstuvwxyz".substring(0, radix+1); |
michael@0 | 507 | if ((new RegExp("^["+allowedChars+"]*$", "i")).test(s)) |
michael@0 | 508 | return t; |
michael@0 | 509 | else return false; |
michael@0 | 510 | } else { |
michael@0 | 511 | var t = +s; // does not ignore trailing chars. |
michael@0 | 512 | if (!t && t !== 0) return false; |
michael@0 | 513 | // simply verify that first char is not whitespace. |
michael@0 | 514 | var c = s.charAt(0); |
michael@0 | 515 | // if +c is 0, but the char is not "0", then we have a whitespace. |
michael@0 | 516 | if (+c === 0 && c !== "0") return false; |
michael@0 | 517 | return t; |
michael@0 | 518 | } |
michael@0 | 519 | } |
michael@0 | 520 | |
michael@0 | 521 | /*** META ((export #t) |
michael@0 | 522 | (type bool) |
michael@0 | 523 | (peephole (not))) |
michael@0 | 524 | */ |
michael@0 | 525 | function sc_not(b) { |
michael@0 | 526 | return b === false; |
michael@0 | 527 | } |
michael@0 | 528 | |
michael@0 | 529 | /*** META ((export #t) |
michael@0 | 530 | (type bool)) |
michael@0 | 531 | */ |
michael@0 | 532 | function sc_isBoolean(b) { |
michael@0 | 533 | return (b === true) || (b === false); |
michael@0 | 534 | } |
michael@0 | 535 | |
michael@0 | 536 | function sc_Pair(car, cdr) { |
michael@0 | 537 | this.car = car; |
michael@0 | 538 | this.cdr = cdr; |
michael@0 | 539 | } |
michael@0 | 540 | |
michael@0 | 541 | sc_Pair.prototype.toString = function() { |
michael@0 | 542 | return sc_toDisplayString(this); |
michael@0 | 543 | }; |
michael@0 | 544 | sc_Pair.prototype.sc_toWriteOrDisplayString = function(writeOrDisplay) { |
michael@0 | 545 | var current = this; |
michael@0 | 546 | |
michael@0 | 547 | var res = "("; |
michael@0 | 548 | |
michael@0 | 549 | while(true) { |
michael@0 | 550 | res += writeOrDisplay(current.car); |
michael@0 | 551 | if (sc_isPair(current.cdr)) { |
michael@0 | 552 | res += " "; |
michael@0 | 553 | current = current.cdr; |
michael@0 | 554 | } else if (current.cdr !== null) { |
michael@0 | 555 | res += " . " + writeOrDisplay(current.cdr); |
michael@0 | 556 | break; |
michael@0 | 557 | } else // current.cdr == null |
michael@0 | 558 | break; |
michael@0 | 559 | } |
michael@0 | 560 | |
michael@0 | 561 | res += ")"; |
michael@0 | 562 | |
michael@0 | 563 | return res; |
michael@0 | 564 | }; |
michael@0 | 565 | sc_Pair.prototype.sc_toDisplayString = function() { |
michael@0 | 566 | return this.sc_toWriteOrDisplayString(sc_toDisplayString); |
michael@0 | 567 | }; |
michael@0 | 568 | sc_Pair.prototype.sc_toWriteString = function() { |
michael@0 | 569 | return this.sc_toWriteOrDisplayString(sc_toWriteString); |
michael@0 | 570 | }; |
michael@0 | 571 | // sc_Pair.prototype.sc_toWriteCircleString in IO.js |
michael@0 | 572 | |
michael@0 | 573 | /*** META ((export #t) |
michael@0 | 574 | (type bool) |
michael@0 | 575 | (peephole (postfix " instanceof sc_Pair"))) |
michael@0 | 576 | */ |
michael@0 | 577 | function sc_isPair(p) { |
michael@0 | 578 | return (p instanceof sc_Pair); |
michael@0 | 579 | } |
michael@0 | 580 | |
michael@0 | 581 | function sc_isPairEqual(p1, p2, comp) { |
michael@0 | 582 | return (comp(p1.car, p2.car) && comp(p1.cdr, p2.cdr)); |
michael@0 | 583 | } |
michael@0 | 584 | |
michael@0 | 585 | /*** META ((export #t) |
michael@0 | 586 | (peephole (hole 2 "new sc_Pair(" car ", " cdr ")"))) |
michael@0 | 587 | */ |
michael@0 | 588 | function sc_cons(car, cdr) { |
michael@0 | 589 | return new sc_Pair(car, cdr); |
michael@0 | 590 | } |
michael@0 | 591 | |
michael@0 | 592 | /*** META ((export cons*)) */ |
michael@0 | 593 | function sc_consStar() { |
michael@0 | 594 | var res = arguments[arguments.length - 1]; |
michael@0 | 595 | for (var i = arguments.length-2; i >= 0; i--) |
michael@0 | 596 | res = new sc_Pair(arguments[i], res); |
michael@0 | 597 | return res; |
michael@0 | 598 | } |
michael@0 | 599 | |
michael@0 | 600 | /*** META ((export #t) |
michael@0 | 601 | (peephole (postfix ".car"))) |
michael@0 | 602 | */ |
michael@0 | 603 | function sc_car(p) { |
michael@0 | 604 | return p.car; |
michael@0 | 605 | } |
michael@0 | 606 | |
michael@0 | 607 | /*** META ((export #t) |
michael@0 | 608 | (peephole (postfix ".cdr"))) |
michael@0 | 609 | */ |
michael@0 | 610 | function sc_cdr(p) { |
michael@0 | 611 | return p.cdr; |
michael@0 | 612 | } |
michael@0 | 613 | |
michael@0 | 614 | /*** META ((export #t) |
michael@0 | 615 | (peephole (hole 2 p ".car = " val))) |
michael@0 | 616 | */ |
michael@0 | 617 | function sc_setCarBang(p, val) { |
michael@0 | 618 | p.car = val; |
michael@0 | 619 | } |
michael@0 | 620 | |
michael@0 | 621 | /*** META ((export #t) |
michael@0 | 622 | (peephole (hole 2 p ".cdr = " val))) |
michael@0 | 623 | */ |
michael@0 | 624 | function sc_setCdrBang(p, val) { |
michael@0 | 625 | p.cdr = val; |
michael@0 | 626 | } |
michael@0 | 627 | |
michael@0 | 628 | /*** META ((export #t) |
michael@0 | 629 | (peephole (postfix ".car.car"))) |
michael@0 | 630 | */ |
michael@0 | 631 | function sc_caar(p) { return p.car.car; } |
michael@0 | 632 | /*** META ((export #t) |
michael@0 | 633 | (peephole (postfix ".cdr.car"))) |
michael@0 | 634 | */ |
michael@0 | 635 | function sc_cadr(p) { return p.cdr.car; } |
michael@0 | 636 | /*** META ((export #t) |
michael@0 | 637 | (peephole (postfix ".car.cdr"))) |
michael@0 | 638 | */ |
michael@0 | 639 | function sc_cdar(p) { return p.car.cdr; } |
michael@0 | 640 | /*** META ((export #t) |
michael@0 | 641 | (peephole (postfix ".cdr.cdr"))) |
michael@0 | 642 | */ |
michael@0 | 643 | function sc_cddr(p) { return p.cdr.cdr; } |
michael@0 | 644 | /*** META ((export #t) |
michael@0 | 645 | (peephole (postfix ".car.car.car"))) |
michael@0 | 646 | */ |
michael@0 | 647 | function sc_caaar(p) { return p.car.car.car; } |
michael@0 | 648 | /*** META ((export #t) |
michael@0 | 649 | (peephole (postfix ".car.cdr.car"))) |
michael@0 | 650 | */ |
michael@0 | 651 | function sc_cadar(p) { return p.car.cdr.car; } |
michael@0 | 652 | /*** META ((export #t) |
michael@0 | 653 | (peephole (postfix ".cdr.car.car"))) |
michael@0 | 654 | */ |
michael@0 | 655 | function sc_caadr(p) { return p.cdr.car.car; } |
michael@0 | 656 | /*** META ((export #t) |
michael@0 | 657 | (peephole (postfix ".cdr.cdr.car"))) |
michael@0 | 658 | */ |
michael@0 | 659 | function sc_caddr(p) { return p.cdr.cdr.car; } |
michael@0 | 660 | /*** META ((export #t) |
michael@0 | 661 | (peephole (postfix ".car.car.cdr"))) |
michael@0 | 662 | */ |
michael@0 | 663 | function sc_cdaar(p) { return p.car.car.cdr; } |
michael@0 | 664 | /*** META ((export #t) |
michael@0 | 665 | (peephole (postfix ".cdr.car.cdr"))) |
michael@0 | 666 | */ |
michael@0 | 667 | function sc_cdadr(p) { return p.cdr.car.cdr; } |
michael@0 | 668 | /*** META ((export #t) |
michael@0 | 669 | (peephole (postfix ".car.cdr.cdr"))) |
michael@0 | 670 | */ |
michael@0 | 671 | function sc_cddar(p) { return p.car.cdr.cdr; } |
michael@0 | 672 | /*** META ((export #t) |
michael@0 | 673 | (peephole (postfix ".cdr.cdr.cdr"))) |
michael@0 | 674 | */ |
michael@0 | 675 | function sc_cdddr(p) { return p.cdr.cdr.cdr; } |
michael@0 | 676 | /*** META ((export #t) |
michael@0 | 677 | (peephole (postfix ".car.car.car.car"))) |
michael@0 | 678 | */ |
michael@0 | 679 | function sc_caaaar(p) { return p.car.car.car.car; } |
michael@0 | 680 | /*** META ((export #t) |
michael@0 | 681 | (peephole (postfix ".car.cdr.car.car"))) |
michael@0 | 682 | */ |
michael@0 | 683 | function sc_caadar(p) { return p.car.cdr.car.car; } |
michael@0 | 684 | /*** META ((export #t) |
michael@0 | 685 | (peephole (postfix ".cdr.car.car.car"))) |
michael@0 | 686 | */ |
michael@0 | 687 | function sc_caaadr(p) { return p.cdr.car.car.car; } |
michael@0 | 688 | /*** META ((export #t) |
michael@0 | 689 | (peephole (postfix ".cdr.cdr.car.car"))) |
michael@0 | 690 | */ |
michael@0 | 691 | function sc_caaddr(p) { return p.cdr.cdr.car.car; } |
michael@0 | 692 | /*** META ((export #t) |
michael@0 | 693 | (peephole (postfix ".car.car.car.cdr"))) |
michael@0 | 694 | */ |
michael@0 | 695 | function sc_cdaaar(p) { return p.car.car.car.cdr; } |
michael@0 | 696 | /*** META ((export #t) |
michael@0 | 697 | (peephole (postfix ".car.cdr.car.cdr"))) |
michael@0 | 698 | */ |
michael@0 | 699 | function sc_cdadar(p) { return p.car.cdr.car.cdr; } |
michael@0 | 700 | /*** META ((export #t) |
michael@0 | 701 | (peephole (postfix ".cdr.car.car.cdr"))) |
michael@0 | 702 | */ |
michael@0 | 703 | function sc_cdaadr(p) { return p.cdr.car.car.cdr; } |
michael@0 | 704 | /*** META ((export #t) |
michael@0 | 705 | (peephole (postfix ".cdr.cdr.car.cdr"))) |
michael@0 | 706 | */ |
michael@0 | 707 | function sc_cdaddr(p) { return p.cdr.cdr.car.cdr; } |
michael@0 | 708 | /*** META ((export #t) |
michael@0 | 709 | (peephole (postfix ".car.car.cdr.car"))) |
michael@0 | 710 | */ |
michael@0 | 711 | function sc_cadaar(p) { return p.car.car.cdr.car; } |
michael@0 | 712 | /*** META ((export #t) |
michael@0 | 713 | (peephole (postfix ".car.cdr.cdr.car"))) |
michael@0 | 714 | */ |
michael@0 | 715 | function sc_caddar(p) { return p.car.cdr.cdr.car; } |
michael@0 | 716 | /*** META ((export #t) |
michael@0 | 717 | (peephole (postfix ".cdr.car.cdr.car"))) |
michael@0 | 718 | */ |
michael@0 | 719 | function sc_cadadr(p) { return p.cdr.car.cdr.car; } |
michael@0 | 720 | /*** META ((export #t) |
michael@0 | 721 | (peephole (postfix ".cdr.cdr.cdr.car"))) |
michael@0 | 722 | */ |
michael@0 | 723 | function sc_cadddr(p) { return p.cdr.cdr.cdr.car; } |
michael@0 | 724 | /*** META ((export #t) |
michael@0 | 725 | (peephole (postfix ".car.car.cdr.cdr"))) |
michael@0 | 726 | */ |
michael@0 | 727 | function sc_cddaar(p) { return p.car.car.cdr.cdr; } |
michael@0 | 728 | /*** META ((export #t) |
michael@0 | 729 | (peephole (postfix ".car.cdr.cdr.cdr"))) |
michael@0 | 730 | */ |
michael@0 | 731 | function sc_cdddar(p) { return p.car.cdr.cdr.cdr; } |
michael@0 | 732 | /*** META ((export #t) |
michael@0 | 733 | (peephole (postfix ".cdr.car.cdr.cdr"))) |
michael@0 | 734 | */ |
michael@0 | 735 | function sc_cddadr(p) { return p.cdr.car.cdr.cdr; } |
michael@0 | 736 | /*** META ((export #t) |
michael@0 | 737 | (peephole (postfix ".cdr.cdr.cdr.cdr"))) |
michael@0 | 738 | */ |
michael@0 | 739 | function sc_cddddr(p) { return p.cdr.cdr.cdr.cdr; } |
michael@0 | 740 | |
michael@0 | 741 | /*** META ((export #t)) */ |
michael@0 | 742 | function sc_lastPair(l) { |
michael@0 | 743 | if (!sc_isPair(l)) sc_error("sc_lastPair: pair expected"); |
michael@0 | 744 | var res = l; |
michael@0 | 745 | var cdr = l.cdr; |
michael@0 | 746 | while (sc_isPair(cdr)) { |
michael@0 | 747 | res = cdr; |
michael@0 | 748 | cdr = res.cdr; |
michael@0 | 749 | } |
michael@0 | 750 | return res; |
michael@0 | 751 | } |
michael@0 | 752 | |
michael@0 | 753 | /*** META ((export #t) |
michael@0 | 754 | (type bool) |
michael@0 | 755 | (peephole (postfix " === null"))) |
michael@0 | 756 | */ |
michael@0 | 757 | function sc_isNull(o) { |
michael@0 | 758 | return (o === null); |
michael@0 | 759 | } |
michael@0 | 760 | |
michael@0 | 761 | /*** META ((export #t) |
michael@0 | 762 | (type bool)) |
michael@0 | 763 | */ |
michael@0 | 764 | function sc_isList(o) { |
michael@0 | 765 | var rabbit; |
michael@0 | 766 | var turtle; |
michael@0 | 767 | |
michael@0 | 768 | var rabbit = o; |
michael@0 | 769 | var turtle = o; |
michael@0 | 770 | while (true) { |
michael@0 | 771 | if (rabbit === null || |
michael@0 | 772 | (rabbit instanceof sc_Pair && rabbit.cdr === null)) |
michael@0 | 773 | return true; // end of list |
michael@0 | 774 | else if ((rabbit instanceof sc_Pair) && |
michael@0 | 775 | (rabbit.cdr instanceof sc_Pair)) { |
michael@0 | 776 | rabbit = rabbit.cdr.cdr; |
michael@0 | 777 | turtle = turtle.cdr; |
michael@0 | 778 | if (rabbit === turtle) return false; // cycle |
michael@0 | 779 | } else |
michael@0 | 780 | return false; // not pair |
michael@0 | 781 | } |
michael@0 | 782 | } |
michael@0 | 783 | |
michael@0 | 784 | /*** META ((export #t)) */ |
michael@0 | 785 | function sc_list() { |
michael@0 | 786 | var res = null; |
michael@0 | 787 | var a = arguments; |
michael@0 | 788 | for (var i = a.length-1; i >= 0; i--) |
michael@0 | 789 | res = new sc_Pair(a[i], res); |
michael@0 | 790 | return res; |
michael@0 | 791 | } |
michael@0 | 792 | |
michael@0 | 793 | /*** META ((export #t)) */ |
michael@0 | 794 | function sc_iota(num, init) { |
michael@0 | 795 | var res = null; |
michael@0 | 796 | if (!init) init = 0; |
michael@0 | 797 | for (var i = num - 1; i >= 0; i--) |
michael@0 | 798 | res = new sc_Pair(i + init, res); |
michael@0 | 799 | return res; |
michael@0 | 800 | } |
michael@0 | 801 | |
michael@0 | 802 | /*** META ((export #t)) */ |
michael@0 | 803 | function sc_makeList(nbEls, fill) { |
michael@0 | 804 | var res = null; |
michael@0 | 805 | for (var i = 0; i < nbEls; i++) |
michael@0 | 806 | res = new sc_Pair(fill, res); |
michael@0 | 807 | return res; |
michael@0 | 808 | } |
michael@0 | 809 | |
michael@0 | 810 | /*** META ((export #t)) */ |
michael@0 | 811 | function sc_length(l) { |
michael@0 | 812 | var res = 0; |
michael@0 | 813 | while (l !== null) { |
michael@0 | 814 | res++; |
michael@0 | 815 | l = l.cdr; |
michael@0 | 816 | } |
michael@0 | 817 | return res; |
michael@0 | 818 | } |
michael@0 | 819 | |
michael@0 | 820 | /*** META ((export #t)) */ |
michael@0 | 821 | function sc_remq(o, l) { |
michael@0 | 822 | var dummy = { cdr : null }; |
michael@0 | 823 | var tail = dummy; |
michael@0 | 824 | while (l !== null) { |
michael@0 | 825 | if (l.car !== o) { |
michael@0 | 826 | tail.cdr = sc_cons(l.car, null); |
michael@0 | 827 | tail = tail.cdr; |
michael@0 | 828 | } |
michael@0 | 829 | l = l.cdr; |
michael@0 | 830 | } |
michael@0 | 831 | return dummy.cdr; |
michael@0 | 832 | } |
michael@0 | 833 | |
michael@0 | 834 | /*** META ((export #t)) */ |
michael@0 | 835 | function sc_remqBang(o, l) { |
michael@0 | 836 | var dummy = { cdr : null }; |
michael@0 | 837 | var tail = dummy; |
michael@0 | 838 | var needsAssig = true; |
michael@0 | 839 | while (l !== null) { |
michael@0 | 840 | if (l.car === o) { |
michael@0 | 841 | needsAssig = true; |
michael@0 | 842 | } else { |
michael@0 | 843 | if (needsAssig) { |
michael@0 | 844 | tail.cdr = l; |
michael@0 | 845 | needsAssig = false; |
michael@0 | 846 | } |
michael@0 | 847 | tail = l; |
michael@0 | 848 | } |
michael@0 | 849 | l = l.cdr; |
michael@0 | 850 | } |
michael@0 | 851 | tail.cdr = null; |
michael@0 | 852 | return dummy.cdr; |
michael@0 | 853 | } |
michael@0 | 854 | |
michael@0 | 855 | /*** META ((export #t)) */ |
michael@0 | 856 | function sc_delete(o, l) { |
michael@0 | 857 | var dummy = { cdr : null }; |
michael@0 | 858 | var tail = dummy; |
michael@0 | 859 | while (l !== null) { |
michael@0 | 860 | if (!sc_isEqual(l.car, o)) { |
michael@0 | 861 | tail.cdr = sc_cons(l.car, null); |
michael@0 | 862 | tail = tail.cdr; |
michael@0 | 863 | } |
michael@0 | 864 | l = l.cdr; |
michael@0 | 865 | } |
michael@0 | 866 | return dummy.cdr; |
michael@0 | 867 | } |
michael@0 | 868 | |
michael@0 | 869 | /*** META ((export #t)) */ |
michael@0 | 870 | function sc_deleteBang(o, l) { |
michael@0 | 871 | var dummy = { cdr : null }; |
michael@0 | 872 | var tail = dummy; |
michael@0 | 873 | var needsAssig = true; |
michael@0 | 874 | while (l !== null) { |
michael@0 | 875 | if (sc_isEqual(l.car, o)) { |
michael@0 | 876 | needsAssig = true; |
michael@0 | 877 | } else { |
michael@0 | 878 | if (needsAssig) { |
michael@0 | 879 | tail.cdr = l; |
michael@0 | 880 | needsAssig = false; |
michael@0 | 881 | } |
michael@0 | 882 | tail = l; |
michael@0 | 883 | } |
michael@0 | 884 | l = l.cdr; |
michael@0 | 885 | } |
michael@0 | 886 | tail.cdr = null; |
michael@0 | 887 | return dummy.cdr; |
michael@0 | 888 | } |
michael@0 | 889 | |
michael@0 | 890 | function sc_reverseAppendBang(l1, l2) { |
michael@0 | 891 | var res = l2; |
michael@0 | 892 | while (l1 !== null) { |
michael@0 | 893 | var tmp = res; |
michael@0 | 894 | res = l1; |
michael@0 | 895 | l1 = l1.cdr; |
michael@0 | 896 | res.cdr = tmp; |
michael@0 | 897 | } |
michael@0 | 898 | return res; |
michael@0 | 899 | } |
michael@0 | 900 | |
michael@0 | 901 | function sc_dualAppend(l1, l2) { |
michael@0 | 902 | if (l1 === null) return l2; |
michael@0 | 903 | if (l2 === null) return l1; |
michael@0 | 904 | var rev = sc_reverse(l1); |
michael@0 | 905 | return sc_reverseAppendBang(rev, l2); |
michael@0 | 906 | } |
michael@0 | 907 | |
michael@0 | 908 | /*** META ((export #t)) */ |
michael@0 | 909 | function sc_append() { |
michael@0 | 910 | if (arguments.length === 0) |
michael@0 | 911 | return null; |
michael@0 | 912 | var res = arguments[arguments.length - 1]; |
michael@0 | 913 | for (var i = arguments.length - 2; i >= 0; i--) |
michael@0 | 914 | res = sc_dualAppend(arguments[i], res); |
michael@0 | 915 | return res; |
michael@0 | 916 | } |
michael@0 | 917 | |
michael@0 | 918 | function sc_dualAppendBang(l1, l2) { |
michael@0 | 919 | if (l1 === null) return l2; |
michael@0 | 920 | if (l2 === null) return l1; |
michael@0 | 921 | var tmp = l1; |
michael@0 | 922 | while (tmp.cdr !== null) tmp=tmp.cdr; |
michael@0 | 923 | tmp.cdr = l2; |
michael@0 | 924 | return l1; |
michael@0 | 925 | } |
michael@0 | 926 | |
michael@0 | 927 | /*** META ((export #t)) */ |
michael@0 | 928 | function sc_appendBang() { |
michael@0 | 929 | var res = null; |
michael@0 | 930 | for (var i = 0; i < arguments.length; i++) |
michael@0 | 931 | res = sc_dualAppendBang(res, arguments[i]); |
michael@0 | 932 | return res; |
michael@0 | 933 | } |
michael@0 | 934 | |
michael@0 | 935 | /*** META ((export #t)) */ |
michael@0 | 936 | function sc_reverse(l1) { |
michael@0 | 937 | var res = null; |
michael@0 | 938 | while (l1 !== null) { |
michael@0 | 939 | res = sc_cons(l1.car, res); |
michael@0 | 940 | l1 = l1.cdr; |
michael@0 | 941 | } |
michael@0 | 942 | return res; |
michael@0 | 943 | } |
michael@0 | 944 | |
michael@0 | 945 | /*** META ((export #t)) */ |
michael@0 | 946 | function sc_reverseBang(l) { |
michael@0 | 947 | return sc_reverseAppendBang(l, null); |
michael@0 | 948 | } |
michael@0 | 949 | |
michael@0 | 950 | /*** META ((export #t)) */ |
michael@0 | 951 | function sc_listTail(l, k) { |
michael@0 | 952 | var res = l; |
michael@0 | 953 | for (var i = 0; i < k; i++) { |
michael@0 | 954 | res = res.cdr; |
michael@0 | 955 | } |
michael@0 | 956 | return res; |
michael@0 | 957 | } |
michael@0 | 958 | |
michael@0 | 959 | /*** META ((export #t)) */ |
michael@0 | 960 | function sc_listRef(l, k) { |
michael@0 | 961 | return sc_listTail(l, k).car; |
michael@0 | 962 | } |
michael@0 | 963 | |
michael@0 | 964 | /* // unoptimized generic versions |
michael@0 | 965 | function sc_memX(o, l, comp) { |
michael@0 | 966 | while (l != null) { |
michael@0 | 967 | if (comp(l.car, o)) |
michael@0 | 968 | return l; |
michael@0 | 969 | l = l.cdr; |
michael@0 | 970 | } |
michael@0 | 971 | return false; |
michael@0 | 972 | } |
michael@0 | 973 | function sc_memq(o, l) { return sc_memX(o, l, sc_isEq); } |
michael@0 | 974 | function sc_memv(o, l) { return sc_memX(o, l, sc_isEqv); } |
michael@0 | 975 | function sc_member(o, l) { return sc_memX(o, l, sc_isEqual); } |
michael@0 | 976 | */ |
michael@0 | 977 | |
michael@0 | 978 | /* optimized versions */ |
michael@0 | 979 | /*** META ((export #t)) */ |
michael@0 | 980 | function sc_memq(o, l) { |
michael@0 | 981 | while (l !== null) { |
michael@0 | 982 | if (l.car === o) |
michael@0 | 983 | return l; |
michael@0 | 984 | l = l.cdr; |
michael@0 | 985 | } |
michael@0 | 986 | return false; |
michael@0 | 987 | } |
michael@0 | 988 | /*** META ((export #t)) */ |
michael@0 | 989 | function sc_memv(o, l) { |
michael@0 | 990 | while (l !== null) { |
michael@0 | 991 | if (l.car === o) |
michael@0 | 992 | return l; |
michael@0 | 993 | l = l.cdr; |
michael@0 | 994 | } |
michael@0 | 995 | return false; |
michael@0 | 996 | } |
michael@0 | 997 | /*** META ((export #t)) */ |
michael@0 | 998 | function sc_member(o, l) { |
michael@0 | 999 | while (l !== null) { |
michael@0 | 1000 | if (sc_isEqual(l.car,o)) |
michael@0 | 1001 | return l; |
michael@0 | 1002 | l = l.cdr; |
michael@0 | 1003 | } |
michael@0 | 1004 | return false; |
michael@0 | 1005 | } |
michael@0 | 1006 | |
michael@0 | 1007 | /* // generic unoptimized versions |
michael@0 | 1008 | function sc_assX(o, al, comp) { |
michael@0 | 1009 | while (al != null) { |
michael@0 | 1010 | if (comp(al.car.car, o)) |
michael@0 | 1011 | return al.car; |
michael@0 | 1012 | al = al.cdr; |
michael@0 | 1013 | } |
michael@0 | 1014 | return false; |
michael@0 | 1015 | } |
michael@0 | 1016 | function sc_assq(o, al) { return sc_assX(o, al, sc_isEq); } |
michael@0 | 1017 | function sc_assv(o, al) { return sc_assX(o, al, sc_isEqv); } |
michael@0 | 1018 | function sc_assoc(o, al) { return sc_assX(o, al, sc_isEqual); } |
michael@0 | 1019 | */ |
michael@0 | 1020 | // optimized versions |
michael@0 | 1021 | /*** META ((export #t)) */ |
michael@0 | 1022 | function sc_assq(o, al) { |
michael@0 | 1023 | while (al !== null) { |
michael@0 | 1024 | if (al.car.car === o) |
michael@0 | 1025 | return al.car; |
michael@0 | 1026 | al = al.cdr; |
michael@0 | 1027 | } |
michael@0 | 1028 | return false; |
michael@0 | 1029 | } |
michael@0 | 1030 | /*** META ((export #t)) */ |
michael@0 | 1031 | function sc_assv(o, al) { |
michael@0 | 1032 | while (al !== null) { |
michael@0 | 1033 | if (al.car.car === o) |
michael@0 | 1034 | return al.car; |
michael@0 | 1035 | al = al.cdr; |
michael@0 | 1036 | } |
michael@0 | 1037 | return false; |
michael@0 | 1038 | } |
michael@0 | 1039 | /*** META ((export #t)) */ |
michael@0 | 1040 | function sc_assoc(o, al) { |
michael@0 | 1041 | while (al !== null) { |
michael@0 | 1042 | if (sc_isEqual(al.car.car, o)) |
michael@0 | 1043 | return al.car; |
michael@0 | 1044 | al = al.cdr; |
michael@0 | 1045 | } |
michael@0 | 1046 | return false; |
michael@0 | 1047 | } |
michael@0 | 1048 | |
michael@0 | 1049 | /* can be used for mutable strings and characters */ |
michael@0 | 1050 | function sc_isCharStringEqual(cs1, cs2) { return cs1.val === cs2.val; } |
michael@0 | 1051 | function sc_isCharStringLess(cs1, cs2) { return cs1.val < cs2.val; } |
michael@0 | 1052 | function sc_isCharStringGreater(cs1, cs2) { return cs1.val > cs2.val; } |
michael@0 | 1053 | function sc_isCharStringLessEqual(cs1, cs2) { return cs1.val <= cs2.val; } |
michael@0 | 1054 | function sc_isCharStringGreaterEqual(cs1, cs2) { return cs1.val >= cs2.val; } |
michael@0 | 1055 | function sc_isCharStringCIEqual(cs1, cs2) |
michael@0 | 1056 | { return cs1.val.toLowerCase() === cs2.val.toLowerCase(); } |
michael@0 | 1057 | function sc_isCharStringCILess(cs1, cs2) |
michael@0 | 1058 | { return cs1.val.toLowerCase() < cs2.val.toLowerCase(); } |
michael@0 | 1059 | function sc_isCharStringCIGreater(cs1, cs2) |
michael@0 | 1060 | { return cs1.val.toLowerCase() > cs2.val.toLowerCase(); } |
michael@0 | 1061 | function sc_isCharStringCILessEqual(cs1, cs2) |
michael@0 | 1062 | { return cs1.val.toLowerCase() <= cs2.val.toLowerCase(); } |
michael@0 | 1063 | function sc_isCharStringCIGreaterEqual(cs1, cs2) |
michael@0 | 1064 | { return cs1.val.toLowerCase() >= cs2.val.toLowerCase(); } |
michael@0 | 1065 | |
michael@0 | 1066 | |
michael@0 | 1067 | |
michael@0 | 1068 | |
michael@0 | 1069 | function sc_Char(c) { |
michael@0 | 1070 | var cached = sc_Char.lazy[c]; |
michael@0 | 1071 | if (cached) |
michael@0 | 1072 | return cached; |
michael@0 | 1073 | this.val = c; |
michael@0 | 1074 | sc_Char.lazy[c] = this; |
michael@0 | 1075 | // add return, so FF does not complain. |
michael@0 | 1076 | return undefined; |
michael@0 | 1077 | } |
michael@0 | 1078 | sc_Char.lazy = new Object(); |
michael@0 | 1079 | // thanks to Eric |
michael@0 | 1080 | sc_Char.char2readable = { |
michael@0 | 1081 | "\000": "#\\null", |
michael@0 | 1082 | "\007": "#\\bell", |
michael@0 | 1083 | "\010": "#\\backspace", |
michael@0 | 1084 | "\011": "#\\tab", |
michael@0 | 1085 | "\012": "#\\newline", |
michael@0 | 1086 | "\014": "#\\page", |
michael@0 | 1087 | "\015": "#\\return", |
michael@0 | 1088 | "\033": "#\\escape", |
michael@0 | 1089 | "\040": "#\\space", |
michael@0 | 1090 | "\177": "#\\delete", |
michael@0 | 1091 | |
michael@0 | 1092 | /* poeticless names */ |
michael@0 | 1093 | "\001": "#\\soh", |
michael@0 | 1094 | "\002": "#\\stx", |
michael@0 | 1095 | "\003": "#\\etx", |
michael@0 | 1096 | "\004": "#\\eot", |
michael@0 | 1097 | "\005": "#\\enq", |
michael@0 | 1098 | "\006": "#\\ack", |
michael@0 | 1099 | |
michael@0 | 1100 | "\013": "#\\vt", |
michael@0 | 1101 | "\016": "#\\so", |
michael@0 | 1102 | "\017": "#\\si", |
michael@0 | 1103 | |
michael@0 | 1104 | "\020": "#\\dle", |
michael@0 | 1105 | "\021": "#\\dc1", |
michael@0 | 1106 | "\022": "#\\dc2", |
michael@0 | 1107 | "\023": "#\\dc3", |
michael@0 | 1108 | "\024": "#\\dc4", |
michael@0 | 1109 | "\025": "#\\nak", |
michael@0 | 1110 | "\026": "#\\syn", |
michael@0 | 1111 | "\027": "#\\etb", |
michael@0 | 1112 | |
michael@0 | 1113 | "\030": "#\\can", |
michael@0 | 1114 | "\031": "#\\em", |
michael@0 | 1115 | "\032": "#\\sub", |
michael@0 | 1116 | "\033": "#\\esc", |
michael@0 | 1117 | "\034": "#\\fs", |
michael@0 | 1118 | "\035": "#\\gs", |
michael@0 | 1119 | "\036": "#\\rs", |
michael@0 | 1120 | "\037": "#\\us"}; |
michael@0 | 1121 | |
michael@0 | 1122 | sc_Char.readable2char = { |
michael@0 | 1123 | "null": "\000", |
michael@0 | 1124 | "bell": "\007", |
michael@0 | 1125 | "backspace": "\010", |
michael@0 | 1126 | "tab": "\011", |
michael@0 | 1127 | "newline": "\012", |
michael@0 | 1128 | "page": "\014", |
michael@0 | 1129 | "return": "\015", |
michael@0 | 1130 | "escape": "\033", |
michael@0 | 1131 | "space": "\040", |
michael@0 | 1132 | "delete": "\000", |
michael@0 | 1133 | "soh": "\001", |
michael@0 | 1134 | "stx": "\002", |
michael@0 | 1135 | "etx": "\003", |
michael@0 | 1136 | "eot": "\004", |
michael@0 | 1137 | "enq": "\005", |
michael@0 | 1138 | "ack": "\006", |
michael@0 | 1139 | "bel": "\007", |
michael@0 | 1140 | "bs": "\010", |
michael@0 | 1141 | "ht": "\011", |
michael@0 | 1142 | "nl": "\012", |
michael@0 | 1143 | "vt": "\013", |
michael@0 | 1144 | "np": "\014", |
michael@0 | 1145 | "cr": "\015", |
michael@0 | 1146 | "so": "\016", |
michael@0 | 1147 | "si": "\017", |
michael@0 | 1148 | "dle": "\020", |
michael@0 | 1149 | "dc1": "\021", |
michael@0 | 1150 | "dc2": "\022", |
michael@0 | 1151 | "dc3": "\023", |
michael@0 | 1152 | "dc4": "\024", |
michael@0 | 1153 | "nak": "\025", |
michael@0 | 1154 | "syn": "\026", |
michael@0 | 1155 | "etb": "\027", |
michael@0 | 1156 | "can": "\030", |
michael@0 | 1157 | "em": "\031", |
michael@0 | 1158 | "sub": "\032", |
michael@0 | 1159 | "esc": "\033", |
michael@0 | 1160 | "fs": "\034", |
michael@0 | 1161 | "gs": "\035", |
michael@0 | 1162 | "rs": "\036", |
michael@0 | 1163 | "us": "\037", |
michael@0 | 1164 | "sp": "\040", |
michael@0 | 1165 | "del": "\177"}; |
michael@0 | 1166 | |
michael@0 | 1167 | sc_Char.prototype.toString = function() { |
michael@0 | 1168 | return this.val; |
michael@0 | 1169 | }; |
michael@0 | 1170 | // sc_toDisplayString == toString |
michael@0 | 1171 | sc_Char.prototype.sc_toWriteString = function() { |
michael@0 | 1172 | var entry = sc_Char.char2readable[this.val]; |
michael@0 | 1173 | if (entry) |
michael@0 | 1174 | return entry; |
michael@0 | 1175 | else |
michael@0 | 1176 | return "#\\" + this.val; |
michael@0 | 1177 | }; |
michael@0 | 1178 | |
michael@0 | 1179 | /*** META ((export #t) |
michael@0 | 1180 | (type bool) |
michael@0 | 1181 | (peephole (postfix "instanceof sc_Char"))) |
michael@0 | 1182 | */ |
michael@0 | 1183 | function sc_isChar(c) { |
michael@0 | 1184 | return (c instanceof sc_Char); |
michael@0 | 1185 | } |
michael@0 | 1186 | |
michael@0 | 1187 | /*** META ((export char=?) |
michael@0 | 1188 | (type bool) |
michael@0 | 1189 | (peephole (hole 2 c1 ".val === " c2 ".val"))) |
michael@0 | 1190 | */ |
michael@0 | 1191 | var sc_isCharEqual = sc_isCharStringEqual; |
michael@0 | 1192 | /*** META ((export char<?) |
michael@0 | 1193 | (type bool) |
michael@0 | 1194 | (peephole (hole 2 c1 ".val < " c2 ".val"))) |
michael@0 | 1195 | */ |
michael@0 | 1196 | var sc_isCharLess = sc_isCharStringLess; |
michael@0 | 1197 | /*** META ((export char>?) |
michael@0 | 1198 | (type bool) |
michael@0 | 1199 | (peephole (hole 2 c1 ".val > " c2 ".val"))) |
michael@0 | 1200 | */ |
michael@0 | 1201 | var sc_isCharGreater = sc_isCharStringGreater; |
michael@0 | 1202 | /*** META ((export char<=?) |
michael@0 | 1203 | (type bool) |
michael@0 | 1204 | (peephole (hole 2 c1 ".val <= " c2 ".val"))) |
michael@0 | 1205 | */ |
michael@0 | 1206 | var sc_isCharLessEqual = sc_isCharStringLessEqual; |
michael@0 | 1207 | /*** META ((export char>=?) |
michael@0 | 1208 | (type bool) |
michael@0 | 1209 | (peephole (hole 2 c1 ".val >= " c2 ".val"))) |
michael@0 | 1210 | */ |
michael@0 | 1211 | var sc_isCharGreaterEqual = sc_isCharStringGreaterEqual; |
michael@0 | 1212 | /*** META ((export char-ci=?) |
michael@0 | 1213 | (type bool) |
michael@0 | 1214 | (peephole (hole 2 c1 ".val.toLowerCase() === " c2 ".val.toLowerCase()"))) |
michael@0 | 1215 | */ |
michael@0 | 1216 | var sc_isCharCIEqual = sc_isCharStringCIEqual; |
michael@0 | 1217 | /*** META ((export char-ci<?) |
michael@0 | 1218 | (type bool) |
michael@0 | 1219 | (peephole (hole 2 c1 ".val.toLowerCase() < " c2 ".val.toLowerCase()"))) |
michael@0 | 1220 | */ |
michael@0 | 1221 | var sc_isCharCILess = sc_isCharStringCILess; |
michael@0 | 1222 | /*** META ((export char-ci>?) |
michael@0 | 1223 | (type bool) |
michael@0 | 1224 | (peephole (hole 2 c1 ".val.toLowerCase() > " c2 ".val.toLowerCase()"))) |
michael@0 | 1225 | */ |
michael@0 | 1226 | var sc_isCharCIGreater = sc_isCharStringCIGreater; |
michael@0 | 1227 | /*** META ((export char-ci<=?) |
michael@0 | 1228 | (type bool) |
michael@0 | 1229 | (peephole (hole 2 c1 ".val.toLowerCase() <= " c2 ".val.toLowerCase()"))) |
michael@0 | 1230 | */ |
michael@0 | 1231 | var sc_isCharCILessEqual = sc_isCharStringCILessEqual; |
michael@0 | 1232 | /*** META ((export char-ci>=?) |
michael@0 | 1233 | (type bool) |
michael@0 | 1234 | (peephole (hole 2 c1 ".val.toLowerCase() >= " c2 ".val.toLowerCase()"))) |
michael@0 | 1235 | */ |
michael@0 | 1236 | var sc_isCharCIGreaterEqual = sc_isCharStringCIGreaterEqual; |
michael@0 | 1237 | |
michael@0 | 1238 | var SC_NUMBER_CLASS = "0123456789"; |
michael@0 | 1239 | var SC_WHITESPACE_CLASS = ' \r\n\t\f'; |
michael@0 | 1240 | var SC_LOWER_CLASS = 'abcdefghijklmnopqrstuvwxyz'; |
michael@0 | 1241 | var SC_UPPER_CLASS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
michael@0 | 1242 | |
michael@0 | 1243 | function sc_isCharOfClass(c, cl) { return (cl.indexOf(c) != -1); } |
michael@0 | 1244 | /*** META ((export #t) |
michael@0 | 1245 | (type bool)) |
michael@0 | 1246 | */ |
michael@0 | 1247 | function sc_isCharAlphabetic(c) |
michael@0 | 1248 | { return sc_isCharOfClass(c.val, SC_LOWER_CLASS) || |
michael@0 | 1249 | sc_isCharOfClass(c.val, SC_UPPER_CLASS); } |
michael@0 | 1250 | /*** META ((export #t) |
michael@0 | 1251 | (type bool) |
michael@0 | 1252 | (peephole (hole 1 "SC_NUMBER_CLASS.indexOf(" c ".val) != -1"))) |
michael@0 | 1253 | */ |
michael@0 | 1254 | function sc_isCharNumeric(c) |
michael@0 | 1255 | { return sc_isCharOfClass(c.val, SC_NUMBER_CLASS); } |
michael@0 | 1256 | /*** META ((export #t) |
michael@0 | 1257 | (type bool)) |
michael@0 | 1258 | */ |
michael@0 | 1259 | function sc_isCharWhitespace(c) { |
michael@0 | 1260 | var tmp = c.val; |
michael@0 | 1261 | return tmp === " " || tmp === "\r" || tmp === "\n" || tmp === "\t" || tmp === "\f"; |
michael@0 | 1262 | } |
michael@0 | 1263 | /*** META ((export #t) |
michael@0 | 1264 | (type bool) |
michael@0 | 1265 | (peephole (hole 1 "SC_UPPER_CLASS.indexOf(" c ".val) != -1"))) |
michael@0 | 1266 | */ |
michael@0 | 1267 | function sc_isCharUpperCase(c) |
michael@0 | 1268 | { return sc_isCharOfClass(c.val, SC_UPPER_CLASS); } |
michael@0 | 1269 | /*** META ((export #t) |
michael@0 | 1270 | (type bool) |
michael@0 | 1271 | (peephole (hole 1 "SC_LOWER_CLASS.indexOf(" c ".val) != -1"))) |
michael@0 | 1272 | */ |
michael@0 | 1273 | function sc_isCharLowerCase(c) |
michael@0 | 1274 | { return sc_isCharOfClass(c.val, SC_LOWER_CLASS); } |
michael@0 | 1275 | |
michael@0 | 1276 | /*** META ((export #t) |
michael@0 | 1277 | (peephole (postfix ".val.charCodeAt(0)"))) |
michael@0 | 1278 | */ |
michael@0 | 1279 | function sc_char2integer(c) |
michael@0 | 1280 | { return c.val.charCodeAt(0); } |
michael@0 | 1281 | /*** META ((export #t) |
michael@0 | 1282 | (peephole (hole 1 "new sc_Char(String.fromCharCode(" n "))"))) |
michael@0 | 1283 | */ |
michael@0 | 1284 | function sc_integer2char(n) |
michael@0 | 1285 | { return new sc_Char(String.fromCharCode(n)); } |
michael@0 | 1286 | |
michael@0 | 1287 | /*** META ((export #t) |
michael@0 | 1288 | (peephole (hole 1 "new sc_Char(" c ".val.toUpperCase())"))) |
michael@0 | 1289 | */ |
michael@0 | 1290 | function sc_charUpcase(c) |
michael@0 | 1291 | { return new sc_Char(c.val.toUpperCase()); } |
michael@0 | 1292 | /*** META ((export #t) |
michael@0 | 1293 | (peephole (hole 1 "new sc_Char(" c ".val.toLowerCase())"))) |
michael@0 | 1294 | */ |
michael@0 | 1295 | function sc_charDowncase(c) |
michael@0 | 1296 | { return new sc_Char(c.val.toLowerCase()); } |
michael@0 | 1297 | |
michael@0 | 1298 | function sc_makeJSStringOfLength(k, c) { |
michael@0 | 1299 | var fill; |
michael@0 | 1300 | if (c === undefined) |
michael@0 | 1301 | fill = " "; |
michael@0 | 1302 | else |
michael@0 | 1303 | fill = c; |
michael@0 | 1304 | var res = ""; |
michael@0 | 1305 | var len = 1; |
michael@0 | 1306 | // every round doubles the size of fill. |
michael@0 | 1307 | while (k >= len) { |
michael@0 | 1308 | if (k & len) |
michael@0 | 1309 | res = res.concat(fill); |
michael@0 | 1310 | fill = fill.concat(fill); |
michael@0 | 1311 | len *= 2; |
michael@0 | 1312 | } |
michael@0 | 1313 | return res; |
michael@0 | 1314 | } |
michael@0 | 1315 | |
michael@0 | 1316 | function sc_makejsString(k, c) { |
michael@0 | 1317 | var fill; |
michael@0 | 1318 | if (c) |
michael@0 | 1319 | fill = c.val; |
michael@0 | 1320 | else |
michael@0 | 1321 | fill = " "; |
michael@0 | 1322 | return sc_makeJSStringOfLength(k, fill); |
michael@0 | 1323 | } |
michael@0 | 1324 | |
michael@0 | 1325 | function sc_jsstring2list(s) { |
michael@0 | 1326 | var res = null; |
michael@0 | 1327 | for (var i = s.length - 1; i >= 0; i--) |
michael@0 | 1328 | res = sc_cons(new sc_Char(s.charAt(i)), res); |
michael@0 | 1329 | return res; |
michael@0 | 1330 | } |
michael@0 | 1331 | |
michael@0 | 1332 | function sc_list2jsstring(l) { |
michael@0 | 1333 | var a = new Array(); |
michael@0 | 1334 | while(l !== null) { |
michael@0 | 1335 | a.push(l.car.val); |
michael@0 | 1336 | l = l.cdr; |
michael@0 | 1337 | } |
michael@0 | 1338 | return "".concat.apply("", a); |
michael@0 | 1339 | } |
michael@0 | 1340 | |
michael@0 | 1341 | var sc_Vector = Array; |
michael@0 | 1342 | |
michael@0 | 1343 | sc_Vector.prototype.sc_toWriteOrDisplayString = function(writeOrDisplay) { |
michael@0 | 1344 | if (this.length === 0) return "#()"; |
michael@0 | 1345 | |
michael@0 | 1346 | var res = "#(" + writeOrDisplay(this[0]); |
michael@0 | 1347 | for (var i = 1; i < this.length; i++) |
michael@0 | 1348 | res += " " + writeOrDisplay(this[i]); |
michael@0 | 1349 | res += ")"; |
michael@0 | 1350 | return res; |
michael@0 | 1351 | }; |
michael@0 | 1352 | sc_Vector.prototype.sc_toDisplayString = function() { |
michael@0 | 1353 | return this.sc_toWriteOrDisplayString(sc_toDisplayString); |
michael@0 | 1354 | }; |
michael@0 | 1355 | sc_Vector.prototype.sc_toWriteString = function() { |
michael@0 | 1356 | return this.sc_toWriteOrDisplayString(sc_toWriteString); |
michael@0 | 1357 | }; |
michael@0 | 1358 | |
michael@0 | 1359 | /*** META ((export vector? array?) |
michael@0 | 1360 | (type bool) |
michael@0 | 1361 | (peephole (postfix " instanceof sc_Vector"))) |
michael@0 | 1362 | */ |
michael@0 | 1363 | function sc_isVector(v) { |
michael@0 | 1364 | return (v instanceof sc_Vector); |
michael@0 | 1365 | } |
michael@0 | 1366 | |
michael@0 | 1367 | // only applies to vectors |
michael@0 | 1368 | function sc_isVectorEqual(v1, v2, comp) { |
michael@0 | 1369 | if (v1.length !== v2.length) return false; |
michael@0 | 1370 | for (var i = 0; i < v1.length; i++) |
michael@0 | 1371 | if (!comp(v1[i], v2[i])) return false; |
michael@0 | 1372 | return true; |
michael@0 | 1373 | } |
michael@0 | 1374 | |
michael@0 | 1375 | /*** META ((export make-vector make-array)) */ |
michael@0 | 1376 | function sc_makeVector(size, fill) { |
michael@0 | 1377 | var a = new sc_Vector(size); |
michael@0 | 1378 | if (fill !== undefined) |
michael@0 | 1379 | sc_vectorFillBang(a, fill); |
michael@0 | 1380 | return a; |
michael@0 | 1381 | } |
michael@0 | 1382 | |
michael@0 | 1383 | /*** META ((export vector array) |
michael@0 | 1384 | (peephole (vector))) |
michael@0 | 1385 | */ |
michael@0 | 1386 | function sc_vector() { |
michael@0 | 1387 | var a = new sc_Vector(); |
michael@0 | 1388 | for (var i = 0; i < arguments.length; i++) |
michael@0 | 1389 | a.push(arguments[i]); |
michael@0 | 1390 | return a; |
michael@0 | 1391 | } |
michael@0 | 1392 | |
michael@0 | 1393 | /*** META ((export vector-length array-length) |
michael@0 | 1394 | (peephole (postfix ".length"))) |
michael@0 | 1395 | */ |
michael@0 | 1396 | function sc_vectorLength(v) { |
michael@0 | 1397 | return v.length; |
michael@0 | 1398 | } |
michael@0 | 1399 | |
michael@0 | 1400 | /*** META ((export vector-ref array-ref) |
michael@0 | 1401 | (peephole (hole 2 v "[" pos "]"))) |
michael@0 | 1402 | */ |
michael@0 | 1403 | function sc_vectorRef(v, pos) { |
michael@0 | 1404 | return v[pos]; |
michael@0 | 1405 | } |
michael@0 | 1406 | |
michael@0 | 1407 | /*** META ((export vector-set! array-set!) |
michael@0 | 1408 | (peephole (hole 3 v "[" pos "] = " val))) |
michael@0 | 1409 | */ |
michael@0 | 1410 | function sc_vectorSetBang(v, pos, val) { |
michael@0 | 1411 | v[pos] = val; |
michael@0 | 1412 | } |
michael@0 | 1413 | |
michael@0 | 1414 | /*** META ((export vector->list array->list)) */ |
michael@0 | 1415 | function sc_vector2list(a) { |
michael@0 | 1416 | var res = null; |
michael@0 | 1417 | for (var i = a.length-1; i >= 0; i--) |
michael@0 | 1418 | res = sc_cons(a[i], res); |
michael@0 | 1419 | return res; |
michael@0 | 1420 | } |
michael@0 | 1421 | |
michael@0 | 1422 | /*** META ((export list->vector list->array)) */ |
michael@0 | 1423 | function sc_list2vector(l) { |
michael@0 | 1424 | var a = new sc_Vector(); |
michael@0 | 1425 | while(l !== null) { |
michael@0 | 1426 | a.push(l.car); |
michael@0 | 1427 | l = l.cdr; |
michael@0 | 1428 | } |
michael@0 | 1429 | return a; |
michael@0 | 1430 | } |
michael@0 | 1431 | |
michael@0 | 1432 | /*** META ((export vector-fill! array-fill!)) */ |
michael@0 | 1433 | function sc_vectorFillBang(a, fill) { |
michael@0 | 1434 | for (var i = 0; i < a.length; i++) |
michael@0 | 1435 | a[i] = fill; |
michael@0 | 1436 | } |
michael@0 | 1437 | |
michael@0 | 1438 | |
michael@0 | 1439 | /*** META ((export #t)) */ |
michael@0 | 1440 | function sc_copyVector(a, len) { |
michael@0 | 1441 | if (len <= a.length) |
michael@0 | 1442 | return a.slice(0, len); |
michael@0 | 1443 | else { |
michael@0 | 1444 | var tmp = a.concat(); |
michael@0 | 1445 | tmp.length = len; |
michael@0 | 1446 | return tmp; |
michael@0 | 1447 | } |
michael@0 | 1448 | } |
michael@0 | 1449 | |
michael@0 | 1450 | /*** META ((export #t) |
michael@0 | 1451 | (peephole (hole 3 a ".slice(" start "," end ")"))) |
michael@0 | 1452 | */ |
michael@0 | 1453 | function sc_vectorCopy(a, start, end) { |
michael@0 | 1454 | return a.slice(start, end); |
michael@0 | 1455 | } |
michael@0 | 1456 | |
michael@0 | 1457 | /*** META ((export #t)) */ |
michael@0 | 1458 | function sc_vectorCopyBang(target, tstart, source, sstart, send) { |
michael@0 | 1459 | if (!sstart) sstart = 0; |
michael@0 | 1460 | if (!send) send = source.length; |
michael@0 | 1461 | |
michael@0 | 1462 | // if target == source we don't want to overwrite not yet copied elements. |
michael@0 | 1463 | if (tstart <= sstart) { |
michael@0 | 1464 | for (var i = tstart, j = sstart; j < send; i++, j++) { |
michael@0 | 1465 | target[i] = source[j]; |
michael@0 | 1466 | } |
michael@0 | 1467 | } else { |
michael@0 | 1468 | var diff = send - sstart; |
michael@0 | 1469 | for (var i = tstart + diff - 1, j = send - 1; |
michael@0 | 1470 | j >= sstart; |
michael@0 | 1471 | i--, j--) { |
michael@0 | 1472 | target[i] = source[j]; |
michael@0 | 1473 | } |
michael@0 | 1474 | } |
michael@0 | 1475 | return target; |
michael@0 | 1476 | } |
michael@0 | 1477 | |
michael@0 | 1478 | /*** META ((export #t) |
michael@0 | 1479 | (type bool) |
michael@0 | 1480 | (peephole (hole 1 "typeof " o " === 'function'"))) |
michael@0 | 1481 | */ |
michael@0 | 1482 | function sc_isProcedure(o) { |
michael@0 | 1483 | return (typeof o === "function"); |
michael@0 | 1484 | } |
michael@0 | 1485 | |
michael@0 | 1486 | /*** META ((export #t)) */ |
michael@0 | 1487 | function sc_apply(proc) { |
michael@0 | 1488 | var args = new Array(); |
michael@0 | 1489 | // first part of arguments are not in list-form. |
michael@0 | 1490 | for (var i = 1; i < arguments.length - 1; i++) |
michael@0 | 1491 | args.push(arguments[i]); |
michael@0 | 1492 | var l = arguments[arguments.length - 1]; |
michael@0 | 1493 | while (l !== null) { |
michael@0 | 1494 | args.push(l.car); |
michael@0 | 1495 | l = l.cdr; |
michael@0 | 1496 | } |
michael@0 | 1497 | return proc.apply(null, args); |
michael@0 | 1498 | } |
michael@0 | 1499 | |
michael@0 | 1500 | /*** META ((export #t)) */ |
michael@0 | 1501 | function sc_map(proc, l1) { |
michael@0 | 1502 | if (l1 === undefined) |
michael@0 | 1503 | return null; |
michael@0 | 1504 | // else |
michael@0 | 1505 | var nbApplyArgs = arguments.length - 1; |
michael@0 | 1506 | var applyArgs = new Array(nbApplyArgs); |
michael@0 | 1507 | var revres = null; |
michael@0 | 1508 | while (l1 !== null) { |
michael@0 | 1509 | for (var i = 0; i < nbApplyArgs; i++) { |
michael@0 | 1510 | applyArgs[i] = arguments[i + 1].car; |
michael@0 | 1511 | arguments[i + 1] = arguments[i + 1].cdr; |
michael@0 | 1512 | } |
michael@0 | 1513 | revres = sc_cons(proc.apply(null, applyArgs), revres); |
michael@0 | 1514 | } |
michael@0 | 1515 | return sc_reverseAppendBang(revres, null); |
michael@0 | 1516 | } |
michael@0 | 1517 | |
michael@0 | 1518 | /*** META ((export #t)) */ |
michael@0 | 1519 | function sc_mapBang(proc, l1) { |
michael@0 | 1520 | if (l1 === undefined) |
michael@0 | 1521 | return null; |
michael@0 | 1522 | // else |
michael@0 | 1523 | var l1_orig = l1; |
michael@0 | 1524 | var nbApplyArgs = arguments.length - 1; |
michael@0 | 1525 | var applyArgs = new Array(nbApplyArgs); |
michael@0 | 1526 | while (l1 !== null) { |
michael@0 | 1527 | var tmp = l1; |
michael@0 | 1528 | for (var i = 0; i < nbApplyArgs; i++) { |
michael@0 | 1529 | applyArgs[i] = arguments[i + 1].car; |
michael@0 | 1530 | arguments[i + 1] = arguments[i + 1].cdr; |
michael@0 | 1531 | } |
michael@0 | 1532 | tmp.car = proc.apply(null, applyArgs); |
michael@0 | 1533 | } |
michael@0 | 1534 | return l1_orig; |
michael@0 | 1535 | } |
michael@0 | 1536 | |
michael@0 | 1537 | /*** META ((export #t)) */ |
michael@0 | 1538 | function sc_forEach(proc, l1) { |
michael@0 | 1539 | if (l1 === undefined) |
michael@0 | 1540 | return undefined; |
michael@0 | 1541 | // else |
michael@0 | 1542 | var nbApplyArgs = arguments.length - 1; |
michael@0 | 1543 | var applyArgs = new Array(nbApplyArgs); |
michael@0 | 1544 | while (l1 !== null) { |
michael@0 | 1545 | for (var i = 0; i < nbApplyArgs; i++) { |
michael@0 | 1546 | applyArgs[i] = arguments[i + 1].car; |
michael@0 | 1547 | arguments[i + 1] = arguments[i + 1].cdr; |
michael@0 | 1548 | } |
michael@0 | 1549 | proc.apply(null, applyArgs); |
michael@0 | 1550 | } |
michael@0 | 1551 | // add return so FF does not complain. |
michael@0 | 1552 | return undefined; |
michael@0 | 1553 | } |
michael@0 | 1554 | |
michael@0 | 1555 | /*** META ((export #t)) */ |
michael@0 | 1556 | function sc_filter(proc, l1) { |
michael@0 | 1557 | var dummy = { cdr : null }; |
michael@0 | 1558 | var tail = dummy; |
michael@0 | 1559 | while (l1 !== null) { |
michael@0 | 1560 | if (proc(l1.car) !== false) { |
michael@0 | 1561 | tail.cdr = sc_cons(l1.car, null); |
michael@0 | 1562 | tail = tail.cdr; |
michael@0 | 1563 | } |
michael@0 | 1564 | l1 = l1.cdr; |
michael@0 | 1565 | } |
michael@0 | 1566 | return dummy.cdr; |
michael@0 | 1567 | } |
michael@0 | 1568 | |
michael@0 | 1569 | /*** META ((export #t)) */ |
michael@0 | 1570 | function sc_filterBang(proc, l1) { |
michael@0 | 1571 | var head = sc_cons("dummy", l1); |
michael@0 | 1572 | var it = head; |
michael@0 | 1573 | var next = l1; |
michael@0 | 1574 | while (next !== null) { |
michael@0 | 1575 | if (proc(next.car) !== false) { |
michael@0 | 1576 | it.cdr = next |
michael@0 | 1577 | it = next; |
michael@0 | 1578 | } |
michael@0 | 1579 | next = next.cdr; |
michael@0 | 1580 | } |
michael@0 | 1581 | it.cdr = null; |
michael@0 | 1582 | return head.cdr; |
michael@0 | 1583 | } |
michael@0 | 1584 | |
michael@0 | 1585 | function sc_filterMap1(proc, l1) { |
michael@0 | 1586 | var revres = null; |
michael@0 | 1587 | while (l1 !== null) { |
michael@0 | 1588 | var tmp = proc(l1.car) |
michael@0 | 1589 | if (tmp !== false) revres = sc_cons(tmp, revres); |
michael@0 | 1590 | l1 = l1.cdr; |
michael@0 | 1591 | } |
michael@0 | 1592 | return sc_reverseAppendBang(revres, null); |
michael@0 | 1593 | } |
michael@0 | 1594 | function sc_filterMap2(proc, l1, l2) { |
michael@0 | 1595 | var revres = null; |
michael@0 | 1596 | while (l1 !== null) { |
michael@0 | 1597 | var tmp = proc(l1.car, l2.car); |
michael@0 | 1598 | if(tmp !== false) revres = sc_cons(tmp, revres); |
michael@0 | 1599 | l1 = l1.cdr; |
michael@0 | 1600 | l2 = l2.cdr |
michael@0 | 1601 | } |
michael@0 | 1602 | return sc_reverseAppendBang(revres, null); |
michael@0 | 1603 | } |
michael@0 | 1604 | |
michael@0 | 1605 | /*** META ((export #t)) */ |
michael@0 | 1606 | function sc_filterMap(proc, l1, l2, l3) { |
michael@0 | 1607 | if (l2 === undefined) |
michael@0 | 1608 | return sc_filterMap1(proc, l1); |
michael@0 | 1609 | else if (l3 === undefined) |
michael@0 | 1610 | return sc_filterMap2(proc, l1, l2); |
michael@0 | 1611 | // else |
michael@0 | 1612 | var nbApplyArgs = arguments.length - 1; |
michael@0 | 1613 | var applyArgs = new Array(nbApplyArgs); |
michael@0 | 1614 | var revres = null; |
michael@0 | 1615 | while (l1 !== null) { |
michael@0 | 1616 | for (var i = 0; i < nbApplyArgs; i++) { |
michael@0 | 1617 | applyArgs[i] = arguments[i + 1].car; |
michael@0 | 1618 | arguments[i + 1] = arguments[i + 1].cdr; |
michael@0 | 1619 | } |
michael@0 | 1620 | var tmp = proc.apply(null, applyArgs); |
michael@0 | 1621 | if(tmp !== false) revres = sc_cons(tmp, revres); |
michael@0 | 1622 | } |
michael@0 | 1623 | return sc_reverseAppendBang(revres, null); |
michael@0 | 1624 | } |
michael@0 | 1625 | |
michael@0 | 1626 | /*** META ((export #t)) */ |
michael@0 | 1627 | function sc_any(proc, l) { |
michael@0 | 1628 | var revres = null; |
michael@0 | 1629 | while (l !== null) { |
michael@0 | 1630 | var tmp = proc(l.car); |
michael@0 | 1631 | if(tmp !== false) return tmp; |
michael@0 | 1632 | l = l.cdr; |
michael@0 | 1633 | } |
michael@0 | 1634 | return false; |
michael@0 | 1635 | } |
michael@0 | 1636 | |
michael@0 | 1637 | /*** META ((export any?) |
michael@0 | 1638 | (peephole (hole 2 "sc_any(" proc "," l ") !== false"))) |
michael@0 | 1639 | */ |
michael@0 | 1640 | function sc_anyPred(proc, l) { |
michael@0 | 1641 | return sc_any(proc, l)!== false; |
michael@0 | 1642 | } |
michael@0 | 1643 | |
michael@0 | 1644 | /*** META ((export #t)) */ |
michael@0 | 1645 | function sc_every(proc, l) { |
michael@0 | 1646 | var revres = null; |
michael@0 | 1647 | var tmp = true; |
michael@0 | 1648 | while (l !== null) { |
michael@0 | 1649 | tmp = proc(l.car); |
michael@0 | 1650 | if (tmp === false) return false; |
michael@0 | 1651 | l = l.cdr; |
michael@0 | 1652 | } |
michael@0 | 1653 | return tmp; |
michael@0 | 1654 | } |
michael@0 | 1655 | |
michael@0 | 1656 | /*** META ((export every?) |
michael@0 | 1657 | (peephole (hole 2 "sc_every(" proc "," l ") !== false"))) |
michael@0 | 1658 | */ |
michael@0 | 1659 | function sc_everyPred(proc, l) { |
michael@0 | 1660 | var tmp = sc_every(proc, l); |
michael@0 | 1661 | if (tmp !== false) return true; |
michael@0 | 1662 | return false; |
michael@0 | 1663 | } |
michael@0 | 1664 | |
michael@0 | 1665 | /*** META ((export #t) |
michael@0 | 1666 | (peephole (postfix "()"))) |
michael@0 | 1667 | */ |
michael@0 | 1668 | function sc_force(o) { |
michael@0 | 1669 | return o(); |
michael@0 | 1670 | } |
michael@0 | 1671 | |
michael@0 | 1672 | /*** META ((export #t)) */ |
michael@0 | 1673 | function sc_makePromise(proc) { |
michael@0 | 1674 | var isResultReady = false; |
michael@0 | 1675 | var result = undefined; |
michael@0 | 1676 | return function() { |
michael@0 | 1677 | if (!isResultReady) { |
michael@0 | 1678 | var tmp = proc(); |
michael@0 | 1679 | if (!isResultReady) { |
michael@0 | 1680 | isResultReady = true; |
michael@0 | 1681 | result = tmp; |
michael@0 | 1682 | } |
michael@0 | 1683 | } |
michael@0 | 1684 | return result; |
michael@0 | 1685 | }; |
michael@0 | 1686 | } |
michael@0 | 1687 | |
michael@0 | 1688 | function sc_Values(values) { |
michael@0 | 1689 | this.values = values; |
michael@0 | 1690 | } |
michael@0 | 1691 | |
michael@0 | 1692 | /*** META ((export #t) |
michael@0 | 1693 | (peephole (values))) |
michael@0 | 1694 | */ |
michael@0 | 1695 | function sc_values() { |
michael@0 | 1696 | if (arguments.length === 1) |
michael@0 | 1697 | return arguments[0]; |
michael@0 | 1698 | else |
michael@0 | 1699 | return new sc_Values(arguments); |
michael@0 | 1700 | } |
michael@0 | 1701 | |
michael@0 | 1702 | /*** META ((export #t)) */ |
michael@0 | 1703 | function sc_callWithValues(producer, consumer) { |
michael@0 | 1704 | var produced = producer(); |
michael@0 | 1705 | if (produced instanceof sc_Values) |
michael@0 | 1706 | return consumer.apply(null, produced.values); |
michael@0 | 1707 | else |
michael@0 | 1708 | return consumer(produced); |
michael@0 | 1709 | } |
michael@0 | 1710 | |
michael@0 | 1711 | /*** META ((export #t)) */ |
michael@0 | 1712 | function sc_dynamicWind(before, thunk, after) { |
michael@0 | 1713 | before(); |
michael@0 | 1714 | try { |
michael@0 | 1715 | var res = thunk(); |
michael@0 | 1716 | return res; |
michael@0 | 1717 | } finally { |
michael@0 | 1718 | after(); |
michael@0 | 1719 | } |
michael@0 | 1720 | } |
michael@0 | 1721 | |
michael@0 | 1722 | |
michael@0 | 1723 | // TODO: eval/scheme-report-environment/null-environment/interaction-environment |
michael@0 | 1724 | |
michael@0 | 1725 | // LIMITATION: 'load' doesn't exist without files. |
michael@0 | 1726 | // LIMITATION: transcript-on/transcript-off doesn't exist without files. |
michael@0 | 1727 | |
michael@0 | 1728 | |
michael@0 | 1729 | function sc_Struct(name) { |
michael@0 | 1730 | this.name = name; |
michael@0 | 1731 | } |
michael@0 | 1732 | sc_Struct.prototype.sc_toDisplayString = function() { |
michael@0 | 1733 | return "#<struct" + sc_hash(this) + ">"; |
michael@0 | 1734 | }; |
michael@0 | 1735 | sc_Struct.prototype.sc_toWriteString = sc_Struct.prototype.sc_toDisplayString; |
michael@0 | 1736 | |
michael@0 | 1737 | /*** META ((export #t) |
michael@0 | 1738 | (peephole (hole 1 "new sc_Struct(" name ")"))) |
michael@0 | 1739 | */ |
michael@0 | 1740 | function sc_makeStruct(name) { |
michael@0 | 1741 | return new sc_Struct(name); |
michael@0 | 1742 | } |
michael@0 | 1743 | |
michael@0 | 1744 | /*** META ((export #t) |
michael@0 | 1745 | (type bool) |
michael@0 | 1746 | (peephole (postfix " instanceof sc_Struct"))) |
michael@0 | 1747 | */ |
michael@0 | 1748 | function sc_isStruct(o) { |
michael@0 | 1749 | return (o instanceof sc_Struct); |
michael@0 | 1750 | } |
michael@0 | 1751 | |
michael@0 | 1752 | /*** META ((export #t) |
michael@0 | 1753 | (type bool) |
michael@0 | 1754 | (peephole (hole 2 "(" 1 " instanceof sc_Struct) && ( " 1 ".name === " 0 ")"))) |
michael@0 | 1755 | */ |
michael@0 | 1756 | function sc_isStructNamed(name, s) { |
michael@0 | 1757 | return ((s instanceof sc_Struct) && (s.name === name)); |
michael@0 | 1758 | } |
michael@0 | 1759 | |
michael@0 | 1760 | /*** META ((export struct-field) |
michael@0 | 1761 | (peephole (hole 3 0 "[" 2 "]"))) |
michael@0 | 1762 | */ |
michael@0 | 1763 | function sc_getStructField(s, name, field) { |
michael@0 | 1764 | return s[field]; |
michael@0 | 1765 | } |
michael@0 | 1766 | |
michael@0 | 1767 | /*** META ((export struct-field-set!) |
michael@0 | 1768 | (peephole (hole 4 0 "[" 2 "] = " 3))) |
michael@0 | 1769 | */ |
michael@0 | 1770 | function sc_setStructFieldBang(s, name, field, val) { |
michael@0 | 1771 | s[field] = val; |
michael@0 | 1772 | } |
michael@0 | 1773 | |
michael@0 | 1774 | /*** META ((export #t) |
michael@0 | 1775 | (peephole (prefix "~"))) |
michael@0 | 1776 | */ |
michael@0 | 1777 | function sc_bitNot(x) { |
michael@0 | 1778 | return ~x; |
michael@0 | 1779 | } |
michael@0 | 1780 | |
michael@0 | 1781 | /*** META ((export #t) |
michael@0 | 1782 | (peephole (infix 2 2 "&"))) |
michael@0 | 1783 | */ |
michael@0 | 1784 | function sc_bitAnd(x, y) { |
michael@0 | 1785 | return x & y; |
michael@0 | 1786 | } |
michael@0 | 1787 | |
michael@0 | 1788 | /*** META ((export #t) |
michael@0 | 1789 | (peephole (infix 2 2 "|"))) |
michael@0 | 1790 | */ |
michael@0 | 1791 | function sc_bitOr(x, y) { |
michael@0 | 1792 | return x | y; |
michael@0 | 1793 | } |
michael@0 | 1794 | |
michael@0 | 1795 | /*** META ((export #t) |
michael@0 | 1796 | (peephole (infix 2 2 "^"))) |
michael@0 | 1797 | */ |
michael@0 | 1798 | function sc_bitXor(x, y) { |
michael@0 | 1799 | return x ^ y; |
michael@0 | 1800 | } |
michael@0 | 1801 | |
michael@0 | 1802 | /*** META ((export #t) |
michael@0 | 1803 | (peephole (infix 2 2 "<<"))) |
michael@0 | 1804 | */ |
michael@0 | 1805 | function sc_bitLsh(x, y) { |
michael@0 | 1806 | return x << y; |
michael@0 | 1807 | } |
michael@0 | 1808 | |
michael@0 | 1809 | /*** META ((export #t) |
michael@0 | 1810 | (peephole (infix 2 2 ">>"))) |
michael@0 | 1811 | */ |
michael@0 | 1812 | function sc_bitRsh(x, y) { |
michael@0 | 1813 | return x >> y; |
michael@0 | 1814 | } |
michael@0 | 1815 | |
michael@0 | 1816 | /*** META ((export #t) |
michael@0 | 1817 | (peephole (infix 2 2 ">>>"))) |
michael@0 | 1818 | */ |
michael@0 | 1819 | function sc_bitUrsh(x, y) { |
michael@0 | 1820 | return x >>> y; |
michael@0 | 1821 | } |
michael@0 | 1822 | |
michael@0 | 1823 | /*** META ((export js-field js-property) |
michael@0 | 1824 | (peephole (hole 2 o "[" field "]"))) |
michael@0 | 1825 | */ |
michael@0 | 1826 | function sc_jsField(o, field) { |
michael@0 | 1827 | return o[field]; |
michael@0 | 1828 | } |
michael@0 | 1829 | |
michael@0 | 1830 | /*** META ((export js-field-set! js-property-set!) |
michael@0 | 1831 | (peephole (hole 3 o "[" field "] = " val))) |
michael@0 | 1832 | */ |
michael@0 | 1833 | function sc_setJsFieldBang(o, field, val) { |
michael@0 | 1834 | return o[field] = val; |
michael@0 | 1835 | } |
michael@0 | 1836 | |
michael@0 | 1837 | /*** META ((export js-field-delete! js-property-delete!) |
michael@0 | 1838 | (peephole (hole 2 "delete" o "[" field "]"))) |
michael@0 | 1839 | */ |
michael@0 | 1840 | function sc_deleteJsFieldBang(o, field) { |
michael@0 | 1841 | delete o[field]; |
michael@0 | 1842 | } |
michael@0 | 1843 | |
michael@0 | 1844 | /*** META ((export #t) |
michael@0 | 1845 | (peephole (jsCall))) |
michael@0 | 1846 | */ |
michael@0 | 1847 | function sc_jsCall(o, fun) { |
michael@0 | 1848 | var args = new Array(); |
michael@0 | 1849 | for (var i = 2; i < arguments.length; i++) |
michael@0 | 1850 | args[i-2] = arguments[i]; |
michael@0 | 1851 | return fun.apply(o, args); |
michael@0 | 1852 | } |
michael@0 | 1853 | |
michael@0 | 1854 | /*** META ((export #t) |
michael@0 | 1855 | (peephole (jsMethodCall))) |
michael@0 | 1856 | */ |
michael@0 | 1857 | function sc_jsMethodCall(o, field) { |
michael@0 | 1858 | var args = new Array(); |
michael@0 | 1859 | for (var i = 2; i < arguments.length; i++) |
michael@0 | 1860 | args[i-2] = arguments[i]; |
michael@0 | 1861 | return o[field].apply(o, args); |
michael@0 | 1862 | } |
michael@0 | 1863 | |
michael@0 | 1864 | /*** META ((export new js-new) |
michael@0 | 1865 | (peephole (jsNew))) |
michael@0 | 1866 | */ |
michael@0 | 1867 | function sc_jsNew(c) { |
michael@0 | 1868 | var evalStr = "new c("; |
michael@0 | 1869 | evalStr +=arguments.length > 1? "arguments[1]": ""; |
michael@0 | 1870 | for (var i = 2; i < arguments.length; i++) |
michael@0 | 1871 | evalStr += ", arguments[" + i + "]"; |
michael@0 | 1872 | evalStr +=")"; |
michael@0 | 1873 | return eval(evalStr); |
michael@0 | 1874 | } |
michael@0 | 1875 | |
michael@0 | 1876 | // ======================== RegExp ==================== |
michael@0 | 1877 | /*** META ((export #t)) */ |
michael@0 | 1878 | function sc_pregexp(re) { |
michael@0 | 1879 | return new RegExp(sc_string2jsstring(re)); |
michael@0 | 1880 | } |
michael@0 | 1881 | |
michael@0 | 1882 | /*** META ((export #t)) */ |
michael@0 | 1883 | function sc_pregexpMatch(re, s) { |
michael@0 | 1884 | var reg = (re instanceof RegExp) ? re : sc_pregexp(re); |
michael@0 | 1885 | var tmp = reg.exec(sc_string2jsstring(s)); |
michael@0 | 1886 | |
michael@0 | 1887 | if (tmp == null) return false; |
michael@0 | 1888 | |
michael@0 | 1889 | var res = null; |
michael@0 | 1890 | for (var i = tmp.length-1; i >= 0; i--) { |
michael@0 | 1891 | if (tmp[i] !== null) { |
michael@0 | 1892 | res = sc_cons(sc_jsstring2string(tmp[i]), res); |
michael@0 | 1893 | } else { |
michael@0 | 1894 | res = sc_cons(false, res); |
michael@0 | 1895 | } |
michael@0 | 1896 | } |
michael@0 | 1897 | return res; |
michael@0 | 1898 | } |
michael@0 | 1899 | |
michael@0 | 1900 | /*** META ((export #t)) */ |
michael@0 | 1901 | function sc_pregexpReplace(re, s1, s2) { |
michael@0 | 1902 | var reg; |
michael@0 | 1903 | var jss1 = sc_string2jsstring(s1); |
michael@0 | 1904 | var jss2 = sc_string2jsstring(s2); |
michael@0 | 1905 | |
michael@0 | 1906 | if (re instanceof RegExp) { |
michael@0 | 1907 | if (re.global) |
michael@0 | 1908 | reg = re; |
michael@0 | 1909 | else |
michael@0 | 1910 | reg = new RegExp(re.source); |
michael@0 | 1911 | } else { |
michael@0 | 1912 | reg = new RegExp(sc_string2jsstring(re)); |
michael@0 | 1913 | } |
michael@0 | 1914 | |
michael@0 | 1915 | return jss1.replace(reg, jss2); |
michael@0 | 1916 | } |
michael@0 | 1917 | |
michael@0 | 1918 | /*** META ((export pregexp-replace*)) */ |
michael@0 | 1919 | function sc_pregexpReplaceAll(re, s1, s2) { |
michael@0 | 1920 | var reg; |
michael@0 | 1921 | var jss1 = sc_string2jsstring(s1); |
michael@0 | 1922 | var jss2 = sc_string2jsstring(s2); |
michael@0 | 1923 | |
michael@0 | 1924 | if (re instanceof RegExp) { |
michael@0 | 1925 | if (re.global) |
michael@0 | 1926 | reg = re; |
michael@0 | 1927 | else |
michael@0 | 1928 | reg = new RegExp(re.source, "g"); |
michael@0 | 1929 | } else { |
michael@0 | 1930 | reg = new RegExp(sc_string2jsstring(re), "g"); |
michael@0 | 1931 | } |
michael@0 | 1932 | |
michael@0 | 1933 | return jss1.replace(reg, jss2); |
michael@0 | 1934 | } |
michael@0 | 1935 | |
michael@0 | 1936 | /*** META ((export #t)) */ |
michael@0 | 1937 | function sc_pregexpSplit(re, s) { |
michael@0 | 1938 | var reg = ((re instanceof RegExp) ? |
michael@0 | 1939 | re : |
michael@0 | 1940 | new RegExp(sc_string2jsstring(re))); |
michael@0 | 1941 | var jss = sc_string2jsstring(s); |
michael@0 | 1942 | var tmp = jss.split(reg); |
michael@0 | 1943 | |
michael@0 | 1944 | if (tmp == null) return false; |
michael@0 | 1945 | |
michael@0 | 1946 | return sc_vector2list(tmp); |
michael@0 | 1947 | } |
michael@0 | 1948 | |
michael@0 | 1949 | |
michael@0 | 1950 | /* =========================================================================== */ |
michael@0 | 1951 | /* Other library stuff */ |
michael@0 | 1952 | /* =========================================================================== */ |
michael@0 | 1953 | |
michael@0 | 1954 | /*** META ((export #t) |
michael@0 | 1955 | (peephole (hole 1 "Math.floor(Math.random()*" 'n ")"))) |
michael@0 | 1956 | */ |
michael@0 | 1957 | function sc_random(n) { |
michael@0 | 1958 | return Math.floor(Math.random()*n); |
michael@0 | 1959 | } |
michael@0 | 1960 | |
michael@0 | 1961 | /*** META ((export current-date) |
michael@0 | 1962 | (peephole (hole 0 "new Date()"))) |
michael@0 | 1963 | */ |
michael@0 | 1964 | function sc_currentDate() { |
michael@0 | 1965 | return new Date(); |
michael@0 | 1966 | } |
michael@0 | 1967 | |
michael@0 | 1968 | function sc_Hashtable() { |
michael@0 | 1969 | } |
michael@0 | 1970 | sc_Hashtable.prototype.toString = function() { |
michael@0 | 1971 | return "#{%hashtable}"; |
michael@0 | 1972 | }; |
michael@0 | 1973 | // sc_toWriteString == sc_toDisplayString == toString |
michael@0 | 1974 | |
michael@0 | 1975 | function sc_HashtableElement(key, val) { |
michael@0 | 1976 | this.key = key; |
michael@0 | 1977 | this.val = val; |
michael@0 | 1978 | } |
michael@0 | 1979 | |
michael@0 | 1980 | /*** META ((export #t) |
michael@0 | 1981 | (peephole (hole 0 "new sc_Hashtable()"))) |
michael@0 | 1982 | */ |
michael@0 | 1983 | function sc_makeHashtable() { |
michael@0 | 1984 | return new sc_Hashtable(); |
michael@0 | 1985 | } |
michael@0 | 1986 | |
michael@0 | 1987 | /*** META ((export #t)) */ |
michael@0 | 1988 | function sc_hashtablePutBang(ht, key, val) { |
michael@0 | 1989 | var hash = sc_hash(key); |
michael@0 | 1990 | ht[hash] = new sc_HashtableElement(key, val); |
michael@0 | 1991 | } |
michael@0 | 1992 | |
michael@0 | 1993 | /*** META ((export #t)) */ |
michael@0 | 1994 | function sc_hashtableGet(ht, key) { |
michael@0 | 1995 | var hash = sc_hash(key); |
michael@0 | 1996 | if (hash in ht) |
michael@0 | 1997 | return ht[hash].val; |
michael@0 | 1998 | else |
michael@0 | 1999 | return false; |
michael@0 | 2000 | } |
michael@0 | 2001 | |
michael@0 | 2002 | /*** META ((export #t)) */ |
michael@0 | 2003 | function sc_hashtableForEach(ht, f) { |
michael@0 | 2004 | for (var v in ht) { |
michael@0 | 2005 | if (ht[v] instanceof sc_HashtableElement) |
michael@0 | 2006 | f(ht[v].key, ht[v].val); |
michael@0 | 2007 | } |
michael@0 | 2008 | } |
michael@0 | 2009 | |
michael@0 | 2010 | /*** META ((export hashtable-contains?) |
michael@0 | 2011 | (peephole (hole 2 "sc_hash(" 1 ") in " 0))) |
michael@0 | 2012 | */ |
michael@0 | 2013 | function sc_hashtableContains(ht, key) { |
michael@0 | 2014 | var hash = sc_hash(key); |
michael@0 | 2015 | if (hash in ht) |
michael@0 | 2016 | return true; |
michael@0 | 2017 | else |
michael@0 | 2018 | return false; |
michael@0 | 2019 | } |
michael@0 | 2020 | |
michael@0 | 2021 | var SC_HASH_COUNTER = 0; |
michael@0 | 2022 | |
michael@0 | 2023 | function sc_hash(o) { |
michael@0 | 2024 | if (o === null) |
michael@0 | 2025 | return "null"; |
michael@0 | 2026 | else if (o === undefined) |
michael@0 | 2027 | return "undefined"; |
michael@0 | 2028 | else if (o === true) |
michael@0 | 2029 | return "true"; |
michael@0 | 2030 | else if (o === false) |
michael@0 | 2031 | return "false"; |
michael@0 | 2032 | else if (typeof o === "number") |
michael@0 | 2033 | return "num-" + o; |
michael@0 | 2034 | else if (typeof o === "string") |
michael@0 | 2035 | return "jsstr-" + o; |
michael@0 | 2036 | else if (o.sc_getHash) |
michael@0 | 2037 | return o.sc_getHash(); |
michael@0 | 2038 | else |
michael@0 | 2039 | return sc_counterHash.call(o); |
michael@0 | 2040 | } |
michael@0 | 2041 | function sc_counterHash() { |
michael@0 | 2042 | if (!this.sc_hash) { |
michael@0 | 2043 | this.sc_hash = "hash-" + SC_HASH_COUNTER; |
michael@0 | 2044 | SC_HASH_COUNTER++; |
michael@0 | 2045 | } |
michael@0 | 2046 | return this.sc_hash; |
michael@0 | 2047 | } |
michael@0 | 2048 | |
michael@0 | 2049 | function sc_Trampoline(args, maxTailCalls) { |
michael@0 | 2050 | this['__trampoline return__'] = true; |
michael@0 | 2051 | this.args = args; |
michael@0 | 2052 | this.MAX_TAIL_CALLs = maxTailCalls; |
michael@0 | 2053 | } |
michael@0 | 2054 | // TODO: call/cc stuff |
michael@0 | 2055 | sc_Trampoline.prototype.restart = function() { |
michael@0 | 2056 | var o = this; |
michael@0 | 2057 | while (true) { |
michael@0 | 2058 | // set both globals. |
michael@0 | 2059 | SC_TAIL_OBJECT.calls = o.MAX_TAIL_CALLs-1; |
michael@0 | 2060 | var fun = o.args.callee; |
michael@0 | 2061 | var res = fun.apply(SC_TAIL_OBJECT, o.args); |
michael@0 | 2062 | if (res instanceof sc_Trampoline) |
michael@0 | 2063 | o = res; |
michael@0 | 2064 | else |
michael@0 | 2065 | return res; |
michael@0 | 2066 | } |
michael@0 | 2067 | } |
michael@0 | 2068 | |
michael@0 | 2069 | /*** META ((export bind-exit-lambda)) */ |
michael@0 | 2070 | function sc_bindExitLambda(proc) { |
michael@0 | 2071 | var escape_obj = new sc_BindExitException(); |
michael@0 | 2072 | var escape = function(res) { |
michael@0 | 2073 | escape_obj.res = res; |
michael@0 | 2074 | throw escape_obj; |
michael@0 | 2075 | }; |
michael@0 | 2076 | try { |
michael@0 | 2077 | return proc(escape); |
michael@0 | 2078 | } catch(e) { |
michael@0 | 2079 | if (e === escape_obj) { |
michael@0 | 2080 | return e.res; |
michael@0 | 2081 | } |
michael@0 | 2082 | throw e; |
michael@0 | 2083 | } |
michael@0 | 2084 | } |
michael@0 | 2085 | function sc_BindExitException() { |
michael@0 | 2086 | this._internalException = true; |
michael@0 | 2087 | } |
michael@0 | 2088 | |
michael@0 | 2089 | var SC_SCM2JS_GLOBALS = new Object(); |
michael@0 | 2090 | |
michael@0 | 2091 | // default tail-call depth. |
michael@0 | 2092 | // normally the program should set it again. but just in case... |
michael@0 | 2093 | var SC_TAIL_OBJECT = new Object(); |
michael@0 | 2094 | SC_SCM2JS_GLOBALS.TAIL_OBJECT = SC_TAIL_OBJECT; |
michael@0 | 2095 | // ======================== I/O ======================= |
michael@0 | 2096 | |
michael@0 | 2097 | /*------------------------------------------------------------------*/ |
michael@0 | 2098 | |
michael@0 | 2099 | function sc_EOF() { |
michael@0 | 2100 | } |
michael@0 | 2101 | var SC_EOF_OBJECT = new sc_EOF(); |
michael@0 | 2102 | |
michael@0 | 2103 | function sc_Port() { |
michael@0 | 2104 | } |
michael@0 | 2105 | |
michael@0 | 2106 | /* --------------- Input ports -------------------------------------*/ |
michael@0 | 2107 | |
michael@0 | 2108 | function sc_InputPort() { |
michael@0 | 2109 | } |
michael@0 | 2110 | sc_InputPort.prototype = new sc_Port(); |
michael@0 | 2111 | |
michael@0 | 2112 | sc_InputPort.prototype.peekChar = function() { |
michael@0 | 2113 | if (!("peeked" in this)) |
michael@0 | 2114 | this.peeked = this.getNextChar(); |
michael@0 | 2115 | return this.peeked; |
michael@0 | 2116 | } |
michael@0 | 2117 | sc_InputPort.prototype.readChar = function() { |
michael@0 | 2118 | var tmp = this.peekChar(); |
michael@0 | 2119 | delete this.peeked; |
michael@0 | 2120 | return tmp; |
michael@0 | 2121 | } |
michael@0 | 2122 | sc_InputPort.prototype.isCharReady = function() { |
michael@0 | 2123 | return true; |
michael@0 | 2124 | } |
michael@0 | 2125 | sc_InputPort.prototype.close = function() { |
michael@0 | 2126 | // do nothing |
michael@0 | 2127 | } |
michael@0 | 2128 | |
michael@0 | 2129 | /* .............. String port ..........................*/ |
michael@0 | 2130 | function sc_ErrorInputPort() { |
michael@0 | 2131 | }; |
michael@0 | 2132 | sc_ErrorInputPort.prototype = new sc_InputPort(); |
michael@0 | 2133 | sc_ErrorInputPort.prototype.getNextChar = function() { |
michael@0 | 2134 | throw "can't read from error-port."; |
michael@0 | 2135 | }; |
michael@0 | 2136 | sc_ErrorInputPort.prototype.isCharReady = function() { |
michael@0 | 2137 | return false; |
michael@0 | 2138 | }; |
michael@0 | 2139 | |
michael@0 | 2140 | |
michael@0 | 2141 | /* .............. String port ..........................*/ |
michael@0 | 2142 | |
michael@0 | 2143 | function sc_StringInputPort(jsStr) { |
michael@0 | 2144 | // we are going to do some charAts on the str. |
michael@0 | 2145 | // instead of recreating all the time a String-object, we |
michael@0 | 2146 | // create one in the beginning. (not sure, if this is really an optim) |
michael@0 | 2147 | this.str = new String(jsStr); |
michael@0 | 2148 | this.pos = 0; |
michael@0 | 2149 | } |
michael@0 | 2150 | sc_StringInputPort.prototype = new sc_InputPort(); |
michael@0 | 2151 | sc_StringInputPort.prototype.getNextChar = function() { |
michael@0 | 2152 | if (this.pos >= this.str.length) |
michael@0 | 2153 | return SC_EOF_OBJECT; |
michael@0 | 2154 | return this.str.charAt(this.pos++); |
michael@0 | 2155 | }; |
michael@0 | 2156 | |
michael@0 | 2157 | /* ------------- Read and other lib-funs -------------------------------*/ |
michael@0 | 2158 | function sc_Token(type, val, pos) { |
michael@0 | 2159 | this.type = type; |
michael@0 | 2160 | this.val = val; |
michael@0 | 2161 | this.pos = pos; |
michael@0 | 2162 | } |
michael@0 | 2163 | sc_Token.EOF = 0/*EOF*/; |
michael@0 | 2164 | sc_Token.OPEN_PAR = 1/*OPEN_PAR*/; |
michael@0 | 2165 | sc_Token.CLOSE_PAR = 2/*CLOSE_PAR*/; |
michael@0 | 2166 | sc_Token.OPEN_BRACE = 3/*OPEN_BRACE*/; |
michael@0 | 2167 | sc_Token.CLOSE_BRACE = 4/*CLOSE_BRACE*/; |
michael@0 | 2168 | sc_Token.OPEN_BRACKET = 5/*OPEN_BRACKET*/; |
michael@0 | 2169 | sc_Token.CLOSE_BRACKET = 6/*CLOSE_BRACKET*/; |
michael@0 | 2170 | sc_Token.WHITESPACE = 7/*WHITESPACE*/; |
michael@0 | 2171 | sc_Token.QUOTE = 8/*QUOTE*/; |
michael@0 | 2172 | sc_Token.ID = 9/*ID*/; |
michael@0 | 2173 | sc_Token.DOT = 10/*DOT*/; |
michael@0 | 2174 | sc_Token.STRING = 11/*STRING*/; |
michael@0 | 2175 | sc_Token.NUMBER = 12/*NUMBER*/; |
michael@0 | 2176 | sc_Token.ERROR = 13/*ERROR*/; |
michael@0 | 2177 | sc_Token.VECTOR_BEGIN = 14/*VECTOR_BEGIN*/; |
michael@0 | 2178 | sc_Token.TRUE = 15/*TRUE*/; |
michael@0 | 2179 | sc_Token.FALSE = 16/*FALSE*/; |
michael@0 | 2180 | sc_Token.UNSPECIFIED = 17/*UNSPECIFIED*/; |
michael@0 | 2181 | sc_Token.REFERENCE = 18/*REFERENCE*/; |
michael@0 | 2182 | sc_Token.STORE = 19/*STORE*/; |
michael@0 | 2183 | sc_Token.CHAR = 20/*CHAR*/; |
michael@0 | 2184 | |
michael@0 | 2185 | var SC_ID_CLASS = SC_LOWER_CLASS + SC_UPPER_CLASS + "!$%*+-./:<=>?@^_~"; |
michael@0 | 2186 | function sc_Tokenizer(port) { |
michael@0 | 2187 | this.port = port; |
michael@0 | 2188 | } |
michael@0 | 2189 | sc_Tokenizer.prototype.peekToken = function() { |
michael@0 | 2190 | if (this.peeked) |
michael@0 | 2191 | return this.peeked; |
michael@0 | 2192 | var newToken = this.nextToken(); |
michael@0 | 2193 | this.peeked = newToken; |
michael@0 | 2194 | return newToken; |
michael@0 | 2195 | }; |
michael@0 | 2196 | sc_Tokenizer.prototype.readToken = function() { |
michael@0 | 2197 | var tmp = this.peekToken(); |
michael@0 | 2198 | delete this.peeked; |
michael@0 | 2199 | return tmp; |
michael@0 | 2200 | }; |
michael@0 | 2201 | sc_Tokenizer.prototype.nextToken = function() { |
michael@0 | 2202 | var port = this.port; |
michael@0 | 2203 | |
michael@0 | 2204 | function isNumberChar(c) { |
michael@0 | 2205 | return (c >= "0" && c <= "9"); |
michael@0 | 2206 | }; |
michael@0 | 2207 | function isIdOrNumberChar(c) { |
michael@0 | 2208 | return SC_ID_CLASS.indexOf(c) != -1 || // ID-char |
michael@0 | 2209 | (c >= "0" && c <= "9"); |
michael@0 | 2210 | } |
michael@0 | 2211 | function isWhitespace(c) { |
michael@0 | 2212 | return c === " " || c === "\r" || c === "\n" || c === "\t" || c === "\f"; |
michael@0 | 2213 | }; |
michael@0 | 2214 | function isWhitespaceOrEOF(c) { |
michael@0 | 2215 | return isWhitespace(c) || c === SC_EOF_OBJECT; |
michael@0 | 2216 | }; |
michael@0 | 2217 | |
michael@0 | 2218 | function readString() { |
michael@0 | 2219 | res = ""; |
michael@0 | 2220 | while (true) { |
michael@0 | 2221 | var c = port.readChar(); |
michael@0 | 2222 | switch (c) { |
michael@0 | 2223 | case '"': |
michael@0 | 2224 | return new sc_Token(11/*STRING*/, res); |
michael@0 | 2225 | case "\\": |
michael@0 | 2226 | var tmp = port.readChar(); |
michael@0 | 2227 | switch (tmp) { |
michael@0 | 2228 | case '0': res += "\0"; break; |
michael@0 | 2229 | case 'a': res += "\a"; break; |
michael@0 | 2230 | case 'b': res += "\b"; break; |
michael@0 | 2231 | case 'f': res += "\f"; break; |
michael@0 | 2232 | case 'n': res += "\n"; break; |
michael@0 | 2233 | case 'r': res += "\r"; break; |
michael@0 | 2234 | case 't': res += "\t"; break; |
michael@0 | 2235 | case 'v': res += "\v"; break; |
michael@0 | 2236 | case '"': res += '"'; break; |
michael@0 | 2237 | case '\\': res += '\\'; break; |
michael@0 | 2238 | case 'x': |
michael@0 | 2239 | /* hexa-number */ |
michael@0 | 2240 | var nb = 0; |
michael@0 | 2241 | while (true) { |
michael@0 | 2242 | var hexC = port.peekChar(); |
michael@0 | 2243 | if (hexC >= '0' && hexC <= '9') { |
michael@0 | 2244 | port.readChar(); |
michael@0 | 2245 | nb = nb * 16 + hexC.charCodeAt(0) - '0'.charCodeAt(0); |
michael@0 | 2246 | } else if (hexC >= 'a' && hexC <= 'f') { |
michael@0 | 2247 | port.readChar(); |
michael@0 | 2248 | nb = nb * 16 + hexC.charCodeAt(0) - 'a'.charCodeAt(0); |
michael@0 | 2249 | } else if (hexC >= 'A' && hexC <= 'F') { |
michael@0 | 2250 | port.readChar(); |
michael@0 | 2251 | nb = nb * 16 + hexC.charCodeAt(0) - 'A'.charCodeAt(0); |
michael@0 | 2252 | } else { |
michael@0 | 2253 | // next char isn't part of hex. |
michael@0 | 2254 | res += String.fromCharCode(nb); |
michael@0 | 2255 | break; |
michael@0 | 2256 | } |
michael@0 | 2257 | } |
michael@0 | 2258 | break; |
michael@0 | 2259 | default: |
michael@0 | 2260 | if (tmp === SC_EOF_OBJECT) { |
michael@0 | 2261 | return new sc_Token(13/*ERROR*/, "unclosed string-literal" + res); |
michael@0 | 2262 | } |
michael@0 | 2263 | res += tmp; |
michael@0 | 2264 | } |
michael@0 | 2265 | break; |
michael@0 | 2266 | default: |
michael@0 | 2267 | if (c === SC_EOF_OBJECT) { |
michael@0 | 2268 | return new sc_Token(13/*ERROR*/, "unclosed string-literal" + res); |
michael@0 | 2269 | } |
michael@0 | 2270 | res += c; |
michael@0 | 2271 | } |
michael@0 | 2272 | } |
michael@0 | 2273 | }; |
michael@0 | 2274 | function readIdOrNumber(firstChar) { |
michael@0 | 2275 | var res = firstChar; |
michael@0 | 2276 | while (isIdOrNumberChar(port.peekChar())) |
michael@0 | 2277 | res += port.readChar(); |
michael@0 | 2278 | if (isNaN(res)) |
michael@0 | 2279 | return new sc_Token(9/*ID*/, res); |
michael@0 | 2280 | else |
michael@0 | 2281 | return new sc_Token(12/*NUMBER*/, res - 0); |
michael@0 | 2282 | }; |
michael@0 | 2283 | |
michael@0 | 2284 | function skipWhitespaceAndComments() { |
michael@0 | 2285 | var done = false; |
michael@0 | 2286 | while (!done) { |
michael@0 | 2287 | done = true; |
michael@0 | 2288 | while (isWhitespace(port.peekChar())) |
michael@0 | 2289 | port.readChar(); |
michael@0 | 2290 | if (port.peekChar() === ';') { |
michael@0 | 2291 | port.readChar(); |
michael@0 | 2292 | done = false; |
michael@0 | 2293 | while (true) { |
michael@0 | 2294 | curChar = port.readChar(); |
michael@0 | 2295 | if (curChar === SC_EOF_OBJECT || |
michael@0 | 2296 | curChar === '\n') |
michael@0 | 2297 | break; |
michael@0 | 2298 | } |
michael@0 | 2299 | } |
michael@0 | 2300 | } |
michael@0 | 2301 | }; |
michael@0 | 2302 | |
michael@0 | 2303 | function readDot() { |
michael@0 | 2304 | if (isWhitespace(port.peekChar())) |
michael@0 | 2305 | return new sc_Token(10/*DOT*/); |
michael@0 | 2306 | else |
michael@0 | 2307 | return readIdOrNumber("."); |
michael@0 | 2308 | }; |
michael@0 | 2309 | |
michael@0 | 2310 | function readSharp() { |
michael@0 | 2311 | var c = port.readChar(); |
michael@0 | 2312 | if (isWhitespace(c)) |
michael@0 | 2313 | return new sc_Token(13/*ERROR*/, "bad #-pattern0."); |
michael@0 | 2314 | |
michael@0 | 2315 | // reference |
michael@0 | 2316 | if (isNumberChar(c)) { |
michael@0 | 2317 | var nb = c - 0; |
michael@0 | 2318 | while (isNumberChar(port.peekChar())) |
michael@0 | 2319 | nb = nb*10 + (port.readChar() - 0); |
michael@0 | 2320 | switch (port.readChar()) { |
michael@0 | 2321 | case '#': |
michael@0 | 2322 | return new sc_Token(18/*REFERENCE*/, nb); |
michael@0 | 2323 | case '=': |
michael@0 | 2324 | return new sc_Token(19/*STORE*/, nb); |
michael@0 | 2325 | default: |
michael@0 | 2326 | return new sc_Token(13/*ERROR*/, "bad #-pattern1." + nb); |
michael@0 | 2327 | } |
michael@0 | 2328 | } |
michael@0 | 2329 | |
michael@0 | 2330 | if (c === "(") |
michael@0 | 2331 | return new sc_Token(14/*VECTOR_BEGIN*/); |
michael@0 | 2332 | |
michael@0 | 2333 | if (c === "\\") { // character |
michael@0 | 2334 | var tmp = "" |
michael@0 | 2335 | while (!isWhitespaceOrEOF(port.peekChar())) |
michael@0 | 2336 | tmp += port.readChar(); |
michael@0 | 2337 | switch (tmp.length) { |
michael@0 | 2338 | case 0: // it's escaping a whitespace char: |
michael@0 | 2339 | if (sc_isEOFObject(port.peekChar)) |
michael@0 | 2340 | return new sc_Token(13/*ERROR*/, "bad #-pattern2."); |
michael@0 | 2341 | else |
michael@0 | 2342 | return new sc_Token(20/*CHAR*/, port.readChar()); |
michael@0 | 2343 | case 1: |
michael@0 | 2344 | return new sc_Token(20/*CHAR*/, tmp); |
michael@0 | 2345 | default: |
michael@0 | 2346 | var entry = sc_Char.readable2char[tmp.toLowerCase()]; |
michael@0 | 2347 | if (entry) |
michael@0 | 2348 | return new sc_Token(20/*CHAR*/, entry); |
michael@0 | 2349 | else |
michael@0 | 2350 | return new sc_Token(13/*ERROR*/, "unknown character description: #\\" + tmp); |
michael@0 | 2351 | } |
michael@0 | 2352 | } |
michael@0 | 2353 | |
michael@0 | 2354 | // some constants (#t, #f, #unspecified) |
michael@0 | 2355 | var res; |
michael@0 | 2356 | var needing; |
michael@0 | 2357 | switch (c) { |
michael@0 | 2358 | case 't': res = new sc_Token(15/*TRUE*/, true); needing = ""; break; |
michael@0 | 2359 | case 'f': res = new sc_Token(16/*FALSE*/, false); needing = ""; break; |
michael@0 | 2360 | case 'u': res = new sc_Token(17/*UNSPECIFIED*/, undefined); needing = "nspecified"; break; |
michael@0 | 2361 | default: |
michael@0 | 2362 | return new sc_Token(13/*ERROR*/, "bad #-pattern3: " + c); |
michael@0 | 2363 | } |
michael@0 | 2364 | while(true) { |
michael@0 | 2365 | c = port.peekChar(); |
michael@0 | 2366 | if ((isWhitespaceOrEOF(c) || c === ')') && |
michael@0 | 2367 | needing == "") |
michael@0 | 2368 | return res; |
michael@0 | 2369 | else if (isWhitespace(c) || needing == "") |
michael@0 | 2370 | return new sc_Token(13/*ERROR*/, "bad #-pattern4 " + c + " " + needing); |
michael@0 | 2371 | else if (needing.charAt(0) == c) { |
michael@0 | 2372 | port.readChar(); // consume |
michael@0 | 2373 | needing = needing.slice(1); |
michael@0 | 2374 | } else |
michael@0 | 2375 | return new sc_Token(13/*ERROR*/, "bad #-pattern5"); |
michael@0 | 2376 | } |
michael@0 | 2377 | |
michael@0 | 2378 | }; |
michael@0 | 2379 | |
michael@0 | 2380 | skipWhitespaceAndComments(); |
michael@0 | 2381 | var curChar = port.readChar(); |
michael@0 | 2382 | if (curChar === SC_EOF_OBJECT) |
michael@0 | 2383 | return new sc_Token(0/*EOF*/, curChar); |
michael@0 | 2384 | switch (curChar) |
michael@0 | 2385 | { |
michael@0 | 2386 | case " ": |
michael@0 | 2387 | case "\n": |
michael@0 | 2388 | case "\t": |
michael@0 | 2389 | return readWhitespace(); |
michael@0 | 2390 | case "(": |
michael@0 | 2391 | return new sc_Token(1/*OPEN_PAR*/); |
michael@0 | 2392 | case ")": |
michael@0 | 2393 | return new sc_Token(2/*CLOSE_PAR*/); |
michael@0 | 2394 | case "{": |
michael@0 | 2395 | return new sc_Token(3/*OPEN_BRACE*/); |
michael@0 | 2396 | case "}": |
michael@0 | 2397 | return new sc_Token(4/*CLOSE_BRACE*/); |
michael@0 | 2398 | case "[": |
michael@0 | 2399 | return new sc_Token(5/*OPEN_BRACKET*/); |
michael@0 | 2400 | case "]": |
michael@0 | 2401 | return new sc_Token(6/*CLOSE_BRACKET*/); |
michael@0 | 2402 | case "'": |
michael@0 | 2403 | return new sc_Token(8/*QUOTE*/); |
michael@0 | 2404 | case "#": |
michael@0 | 2405 | return readSharp(); |
michael@0 | 2406 | case ".": |
michael@0 | 2407 | return readDot(); |
michael@0 | 2408 | case '"': |
michael@0 | 2409 | return readString(); |
michael@0 | 2410 | default: |
michael@0 | 2411 | if (isIdOrNumberChar(curChar)) |
michael@0 | 2412 | return readIdOrNumber(curChar); |
michael@0 | 2413 | throw "unexpected character: " + curChar; |
michael@0 | 2414 | } |
michael@0 | 2415 | }; |
michael@0 | 2416 | |
michael@0 | 2417 | function sc_Reader(tokenizer) { |
michael@0 | 2418 | this.tokenizer = tokenizer; |
michael@0 | 2419 | this.backref = new Array(); |
michael@0 | 2420 | } |
michael@0 | 2421 | sc_Reader.prototype.read = function() { |
michael@0 | 2422 | function readList(listBeginType) { |
michael@0 | 2423 | function matchesPeer(open, close) { |
michael@0 | 2424 | return open === 1/*OPEN_PAR*/ && close === 2/*CLOSE_PAR*/ |
michael@0 | 2425 | || open === 3/*OPEN_BRACE*/ && close === 4/*CLOSE_BRACE*/ |
michael@0 | 2426 | || open === 5/*OPEN_BRACKET*/ && close === 6/*CLOSE_BRACKET*/; |
michael@0 | 2427 | }; |
michael@0 | 2428 | var res = null; |
michael@0 | 2429 | |
michael@0 | 2430 | while (true) { |
michael@0 | 2431 | var token = tokenizer.peekToken(); |
michael@0 | 2432 | |
michael@0 | 2433 | switch (token.type) { |
michael@0 | 2434 | case 2/*CLOSE_PAR*/: |
michael@0 | 2435 | case 4/*CLOSE_BRACE*/: |
michael@0 | 2436 | case 6/*CLOSE_BRACKET*/: |
michael@0 | 2437 | if (matchesPeer(listBeginType, token.type)) { |
michael@0 | 2438 | tokenizer.readToken(); // consume token |
michael@0 | 2439 | return sc_reverseBang(res); |
michael@0 | 2440 | } else |
michael@0 | 2441 | throw "closing par doesn't match: " + listBeginType |
michael@0 | 2442 | + " " + listEndType; |
michael@0 | 2443 | |
michael@0 | 2444 | case 0/*EOF*/: |
michael@0 | 2445 | throw "unexpected end of file"; |
michael@0 | 2446 | |
michael@0 | 2447 | case 10/*DOT*/: |
michael@0 | 2448 | tokenizer.readToken(); // consume token |
michael@0 | 2449 | var cdr = this.read(); |
michael@0 | 2450 | var par = tokenizer.readToken(); |
michael@0 | 2451 | if (!matchesPeer(listBeginType, par.type)) |
michael@0 | 2452 | throw "closing par doesn't match: " + listBeginType |
michael@0 | 2453 | + " " + par.type; |
michael@0 | 2454 | else |
michael@0 | 2455 | return sc_reverseAppendBang(res, cdr); |
michael@0 | 2456 | |
michael@0 | 2457 | |
michael@0 | 2458 | default: |
michael@0 | 2459 | res = sc_cons(this.read(), res); |
michael@0 | 2460 | } |
michael@0 | 2461 | } |
michael@0 | 2462 | }; |
michael@0 | 2463 | function readQuote() { |
michael@0 | 2464 | return sc_cons("quote", sc_cons(this.read(), null)); |
michael@0 | 2465 | }; |
michael@0 | 2466 | function readVector() { |
michael@0 | 2467 | // opening-parenthesis is already consumed |
michael@0 | 2468 | var a = new Array(); |
michael@0 | 2469 | while (true) { |
michael@0 | 2470 | var token = tokenizer.peekToken(); |
michael@0 | 2471 | switch (token.type) { |
michael@0 | 2472 | case 2/*CLOSE_PAR*/: |
michael@0 | 2473 | tokenizer.readToken(); |
michael@0 | 2474 | return a; |
michael@0 | 2475 | |
michael@0 | 2476 | default: |
michael@0 | 2477 | a.push(this.read()); |
michael@0 | 2478 | } |
michael@0 | 2479 | } |
michael@0 | 2480 | }; |
michael@0 | 2481 | |
michael@0 | 2482 | function storeRefence(nb) { |
michael@0 | 2483 | var tmp = this.read(); |
michael@0 | 2484 | this.backref[nb] = tmp; |
michael@0 | 2485 | return tmp; |
michael@0 | 2486 | }; |
michael@0 | 2487 | |
michael@0 | 2488 | function readReference(nb) { |
michael@0 | 2489 | if (nb in this.backref) |
michael@0 | 2490 | return this.backref[nb]; |
michael@0 | 2491 | else |
michael@0 | 2492 | throw "bad reference: " + nb; |
michael@0 | 2493 | }; |
michael@0 | 2494 | |
michael@0 | 2495 | var tokenizer = this.tokenizer; |
michael@0 | 2496 | |
michael@0 | 2497 | var token = tokenizer.readToken(); |
michael@0 | 2498 | |
michael@0 | 2499 | // handle error |
michael@0 | 2500 | if (token.type === 13/*ERROR*/) |
michael@0 | 2501 | throw token.val; |
michael@0 | 2502 | |
michael@0 | 2503 | switch (token.type) { |
michael@0 | 2504 | case 1/*OPEN_PAR*/: |
michael@0 | 2505 | case 3/*OPEN_BRACE*/: |
michael@0 | 2506 | case 5/*OPEN_BRACKET*/: |
michael@0 | 2507 | return readList.call(this, token.type); |
michael@0 | 2508 | case 8/*QUOTE*/: |
michael@0 | 2509 | return readQuote.call(this); |
michael@0 | 2510 | case 11/*STRING*/: |
michael@0 | 2511 | return sc_jsstring2string(token.val); |
michael@0 | 2512 | case 20/*CHAR*/: |
michael@0 | 2513 | return new sc_Char(token.val); |
michael@0 | 2514 | case 14/*VECTOR_BEGIN*/: |
michael@0 | 2515 | return readVector.call(this); |
michael@0 | 2516 | case 18/*REFERENCE*/: |
michael@0 | 2517 | return readReference.call(this, token.val); |
michael@0 | 2518 | case 19/*STORE*/: |
michael@0 | 2519 | return storeRefence.call(this, token.val); |
michael@0 | 2520 | case 9/*ID*/: |
michael@0 | 2521 | return sc_jsstring2symbol(token.val); |
michael@0 | 2522 | case 0/*EOF*/: |
michael@0 | 2523 | case 12/*NUMBER*/: |
michael@0 | 2524 | case 15/*TRUE*/: |
michael@0 | 2525 | case 16/*FALSE*/: |
michael@0 | 2526 | case 17/*UNSPECIFIED*/: |
michael@0 | 2527 | return token.val; |
michael@0 | 2528 | default: |
michael@0 | 2529 | throw "unexpected token " + token.type + " " + token.val; |
michael@0 | 2530 | } |
michael@0 | 2531 | }; |
michael@0 | 2532 | |
michael@0 | 2533 | /*** META ((export #t)) */ |
michael@0 | 2534 | function sc_read(port) { |
michael@0 | 2535 | if (port === undefined) // we assume the port hasn't been given. |
michael@0 | 2536 | port = SC_DEFAULT_IN; // THREAD: shared var... |
michael@0 | 2537 | var reader = new sc_Reader(new sc_Tokenizer(port)); |
michael@0 | 2538 | return reader.read(); |
michael@0 | 2539 | } |
michael@0 | 2540 | /*** META ((export #t)) */ |
michael@0 | 2541 | function sc_readChar(port) { |
michael@0 | 2542 | if (port === undefined) // we assume the port hasn't been given. |
michael@0 | 2543 | port = SC_DEFAULT_IN; // THREAD: shared var... |
michael@0 | 2544 | var t = port.readChar(); |
michael@0 | 2545 | return t === SC_EOF_OBJECT? t: new sc_Char(t); |
michael@0 | 2546 | } |
michael@0 | 2547 | /*** META ((export #t)) */ |
michael@0 | 2548 | function sc_peekChar(port) { |
michael@0 | 2549 | if (port === undefined) // we assume the port hasn't been given. |
michael@0 | 2550 | port = SC_DEFAULT_IN; // THREAD: shared var... |
michael@0 | 2551 | var t = port.peekChar(); |
michael@0 | 2552 | return t === SC_EOF_OBJECT? t: new sc_Char(t); |
michael@0 | 2553 | } |
michael@0 | 2554 | /*** META ((export #t) |
michael@0 | 2555 | (type bool)) |
michael@0 | 2556 | */ |
michael@0 | 2557 | function sc_isCharReady(port) { |
michael@0 | 2558 | if (port === undefined) // we assume the port hasn't been given. |
michael@0 | 2559 | port = SC_DEFAULT_IN; // THREAD: shared var... |
michael@0 | 2560 | return port.isCharReady(); |
michael@0 | 2561 | } |
michael@0 | 2562 | /*** META ((export #t) |
michael@0 | 2563 | (peephole (postfix ".close()"))) |
michael@0 | 2564 | */ |
michael@0 | 2565 | function sc_closeInputPort(p) { |
michael@0 | 2566 | return p.close(); |
michael@0 | 2567 | } |
michael@0 | 2568 | |
michael@0 | 2569 | /*** META ((export #t) |
michael@0 | 2570 | (type bool) |
michael@0 | 2571 | (peephole (postfix " instanceof sc_InputPort"))) |
michael@0 | 2572 | */ |
michael@0 | 2573 | function sc_isInputPort(o) { |
michael@0 | 2574 | return (o instanceof sc_InputPort); |
michael@0 | 2575 | } |
michael@0 | 2576 | |
michael@0 | 2577 | /*** META ((export eof-object?) |
michael@0 | 2578 | (type bool) |
michael@0 | 2579 | (peephole (postfix " === SC_EOF_OBJECT"))) |
michael@0 | 2580 | */ |
michael@0 | 2581 | function sc_isEOFObject(o) { |
michael@0 | 2582 | return o === SC_EOF_OBJECT; |
michael@0 | 2583 | } |
michael@0 | 2584 | |
michael@0 | 2585 | /*** META ((export #t) |
michael@0 | 2586 | (peephole (hole 0 "SC_DEFAULT_IN"))) |
michael@0 | 2587 | */ |
michael@0 | 2588 | function sc_currentInputPort() { |
michael@0 | 2589 | return SC_DEFAULT_IN; |
michael@0 | 2590 | } |
michael@0 | 2591 | |
michael@0 | 2592 | /* ------------ file operations are not supported -----------*/ |
michael@0 | 2593 | /*** META ((export #t)) */ |
michael@0 | 2594 | function sc_callWithInputFile(s, proc) { |
michael@0 | 2595 | throw "can't open " + s; |
michael@0 | 2596 | } |
michael@0 | 2597 | |
michael@0 | 2598 | /*** META ((export #t)) */ |
michael@0 | 2599 | function sc_callWithOutputFile(s, proc) { |
michael@0 | 2600 | throw "can't open " + s; |
michael@0 | 2601 | } |
michael@0 | 2602 | |
michael@0 | 2603 | /*** META ((export #t)) */ |
michael@0 | 2604 | function sc_withInputFromFile(s, thunk) { |
michael@0 | 2605 | throw "can't open " + s; |
michael@0 | 2606 | } |
michael@0 | 2607 | |
michael@0 | 2608 | /*** META ((export #t)) */ |
michael@0 | 2609 | function sc_withOutputToFile(s, thunk) { |
michael@0 | 2610 | throw "can't open " + s; |
michael@0 | 2611 | } |
michael@0 | 2612 | |
michael@0 | 2613 | /*** META ((export #t)) */ |
michael@0 | 2614 | function sc_openInputFile(s) { |
michael@0 | 2615 | throw "can't open " + s; |
michael@0 | 2616 | } |
michael@0 | 2617 | |
michael@0 | 2618 | /*** META ((export #t)) */ |
michael@0 | 2619 | function sc_openOutputFile(s) { |
michael@0 | 2620 | throw "can't open " + s; |
michael@0 | 2621 | } |
michael@0 | 2622 | |
michael@0 | 2623 | /* ----------------------------------------------------------------------------*/ |
michael@0 | 2624 | /*** META ((export #t)) */ |
michael@0 | 2625 | function sc_basename(p) { |
michael@0 | 2626 | var i = p.lastIndexOf('/'); |
michael@0 | 2627 | |
michael@0 | 2628 | if(i >= 0) |
michael@0 | 2629 | return p.substring(i + 1, p.length); |
michael@0 | 2630 | else |
michael@0 | 2631 | return ''; |
michael@0 | 2632 | } |
michael@0 | 2633 | |
michael@0 | 2634 | /*** META ((export #t)) */ |
michael@0 | 2635 | function sc_dirname(p) { |
michael@0 | 2636 | var i = p.lastIndexOf('/'); |
michael@0 | 2637 | |
michael@0 | 2638 | if(i >= 0) |
michael@0 | 2639 | return p.substring(0, i); |
michael@0 | 2640 | else |
michael@0 | 2641 | return ''; |
michael@0 | 2642 | } |
michael@0 | 2643 | |
michael@0 | 2644 | /* ----------------------------------------------------------------------------*/ |
michael@0 | 2645 | |
michael@0 | 2646 | /*** META ((export #t)) */ |
michael@0 | 2647 | function sc_withInputFromPort(p, thunk) { |
michael@0 | 2648 | try { |
michael@0 | 2649 | var tmp = SC_DEFAULT_IN; // THREAD: shared var. |
michael@0 | 2650 | SC_DEFAULT_IN = p; |
michael@0 | 2651 | return thunk(); |
michael@0 | 2652 | } finally { |
michael@0 | 2653 | SC_DEFAULT_IN = tmp; |
michael@0 | 2654 | } |
michael@0 | 2655 | } |
michael@0 | 2656 | |
michael@0 | 2657 | /*** META ((export #t)) */ |
michael@0 | 2658 | function sc_withInputFromString(s, thunk) { |
michael@0 | 2659 | return sc_withInputFromPort(new sc_StringInputPort(sc_string2jsstring(s)), thunk); |
michael@0 | 2660 | } |
michael@0 | 2661 | |
michael@0 | 2662 | /*** META ((export #t)) */ |
michael@0 | 2663 | function sc_withOutputToPort(p, thunk) { |
michael@0 | 2664 | try { |
michael@0 | 2665 | var tmp = SC_DEFAULT_OUT; // THREAD: shared var. |
michael@0 | 2666 | SC_DEFAULT_OUT = p; |
michael@0 | 2667 | return thunk(); |
michael@0 | 2668 | } finally { |
michael@0 | 2669 | SC_DEFAULT_OUT = tmp; |
michael@0 | 2670 | } |
michael@0 | 2671 | } |
michael@0 | 2672 | |
michael@0 | 2673 | /*** META ((export #t)) */ |
michael@0 | 2674 | function sc_withOutputToString(thunk) { |
michael@0 | 2675 | var p = new sc_StringOutputPort(); |
michael@0 | 2676 | sc_withOutputToPort(p, thunk); |
michael@0 | 2677 | return p.close(); |
michael@0 | 2678 | } |
michael@0 | 2679 | |
michael@0 | 2680 | /*** META ((export #t)) */ |
michael@0 | 2681 | function sc_withOutputToProcedure(proc, thunk) { |
michael@0 | 2682 | var t = function(s) { proc(sc_jsstring2string(s)); }; |
michael@0 | 2683 | return sc_withOutputToPort(new sc_GenericOutputPort(t), thunk); |
michael@0 | 2684 | } |
michael@0 | 2685 | |
michael@0 | 2686 | /*** META ((export #t) |
michael@0 | 2687 | (peephole (hole 0 "new sc_StringOutputPort()"))) |
michael@0 | 2688 | */ |
michael@0 | 2689 | function sc_openOutputString() { |
michael@0 | 2690 | return new sc_StringOutputPort(); |
michael@0 | 2691 | } |
michael@0 | 2692 | |
michael@0 | 2693 | /*** META ((export #t)) */ |
michael@0 | 2694 | function sc_openInputString(str) { |
michael@0 | 2695 | return new sc_StringInputPort(sc_string2jsstring(str)); |
michael@0 | 2696 | } |
michael@0 | 2697 | |
michael@0 | 2698 | /* ----------------------------------------------------------------------------*/ |
michael@0 | 2699 | |
michael@0 | 2700 | function sc_OutputPort() { |
michael@0 | 2701 | } |
michael@0 | 2702 | sc_OutputPort.prototype = new sc_Port(); |
michael@0 | 2703 | sc_OutputPort.prototype.appendJSString = function(obj) { |
michael@0 | 2704 | /* do nothing */ |
michael@0 | 2705 | } |
michael@0 | 2706 | sc_OutputPort.prototype.close = function() { |
michael@0 | 2707 | /* do nothing */ |
michael@0 | 2708 | } |
michael@0 | 2709 | |
michael@0 | 2710 | function sc_StringOutputPort() { |
michael@0 | 2711 | this.res = ""; |
michael@0 | 2712 | } |
michael@0 | 2713 | sc_StringOutputPort.prototype = new sc_OutputPort(); |
michael@0 | 2714 | sc_StringOutputPort.prototype.appendJSString = function(s) { |
michael@0 | 2715 | this.res += s; |
michael@0 | 2716 | } |
michael@0 | 2717 | sc_StringOutputPort.prototype.close = function() { |
michael@0 | 2718 | return sc_jsstring2string(this.res); |
michael@0 | 2719 | } |
michael@0 | 2720 | |
michael@0 | 2721 | /*** META ((export #t)) */ |
michael@0 | 2722 | function sc_getOutputString(sp) { |
michael@0 | 2723 | return sc_jsstring2string(sp.res); |
michael@0 | 2724 | } |
michael@0 | 2725 | |
michael@0 | 2726 | |
michael@0 | 2727 | function sc_ErrorOutputPort() { |
michael@0 | 2728 | } |
michael@0 | 2729 | sc_ErrorOutputPort.prototype = new sc_OutputPort(); |
michael@0 | 2730 | sc_ErrorOutputPort.prototype.appendJSString = function(s) { |
michael@0 | 2731 | throw "don't write on ErrorPort!"; |
michael@0 | 2732 | } |
michael@0 | 2733 | sc_ErrorOutputPort.prototype.close = function() { |
michael@0 | 2734 | /* do nothing */ |
michael@0 | 2735 | } |
michael@0 | 2736 | |
michael@0 | 2737 | function sc_GenericOutputPort(appendJSString, close) { |
michael@0 | 2738 | this.appendJSString = appendJSString; |
michael@0 | 2739 | if (close) |
michael@0 | 2740 | this.close = close; |
michael@0 | 2741 | } |
michael@0 | 2742 | sc_GenericOutputPort.prototype = new sc_OutputPort(); |
michael@0 | 2743 | |
michael@0 | 2744 | /*** META ((export #t) |
michael@0 | 2745 | (type bool) |
michael@0 | 2746 | (peephole (postfix " instanceof sc_OutputPort"))) |
michael@0 | 2747 | */ |
michael@0 | 2748 | function sc_isOutputPort(o) { |
michael@0 | 2749 | return (o instanceof sc_OutputPort); |
michael@0 | 2750 | } |
michael@0 | 2751 | |
michael@0 | 2752 | /*** META ((export #t) |
michael@0 | 2753 | (peephole (postfix ".close()"))) |
michael@0 | 2754 | */ |
michael@0 | 2755 | function sc_closeOutputPort(p) { |
michael@0 | 2756 | return p.close(); |
michael@0 | 2757 | } |
michael@0 | 2758 | |
michael@0 | 2759 | /* ------------------ write ---------------------------------------------------*/ |
michael@0 | 2760 | |
michael@0 | 2761 | /*** META ((export #t)) */ |
michael@0 | 2762 | function sc_write(o, p) { |
michael@0 | 2763 | if (p === undefined) // we assume not given |
michael@0 | 2764 | p = SC_DEFAULT_OUT; |
michael@0 | 2765 | p.appendJSString(sc_toWriteString(o)); |
michael@0 | 2766 | } |
michael@0 | 2767 | |
michael@0 | 2768 | function sc_toWriteString(o) { |
michael@0 | 2769 | if (o === null) |
michael@0 | 2770 | return "()"; |
michael@0 | 2771 | else if (o === true) |
michael@0 | 2772 | return "#t"; |
michael@0 | 2773 | else if (o === false) |
michael@0 | 2774 | return "#f"; |
michael@0 | 2775 | else if (o === undefined) |
michael@0 | 2776 | return "#unspecified"; |
michael@0 | 2777 | else if (typeof o === 'function') |
michael@0 | 2778 | return "#<procedure " + sc_hash(o) + ">"; |
michael@0 | 2779 | else if (o.sc_toWriteString) |
michael@0 | 2780 | return o.sc_toWriteString(); |
michael@0 | 2781 | else |
michael@0 | 2782 | return o.toString(); |
michael@0 | 2783 | } |
michael@0 | 2784 | |
michael@0 | 2785 | function sc_escapeWriteString(s) { |
michael@0 | 2786 | var res = ""; |
michael@0 | 2787 | var j = 0; |
michael@0 | 2788 | for (i = 0; i < s.length; i++) { |
michael@0 | 2789 | switch (s.charAt(i)) { |
michael@0 | 2790 | case "\0": res += s.substring(j, i) + "\\0"; j = i + 1; break; |
michael@0 | 2791 | case "\b": res += s.substring(j, i) + "\\b"; j = i + 1; break; |
michael@0 | 2792 | case "\f": res += s.substring(j, i) + "\\f"; j = i + 1; break; |
michael@0 | 2793 | case "\n": res += s.substring(j, i) + "\\n"; j = i + 1; break; |
michael@0 | 2794 | case "\r": res += s.substring(j, i) + "\\r"; j = i + 1; break; |
michael@0 | 2795 | case "\t": res += s.substring(j, i) + "\\t"; j = i + 1; break; |
michael@0 | 2796 | case "\v": res += s.substring(j, i) + "\\v"; j = i + 1; break; |
michael@0 | 2797 | case '"': res += s.substring(j, i) + '\\"'; j = i + 1; break; |
michael@0 | 2798 | case "\\": res += s.substring(j, i) + "\\\\"; j = i + 1; break; |
michael@0 | 2799 | default: |
michael@0 | 2800 | var c = s.charAt(i); |
michael@0 | 2801 | if ("\a" !== "a" && c == "\a") { |
michael@0 | 2802 | res += s.substring(j, i) + "\\a"; j = i + 1; continue; |
michael@0 | 2803 | } |
michael@0 | 2804 | if ("\v" !== "v" && c == "\v") { |
michael@0 | 2805 | res += s.substring(j, i) + "\\v"; j = i + 1; continue; |
michael@0 | 2806 | } |
michael@0 | 2807 | //if (s.charAt(i) < ' ' || s.charCodeAt(i) > 127) { |
michael@0 | 2808 | // CARE: Manuel is this OK with HOP? |
michael@0 | 2809 | if (s.charAt(i) < ' ') { |
michael@0 | 2810 | /* non printable character and special chars */ |
michael@0 | 2811 | res += s.substring(j, i) + "\\x" + s.charCodeAt(i).toString(16); |
michael@0 | 2812 | j = i + 1; |
michael@0 | 2813 | } |
michael@0 | 2814 | // else just let i increase... |
michael@0 | 2815 | } |
michael@0 | 2816 | } |
michael@0 | 2817 | res += s.substring(j, i); |
michael@0 | 2818 | return res; |
michael@0 | 2819 | } |
michael@0 | 2820 | |
michael@0 | 2821 | /* ------------------ display ---------------------------------------------------*/ |
michael@0 | 2822 | |
michael@0 | 2823 | /*** META ((export #t)) */ |
michael@0 | 2824 | function sc_display(o, p) { |
michael@0 | 2825 | if (p === undefined) // we assume not given |
michael@0 | 2826 | p = SC_DEFAULT_OUT; |
michael@0 | 2827 | p.appendJSString(sc_toDisplayString(o)); |
michael@0 | 2828 | } |
michael@0 | 2829 | |
michael@0 | 2830 | function sc_toDisplayString(o) { |
michael@0 | 2831 | if (o === null) |
michael@0 | 2832 | return "()"; |
michael@0 | 2833 | else if (o === true) |
michael@0 | 2834 | return "#t"; |
michael@0 | 2835 | else if (o === false) |
michael@0 | 2836 | return "#f"; |
michael@0 | 2837 | else if (o === undefined) |
michael@0 | 2838 | return "#unspecified"; |
michael@0 | 2839 | else if (typeof o === 'function') |
michael@0 | 2840 | return "#<procedure " + sc_hash(o) + ">"; |
michael@0 | 2841 | else if (o.sc_toDisplayString) |
michael@0 | 2842 | return o.sc_toDisplayString(); |
michael@0 | 2843 | else |
michael@0 | 2844 | return o.toString(); |
michael@0 | 2845 | } |
michael@0 | 2846 | |
michael@0 | 2847 | /* ------------------ newline ---------------------------------------------------*/ |
michael@0 | 2848 | |
michael@0 | 2849 | /*** META ((export #t)) */ |
michael@0 | 2850 | function sc_newline(p) { |
michael@0 | 2851 | if (p === undefined) // we assume not given |
michael@0 | 2852 | p = SC_DEFAULT_OUT; |
michael@0 | 2853 | p.appendJSString("\n"); |
michael@0 | 2854 | } |
michael@0 | 2855 | |
michael@0 | 2856 | /* ------------------ write-char ---------------------------------------------------*/ |
michael@0 | 2857 | |
michael@0 | 2858 | /*** META ((export #t)) */ |
michael@0 | 2859 | function sc_writeChar(c, p) { |
michael@0 | 2860 | if (p === undefined) // we assume not given |
michael@0 | 2861 | p = SC_DEFAULT_OUT; |
michael@0 | 2862 | p.appendJSString(c.val); |
michael@0 | 2863 | } |
michael@0 | 2864 | |
michael@0 | 2865 | /* ------------------ write-circle ---------------------------------------------------*/ |
michael@0 | 2866 | |
michael@0 | 2867 | /*** META ((export #t)) */ |
michael@0 | 2868 | function sc_writeCircle(o, p) { |
michael@0 | 2869 | if (p === undefined) // we assume not given |
michael@0 | 2870 | p = SC_DEFAULT_OUT; |
michael@0 | 2871 | p.appendJSString(sc_toWriteCircleString(o)); |
michael@0 | 2872 | } |
michael@0 | 2873 | |
michael@0 | 2874 | function sc_toWriteCircleString(o) { |
michael@0 | 2875 | var symb = sc_gensym("writeCircle"); |
michael@0 | 2876 | var nbPointer = new Object(); |
michael@0 | 2877 | nbPointer.nb = 0; |
michael@0 | 2878 | sc_prepWriteCircle(o, symb, nbPointer); |
michael@0 | 2879 | return sc_genToWriteCircleString(o, symb); |
michael@0 | 2880 | } |
michael@0 | 2881 | |
michael@0 | 2882 | function sc_prepWriteCircle(o, symb, nbPointer) { |
michael@0 | 2883 | // TODO sc_Struct |
michael@0 | 2884 | if (o instanceof sc_Pair || |
michael@0 | 2885 | o instanceof sc_Vector) { |
michael@0 | 2886 | if (o[symb] !== undefined) { |
michael@0 | 2887 | // not the first visit. |
michael@0 | 2888 | o[symb]++; |
michael@0 | 2889 | // unless there is already a number, assign one. |
michael@0 | 2890 | if (!o[symb + "nb"]) o[symb + "nb"] = nbPointer.nb++; |
michael@0 | 2891 | return; |
michael@0 | 2892 | } |
michael@0 | 2893 | o[symb] = 0; |
michael@0 | 2894 | if (o instanceof sc_Pair) { |
michael@0 | 2895 | sc_prepWriteCircle(o.car, symb, nbPointer); |
michael@0 | 2896 | sc_prepWriteCircle(o.cdr, symb, nbPointer); |
michael@0 | 2897 | } else { |
michael@0 | 2898 | for (var i = 0; i < o.length; i++) |
michael@0 | 2899 | sc_prepWriteCircle(o[i], symb, nbPointer); |
michael@0 | 2900 | } |
michael@0 | 2901 | } |
michael@0 | 2902 | } |
michael@0 | 2903 | |
michael@0 | 2904 | function sc_genToWriteCircleString(o, symb) { |
michael@0 | 2905 | if (!(o instanceof sc_Pair || |
michael@0 | 2906 | o instanceof sc_Vector)) |
michael@0 | 2907 | return sc_toWriteString(o); |
michael@0 | 2908 | return o.sc_toWriteCircleString(symb); |
michael@0 | 2909 | } |
michael@0 | 2910 | sc_Pair.prototype.sc_toWriteCircleString = function(symb, inList) { |
michael@0 | 2911 | if (this[symb + "use"]) { // use-flag is set. Just use it. |
michael@0 | 2912 | var nb = this[symb + "nb"]; |
michael@0 | 2913 | if (this[symb]-- === 0) { // if we are the last use. remove all fields. |
michael@0 | 2914 | delete this[symb]; |
michael@0 | 2915 | delete this[symb + "nb"]; |
michael@0 | 2916 | delete this[symb + "use"]; |
michael@0 | 2917 | } |
michael@0 | 2918 | if (inList) |
michael@0 | 2919 | return '. #' + nb + '#'; |
michael@0 | 2920 | else |
michael@0 | 2921 | return '#' + nb + '#'; |
michael@0 | 2922 | } |
michael@0 | 2923 | if (this[symb]-- === 0) { // if we are the last use. remove all fields. |
michael@0 | 2924 | delete this[symb]; |
michael@0 | 2925 | delete this[symb + "nb"]; |
michael@0 | 2926 | delete this[symb + "use"]; |
michael@0 | 2927 | } |
michael@0 | 2928 | |
michael@0 | 2929 | var res = ""; |
michael@0 | 2930 | |
michael@0 | 2931 | if (this[symb] !== undefined) { // implies > 0 |
michael@0 | 2932 | this[symb + "use"] = true; |
michael@0 | 2933 | if (inList) |
michael@0 | 2934 | res += '. #' + this[symb + "nb"] + '='; |
michael@0 | 2935 | else |
michael@0 | 2936 | res += '#' + this[symb + "nb"] + '='; |
michael@0 | 2937 | inList = false; |
michael@0 | 2938 | } |
michael@0 | 2939 | |
michael@0 | 2940 | if (!inList) |
michael@0 | 2941 | res += "("; |
michael@0 | 2942 | |
michael@0 | 2943 | // print car |
michael@0 | 2944 | res += sc_genToWriteCircleString(this.car, symb); |
michael@0 | 2945 | |
michael@0 | 2946 | if (sc_isPair(this.cdr)) { |
michael@0 | 2947 | res += " " + this.cdr.sc_toWriteCircleString(symb, true); |
michael@0 | 2948 | } else if (this.cdr !== null) { |
michael@0 | 2949 | res += " . " + sc_genToWriteCircleString(this.cdr, symb); |
michael@0 | 2950 | } |
michael@0 | 2951 | if (!inList) |
michael@0 | 2952 | res += ")"; |
michael@0 | 2953 | return res; |
michael@0 | 2954 | }; |
michael@0 | 2955 | sc_Vector.prototype.sc_toWriteCircleString = function(symb) { |
michael@0 | 2956 | if (this[symb + "use"]) { // use-flag is set. Just use it. |
michael@0 | 2957 | var nb = this[symb + "nb"]; |
michael@0 | 2958 | if (this[symb]-- === 0) { // if we are the last use. remove all fields. |
michael@0 | 2959 | delete this[symb]; |
michael@0 | 2960 | delete this[symb + "nb"]; |
michael@0 | 2961 | delete this[symb + "use"]; |
michael@0 | 2962 | } |
michael@0 | 2963 | return '#' + nb + '#'; |
michael@0 | 2964 | } |
michael@0 | 2965 | if (this[symb]-- === 0) { // if we are the last use. remove all fields. |
michael@0 | 2966 | delete this[symb]; |
michael@0 | 2967 | delete this[symb + "nb"]; |
michael@0 | 2968 | delete this[symb + "use"]; |
michael@0 | 2969 | } |
michael@0 | 2970 | |
michael@0 | 2971 | var res = ""; |
michael@0 | 2972 | if (this[symb] !== undefined) { // implies > 0 |
michael@0 | 2973 | this[symb + "use"] = true; |
michael@0 | 2974 | res += '#' + this[symb + "nb"] + '='; |
michael@0 | 2975 | } |
michael@0 | 2976 | res += "#("; |
michael@0 | 2977 | for (var i = 0; i < this.length; i++) { |
michael@0 | 2978 | res += sc_genToWriteCircleString(this[i], symb); |
michael@0 | 2979 | if (i < this.length - 1) res += " "; |
michael@0 | 2980 | } |
michael@0 | 2981 | res += ")"; |
michael@0 | 2982 | return res; |
michael@0 | 2983 | }; |
michael@0 | 2984 | |
michael@0 | 2985 | |
michael@0 | 2986 | /* ------------------ print ---------------------------------------------------*/ |
michael@0 | 2987 | |
michael@0 | 2988 | /*** META ((export #t)) */ |
michael@0 | 2989 | function sc_print(s) { |
michael@0 | 2990 | if (arguments.length === 1) { |
michael@0 | 2991 | sc_display(s); |
michael@0 | 2992 | sc_newline(); |
michael@0 | 2993 | } |
michael@0 | 2994 | else { |
michael@0 | 2995 | for (var i = 0; i < arguments.length; i++) |
michael@0 | 2996 | sc_display(arguments[i]); |
michael@0 | 2997 | sc_newline(); |
michael@0 | 2998 | } |
michael@0 | 2999 | } |
michael@0 | 3000 | |
michael@0 | 3001 | /* ------------------ format ---------------------------------------------------*/ |
michael@0 | 3002 | /*** META ((export #t)) */ |
michael@0 | 3003 | function sc_format(s, args) { |
michael@0 | 3004 | var len = s.length; |
michael@0 | 3005 | var p = new sc_StringOutputPort(); |
michael@0 | 3006 | var i = 0, j = 1; |
michael@0 | 3007 | |
michael@0 | 3008 | while( i < len ) { |
michael@0 | 3009 | var i2 = s.indexOf("~", i); |
michael@0 | 3010 | |
michael@0 | 3011 | if (i2 == -1) { |
michael@0 | 3012 | p.appendJSString( s.substring( i, len ) ); |
michael@0 | 3013 | return p.close(); |
michael@0 | 3014 | } else { |
michael@0 | 3015 | if (i2 > i) { |
michael@0 | 3016 | if (i2 == (len - 1)) { |
michael@0 | 3017 | p.appendJSString(s.substring(i, len)); |
michael@0 | 3018 | return p.close(); |
michael@0 | 3019 | } else { |
michael@0 | 3020 | p.appendJSString(s.substring(i, i2)); |
michael@0 | 3021 | i = i2; |
michael@0 | 3022 | } |
michael@0 | 3023 | } |
michael@0 | 3024 | |
michael@0 | 3025 | switch(s.charCodeAt(i2 + 1)) { |
michael@0 | 3026 | case 65: |
michael@0 | 3027 | case 97: |
michael@0 | 3028 | // a |
michael@0 | 3029 | sc_display(arguments[j], p); |
michael@0 | 3030 | i += 2; j++; |
michael@0 | 3031 | break; |
michael@0 | 3032 | |
michael@0 | 3033 | case 83: |
michael@0 | 3034 | case 115: |
michael@0 | 3035 | // s |
michael@0 | 3036 | sc_write(arguments[j], p); |
michael@0 | 3037 | i += 2; j++; |
michael@0 | 3038 | break; |
michael@0 | 3039 | |
michael@0 | 3040 | case 86: |
michael@0 | 3041 | case 118: |
michael@0 | 3042 | // v |
michael@0 | 3043 | sc_display(arguments[j], p); |
michael@0 | 3044 | p.appendJSString("\n"); |
michael@0 | 3045 | i += 2; j++; |
michael@0 | 3046 | break; |
michael@0 | 3047 | |
michael@0 | 3048 | case 67: |
michael@0 | 3049 | case 99: |
michael@0 | 3050 | // c |
michael@0 | 3051 | p.appendJSString(String.fromCharCode(arguments[j])); |
michael@0 | 3052 | i += 2; j++; |
michael@0 | 3053 | break; |
michael@0 | 3054 | |
michael@0 | 3055 | case 88: |
michael@0 | 3056 | case 120: |
michael@0 | 3057 | // x |
michael@0 | 3058 | p.appendJSString(arguments[j].toString(6)); |
michael@0 | 3059 | i += 2; j++; |
michael@0 | 3060 | break; |
michael@0 | 3061 | |
michael@0 | 3062 | case 79: |
michael@0 | 3063 | case 111: |
michael@0 | 3064 | // o |
michael@0 | 3065 | p.appendJSString(arguments[j].toString(8)); |
michael@0 | 3066 | i += 2; j++; |
michael@0 | 3067 | break; |
michael@0 | 3068 | |
michael@0 | 3069 | case 66: |
michael@0 | 3070 | case 98: |
michael@0 | 3071 | // b |
michael@0 | 3072 | p.appendJSString(arguments[j].toString(2)); |
michael@0 | 3073 | i += 2; j++; |
michael@0 | 3074 | break; |
michael@0 | 3075 | |
michael@0 | 3076 | case 37: |
michael@0 | 3077 | case 110: |
michael@0 | 3078 | // %, n |
michael@0 | 3079 | p.appendJSString("\n"); |
michael@0 | 3080 | i += 2; break; |
michael@0 | 3081 | |
michael@0 | 3082 | case 114: |
michael@0 | 3083 | // r |
michael@0 | 3084 | p.appendJSString("\r"); |
michael@0 | 3085 | i += 2; break; |
michael@0 | 3086 | |
michael@0 | 3087 | case 126: |
michael@0 | 3088 | // ~ |
michael@0 | 3089 | p.appendJSString("~"); |
michael@0 | 3090 | i += 2; break; |
michael@0 | 3091 | |
michael@0 | 3092 | default: |
michael@0 | 3093 | sc_error( "format: illegal ~" |
michael@0 | 3094 | + String.fromCharCode(s.charCodeAt(i2 + 1)) |
michael@0 | 3095 | + " sequence" ); |
michael@0 | 3096 | return ""; |
michael@0 | 3097 | } |
michael@0 | 3098 | } |
michael@0 | 3099 | } |
michael@0 | 3100 | |
michael@0 | 3101 | return p.close(); |
michael@0 | 3102 | } |
michael@0 | 3103 | |
michael@0 | 3104 | /* ------------------ global ports ---------------------------------------------------*/ |
michael@0 | 3105 | |
michael@0 | 3106 | var SC_DEFAULT_IN = new sc_ErrorInputPort(); |
michael@0 | 3107 | var SC_DEFAULT_OUT = new sc_ErrorOutputPort(); |
michael@0 | 3108 | var SC_ERROR_OUT = new sc_ErrorOutputPort(); |
michael@0 | 3109 | |
michael@0 | 3110 | var sc_SYMBOL_PREFIX = "\u1E9C"; |
michael@0 | 3111 | var sc_KEYWORD_PREFIX = "\u1E9D"; |
michael@0 | 3112 | |
michael@0 | 3113 | /*** META ((export #t) |
michael@0 | 3114 | (peephole (id))) */ |
michael@0 | 3115 | function sc_jsstring2string(s) { |
michael@0 | 3116 | return s; |
michael@0 | 3117 | } |
michael@0 | 3118 | |
michael@0 | 3119 | /*** META ((export #t) |
michael@0 | 3120 | (peephole (prefix "'\\u1E9C' +"))) |
michael@0 | 3121 | */ |
michael@0 | 3122 | function sc_jsstring2symbol(s) { |
michael@0 | 3123 | return sc_SYMBOL_PREFIX + s; |
michael@0 | 3124 | } |
michael@0 | 3125 | |
michael@0 | 3126 | /*** META ((export #t) |
michael@0 | 3127 | (peephole (id))) |
michael@0 | 3128 | */ |
michael@0 | 3129 | function sc_string2jsstring(s) { |
michael@0 | 3130 | return s; |
michael@0 | 3131 | } |
michael@0 | 3132 | |
michael@0 | 3133 | /*** META ((export #t) |
michael@0 | 3134 | (peephole (symbol2jsstring_immutable))) |
michael@0 | 3135 | */ |
michael@0 | 3136 | function sc_symbol2jsstring(s) { |
michael@0 | 3137 | return s.slice(1); |
michael@0 | 3138 | } |
michael@0 | 3139 | |
michael@0 | 3140 | /*** META ((export #t) |
michael@0 | 3141 | (peephole (postfix ".slice(1)"))) |
michael@0 | 3142 | */ |
michael@0 | 3143 | function sc_keyword2jsstring(k) { |
michael@0 | 3144 | return k.slice(1); |
michael@0 | 3145 | } |
michael@0 | 3146 | |
michael@0 | 3147 | /*** META ((export #t) |
michael@0 | 3148 | (peephole (prefix "'\\u1E9D' +"))) |
michael@0 | 3149 | */ |
michael@0 | 3150 | function sc_jsstring2keyword(s) { |
michael@0 | 3151 | return sc_KEYWORD_PREFIX + s; |
michael@0 | 3152 | } |
michael@0 | 3153 | |
michael@0 | 3154 | /*** META ((export #t) |
michael@0 | 3155 | (type bool)) |
michael@0 | 3156 | */ |
michael@0 | 3157 | function sc_isKeyword(s) { |
michael@0 | 3158 | return (typeof s === "string") && |
michael@0 | 3159 | (s.charAt(0) === sc_KEYWORD_PREFIX); |
michael@0 | 3160 | } |
michael@0 | 3161 | |
michael@0 | 3162 | |
michael@0 | 3163 | /*** META ((export #t)) */ |
michael@0 | 3164 | var sc_gensym = function() { |
michael@0 | 3165 | var counter = 1000; |
michael@0 | 3166 | return function(sym) { |
michael@0 | 3167 | counter++; |
michael@0 | 3168 | if (!sym) sym = sc_SYMBOL_PREFIX; |
michael@0 | 3169 | return sym + "s" + counter + "~" + "^sC-GeNsYm "; |
michael@0 | 3170 | }; |
michael@0 | 3171 | }(); |
michael@0 | 3172 | |
michael@0 | 3173 | |
michael@0 | 3174 | /*** META ((export #t) |
michael@0 | 3175 | (type bool)) |
michael@0 | 3176 | */ |
michael@0 | 3177 | function sc_isEqual(o1, o2) { |
michael@0 | 3178 | return ((o1 === o2) || |
michael@0 | 3179 | (sc_isPair(o1) && sc_isPair(o2) |
michael@0 | 3180 | && sc_isPairEqual(o1, o2, sc_isEqual)) || |
michael@0 | 3181 | (sc_isVector(o1) && sc_isVector(o2) |
michael@0 | 3182 | && sc_isVectorEqual(o1, o2, sc_isEqual))); |
michael@0 | 3183 | } |
michael@0 | 3184 | |
michael@0 | 3185 | /*** META ((export number->symbol integer->symbol)) */ |
michael@0 | 3186 | function sc_number2symbol(x, radix) { |
michael@0 | 3187 | return sc_SYMBOL_PREFIX + sc_number2jsstring(x, radix); |
michael@0 | 3188 | } |
michael@0 | 3189 | |
michael@0 | 3190 | /*** META ((export number->string integer->string)) */ |
michael@0 | 3191 | var sc_number2string = sc_number2jsstring; |
michael@0 | 3192 | |
michael@0 | 3193 | /*** META ((export #t)) */ |
michael@0 | 3194 | function sc_symbol2number(s, radix) { |
michael@0 | 3195 | return sc_jsstring2number(s.slice(1), radix); |
michael@0 | 3196 | } |
michael@0 | 3197 | |
michael@0 | 3198 | /*** META ((export #t)) */ |
michael@0 | 3199 | var sc_string2number = sc_jsstring2number; |
michael@0 | 3200 | |
michael@0 | 3201 | /*** META ((export #t) |
michael@0 | 3202 | (peephole (prefix "+" s))) |
michael@0 | 3203 | ;; peephole will only apply if no radix is given. |
michael@0 | 3204 | */ |
michael@0 | 3205 | function sc_string2integer(s, radix) { |
michael@0 | 3206 | if (!radix) return +s; |
michael@0 | 3207 | return parseInt(s, radix); |
michael@0 | 3208 | } |
michael@0 | 3209 | |
michael@0 | 3210 | /*** META ((export #t) |
michael@0 | 3211 | (peephole (prefix "+"))) |
michael@0 | 3212 | */ |
michael@0 | 3213 | function sc_string2real(s) { |
michael@0 | 3214 | return +s; |
michael@0 | 3215 | } |
michael@0 | 3216 | |
michael@0 | 3217 | |
michael@0 | 3218 | /*** META ((export #t) |
michael@0 | 3219 | (type bool)) |
michael@0 | 3220 | */ |
michael@0 | 3221 | function sc_isSymbol(s) { |
michael@0 | 3222 | return (typeof s === "string") && |
michael@0 | 3223 | (s.charAt(0) === sc_SYMBOL_PREFIX); |
michael@0 | 3224 | } |
michael@0 | 3225 | |
michael@0 | 3226 | /*** META ((export #t) |
michael@0 | 3227 | (peephole (symbol2string_immutable))) |
michael@0 | 3228 | */ |
michael@0 | 3229 | function sc_symbol2string(s) { |
michael@0 | 3230 | return s.slice(1); |
michael@0 | 3231 | } |
michael@0 | 3232 | |
michael@0 | 3233 | /*** META ((export #t) |
michael@0 | 3234 | (peephole (prefix "'\\u1E9C' +"))) |
michael@0 | 3235 | */ |
michael@0 | 3236 | function sc_string2symbol(s) { |
michael@0 | 3237 | return sc_SYMBOL_PREFIX + s; |
michael@0 | 3238 | } |
michael@0 | 3239 | |
michael@0 | 3240 | /*** META ((export symbol-append) |
michael@0 | 3241 | (peephole (symbolAppend_immutable))) |
michael@0 | 3242 | */ |
michael@0 | 3243 | function sc_symbolAppend() { |
michael@0 | 3244 | var res = sc_SYMBOL_PREFIX; |
michael@0 | 3245 | for (var i = 0; i < arguments.length; i++) |
michael@0 | 3246 | res += arguments[i].slice(1); |
michael@0 | 3247 | return res; |
michael@0 | 3248 | } |
michael@0 | 3249 | |
michael@0 | 3250 | /*** META ((export #t) |
michael@0 | 3251 | (peephole (postfix ".val"))) |
michael@0 | 3252 | */ |
michael@0 | 3253 | function sc_char2string(c) { return c.val; } |
michael@0 | 3254 | |
michael@0 | 3255 | /*** META ((export #t) |
michael@0 | 3256 | (peephole (hole 1 "'\\u1E9C' + " c ".val"))) |
michael@0 | 3257 | */ |
michael@0 | 3258 | function sc_char2symbol(c) { return sc_SYMBOL_PREFIX + c.val; } |
michael@0 | 3259 | |
michael@0 | 3260 | /*** META ((export #t) |
michael@0 | 3261 | (type bool)) |
michael@0 | 3262 | */ |
michael@0 | 3263 | function sc_isString(s) { |
michael@0 | 3264 | return (typeof s === "string") && |
michael@0 | 3265 | (s.charAt(0) !== sc_SYMBOL_PREFIX); |
michael@0 | 3266 | } |
michael@0 | 3267 | |
michael@0 | 3268 | /*** META ((export #t)) */ |
michael@0 | 3269 | var sc_makeString = sc_makejsString; |
michael@0 | 3270 | |
michael@0 | 3271 | |
michael@0 | 3272 | /*** META ((export #t)) */ |
michael@0 | 3273 | function sc_string() { |
michael@0 | 3274 | for (var i = 0; i < arguments.length; i++) |
michael@0 | 3275 | arguments[i] = arguments[i].val; |
michael@0 | 3276 | return "".concat.apply("", arguments); |
michael@0 | 3277 | } |
michael@0 | 3278 | |
michael@0 | 3279 | /*** META ((export #t) |
michael@0 | 3280 | (peephole (postfix ".length"))) |
michael@0 | 3281 | */ |
michael@0 | 3282 | function sc_stringLength(s) { return s.length; } |
michael@0 | 3283 | |
michael@0 | 3284 | /*** META ((export #t)) */ |
michael@0 | 3285 | function sc_stringRef(s, k) { |
michael@0 | 3286 | return new sc_Char(s.charAt(k)); |
michael@0 | 3287 | } |
michael@0 | 3288 | |
michael@0 | 3289 | /* there's no stringSet in the immutable version |
michael@0 | 3290 | function sc_stringSet(s, k, c) |
michael@0 | 3291 | */ |
michael@0 | 3292 | |
michael@0 | 3293 | |
michael@0 | 3294 | /*** META ((export string=?) |
michael@0 | 3295 | (type bool) |
michael@0 | 3296 | (peephole (hole 2 str1 " === " str2))) |
michael@0 | 3297 | */ |
michael@0 | 3298 | function sc_isStringEqual(s1, s2) { |
michael@0 | 3299 | return s1 === s2; |
michael@0 | 3300 | } |
michael@0 | 3301 | /*** META ((export string<?) |
michael@0 | 3302 | (type bool) |
michael@0 | 3303 | (peephole (hole 2 str1 " < " str2))) |
michael@0 | 3304 | */ |
michael@0 | 3305 | function sc_isStringLess(s1, s2) { |
michael@0 | 3306 | return s1 < s2; |
michael@0 | 3307 | } |
michael@0 | 3308 | /*** META ((export string>?) |
michael@0 | 3309 | (type bool) |
michael@0 | 3310 | (peephole (hole 2 str1 " > " str2))) |
michael@0 | 3311 | */ |
michael@0 | 3312 | function sc_isStringGreater(s1, s2) { |
michael@0 | 3313 | return s1 > s2; |
michael@0 | 3314 | } |
michael@0 | 3315 | /*** META ((export string<=?) |
michael@0 | 3316 | (type bool) |
michael@0 | 3317 | (peephole (hole 2 str1 " <= " str2))) |
michael@0 | 3318 | */ |
michael@0 | 3319 | function sc_isStringLessEqual(s1, s2) { |
michael@0 | 3320 | return s1 <= s2; |
michael@0 | 3321 | } |
michael@0 | 3322 | /*** META ((export string>=?) |
michael@0 | 3323 | (type bool) |
michael@0 | 3324 | (peephole (hole 2 str1 " >= " str2))) |
michael@0 | 3325 | */ |
michael@0 | 3326 | function sc_isStringGreaterEqual(s1, s2) { |
michael@0 | 3327 | return s1 >= s2; |
michael@0 | 3328 | } |
michael@0 | 3329 | /*** META ((export string-ci=?) |
michael@0 | 3330 | (type bool) |
michael@0 | 3331 | (peephole (hole 2 str1 ".toLowerCase() === " str2 ".toLowerCase()"))) |
michael@0 | 3332 | */ |
michael@0 | 3333 | function sc_isStringCIEqual(s1, s2) { |
michael@0 | 3334 | return s1.toLowerCase() === s2.toLowerCase(); |
michael@0 | 3335 | } |
michael@0 | 3336 | /*** META ((export string-ci<?) |
michael@0 | 3337 | (type bool) |
michael@0 | 3338 | (peephole (hole 2 str1 ".toLowerCase() < " str2 ".toLowerCase()"))) |
michael@0 | 3339 | */ |
michael@0 | 3340 | function sc_isStringCILess(s1, s2) { |
michael@0 | 3341 | return s1.toLowerCase() < s2.toLowerCase(); |
michael@0 | 3342 | } |
michael@0 | 3343 | /*** META ((export string-ci>?) |
michael@0 | 3344 | (type bool) |
michael@0 | 3345 | (peephole (hole 2 str1 ".toLowerCase() > " str2 ".toLowerCase()"))) |
michael@0 | 3346 | */ |
michael@0 | 3347 | function sc_isStringCIGreater(s1, s2) { |
michael@0 | 3348 | return s1.toLowerCase() > s2.toLowerCase(); |
michael@0 | 3349 | } |
michael@0 | 3350 | /*** META ((export string-ci<=?) |
michael@0 | 3351 | (type bool) |
michael@0 | 3352 | (peephole (hole 2 str1 ".toLowerCase() <= " str2 ".toLowerCase()"))) |
michael@0 | 3353 | */ |
michael@0 | 3354 | function sc_isStringCILessEqual(s1, s2) { |
michael@0 | 3355 | return s1.toLowerCase() <= s2.toLowerCase(); |
michael@0 | 3356 | } |
michael@0 | 3357 | /*** META ((export string-ci>=?) |
michael@0 | 3358 | (type bool) |
michael@0 | 3359 | (peephole (hole 2 str1 ".toLowerCase() >= " str2 ".toLowerCase()"))) |
michael@0 | 3360 | */ |
michael@0 | 3361 | function sc_isStringCIGreaterEqual(s1, s2) { |
michael@0 | 3362 | return s1.toLowerCase() >= s2.toLowerCase(); |
michael@0 | 3363 | } |
michael@0 | 3364 | |
michael@0 | 3365 | /*** META ((export #t) |
michael@0 | 3366 | (peephole (hole 3 s ".substring(" start ", " end ")"))) |
michael@0 | 3367 | */ |
michael@0 | 3368 | function sc_substring(s, start, end) { |
michael@0 | 3369 | return s.substring(start, end); |
michael@0 | 3370 | } |
michael@0 | 3371 | |
michael@0 | 3372 | /*** META ((export #t)) |
michael@0 | 3373 | */ |
michael@0 | 3374 | function sc_isSubstring_at(s1, s2, i) { |
michael@0 | 3375 | return s2 == s1.substring(i, i+ s2.length); |
michael@0 | 3376 | } |
michael@0 | 3377 | |
michael@0 | 3378 | /*** META ((export #t) |
michael@0 | 3379 | (peephole (infix 0 #f "+" "''"))) |
michael@0 | 3380 | */ |
michael@0 | 3381 | function sc_stringAppend() { |
michael@0 | 3382 | return "".concat.apply("", arguments); |
michael@0 | 3383 | } |
michael@0 | 3384 | |
michael@0 | 3385 | /*** META ((export #t)) */ |
michael@0 | 3386 | var sc_string2list = sc_jsstring2list; |
michael@0 | 3387 | |
michael@0 | 3388 | /*** META ((export #t)) */ |
michael@0 | 3389 | var sc_list2string = sc_list2jsstring; |
michael@0 | 3390 | |
michael@0 | 3391 | /*** META ((export #t) |
michael@0 | 3392 | (peephole (id))) |
michael@0 | 3393 | */ |
michael@0 | 3394 | function sc_stringCopy(s) { |
michael@0 | 3395 | return s; |
michael@0 | 3396 | } |
michael@0 | 3397 | |
michael@0 | 3398 | /* there's no string-fill in the immutable version |
michael@0 | 3399 | function sc_stringFill(s, c) |
michael@0 | 3400 | */ |
michael@0 | 3401 | |
michael@0 | 3402 | /*** META ((export #t) |
michael@0 | 3403 | (peephole (postfix ".slice(1)"))) |
michael@0 | 3404 | */ |
michael@0 | 3405 | function sc_keyword2string(o) { |
michael@0 | 3406 | return o.slice(1); |
michael@0 | 3407 | } |
michael@0 | 3408 | |
michael@0 | 3409 | /*** META ((export #t) |
michael@0 | 3410 | (peephole (prefix "'\\u1E9D' +"))) |
michael@0 | 3411 | */ |
michael@0 | 3412 | function sc_string2keyword(o) { |
michael@0 | 3413 | return sc_KEYWORD_PREFIX + o; |
michael@0 | 3414 | } |
michael@0 | 3415 | |
michael@0 | 3416 | String.prototype.sc_toDisplayString = function() { |
michael@0 | 3417 | if (this.charAt(0) === sc_SYMBOL_PREFIX) |
michael@0 | 3418 | // TODO: care for symbols with spaces (escape-chars symbols). |
michael@0 | 3419 | return this.slice(1); |
michael@0 | 3420 | else if (this.charAt(0) === sc_KEYWORD_PREFIX) |
michael@0 | 3421 | return ":" + this.slice(1); |
michael@0 | 3422 | else |
michael@0 | 3423 | return this.toString(); |
michael@0 | 3424 | }; |
michael@0 | 3425 | |
michael@0 | 3426 | String.prototype.sc_toWriteString = function() { |
michael@0 | 3427 | if (this.charAt(0) === sc_SYMBOL_PREFIX) |
michael@0 | 3428 | // TODO: care for symbols with spaces (escape-chars symbols). |
michael@0 | 3429 | return this.slice(1); |
michael@0 | 3430 | else if (this.charAt(0) === sc_KEYWORD_PREFIX) |
michael@0 | 3431 | return ":" + this.slice(1); |
michael@0 | 3432 | else |
michael@0 | 3433 | return '"' + sc_escapeWriteString(this) + '"'; |
michael@0 | 3434 | }; |
michael@0 | 3435 | /* Exported Variables */ |
michael@0 | 3436 | var BgL_testzd2boyerzd2; |
michael@0 | 3437 | var BgL_nboyerzd2benchmarkzd2; |
michael@0 | 3438 | var BgL_setupzd2boyerzd2; |
michael@0 | 3439 | /* End Exports */ |
michael@0 | 3440 | |
michael@0 | 3441 | var translate_term_nboyer; |
michael@0 | 3442 | var translate_args_nboyer; |
michael@0 | 3443 | var untranslate_term_nboyer; |
michael@0 | 3444 | var BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer; |
michael@0 | 3445 | var BgL_sc_za2symbolzd2recordszd2alistza2_2z00_nboyer; |
michael@0 | 3446 | var translate_alist_nboyer; |
michael@0 | 3447 | var apply_subst_nboyer; |
michael@0 | 3448 | var apply_subst_lst_nboyer; |
michael@0 | 3449 | var tautologyp_nboyer; |
michael@0 | 3450 | var if_constructor_nboyer; |
michael@0 | 3451 | var rewrite_count_nboyer; |
michael@0 | 3452 | var rewrite_nboyer; |
michael@0 | 3453 | var rewrite_args_nboyer; |
michael@0 | 3454 | var unify_subst_nboyer; |
michael@0 | 3455 | var one_way_unify1_nboyer; |
michael@0 | 3456 | var false_term_nboyer; |
michael@0 | 3457 | var true_term_nboyer; |
michael@0 | 3458 | var trans_of_implies1_nboyer; |
michael@0 | 3459 | var is_term_equal_nboyer; |
michael@0 | 3460 | var is_term_member_nboyer; |
michael@0 | 3461 | var const_nboyer; |
michael@0 | 3462 | var sc_const_3_nboyer; |
michael@0 | 3463 | var sc_const_4_nboyer; |
michael@0 | 3464 | { |
michael@0 | 3465 | (sc_const_4_nboyer = (new sc_Pair("\u1E9Cimplies",(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cimplies",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cimplies",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cimplies",(new sc_Pair("\u1E9Cz",(new sc_Pair("\u1E9Cu",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cimplies",(new sc_Pair("\u1E9Cu",(new sc_Pair("\u1E9Cw",null)))))),null)))))),null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cimplies",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cw",null)))))),null))))))); |
michael@0 | 3466 | (sc_const_3_nboyer = sc_list((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ccompile",(new sc_Pair("\u1E9Cform",null)))),(new sc_Pair((new sc_Pair("\u1E9Creverse",(new sc_Pair((new sc_Pair("\u1E9Ccodegen",(new sc_Pair((new sc_Pair("\u1E9Coptimize",(new sc_Pair("\u1E9Cform",null)))),(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),null)))))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ceqp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cy",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cgreaterp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clesseqp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cgreatereqp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cboolean",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Ct",null)),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cf",null)),null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ciff",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cimplies",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cimplies",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ceven1",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Ct",null)),(new sc_Pair((new sc_Pair("\u1E9Codd",(new sc_Pair((new sc_Pair("\u1E9Csub1",(new sc_Pair("\u1E9Cx",null)))),null)))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ccountps-",(new sc_Pair("\u1E9Cl",(new sc_Pair("\u1E9Cpred",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ccountps-loop",(new sc_Pair("\u1E9Cl",(new sc_Pair("\u1E9Cpred",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cfact-",(new sc_Pair("\u1E9Ci",null)))),(new sc_Pair((new sc_Pair("\u1E9Cfact-loop",(new sc_Pair("\u1E9Ci",(new sc_Pair((1),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Creverse-",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Creverse-loop",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdivides",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair((new sc_Pair("\u1E9Cremainder",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cassume-true",(new sc_Pair("\u1E9Cvar",(new sc_Pair("\u1E9Calist",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair("\u1E9Cvar",(new sc_Pair((new sc_Pair("\u1E9Ct",null)),null)))))),(new sc_Pair("\u1E9Calist",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cassume-false",(new sc_Pair("\u1E9Cvar",(new sc_Pair("\u1E9Calist",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair("\u1E9Cvar",(new sc_Pair((new sc_Pair("\u1E9Cf",null)),null)))))),(new sc_Pair("\u1E9Calist",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ctautology-checker",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Ctautologyp",(new sc_Pair((new sc_Pair("\u1E9Cnormalize",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cfalsify",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cfalsify1",(new sc_Pair((new sc_Pair("\u1E9Cnormalize",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cprime",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cx",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))),null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cprime1",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Csub1",(new sc_Pair("\u1E9Cx",null)))),null)))))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair("\u1E9Cp",(new sc_Pair("\u1E9Cq",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Cp",(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Cq",(new sc_Pair((new sc_Pair("\u1E9Ct",null)),(new sc_Pair((new sc_Pair("\u1E9Cf",null)),null)))))))),(new sc_Pair((new sc_Pair("\u1E9Cf",null)),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair("\u1E9Cp",(new sc_Pair("\u1E9Cq",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Cp",(new sc_Pair((new sc_Pair("\u1E9Ct",null)),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Cq",(new sc_Pair((new sc_Pair("\u1E9Ct",null)),(new sc_Pair((new sc_Pair("\u1E9Cf",null)),null)))))))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair("\u1E9Cp",null)))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Cp",(new sc_Pair((new sc_Pair("\u1E9Cf",null)),(new sc_Pair((new sc_Pair("\u1E9Ct",null)),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cimplies",(new sc_Pair("\u1E9Cp",(new sc_Pair("\u1E9Cq",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Cp",(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Cq",(new sc_Pair((new sc_Pair("\u1E9Ct",null)),(new sc_Pair((new sc_Pair("\u1E9Cf",null)),null)))))))),(new sc_Pair((new sc_Pair("\u1E9Ct",null)),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",(new sc_Pair("\u1E9Cc",null)))))))),(new sc_Pair("\u1E9Cd",(new sc_Pair("\u1E9Ce",null)))))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Ca",(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Cb",(new sc_Pair("\u1E9Cd",(new sc_Pair("\u1E9Ce",null)))))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair("\u1E9Cc",(new sc_Pair("\u1E9Cd",(new sc_Pair("\u1E9Ce",null)))))))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Cx",null)))),null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Ca",null)))),(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cb",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cc",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cb",null)))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cc",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cy",null)))),null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cmeaning",(new sc_Pair((new sc_Pair("\u1E9Cplus-tree",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))),(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair((new sc_Pair("\u1E9Cmeaning",(new sc_Pair((new sc_Pair("\u1E9Cplus-tree",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cmeaning",(new sc_Pair((new sc_Pair("\u1E9Cplus-tree",(new sc_Pair("\u1E9Cy",null)))),(new sc_Pair("\u1E9Ca",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cmeaning",(new sc_Pair((new sc_Pair("\u1E9Cplus-tree",(new sc_Pair((new sc_Pair("\u1E9Cplus-fringe",(new sc_Pair("\u1E9Cx",null)))),null)))),(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair((new sc_Pair("\u1E9Cmeaning",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Ca",null)))))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Creverse",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair((new sc_Pair("\u1E9Creverse",(new sc_Pair("\u1E9Cb",null)))),(new sc_Pair((new sc_Pair("\u1E9Creverse",(new sc_Pair("\u1E9Ca",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cz",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cy",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cexec",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair("\u1E9Cpds",(new sc_Pair("\u1E9Cenvrn",null)))))))),(new sc_Pair((new sc_Pair("\u1E9Cexec",(new sc_Pair("\u1E9Cy",(new sc_Pair((new sc_Pair("\u1E9Cexec",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cpds",(new sc_Pair("\u1E9Cenvrn",null)))))))),(new sc_Pair("\u1E9Cenvrn",null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cmc-flatten",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair((new sc_Pair("\u1E9Cflatten",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair("\u1E9Cy",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cb",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Creverse",(new sc_Pair("\u1E9Cy",null)))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clength",(new sc_Pair((new sc_Pair("\u1E9Creverse",(new sc_Pair("\u1E9Cx",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Clength",(new sc_Pair("\u1E9Cx",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Ca",(new sc_Pair((new sc_Pair("\u1E9Cintersect",(new sc_Pair("\u1E9Cb",(new sc_Pair("\u1E9Cc",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cc",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cnth",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),(new sc_Pair("\u1E9Ci",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cexp",(new sc_Pair("\u1E9Ci",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cj",(new sc_Pair("\u1E9Ck",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair((new sc_Pair("\u1E9Cexp",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Cj",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cexp",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Ck",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cexp",(new sc_Pair("\u1E9Ci",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cj",(new sc_Pair("\u1E9Ck",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cexp",(new sc_Pair((new sc_Pair("\u1E9Cexp",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Cj",null)))))),(new sc_Pair("\u1E9Ck",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Creverse-loop",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair((new sc_Pair("\u1E9Creverse",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair("\u1E9Cy",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Creverse-loop",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),null)))))),(new sc_Pair((new sc_Pair("\u1E9Creverse",(new sc_Pair("\u1E9Cx",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ccount-list",(new sc_Pair("\u1E9Cz",(new sc_Pair((new sc_Pair("\u1E9Csort-lp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair((new sc_Pair("\u1E9Ccount-list",(new sc_Pair("\u1E9Cz",(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ccount-list",(new sc_Pair("\u1E9Cz",(new sc_Pair("\u1E9Cy",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cc",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cb",(new sc_Pair("\u1E9Cc",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair((new sc_Pair("\u1E9Cremainder",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cy",(new sc_Pair((new sc_Pair("\u1E9Cquotient",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cx",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cpower-eval",(new sc_Pair((new sc_Pair("\u1E9Cbig-plus1",(new sc_Pair("\u1E9Cl",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Cbase",null)))))))),(new sc_Pair("\u1E9Cbase",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair((new sc_Pair("\u1E9Cpower-eval",(new sc_Pair("\u1E9Cl",(new sc_Pair("\u1E9Cbase",null)))))),(new sc_Pair("\u1E9Ci",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cpower-eval",(new sc_Pair((new sc_Pair("\u1E9Cbig-plus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Cbase",null)))))))))),(new sc_Pair("\u1E9Cbase",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Ci",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair((new sc_Pair("\u1E9Cpower-eval",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cbase",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cpower-eval",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cbase",null)))))),null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cremainder",(new sc_Pair("\u1E9Cy",(new sc_Pair((1),null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair((new sc_Pair("\u1E9Cremainder",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cy",null)))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cremainder",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair((new sc_Pair("\u1E9Cquotient",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Cj",null)))))),(new sc_Pair("\u1E9Ci",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Ci",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cj",null)))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cj",(new sc_Pair((1),null)))))),null)))),null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair((new sc_Pair("\u1E9Cremainder",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cy",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cx",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cpower-eval",(new sc_Pair((new sc_Pair("\u1E9Cpower-rep",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Cbase",null)))))),(new sc_Pair("\u1E9Cbase",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Ci",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cpower-eval",(new sc_Pair((new sc_Pair("\u1E9Cbig-plus",(new sc_Pair((new sc_Pair("\u1E9Cpower-rep",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Cbase",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cpower-rep",(new sc_Pair("\u1E9Cj",(new sc_Pair("\u1E9Cbase",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),(new sc_Pair("\u1E9Cbase",null)))))))))),(new sc_Pair("\u1E9Cbase",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Cj",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cgcd",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cgcd",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cnth",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair("\u1E9Ci",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair((new sc_Pair("\u1E9Cnth",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Ci",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnth",(new sc_Pair("\u1E9Cb",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair("\u1E9Ci",(new sc_Pair((new sc_Pair("\u1E9Clength",(new sc_Pair("\u1E9Ca",null)))),null)))))),null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cy",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cy",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cz",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair("\u1E9Cc",(new sc_Pair("\u1E9Cw",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cc",(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cw",(new sc_Pair("\u1E9Cx",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cremainder",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cb",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cc",null)))))),null)))))),(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cb",(new sc_Pair("\u1E9Cc",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))),(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair("\u1E9Cy",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cz",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cz",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cy",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cx",null)))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cgcd",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cz",(new sc_Pair((new sc_Pair("\u1E9Cgcd",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cvalue",(new sc_Pair((new sc_Pair("\u1E9Cnormalize",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cvalue",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Ca",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cflatten",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair("\u1E9Cy",(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cnlistp",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clistp",(new sc_Pair((new sc_Pair("\u1E9Cgopher",(new sc_Pair("\u1E9Cx",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Clistp",(new sc_Pair("\u1E9Cx",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Csamefringe",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cflatten",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cflatten",(new sc_Pair("\u1E9Cy",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cgreatest-factor",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cy",null)))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cy",(new sc_Pair((1),null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cgreatest-factor",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((1),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((1),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cnumberp",(new sc_Pair((new sc_Pair("\u1E9Cgreatest-factor",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cy",null)))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cy",(new sc_Pair((1),null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Cx",null)))),null)))),null)))))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ctimes-list",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair((new sc_Pair("\u1E9Ctimes-list",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Ctimes-list",(new sc_Pair("\u1E9Cy",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cprime-list",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cprime-list",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cprime-list",(new sc_Pair("\u1E9Cy",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cz",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cw",(new sc_Pair("\u1E9Cz",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Cz",null)))),(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cz",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cw",(new sc_Pair((1),null)))))),null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cgreatereqp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cor",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cand",(new sc_Pair((new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cy",(new sc_Pair((1),null)))))),null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cremainder",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((1),null)))))),(new sc_Pair(sc_list("\u1E9Cand", (new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Ca",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),null)))), (new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair("\u1E9Cb",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),null)))), (new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Ca",null)))), (new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Cb",null)))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Csub1",(new sc_Pair("\u1E9Ca",null)))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Csub1",(new sc_Pair("\u1E9Cb",null)))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair((new sc_Pair("\u1E9Clength",(new sc_Pair((new sc_Pair("\u1E9Cdelete",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cl",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Clength",(new sc_Pair("\u1E9Cl",null)))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cl",null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Csort2",(new sc_Pair((new sc_Pair("\u1E9Cdelete",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cl",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cdelete",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Csort2",(new sc_Pair("\u1E9Cl",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdsort",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Csort2",(new sc_Pair("\u1E9Cx",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clength",(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair("\u1E9Cx1",(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair("\u1E9Cx2",(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair("\u1E9Cx3",(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair("\u1E9Cx4",(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair("\u1E9Cx5",(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair("\u1E9Cx6",(new sc_Pair("\u1E9Cx7",null)))))),null)))))),null)))))),null)))))),null)))))),null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair((6),(new sc_Pair((new sc_Pair("\u1E9Clength",(new sc_Pair("\u1E9Cx7",null)))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair("\u1E9Cx",null)))),null)))),(new sc_Pair((2),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cx",null)))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cquotient",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),(new sc_Pair((2),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cquotient",(new sc_Pair("\u1E9Cy",(new sc_Pair((2),null)))))),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Csigma",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),(new sc_Pair("\u1E9Ci",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cquotient",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Ci",(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair("\u1E9Ci",null)))),null)))))),(new sc_Pair((2),null)))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair("\u1E9Cy",null)))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Cy",null)))),(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair("\u1E9Cx",null)))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair("\u1E9Cz",(new sc_Pair("\u1E9Cy",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cz",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cz",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnot",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cz",null)))),null)))))),null)))))))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cmeaning",(new sc_Pair((new sc_Pair("\u1E9Cplus-tree",(new sc_Pair((new sc_Pair("\u1E9Cdelete",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))),(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair((new sc_Pair("\u1E9Cmeaning",(new sc_Pair((new sc_Pair("\u1E9Cplus-tree",(new sc_Pair("\u1E9Cy",null)))),(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cmeaning",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Ca",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cmeaning",(new sc_Pair((new sc_Pair("\u1E9Cplus-tree",(new sc_Pair("\u1E9Cy",null)))),(new sc_Pair("\u1E9Ca",null)))))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cadd1",(new sc_Pair("\u1E9Cy",null)))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Cnumberp",(new sc_Pair("\u1E9Cy",null)))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cx",null)))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cnth",(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),(new sc_Pair("\u1E9Ci",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Ci",null)))),(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clast",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Clistp",(new sc_Pair("\u1E9Cb",null)))),(new sc_Pair((new sc_Pair("\u1E9Clast",(new sc_Pair("\u1E9Cb",null)))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Clistp",(new sc_Pair("\u1E9Ca",null)))),(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair((new sc_Pair("\u1E9Ccar",(new sc_Pair((new sc_Pair("\u1E9Clast",(new sc_Pair("\u1E9Ca",null)))),null)))),(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair("\u1E9Cb",null)))))))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Clessp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ct",null)),(new sc_Pair("\u1E9Cz",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cf",null)),(new sc_Pair("\u1E9Cz",null)))))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cassignment",(new sc_Pair("\u1E9Cx",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Cassignedp",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cassignment",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Ca",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cassignment",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cb",null)))))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Ccar",(new sc_Pair((new sc_Pair("\u1E9Cgopher",(new sc_Pair("\u1E9Cx",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Clistp",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Ccar",(new sc_Pair((new sc_Pair("\u1E9Cflatten",(new sc_Pair("\u1E9Cx",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cflatten",(new sc_Pair((new sc_Pair("\u1E9Ccdr",(new sc_Pair((new sc_Pair("\u1E9Cgopher",(new sc_Pair("\u1E9Cx",null)))),null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Clistp",(new sc_Pair("\u1E9Cx",null)))),(new sc_Pair((new sc_Pair("\u1E9Ccdr",(new sc_Pair((new sc_Pair("\u1E9Cflatten",(new sc_Pair("\u1E9Cx",null)))),null)))),(new sc_Pair((new sc_Pair("\u1E9Ccons",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),null)))))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cquotient",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cx",null)))))),(new sc_Pair("\u1E9Cy",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Czerop",(new sc_Pair("\u1E9Cy",null)))),(new sc_Pair((new sc_Pair("\u1E9Czero",null)),(new sc_Pair((new sc_Pair("\u1E9Cfix",(new sc_Pair("\u1E9Cx",null)))),null)))))))),null)))))), (new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cget",(new sc_Pair("\u1E9Cj",(new sc_Pair((new sc_Pair("\u1E9Cset",(new sc_Pair("\u1E9Ci",(new sc_Pair("\u1E9Cval",(new sc_Pair("\u1E9Cmem",null)))))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cif",(new sc_Pair((new sc_Pair("\u1E9Ceqp",(new sc_Pair("\u1E9Cj",(new sc_Pair("\u1E9Ci",null)))))),(new sc_Pair("\u1E9Cval",(new sc_Pair((new sc_Pair("\u1E9Cget",(new sc_Pair("\u1E9Cj",(new sc_Pair("\u1E9Cmem",null)))))),null)))))))),null)))))))); |
michael@0 | 3467 | (const_nboyer = (new sc_Pair((new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cf",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cc",(new sc_Pair((new sc_Pair("\u1E9Czero",null)),null)))))),null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cy",(new sc_Pair("\u1E9Cf",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair((new sc_Pair("\u1E9Ctimes",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Cc",(new sc_Pair("\u1E9Cd",null)))))),null)))))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cz",(new sc_Pair("\u1E9Cf",(new sc_Pair((new sc_Pair("\u1E9Creverse",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair((new sc_Pair("\u1E9Cappend",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cnil",null)),null)))))),null)))),null)))))),(new sc_Pair((new sc_Pair("\u1E9Cu",(new sc_Pair("\u1E9Cequal",(new sc_Pair((new sc_Pair("\u1E9Cplus",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cdifference",(new sc_Pair("\u1E9Cx",(new sc_Pair("\u1E9Cy",null)))))),null)))))))),(new sc_Pair((new sc_Pair("\u1E9Cw",(new sc_Pair("\u1E9Clessp",(new sc_Pair((new sc_Pair("\u1E9Cremainder",(new sc_Pair("\u1E9Ca",(new sc_Pair("\u1E9Cb",null)))))),(new sc_Pair((new sc_Pair("\u1E9Cmember",(new sc_Pair("\u1E9Ca",(new sc_Pair((new sc_Pair("\u1E9Clength",(new sc_Pair("\u1E9Cb",null)))),null)))))),null)))))))),null))))))))))); |
michael@0 | 3468 | BgL_nboyerzd2benchmarkzd2 = function() { |
michael@0 | 3469 | var args = null; |
michael@0 | 3470 | for (var sc_tmp = arguments.length - 1; sc_tmp >= 0; sc_tmp--) { |
michael@0 | 3471 | args = sc_cons(arguments[sc_tmp], args); |
michael@0 | 3472 | } |
michael@0 | 3473 | var n; |
michael@0 | 3474 | return ((n = ((args === null)?(0):(args.car))), (BgL_setupzd2boyerzd2()), (BgL_runzd2benchmarkzd2(("nboyer"+(sc_number2string(n))), (1), function() { |
michael@0 | 3475 | return (BgL_testzd2boyerzd2(n)); |
michael@0 | 3476 | }, function(rewrites) { |
michael@0 | 3477 | if ((sc_isNumber(rewrites))) |
michael@0 | 3478 | switch (n) { |
michael@0 | 3479 | case (0): |
michael@0 | 3480 | return (rewrites===(95024)); |
michael@0 | 3481 | break; |
michael@0 | 3482 | case (1): |
michael@0 | 3483 | return (rewrites===(591777)); |
michael@0 | 3484 | break; |
michael@0 | 3485 | case (2): |
michael@0 | 3486 | return (rewrites===(1813975)); |
michael@0 | 3487 | break; |
michael@0 | 3488 | case (3): |
michael@0 | 3489 | return (rewrites===(5375678)); |
michael@0 | 3490 | break; |
michael@0 | 3491 | case (4): |
michael@0 | 3492 | return (rewrites===(16445406)); |
michael@0 | 3493 | break; |
michael@0 | 3494 | case (5): |
michael@0 | 3495 | return (rewrites===(51507739)); |
michael@0 | 3496 | break; |
michael@0 | 3497 | default: |
michael@0 | 3498 | return true; |
michael@0 | 3499 | break; |
michael@0 | 3500 | } |
michael@0 | 3501 | else |
michael@0 | 3502 | return false; |
michael@0 | 3503 | }))); |
michael@0 | 3504 | }; |
michael@0 | 3505 | BgL_setupzd2boyerzd2 = function() { |
michael@0 | 3506 | return true; |
michael@0 | 3507 | }; |
michael@0 | 3508 | BgL_testzd2boyerzd2 = function() { |
michael@0 | 3509 | return true; |
michael@0 | 3510 | }; |
michael@0 | 3511 | translate_term_nboyer = function(term) { |
michael@0 | 3512 | var lst; |
michael@0 | 3513 | return (!(term instanceof sc_Pair)?term:(new sc_Pair((BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer((term.car))), ((lst = (term.cdr)), ((lst === null)?null:(new sc_Pair((translate_term_nboyer((lst.car))), (translate_args_nboyer((lst.cdr)))))))))); |
michael@0 | 3514 | }; |
michael@0 | 3515 | translate_args_nboyer = function(lst) { |
michael@0 | 3516 | var sc_lst_5; |
michael@0 | 3517 | var term; |
michael@0 | 3518 | return ((lst === null)?null:(new sc_Pair(((term = (lst.car)), (!(term instanceof sc_Pair)?term:(new sc_Pair((BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer((term.car))), (translate_args_nboyer((term.cdr))))))), ((sc_lst_5 = (lst.cdr)), ((sc_lst_5 === null)?null:(new sc_Pair((translate_term_nboyer((sc_lst_5.car))), (translate_args_nboyer((sc_lst_5.cdr)))))))))); |
michael@0 | 3519 | }; |
michael@0 | 3520 | untranslate_term_nboyer = function(term) { |
michael@0 | 3521 | var optrOpnd; |
michael@0 | 3522 | var tail1131; |
michael@0 | 3523 | var L1127; |
michael@0 | 3524 | var falseHead1130; |
michael@0 | 3525 | var symbol_record; |
michael@0 | 3526 | if (!(term instanceof sc_Pair)) |
michael@0 | 3527 | return term; |
michael@0 | 3528 | else |
michael@0 | 3529 | { |
michael@0 | 3530 | (falseHead1130 = (new sc_Pair(null, null))); |
michael@0 | 3531 | (L1127 = (term.cdr)); |
michael@0 | 3532 | (tail1131 = falseHead1130); |
michael@0 | 3533 | while (!(L1127 === null)) { |
michael@0 | 3534 | { |
michael@0 | 3535 | (tail1131.cdr = (new sc_Pair((untranslate_term_nboyer((L1127.car))), null))); |
michael@0 | 3536 | (tail1131 = (tail1131.cdr)); |
michael@0 | 3537 | (L1127 = (L1127.cdr)); |
michael@0 | 3538 | } |
michael@0 | 3539 | } |
michael@0 | 3540 | (optrOpnd = (falseHead1130.cdr)); |
michael@0 | 3541 | return (new sc_Pair(((symbol_record = (term.car)), (symbol_record[(0)])), optrOpnd)); |
michael@0 | 3542 | } |
michael@0 | 3543 | }; |
michael@0 | 3544 | BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer = function(sym) { |
michael@0 | 3545 | var r; |
michael@0 | 3546 | var x; |
michael@0 | 3547 | return ((x = (sc_assq(sym, BgL_sc_za2symbolzd2recordszd2alistza2_2z00_nboyer))), ((x!== false)?(x.cdr):((r = [sym, null]), (BgL_sc_za2symbolzd2recordszd2alistza2_2z00_nboyer = (new sc_Pair((new sc_Pair(sym, r)), BgL_sc_za2symbolzd2recordszd2alistza2_2z00_nboyer))), r))); |
michael@0 | 3548 | }; |
michael@0 | 3549 | (BgL_sc_za2symbolzd2recordszd2alistza2_2z00_nboyer = null); |
michael@0 | 3550 | translate_alist_nboyer = function(alist) { |
michael@0 | 3551 | var sc_alist_6; |
michael@0 | 3552 | var term; |
michael@0 | 3553 | return ((alist === null)?null:(new sc_Pair((new sc_Pair((alist.car.car), ((term = (alist.car.cdr)), (!(term instanceof sc_Pair)?term:(new sc_Pair((BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer((term.car))), (translate_args_nboyer((term.cdr))))))))), ((sc_alist_6 = (alist.cdr)), ((sc_alist_6 === null)?null:(new sc_Pair((new sc_Pair((sc_alist_6.car.car), (translate_term_nboyer((sc_alist_6.car.cdr))))), (translate_alist_nboyer((sc_alist_6.cdr)))))))))); |
michael@0 | 3554 | }; |
michael@0 | 3555 | apply_subst_nboyer = function(alist, term) { |
michael@0 | 3556 | var lst; |
michael@0 | 3557 | var temp_temp; |
michael@0 | 3558 | return (!(term instanceof sc_Pair)?((temp_temp = (sc_assq(term, alist))), ((temp_temp!== false)?(temp_temp.cdr):term)):(new sc_Pair((term.car), ((lst = (term.cdr)), ((lst === null)?null:(new sc_Pair((apply_subst_nboyer(alist, (lst.car))), (apply_subst_lst_nboyer(alist, (lst.cdr)))))))))); |
michael@0 | 3559 | }; |
michael@0 | 3560 | apply_subst_lst_nboyer = function(alist, lst) { |
michael@0 | 3561 | var sc_lst_7; |
michael@0 | 3562 | return ((lst === null)?null:(new sc_Pair((apply_subst_nboyer(alist, (lst.car))), ((sc_lst_7 = (lst.cdr)), ((sc_lst_7 === null)?null:(new sc_Pair((apply_subst_nboyer(alist, (sc_lst_7.car))), (apply_subst_lst_nboyer(alist, (sc_lst_7.cdr)))))))))); |
michael@0 | 3563 | }; |
michael@0 | 3564 | tautologyp_nboyer = function(sc_x_11, true_lst, false_lst) { |
michael@0 | 3565 | var tmp1125; |
michael@0 | 3566 | var x; |
michael@0 | 3567 | var tmp1126; |
michael@0 | 3568 | var sc_x_8; |
michael@0 | 3569 | var sc_tmp1125_9; |
michael@0 | 3570 | var sc_tmp1126_10; |
michael@0 | 3571 | var sc_x_11; |
michael@0 | 3572 | var true_lst; |
michael@0 | 3573 | var false_lst; |
michael@0 | 3574 | while (true) { |
michael@0 | 3575 | if ((((sc_tmp1126_10 = (is_term_equal_nboyer(sc_x_11, true_term_nboyer))), ((sc_tmp1126_10!== false)?sc_tmp1126_10:(is_term_member_nboyer(sc_x_11, true_lst))))!== false)) |
michael@0 | 3576 | return true; |
michael@0 | 3577 | else |
michael@0 | 3578 | if ((((sc_tmp1125_9 = (is_term_equal_nboyer(sc_x_11, false_term_nboyer))), ((sc_tmp1125_9!== false)?sc_tmp1125_9:(is_term_member_nboyer(sc_x_11, false_lst))))!== false)) |
michael@0 | 3579 | return false; |
michael@0 | 3580 | else |
michael@0 | 3581 | if (!(sc_x_11 instanceof sc_Pair)) |
michael@0 | 3582 | return false; |
michael@0 | 3583 | else |
michael@0 | 3584 | if (((sc_x_11.car)===if_constructor_nboyer)) |
michael@0 | 3585 | if ((((sc_x_8 = (sc_x_11.cdr.car)), (tmp1126 = (is_term_equal_nboyer(sc_x_8, true_term_nboyer))), ((tmp1126!== false)?tmp1126:(is_term_member_nboyer(sc_x_8, true_lst))))!== false)) |
michael@0 | 3586 | (sc_x_11 = (sc_x_11.cdr.cdr.car)); |
michael@0 | 3587 | else |
michael@0 | 3588 | if ((((x = (sc_x_11.cdr.car)), (tmp1125 = (is_term_equal_nboyer(x, false_term_nboyer))), ((tmp1125!== false)?tmp1125:(is_term_member_nboyer(x, false_lst))))!== false)) |
michael@0 | 3589 | (sc_x_11 = (sc_x_11.cdr.cdr.cdr.car)); |
michael@0 | 3590 | else |
michael@0 | 3591 | if (((tautologyp_nboyer((sc_x_11.cdr.cdr.car), (new sc_Pair((sc_x_11.cdr.car), true_lst)), false_lst))!== false)) |
michael@0 | 3592 | { |
michael@0 | 3593 | (false_lst = (new sc_Pair((sc_x_11.cdr.car), false_lst))); |
michael@0 | 3594 | (sc_x_11 = (sc_x_11.cdr.cdr.cdr.car)); |
michael@0 | 3595 | } |
michael@0 | 3596 | else |
michael@0 | 3597 | return false; |
michael@0 | 3598 | else |
michael@0 | 3599 | return false; |
michael@0 | 3600 | } |
michael@0 | 3601 | }; |
michael@0 | 3602 | (if_constructor_nboyer = "\u1E9C*"); |
michael@0 | 3603 | (rewrite_count_nboyer = (0)); |
michael@0 | 3604 | rewrite_nboyer = function(term) { |
michael@0 | 3605 | var term2; |
michael@0 | 3606 | var sc_term_12; |
michael@0 | 3607 | var lst; |
michael@0 | 3608 | var symbol_record; |
michael@0 | 3609 | var sc_lst_13; |
michael@0 | 3610 | { |
michael@0 | 3611 | (++rewrite_count_nboyer); |
michael@0 | 3612 | if (!(term instanceof sc_Pair)) |
michael@0 | 3613 | return term; |
michael@0 | 3614 | else |
michael@0 | 3615 | { |
michael@0 | 3616 | (sc_term_12 = (new sc_Pair((term.car), ((sc_lst_13 = (term.cdr)), ((sc_lst_13 === null)?null:(new sc_Pair((rewrite_nboyer((sc_lst_13.car))), (rewrite_args_nboyer((sc_lst_13.cdr)))))))))); |
michael@0 | 3617 | (lst = ((symbol_record = (term.car)), (symbol_record[(1)]))); |
michael@0 | 3618 | while (true) { |
michael@0 | 3619 | if ((lst === null)) |
michael@0 | 3620 | return sc_term_12; |
michael@0 | 3621 | else |
michael@0 | 3622 | if ((((term2 = ((lst.car).cdr.car)), (unify_subst_nboyer = null), (one_way_unify1_nboyer(sc_term_12, term2)))!== false)) |
michael@0 | 3623 | return (rewrite_nboyer((apply_subst_nboyer(unify_subst_nboyer, ((lst.car).cdr.cdr.car))))); |
michael@0 | 3624 | else |
michael@0 | 3625 | (lst = (lst.cdr)); |
michael@0 | 3626 | } |
michael@0 | 3627 | } |
michael@0 | 3628 | } |
michael@0 | 3629 | }; |
michael@0 | 3630 | rewrite_args_nboyer = function(lst) { |
michael@0 | 3631 | var sc_lst_14; |
michael@0 | 3632 | return ((lst === null)?null:(new sc_Pair((rewrite_nboyer((lst.car))), ((sc_lst_14 = (lst.cdr)), ((sc_lst_14 === null)?null:(new sc_Pair((rewrite_nboyer((sc_lst_14.car))), (rewrite_args_nboyer((sc_lst_14.cdr)))))))))); |
michael@0 | 3633 | }; |
michael@0 | 3634 | (unify_subst_nboyer = "\u1E9C*"); |
michael@0 | 3635 | one_way_unify1_nboyer = function(term1, term2) { |
michael@0 | 3636 | var lst1; |
michael@0 | 3637 | var lst2; |
michael@0 | 3638 | var temp_temp; |
michael@0 | 3639 | if (!(term2 instanceof sc_Pair)) |
michael@0 | 3640 | { |
michael@0 | 3641 | (temp_temp = (sc_assq(term2, unify_subst_nboyer))); |
michael@0 | 3642 | if ((temp_temp!== false)) |
michael@0 | 3643 | return (is_term_equal_nboyer(term1, (temp_temp.cdr))); |
michael@0 | 3644 | else |
michael@0 | 3645 | if ((sc_isNumber(term2))) |
michael@0 | 3646 | return (sc_isEqual(term1, term2)); |
michael@0 | 3647 | else |
michael@0 | 3648 | { |
michael@0 | 3649 | (unify_subst_nboyer = (new sc_Pair((new sc_Pair(term2, term1)), unify_subst_nboyer))); |
michael@0 | 3650 | return true; |
michael@0 | 3651 | } |
michael@0 | 3652 | } |
michael@0 | 3653 | else |
michael@0 | 3654 | if (!(term1 instanceof sc_Pair)) |
michael@0 | 3655 | return false; |
michael@0 | 3656 | else |
michael@0 | 3657 | if (((term1.car)===(term2.car))) |
michael@0 | 3658 | { |
michael@0 | 3659 | (lst1 = (term1.cdr)); |
michael@0 | 3660 | (lst2 = (term2.cdr)); |
michael@0 | 3661 | while (true) { |
michael@0 | 3662 | if ((lst1 === null)) |
michael@0 | 3663 | return (lst2 === null); |
michael@0 | 3664 | else |
michael@0 | 3665 | if ((lst2 === null)) |
michael@0 | 3666 | return false; |
michael@0 | 3667 | else |
michael@0 | 3668 | if (((one_way_unify1_nboyer((lst1.car), (lst2.car)))!== false)) |
michael@0 | 3669 | { |
michael@0 | 3670 | (lst1 = (lst1.cdr)); |
michael@0 | 3671 | (lst2 = (lst2.cdr)); |
michael@0 | 3672 | } |
michael@0 | 3673 | else |
michael@0 | 3674 | return false; |
michael@0 | 3675 | } |
michael@0 | 3676 | } |
michael@0 | 3677 | else |
michael@0 | 3678 | return false; |
michael@0 | 3679 | }; |
michael@0 | 3680 | (false_term_nboyer = "\u1E9C*"); |
michael@0 | 3681 | (true_term_nboyer = "\u1E9C*"); |
michael@0 | 3682 | trans_of_implies1_nboyer = function(n) { |
michael@0 | 3683 | var sc_n_15; |
michael@0 | 3684 | return ((sc_isEqual(n, (1)))?(sc_list("\u1E9Cimplies", (0), (1))):(sc_list("\u1E9Cand", (sc_list("\u1E9Cimplies", (n-(1)), n)), ((sc_n_15 = (n-(1))), ((sc_isEqual(sc_n_15, (1)))?(sc_list("\u1E9Cimplies", (0), (1))):(sc_list("\u1E9Cand", (sc_list("\u1E9Cimplies", (sc_n_15-(1)), sc_n_15)), (trans_of_implies1_nboyer((sc_n_15-(1))))))))))); |
michael@0 | 3685 | }; |
michael@0 | 3686 | is_term_equal_nboyer = function(x, y) { |
michael@0 | 3687 | var lst1; |
michael@0 | 3688 | var lst2; |
michael@0 | 3689 | var r2; |
michael@0 | 3690 | var r1; |
michael@0 | 3691 | if ((x instanceof sc_Pair)) |
michael@0 | 3692 | if ((y instanceof sc_Pair)) |
michael@0 | 3693 | if ((((r1 = (x.car)), (r2 = (y.car)), (r1===r2))!== false)) |
michael@0 | 3694 | { |
michael@0 | 3695 | (lst1 = (x.cdr)); |
michael@0 | 3696 | (lst2 = (y.cdr)); |
michael@0 | 3697 | while (true) { |
michael@0 | 3698 | if ((lst1 === null)) |
michael@0 | 3699 | return (lst2 === null); |
michael@0 | 3700 | else |
michael@0 | 3701 | if ((lst2 === null)) |
michael@0 | 3702 | return false; |
michael@0 | 3703 | else |
michael@0 | 3704 | if (((is_term_equal_nboyer((lst1.car), (lst2.car)))!== false)) |
michael@0 | 3705 | { |
michael@0 | 3706 | (lst1 = (lst1.cdr)); |
michael@0 | 3707 | (lst2 = (lst2.cdr)); |
michael@0 | 3708 | } |
michael@0 | 3709 | else |
michael@0 | 3710 | return false; |
michael@0 | 3711 | } |
michael@0 | 3712 | } |
michael@0 | 3713 | else |
michael@0 | 3714 | return false; |
michael@0 | 3715 | else |
michael@0 | 3716 | return false; |
michael@0 | 3717 | else |
michael@0 | 3718 | return (sc_isEqual(x, y)); |
michael@0 | 3719 | }; |
michael@0 | 3720 | is_term_member_nboyer = function(x, lst) { |
michael@0 | 3721 | var x; |
michael@0 | 3722 | var lst; |
michael@0 | 3723 | while (true) { |
michael@0 | 3724 | if ((lst === null)) |
michael@0 | 3725 | return false; |
michael@0 | 3726 | else |
michael@0 | 3727 | if (((is_term_equal_nboyer(x, (lst.car)))!== false)) |
michael@0 | 3728 | return true; |
michael@0 | 3729 | else |
michael@0 | 3730 | (lst = (lst.cdr)); |
michael@0 | 3731 | } |
michael@0 | 3732 | }; |
michael@0 | 3733 | BgL_setupzd2boyerzd2 = function() { |
michael@0 | 3734 | var symbol_record; |
michael@0 | 3735 | var value; |
michael@0 | 3736 | var BgL_sc_symbolzd2record_16zd2; |
michael@0 | 3737 | var sym; |
michael@0 | 3738 | var sc_sym_17; |
michael@0 | 3739 | var term; |
michael@0 | 3740 | var lst; |
michael@0 | 3741 | var sc_term_18; |
michael@0 | 3742 | var sc_term_19; |
michael@0 | 3743 | { |
michael@0 | 3744 | (BgL_sc_za2symbolzd2recordszd2alistza2_2z00_nboyer = null); |
michael@0 | 3745 | (if_constructor_nboyer = (BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer("\u1E9Cif"))); |
michael@0 | 3746 | (false_term_nboyer = ((sc_term_19 = (new sc_Pair("\u1E9Cf",null))), (!(sc_term_19 instanceof sc_Pair)?sc_term_19:(new sc_Pair((BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer((sc_term_19.car))), (translate_args_nboyer((sc_term_19.cdr)))))))); |
michael@0 | 3747 | (true_term_nboyer = ((sc_term_18 = (new sc_Pair("\u1E9Ct",null))), (!(sc_term_18 instanceof sc_Pair)?sc_term_18:(new sc_Pair((BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer((sc_term_18.car))), (translate_args_nboyer((sc_term_18.cdr)))))))); |
michael@0 | 3748 | (lst = sc_const_3_nboyer); |
michael@0 | 3749 | while (!(lst === null)) { |
michael@0 | 3750 | { |
michael@0 | 3751 | (term = (lst.car)); |
michael@0 | 3752 | if (((term instanceof sc_Pair)&&(((term.car)==="\u1E9Cequal")&&((term.cdr.car) instanceof sc_Pair)))) |
michael@0 | 3753 | { |
michael@0 | 3754 | (sc_sym_17 = ((term.cdr.car).car)); |
michael@0 | 3755 | (value = (new sc_Pair((!(term instanceof sc_Pair)?term:(new sc_Pair((BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer((term.car))), (translate_args_nboyer((term.cdr)))))), ((sym = ((term.cdr.car).car)), (BgL_sc_symbolzd2record_16zd2 = (BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer(sym))), (BgL_sc_symbolzd2record_16zd2[(1)]))))); |
michael@0 | 3756 | (symbol_record = (BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer(sc_sym_17))); |
michael@0 | 3757 | (symbol_record[(1)] = value); |
michael@0 | 3758 | } |
michael@0 | 3759 | else |
michael@0 | 3760 | (sc_error("ADD-LEMMA did not like term: ", term)); |
michael@0 | 3761 | (lst = (lst.cdr)); |
michael@0 | 3762 | } |
michael@0 | 3763 | } |
michael@0 | 3764 | return true; |
michael@0 | 3765 | } |
michael@0 | 3766 | }; |
michael@0 | 3767 | BgL_testzd2boyerzd2 = function(n) { |
michael@0 | 3768 | var optrOpnd; |
michael@0 | 3769 | var term; |
michael@0 | 3770 | var sc_n_20; |
michael@0 | 3771 | var answer; |
michael@0 | 3772 | var sc_term_21; |
michael@0 | 3773 | var sc_term_22; |
michael@0 | 3774 | { |
michael@0 | 3775 | (rewrite_count_nboyer = (0)); |
michael@0 | 3776 | (term = sc_const_4_nboyer); |
michael@0 | 3777 | (sc_n_20 = n); |
michael@0 | 3778 | while (!(sc_n_20=== 0)) { |
michael@0 | 3779 | { |
michael@0 | 3780 | (term = (sc_list("\u1E9Cor", term, (new sc_Pair("\u1E9Cf",null))))); |
michael@0 | 3781 | (--sc_n_20); |
michael@0 | 3782 | } |
michael@0 | 3783 | } |
michael@0 | 3784 | (sc_term_22 = term); |
michael@0 | 3785 | if (!(sc_term_22 instanceof sc_Pair)) |
michael@0 | 3786 | (optrOpnd = sc_term_22); |
michael@0 | 3787 | else |
michael@0 | 3788 | (optrOpnd = (new sc_Pair((BgL_sc_symbolzd2ze3symbolzd2record_1ze3_nboyer((sc_term_22.car))), (translate_args_nboyer((sc_term_22.cdr)))))); |
michael@0 | 3789 | (sc_term_21 = (apply_subst_nboyer(((const_nboyer === null)?null:(new sc_Pair((new sc_Pair((const_nboyer.car.car), (translate_term_nboyer((const_nboyer.car.cdr))))), (translate_alist_nboyer((const_nboyer.cdr)))))), optrOpnd))); |
michael@0 | 3790 | (answer = (tautologyp_nboyer((rewrite_nboyer(sc_term_21)), null, null))); |
michael@0 | 3791 | (sc_write(rewrite_count_nboyer)); |
michael@0 | 3792 | (sc_display(" rewrites")); |
michael@0 | 3793 | (sc_newline()); |
michael@0 | 3794 | if ((answer!== false)) |
michael@0 | 3795 | return rewrite_count_nboyer; |
michael@0 | 3796 | else |
michael@0 | 3797 | return false; |
michael@0 | 3798 | } |
michael@0 | 3799 | }; |
michael@0 | 3800 | } |
michael@0 | 3801 | /* Exported Variables */ |
michael@0 | 3802 | var BgL_parsezd2ze3nbzd2treesze3; |
michael@0 | 3803 | var BgL_earleyzd2benchmarkzd2; |
michael@0 | 3804 | var BgL_parsezd2ze3parsedzf3zc2; |
michael@0 | 3805 | var test; |
michael@0 | 3806 | var BgL_parsezd2ze3treesz31; |
michael@0 | 3807 | var BgL_makezd2parserzd2; |
michael@0 | 3808 | /* End Exports */ |
michael@0 | 3809 | |
michael@0 | 3810 | var const_earley; |
michael@0 | 3811 | { |
michael@0 | 3812 | (const_earley = (new sc_Pair((new sc_Pair("\u1E9Cs",(new sc_Pair((new sc_Pair("\u1E9Ca",null)),(new sc_Pair((new sc_Pair("\u1E9Cs",(new sc_Pair("\u1E9Cs",null)))),null)))))),null))); |
michael@0 | 3813 | BgL_makezd2parserzd2 = function(grammar, lexer) { |
michael@0 | 3814 | var i; |
michael@0 | 3815 | var parser_descr; |
michael@0 | 3816 | var def_loop; |
michael@0 | 3817 | var nb_nts; |
michael@0 | 3818 | var names; |
michael@0 | 3819 | var steps; |
michael@0 | 3820 | var predictors; |
michael@0 | 3821 | var enders; |
michael@0 | 3822 | var starters; |
michael@0 | 3823 | var nts; |
michael@0 | 3824 | var sc_names_1; |
michael@0 | 3825 | var sc_steps_2; |
michael@0 | 3826 | var sc_predictors_3; |
michael@0 | 3827 | var sc_enders_4; |
michael@0 | 3828 | var sc_starters_5; |
michael@0 | 3829 | var nb_confs; |
michael@0 | 3830 | var BgL_sc_defzd2loop_6zd2; |
michael@0 | 3831 | var BgL_sc_nbzd2nts_7zd2; |
michael@0 | 3832 | var sc_nts_8; |
michael@0 | 3833 | var BgL_sc_defzd2loop_9zd2; |
michael@0 | 3834 | var ind; |
michael@0 | 3835 | { |
michael@0 | 3836 | ind = function(nt, sc_nts_10) { |
michael@0 | 3837 | var i; |
michael@0 | 3838 | { |
michael@0 | 3839 | (i = ((sc_nts_10.length)-(1))); |
michael@0 | 3840 | while (true) { |
michael@0 | 3841 | if ((i>=(0))) |
michael@0 | 3842 | if ((sc_isEqual((sc_nts_10[i]), nt))) |
michael@0 | 3843 | return i; |
michael@0 | 3844 | else |
michael@0 | 3845 | (--i); |
michael@0 | 3846 | else |
michael@0 | 3847 | return false; |
michael@0 | 3848 | } |
michael@0 | 3849 | } |
michael@0 | 3850 | }; |
michael@0 | 3851 | (sc_nts_8 = ((BgL_sc_defzd2loop_9zd2 = function(defs, sc_nts_11) { |
michael@0 | 3852 | var rule_loop; |
michael@0 | 3853 | var head; |
michael@0 | 3854 | var def; |
michael@0 | 3855 | return ((defs instanceof sc_Pair)?((def = (defs.car)), (head = (def.car)), (rule_loop = function(rules, sc_nts_12) { |
michael@0 | 3856 | var nt; |
michael@0 | 3857 | var l; |
michael@0 | 3858 | var sc_nts_13; |
michael@0 | 3859 | var rule; |
michael@0 | 3860 | if ((rules instanceof sc_Pair)) |
michael@0 | 3861 | { |
michael@0 | 3862 | (rule = (rules.car)); |
michael@0 | 3863 | (l = rule); |
michael@0 | 3864 | (sc_nts_13 = sc_nts_12); |
michael@0 | 3865 | while ((l instanceof sc_Pair)) { |
michael@0 | 3866 | { |
michael@0 | 3867 | (nt = (l.car)); |
michael@0 | 3868 | (l = (l.cdr)); |
michael@0 | 3869 | (sc_nts_13 = (((sc_member(nt, sc_nts_13))!== false)?sc_nts_13:(new sc_Pair(nt, sc_nts_13)))); |
michael@0 | 3870 | } |
michael@0 | 3871 | } |
michael@0 | 3872 | return (rule_loop((rules.cdr), sc_nts_13)); |
michael@0 | 3873 | } |
michael@0 | 3874 | else |
michael@0 | 3875 | return (BgL_sc_defzd2loop_9zd2((defs.cdr), sc_nts_12)); |
michael@0 | 3876 | }), (rule_loop((def.cdr), (((sc_member(head, sc_nts_11))!== false)?sc_nts_11:(new sc_Pair(head, sc_nts_11)))))):(sc_list2vector((sc_reverse(sc_nts_11))))); |
michael@0 | 3877 | }), (BgL_sc_defzd2loop_9zd2(grammar, null)))); |
michael@0 | 3878 | (BgL_sc_nbzd2nts_7zd2 = (sc_nts_8.length)); |
michael@0 | 3879 | (nb_confs = (((BgL_sc_defzd2loop_6zd2 = function(defs, BgL_sc_nbzd2confs_14zd2) { |
michael@0 | 3880 | var rule_loop; |
michael@0 | 3881 | var def; |
michael@0 | 3882 | return ((defs instanceof sc_Pair)?((def = (defs.car)), (rule_loop = function(rules, BgL_sc_nbzd2confs_15zd2) { |
michael@0 | 3883 | var l; |
michael@0 | 3884 | var BgL_sc_nbzd2confs_16zd2; |
michael@0 | 3885 | var rule; |
michael@0 | 3886 | if ((rules instanceof sc_Pair)) |
michael@0 | 3887 | { |
michael@0 | 3888 | (rule = (rules.car)); |
michael@0 | 3889 | (l = rule); |
michael@0 | 3890 | (BgL_sc_nbzd2confs_16zd2 = BgL_sc_nbzd2confs_15zd2); |
michael@0 | 3891 | while ((l instanceof sc_Pair)) { |
michael@0 | 3892 | { |
michael@0 | 3893 | (l = (l.cdr)); |
michael@0 | 3894 | (++BgL_sc_nbzd2confs_16zd2); |
michael@0 | 3895 | } |
michael@0 | 3896 | } |
michael@0 | 3897 | return (rule_loop((rules.cdr), (BgL_sc_nbzd2confs_16zd2+(1)))); |
michael@0 | 3898 | } |
michael@0 | 3899 | else |
michael@0 | 3900 | return (BgL_sc_defzd2loop_6zd2((defs.cdr), BgL_sc_nbzd2confs_15zd2)); |
michael@0 | 3901 | }), (rule_loop((def.cdr), BgL_sc_nbzd2confs_14zd2))):BgL_sc_nbzd2confs_14zd2); |
michael@0 | 3902 | }), (BgL_sc_defzd2loop_6zd2(grammar, (0))))+BgL_sc_nbzd2nts_7zd2)); |
michael@0 | 3903 | (sc_starters_5 = (sc_makeVector(BgL_sc_nbzd2nts_7zd2, null))); |
michael@0 | 3904 | (sc_enders_4 = (sc_makeVector(BgL_sc_nbzd2nts_7zd2, null))); |
michael@0 | 3905 | (sc_predictors_3 = (sc_makeVector(BgL_sc_nbzd2nts_7zd2, null))); |
michael@0 | 3906 | (sc_steps_2 = (sc_makeVector(nb_confs, false))); |
michael@0 | 3907 | (sc_names_1 = (sc_makeVector(nb_confs, false))); |
michael@0 | 3908 | (nts = sc_nts_8); |
michael@0 | 3909 | (starters = sc_starters_5); |
michael@0 | 3910 | (enders = sc_enders_4); |
michael@0 | 3911 | (predictors = sc_predictors_3); |
michael@0 | 3912 | (steps = sc_steps_2); |
michael@0 | 3913 | (names = sc_names_1); |
michael@0 | 3914 | (nb_nts = (sc_nts_8.length)); |
michael@0 | 3915 | (i = (nb_nts-(1))); |
michael@0 | 3916 | while ((i>=(0))) { |
michael@0 | 3917 | { |
michael@0 | 3918 | (sc_steps_2[i] = (i-nb_nts)); |
michael@0 | 3919 | (sc_names_1[i] = (sc_list((sc_nts_8[i]), (0)))); |
michael@0 | 3920 | (sc_enders_4[i] = (sc_list(i))); |
michael@0 | 3921 | (--i); |
michael@0 | 3922 | } |
michael@0 | 3923 | } |
michael@0 | 3924 | def_loop = function(defs, conf) { |
michael@0 | 3925 | var rule_loop; |
michael@0 | 3926 | var head; |
michael@0 | 3927 | var def; |
michael@0 | 3928 | return ((defs instanceof sc_Pair)?((def = (defs.car)), (head = (def.car)), (rule_loop = function(rules, conf, rule_num) { |
michael@0 | 3929 | var i; |
michael@0 | 3930 | var sc_i_17; |
michael@0 | 3931 | var nt; |
michael@0 | 3932 | var l; |
michael@0 | 3933 | var sc_conf_18; |
michael@0 | 3934 | var sc_i_19; |
michael@0 | 3935 | var rule; |
michael@0 | 3936 | if ((rules instanceof sc_Pair)) |
michael@0 | 3937 | { |
michael@0 | 3938 | (rule = (rules.car)); |
michael@0 | 3939 | (names[conf] = (sc_list(head, rule_num))); |
michael@0 | 3940 | (sc_i_19 = (ind(head, nts))); |
michael@0 | 3941 | (starters[sc_i_19] = (new sc_Pair(conf, (starters[sc_i_19])))); |
michael@0 | 3942 | (l = rule); |
michael@0 | 3943 | (sc_conf_18 = conf); |
michael@0 | 3944 | while ((l instanceof sc_Pair)) { |
michael@0 | 3945 | { |
michael@0 | 3946 | (nt = (l.car)); |
michael@0 | 3947 | (steps[sc_conf_18] = (ind(nt, nts))); |
michael@0 | 3948 | (sc_i_17 = (ind(nt, nts))); |
michael@0 | 3949 | (predictors[sc_i_17] = (new sc_Pair(sc_conf_18, (predictors[sc_i_17])))); |
michael@0 | 3950 | (l = (l.cdr)); |
michael@0 | 3951 | (++sc_conf_18); |
michael@0 | 3952 | } |
michael@0 | 3953 | } |
michael@0 | 3954 | (steps[sc_conf_18] = ((ind(head, nts))-nb_nts)); |
michael@0 | 3955 | (i = (ind(head, nts))); |
michael@0 | 3956 | (enders[i] = (new sc_Pair(sc_conf_18, (enders[i])))); |
michael@0 | 3957 | return (rule_loop((rules.cdr), (sc_conf_18+(1)), (rule_num+(1)))); |
michael@0 | 3958 | } |
michael@0 | 3959 | else |
michael@0 | 3960 | return (def_loop((defs.cdr), conf)); |
michael@0 | 3961 | }), (rule_loop((def.cdr), conf, (1)))):undefined); |
michael@0 | 3962 | }; |
michael@0 | 3963 | (def_loop(grammar, (sc_nts_8.length))); |
michael@0 | 3964 | (parser_descr = [lexer, sc_nts_8, sc_starters_5, sc_enders_4, sc_predictors_3, sc_steps_2, sc_names_1]); |
michael@0 | 3965 | return function(input) { |
michael@0 | 3966 | var optrOpnd; |
michael@0 | 3967 | var sc_optrOpnd_20; |
michael@0 | 3968 | var sc_optrOpnd_21; |
michael@0 | 3969 | var sc_optrOpnd_22; |
michael@0 | 3970 | var loop1; |
michael@0 | 3971 | var BgL_sc_stateza2_23za2; |
michael@0 | 3972 | var toks; |
michael@0 | 3973 | var BgL_sc_nbzd2nts_24zd2; |
michael@0 | 3974 | var sc_steps_25; |
michael@0 | 3975 | var sc_enders_26; |
michael@0 | 3976 | var state_num; |
michael@0 | 3977 | var BgL_sc_statesza2_27za2; |
michael@0 | 3978 | var states; |
michael@0 | 3979 | var i; |
michael@0 | 3980 | var conf; |
michael@0 | 3981 | var l; |
michael@0 | 3982 | var tok_nts; |
michael@0 | 3983 | var sc_i_28; |
michael@0 | 3984 | var sc_i_29; |
michael@0 | 3985 | var l1; |
michael@0 | 3986 | var l2; |
michael@0 | 3987 | var tok; |
michael@0 | 3988 | var tail1129; |
michael@0 | 3989 | var L1125; |
michael@0 | 3990 | var goal_enders; |
michael@0 | 3991 | var BgL_sc_statesza2_30za2; |
michael@0 | 3992 | var BgL_sc_nbzd2nts_31zd2; |
michael@0 | 3993 | var BgL_sc_nbzd2confs_32zd2; |
michael@0 | 3994 | var nb_toks; |
michael@0 | 3995 | var goal_starters; |
michael@0 | 3996 | var sc_states_33; |
michael@0 | 3997 | var BgL_sc_nbzd2confs_34zd2; |
michael@0 | 3998 | var BgL_sc_nbzd2toks_35zd2; |
michael@0 | 3999 | var sc_toks_36; |
michael@0 | 4000 | var falseHead1128; |
michael@0 | 4001 | var sc_names_37; |
michael@0 | 4002 | var sc_steps_38; |
michael@0 | 4003 | var sc_predictors_39; |
michael@0 | 4004 | var sc_enders_40; |
michael@0 | 4005 | var sc_starters_41; |
michael@0 | 4006 | var sc_nts_42; |
michael@0 | 4007 | var lexer; |
michael@0 | 4008 | var sc_ind_43; |
michael@0 | 4009 | var make_states; |
michael@0 | 4010 | var BgL_sc_confzd2setzd2getza2_44za2; |
michael@0 | 4011 | var conf_set_merge_new_bang; |
michael@0 | 4012 | var conf_set_adjoin; |
michael@0 | 4013 | var BgL_sc_confzd2setzd2adjoinza2_45za2; |
michael@0 | 4014 | var BgL_sc_confzd2setzd2adjoinza2za2_46z00; |
michael@0 | 4015 | var conf_set_union; |
michael@0 | 4016 | var forw; |
michael@0 | 4017 | var is_parsed; |
michael@0 | 4018 | var deriv_trees; |
michael@0 | 4019 | var BgL_sc_derivzd2treesza2_47z70; |
michael@0 | 4020 | var nb_deriv_trees; |
michael@0 | 4021 | var BgL_sc_nbzd2derivzd2treesza2_48za2; |
michael@0 | 4022 | { |
michael@0 | 4023 | sc_ind_43 = function(nt, sc_nts_49) { |
michael@0 | 4024 | var i; |
michael@0 | 4025 | { |
michael@0 | 4026 | (i = ((sc_nts_49.length)-(1))); |
michael@0 | 4027 | while (true) { |
michael@0 | 4028 | if ((i>=(0))) |
michael@0 | 4029 | if ((sc_isEqual((sc_nts_49[i]), nt))) |
michael@0 | 4030 | return i; |
michael@0 | 4031 | else |
michael@0 | 4032 | (--i); |
michael@0 | 4033 | else |
michael@0 | 4034 | return false; |
michael@0 | 4035 | } |
michael@0 | 4036 | } |
michael@0 | 4037 | }; |
michael@0 | 4038 | make_states = function(BgL_sc_nbzd2toks_50zd2, BgL_sc_nbzd2confs_51zd2) { |
michael@0 | 4039 | var v; |
michael@0 | 4040 | var i; |
michael@0 | 4041 | var sc_states_52; |
michael@0 | 4042 | { |
michael@0 | 4043 | (sc_states_52 = (sc_makeVector((BgL_sc_nbzd2toks_50zd2+(1)), false))); |
michael@0 | 4044 | (i = BgL_sc_nbzd2toks_50zd2); |
michael@0 | 4045 | while ((i>=(0))) { |
michael@0 | 4046 | { |
michael@0 | 4047 | (v = (sc_makeVector((BgL_sc_nbzd2confs_51zd2+(1)), false))); |
michael@0 | 4048 | (v[(0)] = (-1)); |
michael@0 | 4049 | (sc_states_52[i] = v); |
michael@0 | 4050 | (--i); |
michael@0 | 4051 | } |
michael@0 | 4052 | } |
michael@0 | 4053 | return sc_states_52; |
michael@0 | 4054 | } |
michael@0 | 4055 | }; |
michael@0 | 4056 | BgL_sc_confzd2setzd2getza2_44za2 = function(state, BgL_sc_statezd2num_53zd2, sc_conf_54) { |
michael@0 | 4057 | var conf_set; |
michael@0 | 4058 | var BgL_sc_confzd2set_55zd2; |
michael@0 | 4059 | return ((BgL_sc_confzd2set_55zd2 = (state[(sc_conf_54+(1))])), ((BgL_sc_confzd2set_55zd2!== false)?BgL_sc_confzd2set_55zd2:((conf_set = (sc_makeVector((BgL_sc_statezd2num_53zd2+(6)), false))), (conf_set[(1)] = (-3)), (conf_set[(2)] = (-1)), (conf_set[(3)] = (-1)), (conf_set[(4)] = (-1)), (state[(sc_conf_54+(1))] = conf_set), conf_set))); |
michael@0 | 4060 | }; |
michael@0 | 4061 | conf_set_merge_new_bang = function(conf_set) { |
michael@0 | 4062 | return ((conf_set[((conf_set[(1)])+(5))] = (conf_set[(4)])), (conf_set[(1)] = (conf_set[(3)])), (conf_set[(3)] = (-1)), (conf_set[(4)] = (-1))); |
michael@0 | 4063 | }; |
michael@0 | 4064 | conf_set_adjoin = function(state, conf_set, sc_conf_56, i) { |
michael@0 | 4065 | var tail; |
michael@0 | 4066 | return ((tail = (conf_set[(3)])), (conf_set[(i+(5))] = (-1)), (conf_set[(tail+(5))] = i), (conf_set[(3)] = i), ((tail<(0))?((conf_set[(0)] = (state[(0)])), (state[(0)] = sc_conf_56)):undefined)); |
michael@0 | 4067 | }; |
michael@0 | 4068 | BgL_sc_confzd2setzd2adjoinza2_45za2 = function(sc_states_57, BgL_sc_statezd2num_58zd2, l, i) { |
michael@0 | 4069 | var conf_set; |
michael@0 | 4070 | var sc_conf_59; |
michael@0 | 4071 | var l1; |
michael@0 | 4072 | var state; |
michael@0 | 4073 | { |
michael@0 | 4074 | (state = (sc_states_57[BgL_sc_statezd2num_58zd2])); |
michael@0 | 4075 | (l1 = l); |
michael@0 | 4076 | while ((l1 instanceof sc_Pair)) { |
michael@0 | 4077 | { |
michael@0 | 4078 | (sc_conf_59 = (l1.car)); |
michael@0 | 4079 | (conf_set = (BgL_sc_confzd2setzd2getza2_44za2(state, BgL_sc_statezd2num_58zd2, sc_conf_59))); |
michael@0 | 4080 | if (((conf_set[(i+(5))])=== false)) |
michael@0 | 4081 | { |
michael@0 | 4082 | (conf_set_adjoin(state, conf_set, sc_conf_59, i)); |
michael@0 | 4083 | (l1 = (l1.cdr)); |
michael@0 | 4084 | } |
michael@0 | 4085 | else |
michael@0 | 4086 | (l1 = (l1.cdr)); |
michael@0 | 4087 | } |
michael@0 | 4088 | } |
michael@0 | 4089 | return undefined; |
michael@0 | 4090 | } |
michael@0 | 4091 | }; |
michael@0 | 4092 | BgL_sc_confzd2setzd2adjoinza2za2_46z00 = function(sc_states_60, BgL_sc_statesza2_61za2, BgL_sc_statezd2num_62zd2, sc_conf_63, i) { |
michael@0 | 4093 | var BgL_sc_confzd2setza2_64z70; |
michael@0 | 4094 | var BgL_sc_stateza2_65za2; |
michael@0 | 4095 | var conf_set; |
michael@0 | 4096 | var state; |
michael@0 | 4097 | return ((state = (sc_states_60[BgL_sc_statezd2num_62zd2])), ((((conf_set = (state[(sc_conf_63+(1))])), ((conf_set!== false)?(conf_set[(i+(5))]):false))!== false)?((BgL_sc_stateza2_65za2 = (BgL_sc_statesza2_61za2[BgL_sc_statezd2num_62zd2])), (BgL_sc_confzd2setza2_64z70 = (BgL_sc_confzd2setzd2getza2_44za2(BgL_sc_stateza2_65za2, BgL_sc_statezd2num_62zd2, sc_conf_63))), (((BgL_sc_confzd2setza2_64z70[(i+(5))])=== false)?(conf_set_adjoin(BgL_sc_stateza2_65za2, BgL_sc_confzd2setza2_64z70, sc_conf_63, i)):undefined), true):false)); |
michael@0 | 4098 | }; |
michael@0 | 4099 | conf_set_union = function(state, conf_set, sc_conf_66, other_set) { |
michael@0 | 4100 | var i; |
michael@0 | 4101 | { |
michael@0 | 4102 | (i = (other_set[(2)])); |
michael@0 | 4103 | while ((i>=(0))) { |
michael@0 | 4104 | if (((conf_set[(i+(5))])=== false)) |
michael@0 | 4105 | { |
michael@0 | 4106 | (conf_set_adjoin(state, conf_set, sc_conf_66, i)); |
michael@0 | 4107 | (i = (other_set[(i+(5))])); |
michael@0 | 4108 | } |
michael@0 | 4109 | else |
michael@0 | 4110 | (i = (other_set[(i+(5))])); |
michael@0 | 4111 | } |
michael@0 | 4112 | return undefined; |
michael@0 | 4113 | } |
michael@0 | 4114 | }; |
michael@0 | 4115 | forw = function(sc_states_67, BgL_sc_statezd2num_68zd2, sc_starters_69, sc_enders_70, sc_predictors_71, sc_steps_72, sc_nts_73) { |
michael@0 | 4116 | var next_set; |
michael@0 | 4117 | var next; |
michael@0 | 4118 | var conf_set; |
michael@0 | 4119 | var ender; |
michael@0 | 4120 | var l; |
michael@0 | 4121 | var starter_set; |
michael@0 | 4122 | var starter; |
michael@0 | 4123 | var sc_l_74; |
michael@0 | 4124 | var sc_loop1_75; |
michael@0 | 4125 | var head; |
michael@0 | 4126 | var BgL_sc_confzd2set_76zd2; |
michael@0 | 4127 | var BgL_sc_statezd2num_77zd2; |
michael@0 | 4128 | var state; |
michael@0 | 4129 | var sc_states_78; |
michael@0 | 4130 | var preds; |
michael@0 | 4131 | var BgL_sc_confzd2set_79zd2; |
michael@0 | 4132 | var step; |
michael@0 | 4133 | var sc_conf_80; |
michael@0 | 4134 | var BgL_sc_nbzd2nts_81zd2; |
michael@0 | 4135 | var sc_state_82; |
michael@0 | 4136 | { |
michael@0 | 4137 | (sc_state_82 = (sc_states_67[BgL_sc_statezd2num_68zd2])); |
michael@0 | 4138 | (BgL_sc_nbzd2nts_81zd2 = (sc_nts_73.length)); |
michael@0 | 4139 | while (true) { |
michael@0 | 4140 | { |
michael@0 | 4141 | (sc_conf_80 = (sc_state_82[(0)])); |
michael@0 | 4142 | if ((sc_conf_80>=(0))) |
michael@0 | 4143 | { |
michael@0 | 4144 | (step = (sc_steps_72[sc_conf_80])); |
michael@0 | 4145 | (BgL_sc_confzd2set_79zd2 = (sc_state_82[(sc_conf_80+(1))])); |
michael@0 | 4146 | (head = (BgL_sc_confzd2set_79zd2[(4)])); |
michael@0 | 4147 | (sc_state_82[(0)] = (BgL_sc_confzd2set_79zd2[(0)])); |
michael@0 | 4148 | (conf_set_merge_new_bang(BgL_sc_confzd2set_79zd2)); |
michael@0 | 4149 | if ((step>=(0))) |
michael@0 | 4150 | { |
michael@0 | 4151 | (sc_l_74 = (sc_starters_69[step])); |
michael@0 | 4152 | while ((sc_l_74 instanceof sc_Pair)) { |
michael@0 | 4153 | { |
michael@0 | 4154 | (starter = (sc_l_74.car)); |
michael@0 | 4155 | (starter_set = (BgL_sc_confzd2setzd2getza2_44za2(sc_state_82, BgL_sc_statezd2num_68zd2, starter))); |
michael@0 | 4156 | if (((starter_set[(BgL_sc_statezd2num_68zd2+(5))])=== false)) |
michael@0 | 4157 | { |
michael@0 | 4158 | (conf_set_adjoin(sc_state_82, starter_set, starter, BgL_sc_statezd2num_68zd2)); |
michael@0 | 4159 | (sc_l_74 = (sc_l_74.cdr)); |
michael@0 | 4160 | } |
michael@0 | 4161 | else |
michael@0 | 4162 | (sc_l_74 = (sc_l_74.cdr)); |
michael@0 | 4163 | } |
michael@0 | 4164 | } |
michael@0 | 4165 | (l = (sc_enders_70[step])); |
michael@0 | 4166 | while ((l instanceof sc_Pair)) { |
michael@0 | 4167 | { |
michael@0 | 4168 | (ender = (l.car)); |
michael@0 | 4169 | if ((((conf_set = (sc_state_82[(ender+(1))])), ((conf_set!== false)?(conf_set[(BgL_sc_statezd2num_68zd2+(5))]):false))!== false)) |
michael@0 | 4170 | { |
michael@0 | 4171 | (next = (sc_conf_80+(1))); |
michael@0 | 4172 | (next_set = (BgL_sc_confzd2setzd2getza2_44za2(sc_state_82, BgL_sc_statezd2num_68zd2, next))); |
michael@0 | 4173 | (conf_set_union(sc_state_82, next_set, next, BgL_sc_confzd2set_79zd2)); |
michael@0 | 4174 | (l = (l.cdr)); |
michael@0 | 4175 | } |
michael@0 | 4176 | else |
michael@0 | 4177 | (l = (l.cdr)); |
michael@0 | 4178 | } |
michael@0 | 4179 | } |
michael@0 | 4180 | } |
michael@0 | 4181 | else |
michael@0 | 4182 | { |
michael@0 | 4183 | (preds = (sc_predictors_71[(step+BgL_sc_nbzd2nts_81zd2)])); |
michael@0 | 4184 | (sc_states_78 = sc_states_67); |
michael@0 | 4185 | (state = sc_state_82); |
michael@0 | 4186 | (BgL_sc_statezd2num_77zd2 = BgL_sc_statezd2num_68zd2); |
michael@0 | 4187 | (BgL_sc_confzd2set_76zd2 = BgL_sc_confzd2set_79zd2); |
michael@0 | 4188 | sc_loop1_75 = function(l) { |
michael@0 | 4189 | var sc_state_83; |
michael@0 | 4190 | var BgL_sc_nextzd2set_84zd2; |
michael@0 | 4191 | var sc_next_85; |
michael@0 | 4192 | var pred_set; |
michael@0 | 4193 | var i; |
michael@0 | 4194 | var pred; |
michael@0 | 4195 | if ((l instanceof sc_Pair)) |
michael@0 | 4196 | { |
michael@0 | 4197 | (pred = (l.car)); |
michael@0 | 4198 | (i = head); |
michael@0 | 4199 | while ((i>=(0))) { |
michael@0 | 4200 | { |
michael@0 | 4201 | (pred_set = ((sc_state_83 = (sc_states_78[i])), (sc_state_83[(pred+(1))]))); |
michael@0 | 4202 | if ((pred_set!== false)) |
michael@0 | 4203 | { |
michael@0 | 4204 | (sc_next_85 = (pred+(1))); |
michael@0 | 4205 | (BgL_sc_nextzd2set_84zd2 = (BgL_sc_confzd2setzd2getza2_44za2(state, BgL_sc_statezd2num_77zd2, sc_next_85))); |
michael@0 | 4206 | (conf_set_union(state, BgL_sc_nextzd2set_84zd2, sc_next_85, pred_set)); |
michael@0 | 4207 | } |
michael@0 | 4208 | (i = (BgL_sc_confzd2set_76zd2[(i+(5))])); |
michael@0 | 4209 | } |
michael@0 | 4210 | } |
michael@0 | 4211 | return (sc_loop1_75((l.cdr))); |
michael@0 | 4212 | } |
michael@0 | 4213 | else |
michael@0 | 4214 | return undefined; |
michael@0 | 4215 | }; |
michael@0 | 4216 | (sc_loop1_75(preds)); |
michael@0 | 4217 | } |
michael@0 | 4218 | } |
michael@0 | 4219 | else |
michael@0 | 4220 | return undefined; |
michael@0 | 4221 | } |
michael@0 | 4222 | } |
michael@0 | 4223 | } |
michael@0 | 4224 | }; |
michael@0 | 4225 | is_parsed = function(nt, i, j, sc_nts_86, sc_enders_87, sc_states_88) { |
michael@0 | 4226 | var conf_set; |
michael@0 | 4227 | var state; |
michael@0 | 4228 | var sc_conf_89; |
michael@0 | 4229 | var l; |
michael@0 | 4230 | var BgL_sc_ntza2_90za2; |
michael@0 | 4231 | { |
michael@0 | 4232 | (BgL_sc_ntza2_90za2 = (sc_ind_43(nt, sc_nts_86))); |
michael@0 | 4233 | if ((BgL_sc_ntza2_90za2!== false)) |
michael@0 | 4234 | { |
michael@0 | 4235 | (sc_nts_86.length); |
michael@0 | 4236 | (l = (sc_enders_87[BgL_sc_ntza2_90za2])); |
michael@0 | 4237 | while (true) { |
michael@0 | 4238 | if ((l instanceof sc_Pair)) |
michael@0 | 4239 | { |
michael@0 | 4240 | (sc_conf_89 = (l.car)); |
michael@0 | 4241 | if ((((state = (sc_states_88[j])), (conf_set = (state[(sc_conf_89+(1))])), ((conf_set!== false)?(conf_set[(i+(5))]):false))!== false)) |
michael@0 | 4242 | return true; |
michael@0 | 4243 | else |
michael@0 | 4244 | (l = (l.cdr)); |
michael@0 | 4245 | } |
michael@0 | 4246 | else |
michael@0 | 4247 | return false; |
michael@0 | 4248 | } |
michael@0 | 4249 | } |
michael@0 | 4250 | else |
michael@0 | 4251 | return false; |
michael@0 | 4252 | } |
michael@0 | 4253 | }; |
michael@0 | 4254 | deriv_trees = function(sc_conf_91, i, j, sc_enders_92, sc_steps_93, sc_names_94, sc_toks_95, sc_states_96, BgL_sc_nbzd2nts_97zd2) { |
michael@0 | 4255 | var sc_loop1_98; |
michael@0 | 4256 | var prev; |
michael@0 | 4257 | var name; |
michael@0 | 4258 | return ((name = (sc_names_94[sc_conf_91])), ((name!== false)?((sc_conf_91<BgL_sc_nbzd2nts_97zd2)?(sc_list((sc_list(name, ((sc_toks_95[i]).car))))):(sc_list((sc_list(name))))):((prev = (sc_conf_91-(1))), (sc_loop1_98 = function(l1, l2) { |
michael@0 | 4259 | var loop2; |
michael@0 | 4260 | var ender_set; |
michael@0 | 4261 | var state; |
michael@0 | 4262 | var ender; |
michael@0 | 4263 | var l1; |
michael@0 | 4264 | var l2; |
michael@0 | 4265 | while (true) { |
michael@0 | 4266 | if ((l1 instanceof sc_Pair)) |
michael@0 | 4267 | { |
michael@0 | 4268 | (ender = (l1.car)); |
michael@0 | 4269 | (ender_set = ((state = (sc_states_96[j])), (state[(ender+(1))]))); |
michael@0 | 4270 | if ((ender_set!== false)) |
michael@0 | 4271 | { |
michael@0 | 4272 | loop2 = function(k, l2) { |
michael@0 | 4273 | var loop3; |
michael@0 | 4274 | var ender_trees; |
michael@0 | 4275 | var prev_trees; |
michael@0 | 4276 | var conf_set; |
michael@0 | 4277 | var sc_state_99; |
michael@0 | 4278 | var k; |
michael@0 | 4279 | var l2; |
michael@0 | 4280 | while (true) { |
michael@0 | 4281 | if ((k>=(0))) |
michael@0 | 4282 | if (((k>=i)&&(((sc_state_99 = (sc_states_96[k])), (conf_set = (sc_state_99[(prev+(1))])), ((conf_set!== false)?(conf_set[(i+(5))]):false))!== false))) |
michael@0 | 4283 | { |
michael@0 | 4284 | (prev_trees = (deriv_trees(prev, i, k, sc_enders_92, sc_steps_93, sc_names_94, sc_toks_95, sc_states_96, BgL_sc_nbzd2nts_97zd2))); |
michael@0 | 4285 | (ender_trees = (deriv_trees(ender, k, j, sc_enders_92, sc_steps_93, sc_names_94, sc_toks_95, sc_states_96, BgL_sc_nbzd2nts_97zd2))); |
michael@0 | 4286 | loop3 = function(l3, l2) { |
michael@0 | 4287 | var l4; |
michael@0 | 4288 | var sc_l2_100; |
michael@0 | 4289 | var ender_tree; |
michael@0 | 4290 | if ((l3 instanceof sc_Pair)) |
michael@0 | 4291 | { |
michael@0 | 4292 | (ender_tree = (sc_list((l3.car)))); |
michael@0 | 4293 | (l4 = prev_trees); |
michael@0 | 4294 | (sc_l2_100 = l2); |
michael@0 | 4295 | while ((l4 instanceof sc_Pair)) { |
michael@0 | 4296 | { |
michael@0 | 4297 | (sc_l2_100 = (new sc_Pair((sc_append((l4.car), ender_tree)), sc_l2_100))); |
michael@0 | 4298 | (l4 = (l4.cdr)); |
michael@0 | 4299 | } |
michael@0 | 4300 | } |
michael@0 | 4301 | return (loop3((l3.cdr), sc_l2_100)); |
michael@0 | 4302 | } |
michael@0 | 4303 | else |
michael@0 | 4304 | return (loop2((ender_set[(k+(5))]), l2)); |
michael@0 | 4305 | }; |
michael@0 | 4306 | return (loop3(ender_trees, l2)); |
michael@0 | 4307 | } |
michael@0 | 4308 | else |
michael@0 | 4309 | (k = (ender_set[(k+(5))])); |
michael@0 | 4310 | else |
michael@0 | 4311 | return (sc_loop1_98((l1.cdr), l2)); |
michael@0 | 4312 | } |
michael@0 | 4313 | }; |
michael@0 | 4314 | return (loop2((ender_set[(2)]), l2)); |
michael@0 | 4315 | } |
michael@0 | 4316 | else |
michael@0 | 4317 | (l1 = (l1.cdr)); |
michael@0 | 4318 | } |
michael@0 | 4319 | else |
michael@0 | 4320 | return l2; |
michael@0 | 4321 | } |
michael@0 | 4322 | }), (sc_loop1_98((sc_enders_92[(sc_steps_93[prev])]), null))))); |
michael@0 | 4323 | }; |
michael@0 | 4324 | BgL_sc_derivzd2treesza2_47z70 = function(nt, i, j, sc_nts_101, sc_enders_102, sc_steps_103, sc_names_104, sc_toks_105, sc_states_106) { |
michael@0 | 4325 | var conf_set; |
michael@0 | 4326 | var state; |
michael@0 | 4327 | var sc_conf_107; |
michael@0 | 4328 | var l; |
michael@0 | 4329 | var trees; |
michael@0 | 4330 | var BgL_sc_nbzd2nts_108zd2; |
michael@0 | 4331 | var BgL_sc_ntza2_109za2; |
michael@0 | 4332 | { |
michael@0 | 4333 | (BgL_sc_ntza2_109za2 = (sc_ind_43(nt, sc_nts_101))); |
michael@0 | 4334 | if ((BgL_sc_ntza2_109za2!== false)) |
michael@0 | 4335 | { |
michael@0 | 4336 | (BgL_sc_nbzd2nts_108zd2 = (sc_nts_101.length)); |
michael@0 | 4337 | (l = (sc_enders_102[BgL_sc_ntza2_109za2])); |
michael@0 | 4338 | (trees = null); |
michael@0 | 4339 | while ((l instanceof sc_Pair)) { |
michael@0 | 4340 | { |
michael@0 | 4341 | (sc_conf_107 = (l.car)); |
michael@0 | 4342 | if ((((state = (sc_states_106[j])), (conf_set = (state[(sc_conf_107+(1))])), ((conf_set!== false)?(conf_set[(i+(5))]):false))!== false)) |
michael@0 | 4343 | { |
michael@0 | 4344 | (l = (l.cdr)); |
michael@0 | 4345 | (trees = (sc_append((deriv_trees(sc_conf_107, i, j, sc_enders_102, sc_steps_103, sc_names_104, sc_toks_105, sc_states_106, BgL_sc_nbzd2nts_108zd2)), trees))); |
michael@0 | 4346 | } |
michael@0 | 4347 | else |
michael@0 | 4348 | (l = (l.cdr)); |
michael@0 | 4349 | } |
michael@0 | 4350 | } |
michael@0 | 4351 | return trees; |
michael@0 | 4352 | } |
michael@0 | 4353 | else |
michael@0 | 4354 | return false; |
michael@0 | 4355 | } |
michael@0 | 4356 | }; |
michael@0 | 4357 | nb_deriv_trees = function(sc_conf_110, i, j, sc_enders_111, sc_steps_112, sc_toks_113, sc_states_114, BgL_sc_nbzd2nts_115zd2) { |
michael@0 | 4358 | var sc_loop1_116; |
michael@0 | 4359 | var tmp1124; |
michael@0 | 4360 | var prev; |
michael@0 | 4361 | return ((prev = (sc_conf_110-(1))), ((((tmp1124 = (sc_conf_110<BgL_sc_nbzd2nts_115zd2)), ((tmp1124!== false)?tmp1124:((sc_steps_112[prev])<(0))))!== false)?(1):((sc_loop1_116 = function(l, sc_n_118) { |
michael@0 | 4362 | var nb_ender_trees; |
michael@0 | 4363 | var nb_prev_trees; |
michael@0 | 4364 | var conf_set; |
michael@0 | 4365 | var state; |
michael@0 | 4366 | var k; |
michael@0 | 4367 | var n; |
michael@0 | 4368 | var ender_set; |
michael@0 | 4369 | var sc_state_117; |
michael@0 | 4370 | var ender; |
michael@0 | 4371 | var l; |
michael@0 | 4372 | var sc_n_118; |
michael@0 | 4373 | while (true) { |
michael@0 | 4374 | if ((l instanceof sc_Pair)) |
michael@0 | 4375 | { |
michael@0 | 4376 | (ender = (l.car)); |
michael@0 | 4377 | (ender_set = ((sc_state_117 = (sc_states_114[j])), (sc_state_117[(ender+(1))]))); |
michael@0 | 4378 | if ((ender_set!== false)) |
michael@0 | 4379 | { |
michael@0 | 4380 | (k = (ender_set[(2)])); |
michael@0 | 4381 | (n = sc_n_118); |
michael@0 | 4382 | while ((k>=(0))) { |
michael@0 | 4383 | if (((k>=i)&&(((state = (sc_states_114[k])), (conf_set = (state[(prev+(1))])), ((conf_set!== false)?(conf_set[(i+(5))]):false))!== false))) |
michael@0 | 4384 | { |
michael@0 | 4385 | (nb_prev_trees = (nb_deriv_trees(prev, i, k, sc_enders_111, sc_steps_112, sc_toks_113, sc_states_114, BgL_sc_nbzd2nts_115zd2))); |
michael@0 | 4386 | (nb_ender_trees = (nb_deriv_trees(ender, k, j, sc_enders_111, sc_steps_112, sc_toks_113, sc_states_114, BgL_sc_nbzd2nts_115zd2))); |
michael@0 | 4387 | (k = (ender_set[(k+(5))])); |
michael@0 | 4388 | (n +=(nb_prev_trees*nb_ender_trees)); |
michael@0 | 4389 | } |
michael@0 | 4390 | else |
michael@0 | 4391 | (k = (ender_set[(k+(5))])); |
michael@0 | 4392 | } |
michael@0 | 4393 | return (sc_loop1_116((l.cdr), n)); |
michael@0 | 4394 | } |
michael@0 | 4395 | else |
michael@0 | 4396 | (l = (l.cdr)); |
michael@0 | 4397 | } |
michael@0 | 4398 | else |
michael@0 | 4399 | return sc_n_118; |
michael@0 | 4400 | } |
michael@0 | 4401 | }), (sc_loop1_116((sc_enders_111[(sc_steps_112[prev])]), (0)))))); |
michael@0 | 4402 | }; |
michael@0 | 4403 | BgL_sc_nbzd2derivzd2treesza2_48za2 = function(nt, i, j, sc_nts_119, sc_enders_120, sc_steps_121, sc_toks_122, sc_states_123) { |
michael@0 | 4404 | var conf_set; |
michael@0 | 4405 | var state; |
michael@0 | 4406 | var sc_conf_124; |
michael@0 | 4407 | var l; |
michael@0 | 4408 | var nb_trees; |
michael@0 | 4409 | var BgL_sc_nbzd2nts_125zd2; |
michael@0 | 4410 | var BgL_sc_ntza2_126za2; |
michael@0 | 4411 | { |
michael@0 | 4412 | (BgL_sc_ntza2_126za2 = (sc_ind_43(nt, sc_nts_119))); |
michael@0 | 4413 | if ((BgL_sc_ntza2_126za2!== false)) |
michael@0 | 4414 | { |
michael@0 | 4415 | (BgL_sc_nbzd2nts_125zd2 = (sc_nts_119.length)); |
michael@0 | 4416 | (l = (sc_enders_120[BgL_sc_ntza2_126za2])); |
michael@0 | 4417 | (nb_trees = (0)); |
michael@0 | 4418 | while ((l instanceof sc_Pair)) { |
michael@0 | 4419 | { |
michael@0 | 4420 | (sc_conf_124 = (l.car)); |
michael@0 | 4421 | if ((((state = (sc_states_123[j])), (conf_set = (state[(sc_conf_124+(1))])), ((conf_set!== false)?(conf_set[(i+(5))]):false))!== false)) |
michael@0 | 4422 | { |
michael@0 | 4423 | (l = (l.cdr)); |
michael@0 | 4424 | (nb_trees = ((nb_deriv_trees(sc_conf_124, i, j, sc_enders_120, sc_steps_121, sc_toks_122, sc_states_123, BgL_sc_nbzd2nts_125zd2))+nb_trees)); |
michael@0 | 4425 | } |
michael@0 | 4426 | else |
michael@0 | 4427 | (l = (l.cdr)); |
michael@0 | 4428 | } |
michael@0 | 4429 | } |
michael@0 | 4430 | return nb_trees; |
michael@0 | 4431 | } |
michael@0 | 4432 | else |
michael@0 | 4433 | return false; |
michael@0 | 4434 | } |
michael@0 | 4435 | }; |
michael@0 | 4436 | (lexer = (parser_descr[(0)])); |
michael@0 | 4437 | (sc_nts_42 = (parser_descr[(1)])); |
michael@0 | 4438 | (sc_starters_41 = (parser_descr[(2)])); |
michael@0 | 4439 | (sc_enders_40 = (parser_descr[(3)])); |
michael@0 | 4440 | (sc_predictors_39 = (parser_descr[(4)])); |
michael@0 | 4441 | (sc_steps_38 = (parser_descr[(5)])); |
michael@0 | 4442 | (sc_names_37 = (parser_descr[(6)])); |
michael@0 | 4443 | (falseHead1128 = (new sc_Pair(null, null))); |
michael@0 | 4444 | (L1125 = (lexer(input))); |
michael@0 | 4445 | (tail1129 = falseHead1128); |
michael@0 | 4446 | while (!(L1125 === null)) { |
michael@0 | 4447 | { |
michael@0 | 4448 | (tok = (L1125.car)); |
michael@0 | 4449 | (l1 = (tok.cdr)); |
michael@0 | 4450 | (l2 = null); |
michael@0 | 4451 | while ((l1 instanceof sc_Pair)) { |
michael@0 | 4452 | { |
michael@0 | 4453 | (sc_i_29 = (sc_ind_43((l1.car), sc_nts_42))); |
michael@0 | 4454 | if ((sc_i_29!== false)) |
michael@0 | 4455 | { |
michael@0 | 4456 | (l1 = (l1.cdr)); |
michael@0 | 4457 | (l2 = (new sc_Pair(sc_i_29, l2))); |
michael@0 | 4458 | } |
michael@0 | 4459 | else |
michael@0 | 4460 | (l1 = (l1.cdr)); |
michael@0 | 4461 | } |
michael@0 | 4462 | } |
michael@0 | 4463 | (sc_optrOpnd_22 = (new sc_Pair((tok.car), (sc_reverse(l2))))); |
michael@0 | 4464 | (sc_optrOpnd_21 = (new sc_Pair(sc_optrOpnd_22, null))); |
michael@0 | 4465 | (tail1129.cdr = sc_optrOpnd_21); |
michael@0 | 4466 | (tail1129 = (tail1129.cdr)); |
michael@0 | 4467 | (L1125 = (L1125.cdr)); |
michael@0 | 4468 | } |
michael@0 | 4469 | } |
michael@0 | 4470 | (sc_optrOpnd_20 = (falseHead1128.cdr)); |
michael@0 | 4471 | (sc_toks_36 = (sc_list2vector(sc_optrOpnd_20))); |
michael@0 | 4472 | (BgL_sc_nbzd2toks_35zd2 = (sc_toks_36.length)); |
michael@0 | 4473 | (BgL_sc_nbzd2confs_34zd2 = (sc_steps_38.length)); |
michael@0 | 4474 | (sc_states_33 = (make_states(BgL_sc_nbzd2toks_35zd2, BgL_sc_nbzd2confs_34zd2))); |
michael@0 | 4475 | (goal_starters = (sc_starters_41[(0)])); |
michael@0 | 4476 | (BgL_sc_confzd2setzd2adjoinza2_45za2(sc_states_33, (0), goal_starters, (0))); |
michael@0 | 4477 | (forw(sc_states_33, (0), sc_starters_41, sc_enders_40, sc_predictors_39, sc_steps_38, sc_nts_42)); |
michael@0 | 4478 | (sc_i_28 = (0)); |
michael@0 | 4479 | while ((sc_i_28<BgL_sc_nbzd2toks_35zd2)) { |
michael@0 | 4480 | { |
michael@0 | 4481 | (tok_nts = ((sc_toks_36[sc_i_28]).cdr)); |
michael@0 | 4482 | (BgL_sc_confzd2setzd2adjoinza2_45za2(sc_states_33, (sc_i_28+(1)), tok_nts, sc_i_28)); |
michael@0 | 4483 | (forw(sc_states_33, (sc_i_28+(1)), sc_starters_41, sc_enders_40, sc_predictors_39, sc_steps_38, sc_nts_42)); |
michael@0 | 4484 | (++sc_i_28); |
michael@0 | 4485 | } |
michael@0 | 4486 | } |
michael@0 | 4487 | (nb_toks = (sc_toks_36.length)); |
michael@0 | 4488 | (BgL_sc_nbzd2confs_32zd2 = (sc_steps_38.length)); |
michael@0 | 4489 | (BgL_sc_nbzd2nts_31zd2 = (sc_nts_42.length)); |
michael@0 | 4490 | (BgL_sc_statesza2_30za2 = (make_states(nb_toks, BgL_sc_nbzd2confs_32zd2))); |
michael@0 | 4491 | (goal_enders = (sc_enders_40[(0)])); |
michael@0 | 4492 | (l = goal_enders); |
michael@0 | 4493 | while ((l instanceof sc_Pair)) { |
michael@0 | 4494 | { |
michael@0 | 4495 | (conf = (l.car)); |
michael@0 | 4496 | (BgL_sc_confzd2setzd2adjoinza2za2_46z00(sc_states_33, BgL_sc_statesza2_30za2, nb_toks, conf, (0))); |
michael@0 | 4497 | (l = (l.cdr)); |
michael@0 | 4498 | } |
michael@0 | 4499 | } |
michael@0 | 4500 | (i = nb_toks); |
michael@0 | 4501 | while ((i>=(0))) { |
michael@0 | 4502 | { |
michael@0 | 4503 | (states = sc_states_33); |
michael@0 | 4504 | (BgL_sc_statesza2_27za2 = BgL_sc_statesza2_30za2); |
michael@0 | 4505 | (state_num = i); |
michael@0 | 4506 | (sc_enders_26 = sc_enders_40); |
michael@0 | 4507 | (sc_steps_25 = sc_steps_38); |
michael@0 | 4508 | (BgL_sc_nbzd2nts_24zd2 = BgL_sc_nbzd2nts_31zd2); |
michael@0 | 4509 | (toks = sc_toks_36); |
michael@0 | 4510 | (BgL_sc_stateza2_23za2 = (BgL_sc_statesza2_30za2[i])); |
michael@0 | 4511 | loop1 = function() { |
michael@0 | 4512 | var sc_loop1_127; |
michael@0 | 4513 | var prev; |
michael@0 | 4514 | var BgL_sc_statesza2_128za2; |
michael@0 | 4515 | var sc_states_129; |
michael@0 | 4516 | var j; |
michael@0 | 4517 | var i; |
michael@0 | 4518 | var sc_i_130; |
michael@0 | 4519 | var head; |
michael@0 | 4520 | var conf_set; |
michael@0 | 4521 | var sc_conf_131; |
michael@0 | 4522 | { |
michael@0 | 4523 | (sc_conf_131 = (BgL_sc_stateza2_23za2[(0)])); |
michael@0 | 4524 | if ((sc_conf_131>=(0))) |
michael@0 | 4525 | { |
michael@0 | 4526 | (conf_set = (BgL_sc_stateza2_23za2[(sc_conf_131+(1))])); |
michael@0 | 4527 | (head = (conf_set[(4)])); |
michael@0 | 4528 | (BgL_sc_stateza2_23za2[(0)] = (conf_set[(0)])); |
michael@0 | 4529 | (conf_set_merge_new_bang(conf_set)); |
michael@0 | 4530 | (sc_i_130 = head); |
michael@0 | 4531 | while ((sc_i_130>=(0))) { |
michael@0 | 4532 | { |
michael@0 | 4533 | (i = sc_i_130); |
michael@0 | 4534 | (j = state_num); |
michael@0 | 4535 | (sc_states_129 = states); |
michael@0 | 4536 | (BgL_sc_statesza2_128za2 = BgL_sc_statesza2_27za2); |
michael@0 | 4537 | (prev = (sc_conf_131-(1))); |
michael@0 | 4538 | if (((sc_conf_131>=BgL_sc_nbzd2nts_24zd2)&&((sc_steps_25[prev])>=(0)))) |
michael@0 | 4539 | { |
michael@0 | 4540 | sc_loop1_127 = function(l) { |
michael@0 | 4541 | var k; |
michael@0 | 4542 | var ender_set; |
michael@0 | 4543 | var state; |
michael@0 | 4544 | var ender; |
michael@0 | 4545 | var l; |
michael@0 | 4546 | while (true) { |
michael@0 | 4547 | if ((l instanceof sc_Pair)) |
michael@0 | 4548 | { |
michael@0 | 4549 | (ender = (l.car)); |
michael@0 | 4550 | (ender_set = ((state = (sc_states_129[j])), (state[(ender+(1))]))); |
michael@0 | 4551 | if ((ender_set!== false)) |
michael@0 | 4552 | { |
michael@0 | 4553 | (k = (ender_set[(2)])); |
michael@0 | 4554 | while ((k>=(0))) { |
michael@0 | 4555 | { |
michael@0 | 4556 | if ((k>=i)) |
michael@0 | 4557 | if (((BgL_sc_confzd2setzd2adjoinza2za2_46z00(sc_states_129, BgL_sc_statesza2_128za2, k, prev, i))!== false)) |
michael@0 | 4558 | (BgL_sc_confzd2setzd2adjoinza2za2_46z00(sc_states_129, BgL_sc_statesza2_128za2, j, ender, k)); |
michael@0 | 4559 | (k = (ender_set[(k+(5))])); |
michael@0 | 4560 | } |
michael@0 | 4561 | } |
michael@0 | 4562 | return (sc_loop1_127((l.cdr))); |
michael@0 | 4563 | } |
michael@0 | 4564 | else |
michael@0 | 4565 | (l = (l.cdr)); |
michael@0 | 4566 | } |
michael@0 | 4567 | else |
michael@0 | 4568 | return undefined; |
michael@0 | 4569 | } |
michael@0 | 4570 | }; |
michael@0 | 4571 | (sc_loop1_127((sc_enders_26[(sc_steps_25[prev])]))); |
michael@0 | 4572 | } |
michael@0 | 4573 | (sc_i_130 = (conf_set[(sc_i_130+(5))])); |
michael@0 | 4574 | } |
michael@0 | 4575 | } |
michael@0 | 4576 | return (loop1()); |
michael@0 | 4577 | } |
michael@0 | 4578 | else |
michael@0 | 4579 | return undefined; |
michael@0 | 4580 | } |
michael@0 | 4581 | }; |
michael@0 | 4582 | (loop1()); |
michael@0 | 4583 | (--i); |
michael@0 | 4584 | } |
michael@0 | 4585 | } |
michael@0 | 4586 | (optrOpnd = BgL_sc_statesza2_30za2); |
michael@0 | 4587 | return [sc_nts_42, sc_starters_41, sc_enders_40, sc_predictors_39, sc_steps_38, sc_names_37, sc_toks_36, optrOpnd, is_parsed, BgL_sc_derivzd2treesza2_47z70, BgL_sc_nbzd2derivzd2treesza2_48za2]; |
michael@0 | 4588 | } |
michael@0 | 4589 | }; |
michael@0 | 4590 | } |
michael@0 | 4591 | }; |
michael@0 | 4592 | BgL_parsezd2ze3parsedzf3zc2 = function(parse, nt, i, j) { |
michael@0 | 4593 | var is_parsed; |
michael@0 | 4594 | var states; |
michael@0 | 4595 | var enders; |
michael@0 | 4596 | var nts; |
michael@0 | 4597 | return ((nts = (parse[(0)])), (enders = (parse[(2)])), (states = (parse[(7)])), (is_parsed = (parse[(8)])), (is_parsed(nt, i, j, nts, enders, states))); |
michael@0 | 4598 | }; |
michael@0 | 4599 | BgL_parsezd2ze3treesz31 = function(parse, nt, i, j) { |
michael@0 | 4600 | var BgL_sc_derivzd2treesza2_132z70; |
michael@0 | 4601 | var states; |
michael@0 | 4602 | var toks; |
michael@0 | 4603 | var names; |
michael@0 | 4604 | var steps; |
michael@0 | 4605 | var enders; |
michael@0 | 4606 | var nts; |
michael@0 | 4607 | return ((nts = (parse[(0)])), (enders = (parse[(2)])), (steps = (parse[(4)])), (names = (parse[(5)])), (toks = (parse[(6)])), (states = (parse[(7)])), (BgL_sc_derivzd2treesza2_132z70 = (parse[(9)])), (BgL_sc_derivzd2treesza2_132z70(nt, i, j, nts, enders, steps, names, toks, states))); |
michael@0 | 4608 | }; |
michael@0 | 4609 | BgL_parsezd2ze3nbzd2treesze3 = function(parse, nt, i, j) { |
michael@0 | 4610 | var BgL_sc_nbzd2derivzd2treesza2_133za2; |
michael@0 | 4611 | var states; |
michael@0 | 4612 | var toks; |
michael@0 | 4613 | var steps; |
michael@0 | 4614 | var enders; |
michael@0 | 4615 | var nts; |
michael@0 | 4616 | return ((nts = (parse[(0)])), (enders = (parse[(2)])), (steps = (parse[(4)])), (toks = (parse[(6)])), (states = (parse[(7)])), (BgL_sc_nbzd2derivzd2treesza2_133za2 = (parse[(10)])), (BgL_sc_nbzd2derivzd2treesza2_133za2(nt, i, j, nts, enders, steps, toks, states))); |
michael@0 | 4617 | }; |
michael@0 | 4618 | test = function(k) { |
michael@0 | 4619 | var x; |
michael@0 | 4620 | var p; |
michael@0 | 4621 | return ((p = (BgL_makezd2parserzd2(const_earley, function(l) { |
michael@0 | 4622 | var sc_x_134; |
michael@0 | 4623 | var tail1134; |
michael@0 | 4624 | var L1130; |
michael@0 | 4625 | var falseHead1133; |
michael@0 | 4626 | { |
michael@0 | 4627 | (falseHead1133 = (new sc_Pair(null, null))); |
michael@0 | 4628 | (tail1134 = falseHead1133); |
michael@0 | 4629 | (L1130 = l); |
michael@0 | 4630 | while (!(L1130 === null)) { |
michael@0 | 4631 | { |
michael@0 | 4632 | (tail1134.cdr = (new sc_Pair(((sc_x_134 = (L1130.car)), (sc_list(sc_x_134, sc_x_134))), null))); |
michael@0 | 4633 | (tail1134 = (tail1134.cdr)); |
michael@0 | 4634 | (L1130 = (L1130.cdr)); |
michael@0 | 4635 | } |
michael@0 | 4636 | } |
michael@0 | 4637 | return (falseHead1133.cdr); |
michael@0 | 4638 | } |
michael@0 | 4639 | }))), (x = (p((sc_vector2list((sc_makeVector(k, "\u1E9Ca"))))))), (sc_length((BgL_parsezd2ze3treesz31(x, "\u1E9Cs", (0), k))))); |
michael@0 | 4640 | }; |
michael@0 | 4641 | BgL_earleyzd2benchmarkzd2 = function() { |
michael@0 | 4642 | var args = null; |
michael@0 | 4643 | for (var sc_tmp = arguments.length - 1; sc_tmp >= 0; sc_tmp--) { |
michael@0 | 4644 | args = sc_cons(arguments[sc_tmp], args); |
michael@0 | 4645 | } |
michael@0 | 4646 | var k; |
michael@0 | 4647 | return ((k = ((args === null)?(7):(args.car))), (BgL_runzd2benchmarkzd2("earley", (1), function() { |
michael@0 | 4648 | return (test(k)); |
michael@0 | 4649 | }, function(result) { |
michael@0 | 4650 | return ((sc_display(result)), (sc_newline()), result == 132); |
michael@0 | 4651 | }))); |
michael@0 | 4652 | }; |
michael@0 | 4653 | } |
michael@0 | 4654 | |
michael@0 | 4655 | |
michael@0 | 4656 | /************* END OF GENERATED CODE *************/ |
michael@0 | 4657 | // Invoke this function to run a benchmark. |
michael@0 | 4658 | // The first argument is a string identifying the benchmark. |
michael@0 | 4659 | // The second argument is the number of times to run the benchmark. |
michael@0 | 4660 | // The third argument is a function that runs the benchmark. |
michael@0 | 4661 | // The fourth argument is a unary function that warns if the result |
michael@0 | 4662 | // returned by the benchmark is incorrect. |
michael@0 | 4663 | // |
michael@0 | 4664 | // Example: |
michael@0 | 4665 | // RunBenchmark("new Array()", |
michael@0 | 4666 | // 1, |
michael@0 | 4667 | // function () { new Array(1000000); } |
michael@0 | 4668 | // function (v) { |
michael@0 | 4669 | // return (v instanceof Array) && (v.length == 1000000); |
michael@0 | 4670 | // }); |
michael@0 | 4671 | |
michael@0 | 4672 | SC_DEFAULT_OUT = new sc_GenericOutputPort(function(s) {}); |
michael@0 | 4673 | SC_ERROR_OUT = SC_DEFAULT_OUT; |
michael@0 | 4674 | |
michael@0 | 4675 | function RunBenchmark(name, count, run, warn) { |
michael@0 | 4676 | for (var n = 0; n < count; ++n) { |
michael@0 | 4677 | result = run(); |
michael@0 | 4678 | if (!warn(result)) { |
michael@0 | 4679 | throw new Error("Earley or Boyer did incorrect number of rewrites"); |
michael@0 | 4680 | } |
michael@0 | 4681 | } |
michael@0 | 4682 | } |
michael@0 | 4683 | |
michael@0 | 4684 | var BgL_runzd2benchmarkzd2 = RunBenchmark; |