|
|
@ -1,8 +1,9 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
function Opcode(num) { |
|
|
|
if (!(this instanceof Opcode)) |
|
|
|
if (!(this instanceof Opcode)) { |
|
|
|
return new Opcode(num); |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof num === 'number') { |
|
|
|
this.num = num; |
|
|
@ -39,8 +40,9 @@ Opcode.prototype.fromString = function(str) { |
|
|
|
|
|
|
|
Opcode.prototype.toString = function() { |
|
|
|
var str = Opcode.reverseMap[this.num]; |
|
|
|
if (typeof str === 'undefined') |
|
|
|
if (typeof str === 'undefined') { |
|
|
|
throw new Error('Opcode does not have a string representation'); |
|
|
|
} |
|
|
|
return str; |
|
|
|
}; |
|
|
|
|
|
|
@ -191,4 +193,15 @@ for (var k in Opcode.map) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @returns true if opcode is one of OP_0, OP_1, ..., OP_16 |
|
|
|
*/ |
|
|
|
Opcode.isSmallIntOp = function(opcode) { |
|
|
|
if (opcode instanceof Opcode) { |
|
|
|
opcode = opcode.toNumber(); |
|
|
|
} |
|
|
|
return ((opcode === Opcode.map.OP_0) || |
|
|
|
((opcode >= Opcode.map.OP_1) && (opcode <= Opcode.map.OP_16))); |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = Opcode; |
|
|
|