| OLD | NEW |
| 1 // This file is automatically generated by scheme2js, except for the | 1 // This file is automatically generated by scheme2js, except for the |
| 2 // benchmark harness code at the beginning and end of the file. | 2 // benchmark harness code at the beginning and end of the file. |
| 3 | 3 |
| 4 var EarleyBoyer = new BenchmarkSuite('EarleyBoyer', 666463, [ | 4 var EarleyBoyer = new BenchmarkSuite('EarleyBoyer', 666463, [ |
| 5 new Benchmark("Earley", function () { BgL_earleyzd2benchmarkzd2(); }), | 5 new Benchmark("Earley", function () { BgL_earleyzd2benchmarkzd2(); }), |
| 6 new Benchmark("Boyer", function () { BgL_nboyerzd2benchmarkzd2(); }) | 6 new Benchmark("Boyer", function () { BgL_nboyerzd2benchmarkzd2(); }) |
| 7 ]); | 7 ]); |
| 8 | 8 |
| 9 | 9 |
| 10 /************* GENERATED FILE - DO NOT EDIT *************/ | 10 /************* GENERATED FILE - DO NOT EDIT *************/ |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 /*** META ((export #t)) */ | 127 /*** META ((export #t)) */ |
| 128 function sc_rempropBang(sym, key) { | 128 function sc_rempropBang(sym, key) { |
| 129 var ht = sc_properties[sym]; | 129 var ht = sc_properties[sym]; |
| 130 if (ht) | 130 if (ht) |
| 131 delete ht[key]; | 131 delete ht[key]; |
| 132 } | 132 } |
| 133 | 133 |
| 134 /*** META ((export #t)) */ | 134 /*** META ((export #t)) */ |
| 135 function sc_any2String(o) { | 135 function sc_any2String(o) { |
| 136 return jsstring2string(sc_toDisplayString(o)); | 136 return jsstring2string(sc_toDisplayString(o)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 /*** META ((export #t) | 139 /*** META ((export #t) |
| 140 (peephole (infix 2 2 "===")) | 140 (peephole (infix 2 2 "===")) |
| 141 (type bool)) | 141 (type bool)) |
| 142 */ | 142 */ |
| 143 function sc_isEqv(o1, o2) { | 143 function sc_isEqv(o1, o2) { |
| 144 return (o1 === o2); | 144 return (o1 === o2); |
| 145 } | 145 } |
| 146 | 146 |
| 147 /*** META ((export #t) | 147 /*** META ((export #t) |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 } | 916 } |
| 917 | 917 |
| 918 function sc_dualAppendBang(l1, l2) { | 918 function sc_dualAppendBang(l1, l2) { |
| 919 if (l1 === null) return l2; | 919 if (l1 === null) return l2; |
| 920 if (l2 === null) return l1; | 920 if (l2 === null) return l1; |
| 921 var tmp = l1; | 921 var tmp = l1; |
| 922 while (tmp.cdr !== null) tmp=tmp.cdr; | 922 while (tmp.cdr !== null) tmp=tmp.cdr; |
| 923 tmp.cdr = l2; | 923 tmp.cdr = l2; |
| 924 return l1; | 924 return l1; |
| 925 } | 925 } |
| 926 | 926 |
| 927 /*** META ((export #t)) */ | 927 /*** META ((export #t)) */ |
| 928 function sc_appendBang() { | 928 function sc_appendBang() { |
| 929 var res = null; | 929 var res = null; |
| 930 for (var i = 0; i < arguments.length; i++) | 930 for (var i = 0; i < arguments.length; i++) |
| 931 res = sc_dualAppendBang(res, arguments[i]); | 931 res = sc_dualAppendBang(res, arguments[i]); |
| 932 return res; | 932 return res; |
| 933 } | 933 } |
| 934 | 934 |
| 935 /*** META ((export #t)) */ | 935 /*** META ((export #t)) */ |
| 936 function sc_reverse(l1) { | 936 function sc_reverse(l1) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 "can": "\030", | 1156 "can": "\030", |
| 1157 "em": "\031", | 1157 "em": "\031", |
| 1158 "sub": "\032", | 1158 "sub": "\032", |
| 1159 "esc": "\033", | 1159 "esc": "\033", |
| 1160 "fs": "\034", | 1160 "fs": "\034", |
| 1161 "gs": "\035", | 1161 "gs": "\035", |
| 1162 "rs": "\036", | 1162 "rs": "\036", |
| 1163 "us": "\037", | 1163 "us": "\037", |
| 1164 "sp": "\040", | 1164 "sp": "\040", |
| 1165 "del": "\177"}; | 1165 "del": "\177"}; |
| 1166 | 1166 |
| 1167 sc_Char.prototype.toString = function() { | 1167 sc_Char.prototype.toString = function() { |
| 1168 return this.val; | 1168 return this.val; |
| 1169 }; | 1169 }; |
| 1170 // sc_toDisplayString == toString | 1170 // sc_toDisplayString == toString |
| 1171 sc_Char.prototype.sc_toWriteString = function() { | 1171 sc_Char.prototype.sc_toWriteString = function() { |
| 1172 var entry = sc_Char.char2readable[this.val]; | 1172 var entry = sc_Char.char2readable[this.val]; |
| 1173 if (entry) | 1173 if (entry) |
| 1174 return entry; | 1174 return entry; |
| 1175 else | 1175 else |
| 1176 return "#\\" + this.val; | 1176 return "#\\" + this.val; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 while (l1 !== null) { | 1526 while (l1 !== null) { |
| 1527 var tmp = l1; | 1527 var tmp = l1; |
| 1528 for (var i = 0; i < nbApplyArgs; i++) { | 1528 for (var i = 0; i < nbApplyArgs; i++) { |
| 1529 applyArgs[i] = arguments[i + 1].car; | 1529 applyArgs[i] = arguments[i + 1].car; |
| 1530 arguments[i + 1] = arguments[i + 1].cdr; | 1530 arguments[i + 1] = arguments[i + 1].cdr; |
| 1531 } | 1531 } |
| 1532 tmp.car = proc.apply(null, applyArgs); | 1532 tmp.car = proc.apply(null, applyArgs); |
| 1533 } | 1533 } |
| 1534 return l1_orig; | 1534 return l1_orig; |
| 1535 } | 1535 } |
| 1536 | 1536 |
| 1537 /*** META ((export #t)) */ | 1537 /*** META ((export #t)) */ |
| 1538 function sc_forEach(proc, l1) { | 1538 function sc_forEach(proc, l1) { |
| 1539 if (l1 === undefined) | 1539 if (l1 === undefined) |
| 1540 return undefined; | 1540 return undefined; |
| 1541 // else | 1541 // else |
| 1542 var nbApplyArgs = arguments.length - 1; | 1542 var nbApplyArgs = arguments.length - 1; |
| 1543 var applyArgs = new Array(nbApplyArgs); | 1543 var applyArgs = new Array(nbApplyArgs); |
| 1544 while (l1 !== null) { | 1544 while (l1 !== null) { |
| 1545 for (var i = 0; i < nbApplyArgs; i++) { | 1545 for (var i = 0; i < nbApplyArgs; i++) { |
| 1546 applyArgs[i] = arguments[i + 1].car; | 1546 applyArgs[i] = arguments[i + 1].car; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1864 /*** META ((export new js-new) | 1864 /*** META ((export new js-new) |
| 1865 (peephole (jsNew))) | 1865 (peephole (jsNew))) |
| 1866 */ | 1866 */ |
| 1867 function sc_jsNew(c) { | 1867 function sc_jsNew(c) { |
| 1868 var evalStr = "new c("; | 1868 var evalStr = "new c("; |
| 1869 evalStr +=arguments.length > 1? "arguments[1]": ""; | 1869 evalStr +=arguments.length > 1? "arguments[1]": ""; |
| 1870 for (var i = 2; i < arguments.length; i++) | 1870 for (var i = 2; i < arguments.length; i++) |
| 1871 evalStr += ", arguments[" + i + "]"; | 1871 evalStr += ", arguments[" + i + "]"; |
| 1872 evalStr +=")"; | 1872 evalStr +=")"; |
| 1873 return eval(evalStr); | 1873 return eval(evalStr); |
| 1874 } | 1874 } |
| 1875 | 1875 |
| 1876 // ======================== RegExp ==================== | 1876 // ======================== RegExp ==================== |
| 1877 /*** META ((export #t)) */ | 1877 /*** META ((export #t)) */ |
| 1878 function sc_pregexp(re) { | 1878 function sc_pregexp(re) { |
| 1879 return new RegExp(sc_string2jsstring(re)); | 1879 return new RegExp(sc_string2jsstring(re)); |
| 1880 } | 1880 } |
| 1881 | 1881 |
| 1882 /*** META ((export #t)) */ | 1882 /*** META ((export #t)) */ |
| 1883 function sc_pregexpMatch(re, s) { | 1883 function sc_pregexpMatch(re, s) { |
| 1884 var reg = (re instanceof RegExp) ? re : sc_pregexp(re); | 1884 var reg = (re instanceof RegExp) ? re : sc_pregexp(re); |
| 1885 var tmp = reg.exec(sc_string2jsstring(s)); | 1885 var tmp = reg.exec(sc_string2jsstring(s)); |
| 1886 | 1886 |
| 1887 if (tmp == null) return false; | 1887 if (tmp == null) return false; |
| 1888 | 1888 |
| 1889 var res = null; | 1889 var res = null; |
| 1890 for (var i = tmp.length-1; i >= 0; i--) { | 1890 for (var i = tmp.length-1; i >= 0; i--) { |
| 1891 if (tmp[i] !== null) { | 1891 if (tmp[i] !== null) { |
| 1892 res = sc_cons(sc_jsstring2string(tmp[i]), res); | 1892 res = sc_cons(sc_jsstring2string(tmp[i]), res); |
| 1893 } else { | 1893 } else { |
| 1894 res = sc_cons(false, res); | 1894 res = sc_cons(false, res); |
| 1895 } | 1895 } |
| 1896 } | 1896 } |
| 1897 return res; | 1897 return res; |
| 1898 } | 1898 } |
| 1899 | 1899 |
| 1900 /*** META ((export #t)) */ | 1900 /*** META ((export #t)) */ |
| 1901 function sc_pregexpReplace(re, s1, s2) { | 1901 function sc_pregexpReplace(re, s1, s2) { |
| 1902 var reg; | 1902 var reg; |
| 1903 var jss1 = sc_string2jsstring(s1); | 1903 var jss1 = sc_string2jsstring(s1); |
| 1904 var jss2 = sc_string2jsstring(s2); | 1904 var jss2 = sc_string2jsstring(s2); |
| 1905 | 1905 |
| 1906 if (re instanceof RegExp) { | 1906 if (re instanceof RegExp) { |
| 1907 if (re.global) | 1907 if (re.global) |
| 1908 reg = re; | 1908 reg = re; |
| 1909 else | 1909 else |
| 1910 reg = new RegExp(re.source); | 1910 reg = new RegExp(re.source); |
| 1911 } else { | 1911 } else { |
| 1912 reg = new RegExp(sc_string2jsstring(re)); | 1912 reg = new RegExp(sc_string2jsstring(re)); |
| 1913 } | 1913 } |
| 1914 | 1914 |
| 1915 return jss1.replace(reg, jss2); | 1915 return jss1.replace(reg, jss2); |
| 1916 } | 1916 } |
| 1917 | 1917 |
| 1918 /*** META ((export pregexp-replace*)) */ | 1918 /*** META ((export pregexp-replace*)) */ |
| 1919 function sc_pregexpReplaceAll(re, s1, s2) { | 1919 function sc_pregexpReplaceAll(re, s1, s2) { |
| 1920 var reg; | 1920 var reg; |
| 1921 var jss1 = sc_string2jsstring(s1); | 1921 var jss1 = sc_string2jsstring(s1); |
| 1922 var jss2 = sc_string2jsstring(s2); | 1922 var jss2 = sc_string2jsstring(s2); |
| 1923 | 1923 |
| 1924 if (re instanceof RegExp) { | 1924 if (re instanceof RegExp) { |
| 1925 if (re.global) | 1925 if (re.global) |
| 1926 reg = re; | 1926 reg = re; |
| 1927 else | 1927 else |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1938 var reg = ((re instanceof RegExp) ? | 1938 var reg = ((re instanceof RegExp) ? |
| 1939 re : | 1939 re : |
| 1940 new RegExp(sc_string2jsstring(re))); | 1940 new RegExp(sc_string2jsstring(re))); |
| 1941 var jss = sc_string2jsstring(s); | 1941 var jss = sc_string2jsstring(s); |
| 1942 var tmp = jss.split(reg); | 1942 var tmp = jss.split(reg); |
| 1943 | 1943 |
| 1944 if (tmp == null) return false; | 1944 if (tmp == null) return false; |
| 1945 | 1945 |
| 1946 return sc_vector2list(tmp); | 1946 return sc_vector2list(tmp); |
| 1947 } | 1947 } |
| 1948 | 1948 |
| 1949 | 1949 |
| 1950 /* =========================================================================== *
/ | 1950 /* =========================================================================== *
/ |
| 1951 /* Other library stuff */ | 1951 /* Other library stuff */ |
| 1952 /* =========================================================================== *
/ | 1952 /* =========================================================================== *
/ |
| 1953 | 1953 |
| 1954 /*** META ((export #t) | 1954 /*** META ((export #t) |
| 1955 (peephole (hole 1 "Math.floor(Math.random()*" 'n ")"))) | 1955 (peephole (hole 1 "Math.floor(Math.random()*" 'n ")"))) |
| 1956 */ | 1956 */ |
| 1957 function sc_random(n) { | 1957 function sc_random(n) { |
| 1958 return Math.floor(Math.random()*n); | 1958 return Math.floor(Math.random()*n); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 /* .............. String port ..........................*/ | 2129 /* .............. String port ..........................*/ |
| 2130 function sc_ErrorInputPort() { | 2130 function sc_ErrorInputPort() { |
| 2131 }; | 2131 }; |
| 2132 sc_ErrorInputPort.prototype = new sc_InputPort(); | 2132 sc_ErrorInputPort.prototype = new sc_InputPort(); |
| 2133 sc_ErrorInputPort.prototype.getNextChar = function() { | 2133 sc_ErrorInputPort.prototype.getNextChar = function() { |
| 2134 throw "can't read from error-port."; | 2134 throw "can't read from error-port."; |
| 2135 }; | 2135 }; |
| 2136 sc_ErrorInputPort.prototype.isCharReady = function() { | 2136 sc_ErrorInputPort.prototype.isCharReady = function() { |
| 2137 return false; | 2137 return false; |
| 2138 }; | 2138 }; |
| 2139 | 2139 |
| 2140 | 2140 |
| 2141 /* .............. String port ..........................*/ | 2141 /* .............. String port ..........................*/ |
| 2142 | 2142 |
| 2143 function sc_StringInputPort(jsStr) { | 2143 function sc_StringInputPort(jsStr) { |
| 2144 // we are going to do some charAts on the str. | 2144 // we are going to do some charAts on the str. |
| 2145 // instead of recreating all the time a String-object, we | 2145 // instead of recreating all the time a String-object, we |
| 2146 // create one in the beginning. (not sure, if this is really an optim) | 2146 // create one in the beginning. (not sure, if this is really an optim) |
| 2147 this.str = new String(jsStr); | 2147 this.str = new String(jsStr); |
| 2148 this.pos = 0; | 2148 this.pos = 0; |
| 2149 } | 2149 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2193 this.peeked = newToken; | 2193 this.peeked = newToken; |
| 2194 return newToken; | 2194 return newToken; |
| 2195 }; | 2195 }; |
| 2196 sc_Tokenizer.prototype.readToken = function() { | 2196 sc_Tokenizer.prototype.readToken = function() { |
| 2197 var tmp = this.peekToken(); | 2197 var tmp = this.peekToken(); |
| 2198 delete this.peeked; | 2198 delete this.peeked; |
| 2199 return tmp; | 2199 return tmp; |
| 2200 }; | 2200 }; |
| 2201 sc_Tokenizer.prototype.nextToken = function() { | 2201 sc_Tokenizer.prototype.nextToken = function() { |
| 2202 var port = this.port; | 2202 var port = this.port; |
| 2203 | 2203 |
| 2204 function isNumberChar(c) { | 2204 function isNumberChar(c) { |
| 2205 return (c >= "0" && c <= "9"); | 2205 return (c >= "0" && c <= "9"); |
| 2206 }; | 2206 }; |
| 2207 function isIdOrNumberChar(c) { | 2207 function isIdOrNumberChar(c) { |
| 2208 return SC_ID_CLASS.indexOf(c) != -1 || // ID-char | 2208 return SC_ID_CLASS.indexOf(c) != -1 || // ID-char |
| 2209 (c >= "0" && c <= "9"); | 2209 (c >= "0" && c <= "9"); |
| 2210 } | 2210 } |
| 2211 function isWhitespace(c) { | 2211 function isWhitespace(c) { |
| 2212 return c === " " || c === "\r" || c === "\n" || c === "\t" || c === "\f"
; | 2212 return c === " " || c === "\r" || c === "\n" || c === "\t" || c === "\f"
; |
| 2213 }; | 2213 }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2273 }; | 2273 }; |
| 2274 function readIdOrNumber(firstChar) { | 2274 function readIdOrNumber(firstChar) { |
| 2275 var res = firstChar; | 2275 var res = firstChar; |
| 2276 while (isIdOrNumberChar(port.peekChar())) | 2276 while (isIdOrNumberChar(port.peekChar())) |
| 2277 res += port.readChar(); | 2277 res += port.readChar(); |
| 2278 if (isNaN(res)) | 2278 if (isNaN(res)) |
| 2279 return new sc_Token(9/*ID*/, res); | 2279 return new sc_Token(9/*ID*/, res); |
| 2280 else | 2280 else |
| 2281 return new sc_Token(12/*NUMBER*/, res - 0); | 2281 return new sc_Token(12/*NUMBER*/, res - 0); |
| 2282 }; | 2282 }; |
| 2283 | 2283 |
| 2284 function skipWhitespaceAndComments() { | 2284 function skipWhitespaceAndComments() { |
| 2285 var done = false; | 2285 var done = false; |
| 2286 while (!done) { | 2286 while (!done) { |
| 2287 done = true; | 2287 done = true; |
| 2288 while (isWhitespace(port.peekChar())) | 2288 while (isWhitespace(port.peekChar())) |
| 2289 port.readChar(); | 2289 port.readChar(); |
| 2290 if (port.peekChar() === ';') { | 2290 if (port.peekChar() === ';') { |
| 2291 port.readChar(); | 2291 port.readChar(); |
| 2292 done = false; | 2292 done = false; |
| 2293 while (true) { | 2293 while (true) { |
| 2294 curChar = port.readChar(); | 2294 curChar = port.readChar(); |
| 2295 if (curChar === SC_EOF_OBJECT || | 2295 if (curChar === SC_EOF_OBJECT || |
| 2296 curChar === '\n') | 2296 curChar === '\n') |
| 2297 break; | 2297 break; |
| 2298 } | 2298 } |
| 2299 } | 2299 } |
| 2300 } | 2300 } |
| 2301 }; | 2301 }; |
| 2302 | 2302 |
| 2303 function readDot() { | 2303 function readDot() { |
| 2304 if (isWhitespace(port.peekChar())) | 2304 if (isWhitespace(port.peekChar())) |
| 2305 return new sc_Token(10/*DOT*/); | 2305 return new sc_Token(10/*DOT*/); |
| 2306 else | 2306 else |
| 2307 return readIdOrNumber("."); | 2307 return readIdOrNumber("."); |
| 2308 }; | 2308 }; |
| 2309 | 2309 |
| 2310 function readSharp() { | 2310 function readSharp() { |
| 2311 var c = port.readChar(); | 2311 var c = port.readChar(); |
| 2312 if (isWhitespace(c)) | 2312 if (isWhitespace(c)) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2422 function readList(listBeginType) { | 2422 function readList(listBeginType) { |
| 2423 function matchesPeer(open, close) { | 2423 function matchesPeer(open, close) { |
| 2424 return open === 1/*OPEN_PAR*/ && close === 2/*CLOSE_PAR*/ | 2424 return open === 1/*OPEN_PAR*/ && close === 2/*CLOSE_PAR*/ |
| 2425 || open === 3/*OPEN_BRACE*/ && close === 4/*CLOSE_BRACE*/ | 2425 || open === 3/*OPEN_BRACE*/ && close === 4/*CLOSE_BRACE*/ |
| 2426 || open === 5/*OPEN_BRACKET*/ && close === 6/*CLOSE_BRACKET*/; | 2426 || open === 5/*OPEN_BRACKET*/ && close === 6/*CLOSE_BRACKET*/; |
| 2427 }; | 2427 }; |
| 2428 var res = null; | 2428 var res = null; |
| 2429 | 2429 |
| 2430 while (true) { | 2430 while (true) { |
| 2431 var token = tokenizer.peekToken(); | 2431 var token = tokenizer.peekToken(); |
| 2432 » | 2432 |
| 2433 switch (token.type) { | 2433 switch (token.type) { |
| 2434 case 2/*CLOSE_PAR*/: | 2434 case 2/*CLOSE_PAR*/: |
| 2435 case 4/*CLOSE_BRACE*/: | 2435 case 4/*CLOSE_BRACE*/: |
| 2436 case 6/*CLOSE_BRACKET*/: | 2436 case 6/*CLOSE_BRACKET*/: |
| 2437 if (matchesPeer(listBeginType, token.type)) { | 2437 if (matchesPeer(listBeginType, token.type)) { |
| 2438 tokenizer.readToken(); // consume token | 2438 tokenizer.readToken(); // consume token |
| 2439 return sc_reverseBang(res); | 2439 return sc_reverseBang(res); |
| 2440 } else | 2440 } else |
| 2441 throw "closing par doesn't match: " + listBeginType | 2441 throw "closing par doesn't match: " + listBeginType |
| 2442 + " " + listEndType; | 2442 + " " + listEndType; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 this.backref[nb] = tmp; | 2484 this.backref[nb] = tmp; |
| 2485 return tmp; | 2485 return tmp; |
| 2486 }; | 2486 }; |
| 2487 | 2487 |
| 2488 function readReference(nb) { | 2488 function readReference(nb) { |
| 2489 if (nb in this.backref) | 2489 if (nb in this.backref) |
| 2490 return this.backref[nb]; | 2490 return this.backref[nb]; |
| 2491 else | 2491 else |
| 2492 throw "bad reference: " + nb; | 2492 throw "bad reference: " + nb; |
| 2493 }; | 2493 }; |
| 2494 | 2494 |
| 2495 var tokenizer = this.tokenizer; | 2495 var tokenizer = this.tokenizer; |
| 2496 | 2496 |
| 2497 var token = tokenizer.readToken(); | 2497 var token = tokenizer.readToken(); |
| 2498 | 2498 |
| 2499 // handle error | 2499 // handle error |
| 2500 if (token.type === 13/*ERROR*/) | 2500 if (token.type === 13/*ERROR*/) |
| 2501 throw token.val; | 2501 throw token.val; |
| 2502 | 2502 |
| 2503 switch (token.type) { | 2503 switch (token.type) { |
| 2504 case 1/*OPEN_PAR*/: | 2504 case 1/*OPEN_PAR*/: |
| 2505 case 3/*OPEN_BRACE*/: | 2505 case 3/*OPEN_BRACE*/: |
| 2506 case 5/*OPEN_BRACKET*/: | 2506 case 5/*OPEN_BRACKET*/: |
| 2507 return readList.call(this, token.type); | 2507 return readList.call(this, token.type); |
| 2508 case 8/*QUOTE*/: | 2508 case 8/*QUOTE*/: |
| 2509 return readQuote.call(this); | 2509 return readQuote.call(this); |
| 2510 case 11/*STRING*/: | 2510 case 11/*STRING*/: |
| 2511 return sc_jsstring2string(token.val); | 2511 return sc_jsstring2string(token.val); |
| 2512 case 20/*CHAR*/: | 2512 case 20/*CHAR*/: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2543 port = SC_DEFAULT_IN; // THREAD: shared var... | 2543 port = SC_DEFAULT_IN; // THREAD: shared var... |
| 2544 var t = port.readChar(); | 2544 var t = port.readChar(); |
| 2545 return t === SC_EOF_OBJECT? t: new sc_Char(t); | 2545 return t === SC_EOF_OBJECT? t: new sc_Char(t); |
| 2546 } | 2546 } |
| 2547 /*** META ((export #t)) */ | 2547 /*** META ((export #t)) */ |
| 2548 function sc_peekChar(port) { | 2548 function sc_peekChar(port) { |
| 2549 if (port === undefined) // we assume the port hasn't been given. | 2549 if (port === undefined) // we assume the port hasn't been given. |
| 2550 port = SC_DEFAULT_IN; // THREAD: shared var... | 2550 port = SC_DEFAULT_IN; // THREAD: shared var... |
| 2551 var t = port.peekChar(); | 2551 var t = port.peekChar(); |
| 2552 return t === SC_EOF_OBJECT? t: new sc_Char(t); | 2552 return t === SC_EOF_OBJECT? t: new sc_Char(t); |
| 2553 } | 2553 } |
| 2554 /*** META ((export #t) | 2554 /*** META ((export #t) |
| 2555 (type bool)) | 2555 (type bool)) |
| 2556 */ | 2556 */ |
| 2557 function sc_isCharReady(port) { | 2557 function sc_isCharReady(port) { |
| 2558 if (port === undefined) // we assume the port hasn't been given. | 2558 if (port === undefined) // we assume the port hasn't been given. |
| 2559 port = SC_DEFAULT_IN; // THREAD: shared var... | 2559 port = SC_DEFAULT_IN; // THREAD: shared var... |
| 2560 return port.isCharReady(); | 2560 return port.isCharReady(); |
| 2561 } | 2561 } |
| 2562 /*** META ((export #t) | 2562 /*** META ((export #t) |
| 2563 (peephole (postfix ".close()"))) | 2563 (peephole (postfix ".close()"))) |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2715 this.res += s; | 2715 this.res += s; |
| 2716 } | 2716 } |
| 2717 sc_StringOutputPort.prototype.close = function() { | 2717 sc_StringOutputPort.prototype.close = function() { |
| 2718 return sc_jsstring2string(this.res); | 2718 return sc_jsstring2string(this.res); |
| 2719 } | 2719 } |
| 2720 | 2720 |
| 2721 /*** META ((export #t)) */ | 2721 /*** META ((export #t)) */ |
| 2722 function sc_getOutputString(sp) { | 2722 function sc_getOutputString(sp) { |
| 2723 return sc_jsstring2string(sp.res); | 2723 return sc_jsstring2string(sp.res); |
| 2724 } | 2724 } |
| 2725 | 2725 |
| 2726 | 2726 |
| 2727 function sc_ErrorOutputPort() { | 2727 function sc_ErrorOutputPort() { |
| 2728 } | 2728 } |
| 2729 sc_ErrorOutputPort.prototype = new sc_OutputPort(); | 2729 sc_ErrorOutputPort.prototype = new sc_OutputPort(); |
| 2730 sc_ErrorOutputPort.prototype.appendJSString = function(s) { | 2730 sc_ErrorOutputPort.prototype.appendJSString = function(s) { |
| 2731 throw "don't write on ErrorPort!"; | 2731 throw "don't write on ErrorPort!"; |
| 2732 } | 2732 } |
| 2733 sc_ErrorOutputPort.prototype.close = function() { | 2733 sc_ErrorOutputPort.prototype.close = function() { |
| 2734 /* do nothing */ | 2734 /* do nothing */ |
| 2735 } | 2735 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2845 } | 2845 } |
| 2846 | 2846 |
| 2847 /* ------------------ newline --------------------------------------------------
-*/ | 2847 /* ------------------ newline --------------------------------------------------
-*/ |
| 2848 | 2848 |
| 2849 /*** META ((export #t)) */ | 2849 /*** META ((export #t)) */ |
| 2850 function sc_newline(p) { | 2850 function sc_newline(p) { |
| 2851 if (p === undefined) // we assume not given | 2851 if (p === undefined) // we assume not given |
| 2852 p = SC_DEFAULT_OUT; | 2852 p = SC_DEFAULT_OUT; |
| 2853 p.appendJSString("\n"); | 2853 p.appendJSString("\n"); |
| 2854 } | 2854 } |
| 2855 | 2855 |
| 2856 /* ------------------ write-char -----------------------------------------------
----*/ | 2856 /* ------------------ write-char -----------------------------------------------
----*/ |
| 2857 | 2857 |
| 2858 /*** META ((export #t)) */ | 2858 /*** META ((export #t)) */ |
| 2859 function sc_writeChar(c, p) { | 2859 function sc_writeChar(c, p) { |
| 2860 if (p === undefined) // we assume not given | 2860 if (p === undefined) // we assume not given |
| 2861 p = SC_DEFAULT_OUT; | 2861 p = SC_DEFAULT_OUT; |
| 2862 p.appendJSString(c.val); | 2862 p.appendJSString(c.val); |
| 2863 } | 2863 } |
| 2864 | 2864 |
| 2865 /* ------------------ write-circle ---------------------------------------------
------*/ | 2865 /* ------------------ write-circle ---------------------------------------------
------*/ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2920 else | 2920 else |
| 2921 return '#' + nb + '#'; | 2921 return '#' + nb + '#'; |
| 2922 } | 2922 } |
| 2923 if (this[symb]-- === 0) { // if we are the last use. remove all fields. | 2923 if (this[symb]-- === 0) { // if we are the last use. remove all fields. |
| 2924 delete this[symb]; | 2924 delete this[symb]; |
| 2925 delete this[symb + "nb"]; | 2925 delete this[symb + "nb"]; |
| 2926 delete this[symb + "use"]; | 2926 delete this[symb + "use"]; |
| 2927 } | 2927 } |
| 2928 | 2928 |
| 2929 var res = ""; | 2929 var res = ""; |
| 2930 | 2930 |
| 2931 if (this[symb] !== undefined) { // implies > 0 | 2931 if (this[symb] !== undefined) { // implies > 0 |
| 2932 this[symb + "use"] = true; | 2932 this[symb + "use"] = true; |
| 2933 if (inList) | 2933 if (inList) |
| 2934 res += '. #' + this[symb + "nb"] + '='; | 2934 res += '. #' + this[symb + "nb"] + '='; |
| 2935 else | 2935 else |
| 2936 res += '#' + this[symb + "nb"] + '='; | 2936 res += '#' + this[symb + "nb"] + '='; |
| 2937 inList = false; | 2937 inList = false; |
| 2938 } | 2938 } |
| 2939 | 2939 |
| 2940 if (!inList) | 2940 if (!inList) |
| 2941 res += "("; | 2941 res += "("; |
| 2942 | 2942 |
| 2943 // print car | 2943 // print car |
| 2944 res += sc_genToWriteCircleString(this.car, symb); | 2944 res += sc_genToWriteCircleString(this.car, symb); |
| 2945 | 2945 |
| 2946 if (sc_isPair(this.cdr)) { | 2946 if (sc_isPair(this.cdr)) { |
| 2947 res += " " + this.cdr.sc_toWriteCircleString(symb, true); | 2947 res += " " + this.cdr.sc_toWriteCircleString(symb, true); |
| 2948 } else if (this.cdr !== null) { | 2948 } else if (this.cdr !== null) { |
| 2949 res += " . " + sc_genToWriteCircleString(this.cdr, symb); | 2949 res += " . " + sc_genToWriteCircleString(this.cdr, symb); |
| 2950 } | 2950 } |
| 2951 if (!inList) | 2951 if (!inList) |
| 2952 res += ")"; | 2952 res += ")"; |
| 2953 return res; | 2953 return res; |
| 2954 }; | 2954 }; |
| 2955 sc_Vector.prototype.sc_toWriteCircleString = function(symb) { | 2955 sc_Vector.prototype.sc_toWriteCircleString = function(symb) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3065 p.appendJSString(arguments[j].toString(8)); | 3065 p.appendJSString(arguments[j].toString(8)); |
| 3066 i += 2; j++; | 3066 i += 2; j++; |
| 3067 break; | 3067 break; |
| 3068 | 3068 |
| 3069 case 66: | 3069 case 66: |
| 3070 case 98: | 3070 case 98: |
| 3071 // b | 3071 // b |
| 3072 p.appendJSString(arguments[j].toString(2)); | 3072 p.appendJSString(arguments[j].toString(2)); |
| 3073 i += 2; j++; | 3073 i += 2; j++; |
| 3074 break; | 3074 break; |
| 3075 » | 3075 |
| 3076 case 37: | 3076 case 37: |
| 3077 case 110: | 3077 case 110: |
| 3078 // %, n | 3078 // %, n |
| 3079 p.appendJSString("\n"); | 3079 p.appendJSString("\n"); |
| 3080 i += 2; break; | 3080 i += 2; break; |
| 3081 | 3081 |
| 3082 case 114: | 3082 case 114: |
| 3083 // r | 3083 // r |
| 3084 p.appendJSString("\r"); | 3084 p.appendJSString("\r"); |
| 3085 i += 2; break; | 3085 i += 2; break; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3179 (sc_isPair(o1) && sc_isPair(o2) | 3179 (sc_isPair(o1) && sc_isPair(o2) |
| 3180 && sc_isPairEqual(o1, o2, sc_isEqual)) || | 3180 && sc_isPairEqual(o1, o2, sc_isEqual)) || |
| 3181 (sc_isVector(o1) && sc_isVector(o2) | 3181 (sc_isVector(o1) && sc_isVector(o2) |
| 3182 && sc_isVectorEqual(o1, o2, sc_isEqual))); | 3182 && sc_isVectorEqual(o1, o2, sc_isEqual))); |
| 3183 } | 3183 } |
| 3184 | 3184 |
| 3185 /*** META ((export number->symbol integer->symbol)) */ | 3185 /*** META ((export number->symbol integer->symbol)) */ |
| 3186 function sc_number2symbol(x, radix) { | 3186 function sc_number2symbol(x, radix) { |
| 3187 return sc_SYMBOL_PREFIX + sc_number2jsstring(x, radix); | 3187 return sc_SYMBOL_PREFIX + sc_number2jsstring(x, radix); |
| 3188 } | 3188 } |
| 3189 | 3189 |
| 3190 /*** META ((export number->string integer->string)) */ | 3190 /*** META ((export number->string integer->string)) */ |
| 3191 var sc_number2string = sc_number2jsstring; | 3191 var sc_number2string = sc_number2jsstring; |
| 3192 | 3192 |
| 3193 /*** META ((export #t)) */ | 3193 /*** META ((export #t)) */ |
| 3194 function sc_symbol2number(s, radix) { | 3194 function sc_symbol2number(s, radix) { |
| 3195 return sc_jsstring2number(s.slice(1), radix); | 3195 return sc_jsstring2number(s.slice(1), radix); |
| 3196 } | 3196 } |
| 3197 | 3197 |
| 3198 /*** META ((export #t)) */ | 3198 /*** META ((export #t)) */ |
| 3199 var sc_string2number = sc_jsstring2number; | 3199 var sc_string2number = sc_jsstring2number; |
| (...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4675 function RunBenchmark(name, count, run, warn) { | 4675 function RunBenchmark(name, count, run, warn) { |
| 4676 for (var n = 0; n < count; ++n) { | 4676 for (var n = 0; n < count; ++n) { |
| 4677 result = run(); | 4677 result = run(); |
| 4678 if (!warn(result)) { | 4678 if (!warn(result)) { |
| 4679 throw new Error("Earley or Boyer did incorrect number of rewrites"); | 4679 throw new Error("Earley or Boyer did incorrect number of rewrites"); |
| 4680 } | 4680 } |
| 4681 } | 4681 } |
| 4682 } | 4682 } |
| 4683 | 4683 |
| 4684 var BgL_runzd2benchmarkzd2 = RunBenchmark; | 4684 var BgL_runzd2benchmarkzd2 = RunBenchmark; |
| OLD | NEW |