1
1
import { Equal , Expect } from "type-testing"
2
2
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'
5
4
import { executeInstruction } from "./program"
6
5
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 ;
12
8
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 : [ ] ;
23
11
activeFuncId : "" ;
24
12
activeBranches : { } ;
25
13
activeStackDepth : 0 ;
26
14
activeLocals : { } ;
27
15
globals : { } ;
28
- L1Cache : {
29
- "00000000000000000000010000000000" : "01000001" ;
30
- } ;
16
+ L1Cache : { } ;
31
17
memory : { } ;
32
- garbageCollection : 1022 ;
18
+ garbageCollection : 0 ;
33
19
indirect : { } ;
34
20
memorySize : "" ;
35
21
executionContexts : [ ] ;
36
22
funcs : { } ;
37
23
} >
38
24
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 < {
41
40
count : 1023 ;
42
- results : [ ] ;
43
- stack : [ ] ;
44
41
instructions : [
45
- { kind : 'Const' ; value : '10000000000000000000000000000000 ' } ,
42
+ { kind : 'Nop' , ziltoid : 'theOmniscient ' } ,
46
43
{ kind : 'Nop' , ziltoid : 'theOmniscient' } ,
47
44
] ;
48
- activeFuncId : "" ;
49
- activeBranches : { } ;
50
- activeStackDepth : 0 ;
51
- activeLocals : { } ;
52
- globals : { } ;
53
45
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
56
58
} ;
57
- memory : { } ;
58
59
garbageCollection : 1023 ;
59
- indirect : { } ;
60
- memorySize : "" ;
61
- executionContexts : [ ] ;
62
- funcs : { } ;
63
- } >
64
- type test1023 = Expect < Equal < actual1023 , expected1023 > >
60
+ } > >
65
61
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 < {
68
64
count : 1024 ;
69
- results : [ ] ;
70
- stack : [ '10000000000000000000000000000000' ] ;
71
65
instructions : [
72
66
{ kind : 'Nop' , ziltoid : 'theOmniscient' } ,
73
67
] ;
74
- activeFuncId : "" ;
75
- activeBranches : { } ;
76
- activeStackDepth : 0 ;
77
- activeLocals : { } ;
78
- globals : { } ;
79
68
L1Cache : { } ;
80
69
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
+ }
83
76
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 > >
0 commit comments