Skip to content

Commit

Permalink
Make sure to add slices and arrays to visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
JothamWong committed Apr 19, 2024
1 parent 95f0b87 commit 55caa33
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/server/runOogaLang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function runOogaLangCode(
const bytecode = prepare_and_compile(standardSource, code);
processByteCode(bytecode);
let value = run();
// let value = run(300);
capturedOutput += 'Output: ' + value + '\n';

const heaps = getHeaps();
Expand Down
3 changes: 2 additions & 1 deletion src/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ print(x + " " + y);
`,
'Jotham Wong',
'"Jotham Wong"',
200
300
);

// Test GC with NEW_THREAD instruction to make sure everything works
Expand Down Expand Up @@ -1991,6 +1991,7 @@ go func() {
case <-x:
print("This won't happen");
}
print("This also will not show");
}();
for i := 0; i < 100; i++ {
Expand Down
12 changes: 12 additions & 0 deletions src/vm/oogavm-heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,18 @@ export function getHeapJSON(): any {
heapItem['children'].push(getWord(curr + headerSize + 1 + i));
}
break;
case Tag.ARRAY:
heapItem['capacity'] = getArrayLength(curr);
for (let i = 0; i < getArrayLength(curr); i++) {
heapItem['children'].push(getArrayValueAtIndex(curr, i));
}
break;
case Tag.SLICE:
heapItem['capacity'] = getSliceCapacity(curr);
for (let i = 0; i < getSliceLength(curr); i++) {
heapItem['children'].push(getSliceValueAtIndex(curr, i));
}
break;
default:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vm/oogavm-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,8 @@ export function run(numWords = 1000000) {
const returnValue = addressToTSValue(peekStack(OS[0]));
log('Program value is ' + returnValue);
log('After STD initialization: ');
printHeapUsage();
debugHeap();
// printHeapUsage();
// debugHeap();
log('Return value: ' + returnValue);
return returnValue;
}
Expand Down

0 comments on commit 55caa33

Please sign in to comment.