From 34d5825cf906b599e37792d513c522794dbd5636 Mon Sep 17 00:00:00 2001 From: joshvera Date: Thu, 6 Dec 2018 15:29:30 -0500 Subject: [PATCH] Implement Let --- src/Data/Syntax/Statement.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Data/Syntax/Statement.hs b/src/Data/Syntax/Statement.hs index c40b64c91..b26b1cd8e 100644 --- a/src/Data/Syntax/Statement.hs +++ b/src/Data/Syntax/Statement.hs @@ -133,11 +133,19 @@ instance Ord1 Let where liftCompare = genericLiftCompare instance Show1 Let where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Let where - eval _ Let{..} = do - undefined - -- name <- maybeM (throwEvalError NoNameError) (declaredName letVariable) - -- addr <- snd <$> letrec name (eval letValue >>= Abstract.value) - -- Rval <$> locally (bind name addr *> (eval letBody >>= address)) + eval eval Let{..} = do + name <- maybeM (throwEvalError NoNameError) (declaredName letVariable) + letSpan <- ask @Span + valueName <- maybeM (throwEvalError NoNameError) (declaredName letValue) + assocScope <- associatedScope (Declaration valueName) + + withLexicalScopeAndFrame $ do + declare (Declaration name) letSpan assocScope + letVal <- (eval letValue >>= Abstract.value) + slot <- lookupDeclaration (Declaration name) + assign slot letVal + eval letBody + rvalBox unit -- Assignment