From 55caa3335ecdfb87d8731e1def23975fd61e92a9 Mon Sep 17 00:00:00 2001 From: JothamWong <45916998+JothamWong@users.noreply.github.com> Date: Fri, 19 Apr 2024 17:41:44 +0800 Subject: [PATCH] Make sure to add slices and arrays to visualizer --- src/server/runOogaLang.ts | 1 + src/tests/test.ts | 3 ++- src/vm/oogavm-heap.ts | 12 ++++++++++++ src/vm/oogavm-machine.ts | 4 ++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/server/runOogaLang.ts b/src/server/runOogaLang.ts index 27e588c..7d89255 100644 --- a/src/server/runOogaLang.ts +++ b/src/server/runOogaLang.ts @@ -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(); diff --git a/src/tests/test.ts b/src/tests/test.ts index 61eb610..f631a2c 100644 --- a/src/tests/test.ts +++ b/src/tests/test.ts @@ -1026,7 +1026,7 @@ print(x + " " + y); `, 'Jotham Wong', '"Jotham Wong"', - 200 + 300 ); // Test GC with NEW_THREAD instruction to make sure everything works @@ -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++ { diff --git a/src/vm/oogavm-heap.ts b/src/vm/oogavm-heap.ts index 80217d7..cf95cc1 100644 --- a/src/vm/oogavm-heap.ts +++ b/src/vm/oogavm-heap.ts @@ -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; } diff --git a/src/vm/oogavm-machine.ts b/src/vm/oogavm-machine.ts index 7b34b93..1955a7a 100644 --- a/src/vm/oogavm-machine.ts +++ b/src/vm/oogavm-machine.ts @@ -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; }