Skip to content

Commit 22abb0c

Browse files
committed
make stack smaller and work better
1 parent b0aebcf commit 22abb0c

6 files changed

Lines changed: 13 additions & 8 deletions

File tree

dist/webpage/assembler/assembler.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/webpage/assembler/assembler.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/webpage/emulator/ram.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/webpage/emulator/ram.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/webpage/assembler/assembler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function assemble(files: [string, string][]) {
135135
const globalLabelMap: labelMap = new Map();
136136

137137
function link(labelMap: labelMap, dataLables: linkerInfo, globalRun = false) {
138-
const ram = new Ram(dataView, textView, [dataIndex, textIndex, 0]);
138+
const ram = new Ram(dataView, textView, [dataIndex, textIndex, 1 << 22]);
139139

140140
for (const [address, thing] of dataLables) {
141141
const label = labelMap.get(thing.label);

src/webpage/emulator/ram.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class RamStore {
1616
const arr = new Uint32Array(view.buffer);
1717
return new Uint32Array(arr.slice(0, last + 1).buffer);
1818
}
19+
trimStart(view: DataView, length: number) {
20+
let last = Math.ceil(length / 4);
21+
const arr = new Uint32Array(view.buffer);
22+
return new Uint32Array(arr.slice(last - 1 - arr.length).buffer);
23+
}
1924
toRam() {
2025
const data = new Uint32Array(new ArrayBuffer(1 << 22));
2126
for (const thing in this.data) {
@@ -25,9 +30,9 @@ class RamStore {
2530
for (const thing in this.text) {
2631
text[thing] = this.text[thing];
2732
}
28-
const stack = new Uint32Array(new ArrayBuffer(1 << 22));
33+
const stack = new Uint32Array(new ArrayBuffer(1 << 16));
2934
for (const thing in this.stack) {
30-
stack[thing] = this.stack[thing];
35+
stack[thing] = this.stack[stack.length - +thing];
3136
}
3237
return new Ram(
3338
new DataView(data.buffer),
@@ -67,7 +72,7 @@ class Ram {
6772
}
6873
return ["text", val - 0x00400000];
6974
} else if (val >= 0x7fffeffc - this.stack.byteLength && val < 0x7fffeffc) {
70-
if (!read && val - 0x7fffeffc > this.lengths[2]) {
75+
if (!read && val - 0x7fffeffc < this.lengths[2]) {
7176
this.lengths[1] = val - 0x7fffeffc;
7277
}
7378
return ["stack", val - 0x7fffeffc + this.stack.byteLength];

0 commit comments

Comments
 (0)