getDebugTree(): use $$ for view functions so we don't accidentally call them

This commit is contained in:
Steven Hugg 2020-08-09 14:45:39 -05:00
parent 167d60d402
commit 502ee5de0f
4 changed files with 13 additions and 10 deletions

View File

@ -426,7 +426,7 @@ export class BASICRuntime {
this.gotoLabel(labels[value-1]);
}
nextDatum() : string|number {
nextDatum() : basic.Value {
if (this.dataptr >= this.datums.length)
this.runtimeError("I tried to READ, but ran out of data.");
return this.datums[this.dataptr++].value;

View File

@ -1,6 +1,6 @@
"use strict";
import { hex, clamp } from "./util";
import { hex, clamp, lpad } from "./util";
// external modules
declare var jt, Javatari;
@ -313,13 +313,15 @@ export function dumpRAM(ram:ArrayLike<number>, ramofs:number, ramlen:number) : s
var s = "";
var bpel = ram['BYTES_PER_ELEMENT'] || 1;
var perline = Math.ceil(16 / bpel);
var isFloat = ram instanceof Float32Array || ram instanceof Float64Array;
// TODO: show scrollable RAM for other platforms
for (var ofs=0; ofs<ramlen; ofs+=perline) {
s += '$' + hex(ofs+ramofs) + ':';
for (var i=0; i<perline; i++) {
if (ofs+i < ram.length) {
if (i == perline/2) s += " ";
s += " " + hex(ram[ofs+i], bpel*2);
if (isFloat) s += " " + ram[ofs+i].toPrecision(bpel*2);
else s += " " + hex(ram[ofs+i], bpel*2);
}
}
s += "\n";

View File

@ -1412,15 +1412,16 @@ class TreeNode {
var text = "";
// is it a function? call it first, if we are expanded
// TODO: only call functions w/ signature
if (typeof obj == 'function' && this._content != null) {
obj = obj();
if (obj && obj.$$ && typeof obj.$$ == 'function' && this._content != null) {
obj = obj.$$();
}
// check null first
if (obj == null) {
text = obj+"";
// primitive types
} else if (typeof obj == 'number') {
text = obj + "\t($" + hex(obj) + ")";
if (obj != (obj|0)) text = obj.toString(); // must be a float
else text = obj + "\t($" + hex(obj) + ")";
} else if (typeof obj == 'boolean') {
text = obj.toString();
} else if (typeof obj == 'string') {
@ -1442,7 +1443,7 @@ class TreeNode {
var slicelen = MAX_CHILDREN;
while (obj.length / slicelen > MAX_CHILDREN) slicelen *= 2;
for (let ofs=0; ofs<oldobj.length; ofs+=slicelen) {
newobj["$"+hex(ofs)] = () => { return oldobj.slice(ofs, ofs+slicelen); }
newobj["$"+hex(ofs)] = {$$: () => { return oldobj.slice(ofs, ofs+slicelen); }}
}
obj = newobj;
}

View File

@ -887,9 +887,9 @@ class ZmachinePlatform implements Platform {
var root = {};
//root['debuginfo'] = sym.debuginfo;
if (this.zvm != null) {
root['Objects'] = () => this.getRootObjects();
root['Globals'] = () => this.getGlobalVariables();
//root['VM'] = () => this.zvm;
root['Objects'] = {$$: () => this.getRootObjects()};
root['Globals'] = {$$: () => this.getGlobalVariables()};
//root['VM'] = {$$: () => this.zvm};
}
return root;
}