From b821c4009c6f4d742dfd2310fb4221b11fef754a Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 28 Nov 2017 11:13:05 -0800 Subject: [PATCH] Assignment eval now uses continutation, does envLookup --- src/Data/Syntax/Statement.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Data/Syntax/Statement.hs b/src/Data/Syntax/Statement.hs index a1f9df018..902d0742f 100644 --- a/src/Data/Syntax/Statement.hs +++ b/src/Data/Syntax/Statement.hs @@ -4,6 +4,7 @@ module Data.Syntax.Statement where import Abstract.Eval import Abstract.Value import Abstract.FreeVariables +import Abstract.Environment import Abstract.Store import Algorithm import Data.Foldable @@ -74,13 +75,16 @@ instance ( Monad m , Semigroup (Cell l (Value s a l)) , MonadAddress l m , MonadStore l (Value s a l) m - , FreeVariables1 s) => Eval l (Value s a l) m s a Assignment where - eval ev Assignment{..} = do + , MonadEnv l (Value s a l) m + , FreeVariables1 s) + => Eval l (Value s a l) m s a Assignment where + eval ev yield Assignment{..} = do let [var] = toList (freeVariables assignmentTarget) - v <- ev assignmentValue - a <- alloc @l var + v <- ev pure assignmentValue + env <- askEnv @l @(Value s a l) + a <- maybe (alloc @l var) pure (envLookup var env) assign a v - pure v + localEnv (envInsert var a) (yield v) -- Returns