dbg - Change to hardcoded functions instead of factory-generated ones, because VS Code type checking can't cope with the generated ones

This commit is contained in:
n loewen 2023-08-29 12:02:18 -04:00
parent 28b92b4980
commit 8a19238612
2 changed files with 63 additions and 38 deletions

View File

@ -133,7 +133,7 @@ function handleLabelDefinition(op, IP, labels) {
dbg.nit(` Points to byte: ${labels[label].pointsToByte}`); dbg.nit(` Points to byte: ${labels[label].pointsToByte}`);
dbg.nit(` Bytes to replace: ${labels[label].bytesToReplace}`); dbg.nit(` Bytes to replace: ${labels[label].bytesToReplace}`);
dbg.nit(` IP: $${num2hex(IP)}, new code: none`); dbg.nit(` IP: $${num2hex(IP)}, new code: none`);
dbgGroupEnd(1, 'Input line'); dbg.nitGroupEnd('Input line');
return labels; return labels;
} }
@ -364,11 +364,11 @@ function decodeInstructions(source) {
// Backfill label references // Backfill label references
for (let k of Object.keys(labels)) { for (let k of Object.keys(labels)) {
dbgGroup(1, `${ASM_LABEL_PREFIX}${k}`); dbg.nitGroup(`${ASM_LABEL_PREFIX}${k}`);
let label = labels[k]; let label = labels[k];
dbg.nit(`Points to byte: ${label.pointsToByte}`); dbg.nit(`Points to byte: ${label.pointsToByte}`);
dbg.nit(`Bytes to replace: ${label.bytesToReplace}`); dbg.nit(`Bytes to replace: ${label.bytesToReplace}`);
dbgGroupEnd(1); dbg.nitGroupEnd();
for (let j = 0; j < label.bytesToReplace.length; j++) { for (let j = 0; j < label.bytesToReplace.length; j++) {
machineCode[label.bytesToReplace[j]] = label.pointsToByte; machineCode[label.bytesToReplace[j]] = label.pointsToByte;
} }

View File

@ -8,51 +8,76 @@ module.exports = class DBG {
} else { } else {
throw new Error(`'${level}' is not a valid debug level`); throw new Error(`'${level}' is not a valid debug level`);
} }
this._levels.forEach((l) => {
this._createLogger(l);
this._createGrouper(l)
this._createGroupEnder(l)
this._createExecer(l)
});
} }
_levels = ['nitpick', 'debug', 'info', 'warn']; _levels = ['nitpick', 'debug', 'info', 'warn'];
_shortNames = {'nitpick':'nit', 'debug':'d', 'info':'i', 'warn':'warn'};
_createLogger(name) { warn = (s='') => {
const short = this._shortNames[name] if (this._lvl2num('warn') < this._lvl2num(this._level)) return
this[short] = (s = '') => {
if (this._lvl2num(name) >= this._lvl2num(this._level)) {
console.log(s); console.log(s);
} }
i = (s='') => {
if (this._lvl2num('info') < this._lvl2num(this._level)) return
console.log(s);
} }
d = (s='') => {
if (this._lvl2num('debug') < this._lvl2num(this._level)) return
console.log(s);
}
nit = (s='') => {
if (this._lvl2num('nitpick') < this._lvl2num(this._level)) return
console.log(s);
} }
_createGrouper(name) { warnGroup = (s) => {
const short = this._shortNames[name] if (this._lvl2num('warn') < this._lvl2num(this._level)) return
this[short + 'Group'] = (s) => {
if (this._lvl2num(name) >= this._lvl2num(this._level)) {
console.group(s); console.group(s);
} }
infoGroup = (s) => {
if (this._lvl2num('info') < this._lvl2num(this._level)) return
console.group(s);
} }
debugGroup = (s) => {
if (this._lvl2num('debug') < this._lvl2num(this._level)) return
console.group(s);
}
nitGroup = (s) => {
if (this._lvl2num('nit') < this._lvl2num(this._level)) return
console.group(s);
} }
_createGroupEnder(name) { warnGroupEnd = (s) => {
const short = this._shortNames[name] if (this._lvl2num('warn') < this._lvl2num(this._level)) return
this[short+'GroupEnd'] = () => {
if (this._lvl2num(name) >= this._lvl2num(this._level)) {
console.groupEnd(); console.groupEnd();
} }
infoGroupEnd = (s) => {
if (this._lvl2num('info') < this._lvl2num(this._level)) return
console.group();
} }
debugGroupEnd = (s) => {
if (this._lvl2num('debug') < this._lvl2num(this._level)) return
console.group();
}
nitGroupEnd = (s) => {
if (this._lvl2num('nit') < this._lvl2num(this._level)) return
console.group();
} }
_createExecer(name) { warnExec = (fn) => {
const short = this._shortNames[name] if (this._lvl2num('warn') < this._lvl2num(this._level)) return
this[short+'Exec'] = (func) => { fn();
if (this._lvl2num(name) >= this._lvl2num(this._level)) {
func();
} }
infoExec = (fn) => {
if (this._lvl2num('info') < this._lvl2num(this._level)) return
fn();
} }
debugExec = (fn) => {
if (this._lvl2num('debug') < this._lvl2num(this._level)) return
fn();
}
nitExec = (fn) => {
if (this._lvl2num('nit') < this._lvl2num(this._level)) return
fn();
} }
_lvl2num(lvl) { _lvl2num(lvl) {