From d8b4d7136974e668f95d883ee9a4295738decc1d Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Thu, 17 Jul 2014 00:42:20 -0700 Subject: [PATCH] fix long constants --- classfile/classfile.js | 2 +- classfile/reader.js | 7 ------- tests/TestLong.java | 7 ++++++- tests/TestOps.java | 5 +++++ vm.js | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/classfile/classfile.js b/classfile/classfile.js index 6b2a94f8..f2f818a4 100644 --- a/classfile/classfile.js +++ b/classfile/classfile.js @@ -142,7 +142,7 @@ var getClassImage = function(classBytes) { ++i; break; case TAGS.CONSTANT_Long: - classImage.constant_pool.push({ tag: tag, bits: reader.readLong() }); + classImage.constant_pool.push({ tag: tag, highBits: reader.readInteger(), lowBits: reader.readInteger() }); classImage.constant_pool.push(null); ++i; break; diff --git a/classfile/reader.js b/classfile/reader.js index d9e6c4b0..14b55811 100644 --- a/classfile/reader.js +++ b/classfile/reader.js @@ -42,13 +42,6 @@ Reader.prototype.readFloat = function() { return data; } -Reader.prototype.readLong = function() { - var data = new Int32Array(2); - data[0] = this.readInteger(); - data[1] = this.readInteger(); - return data; -} - Reader.prototype.readDouble = function() { var data = this.bytes.getFloat64(this.offset, false); this.offset += 8; diff --git a/tests/TestLong.java b/tests/TestLong.java index 5ffb54e4..ca2ddf94 100644 --- a/tests/TestLong.java +++ b/tests/TestLong.java @@ -3,7 +3,12 @@ package tests; public class TestLong { static long a = 0x0123456789abcdefL; + public static long x(long a, long b) { + return a + b; + } + public static void main(String[] args) { - System.out.println(0x12345678); + if (x(1L, 2L) == 3L) + System.out.println("OK"); } } diff --git a/tests/TestOps.java b/tests/TestOps.java index a8902df4..865a3fb2 100644 --- a/tests/TestOps.java +++ b/tests/TestOps.java @@ -41,6 +41,10 @@ public class TestOps { return a % b; } + static long ladd(long a, long b) { + return a + b; + } + public static void main(String[] args) { Assert("Do asserts work", true); Assert("add two ints", iadd(1, 2) == 3); @@ -55,5 +59,6 @@ public class TestOps { Assert("float neg", fneg(1.0f) == -1.0f); Assert("float mul", fmul(2.0f, 3.0f) == 6.0f); Assert("float div", fdiv(6.0f, 2.0f) == 3.0f); + Assert("long add", ladd(1L, 2L) == 3L); } } diff --git a/vm.js b/vm.js index 954a3be6..5f9e6d1b 100644 --- a/vm.js +++ b/vm.js @@ -77,7 +77,7 @@ VM.execute = function(frame) { var constant = cp[frame.read16()]; switch(constant.tag) { case TAGS.CONSTANT_Long: - stack.push2(Long.fromBits(constant.bits[0], constant.bits[1])); + stack.push2(Long.fromBits(constant.lowBits, constant.highBits)); break; case TAGS.CONSTANT_Double: stack.push2(constant.double);