felixhao28 / JSCPP

A simple C++ interpreter written in JavaScript
https://felixhao28.github.io/JSCPP/
MIT License
860 stars 72 forks source link

Why makeValueString has noArray option for multidimensional arrays? #159

Open alexandruionascu opened 7 months ago

alexandruionascu commented 7 months ago

In rt.ts I'm noticing this option for transforming a variable into a string. For arrays in 2D, 3D, etc. the returned value would be [[...], [...], [...]]. Is there any reason this line cannot be commented out? I ran the tests again and I don't see any breaking changes. This will help me to debug multi-dimensional arrays.

Thank you!

    makeValueString(l: Variable | DummyVariable, options?: MakeValueStringOptions): string {
        let display: string;
        if (!options) { options = {}; }
        if (this.isPrimitiveType(l)) {
            if (this.isTypeEqualTo(l.t, this.charTypeLiteral)) {
                display = "'" + String.fromCharCode(l.v as number) + "'";
            } else if (this.isBoolType(l.t)) {
                display = l.v !== 0 ? "true" : "false";
            } else {
                display = l.v.toString();
            }
        } else if (this.isPointerType(l)) {
            if (this.isFunctionType(l.t)) {
                display = "<function>";
            } else if (this.isArrayType(l)) {
                if (this.isTypeEqualTo(l.t.eleType, this.charTypeLiteral)) {
                    // string
                    display = "\"" + this.getStringFromCharArray(l) + "\"";
                } else if (options.noArray) {
                    display = "[...]";
                } else {
                    //options.noArray = true;
                    const displayList = [];
                    for (let i = l.v.position, end = l.v.target.length, asc = l.v.position <= end; asc ? i < end : i > end; asc ? i++ : i--) {
                        displayList.push(this.makeValueString(l.v.target[i], options));
                    }
                    display = "[" + displayList.join(",") + "]";
                }
            }