Skip to content

Commit 05dec9c

Browse files
committed
it was a one line fix.... garbage collector broke: it ruined everything.
1 parent ac27faa commit 05dec9c

File tree

7 files changed

+66
-281
lines changed

7 files changed

+66
-281
lines changed

Diff for: packages/playground/evaluate/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const config = {
3434
incrementBy: 100,
3535
comeUpForAirEvery: 100,
3636
transcendTheAstralPlane: 100,
37-
readStringFromMemory: false,
37+
readStringFromMemory: true,
3838
} satisfies Config;
3939

4040
/** this is the magic type alias that the script is looking for in the evaluationFilePath */

Diff for: packages/playground/evaluate/utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export const printType = (typeString: string) => {
231231

232232
// if the first two characters are `{ "` we presume it's an object and format it as such
233233

234+
// object detection
234235
if (output.startsWith('{ "')) {
235236
const lines = output
236237
.replace(/{ "/g, '{\n "')
@@ -240,5 +241,15 @@ export const printType = (typeString: string) => {
240241
const sortedLines = lines.slice(1, lines.length - 1).sort();
241242
output = [lines[0], ...sortedLines, lines[lines.length - 1]].join("\n");
242243
}
244+
245+
// string detection
246+
if (output.startsWith(`"`) && output.endsWith(`"`)) {
247+
output = output.slice(1, output.length - 1);
248+
249+
if (output === "") {
250+
return "<empty string>";
251+
}
252+
}
253+
243254
return output;
244255
};

Diff for: packages/playground/final-doom-pun-intended/data/memory.ts

-194
Large diffs are not rendered by default.

Diff for: packages/playground/final-doom-pun-intended/data/process-frame.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ type _GenerateLine<
4646
count extends `1${infer S}`
4747

4848
? // look up the value in memory
49-
memory[address] extends infer value extends keyof DoomPaletteToAscii
49+
memory[address] extends infer value
5050
? _GenerateLine<
5151
memory,
5252
I32PlusOne<address>,
5353
S,
54-
`${line}${DoomPaletteToAscii[value]}`
54+
`${line}${DoomPaletteToAscii[value extends keyof DoomPaletteToAscii ? value : "00000000"]}`
5555
>
5656

5757
: // you fucked up. you. fucked. up... yet again.

Diff for: packages/wasm-to-typescript-types/state.test.ts

+46-80
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,78 @@
11
import { Equal, Expect } from "type-testing"
22
import { ProgramState } from "./types"
3-
import { State } from './state'
4-
import type { Satisfies } from 'ts-type-math'
3+
import type { evaluate, Satisfies } from 'ts-type-math'
54
import { executeInstruction } from "./program"
65

7-
8-
// end-to-end test for garbage collection
9-
10-
type actual1022 = Satisfies<ProgramState, {
11-
count: 1022;
6+
type blank = Satisfies<ProgramState, {
7+
count: 0;
128
results: [];
13-
stack: ["00000000000000000000010000000001", "00000000000000000000000000000000"];
14-
instructions: [
15-
{
16-
kind: "Store";
17-
subkind: "I32Store8";
18-
offset: "00000000000000000000000000000000";
19-
},
20-
{ kind: 'Const'; value: '10000000000000000000000000000000' },
21-
{ kind: 'Nop', ziltoid: 'theOmniscient' },
22-
];
9+
stack: [];
10+
instructions: [];
2311
activeFuncId: "";
2412
activeBranches: {};
2513
activeStackDepth: 0;
2614
activeLocals: {};
2715
globals: {};
28-
L1Cache: {
29-
"00000000000000000000010000000000": "01000001";
30-
};
16+
L1Cache: {};
3117
memory: {};
32-
garbageCollection: 1022;
18+
garbageCollection: 0;
3319
indirect: {};
3420
memorySize: "";
3521
executionContexts: [];
3622
funcs: {};
3723
}>
3824

39-
type actual1023 = executeInstruction<actual1022, true, 1023>
40-
type expected1023 = Satisfies<ProgramState, {
25+
type s<
26+
Update extends Partial<ProgramState>
27+
> = Satisfies<ProgramState,
28+
evaluate<
29+
& Omit<
30+
blank,
31+
keyof Update
32+
>
33+
& Required<Update>
34+
>
35+
>
36+
37+
// end-to-end test for garbage collection
38+
39+
type actual1023 = Satisfies<ProgramState, s<{
4140
count: 1023;
42-
results: [];
43-
stack: [];
4441
instructions: [
45-
{ kind: 'Const'; value: '10000000000000000000000000000000' },
42+
{ kind: 'Nop', ziltoid: 'theOmniscient' },
4643
{ kind: 'Nop', ziltoid: 'theOmniscient' },
4744
];
48-
activeFuncId: "";
49-
activeBranches: {};
50-
activeStackDepth: 0;
51-
activeLocals: {};
52-
globals: {};
5345
L1Cache: {
54-
"00000000000000000000010000000000": "01000001";
55-
"00000000000000000000010000000001": "00000000";
46+
"00000000000000000000000000000000": "00101110"; // will not change because it matches the source
47+
"00000000000000000000000000000001": "00000000"; // will clear the source value
48+
"00000000000000000000000000000011": "00000000"; // will never be set in the first place
49+
"00000000000000000000000000000100": "01010101"; // will append this new value because it's not false
50+
"00000000000000000000000000000101": "00000000"; // will skip because it's false
51+
"00000000000000000000000000000111": "00000010"; // will modify the source value
52+
}
53+
memory: {
54+
"00000000000000000000000000000000": "00101110"; // will keep because it hasn't changed
55+
"00000000000000000000000000000001": "11111111"; // will be removed because the update for this address is false
56+
"00000000000000000000000000000111": "00000001"; // will be modified by the update
57+
"11111111111111111111111100000011": "00000001"; // will keep because it's random other data only present in the source
5658
};
57-
memory: {};
5859
garbageCollection: 1023;
59-
indirect: {};
60-
memorySize: "";
61-
executionContexts: [];
62-
funcs: {};
63-
}>
64-
type test1023 = Expect<Equal<actual1023, expected1023>>
60+
}>>
6561

66-
type actual1024 = executeInstruction<actual1023, true, 1024>
67-
type expected1024 = Satisfies<ProgramState, {
62+
type actual1025 = executeInstruction<actual1023, true, 1024>
63+
type expected1025 = Satisfies<ProgramState, s<{
6864
count: 1024;
69-
results: [];
70-
stack: ['10000000000000000000000000000000'];
7165
instructions: [
7266
{ kind: 'Nop', ziltoid: 'theOmniscient' },
7367
];
74-
activeFuncId: "";
75-
activeBranches: {};
76-
activeStackDepth: 0;
77-
activeLocals: {};
78-
globals: {};
7968
L1Cache: {};
8069
memory: {
81-
"00000000000000000000010000000000": "01000001";
82-
};
70+
"00000000000000000000000000000000": "00101110"; // source and update match
71+
//"00000000000000000000000000000001": "11111111"; // the update cleared this value
72+
"00000000000000000000000000000100": "01010101"; // newly added by the update
73+
"00000000000000000000000000000111": "00000010"; // modified by the update
74+
"11111111111111111111111100000011": "00000001"; // the random other data only present in the source
75+
}
8376
garbageCollection: 0;
84-
indirect: {};
85-
memorySize: "";
86-
executionContexts: [];
87-
funcs: {};
88-
}>
89-
type test1024 = Expect<Equal<actual1024, expected1024>>
90-
91-
type actual1025 = executeInstruction<actual1024, true, 1025>
92-
type expected1025 = Satisfies<ProgramState, {
93-
count: 1025;
94-
results: [];
95-
stack: ['10000000000000000000000000000000'];
96-
instructions: [];
97-
activeFuncId: "";
98-
activeBranches: {};
99-
activeStackDepth: 0;
100-
activeLocals: {};
101-
globals: {};
102-
L1Cache: {};
103-
memory: {
104-
"00000000000000000000010000000000": "01000001";
105-
};
106-
garbageCollection: 0; // 0 again, because we finalized
107-
indirect: {};
108-
memorySize: "";
109-
executionContexts: [];
110-
funcs: {};
111-
}>
112-
type test1025 = Expect<Equal<actual1025, expected1025>>
77+
}>>
78+
type test1025 = Expect<Equal<actual1025, expected1025>>

Diff for: packages/wasm-to-typescript-types/state.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,11 @@ export namespace State {
495495
instructions: state['instructions'];
496496
activeBranches: state['activeBranches'];
497497
L1Cache: {}; // clear the L1Cache
498-
memory: Patch<
499-
state['memory'],
500-
TypeMath.GarbageCollect<state['L1Cache']>
498+
memory: TypeMath.GarbageCollect<
499+
Patch<
500+
state['memory'],
501+
state['L1Cache']
502+
>
501503
>; // update the memory with the L1Cache
502504
executionContexts: state['executionContexts'];
503505
funcs: state['funcs'];

Diff for: packages/wasm-to-typescript-types/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type GarbageCollection = number;
3333
export type IndirectTable = Record<MemoryAddress, FuncId>;
3434

3535
/** do a memory sweep every 4 kibibytes */
36-
export type SweepL1Every = 4096;
36+
export type SweepL1Every = 1024;
3737

3838
export type StorageBits = 8 | 16 | 32 | 64;
3939

0 commit comments

Comments
 (0)