diff options
| author | Andy Moreton | 2018-08-04 10:28:13 -0600 |
|---|---|---|
| committer | Tom Tromey | 2018-08-04 10:28:13 -0600 |
| commit | bc8ff54efee05f4a2769be32046866ed1e152b41 (patch) | |
| tree | c6dac43f3b9abfc6bde54a9d245c04e5dbb360d5 /test | |
| parent | 76715f8921dca740880cd22c644a6328cd810846 (diff) | |
| download | emacs-bc8ff54efee05f4a2769be32046866ed1e152b41.tar.gz emacs-bc8ff54efee05f4a2769be32046866ed1e152b41.zip | |
Make bignums work better when EMACS_INT is larger than long
* lisp/international/ccl.el (ccl-fixnum): New function.
(ccl-embed-data, ccl-embed-current-address, ccl-dump): Use it.
* src/alloc.c (make_number): Handle case where EMACS_INT is
larger than long.
* src/data.c (bignumcompare): Handle case where EMACS_INT is
larger than long.
(arith_driver): Likewise. Coerce markers.
(float_arith_driver): Coerce markers.
(Flogcount): Use mpz_sgn.
(ash_lsh_impl): Fix bugs.
(Fsub1): Fix underflow check.
* src/lisp.h (NUMBERP): Don't check BIGNUMP.
(CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER): Fix indentation.
* test/lisp/international/ccl-tests.el: New file.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/international/ccl-tests.el | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/test/lisp/international/ccl-tests.el b/test/lisp/international/ccl-tests.el new file mode 100644 index 00000000000..d0c254ce91b --- /dev/null +++ b/test/lisp/international/ccl-tests.el | |||
| @@ -0,0 +1,219 @@ | |||
| 1 | (require 'ert) | ||
| 2 | (require 'ccl) | ||
| 3 | (require 'seq) | ||
| 4 | |||
| 5 | |||
| 6 | (ert-deftest shift () | ||
| 7 | ;; shift left +ve 5628 #x00000000000015fc | ||
| 8 | (should (= (ash 5628 8) 1440768)) ; #x000000000015fc00 | ||
| 9 | (should (= (lsh 5628 8) 1440768)) ; #x000000000015fc00 | ||
| 10 | |||
| 11 | ;; shift left -ve -5628 #x3fffffffffffea04 | ||
| 12 | (should (= (ash -5628 8) -1440768)) ; #x3fffffffffea0400 | ||
| 13 | (should (= (lsh -5628 8) -1440768)) ; #x3fffffffffea0400 | ||
| 14 | |||
| 15 | ;; shift right +ve 5628 #x00000000000015fc | ||
| 16 | (should (= (ash 5628 -8) 21)) ; #x0000000000000015 | ||
| 17 | (should (= (lsh 5628 -8) 21)) ; #x0000000000000015 | ||
| 18 | |||
| 19 | ;; shift right -ve -5628 #x3fffffffffffea04 | ||
| 20 | (should (= (ash -5628 -8) -22)) ; #x3fffffffffffffea | ||
| 21 | |||
| 22 | ;; shift right -5628 #x3fffffffffffea04 | ||
| 23 | (cond | ||
| 24 | ((fboundp 'bignump) | ||
| 25 | (should (= (lsh -5628 -8) -22))) ; #x3fffffffffffffea bignum | ||
| 26 | ((= (logb most-negative-fixnum) 61) | ||
| 27 | (should (= (lsh -5628 -8) | ||
| 28 | (string-to-number | ||
| 29 | "18014398509481962")))) ; #x003fffffffffffea master (64bit) | ||
| 30 | ((= (logb most-negative-fixnum) 29) | ||
| 31 | (should (= (lsh -5628 -8) 4194282))) ; #x003fffea master (32bit) | ||
| 32 | )) | ||
| 33 | |||
| 34 | ;; CCl program from `pgg-parse-crc24' in lisp/obsolete/pgg-parse.el | ||
| 35 | (defconst prog-pgg-source | ||
| 36 | '(1 | ||
| 37 | ((loop | ||
| 38 | (read r0) (r1 ^= r0) (r2 ^= 0) | ||
| 39 | (r5 = 0) | ||
| 40 | (loop | ||
| 41 | (r1 <<= 1) | ||
| 42 | (r1 += ((r2 >> 15) & 1)) | ||
| 43 | (r2 <<= 1) | ||
| 44 | (if (r1 & 256) | ||
| 45 | ((r1 ^= 390) (r2 ^= 19707))) | ||
| 46 | (if (r5 < 7) | ||
| 47 | ((r5 += 1) | ||
| 48 | (repeat)))) | ||
| 49 | (repeat))))) | ||
| 50 | |||
| 51 | (defconst prog-pgg-code | ||
| 52 | [1 30 14 114744 114775 0 161 131127 1 148217 15 82167 | ||
| 53 | 1 1848 131159 1 1595 5 256 114743 390 114775 19707 | ||
| 54 | 1467 16 7 183 1 -5628 -7164 22]) | ||
| 55 | |||
| 56 | (defconst prog-pgg-dump | ||
| 57 | "Out-buffer must be as large as in-buffer. | ||
| 58 | Main-body: | ||
| 59 | 2:[read-register] read r0 (0 remaining) | ||
| 60 | 3:[set-assign-expr-register] r1 ^= r0 | ||
| 61 | 4:[set-assign-expr-const] r2 ^= 0 | ||
| 62 | 6:[set-short-const] r5 = 0 | ||
| 63 | 7:[set-assign-expr-const] r1 <<= 1 | ||
| 64 | 9:[set-expr-const] r7 = r2 >> 15 | ||
| 65 | 11:[set-assign-expr-const] r7 &= 1 | ||
| 66 | 13:[set-assign-expr-register] r1 += r7 | ||
| 67 | 14:[set-assign-expr-const] r2 <<= 1 | ||
| 68 | 16:[jump-cond-expr-const] if !(r1 & 256), jump to 23(+7) | ||
| 69 | 19:[set-assign-expr-const] r1 ^= 390 | ||
| 70 | 21:[set-assign-expr-const] r2 ^= 19707 | ||
| 71 | 23:[jump-cond-expr-const] if !(r5 < 7), jump to 29(+6) | ||
| 72 | 26:[set-assign-expr-const] r5 += 1 | ||
| 73 | 28:[jump] jump to 7(-21) | ||
| 74 | 29:[jump] jump to 2(-27) | ||
| 75 | At EOF: | ||
| 76 | 30:[end] end | ||
| 77 | ") | ||
| 78 | |||
| 79 | (ert-deftest ccl-compile-pgg () | ||
| 80 | (should (equal (ccl-compile prog-pgg-source) prog-pgg-code))) | ||
| 81 | |||
| 82 | (ert-deftest ccl-dump-pgg () | ||
| 83 | (with-temp-buffer | ||
| 84 | (ccl-dump prog-pgg-code) | ||
| 85 | (should (equal (buffer-string) prog-pgg-dump)))) | ||
| 86 | |||
| 87 | (ert-deftest pgg-parse-crc24 () | ||
| 88 | ;; Compiler | ||
| 89 | (require 'pgg) | ||
| 90 | (should (equal pgg-parse-crc24 prog-pgg-code)) | ||
| 91 | ;; Interpreter | ||
| 92 | (should (equal (pgg-parse-crc24-string "foo") (concat [#x4f #xc2 #x55]))) | ||
| 93 | (should (equal (pgg-parse-crc24-string "bar") (concat [#x51 #xd9 #x53]))) | ||
| 94 | (should (equal (pgg-parse-crc24-string "baz") (concat [#xf0 #x58 #x6a])))) | ||
| 95 | |||
| 96 | (ert-deftest pgg-parse-crc24-dump () | ||
| 97 | ;; Disassembler | ||
| 98 | (require 'pgg) | ||
| 99 | (with-temp-buffer | ||
| 100 | (ccl-dump pgg-parse-crc24) | ||
| 101 | (should (equal (buffer-string) prog-pgg-dump)))) | ||
| 102 | |||
| 103 | ;;---------------------------------------------------------------------------- | ||
| 104 | ;; Program from 'midikbd-decoder in midi-kbd-0.2.el GNU ELPA package | ||
| 105 | (defconst prog-midi-source | ||
| 106 | '(2 | ||
| 107 | (loop | ||
| 108 | (loop | ||
| 109 | ;; central message receiver loop here. | ||
| 110 | ;; When it exits, the command to deal with is in r0 | ||
| 111 | ;; Any arguments are in r1 and r2 | ||
| 112 | ;; r3 contains: 0 if no arguments are accepted | ||
| 113 | ;; 1 if 1 argument can be accepted | ||
| 114 | ;; 2 if 2 arguments can be accepted | ||
| 115 | ;; 3 if the first of two arguments has been accepted | ||
| 116 | ;; Arguments are read into r1 and r2. | ||
| 117 | ;; r4 contains the current running status byte if any. | ||
| 118 | (read-if (r0 < #x80) | ||
| 119 | (branch r3 | ||
| 120 | (repeat) | ||
| 121 | ((r1 = r0) (r0 = r4) (break)) | ||
| 122 | ((r1 = r0) (r3 = 3) (repeat)) | ||
| 123 | ((r2 = r0) (r3 = 2) (r0 = r4) (break)))) | ||
| 124 | (if (r0 >= #xf8) ; real time message | ||
| 125 | (break)) | ||
| 126 | (if (r0 < #xf0) ; channel command | ||
| 127 | ((r4 = r0) | ||
| 128 | (if ((r0 & #xe0) == #xc0) | ||
| 129 | ;; program change and channel pressure take only 1 argument | ||
| 130 | (r3 = 1) | ||
| 131 | (r3 = 2)) | ||
| 132 | (repeat))) | ||
| 133 | ;; system common message, we swallow those for now | ||
| 134 | (r3 = 0) | ||
| 135 | (repeat)) | ||
| 136 | (if ((r0 & #xf0) == #x90) | ||
| 137 | (if (r2 == 0) ; Some Midi devices use velocity 0 | ||
| 138 | ; for switching notes off, | ||
| 139 | ; so translate into note-off | ||
| 140 | ; and fall through | ||
| 141 | (r0 -= #x10) | ||
| 142 | ((r0 &= #xf) | ||
| 143 | (write 0) | ||
| 144 | (write r0 r1 r2) | ||
| 145 | (repeat)))) | ||
| 146 | (if ((r0 & #xf0) == #x80) | ||
| 147 | ((r0 &= #xf) | ||
| 148 | (write 1) | ||
| 149 | (write r0 r1 r2) | ||
| 150 | (repeat))) | ||
| 151 | (repeat)))) | ||
| 152 | |||
| 153 | (defconst prog-midi-code | ||
| 154 | [2 72 4893 16 128 1133 5 6 9 12 16 -2556 32 1024 6660 32 865 | ||
| 155 | -4092 64 609 1024 4868 795 20 248 3844 3099 16 240 128 82169 | ||
| 156 | 224 1275 18 192 353 260 609 -9468 97 -9980 82169 240 4091 | ||
| 157 | 18 144 1371 18 0 16407 16 1796 81943 15 20 529 305 81 -14588 | ||
| 158 | 82169 240 2555 18 128 81943 15 276 529 305 81 -17660 -17916 22]) | ||
| 159 | |||
| 160 | (defconst prog-midi-dump | ||
| 161 | "Out-buffer must be 2 times bigger than in-buffer. | ||
| 162 | Main-body: | ||
| 163 | 2:[read-jump-cond-expr-const] read r0, if !(r0 < 128), jump to 22(+20) | ||
| 164 | 5:[branch] jump to array[r3] of length 4 | ||
| 165 | 11 12 15 18 22 | ||
| 166 | 11:[jump] jump to 2(-9) | ||
| 167 | 12:[set-register] r1 = r0 | ||
| 168 | 13:[set-register] r0 = r4 | ||
| 169 | 14:[jump] jump to 41(+27) | ||
| 170 | 15:[set-register] r1 = r0 | ||
| 171 | 16:[set-short-const] r3 = 3 | ||
| 172 | 17:[jump] jump to 2(-15) | ||
| 173 | 18:[set-register] r2 = r0 | ||
| 174 | 19:[set-short-const] r3 = 2 | ||
| 175 | 20:[set-register] r0 = r4 | ||
| 176 | 21:[jump] jump to 41(+20) | ||
| 177 | 22:[jump-cond-expr-const] if !(r0 >= 248), jump to 26(+4) | ||
| 178 | 25:[jump] jump to 41(+16) | ||
| 179 | 26:[jump-cond-expr-const] if !(r0 < 240), jump to 39(+13) | ||
| 180 | 29:[set-register] r4 = r0 | ||
| 181 | 30:[set-expr-const] r7 = r0 & 224 | ||
| 182 | 32:[jump-cond-expr-const] if !(r7 == 192), jump to 37(+5) | ||
| 183 | 35:[set-short-const] r3 = 1 | ||
| 184 | 36:[jump] jump to 38(+2) | ||
| 185 | 37:[set-short-const] r3 = 2 | ||
| 186 | 38:[jump] jump to 2(-36) | ||
| 187 | 39:[set-short-const] r3 = 0 | ||
| 188 | 40:[jump] jump to 2(-38) | ||
| 189 | 41:[set-expr-const] r7 = r0 & 240 | ||
| 190 | 43:[jump-cond-expr-const] if !(r7 == 144), jump to 59(+16) | ||
| 191 | 46:[jump-cond-expr-const] if !(r2 == 0), jump to 52(+6) | ||
| 192 | 49:[set-assign-expr-const] r0 -= 16 | ||
| 193 | 51:[jump] jump to 59(+8) | ||
| 194 | 52:[set-assign-expr-const] r0 &= 15 | ||
| 195 | 54:[write-const-string] write char \"\x00\" | ||
| 196 | 55:[write-register] write r0 (2 remaining) | ||
| 197 | 56:[write-register] write r1 (1 remaining) | ||
| 198 | 57:[write-register] write r2 (0 remaining) | ||
| 199 | 58:[jump] jump to 2(-56) | ||
| 200 | 59:[set-expr-const] r7 = r0 & 240 | ||
| 201 | 61:[jump-cond-expr-const] if !(r7 == 128), jump to 71(+10) | ||
| 202 | 64:[set-assign-expr-const] r0 &= 15 | ||
| 203 | 66:[write-const-string] write char \"\x01\" | ||
| 204 | 67:[write-register] write r0 (2 remaining) | ||
| 205 | 68:[write-register] write r1 (1 remaining) | ||
| 206 | 69:[write-register] write r2 (0 remaining) | ||
| 207 | 70:[jump] jump to 2(-68) | ||
| 208 | 71:[jump] jump to 2(-69) | ||
| 209 | At EOF: | ||
| 210 | 72:[end] end | ||
| 211 | ") | ||
| 212 | |||
| 213 | (ert-deftest ccl-compile-midi () | ||
| 214 | (should (equal (ccl-compile prog-midi-source) prog-midi-code))) | ||
| 215 | |||
| 216 | (ert-deftest ccl-dump-midi () | ||
| 217 | (with-temp-buffer | ||
| 218 | (ccl-dump prog-midi-code) | ||
| 219 | (should (equal (buffer-string) prog-midi-dump)))) | ||