Added the unary + operator, and cleaned up the display of values from the expression parser

This commit is contained in:
Jeff 2017-03-21 12:47:43 -07:00 committed by Jeff Parsons
commit 127ddb88b4
7 changed files with 1006 additions and 817 deletions

View file

@ -673,6 +673,9 @@ class Debugger extends Component
continue;
}
if (!(nUnary & (0xC0000000|0))) {
if (sOp == '+') {
continue;
}
if (sOp == '-') {
nUnary = (nUnary << 2) | 1;
continue;
@ -1020,9 +1023,9 @@ class Debugger extends Component
if (value !== undefined) {
fDefined = true;
if (this.nBase == 8) {
sValue = value + ". " + Str.toOct(value, 0, true);
sValue = this.toStrBase(value, this.nBits, 8, 1) + " " + value + '.';
} else {
sValue = Str.toHex(value, 0, true) + " " + value + ". " + Str.toOct(value, 0, true) + " " + Str.toBinBytes(value, 4, true);
sValue = this.toStrBase(value, this.nBits, 16, 1) + " " + this.toStrBase(value, this.nBits, 8, 1) + " " + this.toStrBase(value, this.nBits, 2, this.nBits <= 32? 8 : 6) + " " + value + '.';
}
if (value >= 0x20 && value < 0x7F) {
sValue += " '" + String.fromCharCode(value) + "'";
@ -1113,24 +1116,26 @@ class Debugger extends Component
}
/**
* toStrBase(n, nBits)
* toStrBase(n, nBits, nBase, nGrouping)
*
* Use this instead of Str's toOct()/toDec()/toHex() to convert numbers to the Debugger's default base.
*
* @this {Debugger}
* @param {number|null|undefined} n
* @param {number} [nBits] (-1 to strip leading zeros, 0 to allow a variable number of digits)
* @param {number} [nBase]
* @param {number} [nGrouping] (if nBase is 2, this is a grouping; otherwise, it's a prefix condition)
* @return {string}
*/
toStrBase(n, nBits = 0)
toStrBase(n, nBits = 0, nBase = 0, nGrouping = 0)
{
var s;
switch(this.nBase) {
switch(nBase || this.nBase) {
case 2:
s = Str.toBin(n, nBits > 0? nBits : 0);
s = Str.toBin(n, nBits > 0? nBits : 0, nGrouping);
break;
case 8:
s = Str.toOct(n, nBits > 0? ((nBits + 2)/3)|0 : 0);
s = Str.toOct(n, nBits > 0? ((nBits + 2)/3)|0 : 0, !!nGrouping);
break;
case 10:
/*
@ -1140,7 +1145,7 @@ class Debugger extends Component
break;
case 16:
default:
s = Str.toHex(n, nBits > 0? ((nBits + 3) >> 2) : 0);
s = Str.toHex(n, nBits > 0? ((nBits + 3) >> 2) : 0, !!nGrouping);
break;
}
return (nBits < 0? Str.stripLeadingZeros(s) : s);

View file

@ -179,7 +179,7 @@ class Str {
}
/**
* toBase(n, radix, cch, sPrefix, grouping)
* toBase(n, radix, cch, sPrefix, nGrouping)
*
* Displays the given number as an unsigned integer using the specified radix and number of digits.
*
@ -187,10 +187,10 @@ class Str {
* @param {number} radix (ie, the base)
* @param {number} cch (the desired number of digits)
* @param {string} [sPrefix] (default is none)
* @param {number} [grouping]
* @param {number} [nGrouping]
* @return {string}
*/
static toBase(n, radix, cch, sPrefix = "", grouping = -1)
static toBase(n, radix, cch, sPrefix = "", nGrouping = 0)
{
/*
* An initial "falsey" check for null takes care of both null and undefined;
@ -222,11 +222,11 @@ class Str {
cch = Math.ceil(Math.log(n) / Math.log(radix));
}
}
var g = grouping;
var g = nGrouping || -1;
while (cch-- > 0) {
if (!g) {
s = ',' + s;
g = grouping;
g = nGrouping;
}
if (n == null) {
s = '?' + s;
@ -242,16 +242,16 @@ class Str {
}
/**
* toBin(n, cch, grouping)
* toBin(n, cch, nGrouping)
*
* Converts an integer to binary, with the specified number of digits (up to a maximum of 36).
*
* @param {number|null|undefined} n (supports integers up to 36 bits now)
* @param {number} [cch] is the desired number of binary digits (0 or undefined for default of either 8, 18, or 36)
* @param {number} [grouping]
* @param {number} [nGrouping]
* @return {string} the binary representation of n
*/
static toBin(n, cch, grouping)
static toBin(n, cch, nGrouping)
{
if (!cch) {
// cch = Math.ceil(Math.log(Math.abs(n) + 1) / Math.LN2) || 1;
@ -264,7 +264,7 @@ class Str {
cch = 36;
}
} else if (cch > 36) cch = 36;
return Str.toBase(n, 2, cch, "", grouping);
return Str.toBase(n, 2, cch, "", nGrouping);
}
/**