File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -73,6 +73,10 @@ code {
7373 expect ( invoke . jump ) . toBe ( true ) ;
7474 expect ( invoke . identifier ) . toBe ( "add" ) ;
7575
76+ // Should have target pointer
77+ const target = invoke . target as Record < string , unknown > ;
78+ expect ( target . pointer ) . toBeDefined ( ) ;
79+
7680 // Should have argument pointers
7781 const args = invoke . arguments as Record < string , unknown > ;
7882 const pointer = args . pointer as Record < string , unknown > ;
@@ -107,7 +111,6 @@ code {
107111 const ctx = ( returnJumpdests [ 0 ] . context as Record < string , unknown > ) ! ;
108112 const ret = ctx . return as Record < string , unknown > ;
109113
110- expect ( ret . jump ) . toBe ( true ) ;
111114 expect ( ret . identifier ) . toBe ( "add" ) ;
112115
113116 // Should have data pointer to return value at
Original file line number Diff line number Diff line change @@ -70,29 +70,23 @@ export function generate<S extends Stack>(
7070
7171 // Add JUMPDEST with continuation annotation if applicable
7272 if ( isContinuation ) {
73- // Check if the call has a return value
74- const predBlock = func ! . blocks . get ( predecessor ! ) ;
75- const hasReturnValue =
76- predBlock ?. terminator . kind === "call" &&
77- ! ! predBlock . terminator . dest ;
78-
7973 // Return context describes state after JUMPDEST
8074 // executes: TOS is the return value (if any).
81- const continuationDebug = {
82- context : {
83- return : {
84- jump : true as const ,
85- identifier : calledFunction ,
86- ...( hasReturnValue && {
87- data : {
88- pointer : {
89- location : "stack" as const ,
90- slot : 0 ,
91- } ,
92- } ,
93- } ) ,
75+ // data pointer is required by the schema; for
76+ // void returns, slot 0 is still valid (empty).
77+ const returnCtx : Format . Program . Context . Return = {
78+ return : {
79+ identifier : calledFunction ,
80+ data : {
81+ pointer : {
82+ location : "stack" as const ,
83+ slot : 0 ,
84+ } ,
9485 } ,
95- } as unknown as Format . Program . Context ,
86+ } ,
87+ } ;
88+ const continuationDebug = {
89+ context : returnCtx as Format . Program . Context ,
9690 } ;
9791 result = result . then ( JUMPDEST ( { debug : continuationDebug } ) ) ;
9892 } else {
Original file line number Diff line number Diff line change @@ -245,23 +245,25 @@ export function generateCallTerminator<S extends Stack>(
245245
246246 // Invoke context describes state after JUMP executes:
247247 // the callee has been entered with args on the stack.
248- // Cast needed because invoke context TS types don't
249- // exist yet (only YAML schemas on call-return branch).
250- const invokeContext = {
251- context : {
252- invoke : {
253- jump : true as const ,
254- identifier : funcName ,
255- ...( argPointers . length > 0 && {
256- arguments : {
257- pointer : {
258- group : argPointers ,
259- } ,
260- } ,
261- } ) ,
248+ // target points to the function address at stack slot 0
249+ // (consumed by JUMP, but describes the call target).
250+ const invoke : Format . Program . Context . Invoke = {
251+ invoke : {
252+ jump : true as const ,
253+ identifier : funcName ,
254+ target : {
255+ pointer : { location : "stack" as const , slot : 0 } ,
262256 } ,
263- } as unknown as Format . Program . Context ,
257+ ...( argPointers . length > 0 && {
258+ arguments : {
259+ pointer : {
260+ group : argPointers ,
261+ } ,
262+ } ,
263+ } ) ,
264+ } ,
264265 } ;
266+ const invokeContext = { context : invoke as Format . Program . Context } ;
265267
266268 currentState = {
267269 ...currentState ,
Original file line number Diff line number Diff line change @@ -36,20 +36,27 @@ function generatePrologue<S extends Stack>(
3636 slot : params . length - 1 - i ,
3737 } ) ) ;
3838
39- const entryDebug = {
40- context : {
41- invoke : {
42- jump : true as const ,
43- identifier : func . name || "anonymous" ,
44- ...( argPointers . length > 0 && {
45- arguments : {
46- pointer : {
47- group : argPointers ,
48- } ,
49- } ,
50- } ) ,
39+ const entryInvoke : Format . Program . Context . Invoke = {
40+ invoke : {
41+ jump : true as const ,
42+ identifier : func . name || "anonymous" ,
43+ target : {
44+ pointer : {
45+ location : "stack" as const ,
46+ slot : 0 ,
47+ } ,
5148 } ,
52- } as unknown as Format . Program . Context ,
49+ ...( argPointers . length > 0 && {
50+ arguments : {
51+ pointer : {
52+ group : argPointers ,
53+ } ,
54+ } ,
55+ } ) ,
56+ } ,
57+ } ;
58+ const entryDebug = {
59+ context : entryInvoke as Format . Program . Context ,
5360 } ;
5461 currentState = {
5562 ...currentState ,
You can’t perform that action at this time.
0 commit comments