Shell now shows value of last (Expr) statement even in case of several statements
@@ -273,6 +273,8 @@ class VM:
if len(root.body) == 1 and isinstance(root.body[0], ast.Expr):
mode = "eval"
+ elif isinstance(root.body[-1], ast.Expr):
+ mode = "exec+eval"
else:
mode = "exec"
@@ -723,6 +725,16 @@ class Executor:
global_vars = __main__.__dict__
try:
+ if mode == "exec+eval":
+ root = ast.parse(source, filename=filename, mode="exec")
+ statements = compile(ast.Module(body=root.body[:-1]), filename, "exec")
+ expression = compile(ast.Expression(root.body[-1].value), filename, "eval")
+ exec(statements, global_vars)
+ value = eval(expression, global_vars)
+ if value is not None:
+ builtins._ = value
+ return {"value_info" : self._vm.export_value(value)}
+ else:
bytecode = self._compile_source(source, filename, mode)
if hasattr(self, "_trace"):
sys.settrace(self._trace)
