@@ -5,11 +5,10 @@ import type {
55 BranchesById ,
66 SweepL1Every ,
77 ExecutionContext ,
8- Func ,
98 GlobalsById ,
109 MemoryAddress ,
11- MemoryByAddress ,
1210 ProgramState ,
11+ FuncId ,
1312} from "./types"
1413import * as TypeMath from "ts-type-math" ;
1514import { WasmValue , WasmType , Convert , Wasm , evaluate , Satisfies } from 'ts-type-math' ;
@@ -20,6 +19,8 @@ export type Patch<Source, Update> = evaluate<
2019 & Update
2120> ;
2221
22+ export type IDugMyselfANiceBigHoleAndNowIHaveToDebugMyWayOutOfItSomehow = true ;
23+
2324export namespace State {
2425 export type error <
2526 reason extends string ,
@@ -66,6 +67,42 @@ export namespace State {
6667 >
6768 >
6869
70+ export namespace CallHistory {
71+ export type record <
72+ funcId extends FuncId ,
73+ state extends ProgramState
74+ > = Satisfies < ProgramState ,
75+ IDugMyselfANiceBigHoleAndNowIHaveToDebugMyWayOutOfItSomehow extends true
76+ ? {
77+ count : state [ 'count' ] ;
78+ stack : state [ 'stack' ] ;
79+ activeFuncId : state [ 'activeFuncId' ] ;
80+ activeStackDepth : state [ 'activeStackDepth' ] ;
81+ activeLocals : state [ 'activeLocals' ] ;
82+ instructions : state [ 'instructions' ] ;
83+ activeBranches : state [ 'activeBranches' ] ;
84+ L1Cache : state [ 'L1Cache' ] ;
85+ memory : state [ 'memory' ] ;
86+ executionContexts : state [ 'executionContexts' ] ;
87+ funcs : state [ 'funcs' ] ;
88+ garbageCollection : state [ 'garbageCollection' ] ;
89+ globals : state [ 'globals' ] ;
90+ memorySize : state [ 'memorySize' ] ;
91+ indirect : state [ 'indirect' ] ;
92+ results : state [ 'results' ] ;
93+ callHistory : state [ 'callHistory' ] extends [ ]
94+ ? [
95+ [ funcId , state [ 'count' ] ] // this is the first one!
96+ ]
97+ : [
98+ ...state [ 'callHistory' ] ,
99+ [ funcId , state [ 'count' ] ] // append
100+ ]
101+ }
102+ : state
103+ >
104+ }
105+
69106 export namespace Count {
70107 export type increment <
71108 state extends ProgramState
@@ -88,6 +125,7 @@ export namespace State {
88125 memorySize : state [ 'memorySize' ] ;
89126 indirect : state [ 'indirect' ] ;
90127 results : state [ 'results' ] ;
128+ callHistory : state [ 'callHistory' ] ;
91129 }
92130 >
93131 }
@@ -116,6 +154,7 @@ export namespace State {
116154 memorySize : state [ 'memorySize' ] ;
117155 indirect : state [ 'indirect' ] ;
118156 results : state [ 'results' ] ;
157+ callHistory : state [ 'callHistory' ] ;
119158 }
120159 >
121160
@@ -182,6 +221,7 @@ export namespace State {
182221 memorySize : state [ 'memorySize' ] ;
183222 indirect : state [ 'indirect' ] ;
184223 results : state [ 'results' ] ;
224+ callHistory : state [ 'callHistory' ] ;
185225 }
186226 >
187227
@@ -236,6 +276,7 @@ export namespace State {
236276 memorySize : state [ 'memorySize' ] ;
237277 indirect : state [ 'indirect' ] ;
238278 results : state [ 'results' ] ;
279+ callHistory : state [ 'callHistory' ] ;
239280 }
240281 >
241282
@@ -264,6 +305,7 @@ export namespace State {
264305 memorySize : state [ 'memorySize' ] ;
265306 indirect : state [ 'indirect' ] ;
266307 results : state [ 'results' ] ;
308+ callHistory : state [ 'callHistory' ] ;
267309 }
268310 : state [ 'instructions' ] extends IEndFunction [ ] // funny story: [IEndFunction] doesn't work here
269311 ? // we hit this case on the very last pop (i.e. when the program completes)
@@ -284,6 +326,7 @@ export namespace State {
284326 memorySize : state [ 'memorySize' ] ;
285327 indirect : state [ 'indirect' ] ;
286328 results : state [ 'results' ] ;
329+ callHistory : state [ 'callHistory' ] ;
287330 }
288331 : State . error < "execution contexts exhausted" , Instruction , state >
289332 >
@@ -316,6 +359,7 @@ export namespace State {
316359 memorySize : state [ 'memorySize' ] ;
317360 indirect : state [ 'indirect' ] ;
318361 results : state [ 'results' ] ;
362+ callHistory : state [ 'callHistory' ] ;
319363 }
320364 >
321365 }
@@ -342,6 +386,7 @@ export namespace State {
342386 memorySize : state [ 'memorySize' ] ;
343387 indirect : state [ 'indirect' ] ;
344388 results : state [ 'results' ] ;
389+ callHistory : state [ 'callHistory' ] ;
345390 }
346391 >
347392
@@ -389,6 +434,7 @@ export namespace State {
389434 memorySize : state [ 'memorySize' ] ;
390435 indirect : state [ 'indirect' ] ;
391436 results : state [ 'results' ] ;
437+ callHistory : state [ 'callHistory' ] ;
392438 }
393439 >
394440 }
@@ -442,6 +488,7 @@ export namespace State {
442488 memorySize : state [ 'memorySize' ] ;
443489 indirect : state [ 'indirect' ] ;
444490 results : state [ 'results' ] ;
491+ callHistory : state [ 'callHistory' ] ;
445492 }
446493 // >
447494 >
@@ -468,6 +515,7 @@ export namespace State {
468515 memorySize : state [ 'memorySize' ] ;
469516 indirect : state [ 'indirect' ] ;
470517 results : state [ 'results' ] ;
518+ callHistory : state [ 'callHistory' ] ;
471519 }
472520 >
473521
@@ -505,6 +553,7 @@ export namespace State {
505553 memorySize : state [ 'memorySize' ] ;
506554 indirect : state [ 'indirect' ] ;
507555 results : state [ 'results' ] ;
556+ callHistory : state [ 'callHistory' ] ;
508557 }
509558 : state
510559 >
@@ -571,6 +620,7 @@ export namespace State {
571620 _resultTypes [ 'length' ] extends 1
572621 ? WasmTypeToTSNumber < _resultTypes [ 0 ] , state [ 'stack' ] [ 0 ] >
573622 : CollectResults < state [ 'stack' ] , _resultTypes > ;
623+ callHistory : state [ 'callHistory' ] ;
574624 }
575625 >
576626
0 commit comments