Floating point calculations probably resolved
This commit is contained in:
parent
f0049c7725
commit
0bbad6a57f
26
src/attributes.jsh
Normal file
26
src/attributes.jsh
Normal file
@ -0,0 +1,26 @@
|
||||
/* -*- Mode: Javascript -*-
|
||||
* -*- coding: UTF-8 -*-
|
||||
* Copyright (C) 2011 by Artur Ventura
|
||||
*
|
||||
* File: cpu.js
|
||||
* Time-stamp: Fri Jul 15 02:46:27 2011
|
||||
*
|
||||
* Author: Artur Ventura
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ATTRIBUTES_JSH_
|
||||
#define _ATTRIBUTES_JSH_
|
||||
|
||||
#define ATTR_UNKOWNATTR 0
|
||||
#define ATTR_CONSTANT_VALUE 1
|
||||
#define ATTR_CODE 2
|
||||
#define ATTR_EXCEPTIONS 3
|
||||
#define ATTR_INNER_CLASSES 4
|
||||
#define ATTR_SYNTHETIC 5
|
||||
#define ATTR_SOURCE_FILE 6
|
||||
#define ATTR_LINE_NUMBER_TABLE 7
|
||||
#define ATTR_LOCAL_VARIABLE_TABLE 8
|
||||
#define ATTR_DEPRECATED 9
|
||||
|
||||
#endif // _ATTRIBUTES_JSH_
|
@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
#include "constantPool.jsh"
|
||||
#include "cpu.jsh"
|
||||
|
||||
/** @constructor */
|
||||
var constUtf8 = function(){
|
||||
@ -52,7 +53,7 @@ var constInt = function(){
|
||||
this.value = null;
|
||||
this.id = CONSTANT_Integer;
|
||||
this.read = function ( dStream ){
|
||||
this.value = dStream.getU4();
|
||||
this.value = dStream.getInt32();
|
||||
}
|
||||
};
|
||||
|
||||
@ -61,7 +62,7 @@ var constFloat = function(){
|
||||
this.value = null;
|
||||
this.id = CONSTANT_Float;
|
||||
this.read = function ( dStream ){
|
||||
this.value = dStream.getU4();
|
||||
this.value = dStream.getFloat32();
|
||||
}
|
||||
};
|
||||
|
||||
@ -71,8 +72,7 @@ var constLong = function(){
|
||||
this.low = null;
|
||||
this.id = CONSTANT_Long;
|
||||
this.read = function (dStream){
|
||||
this.high = dStream.getU4();
|
||||
this.low = dStream.getU4();
|
||||
this.value = dStream.getInt64();
|
||||
}
|
||||
};
|
||||
|
||||
@ -82,8 +82,32 @@ var constDouble = function(){
|
||||
this.low = null;
|
||||
this.id = CONSTANT_Double;
|
||||
this.read = function (dStream){
|
||||
this.high = dStream.getU4();
|
||||
this.low = dStream.getU4();
|
||||
// var high_bytes = dStream.getU4();
|
||||
// var low_bytes = dStream.getU4();
|
||||
// var bits = (high_bytes * Math.pow(2,32)) + low_bytes;
|
||||
// if (bits == 0x7ff0000000000000){
|
||||
// this.value = POSITIVE_INF;
|
||||
// }else if (bits == 0xfff0000000000000){
|
||||
// this.value = NEGATIVE_INF
|
||||
// }else if ((0x7ff0000000000001 < bits && bits < 0x7fffffffffffffff) || (0xfff0000000000001 < bits && bits < 0xffffffffffffffff)){
|
||||
// this.value = NaN;
|
||||
// }else{
|
||||
// var s = ((high_bytes >> 31) == 0) ? 1 : -1;
|
||||
// var e = ((high_bytes >> 20) & 0x7ff);
|
||||
// var m = 1
|
||||
// /*
|
||||
// (e == 0) ?
|
||||
// (bits & 0xfffffffffffff) * 2 :
|
||||
// (bits & 0xfffffffffffff) | 0x10000000000000;*/
|
||||
// var string = (((high_bytes & 0xfffff) * Math.pow(2,32)) + low_bytes).toString(2);
|
||||
// for (var i=0; i<string.length; i++){
|
||||
// if (string[i] == "1"){
|
||||
// m+=Math.pow(2,-(52-i))
|
||||
// }
|
||||
// }
|
||||
// this.value = s * (1+m) * Math.pow(2, e - 1023);
|
||||
//}
|
||||
this.value = dStream.getFloat64();
|
||||
}
|
||||
};
|
||||
|
||||
@ -317,5 +341,5 @@ ConstantPool.prototype.loadFromStream = function(dStream){
|
||||
}
|
||||
|
||||
ConstantPool.prototype.get = function (i){
|
||||
return this.constantPool[i];
|
||||
return this.constantPool[(i-1)];
|
||||
}
|
15
src/cpu.js
15
src/cpu.js
@ -100,17 +100,18 @@ function interpret(frame,code,method,xl){
|
||||
var pc = 0;
|
||||
|
||||
#ifdef DEBUG_INTRP
|
||||
var temp = null;
|
||||
var temp = null;
|
||||
#endif
|
||||
|
||||
while(pc < code.length){
|
||||
opcode = READ_NEXT();
|
||||
switch(OPCODE){
|
||||
opcode = READ_NEXT();
|
||||
switch(OPCODE){
|
||||
#include "intrp.def"
|
||||
default:
|
||||
PANIC("Invalid OPCODE " + opcode);
|
||||
}
|
||||
default:
|
||||
PANIC("Invalid OPCODE " + opcode);
|
||||
}
|
||||
#ifdef DEBUG_INTRP
|
||||
temp = null;
|
||||
temp = null;
|
||||
#endif
|
||||
}
|
||||
PANIC("PC overran CODE");
|
||||
|
@ -32,8 +32,8 @@
|
||||
#define OPPOP() operand_stack.pop()
|
||||
#define OPPUSH(v) operand_stack.push(v)
|
||||
|
||||
#define OPPOPD() operand_stack.pop() && operand_stack.pop()
|
||||
#define OPPUSHD(v) operand_stack.push(v) && operand_stack.push(null)
|
||||
#define OPPOPD() (operand_stack.pop() || operand_stack.pop())
|
||||
#define OPPUSHD(v) (operand_stack.push(v) && operand_stack.push(null))
|
||||
|
||||
#define OPSTACK(v) operand_stack[v]
|
||||
#define OPSTACK_LENGTH() operand_stack.length
|
||||
|
@ -43,8 +43,12 @@ var MethodInfo = function(dStream, constantPool){
|
||||
for (var i=0; i<this.attributes_count; i++){
|
||||
this.attributes[i] = Attribute(dStream,constantPool);
|
||||
}
|
||||
this.invoke = function (self,xl){
|
||||
var frame = { operand_stack: [], local_variables:[] };
|
||||
this.invoke = function (local_var,xl){
|
||||
#ifdef DEBUG_INTRP
|
||||
LOG("Calling " + this.name_ref.str + this.descriptor_ref.str)
|
||||
#endif
|
||||
local_var = local_var||[];
|
||||
var frame = { operand_stack: [], local_variables:local_var };
|
||||
for (var i=0; i<this.attributes_count; i++){
|
||||
var attr = this.attributes[i];
|
||||
if (attr.id == ATTR_CODE){
|
||||
|
@ -288,7 +288,7 @@ DEFALIAS(DSTORE_1)
|
||||
DEFALIAS(DSTORE_2)
|
||||
DEFALIAS(DSTORE_3)
|
||||
DEFNOP()
|
||||
var index = OPCODE - DLOAD_0;
|
||||
var index = OPCODE - DSTORE_0;
|
||||
var value = OPPOPD();
|
||||
LOCAL_VAR(index) = value;
|
||||
ENDDEF
|
||||
@ -932,10 +932,11 @@ DEFOP(INVOKEVIRTUAL)
|
||||
|
||||
var method = this_method_class.constantPool[(indexbyte1 << 8) | indexbyte2];
|
||||
for(var i=0; i<method.descriptor.args.length; i++){
|
||||
|
||||
args.push(OPPOP());
|
||||
}
|
||||
|
||||
PANIC("NOT IMPLEMENTED YET");
|
||||
method.invoke([])
|
||||
ENDDEF
|
||||
|
||||
DEFOP(IOR)
|
||||
@ -1157,10 +1158,10 @@ DEFOP(LDC_W)
|
||||
ENDDEF
|
||||
|
||||
DEFOP(LDC2_W)
|
||||
var index1 = READ_NEXT();
|
||||
var index2 = READ_NEXT();
|
||||
var indexbyte1 = READ_NEXT();
|
||||
var indexbyte2 = READ_NEXT();
|
||||
var index = (indexbyte1 << 8) | indexbyte2
|
||||
var cstt = this_method_class.constantPool.get(index);
|
||||
var cstt = xl.constantPool.get(index);
|
||||
OPPUSHD(cstt.value);
|
||||
ENDDEF
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user