1+ from typing import get_type_hints
2+
13from amitools .vamos .machine import Code , REG_D0 , REG_D1
24from amitools .vamos .libtypes import TagList
35
@@ -18,11 +20,12 @@ def __init__(self, ctx, base_addr=None, run_sp=None):
1820
1921
2022class LibProxyRegs :
21- def __init__ (self , ctx , args , arg_regs , kwargs ):
23+ def __init__ (self , ctx , args , arg_regs , kwargs , stub_method = None ):
2224 assert len (args ) == len (arg_regs )
2325 self .ctx = ctx
2426 self .args = args
2527 self .arg_regs = arg_regs
28+ self .stub_method = stub_method
2629 # shall we return d1 as well?
2730 self .ret_d1 = kwargs .pop ("ret_d1" , False )
2831 # shall we wrap the return value into a type
@@ -83,7 +86,14 @@ def return_d1(self):
8386 return self .ret_d1
8487
8588 def wrap_result (self ):
86- return self .wrap_res
89+ # either use forced type in proxy call argument
90+ result_type = self .wrap_res
91+ # or use from type hint of stub method (if any)
92+ if not result_type and self .stub_method :
93+ hints = get_type_hints (self .stub_method )
94+ if hints and "return" in hints :
95+ result_type = hints ["return" ]
96+ return result_type
8797
8898 def cleanup (self ):
8999 for mem in self .auto_strings :
@@ -109,7 +119,7 @@ def _gen_arg_regs(self, func_def):
109119 def _gen_stub_call (self , arg_regs , stub_method ):
110120 def stub_call (self , * args , ** kwargs ):
111121 """proxy function to call lib stub directly"""
112- regs = LibProxyRegs (self .ctx , args , arg_regs , kwargs )
122+ regs = LibProxyRegs (self .ctx , args , arg_regs , kwargs , stub_method )
113123
114124 # fill registers with arg values
115125 # (lib call may depend on it)
0 commit comments