|
16 | 16 |
|
17 | 17 | import { Tag, utf8 } from "./classfile.ts"; |
18 | 18 | import { |
19 | | - ACC_FINAL, INITIALIZED, JArray, JClass, JField, JMethod, JObject, isWide, newArrayData, parseMethodDesc, |
| 19 | + ACC_FINAL, INITIALIZED, JArray, JClass, JField, JMethod, JObject, isWide, longToFloat, newArrayData, parseMethodDesc, |
20 | 20 | } from "./runtime.ts"; |
21 | 21 | import { memberTarget } from "./natives/invoke.ts"; |
22 | 22 | import { concatStrings } from "./natives/strings.ts"; |
@@ -223,6 +223,7 @@ const runtime = { |
223 | 223 | }, |
224 | 224 | PUSHED, |
225 | 225 | INTERPRET, |
| 226 | + longToFloat, |
226 | 227 | npe: npeAt, |
227 | 228 | arr(o: JArray | null, i: number, pc?: number): any { |
228 | 229 | if (o === null) throw at(new PendingThrow("java/lang/NullPointerException"), pc); |
@@ -744,9 +745,12 @@ function insn(g: Gen, b: Body, pc: number) { |
744 | 745 | case 0x43: case 0x44: case 0x45: case 0x46: emit(`${L(op - 0x43)}=${top()};`); break; |
745 | 746 | case 0x47: case 0x48: case 0x49: case 0x4a: emit(`${L(op - 0x47)}=${top(1)};`); break; |
746 | 747 | case 0x4b: case 0x4c: case 0x4d: case 0x4e: emit(`${L(op - 0x4b)}=${top()};`); break; |
747 | | - case 0x4f: case 0x51: case 0x54: case 0x55: case 0x56: |
| 748 | + case 0x4f: case 0x51: case 0x55: case 0x56: |
748 | 749 | emit(`if(${top(2)}===null)rt.npe(${pc});a=${top(2)}.a;if(${top(1)}>>>0>=a.length)rt.arr(${top(2)},${top(1)},${pc});a[${top(1)}]=${top()};`); |
749 | 750 | break; |
| 751 | + case 0x54: |
| 752 | + emit(`if(${top(2)}===null)rt.npe(${pc});a=${top(2)}.a;if(${top(1)}>>>0>=a.length)rt.arr(${top(2)},${top(1)},${pc});a[${top(1)}]=${top(2)}.cls.name==="[Z"?${top()}&1:${top()};`); |
| 753 | + break; |
750 | 754 | case 0x50: case 0x52: |
751 | 755 | emit(`if(${top(3)}===null)rt.npe(${pc});a=${top(3)}.a;if(${top(2)}>>>0>=a.length)rt.arr(${top(3)},${top(2)},${pc});a[${top(2)}]=${top(1)};`); |
752 | 756 | break; |
@@ -800,7 +804,7 @@ function insn(g: Gen, b: Body, pc: number) { |
800 | 804 | case 0x86: emit(`${top()}=Math.fround(${top()});`); break; |
801 | 805 | case 0x87: break; |
802 | 806 | case 0x88: emit(`${top(1)}=Number(BigInt.asIntN(32,${top(1)}));`); break; |
803 | | - case 0x89: emit(`${top(1)}=Math.fround(Number(${top(1)}));`); break; |
| 807 | + case 0x89: emit(`${top(1)}=rt.longToFloat(${top(1)});`); break; |
804 | 808 | case 0x8a: emit(`${top(1)}=Number(${top(1)});`); break; |
805 | 809 | case 0x8b: emit(`${top()}=rt.f2i(${top()});`); break; |
806 | 810 | case 0x8c: emit(`${top()}=rt.f2l(${top()});`); break; |
@@ -1039,7 +1043,7 @@ const BINARY: Record<number, (a: string, b: string) => string> = { |
1039 | 1043 | const UNARY: Record<number, (a: string) => string> = { |
1040 | 1044 | 0x74: (a) => `((-${a})|0)`, 0x75: (a) => `BigInt.asIntN(64,-${a})`, 0x76: (a) => `(-${a})`, 0x77: (a) => `(-${a})`, |
1041 | 1045 | 0x85: (a) => `BigInt(${a})`, 0x86: (a) => `Math.fround(${a})`, 0x87: (a) => a, 0x88: (a) => `Number(BigInt.asIntN(32,${a}))`, |
1042 | | - 0x89: (a) => `Math.fround(Number(${a}))`, 0x8a: (a) => `Number(${a})`, 0x8b: (a) => `rt.f2i(${a})`, 0x8c: (a) => `rt.f2l(${a})`, |
| 1046 | + 0x89: (a) => `rt.longToFloat(${a})`, 0x8a: (a) => `Number(${a})`, 0x8b: (a) => `rt.f2i(${a})`, 0x8c: (a) => `rt.f2l(${a})`, |
1043 | 1047 | 0x8d: (a) => a, 0x8e: (a) => `rt.f2i(${a})`, 0x8f: (a) => `rt.f2l(${a})`, 0x90: (a) => `Math.fround(${a})`, |
1044 | 1048 | 0x91: (a) => `((${a}<<24)>>24)`, 0x92: (a) => `(${a}&65535)`, 0x93: (a) => `((${a}<<16)>>16)`, |
1045 | 1049 | }; |
|
0 commit comments