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

View File

@ -8,51 +8,76 @@ module.exports = class DBG {
} else {
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'];
_shortNames = {'nitpick':'nit', 'debug':'d', 'info':'i', 'warn':'warn'};
_createLogger(name) {
const short = this._shortNames[name]
this[short] = (s = '') => {
if (this._lvl2num(name) >= this._lvl2num(this._level)) {
console.log(s);
}
}
warn = (s='') => {
if (this._lvl2num('warn') < this._lvl2num(this._level)) return
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) {
const short = this._shortNames[name]
this[short + 'Group'] = (s) => {
if (this._lvl2num(name) >= this._lvl2num(this._level)) {
console.group(s);
}
}
warnGroup = (s) => {
if (this._lvl2num('warn') < this._lvl2num(this._level)) return
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) {
const short = this._shortNames[name]
this[short+'GroupEnd'] = () => {
if (this._lvl2num(name) >= this._lvl2num(this._level)) {
console.groupEnd();
}
}
warnGroupEnd = (s) => {
if (this._lvl2num('warn') < this._lvl2num(this._level)) return
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) {
const short = this._shortNames[name]
this[short+'Exec'] = (func) => {
if (this._lvl2num(name) >= this._lvl2num(this._level)) {
func();
}
}
warnExec = (fn) => {
if (this._lvl2num('warn') < this._lvl2num(this._level)) return
fn();
}
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) {