Skip to content

Commit

Permalink
fix: unallocated cells
Browse files Browse the repository at this point in the history
  • Loading branch information
arturo32 committed Dec 2, 2024
1 parent b7893de commit 04ed7f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion memoryCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default {
if(this.content !== '?') {
const pointerCell = document.querySelector('.memory-cell-' + this.address);
const pointedCell = document.querySelector('.memory-cell-' + this.content);
const isPointedCellHeap = pointedCell.parentElement.id === 'heap';
if(pointedCell !== null) {
const isPointedCellHeap = pointedCell.parentElement.id === 'heap';
globalArrows.set(
this.address + this.content,
new LeaderLine(
Expand Down
10 changes: 9 additions & 1 deletion memoryContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ const vm = createApp({
const heap = lastLineState.heap;

// Transforms [{varName: properties}] into [["varname", properties]]
const heapArray = new Array(...Object.entries(heap));
let heapArray = new Array(...Object.entries(heap));


// Removes unallocated cells
heapArray = heapArray.filter(cell => cell[1][2] !== undefined);

let arrayCells = [];
for(let cell of heapArray) {
cell[0] = '';
Expand All @@ -150,6 +153,9 @@ const vm = createApp({
}
heapArray.push(...arrayCells);

// Removes unallocated cells
heapArray = heapArray.filter(cell => cell[1][2] !== undefined);

for(let cell of heapArray) {
if(cell[1][2][2] === 'pointer') {
cell[1][2][2] = this.findPointedCell(cell, heapArray.concat(this.stack));
Expand All @@ -159,6 +165,8 @@ const vm = createApp({
cell[2] = true;
}



// Ordering by address
heapArray.sort((a, b) => a[1][1].localeCompare(b[1][1]));

Expand Down

0 comments on commit 04ed7f3

Please sign in to comment.