@@ -265,6 +265,7 @@ def import_path(path: Text, module_name: Text, fully_qualified_name: Text,
265265def _do_exec (args : Tuple [Any , ...],
266266 kwargs : Dict [Text , Any ],
267267 ictx : ICtx ) -> Result [None ]:
268+ """Implements the `exec` builtin."""
268269 assert 1 <= len (args ) <= 3 and not kwargs , (args , kwargs )
269270 source , globals_ , locals_ = none_filler (args , 3 )
270271 if isinstance (source , types .CodeType ):
@@ -277,3 +278,20 @@ def _do_exec(args: Tuple[Any, ...],
277278 if res .is_exception ():
278279 return res
279280 return Result (None )
281+
282+
283+ @check_result
284+ @register_builtin ('eval' )
285+ def _do_eval (args : Tuple [Any , ...],
286+ kwargs : Dict [Text , Any ],
287+ ictx : ICtx ) -> Result [None ]:
288+ """Implements the `eval` builtin."""
289+ source , globals_ , locals_ = none_filler (args , 3 )
290+ if isinstance (source , types .CodeType ):
291+ code = source
292+ else :
293+ assert isinstance (source , str ), type (source )
294+ code = compile (source , '<string>' , 'eval' )
295+ res = interp (code , globals_ = globals_ , ictx = ictx , name = 'eval' ,
296+ locals_dict = locals_ , in_function = False )
297+ return res
0 commit comments