this.viewU32 = new Uint32Array(
this.memory.buffer, 0,
Math.floor(this.memory.length / Uint32Array.BYTES_PER_ELEMENT));
+ this.viewFloat = new Float32Array(
+ this.memory.buffer, 0,
+ Math.floor(this.memory.length / Float32Array.BYTES_PER_ELEMENT));
}
Decoder.prototype.skip = function(offset) {
return low + high * 0x100000000;
};
+ Decoder.prototype.decodeFloat = function() {
+ var result = this.viewFloat[this.next / this.viewFloat.BYTES_PER_ELEMENT];
+ this.next += this.viewFloat.BYTES_PER_ELEMENT;
+ return result;
+ };
+
Decoder.prototype.decodePointer = function() {
// TODO(abarth): To correctly decode a pointer, we need to know the real
// base address of the array buffer.
this.next += 8;
};
+ Encoder.prototype.encodeFloat = function(val) {
+ var floatBuffer = new Float32Array(1);
+ floatBuffer[0] = val;
+ var buffer = new Uint8Array(floatBuffer.buffer, 0);
+ for (var i = 0; i < buffer.length; ++i)
+ this.buffer.memory[this.next++] = buffer[i];
+ };
+
Encoder.prototype.encodePointer = function(pointer) {
if (!pointer)
return this.write64(0);