@@ -355,6 +355,19 @@ const pyCmdEvaluators: { [type: string]: CmdEvaluator } = {
355355 pyDefineVariable ( context , functionDefNode . name . lexeme , closure ) ;
356356 } ,
357357
358+ 'Lambda' : ( code , command , context , control , stash , isPrelude ) => {
359+ const lambdaNode = command as ExprNS . Lambda ;
360+
361+ //create closure, capturing current environment
362+ const closure = PyClosure . makeFromLambda (
363+ lambdaNode ,
364+ currentEnvironment ( context ) ,
365+ context
366+ ) ;
367+ // lambda is expression, just push value onto stash
368+ stash . push ( closure ) ;
369+ } ,
370+
358371 /**
359372 * Only handles explicit return for now
360373 * To handle implicit return None next
@@ -463,7 +476,11 @@ const pyCmdEvaluators: { [type: string]: CmdEvaluator } = {
463476
464477 // push reset and implicit return for cleanup at end of function
465478 control . push ( instrCreator . resetInstr ( instr . srcNode ) ) ;
466- control . push ( instrCreator . endOfFunctionBodyInstr ( instr . srcNode ) ) ;
479+
480+ // Only push endOfFunctionBodyInstr for functionDef
481+ if ( closure . node . constructor . name === 'FunctionDef' ) {
482+ control . push ( instrCreator . endOfFunctionBodyInstr ( instr . srcNode ) ) ;
483+ }
467484
468485 // create new function environment
469486 const newEnv = createEnvironment ( context , closure , args , instr . srcNode as ExprNS . Call ) ;
0 commit comments